Пример #1
0
 public function postProcess()
 {
     if (Tools::isSubmit('submitSmsTest')) {
         $number = (string) Tools::getValue('campaign_last_tester');
         if (empty($number) || !Validate::isPhoneNumber($number)) {
             $this->errors[] = $this->module->l('Invalid gsm number !', 'adminmarketingsstep6');
             return false;
         }
         $prefixe = EMTools::getShopPrefixeCountry();
         $number = EMTools::cleanNumber($number, $prefixe);
         if ($number[0] != '0' && $number[0] != '+') {
             $this->errors[] = $this->module->l('Invalid gsm number !', 'adminmarketingsstep6');
             return false;
         }
         $response_array = array();
         $parameters = array('campaign_id' => $this->campaign_api_message_id, 'recipient' => $number, 'text' => $this->module->l('[TEST]', 'adminmarketingsstep6') . ' ' . $this->campaign_sms_text);
         if ($this->session_api->call('sms', 'campaign', 'send_test', $parameters, $response_array)) {
             // We store the last fax number
             // ----------------------------
             Db::getInstance()->update('expressmailing_sms', array('campaign_last_tester' => pSQL($number)), 'campaign_id = ' . $this->campaign_id);
             $this->confirmations[] = sprintf($this->module->l('Please wait, your sms is processing to %s ...', 'adminmarketingsstep6'), $number);
             return true;
         }
         $this->errors[] = sprintf($this->module->l('Error while sending sms to the API : %s', 'adminmarketingsstep6'), $this->session_api->getError());
         return false;
     }
 }
Пример #2
0
 public function initContent()
 {
     parent::initContent();
     if (Tools::isSubmit('submitMessage')) {
         $message = Tools::getValue('message');
         // Html entities is not usefull, iscleanHtml check there is no bad html tags.
         $phone = Tools::getValue('tel');
         $mobile = Tools::getValue('mobile');
         if (!($from = trim(Tools::getValue('from'))) || !Validate::isEmail($from)) {
             $this->errors[] = Tools::displayError('Invalid email address.');
         } else {
             if (!$message) {
                 $this->errors[] = Tools::displayError('The message cannot be blank.');
             } else {
                 if (!Validate::isCleanHtml($message)) {
                     $this->errors[] = Tools::displayError('Invalid message');
                 } else {
                     if (!Validate::isPhoneNumber($phone)) {
                         $this->errors[] = Tools::displayError('Invalid phone number.');
                     } else {
                         if (!Validate::isPhoneNumber($mobile)) {
                             $this->errors[] = Tools::displayError('Invalid Mobile number.');
                         }
                     }
                 }
             }
         }
         //		var_dump($this->errors,empty($this->errors));
         if (empty($this->errors)) {
             $id_product = Tools::getValue('product_id');
             //var_dump($id_product);
             $product = new Product($id_product);
             //var_dump($product);
             $product_name = '';
             $item_number = '';
             if (Validate::isLoadedObject($product) && isset($product->name[(int) $this->context->language->id])) {
                 $product_name = $product->name[(int) $this->context->language->id];
                 $item_number = $product->item_number;
             }
             $data = array('{name}' => Tools::getValue('name'), '{phone}' => $phone, '{mobile}' => $mobile, '{message}' => $message, '{item_number}' => $item_number, '{product}' => $product_name, '{date}' => date('Y-m-d H:i:s'), '{email}' => $from);
             $sampleObj = new requestsample();
             $sampleObj->sendmail($data, $from, (int) $this->context->language->id, 'request_quote', 'New Request for Quote');
             $this->context->smarty->assign('confirmation', 1);
         }
     }
     $this->context->smarty->assign('product_id', $_GET['pr_id']);
     $this->setTemplate('quote_form.tpl');
 }
Пример #3
0
 public function __construct(SimpleXMLElement $order_xml = null)
 {
     if (!$order_xml) {
         return;
     }
     /** Backward compatibility */
     require dirname(__FILE__) . '/../backward_compatibility/backward.php';
     list($this->firstname, $this->familyname) = $this->_formatShippingAddressName($order_xml->ShippingAddress->Name);
     $this->id_order_ref = (string) $order_xml->OrderID;
     $this->amount = (string) $order_xml->AmountPaid;
     $this->status = (string) $order_xml->CheckoutStatus->Status;
     $this->name = (string) $order_xml->ShippingAddress->Name;
     $this->address1 = (string) $order_xml->ShippingAddress->Street1;
     $this->address2 = (string) $order_xml->ShippingAddress->Street2;
     $this->city = (string) $order_xml->ShippingAddress->CityName;
     $this->state = (string) $order_xml->ShippingAddress->StateOrProvince;
     $this->country_iso_code = (string) $order_xml->ShippingAddress->Country;
     $this->country_name = (string) $order_xml->ShippingAddress->CountryName;
     $this->postalcode = (string) $order_xml->ShippingAddress->PostalCode;
     $this->shippingService = (string) $order_xml->ShippingServiceSelected->ShippingService;
     $this->shippingServiceCost = (string) $order_xml->ShippingServiceSelected->ShippingServiceCost;
     $this->payment_method = (string) $order_xml->CheckoutStatus->PaymentMethod;
     $this->id_order_seller = (string) $order_xml->ShippingDetails->SellingManagerSalesRecordNumber;
     if (count($order_xml->TransactionArray->Transaction)) {
         $this->email = (string) $order_xml->TransactionArray->Transaction[0]->Buyer->Email;
     }
     $phone = (string) $order_xml->ShippingAddress->Phone;
     if (!$phone || !Validate::isPhoneNumber($phone)) {
         $this->phone = '0100000000';
     } else {
         $this->phone = $phone;
     }
     $date = substr((string) $order_xml->CreatedTime, 0, 10) . ' ' . substr((string) $order_xml->CreatedTime, 11, 8);
     $this->date = $date;
     $this->date_add = $date;
     if ($order_xml->TransactionArray->Transaction) {
         $this->product_list = $this->_getProductsFromTransactions($order_xml->TransactionArray->Transaction);
     }
 }
 /**
  * Initialize order opc controller
  * @see FrontController::init()
  */
 public function init()
 {
     parent::init();
     if ($this->nbProducts) {
         $this->context->smarty->assign('virtual_cart', $this->context->cart->isVirtualCart());
     }
     $this->context->smarty->assign('is_multi_address_delivery', $this->context->cart->isMultiAddressDelivery() || (int) Tools::getValue('multi-shipping') == 1);
     $this->context->smarty->assign('open_multishipping_fancybox', (int) Tools::getValue('multi-shipping') == 1);
     if ($this->nbProducts) {
         if (Tools::isSubmit('ajax')) {
             if (Tools::isSubmit('method')) {
                 switch (Tools::getValue('method')) {
                     case 'updateMessage':
                         if (Tools::isSubmit('message')) {
                             $txtMessage = urldecode(Tools::getValue('message'));
                             $this->_updateMessage($txtMessage);
                             if (count($this->errors)) {
                                 die('{"hasError" : true, "errors" : ["' . implode('\',\'', $this->errors) . '"]}');
                             }
                             die(true);
                         }
                         break;
                     case 'updateCarrierAndGetPayments':
                         if ((Tools::isSubmit('delivery_option') || Tools::isSubmit('id_carrier')) && Tools::isSubmit('recyclable') && Tools::isSubmit('gift') && Tools::isSubmit('gift_message')) {
                             $this->_assignWrappingAndTOS();
                             if ($this->_processCarrier()) {
                                 $carriers = $this->context->cart->simulateCarriersOutput();
                                 $return = array_merge(array('HOOK_TOP_PAYMENT' => Hook::exec('displayPaymentTop'), 'HOOK_PAYMENT' => $this->_getPaymentMethods(), 'carrier_data' => $this->_getCarrierList(), 'HOOK_BEFORECARRIER' => Hook::exec('displayBeforeCarrier', array('carriers' => $carriers))), $this->getFormatedSummaryDetail());
                                 Cart::addExtraCarriers($return);
                                 //									die(Tools::jsonEncode($return));
                             } else {
                                 $this->errors[] = Tools::displayError('An error occurred while updating the cart.');
                             }
                             if (count($this->errors)) {
                                 die('{"hasError" : true, "errors_discount" : ["' . implode('\',\'', $this->errors) . '"]}');
                             }
                             exit;
                         }
                         break;
                     case 'updateTOSStatusAndGetPayments':
                         if (Tools::isSubmit('checked')) {
                             $this->context->cookie->checkedTOS = (int) Tools::getValue('checked');
                             die(Tools::jsonEncode(array('HOOK_TOP_PAYMENT' => Hook::exec('displayPaymentTop'), 'HOOK_PAYMENT' => $this->_getPaymentMethods())));
                         }
                         break;
                     case 'getCarrierList':
                         die(Tools::jsonEncode($this->_getCarrierList()));
                         break;
                     case 'editCustomer':
                         if (!$this->isLogged) {
                             exit;
                         }
                         if (Tools::getValue('years')) {
                             $this->context->customer->birthday = (int) Tools::getValue('years') . '-' . (int) Tools::getValue('months') . '-' . (int) Tools::getValue('days');
                         }
                         $_POST['lastname'] = $_POST['customer_lastname'];
                         $_POST['firstname'] = $_POST['customer_firstname'];
                         $this->errors = $this->context->customer->validateController();
                         //var_dump($this->errors);
                         if (Tools::getValue('delivery_form')) {
                             $address = new Address($this->context->cart->id_address_delivery);
                             if (empty($_POST['city'])) {
                                 $this->errors['city_courier'] = Tools::displayError('Город обязателен');
                             }
                             if (empty($_POST['street'])) {
                                 $this->errors['street_courier'] = Tools::displayError('Улица обязательна');
                             }
                             if (empty($_POST['house'])) {
                                 $this->errors['house_courier'] = Tools::displayError('Дом обязателен');
                             }
                             if (!Tools::getValue('phone')) {
                                 $this->errors['phone'] = Tools::displayError('Телефон обязателен');
                             } else {
                                 if (!Validate::isPhoneNumber(Tools::getValue('phone'))) {
                                     $this->errors['phone'] = Tools::displayError('мобильный телефон неверный');
                                 }
                             }
                             if (!empty($_POST['date_dilivery'])) {
                                 $address->other = 'Удобная дата доставки: ' . $_POST['date_dilivery'];
                             }
                             if (!count($this->errors) && is_object($address) && isset($address->id_customer)) {
                                 $address->address1 = $_POST['city'] . ' ' . $_POST['street'] . ' ' . $_POST['house'];
                                 $address->city = $_POST['city'];
                                 $address->firstname = $_POST['firstname'];
                                 $address->phone_mobile = $_POST['phone'];
                                 $delivery_pickup = array('delivery_city' => $_POST['city'], 'delivery_street' => $_POST['street'], 'delivery_house' => $_POST['house'], 'delivery_date' => isset($_POST['delivery_date']) ? $_POST['delivery_date'] : '');
                                 $address->other = $delivery_pickup['delivery_date'];
                                 foreach ($delivery_pickup as $k => $v) {
                                     $this->context->cookie->{$k} = $v;
                                 }
                                 $address->save();
                             }
                             //else
                             //$this->errors[] = Tools::displayError('Невозможно загрузить адресс');
                         }
                         $this->context->customer->newsletter = (int) Tools::isSubmit('newsletter');
                         $this->context->customer->optin = (int) Tools::isSubmit('optin');
                         //                            foreach($this->errors as $key=> $value){
                         //                               // if($key=="lastname")$key="customer_lastname";
                         //                               // if($key=="firstname")$key="customer_firstname";
                         //                                $this->val_errors[$key]=$value;
                         //                            }
                         $return = array('hasError' => !empty($this->errors), 'errors' => $this->errors, 'id_customer' => (int) $this->context->customer->id, 'token' => Tools::getToken(false));
                         if (!count($this->errors)) {
                             $url = 'http://api.unisender.com/ru/api/subscribe?format=json&api_key=58priw95sdjt7umw17ixbnkkkudtoq5u7nmfcacy&list_ids=4734062';
                             $url .= '&fields[email]=' . trim($_POST['email']);
                             $url .= '&fields[Name]=' . urlencode($_POST['firstname'] . ' ' . $_POST['lastname']);
                             $url .= '&fields[phone]=' . trim($_POST['phone']);
                             $url .= '&tags=dev_etagerca';
                             $url .= '&double_optin=3';
                             $curl = curl_init($url);
                             curl_setopt_array($curl, array(CURLOPT_HEADER => false, CURLOPT_RETURNTRANSFER => true));
                             $result = json_decode(curl_exec($curl), true);
                             // var_dump($url);var_dump($result);exit();
                             if ($result['result'] && $result['result']['person_id']) {
                                 setcookie('subscribe', '1', time() + 31536000);
                                 $_COOKIE['subscribe'] = '1';
                             }
                             $return['isSaved'] = (bool) $this->context->customer->update();
                         } else {
                             $return['isSaved'] = false;
                         }
                         die(Tools::jsonEncode($return));
                         break;
                     case 'getAddressBlockAndCarriersAndPayments':
                         if ($this->isLogged) {
                             // check if customer have addresses
                             if (!Customer::getAddressesTotalById($this->context->customer->id)) {
                                 die(Tools::jsonEncode(array('no_address' => 1)));
                             }
                             if (file_exists(_PS_MODULE_DIR_ . 'blockuserinfo/blockuserinfo.php')) {
                                 include_once _PS_MODULE_DIR_ . 'blockuserinfo/blockuserinfo.php';
                                 $blockUserInfo = new BlockUserInfo();
                             }
                             $this->context->smarty->assign('isVirtualCart', $this->context->cart->isVirtualCart());
                             $this->_processAddressFormat();
                             $this->_assignAddress();
                             if (!($formatedAddressFieldsValuesList = $this->context->smarty->getTemplateVars('formatedAddressFieldsValuesList'))) {
                                 $formatedAddressFieldsValuesList = array();
                             }
                             // Wrapping fees
                             $wrapping_fees = $this->context->cart->getGiftWrappingPrice(false);
                             $wrapping_fees_tax_inc = $wrapping_fees = $this->context->cart->getGiftWrappingPrice();
                             $return = array_merge(array('order_opc_adress' => $this->context->smarty->fetch(_PS_THEME_DIR_ . 'order-address.tpl'), 'block_user_info' => isset($blockUserInfo) ? $blockUserInfo->hookDisplayTop(array()) : '', 'formatedAddressFieldsValuesList' => $formatedAddressFieldsValuesList, 'carrier_data' => $this->_getCarrierList(), 'HOOK_TOP_PAYMENT' => Hook::exec('displayPaymentTop'), 'HOOK_PAYMENT' => $this->_getPaymentMethods(), 'no_address' => 0, 'gift_price' => Tools::displayPrice(Tools::convertPrice(Product::getTaxCalculationMethod() == 1 ? $wrapping_fees : $wrapping_fees_tax_inc, new Currency((int) $this->context->cookie->id_currency)))), $this->getFormatedSummaryDetail());
                             die(Tools::jsonEncode($return));
                         }
                         die(Tools::displayError());
                         break;
                     case 'makeFreeOrder':
                         /* Bypass payment step if total is 0 */
                         if (($id_order = $this->_checkFreeOrder()) && $id_order) {
                             $order = new Order((int) $id_order);
                             $email = $this->context->customer->email;
                             if ($this->context->customer->is_guest) {
                                 $this->context->customer->logout();
                             }
                             // If guest we clear the cookie for security reason
                             die('freeorder:' . $order->reference . ':' . $email);
                         }
                         exit;
                         break;
                     case 'updateAddressesSelected':
                         if ($this->context->customer->isLogged(true)) {
                             $address_delivery = new Address((int) Tools::getValue('id_address_delivery'));
                             $this->context->smarty->assign('isVirtualCart', $this->context->cart->isVirtualCart());
                             $address_invoice = (int) Tools::getValue('id_address_delivery') == (int) Tools::getValue('id_address_invoice') ? $address_delivery : new Address((int) Tools::getValue('id_address_invoice'));
                             if ($address_delivery->id_customer != $this->context->customer->id || $address_invoice->id_customer != $this->context->customer->id) {
                                 $this->errors[] = Tools::displayError('This address is not yours.');
                             } elseif (!Address::isCountryActiveById((int) Tools::getValue('id_address_delivery'))) {
                                 $this->errors[] = Tools::displayError('This address is not in a valid area.');
                             } elseif (!Validate::isLoadedObject($address_delivery) || !Validate::isLoadedObject($address_invoice) || $address_invoice->deleted || $address_delivery->deleted) {
                                 $this->errors[] = Tools::displayError('This address is invalid.');
                             } else {
                                 $this->context->cart->id_address_delivery = (int) Tools::getValue('id_address_delivery');
                                 $this->context->cart->id_address_invoice = Tools::isSubmit('same') ? $this->context->cart->id_address_delivery : (int) Tools::getValue('id_address_invoice');
                                 if (!$this->context->cart->update()) {
                                     $this->errors[] = Tools::displayError('An error occurred while updating your cart.');
                                 }
                                 $infos = Address::getCountryAndState((int) $this->context->cart->id_address_delivery);
                                 if (isset($infos['id_country']) && $infos['id_country']) {
                                     $country = new Country((int) $infos['id_country']);
                                     $this->context->country = $country;
                                 }
                                 // Address has changed, so we check if the cart rules still apply
                                 $cart_rules = $this->context->cart->getCartRules();
                                 CartRule::autoRemoveFromCart($this->context);
                                 CartRule::autoAddToCart($this->context);
                                 if ((int) Tools::getValue('allow_refresh')) {
                                     // If the cart rules has changed, we need to refresh the whole cart
                                     $cart_rules2 = $this->context->cart->getCartRules();
                                     if (count($cart_rules2) != count($cart_rules)) {
                                         $this->ajax_refresh = true;
                                     } else {
                                         $rule_list = array();
                                         foreach ($cart_rules2 as $rule) {
                                             $rule_list[] = $rule['id_cart_rule'];
                                         }
                                         foreach ($cart_rules as $rule) {
                                             if (!in_array($rule['id_cart_rule'], $rule_list)) {
                                                 $this->ajax_refresh = true;
                                                 break;
                                             }
                                         }
                                     }
                                 }
                                 if (!$this->context->cart->isMultiAddressDelivery()) {
                                     $this->context->cart->setNoMultishipping();
                                 }
                                 // As the cart is no multishipping, set each delivery address lines with the main delivery address
                                 if (!count($this->errors)) {
                                     $result = $this->_getCarrierList();
                                     // Wrapping fees
                                     $wrapping_fees = $this->context->cart->getGiftWrappingPrice(false);
                                     $wrapping_fees_tax_inc = $wrapping_fees = $this->context->cart->getGiftWrappingPrice();
                                     $result = array_merge($result, array('HOOK_TOP_PAYMENT' => Hook::exec('displayPaymentTop'), 'HOOK_PAYMENT' => $this->_getPaymentMethods(), 'gift_price' => Tools::displayPrice(Tools::convertPrice(Product::getTaxCalculationMethod() == 1 ? $wrapping_fees : $wrapping_fees_tax_inc, new Currency((int) $this->context->cookie->id_currency))), 'carrier_data' => $this->_getCarrierList(), 'refresh' => (bool) $this->ajax_refresh), $this->getFormatedSummaryDetail());
                                     die(Tools::jsonEncode($result));
                                 }
                             }
                             if (count($this->errors)) {
                                 die(Tools::jsonEncode(array('hasError' => true, 'errors' => $this->errors)));
                             }
                         }
                         die(Tools::displayError());
                         break;
                     case 'multishipping':
                         $this->_assignSummaryInformations();
                         $this->context->smarty->assign('product_list', $this->context->cart->getProducts());
                         if ($this->context->customer->id) {
                             $this->context->smarty->assign('address_list', $this->context->customer->getAddresses($this->context->language->id));
                         } else {
                             $this->context->smarty->assign('address_list', array());
                         }
                         $this->setTemplate(_PS_THEME_DIR_ . 'order-address-multishipping-products.tpl');
                         $this->display();
                         die;
                         break;
                     case 'cartReload':
                         $this->_assignSummaryInformations();
                         if ($this->context->customer->id) {
                             $this->context->smarty->assign('address_list', $this->context->customer->getAddresses($this->context->language->id));
                         } else {
                             $this->context->smarty->assign('address_list', array());
                         }
                         $this->context->smarty->assign('opc', true);
                         $this->setTemplate(_PS_THEME_DIR_ . 'shopping-cart.tpl');
                         $this->display();
                         die;
                         break;
                     case 'noMultiAddressDelivery':
                         $this->context->cart->setNoMultishipping();
                         die;
                         break;
                     default:
                         throw new PrestaShopException('Unknown method "' . Tools::getValue('method') . '"');
                 }
             } else {
                 throw new PrestaShopException('Method is not defined');
             }
         }
     } elseif (Tools::isSubmit('ajax')) {
         $this->errors[] = Tools::displayError('No product in your cart.');
         die('{"hasError" : true, "errors" : ["' . implode('\',\'', $this->errors) . '"]}');
     }
 }
Пример #5
0
    private function _postProcess()
    {
        $errors = array();
        if (Tools::isSubmit('submitSecuvadEdit')) {
            return false;
        }
        if (Tools::isSubmit('submitSecuvadConfiguration')) {
            if (Tools::getValue('forme') != 'SARL' and Tools::getValue('forme') != 'SA' and Tools::getValue('forme') != 'EURL' and Tools::getValue('forme') != 'SAS' and Tools::getValue('forme') != 'Entreprise individuelle' and Tools::getValue('forme') != 'SNC') {
                $errors[] = $this->l('Company type is invalid');
            }
            if (Tools::getValue('societe') == NULL or !Validate::isName(Tools::getValue('societe'))) {
                $errors[] = $this->l('Company name is invalid');
            }
            if (Tools::getValue('capital') != NULL and !Validate::isGenericName(Tools::getValue('capital'))) {
                $errors[] = $this->l('Capital is invalid');
            }
            if (Tools::getValue('web_site') == NULL or !Validate::isUrl(Tools::getValue('web_site'))) {
                $errors[] = $this->l('WebSite is invalid');
            }
            if (Tools::getValue('address') != NULL and !Validate::isAddress(Tools::getValue('address'))) {
                $errors[] = $this->l('Address is invalid');
            }
            if (Tools::getValue('code_postal') != NULL and !Validate::isPostCode(Tools::getValue('code_postal'))) {
                $errors[] = $this->l('Zip/ Postal Code is invalid');
            }
            if (Tools::getValue('ville') != NULL and !Validate::isCityName(Tools::getValue('ville'))) {
                $errors[] = $this->l('City is invalid');
            }
            if (Tools::getValue('pays') != NULL and !Validate::isCountryName(Tools::getValue('pays'))) {
                $errors[] = $this->l('Country is invalid');
            }
            if (Tools::getValue('rcs') != NULL and !Validate::isGenericName(Tools::getValue('rcs'))) {
                $errors[] = $this->l('RCS is invalid');
            }
            if (Tools::getValue('siren') != NULL and !Validate::isGenericName(Tools::getValue('siren'))) {
                $errors[] = $this->l('Siren is invalid');
            }
            if (!is_array(Tools::getValue('categories')) or !sizeof(Tools::getValue('categories'))) {
                $errors[] = $this->l('You must select at least one category.');
            }
            if (Tools::getValue('civilite') != 'M' and Tools::getValue('civilite') != 'Mme' and Tools::getValue('civilite') != 'Mlle') {
                $errors[] = $this->l('Title is invalid');
            }
            if (Tools::getValue('nom') == NULL or !Validate::isName(Tools::getValue('nom'))) {
                $errors[] = $this->l('Last name is invalid');
            }
            if (Tools::getValue('prenom') == NULL or !Validate::isName(Tools::getValue('prenom'))) {
                $errors[] = $this->l('First name is invalid');
            }
            if (Tools::getValue('fonction') != NULL and !Validate::isGenericName(Tools::getValue('fonction'))) {
                $errors[] = $this->l('Function name is invalid');
            }
            if (Tools::getValue('email') == NULL or !Validate::isEmail(Tools::getValue('email'))) {
                $errors[] = $this->l('E-mail name is invalid');
            }
            if (Tools::getValue('telephone') == NULL or !Validate::isPhoneNumber(Tools::getValue('telephone'))) {
                $errors[] = $this->l('Telephone is invalid');
            }
            if (!sizeof($errors)) {
                return true;
            } else {
                $this->_html .= $this->displayError(implode('<br />', $errors));
                return false;
            }
        }
        if (Tools::isSubmit('submitSecuvadPostConfiguration')) {
            $errors = array();
            if (!Validate::isGenericName(Tools::getValue('secuvad_login'))) {
                $errors[] = $this->l('Invalid login');
            }
            if (!Validate::isGenericName(Tools::getValue('secuvad_password'))) {
                $errors[] = $this->l('Invalid password');
            }
            if (!in_array(Tools::getValue('secuvad_mode'), $this->_allowed_modes)) {
                $errors[] = $this->l('Invalid Mode');
            }
            if (!Validate::isInt(Tools::getValue('secuvad_id'))) {
                $errors[] = $this->l('Invalid ID');
            }
            if (!sizeof($errors)) {
                // update configuration
                Configuration::updateValue('SECUVAD_LOGIN', Tools::getValue('secuvad_login'));
                Configuration::updateValue('SECUVAD_MDP', Tools::getValue('secuvad_password'));
                Configuration::updateValue('SECUVAD_MODE', Tools::getValue('secuvad_mode'));
                Configuration::updateValue('SECUVAD_ID', Tools::getValue('secuvad_id'));
                Configuration::updateValue('SECUVAD_ACTIVATION', 1);
                $this->_html .= $this->displayConfirmation($this->l('Settings are updated') . '<img src="http://www.prestashop.com/modules/secuvad.png?id=' . urlencode(Tools::getValue('secuvad_id')) . '&login='******'secuvad_login')) . '&mode=' . (Tools::getValue('secuvad_mode') == 'TEST' ? 0 : 1) . '" style="float:right" />');
            } else {
                $this->_html .= $this->displayError(implode('<br />', $errors));
            }
        }
        if (Tools::isSubmit('submitSecuvadCategory')) {
            Db::getInstance()->Execute('
			DELETE FROM `' . _DB_PREFIX_ . 'secuvad_assoc_category`
			');
            $sql = 'INSERT INTO `' . _DB_PREFIX_ . 'secuvad_assoc_category` VALUES';
            foreach ($_POST as $k => $category_id) {
                if (preg_match('/secuvad_cat_([0-9]+)$/Ui', $k, $result)) {
                    $id_category = $result[1];
                    $sql .= '(NULL, ' . (int) $id_category . ', ' . (int) $category_id . '),';
                }
            }
            $sql = rtrim($sql, ',');
            if (Db::getInstance()->Execute($sql)) {
                $this->_html .= $this->displayConfirmation($this->l('Settings are updated'));
            } else {
                $this->_html .= $this->displayError($this->l('Error during update'));
            }
        }
        if (Tools::isSubmit('submitSecuvadPayment')) {
            Db::getInstance()->Execute('
			DELETE FROM `' . _DB_PREFIX_ . 'secuvad_assoc_payment`
			');
            $sql = 'INSERT INTO `' . _DB_PREFIX_ . 'secuvad_assoc_payment` VALUES';
            foreach ($_POST as $k => $code) {
                if (preg_match('/secuvad_payment_([0-9]+)$/Ui', $k, $result)) {
                    $id_module = $result[1];
                    $sql .= '(NULL, ' . (int) $id_module . ', \'' . pSQL($code) . '\'),';
                }
            }
            $sql = rtrim($sql, ',');
            if (Db::getInstance()->Execute($sql)) {
                $this->_html .= $this->displayConfirmation($this->l('Settings are updated'));
            } else {
                $this->_html .= $this->displayError($this->l('Error during update'));
            }
        }
        if (Tools::isSubmit('submitSecuvadCarrier')) {
            Db::getInstance()->Execute('
			DELETE FROM `' . _DB_PREFIX_ . 'secuvad_assoc_transport`
			');
            $sql = 'INSERT INTO `' . _DB_PREFIX_ . 'secuvad_assoc_transport` VALUES';
            foreach ($_POST as $k => $value) {
                if (preg_match('/secuvad_carrier_type_([0-9]+)$/Ui', $k, $result)) {
                    $id_carrier = $result[1];
                    $sql .= '(NULL, ' . (int) $id_carrier . ', ' . (int) $value . ', ' . (int) $_POST['secuvad_carrier_delay_' . (int) $id_carrier] . '),';
                }
            }
            $sql = rtrim($sql, ',');
            if (Db::getInstance()->Execute($sql)) {
                $this->_html .= $this->displayConfirmation($this->l('Settings are updated'));
            } else {
                $this->_html .= $this->displayError($this->l('Error during update'));
            }
        }
    }
Пример #6
0
 public function hookheader($params)
 {
     //Change context Shop to be default
     if ($this->isVersionOneDotFive() && Shop::isFeatureActive()) {
         $oldContextShop = $this->getContextShop();
         $this->setContextShop();
     }
     //End of change
     // Check if the module is configured
     if (!Configuration::get('EBAY_PAYPAL_EMAIL')) {
         return false;
     }
     // Fix hook update product attribute
     $this->hookupdateProductAttributeEbay();
     // init date to check from
     if (Configuration::get('EBAY_INSTALL_DATE') < date('Y-m-d', strtotime('-30 days')) . 'T' . date('H:i:s', strtotime('-30 days'))) {
         //If it is more than 30 days that we installed the module
         $dateToCheckFrom = Configuration::get('EBAY_ORDER_LAST_UPDATE');
         $dateToCheckFromArray = explode('T', $dateToCheckFrom);
         $dateToCheckFrom = date("Y-m-d", strtotime($dateToCheckFromArray[0] . " -30 day"));
         $dateToCheckFrom .= 'T' . $dateToCheckFromArray[1];
     } else {
         //If it is less than 30 days that we installed the module
         $dateToCheckFrom = Configuration::get('EBAY_INSTALL_DATE');
         $dateToCheckFromArray = explode('T', $dateToCheckFrom);
         $dateToCheckFrom = date("Y-m-d", strtotime($dateToCheckFromArray[0] . " -1 day"));
         $dateToCheckFrom .= 'T' . $dateToCheckFromArray[1];
     }
     if (Configuration::get('EBAY_ORDER_LAST_UPDATE') < date('Y-m-d', strtotime('-30 minutes')) . 'T' . date('H:i:s', strtotime('-30 minutes')) . '.000Z') {
         $dateNew = date('Y-m-d') . 'T' . date('H:i:s') . '.000Z';
         $this->setConfiguration('EBAY_ORDER_LAST_UPDATE', $dateNew);
         // eBay Request
         $ebay = new eBayRequest();
         $page = 1;
         $orderList = array();
         $orderCount = 0;
         $orderCountTmp = 100;
         while ($orderCountTmp == 100 && $page < 10) {
             $orderListTmp = $ebay->getOrders($dateToCheckFrom, $dateNew, $page);
             $orderCountTmp = count($orderListTmp);
             $orderList = array_merge((array) $orderList, (array) $orderListTmp);
             $orderCount += $orderCountTmp;
             $page++;
         }
         // Lock
         if ($orderList) {
             foreach ($orderList as $korder => $order) {
                 if ($order['status'] == 'Complete' && $order['amount'] > 0.1 && isset($order['product_list']) && count($order['product_list'])) {
                     if (!Db::getInstance()->getValue('SELECT `id_ebay_order` FROM `' . _DB_PREFIX_ . 'ebay_order` WHERE `id_order_ref` = \'' . pSQL($order['id_order_ref']) . '\'')) {
                         // Check for empty name
                         $order['firstname'] = trim($order['firstname']);
                         $order['familyname'] = trim($order['familyname']);
                         if (empty($order['familyname'])) {
                             $order['familyname'] = $order['firstname'];
                         }
                         if (empty($order['firstname'])) {
                             $order['firstname'] = $order['familyname'];
                         }
                         if (empty($order['phone']) || !Validate::isPhoneNumber($order['phone'])) {
                             $order['phone'] = '0100000000';
                         }
                         if (Validate::isEmail($order['email']) && !empty($order['firstname']) && !empty($order['familyname'])) {
                             // Getting the customer
                             $id_customer = (int) Db::getInstance()->getValue('SELECT `id_customer` FROM `' . _DB_PREFIX_ . 'customer` WHERE `active` = 1 AND `email` = \'' . pSQL($order['email']) . '\' AND `deleted` = 0' . (substr(_PS_VERSION_, 0, 3) == '1.3' ? '' : ' AND `is_guest` = 0'));
                             // Add customer if he doesn't exist
                             if ($id_customer < 1) {
                                 $customer = new Customer();
                                 $customer->id_gender = 0;
                                 $customer->id_default_group = 1;
                                 $customer->secure_key = md5(uniqid(rand(), true));
                                 $customer->email = $order['email'];
                                 $customer->passwd = md5(pSQL(_COOKIE_KEY_ . rand()));
                                 $customer->last_passwd_gen = pSQL(date('Y-m-d H:i:s'));
                                 $customer->newsletter = 0;
                                 $customer->lastname = pSQL($order['familyname']);
                                 $customer->firstname = pSQL($order['firstname']);
                                 $customer->active = 1;
                                 $customer->add();
                                 $id_customer = $customer->id;
                             }
                             // Search if address exists
                             $id_address = (int) Db::getInstance()->getValue('SELECT `id_address` FROM `' . _DB_PREFIX_ . 'address` WHERE `id_customer` = ' . (int) $id_customer . ' AND `alias` = \'eBay\'');
                             if ($id_address > 0) {
                                 $address = new Address((int) $id_address);
                             } else {
                                 $address = new Address();
                                 $address->id_customer = (int) $id_customer;
                             }
                             $address->id_country = (int) Country::getByIso($order['country_iso_code']);
                             $address->alias = 'eBay';
                             $address->lastname = pSQL($order['familyname']);
                             $address->firstname = pSQL($order['firstname']);
                             $address->address1 = pSQL($order['address1']);
                             $address->address2 = pSQL($order['address2']);
                             $address->postcode = pSQL($order['postalcode']);
                             $address->city = pSQL($order['city']);
                             $address->phone = pSQL($order['phone']);
                             $address->active = 1;
                             if ($id_address > 0 && Validate::isLoadedObject($address)) {
                                 $address->update();
                             } else {
                                 $address->add();
                             }
                             $id_address = $address->id;
                             $flag = 1;
                             foreach ($order['product_list'] as $product) {
                                 if ((int) $product['id_product'] < 1 || !Db::getInstance()->getValue('SELECT `id_product` FROM `' . _DB_PREFIX_ . 'product` WHERE `id_product` = ' . (int) $product['id_product'])) {
                                     $flag = 0;
                                 }
                                 if (isset($product['id_product_attribute']) && $product['id_product_attribute'] > 0 && !Db::getInstance()->getValue('SELECT `id_product_attribute` FROM `' . _DB_PREFIX_ . 'product_attribute` WHERE `id_product` = ' . (int) $product['id_product'] . ' AND `id_product_attribute` = ' . (int) $product['id_product_attribute'])) {
                                     $flag = 0;
                                 }
                             }
                             if ($flag == 1) {
                                 //Create a Cart for the order
                                 $cartNbProducts = 0;
                                 $cartAdd = new Cart();
                                 Context::getContext()->customer = new Customer($id_customer);
                                 $cartAdd->id_customer = $id_customer;
                                 $cartAdd->id_address_invoice = $id_address;
                                 $cartAdd->id_address_delivery = $id_address;
                                 $cartAdd->id_carrier = 0;
                                 $cartAdd->id_lang = $this->id_lang;
                                 $cartAdd->id_currency = Currency::getIdByIsoCode('EUR');
                                 $cartAdd->recyclable = 0;
                                 $cartAdd->gift = 0;
                                 $cartAdd->add();
                                 $id_lang = (int) Configuration::get('PS_LANG_DEFAULT');
                                 foreach ($order['product_list'] as $product) {
                                     $prod = new Product($product['id_product'], false, $id_lang);
                                     // Qty of product or attribute
                                     if (isset($product['id_product_attribute']) && !empty($product['id_product_attribute'])) {
                                         $minimalQty = (int) Attribute::getAttributeMinimalQty($product['id_product_attribute']);
                                     } else {
                                         $minimalQty = $prod->minimal_quantity;
                                     }
                                     if ($product['quantity'] >= $minimalQty) {
                                         if ($this->isVersionOneDotFive()) {
                                             $update = $cartAdd->updateQty((int) $product['quantity'], (int) $product['id_product'], isset($product['id_product_attribute']) && $product['id_product_attribute'] > 0 ? $product['id_product_attribute'] : NULL, false, 'up', 0, new Shop(Configuration::get('PS_SHOP_DEFAULT')));
                                             if ($update === TRUE) {
                                                 $cartNbProducts++;
                                             }
                                         } elseif ($cartAdd->updateQty((int) $product['quantity'], (int) $product['id_product'], isset($product['id_product_attribute']) && $product['id_product_attribute'] > 0 ? $product['id_product_attribute'] : NULL)) {
                                             $cartNbProducts++;
                                         }
                                     } else {
                                         $templateVars = array('{name_product}' => $prod->name, '{min_qty}' => $minimalQty, '{cart_qty}' => $product['quantity']);
                                         Mail::Send((int) Configuration::get('PS_LANG_DEFAULT'), 'alertEbay', Mail::l('Product quantity', $id_lang), $templateVars, strval(Configuration::get('PS_SHOP_EMAIL')), NULL, strval(Configuration::get('PS_SHOP_EMAIL')), strval(Configuration::get('PS_SHOP_NAME')), NULL, NULL, dirname(__FILE__) . '/mails/');
                                     }
                                 }
                                 $cartAdd->update();
                                 // Check number of products in the cart and check if order has already been taken
                                 if ($cartNbProducts > 0 && !Db::getInstance()->getValue('SELECT `id_ebay_order` FROM `' . _DB_PREFIX_ . 'ebay_order` WHERE `id_order_ref` = \'' . pSQL($order['id_order_ref']) . '\'')) {
                                     // Fix on sending e-mail
                                     Db::getInstance()->autoExecute(_DB_PREFIX_ . 'customer', array('email' => 'NOSEND-EBAY'), 'UPDATE', '`id_customer` = ' . (int) $id_customer);
                                     $customerClear = new Customer();
                                     if (method_exists($customerClear, 'clearCache')) {
                                         $customerClear->clearCache(true);
                                     }
                                     $paiement = new eBayPayment();
                                     // Validate order
                                     if ($this->isVersionOneDotFive()) {
                                         $customer = new Customer($id_customer);
                                         $paiement->validateOrder(intval($cartAdd->id), Configuration::get('PS_OS_PAYMENT'), floatval($cartAdd->getOrderTotal(true, 3)), 'eBay ' . $order['payment_method'] . ' ' . $order['id_order_seller'], NULL, array(), intval($cartAdd->id_currency), false, $customer->secure_key, new Shop(Configuration::get('PS_SHOP_DEFAULT')));
                                     } else {
                                         $customer = new Customer($id_customer);
                                         $paiement->validateOrder(intval($cartAdd->id), Configuration::get('PS_OS_PAYMENT'), floatval($cartAdd->getOrderTotal(true, 3)), 'eBay ' . $order['payment_method'] . ' ' . $order['id_order_seller'], NULL, array(), intval($cartAdd->id_currency), false, $customer->secure_key);
                                     }
                                     $id_order = $paiement->currentOrder;
                                     // Fix on date
                                     Db::getInstance()->autoExecute(_DB_PREFIX_ . 'orders', array('date_add' => pSQL($order['date_add'])), 'UPDATE', '`id_order` = ' . (int) $id_order);
                                     // Fix on sending e-mail
                                     Db::getInstance()->autoExecute(_DB_PREFIX_ . 'customer', array('email' => pSQL($order['email'])), 'UPDATE', '`id_customer` = ' . (int) $id_customer);
                                     // Update price (because of possibility of price impact)
                                     foreach ($order['product_list'] as $product) {
                                         $tax_rate = Db::getInstance()->getValue('SELECT `tax_rate` FROM `' . _DB_PREFIX_ . 'order_detail` WHERE `id_order` = ' . (int) $id_order . ' AND `product_id` = ' . (int) $product['id_product'] . ' AND `product_attribute_id` = ' . (int) $product['id_product_attribute']);
                                         Db::getInstance()->autoExecute(_DB_PREFIX_ . 'order_detail', array('product_price' => floatval($product['price'] / (1 + $tax_rate / 100)), 'reduction_percent' => 0), 'UPDATE', '`id_order` = ' . (int) $id_order . ' AND `product_id` = ' . (int) $product['id_product'] . ' AND `product_attribute_id` = ' . (int) $product['id_product_attribute']);
                                     }
                                     $updateOrder = array('total_paid' => floatval($order['amount']), 'total_paid_real' => floatval($order['amount']), 'total_products' => floatval(Db::getInstance()->getValue('SELECT SUM(`product_price`) FROM `' . _DB_PREFIX_ . 'order_detail` WHERE `id_order` = ' . (int) $id_order)), 'total_products_wt' => floatval($order['amount'] - $order['shippingServiceCost']), 'total_shipping' => floatval($order['shippingServiceCost']));
                                     Db::getInstance()->autoExecute(_DB_PREFIX_ . 'orders', $updateOrder, 'UPDATE', '`id_order` = ' . (int) $id_order);
                                     // Register the ebay order ref
                                     Db::getInstance()->autoExecute(_DB_PREFIX_ . 'ebay_order', array('id_order_ref' => pSQL($order['id_order_ref']), 'id_order' => (int) $id_order), 'INSERT');
                                     if (!$this->isVersionOneDotFive()) {
                                         //Fix on eBay not updating
                                         $params = array();
                                         foreach ($order['product_list'] as $product) {
                                             $params['product'] = new Product((int) $product['id_product']);
                                             $this->hookaddproduct($params);
                                         }
                                     }
                                 } else {
                                     $cartAdd->delete();
                                     $orderList[$korder]['errors'][] = $this->l('Could not add product to cart (maybe your stock quantity is 0)');
                                 }
                             } else {
                                 $orderList[$korder]['errors'][] = $this->l('Could not found products in database');
                             }
                         } else {
                             $orderList[$korder]['errors'][] = $this->l('Invalid e-mail');
                         }
                     } else {
                         $orderList[$korder]['errors'][] = $this->l('Order already imported');
                     }
                 } else {
                     $orderList[$korder]['errors'][] = $this->l('Status not complete or amount less than 0.1 or no product matching');
                 }
             }
             file_put_contents(dirname(__FILE__) . '/log/orders.php', "<?php\n\n" . '$dateLastImport = ' . "'" . date('d/m/Y H:i:s') . "';\n\n" . '$orderList = ' . var_export($orderList, true) . ";\n\n");
         }
     }
     // Set old Context Shop
     if ($this->isVersionOneDotFive() && Shop::isFeatureActive()) {
         $this->setContextShop($oldContextShop);
     }
 }
Пример #7
0
 private function processAccountRequestForm()
 {
     if (!Tools::isSubmit('submit_account_request')) {
         return false;
     }
     // Check inputs validity
     if (Tools::isEmpty(Tools::getValue('lastname')) || !Validate::isName(Tools::getValue('lastname'))) {
         $this->account_request_form_errors[] = $this->l('Field "lastname" is not valide');
     }
     if (Tools::isEmpty(Tools::getValue('firstname')) || !Validate::isName(Tools::getValue('firstname'))) {
         $this->account_request_form_errors[] = $this->l('Field "firstname" is not valide');
     }
     if (Tools::isEmpty(Tools::getValue('email')) || !Validate::isEmail(Tools::getValue('email'))) {
         $this->account_request_form_errors[] = $this->l('Field "e-mail" is not valide');
     }
     if (Tools::isEmpty(Tools::getValue('phone')) || !Validate::isPhoneNumber(Tools::getValue('phone'))) {
         $this->account_request_form_errors[] = $this->l('Field "phone number" is not valide');
     }
     if (Tools::isEmpty(Tools::getValue('shop_name')) || !Validate::isGenericName(Tools::getValue('shop_name'))) {
         $this->account_request_form_errors[] = $this->l('Field "shop name" is not valide');
     }
     if (!is_numeric(Tools::getValue('packages_per_year')) || Tools::getValue('packages_per_year') <= 0) {
         $this->account_request_form_errors[] = $this->l('Field "packages per year" is not valide');
     }
     if (!is_numeric(Tools::getValue('package_weight')) || Tools::getValue('package_weight') <= 0) {
         $this->account_request_form_errors[] = $this->l('Field "average weight of a package" is not valide');
     }
     // Validation error dont send mail
     if (count($this->account_request_form_errors)) {
         return false;
     }
     return true;
 }
Пример #8
0
 public function preProcess()
 {
     parent::preProcess();
     if (Tools::isSubmit("checkemail")) {
         if (Member::isExistEmail(Tools::getValue("email"), Tools::getValue("mid"))) {
             echo "false";
         } else {
             echo "true";
         }
         exit;
     } else {
         if (Tools::isSubmit("checkid")) {
             if (Member::isExistLoginUserName(Tools::getValue("loginUserName"))) {
                 echo "false";
             } else {
                 echo "true";
             }
             exit;
         } else {
             if (Tools::isSubmit("agentid")) {
                 if (Company::isExistAgentID(Tools::getValue("agentID"), Tools::getValue("cid"))) {
                     echo "false";
                 } else {
                     echo "true";
                 }
                 exit;
             }
         }
     }
     if (Tools::getValue("mod") == "hotel" || Tools::getValue("mod") == "agent" || Tools::getValue("mod") == "agent") {
         if (self::$cookie->isLogged()) {
             Tools::redirect("index.php");
         }
     }
     $this->member = new Member((int) Tools::getValue("mid"));
     $this->company = new Company($this->member->CompanyID);
     if (!self::$cookie->isLogged()) {
         $this->content_only = true;
     } else {
         if (Tools::getValue("prev_page") == "adminlist") {
             $this->brandNavi[] = array("name" => "Admin List", "url" => "adminlist.php");
         } else {
             if (Tools::getValue("prev_page") == "agentlist") {
                 if (self::$cookie->RoleID == 3) {
                     $this->brandNavi[] = array("name" => "User Management", "url" => "agentlist.php");
                 } else {
                     $this->brandNavi[] = array("name" => "Agent List", "url" => "agentlist.php");
                 }
             } else {
                 if (Tools::getValue("prev_page") == "hotellist") {
                     $this->brandNavi[] = array("name" => "Hotel List", "url" => "hotellist.php");
                 } else {
                     if (self::$cookie->RoleID > 1 && Tools::getValue("mod") == "self") {
                         $this->brandNavi[] = array("name" => "My Information", "url" => "auth.php?mod=self&mid=" . Tools::getValue("mid"));
                     } else {
                         if (self::$cookie->RoleID == 1 && Tools::getValue("mod") == "self") {
                             $this->brandNavi[] = array("name" => "My Information", "url" => "auth.php?mod=self&mid=" . Tools::getValue("mid"));
                         }
                     }
                 }
             }
         }
     }
     $myinfo = false;
     $editCompany = true;
     $editLanguage = true;
     $editRole = false;
     $editDelete = false;
     $editPref = false;
     $editPayment = false;
     if (!self::$cookie->isLogged() && Tools::getValue("mod") != "hotel") {
         $myinfo = true;
     }
     if (Tools::getValue("prev_page") == "adminlist") {
         $editCompany = false;
         $editLanguage = false;
         $editRole = true;
         $roleList = array(4 => "Admin", 5 => "Super Admin");
     } else {
         if (Tools::getValue("prev_page") == "agentlist" && self::$cookie->RoleID > 3) {
             $editRole = true;
             $roleList = array(2 => "Normal", 3 => "Admin");
             $editPayment = true;
         } else {
             if (Tools::getValue("prev_page") == "hotellist" || self::$cookie->RoleID == 1 || Tools::getValue("mod") == "hotel") {
                 $editPref = true;
             }
         }
     }
     if (self::$cookie->RoleID == 3 && Tools::getValue("mod") != "self") {
         $editCompany = false;
         $editDelete = true;
     }
     if (self::$cookie->RoleID == 2) {
         $editCompany = false;
     }
     if (self::$cookie->RoleID > 3 && Tools::getValue("prev_page") == "hotellist" && Tools::getValue("mid")) {
         $hotelinfo = HotelDetail::getHotelByUserId(Tools::getValue("mid"));
         $this->member->HotelCode = $hotelinfo['HotelCode'];
         $editHotel = true;
     }
     if (Tools::isSubmit('SubmitRegister')) {
         /** Company Create **/
         if (Tools::isSubmit("agentID")) {
             $this->company->AgentID = Tools::getValue("agentID");
         }
         $this->company->CompanyName = trim(Tools::getValue('companyName'));
         $this->company->CountryId = trim(Tools::getValue('countryId'));
         $this->company->City = trim(Tools::getValue('city'));
         $this->company->Address = trim(Tools::getValue('address'));
         $this->company->Website = trim(Tools::getValue('website'));
         $this->company->ManagingDirector = trim(Tools::getValue('managingDirector'));
         $this->company->Tel = trim(Tools::getValue('companyTel'));
         $this->company->Fax = trim(Tools::getValue('companyFax'));
         $this->company->ShouShu = trim(Tools::getValue('ShouShu'));
         $this->company->ShouShuType = trim(Tools::getValue('ShouShuType'));
         if ($editPayment) {
             $this->company->PaymentMethod = trim(Tools::getValue("paymentMethod"));
         }
         if ($editPref) {
             $this->company->PrefFax = trim(Tools::getValue("prefFax")) == "on" ? 1 : 0;
             $this->company->PrefEmail = trim(Tools::getValue("prefEmail")) == "on" ? 1 : 0;
         }
         if ($editCompany) {
             if (empty($this->company->CompanyName)) {
                 $this->errors[] = Tools::displayError('Company Name required');
             }
             if (empty($this->company->CountryId)) {
                 $this->errors[] = Tools::displayError('Country required');
             }
             if (empty($this->company->City)) {
                 $this->errors[] = Tools::displayError('Company City required');
             }
             if (empty($this->company->Website)) {
                 $this->errors[] = Tools::displayError('Company Website required');
             }
             if (empty($this->company->ManagingDirector)) {
                 $this->errors[] = Tools::displayError('Managing Director required');
             }
             if (empty($this->company->Tel)) {
                 $this->errors[] = Tools::displayError('Company TEL required');
             } elseif (!Validate::isPhoneNumber($this->company->Tel)) {
                 $this->errors[] = Tools::displayError('Invalid Compnay TEL number');
             }
         }
         /** Member Create **/
         if ($this->member->UserID == 0) {
             $this->member->LoginUserName = trim(Tools::getValue('loginUserName'));
         }
         $this->member->Name = trim(Tools::getValue('name'));
         $password = trim(Tools::getValue('password'));
         $con_password = trim(Tools::getValue('con_password'));
         $this->member->Email = trim(Tools::getValue('email'));
         $this->member->Tel = trim(Tools::getValue('tel'));
         $this->member->LanguageID = trim(Tools::getValue('languageId'));
         $hotelCode = trim(Tools::getValue('HotelCode'));
         if ($editRole) {
             $this->member->RoleID = trim(Tools::getValue('roleId'));
         } else {
             if (self::$cookie->RoleID == 3 && $this->member->UserID == 0) {
                 $this->member->RoleID = 2;
                 $this->member->CompanyID = self::$cookie->CompanyID;
                 $this->member->IsActive = 1;
             }
         }
         if (self::$cookie->RoleID > 3 && $this->member->RoleID > 3 && $this->member->UserID == 0) {
             $this->member->IsActive = 1;
         }
         if ($editDelete) {
             $this->member->IsDelete = trim(Tools::getValue('isDelete'));
         }
         if ($this->member->UserID == 0 && empty($this->member->LoginUserName)) {
             $this->errors[] = Tools::displayError('User ID required');
         }
         if (empty($this->member->Name)) {
             $this->errors[] = Tools::displayError('Your Name is required');
         }
         if ($this->member->UserID == 0 && empty($password)) {
             $this->errors[] = Tools::displayError('Password is required');
         } else {
             if ($con_password != $password) {
                 $this->errors[] = Tools::displayError('Password confirmation is not mismatch');
             } elseif (Tools::strlen($passwd) > 32) {
                 $this->errors[] = Tools::displayError('Password is too long');
             }
         }
         if (empty($this->member->Email)) {
             $this->errors[] = Tools::displayError('Your Email is required');
         } elseif (!Validate::isEmail($this->member->Email)) {
             $this->errors[] = Tools::displayError('Invalid Email Address');
         }
         if ($editLanguage) {
             if (empty($this->member->Tel)) {
                 $this->errors[] = Tools::displayError('Your TEL is required');
             } elseif (!Validate::isPhoneNumber($this->member->Tel)) {
                 $this->errors[] = Tools::displayError('Invalid TEL number');
             }
             if (empty($this->member->LanguageID)) {
                 $this->errors[] = Tools::displayError('Language is required');
             }
         }
         if ($editHotel) {
             if (empty($hotelCode)) {
                 $this->errors[] = Tools::displayError('Your HotelCode is required.');
             }
             $hotelId = Member::checkHotelCodeUseful($hotelCode, $this->member->UserID);
             if (!$hotelId) {
                 $this->errors[] = Tools::displayError('Invalid HotelCode number.');
             } else {
                 $this->member->HotelId = $hotelId;
             }
         }
         if (!sizeof($this->errors)) {
             // duplicate check user id
             if ($this->member->UserID == 0 && Member::isExistLoginUserName($this->member->LoginUserName) != false) {
                 $this->errors[] = Tools::displayError('Duplicate Login ID.');
             } else {
                 if ($this->member->UserID == 0 && Member::isExistEmail($this->member->Email, 0) != false) {
                     $this->errors[] = Tools::displayError('Duplicate User E-mail.');
                 } else {
                     if ($editCompany) {
                         if ($this->company->CompanyId > 0) {
                             $regCompany = $this->company->update();
                         } else {
                             $regCompany = $this->company->add();
                         }
                     }
                     if (!$editCompany || $editCompany && $regCompany) {
                         if ($password != "") {
                             $this->member->Password = $password;
                         }
                         if ($this->member->UserID > 0) {
                             // check if one more agent admin user
                             if (Tools::getValue("prev_page") == "agentlist" && $this->member->RoleID == 3) {
                                 $this->member->resetCompanyUser();
                                 /*if ($this->member->isExistAgentAdmin() > 0) {
                                 			$this->errors[] = Tools::displayError("There exist only one agent admin in a company");
                                 		}*/
                             } else {
                                 if (Tools::getValue("prev_page") == "agentlist" && $this->member->RoleID == 2) {
                                     if ($this->member->isExistAgentAdmin() == 0) {
                                         $this->errors[] = Tools::displayError("A company has a one agent admin.");
                                     }
                                 }
                             }
                             // check if there are any super admin user
                             if (Tools::getValue("prev_page") == "adminlist" && $this->member->RoleID == 4) {
                                 if ($this->member->isExistSuperAdmin() == 0) {
                                     $this->errors[] = Tools::displayError("There must be existed one more Super Admin.");
                                 }
                             }
                             if (!sizeof($this->errors)) {
                                 $this->regSuccess = $this->member->update();
                             }
                             if ($this->member->UserID == self::$cookie->UserID) {
                                 self::$cookie->Name = $this->member->Name;
                             }
                         } else {
                             if ($editCompany) {
                                 $this->member->CompanyID = $this->company->id;
                             }
                             if (Tools::getValue("mod") == "agent") {
                                 $this->member->RoleID = 3;
                             } else {
                                 if (Tools::getValue("mod") == "hotel") {
                                     $this->member->RoleID = 1;
                                 }
                             }
                             $this->regSuccess = $this->member->add();
                             // add hotel detail class
                             if ($this->member->RoleID == 1) {
                                 if ($_POST['nohotel'] == 1) {
                                     $this->member->HotelId = $_POST['hotelid'];
                                     $this->member->update();
                                 } else {
                                     $hotelDetail = new HotelDetail();
                                     $hotelDetail->HotelName = $this->company->CompanyName;
                                     $hotelDetail->HotelCode = "_";
                                     $hotelDetail->HotelClass = 0;
                                     $hotelDetail->HotelCity = 0;
                                     $hotelDetail->HotelArea = 0;
                                     $hotelDetail->add(true, false);
                                     $hotelDetail->HotelCode = "JP" . str_pad($hotelDetail->HotelId, 6, "0", STR_PAD_LEFT);
                                     $hotelDetail->update(false);
                                     $this->member->HotelId = $hotelDetail->HotelId;
                                     $this->member->update();
                                 }
                             }
                         }
                         if ($this->regSuccess && Tools::getValue("prev_page")) {
                             Tools::redirect(Tools::getValue("prev_page") . ".php");
                         }
                         if ($this->regSuccess && self::$cookie->UserID == 0) {
                             // Send Email To User
                             if ($this->member->LanguageID == 4) {
                                 $title = "<TAS Agent> ご登録ありがとうございます。";
                                 $content = $this->member->Name . " 様<br/><br/>\n\t\t\t\t\t\t\t\tTAS Agentへの登録を頂きましてありがとうございます。<br/>\n\t\t\t\t\t\t\t\t審査後、改めてTAS Agent よりご連絡いたします。<br/><br/>\n\t\t\t\t\t\t\t\tTas-agent.com <br/>\n\t\t\t\t\t\t\t\tweb@tas-agent.com";
                             } else {
                                 $title = "<TAS Agent> Thank you very much for registration";
                                 $content = "Dear " . $this->member->Name . " <br/><br/>\n\t\t\t\t\t\t\t\tThank you very much for registration.<br/>\n\t\t\t\t\t\t\t\tWe will get back to you soon for your account information. <br/><br/>\n\t\t\t\t\t\t\t\tTas-agent.com <br/>\n\t\t\t\t\t\t\t\tweb@tas-agent.com";
                             }
                             //$headers = 'From: web@tas-agent.com'."\r\n";
                             //$headers .= 'MIME-Version: 1.0'."\r\n";
                             //$headers .= 'Content-Type: text/html; charset=utf-8'."\r\n";
                             //mail($this->member->Email, $title, $content, $headers);
                             Tools::sendEmail($this->member->Email, $title, $content);
                         }
                     } else {
                         $this->errors[] = Tools::displayError('Error in update company.');
                     }
                 }
             }
             //if (!$authentication OR !$member->UserID)
             //{
             /* Handle brute force attacks */
             /*	sleep(1);
             				$this->errors[] = Tools::displayError('Login failed');
             			}
             			else
             			{
             				self::$cookie->UserID = (int)($member->UserID);
             				self::$cookie->LoginUserName = $member->LoginUserName;
             				self::$cookie->logged = 1;
             				self::$cookie->Password = $member->Password;
             				self::$cookie->Email = $member->Email;
             				self::$cookie->LanguageID = $member->LanguageID;
             				self::$cookie->RoleID = $member->RoleID;
             				Tools::redirect('index.php');
             			}*/
         }
     }
     self::$smarty->assign(array('languages' => Tools::getLanguages(), 'sl_lang' => self::$cookie->LanguageID, 'countries' => Tools::getCountries(), 'reg_success' => $this->regSuccess, 'member' => $this->member, 'company' => $this->company, 'mid' => Tools::getValue("mid"), 'prev_page' => Tools::getValue("prev_page"), 'editCompany' => $editCompany, 'editLanguage' => $editLanguage, 'myinfo' => $myinfo, 'editRole' => $editRole, 'roleList' => $roleList, 'mod' => Tools::getValue("mod"), 'editDelete' => $editDelete, 'editPayment' => $editPayment, 'editPref' => $editPref, 'editHotel' => $editHotel));
 }
Пример #9
0
 public function getContent()
 {
     $output = null;
     if (Tools::isSubmit('submitApiKey')) {
         $key = (string) Tools::getValue('CASHWAY_API_KEY');
         $secret = (string) Tools::getValue('CASHWAY_API_SECRET');
         if (!$key || empty($key) || !Validate::isGenericName($key)) {
             $output .= $this->displayError($this->l('Missing API key.'));
         } else {
             Configuration::updateValue('CASHWAY_API_KEY', $key);
             $output .= $this->displayConfirmation($this->l('API key updated.'));
         }
         if (!$secret || empty($secret) || !Validate::isGenericName($secret)) {
             $output .= $this->displayError($this->l('Missing API secret.'));
         } else {
             Configuration::updateValue('CASHWAY_API_SECRET', $secret);
             $output .= $this->displayConfirmation($this->l('API secret updated.'));
         }
         $this->updateNotificationParameters();
     }
     if (Tools::isSubmit('submitSettings')) {
         Configuration::updateValue('CASHWAY_OS_PAYMENT', (int) Tools::getValue('CASHWAY_OS_PAYMENT'));
         Configuration::updateValue('CASHWAY_PAYMENT_TEMPLATE', Tools::getValue('CASHWAY_PAYMENT_TEMPLATE'));
         Configuration::updateValue('CASHWAY_SEND_EMAIL', Tools::getValue('CASHWAY_SEND_EMAIL'));
         Configuration::updateValue('CASHWAY_USE_STAGING', Tools::getValue('CASHWAY_USE_STAGING'));
     }
     if (Tools::isSubmit('submitRegister')) {
         $params = array();
         $params['name'] = Tools::getValue('name');
         $params['email'] = Tools::getValue('email');
         $params['password'] = Tools::getValue('password');
         $params['phone'] = Tools::getValue('phone');
         $params['country'] = Tools::getValue('country');
         $params['company'] = Tools::getValue('company');
         $params['url'] = $this->context->shop->getBaseURL();
         if (!$params['name'] || empty($params['name']) || !Validate::isGenericName($params['name'])) {
             $output .= $this->displayError($this->l('Missing name.'));
         }
         if (!$params['password'] || empty($params['password']) || !Validate::isGenericName($params['password'])) {
             $output .= $this->displayError($this->l('Missing password.'));
         } elseif (!$params['email'] || empty($params['email']) || !Validate::isEmail($params['email'])) {
             $output .= $this->displayError($this->l('Missing email.'));
         } elseif (!$params['phone'] || empty($params['phone']) || !Validate::isPhoneNumber($params['phone'])) {
             $output .= $this->displayError($this->l('Missing phone.'));
         } elseif (!$params['country'] || empty($params['country']) || !Validate::isLangIsoCode($params['country'])) {
             $output .= $this->displayError($this->l('Missing country.'));
         } elseif (!$params['company'] || empty($params['company']) || !Validate::isGenericName($params['company'])) {
             $output .= $this->displayError($this->l('Missing company.'));
         } else {
             $cashway = self::getCashWayAPI();
             $res = $cashway->registerAccount($params);
             if (isset($res['errors'])) {
                 foreach ($res['errors'] as $key => $value) {
                     $output .= $this->displayError($value['code'] . ' => ' . $value['message']);
                 }
             } elseif ($res['status'] == 'newbie') {
                 Configuration::updateValue('CASHWAY_API_KEY', $res['api_key']);
                 Configuration::updateValue('CASHWAY_API_SECRET', $res['api_secret']);
                 $this->updateNotificationParameters();
                 $output .= $this->displayConfirmation($this->l('Register completed'));
             }
         }
     }
     return $output . $this->renderForm();
 }
 public function validateSettings()
 {
     if (!Tools::getValue(DpdPolandConfiguration::LOGIN)) {
         self::$errors[] = $this->l('Login can not be empty');
     }
     if (!Tools::getValue(DpdPolandConfiguration::PASSWORD)) {
         self::$errors[] = $this->l('Password can not be empty');
     } elseif (!Validate::isPasswd(Tools::getValue(DpdPolandConfiguration::PASSWORD))) {
         self::$errors[] = $this->l('Password is not valid');
     }
     if (!Tools::getValue(DpdPolandConfiguration::CLIENT_NUMBER)) {
         self::$errors[] = $this->l('Default client number must be set');
     }
     if (!Tools::getValue(DpdPolandConfiguration::COMPANY_NAME)) {
         self::$errors[] = $this->l('Company name can not be empty');
     } elseif (!Validate::isLabel(Tools::getValue(DpdPolandConfiguration::COMPANY_NAME))) {
         self::$errors[] = $this->l('Company name is not valid');
     }
     if (!Tools::getValue(DpdPolandConfiguration::NAME_SURNAME)) {
         self::$errors[] = $this->l('Name and Surname can not be empty');
     } elseif (!Validate::isName(Tools::getValue(DpdPolandConfiguration::NAME_SURNAME))) {
         self::$errors[] = $this->l('Name and surname are not valid. Please use only letters and separate first name from last name with white space.');
     }
     if (!Tools::getValue(DpdPolandConfiguration::ADDRESS)) {
         self::$errors[] = $this->l('Address can not be empty');
     } elseif (!Validate::isAddress(Tools::getValue(DpdPolandConfiguration::ADDRESS))) {
         self::$errors[] = $this->l('Address is not valid');
     }
     if (!Tools::getValue(DpdPolandConfiguration::POSTCODE)) {
         self::$errors[] = $this->l('Postal code not be empty');
     } elseif (!Validate::isPostCode(Tools::getValue(DpdPolandConfiguration::POSTCODE))) {
         self::$errors[] = $this->l('Postal code is not valid');
     }
     if (!Tools::getValue(DpdPolandConfiguration::CITY)) {
         self::$errors[] = $this->l('City can not be empty');
     } elseif (!Validate::isCityName(Tools::getValue(DpdPolandConfiguration::CITY))) {
         self::$errors[] = $this->l('City is not valid');
     }
     if (!Tools::getValue(DpdPolandConfiguration::EMAIL)) {
         self::$errors[] = $this->l('Email can not be empty');
     } elseif (!Validate::isEmail(Tools::getValue(DpdPolandConfiguration::EMAIL))) {
         self::$errors[] = $this->l('Email is not valid');
     }
     if (!Tools::getValue(DpdPolandConfiguration::PHONE)) {
         self::$errors[] = $this->l('Tel. No. can not be empty');
     } elseif (!Validate::isPhoneNumber(Tools::getValue(DpdPolandConfiguration::PHONE))) {
         self::$errors[] = $this->l('Tel. No. is not valid');
     }
     if (Tools::isSubmit(DpdPolandConfiguration::CARRIER_STANDARD_COD)) {
         $checked = false;
         foreach (DpdPoland::getPaymentModules() as $payment_module) {
             if (Tools::isSubmit(DpdPolandConfiguration::COD_MODULE_PREFIX . $payment_module['name'])) {
                 $checked = true;
             }
         }
         if (!$checked) {
             self::$errors[] = $this->l('At least one COD payment method must be checked');
         }
     }
     if (!Tools::getValue(DpdPolandConfiguration::WEIGHT_CONVERSATION_RATE)) {
         self::$errors[] = $this->l('Weight conversation rate can not be empty');
     } elseif (!Validate::isUnsignedFloat(Tools::getValue(DpdPolandConfiguration::WEIGHT_CONVERSATION_RATE))) {
         self::$errors[] = $this->l('Weight conversation rate is not valid');
     }
     if (!Tools::getValue(DpdPolandConfiguration::DIMENSION_CONVERSATION_RATE)) {
         self::$errors[] = $this->l('Dimension conversation rate can not be empty');
     } elseif (!Validate::isUnsignedFloat(Tools::getValue(DpdPolandConfiguration::DIMENSION_CONVERSATION_RATE))) {
         self::$errors[] = $this->l('Dimension conversation rate is not valid');
     }
     if (!Tools::getValue(DpdPolandConfiguration::CUSTOMER_COMPANY)) {
         self::$errors[] = $this->l('Customer company name can not be empty');
     } elseif (!Validate::isLabel(Tools::getValue(DpdPolandConfiguration::CUSTOMER_COMPANY))) {
         self::$errors[] = $this->l('Customer company name is not valid');
     }
     if (!Tools::getValue(DpdPolandConfiguration::CUSTOMER_NAME)) {
         self::$errors[] = $this->l('Customer name and surname can not be empty');
     } elseif (!Validate::isName(Tools::getValue(DpdPolandConfiguration::CUSTOMER_NAME))) {
         self::$errors[] = $this->l('Customer name and surname is not valid');
     }
     if (!Tools::getValue(DpdPolandConfiguration::CUSTOMER_PHONE)) {
         self::$errors[] = $this->l('Customer tel. No. can not be empty');
     } elseif (!Validate::isPhoneNumber(Tools::getValue(DpdPolandConfiguration::CUSTOMER_PHONE))) {
         self::$errors[] = $this->l('Customer tel. No. is not valid');
     }
     if (!Tools::getValue(DpdPolandConfiguration::CUSTOMER_FID)) {
         self::$errors[] = $this->l('Customer FID can not be empty');
     } elseif (!ctype_alnum(Tools::getValue(DpdPolandConfiguration::CUSTOMER_FID))) {
         self::$errors[] = $this->l('Customer FID is not valid');
     }
     if (!Tools::getValue(DpdPolandConfiguration::MASTER_FID)) {
         self::$errors[] = $this->l('Master FID can not be empty');
     } elseif (!ctype_alnum(Tools::getValue(DpdPolandConfiguration::MASTER_FID))) {
         self::$errors[] = $this->l('Master FID is not valid');
     }
     if (!Tools::getValue(DpdPolandConfiguration::WS_URL)) {
         self::$errors[] = $this->l('Web Services URL can not be empty');
     } elseif (!Validate::isUrl(Tools::getValue(DpdPolandConfiguration::WS_URL))) {
         self::$errors[] = $this->l('Web Services URL is not valid');
     }
 }
 public function displayFrontForm()
 {
     global $smarty;
     $error = false;
     $confirm = false;
     if (isset($_POST['submitAddtoafriend'])) {
         global $cookie, $link;
         /* Product informations */
         $product = new Product(intval(Tools::getValue('id_product')), false, intval($cookie->id_lang));
         $productLink = $link->getProductLink($product);
         /*
         	Form Details
         */
         $form_details = array('visitorname' => $_POST['visitorname'] ? $_POST['visitorname'] : "", 'visitoremail' => $_POST['visitoremail'] ? $_POST['visitoremail'] : "", 'visitormobile' => $_POST['visitorphone'] ? $_POST['visitorphone'] : "", 'visitorcountry' => $_POST['id_country'] ? $_POST['id_country'] : "", 'visitorstate' => $_POST['id_state'] ? $_POST['id_state'] : "");
         /* Fields verifications */
         if (empty($_POST['enquiry']) or empty($_POST['enquiry'])) {
             $error = $this->l('You must enter some enquiry.');
         } elseif (empty($_POST['email']) or empty($_POST['name']) or empty($_POST['visitorname']) or empty($_POST['visitoremail']) or empty($_POST['visitorphone']) or empty($_POST['id_country'])) {
             $error = $this->l('You must fill all fields.');
         } elseif (!Validate::isEmail($_POST['visitoremail'])) {
             $error = $this->l('Your email is invalid.');
         } elseif (!Validate::isName($_POST['visitorname'])) {
             $error = $this->l('Your name is invalid.');
         } elseif (!Validate::isPhoneNumber($_POST['visitorphone'])) {
             $error = $this->l('Your phone number is invalid.');
         } elseif (!isset($_GET['id_product']) or !is_numeric($_GET['id_product'])) {
             $error = $this->l('An error occurred during the process.');
         } else {
             $countries = Country::getCountries(intval($cookie->id_lang), true);
             $finalstate = '';
             if (isset($countries[$_POST['id_country']]['country'])) {
                 $states = $countries[$_POST['id_country']]['states'];
                 foreach ($states as $ind => $statevalue) {
                     if ($statevalue['id_state'] == $_POST['id_state']) {
                         $finalstate = $statevalue['name'];
                     }
                 }
             }
             /* Email generation */
             $subject = $_POST['visitorname'] . ' ' . $this->l('enquired about the product') . ' ' . $product->name;
             $templateVars = array('{product}' => $product->name, '{product_link}' => $productLink, '{customer}' => $_POST['visitorname'], '{customeremail}' => $_POST['visitoremail'], '{customerphone}' => $_POST['visitorphone'], '{customercountry}' => isset($countries[$_POST['id_country']]['country']) ? $countries[$_POST['id_country']]['country'] : "", '{customerstate}' => $finalstate, '{name}' => Tools::safeOutput($_POST['name']), '{enquiry}' => Tools::safeOutput($_POST['enquiry']));
             /* Email sending */
             if (!Mail::Send(intval($cookie->id_lang), 'product_enquiry', $subject, $templateVars, $_POST['email'], NULL, $_POST['visitoremail'], $_POST['visitorname'], NULL, NULL, dirname(__FILE__) . '/mails/')) {
                 $error = $this->l('An error occurred during the process.');
             } else {
                 $confirm = $this->l('An email has been sent successfully to') . ' ' . Tools::safeOutput($_POST['email']) . '.';
             }
         }
     } else {
         global $cookie, $link;
         $customer = new Customer(intval($cookie->id_customer));
         $address = new Address(intval($cookie->id_address_delivery));
         /* Product informations */
         $product = new Product(intval(Tools::getValue('id_product')), false, intval($cookie->id_lang));
         $productLink = $link->getProductLink($product);
         /*
         	Form Details
         */
         $form_details = array('visitorname' => $customer->firstname ? $customer->firstname . ' ' . $customer->lastname : "", 'visitoremail' => $customer->email ? $customer->email : "", 'visitormobile' => $address->phone_mobile ? $address->phone_mobile : "", 'visitorcountry' => $address->id_country ? $address->id_country : "", 'visitorstate' => $address->id_state ? $address->id_state : "");
     }
     /*
     	Get country
     */
     if (isset($_POST['id_country']) and !empty($_POST['id_country']) and is_numeric($_POST['id_country'])) {
         $selectedCountry = intval($_POST['id_country']);
     } elseif (isset($address) and isset($address->id_country) and !empty($address->id_country) and is_numeric($address->id_country)) {
         $selectedCountry = intval($address->id_country);
     } elseif (isset($_SERVER['HTTP_ACCEPT_LANGUAGE'])) {
         $array = preg_split('/,|-/', $_SERVER['HTTP_ACCEPT_LANGUAGE']);
         if (!Validate::isLanguageIsoCode($array[0]) or !($selectedCountry = Country::getByIso($array[0]))) {
             $selectedCountry = intval(Configuration::get('PS_COUNTRY_DEFAULT'));
         }
     } else {
         $selectedCountry = intval(Configuration::get('PS_COUNTRY_DEFAULT'));
     }
     $countries = Country::getCountries(intval($cookie->id_lang), true);
     $countriesList = '';
     foreach ($countries as $country) {
         $countriesList .= '<option value="' . intval($country['id_country']) . '" ' . ($country['id_country'] == $selectedCountry ? 'selected="selected"' : '') . '>' . htmlentities($country['name'], ENT_COMPAT, 'UTF-8') . '</option>';
     }
     /*
     	Customer Info.
     */
     $visitorname = $form_details['visitorname'] ? $form_details['visitorname'] : "";
     $visitoremail = $form_details['visitoremail'] ? $form_details['visitoremail'] : "";
     $visitormobile = $form_details['visitormobile'] ? $form_details['visitormobile'] : "";
     $visitorcountry = $selectedCountry ? $selectedCountry : "";
     $visitorstate = $form_details['visitorstate'] ? $form_details['visitorstate'] : "";
     $visitor = array('fullname' => $visitorname, 'email' => $visitoremail, 'mobile' => $visitormobile, 'country' => $visitorcountry, 'state' => $visitorstate);
     /* Image */
     $images = $product->getImages(intval($cookie->id_lang));
     foreach ($images as $k => $image) {
         if ($image['cover']) {
             $cover['id_image'] = intval($product->id) . '-' . intval($image['id_image']);
             $cover['legend'] = $image['legend'];
         }
     }
     if (!isset($cover)) {
         $cover = array('id_image' => Language::getIsoById(intval($cookie->id_lang)) . '-default', 'legend' => 'No picture');
     }
     //CSS ans JS file calls
     $js_files = array(_THEME_JS_DIR_ . 'tools/statesManagement.js');
     $smarty->assign(array('cover' => $cover, 'errors' => $error, 'confirm' => $confirm, 'product' => $product, 'productLink' => $productLink, 'visitor' => $visitor, 'countries_list' => $countriesList, 'countries' => $countries, 'js_files' => $js_files));
     return $this->display(__FILE__, 'productenquiry.tpl');
 }
Пример #12
0
 protected function _update_configuration($key, $value)
 {
     $interface = PS_CLI_Interface::getInterface();
     $validValue = false;
     switch ($key) {
         case 'PS_STORE_DISPLAY_FOOTER':
         case 'PS_STORE_DISPLAY_SITEMAP':
         case 'PS_STORE_SIMPLIFIED':
             $validValue = Validate::isBool($value);
             break;
         case 'PS_STORES_CENTER_LAT':
         case 'PS_STORES_CENTER_LONG':
             $validValue = Validate::isCoordinate($value);
             break;
         case 'PS_SHOP_NAME':
             $validValue = Validate::isName($value);
             break;
         case 'PS_SHOP_EMAIL':
             $validValue = Validate::isEmail($value);
             break;
         case 'PS_SHOP_DETAILS':
             $validValue = Validate::isString($value);
             break;
         case 'PS_SHOP_ADDR1':
         case 'PS_SHOP_ADDR2':
             $validValue = Validate::isAddress($value);
             break;
         case 'PS_SHOP_CODE':
             $validValue = Validate::isPostCode($value);
             break;
         case 'PS_SHOP_CITY':
             $validValue = Validate::isCityName($value);
             break;
         case 'PS_SHOP_COUNTRY_ID':
             if (Validate::isUnsignedId($value)) {
                 $obj = new Country((int) $value);
                 $validValue = Validate::isLoadedObject($obj);
             }
             break;
         case 'PS_SHOP_STATE_ID':
             $validValue = Validate::isUnsignedId($value);
             break;
         case 'PS_SHOP_PHONE':
         case 'PS_SHOP_FAX':
             $validValue = Validate::isPhoneNumber($value);
             break;
         default:
             $interface->error("Configuration key '{$key}' is not handled by this command");
             break;
     }
     if (!$validValue) {
         $interface->error("value '{$value}' is not a valid value for configuration key '{$key}'");
     }
     if (PS_CLI_Utils::update_configuration_value($key, $value)) {
         $interface->success("Successfully updated '{$key}' configuration");
     } else {
         $interface->error("Could not update configuration key '{$key}'");
     }
 }
Пример #13
0
 public static function disableUsesAddress($order)
 {
     if (Validate::isLoadedObject($order)) {
         $address = new Address((int) $order->id_address_delivery);
         if (Validate::isLoadedObject($address)) {
             $default_address = Configuration::getMultiple(array('SHIPTOMYID_DEFAULT_ADDR_ADDRESS', 'SHIPTOMYID_DEFAULT_ADDR_ADDRESS2', 'SHIPTOMYID_DEFAULT_ADDR_CITY', 'SHIPTOMYID_DEFAULT_ADDR_POSTCODE', 'SHIPTOMYID_DEFAULT_ADDR_COUNTRY', 'SHIPTOMYID_DEFAULT_ADDR_STATE', 'SHIPTOMYID_DEFAULT_ADDR_PHONE', 'SHIPTOMYID_DEFAULT_ADDR_ALIAS'));
             if (Validate::isAddress($default_address['SHIPTOMYID_DEFAULT_ADDR_ADDRESS'])) {
                 $address->address1 = Tools::substr($default_address['SHIPTOMYID_DEFAULT_ADDR_ADDRESS'], 0, 128);
             }
             if (Validate::isAddress($default_address['SHIPTOMYID_DEFAULT_ADDR_ADDRESS2'])) {
                 $address->address2 = Tools::substr($default_address['SHIPTOMYID_DEFAULT_ADDR_ADDRESS2'], 0, 128);
             }
             if (Validate::isCityName($default_address['SHIPTOMYID_DEFAULT_ADDR_CITY'])) {
                 $address->city = Tools::substr($default_address['SHIPTOMYID_DEFAULT_ADDR_CITY'], 0, 64);
             }
             if (Validate::isPostCode($default_address['SHIPTOMYID_DEFAULT_ADDR_POSTCODE'])) {
                 $address->postcode = Tools::substr($default_address['SHIPTOMYID_DEFAULT_ADDR_POSTCODE'], 0, 12);
             }
             if (Validate::isPhoneNumber($default_address['SHIPTOMYID_DEFAULT_ADDR_PHONE'])) {
                 $address->phone = Tools::substr($default_address['SHIPTOMYID_DEFAULT_ADDR_PHONE'], 0, 32);
             }
             $address->id_country = (int) $default_address['SHIPTOMYID_DEFAULT_ADDR_COUNTRY'];
             $address->id_state = (int) $default_address['SHIPTOMYID_DEFAULT_ADDR_STATE'];
             $address->update();
         }
     }
     Db::getInstance()->Execute('UPDATE ' . _DB_PREFIX_ . 'address SET deleted = 1 WHERE id_address = ' . (int) $order->id_address_delivery);
 }
 public function processSave()
 {
     $hotel_id = Tools::getValue('hotel_id');
     $hotel_name = Tools::getValue('hotel_name');
     $phone = Tools::getValue('phone');
     $email = Tools::getValue('email');
     $check_in = Tools::getValue('check_in');
     $check_out = Tools::getValue('check_out');
     $short_description = Tools::getValue('short_description');
     $description = Tools::getValue('description');
     $rating = Tools::getValue('hotel_rating');
     $city = Tools::getValue('hotel_city');
     $state = Tools::getValue('hotel_state');
     $country = Tools::getValue('hotel_country');
     $policies = Tools::getValue('hotel_policies');
     $zipcode = Tools::getValue('hotel_postal_code');
     $address = Tools::getValue('address');
     $active = Tools::getValue('ENABLE_HOTEL');
     if ($hotel_name == '') {
         $this->errors[] = Tools::displayError('Hotel name is required field.');
     } else {
         if (!Validate::isGenericName($hotel_name)) {
             $this->errors[] = Tools::displayError($this->l('Hotel name must not have Invalid characters <>;=#{}'));
         }
     }
     if (!$phone) {
         $this->errors[] = Tools::displayError('Phone number is required field.');
     } else {
         if (!Validate::isPhoneNumber($phone)) {
             $this->errors[] = Tools::displayError('Please enter a valid phone number.');
         }
     }
     if ($email == '') {
         $this->errors[] = Tools::displayError('Email is required field.');
     } else {
         if (!Validate::isEmail($email)) {
             $this->errors[] = Tools::displayError('Please enter a valid email.');
         }
     }
     if ($check_in == '') {
         $this->errors[] = Tools::displayError('Check In time is required field.');
     }
     if ($check_out == '') {
         $this->errors[] = Tools::displayError('Check Out Time is required field.');
     }
     if ($zipcode == '') {
         $this->errors[] = Tools::displayError('Postal Code is required field.');
     } else {
         if (!Validate::isPostCode($zipcode)) {
             $this->errors[] = Tools::displayError('Enter a Valid Postal Code.');
         }
     }
     if (!$rating) {
         $this->errors[] = Tools::displayError('Rating is required field.');
     }
     if ($address == '') {
         $this->errors[] = Tools::displayError('Address is required field.');
     }
     if (!$country) {
         $this->errors[] = Tools::displayError('Country is required field.');
     }
     if (!$state) {
         $this->errors[] = Tools::displayError('State is required field.');
     }
     if ($city == '') {
         $this->errors[] = Tools::displayError('City is required field.');
     } else {
         if (!Validate::isCityName($city)) {
             $this->errors[] = Tools::displayError('Enter a Valid City Name.');
         }
     }
     //validate hotel main image
     if (isset($_FILES['hotel_image']) && $_FILES['hotel_image']['name']) {
         $obj_htl_img = new HotelImage();
         $error = $obj_htl_img->validAddHotelMainImage($_FILES['hotel_image']);
         if ($error) {
             $this->errors[] = Tools::displayError('<strong>' . $_FILES['hotel_image']['name'] . '</strong> : Image format not recognized, allowed formats are: .gif, .jpg, .png', false);
         }
     }
     //validate Hotel's other images
     if (isset($_FILES['images']) && $_FILES['images']) {
         $obj_htl_img = new HotelImage();
         $error = $obj_htl_img->validAddHotelOtherImage($_FILES['images']);
         if ($error) {
             $this->errors[] = Tools::displayError('<strong>' . $_FILES['hotel_image']['name'] . '</strong> : Image format not recognized, allowed formats are: .gif, .jpg, .png', false);
         }
     }
     if (!count($this->errors)) {
         if ($hotel_id) {
             $obj_hotel_info = new HotelBranchInformation($hotel_id);
         } else {
             $obj_hotel_info = new HotelBranchInformation();
         }
         if ($obj_hotel_info) {
             if (!$active) {
                 $obj_htl_rm_info = new HotelRoomType();
                 $ids_product = $obj_htl_rm_info->getIdProductByHotelId($obj_hotel_info->id);
                 if (isset($ids_product) && $ids_product) {
                     foreach ($ids_product as $key_prod => $value_prod) {
                         $obj_product = new Product($value_prod['id_product']);
                         if ($obj_product->active) {
                             $obj_product->toggleStatus();
                         }
                     }
                 }
             }
         }
         $obj_hotel_info->active = $active;
         $obj_hotel_info->hotel_name = $hotel_name;
         $obj_hotel_info->phone = $phone;
         $obj_hotel_info->email = $email;
         $obj_hotel_info->check_in = $check_in;
         $obj_hotel_info->check_out = $check_out;
         $obj_hotel_info->short_description = $short_description;
         $obj_hotel_info->description = $description;
         $obj_hotel_info->rating = $rating;
         $obj_hotel_info->city = $city;
         $obj_hotel_info->state_id = $state;
         $obj_hotel_info->country_id = $country;
         $obj_hotel_info->zipcode = $zipcode;
         $obj_hotel_info->policies = $policies;
         $obj_hotel_info->address = $address;
         $obj_hotel_info->save();
         $new_hotel_id = $obj_hotel_info->id;
         $hotel_img_path = _PS_MODULE_DIR_ . 'hotelreservationsystem/views/img/hotel_img/';
         //upload hotel's image
         if (isset($_FILES['hotel_image']) && $_FILES['hotel_image']) {
             $obj_htl_img = new HotelImage();
             $obj_htl_img->uploadMainImage($_FILES['hotel_image'], $new_hotel_id, $hotel_img_path);
         }
         //upload hotel's other images
         if (isset($_FILES['images']) && $_FILES['images']) {
             $obj_htl_img = new HotelImage();
             $obj_htl_img->uploadOtherImages($_FILES['images'], $new_hotel_id, $hotel_img_path);
         }
         if ($new_hotel_id) {
             $grp_ids = array();
             $obj_grp = new Group();
             $data_grp_ids = $obj_grp->getGroups(1, $id_shop = false);
             foreach ($data_grp_ids as $key => $value) {
                 $grp_ids[] = $value['id_group'];
             }
             $country_name = (new Country())->getNameById(Configuration::get('PS_LANG_DEFAULT'), $country);
             $cat_country = $this->addCategory($country_name, false, $grp_ids);
             if ($cat_country) {
                 $state_name = (new State())->getNameById($state);
                 $cat_state = $this->addCategory($state_name, $cat_country, $grp_ids);
             }
             if ($cat_state) {
                 $cat_city = $this->addCategory($city, $cat_state, $grp_ids);
             }
             if ($cat_city) {
                 $cat_hotel = $this->addCategory($hotel_name, $cat_city, $grp_ids, 1, $new_hotel_id);
             }
             if ($cat_hotel) {
                 $obj_hotel_info = new HotelBranchInformation($new_hotel_id);
                 $obj_hotel_info->id_category = $cat_hotel;
                 $obj_hotel_info->save();
             }
         }
         if (Tools::isSubmit('submitAdd' . $this->table . 'AndStay')) {
             if ($hotel_id) {
                 Tools::redirectAdmin(self::$currentIndex . '&id=' . (int) $new_hotel_id . '&update' . $this->table . '&conf=4&token=' . $this->token);
             } else {
                 Tools::redirectAdmin(self::$currentIndex . '&id=' . (int) $new_hotel_id . '&update' . $this->table . '&conf=3&token=' . $this->token);
             }
         } else {
             if ($hotel_id) {
                 Tools::redirectAdmin(self::$currentIndex . '&conf=4&token=' . $this->token);
             } else {
                 Tools::redirectAdmin(self::$currentIndex . '&conf=3&token=' . $this->token);
             }
         }
     } else {
         if ($hotel_id) {
             $this->display = 'edit';
         } else {
             $this->display = 'add';
         }
     }
 }
Пример #15
0
 /**
  * Start forms process
  * @see FrontController::postProcess()
  */
 public function postProcess()
 {
     //var_dump($_POST);exit();
     $customer = new Customer();
     $mail = trim(Tools::getValue('email'));
     if (Validate::isEmail($mail)) {
         $customer->getByEmail($mail, trim(Tools::getValue('passwd')));
     }
     if (Tools::isSubmit('SubmitCreate')) {
         $this->processSubmitCreate();
     }
     if (Tools::isSubmit('submitAccount') && $customer->id) {
         if (!Tools::getValue('customer_firstname')) {
             $this->val_errors['customer_firstname'] = Tools::displayError('Имя обязательно');
         }
         if (!Tools::getValue('phone_mobile')) {
             $this->val_errors['phone_mobile'] = Tools::displayError('Телефон обязателен');
         } else {
             if (!Validate::isPhoneNumber(Tools::getValue('phone_mobile'))) {
                 $this->val_errors['phone_mobile'] = Tools::displayError('мобильный телефон неверный');
             }
         }
         if (isset($_POST['delivery_form']) && $_POST['delivery_form'] == 1) {
             if (empty($_POST['city'])) {
                 $this->val_errors['city_courier'] = Tools::displayError('Город обязателен');
             }
             if (empty($_POST['street'])) {
                 $this->val_errors['street_courier'] = Tools::displayError('Улица обязательна');
             }
             if (empty($_POST['house'])) {
                 $this->val_errors['house_courier'] = Tools::displayError('Дом обязателен');
             }
         }
         if (count($this->val_errors)) {
             $return = array('hasError' => !empty($this->val_errors), 'errors' => $this->errors, 'isSaved' => false, 'id_customer' => 0, 'val_errors' => $this->val_errors);
             die(Tools::jsonEncode($return));
             $this->context->smarty->assign('account_error', $this->errors);
         } else {
             $this->processSubmitLogin();
         }
     } else {
         if (Tools::isSubmit('submitAccount') || Tools::isSubmit('submitGuestAccount')) {
             // if($customer->id)$this->processSubmitLogin();
             $this->processSubmitAccount();
         }
     }
     //$this->processSubmitAccount();
     if (Tools::isSubmit('SubmitLogin')) {
         $this->processSubmitLogin();
     }
 }
Пример #16
0
 private function textmasterWebPageActions()
 {
     if (Tools::getValue('login_to_textmaster_system_action')) {
         Tools::safePostVars();
         $email = Tools::getValue('login_email', '');
         $password = Tools::getValue('login_password', '');
         $errors = array();
         if ($email == '') {
             $errors[] = $this->l('Email is required');
         } elseif (!Validate::isEmail($email)) {
             $errors[] = $this->l('Email must be valid');
         }
         if ($password == '') {
             $errors[] = $this->l('Password is required');
         } elseif (!Validate::isPasswd($password)) {
             $errors[] = $this->l('Password must be valid');
         }
         if (!empty($errors)) {
             return $this->_html .= $this->displayErrors($errors);
         }
         $result = $this->getTextMasterOAuth2Token($email, $password);
         $result = Tools::jsonDecode($result, true);
         if (!isset($result['access_token'])) {
             return $this->_html .= $this->displayErrors(array($this->l('Wrong login / password')));
         }
         $result = $this->getTextMasterAPIKeys($result['access_token']);
         $result = Tools::jsonDecode($result, true);
         if (!isset($result['api_info']['api_key']) || !isset($result['api_info']['api_secret'])) {
             return $this->_html .= $this->displayErrors(array($this->l('Could not get API key / secret')));
         }
         $textmaster_settings_obj = new TextMasterConfiguration();
         $textmaster_settings_obj->api_key = $result['api_info']['api_key'];
         $textmaster_settings_obj->api_secret = $result['api_info']['api_secret'];
         if ($textmaster_settings_obj->updateConfiguration()) {
             Tools::redirectAdmin(self::CURRENT_INDEX . Tools::getValue('token') . '&configure=' . $this->name . '&token=' . Tools::getAdminTokenLite('AdminModules'));
         } else {
             return $this->_html .= $this->displayErrors(array($this->l('Could not save API key / secret')));
         }
     }
     if (Tools::getValue('register_to_textmaster_system')) {
         Tools::safePostVars();
         $email = Tools::getValue('register_email', '');
         $password = Tools::getValue('register_password', '');
         $password_confirm = Tools::getValue('register_password_confirm', '');
         $register_phone = Tools::getValue('register_phone', '');
         $errors = array();
         if ($email == '') {
             $errors[] = $this->l('Email is required');
         } elseif (!Validate::isEmail($email)) {
             $errors[] = $this->l('Email must be valid');
         }
         if ($password == '') {
             $errors[] = $this->l('Password is required');
         } elseif ($password !== $password_confirm) {
             $errors[] = $this->l('Password and Confirm password must be the same');
         } elseif (!Validate::isPasswd($password)) {
             $errors[] = $this->l('Password must be valid');
         }
         if ($register_phone != '') {
             if (!Validate::isPhoneNumber($register_phone)) {
                 $errors[] = $this->l('Phone number must be valid');
             }
         }
         if (!empty($errors)) {
             return $this->_html .= $this->displayErrors($errors);
         }
         $token = $this->getTextMasterOAuth2TokenForUserCreation();
         $token = Tools::jsonDecode($token, true);
         if (!isset($token['access_token'])) {
             return $this->_html .= $this->displayErrors(array($this->l('Could not get access token')));
         }
         $user_info = $this->createNewTextMasterUser($token['access_token'], $email, $password);
         $user_info = Tools::jsonDecode($user_info, true);
         $errors = array();
         if (isset($user_info['errors'])) {
             foreach ($user_info['errors'] as $key => $error) {
                 foreach ($error as $error_key => $value) {
                     $errors[] = $key . ' ' . $this->l('-') . ' ' . $value;
                 }
             }
         }
         if (!empty($errors)) {
             return $this->_html .= $this->displayErrors($errors);
         }
         if (!isset($user_info['api_info']['api_key']) || !isset($user_info['api_info']['api_secret'])) {
             return $this->_html .= $this->displayErrors(array('Could not get API key / secret'));
         }
         $textmaster_settings_obj = new TextMasterConfiguration();
         $textmaster_settings_obj->api_key = $user_info['api_info']['api_key'];
         $textmaster_settings_obj->api_secret = $user_info['api_info']['api_secret'];
         if ($textmaster_settings_obj->updateConfiguration()) {
             Tools::redirectAdmin(self::CURRENT_INDEX . Tools::getValue('token') . '&configure=' . $this->name . '&token=' . Tools::getAdminTokenLite('AdminModules'));
         } else {
             return $this->_html .= $this->displayErrors(array($this->l('Could not save API key / secret')));
         }
     }
 }
Пример #17
0
 public function hookbackOfficeTop($params)
 {
     // Check if the module is configured
     if (!Configuration::get('EBAY_PAYPAL_EMAIL')) {
         return false;
     }
     // If no update yet
     if (!Configuration::get('EBAY_ORDER_LAST_UPDATE')) {
         Configuration::updateValue('EBAY_ORDER_LAST_UPDATE', date('Y-m-d') . 'T' . date('H:i:s') . '.000Z');
     }
     // init Var
     $dateNew = date('Y-m-d') . 'T' . date('H:i:s') . '.000Z';
     if (Configuration::get('EBAY_ORDER_LAST_UPDATE') < date('Y-m-d', strtotime('-30 minutes')) . 'T' . date('H:i:s', strtotime('-30 minutes')) . '.000Z') {
         // Lock
         Configuration::updateValue('EBAY_ORDER_LAST_UPDATE', $dateNew);
         // eBay Request
         $ebay = new eBayRequest();
         $page = 1;
         $orderList = array();
         $orderCount = 0;
         $orderCountTmp = 100;
         while ($orderCountTmp == 100 && $page < 10) {
             $orderListTmp = $ebay->getOrders(date('Y-m-d', strtotime('-30 days')) . 'T' . date('H:i:s', strtotime('-30 days')) . '.000Z', $dateNew, $page);
             $orderCountTmp = count($orderListTmp);
             $orderList = array_merge((array) $orderList, (array) $orderListTmp);
             $orderCount += $orderCountTmp;
             $page++;
         }
         if ($orderList) {
             foreach ($orderList as $korder => $order) {
                 if ($order['status'] == 'Complete' && $order['amount'] > 0.1 && isset($order['product_list']) && count($order['product_list'])) {
                     if (!Db::getInstance()->getValue('SELECT `id_ebay_order` FROM `' . _DB_PREFIX_ . 'ebay_order` WHERE `id_order_ref` = \'' . pSQL($order['id_order_ref']) . '\'')) {
                         $id_customer = (int) Db::getInstance()->getValue('SELECT `id_customer` FROM `' . _DB_PREFIX_ . 'customer` WHERE `active` = 1 AND `email` = \'' . pSQL($order['email']) . '\' AND `deleted` = 0' . (substr(_PS_VERSION_, 0, 3) == '1.3' ? '' : ' AND `is_guest` = 0'));
                         // Check for empty name
                         $order['firstname'] = trim($order['firstname']);
                         $order['familyname'] = trim($order['familyname']);
                         if (empty($order['familyname'])) {
                             $order['familyname'] = $order['firstname'];
                         }
                         if (empty($order['firstname'])) {
                             $order['firstname'] = $order['familyname'];
                         }
                         if (empty($order['phone']) || !Validate::isPhoneNumber($order['phone'])) {
                             $order['phone'] = '0100000000';
                         }
                         if (Validate::isEmail($order['email']) && !empty($order['firstname']) && !empty($order['familyname'])) {
                             // Add customer if he doesn't exist
                             if ($id_customer < 1) {
                                 $customer = new Customer();
                                 $customer->id_gender = 9;
                                 $customer->id_default_group = 1;
                                 $customer->secure_key = md5(uniqid(rand(), true));
                                 $customer->email = $order['email'];
                                 $customer->passwd = md5(pSQL(_COOKIE_KEY_ . rand()));
                                 $customer->last_passwd_gen = pSQL(date('Y-m-d H:i:s'));
                                 $customer->newsletter = 0;
                                 $customer->lastname = pSQL($order['familyname']);
                                 $customer->firstname = pSQL($order['firstname']);
                                 $customer->active = 1;
                                 $customer->add();
                                 $id_customer = $customer->id;
                             }
                             // Search if address exists
                             $id_address = (int) Db::getInstance()->getValue('SELECT `id_address` FROM `' . _DB_PREFIX_ . 'address` WHERE `id_customer` = ' . (int) $id_customer . ' AND `alias` = \'eBay\'');
                             if ($id_address > 0) {
                                 $address = new Address((int) $id_address);
                             } else {
                                 $address = new Address();
                                 $address->id_customer = (int) $id_customer;
                             }
                             $address->id_country = (int) Country::getByIso($order['country_iso_code']);
                             $address->alias = 'eBay';
                             $address->lastname = pSQL($order['familyname']);
                             $address->firstname = pSQL($order['firstname']);
                             $address->address1 = pSQL($order['address1']);
                             $address->address2 = pSQL($order['address2']);
                             $address->postcode = pSQL($order['postalcode']);
                             $address->city = pSQL($order['city']);
                             $address->phone = pSQL($order['phone']);
                             $address->active = 1;
                             if ($id_address > 0 && Validate::isLoadedObject($address)) {
                                 $address->update();
                             } else {
                                 $address->add();
                             }
                             $id_address = $address->id;
                             $flag = 1;
                             foreach ($order['product_list'] as $product) {
                                 if ((int) $product['id_product'] < 1 || !Db::getInstance()->getValue('SELECT `id_product` FROM `' . _DB_PREFIX_ . 'product` WHERE `id_product` = ' . (int) $product['id_product'])) {
                                     $flag = 0;
                                 }
                                 if (isset($product['id_product_attribute']) && $product['id_product_attribute'] > 0 && !Db::getInstance()->getValue('SELECT `id_product_attribute` FROM `' . _DB_PREFIX_ . 'product_attribute` WHERE `id_product` = ' . (int) $product['id_product'] . ' AND `id_product_attribute` = ' . (int) $product['id_product_attribute'])) {
                                     $flag = 0;
                                 }
                             }
                             if ($flag == 1) {
                                 $cartNbProducts = 0;
                                 $cartAdd = new Cart();
                                 $cartAdd->id_customer = $id_customer;
                                 $cartAdd->id_address_invoice = $id_address;
                                 $cartAdd->id_address_delivery = $id_address;
                                 $cartAdd->id_carrier = 1;
                                 $cartAdd->id_lang = $this->id_lang;
                                 $cartAdd->id_currency = Currency::getIdByIsoCode('EUR');
                                 $cartAdd->recyclable = 0;
                                 $cartAdd->gift = 0;
                                 $cartAdd->add();
                                 foreach ($order['product_list'] as $product) {
                                     if ($cartAdd->updateQty((int) $product['quantity'], (int) $product['id_product'], isset($product['id_product_attribute']) && $product['id_product_attribute'] > 0 ? $product['id_product_attribute'] : NULL)) {
                                         $cartNbProducts++;
                                     }
                                 }
                                 $cartAdd->update();
                                 // Check number of products in the cart
                                 if ($cartNbProducts > 0) {
                                     // Fix on sending e-mail
                                     Db::getInstance()->autoExecute(_DB_PREFIX_ . 'customer', array('email' => 'NOSEND-EBAY'), 'UPDATE', '`id_customer` = ' . (int) $id_customer);
                                     $customerClear = new Customer();
                                     if (method_exists($customerClear, 'clearCache')) {
                                         $customerClear->clearCache(true);
                                     }
                                     // Validate order
                                     $paiement = new eBayPayment();
                                     $paiement->validateOrder(intval($cartAdd->id), Configuration::get('PS_OS_PAYMENT'), floatval($cartAdd->getOrderTotal(true, 3)), 'eBay ' . $order['payment_method'] . ' ' . $order['id_order_seller'], NULL, array(), intval($cartAdd->id_currency));
                                     $id_order = $paiement->currentOrder;
                                     // Fix on date
                                     Db::getInstance()->autoExecute(_DB_PREFIX_ . 'orders', array('date_add' => pSQL($order['date_add'])), 'UPDATE', '`id_order` = ' . (int) $id_order);
                                     // Fix on sending e-mail
                                     Db::getInstance()->autoExecute(_DB_PREFIX_ . 'customer', array('email' => pSQL($order['email'])), 'UPDATE', '`id_customer` = ' . (int) $id_customer);
                                     // Update price (because of possibility of price impact)
                                     $updateOrder = array('total_paid' => floatval($order['amount']), 'total_paid_real' => floatval($order['amount']), 'total_products' => floatval($order['amount']), 'total_products_wt' => floatval($order['amount']), 'total_shipping' => floatval($order['shippingServiceCost']));
                                     Db::getInstance()->autoExecute(_DB_PREFIX_ . 'orders', $updateOrder, 'UPDATE', '`id_order` = ' . (int) $id_order);
                                     foreach ($order['product_list'] as $product) {
                                         Db::getInstance()->autoExecute(_DB_PREFIX_ . 'order_detail', array('product_price' => floatval($product['price']), 'tax_rate' => 0, 'reduction_percent' => 0), 'UPDATE', '`id_order` = ' . (int) $id_order . ' AND `product_id` = ' . (int) $product['id_product'] . ' AND `product_attribute_id` = ' . (int) $product['id_product_attribute']);
                                     }
                                     // Register the ebay order ref
                                     Db::getInstance()->autoExecute(_DB_PREFIX_ . 'ebay_order', array('id_order_ref' => pSQL($order['id_order_ref']), 'id_order' => (int) $id_order), 'INSERT');
                                 } else {
                                     $cartAdd->delete();
                                     $orderList[$korder]['errors'][] = $this->l('Could not add product to cart (maybe your stock quantity is 0)');
                                 }
                             } else {
                                 $orderList[$korder]['errors'][] = $this->l('Could not found products in database');
                             }
                         } else {
                             $orderList[$korder]['errors'][] = $this->l('Invalid e-mail');
                         }
                     } else {
                         $orderList[$korder]['errors'][] = $this->l('Order already imported');
                     }
                 } else {
                     $orderList[$korder]['errors'][] = $this->l('Status not complete or amount less than 0.1 or no product matching');
                 }
             }
             file_put_contents(dirname(__FILE__) . '/log/orders.php', "<?php\n\n" . '$dateLastImport = ' . "'" . date('d/m/Y H:i:s') . "';\n\n" . '$orderList = ' . var_export($orderList, true) . ";\n\n");
         }
     }
 }
Пример #18
0
include_once dirname(__FILE__) . '/quickorder.php';
class QuickOrderCreate extends PaymentModule
{
    public $active = true;
}
$context = Context::getContext();
$quickorder = new QuickOrder();
if (Tools::isSubmit('submitQorder')) {
    $errors = array();
    if (!Validate::isLoadedObject($context->cart)) {
        $errors[] = $quickorder->l('Cart not found', 'ajax');
    }
    if (Cart::getNbProducts($context->cart->id) <= 0) {
        $errors[] = $quickorder->l('You must add minimum 1 quantity', 'ajax');
    }
    if (!Tools::getValue('phone') || !Validate::isPhoneNumber(Tools::getValue('phone'))) {
        $errors[] = $quickorder->l('You must register at least one phone number', 'ajax');
    }
    if (!Tools::getValue('firstname') || !Validate::isName(Tools::getValue('firstname'))) {
        $errors[] = $quickorder->l('Name is empty or contains error', 'ajax');
    }
    if (!Tools::getValue('time')) {
        $errors[] = $quickorder->l('Time is empty or contains error', 'ajax');
    }
    if (!empty($errors)) {
        die(Tools::jsonEncode(array('hasError' => true, 'errors' => $errors)));
    } else {
        if (Configuration::get('QUI_CREATE_ORDER')) {
            if (!$context->customer->isLogged()) {
                $customer = new Customer();
                $customer->passwd = md5(time() . _COOKIE_KEY_);
 public function postProcess()
 {
     // On construit un login pour le compte
     // ------------------------------------
     // Si PS_SHOP_EMAIL = info@axalone.com
     // Alors login      = ps-info-axalone
     //   1/ On ajoute 'ps-' devant l'email
     //   2/ On retire l'extention .com à la fin
     //   3/ On remplace toutes les lettres accentuées par leurs équivalents sans accent
     //   4/ On remplace tous les sigles par des tirets
     //   5/ Enfin on remplace les doubles/triples tirets par des simples
     // --------------------------------------------------------------------------------
     $company_login = '******' . Configuration::get('PS_SHOP_EMAIL');
     $company_login = Tools::substr($company_login, 0, strrpos($company_login, '.'));
     $company_login = EMTools::removeAccents($company_login);
     $company_login = Tools::strtolower($company_login);
     $company_login = preg_replace('/[^a-z0-9-]/', '-', $company_login);
     $company_login = preg_replace('/-{2,}/', '-', $company_login);
     $cart_product = (string) Tools::getValue('product', '');
     // Initialisation de l'API
     // -----------------------
     if (Tools::isSubmit('submitInscription')) {
         // On prépare l'ouverture du compte
         // --------------------------------
         $company_name = (string) Tools::getValue('company_name');
         $company_email = (string) Tools::getValue('company_email');
         $company_phone = (string) Tools::getValue('company_phone');
         $company_address1 = (string) Tools::getValue('company_address1');
         $company_address2 = (string) Tools::getValue('company_address2');
         $company_zipcode = (string) Tools::getValue('company_zipcode');
         $company_city = (string) Tools::getValue('company_city');
         $country_id = (int) Tools::getValue('country_id');
         $country = new Country($country_id);
         if (!is_object($country) || empty($country->id)) {
             $this->errors[] = Tools::displayError('Country is invalid');
         } else {
             $company_country = Country::getNameById($this->context->language->id, $country_id);
         }
         if (!Validate::isGenericName($company_name)) {
             $this->errors[] = sprintf(Tools::displayError('The %s field is required.'), '« ' . Translate::getAdminTranslation('Shop name', 'AdminStores') . ' »');
         }
         if (!Validate::isEmail($company_email)) {
             $this->errors[] = sprintf(Tools::displayError('The %s field is required.'), '« ' . Translate::getAdminTranslation('Shop email', 'AdminStores') . ' »');
         }
         if (!Validate::isPhoneNumber($company_phone)) {
             $this->errors[] = sprintf(Tools::displayError('The %s field is required.'), '« ' . Translate::getAdminTranslation('Phone', 'AdminStores') . ' »');
         }
         if (!Validate::isAddress($company_address1)) {
             $this->errors[] = sprintf(Tools::displayError('The %s field is required.'), '« ' . Translate::getAdminTranslation('Shop address line 1', 'AdminStores') . ' »');
         }
         if ($country->zip_code_format && !$country->checkZipCode($company_zipcode)) {
             $this->errors[] = Tools::displayError('Your Zip/postal code is incorrect.') . '<br />' . Tools::displayError('It must be entered as follows:') . ' ' . str_replace('C', $country->iso_code, str_replace('N', '0', str_replace('L', 'A', $country->zip_code_format)));
         } elseif (empty($company_zipcode) && $country->need_zip_code) {
             $this->errors[] = Tools::displayError('A Zip/postal code is required.');
         } elseif ($company_zipcode && !Validate::isPostCode($company_zipcode)) {
             $this->errors[] = Tools::displayError('The Zip/postal code is invalid.');
         }
         if (!Validate::isGenericName($company_city)) {
             $this->errors[] = sprintf(Tools::displayError('The %s field is required.'), '« ' . Translate::getAdminTranslation('City', 'AdminStores') . ' »');
         }
         // We save these informations in the database
         // ------------------------------------------
         Db::getInstance()->insert('expressmailing_order_address', array('id_address' => 1, 'company_name' => pSQL($company_name), 'company_email' => pSQL($company_email), 'company_address1' => pSQL($company_address1), 'company_address2' => pSQL($company_address2), 'company_zipcode' => pSQL($company_zipcode), 'company_city' => pSQL($company_city), 'country_id' => $country_id, 'company_country' => pSQL($company_country), 'company_phone' => pSQL($company_phone), 'product' => pSQL($cart_product)), false, false, Db::REPLACE);
         // If form contains 1 or more errors, we stop the process
         // ------------------------------------------------------
         if (is_array($this->errors) && count($this->errors)) {
             return false;
         }
         // Open a session on Express-Mailing API
         // -------------------------------------
         if ($this->session_api->openSession()) {
             // We create the account
             // ---------------------
             $response_array = array();
             $base_url = Configuration::get('PS_SSL_ENABLED') == 0 ? Tools::getShopDomain(true, true) : Tools::getShopDomainSsl(true, true);
             $module_dir = Tools::str_replace_once(_PS_ROOT_DIR_, '', _PS_MODULE_DIR_);
             $parameters = array('login' => $company_login, 'info_company' => $company_name, 'info_email' => $company_email, 'info_phone' => $company_phone, 'info_address' => $company_address1 . "\r\n" . $company_address2, 'info_country' => $company_country, 'info_zipcode' => $company_zipcode, 'info_city' => $company_city, 'info_phone' => $company_phone, 'info_contact_firstname' => $this->context->employee->firstname, 'info_contact_lastname' => $this->context->employee->lastname, 'email_report' => $this->context->employee->email, 'gift_code' => 'prestashop_' . Translate::getModuleTranslation('expressmailing', '3320', 'session_api'), 'INFO_WWW' => $base_url . $module_dir . $this->module->name . '/campaigns/index.php');
             if ($this->session_api->createAccount($parameters, $response_array)) {
                 // If the form include the buying process (field 'product')
                 // We initiate a new cart with the product selected
                 // --------------------------------------------------------
                 if ($cart_product) {
                     Tools::redirectAdmin('index.php?controller=AdminMarketingBuy&submitCheckout&campaign_id=' . $this->campaign_id . '&media=' . $this->next_controller . '&product=' . $cart_product . '&token=' . Tools::getAdminTokenLite('AdminMarketingBuy'));
                     exit;
                 }
                 // Else we back to the mailing process
                 // -----------------------------------
                 Tools::redirectAdmin($this->next_action);
                 exit;
             }
             if ($this->session_api->error == 11) {
                 // Account already existe, we print the rescue form (with password input)
                 // ----------------------------------------------------------------------
                 $response_array = array();
                 $parameters = array('login' => $company_login);
                 $this->session_api->resendPassword($parameters, $response_array);
                 $this->generateRescueForm();
                 return;
             } else {
                 // Other error
                 // -----------
                 $this->errors[] = sprintf($this->module->l('Unable to create an account : %s', 'adminmarketinginscription'), $this->session_api->getError());
                 return false;
             }
         } else {
             $this->errors[] = sprintf($this->module->l('Error during communication with Express-Mailing API : %s', 'adminmarketinginscription'), $this->session_api->getError());
             return false;
         }
     } elseif (Tools::isSubmit('submitRescue')) {
         // Rescue form : ask for existing password
         // ---------------------------------------
         if ($this->session_api->openSession()) {
             $response_array = array();
             $password = trim((string) Tools::getValue('api_password'));
             $parameters = array('login' => $company_login, 'password' => $password);
             if ($this->session_api->connectUser($parameters, $response_array)) {
                 Db::getInstance()->insert('expressmailing', array('api_login' => pSQL($company_login), 'api_password' => pSQL($password)), false, false, Db::REPLACE);
                 // If the form include the buying process (field 'product')
                 // We initiate a new cart with the product selected
                 // --------------------------------------------------------
                 if ($cart_product) {
                     Tools::redirectAdmin('index.php?controller=AdminMarketingBuy&submitCheckout&campaign_id=' . $this->campaign_id . '&media=' . $this->next_controller . '&product=' . $cart_product . '&token=' . Tools::getAdminTokenLite('AdminMarketingBuy'));
                     exit;
                 }
                 // Else we back to the mailing process
                 // -----------------------------------
                 Tools::redirectAdmin($this->next_action);
                 exit;
             }
         }
         $this->errors[] = sprintf($this->module->l('Error during communication with Express-Mailing API : %s', 'adminmarketinginscription'), $this->session_api->getError());
         return false;
     }
 }
Пример #20
0
 public function postProcess()
 {
     if (Tools::isSubmit('submitFaxTest')) {
         $number_or_email = (string) Tools::getValue('campaign_last_tester');
         if (empty($number_or_email)) {
             $this->errors[] = $this->module->l('Invalid fax number !', 'adminmarketingfstep7');
             return false;
         }
         if (Tools::strpos($number_or_email, '@')) {
             if (!Validate::isEmail($number_or_email)) {
                 $this->errors[] = $this->module->l('Invalid email address !', 'adminmarketingfstep7');
                 return false;
             }
         } else {
             $prefixe = EMTools::getShopPrefixeCountry();
             $number_or_email = EMTools::cleanNumber($number_or_email, $prefixe);
             if (!Validate::isPhoneNumber($number_or_email)) {
                 $this->errors[] = $this->module->l('Invalid fax number !', 'adminmarketingfstep7');
                 return false;
             }
             if ($number_or_email[0] != '0' && $number_or_email[0] != '+') {
                 $this->errors[] = $this->module->l('Invalid fax number !', 'adminmarketingfstep7');
                 return false;
             }
         }
         $response_array = array();
         $parameters = array('campaign_id' => $this->campaign_api_message_id, 'recipient' => $number_or_email);
         if ($this->session_api->call('fax', 'campaign', 'send_test', $parameters, $response_array)) {
             // We store the last fax number
             // ----------------------------
             Db::getInstance()->update('expressmailing_fax', array('campaign_last_tester' => pSQL($number_or_email)), 'campaign_id = ' . $this->campaign_id);
             $this->confirmations[] = sprintf($this->module->l('Please wait, your fax is processing to %s ...', 'adminmarketingfstep7'), $number_or_email);
             return true;
         }
         $this->errors[] = sprintf($this->module->l('Error while sending fax to the API : %s', 'adminmarketingfstep7'), $this->session_api->getError());
         return false;
     }
 }
Пример #21
0
 private function checkAddress()
 {
     $company_name = (string) Tools::getValue('company_name');
     $company_email = (string) Tools::getValue('company_email');
     $company_phone = (string) Tools::getValue('company_phone');
     $company_address1 = (string) Tools::getValue('company_address1');
     $company_address2 = (string) Tools::getValue('company_address2');
     $company_zipcode = (string) Tools::getValue('company_zipcode');
     $company_city = (string) Tools::getValue('company_city');
     $country_id = (int) Tools::getValue('country_id');
     $country = new Country($country_id);
     if (!is_object($country) || empty($country->id)) {
         $this->errors[] = Tools::displayError('Country is invalid');
     } else {
         $company_country = Country::getNameById($this->context->language->id, $country_id);
     }
     if (!Validate::isGenericName($company_name)) {
         $this->errors[] = sprintf(Tools::displayError('The %s field is required.'), '« ' . Translate::getAdminTranslation('Shop name', 'AdminStores') . ' »');
     }
     if (!Validate::isEmail($company_email)) {
         $this->errors[] = sprintf(Tools::displayError('The %s field is required.'), '« ' . Translate::getAdminTranslation('Shop email', 'AdminStores') . ' »');
     }
     if (!Validate::isPhoneNumber($company_phone)) {
         $this->errors[] = sprintf(Tools::displayError('The %s field is required.'), '« ' . Translate::getAdminTranslation('Phone', 'AdminStores') . ' »');
     }
     if (!Validate::isAddress($company_address1)) {
         $this->errors[] = sprintf(Tools::displayError('The %s field is required.'), '« ' . Translate::getAdminTranslation('Shop address line 1', 'AdminStores') . ' »');
     }
     if ($country->zip_code_format && !$country->checkZipCode($company_zipcode)) {
         $this->errors[] = Tools::displayError('Your Zip/postal code is incorrect.') . '<br />' . Tools::displayError('It must be entered as follows:') . ' ' . str_replace('C', $country->iso_code, str_replace('N', '0', str_replace('L', 'A', $country->zip_code_format)));
     } elseif (empty($company_zipcode) && $country->need_zip_code) {
         $this->errors[] = Tools::displayError('A Zip/postal code is required.');
     } elseif ($company_zipcode && !Validate::isPostCode($company_zipcode)) {
         $this->errors[] = Tools::displayError('The Zip/postal code is invalid.');
     }
     if (!Validate::isGenericName($company_city)) {
         $this->errors[] = sprintf(Tools::displayError('The %s field is required.'), '« ' . Translate::getAdminTranslation('City', 'AdminStores') . ' »');
     }
     // We save these informations in the database
     // ------------------------------------------
     Db::getInstance()->insert('expressmailing_order_address', array('id_address' => 1, 'company_name' => pSQL($company_name), 'company_email' => pSQL($company_email), 'company_address1' => pSQL($company_address1), 'company_address2' => pSQL($company_address2), 'company_zipcode' => pSQL($company_zipcode), 'company_city' => pSQL($company_city), 'country_id' => (int) $country_id, 'company_country' => pSQL($company_country), 'company_phone' => pSQL($company_phone)), false, false, Db::REPLACE);
     // If no error we update the cart
     // ------------------------------
     if (!count($this->errors)) {
         $response = array();
         $parameters = array('order_session' => $this->order_session, 'account_email' => $company_email);
         $this->session_api->callExternal('http://www.express-mailing.com/api/cart/ws.php', 'common', 'order', 'update', $parameters, $response);
     }
     return !count($this->errors);
 }