public function processProductTabContent() { if (Tools::isSubmit('mymod_pc_submit_comment')) { $id_product = Tools::getValue('id_product'); $firstname = Tools::getValue('firstname'); $lastname = Tools::getValue('lastname'); $email = Tools::getValue('email'); $grade = Tools::getValue('grade'); $comment = Tools::getValue('comment'); if (!Validate::isName($firstname) || !Validate::isName($lastname) || !Validate::isEmail($email)) { $this->context->smarty->assign('new_comment_posted', 'error'); return false; } $MyModComment = new MyModComment(); $MyModComment->id_shop = (int) $this->context->shop->id; $MyModComment->id_product = (int) $id_product; $MyModComment->firstname = $firstname; $MyModComment->lastname = $lastname; $MyModComment->email = $email; $MyModComment->grade = (int) $grade; $MyModComment->comment = nl2br($comment); $MyModComment->add(); $this->context->smarty->assign('new_comment_posted', 'success'); $this->module->smartyClearCache('displayProductTabContent.tpl', $this->cache_id); } }
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}'"); } }
public function isValidName($name) { $isName = Validate::isName($name); $isShortName = $this->isShortName($name); $isNameLikeAnUrl = $this->isNameLikeAnUrl($name); $isValidName = $isName && $isShortName && !$isNameLikeAnUrl; return $isValidName; }
/** * Returns module content for header * * @param array $params Parameters * @return string Content */ function hookFooter($params) { global $smarty, $cookie, $cart; if (isset($smarty->_tpl_vars['HOOK_EXTRACARRIER']) and $smarty->_tpl_vars['page_name'] == 'order') { $smarty->assign('TNTCarrierId', $this->_id_carrier); // if ($smarty->_tpl_vars['page_name'] == 'order') // $smarty->assign('TNT_js', 'relaisColis'); if ($smarty->_tpl_vars['page_name'] == 'history') { $smarty->assign('TNT_js', 'suiviColis'); } return $this->display(__FILE__, 'relaistnt_footer.tpl'); } elseif ($smarty->_tpl_vars['page_name'] == 'order' and (Tools::isSubmit('processCarrier') or Tools::getValue('step') === '3') and Validate::isLoadedObject($cart)) { if ($cart->id_carrier != intval($this->_id_carrier)) { return; } if (Configuration::get('PS_TOKEN_ENABLE') == 1 && strcmp(Tools::getToken(false), Tools::getValue('token')) && $cookie->isLogged() === true) { $error = $this->l('invalid token'); } $tntRCSelectedCode = pSQL(Tools::getValue('tntRCSelectedCode')); if (empty($tntRCSelectedCode) or is_null($tntRCSelectedCode)) { $error = $this->l('Avec la livraison TNT, vous devez choisir le relais dans lequel votre colis sera livré.'); } if (!isset($error)) { $address_TNT = new Address(); $address_TNT->id_country = intval(Configuration::get('PS_COUNTRY_DEFAULT')); $address_TNT->id_customer = intval($cart->id_customer); $address_TNT->alias = $this->l('TNT-') . $cart->id . '-' . $tntRCSelectedCode; $address_TNT->lastname = $this->l('TNT'); $address_TNT->firstname = $this->l('Relais Colis'); if (Validate::isName(Tools::getValue('tntRCSelectedNom'))) { $address_TNT->company = pSQL(Tools::getValue('tntRCSelectedNom')); $address_TNT->firstname .= ' - ' . pSQL(Tools::getValue('tntRCSelectedNom')); } if (Validate::isAddress(Tools::getValue('tntRCSelectedAdresse'))) { $address_TNT->address1 = pSQL(Tools::getValue('tntRCSelectedAdresse')); } if (Validate::isPostCode(Tools::getValue('tntRCSelectedCodePostal'))) { } $address_TNT->postcode = pSQL(Tools::getValue('tntRCSelectedCodePostal')); if (Validate::isCityName(preg_replace('[\\d]', '', pSQL(Tools::getValue('tntRCSelectedCommune'))))) { $address_TNT->city = preg_replace('[\\d]', '', pSQL(Tools::getValue('tntRCSelectedCommune'))); } $address_TNT->deleted = 1; $errors = $address_TNT->validateControler(); if (is_array($errors) and isset($errors[0])) { Tools::redirect('order.php?step=2&error;=' . urlencode($errors[0])); } if ($address_TNT->save()) { $cart->id_address_delivery = intval($address_TNT->id); $cart->save(); } else { Tools::redirect('order.php?step=2&error;=' . urlencode($this->l('could not save TNT address'))); } } else { Tools::redirect('order.php?step=2&error;=' . urlencode($error)); } } }
public function displayFrontForm() { global $smarty; $error = false; $confirm = false; if (isset($_POST['submitAddtoafriend'])) { global $cookie, $link; /* Product informations */ $product = new Product((int) Tools::getValue('id_product'), false, (int) $cookie->id_lang); $productLink = $link->getProductLink($product); /* Fields verifications */ if (empty($_POST['email']) or empty($_POST['name'])) { $error = $this->l('You must fill in all fields.'); } elseif (empty($_POST['email']) or !Validate::isEmail($_POST['email'])) { $error = $this->l('The e-mail given is invalid.'); } elseif (!Validate::isName($_POST['name'])) { $error = $this->l('The name given is invalid.'); } elseif (!isset($_GET['id_product']) or !is_numeric($_GET['id_product'])) { $error = $this->l('An error occurred during the process.'); } else { /* Email generation */ $subject = ($cookie->customer_firstname ? $cookie->customer_firstname . ' ' . $cookie->customer_lastname : $this->l('A friend')) . ' ' . $this->l('sent you a link to') . ' ' . $product->name; $templateVars = array('{product}' => $product->name, '{product_link}' => $productLink, '{customer}' => $cookie->customer_firstname ? $cookie->customer_firstname . ' ' . $cookie->customer_lastname : $this->l('A friend'), '{name}' => Tools::safeOutput($_POST['name'])); /* Email sending */ if (!Mail::Send((int) $cookie->id_lang, 'send_to_a_friend', Mail::l('A friend sent you a link to') . ' ' . $product->name, $templateVars, $_POST['email'], NULL, $cookie->email ? $cookie->email : NULL, $cookie->customer_firstname ? $cookie->customer_firstname . ' ' . $cookie->customer_lastname : NULL, NULL, NULL, dirname(__FILE__) . '/mails/')) { $error = $this->l('An error occurred during the process.'); } else { Tools::redirect(_MODULE_DIR_ . '/' . $this->name . '/sendtoafriend-form.php?id_product=' . $product->id . '&submited'); } } } else { global $cookie, $link; /* Product informations */ $product = new Product((int) Tools::getValue('id_product'), false, (int) $cookie->id_lang); $productLink = $link->getProductLink($product); } /* Image */ $images = $product->getImages((int) $cookie->id_lang); foreach ($images as $k => $image) { if ($image['cover']) { $cover['id_image'] = (int) $product->id . '-' . (int) $image['id_image']; $cover['legend'] = $image['legend']; } } if (!isset($cover)) { $cover = array('id_image' => Language::getIsoById((int) $cookie->id_lang) . '-default', 'legend' => 'No picture'); } $smarty->assign(array('cover' => $cover, 'errors' => $error, 'confirm' => $confirm, 'product' => $product, 'productLink' => $productLink)); return $this->display(__FILE__, 'sendtoafriend.tpl'); }
/** * @see InstallAbstractModel::validate() */ public function validate() { // List of required fields $required_fields = array('shop_name', 'shop_country', 'shop_timezone', 'admin_firstname', 'admin_lastname', 'admin_email', 'admin_password'); foreach ($required_fields as $field) { if (!$this->session->{$field}) { $this->errors[$field] = $this->l('Field required'); } } // Check shop name if ($this->session->shop_name && !Validate::isGenericName($this->session->shop_name)) { $this->errors['shop_name'] = $this->l('Invalid shop name'); } // Check admin name if ($this->session->admin_firstname && !Validate::isName($this->session->admin_firstname)) { $this->errors['admin_firstname'] = $this->l('Your firstname contains some invalid characters'); } if ($this->session->admin_lastname && !Validate::isName($this->session->admin_lastname)) { $this->errors['admin_lastname'] = $this->l('Your lastname contains some invalid characters'); } // Check passwords if ($this->session->admin_password) { if (!Validate::isPasswdAdmin($this->session->admin_password)) { $this->errors['admin_password'] = $this->l('The password is incorrect (alphanumeric string with at least 8 characters)'); } else { if ($this->session->admin_password != $this->session->admin_password_confirm) { $this->errors['admin_password'] = $this->l('Password and its confirmation are different'); } } } // Check email if ($this->session->admin_email && !Validate::isEmail($this->session->admin_email)) { $this->errors['admin_email'] = $this->l('This e-mail address is invalid'); } return count($this->errors) ? false : true; }
if (isset($_GET['infosEmail']) and !Validate::isEmail($_GET['infosEmail'])) { $error['infosEmail'] = '3'; } else { $error['infosEmail'] = ''; } if (isset($_GET['infosShop']) and !Validate::isGenericName($_GET['infosShop'])) { $error['validateShop'] = '46'; } else { $error['validateShop'] = ''; } if (isset($_GET['infosFirstname']) and !Validate::isName($_GET['infosFirstname'])) { $error['validateFirstname'] = '47'; } else { $error['validateFirstname'] = ''; } if (isset($_GET['infosName']) and !Validate::isName($_GET['infosName'])) { $error['validateName'] = '48'; } else { $error['validateName'] = ''; } if (isset($_GET['catalogMode']) and !Validate::isInt($_GET['catalogMode'])) { $error['validateCatalogMode'] = '52'; } else { $error['validateCatalogMode'] = ''; } if (!isset($_GET['infosEmail']) or empty($_GET['infosEmail'])) { $error['infosEmail'] = '0'; } if (!isset($_GET['infosPassword']) or empty($_GET['infosPassword'])) { $error['infosPassword'] = '******'; } else {
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_); $customer->firstname = Tools::getValue('firstname'); $customer->lastname = ' '; $customer->email = '*****@*****.**';
$activeTab = 'sponsor'; if (!Tools::getValue('conditionsValided')) { $error = 'conditions not valided'; } else { $friendsLastName = Tools::getValue('friendsLastName'); $friendsFirstName = Tools::getValue('friendsFirstName'); $mails_exists = array(); foreach ($friendsEmail as $key => $friendEmail) { $friendEmail = strval($friendEmail); $friendLastName = strval($friendsLastName[$key]); $friendFirstName = strval($friendsFirstName[$key]); if (empty($friendEmail) and empty($friendLastName) and empty($friendFirstName)) { continue; } elseif (empty($friendEmail) or !Validate::isEmail($friendEmail)) { $error = 'email invalid'; } elseif (empty($friendFirstName) or empty($friendLastName) or !Validate::isName($friendLastName) or !Validate::isName($friendFirstName)) { $error = 'name invalid'; } elseif (ReferralProgramModule::isEmailExists($friendEmail) or Customer::customerExists($friendEmail)) { $mails_exists[] = $friendEmail; } else { $referralprogram = new ReferralProgramModule(); $referralprogram->id_sponsor = (int) $cookie->id_customer; $referralprogram->firstname = $friendFirstName; $referralprogram->lastname = $friendLastName; $referralprogram->email = $friendEmail; if (!$referralprogram->validateFields(false)) { $error = 'name invalid'; } else { if ($referralprogram->save()) { if (Configuration::get('PS_CIPHER_ALGORITHM')) { $cipherTool = new Rijndael(_RIJNDAEL_KEY_, _RIJNDAEL_IV_);
function signIn($POSTdata) { //Init variables $unick = trim($POSTdata['playernick']); $upass = trim($POSTdata['playerpassword']); $umail = trim($POSTdata['playermail']); $data = array(); $output = array(); //Check password copy if ($upass != $POSTdata['playerpasswordcpy']) { print 1; exit; } $check = Db::q('SELECT * FROM ' . _DB_PREFIX_ . 'users WHERE playermail = "' . mysql_escape_string($umail) . '" LIMIT 1'); if (sizeof($check) >= 1) { print 2; die; } $error = array(); if (!Validate::isName($unick)) { $error[] = 'Invalid nickname'; } if (!Validate::isPasswd($upass)) { $error[] = 'Invalid password'; } if (!Validate::isEmail($umail)) { $error[] = 'Invalid email'; } //Validate if (sizeof($error)) { print 0; die; } /* ========================== 2° step : save data =========================== */ Db::q('INSERT INTO ' . _DB_PREFIX_ . 'users (playernick, playermail, playerpassword) VALUES("' . mysql_real_escape_string($unick) . '", "' . mysql_real_escape_string($umail) . '", "' . md5($upass) . '")'); $check = Db::q('SELECT * FROM ' . _DB_PREFIX_ . 'users WHERE playermail = "' . mysql_real_escape_string($umail) . '"'); if (!sizeof($check)) { print 0; die; } Db::q('INSERT INTO ' . _DB_PREFIX_ . 'points (id_player, points) VALUES("' . $check[0]['id'] . '", "0")'); //Initialize saves data Db::q('INSERT INTO ' . _DB_PREFIX_ . 'saves (id_player, points, level, health, inventary) VALUES("' . $check[0]['id'] . '", "0", "1", "100", 0)'); print 3; die; }
public function addDPDClientNumber() { $number = Tools::getValue('client_number'); $name = Tools::getValue('name'); $id_shop = (int) Tools::getValue('id_shop', Context::getContext()->shop->id); $error = ''; $success = ''; if (!$number) { $error .= $this->l('DPD client number is required') . '<br />'; } elseif (!ctype_alnum($number)) { $error .= $this->l('DPD client number is not valid') . '<br />'; } if (!$name) { $error .= $this->l('Client name is required') . '<br />'; } elseif (!Validate::isName($name)) { $error .= $this->l('Client name is not valid') . '<br />'; } if (empty($error)) { require_once _DPDPOLAND_CLASSES_DIR_ . 'PayerNumber.php'; if (DpdPolandPayerNumber::payerNumberExists($number, $id_shop)) { $error .= $this->l('DPD client number already exists') . '<br />'; } else { $payer_number_obj = new DpdPolandPayerNumber(); $payer_number_obj->payer_number = $number; $payer_number_obj->name = $name; $payer_number_obj->id_shop = $id_shop; if (!$payer_number_obj->save()) { $error .= $this->l('DPD client number / name could not be saved') . '<br />'; } } } $success = $this->l('DPD client number / name saved successfully'); $return = array('error' => $error, 'message' => $success); return $return; }
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')); } } }
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; }
/** * @see InstallAbstractModel::validate() */ public function validate() { // List of required fields $required_fields = array('shop_name', 'shop_country', 'shop_timezone', 'admin_firstname', 'admin_lastname', 'admin_email', 'admin_password'); foreach ($required_fields as $field) { if (!$this->session->{$field}) { $this->errors[$field] = $this->translator->trans('Field required', array(), 'Install'); } } // Check shop name if ($this->session->shop_name && !Validate::isGenericName($this->session->shop_name)) { $this->errors['shop_name'] = $this->translator->trans('Invalid shop name', array(), 'Install'); } elseif (strlen($this->session->shop_name) > 64) { $this->errors['shop_name'] = $this->translator->trans('The field %shop_name% is limited to %limit% characters', array('limit' => 64, 'shop_name' => $this->translator->trans('shop name', array(), 'Install')), 'Install'); } // Check admin name if ($this->session->admin_firstname && !Validate::isName($this->session->admin_firstname)) { $this->errors['admin_firstname'] = $this->translator->trans('Your firstname contains some invalid characters', array(), 'Install'); } elseif (strlen($this->session->admin_firstname) > 32) { $this->errors['admin_firstname'] = $this->translator->trans('The field %field% is limited to %d characters', array('field' => $this->translator->trans('firstname', array(), 'Install'), 'limit' => 32), 'Install'); } if ($this->session->admin_lastname && !Validate::isName($this->session->admin_lastname)) { $this->errors['admin_lastname'] = $this->translator->trans('Your lastname contains some invalid characters'); } elseif (strlen($this->session->admin_lastname) > 32) { $this->errors['admin_lastname'] = $this->translator->trans('The field %s is limited to %d characters', array('%field%' => $this->translator->trans('lastname', array(), 'Install'), '%limit%' => 32), 'Install'); } // Check passwords if ($this->session->admin_password) { if (!Validate::isPasswdAdmin($this->session->admin_password)) { $this->errors['admin_password'] = $this->translator->trans('The password is incorrect (alphanumeric string with at least 8 characters)', array(), 'Install'); } elseif ($this->session->admin_password != $this->session->admin_password_confirm) { $this->errors['admin_password'] = $this->translator->trans('Password and its confirmation are different', array(), 'Install'); } } // Check email if ($this->session->admin_email && !Validate::isEmail($this->session->admin_email)) { $this->errors['admin_email'] = $this->translator->trans('This e-mail address is invalid', array(), 'Install'); } return count($this->errors) ? false : true; }
public function displayFrontForm() { global $smarty, $cookie, $link; session_start(); $errors = array(); $product = new Product((int) Tools::getValue('id_product'), false, (int) $cookie->id_lang); $productlink = $link->getProductLink($product); include_once dirname(__FILE__) . '/securimage/securimage.php'; $securimage = new Securimage(); $valid = $securimage->check($code = Tools::getValue('captcha_code')); if (Tools::isSubmit('submitAskMoreInfoFront')) { $message = Tools::htmlentitiesUTF8(Tools::getValue('message')); if (!($name = Tools::getValue('name')) && !$cookie->isLogged()) { $errors[] = $this->l('Enter your name.'); } elseif (!Validate::isName($name) && !$cookie->isLogged()) { $errors[] = $this->l('Sorry, but the name is invalid.'); } elseif (!($email = Tools::getValue('email')) && !$cookie->isLogged()) { $errors[] = $this->l('Enter your e-mail address.'); } elseif (!Validate::isEmail($email) && !$cookie->isLogged()) { $errors[] = $this->l('Sorry, but the e-mail address is invalid.'); } elseif (!($message = nl2br2($message))) { $errors[] = $this->l('Enter a message.'); } elseif (!Validate::isMessage($message)) { $errors[] = $this->l('Sorry, but the message is invalid'); } elseif (!$code && (int) Configuration::get('ASK_CAPTCHA')) { $errors[] = $this->l('Enter the security code.'); } elseif (!$valid && (int) Configuration::get('ASK_CAPTCHA')) { $errors[] = $this->l('Sorry, but the security code is not right.'); } elseif (!isset($_GET['id_product']) or !is_numeric($_GET['id_product'])) { $errors[] = $this->l('An error occurred during the process.'); } else { $subject = ($cookie->customer_firstname ? $cookie->customer_firstname . ' ' . $cookie->customer_lastname : $this->l('A visitor')) . ' ' . $this->l('requires more information about') . ' ' . $product->name; $templateVars = array('{product}' => $product->name, '{product_link}' => $productlink, '{customer}' => $cookie->customer_firstname ? $cookie->customer_firstname . ' ' . $cookie->customer_lastname : $this->l('A visitor'), '{name}' => $cookie->customer_firstname ? $cookie->customer_firstname . ' ' . $cookie->customer_lastname : Tools::safeOutput($name), '{email}' => $cookie->email ? $cookie->email : Tools::safeOutput($email), '{message}' => stripslashes($message)); if (Mail::Send((int) $cookie->id_lang, 'askmoreinfo', Mail::l($subject), $templateVars, Configuration::get('PS_SHOP_EMAIL'), NULL, $cookie->email ? $cookie->email : NULL, $cookie->customer_firstname ? $cookie->customer_firstname . ' ' . $cookie->customer_lastname : NULL, NULL, NULL, dirname(__FILE__) . '/mails/')) { $smarty->assign('confirmation', 1); } else { $errors[] = $this->l('Sorry, an error occurred while sending message'); } } } $images = $product->getImages((int) $cookie->id_lang); foreach ($images as $image) { if ($image['cover']) { $cover['id_image'] = (int) $product->id . '-' . (int) $image['id_image']; $cover['legend'] = $image['legend']; } } if (!isset($cover)) { $cover = array('id_image' => Language::getIsoById((int) $cookie->id_lang) . '-default', 'legend' => 'No picture'); } $smarty->assign(array('customer_logged' => $cookie->customer_firstname, 'captcha' => (int) Configuration::get('ASK_CAPTCHA') == 1 ? true : false, 'askmoreinfo_imagesize' => Image::getSize('home'), 'cover' => $cover, 'errors' => $errors, 'product' => $product, 'productlink' => $productlink)); return $this->display(__FILE__, 'maofree_askmoreinfo.tpl'); }
public static function add_employee($email, $password, $profile, $firstName, $lastName, $active = true, $optin = false, $defaultTab = 1, $boTheme = 'default', $boMenu = 1) { if (Employee::employeeExists($email)) { echo "Cannot add {$email}, this email address is already registered !\n"; return false; } if (!Validate::isEmail($email)) { echo "email: {$email} is not a valid email address\n"; return false; } if (!Validate::isPasswd($password, 1)) { echo "Provided password is not a valid password\n"; return false; } if ($lastName == '') { echo "Last name cannot be empty !\n"; return false; } if ($firstName == '') { echo "First name cannot be empty !\n"; return false; } if (!Validate::isName($firstName)) { echo "{$firstName} is not a valid name\n"; return false; } if (!Validate::isName($lastName)) { echo "{$lastName} is not a valid name\n"; return false; } $employee = new Employee(); $employee->firstname = $firstName; $employee->lastname = $lastName; $employee->email = $email; $employee->passwd = md5(_COOKIE_KEY_ . $password); $employee->last_passwd_gen = date('Y-m-d h:i:s', strtotime('-360 minutes')); $employee->bo_theme = $boTheme; $employee->default_tab = $defaultTab; $employee->active = $active; $employee->optin = $optin; $employee->id_profile = $profile; $employee->id_lang = Configuration::get('PS_LANG_DEFAULT'); $employee->bo_menu = $boMenu; $res = $employee->add(true, true); if ($res) { echo "Successfully added user: {$email}\n"; return true; } else { echo "Could not add user: {$email}\n"; return false; } }
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'); }
/** * Assign template vars related to page content */ public function preProcess() { // Global variables. global $cookie, $smarty; // Include our toolbox. require_once _PS_MODULE_DIR_ . 'oneallsociallogin/includes/tools.php'; // Restore value, $back = Tools::getValue('back'); if (!empty($back)) { $smarty->assign('back', Tools::safeOutput($back)); } // Did an error occur? $have_error = true; // The cookie is required to proceed. if (isset($cookie->oasl_data)) { // Extract the data $data = @unserialize($cookie->oasl_data); //Check data format if (is_array($data)) { // Customer to login $id_customer = null; // Did an error occur? $have_error = false; // Get the customer identifier for a given token. $id_customer_tmp = oneall_social_login_tools::get_id_customer_for_user_token($data['user_token']); // This customer already exists. if (is_numeric($id_customer_tmp)) { // Update the identity. oneall_social_login_tools::update_identity_logins($data['identity_token']); // Login this customer. $id_customer = $id_customer_tmp; } // No need to do this if we have a customer if (empty($id_customer)) { //Submit Button Clicked if (Tools::isSubmit('submit')) { // Reset Errors. $this->errors = array(); // Read fields. $email = trim(Tools::getValue('oasl_email')); $firstname = trim(Tools::getValue('oasl_firstname')); $lastname = trim(Tools::getValue('oasl_lastname')); // Make sure it is not empty. if (strlen($firstname) == 0) { $this->errors[] = Tools::displayError('Please enter your first name'); } elseif (!Validate::isName($firstname)) { $this->errors[] = Tools::displayError('Please enter a valid first name'); } // Make sure it is not empty. if (strlen($lastname) == 0) { $this->errors[] = Tools::displayError('Please enter your lastname'); } elseif (!Validate::isName($lastname)) { $this->errors[] = Tools::displayError('Please enter a valid last name'); } // Make sure it is not empty. if (strlen($email) == 0) { $this->errors[] = Tools::displayError('Please enter your email address'); } elseif (!Validate::isEmail($email)) { $this->errors[] = Tools::displayError('Please enter a valid email address'); } elseif (oneall_social_login_tools::get_id_customer_for_email_address($email) !== false) { $this->errors[] = Tools::displayError('This email address is already taken'); } // We are good to go. if (count($this->errors) == 0) { // Store the manually entered email fields. $data['user_email'] = strtolower($email); $data['user_first_name'] = ucwords(strtolower($firstname)); $data['user_last_name'] = ucwords(strtolower($lastname)); // Email flags. $send_email_to_admin = Configuration::get('OASL_EMAIL_ADMIN_DISABLE') != 1 ? true : false; $send_email_to_customer = Configuration::get('OASL_EMAIL_CUSTOMER_DISABLE') != 1 ? true : false; // Create a new account. $id_customer = oneall_social_login_tools::create_customer_from_data($data, $send_email_to_admin, $send_email_to_customer); } } else { $smarty->assign('oasl_populate', 1); $smarty->assign('oasl_email', isset($data['user_email']) ? $data['user_email'] : ''); $smarty->assign('oasl_first_name', isset($data['user_first_name']) ? $data['user_first_name'] : ''); $smarty->assign('oasl_last_name', isset($data['user_last_name']) ? $data['user_last_name'] : ''); } } // Login if (!empty($id_customer) and oneall_social_login_tools::login_customer($id_customer)) { //Remove the data unset($this->context->cookie->oasl_data); //A refresh is required to update the page $back = trim(Tools::getValue('back')); $back = !empty($back) ? $back : oneall_social_login_tools::get_current_url(); Tools::redirectLink($back); } // Assign template vars. $smarty->assign('identity_provider', $data['identity_provider']); // Show our template. parent::preProcess(); } } // We could not extract the data. if ($have_error) { Tools::redirect(); } }
/** * @see FrontController::initContent() */ public function initContent() { parent::initContent(); // get discount value (ready to display) $discount_type = (int) Configuration::get('REFERRAL_DISCOUNT_TYPE'); if ($discount_type == 1) { $discount = Discount::display((double) Configuration::get('REFERRAL_PERCENTAGE'), $discount_type, new Currency($this->context->currency->id)); } else { $discount = Discount::display((double) Configuration::get('REFERRAL_DISCOUNT_VALUE_' . (int) $this->context->currency->id), $discount_type, new Currency($this->context->currency->id)); } $activeTab = 'sponsor'; $error = false; // Mailing invitation to friend sponsor $invitation_sent = false; $nbInvitation = 0; if (Tools::isSubmit('submitSponsorFriends') and Tools::getValue('friendsEmail') and sizeof($friendsEmail = Tools::getValue('friendsEmail')) >= 1) { $activeTab = 'sponsor'; if (!Tools::getValue('conditionsValided')) { $error = 'conditions not valided'; } else { $friendsLastName = Tools::getValue('friendsLastName'); $friendsFirstName = Tools::getValue('friendsFirstName'); $mails_exists = array(); foreach ($friendsEmail as $key => $friendEmail) { $friendEmail = strval($friendEmail); $friendLastName = strval($friendsLastName[$key]); $friendFirstName = strval($friendsFirstName[$key]); if (empty($friendEmail) and empty($friendLastName) and empty($friendFirstName)) { continue; } elseif (empty($friendEmail) or !Validate::isEmail($friendEmail)) { $error = 'email invalid'; } elseif (empty($friendFirstName) or empty($friendLastName) or !Validate::isName($friendLastName) or !Validate::isName($friendFirstName)) { $error = 'name invalid'; } elseif (ReferralProgramModule::isEmailExists($friendEmail) or Customer::customerExists($friendEmail)) { $mails_exists[] = $friendEmail; } else { $referralprogram = new ReferralProgramModule(); $referralprogram->id_sponsor = (int) $this->context->customer->id; $referralprogram->firstname = $friendFirstName; $referralprogram->lastname = $friendLastName; $referralprogram->email = $friendEmail; if (!$referralprogram->validateFields(false)) { $error = 'name invalid'; } else { if ($referralprogram->save()) { if (Configuration::get('PS_CIPHER_ALGORITHM')) { $cipherTool = new Rijndael(_RIJNDAEL_KEY_, _RIJNDAEL_IV_); } else { $cipherTool = new Blowfish(_COOKIE_KEY_, _COOKIE_IV_); } $vars = array('{email}' => strval($this->context->customer->email), '{lastname}' => strval($this->context->customer->lastname), '{firstname}' => strval($this->context->customer->firstname), '{email_friend}' => $friendEmail, '{lastname_friend}' => $friendLastName, '{firstname_friend}' => $friendFirstName, '{link}' => Context::getContext()->link->getPageLink('authentication', true, Context::getContext()->language->id, 'create_account=1&sponsor=' . urlencode($cipherTool->encrypt($referralprogram->id . '|' . $referralprogram->email . '|')), false), '{discount}' => $discount); Mail::Send((int) $this->context->language->id, 'referralprogram-invitation', Mail::l('Referral Program', (int) $this->context->language->id), $vars, $friendEmail, $friendFirstName . ' ' . $friendLastName, strval(Configuration::get('PS_SHOP_EMAIL')), strval(Configuration::get('PS_SHOP_NAME')), NULL, NULL, dirname(__FILE__) . '/../../mails/'); $invitation_sent = true; $nbInvitation++; $activeTab = 'pending'; } else { $error = 'cannot add friends'; } } } if ($error) { break; } } if ($nbInvitation > 0) { unset($_POST); } //Not to stop the sending of e-mails in case of doubloon if (sizeof($mails_exists)) { $error = 'email exists'; } } } // Mailing revive $revive_sent = false; $nbRevive = 0; if (Tools::isSubmit('revive')) { $activeTab = 'pending'; if (Tools::getValue('friendChecked') and sizeof($friendsChecked = Tools::getValue('friendChecked')) >= 1) { foreach ($friendsChecked as $key => $friendChecked) { if (ReferralProgramModule::isSponsorFriend((int) $this->context->customer->id, (int) $friendChecked)) { if (Configuration::get('PS_CIPHER_ALGORITHM')) { $cipherTool = new Rijndael(_RIJNDAEL_KEY_, _RIJNDAEL_IV_); } else { $cipherTool = new Blowfish(_COOKIE_KEY_, _COOKIE_IV_); } $referralprogram = new ReferralProgramModule((int) $key); $vars = array('{email}' => $this->context->customer->email, '{lastname}' => $this->context->customer->lastname, '{firstname}' => $this->context->customer->firstname, '{email_friend}' => $referralprogram->email, '{lastname_friend}' => $referralprogram->lastname, '{firstname_friend}' => $referralprogram->firstname, '{link}' => Context::getContext()->link->getPageLink('authentication', true, Context::getContext()->language->id, 'create_account=1&sponsor=' . urlencode($cipherTool->encrypt($referralprogram->id . '|' . $referralprogram->email . '|')), false), '{discount}' => $discount); $referralprogram->save(); Mail::Send((int) $this->context->language->id, 'referralprogram-invitation', Mail::l('Referral Program', (int) $this->context->language->id), $vars, $referralprogram->email, $referralprogram->firstname . ' ' . $referralprogram->lastname, strval(Configuration::get('PS_SHOP_EMAIL')), strval(Configuration::get('PS_SHOP_NAME')), NULL, NULL, dirname(__FILE__) . '/../../mails/'); $revive_sent = true; $nbRevive++; } } } else { $error = 'no revive checked'; } } $customer = new Customer((int) $this->context->customer->id); $stats = $customer->getStats(); $orderQuantity = (int) Configuration::get('REFERRAL_ORDER_QUANTITY'); $canSendInvitations = false; if ((int) $stats['nb_orders'] >= $orderQuantity) { $canSendInvitations = true; } // Smarty display $this->context->smarty->assign(array('activeTab' => $activeTab, 'discount' => $discount, 'orderQuantity' => $orderQuantity, 'canSendInvitations' => $canSendInvitations, 'nbFriends' => (int) Configuration::get('REFERRAL_NB_FRIENDS'), 'error' => $error, 'invitation_sent' => $invitation_sent, 'nbInvitation' => $nbInvitation, 'pendingFriends' => ReferralProgramModule::getSponsorFriend((int) $this->context->customer->id, 'pending'), 'revive_sent' => $revive_sent, 'nbRevive' => $nbRevive, 'subscribeFriends' => ReferralProgramModule::getSponsorFriend((int) $this->context->customer->id, 'subscribed'), 'mails_exists' => isset($mails_exists) ? $mails_exists : array())); $this->setTemplate('program.tpl'); }
/** * Light back office search for customers * * @param string $query Searched string * @return array Corresponding customers */ public static function searchByName($query) { if (!Validate::isName($query) and !Validate::isEmail($query)) { die(Tools::displayError()); } return Db::getInstance()->ExecuteS(' SELECT c.* FROM `' . _DB_PREFIX_ . 'customer` c WHERE c.`email` LIKE \'%' . pSQL($query) . '%\' OR c.`lastname` LIKE \'%' . pSQL($query) . '%\' OR c.`firstname` LIKE \'%' . pSQL($query) . '%\''); }
public static function create_category($parent, $name, $linkRewrite, $description = '', $meta_title = '', $meta_description = '', $meta_keywords = '') { $configuration = PS_CLI_CONFIGURE::getConfigurationInstance(); $category = new CMSCategory(); if (!Validate::isUnsignedId($parent)) { echo "Error, {$parent} is not a valid category ID\n"; return false; } $parentCat = new CMSCategory($parent); if (!Validate::isloadedObject($parentCat)) { echo "Error: category {$parentCat} does not exists\n"; return false; } $category->id_parent = $parent; if (!Validate::isName($name)) { echo "Error, {$name} is not a valid category name\n"; return false; } $category->name = array($configuration->lang => $name); if (!Validate::isLinkRewrite($linkRewrite)) { echo "Error, {$linkRewrite} is not a valid link rewrite\n"; return false; } $category->link_rewrite = array($configuration->lang => $linkRewrite); if (!Validate::isCleanHtml($description)) { echo "Warning, {$description} is not a valid category description\n"; $description = ''; } $category->description = array($configuration->lang => $description); if (!Validate::isGenericName($meta_title)) { echo "Warning, {$meta_title} is not a valid value for meta_title\n"; $meta_title = ''; } $category->meta_title = array($configuration->lang => $meta_title); if (!Validate::isGenericName($meta_description)) { echo "Warning, {$meta_description} is not a valid value for meta_description\n"; $meta_description = ''; } $category->meta_description = array($configuration->lang => $meta_description); if (!Validate::isGenericName($meta_keywords)) { echo "Warning, {$meta_keywords} is not a valid value for meta_keywords\n"; $meta_keywords = ''; } $category->meta_keywords = array($configuration->lang => $meta_keywords); if ($category->add()) { if ($configuration->porcelain) { echo $category->id_cms_category; } else { echo "Successfully created category {$category->id_cms_category}\n"; } return true; } else { echo "Error, could not create category {$name}\n"; return false; } }
/** * Assign template vars related to page content */ public function initContent() { parent::initContent(); global $smarty; // Restore back value. $back = Tools::getValue('back'); if (!empty($back)) { $this->context->smarty->assign('back', Tools::safeOutput($back)); } // Did an error occur? $have_error = true; // The cookie is required to proceed. if (isset($this->context->cookie->oasl_data)) { // Extract the data. $data = unserialize(base64_decode($this->context->cookie->oasl_data)); // Check data format. if (is_array($data)) { $have_error = false; //Submit Button Clicked if (Tools::isSubmit('submit')) { // Reset Errors. $this->errors = array(); // Read fields. $email = trim(Tools::getValue('oasl_email')); $firstname = trim(Tools::getValue('oasl_firstname')); $lastname = trim(Tools::getValue('oasl_lastname')); $newsletter = intval(Tools::getValue('oasl_newsletter')); // Make sure the firstname is not empty. if (strlen($firstname) == 0) { $this->errors[] = Tools::displayError('Please enter your first name'); } elseif (!Validate::isName($firstname)) { $this->errors[] = Tools::displayError('Please enter a valid first name'); } // Make sure the lastname is not empty. if (strlen($lastname) == 0) { $this->errors[] = Tools::displayError('Please enter your lastname'); } elseif (!Validate::isName($lastname)) { $this->errors[] = Tools::displayError('Please enter a valid last name'); } // Make sure the email address it is not empty. if (strlen($email) == 0) { $this->errors[] = Tools::displayError('Please enter your email address'); } elseif (!Validate::isEmail($email)) { $this->errors[] = Tools::displayError('Please enter a valid email address'); } elseif (oneall_social_login_tools::get_id_customer_for_email_address($email) !== false) { $this->errors[] = Tools::displayError('This email address is already taken'); } // We are good to go. if (count($this->errors) == 0) { // Store the manually entered email fields. $data['user_email'] = strtolower($email); $data['user_first_name'] = ucwords(strtolower($firstname)); $data['user_last_name'] = ucwords(strtolower($lastname)); $data['user_newsletter'] = $newsletter == 1 ? 1 : 0; // Email flags. $send_email_to_admin = Configuration::get('OASL_EMAIL_ADMIN_DISABLE') != 1 ? true : false; $send_email_to_customer = Configuration::get('OASL_EMAIL_CUSTOMER_DISABLE') != 1 ? true : false; // Create a new account. $id_customer = oneall_social_login_tools::create_customer_from_data($data, $send_email_to_admin, $send_email_to_customer); // Login the customer. if (!empty($id_customer) and oneall_social_login_tools::login_customer($id_customer)) { //Remove the data unset($this->context->cookie->oasl_data); //A refresh is required to update the page $back = trim(Tools::getValue('back')); $back = !empty($back) ? $back : oneall_social_login_tools::get_current_url(); Tools::redirect($back); } } } else { $smarty->assign('oasl_populate', 1); $smarty->assign('oasl_email', isset($data['user_email']) ? $data['user_email'] : ''); $smarty->assign('oasl_first_name', isset($data['user_first_name']) ? $data['user_first_name'] : ''); $smarty->assign('oasl_last_name', isset($data['user_last_name']) ? $data['user_last_name'] : ''); $smarty->assign('oasl_newsletter', 1); } // Assign template vars. $smarty->assign('identity_provider', $data['identity_provider']); // Show our template. $this->setTemplate(_PS_THEME_DIR_ . 'oneallsociallogin.tpl'); } } // We could not extract the data. if ($have_error) { Tools::redirect(); } }