2016-04-19 11:02:55 +02:00
< ? php
/* Copyright ( C ) 2007 - 2012 Laurent Destailleur < eldy @ users . sourceforge . net >
* Copyright ( C ) 2014 Juanjo Menent < jmenent @ 2 byte . es >
* Copyright ( C ) 2015 Florian Henry < florian . henry @ open - concept . pro >
* Copyright ( C ) 2015 Raphaël Doursenaud < rdoursenaud @ gpcsolutions . fr >
* Copyright ( C ) --- Put here your own copyright and developer email ---
*
* 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
* the Free Software Foundation ; either version 3 of the License , or
* ( at your option ) any later version .
*
* This program is distributed in the hope that it will be useful ,
* but WITHOUT ANY WARRANTY ; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE . See the
* GNU General Public License for more details .
*
* You should have received a copy of the GNU General Public License
* along with this program . If not , see < http :// www . gnu . org / licenses />.
*/
/**
2017-10-20 21:39:19 +02:00
* \file website / websitepage . class . php
* \ingroup website
2017-08-03 01:45:31 +02:00
* \brief File for the CRUD class of websitepage ( Create / Read / Update / Delete )
2016-04-19 11:02:55 +02:00
*/
// Put here all includes required by your class file
require_once DOL_DOCUMENT_ROOT . '/core/class/commonobject.class.php' ;
//require_once DOL_DOCUMENT_ROOT . '/societe/class/societe.class.php';
//require_once DOL_DOCUMENT_ROOT . '/product/class/product.class.php';
/**
* Class Websitepage
*/
class WebsitePage extends CommonObject
{
/**
* @ var string Id to identify managed objects
*/
public $element = 'websitepage' ;
/**
* @ var string Name of table without prefix where object is stored
*/
public $table_element = 'website_page' ;
2017-10-26 02:55:43 +02:00
/**
2017-11-03 15:56:16 +01:00
* @ var string String with name of icon for websitepage . Must be the part after the 'object_' into object_myobject . png
2017-10-26 02:55:43 +02:00
*/
public $picto = 'label' ;
2016-04-19 11:02:55 +02:00
/**
*/
2016-04-27 09:41:42 +02:00
2016-04-19 11:02:55 +02:00
public $fk_website ;
public $pageurl ;
2018-02-28 14:36:22 +01:00
public $aliasalt ;
2017-12-02 13:24:21 +01:00
public $type_container ;
2016-04-19 11:02:55 +02:00
public $title ;
public $description ;
public $keywords ;
2017-10-02 00:08:00 +02:00
public $htmlheader ;
2016-04-19 11:02:55 +02:00
public $content ;
2018-02-14 20:33:48 +01:00
public $grabbed_from ;
2016-04-19 11:02:55 +02:00
public $status ;
2016-04-21 03:18:42 +02:00
public $date_creation ;
public $date_modification ;
2016-04-19 11:02:55 +02:00
2018-02-14 20:33:48 +01:00
2017-07-28 14:54:13 +02:00
// BEGIN MODULEBUILDER PROPERTIES
2016-04-19 11:02:55 +02:00
/**
2017-07-28 14:54:13 +02:00
* @ var array Array with all fields and their property . Do not use it as a static var . It may be modified by constructor .
*/
public $fields = array (
2017-12-02 13:24:21 +01:00
'rowid' => array ( 'type' => 'integer' , 'label' => 'TechnicalID' , 'enabled' => 1 , 'visible' =>- 1 , 'notnull' => 1 , 'index' => 1 , 'position' => 1 , 'comment' => 'Id' ),
2018-02-28 14:36:22 +01:00
'pageurl' => array ( 'type' => 'varchar(16)' , 'label' => 'WEBSITE_PAGENAME' , 'enabled' => 1 , 'visible' => 1 , 'notnull' => 1 , 'index' => 1 , 'position' => 10 , 'searchall' => 1 , 'comment' => 'Ref/alias of page' ),
'aliasalt' => array ( 'type' => 'varchar(255)' , 'label' => 'AliasAlt' , 'enabled' => 1 , 'visible' => 1 , 'notnull' => 1 , 'index' => 0 , 'position' => 11 , 'searchall' => 0 , 'comment' => 'Alias alternative of page' ),
'type_container' => array ( 'type' => 'varchar(16)' , 'label' => 'Type' , 'enabled' => 1 , 'visible' => 1 , 'notnull' => 1 , 'index' => 0 , 'position' => 12 , 'comment' => 'Type of container' ),
2017-12-02 13:24:21 +01:00
'title' => array ( 'type' => 'varchar(255)' , 'label' => 'Label' , 'enabled' => 1 , 'visible' => 1 , 'position' => 30 , 'searchall' => 1 ),
'description' => array ( 'type' => 'varchar(255)' , 'label' => 'Description' , 'enabled' => 1 , 'visible' => 1 , 'position' => 30 , 'searchall' => 1 ),
'keywords' => array ( 'type' => 'varchar(255)' , 'label' => 'Keywords' , 'enabled' => 1 , 'visible' => 1 , 'position' => 45 , 'searchall' => 0 ),
'lang' => array ( 'type' => 'varchar(6)' , 'label' => 'Lang' , 'enabled' => 1 , 'visible' => 1 , 'position' => 45 , 'searchall' => 0 ),
2017-07-28 14:54:13 +02:00
//'status' =>array('type'=>'integer', 'label'=>'Status', 'enabled'=>1, 'visible'=>1, 'index'=>true, 'position'=>1000),
2017-12-02 13:24:21 +01:00
'fk_website' => array ( 'type' => 'integer' , 'label' => 'WebsiteId' , 'enabled' => 1 , 'visible' => 1 , 'notnull' => 1 , 'position' => 40 , 'searchall' => 0 , 'foreignkey' => 'websitepage.rowid' ),
'fk_page' => array ( 'type' => 'integer' , 'label' => 'ParentPageId' , 'enabled' => 1 , 'visible' => 1 , 'notnull' =>- 1 , 'position' => 45 , 'searchall' => 0 , 'foreignkey' => 'website.rowid' ),
'htmlheader' => array ( 'type' => 'text' , 'label' => 'HtmlHeader' , 'enabled' => 1 , 'visible' => 0 , 'position' => 50 , 'searchall' => 0 ),
'content' => array ( 'type' => 'mediumtext' , 'label' => 'Content' , 'enabled' => 1 , 'visible' => 0 , 'position' => 51 , 'searchall' => 0 ),
'grabbed_from' => array ( 'type' => 'varchar(255)' , 'label' => 'GrabbedFrom' , 'enabled' => 1 , 'visible' => 1 , 'index' => 1 , 'position' => 400 , 'comment' => 'URL page content was grabbed from' ),
'date_creation' => array ( 'type' => 'datetime' , 'label' => 'DateCreation' , 'enabled' => 1 , 'visible' =>- 1 , 'notnull' => 1 , 'position' => 500 ),
'tms' => array ( 'type' => 'timestamp' , 'label' => 'DateModification' , 'enabled' => 1 , 'visible' =>- 1 , 'notnull' => 1 , 'position' => 501 ),
2017-10-22 16:45:18 +02:00
//'date_valid' =>array('type'=>'datetime', 'label'=>'DateValidation', 'enabled'=>1, 'visible'=>-1, 'position'=>502),
//'fk_user_creat' =>array('type'=>'integer', 'label'=>'UserAuthor', 'enabled'=>1, 'visible'=>-1, 'notnull'=>true, 'position'=>510),
//'fk_user_modif' =>array('type'=>'integer', 'label'=>'UserModif', 'enabled'=>1, 'visible'=>-1, 'position'=>511),
//'fk_user_valid' =>array('type'=>'integer', 'label'=>'UserValidation', 'enabled'=>1, 'visible'=>-1, 'position'=>512),
2017-12-02 13:24:21 +01:00
'import_key' => array ( 'type' => 'varchar(14)' , 'label' => 'ImportId' , 'enabled' => 1 , 'visible' =>- 1 , 'index' => 1 , 'position' => 1000 , 'notnull' =>- 1 ),
2017-07-28 14:54:13 +02:00
);
// END MODULEBUILDER PROPERTIES
2016-04-27 09:41:42 +02:00
2016-04-19 11:02:55 +02:00
/**
* Constructor
*
* @ param DoliDb $db Database handler
*/
public function __construct ( DoliDB $db )
{
$this -> db = $db ;
}
/**
* Create object into database
*
* @ param User $user User that creates
* @ param bool $notrigger false = launch triggers after , true = disable triggers
2017-08-20 18:50:51 +02:00
* @ return int < 0 if KO , Id of created object if OK
2016-04-19 11:02:55 +02:00
*/
public function create ( User $user , $notrigger = false )
{
2018-02-19 14:56:37 +01:00
$this -> description = dol_trunc ( $this -> description , 255 , 'right' , 'utf-8' , 1 );
$this -> keywords = dol_trunc ( $this -> keywords , 255 , 'right' , 'utf-8' , 1 );
2018-02-28 14:36:22 +01:00
if ( $this -> aliasalt ) $this -> aliasalt = ',' . preg_replace ( '/,+$/' , '' , preg_replace ( '/^,+/' , '' , $this -> aliasalt )) . ',' ; // content in database must be ',xxx,...,yyy,'
2018-02-19 14:56:37 +01:00
2017-08-20 18:50:51 +02:00
return $this -> createCommon ( $user , $notrigger );
2016-04-19 11:02:55 +02:00
}
/**
* Load object in memory from the database
*
2018-02-28 14:36:22 +01:00
* @ param int $id Id object . If this is 0 , the value into $page will be used . If not found of $page not defined , the default page of website_id will be used or the first page found if not set .
* @ param string $website_id Web site id ( page name must also be filled if this parameter is used )
* @ param string $page Page name ( website id must also be filled if this parameter is used )
* @ param string $aliasalt Alternative alias to search page ( slow )
2016-04-19 11:02:55 +02:00
*
* @ return int < 0 if KO , 0 if not found , > 0 if OK
*/
2018-02-28 14:36:22 +01:00
public function fetch ( $id , $website_id = null , $page = null , $aliasalt = null )
2016-04-19 11:02:55 +02:00
{
dol_syslog ( __METHOD__ , LOG_DEBUG );
$sql = 'SELECT' ;
$sql .= ' t.rowid,' ;
$sql .= " t.fk_website, " ;
2017-12-02 13:24:21 +01:00
$sql .= ' t.type_container,' ;
2016-04-19 11:02:55 +02:00
$sql .= " t.pageurl, " ;
2018-02-28 14:36:22 +01:00
$sql .= " t.aliasalt, " ;
2016-04-19 11:02:55 +02:00
$sql .= " t.title, " ;
$sql .= " t.description, " ;
$sql .= " t.keywords, " ;
2017-10-02 00:08:00 +02:00
$sql .= " t.htmlheader, " ;
2016-04-19 11:02:55 +02:00
$sql .= " t.content, " ;
2017-07-22 20:01:29 +02:00
$sql .= " t.lang, " ;
$sql .= " t.fk_page, " ;
2016-04-19 11:02:55 +02:00
$sql .= " t.status, " ;
2017-08-20 19:47:55 +02:00
$sql .= " t.grabbed_from, " ;
2016-04-19 11:02:55 +02:00
$sql .= " t.date_creation, " ;
2017-01-03 11:22:03 +01:00
$sql .= " t.tms as date_modification " ;
2016-04-19 11:02:55 +02:00
$sql .= ' FROM ' . MAIN_DB_PREFIX . $this -> table_element . ' as t' ;
2017-05-30 18:50:54 +02:00
//$sql .= ' WHERE entity IN ('.getEntity('website').')'; // entity is on website level
2017-04-28 13:10:08 +02:00
$sql .= ' WHERE 1 = 1' ;
2017-07-21 02:30:02 +02:00
if ( $id > 0 )
{
2017-04-28 13:10:08 +02:00
$sql .= ' AND t.rowid = ' . $id ;
2016-04-19 11:02:55 +02:00
}
2017-07-21 02:30:02 +02:00
else
{
if ( null !== $website_id ) {
$sql .= " AND t.fk_website = ' " . $this -> db -> escape ( $website_id ) . " ' " ;
2018-02-28 14:36:22 +01:00
if ( $page ) $sql .= " AND t.pageurl = ' " . $this -> db -> escape ( $page ) . " ' " ;
if ( $aliasalt ) $sql .= " AND t.aliasalt LIKE '%, " . $this -> db -> escape ( $aliasalt ) . " ,%' " ;
2017-07-21 02:30:02 +02:00
}
}
2017-04-28 13:10:08 +02:00
$sql .= $this -> db -> plimit ( 1 );
2017-07-02 23:38:19 +02:00
2016-04-19 11:02:55 +02:00
$resql = $this -> db -> query ( $sql );
if ( $resql ) {
$numrows = $this -> db -> num_rows ( $resql );
if ( $numrows ) {
$obj = $this -> db -> fetch_object ( $resql );
$this -> id = $obj -> rowid ;
2016-04-27 09:41:42 +02:00
2016-04-19 11:02:55 +02:00
$this -> fk_website = $obj -> fk_website ;
2017-12-02 13:24:21 +01:00
$this -> type_container = $obj -> type_container ;
2016-04-19 11:02:55 +02:00
$this -> pageurl = $obj -> pageurl ;
2018-02-28 14:36:22 +01:00
$this -> aliasalt = preg_replace ( '/,+$/' , '' , preg_replace ( '/^,+/' , '' , $obj -> aliasalt ));
2016-04-19 11:02:55 +02:00
$this -> title = $obj -> title ;
$this -> description = $obj -> description ;
$this -> keywords = $obj -> keywords ;
2017-10-02 00:08:00 +02:00
$this -> htmlheader = $obj -> htmlheader ;
2016-04-19 11:02:55 +02:00
$this -> content = $obj -> content ;
2017-07-22 20:01:29 +02:00
$this -> lang = $obj -> lang ;
$this -> fk_page = $obj -> fk_page ;
2016-04-19 11:02:55 +02:00
$this -> status = $obj -> status ;
2017-08-20 19:47:55 +02:00
$this -> grabbed_from = $obj -> grabbed_from ;
2016-04-19 11:02:55 +02:00
$this -> date_creation = $this -> db -> jdate ( $obj -> date_creation );
$this -> date_modification = $this -> db -> jdate ( $obj -> date_modification );
}
$this -> db -> free ( $resql );
if ( $numrows ) {
return 1 ;
} else {
return 0 ;
}
} else {
$this -> errors [] = 'Error ' . $this -> db -> lasterror ();
dol_syslog ( __METHOD__ . ' ' . join ( ',' , $this -> errors ), LOG_ERR );
return - 1 ;
}
}
/**
* Load object in memory from the database
*
2016-05-07 16:38:32 +02:00
* @ param string $websiteid Web site
* @ param string $sortorder Sort Order
* @ param string $sortfield Sort field
* @ param int $limit limit
* @ param int $offset Offset
* @ param array $filter Filter array
* @ param string $filtermode Filter mode ( AND or OR )
* @ return array | int int < 0 if KO , array of pages if OK
2016-04-19 11:02:55 +02:00
*/
2016-05-07 16:38:32 +02:00
public function fetchAll ( $websiteid , $sortorder = '' , $sortfield = '' , $limit = 0 , $offset = 0 , array $filter = array (), $filtermode = 'AND' )
2016-04-19 11:02:55 +02:00
{
dol_syslog ( __METHOD__ , LOG_DEBUG );
2016-04-23 21:34:10 +02:00
$records = array ();
2016-04-27 09:41:42 +02:00
2016-04-19 11:02:55 +02:00
$sql = 'SELECT' ;
$sql .= ' t.rowid,' ;
$sql .= " t.fk_website, " ;
2017-12-02 13:24:21 +01:00
$sql .= " t.type_container, " ;
2016-04-19 11:02:55 +02:00
$sql .= " t.pageurl, " ;
2018-02-28 14:36:22 +01:00
$sql .= " t.aliasalt, " ;
2016-04-19 11:02:55 +02:00
$sql .= " t.title, " ;
$sql .= " t.description, " ;
$sql .= " t.keywords, " ;
2017-10-02 00:08:00 +02:00
$sql .= " t.htmlheader, " ;
2016-04-19 11:02:55 +02:00
$sql .= " t.content, " ;
2017-07-22 20:01:29 +02:00
$sql .= " t.lang, " ;
$sql .= " t.fk_page, " ;
2016-04-19 11:02:55 +02:00
$sql .= " t.status, " ;
2017-08-20 19:47:55 +02:00
$sql .= " t.grabbed_from, " ;
2016-04-19 11:02:55 +02:00
$sql .= " t.date_creation, " ;
2017-01-03 11:22:03 +01:00
$sql .= " t.tms as date_modification " ;
2016-04-19 11:02:55 +02:00
$sql .= ' FROM ' . MAIN_DB_PREFIX . $this -> table_element . ' as t' ;
2017-07-02 23:38:19 +02:00
$sql .= ' WHERE t.fk_website = ' . $websiteid ;
2016-04-19 11:02:55 +02:00
// Manage filter
$sqlwhere = array ();
if ( count ( $filter ) > 0 ) {
foreach ( $filter as $key => $value ) {
2016-04-27 09:41:42 +02:00
if ( $key == 't.rowid' || $key == 't.fk_website' ) {
2016-05-07 16:38:32 +02:00
$sqlwhere [] = $key . '=' . $value ;
2016-04-27 09:41:42 +02:00
} else {
2016-05-07 16:38:32 +02:00
$sqlwhere [] = $key . ' LIKE \'%' . $this -> db -> escape ( $value ) . '%\'' ;
2016-04-27 09:41:42 +02:00
}
2016-04-19 11:02:55 +02:00
}
}
if ( count ( $sqlwhere ) > 0 ) {
2016-04-23 21:34:10 +02:00
$sql .= ' AND ' . implode ( ' ' . $filtermode . ' ' , $sqlwhere );
2016-04-19 11:02:55 +02:00
}
2016-04-27 09:41:42 +02:00
2016-04-19 11:02:55 +02:00
if ( ! empty ( $sortfield )) {
$sql .= $this -> db -> order ( $sortfield , $sortorder );
}
if ( ! empty ( $limit )) {
2017-01-03 11:22:03 +01:00
$sql .= ' ' . $this -> db -> plimit ( $limit , $offset );
2016-04-19 11:02:55 +02:00
}
$resql = $this -> db -> query ( $sql );
if ( $resql ) {
$num = $this -> db -> num_rows ( $resql );
2016-04-27 09:41:42 +02:00
while ( $obj = $this -> db -> fetch_object ( $resql ))
2016-04-23 21:34:10 +02:00
{
2017-01-03 11:22:03 +01:00
$record = new self ( $this -> db );
2016-04-23 21:34:10 +02:00
$record -> id = $obj -> rowid ;
$record -> fk_website = $obj -> fk_website ;
2017-12-02 13:24:21 +01:00
$record -> type_container = $obj -> type_container ;
2016-04-23 21:34:10 +02:00
$record -> pageurl = $obj -> pageurl ;
2018-02-28 14:36:22 +01:00
$record -> aliasalt = preg_replace ( '/,+$/' , '' , preg_replace ( '/^,+/' , '' , $obj -> aliasalt ));
2016-04-23 21:34:10 +02:00
$record -> title = $obj -> title ;
$record -> description = $obj -> description ;
$record -> keywords = $obj -> keywords ;
2017-10-02 00:08:00 +02:00
$record -> htmlheader = $obj -> htmlheader ;
2016-04-23 21:34:10 +02:00
$record -> content = $obj -> content ;
2017-07-22 20:01:29 +02:00
$record -> lang = $obj -> lang ;
$record -> fk_page = $obj -> fk_page ;
2016-04-23 21:34:10 +02:00
$record -> status = $obj -> status ;
2017-08-20 19:47:55 +02:00
$record -> grabbed_from = $obj -> grabbed_from ;
2016-04-23 21:34:10 +02:00
$record -> date_creation = $this -> db -> jdate ( $obj -> date_creation );
$record -> date_modification = $this -> db -> jdate ( $obj -> date_modification );
2016-05-01 21:19:29 +02:00
//var_dump($record->id);
2016-04-23 21:34:10 +02:00
$records [ $record -> id ] = $record ;
2016-04-19 11:02:55 +02:00
}
$this -> db -> free ( $resql );
2016-04-23 21:34:10 +02:00
return $records ;
2016-04-19 11:02:55 +02:00
} else {
$this -> errors [] = 'Error ' . $this -> db -> lasterror ();
dol_syslog ( __METHOD__ . ' ' . join ( ',' , $this -> errors ), LOG_ERR );
2016-04-23 21:34:10 +02:00
return - 1 ;
2016-04-19 11:02:55 +02:00
}
}
/**
* Update object into database
*
* @ param User $user User that modifies
* @ param bool $notrigger false = launch triggers after , true = disable triggers
2017-08-20 19:47:55 +02:00
* @ return int < 0 if KO , > 0 if OK
2016-04-19 11:02:55 +02:00
*/
public function update ( User $user , $notrigger = false )
{
2018-02-28 14:36:22 +01:00
$this -> description = dol_trunc ( $this -> description , 255 , 'right' , 'utf-8' , 1 );
$this -> keywords = dol_trunc ( $this -> keywords , 255 , 'right' , 'utf-8' , 1 );
if ( $this -> aliasalt ) $this -> aliasalt = ',' . preg_replace ( '/,+$/' , '' , preg_replace ( '/^,+/' , '' , $this -> aliasalt )) . ',' ; // content in database must be ',xxx,...,yyy,'
2017-08-20 19:47:55 +02:00
return $this -> updateCommon ( $user , $notrigger );
2016-04-19 11:02:55 +02:00
}
/**
* Delete object in database
*
2017-08-20 18:50:51 +02:00
* @ param User $user User that deletes
* @ param bool $notrigger false = launch triggers after , true = disable triggers
* @ return int < 0 if KO , > 0 if OK
2016-04-19 11:02:55 +02:00
*/
public function delete ( User $user , $notrigger = false )
{
2017-10-07 02:29:27 +02:00
$result = $this -> deleteCommon ( $user , $trigger );
if ( $result > 0 )
{
$websiteobj = new Website ( $this -> db );
$result = $websiteobj -> fetch ( $this -> fk_website );
if ( $result > 0 )
{
global $dolibarr_main_data_root ;
2017-10-20 21:39:19 +02:00
$pathofwebsite = $dolibarr_main_data_root . '/website/' . $websiteobj -> ref ;
2017-10-07 02:29:27 +02:00
$filealias = $pathofwebsite . '/' . $this -> pageurl . '.php' ;
$filetpl = $pathofwebsite . '/page' . $this -> id . '.tpl.php' ;
dol_delete_file ( $filealias );
dol_delete_file ( $filetpl );
}
}
return $result ;
2016-04-19 11:02:55 +02:00
}
/**
* Load an object from its id and create a new one in database
*
2017-08-03 01:45:31 +02:00
* @ param User $user User making the clone
2017-07-22 20:01:29 +02:00
* @ param int $fromid Id of object to clone
* @ param string $newref New ref / alias of page
* @ param string $newlang New language
* @ param int $istranslation 1 = New page is a translation of the cloned page .
2017-07-23 16:20:53 +02:00
* @ param int $newwebsite 0 = Same web site , 1 = New web site
2017-08-21 00:40:45 +02:00
* @ return mixed New object created , < 0 if KO
2016-04-19 11:02:55 +02:00
*/
2017-08-03 01:45:31 +02:00
public function createFromClone ( User $user , $fromid , $newref , $newlang = '' , $istranslation = 0 , $newwebsite = 0 )
2016-04-19 11:02:55 +02:00
{
2017-08-03 01:45:31 +02:00
global $hookmanager , $langs ;
$error = 0 ;
2017-07-21 13:38:13 +02:00
2016-04-19 11:02:55 +02:00
dol_syslog ( __METHOD__ , LOG_DEBUG );
2017-07-21 13:38:13 +02:00
$object = new self ( $this -> db );
2016-04-19 11:02:55 +02:00
$this -> db -> begin ();
// Load source object
$object -> fetch ( $fromid );
// Reset object
$object -> id = 0 ;
// Clear fields
2017-07-22 20:01:29 +02:00
$object -> ref = $newref ;
$object -> pageurl = $newref ;
2018-02-28 14:36:22 +01:00
$object -> aliasalt = '' ;
2017-07-21 13:38:13 +02:00
$object -> title = $langs -> trans ( " CopyOf " ) . ' ' . $object -> title ;
2017-07-22 20:01:29 +02:00
if ( ! empty ( $newlang )) $object -> lang = $newlang ;
if ( $istranslation ) $object -> fk_page = $fromid ;
else $object -> fk_page = 0 ;
2017-07-23 16:20:53 +02:00
if ( ! empty ( $newwebsite )) $object -> fk_website = $newwebsite ;
2016-04-19 11:02:55 +02:00
// Create clone
2017-08-03 01:45:31 +02:00
$object -> context [ 'createfromclone' ] = 'createfromclone' ;
2016-04-19 11:02:55 +02:00
$result = $object -> create ( $user );
if ( $result < 0 ) {
2017-07-21 13:38:13 +02:00
$error ++ ;
$this -> error = $object -> error ;
2016-04-19 11:02:55 +02:00
$this -> errors = $object -> errors ;
dol_syslog ( __METHOD__ . ' ' . join ( ',' , $this -> errors ), LOG_ERR );
}
// End
if ( ! $error ) {
$this -> db -> commit ();
2017-08-21 00:40:45 +02:00
return $object ;
2016-04-19 11:02:55 +02:00
} else {
$this -> db -> rollback ();
2017-07-21 13:38:13 +02:00
return - 1 ;
2016-04-19 11:02:55 +02:00
}
}
/**
* Return a link to the user card ( with optionaly the picto )
* Use this -> id , this -> lastname , this -> firstname
*
* @ param int $withpicto Include picto in link ( 0 = No picto , 1 = Include picto into link , 2 = Only picto )
* @ param string $option On what the link point to
* @ param integer $notooltip 1 = Disable tooltip
* @ param int $maxlen Max length of visible user name
* @ param string $morecss Add more css on link
* @ return string String with URL
*/
function getNomUrl ( $withpicto = 0 , $option = '' , $notooltip = 0 , $maxlen = 24 , $morecss = '' )
{
global $langs , $conf , $db ;
global $dolibarr_main_authentication , $dolibarr_main_demo ;
global $menumanager ;
$result = '' ;
$companylink = '' ;
2016-04-21 03:18:42 +02:00
$label = '<u>' . $langs -> trans ( " Page " ) . '</u>' ;
2016-04-19 11:02:55 +02:00
$label .= '<div width="100%">' ;
$label .= '<b>' . $langs -> trans ( 'Ref' ) . ':</b> ' . $this -> ref ;
2017-10-26 02:55:43 +02:00
$linkstart = '<a href="' . DOL_URL_ROOT . '/website/card.php?id=' . $this -> id . '"' ;
$linkstart .= ( $notooltip ? '' : ' title="' . dol_escape_htmltag ( $label , 1 ) . '" class="classfortooltip' . ( $morecss ? ' ' . $morecss : '' ) . '"' );
$linkstart .= '>' ;
2016-04-19 11:02:55 +02:00
$linkend = '</a>' ;
2017-10-26 02:55:43 +02:00
$linkstart = $linkend = '' ;
2016-04-19 11:02:55 +02:00
if ( $withpicto )
{
2017-10-26 02:55:43 +02:00
$result .= ( $linkstart . img_object (( $notooltip ? '' : $label ), ( $this -> picto ? $this -> picto : 'generic' ), ( $notooltip ? '' : 'class="classfortooltip"' )) . $linkend );
if ( $withpicto != 2 ) $result .= ' ' ;
2016-04-19 11:02:55 +02:00
}
2017-10-26 02:55:43 +02:00
$result .= $linkstart . $this -> ref . $linkend ;
2016-04-19 11:02:55 +02:00
return $result ;
}
2016-04-27 09:41:42 +02:00
2016-04-19 11:02:55 +02:00
/**
* Retourne le libelle du status d ' un user ( actif , inactif )
*
* @ param int $mode 0 = libelle long , 1 = libelle court , 2 = Picto + Libelle court , 3 = Picto , 4 = Picto + Libelle long , 5 = Libelle court + Picto
* @ return string Label of status
*/
function getLibStatut ( $mode = 0 )
{
return $this -> LibStatut ( $this -> status , $mode );
}
/**
* Renvoi le libelle d ' un status donne
*
* @ param int $status Id status
* @ param int $mode 0 = libelle long , 1 = libelle court , 2 = Picto + Libelle court , 3 = Picto , 4 = Picto + Libelle long , 5 = Libelle court + Picto
* @ return string Label of status
*/
function LibStatut ( $status , $mode = 0 )
{
global $langs ;
if ( $mode == 0 )
{
$prefix = '' ;
if ( $status == 1 ) return $langs -> trans ( 'Enabled' );
if ( $status == 0 ) return $langs -> trans ( 'Disabled' );
}
if ( $mode == 1 )
{
if ( $status == 1 ) return $langs -> trans ( 'Enabled' );
if ( $status == 0 ) return $langs -> trans ( 'Disabled' );
}
if ( $mode == 2 )
{
if ( $status == 1 ) return img_picto ( $langs -> trans ( 'Enabled' ), 'statut4' ) . ' ' . $langs -> trans ( 'Enabled' );
if ( $status == 0 ) return img_picto ( $langs -> trans ( 'Disabled' ), 'statut5' ) . ' ' . $langs -> trans ( 'Disabled' );
}
if ( $mode == 3 )
{
if ( $status == 1 ) return img_picto ( $langs -> trans ( 'Enabled' ), 'statut4' );
if ( $status == 0 ) return img_picto ( $langs -> trans ( 'Disabled' ), 'statut5' );
}
if ( $mode == 4 )
{
if ( $status == 1 ) return img_picto ( $langs -> trans ( 'Enabled' ), 'statut4' ) . ' ' . $langs -> trans ( 'Enabled' );
if ( $status == 0 ) return img_picto ( $langs -> trans ( 'Disabled' ), 'statut5' ) . ' ' . $langs -> trans ( 'Disabled' );
}
if ( $mode == 5 )
{
if ( $status == 1 ) return $langs -> trans ( 'Enabled' ) . ' ' . img_picto ( $langs -> trans ( 'Enabled' ), 'statut4' );
if ( $status == 0 ) return $langs -> trans ( 'Disabled' ) . ' ' . img_picto ( $langs -> trans ( 'Disabled' ), 'statut5' );
}
}
2016-04-27 09:41:42 +02:00
2016-04-19 11:02:55 +02:00
/**
* Initialise object with example values
* Id must be 0 if object instance is a specimen
*
* @ return void
*/
public function initAsSpecimen ()
{
$this -> id = 0 ;
2016-04-27 09:41:42 +02:00
2017-01-03 11:22:03 +01:00
$now = dol_now ();
2017-07-02 23:38:19 +02:00
2016-04-19 11:02:55 +02:00
$this -> fk_website = '' ;
2017-12-02 13:24:21 +01:00
$this -> type_container = 'page' ;
$this -> pageurl = 'specimen' ;
2018-02-28 14:36:22 +01:00
$this -> aliasalt = 'specimenalt' ;
2017-01-03 11:22:03 +01:00
$this -> title = 'My Page' ;
$this -> description = 'This is my page' ;
$this -> keywords = 'keyword1, keyword2' ;
2017-10-02 00:08:00 +02:00
$this -> htmlheader = '' ;
2017-01-03 11:22:03 +01:00
$this -> content = '<html><body>This is a html content</body></html>' ;
2016-04-19 11:02:55 +02:00
$this -> status = '' ;
2017-08-20 19:47:55 +02:00
$this -> grabbed_from = '' ;
2017-01-03 11:22:03 +01:00
$this -> date_creation = $now - ( 24 * 30 * 3600 );
$this -> date_modification = $now - ( 24 * 7 * 3600 );
2016-04-19 11:02:55 +02:00
}
}