public static function get_http($url, $headers = array())
 {
     static $_error2 = FALSE;
     PKHelper::DebugLogger('START: PKHelper::get_http(' . $url . ',' . print_r($headers, true) . ')');
     // class: Context is not loaded when using piwik.php proxy on prestashop 1.4
     if (class_exists('Context', FALSE)) {
         $lng = strtolower(isset(Context::getContext()->language->iso_code) ? Context::getContext()->language->iso_code : 'en');
     } else {
         $lng = 'en';
     }
     $timeout = 5;
     // should go in module conf
     if (self::$httpAuthUsername == "" || self::$httpAuthUsername === false) {
         self::$httpAuthUsername = Configuration::get(PKHelper::CPREFIX . 'PAUTHUSR');
     }
     if (self::$httpAuthPassword == "" || self::$httpAuthPassword === false) {
         self::$httpAuthPassword = Configuration::get(PKHelper::CPREFIX . 'PAUTHPWD');
     }
     $httpauth_usr = self::$httpAuthUsername;
     $httpauth_pwd = self::$httpAuthPassword;
     $use_cURL = (bool) Configuration::get(PKHelper::CPREFIX . 'USE_CURL');
     if ($use_cURL === FALSE) {
         PKHelper::DebugLogger('Using \'file_get_contents\' to fetch remote');
         $httpauth = "";
         if (!empty($httpauth_usr) && !is_null($httpauth_usr) && $httpauth_usr !== false && (!empty($httpauth_pwd) && !is_null($httpauth_pwd) && $httpauth_pwd !== false)) {
             $httpauth = "Authorization: Basic " . base64_encode("{$httpauth_usr}:{$httpauth_pwd}") . "\r\n";
         }
         $options = array('http' => array('user_agent' => isset($_SERVER['HTTP_USER_AGENT']) ? $_SERVER['HTTP_USER_AGENT'] : PKHelper::FAKEUSERAGENT, 'method' => "GET", 'timeout' => $timeout, 'header' => (!empty($headers) ? implode('', $headers) : "Accept-language: {$lng}\r\n") . $httpauth));
         $context = stream_context_create($options);
         PKHelper::DebugLogger('Calling: ' . $url . (!empty($httpauth) ? "\n\t- With Http auth" : ""));
         $result = @file_get_contents($url, false, $context);
         if ($result === FALSE) {
             $http_response = "";
             if (isset($http_response_header) && is_array($http_response_header)) {
                 foreach ($http_response_header as $value) {
                     if (preg_match("/^HTTP\\/.*/i", $value)) {
                         $http_response = ':' . $value;
                     }
                 }
             }
             PKHelper::DebugLogger('request returned ERROR: http response: ' . $http_response);
             if (isset($http_response_header)) {
                 PKHelper::DebugLogger('$http_response_header: ' . print_r($http_response_header, true));
             }
             if (!$_error2) {
                 self::$error = sprintf(self::l('Unable to connect to api%s'), " {$http_response}");
                 self::$errors[] = self::$error;
                 $_error2 = TRUE;
                 PKHelper::DebugLogger('Last error message: ' . self::$error);
             }
         } else {
             PKHelper::DebugLogger('request returned OK');
         }
         PKHelper::DebugLogger('END: PKHelper::get_http(): OK');
         return $result;
     } else {
         PKHelper::DebugLogger('Using \'cURL\' to fetch remote');
         try {
             $ch = curl_init();
             PKHelper::DebugLogger("\t: \$ch = curl_init()");
             curl_setopt($ch, CURLOPT_URL, $url);
             PKHelper::DebugLogger("\t: curl_setopt(\$ch, CURLOPT_URL, {$url})");
             !empty($headers) ? curl_setopt($ch, CURLOPT_HTTPHEADER, $headers) : curl_setopt($ch, CURLOPT_HTTPHEADER, array("Accept-language: {$lng}\r\n"));
             PKHelper::DebugLogger("\t: curl_setopt(\$ch, CURLOPT_HTTPHEADER, array(...))");
             curl_setopt($ch, CURLOPT_USERAGENT, isset($_SERVER['HTTP_USER_AGENT']) ? $_SERVER['HTTP_USER_AGENT'] : PKHelper::FAKEUSERAGENT);
             if (!empty($httpauth_usr) && !is_null($httpauth_usr) && $httpauth_usr !== false && (!empty($httpauth_pwd) && !is_null($httpauth_pwd) && $httpauth_pwd !== false)) {
                 curl_setopt($ch, CURLOPT_USERPWD, $httpauth_usr . ":" . $httpauth_pwd);
             }
             curl_setopt($ch, CURLOPT_TIMEOUT, $timeout);
             curl_setopt($ch, CURLOPT_HTTPGET, 1);
             // just to be safe
             curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE);
             curl_setopt($ch, CURLOPT_FAILONERROR, true);
             if (($return = curl_exec($ch)) === false) {
                 if (!$_error2) {
                     self::$error = curl_error($ch);
                     self::$errors[] = self::$error;
                     $_error2 = TRUE;
                 }
                 $return = false;
             }
             curl_close($ch);
             PKHelper::DebugLogger('END: PKHelper::get_http(): OK');
             return $return;
         } catch (Exception $ex) {
             self::$errors[] = $ex->getMessage();
             PKHelper::DebugLogger('Exception: ' . $ex->getMessage());
             PKHelper::DebugLogger('END: PKHelper::get_http(): ERROR');
             return false;
         }
     }
 }
 /**
  * get content to display in the admin area
  * @return string
  */
 public function getContent()
 {
     if (Tools::getIsset('pkapicall')) {
         $this->__pkapicall();
         die;
     }
     if (version_compare(_PS_VERSION_, '1.5.0.4', "<=")) {
         $this->context->controller->addJquery(_PS_JQUERY_VERSION_);
         $this->context->controller->addJs($this->_path . 'js/jquery.alerts.js');
         $this->context->controller->addCss($this->_path . 'js/jquery.alerts.css');
     }
     if (version_compare(_PS_VERSION_, '1.5.2.999', "<=")) {
         $this->context->controller->addJqueryPlugin('fancybox', _PS_JS_DIR_ . 'jquery/plugins/');
     }
     if (version_compare(_PS_VERSION_, '1.6', "<")) {
         $this->context->controller->addJqueryUI(array('ui.core', 'ui.widget'));
     }
     if (version_compare(_PS_VERSION_, '1.5', ">=")) {
         $this->context->controller->addJqueryPlugin('tagify', _PS_JS_DIR_ . 'jquery/plugins/');
     }
     // @todo process only returns a value on error so move them from $_html to $this->_errors
     $_html = "";
     $_html .= $this->processFormsUpdate();
     if (Tools::isSubmit('submitUpdateWizardForm' . $this->name)) {
         $_html .= $this->processWizardFormUpdate();
     }
     $this->piwikSite = false;
     if (!Tools::getIsset('pkwizard')) {
         /* do not try to connect when using wizard */
         if (Configuration::get(PKHelper::CPREFIX . 'TOKEN_AUTH') !== false) {
             $this->piwikSite = PKHelper::getPiwikSite();
         }
     }
     $this->displayErrors(PKHelper::$errors);
     PKHelper::$errors = PKHelper::$error = "";
     $this->__setCurrencies();
     //* warnings on module configure page
     if (!Tools::getIsset('pkwizard')) {
         /* do not show them if we are using the  wizard */
         if ($this->id && !Configuration::get(PKHelper::CPREFIX . 'TOKEN_AUTH') && !Tools::getIsset(PKHelper::CPREFIX . 'TOKEN_AUTH')) {
             /* avoid the same error message twice */
             $this->_errors[] = $this->displayError($this->l('Piwik auth token is empty'));
         }
         if ($this->id && (int) Configuration::get(PKHelper::CPREFIX . 'SITEID') <= 0 && !Tools::getIsset(PKHelper::CPREFIX . 'SITEID')) {
             /* avoid the same error message twice */
             $this->_errors[] = $this->displayError($this->l('Piwik site id is lower or equal to "0"'));
         }
         if ($this->id && !Configuration::get(PKHelper::CPREFIX . 'HOST')) {
             $this->_errors[] = $this->displayError($this->l('Piwik host cannot be empty'));
         }
     }
     $fields_form = array();
     $languages = Language::getLanguages(FALSE);
     foreach ($languages as $languages_key => $languages_value) {
         // is_default
         $languages[$languages_key]['is_default'] = $languages_value['id_lang'] == (int) Configuration::get('PS_LANG_DEFAULT') ? true : false;
     }
     $helper = new HelperForm();
     if (version_compare(_PS_VERSION_, '1.5.0.13', "<")) {
         $helper->base_folder = _PS_MODULE_DIR_ . 'piwikanalyticsjs/views/templates/helpers/form/';
     }
     $helper->languages = $languages;
     $helper->module = $this;
     $helper->name_controller = $this->name;
     $helper->identifier = $this->identifier;
     $helper->token = Tools::getAdminTokenLite('AdminModules');
     $helper->default_form_language = (int) Configuration::get('PS_LANG_DEFAULT');
     $helper->allow_employee_form_lang = (int) Configuration::get('PS_LANG_DEFAULT');
     $helper->show_toolbar = false;
     $helper->toolbar_scroll = false;
     $fields_form[0]['form']['legend'] = array('title' => $this->displayName, 'image' => $this->_path . 'logox22.png');
     if (Tools::getIsset('pkwizard')) {
         $helper->currentIndex = AdminController::$currentIndex . '&configure=' . $this->name . '&pkwizard';
         $step = 1;
         if (empty($this->_errors) && empty($_html)) {
             if (Tools::getIsset(PKHelper::CPREFIX . 'STEP_WIZARD')) {
                 $step = Tools::getValue(PKHelper::CPREFIX . 'STEP_WIZARD', 0);
                 $step++;
             }
         }
         $helper->title = $this->displayName . ' - ' . $this->l('Configuration Wizard');
         $helper->submit_action = 'submitUpdateWizardForm' . $this->name;
         $this->generateWizardForm($step, $fields_form, $helper);
         $this->context->smarty->assign(array('psversion' => _PS_VERSION_));
         if (is_array($this->_errors)) {
             $_html = implode('', $this->_errors) . $_html;
         } else {
             $_html = $this->_errors . $_html;
         }
         return $_html . $helper->generateForm($fields_form) . $this->display(__FILE__, 'views/templates/admin/jsfunctions.tpl') . $this->display(__FILE__, 'views/templates/admin/piwik_site_lookup.tpl');
     }
     $helper->currentIndex = AdminController::$currentIndex . '&configure=' . $this->name;
     $helper->title = $this->displayName;
     $helper->submit_action = 'submitUpdate' . $this->name;
     if ($this->piwikSite !== FALSE) {
         $fields_form[0]['form']['input'][] = array('type' => 'html', 'name' => "<div class=\"nav nav-pills pull-right\">" . "<i class=\"icon-wrench\" style=\"padding-right: 5px;\"></i>" . "<a href='?controller=AdminModules&token=" . Tools::getAdminTokenLite('AdminModules') . "&configure=piwikanalyticsjs&tab_module=analytics_stats&module_name=piwikanalyticsjs&pkwizard' title='{$this->l('Click here to open piwik site lookup wizard')}' data-html='true' data-toggle='tooltip' data-original-title='{$this->l('Click here to open piwik site lookup wizard')}' class='label-tooltip'>{$this->l('Configuration Wizard')}</a>" . "</div>" . $this->l('Based on the settings you provided this is the info i get from Piwik!') . "<br>" . "<strong>" . $this->l('Name') . "</strong>: <i>{$this->piwikSite[0]->name}</i><br>" . "<strong>" . $this->l('Main Url') . "</strong>: <i>{$this->piwikSite[0]->main_url}</i><br>");
     } else {
         $fields_form[0]['form']['input'][] = array('type' => 'html', 'name' => "<div class=\"nav nav-pills pull-right\">" . "<i class=\"icon-wrench\" style=\"padding-right: 5px;\"></i>" . "<a href='?controller=AdminModules&token=" . Tools::getAdminTokenLite('AdminModules') . "&configure=piwikanalyticsjs&tab_module=analytics_stats&module_name=piwikanalyticsjs&pkwizard' title='{$this->l('Click here to open piwik site lookup wizard')}' data-html='true' data-toggle='tooltip' data-original-title='{$this->l('Click here to open piwik site lookup wizard')}' class='label-tooltip'>{$this->l('Configuration Wizard')}</a>" . "</div>");
     }
     $fields_form[0]['form']['input'][] = array('type' => 'text', 'label' => $this->l('Piwik Host'), 'name' => PKHelper::CPREFIX . 'HOST', 'desc' => $this->l('Example: www.example.com/piwik/ (without protocol and with / at the end!)'), 'hint' => $this->l('The host where piwik is installed.!'), 'required' => true);
     $fields_form[0]['form']['input'][] = array('type' => 'switch', 'is_bool' => true, 'label' => $this->l('Use proxy script'), 'name' => PKHelper::CPREFIX . 'USE_PROXY', 'desc' => $this->l('Whether or not to use the proxy insted of Piwik Host'), 'values' => array(array('id' => 'active_on', 'value' => 1, 'label' => $this->l('Enabled')), array('id' => 'active_off', 'value' => 0, 'label' => $this->l('Disabled'))));
     $fields_form[0]['form']['input'][] = array('type' => 'text', 'label' => $this->l('Proxy script'), 'name' => PKHelper::CPREFIX . 'PROXY_SCRIPT', 'hint' => $this->l('Example: www.example.com/pkproxy.php'), 'desc' => sprintf($this->l('the FULL path to proxy script to use, build-in: [%s]'), self::getModuleLink($this->name, 'piwik')), 'required' => false);
     if (function_exists('curl_version')) {
         $fields_form[0]['form']['input'][] = array('type' => 'switch', 'is_bool' => true, 'label' => $this->l('Use cURL'), 'name' => PKHelper::CPREFIX . 'USE_CURL', 'desc' => $this->l('Whether or not to use cURL in Piwik API and proxy requests?'), 'values' => array(array('id' => 'active_on', 'value' => 1, 'label' => $this->l('Enabled')), array('id' => 'active_off', 'value' => 0, 'label' => $this->l('Disabled'))));
     }
     $fields_form[0]['form']['input'][] = array('type' => 'text', 'label' => $this->l('Piwik site id'), 'name' => PKHelper::CPREFIX . 'SITEID', 'desc' => $this->l('Example: 10'), 'hint' => $this->l('You can find piwik site id by loggin to piwik installation.'), 'required' => true);
     $fields_form[0]['form']['input'][] = array('type' => 'text', 'label' => $this->l('Piwik token auth'), 'name' => PKHelper::CPREFIX . 'TOKEN_AUTH', 'desc' => $this->l('You can find piwik token by loggin to piwik installation. under API'), 'required' => true);
     $fields_form[0]['form']['input'][] = array('type' => 'text', 'label' => $this->l('Track visitors across subdomains'), 'name' => PKHelper::CPREFIX . 'COOKIE_DOMAIN', 'desc' => $this->l('The default is the document domain; if your web site can be visited at both www.example.com and example.com, you would use: "*.example.com" OR ".example.com" without the quotes') . '<br />' . $this->l('Leave empty to exclude this from the tracking code'), 'hint' => $this->l('So if one visitor visits x.example.com and y.example.com, they will be counted as a unique visitor. (setCookieDomain)'), 'required' => false);
     $fields_form[0]['form']['input'][] = array('type' => version_compare(_PS_VERSION_, '1.5', '>=') ? 'tags' : 'text', 'label' => $this->l('Hide known alias URLs'), 'name' => PKHelper::CPREFIX . 'SET_DOMAINS', 'desc' => $this->l('In the "Outlinks" report, hide clicks to known alias URLs, Example: *.example.com') . '<br />' . $this->l('Note: to add multiple domains you must separate them with comma ","') . '<br />' . $this->l('Note: the currently tracked website is added to this array automatically') . '<br />' . $this->l('Leave empty to exclude this from the tracking code'), 'hint' => $this->l('So clicks on links to Alias URLs (eg. x.example.com) will not be counted as "Outlink". (setDomains)'), 'required' => false);
     $fields_form[0]['form']['input'][] = array('type' => 'switch', 'is_bool' => true, 'label' => $this->l('Enable client side DoNotTrack detection'), 'name' => PKHelper::CPREFIX . 'DNT', 'desc' => $this->l('So tracking requests will not be sent if visitors do not wish to be tracked.'), 'values' => array(array('id' => 'active_on', 'value' => 1, 'label' => $this->l('Enabled')), array('id' => 'active_off', 'value' => 0, 'label' => $this->l('Disabled'))));
     if (Configuration::get(PKHelper::CPREFIX . 'TOKEN_AUTH') !== false) {
         $image_tracking = PKHelper::getPiwikImageTrackingCode();
     } else {
         $image_tracking = array('default' => $this->l('I need Site ID and Auth Token before i can get your image tracking code'), 'proxy' => $this->l('I need Site ID and Auth Token before i can get your image tracking code'));
     }
     $this->displayErrors(PKHelper::$errors);
     PKHelper::$errors = PKHelper::$error = "";
     $fields_form[0]['form']['input'][] = array('type' => 'html', 'name' => $this->l('Piwik image tracking code append one of them to field "Extra HTML" this will add images tracking code to all your pages') . "<br>" . "<strong>" . $this->l('default') . "</strong>:<br /><i>{$image_tracking['default']}</i><br>" . "<strong>" . $this->l('using proxy script') . "</strong>:<br /><i>{$image_tracking['proxy']}</i><br>" . (version_compare(_PS_VERSION_, '1.6.0.7', '>=') ? "<br><strong>{$this->l("Before you add the image tracking code make sure the HTMLPurifier library isn't in use, check the settings in 'Preferences => General', you can enable the HTMLPurifier again after you made your changes")}</strong>" : ""));
     $fields_form[0]['form']['input'][] = array('type' => 'textarea', 'label' => $this->l('Extra HTML'), 'name' => PKHelper::CPREFIX . 'EXHTML', 'desc' => $this->l('Some extra HTML code to put after the piwik tracking code, this can be any html of your choice'), 'rows' => 10, 'cols' => 50);
     $fields_form[0]['form']['input'][] = array('type' => 'select', 'label' => $this->l('Piwik Currency'), 'name' => PKHelper::CPREFIX . 'DEFAULT_CURRENCY', 'desc' => sprintf($this->l('Based on your settings in Piwik your default currency is %s'), $this->piwikSite !== FALSE ? $this->piwikSite[0]->currency : $this->l('unknown')), 'options' => array('default' => $this->default_currency, 'query' => $this->currencies, 'id' => 'iso_code', 'name' => 'name'));
     $fields_form[0]['form']['input'][] = array('type' => 'select', 'label' => $this->l('Piwik Report date'), 'name' => PKHelper::CPREFIX . 'DREPDATE', 'desc' => $this->l('Report date to load by default from "Stats => Piwik Analytics"'), 'options' => array('default' => array('value' => 'day|today', 'label' => $this->l('Today')), 'query' => array(array('str' => 'day|today', 'name' => $this->l('Today')), array('str' => 'day|yesterday', 'name' => $this->l('Yesterday')), array('str' => 'range|previous7', 'name' => $this->l('Previous 7 days (not including today)')), array('str' => 'range|previous30', 'name' => $this->l('Previous 30 days (not including today)')), array('str' => 'range|last7', 'name' => $this->l('Last 7 days (including today)')), array('str' => 'range|last30', 'name' => $this->l('Last 30 days (including today)')), array('str' => 'week|today', 'name' => $this->l('Current Week')), array('str' => 'month|today', 'name' => $this->l('Current Month')), array('str' => 'year|today', 'name' => $this->l('Current Year'))), 'id' => 'str', 'name' => 'name'));
     $fields_form[0]['form']['input'][] = array('type' => 'text', 'label' => $this->l('Piwik User name'), 'name' => PKHelper::CPREFIX . 'USRNAME', 'desc' => $this->l('You can store your Username for Piwik here to make it easy to open piwik interface from your stats page with automatic login'), 'required' => false, 'autocomplete' => false);
     $fields_form[0]['form']['input'][] = array('type' => 'password', 'label' => $this->l('Piwik User password'), 'name' => PKHelper::CPREFIX . 'USRPASSWD', 'desc' => $this->l('You can store your Password for Piwik here to make it easy to open piwik interface from your stats page with automatic login'), 'required' => false, 'autocomplete' => false);
     $fields_form[0]['form']['submit'] = array('title' => $this->l('Save'), 'class' => 'btn btn-default');
     $fields_form[1]['form'] = array('legend' => array('title' => $this->displayName . ' ' . $this->l('Advanced'), 'image' => $this->_path . 'logox22.png'), 'input' => array(array('type' => 'html', 'name' => $this->l('In this section you can modify certain aspects of the way this plugin sends products, searches, category view etc.. to piwik')), array('type' => 'switch', 'is_bool' => true, 'label' => $this->l('Use HTTPS'), 'name' => PKHelper::CPREFIX . 'CRHTTPS', 'hint' => $this->l('ONLY enable this feature if piwik installation is accessible via https'), 'desc' => $this->l('use Hypertext Transfer Protocol Secure (HTTPS) in all requests from code to piwik, this only affects how requests are sent from proxy script to piwik, your visitors will still use the protocol they visit your shop with'), 'values' => array(array('id' => 'active_on', 'value' => 1, 'label' => $this->l('Enabled')), array('id' => 'active_off', 'value' => 0, 'label' => $this->l('Disabled')))), array('type' => 'html', 'name' => $this->l('in the next few inputs you can set how the product id is passed on to piwik') . '<br />' . $this->l('there are three variables you can use:') . '<br />' . $this->l('{ID} : this variable is replaced with id the product has in prestashop') . '<br />' . $this->l('{REFERENCE} : this variable is replaced with the unique reference you when adding adding/updating a product, this variable is only available in prestashop 1.5 and up') . '<br />' . $this->l('{ATTRID} : this variable is replaced with id the product attribute') . '<br />' . $this->l('in cases where only the product id is available it be parsed as ID and nothing else')), array('type' => 'text', 'label' => $this->l('Product id V1'), 'name' => PKHelper::CPREFIX . 'PRODID_V1', 'desc' => $this->l('This template is used in case ALL three values are available ("Product ID", "Product Attribute ID" and "Product Reference")'), 'required' => false), array('type' => 'text', 'label' => $this->l('Product id V2'), 'name' => PKHelper::CPREFIX . 'PRODID_V2', 'desc' => $this->l('This template is used in case only "Product ID" and "Product Reference" are available'), 'required' => false), array('type' => 'text', 'label' => $this->l('Product id V3'), 'name' => PKHelper::CPREFIX . 'PRODID_V3', 'desc' => $this->l('This template is used in case only "Product ID" and "Product Attribute ID" are available'), 'required' => false), array('type' => 'html', 'name' => "<strong>{$this->l('Piwik Cookies')}</strong>"), array('type' => 'text', 'label' => $this->l('Piwik Session Cookie timeout'), 'name' => PKHelper::CPREFIX . 'SESSION_TIMEOUT', 'required' => false, 'hint' => $this->l('this value must be set in minutes'), 'desc' => $this->l('Piwik Session Cookie timeout, the default is 30 minutes')), array('type' => 'text', 'label' => $this->l('Piwik Visitor Cookie timeout'), 'name' => PKHelper::CPREFIX . 'COOKIE_TIMEOUT', 'required' => false, 'hint' => $this->l('this value must be set in minutes'), 'desc' => $this->l('Piwik Visitor Cookie timeout, the default is 13 months (569777 minutes)')), array('type' => 'text', 'label' => $this->l('Piwik Referral Cookie timeout'), 'name' => PKHelper::CPREFIX . 'RCOOKIE_TIMEOUT', 'required' => false, 'hint' => $this->l('this value must be set in minutes'), 'desc' => $this->l('Piwik Referral Cookie timeout, the default is 6 months (262974 minutes)')), array('type' => 'html', 'name' => "<strong>{$this->l('Piwik Proxy Script Authorization? if piwik is installed behind HTTP Basic Authorization (Both password and username must be filled before the values will be used)')}</strong>"), array('type' => 'text', 'label' => $this->l('Proxy Script Username'), 'name' => PKHelper::CPREFIX . 'PAUTHUSR', 'required' => false, 'autocomplete' => false, 'desc' => $this->l('this field along with password can be used if piwik installation is protected by HTTP Basic Authorization')), array('type' => 'password', 'label' => $this->l('Proxy Script Password'), 'name' => PKHelper::CPREFIX . 'PAUTHPWD', 'required' => false, 'autocomplete' => false, 'desc' => $this->l('this field along with username can be used if piwik installation is protected by HTTP Basic Authorization'))), 'submit' => array('title' => $this->l('Save'), 'class' => 'btn btn-default'));
     if ($this->piwikSite !== FALSE) {
         $tmp = PKHelper::getMyPiwikSites(TRUE);
         $this->displayErrors(PKHelper::$errors);
         PKHelper::$errors = PKHelper::$error = "";
         $pksite_default = array('value' => 0, 'label' => $this->l('Choose Piwik site'));
         $pksites = array();
         foreach ($tmp as $pksid) {
             $pksites[] = array('pkid' => $pksid->idsite, 'name' => "{$pksid->name} #{$pksid->idsite}");
         }
         unset($tmp, $pksid);
         $pktimezone_default = array('value' => 0, 'label' => $this->l('Choose Timezone'));
         $pktimezones = array();
         $tmp = PKHelper::getTimezonesList();
         $this->displayErrors(PKHelper::$errors);
         PKHelper::$errors = PKHelper::$error = "";
         foreach ($tmp as $key => $pktz) {
             if (!isset($pktimezones[$key])) {
                 $pktimezones[$key] = array('name' => $this->l($key), 'query' => array());
             }
             foreach ($pktz as $pktzK => $pktzV) {
                 $pktimezones[$key]['query'][] = array('tzId' => $pktzK, 'tzName' => $pktzV);
             }
         }
         unset($tmp, $pktz, $pktzV, $pktzK);
         $fields_form[2]['form'] = array('legend' => array('title' => $this->displayName . ' ' . $this->l('Advanced') . ' - ' . $this->l('Edit Piwik site'), 'image' => $this->_path . 'logox22.png'), 'input' => array(array('type' => 'select', 'label' => $this->l('Piwik Site'), 'name' => 'SPKSID', 'desc' => sprintf($this->l('Based on your settings in Piwik your default site is %s'), $this->piwikSite[0]->idsite), 'options' => array('default' => $pksite_default, 'query' => $pksites, 'id' => 'pkid', 'name' => 'name'), 'onchange' => 'return ChangePKSiteEdit(this.value)'), array('type' => 'html', 'name' => $this->l('In this section you can modify your settings in piwik just so you don\'t have to login to Piwik to do this') . "<br>" . "<strong>" . $this->l('Currently selected name') . "</strong>: <i id='wnamedsting'>{$this->piwikSite[0]->name}</i><br>" . "<input type=\"hidden\" name=\"PKAdminIdSite\" id=\"PKAdminIdSite\" value=\"{$this->piwikSite[0]->idsite}\" />"), array('type' => 'text', 'label' => $this->l('Piwik Site Name'), 'name' => 'PKAdminSiteName', 'desc' => $this->l('Name of this site in Piwik')), array('type' => 'switch', 'is_bool' => true, 'label' => $this->l('Ecommerce'), 'name' => 'PKAdminEcommerce', 'desc' => $this->l('Is this site an ecommerce site?'), 'values' => array(array('id' => 'active_on', 'value' => 1, 'label' => $this->l('Yes')), array('id' => 'active_off', 'value' => 0, 'label' => $this->l('No')))), array('type' => 'switch', 'is_bool' => true, 'label' => $this->l('Site Search'), 'name' => 'PKAdminSiteSearch', 'values' => array(array('id' => 'active_on', 'value' => 1, 'label' => $this->l('Yes')), array('id' => 'active_off', 'value' => 0, 'label' => $this->l('No')))), array('type' => version_compare(_PS_VERSION_, '1.5', '>=') ? 'tags' : 'text', 'label' => $this->l('Search Keyword Parameters'), 'name' => 'PKAdminSearchKeywordParameters', 'desc' => $this->l('the following keyword parameters must be excluded to avoid normal page views to be interpreted as searches (the tracking code will see them and make the required postback to Piwik if it is a real search), if you are only using PrestaShop with this site setting this to empty, will be sufficient') . "<br><br><strong>tag</strong> and <strong>search_query</strong>"), array('type' => version_compare(_PS_VERSION_, '1.5', '>=') ? 'tags' : 'text', 'label' => $this->l('Search Category Parameters'), 'name' => 'PKAdminSearchCategoryParameters'), array('type' => version_compare(_PS_VERSION_, '1.5', '>=') ? 'tags' : 'text', 'label' => $this->l('Excluded ip addresses'), 'name' => 'PKAdminExcludedIps', 'desc' => $this->l('ip addresses excluded from tracking, separated by comma ","')), array('type' => version_compare(_PS_VERSION_, '1.5', '>=') ? 'tags' : 'text', 'label' => $this->l('Excluded Query Parameters'), 'name' => 'PKAdminExcludedQueryParameters', 'desc' => $this->l('please read: http://piwik.org/faq/how-to/faq_81/')), array('type' => 'select', 'label' => $this->l('Timezone'), 'name' => 'PKAdminTimezone', 'desc' => sprintf($this->l('Based on your settings in Piwik your default timezone is %s'), $this->piwikSite[0]->timezone), 'options' => array('default' => $pktimezone_default, 'optiongroup' => array('label' => 'name', 'query' => $pktimezones), 'options' => array('id' => 'tzId', 'name' => 'tzName', 'query' => 'query'))), array('type' => 'select', 'label' => $this->l('Currency'), 'name' => 'PKAdminCurrency', 'desc' => sprintf($this->l('Based on your settings in Piwik your default currency is %s'), $this->piwikSite[0]->currency), 'options' => array('default' => $this->default_currency, 'query' => $this->currencies, 'id' => 'iso_code', 'name' => 'name')), array('type' => 'textarea', 'label' => $this->l('Excluded User Agents'), 'name' => 'PKAdminExcludedUserAgents', 'rows' => 10, 'cols' => 50, 'desc' => $this->l('please read: http://piwik.org/faq/how-to/faq_17483/')), array('type' => 'switch', 'is_bool' => true, 'label' => $this->l('Keep URL Fragments'), 'name' => 'PKAdminKeepURLFragments', 'values' => array(array('id' => 'active_on', 'value' => 1, 'label' => $this->l('Yes')), array('id' => 'active_off', 'value' => 0, 'label' => $this->l('No')))), array('type' => 'html', 'name' => "\n<button onclick=\"return submitPiwikSiteAPIUpdate()\" \n        id=\"submitUpdatePiwikAdmSite\" class=\"btn btn-default pull-left\" \n        name=\"submitUpdatePiwikAdmSite\" value=\"1\" type=\"button\">\n    <i class=\"process-icon-save\"></i>{$this->l('Save')}</button>")));
     }
     $helper->fields_value = $this->getFormFields();
     $this->context->smarty->assign(array('psversion' => _PS_VERSION_, 'psm_currentIndex' => $helper->currentIndex, 'psm_token' => $helper->token));
     if (is_array($this->_errors)) {
         $_html = implode('', $this->_errors) . $_html;
     } else {
         $_html = $this->_errors . $_html;
     }
     return $_html . $helper->generateForm($fields_form) . $this->display(__FILE__, 'views/templates/admin/jsfunctions.tpl') . $this->display(__FILE__, 'views/templates/admin/piwik_site_manager.tpl');
 }