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