Example #1
0
 public function __construct()
 {
     parent::__construct();
     $this->domain = Tools::getShopDomain(true);
     $this->virtual_uri = '';
     $this->base_uri = '';
 }
Example #2
0
 function hookHeader($params)
 {
     global $smarty, $cookie;
     $id_category = (int) Tools::getValue('id_category');
     if (!$id_category) {
         if (isset($_SERVER['HTTP_REFERER']) and preg_match('!^(.*)\\/([0-9]+)\\-(.*[^\\.])|(.*)id_category=([0-9]+)(.*)$!', $_SERVER['HTTP_REFERER'], $regs) and !strstr($_SERVER['HTTP_REFERER'], '.html')) {
             if (isset($regs[2]) and is_numeric($regs[2])) {
                 $id_category = (int) $regs[2];
             } elseif (isset($regs[5]) and is_numeric($regs[5])) {
                 $id_category = (int) $regs[5];
             }
         } elseif ($id_product = (int) Tools::getValue('id_product')) {
             $product = new Product($id_product);
             $id_category = $product->id_category_default;
         }
     }
     $category = new Category($id_category);
     $orderByValues = array(0 => 'name', 1 => 'price', 2 => 'date_add', 3 => 'date_upd', 4 => 'position', 5 => 'manufacturer_name', 6 => 'quantity');
     $orderWayValues = array(0 => 'ASC', 1 => 'DESC');
     $orderBy = Tools::strtolower(Tools::getValue('orderby', $orderByValues[(int) Configuration::get('PS_PRODUCTS_ORDER_BY')]));
     $orderWay = Tools::strtoupper(Tools::getValue('orderway', $orderWayValues[(int) Configuration::get('PS_PRODUCTS_ORDER_WAY')]));
     if (!in_array($orderBy, $orderByValues)) {
         $orderBy = $orderByValues[0];
     }
     if (!in_array($orderWay, $orderWayValues)) {
         $orderWay = $orderWayValues[0];
     }
     $smarty->assign(array('feedUrl' => Tools::getShopDomain(true, true) . __PS_BASE_URI__ . 'modules/' . $this->name . '/rss.php?id_category=' . $id_category . '&orderby=' . $orderBy . '&orderway=' . $orderWay));
     return $this->display(__FILE__, 'feederHeader.tpl');
 }
Example #3
0
    public static function getJobForm($title = 'New cron task', $update = false)
    {
        $form = array(array('form' => array('legend' => array('title' => self::$module->l($title), 'icon' => 'icon-plus'), 'input' => array(), 'submit' => array('title' => self::$module->l('Save', 'CronJobsForms'), 'type' => 'submit', 'class' => 'btn btn-default pull-right'))));
        $id_shop = (int) Context::getContext()->shop->id;
        $id_shop_group = (int) Context::getContext()->shop->id_shop_group;
        $currencies_cron_url = Tools::getShopDomain(true, true) . __PS_BASE_URI__ . basename(_PS_ADMIN_DIR_);
        $currencies_cron_url .= '/cron_currency_rates.php?secure_key=' . md5(_COOKIE_KEY_ . Configuration::get('PS_SHOP_NAME'));
        if ($update == true && Tools::isSubmit('id_cronjob')) {
            $id_cronjob = (int) Tools::getValue('id_cronjob');
            $id_module = (int) Db::getInstance()->getValue('SELECT `id_module` FROM `' . _DB_PREFIX_ . self::$module->name . '`
				WHERE `id_cronjob` = \'' . (int) $id_cronjob . '\'
					AND `id_shop` = \'' . $id_shop . '\' AND `id_shop_group` = \'' . $id_shop_group . '\'');
            if ((bool) $id_module == true) {
                $form[0]['form']['input'][] = array('type' => 'free', 'name' => 'description', 'label' => self::$module->l('Task description', 'CronJobsForms'), 'placeholder' => self::$module->l('Update my currencies', 'CronJobsForms'));
                $form[0]['form']['input'][] = array('type' => 'free', 'name' => 'task', 'label' => self::$module->l('Target link', 'CronJobsForms'));
            } else {
                $form[0]['form']['input'][] = array('type' => 'text', 'name' => 'description', 'label' => self::$module->l('Task description', 'CronJobsForms'), 'desc' => self::$module->l('Enter a description for this task.', 'CronJobsForms'), 'placeholder' => self::$module->l('Update my currencies', 'CronJobsForms'));
                $form[0]['form']['input'][] = array('type' => 'text', 'name' => 'task', 'label' => self::$module->l('Target link', 'CronJobsForms'), 'desc' => self::$module->l('Set the link of your cron task.', 'CronJobsForms'), 'placeholder' => $currencies_cron_url);
            }
        } else {
            $form[0]['form']['input'][] = array('type' => 'text', 'name' => 'description', 'label' => self::$module->l('Task description', 'CronJobsForms'), 'desc' => self::$module->l('Enter a description for this task.', 'CronJobsForms'), 'placeholder' => self::$module->l('Update my currencies', 'CronJobsForms'));
            $form[0]['form']['input'][] = array('type' => 'text', 'name' => 'task', 'label' => self::$module->l('Target link', 'CronJobsForms'), 'desc' => self::$module->l('Do not forget to use an absolute URL to make it valid! The link also has to be on the same domain as the shop.', 'CronJobsForms'), 'placeholder' => $currencies_cron_url);
        }
        $form[0]['form']['input'][] = array('type' => 'select', 'name' => 'hour', 'label' => self::$module->l('Task frequency', 'CronJobsForms'), 'desc' => self::$module->l('At what time should this task be executed?', 'CronJobsForms'), 'options' => array('query' => self::getHoursFormOptions(), 'id' => 'id', 'name' => 'name'));
        $form[0]['form']['input'][] = array('type' => 'select', 'name' => 'day', 'desc' => self::$module->l('On which day of the month should this task be executed?', 'CronJobsForms'), 'options' => array('query' => self::getDaysFormOptions(), 'id' => 'id', 'name' => 'name'));
        $form[0]['form']['input'][] = array('type' => 'select', 'name' => 'month', 'desc' => self::$module->l('On what month should this task be executed?', 'CronJobsForms'), 'options' => array('query' => self::getMonthsFormOptions(), 'id' => 'id', 'name' => 'name'));
        $form[0]['form']['input'][] = array('type' => 'select', 'name' => 'day_of_week', 'desc' => self::$module->l('On which day of the week should this task be executed?', 'CronJobsForms'), 'options' => array('query' => self::getDaysofWeekFormOptions(), 'id' => 'id', 'name' => 'name'));
        return $form;
    }
/**
 * 
 * @param piwikanalyticsjs $module
 * @return boolean
 */
function upgrade_module_0_6_5($module)
{
    Configuration::updateValue('PIWIK_COOKIE_DOMAIN', '*.' . str_replace('www.', '', Tools::getShopDomain()));
    Configuration::updateValue('PIWIK_SET_DOMAINS', Tools::getShopDomain());
    Configuration::updateValue('PIWIK_DNT', 1);
    Configuration::updateValue('PIWIK_PROXY_SCRIPT', str_replace("http://", '', piwikanalyticsjs::getModuleLink($module->name, 'piwik')));
    return true;
}
Example #5
0
 private function _getShopURL()
 {
     $host = ((Configuration::get('PS_SSL_ENABLED') or !empty($_SERVER['HTTPS']) and strtolower($_SERVER['HTTPS']) != 'off') ? Tools::getShopDomainSsl() : Tools::getShopDomain()) . __PS_BASE_URI__;
     if (substr($host, 0, 4) != 'http') {
         $host = (Configuration::get('PS_SSL_ENABLED') or !empty($_SERVER['HTTPS']) and strtolower($_SERVER['HTTPS']) != 'off') ? 'https://' . $host : 'http://' . $host;
     }
     return $host;
 }
    public function init()
    {
        parent::init();
        $this->fields_list = array('id_currency' => array('title' => $this->l('ID'), 'align' => 'center', 'width' => 25), 'name' => array('title' => $this->l('Currency')), 'iso_code' => array('title' => $this->l('ISO code'), 'align' => 'center', 'width' => 80), 'iso_code_num' => array('title' => $this->l('ISO code number'), 'align' => 'center', 'width' => 120), 'sign' => array('title' => $this->l('Symbol'), 'width' => 20, 'align' => 'center', 'orderby' => false, 'search' => false), 'conversion_rate' => array('title' => $this->l('Conversion rate'), 'type' => 'float', 'align' => 'center', 'width' => 130, 'search' => false), 'active' => array('title' => $this->l('Enabled'), 'width' => 25, 'align' => 'center', 'active' => 'status', 'type' => 'bool', 'orderby' => false));
        $this->bulk_actions = array('delete' => array('text' => $this->l('Delete selected'), 'confirm' => $this->l('Delete selected items?')), 'enableSelection' => array('text' => $this->l('Enable selection')), 'disableSelection' => array('text' => $this->l('Disable selection')));
        $this->fields_options = array('change' => array('title' => $this->l('Currency rates'), 'image' => '../img/admin/exchangesrate.gif', 'description' => $this->l('Use PrestaShop\'s webservice to update your currency exchange rates. Please use caution, rates are provided as-is.'), 'submit' => array('title' => $this->l('Update currency rates'), 'class' => 'button', 'name' => 'SubmitExchangesRates')), 'cron' => array('title' => $this->l('Automatically update currency rates'), 'image' => '../img/admin/tab-tools.gif', 'info' => $this->l('Use PrestaShop\'s webservice to update your currency exchange rates. Please use caution, rates are provided as-is. Place this URL in crontab or access it manually daily') . ':<br />
					<b>' . Tools::getShopDomain(true, true) . __PS_BASE_URI__ . basename(_PS_ADMIN_DIR_) . '/cron_currency_rates.php?secure_key=' . md5(_COOKIE_KEY_ . Configuration::get('PS_SHOP_NAME')) . '</b></p>'));
    }
Example #7
0
 /**
  * Initialize the page
  */
 public function init()
 {
     if (!defined('_PS_BASE_URL_')) {
         define('_PS_BASE_URL_', Tools::getShopDomain(true));
     }
     if (!defined('_PS_BASE_URL_SSL_')) {
         define('_PS_BASE_URL_SSL_', Tools::getShopDomainSsl(true));
     }
 }
Example #8
0
 public function getContent()
 {
     /* display the module name */
     $this->_html = '<h2>' . $this->displayName . '</h2><br />';
     $this->_html .= $this->l('Url for example:') . '<br />';
     $orderBy = Tools::getProductsOrder('by');
     $orderWay = Tools::getProductsOrder('way');
     $this->_html .= Tools::getShopDomain(true, true) . __PS_BASE_URI__ . 'modules/' . $this->name . '/rss.php?id_category=<span style="color:red;">{id_category}</span>&amp;orderby=' . $orderBy . '&amp;orderway=' . $orderWay;
     $this->_html .= '<br /><br />' . $this->l('Replace') . ' <span style="color:red;">{id_category}</span> ' . $this->l('by the id category current or "0"');
     return $this->_html;
 }
Example #9
0
 public function initContent()
 {
     if (!Tools::usingSecureMode() && Configuration::get('PS_SSL_ENABLED')) {
         // You can uncomment these lines if you want to force https even from localhost and automatically redirect
         // header('HTTP/1.1 301 Moved Permanently');
         // header('Location: '.Tools::getShopDomainSsl(true).$_SERVER['REQUEST_URI']);
         // exit();
         $clientIsMaintenanceOrLocal = in_array(Tools::getRemoteAddr(), array_merge(array('127.0.0.1'), explode(',', Configuration::get('PS_MAINTENANCE_IP'))));
         // If ssl is enabled, https protocol is required. Exception for maintenance and local (127.0.0.1) IP
         if ($clientIsMaintenanceOrLocal) {
             $warningSslMessage = Tools::displayError('SSL is activated. However, your IP is allowed to enter unsecure mode for maintenance or local IP issues.');
         } else {
             $url = 'https://' . Tools::safeOutput(Tools::getServerName()) . Tools::safeOutput($_SERVER['REQUEST_URI']);
             $warningSslMessage = sprintf(Translate::ppTags(Tools::displayError('SSL is activated. Please connect using the following link to [1]log into secure mode (https://)[/1]', false), array('<a href="%s">')), $url);
         }
         $this->context->smarty->assign('warningSslMessage', $warningSslMessage);
     }
     if (file_exists(_PS_ADMIN_DIR_ . '/../install')) {
         $this->context->smarty->assign('wrong_install_name', true);
     }
     if (basename(_PS_ADMIN_DIR_) == 'admin' && file_exists(_PS_ADMIN_DIR_ . '/../admin/')) {
         $rand = 'admin' . sprintf('%03d', rand(0, 999)) . Tools::strtolower(Tools::passwdGen(6)) . '/';
         if (@rename(_PS_ADMIN_DIR_ . '/../admin/', _PS_ADMIN_DIR_ . '/../' . $rand)) {
             Tools::redirectAdmin('../' . $rand);
         } else {
             $this->context->smarty->assign(array('wrong_folder_name' => true));
         }
     } else {
         $rand = basename(_PS_ADMIN_DIR_) . '/';
     }
     $this->context->smarty->assign(array('randomNb' => $rand, 'adminUrl' => Tools::getCurrentUrlProtocolPrefix() . Tools::getShopDomain() . __PS_BASE_URI__ . $rand));
     // Redirect to admin panel
     if (Tools::isSubmit('redirect') && Validate::isControllerName(Tools::getValue('redirect'))) {
         $this->context->smarty->assign('redirect', Tools::getValue('redirect'));
     } else {
         $tab = new Tab((int) $this->context->employee->default_tab);
         $this->context->smarty->assign('redirect', $this->context->link->getAdminLink($tab->class_name));
     }
     if ($nb_errors = count($this->errors)) {
         $this->context->smarty->assign(array('errors' => $this->errors, 'nbErrors' => $nb_errors, 'shop_name' => Tools::safeOutput(Configuration::get('PS_SHOP_NAME')), 'disableDefaultErrorOutPut' => true));
     }
     if ($email = Tools::getValue('email')) {
         $this->context->smarty->assign('email', $email);
     }
     if ($password = Tools::getValue('password')) {
         $this->context->smarty->assign('password', $password);
     }
     $this->setMedia();
     $this->initHeader();
     parent::initContent();
     $this->initFooter();
     //force to disable modals
     $this->context->smarty->assign('modals', null);
 }
 public static function getShopDomain()
 {
     // use built-in method if found
     if (method_exists('Tools', 'getShopDomain')) {
         return Tools::getShopDomain(true);
     }
     // discover the domain ourselves
     if (!($domain = Configuration::get('PS_SHOP_DOMAIN'))) {
         $domain = Tools::getHttpHost();
     }
     return 'http://' . $domain;
 }
 public function ajaxProcessInfoQuery()
 {
     $this->content_only = true;
     $result = array('status' => false);
     if (time() > (int) Configuration::get('PP_INFO_CHECK_TIME')) {
         $protocol = Tools::getCurrentUrlProtocolPrefix();
         $iso_lang = Context::getContext()->language->iso_code;
         $iso_country = Context::getContext()->country->iso_code;
         $stream_context = @stream_context_create(array('http' => array('method' => 'GET', 'timeout' => 3)));
         $old_content = $this->getInfo();
         $msg = $old_content === false ? 0 : $old_content[0];
         $shop_url = ShopUrl::getShopUrls($this->context->shop->id)->where('main', '=', 1)->getFirst();
         $shop = $shop_url ? $shop_url->getURL() : Tools::getShopDomain();
         $date = Db::getInstance()->getValue('SELECT `date_add` FROM `' . _DB_PREFIX_ . 'configuration` WHERE `name` = \'PSM_ID_' . Tools::strtoupper($this->module->name) . '\'');
         $psm_date = $date ? urlencode(date('Y-m-d H:i:s', strtotime($date))) : '';
         $plugins_string = '';
         $plugins = $this->module->plugins();
         foreach ($plugins as $name => $api_version) {
             if (Module::isInstalled($name)) {
                 $plugins_string .= '&' . $name . '=' . $this->moduleVersion($name);
             }
         }
         $url = $protocol . 'store.psandmore.com/query/?key=' . $this->module->name . '&ver=' . $this->module->version . '&psm=' . PSM::getPSMId($this->module) . '&psm_date=' . $psm_date . $plugins_string . '&msg=' . $msg . '&iso_country=' . $iso_country . '&iso_lang=' . $iso_lang . '&shop=' . urlencode($shop);
         $contents = Tools::file_get_contents($url, false, $stream_context);
         $check_info_offset = 3600;
         if ($contents !== false) {
             $content = explode('|', $contents);
             if (is_numeric($content[0])) {
                 if (!$this->infoIgnore(false, $content[0])) {
                     if (Validate::isCleanHtml($content[1])) {
                         $this->putInfo($contents);
                         $check_info_offset = 86400;
                     }
                 }
             } else {
                 if ($content[0] == 'hide') {
                     Configuration::deleteByName('PP_INFO_CONTENT');
                 }
             }
         }
         Configuration::updateValue('PP_INFO_CHECK_TIME', time() + $check_info_offset);
     }
     $content = $this->getInfo();
     if ($content !== false) {
         if (!$this->infoIgnore($content)) {
             if (Validate::isCleanHtml($content[1])) {
                 $result['status'] = 'success';
                 $result['content'] = $content[1];
             }
         }
     }
     $this->content = Tools::jsonEncode($result);
 }
Example #12
0
 /**
  * Initialize the page
  */
 public function init()
 {
     if (_PS_MODE_DEV_ && $this->controller_type == 'admin') {
         set_error_handler(array(__CLASS__, 'myErrorHandler'));
     }
     if (!defined('_PS_BASE_URL_')) {
         define('_PS_BASE_URL_', Tools::getShopDomain(true));
     }
     if (!defined('_PS_BASE_URL_SSL_')) {
         define('_PS_BASE_URL_SSL_', Tools::getShopDomainSsl(true));
     }
 }
    public function __construct()
    {
        $this->bootstrap = true;
        $this->table = 'currency';
        $this->className = 'Currency';
        $this->lang = false;
        $this->fields_list = array('id_currency' => array('title' => $this->l('ID'), 'align' => 'center', 'class' => 'fixed-width-xs'), 'name' => array('title' => $this->l('Currency')), 'iso_code' => array('title' => $this->l('ISO code'), 'align' => 'center', 'class' => 'fixed-width-xs'), 'iso_code_num' => array('title' => $this->l('ISO code number'), 'align' => 'center', 'class' => 'fixed-width-xs'), 'sign' => array('title' => $this->l('Symbol'), 'width' => 20, 'align' => 'center', 'orderby' => false, 'search' => false, 'class' => 'fixed-width-xs'), 'conversion_rate' => array('title' => $this->l('Exchange rate'), 'type' => 'float', 'align' => 'center', 'width' => 130, 'search' => false, 'filter_key' => 'currency_shop!conversion_rate'), 'active' => array('title' => $this->l('Enabled'), 'width' => 25, 'align' => 'center', 'active' => 'status', 'type' => 'bool', 'orderby' => false, 'class' => 'fixed-width-sm'));
        $this->bulk_actions = array('delete' => array('text' => $this->l('Delete selected'), 'confirm' => $this->l('Delete selected items?'), 'icon' => 'icon-trash'));
        $this->fields_options = array('change' => array('title' => $this->l('Currency rates'), 'image' => '../img/admin/exchangesrate.gif', 'description' => $this->l('Use PrestaShop\'s webservice to update your currency\'s exchange rates. However, please use caution: rates are provided as-is.'), 'submit' => array('title' => $this->l('Update currency rates'), 'name' => 'SubmitExchangesRates')), 'cron' => array('title' => $this->l('Automatically update currency rates'), 'image' => '../img/admin/tab-tools.gif', 'info' => '<div class="alert alert-block"><p>' . $this->l('Use PrestaShop\'s webservice to update your currency exchange rates. However, please use caution: rates are provided as-is.') . '<br/>' . $this->l('You can place the following URL in your crontab file, or you can click it yourself regularly:') . '</p>
					<p><strong><a href="' . Tools::getShopDomain(true, true) . __PS_BASE_URI__ . basename(_PS_ADMIN_DIR_) . '/cron_currency_rates.php?secure_key=' . md5(_COOKIE_KEY_ . Configuration::get('PS_SHOP_NAME')) . '" onclick="return !window.open($(this).attr(\'href\'));">' . Tools::getShopDomain(true, true) . __PS_BASE_URI__ . basename(_PS_ADMIN_DIR_) . '/cron_currency_rates.php?secure_key=' . md5(_COOKIE_KEY_ . Configuration::get('PS_SHOP_NAME')) . '</a></strong></p></div>'));
        parent::__construct();
        $this->_select .= 'currency_shop.conversion_rate conversion_rate';
        $this->_join .= Shop::addSqlAssociation('currency', 'a');
        $this->_group .= 'GROUP BY a.id_currency';
    }
 /**
  * Get Jirafe application information, including app_id and token
  * @return array Jirafe application information
  */
 public function getApplication()
 {
     // First, get the application info from Prestashop
     $data = array('name' => Configuration::get('PS_SHOP_NAME'), 'url' => Tools::getShopDomain(true));
     // Next, get the Jirafe-specific application info stored in Prestashop
     $token = $this->get('token');
     if (!empty($token)) {
         $data['token'] = $token;
     }
     $appId = $this->get('app_id');
     if (!empty($appId)) {
         $data['app_id'] = $appId;
     }
     return $data;
 }
Example #15
0
 function hookHeader($params)
 {
     if (!($id_category = (int) Tools::getValue('id_category'))) {
         if (isset($_SERVER['HTTP_REFERER']) && strstr($_SERVER['HTTP_REFERER'], Tools::getHttpHost()) && preg_match('!^(.*)\\/([0-9]+)\\-(.*[^\\.])|(.*)id_category=([0-9]+)(.*)$!', $_SERVER['HTTP_REFERER'], $regs)) {
             if (isset($regs[2]) && is_numeric($regs[2])) {
                 $id_category = (int) $regs[2];
             } elseif (isset($regs[5]) && is_numeric($regs[5])) {
                 $id_category = (int) $regs[5];
             }
         } elseif ($id_post = (int) Tools::getValue('id_post')) {
             $id_category = $this->getPostcat($id_post);
         }
     }
     $this->smarty->assign(array('feedUrl' => Tools::getShopDomain(true, true) . __PS_BASE_URI__ . 'modules/' . $this->name . '/rss.php?id_category=' . $id_category));
     return $this->display(__FILE__, 'views/templates/front/blogfeedheader.tpl');
 }
Example #16
0
 /**
  * Constructor (initialization only)
  */
 public function __construct($protocol_link = null, $protocol_content = null)
 {
     $this->allow = (int) Configuration::get('PS_REWRITING_SETTINGS');
     $this->url = $_SERVER['SCRIPT_NAME'];
     $this->protocol_link = $protocol_link;
     $this->protocol_content = $protocol_content;
     if (!defined('_PS_BASE_URL_')) {
         define('_PS_BASE_URL_', Tools::getShopDomain(true));
     }
     if (!defined('_PS_BASE_URL_SSL_')) {
         define('_PS_BASE_URL_SSL_', Tools::getShopDomainSsl(true));
     }
     if (Link::$category_disable_rewrite === null) {
         Link::$category_disable_rewrite = array(Configuration::get('PS_HOME_CATEGORY'), Configuration::get('PS_ROOT_CATEGORY'));
     }
     $this->ssl_enable = Configuration::get('PS_SSL_ENABLED');
 }
 /**
  * @see FrontController::initContent()
  */
 public function initContent()
 {
     parent::initContent();
     try {
         $resp = new Maestrano_Saml_Response($_POST['SAMLResponse']);
         // Check if the Saml response is valid
         if ($resp->isValid()) {
             // Get the user as well as the user group
             $mnoUser = new Maestrano_Sso_User($resp);
             // intilize the user Model
             $userModel = new Maestrano_Sso_Model_User();
             // Find user in db by email if not exist then create locally
             $userResp = $userModel->findOrCreate($mnoUser);
             if ($userResp['id_employee'] > 0) {
                 //update the Cookie for prestashop
                 $cookie = new Cookie('psAdmin');
                 $cookie->id_employee = $userResp['id_employee'];
                 $cookie->email = $mnoUser->email;
                 $cookie->profile = $userResp['id_profile'];
                 $cookie->passwd = $userResp['passwd'];
                 $cookie->remote_addr = (int) ip2long(Tools::getRemoteAddr());
                 $cookie->last_activity = time();
                 // write the cookie in Prestashop session
                 $cookie->write();
                 // Once the user is created/identified, we store the maestrano session.
                 // This session will be used for single logout
                 $mnoSession = new Maestrano_Sso_Session($_SESSION, $mnoUser);
                 $mnoSession->save();
                 // If logged in redirect to admin dashboard startup page
                 if ($cookie->id_employee) {
                     $cookie = new Cookie('psAdDir');
                     Tools::redirect(Tools::getCurrentUrlProtocolPrefix() . Tools::getShopDomain() . __PS_BASE_URI__ . $cookie->admin_directory);
                 }
             }
         } else {
             echo '<p>There was an error during the authentication process.</p><br/>';
             echo '<p>Please try again. If issue persists please contact support@maestrano.com<p>';
             exit;
         }
     } catch (Exception $ex) {
         echo $ex;
         exit;
     }
 }
Example #18
0
 function hookHeader($params)
 {
     if (!($id_category = (int) Tools::getValue('id_category'))) {
         if (isset($_SERVER['HTTP_REFERER']) && preg_match('!^(.*)\\/([0-9]+)\\-(.*[^\\.])|(.*)id_category=([0-9]+)(.*)$!', $_SERVER['HTTP_REFERER'], $regs) && !strstr($_SERVER['HTTP_REFERER'], '.html')) {
             if (isset($regs[2]) && is_numeric($regs[2])) {
                 $id_category = (int) $regs[2];
             } elseif (isset($regs[5]) && is_numeric($regs[5])) {
                 $id_category = (int) $regs[5];
             }
         } elseif ($id_product = (int) Tools::getValue('id_product')) {
             $product = new Product($id_product);
             $id_category = $product->id_category_default;
         }
     }
     $orderBy = Tools::getProductsOrder('by', Tools::getValue('orderby'));
     $orderWay = Tools::getProductsOrder('way', Tools::getValue('orderway'));
     $this->smarty->assign(array('feedUrl' => Tools::getShopDomain(true, true) . __PS_BASE_URI__ . 'modules/' . $this->name . '/rss.php?id_category=' . $id_category . '&amp;orderby=' . $orderBy . '&amp;orderway=' . $orderWay));
     return $this->display(__FILE__, 'feederHeader.tpl');
 }
Example #19
0
 /**
  * Constructor (initialization only)
  */
 public function __construct($protocol_link = null, $protocol_content = null)
 {
     $this->allow = (int) Configuration::get('PS_REWRITING_SETTINGS');
     $this->url = $_SERVER['SCRIPT_NAME'];
     $this->protocol_link = $protocol_link;
     $this->protocol_content = $protocol_content;
     if (!defined('_PS_BASE_URL_')) {
         define('_PS_BASE_URL_', Tools::getShopDomain(true));
     }
     if (!defined('_PS_BASE_URL_SSL_')) {
         define('_PS_BASE_URL_SSL_', Tools::getShopDomainSsl(true));
     }
     if (Link::$category_disable_rewrite === null) {
         $categories = explode(",", Configuration::get('PS_EXCLUDE_CATEGORIES_FROM_URL'));
         $rewrite_dis_arr = array_merge(array(Configuration::get('PS_HOME_CATEGORY'), Configuration::get('PS_ROOT_CATEGORY')), $categories);
         Link::$category_disable_rewrite = $rewrite_dis_arr;
         // array(Configuration::get('PS_HOME_CATEGORY'), Configuration::get('PS_ROOT_CATEGORY'),'146','9');
     }
     $this->ssl_enable = Configuration::get('PS_SSL_ENABLED');
 }
 /**
  * Generate cookie for admin directory becuase prestashop have dynamic names of admin directory
  *
  * @return the directory name
  */
 public function cookieForAdminDirectory()
 {
     $pageURL = 'http';
     if (isset($_SERVER["HTTPS"]) && $_SERVER["HTTPS"] == "on") {
         $pageURL .= "s";
     }
     $pageURL .= "://";
     if ($_SERVER["SERVER_PORT"] != "80") {
         $pageURL .= $_SERVER["SERVER_NAME"] . ":" . $_SERVER["SERVER_PORT"] . $_SERVER["REQUEST_URI"];
     } else {
         $pageURL .= $_SERVER["SERVER_NAME"] . $_SERVER["REQUEST_URI"];
     }
     $pageURL = str_replace(Tools::getCurrentUrlProtocolPrefix() . Tools::getShopDomain() . __PS_BASE_URI__, '', $pageURL);
     $pageURL = str_replace(basename($pageURL), '', $pageURL);
     // Write cookie for the Admin directory
     $cookie = new Cookie('psAdDir');
     $cookie->admin_directory = $pageURL;
     $cookie->write();
     return $pageURL;
 }
Example #21
0
    private function _checkCurrentCountrie()
    {
        global $cookie;
        if (!in_array(strtolower($this->_currentIsoCodeCountry), $this->limited_countries)) {
            $query = '
				SELECT c_l.name as name
				FROM ' . _DB_PREFIX_ . 'country_lang as c_l
				LEFT JOIN ' . _DB_PREFIX_ . 'country as c
				ON c_l.id_country = c.id_country
				WHERE c_l.id_lang = ' . (int) $cookie->id_lang . ' 
				AND c.iso_code IN (';
            foreach ($this->limited_countries as $iso) {
                $query .= "'" . strtoupper($iso) . "', ";
            }
            $query = rtrim($query, ', ') . ')';
            $countriesName = Db::getInstance()->ExecuteS($query);
            $htmlError = '
				<div class="error">
					<p>' . $this->l('Your default country is') . ' : ' . Twenga::getCurrentCountryName() . '</p>
					<p>' . $this->l('Please select one of these available countries approved by Twenga') . ' :</p>
					<ul>';
            foreach ($countriesName as $c) {
                $htmlError .= '<li>' . $c['name'] . '</li>';
            }
            $url = Tools::getShopDomain(true) . $_SERVER['PHP_SELF'] . '?tab=AdminCountries&token=' . Tools::getAdminTokenLite('AdminCountries') . '#Countries';
            $htmlError .= '
					</ul>
					' . $this->l('Follow this link to change the country') . ' : <a style="color:#0282dc;" href="' . $url . '">here</a>
				</div>';
            throw new Exception($htmlError);
        }
    }
Example #22
0
 public function hookDisplayHeader($params)
 {
     $this->context->controller->addCSS($this->_path . 'views/css/gallery-styles.css', 'all');
     $this->context->controller->addCSS($this->_path . 'views/css/smartblogstyle.css', 'all');
     $this->smarty->assign(array('feedUrl' => Tools::getShopDomain(true, true) . __PS_BASE_URI__ . 'modules/' . $this->name . '/rss.php'));
     return $this->display(__FILE__, 'views/templates/front/plugins/blogfeedheader.tpl');
 }
Example #23
0
 protected static function isTaskURLValid($task)
 {
     $task = urlencode($task);
     if (strpos($task, urlencode(Tools::getShopDomain(true, true) . __PS_BASE_URI__)) !== 0 && strpos($task, urlencode(Tools::getShopDomainSsl(true, true) . __PS_BASE_URI__)) !== 0) {
         return false;
     }
     return true;
 }
Example #24
0
    private function _displaySitemap()
    {
        if (file_exists(GSITEMAP_FILE) and filesize(GSITEMAP_FILE)) {
            $fp = fopen(GSITEMAP_FILE, 'r');
            $fstat = fstat($fp);
            fclose($fp);
            $xml = simplexml_load_file(GSITEMAP_FILE);
            $nbPages = sizeof($xml->url);
            $this->_html .= '<p>' . $this->l('Your Google sitemap file is online at the following address:') . '<br />
			<a href="' . Tools::getShopDomain(true, true) . __PS_BASE_URI__ . 'sitemap.xml" target="_blank"><b>' . Tools::getShopDomain(true, true) . __PS_BASE_URI__ . 'sitemap.xml</b></a></p><br />';
            $this->_html .= $this->l('Update:') . ' <b>' . utf8_encode(strftime('%A %d %B %Y %H:%M:%S', $fstat['mtime'])) . '</b><br />';
            $this->_html .= $this->l('Filesize:') . ' <b>' . number_format($fstat['size'] * 1.0E-6, 3) . 'MB</b><br />';
            $this->_html .= $this->l('Indexed pages:') . ' <b>' . $nbPages . '</b><br /><br />';
        }
    }
Example #25
0
global $cookie;
$CheckPay=new greenworld_cvs();
$authorized = false;
foreach (Module::getPaymentModules() as $module)
    if ($module['name'] == $CheckPay->name){
            $authorized = true;
            break;
    }
if (!$authorized)
    die(Tools::displayError('This payment method is not available.'));


$customer = new Customer((int)$cart->id_customer);
$total = $cart->getOrderTotal(true, Cart::BOTH);
$inttotal=round($total);
$HomePage=Tools::getShopDomain(true, true).__PS_BASE_URI__;
$order = new Order((int)$CheckPay->currentOrder);
$PointToFinislURL='order-confirmation.php?key='.$customer->secure_key.'&id_cart='.(int)($cart->id).'&id_module='.(int)$CheckPay->id.'&id_order='.(int)$CheckPay->currentOrder;
$check=Tools::getValue("check");

$smarty->assign(array(
	'total' => $total ,
	'this_path' => "http://".$_SERVER["HTTP_HOST"].$CheckPay->path,
        'inttotal'=> $inttotal,
        'home'=> $HomePage
    ));
//
// SESSION["checkStep"] 用來防止,按上一頁,衍生出reload的問題。 
// 第一次進入開始並宣告 checkStep。
// 進入後呼叫模板 validationOrder.tpl,該模板是讓使用著知道自己將要繳多少錢, 並將checkStep設定值為字串 1
// validationOrder.tpl 當user按下確定鍵之後,會將也面在倒回此頁面
Example #26
0
 public static function addonsRequest($request, $params = array())
 {
     if (!self::$is_addons_up) {
         return false;
     }
     $postData = http_build_query(array('version' => isset($params['version']) ? $params['version'] : _PS_VERSION_, 'iso_lang' => Tools::strtolower(isset($params['iso_lang']) ? $params['iso_lang'] : Context::getContext()->language->iso_code), 'iso_code' => Tools::strtolower(isset($params['iso_country']) ? $params['iso_country'] : Country::getIsoById(Configuration::get('PS_COUNTRY_DEFAULT'))), 'shop_url' => isset($params['shop_url']) ? $params['shop_url'] : Tools::getShopDomain(), 'mail' => isset($params['email']) ? $params['email'] : Configuration::get('PS_SHOP_EMAIL')));
     $protocols = array('https');
     switch ($request) {
         case 'native':
             $protocols[] = 'http';
             $postData .= '&method=listing&action=native';
             break;
         case 'native_all':
             $protocols[] = 'http';
             $postData .= '&method=listing&action=native&iso_code=all';
             break;
         case 'must-have':
             $protocols[] = 'http';
             $postData .= '&method=listing&action=must-have';
             break;
         case 'must-have-themes':
             $protocols[] = 'http';
             $postData .= '&method=listing&action=must-have-themes';
             break;
         case 'customer':
             $postData .= '&method=listing&action=customer&username='******'&password='******'customer_themes':
             $postData .= '&method=listing&action=customer-themes&username='******'&password='******'check_customer':
             $postData .= '&method=check_customer&username='******'username_addons']) . '&password='******'password_addons']);
             break;
         case 'check_module':
             $postData .= '&method=check&module_name=' . urlencode($params['module_name']) . '&module_key=' . urlencode($params['module_key']);
             break;
         case 'module':
             $postData .= '&method=module&id_module=' . urlencode($params['id_module']);
             if (isset($params['username_addons']) && isset($params['password_addons'])) {
                 $postData .= '&username='******'username_addons']) . '&password='******'password_addons']);
             } else {
                 $protocols[] = 'http';
             }
             break;
         case 'install-modules':
             $protocols[] = 'http';
             $postData .= '&method=listing&action=install-modules';
             break;
         default:
             return false;
     }
     $context = stream_context_create(array('http' => array('method' => 'POST', 'content' => $postData, 'header' => 'Content-type: application/x-www-form-urlencoded', 'timeout' => 5)));
     foreach ($protocols as $protocol) {
         if ($content = Tools::file_get_contents($protocol . '://api.addons.prestashop.com', false, $context)) {
             return $content;
         }
     }
     self::$is_addons_up = false;
     return false;
 }
Example #27
0
 if (file_exists(_PS_TRANSLATIONS_DIR_ . $iso . '/errors.php')) {
     include _PS_TRANSLATIONS_DIR_ . $iso . '/errors.php';
 }
 if (file_exists(_PS_TRANSLATIONS_DIR_ . $iso . '/fields.php')) {
     include _PS_TRANSLATIONS_DIR_ . $iso . '/fields.php';
 }
 if (file_exists(_PS_TRANSLATIONS_DIR_ . $iso . '/admin.php')) {
     include _PS_TRANSLATIONS_DIR_ . $iso . '/admin.php';
 }
 /* Server Params */
 $protocol_link = Configuration::get('PS_SSL_ENABLED') ? 'https://' : 'http://';
 $protocol_content = (isset($useSSL) and $useSSL and Configuration::get('PS_SSL_ENABLED')) ? 'https://' : 'http://';
 $link = new Link($protocol_link, $protocol_content);
 $context->link = $link;
 if (!defined('_PS_BASE_URL_')) {
     define('_PS_BASE_URL_', Tools::getShopDomain(true));
 }
 if (!defined('_PS_BASE_URL_SSL_')) {
     define('_PS_BASE_URL_SSL_', Tools::getShopDomainSsl(true));
 }
 $path = dirname(__FILE__) . '/themes/';
 // if the current employee theme is not valid (check layout.tpl presence),
 // reset to default theme
 if (empty($context->employee->bo_theme) || !file_exists($path . $context->employee->bo_theme . '/template/layout.tpl')) {
     // default admin theme is "default".
     $context->employee->bo_theme = '';
     if (file_exists($path . 'default/template/layout.tpl')) {
         $context->employee->bo_theme = 'default';
     } else {
         // if default theme doesn't exists, try to find one, otherwise throw exception
         foreach (scandir($path) as $theme) {
    public function displayOptionsList()
    {
        global $currentIndex;
        $dir = explode(DIRECTORY_SEPARATOR, dirname(__FILE__));
        for ($i = 0; $i < 2; ++$i) {
            $adminDir = array_pop($dir);
        }
        parent::displayOptionsList();
        echo '<br /><br />
		<form action="' . $currentIndex . '&token=' . $this->token . '" method="post">
			<fieldset>
			<legend><img src="../img/admin/exchangesrate.gif" />' . $this->l('Currency rates') . '</legend>
			<label>' . $this->l('Update currency rates') . '</label>
				<div class="margin-form">
					<p>' . $this->l('Update your currencies exchanges rates with a real-time tool') . '</p>
				</div>
				<div class="margin-form">
					<input type="submit" value="' . $this->l('Update currency rates') . '" name="submitExchangesRates" class="button" />
				</div>
			</fieldset>
		</form>';
        echo '<br /></br />
		<fieldset>
			<legend><img src="../img/admin/tab-tools.gif" />' . $this->l('Currency rates update') . '</legend>
			<p>' . $this->l('Place this URL in crontab or call it manually daily') . ':<br />
			<b>' . Tools::getShopDomain(true, true) . __PS_BASE_URI__ . $adminDir . '/cron_currency_rates.php?secure_key=' . md5(_COOKIE_KEY_ . Configuration::get('PS_SHOP_NAME')) . '</b></p>
		</fieldset>';
    }
Example #29
0
 public function init()
 {
     /*
      * Globals are DEPRECATED as of version 1.5.
      * Use the Context to access objects instead.
      * Example: $this->context->cart
      */
     global $useSSL, $cookie, $smarty, $cart, $iso, $defaultCountry, $protocol_link, $protocol_content, $link, $css_files, $js_files, $currency;
     if (self::$initialized) {
         return;
     }
     self::$initialized = true;
     parent::init();
     // If current URL use SSL, set it true (used a lot for module redirect)
     if (Tools::usingSecureMode()) {
         $useSSL = true;
     }
     // For compatibility with globals, DEPRECATED as of version 1.5
     $css_files = $this->css_files;
     $js_files = $this->js_files;
     // If we call a SSL controller without SSL or a non SSL controller with SSL, we redirect with the right protocol
     if (Configuration::get('PS_SSL_ENABLED') && $_SERVER['REQUEST_METHOD'] != 'POST' && $this->ssl != Tools::usingSecureMode()) {
         header('HTTP/1.1 301 Moved Permanently');
         header('Cache-Control: no-cache');
         if ($this->ssl) {
             header('Location: ' . Tools::getShopDomainSsl(true) . $_SERVER['REQUEST_URI']);
         } else {
             header('Location: ' . Tools::getShopDomain(true) . $_SERVER['REQUEST_URI']);
         }
         exit;
     }
     if ($this->ajax) {
         $this->display_header = false;
         $this->display_footer = false;
     }
     // if account created with the 2 steps register process, remove 'accoun_created' from cookie
     if (isset($this->context->cookie->account_created)) {
         $this->context->smarty->assign('account_created', 1);
         unset($this->context->cookie->account_created);
     }
     ob_start();
     // Init cookie language
     // @TODO This method must be moved into switchLanguage
     Tools::setCookieLanguage($this->context->cookie);
     $protocol_link = Configuration::get('PS_SSL_ENABLED') || Tools::usingSecureMode() ? 'https://' : 'http://';
     $useSSL = isset($this->ssl) && $this->ssl && Configuration::get('PS_SSL_ENABLED') || Tools::usingSecureMode() ? true : false;
     $protocol_content = $useSSL ? 'https://' : 'http://';
     $link = new Link($protocol_link, $protocol_content);
     $this->context->link = $link;
     if ($id_cart = (int) $this->recoverCart()) {
         $this->context->cookie->id_cart = (int) $id_cart;
     }
     if ($this->auth && !$this->context->customer->isLogged($this->guestAllowed)) {
         Tools::redirect('index.php?controller=authentication' . ($this->authRedirection ? '&back=' . $this->authRedirection : ''));
     }
     /* Theme is missing */
     if (!is_dir(_PS_THEME_DIR_)) {
         throw new PrestaShopException(sprintf(Tools::displayError('Current theme unavailable "%s". Please check your theme directory name and permissions.'), basename(rtrim(_PS_THEME_DIR_, '/\\'))));
     }
     if (Configuration::get('PS_GEOLOCATION_ENABLED')) {
         if (($newDefault = $this->geolocationManagement($this->context->country)) && Validate::isLoadedObject($newDefault)) {
             $this->context->country = $newDefault;
         }
     }
     $currency = Tools::setCurrency($this->context->cookie);
     if (isset($_GET['logout']) || $this->context->customer->logged && Customer::isBanned($this->context->customer->id)) {
         $this->context->customer->logout();
         Tools::redirect(isset($_SERVER['HTTP_REFERER']) ? $_SERVER['HTTP_REFERER'] : null);
     } elseif (isset($_GET['mylogout'])) {
         $this->context->customer->mylogout();
         Tools::redirect(isset($_SERVER['HTTP_REFERER']) ? $_SERVER['HTTP_REFERER'] : null);
     }
     /* Cart already exists */
     if ((int) $this->context->cookie->id_cart) {
         $cart = new Cart($this->context->cookie->id_cart);
         if ($cart->OrderExists()) {
             unset($this->context->cookie->id_cart, $cart, $this->context->cookie->checkedTOS);
             $this->context->cookie->check_cgv = false;
         } elseif (intval(Configuration::get('PS_GEOLOCATION_ENABLED')) && !in_array(strtoupper($this->context->cookie->iso_code_country), explode(';', Configuration::get('PS_ALLOWED_COUNTRIES'))) && $cart->nbProducts() && intval(Configuration::get('PS_GEOLOCATION_NA_BEHAVIOR')) != -1 && !FrontController::isInWhitelistForGeolocation() && !in_array($_SERVER['SERVER_NAME'], array('localhost', '127.0.0.1'))) {
             unset($this->context->cookie->id_cart, $cart);
         } elseif ($this->context->cookie->id_customer != $cart->id_customer || $this->context->cookie->id_lang != $cart->id_lang || $currency->id != $cart->id_currency) {
             if ($this->context->cookie->id_customer) {
                 $cart->id_customer = (int) $this->context->cookie->id_customer;
             }
             $cart->id_lang = (int) $this->context->cookie->id_lang;
             $cart->id_currency = (int) $currency->id;
             $cart->update();
         }
         /* Select an address if not set */
         if (isset($cart) && (!isset($cart->id_address_delivery) || $cart->id_address_delivery == 0 || !isset($cart->id_address_invoice) || $cart->id_address_invoice == 0) && $this->context->cookie->id_customer) {
             $to_update = false;
             if (!isset($cart->id_address_delivery) || $cart->id_address_delivery == 0) {
                 $to_update = true;
                 $cart->id_address_delivery = (int) Address::getFirstCustomerAddressId($cart->id_customer);
             }
             if (!isset($cart->id_address_invoice) || $cart->id_address_invoice == 0) {
                 $to_update = true;
                 $cart->id_address_invoice = (int) Address::getFirstCustomerAddressId($cart->id_customer);
             }
             if ($to_update) {
                 $cart->update();
             }
         }
     }
     if (!isset($cart) || !$cart->id) {
         $cart = new Cart();
         $cart->id_lang = (int) $this->context->cookie->id_lang;
         $cart->id_currency = (int) $this->context->cookie->id_currency;
         $cart->id_guest = (int) $this->context->cookie->id_guest;
         $cart->id_shop_group = (int) $this->context->shop->id_shop_group;
         $cart->id_shop = $this->context->shop->id;
         if ($this->context->cookie->id_customer) {
             $cart->id_customer = (int) $this->context->cookie->id_customer;
             $cart->id_address_delivery = (int) Address::getFirstCustomerAddressId($cart->id_customer);
             $cart->id_address_invoice = $cart->id_address_delivery;
         } else {
             $cart->id_address_delivery = 0;
             $cart->id_address_invoice = 0;
         }
         // Needed if the merchant want to give a free product to every visitors
         $this->context->cart = $cart;
         CartRule::autoAddToCart($this->context);
     } else {
         $this->context->cart = $cart;
     }
     /* get page name to display it in body id */
     // Are we in a payment module
     $module_name = '';
     if (Validate::isModuleName(Tools::getValue('module'))) {
         $module_name = Tools::getValue('module');
     }
     if (!empty($this->page_name)) {
         $page_name = $this->page_name;
     } elseif (!empty($this->php_self)) {
         $page_name = $this->php_self;
     } elseif (Tools::getValue('fc') == 'module' && $module_name != '' && Module::getInstanceByName($module_name) instanceof PaymentModule) {
         $page_name = 'module-payment-submit';
     } elseif (preg_match('#^' . preg_quote($this->context->shop->physical_uri, '#') . 'modules/([a-zA-Z0-9_-]+?)/(.*)$#', $_SERVER['REQUEST_URI'], $m)) {
         $page_name = 'module-' . $m[1] . '-' . str_replace(array('.php', '/'), array('', '-'), $m[2]);
     } else {
         $page_name = Dispatcher::getInstance()->getController();
         $page_name = preg_match('/^[0-9]/', $page_name) ? 'page_' . $page_name : $page_name;
     }
     $this->context->smarty->assign(Meta::getMetaTags($this->context->language->id, $page_name));
     $this->context->smarty->assign('request_uri', Tools::safeOutput(urldecode($_SERVER['REQUEST_URI'])));
     /* Breadcrumb */
     $navigationPipe = Configuration::get('PS_NAVIGATION_PIPE') ? Configuration::get('PS_NAVIGATION_PIPE') : '>';
     $this->context->smarty->assign('navigationPipe', $navigationPipe);
     // Automatically redirect to the canonical URL if needed
     if (!empty($this->php_self) && !Tools::getValue('ajax')) {
         $this->canonicalRedirection($this->context->link->getPageLink($this->php_self, $this->ssl, $this->context->language->id));
     }
     Product::initPricesComputation();
     $display_tax_label = $this->context->country->display_tax_label;
     if (isset($cart->{Configuration::get('PS_TAX_ADDRESS_TYPE')}) && $cart->{Configuration::get('PS_TAX_ADDRESS_TYPE')}) {
         $infos = Address::getCountryAndState((int) $cart->{Configuration::get('PS_TAX_ADDRESS_TYPE')});
         $country = new Country((int) $infos['id_country']);
         $this->context->country = $country;
         if (Validate::isLoadedObject($country)) {
             $display_tax_label = $country->display_tax_label;
         }
     }
     $languages = Language::getLanguages(true, $this->context->shop->id);
     $meta_language = array();
     foreach ($languages as $lang) {
         $meta_language[] = $lang['iso_code'];
     }
     $compared_products = array();
     if (Configuration::get('PS_COMPARATOR_MAX_ITEM') && isset($this->context->cookie->id_compare)) {
         $compared_products = CompareProduct::getCompareProducts($this->context->cookie->id_compare);
     }
     $this->context->smarty->assign(array('mobile_device' => $this->context->getMobileDevice(), 'link' => $link, 'cart' => $cart, 'currency' => $currency, 'cookie' => $this->context->cookie, 'page_name' => $page_name, 'hide_left_column' => !$this->display_column_left, 'hide_right_column' => !$this->display_column_right, 'base_dir' => _PS_BASE_URL_ . __PS_BASE_URI__, 'base_dir_ssl' => $protocol_link . Tools::getShopDomainSsl() . __PS_BASE_URI__, 'content_dir' => $protocol_content . Tools::getHttpHost() . __PS_BASE_URI__, 'base_uri' => $protocol_content . Tools::getHttpHost() . __PS_BASE_URI__ . (!Configuration::get('PS_REWRITING_SETTINGS') ? 'index.php' : ''), 'tpl_dir' => _PS_THEME_DIR_, 'modules_dir' => _MODULE_DIR_, 'mail_dir' => _MAIL_DIR_, 'lang_iso' => $this->context->language->iso_code, 'come_from' => Tools::getHttpHost(true, true) . Tools::htmlentitiesUTF8(str_replace(array('\'', '\\'), '', urldecode($_SERVER['REQUEST_URI']))), 'cart_qties' => (int) $cart->nbProducts(), 'currencies' => Currency::getCurrencies(), 'languages' => $languages, 'meta_language' => implode(',', $meta_language), 'priceDisplay' => Product::getTaxCalculationMethod((int) $this->context->cookie->id_customer), 'is_logged' => (bool) $this->context->customer->isLogged(), 'is_guest' => (bool) $this->context->customer->isGuest(), 'add_prod_display' => (int) Configuration::get('PS_ATTRIBUTE_CATEGORY_DISPLAY'), 'shop_name' => Configuration::get('PS_SHOP_NAME'), 'roundMode' => (int) Configuration::get('PS_PRICE_ROUND_MODE'), 'use_taxes' => (int) Configuration::get('PS_TAX'), 'show_taxes' => (int) (Configuration::get('PS_TAX_DISPLAY') == 1 && (int) Configuration::get('PS_TAX')), 'display_tax_label' => (bool) $display_tax_label, 'vat_management' => (int) Configuration::get('VATNUMBER_MANAGEMENT'), 'opc' => (bool) Configuration::get('PS_ORDER_PROCESS_TYPE'), 'PS_CATALOG_MODE' => (bool) Configuration::get('PS_CATALOG_MODE') || !(bool) Group::getCurrent()->show_prices, 'b2b_enable' => (bool) Configuration::get('PS_B2B_ENABLE'), 'request' => $link->getPaginationLink(false, false, false, true), 'PS_STOCK_MANAGEMENT' => Configuration::get('PS_STOCK_MANAGEMENT'), 'quick_view' => (bool) Configuration::get('PS_QUICK_VIEW'), 'shop_phone' => Configuration::get('PS_SHOP_PHONE'), 'compared_products' => is_array($compared_products) ? $compared_products : array(), 'comparator_max_item' => (int) Configuration::get('PS_COMPARATOR_MAX_ITEM')));
     // Add the tpl files directory for mobile
     if ($this->useMobileTheme()) {
         $this->context->smarty->assign(array('tpl_mobile_uri' => _PS_THEME_MOBILE_DIR_));
     }
     // Deprecated
     $this->context->smarty->assign(array('id_currency_cookie' => (int) $currency->id, 'logged' => $this->context->customer->isLogged(), 'customerName' => $this->context->customer->logged ? $this->context->cookie->customer_firstname . ' ' . $this->context->cookie->customer_lastname : false));
     $assign_array = array('img_ps_dir' => _PS_IMG_, 'img_cat_dir' => _THEME_CAT_DIR_, 'img_lang_dir' => _THEME_LANG_DIR_, 'img_prod_dir' => _THEME_PROD_DIR_, 'img_manu_dir' => _THEME_MANU_DIR_, 'img_sup_dir' => _THEME_SUP_DIR_, 'img_ship_dir' => _THEME_SHIP_DIR_, 'img_store_dir' => _THEME_STORE_DIR_, 'img_col_dir' => _THEME_COL_DIR_, 'img_dir' => _THEME_IMG_DIR_, 'css_dir' => _THEME_CSS_DIR_, 'js_dir' => _THEME_JS_DIR_, 'pic_dir' => _THEME_PROD_PIC_DIR_);
     // Add the images directory for mobile
     if ($this->useMobileTheme()) {
         $assign_array['img_mobile_dir'] = _THEME_MOBILE_IMG_DIR_;
     }
     // Add the CSS directory for mobile
     if ($this->useMobileTheme()) {
         $assign_array['css_mobile_dir'] = _THEME_MOBILE_CSS_DIR_;
     }
     foreach ($assign_array as $assign_key => $assign_value) {
         if (substr($assign_value, 0, 1) == '/' || $protocol_content == 'https://') {
             $this->context->smarty->assign($assign_key, $protocol_content . Tools::getMediaServer($assign_value) . $assign_value);
         } else {
             $this->context->smarty->assign($assign_key, $assign_value);
         }
     }
     /*
      * These shortcuts are DEPRECATED as of version 1.5.
      * Use the Context to access objects instead.
      * Example: $this->context->cart
      */
     self::$cookie = $this->context->cookie;
     self::$cart = $cart;
     self::$smarty = $this->context->smarty;
     self::$link = $link;
     $defaultCountry = $this->context->country;
     $this->displayMaintenancePage();
     if ($this->restrictedCountry) {
         $this->displayRestrictedCountryPage();
     }
     if (Tools::isSubmit('live_edit') && !$this->checkLiveEditAccess()) {
         Tools::redirect('index.php?controller=404');
     }
     $this->iso = $iso;
     $this->context->cart = $cart;
     $this->context->currency = $currency;
 }
Example #30
0
    public function getContent()
    {
        $html = '';
        /* Save settings */
        if (Tools::isSubmit('submitFollowUp')) {
            foreach ($this->confKeys as $c) {
                Configuration::updateValue($c, (double) Tools::getValue($c));
            }
        }
        /* Init */
        $conf = Configuration::getMultiple($this->confKeys);
        foreach ($this->confKeys as $k) {
            if (!isset($conf[$k])) {
                $conf[$k] = '';
            }
        }
        $currency = new Currency((int) Configuration::get('PS_CURRENCY_DEFAULT'));
        $n1 = $this->cancelledCart(true);
        $n2 = $this->reOrder(true);
        $n3 = $this->bestCustomer(true);
        $n4 = $this->badCustomer(true);
        $html .= '
		<h2>' . $this->l('Customer follow-up') . '</h2>
		<form action="' . Tools::safeOutput($_SERVER['REQUEST_URI']) . '" method="post">
			<fieldset style="width: 400px; float: left;">
				<legend><img src="' . $this->_path . 'logo.gif" alt="" title="" />' . $this->l('Settings') . '</legend>
				<p>' . $this->l('Four kinds of e-mail alerts available in order to stay in touch with your customers!') . '<br /><br />
				' . $this->l('Define settings and place this URL in crontab or call it manually daily:') . '<br />
				<b>' . Tools::getShopDomain(true, true) . __PS_BASE_URI__ . 'modules/followup/cron.php?secure_key=' . Configuration::get('PS_FOLLOWUP_SECURE_KEY') . '</b></p>
				<hr size="1" />
				<p><b>1. ' . $this->l('Cancelled carts') . '</b><br /><br />' . $this->l('For each cancelled cart (with no order), generate a discount and send it to the customer.') . '</p>
				<label>' . $this->l('Enable') . '</label>
				<div class="margin-form" style="padding-top: 5px;"><input type="checkbox" name="PS_FOLLOW_UP_ENABLE_1" value="1" style="vertical-align: middle;" ' . ($conf['PS_FOLLOW_UP_ENABLE_1'] == 1 ? 'checked="checked"' : '') . ' /></div>
				<label>' . $this->l('Discount amount') . '</label>
				<div class="margin-form"><input type="text" name="PS_FOLLOW_UP_AMOUNT_1" value="' . $conf['PS_FOLLOW_UP_AMOUNT_1'] . '" size="6" onKeyUp="javascript:this.value = this.value.replace(/,/g, \'.\');" /> %</div>
				<label>' . $this->l('Discount validity') . '</label>
				<div class="margin-form"><input type="text" name="PS_FOLLOW_UP_DAYS_1" value="' . $conf['PS_FOLLOW_UP_DAYS_1'] . '" size="6" /> ' . $this->l('day(s)') . '</div>
				<p>' . ($n1 > 1 ? sprintf($this->l('Next process will send: %d e-mails'), $n1) : sprintf($this->l('Next process will send: %d e-mail'), $n1)) . '</b></p>
				<hr size="1" />
				<p><b>2. ' . $this->l('Re-order') . '</b><br /><br />' . $this->l('For each validated order, generate a discount and send it to the customer.') . '</p>
				<label>' . $this->l('Enable') . '</label>
				<div class="margin-form" style="padding-top: 5px;"><input type="checkbox" name="PS_FOLLOW_UP_ENABLE_2" value="1" style="vertical-align: middle;" ' . ($conf['PS_FOLLOW_UP_ENABLE_2'] == 1 ? 'checked="checked"' : '') . ' /></div>
				<label>' . $this->l('Discount amount') . '</label>
				<div class="margin-form"><input type="text" name="PS_FOLLOW_UP_AMOUNT_2" value="' . $conf['PS_FOLLOW_UP_AMOUNT_2'] . '" size="6" onKeyUp="javascript:this.value = this.value.replace(/,/g, \'.\');" /> %</div>
				<label>' . $this->l('Discount validity') . '</label>
				<div class="margin-form"><input type="text" name="PS_FOLLOW_UP_DAYS_2" value="' . $conf['PS_FOLLOW_UP_DAYS_2'] . '" size="6" /> ' . $this->l('day(s)') . '</div>
				<p>' . ($n2 > 1 ? sprintf($this->l('Next process will send: %d e-mails'), $n2) : sprintf($this->l('Next process will send: %d e-mail'), $n2)) . '</b></p>
				<hr size="1" />
				<p><b>3. ' . $this->l('Best customers') . '</b><br /><br />' . $this->l('For each customer raising a threshold, generate a discount and send it to the customer.') . '</p>
				<label>' . $this->l('Enable') . '</label>
				<div class="margin-form" style="padding-top: 5px;"><input type="checkbox" name="PS_FOLLOW_UP_ENABLE_3" value="1" style="vertical-align: middle;" ' . ($conf['PS_FOLLOW_UP_ENABLE_3'] == 1 ? 'checked="checked"' : '') . ' /></div>
				<label>' . $this->l('Discount amount') . '</label>
				<div class="margin-form"><input type="text" name="PS_FOLLOW_UP_AMOUNT_3" value="' . $conf['PS_FOLLOW_UP_AMOUNT_3'] . '" size="6" onKeyUp="javascript:this.value = this.value.replace(/,/g, \'.\');" /> %</div>
				<label>' . $this->l('Threshold') . '</label>
				<div class="margin-form">' . ($currency->format == 1 ? ' ' . $currency->sign . ' ' : '') . '<input type="text" name="PS_FOLLOW_UP_THRESHOLD_3" value="' . $conf['PS_FOLLOW_UP_THRESHOLD_3'] . '" size="6" onKeyUp="javascript:this.value = this.value.replace(/,/g, \'.\');" /> ' . ($currency->format == 2 ? ' ' . $currency->sign : '') . '</div>
				<label>' . $this->l('Discount validity') . '</label>
				<div class="margin-form"><input type="text" name="PS_FOLLOW_UP_DAYS_3" value="' . $conf['PS_FOLLOW_UP_DAYS_3'] . '" size="6" /> ' . $this->l('day(s)') . '</div>
				<p>' . ($n3 > 1 ? sprintf($this->l('Next process will send: %d e-mails'), $n3) : sprintf($this->l('Next process will send: %d e-mail'), $n3)) . '</b></p>
				<hr size="1" />
				<p><b>4. ' . $this->l('Bad customers') . '</b><br /><br />' . $this->l('For each customer who has already passed at least one order and with no orders since a given duration, generate a discount and send it to the customer.') . '</p>
				<label>' . $this->l('Enable') . '</label>
				<div class="margin-form" style="padding-top: 5px;"><input type="checkbox" name="PS_FOLLOW_UP_ENABLE_4" value="1" style="vertical-align: middle;" ' . ($conf['PS_FOLLOW_UP_ENABLE_4'] == 1 ? 'checked="checked"' : '') . ' /></div>
				<label>' . $this->l('Discount amount') . '</label>
				<div class="margin-form"><input type="text" name="PS_FOLLOW_UP_AMOUNT_4" value="' . $conf['PS_FOLLOW_UP_AMOUNT_4'] . '" size="6" onKeyUp="javascript:this.value = this.value.replace(/,/g, \'.\');" /> %</div>
				<label>' . $this->l('Since x days') . '</label>
				<div class="margin-form"><input type="text" name="PS_FOLLOW_UP_DAYS_THRESHOLD_4" value="' . $conf['PS_FOLLOW_UP_DAYS_THRESHOLD_4'] . '" size="6" /> ' . $this->l('day(s)') . '</div>
				<label>' . $this->l('Discount validity') . '</label>
				<div class="margin-form"><input type="text" name="PS_FOLLOW_UP_DAYS_4" value="' . $conf['PS_FOLLOW_UP_DAYS_4'] . '" size="6" /> ' . $this->l('day(s)') . '</div>
				<p>' . ($n4 > 1 ? sprintf($this->l('Next process will send: %d e-mails'), $n4) : sprintf($this->l('Next process will send: %d e-mail'), $n4)) . '</b></p>
				<hr size="1" />
				<input type="checkbox" style="vertical-align: middle;" name="PS_FOLLOW_UP_CLEAN_DB" value="1" ' . ($conf['PS_FOLLOW_UP_CLEAN_DB'] == 1 ? 'checked="checked"' : '') . ' /> ' . $this->l('Delete outdated discounts during each launch to clean database.') . '
				<hr size="1" />
				<center><input type="submit" name="submitFollowUp" value="' . $this->l('Save') . '" class="button" /></center>
			</fieldset>
			
			<style type="text/css">
				table tr th {
					text-align: center;
					font-weight: bold;
				}
				
				table tr td, table tr th {
					padding: 3px;
				}
				
				table tr td {
					text-align: right;
				}
				
				table { width: 460px; border: 1px solid #666; }
			</style>
			<fieldset style="width: 460px; margin-left: 10px; float: left;">
				<legend><img src="' . $this->_path . 'logo-2.gif" alt="" title="" />' . $this->l('Statistics') . '</legend>
				' . $this->l('Detailed statistics for last 30 days:') . '<br /><br />
				<p style="font-size: 10px; font-weight: bold;">
				' . $this->l('S = Number of sent e-mails') . '<br />
				' . $this->l('U = Number of discounts used (valid orders only)') . '<br />
				' . $this->l('% = Conversion rate') . '
				</p><br />
				<table border="1" style="font-size: 11px;">
					<tr>
						<th rowspan="2" style="width: 75px;">' . $this->l('Date') . '</th>
						<th colspan="3">' . $this->l('Cancelled carts') . '</th>
						<th colspan="3">' . $this->l('Re-order') . '</th>
						<th colspan="3">' . $this->l('Best cust.') . '</th>
						<th colspan="3">' . $this->l('Bad cust.') . '</th>
					</tr>';
        $stats = Db::getInstance(_PS_USE_SQL_SLAVE_)->executeS('
			SELECT DATE_FORMAT(l.date_add, \'%Y-%m-%d\') date_stat, l.id_email_type, COUNT(l.id_log_email) nb, 
			(SELECT COUNT(l2.id_cart_rule) 
			FROM ' . _DB_PREFIX_ . 'log_email l2
			LEFT JOIN ' . _DB_PREFIX_ . 'order_cart_rule ocr ON (ocr.id_cart_rule = l2.id_cart_rule)
			LEFT JOIN ' . _DB_PREFIX_ . 'orders o ON (o.id_order = ocr.id_order)
			WHERE l2.id_email_type = l.id_email_type AND l2.date_add = l.date_add AND ocr.id_order IS NOT NULL AND o.valid = 1) nb_used
			FROM ' . _DB_PREFIX_ . 'log_email l
			WHERE l.date_add >= DATE_SUB(CURDATE(), INTERVAL 30 DAY)
			GROUP BY DATE_FORMAT(l.date_add, \'%Y-%m-%d\'), l.id_email_type');
        $statsArray = array();
        foreach ($stats as $stat) {
            $statsArray[$stat['date_stat']][$stat['id_email_type']]['nb'] = (int) $stat['nb'];
            $statsArray[$stat['date_stat']][$stat['id_email_type']]['nb_used'] = (int) $stat['nb_used'];
        }
        $html .= '
			<tr>
				<td class="center">' . $this->l('S') . '</td>
				<td class="center">' . $this->l('U') . '</td>
				<td class="center">%</td>
				<td class="center">' . $this->l('S') . '</td>
				<td class="center">' . $this->l('U') . '</td>
				<td class="center">%</td>
				<td class="center">' . $this->l('S') . '</td>
				<td class="center">' . $this->l('U') . '</td>
				<td class="center">%</td>
				<td class="center">' . $this->l('S') . '</td>
				<td class="center">' . $this->l('U') . '</td>
				<td class="center">%</td>
			</tr>';
        if (!sizeof($statsArray)) {
            $html .= '<tr><td colspan="13" style="font-weight: bold; text-align: center;">' . $this->l('No statistics at this time.') . '</td></tr>';
        }
        foreach ($statsArray as $date_stat => $array) {
            $rates = array();
            for ($i = 1; $i != 5; $i++) {
                if (isset($statsArray[$date_stat][$i]['nb']) and isset($statsArray[$date_stat][$i]['nb_used']) and $statsArray[$date_stat][$i]['nb_used'] > 0) {
                    $rates[$i] = number_format($statsArray[$date_stat][$i]['nb_used'] / $statsArray[$date_stat][$i]['nb'] * 100, 2, '.', '');
                }
            }
            $html .= '
				<tr>
					<td>' . $date_stat . '</td>';
            for ($i = 1; $i != 5; $i++) {
                $html .= '
					<td>' . (isset($statsArray[$date_stat][$i]['nb']) ? (int) $statsArray[$date_stat][$i]['nb'] : 0) . '</td>
					<td>' . (isset($statsArray[$date_stat][$i]['nb_used']) ? (int) $statsArray[$date_stat][$i]['nb_used'] : 0) . '</td>
					<td>' . (isset($rates[$i]) ? '<b>' . $rates[$i] . '</b>' : '0.00') . '</td>';
            }
            $html .= '
				</tr>';
        }
        $html .= '
				</table>
			</fieldset>
			<div class="clear"></div>
		</form>';
        return $html;
    }