public function installConfig() { $rand_letters = range('a', 'z'); shuffle($rand_letters); // Creation of employee NetEven $new_employe = new Employee(); $new_employe->lastname = 'Employee'; $new_employe->firstname = 'NetEven'; $new_employe->id_lang = (int) $this->context->language->id; $new_employe->email = 'empl' . rand(0, 100) . $rand_letters[0] . rand(0, 100) . '@neteven.com'; $new_employe->passwd = $rand_letters[0] . '$&-$&-$&-$&' . rand(0, 1000); $new_employe->id_profile = 3; $new_employe->active = 0; $new_employe->add(); Gateway::updateConfig('ID_EMPLOYEE_NETEVEN', (int) $new_employe->id); // Creation of customer Neteven $new_customer = new Customer(); $new_customer->lastname = 'Client'; $new_customer->firstname = 'NetEven'; $new_customer->passwd = $rand_letters[0] . '$&-$&-$&-$&' . rand(0, 1000); $new_customer->email = 'cust' . rand(0, 100) . $rand_letters[0] . rand(0, 100) . '@neteven.com'; $new_customer->newsletter = 0; $new_customer->optin = 0; $new_customer->add(); Gateway::updateConfig('ID_CUSTOMER_NETEVEN', (int) $new_customer->id); // Creation of order status Neteven $order_state = new OrderState(); $order_state->name = array(); foreach (Language::getLanguages() as $language) { $order_state->name[(int) $language['id_lang']] = $this->l('Statut NetEven'); } $order_state->send_email = false; $order_state->color = '#7d204d'; $order_state->hidden = false; $order_state->delivery = false; $order_state->logable = false; $order_state->invoice = false; if ($order_state->add()) { $source = dirname(__FILE__) . '/img/os.gif'; $destination = dirname(__FILE__) . '/../../img/os/' . (int) $order_state->id . '.gif'; copy($source, $destination); } // Set the configuration Gateway::updateConfig('ID_ORDER_STATE_NETEVEN', $order_state->id); Gateway::updateConfig('SHIPPING_DELAY', 3); Gateway::updateConfig('COMMENT', $this->l('Livraison rapide et soignée')); Gateway::updateConfig('DEFAULT_BRAND', Configuration::get('PS_SHOP_NAME')); Gateway::updateConfig('COUNTRY_DEFAULT', 8); Gateway::updateConfig('PASSWORD_DEFAULT', 'password'); Gateway::updateConfig('NETEVEN_URL', 'http://ws.neteven.com/NWS'); Gateway::updateConfig('NETEVEN_NS', 'urn:NWS:examples'); Gateway::updateConfig('SYNCHRONISATION_ORDER', 0); Gateway::updateConfig('SYNCHRONISATION_PRODUCT', 0); Gateway::updateConfig('MAIL_ACTIVE', 1); Gateway::updateConfig('SEND_SHIPPING_PRICE', 0); Gateway::updateConfig('SHIPPING_BY_PRODUCT', 0); Gateway::updateConfig('SHIPPING_BY_PRODUCT_FIELDNAME', 'additional_shipping_cost'); Gateway::updateConfig('IMAGE_TYPE_NAME', ''); $this->installCarrier(); return true; }
<?php include 'Employee.php'; if ($_POST) { $emp = new Employee(); $emp->add(); $emp->index(); } ?> <HTML> <BODY> <form name="add" method="post" enctype="multipart/form-data"> <center>Name: <input type="text" id= "P_name" name="P_name"></center><br> <center>Age: <input type="text" id= "P_age" name="P_age"></center><br> <center>Occupation: <input type="text" id= "P_occup" name="P_occup"></center><br> <center>Address: <input type="text" id= "P_addr" name="P_addr"></center><br> <center>Image:<input type="file" name="fileToUpload" id="fileToUpload"></center><br> <center><input type="submit" class="button" name="Add" value="submit" /></center><br> </BODY> </HTML>
/** * PROCESS : configureShop * Set default shop configuration */ public function configureShop(array $data = array()) { //clear image cache in tmp folder if (file_exists(_PS_TMP_IMG_DIR_)) { foreach (scandir(_PS_TMP_IMG_DIR_) as $file) { if ($file[0] != '.' && $file != 'index.php') { Tools::deleteFile(_PS_TMP_IMG_DIR_ . $file); } } } $default_data = array('shop_name' => 'My Shop', 'shop_activity' => '', 'shop_country' => 'us', 'shop_timezone' => 'US/Eastern', 'use_smtp' => false, 'smtp_server' => '', 'smtp_login' => '', 'smtp_password' => '', 'smtp_encryption' => 'off', 'smtp_port' => 25); foreach ($default_data as $k => $v) { if (!isset($data[$k])) { $data[$k] = $v; } } Context::getContext()->shop = new Shop(1); Configuration::loadConfiguration(); // use the old image system if the safe_mod is enabled otherwise the installer will fail with the fixtures installation if (InstallSession::getInstance()->safe_mode) { Configuration::updateGlobalValue('PS_LEGACY_IMAGES', 1); } $id_country = Country::getByIso($data['shop_country']); // Set default configuration Configuration::updateGlobalValue('PS_SHOP_DOMAIN', Tools::getHttpHost()); Configuration::updateGlobalValue('PS_SHOP_DOMAIN_SSL', Tools::getHttpHost()); Configuration::updateGlobalValue('PS_INSTALL_VERSION', _PS_INSTALL_VERSION_); Configuration::updateGlobalValue('PS_LOCALE_LANGUAGE', $this->language->getLanguageIso()); Configuration::updateGlobalValue('PS_SHOP_NAME', $data['shop_name']); Configuration::updateGlobalValue('PS_SHOP_ACTIVITY', $data['shop_activity']); Configuration::updateGlobalValue('PS_COUNTRY_DEFAULT', $id_country); Configuration::updateGlobalValue('PS_LOCALE_COUNTRY', $data['shop_country']); Configuration::updateGlobalValue('PS_TIMEZONE', $data['shop_timezone']); Configuration::updateGlobalValue('PS_CONFIGURATION_AGREMENT', (int) $data['configuration_agrement']); // Set mails configuration Configuration::updateGlobalValue('PS_MAIL_METHOD', $data['use_smtp'] ? 2 : 1); Configuration::updateGlobalValue('PS_MAIL_SERVER', $data['smtp_server']); Configuration::updateGlobalValue('PS_MAIL_USER', $data['smtp_login']); Configuration::updateGlobalValue('PS_MAIL_PASSWD', $data['smtp_password']); Configuration::updateGlobalValue('PS_MAIL_SMTP_ENCRYPTION', $data['smtp_encryption']); Configuration::updateGlobalValue('PS_MAIL_SMTP_PORT', $data['smtp_port']); // Activate rijndael 128 encrypt algorihtm if mcrypt is activated Configuration::updateGlobalValue('PS_CIPHER_ALGORITHM', function_exists('mcrypt_encrypt') ? 1 : 0); // Set logo configuration if (file_exists(_PS_IMG_DIR_ . 'logo.jpg')) { list($width, $height) = getimagesize(_PS_IMG_DIR_ . 'logo.jpg'); Configuration::updateGlobalValue('SHOP_LOGO_WIDTH', round($width)); Configuration::updateGlobalValue('SHOP_LOGO_HEIGHT', round($height)); } // Active only the country selected by the merchant Db::getInstance()->execute('UPDATE ' . _DB_PREFIX_ . 'country SET active = 0 WHERE id_country != ' . (int) $id_country); // Set localization configuration $version = str_replace('.', '', _PS_VERSION_); $version = substr($version, 0, 2); $localization_file_content = @Tools::file_get_contents('http://api.prestashop.com/localization/' . $version . '/' . $data['shop_country'] . '.xml'); if (!@simplexml_load_string($localization_file_content)) { $localization_file_content = false; } if (!$localization_file_content) { $localization_file = _PS_ROOT_DIR_ . '/localization/default.xml'; if (file_exists(_PS_ROOT_DIR_ . '/localization/' . $data['shop_country'] . '.xml')) { $localization_file = _PS_ROOT_DIR_ . '/localization/' . $data['shop_country'] . '.xml'; } $localization_file_content = file_get_contents($localization_file); } $locale = new LocalizationPackCore(); $locale->loadLocalisationPack($localization_file_content, '', true); // Create default employee if (isset($data['admin_firstname']) && isset($data['admin_lastname']) && isset($data['admin_password']) && isset($data['admin_email'])) { $employee = new Employee(); $employee->firstname = Tools::ucfirst($data['admin_firstname']); $employee->lastname = Tools::ucfirst($data['admin_lastname']); $employee->email = $data['admin_email']; $employee->passwd = md5(_COOKIE_KEY_ . $data['admin_password']); $employee->last_passwd_gen = date('Y-m-d h:i:s', strtotime('-360 minutes')); $employee->bo_theme = 'default'; $employee->default_tab = 1; $employee->active = true; $employee->id_profile = 1; $employee->id_lang = Configuration::get('PS_LANG_DEFAULT'); $employee->bo_show_screencast = 1; if (!$employee->add()) { $this->setError($this->language->l('Cannot create admin account')); return false; } } else { $this->setError($this->language->l('Cannot create admin account')); return false; } // Update default contact if (isset($data['admin_email'])) { Configuration::updateGlobalValue('PS_SHOP_EMAIL', $data['admin_email']); $contacts = new Collection('Contact'); foreach ($contacts as $contact) { $contact->email = $data['admin_email']; $contact->update(); } } return true; }
/** * PROCESS : configureShop * Set default shop configuration */ public function configureShop(array $data = array()) { //clear image cache in tmp folder if (file_exists(_PS_TMP_IMG_DIR_)) { foreach (scandir(_PS_TMP_IMG_DIR_) as $file) { if ($file[0] != '.' && $file != 'index.php') { Tools::deleteFile(_PS_TMP_IMG_DIR_ . $file); } } } $default_data = array('shop_name' => 'My Shop', 'shop_activity' => '', 'shop_country' => 'us', 'shop_timezone' => 'US/Eastern', 'use_smtp' => false, 'smtp_encryption' => 'off', 'smtp_port' => 25, 'rewrite_engine' => false); foreach ($default_data as $k => $v) { if (!isset($data[$k])) { $data[$k] = $v; } } Context::getContext()->shop = new Shop(1); Configuration::loadConfiguration(); // use the old image system if the safe_mod is enabled otherwise the installer will fail with the fixtures installation if (InstallSession::getInstance()->safe_mode) { Configuration::updateGlobalValue('PS_LEGACY_IMAGES', 1); } $id_country = Country::getByIso($data['shop_country']); // Set default configuration Configuration::updateGlobalValue('PS_SHOP_DOMAIN', Tools::getHttpHost()); Configuration::updateGlobalValue('PS_SHOP_DOMAIN_SSL', Tools::getHttpHost()); Configuration::updateGlobalValue('PS_INSTALL_VERSION', _PS_INSTALL_VERSION_); Configuration::updateGlobalValue('PS_LOCALE_LANGUAGE', $this->language->getLanguageIso()); Configuration::updateGlobalValue('PS_SHOP_NAME', $data['shop_name']); Configuration::updateGlobalValue('PS_SHOP_ACTIVITY', $data['shop_activity']); Configuration::updateGlobalValue('PS_COUNTRY_DEFAULT', $id_country); Configuration::updateGlobalValue('PS_LOCALE_COUNTRY', $data['shop_country']); Configuration::updateGlobalValue('PS_TIMEZONE', $data['shop_timezone']); Configuration::updateGlobalValue('PS_CONFIGURATION_AGREMENT', (int) $data['configuration_agrement']); // Set mails configuration Configuration::updateGlobalValue('PS_MAIL_METHOD', $data['use_smtp'] ? 2 : 1); Configuration::updateGlobalValue('PS_MAIL_SMTP_ENCRYPTION', $data['smtp_encryption']); Configuration::updateGlobalValue('PS_MAIL_SMTP_PORT', $data['smtp_port']); // Set default rewriting settings Configuration::updateGlobalValue('PS_REWRITING_SETTINGS', $data['rewrite_engine']); // Activate rijndael 128 encrypt algorihtm if mcrypt is activated Configuration::updateGlobalValue('PS_CIPHER_ALGORITHM', function_exists('mcrypt_encrypt') ? 1 : 0); $groups = Group::getGroups((int) Configuration::get('PS_LANG_DEFAULT')); $groups_default = Db::getInstance()->executeS('SELECT `name` FROM ' . _DB_PREFIX_ . 'configuration WHERE `name` LIKE "PS_%_GROUP" ORDER BY `id_configuration`'); foreach ($groups_default as &$group_default) { if (is_array($group_default) && isset($group_default['name'])) { $group_default = $group_default['name']; } } if (is_array($groups) && count($groups)) { foreach ($groups as $key => $group) { if (Configuration::get($groups_default[$key]) != $groups[$key]['id_group']) { Configuration::updateGlobalValue($groups_default[$key], (int) $groups[$key]['id_group']); } } } $states = Db::getInstance()->executeS('SELECT `id_order_state` FROM ' . _DB_PREFIX_ . 'order_state ORDER by `id_order_state`'); $states_default = Db::getInstance()->executeS('SELECT MIN(`id_configuration`), `name` FROM ' . _DB_PREFIX_ . 'configuration WHERE `name` LIKE "PS_OS_%" GROUP BY `value` ORDER BY`id_configuration`'); foreach ($states_default as &$state_default) { if (is_array($state_default) && isset($state_default['name'])) { $state_default = $state_default['name']; } } if (is_array($states) && count($states)) { foreach ($states as $key => $state) { if (Configuration::get($states_default[$key]) != $states[$key]['id_order_state']) { Configuration::updateGlobalValue($states_default[$key], (int) $states[$key]['id_order_state']); } } /* deprecated order state */ Configuration::updateGlobalValue('PS_OS_OUTOFSTOCK_PAID', (int) Configuration::get('PS_OS_OUTOFSTOCK')); } // Set logo configuration if (file_exists(_PS_IMG_DIR_ . 'logo.jpg')) { list($width, $height) = getimagesize(_PS_IMG_DIR_ . 'logo.jpg'); Configuration::updateGlobalValue('SHOP_LOGO_WIDTH', round($width)); Configuration::updateGlobalValue('SHOP_LOGO_HEIGHT', round($height)); } // Disable cache for debug mode if (_PS_MODE_DEV_) { Configuration::updateGlobalValue('PS_SMARTY_CACHE', 1); } // Active only the country selected by the merchant Db::getInstance()->execute('UPDATE ' . _DB_PREFIX_ . 'country SET active = 0 WHERE id_country != ' . (int) $id_country); // Set localization configuration $version = str_replace('.', '', _PS_VERSION_); $version = substr($version, 0, 2); $localization_file_content = $this->getLocalizationPackContent($version, $data['shop_country']); $locale = new LocalizationPackCore(); $locale->loadLocalisationPack($localization_file_content, '', true); // Create default employee if (isset($data['admin_firstname']) && isset($data['admin_lastname']) && isset($data['admin_password']) && isset($data['admin_email'])) { $employee = new Employee(); $employee->firstname = Tools::ucfirst($data['admin_firstname']); $employee->lastname = Tools::ucfirst($data['admin_lastname']); $employee->email = $data['admin_email']; $employee->passwd = md5(_COOKIE_KEY_ . $data['admin_password']); $employee->last_passwd_gen = date('Y-m-d h:i:s', strtotime('-360 minutes')); $employee->bo_theme = 'default'; $employee->default_tab = 1; $employee->active = true; $employee->optin = (bool) $data['send_informations']; $employee->id_profile = 1; $employee->id_lang = Configuration::get('PS_LANG_DEFAULT'); $employee->bo_menu = 1; if (!$employee->add()) { $this->setError($this->language->l('Cannot create admin account')); return false; } } else { $this->setError($this->language->l('Cannot create admin account')); return false; } // Update default contact if (isset($data['admin_email'])) { Configuration::updateGlobalValue('PS_SHOP_EMAIL', $data['admin_email']); $contacts = new PrestaShopCollection('Contact'); foreach ($contacts as $contact) { $contact->email = $data['admin_email']; $contact->update(); } } if (!@Tools::generateHtaccess(null, $data['rewrite_engine'])) { Configuration::updateGlobalValue('PS_REWRITING_SETTINGS', 0); } return true; }
<?php if (Tools::P('saveEmployee') == 'add') { $employee = new Employee(); if (Tools::P('passwd') != Tools::P('passwd_conf')) { $employee->_errors[] = '两次输入的密码不一样!'; } elseif (Employee::employeeExists(Tools::P('email'))) { $employee->_errors[] = '邮箱地址已存在!'; } else { $employee->copyFromPost(); $employee->add(); } if (is_array($employee->_errors) and count($employee->_errors) > 0) { $errors = $employee->_errors; } else { $_GET['id'] = $employee->id; UIAdminAlerts::conf('管理员已添加'); } } if (isset($_GET['id'])) { $id = (int) $_GET['id']; $obj = new Employee($id); } if (Tools::P('saveEmployee') == 'edit') { if (Tools::P('passwd') != Tools::P('passwd_conf')) { $obj->_errors[] = '两次输入的密码不一样!'; } elseif (Tools::P('email') != $obj->email && Employee::employeeExists(Tools::getRequest('email'))) { $obj->_errors[] = '邮箱地址已存在!'; } elseif (Validate::isLoadedObject($obj)) { $obj->copyFromPost(); $obj->update();
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; } }