Merge pull request #11568 from joseplluis/patch-7
FIX: move doActions hook before standard actions
This commit is contained in:
commit
4bda18fd4d
@ -81,47 +81,71 @@ if ($socid > 0) // Special for thirdparty
|
|||||||
* Actions
|
* Actions
|
||||||
*/
|
*/
|
||||||
|
|
||||||
if ($action == 'add_element_resource' && ! $cancel)
|
$parameters = array('resource_id' => $resource_id);
|
||||||
{
|
$reshook = $hookmanager->executeHooks('doActions', $parameters, $object, $action); // Note that $action and $object may have been modified by some hooks
|
||||||
$res = 0;
|
if ($reshook < 0) setEventMessages($hookmanager->error, $hookmanager->errors, 'errors');
|
||||||
if (! ($resource_id > 0))
|
|
||||||
{
|
|
||||||
$error++;
|
|
||||||
setEventMessages($langs->trans("ErrorFieldRequired", $langs->transnoentitiesnoconv("Resource")), null, 'errors');
|
|
||||||
$action='';
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
$objstat = fetchObjectByElement($element_id, $element, $element_ref);
|
|
||||||
$objstat->element = $element; // For externals module, we need to keep @xx
|
|
||||||
$res = $objstat->add_element_resource($resource_id, $resource_type, $busy, $mandatory);
|
|
||||||
}
|
|
||||||
if (! $error && $res > 0)
|
|
||||||
{
|
|
||||||
setEventMessages($langs->trans('ResourceLinkedWithSuccess'), null, 'mesgs');
|
|
||||||
header("Location: ".$_SERVER['PHP_SELF'].'?element='.$element.'&element_id='.$objstat->id);
|
|
||||||
exit;
|
|
||||||
}
|
|
||||||
elseif ($objstat)
|
|
||||||
{
|
|
||||||
setEventMessages($objstat->error, $objstat->errors, 'errors');
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// Update ressource
|
if (empty($reshook))
|
||||||
if ($action == 'update_linked_resource' && $user->rights->resource->write && !GETPOST('cancel', 'alpha') )
|
|
||||||
{
|
{
|
||||||
$res = $object->fetch_element_resource($lineid);
|
if ($action == 'add_element_resource' && ! $cancel)
|
||||||
if($res)
|
|
||||||
{
|
{
|
||||||
$object->busy = $busy;
|
$res = 0;
|
||||||
$object->mandatory = $mandatory;
|
if (! ($resource_id > 0))
|
||||||
|
{
|
||||||
|
$error++;
|
||||||
|
setEventMessages($langs->trans("ErrorFieldRequired", $langs->transnoentitiesnoconv("Resource")), null, 'errors');
|
||||||
|
$action='';
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
$objstat = fetchObjectByElement($element_id, $element, $element_ref);
|
||||||
|
$objstat->element = $element; // For externals module, we need to keep @xx
|
||||||
|
$res = $objstat->add_element_resource($resource_id, $resource_type, $busy, $mandatory);
|
||||||
|
}
|
||||||
|
if (! $error && $res > 0)
|
||||||
|
{
|
||||||
|
setEventMessages($langs->trans('ResourceLinkedWithSuccess'), null, 'mesgs');
|
||||||
|
header("Location: ".$_SERVER['PHP_SELF'].'?element='.$element.'&element_id='.$objstat->id);
|
||||||
|
exit;
|
||||||
|
}
|
||||||
|
elseif ($objstat)
|
||||||
|
{
|
||||||
|
setEventMessages($objstat->error, $objstat->errors, 'errors');
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
$result = $object->update_element_resource($user);
|
// Update ressource
|
||||||
|
if ($action == 'update_linked_resource' && $user->rights->resource->write && !GETPOST('cancel', 'alpha') )
|
||||||
|
{
|
||||||
|
$res = $object->fetch_element_resource($lineid);
|
||||||
|
if($res)
|
||||||
|
{
|
||||||
|
$object->busy = $busy;
|
||||||
|
$object->mandatory = $mandatory;
|
||||||
|
|
||||||
|
$result = $object->update_element_resource($user);
|
||||||
|
|
||||||
|
if ($result >= 0)
|
||||||
|
{
|
||||||
|
setEventMessages($langs->trans('RessourceLineSuccessfullyUpdated'), null, 'mesgs');
|
||||||
|
header("Location: ".$_SERVER['PHP_SELF']."?element=".$element."&element_id=".$element_id);
|
||||||
|
exit;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
setEventMessages($object->error, $object->errors, 'errors');
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Delete a resource linked to an element
|
||||||
|
if ($action == 'confirm_delete_linked_resource' && $user->rights->resource->delete && $confirm === 'yes')
|
||||||
|
{
|
||||||
|
$result = $object->delete_resource($lineid, $element);
|
||||||
|
|
||||||
if ($result >= 0)
|
if ($result >= 0)
|
||||||
{
|
{
|
||||||
setEventMessages($langs->trans('RessourceLineSuccessfullyUpdated'), null, 'mesgs');
|
setEventMessages($langs->trans('RessourceLineSuccessfullyDeleted'), null, 'mesgs');
|
||||||
header("Location: ".$_SERVER['PHP_SELF']."?element=".$element."&element_id=".$element_id);
|
header("Location: ".$_SERVER['PHP_SELF']."?element=".$element."&element_id=".$element_id);
|
||||||
exit;
|
exit;
|
||||||
}
|
}
|
||||||
@ -132,28 +156,6 @@ if ($action == 'update_linked_resource' && $user->rights->resource->write && !GE
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Delete a resource linked to an element
|
|
||||||
if ($action == 'confirm_delete_linked_resource' && $user->rights->resource->delete && $confirm === 'yes')
|
|
||||||
{
|
|
||||||
$result = $object->delete_resource($lineid, $element);
|
|
||||||
|
|
||||||
if ($result >= 0)
|
|
||||||
{
|
|
||||||
setEventMessages($langs->trans('RessourceLineSuccessfullyDeleted'), null, 'mesgs');
|
|
||||||
header("Location: ".$_SERVER['PHP_SELF']."?element=".$element."&element_id=".$element_id);
|
|
||||||
exit;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
setEventMessages($object->error, $object->errors, 'errors');
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
$parameters=array('resource_id'=>$resource_id);
|
|
||||||
$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');
|
|
||||||
|
|
||||||
|
|
||||||
$parameters=array('resource_id'=>$resource_id);
|
$parameters=array('resource_id'=>$resource_id);
|
||||||
$reshook=$hookmanager->executeHooks('getElementResources', $parameters, $object, $action); // Note that $action and $object may have been modified by some hooks
|
$reshook=$hookmanager->executeHooks('getElementResources', $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 ($reshook < 0) setEventMessages($hookmanager->error, $hookmanager->errors, 'errors');
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user