diff --git a/admin/themes/default/template/form_date_range_picker.tpl b/admin/themes/default/template/form_date_range_picker.tpl
index f75864be5..7334aa52b 100644
--- a/admin/themes/default/template/form_date_range_picker.tpl
+++ b/admin/themes/default/template/form_date_range_picker.tpl
@@ -9,7 +9,7 @@
-
+
\ No newline at end of file
diff --git a/classes/Translate.php b/classes/Translate.php
index a11d739a2..7bb036099 100644
--- a/classes/Translate.php
+++ b/classes/Translate.php
@@ -29,6 +29,8 @@
*/
class TranslateCore
{
+ public static $ignore_folder = array('.', '..', '.svn', '.git', '.htaccess', 'index.php');
+
/**
* Get a translation for an admin controller
*
@@ -315,4 +317,338 @@ class TranslateCore
{
return Translate::postProcessTranslation($string, array('tags' => $tags));
}
+
+ /**
+ * This method parse a file by type of translation and type file
+ *
+ * @param $content
+ * @param $type_translation : front, back, errors, modules...
+ * @param string|bool $type_file : (tpl|php)
+ * @param string $module_name : name of the module
+ * @return array
+ */
+ public static function userParseFile($content, $type_translation, $type_file = false, $module_name = '')
+ {
+ switch ($type_translation) {
+ case 'front':
+ // Parsing file in Front office
+ $regex = '/\{l\s*s=([\'\"])'._PS_TRANS_PATTERN_.'\1(\s*sprintf=.*)?(\s*js=1)?\s*\}/U';
+ break;
+
+ case 'back':
+ // Parsing file in Back office
+ if ($type_file == 'php') {
+ $regex = '/this->l\((\')'._PS_TRANS_PATTERN_.'\'[\)|\,]/U';
+ } elseif ($type_file == 'specific') {
+ $regex = '/Translate::getAdminTranslation\((\')'._PS_TRANS_PATTERN_.'\'(?:,.*)*\)/U';
+ } else {
+ $regex = '/\{l\s*s\s*=([\'\"])'._PS_TRANS_PATTERN_.'\1(\s*sprintf=.*)?(\s*js=1)?(\s*slashes=1)?.*\}/U';
+ }
+ break;
+
+ case 'errors':
+ // Parsing file for all errors syntax
+ $regex = '/Tools::displayError\((\')'._PS_TRANS_PATTERN_.'\'(,\s*(.+))?\)/U';
+ break;
+
+ case 'modules':
+ // Parsing modules file
+ if ($type_file == 'php') {
+ $regex = '/->l\((\')'._PS_TRANS_PATTERN_.'\'(, ?\'(.+)\')?(, ?(.+))?\)/U';
+ } else {
+ // In tpl file look for something that should contain mod='module_name' according to the documentation
+ $regex = '/\{l\s*s=([\'\"])'._PS_TRANS_PATTERN_.'\1.*\s+mod=\''.$module_name.'\'.*\}/U';
+ }
+ break;
+
+ case 'pdf':
+ // Parsing PDF file
+ if ($type_file == 'php') {
+ $regex = array(
+ '/HTMLTemplate.*::l\((\')'._PS_TRANS_PATTERN_.'\'[\)|\,]/U',
+ '/->l\((\')'._PS_TRANS_PATTERN_.'\'(, ?\'(.+)\')?(, ?(.+))?\)/U'
+ );
+ } else {
+ $regex = '/\{l\s*s=([\'\"])'._PS_TRANS_PATTERN_.'\1(\s*sprintf=.*)?(\s*js=1)?(\s*pdf=\'true\')?\s*\}/U';
+ }
+ break;
+ }
+
+ if (!is_array($regex)) {
+ $regex = array($regex);
+ }
+
+ $strings = array();
+ foreach ($regex as $regex_row) {
+ $matches = array();
+ $n = preg_match_all($regex_row, $content, $matches);
+ for ($i = 0; $i < $n; $i += 1) {
+ $quote = $matches[1][$i];
+ $string = $matches[2][$i];
+
+ if ($quote === '"') {
+ // Escape single quotes because the core will do it when looking for the translation of this string
+ $string = str_replace('\'', '\\\'', $string);
+ // Unescape double quotes
+ $string = preg_replace('/\\\\+"/', '"', $string);
+ }
+
+ $strings[] = $string;
+ }
+ }
+
+ return array_unique($strings);
+ }
+
+ /**
+ * Recursively list files in directory $dir
+ *
+ * @param string $dir
+ * @param array $list
+ * @param string $file_ext
+ *
+ * @return array
+ */
+ public static function listFiles($dir, $list = array(), $file_ext = 'tpl')
+ {
+ $dir = rtrim($dir, '/').DIRECTORY_SEPARATOR;
+
+ $to_parse = scandir($dir);
+ // copied (and kind of) adapted from AdminImages.php
+ foreach ($to_parse as $file) {
+ if (!in_array($file, self::$ignore_folder)) {
+ if (preg_match('#'.preg_quote($file_ext, '#').'$#i', $file)) {
+ $list[$dir][] = $file;
+ } elseif (is_dir($dir.$file)) {
+ $list = self::listFiles($dir.$file, $list, $file_ext);
+ }
+ }
+ }
+
+ return $list;
+ }
+
+ /**
+ * Find sentence which use %d, %s, %%, %1$d, %1$s...
+ *
+ * @param $key : english sentence
+ * @return array|bool return list of matches
+ */
+ public static function checkIfKeyUseSprintf($key)
+ {
+ if (preg_match_all('#(?:%%|%(?:[0-9]+\$)?[+-]?(?:[ 0]|\'.)?-?[0-9]*(?:\.[0-9]+)?[bcdeufFosxX])#', $key, $matches)) {
+ return implode(', ', $matches[0]);
+ }
+
+ return false;
+ }
+
+ public static function getTranslationsCountFrontOffice($theme, $isoCode)
+ {
+ $themeDir = _PS_ROOT_DIR_.'/themes/'.$theme.'/';
+ $langFile = $themeDir.'lang/'.$isoCode.'.php';
+
+ // include global translation file
+ if (Tools::file_exists_cache($langFile)) {
+ include $langFile;
+ } else {
+ $_LANG = array();
+ }
+
+ // count translatable strings in theme tpl files
+ $directories = array();
+ $directories['tpl'] = array(_PS_ALL_THEMES_DIR_ => scandir(_PS_ALL_THEMES_DIR_));
+ self::$ignore_folder[] = 'modules';
+ $directories['tpl'] = array_merge($directories['tpl'], self::listFiles($themeDir));
+ if (isset($directories['tpl'][$themeDir.'pdf/'])) {
+ unset($directories['tpl'][$themeDir.'pdf/']);
+ }
+
+ if (Tools::file_exists_cache(_PS_THEME_OVERRIDE_DIR_)) {
+ $directories['tpl'] = array_merge($directories['tpl'], self::listFiles(_PS_THEME_OVERRIDE_DIR_));
+ }
+
+ // process tpl files
+ $countTotal = 0;
+ $countTranslated = 0;
+ foreach ($directories['tpl'] as $dir => $files) {
+ $prefix = $dir == _PS_THEME_OVERRIDE_DIR_ ? 'override_' : '';
+
+ foreach ($files as $file) {
+ if (preg_match('/^(.*).tpl$/', $file) && (Tools::file_exists_cache($filePath = $dir.$file))) {
+ $prefixKey = $prefix.substr(basename($file), 0, -4);
+ $fileContent = Tools::file_get_contents($filePath);
+ $matches = self::userParseFile($fileContent, 'front');
+
+ foreach ($matches as $key) {
+ $countTotal++;
+
+ if (!empty($key)) {
+ if (isset($_LANG[$prefixKey.'_'.md5($key)])) {
+ $countTranslated++;
+ }
+ }
+ }
+ }
+ }
+ }
+
+ return array('total' => $countTotal, 'translated' => $countTranslated);
+ }
+
+ public static function getTranslationsCountBackOffice($isoCode)
+ {
+ $translationsFile = _PS_TRANSLATIONS_DIR_.$isoCode.'/admin.php';
+
+ // include global translation file
+ if (Tools::file_exists_cache($translationsFile)) {
+ include $translationsFile;
+ } else {
+ $_LANGADM = array();
+ }
+
+ // list directories with translatable files
+ $directories = array(
+ 'php' => array(
+ _PS_ADMIN_CONTROLLER_DIR_ => scandir(_PS_ADMIN_CONTROLLER_DIR_),
+ _PS_OVERRIDE_DIR_.'controllers/admin/' => scandir(_PS_OVERRIDE_DIR_.'controllers/admin/'),
+ _PS_CLASS_DIR_.'helper/' => scandir(_PS_CLASS_DIR_.'helper/'),
+ _PS_CLASS_DIR_.'controller/' => array('AdminController.php'),
+ _PS_CLASS_DIR_ => array('PaymentModule.php'),
+ ),
+ 'tpl' => self::listFiles(_PS_ADMIN_DIR_.DIRECTORY_SEPARATOR.'themes/'),
+ 'specific' => array(
+ _PS_ADMIN_DIR_.DIRECTORY_SEPARATOR => array(
+ 'header.inc.php',
+ 'footer.inc.php',
+ 'index.php',
+ 'functions.php',
+ ),
+ ),
+ );
+
+ // list directories from override folders
+ if (Tools::file_exists_cache(_PS_OVERRIDE_DIR_.'controllers'.DIRECTORY_SEPARATOR.'admin'.DIRECTORY_SEPARATOR.'templates')) {
+ $directories['tpl'] = array_merge($directories['tpl'], self::listFiles(_PS_OVERRIDE_DIR_.'controllers'.DIRECTORY_SEPARATOR.'admin'.DIRECTORY_SEPARATOR.'templates'));
+ }
+
+ // process files
+ $countTotal = 0;
+ $countTranslated = 0;
+ foreach ($directories['php'] as $dir => $files) {
+ foreach ($files as $file) {
+ // check if $file is a PHP file and corresponding override file exists
+ if (preg_match('/^(.*)\.php$/', $file) && Tools::file_exists_cache($filePath = $dir.$file) && !in_array($file, self::$ignore_folder)) {
+ $prefixKey = basename($file);
+ // -4 becomes -14 to remove the ending "Controller.php" from the filename
+ if (strpos($file, 'Controller.php') !== false) {
+ $prefixKey = basename(substr($file, 0, -14));
+ } elseif (strpos($file, 'Helper') !== false) {
+ $prefixKey = 'Helper';
+ }
+
+ if ($prefixKey == 'Admin') {
+ $prefixKey = 'AdminController';
+ }
+
+ if ($prefixKey == 'PaymentModule.php') {
+ $prefixKey = 'PaymentModule';
+ }
+
+ $fileContent = Tools::file_get_contents($filePath);
+ $matches = self::userParseFile($fileContent, 'back', 'php');
+
+ foreach ($matches as $key) {
+ $countTotal++;
+
+ if (!empty($key)) {
+ if (isset($_LANGADM[$prefixKey.md5($key)])) {
+ $countTranslated++;
+ }
+ }
+ }
+ }
+ }
+ }
+
+ foreach ($directories['specific'] as $dir => $files) {
+ foreach ($files as $file) {
+ if (Tools::file_exists_cache($filePath = $dir.$file) && !in_array($file, self::$ignore_folder)) {
+ $prefixKey = 'index';
+
+ $fileContent = Tools::file_get_contents($filePath);
+ $matches = self::userParseFile($fileContent, 'back', 'specific');
+
+ foreach ($matches as $key) {
+ $countTotal++;
+
+ if (!empty($key)) {
+ if (isset($_LANGADM[$prefixKey.md5($key)])) {
+ $countTranslated++;
+ }
+ }
+ }
+ }
+ }
+ }
+
+ foreach ($directories['tpl'] as $dir => $files) {
+ foreach ($files as $file) {
+ if (preg_match('/^(.*).tpl$/', $file) && Tools::file_exists_cache($filePath = $dir.$file)) {
+ // get controller name instead of file name
+ $prefixKey = Tools::toCamelCase(str_replace(_PS_ADMIN_DIR_.DIRECTORY_SEPARATOR.'themes', '', $filePath), true);
+ $pos = strrpos($prefixKey, DIRECTORY_SEPARATOR);
+ $tmp = substr($prefixKey, 0, $pos);
+
+ if (preg_match('#controllers#', $tmp)) {
+ $parentClass = explode(DIRECTORY_SEPARATOR, str_replace('/', DIRECTORY_SEPARATOR, $tmp));
+ $override = array_search('override', $parentClass);
+ if ($override !== false) {
+ // case override/controllers/admin/templates/controller_name
+ $prefixKey = 'Admin'.ucfirst($parentClass[$override + 4]);
+ } else {
+ // case admin_name/themes/theme_name/template/controllers/controller_name
+ $key = array_search('controllers', $parentClass);
+ $prefixKey = 'Admin'.ucfirst($parentClass[$key + 1]);
+ }
+ } else {
+ $prefixKey = 'Admin'.ucfirst(substr($tmp, strrpos($tmp, DIRECTORY_SEPARATOR) + 1, $pos));
+ }
+
+ // Adding list, form, option in Helper Translations
+ $listPrefixKey = array('AdminHelpers', 'AdminList', 'AdminView', 'AdminOptions', 'AdminForm',
+ 'AdminCalendar', 'AdminTree', 'AdminUploader', 'AdminDataviz', 'AdminKpi', 'AdminModule_list', 'AdminModulesList');
+ if (in_array($prefixKey, $listPrefixKey)) {
+ $prefixKey = 'Helper';
+ }
+
+ // Adding the folder backup/download/ in AdminBackup Translations
+ if ($prefixKey == 'AdminDownload') {
+ $prefixKey = 'AdminBackup';
+ }
+
+ // use the prefix 'AdminController' (like old php files 'header', 'footer.inc', 'index', 'login', 'password', 'functions'
+ if ($prefixKey == 'Admin' || $prefixKey == 'AdminTemplate') {
+ $prefixKey = 'AdminController';
+ }
+
+ $fileContent = Tools::file_get_contents($filePath);
+ $matches = self::userParseFile($fileContent, 'back', 'tpl');
+
+ // get string translation for each tpl file
+ foreach ($matches as $key) {
+ $countTotal++;
+
+ if (!empty($key)) {
+ if (isset($_LANGADM[$prefixKey.md5($key)])) {
+ $countTranslated++;
+ }
+ }
+ }
+ }
+ }
+ }
+
+ return array('total' => $countTotal, 'translated' => $countTranslated);
+ }
}
diff --git a/controllers/admin/AdminCartsController.php b/controllers/admin/AdminCartsController.php
index ebd03b7a4..4de8b21d1 100644
--- a/controllers/admin/AdminCartsController.php
+++ b/controllers/admin/AdminCartsController.php
@@ -188,11 +188,11 @@ class AdminCartsControllerCore extends AdminController
$helper->color = 'color4';
$helper->title = $this->l('Net Profit per Visitor', null, null, false);
$helper->subtitle = $this->l('30 days', null, null, false);
- if (ConfigurationKPI::get('NETPROFIT_VISITOR') !== false) {
- $helper->value = ConfigurationKPI::get('NETPROFIT_VISITOR');
+ if (ConfigurationKPI::get('NETPROFIT_VISIT') !== false) {
+ $helper->value = ConfigurationKPI::get('NETPROFIT_VISIT');
}
- $helper->source = $this->context->link->getAdminLink('AdminStats').'&ajax=1&action=getKpi&kpi=netprofit_visitor';
- $helper->refresh = (bool)(ConfigurationKPI::get('NETPROFIT_VISITOR_EXPIRE') < $time);
+ $helper->source = $this->context->link->getAdminLink('AdminStats').'&ajax=1&action=getKpi&kpi=netprofit_visit';
+ $helper->refresh = (bool)(ConfigurationKPI::get('NETPROFIT_VISIT_EXPIRE') < $time);
$kpis[] = $helper->generate();
$helper = new HelperKpiRow();
diff --git a/controllers/admin/AdminDashboardController.php b/controllers/admin/AdminDashboardController.php
index a7a01800c..8a694feaf 100644
--- a/controllers/admin/AdminDashboardController.php
+++ b/controllers/admin/AdminDashboardController.php
@@ -70,13 +70,11 @@ class AdminDashboardControllerCore extends AdminController
{
$forms = array();
$currency = new Currency(Configuration::get('PS_CURRENCY_DEFAULT'));
- $carriers = Carrier::getCarriers($this->context->language->id, true, false, false, null, 'ALL_CARRIERS');
$modules = Module::getModulesOnDisk(true);
$forms = array(
+ 'net_profit' => array('title' => $this->l('Net Profit settings'), 'id' => 'net_profit'),
'payment' => array('title' => $this->l('Average bank fees per payment method'), 'id' => 'payment'),
- 'carriers' => array('title' => $this->l('Average shipping fees per shipping method'), 'id' => 'carriers'),
- 'other' => array('title' => $this->l('Other settings'), 'id' => 'other')
);
foreach ($forms as &$form) {
$form['icon'] = 'tab-preferences';
@@ -133,32 +131,9 @@ class AdminDashboardControllerCore extends AdminController
}
}
- foreach ($carriers as $carrier) {
- $forms['carriers']['fields']['CONF_'.strtoupper($carrier['id_reference']).'_SHIP'] = array(
- 'title' => $carrier['name'],
- 'desc' => sprintf($this->l('For the carrier named %s, indicate the domestic delivery costs in percentage of the price charged to customers.'), $carrier['name']),
- 'validation' => 'isPercentage',
- 'cast' => 'floatval',
- 'type' => 'text',
- 'defaultValue' => '0',
- 'suffix' => '%'
- );
- $forms['carriers']['fields']['CONF_'.strtoupper($carrier['id_reference']).'_SHIP_OVERSEAS'] = array(
- 'title' => $carrier['name'],
- 'desc' => sprintf($this->l('For the carrier named %s, indicate the overseas delivery costs in percentage of the price charged to customers.'), $carrier['name']),
- 'validation' => 'isPercentage',
- 'cast' => 'floatval',
- 'type' => 'text',
- 'defaultValue' => '0',
- 'suffix' => '%'
- );
- }
-
- $forms['carriers']['description'] = $this->l('Method: Indicate the percentage of your carrier margin. For example, if you charge $10 of shipping fees to your customer for each shipment, but you really pay $4 to this carrier, then you should indicate "40" in the percentage field.');
-
- $forms['other']['fields']['CONF_AVERAGE_PRODUCT_MARGIN'] = array(
+ $forms['net_profit']['fields']['CONF_AVERAGE_PRODUCT_MARGIN'] = array(
'title' => $this->l('Average gross margin percentage'),
- 'desc' => $this->l('You should calculate this percentage as follows: ((total sales revenue) - (cost of goods sold)) / (total sales revenue) * 100. This value is only used to calculate the Dashboard approximate gross margin, if you do not specify the wholesale price for each product.'),
+ 'desc' => $this->l('You should calculate this percentage as follows: ((total sales revenue) - (total operating cost)) / (total sales revenue) * 100. This value is only used to calculate Dashboard approximate gross margin, if you do not specify operating cost for each room type.'),
'validation' => 'isPercentage',
'cast' => 'intval',
'type' => 'text',
@@ -166,7 +141,7 @@ class AdminDashboardControllerCore extends AdminController
'suffix' => '%'
);
- $forms['other']['fields']['CONF_ORDER_FIXED'] = array(
+ $forms['net_profit']['fields']['CONF_ORDER_FIXED'] = array(
'title' => $this->l('Other fees per order'),
'desc' => $this->l('You should calculate this value by making the sum of all of your additional costs per order.'),
'validation' => 'isPrice',
diff --git a/controllers/admin/AdminStatsController.php b/controllers/admin/AdminStatsController.php
index 60a066d4d..d2df25f9c 100644
--- a/controllers/admin/AdminStatsController.php
+++ b/controllers/admin/AdminStatsController.php
@@ -29,10 +29,10 @@ class AdminStatsControllerCore extends AdminStatsTabController
public static function getVisits($unique = false, $date_from, $date_to, $granularity = false)
{
$visits = ($granularity == false) ? 0 : array();
- $objQGA = Module::isEnabled('qlogoogleanalytics') ? Module::getInstanceByName('qlogoogleanalytics') : false;
- if (Validate::isLoadedObject($objQGA) && $objQGA->isConfigured()) {
+ $objGoogleAnalytics = Module::isEnabled('qlogoogleanalytics') ? Module::getInstanceByName('qlogoogleanalytics') : false;
+ if (Validate::isLoadedObject($objGoogleAnalytics) && $objGoogleAnalytics->isConfigured()) {
$metric = $unique ? 'visitors' : 'visits';
- if ($result = $objQGA->requestReportData($granularity ? 'ga:date' : '', 'ga:'.$metric, $date_from, $date_to, null, null, 1, 5000)) {
+ if ($result = $objGoogleAnalytics->requestReportData($granularity ? 'ga:date' : '', 'ga:'.$metric, $date_from, $date_to, null, null, 1, 5000)) {
foreach ($result as $row) {
if ($granularity == 'day') {
$visits[strtotime(preg_replace('/^([0-9]{4})([0-9]{2})([0-9]{2})$/', '$1-$2-$3', $row['dimensions']['date']))] = $row['metrics'][$metric];
@@ -147,7 +147,6 @@ class AdminStatsControllerCore extends AdminStatsTabController
return round($row['products'] ? 100 * $row['without_stock'] / $row['products'] : 0, 2).'%';
}
-
public static function getProductAverageGrossMargin()
{
$sql = 'SELECT AVG(1 - (IF(IFNULL(product_attribute_shop.wholesale_price, 0) = 0, product_shop.wholesale_price,product_attribute_shop.wholesale_price) / (IFNULL(product_attribute_shop.price, 0) + product_shop.price)))
@@ -261,6 +260,7 @@ class AdminStatsControllerCore extends AdminStatsTabController
FROM `'._DB_PREFIX_.'orders` o
LEFT JOIN `'._DB_PREFIX_.'order_detail` od ON o.id_order = od.id_order
WHERE `invoice_date` BETWEEN "'.pSQL($date_from).' 00:00:00" AND "'.pSQL($date_to).' 23:59:59"
+ AND o.`valid` = 1
'.Shop::addSqlRestriction(false, 'o'));
if (!$distinct_products) {
return '0%';
@@ -524,21 +524,14 @@ class AdminStatsControllerCore extends AdminStatsTabController
: Configuration::get('CONF_'.strtoupper($order['module']).'_VAR_FOREIGN')
) / 100;
- // Add shipping fees for this order
- $shipping_fees = $order['total_shipping_tax_excl'] * (
- $order['id_country'] == Configuration::get('PS_COUNTRY_DEFAULT')
- ? Configuration::get('CONF_'.strtoupper($order['carrier_reference']).'_SHIP')
- : Configuration::get('CONF_'.strtoupper($order['carrier_reference']).'_SHIP_OVERSEAS')
- ) / 100;
-
// Tally up these fees
if ($granularity == 'day') {
if (!isset($expenses[strtotime($order['date'])])) {
$expenses[strtotime($order['date'])] = 0;
}
- $expenses[strtotime($order['date'])] += $flat_fees + $var_fees + $shipping_fees;
+ $expenses[strtotime($order['date'])] += $flat_fees + $var_fees;
} else {
- $expenses += $flat_fees + $var_fees + $shipping_fees;
+ $expenses += $flat_fees + $var_fees;
}
}
return $expenses;
@@ -721,41 +714,11 @@ class AdminStatsControllerCore extends AdminStatsTabController
break;
case 'frontoffice_translations':
- $themes = Theme::getThemes();
- $languages = Language::getLanguages();
- $total = $translated = 0;
- foreach ($themes as $theme) {
- /** @var Theme $theme */
- foreach ($languages as $language) {
- $kpi_key = substr(strtoupper($theme->name.'_'.$language['iso_code']), 0, 16);
- $total += ConfigurationKPI::get('FRONTOFFICE_TRANSLATE_TOTAL_'.$kpi_key);
- $translated += ConfigurationKPI::get('FRONTOFFICE_TRANSLATE_DONE_'.$kpi_key);
- }
- }
- $value = 0;
- if ($translated) {
- $value = round(100 * $translated / $total, 1);
- }
- $value .= '%';
- ConfigurationKPI::updateValue('FRONTOFFICE_TRANSLATIONS', $value);
- ConfigurationKPI::updateValue('FRONTOFFICE_TRANSLATIONS_EXPIRE', strtotime('+2 min'));
+ $value = self::getFrontOfficeTranslations();
break;
case 'backoffice_translations':
- $languages = Language::getLanguages();
- $total = $translated = 0;
- foreach ($languages as $language) {
- $kpi_key = substr(strtoupper($language['iso_code']), 0, 16);
- $total += ConfigurationKPI::get('BACKOFFICE_TRANSLATE_TOTAL_'.$kpi_key);
- $translated += ConfigurationKPI::get('BACKOFFICE_TRANSLATE_DONE_'.$kpi_key);
- }
- $value = 0;
- if ($translated) {
- $value = round(100 * $translated / $total, 1);
- }
- $value .= '%';
- ConfigurationKPI::updateValue('BACKOFFICE_TRANSLATIONS', $value);
- ConfigurationKPI::updateValue('BACKOFFICE_TRANSLATIONS_EXPIRE', strtotime('+2 min'));
+ $value = self::getBackOfficeTranslations();
break;
case 'main_country':
@@ -857,6 +820,35 @@ class AdminStatsControllerCore extends AdminStatsTabController
die(json_encode(array('has_errors' => true)));
}
+ public static function getFrontOfficeTranslations()
+ {
+ $themes = Theme::getThemes();
+ $languages = Language::getLanguages();
+ $total = $translated = 0;
+ foreach ($themes as $theme) {
+ foreach ($languages as $language) {
+ $result = Translate::getTranslationsCountFrontOffice($theme->name, $language['iso_code']);
+ $total += $result['total'];
+ $translated += $result['translated'];
+ }
+ }
+
+ return sprintf('%0.2f', $total ? ($translated / $total) * 100 : 0).'%';
+ }
+
+ public static function getBackOfficeTranslations()
+ {
+ $languages = Language::getLanguages();
+ $total = $translated = 0;
+ foreach ($languages as $language) {
+ $result = Translate::getTranslationsCountBackOffice($language['iso_code']);
+ $total += $result['total'];
+ $translated += $result['translated'];
+ }
+
+ return sprintf('%0.2f', $total ? ($translated / $total) * 100 : 0).'%';
+ }
+
public static function getArrivalsByDate($date, $idHotel = false)
{
$totalArrivals = Db::getInstance()->getValue(
@@ -1020,7 +1012,10 @@ class AdminStatsControllerCore extends AdminStatsTabController
return $occupancyData;
}
- public static function getAvailabilityLineChartData($days, $dateFrom, $idHotel = null) // $dateFrom is inclusive
+ /**
+ * $dateFrom is inclusive
+ */
+ public static function getAvailabilityLineChartData($days, $dateFrom, $idHotel = null)
{
if ($days == 0) {
return array();
@@ -1041,33 +1036,49 @@ class AdminStatsControllerCore extends AdminStatsTabController
return $availabilityData;
}
- public static function getAverageDailyRate($dateFrom, $dateTo, $idHotel = null)
+ public static function getAverageDailyRateForDiscreteDates($dateFrom, $dateTo, $idHotel = null)
{
if ($dateFrom == $dateTo) {
$dateTo = date('Y-m-d', strtotime('+1 day', strtotime($dateTo)));
}
$occupiedRooms = self::getOccupiedRoomsForDiscreteDates($dateFrom, $dateTo, $idHotel);
- $roomsRevenues = self::getRoomsRevenuesForDiscreteDates($dateFrom, $dateTo, $idHotel);
+ $roomsRevenues = self::getRoomsRevenueForDiscreteDates($dateFrom, $dateTo, $idHotel);
if (count($occupiedRooms) != count($roomsRevenues)) {
return false;
}
- $divisor = 0;
- $sumADRs = 0;
+ $averageDailyRates = array();
foreach ($occupiedRooms as $key => $occupiedRoom) {
- if ($occupiedRoom == 0) {
- unset($occupiedRooms[$key]);
- unset($roomsRevenues[$key]);
- continue;
- }
-
- $sumADRs += ($occupiedRoom ? ($roomsRevenues[$key] / $occupiedRoom) : 0);
- $divisor++;
+ $averageDailyRates[$key] = $occupiedRoom ? $roomsRevenues[$key] / $occupiedRoom : 0;
}
- return Tools::displayPrice($divisor ? ($sumADRs / $divisor) : 0);
+ return $averageDailyRates;
+ }
+
+ public static function getAverageDailyRate($dateFrom, $dateTo, $idHotel = null)
+ {
+ if ($dateFrom == $dateTo) {
+ $dateTo = date('Y-m-d', strtotime('+1 day', strtotime($dateTo)));
+ }
+
+ $averageDailyRates = self::getAverageDailyRateForDiscreteDates($dateFrom, $dateTo, $idHotel);
+
+ if (!is_array($averageDailyRates)) {
+ return 0;
+ }
+
+ $sumAverageDailyRates = 0;
+ $countAverageDailyRates = 0;
+ foreach ($averageDailyRates as $averageDailyRate) {
+ if ($averageDailyRate != 0) {
+ $sumAverageDailyRates += $averageDailyRate;
+ $countAverageDailyRates++;
+ }
+ }
+
+ return $countAverageDailyRates ? $sumAverageDailyRates / $countAverageDailyRates : 0;
}
public static function getCancellationRate($dateFrom, $dateTo, $idHotel = false)
@@ -1092,9 +1103,9 @@ class AdminStatsControllerCore extends AdminStatsTabController
);
if ($numAllOrders != 0) {
- return Tools::ps_round(($numCancelledOrders / $numAllOrders) * 100, 2).'%';
+ return $numCancelledOrders / $numAllOrders * 100;
} else {
- return '0.00%';
+ return 0;
}
}
@@ -1112,18 +1123,19 @@ class AdminStatsControllerCore extends AdminStatsTabController
) AS id_hotel
FROM `'._DB_PREFIX_.'orders` o
LEFT JOIN `' ._DB_PREFIX_.'order_return` orr ON orr.`id_order` = o.`id_order`
- WHERE o.`invoice_date` BETWEEN "'.pSQL($dateFrom).' 00:00:00" AND "'.pSQL($dateTo).' 23:59:59"
+ WHERE o.`valid` = 1 AND o.`invoice_date` BETWEEN "'.pSQL($dateFrom).' 00:00:00" AND "'.pSQL($dateTo).' 23:59:59"
HAVING 1 '.HotelBranchInformation::addHotelRestriction($idHotel).'
) AS t'
);
- return Tools::displayPrice($result ? $result : 0);
+ return $result ? $result : 0;
}
public static function getNightsStayed($dateFrom, $dateTo, $idHotel = false)
{
$dateFrom = date('Y-m-d H:i:s', strtotime($dateFrom));
$dateTo = date('Y-m-d H:i:s', strtotime($dateTo));
+
return Db::getInstance()->getValue(
'SELECT IFNULL(SUM(DATEDIFF(
IF (hbd.`id_status` = '.(int) HotelBookingDetail::STATUS_CHECKED_OUT.', IF ("'.$dateTo.'" > check_out, check_out, "'.$dateTo.'"), IF ("'.$dateTo.'" > date_to, date_to, "'.$dateTo.'")),
@@ -1134,8 +1146,7 @@ class AdminStatsControllerCore extends AdminStatsTabController
(IF (hbd.`id_status` = '.(int) HotelBookingDetail::STATUS_CHECKED_OUT.',
(hbd.`check_in` < \''.pSQL($dateTo).'\' AND hbd.`check_out` >= \''.pSQL($dateFrom).'\'),
(hbd.`date_from` < \''.pSQL($dateTo).'\' AND hbd.`date_to` >= \''.pSQL($dateFrom).'\')
- ))'.
- HotelBranchInformation::addHotelRestriction($idHotel, 'hbd')
+ ))'.HotelBranchInformation::addHotelRestriction($idHotel, 'hbd')
);
}
@@ -1164,20 +1175,20 @@ class AdminStatsControllerCore extends AdminStatsTabController
$dateTo = !$dateTo ? date('Y-m-d', strtotime('+1 day', strtotime($dateFrom))) : $dateTo;
$discreteDates = array();
- $date = $dateFrom;
- while ($date < $dateTo) {
- $dateNext = date('Y-m-d', strtotime('+1 day', strtotime($date)));
+ $dateTemp = $dateFrom;
+ while ($dateTemp <= $dateTo) {
+ $dateNext = date('Y-m-d', strtotime('+1 day', strtotime($dateTemp)));
$discreteDates[] = array(
- 'date_from' => $date,
+ 'date_from' => $dateTemp,
'date_to' => $dateNext,
- 'timestamp_from' => strtotime($date),
+ 'timestamp_from' => strtotime($dateTemp),
);
- $date = $dateNext;
+ $dateTemp = $dateNext;
};
$result = array();
foreach ($discreteDates as $discreteDate) {
- $cacheKey = 'AdminStats::getOccupiedRoomsForDiscreteDates_'.(int) $discreteDate['timestamp_from'].'_'.
+ $cacheKey = 'AdminStats::getOccupiedRoomsForDiscreteDates'.'_'.(int) $discreteDate['timestamp_from'].'_'.
(!is_array($idHotel) ? (int) $idHotel : implode('_', $idHotel));
if (!Cache::isStored($cacheKey) || !$useCache) {
$sql = 'SELECT COUNT(DISTINCT hbd.`id_room`)
@@ -1201,33 +1212,31 @@ class AdminStatsControllerCore extends AdminStatsTabController
return $result;
}
- public static function getRoomsRevenuesForDiscreteDates($dateFrom, $dateTo = null, $idHotel = null, $useCache = true)
+ public static function getRoomsRevenueForDiscreteDates($dateFrom, $dateTo = null, $idHotel = null, $useCache = true)
{
$dateTo = !$dateTo ? date('Y-m-d', strtotime('+1 day', strtotime($dateFrom))) : $dateTo;
$discreteDates = array();
- $date = $dateFrom;
- while ($date < $dateTo) {
- $dateNext = date('Y-m-d', strtotime('+1 day', strtotime($date)));
+ $dateTemp = $dateFrom;
+ while ($dateTemp <= $dateTo) {
+ $dateNext = date('Y-m-d', strtotime('+1 day', strtotime($dateTemp)));
$discreteDates[] = array(
- 'date_from' => $date,
+ 'date_from' => $dateTemp,
'date_to' => $dateNext,
- 'timestamp_from' => strtotime($date),
+ 'timestamp_from' => strtotime($dateTemp),
);
- $date = $dateNext;
+ $dateTemp = $dateNext;
};
$result = array();
foreach ($discreteDates as $discreteDate) {
- $cacheKey = 'AdminStats::getRoomsRevenuesForDiscreteDates'.(int) $discreteDate['timestamp_from'].'_'.
+ $cacheKey = 'AdminStats::getRoomsRevenueForDiscreteDates'.'_'.(int) $discreteDate['timestamp_from'].'_'.
(!is_array($idHotel) ? (int) $idHotel : implode('_', $idHotel));
if (!Cache::isStored($cacheKey) || !$useCache) {
$sql = 'SELECT IFNULL(SUM(hbd.`total_price_tax_excl` / DATEDIFF(hbd.`date_to`, hbd.`date_from`)), 0)
FROM `'._DB_PREFIX_.'htl_booking_detail` hbd
- LEFT JOIN `'._DB_PREFIX_.'htl_room_information` hri
- ON (hri.`id` = hbd.`id_room`)
LEFT JOIN `'._DB_PREFIX_.'product` p
- ON (p.`id_product` = hri.`id_product`)
+ ON (p.`id_product` = hbd.`id_product`)
WHERE p.`active` = 1
AND hbd.`is_refunded` = 0
AND hbd.`date_from` < "'.pSQL($discreteDate['date_to']).' 00:00:00" AND hbd.`date_to` > "'.pSQL($discreteDate['date_from']).' 00:00:00"'.
@@ -1243,24 +1252,166 @@ class AdminStatsControllerCore extends AdminStatsTabController
return $result;
}
- public static function getAvailableRoomsForDiscreteDates($dateFrom, $dateTo = null, $idHotel = null, $useCache = true)
+ public static function getTotalRevenueForDiscreteDates($dateFrom, $dateTo = null, $idHotel = null, $useCache = true)
{
$dateTo = !$dateTo ? date('Y-m-d', strtotime('+1 day', strtotime($dateFrom))) : $dateTo;
+
$discreteDates = array();
- $date = $dateFrom;
- while ($date < $dateTo) {
- $dateNext = date('Y-m-d', strtotime('+1 day', strtotime($date)));
+ $dateTemp = $dateFrom;
+ while ($dateTemp <= $dateTo) {
+ $dateNext = date('Y-m-d', strtotime('+1 day', strtotime($dateTemp)));
$discreteDates[] = array(
- 'date_from' => $date,
+ 'date_from' => $dateTemp,
'date_to' => $dateNext,
- 'timestamp_from' => strtotime($date),
+ 'timestamp_from' => strtotime($dateTemp),
);
- $date = $dateNext;
+ $dateTemp = $dateNext;
};
$result = array();
foreach ($discreteDates as $discreteDate) {
- $cacheKey = 'AdminStats::getAvailableRoomsForDiscreteDates'.(int) $discreteDate['timestamp_from'].'_'.
+ $cacheKey = 'AdminStats::getTotalRevenueForDiscreteDates'.'_'.(int) $discreteDate['timestamp_from'].'_'.
+ (!is_array($idHotel) ? (int) $idHotel : implode('_', $idHotel));
+ if (!Cache::isStored($cacheKey) || !$useCache) {
+ $sql = 'SELECT SUM((current_parts / total_parts) * total_paid_tax_excl) AS total_revenue
+ FROM (
+ SELECT o.`id_order`,
+ o.`total_paid_tax_excl` / o.`conversion_rate` AS total_paid_tax_excl,
+ (
+ SELECT SUM(DATEDIFF(hbd.`date_to`, hbd.`date_from`))
+ FROM `'._DB_PREFIX_.'htl_booking_detail` hbd
+ INNER JOIN `'._DB_PREFIX_.'product` p
+ ON (p.`id_product` = hbd.`id_product`)
+ WHERE hbd.`id_order` = o.`id_order`
+ AND p.`active` = 1 AND hbd.`is_refunded` = 0'.
+ (!is_null($idHotel) ? HotelBranchInformation::addHotelRestriction($idHotel, 'hbd') : '').'
+ ) AS total_parts,
+ (
+ SELECT COUNT(*)
+ FROM `'._DB_PREFIX_.'htl_booking_detail` hbd
+ INNER JOIN `'._DB_PREFIX_.'product` p
+ ON (p.`id_product` = hbd.`id_product`)
+ WHERE hbd.`id_order` = o.`id_order`
+ AND hbd.`date_from` <= "'.pSQL($discreteDate['date_from']).' 00:00:00" AND hbd.`date_to` >= "'.pSQL($discreteDate['date_to']).' 00:00:00"
+ AND p.`active` = 1 AND hbd.`is_refunded` = 0'.
+ (!is_null($idHotel) ? HotelBranchInformation::addHotelRestriction($idHotel, 'hbd') : '').'
+ ) AS current_parts
+ FROM `'._DB_PREFIX_.'orders` o
+ HAVING total_parts IS NOT NULL AND current_parts > 0
+ ORDER BY o.`id_order`
+ ) AS t';
+
+ $value = Db::getInstance()->getValue($sql);
+ $value = !$value ? 0: (float) $value;
+ Cache::store($cacheKey, $value);
+ }
+
+ $result[$discreteDate['timestamp_from']] = Cache::retrieve($cacheKey);
+ }
+
+ return $result;
+ }
+
+ /**
+ * total rooms (available for booking) for each date
+ */
+ public static function getTotalRoomsForDiscreteDates($dateFrom, $dateTo = null, $idHotel = null, $useCache = true)
+ {
+ $dateTo = !$dateTo ? date('Y-m-d', strtotime('+1 day', strtotime($dateFrom))) : $dateTo;
+
+ $discreteDates = array();
+ $dateTemp = $dateFrom;
+ while ($dateTemp <= $dateTo) {
+ $dateNext = date('Y-m-d', strtotime('+1 day', strtotime($dateTemp)));
+ $discreteDates[] = array(
+ 'date_from' => $dateTemp,
+ 'date_to' => $dateNext,
+ 'timestamp_from' => strtotime($dateTemp),
+ );
+ $dateTemp = $dateNext;
+ };
+
+ $result = array();
+ foreach ($discreteDates as $discreteDate) {
+ $cacheKey = 'AdminStats::getTotalRoomsForDiscreteDates'.'_'.(int) $discreteDate['timestamp_from'].'_'.
+ (!is_array($idHotel) ? (int) $idHotel : implode('_', $idHotel));
+ if (!Cache::isStored($cacheKey) || !$useCache) {
+ $sql = 'SELECT (num_total_added - num_inactive - num_temporarily_inactive) AS num_total
+ FROM (
+ SELECT (
+ SELECT IFNULL(COUNT(hri.`id`), 0)
+ FROM `'._DB_PREFIX_.'htl_room_information` hri
+ LEFT JOIN `'._DB_PREFIX_.'product` p
+ ON (p.`id_product` = hri.`id_product`)
+ WHERE p.`active` = 1'.
+ (!is_null($idHotel) ? HotelBranchInformation::addHotelRestriction($idHotel, 'hri') : '').'
+ ) AS num_total_added,
+ (
+ SELECT COUNT(DISTINCT hbd.`id_room`)
+ FROM `'._DB_PREFIX_.'htl_booking_detail` hbd
+ LEFT JOIN `'._DB_PREFIX_.'htl_room_information` hri
+ ON (hri.`id` = hbd.`id_room`)
+ LEFT JOIN `'._DB_PREFIX_.'product` p
+ ON (p.`id_product` = hri.`id_product`)
+ WHERE p.`active` = 1
+ AND hbd.`is_refunded` = 0
+ AND hbd.`date_from` < "'.pSQL($discreteDate['date_to']).' 00:00:00" AND hbd.`date_to` > "'.pSQL($discreteDate['date_from']).' 00:00:00"'.
+ (!is_null($idHotel) ? HotelBranchInformation::addHotelRestriction($idHotel, 'hbd') : '').'
+ ) AS num_booked,
+ (
+ SELECT IFNULL(COUNT(hri.`id`), 0)
+ FROM `'._DB_PREFIX_.'htl_room_information` hri
+ LEFT JOIN `'._DB_PREFIX_.'product` p
+ ON (p.`id_product` = hri.`id_product`)
+ WHERE hri.`id_status` = '.(int) HotelRoomInformation::STATUS_INACTIVE.'
+ AND p.`active` = 1'.
+ (!is_null($idHotel) ? HotelBranchInformation::addHotelRestriction($idHotel, 'hri') : '').'
+ ) AS num_inactive,
+ (
+ SELECT IFNULL(COUNT(hri.`id`), 0)
+ FROM `'._DB_PREFIX_.'htl_room_information` hri
+ LEFT JOIN `'._DB_PREFIX_.'htl_room_disable_dates` hrdd
+ ON (hrdd.`id_room` = hri.`id`)
+ LEFT JOIN `'._DB_PREFIX_.'product` p
+ ON (p.`id_product` = hri.`id_product`)
+ WHERE hri.`id_status` = '.(int) HotelRoomInformation::STATUS_TEMPORARY_INACTIVE.'
+ AND ("'.pSQL($discreteDate['date_from']).'" >= hrdd.`date_from` AND "'.pSQL($discreteDate['date_from']).'" < hrdd.`date_to`)
+ AND p.`active` = 1'.
+ (!is_null($idHotel) ? HotelBranchInformation::addHotelRestriction($idHotel, 'hri') : '').'
+ ) AS num_temporarily_inactive
+ ) AS t';
+
+ $value = Db::getInstance()->getValue($sql);
+ Cache::store($cacheKey, $value);
+ }
+
+ $result[$discreteDate['timestamp_from']] = Cache::retrieve($cacheKey);
+ }
+
+ return $result;
+ }
+
+ /**
+ * total available (unoccupied) for each date
+ */
+ public static function getAvailableRoomsForDiscreteDates($dateFrom, $dateTo = null, $idHotel = null, $useCache = true)
+ {
+ $dateTo = !$dateTo ? date('Y-m-d', strtotime('+1 day', strtotime($dateFrom))) : $dateTo;
+ $discreteDates = array();
+ $dateTemp = $dateFrom;
+ while ($dateTemp <= $dateTo) {
+ $dateNext = date('Y-m-d', strtotime('+1 day', strtotime($dateTemp)));
+ $discreteDates[] = array(
+ 'date_from' => $dateTemp,
+ 'date_to' => $dateNext,
+ 'timestamp_from' => strtotime($dateTemp),
+ );
+ $dateTemp = $dateNext;
+ };
+
+ $result = array();
+ foreach ($discreteDates as $discreteDate) {
+ $cacheKey = 'AdminStats::getAvailableRoomsForDiscreteDates'.'_'.(int) $discreteDate['timestamp_from'].'_'.
(!is_array($idHotel) ? (int) $idHotel : implode('_', $idHotel));
if (!Cache::isStored($cacheKey) || !$useCache) {
$sql = 'SELECT (num_total - num_booked - num_inactive - num_temporarily_inactive) AS num_available
@@ -1317,4 +1468,242 @@ class AdminStatsControllerCore extends AdminStatsTabController
return $result;
}
+
+ public static function getOccupancyRateForDiscreteDates($dateFrom, $dateTo, $idHotel = null)
+ {
+ if ($dateFrom == $dateTo) {
+ $dateTo = date('Y-m-d', strtotime('+1 day', strtotime($dateTo)));
+ }
+
+ $occupiedRooms = self::getOccupiedRoomsForDiscreteDates($dateFrom, $dateTo, $idHotel);
+ $totalRooms = self::getTotalRoomsForDiscreteDates($dateFrom, $dateTo, $idHotel);
+
+ if (count($occupiedRooms) != count($totalRooms)) {
+ return false;
+ }
+
+ $occupancyRates = array();
+ foreach ($totalRooms as $key => $totalRoom) {
+ $occupancyRates[$key] = $totalRoom ? $occupiedRooms[$key] / $totalRoom : 0;
+ }
+
+ return $occupancyRates;
+ }
+
+ public static function getAverageOccupancyRate($dateFrom, $dateTo, $idHotel = null)
+ {
+ if ($dateFrom == $dateTo) {
+ $dateTo = date('Y-m-d', strtotime('+1 day', strtotime($dateTo)));
+ }
+
+ $occupancyRates = self::getOccupancyRateForDiscreteDates($dateFrom, $dateTo, $idHotel);
+
+ if (!is_array($occupancyRates)) {
+ return 0;
+ }
+
+ return array_sum($occupancyRates) / count($occupancyRates);
+ }
+
+ public static function getRevenuePerAvailableRoom($dateFrom, $dateTo, $idHotel = null)
+ {
+ if ($dateFrom == $dateTo) {
+ $dateTo = date('Y-m-d', strtotime('+1 day', strtotime($dateTo)));
+ }
+
+ $averageDailyRates = self::getAverageDailyRateForDiscreteDates($dateFrom, $dateTo, $idHotel);
+ $occupancyRates = self::getOccupancyRateForDiscreteDates($dateFrom, $dateTo, $idHotel);
+
+ if (count($averageDailyRates) != count($occupancyRates)) {
+ return false;
+ }
+
+ $sumRevPars = 0;
+ $countRevPars = 0;
+ foreach ($averageDailyRates as $key => $averageDailyRate) {
+ if ($averageDailyRate != 0) {
+ $sumRevPars += ($averageDailyRate * $occupancyRates[$key]);
+ $countRevPars++;
+ }
+ }
+
+ return $countRevPars ? $sumRevPars / $countRevPars : 0;
+ }
+
+ public static function getTotalRevenuePerAvailableRoom($dateFrom, $dateTo, $idHotel = null)
+ {
+ if ($dateFrom == $dateTo) {
+ $dateTo = date('Y-m-d', strtotime('+1 day', strtotime($dateTo)));
+ }
+
+ $totalRevenues = self::getTotalRevenueForDiscreteDates($dateFrom, $dateTo, $idHotel);
+ $totalRooms = self::getTotalRoomsForDiscreteDates($dateFrom, $dateTo, $idHotel);
+
+ if (count($totalRevenues) != count($totalRooms)) {
+ return false;
+ }
+
+ $sumTrevPars = 0;
+ $countTrevPars = 0;
+ foreach ($totalRevenues as $key => $totalRevenue) {
+ if ($totalRevenue != 0) {
+ $sumTrevPars += ($totalRevenue / $totalRooms[$key]);
+ $countTrevPars++;
+ }
+ }
+
+ return $countTrevPars ? $sumTrevPars / $countTrevPars : 0;
+ }
+
+ public static function getAverageLengthOfStay($dateFrom, $dateTo, $idHotel = null)
+ {
+ if ($dateFrom == $dateTo) {
+ $dateTo = date('Y-m-d', strtotime('+1 day', strtotime($dateTo)));
+ }
+
+ $sql = 'SELECT AVG(DATEDIFF(hbd.`date_to`, hbd.`date_from`))
+ FROM `'._DB_PREFIX_.'htl_booking_detail` hbd
+ LEFT JOIN `'._DB_PREFIX_.'product` p
+ ON (p.`id_product` = hbd.`id_product`)
+ WHERE p.`active` = 1
+ AND hbd.`is_refunded` = 0
+ AND hbd.`date_from` < "'.pSQL($dateTo).' 00:00:00" AND hbd.`date_to` > "'.pSQL($dateFrom).' 00:00:00"'.
+ (!is_null($idHotel) ? HotelBranchInformation::addHotelRestriction($idHotel, 'hbd') : '');
+ $result = Db::getInstance()->getValue($sql);
+
+ return $result ? $result : 0;
+ }
+
+ public static function getDirectRevenueRatio($dateFrom, $dateTo, $idHotel = null)
+ {
+ if ($dateFrom == $dateTo) {
+ $dateTo = date('Y-m-d', strtotime('+1 day', strtotime($dateTo)));
+ }
+
+ $sql = 'SELECT SUM(total_paid_tax_excl)
+ FROM (
+ SELECT o.`id_order`, o.`total_paid_tax_excl` / o.`conversion_rate` AS total_paid_tax_excl,
+ (SELECT hbd.`id_hotel`
+ FROM `'._DB_PREFIX_.'htl_booking_detail` hbd
+ WHERE hbd.`id_order` = o.`id_order` LIMIT 1
+ ) AS id_hotel
+ FROM `'._DB_PREFIX_.'orders` o
+ INNER JOIN `'._DB_PREFIX_.'htl_booking_detail` hbd
+ ON (hbd.`id_order` = o.`id_order`)
+ INNER JOIN `'._DB_PREFIX_.'htl_branch_info` hbi
+ ON (hbi.`id` = hbd.`id_hotel`)
+ WHERE o.`valid` = 1 AND hbi.`active` = 1 AND hbd.`is_refunded` = 0
+ AND o.`invoice_date` BETWEEN "'.pSQL($dateFrom).' 00:00:00" AND "'.pSQL($dateTo).' 23:59:59"
+ AND o.`source` = "'.pSQL(Configuration::get('PS_SHOP_DOMAIN')).'"'.
+ (!is_null($idHotel) ? HotelBranchInformation::addHotelRestriction($idHotel, 'hbd') : '').
+ 'GROUP BY o.`id_order`
+ ) AS t';
+ $directRevenue = (float) Db::getInstance()->getValue($sql);
+
+ $totalRevenue = (float) self::getRevenue($dateFrom, $dateTo, $idHotel);
+
+ return $totalRevenue ? ($directRevenue / $totalRevenue) * 100 : 0;
+ }
+
+ public static function getOperatingExpensesForDiscreteDates($dateFrom, $dateTo = null, $idHotel = null, $useCache = true)
+ {
+ $dateTo = !$dateTo ? date('Y-m-d', strtotime('+1 day', strtotime($dateFrom))) : $dateTo;
+
+ $discreteDates = array();
+ $dateTemp = $dateFrom;
+ while ($dateTemp <= $dateTo) {
+ $dateNext = date('Y-m-d', strtotime('+1 day', strtotime($dateTemp)));
+ $discreteDates[] = array(
+ 'date_from' => $dateTemp,
+ 'date_to' => $dateNext,
+ 'timestamp_from' => strtotime($dateTemp),
+ );
+ $dateTemp = $dateNext;
+ };
+
+ $result = array();
+ foreach ($discreteDates as $discreteDate) {
+ $cacheKey = 'AdminStats::getOperatingExpensesForDiscreteDates'.'_'.(int) $discreteDate['timestamp_from'].'_'.
+ (!is_array($idHotel) ? (int) $idHotel : implode('_', $idHotel));
+ if (!Cache::isStored($cacheKey) || !$useCache) {
+ $sql = 'SELECT
+ IFNULL(SUM(
+ CASE
+ WHEN od.`original_wholesale_price` <> "0.000000"
+ THEN od.`original_wholesale_price`
+ WHEN p.`wholesale_price` <> "0.000000"
+ THEN p.`wholesale_price`
+ END
+ ), 0)
+ FROM `'._DB_PREFIX_.'htl_booking_detail` hbd
+ LEFT JOIN `'._DB_PREFIX_.'product` p
+ ON (p.`id_product` = hbd.`id_product`)
+ LEFT JOIN `'._DB_PREFIX_.'order_detail` od
+ ON (od.`id_order_detail` = hbd.`id_order_detail`)
+ WHERE p.`active` = 1
+ AND hbd.`is_refunded` = 0
+ AND hbd.`date_from` < "'.pSQL($discreteDate['date_to']).' 00:00:00" AND hbd.`date_to` > "'.pSQL($discreteDate['date_from']).' 00:00:00"'.
+ (!is_null($idHotel) ? HotelBranchInformation::addHotelRestriction($idHotel, 'hbd') : '');
+
+ $value = Db::getInstance()->getValue($sql);
+ Cache::store($cacheKey, $value);
+ }
+
+ $result[$discreteDate['timestamp_from']] = Cache::retrieve($cacheKey);
+ }
+
+ return $result;
+ }
+
+ public static function getGrossOperatingProfitPerAvailableRoomForDiscreteDates($dateFrom, $dateTo, $idHotel = null)
+ {
+ if ($dateFrom == $dateTo) {
+ $dateTo = date('Y-m-d', strtotime('+1 day', strtotime($dateTo)));
+ }
+
+ $roomsRevenues = self::getRoomsRevenueForDiscreteDates($dateFrom, $dateTo, $idHotel);
+ $operatingExpenses = self::getOperatingExpensesForDiscreteDates($dateFrom, $dateTo, $idHotel);
+ $totalRooms = self::getTotalRoomsForDiscreteDates($dateFrom, $dateTo, $idHotel);
+
+ if (!(count($roomsRevenues) == count($operatingExpenses)
+ && count($operatingExpenses) == count($totalRooms))
+ ) {
+ return false;
+ }
+
+ $operatingProfits = array();
+ foreach ($roomsRevenues as $key => $roomsRevenue) {
+ if ($roomsRevenue != 0 && $totalRooms[$key] != 0) {
+ $operatingProfits[$key] = (($roomsRevenue - $operatingExpenses[$key]) / $totalRooms[$key]);
+ } else {
+ $operatingProfits[$key] = 0;
+ }
+ }
+
+ return $operatingProfits;
+ }
+
+ public static function getGrossOperatingProfitPerAvailableRoom($dateFrom, $dateTo, $idHotel = null)
+ {
+ if ($dateFrom == $dateTo) {
+ $dateTo = date('Y-m-d', strtotime('+1 day', strtotime($dateTo)));
+ }
+
+ $grossOpProfitPars = self::getGrossOperatingProfitPerAvailableRoomForDiscreteDates($dateFrom, $dateTo, $idHotel);
+
+ if (!count($grossOpProfitPars)) {
+ return false;
+ }
+
+ $sumGrossOpProfitPars = 0;
+ $countGrossOpProfitPars = 0;
+ foreach ($grossOpProfitPars as $grossOpProfitPar) {
+ if ($grossOpProfitPar != 0) {
+ $sumGrossOpProfitPars += $grossOpProfitPar;
+ $countGrossOpProfitPars++;
+ }
+ }
+
+ return $countGrossOpProfitPars ? $sumGrossOpProfitPars / $countGrossOpProfitPars : 0;
+ }
}
diff --git a/controllers/admin/AdminStatsTabController.php b/controllers/admin/AdminStatsTabController.php
index 72c2b2e85..3a369c51c 100644
--- a/controllers/admin/AdminStatsTabController.php
+++ b/controllers/admin/AdminStatsTabController.php
@@ -104,6 +104,7 @@ abstract class AdminStatsTabControllerCore extends AdminPreferencesControllerCor
$module = Tools::getValue('module');
$action .= ($module ? '&module='.Tools::safeOutput($module) : '');
$action .= (($id_product = Tools::getValue('id_product')) ? '&id_product='.Tools::safeOutput($id_product) : '');
+ $action .= (($id_hotel = Tools::getValue('id_hotel')) ? '&id_hotel='.Tools::safeOutput($id_hotel) : '');
$tpl->assign(array(
'current' => self::$currentIndex,
'token' => $token,
@@ -150,13 +151,8 @@ abstract class AdminStatsTabControllerCore extends AdminPreferencesControllerCor
$tpl = $this->createTemplate('menu.tpl');
$modules = $this->getModules();
- $key_statsforecast = null;
$module_instance = array();
foreach ($modules as $m => $module) {
- if ($module['name'] == 'statsforecast') {
- $key_statsforecast = $m;
- }
-
if ($module_instance[$module['name']] = Module::getInstanceByName($module['name'])) {
$modules[$m]['displayName'] = $module_instance[$module['name']]->displayName;
} else {
@@ -166,9 +162,6 @@ abstract class AdminStatsTabControllerCore extends AdminPreferencesControllerCor
}
uasort($modules, array($this, 'checkModulesNames'));
- if (!is_null($key_statsforecast)) {
- $modules = array($key_statsforecast => $modules[$key_statsforecast]) + $modules;
- }
$tpl->assign(array(
'current' => self::$currentIndex,
diff --git a/controllers/admin/AdminTranslationsController.php b/controllers/admin/AdminTranslationsController.php
index 87f8e3f5e..3ad0893ad 100644
--- a/controllers/admin/AdminTranslationsController.php
+++ b/controllers/admin/AdminTranslationsController.php
@@ -45,9 +45,6 @@ class AdminTranslationsControllerCore extends AdminController
/** @var array */
protected $modules_translations = array();
- /** @var array : List of folder which must be ignored */
- protected static $ignore_folder = array('.', '..', '.svn', '.git', '.htaccess', 'index.php');
-
/** @var array : List of theme by translation type : FRONT, BACK, ERRORS... */
protected $translations_informations = array();
@@ -320,23 +317,6 @@ class AdminTranslationsControllerCore extends AdminController
}
}
- if (in_array($this->type_selected, array('front', 'back'))) {
- if ($this->type_selected == 'front') {
- $thm_name = str_replace('.', '', Tools::getValue('theme'));
- $kpi_key = substr(strtoupper($thm_name.'_'.Tools::getValue('lang')), 0, 16);
-
- ConfigurationKPI::updateValue('FRONTOFFICE_TRANSLATIONS_EXPIRE', time());
- ConfigurationKPI::updateValue('FRONTOFFICE_TRANSLATE_TOTAL_'.$kpi_key, count($_POST));
- ConfigurationKPI::updateValue('FRONTOFFICE_TRANSLATE_DONE_'.$kpi_key, count($to_insert));
- } else {
- $kpi_key = substr(strtoupper(Tools::getValue('lang')), 0, 16);
-
- ConfigurationKPI::updateValue('BACKOFFICE_TRANSLATIONS_EXPIRE', time());
- ConfigurationKPI::updateValue('BACKOFFICE_TRANSLATE_TOTAL_'.$kpi_key, count($_POST));
- ConfigurationKPI::updateValue('BACKOFFICE_TRANSLATE_DONE_'.$kpi_key, count($to_insert));
- }
- }
-
// translations array is ordered by key (easy merge)
ksort($to_insert);
$tab = $translation_informations['var'];
@@ -546,7 +526,7 @@ class AdminTranslationsControllerCore extends AdminController
// Add mails files
foreach ($arr_mails_needed as $mail_to_add) {
- if (!in_array($mail_to_add, self::$ignore_folder)) {
+ if (!in_array($mail_to_add, Translate::$ignore_folder)) {
@copy(_PS_MAIL_DIR_.$default_language.'/'.$mail_to_add, _PS_MAIL_DIR_.$iso_code.'/'.$mail_to_add);
}
}
@@ -558,11 +538,11 @@ class AdminTranslationsControllerCore extends AdminController
$module_mail_iso_code = array();
foreach ($modules as $module) {
- if (!in_array($module, self::$ignore_folder) && Tools::file_exists_cache(_PS_MODULE_DIR_.$module.'/mails/'.$default_language.'/')) {
+ if (!in_array($module, Translate::$ignore_folder) && Tools::file_exists_cache(_PS_MODULE_DIR_.$module.'/mails/'.$default_language.'/')) {
$arr_files = scandir(_PS_MODULE_DIR_.$module.'/mails/'.$default_language.'/');
foreach ($arr_files as $file) {
- if (!in_array($file, self::$ignore_folder)) {
+ if (!in_array($file, Translate::$ignore_folder)) {
if (Tools::file_exists_cache(_PS_MODULE_DIR_.$module.'/mails/'.$default_language.'/'.$file)) {
$module_mail_en[] = _PS_MODULE_DIR_.$module.'/mails/ISO_CODE/'.$file;
}
@@ -973,7 +953,7 @@ class AdminTranslationsControllerCore extends AdminController
}
foreach ($files as $file) {
- if (preg_match('/^(.*)\.(tpl|php)$/', $file) && Tools::file_exists_cache($dir.$file) && !in_array($file, self::$ignore_folder)) {
+ if (preg_match('/^(.*)\.(tpl|php)$/', $file) && Tools::file_exists_cache($dir.$file) && !in_array($file, Translate::$ignore_folder)) {
// Get content for this file
$content = file_get_contents($dir.$file);
@@ -981,7 +961,7 @@ class AdminTranslationsControllerCore extends AdminController
$type_file = substr($file, -4) == '.tpl' ? 'tpl' : 'php';
// Parse this content
- $matches = $this->userParseFile($content, $this->type_selected, $type_file, $module_name);
+ $matches = Translate::userParseFile($content, $this->type_selected, $type_file, $module_name);
// Write each translation on its module file
$template_name = substr(basename($file), 0, -4);
@@ -1076,7 +1056,7 @@ class AdminTranslationsControllerCore extends AdminController
$type_file = substr($file, -4) == '.tpl' ? 'tpl' : 'php';
// Parse this content
- $matches = $this->userParseFile($content, $this->type_selected, $type_file, $module_name);
+ $matches = Translate::userParseFile($content, $this->type_selected, $type_file, $module_name);
// Write each translation on its module file
$template_name = substr(basename($file), 0, -4);
@@ -1099,7 +1079,7 @@ class AdminTranslationsControllerCore extends AdminController
$this->modules_translations[$theme_name][$module_name][$template_name][$key]['trad'] = '';
$this->missing_translations++;
}
- $this->modules_translations[$theme_name][$module_name][$template_name][$key]['use_sprintf'] = $this->checkIfKeyUseSprintf($key);
+ $this->modules_translations[$theme_name][$module_name][$template_name][$key]['use_sprintf'] = Translate::checkIfKeyUseSprintf($key);
}
}
}
@@ -1118,14 +1098,14 @@ class AdminTranslationsControllerCore extends AdminController
switch ($this->type_selected) {
case 'front':
$directories['tpl'] = array(_PS_ALL_THEMES_DIR_ => scandir(_PS_ALL_THEMES_DIR_));
- self::$ignore_folder[] = 'modules';
- $directories['tpl'] = array_merge($directories['tpl'], $this->listFiles(_PS_THEME_SELECTED_DIR_));
+ Translate::$ignore_folder[] = 'modules';
+ $directories['tpl'] = array_merge($directories['tpl'], Translate::listFiles(_PS_THEME_SELECTED_DIR_));
if (isset($directories['tpl'][_PS_THEME_SELECTED_DIR_.'pdf/'])) {
unset($directories['tpl'][_PS_THEME_SELECTED_DIR_.'pdf/']);
}
if (Tools::file_exists_cache(_PS_THEME_OVERRIDE_DIR_)) {
- $directories['tpl'] = array_merge($directories['tpl'], $this->listFiles(_PS_THEME_OVERRIDE_DIR_));
+ $directories['tpl'] = array_merge($directories['tpl'], Translate::listFiles(_PS_THEME_OVERRIDE_DIR_));
}
break;
@@ -1139,7 +1119,7 @@ class AdminTranslationsControllerCore extends AdminController
_PS_CLASS_DIR_.'controller/' => array('AdminController.php'),
_PS_CLASS_DIR_ => array('PaymentModule.php')
),
- 'tpl' => $this->listFiles(_PS_ADMIN_DIR_.DIRECTORY_SEPARATOR.'themes/'),
+ 'tpl' => Translate::listFiles(_PS_ADMIN_DIR_.DIRECTORY_SEPARATOR.'themes/'),
'specific' => array(
_PS_ADMIN_DIR_.DIRECTORY_SEPARATOR => array(
'header.inc.php',
@@ -1152,7 +1132,7 @@ class AdminTranslationsControllerCore extends AdminController
// For translate the template which are overridden
if (file_exists(_PS_OVERRIDE_DIR_.'controllers'.DIRECTORY_SEPARATOR.'admin'.DIRECTORY_SEPARATOR.'templates')) {
- $directories['tpl'] = array_merge($directories['tpl'], $this->listFiles(_PS_OVERRIDE_DIR_.'controllers'.DIRECTORY_SEPARATOR.'admin'.DIRECTORY_SEPARATOR.'templates'));
+ $directories['tpl'] = array_merge($directories['tpl'], Translate::listFiles(_PS_OVERRIDE_DIR_.'controllers'.DIRECTORY_SEPARATOR.'admin'.DIRECTORY_SEPARATOR.'templates'));
}
break;
@@ -1168,12 +1148,12 @@ class AdminTranslationsControllerCore extends AdminController
);
// Get all files for folders classes/ and override/classes/ recursively
- $directories['php'] = array_merge($directories['php'], $this->listFiles(_PS_CLASS_DIR_, array(), 'php'));
- $directories['php'] = array_merge($directories['php'], $this->listFiles(_PS_OVERRIDE_DIR_.'classes/', array(), 'php'));
+ $directories['php'] = array_merge($directories['php'], Translate::listFiles(_PS_CLASS_DIR_, array(), 'php'));
+ $directories['php'] = array_merge($directories['php'], Translate::listFiles(_PS_OVERRIDE_DIR_.'classes/', array(), 'php'));
break;
case 'fields':
- $directories['php'] = $this->listFiles(_PS_CLASS_DIR_, array(), 'php');
+ $directories['php'] = Translate::listFiles(_PS_CLASS_DIR_, array(), 'php');
break;
case 'pdf':
@@ -1203,8 +1183,8 @@ class AdminTranslationsControllerCore extends AdminController
);
// Get all files for folders classes/ and override/classes/ recursively
- $directories['php'] = array_merge($directories['php'], $this->listFiles(_PS_CLASS_DIR_, array(), 'php'));
- $directories['php'] = array_merge($directories['php'], $this->listFiles(_PS_OVERRIDE_DIR_.'classes/', array(), 'php'));
+ $directories['php'] = array_merge($directories['php'], Translate::listFiles(_PS_CLASS_DIR_, array(), 'php'));
+ $directories['php'] = array_merge($directories['php'], Translate::listFiles(_PS_OVERRIDE_DIR_.'classes/', array(), 'php'));
$directories['php'] = array_merge($directories['php'], $this->getModulesHasMails());
break;
@@ -1213,88 +1193,6 @@ class AdminTranslationsControllerCore extends AdminController
return $directories;
}
- /**
- * This method parse a file by type of translation and type file
- *
- * @param $content
- * @param $type_translation : front, back, errors, modules...
- * @param string|bool $type_file : (tpl|php)
- * @param string $module_name : name of the module
- * @return array
- */
- protected function userParseFile($content, $type_translation, $type_file = false, $module_name = '')
- {
- switch ($type_translation) {
- case 'front':
- // Parsing file in Front office
- $regex = '/\{l\s*s=([\'\"])'._PS_TRANS_PATTERN_.'\1(\s*sprintf=.*)?(\s*js=1)?\s*\}/U';
- break;
-
- case 'back':
- // Parsing file in Back office
- if ($type_file == 'php') {
- $regex = '/this->l\((\')'._PS_TRANS_PATTERN_.'\'[\)|\,]/U';
- } elseif ($type_file == 'specific') {
- $regex = '/Translate::getAdminTranslation\((\')'._PS_TRANS_PATTERN_.'\'(?:,.*)*\)/U';
- } else {
- $regex = '/\{l\s*s\s*=([\'\"])'._PS_TRANS_PATTERN_.'\1(\s*sprintf=.*)?(\s*js=1)?(\s*slashes=1)?.*\}/U';
- }
- break;
-
- case 'errors':
- // Parsing file for all errors syntax
- $regex = '/Tools::displayError\((\')'._PS_TRANS_PATTERN_.'\'(,\s*(.+))?\)/U';
- break;
-
- case 'modules':
- // Parsing modules file
- if ($type_file == 'php') {
- $regex = '/->l\((\')'._PS_TRANS_PATTERN_.'\'(, ?\'(.+)\')?(, ?(.+))?\)/U';
- } else {
- // In tpl file look for something that should contain mod='module_name' according to the documentation
- $regex = '/\{l\s*s=([\'\"])'._PS_TRANS_PATTERN_.'\1.*\s+mod=\''.$module_name.'\'.*\}/U';
- }
- break;
-
- case 'pdf':
- // Parsing PDF file
- if ($type_file == 'php') {
- $regex = array(
- '/HTMLTemplate.*::l\((\')'._PS_TRANS_PATTERN_.'\'[\)|\,]/U',
- '/->l\((\')'._PS_TRANS_PATTERN_.'\'(, ?\'(.+)\')?(, ?(.+))?\)/U'
- );
- } else {
- $regex = '/\{l\s*s=([\'\"])'._PS_TRANS_PATTERN_.'\1(\s*sprintf=.*)?(\s*js=1)?(\s*pdf=\'true\')?\s*\}/U';
- }
- break;
- }
-
- if (!is_array($regex)) {
- $regex = array($regex);
- }
-
- $strings = array();
- foreach ($regex as $regex_row) {
- $matches = array();
- $n = preg_match_all($regex_row, $content, $matches);
- for ($i = 0; $i < $n; $i += 1) {
- $quote = $matches[1][$i];
- $string = $matches[2][$i];
-
- if ($quote === '"') {
- // Escape single quotes because the core will do it when looking for the translation of this string
- $string = str_replace('\'', '\\\'', $string);
- // Unescape double quotes
- $string = preg_replace('/\\\\+"/', '"', $string);
- }
-
- $strings[] = $string;
- }
- }
-
- return array_unique($strings);
- }
-
/**
* Get all translations informations for all type of translations
*
@@ -1760,20 +1658,6 @@ class AdminTranslationsControllerCore extends AdminController
return $return;
}
- /**
- * Find sentence which use %d, %s, %%, %1$d, %1$s...
- *
- * @param $key : english sentence
- * @return array|bool return list of matches
- */
- public function checkIfKeyUseSprintf($key)
- {
- if (preg_match_all('#(?:%%|%(?:[0-9]+\$)?[+-]?(?:[ 0]|\'.)?-?[0-9]*(?:\.[0-9]+)?[bcdeufFosxX])#', $key, $matches)) {
- return implode(', ', $matches[0]);
- }
- return false;
- }
-
/**
* This method generate the form for front translations
*/
@@ -1807,7 +1691,7 @@ class AdminTranslationsControllerCore extends AdminController
$content = file_get_contents($file_path);
// Parse this content
- $matches = $this->userParseFile($content, $this->type_selected);
+ $matches = Translate::userParseFile($content, $this->type_selected);
/* Get string translation */
foreach ($matches as $key) {
@@ -1828,7 +1712,7 @@ class AdminTranslationsControllerCore extends AdminController
}
}
}
- $new_lang[$key]['use_sprintf'] = $this->checkIfKeyUseSprintf($key);
+ $new_lang[$key]['use_sprintf'] = Translate::checkIfKeyUseSprintf($key);
}
}
@@ -1874,7 +1758,7 @@ class AdminTranslationsControllerCore extends AdminController
foreach ($files_per_directory['php'] as $dir => $files) {
foreach ($files as $file) {
// Check if is a PHP file and if the override file exists
- if (preg_match('/^(.*)\.php$/', $file) && Tools::file_exists_cache($file_path = $dir.$file) && !in_array($file, self::$ignore_folder)) {
+ if (preg_match('/^(.*)\.php$/', $file) && Tools::file_exists_cache($file_path = $dir.$file) && !in_array($file, Translate::$ignore_folder)) {
$prefix_key = basename($file);
// -4 becomes -14 to remove the ending "Controller.php" from the filename
if (strpos($file, 'Controller.php') !== false) {
@@ -1895,7 +1779,7 @@ class AdminTranslationsControllerCore extends AdminController
$content = file_get_contents($file_path);
// Parse this content
- $matches = $this->userParseFile($content, $this->type_selected, 'php');
+ $matches = Translate::userParseFile($content, $this->type_selected, 'php');
foreach ($matches as $key) {
// Caution ! front has underscore between prefix key and md5, back has not
@@ -1914,7 +1798,7 @@ class AdminTranslationsControllerCore extends AdminController
}
}
}
- $tabs_array[$prefix_key][$key]['use_sprintf'] = $this->checkIfKeyUseSprintf($key);
+ $tabs_array[$prefix_key][$key]['use_sprintf'] = Translate::checkIfKeyUseSprintf($key);
}
}
}
@@ -1922,14 +1806,14 @@ class AdminTranslationsControllerCore extends AdminController
foreach ($files_per_directory['specific'] as $dir => $files) {
foreach ($files as $file) {
- if (Tools::file_exists_cache($file_path = $dir.$file) && !in_array($file, self::$ignore_folder)) {
+ if (Tools::file_exists_cache($file_path = $dir.$file) && !in_array($file, Translate::$ignore_folder)) {
$prefix_key = 'index';
// Get content for this file
$content = file_get_contents($file_path);
// Parse this content
- $matches = $this->userParseFile($content, $this->type_selected, 'specific');
+ $matches = Translate::userParseFile($content, $this->type_selected, 'specific');
foreach ($matches as $key) {
// Caution ! front has underscore between prefix key and md5, back has not
@@ -1948,7 +1832,7 @@ class AdminTranslationsControllerCore extends AdminController
}
}
}
- $tabs_array[$prefix_key][$key]['use_sprintf'] = $this->checkIfKeyUseSprintf($key);
+ $tabs_array[$prefix_key][$key]['use_sprintf'] = Translate::checkIfKeyUseSprintf($key);
}
}
}
@@ -2000,7 +1884,7 @@ class AdminTranslationsControllerCore extends AdminController
$content = file_get_contents($file_path);
// Parse this content
- $matches = $this->userParseFile($content, $this->type_selected, 'tpl');
+ $matches = Translate::userParseFile($content, $this->type_selected, 'tpl');
/* Get string translation for each tpl file */
foreach ($matches as $english_string) {
@@ -2025,7 +1909,7 @@ class AdminTranslationsControllerCore extends AdminController
}
}
}
- $new_lang[$english_string]['use_sprintf'] = $this->checkIfKeyUseSprintf($english_string);
+ $new_lang[$english_string]['use_sprintf'] = Translate::checkIfKeyUseSprintf($english_string);
}
}
if (isset($tabs_array[$prefix_key])) {
@@ -2098,15 +1982,15 @@ class AdminTranslationsControllerCore extends AdminController
if ($modules = $this->getListModules()) {
foreach ($modules as $module) {
- if (is_dir(_PS_MODULE_DIR_.$module) && !in_array($module, self::$ignore_folder)) {
- $file_by_directory['php'] = array_merge($file_by_directory['php'], $this->listFiles(_PS_MODULE_DIR_.$module.'/', array(), 'php'));
+ if (is_dir(_PS_MODULE_DIR_.$module) && !in_array($module, Translate::$ignore_folder)) {
+ $file_by_directory['php'] = array_merge($file_by_directory['php'], Translate::listFiles(_PS_MODULE_DIR_.$module.'/', array(), 'php'));
}
}
}
foreach ($file_by_directory['php'] as $dir => $files) {
foreach ($files as $file) {
- if (preg_match('/\.php$/', $file) && Tools::file_exists_cache($file_path = $dir.$file) && !in_array($file, self::$ignore_folder)) {
+ if (preg_match('/\.php$/', $file) && Tools::file_exists_cache($file_path = $dir.$file) && !in_array($file, Translate::$ignore_folder)) {
if (!filesize($file_path)) {
continue;
}
@@ -2115,7 +1999,7 @@ class AdminTranslationsControllerCore extends AdminController
$content = file_get_contents($file_path);
// Parse this content
- $matches = $this->userParseFile($content, $this->type_selected);
+ $matches = Translate::userParseFile($content, $this->type_selected);
foreach ($matches as $key) {
if (array_key_exists(md5($key), $GLOBALS[$name_var])) {
@@ -2126,7 +2010,7 @@ class AdminTranslationsControllerCore extends AdminController
$count_empty[$key] = 1;
}
}
- $string_to_translate[$key]['use_sprintf'] = $this->checkIfKeyUseSprintf($key);
+ $string_to_translate[$key]['use_sprintf'] = Translate::checkIfKeyUseSprintf($key);
}
}
}
@@ -2522,7 +2406,7 @@ class AdminTranslationsControllerCore extends AdminController
{
$arr_modules = array();
foreach (scandir($this->translations_informations['modules']['dir']) as $module_dir) {
- if (!in_array($module_dir, self::$ignore_folder)) {
+ if (!in_array($module_dir, Translate::$ignore_folder)) {
$dir = false;
if ($this->theme_selected && Tools::file_exists_cache($this->translations_informations['modules']['override']['dir'].$module_dir.'/mails/')) {
$dir = $this->translations_informations['modules']['override']['dir'].$module_dir.'/';
@@ -2555,7 +2439,7 @@ class AdminTranslationsControllerCore extends AdminController
{
$arr_modules = array();
foreach (scandir($this->translations_informations['modules']['dir']) as $module_dir) {
- if (!in_array($module_dir, self::$ignore_folder)) {
+ if (!in_array($module_dir, Translate::$ignore_folder)) {
$dir = false;
if ($classes) {
if ($this->theme_selected && Tools::file_exists_cache($this->translations_informations['modules']['override']['dir'].$module_dir.'/classes/')) {
@@ -2622,7 +2506,7 @@ class AdminTranslationsControllerCore extends AdminController
foreach ($files_by_directiories['php'] as $dir => $files) {
foreach ($files as $file) {
// If file exist and is not in ignore_folder, in the next step we check if a folder or mail
- if (Tools::file_exists_cache($dir.$file) && !in_array($file, self::$ignore_folder)) {
+ if (Tools::file_exists_cache($dir.$file) && !in_array($file, Translate::$ignore_folder)) {
$subject_mail = $this->getSubjectMail($dir, $file, $subject_mail);
}
}
@@ -2693,7 +2577,7 @@ class AdminTranslationsControllerCore extends AdminController
foreach ($dir_to_copy_iso as $dir) {
foreach (scandir($dir) as $file) {
- if (!in_array($file, self::$ignore_folder)) {
+ if (!in_array($file, Translate::$ignore_folder)) {
$files_to_copy_iso[] = array(
"from" => $dir.$file,
"to" => str_replace((strpos($dir, _PS_CORE_DIR_) !== false) ? _PS_CORE_DIR_ : _PS_ROOT_DIR_, _PS_ROOT_DIR_.'/themes/'.$current_theme, $dir).$file
@@ -2739,7 +2623,7 @@ class AdminTranslationsControllerCore extends AdminController
{
$dir = rtrim($dir, '/');
// If is file and is not in ignore_folder
- if (is_file($dir.'/'.$file) && !in_array($file, self::$ignore_folder) && preg_match('/\.php$/', $file)) {
+ if (is_file($dir.'/'.$file) && !in_array($file, Translate::$ignore_folder) && preg_match('/\.php$/', $file)) {
$content = file_get_contents($dir.'/'.$file);
$content = str_replace("\n", ' ', $content);
@@ -2764,7 +2648,7 @@ class AdminTranslationsControllerCore extends AdminController
}
}
// Or if is folder, we scan folder for check if found in folder and subfolder
- elseif (!in_array($file, self::$ignore_folder) && is_dir($dir.'/'.$file)) {
+ elseif (!in_array($file, Translate::$ignore_folder) && is_dir($dir.'/'.$file)) {
foreach (scandir($dir.'/'.$file) as $temp) {
if ($temp[0] != '.') {
$subject_mail = $this->getSubjectMail($dir.'/'.$file, $temp, $subject_mail);
@@ -2792,7 +2676,7 @@ class AdminTranslationsControllerCore extends AdminController
$subject = str_replace("\\'", "\'", $subject);
$subject_mail_content[$key]['trad'] = htmlentities($subject, ENT_QUOTES, 'UTF-8');
- $subject_mail_content[$key]['use_sprintf'] = $this->checkIfKeyUseSprintf($key);
+ $subject_mail_content[$key]['use_sprintf'] = Translate::checkIfKeyUseSprintf($key);
}
} else {
$this->errors[] = sprintf($this->l('Email subject translation file not found in "%s".'), $directory);
@@ -2976,7 +2860,7 @@ class AdminTranslationsControllerCore extends AdminController
$content = file_get_contents($file_path);
// Parse this content
- $matches = $this->userParseFile($content, $this->type_selected, $file_type);
+ $matches = Translate::userParseFile($content, $this->type_selected, $file_type);
foreach ($matches as $key) {
if (stripslashes(array_key_exists($tab.md5(addslashes($key)), $lang_array))) {
@@ -2989,7 +2873,7 @@ class AdminTranslationsControllerCore extends AdminController
$count_missing[$tab]++;
}
}
- $tabs_array[$tab][$key]['use_sprintf'] = $this->checkIfKeyUseSprintf($key);
+ $tabs_array[$tab][$key]['use_sprintf'] = Translate::checkIfKeyUseSprintf($key);
}
return $tabs_array;
@@ -3034,14 +2918,14 @@ class AdminTranslationsControllerCore extends AdminController
foreach ($files_by_directory as $type => $directories) {
foreach ($directories as $dir => $files) {
foreach ($files as $file) {
- if (!in_array($file, self::$ignore_folder) && Tools::file_exists_cache($file_path = $dir.$file)) {
+ if (!in_array($file, Translate::$ignore_folder) && Tools::file_exists_cache($file_path = $dir.$file)) {
if ($type == 'tpl') {
if (Tools::file_exists_cache($file_path) && is_file($file_path)) {
// Get content for this file
$content = file_get_contents($file_path);
// Parse this content
- $matches = $this->userParseFile($content, $this->type_selected, 'tpl');
+ $matches = Translate::userParseFile($content, $this->type_selected, 'tpl');
foreach ($matches as $key) {
if (isset($GLOBALS[$name_var][$prefix_key.md5($key)])) {
@@ -3056,7 +2940,7 @@ class AdminTranslationsControllerCore extends AdminController
}
}
}
- $tabs_array[$prefix_key][$key]['use_sprintf'] = $this->checkIfKeyUseSprintf($key);
+ $tabs_array[$prefix_key][$key]['use_sprintf'] = Translate::checkIfKeyUseSprintf($key);
}
}
} elseif (Tools::file_exists_cache($file_path)) {
@@ -3081,33 +2965,6 @@ class AdminTranslationsControllerCore extends AdminController
return parent::renderView();
}
- /**
- * Recursively list files in directory $dir
- *
- * @param string $dir
- * @param array $list
- * @param string $file_ext
- *
- * @return array
- */
- public function listFiles($dir, $list = array(), $file_ext = 'tpl')
- {
- $dir = rtrim($dir, '/').DIRECTORY_SEPARATOR;
-
- $to_parse = scandir($dir);
- // copied (and kind of) adapted from AdminImages.php
- foreach ($to_parse as $file) {
- if (!in_array($file, self::$ignore_folder)) {
- if (preg_match('#'.preg_quote($file_ext, '#').'$#i', $file)) {
- $list[$dir][] = $file;
- } elseif (is_dir($dir.$file)) {
- $list = $this->listFiles($dir.$file, $list, $file_ext);
- }
- }
- }
- return $list;
- }
-
/**
* Checks if theme exists
*
diff --git a/install/data/xml/configuration.xml b/install/data/xml/configuration.xml
index eaa524deb..f5651018c 100644
--- a/install/data/xml/configuration.xml
+++ b/install/data/xml/configuration.xml
@@ -605,28 +605,52 @@
10
-
+
100
-
+
400
-
+
1
-
+
2
-
+
1
-
+
2
-
+
1
-
+
+ 3
+
+
+ 100
+
+
+ 400
+
+
+ 1
+
+
+ 2
+
+
+ 1
+
+
+ 2
+
+
+ 1
+
+
3