PageRenderTime 41ms CodeModel.GetById 12ms RepoModel.GetById 1ms app.codeStats 0ms

/admin7677/functions.php

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