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