dolibarr  13.0.2
website.inc.php
Go to the documentation of this file.
1 <?php
2 /* Copyright (C) 2017-2019 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 * or see https://www.gnu.org/
17 */
18 
26 // Load website class
27 include_once DOL_DOCUMENT_ROOT.'/website/class/website.class.php';
28 include_once DOL_DOCUMENT_ROOT.'/website/class/websitepage.class.php';
29 
30 // Detection browser (copy of code from main.inc.php)
31 if (isset($_SERVER["HTTP_USER_AGENT"]) && is_object($conf) && empty($conf->browser->name))
32 {
33  $tmp = getBrowserInfo($_SERVER["HTTP_USER_AGENT"]);
34  $conf->browser->name = $tmp['browsername'];
35  $conf->browser->os = $tmp['browseros'];
36  $conf->browser->version = $tmp['browserversion'];
37  $conf->browser->layout = $tmp['layout']; // 'classic', 'phone', 'tablet'
38  //var_dump($conf->browser);
39 
40  if ($conf->browser->layout == 'phone') $conf->dol_no_mouse_hover = 1;
41 }
42 // Define $website
43 if (!is_object($website))
44 {
45  $website = new Website($db);
46  $website->fetch(0, $websitekey);
47 }
48 // Define $websitepage if we have $websitepagefile defined
49 if (!$pageid && !empty($websitepagefile))
50 {
51  $pageid = str_replace(array('.tpl.php', 'page'), array('', ''), basename($websitepagefile));
52  if ($pageid == 'index.php') $pageid = $website->fk_default_home;
53 }
54 if (!is_object($websitepage))
55 {
56  $websitepage = new WebsitePage($db);
57 }
58 // Define $weblangs
59 if (!is_object($weblangs))
60 {
61  $weblangs = new Translate('', $conf);
62 }
63 if (!is_object($pagelangs))
64 {
65  $pagelangs = new Translate('', $conf);
66 }
67 if ($pageid > 0)
68 {
69  $websitepage->fetch($pageid);
70 
71  $weblangs->setDefaultLang(GETPOSTISSET('lang') ? GETPOST('lang', 'aZ09') : (empty($_COOKIE['weblangs-shortcode']) ? 'auto' : preg_replace('/[^a-zA-Z0-9_\-]/', '', $_COOKIE['weblangs-shortcode'])));
72  $pagelangs->setDefaultLang($websitepage->lang ? $websitepage->lang : $weblangs->shortlang);
73 
74  if (!defined('USEDOLIBARREDITOR') && (in_array($websitepage->type_container, array('menu', 'other')) || empty($websitepage->status)))
75  {
76  $weblangs->load("website");
77  http_response_code(404);
78  print '<center><br><br>'.$weblangs->trans("YouTryToAccessToAFileThatIsNotAWebsitePage", $websitepage->pageurl, $websitepage->type_container, $websitepage->status).'</center>';
79  exit;
80  }
81 }
82 
83 if (!defined('USEDOLIBARRSERVER') && !defined('USEDOLIBARREDITOR')) {
84  header("X-Content-Type-Options: nosniff");
85  if (empty($websitepage->allowed_in_frames) && empty($conf->global->WEBSITE_ALLOW_FRAMES_ON_ALL_PAGES)) {
86  header("X-Frame-Options: SAMEORIGIN");
87  }
88 }
89 
90 // A lang was forced, so we change weblangs init
91 if (GETPOST('l', 'aZ09')) $weblangs->setDefaultLang(GETPOST('l', 'aZ09'));
92 // A lang was forced, so we check to find if we must make a redirect on translation page
93 if ($_SERVER['PHP_SELF'] != DOL_URL_ROOT.'/website/index.php') // If we browsing page using Dolibarr server or a Native web server
94 {
95  //print_r(get_defined_constants(true));exit;
96  if (GETPOST('l', 'aZ09'))
97  {
98  $sql = "SELECT wp.rowid, wp.lang, wp.pageurl, wp.fk_page";
99  $sql .= " FROM ".MAIN_DB_PREFIX."website_page as wp";
100  $sql .= " WHERE wp.fk_website = ".$website->id;
101  $sql .= " AND (wp.fk_page = ".$pageid." OR wp.rowid = ".$pageid;
102  if (is_object($websitepage) && $websitepage->fk_page > 0) $sql .= " OR wp.fk_page = ".$websitepage->fk_page." OR wp.rowid = ".$websitepage->fk_page;
103  $sql .= ")";
104  $sql .= " AND wp.lang = '".$db->escape(GETPOST('l', 'aZ09'))."'";
105 
106  $resql = $db->query($sql);
107  if ($resql)
108  {
109  $obj = $db->fetch_object($resql);
110  if ($obj)
111  {
112  $newpageid = $obj->rowid;
113  if ($newpageid != $pageid) // To avoid to make a redirect on same page (infinite loop)
114  {
115  if (defined('USEDOLIBARRSERVER')) {
116  header("Location: ".DOL_URL_ROOT.'/public/website/index.php?website='.$websitekey.'&pageid='.$newpageid.'&l='.GETPOST('l', 'aZ09'));
117  exit;
118  } else {
119  $newpageref = $obj->pageurl;
120  header("Location: ".(($obj->lang && $obj->lang != $website->lang) ? '/'.$obj->lang.'/' : '/').$newpageref.'.php?l='.GETPOST('l', 'aZ09'));
121  exit;
122  }
123  }
124  }
125  }
126  }
127 }
128 
129 // Show off line message
130 if (!defined('USEDOLIBARREDITOR') && empty($website->status))
131 {
132  $weblangs->load("website");
133  http_response_code(503);
134  print '<center><br><br>'.$weblangs->trans("SorryWebsiteIsCurrentlyOffLine").'</center>';
135  exit;
136 }
GETPOST($paramname, $check= 'alphanohtml', $method=0, $filter=null, $options=null, $noreplace=0)
Return value of a param into GET or POST supervariable.
Class Website.
Class Websitepage.
GETPOSTISSET($paramname)
Return true if we are in a context of submitting the parameter $paramname.
getBrowserInfo($user_agent)
Return information about user browser.
Class to manage translations.
print $_SERVER["PHP_SELF"]
Edit parameters.
print
Draft customers invoices.
Definition: index.php:89
if(!empty($conf->facture->enabled)&&$user->rights->facture->lire) if((!empty($conf->fournisseur->enabled)&&empty($conf->global->MAIN_USE_NEW_SUPPLIERMOD)||!empty($conf->supplier_invoice->enabled))&&$user->rights->fournisseur->facture->lire) if(!empty($conf->don->enabled)&&$user->rights->don->lire) if(!empty($conf->tax->enabled)&&$user->rights->tax->charges->lire) if(!empty($conf->facture->enabled)&&!empty($conf->commande->enabled)&&$user->rights->commande->lire &&empty($conf->global->WORKFLOW_DISABLE_CREATE_INVOICE_FROM_ORDER)) if(!empty($conf->facture->enabled)&&$user->rights->facture->lire) if((!empty($conf->fournisseur->enabled)&&empty($conf->global->MAIN_USE_NEW_SUPPLIERMOD)||!empty($conf->supplier_invoice->enabled))&&$user->rights->fournisseur->facture->lire) $resql
Social contributions to pay.
Definition: index.php:1232