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.= '