PageRenderTime 51ms CodeModel.GetById 22ms RepoModel.GetById 1ms app.codeStats 0ms

/admin-dev/functions.php

https://github.com/netplayer/PrestaShop
PHP | 573 lines | 401 code | 44 blank | 128 comment | 113 complexity | f075c2979a9aeb655a24a25bdd68b75b MD5 | raw file
Possible License(s): CC-BY-SA-3.0, LGPL-2.1, LGPL-3.0
  1. <?php
  2. /*
  3. * 2007-2014 PrestaShop
  4. *
  5. * NOTICE OF LICENSE
  6. *
  7. * This source file is subject to the Open Software License (OSL 3.0)
  8. * that is bundled with this package in the file LICENSE.txt.
  9. * It is also available through the world-wide-web at this URL:
  10. * http://opensource.org/licenses/osl-3.0.php
  11. * If you did not receive a copy of the license and are unable to
  12. * obtain it through the world-wide-web, please send an email
  13. * to license@prestashop.com so we can send you a copy immediately.
  14. *
  15. * DISCLAIMER
  16. *
  17. * Do not edit or add to this file if you wish to upgrade PrestaShop to newer
  18. * versions in the future. If you wish to customize PrestaShop for your
  19. * needs please refer to http://www.prestashop.com for more information.
  20. *
  21. * @author PrestaShop SA <contact@prestashop.com>
  22. * @copyright 2007-2014 PrestaShop SA
  23. * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
  24. * International Registered Trademark & Property of PrestaShop SA
  25. */
  26. if (!defined('_PS_ADMIN_DIR_'))
  27. define('_PS_ADMIN_DIR_', getcwd());
  28. require_once(_PS_ADMIN_DIR_.'/../images.inc.php');
  29. function bindDatepicker($id, $time)
  30. {
  31. if ($time)
  32. echo '
  33. var dateObj = new Date();
  34. var hours = dateObj.getHours();
  35. var mins = dateObj.getMinutes();
  36. var secs = dateObj.getSeconds();
  37. if (hours < 10) { hours = "0" + hours; }
  38. if (mins < 10) { mins = "0" + mins; }
  39. if (secs < 10) { secs = "0" + secs; }
  40. var time = " "+hours+":"+mins+":"+secs;';
  41. echo '
  42. $(function() {
  43. $("#'.Tools::htmlentitiesUTF8($id).'").datepicker({
  44. prevText:"",
  45. nextText:"",
  46. dateFormat:"yy-mm-dd"'.($time ? '+time' : '').'});
  47. });';
  48. }
  49. /**
  50. * Deprecated since 1.5
  51. * Use Controller::addJqueryUi('ui.datepicker') instead
  52. *
  53. * @param int|array $id id can be a identifier or an array of identifiers
  54. * @param unknown_type $time
  55. */
  56. function includeDatepicker($id, $time = false)
  57. {
  58. Tools::displayAsDeprecated();
  59. echo '<script type="text/javascript" src="'.__PS_BASE_URI__.'js/jquery/ui/jquery.ui.core.min.js"></script>';
  60. echo '<link type="text/css" rel="stylesheet" href="'.__PS_BASE_URI__.'js/jquery/ui/themes/ui-lightness/jquery.ui.theme.css" />';
  61. echo '<link type="text/css" rel="stylesheet" href="'.__PS_BASE_URI__.'js/jquery/ui/themes/ui-lightness/jquery.ui.datepicker.css" />';
  62. $iso = Db::getInstance()->getValue('SELECT iso_code FROM '._DB_PREFIX_.'lang WHERE `id_lang` = '.(int)Context::getContext()->language->id);
  63. if ($iso != 'en')
  64. echo '<script type="text/javascript" src="'.__PS_BASE_URI__.'js/jquery/ui/i18n/jquery.ui.datepicker-'.Tools::htmlentitiesUTF8($iso).'.js"></script>';
  65. echo '<script type="text/javascript">';
  66. if (is_array($id))
  67. foreach ($id as $id2)
  68. bindDatepicker($id2, $time);
  69. else
  70. bindDatepicker($id, $time);
  71. echo '</script>';
  72. }
  73. /**
  74. * Generate a new settings file, only transmitted parameters are updated
  75. *
  76. * @param string $baseUri Base URI
  77. * @param string $theme Theme name (eg. default)
  78. * @param array $arrayDB Parameters in order to connect to database
  79. */
  80. function rewriteSettingsFile($baseUrls = null, $theme = null, $arrayDB = null)
  81. {
  82. $defines = array();
  83. $defines['_MEDIA_SERVER_1_'] = ($baseUrls && isset($baseUrls['_MEDIA_SERVER_1_'])) ? $baseUrls['_MEDIA_SERVER_1_'] : _MEDIA_SERVER_1_;
  84. $defines['_MEDIA_SERVER_2_'] = ($baseUrls && isset($baseUrls['_MEDIA_SERVER_2_'])) ? $baseUrls['_MEDIA_SERVER_2_'] : _MEDIA_SERVER_2_;
  85. $defines['_MEDIA_SERVER_3_'] = ($baseUrls && isset($baseUrls['_MEDIA_SERVER_3_'])) ? $baseUrls['_MEDIA_SERVER_3_'] : _MEDIA_SERVER_3_;
  86. $defines['_PS_CACHING_SYSTEM_'] = _PS_CACHING_SYSTEM_;
  87. $defines['_PS_CACHE_ENABLED_'] = _PS_CACHE_ENABLED_;
  88. $defines['_DB_NAME_'] = (($arrayDB && isset($arrayDB['_DB_NAME_'])) ? $arrayDB['_DB_NAME_'] : _DB_NAME_);
  89. $defines['_MYSQL_ENGINE_'] = (($arrayDB && isset($arrayDB['_MYSQL_ENGINE_'])) ? $arrayDB['_MYSQL_ENGINE_'] : _MYSQL_ENGINE_);
  90. $defines['_DB_SERVER_'] = (($arrayDB && isset($arrayDB['_DB_SERVER_'])) ? $arrayDB['_DB_SERVER_'] : _DB_SERVER_);
  91. $defines['_DB_USER_'] = (($arrayDB && isset($arrayDB['_DB_USER_'])) ? $arrayDB['_DB_USER_'] : _DB_USER_);
  92. $defines['_DB_PREFIX_'] = (($arrayDB && isset($arrayDB['_DB_PREFIX_'])) ? $arrayDB['_DB_PREFIX_'] : _DB_PREFIX_);
  93. $defines['_DB_PASSWD_'] = (($arrayDB && isset($arrayDB['_DB_PASSWD_'])) ? $arrayDB['_DB_PASSWD_'] : _DB_PASSWD_);
  94. $defines['_COOKIE_KEY_'] = addslashes(_COOKIE_KEY_);
  95. $defines['_COOKIE_IV_'] = addslashes(_COOKIE_IV_);
  96. $defines['_PS_CREATION_DATE_'] = addslashes(_PS_CREATION_DATE_);
  97. if (defined('_RIJNDAEL_KEY_'))
  98. $defines['_RIJNDAEL_KEY_'] = addslashes(_RIJNDAEL_KEY_);
  99. if (defined('_RIJNDAEL_IV_'))
  100. $defines['_RIJNDAEL_IV_'] = addslashes(_RIJNDAEL_IV_);
  101. $defines['_PS_VERSION_'] = addslashes(_PS_VERSION_);
  102. $content = "<?php\n\n";
  103. foreach ($defines as $k => $value)
  104. {
  105. if ($k == '_PS_VERSION_')
  106. $content .= 'if (!defined(\''.$k.'\'))'."\n\t";
  107. $content .= 'define(\''.$k.'\', \''.addslashes($value).'\');'."\n";
  108. }
  109. copy(_PS_ADMIN_DIR_.'/../config/settings.inc.php', _PS_ADMIN_DIR_.'/../config/settings.old.php');
  110. if ($fd = fopen(_PS_ADMIN_DIR_.'/../config/settings.inc.php', 'w'))
  111. {
  112. fwrite($fd, $content);
  113. fclose($fd);
  114. return true;
  115. }
  116. return false;
  117. }
  118. /**
  119. * Display SQL date in friendly format
  120. *
  121. * @param string $sqlDate Date in SQL format (YYYY-MM-DD HH:mm:ss)
  122. * @param boolean $withTime Display both date and time
  123. * @todo Several formats (french : DD-MM-YYYY)
  124. */
  125. function displayDate($sqlDate, $withTime = false)
  126. {
  127. return strftime('%Y-%m-%d'.($withTime ? ' %H:%M:%S' : ''), strtotime($sqlDate));
  128. }
  129. /**
  130. * Return path to a product category
  131. *
  132. * @param string $urlBase Start URL
  133. * @param integer $id_category Start category
  134. * @param string $path Current path
  135. * @param string $highlight String to highlight (in XHTML/CSS)
  136. * @param string $type Category type (products/cms)
  137. */
  138. function getPath($urlBase, $id_category, $path = '', $highlight = '', $categoryType = 'catalog', $home = false)
  139. {
  140. $context = Context::getContext();
  141. if ($categoryType == 'catalog')
  142. {
  143. $category = Db::getInstance()->getRow('
  144. SELECT id_category, level_depth, nleft, nright
  145. FROM '._DB_PREFIX_.'category
  146. WHERE id_category = '.(int)$id_category);
  147. if (isset($category['id_category']))
  148. {
  149. $sql = 'SELECT c.id_category, cl.name, cl.link_rewrite
  150. FROM '._DB_PREFIX_.'category c
  151. LEFT JOIN '._DB_PREFIX_.'category_lang cl ON (cl.id_category = c.id_category'.Shop::addSqlRestrictionOnLang('cl').')
  152. WHERE c.nleft <= '.(int)$category['nleft'].'
  153. AND c.nright >= '.(int)$category['nright'].'
  154. AND cl.id_lang = '.(int)$context->language->id.
  155. ($home ? ' AND c.id_category='.(int)$id_category : '').'
  156. AND c.id_category != '.(int)Category::getTopCategory()->id.'
  157. GROUP BY c.id_category
  158. ORDER BY c.level_depth ASC
  159. LIMIT '.(!$home ? (int)($category['level_depth'] + 1) : 1);
  160. $categories = Db::getInstance()->executeS($sql);
  161. $fullPath = '';
  162. $n = 1;
  163. $nCategories = (int)sizeof($categories);
  164. foreach ($categories AS $category)
  165. {
  166. $link = Context::getContext()->link->getAdminLink('AdminCategories');
  167. $edit = '<a href="'.$link.'&id_category='.(int)$category['id_category'].'&'.(($category['id_category'] == 1 || $home) ? 'viewcategory' : 'updatecategory').'" title="'.($category['id_category'] == Category::getRootCategory()->id_category ? 'Home' : 'Modify').'"><i class="icon-'.(($category['id_category'] == Category::getRootCategory()->id_category || $home) ? 'home' : 'pencil').'"></i></a> ';
  168. $fullPath .= $edit.
  169. ($n < $nCategories ? '<a href="'.$urlBase.'&id_category='.(int)$category['id_category'].'&viewcategory&token='.Tools::getAdminToken('AdminCategories'.(int)(Tab::getIdFromClassName('AdminCategories')).(int)$context->employee->id).'" title="'.htmlentities($category['name'], ENT_NOQUOTES, 'UTF-8').'">' : '').
  170. (!empty($highlight) ? str_ireplace($highlight, '<span class="highlight">'.htmlentities($highlight, ENT_NOQUOTES, 'UTF-8').'</span>', $category['name']) : $category['name']).
  171. ($n < $nCategories ? '</a>' : '').
  172. (($n++ != $nCategories || !empty($path)) ? ' > ' : '');
  173. }
  174. return $fullPath.$path;
  175. }
  176. }
  177. elseif ($categoryType == 'cms')
  178. {
  179. $category = new CMSCategory($id_category, $context->language->id);
  180. if (!$category->id)
  181. return $path;
  182. $name = ($highlight != null) ? str_ireplace($highlight, '<span class="highlight">'.$highlight.'</span>', CMSCategory::hideCMSCategoryPosition($category->name)) : CMSCategory::hideCMSCategoryPosition($category->name);
  183. $edit = '<a href="'.$urlBase.'&id_cms_category='.$category->id.'&addcategory&token=' . Tools::getAdminToken('AdminCmsContent'.(int)(Tab::getIdFromClassName('AdminCmsContent')).(int)$context->employee->id).'">
  184. <i class="icon-pencil"></i></a> ';
  185. if ($category->id == 1)
  186. $edit = '<li><a href="'.$urlBase.'&id_cms_category='.$category->id.'&viewcategory&token=' . Tools::getAdminToken('AdminCmsContent'.(int)(Tab::getIdFromClassName('AdminCmsContent')).(int)$context->employee->id).'">
  187. <i class="icon-home"></i></a></li> ';
  188. $path = $edit.'<li><a href="'.$urlBase.'&id_cms_category='.$category->id.'&viewcategory&token=' . Tools::getAdminToken('AdminCmsContent'.(int)(Tab::getIdFromClassName('AdminCmsContent')).(int)$context->employee->id).'">
  189. '.$name.'</a></li> > '.$path;
  190. if ($category->id == 1)
  191. return substr($path, 0, strlen($path) - 3);
  192. return getPath($urlBase, $category->id_parent, $path, '', 'cms');
  193. }
  194. }
  195. function getDirContent($path)
  196. {
  197. $content = array();
  198. if (is_dir($path))
  199. {
  200. $d = dir($path);
  201. while (false !== ($entry = $d->read()))
  202. if ($entry{0} != '.')
  203. $content[] = $entry;
  204. $d->close();
  205. }
  206. return $content;
  207. }
  208. function createDir($path, $rights)
  209. {
  210. if (file_exists($path))
  211. return true;
  212. return @mkdir($path, $rights);
  213. }
  214. function checkPSVersion()
  215. {
  216. $upgrader = new Upgrader();
  217. return $upgrader->checkPSVersion();
  218. }
  219. /**
  220. * Deprecated since > 1.5.4.1
  221. * Use Translate::getAdminTranslation($string) instead
  222. *
  223. * @param string $string
  224. */
  225. function translate($string)
  226. {
  227. Tools::displayAsDeprecated();
  228. global $_LANGADM;
  229. if (!is_array($_LANGADM))
  230. return str_replace('"', '&quot;', $string);
  231. $key = md5(str_replace('\'', '\\\'', $string));
  232. $str = (array_key_exists('index'.$key, $_LANGADM)) ? $_LANGADM['index'.$key] : ((array_key_exists('index'.$key, $_LANGADM)) ? $_LANGADM['index'.$key] : $string);
  233. return str_replace('"', '&quot;', stripslashes($str));
  234. }
  235. /**
  236. * Returns a new Tab object
  237. *
  238. * @param string $tab class name
  239. * @return mixed(AdminTab, bool) tab object or false if failed
  240. */
  241. function checkingTab($tab)
  242. {
  243. $tab = trim($tab);
  244. $tab_lowercase = strtolower($tab);
  245. if (!Validate::isTabName($tab))
  246. return false;
  247. $row = Db::getInstance(_PS_USE_SQL_SLAVE_)->getRow('SELECT id_tab, module, class_name FROM `'._DB_PREFIX_.'tab` WHERE class_name = \''.pSQL($tab).'\'');
  248. if (!$row['id_tab'])
  249. {
  250. if (isset(AdminTab::$tabParenting[$tab]))
  251. Tools::redirectAdmin('?tab='.AdminTab::$tabParenting[$tab].'&token='.Tools::getAdminTokenLite(AdminTab::$tabParenting[$tab]));
  252. echo sprintf(Tools::displayError('Page %s cannot be found..'),$tab);
  253. return false;
  254. }
  255. // Class file is included in Dispatcher::dispatch() function
  256. if (!class_exists($tab, false) || !$row['id_tab'])
  257. {
  258. echo sprintf(Tools::displayError('The class %s cannot be found.'),$tab);
  259. return false;
  260. }
  261. $adminObj = new $tab;
  262. if (!$adminObj->viewAccess() && ($adminObj->table != 'employee' || Context::getContext()->employee->id != Tools::getValue('id_employee') || !Tools::isSubmit('updateemployee')))
  263. {
  264. $adminObj->_errors = array(Tools::displayError('Access denied.'));
  265. echo $adminObj->displayErrors();
  266. return false;
  267. }
  268. return $adminObj;
  269. }
  270. /**
  271. * @TODO deprecate for Tab::checkTabRights()
  272. */
  273. function checkTabRights($id_tab)
  274. {
  275. static $tabAccesses = null;
  276. if ($tabAccesses === null)
  277. $tabAccesses = Profile::getProfileAccesses(Context::getContext()->employee->id_profile);
  278. if (isset($tabAccesses[(int)($id_tab)]['view']))
  279. return ($tabAccesses[(int)($id_tab)]['view'] === '1');
  280. return false;
  281. }
  282. /**
  283. * Converts a simpleXML element into an array. Preserves attributes and everything.
  284. * You can choose to get your elements either flattened, or stored in a custom index that
  285. * you define.
  286. * For example, for a given element
  287. * <field name="someName" type="someType"/>
  288. * if you choose to flatten attributes, you would get:
  289. * $array['field']['name'] = 'someName';
  290. * $array['field']['type'] = 'someType';
  291. * If you choose not to flatten, you get:
  292. * $array['field']['@attributes']['name'] = 'someName';
  293. * _____________________________________
  294. * Repeating fields are stored in indexed arrays. so for a markup such as:
  295. * <parent>
  296. * <child>a</child>
  297. * <child>b</child>
  298. * <child>c</child>
  299. * </parent>
  300. * you array would be:
  301. * $array['parent']['child'][0] = 'a';
  302. * $array['parent']['child'][1] = 'b';
  303. * ...And so on.
  304. * _____________________________________
  305. * @param simpleXMLElement $xml the XML to convert
  306. * @param boolean $flattenValues Choose wether to flatten values
  307. * or to set them under a particular index.
  308. * defaults to true;
  309. * @param boolean $flattenAttributes Choose wether to flatten attributes
  310. * or to set them under a particular index.
  311. * Defaults to true;
  312. * @param boolean $flattenChildren Choose wether to flatten children
  313. * or to set them under a particular index.
  314. * Defaults to true;
  315. * @param string $valueKey index for values, in case $flattenValues was set to
  316. * false. Defaults to "@value"
  317. * @param string $attributesKey index for attributes, in case $flattenAttributes was set to
  318. * false. Defaults to "@attributes"
  319. * @param string $childrenKey index for children, in case $flattenChildren was set to
  320. * false. Defaults to "@children"
  321. * @return array the resulting array.
  322. */
  323. function simpleXMLToArray ($xml, $flattenValues = true, $flattenAttributes = true, $flattenChildren = true, $valueKey = '@value', $attributesKey = '@attributes', $childrenKey = '@children')
  324. {
  325. $return = array();
  326. if (!($xml instanceof SimpleXMLElement))
  327. return $return;
  328. $name = $xml->getName();
  329. $_value = trim((string)$xml);
  330. if (strlen($_value) == 0)
  331. $_value = null;
  332. if ($_value !== null)
  333. {
  334. if (!$flattenValues)
  335. $return[$valueKey] = $_value;
  336. else
  337. $return = $_value;
  338. }
  339. $children = array();
  340. $first = true;
  341. foreach($xml->children() as $elementName => $child)
  342. {
  343. $value = simpleXMLToArray($child, $flattenValues, $flattenAttributes, $flattenChildren, $valueKey, $attributesKey, $childrenKey);
  344. if (isset($children[$elementName]))
  345. {
  346. if ($first)
  347. {
  348. $temp = $children[$elementName];
  349. unset($children[$elementName]);
  350. $children[$elementName][] = $temp;
  351. $first=false;
  352. }
  353. $children[$elementName][] = $value;
  354. }
  355. else
  356. $children[$elementName] = $value;
  357. }
  358. if (count($children) > 0 )
  359. {
  360. if (!$flattenChildren)
  361. $return[$childrenKey] = $children;
  362. else
  363. $return = array_merge($return, $children);
  364. }
  365. $attributes = array();
  366. foreach($xml->attributes() as $name => $value)
  367. $attributes[$name] = trim($value);
  368. if (count($attributes) > 0)
  369. {
  370. if (!$flattenAttributes)
  371. $return[$attributesKey] = $attributes;
  372. else
  373. $return = array_merge($return, $attributes);
  374. }
  375. return $return;
  376. }
  377. /**
  378. * for retrocompatibility with old AdminTab, old index.php
  379. *
  380. * @return void
  381. */
  382. function runAdminTab($tab, $ajaxMode = false)
  383. {
  384. $ajaxMode = (bool)$ajaxMode;
  385. require_once(_PS_ADMIN_DIR_.'/init.php');
  386. $cookie = Context::getContext()->cookie;
  387. if (empty($tab) && !sizeof($_POST))
  388. {
  389. $tab = 'AdminDashboard';
  390. $_POST['tab'] = $tab;
  391. $_POST['token'] = Tools::getAdminTokenLite($tab);
  392. }
  393. // $tab = $_REQUEST['tab'];
  394. if ($adminObj = checkingTab($tab))
  395. {
  396. Context::getContext()->controller = $adminObj;
  397. // init is different for new tabs (AdminController) and old tabs (AdminTab)
  398. if ($adminObj instanceof AdminController)
  399. {
  400. if($ajaxMode)
  401. $adminObj->ajax = true;
  402. $adminObj->path = dirname($_SERVER["PHP_SELF"]);
  403. $adminObj->run();
  404. }
  405. else
  406. {
  407. if (!$ajaxMode)
  408. require_once(_PS_ADMIN_DIR_.'/header.inc.php');
  409. $isoUser = Context::getContext()->language->id;
  410. $tabs = array();
  411. $tabs = Tab::recursiveTab($adminObj->id, $tabs);
  412. $tabs = array_reverse($tabs);
  413. $bread = '';
  414. foreach ($tabs AS $key => $item)
  415. {
  416. $bread .= ' <img src="../img/admin/separator_breadcrumb.png" style="margin-right:5px" alt="&gt;" />';
  417. if (count($tabs) - 1 > $key)
  418. $bread .= '<a href="?tab='.$item['class_name'].'&token='.Tools::getAdminToken($item['class_name'].intval($item['id_tab']).(int)Context::getContext()->employee->id).'">';
  419. $bread .= $item['name'];
  420. if (count($tabs) - 1 > $key)
  421. $bread .= '</a>';
  422. }
  423. if (!$ajaxMode && Shop::isFeatureActive() && Shop::getContext() != Shop::CONTEXT_ALL && Context::getContext()->controller->multishop_context != Shop::CONTEXT_ALL)
  424. {
  425. echo '<div class="multishop_info">';
  426. if (Shop::getContext() == Shop::CONTEXT_GROUP)
  427. {
  428. $shop_group = new ShopGroup((int)Shop::getContextShopGroupID());
  429. printf(Translate::getAdminTranslation('You are configuring your store for group shop %s'), '<b>'.$shop_group->name.'</b>');
  430. }
  431. elseif (Shop::getContext() == Shop::CONTEXT_SHOP)
  432. printf(Translate::getAdminTranslation('You are configuring your store for shop %s'), '<b>'.Context::getContext()->shop->name.'</b>');
  433. echo '</div>';
  434. }
  435. if (Validate::isLoadedObject($adminObj))
  436. {
  437. if ($adminObj->checkToken())
  438. {
  439. if($ajaxMode)
  440. {
  441. // the differences with index.php is here
  442. $adminObj->ajaxPreProcess();
  443. $action = Tools::getValue('action');
  444. // no need to use displayConf() here
  445. if (!empty($action) && method_exists($adminObj, 'ajaxProcess'.Tools::toCamelCase($action)) )
  446. $adminObj->{'ajaxProcess'.Tools::toCamelCase($action)}();
  447. else
  448. $adminObj->ajaxProcess();
  449. // @TODO We should use a displayAjaxError
  450. $adminObj->displayErrors();
  451. if (!empty($action) && method_exists($adminObj, 'displayAjax'.Tools::toCamelCase($action)) )
  452. $adminObj->{'displayAjax'.$action}();
  453. else
  454. $adminObj->displayAjax();
  455. }
  456. else
  457. {
  458. /* Filter memorization */
  459. if (isset($_POST) && !empty($_POST) && isset($adminObj->table))
  460. foreach ($_POST AS $key => $value)
  461. if (is_array($adminObj->table))
  462. {
  463. foreach ($adminObj->table AS $table)
  464. if (strncmp($key, $table.'Filter_', 7) === 0 || strncmp($key, 'submitFilter', 12) === 0)
  465. $cookie->$key = !is_array($value) ? $value : serialize($value);
  466. }
  467. elseif (strncmp($key, $adminObj->table.'Filter_', 7) === 0 || strncmp($key, 'submitFilter', 12) === 0)
  468. $cookie->$key = !is_array($value) ? $value : serialize($value);
  469. if (isset($_GET) && !empty($_GET) && isset($adminObj->table))
  470. foreach ($_GET AS $key => $value)
  471. if (is_array($adminObj->table))
  472. {
  473. foreach ($adminObj->table AS $table)
  474. if (strncmp($key, $table.'OrderBy', 7) === 0 || strncmp($key, $table.'Orderway', 8) === 0)
  475. $cookie->$key = $value;
  476. }
  477. elseif (strncmp($key, $adminObj->table.'OrderBy', 7) === 0 || strncmp($key, $adminObj->table.'Orderway', 12) === 0)
  478. $cookie->$key = $value;
  479. $adminObj->displayConf();
  480. $adminObj->postProcess();
  481. $adminObj->displayErrors();
  482. $adminObj->display();
  483. include(_PS_ADMIN_DIR_.'/footer.inc.php');
  484. }
  485. }
  486. else
  487. {
  488. if($ajaxMode)
  489. {
  490. // If this is an XSS attempt, then we should only display a simple, secure page
  491. if (ob_get_level() && ob_get_length() > 0)
  492. ob_clean();
  493. // ${1} in the replacement string of the regexp is required, because the token may begin with a number and mix up with it (e.g. $17)
  494. $url = preg_replace('/([&?]token=)[^&]*(&.*)?$/', '${1}'.$adminObj->token.'$2', $_SERVER['REQUEST_URI']);
  495. if (false === strpos($url, '?token=') && false === strpos($url, '&token='))
  496. $url .= '&token='.$adminObj->token;
  497. // we can display the correct url
  498. // die(Tools::jsonEncode(array(Translate::getAdminTranslation('Invalid security token'),$url)));
  499. die(Tools::jsonEncode(Translate::getAdminTranslation('Invalid security token')));
  500. }
  501. else
  502. {
  503. // If this is an XSS attempt, then we should only display a simple, secure page
  504. if (ob_get_level() && ob_get_length() > 0)
  505. ob_clean();
  506. // ${1} in the replacement string of the regexp is required, because the token may begin with a number and mix up with it (e.g. $17)
  507. $url = preg_replace('/([&?]token=)[^&]*(&.*)?$/', '${1}'.$adminObj->token.'$2', $_SERVER['REQUEST_URI']);
  508. if (false === strpos($url, '?token=') && false === strpos($url, '&token='))
  509. $url .= '&token='.$adminObj->token;
  510. $message = Translate::getAdminTranslation('Invalid security token');
  511. echo '<html><head><title>'.$message.'</title></head><body style="font-family:Arial,Verdana,Helvetica,sans-serif;background-color:#EC8686">
  512. <div style="background-color:#FAE2E3;border:1px solid #000000;color:#383838;font-weight:700;line-height:20px;margin:0 0 10px;padding:10px 15px;width:500px">
  513. <img src="../img/admin/error2.png" style="margin:-4px 5px 0 0;vertical-align:middle">
  514. '.$message.'
  515. </div>';
  516. echo '<a href="'.htmlentities($url).'" method="get" style="float:left;margin:10px">
  517. <input type="button" value="'.Tools::htmlentitiesUTF8(Translate::getAdminTranslation('I understand the risks and I really want to display this page')).'" style="height:30px;margin-top:5px" />
  518. </a>
  519. <a href="index.php" method="get" style="float:left;margin:10px">
  520. <input type="button" value="'.Tools::htmlentitiesUTF8(Translate::getAdminTranslation('Take me out of here!')).'" style="height:40px" />
  521. </a>
  522. </body></html>';
  523. die;
  524. }
  525. }
  526. }
  527. }
  528. }
  529. }