* * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 3 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program. If not, see . */ /** * \file htdocs/website/index.php * \ingroup website * \brief Page to website view/edit */ define('NOSCANPOSTFORINJECTION',1); define('NOSTYLECHECK',1); /** * Show HTML header HTML + BODY + Top menu + left menu + DIV * * @param string $head Optionnal head lines * @param string $title HTML title * @param string $help_url Url links to help page * Syntax is: For a wiki page: EN:EnglishPage|FR:FrenchPage|ES:SpanishPage * For other external page: http://server/url * @param string $target Target to use on links * @param int $disablejs More content into html header * @param int $disablehead More content into html header * @param array $arrayofjs Array of complementary js files * @param array $arrayofcss Array of complementary css files * @param string $morequerystring Query string to add to the link "print" to get same parameters (use only if autodetect fails) * @return void */ function llxHeader($head='', $title='', $help_url='', $target='', $disablejs=0, $disablehead=0, $arrayofjs='', $arrayofcss='', $morequerystring='') { global $conf; // html header top_htmlhead($head, $title, $disablejs, $disablehead, $arrayofjs, $arrayofcss); // top menu and left menu area if (empty($conf->dol_hide_topmenu)) { top_menu($head, $title, $target, $disablejs, $disablehead, $arrayofjs, $arrayofcss, $morequerystring, $help_url); } if (empty($conf->dol_hide_leftmenu)) { left_menu('', $help_url, '', '', 1, $title, 1); } // main area //main_area($title); } require '../main.inc.php'; require_once DOL_DOCUMENT_ROOT.'/core/lib/admin.lib.php'; require_once DOL_DOCUMENT_ROOT.'/core/lib/files.lib.php'; require_once DOL_DOCUMENT_ROOT.'/websites/class/website.class.php'; require_once DOL_DOCUMENT_ROOT.'/websites/class/websitepage.class.php'; $langs->load("admin"); $langs->load("other"); $langs->load("website"); if (! $user->admin) accessforbidden(); $conf->dol_hide_leftmenu = 1; $error=0; $website=GETPOST('website', 'alpha'); $page=GETPOST('page', 'alpha'); $pageid=GETPOST('pageid', 'int'); $action=GETPOST('action','alpha'); if (GETPOST('delete')) { $action='delete'; } if (GETPOST('preview')) $action='preview'; if (GETPOST('create')) { $action='create'; } if (GETPOST('editmedia')) { $action='editmedia'; } if (GETPOST('editcss')) { $action='editcss'; } if (GETPOST('editmenu')) { $action='editmenu'; } if (GETPOST('setashome')) { $action='setashome'; } if (GETPOST('editmeta')) { $action='editmeta'; } if (GETPOST('editcontent')) { $action='editcontent'; } if (empty($action)) $action='preview'; $object=new Website($db); $objectpage=new WebsitePage($db); $object->fetchAll(); // Init $object->records // If website not defined, we take first found if (empty($website)) { foreach($object->records as $key => $valwebsite) { $website=$valwebsite->ref; break; } } if ($website) { $res = $object->fetch(0, $website); } if ($pageid < 0) $pageid = 0; if ($pageid > 0 && $action != 'add') { $res = $objectpage->fetch($pageid); } global $dolibarr_main_data_root; $pathofwebsite=$dolibarr_main_data_root.'/websites/'.$website; $filecss=$pathofwebsite.'/styles.css'; $filetpl=$pathofwebsite.'/page'.$pageid.'.tpl.php'; // Define $urlwithroot $urlwithouturlroot=preg_replace('/'.preg_quote(DOL_URL_ROOT,'/').'$/i','',trim($dolibarr_main_url_root)); $urlwithroot=$urlwithouturlroot.DOL_URL_ROOT; // This is to use external domain name found into config file //$urlwithroot=DOL_MAIN_URL_ROOT; // This is to use same domain name than current /* * Actions */ if (GETPOST('refreshsite')) $pageid=0; // If we change the site, we reset the pageid. // Add page if ($action == 'add') { $db->begin(); $objectpage->fk_website = $object->id; $objectpage->title = GETPOST('WEBSITE_TITLE'); $objectpage->pageurl = GETPOST('WEBSITE_PAGENAME'); $objectpage->description = GETPOST('WEBSITE_DESCRIPTION'); $objectpage->keywords = GETPOST('WEBSITE_KEYWORD'); if (empty($objectpage->title)) { setEventMessages($langs->trans("ErrorFieldRequired", $langs->transnoentitiesnoconv("WEBSITE_PAGENAME")), null, 'errors'); $error++; } if (! $error) { $res = $objectpage->create($user); if ($res <= 0) { $error++; setEventMessages($objectpage->error, $objectpage->errors, 'errors'); } } if (! $error) { $db->commit(); setEventMessages($langs->trans("PageAdded", $objectpage->pageurl), null, 'mesgs'); $action=''; } else { $db->rollback(); } } // Update page if ($action == 'update') { $db->begin(); $res = $object->fetch(0, $website); $objectpage->fk_website = $object->id; $objectpage->pageurl = GETPOST('WEBSITE_PAGENAME'); $res = $objectpage->fetch(0, $object->fk_website, $objectpage->pageurl); if ($res > 0) { $objectpage->title = GETPOST('WEBSITE_TITLE'); $objectpage->description = GETPOST('WEBSITE_DESCRIPTION'); $objectpage->keyword = GETPOST('WEBSITE_KEYWORD'); $res = $objectpage->update($user); if (! $res > 0) { $error++; setEventMessages($objectpage->error, $objectpage->errors, 'errors'); } if (! $error) { $db->commit(); setEventMessages($langs->trans("SetupSaved"), null, 'mesgs'); $action=''; } else { $db->rollback(); } } else { dol_print_error($db); } } // Update page if ($action == 'delete') { $db->begin(); $res = $object->fetch(0, $website); $res = $objectpage->fetch($pageid, $object->fk_website); if ($res > 0) { $res = $objectpage->delete($user); if (! $res > 0) { $error++; setEventMessages($objectpage->error, $objectpage->errors, 'errors'); } if (! $error) { $db->commit(); setEventMessages($langs->trans("PageDeleted", $objectpage->pageurl, $website), null, 'mesgs'); header("Location: ".$_SERVER["PHP_SELF"].'?website='.$website); exit; } else { $db->rollback(); } } else { dol_print_error($db); } } // Update css if ($action == 'updatecss') { $db->begin(); $res = $object->fetch(0, $website); /* $res = $object->update($user); if ($res > 0) { $db->commit(); setEventMessages($langs->trans("SetupSaved"), null, 'mesgs'); $action=''; } else { $db->rollback(); }*/ $csscontent = GETPOST('WEBSITE_CSS_INLINE'); dol_mkdir($pathofwebsite); file_put_contents($filecss, $csscontent); if (! empty($conf->global->MAIN_UMASK)) @chmod($filecss, octdec($conf->global->MAIN_UMASK)); $action='preview'; } // Update page if ($action == 'setashome') { $db->begin(); $object->fetch(0, $website); $object->fk_default_home = $pageid; $res = $object->update($user); if (! $res > 0) { $error++; setEventMessages($objectpage->error, $objectpage->errors, 'errors'); } if (! $error) { $db->commit(); setEventMessages($langs->trans("Saved"), null, 'mesgs'); $action='preview'; } else { $db->rollback(); } } // Update page if ($action == 'updatemeta') { $db->begin(); $object->fetch(0, $website); $objectpage->fk_website = $object->id; $res = $objectpage->fetch($pageid, $object->fk_website); if ($res > 0) { $objectpage->pageurl = GETPOST('WEBSITE_PAGENAME'); $objectpage->title = GETPOST('WEBSITE_TITLE'); $objectpage->description = GETPOST('WEBSITE_DESCRIPTION'); $objectpage->keywords = GETPOST('WEBSITE_KEYWORDS'); $res = $objectpage->update($user); if (! $res > 0) { $error++; setEventMessages($objectpage->error, $objectpage->errors, 'errors'); } if (! $error) { $db->commit(); setEventMessages($langs->trans("Saved"), null, 'mesgs'); $action='preview'; } else { $db->rollback(); } } else { dol_print_error($db, 'Page not found'); } } // Update page if ($action == 'updatecontent') { $db->begin(); $object->fetch(0, $website); $objectpage->fk_website = $object->id; $res = $objectpage->fetch($pageid, $object->fk_website); if ($res > 0) { $objectpage->content = GETPOST('PAGE_CONTENT'); // Clean data. We remove all the head section. $objectpage->content = preg_replace('//s', '', $objectpage->content); /* $objectpage->content = preg_replace('//s', '', $objectpage->content); */ $res = $objectpage->update($user); if (! $res > 0) { $error++; setEventMessages($objectpage->error, $objectpage->errors, 'errors'); } if (! $error) { $db->commit(); setEventMessages($langs->trans("Saved"), null, 'mesgs'); dol_mkdir($pathofwebsite); dol_delete_file($filetpl); file_put_contents($filetpl, $objectpage->content); if (! empty($conf->global->MAIN_UMASK)) @chmod($filetpl, octdec($conf->global->MAIN_UMASK)); header("Location: ".$_SERVER["PHP_SELF"].'?website='.$website.'&pageid='.$pageid); exit; } else { $db->rollback(); } } else { dol_print_error($db, 'Page not found'); } } /* * View */ $form = new Form($db); $help_url=''; llxHeader('', $langs->trans("WebsiteSetup"), $help_url); print "\n".'
'; print ''; if ($action == 'create') { print ''; } if ($action == 'editcss') { print ''; } if ($action == 'editmenu') { print ''; } if ($action == 'setashome') { print ''; } if ($action == 'editmeta') { print ''; } if ($action == 'editcontent') { print ''; } if ($action == 'edit') { print ''; } // Add a margin under toolbar ? $style=''; if ($action != 'preview' && $action != 'editcontent') $style=' margin-bottom: 5px;'; print '
'; if (count($object->records) > 0) { print '
'; print $langs->trans("Website").': '; print '
'; // List of websites print '
'; $out=''; $out.=''; print $out; print ''; if ($website) { print ' - '.$langs->trans("RealURL").' '; $realurl=$urlwithroot.'/public/websites/index.php?website='.$website; print ' '; print ''.$langs->trans("ViewSiteInNewTab").''; } print '
'; // Button for websites print '
'; if ($action == 'preview') { $disabled=''; if (empty($user->rights->websites->create)) $disabled=' disabled="disabled"'; //print ''; print ''; print ''; print ''; } if (in_array($action, array('editcss','editmenu','create'))) { if ($action != 'preview') print ''; if (preg_match('/^create/',$action)) print ''; if (preg_match('/^edit/',$action)) print ''; } print '
'; // Part for pages if ($website) { print '
'; $array=$objectpage->fetchAll($object->id); if (! is_array($array) && $array < 0) dol_print_error('', $objectpage->error, $objectpage->errors); $atleastonepage=(is_array($array) && count($array) > 0); print '
'; print '
'; print $langs->trans("Page").': '; print '
'; print '
'; $out=''; $out.=''; print $out; print ''; print ''; //print $form->selectarray('page', $array); if ($website && $pageid > 0) { print ' - '.$langs->trans("RealURL").' '; $realurl=$urlwithroot.'/public/websites/index.php?website='.$website.'&page='.$pageid; print ' '; print ''.$langs->trans("ViewPageInNewTab").''; } print '
'; print '
'; print '
'; print '
'; if ($action == 'preview') { $disabled=''; if (empty($user->rights->websites->create)) $disabled=' disabled="disabled"'; if ($pageid > 0) { if ($object->fk_default_home > 0 && $pageid == $object->fk_default_home) print ''; else print ''; print ''; print ''; //print ''.dol_escape_htmltag($langs->trans("EditPageMeta")).''; //print ''.dol_escape_htmltag($langs->trans("EditPageContent")).''; } } if (! in_array($action, array('editcss','editmenu','create'))) { if ($action != 'preview') print ''; if (preg_match('/^create/',$action)) print ''; if (preg_match('/^edit/',$action)) print ''; } print '
'; } } else { print '
'; $langs->load("errors"); print $langs->trans("ErrorModuleSetupNotComplete"); print '
'; $action=''; } print '
'; $head = array(); /* * Edit mode */ if ($action == 'editcss') { print '
'; print '
'; $csscontent = @file_get_contents($filecss); dol_fiche_head(); print ''; print ''; print ''; /*print '';*/ print '
'; print $langs->trans('WebSite'); print ''; print $website; print '
'; print $langs->trans('WEBSITE_CSS_INLINE'); print ''; print ''; print '
'; print $langs->trans('WEBSITE_CSS_URL'); print ''; print ''; print '
'; dol_fiche_end(); print '
'; print '
'; } if ($action == 'editmeta' || $action == 'create') { print '
'; print '
'; dol_fiche_head(); print ''; if ($action != 'create') { print ''; $pageurl=dol_escape_htmltag($objectpage->pageurl); $pagetitle=dol_escape_htmltag($objectpage->title); $pagedescription=dol_escape_htmltag($objectpage->description); $pagekeywords=dol_escape_htmltag($objectpage->keywords); } if (GETPOST('WEBSITE_PAGENAME')) $pageurl=GETPOST('WEBSITE_PAGENAME'); if (GETPOST('WEBSITE_TITLE')) $pagetitle=GETPOST('WEBSITE_TITLE'); if (GETPOST('WEBSITE_DESCRIPTION')) $pagedescription=GETPOST('WEBSITE_DESCRIPTION'); if (GETPOST('WEBSITE_KEYWORDS')) $pagekeywords=GETPOST('WEBSITE_KEYWORDS'); print ''; print ''; print ''; print ''; print '
'; print $langs->trans('WEBSITE_PAGEURL'); print ''; print '/public/websites/index.php?website='.urlencode($website).'&pageid='.urlencode($pageid); print '
'; print $langs->trans('WEBSITE_PAGENAME'); print ''; print ''; print '
'; print $langs->trans('WEBSITE_TITLE'); print ''; print ''; print '
'; print $langs->trans('WEBSITE_DESCRIPTION'); print ''; print ''; print '
'; print $langs->trans('WEBSITE_KEYWORDS'); print ''; print ''; print '
'; dol_fiche_end(); print '
'; print '
'; } if ($action == 'editmedia') { print '
'.$langs->trans("FeatureNotYetAvailable").''; } if ($action == 'editmenu') { print '
'.$langs->trans("FeatureNotYetAvailable").''; } if ($action == 'editcontent') { /* * Editing global variables not related to a specific theme */ require_once DOL_DOCUMENT_ROOT.'/core/class/doleditor.class.php'; $doleditor=new DolEditor('PAGE_CONTENT',$objectpage->content,'',500,'Full','',true,true,true,5,60); $doleditor->Create(); } print ''; if ($action == 'preview') { if ($pageid > 0) { $objectpage->fetch($pageid); print "\n".''."\n"; $csscontent = @file_get_contents($filecss); $out=''; $out.='
'."\n"; $out.=''."\n"; $out.=$objectpage->content."\n"; $out.='
'; print $out; /*file_put_contents($filetpl, $out); if (! empty($conf->global->MAIN_UMASK)) @chmod($filetpl, octdec($conf->global->MAIN_UMASK)); // Output file on browser dol_syslog("index.php include $filetpl $filename content-type=$type"); $original_file_osencoded=dol_osencode($filetpl); // New file name encoded in OS encoding charset // This test if file exists should be useless. We keep it to find bug more easily if (! file_exists($original_file_osencoded)) { dol_print_error(0,$langs->trans("ErrorFileDoesNotExists",$original_file)); exit; } //include_once $original_file_osencoded; */ /*print '';*/ } else { print '

'.$langs->trans("PreviewOfSiteNotYetAvailable", $website).'


'; print '
'; } } llxFooter(); $db->close();