dolibarr  13.0.2
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) accessforbidden();
35 
36 $conf->dol_hide_leftmenu = 1; // Force hide of left menu.
37 
38 $error = 0;
39 $website = GETPOST('website', 'alpha');
40 $page = GETPOST('page', 'alpha');
41 $pageid = GETPOST('pageid', 'int');
42 $action = GETPOST('action', 'aZ09');
43 
44 if (GETPOST('delete')) { $action = 'delete'; }
45 if (GETPOST('preview')) $action = 'preview';
46 if (GETPOST('create')) { $action = 'create'; }
47 if (GETPOST('editmedia')) { $action = 'editmedia'; }
48 if (GETPOST('editcss')) { $action = 'editcss'; }
49 if (GETPOST('editmenu')) { $action = 'editmenu'; }
50 if (GETPOST('setashome')) { $action = 'setashome'; }
51 if (GETPOST('editmeta')) { $action = 'editmeta'; }
52 if (GETPOST('editcontent')) { $action = 'editcontent'; }
53 
54 if (empty($action)) $action = 'preview';
55 
56 
57 
58 
59 /*
60  * Actions
61  */
62 
63 if (GETPOST('refreshsite')) $pageid = 0; // If we change the site, we reset the pageid.
64 if (GETPOST('refreshpage')) $action = 'preview';
65 
66 
67 // Add a collab page
68 if ($action == 'add')
69 {
70  $db->begin();
71 
72  $objectpage->title = GETPOST('WEBSITE_TITLE');
73  $objectpage->pageurl = GETPOST('WEBSITE_PAGENAME');
74  $objectpage->description = GETPOST('WEBSITE_DESCRIPTION');
75  $objectpage->keywords = GETPOST('WEBSITE_KEYWORD');
76 
77  if (empty($objectpage->title))
78  {
79  setEventMessages($langs->trans("ErrorFieldRequired", $langs->transnoentitiesnoconv("WEBSITE_PAGENAME")), null, 'errors');
80  $error++;
81  }
82 
83  if (!$error)
84  {
85  $res = $objectpage->create($user);
86  if ($res <= 0)
87  {
88  $error++;
89  setEventMessages($objectpage->error, $objectpage->errors, 'errors');
90  }
91  }
92  if (!$error)
93  {
94  $db->commit();
95  setEventMessages($langs->trans("PageAdded", $objectpage->pageurl), null, 'mesgs');
96  $action = '';
97  } else {
98  $db->rollback();
99  }
100 
101  $action = 'preview';
102  $id = $objectpage->id;
103 }
104 
105 // Update page
106 if ($action == 'delete')
107 {
108  $db->begin();
109 
110  $res = $object->fetch(0, $website);
111 
112  $res = $objectpage->fetch($pageid, $object->fk_website);
113 
114  if ($res > 0)
115  {
116  $res = $objectpage->delete($user);
117  if (!($res > 0))
118  {
119  $error++;
120  setEventMessages($objectpage->error, $objectpage->errors, 'errors');
121  }
122 
123  if (!$error)
124  {
125  $db->commit();
126  setEventMessages($langs->trans("PageDeleted", $objectpage->pageurl, $website), null, 'mesgs');
127 
128  header("Location: ".$_SERVER["PHP_SELF"].'?website='.$website);
129  exit;
130  } else {
131  $db->rollback();
132  }
133  } else {
134  dol_print_error($db);
135  }
136 }
137 
138 
139 
140 /*
141  * View
142  */
143 
144 $form = new Form($db);
145 
146 $help_url = '';
147 
148 llxHeader('', $langs->trans("WebsiteSetup"), $help_url, '', 0, '', '', '', '', '', '<!-- Begin div class="fiche" -->'."\n".'<div class="fichebutwithotherclass">');
149 
150 print "\n".'<form action="'.$_SERVER["PHP_SELF"].'" method="POST"><div>';
151 print '<input type="hidden" name="token" value="'.newToken().'">';
152 if ($action == 'create')
153 {
154  print '<input type="hidden" name="action" value="add">';
155 }
156 
157 
158 // Add a margin under toolbar ?
159 $style = '';
160 if ($action != 'preview' && $action != 'editcontent') $style = ' margin-bottom: 5px;';
161 
162 //var_dump($objectpage);exit;
163 print '<div class="centpercent websitebar">';
164 
165 
166 
167 
168 print "</div>\n</form>\n";
169 
170 // End of page
171 llxFooter();
172 $db->close();
GETPOST($paramname, $check= 'alphanohtml', $method=0, $filter=null, $options=null, $noreplace=0)
Return value of a param into GET or POST supervariable.
llxHeader()
Empty header.
Definition: wrapper.php:45
setEventMessages($mesg, $mesgs, $style= 'mesgs', $messagekey= '')
Set event messages in dol_events session object.
Class to manage generation of HTML components Only common components must be here.
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 ...
print $_SERVER["PHP_SELF"]
Edit parameters.
print
Draft customers invoices.
Definition: index.php:89
dol_print_error($db= '', $error= '', $errors=null)
Displays error message system with all the information to facilitate the diagnosis and the escalation...
llxFooter()
Empty footer.
Definition: wrapper.php:59