dolibarr  16.0.5
index.php
Go to the documentation of this file.
1 <?php
2 /* Copyright (C) 2016-2020 Laurent Destailleur <eldy@users.sourceforge.net>
3  * Copyright (C) 2020 Nicolas ZABOURI <info@inovea-conseil.com>
4  *
5  * This program is free software; you can redistribute it and/or modify
6  * it under the terms of the GNU General Public License as published by
7  * the Free Software Foundation; either version 3 of the License, or
8  * (at your option) any later version.
9  *
10  * This program is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13  * GNU General Public License for more details.
14  *
15  * You should have received a copy of the GNU General Public License
16  * along with this program. If not, see <https://www.gnu.org/licenses/>.
17  */
18 
25 define('NOSCANPOSTFORINJECTION', 1);
26 define('NOSTYLECHECK', 1);
27 define('USEDOLIBARREDITOR', 1);
28 define('FORCE_CKEDITOR', 1); // We need CKEditor, even if module is off.
29 if (!defined('DISABLE_JS_GRAHP')) define('DISABLE_JS_GRAPH', 1);
30 
31 //header('X-XSS-Protection:0'); // Disable XSS filtering protection of some browsers (note: use of Content-Security-Policy is more efficient). Disabled as deprecated.
32 
33 require '../main.inc.php';
34 require_once DOL_DOCUMENT_ROOT.'/core/lib/admin.lib.php';
35 require_once DOL_DOCUMENT_ROOT.'/core/lib/files.lib.php';
36 require_once DOL_DOCUMENT_ROOT.'/core/lib/website.lib.php';
37 require_once DOL_DOCUMENT_ROOT.'/core/lib/website2.lib.php';
38 require_once DOL_DOCUMENT_ROOT.'/core/lib/images.lib.php';
39 require_once DOL_DOCUMENT_ROOT.'/core/class/doleditor.class.php';
40 require_once DOL_DOCUMENT_ROOT.'/core/class/html.formadmin.class.php';
41 require_once DOL_DOCUMENT_ROOT.'/core/class/html.formwebsite.class.php';
42 require_once DOL_DOCUMENT_ROOT.'/core/class/html.formother.class.php';
43 require_once DOL_DOCUMENT_ROOT.'/core/class/html.formfile.class.php';
44 require_once DOL_DOCUMENT_ROOT.'/website/class/website.class.php';
45 require_once DOL_DOCUMENT_ROOT.'/website/class/websitepage.class.php';
46 require_once DOL_DOCUMENT_ROOT.'/categories/class/categorie.class.php';
47 
48 $langs->loadLangs(array("admin", "other", "website", "errors"));
49 
50 if (!$user->rights->website->read) {
52 }
53 
54 $conf->dol_hide_leftmenu = 1; // Force hide of left menu.
55 
56 $error = 0;
57 $websiteid = GETPOST('websiteid', 'int');
58 $websitekey = GETPOST('website', 'alpha');
59 $page = GETPOST('page', 'alpha');
60 $pageid = GETPOST('pageid', 'int');
61 $pageref = GETPOST('pageref', 'alphanohtml');
62 
63 $action = GETPOST('action', 'aZ09');
64 $massaction = GETPOST('massaction', 'alpha'); // The bulk action (combo box choice into lists)
65 $confirm = GETPOST('confirm', 'alpha');
66 $cancel = GETPOST('cancel', 'alpha');
67 $toselect = GETPOST('toselect', 'array'); // Array of ids of elements selected into a list
68 $contextpage = GETPOST('contextpage', 'aZ') ?GETPOST('contextpage', 'aZ') : 'websitelist'; // To manage different context of search
69 $backtopage = GETPOST('backtopage', 'alpha'); // Go back to a dedicated page
70 $optioncss = GETPOST('optioncss', 'aZ'); // Option for the css output (always '' except when 'print')
71 $dol_hide_topmenu = GETPOST('dol_hide_topmenu', 'int');
72 $dol_hide_leftmenu = GETPOST('dol_hide_leftmenu', 'int');
73 $dol_openinpopup = GETPOST('dol_openinpopup', 'aZ09');
74 
75 $type_container = GETPOST('WEBSITE_TYPE_CONTAINER', 'alpha');
76 
77 $section_dir = GETPOST('section_dir', 'alpha');
78 $file_manager = GETPOST('file_manager', 'alpha');
79 $replacesite = GETPOST('replacesite', 'alpha');
80 
81 if (GETPOST('deletesite', 'alpha')) {
82  $action = 'deletesite';
83 }
84 if (GETPOST('delete', 'alpha')) {
85  $action = 'delete';
86 }
87 if (GETPOST('preview', 'alpha')) {
88  $action = 'preview';
89 }
90 if (GETPOST('createsite', 'alpha')) {
91  $action = 'createsite';
92 }
93 if (GETPOST('createcontainer', 'alpha')) {
94  $action = 'createcontainer';
95 }
96 if (GETPOST('editcss', 'alpha')) {
97  $action = 'editcss';
98 }
99 if (GETPOST('editmenu', 'alpha')) {
100  $action = 'editmenu';
101 }
102 if (GETPOST('setashome', 'alpha')) {
103  $action = 'setashome';
104 }
105 if (GETPOST('editmeta', 'alpha')) {
106  $action = 'editmeta';
107 }
108 if (GETPOST('editsource', 'alpha')) {
109  $action = 'editsource';
110 }
111 if (GETPOST('editcontent', 'alpha')) {
112  $action = 'editcontent';
113 }
114 if (GETPOST('exportsite', 'alpha')) {
115  $action = 'exportsite';
116 }
117 if (GETPOST('importsite', 'alpha')) {
118  $action = 'importsite';
119 }
120 if (GETPOST('createfromclone', 'alpha')) {
121  $action = 'createfromclone';
122 }
123 if (GETPOST('createpagefromclone', 'alpha')) {
124  $action = 'createpagefromclone';
125 }
126 if (empty($action) && $file_manager) {
127  $action = 'file_manager';
128 }
129 if (empty($action) && $replacesite) {
130  $action = 'replacesite';
131 }
132 if (GETPOST('refreshsite') || GETPOST('refreshsite_x') || GETPOST('refreshsite.x')) {
133  $pageid = 0;
134 }
135 
136 // Load variable for pagination
137 $limit = GETPOST('limit', 'int') ?GETPOST('limit', 'int') : $conf->liste_limit;
138 $sortfield = GETPOST('sortfield', 'aZ09comma');
139 $sortorder = GETPOST('sortorder', 'aZ09comma');
140 $page = GETPOSTISSET('pageplusone') ? (GETPOST('pageplusone') - 1) : GETPOST("page", 'int');
141 if (empty($page) || $page == -1) {
142  $page = 0;
143 } // If $page is not defined, or '' or -1
144 $offset = $limit * $page;
145 $pageprev = $page - 1;
146 $pagenext = $page + 1;
147 //if (! $sortfield) $sortfield='name';
148 //if (! $sortorder) $sortorder='ASC';
149 
150 if (empty($action)) {
151  $action = 'preview';
152 }
153 
154 $object = new Website($db);
155 $objectpage = new WebsitePage($db);
156 
157 $object->fetchAll('ASC', 'position'); // Init $object->records with list of websites
158 
159 // If website not defined, we take first found
160 if (!($websiteid > 0) && empty($websitekey) && $action != 'createsite') {
161  foreach ($object->records as $key => $valwebsite) {
162  $websitekey = $valwebsite->ref;
163  break;
164  }
165 }
166 if ($websiteid > 0 || $websitekey) {
167  $res = $object->fetch($websiteid, $websitekey);
168  $websitekey = $object->ref;
169 }
170 
171 $website = $object;
172 
173 // Check pageid received as parameter
174 if ($pageid < 0) {
175  $pageid = 0;
176 }
177 if (($pageid > 0 || $pageref) && $action != 'addcontainer') {
178  $res = $objectpage->fetch($pageid, ($object->id > 0 ? $object->id : null), $pageref);
179  if ($res == 0) {
180  $res = $objectpage->fetch($pageid, ($object->id > 0 ? $object->id : null), null, $pageref);
181  }
182 
183  // Check if pageid is inside the new website, if not we reset param pageid
184  if ($res >= 0 && $object->id > 0) {
185  if ($objectpage->fk_website != $object->id) { // We have a bad page that does not belong to web site
186  if ($object->fk_default_home > 0) {
187  $res = $objectpage->fetch($object->fk_default_home, $object->id, ''); // We search first page of web site
188  if ($res > 0) {
189  $pageid = $object->fk_default_home;
190  }
191  } else {
192  $res = $objectpage->fetch(0, $object->id, ''); // We search first page of web site
193  if ($res == 0) { // Page was not found, we reset it
194  $objectpage = new WebsitePage($db);
195  } else // We found a page, we set pageid to it.
196  {
197  $pageid = $objectpage->id;
198  }
199  }
200  } else // We have a valid page. We force pageid for the case we got the page with a fetch on ref.
201  {
202  $pageid = $objectpage->id;
203  }
204  }
205 }
206 
207 // Define pageid if pageid and pageref not received as parameter or was wrong
208 if (empty($pageid) && empty($pageref) && $object->id > 0 && $action != 'createcontainer') {
209  $pageid = $object->fk_default_home;
210  if (empty($pageid)) {
211  $array = $objectpage->fetchAll($object->id, 'ASC,ASC', 'type_container,pageurl');
212  if (!is_array($array) && $array < 0) {
213  dol_print_error('', $objectpage->error, $objectpage->errors);
214  }
215  $atleastonepage = (is_array($array) && count($array) > 0);
216 
217  $firstpageid = 0; $homepageid = 0;
218  foreach ($array as $key => $valpage) {
219  if (empty($firstpageid)) {
220  $firstpageid = $valpage->id;
221  }
222  if ($object->fk_default_home && $key == $object->fk_default_home) {
223  $homepageid = $valpage->id;
224  }
225  }
226  $pageid = ($homepageid ? $homepageid : $firstpageid); // We choose home page and if not defined yet, we take first page
227  }
228 }
229 
230 
231 global $dolibarr_main_data_root;
232 $pathofwebsite = $dolibarr_main_data_root.($conf->entity > 1 ? '/'.$conf->entity : '').'/website/'.$websitekey;
233 $filehtmlheader = $pathofwebsite.'/htmlheader.html';
234 $filecss = $pathofwebsite.'/styles.css.php';
235 $filejs = $pathofwebsite.'/javascript.js.php';
236 $filerobot = $pathofwebsite.'/robots.txt';
237 $filehtaccess = $pathofwebsite.'/.htaccess';
238 $filetpl = $pathofwebsite.'/page'.$pageid.'.tpl.php';
239 $fileindex = $pathofwebsite.'/index.php';
240 $filewrapper = $pathofwebsite.'/wrapper.php';
241 $filemanifestjson = $pathofwebsite.'/manifest.json.php';
242 $filereadme = $pathofwebsite.'/README.md';
243 $filemaster = $pathofwebsite.'/master.inc.php';
244 
245 // Define $urlwithroot
246 $urlwithouturlroot = preg_replace('/'.preg_quote(DOL_URL_ROOT, '/').'$/i', '', trim($dolibarr_main_url_root));
247 $urlwithroot = $urlwithouturlroot.DOL_URL_ROOT; // This is to use external domain name found into config file
248 //$urlwithroot=DOL_MAIN_URL_ROOT; // This is to use same domain name than current
249 
250 
251 $permtouploadfile = $user->rights->website->write;
252 $diroutput = $conf->medias->multidir_output[$conf->entity];
253 
254 $relativepath = $section_dir;
255 $upload_dir = preg_replace('/\/$/', '', $diroutput).'/'.preg_replace('/^\//', '', $relativepath);
256 
257 $htmlheadercontentdefault = '';
258 $htmlheadercontentdefault .= '<link rel="stylesheet" id="google-fonts-css" href="//fonts.googleapis.com/css?family=Open+Sans:300,400,700" />'."\n";
259 $htmlheadercontentdefault .= '<link rel="stylesheet" id="font-wasesome-css" href="//cdnjs.cloudflare.com/ajax/libs/font-awesome/4.7.0/css/font-awesome.min.css" />'."\n";
260 $htmlheadercontentdefault .= '<script src="//cdnjs.cloudflare.com/ajax/libs/jquery/3.2.1/jquery.min.js"></script>'."\n";
261 $htmlheadercontentdefault .= '<script src="//cdnjs.cloudflare.com/ajax/libs/jqueryui/1.12.1/jquery-ui.min.js"></script>'."\n";
262 $htmlheadercontentdefault .= '<script src="//cdnjs.cloudflare.com/ajax/libs/tether/1.4.0/js/tether.min.js"></script>'."\n";
263 $htmlheadercontentdefault .= '<script src="//cdnjs.cloudflare.com/ajax/libs/popper.js/1.13.0/umd/popper.min.js"></script>'."\n";
264 $htmlheadercontentdefault .= '<script src="//cdnjs.cloudflare.com/ajax/libs/twitter-bootstrap/4.0.0-beta.2/js/bootstrap.min.js"></script>'."\n";
265 $htmlheadercontentdefault .= '<!--'."\n";
266 $htmlheadercontentdefault .= '<script src="/document.php?modulepart=medias&file=css/myfile.css"></script>'."\n";
267 $htmlheadercontentdefault .= '<script src="/document.php?modulepart=medias&file=js/myfile.js"></script>'."\n";
268 $htmlheadercontentdefault .= '-->'."\n";
269 
270 $manifestjsoncontentdefault = '';
271 $manifestjsoncontentdefault .= '{
272  "name": "MyWebsite",
273  "short_name": "MyWebsite",
274  "start_url": "/",
275  "lang": "en-US",
276  "display": "standalone",
277  "background_color": "#fff",
278  "description": "A simple Web app.",
279  "icons": [{
280  "src": "images/'.urlencode($website->ref).'/homescreen48.png",
281  "sizes": "48x48",
282  "type": "image/png"
283  }, {
284  "src": "image/'.urlencode($website->ref).'/homescreen72.png",
285  "sizes": "72x72",
286  "type": "image/png"
287  }, {
288  "src": "image/'.urlencode($website->ref).'/homescreen96.png",
289  "sizes": "96x96",
290  "type": "image/png"
291  }, {
292  "src": "image/'.urlencode($website->ref).'/homescreen144.png",
293  "sizes": "144x144",
294  "type": "image/png"
295  }, {
296  "src": "image/'.urlencode($website->ref).'/homescreen168.png",
297  "sizes": "168x168",
298  "type": "image/png"
299  }, {
300  "src": "image/'.urlencode($website->ref).'/homescreen192.png",
301  "sizes": "192x192",
302  "type": "image/png"
303  }],
304  "related_applications": [{
305  "platform": "play",
306  "url": "https://play.google.com/store/apps/details?id=com.nltechno.dolidroidpro"
307  }]
308 }';
309 
310 $listofpages = array();
311 
312 $algo = '';
313 if (GETPOST('optionmeta')) {
314  $algo .= 'meta';
315 }
316 if (GETPOST('optioncontent')) {
317  $algo .= 'content';
318 }
319 if (GETPOST('optionsitefiles')) {
320  $algo .= 'sitefiles';
321 }
322 
323 if (empty($sortfield)) {
324  if ($action == 'file_manager') {
325  $sortfield = 'name'; $sortorder = 'ASC';
326  } else {
327  $sortfield = 'pageurl'; $sortorder = 'ASC';
328  }
329 }
330 
331 $searchkey = GETPOST('searchstring', 'restricthtml');
332 
333 if ($action == 'replacesiteconfirm') {
334  $containertype = GETPOST('optioncontainertype', 'aZ09') != '-1' ? GETPOST('optioncontainertype', 'aZ09') : '';
335  $langcode = GETPOST('optionlanguage', 'aZ09');
336  $otherfilters = array();
337  if (GETPOST('optioncategory', 'int') > 0) {
338  $otherfilters['category'] = GETPOST('optioncategory', 'int');
339  }
340 
341  $listofpages = getPagesFromSearchCriterias($containertype, $algo, $searchkey, 1000, $sortfield, $sortorder, $langcode, $otherfilters, -1);
342 }
343 
344 $usercanedit = $user->rights->website->write;
345 $permissiontoadd = $user->rights->website->write; // Used by the include of actions_addupdatedelete.inc.php and actions_linkedfiles
346 $permissiontodelete = $user->rights->website->delete;
347 
348 
349 /*
350  * Actions
351  */
352 
353 // Protections
354 if (GETPOST('refreshsite') || GETPOST('refreshsite_x') || GETPOST('refreshsite.x') || GETPOST('refreshpage') || GETPOST('refreshpage_x') || GETPOST('refreshpage.x')) {
355  $action = 'preview'; // To avoid to make an action on another page or another site when we click on button to select another site or page.
356 }
357 if (GETPOST('refreshsite', 'alpha') || GETPOST('refreshsite.x', 'alpha') || GETPOST('refreshsite_x', 'alpha')) { // If we change the site, we reset the pageid and cancel addsite action.
358  if ($action == 'addsite') {
359  $action = 'preview';
360  }
361  if ($action == 'updatesource') {
362  $action = 'preview';
363  }
364 
365  $pageid = $object->fk_default_home;
366  if (empty($pageid)) {
367  $array = $objectpage->fetchAll($object->id, 'ASC,ASC', 'type_container,pageurl');
368  if (!is_array($array) && $array < 0) {
369  dol_print_error('', $objectpage->error, $objectpage->errors);
370  }
371  $atleastonepage = (is_array($array) && count($array) > 0);
372 
373  $firstpageid = 0; $homepageid = 0;
374  foreach ($array as $key => $valpage) {
375  if (empty($firstpageid)) {
376  $firstpageid = $valpage->id;
377  }
378  if ($object->fk_default_home && $key == $object->fk_default_home) {
379  $homepageid = $valpage->id;
380  }
381  }
382  $pageid = ($homepageid ? $homepageid : $firstpageid); // We choose home page and if not defined yet, we take first page
383  }
384 }
385 if (GETPOST('refreshpage', 'alpha') && !in_array($action, array('updatecss'))) {
386  $action = 'preview';
387 }
388 
389 if ($cancel && $action == 'renamefile') {
390  $cancel = '';
391 }
392 
393 // Cancel
394 if ($cancel) {
395  $action = 'preview';
396  if ($backtopage) {
397  header("Location: ".$backtopage);
398  exit;
399  }
400 }
401 
402 $savbacktopage = $backtopage;
403 $backtopage = $_SERVER["PHP_SELF"].'?file_manager=1&website='.urlencode($websitekey).'&pageid='.urlencode($pageid).(GETPOST('section_dir', 'alpha') ? '&section_dir='.urlencode(GETPOST('section_dir', 'alpha')) : ''); // used after a confirm_deletefile into actions_linkedfiles.inc.php
404 if ($sortfield) {
405  $backtopage .= '&sortfield='.urlencode($sortfield);
406 }
407 if ($sortorder) {
408  $backtopage .= '&sortorder='.urlencode($sortorder);
409 }
410 include DOL_DOCUMENT_ROOT.'/core/actions_linkedfiles.inc.php'; // This manage 'sendit' action when submitting new file.
411 
412 $backtopage = $savbacktopage;
413 //var_dump($backtopage);
414 //var_dump($action);
415 
416 if ($action == 'renamefile') { // Must be after include DOL_DOCUMENT_ROOT.'/core/actions_linkedfiles.inc.php'; If action were renamefile, we set it to 'file_manager'
417  $action = 'file_manager';
418 }
419 
420 if ($action == 'seteditinline') {
421  dolibarr_set_const($db, 'WEBSITE_EDITINLINE', 1);
422  setEventMessages($langs->trans("FeatureNotYetAvailable"), null, 'warnings');
423  //dolibarr_set_const($db, 'WEBSITE_SUBCONTAINERSINLINE', 0); // Force disable of 'Include dynamic content'
424  header("Location: ".$_SERVER["PHP_SELF"].'?website='.GETPOST('website', 'alphanohtml').'&pageid='.GETPOST('pageid', 'int'));
425  exit;
426 }
427 if ($action == 'unseteditinline') {
428  dolibarr_del_const($db, 'WEBSITE_EDITINLINE');
429  header("Location: ".$_SERVER["PHP_SELF"].'?website='.GETPOST('website', 'alphanohtml').'&pageid='.GETPOST('pageid', 'int'));
430  exit;
431 }
432 if ($action == 'setshowsubcontainers') {
433  dolibarr_set_const($db, 'WEBSITE_SUBCONTAINERSINLINE', 1);
434  //dolibarr_set_const($db, 'WEBSITE_EDITINLINE', 0); // Force disable of edit inline
435  header("Location: ".$_SERVER["PHP_SELF"].'?website='.GETPOST('website', 'alphanohtml').'&pageid='.GETPOST('pageid', 'int'));
436  exit;
437 }
438 if ($action == 'unsetshowsubcontainers') {
439  dolibarr_del_const($db, 'WEBSITE_SUBCONTAINERSINLINE');
440  header("Location: ".$_SERVER["PHP_SELF"].'?website='.GETPOST('website', 'alphanohtml').'&pageid='.GETPOST('pageid', 'int'));
441  exit;
442 }
443 
444 if ($massaction == 'replace' && GETPOST('confirmmassaction', 'alpha') && !$searchkey) {
445  $action = 'replacesite';
446  $massaction = '';
447 }
448 
449 // Set category
450 if ($massaction == 'setcategory' && GETPOST('confirmmassaction', 'alpha') && $usercanedit) {
451  $error = 0;
452  $nbupdate = 0;
453 
454  $db->begin();
455 
456  $categoryid = GETPOST('setcategory', 'restricthtml');
457  if ($categoryid > 0) {
458  $tmpwebsitepage = new WebsitePage($db);
459  $category = new Categorie($db);
460  $category->fetch($categoryid);
461 
462  foreach ($toselect as $tmpid) {
463  $tmpwebsitepage->id = $tmpid;
464  $result = $category->add_type($tmpwebsitepage, 'website_page');
465  if ($result < 0 && $result != -3) {
466  $error++;
467  setEventMessages($category->error, $category->errors, 'errors');
468  break;
469  } else {
470  $nbupdate++;
471  }
472  }
473  }
474 
475  if ($error) {
476  $db->rollback();
477  } else {
478  if ($nbupdate) {
479  setEventMessages($langs->trans("RecordsModified", $nbupdate), null, 'mesgs');
480  }
481 
482  $db->commit();
483  }
484  // Now we reload list
485  $listofpages = getPagesFromSearchCriterias($containertype, $algo, $searchkey, 1000, $sortfield, $sortorder, $langcode, $otherfilters, -1);
486 }
487 
488 // Replacement of string into pages
489 if ($massaction == 'replace' && GETPOST('confirmmassaction', 'alpha') && $usercanedit) {
490  $replacestring = GETPOST('replacestring', 'none');
491 
492  if (empty($user->rights->website->writephp)) {
493  setEventMessages("NotAllowedToAddDynamicContent", null, 'errors');
494  } elseif (!$replacestring) {
495  setEventMessages("ErrorReplaceStringEmpty", null, 'errors');
496  } else {
497  $nbreplacement = 0;
498 
499  foreach ($toselect as $keyselected) {
500  $objectpage = $listofpages['list'][$keyselected];
501  if ($objectpage->pageurl) {
502  dol_syslog("Replace string into page ".$objectpage->pageurl);
503 
504  if (GETPOST('optioncontent', 'aZ09')) {
505  $objectpage->content = str_replace($searchkey, $replacestring, $objectpage->content);
506  }
507  if (GETPOST('optionmeta', 'aZ09')) {
508  $objectpage->title = str_replace($searchkey, $replacestring, $objectpage->title);
509  $objectpage->description = str_replace($searchkey, $replacestring, $objectpage->description);
510  $objectpage->keywords = str_replace($searchkey, $replacestring, $objectpage->keywords);
511  }
512 
513  $filealias = $pathofwebsite.'/'.$objectpage->pageurl.'.php';
514  $filetpl = $pathofwebsite.'/page'.$objectpage->id.'.tpl.php';
515 
516  // Save page alias
517  $result = dolSavePageAlias($filealias, $object, $objectpage);
518  if (!$result) {
519  setEventMessages('Failed to write file '.basename($filealias), null, 'errors');
520  }
521 
522  // Save page of content
523  $result = dolSavePageContent($filetpl, $object, $objectpage, 1);
524  if ($result) {
525  $nbreplacement++;
526  //var_dump($objectpage->content);exit;
527  $objectpage->update($user);
528  } else {
529  $error++;
530  setEventMessages('Failed to write file '.$filetpl, null, 'errors');
531  $action = 'createcontainer';
532  break;
533  }
534  }
535  }
536 
537  if ($nbreplacement > 0) {
538  setEventMessages($langs->trans("ReplacementDoneInXPages", $nbreplacement), null, 'mesgs');
539  }
540 
541  $containertype = GETPOST('optioncontainertype', 'aZ09') != '-1' ? GETPOST('optioncontainertype', 'aZ09') : '';
542  $langcode = GETPOST('optionlanguage', 'aZ09');
543  $otherfilters = array();
544  if (GETPOST('optioncategory', 'int') > 0) {
545  $otherfilters['category'] = GETPOST('optioncategory', 'int');
546  }
547 
548  // Now we reload list
549  $listofpages = getPagesFromSearchCriterias($containertype, $algo, $searchkey, 1000, $sortfield, $sortorder, $langcode, $otherfilters);
550  }
551 }
552 
553 
554 // Add directory
555 /*
556 if ($action == 'adddir' && $permtouploadfile)
557 {
558  $ecmdir->ref = 'NOTUSEDYET';
559  $ecmdir->label = GETPOST("label");
560  $ecmdir->description = GETPOST("desc");
561 
562  //$id = $ecmdir->create($user);
563  if ($id > 0)
564  {
565  header("Location: ".$_SERVER["PHP_SELF"]);
566  exit;
567  }
568  else
569  {
570  setEventMessages('Error '.$langs->trans($ecmdir->error), null, 'errors');
571  $action = "createcontainer";
572  }
573 
574  clearstatcache();
575 }
576 */
577 
578 // Add site
579 if ($action == 'addsite' && $usercanedit) {
580  $db->begin();
581 
582  if (GETPOST('virtualhost', 'alpha') && !preg_match('/^http/', GETPOST('virtualhost', 'alpha'))) {
583  $error++;
584  setEventMessages($langs->trans('ErrorURLMustStartWithHttp', $langs->transnoentitiesnoconv("VirtualHost")), null, 'errors');
585  }
586 
587  if (!$error && !GETPOST('WEBSITE_REF', 'alpha')) {
588  $error++;
589  $langs->load("errors");
590  setEventMessages($langs->transnoentities("ErrorFieldRequired", $langs->transnoentities("Ref")), null, 'errors');
591  }
592  if (!$error && !preg_match('/^[a-z0-9_\-\.]+$/i', GETPOST('WEBSITE_REF', 'alpha'))) {
593  $error++;
594  $langs->load("errors");
595  setEventMessages($langs->transnoentities("ErrorFieldCanNotContainSpecialCharacters", $langs->transnoentities("Ref")), null, 'errors');
596  }
597 
598  if (!$error) {
599  $arrayotherlang = explode(',', GETPOST('WEBSITE_OTHERLANG', 'alphanohtml'));
600  foreach ($arrayotherlang as $key => $val) {
601  // It possible we have empty val here if postparam WEBSITE_OTHERLANG is empty or set like this : 'en,,sv' or 'en,sv,'
602  if (empty(trim($val))) continue;
603  $arrayotherlang[$key] = substr(trim($val), 0, 2); // Kept short language code only
604  }
605 
606  $tmpobject = new Website($db);
607  $tmpobject->ref = GETPOST('WEBSITE_REF', 'alpha');
608  $tmpobject->description = GETPOST('WEBSITE_DESCRIPTION', 'alphanohtml');
609  $tmpobject->lang = GETPOST('WEBSITE_LANG', 'aZ09');
610  $tmpobject->otherlang = join(',', $arrayotherlang);
611  $tmpobject->virtualhost = GETPOST('virtualhost', 'alpha');
612 
613  $result = $tmpobject->create($user);
614  if ($result <= 0) {
615  $error++;
616  setEventMessages($tmpobject->error, $tmpobject->errors, 'errors');
617  }
618  }
619 
620  if (!$error) {
621  $db->commit();
622  setEventMessages($langs->trans("SiteAdded", $object->ref), null, 'mesgs');
623  $action = '';
624 
625  header("Location: ".$_SERVER["PHP_SELF"].'?website='.$tmpobject->ref);
626  exit;
627  } else {
628  $db->rollback();
629  $action = 'createsite';
630  }
631 
632  if (!$error) {
633  $action = 'preview';
634  $id = $object->id;
635  }
636 }
637 
638 // Add page/container
639 if ($action == 'addcontainer' && $usercanedit) {
640  dol_mkdir($pathofwebsite);
641 
642  $db->begin();
643 
644  $objectpage->fk_website = $object->id;
645 
646  if (GETPOSTISSET('fetchexternalurl')) { // Fetch from external url
647  $urltograb = GETPOST('externalurl', 'alpha');
648  $grabimages = GETPOST('grabimages', 'alpha');
649  $grabimagesinto = GETPOST('grabimagesinto', 'alpha');
650 
651  include_once DOL_DOCUMENT_ROOT.'/core/lib/geturl.lib.php';
652 
653  if (empty($urltograb)) {
654  $error++;
655  $langs->load("errors");
656  setEventMessages($langs->trans("ErrorFieldRequired", $langs->transnoentitiesnoconv("URL")), null, 'errors');
657  $action = 'createcontainer';
658  } elseif (!preg_match('/^http/', $urltograb)) {
659  $error++;
660  $langs->load("errors");
661  setEventMessages('Error URL must start with http:// or https://', null, 'errors');
662  $action = 'createcontainer';
663  }
664 
665  if (!$error) {
666  // Clean url to grab, so url can be
667  // http://www.example.com/ or http://www.example.com/dir1/ or http://www.example.com/dir1/aaa
668  $urltograbwithoutdomainandparam = preg_replace('/^https?:\/\/[^\/]+\/?/i', '', $urltograb);
669  //$urltograbwithoutdomainandparam = preg_replace('/^file:\/\/[^\/]+\/?/i', '', $urltograb);
670  $urltograbwithoutdomainandparam = preg_replace('/\?.*$/', '', $urltograbwithoutdomainandparam);
671  if (empty($urltograbwithoutdomainandparam) && !preg_match('/\/$/', $urltograb)) {
672  $urltograb .= '/';
673  }
674  $pageurl = dol_sanitizeFileName(preg_replace('/[\/\.]/', '-', preg_replace('/\/+$/', '', $urltograbwithoutdomainandparam)));
675 
676  $urltograbdirwithoutslash = dirname($urltograb.'.');
677  $urltograbdirrootwithoutslash = getRootURLFromURL($urltograbdirwithoutslash);
678  // Exemple, now $urltograbdirwithoutslash is https://www.dolimed.com/screenshots
679  // and $urltograbdirrootwithoutslash is https://www.dolimed.com
680  }
681 
682  // Check pageurl is not already used
683  if ($pageurl) {
684  $tmpwebsitepage = new WebsitePage($db);
685  $result = $tmpwebsitepage->fetch(0, $object->id, $pageurl);
686  if ($result > 0) {
687  setEventMessages($langs->trans("AliasPageAlreadyExists", $pageurl), null, 'errors');
688  $error++;
689  $action = 'createcontainer';
690  }
691  }
692 
693  if (!$error) {
694  $tmp = getURLContent($urltograb, 'GET', '', 1, array(), array('http', 'https'), 0);
695  if ($tmp['curl_error_no']) {
696  $error++;
697  setEventMessages('Error getting '.$urltograb.': '.$tmp['curl_error_msg'], null, 'errors');
698  $action = 'createcontainer';
699  } elseif ($tmp['http_code'] != '200') {
700  $error++;
701  setEventMessages('Error getting '.$urltograb.': '.$tmp['http_code'], null, 'errors');
702  $action = 'createcontainer';
703  } else {
704  // Remove comments
705  $tmp['content'] = removeHtmlComment($tmp['content']);
706 
707  $regs = array();
708 
709  preg_match('/<head>(.*)<\/head>/ims', $tmp['content'], $regs);
710  $head = $regs[1];
711 
712  $objectpage->type_container = 'page';
713  $objectpage->pageurl = $pageurl;
714  if (empty($objectpage->pageurl)) {
715  $tmpdomain = getDomainFromURL($urltograb);
716  $objectpage->pageurl = $tmpdomain.'-home';
717  }
718 
719  $objectpage->aliasalt = '';
720 
721  if (preg_match('/^(\d+)\-/', basename($urltograb), $regs)) {
722  $objectpage->aliasalt = $regs[1];
723  }
724 
725  $regtmp = array();
726  if (preg_match('/<title>(.*)<\/title>/ims', $head, $regtmp)) {
727  $objectpage->title = $regtmp[1];
728  }
729  if (preg_match('/<meta name="title"[^"]+content="([^"]+)"/ims', $head, $regtmp)) {
730  if (empty($objectpage->title)) {
731  $objectpage->title = $regtmp[1]; // If title not found into <title>, we get it from <meta title>
732  }
733  }
734  if (preg_match('/<meta name="description"[^"]+content="([^"]+)"/ims', $head, $regtmp)) {
735  $objectpage->description = $regtmp[1];
736  }
737  if (preg_match('/<meta name="keywords"[^"]+content="([^"]+)"/ims', $head, $regtmp)) {
738  $objectpage->keywords = $regtmp[1];
739  }
740  if (preg_match('/<html\s+lang="([^"]+)"/ims', $tmp['content'], $regtmp)) {
741  $tmplang = explode('-', $regtmp[1]);
742  $objectpage->lang = $tmplang[0].($tmplang[1] ? '_'.strtoupper($tmplang[1]) : '');
743  }
744 
745  $tmp['content'] = preg_replace('/\s*<meta name="generator"[^"]+content="([^"]+)"\s*\/?>/ims', '', $tmp['content']);
746 
747  $objectpage->content = $tmp['content'];
748  $objectpage->content = preg_replace('/^.*<body(\s[^>]*)*>/ims', '', $objectpage->content);
749  $objectpage->content = preg_replace('/<\/body(\s[^>]*)*>.*$/ims', '', $objectpage->content);
750 
751  $absoluteurlinaction = $urltograbdirwithoutslash;
752  // TODO Replace 'action="$urltograbdirwithoutslash' into action="/"
753  // TODO Replace 'action="$urltograbdirwithoutslash..."' into action="..."
754  // TODO Replace 'a href="$urltograbdirwithoutslash' into a href="/"
755  // TODO Replace 'a href="$urltograbdirwithoutslash..."' into a href="..."
756 
757  // Now loop to fetch all css files. Include them inline into header of page
758  $objectpage->htmlheader = $tmp['content'];
759  $objectpage->htmlheader = preg_replace('/^.*<head(\s[^>]*)*>/ims', '', $objectpage->htmlheader);
760  $objectpage->htmlheader = preg_replace('/<\/head(\s[^>]*)*>.*$/ims', '', $objectpage->htmlheader);
761  $objectpage->htmlheader = preg_replace('/<base(\s[^>]*)*>\n*/ims', '', $objectpage->htmlheader);
762  $objectpage->htmlheader = preg_replace('/<meta http-equiv="content-type"([^>]*)*>\n*/ims', '', $objectpage->htmlheader);
763  $objectpage->htmlheader = preg_replace('/<meta name="robots"([^>]*)*>\n*/ims', '', $objectpage->htmlheader);
764  $objectpage->htmlheader = preg_replace('/<meta name="title"([^>]*)*>\n*/ims', '', $objectpage->htmlheader);
765  $objectpage->htmlheader = preg_replace('/<meta name="description"([^>]*)*>\n*/ims', '', $objectpage->htmlheader);
766  $objectpage->htmlheader = preg_replace('/<meta name="keywords"([^>]*)*>\n*/ims', '', $objectpage->htmlheader);
767  $objectpage->htmlheader = preg_replace('/<meta name="generator"([^>]*)*>\n*/ims', '', $objectpage->htmlheader);
768  //$objectpage->htmlheader = preg_replace('/<meta name="verify-v1[^>]*>\n*/ims', '', $objectpage->htmlheader);
769  //$objectpage->htmlheader = preg_replace('/<meta name="msvalidate.01[^>]*>\n*/ims', '', $objectpage->htmlheader);
770  $objectpage->htmlheader = preg_replace('/<title>[^<]*<\/title>\n*/ims', '', $objectpage->htmlheader);
771  $objectpage->htmlheader = preg_replace('/<link[^>]*rel="shortcut[^>]*>\n/ims', '', $objectpage->htmlheader);
772  $objectpage->htmlheader = preg_replace('/<link[^>]*rel="alternate[^>]*>\n/ims', '', $objectpage->htmlheader);
773  $objectpage->htmlheader = preg_replace('/<link[^>]*rel="canonical[^>]*>\n/ims', '', $objectpage->htmlheader);
774 
775  // Now loop to fetch JS
776  $tmp = $objectpage->htmlheader;
777 
778  // We grab files found into <script> tags
779  preg_match_all('/<script([^\.>]+)src=["\']([^"\'>]+)["\']([^>]*)><\/script>/i', $objectpage->htmlheader, $regs);
780  $errorforsubresource = 0;
781  foreach ($regs[0] as $key => $val) {
782  dol_syslog("We will grab the script resource found into script tag ".$regs[2][$key]);
783 
784  $linkwithoutdomain = $regs[2][$key];
785  if (preg_match('/^\//', $regs[2][$key])) {
786  $urltograbbis = $urltograbdirrootwithoutslash.$regs[2][$key]; // We use dirroot
787  } else {
788  $urltograbbis = $urltograbdirwithoutslash.'/'.$regs[2][$key]; // We use dir of grabbed file
789  }
790 
791  //$filetosave = $conf->medias->multidir_output[$conf->entity].'/css/'.$object->ref.'/'.$objectpage->pageurl.(preg_match('/^\//', $regs[2][$key])?'':'/').$regs[2][$key];
792  if (preg_match('/^http/', $regs[2][$key])) {
793  $urltograbbis = $regs[2][$key];
794  $linkwithoutdomain = preg_replace('/^https?:\/\/[^\/]+\//i', '', $regs[2][$key]);
795  //$filetosave = $conf->medias->multidir_output[$conf->entity].'/css/'.$object->ref.'/'.$objectpage->pageurl.(preg_match('/^\//', $linkwithoutdomain)?'':'/').$linkwithoutdomain;
796  }
797 
798  //print $domaintograb.' - '.$domaintograbbis.' - '.$urltograbdirwithoutslash.' - ';
799  //print $linkwithoutdomain.' - '.$urltograbbis."<br>\n";
800 
801  // Test if this is an external URL of grabbed web site. If yes, we do not load resource
802  $domaintograb = getDomainFromURL($urltograbdirwithoutslash);
803  $domaintograbbis = getDomainFromURL($urltograbbis);
804  if ($domaintograb != $domaintograbbis) {
805  continue;
806  }
807 
808  /*
809  $tmpgeturl = getURLContent($urltograbbis, 'GET', '', 1, array(), array('http', 'https'), 0);
810  if ($tmpgeturl['curl_error_no'])
811  {
812  $error++;
813  setEventMessages('Error getting script url '.$urltograbbis.': '.$tmpgeturl['curl_error_msg'], null, 'errors');
814  $errorforsubresource++;
815  $action='createcontainer';
816  }
817  elseif ($tmpgeturl['http_code'] != '200')
818  {
819  $error++;
820  setEventMessages('Error getting script url '.$urltograbbis.': '.$tmpgeturl['http_code'], null, 'errors');
821  $errorforsubresource++;
822  $action='createcontainer';
823  }
824  else
825  {
826  dol_mkdir(dirname($filetosave));
827 
828  $fp = fopen($filetosave, "w");
829  fputs($fp, $tmpgeturl['content']);
830  fclose($fp);
831  if (! empty($conf->global->MAIN_UMASK))
832  @chmod($file, octdec($conf->global->MAIN_UMASK));
833  }
834  */
835 
836  //$filename = 'image/'.$object->ref.'/'.$objectpage->pageurl.(preg_match('/^\//', $linkwithoutdomain)?'':'/').$linkwithoutdomain;
837  $tmp = preg_replace('/'.preg_quote($regs[0][$key], '/').'/i', '', $tmp);
838  }
839  $objectpage->htmlheader = trim($tmp)."\n";
840 
841 
842  // Now we grab CSS found into <link> tags
843  $pagecsscontent = "\n".'<style>'."\n";
844 
845  preg_match_all('/<link([^\.>]+)href=["\']([^"\'>]+\.css[^"\'>]*)["\']([^>]*)>/i', $objectpage->htmlheader, $regs);
846  $errorforsubresource = 0;
847  foreach ($regs[0] as $key => $val) {
848  dol_syslog("We will grab the css resources found into link tag ".$regs[2][$key]);
849 
850  $linkwithoutdomain = $regs[2][$key];
851  if (preg_match('/^\//', $regs[2][$key])) {
852  $urltograbbis = $urltograbdirrootwithoutslash.$regs[2][$key]; // We use dirroot
853  } else {
854  $urltograbbis = $urltograbdirwithoutslash.'/'.$regs[2][$key]; // We use dir of grabbed file
855  }
856 
857  //$filetosave = $conf->medias->multidir_output[$conf->entity].'/css/'.$object->ref.'/'.$objectpage->pageurl.(preg_match('/^\//', $regs[2][$key])?'':'/').$regs[2][$key];
858  if (preg_match('/^http/', $regs[2][$key])) {
859  $urltograbbis = $regs[2][$key];
860  $linkwithoutdomain = preg_replace('/^https?:\/\/[^\/]+\//i', '', $regs[2][$key]);
861  //$filetosave = $conf->medias->multidir_output[$conf->entity].'/css/'.$object->ref.'/'.$objectpage->pageurl.(preg_match('/^\//', $linkwithoutdomain)?'':'/').$linkwithoutdomain;
862  }
863 
864  //print $domaintograb.' - '.$domaintograbbis.' - '.$urltograbdirwithoutslash.' - ';
865  //print $linkwithoutdomain.' - '.$urltograbbis."<br>\n";
866 
867  // Test if this is an external URL of grabbed web site. If yes, we do not load resource
868  $domaintograb = getDomainFromURL($urltograbdirwithoutslash);
869  $domaintograbbis = getDomainFromURL($urltograbbis);
870  if ($domaintograb != $domaintograbbis) {
871  continue;
872  }
873 
874  $tmpgeturl = getURLContent($urltograbbis, 'GET', '', 1, array(), array('http', 'https'), 0);
875  if ($tmpgeturl['curl_error_no']) {
876  $errorforsubresource++;
877  setEventMessages('Error getting link tag url '.$urltograbbis.': '.$tmpgeturl['curl_error_msg'], null, 'errors');
878  dol_syslog('Error getting '.$urltograbbis.': '.$tmpgeturl['curl_error_msg']);
879  $action = 'createcontainer';
880  } elseif ($tmpgeturl['http_code'] != '200') {
881  $errorforsubresource++;
882  setEventMessages('Error getting link tag url '.$urltograbbis.': '.$tmpgeturl['http_code'], null, 'errors');
883  dol_syslog('Error getting '.$urltograbbis.': '.$tmpgeturl['curl_error_msg']);
884  $action = 'createcontainer';
885  } else {
886  // Clean some comment
887  //$tmpgeturl['content'] = dol_string_is_good_iso($tmpgeturl['content'], 1);
888  //$tmpgeturl['content'] = mb_convert_encoding($tmpgeturl['content'], 'UTF-8', 'UTF-8');
889  //$tmpgeturl['content'] = remove_bs($tmpgeturl['content']);
890  //$tmpgeturl['content'] = str_replace('$screen-md-max', 'auto', $tmpgeturl['content']);
891 
892  //var_dump($tmpgeturl['content']);exit;
893  $tmpgeturl['content'] = preg_replace('/\/\*\s+CSS content[a-z\s]*\s+\*\//', '', $tmpgeturl['content']);
894 
895  //dol_mkdir(dirname($filetosave));
896 
897  //$fp = fopen($filetosave, "w");
898  //fputs($fp, $tmpgeturl['content']);
899  //fclose($fp);
900  //if (! empty($conf->global->MAIN_UMASK))
901  // @chmod($file, octdec($conf->global->MAIN_UMASK));
902 
903  // $filename = 'image/'.$object->ref.'/'.$objectpage->pageurl.(preg_match('/^\//', $linkwithoutdomain)?'':'/').$linkwithoutdomain;
904  $pagecsscontent .= '/* Content of file '.$urltograbbis.' */'."\n";
905 
906  getAllImages($object, $objectpage, $urltograbbis, $tmpgeturl['content'], $action, 1, $grabimages, $grabimagesinto);
907 
908  // We try to convert the CSS we got by adding a prefix .bodywebsite with lessc to avoid conflicit with CSS of Dolibarr.
909  include_once DOL_DOCUMENT_ROOT.'/core/class/lessc.class.php';
910  $lesscobj = new Lessc();
911  try {
912  $contentforlessc = ".bodywebsite {\n".$tmpgeturl['content']."\n}\n";
913  //print '<pre>'.$contentforlessc.'</pre>';
914  $contentforlessc = $lesscobj->compile($contentforlessc);
915  //var_dump($contentforlessc); exit;
916 
917  $pagecsscontent .= $contentforlessc."\n";
918  //$pagecsscontent.=$tmpgeturl['content']."\n";
919  } catch (exception $e) {
920  //echo "failed to compile lessc";
921  dol_syslog("Failed to compile the CSS from URL ".$urltograbbis." with lessc: ".$e->getMessage(), LOG_WARNING);
922  $pagecsscontent .= $tmpgeturl['content']."\n";
923  }
924 
925  $objectpage->htmlheader = preg_replace('/'.preg_quote($regs[0][$key], '/').'\n*/ims', '', $objectpage->htmlheader);
926  }
927  }
928 
929  $pagecsscontent .= '</style>';
930  //var_dump($pagecsscontent);
931 
932  //print dol_escape_htmltag($tmp);exit;
933  $objectpage->htmlheader .= trim($pagecsscontent)."\n";
934 
935 
936  // Now we have to fetch all images into page
937  $tmp = $objectpage->content;
938 
939  getAllImages($object, $objectpage, $urltograb, $tmp, $action, 1, $grabimages, $grabimagesinto);
940 
941  // Normalize links href to Dolibarr internal naming
942  $tmp = preg_replace('/a href="\/([^\/"]+)\/([^\/"]+)"/', 'a href="/\1-\2.php"', $tmp);
943  $tmp = preg_replace('/a href="\/([^\/"]+)\/([^\/"]+)\/([^\/"]+)"/', 'a href="/\1-\2-\3.php"', $tmp);
944  $tmp = preg_replace('/a href="\/([^\/"]+)\/([^\/"]+)\/([^\/"]+)\/([^\/"]+)"/', 'a href="/\1-\2-\3-\4.php"', $tmp);
945 
946  //print dol_escape_htmltag($tmp);exit;
947  $objectpage->content = $tmp;
948 
949  $objectpage->grabbed_from = $urltograb;
950  }
951  }
952  } else {
953  $newaliasnames = '';
954  if (!$error && GETPOST('WEBSITE_ALIASALT', 'alpha')) {
955  $arrayofaliastotest = explode(',', str_replace(array('<', '>'), '', GETPOST('WEBSITE_ALIASALT', 'alpha')));
956  $websitepagetemp = new WebsitePage($db);
957  foreach ($arrayofaliastotest as $aliastotest) {
958  $aliastotest = trim(preg_replace('/\.php$/i', '', $aliastotest));
959 
960  // Disallow alias name pageX (already used to save the page with id)
961  if (preg_match('/^page\d+/i', $aliastotest)) {
962  $error++;
963  $langs->load("errors");
964  setEventMessages("Alias name 'pageX' is not allowed", null, 'errors');
965  $action = 'createcontainer';
966  break;
967  } else {
968  $result = $websitepagetemp->fetch(0, $object->id, $aliastotest);
969  if ($result < 0) {
970  $error++;
971  $langs->load("errors");
972  setEventMessages($websitepagetemp->error, $websitepagetemp->errors, 'errors');
973  $action = 'createcontainer';
974  break;
975  }
976  if ($result > 0) {
977  $error++;
978  $langs->load("errors");
979  setEventMessages($langs->trans("ErrorAPageWithThisNameOrAliasAlreadyExists", $websitepagetemp->pageurl), null, 'errors');
980  $action = 'createcontainer';
981  break;
982  }
983  $newaliasnames .= ($newaliasnames ? ', ' : '').$aliastotest;
984  }
985  }
986  }
987 
988  $objectpage->title = str_replace(array('<', '>'), '', GETPOST('WEBSITE_TITLE', 'alphanohtml'));
989  $objectpage->type_container = GETPOST('WEBSITE_TYPE_CONTAINER', 'aZ09');
990  $objectpage->pageurl = GETPOST('WEBSITE_PAGENAME', 'alpha');
991  $objectpage->aliasalt = $newaliasnames;
992  $objectpage->description = str_replace(array('<', '>'), '', GETPOST('WEBSITE_DESCRIPTION', 'alphanohtml'));
993  $objectpage->lang = GETPOST('WEBSITE_LANG', 'aZ09');
994  $objectpage->otherlang = GETPOST('WEBSITE_OTHERLANG', 'aZ09comma');
995  $objectpage->image = GETPOST('WEBSITE_IMAGE', 'alpha');
996  $objectpage->keywords = str_replace(array('<', '>'), '', GETPOST('WEBSITE_KEYWORDS', 'alphanohtml'));
997  $objectpage->allowed_in_frames = GETPOST('WEBSITE_ALLOWED_IN_FRAMES', 'aZ09');
998  $objectpage->htmlheader = GETPOST('htmlheader', 'none');
999  $objectpage->author_alias = GETPOST('WEBSITE_AUTHORALIAS', 'alphanohtml');
1000  $objectpage->object_type = GETPOST('WEBSITE_OBJECTCLASS');
1001  $objectpage->fk_object = GETPOST('WEBSITE_OBJECTID');
1002  $substitutionarray = array();
1003  $substitutionarray['__WEBSITE_CREATE_BY__'] = $user->getFullName($langs);
1004 
1005  // Define id of page the new page is translation of
1006  $pageidfortranslation = (GETPOST('pageidfortranslation', 'int') > 0 ? GETPOST('pageidfortranslation', 'int') : 0);
1007  if ($pageidfortranslation > 0) {
1008  // Check if the page we are translation of is alreayd a translation of a source page. if yes, we will use source id instead
1009  $objectpagetmp = new WebsitePage($db);
1010  $objectpagetmp->fetch($pageidfortranslation);
1011  if ($objectpagetmp->fk_page > 0) {
1012  $pageidfortranslation = $objectpagetmp->fk_page;
1013  }
1014  }
1015  $objectpage->fk_page = $pageidfortranslation;
1016 
1017  $sample = GETPOST('sample', 'alpha');
1018  if (empty($sample)) {
1019  $sample = 'empty';
1020  }
1021 
1022  $pathtosample = DOL_DOCUMENT_ROOT.'/website/samples/page-sample-'.dol_sanitizeFileName($sample).'.html';
1023 
1024  // Init content with content into pagetemplate.html, blogposttempltate.html, ...
1025  $objectpage->content = make_substitutions(@file_get_contents($pathtosample), $substitutionarray);
1026  }
1027 
1028  if (!$error) {
1029  if (empty($objectpage->pageurl)) {
1030  $langs->load("errors");
1031  setEventMessages($langs->trans("ErrorFieldRequired", $langs->transnoentitiesnoconv("WEBSITE_PAGENAME")), null, 'errors');
1032  $error++;
1033  $action = 'createcontainer';
1034  } elseif (!preg_match('/^[a-z0-9\-\_]+$/i', $objectpage->pageurl)) {
1035  $langs->load("errors");
1036  setEventMessages($langs->transnoentities("ErrorFieldCanNotContainSpecialCharacters", $langs->transnoentities('WEBSITE_PAGENAME')), null, 'errors');
1037  $error++;
1038  $action = 'createcontainer';
1039  }
1040  if (empty($objectpage->title)) {
1041  $langs->load("errors");
1042  setEventMessages($langs->trans("ErrorFieldRequired", $langs->transnoentitiesnoconv("WEBSITE_TITLE")), null, 'errors');
1043  $error++;
1044  $action = 'createcontainer';
1045  }
1046  if ($objectpage->fk_page > 0 && empty($objectpage->lang)) {
1047  $langs->load("errors");
1048  setEventMessages($langs->trans("ErrorLanguageRequiredIfPageIsTranslationOfAnother"), null, 'errors');
1049  $error++;
1050  $action = 'createcontainer';
1051  }
1052  if ($objectpage->fk_page > 0 && !empty($objectpage->lang)) {
1053  if ($objectpage->lang == $website->lang) {
1054  $langs->load("errors");
1055  setEventMessages($langs->trans("ErrorLanguageMustNotBeSourceLanguageIfPageIsTranslationOfAnother"), null, 'errors');
1056  $error++;
1057  $action = 'createcontainer';
1058  }
1059  }
1060  }
1061 
1062  if (!$error) {
1063  $pageid = $objectpage->create($user);
1064  if ($pageid <= 0) {
1065  $error++;
1066  setEventMessages($objectpage->error, $objectpage->errors, 'errors');
1067  $action = 'createcontainer';
1068  }
1069  }
1070 
1071  if (!$error) {
1072  // Website categories association
1073  $categoriesarray = GETPOST('categories', 'array');
1074  $result = $objectpage->setCategories($categoriesarray);
1075  if ($result < 0) {
1076  $error++;
1077  setEventMessages($object->error, $object->errors, 'errors');
1078  }
1079  }
1080 
1081  if (!$error) {
1082  // If there is no home page yet, this new page will be set as the home page
1083  if (empty($object->fk_default_home)) {
1084  $object->fk_default_home = $pageid;
1085  $res = $object->update($user);
1086  if ($res <= 0) {
1087  $error++;
1088  setEventMessages($object->error, $object->errors, 'errors');
1089  } else {
1090  $filetpl = $pathofwebsite.'/page'.$pageid.'.tpl.php';
1091 
1092  // Generate the index.php page (to be the home page) and the wrapper.php file
1093  $result = dolSaveIndexPage($pathofwebsite, $fileindex, $filetpl, $filewrapper, $object);
1094 
1095  if ($result <= 0) {
1096  setEventMessages('Failed to write file '.$fileindex, null, 'errors');
1097  }
1098  }
1099  }
1100  }
1101 
1102  if (!$error) {
1103  if (!empty($objectpage->content)) {
1104  $filealias = $pathofwebsite.'/'.$objectpage->pageurl.'.php';
1105  $filetpl = $pathofwebsite.'/page'.$objectpage->id.'.tpl.php';
1106 
1107  // Save page alias
1108  $result = dolSavePageAlias($filealias, $object, $objectpage);
1109  if (!$result) {
1110  setEventMessages('Failed to write file '.basename($filealias), null, 'errors');
1111  }
1112 
1113  // Save page of content
1114  $result = dolSavePageContent($filetpl, $object, $objectpage, 1);
1115  if ($result) {
1116  setEventMessages($langs->trans("Saved"), null, 'mesgs');
1117  } else {
1118  setEventMessages('Failed to write file '.$filetpl, null, 'errors');
1119  $action = 'createcontainer';
1120  }
1121  }
1122  }
1123 
1124  if (!$error) {
1125  $db->commit();
1126  setEventMessages($langs->trans("PageAdded", $objectpage->pageurl), null, 'mesgs');
1127  $action = '';
1128  } else {
1129  $db->rollback();
1130  }
1131 
1132  if (!$error) {
1133  $pageid = $objectpage->id;
1134 
1135  // To generate the CSS, robot and htmlheader file.
1136 
1137  // Check symlink to medias and restore it if ko
1138  $pathtomedias = DOL_DATA_ROOT.'/medias';
1139  $pathtomediasinwebsite = $pathofwebsite.'/medias';
1140  if (!is_link(dol_osencode($pathtomediasinwebsite))) {
1141  dol_syslog("Create symlink for ".$pathtomedias." into name ".$pathtomediasinwebsite);
1142  dol_mkdir(dirname($pathtomediasinwebsite)); // To be sure dir for website exists
1143  $result = symlink($pathtomedias, $pathtomediasinwebsite);
1144  }
1145 
1146  // Now generate the master.inc.php page if it does not exists yet
1147  if (!dol_is_file($filemaster)) {
1148  $result = dolSaveMasterFile($filemaster);
1149  if (!$result) {
1150  $error++;
1151  setEventMessages('Failed to write file '.$filemaster, null, 'errors');
1152  }
1153  }
1154 
1155  if (!dol_is_file($filehtmlheader)) {
1156  $htmlheadercontent = "<html>\n";
1157  $htmlheadercontent .= $htmlheadercontentdefault;
1158  $htmlheadercontent .= "</html>";
1159  $result = dolSaveHtmlHeader($filehtmlheader, $htmlheadercontent);
1160  }
1161 
1162  if (!dol_is_file($filecss)) {
1163  $csscontent = "/* CSS content (all pages) */\nbody.bodywebsite { margin: 0; font-family: 'Open Sans', sans-serif; }\n.bodywebsite h1 { margin-top: 0; margin-bottom: 0; padding: 10px;}";
1164  $result = dolSaveCssFile($filecss, $csscontent);
1165  }
1166 
1167  if (!dol_is_file($filejs)) {
1168  $jscontent = "/* JS content (all pages) */\n";
1169  $result = dolSaveJsFile($filejs, $jscontent);
1170  }
1171 
1172  if (!dol_is_file($filerobot)) {
1173  $robotcontent = "# Robot file. Generated with Dolibarr\nUser-agent: *\nAllow: /public/\nDisallow: /administrator/";
1174  $result = dolSaveRobotFile($filerobot, $robotcontent);
1175  }
1176 
1177  if (!dol_is_file($filehtaccess)) {
1178  $htaccesscontent = "# Order allow,deny\n# Deny from all";
1179  $result = dolSaveHtaccessFile($filehtaccess, $htaccesscontent);
1180  }
1181 
1182  if (!dol_is_file($filemanifestjson)) {
1183  $manifestjsoncontent = "";
1184  $result = dolSaveManifestJson($filemanifestjson, $manifestjsoncontent);
1185  }
1186 
1187  if (!dol_is_file($filereadme)) {
1188  $readmecontent = "Website generated by Dolibarr ERP CRM";
1189  $result = dolSaveReadme($filereadme, $readmecontent);
1190  }
1191 
1192  $action = 'preview';
1193  }
1194 }
1195 
1196 // Delete site
1197 if ($action == 'confirm_deletesite' && $confirm == 'yes' && $permissiontodelete) {
1198  $error = 0;
1199 
1200  $db->begin();
1201 
1202  $res = $object->fetch(GETPOST('id', 'int'));
1203  $website = $object;
1204 
1205  if ($res > 0) {
1206  $res = $object->delete($user);
1207  if ($res <= 0) {
1208  $error++;
1209  setEventMessages($object->error, $object->errors, 'errors');
1210  }
1211  }
1212  if (!$error) {
1213  if (GETPOST('delete_also_js', 'alpha') == 'on') {
1214  $pathofwebsitejs = DOL_DATA_ROOT.'/medias/js/'.$object->ref;
1215 
1216  dol_delete_dir_recursive($pathofwebsitejs);
1217  }
1218  if (GETPOST('delete_also_medias', 'alpha') == 'on') {
1219  $pathofwebsitemedias = DOL_DATA_ROOT.'/medias/image/'.$object->ref;
1220 
1221  dol_delete_dir_recursive($pathofwebsitemedias);
1222  }
1223  }
1224 
1225  if (!$error) {
1226  $db->commit();
1227  setEventMessages($langs->trans("SiteDeleted", $object->ref), null, 'mesgs');
1228 
1229  header("Location: ".$_SERVER["PHP_SELF"].'?id='.$object->id);
1230  exit;
1231  } else {
1232  $db->rollback();
1233  dol_print_error($db);
1234  }
1235 }
1236 
1237 // Delete page (from website page menu)
1238 if (GETPOSTISSET('pageid') && $action == 'delete' && $permissiontodelete && !GETPOST('file_manager')) {
1239  $error = 0;
1240 
1241  $db->begin();
1242 
1243  $res = $object->fetch(0, $websitekey);
1244  $website = $object;
1245 
1246  $res = $objectpage->fetch($pageid, $object->id);
1247 
1248  if ($res > 0) {
1249  $res = $objectpage->delete($user);
1250  if ($res <= 0) {
1251  $error++;
1252  setEventMessages($objectpage->error, $objectpage->errors, 'errors');
1253  }
1254  }
1255 
1256  if (!$error) {
1257  $db->commit();
1258  setEventMessages($langs->trans("PageDeleted", $objectpage->pageurl, $websitekey), null, 'mesgs');
1259 
1260  header("Location: ".$_SERVER["PHP_SELF"].'?website='.$websitekey);
1261  exit;
1262  } else {
1263  $db->rollback();
1264  dol_print_error($db);
1265  }
1266 }
1267 // Delete page (from menu search)
1268 if (!GETPOSTISSET('pageid')) {
1269  $objectclass = 'WebsitePage';
1270 
1271  // Add part of code from actions_massactions.inc.php
1272  // Delete record from mass action (massaction = 'delete' for direct delete, action/confirm='delete'/'yes' with a confirmation step before)
1273  if (!$error && ($massaction == 'delete' || ($action == 'delete' && $confirm == 'yes')) && $permissiontodelete) {
1274  $db->begin();
1275 
1276  $objecttmp = new $objectclass($db);
1277  $nbok = 0;
1278  foreach ($toselect as $toselectid) {
1279  $result = $objecttmp->fetch($toselectid);
1280  if ($result > 0) {
1281  $result = $objecttmp->delete($user);
1282 
1283  if ($result <= 0) {
1284  setEventMessages($objecttmp->error, $objecttmp->errors, 'errors');
1285  $error++;
1286  break;
1287  } else {
1288  $nbok++;
1289  }
1290  } else {
1291  setEventMessages($objecttmp->error, $objecttmp->errors, 'errors');
1292  $error++;
1293  break;
1294  }
1295  }
1296 
1297  if (!$error) {
1298  if ($nbok > 1) {
1299  setEventMessages($langs->trans("RecordsDeleted", $nbok), null, 'mesgs');
1300  } else {
1301  setEventMessages($langs->trans("RecordDeleted", $nbok), null, 'mesgs');
1302  }
1303  $db->commit();
1304  } else {
1305  $db->rollback();
1306  }
1307  //var_dump($listofobjectthirdparties);exit;
1308  }
1309 
1310  if ($action == 'delete') {
1311  $action = 'replacesiteconfirm';
1312 
1313  $containertype = GETPOST('optioncontainertype', 'aZ09') != '-1' ? GETPOST('optioncontainertype', 'aZ09') : '';
1314  $langcode = GETPOST('optionlanguage', 'aZ09');
1315  $otherfilters = array();
1316  if (GETPOST('optioncategory', 'int') > 0) {
1317  $otherfilters['category'] = GETPOST('optioncategory', 'int');
1318  }
1319 
1320  $listofpages = getPagesFromSearchCriterias($containertype, $algo, $searchkey, 1000, $sortfield, $sortorder, $langcode, $otherfilters);
1321  }
1322 }
1323 
1324 // Update css site properties. Re-generates also the wrapper.
1325 if ($action == 'updatecss' && $usercanedit) {
1326  // If we tried to reload another site/page, we stay on editcss mode.
1327  if (GETPOST('refreshsite') || GETPOST('refreshsite_x') || GETPOST('refreshsite.x') || GETPOST('refreshpage') || GETPOST('refreshpage_x') || GETPOST('refreshpage.x')) {
1328  $action = 'editcss';
1329  } else {
1330  $res = $object->fetch(0, $websitekey);
1331  $website = $object;
1332 
1333  if (GETPOSTISSET('virtualhost')) {
1334  $tmpvirtualhost = preg_replace('/\/$/', '', GETPOST('virtualhost', 'alpha'));
1335  if ($tmpvirtualhost && !preg_match('/^http/', $tmpvirtualhost)) {
1336  $error++;
1337  setEventMessages($langs->trans('ErrorURLMustStartWithHttp', $langs->transnoentitiesnoconv("VirtualHost")), null, 'errors');
1338  $action = 'editcss';
1339  }
1340 
1341  if (!$error) {
1342  $arrayotherlang = explode(',', GETPOST('WEBSITE_OTHERLANG', 'alphanohtml'));
1343  foreach ($arrayotherlang as $key => $val) {
1344  // It possible we have empty val here if postparam WEBSITE_OTHERLANG is empty or set like this : 'en,,sv' or 'en,sv,'
1345  if (empty(trim($val))) continue;
1346  $arrayotherlang[$key] = substr(trim($val), 0, 2); // Kept short language code only
1347  }
1348 
1349  $object->virtualhost = $tmpvirtualhost;
1350  $object->lang = GETPOST('WEBSITE_LANG', 'aZ09');
1351  $object->otherlang = join(',', $arrayotherlang);
1352  $object->use_manifest = GETPOST('use_manifest', 'alpha');
1353 
1354  $result = $object->update($user);
1355  if ($result < 0) {
1356  $error++;
1357  setEventMessages($object->error, $object->errors, 'errors');
1358  $action = 'editcss';
1359  }
1360  }
1361  }
1362 
1363  if (!$error) {
1364  if (($_FILES['addedfile']["name"] != '')) {
1365  $uploadfolder = $conf->website->dir_output.'/'.$websitekey;
1366  if ($_FILES['addedfile']['type'] != 'image/png') {
1367  $error++;
1368  setEventMessages($langs->trans('ErrorFaviconType'), array(), 'errors');
1369  }
1370  $filetoread = realpath(dol_osencode($_FILES['addedfile']['tmp_name']));
1371  $filesize = getimagesize($filetoread);
1372  if ($filesize[0] != $filesize[1]) {
1373  $error++;
1374  setEventMessages($langs->trans('ErrorFaviconMustBeASquaredImage'), array(), 'errors');
1375  }
1376  if (! $error && ($filesize[0] != 16 && $filesize[0] != 32 && $filesize[0] != 64)) {
1377  $error++;
1378  setEventMessages($langs->trans('ErrorFaviconSize'), array(), 'errors');
1379  }
1380  if (!$error) {
1381  dol_add_file_process($uploadfolder, 1, 0, 'addedfile', 'favicon.png');
1382  }
1383  }
1384  if ($error) {
1385  if (!GETPOSTISSET('updateandstay')) { // If we click on "Save And Stay", we don not make the redirect
1386  $action = 'preview';
1387  if ($backtopage) {
1388  $backtopage = preg_replace('/searchstring=[^&]*/', '', $backtopage); // Clean backtopage url
1389  header("Location: ".$backtopage);
1390  exit;
1391  }
1392  } else {
1393  $action = 'editcss';
1394  }
1395  }
1396  }
1397 
1398  if (!$error) {
1399  // Save master.inc.php file
1400  dol_syslog("Save master file ".$filemaster);
1401 
1402  dol_mkdir($pathofwebsite);
1403 
1404  // Now generate the master.inc.php page
1405  $result = dolSaveMasterFile($filemaster);
1406  if (!$result) {
1407  $error++;
1408  setEventMessages('Failed to write file '.$filemaster, null, 'errors');
1409  }
1410 
1411 
1412  $dataposted = trim(GETPOST('WEBSITE_HTML_HEADER', 'none'));
1413  $dataposted = preg_replace(array('/<html>\n*/ims', '/<\/html>\n*/ims'), array('', ''), $dataposted);
1414  $dataposted = str_replace('<?=', '<?php', $dataposted);
1415 
1416  // Html header file
1417  $phpfullcodestringold = '';
1418  $phpfullcodestring = dolKeepOnlyPhpCode($dataposted);
1419 
1420  // Security analysis
1421  $errorphpcheck = checkPHPCode($phpfullcodestringold, $phpfullcodestring); // Contains the setEventMessages
1422 
1423  if (!$errorphpcheck) {
1424  $htmlheadercontent = '';
1425 
1426  /* We disable php code since htmlheader is never executed as an include but only read by fgets_content.
1427  $htmlheadercontent.= "<?php // BEGIN PHP\n";
1428  $htmlheadercontent.= '$websitekey=basename(__DIR__);'."\n";
1429  $htmlheadercontent.= "if (! defined('USEDOLIBARRSERVER') && ! defined('USEDOLIBARREDITOR')) { require_once './master.inc.php'; } // Load env if not already loaded"."\n";
1430  $htmlheadercontent.= "require_once DOL_DOCUMENT_ROOT.'/core/lib/website.lib.php';\n";
1431  $htmlheadercontent.= "require_once DOL_DOCUMENT_ROOT.'/core/website.inc.php';\n";
1432  $htmlheadercontent.= "ob_start();\n";
1433  // $htmlheadercontent.= "header('Content-type: text/html');\n"; // Not required. htmlheader.html is never call as a standalone page
1434  $htmlheadercontent.= "// END PHP ?>\n";*/
1435 
1436  $htmlheadercontent .= $dataposted."\n";
1437 
1438  /*$htmlheadercontent.= "\n".'<?php // BEGIN PHP'."\n";
1439  $htmlheadercontent.= '$tmp = ob_get_contents(); ob_end_clean(); dolWebsiteOutput($tmp);'."\n";
1440  $htmlheadercontent.= "// END PHP ?>"."\n";*/
1441 
1442  $result = dolSaveHtmlHeader($filehtmlheader, $htmlheadercontent);
1443  if (!$result) {
1444  $error++;
1445  setEventMessages('Failed to write file '.$filehtmlheader, null, 'errors');
1446  }
1447  } else {
1448  $error++;
1449  }
1450 
1451  $dataposted = trim(GETPOST('WEBSITE_CSS_INLINE', 'none'));
1452  $dataposted = str_replace('<?=', '<?php', $dataposted);
1453 
1454  // Css file
1455  $phpfullcodestringold = '';
1456  $phpfullcodestring = dolKeepOnlyPhpCode($dataposted);
1457 
1458  // Security analysis
1459  $errorphpcheck = checkPHPCode($phpfullcodestringold, $phpfullcodestring); // Contains the setEventMessages
1460 
1461  if (!$errorphpcheck) {
1462  $csscontent = '';
1463 
1464  $csscontent .= "<?php // BEGIN PHP\n";
1465  $csscontent .= '$websitekey=basename(__DIR__);'."\n";
1466  $csscontent .= "if (! defined('USEDOLIBARRSERVER') && ! defined('USEDOLIBARREDITOR')) { require_once __DIR__.'/master.inc.php'; } // Load env if not already loaded\n"; // For the css, we need to set path of master using the dirname of css file.
1467  $csscontent .= "require_once DOL_DOCUMENT_ROOT.'/core/lib/website.lib.php';\n";
1468  $csscontent .= "require_once DOL_DOCUMENT_ROOT.'/core/website.inc.php';\n";
1469  $csscontent .= "ob_start();\n";
1470  $csscontent .= "if (! headers_sent()) { /* because file is included inline when in edit mode and we don't want warning */ \n";
1471  $csscontent .= "header('Cache-Control: max-age=3600, public, must-revalidate');\n";
1472  $csscontent .= "header('Content-type: text/css');\n";
1473  $csscontent .= "}\n";
1474  $csscontent .= "// END PHP ?>\n";
1475 
1476  $csscontent .= $dataposted."\n";
1477 
1478  $csscontent .= '<?php // BEGIN PHP'."\n";
1479  $csscontent .= '$tmp = ob_get_contents(); ob_end_clean(); dolWebsiteOutput($tmp, "css");'."\n";
1480  $csscontent .= "// END PHP ?>\n";
1481 
1482  dol_syslog("Save css content into ".$filecss);
1483 
1484  $result = dolSaveCssFile($filecss, $csscontent);
1485  if (!$result) {
1486  $error++;
1487  setEventMessages('Failed to write file '.$filecss, null, 'errors');
1488  }
1489  } else {
1490  $error++;
1491  }
1492 
1493 
1494  $dataposted = trim(GETPOST('WEBSITE_JS_INLINE', 'none'));
1495  $dataposted = str_replace('<?=', '<?php', $dataposted);
1496 
1497  // Js file
1498  $phpfullcodestringold = '';
1499  $phpfullcodestring = dolKeepOnlyPhpCode($dataposted);
1500 
1501  // Security analysis
1502  $errorphpcheck = checkPHPCode($phpfullcodestringold, $phpfullcodestring); // Contains the setEventMessages
1503 
1504  if (!$errorphpcheck) {
1505  $jscontent = '';
1506 
1507  $jscontent .= "<?php // BEGIN PHP\n";
1508  $jscontent .= '$websitekey=basename(__DIR__);'."\n";
1509  $jscontent .= "if (! defined('USEDOLIBARRSERVER') && ! defined('USEDOLIBARREDITOR')) { require_once __DIR__.'/master.inc.php'; } // Load env if not already loaded\n"; // For the css, we need to set path of master using the dirname of css file.
1510  $jscontent .= "require_once DOL_DOCUMENT_ROOT.'/core/lib/website.lib.php';\n";
1511  $jscontent .= "require_once DOL_DOCUMENT_ROOT.'/core/website.inc.php';\n";
1512  $jscontent .= "ob_start();\n";
1513  $jscontent .= "header('Cache-Control: max-age=3600, public, must-revalidate');\n";
1514  $jscontent .= "header('Content-type: application/javascript');\n";
1515  $jscontent .= "// END PHP ?>\n";
1516 
1517  $jscontent .= $dataposted."\n";
1518 
1519  $jscontent .= '<?php // BEGIN PHP'."\n";
1520  $jscontent .= '$tmp = ob_get_contents(); ob_end_clean(); dolWebsiteOutput($tmp, "js");'."\n";
1521  $jscontent .= "// END PHP ?>\n";
1522 
1523  $result = dolSaveJsFile($filejs, $jscontent);
1524  if (!$result) {
1525  $error++;
1526  setEventMessages('Failed to write file '.$filejs, null, 'errors');
1527  }
1528  } else {
1529  $error++;
1530  }
1531 
1532  $dataposted = trim(GETPOST('WEBSITE_ROBOT', 'restricthtml'));
1533  $dataposted = str_replace('<?=', '<?php', $dataposted);
1534 
1535  // Robot file
1536  $phpfullcodestringold = '';
1537  $phpfullcodestring = dolKeepOnlyPhpCode($dataposted);
1538 
1539  // Security analysis
1540  $errorphpcheck = checkPHPCode($phpfullcodestringold, $phpfullcodestring); // Contains the setEventMessages
1541 
1542  if (!$errorphpcheck) {
1543  $robotcontent = '';
1544 
1545  /*$robotcontent.= "<?php // BEGIN PHP\n";
1546  $robotcontent.= '$websitekey=basename(__DIR__);'."\n";
1547  $robotcontent.= "if (! defined('USEDOLIBARRSERVER') && ! defined('USEDOLIBARREDITOR')) { require_once './master.inc.php'; } // Load env if not already loaded"."\n";
1548  $robotcontent.= "require_once DOL_DOCUMENT_ROOT.'/core/lib/website.lib.php';\n";
1549  $robotcontent.= "require_once DOL_DOCUMENT_ROOT.'/core/website.inc.php';\n";
1550  $robotcontent.= "ob_start();\n";
1551  $robotcontent.= "header('Cache-Control: max-age=3600, public, must-revalidate');\n";
1552  $robotcontent.= "header('Content-type: text/css');\n";
1553  $robotcontent.= "// END PHP ?>\n";*/
1554 
1555  $robotcontent .= $dataposted."\n";
1556 
1557  /*$robotcontent.= "\n".'<?php // BEGIN PHP'."\n";
1558  $robotcontent.= '$tmp = ob_get_contents(); ob_end_clean(); dolWebsiteOutput($tmp, "robot");'."\n";
1559  $robotcontent.= "// END PHP ?>"."\n";*/
1560 
1561  $result = dolSaveRobotFile($filerobot, $robotcontent);
1562  if (!$result) {
1563  $error++;
1564  setEventMessages('Failed to write file '.$filerobot, null, 'errors');
1565  }
1566  } else {
1567  $error++;
1568  }
1569 
1570  $dataposted = trim(GETPOST('WEBSITE_HTACCESS', 'restricthtml'));
1571  $dataposted = str_replace('<?=', '<?php', $dataposted);
1572 
1573  // Htaccess file
1574  $phpfullcodestringold = '';
1575  $phpfullcodestring = dolKeepOnlyPhpCode($dataposted);
1576 
1577  // Security analysis
1578  $errorphpcheck = checkPHPCode($phpfullcodestringold, $phpfullcodestring); // Contains the setEventMessages
1579 
1580  if (!$errorphpcheck) {
1581  $htaccesscontent = '';
1582  $htaccesscontent .= $dataposted."\n";
1583 
1584  $result = dolSaveHtaccessFile($filehtaccess, $htaccesscontent);
1585  if (!$result) {
1586  $error++;
1587  setEventMessages('Failed to write file '.$filehtaccess, null, 'errors');
1588  }
1589  } else {
1590  $error++;
1591  }
1592 
1593 
1594  $dataposted = trim(GETPOST('WEBSITE_MANIFEST_JSON', 'none'));
1595  $dataposted = str_replace('<?=', '<?php', $dataposted);
1596 
1597  // Manifest.json file
1598  $phpfullcodestringold = '';
1599  $phpfullcodestring = dolKeepOnlyPhpCode($dataposted);
1600 
1601  // Security analysis
1602  $errorphpcheck = checkPHPCode($phpfullcodestringold, $phpfullcodestring); // Contains the setEventMessages
1603 
1604  if (!$errorphpcheck) {
1605  $manifestjsoncontent = '';
1606 
1607  $manifestjsoncontent .= "<?php // BEGIN PHP\n";
1608  $manifestjsoncontent .= '$websitekey=basename(__DIR__);'."\n";
1609  $manifestjsoncontent .= "if (! defined('USEDOLIBARRSERVER') && ! defined('USEDOLIBARREDITOR')) { require_once __DIR__.'/master.inc.php'; } // Load env if not already loaded\n"; // For the css, we need to set path of master using the dirname of css file.
1610  $manifestjsoncontent .= "require_once DOL_DOCUMENT_ROOT.'/core/lib/website.lib.php';\n";
1611  $manifestjsoncontent .= "require_once DOL_DOCUMENT_ROOT.'/core/website.inc.php';\n";
1612  $manifestjsoncontent .= "ob_start();\n";
1613  $manifestjsoncontent .= "header('Cache-Control: max-age=3600, public, must-revalidate');\n";
1614  $manifestjsoncontent .= "header('Content-type: application/manifest+json');\n";
1615  $manifestjsoncontent .= "// END PHP ?>\n";
1616 
1617  $manifestjsoncontent .= $dataposted."\n";
1618 
1619  $manifestjsoncontent .= '<?php // BEGIN PHP'."\n";
1620  $manifestjsoncontent .= '$tmp = ob_get_contents(); ob_end_clean(); dolWebsiteOutput($tmp, "manifest");'."\n";
1621  $manifestjsoncontent .= "// END PHP ?>\n";
1622 
1623  $result = dolSaveManifestJson($filemanifestjson, $manifestjsoncontent);
1624  if (!$result) {
1625  $error++;
1626  setEventMessages('Failed to write file '.$filemanifestjson, null, 'errors');
1627  }
1628  } else {
1629  $error++;
1630  }
1631 
1632  $dataposted = trim(GETPOST('WEBSITE_README', 'restricthtml'));
1633  $dataposted = str_replace('<?=', '<?php', $dataposted);
1634 
1635  // README.md file
1636  $phpfullcodestringold = '';
1637  $phpfullcodestring = dolKeepOnlyPhpCode($dataposted);
1638 
1639  // Security analysis
1640  $errorphpcheck = checkPHPCode($phpfullcodestringold, $phpfullcodestring); // Contains the setEventMessages
1641 
1642  if (!$errorphpcheck) {
1643  $readmecontent = '';
1644 
1645  /*$readmecontent.= "<?php // BEGIN PHP\n";
1646  $readmecontent.= '$websitekey=basename(__DIR__);'."\n";
1647  $readmecontent.= "if (! defined('USEDOLIBARRSERVER') && ! defined('USEDOLIBARREDITOR')) { require_once __DIR__.'/master.inc.php'; } // Load env if not already loaded"."\n"; // For the css, we need to set path of master using the dirname of css file.
1648  $readmecontent.= "require_once DOL_DOCUMENT_ROOT.'/core/lib/website.lib.php';\n";
1649  $readmecontent.= "require_once DOL_DOCUMENT_ROOT.'/core/website.inc.php';\n";
1650  $readmecontent.= "ob_start();\n";
1651  $readmecontent.= "header('Cache-Control: max-age=3600, public, must-revalidate');\n";
1652  $readmecontent.= "header('Content-type: application/manifest+json');\n";
1653  $readmecontent.= "// END PHP ?>\n";*/
1654 
1655  $readmecontent .= $dataposted."\n";
1656 
1657  /*$readmecontent.= '<?php // BEGIN PHP'."\n";
1658  $readmecontent.= '$tmp = ob_get_contents(); ob_end_clean(); dolWebsiteOutput($tmp, "manifest");'."\n";
1659  $readmecontent.= "// END PHP ?>"."\n";*/
1660 
1661  $result = dolSaveReadme($filereadme, $readmecontent);
1662  if (!$result) {
1663  $error++;
1664  setEventMessages('Failed to write file '.$filereadme, null, 'errors');
1665  }
1666  } else {
1667  $error++;
1668  }
1669 
1670 
1671  // Save wrapper.php
1672  $result = dolSaveIndexPage($pathofwebsite, '', '', $filewrapper, $object);
1673 
1674 
1675  // Message if no error
1676  if (!$error) {
1677  setEventMessages($langs->trans("Saved"), null, 'mesgs');
1678  }
1679 
1680  if (!GETPOSTISSET('updateandstay')) { // If we click on "Save And Stay", we don not make the redirect
1681  $action = 'preview';
1682  if ($backtopage) {
1683  $backtopage = preg_replace('/searchstring=[^&]*/', '', $backtopage); // Clean backtopage url
1684  header("Location: ".$backtopage);
1685  exit;
1686  }
1687  } else {
1688  $action = 'editcss';
1689  }
1690  }
1691  }
1692 }
1693 
1694 // Update page
1695 if ($action == 'setashome' && $usercanedit) {
1696  $db->begin();
1697  $object->fetch(0, $websitekey);
1698  $website = $object;
1699 
1700  $object->fk_default_home = $pageid;
1701  $res = $object->update($user);
1702  if (! ($res > 0)) {
1703  $error++;
1704  setEventMessages($object->error, $object->errors, 'errors');
1705  }
1706 
1707  if (!$error) {
1708  $db->commit();
1709 
1710  $filetpl = $pathofwebsite.'/page'.$pageid.'.tpl.php';
1711 
1712  // Generate the index.php page to be the home page
1713  $result = dolSaveIndexPage($pathofwebsite, $fileindex, $filetpl, $filewrapper, $object);
1714 
1715  if ($result) {
1716  setEventMessages($langs->trans("Saved"), null, 'mesgs');
1717  } else {
1718  setEventMessages('Failed to write file '.$fileindex, null, 'errors');
1719  }
1720 
1721  $action = 'preview';
1722  } else {
1723  $db->rollback();
1724  }
1725 }
1726 
1727 // Update page properties (meta)
1728 if ($action == 'updatemeta' && $usercanedit) {
1729  $db->begin();
1730 
1731  $result = $object->fetch(0, $websitekey);
1732  $website = $object;
1733 
1734  $objectpage->fk_website = $object->id;
1735 
1736  // Check parameters
1737  if (!preg_match('/^[a-z0-9\-\_]+$/i', GETPOST('WEBSITE_PAGENAME', 'alpha'))) {
1738  $error++;
1739  $langs->load("errors");
1740  setEventMessages($langs->transnoentities("ErrorFieldCanNotContainSpecialCharacters", $langs->transnoentities('WEBSITE_PAGENAME')), null, 'errors');
1741  $action = 'editmeta';
1742  }
1743 
1744  $res = $objectpage->fetch($pageid, $object->id);
1745  if ($res <= 0) {
1746  $error++;
1747  setEventMessages('Page not found '.$objectpage->error, $objectpage->errors, 'errors');
1748  }
1749 
1750  // Check alias not exists
1751  if (!$error && GETPOST('WEBSITE_PAGENAME', 'alpha')) {
1752  $websitepagetemp = new WebsitePage($db);
1753  $result = $websitepagetemp->fetch(-1 * $objectpage->id, $object->id, GETPOST('WEBSITE_PAGENAME', 'alpha'));
1754  if ($result < 0) {
1755  $error++;
1756  $langs->load("errors");
1757  setEventMessages($websitepagetemp->error, $websitepagetemp->errors, 'errors');
1758  $action = 'editmeta';
1759  }
1760  if ($result > 0) {
1761  $error++;
1762  $langs->load("errors");
1763  setEventMessages($langs->trans("ErrorAPageWithThisNameOrAliasAlreadyExists", $websitepagetemp->pageurl), null, 'errors');
1764  $action = 'editmeta';
1765  }
1766  }
1767 
1768  $newaliasnames = '';
1769  if (!$error && GETPOST('WEBSITE_ALIASALT', 'alpha')) {
1770  $arrayofaliastotest = explode(',', str_replace(array('<', '>'), '', GETPOST('WEBSITE_ALIASALT', 'alpha')));
1771 
1772  $websitepagetemp = new WebsitePage($db);
1773  foreach ($arrayofaliastotest as $aliastotest) {
1774  $aliastotest = trim(preg_replace('/\.php$/i', '', $aliastotest));
1775 
1776  // Disallow alias name pageX (already used to save the page with id)
1777  if (preg_match('/^page\d+/i', $aliastotest)) {
1778  $error++;
1779  $langs->load("errors");
1780  setEventMessages("Alias name 'pageX' is not allowed", null, 'errors');
1781  $action = 'editmeta';
1782  break;
1783  } else {
1784  $result = $websitepagetemp->fetch(-1 * $objectpage->id, $object->id, $aliastotest);
1785  if ($result < 0) {
1786  $error++;
1787  $langs->load("errors");
1788  setEventMessages($websitepagetemp->error, $websitepagetemp->errors, 'errors');
1789  $action = 'editmeta';
1790  break;
1791  }
1792  if ($result > 0) {
1793  $error++;
1794  $langs->load("errors");
1795  setEventMessages($langs->trans("ErrorAPageWithThisNameOrAliasAlreadyExists", $websitepagetemp->pageurl), null, 'errors');
1796  $action = 'editmeta';
1797  break;
1798  }
1799  $newaliasnames .= ($newaliasnames ? ', ' : '').$aliastotest;
1800  }
1801  }
1802  }
1803 
1804  if (!$error) {
1805  $objectpage->old_object = clone $objectpage;
1806 
1807  $objectpage->title = str_replace(array('<', '>'), '', GETPOST('WEBSITE_TITLE', 'alphanohtml'));
1808  $objectpage->type_container = GETPOST('WEBSITE_TYPE_CONTAINER', 'aZ09');
1809  $objectpage->pageurl = GETPOST('WEBSITE_PAGENAME', 'alpha');
1810  $objectpage->aliasalt = $newaliasnames;
1811  $objectpage->lang = GETPOST('WEBSITE_LANG', 'aZ09');
1812  $objectpage->otherlang = GETPOST('WEBSITE_OTHERLANG', 'aZ09comma');
1813  $objectpage->description = str_replace(array('<', '>'), '', GETPOST('WEBSITE_DESCRIPTION', 'alphanohtml'));
1814  $objectpage->image = GETPOST('WEBSITE_IMAGE', 'alpha');
1815  $objectpage->keywords = str_replace(array('<', '>'), '', GETPOST('WEBSITE_KEYWORDS', 'alphanohtml'));
1816  $objectpage->allowed_in_frames = GETPOST('WEBSITE_ALLOWED_IN_FRAMES', 'aZ09');
1817  $objectpage->htmlheader = trim(GETPOST('htmlheader', 'none'));
1818  $objectpage->fk_page = (GETPOST('pageidfortranslation', 'int') > 0 ? GETPOST('pageidfortranslation', 'int') : 0);
1819  $objectpage->author_alias = trim(GETPOST('WEBSITE_AUTHORALIAS', 'alphanohtml'));
1820  $objectpage->object_type = GETPOST('WEBSITE_OBJECTCLASS', 'alpha');
1821  $objectpage->fk_object = GETPOST('WEBSITE_OBJECTID', 'aZ09');
1822 
1823  $newdatecreation = dol_mktime(GETPOST('datecreationhour', 'int'), GETPOST('datecreationmin', 'int'), GETPOST('datecreationsec', 'int'), GETPOST('datecreationmonth', 'int'), GETPOST('datecreationday', 'int'), GETPOST('datecreationyear', 'int'));
1824  if ($newdatecreation) {
1825  $objectpage->date_creation = $newdatecreation;
1826  }
1827 
1828  $res = $objectpage->update($user);
1829  if (!($res > 0)) {
1830  $langs->load("errors");
1831  if ($db->lasterrno == 'DB_ERROR_RECORD_ALREADY_EXISTS') {
1832  $error++;
1833  $langs->load("errors");
1834  setEventMessages($langs->trans("ErrorAPageWithThisNameOrAliasAlreadyExists"), null, 'errors');
1835  $action = 'editmeta';
1836  } else {
1837  $error++;
1838  $langs->load("errors");
1839  setEventMessages($objectpage->error, $objectpage->errors, 'errors');
1840  $action = 'editmeta';
1841  }
1842  }
1843  }
1844 
1845  if (!$error) {
1846  // Website categories association
1847  $categoriesarray = GETPOST('categories', 'array');
1848  $result = $objectpage->setCategories($categoriesarray);
1849  if ($result < 0) {
1850  $error++;
1851  setEventMessages($object->error, $object->errors, 'errors');
1852  }
1853  }
1854 
1855  if (!$error) {
1856  $db->commit();
1857  } else {
1858  $db->rollback();
1859  }
1860 
1861  if (!$error) {
1862  $filemaster = $pathofwebsite.'/master.inc.php';
1863  $fileoldalias = $pathofwebsite.'/'.$objectpage->old_object->pageurl.'.php';
1864  $filealias = $pathofwebsite.'/'.$objectpage->pageurl.'.php';
1865 
1866  dol_mkdir($pathofwebsite);
1867 
1868  // Now generate the master.inc.php page
1869  $result = dolSaveMasterFile($filemaster);
1870  if (!$result) {
1871  setEventMessages('Failed to write file '.$filemaster, null, 'errors');
1872  }
1873 
1874  // Now delete the alias.php page
1875  if (!empty($fileoldalias)) {
1876  dol_syslog("We delete old alias page name=".$fileoldalias." to build a new alias page=".$filealias);
1877  dol_delete_file($fileoldalias);
1878 
1879  // Delete also pages into language subdirectories
1880  if (empty($objectpage->lang) || !in_array($objectpage->lang, explode(',', $object->otherlang))) {
1881  $dirname = dirname($fileoldalias);
1882  $filename = basename($fileoldalias);
1883  $sublangs = explode(',', $object->otherlang);
1884  foreach ($sublangs as $sublang) {
1885  // Under certain conditions $sublang can be an empty string
1886  // ($object->otherlang with empty string or with string like this 'en,,sv')
1887  // if is the case we try to re-delete the main alias file. Avoid it.
1888  if (empty(trim($sublang))) continue;
1889  $fileoldaliassub = $dirname.'/'.$sublang.'/'.$filename;
1890  dol_delete_file($fileoldaliassub);
1891  }
1892  }
1893  }
1894  // Now delete the alternative alias.php pages
1895  if (!empty($objectpage->old_object->aliasalt)) {
1896  $tmpaltaliases = explode(',', $objectpage->old_object->aliasalt);
1897  if (is_array($tmpaltaliases)) {
1898  foreach ($tmpaltaliases as $tmpaliasalt) {
1899  dol_syslog("We delete old alt alias pages name=".trim($tmpaliasalt));
1900  dol_delete_file($pathofwebsite.'/'.trim($tmpaliasalt).'.php');
1901 
1902  // Delete also pages into language subdirectories
1903  if (empty($objectpage->lang) || !in_array($objectpage->lang, explode(',', $object->otherlang))) {
1904  $dirname = dirname($pathofwebsite.'/'.trim($tmpaliasalt).'.php');
1905  $filename = basename($pathofwebsite.'/'.trim($tmpaliasalt).'.php');
1906  $sublangs = explode(',', $object->otherlang);
1907  foreach ($sublangs as $sublang) {
1908  // Under certain conditions $ sublang can be an empty string
1909  // ($object->otherlang with empty string or with string like this 'en,,sv')
1910  // if is the case we try to re-delete the main alias file. Avoid it.
1911  if (empty(trim($sublang))) continue;
1912  $fileoldaliassub = $dirname.'/'.$sublang.'/'.$filename;
1913  dol_delete_file($fileoldaliassub);
1914  }
1915  }
1916  }
1917  }
1918  }
1919 
1920  // Save page main alias
1921  $result = dolSavePageAlias($filealias, $object, $objectpage);
1922  if (!$result) {
1923  setEventMessages('Failed to write file '.$filealias, null, 'errors');
1924  }
1925  // Save alt aliases
1926  if (!empty($objectpage->aliasalt)) {
1927  $tmpaltaliases = explode(',', $objectpage->aliasalt);
1928  if (is_array($tmpaltaliases)) {
1929  foreach ($tmpaltaliases as $tmpaliasalt) {
1930  if (trim($tmpaliasalt)) {
1931  $filealias = $pathofwebsite.'/'.trim($tmpaliasalt).'.php';
1932  $result = dolSavePageAlias($filealias, $object, $objectpage);
1933  if (!$result) {
1934  setEventMessages('Failed to write file '.basename($filealias), null, 'errors');
1935  }
1936  }
1937  }
1938  }
1939  }
1940 
1941 
1942  // Save page of content
1943  $result = dolSavePageContent($filetpl, $object, $objectpage, 1);
1944  if ($result) {
1945  setEventMessages($langs->trans("Saved"), null, 'mesgs');
1946 
1947  if (!GETPOSTISSET('updateandstay')) { // If we click on "Save And Stay", we do not make the redirect
1948  //header("Location: ".$_SERVER["PHP_SELF"].'?website='.$websitekey.'&pageid='.$pageid);
1949  //exit;
1950  $action = 'preview';
1951  } else {
1952  $action = 'editmeta';
1953  }
1954  } else {
1955  setEventMessages('Failed to write file '.$filetpl, null, 'errors');
1956  //header("Location: ".$_SERVER["PHP_SELF"].'?website='.$websitekey.'&pageid='.$pageid);
1957  //exit;
1958  $action = 'preview';
1959  }
1960  }
1961 }
1962 
1963 // Update page
1964 if ($usercanedit && (($action == 'updatesource' || $action == 'updatecontent' || $action == 'confirm_createfromclone' || $action == 'confirm_createpagefromclone')
1965  || ($action == 'preview' && (GETPOST('refreshsite') || GETPOST('refreshpage') || GETPOST('preview'))))) {
1966  $object->fetch(0, $websitekey);
1967  $website = $object;
1968 
1969  if ($action == 'confirm_createfromclone') {
1970  $db->begin();
1971 
1972  $objectnew = new Website($db);
1973  $result = $objectnew->createFromClone($user, GETPOST('id', 'int'), GETPOST('siteref', 'aZ09'), (GETPOST('newlang', 'aZ09') ?GETPOST('newlang', 'aZ09') : ''));
1974 
1975  if ($result < 0) {
1976  $error++;
1977  setEventMessages($objectnew->error, $objectnew->errors, 'errors');
1978  $action = 'preview';
1979 
1980  $db->rollback();
1981  } else {
1982  $object = $objectnew;
1983  $id = $object->id;
1984  $pageid = $object->fk_default_home;
1985  $websitekey = GETPOST('siteref', 'aZ09');
1986 
1987  $db->commit();
1988  }
1989  }
1990 
1991  if ($action == 'confirm_createpagefromclone') {
1992  $istranslation = (GETPOST('is_a_translation', 'aZ09') == 'on' ? 1 : 0);
1993  // Protection if it is a translation page
1994  if ($istranslation) {
1995  if (GETPOST('newlang', 'aZ09') == $objectpage->lang || !GETPOST('newlang', 'aZ09')) {
1996  $error++;
1997  setEventMessages($langs->trans("LanguageMustNotBeSameThanClonedPage"), null, 'errors');
1998  $action = 'preview';
1999  }
2000  if (GETPOST('newwebsite', 'int') != $object->id) {
2001  $error++;
2002  setEventMessages($langs->trans("WebsiteMustBeSameThanClonedPageIfTranslation"), null, 'errors');
2003  $action = 'preview';
2004  }
2005  }
2006 
2007  if (!$error) {
2008  $db->begin();
2009 
2010  $newwebsiteid = GETPOST('newwebsite', 'int');
2011  $pathofwebsitenew = $pathofwebsite;
2012 
2013  $tmpwebsite = new Website($db);
2014  if ($newwebsiteid > 0 && $newwebsiteid != $object->id) {
2015  $tmpwebsite->fetch($newwebsiteid);
2016  $pathofwebsitenew = $dolibarr_main_data_root.($conf->entity > 1 ? '/'.$conf->entity : '').'/website/'.$tmpwebsite->ref;
2017  } else {
2018  $tmpwebsite = $object;
2019  }
2020 
2021  $objectpage = new WebsitePage($db);
2022  $resultpage = $objectpage->createFromClone($user, $pageid, GETPOST('newpageurl', 'aZ09'), (GETPOST('newlang', 'aZ09') ? GETPOST('newlang', 'aZ09') : ''), $istranslation, $newwebsiteid, GETPOST('newtitle', 'alphanohtml'));
2023  if ($resultpage < 0) {
2024  $error++;
2025  setEventMessages($objectpage->error, $objectpage->errors, 'errors');
2026  $action = 'createpagefromclone';
2027 
2028  $db->rollback();
2029  } else {
2030  $filetpl = $pathofwebsitenew.'/page'.$resultpage->id.'.tpl.php';
2031  $fileindex = $pathofwebsitenew.'/index.php';
2032  $filewrapper = $pathofwebsitenew.'/wrapper.php';
2033 
2034  //var_dump($pathofwebsitenew);
2035  //var_dump($filetpl);
2036  //exit;
2037 
2038  dolSavePageContent($filetpl, $tmpwebsite, $resultpage, 1);
2039 
2040  // Switch on the new page if web site of new page/container is same
2041  if (empty($newwebsiteid) || $newwebsiteid == $object->id) {
2042  $pageid = $resultpage->id;
2043  }
2044 
2045  $db->commit();
2046  }
2047  }
2048  }
2049 
2050  $res = 0;
2051 
2052  if (!$error) {
2053  // Check symlink to medias and restore it if ko
2054  $pathtomedias = DOL_DATA_ROOT.'/medias';
2055  $pathtomediasinwebsite = $pathofwebsite.'/medias';
2056  if (!is_link(dol_osencode($pathtomediasinwebsite))) {
2057  dol_syslog("Create symlink for ".$pathtomedias." into name ".$pathtomediasinwebsite);
2058  dol_mkdir(dirname($pathtomediasinwebsite)); // To be sure dir for website exists
2059  $result = symlink($pathtomedias, $pathtomediasinwebsite);
2060  }
2061 
2062  /*if (GETPOST('savevirtualhost') && $object->virtualhost != GETPOST('previewsite'))
2063  {
2064  $object->virtualhost = GETPOST('previewsite', 'alpha');
2065  $object->update($user);
2066  }*/
2067 
2068  $objectpage->fk_website = $object->id;
2069 
2070  if ($pageid > 0) {
2071  $res = $objectpage->fetch($pageid);
2072  } else {
2073  $res = 0;
2074  if ($object->fk_default_home > 0) {
2075  $res = $objectpage->fetch($object->fk_default_home);
2076  }
2077  if (!($res > 0)) {
2078  $res = $objectpage->fetch(0, $object->id);
2079  }
2080  }
2081  }
2082 
2083  if (!$error && $res > 0) {
2084  if ($action == 'updatesource' || $action == 'updatecontent') {
2085  $db->begin();
2086 
2087  $phpfullcodestringold = dolKeepOnlyPhpCode($objectpage->content);
2088 
2089  $objectpage->content = GETPOST('PAGE_CONTENT', 'none');
2090 
2091  $phpfullcodestring = dolKeepOnlyPhpCode($objectpage->content);
2092 
2093  // Security analysis
2094  $error = checkPHPCode($phpfullcodestringold, $phpfullcodestring);
2095 
2096  if ($error) {
2097  if ($action == 'updatesource') {
2098  $action = 'editsource';
2099  }
2100  if ($action == 'updatecontent') {
2101  $action = 'editcontent';
2102  }
2103  }
2104 
2105  // Clean data. We remove all the head section.
2106  $objectpage->content = preg_replace('/<head>.*<\/head>/ims', '', $objectpage->content);
2107  /* $objectpage->content = preg_replace('/<base\s+href=[\'"][^\'"]+[\'"]\s/?>/s', '', $objectpage->content); */
2108 
2109 
2110  $res = $objectpage->update($user);
2111  if ($res < 0) {
2112  $error++;
2113  setEventMessages($objectpage->error, $objectpage->errors, 'errors');
2114  if ($action == 'updatesource') {
2115  $action = 'editsource';
2116  }
2117  if ($action == 'updatecontent') {
2118  $action = 'editcontent';
2119  }
2120  }
2121 
2122  if (!$error) {
2123  $db->commit();
2124 
2125  $filemaster = $pathofwebsite.'/master.inc.php';
2126  //$fileoldalias=$pathofwebsite.'/'.$objectpage->old_object->pageurl.'.php';
2127  $filealias = $pathofwebsite.'/'.$objectpage->pageurl.'.php';
2128 
2129  dol_mkdir($pathofwebsite);
2130 
2131  // Now generate the master.inc.php page
2132  $result = dolSaveMasterFile($filemaster);
2133 
2134  if (!$result) {
2135  setEventMessages('Failed to write the master file file '.$filemaster, null, 'errors');
2136  }
2137 
2138  // Now delete the old alias.php page if we removed one
2139  /*if (!empty($fileoldalias))
2140  {
2141  dol_syslog("We regenerate alias page new name=".$filealias.", old name=".$fileoldalias);
2142  dol_delete_file($fileoldalias);
2143 
2144  // Delete also pages into language subdirectories
2145  if (empty($objectpage->lang) || !in_array($objectpage->lang, explode(',', $object->otherlang))) {
2146  $dirname = dirname($fileoldalias);
2147  $filename = basename($fileoldalias);
2148  $sublangs = explode(',', $object->otherlang);
2149  foreach ($sublangs as $sublang) {
2150  $fileoldaliassub = $dirname.'/'.$sublang.'/'.$filename;
2151  dol_delete_file($fileoldaliassub);
2152  }
2153  }
2154  }*/
2155 
2156  // Save page alias
2157  $result = dolSavePageAlias($filealias, $object, $objectpage);
2158  if (!$result) {
2159  setEventMessages('Failed to write the alias file '.basename($filealias), null, 'errors');
2160  }
2161 
2162  // Save page content
2163  $result = dolSavePageContent($filetpl, $object, $objectpage, 1);
2164  if ($result) {
2165  setEventMessages($langs->trans("Saved"), null, 'mesgs');
2166 
2167  if (!GETPOSTISSET('updateandstay')) { // If we click on "Save And Stay", we do not make the redirect
2168  if ($backtopage) {
2169  header("Location: ".$backtopage);
2170  exit;
2171  } else {
2172  header("Location: ".$_SERVER["PHP_SELF"].'?website='.$websitekey.'&pageid='.$pageid);
2173  exit;
2174  }
2175  } else {
2176  if ($action == 'updatesource') {
2177  $action = 'editsource';
2178  }
2179  if ($action == 'updatecontent') {
2180  $action = 'editcontent';
2181  }
2182  }
2183  } else {
2184  setEventMessages('Failed to write file '.$filetpl, null, 'errors');
2185  header("Location: ".$_SERVER["PHP_SELF"].'?website='.$websitekey.'&pageid='.$pageid);
2186  exit;
2187  }
2188  } else {
2189  $db->rollback();
2190  }
2191  } else {
2192  header("Location: ".$_SERVER["PHP_SELF"].'?website='.$websitekey.'&pageid='.$pageid);
2193  exit;
2194  }
2195  } else {
2196  if (!$error) {
2197  if (empty($websitekey) || $websitekey == '-1') {
2198  setEventMessages($langs->trans("NoWebSiteCreateOneFirst"), null, 'warnings');
2199  } else {
2200  setEventMessages($langs->trans("NoPageYet"), null, 'warnings');
2201  setEventMessages($langs->trans("YouCanCreatePageOrImportTemplate"), null, 'warnings');
2202  }
2203  }
2204  }
2205 }
2206 
2207 // Export site
2208 if ($action == 'exportsite' && !empty($user->rights->website->export)) {
2209  $fileofzip = $object->exportWebSite();
2210 
2211  if ($fileofzip) {
2212  $file_name = basename($fileofzip);
2213 
2214  header("Content-Type: application/zip");
2215  header("Content-Disposition: attachment; filename=".$file_name);
2216  header("Content-Length: ".filesize($fileofzip));
2217 
2218  readfile($fileofzip);
2219  exit;
2220  } else {
2221  setEventMessages($object->error, $object->errors, 'errors');
2222  $action = 'preview';
2223  }
2224 }
2225 
2226 // Regenerate site
2227 if ($action == 'regeneratesite' && $usercanedit) {
2228  // Check symlink to medias and restore it if ko. Recreate also dir of website if not found.
2229  $pathtomedias = DOL_DATA_ROOT.'/medias';
2230  $pathtomediasinwebsite = $pathofwebsite.'/medias';
2231  if (!is_link(dol_osencode($pathtomediasinwebsite))) {
2232  dol_syslog("Create symlink for ".$pathtomedias." into name ".$pathtomediasinwebsite);
2233  dol_mkdir(dirname($pathtomediasinwebsite)); // To be sure that the directory for website exists
2234  $result = symlink($pathtomedias, $pathtomediasinwebsite);
2235  if (!$result) {
2236  setEventMessages($langs->trans("ErrorFieldToCreateSymLinkToMedias", $pathtomediasinwebsite, $pathtomedias), null, 'errors');
2237  $action = 'preview';
2238  }
2239  }
2240 
2241  $result = $object->rebuildWebSiteFiles();
2242  if ($result > 0) {
2243  setEventMessages($langs->trans("PagesRegenerated", $result), null, 'mesgs');
2244  $action = 'preview';
2245  } else {
2246  setEventMessages($object->error, $object->errors, 'errors');
2247  $action = 'preview';
2248  }
2249 }
2250 
2251 // Import site
2252 if ($action == 'importsiteconfirm' && $usercanedit) {
2253  if (empty($_FILES) && !GETPOSTISSET('templateuserfile')) {
2254  setEventMessages($langs->trans("ErrorFieldRequired", $langs->transnoentitiesnoconv("File")), null, 'errors');
2255  $action = 'importsite';
2256  } else {
2257  if (!empty($_FILES) || GETPOSTISSET('templateuserfile')) {
2258  // Check symlink to medias and restore it if ko. Recreate also dir of website if not found.
2259  $pathtomedias = DOL_DATA_ROOT.'/medias';
2260  $pathtomediasinwebsite = $pathofwebsite.'/medias';
2261  if (!is_link(dol_osencode($pathtomediasinwebsite))) {
2262  dol_syslog("Create symlink for ".$pathtomedias." into name ".$pathtomediasinwebsite);
2263  dol_mkdir(dirname($pathtomediasinwebsite)); // To be sure dir for website exists
2264  $result = symlink($pathtomedias, $pathtomediasinwebsite);
2265  if (!$result) {
2266  setEventMessages($langs->trans("ErrorFieldToCreateSymLinkToMedias", $pathtomediasinwebsite, $pathtomedias), null, 'errors');
2267  $action = 'importsite';
2268  }
2269  }
2270 
2271  $fileofzip = '';
2272  if (GETPOSTISSET('templateuserfile')) {
2273  $fileofzip = DOL_DATA_ROOT.'/doctemplates/websites/'.GETPOST('templateuserfile', 'alpha');
2274  } elseif (!empty($_FILES) && is_array($_FILES['userfile'])) {
2275  if (is_array($_FILES['userfile']['tmp_name'])) {
2276  $userfiles = $_FILES['userfile']['tmp_name'];
2277  } else {
2278  $userfiles = array($_FILES['userfile']['tmp_name']);
2279  }
2280 
2281  foreach ($userfiles as $key => $userfile) {
2282  if (empty($_FILES['userfile']['tmp_name'][$key])) {
2283  $error++;
2284  if ($_FILES['userfile']['error'][$key] == 1 || $_FILES['userfile']['error'][$key] == 2) {
2285  setEventMessages($langs->trans('ErrorFileSizeTooLarge'), null, 'errors');
2286  $action = 'importsite';
2287  } else {
2288  setEventMessages($langs->trans("ErrorFieldRequired", $langs->transnoentitiesnoconv("File")), null, 'errors');
2289  $action = 'importsite';
2290  }
2291  }
2292  }
2293 
2294  if (!$error) {
2295  $upload_dir = $conf->website->dir_temp;
2296  $result = dol_add_file_process($upload_dir, 1, -1, 'userfile', '');
2297  }
2298 
2299  // Get name of file (take last one if several name provided)
2300  $fileofzip = $upload_dir.'/unknown';
2301  foreach ($_FILES as $key => $ifile) {
2302  foreach ($ifile['name'] as $key2 => $ifile2) {
2303  $fileofzip = $upload_dir.'/'.$ifile2;
2304  }
2305  }
2306  }
2307 
2308  if (!$error) {
2309  $result = $object->importWebSite($fileofzip);
2310 
2311  if ($result < 0) {
2312  setEventMessages($object->error, $object->errors, 'errors');
2313  $action = 'importsite';
2314  } else {
2315  // Force mode dynamic on
2316  dolibarr_set_const($db, 'WEBSITE_SUBCONTAINERSINLINE', 1, 'chaine', 0, '', $conf->entity);
2317 
2318  header("Location: ".$_SERVER["PHP_SELF"].'?website='.$object->ref);
2319  exit();
2320  }
2321  }
2322  }
2323  }
2324 }
2325 
2326 $domainname = '0.0.0.0:8080';
2327 $tempdir = $conf->website->dir_output.'/'.$websitekey.'/';
2328 
2329 // Generate web site sitemaps
2330 if ($action == 'generatesitemaps' && $usercanedit) {
2331  $domtree = new DOMDocument('1.0', 'UTF-8');
2332 
2333  $root = $domtree->createElementNS('http://www.sitemaps.org/schemas/sitemap/0.9', 'urlset');
2334  $root->setAttributeNS('http://www.w3.org/2000/xmlns/', 'xmlns:xhtml', 'http://www.w3.org/1999/xhtml');
2335 
2336  $domtree->formatOutput = true;
2337 
2338  $xmlname = 'sitemap.xml';
2339 
2340  $sql = "SELECT wp.rowid, wp.type_container , wp.pageurl, wp.lang, wp.fk_page, wp.tms as tms,";
2341  $sql .= " w.virtualhost, w.fk_default_home";
2342  $sql .= " FROM ".MAIN_DB_PREFIX."website_page as wp, ".MAIN_DB_PREFIX."website as w";
2343  $sql .= " WHERE wp.type_container IN ('page', 'blogpost')";
2344  $sql .= " AND wp.fk_website = w.rowid";
2345  $sql .= " AND wp.status = ".WebsitePage::STATUS_VALIDATED;
2346  $sql .= " AND wp.pageurl NOT IN ('404', '500', '501', '503')";
2347  $sql .= " AND w.ref = '".dol_escape_json($websitekey)."'";
2348  $sql .= " ORDER BY wp.tms DESC, wp.rowid DESC";
2349  $resql = $db->query($sql);
2350  if ($resql) {
2351  $num_rows = $db->num_rows($resql);
2352  if ($num_rows > 0) {
2353  $i = 0;
2354  while ($i < $num_rows) {
2355  $objp = $db->fetch_object($resql);
2356  $url = $domtree->createElement('url');
2357 
2358  $shortlangcode = '';
2359  if ($objp->lang) {
2360  $shortlangcode = substr($objp->lang, 0, 2); // en_US or en-US -> en
2361  }
2362  if (empty($shortlangcode)) {
2363  $shortlangcode = substr($object->lang, 0, 2); // Use short lang code of website
2364  }
2365 
2366  // Forge $pageurl, adding language prefix if it is an alternative language
2367  $pageurl = $objp->pageurl.'.php';
2368  if ($objp->fk_default_home == $objp->rowid) {
2369  $pageurl = '';
2370  } else {
2371  if ($shortlangcode != substr($object->lang, 0, 2)) {
2372  $pageurl = $shortlangcode.'/'.$pageurl;
2373  }
2374  }
2375 
2376  if ($objp->virtualhost) {
2377  $domainname = $objp->virtualhost;
2378  }
2379  if (! preg_match('/^http/i', $domainname)) {
2380  $domainname = 'https://'.$domainname;
2381  }
2382  //$pathofpage = $dolibarr_main_url_root.'/'.$pageurl.'.php';
2383 
2384  // URL of sitemaps must end with trailing slash if page is ''
2385  $loc = $domtree->createElement('loc', $domainname.'/'.$pageurl);
2386  $lastmod = $domtree->createElement('lastmod', dol_print_date($db->jdate($objp->tms), 'dayrfc', 'gmt'));
2387  $changefreq = $domtree->createElement('changefreq', 'weekly'); // TODO Manage other values
2388  $priority = $domtree->createElement('priority', '1');
2389 
2390  $url->appendChild($loc);
2391  $url->appendChild($lastmod);
2392  // Add suggested frequency for refresh
2393  if (!empty($conf->global->WEBSITE_SITEMAPS_ADD_WEEKLY_FREQ)) {
2394  $url->appendChild($changefreq);
2395  }
2396  // Add higher priority for home page
2397  if ($objp->fk_default_home == $objp->rowid) {
2398  $url->appendChild($priority);
2399  }
2400 
2401  // Now add alternate language entries
2402  if ($object->isMultiLang()) {
2403  $alternatefound = 0;
2404 
2405  // Add page "translation of"
2406  $translationof = $objp->fk_page;
2407  if ($translationof) {
2408  $tmppage = new WebsitePage($db);
2409  $tmppage->fetch($translationof);
2410  if ($tmppage->id > 0) {
2411  $tmpshortlangcode = '';
2412  if ($tmppage->lang) {
2413  $tmpshortlangcode = preg_replace('/[_-].*$/', '', $tmppage->lang); // en_US or en-US -> en
2414  }
2415  if (empty($tmpshortlangcode)) {
2416  $tmpshortlangcode = preg_replace('/[_-].*$/', '', $object->lang); // en_US or en-US -> en
2417  }
2418  if ($tmpshortlangcode != $shortlangcode) {
2419  $xhtmllink = $domtree->createElement('xhtml:link', '');
2420  $xhtmllink->setAttribute("rel", "alternate");
2421  $xhtmllink->setAttribute("hreflang", $tmpshortlangcode);
2422  $xhtmllink->setAttribute("href", $domainname.($objp->fk_default_home == $tmppage->id ? '/' : (($tmpshortlangcode != substr($object->lang, 0, 2)) ? '/'.$tmpshortlangcode : '').'/'.$tmppage->pageurl.'.php'));
2423  $url->appendChild($xhtmllink);
2424 
2425  $alternatefound++;
2426  }
2427  }
2428  }
2429 
2430  // Add "has translation pages"
2431  $sql = 'SELECT rowid as id, lang, pageurl from '.MAIN_DB_PREFIX.'website_page';
2432  $sql .= " WHERE status = ".((int) WebsitePage::STATUS_VALIDATED).' AND fk_page IN ('.$db->sanitize($objp->rowid.($translationof ? ", ".$translationof : "")).")";
2433  $resqlhastrans = $db->query($sql);
2434  if ($resqlhastrans) {
2435  $num_rows_hastrans = $db->num_rows($resqlhastrans);
2436  if ($num_rows_hastrans > 0) {
2437  while ($objhastrans = $db->fetch_object($resqlhastrans)) {
2438  $tmpshortlangcode = '';
2439  if ($objhastrans->lang) {
2440  $tmpshortlangcode = preg_replace('/[_-].*$/', '', $objhastrans->lang); // en_US or en-US -> en
2441  }
2442  if ($tmpshortlangcode != $shortlangcode) {
2443  $xhtmllink = $domtree->createElement('xhtml:link', '');
2444  $xhtmllink->setAttribute("rel", "alternate");
2445  $xhtmllink->setAttribute("hreflang", $tmpshortlangcode);
2446  $xhtmllink->setAttribute("href", $domainname.($objp->fk_default_home == $objhastrans->id ? '/' : (($tmpshortlangcode != substr($object->lang, 0, 2) ? '/'.$tmpshortlangcode : '')).'/'.$objhastrans->pageurl.'.php'));
2447  $url->appendChild($xhtmllink);
2448 
2449  $alternatefound++;
2450  }
2451  }
2452  }
2453  } else {
2454  dol_print_error($db);
2455  }
2456 
2457  if ($alternatefound) {
2458  // Add myself
2459  $xhtmllink = $domtree->createElement('xhtml:link', '');
2460  $xhtmllink->setAttribute("rel", "alternate");
2461  $xhtmllink->setAttribute("hreflang", $shortlangcode);
2462  $xhtmllink->setAttribute("href", $domainname.'/'.$pageurl);
2463  $url->appendChild($xhtmllink);
2464  }
2465  }
2466 
2467  // Now add sitempas extension for news
2468  // TODO When adding and when not ?
2469  /*<news:news>
2470  <news:publication>
2471  <news:name>The Example Times</news:name>
2472  <news:language>en</news:language>
2473  </news:publication>
2474  <news:publication_date>2008-12-23</news:publication_date>
2475  <news:title>Companies A, B in Merger Talks</news:title>
2476  </news:news>
2477  */
2478 
2479  $root->appendChild($url);
2480  $i++;
2481  }
2482  $domtree->appendChild($root);
2483  if ($domtree->save($tempdir.$xmlname)) {
2484  if (!empty($conf->global->MAIN_UMASK)) {
2485  @chmod($tempdir.$xmlname, octdec($conf->global->MAIN_UMASK));
2486  }
2487  setEventMessages($langs->trans("SitemapGenerated", $xmlname), null, 'mesgs');
2488  } else {
2489  setEventMessages($object->error, $object->errors, 'errors');
2490  }
2491  }
2492  } else {
2493  dol_print_error($db);
2494  }
2495 
2496  // Add the entry Sitemap: into the robot file.
2497  $robotcontent = @file_get_contents($filerobot);
2498  $result = preg_replace('/<?php // BEGIN PHP[^?]END PHP ?>\n/ims', '', $robotcontent);
2499  if ($result) {
2500  $robotcontent = $result;
2501  }
2502  $robotsitemap = "Sitemap: ".$domainname."/".$xmlname;
2503  $result = strpos($robotcontent, 'Sitemap: ');
2504  if ($result) {
2505  $result = preg_replace('/Sitemap:.*/', $robotsitemap, $robotcontent);
2506  $robotcontent = $result ? $result : $robotcontent;
2507  } else {
2508  $robotcontent .= $robotsitemap."\n";
2509  }
2510  $result = dolSaveRobotFile($filerobot, $robotcontent);
2511  if (!$result) {
2512  $error++;
2513  setEventMessages('Failed to write file '.$filerobot, null, 'errors');
2514  }
2515  $action = 'preview';
2516 }
2517 
2518 
2519 /*
2520  * View
2521  */
2522 
2523 $form = new Form($db);
2524 $formadmin = new FormAdmin($db);
2525 $formwebsite = new FormWebsite($db);
2526 $formother = new FormOther($db);
2527 $formconfirm = "";
2528 
2529 // Confirm generation of website sitemaps
2530 if ($action == 'confirmgeneratesitemaps') {
2531  $formconfirm = $form->formconfirm($_SERVER["PHP_SELF"].'?website='.urlencode($website->ref), $langs->trans('ConfirmSitemapsCreation'), $langs->trans('ConfirmGenerateSitemaps', $object->ref), 'generatesitemaps', '', "yes", 1);
2532  $action = 'preview';
2533 }
2534 $helpurl = 'EN:Module_Website|FR:Module_Website_FR|ES:M&oacute;dulo_Website';
2535 
2536 $arrayofjs = array(
2537  '/includes/ace/src/ace.js',
2538  '/includes/ace/src/ext-statusbar.js',
2539  '/includes/ace/src/ext-language_tools.js',
2540  //'/includes/ace/src/ext-chromevox.js'
2541  //'/includes/jquery/plugins/jqueryscoped/jquery.scoped.js',
2542 );
2543 $arrayofcss = array();
2544 
2545 $moreheadcss = '';
2546 $moreheadjs = '';
2547 
2548 $arrayofjs[] = 'includes/jquery/plugins/blockUI/jquery.blockUI.js';
2549 $arrayofjs[] = 'core/js/blockUI.js'; // Used by ecm/tpl/enabledfiletreeajax.tpl.php
2550 if (empty($conf->global->MAIN_ECM_DISABLE_JS)) {
2551  $arrayofjs[] = "includes/jquery/plugins/jqueryFileTree/jqueryFileTree.js";
2552 }
2553 
2554 $moreheadjs .= '<script type="text/javascript">'."\n";
2555 $moreheadjs .= 'var indicatorBlockUI = \''.DOL_URL_ROOT."/theme/".$conf->theme."/img/working.gif".'\';'."\n";
2556 $moreheadjs .= '</script>'."\n";
2557 
2558 llxHeader($moreheadcss.$moreheadjs, $langs->trans("WebsiteSetup"), $helpurl, '', 0, 0, $arrayofjs, $arrayofcss, '', '', '<!-- Begin div class="fiche" -->'."\n".'<div class="fichebutwithotherclass">');
2559 
2560 print "\n";
2561 print '<!-- Open form for all page -->'."\n";
2562 print '<form action="'.$_SERVER["PHP_SELF"].($action == 'file_manager' ? '?uploadform=1': '').'" method="POST" enctype="multipart/form-data" class="websiteformtoolbar">';
2563 print '<input type="hidden" name="token" value="'.newToken().'">';
2564 print '<input type="hidden" name="backtopage" value="'.$backtopage.'">';
2565 print '<input type="hidden" name="dol_openinpopup" value="'.$dol_openinpopup.'">';
2566 
2567 if ($action == 'createsite') {
2568  print '<input type="hidden" name="action" value="addsite">';
2569 }
2570 if ($action == 'createcontainer') {
2571  print '<input type="hidden" name="action" value="addcontainer">';
2572 }
2573 if ($action == 'editcss') {
2574  print '<input type="hidden" name="action" value="updatecss">';
2575 }
2576 if ($action == 'editmenu') {
2577  print '<input type="hidden" name="action" value="updatemenu">';
2578 }
2579 if ($action == 'setashome') {
2580  print '<input type="hidden" name="action" value="updateashome">';
2581 }
2582 if ($action == 'editmeta') {
2583  print '<input type="hidden" name="action" value="updatemeta">';
2584 }
2585 if ($action == 'editsource') {
2586  print '<input type="hidden" name="action" value="updatesource">';
2587 }
2588 if ($action == 'editcontent') {
2589  print '<input type="hidden" name="action" value="updatecontent">';
2590 }
2591 if ($action == 'edit') {
2592  print '<input type="hidden" name="action" value="update">';
2593 }
2594 if ($action == 'importsite') {
2595  print '<input type="hidden" name="action" value="importsiteconfirm">';
2596 }
2597 if ($action == 'file_manager') {
2598  print '<input type="hidden" name="action" value="file_manager">';
2599 }
2600 if ($action == 'replacesite') {
2601  print '<input type="hidden" name="action" value="replacesiteconfirm">';
2602 }
2603 if ($action == 'replacesiteconfirm') {
2604  print '<input type="hidden" name="action" value="replacesiteconfirm">';
2605 }
2606 
2607 print '<div>';
2608 
2609 // Add a margin under toolbar ?
2610 $style = '';
2611 if ($action != 'preview' && $action != 'editcontent' && $action != 'editsource' && !GETPOST('createpagefromclone', 'alphanohtml')) {
2612  $style = ' margin-bottom: 5px;';
2613 }
2614 
2615 
2616 if (!GETPOST('hide_websitemenu')) {
2617  $disabled = '';
2618  if (empty($user->rights->website->write)) {
2619  $disabled = ' disabled="disabled"';
2620  }
2621  $disabledexport = '';
2622  if (empty($user->rights->website->export)) {
2623  $disabledexport = ' disabled="disabled"';
2624  }
2625 
2626  if ($websitekey) {
2627  $virtualurl = '';
2628  $dataroot = DOL_DATA_ROOT.($conf->entity > 1 ? '/'.$conf->entity : '').'/website/'.$websitekey;
2629  if (!empty($object->virtualhost)) {
2630  $virtualurl = $object->virtualhost;
2631  }
2632  }
2633 
2634  $array = array();
2635  if ($object->id > 0) {
2636  $array = $objectpage->fetchAll($object->id, 'ASC,ASC', 'type_container,pageurl');
2637  $object->lines = $array;
2638  }
2639  if (!is_array($array) && $array < 0) {
2640  dol_print_error('', $objectpage->error, $objectpage->errors);
2641  }
2642  $atleastonepage = (is_array($array) && count($array) > 0);
2643 
2644 
2645  //var_dump($objectpage);exit;
2646  print '<div class="centpercent websitebar'.(GETPOST('dol_openinpopup', 'aZ09') ? ' hidden' : '').'">';
2647 
2648  //
2649  // Toolbar for websites
2650  //
2651 
2652  print '<!-- Bar for website -->';
2653  if ($action != 'file_manager') {
2654  print '<span class="websiteselection hideonsmartphoneimp minwidth100 tdoverflowmax100">';
2655  print $langs->trans("Website").': ';
2656  print '</span>';
2657 
2658  $urltocreatenewwebsite = $_SERVER["PHP_SELF"].'?action=createsite';
2659  if (empty($conf->use_javascript_ajax)) {
2660  print '<span class="websiteselection hideonsmartphoneimp">';
2661  print '<a href="'.$urltocreatenewwebsite.'" class="button bordertransp"'.$disabled.' title="'.dol_escape_htmltag($langs->trans("AddWebsite")).'"><span class="fa fa-plus-circle valignmiddle btnTitle-icon"><span></a>';
2662  print '</span>';
2663  }
2664 
2665  // List of website
2666  print '<span class="websiteselection">';
2667  $out = '';
2668  $out .= '<select name="website" class="minwidth100 width200 maxwidth150onsmartphone" id="website">';
2669  if (empty($object->records)) {
2670  $out .= '<option value="-1">&nbsp;</option>';
2671  }
2672  if (!empty($conf->use_javascript_ajax)) {
2673  $valueoption = '<span class="classlink">'.img_picto('', 'add', 'class="paddingrightonly"').$langs->trans("AddWebsite").'</span>';
2674  $out .= '<option value="-2" data-html="'.dol_escape_htmltag($valueoption).'">'.$valueoption.'</option>';
2675  }
2676  // Loop on each sites
2677  $i = 0;
2678  foreach ($object->records as $key => $valwebsite) {
2679  if (empty($websitekey)) {
2680  if ($action != 'createsite') {
2681  $websitekey = $valwebsite->ref;
2682  }
2683  }
2684 
2685  $out .= '<option value="'.$valwebsite->ref.'"';
2686  if ($websitekey == $valwebsite->ref) {
2687  $out .= ' selected'; // To preselect a value
2688  }
2689  //$outoption = $valwebsite->getLibStatut(3).' '.$valwebsite->ref.' ';
2690  $outoption = (($valwebsite->status == $valwebsite::STATUS_DRAFT) ? '<span class="opacitymedium">' : '').$valwebsite->ref.(($valwebsite->status == $valwebsite::STATUS_DRAFT) ? '</span>' : '');
2691  $out .= ' data-html="'.dol_escape_htmltag($outoption).'"';
2692  $out .= '>';
2693  $out .= $valwebsite->ref;
2694  $out .= '</option>';
2695  $i++;
2696  }
2697  $out .= '</select>';
2698  $out .= ajax_combobox('website');
2699 
2700  if (!empty($conf->use_javascript_ajax)) {
2701  $out .= '<script type="text/javascript">';
2702  $out .= 'jQuery(document).ready(function () {';
2703  $out .= ' jQuery("#website").change(function () {';
2704  $out .= ' console.log("We select "+jQuery("#website option:selected").val());';
2705  $out .= ' if (jQuery("#website option:selected").val() == \'-2\') {';
2706  $out .= ' window.location.href = "'.dol_escape_js($urltocreatenewwebsite).'";';
2707  $out .= ' } else {';
2708  $out .= ' window.location.href = "'.$_SERVER["PHP_SELF"].'?website="+jQuery("#website option:selected").val();';
2709  $out .= ' }';
2710  $out .= ' });';
2711  $out .= '});';
2712  $out .= '</script>';
2713  }
2714  print $out;
2715 
2716  if (empty($conf->use_javascript_ajax)) {
2717  print '<input type="image" class="valignmiddle" src="'.img_picto('', 'refresh', '', 0, 1).'" name="refreshsite" value="'.$langs->trans("Load").'">';
2718  }
2719 
2720  if ($websitekey && $websitekey != '-1' && ($action == 'preview' || $action == 'createfromclone' || $action == 'createpagefromclone' || $action == 'deletesite')) {
2721  print ' &nbsp; ';
2722 
2723  //print '<input type="submit" class="button bordertransp"'.$disabled.' value="'.dol_escape_htmltag($langs->trans("EditCss")).'" name="editcss">';
2724  print '<a href="'.$_SERVER["PHP_SELF"].'?website='.$object->ref.'&pageid='.$pageid.'&action=editcss&token='.newToken().'" class="button bordertransp" title="'.dol_escape_htmltag($langs->trans("EditCss")).'"'.$disabled.'><span class="fa fa-cog paddingrightonly"></span><span class="hideonsmartphone">'.dol_escape_htmltag($langs->trans("EditCss")).'</span></a>';
2725 
2726  $importlabel = $langs->trans("ImportSite");
2727  $exportlabel = $langs->trans("ExportSite");
2728  if (!empty($conf->dol_optimize_smallscreen)) {
2729  $importlabel = $langs->trans("Import");
2730  $exportlabel = $langs->trans("Export");
2731  }
2732 
2733  if ($atleastonepage) {
2734  print '<input type="submit" class="button bordertransp" disabled="disabled" value="'.dol_escape_htmltag($importlabel).'" name="importsite">';
2735  } else {
2736  print '<input type="submit" class="button bordertransp"'.$disabled.' value="'.dol_escape_htmltag($importlabel).'" name="importsite">';
2737  }
2738 
2739  //print '<input type="submit" class="button"'.$disabled.' value="'.dol_escape_htmltag($langs->trans("EditMenu")).'" name="editmenu">';
2740  print '<input type="submit" class="button bordertransp"'.$disabledexport.' value="'.dol_escape_htmltag($exportlabel).'" name="exportsite">';
2741 
2742  print '<input type="submit" class="button bordertransp"'.$disabled.' value="'.dol_escape_htmltag($langs->trans("CloneSite")).'" name="createfromclone">';
2743 
2744  // Delete website
2745  if ($website->status == $website::STATUS_VALIDATED) {
2746  print '<input type="submit" class="buttonDelete bordertransp" name="deletesite" value="'.$langs->trans("Delete").'" disabled="disabled" title="'.dol_escape_htmltag($langs->trans("WebsiteMustBeDisabled")).'">';
2747  } else {
2748  print '<input type="submit" class="buttonDelete bordertransp" name="deletesite" value="'.$langs->trans("Delete").'"'.($atleastonepage ? ' disabled="disabled"' : '').'>';
2749  }
2750 
2751  // Regenerate all pages
2752  print '<a href="'.$_SERVER["PHP_SELF"].'?action=regeneratesite&token='.newToken().'&website='.urlencode($website->ref).'" class="button bordertransp"'.$disabled.' title="'.dol_escape_htmltag($langs->trans("RegenerateWebsiteContent")).'"><span class="far fa-hdd"></span></a>';
2753 
2754  // Generate site map
2755  print '<a href="'.$_SERVER["PHP_SELF"].'?action=confirmgeneratesitemaps&token='.newToken().'&website='.urlencode($website->ref).'" class="button bordertransp"'.$disabled.' title="'.dol_escape_htmltag($langs->trans("GenerateSitemaps")).'"><span class="fa fa-sitemap"></span></a>';
2756 
2757  print '<a href="'.$_SERVER["PHP_SELF"].'?action=replacesite&token='.newToken().'&website='.urlencode($website->ref).'" class="button bordertransp"'.$disabled.' title="'.dol_escape_htmltag($langs->trans("ReplaceWebsiteContent")).'"><span class="fa fa-search"></span></a>';
2758  }
2759 
2760  print '</span>';
2761 
2762  if ($websitekey && $websitekey != '-1' && ($action == 'preview' || $action == 'createfromclone' || $action == 'createpagefromclone' || $action == 'deletesite')) {
2763  print '<span class="websiteselection">';
2764 
2765  print dolButtonToOpenUrlInDialogPopup('file_manager', $langs->transnoentitiesnoconv("MediaFiles"), '<span class="fa fa-image"></span>', '/website/index.php?action=file_manager&website='.urlencode($website->ref).'&section_dir='.urlencode('image/'.$website->ref.'/'), $disabled);
2766 
2767  if (!empty($conf->categorie->enabled)) {
2768  //print '<a href="'.DOL_URL_ROOT.'/categories/index.php?leftmenu=website&dol_hide_leftmenu=1&nosearch=1&type=website_page&website='.$website->ref.'" class="button bordertransp"'.$disabled.' title="'.dol_escape_htmltag($langs->trans("Categories")).'"><span class="fa fa-tags"></span></a>';
2769  print dolButtonToOpenUrlInDialogPopup('categories', $langs->transnoentitiesnoconv("Categories"), '<span class="fa fa-tags"></span>', '/categories/index.php?leftmenu=website&nosearch=1&type=website_page&website='.urlencode($website->ref), $disabled);
2770  }
2771 
2772  print '</span>';
2773  }
2774  } else {
2775  print '<input type="hidden" name="website" id="website" value="'.$websitekey.'">';
2776  }
2777 
2778 
2779  print '<span class="websitetools">';
2780 
2781  if ($action == 'preview' || $action == 'createfromclone' || $action == 'createpagefromclone' || $action == 'deletesite') {
2782  $urlext = $virtualurl;
2783  $urlint = $urlwithroot.'/public/website/index.php?website='.$websitekey;
2784 
2785  print '<span class="websiteinputurl valignmiddle" id="websiteinputurl">';
2786  $linktotestonwebserver = '<a href="'.($virtualurl ? $virtualurl : '#').'" class="valignmiddle">';
2787  $linktotestonwebserver .= '<span class="hideonsmartphone paddingrightonly">'.$langs->trans("TestDeployOnWeb", $virtualurl).'</span>'.img_picto('', 'globe');
2788  $linktotestonwebserver .= '</a>';
2789  $htmltext = '';
2790  if (empty($object->fk_default_home)) {
2791  $htmltext .= '<br><span class="error">'.$langs->trans("YouMustDefineTheHomePage").'</span><br><br>';
2792  } elseif (empty($virtualurl)) {
2793  //$htmltext .= '<br><span class="error">'.$langs->trans("VirtualHostUrlNotDefined").'</span><br><br>';
2794  } else {
2795  $htmltext .= '<br><center>'.$langs->trans("GoTo").' <a href="'.$virtualurl.'" target="_website">'.$virtualurl.'</a></center><br>';
2796  }
2797  if (!empty($conf->global->WEBSITE_REPLACE_INFO_ABOUT_USAGE_WITH_WEBSERVER)) {
2798  $htmltext .= '<!-- Message defined translate key set into WEBSITE_REPLACE_INFO_ABOUT_USAGE_WITH_WEBSERVER -->';
2799  $htmltext .= '<br>'.$langs->trans($conf->global->WEBSITE_REPLACE_INFO_ABOUT_USAGE_WITH_WEBSERVER);
2800  } else {
2801  $htmltext .= $langs->trans("SetHereVirtualHost", $dataroot);
2802  $htmltext .= '<br>';
2803  $htmltext .= '<br>'.$langs->trans("CheckVirtualHostPerms", $langs->transnoentitiesnoconv("ReadPerm"), DOL_DOCUMENT_ROOT);
2804  $htmltext .= '<br>'.$langs->trans("CheckVirtualHostPerms", $langs->transnoentitiesnoconv("WritePerm"), '{s1}');
2805  $htmltext = str_replace('{s1}', DOL_DATA_ROOT.'/website<br>'.DOL_DATA_ROOT.'/medias', $htmltext);
2806 
2807  $examplewithapache = '#php_admin_value open_basedir /tmp/:'.DOL_DOCUMENT_ROOT.':'.DOL_DATA_ROOT.':/dev/urandom'."\n";
2808  $examplewithapache .= '<Directory "'.DOL_DOCUMENT_ROOT.'">'."\n";
2809  $examplewithapache .= 'AllowOverride FileInfo Options
2810  Options -Indexes -MultiViews -FollowSymLinks -ExecCGI
2811  Require all granted
2812  </Directory>
2813  <Directory "'.DOL_DATA_ROOT.'/website">
2814  AllowOverride FileInfo Options
2815  Options -Indexes -MultiViews +FollowSymLinks -ExecCGI
2816  Require all granted
2817  </Directory>
2818  <Directory "'.DOL_DATA_ROOT.'/medias">
2819  AllowOverride FileInfo Options
2820  Options -Indexes -MultiViews -FollowSymLinks -ExecCGI
2821  Require all granted
2822  </Directory>';
2823 
2824  $htmltext .= '<br>'.$langs->trans("ExampleToUseInApacheVirtualHostConfig").':<br>';
2825  $htmltext .= '<div class="centpercent exampleapachesetup">'.dol_nl2br(dol_escape_htmltag($examplewithapache, 1, 1)).'</div>';
2826 
2827  $htmltext .= '<br>';
2828  $htmltext .= $langs->trans("YouCanAlsoTestWithPHPS", $dataroot);
2829  $htmltext .= '<br>';
2830  $htmltext .= '<br>';
2831  $htmltext .= $langs->trans("YouCanAlsoDeployToAnotherWHP");
2832  }
2833  print $form->textwithpicto($linktotestonwebserver, $htmltext, 1, 'none', 'valignmiddle', 0, 3, 'helpvirtualhost');
2834  print '</span>';
2835  }
2836 
2837  if (in_array($action, array('editcss', 'editmenu', 'file_manager', 'replacesite', 'replacesiteconfirm'))) {
2838  if ($action == 'editcss') {
2839  print '<input type="submit" id="savefileandstay" class="button buttonforacesave hideonsmartphone small" value="'.dol_escape_htmltag($langs->trans("SaveAndStay")).'" name="updateandstay">';
2840  }
2841  if (preg_match('/^create/', $action) && $action != 'file_manager' && $action != 'replacesite' && $action != 'replacesiteconfirm') {
2842  print '<input type="submit" id="savefile" class="button buttonforacesave button-save small" value="'.dol_escape_htmltag($langs->trans("Save")).'" name="update">';
2843  }
2844  if (preg_match('/^edit/', $action) && $action != 'file_manager' && $action != 'replacesite' && $action != 'replacesiteconfirm') {
2845  print '<input type="submit" id="savefile" class="button buttonforacesave button-save small" value="'.dol_escape_htmltag($langs->trans("Save")).'" name="update">';
2846  }
2847  if ($action != 'preview') {
2848  print '<input type="submit" class="button button-cancel small" value="'.dol_escape_htmltag($langs->trans("Cancel")).'" name="cancel">';
2849  }
2850  }
2851 
2852  print '</span>';
2853 
2854  //
2855  // Toolbar for pages
2856  //
2857 
2858  if ($websitekey && $websitekey != '-1' && !in_array($action, array('editcss', 'editmenu', 'importsite', 'file_manager', 'replacesite', 'replacesiteconfirm')) && !$file_manager) {
2859  print '</div>'; // Close current websitebar to open a new one
2860 
2861  print '<!-- Bar for websitepage -->';
2862  print '<div class="centpercent websitebar"'.($style ? ' style="'.$style.'"' : '').'">';
2863 
2864  print '<span class="websiteselection hideonsmartphoneimp minwidth100 tdoverflowmax100">';
2865  print $langs->trans("PageContainer").': ';
2866  print '</span>';
2867 
2868  print '<span class="websiteselection">';
2869  print '<a href="'.$_SERVER["PHP_SELF"].'?action=createcontainer&token='.newToken().'&website='.urlencode($website->ref).'" class="button bordertransp"'.$disabled.' title="'.dol_escape_htmltag($langs->trans("AddPage")).'"><span class="fa fa-plus-circle valignmiddle btnTitle-icon"></span></a>';
2870  print '</span>';
2871 
2872  //print '<span class="websiteselection">';
2873 
2874  if ($action != 'addcontainer') {
2875  $out = '';
2876 
2877  $s = $formwebsite->selectContainer($website, 'pageid', $pageid, 0, $action, 'maxwidth200onsmartphone');
2878 
2879  if ($formwebsite->num > 0) {
2880  $out .= '<span class="websiteselection">';
2881  $out .= $s;
2882  $out .= '</span>';
2883 
2884  $urltocreatenewpage = $_SERVER["PHP_SELF"].'?action=createcontainer&token='.newToken().'&website='.urlencode($website->ref);
2885 
2886  if (!empty($conf->use_javascript_ajax)) {
2887  $out .= '<script type="text/javascript">';
2888  $out .= 'jQuery(document).ready(function () {';
2889  $out .= ' jQuery("#pageid").change(function () {';
2890  $out .= ' console.log("We select "+jQuery("#pageid option:selected").val());';
2891  $out .= ' if (jQuery("#pgeid option:selected").val() == \'-2\') {';
2892  $out .= ' window.location.href = "'.$urltocreatenewpage.'";';
2893  $out .= ' } else {';
2894  $out .= ' window.location.href = "'.$_SERVER["PHP_SELF"].'?website='.urlencode($website->ref).'&pageid="+jQuery("#pageid option:selected").val();';
2895  $out .= ' }';
2896  $out .= ' });';
2897  $out .= '});';
2898  $out .= '</script>';
2899  }
2900  }
2901 
2902  print $out;
2903  } else {
2904  print $langs->trans("New");
2905  }
2906 
2907 
2908  print '<span class="websiteselection">';
2909 
2910  print '<input type="image" class="valignmiddle" src="'.img_picto('', 'refresh', '', 0, 1).'" name="refreshpage" value="'.$langs->trans("Load").'"'.(($atleastonepage && $action != 'editsource') ? '' : ' disabled="disabled"').'>';
2911 
2912  // Print nav arrows
2913  $pagepreviousid = 0;
2914  $pagenextid = 0;
2915  if ($pageid) {
2916  $sql = "SELECT MAX(rowid) as pagepreviousid FROM ".MAIN_DB_PREFIX."website_page WHERE rowid < ".((int) $pageid)." AND fk_website = ".((int) $object->id);
2917  $resql = $db->query($sql);
2918  if ($resql) {
2919  $obj = $db->fetch_object($resql);
2920  if ($obj) {
2921  $pagepreviousid = $obj->pagepreviousid;
2922  }
2923  } else {
2924  dol_print_error($db);
2925  }
2926  $sql = "SELECT MIN(rowid) as pagenextid FROM ".MAIN_DB_PREFIX."website_page WHERE rowid > ".((int) $pageid)." AND fk_website = ".((int) $object->id);
2927  $resql = $db->query($sql);
2928  if ($resql) {
2929  $obj = $db->fetch_object($resql);
2930  if ($obj) {
2931  $pagenextid = $obj->pagenextid;
2932  }
2933  } else {
2934  dol_print_error($db);
2935  }
2936  }
2937 
2938  if ($pagepreviousid) {
2939  print '<a class="valignmiddle" href="'.$_SERVER['PHP_SELF'].'?website='.urlencode($object->ref).'&pageid='.$pagepreviousid.'&action='.$action.'&token='.newToken().'">'.img_previous($langs->trans("PreviousContainer")).'</a>';
2940  } else {
2941  print '<span class="valignmiddle opacitymedium">'.img_previous($langs->trans("Previous")).'</span>';
2942  }
2943  if ($pagenextid) {
2944  print '<a class="valignmiddle" href="'.$_SERVER['PHP_SELF'].'?website='.urlencode($object->ref).'&pageid='.$pagenextid.'&action='.$action.'&token='.newToken().'">'.img_next($langs->trans("NextContainer")).'</a>';
2945  } else {
2946  print '<span class="valignmiddle opacitymedium">'.img_next($langs->trans("Next")).'</span>';
2947  }
2948 
2949  print '</span>';
2950 
2951  $websitepage = new WebSitePage($db);
2952  if ($pageid > 0 && ($action == 'preview' || $action == 'createfromclone' || $action == 'createpagefromclone')) {
2953  $websitepage->fetch($pageid);
2954  }
2955 
2956  if ($action == 'preview' || $action == 'createfromclone' || $action == 'createpagefromclone' || $action == 'deletesite') {
2957  $disabled = '';
2958  if (empty($user->rights->website->write)) {
2959  $disabled = ' disabled="disabled"';
2960  }
2961 
2962  // Confirmation delete site
2963  if ($action == 'deletesite') {
2964  // Create an array for form
2965  $formquestion = array(
2966  array('type' => 'checkbox', 'name' => 'delete_also_js', 'label' => $langs->trans("DeleteAlsoJs"), 'value' => 0),
2967  array('type' => 'checkbox', 'name' => 'delete_also_medias', 'label' => $langs->trans("DeleteAlsoMedias"), 'value' => 0),
2968  //array('type' => 'other','name' => 'newlang','label' => $langs->trans("Language"), 'value' => $formadmin->select_language(GETPOST('newlang', 'aZ09')?GETPOST('newlang', 'aZ09'):$langs->defaultlang, 'newlang', 0, null, '', 0, 0, 'minwidth200')),
2969  //array('type' => 'other','name' => 'newwebsite','label' => $langs->trans("WebSite"), 'value' => $formwebsite->selectWebsite($object->id, 'newwebsite', 0))
2970  );
2971 
2972  $formconfirm = $form->formconfirm($_SERVER["PHP_SELF"].'?id='.$object->id, $langs->trans('DeleteWebsite'), '', 'confirm_deletesite', $formquestion, 0, 1, 200);
2973 
2974  print $formconfirm;
2975  }
2976 
2977  // Confirmation to clone
2978  if ($action == 'createfromclone') {
2979  // Create an array for form
2980  $formquestion = array(
2981  array('type' => 'text', 'name' => 'siteref', 'label'=> $langs->trans("WebSite"), 'value'=> 'copy_of_'.$object->ref)
2982  );
2983 
2984  $formconfirm = $form->formconfirm($_SERVER["PHP_SELF"].'?id='.$object->id, $langs->trans('CloneSite'), '', 'confirm_createfromclone', $formquestion, 0, 1, 200);
2985 
2986  print $formconfirm;
2987  }
2988 
2989  if ($pageid > 0 && $atleastonepage) { // pageid can be set without pages, if homepage of site is set and all pages were removed
2990  // Confirmation to clone
2991  if ($action == 'createpagefromclone') {
2992  // Create an array for form
2993  $preselectedlanguage = GETPOST('newlang', 'aZ09') ? GETPOST('newlang', 'aZ09') : ''; // Dy default, we do not force any language on pages
2994  $onlylang = array();
2995  if ($website->otherlang) {
2996  if (!empty($website->lang)) {
2997  $onlylang[$website->lang] = $website->lang.' ('.$langs->trans("Default").')';
2998  }
2999  foreach (explode(',', $website->otherlang) as $langkey) {
3000  if (empty(trim($langkey))) continue;
3001  $onlylang[$langkey] = $langkey;
3002  }
3003  $textifempty = $langs->trans("Default");
3004  } else {
3005  $onlylang['none'] = 'none';
3006  $textifempty = $langs->trans("Default");
3007  }
3008  $formquestion = array(
3009  array('type' => 'hidden', 'name' => 'sourcepageurl', 'value'=> $objectpage->pageurl),
3010  array('type' => 'other', 'tdclass'=>'fieldrequired', 'name' => 'newwebsite', 'label' => $langs->trans("WebSite"), 'value' => $formwebsite->selectWebsite($object->id, 'newwebsite', 0)),
3011  array('type' => 'text', 'tdclass'=>'maxwidth200 fieldrequired', 'moreattr'=>'autofocus="autofocus"', 'name' => 'newtitle', 'label'=> $langs->trans("WEBSITE_TITLE"), 'value'=> $langs->trans("CopyOf").' '.$objectpage->title),
3012  array('type' => 'text', 'tdclass'=>'maxwidth200', 'name' => 'newpageurl', 'label'=> $langs->trans("WEBSITE_PAGENAME"), 'value'=> '')
3013  );
3014  if (count($onlylang) > 1) {
3015  $formquestion[] = array('type' => 'checkbox', 'tdclass'=>'maxwidth200', 'name' => 'is_a_translation', 'label' => $langs->trans("PageIsANewTranslation"), 'value' => 0, 'morecss'=>'margintoponly');
3016  }
3017 
3018  $value= $formadmin->select_language($preselectedlanguage, 'newlang', 0, null, $textifempty, 0, 0, 'minwidth200', 1, 0, 0, $onlylang, 1);
3019  $formquestion[] = array('type' => 'other', 'name' => 'newlang', 'label' => $form->textwithpicto($langs->trans("Language"), $langs->trans("DefineListOfAltLanguagesInWebsiteProperties")), 'value' => $value);
3020 
3021  $formconfirm = $form->formconfirm($_SERVER["PHP_SELF"].'?website='.$object->ref.'&pageid='.$pageid, $langs->trans('ClonePage'), '', 'confirm_createpagefromclone', $formquestion, 0, 1, 300, 550);
3022 
3023  print $formconfirm;
3024  }
3025 
3026  print '<span class="websiteselection">';
3027 
3028  print ' &nbsp; ';
3029 
3030  //print '<input type="submit" class="button bordertransp"'.$disabled.' value="'.dol_escape_htmltag($langs->trans("EditPageMeta")).'" name="editmeta">';
3031  print '<a href="'.$_SERVER["PHP_SELF"].'?website='.$object->ref.'&pageid='.$pageid.'&action=editmeta&token='.newToken().'" class="button bordertransp" title="'.dol_escape_htmltag($langs->trans("EditPageMeta")).'"'.$disabled.'><span class="fa fa-cog paddingrightonly"></span><span class="hideonsmartphone">'.dol_escape_htmltag($langs->trans("EditPageMeta")).'</span></a>';
3032 
3033  //print '<input type="submit" class="button bordertransp"'.$disabled.' value="'.dol_escape_htmltag($langs->trans("EditHTMLSource")).'" name="editsource">';
3034  print '<a href="'.$_SERVER["PHP_SELF"].'?website='.$object->ref.'&pageid='.$pageid.'&action=editsource&token='.newToken().'" class="button bordertransp"'.$disabled.'>'.dol_escape_htmltag($langs->trans($conf->dol_optimize_smallscreen ? "HTML" : "EditHTMLSource")).'</a>';
3035  print '</span>';
3036 
3037  print '<!-- button EditInLine and ShowSubcontainers -->'."\n";
3038  print '<div class="websiteselectionsection inline-block">';
3039 
3040  print '<div class="inline-block marginrightonly">'; // Button include dynamic contant
3041  print $langs->trans("ShowSubcontainers");
3042  if (empty($conf->global->WEBSITE_SUBCONTAINERSINLINE)) {
3043  print '<a class="nobordertransp nohoverborder marginleftonlyshort valignmiddle"'.$disabled.' href="'.$_SERVER["PHP_SELF"].'?website='.$object->ref.'&pageid='.$websitepage->id.'&action=setshowsubcontainers&token='.newToken().'">'.img_picto($langs->trans("ShowSubContainersOnOff", $langs->transnoentitiesnoconv("Off")), 'switch_off', '', false, 0, 0, '', 'nomarginleft').'</a>';
3044  } else {
3045  print '<a class="nobordertransp nohoverborder marginleftonlyshort valignmiddle"'.$disabled.' href="'.$_SERVER["PHP_SELF"].'?website='.$object->ref.'&pageid='.$websitepage->id.'&action=unsetshowsubcontainers&token='.newToken().'">'.img_picto($langs->trans("ShowSubContainersOnOff", $langs->transnoentitiesnoconv("On")), 'switch_on', '', false, 0, 0, '', 'nomarginleft').'</a>';
3046  }
3047  print '</div>';
3048 
3049  print '<div class="inline-block marginrightonly">'; // Button edit inline
3050 
3051  print '<span id="switchckeditorinline">'."\n";
3052  print '<!-- Code to enabled edit inline ckeditor -->'."\n";
3053  print '<script type="text/javascript">
3054  $(document).ready(function() {
3055  var isEditingEnabled = '.(getDolGlobalString("WEBSITE_EDITINLINE") ? 'true' : 'false').';
3056  if (isEditingEnabled)
3057  {
3058  switchEditorOnline(true);
3059  }
3060 
3061  $( "#switchckeditorinline" ).click(function() {
3062  switchEditorOnline();
3063  });
3064 
3065  function switchEditorOnline(forceenable)
3066  {
3067  if (! isEditingEnabled || forceenable)
3068  {
3069  console.log("Enable inline edit");
3070  jQuery(\'section[contenteditable="true"],div[contenteditable="true"]\').each(function(idx){
3071  var idtouse = $(this).attr(\'id\');
3072  console.log("Enable inline edit for "+idtouse);
3073  CKEDITOR.inline(idtouse, {
3074  // Allow some non-standard markup that we used in the introduction.
3075  extraAllowedContent: \'span(*);cite(*);q(*);dl(*);dt(*);dd(*);ul(*);li(*);header(*);button(*);h1(*);h2(*);\',
3076  //extraPlugins: \'sourcedialog\',
3077  removePlugins: \'flash,stylescombo,exportpdf,scayt,wsc,pagebreak,iframe,smiley\',
3078  // Show toolbar on startup (optional).
3079  // startupFocus: true
3080  });
3081  })
3082 
3083  isEditingEnabled = true;
3084  }
3085  else {
3086  console.log("Disable inline edit");
3087  for(name in CKEDITOR.instances)
3088  {
3089  CKEDITOR.instances[name].destroy(true);
3090  }
3091  isEditingEnabled = false;
3092  }
3093  };
3094  });
3095  </script>';
3096  print $langs->trans("EditInLine");
3097  print '</span>';
3098 
3099  //$disableeditinline = $websitepage->grabbed_from;
3100  $disableeditinline = 0;
3101  if ($disableeditinline) {
3102  //print '<input type="submit" class="button bordertransp" disabled="disabled" title="'.dol_escape_htmltag($langs->trans("OnlyEditionOfSourceForGrabbedContent")).'" value="'.dol_escape_htmltag($langs->trans("EditWithEditor")).'" name="editcontent">';
3103  print '<a class="nobordertransp opacitymedium nohoverborder marginleftonlyshort"'.$disabled.' href="#" disabled="disabled" title="'.dol_escape_htmltag($langs->trans("OnlyEditionOfSourceForGrabbedContent")).'">'.img_picto($langs->trans("OnlyEditionOfSourceForGrabbedContent"), 'switch_off', '', false, 0, 0, '', 'nomarginleft').'</a>';
3104  } else {
3105  //print '<input type="submit" class="button nobordertransp"'.$disabled.' value="'.dol_escape_htmltag($langs->trans("EditWithEditor")).'" name="editcontent">';
3106  if (empty($conf->global->WEBSITE_EDITINLINE)) {
3107  print '<a class="nobordertransp nohoverborder marginleftonlyshort valignmiddle"'.$disabled.' href="'.$_SERVER["PHP_SELF"].'?website='.$object->ref.'&pageid='.$websitepage->id.'&action=seteditinline&token='.newToken().'">'.img_picto($langs->trans("EditInLineOnOff", $langs->transnoentitiesnoconv("Off")), 'switch_off', '', false, 0, 0, '', 'nomarginleft').'</a>';
3108  } else {
3109  print '<a class="nobordertransp nohoverborder marginleftonlyshort valignmiddle"'.$disabled.' href="'.$_SERVER["PHP_SELF"].'?website='.$object->ref.'&pageid='.$websitepage->id.'&action=unseteditinline&token='.newToken().'">'.img_picto($langs->trans("EditInLineOnOff", $langs->transnoentitiesnoconv("On")), 'switch_on', '', false, 0, 0, '', 'nomarginleft').'</a>';
3110  }
3111  }
3112 
3113  print '</div>';
3114 
3115  print '</div>';
3116 
3117  // Set page as homepage
3118  if ($object->fk_default_home > 0 && $pageid == $object->fk_default_home) {
3119  //$disabled=' disabled="disabled"';
3120  //print '<span class="button bordertransp disabled"'.$disabled.' title="'.dol_escape_htmltag($langs->trans("SetAsHomePage")).'"><span class="fa fa-home"></span></span>';
3121  //print '<input type="submit" class="button bordertransp" disabled="disabled" value="'.dol_escape_htmltag($langs->trans("SetAsHomePage")).'" name="setashome">';
3122  print '<a href="#" class="button bordertransp disabled" disabled="disabled" title="'.dol_escape_htmltag($langs->trans("SetAsHomePage")).'"><span class="fa fa-home valignmiddle btnTitle-icon"></span></a>';
3123  } else {
3124  //$disabled='';
3125  //print '<input type="submit" class="button bordertransp"'.$disabled.' value="'.dol_escape_htmltag($langs->trans("SetAsHomePage")).'" name="setashome">';
3126  print '<a href="'.$_SERVER["PHP_SELF"].'?action=setashome&token='.newToken().'&website='.urlencode($website->ref).'&pageid='.((int) $pageid).'" class="button bordertransp"'.$disabled.' title="'.dol_escape_htmltag($langs->trans("SetAsHomePage")).'"><span class="fa fa-home valignmiddle btnTitle-icon"></span></a>';
3127  }
3128  print '<input type="submit" class="button bordertransp"'.$disabled.' value="'.dol_escape_htmltag($langs->trans("ClonePage")).'" name="createpagefromclone">';
3129  print '<input type="submit" class="buttonDelete bordertransp" name="delete" value="'.$langs->trans("Delete").'"'.($atleastonepage ? '' : ' disabled="disabled"').'>';
3130  }
3131  }
3132 
3133  //print '</span>'; // end website selection
3134 
3135  print '<span class="websitetools">';
3136 
3137  if (($pageid > 0 && $atleastonepage) && ($action == 'preview' || $action == 'createfromclone' || $action == 'createpagefromclone' || $action == 'deletesite')) {
3138  $realpage = $urlwithroot.'/public/website/index.php?website='.$websitekey.'&pageref='.$websitepage->pageurl;
3139  $pagealias = $websitepage->pageurl;
3140 
3141  $htmltext = $langs->trans("PreviewSiteServedByDolibarr", $langs->transnoentitiesnoconv("Page"), $langs->transnoentitiesnoconv("Page"), $realpage, $dataroot);
3142  $htmltext .= '<br>'.$langs->trans("CheckVirtualHostPerms", $langs->transnoentitiesnoconv("ReadPerm"), '{s1}');
3143  $htmltext = str_replace('{s1}', $dataroot.'<br>'.DOL_DATA_ROOT.'/medias<br>'.DOL_DOCUMENT_ROOT, $htmltext);
3144  //$htmltext .= '<br>'.$langs->trans("CheckVirtualHostPerms", $langs->transnoentitiesnoconv("WritePerm"), '{s1}');
3145  //$htmltext = str_replace('{s1}', DOL_DATA_ROOT.'/medias', $htmltext);
3146 
3147  print '<div class="websiteinputurl inline-block paddingright">';
3148  print '<a class="websitebuttonsitepreview inline-block" id="previewpage" href="'.$realpage.'&nocache='.dol_now().'" class="button" target="tab'.$websitekey.'" alt="'.dol_escape_htmltag($htmltext).'">';
3149  print $form->textwithpicto('', $htmltext, 1, 'preview');
3150  print '</a>'; // View page in new Tab
3151  print '</div>';
3152 
3153  /*print '<div class="websiteinputurl inline-block" id="websiteinputpage">';
3154  print '<input type="text" id="previewpageurl" class="minwidth200imp" name="previewsite" value="'.$pagealias.'" disabled="disabled">';
3155  $htmltext = $langs->trans("PageNameAliasHelp", $langs->transnoentitiesnoconv("EditPageMeta"));
3156  print $form->textwithpicto('', $htmltext, 1, 'help', '', 0, 2, 'helppagealias');
3157  print '</div>';*/
3158 
3159  /*
3160  $urlext = $virtualurl.'/'.$pagealias.'.php';
3161  $urlint = $urlwithroot.'/public/website/index.php?website='.$websitekey;
3162 
3163  $htmltext = $langs->trans("PreviewSiteServedByWebServer", $langs->transnoentitiesnoconv("Page"), $langs->transnoentitiesnoconv("Page"), $dataroot, $virtualurl ? $urlext : '<span class="error">'.$langs->trans("VirtualHostUrlNotDefined").'</span>');
3164 
3165  print '<a class="websitebuttonsitepreview'.($virtualurl ? '' : ' websitebuttonsitepreviewdisabled cursornotallowed').'" id="previewpageext" href="'.$urlext.'" target="tab'.$websitekey.'ext" alt="'.dol_escape_htmltag($htmltext).'">';
3166  print $form->textwithpicto('', $htmltext, 1, 'preview_ext');
3167  print '</a>';
3168  */
3169  //print '<input type="submit" class="button" name="previewpage" target="tab'.$websitekey.'"value="'.$langs->trans("ViewPageInNewTab").'">';
3170 
3171  // TODO Add js to save alias like we save virtual host name and use dynamic virtual host for url of id=previewpageext
3172  }
3173  if (!in_array($action, array('editcss', 'editmenu', 'file_manager', 'replacesite', 'replacesiteconfirm', 'createsite', 'createcontainer', 'createfromclone', 'createpagefromclone', 'deletesite'))) {
3174  if ($action == 'editsource' || $action == 'editmeta') {
3175  print '<input type="submit" id="savefileandstay" class="button buttonforacesave hideonsmartphone small" value="'.dol_escape_htmltag($langs->trans("SaveAndStay")).'" name="updateandstay">';
3176  }
3177  if (preg_match('/^create/', $action)) {
3178  print '<input type="submit" id="savefile" class="button buttonforacesave button-save small" value="'.dol_escape_htmltag($langs->trans("Save")).'" name="update">';
3179  }
3180  if (preg_match('/^edit/', $action)) {
3181  print '<input type="submit" id="savefile" class="button buttonforacesave button-save small" value="'.dol_escape_htmltag($langs->trans("Save")).'" name="update">';
3182  }
3183  if ($action != 'preview') {
3184  print '<input type="submit" class="button button-cancel small" value="'.dol_escape_htmltag($langs->trans("Cancel")).'" name="cancel">';
3185  }
3186  }
3187 
3188  print '</span>'; // end websitetools
3189 
3190  print '<span class="websitehelp">';
3191  if ($action == 'editsource' || $action == 'editcontent' || GETPOST('editsource', 'alpha') || GETPOST('editcontent', 'alpha')) {
3192  $url = 'https://wiki.dolibarr.org/index.php/Module_Website';
3193 
3194  $htmltext = $langs->transnoentitiesnoconv("YouCanEditHtmlSource", $url);
3195  $htmltext .= $langs->transnoentitiesnoconv("YouCanEditHtmlSource2", $url);
3196  $htmltext .= $langs->transnoentitiesnoconv("YouCanEditHtmlSourceMore", $url);
3197  $htmltext .= '<br>';
3198  if ($conf->browser->layout == 'phone') {
3199  print $form->textwithpicto('', $htmltext, 1, 'help', 'inline-block', 1, 2, 'tooltipsubstitution');
3200  } else {
3201  //img_help(($tooltiptrigger != '' ? 2 : 1), $alt)
3202  print $form->textwithpicto($langs->trans("SyntaxHelp").' '.img_help(2, $langs->trans("SyntaxHelp")), $htmltext, 1, 'none', 'inline-block', 1, 2, 'tooltipsubstitution');
3203  }
3204  }
3205  print '</span>'; // end websitehelp
3206 
3207 
3208  if ($action == 'preview' || $action == 'createfromclone' || $action == 'createpagefromclone') {
3209  // Adding jquery code to change on the fly url of preview ext
3210  if (!empty($conf->use_javascript_ajax)) {
3211  print '<script type="text/javascript">
3212  jQuery(document).ready(function() {
3213  jQuery("#websiteinputurl").keyup(function() {
3214  console.log("Website external url modified "+jQuery("#previewsiteurl").val());
3215  if (jQuery("#previewsiteurl").val() != "" && jQuery("#previewsiteurl").val().startsWith("http"))
3216  {
3217  jQuery("a.websitebuttonsitepreviewdisabled img").css({ opacity: 1 });
3218  }
3219  else jQuery("a.websitebuttonsitepreviewdisabled img").css({ opacity: 0.2 });
3220  ';
3221  print '
3222  });
3223  jQuery("#previewsiteext,#previewpageext").click(function() {
3224 
3225  newurl=jQuery("#previewsiteurl").val();
3226  if (! newurl.startsWith("http"))
3227  {
3228  alert(\''.dol_escape_js($langs->trans("ErrorURLMustStartWithHttp")).'\');
3229  return false;
3230  }
3231 
3232  newpage=jQuery("#previewsiteurl").val() + "/" + jQuery("#previewpageurl").val() + ".php";
3233  console.log("Open url "+newurl);
3234  /* Save url */
3235  jQuery.ajax({
3236  method: "POST",
3237  url: "'.DOL_URL_ROOT.'/core/ajax/saveinplace.php",
3238  data: {
3239  field: \'editval_virtualhost\',
3240  element: \'website\',
3241  table_element: \'website\',
3242  fk_element: '.((int) $object->id).',
3243  value: newurl,
3244  },
3245  context: document.body
3246  });
3247 
3248  jQuery("#previewsiteext").attr("href",newurl);
3249  jQuery("#previewpageext").attr("href",newpage);
3250  });
3251  });
3252  </script>';
3253  }
3254  }
3255  }
3256 
3257  print '</div>'; // end current websitebar
3258 }
3259 
3260 
3261 $head = array();
3262 
3263 
3264 /*
3265  * Edit Site HTML header and CSS
3266  */
3267 
3268 if ($action == 'editcss') {
3269  print '<div class="fiche">';
3270 
3271  print '<br>';
3272 
3273  if (!GETPOSTISSET('WEBSITE_CSS_INLINE')) {
3274  $csscontent = @file_get_contents($filecss);
3275  // Clean the php css file to remove php code and get only css part
3276  $csscontent = preg_replace('/<\?php \/\/ BEGIN PHP[^\?]*END PHP \?>\n*/ims', '', $csscontent);
3277  } else {
3278  $csscontent = GETPOST('WEBSITE_CSS_INLINE', 'none');
3279  }
3280  if (!trim($csscontent)) {
3281  $csscontent = '/* CSS content (all pages) */'."\nbody.bodywebsite { margin: 0; font-family: 'Open Sans', sans-serif; }\n.bodywebsite h1 { margin-top: 0; margin-bottom: 0; padding: 10px;}";
3282  }
3283 
3284  if (!GETPOSTISSET('WEBSITE_JS_INLINE')) {
3285  $jscontent = @file_get_contents($filejs);
3286  // Clean the php js file to remove php code and get only js part
3287  $jscontent = preg_replace('/<\?php \/\/ BEGIN PHP[^\?]*END PHP \?>\n*/ims', '', $jscontent);
3288  } else {
3289  $jscontent = GETPOST('WEBSITE_JS_INLINE', 'none');
3290  }
3291  if (!trim($jscontent)) {
3292  $jscontent = '/* JS content (all pages) */'."\n";
3293  }
3294 
3295  if (!GETPOSTISSET('WEBSITE_HTML_HEADER')) {
3296  $htmlheadercontent = @file_get_contents($filehtmlheader);
3297  // Clean the php htmlheader file to remove php code and get only html part
3298  $htmlheadercontent = preg_replace('/<\?php \/\/ BEGIN PHP[^\?]*END PHP \?>\n*/ims', '', $htmlheadercontent);
3299  } else {
3300  $htmlheadercontent = GETPOST('WEBSITE_HTML_HEADER', 'none');
3301  }
3302  if (!trim($htmlheadercontent)) {
3303  $htmlheadercontent = "<html>\n";
3304  $htmlheadercontent .= $htmlheadercontentdefault;
3305  $htmlheadercontent .= "</html>";
3306  } else {
3307  $htmlheadercontent = preg_replace('/^\s*<html>/ims', '', $htmlheadercontent);
3308  $htmlheadercontent = preg_replace('/<\/html>\s*$/ims', '', $htmlheadercontent);
3309  $htmlheadercontent = '<html>'."\n".trim($htmlheadercontent)."\n".'</html>';
3310  }
3311 
3312  if (!GETPOSTISSET('WEBSITE_ROBOT')) {
3313  $robotcontent = @file_get_contents($filerobot);
3314  // Clean the php htmlheader file to remove php code and get only html part
3315  $robotcontent = preg_replace('/<\?php \/\/ BEGIN PHP[^\?]*END PHP \?>\n*/ims', '', $robotcontent);
3316  } else {
3317  $robotcontent = GETPOST('WEBSITE_ROBOT', 'nothtml');
3318  }
3319  if (!trim($robotcontent)) {
3320  $robotcontent .= "# Robot file. Generated with ".DOL_APPLICATION_TITLE."\n";
3321  $robotcontent .= "User-agent: *\n";
3322  $robotcontent .= "Allow: /public/\n";
3323  $robotcontent .= "Disallow: /administrator/\n";
3324  }
3325 
3326  if (!GETPOSTISSET('WEBSITE_HTACCESS')) {
3327  $htaccesscontent = @file_get_contents($filehtaccess);
3328  // Clean the php htaccesscontent file to remove php code and get only html part
3329  $htaccesscontent = preg_replace('/<\?php \/\/ BEGIN PHP[^\?]*END PHP \?>\n*/ims', '', $htaccesscontent);
3330  } else {
3331  $htaccesscontent = GETPOST('WEBSITE_HTACCESS', 'nohtml'); // We must use 'nohtml' and not 'alphanohtml' because we must accept "
3332  }
3333  if (!trim($htaccesscontent)) {
3334  $htaccesscontent .= "# Order allow,deny\n";
3335  $htaccesscontent .= "# Deny from all\n";
3336  }
3337 
3338 
3339  if (!GETPOSTISSET('WEBSITE_MANIFEST_JSON')) {
3340  $manifestjsoncontent = @file_get_contents($filemanifestjson);
3341  // Clean the manifestjson file to remove php code and get only html part
3342  $manifestjsoncontent = preg_replace('/<\?php \/\/ BEGIN PHP[^\?]*END PHP \?>\n*/ims', '', $manifestjsoncontent);
3343  } else {
3344  $manifestjsoncontent = GETPOST('WEBSITE_MANIFEST_JSON', 'restricthtml');
3345  }
3346  if (!trim($manifestjsoncontent)) {
3347  //$manifestjsoncontent.="";
3348  }
3349 
3350  if (!GETPOSTISSET('WEBSITE_README')) {
3351  $readmecontent = @file_get_contents($filereadme);
3352  // Clean the readme file to remove php code and get only html part
3353  $readmecontent = preg_replace('/<\?php \/\/ BEGIN PHP[^\?]*END PHP \?>\n*/ims', '', $readmecontent);
3354  } else {
3355  $readmecontent = GETPOST('WEBSITE_README', 'none');
3356  }
3357  if (!trim($readmecontent)) {
3358  //$readmecontent.="";
3359  }
3360 
3361  print dol_get_fiche_head();
3362 
3363  print '<!-- Edit Website properties -->'."\n";
3364  print '<table class="border centpercent">';
3365 
3366  // Website
3367  print '<tr><td class="titlefieldcreate fieldrequired">';
3368  print $langs->trans('WebSite');
3369  print '</td><td>';
3370  print $websitekey;
3371  print '</td></tr>';
3372 
3373  // Status of web site
3374  print '<!-- Status of website -->'."\n";
3375  print '<tr><td class="fieldrequired">';
3376  print $langs->trans('Status');
3377  print '</td><td>';
3378  print ajax_object_onoff($object, 'status', 'status', 'Enabled', 'Disabled');
3379  //print dol_print_date($pagedatecreation, 'dayhour');
3380  print '</td></tr>';
3381 
3382  // Main language
3383  print '<tr><td class="tdtop fieldrequired">';
3384  $htmltext = '';
3385  print $form->textwithpicto($langs->trans('MainLanguage'), $htmltext, 1, 'help', '', 0, 2, 'WEBSITE_LANG');
3386  print '</td><td>';
3387  print $formadmin->select_language((GETPOSTISSET('WEBSITE_LANG') ? GETPOST('WEBSITE_LANG', 'aZ09comma') : ($object->lang ? $object->lang : '0')), 'WEBSITE_LANG', 0, null, 1, 0, 0, 'minwidth300', 2, 0, 0, array(), 1);
3388  print '</td>';
3389  print '</tr>';
3390 
3391  // Other languages
3392  print '<tr><td class="tdtop">';
3393  $htmltext = $langs->trans("Example").': fr,de,sv,it,pt';
3394  print $form->textwithpicto($langs->trans('OtherLanguages'), $htmltext, 1, 'help', '', 0, 2);
3395  print '</td><td>';
3396  print '<input type="text" class="flat" value="'.(GETPOSTISSET('WEBSITE_OTHERLANG') ? GETPOST('WEBSITE_OTHERLANG', 'alpha') : $object->otherlang).'" name="WEBSITE_OTHERLANG">';
3397  print '</td>';
3398  print '</tr>';
3399 
3400  // VirtualHost
3401  print '<tr><td class="tdtop">';
3402 
3403  $htmltext = $langs->trans("SetHereVirtualHost", DOL_DATA_ROOT.($conf->entity > 1 ? '/'.$conf->entity : '').'/website/{s1}'.$websitekey.'{s2}');
3404  $htmltext = str_replace(array('{s1}', '{s2}'), array('<i>', '</i>'), $htmltext);
3405  $htmltext .= '<br>';
3406  $htmltext .= '<br>'.$langs->trans("CheckVirtualHostPerms", $langs->transnoentitiesnoconv("ReadPerm"), DOL_DOCUMENT_ROOT);
3407  $htmltext .= '<br>'.$langs->trans("CheckVirtualHostPerms", $langs->transnoentitiesnoconv("WritePerm"), '{s1}');
3408  $htmltext = str_replace('{s1}', DOL_DATA_ROOT.'/website<br>'.DOL_DATA_ROOT.'/medias', $htmltext);
3409 
3410  print $form->textwithpicto($langs->trans('Virtualhost'), $htmltext, 1, 'help', '', 0, 2, 'virtualhosttooltip');
3411  print '</td><td>';
3412  print '<input type="text" class="flat minwidth300" value="'.(GETPOSTISSET('virtualhost') ? GETPOST('virtualhost', 'alpha') : $virtualurl).'" name="virtualhost">';
3413  print '</td>';
3414  print '</tr>';
3415 
3416  // Favicon
3417  print '<tr><td>';
3418  print $form->textwithpicto($langs->trans('ImportFavicon'), $langs->trans('FaviconTooltip'));
3419  print '</td><td>';
3420  $maxfilesizearray = getMaxFileSizeArray();
3421  $maxmin = $maxfilesizearray['maxmin'];
3422  if ($maxmin > 0) {
3423  print '<input type="hidden" name="MAX_FILE_SIZE" value="'.($maxmin * 1024).'">'; // MAX_FILE_SIZE must precede the field type=file
3424  }
3425  print '<input type="file" class="flat minwidth300" name="addedfile" id="addedfile"/>';
3426  print '</tr></td>';
3427 
3428  // CSS file
3429  print '<tr><td class="tdtop">';
3430  $htmlhelp = $langs->trans("CSSContentTooltipHelp");
3431  print $form->textwithpicto($langs->trans('WEBSITE_CSS_INLINE'), $htmlhelp, 1, 'help', '', 0, 2, 'csstooltip');
3432  print '</td><td>';
3433 
3434  $poscursor = array('x'=>GETPOST('WEBSITE_CSS_INLINE_x'), 'y'=>GETPOST('WEBSITE_CSS_INLINE_y'));
3435  $doleditor = new DolEditor('WEBSITE_CSS_INLINE', $csscontent, '', '220', 'ace', 'In', true, false, 'ace', 0, '100%', '', $poscursor);
3436  print $doleditor->Create(1, '', true, 'CSS', 'css');
3437 
3438  print '</td></tr>';
3439 
3440  // JS file
3441  print '<tr><td class="tdtop">';
3442  $textwithhelp = $langs->trans('WEBSITE_JS_INLINE');
3443  $htmlhelp2 = $langs->trans("LinkAndScriptsHereAreNotLoadedInEditor").'<br>';
3444  print $form->textwithpicto($textwithhelp, $htmlhelp2, 1, 'warning', '', 0, 2, 'htmljstooltip2');
3445 
3446  print '</td><td>';
3447 
3448  $poscursor = array('x'=>GETPOST('WEBSITE_JS_INLINE_x'), 'y'=>GETPOST('WEBSITE_JS_INLINE_y'));
3449  $doleditor = new DolEditor('WEBSITE_JS_INLINE', $jscontent, '', '220', 'ace', 'In', true, false, 'ace', 0, '100%', '', $poscursor);
3450  print $doleditor->Create(1, '', true, 'JS', 'javascript');
3451 
3452  print '</td></tr>';
3453 
3454  // Common HTML header
3455  print '<tr><td class="tdtop">';
3456  print $langs->trans('WEBSITE_HTML_HEADER');
3457  $htmlhelp = $langs->trans("Example").' :<br>';
3458  $htmlhelp .= dol_htmlentitiesbr($htmlheadercontentdefault);
3459  $textwithhelp = $form->textwithpicto('', $htmlhelp, 1, 'help', '', 0, 2, 'htmlheadertooltip');
3460  $htmlhelp2 = $langs->trans("LinkAndScriptsHereAreNotLoadedInEditor").'<br>';
3461  print $form->textwithpicto($textwithhelp, $htmlhelp2, 1, 'warning', '', 0, 2, 'htmlheadertooltip2');
3462  print '</td><td>';
3463 
3464  $poscursor = array('x'=>GETPOST('WEBSITE_HTML_HEADER_x'), 'y'=>GETPOST('WEBSITE_HTML_HEADER_y'));
3465  $doleditor = new DolEditor('WEBSITE_HTML_HEADER', $htmlheadercontent, '', '220', 'ace', 'In', true, false, 'ace', 0, '100%', '', $poscursor);
3466  print $doleditor->Create(1, '', true, 'HTML Header', 'html');
3467 
3468  print '</td></tr>';
3469 
3470  // Robot file
3471  print '<tr><td class="tdtop">';
3472  print $langs->trans('WEBSITE_ROBOT');
3473  print '</td><td>';
3474 
3475  $poscursor = array('x'=>GETPOST('WEBSITE_ROBOT_x'), 'y'=>GETPOST('WEBSITE_ROBOT_y'));
3476  $doleditor = new DolEditor('WEBSITE_ROBOT', $robotcontent, '', '220', 'ace', 'In', true, false, 'ace', 0, '100%', '', $poscursor);
3477  print $doleditor->Create(1, '', true, 'Robot file', 'text');
3478 
3479  print '</td></tr>';
3480 
3481  // .htaccess
3482  print '<tr><td class="tdtop">';
3483  print $langs->trans('WEBSITE_HTACCESS');
3484  print '</td><td>';
3485 
3486  $poscursor = array('x'=>GETPOST('WEBSITE_HTACCESS_x'), 'y'=>GETPOST('WEBSITE_HTACCESS_y'));
3487  $doleditor = new DolEditor('WEBSITE_HTACCESS', $htaccesscontent, '', '220', 'ace', 'In', true, false, 'ace', 0, '100%', '', $poscursor);
3488  print $doleditor->Create(1, '', true, $langs->trans("File").' .htaccess', 'text');
3489 
3490  print '</td></tr>';
3491 
3492  // Manifest.json
3493  print '<tr><td class="tdtop">';
3494  $htmlhelp = $langs->trans("Example").' :<br>';
3495  $htmlhelp .= dol_htmlentitiesbr($manifestjsoncontentdefault);
3496  print $form->textwithpicto($langs->trans('WEBSITE_MANIFEST_JSON'), $htmlhelp, 1, 'help', '', 0, 2, 'manifestjsontooltip');
3497  print '</td><td>';
3498  print $langs->trans("UseManifest").': '.$form->selectyesno('use_manifest', $website->use_manifest, 1).'<br>';
3499 
3500  $poscursor = array('x'=>GETPOST('WEBSITE_MANIFEST_JSON_x'), 'y'=>GETPOST('WEBSITE_MANIFEST_JSON_y'));
3501  $doleditor = new DolEditor('WEBSITE_MANIFEST_JSON', $manifestjsoncontent, '', '220', 'ace', 'In', true, false, 'ace', 0, '100%', '', $poscursor);
3502  print $doleditor->Create(1, '', true, $langs->trans("File").' manifest.json', 'text');
3503  print '</td></tr>';
3504 
3505  // README.md
3506  print '<tr><td class="tdtop">';
3507  $htmlhelp = $langs->trans("EnterHereLicenseInformation");
3508  print $form->textwithpicto($langs->trans('WEBSITE_README'), $htmlhelp, 1, 'help', '', 0, 2, 'readmetooltip');
3509  print '</td><td>';
3510 
3511  $poscursor = array('x'=>GETPOST('WEBSITE_README_x'), 'y'=>GETPOST('WEBSITE_README_y'));
3512  $doleditor = new DolEditor('WEBSITE_README', $readmecontent, '', '220', 'ace', 'In', true, false, 'ace', 0, '100%', '', $poscursor);
3513  print $doleditor->Create(1, '', true, $langs->trans("File").' README.md', 'text');
3514 
3515  print '</td></tr>';
3516 
3517  // RSS
3518  print '<tr><td class="tdtop">';
3519  $htmlhelp = $langs->trans('RSSFeedDesc');
3520  print $form->textwithpicto($langs->trans('RSSFeed'), $htmlhelp, 1, 'help', '', 0, 2, '');
3521  print '</td><td>';
3522  print '/wrapper.php?rss=1[&l=XX][&limit=123]';
3523  print '</td></tr>';
3524 
3525  print '</table>';
3526 
3527  print dol_get_fiche_end();
3528 
3529  print '</div>';
3530 
3531  print '<br>';
3532 }
3533 
3534 
3535 if ($action == 'createsite') {
3536  print '<div class="fiche">';
3537 
3538  print '<br>';
3539 
3540  /*$h = 0;
3541  $head = array();
3542 
3543  $head[$h][0] = dol_buildpath('/website/index.php',1).'?id='.$object->id;
3544  $head[$h][1] = $langs->trans("AddSite");
3545  $head[$h][2] = 'card';
3546  $h++;
3547 
3548  print dol_get_fiche_head($head, 'card', $langs->trans("AddSite"), -1, 'globe');
3549  */
3550  if ($action == 'createcontainer') {
3551  print load_fiche_titre($langs->trans("AddSite"));
3552  }
3553 
3554  print '<!-- Add site -->'."\n";
3555  //print '<div class="fichecenter">';
3556 
3557  print '<table class="border centpercent">';
3558 
3559  $siteref = $sitedesc = $sitelang = $siteotherlang = '';
3560  if (GETPOST('WEBSITE_REF')) {
3561  $siteref = GETPOST('WEBSITE_REF', 'aZ09');
3562  }
3563  if (GETPOST('WEBSITE_DESCRIPTION')) {
3564  $sitedesc = GETPOST('WEBSITE_DESCRIPTION', 'alpha');
3565  }
3566  if (GETPOST('WEBSITE_LANG')) {
3567  $sitelang = GETPOST('WEBSITE_LANG', 'aZ09');
3568  }
3569  if (GETPOST('WEBSITE_OTHERLANG')) {
3570  $siteotherlang = GETPOST('WEBSITE_OTHERLANG', 'aZ09comma');
3571  }
3572 
3573  print '<tr><td class="titlefieldcreate fieldrequired">';
3574  print $form->textwithpicto($langs->trans('WebSite'), $langs->trans("Example").': www.mywebsite.com, myportal, ...');
3575  print '</td><td>';
3576  print '<input type="text" class="flat maxwidth300" name="WEBSITE_REF" value="'.dol_escape_htmltag($siteref).'" autofocus>';
3577  print '</td></tr>';
3578 
3579  print '<tr><td class="fieldrequired">';
3580  print $langs->trans('MainLanguage');
3581  print '</td><td>';
3582  $shortlangcode = preg_replace('/[_-].*$/', '', trim($langs->defaultlang));
3583  print $formadmin->select_language((GETPOSTISSET('WEBSITE_LANG') ? GETPOST('WEBSITE_LANG', 'aZ09comma') : $shortlangcode), 'WEBSITE_LANG', 0, null, 1, 0, 0, 'minwidth300', 2, 0, 0, array(), 1);
3584  print '</td></tr>';
3585 
3586  print '<tr><td>';
3587  print $langs->trans('Description');
3588  print '</td><td>';
3589  print '<input type="text" class="flat minwidth500" name="WEBSITE_DESCRIPTION" value="'.dol_escape_htmltag($sitedesc).'">';
3590  print '</td></tr>';
3591 
3592  print '<tr><td>';
3593  $htmltext = $langs->trans("Example").': fr,de,sv,it,pt';
3594  print $form->textwithpicto($langs->trans('OtherLanguages'), $htmltext, 1, 'help', '', 0, 2);
3595  print '</td><td>';
3596  print '<input type="text" class="flat minwidth300" name="WEBSITE_OTHERLANG" value="'.dol_escape_htmltag($siteotherlang).'">';
3597  print '</td></tr>';
3598 
3599  print '<tr><td>';
3600 
3601  $htmltext = $langs->trans("SetHereVirtualHost", '{s1}');
3602  $htmltext = str_replace('{s1}', DOL_DATA_ROOT.($conf->entity > 1 ? '/'.$conf->entity : '').'/website/<i>websiteref</i>', $htmltext);
3603  $htmltext .= '<br>';
3604  $htmltext .= '<br>'.$langs->trans("CheckVirtualHostPerms", $langs->transnoentitiesnoconv("ReadPerm"), DOL_DOCUMENT_ROOT);
3605  $htmltext .= '<br>'.$langs->trans("CheckVirtualHostPerms", $langs->transnoentitiesnoconv("WritePerm"), '{s1}');
3606  $htmltext = str_replace('{s1}', DOL_DATA_ROOT.'/website<br>'.DOL_DATA_ROOT.'/medias', $htmltext);
3607 
3608  print $form->textwithpicto($langs->trans('Virtualhost'), $htmltext, 1, 'help', '', 0, 2, 'virtualhosttooltip');
3609  print '</td><td>';
3610  print '<input type="text" class="flat minwidth300" name="virtualhost" value="'.dol_escape_htmltag(GETPOST('virtualhost', 'alpha')).'">';
3611  print '</td></tr>';
3612 
3613 
3614  print '</table>';
3615 
3616  if ($action == 'createsite') {
3617  print '<div class="center">';
3618 
3619  print '<input type="submit" class="button small" name="addcontainer" value="'.$langs->trans("Create").'">';
3620  print '<input class="button button-cancel small" type="submit" name="preview" value="'.$langs->trans("Cancel").'">';
3621 
3622  print '</div>';
3623  }
3624 
3625 
3626  //print '</div>';
3627 
3628  //print dol_get_fiche_end();
3629 
3630  print '</div>';
3631 
3632  print '<br>';
3633 }
3634 
3635 if ($action == 'importsite') {
3636  print '<div class="fiche">';
3637 
3638  print '<br>';
3639 
3640  print load_fiche_titre($langs->trans("ImportSite"));
3641 
3642  print dol_get_fiche_head(array(), '0', '', -1);
3643 
3644  print '<span class="opacitymedium">'.$langs->trans("ZipOfWebsitePackageToImport").'</span><br><br>';
3645 
3646  $maxfilesizearray = getMaxFileSizeArray();
3647  $maxmin = $maxfilesizearray['maxmin'];
3648  if ($maxmin > 0) {
3649  print '<input type="hidden" name="MAX_FILE_SIZE" value="'.($maxmin * 1024).'">'; // MAX_FILE_SIZE must precede the field type=file
3650  }
3651  print '<input class="flat minwidth400" type="file" name="userfile[]" accept=".zip">';
3652  print '<input type="submit" class="button small" name="buttonsubmitimportfile" value="'.dol_escape_htmltag($langs->trans("Upload")).'">';
3653  print '<input type="submit" class="button button-cancel small" name="preview" value="'.dol_escape_htmltag($langs->trans("Cancel")).'">';
3654 
3655  print '<br><br><br>';
3656 
3657 
3658  print '<span class="opacitymedium">'.$langs->trans("ZipOfWebsitePackageToLoad").'</span><br><br>';
3659 
3660  showWebsiteTemplates($website);
3661 
3662  print dol_get_fiche_end();
3663 
3664  print '</div>';
3665 
3666  print '<br>';
3667 }
3668 
3669 if ($action == 'editmeta' || $action == 'createcontainer') { // Edit properties of a web site OR properties of a web page
3670  print '<div class="fiche">';
3671 
3672  print '<br>';
3673 
3674  /*$h = 0;
3675  $head = array();
3676 
3677  $head[$h][0] = dol_buildpath('/website/index.php',1).'?id='.$object->id;
3678  $head[$h][1] = $langs->trans("AddPage");
3679  $head[$h][2] = 'card';
3680  $h++;
3681 
3682  print dol_get_fiche_head($head, 'card', $langs->trans("AddPage"), -1, 'globe');
3683  */
3684  if ($action == 'createcontainer') {
3685  print load_fiche_titre($langs->trans("AddPage"));
3686  }
3687 
3688  print '<!-- Edit or create page/container -->'."\n";
3689  //print '<div class="fichecenter">';
3690 
3691  $hiddenfromfetchingafterload = ' hideobject';
3692  $hiddenmanuallyafterload = ' hideobject';
3693  if (GETPOST('radiocreatefrom') == 'checkboxcreatefromfetching') {
3694  $hiddenfromfetchingafterload = '';
3695  }
3696  if (GETPOST('radiocreatefrom') == 'checkboxcreatemanually') {
3697  $hiddenmanuallyafterload = '';
3698  }
3699 
3700  if ($action == 'editmeta' || empty($conf->use_javascript_ajax)) { // No autohide/show in such case
3701  $hiddenfromfetchingafterload = '';
3702  $hiddenmanuallyafterload = '';
3703  }
3704 
3705  if ($action == 'createcontainer') {
3706  print '<br>';
3707 
3708  if (!empty($conf->use_javascript_ajax)) {
3709  print '<input type="radio" name="radiocreatefrom" id="checkboxcreatemanually" value="checkboxcreatemanually"'.(GETPOST('radiocreatefrom') == 'checkboxcreatemanually' ? ' checked' : '').'> ';
3710  }
3711  print '<label for="checkboxcreatemanually"><span class="opacitymediumxx">'.$langs->trans("OrEnterPageInfoManually").'</span></label><br>';
3712  print '<hr class="tablecheckboxcreatemanually'.$hiddenmanuallyafterload.'">';
3713  }
3714 
3715  print '<table class="border tableforfield nobackground centpercent tablecheckboxcreatemanually'.$hiddenmanuallyafterload.'">';
3716 
3717  if ($action != 'createcontainer') {
3718  print '<tr><td class="titlefield fieldrequired">';
3719  print $langs->trans('IDOfPage').' - '.$langs->trans('InternalURLOfPage');
3720  print '</td><td>';
3721  print $pageid;
3722  //print '</td></tr>';
3723 
3724  //print '<tr><td class="titlefield fieldrequired">';
3725  //print $langs->trans('InternalURLOfPage');
3726  //print '</td><td>';
3727  print ' &nbsp; - &nbsp; ';
3728  print '/public/website/index.php?website='.urlencode($websitekey).'&pageid='.urlencode($pageid);
3729  //if ($objectpage->grabbed_from) print ' - <span class="opacitymedium">'.$langs->trans('InitiallyGrabbedFrom').' '.$objectpage->grabbed_from.'</span>';
3730  print '</td></tr>';
3731 
3732  $type_container = $objectpage->type_container;
3733  $pageurl = $objectpage->pageurl;
3734  $pagealiasalt = $objectpage->aliasalt;
3735  $pagetitle = $objectpage->title;
3736  $pagedescription = $objectpage->description;
3737  $pageimage = $objectpage->image;
3738  $pagekeywords = $objectpage->keywords;
3739  $pagelang = $objectpage->lang;
3740  $pageallowedinframes = $objectpage->allowed_in_frames;
3741  $pagehtmlheader = $objectpage->htmlheader;
3742  $pagedatecreation = $objectpage->date_creation;
3743  $pagedatemodification = $objectpage->date_modification;
3744  $pageauthorid = $objectpage->fk_user_creat;
3745  $pageusermodifid = $objectpage->fk_user_modif;
3746  $pageauthoralias = $objectpage->author_alias;
3747  $pagestatus = $objectpage->status;
3748  } else {
3749  $type_container = 'page';
3750  $pageurl = '';
3751  $pagealiasalt = '';
3752  $pagetitle = '';
3753  $pagedescription = '';
3754  $pageimage = '';
3755  $pagekeywords = '';
3756  $pagelang = '';
3757  $pageallowedinframes = 0;
3758  $pagehtmlheader = '';
3759  $pagedatecreation = dol_now();
3760  $pagedatemodification = '';
3761  $pageauthorid = $user->id;
3762  $pageusermodifid = 0;
3763  $pageauthoralias = '';
3764  $pagestatus = 1;
3765  }
3766  if (GETPOST('WEBSITE_TITLE', 'alpha')) {
3767  $pagetitle = str_replace(array('<', '>'), '', GETPOST('WEBSITE_TITLE', 'alphanohtml'));
3768  }
3769  if (GETPOST('WEBSITE_PAGENAME', 'alpha')) {
3770  $pageurl = GETPOST('WEBSITE_PAGENAME', 'alpha');
3771  }
3772  if (GETPOST('WEBSITE_ALIASALT', 'alpha')) {
3773  $pagealiasalt = str_replace(array('<', '>'), '', GETPOST('WEBSITE_ALIASALT', 'alphanohtml'));
3774  }
3775  if (GETPOST('WEBSITE_DESCRIPTION', 'alpha')) {
3776  $pagedescription = str_replace(array('<', '>'), '', GETPOST('WEBSITE_DESCRIPTION', 'alphanohtml'));
3777  }
3778  if (GETPOST('WEBSITE_IMAGE', 'alpha')) {
3779  $pageimage = GETPOST('WEBSITE_IMAGE', 'alpha');
3780  }
3781  if (GETPOST('WEBSITE_KEYWORDS', 'alpha')) {
3782  $pagekeywords = str_replace(array('<', '>'), '', GETPOST('WEBSITE_KEYWORDS', 'alphanohtml'));
3783  }
3784  if (GETPOST('WEBSITE_LANG', 'aZ09')) {
3785  $pagelang = GETPOST('WEBSITE_LANG', 'aZ09');
3786  }
3787  if (GETPOST('WEBSITE_ALLOWED_IN_FRAMES', 'aZ09')) {
3788  $pageallowedinframes = GETPOST('WEBSITE_ALLOWED_IN_FRAMES', 'aZ09');
3789  }
3790  if (GETPOST('htmlheader', 'none')) {
3791  $pagehtmlheader = GETPOST('htmlheader', 'none');
3792  }
3793 
3794  if ($action != 'createcontainer') {
3795  print '<!-- Status of page -->'."\n";
3796  print '<tr><td class="fieldrequired">';
3797  print $langs->trans('Status');
3798  print '</td><td>';
3799  print ajax_object_onoff($objectpage, 'status', 'status', 'Enabled', 'Disabled');
3800  //print dol_print_date($pagedatecreation, 'dayhour');
3801  print '</td></tr>';
3802  }
3803 
3804  // Type of container
3805  print '<tr><td class="titlefield fieldrequired">';
3806  print $langs->trans('WEBSITE_TYPE_CONTAINER');
3807  print '</td><td>';
3808  print img_picto('', 'object_technic', 'class="paddingrightonly"').' ';
3809  $formwebsite->selectTypeOfContainer('WEBSITE_TYPE_CONTAINER', (GETPOST('WEBSITE_TYPE_CONTAINER', 'alpha') ? GETPOST('WEBSITE_TYPE_CONTAINER', 'alpha') : $type_container), 0, '', 1);
3810  print '</td></tr>';
3811 
3812  if ($action == 'createcontainer') {
3813  print '<tr><td class="titlefield fieldrequired">';
3814  print $langs->trans('WEBSITE_PAGE_EXAMPLE');
3815  print '</td><td>';
3816  print $formwebsite->selectSampleOfContainer('sample', (GETPOSTISSET('sample') ? GETPOST('sample', 'alpha') : 'empty'), 0, '', 1, 'minwidth300');
3817  print '</td></tr>';
3818  }
3819 
3820  // Title
3821  print '<tr><td class="fieldrequired">';
3822  print $langs->trans('WEBSITE_TITLE');
3823  print '</td><td>';
3824  print '<input type="text" class="flat quatrevingtpercent" name="WEBSITE_TITLE" id="WEBSITE_TITLE" value="'.dol_escape_htmltag($pagetitle).'" autofocus>';
3825  print '</td></tr>';
3826 
3827  // Alias
3828  print '<tr><td class="titlefieldcreate fieldrequired">';
3829  print $langs->trans('WEBSITE_PAGENAME');
3830  print '</td><td>';
3831  print '<input type="text" class="flat minwidth300" name="WEBSITE_PAGENAME" id="WEBSITE_PAGENAME" value="'.dol_escape_htmltag($pageurl).'">';
3832  print '</td></tr>';
3833 
3834  print '<tr><td class="titlefieldcreate">';
3835  $htmlhelp = $langs->trans("WEBSITE_ALIASALTDesc");
3836  print $form->textwithpicto($langs->trans('WEBSITE_ALIASALT'), $htmlhelp, 1, 'help', '', 0, 2, 'aliastooltip');
3837  print '</td><td>';
3838  print '<input type="text" class="flat minwidth500" name="WEBSITE_ALIASALT" value="'.dol_escape_htmltag($pagealiasalt).'">';
3839  print '</td></tr>';
3840 
3841  print '<tr><td>';
3842  print $langs->trans('WEBSITE_DESCRIPTION');
3843  print '</td><td>';
3844  print '<input type="text" class="flat quatrevingtpercent" name="WEBSITE_DESCRIPTION" value="'.dol_escape_htmltag($pagedescription).'">';
3845  print '</td></tr>';
3846 
3847  print '<tr><td>';
3848  $htmlhelp = $langs->trans("WEBSITE_IMAGEDesc");
3849  print $form->textwithpicto($langs->trans('WEBSITE_IMAGE'), $htmlhelp, 1, 'help', '', 0, 2, 'imagetooltip');
3850  print '</td><td>';
3851  print '<input type="text" class="flat quatrevingtpercent" name="WEBSITE_IMAGE" value="'.dol_escape_htmltag($pageimage).'">';
3852  print '</td></tr>';
3853 
3854  // Keywords
3855  print '<tr><td>';
3856  $htmlhelp = $langs->trans("WEBSITE_KEYWORDSDesc");
3857  print $form->textwithpicto($langs->trans('WEBSITE_KEYWORDS'), $htmlhelp, 1, 'help', '', 0, 2, 'keywordtooltip');
3858  print '</td><td>';
3859  print '<input type="text" class="flat quatrevingtpercent" name="WEBSITE_KEYWORDS" value="'.dol_escape_htmltag($pagekeywords).'">';
3860  print '</td></tr>';
3861 
3862  print '<tr><td>';
3863  print $langs->trans('Language');
3864  print '</td><td>';
3865  $onlykeys = array();
3866  if ($object->lang) {
3867  $onlykeys[$object->lang] = $object->lang;
3868  } else {
3869  $onlykeys[$langs->defaultlang] = $langs->defaultlang;
3870  }
3871  if ($object->otherlang) {
3872  $tmparray = explode(',', $object->otherlang);
3873  foreach ($tmparray as $key) {
3874  $tmpkey = trim($key);
3875  if (strlen($key) == 2) {
3876  $tmpkey = strtolower($key);
3877  }
3878  $onlykeys[$tmpkey] = $tmpkey;
3879  }
3880  }
3881  if (empty($object->lang) && empty($object->otherlang)) {
3882  $onlykeys = null; // We keep full list of languages
3883  }
3884  print img_picto('', 'language', 'class="pictofixedwidth"').$formadmin->select_language($pagelang ? $pagelang : '', 'WEBSITE_LANG', 0, null, '1', 0, 0, 'minwidth200', 0, 0, 0, $onlykeys, 1);
3885  $htmltext = $langs->trans("AvailableLanguagesAreDefinedIntoWebsiteProperties");
3886  print $form->textwithpicto('', $htmltext);
3887  print '</td></tr>';
3888 
3889  // Translation of
3890  $translationof = 0;
3891  $translatedby = 0;
3892  print '<!-- Translation of --><tr><td>';
3893  print $langs->trans('TranslationLinks');
3894  print '</td><td>';
3895  if ($action != 'createcontainer') {
3896  // Has translation pages
3897  $sql = "SELECT rowid, lang from ".MAIN_DB_PREFIX."website_page where fk_page = ".((int) $objectpage->id);
3898  $resql = $db->query($sql);
3899  if ($resql) {
3900  $num_rows = $db->num_rows($resql);
3901  if ($num_rows > 0) {
3902  print '<span class="opacitymedium">'.$langs->trans('ThisPageHasTranslationPages').':</span>';
3903  $i = 0;
3904  $tmppage = new WebsitePage($db);
3905  $tmpstring = '';
3906  while ($obj = $db->fetch_object($resql)) {
3907  $result = $tmppage->fetch($obj->rowid);
3908  if ($result > 0) {
3909  if ($i > 0) {
3910  $tmpstring .= '<br>';
3911  }
3912  $tmpstring .= $tmppage->getNomUrl(1).' ('.$tmppage->lang.')';
3913  $translatedby++;
3914  $i++;
3915  }
3916  }
3917  if ($i > 1) {
3918  print '<br>';
3919  } else {
3920  print ' ';
3921  }
3922  print $tmpstring;
3923  }
3924  } else {
3925  dol_print_error($db);
3926  }
3927  }
3928  if (empty($translatedby) && ($action == 'editmeta' || $action == 'createcontainer' || $objectpage->fk_page > 0)) {
3929  $sourcepage = new WebsitePage($db);
3930  $result = $sourcepage->fetch($objectpage->fk_page);
3931  if ($result == 0) {
3932  // not found, we can reset value to clean database
3933  } elseif ($result > 0) {
3934  $translationof = $objectpage->fk_page;
3935  print '<span class="opacitymedium">'.$langs->trans('ThisPageIsTranslationOf').'</span> ';
3936  print $formwebsite->selectContainer($website, 'pageidfortranslation', ($translationof ? $translationof : -1), 1, $action, 'minwidth300', array($objectpage->id));
3937  if ($translationof > 0 && $sourcepage->lang) {
3938  print $sourcepage->getNomUrl(2).' ('.$sourcepage->lang.')';
3939  }
3940  }
3941  }
3942  print '</td></tr>';
3943 
3944  // Allowed in frames
3945  print '<tr><td>';
3946  print $langs->trans('AllowedInFrames');
3947  //$htmlhelp = $langs->trans("AllowedInFramesDesc");
3948  //print $form->textwithpicto($langs->trans('AllowedInFrames'), $htmlhelp, 1, 'help', '', 0, 2, 'allowedinframestooltip');
3949  print '</td><td>';
3950  print '<input type="checkbox" class="flat" name="WEBSITE_ALLOWED_IN_FRAMES" value="1"'.($pageallowedinframes ? 'checked="checked"' : '').'>';
3951  print '</td></tr>';
3952 
3953  // Categories
3954  if (!empty($conf->categorie->enabled) && !empty($user->rights->categorie->lire)) {
3955  $langs->load('categories');
3956 
3957  if (!GETPOSTISSET('categories')) {
3958  $cate_arbo = $form->select_all_categories(Categorie::TYPE_WEBSITE_PAGE, '', null, null, null, 1);
3959  $c = new Categorie($db);
3960  $cats = $c->containing($objectpage->id, Categorie::TYPE_WEBSITE_PAGE);
3961  $arrayselected = array();
3962  if (is_array($cats)) {
3963  foreach ($cats as $cat) {
3964  $arrayselected[] = $cat->id;
3965  }
3966  }
3967 
3968  $cate_arbo = $form->select_all_categories(Categorie::TYPE_WEBSITE_PAGE, '', 'parent', null, null, 1);
3969  }
3970 
3971  print '<tr><td class="toptd">'.$form->editfieldkey('Categories', 'categories', '', $objectpage, 0).'</td><td>';
3972  print img_picto('', 'category', 'class="pictofixedwidth"');
3973  print $form->multiselectarray('categories', $cate_arbo, (GETPOSTISSET('categories') ? GETPOST('categories', 'array') : $arrayselected), null, null, 'minwidth200 widthcentpercentminusxx');
3974  print "</td></tr>";
3975  }
3976 
3977  if (!empty($conf->global->WEBSITE_PAGE_SHOW_INTERNAL_LINKS_TO_OBJECT)) { // TODO Replace this with link into element_element ?
3978  print '<tr><td class="titlefieldcreate">';
3979  print 'ObjectClass';
3980  print '</td><td>';
3981  print '<input type="text" class="flat minwidth300" name="WEBSITE_OBJECTCLASS" placeholder="ClassName::/path/class/ObjectClass.class.php" >';
3982  print '</td></tr>';
3983 
3984  print '<tr><td class="titlefieldcreate">';
3985  print 'ObjectID';
3986  print '</td><td>';
3987  print '<input type="text" class="flat minwidth300" name="WEBSITE_OBJECTID" >';
3988  print '</td></tr>';
3989  }
3990 
3991  $fuser = new User($db);
3992 
3993  print '<tr><td>';
3994  print $langs->trans('Author');
3995  print '</td><td>';
3996  if ($pageauthorid > 0) {
3997  $fuser->fetch($pageauthorid);
3998  print $fuser->getNomUrl(1);
3999  } else {
4000  print '<span class="opacitymedium">'.$langs->trans("Unknown").'</span>';
4001  }
4002  print '</td></tr>';
4003 
4004  print '<tr><td>';
4005  print $langs->trans('PublicAuthorAlias');
4006  print '</td><td>';
4007  print '<input type="text" class="flat minwidth300" name="WEBSITE_AUTHORALIAS" value="'.dol_escape_htmltag($pageauthoralias).'" placeholder="Anonymous">';
4008  print '</td></tr>';
4009 
4010  print '<tr><td>';
4011  print $langs->trans('DateCreation');
4012  print '</td><td>';
4013  print $form->selectDate($pagedatecreation, 'datecreation', 1, 1, 0, '', 1, 1);
4014  //print dol_print_date($pagedatecreation, 'dayhour');
4015  print '</td></tr>';
4016 
4017  if ($action != 'createcontainer') {
4018  print '<tr><td>';
4019  print $langs->trans('UserModif');
4020  print '</td><td>';
4021  if ($pageusermodifid > 0) {
4022  $fuser->fetch($pageusermodifid);
4023  print $fuser->getNomUrl(1);
4024  }
4025  print '</td></tr>';
4026 
4027  print '<tr><td>';
4028  print $langs->trans('DateModification');
4029  print '</td><td>';
4030  print dol_print_date($pagedatemodification, 'dayhour', 'tzuser');
4031  print '</td></tr>';
4032  }
4033 
4034  print '<tr><td class="tdhtmlheader tdtop">';
4035  $htmlhelp = $langs->trans("EditTheWebSiteForACommonHeader").'<br><br>';
4036  $htmlhelp .= $langs->trans("Example").' :<br>';
4037  $htmlhelp .= dol_htmlentitiesbr($htmlheadercontentdefault);
4038  print $form->textwithpicto($langs->trans('HtmlHeaderPage'), $htmlhelp, 1, 'help', '', 0, 2, 'htmlheadertooltip');
4039  print '</td><td>';
4040  $poscursor = array('x'=>GETPOST('htmlheader_x'), 'y'=>GETPOST('htmlheader_y'));
4041  $doleditor = new DolEditor('htmlheader', $pagehtmlheader, '', '120', 'ace', 'In', true, false, 'ace', ROWS_3, '100%', '', $poscursor);
4042  print $doleditor->Create(1, '', true, 'HTML Header', 'html');
4043  print '</td></tr>';
4044 
4045  print '</table>';
4046  if ($action == 'createcontainer') {
4047  print '<div class="center tablecheckboxcreatemanually'.$hiddenmanuallyafterload.'">';
4048 
4049  print '<input type="submit" class="button small" name="addcontainer" value="'.$langs->trans("Create").'">';
4050  print '<input class="button button-cancel small" type="submit" name="preview" value="'.$langs->trans("Cancel").'">';
4051 
4052  print '</div>';
4053 
4054 
4055  print '<br>';
4056 
4057  if (!empty($conf->use_javascript_ajax)) {
4058  print '<input type="radio" name="radiocreatefrom" id="checkboxcreatefromfetching" value="checkboxcreatefromfetching"'.(GETPOST('radiocreatefrom') == 'checkboxcreatefromfetching' ? ' checked' : '').'> ';
4059  }
4060  print '<label for="checkboxcreatefromfetching"><span class="opacitymediumxx">'.$langs->trans("CreateByFetchingExternalPage").'</span></label><br>';
4061  print '<hr class="tablecheckboxcreatefromfetching'.$hiddenfromfetchingafterload.'">';
4062  print '<table class="tableforfield centpercent tablecheckboxcreatefromfetching'.$hiddenfromfetchingafterload.'">';
4063  print '<tr><td class="titlefield">';
4064  print $langs->trans("URL");
4065  print '</td><td>';
4066  print info_admin($langs->trans("OnlyEditionOfSourceForGrabbedContentFuture"), 0, 0, 'warning');
4067  print '<input class="flat minwidth500" type="text" name="externalurl" value="'.dol_escape_htmltag(GETPOST('externalurl', 'alpha')).'" placeholder="https://externalsite/pagetofetch"> ';
4068  print '<br><input class="flat paddingtop" type="checkbox" name="grabimages" value="1" checked="checked"> '.$langs->trans("GrabImagesInto");
4069  print ' ';
4070  print $langs->trans("ImagesShouldBeSavedInto").' ';
4071  $arraygrabimagesinto = array('root'=>$langs->trans("WebsiteRootOfImages"), 'subpage'=>$langs->trans("SubdirOfPage"));
4072  print $form->selectarray('grabimagesinto', $arraygrabimagesinto, GETPOSTISSET('grabimagesinto') ? GETPOST('grabimagesinto') : 'root', 0, 0, 0, '', 0, 0, 0, '', '', 1);
4073  print '<br>';
4074  print '<input class="button" style="margin-top: 5px" type="submit" name="fetchexternalurl" value="'.dol_escape_htmltag($langs->trans("FetchAndCreate")).'">';
4075  print '</td></tr>';
4076  print '</table>';
4077  }
4078 
4079  if ($action == 'createcontainer') {
4080  print '<script type="text/javascript">
4081  jQuery(document).ready(function() {
4082  var disableautofillofalias = 0;
4083  var selectedm = \'\';
4084  var selectedf = \'\';
4085  jQuery("#WEBSITE_TITLE").keyup(function() {
4086  if (disableautofillofalias == 0)
4087  {
4088  var valnospecial = jQuery("#WEBSITE_TITLE").val();
4089  valnospecial = valnospecial.replace(/[éèê]/g, \'e\').replace(/[à]/g, \'a\').replace(/[ù]/g, \'u\').replace(/[î]/g, \'i\');
4090  valnospecial = valnospecial.replace(/[ç]/g, \'c\').replace(/[ö]/g, \'o\');
4091  valnospecial = valnospecial.replace(/[^\w]/gi, \'-\').toLowerCase();
4092  valnospecial = valnospecial.replace(/\-+/g, \'-\').replace(/\-$/, \'\');
4093  console.log("disableautofillofalias=0 so we replace WEBSITE_TITLE with "+valnospecial);
4094  jQuery("#WEBSITE_PAGENAME").val(valnospecial);
4095  }
4096  });
4097  jQuery("#WEBSITE_PAGENAME").keyup(function() {
4098  disableautofillofalias = 1;
4099  });
4100 
4101  jQuery("#checkboxcreatefromfetching,#checkboxcreatemanually").click(function() {
4102  console.log("we select a method to create a new container "+jQuery("#checkboxcreatefromfetching:checked").val())
4103  jQuery(".tablecheckboxcreatefromfetching").hide();
4104  jQuery(".tablecheckboxcreatemanually").hide();
4105  if (typeof(jQuery("#checkboxcreatefromfetching:checked").val()) != \'undefined\') {
4106  console.log("show a");
4107  if (selectedf != \'createfromfetching\') {
4108  jQuery(".tablecheckboxcreatefromfetching").show();
4109  selectedf = \'createfromfetching\';
4110  selectedm = \'\';
4111  } else {
4112  jQuery(".tablecheckboxcreatefromfetching").hide();
4113  selectedf = \'\';
4114  }
4115  }
4116  if (typeof(jQuery("#checkboxcreatemanually:checked").val()) != \'undefined\') {
4117  console.log("show b");
4118  if (selectedm != \'createmanually\') {
4119  jQuery(".tablecheckboxcreatemanually").show();
4120  selectedm = \'createmanually\';
4121  selectedf = \'\';
4122  } else {
4123  jQuery(".tablecheckboxcreatemanually").hide();
4124  selectedm = \'\';
4125  }
4126  }
4127  });
4128  });
4129  </script>';
4130  }
4131  //print '</div>';
4132 
4133  //print dol_get_fiche_end();
4134 
4135  print '</div>';
4136 
4137  print '<br>';
4138 }
4139 
4140 
4141 // Print formconfirm
4142 if ($action == 'preview') {
4143  print $formconfirm;
4144 }
4145 
4146 if ($action == 'editfile' || $action == 'file_manager' || $action == 'convertimgwebp' || $action == 'confirmconvertimgwebp') {
4147  print '<!-- Edit Media -->'."\n";
4148  print '<div class="fiche"><br>';
4149  //print '<div class="center">'.$langs->trans("FeatureNotYetAvailable").'</center>';
4150 
4151 
4152  $module = 'medias';
4153  $formalreadyopen = 2; // So the form to submit a new file will not be opened another time inside the core/tpl/filemanager.tpl.php
4154  if (empty($url)) {
4155  $url = DOL_URL_ROOT.'/website/index.php'; // Must be an url without param
4156  }
4157  include DOL_DOCUMENT_ROOT.'/core/tpl/filemanager.tpl.php';
4158 
4159  print '</div>';
4160 }
4161 
4162 if ($action == 'editmenu') {
4163  print '<!-- Edit Menu -->'."\n";
4164  print '<div class="center">'.$langs->trans("FeatureNotYetAvailable").'</center>';
4165 }
4166 
4167 if ($action == 'editsource') {
4168  // Editing with source editor
4169 
4170  $contentforedit = '';
4171  //$contentforedit.='<style scoped>'."\n"; // "scoped" means "apply to parent element only". Not yet supported by browsers
4172  //$contentforedit.=$csscontent;
4173  //$contentforedit.='</style>'."\n";
4174  $contentforedit .= $objectpage->content;
4175  //var_dump($_SESSION["dol_screenheight"]);
4176  $maxheightwin = 480;
4177  if (isset($_SESSION["dol_screenheight"])) {
4178  if ($_SESSION["dol_screenheight"] > 680) {
4179  $maxheightwin = $_SESSION["dol_screenheight"] - 400;
4180  }
4181  if ($_SESSION["dol_screenheight"] > 800) {
4182  $maxheightwin = $_SESSION["dol_screenheight"] - 490;
4183  }
4184  }
4185 
4186  $poscursor = array('x'=>GETPOST('PAGE_CONTENT_x'), 'y'=>GETPOST('PAGE_CONTENT_y'));
4187  require_once DOL_DOCUMENT_ROOT.'/core/class/doleditor.class.php';
4188  $doleditor = new DolEditor('PAGE_CONTENT', $contentforedit, '', $maxheightwin, 'Full', '', true, true, 'ace', ROWS_5, '40%', 0, $poscursor);
4189  $doleditor->Create(0, '', false, 'HTML Source', 'php');
4190 }
4191 
4192 /*if ($action == 'editcontent')
4193 {
4194  // Editing with default ckeditor
4195 
4196  $contentforedit = '';
4197  //$contentforedit.='<style scoped>'."\n"; // "scoped" means "apply to parent element only". Not yet supported by browsers
4198  //$contentforedit.=$csscontent;
4199  //$contentforedit.='</style>'."\n";
4200  $contentforedit .= $objectpage->content;
4201 
4202  $contentforedit = preg_replace('/(<img.*src=")(?!http)/', '\1'.DOL_URL_ROOT.'/viewimage.php?modulepart=medias&file=', $contentforedit, -1, $nbrep);
4203 
4204  require_once DOL_DOCUMENT_ROOT.'/core/class/doleditor.class.php';
4205  $poscursor = array('x'=>GETPOST('PAGE_CONTENT_x'), 'y'=>GETPOST('PAGE_CONTENT_y'));
4206  $doleditor=new DolEditor('PAGE_CONTENT',$contentforedit,'',500,'Full','',true,true,true,ROWS_5,'90%',$poscursor);
4207  $doleditor->Create(0, '', false);
4208 }*/
4209 
4210 print "</div>\n";
4211 print "</form>\n";
4212 
4213 
4214 if ($action == 'replacesite' || $action == 'replacesiteconfirm' || $massaction == 'replace') {
4215  print '<form action="'.$_SERVER["PHP_SELF"].'" method="POST">';
4216  print '<input type="hidden" name="token" value="'.newToken().'">';
4217  print '<input type="hidden" name="action" value="replacesiteconfirm">';
4218  print '<input type="hidden" name="website" value="'.$website->ref.'">';
4219 
4220 
4221  print '<!-- Search page and replace string -->'."\n";
4222  print '<div class="fiche"><br>';
4223 
4224  print load_fiche_titre($langs->trans("ReplaceWebsiteContent"), '', 'search');
4225 
4226  print '<div class="fichecenter"><div class="fichehalfleft">';
4227 
4228  print '<div class="tagtable">';
4229 
4230  print '<div class="tagtr">';
4231  print '<div class="tagtd paddingrightonly opacitymedium">';
4232  print $langs->trans("SearchReplaceInto");
4233  print '</div>';
4234  print '<div class="tagtd">';
4235  print '<input type="checkbox" class="marginleftonly" id="checkboxoptioncontent" name="optioncontent" value="content"'.((!GETPOSTISSET('buttonreplacesitesearch') || GETPOST('optioncontent', 'aZ09')) ? ' checked' : '').'> <label for="checkboxoptioncontent" class="tdoverflowmax150onsmartphone inline-block valignmiddle">'.$langs->trans("Content").'</label><br>';
4236  print '<input type="checkbox" class="marginleftonly" id="checkboxoptionmeta" name="optionmeta" value="meta"'.(GETPOST('optionmeta', 'aZ09') ? ' checked' : '').'> <label for="checkboxoptionmeta" class="tdoverflowmax150onsmartphone inline-block valignmiddle">'.$langs->trans("Title").' | '.$langs->trans("Description").' | '.$langs->trans("Keywords").'</label><br>';
4237  print '<input type="checkbox" class="marginleftonly" id="checkboxoptionsitefiles" name="optionsitefiles" value="sitefiles"'.(GETPOST('optionsitefiles', 'aZ09') ? ' checked' : '').'> <label for="checkboxoptionsitefiles" class="tdoverflowmax150onsmartphone inline-block valignmiddle">'.$langs->trans("GlobalCSSorJS").'</label><br>';
4238  print '</div>';
4239  print '</div>';
4240 
4241  print '<div class="tagtr">';
4242  print '<div class="tagtd paddingrightonly opacitymedium" style="padding-right: 10px !important">';
4243  print $langs->trans("SearchString");
4244  print '</div>';
4245  print '<div class="tagtd">';
4246  print '<input type="text" name="searchstring" value="'.dol_escape_htmltag($searchkey, 0, 0, '', 1).'" autofocus>';
4247  print '</div>';
4248  print '</div>';
4249 
4250  print '</div>';
4251 
4252  print '</div><div class="fichehalfleft">';
4253 
4254  print '<div class="tagtable">';
4255 
4256  print '<div class="tagtr">';
4257  print '<div class="tagtd paddingrightonly opacitymedium tdoverflowmax100onsmartphone" style="padding-right: 10px !important">';
4258  print $langs->trans("WEBSITE_TYPE_CONTAINER");
4259  print '</div>';
4260  print '<div class="tagtd">';
4261  print img_picto('', 'object_technic', 'class="paddingrightonly"').' ';
4262  $formwebsite->selectTypeOfContainer('optioncontainertype', (GETPOST('optioncontainertype', 'alpha') ? GETPOST('optioncontainertype', 'alpha') : ''), 1, '', 1, 'minwidth125 maxwidth400 widthcentpercentminusx');
4263  print '</div>';
4264  print '</div>';
4265 
4266  print '<div class="tagtr">';
4267  print '<div class="tagtd paddingrightonly opacitymedium tdoverflowmax100onsmartphone" style="padding-right: 10px !important">';
4268  print $langs->trans("Language");
4269  print '</div>';
4270  print '<div class="tagtd">';
4271  print img_picto('', 'language', 'class="paddingrightonly"').' '.$formadmin->select_language(GETPOSTISSET('optionlanguage') ? GETPOST('optionlanguage') : '', 'optionlanguage', 0, null, '1', 0, 0, 'minwidth125 maxwidth400 widthcentpercentminusx', 2, 0, 0, null, 1);
4272  print '</div>';
4273  print '</div>';
4274 
4275  // Categories
4276  if (!empty($conf->categorie->enabled) && !empty($user->rights->categorie->lire)) {
4277  print '<div class="tagtr">';
4278  print '<div class="tagtd paddingrightonly marginrightonly opacitymedium tdoverflowmax100onsmartphone" style="padding-right: 10px !important">';
4279  print $langs->trans("Category");
4280  print '</div>';
4281  print '<div class="tagtd">';
4282  print img_picto('', 'category', 'class="paddingrightonly"').' '.$form->select_all_categories(Categorie::TYPE_WEBSITE_PAGE, GETPOSTISSET('optioncategory') ? GETPOST('optioncategory') : '', 'optioncategory', 0, 0, 0, 0, 'minwidth125 maxwidth400 widthcentpercentminusx');
4283  include_once DOL_DOCUMENT_ROOT.'/core/lib/ajax.lib.php';
4284  print ajax_combobox('optioncategory');
4285  print '</div>';
4286  print '</div>';
4287  }
4288 
4289  print '</div>';
4290 
4291  print '<input type="submit" class="button margintoponly" name="buttonreplacesitesearch" value="'.dol_escape_htmltag($langs->trans("Search")).'">';
4292 
4293  print '</div></div>';
4294 
4295  if ($action == 'replacesiteconfirm') {
4296  print '<!-- List of search result -->'."\n";
4297  print '<div class="rowsearchresult clearboth">';
4298 
4299  print '<br>';
4300  print '<br>';
4301 
4302  if ($listofpages['code'] == 'OK') {
4303  $arrayofselected = is_array($toselect) ? $toselect : array();
4304  $param = '';
4305  $nbtotalofrecords = count($listofpages['list']);
4306  $num = $limit;
4307  $permissiontodelete = $user->rights->website->delete;
4308 
4309  // List of mass actions available
4310  $arrayofmassactions = array();
4311  if ($user->rights->website->writephp && $searchkey) {
4312  $arrayofmassactions['replace'] = $langs->trans("Replace");
4313  }
4314  if ($user->rights->website->write) {
4315  $arrayofmassactions['setcategory'] = $langs->trans("ClassifyInCategory");
4316  }
4317  if ($permissiontodelete) {
4318  $arrayofmassactions['predelete'] = '<span class="fa fa-trash paddingrightonly"></span>'.$langs->trans("Delete");
4319  }
4320  if (GETPOST('nomassaction', 'int') || in_array($massaction, array('presend', 'predelete'))) {
4321  $arrayofmassactions = array();
4322  }
4323 
4324  $massactionbutton = $form->selectMassAction('', $arrayofmassactions);
4325  $massactionbutton .= '<div class="massactionother massactionreplace hidden">';
4326  $massactionbutton .= $langs->trans("ReplaceString");
4327  $massactionbutton .= ' <input type="text" name="replacestring" value="'.dol_escape_htmltag(GETPOST('replacestring', 'none')).'">';
4328  $massactionbutton .= '</div>';
4329  $massactionbutton .= '<div class="massactionother massactionsetcategory hidden">';
4330  $massactionbutton .= $langs->trans("Category");
4331  $massactionbutton .= ' '.$form->select_all_categories(Categorie::TYPE_WEBSITE_PAGE, GETPOSTISSET('setcategory') ? GETPOST('setcategory') : '', 'setcategory', 64, 0, 0, 0, 'minwidth300 alignstart');
4332  include_once DOL_DOCUMENT_ROOT.'/core/lib/ajax.lib.php';
4333  $massactionbutton .= ajax_combobox('setcategory');
4334  $massactionbutton .= '</div>';
4335 
4336  $varpage = empty($contextpage) ? $_SERVER["PHP_SELF"] : $contextpage;
4337  //$selectedfields = $form->multiSelectArrayWithCheckbox('selectedfields', $arrayfields, $varpage); // This also change content of $arrayfields
4338  $selectedfields .= $form->showCheckAddButtons('checkforselect', 1);
4339 
4340  print_barre_liste($langs->trans("Results"), $page, $_SERVER["PHP_SELF"], $param, $sortfield, $sortorder, $massactionbutton, $num, $nbtotalofrecords, 'generic', 0, '', '', $limit, 1, 1, 1);
4341 
4342  $topicmail = "WebsitePageRef";
4343  $modelmail = "websitepage_send";
4344  $objecttmp = new WebsitePage($db);
4345  $trackid = 'wsp'.$object->id;
4346  include DOL_DOCUMENT_ROOT.'/core/tpl/massactions_pre.tpl.php';
4347 
4348  $param = 'action=replacesiteconfirm&website='.urlencode($website->ref);
4349  $param .= '&searchstring='.urlencode($searchkey);
4350  if (GETPOST('optioncontent')) {
4351  $param .= '&optioncontent=content';
4352  }
4353  if (GETPOST('optionmeta')) {
4354  $param .= '&optionmeta=meta';
4355  }
4356  if (GETPOST('optionsitefiles')) {
4357  $param .= '&optionsitefiles=optionsitefiles';
4358  }
4359  if (GETPOST('optioncontainertype')) {
4360  $param .= '&optioncontainertype='.GETPOST('optioncontainertype', 'aZ09');
4361  }
4362  if (GETPOST('optionlanguage')) {
4363  $param .= '&optionlanguage='.GETPOST('optionlanguage', 'aZ09');
4364  }
4365  if (GETPOST('optioncategory')) {
4366  $param .= '&optioncategory='.GETPOST('optioncategory', 'aZ09');
4367  }
4368 
4369  print '<div class="div-table-responsive-no-min">';
4370  print '<table class="noborder centpercent">';
4371  print '<tr class="liste_titre">';
4372  print getTitleFieldOfList("Type", 0, $_SERVER['PHP_SELF'], 'type_container', '', $param, '', $sortfield, $sortorder, '')."\n";
4373  print getTitleFieldOfList("Page", 0, $_SERVER['PHP_SELF'], 'pageurl', '', $param, '', $sortfield, $sortorder, '')."\n";
4374  print getTitleFieldOfList("Categories", 0, $_SERVER['PHP_SELF']);
4375  print getTitleFieldOfList("Language", 0, $_SERVER['PHP_SELF'], 'lang', '', $param, '', $sortfield, $sortorder, 'center ')."\n";
4376  print getTitleFieldOfList("", 0, $_SERVER['PHP_SELF']);
4377  print getTitleFieldOfList("DateLastModification", 0, $_SERVER['PHP_SELF'], 'tms', '', $param, '', $sortfield, $sortorder, 'center ')."\n"; // Date last modif
4378  print getTitleFieldOfList("", 0, $_SERVER['PHP_SELF']);
4379  print getTitleFieldOfList($selectedfields, 0, $_SERVER["PHP_SELF"], '', '', '', '', $sortfield, $sortorder, 'center maxwidthsearch ')."\n";
4380  print '</tr>';
4381 
4382  require_once DOL_DOCUMENT_ROOT.'/categories/class/categorie.class.php';
4383  $c = new Categorie($db);
4384 
4385  $totalnbwords = 0;
4386 
4387  foreach ($listofpages['list'] as $answerrecord) {
4388  if (get_class($answerrecord) == 'WebsitePage') {
4389  print '<tr>';
4390 
4391  // Type of container
4392  print '<td class="nowraponall">'.$langs->trans("Container").' - ';
4393  print $langs->trans($answerrecord->type_container); // TODO Use label of container
4394  print '</td>';
4395 
4396  // Container url and label
4397  print '<td>';
4398  print $answerrecord->getNomUrl(1);
4399  print ' <span class="opacitymedium">('.($answerrecord->title ? $answerrecord->title : $langs->trans("NoTitle")).')</span>';
4400  //print '</td>';
4401  //print '<td class="tdoverflow100">';
4402  print '<br>';
4403  print '<span class="opacitymedium">'.$answerrecord->description.'</span>';
4404  print '</td>';
4405 
4406  // Categories - Tags
4407  print '<td>';
4408  if (!empty($conf->categorie->enabled) && !empty($user->rights->categorie->lire)) {
4409  // Get current categories
4410  $existing = $c->containing($answerrecord->id, Categorie::TYPE_WEBSITE_PAGE, 'object');
4411  if (is_array($existing)) {
4412  foreach ($existing as $tmpcategory) {
4413  //var_dump($tmpcategory);
4414  print img_object($langs->trans("Category").' : '.$tmpcategory->label, 'category', 'style="padding-left: 2px; padding-right: 2px; color: #'.($tmpcategory->color != '' ? $tmpcategory->color : '888').'"');
4415  }
4416  }
4417  }
4418  //var_dump($existing);
4419  print '</td>';
4420 
4421 
4422  $param = '?action=replacesiteconfirm';
4423  $param .= '&websiteid='.$website->id;
4424  $param .= '&optioncontent='.GETPOST('optioncontent', 'aZ09');
4425  $param .= '&optionmeta='.GETPOST('optionmeta', 'aZ09');
4426  $param .= '&optionsitefiles='.GETPOST('optionsitefiles', 'aZ09');
4427  $param .= '&optioncontainertype='.GETPOST('optioncontainertype', 'aZ09');
4428  $param .= '&optionlanguage='.GETPOST('optionlanguage', 'aZ09');
4429  $param .= '&optioncategory='.GETPOST('optioncategory', 'aZ09');
4430  $param .= '&searchstring='.urlencode($searchkey);
4431 
4432  // Language
4433  print '<td class="center">';
4434  print picto_from_langcode($answerrecord->lang, $answerrecord->lang);
4435  print '</td>';
4436 
4437  // Number of words
4438  print '<td class="center nowraponall">';
4439  $textwithouthtml = dol_string_nohtmltag(dolStripPhpCode($answerrecord->content));
4440  $characterMap = 'áàéèëíóúüñùç0123456789';
4441  $nbofwords = str_word_count($textwithouthtml, 0, $characterMap);
4442  if ($nbofwords) {
4443  print $nbofwords.' '.$langs->trans("words");
4444  $totalnbwords += $nbofwords;
4445  }
4446  print '</td>';
4447 
4448  // Date last modification
4449  print '<td class="center nowraponall">';
4450  print dol_print_date($answerrecord->date_modification, 'dayhour');
4451  print '</td>';
4452 
4453  // Edit properties, HTML sources, status
4454  print '<td class="tdwebsitesearchresult right nowraponall">';
4455  $disabled = '';
4456  $urltoedithtmlsource = $_SERVER["PHP_SELF"].'?action=editmeta&token='.newToken().'&websiteid='.$website->id.'&pageid='.$answerrecord->id.'&backtopage='.urlencode($_SERVER["PHP_SELF"].$param);
4457  if (empty($user->rights->website->write)) {
4458  $disabled = ' disabled';
4459  $urltoedithtmlsource = '';
4460  }
4461  print '<a class="editfielda marginleftonly marginrightonly '.$disabled.'" href="'.$urltoedithtmlsource.'" title="'.$langs->trans("EditPageMeta").'">'.img_picto($langs->trans("EditPageMeta"), 'pencil-ruler').'</a>';
4462 
4463  $disabled = '';
4464  $urltoedithtmlsource = $_SERVER["PHP_SELF"].'?action=editsource&token='.newToken().'&websiteid='.$website->id.'&pageid='.$answerrecord->id.'&backtopage='.urlencode($_SERVER["PHP_SELF"].$param);
4465  if (empty($user->rights->website->write)) {
4466  $disabled = ' disabled';
4467  $urltoedithtmlsource = '';
4468  }
4469  print '<a class="editfielda marginleftonly marginrightonly '.$disabled.'" href="'.$urltoedithtmlsource.'" title="'.$langs->trans("EditHTMLSource").'">'.img_picto($langs->trans("EditHTMLSource"), 'edit').'</a>';
4470 
4471  print '<span class="marginleftonly marginrightonly"></span>'.ajax_object_onoff($answerrecord, 'status', 'status', 'Enabled', 'Disabled', array(), 'valignmiddle');
4472 
4473  print '</td>';
4474 
4475  // Action column
4476  print '<td class="nowrap center">';
4477 
4478  print '<!-- Status of page -->'."\n";
4479  if ($massactionbutton || $massaction) {
4480  $selected = 0;
4481  if (in_array($answerrecord->id, $arrayofselected)) {
4482  $selected = 1;
4483  }
4484  print '<input id="'.$answerrecord->id.'" class="flat checkforselect" type="checkbox" name="toselect[]" value="'.$answerrecord->id.'"'.($selected ? ' checked="checked"' : '').'>';
4485  }
4486  print '</td>';
4487 
4488  print '</tr>';
4489  } else {
4490  print '<tr>';
4491 
4492  // Type of container
4493  print '<td>';
4494  $translateofrecordtype = array(
4495  'website_csscontent'=>'WEBSITE_CSS_INLINE',
4496  'website_jscontent'=>'WEBSITE_JS_INLINE',
4497  'website_robotcontent'=>'WEBSITE_ROBOT',
4498  'website_htmlheadercontent'=>'WEBSITE_HTML_HEADER',
4499  'website_htaccess'=>'WEBSITE_HTACCESS',
4500  'website_readme'=>'WEBSITE_README',
4501  'website_manifestjson'=>'WEBSITE_MANIFEST_JSON'
4502  );
4503  if (!empty($translateofrecordtype[$answerrecord['type']])) {
4504  print $langs->trans($translateofrecordtype[$answerrecord['type']]);
4505  } else {
4506  print $answerrecord['type'];
4507  }
4508  print '</td>';
4509 
4510  $param = '?action=replacesiteconfirm';
4511  $param .= '&websiteid='.$website->id;
4512  $param .= '&optioncontent='.GETPOST('optioncontent', 'aZ09');
4513  $param .= '&optionmeta='.GETPOST('optionmeta', 'aZ09');
4514  $param .= '&optionsitefiles='.GETPOST('optionsitefiles', 'aZ09');
4515  $param .= '&optioncontainertype='.GETPOST('optioncontainertype', 'aZ09');
4516  $param .= '&optionlanguage='.GETPOST('optionlanguage', 'aZ09');
4517  $param .= '&optioncategory='.GETPOST('optioncategory', 'aZ09');
4518  $param .= '&searchstring='.urlencode($searchkey);
4519 
4520  // Container url and label
4521  print '<td>';
4522  $backtopageurl = $_SERVER["PHP_SELF"].$param;
4523  print '<a href="'.$_SERVER["PHP_SELF"].'?action=editcss&token='.newToken().'&website='.urlencode($website->ref).'&backtopage='.urlencode($backtopageurl).'">'.$langs->trans("EditCss").'</a>';
4524  print '</td>';
4525 
4526  // Language
4527  print '<td>';
4528  print '</td>';
4529 
4530  // Categories - Tags
4531  print '<td>';
4532  print '</td>';
4533 
4534  // Nb of words
4535  print '<td>';
4536  print '</td>';
4537 
4538  // Date last modification
4539  print '<td class="center nowraponall">';
4540  //print dol_print_date(filemtime());
4541  print '</td>';
4542 
4543  // Edit properties, HTML sources, status
4544  print '<td>';
4545  print '</td>';
4546 
4547  // Action column
4548  print '<td class="nowrap center">';
4549  print '</td>';
4550 
4551  print '</tr>';
4552  }
4553  }
4554 
4555  if (count($listofpages['list']) >= 2) {
4556  // Total
4557  print '<tr class="lite_titre">';
4558 
4559  // Type of container
4560  print '<td>';
4561  print $langs->trans("Total");
4562  print '</td>';
4563 
4564  // Container url and label
4565  print '<td>';
4566  print '</td>';
4567 
4568  // Language
4569  print '<td>';
4570  print '</td>';
4571 
4572  // Categories - Tags
4573  print '<td>';
4574  print '</td>';
4575 
4576  // Nb of words
4577  print '<td class="center nowraponall">';
4578  print $totalnbwords.' '.$langs->trans("words");
4579  print '</td>';
4580 
4581  // Date last modification
4582  print '<td>';
4583  print '</td>';
4584 
4585  // Edit properties, HTML sources, status
4586  print '<td>';
4587  print '</td>';
4588 
4589  // Action column
4590  print '<td class="nowrap center">';
4591  print '</td>';
4592 
4593  print '</tr>';
4594  }
4595 
4596  print '</table>';
4597  print '</div>';
4598  print '<br>';
4599  } else {
4600  print '<div class="warning">'.$listofpages['message'].'</div>';
4601  }
4602 
4603  print '</div>';
4604  }
4605 
4606  print '</form>';
4607 }
4608 
4609 if ($action == 'preview' || $action == 'createfromclone' || $action == 'createpagefromclone') {
4610  if ($pageid > 0 && $atleastonepage) {
4611  // $filejs
4612  // $filecss
4613  // $filephp
4614 
4615  // Ouput page under the Dolibarr top menu
4616  $objectpage->fetch($pageid);
4617 
4618  $jscontent = @file_get_contents($filejs);
4619 
4620  $out = '<!-- Page content '.$filetpl.' : Div with (Htmlheader/Style of page from database + CSS Of website from file + Page content from database or by include if WEBSITE_SUBCONTAINERSINLINE is on) -->'."\n";
4621 
4622  // Include a html so we can benefit of the header of page.
4623  // Note: We can't use iframe as it can be used to include another external html file
4624  // Note: We can't use frame as it is deprecated.
4625  /*if ($includepageintoaframeoradiv == 'iframe')
4626  {
4627  $out .= "<iframe><body></html>";
4628  }*/
4629  $out .= "\n<html><head>\n";
4630  $out .= "<!-- htmlheader/style of page from database -->\n";
4631  $out .= dolWebsiteReplacementOfLinks($object, $objectpage->htmlheader, 1, 'htmlheader');
4632 
4633  $out .= "<!-- htmlheader/style of website from files -->\n";
4634  // TODO Keep only the <link> or the <script> tags
4635  /*
4636  $htmlheadercontent = @file_get_contents($filehtmlheader);
4637  $dom = new DOMDocument;
4638  @$dom->loadHTML($htmlheadercontent);
4639  $styles = $dom->getElementsByTagName('link');
4640  $scripts = $dom->getElementsByTagName('script');
4641  foreach($styles as $stylescursor)
4642  {
4643  $out.=$stylescursor;
4644  }
4645  foreach($scripts as $scriptscursor)
4646  {
4647  $out.=$scriptscursor;
4648  }
4649  */
4650 
4651  $out .= "</head>\n";
4652  $out .= "\n<body>";
4653 
4654 
4655  $out .= '<div id="websitecontentundertopmenu" class="websitecontentundertopmenu boostrap-iso">'."\n";
4656 
4657  // REPLACEMENT OF LINKS When page called by website editor
4658 
4659  $out .= '<!-- style of website from file -->'."\n";
4660  $out .= '<style scoped>'."\n"; // "scoped" means "apply to parent element only and not grand parent". No more supported by browsers, snif !
4661  $tmpout = '';
4662  $tmpout .= '/* Include website CSS file */'."\n";
4663  //$csscontent = @file_get_contents($filecss);
4664  ob_start();
4665  include $filecss;
4666  $csscontent = ob_get_contents();
4667  ob_end_clean();
4668  $tmpout .= dolWebsiteReplacementOfLinks($object, $csscontent, 1, 'css');
4669  $tmpout .= '/* Include style from the HTML header of page */'."\n";
4670  // Clean the html header of page to get only <style> content
4671  $tmp = preg_split('(<style[^>]*>|</style>)', $objectpage->htmlheader);
4672  $tmpstyleinheader = '';
4673  $i = 0;
4674  foreach ($tmp as $valtmp) {
4675  $i++;
4676  if ($i % 2 == 0) {
4677  $tmpstyleinheader .= $valtmp."\n";
4678  }
4679  }
4680  $tmpout .= $tmpstyleinheader."\n";
4681  // Clean style that may affect global style of Dolibarr
4682  $tmpout = preg_replace('/}[\s\n]*body\s*{[^}]+}/ims', '}', $tmpout);
4683  $out .= $tmpout;
4684  $out .= '</style>'."\n";
4685 
4686  // Note: <div> or <section> with contenteditable="true" inside this can be edited with inline ckeditor
4687 
4688  // Do not enable the contenteditable when page was grabbed, ckeditor is removing span and adding borders,
4689  // so editable will be available only from container created from scratch
4690  //$out.='<div id="bodywebsite" class="bodywebsite"'.($objectpage->grabbed_from ? ' contenteditable="true"' : '').'>'."\n";
4691  $out .= '<div id="divbodywebsite" class="bodywebsite bodywebpage-'.$objectpage->ref.'">'."\n";
4692 
4693  $newcontent = $objectpage->content;
4694 
4695  // If mode WEBSITE_SUBCONTAINERSINLINE is on
4696  if (!empty($conf->global->WEBSITE_SUBCONTAINERSINLINE)) {
4697  // TODO Check file $filephp exists, if not create it.
4698 
4699  //var_dump($filetpl);
4700  $filephp = $filetpl;
4701  ob_start();
4702  try {
4703  $res = include $filephp;
4704  if (empty($res)) {
4705  print "ERROR: Failed to include file '".$filephp."'. Try to edit and re-save page ith this ID.";
4706  }
4707  } catch (Exception $e) {
4708  print $e->getMessage();
4709  }
4710  $newcontent = ob_get_contents();
4711  ob_end_clean();
4712  }
4713 
4714  // Change the contenteditable to "true" or "false" when mode Edit Inline is on or off
4715  if (empty($conf->global->WEBSITE_EDITINLINE)) {
4716  // Remove the contenteditable="true"
4717  $newcontent = preg_replace('/(div|section)(\s[^>]*)contenteditable="true"/', '\1\2', $newcontent);
4718  } else {
4719  // Keep the contenteditable="true" when mode Edit Inline is on
4720  }
4721  $out .= dolWebsiteReplacementOfLinks($object, $newcontent, 0, 'html', $objectpage->id)."\n";
4722  //$out.=$newcontent;
4723 
4724  $out .= '</div>';
4725 
4726  $out .= '</div> <!-- End div id=websitecontentundertopmenu -->';
4727 
4728  /*if ($includepageintoaframeoradiv == 'iframe')
4729  {
4730  $out .= "</body></html></iframe>";
4731  }*/
4732  $out .= "\n</body></html>\n";
4733 
4734  $out .= "\n".'<!-- End page content '.$filetpl.' -->'."\n\n";
4735 
4736  print $out;
4737 
4738  /*file_put_contents($filetpl, $out);
4739  if (! empty($conf->global->MAIN_UMASK))
4740  @chmod($filetpl, octdec($conf->global->MAIN_UMASK));
4741 
4742  // Output file on browser
4743  dol_syslog("index.php include $filetpl $filename content-type=$type");
4744  $original_file_osencoded=dol_osencode($filetpl); // New file name encoded in OS encoding charset
4745 
4746  // This test if file exists should be useless. We keep it to find bug more easily
4747  if (! file_exists($original_file_osencoded))
4748  {
4749  dol_print_error(0,$langs->trans("ErrorFileDoesNotExists",$original_file));
4750  exit;
4751  }
4752 
4753  //include_once $original_file_osencoded;
4754  */
4755 
4756  /*print '<iframe class="websiteiframenoborder centpercent" src="'.DOL_URL_ROOT.'/public/website/index.php?website='.$websitekey.'&pageid='.$pageid.'"/>';
4757  print '</iframe>';*/
4758  } else {
4759  if (empty($websitekey) || $websitekey == '-1') {
4760  print '<br><br><div class="center previewnotyetavailable"><span class="">'.$langs->trans("NoWebSiteCreateOneFirst").'</span></div><br><br><br>';
4761  print '<div class="center"><div class="logo_setup"></div></div>';
4762  } else {
4763  print '<br><br><div class="center previewnotyetavailable"><span class="">'.$langs->trans("PreviewOfSiteNotYetAvailable", $object->ref).'</span></div><br><br><br>';
4764  print '<div class="center"><div class="logo_setup"></div></div>';
4765  }
4766  }
4767 }
4768 
4769 // End of page
4770 llxFooter();
4771 $db->close();
make_substitutions
make_substitutions($text, $substitutionarray, $outputlangs=null, $converttextinhtmlifnecessary=0)
Make substitution into a text string, replacing keys with vals from $substitutionarray (oldval=>newva...
Definition: functions.lib.php:7839
ajax_combobox
ajax_combobox($htmlname, $events=array(), $minLengthToAutocomplete=0, $forcefocus=0, $widthTypeOfAutocomplete='resolve', $idforemptyvalue='-1')
Convert a html select field into an ajax combobox.
Definition: ajax.lib.php:438
dol_escape_htmltag
dol_escape_htmltag($stringtoescape, $keepb=0, $keepn=0, $noescapetags='', $escapeonlyhtmltags=0)
Returns text escaped for inclusion in HTML alt or title tags, or into values of HTML input fields.
Definition: functions.lib.php:1468
dolStripPhpCode
dolStripPhpCode($str, $replacewith='')
Remove PHP code part from a string.
Definition: website.lib.php:32
dolSavePageContent
dolSavePageContent($filetpl, Website $object, WebsitePage $objectpage, $backupold=0)
Save content of a page on disk (page name is generally ID_of_page.php).
Definition: website2.lib.php:147
WebsitePage
Class Websitepage.
Definition: websitepage.class.php:36
dol_sanitizeFileName
dol_sanitizeFileName($str, $newstr='_', $unaccent=1)
Clean a string to use it as a file name.
Definition: functions.lib.php:1226
dolButtonToOpenUrlInDialogPopup
dolButtonToOpenUrlInDialogPopup($name, $label, $buttonstring, $url, $disabled='', $morecss='button bordertransp', $backtopagejsfields='')
Return HTML code to output a button to open a dialog popup box.
Definition: functions.lib.php:1720
dolSaveManifestJson
dolSaveManifestJson($file, $content)
Save content of a page on disk.
Definition: website2.lib.php:499
dolibarr_del_const
dolibarr_del_const($db, $name, $entity=1)
Delete a constant.
Definition: admin.lib.php:552
dol_delete_dir_recursive
dol_delete_dir_recursive($dir, $count=0, $nophperrors=0, $onlysub=0, &$countdeleted=0, $indexdatabase=1, $nolog=0)
Remove a directory $dir and its subdirectories (or only files and subdirectories)
Definition: files.lib.php:1383
dol_osencode
dol_osencode($str)
Return a string encoded into OS filesystem encoding.
Definition: functions.lib.php:8499
getTitleFieldOfList
getTitleFieldOfList($name, $thead=0, $file="", $field="", $begin="", $moreparam="", $moreattrib="", $sortfield="", $sortorder="", $prefix="", $disablesortlink=0, $tooltip='', $forcenowrapcolumntitle=0)
Get title line of an array.
Definition: functions.lib.php:5049
load_fiche_titre
load_fiche_titre($titre, $morehtmlright='', $picto='generic', $pictoisfullpath=0, $id='', $morecssontable='', $morehtmlcenter='')
Load a title with picto.
Definition: functions.lib.php:5204
GETPOST
GETPOST($paramname, $check='alphanohtml', $method=0, $filter=null, $options=null, $noreplace=0)
Return value of a param into GET or POST supervariable.
Definition: functions.lib.php:484
dol_print_error
dol_print_error($db='', $error='', $errors=null)
Displays error message system with all the information to facilitate the diagnosis and the escalation...
Definition: functions.lib.php:4844
img_help
img_help($usehelpcursor=1, $usealttitle=1)
Show help logo with cursor "?".
Definition: functions.lib.php:4481
dol_add_file_process
dol_add_file_process($upload_dir, $allowoverwrite=0, $donotupdatesession=0, $varfiles='addedfile', $savingdocmask='', $link=null, $trackid='', $generatethumbs=1, $object=null)
Get and save an upload file (for example after submitting a new file a mail form).
Definition: files.lib.php:1634
Lessc
lessphp v0.5.0 http://leafo.net/lessphp
Definition: lessc.class.php:38
FormWebsite
Class to manage component html for module website.
Definition: html.formwebsite.class.php:28
picto_from_langcode
picto_from_langcode($codelang, $moreatt='', $notitlealt=0)
Return img flag of country for a language code or country code.
Definition: functions.lib.php:8742
dolKeepOnlyPhpCode
dolKeepOnlyPhpCode($str)
Keep only PHP code part from a HTML string page.
Definition: website.lib.php:76
$form
if($cancel &&! $id) if($action=='add' &&! $cancel) if($action=='delete') if($id) $form
Actions.
Definition: card.php:142
ajax_object_onoff
ajax_object_onoff($object, $code, $field, $text_on, $text_off, $input=array(), $morecss='')
On/off button to change status of an object This is called when MAIN_DIRECT_STATUS_UPDATE is set and ...
Definition: ajax.lib.php:652
getRootURLFromURL
getRootURLFromURL($url)
Function root url from a long url For example: https://www.abc.mydomain.com/dir/page....
Definition: geturl.lib.php:349
name
$conf db name
Definition: repair.php:122
FormOther
Classe permettant la generation de composants html autre Only common components are here.
Definition: html.formother.class.php:39
Categorie
Class to manage categories.
Definition: categorie.class.php:47
FormAdmin
Class to generate html code for admin pages.
Definition: html.formadmin.class.php:30
dolSaveMasterFile
dolSaveMasterFile($filemaster)
Save content of a page on disk.
Definition: website2.lib.php:32
dol_is_file
dol_is_file($pathoffile)
Return if path is a file.
Definition: files.lib.php:477
getURLContent
getURLContent($url, $postorget='GET', $param='', $followlocation=1, $addheaders=array(), $allowedschemes=array('http', 'https'), $localurl=0, $ssl_verifypeer=-1)
Function to get a content from an URL (use proxy if proxy defined).
Definition: geturl.lib.php:41
dolSaveRobotFile
dolSaveRobotFile($filerobot, $robotcontent)
Save content of a page on disk.
Definition: website2.lib.php:455
dolSaveIndexPage
dolSaveIndexPage($pathofwebsite, $fileindex, $filetpl, $filewrapper, $object=null)
Save content of the index.php and/or the wrapper.php page.
Definition: website2.lib.php:297
dol_print_date
dol_print_date($time, $format='', $tzoutput='auto', $outputlangs='', $encodetooutput=false)
Output date in a string format according to outputlangs (or langs if not defined).
Definition: functions.lib.php:2514
img_picto
img_picto($titlealt, $picto, $moreatt='', $pictoisfullpath=false, $srconly=0, $notitle=0, $alt='', $morecss='', $marginleftonlyshort=2)
Show picto whatever it's its name (generic function)
Definition: functions.lib.php:3880
dolSaveHtaccessFile
dolSaveHtaccessFile($filehtaccess, $htaccess)
Save content of a page on disk.
Definition: website2.lib.php:477
llxFooter
llxFooter()
Footer empty.
Definition: index.php:71
dol_delete_file
dol_delete_file($file, $disableglob=0, $nophperrors=0, $nohook=0, $object=null, $allowdotdot=false, $indexdatabase=1, $nolog=0)
Remove a file or several files with a mask.
Definition: files.lib.php:1231
getMaxFileSizeArray
getMaxFileSizeArray()
Return the max allowed for file upload.
Definition: security.lib.php:993
Exception
img_next
img_next($titlealt='default', $moreatt='')
Show next logo.
Definition: functions.lib.php:4557
$formconfirm
$formconfirm
if ($action == 'delbookkeepingyear') {
Definition: listbyaccount.php:576
dolWebsiteReplacementOfLinks
dolWebsiteReplacementOfLinks($website, $content, $removephppart=0, $contenttype='html', $containerid='')
Convert a page content to have correct links (based on DOL_URL_ROOT) into an html content.
Definition: website.lib.php:118
dolSaveCssFile
dolSaveCssFile($filecss, $csscontent)
Save content of a page on disk.
Definition: website2.lib.php:411
dolSaveHtmlHeader
dolSaveHtmlHeader($filehtmlheader, $htmlheadercontent)
Save content of a page on disk.
Definition: website2.lib.php:389
getAllImages
getAllImages($object, $objectpage, $urltograb, &$tmp, &$action, $modifylinks=0, $grabimages=1, $grabimagesinto='subpage')
Download all images found into page content $tmp.
Definition: website.lib.php:1061
dol_string_nohtmltag
dol_string_nohtmltag($stringtoclean, $removelinefeed=1, $pagecodeto='UTF-8', $strip_tags=0, $removedoublespaces=1)
Clean a string from all HTML tags and entities.
Definition: functions.lib.php:6694
dol_syslog
dol_syslog($message, $level=LOG_INFO, $ident=0, $suffixinfilename='', $restricttologhandler='', $logcontext=null)
Write log message into outputs.
Definition: functions.lib.php:1603
getDomainFromURL
getDomainFromURL($url, $mode=0)
Function get second level domain name.
Definition: geturl.lib.php:325
print_barre_liste
print_barre_liste($titre, $page, $file, $options='', $sortfield='', $sortorder='', $morehtmlcenter='', $num=-1, $totalnboflines='', $picto='generic', $pictoisfullpath=0, $morehtmlright='', $morecss='', $limit=-1, $hideselectlimit=0, $hidenavigation=0, $pagenavastextinput=0, $morehtmlrightbeforearrow='')
Print a title with navigation controls for pagination.
Definition: functions.lib.php:5257
getPagesFromSearchCriterias
getPagesFromSearchCriterias($type, $algo, $searchstring, $max=25, $sortfield='date_creation', $sortorder='DESC', $langcode='', $otherfilters='null', $status=1)
Return list of containers object that match a criteria.
Definition: website.lib.php:896
dol_get_fiche_head
dol_get_fiche_head($links=array(), $active='', $title='', $notab=0, $picto='', $pictoisfullpath=0, $morehtmlright='', $morecss='', $limittoshow=0, $moretabssuffix='')
Show tabs of a record.
Definition: functions.lib.php:1822
info_admin
info_admin($text, $infoonimgalt=0, $nodiv=0, $admin='1', $morecss='hideonsmartphone', $textfordropdown='')
Show information for admin users or standard users.
Definition: functions.lib.php:4800
newToken
newToken()
Return the value of token currently saved into session with name 'newtoken'.
Definition: functions.lib.php:10878
dol_get_fiche_end
dol_get_fiche_end($notab=0)
Return tab footer of a card.
Definition: functions.lib.php:2018
Website
Class Website.
Definition: website.class.php:36
dolibarr_set_const
dolibarr_set_const($db, $name, $value, $type='chaine', $visible=0, $note='', $entity=1)
Insert a parameter (key,value) into database (delete old key then insert it again).
Definition: admin.lib.php:627
User
Class to manage Dolibarr users.
Definition: user.class.php:44
GETPOSTISSET
GETPOSTISSET($paramname)
Return true if we are in a context of submitting the parameter $paramname from a POST of a form.
Definition: functions.lib.php:386
dolSavePageAlias
dolSavePageAlias($filealias, $object, $objectpage)
Save an alias page on disk (A page that include the reference page).
Definition: website2.lib.php:65
Form
Class to manage generation of HTML components Only common components must be here.
Definition: html.form.class.php:52
img_object
img_object($titlealt, $picto, $moreatt='', $pictoisfullpath=false, $srconly=0, $notitle=0)
Show a picto called object_picto (generic function)
Definition: functions.lib.php:4211
dol_htmlentitiesbr
dol_htmlentitiesbr($stringtoencode, $nl2brmode=0, $pagecodefrom='UTF-8', $removelasteolbr=1)
This function is called to encode a string into a HTML string but differs from htmlentities because a...
Definition: functions.lib.php:6991
dol_now
dol_now($mode='auto')
Return date for now.
Definition: functions.lib.php:2845
$resql
if(isModEnabled('facture') &&!empty($user->rights->facture->lire)) if((isModEnabled('fournisseur') &&empty($conf->global->MAIN_USE_NEW_SUPPLIERMOD) && $user->rights->fournisseur->facture->lire)||(isModEnabled('supplier_invoice') && $user->rights->supplier_invoice->lire)) if(isModEnabled('don') &&!empty($user->rights->don->lire)) if(isModEnabled('tax') &&!empty($user->rights->tax->charges->lire)) if(isModEnabled('facture') &&isModEnabled('commande') && $user->rights->commande->lire &&empty($conf->global->WORKFLOW_DISABLE_CREATE_INVOICE_FROM_ORDER)) $resql
Social contributions to pay.
Definition: index.php:742
showWebsiteTemplates
showWebsiteTemplates(Website $website)
Show list of themes.
Definition: website2.lib.php:543
checkPHPCode
checkPHPCode($phpfullcodestringold, $phpfullcodestring)
checkPHPCode
Definition: website2.lib.php:652
setEventMessages
setEventMessages($mesg, $mesgs, $style='mesgs', $messagekey='')
Set event messages in dol_events session object.
Definition: functions.lib.php:8137
removeHtmlComment
removeHtmlComment($content)
Function to remove comments into HTML content.
Definition: geturl.lib.php:369
accessforbidden
accessforbidden($message='', $printheader=1, $printfooter=1, $showonlymessage=0, $params=null)
Show a message to say access is forbidden and stop program Calling this function terminate execution ...
Definition: security.lib.php:933
dol_mkdir
dol_mkdir($dir, $dataroot='', $newmask='')
Creation of a directory (this can create recursive subdir)
Definition: functions.lib.php:6603
dol_mktime
dol_mktime($hour, $minute, $second, $month, $day, $year, $gm='auto', $check=1)
Return a timestamp date built from detailed informations (by default a local PHP server timestamp) Re...
Definition: functions.lib.php:2757
img_previous
img_previous($titlealt='default', $moreatt='')
Show previous logo.
Definition: functions.lib.php:4576
type
if(preg_match('/crypted:/i', $dolibarr_main_db_pass)||!empty($dolibarr_main_db_encrypted_pass)) $conf db type
Definition: repair.php:119
dolSaveReadme
dolSaveReadme($file, $content)
Save content of a page on disk.
Definition: website2.lib.php:521
DolEditor
Class to manage a WYSIWYG editor.
Definition: doleditor.class.php:30
dolSaveJsFile
dolSaveJsFile($filejs, $jscontent)
Save content of a page on disk.
Definition: website2.lib.php:433
if
if(!defined( 'CSRFCHECK_WITH_TOKEN'))
Definition: journals_list.php:25