From b2b2a4fbc6596f34b5b2e9f65f88836d8e9b8915 Mon Sep 17 00:00:00 2001 From: tDidierjean Date: Tue, 18 Oct 2011 12:40:35 +0000 Subject: [PATCH] [*] BO : #PSFV-94 - added AdminBackupController and some changes to AdminController --- admin-dev/tabs/AdminBackup.php | 306 ------------------ admin-dev/themes/template/backup/content.tpl | 77 +++++ admin-dev/themes/template/backup/view.tpl | 33 ++ admin-dev/themes/template/images/content.tpl | 104 ++++++ classes/AdminController.php | 30 +- controllers/admin/AdminBackupController.php | 271 ++++++++++++++++ controllers/admin/AdminHomeController.php | 45 ++- controllers/admin/AdminImagesController.php | 5 +- .../admin/AdminRequestSqlController.php | 12 - controllers/admin/AdminStoresController.php | 4 +- 10 files changed, 532 insertions(+), 355 deletions(-) delete mode 100644 admin-dev/tabs/AdminBackup.php create mode 100644 admin-dev/themes/template/backup/content.tpl create mode 100644 admin-dev/themes/template/backup/view.tpl create mode 100644 admin-dev/themes/template/images/content.tpl create mode 100644 controllers/admin/AdminBackupController.php diff --git a/admin-dev/tabs/AdminBackup.php b/admin-dev/tabs/AdminBackup.php deleted file mode 100644 index e3612e210..000000000 --- a/admin-dev/tabs/AdminBackup.php +++ /dev/null @@ -1,306 +0,0 @@ - -* @copyright 2007-2011 PrestaShop SA -* @version Release: $Revision: 7320 $ -* @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_.'/../classes/AdminTab.php'); - -class AdminBackup extends AdminTab -{ - /** @var string The field we are sorting on */ - protected $_sortBy = 'date'; - - public function __construct() - { - $this->table = 'backup'; - $this->className = 'Backup'; - parent::__construct(); - - $this->edit = false; - $this->delete = true; - $this->view = true; - - $this->deleted = false; - - $this->requiredDatabase = false; - - $this->fieldsDisplay = array ( - 'date' => array('title' => $this->l('Date'), 'type' => 'datetime', 'width' => 120, 'align' => 'right'), - 'age' => array('title' => $this->l('Age')), - 'filename' => array('title' => $this->l('File name'), 'width' => 200), - 'filesize' => array('title' => $this->l('File size')) - ); - - $this->optionsList = array( - 'general' => array( - 'title' => $this->l('Backup options'), - 'fields' => array( - 'PS_BACKUP_ALL' => array('title' => $this->l('Ignore statistics tables:'), - 'desc' => $this->l('The following tables will NOT be backed up if you enable this option:').'
'._DB_PREFIX_.'connections, '._DB_PREFIX_.'connections_page, '._DB_PREFIX_.'connections_source, '._DB_PREFIX_.'guest, '._DB_PREFIX_.'statssearch', 'cast' => 'intval', 'type' => 'bool'), - 'PS_BACKUP_DROP_TABLE' => array('title' => $this->l('Drop existing tables during import:'), - 'desc' => $this->l('Select this option to instruct the backup file to drop your tables prior to restoring the backed up data').'
(ie. "DROP TABLE IF EXISTS")', 'cast' => 'intval', 'type' => 'bool'), - ), - ), - ); - $this->identifier = 'filename'; - } - - /** - * Load class object using identifier in $_GET (if possible) - * otherwise return an empty object - * This method overrides the one in AdminTab because AdminTab assumes the id is a UnsignedInt - * "Backups" Directory in admin directory must be writeable (CHMOD 777) - * @param boolean $opt Return an empty object if load fail - * @return object - */ - protected function loadObject($opt = false) - { - if ($id = Tools::getValue($this->identifier)) - return new $this->className($id); - return new $this->className(); - } - - /** - * Creates a new backup, and then displays the normal menu - */ - public function displayForm($isMainTab = true) - { - if(is_writable(_PS_ADMIN_DIR_.'/backups/')) - { - if (!($object = $this->loadObject())) - return; - if ($object->add()) - { - echo '
 '.$this->l('It appears that the Backup was successful, however, you must download and carefully verify the Backup file.').'
'; - if ($this->tabAccess['view'] === '1') - echo ' -
- '.$this->l('Download').' -

'.$this->l('Download the Backup file').' ('.number_format((filesize($object->id)*0.000001), 2, '.', '').$this->l('Mb').')

- '.$this->l('Tip: You can also download this file by FTP, Backup files are located in "admin/backups" directory.').'

-
'; - - $this->displayHowTo(false); - } - elseif ($object->error) - $this->_errors[] = $object->error; - } - else - $this->_errors[] = $this->l('"Backups" Directory in admin directory must be writeable (CHMOD 755 / 777)'); - $this->displayErrors(); - } - - /** - * Displays the page which allows the backup to be downloaded - */ - public function viewbackup() - { - if (!($object = $this->loadObject())) - return; - if ($object->id) - { - $url = $object->getBackupURL(); - echo '
 '.$this->l('Beginning download ...').'
'; - echo '
'.$this->l('Back-up file should automatically download.'); - echo '

'.$this->l('If not,').' '.$this->l('please click here!').''; - echo ''; - echo '


'.$this->l('Back to list').'
'; - } - elseif ($object->error) - $this->_errors[] = $object->error; - $this->displayErrors(); - } - - public function displayHowTo($showForm = true) - { - echo ' -
-

'.$this->l('Disclaimer before creating a new Backup').'

-
    -
  1. '.$this->l('PrestaShop is not responsible for your database, Backups, restore and data.').'
  2. -
  3. '.$this->l('PrestaShop is an Open-source software, you are using it at your own risk under the licence agreement.').'
  4. -
  5. '.$this->l('You should Backup your data on a regular basis (both files and database).').'
  6. -
  7. '.$this->l('This function only backs up your database, not your files.').'
  8. -
  9. '.$this->l('By default, your existing database tables will be deleted during Backup restore (see options).').'
  10. -
  11. '.$this->l('Always verify the quality and integrity of your Backups files.').'
  12. -
  13. '.$this->l('Always verify that your Backups files are complete, up-to-date and valid. Even if you had a success message during the Backup process.').'
  14. -
  15. '.$this->l('Always check your data.').'
  16. -
  17. '.$this->l('Never restore a Backup on a live site.').'
  18. -
'; - - if ($showForm) - echo ' -
- -
'; - - echo ' -
-
-

'.$this->l('How-to restore a database Backup in 10 easy steps').'

-
    -
  1. '.$this->l('Turn off the "Enable Shop" option in the "Preferences" tab.').'
  2. -
  3. '.$this->l('Download the Backup from the list below or from your FTP server (in the folder "admin/backups").').'
  4. -
  5. '.$this->l('Check the Backup integrity: look for errors, incomplete file. Verify all your data.').'
  6. -
  7. '.$this->l('Ask your hosting provider for a "phpMyAdmin" access to your database').'
  8. -
  9. '.$this->l('Connect to "phpMyAdmin" and select your current database').'
  10. -
  11. '.$this->l('Unless you enabled the "Drop existing tables" option, you must delete all tables from your current database.').'
  12. -
  13. '.$this->l('At the top of the screen select the tab "Import"').'
  14. -
  15. '.$this->l('Click on the "Browse..." button and select the Backup file from your hard drive').'
  16. -
  17. '.$this->l('Check the max. allowed filesize (ie. Max: 16Mb)').'
    '.$this->l('If your Backup file exceeds this limit, contact your hosting provider').'
  18. -
  19. '.$this->l('Click on the "Go" button and wait during the import, the process can take several minutes').'
  20. -
-
-
'; - } - - public function displayList() - { - // Test if the backup dir is writable - if(!is_writable(_PS_ADMIN_DIR_.'/backups/')) - $this->displayWarning($this->l('"Backups" Directory in admin directory must be writeable (CHMOD 755 / 777)')); - - $this->displayErrors(); - $this->displayHowTo(); - - parent::displayList(); - } - - public function getList($id_lang, $orderBy = NULL, $orderWay = NULL, $start = 0, $limit = NULL, $id_lang_shop = NULL) - { - - if (!Validate::isTableOrIdentifier($this->table)) - die('filter is corrupted'); - if (empty($orderBy)) - $orderBy = Tools::getValue($this->table.'Orderby', $this->_defaultOrderBy); - if (empty($orderWay)) - $orderWay = Tools::getValue($this->table.'Orderway', 'ASC'); - - // Try and obtain getList arguments from $_GET - $orderBy = Tools::getValue($this->table.'Orderby'); - $orderWay = Tools::getValue($this->table.'Orderway'); - - // Validate the orderBy and orderWay fields - switch ($orderBy) - { - case 'filename': - case 'filesize': - case 'date': - case 'age': - break; - default: - $orderBy = 'date'; - } - switch ($orderWay) - { - case 'asc': - case 'desc': - break; - default: - $orderWay = 'desc'; - } - if (empty($limit)) - $limit = ((!isset($this->context->cookie->{$this->table.'_pagination'})) ? $this->_pagination[0] : $limit = $this->context->cookie->{$this->table.'_pagination'}); - $limit = (int)(Tools::getValue('pagination', $limit)); - $this->context->cookie->{$this->table.'_pagination'} = $limit; - - /* Determine offset from current page */ - if (!empty($_POST['submitFilter'.$this->table]) AND is_numeric($_POST['submitFilter'.$this->table])) - $start = (int)($_POST['submitFilter'.$this->table] - 1) * $limit; - $this->_lang = (int)($id_lang); - $this->_orderBy = $orderBy; - $this->_orderWay = strtoupper($orderWay); - $this->_list = array(); - - // Find all the backups - $dh = @opendir(_PS_ADMIN_DIR_.'/backups/'); - if ($dh === false) - { - $this->_errors[] = Tools::displayError('Unable to open backup directory .').addslashes(_PS_ADMIN_DIR_.'/backups/').'"'; - return; - } - while (($file = readdir($dh)) !== false) - { - if (preg_match('/^([\d]+-[a-z\d]+)\.sql(\.gz|\.bz2)?$/', $file, $matches) == 0) - continue; - $timestamp = (int)($matches[1]); - $date = date('Y-m-d H:i:s', $timestamp); - $age = time() - $timestamp; - if ($age < 3600) - $age = '< 1 '.$this->l('hour'); - else if ($age < 86400) - { - $age = floor($age / 3600); - $age = $age.' '.(($age == 1) ? $this->l('hour') : $this->l('hours')); - } - else - { - $age = floor($age / 86400); - $age = $age.' '.(($age == 1) ? $this->l('day') : $this->l('days')); - } - $size = filesize(_PS_ADMIN_DIR_.'/backups/'.$file); - $this->_list[] = array( - 'filename' => $file, - 'age' => $age, - 'date' => $date, - 'filesize' => number_format($size / 1000, 2).' Kb', - 'timestamp' => $timestamp, - 'filesize_sort' => $size, - ); - } - closedir($dh); - $this->_listTotal = count($this->_list); - - // Sort the _list based on the order requirements - switch ($this->_orderBy) - { - case 'filename': - $this->_sortBy = 'filename'; - $sorter = 'str_sort'; - break; - case 'filesize': - $this->_sortBy = 'filesize_sort'; - $sorter = 'int_sort'; - break; - case 'age': - case 'date': - $this->_sortBy = 'timestamp'; - $sorter = 'int_sort'; - break; - } - usort($this->_list, array($this, $sorter)); - $this->_list = array_slice($this->_list, $start, $limit); - } - - public function int_sort($a, $b) - { - return $this->_orderWay == 'ASC' ? $a[$this->_sortBy] - $b[$this->_sortBy] : $b[$this->_sortBy] - $a[$this->_sortBy]; - } - - public function str_sort($a, $b) - { - return $this->_orderWay == 'ASC' ? strcmp($a[ $this->_sortBy], $b[$this->_sortBy]) : strcmp($b[ $this->_sortBy], $a[$this->_sortBy]); - } -} diff --git a/admin-dev/themes/template/backup/content.tpl b/admin-dev/themes/template/backup/content.tpl new file mode 100644 index 000000000..0034dc011 --- /dev/null +++ b/admin-dev/themes/template/backup/content.tpl @@ -0,0 +1,77 @@ +{* +* 2007-2011 PrestaShop +* +* NOTICE OF LICENSE +* +* This source file is subject to the Academic Free License (AFL 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/afl-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 +* @copyright 2007-2011 PrestaShop SA +* @version Release: $Revision$ +* @license http://opensource.org/licenses/afl-3.0.php Academic Free License (AFL 3.0) +* International Registered Trademark & Property of PrestaShop SA +*} + +{if isset($download)} +
+ {l s='Download'} +

{l s='Download the Backup file'} ({$backup_weight}{l s='Mb'})

+ {l s='Tip: You can also download this file by FTP, Backup files are located in "admin/backups" directory.'}

+
+{/if} + +{if isset($how_to)} +
+

{l s='Disclaimer before creating a new Backup'}

+
    +
  1. {l s='PrestaShop is not responsible for your database, Backups, restore and data.'}
  2. +
  3. {l s='PrestaShop is an Open-source software, you are using it at your own risk under the licence agreement.'}
  4. +
  5. {l s='You should Backup your data on a regular basis (both files and database).'}
  6. +
  7. {l s='This function only backs up your database, not your files.'}
  8. +
  9. {l s='By default, your existing database tables will be deleted during Backup restore (see options).'}
  10. +
  11. {l s='Always verify the quality and integrity of your Backups files.'}
  12. +
  13. {l s='Always verify that your Backups files are complete, up-to-date and valid. Even if you had a success message during the Backup process.'}
  14. +
  15. {l s='Always check your data.'}
  16. +
  17. {l s='Never restore a Backup on a live site.'}
  18. +
+ + {if $show_form} +
+ +
+ {/if} +
+
+

{l s='How-to restore a database Backup in 10 easy steps'}

+
    +
  1. {l s='Turn off the "Enable Shop" option in the "Preferences" tab.'}
  2. +
  3. {l s='Download the Backup from the list below or from your FTP server (in the folder "admin/backups").'}
  4. +
  5. {l s='Check the Backup integrity: look for errors, incomplete file. Verify all your data.'}
  6. +
  7. {l s='Ask your hosting provider for a "phpMyAdmin" access to your database'}
  8. +
  9. {l s='Connect to "phpMyAdmin" and select your current database'}
  10. +
  11. {l s='Unless you enabled the "Drop existing tables" option, you must delete all tables from your current database.'}
  12. +
  13. {l s='At the top of the screen select the tab "Import"'}
  14. +
  15. {l s='Click on the "Browse..." button and select the Backup file from your hard drive'}
  16. +
  17. {l s='Check the max. allowed filesize (ie. Max: 16Mb)'}
    {l s='If your Backup file exceeds this limit, contact your hosting provider'}
  18. +
  19. {l s='Click on the "Go" button and wait during the import, the process can take several minutes'}
  20. +
+
+
+{/if} +{if isset($download)} +

{l s='Back to list'}
+{/if} + +{$content} diff --git a/admin-dev/themes/template/backup/view.tpl b/admin-dev/themes/template/backup/view.tpl new file mode 100644 index 000000000..596c20197 --- /dev/null +++ b/admin-dev/themes/template/backup/view.tpl @@ -0,0 +1,33 @@ +{* +* 2007-2011 PrestaShop +* +* NOTICE OF LICENSE +* +* This source file is subject to the Academic Free License (AFL 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/afl-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 +* @copyright 2007-2011 PrestaShop SA +* @version Release: $Revision$ +* @license http://opensource.org/licenses/afl-3.0.php Academic Free License (AFL 3.0) +* International Registered Trademark & Property of PrestaShop SA +*} + +
 {l s='Beginning download ...'}
+
{l s='Back-up file should automatically download.'} +

{l s='If not,'} {l s='please click here!'} + +


{l s='Back to list'}
+ + diff --git a/admin-dev/themes/template/images/content.tpl b/admin-dev/themes/template/images/content.tpl new file mode 100644 index 000000000..6437bb354 --- /dev/null +++ b/admin-dev/themes/template/images/content.tpl @@ -0,0 +1,104 @@ +{* +* 2007-2011 PrestaShop +* +* NOTICE OF LICENSE +* +* This source file is subject to the Academic Free License (AFL 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/afl-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 +* @copyright 2007-2011 PrestaShop SA +* @version Release: $Revision$ +* @license http://opensource.org/licenses/afl-3.0.php Academic Free License (AFL 3.0) +* International Registered Trademark & Property of PrestaShop SA +*} + +{$content} + +{if isset($display_regenerate)} +

{l s='Regenerate thumbnails'}

+ {l s='Regenerates thumbnails for all existing product images'}

+
+
+ {l s='Please be patient, as this can take several minutes'}
+ {l s='Be careful! Manually generated thumbnails will be erased by automatically generated thumbnails.'} +
+
+
+
+ {l s='Regenerate thumbnails'}
+ +
+ +
+ + {foreach $types AS $k => $type} + + + {/foreach} + + +
+ +

{l s='Uncheck this checkbox only if your server timed out and you need to resume the regeneration.'}

+
+
+
+
+
+{/if} + +{if isset($display_move)} +

{l s='Move images'}

+ {l s='A new storage system for product images is now used by PrestaShop. It offers better performance if your shop has a very large number of products.'}
+
+ {if $safe_mode} +
+ {l s='PrestaShop has detected that your server configuration is not compatible with the new storage system (directive "safe_mode" is activated). You should continue to use the actual system.'} +
+ {else} +
+
+ {l s='Move images'}
+ {l s='You can choose to keep your images stored in the previous system - nothing wrong with that.'}
+ {l s='You can also decide to move your images to the new storage system: in this case, click on the "Move images" button below. Please be patient, as this can take several minutes.'} +

+
  + {l s='After moving all of your product images, for best performance go to the '} + {l s='product preferences tab'} + {l s=' and set "Use the legacy image filesystem" to NO.'} +
+
+
+
+ {/if} +{/if} \ No newline at end of file diff --git a/classes/AdminController.php b/classes/AdminController.php index ac4d2ed07..bdc68a27e 100644 --- a/classes/AdminController.php +++ b/classes/AdminController.php @@ -76,7 +76,8 @@ class AdminControllerCore extends Controller protected $list_display; - protected $form_list; + /** @var array list of option forms to be generated */ + protected $options; protected $_listSkipDelete = array(); @@ -292,7 +293,6 @@ class AdminControllerCore extends Controller // Sub included tab postProcessing $this->includeSubTab('postProcess', array('status', 'submitAdd1', 'submitDel', 'delete', 'submitFilter', 'submitReset')); - switch ($this->action) { /* Delete object image */ @@ -725,6 +725,7 @@ class AdminControllerCore extends Controller $tpl = $this->tpl_folder.'content.tpl'; $tpl_action = $this->tpl_folder.$this->display.'.tpl'; // Check if action template has been override + if (file_exists($this->context->smarty->template_dir.'/'.$tpl_action)) $this->context->smarty->assign('content', $this->context->smarty->fetch($tpl_action)); @@ -934,6 +935,11 @@ class AdminControllerCore extends Controller */ public function initContent() { + $this->context->smarty->assign(array( + 'current' => self::$currentIndex, + 'token' => $this->token + )); + if ($this->display == 'edit' || $this->display == 'add') { if (!($obj = $this->loadObject(true))) @@ -1195,12 +1201,10 @@ class AdminControllerCore extends Controller /* Delete object image */ if (isset($_GET['deleteImage'])) { - $this->action = 'delete_image'; - $token = Tools::getValue('token') ? Tools::getValue('token') : $this->token; - if (Validate::isLoadedObject($object = $this->loadObject())) - if (($object->deleteImage())) - Tools::redirectAdmin(self::$currentIndex.'&add'.$this->table.'&'.$this->identifier.'='.Tools::getValue($this->identifier).'&conf=7&token='.$token); - $this->_errors[] = Tools::displayError('An error occurred during image deletion (cannot load object).'); + if ($this->tabAccess['delete'] === '1') + $this->action = 'delete_image'; + else + $this->_errors[] = Tools::displayError('You do not have permission to delete here.'); } /* Delete object */ else if (isset($_GET['delete'.$this->table])) @@ -1249,11 +1253,19 @@ class AdminControllerCore extends Controller } else if (isset($_GET['update'.$this->table]) && isset($_GET['id_'.$this->table])) { + // @TODO move the employee condition to AdminEmployee if ($this->tabAccess['edit'] === '1' || ($this->table == 'employee' && $this->context->employee->id == Tools::getValue('id_employee'))) $this->display = 'edit'; else $this->_errors[] = Tools::displayError('You do not have permission to edit here.'); } + if (isset($_GET['view'.$this->table])) + { + if ($this->tabAccess['view'] === '1') + $this->display = 'view'; + else + $this->_errors[] = Tools::displayError('You do not have permission to view here.'); + } /* Cancel all filters for this tab */ else if (isset($_POST['submitReset'.$this->table])) $this->action = 'reset_filters'; @@ -1663,7 +1675,7 @@ class AdminControllerCore extends Controller $languages = Language::getLanguages(false); - foreach ($this->form_list as $option_list) + foreach ($this->options as $option_list) { foreach ($option_list as $category => $categoryData) { diff --git a/controllers/admin/AdminBackupController.php b/controllers/admin/AdminBackupController.php new file mode 100644 index 000000000..109c98b25 --- /dev/null +++ b/controllers/admin/AdminBackupController.php @@ -0,0 +1,271 @@ + +* @copyright 2007-2011 PrestaShop SA +* @version Release: $Revision: 7320 $ +* @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) +* International Registered Trademark & Property of PrestaShop SA +*/ + +class AdminBackupControllerCore extends AdminController +{ + /** @var string The field we are sorting on */ + protected $_sortBy = 'date'; + + public function __construct() + { + $this->table = 'backup'; + $this->className = 'Backup'; + parent::__construct(); + + $this->addRowAction('delete'); + $this->addRowAction('view'); + + $this->deleted = false; + + $this->requiredDatabase = false; + + $this->fieldsDisplay = array ( + 'date' => array('title' => $this->l('Date'), 'type' => 'datetime', 'width' => 120, 'align' => 'right'), + 'age' => array('title' => $this->l('Age')), + 'filename' => array('title' => $this->l('File name'), 'width' => 200), + 'filesize' => array('title' => $this->l('File size')) + ); + + $this->options = array( + 'options_general' => array( + 'general' => array( + 'title' => $this->l('Backup options'), + 'fields' => array( + 'PS_BACKUP_ALL' => array('title' => $this->l('Ignore statistics tables:'), + 'desc' => $this->l('The following tables will NOT be backed up if you enable this option:').'
'._DB_PREFIX_.'connections, '._DB_PREFIX_.'connections_page, '._DB_PREFIX_.'connections_source, '._DB_PREFIX_.'guest, '._DB_PREFIX_.'statssearch', 'cast' => 'intval', 'type' => 'bool'), + 'PS_BACKUP_DROP_TABLE' => array('title' => $this->l('Drop existing tables during import:'), + 'desc' => $this->l('Select this option to instruct the backup file to drop your tables prior to restoring the backed up data').'
(ie. "DROP TABLE IF EXISTS")', 'cast' => 'intval', 'type' => 'bool'), + ), + ), + ), + ); + $this->identifier = 'filename'; + } + + /** + * Load class object using identifier in $_GET (if possible) + * otherwise return an empty object + * This method overrides the one in AdminTab because AdminTab assumes the id is a UnsignedInt + * "Backups" Directory in admin directory must be writeable (CHMOD 777) + * @param boolean $opt Return an empty object if load fail + * @return object + */ + protected function loadObject($opt = false) + { + if ($id = Tools::getValue($this->identifier)) + return new $this->className($id); + return new $this->className(); + } + + public function initContent() + { + if ($this->display == 'view') + { + if (!($object = $this->loadObject())) + $this->_errors[] = Tools::displayError('The object could not be loaded.'); + if ($object->id) + { + $this->context->smarty->assign(array( + 'url_backup' => $object->getBackupURL() + )); + } + elseif ($object->error) + $this->_errors[] = $object->error; + } + else + { + if ($this->display == 'add') + { + $download = true; + $show_form = false; + } + else + { + $this->display = 'list'; + $show_form = true; + } + + $this->context->smarty->assign(array( + 'current' => self::$currentIndex, + 'show_form' => $show_form, + 'download' => isset($download) ? $download : null, + 'how_to' => true, + )); + } + parent::initContent(); + + if ($this->display == 'list') + { + $helper = new HelperOptions(); + $helper->id = $this->id; + $helper->currentIndex = self::$currentIndex; + $this->content .= $helper->generateOptions($this->options['options_general']); + } + } + + public function postProcess() + { + // Test if the backup dir is writable + if(!is_writable(_PS_ADMIN_DIR_.'/backups/')) + $this->warnings[] = $this->l('"Backups" Directory in admin directory must be writeable (CHMOD 755 / 777)'); + + if($this->action == 'new' && is_writable(_PS_ADMIN_DIR_.'/backups/')) + { + if (($object = $this->loadObject())) + { + if ($object->add()) + { + $this->context->smarty->assign(array( + 'conf' => $this->l('It appears that the Backup was successful, however, you must download and carefully verify the Backup file.'), + 'backup_url' => $object->getBackupURL(), + 'backup_weight' => number_format((filesize($object->id)*0.000001), 2, '.', '') + )); + } + elseif ($object->error) + $this->_errors[] = $object->error; + } + } + + parent::postProcess(); + } + + public function getList($id_lang, $orderBy = NULL, $orderWay = NULL, $start = 0, $limit = NULL, $id_lang_shop = NULL) + { + + if (!Validate::isTableOrIdentifier($this->table)) + die('filter is corrupted'); + if (empty($orderBy)) + $orderBy = Tools::getValue($this->table.'Orderby', $this->_defaultOrderBy); + if (empty($orderWay)) + $orderWay = Tools::getValue($this->table.'Orderway', 'ASC'); + + // Try and obtain getList arguments from $_GET + $orderBy = Tools::getValue($this->table.'Orderby'); + $orderWay = Tools::getValue($this->table.'Orderway'); + + // Validate the orderBy and orderWay fields + switch ($orderBy) + { + case 'filename': + case 'filesize': + case 'date': + case 'age': + break; + default: + $orderBy = 'date'; + } + switch ($orderWay) + { + case 'asc': + case 'desc': + break; + default: + $orderWay = 'desc'; + } + if (empty($limit)) + $limit = ((!isset($this->context->cookie->{$this->table.'_pagination'})) ? $this->_pagination[0] : $limit = $this->context->cookie->{$this->table.'_pagination'}); + $limit = (int)(Tools::getValue('pagination', $limit)); + $this->context->cookie->{$this->table.'_pagination'} = $limit; + + /* Determine offset from current page */ + if (!empty($_POST['submitFilter'.$this->table]) AND is_numeric($_POST['submitFilter'.$this->table])) + $start = (int)($_POST['submitFilter'.$this->table] - 1) * $limit; + $this->_lang = (int)($id_lang); + $this->_orderBy = $orderBy; + $this->_orderWay = strtoupper($orderWay); + $this->_list = array(); + + // Find all the backups + $dh = @opendir(_PS_ADMIN_DIR_.'/backups/'); + if ($dh === false) + { + $this->_errors[] = Tools::displayError('Unable to open backup directory .').addslashes(_PS_ADMIN_DIR_.'/backups/').'"'; + return; + } + while (($file = readdir($dh)) !== false) + { + if (preg_match('/^([\d]+-[a-z\d]+)\.sql(\.gz|\.bz2)?$/', $file, $matches) == 0) + continue; + $timestamp = (int)($matches[1]); + $date = date('Y-m-d H:i:s', $timestamp); + $age = time() - $timestamp; + if ($age < 3600) + $age = '< 1 '.$this->l('hour'); + else if ($age < 86400) + { + $age = floor($age / 3600); + $age = $age.' '.(($age == 1) ? $this->l('hour') : $this->l('hours')); + } + else + { + $age = floor($age / 86400); + $age = $age.' '.(($age == 1) ? $this->l('day') : $this->l('days')); + } + $size = filesize(_PS_ADMIN_DIR_.'/backups/'.$file); + $this->_list[] = array( + 'filename' => $file, + 'age' => $age, + 'date' => $date, + 'filesize' => number_format($size / 1000, 2).' Kb', + 'timestamp' => $timestamp, + 'filesize_sort' => $size, + ); + } + closedir($dh); + $this->_listTotal = count($this->_list); + + // Sort the _list based on the order requirements + switch ($this->_orderBy) + { + case 'filename': + $this->_sortBy = 'filename'; + $sorter = 'str_sort'; + break; + case 'filesize': + $this->_sortBy = 'filesize_sort'; + $sorter = 'int_sort'; + break; + case 'age': + case 'date': + $this->_sortBy = 'timestamp'; + $sorter = 'int_sort'; + break; + } + usort($this->_list, array($this, $sorter)); + $this->_list = array_slice($this->_list, $start, $limit); + } + + public function int_sort($a, $b) + { + return $this->_orderWay == 'ASC' ? $a[$this->_sortBy] - $b[$this->_sortBy] : $b[$this->_sortBy] - $a[$this->_sortBy]; + } + + public function str_sort($a, $b) + { + return $this->_orderWay == 'ASC' ? strcmp($a[ $this->_sortBy], $b[$this->_sortBy]) : strcmp($b[ $this->_sortBy], $a[$this->_sortBy]); + } +} diff --git a/controllers/admin/AdminHomeController.php b/controllers/admin/AdminHomeController.php index b5124765b..44a3652fd 100644 --- a/controllers/admin/AdminHomeController.php +++ b/controllers/admin/AdminHomeController.php @@ -1,6 +1,6 @@ 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; @@ -70,7 +70,7 @@ class AdminHomeControllerCore extends AdminController $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; @@ -85,15 +85,15 @@ class AdminHomeControllerCore extends AdminController $cccOptimized = 2; else $cccOptimized = 1; - + $shopEnabled = (Configuration::get('PS_SHOP_ENABLE') ? 2 : 1); - + $lights = array( - 0 => array('image'=>'error2.png','color'=>'#fbe8e8'), + 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->context->smarty->assign('hide_tips',Configuration::get('PS_HIDE_OPTIMIZATION_TIPS')); @@ -124,13 +124,13 @@ class AdminHomeControllerCore extends AdminController 'color' => $lights[$cccOptimized]['color'], 'image' => $lights[$cccOptimized]['image'], ); - + $opti_list[] = array( 'title' => $this->l('Shop enabled'), 'href' => $link->getAdminLink('AdminPreferences'), 'color' => $lights[$shopEnabled]['color'], 'image' => $lights[$shopEnabled]['image'], - ); + ); $opti_list[] = array( 'title' => $this->l('index rebuilt after update'), @@ -138,7 +138,7 @@ class AdminHomeControllerCore extends AdminController 'color' => $lights[$indexRebuiltAfterUpdate]['color'], 'image' => $lights[$indexRebuiltAfterUpdate]['image'], ); - + $opti_list[] = array( 'title' => $this->l('.htaccess up-to-date'), 'href' => $link->getAdminLink('AdminGenerator'), @@ -181,7 +181,7 @@ class AdminHomeControllerCore extends AdminController 'title' => $this->l('New product'), 'description' => $this->l('Fill up your catalog with new articles and attributes.'), ); - + $quick_links['third'] = array( 'href' => $this->context->link->getAdminLink('AdminStats'), 'title' => $this->l('Statistics'), @@ -313,7 +313,7 @@ class AdminHomeControllerCore extends AdminController $content = '
'.$this->l('View more').' '.$this->l('Statistics').' / '.$this->l('Sales of the week').'
'; - + $chart = new Chart(); $result = Db::getInstance(_PS_USE_SQL_SLAVE_)->executeS(' SELECT total_paid / conversion_rate as total_converted, invoice_date @@ -326,13 +326,13 @@ class AdminHomeControllerCore extends AdminController $chart->setTimeMode(strtotime('-7 DAYS', time()), time(), 'd'); $currency = Tools::setCurrency($this->context->cookie); $chart->getCurve(1)->setLabel($this->l('Sales +Tx').' ('.strtoupper($currency->iso_code).')'); - + $content .= $chart->fetch(); $content .= '
'; return $content; } - + public function getLastOrders() { $content = ' @@ -347,7 +347,7 @@ class AdminHomeControllerCore extends AdminController '; - + $orders = Order::getOrdersWithInformations(10); $i = 0; foreach ($orders AS $order) @@ -366,7 +366,7 @@ class AdminHomeControllerCore extends AdminController '; $i++; } - + $content .= ' @@ -388,9 +388,9 @@ class AdminHomeControllerCore extends AdminController $result['msg'] = $this->l('an error occured a'); } $this->content = Tools::jsonEncode($result); - + } - + public function displayAjax() { echo $this->content; @@ -496,7 +496,6 @@ class AdminHomeControllerCore extends AdminController public function initContent() { $smarty = $this->context->smarty; - $smarty->assign('token',$this->token); $this->warnDomainName(); @@ -513,7 +512,7 @@ class AdminHomeControllerCore extends AdminController $upgrade->checkPSVersion(); } $smarty->assign('upgrade', $upgrade); - + $smarty->assign('show_screencast', $this->context->employee->show_screencast); $smarty->assign('quick_links', $this->getQuickLinks()); $smarty->assign('monthly_statistics', $this->getMonthlyStatistics()); @@ -521,7 +520,7 @@ class AdminHomeControllerCore extends AdminController $smarty->assign('stats_sales', $this->getStatsSales()); $smarty->assign('last_orders',$this->getLastOrders()); $smarty->assign('tips_optimization', $this->_displayOptimizationTips()); - + $HOOK_BACKOFFICEHOME = Module::hookExec('backOfficeHome'); $smarty->assign('HOOK_BACKOFFICEHOME', $HOOK_BACKOFFICEHOME); diff --git a/controllers/admin/AdminImagesController.php b/controllers/admin/AdminImagesController.php index cf941e8f4..4549da671 100644 --- a/controllers/admin/AdminImagesController.php +++ b/controllers/admin/AdminImagesController.php @@ -46,7 +46,7 @@ class AdminImagesController extends AdminController 'height' => array('title' => $this->l('Height'), 'align' => 'right', 'suffix' => ' px', 'width' => 50, 'size' => 5) ); - $this->form_list = array( + $this->options = array( 'options_image_pref' => array( 'images' => array( 'title' => $this->l('Images'), @@ -534,11 +534,10 @@ class AdminImagesController extends AdminController if ($this->display == 'list') { - $helper = new HelperOptions(); $helper->id = $this->id; $helper->currentIndex = self::$currentIndex; - $this->content .= $helper->generateOptions($this->form_list['options_image_pref']); + $this->content .= $helper->generateOptions($this->options['options_image_pref']); $this->initRegenerate(); $this->initMoveImages(); diff --git a/controllers/admin/AdminRequestSqlController.php b/controllers/admin/AdminRequestSqlController.php index 59dfe4f76..361dff3f3 100644 --- a/controllers/admin/AdminRequestSqlController.php +++ b/controllers/admin/AdminRequestSqlController.php @@ -120,18 +120,6 @@ class AdminRequestSqlControllerCore extends AdminController } } - public function init() - { - if (isset($_GET['view'.$this->table]) && isset($_GET['id_'.$this->table])) - { - if ($this->tabAccess['edit'] === '1' || ($this->table == 'employee' && $this->context->employee->id == Tools::getValue('id_employee'))) - $this->display = 'view'; - else - $this->_errors[] = Tools::displayError('You do not have permission to edit here.'); - } - parent::init(); - } - public function initContent() { $this->displayWarning($this->l('When saving the query, only the request type "SELECT" are allowed.')); diff --git a/controllers/admin/AdminStoresController.php b/controllers/admin/AdminStoresController.php index 0a1e445cf..049009c90 100644 --- a/controllers/admin/AdminStoresController.php +++ b/controllers/admin/AdminStoresController.php @@ -213,7 +213,7 @@ class AdminStoresControllerCore extends AdminController ) ); - $this->form_list = array( + $this->options = array( 'option_store_pref' => array( 'general' => array( 'title' => $this->l('Parameters'), @@ -371,7 +371,7 @@ class AdminStoresControllerCore extends AdminController $helper->id = $this->id; $helper->currentIndex = self::$currentIndex; - $this->content .= $helper->generateOptions($this->form_list['option_store_pref']); + $this->content .= $helper->generateOptions($this->options['option_store_pref']); } }