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