From 0ba6433a6166853b4b8a7a4d019c0b9e29a2b68f Mon Sep 17 00:00:00 2001 From: Laurent Destailleur Date: Fri, 28 Apr 2017 13:10:08 +0200 Subject: [PATCH] Work on module website --- htdocs/admin/websites.php | 49 +++++-------- .../install/mysql/migration/5.0.0-6.0.0.sql | 3 + htdocs/install/mysql/tables/llx_website.sql | 7 +- .../mysql/tables/llx_website_pages.sql | 6 +- htdocs/langs/en_US/website.lang | 4 +- htdocs/theme/eldy/img/save.png | Bin 0 -> 264 bytes htdocs/theme/md/img/save.png | Bin 0 -> 264 bytes htdocs/websites/class/website.class.php | 47 +++++------- htdocs/websites/class/websitepage.class.php | 13 ++-- htdocs/websites/index.php | 68 +++++++++++++----- 10 files changed, 105 insertions(+), 92 deletions(-) create mode 100644 htdocs/theme/eldy/img/save.png create mode 100644 htdocs/theme/md/img/save.png diff --git a/htdocs/admin/websites.php b/htdocs/admin/websites.php index b0c81ec18af..06e9a7b93a4 100644 --- a/htdocs/admin/websites.php +++ b/htdocs/admin/websites.php @@ -375,11 +375,11 @@ if ($id) // dans les dictionnaires de donnees $valuetoshow=ucfirst($fieldlist[$field]); // Par defaut $valuetoshow=$langs->trans($valuetoshow); // try to translate - $align="left"; + $align=''; if ($fieldlist[$field]=='lang') { $valuetoshow=$langs->trans("Language"); } if ($valuetoshow != '') { - print ''; + print ''; if (! empty($tabhelp[$id][$value]) && preg_match('/^http(s*):/i',$tabhelp[$id][$value])) print ''.$valuetoshow.' '.img_help(1,$valuetoshow).''; else if (! empty($tabhelp[$id][$value])) print $form->textwithpicto($valuetoshow,$tabhelp[$id][$value]); else print $valuetoshow; @@ -413,14 +413,11 @@ if ($id) $reshook=$hookmanager->executeHooks('createDictionaryFieldlist',$parameters, $obj, $tmpaction); // Note that $action and $object may have been modified by some hooks $error=$hookmanager->error; $errors=$hookmanager->errors; - if ($id == 3) unset($fieldlist[2]); - if (empty($reshook)) { fieldListWebsites($fieldlist,$obj,$tabname[$id],'add'); } - if ($id == 4) print ''; print ''; if ($action != 'edit') { @@ -430,15 +427,9 @@ if ($id) print ""; $colspan=count($fieldlist)+2; - if ($id == 4) $colspan++; - - if (! empty($alabelisused) && $id != 25) // If there is one label among fields, we show legend of * - { - print '* '.$langs->trans("LabelUsedByDefault").'.'; - } - print ' '; // Keep   to have a line with enough height } + print ''; print ''; @@ -453,6 +444,15 @@ if ($id) $var=true; if ($num) { + print '
'; + + print '
'; + print ''; + print ''; + print ''; + + print ''; + // There is several pages if ($num > $listlimit) { @@ -503,14 +503,9 @@ if ($id) $obj = $db->fetch_object($resql); //print_r($obj); - print ''; + print ''; if ($action == 'edit' && ($rowid == (! empty($obj->rowid)?$obj->rowid:$obj->code))) { - print ''; - print ''; - print ''; - print ''; - $tmpaction='edit'; $parameters=array('fieldlist'=>$fieldlist, 'tabname'=>$tabname[$id]); $reshook=$hookmanager->executeHooks('editDictionaryFieldlist',$parameters,$obj, $tmpaction); // Note that $action and $object may have been modified by some hooks @@ -548,16 +543,6 @@ if ($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):'').'&id='.$id.'&'; - // Favorite - // Only activated on country dictionary - if ($id == 4) - { - print ''; - } - // Active print '
'; - if ($iserasable) print ''.$actl[$obj->favorite].''; - else print $langs->trans("AlwaysActive"); - print ''; print ''.$actl[$obj->status].''; @@ -575,15 +560,15 @@ if ($id) } $i++; } + + print '
'; + + print '
'; } } else { dol_print_error($db); } - - print ''; - - print ''; } print '
'; 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 9ff9de4e70d..c2edae8b592 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 @@ -137,6 +137,9 @@ ALTER TABLE llx_chargesociales ADD COLUMN fk_projet integer DEFAULT NULL; ALTER TABLE llx_cronjob ADD COLUMN processing integer NOT NULL DEFAULT 0; +ALTER TABLE llx_website ADD COLUMN fk_user_create integer; +ALTER TABLE llx_website ADD COLUMN fk_user_modif integer; + create table llx_payment_various ( diff --git a/htdocs/install/mysql/tables/llx_website.sql b/htdocs/install/mysql/tables/llx_website.sql index 331e6b085bd..84a9dd47188 100644 --- a/htdocs/install/mysql/tables/llx_website.sql +++ b/htdocs/install/mysql/tables/llx_website.sql @@ -26,7 +26,8 @@ CREATE TABLE llx_website status integer, fk_default_home integer, virtualhost varchar(255), - date_creation datetime, - date_modification datetime, - tms timestamp + fk_user_create integer, + fk_user_modif integer, + date_creation datetime, + tms timestamp ) ENGINE=innodb; diff --git a/htdocs/install/mysql/tables/llx_website_pages.sql b/htdocs/install/mysql/tables/llx_website_pages.sql index 982420dd507..69b6c417528 100644 --- a/htdocs/install/mysql/tables/llx_website_pages.sql +++ b/htdocs/install/mysql/tables/llx_website_pages.sql @@ -27,6 +27,8 @@ CREATE TABLE llx_website_page keywords varchar(255), content mediumtext, -- text is not enough in size status integer, - date_creation datetime, - tms timestamp + fk_user_create integer, + fk_user_modif integer, + date_creation datetime, + tms timestamp ) ENGINE=innodb; diff --git a/htdocs/langs/en_US/website.lang b/htdocs/langs/en_US/website.lang index fcb09c8d5c1..03069d6f649 100644 --- a/htdocs/langs/en_US/website.lang +++ b/htdocs/langs/en_US/website.lang @@ -24,5 +24,5 @@ SetAsHomePage=Set as Home page RealURL=Real URL ViewWebsiteInProduction=View web site using home URLs SetHereVirtualHost=If you can set, on your web server, a dedicated virtual host with a root directory on %s, define here the virtual hostname so the preview can be done also using this direct web server access and not only using Dolibarr server. -PreviewSiteServedByWebServer=Preview %s in a new tab. The %s will be served by an external web server (like Apache, Nginx, IIS). You must instal and setup this server before.
URL of %s served by external server:
%s -PreviewSiteServedByDolibarr=Preview %s in a new tab. The %s will be served by Dolibarr server so it does not need any extra web server (like Apache, Nginx, IIS) to be installed.
The inconvenient is that URL of pages are not user friendly and start with path of your Dolibarr.
URL of %s served by Dolibarr:
%s +PreviewSiteServedByWebServer=Preview %s in a new tab.

The %s will be served by an external web server (like Apache, Nginx, IIS). You must install and setup this server before to point to directory:
%s
URL served by external server:
%s +PreviewSiteServedByDolibarr=Preview %s in a new tab.

The %s will be served by Dolibarr server so it does not need any extra web server (like Apache, Nginx, IIS) to be installed.
The inconvenient is that URL of pages are not user friendly and start with path of your Dolibarr.
URL served by Dolibarr:
%s

To use your own external web server to serve this web site, create a virtual host on your web server that point on directory
%s
then enter the name of this virtual server and clicking on the other preview button. diff --git a/htdocs/theme/eldy/img/save.png b/htdocs/theme/eldy/img/save.png new file mode 100644 index 0000000000000000000000000000000000000000..eca2d92eccc5665b070d3c04e7241fbc2cbb71d5 GIT binary patch literal 264 zcmV+j0r&oiP)^5To~qfUqA&PMF*F<|kx;Md$&W&;x!#4;TRufSvnyKmY=;&`=O< zD`{EPz!xd^WlTz7A;m7|q5~RSbvmHHRiy(WT*Yq$l(?#OK#Qwh2dre+9fV)gZ4fyZ>#A&pWX|cF@nuJ>{9{^+CL!nen`MaoS0vDoPmT;NZb{N*U=t-36Ko{ O0000^5To~qfUqA&PMF*F<|kx;Md$&W&;x!#4;TRufSvnyKmY=;&`=O< zD`{EPz!xd^WlTz7A;m7|q5~RSbvmHHRiy(WT*Yq$l(?#OK#Qwh2dre+9fV)gZ4fyZ>#A&pWX|cF@nuJ>{9{^+CL!nen`MaoS0vDoPmT;NZb{N*U=t-36Ko{ O0000entity)) { $this->entity = trim($this->entity); } @@ -136,36 +131,30 @@ class Website extends CommonObject if (isset($this->status)) { $this->status = trim($this->status); } - - + if (empty($this->date_creation)) $this->date_creation = dol_now(); // Check parameters // Put here code to add control on parameters values // Insert request $sql = 'INSERT INTO ' . MAIN_DB_PREFIX . $this->table_element . '('; - $sql.= 'entity,'; $sql.= 'ref,'; $sql.= 'description,'; $sql.= 'status,'; $sql.= 'fk_default_home,'; $sql.= 'virtualhost,'; - $sql.= 'date_creation,'; - $sql.= 'date_modification'; - + $sql.= 'fk_user_create'; + $sql.= 'date_creation'; $sql .= ') VALUES ('; - $sql .= ' '.(! isset($this->entity)?'NULL':$this->entity).','; $sql .= ' '.(! isset($this->ref)?'NULL':"'".$this->db->escape($this->ref)."'").','; $sql .= ' '.(! isset($this->description)?'NULL':"'".$this->db->escape($this->description)."'").','; $sql .= ' '.(! isset($this->status)?'NULL':$this->status).','; $sql .= ' '.(! isset($this->fk_default_home)?'NULL':$this->fk_default_home).','; $sql .= ' '.(! isset($this->virtualhost)?'NULL':$this->virtualhost).','; - $sql .= ' '.(! isset($this->date_creation) || dol_strlen($this->date_creation)==0?'NULL':"'".$this->db->idate($this->date_creation)."'").','; - $sql .= ' '.(! isset($this->date_modification) || dol_strlen($this->date_modification)==0?'NULL':"'".$this->db->idate($this->date_modification)."'"); - - + $sql .= ' '.(! isset($this->fk_user_create)?$user->id:$this->fk_user_create).','; + $sql .= ' '.(! isset($this->date_creation) || dol_strlen($this->date_creation)==0?'NULL':"'".$this->db->idate($this->date_creation)."'"); $sql .= ')'; $this->db->begin(); @@ -223,8 +212,9 @@ class Website extends CommonObject $sql .= " t.status,"; $sql .= " t.fk_default_home,"; $sql .= " t.virtualhost,"; + $sql .= " t.fk_user_create,"; + $sql .= " t.fk_user_modif,"; $sql .= " t.date_creation,"; - $sql .= " t.date_modification,"; $sql .= " t.tms"; $sql .= ' FROM ' . MAIN_DB_PREFIX . $this->table_element . ' as t'; if (null !== $ref) { @@ -247,11 +237,10 @@ class Website extends CommonObject $this->status = $obj->status; $this->fk_default_home = $obj->fk_default_home; $this->virtualhost = $obj->virtualhost; + $this->fk_user_create = $obj->fk_user_create; + $this->fk_user_modif = $obj->fk_user_modif; $this->date_creation = $this->db->jdate($obj->date_creation); - $this->date_modification = $this->db->jdate($obj->date_modification); $this->tms = $this->db->jdate($obj->tms); - - } $this->db->free($resql); @@ -292,8 +281,9 @@ class Website extends CommonObject $sql .= " t.status,"; $sql .= " t.fk_default_home,"; $sql .= " t.virtualhost,"; + $sql .= " t.fk_user_create,"; + $sql .= " t.fk_user_modif,"; $sql .= " t.date_creation,"; - $sql .= " t.date_modification,"; $sql .= " t.tms"; $sql .= ' FROM ' . MAIN_DB_PREFIX . $this->table_element. ' as t'; @@ -331,8 +321,9 @@ class Website extends CommonObject $line->status = $obj->status; $line->fk_default_home = $obj->fk_default_home; $line->virtualhost = $obj->virtualhost; + $this->fk_user_create = $obj->fk_user_create; + $this->fk_user_modif = $obj->fk_user_modif; $line->date_creation = $this->db->jdate($obj->date_creation); - $line->date_modification = $this->db->jdate($obj->date_modification); $line->tms = $this->db->jdate($obj->tms); $this->records[$line->id] = $line; @@ -377,25 +368,20 @@ class Website extends CommonObject $this->status = trim($this->status); } - - // Check parameters // Put here code to add a control on parameters values // Update request $sql = 'UPDATE ' . MAIN_DB_PREFIX . $this->table_element . ' SET'; - $sql .= ' entity = '.(isset($this->entity)?$this->entity:"null").','; $sql .= ' ref = '.(isset($this->ref)?"'".$this->db->escape($this->ref)."'":"null").','; $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->db->escape($this->virtualhost)."'":"null").','; + $sql .= ' fk_user_modif = '.(! isset($this->fk_user_modif) ? $user->id : $this->fk_user_modif).','; $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())."'"); - - $sql .= ' WHERE rowid=' . $this->id; $this->db->begin(); @@ -631,6 +617,8 @@ class Website extends CommonObject */ public function initAsSpecimen() { + global $user; + $this->id = 0; $this->entity = 1; @@ -639,8 +627,9 @@ class Website extends CommonObject $this->status = ''; $this->fk_default_home = null; $this->virtualhost = 'http://myvirtualhost'; + $this->fk_user_create = $user->id; + $this->fk_user_modif = $user->id; $this->date_creation = dol_now(); - $this->date_modification = dol_now(); $this->tms = dol_now(); diff --git a/htdocs/websites/class/websitepage.class.php b/htdocs/websites/class/websitepage.class.php index 883b6495c53..c80d20fe44b 100644 --- a/htdocs/websites/class/websitepage.class.php +++ b/htdocs/websites/class/websitepage.class.php @@ -181,7 +181,7 @@ class WebsitePage extends CommonObject /** * Load object in memory from the database * - * @param int $id Id object + * @param int $id Id object. If this is 0, the default page of website_id will be used, if not defined, the first one. found * @param string $website_id Web site id * @param string $page Page name * @@ -205,13 +205,16 @@ class WebsitePage extends CommonObject $sql .= " t.tms as date_modification"; $sql .= ' FROM ' . MAIN_DB_PREFIX . $this->table_element . ' as t'; + //$sql .= ' WHERE entity IN ('.getEntity('website', 1).')'; // entity is on website level + $sql .= ' WHERE 1 = 1'; if (null !== $website_id) { - $sql .= ' WHERE t.fk_website = ' . '\'' . $website_id . '\''; - $sql .= ' AND t.pageurl = ' . '\'' . $page . '\''; + $sql .= " AND t.fk_website = '" . $this->db->escape($website_id) . "'"; + if ($page) $sql .= " AND t.pageurl = '" . $this->db->escape($page) . "'"; } else { - $sql .= ' WHERE t.rowid = ' . $id; + $sql .= ' AND t.rowid = ' . $id; } - + $sql .= $this->db->plimit(1); + $resql = $this->db->query($sql); if ($resql) { $numrows = $this->db->num_rows($resql); diff --git a/htdocs/websites/index.php b/htdocs/websites/index.php index b55f81f5b7f..b78a172e01f 100644 --- a/htdocs/websites/index.php +++ b/htdocs/websites/index.php @@ -438,16 +438,34 @@ if ($action == 'updatemeta') // Update page if ($action == 'updatecontent' || GETPOST('refreshsite') || GETPOST('refreshpage') || GETPOST('preview')) { - $db->begin(); $object->fetch(0, $website); + /*if (GETPOST('savevirtualhost') && $object->virtualhost != GETPOST('previewsite')) + { + $object->virtualhost = GETPOST('previewsite', 'alpha'); + $object->update($user); + }*/ + $objectpage->fk_website = $object->id; - $res = $objectpage->fetch($pageid, $object->fk_website); + if ($pageid > 0) + { + $res = $objectpage->fetch($pageid); + } + else + { + $res = $objectpage->fetch($object->fk_default_home); + if (! $res > 0) + { + $res = $objectpage->fetch(0, $object->fk_website); + } + } if ($res > 0) { if ($action == 'updatecontent') { + $db->begin(); + $objectpage->content = GETPOST('PAGE_CONTENT'); // Clean data. We remove all the head section. @@ -632,7 +650,7 @@ if (count($object->records) > 0) // List of websites print '
'; $out=''; - $out.=''; if (empty($object->records)) $out.=''; // Loop on each sites $i=0; @@ -654,9 +672,9 @@ if (count($object->records) > 0) if ($website) { - $realurl=$urlwithroot.'/public/websites/index.php?website='.$website; + $virtualurl=''; $dataroot=DOL_DATA_ROOT.'/websites/'.$website; - if (! empty($object->virtualhost)) $realurl=$object->virtualhost; + if (! empty($object->virtualhost)) $virtualurl=$object->virtualhost; } if ($website && $action == 'preview') @@ -680,20 +698,23 @@ if (count($object->records) > 0) if ($action == 'preview') { print '
'; - print ''; + print ''; //print ''; $htmltext=$langs->trans("SetHereVirtualHost", $dataroot); print $form->textwithpicto('', $htmltext); print '
'; - $urlext=$realurl; - $urlint=DOL_URL_ROOT.'/public/websites/index.php?website='.$website; - print ''; - print $form->textwithpicto('', $langs->trans("PreviewSiteServedByWebServer", $langs->transnoentitiesnoconv("Page"), $langs->transnoentitiesnoconv("Page"), $langs->transnoentitiesnoconv("Page"), $urlext), 1, 'preview_ext'); - print ''; + $urlext=$virtualurl; + $urlint=$urlwithroot.'/public/websites/index.php?website='.$website; + //if (! empty($object->virtualhost)) + //{ + print 'transnoentitiesnoconv("Site"), $langs->transnoentitiesnoconv("Site"), $dataroot, $urlext)).'">'; + print $form->textwithpicto('', $langs->trans("PreviewSiteServedByWebServer", $langs->transnoentitiesnoconv("Site"), $langs->transnoentitiesnoconv("Site"), $dataroot, $urlext?$urlext:$langs->trans("VirtualHostUrlNotDefined")), 1, 'preview_ext'); + print ''; + //} - print ''; - print $form->textwithpicto('', $langs->trans("PreviewSiteServedByDolibarr", $langs->transnoentitiesnoconv("Page"), $langs->transnoentitiesnoconv("Page"), $langs->transnoentitiesnoconv("Page"), $urlint), 1, 'preview'); + print 'transnoentitiesnoconv("Site"), $langs->transnoentitiesnoconv("Site"), $urlint)).'">'; + print $form->textwithpicto('', $langs->trans("PreviewSiteServedByDolibarr", $langs->transnoentitiesnoconv("Site"), $langs->transnoentitiesnoconv("Site"), $urlint, $dataroot), 1, 'preview'); print ''; } @@ -803,13 +824,22 @@ if (count($object->records) > 0) print $form->textwithpicto('', $htmltext); print '
'; - $urlext=$realurl.'/'.$pagealias.'.php'; - print ''; - print $form->textwithpicto('', $langs->trans("PreviewSiteServedByWebServer", $langs->transnoentitiesnoconv("Page"), $langs->transnoentitiesnoconv("Page"), $langs->transnoentitiesnoconv("Page"), $urlext), 1, 'preview_ext'); - print ''; + if (! empty($object->virtualhost)) + { + $urlext=$virtualurl.'/'.$pagealias.'.php'; + print 'transnoentitiesnoconv("Page"), $langs->transnoentitiesnoconv("Page"), $dataroot, $urlext)).'">'; + print $form->textwithpicto('', $langs->trans("PreviewSiteServedByWebServer", $langs->transnoentitiesnoconv("Page"), $langs->transnoentitiesnoconv("Page"), $dataroot, $urlext?$urlext:$langs->trans("VirtualHostUrlNotDefined")), 1, 'preview_ext'); + print ''; + } + else + { + print ''; + print $form->textwithpicto('', $langs->trans("PreviewSiteServedByWebServer", $langs->transnoentitiesnoconv("Page"), $langs->transnoentitiesnoconv("Page"), $dataroot, $urlext?$urlext:$langs->trans("VirtualHostUrlNotDefined")), 1, 'preview_ext'); + print ''; + } - print ''; - print $form->textwithpicto('', $langs->trans("PreviewSiteServedByDolibarr", $langs->transnoentitiesnoconv("Page"), $langs->transnoentitiesnoconv("Page"), $langs->transnoentitiesnoconv("Page"), $realpage), 1, 'preview'); + print 'transnoentitiesnoconv("Page"), $langs->transnoentitiesnoconv("Page"), $realpage)).'">'; + print $form->textwithpicto('', $langs->trans("PreviewSiteServedByDolibarr", $langs->transnoentitiesnoconv("Page"), $langs->transnoentitiesnoconv("Page"), $realpage, $dataroot), 1, 'preview'); print ''; // View page in new Tab //print '';