29 require_once DOL_DOCUMENT_ROOT.
'/core/class/commonobject.class.php';
41 public $element =
'website';
46 public $table_element =
'website';
51 public $ismultientitymanaged = 1;
56 public $picto =
'globe';
91 public $date_creation;
96 public $date_modification;
101 public $fk_default_home;
106 public $fk_user_creat;
116 public $use_manifest;
131 const STATUS_DRAFT = 0;
132 const STATUS_VALIDATED = 1;
156 global $conf, $langs;
164 if (isset($this->entity)) {
165 $this->entity = (int) $this->entity;
167 if (isset($this->ref)) {
168 $this->ref = trim($this->ref);
173 if (isset($this->status)) {
174 $this->status = (int) $this->status;
176 if (empty($this->date_creation)) {
177 $this->date_creation = $now;
179 if (empty($this->date_modification)) {
180 $this->date_modification = $now;
183 $this->lang = preg_replace(
'/[_-].*$/',
'', trim($this->lang));
184 $tmparray = explode(
',', $this->otherlang);
185 if (is_array($tmparray)) {
186 foreach ($tmparray as $key => $val) {
187 $tmparray[$key] = preg_replace(
'/[_-].*$/',
'', trim($val));
189 $this->otherlang = join(
',', $tmparray);
193 if (empty($this->entity)) {
194 $this->entity = $conf->entity;
196 if (empty($this->lang)) {
197 $this->error = $langs->trans(
"ErrorFieldRequired", $langs->transnoentitiesnoconv(
"MainLanguage"));
202 $sql =
'INSERT INTO '.MAIN_DB_PREFIX.$this->table_element.
'(';
205 $sql .=
'description,';
207 $sql .=
'otherlang,';
209 $sql .=
'fk_default_home,';
210 $sql .=
'virtualhost,';
211 $sql .=
'fk_user_creat,';
212 $sql .=
'date_creation,';
215 $sql .=
') VALUES (';
216 $sql .=
' '.((empty($this->entity) && $this->entity !=
'0') ?
'NULL' : $this->entity).
',';
217 $sql .=
' '.(!isset($this->ref) ?
'NULL' :
"'".$this->db->escape($this->ref).
"'").
',';
219 $sql .=
' '.(!isset($this->lang) ?
'NULL' :
"'".$this->db->escape($this->lang).
"'").
',';
220 $sql .=
' '.(!isset($this->otherlang) ?
'NULL' :
"'".$this->db->escape($this->otherlang).
"'").
',';
221 $sql .=
' '.(!isset($this->status) ?
'1' : $this->status).
',';
222 $sql .=
' '.(!isset($this->fk_default_home) ?
'NULL' : $this->fk_default_home).
',';
223 $sql .=
' '.(!isset($this->virtualhost) ?
'NULL' :
"'".$this->db->escape($this->virtualhost).
"'").
",";
224 $sql .=
' '.(!isset($this->fk_user_creat) ? $user->id : $this->fk_user_creat).
',';
225 $sql .=
' '.(!isset($this->date_creation) ||
dol_strlen($this->date_creation) == 0 ?
'NULL' :
"'".$this->db->idate($this->date_creation).
"'").
",";
226 $sql .=
' '.((int) $this->position).
",";
227 $sql .=
' '.(!isset($this->date_modification) ||
dol_strlen($this->date_modification) == 0 ?
'NULL' :
"'".$this->db->idate($this->date_modification).
"'");
235 $this->errors[] =
'Error '.$this->db->lasterror();
236 dol_syslog(__METHOD__.
' '.join(
',', $this->errors), LOG_ERR);
240 $this->
id = $this->
db->last_insert_id(MAIN_DB_PREFIX.$this->table_element);
243 $tmplangarray = explode(
',', $this->otherlang);
244 if (is_array($tmplangarray)) {
245 dol_mkdir($conf->website->dir_output.
'/'.$this->ref);
246 foreach ($tmplangarray as $val) {
247 if (trim($val) == $this->lang)
continue;
248 dol_mkdir($conf->website->dir_output.
'/'.$this->ref.
'/'.trim($val));
264 $stringtodolibarrfile =
"# Some properties for Dolibarr web site CMS\n";
265 $stringtodolibarrfile .=
"param=value\n";
267 file_put_contents($conf->website->dir_output.
'/'.$this->ref.
'/.dolibarr', $stringtodolibarrfile);
272 $this->
db->rollback();
289 public function fetch($id, $ref = null)
295 $sql .=
" t.entity,";
297 $sql .=
" t.position,";
298 $sql .=
" t.description,";
300 $sql .=
" t.otherlang,";
301 $sql .=
" t.status,";
302 $sql .=
" t.fk_default_home,";
303 $sql .=
" t.use_manifest,";
304 $sql .=
" t.virtualhost,";
305 $sql .=
" t.fk_user_creat,";
306 $sql .=
" t.fk_user_modif,";
307 $sql .=
" t.date_creation,";
308 $sql .=
" t.tms as date_modification";
309 $sql .=
' FROM '.MAIN_DB_PREFIX.$this->table_element.
' as t';
310 $sql .=
' WHERE t.entity IN ('.getEntity(
'website').
')';
312 $sql .=
" AND t.ref = '".$this->db->escape($ref).
"'";
314 $sql .=
' AND t.rowid = '.(int) $id;
319 $numrows = $this->
db->num_rows(
$resql);
321 $obj = $this->
db->fetch_object(
$resql);
323 $this->
id = $obj->rowid;
325 $this->entity = $obj->entity;
326 $this->ref = $obj->ref;
327 $this->position = $obj->position;
329 $this->lang = $obj->lang;
330 $this->otherlang = $obj->otherlang;
331 $this->status = $obj->status;
332 $this->fk_default_home = $obj->fk_default_home;
333 $this->virtualhost = $obj->virtualhost;
334 $this->use_manifest = $obj->use_manifest;
335 $this->fk_user_creat = $obj->fk_user_creat;
336 $this->fk_user_modif = $obj->fk_user_modif;
337 $this->date_creation = $this->
db->jdate($obj->date_creation);
338 $this->date_modification = $this->
db->jdate($obj->date_modification);
353 $this->errors[] =
'Error '.$this->db->lasterror();
354 dol_syslog(__METHOD__.
' '.join(
',', $this->errors), LOG_ERR);
367 $this->lines = array();
371 return count($this->lines) ? 1 : 0;
387 public function fetchAll($sortorder =
'', $sortfield =
'', $limit = 0, $offset = 0, array $filter = array(), $filtermode =
'AND')
393 $sql .=
" t.entity,";
395 $sql .=
" t.description,";
397 $sql .=
" t.otherlang,";
398 $sql .=
" t.status,";
399 $sql .=
" t.fk_default_home,";
400 $sql .=
" t.virtualhost,";
401 $sql .=
" t.fk_user_creat,";
402 $sql .=
" t.fk_user_modif,";
403 $sql .=
" t.date_creation,";
404 $sql .=
" t.tms as date_modification";
405 $sql .=
' FROM '.MAIN_DB_PREFIX.$this->table_element.
' as t';
406 $sql .=
' WHERE t.entity IN ('.getEntity(
'website').
')';
409 if (count($filter) > 0) {
410 foreach ($filter as $key => $value) {
411 $sqlwhere [] = $key.
' LIKE \'%'.$this->
db->escape($value).
'%\'';
414 if (count($sqlwhere) > 0) {
415 $sql .=
' AND '.implode(
' '.$filtermode.
' ', $sqlwhere);
418 if (!empty($sortfield)) {
419 $sql .= $this->
db->order($sortfield, $sortorder);
421 if (!empty($limit)) {
422 $sql .=
' '.$this->db->plimit($limit, $offset);
424 $this->records = array();
430 while ($obj = $this->
db->fetch_object(
$resql)) {
431 $line =
new self($this->db);
433 $line->id = $obj->rowid;
435 $line->entity = $obj->entity;
436 $line->ref = $obj->ref;
437 $line->description = $obj->description;
438 $line->lang = $obj->lang;
439 $line->otherlang = $obj->otherlang;
440 $line->status = $obj->status;
441 $line->fk_default_home = $obj->fk_default_home;
442 $line->virtualhost = $obj->virtualhost;
443 $this->fk_user_creat = $obj->fk_user_creat;
444 $this->fk_user_modif = $obj->fk_user_modif;
445 $line->date_creation = $this->
db->jdate($obj->date_creation);
446 $line->date_modification = $this->
db->jdate($obj->date_modification);
448 $this->records[$line->id] = $line;
454 $this->errors[] =
'Error '.$this->db->lasterror();
455 dol_syslog(__METHOD__.
' '.join(
',', $this->errors), LOG_ERR);
471 global $conf, $langs;
479 if (isset($this->entity)) {
480 $this->entity = (int) $this->entity;
482 if (isset($this->ref)) {
483 $this->ref = trim($this->ref);
488 if (isset($this->status)) {
489 $this->status = (int) $this->status;
493 $this->lang = preg_replace(
'/[_-].*$/',
'', trim($this->lang));
494 $tmparray = explode(
',', $this->otherlang);
495 if (is_array($tmparray)) {
496 foreach ($tmparray as $key => $val) {
497 $tmparray[$key] = preg_replace(
'/[_-].*$/',
'', trim($val));
499 $this->otherlang = join(
',', $tmparray);
501 if (empty($this->lang)) {
502 $this->error = $langs->trans(
"ErrorFieldRequired", $langs->transnoentitiesnoconv(
"MainLanguage"));
510 $sql =
'UPDATE '.MAIN_DB_PREFIX.$this->table_element.
' SET';
511 $sql .=
' entity = '.(isset($this->entity) ? $this->entity :
"null").
',';
512 $sql .=
' ref = '.(isset($this->ref) ?
"'".$this->db->escape($this->ref).
"'" :
"null").
',';
513 $sql .=
' description = '.(isset($this->
description) ?
"'".$this->db->escape($this->
description).
"'" :
"null").
',';
514 $sql .=
' lang = '.(isset($this->lang) ?
"'".$this->db->escape($this->lang).
"'" :
"null").
',';
515 $sql .=
' otherlang = '.(isset($this->otherlang) ?
"'".$this->db->escape($this->otherlang).
"'" :
"null").
',';
516 $sql .=
' status = '.(isset($this->status) ? $this->status :
"null").
',';
517 $sql .=
' fk_default_home = '.(($this->fk_default_home > 0) ? $this->fk_default_home :
"null").
',';
518 $sql .=
' use_manifest = '.((int) $this->use_manifest).
',';
519 $sql .=
' virtualhost = '.(($this->virtualhost !=
'') ?
"'".$this->
db->escape($this->virtualhost).
"'" :
"null").
',';
520 $sql .=
' fk_user_modif = '.(!isset($this->fk_user_modif) ? $user->id : $this->fk_user_modif).
',';
521 $sql .=
' date_creation = '.(!isset($this->date_creation) ||
dol_strlen($this->date_creation) != 0 ?
"'".$this->db->idate($this->date_creation).
"'" :
'null').
',';
522 $sql .=
' tms = '.(dol_strlen($this->date_modification) != 0 ?
"'".$this->db->idate($this->date_modification).
"'" :
"'".$this->db->idate(
dol_now()).
"'");
523 $sql .=
' WHERE rowid='.$this->id;
530 $this->errors[] =
'Error '.$this->db->lasterror();
531 dol_syslog(__METHOD__.
' '.join(
',', $this->errors), LOG_ERR);
534 if (!$error && !$notrigger) {
539 $tmplangarray = explode(
',', $this->otherlang);
540 if (is_array($tmplangarray)) {
541 dol_mkdir($conf->website->dir_output.
'/'.$this->ref);
542 foreach ($tmplangarray as $val) {
543 if (trim($val) == $this->lang)
continue;
544 dol_mkdir($conf->website->dir_output.
'/'.$this->ref.
'/'.trim($val));
556 $this->
db->rollback();
574 public function delete(
User $user, $notrigger =
false)
595 $sql =
'DELETE FROM '.MAIN_DB_PREFIX.$this->table_element;
596 $sql .=
' WHERE rowid='.$this->id;
601 $this->errors[] =
'Error '.$this->db->lasterror();
602 dol_syslog(__METHOD__.
' '.join(
',', $this->errors), LOG_ERR);
606 if (!$error && !empty($this->ref))
608 $pathofwebsite = DOL_DATA_ROOT.
'/website/'.$this->ref;
615 $this->
db->rollback();
637 global $conf, $langs;
638 global $dolibarr_main_data_root;
645 $object =
new self($this->db);
648 if ($object->fetch(0, $newref) > 0)
650 $this->error =
'ErrorNewRefIsAlreadyUsed';
657 $object->fetch($fromid);
659 $oldidforhome = $object->fk_default_home;
660 $oldref = $object->ref;
662 $pathofwebsiteold = $dolibarr_main_data_root.
'/website/'.$oldref;
663 $pathofwebsitenew = $dolibarr_main_data_root.
'/website/'.$newref;
666 $fileindex = $pathofwebsitenew.
'/index.php';
670 unset($object->fk_user_creat);
671 unset($object->import_key);
674 $object->ref = $newref;
675 $object->fk_default_home = 0;
676 $object->virtualhost =
'';
677 $object->date_creation = $now;
678 $object->fk_user_creat = $user->id;
679 $object->position = ((int) $object->position) + 1;
680 $object->status = self::STATUS_DRAFT;
681 if (empty($object->lang)) $object->lang = substr($langs->defaultlang, 0, 2);
684 $object->context[
'createfromclone'] =
'createfromclone';
685 $result = $object->create($user);
688 $this->error = $object->error;
689 $this->errors = $object->errors;
690 dol_syslog(__METHOD__.
' '.join(
',', $this->errors), LOG_ERR);
695 dolCopyDir($pathofwebsiteold, $pathofwebsitenew, $conf->global->MAIN_UMASK, 0, null, 2);
698 $pathtomedias = DOL_DATA_ROOT.
'/medias';
699 $pathtomediasinwebsite = $pathofwebsitenew.
'/medias';
702 dol_syslog(
"Create symlink for ".$pathtomedias.
" into name ".$pathtomediasinwebsite);
703 dol_mkdir(dirname($pathtomediasinwebsite));
704 $result = symlink($pathtomedias, $pathtomediasinwebsite);
708 $pathofmediasjsold = DOL_DATA_ROOT.
'/medias/js/'.$oldref;
709 $pathofmediasjsnew = DOL_DATA_ROOT.
'/medias/js/'.$newref;
710 dolCopyDir($pathofmediasjsold, $pathofmediasjsnew, $conf->global->MAIN_UMASK, 0);
712 $pathofmediasimageold = DOL_DATA_ROOT.
'/medias/image/'.$oldref;
713 $pathofmediasimagenew = DOL_DATA_ROOT.
'/medias/image/'.$newref;
714 dolCopyDir($pathofmediasimageold, $pathofmediasimagenew, $conf->global->MAIN_UMASK, 0);
720 $listofpages = $objectpages->fetchAll($fromid);
721 foreach ($listofpages as $pageid => $objectpageold)
724 $filetplold = $pathofwebsitenew.
'/page'.$pageid.
'.tpl.php';
728 $objectpagenew = $objectpageold->createFromClone($user, $pageid, $objectpageold->pageurl,
'', 0, $object->id, 1);
731 if (is_object($objectpagenew) && $objectpagenew->pageurl)
733 $filealias = $pathofwebsitenew.
'/'.$objectpagenew->pageurl.
'.php';
734 $filetplnew = $pathofwebsitenew.
'/page'.$objectpagenew->id.
'.tpl.php';
738 if (!$result)
setEventMessages(
'Failed to write file '.$filealias, null,
'errors');
741 if (!$result)
setEventMessages(
'Failed to write file '.$filetplnew, null,
'errors');
743 if ($pageid == $oldidforhome)
745 $newidforhome = $objectpagenew->id;
758 $object->fk_default_home = $newidforhome;
759 $res = $object->update($user);
768 $filetpl = $pathofwebsitenew.
'/page'.$newidforhome.
'.tpl.php';
769 $filewrapper = $pathofwebsitenew.
'/wrapper.php';
773 $result =
dolSaveIndexPage($pathofwebsitenew, $fileindex, $filetpl, $filewrapper);
777 unset($object->context[
'createfromclone']);
785 $this->
db->rollback();
802 public function getNomUrl($withpicto = 0, $option =
'', $notooltip = 0, $maxlen = 24, $morecss =
'')
804 global $langs, $conf, $db;
805 global $dolibarr_main_authentication, $dolibarr_main_demo;
812 $label =
'<u>'.$langs->trans(
"WebSite").
'</u>';
814 $label .=
'<b>'.$langs->trans(
'Ref').
':</b> '.$this->ref.
'<br>';
815 $label .=
'<b>'.$langs->trans(
'MainLanguage').
':</b> '.$this->lang;
817 $linkstart =
'<a href="'.DOL_URL_ROOT.
'/website/card.php?id='.$this->
id.
'"';
818 $linkstart .= ($notooltip ?
'' :
' title="'.dol_escape_htmltag($label, 1).
'" class="classfortooltip'.($morecss ?
' '.$morecss :
'').
'"');
822 $linkstart = $linkend =
'';
826 $result .= ($linkstart.img_object(($notooltip ?
'' : $label), ($this->picto ? $this->picto :
'generic'), ($notooltip ?
'' :
'class="classfortooltip"')).$linkend);
827 if ($withpicto != 2) $result .=
' ';
829 $result .= $linkstart.$this->ref.$linkend;
841 return $this->
LibStatut($this->status, $mode);
857 if (empty($this->labelStatus) || empty($this->labelStatusShort))
861 $this->labelStatus[self::STATUS_DRAFT] = $langs->trans(
'Disabled');
862 $this->labelStatus[self::STATUS_VALIDATED] = $langs->trans(
'Enabled');
863 $this->labelStatusShort[self::STATUS_DRAFT] = $langs->trans(
'Disabled');
864 $this->labelStatusShort[self::STATUS_VALIDATED] = $langs->trans(
'Enabled');
867 $statusType =
'status5';
868 if ($status == self::STATUS_VALIDATED) $statusType =
'status4';
870 return dolGetStatus($this->labelStatus[$status], $this->labelStatusShort[$status],
'', $statusType, $mode);
887 $this->ref =
'myspecimenwebsite';
890 $this->otherlang =
'fr,es';
892 $this->fk_default_home = null;
893 $this->virtualhost =
'http://myvirtualhost';
894 $this->fk_user_creat = $user->id;
895 $this->fk_user_modif = $user->id;
896 $this->date_creation =
dol_now();
908 global $conf, $mysoc;
912 if (empty($website->id) || empty($website->ref))
918 dol_syslog(
"Create temp dir ".$conf->website->dir_temp);
920 if (!is_writable($conf->website->dir_temp))
922 setEventMessages(
"Temporary dir ".$conf->website->dir_temp.
" is not writable", null,
'errors');
926 $destdir = $conf->website->dir_temp.
'/'.$website->ref;
929 $count = 0; $countreallydeleted = 0;
931 if ($counttodelete != $countreallydeleted)
933 setEventMessages(
"Failed to clean temp directory ".$destdir, null,
'errors');
937 $arrayreplacementinfilename = array();
938 $arrayreplacementincss = array();
939 $arrayreplacementincss[
'file=image/'.$website->ref.
'/'] =
"file=image/__WEBSITE_KEY__/";
940 $arrayreplacementincss[
'file=js/'.$website->ref.
'/'] =
"file=js/__WEBSITE_KEY__/";
941 $arrayreplacementincss[
'medias/image/'.$website->ref.
'/'] =
"medias/image/__WEBSITE_KEY__/";
942 $arrayreplacementincss[
'medias/js/'.$website->ref.
'/'] =
"medias/js/__WEBSITE_KEY__/";
943 if ($mysoc->logo_small) {
944 $arrayreplacementincss[
'file=logos%2Fthumbs%2F'.$mysoc->logo_small] =
"file=logos%2Fthumbs%2F__LOGO_SMALL_KEY__";
946 if ($mysoc->logo_mini) {
947 $arrayreplacementincss[
'file=logos%2Fthumbs%2F'.$mysoc->logo_mini] =
"file=logos%2Fthumbs%2F__LOGO_MINI_KEY__";
950 $arrayreplacementincss[
'file=logos%2Fthumbs%2F'.$mysoc->logo] =
"file=logos%2Fthumbs%2F__LOGO_KEY__";
955 dol_mkdir($conf->website->dir_temp.
'/'.$website->ref.
'/containers');
956 dol_mkdir($conf->website->dir_temp.
'/'.$website->ref.
'/medias/image/websitekey');
957 dol_mkdir($conf->website->dir_temp.
'/'.$website->ref.
'/medias/js/websitekey');
960 $srcdir = $conf->website->dir_output.
'/'.$website->ref;
961 $destdir = $conf->website->dir_temp.
'/'.$website->ref.
'/containers';
963 dol_syslog(
"Copy content from ".$srcdir.
" into ".$destdir);
964 dolCopyDir($srcdir, $destdir, 0, 1, $arrayreplacementinfilename, 2);
967 $srcdir = DOL_DATA_ROOT.
'/medias/image/'.$website->ref;
968 $destdir = $conf->website->dir_temp.
'/'.$website->ref.
'/medias/image/websitekey';
970 dol_syslog(
"Copy content from ".$srcdir.
" into ".$destdir);
971 dolCopyDir($srcdir, $destdir, 0, 1, $arrayreplacementinfilename);
974 $srcdir = DOL_DATA_ROOT.
'/medias/js/'.$website->ref;
975 $destdir = $conf->website->dir_temp.
'/'.$website->ref.
'/medias/js/websitekey';
977 dol_syslog(
"Copy content from ".$srcdir.
" into ".$destdir);
978 dolCopyDir($srcdir, $destdir, 0, 1, $arrayreplacementinfilename);
981 $cssindestdir = $conf->website->dir_temp.
'/'.$website->ref.
'/containers/styles.css.php';
984 $htmldeaderindestdir = $conf->website->dir_temp.
'/'.$website->ref.
'/containers/htmlheader.html';
988 $filesql = $conf->website->dir_temp.
'/'.$website->ref.
'/website_pages.sql';
989 $fp = fopen($filesql,
"w");
997 $listofpages = $objectpages->fetchAll($website->id);
1001 foreach ($listofpages as $pageid => $objectpageold)
1003 $objectpageold->newid = $i;
1007 foreach ($listofpages as $pageid => $objectpageold)
1011 foreach ($listofpages as $pageid2 => $objectpageold2)
1013 if ($pageid2 == $objectpageold->fk_page)
1015 $newfk_page = $objectpageold2->newid;
1019 $objectpageold->newfk_page = $newfk_page;
1022 foreach ($listofpages as $pageid => $objectpageold)
1024 $allaliases = $objectpageold->pageurl;
1025 $allaliases .= ($objectpageold->aliasalt ?
','.$objectpageold->aliasalt :
'');
1027 $line =
'-- Page ID '.$objectpageold->id.
' -> '.$objectpageold->newid.
'__+MAX_llx_website_page__ - Aliases '.$allaliases.
' --;';
1032 $line =
'INSERT INTO llx_website_page(rowid, fk_page, fk_website, pageurl, aliasalt, title, description, lang, image, keywords, status, date_creation, tms, import_key, grabbed_from, type_container, htmlheader, content, author_alias)';
1034 $line .=
" VALUES(";
1035 $line .= $objectpageold->newid.
"__+MAX_llx_website_page__, ";
1036 $line .= ($objectpageold->newfk_page ? $this->
db->escape($objectpageold->newfk_page).
"__+MAX_llx_website_page__" :
"null").
", ";
1037 $line .=
"__WEBSITE_ID__, ";
1038 $line .=
"'".$this->db->escape($objectpageold->pageurl).
"', ";
1039 $line .=
"'".$this->db->escape($objectpageold->aliasalt).
"', ";
1040 $line .=
"'".$this->db->escape($objectpageold->title).
"', ";
1041 $line .=
"'".$this->db->escape($objectpageold->description).
"', ";
1042 $line .=
"'".$this->db->escape($objectpageold->lang).
"', ";
1043 $line .=
"'".$this->db->escape($objectpageold->image).
"', ";
1044 $line .=
"'".$this->db->escape($objectpageold->keywords).
"', ";
1045 $line .=
"'".$this->db->escape($objectpageold->status).
"', ";
1046 $line .=
"'".$this->db->idate($objectpageold->date_creation).
"', ";
1047 $line .=
"'".$this->db->idate($objectpageold->date_modification).
"', ";
1048 $line .= ($objectpageold->import_key ?
"'".$this->db->escape($objectpageold->import_key).
"'" :
"null").
", ";
1049 $line .=
"'".$this->db->escape($objectpageold->grabbed_from).
"', ";
1050 $line .=
"'".$this->db->escape($objectpageold->type_container).
"', ";
1052 $stringtoexport = $objectpageold->htmlheader;
1053 $stringtoexport = str_replace(array(
"\r\n",
"\r",
"\n"),
"__N__", $stringtoexport);
1054 $stringtoexport = str_replace(
'file=image/'.$website->ref.
'/',
"file=image/__WEBSITE_KEY__/", $stringtoexport);
1055 $stringtoexport = str_replace(
'file=js/'.$website->ref.
'/',
"file=js/__WEBSITE_KEY__/", $stringtoexport);
1056 $stringtoexport = str_replace(
'medias/image/'.$website->ref.
'/',
"medias/image/__WEBSITE_KEY__/", $stringtoexport);
1057 $stringtoexport = str_replace(
'medias/js/'.$website->ref.
'/',
"medias/js/__WEBSITE_KEY__/", $stringtoexport);
1058 $stringtoexport = str_replace(
'file=logos%2Fthumbs%2F'.$mysoc->logo_small,
"file=logos%2Fthumbs%2F__LOGO_SMALL_KEY__", $stringtoexport);
1059 $stringtoexport = str_replace(
'file=logos%2Fthumbs%2F'.$mysoc->logo_mini,
"file=logos%2Fthumbs%2F__LOGO_MINI_KEY__", $stringtoexport);
1060 $stringtoexport = str_replace(
'file=logos%2Fthumbs%2F'.$mysoc->logo,
"file=logos%2Fthumbs%2F__LOGO_KEY__", $stringtoexport);
1061 $line .=
"'".$this->db->escape(str_replace(array(
"\r\n",
"\r",
"\n"),
"__N__", $stringtoexport)).
"', ";
1063 $stringtoexport = $objectpageold->content;
1064 $stringtoexport = str_replace(array(
"\r\n",
"\r",
"\n"),
"__N__", $stringtoexport);
1065 $stringtoexport = str_replace(
'file=image/'.$website->ref.
'/',
"file=image/__WEBSITE_KEY__/", $stringtoexport);
1066 $stringtoexport = str_replace(
'file=js/'.$website->ref.
'/',
"file=js/__WEBSITE_KEY__/", $stringtoexport);
1067 $stringtoexport = str_replace(
'medias/image/'.$website->ref.
'/',
"medias/image/__WEBSITE_KEY__/", $stringtoexport);
1068 $stringtoexport = str_replace(
'medias/js/'.$website->ref.
'/',
"medias/js/__WEBSITE_KEY__/", $stringtoexport);
1069 $stringtoexport = str_replace(
'file=logos%2Fthumbs%2F'.$mysoc->logo_small,
"file=logos%2Fthumbs%2F__LOGO_SMALL_KEY__", $stringtoexport);
1070 $stringtoexport = str_replace(
'file=logos%2Fthumbs%2F'.$mysoc->logo_mini,
"file=logos%2Fthumbs%2F__LOGO_MINI_KEY__", $stringtoexport);
1071 $stringtoexport = str_replace(
'file=logos%2Fthumbs%2F'.$mysoc->logo,
"file=logos%2Fthumbs%2F__LOGO_KEY__", $stringtoexport);
1074 $stringtoexport = str_replace(
'="image/'.$website->ref.
'/',
'="image/__WEBSITE_KEY__/', $stringtoexport);
1076 $line .=
"'".$this->db->escape($stringtoexport).
"', ";
1077 $line .=
"'".$this->db->escape($objectpageold->author_alias).
"'";
1084 if ($this->fk_default_home > 0 && ($objectpageold->id == $this->fk_default_home) && ($objectpageold->newid > 0))
1087 $line =
"UPDATE llx_website SET fk_default_home = ".($objectpageold->newid > 0 ? $this->
db->escape($objectpageold->newid).
"__+MAX_llx_website_page__" :
"null").
" WHERE rowid = __WEBSITE_ID__;";
1094 if (!empty($conf->global->MAIN_UMASK))
1095 @chmod($filesql, octdec($conf->global->MAIN_UMASK));
1098 $filedir = $conf->website->dir_temp.
'/'.$website->ref.
'/.';
1099 $fileglob = $conf->website->dir_temp.
'/'.$website->ref.
'/website_'.$website->ref.
'-*.zip';
1100 $filename = $conf->website->dir_temp.
'/'.$website->ref.
'/website_'.$website->ref.
'-'.
dol_print_date(
dol_now(),
'dayhourlog').
'-V'.((
float) DOL_VERSION).
'.zip';
1103 $result = dol_compress_file($filedir, $filename,
'zip');
1111 $this->error = $errormsg;
1125 global $conf, $mysoc;
1130 if (empty($object->ref))
1132 $this->error =
'Function importWebSite called on object not loaded (object->ref is empty)';
1137 dol_mkdir($conf->website->dir_temp.
'/'.$object->ref);
1139 $filename = basename($pathtofile);
1140 if (!preg_match(
'/^website_(.*)-(.*)$/', $filename, $reg))
1142 $this->errors[] =
'Bad format for filename '.$filename.
'. Must be website_XXX-VERSION.';
1146 $result =
dol_uncompress($pathtofile, $conf->website->dir_temp.
'/'.$object->ref);
1148 if (!empty($result[
'error']))
1150 $this->errors[] =
'Failed to unzip file '.$pathtofile.
'.';
1154 $arrayreplacement = array();
1155 $arrayreplacement[
'__WEBSITE_ID__'] = $object->id;
1156 $arrayreplacement[
'__WEBSITE_KEY__'] = $object->ref;
1157 $arrayreplacement[
'__N__'] = $this->
db->escape(
"\n");
1158 $arrayreplacement[
'__LOGO_SMALL_KEY__'] = $this->
db->escape($mysoc->logo_small);
1159 $arrayreplacement[
'__LOGO_MINI_KEY__'] = $this->
db->escape($mysoc->logo_mini);
1160 $arrayreplacement[
'__LOGO_KEY__'] = $this->
db->escape($mysoc->logo);
1163 dolCopyDir($conf->website->dir_temp.
'/'.$object->ref.
'/containers', $conf->website->dir_output.
'/'.$object->ref, 0, 1);
1166 $cssindestdir = $conf->website->dir_output.
'/'.$object->ref.
'/styles.css.php';
1169 $htmldeaderindestdir = $conf->website->dir_output.
'/'.$object->ref.
'/htmlheader.html';
1173 $filemaster = $conf->website->dir_output.
'/'.$object->ref.
'/master.inc.php';
1177 $this->errors[] =
'Failed to write file '.$filemaster;
1181 dolCopyDir($conf->website->dir_temp.
'/'.$object->ref.
'/medias/image/websitekey', $conf->website->dir_output.
'/'.$object->ref.
'/medias/image/'.$object->ref, 0, 1);
1182 dolCopyDir($conf->website->dir_temp.
'/'.$object->ref.
'/medias/js/websitekey', $conf->website->dir_output.
'/'.$object->ref.
'/medias/js/'.$object->ref, 0, 1);
1184 $sqlfile = $conf->website->dir_temp.
'/'.$object->ref.
'/website_pages.sql';
1191 $sqlgetrowid =
'SELECT MAX(rowid) as max from '.MAIN_DB_PREFIX.
'website_page';
1192 $resql = $this->
db->query($sqlgetrowid);
1195 $obj = $this->
db->fetch_object(
$resql);
1196 $maxrowid = $obj->max;
1200 $runsql =
run_sql($sqlfile, 1,
'', 0,
'',
'none', 0, 1);
1203 $this->errors[] =
'Failed to load sql file '.$sqlfile;
1210 $fp = fopen($sqlfile,
"r");
1218 $buf = fgets($fp, 65000);
1219 if (preg_match(
'/^-- Page ID (\d+)\s[^\s]+\s(\d+).*Aliases\s(.*)\s--;/i', $buf, $reg))
1222 $newid = ($reg[2] + $maxrowid);
1223 $aliasesarray = explode(
',', $reg[3]);
1225 dol_syslog(
"Found ID ".$oldid.
" to replace with ID ".$newid.
" and shortcut aliases to create: ".$reg[3]);
1227 dol_move($conf->website->dir_output.
'/'.$object->ref.
'/page'.$oldid.
'.tpl.php', $conf->website->dir_output.
'/'.$object->ref.
'/page'.$newid.
'.tpl.php', 0, 1, 0, 0);
1229 $objectpagestatic->fetch($newid);
1232 $filetpl = $conf->website->dir_output.
'/'.$object->ref.
'/page'.$newid.
'.tpl.php';
1235 $this->errors[] =
'Failed to write file '.basename($filetpl);
1240 if (is_array($aliasesarray))
1242 foreach ($aliasesarray as $aliasshortcuttocreate)
1244 if (trim($aliasshortcuttocreate))
1246 $filealias = $conf->website->dir_output.
'/'.$object->ref.
'/'.trim($aliasshortcuttocreate).
'.php';
1249 $this->errors[] =
'Failed to write file '.basename($filealias);
1261 $sql =
'SELECT fk_default_home FROM '.MAIN_DB_PREFIX.
'website WHERE rowid = '.$object->id;
1264 $obj = $this->
db->fetch_object(
$resql);
1266 $object->fk_default_home = $obj->fk_default_home;
1274 $pathofwebsite = $conf->website->dir_output.
'/'.$object->ref;
1275 dolSaveIndexPage($pathofwebsite, $pathofwebsite.
'/index.php', $pathofwebsite.
'/page'.$object->fk_default_home.
'.tpl.php', $pathofwebsite.
'/wrapper.php');
1279 $this->
db->rollback();
1283 $this->
db->commit();
1301 if (empty($object->ref))
1303 $this->error =
'Function rebuildWebSiteFiles called on object not loaded (object->ref is empty)';
1309 $sql =
'SELECT rowid FROM '.MAIN_DB_PREFIX.
'website_page WHERE fk_website = '.$this->id;
1313 $this->error = $this->
db->lasterror();
1317 $num = $this->
db->num_rows(
$resql);
1322 $obj = $this->
db->fetch_object(
$resql);
1324 $newid = $obj->rowid;
1326 $objectpagestatic->fetch($newid);
1328 $aliasesarray = explode(
',', $objectpagestatic->aliasalt);
1330 $filetpl = $conf->website->dir_output.
'/'.$object->ref.
'/page'.$newid.
'.tpl.php';
1333 $this->errors[] =
'Failed to write file '.basename($filetpl);
1338 if (!empty($objectpagestatic->pageurl) && !in_array($objectpagestatic->pageurl, $aliasesarray)) {
1339 $aliasesarray[] = $objectpagestatic->pageurl;
1343 if (is_array($aliasesarray)) {
1344 foreach ($aliasesarray as $aliasshortcuttocreate) {
1345 if (trim($aliasshortcuttocreate)) {
1346 $filealias = $conf->website->dir_output.
'/'.$object->ref.
'/'.trim($aliasshortcuttocreate).
'.php';
1349 $this->errors[] =
'Failed to write file '.basename($filealias);
1373 return (empty($this->otherlang) ?
false :
true);
1387 global $websitepagefile, $website;
1389 if (!is_object($weblangs))
return 'ERROR componentSelectLang called with parameter $weblangs not defined';
1391 $arrayofspecialmainlanguages = array(
1422 if (!empty($websitepagefile))
1424 $websitepagefileshort = basename($websitepagefile);
1425 if ($websitepagefileshort ==
'index.php') $pageid = $website->fk_default_home;
1426 else $pageid = str_replace(array(
'.tpl.php',
'page'), array(
'',
''), $websitepagefileshort);
1429 $tmppage->fetch($pageid);
1434 if (!is_array($languagecodes) && $pageid > 0)
1436 $languagecodes = array();
1438 $sql =
"SELECT wp.rowid, wp.lang, wp.pageurl, wp.fk_page";
1439 $sql .=
" FROM ".MAIN_DB_PREFIX.
"website_page as wp";
1440 $sql .=
" WHERE wp.fk_website = ".$website->id;
1441 $sql .=
" AND (wp.fk_page = ".$pageid.
" OR wp.rowid = ".$pageid;
1442 if ($tmppage->fk_page > 0) $sql .=
" OR wp.fk_page = ".$tmppage->fk_page.
" OR wp.rowid = ".$tmppage->fk_page;
1448 while ($obj = $this->
db->fetch_object(
$resql))
1450 $newlang = $obj->lang;
1451 if ($obj->rowid == $pageid) $newlang = $obj->lang;
1452 if (!in_array($newlang, $languagecodes)) $languagecodes[] = $newlang;
1458 $languagecodeselected = substr($weblangs->defaultlang, 0, 2);
1459 if (!empty($websitepagefile))
1461 $pageid = str_replace(array(
'.tpl.php',
'page'), array(
'',
''), basename($websitepagefile));
1464 $pagelang = substr($tmppage->lang, 0, 2);
1465 $languagecodeselected = substr($pagelang, 0, 2);
1466 if (!in_array($pagelang, $languagecodes)) $languagecodes[] = $pagelang;
1470 $weblangs->load(
'languages');
1474 $url = preg_replace(
'/(\?|&)l=([a-zA-Z_]*)/',
'', $url);
1476 $url .= (preg_match(
'/\?/', $url) ?
'&' :
'?').
'l=';
1477 if (!preg_match(
'/^\//', $url)) $url =
'/'.$url;
1480 $MAXHEIGHT = 4 * $HEIGHTOPTION;
1481 $nboflanguage = count($languagecodes);
1483 $out =
'<!-- componentSelectLang'.$htmlname.
' -->'.
"\n";
1486 $out .=
'.componentSelectLang'.$htmlname.
':hover { height: '.min($MAXHEIGHT, ($HEIGHTOPTION * $nboflanguage)).
'px; overflow-x: hidden; overflow-y: '.((($HEIGHTOPTION * $nboflanguage) > $MAXHEIGHT) ?
' scroll' :
'hidden').
'; }'.
"\n";
1487 $out .=
'.componentSelectLang'.$htmlname.
' li { line-height: '.$HEIGHTOPTION.
'px; }'.
"\n";
1488 $out .=
'.componentSelectLang'.$htmlname.
' {
1489 display: inline-block;
1491 height: '.$HEIGHTOPTION.
'px;
1493 transition: all .3s ease;
1495 vertical-align: top;
1497 .componentSelectLang'.$htmlname.
':hover, .componentSelectLang'.$htmlname.
':hover a { background-color: #fff; color: #000 !important; }
1498 ul.componentSelectLang'.$htmlname.
' { width: 150px; }
1499 ul.componentSelectLang'.$htmlname.
':hover .fa { visibility: hidden; }
1500 .componentSelectLang'.$htmlname.
' a { text-decoration: none; width: 100%; }
1501 .componentSelectLang'.$htmlname.
' li { display: block; padding: 0px 15px; margin-left: 0; margin-right: 0; }
1502 .componentSelectLang'.$htmlname.
' li:hover { background-color: #EEE; }
1505 $out .=
'<ul class="componentSelectLang'.$htmlname.($morecss ?
' '.$morecss :
'').
'">';
1507 if ($languagecodeselected)
1510 if (strlen($languagecodeselected) == 2) {
1511 $languagecodeselected = (empty($arrayofspecialmainlanguages[$languagecodeselected]) ? $languagecodeselected.
'_'.strtoupper($languagecodeselected) : $arrayofspecialmainlanguages[$languagecodeselected]);
1514 $countrycode = strtolower(substr($languagecodeselected, -2));
1515 $label = $weblangs->trans(
"Language_".$languagecodeselected);
1516 if ($countrycode ==
'us') $label = preg_replace(
'/\s*\(.*\)/',
'', $label);
1517 $out .=
'<a href="'.$url.substr($languagecodeselected, 0, 2).
'"><li><img height="12px" src="/medias/image/common/flags/'.$countrycode.
'.png" style="margin-right: 5px;"/><span class="websitecomponentlilang">'.$label.
'</span>';
1518 $out .=
'<span class="fa fa-caret-down" style="padding-left: 5px;" />';
1519 $out .=
'</li></a>';
1522 if (is_array($languagecodes))
1524 foreach ($languagecodes as $languagecode)
1527 if (strlen($languagecode) == 2) {
1528 $languagecode = (empty($arrayofspecialmainlanguages[$languagecode]) ? $languagecode.
'_'.strtoupper($languagecode) : $arrayofspecialmainlanguages[$languagecode]);
1531 if ($languagecode == $languagecodeselected)
continue;
1533 $countrycode = strtolower(substr($languagecode, -2));
1534 $label = $weblangs->trans(
"Language_".$languagecode);
1535 if ($countrycode ==
'us') $label = preg_replace(
'/\s*\(.*\)/',
'', $label);
1536 $out .=
'<a href="'.$url.substr($languagecode, 0, 2).
'"><li><img height="12px" src="/medias/image/common/flags/'.$countrycode.
'.png" style="margin-right: 5px;"/><span class="websitecomponentlilang">'.$label.
'</span>';
1537 if (empty($i) && empty($languagecodeselected)) $out .=
'<span class="fa fa-caret-down" style="padding-left: 5px;" />';
1538 $out .=
'</li></a>';
dol_osencode($str)
Return a string encoded into OS filesystem encoding.
createFromClone($user, $fromid, $newref, $newlang= '')
Load an object from its id and create a new one in database.
dolCopyDir($srcfile, $destfile, $newmask, $overwriteifexists, $arrayreplacement=null, $excludesubdir=0)
Copy a dir to another dir.
__construct(DoliDB $db)
Constructor.
isMultiLang()
Return if web site is a multilanguage web site.
</td > param sortfield sortorder printFieldListOption< tdclass="liste_titremaxwidthsearchright"></td ></tr >< trclass="liste_titre">< inputtype="checkbox"onClick="toggle(this)"/> Ref p ref Label p label Duration p duration center DesiredStock p desiredstock right StockLimitShort p seuil_stock_alerte right stock_physique right stock_real_warehouse right Ordered right StockToBuy right SupplierRef right param sortfield sortorder printFieldListTitle warehouseinternal SELECT description FROM product_lang WHERE qty< br > qty qty qty StockTooLow StockTooLow help help help< trclass="oddeven">< td >< inputtype="checkbox"class="check"name="choose'.$i.'"></td >< tdclass="nowrap"> stock</td >< td >< inputtype="hidden"name="desc'.$i.'"value="'.dol_escape_htmltag($objp-> description
Only used if Module[ID]Desc translation string is not found.
dolSaveMasterFile($filemaster)
Save content of a page on disk.
dol_now($mode= 'auto')
Return date for now.
Class to manage Dolibarr users.
Class to manage Dolibarr database access.
dolSavePageContent($filetpl, Website $object, WebsitePage $objectpage)
Save content of a page on disk (page name is generally ID_of_page.php).
$conf db
API class for accounts.
exportWebSite()
Generate a zip with all data of web site.
dol_move($srcfile, $destfile, $newmask=0, $overwriteifexists=1, $testvirus=0, $indexdatabase=1)
Move a file into another name.
setEventMessages($mesg, $mesgs, $style= 'mesgs', $messagekey= '')
Set event messages in dol_events session object.
rebuildWebSiteFiles()
Rebuild all files of a containers of a website.
dol_strlen($string, $stringencoding= 'UTF-8')
Make a strlen call.
initAsSpecimen()
Initialise object with example values Id must be 0 if object instance is a specimen.
getLibStatut($mode=0)
Retourne le libelle du status d'un user (actif, inactif)
dol_syslog($message, $level=LOG_INFO, $ident=0, $suffixinfilename= '', $restricttologhandler= '', $logcontext=null)
Write log message into outputs.
dol_delete_dir_recursive($dir, $count=0, $nophperrors=0, $onlysub=0, &$countdeleted=0)
Remove a directory $dir and its subdirectories (or only files and subdirectories) ...
dolSaveIndexPage($pathofwebsite, $fileindex, $filetpl, $filewrapper)
Save content of the index.php and/or wrapper.php page.
dol_delete_file($file, $disableglob=0, $nophperrors=0, $nohook=0, $object=null, $allowdotdot=false, $indexdatabase=1)
Remove a file or several files with a mask.
run_sql($sqlfile, $silent=1, $entity= '', $usesavepoint=1, $handler= '', $okerror= 'default', $linelengthlimit=32768, $nocommentremoval=0, $offsetforchartofaccount=0)
Launch a sql file.
componentSelectLang($languagecodes, $weblangs, $morecss= '', $htmlname= '')
Component to select language inside a container (Full CSS Only)
dolSavePageAlias($filealias, $object, $objectpage)
Save an alias page on disk (A page that include the reference page).
print $_SERVER["PHP_SELF"]
Edit parameters.
fetchLines()
Load object lines in memory from the database.
dolReplaceInFile($srcfile, $arrayreplacement, $destfile= '', $newmask=0, $indexdatabase=0, $arrayreplacementisregex=0)
Make replacement of strings into a file.
update(User $user, $notrigger=false)
Update object into database.
dol_uncompress($inputfile, $outputdir)
Uncompress a file.
div float
Buy price without taxes.
dol_print_date($time, $format= '', $tzoutput= 'auto', $outputlangs= '', $encodetooutput=false)
Output date in a string format according to outputlangs (or langs if not defined).
if(!empty($conf->facture->enabled)&&$user->rights->facture->lire) if((!empty($conf->fournisseur->enabled)&&empty($conf->global->MAIN_USE_NEW_SUPPLIERMOD)||!empty($conf->supplier_invoice->enabled))&&$user->rights->fournisseur->facture->lire) if(!empty($conf->don->enabled)&&$user->rights->don->lire) if(!empty($conf->tax->enabled)&&$user->rights->tax->charges->lire) if(!empty($conf->facture->enabled)&&!empty($conf->commande->enabled)&&$user->rights->commande->lire &&empty($conf->global->WORKFLOW_DISABLE_CREATE_INVOICE_FROM_ORDER)) if(!empty($conf->facture->enabled)&&$user->rights->facture->lire) if((!empty($conf->fournisseur->enabled)&&empty($conf->global->MAIN_USE_NEW_SUPPLIERMOD)||!empty($conf->supplier_invoice->enabled))&&$user->rights->fournisseur->facture->lire) $resql
Social contributions to pay.
importWebSite($pathtofile)
Open a zip with all data of web site and load it into database.
dolGetStatus($statusLabel= '', $statusLabelShort= '', $html= '', $statusType= 'status0', $displayMode=0, $url= '', $params=array())
Output the badge of a status.
fetchAll($sortorder= '', $sortfield= '', $limit=0, $offset=0, array $filter=array(), $filtermode= 'AND')
Load all object in memory ($this->records) from the database.
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, this->firstname.
Parent class of all other business classes (invoices, contracts, proposals, orders, ...)
LibStatut($status, $mode=0)
Renvoi le libelle d'un status donne.
dol_mkdir($dir, $dataroot= '', $newmask=null)
Creation of a directory (this can create recursive subdir)
fetch($id, $ref=null)
Load object in memory from the database.
create(User $user, $notrigger=false)
Create object into database.