name = 'deleteordersfree'; $this->author = 'MyPresta.eu'; $this->tab = 'Other'; $this->version = '1.5.3'; $this->module_key = ''; $this->dir = '/modules/deleteordersfree/'; $this->mypresta_link = 'https://mypresta.eu/modules/administration-tools/delete-orders-free.html'; $this->bootstrap = 1; parent::__construct(); $this->displayName = $this->l('Delete Orders Free'); $this->description = $this->l('Delete Orders Free is the best module for deleting orders. This version is free. Developed by MyPresta.eu'); $this->tab = 'Admin'; $this->tabClassName = 'deleteorderstab'; $this->tabParentName = 'AdminParentOrders'; $this->checkforupdates(); } public function checkforupdates($display_msg = 0, $form = 0) { // ---------- // // ---------- // // VERSION 16 // // ---------- // // ---------- // $this->mkey = "nlc"; if (@file_exists('../modules/' . $this->name . '/key.php')) { @require_once('../modules/' . $this->name . '/key.php'); } else { if (@file_exists(dirname(__FILE__) . $this->name . '/key.php')) { @require_once(dirname(__FILE__) . $this->name . '/key.php'); } else { if (@file_exists('modules/' . $this->name . '/key.php')) { @require_once('modules/' . $this->name . '/key.php'); } } } if ($form == 1) { return '
' . ($this->psversion() == 6 || $this->psversion() == 7 ? '
' . $this->l('MyPresta updates') . '
' : '') . '
' . ($this->psversion() == 5 ? '' . $this->l('MyPresta updates') . '' : '') . '
' . (Tools::isSubmit('submit_settings_updates_now') ? ($this->inconsistency(0) ? '' : '') . $this->checkforupdates(1) : '') . '

' . $this->l('Turn this option on if you want to check MyPresta.eu for module updates automatically. This option will display notification about new versions of this addon.') . '

' . $this->displayName . '

' . $this->l('This is direct link to official addon page, where you can read about changes in the module (changelog)') . '

'; } else { if (defined('_PS_ADMIN_DIR_')) { if (Tools::isSubmit('submit_settings_updates')) { Configuration::updateValue('mypresta_updates', Tools::getValue('mypresta_updates')); } if (Configuration::get('mypresta_updates') != 0 || (bool)Configuration::get('mypresta_updates') != false) { if (Configuration::get('update_' . $this->name) < (date("U") - 259200)) { $actual_version = deleteordersfreeUpdate::verify($this->name, (isset($this->mkey) ? $this->mkey : 'nokey'), $this->version); } if (deleteordersfreeUpdate::version($this->version) < deleteordersfreeUpdate::version(Configuration::get('updatev_' . $this->name)) && Tools::getValue('ajax', 'false') == 'false') { $this->context->controller->warnings[] = '' . $this->displayName . ': ' . $this->l('New version available, check http://MyPresta.eu for more informations') . ' ' . $this->l('More details in changelog') . ''; $this->warning = $this->context->controller->warnings[0]; } } else { if (Configuration::get('update_' . $this->name) < (date("U") - 259200)) { $actual_version = deleteordersfreeUpdate::verify($this->name, (isset($this->mkey) ? $this->mkey : 'nokey'), $this->version); } } if ($display_msg == 1) { if (deleteordersfreeUpdate::version($this->version) < deleteordersfreeUpdate::version(deleteordersfreeUpdate::verify($this->name, (isset($this->mkey) ? $this->mkey : 'nokey'), $this->version))) { return "" . $this->l('New version available!') . ""; } else { return "" . $this->l('Module is up to date!') . ""; } } } } } public function viewAccess($disable = false) { $result = true; return $result; } function install() { if (parent::install() == false) { return false; } if (!isset($id_tab)) { $tab = new Tab(); $tab->class_name = $this->tabClassName; $tab->id_parent = Tab::getIdFromClassName($this->tabParentName); $tab->module = $this->name; $languages = Language::getLanguages(); foreach ($languages as $language) { $tab->name[$language['id_lang']] = $this->displayName; } $tab->add(); } return true; } public function uninstall() { if (parent::uninstall() == false) { return false; } $id_tab = Tab::getIdFromClassName($this->tabClassName); if ($id_tab) { $tab = new Tab($id_tab); $tab->delete(); } return true; } public function psversion() { $version = _PS_VERSION_; $exp = $explode = explode(".", $version); return $exp[1]; } public function displayAdvert($return = 0) { $ret = ''; if ($return == 0) { echo $ret; } else { return $ret; } } public function displayFooter($return = 0) { $ret = "
"; $ret .= $this->l('proudly developed by') . " MyPresta.eu

"; $ret .= ''; $ret .= "
"; if ($return == 0) { echo $ret; } else { return $ret; } } public function displayinputid($return = 0) { $verps = ""; $ret = "

" . $this->l('Fill form with correct ORDER ID and delete it') . "

" . $this->l('ORDER ID') . "


l('Are you sure you want to delete:') . " #" . "'+document.getElementById('idord').value+'" . " " . $this->l('order?') . "');\" style=\"cursor:pointer;\" >
" . $this->l('click to remove') . "
"; if ($return == 0) { echo $ret; } else { return $ret; } } public function deleteorderbyid($id, $return = 0) { $psversion = $this->psversion(); if ($psversion == 7) { $thisorder = Db::getInstance(_PS_USE_SQL_SLAVE_)->ExecuteS('SELECT id_cart FROM ' . _DB_PREFIX_ . 'orders WHERE id_order = ' . $id); if (isset($thisorder[0])) { //deleting order_return $q = 'DELETE a,b FROM ' . _DB_PREFIX_ . 'order_return AS a LEFT JOIN ' . _DB_PREFIX_ . 'order_return_detail AS b ON a.id_order_return = b.id_order_return WHERE id_order="' . $id . '"'; if (!Db::getInstance()->Execute($q)) { $this->errorlog[] = $this->l("ERROR"); } //deleting order_slip $q = 'DELETE a,b FROM ' . _DB_PREFIX_ . 'order_slip AS a LEFT JOIN ' . _DB_PREFIX_ . 'order_slip_detail AS b ON a.id_order_slip = b.id_order_slip WHERE id_order="' . $id . '"'; if (!Db::getInstance()->Execute($q)) { $this->errorlog[] = $this->l("ERROR"); } $q = 'DELETE FROM ' . _DB_PREFIX_ . 'cart_product WHERE id_cart="' . $thisorder[0]['id_cart'] . '"'; if (!Db::getInstance()->Execute($q)) { $this->errorlog[] = $this->l("ERROR"); } $q = 'DELETE FROM ' . _DB_PREFIX_ . 'order_history WHERE id_order="' . $id . '"'; if (!Db::getInstance()->Execute($q)) { $this->errorlog[] = $this->l("ERROR"); } $q = 'DELETE FROM ' . _DB_PREFIX_ . 'order_detail_tax WHERE id_order_detail IN (SELECT id_order_detail FROM ' . _DB_PREFIX_ . 'order_detail WHERE id_order ="' . $id . '")'; if (!Db::getInstance()->Execute($q)) { $this->errorlog[] = $this->l("ERROR"); } $q = 'DELETE FROM ' . _DB_PREFIX_ . 'order_detail WHERE id_order="' . $id . '"'; if (!Db::getInstance()->Execute($q)) { $this->errorlog[] = $this->l("ERROR"); } $q = 'DELETE FROM ' . _DB_PREFIX_ . 'order_payment WHERE order_reference IN (SELECT reference FROM ' . _DB_PREFIX_ . 'orders WHERE id_order="' . $id . '")'; if (!Db::getInstance()->Execute($q)) { $this->errorlog[] = $this->l("ERROR"); } $q = 'DELETE FROM ' . _DB_PREFIX_ . 'orders WHERE id_order="' . $id . '"'; if (!Db::getInstance()->Execute($q)) { $this->errorlog[] = $this->l("ERROR"); } $q = 'DELETE FROM ' . _DB_PREFIX_ . 'order_carrier WHERE id_order="' . $id . '"'; if (!Db::getInstance()->Execute($q)) { $this->errorlog[] = $this->l("ERROR"); } $q = 'DELETE FROM ' . _DB_PREFIX_ . 'order_invoice_tax WHERE id_order_invoice IN (SELECT id_order_invoice FROM ' . _DB_PREFIX_ . 'order_invoice WHERE id_order="' . $id . '")'; if (!Db::getInstance()->Execute($q)) { $this->errorlog[] = $this->l("ERROR"); } $q = 'DELETE FROM ' . _DB_PREFIX_ . 'order_invoice WHERE id_order="' . $id . '"'; if (!Db::getInstance()->Execute($q)) { $this->errorlog[] = $this->l("ERROR"); } $q = 'DELETE FROM ' . _DB_PREFIX_ . 'order_invoice_payment WHERE id_order="' . $id . '"'; if (!Db::getInstance()->Execute($q)) { $this->errorlog[] = $this->l("ERROR"); } $q = 'DELETE FROM ' . _DB_PREFIX_ . 'order_cart_rule WHERE id_order="' . $id . '"'; if (!Db::getInstance()->Execute($q)) { $this->errorlog[] = $this->l("ERROR"); } if (empty($this->errorlog)) { if ($return == 1) { $this->context->controller->confirmations[] = $this->l('Order deleted'); } else { return $this->l('Order deleted'); } } else { if ($return == 1) { $this->context->controller->errors[] = $this->l('Something wrong'); } else { return $this->l('Something wrong'); } } } else { if ($return == 1) { $this->context->controller->errors[] = $this->l('Order with this id doesnt exists'); } else { return $this->l('Order with this id doesnt exists'); } } } } public function getContent() { $this->context->controller->informations[] = $this->l('Delete orders form is available here: ') . '' . $this->l('Delete orders form') . ''; return $this->checkforupdates(0, 1); } public function inconsistency($var) { return; } public function displayForm() { return ''; } public function getorders_psv3($limit = null) { global $cookie; return Db::getInstance()->ExecuteS(' SELECT *, ( SELECT `name` FROM `' . _DB_PREFIX_ . 'order_history` oh LEFT JOIN `' . _DB_PREFIX_ . 'order_state_lang` osl ON (osl.`id_order_state` = oh.`id_order_state`) WHERE oh.`id_order` = o.`id_order` AND osl.`id_lang` = ' . (int)$cookie->id_lang . ' ORDER BY oh.`date_add` DESC LIMIT 1 ) AS `state_name` FROM `' . _DB_PREFIX_ . 'orders` o LEFT JOIN `' . _DB_PREFIX_ . 'customer` c ON (c.`id_customer` = o.`id_customer`) ORDER BY o.`date_add` DESC ' . ((int)$limit ? 'LIMIT 0, ' . (int)$limit : '')); } } class deleteordersfreeUpdate extends deleteordersfree { public static function version($version) { $version = (int)str_replace(".", "", $version); if (strlen($version) == 3) { $version = (int)$version . "0"; } if (strlen($version) == 2) { $version = (int)$version . "00"; } if (strlen($version) == 1) { $version = (int)$version . "000"; } if (strlen($version) == 0) { $version = (int)$version . "0000"; } return (int)$version; } public static function encrypt($string) { return base64_encode($string); } public static function verify($module, $key, $version) { if (ini_get("allow_url_fopen")) { if (function_exists("file_get_contents")) { $actual_version = @file_get_contents('http://dev.mypresta.eu/update/get.php?module=' . $module . "&version=" . self::encrypt($version) . "&lic=$key&u=" . self::encrypt(_PS_BASE_URL_ . __PS_BASE_URI__)); } } Configuration::updateValue("update_" . $module, date("U")); Configuration::updateValue("updatev_" . $module, $actual_version); return $actual_version; } } ?>