dolibarr  17.0.3
index.php
Go to the documentation of this file.
1 <?php
2 /* Copyright (C) 2016-2017 Laurent Destailleur <eldy@users.sourceforge.net>
3  *
4  * This program is free software; you can redistribute it and/or modify
5  * it under the terms of the GNU General Public License as published by
6  * the Free Software Foundation; either version 3 of the License, or
7  * (at your option) any later version.
8  *
9  * This program is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12  * GNU General Public License for more details.
13  *
14  * You should have received a copy of the GNU General Public License
15  * along with this program. If not, see <https://www.gnu.org/licenses/>.
16  */
17 
24 define('NOSCANPOSTFORINJECTION', 1);
25 define('NOSTYLECHECK', 1);
26 
27 // Load Dolibarr environment
28 require '../main.inc.php';
29 require_once DOL_DOCUMENT_ROOT.'/core/lib/admin.lib.php';
30 require_once DOL_DOCUMENT_ROOT.'/core/lib/files.lib.php';
31 
32 // Load translation files required by the page
33 $langs->loadLangs(array("admin", "other", "website"));
34 
35 if (!$user->admin) {
37 }
38 
39 $conf->dol_hide_leftmenu = 1; // Force hide of left menu.
40 
41 $error = 0;
42 $website = GETPOST('website', 'alpha');
43 $page = GETPOST('page', 'alpha');
44 $pageid = GETPOST('pageid', 'int');
45 $action = GETPOST('action', 'aZ09');
46 
47 if (GETPOST('delete')) {
48  $action = 'delete';
49 }
50 if (GETPOST('preview')) {
51  $action = 'preview';
52 }
53 if (GETPOST('create')) {
54  $action = 'create';
55 }
56 if (GETPOST('editmedia')) {
57  $action = 'editmedia';
58 }
59 if (GETPOST('editcss')) {
60  $action = 'editcss';
61 }
62 if (GETPOST('editmenu')) {
63  $action = 'editmenu';
64 }
65 if (GETPOST('setashome')) {
66  $action = 'setashome';
67 }
68 if (GETPOST('editmeta')) {
69  $action = 'editmeta';
70 }
71 if (GETPOST('editcontent')) {
72  $action = 'editcontent';
73 }
74 
75 if (empty($action)) {
76  $action = 'preview';
77 }
78 
79 
80 
81 
82 /*
83  * Actions
84  */
85 
86 if (GETPOST('refreshsite')) {
87  $pageid = 0; // If we change the site, we reset the pageid.
88 }
89 if (GETPOST('refreshpage')) {
90  $action = 'preview';
91 }
92 
93 
94 // Add a collab page
95 if ($action == 'add') {
96  $db->begin();
97 
98  $objectpage->title = GETPOST('WEBSITE_TITLE');
99  $objectpage->pageurl = GETPOST('WEBSITE_PAGENAME');
100  $objectpage->description = GETPOST('WEBSITE_DESCRIPTION');
101  $objectpage->keywords = GETPOST('WEBSITE_KEYWORD');
102 
103  if (empty($objectpage->title)) {
104  setEventMessages($langs->trans("ErrorFieldRequired", $langs->transnoentitiesnoconv("WEBSITE_PAGENAME")), null, 'errors');
105  $error++;
106  }
107 
108  if (!$error) {
109  $res = $objectpage->create($user);
110  if ($res <= 0) {
111  $error++;
112  setEventMessages($objectpage->error, $objectpage->errors, 'errors');
113  }
114  }
115  if (!$error) {
116  $db->commit();
117  setEventMessages($langs->trans("PageAdded", $objectpage->pageurl), null, 'mesgs');
118  $action = '';
119  } else {
120  $db->rollback();
121  }
122 
123  $action = 'preview';
124  $id = $objectpage->id;
125 }
126 
127 // Update page
128 if ($action == 'delete') {
129  $db->begin();
130 
131  $res = $object->fetch(0, $website);
132 
133  $res = $objectpage->fetch($pageid, $object->fk_website);
134 
135  if ($res > 0) {
136  $res = $objectpage->delete($user);
137  if (!($res > 0)) {
138  $error++;
139  setEventMessages($objectpage->error, $objectpage->errors, 'errors');
140  }
141 
142  if (!$error) {
143  $db->commit();
144  setEventMessages($langs->trans("PageDeleted", $objectpage->pageurl, $website), null, 'mesgs');
145 
146  header("Location: ".$_SERVER["PHP_SELF"].'?website='.$website);
147  exit;
148  } else {
149  $db->rollback();
150  }
151  } else {
152  dol_print_error($db);
153  }
154 }
155 
156 
157 
158 /*
159  * View
160  */
161 
162 $form = new Form($db);
163 
164 $help_url = '';
165 
166 llxHeader('', $langs->trans("WebsiteSetup"), $help_url, '', 0, '', '', '', '', '', '<!-- Begin div class="fiche" -->'."\n".'<div class="fichebutwithotherclass">');
167 
168 print "\n".'<form action="'.$_SERVER["PHP_SELF"].'" method="POST"><div>';
169 print '<input type="hidden" name="token" value="'.newToken().'">';
170 if ($action == 'create') {
171  print '<input type="hidden" name="action" value="add">';
172 }
173 
174 
175 // Add a margin under toolbar ?
176 $style = '';
177 if ($action != 'preview' && $action != 'editcontent') {
178  $style = ' margin-bottom: 5px;';
179 }
180 
181 //var_dump($objectpage);exit;
182 print '<div class="centpercent websitebar">';
183 
184 
185 
186 
187 print "</div>\n</form>\n";
188 
189 // End of page
190 llxFooter();
191 $db->close();
GETPOST
GETPOST($paramname, $check='alphanohtml', $method=0, $filter=null, $options=null, $noreplace=0)
Return value of a param into GET or POST supervariable.
Definition: functions.lib.php:520
dol_print_error
dol_print_error($db='', $error='', $errors=null)
Displays error message system with all the information to facilitate the diagnosis and the escalation...
Definition: functions.lib.php:4993
$form
if($cancel &&! $id) if($action=='add' &&! $cancel) if($action=='delete') if($id) $form
Actions.
Definition: card.php:143
$help_url
if(GETPOST('button_removefilter_x', 'alpha')||GETPOST('button_removefilter.x', 'alpha')||GETPOST('button_removefilter', 'alpha')) if(GETPOST('button_search_x', 'alpha')||GETPOST('button_search.x', 'alpha')||GETPOST('button_search', 'alpha')) if($action=="save" &&empty($cancel)) $help_url
View.
Definition: agenda.php:118
llxFooter
llxFooter()
Footer empty.
Definition: index.php:71
llxHeader
if(!defined('NOTOKENRENEWAL')) if(!defined('NOLOGIN')) if(!defined('NOCSRFCHECK')) if(!defined('NOREQUIREMENU')) if(!defined('NOREQUIREHTML')) if(!defined('NOREQUIREAJAX')) if(!defined('NOIPCHECK')) if(!defined('NOBROWSERNOTIF')) llxHeader()
Header empty.
Definition: index.php:63
Form
Class to manage generation of HTML components Only common components must be here.
Definition: html.form.class.php:53
setEventMessages
setEventMessages($mesg, $mesgs, $style='mesgs', $messagekey='')
Set event messages in dol_events session object.
Definition: functions.lib.php:8466
accessforbidden
accessforbidden($message='', $printheader=1, $printfooter=1, $showonlymessage=0, $params=null)
Show a message to say access is forbidden and stop program.
Definition: security.lib.php:1125