/**
  * Initialize order confirmation controller
  * @see FrontController::init()
  */
 public function init()
 {
     parent::init();
     $this->id_cart = (int) Tools::getValue('id_cart', 0);
     $is_guest = false;
     /* check if the cart has been made by a Guest customer, for redirect link */
     if (Cart::isGuestCartByCartId($this->id_cart)) {
         $is_guest = true;
         $redirectLink = 'index.php?controller=guest-tracking';
     } else {
         $redirectLink = 'index.php?controller=history';
     }
     $this->id_module = (int) Tools::getValue('id_module', 0);
     $this->id_order = Order::getOrderByCartId((int) $this->id_cart);
     $this->secure_key = Tools::getValue('key', false);
     $order = new Order((int) $this->id_order);
     if ($is_guest) {
         $customer = new Customer((int) $order->id_customer);
         $redirectLink .= '&id_order=' . $order->reference . '&email=' . urlencode($customer->email);
     }
     if (!$this->id_order || !$this->id_module || !$this->secure_key || empty($this->secure_key)) {
         Tools::redirect($redirectLink . (Tools::isSubmit('slowvalidation') ? '&slowvalidation' : ''));
     }
     $this->reference = $order->reference;
     if (!Validate::isLoadedObject($order) || $order->id_customer != $this->context->customer->id || $this->secure_key != $order->secure_key) {
         Tools::redirect($redirectLink);
     }
     $module = Module::getInstanceById((int) $this->id_module);
     if ($order->payment != $module->displayName) {
         Tools::redirect($redirectLink);
     }
 }
 public function renderForm()
 {
     if (Context::getContext()->shop->getContext() != Shop::CONTEXT_SHOP && Shop::isFeatureActive()) {
         $this->errors[] = $this->l('You have to select a shop before creating new orders.');
     }
     $id_cart = (int) Tools::getValue('id_cart');
     $cart = new Cart((int) $id_cart);
     if ($id_cart && !Validate::isLoadedObject($cart)) {
         $this->errors[] = $this->l('This cart does not exists');
     }
     if ($id_cart && Validate::isLoadedObject($cart) && !$cart->id_customer) {
         $this->errors[] = $this->l('The cart must have a customer');
     }
     if (count($this->errors)) {
         return false;
     }
     parent::renderForm();
     unset($this->toolbar_btn['save']);
     $this->addJqueryPlugin(array('autocomplete', 'fancybox', 'typewatch'));
     $defaults_order_state = array('cheque' => (int) Configuration::get('PS_OS_CHEQUE'), 'bankwire' => (int) Configuration::get('PS_OS_BANKWIRE'), 'cashondelivery' => Configuration::get('PS_OS_COD_VALIDATION') ? (int) Configuration::get('PS_OS_COD_VALIDATION') : (int) Configuration::get('PS_OS_PREPARATION'), 'other' => (int) Configuration::get('PS_OS_PAYMENT'));
     $payment_modules = array();
     foreach (PaymentModule::getInstalledPaymentModules() as $p_module) {
         $payment_modules[] = Module::getInstanceById((int) $p_module['id_module']);
     }
     $this->context->smarty->assign(array('recyclable_pack' => (int) Configuration::get('PS_RECYCLABLE_PACK'), 'gift_wrapping' => (int) Configuration::get('PS_GIFT_WRAPPING'), 'cart' => $cart, 'currencies' => Currency::getCurrenciesByIdShop(Context::getContext()->shop->id), 'langs' => Language::getLanguages(true, Context::getContext()->shop->id), 'payment_modules' => $payment_modules, 'order_states' => OrderState::getOrderStates((int) Context::getContext()->language->id), 'defaults_order_state' => $defaults_order_state, 'show_toolbar' => $this->show_toolbar, 'toolbar_btn' => $this->toolbar_btn, 'toolbar_scroll' => $this->toolbar_scroll, 'PS_CATALOG_MODE' => Configuration::get('PS_CATALOG_MODE'), 'title' => array($this->l('Orders'), $this->l('Create order'))));
     $this->content .= $this->createTemplate('form.tpl')->fetch();
 }
 public function preProcess()
 {
     parent::preProcess();
     $this->id_cart = (int) Tools::getValue('id_cart', 0);
     /* check if the cart has been made by a Guest customer, for redirect link */
     if (Cart::isGuestCartByCartId($this->id_cart)) {
         $redirectLink = 'guest-tracking.php';
     } else {
         $redirectLink = 'history.php';
     }
     $this->id_module = (int) Tools::getValue('id_module', 0);
     $this->id_order = Order::getOrderByCartId((int) $this->id_cart);
     $this->secure_key = Tools::getValue('key', false);
     if (!$this->id_order or !$this->id_module or !$this->secure_key or empty($this->secure_key)) {
         Tools::redirect($redirectLink . (Tools::isSubmit('slowvalidation') ? '?slowvalidation' : ''));
     }
     $order = new Order((int) $this->id_order);
     if (!Validate::isLoadedObject($order) or $order->id_customer != self::$cookie->id_customer or $this->secure_key != $order->secure_key) {
         Tools::redirect($redirectLink);
     }
     $module = Module::getInstanceById((int) $this->id_module);
     if ($order->payment != $module->displayName) {
         Tools::redirect($redirectLink);
     }
 }
Example #4
0
    public function renderForm($data)
    {
        $helper = $this->getFormHelper();
        $id_shop = Context::getContext()->shop->id;
        if (isset($data['params']['hookmodule'])) {
            $hid = Hook::getIdByName($data['params']['hookmodule']);
            if ($hid) {
                $hms = Hook::getModulesFromHook($hid);
                foreach ($hms as $hm) {
                    if ($data['params']['loadmodule'] == $hm['name']) {
                        $id_module = $hm['id_module'];
                        $module = Module::getInstanceById($id_module);
                        if (Validate::isLoadedObject($module)) {
                            !$module->unregisterHook((int) $hid, array($id_shop));
                        }
                    }
                }
            }
        }
        $modules = Module::getModulesInstalled(0);
        $output = array();
        $hooks = array('displayHome', 'displayLeftColumn', 'displayRightColumn', 'displayTop', 'displayHeaderRight', 'displaySlideshow', 'topNavigation', 'displayMainmenu', 'displayPromoteTop', 'displayRightColumn', 'displayLeftColumn', 'displayHome', 'displayFooter', 'displayBottom', 'displayContentBottom', 'displayFootNav', 'displayFooterTop', 'displayMapLocal', 'displayFooterBottom');
        foreach ($hooks as $hook) {
            $output[] = array('name' => $hook, 'id' => $hook);
        }
        $this->fields_form[1]['form'] = array('legend' => array('title' => $this->l('Widget Form.')), 'input' => array(array('type' => 'select', 'label' => $this->l('Select A Module'), 'name' => 'loadmodule', 'options' => array('query' => $modules, 'id' => 'name', 'name' => 'name'), 'default' => '1', 'desc' => $this->l('Select A Module is used as widget. the hook of this module was unhooked.')), array('type' => 'select', 'label' => $this->l('Select A Hook'), 'name' => 'hookmodule', 'options' => array('query' => $output, 'id' => 'name', 'name' => 'name'), 'default' => '1', 'desc' => $this->l('Select A hook is used to render module\'s content. the hook of this module was unhooked. 
						You could not rollback it\'s position. So you need asign it in position management of prestashop.'))), 'submit' => array('title' => $this->l('Save'), 'class' => 'button'));
        $default_lang = (int) Configuration::get('PS_LANG_DEFAULT');
        $a = $this->getConfigFieldsValues($data);
        $helper->tpl_vars = array('fields_value' => $a, 'languages' => Context::getContext()->controller->getLanguages(), 'id_language' => $default_lang);
        return $helper->generateForm($this->fields_form);
    }
 /**
  * Initialize order confirmation controller
  * @see FrontController::init()
  */
 public function init()
 {
     parent::init();
     if (isset($this->context->cookie->{'url_confirmation'})) {
         unset($this->context->cookie->{'url_confirmation'});
     }
     $this->id_cart = (int) Tools::getValue('id_cart', 0);
     $is_guest = false;
     /* check if the cart has been made by a Guest customer, for redirect link */
     if (Cart::isGuestCartByCartId($this->id_cart)) {
         $is_guest = true;
         $redirectLink = 'index.php?controller=guest-tracking';
     } else {
         $redirectLink = 'index.php?controller=history';
     }
     $this->id_module = (int) Tools::getValue('id_module', 0);
     $this->id_order = Order::getOrderByCartId((int) $this->id_cart);
     $this->secure_key = Tools::getValue('key', false);
     $order = new Order((int) $this->id_order);
     if ($is_guest) {
         $customer = new Customer((int) $order->id_customer);
         $redirectLink .= '&id_order=' . $order->reference . '&email=' . urlencode($customer->email);
     }
     if (!$this->id_order || !$this->id_module || !$this->secure_key || empty($this->secure_key)) {
         Tools::redirect($redirectLink . (Tools::isSubmit('slowvalidation') ? '&slowvalidation' : ''));
     }
     $this->reference = $order->reference;
     if (!Validate::isLoadedObject($order) || $order->id_customer != $this->context->customer->id || $this->secure_key != $order->secure_key) {
         Tools::redirect($redirectLink);
     }
     $module = Module::getInstanceById((int) $this->id_module);
     if (isset($order->payment) && isset($module->displayName) && $order->payment != $module->displayName && !in_array($order->payment, $this->get_mediosp())) {
         Tools::redirect($redirectLink);
     }
     $url_banco2 = Tools::getValue('bankdest2', 0);
     $url_dec_64 = base64_decode(strtr($url_banco2, '-_,', '+/='));
     if ($url_banco2 != false) {
         $this->url_banco = $url_dec_64;
         Tools::redirect($this->url_banco);
     }
     $URL_PAYMENT_RECEIPT_HTML = Tools::getValue('URL_PAYMENT_RECEIPT_HTML', 0);
     $url_iframe = base64_decode(strtr($URL_PAYMENT_RECEIPT_HTML, '-_,', '+/='));
     if ($URL_PAYMENT_RECEIPT_HTML != false) {
         $this->url_iframe = $url_iframe;
     }
 }
    /**
     * AdminController::renderForm() override
     * @see AdminController::renderForm()
     */
    public function renderForm()
    {
        $current_profile = (int) $this->getCurrentProfileId();
        $profiles = Profile::getProfiles($this->context->language->id);
        $tabs = Tab::getTabs($this->context->language->id);
        $accesses = array();
        foreach ($profiles as $profile) {
            $accesses[$profile['id_profile']] = Profile::getProfileAccesses($profile['id_profile']);
        }
        // Deleted id_tab that do not have access
        foreach ($tabs as $key => $tab) {
            // Don't allow permissions for unnamed tabs (ie. AdminLogin)
            if (empty($tab['name'])) {
                unset($tabs[$key]);
            }
            foreach ($this->accesses_black_list as $id_tab) {
                if ($tab['id_tab'] == (int) $id_tab) {
                    unset($tabs[$key]);
                }
            }
        }
        $modules = array();
        foreach ($profiles as $profile) {
            $modules[$profile['id_profile']] = Db::getInstance(_PS_USE_SQL_SLAVE_)->executeS('
				SELECT ma.`id_module`, m.`name`, ma.`view`, ma.`configure`, ma.`uninstall`
				FROM ' . _DB_PREFIX_ . 'module_access ma
				LEFT JOIN ' . _DB_PREFIX_ . 'module m
					ON ma.id_module = m.id_module
				WHERE id_profile = ' . (int) $profile['id_profile'] . '
				ORDER BY m.name
			');
            foreach ($modules[$profile['id_profile']] as $k => &$module) {
                $m = Module::getInstanceById($module['id_module']);
                // the following condition handles invalid modules
                if ($m) {
                    $module['name'] = $m->displayName;
                } else {
                    unset($modules[$profile['id_profile']][$k]);
                }
            }
            uasort($modules[$profile['id_profile']], array($this, 'sortModuleByName'));
        }
        $this->fields_form = array('');
        $this->tpl_form_vars = array('profiles' => $profiles, 'accesses' => $accesses, 'id_tab_parentmodule' => (int) Tab::getIdFromClassName('AdminParentModules'), 'id_tab_module' => (int) Tab::getIdFromClassName('AdminModules'), 'tabs' => $tabs, 'current_profile' => (int) $current_profile, 'admin_profile' => (int) _PS_ADMIN_PROFILE_, 'access_edit' => $this->tabAccess['edit'], 'perms' => array('view', 'add', 'edit', 'delete'), 'modules' => $modules, 'link' => $this->context->link);
        return parent::renderForm();
    }
 protected function runModulesCrons()
 {
     $query = 'SELECT * FROM ' . _DB_PREFIX_ . $this->module->name . ' WHERE `active` = 1 AND `id_module` IS NOT NULL';
     $crons = Db::getInstance()->executeS($query);
     if (is_array($crons) && count($crons) > 0) {
         foreach ($crons as &$cron) {
             $module = Module::getInstanceById((int) $cron['id_module']);
             if ($module == false) {
                 Db::getInstance()->execute('DELETE FROM ' . _DB_PREFIX_ . $this->name . ' WHERE `id_cronjob` = \'' . (int) $cron['id_cronjob'] . '\'');
                 break;
             } elseif ($this->shouldBeExecuted($cron) == true) {
                 Hook::exec('actionCronJob', array(), $cron['id_module']);
                 $query = 'UPDATE ' . _DB_PREFIX_ . $this->module->name . ' SET `updated_at` = NOW(), `active` = IF (`one_shot` = TRUE, FALSE, `active`) WHERE `id_cronjob` = \'' . $cron['id_cronjob'] . '\'';
                 Db::getInstance()->execute($query);
             }
         }
     }
 }
 /**
  * Initialize order confirmation controller.
  *
  * @see FrontController::init()
  */
 public function init()
 {
     parent::init();
     $this->id_cart = (int) Tools::getValue('id_cart', 0);
     $redirectLink = 'index.php?controller=history';
     $this->id_module = (int) Tools::getValue('id_module', 0);
     $this->id_order = Order::getOrderByCartId((int) $this->id_cart);
     $this->secure_key = Tools::getValue('key', false);
     $order = new Order((int) $this->id_order);
     if (!$this->id_order || !$this->id_module || !$this->secure_key || empty($this->secure_key)) {
         Tools::redirect($redirectLink . (Tools::isSubmit('slowvalidation') ? '&slowvalidation' : ''));
     }
     $this->reference = $order->reference;
     if (!Validate::isLoadedObject($order) || $order->id_customer != $this->context->customer->id || $this->secure_key != $order->secure_key) {
         Tools::redirect($redirectLink);
     }
     $module = Module::getInstanceById((int) $this->id_module);
     if ($order->module != $module->name) {
         Tools::redirect($redirectLink);
     }
     $this->order_presenter = new OrderPresenter();
 }
Example #9
0
 public static function getModuleArrFromBackuptbl($id_hook, $getshop = false)
 {
     $modulesArr = array();
     $modules = Db::getInstance()->ExecuteS('
             SELECT *
             FROM `' . _DB_PREFIX_ . 'ovic_backup_hook_module`
             WHERE `id_hook` = ' . (int) $id_hook);
     $hookname = Hook::getNameById($id_hook);
     if ($modules && count($modules) > 0) {
         foreach ($modules as $module) {
             $moduleObject = Module::getInstanceById((int) $module['id_module']);
             if (!is_object($moduleObject) || !Validate::isModuleName($moduleObject->name)) {
                 continue;
             }
             $moduleHook = array();
             $moduleHook[] = $moduleObject->name;
             $moduleHook[] = $hookname;
             if ($getshop) {
                 $modulesArr[$module['id_shop']][] = $moduleHook;
             } else {
                 $modulesArr[] = $moduleHook;
             }
         }
     }
     return $modulesArr;
 }
Example #10
0
     CartRule::autoAddToCart($context);
     if (!$context->cart->isMultiAddressDelivery()) {
         $context->cart->setNoMultishipping();
     }
 } else {
     $message = new Message();
     $message->id_cart = $cart->id;
     $message->message = 'Имя:' . ' ' . Tools::getValue('firstname') . "\r\n" . 'Эл.адрес:' . ' default@default.ru' . "\r\n" . 'Телефон:' . ' ' . Tools::getValue('phone') . "\r\n" . 'Время:	 ' . Tools::getValue('time');
     $message->private = true;
     $message->add();
 }
 if (Configuration::get('QUI_CARRIER')) {
     $cart->id_carrier = Configuration::get('QUI_CARRIER');
 }
 if (Configuration::get('QUI_PAYMENT')) {
     $payment = Module::getInstanceById(Configuration::get('QUI_PAYMENT'));
 }
 $cart->id_customer = (int) $customer->id;
 $cookie->id_customer = (int) $customer->id;
 $cookie->update();
 if (Tools::getValue('comment')) {
     $message = new Message();
     $message->id_cart = $cart->id;
     $message->message = 'Комментарий:' . ' ' . Tools::getValue('comment');
     $message->private = true;
     $message->add();
 }
 $cart->update();
 $total = $cart->getOrderTotal(true, Cart::BOTH);
 $order = new QuickOrderCreate();
 if (Configuration::get('QUI_PAYMENT')) {
 /**
  * returns the payment modules list as an array indexed by module_id and containing the module name and the corresponding fia-net payment type
  * 
  * @return array
  */
 private function loadPaymentMethods()
 {
     if (_PS_VERSION_ < '1.5') {
         $payments = $this->getInstalledPaymentModules();
     } else {
         $payments = PaymentModule::getPaymentModules();
     }
     $payment_modules = array();
     foreach ($payments as $payment) {
         $module = Module::getInstanceById($payment['id_module']);
         //reloads submitted values if exists, loads conf otherwise
         $certissim_type = Tools::isSubmit('certissim_' . $module->id . '_payment_type') ? Tools::getValue('certissim_' . $module->id . '_payment_type') : Configuration::get('CERTISSIM_' . $module->id . '_PAYMENT_TYPE');
         $certissim_enabled = Tools::isSubmit('certissim_' . $module->id . '_payment_enabled') ? Tools::getValue('certissim_' . $module->id . '_payment_enabled') : Configuration::get('CERTISSIM_' . $module->id . '_PAYMENT_ENABLED');
         $payment_modules[$module->id] = array('name' => $module->displayName, 'certissim_type' => $certissim_type, 'enabled' => $certissim_enabled);
     }
     return $payment_modules;
 }
Example #12
0
 public function execModuleHook($hook_name, $hook_args = array(), $id_module = null, $id_shop = null)
 {
     // Check arguments validity
     if ($id_module && !is_numeric($id_module) || !Validate::isHookName($hook_name)) {
         throw new PrestaShopException('Invalid id_module or hook_name');
     }
     // Check if hook exists
     if (!($id_hook = Hook::getIdByName($hook_name))) {
         return false;
     }
     // Store list of executed hooks on this page
     Hook::$executed_hooks[$id_hook] = $hook_name;
     $live_edit = false;
     $context = Context::getContext();
     if (!isset($hook_args['cookie']) || !$hook_args['cookie']) {
         $hook_args['cookie'] = $context->cookie;
     }
     if (!isset($hook_args['cart']) || !$hook_args['cart']) {
         $hook_args['cart'] = $context->cart;
     }
     $retro_hook_name = Hook::getRetroHookName($hook_name);
     // Look on modules list
     $altern = 0;
     $output = '';
     $different_shop = false;
     if ($id_shop !== null && Validate::isUnsignedId($id_shop) && $id_shop != $context->shop->getContextShopID()) {
         $old_context_shop_id = $context->shop->getContextShopID();
         $old_context = $context->shop->getContext();
         $old_shop = clone $context->shop;
         $shop = new Shop((int) $id_shop);
         if (Validate::isLoadedObject($shop)) {
             $context->shop = $shop;
             $context->shop->setContext(Shop::CONTEXT_SHOP, $shop->id);
             $different_shop = true;
         }
     }
     if (!($moduleInstance = Module::getInstanceById($id_module))) {
         continue;
     }
     // Check which / if method is callable
     $hook_callable = is_callable(array($moduleInstance, 'hook' . $hook_name));
     $hook_retro_callable = is_callable(array($moduleInstance, 'hook' . $retro_hook_name));
     if (($hook_callable || $hook_retro_callable) && Module::preCall($moduleInstance->name)) {
         $hook_args['altern'] = ++$altern;
         // Call hook method
         if ($hook_callable) {
             $display = $moduleInstance->{'hook' . $hook_name}($hook_args);
         } elseif ($hook_retro_callable) {
             $display = $moduleInstance->{'hook' . $retro_hook_name}($hook_args);
         }
         $output .= $display;
     }
     if ($different_shop) {
         $context->shop = $old_shop;
         $context->shop->setContext($old_context, $shop->id);
     }
     return $output;
 }
Example #13
0
    $import = new AdminImport();
    $languages = Language::getLanguages(false);
    $defaultLanguage = (int) Configuration::get('PS_LANG_DEFAULT');
    $fields = $import->getAvailableFields(true);
    foreach ($fields as $field) {
        $jsonArray[] = '{"field":"' . addslashes($field) . '"}';
    }
    die('[' . implode(',', $jsonArray) . ']');
}
if (array_key_exists('ajaxModulesPositions', $_POST)) {
    $id_module = (int) Tools::getValue('id_module');
    $id_hook = (int) Tools::getValue('id_hook');
    $way = (int) Tools::getValue('way');
    $positions = Tools::getValue(strval($id_hook));
    $position = is_array($positions) ? array_search($id_hook . '_' . $id_module, $positions) : null;
    $module = Module::getInstanceById($id_module);
    if (Validate::isLoadedObject($module)) {
        if ($module->updatePosition($id_hook, $way, $position)) {
            die(true);
        } else {
            die('{"hasError" : true, "errors" : "Can not update module position"}');
        }
    } else {
        die('{"hasError" : true, "errors" : "This module can not be loaded"}');
    }
}
if (array_key_exists('ajaxCategoriesPositions', $_POST)) {
    $id_category_to_move = (int) Tools::getValue('id_category_to_move');
    $id_category_parent = (int) Tools::getValue('id_category_parent');
    $way = (int) Tools::getValue('way');
    $positions = Tools::getValue('category');
 /**
  * Change hook execute off module
  */
 public function ajaxProcessChangeModuleHook()
 {
     $result = array();
     $pagemeta = Tools::getValue('pagemeta');
     $hookcolumn = Tools::getValue('hookcolumn');
     $id_hookexec = (int) Tools::getValue('id_hookexec');
     $hookexec_name = Hook::getNameById($id_hookexec);
     $old_hook = (int) Tools::getValue('old_hook');
     $id_module = (int) Tools::getValue('id_module');
     if ($id_module && Validate::isUnsignedId($id_module) && $hookexec_name && Validate::isHookName($hookexec_name)) {
         $result['status'] = true;
         $moduleObject = Module::getInstanceById($id_module);
         $HookedModulesArr = OvicLayoutControl::getSideBarModulesByPage($pagemeta, $hookcolumn, false);
         if (!is_array($HookedModulesArr)) {
             $result['status'] = false;
         }
         if ($result['status']) {
             $moduleHook = array();
             $moduleHook[] = $moduleObject->name;
             $moduleHook[] = Hook::getNameById($old_hook);
             $key = array_search($moduleHook, $HookedModulesArr);
             if (array_key_exists($key, $HookedModulesArr)) {
                 $moduleHook[1] = $hookexec_name;
                 $HookedModulesArr[$key] = $moduleHook;
                 $result['status'] = OvicLayoutControl::registerSidebarModule($pagemeta, $hookcolumn, Tools::jsonEncode($HookedModulesArr), $this->context->shop->id);
                 $result['moduleinfo'] = $moduleObject->name . '-' . $hookexec_name;
             }
         }
     }
     Tools::clearCache();
     die(Tools::jsonEncode($result));
 }
Example #15
0
    foreach (${${"GLOBALS"}["nctaytx"]} as ${${"GLOBALS"}["vniipdyl"]}) {
        ${${"GLOBALS"}["fbrxiprf"]}[] = "{\"field\":\"" . addslashes(${${"GLOBALS"}["wrpesthj"]}) . "\"}";
    }
    die("[" . implode(",", ${${"GLOBALS"}["rrcmgcgvzw"]}) . "]");
}
if (Tools::isSubmit("ajaxModulesPositions")) {
    ${"GLOBALS"}["gmoqyrjz"] = "positions";
    $znwojiwbe = "id_hook";
    ${${"GLOBALS"}["uhohwmowndl"]} = (int) Tools::getValue("id_module");
    ${$znwojiwbe} = (int) Tools::getValue("id_hook");
    ${"GLOBALS"}["dejbhwrjngdx"] = "positions";
    ${${"GLOBALS"}["bexdhpfik"]} = (int) Tools::getValue("way");
    ${"GLOBALS"}["ddwciizou"] = "id_hook";
    ${${"GLOBALS"}["dejbhwrjngdx"]} = Tools::getValue(strval(${${"GLOBALS"}["ddwciizou"]}));
    ${${"GLOBALS"}["iggxtsqn"]} = is_array(${${"GLOBALS"}["gmoqyrjz"]}) ? array_search(${${"GLOBALS"}["acmlhwatnv"]} . "_" . ${${"GLOBALS"}["uhohwmowndl"]}, ${${"GLOBALS"}["ejncxgwa"]}) : null;
    ${${"GLOBALS"}["cqfemfj"]} = Module::getInstanceById(${${"GLOBALS"}["uhohwmowndl"]});
    if (Validate::isLoadedObject(${${"GLOBALS"}["cqfemfj"]})) {
        ${"GLOBALS"}["eopzpuoncab"] = "way";
        ${"GLOBALS"}["htfgqds"] = "position";
        $bucidyjuwc = "id_hook";
        if ($module->updatePosition(${$bucidyjuwc}, ${${"GLOBALS"}["eopzpuoncab"]}, ${${"GLOBALS"}["htfgqds"]})) {
            die(true);
        } else {
            die("{\"hasError\" : true, \"errors\" : \"Can not update module position\"}");
        }
    } else {
        die("{\"hasError\" : true, \"errors\" : \"This module can not be loaded\"}");
    }
}
if (Tools::isSubmit("ajaxCategoriesPositions")) {
    ${"GLOBALS"}["moopdjenwj"] = "id_category_parent";
Example #16
0
 /**
  * execute cron jobs
  * invalide job will be deleted
  *
  * @return void
  **/
 public function runJobs()
 {
     if ($this->active && Configuration::get('cron_lasttime') + 60 <= time()) {
         Configuration::updateValue('cron_lasttime', time());
         require_once dirname(__FILE__) . '/CronParser.php';
         $cronParser = new CronParser();
         // get the jobs
         $sql = 'SELECT * FROM `' . _DB_PREFIX_ . 'cron`';
         $crons = Db::getInstance()->executeS($sql);
         foreach ($crons as $cron) {
             // When the job should have been executed for the last time ?
             // if it's in the past execute it
             $cronParser->calcLastRan($cron['mhdmd']);
             var_dump($cron['mhdmd'], date('r', $cronParser->getLastRanUnix()), date('r', $cron['last_execution']));
             if ($cronParser->getLastRanUnix() > $cron['last_execution']) {
                 // if module doesn't exists delete job
                 if (!($module = Module::getInstanceById($cron['id_module']))) {
                     $this->deleteCron($cron['id_module'], $cron['method']);
                 } else {
                     $classMethods = array_map('strtolower', get_class_methods($module));
                     // if method doesn't exists delete job
                     if (!$classMethods || !in_array(strtolower($cron['method']), $classMethods)) {
                         $this->deleteCron($cron['id_module'], $cron['method']);
                     } else {
                         $values = array('last_execution' => time());
                         Db::getInstance()->autoExecute(_DB_PREFIX_ . 'cron', $values, 'UPDATE', 'id_cron = ' . $cron['id_cron']);
                         // run job TODO: make it asynchronous
                         call_user_func(array($module, $cron['method']));
                     }
                 }
             }
         }
         // get the url to visit
         $sql = 'SELECT * FROM `' . _DB_PREFIX_ . 'cron_url`';
         $crons = Db::getInstance()->executeS($sql);
         foreach ($crons as $cron) {
             // When the job should have been executed for the last time ?
             // if it's in the past execute it
             $cronParser->calcLastRan($cron['mhdmd']);
             if ($cronParser->getLastRanUnix() > $cron['last_execution']) {
                 $values = array('last_execution' => time());
                 Db::getInstance()->autoExecute(_DB_PREFIX_ . 'cron_url', $values, 'UPDATE', 'id_cron_url = ' . $cron['id_cron_url']);
                 // run job TODO: make it asynchronous
                 @file_get_contents($cron['url']);
             }
         }
     }
 }
Example #17
0
 public static function getTasksListValues()
 {
     $id_shop = (int) Context::getContext()->shop->id;
     $id_shop_group = (int) Context::getContext()->shop->id_shop_group;
     self::$module->addNewModulesTasks();
     $crons = Db::getInstance()->executeS('SELECT * FROM `' . _DB_PREFIX_ . self::$module->name . '` WHERE `id_shop` = \'' . $id_shop . '\' AND `id_shop_group` = \'' . $id_shop_group . '\'');
     foreach ($crons as $key => &$cron) {
         if (empty($cron['id_module']) == false) {
             $module = Module::getInstanceById((int) $cron['id_module']);
             if ($module == false) {
                 Db::getInstance()->execute('DELETE FROM ' . _DB_PREFIX_ . self::$module->name . ' WHERE `id_cronjob` = \'' . (int) $cron['id_cronjob'] . '\'');
                 unset($crons[$key]);
                 break;
             }
             $query = 'SELECT `name` FROM `' . _DB_PREFIX_ . 'module` WHERE `id_module` = \'' . (int) $cron['id_module'] . '\'';
             $module_name = Db::getInstance()->getValue($query);
             $cron['description'] = Tools::safeOutput(Module::getModuleName($module_name));
             $cron['task'] = self::$module->l('Module - Hook', 'CronJobsForms');
         } else {
             $cron['task'] = Tools::safeOutput(urldecode($cron['task']));
         }
         $cron['hour'] = $cron['hour'] == -1 ? self::$module->l('Every hour', 'CronJobsForms') : date('H:i', mktime((int) $cron['hour'], 0, 0, 0, 1));
         $cron['day'] = $cron['day'] == -1 ? self::$module->l('Every day', 'CronJobsForms') : (int) $cron['day'];
         $cron['month'] = $cron['month'] == -1 ? self::$module->l('Every month', 'CronJobsForms') : self::$module->l(date('F', mktime(0, 0, 0, (int) $cron['month'], 1)));
         $cron['day_of_week'] = $cron['day_of_week'] == -1 ? self::$module->l('Every day of the week', 'CronJobsForms') : self::$module->l(date('l', mktime(0, 0, 0, 0, (int) $cron['day_of_week'])));
         $cron['updated_at'] = $cron['updated_at'] == 0 ? self::$module->l('Never', 'CronJobsForms') : date('Y-m-d H:i:s', strtotime($cron['updated_at']));
         $cron['one_shot'] = (bool) $cron['one_shot'];
         $cron['active'] = (bool) $cron['active'];
     }
     return $crons;
 }
 public function ajaxProcessChangePaymentMethod()
 {
     $customer = new Customer(Tools::getValue('id_customer'));
     $modules = Module::getAuthorizedModules($customer->id_default_group);
     $authorized_modules = array();
     if (!Validate::isLoadedObject($customer) || !is_array($modules)) {
         die(Tools::jsonEncode(array('result' => false)));
     }
     foreach ($modules as $module) {
         $authorized_modules[] = (int) $module['id_module'];
     }
     $payment_modules = array();
     foreach (PaymentModule::getInstalledPaymentModules() as $p_module) {
         if (in_array((int) $p_module['id_module'], $authorized_modules)) {
             $payment_modules[] = Module::getInstanceById((int) $p_module['id_module']);
         }
     }
     $this->context->smarty->assign(array('payment_modules' => $payment_modules));
     die(Tools::jsonEncode(array('result' => true, 'view' => $this->createTemplate('_select_payment.tpl')->fetch())));
 }
 public function formatModuleListAuth($id_group)
 {
     $modules = Module::getModulesInstalled();
     $authorized_modules = '';
     $auth_modules = array();
     $unauth_modules = array();
     if ($id_group) {
         $authorized_modules = Module::getAuthorizedModules($id_group);
     }
     if (is_array($authorized_modules)) {
         foreach ($modules as $module) {
             $authorized = false;
             foreach ($authorized_modules as $auth_module) {
                 if ($module['id_module'] == $auth_module['id_module']) {
                     $authorized = true;
                 }
             }
             if ($authorized) {
                 $auth_modules[] = $module;
             } else {
                 $unauth_modules[] = $module;
             }
         }
     } else {
         $auth_modules = $modules;
     }
     $auth_modules_tmp = array();
     foreach ($auth_modules as $key => $val) {
         if ($module = Module::getInstanceById($val['id_module'])) {
             $auth_modules_tmp[] = $module;
         }
     }
     $auth_modules = $auth_modules_tmp;
     $unauth_modules_tmp = array();
     foreach ($unauth_modules as $key => $val) {
         if ($tmp_obj = Module::getInstanceById($val['id_module'])) {
             $unauth_modules_tmp[] = $tmp_obj;
         }
     }
     $unauth_modules = $unauth_modules_tmp;
     return array('unauth_modules' => $unauth_modules, 'auth_modules' => $auth_modules);
 }
<?php

/* SSL Management */
$useSSL = true;
include dirname(__FILE__) . '/config/config.inc.php';
include dirname(__FILE__) . '/header.php';
$id_cart = intval(Tools::getValue('id_cart', 0));
$id_module = intval(Tools::getValue('id_module', 0));
$id_order = Order::getOrderByCartId(intval($id_cart));
$secure_key = isset($_GET['key']) ? $_GET['key'] : false;
if (!$id_order or !$id_module or !$secure_key or empty($secure_key)) {
    Tools::redirect('history.php');
}
$order = new Order(intval($id_order));
if (!Validate::isLoadedObject($order) or $order->id_customer != $cookie->id_customer or $secure_key != $order->secure_key) {
    Tools::redirect('history.php');
}
$module = Module::getInstanceById(intval($id_module));
if ($order->payment != $module->displayName) {
    Tools::redirect('history.php');
}
$smarty->assign(array('HOOK_ORDER_CONFIRMATION' => Hook::orderConfirmation(intval($id_order)), 'HOOK_PAYMENT_RETURN' => Hook::paymentReturn(intval($id_order), intval($id_module))));
$smarty->display(_PS_THEME_DIR_ . 'order-confirmation.tpl');
include dirname(__FILE__) . '/footer.php';
 /**
  * Change hook execute off module
  */
 public function ajaxProcessChangeModuleHook()
 {
     $result = array();
     $id_hook = (int) Tools::getValue('id_hook');
     $hookname = Hook::getNameById($id_hook);
     $id_option = (int) Tools::getValue('id_option');
     $option = new Options($id_option);
     $id_hookexec = (int) Tools::getValue('id_hookexec');
     $hookexec_name = Hook::getNameById($id_hookexec);
     $old_hook = (int) Tools::getValue('old_hook');
     $id_module = (int) Tools::getValue('id_module');
     if ($option && Validate::isLoadedObject($option) && $id_module && Validate::isUnsignedId($id_module) && $hookname && Validate::isHookName($hookname) && $hookexec_name && Validate::isHookName($hookexec_name)) {
         $result['status'] = true;
         $moduleObject = Module::getInstanceById($id_module);
         $HookedModulesArr = OvicLayoutControl::getModulesHook($option->theme, $option->alias, $hookname);
         $HookedModulesArr = Tools::jsonDecode($HookedModulesArr['modules'], true);
         if (!is_array($HookedModulesArr)) {
             $result['status'] = false;
         }
         if ($result['status']) {
             $moduleHook = array();
             $moduleHook[] = $moduleObject->name;
             $moduleHook[] = Hook::getNameById($old_hook);
             $key = array_search($moduleHook, $HookedModulesArr);
             $result['test'] = $key;
             if (array_key_exists($key, $HookedModulesArr)) {
                 $moduleHook[1] = $hookexec_name;
                 $HookedModulesArr[$key] = $moduleHook;
                 $result['status'] = OvicLayoutControl::registerHookModule($option, $hookname, Tools::jsonEncode($HookedModulesArr), $this->context->shop->id);
                 $result['moduleinfo'] = $moduleObject->name . '-' . $hookexec_name;
             }
         }
     }
     die(Tools::jsonEncode($result));
 }
 /**
  * remove a module from a hook
  */
 public function ajaxProcessremoveModuleHook()
 {
     $result = array();
     $hookname = Tools::getValue('hookname');
     $id_option = (int) Tools::getValue('id_option');
     $id_hookexec = (int) Tools::getValue('id_hookexec');
     $hookexec_name = Hook::getNameById($id_hookexec);
     $id_module = (int) Tools::getValue('id_module');
     if ($id_module && Validate::isUnsignedId($id_module) && $hookname && Validate::isHookName($hookname) && $hookexec_name && Validate::isHookName($hookexec_name)) {
         $moduleObject = Module::getInstanceById($id_module);
         $HookedModulesArr = OvicLayoutControl::getModulesHook($id_option, $hookname);
         $HookedModulesArr = Tools::jsonDecode($HookedModulesArr['modules'], true);
         $HookedModulesArr = array_values($HookedModulesArr);
         $moduleHook = array();
         $moduleHook[] = $moduleObject->name;
         $moduleHook[] = $hookexec_name;
         if ($HookedModulesArr && is_array($HookedModulesArr) && sizeof($HookedModulesArr)) {
             $key = array_search($moduleHook, $HookedModulesArr);
             unset($HookedModulesArr[$key]);
         }
         $HookedModulesArr = array_values($HookedModulesArr);
         $result['status'] = OvicLayoutControl::registerHookModule($id_option, $hookname, Tools::jsonEncode($HookedModulesArr), $this->context->shop->id);
         $result['msg'] = $this->l('Successful deletion');
         //$this->displayError
     }
     Tools::clearCache();
     die(Tools::jsonEncode($result));
 }
 public function ajaxProcessUpdatePositions()
 {
     if ($this->tabAccess['edit'] === '1') {
         $id_module = (int) Tools::getValue('id_module');
         $id_hook = (int) Tools::getValue('id_hook');
         $way = (int) Tools::getValue('way');
         $positions = Tools::getValue(strval($id_hook));
         $position = is_array($positions) ? array_search($id_hook . '_' . $id_module, $positions) : null;
         $module = Module::getInstanceById($id_module);
         if (Validate::isLoadedObject($module)) {
             if ($module->updatePosition($id_hook, $way, $position)) {
                 die(true);
             } else {
                 die('{"hasError" : true, "errors" : "Can not update module position"}');
             }
         } else {
             die('{"hasError" : true, "errors" : "This module can not be loaded"}');
         }
     }
 }
 /**
  * Return a json array containing the possible hooks for a module.
  *
  * @return null
  */
 public function ajaxProcessGetPossibleHookingListForModule()
 {
     $module_id = (int) Tools::getValue('module_id');
     if ($module_id == 0) {
         die('{"hasError" : true, "errors" : ["Wrong module ID."]}');
     }
     $module_instance = Module::getInstanceById($module_id);
     die(json_encode($module_instance->getPossibleHooksList()));
 }
Example #25
0
    public function displayForm()
    {
        global $currentIndex;
        $id_module = intval(Tools::getValue('id_module'));
        $id_hook = intval(Tools::getValue('id_hook'));
        if ($id_module and $id_hook and Tools::isSubmit('editGraft')) {
            $slModule = Module::getInstanceById($id_module);
            $exceptsList = $slModule->getExceptions($id_hook);
            $excepts = '';
            foreach ($exceptsList as $key => $except) {
                $excepts .= ($key ? ',' : '') . $except['file_name'];
            }
        }
        $excepts = strval(Tools::getValue('exceptions', (isset($slModule) and Validate::isLoadedObject($slModule)) ? $excepts : ''));
        $modules = Module::getModulesInstalled(0);
        $instances = array();
        foreach ($modules as $module) {
            if ($tmpInstance = Module::getInstanceById($module['id_module'])) {
                $instances[$tmpInstance->displayName] = $tmpInstance;
            }
        }
        ksort($instances);
        $modules = $instances;
        $hooks = Hook::getHooks(0);
        echo '
		<form action="' . $currentIndex . '&token=' . $this->token . '" method="post">';
        if ($this->displayKey) {
            echo '<input type="hidden" name="show_modules" value="' . $this->displayKey . '" />';
        }
        echo '<fieldset class="width3" style="width:700px;"><legend><img src="../img/t/AdminModulesPositions.gif" />' . $this->l('Transplant a module') . '</legend>
				<label>' . $this->l('Module') . ' :</label>
				<div class="margin-form">
					<select name="id_module"' . (Tools::isSubmit('editGraft') ? ' disabled="disabled"' : '') . '>';
        foreach ($modules as $module) {
            echo '
						<option value="' . $module->id . '" ' . ($id_module == $module->id ? 'selected="selected" ' : '') . '>' . stripslashes($module->displayName) . '</option>';
        }
        echo '
					</select><sup> *</sup>
				</div>
				<label>' . $this->l('Hook into') . ' :</label>
				<div class="margin-form">
					<select name="id_hook"' . (Tools::isSubmit('editGraft') ? ' disabled="disabled"' : '') . '>';
        foreach ($hooks as $hook) {
            echo '
						<option value="' . $hook['id_hook'] . '" ' . ($id_hook == $hook['id_hook'] ? 'selected="selected" ' : '') . '>' . $hook['title'] . '</option>';
        }
        echo '
					</select><sup> *</sup>
				</div>
				<label>' . $this->l('Exceptions') . ' :</label>
				<div class="margin-form">
					<input type="text" name="exceptions" size="40" ' . (!empty($excepts) ? 'value="' . $excepts . '"' : '') . '><br />Ex: identity.php, history.php, order.php, product.php<br /><br />
					' . $this->l('Please specify those files in which you do not want the module to be displayed') . '.<br />
					' . $this->l('These files are located in your base directory') . ', ' . $this->l('e.g., ') . ' <b>identity.php</b>.<br />
					' . $this->l('Please type each filename separated by a comma') . '.
					<br /><br />
				</div>
				<div class="margin-form">
				';
        if (Tools::isSubmit('editGraft')) {
            echo '
					<input type="hidden" name="id_module" value="' . $id_module . '" />
					<input type="hidden" name="id_hook" value="' . $id_hook . '" />';
        }
        echo '
					<input type="submit" value="' . $this->l('Save') . '" name="' . (Tools::isSubmit('editGraft') ? 'submitEditGraft' : 'submitAddToHook') . '" class="button" />
				</div>
				<div class="small"><sup>*</sup> ' . $this->l('Required field') . '</div>
			</fieldset>
		</form>';
    }
 public function ajaxProcessChangePaymentMethod()
 {
     $id_customer = Tools::getValue('id_customer');
     $customer = new Customer(Tools::getValue('id_customer'));
     $this->context->customer = $customer;
     //by webkul code to add id_customer in cart table
     $this->context->customer = new Customer($id_customer);
     if ($id_customer) {
         // setting data in the cart set from book now page by webkul
         $this->context->cart = new Cart(Tools::getValue('id_cart'));
         $this->context->cart->id_customer = $id_customer;
         /*if (Validate::isLoadedObject($this->context->cart) && $this->context->cart->OrderExists())
         		return;*/
         if (!$this->context->cart->secure_key) {
             $this->context->cart->secure_key = $this->context->customer->secure_key;
         }
         if (!$this->context->cart->id_shop) {
             $this->context->cart->id_shop = (int) $this->context->shop->id;
         }
         if (!$this->context->cart->id_lang) {
             $this->context->cart->id_lang = ($id_lang = (int) Tools::getValue('id_lang')) ? $id_lang : Configuration::get('PS_LANG_DEFAULT');
         }
         if (!$this->context->cart->id_currency) {
             $this->context->cart->id_currency = ($id_currency = (int) Tools::getValue('id_currency')) ? $id_currency : Configuration::get('PS_CURRENCY_DEFAULT');
         }
         $addresses = $customer->getAddresses((int) $this->context->cart->id_lang);
         if (!$this->context->cart->id_address_invoice && isset($addresses[0])) {
             $this->context->cart->id_address_invoice = (int) $addresses[0]['id_address'];
         } elseif ($id_address_invoice) {
             $this->context->cart->id_address_invoice = (int) $id_address_invoice;
         }
         if (!$this->context->cart->id_address_delivery && isset($addresses[0])) {
             $this->context->cart->id_address_delivery = $addresses[0]['id_address'];
         }
         $this->context->cart->save();
     }
     //end
     $modules = Module::getAuthorizedModules($customer->id_default_group);
     $authorized_modules = array();
     if (!Validate::isLoadedObject($customer) || !is_array($modules)) {
         die(Tools::jsonEncode(array('result' => false)));
     }
     foreach ($modules as $module) {
         $authorized_modules[] = (int) $module['id_module'];
     }
     $payment_modules = array();
     foreach (PaymentModule::getInstalledPaymentModules() as $p_module) {
         if (in_array((int) $p_module['id_module'], $authorized_modules)) {
             $payment_modules[] = Module::getInstanceById((int) $p_module['id_module']);
         }
     }
     $this->context->smarty->assign(array('payment_modules' => $payment_modules));
     die(Tools::jsonEncode(array('result' => true, 'view' => $this->createTemplate('_select_payment.tpl')->fetch())));
 }
 /**
  * returns payment means of the shop in an array which have module ID in indice with module's name and FIA-NET payment type. 
  * 
  * @return array
  */
 private function loadPaymentMethods()
 {
     if (_PS_VERSION_ >= '1.5') {
         $payments = Module::getPaymentModules();
     } else {
         $payments = $this->getInstalledPaymentModules();
     }
     $payment_modules = array();
     foreach ($payments as $payment) {
         $module = Module::getInstanceById($payment['id_module']);
         $payment_modules[$payment['id_module']] = array('name' => $module->displayName, 'fianetsceau_type' => Configuration::get('FIANETSCEAU_' . $payment['id_module'] . '_PAYMENT_TYPE'));
     }
     return $payment_modules;
 }
 /**
  * Ajax call for statistic
  *
  * @result : die the request
  */
 public function ajaxProcessWsModuleCall()
 {
     if (($list = Tools::getValue('modules_list')) && is_array($list)) {
         foreach ($list as $id) {
             if (($obj = Module::getInstanceById($id)) && isset($obj->module_key)) {
                 $this->sendStatisticRequest($obj->module_key);
             }
         }
     }
     die;
 }
Example #29
0
    protected function registerModuleHook($id_module)
    {
        $id_shop = (int) Context::getContext()->shop->id;
        $id_shop_group = (int) Context::getContext()->shop->id_shop_group;
        $module = Module::getInstanceById($id_module);
        if (is_callable(array($module, 'getCronFrequency')) == true) {
            $frequency = $module->getCronFrequency();
            $query = 'INSERT INTO ' . _DB_PREFIX_ . $this->name . '
				(`id_module`, `hour`, `day`, `month`, `day_of_week`, `active`, `id_shop`, `id_shop_group`)
				VALUES (\'' . $id_module . '\', \'' . $frequency['hour'] . '\', \'' . $frequency['day'] . '\',
					\'' . $frequency['month'] . '\', \'' . $frequency['day_of_week'] . '\',
					TRUE, ' . $id_shop . ', ' . $id_shop_group . ')';
        } else {
            $query = 'INSERT INTO ' . _DB_PREFIX_ . $this->name . '
				(`id_module`, `active`, `id_shop`, `id_shop_group`)
				VALUES (' . $id_module . ', FALSE, ' . $id_shop . ', ' . $id_shop_group . ')';
        }
        return Db::getInstance()->execute($query);
    }
    /** 
     * Process posting data
     */
    public function postProcess()
    {
        if (Tools::getValue('action') && Tools::getValue('action') == 'modulehook') {
            $id = (int) Tools::getValue('id');
            $tmp_instance = Module::getInstanceById($id);
            $hooks = array();
            foreach ($this->hookspos as $hk) {
                $retro_hook_name = Hook::getRetroHookName($hk);
                $hook_callable = is_callable(array($tmp_instance, 'hook' . $hk));
                $hook_retro_callable = is_callable(array($tmp_instance, 'hook' . $retro_hook_name));
                if ($hook_retro_callable || $hook_callable) {
                    $hooks[] = $hk;
                    //	break;
                }
            }
            $hooks = implode("|", $hooks);
            $sql = 'SELECT *
				FROM `' . _DB_PREFIX_ . 'leohook` WHERE id_module=' . $id . ' AND theme="' . $this->theme_name . '" AND id_shop=' . (int) $this->context->shop->id;
            if ($row = Db::getInstance()->getRow($sql)) {
                die('{"hasError" : false, "hook" : "' . $row['name_hook'] . '","hooks":"' . $hooks . '"}');
            } else {
                die('{"hasError" : true, "errors" : "Can not update module position","hooks":"' . $hooks . '"}');
            }
        }
        if (Tools::getValue('action') && Tools::getValue('action') == 'overridehook') {
            $id_module = (int) Tools::getValue('hdidmodule');
            $name_hook = Tools::getValue('name_hook');
            if (is_numeric($name_hook)) {
                $sql = 'DELETE  FROM`' . _DB_PREFIX_ . 'leohook` WHERE id_module=' . $id_module . ' AND theme="' . $this->theme_name . '" AND id_shop=' . (int) $this->context->shop->id;
                Db::getInstance(_PS_USE_SQL_SLAVE_)->execute($sql);
                die('{"hasError" : false, "errors" : done!delete module position"}');
            } elseif ($name_hook) {
                $desHook = Tools::getValue("deshook");
                $desHookId = Db::getInstance(_PS_USE_SQL_SLAVE_)->getValue("SELECT id_hook FROM `" . _DB_PREFIX_ . "hook` WHERE name='" . $desHook . "'");
                $sql = 'SELECT *
					FROM `' . _DB_PREFIX_ . 'leohook` WHERE id_hook= ' . $desHookId . ' AND id_module=' . $id_module . ' AND theme="' . $this->theme_name . '" AND id_shop=' . (int) $this->context->shop->id;
                if ($row = Db::getInstance()->getRow($sql)) {
                    $sql = ' UPDATE `' . _DB_PREFIX_ . 'leohook`  SET `id_hook`=' . $desHookId . ', name_hook="' . $name_hook . '" 
						 WHERE id_module=' . $id_module . ' AND theme="' . $this->theme_name . '" AND id_shop=' . (int) $this->context->shop->id;
                    Db::getInstance(_PS_USE_SQL_SLAVE_)->execute($sql);
                } else {
                    $sql = ' INSERT INTO `' . _DB_PREFIX_ . 'leohook` (id_hook, id_module,id_shop,theme, name_hook) 
						VALUES(' . $desHookId . ',' . $id_module . ',' . (int) $this->context->shop->id . ',"' . $this->theme_name . '","' . $name_hook . '")
					';
                    Db::getInstance(_PS_USE_SQL_SLAVE_)->execute($sql);
                }
                die('{"hasError" : false, "errors" : done!update module position"}');
            }
            die('{"hasError" : true, "errors" : "Can not update module position"}');
        }
        if (Tools::getValue('action') && Tools::getValue('action') == 'savepos') {
            $positions = Tools::getValue('position');
            $way = (int) Tools::getValue('way');
            $unhook = Tools::getValue('unhook');
            $id_shop = Context::getContext()->shop->id;
            if (is_array($unhook)) {
                foreach ($unhook as $id_module => $hookId) {
                    $module = Module::getInstanceById($id_module);
                    if (Validate::isLoadedObject($module)) {
                        !$module->unregisterHook((int) $hookId, array($id_shop));
                    }
                }
            }
            if (is_array($positions) && !empty($positions)) {
                foreach ($positions as $pos) {
                    $tmp = explode("|", $pos);
                    if (count($tmp) == 2 && $tmp[0] && $tmp[1]) {
                        $position = $tmp[0];
                        $hookId = Hook::getIdByName($position);
                        $oldhooks = explode(",", Tools::getValue($position));
                        $ids = explode(",", $tmp[1]);
                        if ($hookId && count($oldhooks)) {
                            foreach ($ids as $index => $id_module) {
                                $module = Module::getInstanceById($id_module);
                                if (Validate::isLoadedObject($module) && isset($oldhooks[$index]) && is_numeric($oldhooks[$index]) && $oldhooks[$index] != $hookId) {
                                    Db::getInstance(_PS_USE_SQL_SLAVE_)->execute('
								 		UPDATE `' . _DB_PREFIX_ . 'hook_module` SET id_hook=' . $hookId . ' 
								 				WHERE id_module=' . $id_module . ' AND id_hook=' . (int) $oldhooks[$index] . ' AND id_shop=' . (int) $id_shop);
                                    //	echo '<pre>'.print_r( $idshooks ,1);
                                    echo $oldhooks[$index] . '<br>';
                                    echo '<br>update:' . $id_module . "-";
                                } elseif (Validate::isLoadedObject($module) && (!isset($oldhooks[$index]) || !(int) $oldhooks[$index])) {
                                    $this->registerHook($id_module, $hookId, array($id_shop));
                                    echo 'new:' . $id_module;
                                }
                                $module->updatePosition($hookId, $way, $index + 1);
                            }
                        }
                        //	echo '<pre>'.print_r( $hookId, 1 ); die;
                    }
                }
            }
            // echo '<pre>'.print_r( $position, 1 ); die;
            die("done done");
        }
    }