dolibarr  16.0.5
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 require '../main.inc.php';
28 require_once DOL_DOCUMENT_ROOT.'/core/lib/admin.lib.php';
29 require_once DOL_DOCUMENT_ROOT.'/core/lib/files.lib.php';
30 
31 // Load translation files required by the page
32 $langs->loadLangs(array("admin", "other", "website"));
33 
34 if (!$user->admin) {
36 }
37 
38 $conf->dol_hide_leftmenu = 1; // Force hide of left menu.
39 
40 $error = 0;
41 $website = GETPOST('website', 'alpha');
42 $page = GETPOST('page', 'alpha');
43 $pageid = GETPOST('pageid', 'int');
44 $action = GETPOST('action', 'aZ09');
45 
46 if (GETPOST('delete')) {
47  $action = 'delete';
48 }
49 if (GETPOST('preview')) {
50  $action = 'preview';
51 }
52 if (GETPOST('create')) {
53  $action = 'create';
54 }
55 if (GETPOST('editmedia')) {
56  $action = 'editmedia';
57 }
58 if (GETPOST('editcss')) {
59  $action = 'editcss';
60 }
61 if (GETPOST('editmenu')) {
62  $action = 'editmenu';
63 }
64 if (GETPOST('setashome')) {
65  $action = 'setashome';
66 }
67 if (GETPOST('editmeta')) {
68  $action = 'editmeta';
69 }
70 if (GETPOST('editcontent')) {
71  $action = 'editcontent';
72 }
73 
74 if (empty($action)) {
75  $action = 'preview';
76 }
77 
78 
79 
80 
81 /*
82  * Actions
83  */
84 
85 if (GETPOST('refreshsite')) {
86  $pageid = 0; // If we change the site, we reset the pageid.
87 }
88 if (GETPOST('refreshpage')) {
89  $action = 'preview';
90 }
91 
92 
93 // Add a collab page
94 if ($action == 'add') {
95  $db->begin();
96 
97  $objectpage->title = GETPOST('WEBSITE_TITLE');
98  $objectpage->pageurl = GETPOST('WEBSITE_PAGENAME');
99  $objectpage->description = GETPOST('WEBSITE_DESCRIPTION');
100  $objectpage->keywords = GETPOST('WEBSITE_KEYWORD');
101 
102  if (empty($objectpage->title)) {
103  setEventMessages($langs->trans("ErrorFieldRequired", $langs->transnoentitiesnoconv("WEBSITE_PAGENAME")), null, 'errors');
104  $error++;
105  }
106 
107  if (!$error) {
108  $res = $objectpage->create($user);
109  if ($res <= 0) {
110  $error++;
111  setEventMessages($objectpage->error, $objectpage->errors, 'errors');
112  }
113  }
114  if (!$error) {
115  $db->commit();
116  setEventMessages($langs->trans("PageAdded", $objectpage->pageurl), null, 'mesgs');
117  $action = '';
118  } else {
119  $db->rollback();
120  }
121 
122  $action = 'preview';
123  $id = $objectpage->id;
124 }
125 
126 // Update page
127 if ($action == 'delete') {
128  $db->begin();
129 
130  $res = $object->fetch(0, $website);
131 
132  $res = $objectpage->fetch($pageid, $object->fk_website);
133 
134  if ($res > 0) {
135  $res = $objectpage->delete($user);
136  if (!($res > 0)) {
137  $error++;
138  setEventMessages($objectpage->error, $objectpage->errors, 'errors');
139  }
140 
141  if (!$error) {
142  $db->commit();
143  setEventMessages($langs->trans("PageDeleted", $objectpage->pageurl, $website), null, 'mesgs');
144 
145  header("Location: ".$_SERVER["PHP_SELF"].'?website='.$website);
146  exit;
147  } else {
148  $db->rollback();
149  }
150  } else {
151  dol_print_error($db);
152  }
153 }
154 
155 
156 
157 /*
158  * View
159  */
160 
161 $form = new Form($db);
162 
163 $help_url = '';
164 
165 llxHeader('', $langs->trans("WebsiteSetup"), $help_url, '', 0, '', '', '', '', '', '<!-- Begin div class="fiche" -->'."\n".'<div class="fichebutwithotherclass">');
166 
167 print "\n".'<form action="'.$_SERVER["PHP_SELF"].'" method="POST"><div>';
168 print '<input type="hidden" name="token" value="'.newToken().'">';
169 if ($action == 'create') {
170  print '<input type="hidden" name="action" value="add">';
171 }
172 
173 
174 // Add a margin under toolbar ?
175 $style = '';
176 if ($action != 'preview' && $action != 'editcontent') {
177  $style = ' margin-bottom: 5px;';
178 }
179 
180 //var_dump($objectpage);exit;
181 print '<div class="centpercent websitebar">';
182 
183 
184 
185 
186 print "</div>\n</form>\n";
187 
188 // End of page
189 llxFooter();
190 $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:484
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:4844
$form
if($cancel &&! $id) if($action=='add' &&! $cancel) if($action=='delete') if($id) $form
Actions.
Definition: card.php:142
$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:116
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:52
setEventMessages
setEventMessages($mesg, $mesgs, $style='mesgs', $messagekey='')
Set event messages in dol_events session object.
Definition: functions.lib.php:8137
accessforbidden
accessforbidden($message='', $printheader=1, $printfooter=1, $showonlymessage=0, $params=null)
Show a message to say access is forbidden and stop program Calling this function terminate execution ...
Definition: security.lib.php:933