dolibarr 21.0.0-beta
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
68 public $fk_website;
69
73 public $fk_page; // If translation of another page
74
78 public $pageurl;
79
83 public $aliasalt;
84
88 public $type_container;
89
93 public $title;
94
98 public $description;
99
103 public $image;
104
108 public $keywords;
109
113 public $lang;
114
118 public $allowed_in_frames;
119
123 public $htmlheader;
124
128 public $content;
129
133 public $grabbed_from;
134
138 public $status;
139
143 public $fk_user_creat;
144
148 public $fk_user_modif;
149
153 public $author_alias;
154
158 public $object_type;
159
163 public $fk_object;
164
168 public $newid;
169
170
171 const STATUS_DRAFT = 0; // offline
172 const STATUS_VALIDATED = 1; // online
173
174
199 // BEGIN MODULEBUILDER PROPERTIES
203 public $fields = array(
204 'rowid' => array('type' => 'integer', 'label' => 'TechnicalID', 'enabled' => 1, 'visible' => -1, 'notnull' => 1, 'index' => 1, 'position' => 1, 'comment' => 'Id'),
205 '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'),
206 'aliasalt' => array('type' => 'varchar(255)', 'label' => 'AliasAlt', 'enabled' => 1, 'visible' => 1, 'notnull' => 1, 'index' => 0, 'position' => 11, 'searchall' => 0, 'comment' => 'Alias alternative of page'),
207 'type_container' => array('type' => 'varchar(16)', 'label' => 'Type', 'enabled' => 1, 'visible' => 1, 'notnull' => 1, 'index' => 0, 'position' => 12, 'comment' => 'Type of container'),
208 'title' => array('type' => 'varchar(255)', 'label' => 'Label', 'enabled' => 1, 'visible' => 1, 'position' => 30, 'searchall' => 1, 'help' => 'UseTextBetween5And70Chars'),
209 'description' => array('type' => 'varchar(255)', 'label' => 'Description', 'enabled' => 1, 'visible' => 1, 'position' => 30, 'searchall' => 1),
210 '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"'),
211 'keywords' => array('type' => 'varchar(255)', 'label' => 'Keywords', 'enabled' => 1, 'visible' => 1, 'position' => 45, 'searchall' => 0),
212 'lang' => array('type' => 'varchar(6)', 'label' => 'Lang', 'enabled' => 1, 'notnull' => -1, 'visible' => 1, 'position' => 45, 'searchall' => 0),
213 //'status' =>array('type'=>'integer', 'label'=>'Status', 'enabled'=>1, 'visible'=>1, 'index'=>true, 'position'=>1000),
214 'fk_website' => array('type' => 'integer', 'label' => 'WebsiteId', 'enabled' => 1, 'visible' => 1, 'notnull' => 1, 'position' => 40, 'searchall' => 0, 'foreignkey' => 'websitepage.rowid'),
215 'fk_page' => array('type' => 'integer', 'label' => 'ParentPageId', 'enabled' => 1, 'visible' => 1, 'notnull' => -1, 'position' => 45, 'searchall' => 0, 'foreignkey' => 'website.rowid'),
216 'allowed_in_frames' => array('type' => 'integer', 'label' => 'AllowedInFrames', 'enabled' => 1, 'visible' => -1, 'position' => 48, 'searchall' => 0, 'default' => '0'),
217 'htmlheader' => array('type' => 'html', 'label' => 'HtmlHeader', 'enabled' => 1, 'visible' => 0, 'position' => 50, 'searchall' => 0),
218 'content' => array('type' => 'mediumtext', 'label' => 'Content', 'enabled' => 1, 'visible' => 0, 'position' => 51, 'searchall' => 0),
219 'grabbed_from' => array('type' => 'varchar(255)', 'label' => 'GrabbedFrom', 'enabled' => 1, 'visible' => 1, 'index' => 1, 'position' => 400, 'comment' => 'URL page content was grabbed from'),
220 'date_creation' => array('type' => 'datetime', 'label' => 'DateCreation', 'enabled' => 1, 'visible' => -1, 'notnull' => 1, 'position' => 500),
221 'tms' => array('type' => 'timestamp', 'label' => 'DateModification', 'enabled' => 1, 'visible' => -1, 'notnull' => 1, 'position' => 501),
222 //'date_valid' =>array('type'=>'datetime', 'label'=>'DateValidation', 'enabled'=>1, 'visible'=>-1, 'position'=>502),
223 'fk_user_creat' => array('type' => 'integer', 'label' => 'UserAuthor', 'enabled' => 1, 'visible' => -1, 'notnull' => true, 'position' => 510),
224 'author_alias' => array('type' => 'varchar(64)', 'label' => 'AuthorAlias', 'enabled' => 1, 'visible' => -1, 'index' => 0, 'position' => 511, 'comment' => 'Author alias'),
225 'fk_user_modif' => array('type' => 'integer', 'label' => 'UserModif', 'enabled' => 1, 'visible' => -1, 'position' => 512),
226 //'fk_user_valid' =>array('type'=>'integer', 'label'=>'UserValidation', 'enabled'=>1, 'visible'=>-1, 'position'=>512),
227 'import_key' => array('type' => 'varchar(14)', 'label' => 'ImportId', 'enabled' => 1, 'visible' => -1, 'index' => 1, 'position' => 1000, 'notnull' => -1),
228 'object_type' => array('type' => 'varchar(255)', 'label' => 'ObjectType', 'enabled' => 1, 'visible' => 0, 'position' => 46, 'searchall' => 0, 'help' => ''),
229 'fk_object' => array('type' => 'varchar(255)', 'label' => 'ObjectId', 'enabled' => 1, 'visible' => 0, 'position' => 47, 'searchall' => 0, 'help' => '')
230 );
231 // END MODULEBUILDER PROPERTIES
232
233
239 public function __construct(DoliDB $db)
240 {
241 $this->db = $db;
242 }
243
251 public function create(User $user, $notrigger = 0)
252 {
253 $this->description = dol_trunc($this->description, 255, 'right', 'utf-8', 1);
254 $this->keywords = dol_trunc($this->keywords, 255, 'right', 'utf-8', 1);
255 if ($this->aliasalt) {
256 $this->aliasalt = ','.preg_replace('/,+$/', '', preg_replace('/^,+/', '', $this->aliasalt)).','; // content in database must be ',xxx,...,yyy,'
257 }
258
259 $this->pageurl = preg_replace('/[^a-z0-9\-\_]/i', '', $this->pageurl);
260 $this->pageurl = preg_replace('/\-\-+/', '-', $this->pageurl);
261 $this->pageurl = preg_replace('/^\-/', '', $this->pageurl);
262
263 // Remove spaces and be sure we have main language only
264 $this->lang = preg_replace('/[_-].*$/', '', trim($this->lang)); // en_US or en-US -> en
265
266 return $this->createCommon($user, $notrigger);
267 }
268
282 public function fetch($id, $website_id = null, $page = null, $aliasalt = null, $translationparentid = 0, $translationparentlang = '')
283 {
284 dol_syslog(__METHOD__, LOG_DEBUG);
285
286 $sql = 'SELECT';
287 $sql .= ' t.rowid,';
288 $sql .= " t.fk_website,";
289 $sql .= ' t.type_container,';
290 $sql .= " t.pageurl,";
291 $sql .= " t.aliasalt,";
292 $sql .= " t.title,";
293 $sql .= " t.description,";
294 $sql .= " t.image,";
295 $sql .= " t.keywords,";
296 $sql .= " t.htmlheader,";
297 $sql .= " t.content,";
298 $sql .= " t.lang,";
299 $sql .= " t.fk_page,"; // Translation parent page (in mani language)
300 $sql .= " t.allowed_in_frames,";
301 $sql .= " t.status,";
302 $sql .= " t.grabbed_from,";
303 $sql .= " t.date_creation,";
304 $sql .= " t.tms as date_modification,";
305 $sql .= " t.fk_user_creat,";
306 $sql .= " t.author_alias,";
307 $sql .= " t.fk_user_modif,";
308 $sql .= " t.import_key,";
309 $sql .= " t.object_type,";
310 $sql .= " t.fk_object";
311 $sql .= ' FROM '.MAIN_DB_PREFIX.$this->table_element.' as t';
312 //$sql .= ' WHERE entity IN ('.getEntity('website').')'; // entity is on website level
313 $sql .= ' WHERE 1 = 1';
314 if ($id > 0) {
315 $sql .= ' AND t.rowid = '.((int) $id);
316 } else {
317 if ($id < 0) {
318 $sql .= ' AND t.rowid <> '.((int) abs($id));
319 }
320 if (null !== $website_id) {
321 $sql .= " AND t.fk_website = '".$this->db->escape($website_id)."'";
322 if ($page) {
323 $pagetouse = $page;
324 $langtouse = '';
325 $tmppage = explode('/', $page);
326 if (!empty($tmppage[1])) {
327 $pagetouse = $tmppage[1];
328 if (strlen($tmppage[0])) {
329 $langtouse = $tmppage[0];
330 }
331 }
332 $sql .= " AND t.pageurl = '".$this->db->escape($pagetouse)."'";
333 if ($langtouse) {
334 $sql .= " AND t.lang = '".$this->db->escape($langtouse)."'";
335 }
336 }
337 if ($aliasalt) {
338 $sql .= " AND (t.aliasalt LIKE '%,".$this->db->escape($this->db->escapeforlike($aliasalt)).",%' OR t.aliasalt LIKE '%, ".$this->db->escape($this->db->escapeforlike($aliasalt)).",%')";
339 }
340 if ($translationparentid && $translationparentlang) {
341 $sql .= " AND t.fk_page = ".((int) $translationparentid);
342 $sql .= " AND t.lang = '".$this->db->escape($translationparentlang)."'";
343 }
344 }
345 }
346 $sql .= $this->db->plimit(1);
347
348 $resql = $this->db->query($sql);
349 if ($resql) {
350 $numrows = $this->db->num_rows($resql);
351 if ($numrows) {
352 $obj = $this->db->fetch_object($resql);
353
354 $this->id = $obj->rowid;
355
356 $this->fk_website = $obj->fk_website;
357 $this->type_container = $obj->type_container;
358
359 $this->pageurl = $obj->pageurl;
360 $this->ref = $obj->pageurl;
361 $this->aliasalt = preg_replace('/,+$/', '', preg_replace('/^,+/', '', $obj->aliasalt));
362
363 $this->title = $obj->title;
364 $this->description = $obj->description;
365 $this->image = $obj->image;
366 $this->keywords = $obj->keywords;
367 $this->htmlheader = $obj->htmlheader;
368 $this->content = $obj->content;
369 $this->lang = $obj->lang;
370 $this->fk_page = $obj->fk_page;
371 $this->allowed_in_frames = $obj->allowed_in_frames;
372 $this->status = $obj->status;
373 $this->grabbed_from = $obj->grabbed_from;
374 $this->date_creation = $this->db->jdate($obj->date_creation);
375 $this->date_modification = $this->db->jdate($obj->date_modification);
376 $this->fk_user_creat = $obj->fk_user_creat;
377 $this->author_alias = $obj->author_alias;
378 $this->fk_user_modif = $obj->fk_user_modif;
379 $this->import_key = $obj->import_key;
380 $this->object_type = $obj->object_type;
381 $this->fk_object = $obj->fk_object;
382 }
383 $this->db->free($resql);
384
385 if ($numrows) {
386 return 1;
387 } else {
388 return 0;
389 }
390 } else {
391 $this->errors[] = 'Error '.$this->db->lasterror();
392 dol_syslog(__METHOD__.' '.implode(',', $this->errors), LOG_ERR);
393
394 return -1;
395 }
396 }
397
411 public function fetchAll($websiteid = '', $sortorder = '', $sortfield = '', $limit = 0, $offset = 0, $filter = '', $filtermode = 'AND')
412 {
413 dol_syslog(__METHOD__, LOG_DEBUG);
414
415 $records = array();
416
417 $sql = 'SELECT';
418 $sql .= ' t.rowid,';
419 $sql .= " t.fk_website,";
420 $sql .= " t.type_container,";
421 $sql .= " t.pageurl,";
422 $sql .= " t.aliasalt,";
423 $sql .= " t.title,";
424 $sql .= " t.description,";
425 $sql .= " t.image,";
426 $sql .= " t.keywords,";
427 $sql .= " t.htmlheader,";
428 $sql .= " t.content,";
429 $sql .= " t.lang,";
430 $sql .= " t.fk_page,";
431 $sql .= " t.allowed_in_frames,";
432 $sql .= " t.status,";
433 $sql .= " t.grabbed_from,";
434 $sql .= " t.date_creation,";
435 $sql .= " t.tms as date_modification,";
436 $sql .= " t.fk_user_creat,";
437 $sql .= " t.author_alias,";
438 $sql .= " t.fk_user_modif,";
439 $sql .= " t.import_key,";
440 $sql .= " t.object_type,";
441 $sql .= " t.fk_object";
442 $sql .= ' FROM '.MAIN_DB_PREFIX.$this->table_element.' as t';
443 if (!empty($websiteid)) {
444 $sql .= ' WHERE t.fk_website = '.((int) $websiteid);
445 }
446
447 // Deprecated. If we receive an array, we use it. Prefer using the USF syntax.
448 if (is_array($filter)) {
449 $sqlwhere = array();
450
451 if (count($filter) > 0) {
452 foreach ($filter as $key => $value) {
453 if ($key == 't.rowid' || $key == 'rowid' || $key == 't.fk_website' || $key == 'fk_website' || $key == 'status' || $key == 't.status') {
454 $sqlwhere[] = $key." = ".((int) $value);
455 } elseif ($key == 'type_container' || $key == 't.type_container') {
456 $sqlwhere[] = $key." = '".$this->db->escape($value)."'";
457 } elseif ($key == 'lang' || $key == 't.lang') {
458 $listoflang = array();
459 $foundnull = 0;
460 foreach (explode(',', $value) as $tmpvalue) {
461 if ($tmpvalue == 'null') {
462 $foundnull++;
463 continue;
464 }
465 $listoflang[] = "'".$this->db->escape(substr(str_replace("'", '', $tmpvalue), 0, 2))."'";
466 }
467 $stringtouse = $this->db->sanitize($key)." IN (".$this->db->sanitize(implode(',', $listoflang), 1).")";
468 if ($foundnull) {
469 $stringtouse = "(".$stringtouse." OR ".$this->db->sanitize($key)." IS NULL)";
470 }
471 $sqlwhere[] = $stringtouse;
472 } else {
473 $sqlwhere[] = $this->db->sanitize($key)." LIKE '%".$this->db->escape($value)."%'";
474 }
475 }
476 }
477 if (count($sqlwhere) > 0) {
478 if (!empty($websiteid)) {
479 $sql .= " AND (".implode(' '.$this->db->escape($filtermode).' ', $sqlwhere).')';
480 } else {
481 $sql .= " WHERE ".implode(' '.$this->db->escape($filtermode).' ', $sqlwhere);
482 }
483 }
484
485 $filter = '';
486 }
487
488 $errormessage = '';
489 $sql .= forgeSQLFromUniversalSearchCriteria($filter, $errormessage);
490 if ($errormessage) {
491 $this->errors[] = $errormessage;
492 dol_syslog(__METHOD__.' '.implode(',', $this->errors), LOG_ERR);
493 return -1;
494 }
495
496 if (!empty($sortfield)) {
497 $sql .= $this->db->order($sortfield, $sortorder);
498 }
499 if (!empty($limit)) {
500 $sql .= $this->db->plimit($limit, $offset);
501 }
502
503 $resql = $this->db->query($sql);
504 if ($resql) {
505 $num = $this->db->num_rows($resql);
506
507 while ($obj = $this->db->fetch_object($resql)) {
508 $record = new self($this->db);
509
510 $record->id = $obj->rowid;
511 $record->fk_website = $obj->fk_website;
512 $record->type_container = $obj->type_container;
513 $record->pageurl = $obj->pageurl;
514 $record->aliasalt = preg_replace('/,+$/', '', preg_replace('/^,+/', '', $obj->aliasalt));
515 $record->title = $obj->title;
516 $record->description = $obj->description;
517 $record->image = $obj->image;
518 $record->keywords = $obj->keywords;
519 $record->htmlheader = $obj->htmlheader;
520 $record->content = $obj->content;
521 $record->lang = $obj->lang;
522 $record->fk_page = $obj->fk_page;
523 $record->allowed_in_frames = $obj->allowed_in_frames;
524 $record->status = $obj->status;
525 $record->grabbed_from = $obj->grabbed_from;
526 $record->date_creation = $this->db->jdate($obj->date_creation);
527 $record->date_modification = $this->db->jdate($obj->date_modification);
528 $record->fk_user_creat = $obj->fk_user_creat;
529 $record->author_alias = $obj->author_alias;
530 $record->fk_user_modif = $obj->fk_user_modif;
531 $record->import_key = $obj->import_key;
532 $record->object_type = $obj->object_type;
533 $record->fk_object = $obj->fk_object;
534 //var_dump($record->id);
535 $records[$record->id] = $record;
536 }
537 $this->db->free($resql);
538
539 return $records;
540 } else {
541 $this->error = 'Error '.$this->db->lasterror();
542 $this->errors[] = $this->error;
543 dol_syslog(__METHOD__.' '.implode(',', $this->errors), LOG_ERR);
544
545 return -1;
546 }
547 }
548
558 public function countAll($websiteid, $filter = '', $filtermode = 'AND')
559 {
560 dol_syslog(__METHOD__, LOG_DEBUG);
561
562 $result = 0;
563
564 $sql = 'SELECT COUNT(t.rowid) as nb';
565 $sql .= ' FROM '.MAIN_DB_PREFIX.$this->table_element.' as t';
566 $sql .= ' WHERE t.fk_website = '.((int) $websiteid);
567
568 // Deprecated. If we receive an array, we use it. Prefer using the USF syntax.
569 if (is_array($filter)) {
570 $sqlwhere = array();
571
572 if (count($filter) > 0) {
573 foreach ($filter as $key => $value) {
574 if ($key == 't.rowid' || $key == 'rowid' || $key == 't.fk_website' || $key == 'fk_website' || $key == 'status' || $key == 't.status') {
575 $sqlwhere[] = $key." = ".((int) $value);
576 } elseif ($key == 'type_container' || $key == 't.type_container') {
577 $sqlwhere[] = $key." = '".$this->db->escape($value)."'";
578 } elseif ($key == 'lang' || $key == 't.lang') {
579 $listoflang = array();
580 $foundnull = 0;
581 foreach (explode(',', $value) as $tmpvalue) {
582 if ($tmpvalue == 'null') {
583 $foundnull++;
584 continue;
585 }
586 $listoflang[] = "'".$this->db->escape(substr(str_replace("'", '', $tmpvalue), 0, 2))."'";
587 }
588 $stringtouse = $this->db->sanitize($key)." IN (".$this->db->sanitize(implode(',', $listoflang), 1).")";
589 if ($foundnull) {
590 $stringtouse = "(".$stringtouse." OR ".$this->db->sanitize($key)." IS NULL)";
591 }
592 $sqlwhere[] = $stringtouse;
593 } else {
594 $sqlwhere[] = $this->db->sanitize($key)." LIKE '%".$this->db->escape($value)."%'";
595 }
596 }
597 }
598 if (count($sqlwhere) > 0) {
599 if (!empty($websiteid)) {
600 $sql .= " AND (".implode(' '.$this->db->escape($filtermode).' ', $sqlwhere).')';
601 } else {
602 $sql .= " WHERE ".implode(' '.$this->db->escape($filtermode).' ', $sqlwhere);
603 }
604 }
605
606 $filter = '';
607 }
608
609 $errormessage = '';
610 $sql .= forgeSQLFromUniversalSearchCriteria($filter, $errormessage);
611 if ($errormessage) {
612 $this->errors[] = $errormessage;
613 dol_syslog(__METHOD__.' '.implode(',', $this->errors), LOG_ERR);
614 return -1;
615 }
616
617 $resql = $this->db->query($sql);
618 if ($resql) {
619 $obj = $this->db->fetch_object($resql);
620 if ($obj) {
621 $result = $obj->nb;
622 }
623
624 $this->db->free($resql);
625
626 return $result;
627 } else {
628 $this->error = 'Error '.$this->db->lasterror();
629 $this->errors[] = $this->error;
630 dol_syslog(__METHOD__.' '.implode(',', $this->errors), LOG_ERR);
631
632 return -1;
633 }
634 }
635
643 public function update(User $user, $notrigger = 0)
644 {
645 $this->description = dol_trunc($this->description, 255, 'right', 'utf-8', 1);
646 $this->keywords = dol_trunc($this->keywords, 255, 'right', 'utf-8', 1);
647 if ($this->aliasalt) {
648 $this->aliasalt = ','.preg_replace('/,+$/', '', preg_replace('/^,+/', '', $this->aliasalt)).','; // content in database must be ',xxx,...,yyy,'
649 }
650
651 $this->pageurl = preg_replace('/[^a-z0-9\-\_]/i', '', $this->pageurl);
652 $this->pageurl = preg_replace('/\-\-+/', '-', $this->pageurl);
653 $this->pageurl = preg_replace('/^\-/', '', $this->pageurl);
654
655 // Remove spaces and be sure we have main language only
656 $this->lang = preg_replace('/[_-].*$/', '', trim($this->lang)); // en_US or en-US -> en
657
658 if ($this->fk_page > 0) {
659 if (empty($this->lang)) {
660 $this->error = "ErrorLanguageMandatoryIfPageSetAsTranslationOfAnother";
661 return -1;
662 }
663 $tmppage = new WebsitePage($this->db);
664 $tmppage->fetch($this->fk_page);
665 if ($tmppage->lang == $this->lang) {
666 $this->error = "ErrorLanguageOfTranslatedPageIsSameThanThisPage";
667 return -1;
668 }
669 }
670
671 return $this->updateCommon($user, $notrigger);
672 }
673
681 public function delete(User $user, $notrigger = 0)
682 {
683 global $conf;
684
685 $error = 0;
686
687 // Delete all child tables
688 if (!$error) {
689 foreach ($this->childtablesoncascade as $table) {
690 $sql = "DELETE FROM ".MAIN_DB_PREFIX.$table;
691 $sql .= " WHERE fk_website_page = ".(int) $this->id;
692
693 $result = $this->db->query($sql);
694 if (!$result) {
695 $error++;
696 $this->errors[] = $this->db->lasterror();
697 break;
698 }
699 }
700 }
701
702 if (!$error) {
703 $result = $this->deleteCommon($user, $notrigger);
704 if ($result <= 0) {
705 $error++;
706 }
707 }
708
709 if (!$error) {
710 $websiteobj = new Website($this->db);
711 $result = $websiteobj->fetch($this->fk_website);
712
713 if ($result > 0) {
714 global $dolibarr_main_data_root;
715 $pathofwebsite = $dolibarr_main_data_root.($conf->entity > 1 ? '/'.$conf->entity : '').'/website/'.$websiteobj->ref;
716
717 $filealias = $pathofwebsite.'/'.$this->pageurl.'.php';
718 $filetpl = $pathofwebsite.'/page'.$this->id.'.tpl.php';
719
720 dol_delete_file($filealias);
721 dol_delete_file($filetpl);
722 } else {
723 $this->error = $websiteobj->error;
724 $this->errors = $websiteobj->errors;
725 }
726 }
727
728 if (!$error) {
729 return 1;
730 } else {
731 return -1;
732 }
733 }
734
748 public function createFromClone(User $user, $fromid, $newref, $newlang = '', $istranslation = 0, $newwebsite = 0, $newtitle = '', $website = null)
749 {
750 global $hookmanager, $langs;
751
752 $now = dol_now();
753 $error = 0;
754
755 dol_syslog(__METHOD__, LOG_DEBUG);
756
757 $object = new self($this->db);
758
759 // Clean parameters
760 if (empty($newref) && !empty($newtitle)) {
761 $newref = strtolower(dol_sanitizeFileName(preg_replace('/\s+/', '-', $newtitle), '-', 1));
762 }
763
764 // Check parameters
765 if (empty($newref)) {
766 $langs->load("errors");
767 $this->error = $langs->trans("ErrorFieldRequired", $langs->transnoentitiesnoconv("WEBSITE_TITLE"));
768 return -1;
769 }
770
771 if ($istranslation) {
772 if (is_null($website)) {
773 $website = new Website($this->db);
774 }
775 $website->fetch($object->fk_website);
776
777 if ($website->id != $newwebsite) {
778 $langs->load("errors");
779 $this->error = $langs->trans("WebsiteMustBeSameThanClonedPageIfTranslation");
780 return -1;
781 }
782 }
783
784 $this->db->begin();
785
786 // Load source object
787 $object->fetch($fromid);
788 // Reset object
789 $object->id = 0;
790
791 // Clear fields
792 $object->ref = $newref;
793 $object->pageurl = $newref;
794 $object->aliasalt = '';
795 $object->fk_user_creat = $user->id;
796 $object->author_alias = '';
797 $object->date_creation = $now;
798 $object->title = ($newtitle == '1' ? $object->title : ($newtitle ? $newtitle : $object->title));
799 $object->description = $object->title;
800 if (!empty($newlang)) {
801 $object->lang = $newlang;
802 }
803
804 if ($istranslation) {
805 if ($website->lang == $newlang) {
806 // The new page is into the website language, the parent page will be 0, and we must instead update the source page later.
807 $object->fk_page = 0;
808 } else {
809 $object->fk_page = $fromid;
810 }
811 } else {
812 $object->fk_page = 0;
813 }
814
815 if (!empty($newwebsite)) {
816 $object->fk_website = $newwebsite;
817 }
818 $object->import_key = '';
819 $object->status = self::STATUS_DRAFT;
820
821 // Create clone
822 $object->context['createfromclone'] = 'createfromclone';
823 $result = $object->create($user);
824 if ($result < 0) {
825 $error++;
826 $this->error = $object->error;
827 $this->errors = $object->errors;
828 dol_syslog(__METHOD__.' '.implode(',', $this->errors), LOG_ERR);
829 }
830
831 if ($istranslation) {
832 if ($website->lang == $newlang) {
833 // We must now update the source page to link to the new page as a translation of.
834 $sql = "UPDATE ".MAIN_DB_PREFIX."website_page SET fk_page = ".((int) $result)." WHERE rowid = ".((int) $fromid);
835
836 $result = $this->db->query($sql);
837 if (!$result) {
838 $error++;
839 $this->error = $this->db->lasterror();
840 }
841 }
842 }
843
844 unset($object->context['createfromclone']);
845
846 // End
847 if (!$error) {
848 $this->db->commit();
849
850 return $object;
851 } else {
852 $this->db->rollback();
853
854 return -1;
855 }
856 }
857
869 public function getNomUrl($withpicto = 0, $option = '', $notooltip = 0, $maxlen = 24, $morecss = '')
870 {
871 global $langs, $conf, $db;
872 global $dolibarr_main_authentication, $dolibarr_main_demo;
873 global $menumanager;
874
875 $result = '';
876
877 $label = '<u>'.$langs->trans("Page").'</u>';
878 $label .= '<br>';
879 $label .= '<b>'.$langs->trans('Ref').':</b> '.$this->ref.'<br>';
880 $label .= '<b>'.$langs->trans('ID').':</b> '.$this->id.'<br>';
881 $label .= '<b>'.$langs->trans('Title').':</b> '.$this->title.'<br>';
882 $label .= '<b>'.$langs->trans('Language').':</b> '.$this->lang;
883
884 $url = DOL_URL_ROOT.'/website/index.php?websiteid='.$this->fk_website.'&pageid='.$this->id;
885
886 $linkclose = '';
887 if (empty($notooltip)) {
888 if (getDolGlobalString('MAIN_OPTIMIZEFORTEXTBROWSER')) {
889 $label = $langs->trans("ShowMyObject");
890 $linkclose .= ' alt="'.dol_escape_htmltag($label, 1).'"';
891 }
892 $linkclose .= ' title="'.dol_escape_htmltag($label, 1).'"';
893 $linkclose .= ' class="classfortooltip'.($morecss ? ' '.$morecss : '').'"';
894 } else {
895 $linkclose = ($morecss ? ' class="'.$morecss.'"' : '');
896 }
897
898 $linkstart = '<a href="'.$url.'"';
899 $linkstart .= $linkclose.'>';
900 $linkend = '</a>';
901
902 //$linkstart = $linkend = '';
903
904 $result .= $linkstart;
905 if ($withpicto) {
906 $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);
907 }
908 if ($withpicto != 2) {
909 $result .= $this->ref;
910 }
911 $result .= $linkend;
912
913 return $result;
914 }
915
922 public function getLibStatut($mode = 0)
923 {
924 return $this->LibStatut($this->status, $mode);
925 }
926
927 // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
935 public function LibStatut($status, $mode = 0)
936 {
937 // phpcs:enable
938 global $langs;
939
940 if (empty($this->labelStatus) || empty($this->labelStatusShort)) {
941 global $langs;
942 //$langs->load("mymodule");
943 $this->labelStatus[self::STATUS_DRAFT] = $langs->transnoentitiesnoconv('Offline');
944 $this->labelStatus[self::STATUS_VALIDATED] = $langs->transnoentitiesnoconv('Online');
945 $this->labelStatusShort[self::STATUS_DRAFT] = $langs->transnoentitiesnoconv('Offline');
946 $this->labelStatusShort[self::STATUS_VALIDATED] = $langs->transnoentitiesnoconv('Online');
947 }
948
949 $statusType = 'status5';
950 if ($status == self::STATUS_VALIDATED) {
951 $statusType = 'status4';
952 }
953
954 return dolGetStatus($this->labelStatus[$status], $this->labelStatusShort[$status], '', $statusType, $mode);
955 }
956
967 public function setCategories($categories)
968 {
969 require_once DOL_DOCUMENT_ROOT.'/categories/class/categorie.class.php';
970 return $this->setCategoriesCommon($categories, Categorie::TYPE_WEBSITE_PAGE);
971 }
972
979 public function initAsSpecimen()
980 {
981 global $user;
982
983 $this->id = 0;
984
985 $now = dol_now();
986
987 $this->fk_website = 0;
988 $this->type_container = 'page';
989 $this->pageurl = 'specimen';
990 $this->aliasalt = 'specimenalt';
991 $this->title = 'My Page';
992 $this->description = 'This is my page';
993 $this->image = '';
994 $this->keywords = 'keyword1, keyword2';
995 $this->allowed_in_frames = 1;
996 $this->htmlheader = '';
997 $this->content = '<html><body>This is a html content</body></html>';
998 $this->status = self::STATUS_DRAFT;
999 $this->grabbed_from = '';
1000 $this->date_creation = $now - (24 * 30 * 3600);
1001 $this->date_modification = $now - (24 * 7 * 3600);
1002 $this->fk_user_creat = $user->id;
1003 $this->author_alias = 'mypublicpseudo';
1004
1005 return 1;
1006 }
1007}
if( $user->socid > 0) if(! $user->hasRight('accounting', 'chartofaccount')) $object
Definition card.php:66
$object ref
Definition info.php:89
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.
fetch($id, $website_id=null, $page=null, $aliasalt=null, $translationparentid=0, $translationparentlang='')
Load object in memory from 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.
LibStatut($status, $mode=0)
Return the label of a given status.
createFromClone(User $user, $fromid, $newref, $newlang='', $istranslation=0, $newwebsite=0, $newtitle='', $website=null)
Load an object from its id and create a new one in database.
fetchAll($websiteid='', $sortorder='', $sortfield='', $limit=0, $offset=0, $filter='', $filtermode='AND')
Return array of all web site pages.
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,...
countAll($websiteid, $filter='', $filtermode='AND')
Count objects in the database.
print $langs trans("Ref").' m titre as m m statut as status
Or an array listing all the potential status of the object: array: int of the status => translated la...
Definition index.php:171
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.
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.
getDolGlobalString($key, $default='')
Return a Dolibarr global constant string value.
dol_syslog($message, $level=LOG_INFO, $ident=0, $suffixinfilename='', $restricttologhandler='', $logcontext=null)
Write log message into outputs.
global $conf
The following vars must be defined: $type2label $form $conf, $lang, The following vars may also be de...
Definition member.php:79