website.php 23 KB

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