From 50a7046bd4820aadd875e5fbe9994fd0a8abfac1 Mon Sep 17 00:00:00 2001 From: Laurent Destailleur Date: Mon, 8 Aug 2016 18:25:37 +0200 Subject: [PATCH] Fix edit of page in module website --- htdocs/websites/class/website.class.php | 2 +- htdocs/websites/index.php | 111 +++++++++++++++++++++--- 2 files changed, 101 insertions(+), 12 deletions(-) diff --git a/htdocs/websites/class/website.class.php b/htdocs/websites/class/website.class.php index a3760a792ce..e75cacf9100 100644 --- a/htdocs/websites/class/website.class.php +++ b/htdocs/websites/class/website.class.php @@ -392,7 +392,7 @@ class Website extends CommonObject $sql .= ' description = '.(isset($this->description)?"'".$this->db->escape($this->description)."'":"null").','; $sql .= ' status = '.(isset($this->status)?$this->status:"null").','; $sql .= ' fk_default_home = '.(($this->fk_default_home > 0)?$this->fk_default_home:"null").','; - $sql .= ' virtualhost = '.(($this->virtualhost != '')?$this->virtualhost:"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_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())."'"); diff --git a/htdocs/websites/index.php b/htdocs/websites/index.php index b5eb5df1ef3..113e4531f04 100644 --- a/htdocs/websites/index.php +++ b/htdocs/websites/index.php @@ -125,6 +125,7 @@ global $dolibarr_main_data_root; $pathofwebsite=$dolibarr_main_data_root.'/websites/'.$website; $filecss=$pathofwebsite.'/styles.css.php'; $filetpl=$pathofwebsite.'/page'.$pageid.'.tpl.php'; +$fileindex=$pathofwebsite.'/index.php'; // Define $urlwithroot $urlwithouturlroot=preg_replace('/'.preg_quote(DOL_URL_ROOT,'/').'$/i','',trim($dolibarr_main_url_root)); @@ -279,13 +280,16 @@ if ($action == 'updatecss') $csscontent ='"."\n"; - $csscontent .= GETPOST('WEBSITE_CSS_INLINE'); + $csscontent.= GETPOST('WEBSITE_CSS_INLINE'); dol_mkdir($pathofwebsite); - file_put_contents($filecss, $csscontent); + $result = file_put_contents($filecss, $csscontent); if (! empty($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'; } @@ -306,7 +310,23 @@ if ($action == 'setashome') if (! $error) { $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 = ''."\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'; } else @@ -326,6 +346,8 @@ if ($action == 'updatemeta') $res = $objectpage->fetch($pageid, $object->fk_website); if ($res > 0) { + $oldobjectpage = clone $objectpage; + $objectpage->pageurl = GETPOST('WEBSITE_PAGENAME'); $objectpage->title = GETPOST('WEBSITE_TITLE'); $objectpage->description = GETPOST('WEBSITE_DESCRIPTION'); @@ -341,7 +363,61 @@ if ($action == 'updatemeta') if (! $error) { $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 = '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 = ''."\n"; + $tplcontent.= '
'."\n"; + $tplcontent.= ''."\n"; + $tplcontent.= ''."\n"; + $tplcontent.= ''."\n"; + $tplcontent.= ''."\n"; + $tplcontent.= ''."\n"; + $tplcontent.= ''."\n"; + $tplcontent.= ''."\n"; + $tplcontent.= ''."\n"; + $tplcontent.= ''.dol_escape_htmltag($objectpage->title).''."\n"; + $tplcontent.= '
'."\n"; + + $tplcontent.= ''."\n"; + $tplcontent.= $objectpage->content."\n"; + $tplcontent.= ''."\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'; } else @@ -384,25 +460,38 @@ if ($action == 'updatecontent') $db->commit(); // Now create the .tpl file + // TODO Keep a one time generate file or include a dynamicaly generated content ? dol_mkdir($pathofwebsite); dol_delete_file($filetpl); $tplcontent = ''."\n"; $tplcontent.= '
'."\n"; + $tplcontent.= ''."\n"; + $tplcontent.= ''."\n"; + $tplcontent.= ''."\n"; + $tplcontent.= ''."\n"; + $tplcontent.= ''."\n"; + $tplcontent.= ''."\n"; + $tplcontent.= ''."\n"; $tplcontent.= ''."\n"; + $tplcontent.= ''.dol_escape_htmltag($objectpage->title).''."\n"; $tplcontent.= '
'."\n"; + $tplcontent.= ''."\n"; $tplcontent.= $objectpage->content."\n"; $tplcontent.= ''."\n"; -//var_dump($filetpl);exit; + //var_dump($filetpl);exit; $result = file_put_contents($filetpl, $tplcontent); if (! empty($conf->global->MAIN_UMASK)) @chmod($filetpl, octdec($conf->global->MAIN_UMASK)); - - setEventMessages($langs->trans("Saved"), null, 'mesgs'); - - header("Location: ".$_SERVER["PHP_SELF"].'?website='.$website.'&pageid='.$pageid); - exit; + + 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'); } else {