Merge pull request #1136 from jfefe/extrarequired
Missing checks on extrafields
This commit is contained in:
commit
385d3612c5
@ -344,9 +344,14 @@ else if ($action == 'add' && $user->rights->propal->creer)
|
|||||||
|
|
||||||
// Fill array 'array_options' with data from add form
|
// Fill array 'array_options' with data from add form
|
||||||
$ret = $extrafields->setOptionalsFromPost($extralabels,$object);
|
$ret = $extrafields->setOptionalsFromPost($extralabels,$object);
|
||||||
|
if($ret < 0) {
|
||||||
$id = $object->create($user);
|
$error++;
|
||||||
|
$action = 'create';
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if(!$error) {
|
||||||
|
$id = $object->create($user);
|
||||||
|
|
||||||
if ($id > 0)
|
if ($id > 0)
|
||||||
{
|
{
|
||||||
@ -395,6 +400,7 @@ else if ($action == 'add' && $user->rights->propal->creer)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// Classify billed
|
// Classify billed
|
||||||
else if ($action == 'classifybilled' && $user->rights->propal->cloturer)
|
else if ($action == 'classifybilled' && $user->rights->propal->cloturer)
|
||||||
@ -1121,6 +1127,12 @@ else if ($action == 'update_extras')
|
|||||||
$extralabels=$extrafields->fetch_name_optionals_label($object->table_element);
|
$extralabels=$extrafields->fetch_name_optionals_label($object->table_element);
|
||||||
$ret = $extrafields->setOptionalsFromPost($extralabels,$object);
|
$ret = $extrafields->setOptionalsFromPost($extralabels,$object);
|
||||||
|
|
||||||
|
if($ret < 0) {
|
||||||
|
$error++;
|
||||||
|
$action = 'edit_extras';
|
||||||
|
}
|
||||||
|
|
||||||
|
if(!$error) {
|
||||||
// Actions on extra fields (by external module or standard code)
|
// Actions on extra fields (by external module or standard code)
|
||||||
// FIXME le hook fait double emploi avec le trigger !!
|
// FIXME le hook fait double emploi avec le trigger !!
|
||||||
$hookmanager->initHooks(array('propaldao'));
|
$hookmanager->initHooks(array('propaldao'));
|
||||||
@ -1138,7 +1150,7 @@ else if ($action == 'update_extras')
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
else if ($reshook < 0) $error++;
|
else if ($reshook < 0) $error++;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (! empty($conf->global->MAIN_DISABLE_CONTACTS_TAB) && $user->rights->propal->creer)
|
if (! empty($conf->global->MAIN_DISABLE_CONTACTS_TAB) && $user->rights->propal->creer)
|
||||||
|
|||||||
@ -275,7 +275,10 @@ else if ($action == 'add' && $user->rights->commande->creer)
|
|||||||
|
|
||||||
// Fill array 'array_options' with data from add form
|
// Fill array 'array_options' with data from add form
|
||||||
$ret = $extrafields->setOptionalsFromPost($extralabels,$object);
|
$ret = $extrafields->setOptionalsFromPost($extralabels,$object);
|
||||||
|
if($ret < 0)
|
||||||
|
$error++;
|
||||||
|
|
||||||
|
if(!$error) {
|
||||||
$object_id = $object->create($user);
|
$object_id = $object->create($user);
|
||||||
|
|
||||||
if ($object_id > 0)
|
if ($object_id > 0)
|
||||||
@ -370,10 +373,19 @@ else if ($action == 'add' && $user->rights->commande->creer)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
|
{
|
||||||
|
// Required extrafield left blank, error message already defined by setOptionalsFromPost()
|
||||||
|
$action='create';
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
{
|
{
|
||||||
// Fill array 'array_options' with data from add form
|
// Fill array 'array_options' with data from add form
|
||||||
$ret = $extrafields->setOptionalsFromPost($extralabels,$object);
|
$ret = $extrafields->setOptionalsFromPost($extralabels,$object);
|
||||||
|
if($ret < 0)
|
||||||
|
$error++;
|
||||||
|
|
||||||
|
if(!$error) {
|
||||||
$object_id = $object->create($user);
|
$object_id = $object->create($user);
|
||||||
|
|
||||||
// If some invoice's lines already known
|
// If some invoice's lines already known
|
||||||
@ -389,6 +401,7 @@ else if ($action == 'add' && $user->rights->commande->creer)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// Insert default contacts if defined
|
// Insert default contacts if defined
|
||||||
if ($object_id > 0)
|
if ($object_id > 0)
|
||||||
@ -1130,6 +1143,10 @@ else if ($action == 'update_extras')
|
|||||||
$extralabels=$extrafields->fetch_name_optionals_label($object->table_element);
|
$extralabels=$extrafields->fetch_name_optionals_label($object->table_element);
|
||||||
$ret = $extrafields->setOptionalsFromPost($extralabels,$object);
|
$ret = $extrafields->setOptionalsFromPost($extralabels,$object);
|
||||||
|
|
||||||
|
if($ret < 0)
|
||||||
|
$error++;
|
||||||
|
|
||||||
|
if(!$error) {
|
||||||
// Actions on extra fields (by external module or standard code)
|
// Actions on extra fields (by external module or standard code)
|
||||||
// FIXME le hook fait double emploi avec le trigger !!
|
// FIXME le hook fait double emploi avec le trigger !!
|
||||||
$hookmanager->initHooks(array('orderdao'));
|
$hookmanager->initHooks(array('orderdao'));
|
||||||
@ -1147,6 +1164,11 @@ else if ($action == 'update_extras')
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
else if ($reshook < 0) $error++;
|
else if ($reshook < 0) $error++;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
$action = 'edit_extras';
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1335,7 +1357,7 @@ if ($action == 'send' && ! GETPOST('addfile') && ! GETPOST('removedfile') && ! G
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (! empty($conf->global->MAIN_DISABLE_CONTACTS_TAB) && $user->rights->commande->creer)
|
if (! $error && ! empty($conf->global->MAIN_DISABLE_CONTACTS_TAB) && $user->rights->commande->creer)
|
||||||
{
|
{
|
||||||
if ($action == 'addcontact')
|
if ($action == 'addcontact')
|
||||||
{
|
{
|
||||||
|
|||||||
@ -659,7 +659,8 @@ else if ($action == 'add' && $user->rights->facture->creer)
|
|||||||
// Fill array 'array_options' with data from add form
|
// Fill array 'array_options' with data from add form
|
||||||
$extralabels=$extrafields->fetch_name_optionals_label($object->table_element);
|
$extralabels=$extrafields->fetch_name_optionals_label($object->table_element);
|
||||||
$ret = $extrafields->setOptionalsFromPost($extralabels,$object);
|
$ret = $extrafields->setOptionalsFromPost($extralabels,$object);
|
||||||
|
if($ret < 0)
|
||||||
|
$error++;
|
||||||
|
|
||||||
// Replacement invoice
|
// Replacement invoice
|
||||||
if ($_POST['type'] == 1)
|
if ($_POST['type'] == 1)
|
||||||
@ -1858,7 +1859,10 @@ if ($action == 'update_extras')
|
|||||||
// Fill array 'array_options' with data from add form
|
// Fill array 'array_options' with data from add form
|
||||||
$extralabels=$extrafields->fetch_name_optionals_label($object->table_element);
|
$extralabels=$extrafields->fetch_name_optionals_label($object->table_element);
|
||||||
$ret = $extrafields->setOptionalsFromPost($extralabels,$object);
|
$ret = $extrafields->setOptionalsFromPost($extralabels,$object);
|
||||||
|
if($ret < 0)
|
||||||
|
$error++;
|
||||||
|
|
||||||
|
if(!$error) {
|
||||||
// Actions on extra fields (by external module or standard code)
|
// Actions on extra fields (by external module or standard code)
|
||||||
// FIXME le hook fait double emploi avec le trigger !!
|
// FIXME le hook fait double emploi avec le trigger !!
|
||||||
$hookmanager->initHooks(array('invoicedao'));
|
$hookmanager->initHooks(array('invoicedao'));
|
||||||
@ -1876,6 +1880,11 @@ if ($action == 'update_extras')
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
else if ($reshook < 0) $error++;
|
else if ($reshook < 0) $error++;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
$action = 'edit_extras';
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -894,7 +894,9 @@ class ExtraFields
|
|||||||
*/
|
*/
|
||||||
function setOptionalsFromPost($extralabels,&$object)
|
function setOptionalsFromPost($extralabels,&$object)
|
||||||
{
|
{
|
||||||
global $_POST;
|
global $_POST, $langs;
|
||||||
|
$nofillrequired='';// For error when required field left blank
|
||||||
|
$error_field_required = array();
|
||||||
|
|
||||||
if (is_array($extralabels))
|
if (is_array($extralabels))
|
||||||
{
|
{
|
||||||
@ -902,6 +904,11 @@ class ExtraFields
|
|||||||
foreach ($extralabels as $key => $value)
|
foreach ($extralabels as $key => $value)
|
||||||
{
|
{
|
||||||
$key_type = $this->attribute_type[$key];
|
$key_type = $this->attribute_type[$key];
|
||||||
|
if($this->attribute_required[$key] && !GETPOST("options_$key",2))
|
||||||
|
{
|
||||||
|
$nofillrequired++;
|
||||||
|
$error_field_required[] = $value;
|
||||||
|
}
|
||||||
|
|
||||||
if (in_array($key_type,array('date','datetime')))
|
if (in_array($key_type,array('date','datetime')))
|
||||||
{
|
{
|
||||||
@ -929,8 +936,15 @@ class ExtraFields
|
|||||||
$object->array_options["options_".$key]=$value_key;
|
$object->array_options["options_".$key]=$value_key;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if($nofillrequired) {
|
||||||
|
$langs->load('errors');
|
||||||
|
setEventMessage($langs->trans('ErrorFieldsRequired').' : '.implode(', ',$error_field_required),'errors');
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
else {
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
else {
|
else {
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user