dolibarr  9.0.0
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 <http://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 if (! ((GETPOST('testmenuhider','int') || ! empty($conf->global->MAIN_TESTMENUHIDER)) && empty($conf->global->MAIN_OPTIMIZEFORTEXTBROWSER)))
37 {
38  $conf->dol_hide_leftmenu = 1; // Force hide of left menu.
39 }
40 
41 $error=0;
42 $website=GETPOST('website', 'alpha');
43 $page=GETPOST('page', 'alpha');
44 $pageid=GETPOST('pageid', 'int');
45 $action=GETPOST('action','alpha');
46 
47 if (GETPOST('delete')) { $action='delete'; }
48 if (GETPOST('preview')) $action='preview';
49 if (GETPOST('create')) { $action='create'; }
50 if (GETPOST('editmedia')) { $action='editmedia'; }
51 if (GETPOST('editcss')) { $action='editcss'; }
52 if (GETPOST('editmenu')) { $action='editmenu'; }
53 if (GETPOST('setashome')) { $action='setashome'; }
54 if (GETPOST('editmeta')) { $action='editmeta'; }
55 if (GETPOST('editcontent')) { $action='editcontent'; }
56 
57 if (empty($action)) $action='preview';
58 
59 
60 
61 
62 /*
63  * Actions
64  */
65 
66 if (GETPOST('refreshsite')) $pageid=0; // If we change the site, we reset the pageid.
67 if (GETPOST('refreshpage')) $action='preview';
68 
69 
70 // Add a collab page
71 if ($action == 'add')
72 {
73  $db->begin();
74 
75  $objectpage->title = GETPOST('WEBSITE_TITLE');
76  $objectpage->pageurl = GETPOST('WEBSITE_PAGENAME');
77  $objectpage->description = GETPOST('WEBSITE_DESCRIPTION');
78  $objectpage->keywords = GETPOST('WEBSITE_KEYWORD');
79 
80  if (empty($objectpage->title))
81  {
82  setEventMessages($langs->trans("ErrorFieldRequired", $langs->transnoentitiesnoconv("WEBSITE_PAGENAME")), null, 'errors');
83  $error++;
84  }
85 
86  if (! $error)
87  {
88  $res = $objectpage->create($user);
89  if ($res <= 0)
90  {
91  $error++;
92  setEventMessages($objectpage->error, $objectpage->errors, 'errors');
93  }
94  }
95  if (! $error)
96  {
97  $db->commit();
98  setEventMessages($langs->trans("PageAdded", $objectpage->pageurl), null, 'mesgs');
99  $action='';
100  }
101  else
102  {
103  $db->rollback();
104  }
105 
106  $action = 'preview';
107  $id = $objectpage->id;
108 }
109 
110 // Update page
111 if ($action == 'delete')
112 {
113  $db->begin();
114 
115  $res = $object->fetch(0, $website);
116 
117  $res = $objectpage->fetch($pageid, $object->fk_website);
118 
119  if ($res > 0)
120  {
121  $res = $objectpage->delete($user);
122  if (! $res > 0)
123  {
124  $error++;
125  setEventMessages($objectpage->error, $objectpage->errors, 'errors');
126  }
127 
128  if (! $error)
129  {
130  $db->commit();
131  setEventMessages($langs->trans("PageDeleted", $objectpage->pageurl, $website), null, 'mesgs');
132 
133  header("Location: ".$_SERVER["PHP_SELF"].'?website='.$website);
134  exit;
135  }
136  else
137  {
138  $db->rollback();
139  }
140  }
141  else
142  {
143  dol_print_error($db);
144  }
145 }
146 
147 
148 
149 /*
150  * View
151  */
152 
153 $form = new Form($db);
154 
155 $help_url='';
156 
157 llxHeader('', $langs->trans("WebsiteSetup"), $help_url, '', 0, '', '', '', '', '', '<!-- Begin div class="fiche" -->'."\n".'<div class="fichebutwithotherclass">');
158 
159 print "\n".'<form action="'.$_SERVER["PHP_SELF"].'" method="POST"><div>';
160 print '<input type="hidden" name="token" value="'.$_SESSION['newtoken'].'">';
161 if ($action == 'create')
162 {
163  print '<input type="hidden" name="action" value="add">';
164 }
165 
166 
167 // Add a margin under toolbar ?
168 $style='';
169 if ($action != 'preview' && $action != 'editcontent') $style=' margin-bottom: 5px;';
170 
171 //var_dump($objectpage);exit;
172 print '<div class="centpercent websitebar">';
173 
174 if (count($object->records) > 0)
175 {
176  // ***** Part for web sites
177 
178  print '<div class="websiteselection hideonsmartphoneimp">';
179  print $langs->trans("WebSite").': ';
180  print '</div>';
181 
182  // List of websites
183  print '<div class="websiteselection">';
184  $out='';
185  $out.='<select name="website" class="minwidth100" id="website">';
186  if (empty($object->records)) $out.='<option value="-1">&nbsp;</option>';
187  // Loop on each sites
188  $i=0;
189  foreach($object->records as $key => $valwebsite)
190  {
191  if (empty($website)) $website=$valwebsite->ref;
192 
193  $out.='<option value="'.$valwebsite->ref.'"';
194  if ($website == $valwebsite->ref) $out.=' selected'; // To preselect a value
195  $out.='>';
196  $out.=$valwebsite->ref;
197  $out.='</option>';
198  $i++;
199  }
200  $out.='</select>';
201  $out.=ajax_combobox('website');
202  print $out;
203  print '<input type="submit" class="button" name="refreshsite" value="'.$langs->trans("Load").'">';
204 
205  if ($website)
206  {
207  $virtualurl='';
208  $dataroot=DOL_DATA_ROOT.'/collab/'.$website;
209  if (! empty($object->virtualhost)) $virtualurl=$object->virtualhost;
210  }
211 
212  if ($website && $action == 'preview')
213  {
214  $disabled='';
215  if (empty($user->rights->websites->write)) $disabled=' disabled="disabled"';
216 
217  print ' &nbsp; ';
218 
219  //print '<input type="submit" class="button"'.$disabled.' value="'.dol_escape_htmltag($langs->trans("MediaFiles")).'" name="editmedia">';
220  print '<input type="submit" class="button"'.$disabled.' value="'.dol_escape_htmltag($langs->trans("EditCss")).'" name="editcss">';
221  print '<input type="submit" class="button"'.$disabled.' value="'.dol_escape_htmltag($langs->trans("EditMenu")).'" name="editmenu">';
222  print '<input type="submit"'.$disabled.' class="button" value="'.dol_escape_htmltag($langs->trans("AddPage")).'" name="create">';
223  }
224 
225  print '</div>';
226 
227  // Button for websites
228  print '<div class="websitetools">';
229 
230  if ($action == 'preview')
231  {
232  print '<div class="websiteinputurl">';
233  print '<input type="text" id="previewsiteurl" class="minwidth200imp" name="previewsite" placeholder="'.$langs->trans("http://myvirtualhost").'" value="'.$virtualurl.'">';
234  //print '<input type="submit" class="button" name="previewwebsite" target="tab'.$website.'" value="'.$langs->trans("ViewSiteInNewTab").'">';
235  $htmltext=$langs->trans("SetHereVirtualHost", $dataroot);
236  print $form->textwithpicto('', $htmltext);
237  print '</div>';
238 
239  $urlext=$virtualurl;
240  $urlint=$urlwithroot.'/public/collab/index.php?website='.$website;
241  //if (! empty($object->virtualhost))
242  //{
243  print '<a class="websitebuttonsitepreview" id="previewsiteext" href="'.$urlext.'" target="tab'.$website.'" alt="'.dol_escape_htmltag($langs->trans("PreviewSiteServedByWebServer", $langs->transnoentitiesnoconv("Site"), $langs->transnoentitiesnoconv("Site"), $dataroot, $urlext)).'">';
244  print $form->textwithpicto('', $langs->trans("PreviewSiteServedByWebServer", $langs->transnoentitiesnoconv("Site"), $langs->transnoentitiesnoconv("Site"), $dataroot, $urlext?$urlext:$langs->trans("VirtualHostUrlNotDefined")), 1, 'preview_ext');
245  print '</a>';
246  //}
247 
248  print '<a class="websitebuttonsitepreview" id="previewsite" href="'.$urlwithroot.'/public/collab/index.php?website='.$website.'" target="tab'.$website.'" alt="'.dol_escape_htmltag($langs->trans("PreviewSiteServedByDolibarr", $langs->transnoentitiesnoconv("Site"), $langs->transnoentitiesnoconv("Site"), $urlint)).'">';
249  print $form->textwithpicto('', $langs->trans("PreviewSiteServedByDolibarr", $langs->transnoentitiesnoconv("Site"), $langs->transnoentitiesnoconv("Site"), $urlint, $dataroot), 1, 'preview');
250  print '</a>';
251  }
252 
253  if (in_array($action, array('editcss','editmenu','create')))
254  {
255  if ($action != 'preview') print '<input type="submit" class="button" value="'.dol_escape_htmltag($langs->trans("Cancel")).'" name="preview">';
256  if (preg_match('/^create/',$action)) print '<input type="submit" class="button" value="'.dol_escape_htmltag($langs->trans("Save")).'" name="update">';
257  if (preg_match('/^edit/',$action)) print '<input type="submit" class="button" value="'.dol_escape_htmltag($langs->trans("Save")).'" name="update">';
258  }
259 
260  print '</div>';
261 
262 
263  // ***** Part for pages
264 
265  if ($website)
266  {
267  print '</div>';
268 
269  $array=$objectpage->fetchAll($object->id);
270  if (! is_array($array) && $array < 0) dol_print_error('', $objectpage->error, $objectpage->errors);
271  $atleastonepage=(is_array($array) && count($array) > 0);
272 
273  print '<div class="centpercent websitebar"'.($style?' style="'.$style.'"':'').'">';
274  print '<div class="websiteselection hideonsmartphoneimp">';
275  print $langs->trans("Page").': ';
276  print '</div>';
277  print '<div class="websiteselection">';
278 
279  if ($action != 'add')
280  {
281  $out='';
282  $out.='<select name="pageid" id="pageid" class="minwidth200">';
283  if ($atleastonepage)
284  {
285  if (empty($pageid) && $action != 'create') // Page id is not defined, we try to take one
286  {
287  $firstpageid=0;$homepageid=0;
288  foreach($array as $key => $valpage)
289  {
290  if (empty($firstpageid)) $firstpageid=$valpage->id;
291  if ($object->fk_default_home && $key == $object->fk_default_home) $homepageid=$valpage->id;
292  }
293  $pageid=$homepageid?$homepageid:$firstpageid; // We choose home page and if not defined yet, we take first page
294  }
295 
296  foreach($array as $key => $valpage)
297  {
298  $out.='<option value="'.$key.'"';
299  if ($pageid > 0 && $pageid == $key) $out.=' selected'; // To preselect a value
300  $out.='>';
301  $out.=$valpage->title;
302  if ($object->fk_default_home && $key == $object->fk_default_home) $out.=' ('.$langs->trans("HomePage").')';
303  $out.='</option>';
304  }
305  }
306  else $out.='<option value="-1">&nbsp;</option>';
307  $out.='</select>';
308  $out.=ajax_combobox('pageid');
309  print $out;
310  }
311  else
312  {
313  print $langs->trans("New");
314  }
315 
316  print '<input type="submit" class="button" name="refreshpage" value="'.$langs->trans("Load").'"'.($atleastonepage?'':' disabled="disabled"').'>';
317  //print $form->selectarray('page', $array);
318 
319  if ($action == 'preview')
320  {
321  $disabled='';
322  if (empty($user->rights->websites->write)) $disabled=' disabled="disabled"';
323 
324  if ($pageid > 0)
325  {
326  print ' &nbsp; ';
327 
328  if ($object->fk_default_home > 0 && $pageid == $object->fk_default_home) print '<input type="submit" class="button" disabled="disabled" value="'.dol_escape_htmltag($langs->trans("SetAsHomePage")).'" name="setashome">';
329  else print '<input type="submit" class="button"'.$disabled.' value="'.dol_escape_htmltag($langs->trans("SetAsHomePage")).'" name="setashome">';
330  print '<input type="submit" class="button"'.$disabled.' value="'.dol_escape_htmltag($langs->trans("EditPageMeta")).'" name="editmeta">';
331  print '<input type="submit" class="button"'.$disabled.' value="'.dol_escape_htmltag($langs->trans("EditPageContent")).'" name="editcontent">';
332  //print '<a href="'.$_SERVER["PHP_SELF"].'?action=editmeta&website='.urlencode($website).'&pageid='.urlencode($pageid).'" class="button">'.dol_escape_htmltag($langs->trans("EditPageMeta")).'</a>';
333  //print '<a href="'.$_SERVER["PHP_SELF"].'?action=editcontent&website='.urlencode($website).'&pageid='.urlencode($pageid).'" class="button">'.dol_escape_htmltag($langs->trans("EditPageContent")).'</a>';
334  print '<input type="submit" class="buttonDelete" name="delete" value="'.$langs->trans("Delete").'"'.($atleastonepage?'':' disabled="disabled"').'>';
335  }
336  }
337 
338  print '</div>';
339  print '<div class="websiteselection">';
340  print '</div>';
341 
342  print '<div class="websitetools">';
343 
344  if ($website && $pageid > 0 && $action == 'preview')
345  {
346  $websitepage = new WebSitePage($db);
347  $websitepage->fetch($pageid);
348 
349  $realpage=$urlwithroot.'/public/collab/index.php?website='.$website.'&page='.$pageid;
350  $pagealias = $websitepage->pageurl;
351 
352  print '<div class="websiteinputurl">';
353  print '<input type="text" id="previewpageurl" class="minwidth200imp" name="previewsite" value="'.$pagealias.'" disabled="disabled">';
354  //print '<input type="submit" class="button" name="previewwebsite" target="tab'.$website.'" value="'.$langs->trans("ViewSiteInNewTab").'">';
355  $htmltext=$langs->trans("WEBSITE_PAGENAME", $pagealias);
356  print $form->textwithpicto('', $htmltext);
357  print '</div>';
358 
359  if (! empty($object->virtualhost))
360  {
361  $urlext=$virtualurl.'/'.$pagealias.'.php';
362  print '<a class="websitebuttonsitepreview" id="previewpageext" href="'.$urlext.'" target="tab'.$website.'" alt="'.dol_escape_htmltag($langs->trans("PreviewSiteServedByWebServer", $langs->transnoentitiesnoconv("Page"), $langs->transnoentitiesnoconv("Page"), $dataroot, $urlext)).'">';
363  print $form->textwithpicto('', $langs->trans("PreviewSiteServedByWebServer", $langs->transnoentitiesnoconv("Page"), $langs->transnoentitiesnoconv("Page"), $dataroot, $urlext?$urlext:$langs->trans("VirtualHostUrlNotDefined")), 1, 'preview_ext');
364  print '</a>';
365  }
366  else
367  {
368  print '<a class="websitebuttonsitepreview" id="previewpageextnoclick" href="#">';
369  print $form->textwithpicto('', $langs->trans("PreviewSiteServedByWebServer", $langs->transnoentitiesnoconv("Page"), $langs->transnoentitiesnoconv("Page"), $dataroot, $urlext?$urlext:$langs->trans("VirtualHostUrlNotDefined")), 1, 'preview_ext');
370  print '</a>';
371  }
372 
373  print '<a class="websitebuttonsitepreview" id="previewpage" href="'.$realpage.'&nocache='.dol_now().'" class="button" target="tab'.$website.'" alt="'.dol_escape_htmltag($langs->trans("PreviewSiteServedByDolibarr", $langs->transnoentitiesnoconv("Page"), $langs->transnoentitiesnoconv("Page"), $realpage)).'">';
374  print $form->textwithpicto('', $langs->trans("PreviewSiteServedByDolibarr", $langs->transnoentitiesnoconv("Page"), $langs->transnoentitiesnoconv("Page"), $realpage, $dataroot), 1, 'preview');
375  print '</a>'; // View page in new Tab
376  //print '<input type="submit" class="button" name="previewpage" target="tab'.$website.'"value="'.$langs->trans("ViewPageInNewTab").'">';
377 
378  // TODO Add js to save alias like we save virtual host name and use dynamic virtual host for url of id=previewpageext
379  }
380  if (! in_array($action, array('editcss','editmenu','create')))
381  {
382  if ($action != 'preview') print '<input type="submit" class="button" value="'.dol_escape_htmltag($langs->trans("Cancel")).'" name="preview">';
383  if (preg_match('/^create/',$action)) print '<input type="submit" class="button" value="'.dol_escape_htmltag($langs->trans("Save")).'" name="update">';
384  if (preg_match('/^edit/',$action)) print '<input type="submit" class="button" value="'.dol_escape_htmltag($langs->trans("Save")).'" name="update">';
385  }
386 
387  print '</div>';
388 
389  if ($action == 'preview')
390  {
391  // Adding jquery code to change on the fly url of preview ext
392  if (! empty($conf->use_javascript_ajax))
393  {
394  print '<script type="text/javascript" language="javascript">
395  jQuery(document).ready(function() {
396  jQuery("#previewsiteext,#previewpageext").click(function() {
397  newurl=jQuery("#previewsiteurl").val();
398  newpage=jQuery("#previewsiteurl").val() + "/" + jQuery("#previewpageurl").val() + ".php";
399  console.log("Open url "+newurl);
400  /* Save url */
401  jQuery.ajax({
402  method: "POST",
403  url: "'.DOL_URL_ROOT.'/core/ajax/saveinplace.php",
404  data: {
405  field: \'editval_virtualhost\',
406  element: \'websites\',
407  table_element: \'website\',
408  fk_element: '.$object->id.',
409  value: newurl,
410  },
411  context: document.body
412  });
413 
414  jQuery("#previewsiteext").attr("href",newurl);
415  jQuery("#previewpageext").attr("href",newpage);
416  });
417  });
418  </script>';
419  }
420  }
421  }
422 }
423 else
424 {
425  print '<div class="websiteselection">';
426  $langs->load("errors");
427  print $langs->trans("ErrorModuleSetupNotComplete");
428  print '<div>';
429  $action='';
430 }
431 
432 
433 print '</div>';
434 
435 $head = array();
436 
437 if ($action == 'editcontent')
438 {
439  /*
440  * Editing global variables not related to a specific theme
441  */
442 
443  $csscontent = @file_get_contents($filecss);
444 
445  $contentforedit = '';
446  /*$contentforedit.='<style scoped>'."\n"; // "scoped" means "apply to parent element only". Not yet supported by browsers
447  $contentforedit.=$csscontent;
448  $contentforedit.='</style>'."\n";*/
449  $contentforedit .= $objectpage->content;
450 
451  require_once DOL_DOCUMENT_ROOT.'/core/class/doleditor.class.php';
452  $doleditor=new DolEditor('PAGE_CONTENT',$contentforedit,'',500,'Full','',true,true,true,ROWS_5,'90%');
453  $doleditor->Create(0, '', false);
454 }
455 
456 print "</div>\n</form>\n";
457 
458 // End of page
459 llxFooter();
460 $db->close();
llxFooter()
Footer empty.
Definition: index.php:44
ajax_combobox($htmlname, $events=array(), $minLengthToAutocomplete=0, $forcefocus=0, $widthTypeOfAutocomplete='resolve')
Convert a html select field into an ajax combobox.
Definition: ajax.lib.php:374
GETPOST($paramname, $check='none', $method=0, $filter=null, $options=null, $noreplace=0)
Return value of a param into GET or POST supervariable.
print
Draft customers invoices.
Definition: index.php:91
setEventMessages($mesg, $mesgs, $style='mesgs')
Set event messages in dol_events session object.
dol_print_error($db='', $error='', $errors=null)
Affiche message erreur system avec toutes les informations pour faciliter le diagnostic et la remonte...
dol_escape_htmltag($stringtoescape, $keepb=0, $keepn=0)
Returns text escaped for inclusion in HTML alt or title tags, or into values of HTML input fields...
accessforbidden($message='', $printheader=1, $printfooter=1, $showonlymessage=0)
Show a message to say access is forbidden and stop program Calling this function terminate execution ...
Class to manage generation of HTML components Only common components must be here.
llxHeader()
Header empty.
Definition: index.php:36
dol_now($mode='gmt')
Return date for now.
Class to manage a WYSIWYG editor.