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