Skip to content
Snippets Groups Projects
Commit 80968bc0 authored by Laurent Destailleur's avatar Laurent Destailleur
Browse files

Merge pull request #1857 from aternatik/resource-fix

Fixes for resource module
parents 257d7c41 b7a2e378
No related branches found
No related tags found
No related merge requests found
......@@ -23,9 +23,11 @@ ShowResourcePlanning=Show resource planning
NoResourceInDatabase=No resource in database
GotoDate=Go to date
ResourceElementPage=Element resources
ResourceCreatedWithSuccess=Resource successfully created
RessourceLineSuccessfullyDeleted=Resource line successfully deleted
RessourceLineSuccessfullyUpdated=Resource line successfully updated
ResourceLinkedWithSuccess=Resource linked with success
TitleResourceCard=Resource card
ConfirmDeleteResource=Confirm to delete this resource
......
......@@ -2,7 +2,7 @@
MenuResourceIndex=Ressources
MenuResourceAdd=Nouvelle ressource
MenuResourcePlanning=Planning des Ressources
DeleteResource=Effacer resource
DeleteResource=Effacer ressource
ConfirmDeleteResourceElement=Confirmer la suppression de la ressource pour cet élément
NoResourceInDatabase=Aucune ressource en base de données.
NoResourceLinked=Aucune ressource liée
......@@ -17,17 +17,19 @@ ResourceFormLabel_description=Description de la ressource
ResourcesLinkedToElement=Ressources liées à l'élément
RessourceLineSuccessfullyUpdated=Ressource mise à jour
RessourceLineSuccessfullyDeleted=Resource supprimée
RessourceLineSuccessfullyDeleted=Ressource supprimée
ShowResourcePlanning=Montrer le planning des ressources
PlanningOfAffectedResources=Planning des ressources affectées aux évènements
GotoDate=Afficher la date
ResourceElementPage=Ressources de l'élément
ResourceCreatedWithSuccess=Ressource créee avec succès
RessourceLineSuccessfullyDeleted=Ressource supprimée avec succès
RessourceLineSuccessfullyUpdated=Ressource mise à jour
ResourceLinkedWithSuccess=Ressource liée avec succès
TitleResourceCard=Fiche resource
TitleResourceCard=Fiche ressource
ConfirmDeleteResource=Confirmer la suppression de cette ressource?
RessourceSuccessfullyDeleted=Ressource effacée avec succès
DictionaryResourceType=Type de ressources
\ No newline at end of file
......@@ -82,87 +82,5 @@ class ActionsResource
}
}
}
if (in_array('element_resource',explode(':',$parameters['context'])))
{
$element_id = GETPOST('element_id','int');
$element = GETPOST('element','alpha');
$resource_type = GETPOST('resource_type');
$fk_resource = GETPOST('fk_resource');
$busy = GETPOST('busy','int');
$mandatory = GETPOST('mandatory','int');
if($action == 'add_element_resource' && !GETPOST('cancel'))
{
$objstat = fetchObjectByElement($element_id,$element);
$res = $objstat->add_element_resource($fk_resource,$resource_type,$busy,$mandatory);
if($res > 0)
{
setEventMessage($langs->trans('ResourceLinkedWithSuccess'),'mesgs');
header("Location: ".$_SERVER['PHP_SELF'].'?element='.$element.'&element_id='.$element_id);
exit;
}
else
{
setEventMessage($langs->trans('ErrorWhenLinkingResource'),'errors');
header("Location: ".$_SERVER['PHP_SELF'].'?mode=add&resource_type='.$resource_type.'&element='.$element.'&element_id='.$element_id);
exit;
}
}
// Delete a resource linked to an element
if ($action == 'confirm_delete_linked_resource' && $user->rights->resource->delete && GETPOST('confirm') == 'yes')
{
$res = $object->fetch(GETPOST('id'));
if($res)
{
$result = $object->delete_resource(GETPOST('lineid'),GETPOST('element'));
if ($result >= 0)
{
setEventMessage($langs->trans('RessourceLineSuccessfullyDeleted'));
Header("Location: ".$_SERVER['PHP_SELF']."?element=".GETPOST('element')."&element_id=".GETPOST('element_id'));
exit;
}
else {
setEventMessage($object->error,'errors');
}
}
else
{
setEventMessage($object->error,'errors');
}
}
// Update ressource
if ($action == 'update_linked_resource' && $user->rights->resource->write && !GETPOST('cancel') )
{
$res = $object->fetch_element_resource(GETPOST('lineid'));
if($res)
{
$object->busy = GETPOST('busy');
$object->mandatory = GETPOST('mandatory');
$result = $object->update_element_resource($user);
if ($result >= 0)
{
setEventMessage($langs->trans('RessourceLineSuccessfullyUpdated'));
Header("Location: ".$_SERVER['PHP_SELF']."?element=".GETPOST('element')."&element_id=".GETPOST('element_id'));
exit;
}
else {
setEventMessage($object->error,'errors');
}
}
}
}
}*/
}
......@@ -779,7 +779,7 @@ class Resource extends CommonObject
// Links beetween objects are stored in this table
$sql = 'SELECT rowid, resource_id, resource_type, busy, mandatory';
$sql.= ' FROM '.MAIN_DB_PREFIX.'element_resources';
$sql.= " WHERE element_id='".$element_id."' AND resource_type='".$this->element."'";
$sql.= " WHERE element_id='".$element_id."' AND element_type='".$element."'";
if($resource_type)
$sql.=" AND resource_type LIKE '%".$resource_type."%'";
$sql .= ' ORDER BY resource_type';
......
......@@ -57,13 +57,90 @@ if( ! $user->rights->resource->read)
$object=new Resource($db);
$hookmanager->initHooks(array('element_resource'));
$object->available_resources = array('resource');
// Get parameters
$id = GETPOST('id','int');
$action = GETPOST('action','alpha');
$mode = GETPOST('mode','alpha');
$lineid = GETPOST('lineid','int');
$element = GETPOST('element','alpha');
$element_id = GETPOST('element_id','int');
$resource_id = GETPOST('fk_resource','int');
$resource_type = GETPOST('resource_type','alpha');
$busy = GETPOST('busy','int');
$mandatory = GETPOST('mandatory','int');
if($action == 'add_element_resource' && !GETPOST('cancel'))
{
$objstat = fetchObjectByElement($element_id,$element);
$res = $objstat->add_element_resource($resource_id,$resource_type,$busy,$mandatory);
if($res > 0)
{
setEventMessage($langs->trans('ResourceLinkedWithSuccess'),'mesgs');
header("Location: ".$_SERVER['PHP_SELF'].'?element='.$element.'&element_id='.$element_id);
exit;
}
else
{
setEventMessage($langs->trans('ErrorWhenLinkingResource'),'errors');
header("Location: ".$_SERVER['PHP_SELF'].'?mode=add&resource_type='.$resource_type.'&element='.$element.'&element_id='.$element_id);
exit;
}
}
// Update ressource
if ($action == 'update_linked_resource' && $user->rights->resource->write && !GETPOST('cancel') )
{
$res = $object->fetch_element_resource($lineid);
if($res)
{
$object->busy = $busy;
$object->mandatory = $mandatory;
$object->available_resources = array('resource');
$result = $object->update_element_resource($user);
$parameters=array('resource_id'=>$available_resources);
if ($result >= 0)
{
setEventMessage($langs->trans('RessourceLineSuccessfullyUpdated'));
Header("Location: ".$_SERVER['PHP_SELF']."?element=".$element."&element_id=".$element_id);
exit;
}
else {
setEventMessage($object->error,'errors');
}
}
}
// Delete a resource linked to an element
if ($action == 'confirm_delete_linked_resource' && $user->rights->resource->delete && GETPOST('confirm') == 'yes')
{
$res = $object->fetch(GETPOST('id'));
if($res)
{
$result = $object->delete_resource($lineid,$element);
if ($result >= 0)
{
setEventMessage($langs->trans('RessourceLineSuccessfullyDeleted'));
Header("Location: ".$_SERVER['PHP_SELF']."?element=".$element."&element_id=".$element_id);
exit;
}
else {
setEventMessage($object->error,'errors');
}
}
else
{
setEventMessage($object->error,'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
$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
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment