website.php 22 KB

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