Fix edit of page in module website

Conflicts:
	htdocs/websites/class/website.class.php
This commit is contained in:
Laurent Destailleur 2016-08-08 18:25:37 +02:00
parent fb3f6972eb
commit 54b47d7f4f
3 changed files with 102 additions and 11 deletions

View File

@ -25,6 +25,7 @@ CREATE TABLE llx_website
description varchar(255), description varchar(255),
status integer, status integer,
fk_default_home integer, fk_default_home integer,
virtualhost varchar(255),
date_creation datetime, date_creation datetime,
date_modification datetime, date_modification datetime,
tms timestamp tms timestamp

View File

@ -380,6 +380,7 @@ class Website extends CommonObject
$sql .= ' description = '.(isset($this->description)?"'".$this->db->escape($this->description)."'":"null").','; $sql .= ' description = '.(isset($this->description)?"'".$this->db->escape($this->description)."'":"null").',';
$sql .= ' status = '.(isset($this->status)?$this->status:"null").','; $sql .= ' status = '.(isset($this->status)?$this->status:"null").',';
$sql .= ' fk_default_home = '.(($this->fk_default_home > 0)?$this->fk_default_home:"null").','; $sql .= ' fk_default_home = '.(($this->fk_default_home > 0)?$this->fk_default_home:"null").',';
$sql .= ' virtualhost = '.(($this->virtualhost != '')?"'".$this->db->escape($this->virtualhost)."'":"null").',';
$sql .= ' date_creation = '.(! isset($this->date_creation) || dol_strlen($this->date_creation) != 0 ? "'".$this->db->idate($this->date_creation)."'" : 'null').','; $sql .= ' date_creation = '.(! isset($this->date_creation) || dol_strlen($this->date_creation) != 0 ? "'".$this->db->idate($this->date_creation)."'" : 'null').',';
$sql .= ' date_modification = '.(! isset($this->date_modification) || dol_strlen($this->date_modification) != 0 ? "'".$this->db->idate($this->date_modification)."'" : 'null').','; $sql .= ' date_modification = '.(! isset($this->date_modification) || dol_strlen($this->date_modification) != 0 ? "'".$this->db->idate($this->date_modification)."'" : 'null').',';
$sql .= ' tms = '.(dol_strlen($this->tms) != 0 ? "'".$this->db->idate($this->tms)."'" : "'".$this->db->idate(dol_now())."'"); $sql .= ' tms = '.(dol_strlen($this->tms) != 0 ? "'".$this->db->idate($this->tms)."'" : "'".$this->db->idate(dol_now())."'");

View File

@ -125,6 +125,7 @@ global $dolibarr_main_data_root;
$pathofwebsite=$dolibarr_main_data_root.'/websites/'.$website; $pathofwebsite=$dolibarr_main_data_root.'/websites/'.$website;
$filecss=$pathofwebsite.'/styles.css.php'; $filecss=$pathofwebsite.'/styles.css.php';
$filetpl=$pathofwebsite.'/page'.$pageid.'.tpl.php'; $filetpl=$pathofwebsite.'/page'.$pageid.'.tpl.php';
$fileindex=$pathofwebsite.'/index.php';
// Define $urlwithroot // Define $urlwithroot
$urlwithouturlroot=preg_replace('/'.preg_quote(DOL_URL_ROOT,'/').'$/i','',trim($dolibarr_main_url_root)); $urlwithouturlroot=preg_replace('/'.preg_quote(DOL_URL_ROOT,'/').'$/i','',trim($dolibarr_main_url_root));
@ -279,13 +280,16 @@ if ($action == 'updatecss')
$csscontent ='<?php'."\n"; $csscontent ='<?php'."\n";
$csscontent.= "header('Content-type: text/css');\n"; $csscontent.= "header('Content-type: text/css');\n";
$csscontent.= "?>"."\n"; $csscontent.= "?>"."\n";
$csscontent .= GETPOST('WEBSITE_CSS_INLINE'); $csscontent.= GETPOST('WEBSITE_CSS_INLINE');
dol_mkdir($pathofwebsite); dol_mkdir($pathofwebsite);
file_put_contents($filecss, $csscontent); $result = file_put_contents($filecss, $csscontent);
if (! empty($conf->global->MAIN_UMASK)) if (! empty($conf->global->MAIN_UMASK))
@chmod($filecss, octdec($conf->global->MAIN_UMASK)); @chmod($filecss, octdec($conf->global->MAIN_UMASK));
if ($result) setEventMessages($langs->trans("Saved"), null, 'mesgs');
else setEventMessages('Failed to write file '.$fileindex, null, 'errors');
$action='preview'; $action='preview';
} }
@ -306,7 +310,23 @@ if ($action == 'setashome')
if (! $error) if (! $error)
{ {
$db->commit(); $db->commit();
setEventMessages($langs->trans("Saved"), null, 'mesgs');
// Generate the index.php page to be the home page
//-------------------------------------------------
dol_mkdir($pathofwebsite);
dol_delete_file($fileindex);
$indexcontent = '<?php'."\n";
$indexcontent.= '// File generated to wrap the home page'."\n";
$indexcontent.= "include_once './".basename($filetpl)."'\n";
$indexcontent.= '?>'."\n";
$result = file_put_contents($fileindex, $indexcontent);
if (! empty($conf->global->MAIN_UMASK))
@chmod($fileindex, octdec($conf->global->MAIN_UMASK));
if ($result) setEventMessages($langs->trans("Saved"), null, 'mesgs');
else setEventMessages('Failed to write file '.$fileindex, null, 'errors');
$action='preview'; $action='preview';
} }
else else
@ -326,6 +346,8 @@ if ($action == 'updatemeta')
$res = $objectpage->fetch($pageid, $object->fk_website); $res = $objectpage->fetch($pageid, $object->fk_website);
if ($res > 0) if ($res > 0)
{ {
$oldobjectpage = clone $objectpage;
$objectpage->pageurl = GETPOST('WEBSITE_PAGENAME'); $objectpage->pageurl = GETPOST('WEBSITE_PAGENAME');
$objectpage->title = GETPOST('WEBSITE_TITLE'); $objectpage->title = GETPOST('WEBSITE_TITLE');
$objectpage->description = GETPOST('WEBSITE_DESCRIPTION'); $objectpage->description = GETPOST('WEBSITE_DESCRIPTION');
@ -341,7 +363,61 @@ if ($action == 'updatemeta')
if (! $error) if (! $error)
{ {
$db->commit(); $db->commit();
setEventMessages($langs->trans("Saved"), null, 'mesgs');
$fileoldalias=$pathofwebsite.'/'.$oldobjectpage->pageurl.'.php';
$filealias=$pathofwebsite.'/'.$objectpage->pageurl.'.php';
// Generate the alias.php page
//-----------------------------
dol_mkdir($pathofwebsite);
dol_delete_file($fileoldalias);
$aliascontent = '<?php'."\n";
$aliascontent.= '// File generated to wrap the alias page'."\n";
$aliascontent.= "include_once './page".$objectpage->id.".tpl.php'\n";
$aliascontent.= '?>'."\n";
$result = file_put_contents($filealias, $aliascontent);
if (! empty($conf->global->MAIN_UMASK))
@chmod($filealias, octdec($conf->global->MAIN_UMASK));
if ($result) setEventMessages($langs->trans("Saved"), null, 'mesgs');
else setEventMessages('Failed to write file '.$filealias, null, 'errors');
// Now create the .tpl file (duplicate code with actions updatecontent but we need this to save new header)
dol_mkdir($pathofwebsite);
dol_delete_file($filetpl);
$tplcontent = '<html>'."\n";
$tplcontent.= '<header>'."\n";
$tplcontent.= '<meta http-equiv="content-type" content="text/html; charset=utf-8" />'."\n";
$tplcontent.= '<meta name="robots" content="index, follow" />'."\n";
$tplcontent.= '<meta name="viewport" content="width=device-width, initial-scale=0.8">'."\n";
$tplcontent.= '<meta name="keywords" content="'.join(', ', explode(',',$objectpage->keywords)).'" />'."\n";
$tplcontent.= '<meta name="title" content="'.dol_escape_htmltag($objectpage->title).'" />'."\n";
$tplcontent.= '<meta name="description" content="'.dol_escape_htmltag($objectpage->description).'" />'."\n";
$tplcontent.= '<meta name="generator" content="'.DOL_APPLICATION_TITLE.'" />'."\n";
$tplcontent.= '<link rel="stylesheet" href="styles.css.php?website='.$website.'" type="text/css" />'."\n";
$tplcontent.= '<title>'.dol_escape_htmltag($objectpage->title).'</title>'."\n";
$tplcontent.= '</header>'."\n";
$tplcontent.= '<body>'."\n";
$tplcontent.= $objectpage->content."\n";
$tplcontent.= '</body>'."\n";
//var_dump($filetpl);exit;
$result = file_put_contents($filetpl, $tplcontent);
if (! empty($conf->global->MAIN_UMASK))
@chmod($filetpl, octdec($conf->global->MAIN_UMASK));
if ($result)
{
//setEventMessages($langs->trans("Saved"), null, 'mesgs');
//header("Location: ".$_SERVER["PHP_SELF"].'?website='.$website.'&pageid='.$pageid);
//exit;
}
else setEventMessages('Failed to write file '.$filetpl, null, 'errors');
$action='preview'; $action='preview';
} }
else else
@ -384,25 +460,38 @@ if ($action == 'updatecontent')
$db->commit(); $db->commit();
// Now create the .tpl file // Now create the .tpl file
// TODO Keep a one time generate file or include a dynamicaly generated content ?
dol_mkdir($pathofwebsite); dol_mkdir($pathofwebsite);
dol_delete_file($filetpl); dol_delete_file($filetpl);
$tplcontent = '<html>'."\n"; $tplcontent = '<html>'."\n";
$tplcontent.= '<header>'."\n"; $tplcontent.= '<header>'."\n";
$tplcontent.= '<meta http-equiv="content-type" content="text/html; charset=utf-8" />'."\n";
$tplcontent.= '<meta name="robots" content="index, follow" />'."\n";
$tplcontent.= '<meta name="viewport" content="width=device-width, initial-scale=0.8">'."\n";
$tplcontent.= '<meta name="keywords" content="'.join(', ', explode(',',$objectpage->keywords)).'" />'."\n";
$tplcontent.= '<meta name="title" content="'.dol_escape_htmltag($objectpage->title).'" />'."\n";
$tplcontent.= '<meta name="description" content="'.dol_escape_htmltag($objectpage->description).'" />'."\n";
$tplcontent.= '<meta name="generator" content="'.DOL_APPLICATION_TITLE.'" />'."\n";
$tplcontent.= '<link rel="stylesheet" href="styles.css.php?website='.$website.'" type="text/css" />'."\n"; $tplcontent.= '<link rel="stylesheet" href="styles.css.php?website='.$website.'" type="text/css" />'."\n";
$tplcontent.= '<title>'.dol_escape_htmltag($objectpage->title).'</title>'."\n";
$tplcontent.= '</header>'."\n"; $tplcontent.= '</header>'."\n";
$tplcontent.= '<body>'."\n"; $tplcontent.= '<body>'."\n";
$tplcontent.= $objectpage->content."\n"; $tplcontent.= $objectpage->content."\n";
$tplcontent.= '</body>'."\n"; $tplcontent.= '</body>'."\n";
//var_dump($filetpl);exit; //var_dump($filetpl);exit;
$result = file_put_contents($filetpl, $tplcontent); $result = file_put_contents($filetpl, $tplcontent);
if (! empty($conf->global->MAIN_UMASK)) if (! empty($conf->global->MAIN_UMASK))
@chmod($filetpl, octdec($conf->global->MAIN_UMASK)); @chmod($filetpl, octdec($conf->global->MAIN_UMASK));
setEventMessages($langs->trans("Saved"), null, 'mesgs'); if ($result)
{
header("Location: ".$_SERVER["PHP_SELF"].'?website='.$website.'&pageid='.$pageid); setEventMessages($langs->trans("Saved"), null, 'mesgs');
exit; header("Location: ".$_SERVER["PHP_SELF"].'?website='.$website.'&pageid='.$pageid);
exit;
}
else setEventMessages('Failed to write file '.$filetpl, null, 'errors');
} }
else else
{ {