Can set the home page of web sites

This commit is contained in:
Laurent Destailleur 2016-05-02 15:51:18 +02:00
parent df4afdd663
commit d69904c14d
5 changed files with 63 additions and 11 deletions

View File

@ -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

View File

@ -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

View File

@ -17,4 +17,6 @@ AddPage=Add page
Page=Page
PreviewOfSiteNotYetAvailable=Preview of your website <strong>%s</strong> not yet available. You must first add a page.
PageDeleted=Page %s of website %s deleted
ViewInNewTab=View in new tab
ViewSiteInNewTab=View site in new tab
ViewPageInNewTab=View page in new tab
SetAsHomePage=Set as Home page

View File

@ -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 = '';

View File

@ -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 '<input type="hidden" name="action" value="updatemenu">';
}
if ($action == 'setashome')
{
print '<input type="hidden" name="action" value="updateashome">';
}
if ($action == 'editmeta')
{
print '<input type="hidden" name="action" value="updatemeta">';
@ -444,7 +475,7 @@ if (count($object->records) > 0)
if ($website)
{
print '<a href="'.DOL_URL_ROOT.'/public/websites/index.php?website='.$website.'" target="tab'.$website.'">'.$langs->trans("ViewInNewTab").'</a>';
print '<a href="'.DOL_URL_ROOT.'/public/websites/index.php?website='.$website.'" target="tab'.$website.'">'.$langs->trans("ViewSiteInNewTab").'</a>';
}
print '</div>';
@ -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.='</option>';
}
}
@ -505,6 +537,12 @@ if (count($object->records) > 0)
print '<input type="submit" class="button" name="refresh" value="'.$langs->trans("Refresh").'">';
print '<input type="submit" class="buttonDelete" name="delete" value="'.$langs->trans("Delete").'">';
//print $form->selectarray('page', $array);
if ($website && $pageid > 0)
{
print '<a href="'.DOL_URL_ROOT.'/public/websites/index.php?website='.$website.'&page='.$pageid.'" target="tab'.$website.'">'.$langs->trans("ViewPageInNewTab").'</a>';
}
print '</div>';
print '<div class="websiteselection">';
print '</div>';
@ -518,6 +556,8 @@ if (count($object->records) > 0)
if ($pageid > 0)
{
if ($object->fk_default_home > 0 && $pageid == $object->fk_default_home) print '<input type="submit" class="button" disabled="disabled" value="'.dol_escape_htmltag($langs->trans("SetAsHomePage")).'" name="setashome">';
else print '<input type="submit" class="button"'.$disabled.' value="'.dol_escape_htmltag($langs->trans("SetAsHomePage")).'" name="setashome">';
print '<input type="submit" class="button"'.$disabled.' value="'.dol_escape_htmltag($langs->trans("EditPageMeta")).'" name="editmeta">';
print '<input type="submit" class="button"'.$disabled.' value="'.dol_escape_htmltag($langs->trans("EditPageContent")).'" name="editcontent">';
//print '<a href="'.$_SERVER["PHP_SELF"].'?action=editmeta&website='.urlencode($website).'&pageid='.urlencode($pageid).'" class="button">'.dol_escape_htmltag($langs->trans("EditPageMeta")).'</a>';