public function getTotalGuests()
    {
        return Db::getInstance(_PS_USE_SQL_SLAVE_)->getValue('
		SELECT COUNT(DISTINCT c.`id_guest`)
		FROM `' . _DB_PREFIX_ . 'connections` c
		WHERE c.`date_add` BETWEEN ' . ModuleGraph::getDateBetween());
    }
Exemple #2
0
    function hookAdminStatsModules()
    {
        $result = Db::getInstance()->ExecuteS($this->_query . ModuleGraph::getDateBetween() . $this->_query2);
        $this->_html = '<fieldset class="width3"><legend><img src="../modules/' . $this->name . '/logo.gif" /> ' . $this->displayName . '</legend>';
        if ($result and sizeof($result)) {
            $table = '<div style="overflow-y: scroll; height: 600px;">
			<table class="table" border="0" cellspacing="0" cellspacing="0">
			<thead>
				<tr><th style="width:400px;">' . $this->l('Keywords') . '</th>
				<th style="width:50px; text-align: right">' . $this->l('Occurences') . '</th></tr>
			</thead><tbody>';
            foreach ($result as $index => $row) {
                $keyword =& $row['keyword'];
                $occurences =& $row['occurences'];
                $table .= '<tr><td>' . $keyword . '</td><td style="text-align: right">' . $occurences . '</td></tr>';
            }
            $table .= '</tbody></table></div>';
            $this->_html .= '<center>' . ModuleGraph::engine(array('type' => 'pie')) . '</center><br class="clear" />' . $table;
        } else {
            $this->_html .= '<p><strong>' . $this->l('No keyword searched for more than once found') . '</strong></p>';
        }
        $this->_html .= '</fieldset><br class="clear" />
		<fieldset class="width3"><legend><img src="../img/admin/comment.gif" /> ' . $this->l('Guide') . '</legend>
			<h2>' . $this->l('Identify external search engines keywords') . '</h2>
			<p>' . $this->l('There are many ways to find a website, but one of the most common is to find it with a search engine. Identifying the most "visitor-making" keywords entered by your new visitors is really important, it allows you to see which product you have to put in front if you want more visitors and customers.') . '</p><br />
			<h3>' . $this->l('How does it work?') . '</h2>
			<p>' . $this->l('When a visitors comes to your website, the server knows its previous location. This module parses this URL and finds the keywords in it. Currently, it manages the following search engines:') . '<b> Google, AOL, Yandex, Ask, NHL, Yahoo, Baidu, Lycos, Exalead, Live, Voila</b> ' . $this->l('and') . ' <b>Altavista</b>. ' . $this->l('Soon it will be possible to add dynamically new search engine and to contribute to this module!') . '</p><br />
		</fieldset>';
        return $this->_html;
    }
    function hookAdminStatsModules()
    {
        if (Tools::getValue('export')) {
            $this->csvExport(array('type' => 'pie'));
        }
        $result = Db::getInstance(_PS_USE_SQL_SLAVE_)->ExecuteS($this->_query . ModuleGraph::getDateBetween() . $this->_query2);
        $this->_html = '
		<fieldset class="width3"><legend><img src="../modules/' . $this->name . '/logo.gif" /> ' . $this->displayName . '</legend>';
        $table = '<div style="overflow-y: scroll; height: 600px;">
		<table class="table" border="0" cellspacing="0" cellspacing="0">
		<thead>
			<tr>
				<th style="width:400px;">' . $this->l('Keywords') . '</th>
				<th style="width:50px; text-align: right">' . $this->l('Occurrences') . '</th>
				<th style="width:50px; text-align: right">' . $this->l('Results') . '</th>
			</tr>
		</thead><tbody>';
        foreach ($result as $row) {
            $table .= '<tr>
				<td>' . $row['keywords'] . '</td>
				<td style="text-align: right">' . $row['occurences'] . '</td>
				<td style="text-align: right">' . $row['total'] . '</td>
			</tr>';
        }
        $table .= '</tbody></table></div>';
        if (sizeof($result)) {
            $this->_html .= '<center>' . ModuleGraph::engine(array('type' => 'pie')) . '</center>
									<p><a href="' . $_SERVER['REQUEST_URI'] . '&export=1"><img src="../img/admin/asterisk.gif" />' . $this->l('CSV Export') . '</a></p>
									<br class="clear" />' . $table;
        } else {
            $this->_html .= '<p><strong>' . $this->l('No keywords searched more than once found.') . '</strong></p>';
        }
        $this->_html .= '</fieldset>';
        return $this->_html;
    }
Exemple #4
0
    /**
     * @return array Get list of browser "plugins" (javascript, media player, etc.)
     */
    private function getEquipment()
    {
        $sql = 'SELECT DISTINCT g.*
				FROM `' . _DB_PREFIX_ . 'connections` c 
				LEFT JOIN `' . _DB_PREFIX_ . 'guest` g ON g.`id_guest` = c.`id_guest`
				WHERE c.`date_add` BETWEEN ' . ModuleGraph::getDateBetween() . '
					' . Shop::addSqlRestriction(false, 'c');
        $result = Db::getInstance(_PS_USE_SQL_SLAVE_)->query($sql);
        $calcArray = array('jsOK' => 0, 'jsKO' => 0, 'javaOK' => 0, 'javaKO' => 0, 'wmpOK' => 0, 'wmpKO' => 0, 'qtOK' => 0, 'qtKO' => 0, 'realOK' => 0, 'realKO' => 0, 'flashOK' => 0, 'flashKO' => 0, 'directorOK' => 0, 'directorKO' => 0);
        while ($row = Db::getInstance(_PS_USE_SQL_SLAVE_)->nextRow($result)) {
            if (!$row['javascript']) {
                ++$calcArray['jsKO'];
                continue;
            }
            ++$calcArray['jsOK'];
            $row['windows_media'] ? ++$calcArray['wmpOK'] : ++$calcArray['wmpKO'];
            $row['real_player'] ? ++$calcArray['realOK'] : ++$calcArray['realKO'];
            $row['adobe_flash'] ? ++$calcArray['flashOK'] : ++$calcArray['flashKO'];
            $row['adobe_director'] ? ++$calcArray['directorOK'] : ++$calcArray['directorKO'];
            $row['sun_java'] ? ++$calcArray['javaOK'] : ++$calcArray['javaKO'];
            $row['apple_quicktime'] ? ++$calcArray['qtOK'] : ++$calcArray['qtKO'];
        }
        if (!$calcArray['jsOK']) {
            return false;
        }
        $equip = array('Windows Media Player' => $calcArray['wmpOK'] / ($calcArray['wmpOK'] + $calcArray['wmpKO']), 'Real Player' => $calcArray['realOK'] / ($calcArray['realOK'] + $calcArray['realKO']), 'Apple Quicktime' => $calcArray['qtOK'] / ($calcArray['qtOK'] + $calcArray['qtKO']), 'Sun Java' => $calcArray['javaOK'] / ($calcArray['javaOK'] + $calcArray['javaKO']), 'Adobe Flash' => $calcArray['flashOK'] / ($calcArray['flashOK'] + $calcArray['flashKO']), 'Adobe Shockwave' => $calcArray['directorOK'] / ($calcArray['directorOK'] + $calcArray['directorKO']));
        arsort($equip);
        return $equip;
    }
Exemple #5
0
    private function getEquipment()
    {
        $result = mysql_query('
		SELECT DISTINCT g.*
		FROM `' . _DB_PREFIX_ . 'connections` c 
		LEFT JOIN `' . _DB_PREFIX_ . 'guest` g ON g.`id_guest` = c.`id_guest`
		WHERE c.`date_add` BETWEEN ' . ModuleGraph::getDateBetween());
        $calcArray = array('jsOK' => 0, 'jsKO' => 0, 'javaOK' => 0, 'javaKO' => 0, 'wmpOK' => 0, 'wmpKO' => 0, 'qtOK' => 0, 'qtKO' => 0, 'realOK' => 0, 'realKO' => 0, 'flashOK' => 0, 'flashKO' => 0, 'directorOK' => 0, 'directorKO' => 0);
        while ($row = mysql_fetch_assoc($result)) {
            if (!$row['javascript']) {
                ++$calcArray['jsKO'];
                continue;
            }
            ++$calcArray['jsOK'];
            $row['windows_media'] ? ++$calcArray['wmpOK'] : ++$calcArray['wmpKO'];
            $row['real_player'] ? ++$calcArray['realOK'] : ++$calcArray['realKO'];
            $row['adobe_flash'] ? ++$calcArray['flashOK'] : ++$calcArray['flashKO'];
            $row['adobe_director'] ? ++$calcArray['directorOK'] : ++$calcArray['directorKO'];
            $row['sun_java'] ? ++$calcArray['javaOK'] : ++$calcArray['javaKO'];
            $row['apple_quicktime'] ? ++$calcArray['qtOK'] : ++$calcArray['qtKO'];
        }
        mysql_free_result($result);
        if (!$calcArray['jsOK']) {
            return false;
        }
        $equip = array('Windows Media Player' => $calcArray['wmpOK'] / ($calcArray['wmpOK'] + $calcArray['wmpKO']), 'Real Player' => $calcArray['realOK'] / ($calcArray['realOK'] + $calcArray['realKO']), 'Apple Quicktime' => $calcArray['qtOK'] / ($calcArray['qtOK'] + $calcArray['qtKO']), 'Sun Java' => $calcArray['javaOK'] / ($calcArray['javaOK'] + $calcArray['javaKO']), 'Adobe Flash' => $calcArray['flashOK'] / ($calcArray['flashOK'] + $calcArray['flashKO']), 'Adobe Shockwave' => $calcArray['directorOK'] / ($calcArray['directorOK'] + $calcArray['directorKO']));
        arsort($equip);
        return $equip;
    }
    public function getTotalGuests()
    {
        $sql = 'SELECT COUNT(DISTINCT c.`id_guest`)
				FROM `' . _DB_PREFIX_ . 'connections` c
				WHERE c.`date_add` BETWEEN ' . ModuleGraph::getDateBetween() . '
					' . Shop::addSqlRestriction(false, 'c');
        return Db::getInstance(_PS_USE_SQL_SLAVE_)->getValue($sql);
    }
    public function getFirstBuyers()
    {
        $result = Db::getInstance(_PS_USE_SQL_SLAVE_)->getRow('
		SELECT COUNT(DISTINCT o.`id_customer`) as buyers
		FROM `' . _DB_PREFIX_ . 'orders` o
		LEFT JOIN `' . _DB_PREFIX_ . 'guest` g ON o.id_customer = g.id_customer
		LEFT JOIN `' . _DB_PREFIX_ . 'connections` c ON c.id_guest = g.id_guest
		WHERE o.`date_add` BETWEEN ' . ModuleGraph::getDateBetween() . ' AND o.valid = 1
		AND ABS(TIMEDIFF(o.date_add, c.date_add)+0) < 120000');
        return $result['buyers'];
    }
    private function getTotals()
    {
        $result1 = Db::getInstance(_PS_USE_SQL_SLAVE_)->getRow('
		SELECT COUNT(*) as customers
		FROM `' . _DB_PREFIX_ . 'customer` c
		WHERE c.`newsletter_date_add` BETWEEN ' . ModuleGraph::getDateBetween());
        $result2 = Db::getInstance(_PS_USE_SQL_SLAVE_)->getRow('
		SELECT COUNT(*) as visitors
		FROM ' . _DB_PREFIX_ . 'newsletter n
		WHERE n.`newsletter_date_add` BETWEEN ' . ModuleGraph::getDateBetween());
        return array('customers' => $result1['customers'], 'visitors' => $result2['visitors'], 'both' => $result1['customers'] + $result2['visitors']);
    }
    public function getTotalViewed($id_product)
    {
        $dateBetween = ModuleGraph::getDateBetween();
        $result = Db::getInstance(_PS_USE_SQL_SLAVE_)->getRow('
		SELECT SUM(pv.`counter`) AS total
		FROM `' . _DB_PREFIX_ . 'page_viewed` pv
		LEFT JOIN `' . _DB_PREFIX_ . 'date_range` dr ON pv.`id_date_range` = dr.`id_date_range`
		LEFT JOIN `' . _DB_PREFIX_ . 'page` p ON pv.`id_page` = p.`id_page`
		LEFT JOIN `' . _DB_PREFIX_ . 'page_type` pt ON pt.`id_page_type` = p.`id_page_type`
		WHERE pt.`name` = \'product.php\'
		AND p.`id_object` = ' . (int) $id_product . '
		AND dr.`time_start` BETWEEN ' . $dateBetween . '
		AND dr.`time_end` BETWEEN ' . $dateBetween . '');
        return isset($result['total']) ? $result['total'] : 0;
    }
    private function getTotals()
    {
        $sql = 'SELECT COUNT(*) as customers
				FROM `' . _DB_PREFIX_ . 'customer`
				WHERE 1
					' . Shop::addSqlRestriction(Shop::SHARE_CUSTOMER) . '
					AND `newsletter_date_add` BETWEEN ' . ModuleGraph::getDateBetween();
        $result1 = Db::getInstance(_PS_USE_SQL_SLAVE_)->getRow($sql);
        $sql = 'SELECT COUNT(*) as visitors
				FROM ' . _DB_PREFIX_ . 'newsletter
				WHERE 1
				   ' . Shop::addSqlRestriction() . '
					AND `newsletter_date_add` BETWEEN ' . ModuleGraph::getDateBetween();
        $result2 = Db::getInstance(_PS_USE_SQL_SLAVE_)->getRow($sql);
        return array('customers' => $result1['customers'], 'visitors' => $result2['visitors'], 'both' => $result1['customers'] + $result2['visitors']);
    }
    public function hookAdminStatsModules()
    {
        $websites = $this->getOrigins(ModuleGraph::getDateBetween());
        if (Tools::getValue('export')) {
            if (Tools::getValue('exportType') == 'top') {
                $this->csvExport(array('type' => 'pie'));
            }
        }
        $this->_html = '<div class="blocStats"><h2 class="icon-' . $this->name . '"><span></span>' . $this->l('Origin') . '</h2>';
        if (count($websites)) {
            $this->_html .= '
			<p><img src="../img/admin/down.gif" />' . $this->l('Here we break down the 10 most popular referral websites that call customers to your e-store.') . '</p>
			<div>' . $this->engine(array('type' => 'pie')) . '</div><br />
			<p><a class="button export-csv" href="' . Tools::safeOutput($_SERVER['REQUEST_URI']) . '&export=1&exportType=top"><span>' . $this->l('CSV Export') . '</span></a></p><br />
			
			<table class="table " border="0" cellspacing="0" cellspacing="0">
				<tr>
					<th style="width:400px;">' . $this->l('Origin') . '</th>
					<th style="width:50px; text-align: right">' . $this->l('Total') . '</th>
				</tr>';
            foreach ($websites as $website => $total) {
                $this->_html .= '<tr>
					<td>' . (!strstr($website, ' ') ? '<a href="' . Tools::getProtocol() . $website . '">' : '') . $website . (!strstr($website, ' ') ? '</a>' : '') . '</td><td style="text-align: right">' . $total . '</td>
				</tr>';
            }
            $this->_html .= '</table></div>';
        } else {
            $this->_html .= '<p><strong>' . $this->l('Direct links only') . '</strong></p>';
        }
        $this->_html .= '</div><br />
		<div class="blocStats"><h2 class="icon-guide"><span></span>' . $this->l('Guide') . '</h2>
		<h2>' . $this->l('What is a referral website?') . '</h2>
			<p>
				' . $this->l('When visiting a webpage, the referrer is the URL of the previous webpage from which a link was followed.') . '<br />
				' . $this->l('A referrer enables you to know which keywords visitors use in search engines when browsing for your online store.') . '<br /><br />
				' . $this->l('A referrer can be:') . '
				<ul>
					<li class="bullet">' . $this->l('Someone who posts a link to your shop.') . '</li>
					<li class="bullet">' . $this->l('A partner who has agreed to a link exchange in order to attract new customers.') . '</li>
				</ul>
			</p>
		</div>';
        return $this->_html;
    }
    function hookAdminStatsModules()
    {
        $websites = $this->getOrigins(ModuleGraph::getDateBetween());
        if (Tools::getValue('export')) {
            if (Tools::getValue('exportType') == 'top') {
                $this->csvExport(array('type' => 'pie'));
            }
        }
        $this->_html = '<fieldset class="width3"><legend><img src="../modules/' . $this->name . '/logo.gif" /> ' . $this->l('Origin') . '</legend>';
        if (sizeof($websites)) {
            $this->_html .= '
			<center><p><img src="../img/admin/down.gif" />' . $this->l('Here is the percentage of the 10 most popular referrer websites by which visitors went through to get to your shop.') . '</p>
			' . ModuleGraph::engine(array('type' => 'pie')) . '</center>
			<p><a href="' . Tools::safeOutput($_SERVER['REQUEST_URI']) . '&export=1&exportType=top"><img src="../img/admin/asterisk.gif" />' . $this->l('CSV Export') . '</a></p><br /><br />
			<div style="overflow-y: scroll; height: 600px;">
			<center>
			<table class="table " border="0" cellspacing="0" cellspacing="0">
				<tr>
					<th style="width:400px;">' . $this->l('Origin') . '</th>
					<th style="width:50px; text-align: right">' . $this->l('Total') . '</th>
				</tr>';
            foreach ($websites as $website => $total) {
                $this->_html .= '<tr><td>' . (!strstr($website, ' ') ? '<a href="' . Tools::getProtocol() . $website . '">' : '') . $website . (!strstr($website, ' ') ? '</a>' : '') . '</td><td style="text-align: right">' . $total . '</td></tr>';
            }
            $this->_html .= '</table></center></div>';
        } else {
            $this->_html .= '<p><strong>' . $this->l('Direct links only') . '</strong></p>';
        }
        $this->_html .= '</fieldset><br />
		<fieldset class="width3"><legend><img src="../img/admin/comment.gif" /> ' . $this->l('Guide') . '</legend>
		<h2>' . $this->l('What is a referrer website?') . '</h2>
			<p>
				' . $this->l('When visiting a webpage, the referrer is the URL of the previous webpage from which a link was followed.') . '<br />
				' . $this->l('A referrer enables you to know which keywords are entered by visitors in search engines when getting to your shop and allows you to optimize web promotion.') . '<br /><br />
				' . $this->l('A referrer can be:') . '
				<ul>
					<li class="bullet">' . $this->l('Someone who put a link on their website for your shop') . '</li>
					<li class="bullet">' . $this->l('A partner with whom you made a link exchange in order to bring in sales or attract new customers') . '</li>
				</ul>
			</p>
		</fieldset>';
        return $this->_html;
    }
    protected function getData($layers)
    {
        $stateQuery = '';
        if (intval($this->_option)) {
            $stateQuery = 'AND (SELECT oh.id_order_state FROM `' . _DB_PREFIX_ . 'order_history` oh WHERE o.id_order = oh.id_order ORDER BY oh.date_add DESC, oh.id_order_history DESC LIMIT 1) = ' . intval($this->_option);
        }
        $this->_titles['main'] = $this->l('Percentage of orders by carrier');
        $result = Db::getInstance()->ExecuteS('
		SELECT c.name, COUNT(DISTINCT o.`id_order`) as total
		FROM `' . _DB_PREFIX_ . 'carrier` c
		LEFT JOIN `' . _DB_PREFIX_ . 'orders` o ON o.id_carrier = c.id_carrier
		WHERE o.`date_add` BETWEEN ' . ModuleGraph::getDateBetween() . '
		' . $stateQuery . '
		GROUP BY c.`id_carrier`');
        foreach ($result as $row) {
            $this->_values[] = $row['total'];
            $this->_legend[] = $row['name'];
        }
    }
Exemple #14
0
    public function hookAdminStatsModules()
    {
        if (Tools::getValue('export')) {
            $this->csvExport(array('type' => 'pie'));
        }
        $result = Db::getInstance(_PS_USE_SQL_SLAVE_)->executeS($this->query . ModuleGraph::getDateBetween() . $this->query_group_by);
        $this->html = '
		<div class="panel-heading">
			' . $this->displayName . '
		</div>';
        $table = '
		<table class="table">
			<thead>
				<tr>
					<th><span class="title_box active">' . $this->l('Keywords') . '</span></th>
					<th><span class="title_box active">' . $this->l('Occurrences') . '</span></th>
					<th><span class="title_box active">' . $this->l('Results') . '</span></th>
				</tr>
			</thead>
			<tbody>';
        foreach ($result as $row) {
            if (Tools::strlen($row['keywords']) >= Configuration::get('PS_SEARCH_MINWORDLEN')) {
                $table .= '<tr>
					<td>' . $row['keywords'] . '</td>
					<td>' . $row['occurences'] . '</td>
					<td>' . $row['total'] . '</td>
				</tr>';
            }
        }
        $table .= '
			</tbody>
		</table>';
        if (count($result)) {
            $this->html .= '<div>' . $this->engine(array('type' => 'pie')) . '</div>
							<a class="btn btn-default" href="' . Tools::safeOutput($_SERVER['REQUEST_URI']) . '&export=1">
								<i class="icon-cloud-upload"></i> ' . $this->l('CSV Export') . '
							</a>' . $table;
        } else {
            $this->html .= '<p>' . $this->l('Cannot find any keywords that have been searched for more than once.') . '</p>';
        }
        return $this->html;
    }
    private function getPages()
    {
        $result = Db::getInstance(_PS_USE_SQL_SLAVE_)->ExecuteS('
		SELECT http_referer, request_uri, COUNT(*) as nb
		FROM `' . _DB_PREFIX_ . 'pagenotfound` p
		WHERE p.date_add BETWEEN ' . ModuleGraph::getDateBetween() . '
		GROUP BY http_referer, request_uri');
        $pages = array();
        foreach ($result as $row) {
            $row['http_referer'] = parse_url($row['http_referer'], PHP_URL_HOST) . parse_url($row['http_referer'], PHP_URL_PATH);
            if (!isset($row['http_referer']) or empty($row['http_referer'])) {
                $row['http_referer'] = '--';
            }
            if (!isset($pages[$row['request_uri']])) {
                $pages[$row['request_uri']] = array('nb' => 0);
            }
            $pages[$row['request_uri']][$row['http_referer']] = $row['nb'];
            $pages[$row['request_uri']]['nb'] += $row['nb'];
        }
        uasort($pages, 'pnfSort');
        return $pages;
    }
Exemple #16
0
    public function hookAdminStatsModules()
    {
        $websites = $this->getOrigins(ModuleGraph::getDateBetween());
        if (Tools::getValue('export')) {
            if (Tools::getValue('exportType') == 'top') {
                $this->csvExport(array('type' => 'pie'));
            }
        }
        $this->_html = '<div class="panel-heading">' . $this->l('Origin') . '</div>';
        if (count($websites)) {
            $this->_html .= '
			<div class="alert alert-info">
				' . $this->l('In the tab, we break down the 10 most popular referral websites that bring customers to your online store.') . '
			</div>
			<h4>' . $this->l('Guide') . '</h4>
			<div class="alert alert-warning">
				<h4>' . $this->l('What is a referral website?') . '</h4>
				<p>
					' . $this->l('The referrer is the URL of the previous webpage from which a link was followed by the visitor.') . '<br />
					' . $this->l('A referrer also enables you to know which keywords visitors use in search engines when browsing for your online store.') . '<br /><br />
					' . $this->l('A referrer can be:') . '
				</p>
				<ul>
					<li>' . $this->l('Someone who posts a link to your shop.') . '</li>
					<li>' . $this->l('A partner who has agreed to a link exchange in order to attract new customers.') . '</li>
				</ul>
			</div>
			<div class="row row-margin-bottom">
				<div class="col-lg-12">
					<div class="col-lg-8">
						' . $this->engine(array('type' => 'pie')) . '
					</div>
					<div class="col-lg-4">
						<a href="' . Tools::safeOutput($_SERVER['REQUEST_URI'] . '&export=1&exportType=top') . '" class="btn btn-default">
							<i class="icon-cloud-upload"></i> ' . $this->l('CSV Export') . '
						</a>
					</div>
				</div>
			</div>
			<table class="table">
				<thead>
					<tr>
						<th><span class="title_box active">' . $this->l('Origin') . '</span></th>
						<th><span class="title_box active">' . $this->l('Total') . '</span></th>
					</tr>
				</thead>
				<tbody>';
            foreach ($websites as $website => $total) {
                $this->_html .= '
					<tr>
						<td>' . (!strstr($website, ' ') ? '<a href="' . Tools::getProtocol() . $website . '">' : '') . $website . (!strstr($website, ' ') ? '</a>' : '') . '</td><td>' . $total . '</td>
					</tr>';
            }
            $this->_html .= '
				</tbody>
			</table>';
        } else {
            $this->_html .= '<p>' . $this->l('Direct links only') . '</p>';
        }
        return $this->_html;
    }
Exemple #17
0
    private function getStatesData()
    {
        $result = Db::getInstance(_PS_USE_SQL_SLAVE_)->executeS('
		SELECT osl.`name`, COUNT(oh.`id_order`) as total
		FROM `' . _DB_PREFIX_ . 'order_state` os
		LEFT JOIN `' . _DB_PREFIX_ . 'order_state_lang` osl ON (os.`id_order_state` = osl.`id_order_state` AND osl.`id_lang` = ' . (int) $this->getLang() . ')
		LEFT JOIN `' . _DB_PREFIX_ . 'order_history` oh ON os.`id_order_state` = oh.`id_order_state`
		LEFT JOIN `' . _DB_PREFIX_ . 'orders` o ON o.`id_order` = oh.`id_order`
		' . ((int) $this->id_country ? 'LEFT JOIN `' . _DB_PREFIX_ . 'address` a ON o.id_address_delivery = a.id_address' : '') . '
		WHERE oh.`id_order_history` = (
			SELECT ios.`id_order_history`
			FROM `' . _DB_PREFIX_ . 'order_history` ios
			WHERE ios.`id_order` = oh.`id_order`
			ORDER BY ios.`date_add` DESC, oh.`id_order_history` DESC
			LIMIT 1
		)
		' . ((int) $this->id_country ? 'AND a.id_country = ' . (int) $this->id_country : '') . '
		AND o.`date_add` BETWEEN ' . ModuleGraph::getDateBetween() . '
		GROUP BY oh.`id_order_state`');
        foreach ($result as $row) {
            $this->_values[] = $row['total'];
            $this->_legend[] = $row['name'];
        }
    }
    public function hookAdminStatsModules()
    {
        if (Tools::isSubmit('submitSEK')) {
            Configuration::updateValue('SEK_FILTER_KW', trim(Tools::getValue('SEK_FILTER_KW')));
            Configuration::updateValue('SEK_MIN_OCCURENCES', (int) Tools::getValue('SEK_MIN_OCCURENCES'));
            Tools::redirectAdmin('index.php?tab=AdminStats&token=' . Tools::getValue('token') . '&module=' . $this->name);
        }
        if (Tools::getValue('export')) {
            $this->csvExport(array('type' => 'pie'));
        }
        $result = Db::getInstance(_PS_USE_SQL_SLAVE_)->executeS($this->query . ModuleGraph::getDateBetween() . $this->query2);
        $total = count($result);
        $this->html = '
		<div class="panel-heading">' . $this->displayName . '
		</div>
		<h4>' . $this->l('Guide') . '</h4>
		<div class="alert alert-warning">
			<h4>' . $this->l('Identify external search engine keywords') . '</h4>
			<p>' . $this->l('This is one of the most common ways of finding a website through a search engine.') . '&nbsp;' . $this->l('Identifying the most popular keywords entered by your new visitors allows you to see the products you should put in front if you want to achieve better visibility in search engines.') . '
			</p>
			<p>&nbsp;</p>
			<h4>' . $this->l('How does it work?') . '</h4>
			<p>' . $this->l('When a visitor comes to your website, the web server notes the URL of the site he/she comes from. This module then parses the URL, and if it finds a reference to a known search engine, it finds the keywords in it.') . '<br>' . $this->l('This module can recognize all the search engines listed in PrestaShop\'s Stats/Search Engine page -- and you can add more!') . '<br>' . $this->l('IMPORTANT NOTE: in September 2013, Google chose to encrypt its searches queries using SSL. This means all the referer-based tools in the World (including this one) cannot identify Google keywords anymore.') . '
			</p>
		</div>
		<p>' . ($total == 1 ? sprintf($this->l('%d keyword matches your query.'), $total) : sprintf($this->l('%d keywords match your query.'), $total)) . '</p>';
        $form = '
		<form action="' . Tools::htmlentitiesUTF8($_SERVER['REQUEST_URI']) . '" method="post" class="form-horizontal">
			<div class="row row-margin-bottom">
				<label class="control-label col-lg-3">' . $this->l('Filter by keyword') . '</label>
				<div class="col-lg-9">
					<input type="text" name="SEK_FILTER_KW" value="' . Tools::htmlentitiesUTF8(Configuration::get('SEK_FILTER_KW')) . '" />
				</div>
			</div>
			<div class="row row-margin-bottom">
				<label class="control-label col-lg-3">' . $this->l('And min occurrences') . '</label>
				<div class="col-lg-9">
					<input type="text" name="SEK_MIN_OCCURENCES" value="' . (int) Configuration::get('SEK_MIN_OCCURENCES') . '" />
				</div>
			</div>
			<div class="row row-margin-bottom">
				<div class="col-lg-9 col-lg-offset-3">
					<button type="submit" class="btn btn-default" name="submitSEK">
						<i class="icon-ok"></i> ' . $this->l('Apply') . '
					</button>
				</div>
			</div>
		</form>';
        if ($result && $total) {
            $table = '
			<table class="table">
				<thead>
					<tr>
						<th><span class="title_box active">' . $this->l('Keywords') . '</span></th>
						<th><span class="title_box active">' . $this->l('Occurrences') . '</span></th>
					</tr>
				</thead>
				<tbody>';
            foreach ($result as $row) {
                $keyword =& $row['keyword'];
                $occurences =& $row['occurences'];
                $table .= '<tr><td>' . $keyword . '</td><td>' . $occurences . '</td></tr>';
            }
            $table .= '</tbody></table>';
            $this->html .= '<div>' . $this->engine(array('type' => 'pie')) . '</div>
			<a class="btn btn-default" href="' . Tools::safeOutput($_SERVER['REQUEST_URI']) . '&export=1&exportType=language"><<i class="icon-cloud-upload"></i> ' . $this->l('CSV Export') . '</a>
			' . $form . '<br/>' . $table;
        } else {
            $this->html .= $form . '<p><strong>' . $this->l('No keywords') . '</strong></p>';
        }
        return $this->html;
    }
Exemple #19
0
    public function hookAdminStatsModules()
    {
        if (Tools::isSubmit('submitTruncatePNF')) {
            Db::getInstance()->execute('TRUNCATE `' . _DB_PREFIX_ . 'pagenotfound`');
            $this->_html .= '<div class="conf confirm"> ' . $this->l('Pages not found has been emptied.') . '</div>';
        } else {
            if (Tools::isSubmit('submitDeletePNF')) {
                Db::getInstance()->execute('
				DELETE FROM `' . _DB_PREFIX_ . 'pagenotfound`
				WHERE date_add BETWEEN ' . ModuleGraph::getDateBetween());
                $this->_html .= '<div class="conf confirm"> ' . $this->l('Pages not found have been deleted.') . '</div>';
            }
        }
        $this->_html .= '<div class="blocStats"><h2 class="icon-' . $this->name . '"><span></span>' . $this->displayName . '</h2>';
        if (!file_exists(dirname(__FILE__) . '/../../.htaccess')) {
            $this->_html .= '<br/><div class="warning warn">' . $this->l('You <b>must</b> use a .htaccess file to redirect 404 errors to the page "404.php"') . '</div>';
        }
        $pages = $this->getPages();
        if (count($pages)) {
            $this->_html .= '
			<table class="table" cellpadding="0" cellspacing="0">
				<tr>
					<th width="200">' . $this->l('Page') . '</th>
					<th width="500">' . $this->l('Referrer') . '</th>
					<th>' . $this->l('Counter') . '</th>
				</tr>';
            foreach ($pages as $ru => $hrs) {
                foreach ($hrs as $hr => $counter) {
                    if ($hr != 'nb') {
                        $this->_html .= '
						<tr>
							<td><a href="' . $ru . '-admin404">' . wordwrap($ru, 30, '<br />', true) . '</a></td>
							<td><a href="' . Tools::getProtocol() . $hr . '">' . wordwrap($hr, 40, '<br />', true) . '</a></td>
							<td align="right">' . $counter . '</td>
						</tr>';
                    }
                }
            }
            $this->_html .= '
			</table>';
        } else {
            $this->_html .= '<div class="conf confirm"> ' . $this->l('No pages registered') . '</div>';
        }
        $this->_html .= '</div>';
        if (count($pages)) {
            $this->_html .= '<div class="clear">&nbsp;</div>
			<div class="blocStats"><h2 class="icon-' . $this->name . '">' . $this->l('Empty database') . '</h2>
				<form action="' . Tools::htmlEntitiesUtf8($_SERVER['REQUEST_URI']) . '" method="post">
					<input type="submit" class="button" name="submitDeletePNF" value="' . $this->l('Empty ALL pages not found in this period') . '">
					<input type="submit" class="button" name="submitTruncatePNF" value="' . $this->l('Empty ALL pages not found') . '">
				</form>	
			</div>';
        }
        $this->_html .= '<br />
		<div class="blocStats"><h2 class="icon-guide"><span></span>' . $this->l('Guide') . '</h2>
			<h2>' . $this->l('404 errors') . '</h2>
			<p>' . $this->l('A 404 error is an HTTP error code which means that the file requested by the user cannot be found. 
				In your case it means that one of your visitors entered a wrong URL in the address bar or that you or another website has a dead link. 
				When it is available, the referrer is shown so you can find the page which contains the dead link. 
				If not, it means generally that it is a direct access, so someone may have bookmarked a link which doesn\'t exist anymore.') . '</p>
			<h3>' . $this->l('How to catch these errors?') . '</h3>
			<p>' . $this->l('If your webhost supports the <i>.htaccess</i> file, you can create it in the root directory of PrestaShop and insert the following line inside:') . ' 
				<i>ErrorDocument 404 ' . __PS_BASE_URI__ . '404.php</i>. ' . $this->l('A user requesting a page which doesn\'t exist will be redirected to the page.') . ' <i>' . __PS_BASE_URI__ . '404.php</i>. ' . $this->l('This module logs the accesses to this page: the page requested, the referrer and the number of times that it occurred.') . '</p><br />
		</div>';
        return $this->_html;
    }
Exemple #20
0
    private function getRealCA()
    {
        global $cookie;
        $employee = new Employee($cookie->id_employee);
        if ((int) $cookie->stats_id_zone) {
            $join = ' LEFT JOIN `' . _DB_PREFIX_ . 'address` a ON o.id_address_invoice = a.id_address LEFT JOIN `' . _DB_PREFIX_ . 'country` co ON co.id_country = a.id_country';
            $where = ' AND co.id_zone = ' . (int) $cookie->stats_id_zone . ' ';
        }
        $ca = array();
        $ca['cat'] = Db::getInstance()->ExecuteS('
		SELECT SUM(od.`product_price` * od.`product_quantity` / o.conversion_rate) as orderSum, COUNT(*) AS orderQty, cl.name, AVG(od.`product_price` / o.conversion_rate) as priveAvg
		FROM `' . _DB_PREFIX_ . 'orders` o
		LEFT JOIN `' . _DB_PREFIX_ . 'order_detail` od ON o.id_order = od.id_order
		LEFT JOIN `' . _DB_PREFIX_ . 'product` p ON p.id_product = od.product_id
		LEFT JOIN `' . _DB_PREFIX_ . 'category_lang` cl ON (p.id_category_default = cl.id_category AND cl.id_lang = ' . (int) $cookie->id_lang . ')
		' . ((int) $cookie->stats_id_zone ? $join : '') . '
		WHERE o.valid = 1
		AND o.`invoice_date` BETWEEN ' . ModuleGraph::getDateBetween() . '
		' . ((int) $cookie->stats_id_zone ? $where : '') . '
		GROUP BY p.id_category_default');
        uasort($ca['cat'], 'statsforecast_sort');
        $langValues = '';
        $languages = Db::getInstance()->ExecuteS('SELECT id_lang, iso_code FROM `' . _DB_PREFIX_ . 'lang` WHERE active = 1');
        foreach ($languages as $language) {
            $langValues .= 'SUM(IF(o.id_lang = ' . (int) $language['id_lang'] . ', total_products / o.conversion_rate, 0)) as ' . pSQL($language['iso_code']) . ',';
        }
        $langValues = rtrim($langValues, ',');
        $ca['lang'] = Db::getInstance()->getRow('
		SELECT ' . $langValues . '
		FROM `' . _DB_PREFIX_ . 'orders` o
		WHERE o.valid = 1
		AND o.`invoice_date` BETWEEN ' . ModuleGraph::getDateBetween());
        arsort($ca['lang']);
        $ca['langprev'] = Db::getInstance()->getRow('
		SELECT ' . $langValues . '
		FROM `' . _DB_PREFIX_ . 'orders` o
		WHERE o.valid = 1
		AND ADDDATE(o.`invoice_date`, interval 30 day) BETWEEN \'' . $employee->stats_date_from . ' 00:00:00\' AND \'' . min(date('Y-m-d H:i:s'), $employee->stats_date_to . ' 23:59:59') . '\'');
        $ca['payment'] = Db::getInstance()->ExecuteS('
		SELECT module, SUM(total_products / o.conversion_rate) as total, COUNT(*) as nb, AVG(total_products / o.conversion_rate) as cart
		FROM `' . _DB_PREFIX_ . 'orders` o
		' . ((int) $cookie->stats_id_zone ? $join : '') . '
		WHERE o.valid = 1
		AND o.`invoice_date` BETWEEN ' . ModuleGraph::getDateBetween() . '
		' . ((int) $cookie->stats_id_zone ? $where : '') . '
		GROUP BY o.module
		ORDER BY total DESC');
        $ca['zones'] = Db::getInstance()->ExecuteS('
		SELECT z.name, SUM(o.total_products / o.conversion_rate) as total, COUNT(*) as nb
		FROM `' . _DB_PREFIX_ . 'orders` o
		LEFT JOIN `' . _DB_PREFIX_ . 'address` a ON o.id_address_invoice = a.id_address
		LEFT JOIN `' . _DB_PREFIX_ . 'country` c ON c.id_country = a.id_country
		LEFT JOIN `' . _DB_PREFIX_ . 'zone` z ON z.id_zone = c.id_zone
		WHERE o.valid = 1
		AND o.`invoice_date` BETWEEN ' . ModuleGraph::getDateBetween() . '
		GROUP BY c.id_zone
		ORDER BY total DESC');
        $ca['currencies'] = Db::getInstance()->ExecuteS('
		SELECT cu.name, SUM(o.total_products / o.conversion_rate) as total, COUNT(*) as nb
		FROM `' . _DB_PREFIX_ . 'orders` o
		LEFT JOIN `' . _DB_PREFIX_ . 'currency` cu ON o.id_currency = cu.id_currency
		' . ((int) $cookie->stats_id_zone ? $join : '') . '
		WHERE o.valid = 1
		AND o.`invoice_date` BETWEEN ' . ModuleGraph::getDateBetween() . '
		' . ((int) $cookie->stats_id_zone ? $where : '') . '
		GROUP BY o.id_currency
		ORDER BY total DESC');
        $ca['ventil'] = Db::getInstance()->getRow('
		SELECT SUM(total_products / o.conversion_rate) as total, COUNT(*) AS nb
		FROM `' . _DB_PREFIX_ . 'orders` o
		WHERE o.valid = 1
		AND o.`invoice_date` BETWEEN ' . ModuleGraph::getDateBetween());
        $ca['attributes'] = Db::getInstance()->ExecuteS('
		SELECT /*pac.id_attribute,*/ agl.name as gname, al.name as aname, COUNT(*) as total
		FROM ' . _DB_PREFIX_ . 'orders o
		LEFT JOIN ' . _DB_PREFIX_ . 'order_detail od ON o.id_order = od.id_order
		INNER JOIN ' . _DB_PREFIX_ . 'product_attribute_combination pac ON od.product_attribute_id = pac.id_product_attribute
		INNER JOIN ' . _DB_PREFIX_ . 'attribute a ON pac.id_attribute = a.id_attribute
		INNER JOIN ' . _DB_PREFIX_ . 'attribute_group_lang agl ON (a.id_attribute_group = agl.id_attribute_group AND agl.id_lang = ' . (int) $cookie->id_lang . ')
		INNER JOIN ' . _DB_PREFIX_ . 'attribute_lang al ON (a.id_attribute = al.id_attribute AND al.id_lang = ' . (int) $cookie->id_lang . ')
		WHERE o.valid = 1
		AND o.`invoice_date` BETWEEN ' . ModuleGraph::getDateBetween() . '
		GROUP BY pac.id_attribute');
        return $ca;
    }
    private function getRealCA()
    {
        $employee = $this->context->employee;
        $ca = array();
        $where = $join = '';
        if ((int) $this->context->cookie->stats_id_zone) {
            $join = ' LEFT JOIN `' . _DB_PREFIX_ . 'address` a ON o.id_address_invoice = a.id_address LEFT JOIN `' . _DB_PREFIX_ . 'country` co ON co.id_country = a.id_country';
            $where = ' AND co.id_zone = ' . (int) $this->context->cookie->stats_id_zone . ' ';
        }
        $sql = 'SELECT SUM(od.`product_price` * od.`product_quantity` / o.conversion_rate) as orderSum, SUM(od.product_quantity) as orderQty, cl.name, AVG(od.`product_price` / o.conversion_rate) as priveAvg
				FROM `' . _DB_PREFIX_ . 'orders` o
				STRAIGHT_JOIN `' . _DB_PREFIX_ . 'order_detail` od ON o.id_order = od.id_order
				LEFT JOIN `' . _DB_PREFIX_ . 'product` p ON p.id_product = od.product_id
				' . Shop::addSqlAssociation('product', 'p') . '
				LEFT JOIN `' . _DB_PREFIX_ . 'category_lang` cl ON (product_shop.id_category_default = cl.id_category AND cl.id_lang = ' . (int) $this->context->language->id . Shop::addSqlRestrictionOnLang('cl') . ')
				' . $join . '
				WHERE o.valid = 1
					AND o.`invoice_date` BETWEEN ' . ModuleGraph::getDateBetween() . '
					' . $where . '
					' . Shop::addSqlRestriction(Shop::SHARE_ORDER, 'o') . '
				GROUP BY product_shop.id_category_default';
        $ca['cat'] = Db::getInstance()->executeS($sql);
        uasort($ca['cat'], 'statsforecast_sort');
        $lang_values = '';
        $sql = 'SELECT l.id_lang, l.iso_code
				FROM `' . _DB_PREFIX_ . 'lang` l
				' . Shop::addSqlAssociation('lang', 'l') . '
				WHERE l.active = 1';
        $languages = Db::getInstance()->executeS($sql);
        foreach ($languages as $language) {
            $lang_values .= 'SUM(IF(o.id_lang = ' . (int) $language['id_lang'] . ', total_paid_tax_excl / o.conversion_rate, 0)) as ' . pSQL($language['iso_code']) . ',';
        }
        $lang_values = rtrim($lang_values, ',');
        if ($lang_values) {
            $sql = 'SELECT ' . $lang_values . '
					FROM `' . _DB_PREFIX_ . 'orders` o
					WHERE o.valid = 1
					AND o.`invoice_date` BETWEEN ' . ModuleGraph::getDateBetween() . '
					' . Shop::addSqlRestriction(Shop::SHARE_ORDER, 'o');
            $ca['lang'] = Db::getInstance()->getRow($sql);
            arsort($ca['lang']);
            $sql = 'SELECT ' . $lang_values . '
					FROM `' . _DB_PREFIX_ . 'orders` o
					WHERE o.valid = 1
						AND ADDDATE(o.`invoice_date`, interval 30 day) BETWEEN \'' . $employee->stats_date_from . ' 00:00:00\' AND \'' . min(date('Y-m-d H:i:s'), $employee->stats_date_to . ' 23:59:59') . '\'
						' . Shop::addSqlRestriction(Shop::SHARE_ORDER, 'o');
            $ca['langprev'] = Db::getInstance()->getRow($sql);
        } else {
            $ca['lang'] = array();
            $ca['langprev'] = array();
        }
        $sql = 'SELECT op.payment_method, SUM(op.amount / op.conversion_rate) as total, COUNT(DISTINCT op.order_reference) as nb
				FROM `' . _DB_PREFIX_ . 'order_payment` op
				WHERE op.`date_add` BETWEEN ' . ModuleGraph::getDateBetween() . '
				AND op.order_reference IN (
					SELECT reference
					FROM `' . _DB_PREFIX_ . 'orders` o
					' . $join . '
					WHERE o.valid
					' . $where . '
					' . Shop::addSqlRestriction(Shop::SHARE_ORDER, 'o') . '
					AND o.invoice_date BETWEEN ' . ModuleGraph::getDateBetween() . '
				)
				GROUP BY op.payment_method
				ORDER BY total DESC';
        $ca['payment'] = Db::getInstance()->executeS($sql);
        $sql = 'SELECT z.name, SUM(o.total_paid_tax_excl / o.conversion_rate) as total, COUNT(*) as nb
				FROM `' . _DB_PREFIX_ . 'orders` o
				LEFT JOIN `' . _DB_PREFIX_ . 'address` a ON o.id_address_invoice = a.id_address
				LEFT JOIN `' . _DB_PREFIX_ . 'country` c ON c.id_country = a.id_country
				LEFT JOIN `' . _DB_PREFIX_ . 'zone` z ON z.id_zone = c.id_zone
				WHERE o.valid = 1
					AND o.`invoice_date` BETWEEN ' . ModuleGraph::getDateBetween() . '
					' . Shop::addSqlRestriction(Shop::SHARE_ORDER, 'o') . '
				GROUP BY c.id_zone
				ORDER BY total DESC';
        $ca['zones'] = Db::getInstance()->executeS($sql);
        $sql = 'SELECT cu.name, SUM(o.total_paid_tax_excl / o.conversion_rate) as total, COUNT(*) as nb
				FROM `' . _DB_PREFIX_ . 'orders` o
				LEFT JOIN `' . _DB_PREFIX_ . 'currency` cu ON o.id_currency = cu.id_currency
				' . $join . '
				WHERE o.valid = 1
					AND o.`invoice_date` BETWEEN ' . ModuleGraph::getDateBetween() . '
					' . $where . '
					' . Shop::addSqlRestriction(Shop::SHARE_ORDER, 'o') . '
				GROUP BY o.id_currency
				ORDER BY total DESC';
        $ca['currencies'] = Db::getInstance()->executeS($sql);
        $sql = 'SELECT SUM(total_paid_tax_excl / o.conversion_rate) as total, COUNT(*) AS nb
				FROM `' . _DB_PREFIX_ . 'orders` o
				WHERE o.valid = 1
					AND o.`invoice_date` BETWEEN ' . ModuleGraph::getDateBetween() . '
					' . Shop::addSqlRestriction(Shop::SHARE_ORDER, 'o');
        $ca['ventil'] = Db::getInstance()->getRow($sql);
        $sql = 'SELECT /*pac.id_attribute,*/ agl.name as gname, al.name as aname, COUNT(*) as total
				FROM ' . _DB_PREFIX_ . 'orders o
				LEFT JOIN ' . _DB_PREFIX_ . 'order_detail od ON o.id_order = od.id_order
				INNER JOIN ' . _DB_PREFIX_ . 'product_attribute_combination pac ON od.product_attribute_id = pac.id_product_attribute
				INNER JOIN ' . _DB_PREFIX_ . 'attribute a ON pac.id_attribute = a.id_attribute
				INNER JOIN ' . _DB_PREFIX_ . 'attribute_group_lang agl ON (a.id_attribute_group = agl.id_attribute_group AND agl.id_lang = ' . (int) $this->context->language->id . ')
				INNER JOIN ' . _DB_PREFIX_ . 'attribute_lang al ON (a.id_attribute = al.id_attribute AND al.id_lang = ' . (int) $this->context->language->id . ')
				WHERE o.valid = 1
					AND o.`invoice_date` BETWEEN ' . ModuleGraph::getDateBetween() . '
					' . Shop::addSqlRestriction(Shop::SHARE_ORDER, 'o') . '
				GROUP BY pac.id_attribute';
        $ca['attributes'] = Db::getInstance()->executeS($sql);
        return $ca;
    }
    public function hookAdminStatsModules()
    {
        if (Tools::isSubmit('submitCheckup')) {
            $confs = array('CHECKUP_DESCRIPTIONS_LT', 'CHECKUP_DESCRIPTIONS_GT', 'CHECKUP_IMAGES_LT', 'CHECKUP_IMAGES_GT', 'CHECKUP_SALES_LT', 'CHECKUP_SALES_GT', 'CHECKUP_STOCK_LT', 'CHECKUP_STOCK_GT');
            foreach ($confs as $confname) {
                Configuration::updateValue($confname, (int) Tools::getValue($confname));
            }
            echo '<div class="conf confirm"> ' . $this->l('Configuration updated') . '</div>';
        }
        if (Tools::isSubmit('submitCheckupOrder')) {
            $this->context->cookie->checkup_order = (int) Tools::getValue('submitCheckupOrder');
            echo '<div class="conf confirm"> ' . $this->l('Configuration updated') . '</div>';
        }
        if (!isset($this->context->cookie->checkup_order)) {
            $this->context->cookie->checkup_order = 1;
        }
        $db = Db::getInstance(_PS_USE_SQL_SLAVE_);
        $employee = Context::getContext()->employee;
        $prop30 = (strtotime($employee->stats_date_to . ' 23:59:59') - strtotime($employee->stats_date_from . ' 00:00:00')) / 60 / 60 / 24 / 30;
        // Get languages
        $sql = 'SELECT l.*
				FROM ' . _DB_PREFIX_ . 'lang l' . Shop::addSqlAssociation('lang', 'l');
        $languages = $db->executeS($sql);
        $array_colors = array(0 => '<img src="../modules/' . $this->name . '/img/red.png" alt="' . $this->l('Bad') . '" />', 1 => '<img src="../modules/' . $this->name . '/img/orange.png" alt="' . $this->l('Average') . '" />', 2 => '<img src="../modules/' . $this->name . '/img/green.png" alt="' . $this->l('Good') . '" />');
        $token_products = Tools::getAdminToken('AdminProducts' . (int) Tab::getIdFromClassName('AdminProducts') . (int) Context::getContext()->employee->id);
        $divisor = 4;
        $totals = array('products' => 0, 'active' => 0, 'images' => 0, 'sales' => 0, 'stock' => 0);
        foreach ($languages as $language) {
            $divisor++;
            $totals['description_' . $language['iso_code']] = 0;
        }
        $order_by = 'p.id_product';
        if ($this->context->cookie->checkup_order == 2) {
            $order_by = 'pl.name';
        } else {
            if ($this->context->cookie->checkup_order == 3) {
                $order_by = 'nbSales DESC';
            }
        }
        // Get products stats
        $sql = 'SELECT p.id_product, product_shop.active, pl.name, (
					SELECT COUNT(*)
					FROM ' . _DB_PREFIX_ . 'image i
					' . Shop::addSqlAssociation('image', 'i') . '
					WHERE i.id_product = p.id_product
				) as nbImages, (
					SELECT SUM(od.product_quantity)
					FROM ' . _DB_PREFIX_ . 'orders o
					LEFT JOIN ' . _DB_PREFIX_ . 'order_detail od ON o.id_order = od.id_order
					WHERE od.product_id = p.id_product
						AND o.invoice_date BETWEEN ' . ModuleGraph::getDateBetween() . '
						' . Shop::addSqlRestriction(Shop::SHARE_ORDER, 'o') . '
				) as nbSales,
				IFNULL(stock.quantity, 0) as stock
				FROM ' . _DB_PREFIX_ . 'product p
				' . Shop::addSqlAssociation('product', 'p') . '
				' . Product::sqlStock('p', 0) . '
				LEFT JOIN ' . _DB_PREFIX_ . 'product_lang pl
					ON (p.id_product = pl.id_product AND pl.id_lang = ' . (int) $this->context->language->id . Shop::addSqlRestrictionOnLang('pl') . ')
				ORDER BY ' . $order_by;
        $result = $db->executeS($sql);
        if (!$result) {
            return $this->l('No product was found.');
        }
        $array_conf = array('DESCRIPTIONS' => array('name' => $this->l('Descriptions'), 'text' => $this->l('chars (without HTML)')), 'IMAGES' => array('name' => $this->l('Images'), 'text' => $this->l('images')), 'SALES' => array('name' => $this->l('Sales'), 'text' => $this->l('orders / month')), 'STOCK' => array('name' => $this->l('Available quantity for sale'), 'text' => $this->l('items')));
        $this->html = '
		<div class="panel-heading">' . $this->displayName . '
		</div>
		<form action="' . Tools::safeOutput(AdminController::$currentIndex . '&token=' . Tools::getValue('token') . '&module=' . $this->name) . '" method="post" class="checkup form-horizontal">
			<table class="table checkup">
				<thead>
					<tr>
						<th></th>
						<th><span class="title_box active">' . $array_colors[0] . ' ' . $this->l('Not enough') . '</span></th>
						<th><span class="title_box active">' . $array_colors[2] . ' ' . $this->l('Alright') . '</span></th>
					</tr>
				</thead>';
        foreach ($array_conf as $conf => $translations) {
            $this->html .= '
				<tbody>
					<tr>
						<td>
							<label class="control-label col-lg-12">' . $translations['name'] . '</label>
						</td>
						<td>
							<div class="row">
								<div class="col-lg-11 input-group">
									<span class="input-group-addon">' . $this->l('Less than') . '</span>
									<input type="text" name="CHECKUP_' . $conf . '_LT" value="' . Tools::safeOutput(Tools::getValue('CHECKUP_' . $conf . '_LT', Configuration::get('CHECKUP_' . $conf . '_LT'))) . '" />
									<span class="input-group-addon">' . $translations['text'] . '</span>
								 </div>
							 </div>
						</td>
						<td>
							<div class="row">
								<div class="col-lg-12 input-group">
									<span class="input-group-addon">' . $this->l('Greater than') . '</span>
									<input type="text" name="CHECKUP_' . $conf . '_GT" value="' . Tools::safeOutput(Tools::getValue('CHECKUP_' . $conf . '_GT', Configuration::get('CHECKUP_' . $conf . '_GT'))) . '" />
									<span class="input-group-addon">' . $translations['text'] . '</span>
								 </div>
							 </div>
						</td>
					</tr>
				</tbody>';
        }
        $this->html .= '</table>
			<button type="submit" name="submitCheckup" class="btn btn-default pull-right">
				<i class="icon-save"></i> ' . $this->l('Save') . '
			</button> 
		</form>
		<form action="' . Tools::safeOutput(AdminController::$currentIndex . '&token=' . Tools::getValue('token') . '&module=' . $this->name) . '" method="post" class="form-horizontal alert">
			<div class="row">
				<div class="col-lg-12">
					<label class="control-label pull-left">' . $this->l('Order by') . '</label>
					<div class="col-lg-3">
						<select name="submitCheckupOrder" onchange="this.form.submit();">
							<option value="1">' . $this->l('ID') . '</option>
							<option value="2" ' . ($this->context->cookie->checkup_order == 2 ? 'selected="selected"' : '') . '>' . $this->l('Name') . '</option>
							<option value="3" ' . ($this->context->cookie->checkup_order == 3 ? 'selected="selected"' : '') . '>' . $this->l('Sales') . '</option>
						</select>
					</div>
				</div>
			</div>
		</form>
		<div style="overflow-x:auto">
		<table class="table checkup2">
			<thead>
				<tr>
					<th><span class="title_box active">' . $this->l('ID') . '</span></th>
					<th><span class="title_box active">' . $this->l('Item') . '</span></th>
					<th class="center"><span class="title_box active">' . $this->l('Active') . '</span></th>';
        foreach ($languages as $language) {
            $this->html .= '<th><span class="title_box active">' . $this->l('Desc.') . ' (' . Tools::strtoupper($language['iso_code']) . ')</span></th>';
        }
        $this->html .= '
					<th class="center"><span class="title_box active">' . $this->l('Images') . '</span></th>
					<th class="center"><span class="title_box active">' . $this->l('Sales') . '</span></th>
					<th class="center"><span class="title_box active">' . $this->l('Available quantity for sale') . '</span></th>
					<th class="center"><span class="title_box active">' . $this->l('Global') . '</span></th>
				</tr>
			</thead>
			<tbody>';
        foreach ($result as $row) {
            $totals['products']++;
            $scores = array('active' => $row['active'] ? 2 : 0, 'images' => $row['nbImages'] < Configuration::get('CHECKUP_IMAGES_LT') ? 0 : ($row['nbImages'] > Configuration::get('CHECKUP_IMAGES_GT') ? 2 : 1), 'sales' => $row['nbSales'] * $prop30 < Configuration::get('CHECKUP_SALES_LT') ? 0 : ($row['nbSales'] * $prop30 > Configuration::get('CHECKUP_SALES_GT') ? 2 : 1), 'stock' => $row['stock'] < Configuration::get('CHECKUP_STOCK_LT') ? 0 : ($row['stock'] > Configuration::get('CHECKUP_STOCK_GT') ? 2 : 1));
            $totals['active'] += (int) $scores['active'];
            $totals['images'] += (int) $scores['images'];
            $totals['sales'] += (int) $scores['sales'];
            $totals['stock'] += (int) $scores['stock'];
            $descriptions = $db->executeS('
				SELECT l.iso_code, pl.description
				FROM ' . _DB_PREFIX_ . 'product_lang pl
				LEFT JOIN ' . _DB_PREFIX_ . 'lang l
					ON pl.id_lang = l.id_lang
				WHERE id_product = ' . (int) $row['id_product'] . Shop::addSqlRestrictionOnLang('pl'));
            foreach ($descriptions as $description) {
                if (isset($description['iso_code']) && isset($description['description'])) {
                    $row['desclength_' . $description['iso_code']] = Tools::strlen(strip_tags($description['description']));
                }
                if (isset($description['iso_code'])) {
                    $scores['description_' . $description['iso_code']] = $row['desclength_' . $description['iso_code']] < Configuration::get('CHECKUP_DESCRIPTIONS_LT') ? 0 : ($row['desclength_' . $description['iso_code']] > Configuration::get('CHECKUP_DESCRIPTIONS_GT') ? 2 : 1);
                    $totals['description_' . $description['iso_code']] += $scores['description_' . $description['iso_code']];
                }
            }
            $scores['average'] = array_sum($scores) / $divisor;
            $scores['average'] = $scores['average'] < 1 ? 0 : ($scores['average'] > 1.5 ? 2 : 1);
            $this->html .= '
				<tr>
					<td>' . $row['id_product'] . '</td>
					<td><a href="' . Tools::safeOutput('index.php?tab=AdminProducts&updateproduct&id_product=' . $row['id_product'] . '&token=' . $token_products) . '">' . Tools::substr($row['name'], 0, 42) . '</a></td>
					<td class="center">' . $array_colors[$scores['active']] . '</td>';
            foreach ($languages as $language) {
                if (isset($row['desclength_' . $language['iso_code']])) {
                    $this->html .= '<td class="center">' . (int) $row['desclength_' . $language['iso_code']] . ' ' . $array_colors[$scores['description_' . $language['iso_code']]] . '</td>';
                } else {
                    $this->html .= '<td>0 ' . $array_colors[0] . '</td>';
                }
            }
            $this->html .= '
					<td class="center">' . (int) $row['nbImages'] . ' ' . $array_colors[$scores['images']] . '</td>
					<td class="center">' . (int) $row['nbSales'] . ' ' . $array_colors[$scores['sales']] . '</td>
					<td class="center">' . (int) $row['stock'] . ' ' . $array_colors[$scores['stock']] . '</td>
					<td class="center">' . $array_colors[$scores['average']] . '</td>
				</tr>';
        }
        $this->html .= '</tbody>';
        $totals['active'] = $totals['active'] / $totals['products'];
        $totals['active'] = $totals['active'] < 1 ? 0 : ($totals['active'] > 1.5 ? 2 : 1);
        $totals['images'] = $totals['images'] / $totals['products'];
        $totals['images'] = $totals['images'] < 1 ? 0 : ($totals['images'] > 1.5 ? 2 : 1);
        $totals['sales'] = $totals['sales'] / $totals['products'];
        $totals['sales'] = $totals['sales'] < 1 ? 0 : ($totals['sales'] > 1.5 ? 2 : 1);
        $totals['stock'] = $totals['stock'] / $totals['products'];
        $totals['stock'] = $totals['stock'] < 1 ? 0 : ($totals['stock'] > 1.5 ? 2 : 1);
        foreach ($languages as $language) {
            $totals['description_' . $language['iso_code']] = $totals['description_' . $language['iso_code']] / $totals['products'];
            $totals['description_' . $language['iso_code']] = $totals['description_' . $language['iso_code']] < 1 ? 0 : ($totals['description_' . $language['iso_code']] > 1.5 ? 2 : 1);
        }
        $totals['average'] = array_sum($totals) / $divisor;
        $totals['average'] = $totals['average'] < 1 ? 0 : ($totals['average'] > 1.5 ? 2 : 1);
        $this->html .= '
			<tfoot>
				<tr>
					<th colspan="2"></th>
					<th class="center"><span class="title_box active">' . $this->l('Active') . '</span></th>';
        foreach ($languages as $language) {
            $this->html .= '<th class="center"><span class="title_box active">' . $this->l('Desc.') . ' (' . Tools::strtoupper($language['iso_code']) . ')</span></th>';
        }
        $this->html .= '
					<th class="center"><span class="title_box active">' . $this->l('Images') . '</span></th>
					<th class="center"><span class="title_box active">' . $this->l('Sales') . '</span></th>
					<th class="center"><span class="title_box active">' . $this->l('Available quantity for sale') . '</span></th>
					<th class="center"><span class="title_box active">' . $this->l('Global') . '</span></th>
				</tr>
				<tr>
					<td colspan="2"></td>
					<td class="center">' . $array_colors[$totals['active']] . '</td>';
        foreach ($languages as $language) {
            $this->html .= '<td class="center">' . $array_colors[$totals['description_' . $language['iso_code']]] . '</td>';
        }
        $this->html .= '
					<td class="center">' . $array_colors[$totals['images']] . '</td>
					<td class="center">' . $array_colors[$totals['sales']] . '</td>
					<td class="center">' . $array_colors[$totals['stock']] . '</td>
					<td class="center">' . $array_colors[$totals['average']] . '</td>
				</tr>
			</tfoot>
		</table></div>';
        return $this->html;
    }
    public function hookAdminStatsModules()
    {
        if (Tools::isSubmit('submitTruncatePNF')) {
            Db::getInstance()->execute('TRUNCATE `' . _DB_PREFIX_ . 'pagenotfound`');
            $this->html .= '<div class="alert alert-warning"> ' . $this->l('The "pages not found" cache has been emptied.') . '</div>';
        } else {
            if (Tools::isSubmit('submitDeletePNF')) {
                Db::getInstance()->execute('DELETE FROM `' . _DB_PREFIX_ . 'pagenotfound`
				WHERE date_add BETWEEN ' . ModuleGraph::getDateBetween());
                $this->html .= '<div class="alert alert-warning"> ' . $this->l('The "pages not found" cache has been deleted.') . '</div>';
            }
        }
        $this->html .= '
			<div class="panel-heading">
				' . $this->displayName . '
			</div>
			<h4>' . $this->l('Guide') . '</h4>
			<div class="alert alert-warning">
				<h4>' . $this->l('404 errors') . '</h4>
				<p>' . $this->l('A 404 error is an HTTP error code which means that the file requested by the user cannot be found. In your case it means that one of your visitors entered a wrong URL in the address bar, or that you or another website has a dead link. When possible, the referrer is shown so you can find the page/site which contains the dead link. If not, it generally means that it is a direct access, so someone may have bookmarked a link which doesn\'t exist anymore.') . '
				</p>
				<p>&nbsp;</p>
				<h4>' . $this->l('How to catch these errors?') . '</h4>
				<p>' . sprintf($this->l('If your webhost supports .htaccess files, you can create one in the root directory of PrestaShop and insert the following line inside: "%s".'), 'ErrorDocument 404 ' . __PS_BASE_URI__ . '404.php') . '<br />' . sprintf($this->l('A user requesting a page which doesn\'t exist will be redirected to the following page: %s. This module logs access to this page.'), __PS_BASE_URI__ . '404.php') . '
				</p>
			</div>';
        if (!file_exists($this->_normalizeDirectory(_PS_ROOT_DIR_) . '.htaccess')) {
            $this->html .= '<div class="alert alert-warning">' . $this->l('You must use a .htaccess file to redirect 404 errors to the "404.php" page.') . '</div>';
        }
        $pages = $this->getPages();
        if (count($pages)) {
            $this->html .= '
			<table class="table">
				<thead>
					<tr>
						<th><span class="title_box active">' . $this->l('Page') . '</span></th>
						<th><span class="title_box active">' . $this->l('Referrer') . '</span></th>
						<th><span class="title_box active">' . $this->l('Counter') . '</span></th>
					</tr>
				</thead>
				<tbody>';
            foreach ($pages as $ru => $hrs) {
                foreach ($hrs as $hr => $counter) {
                    if ($hr != 'nb') {
                        $this->html .= '
						<tr>
							<td><a href="' . $ru . '-admin404">' . wordwrap($ru, 30, '<br />', true) . '</a></td>
							<td><a href="' . Tools::getProtocol() . $hr . '">' . wordwrap($hr, 40, '<br />', true) . '</a></td>
							<td>' . $counter . '</td>
						</tr>';
                    }
                }
            }
            $this->html .= '
				</tbody>
			</table>';
        } else {
            $this->html .= '<div class="alert alert-warning"> ' . $this->l('No "page not found" issue registered for now.') . '</div>';
        }
        if (count($pages)) {
            $this->html .= '
				<h4>' . $this->l('Empty database') . '</h4>
				<form action="' . Tools::htmlEntitiesUtf8($_SERVER['REQUEST_URI']) . '" method="post">
					<button type="submit" class="btn btn-default" name="submitDeletePNF">
						<i class="icon-remove"></i> ' . $this->l('Empty ALL "pages not found" notices for this period') . '
					</button>
					<button type="submit" class="btn btn-default" name="submitTruncatePNF">
						<i class="icon-remove"></i> ' . $this->l('Empty ALL "pages not found" notices') . '
					</button>
				</form>';
        }
        return $this->html;
    }
Exemple #24
0
    protected function getData($layers)
    {
        $state_query = '';
        if ((int) $this->option) {
            $state_query = 'AND (
				SELECT oh.id_order_state FROM `' . _DB_PREFIX_ . 'order_history` oh
				WHERE o.id_order = oh.id_order
				ORDER BY oh.date_add DESC, oh.id_order_history DESC
				LIMIT 1) = ' . (int) $this->option;
        }
        $this->_titles['main'] = $this->l('Percentage of orders listed by carrier.');
        $sql = 'SELECT c.name, COUNT(DISTINCT o.`id_order`) as total
				FROM `' . _DB_PREFIX_ . 'carrier` c
				LEFT JOIN `' . _DB_PREFIX_ . 'orders` o ON o.id_carrier = c.id_carrier
				WHERE o.`date_add` BETWEEN ' . ModuleGraph::getDateBetween() . '
					' . Shop::addSqlRestriction(Shop::SHARE_ORDER, 'o') . '
					' . $state_query . '
				GROUP BY c.`id_carrier`';
        $result = Db::getInstance(_PS_USE_SQL_SLAVE_)->executeS($sql);
        foreach ($result as $row) {
            $this->_values[] = $row['total'];
            $this->_legend[] = $row['name'];
        }
    }
 public function postProcess()
 {
     if ($this->enableCalendar()) {
         // Warning, instantiating a controller here changes the controller in the Context...
         $calendar_tab = new AdminStatsController();
         $calendar_tab->postProcess();
         // ...so we set it back to the correct one here
         $this->context->controller = $this;
     }
     if (Tools::isSubmit('submitSettings')) {
         if ($this->tabAccess['edit'] === '1') {
             if (Configuration::updateValue('TRACKING_DIRECT_TRAFFIC', (int) Tools::getValue('tracking_dt'))) {
                 Tools::redirectAdmin(self::$currentIndex . '&conf=4&token=' . Tools::getValue('token'));
             }
         }
     }
     if (ModuleGraph::getDateBetween() != Configuration::get('PS_REFERRERS_CACHE_LIKE') || Tools::isSubmit('submitRefreshCache')) {
         Referrer::refreshCache();
     }
     if (Tools::isSubmit('submitRefreshIndex')) {
         Referrer::refreshIndex();
     }
     return parent::postProcess();
 }
 /**
  * Refresh cache data of referrer statistics in referrer_shop table
  *
  * @param array $referrers
  * @param int $employee
  * @return true
  */
 public static function refreshCache($referrers = null, $employee = null)
 {
     if (!$referrers || !is_array($referrers)) {
         $referrers = Db::getInstance()->executeS('SELECT id_referrer FROM ' . _DB_PREFIX_ . 'referrer');
     }
     foreach ($referrers as $row) {
         $referrer = new Referrer($row['id_referrer']);
         foreach (Shop::getShops(true, null, true) as $shop_id) {
             if (!$referrer->isAssociatedToShop($shop_id)) {
                 continue;
             }
             $stats_visits = $referrer->getStatsVisits(null, $employee);
             $registrations = $referrer->getRegistrations(null, $employee);
             $stats_sales = $referrer->getStatsSales(null, $employee);
             Db::getInstance()->update('referrer_shop', array('cache_visitors' => (int) $stats_visits['uniqs'], 'cache_visits' => (int) $stats_visits['visits'], 'cache_pages' => (int) $stats_visits['pages'], 'cache_registrations' => (int) $registrations, 'cache_orders' => (int) $stats_sales['orders'], 'cache_sales' => number_format($stats_sales['sales'], 2, '.', ''), 'cache_reg_rate' => $stats_visits['uniqs'] ? $registrations / $stats_visits['uniqs'] : 0, 'cache_order_rate' => $stats_visits['uniqs'] ? $stats_sales['orders'] / $stats_visits['uniqs'] : 0), 'id_referrer = ' . (int) $referrer->id . ' AND id_shop = ' . (int) $shop_id);
         }
     }
     Configuration::updateValue('PS_REFERRERS_CACHE_LIKE', ModuleGraph::getDateBetween($employee));
     Configuration::updateValue('PS_REFERRERS_CACHE_DATE', date('Y-m-d H:i:s'));
     return true;
 }
Exemple #27
0
    public function hookAdminStatsModules()
    {
        if (Tools::isSubmit('submitSEK')) {
            Configuration::updateValue('SEK_FILTER_KW', trim(Tools::getValue('SEK_FILTER_KW')));
            Configuration::updateValue('SEK_MIN_OCCURENCES', (int) Tools::getValue('SEK_MIN_OCCURENCES'));
            Tools::redirectAdmin('index.php?tab=AdminStats&token=' . Tools::getValue('token') . '&module=' . $this->name);
        }
        if (Tools::getValue('export')) {
            $this->csvExport(array('type' => 'pie'));
        }
        $result = Db::getInstance(_PS_USE_SQL_SLAVE_)->executeS($this->_query . ModuleGraph::getDateBetween() . $this->_query2);
        $total = count($result);
        $this->html = '<div class="blocStats"><h2 class="icon-' . $this->name . '"><span></span>' . $this->displayName . '</h2>
		<p>' . ($total == 1 ? sprintf($this->l('%d keyword matches your query.'), $total) : sprintf($this->l('%d keywords match your query.'), $total)) . '</p>';
        if ($result && $total) {
            $table = '
			<div style="overflow-y: scroll; height: 600px;">
			<table class="table" border="0" cellspacing="0" cellspacing="0">
			<thead>
				<tr><th style="width:400px;">' . $this->l('Keywords') . '</th>
				<th style="width:50px; text-align: right">' . $this->l('Occurrences') . '</th></tr>
			</thead><tbody>';
            foreach ($result as $index => $row) {
                $keyword =& $row['keyword'];
                $occurences =& $row['occurences'];
                $table .= '<tr><td>' . $keyword . '</td><td style="text-align: right">' . $occurences . '</td></tr>';
            }
            $table .= '</tbody></table></div>';
            $this->html .= '<div>' . $this->engine(array('type' => 'pie')) . '</div>
			<br/>
			<p><a href="' . Tools::safeOutput($_SERVER['REQUEST_URI']) . '&export=1&exportType=language"><img src="../img/admin/asterisk.gif" />' . $this->l('CSV Export') . '</a></p><br/>
			<form action="' . Tools::htmlentitiesUTF8($_SERVER['REQUEST_URI']) . '" method="post">
				' . $this->l('Filter by keyword') . ' <input type="text" name="SEK_FILTER_KW" value="' . Tools::htmlentitiesUTF8(Configuration::get('SEK_FILTER_KW')) . '" />
				' . $this->l('and min occurrences') . ' <input type="text" name="SEK_MIN_OCCURENCES" value="' . (int) Configuration::get('SEK_MIN_OCCURENCES') . '" />
				<input type="submit" class="button" name="submitSEK" value="' . $this->l('   Apply   ') . '" />
			</form>
			<br/>' . $table;
        } else {
            $this->html .= '<p><strong>' . $this->l('No keywords') . '</strong></p>';
        }
        $this->html .= '</div><br/>
		<div class="blocStats"><h2 class="icon-guide"><span></span>' . $this->l('Guide') . '</h2>
			<h2>' . $this->l('Identify external search engines\' keywords') . '</h2>
			<p>' . $this->l('One of the most common ways of finding a website through a search engine.') . $this->l('Identifying the most popular keywords entered by your new visitors allows you to see which products you should put in front if you want to attract more visitors and potential customers.') . '
			</p><br />
			<h3>' . $this->l('How does it work?') . '</h2>
			<p>' . $this->l('When a visitor comes to your website, the server notes their previous location. This module parses the URL and finds the keywords in it.') . sprintf($this->l('Currently, it manages the following search engines: %1$s and %2$s.'), '<b>Google, AOL, Yandex, Ask, NHL, Yahoo, Baidu, Lycos, Exalead, Live, Voila</b>', '<b>Altavista</b>') . $this->l('Soon it will be possible to dynamically add new search engines and contribute to this module.') . '</p><br />
		</div>';
        return $this->html;
    }
Exemple #28
0
 public function getDate()
 {
     return ModuleGraph::getDateBetween($this->_employee);
 }
Exemple #29
0
    public function display()
    {
        global $cookie;
        $currency = Currency::getCurrency(Configuration::get('PS_CURRENCY_DEFAULT'));
        $language = Language::getLanguage(intval($cookie->id_lang));
        $iso = $language['iso_code'];
        $dateBetween = ModuleGraph::getDateBetween();
        $sales = self::getSales($dateBetween);
        $carts = self::getCarts($dateBetween);
        $records = self::getRecords($dateBetween);
        echo '
		<div style="float: left">';
        $this->displayCalendar();
        $this->displayMenu(false);
        $this->displayEngines();
        $this->displaySearch();
        echo '
		</div>
		<div style="float: left; margin-left: 40px;">
			<fieldset class="width3"><legend><img src="../img/admin/tab-stats.gif" /> ' . $this->l('Help') . '</legend>
				<p>' . $this->l('Use the calendar on the left to select the time period.') . '</p>
				<p>' . $this->l('All available statistic modules are displayed in the Navigation list beneath the calendar.') . '</p>
				<p>' . $this->l('In the Settings sub-tab, you can also customize the Stats tab to fit your needs and resources, change the graph rendering engine, and adjust the database settings.') . '</p>
			</fieldset>
			<br /><br />
			<fieldset class="width3"><legend><img src="../img/admin/___info-ca.gif" style="vertical-align: middle" /> ' . $this->l('Sales') . '</legend>
				<table>
					<tr><td style="font-weight: bold">' . $this->l('Total placed orders') . '</td><td style="padding-left: 20px">' . $sales['orders'] . '</td></tr>
					<tr><td style="font-weight: bold">' . $this->l('Total products sold') . '</td><td style="padding-left: 20px">' . $sales['products'] . '</td></tr>
				</table>
				<table cellspacing="0" cellpadding="0" class="table space">
					<tr>
						<th style="width: 150px"></th>
						<th style="width: 180px; text-align: center; font-weight: bold">' . $this->l('total paid with tax') . '</th>
						<th style="width: 220px; text-align: center; font-weight: bold">' . $this->l('total products not incl. tax') . '</th>
					</tr>
					<tr>
						<th style="font-weight: bold">' . $this->l('Sales turnover') . '</th>
						<td align="right">' . Tools::displayPrice($sales['ttc'], $currency) . '</td>
						<td align="right">' . Tools::displayPrice($sales['ht'], $currency) . '</td>
					</tr>
					<tr>
						<th style="font-weight: bold">' . $this->l('Largest order') . '</th>
						<td align="right">' . Tools::displayPrice($sales['maxttc'], $currency) . '</td>
						<td align="right">' . Tools::displayPrice($sales['maxht'], $currency) . '</td>
					</tr>
					<tr>
						<th style="font-weight: bold">' . $this->l('Smallest order') . '</th>
						<td align="right">' . Tools::displayPrice($sales['minttc'], $currency) . '</td>
						<td align="right">' . Tools::displayPrice($sales['minht'], $currency) . '</td>
					</tr>
				</table>
			</fieldset>
			<br /><br />
			<fieldset class="width3"><legend><img src="../img/admin/products.gif" style="vertical-align: middle" /> ' . $this->l('Carts') . '</legend>
				<table cellspacing="0" cellpadding="0" class="table">
					<tr>
						<th style="width: 150px"></th>
						<th style="width: 180px; text-align: center; font-weight: bold">' . $this->l('Products total all tax inc.') . '</th>
					</tr>
					<tr>
						<th style="font-weight: bold">' . $this->l('Average cart') . '</th>
						<td align="right">' . Tools::displayPrice($carts['average'], $currency) . '</td>
					</tr>
					<tr>
						<th style="font-weight: bold">' . $this->l('Largest cart') . '</th>
						<td align="right">' . Tools::displayPrice($carts['highest'], $currency) . '</td>
					</tr>
					<tr>
						<th style="font-weight: bold">' . $this->l('Smallest cart') . '</th>
						<td align="right">' . Tools::displayPrice($carts['lowest'], $currency) . '</td>
					</tr>
				</table>
			</fieldset>';
        if (strtolower($cookie->stats_granularity) != 'd' and $records and is_array($records)) {
            echo '
			<br /><br />
			<fieldset class="width3"><legend><img src="../img/admin/medal.png" style="vertical-align: middle" />' . $this->l('Records') . '</legend>
				<table cellspacing="0" cellpadding="0" class="table">
					<tr>
						<th style="width: 150px"></th>
						<th style="width: 100px; text-align: center; font-weight: bold">' . $this->l('date') . '</th>
						<th style="width: 120px; text-align: center; font-weight: bold">' . $this->l('with tax') . '</th>
						<th style="width: 180px; text-align: center; font-weight: bold">' . $this->l('only products not incl. tax') . '</th>
					</tr>';
            if (strtolower($cookie->stats_granularity) == 'y') {
                echo '
					<tr>
						<th style="font-weight: bold">' . $this->l('Best month') . '</th>
						<td align="right">' . $this->displayDate($records['bestmonth']['date'], $iso) . '</td>
						<td align="right">' . Tools::displayPrice($records['bestmonth']['totalttc'], $currency) . '</td>
						<td align="right">' . Tools::displayPrice($records['bestmonth']['totalht'], $currency) . '</td>
					</tr>
					<tr>
						<th style="font-weight: bold">' . $this->l('Worst month') . '</th>
						<td align="right">' . $this->displayDate($records['worstmonth']['date'], $iso) . '</td>
						<td align="right">' . Tools::displayPrice($records['worstmonth']['totalttc'], $currency) . '</td>
						<td align="right">' . Tools::displayPrice($records['worstmonth']['totalht'], $currency) . '</td>
					</tr>';
            }
            echo '
					<tr>
						<th style="font-weight: bold">' . $this->l('Best day') . '</th>
						<td align="right">' . $this->displayDate($records['bestday']['date'], $iso) . '</td>
						<td align="right">' . Tools::displayPrice($records['bestday']['totalttc'], $currency) . '</td>
						<td align="right">' . Tools::displayPrice($records['bestday']['totalht'], $currency) . '</td>
					</tr>
					<tr>
						<th style="font-weight: bold">' . $this->l('Worst day') . '</th>
						<td align="right">' . $this->displayDate($records['worstday']['date'], $iso) . '</td>
						<td align="right">' . Tools::displayPrice($records['worstday']['totalttc'], $currency) . '</td>
						<td align="right">' . Tools::displayPrice($records['worstday']['totalht'], $currency) . '</td>
					</tr>
				</table>
			</fieldset>';
        }
        echo '
		</div>
		<div class="clear"></div>';
    }
 public function postProcess()
 {
     global $currentIndex;
     if ($this->enableCalendar()) {
         $calendarTab = new AdminStats();
         $calendarTab->postProcess();
     }
     if (Tools::isSubmit('submitSettings')) {
         if ($this->tabAccess['edit'] === '1') {
             if (Configuration::updateValue('TRACKING_DIRECT_TRAFFIC', (int) Tools::getValue('tracking_dt'))) {
                 Tools::redirectAdmin($currentIndex . '&conf=4&token=' . Tools::getValue('token'));
             }
         }
     }
     if (ModuleGraph::getDateBetween() != Configuration::get('PS_REFERRERS_CACHE_LIKE') or Tools::isSubmit('submitRefreshCache')) {
         Referrer::refreshCache();
     }
     if (Tools::isSubmit('submitRefreshIndex')) {
         Referrer::refreshIndex();
     }
     return parent::postProcess();
 }