25require
'../main.inc.php';
26require_once DOL_DOCUMENT_ROOT.
'/core/class/html.formadmin.class.php';
27require_once DOL_DOCUMENT_ROOT.
'/core/class/html.formcompany.class.php';
28require_once DOL_DOCUMENT_ROOT.
'/core/lib/admin.lib.php';
29require_once DOL_DOCUMENT_ROOT.
'/core/lib/files.lib.php';
30require_once DOL_DOCUMENT_ROOT.
'/core/lib/website.lib.php';
31require_once DOL_DOCUMENT_ROOT.
'/core/lib/functions2.lib.php';
32require_once DOL_DOCUMENT_ROOT.
'/core/class/doleditor.class.php';
33require_once DOL_DOCUMENT_ROOT.
'/website/class/website.class.php';
36$langs->loadlangs(array(
'errors',
'admin',
'companies',
'website'));
38$action =
GETPOST(
'action',
'alpha') ?
GETPOST(
'action',
'alpha') :
'view';
39$confirm =
GETPOST(
'confirm',
'alpha');
40$backtopage =
GETPOST(
'backtopage',
'alpha');
42$rowid =
GETPOST(
'rowid',
'alpha');
48$actl[0] =
img_picto($langs->trans(
"Disabled"),
'switch_off',
'class="size15x"');
49$actl[1] =
img_picto($langs->trans(
"Activated"),
'switch_on',
'class="size15x"');
52$limit =
GETPOST(
'limit',
'int') ?
GETPOST(
'limit',
'int') : $conf->liste_limit;
53$sortfield =
GETPOST(
'sortfield',
'aZ09comma');
54$sortorder =
GETPOST(
'sortorder',
'aZ09comma');
55$page = GETPOSTISSET(
'pageplusone') ? (
GETPOST(
'pageplusone') - 1) :
GETPOST(
"page",
'int');
56if (empty($page) || $page == -1) {
59$offset = $limit * $page;
63if (empty($sortfield)) {
64 $sortfield =
'position, ref';
66if (empty($sortorder)) {
71$hookmanager->initHooks(array(
'website'));
75$tabname[1] = MAIN_DB_PREFIX.
"website";
79$tablib[1] =
"Websites";
83$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').
')';
87$tabsqlsort[1] =
"ref ASC";
91$tabfield[1] =
"ref,description,virtualhost,position,date_creation,lastaccess,pageviews_previous_month,pageviews_total";
94$tabfieldvalue = array();
95$tabfieldvalue[1] =
"ref,description,virtualhost,position,entity";
98$tabfieldinsert = array();
99$tabfieldinsert[1] =
"ref,description,virtualhost,position,entity";
109$tabcond[1] = (isModEnabled(
'website'));
113$tabhelp[1] = array(
'ref'=>$langs->trans(
"EnterAnyCode"),
'virtualhost'=>$langs->trans(
"SetHereVirtualHost", DOL_DATA_ROOT.($conf->entity > 1 ?
'/'.$conf->entity :
'').
'/website/<i>websiteref</i>'));
116$tabfieldcheck = array();
117$tabfieldcheck[1] = array();
121$elementList = array();
122$sourceList = array();
134if (
GETPOST(
'actionadd',
'alpha') ||
GETPOST(
'actionmodify',
'alpha')) {
135 $listfield = explode(
',', $tabfield[$id]);
136 $listfieldinsert = explode(
',', $tabfieldinsert[$id]);
137 $listfieldmodify = explode(
',', $tabfieldinsert[$id]);
138 $listfieldvalue = explode(
',', $tabfieldvalue[$id]);
142 foreach ($listfield as $f => $value) {
143 if ($value ==
'ref' && (!GETPOSTISSET($value) ||
GETPOST($value) ==
'')) {
145 $fieldnamekey = $listfield[$f];
146 setEventMessages($langs->transnoentities(
"ErrorFieldRequired", $langs->transnoentities($fieldnamekey)),
null,
'errors');
148 } elseif ($value ==
'ref' && !preg_match(
'/^[a-z0-9_\-\.]+$/i',
GETPOST($value))) {
150 $fieldnamekey = $listfield[$f];
151 setEventMessages($langs->transnoentities(
"ErrorFieldCanNotContainSpecialCharacters", $langs->transnoentities($fieldnamekey)),
null,
'errors');
158 $websitekey = strtolower(
GETPOST(
'ref'));
162 if ($ok &&
GETPOST(
'actionadd',
'alpha')) {
163 if ($tabrowid[$id]) {
166 $sql =
"SELECT max(".$tabrowid[$id].
") newid from ".$tabname[$id];
167 $result = $db->query($sql);
169 $obj = $db->fetch_object($result);
170 $newid = ($obj->newid + 1);
183 $sql =
"INSERT INTO ".$tabname[$id].
" (";
185 if ($tabrowid[$id] && !in_array($tabrowid[$id], $listfieldinsert)) {
186 $sql .= $tabrowid[$id].
",";
188 $sql .= $tabfieldinsert[$id];
189 $sql .=
", status, date_creation)";
193 if ($tabrowid[$id] && !in_array($tabrowid[$id], $listfieldinsert)) {
197 foreach ($listfieldinsert as $f => $value) {
198 if ($value ==
'entity') {
199 $_POST[$listfieldvalue[$i]] = $conf->entity;
201 if ($value ==
'ref') {
202 $_POST[$listfieldvalue[$i]] = strtolower(
GETPOST($listfieldvalue[$i]));
207 if (
GETPOST($listfieldvalue[$i]) ==
'') {
210 $sql .=
"'".$db->escape(
GETPOST($listfieldvalue[$i])).
"'";
214 $sql .=
", 1, '".$db->idate(
dol_now()).
"')";
217 $result = $db->query($sql);
222 if ($db->errno() ==
'DB_ERROR_RECORD_ALREADY_EXISTS') {
223 setEventMessages($langs->transnoentities(
"ErrorRecordAlreadyExists"),
null,
'errors');
231 if ($ok &&
GETPOST(
'actionmodify',
'alpha')) {
232 if ($tabrowid[$id]) {
233 $rowidcol = $tabrowid[$id];
241 $rowid =
GETPOST(
'rowid',
'int');
242 $website->fetch($rowid);
245 $sql =
"UPDATE ".$tabname[$id].
" SET ";
247 if ($tabrowid[$id] && !in_array($tabrowid[$id], $listfieldmodify)) {
248 $sql .= $tabrowid[$id].
"=";
249 $sql .=
"'".$db->escape($rowid).
"', ";
252 foreach ($listfieldmodify as $field) {
253 if ($field ==
'entity') {
254 $_POST[$listfieldvalue[$i]] = $conf->entity;
260 if ($_POST[$listfieldvalue[$i]] ==
'') {
263 $sql .=
"'".$db->escape(
GETPOST($listfieldvalue[$i])).
"'";
267 $sql .=
" WHERE ".$rowidcol.
" = ".((int) $rowid);
271 $resql = $db->query($sql);
274 if ($newname != $website->ref) {
275 $srcfile = DOL_DATA_ROOT.($conf->entity > 1 ?
'/'.$conf->entity :
'').
'/website/'.$website->ref;
276 $destfile = DOL_DATA_ROOT.($conf->entity > 1 ?
'/'.$conf->entity :
'').
'/website/'.$newname;
280 setEventMessages($langs->trans(
'ErrorDirAlreadyExists', $destfile),
null,
'errors');
282 @rename($srcfile, $destfile);
285 $arrayreplacement = array($website->ref.
'/htmlheader.html' => $newname.
'/htmlheader.html');
286 $listofilestochange =
dol_dir_list($destfile,
'files', 0,
'\.php$');
287 foreach ($listofilestochange as $key => $value) {
306if (
GETPOST(
'actioncancel',
'alpha')) {
310if ($action ==
'confirm_delete' && $confirm ==
'yes') {
311 if ($tabrowid[$id]) {
312 $rowidcol = $tabrowid[$id];
318 $website->fetch($rowid);
320 if ($website->id > 0) {
321 $sql =
"DELETE from ".MAIN_DB_PREFIX.
"website_account WHERE fk_website = ".((int) $rowid);
322 $result = $db->query($sql);
324 $sql =
"DELETE from ".MAIN_DB_PREFIX.
"website_page WHERE fk_website = ".((int) $rowid);
325 $result = $db->query($sql);
327 $sql =
"DELETE from ".MAIN_DB_PREFIX.
"website_extrafields WHERE fk_object = ".((int) $rowid);
328 $result = $db->query($sql);
330 $sql =
"DELETE from ".MAIN_DB_PREFIX.
"website WHERE rowid = ".((int) $rowid);
331 $result = $db->query($sql);
333 if ($db->errno() ==
'DB_ERROR_CHILD_EXISTS') {
334 setEventMessages($langs->transnoentities(
"ErrorRecordIsUsedByChild"),
null,
'errors');
349if ($action == $acts[0]) {
350 if ($tabrowid[$id]) {
351 $rowidcol = $tabrowid[$id];
357 $sql =
"UPDATE ".$tabname[$id].
" SET status = 1 WHERE rowid = ".((int) $rowid);
360 $result = $db->query($sql);
367if ($action == $acts[1]) {
368 if ($tabrowid[$id]) {
369 $rowidcol = $tabrowid[$id];
375 $sql =
"UPDATE ".$tabname[$id].
" SET status = 0 WHERE rowid = ".((int) $rowid);
378 $result = $db->query($sql);
390$form =
new Form($db);
393llxHeader(
'', $langs->trans(
"WebsiteSetup"));
395$titre = $langs->trans(
"WebsiteSetup");
396$linkback =
'<a href="'.($backtopage ? $backtopage : DOL_URL_ROOT.
'/admin/modules.php').
'">'.$langs->trans(
"BackToModuleList").
'</a>';
403$head[$h][0] = DOL_URL_ROOT.
"/admin/website.php";
404$head[$h][1] = $langs->trans(
"WebSites");
405$head[$h][2] =
'website';
408$head[$h][0] = DOL_URL_ROOT.
"/admin/website_options.php";
409$head[$h][1] = $langs->trans(
"Options");
410$head[$h][2] =
'options';
416print
'<span class="opacitymedium">'.$langs->trans(
"WebsiteSetupDesc").
'</span><br>';
421if ($action ==
'delete') {
422 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);
432 $sql .= $db->order($sortfield, $sortorder);
433 $sql .= $db->plimit($limit + 1, $offset);
436 $fieldlist = explode(
',', $tabfield[$id]);
438 print
'<form action="'.$_SERVER[
'PHP_SELF'].
'" method="POST">';
439 print
'<input type="hidden" name="token" value="'.newToken().
'">';
440 print
'<table class="noborder centpercent">';
445 print
'<tr class="liste_titre">';
446 foreach ($fieldlist as $field => $value) {
447 if (in_array($fieldlist[$field], array(
'date_creation',
'lastaccess',
'pageviews_previous_month',
'pageviews_month',
'pageviews_total'))) {
453 $valuetoshow = ucfirst($fieldlist[$field]);
454 $valuetoshow = $langs->trans($valuetoshow);
456 if ($fieldlist[$field] ==
'lang') {
457 $valuetoshow = $langs->trans(
"Language");
459 if ($valuetoshow !=
'') {
460 print
'<td class="'.$align.
'">';
461 if (!empty($tabhelp[$id][$value]) && preg_match(
'/^http(s*):/i', $tabhelp[$id][$value])) {
462 print
'<a href="'.$tabhelp[$id][$value].
'" target="_blank" rel="noopener noreferrer">'.$valuetoshow.
' '.
img_help(1, $valuetoshow).
'</a>';
463 } elseif (!empty($tabhelp[$id][$value])) {
464 if ($value ==
'virtualhost') {
465 print $form->textwithpicto($valuetoshow, $tabhelp[$id][$value], 1,
'help',
'', 0, 2,
'tooltipvirtual');
467 print $form->textwithpicto($valuetoshow, $tabhelp[$id][$value]);
476 print
'<td colspan="4">';
481 print
'<tr class="oddeven">';
483 $obj =
new stdClass();
485 if (
GETPOST(
'actionadd',
'alpha')) {
486 foreach ($fieldlist as $key => $val) {
492 if (!isset($obj->position)) {
498 print
'<td colspan="3" class="right">';
499 if ($action !=
'edit') {
500 print
'<input type="submit" class="button button-add" name="actionadd" value="'.$langs->trans(
"Add").
'">';
511 $resql = $db->query($sql);
513 $num = $db->num_rows($resql);
518 print
'<form action="'.$_SERVER[
'PHP_SELF'].
'" method="POST">';
519 print
'<input type="hidden" name="token" value="'.newToken().
'">';
520 print
'<input type="hidden" name="page" value="'.$page.
'">';
521 print
'<input type="hidden" name="rowid" value="'.$rowid.
'">';
523 print
'<div class="div-table-responsive">';
524 print
'<table class="noborder centpercent">';
527 print
'<tr class="liste_titre">';
528 foreach ($fieldlist as $field => $value) {
535 if (in_array($fieldlist[$field], array(
'pageviews_total',
'pageviews_previous_month'))) {
546 $valuetoshow = ucfirst($fieldlist[$field]);
547 $valuetoshow = $langs->trans($valuetoshow);
548 if ($fieldlist[$field] ==
'lang') {
549 $valuetoshow = $langs->trans(
"Language");
551 if ($fieldlist[$field] ==
'type') {
552 $valuetoshow = $langs->trans(
"Type");
554 if ($fieldlist[$field] ==
'code') {
555 $valuetoshow = $langs->trans(
"Code");
557 if ($fieldlist[$field] ==
'date_creation') {
558 $valuetoshow = $langs->trans(
"DateCreation");
560 if ($fieldlist[$field] ==
'lastaccess') {
561 $valuetoshow = $langs->trans(
"LastAccess");
563 if ($fieldlist[$field] ==
'pageviews_previous_month') {
564 $valuetoshow = $langs->trans(
"PagesViewedPreviousMonth");
566 if ($fieldlist[$field] ==
'pageviews_total') {
567 $valuetoshow = $langs->trans(
"PagesViewedTotal");
572 print
getTitleFieldOfList($valuetoshow, 0, $_SERVER[
"PHP_SELF"], ($sortable ? $fieldlist[$field] :
''), ($page ?
'page='.$page.
'&' :
''),
"",
'', $sortfield, $sortorder, $align.
' ');
577 print
getTitleFieldOfList($langs->trans(
"Status"), 0, $_SERVER[
"PHP_SELF"],
"status", ($page ?
'page='.$page.
'&' :
''),
"",
'', $sortfield, $sortorder,
'center ');
584 $obj = $db->fetch_object($resql);
586 print
'<tr class="oddeven" id="rowid-'.$obj->rowid.
'">';
587 if ($action ==
'edit' && ($rowid == (!empty($obj->rowid) ? $obj->rowid : $obj->code))) {
589 $parameters = array(
'fieldlist'=>$fieldlist,
'tabname'=>$tabname[$id]);
590 $reshook = $hookmanager->executeHooks(
'editWebsiteFieldlist', $parameters, $obj, $tmpaction);
591 $error = $hookmanager->error; $errors = $hookmanager->errors;
593 if (empty($reshook)) {
597 print
'<td colspan="7" class="right"><a name="'.(!empty($obj->rowid) ? $obj->rowid : $obj->code).
'"> </a>';
598 print
'<input type="submit" class="button button-edit small" name="actionmodify" value="'.$langs->trans(
"Modify").
'">';
600 print
'<input type="submit" class="button button-cancel small" name="actioncancel" value="'.$langs->trans(
"Cancel").
'">';
604 $parameters = array(
'fieldlist'=>$fieldlist,
'tabname'=>$tabname[$id]);
605 $reshook = $hookmanager->executeHooks(
'viewWebsiteFieldlist', $parameters, $obj, $tmpaction);
607 $error = $hookmanager->error; $errors = $hookmanager->errors;
609 if (empty($reshook)) {
610 foreach ($fieldlist as $field => $value) {
612 $fieldname = $fieldlist[$field];
614 if (in_array($fieldname, array(
'pageviews_total',
'pageviews_previous_month'))) {
617 $valuetoshow = $obj->$fieldname;
621 print
'<td class="'.$align.
'">'.$valuetoshow.
'</td>';
627 $iserasable = 1; $isdisable = 1;
632 $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) :
'').
'&';
636 print
'<td align="center" class="nowrap">';
637 print
'<a class="reposition" href="'.$url.
'action='.$acts[($obj->status ? 1 : 0)].
'&token='.newToken().
'">'.$actl[($obj->status ? 1 : 0)].
'</a>';
641 print
'<td align="center"><a class="reposition editfielda" href="'.$url.
'action=edit&token='.newToken().
'">'.
img_edit().
'</a></td>';
645 print
'<td align="center"><a class="reposition" href="'.$url.
'action=delete&token='.newToken().
'">'.
img_delete().
'</a></td>';
647 print
'<td class="center">'.img_delete($langs->trans(
"DisableSiteFirst"),
'class="opacitymedium"').
'</td>';
683 global $conf, $langs, $db;
686 global $elementList, $sourceList, $localtax_typeList;
691 foreach ($fieldlist as $field => $value) {
692 if (in_array($fieldlist[$field], array(
'lastaccess',
'pageviews_previous_month',
'pageviews_month',
'pageviews_total'))) {
696 $fieldname = $fieldlist[$field];
698 if ($fieldlist[$field] ==
'lang') {
700 print $formadmin->select_language($conf->global->MAIN_LANG_DEFAULT,
'lang');
702 } elseif ($fieldlist[$field] ==
'code' && isset($obj->$fieldname)) {
703 print
'<td><input type="text" class="flat" value="'.(!empty($obj->$fieldname) ? $obj->$fieldname :
'').
'" size="10" name="'.$fieldlist[$field].
'"></td>';
705 if ($fieldlist[$field] ==
'date_creation') {
711 if ($fieldlist[$field] ==
'code') {
714 if ($fieldlist[$field] ==
'position') {
717 if ($fieldlist[$field] ==
'libelle') {
718 $size =
'size="32" ';
720 if ($fieldlist[$field] ==
'tracking') {
721 $size =
'size="92" ';
723 if ($fieldlist[$field] ==
'sortorder') {
726 print
'<input type="text" '.$size.
' class="flat" value="'.(isset($obj->$fieldname) ? $obj->$fieldname :
'').
'" name="'.$fieldlist[$field].
'">';
fieldListWebsites($fieldlist, $obj='', $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()
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)
dolReplaceInFile($srcfile, $arrayreplacement, $destfile='', $newmask=0, $indexdatabase=0, $arrayreplacementisregex=0)
Make replacement of strings into a file.
dol_dir_list($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.
load_fiche_titre($titre, $morehtmlright='', $picto='generic', $pictoisfullpath=0, $id='', $morecssontable='', $morehtmlcenter='')
Load a title with picto.
img_help($usehelpcursor=1, $usealttitle=1)
Show help logo with cursor "?".
img_delete($titlealt='default', $other='class="pictodelete"', $morecss='')
Show delete logo.
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_print_error($db='', $error='', $errors=null)
Displays error message system with all the information to facilitate the diagnosis and the escalation...
dol_get_fiche_end($notab=0)
Return tab footer of a card.
dol_now($mode='auto')
Return date for now.
img_picto($titlealt, $picto, $moreatt='', $pictoisfullpath=false, $srconly=0, $notitle=0, $alt='', $morecss='', $marginleftonlyshort=2)
Show picto whatever it's its name (generic function)
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.
setEventMessages($mesg, $mesgs, $style='mesgs', $messagekey='', $noduplicate=0)
Set event messages in dol_events session object.
dol_sanitizeFileName($str, $newstr='_', $unaccent=1)
Clean a string to use it as a file name.
img_edit($titlealt='default', $float=0, $other='')
Show logo editer/modifier 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.
accessforbidden($message='', $printheader=1, $printfooter=1, $showonlymessage=0, $params=null)
Show a message to say access is forbidden and stop program.