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