PageRenderTime 43ms CodeModel.GetById 19ms RepoModel.GetById 0ms app.codeStats 0ms

/modules/storecommander/controllers/admin/AdminStoreCommander.php

https://gitlab.com/ptisky/API_prestashop
PHP | 183 lines | 141 code | 15 blank | 27 comment | 36 complexity | a19df2fcd7b25f8b8062d89824804e2e MD5 | raw file
  1. <?php
  2. /**
  3. * Store Commander
  4. *
  5. * @category administration
  6. * @author Store Commander - support@storecommander.com
  7. * @version 2016-04-01
  8. * @uses Prestashop modules
  9. * @since 2009
  10. * @copyright Copyright &copy; 2009-2015, Store Commander
  11. * @license commercial
  12. * All rights reserved! Copying, duplication strictly prohibited
  13. *
  14. * *****************************************
  15. * * STORE COMMANDER *
  16. * * http://www.StoreCommander.com *
  17. * * V 2016-04-01 *
  18. * *****************************************
  19. *
  20. * Compatibility: PS version: 1.1 to 1.6
  21. *
  22. **/
  23. class AdminStoreCommander extends ModuleAdminController
  24. {
  25. public function __construct()
  26. {
  27. $this->display = 'view';
  28. if (version_compare(_PS_VERSION_, '1.5.0.0', '>=')) {
  29. $this->multishop_context = false;
  30. $this->multishop_context_group = false;
  31. }
  32. parent::__construct();
  33. }
  34. private function findSCFolder()
  35. {
  36. $dir = dirname(__FILE__) . "/../../";
  37. if (is_dir($dir)) {
  38. $objects = scandir($dir);
  39. foreach ($objects as $object) {
  40. if (is_dir($dir . '/' . $object) && Tools::strlen(basename($object)) == 11 && basename($object) != "controllers") {
  41. return basename($object);
  42. }
  43. }
  44. }
  45. return false;
  46. }
  47. public function renderView()
  48. {
  49. $link = Context::getContext()->link;
  50. $cookie = Context::getContext()->cookie;
  51. $this->addCSS(__PS_BASE_URI__.'/modules/storecommander/views/css/admin.css', 'all');
  52. $errors = array();
  53. $sc_title = "";
  54. $sc_url = "";
  55. //
  56. // Login as selected user on the front office
  57. // Fix connection for specific 1.5 shops
  58. //
  59. $_html = "";
  60. if (Tools::getIsset("SETLOGUSER")) {
  61. $path = '';
  62. $domains = null;
  63. if (version_compare(_PS_VERSION_, '1.5.0.0', '>=')) {
  64. $id_shop = (int)(Tools::getValue('id_shop'));
  65. if ($id_shop == 0 && Shop::getTotalShops() > 1) {
  66. $errors[] = Tools::displayError('There is a problem with the shop ID');
  67. } else {
  68. $cookie_lifetime = (int)(defined('_PS_ADMIN_DIR_') ? Configuration::get('PS_COOKIE_LIFETIME_BO') : Configuration::get('PS_COOKIE_LIFETIME_FO'));
  69. $cookie_lifetime = time() + (max($cookie_lifetime, 1) * 3600);
  70. if (Shop::getTotalShops() > 1) {
  71. $shop = new Shop($id_shop);
  72. $shop_group = $shop->getGroup();
  73. if ($shop_group->share_order) {
  74. $cookie = new Cookie('ps-sg' . $shop_group->id, '', $cookie_lifetime,
  75. $shop->getUrlsSharedCart());
  76. } else {
  77. $domains = null;
  78. if ($shop->domain != $shop->domain_ssl) {
  79. $domains = array($shop->domain_ssl, $shop->domain);
  80. }
  81. $cookie = new Cookie('ps-s' . $shop->id, '', $cookie_lifetime, $domains);
  82. }
  83. } else {
  84. $shop = new Shop((int)Configuration::get('PS_SHOP_DEFAULT'));
  85. if ($shop->domain != $shop->domain_ssl) {
  86. $domains = array($shop->domain_ssl, $shop->domain);
  87. }
  88. $cookie = new Cookie('ps-s' . (int)Configuration::get('PS_SHOP_DEFAULT'), '', $cookie_lifetime,
  89. $domains);
  90. }
  91. }
  92. } else {
  93. $cookie = new Cookie('ps');
  94. }
  95. if ($cookie->logged) {
  96. $cookie->logout();
  97. }
  98. Tools::setCookieLanguage();
  99. Tools::switchLanguage();
  100. $customer = new Customer((int)(Tools::getValue('id_customer')));
  101. $cookie->id_customer = (int)($customer->id);
  102. $cookie->customer_lastname = $customer->lastname;
  103. $cookie->customer_firstname = $customer->firstname;
  104. $cookie->logged = 1;
  105. $cookie->passwd = $customer->passwd;
  106. $cookie->email = $customer->email;
  107. if (Configuration::get('PS_CART_FOLLOWING') AND (empty($cookie->id_cart) OR Cart::getNbProducts($cookie->id_cart) == 0)) {
  108. $cookie->id_cart = Cart::lastNoneOrderedCart($customer->id);
  109. }
  110. if (Tools::getIsset('used_last_cart')) {
  111. if (version_compare(_PS_VERSION_, '1.5.0.0', '<')) {
  112. $cookie->id_cart = $customer->getLastCart();
  113. }
  114. }
  115. if (version_compare(_PS_VERSION_, '1.5.0.0', '>=')) {
  116. $order_process = Configuration::get('PS_ORDER_PROCESS_TYPE') ? 'order-opc' : 'order';
  117. if (Shop::getTotalShops() > 1) {
  118. $server_host = Tools::getHttpHost(false, true);
  119. $protocol = 'http://';
  120. $protocol_ssl = 'https://';
  121. $protocol_link = (Configuration::get('PS_SSL_ENABLED')) ? $protocol_ssl : $protocol;
  122. // we replace default domain by selected shop domain
  123. $urltmp = $link->getPageLink($order_process, true);
  124. $urltmparr = explode('index.php', $urltmp);
  125. $urlbase = $protocol_link . $shop->domain . $shop->getBaseURI();
  126. $sc_url = $urlbase . 'index.php' . $urltmparr[1];
  127. } else {
  128. $sc_url = $link->getPageLink($order_process,
  129. true); // http://127.0.0.1/ps15301/index.php?controller=order-opc
  130. }
  131. } else {
  132. $sc_url = __PS_BASE_URI__ . 'order.php';
  133. }
  134. $sc_title = "Connecting...";
  135. } else {
  136. $currentFileName = array_reverse(explode("/", $_SERVER['SCRIPT_NAME']));
  137. $psadminpath = $currentFileName[1];
  138. $datelastregen = Db::getInstance()->getValue('SELECT last_passwd_gen FROM ' . _DB_PREFIX_ . 'employee WHERE id_employee=' . (int)($cookie->id_employee));
  139. $scdir = $this->findSCFolder();
  140. if ($scdir === false) {
  141. $errors[] = 'Unable to find the Store Commander folder. Please contact <a href="support.storecommander.com" targe="_blank">support.storecommander.com</a>';
  142. } else {
  143. $sc_title = "Loading...";
  144. $sc_url = '../modules/storecommander/' . $scdir . '/SC/index.php?ide=' . $cookie->id_employee . '&psap=' . $psadminpath . '&key=' . md5($cookie->id_employee . $datelastregen) . (version_compare(_PS_VERSION_,'1.4.0.0', '>=') ? '' : '&id_lang=' . $cookie->id_lang);
  145. }
  146. }
  147. $errors_html = $this->displayScErrors($errors);
  148. $this->tpl_view_vars = array(
  149. 'html' => $errors_html.$_html,
  150. 'sc_url' => $sc_url,
  151. 'sc_title' => $sc_title
  152. );
  153. return parent::renderView();
  154. }
  155. // useless but needed for compatibility with other modules
  156. public function displayErrors(){}
  157. public function displayScErrors($errors)
  158. {
  159. if (is_array($errors) && count($errors)) {
  160. $_html = '';
  161. $this->context->smarty->assign(array(
  162. 'errors' => $errors
  163. ));
  164. $_html = $this->context->smarty->fetch(dirname(__FILE__).'/../../views/templates/hook/errors.tpl');
  165. return $_html;
  166. }
  167. }
  168. }