dolibarr  17.0.4
websitepage.class.php
Go to the documentation of this file.
1 <?php
2 /* Copyright (C) 2007-2018 Laurent Destailleur <eldy@users.sourceforge.net>
3  * Copyright (C) 2014 Juanjo Menent <jmenent@2byte.es>
4  * Copyright (C) 2015 Florian Henry <florian.henry@open-concept.pro>
5  * Copyright (C) 2015 Raphaël Doursenaud <rdoursenaud@gpcsolutions.fr>
6  * Copyright (C) 2020 Nicolas ZABOURI <info@inovea-conseil.com>
7  *
8  * This program is free software; you can redistribute it and/or modify
9  * it under the terms of the GNU General Public License as published by
10  * the Free Software Foundation; either version 3 of the License, or
11  * (at your option) any later version.
12  *
13  * This program is distributed in the hope that it will be useful,
14  * but WITHOUT ANY WARRANTY; without even the implied warranty of
15  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16  * GNU General Public License for more details.
17  *
18  * You should have received a copy of the GNU General Public License
19  * along with this program. If not, see <https://www.gnu.org/licenses/>.
20  */
21 
28 // Put here all includes required by your class file
29 require_once DOL_DOCUMENT_ROOT.'/core/class/commonobject.class.php';
30 //require_once DOL_DOCUMENT_ROOT . '/societe/class/societe.class.php';
31 //require_once DOL_DOCUMENT_ROOT . '/product/class/product.class.php';
32 
37 {
41  public $element = 'websitepage';
42 
46  public $table_element = 'website_page';
47 
51  public $picto = 'file-code';
52 
53 
57  public $fk_website;
58 
59  public $fk_page; // If translation of another page
60 
61  public $pageurl;
62  public $aliasalt;
63  public $type_container;
64 
68  public $title;
72  public $description;
76  public $image;
80  public $keywords;
84  public $lang;
85 
86  public $allowed_in_frames;
87  public $htmlheader;
88  public $content;
89  public $grabbed_from;
90 
94  public $status;
95 
99  public $date_creation;
100 
104  public $date_modification;
105 
109  public $author_alias;
110 
114  public $object_type;
115 
119  public $fk_object;
120 
121  const STATUS_DRAFT = 0; // offline
122  const STATUS_VALIDATED = 1; // online
123 
124 
149  // BEGIN MODULEBUILDER PROPERTIES
153  public $fields = array(
154  'rowid' =>array('type'=>'integer', 'label'=>'TechnicalID', 'enabled'=>1, 'visible'=>-1, 'notnull'=>1, 'index'=>1, 'position'=>1, 'comment'=>'Id'),
155  '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'),
156  'aliasalt' =>array('type'=>'varchar(255)', 'label'=>'AliasAlt', 'enabled'=>1, 'visible'=>1, 'notnull'=>1, 'index'=>0, 'position'=>11, 'searchall'=>0, 'comment'=>'Alias alternative of page'),
157  'type_container' =>array('type'=>'varchar(16)', 'label'=>'Type', 'enabled'=>1, 'visible'=>1, 'notnull'=>1, 'index'=>0, 'position'=>12, 'comment'=>'Type of container'),
158  'title' =>array('type'=>'varchar(255)', 'label'=>'Label', 'enabled'=>1, 'visible'=>1, 'position'=>30, 'searchall'=>1, 'help'=>'UseTextBetween5And70Chars'),
159  'description' =>array('type'=>'varchar(255)', 'label'=>'Description', 'enabled'=>1, 'visible'=>1, 'position'=>30, 'searchall'=>1),
160  'image' =>array('type'=>'varchar(255)', 'label'=>'Image', 'enabled'=>1, 'visible'=>1, 'position'=>32, 'searchall'=>0, 'help'=>'Relative path of media. Used if Type is "blogpost"'),
161  'keywords' =>array('type'=>'varchar(255)', 'label'=>'Keywords', 'enabled'=>1, 'visible'=>1, 'position'=>45, 'searchall'=>0),
162  'lang' =>array('type'=>'varchar(6)', 'label'=>'Lang', 'enabled'=>1, 'notnull'=>-1, 'visible'=>1, 'position'=>45, 'searchall'=>0),
163  //'status' =>array('type'=>'integer', 'label'=>'Status', 'enabled'=>1, 'visible'=>1, 'index'=>true, 'position'=>1000),
164  'fk_website' =>array('type'=>'integer', 'label'=>'WebsiteId', 'enabled'=>1, 'visible'=>1, 'notnull'=>1, 'position'=>40, 'searchall'=>0, 'foreignkey'=>'websitepage.rowid'),
165  'fk_page' =>array('type'=>'integer', 'label'=>'ParentPageId', 'enabled'=>1, 'visible'=>1, 'notnull'=>-1, 'position'=>45, 'searchall'=>0, 'foreignkey'=>'website.rowid'),
166  'allowed_in_frames' =>array('type'=>'integer', 'label'=>'AllowedInFrames', 'enabled'=>1, 'visible'=>-1, 'position'=>48, 'searchall'=>0, 'default'=>0),
167  'htmlheader' =>array('type'=>'text', 'label'=>'HtmlHeader', 'enabled'=>1, 'visible'=>0, 'position'=>50, 'searchall'=>0),
168  'content' =>array('type'=>'mediumtext', 'label'=>'Content', 'enabled'=>1, 'visible'=>0, 'position'=>51, 'searchall'=>0),
169  'grabbed_from' =>array('type'=>'varchar(255)', 'label'=>'GrabbedFrom', 'enabled'=>1, 'visible'=>1, 'index'=>1, 'position'=>400, 'comment'=>'URL page content was grabbed from'),
170  'date_creation' =>array('type'=>'datetime', 'label'=>'DateCreation', 'enabled'=>1, 'visible'=>-1, 'notnull'=>1, 'position'=>500),
171  'tms' =>array('type'=>'timestamp', 'label'=>'DateModification', 'enabled'=>1, 'visible'=>-1, 'notnull'=>1, 'position'=>501),
172  //'date_valid' =>array('type'=>'datetime', 'label'=>'DateValidation', 'enabled'=>1, 'visible'=>-1, 'position'=>502),
173  'fk_user_creat' =>array('type'=>'integer', 'label'=>'UserAuthor', 'enabled'=>1, 'visible'=>-1, 'notnull'=>true, 'position'=>510),
174  'author_alias' =>array('type'=>'varchar(64)', 'label'=>'AuthorAlias', 'enabled'=>1, 'visible'=>-1, 'index'=>0, 'position'=>511, 'comment'=>'Author alias'),
175  'fk_user_modif' =>array('type'=>'integer', 'label'=>'UserModif', 'enabled'=>1, 'visible'=>-1, 'position'=>512),
176  //'fk_user_valid' =>array('type'=>'integer', 'label'=>'UserValidation', 'enabled'=>1, 'visible'=>-1, 'position'=>512),
177  'import_key' =>array('type'=>'varchar(14)', 'label'=>'ImportId', 'enabled'=>1, 'visible'=>-1, 'index'=>1, 'position'=>1000, 'notnull'=>-1),
178  'object_type' => array('type' => 'varchar(255)', 'label' => 'ObjectType', 'enabled'=>1, 'visible'=>0, 'position'=>46, 'searchall'=>0, 'help'=>''),
179  'fk_object' => array('type' => 'varchar(255)', 'label' => 'ObjectId', 'enabled'=>1, 'visible'=>0, 'position'=>47, 'searchall'=>0, 'help'=>'')
180  );
181  // END MODULEBUILDER PROPERTIES
182 
183 
184  // If this object has a subtable with lines
185 
186  // /**
187  // * @var string Name of subtable line
188  // */
189  //public $table_element_line = 'mymodule_myobjectline';
190 
194  public $fk_element = 'fk_website_page';
195 
196  // /**
197  // * @var string Name of subtable class that manage subtable lines
198  // */
199  //public $class_element_line = 'MyObjectline';
200 
204  //protected $childtables=array();
205 
209  protected $childtablesoncascade = array('categorie_website_page');
210 
211 
212 
218  public function __construct(DoliDB $db)
219  {
220  $this->db = $db;
221  }
222 
230  public function create(User $user, $notrigger = false)
231  {
232  $this->description = dol_trunc($this->description, 255, 'right', 'utf-8', 1);
233  $this->keywords = dol_trunc($this->keywords, 255, 'right', 'utf-8', 1);
234  if ($this->aliasalt) {
235  $this->aliasalt = ','.preg_replace('/,+$/', '', preg_replace('/^,+/', '', $this->aliasalt)).','; // content in database must be ',xxx,...,yyy,'
236  }
237 
238  $this->pageurl = preg_replace('/[^a-z0-9\-\_]/i', '', $this->pageurl);
239  $this->pageurl = preg_replace('/\-\-+/', '-', $this->pageurl);
240  $this->pageurl = preg_replace('/^\-/', '', $this->pageurl);
241 
242  // Remove spaces and be sure we have main language only
243  $this->lang = preg_replace('/[_-].*$/', '', trim($this->lang)); // en_US or en-US -> en
244 
245  return $this->createCommon($user, $notrigger);
246  }
247 
260  public function fetch($id, $website_id = null, $page = null, $aliasalt = null)
261  {
262  dol_syslog(__METHOD__, LOG_DEBUG);
263 
264  $sql = 'SELECT';
265  $sql .= ' t.rowid,';
266  $sql .= " t.fk_website,";
267  $sql .= ' t.type_container,';
268  $sql .= " t.pageurl,";
269  $sql .= " t.aliasalt,";
270  $sql .= " t.title,";
271  $sql .= " t.description,";
272  $sql .= " t.image,";
273  $sql .= " t.keywords,";
274  $sql .= " t.htmlheader,";
275  $sql .= " t.content,";
276  $sql .= " t.lang,";
277  $sql .= " t.fk_page,";
278  $sql .= " t.allowed_in_frames,";
279  $sql .= " t.status,";
280  $sql .= " t.grabbed_from,";
281  $sql .= " t.date_creation,";
282  $sql .= " t.tms as date_modification,";
283  $sql .= " t.fk_user_creat,";
284  $sql .= " t.author_alias,";
285  $sql .= " t.fk_user_modif,";
286  $sql .= " t.import_key,";
287  $sql .= " t.object_type,";
288  $sql .= " t.fk_object";
289  $sql .= ' FROM '.MAIN_DB_PREFIX.$this->table_element.' as t';
290  //$sql .= ' WHERE entity IN ('.getEntity('website').')'; // entity is on website level
291  $sql .= ' WHERE 1 = 1';
292  if ($id > 0) {
293  $sql .= ' AND t.rowid = '.((int) $id);
294  } else {
295  if ($id < 0) {
296  $sql .= ' AND t.rowid <> '.abs($id);
297  }
298  if (null !== $website_id) {
299  $sql .= " AND t.fk_website = '".$this->db->escape($website_id)."'";
300  if ($page) {
301  $pagetouse = $page;
302  $langtouse = '';
303  $tmppage = explode('/', $page);
304  if (!empty($tmppage[1])) {
305  $pagetouse = $tmppage[1];
306  if (strlen($tmppage[0])) {
307  $langtouse = $tmppage[0];
308  }
309  }
310  $sql .= " AND t.pageurl = '".$this->db->escape($pagetouse)."'";
311  if ($langtouse) {
312  $sql .= " AND t.lang = '".$this->db->escape($langtouse)."'";
313  }
314  }
315  if ($aliasalt) {
316  $sql .= " AND (t.aliasalt LIKE '%,".$this->db->escape($aliasalt).",%' OR t.aliasalt LIKE '%, ".$this->db->escape($aliasalt).",%')";
317  }
318  }
319  }
320  $sql .= $this->db->plimit(1);
321 
322  $resql = $this->db->query($sql);
323  if ($resql) {
324  $numrows = $this->db->num_rows($resql);
325  if ($numrows) {
326  $obj = $this->db->fetch_object($resql);
327 
328  $this->id = $obj->rowid;
329 
330  $this->fk_website = $obj->fk_website;
331  $this->type_container = $obj->type_container;
332 
333  $this->pageurl = $obj->pageurl;
334  $this->ref = $obj->pageurl;
335  $this->aliasalt = preg_replace('/,+$/', '', preg_replace('/^,+/', '', $obj->aliasalt));
336 
337  $this->title = $obj->title;
338  $this->description = $obj->description;
339  $this->image = $obj->image;
340  $this->keywords = $obj->keywords;
341  $this->htmlheader = $obj->htmlheader;
342  $this->content = $obj->content;
343  $this->lang = $obj->lang;
344  $this->fk_page = $obj->fk_page;
345  $this->allowed_in_frames = $obj->allowed_in_frames;
346  $this->status = $obj->status;
347  $this->grabbed_from = $obj->grabbed_from;
348  $this->date_creation = $this->db->jdate($obj->date_creation);
349  $this->date_modification = $this->db->jdate($obj->date_modification);
350  $this->fk_user_creat = $obj->fk_user_creat;
351  $this->author_alias = $obj->author_alias;
352  $this->fk_user_modif = $obj->fk_user_modif;
353  $this->import_key = $obj->import_key;
354  $this->object_type = $obj->object_type;
355  $this->fk_object = $obj->fk_object;
356  }
357  $this->db->free($resql);
358 
359  if ($numrows) {
360  return 1;
361  } else {
362  return 0;
363  }
364  } else {
365  $this->errors[] = 'Error '.$this->db->lasterror();
366  dol_syslog(__METHOD__.' '.join(',', $this->errors), LOG_ERR);
367 
368  return -1;
369  }
370  }
371 
384  public function fetchAll($websiteid, $sortorder = '', $sortfield = '', $limit = 0, $offset = 0, array $filter = array(), $filtermode = 'AND')
385  {
386  dol_syslog(__METHOD__, LOG_DEBUG);
387 
388  $records = array();
389 
390  $sql = 'SELECT';
391  $sql .= ' t.rowid,';
392  $sql .= " t.fk_website,";
393  $sql .= " t.type_container,";
394  $sql .= " t.pageurl,";
395  $sql .= " t.aliasalt,";
396  $sql .= " t.title,";
397  $sql .= " t.description,";
398  $sql .= " t.image,";
399  $sql .= " t.keywords,";
400  $sql .= " t.htmlheader,";
401  $sql .= " t.content,";
402  $sql .= " t.lang,";
403  $sql .= " t.fk_page,";
404  $sql .= " t.allowed_in_frames,";
405  $sql .= " t.status,";
406  $sql .= " t.grabbed_from,";
407  $sql .= " t.date_creation,";
408  $sql .= " t.tms as date_modification,";
409  $sql .= " t.fk_user_creat,";
410  $sql .= " t.author_alias,";
411  $sql .= " t.fk_user_modif,";
412  $sql .= " t.import_key,";
413  $sql .= " t.object_type,";
414  $sql .= " t.fk_object";
415  $sql .= ' FROM '.MAIN_DB_PREFIX.$this->table_element.' as t';
416  $sql .= ' WHERE t.fk_website = '.((int) $websiteid);
417  // Manage filter (same than into countAll)
418  $sqlwhere = array();
419  if (count($filter) > 0) {
420  foreach ($filter as $key => $value) {
421  if ($key == 't.rowid' || $key == 'rowid' || $key == 't.fk_website' || $key == 'fk_website' || $key == 'status' || $key == 't.status') {
422  $sqlwhere[] = $key." = ".((int) $value);
423  } elseif ($key == 'type_container' || $key == 't.type_container') {
424  $sqlwhere[] = $key." = '".$this->db->escape($value)."'";
425  } elseif ($key == 'lang' || $key == 't.lang') {
426  $listoflang = array();
427  $foundnull = 0;
428  foreach (explode(',', $value) as $tmpvalue) {
429  if ($tmpvalue == 'null') {
430  $foundnull++;
431  continue;
432  }
433  $listoflang[] = "'".$this->db->escape(substr(str_replace("'", '', $tmpvalue), 0, 2))."'";
434  }
435  $stringtouse = $key." IN (".$this->db->sanitize(join(',', $listoflang), 1).")";
436  if ($foundnull) {
437  $stringtouse = "(".$stringtouse." OR ".$key." IS NULL)";
438  }
439  $sqlwhere[] = $stringtouse;
440  } else {
441  $sqlwhere[] = $key." LIKE '%".$this->db->escape($value)."%'";
442  }
443  }
444  }
445  if (count($sqlwhere) > 0) {
446  $sql .= " AND (".implode(' '.$this->db->escape($filtermode).' ', $sqlwhere).')';
447  }
448 
449  if (!empty($sortfield)) {
450  $sql .= $this->db->order($sortfield, $sortorder);
451  }
452  if (!empty($limit)) {
453  $sql .= $this->db->plimit($limit, $offset);
454  }
455 
456  $resql = $this->db->query($sql);
457  if ($resql) {
458  $num = $this->db->num_rows($resql);
459 
460  while ($obj = $this->db->fetch_object($resql)) {
461  $record = new self($this->db);
462 
463  $record->id = $obj->rowid;
464  $record->fk_website = $obj->fk_website;
465  $record->type_container = $obj->type_container;
466  $record->pageurl = $obj->pageurl;
467  $record->aliasalt = preg_replace('/,+$/', '', preg_replace('/^,+/', '', $obj->aliasalt));
468  $record->title = $obj->title;
469  $record->description = $obj->description;
470  $record->image = $obj->image;
471  $record->keywords = $obj->keywords;
472  $record->htmlheader = $obj->htmlheader;
473  $record->content = $obj->content;
474  $record->lang = $obj->lang;
475  $record->fk_page = $obj->fk_page;
476  $record->allowed_in_frames = $obj->allowed_in_frames;
477  $record->status = $obj->status;
478  $record->grabbed_from = $obj->grabbed_from;
479  $record->date_creation = $this->db->jdate($obj->date_creation);
480  $record->date_modification = $this->db->jdate($obj->date_modification);
481  $record->fk_user_creat = $obj->fk_user_creat;
482  $record->author_alias = $obj->author_alias;
483  $record->fk_user_modif = $obj->fk_user_modif;
484  $record->import_key = $obj->import_key;
485  $record->object_type = $obj->object_type;
486  $record->fk_object = $obj->fk_object;
487  //var_dump($record->id);
488  $records[$record->id] = $record;
489  }
490  $this->db->free($resql);
491 
492  return $records;
493  } else {
494  $this->error = 'Error '.$this->db->lasterror();
495  $this->errors[] = $this->error;
496  dol_syslog(__METHOD__.' '.join(',', $this->errors), LOG_ERR);
497 
498  return -1;
499  }
500  }
501 
510  public function countAll($websiteid, array $filter = array(), $filtermode = 'AND')
511  {
512  dol_syslog(__METHOD__, LOG_DEBUG);
513 
514  $result = 0;
515 
516  $sql = 'SELECT COUNT(t.rowid) as nb';
517  $sql .= ' FROM '.MAIN_DB_PREFIX.$this->table_element.' as t';
518  $sql .= ' WHERE t.fk_website = '.((int) $websiteid);
519  // Manage filter (same than into fetchAll)
520  $sqlwhere = array();
521  if (count($filter) > 0) {
522  foreach ($filter as $key => $value) {
523  if ($key == 't.rowid' || $key == 't.fk_website' || $key == 'status') {
524  $sqlwhere[] = $key." = ".((int) $value);
525  } elseif ($key == 'type_container') {
526  $sqlwhere[] = $key." = '".$this->db->escape($value)."'";
527  } elseif ($key == 'lang' || $key == 't.lang') {
528  $listoflang = array();
529  $foundnull = 0;
530  foreach (explode(',', $value) as $tmpvalue) {
531  if ($tmpvalue == 'null') {
532  $foundnull++;
533  continue;
534  }
535  $listoflang[] = "'".$this->db->escape(substr(str_replace("'", '', $tmpvalue), 0, 2))."'";
536  }
537  $stringtouse = $key." IN (".$this->db->sanitize(join(',', $listoflang), 1).")";
538  if ($foundnull) {
539  $stringtouse = "(".$stringtouse." OR ".$key." IS NULL)";
540  }
541  $sqlwhere[] = $stringtouse;
542  } else {
543  $sqlwhere[] = $key." LIKE '%".$this->db->escape($value)."%'";
544  }
545  }
546  }
547  if (count($sqlwhere) > 0) {
548  $sql .= ' AND ('.implode(' '.$this->db->escape($filtermode).' ', $sqlwhere).')';
549  }
550 
551  $resql = $this->db->query($sql);
552  if ($resql) {
553  $obj = $this->db->fetch_object($resql);
554  if ($obj) {
555  $result = $obj->nb;
556  }
557 
558  $this->db->free($resql);
559 
560  return $result;
561  } else {
562  $this->error = 'Error '.$this->db->lasterror();
563  $this->errors[] = $this->error;
564  dol_syslog(__METHOD__.' '.join(',', $this->errors), LOG_ERR);
565 
566  return -1;
567  }
568  }
569 
577  public function update(User $user, $notrigger = false)
578  {
579  $this->description = dol_trunc($this->description, 255, 'right', 'utf-8', 1);
580  $this->keywords = dol_trunc($this->keywords, 255, 'right', 'utf-8', 1);
581  if ($this->aliasalt) {
582  $this->aliasalt = ','.preg_replace('/,+$/', '', preg_replace('/^,+/', '', $this->aliasalt)).','; // content in database must be ',xxx,...,yyy,'
583  }
584 
585  $this->pageurl = preg_replace('/[^a-z0-9\-\_]/i', '', $this->pageurl);
586  $this->pageurl = preg_replace('/\-\-+/', '-', $this->pageurl);
587  $this->pageurl = preg_replace('/^\-/', '', $this->pageurl);
588 
589  // Remove spaces and be sure we have main language only
590  $this->lang = preg_replace('/[_-].*$/', '', trim($this->lang)); // en_US or en-US -> en
591 
592  if ($this->fk_page > 0) {
593  if (empty($this->lang)) {
594  $this->error = "ErrorLanguageMandatoryIfPageSetAsTranslationOfAnother";
595  return -1;
596  }
597  $tmppage = new WebsitePage($this->db);
598  $tmppage->fetch($this->fk_page);
599  if ($tmppage->lang == $this->lang) {
600  $this->error = "ErrorLanguageOfTranslatedPageIsSameThanThisPage";
601  return -1;
602  }
603  }
604 
605  return $this->updateCommon($user, $notrigger);
606  }
607 
615  public function delete(User $user, $notrigger = false)
616  {
617  global $conf;
618 
619  $error = 0;
620 
621  // Delete all child tables
622  if (!$error) {
623  foreach ($this->childtablesoncascade as $table) {
624  $sql = "DELETE FROM ".MAIN_DB_PREFIX.$table;
625  $sql .= " WHERE fk_website_page = ".(int) $this->id;
626 
627  $result = $this->db->query($sql);
628  if (!$result) {
629  $error++;
630  $this->errors[] = $this->db->lasterror();
631  break;
632  }
633  }
634  }
635 
636  if (!$error) {
637  $result = $this->deleteCommon($user, $notrigger);
638  if ($result <= 0) {
639  $error++;
640  }
641  }
642 
643  if (!$error) {
644  $websiteobj = new Website($this->db);
645  $result = $websiteobj->fetch($this->fk_website);
646 
647  if ($result > 0) {
648  global $dolibarr_main_data_root;
649  $pathofwebsite = $dolibarr_main_data_root.($conf->entity > 1 ? '/'.$conf->entity : '').'/website/'.$websiteobj->ref;
650 
651  $filealias = $pathofwebsite.'/'.$this->pageurl.'.php';
652  $filetpl = $pathofwebsite.'/page'.$this->id.'.tpl.php';
653 
654  dol_delete_file($filealias);
655  dol_delete_file($filetpl);
656  } else {
657  $this->error = $websiteobj->error;
658  $this->errors = $websiteobj->errors;
659  }
660  }
661 
662  if (!$error) {
663  return 1;
664  } else {
665  return -1;
666  }
667  }
668 
681  public function createFromClone(User $user, $fromid, $newref, $newlang = '', $istranslation = 0, $newwebsite = 0, $newtitle = '')
682  {
683  global $hookmanager, $langs;
684 
685  $now = dol_now();
686  $error = 0;
687 
688  dol_syslog(__METHOD__, LOG_DEBUG);
689 
690  $object = new self($this->db);
691 
692  // Clean parameters
693  if (empty($newref) && !empty($newtitle)) {
694  $newref = strtolower(dol_sanitizeFileName(preg_replace('/\s+/', '-', $newtitle), '-', 1));
695  }
696 
697  // Check parameters
698  if (empty($newref)) {
699  $langs->load("errors");
700  $this->error = $langs->trans("ErrorFieldRequired", $langs->transnoentitiesnoconv("WEBSITE_TITLE"));
701  return -1;
702  }
703 
704  $this->db->begin();
705 
706  // Load source object
707  $object->fetch($fromid);
708  // Reset object
709  $object->id = 0;
710 
711  // Clear fields
712  $object->ref = $newref;
713  $object->pageurl = $newref;
714  $object->aliasalt = '';
715  $object->fk_user_creat = $user->id;
716  $object->author_alias = '';
717  $object->date_creation = $now;
718  $object->title = ($newtitle == '1' ? $object->title : ($newtitle ? $newtitle : $object->title));
719  $object->description = $object->title;
720  if (!empty($newlang)) {
721  $object->lang = $newlang;
722  }
723  if ($istranslation) {
724  $object->fk_page = $fromid;
725  } else {
726  $object->fk_page = 0;
727  }
728  if (!empty($newwebsite)) {
729  $object->fk_website = $newwebsite;
730  }
731  $object->import_key = '';
732  $object->status = self::STATUS_DRAFT;
733 
734  // Create clone
735  $object->context['createfromclone'] = 'createfromclone';
736  $result = $object->create($user);
737  if ($result < 0) {
738  $error++;
739  $this->error = $object->error;
740  $this->errors = $object->errors;
741  dol_syslog(__METHOD__.' '.join(',', $this->errors), LOG_ERR);
742  }
743 
744  unset($object->context['createfromclone']);
745 
746  // End
747  if (!$error) {
748  $this->db->commit();
749 
750  return $object;
751  } else {
752  $this->db->rollback();
753 
754  return -1;
755  }
756  }
757 
769  public function getNomUrl($withpicto = 0, $option = '', $notooltip = 0, $maxlen = 24, $morecss = '')
770  {
771  global $langs, $conf, $db;
772  global $dolibarr_main_authentication, $dolibarr_main_demo;
773  global $menumanager;
774 
775  $result = '';
776 
777  $label = '<u>'.$langs->trans("Page").'</u>';
778  $label .= '<br>';
779  $label .= '<b>'.$langs->trans('Ref').':</b> '.$this->ref.'<br>';
780  $label .= '<b>'.$langs->trans('ID').':</b> '.$this->id.'<br>';
781  $label .= '<b>'.$langs->trans('Title').':</b> '.$this->title.'<br>';
782  $label .= '<b>'.$langs->trans('Language').':</b> '.$this->lang;
783 
784  $url = DOL_URL_ROOT.'/website/index.php?websiteid='.$this->fk_website.'&pageid='.$this->id;
785 
786  $linkclose = '';
787  if (empty($notooltip)) {
788  if (!empty($conf->global->MAIN_OPTIMIZEFORTEXTBROWSER)) {
789  $label = $langs->trans("ShowMyObject");
790  $linkclose .= ' alt="'.dol_escape_htmltag($label, 1).'"';
791  }
792  $linkclose .= ' title="'.dol_escape_htmltag($label, 1).'"';
793  $linkclose .= ' class="classfortooltip'.($morecss ? ' '.$morecss : '').'"';
794  } else {
795  $linkclose = ($morecss ? ' class="'.$morecss.'"' : '');
796  }
797 
798  $linkstart = '<a href="'.$url.'"';
799  $linkstart .= $linkclose.'>';
800  $linkend = '</a>';
801 
802  //$linkstart = $linkend = '';
803 
804  $result .= $linkstart;
805  if ($withpicto) {
806  $result .= img_picto(($notooltip ? '' : $label), ($this->picto ? $this->picto : 'generic'), ($notooltip ? (($withpicto != 2) ? 'class="paddingright"' : '') : 'class="'.(($withpicto != 2) ? 'paddingright ' : '').'classfortooltip"'), 0, 0, $notooltip ? 0 : 1);
807  }
808  if ($withpicto != 2) {
809  $result .= $this->ref;
810  }
811  $result .= $linkend;
812 
813  return $result;
814  }
815 
822  public function getLibStatut($mode = 0)
823  {
824  return $this->LibStatut($this->status, $mode);
825  }
826 
827  // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
835  public function LibStatut($status, $mode = 0)
836  {
837  // phpcs:enable
838  global $langs;
839 
840  if (empty($this->labelStatus) || empty($this->labelStatusShort)) {
841  global $langs;
842  //$langs->load("mymodule");
843  $this->labelStatus[self::STATUS_DRAFT] = $langs->transnoentitiesnoconv('Offline');
844  $this->labelStatus[self::STATUS_VALIDATED] = $langs->transnoentitiesnoconv('Online');
845  $this->labelStatusShort[self::STATUS_DRAFT] = $langs->transnoentitiesnoconv('Offline');
846  $this->labelStatusShort[self::STATUS_VALIDATED] = $langs->transnoentitiesnoconv('Online');
847  }
848 
849  $statusType = 'status5';
850  if ($status == self::STATUS_VALIDATED) {
851  $statusType = 'status4';
852  }
853 
854  return dolGetStatus($this->labelStatus[$status], $this->labelStatusShort[$status], '', $statusType, $mode);
855  }
856 
867  public function setCategories($categories)
868  {
869  require_once DOL_DOCUMENT_ROOT.'/categories/class/categorie.class.php';
870  return $this->setCategoriesCommon($categories, Categorie::TYPE_WEBSITE_PAGE);
871  }
872 
879  public function initAsSpecimen()
880  {
881  global $user;
882 
883  $this->id = 0;
884 
885  $now = dol_now();
886 
887  $this->fk_website = '';
888  $this->type_container = 'page';
889  $this->pageurl = 'specimen';
890  $this->aliasalt = 'specimenalt';
891  $this->title = 'My Page';
892  $this->description = 'This is my page';
893  $this->image = '';
894  $this->keywords = 'keyword1, keyword2';
895  $this->allowed_in_frames = 1;
896  $this->htmlheader = '';
897  $this->content = '<html><body>This is a html content</body></html>';
898  $this->status = '';
899  $this->grabbed_from = '';
900  $this->date_creation = $now - (24 * 30 * 3600);
901  $this->date_modification = $now - (24 * 7 * 3600);
902  $this->fk_user_creat = $user->id;
903  $this->author_alias = 'mypublicpseudo';
904  }
905 }
$object ref
Definition: info.php:78
Parent class of all other business classes (invoices, contracts, proposals, orders,...
createCommon(User $user, $notrigger=false)
Create object into database.
deleteCommon(User $user, $notrigger=false, $forcechilddeletion=0)
Delete object in database.
updateCommon(User $user, $notrigger=false)
Update object into database.
setCategoriesCommon($categories, $type_categ='', $remove_existing=true)
Sets object to given categories.
Class to manage Dolibarr database access.
Class to manage Dolibarr users.
Definition: user.class.php:47
Class Website.
Class Websitepage.
update(User $user, $notrigger=false)
Update object into database.
__construct(DoliDB $db)
Constructor.
countAll($websiteid, array $filter=array(), $filtermode='AND')
Count objects in the database.
fetchAll($websiteid, $sortorder='', $sortfield='', $limit=0, $offset=0, array $filter=array(), $filtermode='AND')
Return array of all web site pages.
initAsSpecimen()
Initialise object with example values Id must be 0 if object instance is a specimen.
fetch($id, $website_id=null, $page=null, $aliasalt=null)
Load object in memory from the database.
LibStatut($status, $mode=0)
Renvoi le libelle d'un status donne.
create(User $user, $notrigger=false)
Create object into database.
createFromClone(User $user, $fromid, $newref, $newlang='', $istranslation=0, $newwebsite=0, $newtitle='')
Load an object from its id and create a new one in database.
getLibStatut($mode=0)
Retourne le libelle du status d'un user (actif, inactif)
setCategories($categories)
Sets object to given categories.
getNomUrl($withpicto=0, $option='', $notooltip=0, $maxlen=24, $morecss='')
Return a link to the user card (with optionaly the picto) Use this->id,this->lastname,...
if(isModEnabled('facture') &&!empty($user->rights->facture->lire)) if((isModEnabled('fournisseur') &&empty($conf->global->MAIN_USE_NEW_SUPPLIERMOD) && $user->hasRight("fournisseur", "facture", "lire"))||(isModEnabled('supplier_invoice') && $user->hasRight("supplier_invoice", "lire"))) if(isModEnabled('don') &&!empty($user->rights->don->lire)) if(isModEnabled('tax') &&!empty($user->rights->tax->charges->lire)) if(isModEnabled('facture') &&isModEnabled('commande') && $user->hasRight("commande", "lire") &&empty($conf->global->WORKFLOW_DISABLE_CREATE_INVOICE_FROM_ORDER)) $resql
Social contributions to pay.
Definition: index.php:745
print *****$script_file(".$version.") pid cd cd cd description as description
Only used if Module[ID]Desc translation string is not found.
dol_delete_file($file, $disableglob=0, $nophperrors=0, $nohook=0, $object=null, $allowdotdot=false, $indexdatabase=1, $nolog=0)
Remove a file or several files with a mask.
Definition: files.lib.php:1251
dol_now($mode='auto')
Return date for now.
img_picto($titlealt, $picto, $moreatt='', $pictoisfullpath=false, $srconly=0, $notitle=0, $alt='', $morecss='', $marginleftonlyshort=2)
Show picto whatever it's its name (generic function)
dolGetStatus($statusLabel='', $statusLabelShort='', $html='', $statusType='status0', $displayMode=0, $url='', $params=array())
Output the badge of a status.
dol_sanitizeFileName($str, $newstr='_', $unaccent=1)
Clean a string to use it as a file name.
dol_trunc($string, $size=40, $trunc='right', $stringencoding='UTF-8', $nodot=0, $display=0)
Truncate a string to a particular length adding '…' if string larger than length.
dol_syslog($message, $level=LOG_INFO, $ident=0, $suffixinfilename='', $restricttologhandler='', $logcontext=null)
Write log message into outputs.
$conf db
API class for accounts.
Definition: inc.php:41