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');
58$actl[0] =
img_picto($langs->trans(
"Disabled"),
'switch_off',
'class="size15x"');
59$actl[1] =
img_picto($langs->trans(
"Activated"),
'switch_on',
'class="size15x"');
63$sortfield =
GETPOST(
'sortfield',
'aZ09comma');
64$sortorder =
GETPOST(
'sortorder',
'aZ09comma');
66if (empty($page) || $page == -1) {
69$offset = $limit * $page;
73if (empty($sortfield)) {
74 $sortfield =
'position, ref';
76if (empty($sortorder)) {
81$hookmanager->initHooks(array(
'website'));
85$tabname[1] = MAIN_DB_PREFIX.
"website";
89$tablib[1] =
"Websites";
93$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').
')';
97$tabsqlsort[1] =
"ref ASC";
101$tabfield[1] =
"ref,description,virtualhost,position,date_creation,lastaccess,pageviews_previous_month,pageviews_total";
104$tabfieldvalue = array();
105$tabfieldvalue[1] =
"ref,description,virtualhost,position,entity";
108$tabfieldinsert = array();
109$tabfieldinsert[1] =
"ref,description,virtualhost,position,entity";
119$tabcond[1] = (isModEnabled(
'website'));
123$tabhelp[1] = array(
'ref' => $langs->trans(
"EnterAnyCode"),
'virtualhost' => $langs->trans(
"SetHereVirtualHost", DOL_DATA_ROOT.($conf->entity > 1 ?
'/'.$conf->entity :
'').
'/website/<i>websiteref</i>'));
126$tabfieldcheck = array();
127$tabfieldcheck[1] = array();
131$elementList = array();
132$sourceList = array();
145if (
GETPOST(
'actionadd',
'alpha') ||
GETPOST(
'actionmodify',
'alpha')) {
146 $listfield = explode(
',', $tabfield[$id]);
147 $listfieldinsert = explode(
',', $tabfieldinsert[$id]);
148 $listfieldmodify = explode(
',', $tabfieldinsert[$id]);
149 $listfieldvalue = explode(
',', $tabfieldvalue[$id]);
153 foreach ($listfield as $f => $value) {
154 if ($value ==
'ref' && (!GETPOSTISSET($value) ||
GETPOST($value) ==
'')) {
156 $fieldnamekey = $listfield[$f];
157 setEventMessages($langs->transnoentities(
"ErrorFieldRequired", $langs->transnoentities($fieldnamekey)),
null,
'errors');
159 } elseif ($value ==
'ref' && !preg_match(
'/^[a-z0-9_\-\.]+$/i',
GETPOST($value))) {
161 $fieldnamekey = $listfield[$f];
162 setEventMessages($langs->transnoentities(
"ErrorFieldCanNotContainSpecialCharacters", $langs->transnoentities($fieldnamekey)),
null,
'errors');
169 $websitekey = strtolower(
GETPOST(
'ref'));
175 if ($ok &&
GETPOST(
'actionadd',
'alpha')) {
176 if ($tabrowid[$id]) {
178 $sql =
"SELECT MAX(".$tabrowid[
$id].
") newid from ".$tabname[
$id];
179 $result = $db->query($sql);
181 $obj = $db->fetch_object($result);
182 $newid = ($obj->newid + 1);
195 $sql =
"INSERT INTO ".$tabname[
$id].
" (";
197 if ($tabrowid[$id] && !in_array($tabrowid[$id], $listfieldinsert)) {
198 $sql .= $tabrowid[
$id].
",";
200 $sql .= $tabfieldinsert[
$id];
201 $sql .=
", status, date_creation)";
205 if ($tabrowid[$id] && !in_array($tabrowid[$id], $listfieldinsert)) {
209 foreach ($listfieldinsert as $f => $value) {
210 if ($value ==
'entity') {
211 $_POST[$listfieldvalue[$i]] =
$conf->entity;
213 if ($value ==
'ref') {
214 $_POST[$listfieldvalue[$i]] = strtolower(
GETPOST($listfieldvalue[$i]));
219 if (
GETPOST($listfieldvalue[$i]) ==
'') {
222 $sql .=
"'".$db->escape(
GETPOST($listfieldvalue[$i])).
"'";
226 $sql .=
", 1, '".$db->idate(
dol_now()).
"')";
229 $result = $db->query($sql);
234 if ($db->errno() ==
'DB_ERROR_RECORD_ALREADY_EXISTS') {
235 setEventMessages($langs->transnoentities(
"ErrorRecordAlreadyExists"),
null,
'errors');
243 if ($ok &&
GETPOST(
'actionmodify',
'alpha')) {
244 if ($tabrowid[$id]) {
245 $rowidcol = $tabrowid[
$id];
254 $website->fetch($rowid);
257 $sql =
"UPDATE ".$tabname[
$id].
" SET ";
259 if ($tabrowid[$id] && !in_array($tabrowid[$id], $listfieldmodify)) {
260 $sql .= $tabrowid[
$id].
"=";
261 $sql .=
"'".$db->escape($rowid).
"', ";
264 foreach ($listfieldmodify as $field) {
265 if ($field ==
'entity') {
266 $_POST[$listfieldvalue[$i]] =
$conf->entity;
272 if (
GETPOST($listfieldvalue[$i]) ==
'') {
275 $sql .=
"'".$db->escape(
GETPOST($listfieldvalue[$i])).
"'";
279 $sql .=
" WHERE ".$rowidcol.
" = ".((int) $rowid);
283 $resql = $db->query($sql);
286 if ($newname != $website->ref) {
287 $srcfile = DOL_DATA_ROOT.($conf->entity > 1 ?
'/'.$conf->entity :
'').
'/website/'.$website->ref;
288 $destfile = DOL_DATA_ROOT.($conf->entity > 1 ?
'/'.$conf->entity :
'').
'/website/'.$newname;
292 setEventMessages($langs->trans(
'ErrorDirAlreadyExists', $destfile),
null,
'errors');
294 @rename($srcfile, $destfile);
297 $arrayreplacement = array($website->ref.
'/htmlheader.html' => $newname.
'/htmlheader.html');
298 $listofilestochange =
dol_dir_list($destfile,
'files', 0,
'\.php$');
299 foreach ($listofilestochange as $key => $value) {
317if ($action ==
'confirm_delete' && $confirm ==
'yes') {
318 if ($tabrowid[$id]) {
319 $rowidcol = $tabrowid[
$id];
325 $website->fetch($rowid);
327 if ($website->id > 0) {
328 $sql =
"DELETE from ".MAIN_DB_PREFIX.
"website_account WHERE fk_website = ".((int) $rowid);
329 $result = $db->query($sql);
331 $sql =
"DELETE from ".MAIN_DB_PREFIX.
"website_page WHERE fk_website = ".((int) $rowid);
332 $result = $db->query($sql);
334 $sql =
"DELETE from ".MAIN_DB_PREFIX.
"website_extrafields WHERE fk_object = ".((int) $rowid);
335 $result = $db->query($sql);
337 $sql =
"DELETE from ".MAIN_DB_PREFIX.
"website WHERE rowid = ".((int) $rowid);
338 $result = $db->query($sql);
340 if ($db->errno() ==
'DB_ERROR_CHILD_EXISTS') {
341 setEventMessages($langs->transnoentities(
"ErrorRecordIsUsedByChild"),
null,
'errors');
356if ($action == $acts[0]) {
357 if ($tabrowid[$id]) {
358 $rowidcol = $tabrowid[
$id];
364 $sql =
"UPDATE ".$tabname[
$id].
" SET status = 1 WHERE rowid = ".((int) $rowid);
370 $result = $db->query($sql);
380if ($action == $acts[1]) {
381 if ($tabrowid[$id]) {
382 $rowidcol = $tabrowid[
$id];
388 $sql =
"UPDATE ".$tabname[
$id].
" SET status = 0 WHERE rowid = ".((int) $rowid);
394 $result = $db->query($sql);
409$form =
new Form($db);
412llxHeader(
'', $langs->trans(
"WebsiteSetup"),
'',
'', 0, 0,
'',
'',
'',
'mod-admin page-website');
414$titre = $langs->trans(
"WebsiteSetup");
415$linkback =
'<a href="'.($backtopage ? $backtopage : DOL_URL_ROOT.
'/admin/modules.php').
'">'.$langs->trans(
"BackToModuleList").
'</a>';
422$head[$h][0] = DOL_URL_ROOT.
"/admin/website.php";
423$head[$h][1] = $langs->trans(
"WebSites");
424$head[$h][2] =
'website';
427$head[$h][0] = DOL_URL_ROOT.
"/admin/website_options.php";
428$head[$h][1] = $langs->trans(
"Options");
429$head[$h][2] =
'options';
435print
'<span class="opacitymedium">'.$langs->trans(
"WebsiteSetupDesc").
'</span><br>';
440if ($action ==
'delete') {
441 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);
451 $sql .= $db->order($sortfield, $sortorder);
452 $sql .= $db->plimit($limit + 1, $offset);
455 $fieldlist = explode(
',', $tabfield[$id]);
457 print
'<form action="'.$_SERVER[
'PHP_SELF'].
'" method="POST">';
458 print
'<input type="hidden" name="token" value="'.newToken().
'">';
459 print
'<table class="noborder centpercent">';
464 print
'<tr class="liste_titre">';
465 foreach ($fieldlist as $field => $value) {
466 if (in_array($fieldlist[$field], array(
'date_creation',
'lastaccess',
'pageviews_previous_month',
'pageviews_month',
'pageviews_total'))) {
472 $valuetoshow = ucfirst($fieldlist[$field]);
473 $valuetoshow = $langs->trans($valuetoshow);
475 if ($fieldlist[$field] ==
'lang') {
476 $valuetoshow = $langs->trans(
"Language");
478 if ($valuetoshow !=
'') {
479 print
'<td class="'.$align.
'">';
480 if (!empty($tabhelp[$id][$value]) && preg_match(
'/^http(s*):/i', $tabhelp[$id][$value])) {
481 print
'<a href="'.$tabhelp[
$id][$value].
'" target="_blank" rel="noopener noreferrer">'.$valuetoshow.
' '.
img_help(1, $valuetoshow).
'</a>';
482 } elseif (!empty($tabhelp[$id][$value])) {
483 if ($value ==
'virtualhost') {
484 print $form->textwithpicto($valuetoshow, $tabhelp[$id][$value], 1,
'help',
'', 0, 2,
'tooltipvirtual');
486 print $form->textwithpicto($valuetoshow, $tabhelp[$id][$value]);
495 print
'<td colspan="4">';
500 print
'<tr class="oddeven">';
504 if (
GETPOST(
'actionadd',
'alpha')) {
505 foreach ($fieldlist as $key => $val) {
511 if (!isset($obj->position)) {
517 print
'<td colspan="3" class="right">';
518 if ($action !=
'edit') {
519 print
'<input type="submit" class="button button-add" name="actionadd" value="'.$langs->trans(
"Add").
'">';
530 $resql = $db->query($sql);
532 $num = $db->num_rows($resql);
537 print
'<form action="'.$_SERVER[
'PHP_SELF'].
'" method="POST">';
538 print
'<input type="hidden" name="token" value="'.newToken().
'">';
539 print
'<input type="hidden" name="page" value="'.$page.
'">';
540 print
'<input type="hidden" name="rowid" value="'.$rowid.
'">';
542 print
'<div class="div-table-responsive">';
543 print
'<table class="noborder centpercent">';
546 print
'<tr class="liste_titre">';
547 foreach ($fieldlist as $field => $value) {
554 if (in_array($fieldlist[$field], array(
'pageviews_total',
'pageviews_previous_month'))) {
565 $valuetoshow = ucfirst($fieldlist[$field]);
566 $valuetoshow = $langs->trans($valuetoshow);
567 if ($fieldlist[$field] ==
'lang') {
568 $valuetoshow = $langs->trans(
"Language");
570 if ($fieldlist[$field] ==
'type') {
571 $valuetoshow = $langs->trans(
"Type");
573 if ($fieldlist[$field] ==
'code') {
574 $valuetoshow = $langs->trans(
"Code");
576 if ($fieldlist[$field] ==
'date_creation') {
577 $valuetoshow = $langs->trans(
"DateCreation");
579 if ($fieldlist[$field] ==
'lastaccess') {
580 $valuetoshow = $langs->trans(
"LastAccess");
582 if ($fieldlist[$field] ==
'pageviews_previous_month') {
583 $valuetoshow = $langs->trans(
"PagesViewedPreviousMonth");
585 if ($fieldlist[$field] ==
'pageviews_total') {
586 $valuetoshow = $langs->trans(
"PagesViewedTotal");
591 print
getTitleFieldOfList($valuetoshow, 0, $_SERVER[
"PHP_SELF"], ($sortable ? $fieldlist[$field] :
''), ($page ?
'page='.$page.
'&' :
''),
"",
'', $sortfield, $sortorder, $align.
' ');
596 print
getTitleFieldOfList($langs->trans(
"Status"), 0, $_SERVER[
"PHP_SELF"],
"status", ($page ?
'page='.$page.
'&' :
''),
"",
'', $sortfield, $sortorder,
'center ');
603 $obj = $db->fetch_object($resql);
605 print
'<tr class="oddeven" id="rowid-'.$obj->rowid.
'">';
606 if ($action ==
'edit' && ($rowid == (!empty($obj->rowid) ? $obj->rowid : $obj->code))) {
608 $parameters = array(
'fieldlist' => $fieldlist,
'tabname' => $tabname[$id]);
609 $reshook = $hookmanager->executeHooks(
'editWebsiteFieldlist', $parameters, $obj, $tmpaction);
610 $error = $hookmanager->error;
611 $errors = $hookmanager->errors;
613 if (empty($reshook)) {
617 print
'<td colspan="7" class="right"><a name="'.(!empty($obj->rowid) ? $obj->rowid : $obj->code).
'"> </a>';
618 print
'<input type="submit" class="button button-edit small" name="actionmodify" value="'.$langs->trans(
"Modify").
'">';
620 print
'<input type="submit" class="button button-cancel small" name="actioncancel" value="'.$langs->trans(
"Cancel").
'">';
624 $parameters = array(
'fieldlist' => $fieldlist,
'tabname' => $tabname[$id]);
625 $reshook = $hookmanager->executeHooks(
'viewWebsiteFieldlist', $parameters, $obj, $tmpaction);
627 $error = $hookmanager->error;
628 $errors = $hookmanager->errors;
630 if (empty($reshook)) {
631 foreach ($fieldlist as $field => $value) {
633 $fieldname = $fieldlist[$field];
635 if (in_array($fieldname, array(
'pageviews_total',
'pageviews_previous_month'))) {
638 $valuetoshow = $obj->$fieldname;
642 print
'<td class="'.$align.
'">'.$valuetoshow.
'</td>';
654 $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) :
'').
'&';
658 print
'<td align="center" class="nowrap">';
659 print
'<a class="reposition" href="'.$url.
'action='.$acts[($obj->status ? 1 : 0)].
'&token='.
newToken().
'">'.$actl[($obj->status ? 1 : 0)].
'</a>';
663 print
'<td align="center"><a class="reposition editfielda" href="'.$url.
'action=edit&token='.
newToken().
'">'.
img_edit().
'</a></td>';
667 print
'<td align="center"><a class="reposition" href="'.$url.
'action=delete&token='.
newToken().
'">'.
img_delete().
'</a></td>';
669 print
'<td class="center">'.img_delete($langs->trans(
"DisableSiteFirst"),
'class="opacitymedium"').
'</td>';
705 global
$conf, $langs, $db;
708 global $elementList, $sourceList, $localtax_typeList;
713 foreach ($fieldlist as $field => $value) {
714 if (in_array($fieldlist[$field], array(
'lastaccess',
'pageviews_previous_month',
'pageviews_month',
'pageviews_total'))) {
718 $fieldname = $fieldlist[$field];
720 if ($fieldlist[$field] ==
'lang') {
724 } elseif ($fieldlist[$field] ==
'code' && isset($obj->$fieldname)) {
725 print
'<td><input type="text" class="flat" value="'.(!empty($obj->$fieldname) ? $obj->$fieldname :
'').
'" size="10" name="'.$fieldlist[$field].
'"></td>';
727 if ($fieldlist[$field] ==
'date_creation') {
733 if ($fieldlist[$field] ==
'code') {
736 if ($fieldlist[$field] ==
'position') {
739 if ($fieldlist[$field] ==
'libelle') {
740 $size =
'size="32" ';
742 if ($fieldlist[$field] ==
'tracking') {
743 $size =
'size="92" ';
745 if ($fieldlist[$field] ==
'sortorder') {
748 print
'<input type="text" '.$size.
' class="flat" value="'.(isset($obj->$fieldname) ? $obj->$fieldname :
'').
'" name="'.$fieldlist[$field].
'">';
fieldListWebsites($fieldlist, $obj=null, $tabname='', $context='')
Show fields in insert/edit mode.
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)
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.
load_fiche_titre($title, $morehtmlright='', $picto='generic', $pictoisfullpath=0, $id='', $morecssontable='', $morehtmlcenter='')
Load a title with picto.
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_delete($titlealt='default', $other='class="pictodelete"', $morecss='')
Show delete logo.
img_picto($titlealt, $picto, $moreatt='', $pictoisfullpath=0, $srconly=0, $notitle=0, $alt='', $morecss='', $marginleftonlyshort=2)
Show picto whatever it's its name (generic function)
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)
Show tabs of a record.
dol_get_fiche_end($notab=0)
Return tab footer of a card.
dol_now($mode='auto')
Return date for now.
newToken()
Return the value of token currently saved into session with name 'newtoken'.
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_sanitizeFileName($str, $newstr='_', $unaccent=1)
Clean a string to use it as a file name.
dol_print_error($db=null, $error='', $errors=null)
Displays error message system with all the information to facilitate the diagnosis and the escalation...
getDolGlobalString($key, $default='')
Return a Dolibarr global constant string value.
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.
global $conf
The following vars must be defined: $type2label $form $conf, $lang, The following vars may also be de...
$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.