[-] BO: Modified treatment. now the limit of upload can be modified in the "preferences" tab
This commit is contained in:
@@ -33,6 +33,10 @@ class AdminPreferencesControllerCore extends AdminController
|
||||
$this->context = Context::getContext();
|
||||
$this->className = 'Configuration';
|
||||
$this->table = 'configuration';
|
||||
|
||||
$max_upload = (int)ini_get('upload_max_filesize');
|
||||
$max_post = (int)ini_get('post_max_size');
|
||||
$upload_mb = min($max_upload, $max_post);
|
||||
|
||||
// Prevent classes which extend AdminPreferences to load useless data
|
||||
if (get_class($this) == 'AdminPreferencesController')
|
||||
@@ -156,13 +160,6 @@ class AdminPreferencesControllerCore extends AdminController
|
||||
'default' => '480',
|
||||
'visibility' => Shop::CONTEXT_ALL
|
||||
),
|
||||
'PS_B2B_ENABLE' => array(
|
||||
'title' => $this->l('Enable B2B mode'),
|
||||
'desc' => $this->l('Activate or deactivate B2B mode. When this option is enable some features about B2B appear.'),
|
||||
'validation' => 'isBool',
|
||||
'cast' => 'intval',
|
||||
'type' => 'bool'
|
||||
),
|
||||
'PS_ORDER_PROCESS_TYPE' => array(
|
||||
'title' => $this->l('Order process type'),
|
||||
'desc' => $this->l('You can choose the order process type as either standard (5 steps) or One Page Checkout'),
|
||||
@@ -319,9 +316,27 @@ class AdminPreferencesControllerCore extends AdminController
|
||||
'validation' => 'isBool',
|
||||
'cast' => 'intval',
|
||||
'type' => 'bool'
|
||||
)
|
||||
),
|
||||
'PS_LIMIT_UPLOAD_FILE_VALUE' => array(
|
||||
'title' => $this->l('Limit upload file value'),
|
||||
'desc' => $this->l('Define the limit upload for a downloadable product, this value have to be inferior or egal to your server\'s maximum upload file ').sprintf('(%s MB).',$upload_mb),
|
||||
'validation' => 'isInt',
|
||||
'cast' => 'intval',
|
||||
'type' => 'text',
|
||||
'suffix' => $this->l('Megabits'),
|
||||
'default' => '1'
|
||||
),
|
||||
'PS_LIMIT_UPLOAD_IMAGE_VALUE' => array(
|
||||
'title' => $this->l('Limit upload image value'),
|
||||
'desc' => $this->l('Define the limit upload for an image, this value have to be inferior or egal to your server\'s maximum upload file ').sprintf('(%s MB).',$upload_mb),
|
||||
'validation' => 'isInt',
|
||||
'cast' => 'intval',
|
||||
'type' => 'text',
|
||||
'suffix' => $this->l('Megabits'),
|
||||
'default' => '1'
|
||||
),
|
||||
);
|
||||
|
||||
|
||||
if (function_exists('date_default_timezone_set'))
|
||||
$fields['PS_TIMEZONE'] = array(
|
||||
'title' => $this->l('Time Zone:'),
|
||||
@@ -345,7 +360,8 @@ class AdminPreferencesControllerCore extends AdminController
|
||||
'title' => $this->l('General'),
|
||||
'icon' => 'tab-preferences',
|
||||
'fields' => $fields,
|
||||
'submit' => array('title' => $this->l(' Save '), 'class' => 'button')
|
||||
'submit' => array('title' => $this->l(' Save '), 'class' => 'button'),
|
||||
|
||||
),
|
||||
);
|
||||
}
|
||||
@@ -355,6 +371,22 @@ class AdminPreferencesControllerCore extends AdminController
|
||||
|
||||
public function postProcess()
|
||||
{
|
||||
$upload_max_size = (int)str_replace('M', '', ini_get('upload_max_filesize'));
|
||||
$post_max_size = (int)str_replace('M', '', ini_get('post_max_size'));
|
||||
$max_size = $upload_max_size < $post_max_size ? $upload_max_size : $post_max_size;
|
||||
|
||||
if (Tools::getValue('PS_LIMIT_UPLOAD_FILE_VALUE') > $max_size or Tools::getValue('PS_LIMIT_UPLOAD_IMAGE_VALUE') > $max_size)
|
||||
{
|
||||
$this->_errors[] = Tools::displayError('The limit choosen is superior to the server\'s maximum upload file You need to improve the limit of your server.');
|
||||
return;
|
||||
}
|
||||
|
||||
if (Tools::getIsset('PS_LIMIT_UPLOAD_FILE_VALUE') && !Tools::getValue('PS_LIMIT_UPLOAD_FILE_VALUE'))
|
||||
$_POST['PS_LIMIT_UPLOAD_FILE_VALUE'] = 1;
|
||||
|
||||
if (Tools::getIsset('PS_LIMIT_UPLOAD_IMAGE_VALUE') && !Tools::getValue('PS_LIMIT_UPLOAD_IMAGE_VALUE'))
|
||||
$_POST['PS_LIMIT_UPLOAD_IMAGE_VALUE'] = 1;
|
||||
|
||||
Tools::clearCache($this->context->smarty);
|
||||
parent::postProcess();
|
||||
}
|
||||
@@ -385,37 +417,15 @@ class AdminPreferencesControllerCore extends AdminController
|
||||
/**
|
||||
* Update PS_ATTACHMENT_MAXIMUM_SIZE
|
||||
*/
|
||||
public function updateOptionPsAttachmentMaximumSize($value)
|
||||
public function updateOptionPsAttachementMaximumSize($value)
|
||||
{
|
||||
if (!$value)
|
||||
return;
|
||||
|
||||
$upload_max_size = Tools::convertBytes(ini_get('upload_max_filesize'));
|
||||
$post_max_size = Tools::convertBytes(ini_get('post_max_size'));
|
||||
$max_size = ($upload_max_size < $post_max_size ? $upload_max_size : $post_max_size) / 1048576;
|
||||
// at this point, all values are in megaBytes
|
||||
$upload_max_size = (int)str_replace('M', '', ini_get('upload_max_filesize'));
|
||||
$post_max_size = (int)str_replace('M', '', ini_get('post_max_size'));
|
||||
$max_size = $upload_max_size < $post_max_size ? $upload_max_size : $post_max_size;
|
||||
$value = ($max_size < Tools::getValue('PS_ATTACHMENT_MAXIMUM_SIZE')) ? $max_size : Tools::getValue('PS_ATTACHMENT_MAXIMUM_SIZE');
|
||||
Configuration::update('PS_ATTACHMENT_MAXIMUM_SIZE', $value);
|
||||
}
|
||||
|
||||
/**
|
||||
* Update PS_B2B_ENABLE and enables / disables the associated tabs
|
||||
* @param $value integer Value of option
|
||||
*/
|
||||
public function updateOptionPsB2bEnable($value)
|
||||
{
|
||||
$value = (int)$value;
|
||||
|
||||
$tabs_class_name = array('AdminOutstanding');
|
||||
if (!empty($tabs_class_name)) {
|
||||
foreach ($tabs_class_name as $tab_class_name) {
|
||||
$tab = Tab::getInstanceFromClassName($tab_class_name);
|
||||
if (Validate::isLoadedObject($tab)) {
|
||||
$tab->active = $value;
|
||||
$tab->save();
|
||||
}
|
||||
}
|
||||
}
|
||||
Configuration::updateValue('PS_B2B_ENABLE', $value);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user