* @copyright 2007-2011 PrestaShop SA * @version Release: $Revision: 6594 $ * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) * International Registered Trademark & Property of PrestaShop SA */ include_once(PS_ADMIN_DIR.'/tabs/AdminPreferences.php'); abstract class AdminStatsTab extends AdminPreferences { public function __construct() { $this->_fieldsSettings = array( 'PS_STATS_RENDER' => array('title' => $this->l('Graph engine'), 'validation' => 'isGenericName'), 'PS_STATS_GRID_RENDER' => array('title' => $this->l('Grid engine'), 'validation' => 'isGenericName') ); parent::__construct(); } public function postProcess() { global $cookie, $currentIndex; if (Tools::isSubmit('submitDatePicker')) { if (!Validate::isDate($from = Tools::getValue('datepickerFrom')) OR !Validate::isDate($to = Tools::getValue('datepickerTo'))) $this->_errors[] = Tools::displayError('Date specified is invalid'); } if (Tools::isSubmit('submitDateDay')) { $from = date('Y-m-d'); $to = date('Y-m-d'); } if (Tools::isSubmit('submitDateDayPrev')) { $yesterday = time() - 60*60*24; $from = date('Y-m-d', $yesterday); $to = date('Y-m-d', $yesterday); } if (Tools::isSubmit('submitDateMonth')) { $from = date('Y-m-01'); $to = date('Y-m-t'); } if (Tools::isSubmit('submitDateMonthPrev')) { $m = (date('m') == 1 ? 12 : date('m') - 1); $y = ($m == 12 ? date('Y') - 1 : date('Y')); $from = $y.'-'.$m.'-01'; $to = $y.'-'.$m.date('-t', mktime(12, 0, 0, $m, 15, $y)); } if (Tools::isSubmit('submitDateYear')) { $from = date('Y-01-01'); $to = date('Y-12-31'); } if (Tools::isSubmit('submitDateYearPrev')) { $from = (date('Y') - 1).date('-01-01'); $to = (date('Y') - 1).date('-12-31'); } if (isset($from) AND isset($to) AND !sizeof($this->_errors)) { $employee = new Employee($cookie->id_employee); $employee->stats_date_from = $from; $employee->stats_date_to = $to; $employee->update(); Tools::redirectAdmin($_SERVER['REQUEST_URI']); } if (Tools::getValue('submitSettings')) { if ($this->tabAccess['edit'] === '1') { $currentIndex .= '&module='.Tools::getValue('module'); $this->_postConfig($this->_fieldsSettings); } else $this->_errors[] = Tools::displayError('You do not have permission to edit here.'); } if (sizeof($this->_errors)) AdminTab::displayErrors(); } protected function displayEngines() { global $currentIndex, $cookie; $graphEngine = Configuration::get('PS_STATS_RENDER'); $gridEngine = Configuration::get('PS_STATS_GRID_RENDER'); $arrayGraphEngines = ModuleGraphEngine::getGraphEngines(); $arrayGridEngines = ModuleGridEngine::getGridEngines(); echo '
'.$this->l('Settings', 'AdminStatsTab').''; echo '

'.$this->l('Graph engine', 'AdminStatsTab').'
'; if (sizeof($arrayGraphEngines)) { echo '

'; } else echo $this->l('No graph engine module installed', 'AdminStatsTab'); echo '

'.$this->l('Grid engine', 'AdminStatsTab').'
'; if (sizeof($arrayGridEngines)) { echo '

'; } else echo $this->l('No grid engine module installed', 'AdminStatsTab'); echo '

 
'; } protected function getDate() { global $cookie; $year = isset($cookie->stats_year) ? $cookie->stats_year : date('Y'); $month = isset($cookie->stats_month) ? sprintf('%02d', $cookie->stats_month) : '%'; $day = isset($cookie->stats_day) ? sprintf('%02d', $cookie->stats_day) : '%'; return $year.'-'.$month.'-'.$day; } public function displayCalendar() { echo '
'.self::displayCalendarStatic(array( 'Calendar' => $this->l('Calendar', 'AdminStatsTab'), 'Day' => $this->l('Day', 'AdminStatsTab'), 'Month' => $this->l('Month', 'AdminStatsTab'), 'Year' => $this->l('Year', 'AdminStatsTab'), 'From' => $this->l('From:', 'AdminStatsTab'), 'To' => $this->l('To:', 'AdminStatsTab'), 'Save' => $this->l('Save', 'AdminStatsTab') )).'
 
'; } public static function displayCalendarStatic($translations) { global $cookie; $employee = new Employee($cookie->id_employee); includeDatepicker(array('datepickerFrom', 'datepickerTo')); return '
'.$translations['Calendar'].'

'.(isset($translations['From']) ? $translations['From'] : 'From:').'

'.(isset($translations['To']) ? $translations['To'] : 'To:').'

'; } public function displaySearch() { return; echo '
'.$this->l('Search', 'AdminStatsTab').'
'; } private function getModules() { return Db::getInstance()->ExecuteS(' SELECT h.`name` AS hook, m.`name` FROM `'._DB_PREFIX_.'module` m LEFT JOIN `'._DB_PREFIX_.'hook_module` hm ON hm.`id_module` = m.`id_module` LEFT JOIN `'._DB_PREFIX_.'hook` h ON hm.`id_hook` = h.`id_hook` WHERE h.`name` LIKE \'AdminStatsModules\' AND m.`active` = 1 ORDER BY hm.`position`'); } public function displayMenu() { global $currentIndex, $cookie; $modules = $this->getModules(); echo '
'.$this->l('Navigation', 'AdminStatsTab').''; if (sizeof($modules)) { foreach ($modules AS $module) if ($moduleInstance = Module::getInstanceByName($module['name'])) echo '

'.$moduleInstance->displayName.'

'; } else echo $this->l('No module installed', 'AdminStatsTab'); echo '
 
'; } public function display() { echo '
'; $this->displayCalendar(); $this->displayEngines(); $this->displayMenu(); $this->displaySearch(); echo '
'; if (!($moduleName = Tools::getValue('module')) AND $moduleInstance = Module::getInstanceByName('statsforecast') AND $moduleInstance->active) $moduleName = 'statsforecast'; if ($moduleName) { // Needed for the graphics display when this is the default module $_GET['module'] = $moduleName; if (!isset($moduleInstance)) $moduleInstance = Module::getInstanceByName($moduleName); if ($moduleInstance AND $moduleInstance->active) echo Module::hookExec('AdminStatsModules', NULL, $moduleInstance->id); else echo $this->l('Module not found', 'AdminStatsTab'); } else echo '

'.$this->l('Please select a module in the left column.').'

'; echo '
'; } }