[+] BO : New AdminController system, including smarty backoffice, thanks to Raphael and Thomas

This commit is contained in:
mMarinetti
2011-09-23 15:01:49 +00:00
parent 230ed9d5ee
commit 6191e868f1
13 changed files with 833 additions and 220 deletions
+147 -16
View File
@@ -224,14 +224,6 @@ function translate($string)
return str_replace('"', '"', stripslashes($str));
}
function recursiveTab($id_tab, $tabs)
{
$adminTab = Tab::getTab((int)Context::getContext()->language->id, $id_tab);
$tabs[]= $adminTab;
if ($adminTab['id_parent'] > 0)
$tabs = recursiveTab($adminTab['id_parent'], $tabs);
return $tabs;
}
/**
* Returns a new Tab object
@@ -244,22 +236,21 @@ function checkingTab($tab)
$tab = trim($tab);
if (!Validate::isTabName($tab))
return false;
$row = Db::getInstance(_PS_USE_SQL_SLAVE_)->getRow('SELECT id_tab, module FROM `'._DB_PREFIX_.'tab` WHERE class_name = \''.pSQL($tab).'\'');
if (!$row['id_tab'])
{
if (isset(AdminTab::$tabParenting[$tab]))
Tools::redirectAdmin('?tab='.AdminTab::$tabParenting[$tab].'&token='.Tools::getAdminTokenLite(AdminTab::$tabParenting[$tab]));
echo Tools::displayError('Tab cannot be found.');
echo sprintf(Tools::displayError('Tab %s cannot be found.'),$tab);
return false;
}
if ($row['module'] AND file_exists(_PS_MODULE_DIR_.'/'.$row['module'].'/'.$tab.'.php'))
include_once(_PS_MODULE_DIR_.'/'.$row['module'].'/'.$tab.'.php');
elseif (file_exists(_PS_ADMIN_DIR_.'/tabs/'.$tab.'.php'))
include_once(_PS_ADMIN_DIR_.'/tabs/'.$tab.'.php');
if ($row['module'] AND file_exists(_PS_MODULE_DIR_.'/'.$row['module'].'/'.Dispatcher::$controllers[$tab].'.php'))
include_once(_PS_MODULE_DIR_.'/'.$row['module'].'/'.Dispatcher::$controllers[$tab].'.php');
elseif (file_exists(_PS_ADMIN_DIR_.'/tabs/'.Dispatcher::$controllers[$tab].'.php'))
include_once(_PS_ADMIN_DIR_.'/tabs/'.Dispatcher::$controllers[$tab].'.php');
if (!class_exists($tab, false) OR !$row['id_tab'])
{
echo Tools::displayError('Tab file cannot be found.');
echo sprintf(Tools::displayError('Tab file %s cannot be found.'),$tab);
return false;
}
$adminObj = new $tab;
@@ -424,4 +415,144 @@ function generateShopList()
$html .= '</select>';
return $html;
}
}
/**
* for retrocompatibility with old AdminTab, old index.php
*
* @return void
*/
function runAdminTab()
{
require_once(_PS_ADMIN_DIR_.'/../config/config.inc.php');
require_once(_PS_ADMIN_DIR_.'/functions.php');
require_once(_PS_ADMIN_DIR_.'/init.php');
if (empty($tab) and !sizeof($_POST))
{
$tab = 'AdminHome';
$_POST['tab'] = 'AdminHome';
$_POST['token'] = Tools::getAdminTokenLite($tab);
}
// $tab = $_REQUEST['tab'];
if ($adminObj = checkingTab($tab))
{
// init is different for new tabs (AdminController) and old tabs (AdminTab)
if ($adminObj instanceof AdminController)
{
$adminObj->path = dirname($_SERVER["PHP_SELF"]);
$adminObj->run();
}
else
{
require_once(_PS_ADMIN_DIR_.'/header.inc.php');
$isoUser = Context::getContext()->language->id;
$tabs = array();
$tabs = Tab::recursiveTab($adminObj->id, $tabs);
$tabs = array_reverse($tabs);
$bread = '';
foreach ($tabs AS $key => $item)
$bread .= ' <img src="../img/admin/separator_breadcrum.png" style="margin-right:5px" alt="&gt;" />
'.((sizeof($tabs) - 1 > $key)
? '<a href="?tab='.$item['class_name'].'&token='.Tools::getAdminToken($item['class_name'].intval($item['id_tab']).(int)Context::getContext()->employee->id).'">'
: '').'
'.$item['name'].((sizeof($tabs) - 1 > $key) ? '</a>' : '');
// @TODO : a way to desactivate this feature
echo'<script type="text/javascript">
$(function() {
$.ajax({
type: \'POST\',
url: \'ajax.php\',
data: \'helpAccess=1&item='.$item['class_name'].'&isoUser='.$isoUser.'&country='.Context::getContext()->country->iso_code.'&version='._PS_VERSION_.'\',
async : true,
success: function(msg) {
$("#help-button").html(msg);
$("#help-button").fadeIn("slow");
}
});
});</script>';
echo '<div class="path_bar">
<div id="help-button" class="floatr" style="display: none; font-family: Verdana; font-size: 10px; margin-right: 4px; margin-top: 4px;">
</div>
<a href="?token='.Tools::getAdminToken($tab.intval(Tab::getIdFromClassName($tab)).(int)Context::getContext()->employee->id).'">'.translate('Back Office').'</a>
'.$bread;
echo '
</div>';
if (Shop::isMultiShopActivated() && Context::shop() != Shop::CONTEXT_ALL)
{
echo '<div class="multishop_info">';
if (Context::shop() == Shop::CONTEXT_GROUP)
printf(translate('You are configuring your store for group shop %s'), '<b>'.Context::getContext()->shop->getGroup()->name.'</b>');
elseif (Context::shop() == Shop::CONTEXT_SHOP)
printf(translate('You are configuring your store for shop %s'), '<b>'.Context::getContext()->shop->name.'</b>');
echo '</div>';
}
if (Validate::isLoadedObject($adminObj))
{
if ($adminObj->checkToken())
{
/* Filter memorization */
if (isset($_POST) AND !empty($_POST) AND isset($adminObj->table))
foreach ($_POST AS $key => $value)
if (is_array($adminObj->table))
{
foreach ($adminObj->table AS $table)
if (strncmp($key, $table.'Filter_', 7) === 0 OR strncmp($key, 'submitFilter', 12) === 0)
$cookie->$key = !is_array($value) ? $value : serialize($value);
}
elseif (strncmp($key, $adminObj->table.'Filter_', 7) === 0 OR strncmp($key, 'submitFilter', 12) === 0)
$cookie->$key = !is_array($value) ? $value : serialize($value);
if (isset($_GET) AND !empty($_GET) AND isset($adminObj->table))
foreach ($_GET AS $key => $value)
if (is_array($adminObj->table))
{
foreach ($adminObj->table AS $table)
if (strncmp($key, $table.'OrderBy', 7) === 0 OR strncmp($key, $table.'Orderway', 8) === 0)
$cookie->$key = $value;
}
elseif (strncmp($key, $adminObj->table.'OrderBy', 7) === 0 OR strncmp($key, $adminObj->table.'Orderway', 12) === 0)
$cookie->$key = $value;
$adminObj->displayConf();
$adminObj->postProcess();
$adminObj->displayErrors();
$adminObj->display();
}
else
{
// If this is an XSS attempt, then we should only display a simple, secure page
ob_clean();
// ${1} in the replacement string of the regexp is required, because the token may begin with a number and mix up with it (e.g. $17)
$url = preg_replace('/([&?]token=)[^&]*(&.*)?$/', '${1}'.$adminObj->token.'$2', $_SERVER['REQUEST_URI']);
if (false === strpos($url, '?token=') AND false === strpos($url, '&token='))
$url .= '&token='.$adminObj->token;
$message = translate('Invalid security token');
echo '<html><head><title>'.$message.'</title></head><body style="font-family:Arial,Verdana,Helvetica,sans-serif;background-color:#EC8686">
<div style="background-color:#FAE2E3;border:1px solid #000000;color:#383838;font-weight:700;line-height:20px;margin:0 0 10px;padding:10px 15px;width:500px">
<img src="../img/admin/error2.png" style="margin:-4px 5px 0 0;vertical-align:middle">
'.$message.'
</div>';
echo '<a href="'.htmlentities($url).'" method="get" style="float:left;margin:10px">
<input type="button" value="'.Tools::htmlentitiesUTF8(translate('I understand the risks and I really want to display this page')).'" style="height:30px;margin-top:5px" />
</a>
<a href="index.php" method="get" style="float:left;margin:10px">
<input type="button" value="'.Tools::htmlentitiesUTF8(translate('Take me out of here!')).'" style="height:40px" />
</a>
</body></html>';
die;
}
}
include(_PS_ADMIN_DIR_.'/footer.inc.php');
}
}
}
+14 -12
View File
@@ -75,7 +75,7 @@ echo '
html = "";
nb_notifs = 0;
$.each(json.order, function(property, value) {
html += "<li>'.translate('A new order has been made on your shop.').'<br />'.translate('Order number : ').'<strong>#" + parseInt(value.id_order) + "</strong><br />'.translate('Total : ').'<strong>" + value.total_paid_real + "</strong><br />'.translate('From : ').'<strong>" + value.customer_name + "</strong><br /><a href=\"index.php?tab=AdminOrders&token='.Tools::getAdminTokenLite('AdminOrders').'&vieworder&id_order=" + parseInt(value.id_order) + "\">'.translate('Click here to see that order').'</a></li>";
html += "<li>'.translate('A new order has been made on your shop.').'<br />'.translate('Order number : ').'<strong>#" + parseInt(value.id_order) + "</strong><br />'.translate('Total : ').'<strong>" + value.total_paid_real + "</strong><br />'.translate('From : ').'<strong>" + value.customer_name + "</strong><br /><a href=\"index.php?controller=AdminOrders&token='.Tools::getAdminTokenLite('AdminOrders').'&vieworder&id_order=" + parseInt(value.id_order) + "\">'.translate('Click here to see that order').'</a></li>";
});
if (html != "")
{
@@ -94,7 +94,7 @@ echo '
html = "";
nb_notifs = 0;
$.each(json.customer, function(property, value) {
html += "<li>'.translate('A new customer registered on your shop.').'<br />'.translate('Customer name : ').'<strong>" + value.customer_name + "</strong><br /><a href=\"index.php?tab=AdminCustomers&token='.Tools::getAdminTokenLite('AdminCustomers').'&viewcustomer&id_customer=" + parseInt(value.id_customer) + "\">'.translate('Click here to see that customer').'</a></li>";
html += "<li>'.translate('A new customer registered on your shop.').'<br />'.translate('Customer name : ').'<strong>" + value.customer_name + "</strong><br /><a href=\"index.php?controller=AdminCustomers&token='.Tools::getAdminTokenLite('AdminCustomers').'&viewcustomer&id_customer=" + parseInt(value.id_customer) + "\">'.translate('Click here to see that customer').'</a></li>";
});
if (html != "")
{
@@ -113,7 +113,7 @@ echo '
html = "";
nb_notifs = 0;
$.each(json.message, function(property, value) {
html += "<li>'.translate('A new message posted on your shop.').'<br />'.translate('From : ').'<strong>" + value.customer_name + "</strong><br />'.translate('Excerpt : ').'<strong>" + value.message_customer + "</strong><br /><a href=\"index.php?tab=AdminOrders&token='.Tools::getAdminTokenLite('AdminOrders').'&vieworder&id_order=" + parseInt(value.id_order) + "\">'.translate('Click here to see that message').'</a></li>";
html += "<li>'.translate('A new message posted on your shop.').'<br />'.translate('From : ').'<strong>" + value.customer_name + "</strong><br />'.translate('Excerpt : ').'<strong>" + value.message_customer + "</strong><br /><a href=\"index.php?controller=AdminOrders&token='.Tools::getAdminTokenLite('AdminOrders').'&vieworder&id_order=" + parseInt(value.id_order) + "\">'.translate('Click here to see that message').'</a></li>";
});
if (html != "")
{
@@ -192,7 +192,7 @@ echo ' var html = "";
<h3>'.translate('Last orders').'</h3>
<p class="no_notifs">'.translate('No new orders has been made on your shop').'</p>
<ul id="list_orders_notif"></ul>
<p><a href="index.php?tab=AdminOrders&token='.Tools::getAdminTokenLite('AdminOrders').'">'.translate('Show all orders').'</a></p>
<p><a href="index.php?controller=AdminOrders&token='.Tools::getAdminTokenLite('AdminOrders').'">'.translate('Show all orders').'</a></p>
</div>
</div>';
}
@@ -203,7 +203,7 @@ echo ' var html = "";
<h3>'.translate('Last customers').'</h3>
<p class="no_notifs">'.translate('No new customers registered on your shop').'</p>
<ul id="list_customers_notif"></ul>
<p><a href="index.php?tab=AdminCustomers&token='.Tools::getAdminTokenLite('AdminCustomers').'">'.translate('Show all customers').'</a></p>
<p><a href="index.php?controller=AdminCustomers&token='.Tools::getAdminTokenLite('AdminCustomers').'">'.translate('Show all customers').'</a></p>
</div>
</div>';
}
@@ -214,7 +214,7 @@ echo ' var html = "";
<h3>'.translate('Last messages').'</h3>
<p class="no_notifs">'.translate('No new messages posted on your shop').'</p>
<ul id="list_messages_notif"></ul>
<p><a href="index.php?tab=AdminMessages&token='.Tools::getAdminTokenLite('AdminMessages').'">'.translate('Show all messages').'</a></p>
<p><a href="index.php?controller=AdminMessages&token='.Tools::getAdminTokenLite('AdminMessages').'">'.translate('Show all messages').'</a></p>
</div>
</div>';
}
@@ -223,10 +223,10 @@ echo ' var html = "";
[ <a href="index.php?logout" id="header_logout"><span>'.translate('logout').'</span></a> ]';
if (Context::getContext()->shop->getBaseURL())
echo '- <a href="'.Context::getContext()->shop->getBaseURL().'" id="header_foaccess" target="_blank" title="'.translate('View my shop').'"><span>'.translate('View my shop').'</span></a>';
echo ' - <a href="index.php?tab=AdminEmployees&id_employee='.(int)Context::getContext()->employee->id.'&updateemployee&token='.Tools::getAdminTokenLite('AdminEmployees').'" style="font-size: 10px;"><img src="../img/admin/employee.gif" alt="" /> '.translate('My preferences').'</a>
echo ' - <a href="index.php?controller=AdminEmployees&id_employee='.(int)Context::getContext()->employee->id.'&updateemployee&token='.Tools::getAdminTokenLite('AdminEmployees').'" style="font-size: 10px;"><img src="../img/admin/employee.gif" alt="" /> '.translate('My preferences').'</a>
</span></div>
<div id="header_search">
<form method="post" action="index.php?tab=AdminSearch&token='.Tools::getAdminTokenLite('AdminSearch').'">
<form method="post" action="index.php?controller=AdminSearch&token='.Tools::getAdminTokenLite('AdminSearch').'">
<input type="text" name="bo_query" id="bo_query"
value="'.Tools::safeOutput(Tools::stripslashes(Tools::getValue('bo_query'))).'"
/>
@@ -256,7 +256,7 @@ echo ' var html = "";
<option value="0">'.translate('Quick Access').'</option>';
foreach (QuickAccess::getQuickAccesses(Context::getContext()->language->id) AS $quick)
{
preg_match('/tab=(.+)(&.+)?$/', $quick['link'], $adminTab);
preg_match('/controller=(.+)(&.+)?$/', $quick['link'], $adminTab);
if (isset($adminTab[1]))
{
if (strpos($adminTab[1], '&'))
@@ -282,15 +282,16 @@ $id_parent_tab_current = (int)(Tab::getCurrentParentId());
$tabs = Tab::getTabs(Context::getContext()->language->id, 0);
$echoLis = '';
$mainsubtablist = '';
foreach ($tabs AS $t)
if (checkTabRights($t['id_tab']) === true)
{
$img = (Tools::file_exists_cache(_PS_ADMIN_DIR_.'/themes/'.Context::getContext()->employee->bo_theme.'/img/t/'.$t['class_name'].'.gif') ? 'themes/'.Context::getContext()->employee->bo_theme.'/img/' : _PS_IMG_).'t/'.$t['class_name'].'.gif';
if (trim($t['module']) != '')
$img = _MODULE_DIR_.$t['module'].'/'.$t['class_name'].'.gif';
$current = (($t['class_name'] == $tab) OR ($id_parent_tab_current == $t['id_tab']));
$current = ((strtolower($t['class_name']) == $tab) OR ($id_parent_tab_current == $t['id_tab']));
echo '<li class="submenu_size '.($current ? 'active' : '').'" id="maintab'.$t['id_tab'].'">
<a href="index.php?tab='.$t['class_name'].'&token='.Tools::getAdminToken($t['class_name'].(int)($t['id_tab']).(int)Context::getContext()->employee->id).'">
<a href="index.php?controller='.$t['class_name'].'&token='.Tools::getAdminToken($t['class_name'].(int)($t['id_tab']).(int)Context::getContext()->employee->id).'">
<img src="'.$img.'" alt="" /> '.$t['name'].'
</a>
</li>';
@@ -298,7 +299,8 @@ foreach ($tabs AS $t)
$subTabs = Tab::getTabs(Context::getContext()->language->id, (int)$t['id_tab']);
foreach ($subTabs AS $t2)
if (checkTabRights($t2['id_tab']) === true)
$echoLi .= '<li><a href="index.php?tab='.$t2['class_name'].'&token='.Tools::getAdminTokenLite($t2['class_name']).'">'.$t2['name'].'</a></li>';
$echoLi .= '<li><a href="index.php?controller='.$t2['class_name'].'&token='.Tools::getAdminTokenLite($t2['class_name']).'">'.$t2['name'].'</a></li>';
if ($current)
$mainsubtablist = $echoLi;
$echoLis .= '<div id="tab'.(int)($t['id_tab']).'_subtabs" style="display:none">'.$echoLi.'</div>';
+2 -129
View File
@@ -26,133 +26,6 @@
*/
define('_PS_ADMIN_DIR_', getcwd());
include(_PS_ADMIN_DIR_.'/../config/config.inc.php');
include(_PS_ADMIN_DIR_.'/functions.php');
include(_PS_ADMIN_DIR_.'/init.php');
if (empty($tab) and !sizeof($_POST))
{
$tab = 'AdminHome';
$_POST['tab'] = 'AdminHome';
$_POST['token'] = Tools::getAdminTokenLite($tab);
}
if ($adminObj = checkingTab($tab))
{
// init is different for new tabs (AdminController) and old tabs (AdminTab)
if ($adminObj instanceof AdminController)
{
$adminObj->path = dirname($_SERVER["PHP_SELF"]);
$adminObj->run();
}
else
{
include(_PS_ADMIN_DIR_.'/header.inc.php');
$isoUser = Context::getContext()->language->id;
$tabs = array();
$tabs = recursiveTab($adminObj->id, $tabs);
$tabs = array_reverse($tabs);
$bread = '';
foreach ($tabs AS $key => $item)
$bread .= ' <img src="../img/admin/separator_breadcrum.png" style="margin-right:5px" alt="&gt;" />
'.((sizeof($tabs) - 1 > $key)
? '<a href="?tab='.$item['class_name'].'&token='.Tools::getAdminToken($item['class_name'].intval($item['id_tab']).(int)Context::getContext()->employee->id).'">'
: '').'
'.$item['name'].((sizeof($tabs) - 1 > $key) ? '</a>' : '');
// @TODO : a way to desactivate this feature
echo'<script type="text/javascript">
$(function() {
$.ajax({
type: \'POST\',
url: \'ajax.php\',
data: \'helpAccess=1&item='.$item['class_name'].'&isoUser='.$isoUser.'&country='.Context::getContext()->country->iso_code.'&version='._PS_VERSION_.'\',
async : true,
success: function(msg) {
$("#help-button").html(msg);
$("#help-button").fadeIn("slow");
}
});
});</script>';
echo '<div class="path_bar">
<div id="help-button" class="floatr" style="display: none; font-family: Verdana; font-size: 10px; margin-right: 4px; margin-top: 4px;">
</div>
<a href="?token='.Tools::getAdminToken($tab.intval(Tab::getIdFromClassName($tab)).(int)Context::getContext()->employee->id).'">'.translate('Back Office').'</a>
'.$bread;
echo '
</div>';
if (Shop::isMultiShopActivated() && Context::shop() != Shop::CONTEXT_ALL)
{
echo '<div class="multishop_info">';
if (Context::shop() == Shop::CONTEXT_GROUP)
printf(translate('You are configuring your store for group shop %s'), '<b>'.Context::getContext()->shop->getGroup()->name.'</b>');
elseif (Context::shop() == Shop::CONTEXT_SHOP)
printf(translate('You are configuring your store for shop %s'), '<b>'.Context::getContext()->shop->name.'</b>');
echo '</div>';
}
if (Validate::isLoadedObject($adminObj))
{
if ($adminObj->checkToken())
{
/* Filter memorization */
if (isset($_POST) AND !empty($_POST) AND isset($adminObj->table))
foreach ($_POST AS $key => $value)
if (is_array($adminObj->table))
{
foreach ($adminObj->table AS $table)
if (strncmp($key, $table.'Filter_', 7) === 0 OR strncmp($key, 'submitFilter', 12) === 0)
$cookie->$key = !is_array($value) ? $value : serialize($value);
}
elseif (strncmp($key, $adminObj->table.'Filter_', 7) === 0 OR strncmp($key, 'submitFilter', 12) === 0)
$cookie->$key = !is_array($value) ? $value : serialize($value);
if (isset($_GET) AND !empty($_GET) AND isset($adminObj->table))
foreach ($_GET AS $key => $value)
if (is_array($adminObj->table))
{
foreach ($adminObj->table AS $table)
if (strncmp($key, $table.'OrderBy', 7) === 0 OR strncmp($key, $table.'Orderway', 8) === 0)
$cookie->$key = $value;
}
elseif (strncmp($key, $adminObj->table.'OrderBy', 7) === 0 OR strncmp($key, $adminObj->table.'Orderway', 12) === 0)
$cookie->$key = $value;
$adminObj->displayConf();
$adminObj->postProcess();
$adminObj->displayErrors();
$adminObj->display();
}
else
{
// If this is an XSS attempt, then we should only display a simple, secure page
ob_clean();
// ${1} in the replacement string of the regexp is required, because the token may begin with a number and mix up with it (e.g. $17)
$url = preg_replace('/([&?]token=)[^&]*(&.*)?$/', '${1}'.$adminObj->token.'$2', $_SERVER['REQUEST_URI']);
if (false === strpos($url, '?token=') AND false === strpos($url, '&token='))
$url .= '&token='.$adminObj->token;
$message = translate('Invalid security token');
echo '<html><head><title>'.$message.'</title></head><body style="font-family:Arial,Verdana,Helvetica,sans-serif;background-color:#EC8686">
<div style="background-color:#FAE2E3;border:1px solid #000000;color:#383838;font-weight:700;line-height:20px;margin:0 0 10px;padding:10px 15px;width:500px">
<img src="../img/admin/error2.png" style="margin:-4px 5px 0 0;vertical-align:middle">
'.$message.'
</div>';
echo '<a href="'.htmlentities($url).'" method="get" style="float:left;margin:10px">
<input type="button" value="'.Tools::htmlentitiesUTF8(translate('I understand the risks and I really want to display this page')).'" style="height:30px;margin-top:5px" />
</a>
<a href="index.php" method="get" style="float:left;margin:10px">
<input type="button" value="'.Tools::htmlentitiesUTF8(translate('Take me out of here!')).'" style="height:40px" />
</a>
</body></html>';
die;
}
}
include(_PS_ADMIN_DIR_.'/footer.inc.php');
}
}
require(dirname(__FILE__).'/../config/config.inc.php');
Dispatcher::getInstance()->dispatch();
+21 -3
View File
@@ -28,6 +28,20 @@
ob_start();
$timerStart = microtime(true);
{
if (!isset($_GET['controller']) && isset($_GET['tab'])){
$_GET['controller'] = $_GET['tab'];
}
if (!isset($_POST['controller']) && isset($_POST['tab']))
$_POST['controller'] = $_POST['tab'];
if (!isset($_REQUEST['controller']) && isset($_REQUEST['tab']))
$_REQUEST['controller'] = $_REQUEST['tab'];
}
// $_GET['tab'] = $_GET['controller'];
// $_POST['tab'] = $_POST['controller'];
// $_REQUEST['tab'] = $_REQUEST['controller'];
$context = Context::getContext();
if (isset($_GET['logout']))
$context->employee->logout();
@@ -38,6 +52,11 @@ if (!isset($context->employee) || !$context->employee->isLoggedBack())
// Set current index
$currentIndex = $_SERVER['SCRIPT_NAME'].(($tab = Tools::getValue('tab')) ? '?tab='.$tab : '');
if (empty($tab))
{
$currentIndex = $_SERVER['SCRIPT_NAME'].(($controller = Tools::getValue('controller')) ? '?controller='.$controller: '');
$tab = $controller;
}
if ($back = Tools::getValue('back'))
$currentIndex .= '&back='.urlencode($back);
AdminTab::$currentIndex = $currentIndex;
@@ -56,7 +75,7 @@ define('_PS_BASE_URL_', Tools::getShopDomain(true));
define('_PS_BASE_URL_SSL_', Tools::getShopDomainSsl(true));
$path = dirname(__FILE__).'/themes/';
if (empty($context->employee->bo_theme) OR !file_exists($path.$employee->bo_theme.'/admin.css'))
if (empty($context->employee->bo_theme) OR !file_exists($path.$context->employee->bo_theme.'/admin.css'))
{
if (file_exists($path.'oldschool/admin.css'))
$context->employee->bo_theme = 'oldschool';
@@ -84,7 +103,6 @@ if (Shop::isMultiShopActivated() && Tools::getValue('setShopContext') !== false)
}
$context->currency = new Currency(Configuration::get('PS_CURRENCY_DEFAULT'));
$context->country = $defaultCountry;
$shopID = '';
if ($context->cookie->shopContext)
@@ -93,4 +111,4 @@ if ($context->cookie->shopContext)
if (count($split) == 2 && $split[0] == 's')
$shopID = (int)$split[1];
}
$context->shop = new Shop($shopID);
$context->shop = new Shop($shopID);
+12 -10
View File
@@ -23,7 +23,6 @@
* @license http://opensource.org/licenses/afl-3.0.php Academic Free License (AFL 3.0)
* International Registered Trademark & Property of PrestaShop SA
*}
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="{$iso}" lang="{$iso}">
<head>
@@ -112,7 +111,7 @@
<h3>{l s='Last orders'}</h3>
<p class="no_notifs">{l s='No new orders has been made on your shop'}</p>
<ul id="list_orders_notif"></ul>
<p><a href="index.php?tab=AdminOrders&token={$token_admin_orders}">{l s='Show all orders'}</a></p>
<p><a href="index.php?controller=AdminOrders&token={$token_admin_orders}">{l s='Show all orders'}</a></p>
</div>
</div>
{/if}
@@ -125,7 +124,7 @@
<h3>{l s='Last customers'}</h3>
<p class="no_notifs">{l s='No new customers registered on your shop'}</p>
<ul id="list_customers_notif"></ul>
<p><a href="index.php?tab=AdminCustomers&token={$token_admin_customers}">{l s='Show all customers'}</a></p>
<p><a href="index.php?controller=AdminCustomers&token={$token_admin_customers}">{l s='Show all customers'}</a></p>
</div>
</div>
{/if}
@@ -138,7 +137,7 @@
<h3>{l s='Last messages'}</h3>
<p class="no_notifs">{l s='No new messages posted on your shop'}</p>
<ul id="list_messages_notif"></ul>
<p><a href="index.php?tab=AdminMessages&token={$token_admin_messages}">{l s='Show all messages'}</a></p>
<p><a href="index.php?controller=AdminMessages&token={$token_admin_messages}">{l s='Show all messages'}</a></p>
</div>
</div>
{/if}
@@ -151,10 +150,10 @@
{if {$base_url}}
- <a href="{$base_url}" id="header_foaccess" target="_blank" title="{l s='View my shop'}"><span>{l s='View my shop'}</span></a>
{/if}
- <a href="index.php?tab=AdminEmployees&id_employee={$employee->id}&updateemployee&token={$token_admin_employees}" style="font-size: 10px;"><img src="../img/admin/employee.gif" alt="" /> {l s='My preferences'}</a>
- <a href="index.php?controller=AdminEmployees&id_employee={$employee->id}&updateemployee&token={$token_admin_employees}" style="font-size: 10px;"><img src="../img/admin/employee.gif" alt="" /> {l s='My preferences'}</a>
</span></div>
<div id="header_search">
<form method="post" action="index.php?tab=AdminSearch&token={$token_admin_search}">
<form method="post" action="index.php?controller=AdminSearch&token={$token_admin_search}">
<input type="text" name="bo_query" id="bo_query" value="{$bo_query}" />
<select name="bo_search_type" id="bo_search_type">
<option value="0">{l s='everywhere'}</option>
@@ -197,7 +196,7 @@
{/if}
{foreach $tabs AS $t}
<li class="submenu_size {if $t.current}active{/if}" id="maintab{$t.id_tab}">
<a href="index.php?tab={$t.class_name}&token={$t.token}">
<a href="index.php?controller={$t.class_name}&token={$t.token}">
<img src="{$t.img}" alt="" /> {$t.name}
</a>
</li>
@@ -206,7 +205,7 @@
{foreach $tabs AS $t}
<div id="tab{$t.id_tab}_subtabs" style="display:none">
{foreach $t.sub_tabs AS $t2}
<li><a href="index.php?tab={$t2.class_name}&token={$t2.token}">{$t2.name}</a></li>
<li><a href="index.php?controller={$t2.class_name}&token={$t2.token}">{$t2.name}</a></li>
{/foreach}
{if $t.current}
{assign var='mainsubtab' value=$t}
@@ -232,7 +231,7 @@
<ul id="submenu" {if isset($mainsubtab)}class="withLeftBorder clearfix"{/if}>
{if isset($mainsubtab)}
{foreach $mainsubtab.sub_tabs AS $t}
<li><a href="index.php?tab={$t.class_name}&token={$t.token}">{$t.name}</a></li>
<li><a href="index.php?controller={$t.class_name}&token={$t.token}">{$t.name}</a></li>
{/foreach}
{/if}
</ul>
@@ -244,16 +243,19 @@
</div>
{/if}
{* We should display breadcrumb only if needed *}
{if count($tabs_breadcrumb)>1}
<div class="path_bar">
<div id="help-button" class="floatr" style="display: none; font-family: Verdana; font-size: 10px; margin-right: 4px; margin-top: 4px;"></div>
<a href="?token={$home_token}">{l s='Back Office'}</a>
{foreach $tabs_breadcrumb AS $item}
<img src="../img/admin/separator_breadcrum.png" style="margin-right:5px" alt="&gt;" />
{if isset($item.token)}<a href="?tab={$item.class_name}&token={$item.token}">{/if}
{if isset($item.token)}<a href="?controller={$item.class_name}&token={$item.token}">{/if}
{$item.name}
{if isset($item.token)}</a>{/if}
{/foreach}
</div>
{/if}
{if $is_multishop}
<div class="multishop_info">
{if $shop_context == 'group'}
+48 -1
View File
@@ -25,5 +25,52 @@
*}
{include file='header.tpl'}
{if count($warnings)}
<script type="text/javascript">
$(document).ready(function() {
$('#linkSeeMore').unbind('click').click(function(){
$('#seeMore').show('slow');
$(this).hide();
$('#linkHide').show();
return false;
});
$('#linkHide').unbind('click').click(function(){
$('#seeMore').hide('slow');
$(this).hide();
$('#linkSeeMore').show();
return false;
});
$('#hideWarn').unbind('click').click(function(){
$('.warn').hide('slow', function (){
$('.warn').remove();
});
return false;
});
});
</script>
<div class="warn">
<span style="float:right">
<a id="hideWarn" href=""><img alt="X" src="../img/admin/close.png" /></a>
</span>
<img src="../img/admin/warn2.png" />
{if count($warnings) > 1}
{l s='There are'} {count($warnings)} {l s='warnings'}
{else}
{l s='There is'} {count($warnings)} {l s='warning'}
{/if}
<span style="margin-left:20px;" id="labelSeeMore">
<a id="linkSeeMore" href="#" style="text-decoration:underline">{l s='Click here to see more'}</a>
<a id="linkHide" href="#" style="text-decoration:underline;display:none">{l s='Hide warning'}</a>
</span>
<ul style="display:none;" id="seeMore">
{foreach $warnings item=warning}
<li>{$warning}</mo>
{/foreach}
</ul>
</div>
{/if}
{$content}
{include file='footer.tpl'}
{include file='footer.tpl'}
+63 -19
View File
@@ -1,13 +1,16 @@
<?php
class AdminController extends Controller
class AdminControllerCore extends Controller
{
public $path;
public $content;
public $warnings;
public $content_only = false;
public $layout = 'index.tpl';
public $template = 'content.tpl';
/** @var string Associated table name */
public $table;
@@ -54,10 +57,17 @@ class AdminController extends Controller
if (!$this->identifier) $this->identifier = 'id_'.$this->table;
if (!$this->_defaultOrderBy) $this->_defaultOrderBy = $this->identifier;
$className = get_class($this);
if ($className == 'AdminCategories' OR $className == 'AdminProducts')
$className = 'AdminCatalog';
$this->token = Tools::getAdminToken($className.(int)$this->id.(int)$this->context->employee->id);
// temporary fix for Token retrocompatibility
// This has to be done when url is built instead of here)
if(strpos($className,'Controller'))
$className = substr($className,0,-10);
$this->token = Tools::getAdminToken($className.(int)$this->id.(int)$this->context->employee->id);
if (!Shop::isMultiShopActivated())
$this->shopLinkType = '';
}
@@ -87,17 +97,14 @@ class AdminController extends Controller
return (!empty($token) AND $token === $this->token);
}
public function run()
public function action()
{
$this->checkAccess();
$this->init();
$this->postProcess();
$this->setMedia();
$this->initHeader();
$this->initFooter();
//$adminObj->displayConf();
//$adminObj->displayErrors();
$this->display();
}
/**
@@ -112,23 +119,57 @@ class AdminController extends Controller
$url = preg_replace('/([&?]token=)[^&]*(&.*)?$/', '${1}'.$this->token.'$2', $_SERVER['REQUEST_URI']);
if (false === strpos($url, '?token=') AND false === strpos($url, '&token='))
$url .= '&token='.$this->token;
if(strpos($url,'?') === false)
$url = str_replace('&token', '?controller=AdminHome&token', $url);
$this->context->smarty->assign('url', htmlentities($url));
$this->context->smarty->display(_PS_ADMIN_DIR_.'/themes/invalid_token.tpl');
$this->context->smarty->display('invalid_token.tpl');
die;
}
}
public function displayNoSmarty()
{
}
public function display()
{
if(!empty($this->content))
$this->assign('content', $this->content);
if (empty($this->template) or $this->template == 'content.tpl')
{
$default_tpl = substr(lcfirst(get_class($this)),0,-10).'.tpl';
if (file_exists($this->context->smarty->template_dir.'/'.$default_tpl))
{
$this->template = $default_tpl;
}
else
return $this->displayNoSmarty();
}
else
$this->content = $this->context->smarty->fetch($this->template);
if ($this->content_only)
$this->context->smarty->display($this->template);
echo $this->content;
else
{
$this->context->smarty->assign('warnings',$this->warnings);
$this->content = $this->context->smarty->fetch($this->template);
$this->context->smarty->assign('content', $this->content);
$this->context->smarty->display($this->layout);
}
$this->context->smarty->assign('content',$this->content);
$this->context->smarty->display($this->layout);
}
/**
* add a warning message to display at the top of the page
*
* @param string $msg
*/
protected function displayWarning($msg)
{
$this->warnings[] = $msg;
}
/**
@@ -221,14 +262,14 @@ class AdminController extends Controller
}
// Breadcrumbs
$home_token = Tools::getAdminToken('AdminHome'.intval(Tab::getIdFromClassName('AdminHome')).(int)$this->context->employee->id);
$tabs_breadcrumb = array();
$tabs_breadcrumb = recursiveTab($this->id, $tabs_breadcrumb);
$tabs_breadcrumb = Tab::recursiveTab($this->id, $tabs_breadcrumb);
$tabs_breadcrumb = array_reverse($tabs_breadcrumb);
foreach ($tabs_breadcrumb AS $key => $item)
for ($i = 0; $i < (count($tabs_breadcrumb) - 1); $i++)
$tabs_breadcrumb[$key]['token'] = Tools::getAdminToken($item['class_name'].intval($item['id_tab']).(int)$this->context->employee->id);
for ($i = 0; $i < (count($tabs_breadcrumb) - 1); $i++)
$tabs_breadcrumb[$key]['token'] = Tools::getAdminToken($item['class_name'].intval($item['id_tab']).(int)$this->context->employee->id);
/* Hooks are volontary out the initialize array (need those variables already assigned) */
$this->context->smarty->assign(array(
@@ -309,8 +350,7 @@ class AdminController extends Controller
$this->addCSS(_PS_JS_DIR_.'jquery/datepicker/datepicker.css', 'all');
$this->addCSS(_PS_CSS_DIR_.'admin.css', 'all');
$this->addCSS(_PS_CSS_DIR_.'jquery.cluetip.css', 'all');
$this->addCSS($this->path.'/themes/'.'default/admin.css', 'all');
$this->addCSS(__PS_BASE_URI__.'admin-dev/themes/default/admin.css', 'all');
if ($this->context->language->is_rtl)
$this->addCSS(_THEME_CSS_DIR_.'rtl.css');
@@ -335,7 +375,10 @@ class AdminController extends Controller
return Module::findTranslation(Module::$classInModule[$class], $string, $class);
}
global $_LANGADM;
$_LANGADM = array_change_key_case($_LANGADM);
if(is_array($_LANGADM))
$_LANGADM = array_change_key_case($_LANGADM);
else
$_LANGADM = array();
//if ($class == __CLASS__)
// $class = 'AdminTab';
@@ -363,7 +406,8 @@ class AdminController extends Controller
public function init()
{
ob_start();
// ob_start();
$this->checkAccess();
$this->timerStart = microtime(true);
if (isset($_GET['logout']))
@@ -462,4 +506,4 @@ class AdminController extends Controller
}
}
}
+1 -1
View File
@@ -197,7 +197,7 @@ abstract class AdminTabCore
{
$this->context = Context::getContext();
$this->id = Tab::getCurrentTabId();
$this->id = Tab::getIdFromClassName(get_class($this));
$this->_conf = array(
1 => $this->l('Deletion successful'), 2 => $this->l('Selection successfully deleted'),
3 => $this->l('Creation successful'), 4 => $this->l('Update successful'),
+9 -8
View File
@@ -47,16 +47,13 @@ class ChartCore
if (!self::$poolId)
{
++self::$poolId;
echo '
<!--[if IE]><script type="text/javascript" src="'.PS_BASE_URI.'js/jquery/excanvas.min.js"></script><![endif]-->
<script type="text/javascript" src="'.PS_BASE_URI.'js/jquery/jquery.flot.min.js"></script>';
return true;
}
}
/** @prototype void public function __construct() */
public function __construct()
{
self::init();
++self::$poolId;
}
@@ -101,7 +98,11 @@ class ChartCore
/** @prototype void public function display() */
public function display()
{
$options = '';
echo $this->fetch();
}
public function fetch()
{
if ($this->timeMode)
{
$options = 'xaxis:{mode:"time",timeformat:\''.addslashes($this->format).'\',min:'.$this->from.'000,max:'.$this->to.'000}';
@@ -117,7 +118,7 @@ class ChartCore
$jsCurves[] = $curve->getValues($this->timeMode);
if (count($jsCurves))
echo '
return '
<div id="flot'.self::$poolId.'" style="width:'.$this->width.'px;height:'.$this->height.'px"></div>
<script type="text/javascript">
$(function () {
@@ -125,7 +126,7 @@ class ChartCore
});
</script>';
else
echo ErrorFacade::Display(PS_ERROR_UNDEFINED, 'No values for this chart.');
return ErrorFacade::Display(PS_ERROR_UNDEFINED, 'No values for this chart.');
}
}
@@ -175,4 +176,4 @@ class Curve
if (array_key_exists((string)$x, $this->values))
return $this->values[(string)$x];
}
}
}
+45 -18
View File
@@ -35,6 +35,10 @@ class DispatcherCore
*/
public static $instance = null;
/*
* @var array
*/
public static $controllers = array();
/**
* List of default routes
*
@@ -196,12 +200,34 @@ class DispatcherCore
}
// Get and instantiate controller
$this->getController();
$controllers = Dispatcher::getControllers(_PS_CONTROLLER_DIR_);
if(defined('_PS_ADMIN_DIR_'))
Dispatcher::getControllers(_PS_ADMIN_DIR_.'/tabs/','');
// getControllers load all controller files from the specified dir
Dispatcher::getControllers(_PS_CONTROLLER_DIR_);
if (!$this->controller)
$this->controller = 'index';
if (!isset($controllers[$this->controller]))
$this->controller = 'pagenotfound';
Controller::getController($controllers[$this->controller])->run();
{
if (defined('_PS_ADMIN_DIR_'))
$this->controller = 'adminhome';
else
$this->controller = 'index';
}
// temporary code for AdminTab / AdminController
if (defined('_PS_ADMIN_DIR_') && $this->controller != 'adminhome')
{
if (file_exists(_PS_ADMIN_DIR_.'/tabs/'.self::$controllers[$this->controller].'.php'))
{
// Tools::displayAsDeprecated('AdminTab is deprecated'); // To put in AdminTab::__construct()
require_once(_PS_ADMIN_DIR_.'/functions.php');
runAdminTab();
die('');
}
}
else if (!isset(self::$controllers[$this->controller]))
$this->controller = 'pagenotfound';
Controller::getController(self::$controllers[$this->controller])->run();
}
/**
@@ -427,33 +453,34 @@ class DispatcherCore
}
/**
* Get list of available controllers
*
* Get list of available controllers from the specified dir
* @param string dir directory to scan (recursively)
* @param filename suffix (without .php extension). Others files will be ignored.
* @return array
*/
public static function getControllers($dir)
public static function getControllers($dir, $suffix = 'Controller')
{
static $controllers;
$controller_files = scandir($dir);
foreach ($controller_files as $controller_filename)
{
if (!in_array($controller_filename, array('.','..','.svn')) AND is_dir($dir.$controller_filename))
$controllers = self::getControllers($dir.$controller_filename.DIRECTORY_SEPARATOR);
else if (substr($controller_filename, -14, 14) == 'Controller.php')
{
self::$controllers = self::getControllers($dir.$controller_filename.DIRECTORY_SEPARATOR);
}
else if (substr($controller_filename, - (strlen($suffix)+4), - 4) == $suffix)
{
$subdir = str_replace(_PS_CONTROLLER_DIR_,'',$dir);
$controllers[strtolower(substr($controller_filename, 0, -14))] = basename($controller_filename, '.php');
self::$controllers[strtolower(substr($controller_filename, 0, - (strlen($suffix)+ 4)))] = basename($controller_filename, '.php');
}
}
// add default controller
$controllers['index'] = 'IndexController';
if (isset($controllers['auth']))
$controllers['authentication'] = $controllers['auth'];
self::$controllers['index'] = 'IndexController';
if (isset(self::$controllers['auth']))
self::$controllers['authentication'] = self::$controllers['auth'];
if (isset($controllers['compare']))
$controllers['productscomparison'] = $controllers['compare'];
self::$controllers['productscomparison'] = self::$controllers['compare'];
return $controllers;
return self::$controllers;
}
}
+11
View File
@@ -252,4 +252,15 @@ class TabCore extends ObjectModel
return ($tabAccesses[(int)($id_tab)]['view'] === '1');
return false;
}
public static function recursiveTab($id_tab, $tabs)
{
$adminTab = Tab::getTab((int)Context::getContext()->language->id, $id_tab);
$tabs[]= $adminTab;
if ($adminTab['id_parent'] > 0)
{
$tabs[] = Tab::recursiveTab($adminTab['id_parent'], $tabs);
}
return $tabs;
}
}
+459
View File
@@ -0,0 +1,459 @@
<?php
/*
* 2007-2011 PrestaShop
*
* NOTICE OF LICENSE
*
* This source file is subject to the Open Software License (OSL 3.0)
* that is bundled with this package in the file LICENSE.txt.
* It is also available through the world-wide-web at this URL:
* http://opensource.org/licenses/osl-3.0.php
* If you did not receive a copy of the license and are unable to
* obtain it through the world-wide-web, please send an email
* to license@prestashop.com so we can send you a copy immediately.
*
* DISCLAIMER
*
* Do not edit or add to this file if you wish to upgrade PrestaShop to newer
* versions in the future. If you wish to customize PrestaShop for your
* needs please refer to http://www.prestashop.com for more information.
*
* @author PrestaShop SA <contact@prestashop.com>
* @copyright 2007-2011 PrestaShop SA
* @version Release: $Revision$
* @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
* International Registered Trademark & Property of PrestaShop SA
*/
class AdminHomeControllerCore extends AdminController
{
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;
}
$indexRebuiltAfterUpdate = 0;
$needRebuild=Configuration::get('PS_NEED_REBUILD_INDEX');
if($needRebuild !='0');
$indexRebuiltAfterUpdate = 2;
$smartyOptimized = 0;
if (Configuration::get('PS_SMARTY_FORCE_COMPILE') == _PS_SMARTY_NO_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 + $indexRebuiltAfterUpdate != 14)
{
$this->content .= '
<div class="admin-box1">
<h5>'.$this->l('A good beginning...')
.'
<span style="float:right">
<a id="optimizationTipsFold"'.
(Configuration::get('PS_HIDE_OPTIMIZATION_TIPS')
?'" href="#"><img alt="v" style="padding-top:0px; padding-right: 5px;" src="../img/admin/down-white.gif" /></a>':'href="?hideOptimizationTips" >
<img alt="X" style="padding-top:0px; padding-right: 5px;" src="../img/admin/close-white.png" />
</a>').'</span></h5>';
$this->content .= '
<script type="text/javascript">
$(document).ready(function(){
$("#optimizationTipsFold").click(function(e){
$("#list-optimization-tips").toggle(function(){
if($("#optimizationTipsFold").children("img").attr("src") == "../img/admin/down-white.gif")
$("#optimizationTipsFold").children("img").attr("src","../img/admin/close-white.png");
else
$("#optimizationTipsFold").children("img").attr("src","../img/admin/down-white.gif");
});
})
});
</script>
';
$this->content .= '<ul id="list-optimization-tips" class="admin-home-box-list" '
.(Configuration::get('PS_HIDE_OPTIMIZATION_TIPS')?'style="display:none"':'').'>
<li style="background-color:'.$lights[$rewrite]['color'].'">
<img src="../img/admin/'.$lights[$rewrite]['image'].'" class="pico" />
<a href="index.php?tab=AdminGenerator&token='.Tools::getAdminTokenLite('AdminGenerator').'">'.$this->l('URL rewriting').'</a>
</li>
<li style="background-color:'.$lights[$htaccessOptimized]['color'].'">
<img src="../img/admin/'.$lights[$htaccessOptimized]['image'].'" class="pico" />
<a href="index.php?tab=AdminGenerator&token='.Tools::getAdminTokenLite('AdminGenerator').'">'.$this->l('Browser cache & compression').'</a>
</li>
<li style="background-color:'.$lights[$smartyOptimized]['color'].'">
<img src="../img/admin/'.$lights[$smartyOptimized]['image'].'" class="pico" />
<a href="index.php?tab=AdminPerformance&token='.Tools::getAdminTokenLite('AdminPerformance').'">'.$this->l('Smarty optimization').'</a></li>
<li style="background-color:'.$lights[$cccOptimized]['color'].'">
<img src="../img/admin/'.$lights[$cccOptimized]['image'].'" class="pico" />
<a href="index.php?tab=AdminPerformance&token='.Tools::getAdminTokenLite('AdminPerformance').'">'.$this->l('Combine, Compress & Cache').'</a></li>
<li style="background-color:'.$lights[$shopEnabled]['color'].'">
<img src="../img/admin/'.$lights[$shopEnabled]['image'].'" class="pico" />
<a href="index.php?tab=AdminPreferences&token='.Tools::getAdminTokenLite('AdminPreferences').'">'.$this->l('Shop enabled').'</a></li>
<li style="background-color:'.$lights[$indexRebuiltAfterUpdate]['color'].'">
<img src="../img/admin/'.$lights[$indexRebuiltAfterUpdate]['image'].'" class="pico" />
<a href="index.php?tab=AdminSearchConf&token='.Tools::getAdminTokenLite('AdminSearchConf').'">'.$this->l('index rebuilt after update').'</a></li>
<li style="background-color:'.$lights[$htaccessAfterUpdate]['color'].'">
<img src="../img/admin/'.$lights[$htaccessAfterUpdate]['image'].'" class="pico" />
<a href="index.php?tab=AdminGenerator&token='.Tools::getAdminTokenLite('AdminGenerator').'">'.$this->l('.htaccess up-to-date').'</a></li>
</ul>
</div>';
}
}
public function setMedia()
{
$this->addJS(_PS_JS_DIR_.'jquery/jquery.flot.min.js');
if (strpos($_SERVER['HTTP_USER_AGENT'],'MSIE') !== false)
$this->addJS(_PS_JS_DIR_.'jquery/excanvas.min.js');
parent::setMedia();
}
protected function warnDomainName()
{
if ($_SERVER['HTTP_HOST'] != Configuration::get('PS_SHOP_DOMAIN') AND $_SERVER['HTTP_HOST'] != Configuration::get('PS_SHOP_DOMAIN_SSL'))
$this->displayWarning($this->l('Your are currently connected with the following domain name:').' <span style="color: #CC0000;">'.$_SERVER['HTTP_HOST'].'</span><br />'.
$this->l('This one is different from the main shop domain name set in "Preferences > SEO & URLs":').' <span style="color: #CC0000;">'.Configuration::get('PS_SHOP_DOMAIN').'</span><br />
<a href="index.php?tab=AdminMeta&token='.Tools::getAdminTokenLite('AdminMeta').'#SEO%20%26%20URLs">'.
$this->l('Click here if you want to modify the main shop domain name').'</a>');
}
public function display()
{
$this->warnDomainName();
$tab = get_class();
$protocol = Tools::usingSecureMode()?'https':'http';
$isoUser = $this->context->language->iso_code;
$currency = Tools::setCurrency($this->context->cookie);
$this->content .= '<div>
<h1>'.$this->l('Dashboard').'</h1>
<hr style="background-color: #812143;color: #812143;" />
<br />';
if (@ini_get('allow_url_fopen'))
{
$upgrade = new Upgrader();
if($update = $upgrade->checkPSVersion())
$this->content .= '<div class="warning warn" style="margin-bottom:30px;"><h3>'.$this->l('New PrestaShop version available').' : <a style="text-decoration: underline;" href="'.$update['link'].'" target="_blank">'.$this->l('Download').'&nbsp;'.$update['name'].'</a> !</h3></div>';
}
else
{
$this->content .= '<p>'.$this->l('Update notification unavailable').'</p>';
$this->content .= '<p>&nbsp;</p>';
$this->content .= '<p>'.$this->l('To receive PrestaShop update warnings, you need to activate the <b>allow_url_fopen</b> command in your <b>php.ini</b> config file.').' [<a href="http://www.php.net/manual/'.$isoUser.'/ref.filesystem.php">'.$this->l('more info').'</a>]</p>';
$this->content .= '<p>'.$this->l('If you don\'t know how to do that, please contact your host administrator !').'</p><br>';
}
$this->content .= '</div>';
if ($this->context->employee->show_screencast)
$this->content .= '
<div id="adminpresentation">
<iframe src="'.$protocol.'://screencasts.prestashop.com/screencast.php?iso_lang='.Tools::strtolower($isoUser).'" style="border:none;width:100%;height:420px;" scrolling="no"></iframe>
<div id="footer_iframe_home">
<!--<a href="#">'.$this->l('View more video tutorials').'</a>-->
<input type="checkbox" id="screencast_dont_show_again"><label for="screencast_dont_show_again">'.$this->l('don\'t show again').'</label>
</div>
</div>
<script type="text/javascript">
$(document).ready(function() {
$(\'#screencast_dont_show_again\').click(function() {
if ($(this).is(\':checked\'))
{
$.ajax({
type: \'POST\',
async: true,
url: \'ajax.php?toggleScreencast\',
success: function(data) {
$(\'#adminpresentation\').slideUp(\'slow\');
}
});
}
});
});
</script>
<div class="clear"></div><br />';
$this->content .= '
<div id="column_left">
<ul class="F_list clearfix">
<li id="first_block">
<h4><a href="index.php?tab=AdminCatalog&addcategory&token='.Tools::getAdminTokenLite('AdminCatalog').'">'.$this->l('New category').'</a></h4>
<p>'.$this->l('Create a new category and organize your products.').'</p>
</li>
<li id="second_block">
<h4><a href="index.php?tab=AdminCatalog&id_category=1&addproduct&token='.Tools::getAdminTokenLite('AdminCatalog').'">'.$this->l('New product').'</a></h4>
<p>'.$this->l('Fill up your catalog with new articles and attributes.').'</p>
</li>
<li id="third_block">
<h4><a href="index.php?tab=AdminStats&token='.Tools::getAdminTokenLite('AdminStats').'">'.$this->l('Statistics').'</a></h4>
<p>'.$this->l('Manage your activity with a thorough analysis of your e-shop.').'</p>
</li>
<li id="fourth_block">
<h4><a href="index.php?tab=AdminEmployees&addemployee&token='.Tools::getAdminTokenLite('AdminEmployees').'">'.$this->l('New employee').'</a></h4>
<p>'.$this->l('Add a new employee account and discharge a part of your duties of shop owner.').'</p>
</li>
</ul>
';
$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));
$this->content .= '
<div class="table_info">
<h5><a href="index.php?tab=AdminStats&token='.Tools::getAdminTokenLite('AdminStats').'">'.$this->l('View more').'</a> '.$this->l('Monthly Statistics').' </h5>
<table class="table_info_details">
<tr class="tr_odd">
<td class="td_align_left">
'.$this->l('Sales').'
</td>
<td>
'
.Tools::displayPrice($results['total_sales'], $currency)
.'
</td>
</tr>
<tr>
<td class="td_align_left">
'.$this->l('Total registrations').'
</td>
<td>
'.(int)($results['total_registrations']).'
</td>
</tr>
<tr class="tr_odd">
<td class="td_align_left">
'.$this->l('Total orders').'
</td>
<td>
'.(int)($results['total_orders']).'
</td>
</tr>
<tr>
<td class="td_align_left">
'.$this->l('Product pages viewed').'
</td>
<td>
'.(int)($results['total_viewed']).'
</td>
</tr>
</table>
</div>
';
$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);
$this->content .= '
<div class="table_info" id="table_info_last">
<h5><a href="index.php?tab=AdminCustomerThreads&token='.Tools::getAdminTokenLite('AdminCustomerThreads').'">'.$this->l('View more').'</a> '.$this->l('Customers service').'</h5>
<table class="table_info_details">
<tr class="tr_odd">
<td class="td_align_left">
'.$this->l('Thread unread').'
</td>
<td>
'.$unread.'
</td>
</tr>
<tr>
<td class="td_align_left">
'.$this->l('Thread pending').'
</td>
<td>
'.$pending.'
</td>
</tr>
<tr class="tr_odd">
<td class="td_align_left">
'.$this->l('Thread closed').'
</td>
<td>
'.$close.'
</td>
</tr>
<tr>
<td class="td_align_left">
'.$this->l('Total thread').'
</td>
<td>
'.$all.'
</td>
</tr>
</table>
</div>
<div id="table_info_large">
<h5><a href="index.php?tab=AdminStats&token='.Tools::getAdminTokenLite('AdminStats').'">'.$this->l('View more').'</a> <strong>'.$this->l('Statistics').'</strong> / '.$this->l('Sales of the week').'</h5>
<div id="stat_google">';
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).')');
$this->content .= $chart->fetch();
$this->content .= ' </div>
</div>
<table cellpadding="0" cellspacing="0" id="table_customer">
<thead>
<tr>
<th class="order_id"><span class="first">'.$this->l('ID').'</span></th>
<th class="order_customer"><span>'.$this->l('Customer Name').'</span></th>
<th class="order_status"><span>'.$this->l('Status').'</span></th>
<th class="order_total"><span>'.$this->l('Total').'</span></th>
<th class="order_action"><span class="last">'.$this->l('Action').'</span></th>
<tr>
</thead>
<tbody>';
$orders = Order::getOrdersWithInformations(10);
$i = 0;
foreach ($orders AS $order)
{
$currency = Currency::getCurrency((int)$order['id_currency']);
$this->content .= '
<tr'.($i % 2 ? ' id="order_line1"' : '').'>
<td class="order_td_first order_id">'.(int)$order['id_order'].'</td>
<td class="order_customer">'.Tools::htmlentitiesUTF8($order['firstname']).' '.Tools::htmlentitiesUTF8($order['lastname']).'</td>
<td class="order_status">'.Tools::htmlentitiesUTF8($order['state_name']).'</td>
<td class="order_total">'.Tools::displayPrice((float)$order['total_paid'], $currency).'</td>
<td class="order_action">
<a href="index.php?tab=AdminOrders&id_order='.(int)$order['id_order'].'&vieworder&token='.Tools::getAdminTokenLite('AdminOrders').'" title="'.$this->l('Details').'"><img src="../img/admin/details.gif" alt="'.$this->l('See').'" /></a>
</td>
</tr>
';
$i++;
}
$this->content .= '
</tbody>
</table>
</div>
<div id="column_right">
<script type="text/javascript">
$(document).ready(function() {
$.ajax({
url: "ajax.php",
dataType: "json",
data: "getAdminHomeElement",
success: function(json) {
if (json.screencast != \'NOK\')
$(\'#adminpresentation\').fadeIn(\'slow\');
else
$(\'#adminpresentation\').fadeOut(\'slow\');
$(\'#partner_preactivation\').fadeOut(\'slow\', function() {
if (json.partner_preactivation != \'NOK\')
$(\'#partner_preactivation\').html(json.partner_preactivation);
else
$(\'#partner_preactivation\').html(\'\');
$(\'#partner_preactivation\').fadeIn(\'slow\');
});
$(\'#discover_prestashop\').fadeOut(\'slow\', function() {
if (json.discover_prestashop != \'NOK\')
$(\'#discover_prestashop\').html(json.discover_prestashop);
else
$(\'#discover_prestashop\').html(\'\');
$(\'#discover_prestashop\').fadeIn(\'slow\');
});
},
error: function(XMLHttpRequest, textStatus, errorThrown)
{
$(\'#adminpresentation\').fadeOut(\'slow\');
$(\'#partner_preactivation\').fadeOut(\'slow\');
$(\'#discover_prestashop\').fadeOut(\'slow\');
}
});
});
</script>
<div id="partner_preactivation">
<p class="center"><img src="../img/loader.gif" alt="" /> '.$this->l('Loading...').'</p>
</div>
';
if (Tools::isSubmit('hideOptimizationTips'))
Configuration::updateValue('PS_HIDE_OPTIMIZATION_TIPS', 1);
$this->_displayOptimizationTips();
$this->content .= '
<div id="discover_prestashop">
<p class="center"><img src="../img/loader.gif" alt="" /> '.$this->l('Loading...').'</p>
</div>
</div>
<div class="clear"></div>';
$this->content .= Module::hookExec('backOfficeHome');
$this->context->smarty->assign('content', $this->content);
parent::display();
}
}
@@ -25,15 +25,13 @@
* International Registered Trademark & Property of PrestaShop SA
*/
class AdminTools extends AdminController
class AdminToolsControllerCore extends AdminController
{
public $template = 'adminTools.tpl';
public function __construct()
{
$this->className = 'AdminTools';
parent::__construct();
}
}