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