dolibarr 21.0.0-alpha
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 * Copyright (C) 2024 Frédéric France <frederic.france@free.fr>
8 * Copyright (C) 2024 MDW <mdeweerd@users.noreply.github.com>
9 *
10 * This program is free software; you can redistribute it and/or modify
11 * it under the terms of the GNU General Public License as published by
12 * the Free Software Foundation; either version 3 of the License, or
13 * (at your option) any later version.
14 *
15 * This program is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 * GNU General Public License for more details.
19 *
20 * You should have received a copy of the GNU General Public License
21 * along with this program. If not, see <https://www.gnu.org/licenses/>.
22 */
23
30// Put here all includes required by your class file
31require_once DOL_DOCUMENT_ROOT.'/core/class/commonobject.class.php';
32//require_once DOL_DOCUMENT_ROOT . '/societe/class/societe.class.php';
33//require_once DOL_DOCUMENT_ROOT . '/product/class/product.class.php';
34
39{
43 public $element = 'websitepage';
44
48 public $table_element = 'website_page';
49
53 public $picto = 'file-code';
54
58 public $fk_element = 'fk_website_page';
59
63 protected $childtablesoncascade = array('categorie_website_page');
64
65
69 public $fk_website;
70
71 public $fk_page; // If translation of another page
72
73 public $pageurl;
74 public $aliasalt;
75 public $type_container;
76
80 public $title;
84 public $description;
88 public $image;
92 public $keywords;
96 public $lang;
97
98 public $allowed_in_frames;
99 public $htmlheader;
100 public $content;
101 public $grabbed_from;
102
106 public $status;
107
108 public $fk_user_creat;
109 public $fk_user_modif;
110
114 public $author_alias;
115
119 public $object_type;
120
124 public $fk_object;
125
129 public $newid;
130
131
132 const STATUS_DRAFT = 0; // offline
133 const STATUS_VALIDATED = 1; // online
134
135
160 // BEGIN MODULEBUILDER PROPERTIES
164 public $fields = array(
165 'rowid' => array('type' => 'integer', 'label' => 'TechnicalID', 'enabled' => 1, 'visible' => -1, 'notnull' => 1, 'index' => 1, 'position' => 1, 'comment' => 'Id'),
166 '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'),
167 'aliasalt' => array('type' => 'varchar(255)', 'label' => 'AliasAlt', 'enabled' => 1, 'visible' => 1, 'notnull' => 1, 'index' => 0, 'position' => 11, 'searchall' => 0, 'comment' => 'Alias alternative of page'),
168 'type_container' => array('type' => 'varchar(16)', 'label' => 'Type', 'enabled' => 1, 'visible' => 1, 'notnull' => 1, 'index' => 0, 'position' => 12, 'comment' => 'Type of container'),
169 'title' => array('type' => 'varchar(255)', 'label' => 'Label', 'enabled' => 1, 'visible' => 1, 'position' => 30, 'searchall' => 1, 'help' => 'UseTextBetween5And70Chars'),
170 'description' => array('type' => 'varchar(255)', 'label' => 'Description', 'enabled' => 1, 'visible' => 1, 'position' => 30, 'searchall' => 1),
171 '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"'),
172 'keywords' => array('type' => 'varchar(255)', 'label' => 'Keywords', 'enabled' => 1, 'visible' => 1, 'position' => 45, 'searchall' => 0),
173 'lang' => array('type' => 'varchar(6)', 'label' => 'Lang', 'enabled' => 1, 'notnull' => -1, 'visible' => 1, 'position' => 45, 'searchall' => 0),
174 //'status' =>array('type'=>'integer', 'label'=>'Status', 'enabled'=>1, 'visible'=>1, 'index'=>true, 'position'=>1000),
175 'fk_website' => array('type' => 'integer', 'label' => 'WebsiteId', 'enabled' => 1, 'visible' => 1, 'notnull' => 1, 'position' => 40, 'searchall' => 0, 'foreignkey' => 'websitepage.rowid'),
176 'fk_page' => array('type' => 'integer', 'label' => 'ParentPageId', 'enabled' => 1, 'visible' => 1, 'notnull' => -1, 'position' => 45, 'searchall' => 0, 'foreignkey' => 'website.rowid'),
177 'allowed_in_frames' => array('type' => 'integer', 'label' => 'AllowedInFrames', 'enabled' => 1, 'visible' => -1, 'position' => 48, 'searchall' => 0, 'default' => '0'),
178 'htmlheader' => array('type' => 'html', 'label' => 'HtmlHeader', 'enabled' => 1, 'visible' => 0, 'position' => 50, 'searchall' => 0),
179 'content' => array('type' => 'mediumtext', 'label' => 'Content', 'enabled' => 1, 'visible' => 0, 'position' => 51, 'searchall' => 0),
180 'grabbed_from' => array('type' => 'varchar(255)', 'label' => 'GrabbedFrom', 'enabled' => 1, 'visible' => 1, 'index' => 1, 'position' => 400, 'comment' => 'URL page content was grabbed from'),
181 'date_creation' => array('type' => 'datetime', 'label' => 'DateCreation', 'enabled' => 1, 'visible' => -1, 'notnull' => 1, 'position' => 500),
182 'tms' => array('type' => 'timestamp', 'label' => 'DateModification', 'enabled' => 1, 'visible' => -1, 'notnull' => 1, 'position' => 501),
183 //'date_valid' =>array('type'=>'datetime', 'label'=>'DateValidation', 'enabled'=>1, 'visible'=>-1, 'position'=>502),
184 'fk_user_creat' => array('type' => 'integer', 'label' => 'UserAuthor', 'enabled' => 1, 'visible' => -1, 'notnull' => true, 'position' => 510),
185 'author_alias' => array('type' => 'varchar(64)', 'label' => 'AuthorAlias', 'enabled' => 1, 'visible' => -1, 'index' => 0, 'position' => 511, 'comment' => 'Author alias'),
186 'fk_user_modif' => array('type' => 'integer', 'label' => 'UserModif', 'enabled' => 1, 'visible' => -1, 'position' => 512),
187 //'fk_user_valid' =>array('type'=>'integer', 'label'=>'UserValidation', 'enabled'=>1, 'visible'=>-1, 'position'=>512),
188 'import_key' => array('type' => 'varchar(14)', 'label' => 'ImportId', 'enabled' => 1, 'visible' => -1, 'index' => 1, 'position' => 1000, 'notnull' => -1),
189 'object_type' => array('type' => 'varchar(255)', 'label' => 'ObjectType', 'enabled' => 1, 'visible' => 0, 'position' => 46, 'searchall' => 0, 'help' => ''),
190 'fk_object' => array('type' => 'varchar(255)', 'label' => 'ObjectId', 'enabled' => 1, 'visible' => 0, 'position' => 47, 'searchall' => 0, 'help' => '')
191 );
192 // END MODULEBUILDER PROPERTIES
193
194
200 public function __construct(DoliDB $db)
201 {
202 $this->db = $db;
203 }
204
212 public function create(User $user, $notrigger = 0)
213 {
214 $this->description = dol_trunc($this->description, 255, 'right', 'utf-8', 1);
215 $this->keywords = dol_trunc($this->keywords, 255, 'right', 'utf-8', 1);
216 if ($this->aliasalt) {
217 $this->aliasalt = ','.preg_replace('/,+$/', '', preg_replace('/^,+/', '', $this->aliasalt)).','; // content in database must be ',xxx,...,yyy,'
218 }
219
220 $this->pageurl = preg_replace('/[^a-z0-9\-\_]/i', '', $this->pageurl);
221 $this->pageurl = preg_replace('/\-\-+/', '-', $this->pageurl);
222 $this->pageurl = preg_replace('/^\-/', '', $this->pageurl);
223
224 // Remove spaces and be sure we have main language only
225 $this->lang = preg_replace('/[_-].*$/', '', trim($this->lang)); // en_US or en-US -> en
226
227 return $this->createCommon($user, $notrigger);
228 }
229
241 public function fetch($id, $website_id = null, $page = null, $aliasalt = null)
242 {
243 dol_syslog(__METHOD__, LOG_DEBUG);
244
245 $sql = 'SELECT';
246 $sql .= ' t.rowid,';
247 $sql .= " t.fk_website,";
248 $sql .= ' t.type_container,';
249 $sql .= " t.pageurl,";
250 $sql .= " t.aliasalt,";
251 $sql .= " t.title,";
252 $sql .= " t.description,";
253 $sql .= " t.image,";
254 $sql .= " t.keywords,";
255 $sql .= " t.htmlheader,";
256 $sql .= " t.content,";
257 $sql .= " t.lang,";
258 $sql .= " t.fk_page,";
259 $sql .= " t.allowed_in_frames,";
260 $sql .= " t.status,";
261 $sql .= " t.grabbed_from,";
262 $sql .= " t.date_creation,";
263 $sql .= " t.tms as date_modification,";
264 $sql .= " t.fk_user_creat,";
265 $sql .= " t.author_alias,";
266 $sql .= " t.fk_user_modif,";
267 $sql .= " t.import_key,";
268 $sql .= " t.object_type,";
269 $sql .= " t.fk_object";
270 $sql .= ' FROM '.MAIN_DB_PREFIX.$this->table_element.' as t';
271 //$sql .= ' WHERE entity IN ('.getEntity('website').')'; // entity is on website level
272 $sql .= ' WHERE 1 = 1';
273 if ($id > 0) {
274 $sql .= ' AND t.rowid = '.((int) $id);
275 } else {
276 if ($id < 0) {
277 $sql .= ' AND t.rowid <> '.abs($id);
278 }
279 if (null !== $website_id) {
280 $sql .= " AND t.fk_website = '".$this->db->escape($website_id)."'";
281 if ($page) {
282 $pagetouse = $page;
283 $langtouse = '';
284 $tmppage = explode('/', $page);
285 if (!empty($tmppage[1])) {
286 $pagetouse = $tmppage[1];
287 if (strlen($tmppage[0])) {
288 $langtouse = $tmppage[0];
289 }
290 }
291 $sql .= " AND t.pageurl = '".$this->db->escape($pagetouse)."'";
292 if ($langtouse) {
293 $sql .= " AND t.lang = '".$this->db->escape($langtouse)."'";
294 }
295 }
296 if ($aliasalt) {
297 $sql .= " AND (t.aliasalt LIKE '%,".$this->db->escape($aliasalt).",%' OR t.aliasalt LIKE '%, ".$this->db->escape($aliasalt).",%')";
298 }
299 }
300 }
301 $sql .= $this->db->plimit(1);
302
303 $resql = $this->db->query($sql);
304 if ($resql) {
305 $numrows = $this->db->num_rows($resql);
306 if ($numrows) {
307 $obj = $this->db->fetch_object($resql);
308
309 $this->id = $obj->rowid;
310
311 $this->fk_website = $obj->fk_website;
312 $this->type_container = $obj->type_container;
313
314 $this->pageurl = $obj->pageurl;
315 $this->ref = $obj->pageurl;
316 $this->aliasalt = preg_replace('/,+$/', '', preg_replace('/^,+/', '', $obj->aliasalt));
317
318 $this->title = $obj->title;
319 $this->description = $obj->description;
320 $this->image = $obj->image;
321 $this->keywords = $obj->keywords;
322 $this->htmlheader = $obj->htmlheader;
323 $this->content = $obj->content;
324 $this->lang = $obj->lang;
325 $this->fk_page = $obj->fk_page;
326 $this->allowed_in_frames = $obj->allowed_in_frames;
327 $this->status = $obj->status;
328 $this->grabbed_from = $obj->grabbed_from;
329 $this->date_creation = $this->db->jdate($obj->date_creation);
330 $this->date_modification = $this->db->jdate($obj->date_modification);
331 $this->fk_user_creat = $obj->fk_user_creat;
332 $this->author_alias = $obj->author_alias;
333 $this->fk_user_modif = $obj->fk_user_modif;
334 $this->import_key = $obj->import_key;
335 $this->object_type = $obj->object_type;
336 $this->fk_object = $obj->fk_object;
337 }
338 $this->db->free($resql);
339
340 if ($numrows) {
341 return 1;
342 } else {
343 return 0;
344 }
345 } else {
346 $this->errors[] = 'Error '.$this->db->lasterror();
347 dol_syslog(__METHOD__.' '.implode(',', $this->errors), LOG_ERR);
348
349 return -1;
350 }
351 }
352
366 public function fetchAll($websiteid = '', $sortorder = '', $sortfield = '', $limit = 0, $offset = 0, $filter = '', $filtermode = 'AND')
367 {
368 dol_syslog(__METHOD__, LOG_DEBUG);
369
370 $records = array();
371
372 $sql = 'SELECT';
373 $sql .= ' t.rowid,';
374 $sql .= " t.fk_website,";
375 $sql .= " t.type_container,";
376 $sql .= " t.pageurl,";
377 $sql .= " t.aliasalt,";
378 $sql .= " t.title,";
379 $sql .= " t.description,";
380 $sql .= " t.image,";
381 $sql .= " t.keywords,";
382 $sql .= " t.htmlheader,";
383 $sql .= " t.content,";
384 $sql .= " t.lang,";
385 $sql .= " t.fk_page,";
386 $sql .= " t.allowed_in_frames,";
387 $sql .= " t.status,";
388 $sql .= " t.grabbed_from,";
389 $sql .= " t.date_creation,";
390 $sql .= " t.tms as date_modification,";
391 $sql .= " t.fk_user_creat,";
392 $sql .= " t.author_alias,";
393 $sql .= " t.fk_user_modif,";
394 $sql .= " t.import_key,";
395 $sql .= " t.object_type,";
396 $sql .= " t.fk_object";
397 $sql .= ' FROM '.MAIN_DB_PREFIX.$this->table_element.' as t';
398 if (!empty($websiteid)) {
399 $sql .= ' WHERE t.fk_website = '.((int) $websiteid);
400 }
401
402 // Deprecated. If we receive an array, we use it. Prefer using the USF syntax.
403 if (is_array($filter)) {
404 $sqlwhere = array();
405
406 if (count($filter) > 0) {
407 foreach ($filter as $key => $value) {
408 if ($key == 't.rowid' || $key == 'rowid' || $key == 't.fk_website' || $key == 'fk_website' || $key == 'status' || $key == 't.status') {
409 $sqlwhere[] = $key." = ".((int) $value);
410 } elseif ($key == 'type_container' || $key == 't.type_container') {
411 $sqlwhere[] = $key." = '".$this->db->escape($value)."'";
412 } elseif ($key == 'lang' || $key == 't.lang') {
413 $listoflang = array();
414 $foundnull = 0;
415 foreach (explode(',', $value) as $tmpvalue) {
416 if ($tmpvalue == 'null') {
417 $foundnull++;
418 continue;
419 }
420 $listoflang[] = "'".$this->db->escape(substr(str_replace("'", '', $tmpvalue), 0, 2))."'";
421 }
422 $stringtouse = $this->db->sanitize($key)." IN (".$this->db->sanitize(implode(',', $listoflang), 1).")";
423 if ($foundnull) {
424 $stringtouse = "(".$stringtouse." OR ".$this->db->sanitize($key)." IS NULL)";
425 }
426 $sqlwhere[] = $stringtouse;
427 } else {
428 $sqlwhere[] = $this->db->sanitize($key)." LIKE '%".$this->db->escape($value)."%'";
429 }
430 }
431 }
432 if (count($sqlwhere) > 0) {
433 if (!empty($websiteid)) {
434 $sql .= " AND (".implode(' '.$this->db->escape($filtermode).' ', $sqlwhere).')';
435 } else {
436 $sql .= " WHERE ".implode(' '.$this->db->escape($filtermode).' ', $sqlwhere);
437 }
438 }
439
440 $filter = '';
441 }
442
443 $errormessage = '';
444 $sql .= forgeSQLFromUniversalSearchCriteria($filter, $errormessage);
445 if ($errormessage) {
446 $this->errors[] = $errormessage;
447 dol_syslog(__METHOD__.' '.implode(',', $this->errors), LOG_ERR);
448 return -1;
449 }
450
451 if (!empty($sortfield)) {
452 $sql .= $this->db->order($sortfield, $sortorder);
453 }
454 if (!empty($limit)) {
455 $sql .= $this->db->plimit($limit, $offset);
456 }
457
458 $resql = $this->db->query($sql);
459 if ($resql) {
460 $num = $this->db->num_rows($resql);
461
462 while ($obj = $this->db->fetch_object($resql)) {
463 $record = new self($this->db);
464
465 $record->id = $obj->rowid;
466 $record->fk_website = $obj->fk_website;
467 $record->type_container = $obj->type_container;
468 $record->pageurl = $obj->pageurl;
469 $record->aliasalt = preg_replace('/,+$/', '', preg_replace('/^,+/', '', $obj->aliasalt));
470 $record->title = $obj->title;
471 $record->description = $obj->description;
472 $record->image = $obj->image;
473 $record->keywords = $obj->keywords;
474 $record->htmlheader = $obj->htmlheader;
475 $record->content = $obj->content;
476 $record->lang = $obj->lang;
477 $record->fk_page = $obj->fk_page;
478 $record->allowed_in_frames = $obj->allowed_in_frames;
479 $record->status = $obj->status;
480 $record->grabbed_from = $obj->grabbed_from;
481 $record->date_creation = $this->db->jdate($obj->date_creation);
482 $record->date_modification = $this->db->jdate($obj->date_modification);
483 $record->fk_user_creat = $obj->fk_user_creat;
484 $record->author_alias = $obj->author_alias;
485 $record->fk_user_modif = $obj->fk_user_modif;
486 $record->import_key = $obj->import_key;
487 $record->object_type = $obj->object_type;
488 $record->fk_object = $obj->fk_object;
489 //var_dump($record->id);
490 $records[$record->id] = $record;
491 }
492 $this->db->free($resql);
493
494 return $records;
495 } else {
496 $this->error = 'Error '.$this->db->lasterror();
497 $this->errors[] = $this->error;
498 dol_syslog(__METHOD__.' '.implode(',', $this->errors), LOG_ERR);
499
500 return -1;
501 }
502 }
503
512 public function countAll($websiteid, array $filter = array(), $filtermode = 'AND')
513 {
514 dol_syslog(__METHOD__, LOG_DEBUG);
515
516 $result = 0;
517
518 $sql = 'SELECT COUNT(t.rowid) as nb';
519 $sql .= ' FROM '.MAIN_DB_PREFIX.$this->table_element.' as t';
520 $sql .= ' WHERE t.fk_website = '.((int) $websiteid);
521
522 // Manage filter (same than into fetchAll)
523 $sqlwhere = array();
524 if (count($filter) > 0) {
525 foreach ($filter as $key => $value) {
526 if ($key == 't.rowid' || $key == 't.fk_website' || $key == 'status') {
527 $sqlwhere[] = $key." = ".((int) $value);
528 } elseif ($key == 'type_container') {
529 $sqlwhere[] = $key." = '".$this->db->escape($value)."'";
530 } elseif ($key == 'lang' || $key == 't.lang') {
531 $listoflang = array();
532 $foundnull = 0;
533 foreach (explode(',', $value) as $tmpvalue) {
534 if ($tmpvalue == 'null') {
535 $foundnull++;
536 continue;
537 }
538 $listoflang[] = "'".$this->db->escape(substr(str_replace("'", '', $tmpvalue), 0, 2))."'";
539 }
540 $stringtouse = $key." IN (".$this->db->sanitize(implode(',', $listoflang), 1).")";
541 if ($foundnull) {
542 $stringtouse = "(".$stringtouse." OR ".$key." IS NULL)";
543 }
544 $sqlwhere[] = $stringtouse;
545 } else {
546 $sqlwhere[] = $key." LIKE '%".$this->db->escape($value)."%'";
547 }
548 }
549 }
550 if (count($sqlwhere) > 0) {
551 $sql .= ' AND ('.implode(' '.$this->db->escape($filtermode).' ', $sqlwhere).')';
552 }
553
554 $resql = $this->db->query($sql);
555 if ($resql) {
556 $obj = $this->db->fetch_object($resql);
557 if ($obj) {
558 $result = $obj->nb;
559 }
560
561 $this->db->free($resql);
562
563 return $result;
564 } else {
565 $this->error = 'Error '.$this->db->lasterror();
566 $this->errors[] = $this->error;
567 dol_syslog(__METHOD__.' '.implode(',', $this->errors), LOG_ERR);
568
569 return -1;
570 }
571 }
572
580 public function update(User $user, $notrigger = 0)
581 {
582 $this->description = dol_trunc($this->description, 255, 'right', 'utf-8', 1);
583 $this->keywords = dol_trunc($this->keywords, 255, 'right', 'utf-8', 1);
584 if ($this->aliasalt) {
585 $this->aliasalt = ','.preg_replace('/,+$/', '', preg_replace('/^,+/', '', $this->aliasalt)).','; // content in database must be ',xxx,...,yyy,'
586 }
587
588 $this->pageurl = preg_replace('/[^a-z0-9\-\_]/i', '', $this->pageurl);
589 $this->pageurl = preg_replace('/\-\-+/', '-', $this->pageurl);
590 $this->pageurl = preg_replace('/^\-/', '', $this->pageurl);
591
592 // Remove spaces and be sure we have main language only
593 $this->lang = preg_replace('/[_-].*$/', '', trim($this->lang)); // en_US or en-US -> en
594
595 if ($this->fk_page > 0) {
596 if (empty($this->lang)) {
597 $this->error = "ErrorLanguageMandatoryIfPageSetAsTranslationOfAnother";
598 return -1;
599 }
600 $tmppage = new WebsitePage($this->db);
601 $tmppage->fetch($this->fk_page);
602 if ($tmppage->lang == $this->lang) {
603 $this->error = "ErrorLanguageOfTranslatedPageIsSameThanThisPage";
604 return -1;
605 }
606 }
607
608 return $this->updateCommon($user, $notrigger);
609 }
610
618 public function delete(User $user, $notrigger = 0)
619 {
620 global $conf;
621
622 $error = 0;
623
624 // Delete all child tables
625 if (!$error) {
626 foreach ($this->childtablesoncascade as $table) {
627 $sql = "DELETE FROM ".MAIN_DB_PREFIX.$table;
628 $sql .= " WHERE fk_website_page = ".(int) $this->id;
629
630 $result = $this->db->query($sql);
631 if (!$result) {
632 $error++;
633 $this->errors[] = $this->db->lasterror();
634 break;
635 }
636 }
637 }
638
639 if (!$error) {
640 $result = $this->deleteCommon($user, $notrigger);
641 if ($result <= 0) {
642 $error++;
643 }
644 }
645
646 if (!$error) {
647 $websiteobj = new Website($this->db);
648 $result = $websiteobj->fetch($this->fk_website);
649
650 if ($result > 0) {
651 global $dolibarr_main_data_root;
652 $pathofwebsite = $dolibarr_main_data_root.($conf->entity > 1 ? '/'.$conf->entity : '').'/website/'.$websiteobj->ref;
653
654 $filealias = $pathofwebsite.'/'.$this->pageurl.'.php';
655 $filetpl = $pathofwebsite.'/page'.$this->id.'.tpl.php';
656
657 dol_delete_file($filealias);
658 dol_delete_file($filetpl);
659 } else {
660 $this->error = $websiteobj->error;
661 $this->errors = $websiteobj->errors;
662 }
663 }
664
665 if (!$error) {
666 return 1;
667 } else {
668 return -1;
669 }
670 }
671
684 public function createFromClone(User $user, $fromid, $newref, $newlang = '', $istranslation = 0, $newwebsite = 0, $newtitle = '')
685 {
686 global $hookmanager, $langs;
687
688 $now = dol_now();
689 $error = 0;
690
691 dol_syslog(__METHOD__, LOG_DEBUG);
692
693 $object = new self($this->db);
694
695 // Clean parameters
696 if (empty($newref) && !empty($newtitle)) {
697 $newref = strtolower(dol_sanitizeFileName(preg_replace('/\s+/', '-', $newtitle), '-', 1));
698 }
699
700 // Check parameters
701 if (empty($newref)) {
702 $langs->load("errors");
703 $this->error = $langs->trans("ErrorFieldRequired", $langs->transnoentitiesnoconv("WEBSITE_TITLE"));
704 return -1;
705 }
706
707 $this->db->begin();
708
709 // Load source object
710 $object->fetch($fromid);
711 // Reset object
712 $object->id = 0;
713
714 // Clear fields
715 $object->ref = $newref;
716 $object->pageurl = $newref;
717 $object->aliasalt = '';
718 $object->fk_user_creat = $user->id;
719 $object->author_alias = '';
720 $object->date_creation = $now;
721 $object->title = ($newtitle == '1' ? $object->title : ($newtitle ? $newtitle : $object->title));
722 $object->description = $object->title;
723 if (!empty($newlang)) {
724 $object->lang = $newlang;
725 }
726 if ($istranslation) {
727 $object->fk_page = $fromid;
728 } else {
729 $object->fk_page = 0;
730 }
731 if (!empty($newwebsite)) {
732 $object->fk_website = $newwebsite;
733 }
734 $object->import_key = '';
735 $object->status = self::STATUS_DRAFT;
736
737 // Create clone
738 $object->context['createfromclone'] = 'createfromclone';
739 $result = $object->create($user);
740 if ($result < 0) {
741 $error++;
742 $this->error = $object->error;
743 $this->errors = $object->errors;
744 dol_syslog(__METHOD__.' '.implode(',', $this->errors), LOG_ERR);
745 }
746
747 unset($object->context['createfromclone']);
748
749 // End
750 if (!$error) {
751 $this->db->commit();
752
753 return $object;
754 } else {
755 $this->db->rollback();
756
757 return -1;
758 }
759 }
760
772 public function getNomUrl($withpicto = 0, $option = '', $notooltip = 0, $maxlen = 24, $morecss = '')
773 {
774 global $langs, $conf, $db;
775 global $dolibarr_main_authentication, $dolibarr_main_demo;
776 global $menumanager;
777
778 $result = '';
779
780 $label = '<u>'.$langs->trans("Page").'</u>';
781 $label .= '<br>';
782 $label .= '<b>'.$langs->trans('Ref').':</b> '.$this->ref.'<br>';
783 $label .= '<b>'.$langs->trans('ID').':</b> '.$this->id.'<br>';
784 $label .= '<b>'.$langs->trans('Title').':</b> '.$this->title.'<br>';
785 $label .= '<b>'.$langs->trans('Language').':</b> '.$this->lang;
786
787 $url = DOL_URL_ROOT.'/website/index.php?websiteid='.$this->fk_website.'&pageid='.$this->id;
788
789 $linkclose = '';
790 if (empty($notooltip)) {
791 if (getDolGlobalString('MAIN_OPTIMIZEFORTEXTBROWSER')) {
792 $label = $langs->trans("ShowMyObject");
793 $linkclose .= ' alt="'.dol_escape_htmltag($label, 1).'"';
794 }
795 $linkclose .= ' title="'.dol_escape_htmltag($label, 1).'"';
796 $linkclose .= ' class="classfortooltip'.($morecss ? ' '.$morecss : '').'"';
797 } else {
798 $linkclose = ($morecss ? ' class="'.$morecss.'"' : '');
799 }
800
801 $linkstart = '<a href="'.$url.'"';
802 $linkstart .= $linkclose.'>';
803 $linkend = '</a>';
804
805 //$linkstart = $linkend = '';
806
807 $result .= $linkstart;
808 if ($withpicto) {
809 $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);
810 }
811 if ($withpicto != 2) {
812 $result .= $this->ref;
813 }
814 $result .= $linkend;
815
816 return $result;
817 }
818
825 public function getLibStatut($mode = 0)
826 {
827 return $this->LibStatut($this->status, $mode);
828 }
829
830 // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
838 public function LibStatut($status, $mode = 0)
839 {
840 // phpcs:enable
841 global $langs;
842
843 if (empty($this->labelStatus) || empty($this->labelStatusShort)) {
844 global $langs;
845 //$langs->load("mymodule");
846 $this->labelStatus[self::STATUS_DRAFT] = $langs->transnoentitiesnoconv('Offline');
847 $this->labelStatus[self::STATUS_VALIDATED] = $langs->transnoentitiesnoconv('Online');
848 $this->labelStatusShort[self::STATUS_DRAFT] = $langs->transnoentitiesnoconv('Offline');
849 $this->labelStatusShort[self::STATUS_VALIDATED] = $langs->transnoentitiesnoconv('Online');
850 }
851
852 $statusType = 'status5';
853 if ($status == self::STATUS_VALIDATED) {
854 $statusType = 'status4';
855 }
856
857 return dolGetStatus($this->labelStatus[$status], $this->labelStatusShort[$status], '', $statusType, $mode);
858 }
859
870 public function setCategories($categories)
871 {
872 require_once DOL_DOCUMENT_ROOT.'/categories/class/categorie.class.php';
873 return $this->setCategoriesCommon($categories, Categorie::TYPE_WEBSITE_PAGE);
874 }
875
882 public function initAsSpecimen()
883 {
884 global $user;
885
886 $this->id = 0;
887
888 $now = dol_now();
889
890 $this->fk_website = 0;
891 $this->type_container = 'page';
892 $this->pageurl = 'specimen';
893 $this->aliasalt = 'specimenalt';
894 $this->title = 'My Page';
895 $this->description = 'This is my page';
896 $this->image = '';
897 $this->keywords = 'keyword1, keyword2';
898 $this->allowed_in_frames = 1;
899 $this->htmlheader = '';
900 $this->content = '<html><body>This is a html content</body></html>';
901 $this->status = self::STATUS_DRAFT;
902 $this->grabbed_from = '';
903 $this->date_creation = $now - (24 * 30 * 3600);
904 $this->date_modification = $now - (24 * 7 * 3600);
905 $this->fk_user_creat = $user->id;
906 $this->author_alias = 'mypublicpseudo';
907
908 return 1;
909 }
910}
if( $user->socid > 0) if(! $user->hasRight('accounting', 'chartofaccount')) $object
Definition card.php:58
print $langs trans("AuditedSecurityEvents").'</strong >< span class="opacitymedium"></span >< br > status
Or an array listing all the potential status of the object: array: int of the status => translated la...
Definition security.php:626
$object ref
Definition info.php:79
Parent class of all other business classes (invoices, contracts, proposals, orders,...
createCommon(User $user, $notrigger=0)
Create object in the database.
updateCommon(User $user, $notrigger=0)
Update object into database.
setCategoriesCommon($categories, $type_categ='', $remove_existing=true)
Sets object to given categories.
deleteCommon(User $user, $notrigger=0, $forcechilddeletion=0)
Delete object in database.
Class to manage Dolibarr database access.
Class to manage Dolibarr users.
Class Website.
Class Websitepage.
__construct(DoliDB $db)
Constructor.
countAll($websiteid, array $filter=array(), $filtermode='AND')
Count objects in the database.
update(User $user, $notrigger=0)
Update object into database.
create(User $user, $notrigger=0)
Create object into database.
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)
Return the label of a given status.
fetchAll($websiteid='', $sortorder='', $sortfield='', $limit=0, $offset=0, $filter='', $filtermode='AND')
Return array of all web site pages.
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)
Return the label of the status.
setCategories($categories)
Sets object to given categories.
getNomUrl($withpicto=0, $option='', $notooltip=0, $maxlen=24, $morecss='')
Return a link to the user card (with optionally the picto) Use this->id,this->lastname,...
print $script_file $mode $langs defaultlang(is_numeric($duration_value) ? " delay=". $duration_value :"").(is_numeric($duration_value2) ? " after 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.
img_picto($titlealt, $picto, $moreatt='', $pictoisfullpath=0, $srconly=0, $notitle=0, $alt='', $morecss='', $marginleftonlyshort=2)
Show picto whatever it's its name (generic function)
forgeSQLFromUniversalSearchCriteria($filter, &$errorstr='', $noand=0, $nopar=0, $noerror=0)
forgeSQLFromUniversalSearchCriteria
dol_now($mode='auto')
Return date for now.
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.
getDolGlobalString($key, $default='')
Return dolibarr global constant string value.
dol_syslog($message, $level=LOG_INFO, $ident=0, $suffixinfilename='', $restricttologhandler='', $logcontext=null)
Write log message into outputs.