dolibarr 19.0.3
websiteaccount_card.php
Go to the documentation of this file.
1<?php
2/* Copyright (C) 2017 Laurent Destailleur <eldy@users.sourceforge.net>
3 * Copyright (C) 2023 Lionel Vessiller <lvessiller@open-dsi.fr>
4 *
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 3 of the License, or
8 * (at your option) any later version.
9 *
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License
16 * along with this program. If not, see <https://www.gnu.org/licenses/>.
17 */
18
25// Load Dolibarr environment
26require '../main.inc.php';
27require_once DOL_DOCUMENT_ROOT.'/core/class/html.formcompany.class.php';
28require_once DOL_DOCUMENT_ROOT.'/core/class/html.formfile.class.php';
29require_once DOL_DOCUMENT_ROOT.'/societe/class/societeaccount.class.php';
30require_once DOL_DOCUMENT_ROOT.'/website/lib/websiteaccount.lib.php';
31
32// Load translation files required by the page
33$langs->loadLangs(array("website", "other"));
34
35// Get parameters
36$id = GETPOST('id', 'int');
37$ref = GETPOST('ref', 'alpha');
38$action = GETPOST('action', 'aZ09');
39$confirm = GETPOST('confirm', 'alpha');
40$cancel = GETPOST('cancel', 'aZ09');
41$backtopage = GETPOST('backtopage', 'alpha');
42
43// Initialize technical objects
44$object = new SocieteAccount($db);
45$extrafields = new ExtraFields($db);
46$diroutputmassaction = $conf->website->dir_output.'/temp/massgeneration/'.$user->id;
47$hookmanager->initHooks(array($object->element.'card', 'globalcard')); // Note that conf->hooks_modules contains array
48
49// Fetch optionals attributes and labels
50$extrafields->fetch_name_optionals_label($object->table_element);
51
52$search_array_options = $extrafields->getOptionalsFromPost($object->table_element, '', 'search_');
53
54// Initialize array of search criterias
55$search_all = GETPOST("search_all", 'alpha');
56$search = array();
57foreach ($object->fields as $key => $val) {
58 if (GETPOST('search_'.$key, 'alpha')) {
59 $search[$key] = GETPOST('search_'.$key, 'alpha');
60 }
61}
62
63if (empty($action) && empty($id) && empty($ref)) {
64 $action = 'view';
65}
66
67// Load object
68include DOL_DOCUMENT_ROOT.'/core/actions_fetchobject.inc.php'; // Must be include, not include_once.
69
70// Security check
71//if ($user->socid > 0) accessforbidden();
72//if ($user->socid > 0) $socid = $user->socid;
73//$result = restrictedArea($user, 'website', $id);
74$permissiontoaccess = (isModEnabled('website') && $user->hasRight('website', 'read')) || isModEnabled('webportal');
75if (!$permissiontoaccess) {
76 accessforbidden('NotAllowed');
77}
78
79// Permissions
80$permissiontocreate = 0;
81$permissiontodelete = 0;
82// permissions from object type of site
83if ($object->id > 0) {
84 if ($object->site == 'dolibarr_website') {
85 $permissiontocreate = isModEnabled('website') && $user->hasRight('website', 'write');
86 $permissiontodelete = isModEnabled('website') && $user->hasRight('website', 'delete');
87 } elseif ($object->site == 'dolibarr_portal') {
88 $permissiontocreate = isModEnabled('webportal') && $user->hasRight('webportal', 'write');
89 }
90} else {
91 $permissiontocreate = isModEnabled('website') && $user->hasRight('website', 'write') || isModEnabled('webportal') && $user->hasRight('webportal', 'write');
92}
93$permissionnote = $permissiontocreate; // Used by the include of actions_setnotes.inc.php
94$permissiondellink = $permissiontocreate; // Used by the include of actions_dellink.inc.php
95$permissiontoadd = $permissiontocreate; // Used by the include of actions_addupdatedelete.inc.php and actions_lineupdown.inc.php
96
97// check access from type of site on create, edit, delete (other than view)
98$site_type_js = '';
99if (!empty($action) && $action != 'view') {
100 if (!empty($object->fields['site']['arrayofkeyval'])) {
101 if (isset($object->fields['site']['arrayofkeyval']['dolibarr_website'])) {
102 if ($action == 'delete' || $action == 'confirm_delete') {
103 if (!$user->hasRight('website', 'delete')) {
104 unset($object->fields['site']['arrayofkeyval']['dolibarr_website']);
105 }
106 } else {
107 if (!$user->hasRight('website', 'write')) {
108 unset($object->fields['site']['arrayofkeyval']['dolibarr_website']);
109 }
110 }
111 }
112
113 if (isset($object->fields['site']['arrayofkeyval']['dolibarr_portal'])) {
114 if (!$user->hasRight('webportal', 'write')) {
115 unset($object->fields['site']['arrayofkeyval']['dolibarr_portal']);
116 }
117 }
118 }
119 if (empty($object->fields['site']['arrayofkeyval'])) {
120 accessforbidden('NotAllowed');
121 }
122
123 if ($object->id > 0) { // update or delete or other than create
124 // check user has the right to modify this type of website
125 if (!key_exists($object->site, $object->fields['site']['arrayofkeyval'])) {
126 accessforbidden('NotAllowed');
127 }
128 }
129}
130
131
132/*
133 * Actions
134 */
135
136$parameters = array();
137$reshook = $hookmanager->executeHooks('doActions', $parameters, $object, $action); // Note that $action and $object may have been modified by some hooks
138if ($reshook < 0) {
139 setEventMessages($hookmanager->error, $hookmanager->errors, 'errors');
140}
141
142if (empty($reshook)) {
143 $error = 0;
144
145 $backurlforlist = dol_buildpath('/societe/website.php', 1).'?id='.$object->fk_soc;
146
147 // Actions cancel, add, update or delete
148 include DOL_DOCUMENT_ROOT.'/core/actions_addupdatedelete.inc.php';
149
150 // Actions when printing a doc from card
151 include DOL_DOCUMENT_ROOT.'/core/actions_printing.inc.php';
152
153 // Actions to send emails
154 $triggersendname = 'WEBSITEACCOUNT_SENTBYMAIL';
155 $autocopy = 'MAIN_MAIL_AUTOCOPY_WEBSITEACCOUNT_TO';
156 $trackid = 'websiteaccount'.$object->id;
157 include DOL_DOCUMENT_ROOT.'/core/actions_sendmails.inc.php';
158}
159
160
161/*
162 * View
163 */
164
165$form = new Form($db);
166$formfile = new FormFile($db);
167
168$title = $langs->trans("WebsiteAccount");
169$help_url = '';
170
171llxHeader('', $title, $help_url);
172
173// prepare output js
174$out_js = '';
175if ($action == 'create' || $action == 'edit') {
176 if (!empty($object->fields['site']['visible']) && !empty($object->fields['fk_website']['visible'])) {
177 $site_type_js = 'function siteTypeChange(site_type) {';
178 $site_type_js .= ' if (site_type == "dolibarr_website") {';
179 $site_type_js .= ' jQuery("tr.field_fk_website").show();';
180 $site_type_js .= ' } else {';
181 $site_type_js .= ' jQuery("select#fk_website").val("-1").change();';
182 $site_type_js .= ' jQuery("tr.field_fk_website").hide();';
183 $site_type_js .= ' }';
184 $site_type_js .= '}';
185 $site_type_js .= 'jQuery(document).ready(function(){';
186 $site_type_js .= ' siteTypeChange(jQuery("#site").val());';
187 $site_type_js .= ' jQuery("#site").change(function(){';
188 $site_type_js .= ' siteTypeChange(this.value);';
189 $site_type_js .= ' });';
190 $site_type_js .= '});';
191
192 $out_js .= '<script type"text/javascript">';
193 $out_js .= $site_type_js;
194 $out_js .= '</script>';
195 }
196}
197
198// Part to create
199if ($action == 'create') {
200 if (empty($permissiontoadd)) {
201 accessforbidden('NotEnoughPermissions', 0, 1);
202 }
203
204 print load_fiche_titre($langs->trans("NewWebsiteAccount", $langs->transnoentitiesnoconv("WebsiteAccount")));
205
206 print '<form method="POST" action="'.$_SERVER["PHP_SELF"].'">';
207 print '<input type="hidden" name="token" value="'.newToken().'">';
208 print '<input type="hidden" name="action" value="add">';
209 if ($backtopage) {
210 print '<input type="hidden" name="backtopage" value="'.$backtopage.'">';
211 }
212 if ($backtopageforcancel) {
213 print '<input type="hidden" name="backtopageforcancel" value="'.$backtopageforcancel.'">';
214 }
215 if ($backtopagejsfields) {
216 print '<input type="hidden" name="backtopagejsfields" value="'.$backtopagejsfields.'">';
217 }
218 if ($dol_openinpopup) {
219 print '<input type="hidden" name="dol_openinpopup" value="'.$dol_openinpopup.'">';
220 }
221
222 print dol_get_fiche_head(array(), '');
223
224 print '<table class="border centpercent tableforfieldcreate">'."\n";
225
226 // Common attributes
227 include DOL_DOCUMENT_ROOT.'/core/tpl/commonfields_add.tpl.php';
228
229 // Other attributes
230 include DOL_DOCUMENT_ROOT.'/core/tpl/extrafields_add.tpl.php';
231
232 print '</table>'."\n";
233
234 print dol_get_fiche_end();
235
236 print $form->buttonsSaveCancel("Create");
237
238 print '</form>';
239
240 print $out_js;
241}
242
243// Part to edit record
244if (($id || $ref) && $action == 'edit') {
245 print load_fiche_titre($langs->trans("WebsiteAccount"));
246
247 print '<form method="POST" action="'.$_SERVER["PHP_SELF"].'">';
248 print '<input type="hidden" name="token" value="'.newToken().'">';
249 print '<input type="hidden" name="action" value="update">';
250 print '<input type="hidden" name="backtopage" value="'.$backtopage.'">';
251 print '<input type="hidden" name="id" value="'.$object->id.'">';
252
253 print dol_get_fiche_head();
254
255 print '<table class="border centpercent tableforfieldedit">'."\n";
256
257 // Common attributes
258 include DOL_DOCUMENT_ROOT.'/core/tpl/commonfields_edit.tpl.php';
259
260 // Other attributes
261 include DOL_DOCUMENT_ROOT.'/core/tpl/extrafields_edit.tpl.php';
262
263 print '</table>';
264
265 print dol_get_fiche_end();
266
267 print $form->buttonsSaveCancel();
268
269 print '</form>';
270
271 print $out_js;
272}
273
274// Part to show record
275if ($object->id > 0 && (empty($action) || ($action != 'edit' && $action != 'create'))) {
276 if ($object->fk_soc > 0 && empty($socid)) {
277 $socid = $object->fk_soc;
278 }
279
280 //$res = $object->fetch_optionals();
281
282 $head = websiteaccountPrepareHead($object);
283
284 print dol_get_fiche_head($head, 'card', $langs->trans("WebsiteAccount"), -1, 'websiteaccount@website');
285
286 $formconfirm = '';
287
288 // Confirmation to delete
289 if ($action == 'delete') {
290 $formconfirm = $form->formconfirm($_SERVER["PHP_SELF"].'?id='.$object->id, $langs->trans('DeleteWebsiteAccount'), $langs->trans('ConfirmDeleteWebsiteAccount'), 'confirm_delete', '', 0, 1);
291 }
292
293 // Call Hook formConfirm
294 $parameters = array('formConfirm' => $formconfirm);
295 $reshook = $hookmanager->executeHooks('formConfirm', $parameters, $object, $action); // Note that $action and $object may have been modified by hook
296 if (empty($reshook)) {
297 $formconfirm .= $hookmanager->resPrint;
298 } elseif ($reshook > 0) {
299 $formconfirm = $hookmanager->resPrint;
300 }
301
302 // Print form confirm
303 print $formconfirm;
304
305
306 // Object card
307 // ------------------------------------------------------------
308 $linkback = '';
309 if ($socid) {
310 $linkback = '<a href="'.DOL_URL_ROOT.'/societe/website.php?socid='.$socid.'&restore_lastsearch_values=1'.(!empty($socid) ? '&socid='.$socid : '').'">'.$langs->trans("BackToListForThirdParty").'</a>';
311 }
312 //if ($fk_website) {
313 // $linkback = '<a href="'.DOL_URL_ROOT.'/website/website_card.php?fk_website='.$fk_website.'&restore_lastsearch_values=1'.(!empty($socid) ? '&socid='.$socid : '').'">'.$langs->trans("BackToList").'</a>';
314 //}
315
316 $morehtmlref = '<div class="refidno">';
317 /*
318 // Ref bis
319 $morehtmlref.=$form->editfieldkey("RefBis", 'ref_client', $object->ref_client, $object, $user->hasRight('website', 'write'), 'string', '', 0, 1);
320 $morehtmlref.=$form->editfieldval("RefBis", 'ref_client', $object->ref_client, $object, $user->hasRight('website', 'write'), 'string', '', null, null, '', 1);
321 // Thirdparty
322 $morehtmlref.='<br>'.$langs->trans('ThirdParty') . ' : ' . $soc->getNomUrl(1);
323 // Project
324 if (isModEnabled('project'))
325 {
326 $langs->load("projects");
327 $morehtmlref.='<br>'.$langs->trans('Project') . ' ';
328 if ($user->hasRight('website', 'write'))
329 {
330 if ($action != 'classify')
331 {
332 $morehtmlref.='<a class="editfielda" href="' . $_SERVER['PHP_SELF'] . '?action=classify&token='.newToken().'&id=' . $object->id . '">' . img_edit($langs->transnoentitiesnoconv('SetProject')) . '</a> : ';
333 if ($action == 'classify') {
334 //$morehtmlref.=$form->form_project($_SERVER['PHP_SELF'] . '?id=' . $object->id, $object->socid, $object->fk_project, 'projectid', 0, 0, 1, 1);
335 $morehtmlref.='<form method="post" action="'.$_SERVER['PHP_SELF'].'?id='.$object->id.'">';
336 $morehtmlref.='<input type="hidden" name="action" value="classin">';
337 $morehtmlref.='<input type="hidden" name="token" value="'.newToken().'">';
338 $morehtmlref.=$formproject->select_projects($object->socid, $object->fk_project, 'projectid', $maxlength, 0, 1, 0, 1, 0, 0, '', 1);
339 $morehtmlref.='<input type="submit" class="button valignmiddle" value="'.$langs->trans("Modify").'">';
340 $morehtmlref.='</form>';
341 } else {
342 $morehtmlref.=$form->form_project($_SERVER['PHP_SELF'] . '?id=' . $object->id, $object->socid, $object->fk_project, 'none', 0, 0, 0, 1);
343 }
344 }
345 } else {
346 if (!empty($object->fk_project)) {
347 $proj = new Project($db);
348 $proj->fetch($object->fk_project);
349 $morehtmlref.='<a href="'.DOL_URL_ROOT.'/projet/card.php?id=' . $object->fk_project . '" title="' . $langs->trans('ShowProject') . '">';
350 $morehtmlref.=$proj->ref;
351 $morehtmlref.='</a>';
352 } else {
353 $morehtmlref.='';
354 }
355 }
356 }
357 */
358 $morehtmlref .= '</div>';
359
360 if ($socid > 0) {
361 $object->next_prev_filter = 'te.fk_soc = '.((int) $socid);
362 }
363
364 dol_banner_tab($object, 'id', $linkback, 1, 'rowid', 'rowid', $morehtmlref);
365
366
367 print '<div class="fichecenter">';
368 print '<div class="fichehalfleft">';
369 print '<div class="underbanner clearboth"></div>';
370 print '<table class="border centpercent tableforfield">'."\n";
371
372 // Common attributes
373 include DOL_DOCUMENT_ROOT.'/core/tpl/commonfields_view.tpl.php';
374
375 // Other attributes
376 include DOL_DOCUMENT_ROOT.'/core/tpl/extrafields_view.tpl.php';
377
378 print '</table>';
379 print '</div>';
380 print '</div>';
381
382 print '<div class="clearboth"></div>';
383
384 print dol_get_fiche_end();
385
386
387 // Buttons for actions
388 if ($action != 'presend' && $action != 'editline') {
389 print '<div class="tabsAction">'."\n";
390 $parameters = array();
391 $reshook = $hookmanager->executeHooks('addMoreActionsButtons', $parameters, $object, $action); // Note that $action and $object may have been modified by hook
392 if ($reshook < 0) {
393 setEventMessages($hookmanager->error, $hookmanager->errors, 'errors');
394 }
395
396 if (empty($reshook)) {
397 // Send
398 if (empty($user->socid)) {
399 print dolGetButtonAction('', $langs->trans('SendMail'), 'default', $_SERVER["PHP_SELF"].'?id='.$object->id.'&action=presend&token='.newToken().'&mode=init#formmailbeforetitle');
400 }
401
402 // Clone
403 if ($permissiontoadd) {
404 print dolGetButtonAction('', $langs->trans('ToClone'), 'default', $_SERVER['PHP_SELF'].'?id='.$object->id.(!empty($object->socid) ? '&socid='.$object->socid : '').'&action=clone&token='.newToken(), '', $permissiontoadd);
405 }
406
407 /*
408 if ($user->rights->sellyoursaas->create)
409 {
410 if ($object->status == 1)
411 {
412 print '<div class="inline-block divButAction"><a class="butActionDelete" href="'.$_SERVER["PHP_SELF"].'?id='.$object->id.'&action=disable&token='.newToken().'">'.$langs->trans("Disable").'</a></div>'."\n";
413 }
414 else
415 {
416 print '<div class="inline-block divButAction"><a class="butAction" href="'.$_SERVER["PHP_SELF"].'?id='.$object->id.'&action=enable&token='.newToken().'">'.$langs->trans("Enable").'</a></div>'."\n";
417 }
418 }
419 */
420
421 // Delete
422 $params = array();
423 print dolGetButtonAction('', $langs->trans("Delete"), 'delete', $_SERVER["PHP_SELF"].'?id='.$object->id.'&action=delete&token='.newToken(), 'delete', $permissiontodelete, $params);
424 }
425 print '</div>'."\n";
426 }
427
428
429 // Select mail models is same action as presend
430 if (GETPOST('modelselected')) {
431 $action = 'presend';
432 }
433
434 if ($action != 'presend') {
435 print '<div class="fichecenter"><div class="fichehalfleft">';
436 print '<a name="builddoc"></a>'; // ancre
437
438 print '</div><div class="fichehalfright">';
439
440 /*
441 $MAXEVENT = 10;
442
443 $morehtmlcenter = dolGetButtonTitle($langs->trans('SeeAll'), '', 'fa fa-bars imgforviewmode', dol_buildpath('/mymodule/myobject_agenda.php', 1).'?id='.$object->id);
444
445 // List of actions on element
446 include_once DOL_DOCUMENT_ROOT . '/core/class/html.formactions.class.php';
447 $formactions = new FormActions($db);
448 $somethingshown = $formactions->showactions($object, $object->element, $socid, 1, '', $MAXEVENT);
449 */
450
451 print '</div></div>';
452 }
453
454 // Presend form
455 $modelmail = 'websiteaccount';
456 $defaulttopic = 'Information';
457 $diroutput = $conf->website->dir_output;
458 $trackid = 'websiteaccount'.$object->id;
459
460 include DOL_DOCUMENT_ROOT.'/core/tpl/card_presend.tpl.php';
461}
462
463// End of page
464llxFooter();
465$db->close();
if(!defined('NOREQUIRESOC')) if(!defined( 'NOREQUIRETRAN')) if(!defined('NOTOKENRENEWAL')) if(!defined( 'NOREQUIREMENU')) if(!defined('NOREQUIREHTML')) if(!defined( 'NOREQUIREAJAX')) llxHeader()
Empty header.
Definition wrapper.php:55
llxFooter()
Empty footer.
Definition wrapper.php:69
Class to manage standard extra fields.
Class to offer components to list and upload files.
Class to manage generation of HTML components Only common components must be here.
Class for SocieteAccount.
dol_banner_tab($object, $paramid, $morehtml='', $shownav=1, $fieldid='rowid', $fieldref='ref', $morehtmlref='', $moreparam='', $nodbprefix=0, $morehtmlleft='', $morehtmlstatus='', $onlybanner=0, $morehtmlright='')
Show tab footer of a card.
load_fiche_titre($titre, $morehtmlright='', $picto='generic', $pictoisfullpath=0, $id='', $morecssontable='', $morehtmlcenter='')
Load a title with picto.
dol_get_fiche_head($links=array(), $active='', $title='', $notab=0, $picto='', $pictoisfullpath=0, $morehtmlright='', $morecss='', $limittoshow=0, $moretabssuffix='', $dragdropfile=0)
Show tabs of a record.
dol_get_fiche_end($notab=0)
Return tab footer of a card.
dolGetButtonAction($label, $text='', $actionType='default', $url='', $id='', $userRight=1, $params=array())
Function dolGetButtonAction.
GETPOST($paramname, $check='alphanohtml', $method=0, $filter=null, $options=null, $noreplace=0)
Return value of a param into GET or POST supervariable.
setEventMessages($mesg, $mesgs, $style='mesgs', $messagekey='', $noduplicate=0)
Set event messages in dol_events session object.
dol_buildpath($path, $type=0, $returnemptyifnotfound=0)
Return path of url or filesystem.
accessforbidden($message='', $printheader=1, $printfooter=1, $showonlymessage=0, $params=null)
Show a message to say access is forbidden and stop program.
websiteaccountPrepareHead($object)
Prepare array of tabs for SocieteAccount.