dolibarr 22.0.5
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 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$id = GETPOSTINT('id');
46$ref = GETPOST('ref', 'alpha');
47$action = GETPOST('action', 'aZ09');
48$confirm = GETPOST('confirm', 'alpha');
49$cancel = GETPOST('cancel');
50$backtopage = GETPOST('backtopage', 'alpha');
51
52// Initialize a technical objects
53$object = new SocieteAccount($db);
54$extrafields = new ExtraFields($db);
55$hookmanager->initHooks(array($object->element.'card', 'globalcard')); // Note that conf->hooks_modules contains array
56
57// Fetch optionals attributes and labels
58$extrafields->fetch_name_optionals_label($object->table_element);
59
60$search_array_options = $extrafields->getOptionalsFromPost($object->table_element, '', 'search_');
61
62// Initialize array of search criteria
63$search_all = GETPOST("search_all", 'alpha');
64$search = array();
65foreach ($object->fields as $key => $val) {
66 if (GETPOST('search_'.$key, 'alpha')) {
67 $search[$key] = GETPOST('search_'.$key, 'alpha');
68 }
69}
70
71if (empty($action) && empty($id) && empty($ref)) {
72 $action = 'view';
73}
74
75// Load object
76include DOL_DOCUMENT_ROOT.'/core/actions_fetchobject.inc.php'; // Must be 'include', not 'include_once'.
77
78// Security check
79//if ($user->socid > 0) accessforbidden();
80//if ($user->socid > 0) $socid = $user->socid;
81//$result = restrictedArea($user, 'website', $id);
82$permissiontoaccess = (isModEnabled('website') && $user->hasRight('website', 'read')) || isModEnabled('webportal');
83if (!$permissiontoaccess) {
84 accessforbidden('NotAllowed');
85}
86
87// Permissions
88$permissiontocreate = 0;
89$permissiontodelete = 0;
90// permissions from object type of site
91if ($object->id > 0) {
92 if ($object->site == 'dolibarr_website') {
93 $permissiontocreate = isModEnabled('website') && $user->hasRight('website', 'write');
94 $permissiontodelete = isModEnabled('website') && $user->hasRight('website', 'delete');
95 } elseif ($object->site == 'dolibarr_portal') {
96 $permissiontocreate = $permissiontodelete = isModEnabled('webportal') && $user->hasRight('webportal', 'write');
97 }
98} else {
99 $permissiontocreate = isModEnabled('website') && $user->hasRight('website', 'write') || isModEnabled('webportal') && $user->hasRight('webportal', 'write');
100}
101$permissionnote = $permissiontocreate; // Used by the include of actions_setnotes.inc.php
102$permissiondellink = $permissiontocreate; // Used by the include of actions_dellink.inc.php
103$permissiontoadd = $permissiontocreate; // Used by the include of actions_addupdatedelete.inc.php and actions_lineupdown.inc.php
104
105// check access from type of site on create, edit, delete (other than view)
106$site_type_js = '';
107if (!empty($action) && $action != 'view') {
108 if (!empty($object->fields['site']['arrayofkeyval'])) {
109 if (isset($object->fields['site']['arrayofkeyval']['dolibarr_website'])) {
110 if ($action == 'delete' || $action == 'confirm_delete') {
111 if (!$user->hasRight('website', 'delete')) {
112 unset($object->fields['site']['arrayofkeyval']['dolibarr_website']);
113 }
114 } else {
115 if (!$user->hasRight('website', 'write')) {
116 unset($object->fields['site']['arrayofkeyval']['dolibarr_website']);
117 }
118 }
119 }
120
121 if (isset($object->fields['site']['arrayofkeyval']['dolibarr_portal'])) {
122 if (!$user->hasRight('webportal', 'write')) {
123 unset($object->fields['site']['arrayofkeyval']['dolibarr_portal']);
124 }
125 }
126 }
127 if (empty($object->fields['site']['arrayofkeyval'])) {
128 accessforbidden('NotAllowed');
129 }
130
131 if ($object->id > 0) { // update or delete or other than create
132 // check user has the right to modify this type of website
133 if (!array_key_exists($object->site, $object->fields['site']['arrayofkeyval'])) {
134 accessforbidden('NotAllowed');
135 }
136 }
137}
138
139$error = 0;
140
141
142/*
143 * Actions
144 */
145
146$parameters = array();
147$reshook = $hookmanager->executeHooks('doActions', $parameters, $object, $action); // Note that $action and $object may have been modified by some hooks
148if ($reshook < 0) {
149 setEventMessages($hookmanager->error, $hookmanager->errors, 'errors');
150}
151
152if (empty($reshook)) {
153 $backurlforlist = dol_buildpath('/societe/website.php', 1).'?id='.$object->fk_soc;
154
155 if ($action == 'add' && !GETPOST('site')) { // Test on permission not required
156 setEventMessages($langs->trans("ErrorFieldRequired", $langs->transnoentitiesnoconv("Website")), null, 'errors');
157 $action = 'create';
158 }
159
160 // Actions cancel, add, update or delete
161 include DOL_DOCUMENT_ROOT.'/core/actions_addupdatedelete.inc.php';
162
163 // Actions when printing a doc from card
164 include DOL_DOCUMENT_ROOT.'/core/actions_printing.inc.php';
165
166 // Actions to send emails
167 $triggersendname = 'WEBSITEACCOUNT_SENTBYMAIL';
168 $autocopy = 'MAIN_MAIL_AUTOCOPY_WEBSITEACCOUNT_TO';
169 $trackid = 'websiteaccount'.$object->id;
170 include DOL_DOCUMENT_ROOT.'/core/actions_sendmails.inc.php';
171}
172
173
174/*
175 * View
176 */
177
178$form = new Form($db);
179$formfile = new FormFile($db);
180
181$title = $langs->trans("WebsiteAccount");
182$help_url = '';
183
184llxHeader('', $title, $help_url, '', 0, 0, '', '', '', 'mod-website page-card_websiteaccount');
185
186// prepare output js
187$out_js = '';
188if ($action == 'create' || $action == 'edit') {
189 if (!empty($object->fields['site']['visible']) && !empty($object->fields['fk_website']['visible'])) {
190 $site_type_js = 'function siteTypeChange(site_type) {';
191 $site_type_js .= ' if (site_type == "dolibarr_website") {';
192 $site_type_js .= ' jQuery("tr.field_fk_website").show();';
193 $site_type_js .= ' } else {';
194 $site_type_js .= ' jQuery("select#fk_website").val("-1").change();';
195 $site_type_js .= ' jQuery("tr.field_fk_website").hide();';
196 $site_type_js .= ' }';
197 $site_type_js .= '}';
198 $site_type_js .= 'jQuery(document).ready(function(){';
199 $site_type_js .= ' siteTypeChange(jQuery("#site").val());';
200 $site_type_js .= ' jQuery("#site").change(function(){';
201 $site_type_js .= ' siteTypeChange(this.value);';
202 $site_type_js .= ' });';
203 $site_type_js .= '});';
204
205 $out_js .= '<script type"text/javascript">';
206 $out_js .= $site_type_js;
207 $out_js .= '</script>';
208 }
209}
210
211// Part to create
212if ($action == 'create') {
213 if (empty($permissiontoadd)) {
214 accessforbidden('NotEnoughPermissions', 0, 1);
215 }
216
217 print load_fiche_titre($langs->trans("NewWebsiteAccount", $langs->transnoentitiesnoconv("WebsiteAccount")));
218
219 print '<form method="POST" action="'.$_SERVER["PHP_SELF"].'">';
220 print '<input type="hidden" name="token" value="'.newToken().'">';
221 print '<input type="hidden" name="action" value="add">';
222 if ($backtopage) {
223 print '<input type="hidden" name="backtopage" value="'.$backtopage.'">';
224 }
225 if (!empty($backtopageforcancel)) {
226 print '<input type="hidden" name="backtopageforcancel" value="'.$backtopageforcancel.'">';
227 }
228 if (!empty($dol_openinpopup)) {
229 print '<input type="hidden" name="dol_openinpopup" value="'.$dol_openinpopup.'">';
230 }
231
232 print dol_get_fiche_head(array(), '');
233
234 print '<table class="border centpercent tableforfieldcreate">'."\n";
235
236 // Common attributes
237 include DOL_DOCUMENT_ROOT.'/core/tpl/commonfields_add.tpl.php';
238
239 // Other attributes
240 include DOL_DOCUMENT_ROOT.'/core/tpl/extrafields_add.tpl.php';
241
242 print '</table>'."\n";
243
244 print dol_get_fiche_end();
245
246 print $form->buttonsSaveCancel("Create");
247
248 print '</form>';
249
250 print $out_js;
251}
252
253// Part to edit record
254if (($id || $ref) && $action == 'edit') {
255 print load_fiche_titre($langs->trans("WebsiteAccount"));
256
257 print '<form method="POST" action="'.$_SERVER["PHP_SELF"].'">';
258 print '<input type="hidden" name="token" value="'.newToken().'">';
259 print '<input type="hidden" name="action" value="update">';
260 print '<input type="hidden" name="backtopage" value="'.$backtopage.'">';
261 print '<input type="hidden" name="id" value="'.$object->id.'">';
262
263 print dol_get_fiche_head();
264
265 print '<table class="border centpercent tableforfieldedit">'."\n";
266
267 // Common attributes
268 include DOL_DOCUMENT_ROOT.'/core/tpl/commonfields_edit.tpl.php';
269
270 // Other attributes
271 include DOL_DOCUMENT_ROOT.'/core/tpl/extrafields_edit.tpl.php';
272
273 print '</table>';
274
275 print dol_get_fiche_end();
276
277 print $form->buttonsSaveCancel();
278
279 print '</form>';
280
281 print $out_js;
282}
283
284// Part to show record
285if ($object->id > 0 && (empty($action) || ($action != 'edit' && $action != 'create'))) {
286 if ($object->fk_soc > 0 && empty($socid)) {
287 $socid = $object->fk_soc;
288 }
289
290 //$res = $object->fetch_optionals();
291
292 $head = websiteaccountPrepareHead($object);
293
294 print dol_get_fiche_head($head, 'card', $langs->trans("WebsiteAccount"), -1, $object->picto);
295
296 $formconfirm = '';
297
298 // Confirmation to delete
299 if ($action == 'delete') {
300 $formconfirm = $form->formconfirm($_SERVER["PHP_SELF"].'?id='.$object->id, $langs->trans('DeleteWebsiteAccount'), $langs->trans('ConfirmDeleteWebsiteAccount').'<br>'.$langs->trans('ConfirmDeleteWebsiteAccount2'), 'confirm_delete', '', 0, 1);
301 }
302
303 // Call Hook formConfirm
304 $parameters = array('formConfirm' => $formconfirm);
305 $reshook = $hookmanager->executeHooks('formConfirm', $parameters, $object, $action); // Note that $action and $object may have been modified by hook
306 if (empty($reshook)) {
307 $formconfirm .= $hookmanager->resPrint;
308 } elseif ($reshook > 0) {
309 $formconfirm = $hookmanager->resPrint;
310 }
311
312 // Print form confirm
313 print $formconfirm;
314
315
316 // Object card
317 // ------------------------------------------------------------
318 $linkback = '';
319 if ($socid) {
320 $linkback = '<a href="'.DOL_URL_ROOT.'/societe/website.php?socid='.$socid.'&restore_lastsearch_values=1'.(!empty($socid) ? '&socid='.$socid : '').'">'.$langs->trans("BackToListForThirdParty").'</a>';
321 }
322 //if ($fk_website) {
323 // $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>';
324 //}
325
326 $morehtmlref = '<div class="refidno">';
327 /*
328 // Ref bis
329 $morehtmlref.=$form->editfieldkey("RefBis", 'ref_client', $object->ref_client, $object, $user->hasRight('website', 'write'), 'string', '', 0, 1);
330 $morehtmlref.=$form->editfieldval("RefBis", 'ref_client', $object->ref_client, $object, $user->hasRight('website', 'write'), 'string', '', null, null, '', 1);
331 // Thirdparty
332 $morehtmlref.='<br>'.$langs->trans('ThirdParty') . ' : ' . $soc->getNomUrl(1);
333 // Project
334 if (isModEnabled('project'))
335 {
336 $langs->load("projects");
337 $morehtmlref.='<br>'.$langs->trans('Project') . ' ';
338 if ($user->hasRight('website', 'write'))
339 {
340 if ($action != 'classify')
341 {
342 $morehtmlref.='<a class="editfielda" href="' . $_SERVER['PHP_SELF'] . '?action=classify&token='.newToken().'&id=' . $object->id . '">' . img_edit($langs->transnoentitiesnoconv('SetProject')) . '</a> : ';
343 if ($action == 'classify') {
344 //$morehtmlref.=$form->form_project($_SERVER['PHP_SELF'] . '?id=' . $object->id, $object->socid, $object->fk_project, 'projectid', 0, 0, 1, 1);
345 $morehtmlref.='<form method="post" action="'.$_SERVER['PHP_SELF'].'?id='.$object->id.'">';
346 $morehtmlref.='<input type="hidden" name="action" value="classin">';
347 $morehtmlref.='<input type="hidden" name="token" value="'.newToken().'">';
348 $morehtmlref.=$formproject->select_projects($object->socid, $object->fk_project, 'projectid', $maxlength, 0, 1, 0, 1, 0, 0, '', 1);
349 $morehtmlref.='<input type="submit" class="button valignmiddle" value="'.$langs->trans("Modify").'">';
350 $morehtmlref.='</form>';
351 } else {
352 $morehtmlref.=$form->form_project($_SERVER['PHP_SELF'] . '?id=' . $object->id, $object->socid, $object->fk_project, 'none', 0, 0, 0, 1);
353 }
354 }
355 } else {
356 if (!empty($object->fk_project)) {
357 $proj = new Project($db);
358 $proj->fetch($object->fk_project);
359 $morehtmlref.='<a href="'.DOL_URL_ROOT.'/projet/card.php?id=' . $object->fk_project . '" title="' . $langs->trans('ShowProject') . '">';
360 $morehtmlref.=$proj->ref;
361 $morehtmlref.='</a>';
362 } else {
363 $morehtmlref.='';
364 }
365 }
366 }
367 */
368 $morehtmlref .= '</div>';
369
370 if ($socid > 0) {
371 $object->next_prev_filter = 'te.fk_soc:=:'.((int) $socid);
372 }
373
374 dol_banner_tab($object, 'id', $linkback, 1, 'rowid', 'rowid', $morehtmlref);
375
376
377 print '<div class="fichecenter">';
378 print '<div class="fichehalfleft">';
379 print '<div class="underbanner clearboth"></div>';
380 print '<table class="border centpercent tableforfield">'."\n";
381
382 // Common attributes
383 $keyforbreak='note_private'; // We change column just before this field
384 //unset($object->fields['fk_project']); // Hide field already shown in banner
385 //unset($object->fields['fk_soc']); // Hide field already shown in banner
386 include DOL_DOCUMENT_ROOT.'/core/tpl/commonfields_view.tpl.php';
387
388 // Other attributes
389 include DOL_DOCUMENT_ROOT.'/core/tpl/extrafields_view.tpl.php';
390
391 print '</table>';
392 print '</div>';
393 print '</div>';
394
395 print '<div class="clearboth"></div>';
396
397 print dol_get_fiche_end();
398
399
400 // Buttons for actions
401 if ($action != 'presend' && $action != 'editline') {
402 print '<div class="tabsAction">'."\n";
403 $parameters = array();
404 $reshook = $hookmanager->executeHooks('addMoreActionsButtons', $parameters, $object, $action); // Note that $action and $object may have been modified by hook
405 if ($reshook < 0) {
406 setEventMessages($hookmanager->error, $hookmanager->errors, 'errors');
407 }
408
409 if (empty($reshook)) {
410 // Send
411 if (empty($user->socid)) {
412 print dolGetButtonAction('', $langs->trans('SendMail'), 'default', $_SERVER["PHP_SELF"].'?id='.$object->id.'&action=presend&token='.newToken().'&mode=init#formmailbeforetitle');
413 }
414
415 // Modify
416 if ($permissiontoadd) {
417 print dolGetButtonAction('', $langs->trans('Modify'), 'default', $_SERVER['PHP_SELF'].'?id='.$object->id.(!empty($object->socid) ? '&socid='.$object->socid : '').'&action=edit&token='.newToken(), '', $permissiontoadd);
418 }
419
420 // Clone
421 if ($permissiontoadd) {
422 print dolGetButtonAction('', $langs->trans('ToClone'), 'default', $_SERVER['PHP_SELF'].'?id='.$object->id.(!empty($object->socid) ? '&socid='.$object->socid : '').'&action=clone&token='.newToken(), '', $permissiontoadd);
423 }
424
425 // Delete
426 $params = array();
427 print dolGetButtonAction('', $langs->trans("Delete"), 'delete', $_SERVER["PHP_SELF"].'?id='.$object->id.'&action=delete&token='.newToken(), 'delete', $permissiontodelete, $params);
428 }
429 print '</div>'."\n";
430 }
431
432
433 // Select mail models is same action as presend
434 if (GETPOST('modelselected')) {
435 $action = 'presend';
436 }
437
438 if ($action != 'presend') {
439 print '<div class="fichecenter"><div class="fichehalfleft">';
440 print '<a name="builddoc"></a>'; // ancre
441
442 print '</div><div class="fichehalfright">';
443
444 /*
445 $MAXEVENT = 10;
446
447 $morehtmlcenter = dolGetButtonTitle($langs->trans('SeeAll'), '', 'fa fa-bars imgforviewmode', dol_buildpath('/mymodule/myobject_agenda.php', 1).'?id='.$object->id);
448
449 // List of actions on element
450 include_once DOL_DOCUMENT_ROOT . '/core/class/html.formactions.class.php';
451 $formactions = new FormActions($db);
452 $somethingshown = $formactions->showactions($object, $object->element, $socid, 1, '', $MAXEVENT);
453 */
454
455 print '</div></div>';
456 }
457
458 // Presend form
459 $modelmail = 'websiteaccount';
460 $defaulttopic = 'Information';
461 $diroutput = isModEnabled('website') ? $conf->website->dir_output : '';
462 $trackid = 'websiteaccount'.$object->id;
463
464 include DOL_DOCUMENT_ROOT.'/core/tpl/card_presend.tpl.php';
465}
466
467// End of page
468llxFooter();
469$db->close();
$id
Support class for third parties, contacts, members, users or resources.
Definition account.php:48
if( $user->socid > 0) if(! $user->hasRight('accounting', 'chartofaccount')) $object
Definition card.php:67
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.
load_fiche_titre($title, $morehtmlright='', $picto='generic', $pictoisfullpath=0, $id='', $morecssontable='', $morehtmlcenter='')
Load a title with picto.
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.
newToken()
Return the value of token currently saved into session with name 'newtoken'.
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.
dol_buildpath($path, $type=0, $returnemptyifnotfound=0)
Return path of url or filesystem.
global $conf
The following vars must be defined: $type2label $form $conf, $lang, The following vars may also be de...
Definition member.php:79
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.