index.php 26 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849
  1. <?php
  2. /* Copyright (C) 2016 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/website/index.php
  19. * \ingroup website
  20. * \brief Page to website view/edit
  21. */
  22. define('NOSCANPOSTFORINJECTION',1);
  23. define('NOSTYLECHECK',1);
  24. /**
  25. * Show HTML header HTML + BODY + Top menu + left menu + DIV
  26. *
  27. * @param string $head Optionnal head lines
  28. * @param string $title HTML title
  29. * @param string $help_url Url links to help page
  30. * Syntax is: For a wiki page: EN:EnglishPage|FR:FrenchPage|ES:SpanishPage
  31. * For other external page: http://server/url
  32. * @param string $target Target to use on links
  33. * @param int $disablejs More content into html header
  34. * @param int $disablehead More content into html header
  35. * @param array $arrayofjs Array of complementary js files
  36. * @param array $arrayofcss Array of complementary css files
  37. * @param string $morequerystring Query string to add to the link "print" to get same parameters (use only if autodetect fails)
  38. * @return void
  39. */
  40. function llxHeader($head='', $title='', $help_url='', $target='', $disablejs=0, $disablehead=0, $arrayofjs='', $arrayofcss='', $morequerystring='')
  41. {
  42. global $conf;
  43. // html header
  44. top_htmlhead($head, $title, $disablejs, $disablehead, $arrayofjs, $arrayofcss);
  45. // top menu and left menu area
  46. if (empty($conf->dol_hide_topmenu))
  47. {
  48. top_menu($head, $title, $target, $disablejs, $disablehead, $arrayofjs, $arrayofcss, $morequerystring, $help_url);
  49. }
  50. if (empty($conf->dol_hide_leftmenu))
  51. {
  52. left_menu('', $help_url, '', '', 1, $title, 1);
  53. }
  54. // main area
  55. //main_area($title);
  56. }
  57. require '../main.inc.php';
  58. require_once DOL_DOCUMENT_ROOT.'/core/lib/admin.lib.php';
  59. require_once DOL_DOCUMENT_ROOT.'/core/lib/files.lib.php';
  60. require_once DOL_DOCUMENT_ROOT.'/websites/class/website.class.php';
  61. require_once DOL_DOCUMENT_ROOT.'/websites/class/websitepage.class.php';
  62. $langs->load("admin");
  63. $langs->load("other");
  64. $langs->load("website");
  65. if (! $user->admin) accessforbidden();
  66. $conf->dol_hide_leftmenu = 1;
  67. $error=0;
  68. $website=GETPOST('website', 'alpha');
  69. $page=GETPOST('page', 'alpha');
  70. $pageid=GETPOST('pageid', 'int');
  71. $action=GETPOST('action','alpha');
  72. if (GETPOST('delete')) { $action='delete'; }
  73. if (GETPOST('preview')) $action='preview';
  74. if (GETPOST('create')) { $action='create'; }
  75. if (GETPOST('editmedia')) { $action='editmedia'; }
  76. if (GETPOST('editcss')) { $action='editcss'; }
  77. if (GETPOST('editmenu')) { $action='editmenu'; }
  78. if (GETPOST('setashome')) { $action='setashome'; }
  79. if (GETPOST('editmeta')) { $action='editmeta'; }
  80. if (GETPOST('editcontent')) { $action='editcontent'; }
  81. if (empty($action)) $action='preview';
  82. $object=new Website($db);
  83. $objectpage=new WebsitePage($db);
  84. $object->fetchAll(); // Init $object->records
  85. // If website not defined, we take first found
  86. if (empty($website))
  87. {
  88. foreach($object->records as $key => $valwebsite)
  89. {
  90. $website=$valwebsite->ref;
  91. break;
  92. }
  93. }
  94. if ($website)
  95. {
  96. $res = $object->fetch(0, $website);
  97. }
  98. if ($pageid < 0) $pageid = 0;
  99. if ($pageid > 0 && $action != 'add')
  100. {
  101. $res = $objectpage->fetch($pageid);
  102. }
  103. global $dolibarr_main_data_root;
  104. $pathofwebsite=$dolibarr_main_data_root.'/websites/'.$website;
  105. $filecss=$pathofwebsite.'/styles.css';
  106. $filetpl=$pathofwebsite.'/page'.$pageid.'.tpl.php';
  107. // Define $urlwithroot
  108. $urlwithouturlroot=preg_replace('/'.preg_quote(DOL_URL_ROOT,'/').'$/i','',trim($dolibarr_main_url_root));
  109. $urlwithroot=$urlwithouturlroot.DOL_URL_ROOT; // This is to use external domain name found into config file
  110. //$urlwithroot=DOL_MAIN_URL_ROOT; // This is to use same domain name than current
  111. /*
  112. * Actions
  113. */
  114. if (GETPOST('refreshsite')) $pageid=0; // If we change the site, we reset the pageid.
  115. // Add page
  116. if ($action == 'add')
  117. {
  118. $db->begin();
  119. $objectpage->fk_website = $object->id;
  120. $objectpage->title = GETPOST('WEBSITE_TITLE');
  121. $objectpage->pageurl = GETPOST('WEBSITE_PAGENAME');
  122. $objectpage->description = GETPOST('WEBSITE_DESCRIPTION');
  123. $objectpage->keywords = GETPOST('WEBSITE_KEYWORD');
  124. if (empty($objectpage->title))
  125. {
  126. setEventMessages($langs->trans("ErrorFieldRequired", $langs->transnoentitiesnoconv("WEBSITE_PAGENAME")), null, 'errors');
  127. $error++;
  128. }
  129. if (! $error)
  130. {
  131. $res = $objectpage->create($user);
  132. if ($res <= 0)
  133. {
  134. $error++;
  135. setEventMessages($objectpage->error, $objectpage->errors, 'errors');
  136. }
  137. }
  138. if (! $error)
  139. {
  140. $db->commit();
  141. setEventMessages($langs->trans("PageAdded", $objectpage->pageurl), null, 'mesgs');
  142. $action='';
  143. }
  144. else
  145. {
  146. $db->rollback();
  147. }
  148. }
  149. // Update page
  150. if ($action == 'update')
  151. {
  152. $db->begin();
  153. $res = $object->fetch(0, $website);
  154. $objectpage->fk_website = $object->id;
  155. $objectpage->pageurl = GETPOST('WEBSITE_PAGENAME');
  156. $res = $objectpage->fetch(0, $object->fk_website, $objectpage->pageurl);
  157. if ($res > 0)
  158. {
  159. $objectpage->title = GETPOST('WEBSITE_TITLE');
  160. $objectpage->description = GETPOST('WEBSITE_DESCRIPTION');
  161. $objectpage->keyword = GETPOST('WEBSITE_KEYWORD');
  162. $res = $objectpage->update($user);
  163. if (! $res > 0)
  164. {
  165. $error++;
  166. setEventMessages($objectpage->error, $objectpage->errors, 'errors');
  167. }
  168. if (! $error)
  169. {
  170. $db->commit();
  171. setEventMessages($langs->trans("SetupSaved"), null, 'mesgs');
  172. $action='';
  173. }
  174. else
  175. {
  176. $db->rollback();
  177. }
  178. }
  179. else
  180. {
  181. dol_print_error($db);
  182. }
  183. }
  184. // Update page
  185. if ($action == 'delete')
  186. {
  187. $db->begin();
  188. $res = $object->fetch(0, $website);
  189. $res = $objectpage->fetch($pageid, $object->fk_website);
  190. if ($res > 0)
  191. {
  192. $res = $objectpage->delete($user);
  193. if (! $res > 0)
  194. {
  195. $error++;
  196. setEventMessages($objectpage->error, $objectpage->errors, 'errors');
  197. }
  198. if (! $error)
  199. {
  200. $db->commit();
  201. setEventMessages($langs->trans("PageDeleted", $objectpage->pageurl, $website), null, 'mesgs');
  202. header("Location: ".$_SERVER["PHP_SELF"].'?website='.$website);
  203. exit;
  204. }
  205. else
  206. {
  207. $db->rollback();
  208. }
  209. }
  210. else
  211. {
  212. dol_print_error($db);
  213. }
  214. }
  215. // Update css
  216. if ($action == 'updatecss')
  217. {
  218. $db->begin();
  219. $res = $object->fetch(0, $website);
  220. /*
  221. $res = $object->update($user);
  222. if ($res > 0)
  223. {
  224. $db->commit();
  225. setEventMessages($langs->trans("SetupSaved"), null, 'mesgs');
  226. $action='';
  227. }
  228. else
  229. {
  230. $db->rollback();
  231. }*/
  232. $csscontent = GETPOST('WEBSITE_CSS_INLINE');
  233. dol_mkdir($pathofwebsite);
  234. file_put_contents($filecss, $csscontent);
  235. if (! empty($conf->global->MAIN_UMASK))
  236. @chmod($filecss, octdec($conf->global->MAIN_UMASK));
  237. $action='preview';
  238. }
  239. // Update page
  240. if ($action == 'setashome')
  241. {
  242. $db->begin();
  243. $object->fetch(0, $website);
  244. $object->fk_default_home = $pageid;
  245. $res = $object->update($user);
  246. if (! $res > 0)
  247. {
  248. $error++;
  249. setEventMessages($objectpage->error, $objectpage->errors, 'errors');
  250. }
  251. if (! $error)
  252. {
  253. $db->commit();
  254. setEventMessages($langs->trans("Saved"), null, 'mesgs');
  255. $action='preview';
  256. }
  257. else
  258. {
  259. $db->rollback();
  260. }
  261. }
  262. // Update page
  263. if ($action == 'updatemeta')
  264. {
  265. $db->begin();
  266. $object->fetch(0, $website);
  267. $objectpage->fk_website = $object->id;
  268. $res = $objectpage->fetch($pageid, $object->fk_website);
  269. if ($res > 0)
  270. {
  271. $objectpage->pageurl = GETPOST('WEBSITE_PAGENAME');
  272. $objectpage->title = GETPOST('WEBSITE_TITLE');
  273. $objectpage->description = GETPOST('WEBSITE_DESCRIPTION');
  274. $objectpage->keywords = GETPOST('WEBSITE_KEYWORDS');
  275. $res = $objectpage->update($user);
  276. if (! $res > 0)
  277. {
  278. $error++;
  279. setEventMessages($objectpage->error, $objectpage->errors, 'errors');
  280. }
  281. if (! $error)
  282. {
  283. $db->commit();
  284. setEventMessages($langs->trans("Saved"), null, 'mesgs');
  285. $action='preview';
  286. }
  287. else
  288. {
  289. $db->rollback();
  290. }
  291. }
  292. else
  293. {
  294. dol_print_error($db, 'Page not found');
  295. }
  296. }
  297. // Update page
  298. if ($action == 'updatecontent')
  299. {
  300. $db->begin();
  301. $object->fetch(0, $website);
  302. $objectpage->fk_website = $object->id;
  303. $res = $objectpage->fetch($pageid, $object->fk_website);
  304. if ($res > 0)
  305. {
  306. $objectpage->content = GETPOST('PAGE_CONTENT');
  307. // Clean data. We remove all the head section.
  308. $objectpage->content = preg_replace('/<head.*<\/head>/s', '', $objectpage->content);
  309. /* $objectpage->content = preg_replace('/<base\s+href=[\'"][^\'"]+[\'"]\s/?>/s', '', $objectpage->content); */
  310. $res = $objectpage->update($user);
  311. if (! $res > 0)
  312. {
  313. $error++;
  314. setEventMessages($objectpage->error, $objectpage->errors, 'errors');
  315. }
  316. if (! $error)
  317. {
  318. $db->commit();
  319. setEventMessages($langs->trans("Saved"), null, 'mesgs');
  320. dol_mkdir($pathofwebsite);
  321. dol_delete_file($filetpl);
  322. file_put_contents($filetpl, $objectpage->content);
  323. if (! empty($conf->global->MAIN_UMASK))
  324. @chmod($filetpl, octdec($conf->global->MAIN_UMASK));
  325. header("Location: ".$_SERVER["PHP_SELF"].'?website='.$website.'&pageid='.$pageid);
  326. exit;
  327. }
  328. else
  329. {
  330. $db->rollback();
  331. }
  332. }
  333. else
  334. {
  335. dol_print_error($db, 'Page not found');
  336. }
  337. }
  338. /*
  339. * View
  340. */
  341. $form = new Form($db);
  342. $help_url='';
  343. llxHeader('', $langs->trans("WebsiteSetup"), $help_url);
  344. print "\n".'<form action="'.$_SERVER["PHP_SELF"].'" method="POST">';
  345. print '<input type="hidden" name="token" value="'.$_SESSION['newtoken'].'">';
  346. if ($action == 'create')
  347. {
  348. print '<input type="hidden" name="action" value="add">';
  349. }
  350. if ($action == 'editcss')
  351. {
  352. print '<input type="hidden" name="action" value="updatecss">';
  353. }
  354. if ($action == 'editmenu')
  355. {
  356. print '<input type="hidden" name="action" value="updatemenu">';
  357. }
  358. if ($action == 'setashome')
  359. {
  360. print '<input type="hidden" name="action" value="updateashome">';
  361. }
  362. if ($action == 'editmeta')
  363. {
  364. print '<input type="hidden" name="action" value="updatemeta">';
  365. }
  366. if ($action == 'editcontent')
  367. {
  368. print '<input type="hidden" name="action" value="updatecontent">';
  369. }
  370. if ($action == 'edit')
  371. {
  372. print '<input type="hidden" name="action" value="update">';
  373. }
  374. // Add a margin under toolbar ?
  375. $style='';
  376. if ($action != 'preview' && $action != 'editcontent') $style=' margin-bottom: 5px;';
  377. print '<div class="centpercent websitebar">';
  378. if (count($object->records) > 0)
  379. {
  380. // ***** Part for web sites
  381. print '<div class="websiteselection">';
  382. print $langs->trans("Website").': ';
  383. print '</div>';
  384. // List of websites
  385. print '<div class="websiteselection">';
  386. $out='';
  387. $out.='<select name="website">';
  388. if (empty($object->records)) $out.='<option value="-1">&nbsp;</option>';
  389. // Loop on each sites
  390. $i=0;
  391. foreach($object->records as $key => $valwebsite)
  392. {
  393. if (empty($website)) $website=$valwebsite->ref;
  394. $out.='<option value="'.$valwebsite->ref.'"';
  395. if ($website == $valwebsite->ref) $out.=' selected'; // To preselect a value
  396. $out.='>';
  397. $out.=$valwebsite->ref;
  398. $out.='</option>';
  399. $i++;
  400. }
  401. $out.='</select>';
  402. print $out;
  403. print '<input type="submit" class="button" name="refreshsite" value="'.$langs->trans("Load").'">';
  404. if ($website)
  405. {
  406. $realurl=$urlwithroot.'/public/websites/index.php?website='.$website;
  407. $dataroot=DOL_DATA_ROOT.'/websites/'.$website;
  408. if (! empty($object->virtualhost)) $realurl=$object->virtualhost;
  409. // TODO If virtual url defined, we use it
  410. /*print ' - '.$langs->trans("RealURL").' ';
  411. print '<input type="text" name="realurl" value="'.$realurl.'"> ';
  412. print '<a href="'.DOL_URL_ROOT.'/public/websites/index.php?website='.$website.'" target="tab'.$website.'">'.$langs->trans("ViewSiteInNewTab").'</a>';*/
  413. print ' &nbsp; ';
  414. print $langs->trans("ViewWebsiteInProduction").': ';
  415. print '<input type="text" id="previewsiteurl" class="minwidth200imp" name="previewsite" value="'.$realurl.'">';
  416. //print '<input type="submit" class="button" name="previewwebsite" target="tab'.$website.'" value="'.$langs->trans("ViewSiteInNewTab").'">';
  417. $htmltext=$langs->trans("SetHereVirtualHost", $dataroot);
  418. print $form->textwithpicto('', $htmltext);
  419. print '<a class="button" id="previewsite" href="'.DOL_URL_ROOT.'/public/websites/index.php?website='.$website.'" target="tab'.$website.'">'.$langs->trans("ViewSiteInNewTab").'</a>';
  420. // Example : Adding jquery code
  421. if (! empty($conf->use_javascript_ajax))
  422. {
  423. print '<script type="text/javascript" language="javascript">
  424. jQuery(document).ready(function() {
  425. jQuery("#previewsite").click(function() {
  426. newurl=jQuery("#previewsiteurl").val();
  427. console.log("Open url "+newurl);
  428. /* Save url */
  429. jQuery.ajax({
  430. method: "POST",
  431. url: "'.DOL_URL_ROOT.'/core/ajax/saveinplace.php",
  432. data: {
  433. field: \'editval_virtualhost\',
  434. element: \'websites\',
  435. table_element: \'website\',
  436. fk_element: '.$object->id.',
  437. value: newurl,
  438. },
  439. context: document.body
  440. });
  441. $(this).attr("href",newurl);
  442. });
  443. });
  444. </script>';
  445. }
  446. }
  447. print '</div>';
  448. // Button for websites
  449. print '<div class="websitetools">';
  450. if ($action == 'preview')
  451. {
  452. $disabled='';
  453. if (empty($user->rights->websites->create)) $disabled=' disabled="disabled"';
  454. //print '<input type="submit" class="button"'.$disabled.' value="'.dol_escape_htmltag($langs->trans("MediaFiles")).'" name="editmedia">';
  455. print '<input type="submit" class="button"'.$disabled.' value="'.dol_escape_htmltag($langs->trans("EditCss")).'" name="editcss">';
  456. print '<input type="submit" class="button"'.$disabled.' value="'.dol_escape_htmltag($langs->trans("EditMenu")).'" name="editmenu">';
  457. print '<input type="submit"'.$disabled.' class="button" value="'.dol_escape_htmltag($langs->trans("AddPage")).'" name="create">';
  458. }
  459. if (in_array($action, array('editcss','editmenu','create')))
  460. {
  461. if ($action != 'preview') print '<input type="submit" class="button" value="'.dol_escape_htmltag($langs->trans("Cancel")).'" name="preview">';
  462. if (preg_match('/^create/',$action)) print '<input type="submit" class="button" value="'.dol_escape_htmltag($langs->trans("Save")).'" name="update">';
  463. if (preg_match('/^edit/',$action)) print '<input type="submit" class="button" value="'.dol_escape_htmltag($langs->trans("Save")).'" name="update">';
  464. }
  465. print '</div>';
  466. // ***** Part for pages
  467. if ($website)
  468. {
  469. print '</div>';
  470. $array=$objectpage->fetchAll($object->id);
  471. if (! is_array($array) && $array < 0) dol_print_error('', $objectpage->error, $objectpage->errors);
  472. $atleastonepage=(is_array($array) && count($array) > 0);
  473. print '<div class="centpercent websitebar"'.($style?' style="'.$style.'"':'').'">';
  474. print '<div class="websiteselection">';
  475. print $langs->trans("Page").': ';
  476. print '</div>';
  477. print '<div class="websiteselection">';
  478. $out='';
  479. $out.='<select name="pageid">';
  480. if ($atleastonepage)
  481. {
  482. if (empty($pageid) && $action != 'create') // Page id is not defined, we try to take one
  483. {
  484. $firstpageid=0;$homepageid=0;
  485. foreach($array as $key => $valpage)
  486. {
  487. if (empty($firstpageid)) $firstpageid=$valpage->id;
  488. if ($object->fk_default_home && $key == $object->fk_default_home) $homepageid=$valpage->id;
  489. }
  490. $pageid=$homepageid?$homepageid:$firstpageid; // We choose home page and if not defined yet, we take first page
  491. }
  492. foreach($array as $key => $valpage)
  493. {
  494. $out.='<option value="'.$key.'"';
  495. if ($pageid > 0 && $pageid == $key) $out.=' selected'; // To preselect a value
  496. $out.='>';
  497. $out.=$valpage->title;
  498. if ($object->fk_default_home && $key == $object->fk_default_home) $out.=' ('.$langs->trans("HomePage").')';
  499. $out.='</option>';
  500. }
  501. }
  502. else $out.='<option value="-1">&nbsp;</option>';
  503. $out.='</select>';
  504. print $out;
  505. print '<input type="submit" class="button" name="refreshpage" value="'.$langs->trans("Load").'"'.($atleastonepage?'':' disabled="disabled"').'>';
  506. print '<input type="submit" class="buttonDelete" name="delete" value="'.$langs->trans("Delete").'"'.($atleastonepage?'':' disabled="disabled"').'>';
  507. //print $form->selectarray('page', $array);
  508. if ($website && $pageid > 0)
  509. {
  510. print ' - '.$langs->trans("RealURL").' ';
  511. $realurl=$urlwithroot.'/public/websites/index.php?website='.$website.'&page='.$pageid;
  512. print '<input type="text" name="realurl" class="minwidth200imp" disabled="disabled" value="'.$realurl.'"> ';
  513. print '<a href="'.$realurl.'" class="button" target="tab'.$website.'">'.$langs->trans("ViewPageInNewTab").'</a>';
  514. //print '<input type="submit" class="button" name="previewpage" target="tab'.$website.'"value="'.$langs->trans("ViewPageInNewTab").'">';
  515. }
  516. print '</div>';
  517. print '<div class="websiteselection">';
  518. print '</div>';
  519. print '<div class="websitetools">';
  520. if ($action == 'preview')
  521. {
  522. $disabled='';
  523. if (empty($user->rights->websites->create)) $disabled=' disabled="disabled"';
  524. if ($pageid > 0)
  525. {
  526. if ($object->fk_default_home > 0 && $pageid == $object->fk_default_home) print '<input type="submit" class="button" disabled="disabled" value="'.dol_escape_htmltag($langs->trans("SetAsHomePage")).'" name="setashome">';
  527. else print '<input type="submit" class="button"'.$disabled.' value="'.dol_escape_htmltag($langs->trans("SetAsHomePage")).'" name="setashome">';
  528. print '<input type="submit" class="button"'.$disabled.' value="'.dol_escape_htmltag($langs->trans("EditPageMeta")).'" name="editmeta">';
  529. print '<input type="submit" class="button"'.$disabled.' value="'.dol_escape_htmltag($langs->trans("EditPageContent")).'" name="editcontent">';
  530. //print '<a href="'.$_SERVER["PHP_SELF"].'?action=editmeta&website='.urlencode($website).'&pageid='.urlencode($pageid).'" class="button">'.dol_escape_htmltag($langs->trans("EditPageMeta")).'</a>';
  531. //print '<a href="'.$_SERVER["PHP_SELF"].'?action=editcontent&website='.urlencode($website).'&pageid='.urlencode($pageid).'" class="button">'.dol_escape_htmltag($langs->trans("EditPageContent")).'</a>';
  532. }
  533. }
  534. if (! in_array($action, array('editcss','editmenu','create')))
  535. {
  536. if ($action != 'preview') print '<input type="submit" class="button" value="'.dol_escape_htmltag($langs->trans("Cancel")).'" name="preview">';
  537. if (preg_match('/^create/',$action)) print '<input type="submit" class="button" value="'.dol_escape_htmltag($langs->trans("Save")).'" name="update">';
  538. if (preg_match('/^edit/',$action)) print '<input type="submit" class="button" value="'.dol_escape_htmltag($langs->trans("Save")).'" name="update">';
  539. }
  540. print '</div>';
  541. }
  542. }
  543. else
  544. {
  545. print '<div class="websiteselection">';
  546. $langs->load("errors");
  547. print $langs->trans("ErrorModuleSetupNotComplete");
  548. print '<div>';
  549. $action='';
  550. }
  551. print '</div>';
  552. $head = array();
  553. /*
  554. * Edit mode
  555. */
  556. if ($action == 'editcss')
  557. {
  558. print '<div class="fiche">';
  559. print '<br>';
  560. $csscontent = @file_get_contents($filecss);
  561. dol_fiche_head();
  562. print '<table class="border" width="100%">';
  563. print '<tr><td>';
  564. print $langs->trans('WebSite');
  565. print '</td><td>';
  566. print $website;
  567. print '</td></tr>';
  568. print '<tr><td valign="top">';
  569. print $langs->trans('WEBSITE_CSS_INLINE');
  570. print '</td><td>';
  571. print '<textarea class="flat centpercent" rows="32" name="WEBSITE_CSS_INLINE">';
  572. print $csscontent;
  573. print '</textarea>';
  574. print '</td></tr>';
  575. /*print '<tr><td>';
  576. print $langs->trans('WEBSITE_CSS_URL');
  577. print '</td><td>';
  578. print '<input type="text" class="flat" size="96" name="WEBSITE_CSS_URL" value="'.dol_escape_htmltag($obj->WEBSITE_CSS_URL).'">';
  579. print '</td></tr>';*/
  580. print '</table>';
  581. dol_fiche_end();
  582. print '</div>';
  583. print '<br>';
  584. }
  585. if ($action == 'editmeta' || $action == 'create')
  586. {
  587. print '<div class="fiche">';
  588. print '<br>';
  589. dol_fiche_head();
  590. print '<table class="border" width="100%">';
  591. if ($action != 'create')
  592. {
  593. print '<tr><td>';
  594. print $langs->trans('WEBSITE_PAGEURL');
  595. print '</td><td>';
  596. print '/public/websites/index.php?website='.urlencode($website).'&pageid='.urlencode($pageid);
  597. print '</td></tr>';
  598. $pageurl=dol_escape_htmltag($objectpage->pageurl);
  599. $pagetitle=dol_escape_htmltag($objectpage->title);
  600. $pagedescription=dol_escape_htmltag($objectpage->description);
  601. $pagekeywords=dol_escape_htmltag($objectpage->keywords);
  602. }
  603. if (GETPOST('WEBSITE_PAGENAME')) $pageurl=GETPOST('WEBSITE_PAGENAME');
  604. if (GETPOST('WEBSITE_TITLE')) $pagetitle=GETPOST('WEBSITE_TITLE');
  605. if (GETPOST('WEBSITE_DESCRIPTION')) $pagedescription=GETPOST('WEBSITE_DESCRIPTION');
  606. if (GETPOST('WEBSITE_KEYWORDS')) $pagekeywords=GETPOST('WEBSITE_KEYWORDS');
  607. print '<tr><td>';
  608. print $langs->trans('WEBSITE_PAGENAME');
  609. print '</td><td>';
  610. print '<input type="text" class="flat" size="96" name="WEBSITE_PAGENAME" value="'.$pageurl.'">';
  611. print '</td></tr>';
  612. print '<tr><td>';
  613. print $langs->trans('WEBSITE_TITLE');
  614. print '</td><td>';
  615. print '<input type="text" class="flat" size="96" name="WEBSITE_TITLE" value="'.$pagetitle.'">';
  616. print '</td></tr>';
  617. print '<tr><td>';
  618. print $langs->trans('WEBSITE_DESCRIPTION');
  619. print '</td><td>';
  620. print '<input type="text" class="flat" size="96" name="WEBSITE_DESCRIPTION" value="'.$pagedescription.'">';
  621. print '</td></tr>';
  622. print '<tr><td>';
  623. print $langs->trans('WEBSITE_KEYWORDS');
  624. print '</td><td>';
  625. print '<input type="text" class="flat" size="128" name="WEBSITE_KEYWORDS" value="'.$pagekeywords.'">';
  626. print '</td></tr>';
  627. print '</table>';
  628. dol_fiche_end();
  629. print '</div>';
  630. print '<br>';
  631. }
  632. if ($action == 'editmedia')
  633. {
  634. print '<div class="center">'.$langs->trans("FeatureNotYetAvailable").'</center>';
  635. }
  636. if ($action == 'editmenu')
  637. {
  638. print '<div class="center">'.$langs->trans("FeatureNotYetAvailable").'</center>';
  639. }
  640. if ($action == 'editcontent')
  641. {
  642. /*
  643. * Editing global variables not related to a specific theme
  644. */
  645. require_once DOL_DOCUMENT_ROOT.'/core/class/doleditor.class.php';
  646. $doleditor=new DolEditor('PAGE_CONTENT',$objectpage->content,'',500,'Full','',true,true,true,5,60);
  647. $doleditor->Create();
  648. }
  649. print '</form>';
  650. if ($action == 'preview')
  651. {
  652. if ($pageid > 0)
  653. {
  654. $objectpage->fetch($pageid);
  655. print "\n".'<!-- Page content '.$filetpl.' c-->'."\n";
  656. $csscontent = @file_get_contents($filecss);
  657. $out='';
  658. $out.='<div id="websitecontent" class="websitecontent">'."\n";
  659. $out.='<style scoped>'."\n"; // "scoped" means "apply to parent element only". Not yet supported by browsers
  660. $out.=$csscontent;
  661. $out.='</style>'."\n";
  662. $out.=$objectpage->content."\n";
  663. $out.='</div>';
  664. print $out;
  665. /*file_put_contents($filetpl, $out);
  666. if (! empty($conf->global->MAIN_UMASK))
  667. @chmod($filetpl, octdec($conf->global->MAIN_UMASK));
  668. // Output file on browser
  669. dol_syslog("index.php include $filetpl $filename content-type=$type");
  670. $original_file_osencoded=dol_osencode($filetpl); // New file name encoded in OS encoding charset
  671. // This test if file exists should be useless. We keep it to find bug more easily
  672. if (! file_exists($original_file_osencoded))
  673. {
  674. dol_print_error(0,$langs->trans("ErrorFileDoesNotExists",$original_file));
  675. exit;
  676. }
  677. //include_once $original_file_osencoded;
  678. */
  679. /*print '<iframe class="websiteiframenoborder centpercent" src="'.DOL_URL_ROOT.'/public/websites/index.php?website='.$website.'&pageid='.$pageid.'"/>';
  680. print '</iframe>';*/
  681. }
  682. else
  683. {
  684. print '<br><br><div class="center">'.$langs->trans("PreviewOfSiteNotYetAvailable", $website).'</center><br><br><br>';
  685. print '<div class="center"><div class="logo_setup"></div></div>';
  686. }
  687. }
  688. llxFooter();
  689. $db->close();