Merge pull request #7244 from atm-john/new_resource_ref_mask
FIX resource hooks
This commit is contained in:
commit
5c53081007
@ -66,64 +66,72 @@ $extrafields = new ExtraFields($db);
|
||||
// fetch optionals attributes and labels
|
||||
$extralabels=$extrafields->fetch_name_optionals_label($object->table_element);
|
||||
|
||||
if ($action == 'confirm_add_resource')
|
||||
$hookmanager->initHooks(array('resource_card_add','globalcard'));
|
||||
$parameters=array();
|
||||
$reshook=$hookmanager->executeHooks('doActions',$parameters,$object,$action); // Note that $action and $object may have been modified by some hooks
|
||||
if ($reshook < 0) setEventMessages($hookmanager->error, $hookmanager->errors, 'errors');
|
||||
|
||||
if (empty($reshook))
|
||||
{
|
||||
if (! $cancel)
|
||||
{
|
||||
$error='';
|
||||
|
||||
$ref=GETPOST('ref','alpha');
|
||||
$description=GETPOST('description','alpha');
|
||||
$fk_code_type_resource=GETPOST('fk_code_type_resource','alpha');
|
||||
|
||||
if (empty($ref))
|
||||
{
|
||||
$mesg=$langs->trans("ErrorFieldRequired",$langs->transnoentities("Ref"));
|
||||
setEventMessages($mesg, null, 'errors');
|
||||
$error++;
|
||||
}
|
||||
|
||||
if (! $error)
|
||||
{
|
||||
$object=new Dolresource($db);
|
||||
$object->ref=$ref;
|
||||
$object->description=$description;
|
||||
$object->fk_code_type_resource=$fk_code_type_resource;
|
||||
|
||||
// Fill array 'array_options' with data from add form
|
||||
$ret = $extrafields->setOptionalsFromPost($extralabels, $object);
|
||||
if ($ret < 0) {
|
||||
$error ++;
|
||||
}
|
||||
|
||||
$result=$object->create($user);
|
||||
if ($result > 0)
|
||||
{
|
||||
// Creation OK
|
||||
$db->commit();
|
||||
setEventMessages($langs->trans('ResourceCreatedWithSuccess'), null, 'mesgs');
|
||||
Header("Location: card.php?id=" . $object->id);
|
||||
return;
|
||||
}
|
||||
else
|
||||
{
|
||||
// Creation KO
|
||||
setEventMessages($object->error, $object->errors, 'errors');
|
||||
$action = '';
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
$action = '';
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
Header("Location: list.php");
|
||||
}
|
||||
if ($action == 'confirm_add_resource')
|
||||
{
|
||||
if (! $cancel)
|
||||
{
|
||||
$error='';
|
||||
|
||||
$ref=GETPOST('ref','alpha');
|
||||
$description=GETPOST('description','alpha');
|
||||
$fk_code_type_resource=GETPOST('fk_code_type_resource','alpha');
|
||||
|
||||
if (empty($ref))
|
||||
{
|
||||
$mesg=$langs->trans("ErrorFieldRequired",$langs->transnoentities("Ref"));
|
||||
setEventMessages($mesg, null, 'errors');
|
||||
$error++;
|
||||
}
|
||||
|
||||
if (! $error)
|
||||
{
|
||||
$object=new Dolresource($db);
|
||||
$object->ref=$ref;
|
||||
$object->description=$description;
|
||||
$object->fk_code_type_resource=$fk_code_type_resource;
|
||||
|
||||
// Fill array 'array_options' with data from add form
|
||||
$ret = $extrafields->setOptionalsFromPost($extralabels, $object);
|
||||
if ($ret < 0) {
|
||||
$error ++;
|
||||
}
|
||||
|
||||
$result=$object->create($user);
|
||||
if ($result > 0)
|
||||
{
|
||||
// Creation OK
|
||||
$db->commit();
|
||||
setEventMessages($langs->trans('ResourceCreatedWithSuccess'), null, 'mesgs');
|
||||
Header("Location: card.php?id=" . $object->id);
|
||||
return;
|
||||
}
|
||||
else
|
||||
{
|
||||
// Creation KO
|
||||
setEventMessages($object->error, $object->errors, 'errors');
|
||||
$action = '';
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
$action = '';
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
Header("Location: list.php");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* View
|
||||
*/
|
||||
|
||||
@ -54,10 +54,13 @@ if ($user->societe_id > 0)
|
||||
accessforbidden();
|
||||
}
|
||||
|
||||
if( ! $user->rights->resource->read)
|
||||
if (! $user->rights->resource->read)
|
||||
accessforbidden();
|
||||
|
||||
$object = new Dolresource($db);
|
||||
$objectFetchRes = $object->fetch($id);
|
||||
if (! ($objectFetchRes > 0)) dol_print_error($db, $object->error);
|
||||
|
||||
|
||||
$extrafields = new ExtraFields($db);
|
||||
|
||||
@ -162,7 +165,7 @@ llxHeader('',$pagetitle,'');
|
||||
$form = new Form($db);
|
||||
$formresource = new FormResource($db);
|
||||
|
||||
if ( $object->fetch($id) > 0 )
|
||||
if ( $objectFetchRes > 0 )
|
||||
{
|
||||
$head=resource_prepare_head($object);
|
||||
|
||||
|
||||
Loading…
Reference in New Issue
Block a user