diff --git a/htdocs/admin/websites.php b/htdocs/admin/websites.php index 4dbd154096f4e73b4c72f412990d0c0ecd21e972..0336a2533c0890db6f6900999b930be426bfe3d7 100644 --- a/htdocs/admin/websites.php +++ b/htdocs/admin/websites.php @@ -25,8 +25,10 @@ require '../main.inc.php'; require_once DOL_DOCUMENT_ROOT.'/core/class/html.formadmin.class.php'; require_once DOL_DOCUMENT_ROOT.'/core/class/html.formcompany.class.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.'/core/lib/functions2.lib.php'; require_once DOL_DOCUMENT_ROOT.'/core/class/doleditor.class.php'; +require_once DOL_DOCUMENT_ROOT.'/websites/class/website.class.php'; $langs->load("errors"); $langs->load("admin"); @@ -35,7 +37,6 @@ $langs->load("website"); $action=GETPOST('action','alpha')?GETPOST('action','alpha'):'view'; $confirm=GETPOST('confirm','alpha'); -$id=GETPOST('id','int'); $rowid=GETPOST('rowid','alpha'); $id=1; @@ -135,7 +136,7 @@ if (GETPOST('actionadd') || GETPOST('actionmodify')) setEventMessages($langs->transnoentities("ErrorFieldRequired", $langs->transnoentities($fieldnamekey)), null, 'errors'); } } - + // Si verif ok et action add, on ajoute la ligne if ($ok && GETPOST('actionadd')) { @@ -185,7 +186,7 @@ if (GETPOST('actionadd') || GETPOST('actionmodify')) if ($result) // Add is ok { setEventMessages($langs->transnoentities("RecordSaved"), null, 'mesgs'); - $_POST=array('id'=>$id); // Clean $_POST array, we keep only + unset($_POST); // Clean $_POST array, we keep only } else { @@ -204,6 +205,10 @@ if (GETPOST('actionadd') || GETPOST('actionmodify')) if ($tabrowid[$id]) { $rowidcol=$tabrowid[$id]; } else { $rowidcol="rowid"; } + $website=new Website($db); + $rowid=GETPOST('rowid','int'); + $website->fetch($rowid); + // Modify entry $sql = "UPDATE ".$tabname[$id]." SET "; // Modifie valeur des champs @@ -229,7 +234,17 @@ if (GETPOST('actionadd') || GETPOST('actionmodify')) dol_syslog("actionmodify", LOG_DEBUG); //print $sql; $resql = $db->query($sql); - if (! $resql) + if ($resql) + { + $newname = dol_sanitizeFileName(GETPOST('ref','aZ09')); + if ($newname != $website->ref) + { + $srcfile=DOL_DATA_ROOT.'/websites/'.$website->ref; + $destfile=DOL_DATA_ROOT.'/websites/'.$newname; + @rename($srcfile, $destfile); + } + } + else { setEventMessages($db->error(), null, 'errors'); } @@ -249,7 +264,7 @@ if ($action == 'confirm_delete' && $confirm == 'yes') // delete $sql = "DELETE from ".MAIN_DB_PREFIX."website_pages WHERE fk_website ='".$rowid."'"; $result = $db->query($sql); - + $sql = "DELETE from ".MAIN_DB_PREFIX."website WHERE rowid ='".$rowid."'"; $result = $db->query($sql); if (! $result) @@ -321,7 +336,7 @@ print "<br>\n"; // Confirmation de la suppression de la ligne if ($action == 'delete') { - print $form->formconfirm($_SERVER["PHP_SELF"].'?'.($page?'page='.$page.'&':'').'sortfield='.$sortfield.'&sortorder='.$sortorder.'&rowid='.$rowid.'&id='.$id, $langs->trans('DeleteWebsite'), $langs->trans('ConfirmDeleteWebsite'), 'confirm_delete','',0,1); + print $form->formconfirm($_SERVER["PHP_SELF"].'?'.($page?'page='.$page.'&':'').'sortfield='.$sortfield.'&sortorder='.$sortorder.'&rowid='.$rowid, $langs->trans('DeleteWebsite'), $langs->trans('ConfirmDeleteWebsite'), 'confirm_delete','',0,1); } //var_dump($elementList); @@ -355,7 +370,7 @@ if ($id) $fieldlist=explode(',',$tabfield[$id]); - print '<form action="'.$_SERVER['PHP_SELF'].'?id='.$id.'" method="POST">'; + print '<form action="'.$_SERVER['PHP_SELF'].'" method="POST">'; print '<input type="hidden" name="token" value="'.$_SESSION['newtoken'].'">'; print '<table class="noborder" width="100%">'; @@ -388,9 +403,7 @@ if ($id) if ($fieldlist[$field]=='libelle' || $fieldlist[$field]=='label') $alabelisused=1; } - if ($id == 4) print '<td></td>'; print '<td colspan="4">'; - print '<input type="hidden" name="id" value="'.$id.'">'; print '</td>'; print '</tr>'; @@ -444,19 +457,19 @@ if ($id) if ($num) { print '<br>'; - - print '<form action="'.$_SERVER['PHP_SELF'].'?id='.$id.'" method="POST">'; + + print '<form action="'.$_SERVER['PHP_SELF'].'" method="POST">'; print '<input type="hidden" name="token" value="'.$_SESSION['newtoken'].'">'; print '<input type="hidden" name="page" value="'.$page.'">'; print '<input type="hidden" name="rowid" value="'.$rowid.'">'; - + print '<table class="noborder" width="100%">'; - + // There is several pages if ($num > $listlimit) { print '<tr class="none"><td align="right" colspan="'.(3+count($fieldlist)).'">'; - print_fleche_navigation($page, $_SERVER["PHP_SELF"], '&id='.$id, ($num > $listlimit), '<li class="pagination"><span>'.$langs->trans("Page").' '.($page+1).'</span></li>'); + print_fleche_navigation($page, $_SERVER["PHP_SELF"], '', ($num > $listlimit), '<li class="pagination"><span>'.$langs->trans("Page").' '.($page+1).'</span></li>'); print '</td></tr>'; } @@ -486,11 +499,11 @@ if ($id) // Affiche nom du champ if ($showfield) { - print getTitleFieldOfList($valuetoshow,0,$_SERVER["PHP_SELF"],($sortable?$fieldlist[$field]:''),($page?'page='.$page.'&':'').'&id='.$id,"","align=".$align,$sortfield,$sortorder); + print getTitleFieldOfList($valuetoshow,0,$_SERVER["PHP_SELF"],($sortable?$fieldlist[$field]:''),($page?'page='.$page.'&':''),"","align=".$align,$sortfield,$sortorder); } } - print getTitleFieldOfList($langs->trans("Status"),0,$_SERVER["PHP_SELF"],"status",($page?'page='.$page.'&':'').'&id='.$id,"",'align="center"',$sortfield,$sortorder); + print getTitleFieldOfList($langs->trans("Status"),0,$_SERVER["PHP_SELF"],"status",($page?'page='.$page.'&':''),"",'align="center"',$sortfield,$sortorder); print getTitleFieldOfList(''); print getTitleFieldOfList(''); print '</tr>'; @@ -539,7 +552,7 @@ if ($id) // Can an entry be erased or disabled ? $iserasable=1;$isdisable=1; // true by default - $url = $_SERVER["PHP_SELF"].'?'.($page?'page='.$page.'&':'').'sortfield='.$sortfield.'&sortorder='.$sortorder.'&rowid='.(! empty($obj->rowid)?$obj->rowid:(! empty($obj->code)?$obj->code:'')).'&code='.(! empty($obj->code)?urlencode($obj->code):'').'&id='.$id.'&'; + $url = $_SERVER["PHP_SELF"].'?'.($page?'page='.$page.'&':'').'sortfield='.$sortfield.'&sortorder='.$sortorder.'&rowid='.(! empty($obj->rowid)?$obj->rowid:(! empty($obj->code)?$obj->code:'')).'&code='.(! empty($obj->code)?urlencode($obj->code):'').'&'; // Active print '<td align="center" class="nowrap">'; @@ -558,9 +571,9 @@ if ($id) } $i++; } - + print '</table>'; - + print '</form>'; } } diff --git a/htdocs/core/lib/pdf.lib.php b/htdocs/core/lib/pdf.lib.php index dedb169dc38074429a2d27c2c36ce483413b3e95..614379a2900a057e05290f3e2d600f6fd23451c1 100644 --- a/htdocs/core/lib/pdf.lib.php +++ b/htdocs/core/lib/pdf.lib.php @@ -865,7 +865,7 @@ function pdf_pagefoot(&$pdf,$outputlangs,$paramfreetext,$fromcompany,$marge_bass // Make a change into HTML code to allow to include images from medias directory. // <img alt="" src="/dolibarr_dev/htdocs/viewimage.php?modulepart=medias&entity=1&file=image/ldestailleur_166x166.jpg" style="height:166px; width:166px" /> // become - // <img alt="" src="'.DOL_DATA_ROOT.'/media/image/ldestailleur_166x166.jpg" style="height:166px; width:166px" /> + // <img alt="" src="'.DOL_DATA_ROOT.'/medias/image/ldestailleur_166x166.jpg" style="height:166px; width:166px" /> $newfreetext=preg_replace('/(<img.*src=")[^\"]*viewimage\.php[^\"]*modulepart=medias[^\"]*file=([^\"]*)("[^\/]*\/>)/', '\1'.DOL_DATA_ROOT.'/medias/\2\3', $newfreetext); $line.=$outputlangs->convToOutputCharset($newfreetext); diff --git a/htdocs/core/lib/website.lib.php b/htdocs/core/lib/website.lib.php index ebbd261984e4a061d0c442ccc2ba490bec80eff2..37f01a0ffe35f0dfba7865d1d59c852590cae7c5 100644 --- a/htdocs/core/lib/website.lib.php +++ b/htdocs/core/lib/website.lib.php @@ -31,21 +31,36 @@ function dolWebsiteOutput($content) { global $db, $langs, $conf, $user; + global $dolibarr_main_url_root; dol_syslog("dolWebsiteOutput start"); - + if (! defined('USEDOLIBARRSERVER')) { - // Replace link of Dolibarr medias with direct link for virtual server - - - - - + // 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 + + $symlinktomediaexists=1; + + // Make a change into HTML code to allow to include images from medias directory correct with direct link for virtual server + // <img alt="" src="/dolibarr_dev/htdocs/viewimage.php?modulepart=medias&entity=1&file=image/ldestailleur_166x166.jpg" style="height:166px; width:166px" /> + // become + // <img alt="" src="'.$urlwithroot.'/medias/image/ldestailleur_166x166.jpg" style="height:166px; width:166px" /> + $nbrep=0; + if (! $symlinktomediaexists) + { + $content=preg_replace('/(<img.*src=")[^\"]*viewimage\.php([^\"]*)modulepart=medias([^\"]*)file=([^\"]*)("[^\/]*\/>)/', '\1'.$urlwithroot.'/viewimage.php\2modulepart=medias\3file=\4\5', $content, -1, $nbrep); + } + else + { + $content=preg_replace('/(<img.*src=")[^\"]*viewimage\.php([^\"]*)modulepart=medias([^\"]*)file=([^\"]*)("[^\/]*\/>)/', '\1medias/\4\5', $content, -1, $nbrep); + } } - + dol_syslog("dolWebsiteOutput end"); - + print $content; } diff --git a/htdocs/core/modules/modWebsites.class.php b/htdocs/core/modules/modWebsites.class.php index 877c78b85ebfd82349d73cf0d800035e0cbdd7c9..57abe3713143b4d7c18d375e7f1365149413e44a 100644 --- a/htdocs/core/modules/modWebsites.class.php +++ b/htdocs/core/modules/modWebsites.class.php @@ -42,15 +42,15 @@ class modWebsites extends DolibarrModules $this->db = $db; $this->numero = 10000; - + // Family can be 'crm','financial','hr','projects','products','ecm','technic','other' // It is used to group modules in module setup page $this->family = "portal"; $this->module_position = 50; // Module label (no space allowed), used if translation string 'ModuleXXXName' not found (where XXX is value of numeric property 'numero' of module) $this->name = preg_replace('/^mod/i','',get_class($this)); - $this->description = "Enable the public website with CMS features"; - $this->version = 'development'; // 'experimental' or 'dolibarr' or version + $this->description = "Enable to build and serve public websites with CMS features"; + $this->version = 'experimental'; // 'experimental' or 'dolibarr' or version // Key used in llx_const table to save module status enabled/disabled (where MYMODULE is value of property name of module in uppercase) $this->const_name = 'MAIN_MODULE_'.strtoupper($this->name); // Where to store the module in setup page (0=common,1=interface,2=others,3=very specific) diff --git a/htdocs/install/mysql/migration/5.0.0-6.0.0.sql b/htdocs/install/mysql/migration/5.0.0-6.0.0.sql index 0b41cf739ef695cd8171e69fa05f31ff14fe4e13..f418a5e6a1f5c740e2c565f1d7dcc031fd533e5f 100644 --- a/htdocs/install/mysql/migration/5.0.0-6.0.0.sql +++ b/htdocs/install/mysql/migration/5.0.0-6.0.0.sql @@ -346,6 +346,8 @@ ALTER TABLE llx_product_fournisseur_price_log ADD COLUMN multicurrency_tx d ALTER TABLE llx_product_fournisseur_price_log ADD COLUMN multicurrency_price double(24,8) DEFAULT NULL; ALTER TABLE llx_product_fournisseur_price_log ADD COLUMN multicurrency_price_ttc double(24,8) DEFAULT NULL; +UPDATE TABLE llx_contrat set ref = rowid where ref is null or ref = ''; + create table llx_payment_various ( rowid integer AUTO_INCREMENT PRIMARY KEY, diff --git a/htdocs/langs/en_US/website.lang b/htdocs/langs/en_US/website.lang index 4482093b26dc641815a4eea1efa6b539029e4147..dd6332b11a78c90d1df173688447b02bfe0e6290 100644 --- a/htdocs/langs/en_US/website.lang +++ b/htdocs/langs/en_US/website.lang @@ -14,8 +14,9 @@ EditPageContent=Edit Content Website=Web site Webpage=Web page AddPage=Add page +HomePage=Home Page PreviewOfSiteNotYetAvailable=Preview of your website <strong>%s</strong> not yet available. You must first add a page. -RequestedPageHasNoContentYet=Requested page with id %s has not content yet or cache file .tpl.php was removed. Edit content of page to solve this. +RequestedPageHasNoContentYet=Requested page with id %s has no content yet, or cache file .tpl.php was removed. Edit content of the page to solve this. PageDeleted=Page '%s' of website %s deleted PageAdded=Page '%s' added ViewSiteInNewTab=View site in new tab diff --git a/htdocs/public/error-404.php b/htdocs/public/error-404.php index 951f29b7ddee5534875dfd945a83d7078b34a01c..36547d267041bb3562d381929e117a7a3ce652c0 100644 --- a/htdocs/public/error-404.php +++ b/htdocs/public/error-404.php @@ -18,7 +18,7 @@ <h2>Error</h2> <br> - You requested a page that does not exists. + You requested a website or a page that does not exists. <br> <?php print isset($_SERVER["HTTP_REFERER"])?'You come from '.$_SERVER["HTTP_REFERER"].'.':''; ?> diff --git a/htdocs/public/websites/index.php b/htdocs/public/websites/index.php index 4c2eec0edc57c95c3f16f2e71757e2d49d437639..0bc85dce463bb2210b910c8cafb0872751d604eb 100644 --- a/htdocs/public/websites/index.php +++ b/htdocs/public/websites/index.php @@ -67,23 +67,51 @@ if (empty($pageid)) { require_once DOL_DOCUMENT_ROOT.'/websites/class/website.class.php'; require_once DOL_DOCUMENT_ROOT.'/websites/class/websitepage.class.php'; - + $object=new Website($db); $object->fetch(0, $website); - + if (empty($object->id)) + { + if (empty($pageid)) + { + // Return header 404 + header($_SERVER["SERVER_PROTOCOL"]." 404 Not Found", true, 404); + + include DOL_DOCUMENT_ROOT.'/public/error-404.php'; + exit; + } + } + $objectpage=new WebsitePage($db); - $array=$objectpage->fetchAll($object->id); - - if (count($array) > 0) + + if ($object->fk_default_home > 0) + { + $result=$objectpage->fetch($object->fk_default_home); + if ($result > 0) + { + $pageid = $objectpage->id; + } + } + + if (empty($pageid)) { - $firstrep=reset($array); - $pageid=$firstrep->id; + $array=$objectpage->fetchAll($object->id); + if (is_array($array) && count($array) > 0) + { + $firstrep=reset($array); + $pageid=$firstrep->id; + } } } if (empty($pageid)) { + // Return header 404 + header($_SERVER["SERVER_PROTOCOL"]." 404 Not Found", true, 404); + $langs->load("website"); print $langs->trans("PreviewOfSiteNotYetAvailable"); + + include DOL_DOCUMENT_ROOT.'/public/error-404.php'; exit; } @@ -95,7 +123,7 @@ if ($pageid == 'css') // No more used ? header('Content-type: text/css'); // Important: Following code is to avoid page request by browser and PHP CPU at each Dolibarr page access. //if (empty($dolibarr_nocache)) header('Cache-Control: max-age=3600, public, must-revalidate'); - //else + //else header('Cache-Control: no-cache'); $original_file=$dolibarr_main_data_root.'/websites/'.$website.'/styles.css.php'; } @@ -136,9 +164,13 @@ $original_file_osencoded=dol_osencode($original_file); // New file name encoded // This test if file exists should be useless. We keep it to find bug more easily if (! file_exists($original_file_osencoded)) { + // Return header 404 + header($_SERVER["SERVER_PROTOCOL"]." 404 Not Found", true, 404); + $langs->load("website"); print $langs->trans("RequestedPageHasNoContentYet", $pageid); - //dol_print_error(0,$langs->trans("ErrorFileDoesNotExists",$original_file)); + + include DOL_DOCUMENT_ROOT.'/public/error-404.php'; exit; } diff --git a/htdocs/public/websites/styles.css.php b/htdocs/public/websites/styles.css.php index 5a736affc25c7e0d4e0558574668fee55df4cbaa..14014577cea772d4fe881caf3abee8bb8ca003d2 100644 --- a/htdocs/public/websites/styles.css.php +++ b/htdocs/public/websites/styles.css.php @@ -1,5 +1,5 @@ <?php -/* Copyright (C) 2016 Laurent Destailleur <eldy@users.sourceforge.net> +/* Copyright (C) 2016-2017 Laurent Destailleur <eldy@users.sourceforge.net> * * 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 @@ -18,8 +18,7 @@ /** * \file htdocs/public/websites/styles.css.php * \ingroup website - * \brief Page to output style page - * \author Laurent Destailleur + * \brief Page to output style page. Called with <link rel="stylesheet" href="styles.css.php?websiteid=123" type="text/css" /> */ define('NOTOKENRENEWAL',1); // Disables token renewal @@ -48,6 +47,7 @@ require_once DOL_DOCUMENT_ROOT.'/core/lib/files.lib.php'; $error=0; $website=GETPOST('website', 'alpha'); +$websiteid=GETPOST('websiteid', 'int'); $pageid=GETPOST('page', 'alpha')?GETPOST('page', 'alpha'):GETPOST('pageid', 'alpha'); $accessallowed = 1; @@ -67,13 +67,20 @@ if (empty($pageid)) { require_once DOL_DOCUMENT_ROOT.'/websites/class/website.class.php'; require_once DOL_DOCUMENT_ROOT.'/websites/class/websitepage.class.php'; - + $object=new Website($db); - $object->fetch(0, $website); - + if ($websiteid) + { + $object->fetch($websiteid); + $website=$object->ref; + } + else + { + $object->fetch(0, $website); + } $objectpage=new WebsitePage($db); $array=$objectpage->fetchAll($object->id); - + if (count($array) > 0) { $firstrep=reset($array); diff --git a/htdocs/websites/index.php b/htdocs/websites/index.php index 183fa45298a78e5be265b23619fae1b9af45478f..1a11ea2a4e1e868ee4bf8c1944741e8881340b91 100644 --- a/htdocs/websites/index.php +++ b/htdocs/websites/index.php @@ -414,7 +414,7 @@ if ($action == 'updatemeta') $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?websiteid='.$object->id.'" type="text/css" />'."\n"; $tplcontent.= '<title>'.dol_escape_htmltag($objectpage->title).'</title>'."\n"; $tplcontent.= '</header>'."\n"; @@ -452,6 +452,15 @@ if ($action == 'updatecontent' || GETPOST('refreshsite') || GETPOST('refreshpage { $object->fetch(0, $website); + // Check symlink to medias and restore it if ko + $pathtomedias=DOL_DATA_ROOT.'/medias'; + $pathtomediasinwebsite=$pathofwebsite.'/medias'; + if (! is_link(dol_osencode($pathtomediasinwebsite))) + { + dol_syslog("Create symlink for ".$pathtomedias." into name ".$pathtomediasinwebsite); + symlink($pathtomedias, $pathtomediasinwebsite); + } + /*if (GETPOST('savevirtualhost') && $object->virtualhost != GETPOST('previewsite')) { $object->virtualhost = GETPOST('previewsite', 'alpha'); @@ -558,7 +567,7 @@ if ($action == 'updatecontent' || GETPOST('refreshsite') || GETPOST('refreshpage $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?websiteid='.$object->id.'" type="text/css" />'."\n"; $tplcontent.= '<title>'.dol_escape_htmltag($objectpage->title).'</title>'."\n"; $tplcontent.= '</header>'."\n";