27require
'../main.inc.php';
28require_once DOL_DOCUMENT_ROOT.
'/core/class/html.formadmin.class.php';
29require_once DOL_DOCUMENT_ROOT.
'/core/class/html.formcompany.class.php';
30require_once DOL_DOCUMENT_ROOT.
'/core/lib/admin.lib.php';
31require_once DOL_DOCUMENT_ROOT.
'/core/lib/files.lib.php';
32require_once DOL_DOCUMENT_ROOT.
'/core/lib/website.lib.php';
33require_once DOL_DOCUMENT_ROOT.
'/core/lib/functions2.lib.php';
34require_once DOL_DOCUMENT_ROOT.
'/core/class/doleditor.class.php';
35require_once DOL_DOCUMENT_ROOT.
'/website/class/website.class.php';
46$langs->loadlangs(array(
'errors',
'admin',
'companies',
'website'));
48$action =
GETPOST(
'action',
'alpha') ?
GETPOST(
'action',
'alpha') :
'view';
49$confirm =
GETPOST(
'confirm',
'alpha');
50$backtopage =
GETPOST(
'backtopage',
'alpha');
52$rowid =
GETPOST(
'rowid',
'alpha');
60$actl[0] =
img_picto($langs->trans(
"Disabled"),
'switch_off',
'class="size15x"');
61$actl[1] =
img_picto($langs->trans(
"Activated"),
'switch_on',
'class="size15x"');
65$sortfield =
GETPOST(
'sortfield',
'aZ09comma');
66$sortorder =
GETPOST(
'sortorder',
'aZ09comma');
68if (empty($page) || $page == -1) {
71$offset = $limit * $page;
75if (empty($sortfield)) {
76 $sortfield =
'position, ref';
78if (empty($sortorder)) {
83$hookmanager->initHooks(array(
'website'));
87$tabname[1] = MAIN_DB_PREFIX.
"website";
91$tablib[1] =
"Websites";
95$tabsql[1] =
"SELECT f.rowid as rowid, f.entity, f.ref, f.description, f.virtualhost, f.position, f.status, f.date_creation, f.lastaccess, f.pageviews_previous_month, f.pageviews_total FROM ".MAIN_DB_PREFIX.
'website as f WHERE f.entity IN ('.
getEntity(
'website').
')';
99$tabsqlsort[1] =
"ref ASC";
103$tabfield[1] =
"ref,description,virtualhost,position,date_creation,lastaccess,pageviews_previous_month,pageviews_total";
106$tabfieldvalue = array();
107$tabfieldvalue[1] =
"ref,description,virtualhost,position,entity";
110$tabfieldinsert = array();
111$tabfieldinsert[1] =
"ref,description,virtualhost,position,entity";
125$tabhelp[1] = array(
'ref' => $langs->trans(
"EnterAnyCode"),
'virtualhost' => $langs->trans(
"SetHereVirtualHost", DOL_DATA_ROOT.($conf->entity > 1 ?
'/'.$conf->entity :
'').
'/website/<i>websiteref</i>'));
128$tabfieldcheck = array();
129$tabfieldcheck[1] = array();
133$elementList = array();
134$sourceList = array();
147if (
GETPOST(
'actionadd',
'alpha') ||
GETPOST(
'actionmodify',
'alpha')) {
148 $listfield = explode(
',', $tabfield[$id]);
149 $listfieldinsert = explode(
',', $tabfieldinsert[$id]);
150 $listfieldmodify = explode(
',', $tabfieldinsert[$id]);
151 $listfieldvalue = explode(
',', $tabfieldvalue[$id]);
155 foreach ($listfield as $f => $value) {
156 if ($value ==
'ref' && (!GETPOSTISSET($value) ||
GETPOST($value) ==
'')) {
158 $fieldnamekey = $listfield[$f];
159 setEventMessages($langs->transnoentities(
"ErrorFieldRequired", $langs->transnoentities($fieldnamekey)),
null,
'errors');
161 } elseif ($value ==
'ref' && !preg_match(
'/^[a-z0-9_\-\.]+$/i',
GETPOST($value))) {
163 $fieldnamekey = $listfield[$f];
164 setEventMessages($langs->transnoentities(
"ErrorFieldCanNotContainSpecialCharacters", $langs->transnoentities($fieldnamekey)),
null,
'errors');
171 $websitekey = strtolower(
GETPOST(
'ref'));
177 if ($ok &&
GETPOST(
'actionadd',
'alpha')) {
178 if ($tabrowid[$id]) {
180 $sql =
"SELECT MAX(".$db->sanitize($tabrowid[$id]).
") newid FROM ".
$db->sanitize($tabname[$id]);
181 $result =
$db->query($sql);
183 $obj =
$db->fetch_object($result);
184 $newid = ($obj->newid + 1);
197 $sql =
"INSERT INTO ".$db->sanitize($tabname[$id]).
" (";
199 if ($tabrowid[$id] && !in_array($tabrowid[$id], $listfieldinsert)) {
200 $sql .=
$db->sanitize($tabrowid[$id]).
",";
202 $sql .= $tabfieldinsert[
$id];
203 $sql .=
", status, date_creation)";
207 if ($tabrowid[$id] && !in_array($tabrowid[$id], $listfieldinsert)) {
211 foreach ($listfieldinsert as $f => $value) {
212 if ($value ==
'entity') {
213 $_POST[$listfieldvalue[$i]] =
$conf->entity;
215 if ($value ==
'ref') {
216 $_POST[$listfieldvalue[$i]] = strtolower(
GETPOST($listfieldvalue[$i]));
221 if (
GETPOST($listfieldvalue[$i]) ==
'') {
224 $sql .=
"'".$db->escape(
GETPOST($listfieldvalue[$i])).
"'";
228 $sql .=
", 1, '".$db->idate(
dol_now()).
"')";
231 $result =
$db->query($sql);
236 if (
$db->errno() ==
'DB_ERROR_RECORD_ALREADY_EXISTS') {
237 setEventMessages($langs->transnoentities(
"ErrorRecordAlreadyExists"),
null,
'errors');
245 if ($ok &&
GETPOST(
'actionmodify',
'alpha')) {
246 if ($tabrowid[$id]) {
247 $rowidcol = $tabrowid[
$id];
256 $website->fetch($rowid);
259 $sql =
"UPDATE ".$db->sanitize($tabname[$id]).
" SET ";
261 if ($tabrowid[$id] && !in_array($tabrowid[$id], $listfieldmodify)) {
262 $sql .=
$db->sanitize($tabrowid[$id]).
" = ";
263 $sql .=
"'".$db->escape((
string) $rowid).
"', ";
266 foreach ($listfieldmodify as $field) {
267 if ($field ==
'entity') {
268 $_POST[$listfieldvalue[$i]] =
$conf->entity;
274 if (
GETPOST($listfieldvalue[$i]) ==
'') {
277 $sql .=
"'".$db->escape(
GETPOST($listfieldvalue[$i])).
"'";
281 $sql .=
" WHERE ".$db->sanitize($rowidcol).
" = ".((int) $rowid);
285 $resql =
$db->query($sql);
288 if ($newname != $website->ref) {
289 $srcfile = DOL_DATA_ROOT.($conf->entity > 1 ?
'/'.$conf->entity :
'').
'/website/'.$website->ref;
290 $destfile = DOL_DATA_ROOT.($conf->entity > 1 ?
'/'.$conf->entity :
'').
'/website/'.$newname;
294 setEventMessages($langs->trans(
'ErrorDirAlreadyExists', $destfile),
null,
'errors');
296 @rename($srcfile, $destfile);
299 $arrayreplacement = array($website->ref.
'/htmlheader.html' => $newname.
'/htmlheader.html');
300 $listofilestochange =
dol_dir_list($destfile,
'files', 0,
'\.php$');
301 foreach ($listofilestochange as $key => $value) {
319if ($action ==
'confirm_delete' && $confirm ==
'yes') {
320 if ($tabrowid[$id]) {
321 $rowidcol = $tabrowid[
$id];
327 $website->fetch($rowid);
329 if ($website->id > 0) {
330 $sql =
"DELETE from ".MAIN_DB_PREFIX.
"website_account WHERE fk_website = ".((int) $rowid);
331 $result =
$db->query($sql);
333 $sql =
"DELETE from ".MAIN_DB_PREFIX.
"website_page WHERE fk_website = ".((int) $rowid);
334 $result =
$db->query($sql);
336 $sql =
"DELETE from ".MAIN_DB_PREFIX.
"website_extrafields WHERE fk_object = ".((int) $rowid);
337 $result =
$db->query($sql);
339 $sql =
"DELETE from ".MAIN_DB_PREFIX.
"website WHERE rowid = ".((int) $rowid);
340 $result =
$db->query($sql);
342 if (
$db->errno() ==
'DB_ERROR_CHILD_EXISTS') {
343 setEventMessages($langs->transnoentities(
"ErrorRecordIsUsedByChild"),
null,
'errors');
358if ($action == $acts[0]) {
359 if ($tabrowid[$id]) {
360 $rowidcol = $tabrowid[
$id];
366 $sql =
"UPDATE ".$db->sanitize($tabname[$id]).
" SET status = 1 WHERE rowid = ".((int) $rowid);
372 $result =
$db->query($sql);
382if ($action == $acts[1]) {
383 if ($tabrowid[$id]) {
384 $rowidcol = $tabrowid[
$id];
390 $sql =
"UPDATE ".$db->sanitize($tabname[$id]).
" SET status = 0 WHERE rowid = ".((int) $rowid);
396 $result =
$db->query($sql);
414llxHeader(
'', $langs->trans(
"WebsiteSetup"),
'',
'', 0, 0,
'',
'',
'',
'mod-admin page-website');
416$titre = $langs->trans(
"WebsiteSetup");
418$linkback =
'<a href="'.($backtopage ? $backtopage : DOL_URL_ROOT.
'/admin/modules.php?restore_lastsearch_values=1').
'">'.
img_picto($langs->trans(
"BackToModuleList"),
'back',
'class="pictofixedwidth"').
'<span class="hideonsmartphone">'.$langs->trans(
"BackToModuleList").
'</span></a>';
426$head[$h][0] = DOL_URL_ROOT.
"/admin/website.php";
427$head[$h][1] = $langs->trans(
"WebSites");
428$head[$h][2] =
'website';
441print
'<span class="opacitymedium">'.$langs->trans(
"WebsiteSetupDesc").
'</span><br>';
446if ($action ==
'delete') {
447 print $form->formconfirm($_SERVER[
"PHP_SELF"].
'?'.($page ?
'page='.$page.
'&' :
'').
'sortfield='.$sortfield.
'&sortorder='.$sortorder.
'&rowid='.$rowid, $langs->trans(
'DeleteWebsite'), $langs->trans(
'ConfirmDeleteWebsite'),
'confirm_delete',
'', 0, 1, 220);
457 $sql .=
$db->order($sortfield, $sortorder);
458 $sql .=
$db->plimit($limit + 1, $offset);
461 $fieldlist = explode(
',', $tabfield[$id]);
463 print
'<form action="'.$_SERVER[
'PHP_SELF'].
'" method="POST">';
464 print
'<input type="hidden" name="token" value="'.newToken().
'">';
466 print
'<div class="div-table-responsive-no-min">';
467 print
'<table class="noborder centpercent">';
472 print
'<tr class="liste_titre">';
473 foreach ($fieldlist as $field => $value) {
474 if (in_array($fieldlist[$field], array(
'date_creation',
'lastaccess',
'pageviews_previous_month',
'pageviews_month',
'pageviews_total'))) {
479 $valuetoshow = ucfirst($fieldlist[$field]);
480 $valuetoshow = $langs->trans($valuetoshow);
482 if ($fieldlist[$field] ==
'lang') {
483 $valuetoshow = $langs->trans(
"Language");
485 if ($valuetoshow !=
'') {
486 print
'<td class="'.$css.
'">';
487 if (!empty($tabhelp[$id][$value]) && preg_match(
'/^http(s*):/i', $tabhelp[$id][$value])) {
488 print
'<a href="'.$tabhelp[
$id][$value].
'" target="_blank" rel="noopener noreferrer">'.$valuetoshow.
' '.
img_help(1, $valuetoshow).
'</a>';
489 } elseif (!empty($tabhelp[$id][$value])) {
490 if ($value ==
'virtualhost') {
491 print $form->textwithpicto($valuetoshow, $tabhelp[$id][$value], 1,
'help',
'', 0, 2,
'tooltipvirtual');
493 print $form->textwithpicto($valuetoshow, $tabhelp[$id][$value]);
502 print
'<td colspan="4">';
507 print
'<tr class="oddeven">';
511 if (
GETPOST(
'actionadd',
'alpha')) {
512 foreach ($fieldlist as $key => $val) {
518 if (!isset($obj->position)) {
524 print
'<td colspan="3" class="right">';
525 if ($action !=
'edit') {
526 print
'<input type="submit" class="button button-add" name="actionadd" value="'.$langs->trans(
"Add").
'">';
539 $resql =
$db->query($sql);
541 $num =
$db->num_rows($resql);
546 print
'<form action="'.$_SERVER[
'PHP_SELF'].
'" method="POST">';
547 print
'<input type="hidden" name="token" value="'.newToken().
'">';
548 print
'<input type="hidden" name="page" value="'.$page.
'">';
549 print
'<input type="hidden" name="rowid" value="'.$rowid.
'">';
551 print
'<div class="div-table-responsive">';
552 print
'<table class="noborder centpercent">';
555 print
'<tr class="liste_titre">';
556 foreach ($fieldlist as $field => $value) {
563 if (in_array($fieldlist[$field], array(
'pageviews_total',
'pageviews_previous_month'))) {
574 $valuetoshow = ucfirst($fieldlist[$field]);
575 $valuetoshow = $langs->trans($valuetoshow);
576 if ($fieldlist[$field] ==
'lang') {
577 $valuetoshow = $langs->trans(
"Language");
579 if ($fieldlist[$field] ==
'type') {
580 $valuetoshow = $langs->trans(
"Type");
582 if ($fieldlist[$field] ==
'code') {
583 $valuetoshow = $langs->trans(
"Code");
585 if ($fieldlist[$field] ==
'date_creation') {
586 $valuetoshow = $langs->trans(
"DateCreation");
588 if ($fieldlist[$field] ==
'lastaccess') {
589 $valuetoshow = $langs->trans(
"LastAccess");
591 if ($fieldlist[$field] ==
'pageviews_previous_month') {
592 $valuetoshow = $langs->trans(
"PagesViewedPreviousMonth");
594 if ($fieldlist[$field] ==
'pageviews_total') {
595 $valuetoshow = $langs->trans(
"PagesViewedTotal");
600 print
getTitleFieldOfList($valuetoshow, 0, $_SERVER[
"PHP_SELF"], ($sortable ? $fieldlist[$field] :
''), ($page ?
'page='.$page.
'&' :
''),
"",
'', $sortfield, $sortorder, $align.
' ');
605 print
getTitleFieldOfList($langs->trans(
"Status"), 0, $_SERVER[
"PHP_SELF"],
"status", ($page ?
'page='.$page.
'&' :
''),
"",
'', $sortfield, $sortorder,
'center ');
612 $obj =
$db->fetch_object($resql);
614 print
'<tr class="oddeven" id="rowid-'.$obj->rowid.
'">';
615 if ($action ==
'edit' && ($rowid == (!empty($obj->rowid) ? $obj->rowid : $obj->code))) {
617 $parameters = array(
'fieldlist' => $fieldlist,
'tabname' => $tabname[$id]);
618 $reshook = $hookmanager->executeHooks(
'editWebsiteFieldlist', $parameters, $obj, $tmpaction);
619 $error = $hookmanager->error;
620 $errors = $hookmanager->errors;
622 if (empty($reshook)) {
626 print
'<td colspan="7" class="right"><a name="'.(!empty($obj->rowid) ? $obj->rowid : $obj->code).
'"> </a>';
627 print
'<input type="submit" class="button button-edit small" name="actionmodify" value="'.$langs->trans(
"Modify").
'">';
629 print
'<input type="submit" class="button button-cancel small" name="actioncancel" value="'.$langs->trans(
"Cancel").
'">';
633 $parameters = array(
'fieldlist' => $fieldlist,
'tabname' => $tabname[$id]);
634 $reshook = $hookmanager->executeHooks(
'viewWebsiteFieldlist', $parameters, $obj, $tmpaction);
636 $error = $hookmanager->error;
637 $errors = $hookmanager->errors;
639 if (empty($reshook)) {
640 foreach ($fieldlist as $field => $value) {
642 $fieldname = $fieldlist[$field];
644 if ($fieldlist[$field] ==
'description') {
645 $css .=
' tdoverflowmax300';
647 if (in_array($fieldname, array(
'pageviews_total',
'pageviews_previous_month'))) {
650 if ($fieldlist[$field] ==
'date_creation') {
651 $css .=
' nowraponall';
653 if ($fieldlist[$field] ==
'lastaccess') {
654 $css .=
' nowraponall';
656 $valuetoshow = $obj->$fieldname;
660 print
'<td class="'.$css.
'">'.$valuetoshow.
'</td>';
672 $url = $_SERVER[
"PHP_SELF"].
'?'.($page ?
'page='.$page.
'&' :
'').
'sortfield='.$sortfield.
'&sortorder='.$sortorder.
'&rowid='.(!empty($obj->rowid) ? $obj->rowid : (!empty($obj->code) ? $obj->code :
'')).
'&code='.(!empty($obj->code) ? urlencode($obj->code) :
'').
'&';
676 print
'<td align="center" class="nowrap">';
677 print
'<a class="reposition" href="'.$url.
'action='.$acts[($obj->status ? 1 : 0)].
'&token='.newToken().
'">'.$actl[($obj->status ? 1 : 0)].
'</a>';
681 print
'<td align="center"><a class="reposition editfielda" href="'.$url.
'action=edit&token='.newToken().
'">'.
img_edit().
'</a></td>';
685 print
'<td align="center"><a class="reposition" href="'.$url.
'action=delete&token='.newToken().
'">'.
img_delete().
'</a></td>';
687 print
'<td class="center">'.img_delete($langs->trans(
"DisableSiteFirst"),
'class="opacitymedium"').
'</td>';
726 global $elementList, $sourceList, $localtax_typeList;
731 foreach ($fieldlist as $field => $value) {
732 if (in_array($fieldlist[$field], array(
'lastaccess',
'pageviews_previous_month',
'pageviews_month',
'pageviews_total'))) {
736 $fieldname = $fieldlist[$field];
738 if ($fieldlist[$field] ==
'lang') {
742 } elseif ($fieldlist[$field] ==
'code' && isset($obj->$fieldname)) {
743 print
'<td><input type="text" class="flat" value="'.(!empty($obj->$fieldname) ? $obj->$fieldname :
'').
'" size="10" name="'.$fieldlist[$field].
'"></td>';
745 if ($fieldlist[$field] ==
'date_creation') {
751 if ($fieldlist[$field] ==
'code') {
754 if ($fieldlist[$field] ==
'position') {
757 if ($fieldlist[$field] ==
'libelle') {
758 $size =
'size="32" ';
760 if ($fieldlist[$field] ==
'tracking') {
761 $size =
'size="92" ';
763 if ($fieldlist[$field] ==
'sortorder') {
766 print
'<input type="text" '.$size.
' class="flat" value="'.(isset($obj->$fieldname) ? $obj->$fieldname :
'').
'" name="'.$fieldlist[$field].
'">';
$id
Support class for third parties, contacts, members, users or resources.
fieldListWebsites($fieldlist, $obj=null, $tabname='', $context='')
Show fields in insert/edit mode.
llxFooter($comment='', $zone='private', $disabledoutputofmessages=0)
Empty footer.
if(!defined('NOREQUIRESOC')) if(!defined( 'NOREQUIRETRAN')) if(!defined('NOTOKENRENEWAL')) if(!defined( 'NOREQUIREMENU')) if(!defined('NOREQUIREHTML')) if(!defined( 'NOREQUIREAJAX')) llxHeader($head='', $title='', $help_url='', $target='', $disablejs=0, $disablehead=0, $arrayofjs='', $arrayofcss='', $morequerystring='', $morecssonbody='', $replacemainareaby='', $disablenofollow=0, $disablenoindex=0)
Empty header.
dol_delete_dir_recursive($dir, $count=0, $nophperrors=0, $onlysub=0, &$countdeleted=0, $indexdatabase=1, $nolog=0, $level=0)
Remove a directory $dir and its subdirectories (or only files and subdirectories)
dol_dir_list($utf8_path, $types="all", $recursive=0, $filter="", $excludefilter=null, $sortcriteria="name", $sortorder=SORT_ASC, $mode=0, $nohook=0, $relativename="", $donotfollowsymlinks=0, $nbsecondsold=0)
Scan a directory and return a list of files/directories.
dol_is_dir($folder)
Test if filename is a directory.
dolReplaceInFile($srcfile, $arrayreplacement, $destfile='', $newmask='0', $indexdatabase=0, $arrayreplacementisregex=0)
Make replacement of strings into a file.
dol_now($mode='gmt')
Return date for now.
setEventMessages($mesg, $mesgs, $style='mesgs', $messagekey='', $noduplicate=0, $attop=0)
Set event messages in dol_events session object.
img_help($usehelpcursor=1, $usealttitle=1)
Show help logo with cursor "?".
img_picto($titlealt, $picto, $moreatt='', $pictoisfullpath=0, $srconly=0, $notitle=0, $alt='', $morecss='', $marginleftonlyshort=2, $allowothertags=array())
Show picto whatever it's its name (generic function)
img_delete($titlealt='default', $other='class="pictodelete"', $morecss='')
Show delete logo.
GETPOSTINT($paramname, $method=0)
Return the value of a $_GET or $_POST supervariable, converted into integer.
dol_get_fiche_head($links=array(), $active='', $title='', $notab=0, $picto='', $pictoisfullpath=0, $morehtmlright='', $morecss='', $limittoshow=0, $moretabssuffix='', $dragdropfile=0, $morecssdiv='')
Show tabs of a record.
dol_get_fiche_end($notab=0)
Return tab footer of a card.
dol_sanitizeFileName($str, $newstr='_', $unaccent=1, $includequotes=0, $allowdash=0)
Clean a string to use it as a file name.
getTitleFieldOfList($name, $thead=0, $file="", $field="", $begin="", $moreparam="", $moreattrib="", $sortfield="", $sortorder="", $prefix="", $disablesortlink=0, $tooltip='', $forcenowrapcolumntitle=0)
Get title line of an array.
GETPOST($paramname, $check='alphanohtml', $method=0, $filter=null, $options=null, $noreplace=0)
Return value of a param into GET or POST supervariable.
dol_print_error($db=null, $error='', $errors=null)
Displays error message system with all the information to facilitate the diagnosis and the escalation...
load_fiche_titre($title, $morehtmlright='', $picto='generic', $pictoisfullpath=0, $id='', $morecssontable='', $morehtmlcenter='', $morecssonpicto='widthpictotitle')
Load a title with picto.
getDolGlobalString($key, $default='')
Return a Dolibarr global constant string value.
isModEnabled($module)
Is Dolibarr module enabled.
img_edit($titlealt='default', $float=0, $other='')
Show logo edit/modify fiche.
dol_syslog($message, $level=LOG_INFO, $ident=0, $suffixinfilename='', $restricttologhandler='', $logcontext=null)
Write log message into outputs.
getEntity($element, $shared=1, $currentobject=null)
Get list of entity id to use.
$context
@method int call_trigger(string $triggerName, ?User $user)
accessforbidden($message='', $printheader=1, $printfooter=1, $showonlymessage=0, $params=null)
Show a message to say access is forbidden and stop program.