* @copyright 2007-2011 PrestaShop SA
* @version Release: $Revision: 1.4 $
* @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
* International Registered Trademark & Property of PrestaShop SA
*/
class AdminHome extends AdminTab
{
public function postProcess()
{
}
private function _displayOptimizationTips()
{
$rewrite = 0;
if (Configuration::get('PS_REWRITING_SETTINGS'))
{
$rewrite = 2;
if (!file_exists(dirname(__FILE__).'/../../.htaccess'))
$rewrite = 1;
else
{
$stat = stat(dirname(__FILE__).'/../../.htaccess');
if (strtotime(Db::getInstance()->getValue('SELECT date_upd FROM '._DB_PREFIX_.'configuration WHERE name = "PS_REWRITING_SETTINGS"')) > $stat['mtime'])
$rewrite = 0;
}
}
$htaccessAfterUpdate = 2;
$htaccessOptimized = (Configuration::get('PS_HTACCESS_CACHE_CONTROL') ? 2 : 0);
if (!file_exists(dirname(__FILE__).'/../.htaccess'))
{
if (Configuration::get('PS_HTACCESS_CACHE_CONTROL'))
$htaccessOptimized = 1;
}
else
{
$stat = stat(dirname(__FILE__).'/../.htaccess');
$dateUpdHtaccess = Db::getInstance()->getValue('SELECT date_upd FROM '._DB_PREFIX_.'configuration WHERE name = "PS_HTACCESS_CACHE_CONTROL"');
if (Configuration::get('PS_HTACCESS_CACHE_CONTROL') AND strtotime($dateUpdHtaccess) > $stat['mtime'])
$htaccessOptimized = 1;
$dateUpdate = Configuration::get('PS_LAST_SHOP_UPDATE');
if ($dateUpdate AND strtotime($dateUpdate) > $stat['mtime'])
$htaccessAfterUpdate = 0;
}
$smartyOptimized = 0;
if (!Configuration::get('PS_SMARTY_FORCE_COMPILE'))
++$smartyOptimized;
if (Configuration::get('PS_SMARTY_CACHE'))
++$smartyOptimized;
$cccOptimized = Configuration::get('PS_CSS_THEME_CACHE')
+ Configuration::get('PS_JS_THEME_CACHE')
+ Configuration::get('PS_HTML_THEME_COMPRESSION')
+ Configuration::get('PS_JS_HTML_THEME_COMPRESSION');
if ($cccOptimized == 4)
$cccOptimized = 2;
else
$cccOptimized = 1;
$shopEnabled = (Configuration::get('PS_SHOP_ENABLE') ? 2 : 1);
$lights = array(
0 => array('image'=>'error2.png','color'=>'#fbe8e8'),
1 => array('image'=>'warn2.png','color'=>'#fffac6'),
2 => array('image'=>'ok2.png','color'=>'#dffad3'));
if ($rewrite + $htaccessOptimized + $smartyOptimized + $cccOptimized + $shopEnabled + $htaccessAfterUpdate != 12)
echo '
'.$this->l('A good beginning...')
.'
':'href="?hideOptimizationTips" >
').'
';
echo '
';
echo '
';
}
public function display()
{
global $cookie;
$tab = get_class();
$protocol = (!empty($_SERVER['HTTPS']) AND strtolower($_SERVER['HTTPS']) != 'off')?'https':'http';
$isoDefault = Language::getIsoById(intval(Configuration::get('PS_LANG_DEFAULT')));
$isoUser = Language::getIsoById(intval($cookie->id_lang));
$isoCountry = Country::getIsoById(Configuration::get('PS_COUNTRY_DEFAULT'));
$currency = new Currency((int)(Configuration::get('PS_CURRENCY_DEFAULT')));
echo '
'.$this->l('Dashboard').'
';
if (@ini_get('allow_url_fopen') AND $update = checkPSVersion())
echo '
';
elseif (!@ini_get('allow_url_fopen'))
{
echo '
'.$this->l('Update notification unavailable').'
';
echo '
';
echo '
'.$this->l('To receive PrestaShop update warnings, you need to activate the allow_url_fopen command in your php.ini config file.').' ['.$this->l('more info').']
';
echo '
'.$this->l('If you don\'t know how to do that, please contact your host administrator !').'
';
}
echo '
';
if (!isset($cookie->show_screencast))
$cookie->show_screencast = true;
if ($cookie->show_screencast)
echo'
';
echo '
-
'.$this->l('Create a new category and organize your products.').'
-
'.$this->l('Fill up your catalog with new articles and attributes.').'
-
'.$this->l('Manage your activity with a thorough analysis of your e-shop.').'
-
'.$this->l('Add a new employee account and discharge a part of your duties of shop owner.').'
';
$result = Db::getInstance(_PS_USE_SQL_SLAVE_)->getRow('
SELECT SUM(o.`total_paid_real` / o.conversion_rate) as total_sales, COUNT(*) as total_orders
FROM `'._DB_PREFIX_.'orders` o
WHERE o.valid = 1
AND o.`invoice_date` BETWEEN \''.date('Y-m').'-01 00:00:00\' AND \''.date('Y-m').'-31 23:59:59\' ');
$result2 = Db::getInstance(_PS_USE_SQL_SLAVE_)->getRow('
SELECT COUNT(`id_customer`) AS total_registrations
FROM `'._DB_PREFIX_.'customer` c
WHERE c.`date_add` BETWEEN \''.date('Y-m').'-01 00:00:00\' AND \''.date('Y-m').'-31 23:59:59\'');
$result3 = Db::getInstance(_PS_USE_SQL_SLAVE_)->getRow('
SELECT SUM(pv.`counter`) AS total_viewed
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 dr.`time_start` BETWEEN \''.date('Y-m').'-01 00:00:00\' AND \''.date('Y-m').'-31 23:59:59\'
AND dr.`time_end` BETWEEN \''.date('Y-m').'-01 00:00:00\' AND \''.date('Y-m').'-31 23:59:59\'');
$results = array_merge($result, array_merge($result2, $result3));
echo '
|
'.$this->l('Sales').'
|
'.Tools::displayPrice($results['total_sales'], $currency).'
|
|
'.$this->l('Total registrations').'
|
'.(int)($results['total_registrations']).'
|
|
'.$this->l('Total orders').'
|
'.(int)($results['total_orders']).'
|
|
'.$this->l('Product pages viewed').'
|
'.(int)($results['total_viewed']).'
|
';
$all = Db::getInstance(_PS_USE_SQL_SLAVE_)->getValue('SELECT COUNT(*) FROM '._DB_PREFIX_.'customer_thread');
$unread = (int)Db::getInstance(_PS_USE_SQL_SLAVE_)->getValue('SELECT COUNT(*) FROM `'._DB_PREFIX_.'customer_thread` WHERE `status` = "open"');
$pending = (int)Db::getInstance(_PS_USE_SQL_SLAVE_)->getValue('SELECT COUNT(*) FROM `'._DB_PREFIX_.'customer_thread` WHERE `status` LIKE "%pending%"');
$close = $all - ($unread + $pending);
echo '
|
'.$this->l('Thread unread').'
|
'.$unread.'
|
|
'.$this->l('Thread pending').'
|
'.$pending.'
|
|
'.$this->l('Thread closed').'
|
'.$close.'
|
|
'.$this->l('Total thread').'
|
'.$all.'
|
'.$this->l('View more').' '.$this->l('Statistics').' / '.$this->l('Sales of the week').'
';
define('PS_BASE_URI', __PS_BASE_URI__);
$chart = new Chart();
$result = Db::getInstance(_PS_USE_SQL_SLAVE_)->ExecuteS('
SELECT total_paid / conversion_rate as total_converted, invoice_date
FROM '._DB_PREFIX_.'orders o
WHERE valid = 1
AND invoice_date BETWEEN \''.date('Y-m-d', strtotime('-7 DAYS', time())).' 00:00:00\' AND \''.date('Y-m-d H:i:s').'\'');
foreach ($result as $row)
$chart->getCurve(1)->setPoint(strtotime($row['invoice_date']), $row['total_converted']);
$chart->setSize(580, 170);
$chart->setTimeMode(strtotime('-7 DAYS', time()), time(), 'd');
$chart->getCurve(1)->setLabel($this->l('Sales +Tx').' ('.strtoupper($currency->iso_code).')');
$chart->display();
echo '
| '.$this->l('ID').' |
'.$this->l('Customer Name').' |
'.$this->l('Status').' |
'.$this->l('Total').' |
'.$this->l('Action').' |
';
$orders = Order::getOrdersWithInformations(10);
$i = 0;
foreach ($orders AS $order)
{
$currency = Currency::getCurrency((int)$order['id_currency']);
echo '
| '.(int)$order['id_order'].' |
'.Tools::htmlentitiesUTF8($order['firstname']).' '.Tools::htmlentitiesUTF8($order['lastname']).' |
'.Tools::htmlentitiesUTF8($order['state_name']).' |
'.Tools::displayPrice((float)$order['total_paid'], $currency).' |
|
';
$i++;
}
echo '
';
echo '
';
$context = stream_context_create(array('http' => array('method'=>"GET", 'timeout' => 5)));
$content = @file_get_contents('https://www.prestashop.com/partner/preactivation/preactivation-block.php?version=1.0&shop='.urlencode(Configuration::get('PS_SHOP_NAME')).'&protocol='.$protocol.'&url='.urlencode($_SERVER['HTTP_HOST']).'&iso_country='.$isoCountry.'&iso_lang='.Tools::strtolower($isoUser).'&id_lang='.(int)$cookie->id_lang.'&email='.urlencode(Configuration::get('PS_SHOP_EMAIL')).'&security='.md5(Configuration::get('PS_SHOP_EMAIL')._COOKIE_IV_), false, $context);
$content = explode('|', $content);
if ($content[0] == 'OK')
{
echo $content[2];
$content[1] = explode('#%#', $content[1]);
foreach ($content[1] as $partnerPopUp)
if ($partnerPopUp)
{
$partnerPopUp = explode('%%', $partnerPopUp);
if (!Configuration::get('PS_PREACTIVATION_'.strtoupper($partnerPopUp[0])))
{
echo $partnerPopUp[1];
Configuration::updateValue('PS_PREACTIVATION_'.strtoupper($partnerPopUp[0]), 'TRUE');
}
}
}
if (Tools::isSubmit('hideOptimizationTips'))
Configuration::updateValue('PS_HIDE_OPTIMIZATION_TIPS', 1);
$this->_displayOptimizationTips();
$context = stream_context_create(array('http' => array('method'=>"GET", 'timeout' => 5)));
$content = @file_get_contents('https://www.prestashop.com/partner/prestashop/prestashop-link.php?iso_country='.$isoCountry.'&iso_lang='.Tools::strtolower($isoUser).'&id_lang='.(int)$cookie->id_lang, false, $context);
$content = explode('|', $content);
if ($content[0] == 'OK')
echo $content[1];
else
echo '
'.$this->l('PrestaShop Link').'
';
if (@fsockopen('www.prestashop.com', 80, $errno, $errst, 3))
echo '
';
$context = stream_context_create(array('http' => array('method'=>"GET", 'timeout' => 5)));
$content = @file_get_contents('https://www.prestashop.com/partner/paypal/paypal-tips.php?protocol='.$protocol.'&iso_country='.$isoCountry.'&iso_lang='.Tools::strtolower($isoUser).'&id_lang='.(int)$cookie->id_lang, false, $context);
$content = explode('|', $content);
if ($content[0] == 'OK')
echo $content[1];
echo '
';
echo Module::hookExec('backOfficeHome');
}
}