website.php 23 KB

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