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