Skip to content

Commit

Permalink
Work on module website
Browse files Browse the repository at this point in the history
  • Loading branch information
eldy committed Apr 28, 2017
1 parent 853c8a8 commit 0ba6433
Show file tree
Hide file tree
Showing 10 changed files with 105 additions and 92 deletions.
49 changes: 17 additions & 32 deletions htdocs/admin/websites.php
Expand Up @@ -375,11 +375,11 @@
// 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 '<td align="'.$align.'">';
print '<td class="'.$align.'">';
if (! empty($tabhelp[$id][$value]) && preg_match('/^http(s*):/i',$tabhelp[$id][$value])) print '<a href="'.$tabhelp[$id][$value].'" target="_blank">'.$valuetoshow.' '.img_help(1,$valuetoshow).'</a>';
else if (! empty($tabhelp[$id][$value])) print $form->textwithpicto($valuetoshow,$tabhelp[$id][$value]);
else print $valuetoshow;
Expand Down Expand Up @@ -413,14 +413,11 @@
$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 '<td></td>';
print '<td colspan="3" align="right">';
if ($action != 'edit')
{
Expand All @@ -430,15 +427,9 @@
print "</tr>";

$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 '<tr><td colspan="'.$colspan.'">* '.$langs->trans("LabelUsedByDefault").'.</td></tr>';
}
print '<tr><td colspan="'.$colspan.'">&nbsp;</td></tr>'; // Keep &nbsp; to have a line with enough height
}

print '</table>';
print '</form>';


Expand All @@ -453,6 +444,15 @@
$var=true;
if ($num)
{
print '<br>';

print '<form action="'.$_SERVER['PHP_SELF'].'?id='.$id.'" 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)
{
Expand Down Expand Up @@ -503,14 +503,9 @@

$obj = $db->fetch_object($resql);
//print_r($obj);
print '<tr '.$bc[$var].' id="rowid-'.$obj->rowid.'">';
print '<tr class="oddeven" id="rowid-'.$obj->rowid.'">';
if ($action == 'edit' && ($rowid == (! empty($obj->rowid)?$obj->rowid:$obj->code)))
{
print '<form action="'.$_SERVER['PHP_SELF'].'?id='.$id.'" 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.'">';

$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
Expand Down Expand Up @@ -548,16 +543,6 @@

$url = $_SERVER["PHP_SELF"].'?'.($page?'page='.$page.'&':'').'sortfield='.$sortfield.'&sortorder='.$sortorder.'&rowid='.(! empty($obj->rowid)?$obj->rowid:(! empty($obj->code)?$obj->code:'')).'&amp;code='.(! empty($obj->code)?urlencode($obj->code):'').'&amp;id='.$id.'&amp;';

// Favorite
// Only activated on country dictionary
if ($id == 4)
{
print '<td align="center" class="nowrap">';
if ($iserasable) print '<a href="'.$url.'action='.$acts[$obj->favorite].'_favorite">'.$actl[$obj->favorite].'</a>';
else print $langs->trans("AlwaysActive");
print '</td>';
}

// Active
print '<td align="center" class="nowrap">';
print '<a href="'.$url.'action='.$acts[$obj->status].'">'.$actl[$obj->status].'</a>';
Expand All @@ -575,15 +560,15 @@
}
$i++;
}

print '</table>';

print '</form>';
}
}
else {
dol_print_error($db);
}

print '</table>';

print '</form>';
}

print '<br>';
Expand Down
3 changes: 3 additions & 0 deletions htdocs/install/mysql/migration/5.0.0-6.0.0.sql
Expand Up @@ -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
(
Expand Down
7 changes: 4 additions & 3 deletions htdocs/install/mysql/tables/llx_website.sql
Expand Up @@ -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;
6 changes: 4 additions & 2 deletions htdocs/install/mysql/tables/llx_website_pages.sql
Expand Up @@ -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;
4 changes: 2 additions & 2 deletions htdocs/langs/en_US/website.lang
Expand Up @@ -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 <strong>%s</strong>, 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.<br>URL of %s served by external server:<br><strong>%s</strong>
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.<br>The inconvenient is that URL of pages are not user friendly and start with path of your Dolibarr.<br>URL of %s served by Dolibarr:<br><strong>%s</strong>
PreviewSiteServedByWebServer=Preview %s in a new tab.<br><br>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:<br><strong>%s</strong><br>URL served by external server:<br><strong>%s</strong>
PreviewSiteServedByDolibarr=Preview %s in a new tab.<br><br>The %s will be served by Dolibarr server so it does not need any extra web server (like Apache, Nginx, IIS) to be installed.<br>The inconvenient is that URL of pages are not user friendly and start with path of your Dolibarr.<br>URL served by Dolibarr:<br><strong>%s</strong><br><br>To use your own external web server to serve this web site, create a virtual host on your web server that point on directory<br><strong>%s</strong><br>then enter the name of this virtual server and clicking on the other preview button.
Binary file added htdocs/theme/eldy/img/save.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added htdocs/theme/md/img/save.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
47 changes: 18 additions & 29 deletions htdocs/websites/class/website.class.php
Expand Up @@ -73,10 +73,6 @@ class Website extends CommonObject
* @var mixed
*/
public $date_creation;
/**
* @var mixed
*/
public $date_modification;
/**
* @var mixed
*/
Expand Down Expand Up @@ -123,7 +119,6 @@ public function create(User $user, $notrigger = false)
$error = 0;

// Clean parameters

if (isset($this->entity)) {
$this->entity = trim($this->entity);
}
Expand All @@ -136,36 +131,30 @@ public function create(User $user, $notrigger = false)
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();
Expand Down Expand Up @@ -223,8 +212,9 @@ public function fetch($id, $ref = null)
$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) {
Expand All @@ -247,11 +237,10 @@ public function fetch($id, $ref = null)
$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);

Expand Down Expand Up @@ -292,8 +281,9 @@ public function fetchAll($sortorder='', $sortfield='', $limit=0, $offset=0, arra
$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';

Expand Down Expand Up @@ -331,8 +321,9 @@ public function fetchAll($sortorder='', $sortfield='', $limit=0, $offset=0, arra
$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;
Expand Down Expand Up @@ -377,25 +368,20 @@ public function update(User $user, $notrigger = false)
$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();
Expand Down Expand Up @@ -631,6 +617,8 @@ function LibStatut($status,$mode=0)
*/
public function initAsSpecimen()
{
global $user;

$this->id = 0;

$this->entity = 1;
Expand All @@ -639,8 +627,9 @@ public function initAsSpecimen()
$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();


Expand Down
13 changes: 8 additions & 5 deletions htdocs/websites/class/websitepage.class.php
Expand Up @@ -181,7 +181,7 @@ public function create(User $user, $notrigger = false)
/**
* 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
*
Expand All @@ -205,13 +205,16 @@ public function fetch($id, $website_id = null, $page = null)
$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);
Expand Down

0 comments on commit 0ba6433

Please sign in to comment.