dolibarr 21.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 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("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', 'aZ09');
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 = 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($backtopagejsfields)) {
229 print '<input type="hidden" name="backtopagejsfields" value="'.$backtopagejsfields.'">';
230 }
231 if (!empty($dol_openinpopup)) {
232 print '<input type="hidden" name="dol_openinpopup" value="'.$dol_openinpopup.'">';
233 }
234
235 print dol_get_fiche_head(array(), '');
236
237 print '<table class="border centpercent tableforfieldcreate">'."\n";
238
239 // Common attributes
240 include DOL_DOCUMENT_ROOT.'/core/tpl/commonfields_add.tpl.php';
241
242 // Other attributes
243 include DOL_DOCUMENT_ROOT.'/core/tpl/extrafields_add.tpl.php';
244
245 print '</table>'."\n";
246
247 print dol_get_fiche_end();
248
249 print $form->buttonsSaveCancel("Create");
250
251 print '</form>';
252
253 print $out_js;
254}
255
256// Part to edit record
257if (($id || $ref) && $action == 'edit') {
258 print load_fiche_titre($langs->trans("WebsiteAccount"));
259
260 print '<form method="POST" action="'.$_SERVER["PHP_SELF"].'">';
261 print '<input type="hidden" name="token" value="'.newToken().'">';
262 print '<input type="hidden" name="action" value="update">';
263 print '<input type="hidden" name="backtopage" value="'.$backtopage.'">';
264 print '<input type="hidden" name="id" value="'.$object->id.'">';
265
266 print dol_get_fiche_head();
267
268 print '<table class="border centpercent tableforfieldedit">'."\n";
269
270 // Common attributes
271 include DOL_DOCUMENT_ROOT.'/core/tpl/commonfields_edit.tpl.php';
272
273 // Other attributes
274 include DOL_DOCUMENT_ROOT.'/core/tpl/extrafields_edit.tpl.php';
275
276 print '</table>';
277
278 print dol_get_fiche_end();
279
280 print $form->buttonsSaveCancel();
281
282 print '</form>';
283
284 print $out_js;
285}
286
287// Part to show record
288if ($object->id > 0 && (empty($action) || ($action != 'edit' && $action != 'create'))) {
289 if ($object->fk_soc > 0 && empty($socid)) {
290 $socid = $object->fk_soc;
291 }
292
293 //$res = $object->fetch_optionals();
294
295 $head = websiteaccountPrepareHead($object);
296
297 print dol_get_fiche_head($head, 'card', $langs->trans("WebsiteAccount"), -1, $object->picto);
298
299 $formconfirm = '';
300
301 // Confirmation to delete
302 if ($action == 'delete') {
303 $formconfirm = $form->formconfirm($_SERVER["PHP_SELF"].'?id='.$object->id, $langs->trans('DeleteWebsiteAccount'), $langs->trans('ConfirmDeleteWebsiteAccount'), 'confirm_delete', '', 0, 1);
304 }
305
306 // Call Hook formConfirm
307 $parameters = array('formConfirm' => $formconfirm);
308 $reshook = $hookmanager->executeHooks('formConfirm', $parameters, $object, $action); // Note that $action and $object may have been modified by hook
309 if (empty($reshook)) {
310 $formconfirm .= $hookmanager->resPrint;
311 } elseif ($reshook > 0) {
312 $formconfirm = $hookmanager->resPrint;
313 }
314
315 // Print form confirm
316 print $formconfirm;
317
318
319 // Object card
320 // ------------------------------------------------------------
321 $linkback = '';
322 if ($socid) {
323 $linkback = '<a href="'.DOL_URL_ROOT.'/societe/website.php?socid='.$socid.'&restore_lastsearch_values=1'.(!empty($socid) ? '&socid='.$socid : '').'">'.$langs->trans("BackToListForThirdParty").'</a>';
324 }
325 //if ($fk_website) {
326 // $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>';
327 //}
328
329 $morehtmlref = '<div class="refidno">';
330 /*
331 // Ref bis
332 $morehtmlref.=$form->editfieldkey("RefBis", 'ref_client', $object->ref_client, $object, $user->hasRight('website', 'write'), 'string', '', 0, 1);
333 $morehtmlref.=$form->editfieldval("RefBis", 'ref_client', $object->ref_client, $object, $user->hasRight('website', 'write'), 'string', '', null, null, '', 1);
334 // Thirdparty
335 $morehtmlref.='<br>'.$langs->trans('ThirdParty') . ' : ' . $soc->getNomUrl(1);
336 // Project
337 if (isModEnabled('project'))
338 {
339 $langs->load("projects");
340 $morehtmlref.='<br>'.$langs->trans('Project') . ' ';
341 if ($user->hasRight('website', 'write'))
342 {
343 if ($action != 'classify')
344 {
345 $morehtmlref.='<a class="editfielda" href="' . $_SERVER['PHP_SELF'] . '?action=classify&token='.newToken().'&id=' . $object->id . '">' . img_edit($langs->transnoentitiesnoconv('SetProject')) . '</a> : ';
346 if ($action == 'classify') {
347 //$morehtmlref.=$form->form_project($_SERVER['PHP_SELF'] . '?id=' . $object->id, $object->socid, $object->fk_project, 'projectid', 0, 0, 1, 1);
348 $morehtmlref.='<form method="post" action="'.$_SERVER['PHP_SELF'].'?id='.$object->id.'">';
349 $morehtmlref.='<input type="hidden" name="action" value="classin">';
350 $morehtmlref.='<input type="hidden" name="token" value="'.newToken().'">';
351 $morehtmlref.=$formproject->select_projects($object->socid, $object->fk_project, 'projectid', $maxlength, 0, 1, 0, 1, 0, 0, '', 1);
352 $morehtmlref.='<input type="submit" class="button valignmiddle" value="'.$langs->trans("Modify").'">';
353 $morehtmlref.='</form>';
354 } else {
355 $morehtmlref.=$form->form_project($_SERVER['PHP_SELF'] . '?id=' . $object->id, $object->socid, $object->fk_project, 'none', 0, 0, 0, 1);
356 }
357 }
358 } else {
359 if (!empty($object->fk_project)) {
360 $proj = new Project($db);
361 $proj->fetch($object->fk_project);
362 $morehtmlref.='<a href="'.DOL_URL_ROOT.'/projet/card.php?id=' . $object->fk_project . '" title="' . $langs->trans('ShowProject') . '">';
363 $morehtmlref.=$proj->ref;
364 $morehtmlref.='</a>';
365 } else {
366 $morehtmlref.='';
367 }
368 }
369 }
370 */
371 $morehtmlref .= '</div>';
372
373 if ($socid > 0) {
374 $object->next_prev_filter = 'te.fk_soc:=:'.((int) $socid);
375 }
376
377 dol_banner_tab($object, 'id', $linkback, 1, 'rowid', 'rowid', $morehtmlref);
378
379
380 print '<div class="fichecenter">';
381 print '<div class="fichehalfleft">';
382 print '<div class="underbanner clearboth"></div>';
383 print '<table class="border centpercent tableforfield">'."\n";
384
385 // Common attributes
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 // Clone
416 if ($permissiontoadd) {
417 print dolGetButtonAction('', $langs->trans('ToClone'), 'default', $_SERVER['PHP_SELF'].'?id='.$object->id.(!empty($object->socid) ? '&socid='.$object->socid : '').'&action=clone&token='.newToken(), '', $permissiontoadd);
418 }
419
420 // Delete
421 $params = array();
422 print dolGetButtonAction('', $langs->trans("Delete"), 'delete', $_SERVER["PHP_SELF"].'?id='.$object->id.'&action=delete&token='.newToken(), 'delete', $permissiontodelete, $params);
423 }
424 print '</div>'."\n";
425 }
426
427
428 // Select mail models is same action as presend
429 if (GETPOST('modelselected')) {
430 $action = 'presend';
431 }
432
433 if ($action != 'presend') {
434 print '<div class="fichecenter"><div class="fichehalfleft">';
435 print '<a name="builddoc"></a>'; // ancre
436
437 print '</div><div class="fichehalfright">';
438
439 /*
440 $MAXEVENT = 10;
441
442 $morehtmlcenter = dolGetButtonTitle($langs->trans('SeeAll'), '', 'fa fa-bars imgforviewmode', dol_buildpath('/mymodule/myobject_agenda.php', 1).'?id='.$object->id);
443
444 // List of actions on element
445 include_once DOL_DOCUMENT_ROOT . '/core/class/html.formactions.class.php';
446 $formactions = new FormActions($db);
447 $somethingshown = $formactions->showactions($object, $object->element, $socid, 1, '', $MAXEVENT);
448 */
449
450 print '</div></div>';
451 }
452
453 // Presend form
454 $modelmail = 'websiteaccount';
455 $defaulttopic = 'Information';
456 $diroutput = isModEnabled('website') ? $conf->website->dir_output : '';
457 $trackid = 'websiteaccount'.$object->id;
458
459 include DOL_DOCUMENT_ROOT.'/core/tpl/card_presend.tpl.php';
460}
461
462// End of page
463llxFooter();
464$db->close();
$id
Definition account.php:48
if( $user->socid > 0) if(! $user->hasRight('accounting', 'chartofaccount')) $object
Definition card.php:66
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:71
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.
llxFooter()
Footer empty.
Definition document.php:107
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)
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.