dolibarr 24.0.0-beta
website.php
Go to the documentation of this file.
1<?php
2/* Copyright (C) 2004-2017 Laurent Destailleur <eldy@users.sourceforge.net>
3 * Copyright (C) 2024-2026 Frédéric France <frederic.france@free.fr>
4 * Copyright (C) 2024-2026 MDW <mdeweerd@users.noreply.github.com>
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.formadmin.class.php';
29require_once DOL_DOCUMENT_ROOT.'/core/class/html.formcompany.class.php';
30require_once DOL_DOCUMENT_ROOT.'/core/lib/admin.lib.php';
31require_once DOL_DOCUMENT_ROOT.'/core/lib/files.lib.php';
32require_once DOL_DOCUMENT_ROOT.'/core/lib/website.lib.php';
33require_once DOL_DOCUMENT_ROOT.'/core/lib/functions2.lib.php';
34require_once DOL_DOCUMENT_ROOT.'/core/class/doleditor.class.php';
35require_once DOL_DOCUMENT_ROOT.'/website/class/website.class.php';
36
45// Load translation files required by the page
46$langs->loadlangs(array('errors', 'admin', 'companies', 'website'));
47
48$action = GETPOST('action', 'alpha') ? GETPOST('action', 'alpha') : 'view';
49$confirm = GETPOST('confirm', 'alpha');
50$backtopage = GETPOST('backtopage', 'alpha');
51
52$rowid = GETPOST('rowid', 'alpha');
53
54$id = 1;
55
56$acts = array();
57$acts[0] = "activate";
58$acts[1] = "disable";
59$actl = array();
60$actl[0] = img_picto($langs->trans("Disabled"), 'switch_off', 'class="size15x"');
61$actl[1] = img_picto($langs->trans("Activated"), 'switch_on', 'class="size15x"');
62
63// Load variable for pagination
64$limit = GETPOSTINT('limit') ? GETPOSTINT('limit') : $conf->liste_limit;
65$sortfield = GETPOST('sortfield', 'aZ09comma');
66$sortorder = GETPOST('sortorder', 'aZ09comma');
67$page = GETPOSTISSET('pageplusone') ? (GETPOSTINT('pageplusone') - 1) : GETPOSTINT("page");
68if (empty($page) || $page == -1) {
69 $page = 0;
70} // If $page is not defined, or '' or -1
71$offset = $limit * $page;
72$pageprev = $page - 1;
73$pagenext = $page + 1;
74
75if (empty($sortfield)) {
76 $sortfield = 'position, ref';
77}
78if (empty($sortorder)) {
79 $sortorder = 'ASC';
80}
81
82// Initialize a technical object to manage hooks of page. Note that conf->hooks_modules contains an array of hook context
83$hookmanager->initHooks(array('website'));
84
85// Name of SQL tables of dictionaries
86$tabname = array();
87$tabname[1] = MAIN_DB_PREFIX."website";
88
89// Dictionary labels
90$tablib = array();
91$tablib[1] = "Websites";
92
93// Requests to extract data
94$tabsql = array();
95$tabsql[1] = "SELECT f.rowid as rowid, f.entity, f.ref, f.description, f.virtualhost, f.position, f.status, f.date_creation, f.lastaccess, f.pageviews_previous_month, f.pageviews_total FROM ".MAIN_DB_PREFIX.'website as f WHERE f.entity IN ('.getEntity('website').')';
96
97// Criteria to sort dictionaries
98$tabsqlsort = array();
99$tabsqlsort[1] = "ref ASC";
100
101// Nom des champs en resultat de select pour affichage du dictionnaire
102$tabfield = array();
103$tabfield[1] = "ref,description,virtualhost,position,date_creation,lastaccess,pageviews_previous_month,pageviews_total";
104
105// Nom des champs d'edition pour modification d'un enregistrement
106$tabfieldvalue = array();
107$tabfieldvalue[1] = "ref,description,virtualhost,position,entity";
108
109// Nom des champs dans la table pour insertion d'un enregistrement
110$tabfieldinsert = array();
111$tabfieldinsert[1] = "ref,description,virtualhost,position,entity";
112
113// Nom du rowid si le champ n'est pas de type autoincrement
114// Example: "" if id field is "rowid" and has autoincrement on
115// "nameoffield" if id field is not "rowid" or has not autoincrement on
116$tabrowid = array();
117$tabrowid[1] = "";
118
119// Condition to show dictionary in setup page
120$tabcond = array();
121$tabcond[1] = (isModEnabled('website'));
122
123// List of help for fields
124$tabhelp = array();
125$tabhelp[1] = array('ref' => $langs->trans("EnterAnyCode"), 'virtualhost' => $langs->trans("SetHereVirtualHost", DOL_DATA_ROOT.($conf->entity > 1 ? '/'.$conf->entity : '').'/website/<i>websiteref</i>'));
126
127// List of check for fields (NOT USED YET)
128$tabfieldcheck = array();
129$tabfieldcheck[1] = array();
130
131
132// Define elementList and sourceList (used for dictionary type of contacts "llx_c_type_contact")
133$elementList = array();
134$sourceList = array();
135
136if (!$user->admin) {
138}
139
140
141/*
142 * Actions
143 */
144$error = 0;
145
146// Actions add or modify a website
147if (GETPOST('actionadd', 'alpha') || GETPOST('actionmodify', 'alpha')) {
148 $listfield = explode(',', $tabfield[$id]);
149 $listfieldinsert = explode(',', $tabfieldinsert[$id]);
150 $listfieldmodify = explode(',', $tabfieldinsert[$id]);
151 $listfieldvalue = explode(',', $tabfieldvalue[$id]);
152
153 // Check that all fields are filled
154 $ok = 1;
155 foreach ($listfield as $f => $value) {
156 if ($value == 'ref' && (!GETPOSTISSET($value) || GETPOST($value) == '')) {
157 $ok = 0;
158 $fieldnamekey = $listfield[$f];
159 setEventMessages($langs->transnoentities("ErrorFieldRequired", $langs->transnoentities($fieldnamekey)), null, 'errors');
160 break;
161 } elseif ($value == 'ref' && !preg_match('/^[a-z0-9_\-\.]+$/i', GETPOST($value))) {
162 $ok = 0;
163 $fieldnamekey = $listfield[$f];
164 setEventMessages($langs->transnoentities("ErrorFieldCanNotContainSpecialCharacters", $langs->transnoentities($fieldnamekey)), null, 'errors');
165 break;
166 }
167 }
168
169 // Clean parameters
170 if (GETPOST('ref')) {
171 $websitekey = strtolower(GETPOST('ref'));
172 }
173
174 $newid = 0;
175
176 // In case of 'actionadd' and with valid parameters, add the line
177 if ($ok && GETPOST('actionadd', 'alpha')) {
178 if ($tabrowid[$id]) {
179 // Get free id for insert
180 $sql = "SELECT MAX(".$db->sanitize($tabrowid[$id]).") newid FROM ".$db->sanitize($tabname[$id]);
181 $result = $db->query($sql);
182 if ($result) {
183 $obj = $db->fetch_object($result);
184 $newid = ($obj->newid + 1);
185 } else {
187 }
188 }
189
190 /* $website=new Website($db);
191 $website->ref=
192 $website->description=
193 $website->virtualhost=
194 $website->create($user); */
195
196 // Add new entry
197 $sql = "INSERT INTO ".$db->sanitize($tabname[$id])." (";
198 // List of fields
199 if ($tabrowid[$id] && !in_array($tabrowid[$id], $listfieldinsert)) {
200 $sql .= $db->sanitize($tabrowid[$id]).",";
201 }
202 $sql .= $tabfieldinsert[$id];
203 $sql .= ", status, date_creation)";
204 $sql .= " VALUES(";
205
206 // List of values
207 if ($tabrowid[$id] && !in_array($tabrowid[$id], $listfieldinsert)) {
208 $sql .= $newid.",";
209 }
210 $i = 0;
211 foreach ($listfieldinsert as $f => $value) {
212 if ($value == 'entity') {
213 $_POST[$listfieldvalue[$i]] = $conf->entity;
214 }
215 if ($value == 'ref') {
216 $_POST[$listfieldvalue[$i]] = strtolower(GETPOST($listfieldvalue[$i]));
217 }
218 if ($i) {
219 $sql .= ",";
220 }
221 if (GETPOST($listfieldvalue[$i]) == '') {
222 $sql .= "null";
223 } else {
224 $sql .= "'".$db->escape(GETPOST($listfieldvalue[$i]))."'";
225 }
226 $i++;
227 }
228 $sql .= ", 1, '".$db->idate(dol_now())."')";
229
230 dol_syslog("actionadd", LOG_DEBUG);
231 $result = $db->query($sql);
232 if ($result) { // Add is ok
233 setEventMessages($langs->transnoentities("RecordSaved"), null, 'mesgs');
234 unset($_POST); // Clean $_POST array, we keep only
235 } else {
236 if ($db->errno() == 'DB_ERROR_RECORD_ALREADY_EXISTS') {
237 setEventMessages($langs->transnoentities("ErrorRecordAlreadyExists"), null, 'errors');
238 } else {
240 }
241 }
242 }
243
244 // In case of 'actionmodify' and with valid parameters, modify the line
245 if ($ok && GETPOST('actionmodify', 'alpha')) {
246 if ($tabrowid[$id]) {
247 $rowidcol = $tabrowid[$id];
248 } else {
249 $rowidcol = "rowid";
250 }
251
252 $db->begin();
253
254 $website = new Website($db);
255 $rowid = GETPOSTINT('rowid');
256 $website->fetch($rowid);
257
258 // Modify entry
259 $sql = "UPDATE ".$db->sanitize($tabname[$id])." SET ";
260 // Modify the field values
261 if ($tabrowid[$id] && !in_array($tabrowid[$id], $listfieldmodify)) {
262 $sql .= $db->sanitize($tabrowid[$id])." = ";
263 $sql .= "'".$db->escape((string) $rowid)."', ";
264 }
265 $i = 0;
266 foreach ($listfieldmodify as $field) {
267 if ($field == 'entity') {
268 $_POST[$listfieldvalue[$i]] = $conf->entity;
269 }
270 if ($i) {
271 $sql .= ",";
272 }
273 $sql .= $field."=";
274 if (GETPOST($listfieldvalue[$i]) == '') {
275 $sql .= "null";
276 } else {
277 $sql .= "'".$db->escape(GETPOST($listfieldvalue[$i]))."'";
278 }
279 $i++;
280 }
281 $sql .= " WHERE ".$db->sanitize($rowidcol)." = ".((int) $rowid);
282
283 dol_syslog("actionmodify", LOG_DEBUG);
284 //print $sql;
285 $resql = $db->query($sql);
286 if ($resql) {
287 $newname = dol_sanitizeFileName(GETPOST('ref', 'aZ09'));
288 if ($newname != $website->ref) {
289 $srcfile = DOL_DATA_ROOT.($conf->entity > 1 ? '/'.$conf->entity : '').'/website/'.$website->ref;
290 $destfile = DOL_DATA_ROOT.($conf->entity > 1 ? '/'.$conf->entity : '').'/website/'.$newname;
291
292 if (dol_is_dir($destfile)) {
293 $error++;
294 setEventMessages($langs->trans('ErrorDirAlreadyExists', $destfile), null, 'errors');
295 } else {
296 @rename($srcfile, $destfile);
297
298 // We must now rename $website->ref into $newname inside files
299 $arrayreplacement = array($website->ref.'/htmlheader.html' => $newname.'/htmlheader.html');
300 $listofilestochange = dol_dir_list($destfile, 'files', 0, '\.php$');
301 foreach ($listofilestochange as $key => $value) {
302 dolReplaceInFile($value['fullname'], $arrayreplacement);
303 }
304 }
305 }
306 } else {
307 $error++;
308 setEventMessages($db->lasterror(), null, 'errors');
309 }
310
311 if (!$error) {
312 $db->commit();
313 } else {
314 $db->rollback();
315 }
316 }
317}
318
319if ($action == 'confirm_delete' && $confirm == 'yes') { // delete
320 if ($tabrowid[$id]) {
321 $rowidcol = $tabrowid[$id];
322 } else {
323 $rowidcol = "rowid";
324 }
325
326 $website = new Website($db);
327 $website->fetch($rowid);
328
329 if ($website->id > 0) {
330 $sql = "DELETE from ".MAIN_DB_PREFIX."website_account WHERE fk_website = ".((int) $rowid);
331 $result = $db->query($sql);
332
333 $sql = "DELETE from ".MAIN_DB_PREFIX."website_page WHERE fk_website = ".((int) $rowid);
334 $result = $db->query($sql);
335
336 $sql = "DELETE from ".MAIN_DB_PREFIX."website_extrafields WHERE fk_object = ".((int) $rowid);
337 $result = $db->query($sql);
338
339 $sql = "DELETE from ".MAIN_DB_PREFIX."website WHERE rowid = ".((int) $rowid);
340 $result = $db->query($sql);
341 if (!$result) {
342 if ($db->errno() == 'DB_ERROR_CHILD_EXISTS') {
343 setEventMessages($langs->transnoentities("ErrorRecordIsUsedByChild"), null, 'errors');
344 } else {
346 }
347 }
348
349 if ($website->ref) {
350 dol_delete_dir_recursive($conf->website->dir_output.'/'.$website->ref);
351 }
352 } else {
353 dol_print_error($db, 'Failed to load website with id '.$rowid);
354 }
355}
356
357// activate
358if ($action == $acts[0]) {
359 if ($tabrowid[$id]) {
360 $rowidcol = $tabrowid[$id];
361 } else {
362 $rowidcol = "rowid";
363 }
364
365 if ($rowid) {
366 $sql = "UPDATE ".$db->sanitize($tabname[$id])." SET status = 1 WHERE rowid = ".((int) $rowid);
367 } else {
368 $sql = null;
369 }
370
371 if ($sql !== null) {
372 $result = $db->query($sql);
373 if (!$result) {
375 }
376 } else {
377 dol_print_error(null, "No DB entry");
378 }
379}
380
381// disable
382if ($action == $acts[1]) {
383 if ($tabrowid[$id]) {
384 $rowidcol = $tabrowid[$id];
385 } else {
386 $rowidcol = "rowid";
387 }
388
389 if ($rowid) {
390 $sql = "UPDATE ".$db->sanitize($tabname[$id])." SET status = 0 WHERE rowid = ".((int) $rowid);
391 } else {
392 $sql = null;
393 }
394
395 if ($sql !== null) {
396 $result = $db->query($sql);
397 if (!$result) {
399 }
400 } else {
401 dol_print_error(null, "No DB entry");
402 }
403}
404
405
406
407/*
408 * View
409 */
410
411$form = new Form($db);
412$formadmin = new FormAdmin($db);
413
414llxHeader('', $langs->trans("WebsiteSetup"), '', '', 0, 0, '', '', '', 'mod-admin page-website');
415
416$titre = $langs->trans("WebsiteSetup");
417
418$linkback = '<a href="'.($backtopage ? $backtopage : DOL_URL_ROOT.'/admin/modules.php?restore_lastsearch_values=1').'">'.img_picto($langs->trans("BackToModuleList"), 'back', 'class="pictofixedwidth"').'<span class="hideonsmartphone">'.$langs->trans("BackToModuleList").'</span></a>';
419
420print load_fiche_titre($titre, $linkback, 'title_setup');
421
422// Onglets
423$head = array();
424$h = 0;
425
426$head[$h][0] = DOL_URL_ROOT."/admin/website.php";
427$head[$h][1] = $langs->trans("WebSites");
428$head[$h][2] = 'website';
429$h++;
430
431/* disable, no option for the moment
432$head[$h][0] = DOL_URL_ROOT."/admin/website_options.php";
433$head[$h][1] = $langs->trans("Options");
434$head[$h][2] = 'options';
435$h++;
436*/
437
438print dol_get_fiche_head($head, 'website', '', -1);
439
440
441print '<span class="opacitymedium">'.$langs->trans("WebsiteSetupDesc").'</span><br>';
442print "<br>\n";
443
444
445// Generate form to confirm line deletion
446if ($action == 'delete') {
447 print $form->formconfirm($_SERVER["PHP_SELF"].'?'.($page ? 'page='.$page.'&' : '').'sortfield='.$sortfield.'&sortorder='.$sortorder.'&rowid='.$rowid, $langs->trans('DeleteWebsite'), $langs->trans('ConfirmDeleteWebsite'), 'confirm_delete', '', 0, 1, 220);
448}
449//var_dump($elementList);
450
451/*
452 * Show website list
453 */
454if ($id) {
455 // Complete the request - lookup values with sort condition
456 $sql = $tabsql[$id];
457 $sql .= $db->order($sortfield, $sortorder);
458 $sql .= $db->plimit($limit + 1, $offset);
459 //print $sql;
460
461 $fieldlist = explode(',', $tabfield[$id]);
462
463 print '<form action="'.$_SERVER['PHP_SELF'].'" method="POST">';
464 print '<input type="hidden" name="token" value="'.newToken().'">';
465
466 print '<div class="div-table-responsive-no-min">';
467 print '<table class="noborder centpercent">';
468
469 // Form to add a new line
470 if ($tabname[$id]) {
471 // Line for title
472 print '<tr class="liste_titre">';
473 foreach ($fieldlist as $field => $value) {
474 if (in_array($fieldlist[$field], array('date_creation', 'lastaccess', 'pageviews_previous_month', 'pageviews_month', 'pageviews_total'))) {
475 continue;
476 }
477
478 // Get the field name based on the names available in the data dictionaries
479 $valuetoshow = ucfirst($fieldlist[$field]); // By default
480 $valuetoshow = $langs->trans($valuetoshow); // try to translate
481 $css = '';
482 if ($fieldlist[$field] == 'lang') {
483 $valuetoshow = $langs->trans("Language");
484 }
485 if ($valuetoshow != '') {
486 print '<td class="'.$css.'">';
487 if (!empty($tabhelp[$id][$value]) && preg_match('/^http(s*):/i', $tabhelp[$id][$value])) {
488 print '<a href="'.$tabhelp[$id][$value].'" target="_blank" rel="noopener noreferrer">'.$valuetoshow.' '.img_help(1, $valuetoshow).'</a>';
489 } elseif (!empty($tabhelp[$id][$value])) {
490 if ($value == 'virtualhost') {
491 print $form->textwithpicto($valuetoshow, $tabhelp[$id][$value], 1, 'help', '', 0, 2, 'tooltipvirtual');
492 } else {
493 print $form->textwithpicto($valuetoshow, $tabhelp[$id][$value]);
494 }
495 } else {
496 print $valuetoshow;
497 }
498 print '</td>';
499 }
500 }
501
502 print '<td colspan="4">';
503 print '</td>';
504 print '</tr>';
505
506 // Line to enter new values
507 print '<tr class="oddeven">';
508
509 $obj = new stdClass();
510 // If data was already input, we define them in obj to populate input fields.
511 if (GETPOST('actionadd', 'alpha')) {
512 foreach ($fieldlist as $key => $val) {
513 if (GETPOST($val, 'alpha')) {
514 $obj->$val = GETPOST($val);
515 }
516 }
517 }
518 if (!isset($obj->position)) {
519 $obj->position = 1;
520 }
521
522 fieldListWebsites($fieldlist, $obj, $tabname[$id], 'add');
523
524 print '<td colspan="3" class="right">';
525 if ($action != 'edit') {
526 print '<input type="submit" class="button button-add" name="actionadd" value="'.$langs->trans("Add").'">';
527 }
528 print '</td>';
529 print "</tr>";
530 }
531
532 print '</table>';
533 print '</div>';
534
535 print '</form>';
536
537
538 // List of websites in database
539 $resql = $db->query($sql);
540 if ($resql) {
541 $num = $db->num_rows($resql);
542 $i = 0;
543 if ($num) {
544 print '<br>';
545
546 print '<form action="'.$_SERVER['PHP_SELF'].'" method="POST">';
547 print '<input type="hidden" name="token" value="'.newToken().'">';
548 print '<input type="hidden" name="page" value="'.$page.'">';
549 print '<input type="hidden" name="rowid" value="'.$rowid.'">';
550
551 print '<div class="div-table-responsive">';
552 print '<table class="noborder centpercent">';
553
554 // Title of lines
555 print '<tr class="liste_titre">';
556 foreach ($fieldlist as $field => $value) {
557 // Determine the field name based on the possible names
558 // in the data dictionaries.
559 $showfield = 1; // By default
560 $align = "left";
561 $sortable = 1;
562 $valuetoshow = '';
563 if (in_array($fieldlist[$field], array('pageviews_total', 'pageviews_previous_month'))) {
564 $align = 'right';
565 }
566
567 /*
568 $tmparray=getLabelOfField($fieldlist[$field]);
569 $showfield=$tmp['showfield'];
570 $valuetoshow=$tmp['valuetoshow'];
571 $align=$tmp['align'];
572 $sortable=$tmp['sortable'];
573 */
574 $valuetoshow = ucfirst($fieldlist[$field]); // By default
575 $valuetoshow = $langs->trans($valuetoshow); // try to translate
576 if ($fieldlist[$field] == 'lang') {
577 $valuetoshow = $langs->trans("Language");
578 }
579 if ($fieldlist[$field] == 'type') {
580 $valuetoshow = $langs->trans("Type");
581 }
582 if ($fieldlist[$field] == 'code') {
583 $valuetoshow = $langs->trans("Code");
584 }
585 if ($fieldlist[$field] == 'date_creation') {
586 $valuetoshow = $langs->trans("DateCreation");
587 }
588 if ($fieldlist[$field] == 'lastaccess') {
589 $valuetoshow = $langs->trans("LastAccess");
590 }
591 if ($fieldlist[$field] == 'pageviews_previous_month') {
592 $valuetoshow = $langs->trans("PagesViewedPreviousMonth");
593 }
594 if ($fieldlist[$field] == 'pageviews_total') {
595 $valuetoshow = $langs->trans("PagesViewedTotal");
596 }
597
598 // Affiche nom du champ
599 if ($showfield) {
600 print getTitleFieldOfList($valuetoshow, 0, $_SERVER["PHP_SELF"], ($sortable ? $fieldlist[$field] : ''), ($page ? 'page='.$page.'&' : ''), "", '', $sortfield, $sortorder, $align.' ');
601 }
602 }
603
604 // Status
605 print getTitleFieldOfList($langs->trans("Status"), 0, $_SERVER["PHP_SELF"], "status", ($page ? 'page='.$page.'&' : ''), "", '', $sortfield, $sortorder, 'center ');
606 print getTitleFieldOfList('');
607 print getTitleFieldOfList('');
608 print '</tr>';
609
610 // Lines with values
611 while ($i < $num) {
612 $obj = $db->fetch_object($resql);
613 //print_r($obj);
614 print '<tr class="oddeven" id="rowid-'.$obj->rowid.'">';
615 if ($action == 'edit' && ($rowid == (!empty($obj->rowid) ? $obj->rowid : $obj->code))) {
616 $tmpaction = 'edit';
617 $parameters = array('fieldlist' => $fieldlist, 'tabname' => $tabname[$id]);
618 $reshook = $hookmanager->executeHooks('editWebsiteFieldlist', $parameters, $obj, $tmpaction); // Note that $action and $object may have been modified by some hooks
619 $error = $hookmanager->error;
620 $errors = $hookmanager->errors;
621
622 if (empty($reshook)) {
623 fieldListWebsites($fieldlist, $obj, $tabname[$id], 'edit');
624 }
625
626 print '<td colspan="7" class="right"><a name="'.(!empty($obj->rowid) ? $obj->rowid : $obj->code).'">&nbsp;</a>';
627 print '<input type="submit" class="button button-edit small" name="actionmodify" value="'.$langs->trans("Modify").'">';
628 print '&nbsp;';
629 print '<input type="submit" class="button button-cancel small" name="actioncancel" value="'.$langs->trans("Cancel").'">';
630 print '</td>';
631 } else {
632 $tmpaction = 'view';
633 $parameters = array('fieldlist' => $fieldlist, 'tabname' => $tabname[$id]);
634 $reshook = $hookmanager->executeHooks('viewWebsiteFieldlist', $parameters, $obj, $tmpaction); // Note that $action and $object may have been modified by some hooks
635
636 $error = $hookmanager->error;
637 $errors = $hookmanager->errors;
638
639 if (empty($reshook)) {
640 foreach ($fieldlist as $field => $value) {
641 $showfield = 1;
642 $fieldname = $fieldlist[$field];
643 $css = "";
644 if ($fieldlist[$field] == 'description') {
645 $css .= ' tdoverflowmax300';
646 }
647 if (in_array($fieldname, array('pageviews_total', 'pageviews_previous_month'))) {
648 $css = 'right';
649 }
650 if ($fieldlist[$field] == 'date_creation') {
651 $css .= ' nowraponall';
652 }
653 if ($fieldlist[$field] == 'lastaccess') {
654 $css .= ' nowraponall';
655 }
656 $valuetoshow = $obj->$fieldname;
657
658 // Show value for field
659 if ($showfield) {
660 print '<td class="'.$css.'">'.$valuetoshow.'</td>';
661 }
662 }
663 }
664
665 // Can an entry be erased or disabled ?
666 $iserasable = 1;
667 $isdisable = 1; // true by default
668 if ($obj->status) {
669 $iserasable = 0; // We can't delete a website on. Disable it first.
670 }
671
672 $url = $_SERVER["PHP_SELF"].'?'.($page ? 'page='.$page.'&' : '').'sortfield='.$sortfield.'&sortorder='.$sortorder.'&rowid='.(!empty($obj->rowid) ? $obj->rowid : (!empty($obj->code) ? $obj->code : '')).'&amp;code='.(!empty($obj->code) ? urlencode($obj->code) : '').'&amp;';
673
674
675 // Active
676 print '<td align="center" class="nowrap">';
677 print '<a class="reposition" href="'.$url.'action='.$acts[($obj->status ? 1 : 0)].'&token='.newToken().'">'.$actl[($obj->status ? 1 : 0)].'</a>';
678 print "</td>";
679
680 // Modify link
681 print '<td align="center"><a class="reposition editfielda" href="'.$url.'action=edit&token='.newToken().'">'.img_edit().'</a></td>';
682
683 // Delete link
684 if ($iserasable) {
685 print '<td align="center"><a class="reposition" href="'.$url.'action=delete&token='.newToken().'">'.img_delete().'</a></td>';
686 } else {
687 print '<td class="center">'.img_delete($langs->trans("DisableSiteFirst"), 'class="opacitymedium"').'</td>';
688 }
689
690 print "</tr>\n";
691 }
692 $i++;
693 }
694
695 print '</table>';
696 print '</div>';
697
698 print '</form>';
699 }
700 } else {
702 }
703}
704
705print dol_get_fiche_end();
706
707// End of page
708llxFooter();
709$db->close();
710
711
721function fieldListWebsites($fieldlist, $obj = null, $tabname = '', $context = '')
722{
723 global $conf, $langs, $db;
724 global $form;
725 global $region_id;
726 global $elementList, $sourceList, $localtax_typeList;
727 global $bc;
728
729 $formadmin = new FormAdmin($db);
730
731 foreach ($fieldlist as $field => $value) {
732 if (in_array($fieldlist[$field], array('lastaccess', 'pageviews_previous_month', 'pageviews_month', 'pageviews_total'))) {
733 continue;
734 }
735
736 $fieldname = $fieldlist[$field];
737
738 if ($fieldlist[$field] == 'lang') {
739 print '<td>';
740 print $formadmin->select_language(getDolGlobalString('MAIN_LANG_DEFAULT'), 'lang');
741 print '</td>';
742 } elseif ($fieldlist[$field] == 'code' && isset($obj->$fieldname)) {
743 print '<td><input type="text" class="flat" value="'.(!empty($obj->$fieldname) ? $obj->$fieldname : '').'" size="10" name="'.$fieldlist[$field].'"></td>';
744 } else {
745 if ($fieldlist[$field] == 'date_creation') {
746 continue;
747 }
748
749 print '<td>';
750 $size = '';
751 if ($fieldlist[$field] == 'code') {
752 $size = 'size="8" ';
753 }
754 if ($fieldlist[$field] == 'position') {
755 $size = 'size="4" ';
756 }
757 if ($fieldlist[$field] == 'libelle') {
758 $size = 'size="32" ';
759 }
760 if ($fieldlist[$field] == 'tracking') {
761 $size = 'size="92" ';
762 }
763 if ($fieldlist[$field] == 'sortorder') {
764 $size = 'size="2" ';
765 }
766 print '<input type="text" '.$size.' class="flat" value="'.(isset($obj->$fieldname) ? $obj->$fieldname : '').'" name="'.$fieldlist[$field].'">';
767 print '</td>';
768 }
769 }
770}
$id
Support class for third parties, contacts, members, users or resources.
Definition account.php:47
fieldListWebsites($fieldlist, $obj=null, $tabname='', $context='')
Show fields in insert/edit mode.
Definition website.php:721
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 generate html code for admin pages.
Class to manage generation of HTML components Only common components must be here.
Class Website.
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.
dol_delete_dir_recursive($dir, $count=0, $nophperrors=0, $onlysub=0, &$countdeleted=0, $indexdatabase=1, $nolog=0, $level=0)
Remove a directory $dir and its subdirectories (or only files and subdirectories)
dol_dir_list($utf8_path, $types="all", $recursive=0, $filter="", $excludefilter=null, $sortcriteria="name", $sortorder=SORT_ASC, $mode=0, $nohook=0, $relativename="", $donotfollowsymlinks=0, $nbsecondsold=0)
Scan a directory and return a list of files/directories.
Definition files.lib.php:64
dol_is_dir($folder)
Test if filename is a directory.
dolReplaceInFile($srcfile, $arrayreplacement, $destfile='', $newmask='0', $indexdatabase=0, $arrayreplacementisregex=0)
Make replacement of strings into a file.
dol_now($mode='gmt')
Return date for now.
setEventMessages($mesg, $mesgs, $style='mesgs', $messagekey='', $noduplicate=0, $attop=0)
Set event messages in dol_events session object.
img_help($usehelpcursor=1, $usealttitle=1)
Show help logo with cursor "?".
img_picto($titlealt, $picto, $moreatt='', $pictoisfullpath=0, $srconly=0, $notitle=0, $alt='', $morecss='', $marginleftonlyshort=2, $allowothertags=array())
Show picto whatever it's its name (generic function)
img_delete($titlealt='default', $other='class="pictodelete"', $morecss='')
Show delete logo.
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.
dol_sanitizeFileName($str, $newstr='_', $unaccent=1, $includequotes=0, $allowdash=0)
Clean a string to use it as a file name.
getTitleFieldOfList($name, $thead=0, $file="", $field="", $begin="", $moreparam="", $moreattrib="", $sortfield="", $sortorder="", $prefix="", $disablesortlink=0, $tooltip='', $forcenowrapcolumntitle=0)
Get title line of an array.
GETPOST($paramname, $check='alphanohtml', $method=0, $filter=null, $options=null, $noreplace=0)
Return value of a param into GET or POST supervariable.
dol_print_error($db=null, $error='', $errors=null)
Displays error message system with all the information to facilitate the diagnosis and the escalation...
load_fiche_titre($title, $morehtmlright='', $picto='generic', $pictoisfullpath=0, $id='', $morecssontable='', $morehtmlcenter='', $morecssonpicto='widthpictotitle')
Load a title with picto.
getDolGlobalString($key, $default='')
Return a Dolibarr global constant string value.
isModEnabled($module)
Is Dolibarr module enabled.
img_edit($titlealt='default', $float=0, $other='')
Show logo edit/modify fiche.
dol_syslog($message, $level=LOG_INFO, $ident=0, $suffixinfilename='', $restricttologhandler='', $logcontext=null)
Write log message into outputs.
getEntity($element, $shared=1, $currentobject=null)
Get list of entity id to use.
$context
@method int call_trigger(string $triggerName, ?User $user)
Definition logout.php:42
accessforbidden($message='', $printheader=1, $printfooter=1, $showonlymessage=0, $params=null)
Show a message to say access is forbidden and stop program.