diff --git a/htdocs/install/mysql/migration/3.9.0-4.0.0.sql b/htdocs/install/mysql/migration/3.9.0-4.0.0.sql index a429ef5c7cf..adce0125c1c 100644 --- a/htdocs/install/mysql/migration/3.9.0-4.0.0.sql +++ b/htdocs/install/mysql/migration/3.9.0-4.0.0.sql @@ -115,11 +115,12 @@ CREATE TABLE llx_website ref varchar(24) NOT NULL, description varchar(255), status integer, + fk_default_home integer, date_creation datetime, date_modification datetime, tms timestamp ) ENGINE=innodb; - +ALTER TABLE llx_website ADD COLUMN fk_default_home integer; ALTER TABLE llx_website ADD UNIQUE INDEX uk_website_ref (ref, entity); CREATE TABLE llx_website_page diff --git a/htdocs/install/mysql/tables/llx_website.sql b/htdocs/install/mysql/tables/llx_website.sql index fd8ed4cc39c..8dd257ffa69 100644 --- a/htdocs/install/mysql/tables/llx_website.sql +++ b/htdocs/install/mysql/tables/llx_website.sql @@ -24,6 +24,7 @@ CREATE TABLE llx_website ref varchar(24) NOT NULL, description varchar(255), status integer, + fk_default_home integer, date_creation datetime, date_modification datetime, tms timestamp diff --git a/htdocs/langs/en_US/website.lang b/htdocs/langs/en_US/website.lang index a0b2106ac63..d94ac13cd05 100644 --- a/htdocs/langs/en_US/website.lang +++ b/htdocs/langs/en_US/website.lang @@ -17,4 +17,6 @@ AddPage=Add page Page=Page PreviewOfSiteNotYetAvailable=Preview of your website %s not yet available. You must first add a page. PageDeleted=Page %s of website %s deleted -ViewInNewTab=View in new tab \ No newline at end of file +ViewSiteInNewTab=View site in new tab +ViewPageInNewTab=View page in new tab +SetAsHomePage=Set as Home page \ No newline at end of file diff --git a/htdocs/websites/class/website.class.php b/htdocs/websites/class/website.class.php index 4b6d4e04245..a82a0833aba 100644 --- a/htdocs/websites/class/website.class.php +++ b/htdocs/websites/class/website.class.php @@ -63,7 +63,7 @@ class Website extends CommonObject public $date_creation = ''; public $date_modification = ''; public $tms = ''; - + public $fk_default_home; public $records; /** @@ -122,9 +122,9 @@ class Website extends CommonObject $sql.= 'ref,'; $sql.= 'description,'; $sql.= 'status,'; + $sql.= 'fk_default_home,'; $sql.= 'date_creation,'; $sql.= 'date_modification'; - $sql .= ') VALUES ('; @@ -132,6 +132,7 @@ class Website extends CommonObject $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->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)."'"); @@ -191,6 +192,7 @@ class Website extends CommonObject $sql .= " t.ref,"; $sql .= " t.description,"; $sql .= " t.status,"; + $sql .= " t.fk_default_home,"; $sql .= " t.date_creation,"; $sql .= " t.date_modification,"; $sql .= " t.tms"; @@ -213,6 +215,7 @@ class Website extends CommonObject $this->ref = $obj->ref; $this->description = $obj->description; $this->status = $obj->status; + $this->fk_default_home = $obj->fk_default_home; $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); @@ -257,6 +260,7 @@ class Website extends CommonObject $sql .= " t.ref,"; $sql .= " t.description,"; $sql .= " t.status,"; + $sql .= " t.fk_default_home,"; $sql .= " t.date_creation,"; $sql .= " t.date_modification,"; $sql .= " t.tms"; @@ -295,6 +299,7 @@ class Website extends CommonObject $line->ref = $obj->ref; $line->description = $obj->description; $line->status = $obj->status; + $line->fk_default_home = $obj->fk_default_home; $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); @@ -353,6 +358,7 @@ class Website extends CommonObject $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 .= ' 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())."'"); @@ -595,13 +601,14 @@ class Website extends CommonObject { $this->id = 0; - $this->entity = ''; - $this->ref = ''; - $this->description = ''; + $this->entity = 1; + $this->ref = 'myspecimenwebsite'; + $this->description = 'A specimen website'; $this->status = ''; - $this->date_creation = ''; - $this->date_modification = ''; - $this->tms = ''; + $this->fk_default_home = null; + $this->date_creation = dol_now(); + $this->date_modification = dol_now(); + $this->tms = dol_now(); } @@ -625,6 +632,7 @@ class WebsiteLine public $ref; public $description; public $status; + public $fk_default_home; public $date_creation = ''; public $date_modification = ''; public $tms = ''; diff --git a/htdocs/websites/index.php b/htdocs/websites/index.php index 98efd23f45b..1b7532bd0da 100644 --- a/htdocs/websites/index.php +++ b/htdocs/websites/index.php @@ -90,6 +90,7 @@ if (GETPOST('create')) { $action='create'; } if (GETPOST('editmedia')) { $action='editmedia'; } if (GETPOST('editcss')) { $action='editcss'; } if (GETPOST('editmenu')) { $action='editmenu'; } +if (GETPOST('setashome')) { $action='setashome'; } if (GETPOST('editmeta')) { $action='editmeta'; } if (GETPOST('editcontent')) { $action='editcontent'; } @@ -278,6 +279,32 @@ if ($action == 'updatecss') $action='preview'; } +// Update page +if ($action == 'setashome') +{ + $db->begin(); + $object->fetch(0, $website); + + $object->fk_default_home = $pageid; + $res = $object->update($user); + if (! $res > 0) + { + $error++; + setEventMessages($objectpage->error, $objectpage->errors, 'errors'); + } + + if (! $error) + { + $db->commit(); + setEventMessages($langs->trans("Saved"), null, 'mesgs'); + $action='preview'; + } + else + { + $db->rollback(); + } +} + // Update page if ($action == 'updatemeta') { @@ -393,6 +420,10 @@ if ($action == 'editmenu') { print ''; } +if ($action == 'setashome') +{ + print ''; +} if ($action == 'editmeta') { print ''; @@ -444,7 +475,7 @@ if (count($object->records) > 0) if ($website) { - print ''.$langs->trans("ViewInNewTab").''; + print ''.$langs->trans("ViewSiteInNewTab").''; } print ''; @@ -496,6 +527,7 @@ if (count($object->records) > 0) if ($pageid > 0 && $pageid == $key) $out.=' selected'; // To preselect a value $out.='>'; $out.=$valpage->title; + if ($object->fk_default_home && $key == $object->fk_default_home) $out.=' ('.$langs->trans("HomePage").')'; $out.=''; } } @@ -505,6 +537,12 @@ if (count($object->records) > 0) print ''; print ''; //print $form->selectarray('page', $array); + + if ($website && $pageid > 0) + { + print ''.$langs->trans("ViewPageInNewTab").''; + } + print ''; print '
'; print '
'; @@ -518,6 +556,8 @@ if (count($object->records) > 0) if ($pageid > 0) { + if ($object->fk_default_home > 0 && $pageid == $object->fk_default_home) print ''; + else print ''; print ''; print ''; //print ''.dol_escape_htmltag($langs->trans("EditPageMeta")).'';