예제 #1
0
 public function delete()
 {
     $addresses = $this->getAddresses((int) Configuration::get('PS_LANG_DEFAULT'));
     foreach ($addresses as $address) {
         $obj = new Address((int) $address['id_address']);
         $obj->delete();
     }
     Db::getInstance()->Execute('DELETE FROM `' . _DB_PREFIX_ . 'customer_group` WHERE `id_customer` = ' . (int) $this->id);
     Discount::deleteByIdCustomer((int) $this->id);
     return parent::delete();
 }
    public function postProcess()
    {
        global $currentIndex;
        if (Tools::isSubmit('submitDel' . $this->table) or Tools::isSubmit('delete' . $this->table)) {
            $deleteForm = '
			<form action="' . htmlentities($_SERVER['REQUEST_URI']) . '" method="post">
				<fieldset><legend>' . $this->l('How do you want to delete your customer(s)?') . '</legend>
					' . $this->l('You have two ways to delete a customer, please choose what you want to do.') . '
					<p>
						<input type="radio" name="deleteMode" value="real" id="deleteMode_real" />
						<label for="deleteMode_real" style="float:none">' . $this->l('I want to delete my customer(s) for real, all data will be removed from the database. A customer with the same e-mail address will be able to register again.') . '</label>
					</p>
					<p>
						<input type="radio" name="deleteMode" value="deleted" id="deleteMode_deleted" />
						<label for="deleteMode_deleted" style="float:none">' . $this->l('I don\'t want my customer(s) to register again. The customer(s) will be removed from this list but all data will be kept in the database.') . '</label>
					</p>';
            foreach ($_POST as $key => $value) {
                if (is_array($value)) {
                    foreach ($value as $val) {
                        $deleteForm .= '<input type="hidden" name="' . htmlentities($key) . '[]" value="' . htmlentities($val) . '" />';
                    }
                } else {
                    $deleteForm .= '<input type="hidden" name="' . htmlentities($key) . '" value="' . htmlentities($value) . '" />';
                }
            }
            $deleteForm .= '	<br /><input type="submit" class="button" value="' . $this->l('   Delete   ') . '" />
				</fieldset>
			</form>
			<div class="clear">&nbsp;</div>';
        }
        if (Tools::getValue('submitAdd' . $this->table)) {
            $groupList = Tools::getValue('groupBox');
            /* Checking fields validity */
            $this->validateRules();
            if (!sizeof($this->_errors)) {
                $id = (int) Tools::getValue('id_' . $this->table);
                if (isset($id) and !empty($id)) {
                    if ($this->tabAccess['edit'] !== '1') {
                        $this->_errors[] = Tools::displayError('You do not have permission to edit here.');
                    } else {
                        $object = new $this->className($id);
                        if (Validate::isLoadedObject($object)) {
                            $customer_email = strval(Tools::getValue('email'));
                            // check if e-mail already used
                            if ($customer_email != $object->email) {
                                $customer = new Customer();
                                $customer->getByEmail($customer_email);
                                if ($customer->id) {
                                    $this->_errors[] = Tools::displayError('An account already exists for this e-mail address:') . ' ' . $customer_email;
                                }
                            }
                            if (!is_array($groupList) or sizeof($groupList) == 0) {
                                $this->_errors[] = Tools::displayError('Customer must be in at least one group.');
                            } else {
                                if (!in_array(Tools::getValue('id_default_group'), $groupList)) {
                                    $this->_errors[] = Tools::displayError('Default customer group must be selected in group box.');
                                }
                            }
                            // Updating customer's group
                            if (!sizeof($this->_errors)) {
                                $object->cleanGroups();
                                if (is_array($groupList) and sizeof($groupList) > 0) {
                                    $object->addGroups($groupList);
                                }
                            }
                        } else {
                            $this->_errors[] = Tools::displayError('An error occurred while loading object.') . ' <b>' . $this->table . '</b> ' . Tools::displayError('(cannot load object)');
                        }
                    }
                } else {
                    if ($this->tabAccess['add'] === '1') {
                        $object = new $this->className();
                        $this->copyFromPost($object, $this->table);
                        if (!$object->add()) {
                            $this->_errors[] = Tools::displayError('An error occurred while creating object.') . ' <b>' . $this->table . ' (' . mysql_error() . ')</b>';
                        } elseif ($_POST[$this->identifier] = $object->id and $this->postImage($object->id) and !sizeof($this->_errors) and $this->_redirect) {
                            // Add Associated groups
                            $group_list = Tools::getValue('groupBox');
                            if (is_array($group_list) && sizeof($group_list) > 0) {
                                $object->addGroups($group_list, true);
                            }
                            $parent_id = (int) Tools::getValue('id_parent', 1);
                            // Save and stay on same form
                            if (Tools::isSubmit('submitAdd' . $this->table . 'AndStay')) {
                                Tools::redirectAdmin($currentIndex . '&' . $this->identifier . '=' . $object->id . '&conf=3&update' . $this->table . '&token=' . $this->token);
                            }
                            // Save and back to parent
                            if (Tools::isSubmit('submitAdd' . $this->table . 'AndBackToParent')) {
                                Tools::redirectAdmin($currentIndex . '&' . $this->identifier . '=' . $parent_id . '&conf=3&token=' . $this->token);
                            }
                            // Default behavior (save and back)
                            Tools::redirectAdmin($currentIndex . ($parent_id ? '&' . $this->identifier . '=' . $object->id : '') . '&conf=3&token=' . $this->token);
                        }
                    } else {
                        $this->_errors[] = Tools::displayError('You do not have permission to add here.');
                    }
                }
            }
        } elseif (Tools::isSubmit('delete' . $this->table) and $this->tabAccess['delete'] === '1') {
            switch (Tools::getValue('deleteMode')) {
                case 'real':
                    $this->deleted = false;
                    Discount::deleteByIdCustomer((int) Tools::getValue('id_customer'));
                    break;
                case 'deleted':
                    $this->deleted = true;
                    break;
                default:
                    echo $deleteForm;
                    if (isset($_POST['delete' . $this->table])) {
                        unset($_POST['delete' . $this->table]);
                    }
                    if (isset($_GET['delete' . $this->table])) {
                        unset($_GET['delete' . $this->table]);
                    }
                    break;
            }
        } elseif (Tools::isSubmit('submitDel' . $this->table) and $this->tabAccess['delete'] === '1') {
            switch (Tools::getValue('deleteMode')) {
                case 'real':
                    $this->deleted = false;
                    foreach (Tools::getValue('customerBox') as $id_customer) {
                        Discount::deleteByIdCustomer((int) $id_customer);
                    }
                    break;
                case 'deleted':
                    $this->deleted = true;
                    break;
                default:
                    echo $deleteForm;
                    if (isset($_POST['submitDel' . $this->table])) {
                        unset($_POST['submitDel' . $this->table]);
                    }
                    if (isset($_GET['submitDel' . $this->table])) {
                        unset($_GET['submitDel' . $this->table]);
                    }
                    break;
            }
        } elseif (Tools::isSubmit('submitGuestToCustomer') and Tools::getValue('id_customer')) {
            if ($this->tabAccess['edit'] === '1') {
                $customer = new Customer((int) Tools::getValue('id_customer'));
                if (!Validate::isLoadedObject($customer)) {
                    $this->_errors[] = Tools::displayError('This customer does not exist.');
                }
                if (Customer::customerExists($customer->email)) {
                    $this->_errors[] = Tools::displayError('This customer already exist as non-guest.');
                } elseif ($customer->transformToCustomer(Tools::getValue('id_lang', Configuration::get('PS_LANG_DEFAULT')))) {
                    Tools::redirectAdmin($currentIndex . '&' . $this->identifier . '=' . $customer->id . '&conf=3&token=' . $this->token);
                } else {
                    $this->_errors[] = Tools::displayError('An error occurred while updating customer.');
                }
            } else {
                $this->_errors[] = Tools::displayError('You do not have permission to edit here.');
            }
        } elseif (Tools::isSubmit('changeNewsletterVal') and Tools::getValue('id_customer')) {
            $id_customer = (int) Tools::getValue('id_customer');
            $customer = new Customer($id_customer);
            if (!Validate::isLoadedObject($customer)) {
                $this->_errors[] = Tools::displayError('An error occurred while updating customer.');
            }
            $update = Db::getInstance()->Execute('UPDATE `' . _DB_PREFIX_ . 'customer` SET newsletter = ' . ($customer->newsletter ? 0 : 1) . ' WHERE `id_customer` = ' . (int) $customer->id);
            if (!$update) {
                $this->_errors[] = Tools::displayError('An error occurred while updating customer.');
            }
            Tools::redirectAdmin($currentIndex . '&token=' . $this->token);
        } elseif (Tools::isSubmit('changeOptinVal') and Tools::getValue('id_customer')) {
            $id_customer = (int) Tools::getValue('id_customer');
            $customer = new Customer($id_customer);
            if (!Validate::isLoadedObject($customer)) {
                $this->_errors[] = Tools::displayError('An error occurred while updating customer.');
            }
            $update = Db::getInstance()->Execute('UPDATE `' . _DB_PREFIX_ . 'customer` SET optin = ' . ($customer->optin ? 0 : 1) . ' WHERE `id_customer` = ' . (int) $customer->id);
            if (!$update) {
                $this->_errors[] = Tools::displayError('An error occurred while updating customer.');
            }
            Tools::redirectAdmin($currentIndex . '&token=' . $this->token);
        }
        return parent::postProcess();
    }
 public function processDelete()
 {
     if ($this->delete_mode == 'real') {
         $this->deleted = false;
         Discount::deleteByIdCustomer((int) Tools::getValue('id_customer'));
     } elseif ($this->delete_mode == 'deleted') {
         $this->deleted = true;
     } else {
         $this->errors[] = Tools::displayError('Unknown delete mode:') . ' ' . $this->deleted;
         return;
     }
     parent::processDelete();
 }