diff --git a/htdocs/core/class/commonobject.class.php b/htdocs/core/class/commonobject.class.php index 379b955cd0d..cf376520fa7 100644 --- a/htdocs/core/class/commonobject.class.php +++ b/htdocs/core/class/commonobject.class.php @@ -3277,9 +3277,10 @@ abstract class CommonObject print ''; } - + /** - * Add resources to the current object + * Add resources to the current object : add entry into llx_element_resources + *Need $this->element & $this->id * * @param int $resource_id Resource id * @param string $resource_element Resource element @@ -3288,7 +3289,7 @@ abstract class CommonObject function add_element_resource($resource_id,$resource_element,$busy=0,$mandatory=0) { $this->db->begin(); - + $sql = "INSERT INTO ".MAIN_DB_PREFIX."element_resources ("; $sql.= "resource_id"; $sql.= ", resource_type"; @@ -3304,7 +3305,7 @@ abstract class CommonObject $sql.= ", '".$busy."'"; $sql.= ", '".$mandatory."'"; $sql.= ")"; - + dol_syslog(get_class($this)."::add_element_resource sql=".$sql, LOG_DEBUG); if ($this->db->query($sql)) { @@ -3318,8 +3319,8 @@ abstract class CommonObject return 0; } } - - + + /** * Overwrite magic function to solve problem of cloning object that are kept as references * diff --git a/htdocs/core/tpl/resource_add.tpl.php b/htdocs/core/tpl/resource_add.tpl.php index fe4d0cdf94d..f9cd20b5dc3 100644 --- a/htdocs/core/tpl/resource_add.tpl.php +++ b/htdocs/core/tpl/resource_add.tpl.php @@ -1,6 +1,45 @@ '.$langs->trans('NotAvailableYet').''; -print '
'; +//$langs->load($resource_type); + +$form = new Form($db); +if(!class_exists('FormResource')) + require_once(DOL_DOCUMENT_ROOT.'/resource/class/html.formresource.class.php'); +$formresources = new FormResource($db); + +$out .= '
'; + +$out .= '
'; +$out .= ''; +$out .= ''; +$out .= ''; +$out .= ''; +$out .= ''; + + +// Place +$out .= '
'.$langs->trans("SelectResource").'
'; +$events=array(); +$out .= $formresources->select_resource_list('','fk_resource','',1,1,0,$events,'',2); +$out .= '
'; + +$out .= '
'.$form->selectyesno('busy',$linked_resource['busy']?1:0,1).'
'; +$out .= '
'.$form->selectyesno('mandatory',$linked_resource['mandatory']?1:0,1).'
'; + +$out .= '
'; +$out .='trans("Cancel").'" />'; +$out .= '
'; + +$out .='
'; + +$out .= '
'; +$out .= '
'; + +print $out; + + + // FIN DU TPL diff --git a/htdocs/core/tpl/resource_view.tpl.php b/htdocs/core/tpl/resource_view.tpl.php index dccc59a069c..6f4d80ed84f 100644 --- a/htdocs/core/tpl/resource_view.tpl.php +++ b/htdocs/core/tpl/resource_view.tpl.php @@ -42,13 +42,10 @@ if( (array) $linked_resources && count($linked_resources) > 0) foreach ($linked_resources as $linked_resource) { $var=!$var; - $object_resource = $object->fetchObjectByElement($linked_resource['resource_id'],$linked_resource['resource_type']); - + $object_resource = fetchObjectByElement($linked_resource['resource_id'],$linked_resource['resource_type']); if($mode == 'edit' && $linked_resource['rowid'] == GETPOST('lineid')) { - /*print '
action="" method="POST">';*/ - print ''; print ''; print ''; @@ -56,7 +53,7 @@ if( (array) $linked_resources && count($linked_resources) > 0) print ''; print ''; - print '
'; + print '
'.$object_resource->type_label.'
'; print '
'.$object_resource->getNomUrl(1).'
'; print '
'.$form->selectyesno('busy',$linked_resource['busy']?1:0,1).'
'; print '
'.$form->selectyesno('mandatory',$linked_resource['mandatory']?1:0,1).'
'; @@ -73,7 +70,7 @@ if( (array) $linked_resources && count($linked_resources) > 0) print '
'; print '
'; - print $langs->trans(ucfirst($object_resource->element)); + print $object_resource->type_label; print '
'; print '
'; diff --git a/htdocs/resource/class/actions_resource.class.php b/htdocs/resource/class/actions_resource.class.php index 9e1f9b44f80..f41504e829d 100644 --- a/htdocs/resource/class/actions_resource.class.php +++ b/htdocs/resource/class/actions_resource.class.php @@ -22,7 +22,7 @@ /** * Actions class file for resources - * + * */ class ActionsResource { @@ -43,18 +43,49 @@ class ActionsResource /** * doActions for resource module - * + * * @param array $parameters parameters * @param Object $object object * @param string $action action */ - function doActions($parameters, &$object, &$action) + function doActions($parameters, &$object, &$action) { global $langs,$user; $langs->load('resource'); - + 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_resource' && $user->rights->resource->delete && GETPOST('confirm') == 'yes') { diff --git a/htdocs/resource/class/html.formresource.class.php b/htdocs/resource/class/html.formresource.class.php index 11a51340971..cdeb11950eb 100644 --- a/htdocs/resource/class/html.formresource.class.php +++ b/htdocs/resource/class/html.formresource.class.php @@ -53,7 +53,7 @@ class FormResource /** - * Output html form to select a location (place) + * Output html form to select a resource * * @param string $selected Preselected type * @param string $htmlname Name of field in form @@ -63,7 +63,7 @@ class FormResource * @param int $forcecombo Force to use combo box * @param array $event Event options. Example: array(array('method'=>'getContacts', 'url'=>dol_buildpath('/core/ajax/contacts.php',1), 'htmlname'=>'contactid', 'params'=>array('add-customer-contact'=>'disabled'))) * @param string $filterkey Filter on key value - * @param int $outputmode 0=HTML select string, 1=Array + * @param int $outputmode 0=HTML select string, 1=Array, 2=without form tag * @param int $limit Limit number of answers * @return string HTML string with */ @@ -76,10 +76,13 @@ class FormResource $resourcestat = new Resource($this->db); - $resources_used = $resourcestat->fetch_all_used('ASC', 't.rowid', $limit, $offset, $filter=''); + $resources_used = $resourcestat->fetch_all('ASC', 't.rowid', $limit, $offset, $filter=''); - $out = ''; - $out.= ''; + if ($outputmode != 2) + { + $out = ''; + $out.= ''; + } //$out.= ''; //$out.= ''; @@ -122,20 +125,23 @@ class FormResource } $out.= ''."\n"; + if ($outputmode != 2) + { - $out.= '     '; + $out.= '     '; - $out.= ''; + $out.= ''; + } } else { dol_print_error($this->db); } - if ($outputmode) return $outarray; + if ($outputmode && $outputmode != 2) return $outarray; return $out; } - + /** * Return html list of tickets type * @@ -151,15 +157,15 @@ class FormResource function select_types_resource($selected='',$htmlname='type_resource',$filtertype='',$format=0, $empty=0, $noadmininfo=0,$maxlength=0) { global $langs,$user; - + $resourcestat = new Resource($this->db); - + dol_syslog(get_class($this)."::select_types_resource ".$selected.", ".$htmlname.", ".$filtertype.", ".$format,LOG_DEBUG); - + $filterarray=array(); - + if ($filtertype != '' && $filtertype != '-1') $filterarray=explode(',',$filtertype); - + $resourcestat->load_cache_code_type_resource(); print '