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