[*] BO : #PSFV-94 - added AdminBackupController and some changes to AdminController

This commit is contained in:
tDidierjean
2011-10-18 12:40:35 +00:00
parent a2f6996ced
commit b2b2a4fbc6
10 changed files with 532 additions and 355 deletions
-306
View File
@@ -1,306 +0,0 @@
<?php
/*
* 2007-2011 PrestaShop
*
* NOTICE OF LICENSE
*
* This source file is subject to the Open Software License (OSL 3.0)
* that is bundled with this package in the file LICENSE.txt.
* It is also available through the world-wide-web at this URL:
* http://opensource.org/licenses/osl-3.0.php
* If you did not receive a copy of the license and are unable to
* obtain it through the world-wide-web, please send an email
* to license@prestashop.com so we can send you a copy immediately.
*
* DISCLAIMER
*
* Do not edit or add to this file if you wish to upgrade PrestaShop to newer
* versions in the future. If you wish to customize PrestaShop for your
* needs please refer to http://www.prestashop.com for more information.
*
* @author PrestaShop SA <contact@prestashop.com>
* @copyright 2007-2011 PrestaShop SA
* @version Release: $Revision: 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:').'<br />'._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').'<br />(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 '<div class="conf confirm"><img src="../img/admin/ok.gif" />&nbsp;'.$this->l('It appears that the Backup was successful, however, you must download and carefully verify the Backup file.').'</div>';
if ($this->tabAccess['view'] === '1')
echo '
<fieldset style="margin: 40px 0;" class="width3">
<legend><img src="../img/admin/AdminBackup.gif" alt="" class="icon" /> '.$this->l('Download').'</legend>
<p style="font-size: 13px;"><a href="'.$object->getBackupURL().'"><img src="../img/admin/AdminBackup.gif" alt="" class="icon" /></a><b><a href="'.$object->getBackupURL().'">'.$this->l('Download the Backup file').' ('.number_format((filesize($object->id)*0.000001), 2, '.', '').$this->l('Mb').')</a></b><br /><br />
'.$this->l('Tip: You can also download this file by FTP, Backup files are located in "admin/backups" directory.').'</p>
</fieldset>';
$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 '<div class="conf confirm"><img src="../img/admin/ok.gif" />&nbsp;'.$this->l('Beginning download ...').'</div>';
echo '<br />'.$this->l('Back-up file should automatically download.');
echo '<br /><br />'.$this->l('If not,').' <b><a href="'.$url.'">'.$this->l('please click here!').'</a></b>';
echo '<iframe width="0" height="0" scrolling="no" frameborder="0" src="'.$url.'"></iframe>';
echo '<br /><br /><br /><a href="'.self::$currentIndex.'&token='.$this->token.'"><img src="../img/admin/arrow2.gif" /> '.$this->l('Back to list').'</a><br />';
}
elseif ($object->error)
$this->_errors[] = $object->error;
$this->displayErrors();
}
public function displayHowTo($showForm = true)
{
echo '
<div class="error width1" style="float: left; margin-right: 10px;">
<p>'.$this->l('Disclaimer before creating a new Backup').'</p>
<ol style="font-size: 11px; font-weight: normal; line-height: 20px; padding-left: 10px;">
<li>'.$this->l('PrestaShop is not responsible for your database, Backups, restore and data.').'</li>
<li>'.$this->l('PrestaShop is an Open-source software, you are using it at your own risk under the licence agreement.').'</li>
<li>'.$this->l('You should Backup your data on a regular basis (both files and database).').'</li>
<li>'.$this->l('This function only backs up your database, not your files.').'</li>
<li>'.$this->l('By default, your existing database tables will be deleted during Backup restore (see options).').'</li>
<li>'.$this->l('Always verify the quality and integrity of your Backups files.').'</li>
<li>'.$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.').'</li>
<li>'.$this->l('Always check your data.').'</li>
<li>'.$this->l('Never restore a Backup on a live site.').'</li>
</ol>';
if ($showForm)
echo '
<form action="'.self::$currentIndex.'&add'.$this->table.'&token='.$this->token.'" method="post" style="text-align: center;">
<input type="submit" class="button" value="'.$this->l('I read the disclaimer - Create a new Backup').'" style="padding: 10px; font-weight: bold; border: 1px solid;" />
</form>';
echo '
</div>
<div class="warn width2" style="float: left;">
<p>'.$this->l('How-to restore a database Backup in 10 easy steps').'</p>
<ol style="font-size: 11px; font-weight: normal; line-height: 20px;">
<li>'.$this->l('Turn off the "Enable Shop" option in the "Preferences" tab.').'</li>
<li>'.$this->l('Download the Backup from the list below or from your FTP server (in the folder "admin/backups").').'</li>
<li>'.$this->l('Check the Backup integrity: look for errors, incomplete file. Verify all your data.').'</li>
<li>'.$this->l('Ask your hosting provider for a "phpMyAdmin" access to your database').'</li>
<li>'.$this->l('Connect to "phpMyAdmin" and select your current database').'</li>
<li>'.$this->l('Unless you enabled the "Drop existing tables" option, you must delete all tables from your current database.').'</li>
<li>'.$this->l('At the top of the screen select the tab "Import"').'</li>
<li>'.$this->l('Click on the "Browse..." button and select the Backup file from your hard drive').'</li>
<li>'.$this->l('Check the max. allowed filesize (ie. Max: 16Mb)').'<br />'.$this->l('If your Backup file exceeds this limit, contact your hosting provider').'</li>
<li>'.$this->l('Click on the "Go" button and wait during the import, the process can take several minutes').'</li>
</ol>
</div>
<div class="clear"></div>';
}
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]);
}
}
@@ -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 <contact@prestashop.com>
* @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)}
<fieldset style="margin: 40px 0;" class="width3">
<legend><img src="../img/admin/AdminBackup.gif" alt="" class="icon" /> {l s='Download'}</legend>
<p style="font-size: 13px;"><a href="{$backup_url}"><img src="../img/admin/AdminBackup.gif" alt="" class="icon" /></a><b><a href="{$backup_url}">{l s='Download the Backup file'} ({$backup_weight}{l s='Mb'})</a></b><br /><br />
{l s='Tip: You can also download this file by FTP, Backup files are located in "admin/backups" directory.'}</p>
</fieldset>
{/if}
{if isset($how_to)}
<div class="error width1" style="float: left; margin-right: 10px;">
<p>{l s='Disclaimer before creating a new Backup'}</p>
<ol style="font-size: 11px; font-weight: normal; line-height: 20px; padding-left: 10px;">
<li>{l s='PrestaShop is not responsible for your database, Backups, restore and data.'}</li>
<li>{l s='PrestaShop is an Open-source software, you are using it at your own risk under the licence agreement.'}</li>
<li>{l s='You should Backup your data on a regular basis (both files and database).'}</li>
<li>{l s='This function only backs up your database, not your files.'}</li>
<li>{l s='By default, your existing database tables will be deleted during Backup restore (see options).'}</li>
<li>{l s='Always verify the quality and integrity of your Backups files.'}</li>
<li>{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.'}</li>
<li>{l s='Always check your data.'}</li>
<li>{l s='Never restore a Backup on a live site.'}</li>
</ol>
{if $show_form}
<form action="{$current}&add{$table}&token={$token}" method="post" style="text-align: center;">
<input type="submit" class="button" value="{l s='I read the disclaimer - Create a new Backup'}" style="padding: 10px; font-weight: bold; border: 1px solid;" />
</form>
{/if}
</div>
<div class="warn width2" style="float: left;">
<p>{l s='How-to restore a database Backup in 10 easy steps'}</p>
<ol style="font-size: 11px; font-weight: normal; line-height: 20px;">
<li>{l s='Turn off the "Enable Shop" option in the "Preferences" tab.'}</li>
<li>{l s='Download the Backup from the list below or from your FTP server (in the folder "admin/backups").'}</li>
<li>{l s='Check the Backup integrity: look for errors, incomplete file. Verify all your data.'}</li>
<li>{l s='Ask your hosting provider for a "phpMyAdmin" access to your database'}</li>
<li>{l s='Connect to "phpMyAdmin" and select your current database'}</li>
<li>{l s='Unless you enabled the "Drop existing tables" option, you must delete all tables from your current database.'}</li>
<li>{l s='At the top of the screen select the tab "Import"'}</li>
<li>{l s='Click on the "Browse..." button and select the Backup file from your hard drive'}</li>
<li>{l s='Check the max. allowed filesize (ie. Max: 16Mb)'}<br />{l s='If your Backup file exceeds this limit, contact your hosting provider'}</li>
<li>{l s='Click on the "Go" button and wait during the import, the process can take several minutes'}</li>
</ol>
</div>
<div class="clear"></div>
{/if}
{if isset($download)}
<br /><br /><a href="{$current}&token={$token}"><img src="../img/admin/arrow2.gif" /> {l s='Back to list'}</a><br />
{/if}
{$content}
+33
View File
@@ -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 <contact@prestashop.com>
* @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
*}
<div class="conf confirm"><img src="../img/admin/ok.gif" />&nbsp;{l s='Beginning download ...'}</div>
<br />{l s='Back-up file should automatically download.'}
<br /><br />{l s='If not,'} <b><a href="{$url_backup}">{l s='please click here!'}</a></b>
<iframe width="0" height="0" scrolling="no" frameborder="0" src="{$url_backup}"></iframe>
<br /><br /><br /><a href="{$current}&token={$token}"><img src="../img/admin/arrow2.gif" /> {l s='Back to list'}</a><br />
@@ -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 <contact@prestashop.com>
* @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)}
<h2 class="space">{l s='Regenerate thumbnails'}</h2>
{l s='Regenerates thumbnails for all existing product images'}<br /><br />
<div class="width4">
<div class="warn">
{l s='Please be patient, as this can take several minutes'}<br />
{l s='Be careful! Manually generated thumbnails will be erased by automatically generated thumbnails.'}
</div>
</div>
<form action="{$current}&token={$token}" method="post">
<fieldset class="width4">
<legend><img src="../img/admin/picture.gif" /> {l s='Regenerate thumbnails'}</legend><br />
<label>{l s='Select image'}</label>
<div class="margin-form">
<select name="type" onchange="changeFormat(this)">
<option value="all">{l s='All'}</option>
{foreach $types AS $k => $type}
<option value="{$k}">{$type}</option>
{/foreach}
</select>
</div>
{foreach $types AS $k => $type}
<label class="second-select format_{$k}" style="display:none;">{l s='Select format'}</label>
<div class="second-select margin-form format_{$k}" style="display:none;">
<select class="second-select format_{$k}" name="format_{$k}">
<option value="all">{l s='All'}</option>';
{foreach $formats AS $format}
<option value="{$format['id_image_type']}">{$format['name']}</option>
{/foreach}
</select>
</div>
{/foreach}
<script>
function changeFormat(elt)
{ldelim}
$('.second-select').hide();
$('.format_' + $(elt).val()).show();
{rdelim}
</script>
<label>{l s='Erase previous images'}</label>
<div class="margin-form">
<input name="erase" type="checkbox" value="1" checked="checked" />
<p>{l s='Uncheck this checkbox only if your server timed out and you need to resume the regeneration.'}</p>
</div>
<div class="clear"></div>
<center><input type="Submit" name="submitRegenerate{$table}" value="{l s='Regenerate thumbnails'}" class="button space" onclick="return confirm('{l s='Are you sure?'}');" /></center>
</fieldset>
</form>
{/if}
{if isset($display_move)}
<br /><h2 class="space">{l s='Move images'}</h2>
{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.'}<br />
<br />
{if $safe_mode}
<div class="warn">
{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.'}
</div>
{else}
<form action="{$current}&token={$token}" method="post">
<fieldset class="width4">
<legend><img src="../img/admin/picture.gif" /> {l s='Move images'}</legend><br />
{l s='You can choose to keep your images stored in the previous system - nothing wrong with that.'}<br />
{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.'}
<br /><br />
<div class="hint clear" style="display: block;">&nbsp;
{l s='After moving all of your product images, for best performance go to the '}
<a style="text-decoration:underline" href="{$link_ppreferences}">{l s='product preferences tab'}</a>
{l s=' and set "Use the legacy image filesystem" to NO.'}
</div>
<center><input type="Submit" name="submitMoveImages{$table}" value="{l s='Move images'}" class="button space" onclick="return confirm('{l s='Are you sure?'}');" /></center>
</fieldset>
</form>
{/if}
{/if}
+21 -9
View File
@@ -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)
{
+271
View File
@@ -0,0 +1,271 @@
<?php
/*
* 2007-2011 PrestaShop
*
* NOTICE OF LICENSE
*
* This source file is subject to the Open Software License (OSL 3.0)
* that is bundled with this package in the file LICENSE.txt.
* It is also available through the world-wide-web at this URL:
* http://opensource.org/licenses/osl-3.0.php
* If you did not receive a copy of the license and are unable to
* obtain it through the world-wide-web, please send an email
* to license@prestashop.com so we can send you a copy immediately.
*
* DISCLAIMER
*
* Do not edit or add to this file if you wish to upgrade PrestaShop to newer
* versions in the future. If you wish to customize PrestaShop for your
* needs please refer to http://www.prestashop.com for more information.
*
* @author PrestaShop SA <contact@prestashop.com>
* @copyright 2007-2011 PrestaShop SA
* @version Release: $Revision: 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:').'<br />'._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').'<br />(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]);
}
}
+22 -23
View File
@@ -1,6 +1,6 @@
<?php
/*
* 2007-2011 PrestaShop
* 2007-2011 PrestaShop
*
* NOTICE OF LICENSE
*
@@ -47,7 +47,7 @@ class AdminHomeControllerCore extends AdminController
$rewrite = 0;
}
}
$htaccessAfterUpdate = 2;
$htaccessOptimized = (Configuration::get('PS_HTACCESS_CACHE_CONTROL') ? 2 : 0);
if (!file_exists(dirname(__FILE__).'/../../.htaccess'))
@@ -61,7 +61,7 @@ class AdminHomeControllerCore extends AdminController
$dateUpdHtaccess = Db::getInstance()->getValue('SELECT date_upd FROM '._DB_PREFIX_.'configuration WHERE name = "PS_HTACCESS_CACHE_CONTROL"');
if (Configuration::get('PS_HTACCESS_CACHE_CONTROL') AND strtotime($dateUpdHtaccess) > $stat['mtime'])
$htaccessOptimized = 1;
$dateUpdate = Configuration::get('PS_LAST_SHOP_UPDATE');
if ($dateUpdate AND strtotime($dateUpdate) > $stat['mtime'])
$htaccessAfterUpdate = 0;
@@ -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 = '<div id="table_info_large">
<h5><a href="index.php?tab=AdminStats&token='.Tools::getAdminTokenLite('AdminStats').'">'.$this->l('View more').'</a> <strong>'.$this->l('Statistics').'</strong> / '.$this->l('Sales of the week').'</h5>
<div id="stat_google">';
$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 .= ' </div>
</div>';
return $content;
}
public function getLastOrders()
{
$content = '
@@ -347,7 +347,7 @@ class AdminHomeControllerCore extends AdminController
<tr>
</thead>
<tbody>';
$orders = Order::getOrdersWithInformations(10);
$i = 0;
foreach ($orders AS $order)
@@ -366,7 +366,7 @@ class AdminHomeControllerCore extends AdminController
';
$i++;
}
$content .= '
</tbody>
</table>
@@ -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);
+2 -3
View File
@@ -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();
@@ -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.'));
+2 -2
View File
@@ -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']);
}
}