website.inc.php 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293
  1. <?php
  2. /* Copyright (C) 2017-2018 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. * or see http://www.gnu.org/
  17. */
  18. /**
  19. * \file htdocs/core/website.inc.php
  20. * \brief Common file loaded by all website pages (after master.inc.php). It set the new object $weblangs, using parameter 'l'.
  21. * This file is included in top of all container pages.
  22. * The global variable $websitekey must be defined.
  23. */
  24. // Load website class
  25. include_once DOL_DOCUMENT_ROOT.'/website/class/website.class.php';
  26. // Define $website
  27. if (! is_object($website))
  28. {
  29. $website=new Website($db);
  30. $website->fetch(0,$websitekey);
  31. }
  32. // Define $weblangs
  33. if (! is_object($weblangs))
  34. {
  35. $weblangs = dol_clone($langs); // TODO Use an object lang from a language set into $website object instead of backoffice
  36. }
  37. // Define $websitepage if we have $websitepagefile defined
  38. if (! $pageid && ! empty($websitepagefile))
  39. {
  40. $pageid = str_replace(array('.tpl.php', 'page'), array('', ''), basename($websitepagefile));
  41. }
  42. if ($pageid > 0)
  43. {
  44. include_once DOL_DOCUMENT_ROOT.'/website/class/websitepage.class.php';
  45. $websitepage=new WebsitePage($db);
  46. $websitepage->fetch($pageid);
  47. }
  48. // A lang was forced, so we change weblangs init
  49. if (GETPOST('l','aZ09')) $weblangs->setDefaultLang(GETPOST('l','aZ09'));
  50. // A lang was forced, so we check to find if we must make a redirect on translation page
  51. if ($_SERVER['PHP_SELF'] != DOL_URL_ROOT.'/website/index.php') // If we browsing page using Dolibarr server or a Native web server
  52. {
  53. //print_r(get_defined_constants(true));exit;
  54. if (GETPOST('l','aZ09'))
  55. {
  56. $sql ="SELECT wp.rowid, wp.lang, wp.pageurl, wp.fk_page";
  57. $sql.=" FROM ".MAIN_DB_PREFIX."website_page as wp";
  58. $sql.=" WHERE wp.fk_website = ".$website->id;
  59. $sql.=" AND (wp.fk_page = ".$pageid." OR wp.rowid = ".$pageid;
  60. if (is_object($websitepage) && $websitepage->fk_page > 0) $sql.=" OR wp.fk_page = ".$websitepage->fk_page." OR wp.rowid = ".$websitepage->fk_page;
  61. $sql.=")";
  62. $sql.= " AND wp.lang = '".$db->escape(GETPOST('l','aZ09'))."'";
  63. $resql = $db->query($sql);
  64. if ($resql)
  65. {
  66. $obj = $db->fetch_object($resql);
  67. if ($obj)
  68. {
  69. $newpageid = $obj->rowid;
  70. if ($newpageid != $pageid) // To avoid to make a redirect on same page (infinite loop)
  71. {
  72. if (defined('USEDOLIBARRSERVER')) {
  73. header("Location: ".DOL_URL_ROOT.'/public/website/index.php?website='.$websitekey.'&pageid='.$newpageid.'&l='.GETPOST('l','aZ09'));
  74. exit;
  75. }
  76. else
  77. {
  78. $newpageref = $obj->pageurl;
  79. header("Location: ".$newpageref.'.php?l='.GETPOST('l','aZ09'));
  80. exit;
  81. }
  82. }
  83. }
  84. }
  85. }
  86. }
  87. // Load websitepage class
  88. include_once DOL_DOCUMENT_ROOT.'/website/class/websitepage.class.php';