[*] BO : Required fields improved (with a white list)

git-svn-id: http://dev.prestashop.com/svn/v1/branches/1.5.x@11276 b9a71923-0436-4b27-9f14-aed3839534dd
This commit is contained in:
vChabot
2011-12-15 16:37:08 +00:00
parent 79bf1d6d5c
commit 7d0942bcc2
5 changed files with 127 additions and 5 deletions

View File

@@ -0,0 +1,59 @@
{*
* 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: 11256 $
* @license http://opensource.org/licenses/afl-3.0.php Academic Free License (AFL 3.0)
* International Registered Trademark & Property of PrestaShop SA
*}
<br />
<p>
<a href="#" onclick="if ($('.requiredFieldsParameters:visible').length == 0) $('.requiredFieldsParameters').slideDown('slow'); else $('.requiredFieldsParameters').slideUp('slow'); return false;"><img src="../img/admin/duplicate.gif" alt="" /> {l s='Set required fields for this section'}</a>
</p>
<fieldset style="display:none" class="width1 requiredFieldsParameters">
<legend>{l s='Required Fields'}</legend>
<form name="updateFields" action="{$current}&submitFields=1&token={$token}" method="post">
<p>
<b>{l s='Select the fields you would like to be required for this section.'}</b><br />
<table cellspacing="0" cellpadding="0" class="table width1 clear">
<thead>
<tr>
<th><input type="checkbox" onclick="checkDelBoxes(this.form, 'fieldsBox[]', this.checked)" class="noborder" name="checkme"></th>
<th>{l s='Field Name'}</th>
</tr>
</thead>
<tbody>
{foreach $table_fields as $field}
{if !in_array($field, $required_class_fields)}
<tr class="{if $irow++ % 2}alt_row{/if}">
<td class="noborder"><input type="checkbox" name="fieldsBox[]" value="{$field}" {if in_array($field, $required_fields)} checked="checked"{/if} /></td>
<td>{$field}</td>
</tr>
{/if}
{/foreach}
</tbody>
</table><br />
<center>
<input style="margin-left:15px;" class="button" type="submit" value="{l s=' Save '}" name="submitFields" />
</center>
</p>
</form>
</fieldset>

View File

@@ -64,6 +64,8 @@ class AdminControllerCore extends Controller
/** @var array noTabLink array of admintab names witch have no content */
public $noTabLink = array('AdminCatalog', 'AdminTools', 'AdminStock', 'AdminAccounting');
public $required_database = false;
/** @var string Security token */
public $token;
@@ -78,6 +80,7 @@ class AdminControllerCore extends Controller
public $tpl_delete_link_vars = array();
public $tpl_option_vars = array();
public $tpl_view_vars = array();
public $tpl_required_fields_vars = array();
public $base_tpl_view = null;
public $base_tpl_form = null;
@@ -158,6 +161,9 @@ class AdminControllerCore extends Controller
/** @var array $cache_lang cache for traduction */
public static $cache_lang = array();
/** @var array required_fields to display in the Required Fields form */
public $required_fields = array();
/**
* @var array actions to execute on multiple selections
* Usage:
@@ -1361,6 +1367,9 @@ class AdminControllerCore extends Controller
$this->content .= $this->renderList();
$this->content .= $this->renderOptions();
}
// if we have to display the required fields form
if ($this->required_database)
$this->content .= $this->displayRequiredFields();
$this->context->smarty->assign(array(
'content' => $this->content,
@@ -1853,7 +1862,7 @@ class AdminControllerCore extends Controller
/* Submit options list */
else if (Tools::getValue('submitOptions'.$this->table) || Tools::getValue('submitOptions'))
$this->action = 'update_options';
else if (Tools::isSubmit('submitFields') && $this->requiredDatabase && $this->tabAccess['add'] === '1' && $this->tabAccess['delete'] === '1')
else if (Tools::isSubmit('submitFields') && $this->required_database && $this->tabAccess['add'] === '1' && $this->tabAccess['delete'] === '1')
$this->action = 'update_fields';
else if (is_array($this->bulk_actions))
foreach ($this->bulk_actions as $bulk_action => $params)
@@ -2512,5 +2521,19 @@ class AdminControllerCore extends Controller
{
return true;
}
/**
* prepare the view to display the required fields form
*/
public function displayRequiredFields()
{
if (!$this->tabAccess['add'] || !$this->tabAccess['delete'] === '1' || !$this->required_database)
return;
$helper = new Helper();
$helper->currentIndex = self::$currentIndex;
$helper->token = $this->token;
return $helper->renderRequiredFields($this->className, $this->identifier, $this->required_fields);
}
}

View File

@@ -321,17 +321,17 @@ class HelperCore
$type = 'shop';
$assos = array();
if ((int)$this->id)
{
$sql = 'SELECT id_'.$type.', `'.pSQL($this->identifier).'`
FROM `'._DB_PREFIX_.pSQL($this->table).'_'.$type.'`
WHERE `'.pSQL($this->identifier).'` = '.(int)$this->id;
foreach (Db::getInstance()->executeS($sql) as $row)
$assos[$row['id_'.$type]] = $row['id_'.$type];
}
$tpl = $this->createTemplate('helper/assoshop.tpl');
$tpl->assign(array(
'input' => array(
@@ -347,5 +347,41 @@ class HelperCore
return $tpl->fetch();
}
/**
* Render a form with potentials required fields
*
* @param string $class_name
* @param string $identifier
* @param array $table_fields
* @return string
*/
public function renderRequiredFields($class_name, $identifier, $table_fields)
{
$rules = call_user_func_array(array($class_name, 'getValidationRules'), array($class_name));
$required_class_fields = array($identifier);
foreach ($rules['required'] as $required)
$required_class_fields[] = $required;
$object = new $class_name();
$res = $object->getFieldsRequiredDatabase();
$required_fields = array();
foreach ($res as $row)
$required_fields[(int)$row['id_required_field']] = $row['field_name'];
$this->tpl_vars = array(
'table_fields' => $table_fields,
'irow' => 0,
'required_class_fields' => $required_class_fields,
'required_fields' => $required_fields,
'current' => $this->currentIndex,
'token' => $this->token
);
$tpl = $this->createTemplate('helper/required_fields.tpl');
$tpl->assign($this->tpl_vars);
return $tpl->fetch();
}
}

View File

@@ -32,6 +32,8 @@ class AdminAddressesControllerCore extends AdminController
public function __construct()
{
$this->required_database = true;
$this->required_fields = array('company','address2', 'postcode', 'other', 'phone', 'phone_mobile', 'vat_number', 'dni');
$this->table = 'address';
$this->className = 'Address';
$this->lang = false;

View File

@@ -31,6 +31,8 @@ class AdminCustomersControllerCore extends AdminController
public function __construct()
{
$this->required_database = true;
$this->required_fields = array('newsletter','optin');
$this->table = 'customer';
$this->className = 'Customer';
$this->lang = false;
@@ -157,6 +159,7 @@ class AdminCustomersControllerCore extends AdminController
'url_delete' => htmlentities($_SERVER['REQUEST_URI']),
'boxes' => $this->boxes,
));
parent::initContent();
}
@@ -736,7 +739,6 @@ class AdminCustomersControllerCore extends AdminController
'.($customer->optin ? '<img src="../img/admin/enabled.gif" />' : '<img src="../img/admin/disabled.gif" />').
'</a>';
}
}