PageRenderTime 45ms CodeModel.GetById 17ms RepoModel.GetById 0ms app.codeStats 0ms

/adminstrator/ajax.php

http://marocmall.googlecode.com/
PHP | 699 lines | 581 code | 86 blank | 32 comment | 130 complexity | 79be7246841e5d9ce7c2dae59a96cfe7 MD5 | raw file
Possible License(s): LGPL-2.1
  1. <?php
  2. /*
  3. * 2007-2011 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-2011 PrestaShop SA
  23. * @version Release: $Revision: 9080 $
  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. define('PS_ADMIN_DIR', getcwd());
  28. include(PS_ADMIN_DIR.'/../config/config.inc.php');
  29. /* Getting cookie or logout */
  30. require_once(dirname(__FILE__).'/init.php');
  31. if (isset($_GET['changeParentUrl']))
  32. echo '<script type="text/javascript">parent.parent.document.location.href = "'.addslashes(urldecode(Tools::getValue('changeParentUrl'))).'";</script>';
  33. if (isset($_GET['installBoughtModule']))
  34. {
  35. $file = false;
  36. while ($file === false OR file_exists(_PS_MODULE_DIR_.$file))
  37. $file = uniqid();
  38. $file = _PS_MODULE_DIR_.$file.'.zip';
  39. $sourceFile = 'http://addons.prestashop.com/iframe/getboughtfile.php?id_order_detail='.Tools::getValue('id_order_detail').'&token='.Tools::getValue('token');
  40. if (!copy($sourceFile, $file))
  41. {
  42. if (!($content = file_get_contents($sourceFile)))
  43. die(displayJavascriptAlert('Access denied: Please download your module directly from PrestaShop Addons website'));
  44. elseif (!file_put_contents($file, $content))
  45. die(displayJavascriptAlert('Local error: your module directory is not writable'));
  46. }
  47. $first6 = fread($fd = fopen($file, 'r'), 6);
  48. if (!strncmp($first6, 'Error:', 6))
  49. {
  50. $displayJavascriptAlert = displayJavascriptAlert(fread($fd, 1024));
  51. fclose($fd);
  52. unlink($file);
  53. die($displayJavascriptAlert);
  54. }
  55. fclose($fd);
  56. if (!Tools::ZipExtract($file, _PS_MODULE_DIR_))
  57. {
  58. unlink($file);
  59. die(displayJavascriptAlert('Cannot unzip file'));
  60. }
  61. unlink($file);
  62. die(displayJavascriptAlert('Module copied to disk'));
  63. }
  64. function displayJavascriptAlert($s){echo '<script type="text/javascript">alert(\''.addslashes($s).'\');</script>';}
  65. if (isset($_GET['ajaxProductManufacturers']))
  66. {
  67. $currentIndex = 'index.php?tab=AdminCatalog';
  68. $manufacturers = Manufacturer::getManufacturers();
  69. if ($manufacturers)
  70. {
  71. $jsonArray = array();
  72. foreach ($manufacturers AS $manufacturer)
  73. $jsonArray[] = '{"optionValue": "'.$manufacturer['id_manufacturer'].'", "optionDisplay": "'.htmlspecialchars(trim($manufacturer['name'])).'"}';
  74. die('['.implode(',', $jsonArray).']');
  75. }
  76. }
  77. if (isset($_GET['ajaxReferrers']))
  78. {
  79. require('tabs/AdminReferrers.php');
  80. }
  81. if (isset($_GET['ajaxProductSuppliers']))
  82. {
  83. $currentIndex = 'index.php?tab=AdminCatalog';
  84. $suppliers = Supplier::getSuppliers();
  85. if ($suppliers)
  86. {
  87. $jsonArray = array();
  88. foreach ($suppliers AS $supplier)
  89. $jsonArray[] = '{"optionValue": "'.$supplier['id_supplier'].'", "optionDisplay": "'.htmlspecialchars(trim($supplier['name'])).'"}';
  90. die('['.implode(',', $jsonArray).']');
  91. }
  92. }
  93. if (isset($_GET['ajaxProductAccessories']))
  94. {
  95. $currentIndex = 'index.php?tab=AdminCatalog';
  96. $jsonArray = array();
  97. $products = Db::getInstance()->ExecuteS('
  98. SELECT p.`id_product`, pl.`name`
  99. FROM `'._DB_PREFIX_.'product` p
  100. NATURAL LEFT JOIN `'._DB_PREFIX_.'product_lang` pl
  101. WHERE pl.`id_lang` = '.(int)(Tools::getValue('id_lang')).'
  102. AND p.`id_product` != '.(int)(Tools::getValue('id_product')).'
  103. AND p.`id_product` NOT IN (
  104. SELECT a.`id_product_2`
  105. FROM `'._DB_PREFIX_.'accessory` a
  106. WHERE a.`id_product_1` = '.(int)(Tools::getValue('id_product')).')
  107. ORDER BY pl.`name`');
  108. foreach ($products AS $accessory)
  109. $jsonArray[] = '{"value: "'.(int)($accessory['id_product']).'-'.addslashes($accessory['name']).'", "text":"'.(int)($accessory['id_product']).' - '.addslashes($accessory['name']).'"}';
  110. die('['.implode(',', $jsonArray).']');
  111. }
  112. if (isset($_GET['ajaxDiscountCustomers']))
  113. {
  114. global $cookie;
  115. $currentIndex = 'index.php?tab=AdminDiscounts';
  116. $jsonArray = array();
  117. $filter = Tools::getValue('filter');
  118. if (Validate::isBool_Id($filter))
  119. $filterArray = explode('_', $filter);
  120. $customers = Db::getInstance()->ExecuteS('
  121. SELECT `id_customer`, `email`, CONCAT(`lastname`, \' \', `firstname`) as name
  122. FROM `'._DB_PREFIX_.'customer`
  123. WHERE `deleted` = 0 AND is_guest = 0
  124. AND '.(Validate::isUnsignedInt($filter) ? '`id_customer` = '.(int)($filter) : '(`email` LIKE "%'.pSQL($filter).'%"
  125. '.((Validate::isBool_Id($filter) AND $filterArray[0] == 0) ? 'OR `id_customer` = '.(int)($filterArray[1]) : '').'
  126. '.(Validate::isUnsignedInt($filter) ? '`id_customer` = '.(int)($filter) : '').'
  127. OR CONCAT(`firstname`, \' \', `lastname`) LIKE "%'.pSQL($filter).'%"
  128. OR CONCAT(`lastname`, \' \', `firstname`) LIKE "%'.pSQL($filter).'%")').'
  129. ORDER BY CONCAT(`lastname`, \' \', `firstname`) ASC
  130. LIMIT 50');
  131. $groups = Db::getInstance()->ExecuteS('
  132. SELECT g.`id_group`, gl.`name`
  133. FROM `'._DB_PREFIX_.'group` g
  134. LEFT JOIN `'._DB_PREFIX_.'group_lang` AS gl ON (g.`id_group` = gl.`id_group` AND gl.`id_lang` = '.(int)($cookie->id_lang).')
  135. WHERE '.(Validate::isUnsignedInt($filter) ? 'g.`id_group` = '.(int)($filter) : 'gl.`name` LIKE "%'.pSQL($filter).'%"
  136. '.((Validate::isBool_Id($filter) AND $filterArray[0] == 1) ? 'OR g.`id_group` = '.(int)($filterArray[1]) : '')).'
  137. ORDER BY gl.`name` ASC
  138. LIMIT 50');
  139. $json = '{"customers" : ';
  140. foreach ($customers AS $customer)
  141. $jsonArray[] = '{"value":"0_'.(int)($customer['id_customer']).'", "text":"'.addslashes($customer['name']).' ('.addslashes($customer['email']).')"}';
  142. $json .= '['.implode(',', $jsonArray).'],
  143. "groups" : ';
  144. $jsonArray = array();
  145. foreach ($groups AS $group)
  146. $jsonArray[] = '{"value":"1_'.(int)($group['id_group']).'", "text":"'.addslashes($group['name']).'"}';
  147. $json .= '['.implode(',', $jsonArray).']}';
  148. die($json);
  149. }
  150. if (Tools::getValue('page') == 'prestastore' AND @fsockopen('addons.prestashop.com', 80, $errno, $errst, 3))
  151. readfile('http://addons.prestashop.com/adminmodules.php?lang='.Language::getIsoById($cookie->id_lang));
  152. if (Tools::getValue('page') == 'themes' AND @fsockopen('addons.prestashop.com', 80, $errno, $errst, 3))
  153. readfile('http://addons.prestashop.com/adminthemes.php?lang='.Language::getIsoById($cookie->id_lang));
  154. if ($step = (int)(Tools::getValue('ajaxProductTab')))
  155. {
  156. require_once(dirname(__FILE__).'/tabs/AdminCatalog.php');
  157. $catalog = new AdminCatalog();
  158. $admin = new AdminProducts();
  159. $languages = Language::getLanguages(false);
  160. $defaultLanguage = (int)(Configuration::get('PS_LANG_DEFAULT'));
  161. $product = new Product((int)(Tools::getValue('id_product')));
  162. if (!Validate::isLoadedObject($product))
  163. die (Tools::displayError('Product cannot be loaded'));
  164. $switchArray = array(3 => 'displayFormPrices', 4 => 'displayFormAttributes', 5 => 'displayFormFeatures', 6 => 'displayFormCustomization', 7 => 'displayFormAttachments');
  165. $currentIndex = 'index.php?tab=AdminCatalog';
  166. if (key_exists($step, $switchArray))
  167. $admin->{$switchArray[$step]}($product, $languages, $defaultLanguage);
  168. }
  169. if (isset($_GET['getAvailableFields']) and isset($_GET['entity']))
  170. {
  171. $currentIndex = 'index.php?tab=AdminImport';
  172. $jsonArray = array();
  173. require_once(dirname(__FILE__).'/tabs/AdminImport.php');
  174. $import = new AdminImport();
  175. $languages = Language::getLanguages(false);
  176. $defaultLanguage = (int)(Configuration::get('PS_LANG_DEFAULT'));
  177. $fields = $import->getAvailableFields(true);
  178. foreach ($fields AS $field)
  179. $jsonArray[] = '{"field":"'.addslashes($field).'"}';
  180. die('['.implode(',', $jsonArray).']');
  181. }
  182. if (array_key_exists('ajaxModulesPositions', $_POST))
  183. {
  184. $id_module = (int)(Tools::getValue('id_module'));
  185. $id_hook = (int)(Tools::getValue('id_hook'));
  186. $way = (int)(Tools::getValue('way'));
  187. $positions = Tools::getValue(strval($id_hook));
  188. $position = (is_array($positions)) ? array_search($id_hook.'_'.$id_module, $positions) : null;
  189. $module = Module::getInstanceById($id_module);
  190. if (Validate::isLoadedObject($module))
  191. if ($module->updatePosition($id_hook, $way, $position))
  192. die(true);
  193. else
  194. die('{"hasError" : true, "errors" : "Can not update module position"}');
  195. else
  196. die('{"hasError" : true, "errors" : "This module can not be loaded"}');
  197. }
  198. if (array_key_exists('ajaxCategoriesPositions', $_POST))
  199. {
  200. $id_category_to_move = (int)(Tools::getValue('id_category_to_move'));
  201. $id_category_parent = (int)(Tools::getValue('id_category_parent'));
  202. $way = (int)(Tools::getValue('way'));
  203. $positions = Tools::getValue('category');
  204. if (is_array($positions))
  205. foreach ($positions AS $key => $value)
  206. {
  207. $pos = explode('_', $value);
  208. if ((isset($pos[1]) AND isset($pos[2])) AND ($pos[1] == $id_category_parent AND $pos[2] == $id_category_to_move))
  209. {
  210. $position = $key;
  211. break;
  212. }
  213. }
  214. $category = new Category($id_category_to_move);
  215. if (Validate::isLoadedObject($category))
  216. {
  217. if (isset($position) && $category->updatePosition($way, $position))
  218. {
  219. Module::hookExec('categoryUpdate');
  220. die(true);
  221. }
  222. else
  223. die('{"hasError" : true, errors : "Can not update categories position"}');
  224. }
  225. else
  226. die('{"hasError" : true, "errors" : "This category can not be loaded"}');
  227. }
  228. if (array_key_exists('ajaxCMSCategoriesPositions', $_POST))
  229. {
  230. $id_cms_category_to_move = (int)(Tools::getValue('id_cms_category_to_move'));
  231. $id_cms_category_parent = (int)(Tools::getValue('id_cms_category_parent'));
  232. $way = (int)(Tools::getValue('way'));
  233. $positions = Tools::getValue('cms_category');
  234. if (is_array($positions))
  235. foreach ($positions AS $key => $value)
  236. {
  237. $pos = explode('_', $value);
  238. if ((isset($pos[1]) AND isset($pos[2])) AND ($pos[1] == $id_cms_category_parent AND $pos[2] == $id_cms_category_to_move))
  239. {
  240. $position = $key;
  241. break;
  242. }
  243. }
  244. $cms_category = new CMSCategory($id_cms_category_to_move);
  245. if (Validate::isLoadedObject($cms_category))
  246. {
  247. if (isset($position) && $cms_category->updatePosition($way, $position))
  248. die(true);
  249. else
  250. die('{"hasError" : true, "errors" : "Can not update cms categories position"}');
  251. }
  252. else
  253. die('{"hasError" : true, "errors" : "This cms category can not be loaded"}');
  254. }
  255. if (array_key_exists('ajaxCMSPositions', $_POST))
  256. {
  257. $id_cms = (int)(Tools::getValue('id_cms'));
  258. $id_category = (int)(Tools::getValue('id_cms_category'));
  259. $way = (int)(Tools::getValue('way'));
  260. $positions = Tools::getValue('cms');
  261. if (is_array($positions))
  262. foreach ($positions AS $key => $value)
  263. {
  264. $pos = explode('_', $value);
  265. if ((isset($pos[1]) AND isset($pos[2])) AND ($pos[1] == $id_category AND $pos[2] == $id_cms))
  266. {
  267. $position = $key;
  268. break;
  269. }
  270. }
  271. $cms = new CMS($id_cms);
  272. if (Validate::isLoadedObject($cms))
  273. {
  274. if (isset($position) && $cms->updatePosition($way, $position))
  275. die(true);
  276. else
  277. die('{"hasError" : true, "errors" : "Can not update cms position"}');
  278. }
  279. else
  280. die('{"hasError" : true, "errors" : "This cms can not be loaded"}');
  281. }
  282. /* Modify product position in catalog */
  283. if (array_key_exists('ajaxProductsPositions', $_POST))
  284. {
  285. $way = (int)(Tools::getValue('way'));
  286. $id_product = (int)(Tools::getValue('id_product'));
  287. $id_category = (int)(Tools::getValue('id_category'));
  288. $positions = Tools::getValue('product');
  289. if (is_array($positions))
  290. foreach ($positions AS $position => $value)
  291. {
  292. // pos[1] = id_categ, pos[2] = id_product, pos[3]=old position
  293. $pos = explode('_', $value);
  294. if ((isset($pos[1]) AND isset($pos[2])) AND ($pos[1] == $id_category AND (int)$pos[2] === $id_product))
  295. {
  296. if ($product = new Product((int)$pos[2]))
  297. if (isset($position) && $product->updatePosition($way, $position))
  298. echo "ok position $position for product $pos[2]\r\n";
  299. else
  300. echo '{"hasError" : true, "errors" : "Can not update product '. $id_product . ' to position '.$position.' "}';
  301. else
  302. echo '{"hasError" : true, "errors" : "This product ('.$id_product.') can t be loaded"}';
  303. break;
  304. }
  305. }
  306. }
  307. if (isset($_GET['ajaxProductPackItems']))
  308. {
  309. $jsonArray = array();
  310. $products = Db::getInstance()->ExecuteS('
  311. SELECT p.`id_product`, pl.`name`
  312. FROM `'._DB_PREFIX_.'product` p
  313. NATURAL LEFT JOIN `'._DB_PREFIX_.'product_lang` pl
  314. WHERE pl.`id_lang` = '.(int)(Tools::getValue('id_lang')).'
  315. AND p.`id_product` NOT IN (SELECT DISTINCT id_product_pack FROM `'._DB_PREFIX_.'pack`)
  316. AND p.`id_product` != '.(int)(Tools::getValue('id_product')));
  317. foreach ($products AS $packItem)
  318. $jsonArray[] = '{"value": "'.(int)($packItem['id_product']).'-'.addslashes($packItem['name']).'", "text":"'.(int)($packItem['id_product']).' - '.addslashes($packItem['name']).'"}';
  319. die('['.implode(',', $jsonArray).']');
  320. }
  321. if (isset($_GET['ajaxStates']) AND isset($_GET['id_country']))
  322. {
  323. $states = Db::getInstance()->ExecuteS('
  324. SELECT s.id_state, s.name
  325. FROM '._DB_PREFIX_.'state s
  326. LEFT JOIN '._DB_PREFIX_.'country c ON (s.`id_country` = c.`id_country`)
  327. WHERE s.id_country = '.(int)(Tools::getValue('id_country')).' AND s.active = 1 AND c.`contains_states` = 1
  328. ORDER BY s.`name` ASC');
  329. if (is_array($states) AND !empty($states))
  330. {
  331. $list = '';
  332. if (Tools::getValue('no_empty') != true)
  333. $list = '<option value="0">-----------</option>'."\n";
  334. foreach ($states AS $state)
  335. $list .= '<option value="'.(int)($state['id_state']).'"'.((isset($_GET['id_state']) AND $_GET['id_state'] == $state['id_state']) ? ' selected="selected"' : '').'>'.$state['name'].'</option>'."\n";
  336. }
  337. else
  338. $list = 'false';
  339. die($list);
  340. }
  341. if (Tools::isSubmit('submitCustomerNote') AND $id_customer = (int)Tools::getValue('id_customer'))
  342. {
  343. $note = html_entity_decode(Tools::getValue('note'));
  344. if (!empty($note) AND !Validate::isCleanHtml($note))
  345. die ('error:validation');
  346. if (!Db::getInstance()->Execute('UPDATE '._DB_PREFIX_.'customer SET `note` = "'.pSQL($note, true).'" WHERE id_customer = '.(int)$id_customer.' LIMIT 1'))
  347. die ('error:update');
  348. die('ok');
  349. }
  350. if (Tools::getValue('form_language_id'))
  351. {
  352. if (!($cookie->employee_form_lang = (int)(Tools::getValue('form_language_id'))))
  353. die ('Error while updating cookie.');
  354. die ('Form language updated.');
  355. }
  356. if (Tools::getValue('submitPublishProduct'))
  357. {
  358. global $cookie;
  359. if (Tools::getIsset('id_product'))
  360. {
  361. $id_product = (int)(Tools::getValue('id_product'));
  362. $id_tab_catalog = (int)(Tab::getIdFromClassName('AdminCatalog'));
  363. $token = Tools::getAdminToken('AdminCatalog'.(int)($id_tab_catalog).(int)($cookie->id_employee));
  364. $bo_product_url = dirname($_SERVER['PHP_SELF']).'/index.php?tab=AdminCatalog&id_product='.$id_product.'&updateproduct&token='.$token;
  365. if (Tools::getValue('redirect'))
  366. die($bo_product_url);
  367. $profileAccess = Profile::getProfileAccess((int)$cookie->profile, $id_tab_catalog);
  368. if ($profileAccess['edit'])
  369. {
  370. $product = new Product((int)(Tools::getValue('id_product')));
  371. if (!Validate::isLoadedObject($product))
  372. die('error: invalid id');
  373. $product->active = 1;
  374. if ($product->save())
  375. die($bo_product_url);
  376. else
  377. die('error: saving');
  378. } else {
  379. die('error: permissions');
  380. }
  381. }
  382. else
  383. die ('error: parameters');
  384. }
  385. if (Tools::getValue('submitPublishCMS'))
  386. {
  387. global $cookie;
  388. if (Tools::getIsset('id_cms'))
  389. {
  390. $id_cms = (int)(Tools::getValue('id_cms'));
  391. $id_tab_cms = (int)(Tab::getIdFromClassName('AdminCMSContent'));
  392. $token = Tools::getAdminToken('AdminCMSContent'.(int)($id_tab_cms).(int)($cookie->id_employee));
  393. $bo_cms_url = dirname($_SERVER['PHP_SELF']).'/index.php?tab=AdminCMSContent&id_cms='.(int)$id_cms.'&updatecms&token='.$token;
  394. if (Tools::getValue('redirect'))
  395. die($bo_cms_url);
  396. $profileAccess = Profile::getProfileAccess((int)$cookie->profile, $id_tab_cms);
  397. if ($profileAccess['edit'])
  398. {
  399. $cms = new CMS((int)(Tools::getValue('id_cms')));
  400. if (!Validate::isLoadedObject($cms))
  401. die('error: invalid id');
  402. $cms->active = 1;
  403. if ($cms->save())
  404. die($bo_cms_url);
  405. else
  406. die('error: saving');
  407. } else {
  408. die('error: permissions');
  409. }
  410. }
  411. else
  412. die ('error: parameters');
  413. }
  414. if (Tools::isSubmit('submitTrackClickOnHelp'))
  415. {
  416. $label = Tools::getValue('label');
  417. $version = Tools::getValue('version');
  418. if (!empty($label) && !empty($version))
  419. HelpAccess::trackClick($label, $version);
  420. }
  421. if (Tools::isSubmit('saveImportMatchs'))
  422. {
  423. $match = implode('|', Tools::getValue('type_value'));
  424. Db::getInstance()->Execute('INSERT INTO `'._DB_PREFIX_.'import_match` (
  425. `id_import_match` ,
  426. `name` ,
  427. `match`,
  428. `skip`
  429. )
  430. VALUES (
  431. NULL ,
  432. \''.pSQL(Tools::getValue('newImportMatchs')).'\',
  433. \''.pSQL($match).'\',
  434. \''.pSQL(Tools::getValue('skip')).'\'
  435. )');
  436. die('{"id" : "'.Db::getInstance()->Insert_ID().'"}');
  437. }
  438. if (Tools::isSubmit('deleteImportMatchs'))
  439. {
  440. Db::getInstance()->Execute('DELETE FROM `'._DB_PREFIX_.'import_match` WHERE `id_import_match` = '.(int)Tools::getValue('idImportMatchs'));
  441. }
  442. if (Tools::isSubmit('loadImportMatchs'))
  443. {
  444. $return = Db::getInstance()->ExecuteS('SELECT * FROM `'._DB_PREFIX_.'import_match` WHERE `id_import_match` = '.(int)Tools::getValue('idImportMatchs'));
  445. die('{"id" : "'.$return[0]['id_import_match'].'", "matchs" : "'.$return[0]['match'].'", "skip" : "'.$return[0]['skip'].'"}');
  446. }
  447. if (Tools::isSubmit('toggleScreencast'))
  448. {
  449. global $cookie;
  450. $employee = new Employee($cookie->id_employee);
  451. if (Validate::isLoadedObject($employee))
  452. {
  453. $employee->bo_show_screencast = !$employee->bo_show_screencast;
  454. $employee->update();
  455. }
  456. }
  457. if (Tools::isSubmit('ajaxAddZipCode') OR Tools::isSubmit('ajaxRemoveZipCode'))
  458. {
  459. require_once(PS_ADMIN_DIR.'/tabs/AdminCounty.php');
  460. $zipcodes = Tools::getValue('zipcodes');
  461. $id_county = (int)Tools::getValue('id_county');
  462. $county = new County($id_county);
  463. if (!Validate::isLoadedObject($county))
  464. die('error');
  465. if (Tools::isSubmit('ajaxAddZipCode'))
  466. {
  467. if ($county->isZipCodeRangePresent($zipcodes))
  468. die('error:'.Tools::displayError('This Zip Code is already in use.'));
  469. if ($county->addZipCodes($zipcodes))
  470. die(AdminCounty::renderZipCodeList($county->getZipCodes()));
  471. }
  472. elseif (Tools::isSubmit('ajaxRemoveZipCode') AND $county->removeZipCodes($zipcodes))
  473. die(AdminCounty::renderZipCodeList($county->getZipCodes()));
  474. die('error');
  475. }
  476. if (Tools::isSubmit('helpAccess'))
  477. {
  478. $item = Tools::getValue('item');
  479. $isoUser = Tools::getValue('isoUser');
  480. $country = Tools::getValue('country');
  481. $version = Tools::getValue('version');
  482. if (isset($item) AND isset($isoUser) AND isset($country))
  483. die(HelpAccess::displayHelp($item, $isoUser, $country, $version));
  484. die();
  485. }
  486. if (Tools::isSubmit('getHookableList'))
  487. {
  488. if (!strlen(Tools::getValue('hooks_list')))
  489. die('{"hasError" : true, "errors" : ["Live Edit : no module on this page"]}');
  490. $modules_list = explode(',', Tools::getValue('modules_list'));
  491. $hooks_list = explode(',', Tools::getValue('hooks_list'));
  492. $hookableList = array();
  493. foreach ($modules_list as $module)
  494. {
  495. $moduleInstance = Module::getInstanceByName($module);
  496. foreach($hooks_list as $hook_name)
  497. {
  498. if (!array_key_exists($hook_name, $hookableList))
  499. $hookableList[$hook_name] = array();
  500. if ($moduleInstance->isHookableOn($hook_name))
  501. array_push($hookableList[$hook_name], $module);
  502. }
  503. }
  504. $hookableList['hasError'] = false;
  505. die(Tools::jsonEncode($hookableList));
  506. }
  507. if (Tools::isSubmit('getHookableModuleList'))
  508. {
  509. include('../init.php');
  510. $hook_name = Tools::getValue('hook');
  511. $hookableModulesList = array();
  512. $modules = Db::getInstance()->ExecuteS('SELECT id_module, name FROM `'._DB_PREFIX_.'module` ');
  513. foreach ($modules as $module)
  514. {
  515. if (file_exists(_PS_MODULE_DIR_.$module['name'].'/'.$module['name'].'.php'))
  516. {
  517. include_once(_PS_MODULE_DIR_.$module['name'].'/'.$module['name'].'.php');
  518. $mod = new $module['name']();
  519. if ($mod->isHookableOn($hook_name))
  520. $hookableModulesList[] = array('id' => (int)$mod->id, 'name' => $mod->displayName, 'display' => Module::hookExec($hook_name, array(), (int)$mod->id));
  521. }
  522. }
  523. die(Tools::jsonEncode($hookableModulesList));
  524. }
  525. if (Tools::isSubmit('saveHook'))
  526. {
  527. $hooks_list = explode(',', Tools::getValue('hooks_list'));
  528. foreach ($hooks_list as $hook)
  529. {
  530. Db::getInstance()->Execute('DELETE FROM `'._DB_PREFIX_.'hook_module` WHERE `id_hook` = (SELECT id_hook FROM `'._DB_PREFIX_.'hook` WHERE `name` = \''.pSQL($hook).'\' LIMIT 0, 1)');
  531. $hookedModules = explode(',', Tools::getValue($hook));
  532. $i = 1;
  533. $value = '';
  534. foreach($hookedModules as $module)
  535. {
  536. $ids = explode('_', $module);
  537. $value .= '('.(int)$ids[1].', (SELECT id_hook FROM `'._DB_PREFIX_.'hook` WHERE `name` = \''.pSQL($hook).'\' LIMIT 0, 1), '.(int)$i.'),';
  538. $i ++;
  539. }
  540. $value = rtrim($value, ',');
  541. Db::getInstance()->Execute('INSERT INTO `'._DB_PREFIX_.'hook_module` (`id_module`, `id_hook`, `position`) VALUES '.$value);
  542. }
  543. die('{"hasError" : false, "errors" : ""}');
  544. }
  545. if (Tools::isSubmit('getAdminHomeElement'))
  546. {
  547. $result = array();
  548. $protocol = Tools::usingSecureMode() ? 'https' : 'http';
  549. $isoUser = Language::getIsoById(intval($cookie->id_lang));
  550. $isoCountry = Country::getIsoById(Configuration::get('PS_COUNTRY_DEFAULT'));
  551. $stream_context = @stream_context_create(array('http' => array('method'=> 'GET', 'timeout' => 5)));
  552. // SCREENCAST
  553. if (@fsockopen('www.prestashop.com', 80, $errno, $errst, 3))
  554. $result['screencast'] = 'OK';
  555. else
  556. $result['screencast'] = 'NOK';
  557. // PREACTIVATION
  558. $content = @file_get_contents($protocol.'://www.prestashop.com/partner/preactivation/preactivation-block.php?version=1.0&shop='.urlencode(Configuration::get('PS_SHOP_NAME')).'&protocol='.$protocol.'&url='.urlencode($_SERVER['HTTP_HOST']).'&iso_country='.$isoCountry.'&iso_lang='.Tools::strtolower($isoUser).'&id_lang='.(int)$cookie->id_lang.'&email='.urlencode(Configuration::get('PS_SHOP_EMAIL')).'&date_creation='._PS_CREATION_DATE_.'&v='._PS_VERSION_.'&security='.md5(Configuration::get('PS_SHOP_EMAIL')._COOKIE_IV_), false, $stream_context);
  559. if (!$content)
  560. $result['partner_preactivation'] = 'NOK';
  561. else
  562. {
  563. $content = explode('|', $content);
  564. if ($content[0] == 'OK' && Validate::isCleanHtml($content[2]) && Validate::isCleanHtml($content[1]))
  565. {
  566. $result['partner_preactivation'] = $content[2];
  567. $content[1] = explode('#%#', $content[1]);
  568. foreach ($content[1] as $partnerPopUp)
  569. if ($partnerPopUp)
  570. {
  571. $partnerPopUp = explode('%%', $partnerPopUp);
  572. if (!Configuration::get('PS_PREACTIVATION_'.strtoupper($partnerPopUp[0])))
  573. {
  574. $result['partner_preactivation'] .= $partnerPopUp[1];
  575. Configuration::updateValue('PS_PREACTIVATION_'.strtoupper($partnerPopUp[0]), 'TRUE');
  576. }
  577. }
  578. }
  579. else
  580. $result['partner_preactivation'] = 'NOK';
  581. }
  582. // PREACTIVATION PAYPAL WARNING
  583. $content = @file_get_contents('https://www.prestashop.com/partner/preactivation/preactivation-warnings.php?version=1.0&partner=paypal&iso_country='.Tools::strtolower(Country::getIsoById(Configuration::get('PS_COUNTRY_DEFAULT'))).'&iso_lang='.Tools::strtolower(Language::getIsoById(intval($cookie->id_lang))).'&id_lang='.(int)$cookie->id_lang.'&email='.urlencode(Configuration::get('PS_SHOP_EMAIL')).'&security='.md5(Configuration::get('PS_SHOP_EMAIL')._COOKIE_IV_), false, $stream_context);
  584. $content = explode('|', $content);
  585. if ($content[0] == 'OK' && Validate::isCleanHtml($content[1]))
  586. Configuration::updateValue('PS_PREACTIVATION_PAYPAL_WARNING', $content[1]);
  587. else
  588. Configuration::updateValue('PS_PREACTIVATION_PAYPAL_WARNING', '');
  589. // DISCOVER PRESTASHOP
  590. $content = @file_get_contents($protocol.'://www.prestashop.com/partner/prestashop/prestashop-link.php?iso_country='.$isoCountry.'&iso_lang='.Tools::strtolower($isoUser).'&id_lang='.(int)$cookie->id_lang, false, $stream_context);
  591. if (!$content)
  592. $result['discover_prestashop'] = 'NOK';
  593. else
  594. {
  595. $content = explode('|', $content);
  596. if ($content[0] == 'OK' && Validate::isCleanHtml($content[1]))
  597. $result['discover_prestashop'] = $content[1];
  598. else
  599. $result['discover_prestashop'] = 'NOK';
  600. if (@fsockopen('www.prestashop.com', 80, $errno, $errst, 3))
  601. $result['discover_prestashop'] .= '<iframe frameborder="no" style="margin: 0px; padding: 0px; width: 315px; height: 290px;" src="'.$protocol.'://www.prestashop.com/rss/news2.php?v='._PS_VERSION_.'&lang='.$isoUser.'"></iframe>';
  602. $content = @file_get_contents($protocol.'://www.prestashop.com/partner/paypal/paypal-tips.php?protocol='.$protocol.'&iso_country='.$isoCountry.'&iso_lang='.Tools::strtolower($isoUser).'&id_lang='.(int)$cookie->id_lang, false, $stream_context);
  603. $content = explode('|', $content);
  604. if ($content[0] == 'OK' && Validate::isCleanHtml($content[1]))
  605. $result['discover_prestashop'] .= $content[1];
  606. }
  607. die(Tools::jsonEncode($result));
  608. }
  609. if (Tools::isSubmit('getChildrenCategories') && Tools::getValue('id_category_parent'))
  610. {
  611. $children_categories = Category::getChildrenWithNbSelectedSubCat(Tools::getValue('id_category_parent'), Tools::getValue('selectedCat'), $cookie->id_lang);
  612. die(Tools::jsonEncode($children_categories));
  613. }