diff --git a/htdocs/resource/card.php b/htdocs/resource/card.php index abb07820fa0..5007c70e867 100644 --- a/htdocs/resource/card.php +++ b/htdocs/resource/card.php @@ -44,6 +44,7 @@ $id = GETPOST('id','int'); $action = GETPOST('action','alpha'); $ref = GETPOST('ref'); $description = GETPOST('description'); +$confirm = GETPOST('confirm'); $fk_code_type_resource = GETPOST('fk_code_type_resource','alpha'); // Protection if external user @@ -111,6 +112,29 @@ if (empty($reshook)) $action='edit'; } } + + if ($action == 'confirm_delete_resource' && $user->rights->resource->delete && $confirm === 'yes') + { + $res = $object->fetch($id); + if($res > 0) + { + $result = $object->delete($id); + + if ($result >= 0) + { + setEventMessage($langs->trans('RessourceSuccessfullyDeleted')); + Header('Location: '.DOL_URL_ROOT.'/resource/list.php'); + exit; + } + else { + setEventMessage($object->error,'errors'); + } + } + else + { + setEventMessage($object->error,'errors'); + } + } } diff --git a/htdocs/resource/class/resource.class.php b/htdocs/resource/class/resource.class.php index cac917fa85b..3c3f0ee6e49 100644 --- a/htdocs/resource/class/resource.class.php +++ b/htdocs/resource/class/resource.class.php @@ -84,7 +84,7 @@ class Resource extends CommonObject // Insert request - $sql = "INSERT INTO ".MAIN_DB_PREFIX."resource("; + $sql = "INSERT INTO ".MAIN_DB_PREFIX.$this->table_element."("; $sql.= " entity,"; $sql.= "ref,"; @@ -114,7 +114,7 @@ class Resource extends CommonObject if (! $error) { - $this->id = $this->db->last_insert_id(MAIN_DB_PREFIX."place"); + $this->id = $this->db->last_insert_id(MAIN_DB_PREFIX.$this->table_element); if (! $notrigger) { @@ -164,7 +164,7 @@ class Resource extends CommonObject $sql.= " t.note_private,"; $sql.= " t.tms,"; $sql.= " ty.label as type_label"; - $sql.= " FROM ".MAIN_DB_PREFIX."resource as t"; + $sql.= " FROM ".MAIN_DB_PREFIX.$this->table_element." as t"; $sql.= " LEFT JOIN ".MAIN_DB_PREFIX."c_type_resource as ty ON ty.code=t.fk_code_type_resource"; $sql.= " WHERE t.rowid = ".$this->db->escape($id); @@ -216,7 +216,7 @@ class Resource extends CommonObject if (isset($this->description)) $this->description=trim($this->description); // Update request - $sql = "UPDATE ".MAIN_DB_PREFIX."resource SET"; + $sql = "UPDATE ".MAIN_DB_PREFIX.$this->table_element." SET"; $sql.= " ref=".(isset($this->ref)?"'".$this->db->escape($this->ref)."'":"null").","; $sql.= " description=".(isset($this->description)?"'".$this->db->escape($this->description)."'":"null").","; $sql.= " fk_code_type_resource=".(isset($this->fk_code_type_resource)?"'".$this->db->escape($this->fk_code_type_resource)."'":"null").","; @@ -340,7 +340,7 @@ class Resource extends CommonObject // End call triggers } - $sql = "DELETE FROM ".MAIN_DB_PREFIX."resource"; + $sql = "DELETE FROM ".MAIN_DB_PREFIX.$this->table_element; $sql.= " WHERE rowid =".$rowid; dol_syslog(get_class($this)."::delete", LOG_DEBUG); @@ -386,7 +386,7 @@ class Resource extends CommonObject $sql.= " t.fk_code_type_resource,"; $sql.= " t.tms,"; $sql.= " ty.label as type_label"; - $sql.= " FROM ".MAIN_DB_PREFIX."resource as t"; + $sql.= " FROM ".MAIN_DB_PREFIX.$this->table_element." as t"; $sql.= " LEFT JOIN ".MAIN_DB_PREFIX."c_type_resource as ty ON ty.code=t.fk_code_type_resource"; $sql.= " WHERE t.entity IN (".getEntity('resource',1).")"; diff --git a/htdocs/resource/element_resource.php b/htdocs/resource/element_resource.php index 123673654c9..148d2d3b39d 100644 --- a/htdocs/resource/element_resource.php +++ b/htdocs/resource/element_resource.php @@ -34,16 +34,6 @@ require_once DOL_DOCUMENT_ROOT.'/core/lib/functions2.lib.php'; $langs->load("resource"); $langs->load("other"); -// 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('resource_id','int'); -$resource_type = GETPOST('resource_type','alpha'); - /* $sortorder = GETPOST('sortorder','alpha'); $sortfield = GETPOST('sortfield','alpha'); @@ -80,7 +70,11 @@ $confirm = GETPOST('confirm','alpha'); if($action == 'add_element_resource' && ! $cancel) { $objstat = fetchObjectByElement($element_id,$element); - $res = $objstat->add_element_resource($resource_id,$resource_type,$busy,$mandatory); + $res = 0; + if ($resource_id >= 0) + { + $res = $objstat->add_element_resource($resource_id, $resource_type, $busy, $mandatory); + } if($res > 0) { setEventMessage($langs->trans('ResourceLinkedWithSuccess'),'mesgs'); @@ -89,7 +83,7 @@ if($action == 'add_element_resource' && ! $cancel) } else { - setEventMessage($langs->trans('ErrorWhenLinkingResource'),'errors'); + setEventMessage($langs->trans('ErrorWhenLinkingResource') . " " . $objstat->error, 'errors'); header("Location: ".$_SERVER['PHP_SELF'].'?mode=add&resource_type='.$resource_type.'&element='.$element.'&element_id='.$element_id); exit; } @@ -142,7 +136,7 @@ if ($action == 'confirm_delete_linked_resource' && $user->rights->resource->dele } } -$parameters=array('resource_id'=>resource_id); +$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'); @@ -254,7 +248,7 @@ else - foreach ($object->available_resources as $modresources => $resources) + foreach ($object->available_resources as $modresources => $resources) { $resources=(array) $resources; // To be sure $resources is an array foreach($resources as $resource_obj)