New : link resource with any element
With tpl system, external modules can declare resource with hook getElementResources
This commit is contained in:
parent
8f3940aab6
commit
225c7ae07b
@ -3279,7 +3279,8 @@ abstract class CommonObject
|
|||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 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 int $resource_id Resource id
|
||||||
* @param string $resource_element Resource element
|
* @param string $resource_element Resource element
|
||||||
|
|||||||
@ -1,6 +1,45 @@
|
|||||||
<?php
|
<?php
|
||||||
|
|
||||||
|
|
||||||
print '<div class="error">'.$langs->trans('NotAvailableYet').'</div>';
|
//$langs->load($resource_type);
|
||||||
print '<br />';
|
|
||||||
|
$form = new Form($db);
|
||||||
|
if(!class_exists('FormResource'))
|
||||||
|
require_once(DOL_DOCUMENT_ROOT.'/resource/class/html.formresource.class.php');
|
||||||
|
$formresources = new FormResource($db);
|
||||||
|
|
||||||
|
$out .= '<div class="tagtable centpercent border allwidth">';
|
||||||
|
|
||||||
|
$out .= '<form class="tagtr '.($var==true?'pair':'impair').'" action="'.$_SERVER["PHP_SELF"].'" method="POST">';
|
||||||
|
$out .= '<input type="hidden" name="token" value="'.$_SESSION['newtoken'].'">';
|
||||||
|
$out .= '<input type="hidden" name="action" value="add_element_resource">';
|
||||||
|
$out .= '<input type="hidden" name="element" value="'.$element.'">';
|
||||||
|
$out .= '<input type="hidden" name="element_id" value="'.$element_id.'">';
|
||||||
|
$out .= '<input type="hidden" name="resource_type" value="'.$resource_type.'">';
|
||||||
|
|
||||||
|
|
||||||
|
// Place
|
||||||
|
$out .= '<div class="tagtd">'.$langs->trans("SelectResource").'</div><div>';
|
||||||
|
$events=array();
|
||||||
|
$out .= $formresources->select_resource_list('','fk_resource','',1,1,0,$events,'',2);
|
||||||
|
$out .= '</div>';
|
||||||
|
|
||||||
|
$out .= '<div class="tagtd"><label>'.$langs->trans('Busy').'</label> '.$form->selectyesno('busy',$linked_resource['busy']?1:0,1).'</div>';
|
||||||
|
$out .= '<div class="tagtd"><label>'.$langs->trans('Mandatory').'</label> '.$form->selectyesno('mandatory',$linked_resource['mandatory']?1:0,1).'</div>';
|
||||||
|
|
||||||
|
$out .= '<div class="tagtd">';
|
||||||
|
$out .='<input type="submit" id="add-resource-place" class="button" value="'.$langs->trans("Add").'"';
|
||||||
|
$out .=' />';
|
||||||
|
$out .='<input type="submit" name="cancel" class="button" value="'.$langs->trans("Cancel").'" />';
|
||||||
|
$out .= '</div>';
|
||||||
|
|
||||||
|
$out .='</form>';
|
||||||
|
|
||||||
|
$out .= '</div>';
|
||||||
|
$out .= '<br />';
|
||||||
|
|
||||||
|
print $out;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
// FIN DU TPL
|
// FIN DU TPL
|
||||||
|
|||||||
@ -42,13 +42,10 @@ if( (array) $linked_resources && count($linked_resources) > 0)
|
|||||||
foreach ($linked_resources as $linked_resource)
|
foreach ($linked_resources as $linked_resource)
|
||||||
{
|
{
|
||||||
$var=!$var;
|
$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'))
|
if($mode == 'edit' && $linked_resource['rowid'] == GETPOST('lineid'))
|
||||||
{
|
{
|
||||||
|
|
||||||
/*print '<form $bc[$var]; ?> action="<?php echo $_SERVER["PHP_SELF"].'?element='.$element.'&element_id='.$element_id; ?>" method="POST">';*/
|
|
||||||
|
|
||||||
print '<form class="tagtr '.($var==true?'pair':'impair').'" action="'.$_SERVER["PHP_SELF"].'?element='.$element.'&element_id='.$element_id.'" method="POST">';
|
print '<form class="tagtr '.($var==true?'pair':'impair').'" action="'.$_SERVER["PHP_SELF"].'?element='.$element.'&element_id='.$element_id.'" method="POST">';
|
||||||
print '<input type="hidden" name="token" value="'.$_SESSION['newtoken'].'" />';
|
print '<input type="hidden" name="token" value="'.$_SESSION['newtoken'].'" />';
|
||||||
print '<input type="hidden" name="id" value="'.$object->id.'" />';
|
print '<input type="hidden" name="id" value="'.$object->id.'" />';
|
||||||
@ -56,7 +53,7 @@ if( (array) $linked_resources && count($linked_resources) > 0)
|
|||||||
print '<input type="hidden" name="resource_type" value="'.$resource_type.'" />';
|
print '<input type="hidden" name="resource_type" value="'.$resource_type.'" />';
|
||||||
print '<input type="hidden" name="lineid" value="'.$linked_resource['rowid'].'" />';
|
print '<input type="hidden" name="lineid" value="'.$linked_resource['rowid'].'" />';
|
||||||
|
|
||||||
print '<div class="tagtd"></div>';
|
print '<div class="tagtd">'.$object_resource->type_label.'</div>';
|
||||||
print '<div class="tagtd">'.$object_resource->getNomUrl(1).'</div>';
|
print '<div class="tagtd">'.$object_resource->getNomUrl(1).'</div>';
|
||||||
print '<div class="tagtd">'.$form->selectyesno('busy',$linked_resource['busy']?1:0,1).'</div>';
|
print '<div class="tagtd">'.$form->selectyesno('busy',$linked_resource['busy']?1:0,1).'</div>';
|
||||||
print '<div class="tagtd">'.$form->selectyesno('mandatory',$linked_resource['mandatory']?1:0,1).'</div>';
|
print '<div class="tagtd">'.$form->selectyesno('mandatory',$linked_resource['mandatory']?1:0,1).'</div>';
|
||||||
@ -73,7 +70,7 @@ if( (array) $linked_resources && count($linked_resources) > 0)
|
|||||||
print '<div class="tagtr '.($var==true?"pair":"impair").'" '.$style.'>';
|
print '<div class="tagtr '.($var==true?"pair":"impair").'" '.$style.'>';
|
||||||
|
|
||||||
print '<div class="tagtd">';
|
print '<div class="tagtd">';
|
||||||
print $langs->trans(ucfirst($object_resource->element));
|
print $object_resource->type_label;
|
||||||
print '</div>';
|
print '</div>';
|
||||||
|
|
||||||
print '<div class="tagtd">';
|
print '<div class="tagtd">';
|
||||||
|
|||||||
@ -55,6 +55,37 @@ class ActionsResource
|
|||||||
|
|
||||||
if (in_array('element_resource',explode(':',$parameters['context'])))
|
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
|
// Delete a resource linked to an element
|
||||||
if ($action == 'confirm_delete_resource' && $user->rights->resource->delete && GETPOST('confirm') == 'yes')
|
if ($action == 'confirm_delete_resource' && $user->rights->resource->delete && GETPOST('confirm') == 'yes')
|
||||||
{
|
{
|
||||||
|
|||||||
@ -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 $selected Preselected type
|
||||||
* @param string $htmlname Name of field in form
|
* @param string $htmlname Name of field in form
|
||||||
@ -63,7 +63,7 @@ class FormResource
|
|||||||
* @param int $forcecombo Force to use combo box
|
* @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 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 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
|
* @param int $limit Limit number of answers
|
||||||
* @return string HTML string with
|
* @return string HTML string with
|
||||||
*/
|
*/
|
||||||
@ -76,10 +76,13 @@ class FormResource
|
|||||||
|
|
||||||
$resourcestat = new Resource($this->db);
|
$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 = '<form action="'.$_SERVER["PHP_SELF"].'" method="POST">';
|
if ($outputmode != 2)
|
||||||
$out.= '<input type="hidden" name="token" value="'.$_SESSION['newtoken'].'">';
|
{
|
||||||
|
$out = '<form action="'.$_SERVER["PHP_SELF"].'" method="POST">';
|
||||||
|
$out.= '<input type="hidden" name="token" value="'.$_SESSION['newtoken'].'">';
|
||||||
|
}
|
||||||
//$out.= '<input type="hidden" name="action" value="search">';
|
//$out.= '<input type="hidden" name="action" value="search">';
|
||||||
//$out.= '<input type="hidden" name="id" value="'.$theme->id.'">';
|
//$out.= '<input type="hidden" name="id" value="'.$theme->id.'">';
|
||||||
|
|
||||||
@ -122,17 +125,20 @@ class FormResource
|
|||||||
}
|
}
|
||||||
$out.= '</select>'."\n";
|
$out.= '</select>'."\n";
|
||||||
|
|
||||||
|
if ($outputmode != 2)
|
||||||
|
{
|
||||||
|
|
||||||
$out.= '<input type="submit" class="button" value="'.$langs->trans("Search").'"> ';
|
$out.= '<input type="submit" class="button" value="'.$langs->trans("Search").'"> ';
|
||||||
|
|
||||||
$out.= '</form>';
|
$out.= '</form>';
|
||||||
|
}
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
dol_print_error($this->db);
|
dol_print_error($this->db);
|
||||||
}
|
}
|
||||||
|
|
||||||
if ($outputmode) return $outarray;
|
if ($outputmode && $outputmode != 2) return $outarray;
|
||||||
return $out;
|
return $out;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -559,6 +559,8 @@ class Resource extends CommonObject
|
|||||||
* Fetch all resources available, declared by modules
|
* Fetch all resources available, declared by modules
|
||||||
* Load available resource in array $this->available_resources
|
* Load available resource in array $this->available_resources
|
||||||
*
|
*
|
||||||
|
* note : deprecated, remplaced by hook getElementResources
|
||||||
|
*
|
||||||
* @return int number of available resources declared by modules
|
* @return int number of available resources declared by modules
|
||||||
*/
|
*/
|
||||||
function fetch_all_available() {
|
function fetch_all_available() {
|
||||||
@ -725,7 +727,7 @@ class Resource extends CommonObject
|
|||||||
// Links beetween objects are stored in this table
|
// Links beetween objects are stored in this table
|
||||||
$sql = 'SELECT rowid, resource_id, resource_type, busy, mandatory';
|
$sql = 'SELECT rowid, resource_id, resource_type, busy, mandatory';
|
||||||
$sql.= ' FROM '.MAIN_DB_PREFIX.'element_resources';
|
$sql.= ' FROM '.MAIN_DB_PREFIX.'element_resources';
|
||||||
$sql.= " WHERE element_id='".$element_id."' AND element_type='".$element."'";
|
$sql.= " WHERE element_id='".$element_id."' AND resource_type='".$this->element."'";
|
||||||
if($resource_type)
|
if($resource_type)
|
||||||
$sql.=" AND resource_type LIKE '%".$resource_type."%'";
|
$sql.=" AND resource_type LIKE '%".$resource_type."%'";
|
||||||
$sql .= ' ORDER BY resource_type';
|
$sql .= ' ORDER BY resource_type';
|
||||||
@ -850,5 +852,36 @@ class Resource extends CommonObject
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Return clicable link of object (with eventually picto)
|
||||||
|
*
|
||||||
|
* @param int $withpicto Add picto into link
|
||||||
|
* @param string $option Where point the link ('compta', 'expedition', 'document', ...)
|
||||||
|
* @param string $get_params Parametres added to url
|
||||||
|
* @return string String with URL
|
||||||
|
*/
|
||||||
|
function getNomUrl($withpicto=0,$option='', $get_params='')
|
||||||
|
{
|
||||||
|
global $langs;
|
||||||
|
|
||||||
|
$result='';
|
||||||
|
|
||||||
|
if ($option == '')
|
||||||
|
{
|
||||||
|
$lien = '<a href="'.dol_buildpath('/resource/card.php',1).'?id='.$this->id. $get_params .'">';
|
||||||
|
$picto='resource@resource';
|
||||||
|
$label=$langs->trans("ShowResource").': '.$this->ref;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
$lienfin='</a>';
|
||||||
|
|
||||||
|
$label=$langs->trans("ShowResource").': '.$this->ref;
|
||||||
|
|
||||||
|
if ($withpicto) $result.=($lien.img_object($label,$picto).$lienfin);
|
||||||
|
if ($withpicto && $withpicto != 2) $result.=' ';
|
||||||
|
$result.=$lien.$this->ref.$lienfin;
|
||||||
|
return $result;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
?>
|
?>
|
||||||
|
|||||||
@ -58,9 +58,14 @@ $object=new Resource($db);
|
|||||||
|
|
||||||
$hookmanager->initHooks(array('element_resource'));
|
$hookmanager->initHooks(array('element_resource'));
|
||||||
|
|
||||||
$parameters=array('resource_id'=>$resource_id);
|
|
||||||
|
$object->available_resources = array('resource','place@place');
|
||||||
|
|
||||||
|
$parameters=array('resource_id'=>$available_resources);
|
||||||
$reshook=$hookmanager->executeHooks('doActions',$parameters,$object,$action); // Note that $action and $object may have been modified by some hooks
|
$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
|
||||||
|
|
||||||
|
|
||||||
/***************************************************
|
/***************************************************
|
||||||
@ -77,7 +82,7 @@ $form=new Form($db);
|
|||||||
|
|
||||||
|
|
||||||
// Load available resource, declared by modules
|
// Load available resource, declared by modules
|
||||||
$ret = $object->fetch_all("ASC",'rowid',0);
|
$ret = count($object->available_resources);
|
||||||
if($ret == -1) {
|
if($ret == -1) {
|
||||||
dol_print_error($db,$object->error);
|
dol_print_error($db,$object->error);
|
||||||
exit;
|
exit;
|
||||||
@ -168,15 +173,13 @@ else
|
|||||||
|
|
||||||
foreach ($object->available_resources as $modresources => $resources)
|
foreach ($object->available_resources as $modresources => $resources)
|
||||||
{
|
{
|
||||||
$langs->load($modresources);
|
$langs->load($resources);
|
||||||
//print '<h2>'.$modresources.'</h2>';
|
//print '<h2>'.$modresources.'</h2>';
|
||||||
//var_dump($resources);
|
|
||||||
|
|
||||||
$resources=(array) $resources; // To be sure $resources is an array
|
$resources=(array) $resources; // To be sure $resources is an array
|
||||||
foreach($resources as $resource_obj)
|
foreach($resources as $resource_obj)
|
||||||
{
|
{
|
||||||
$element_prop = getElementProperties($resource_obj);
|
$element_prop = getElementProperties($resource_obj);
|
||||||
//var_dump($element_prop);
|
|
||||||
|
|
||||||
print_titre($langs->trans(ucfirst($element_prop['element']).'Singular'));
|
print_titre($langs->trans(ucfirst($element_prop['element']).'Singular'));
|
||||||
|
|
||||||
@ -190,20 +193,14 @@ else
|
|||||||
|
|
||||||
if ( $mode == 'add' && $resource_obj == $resource_type)
|
if ( $mode == 'add' && $resource_obj == $resource_type)
|
||||||
{
|
{
|
||||||
//print '/'.$element_prop['module'].'/core/tpl/resource_'.$element_prop['element'].'_'.$mode.'.tpl.php'.'<BR>';
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
// If we have a specific template we use it
|
// If we have a specific template we use it
|
||||||
if(file_exists(dol_buildpath($path.'/core/tpl/resource_'.$element_prop['element'].'_'.$mode.'.tpl.php')))
|
if(file_exists(dol_buildpath($path.'/core/tpl/resource_'.$element_prop['element'].'_'.$mode.'.tpl.php')))
|
||||||
{
|
{
|
||||||
$res=include dol_buildpath($path.'/core/tpl/resource_'.$element_prop['element'].'_'.$mode.'.tpl.php');
|
$res=include dol_buildpath($path.'/core/tpl/resource_'.$element_prop['element'].'_'.$mode.'.tpl.php');
|
||||||
|
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
$res=@include dol_buildpath('/resource/core/tpl/resource_add.tpl.php');
|
$res=include DOL_DOCUMENT_ROOT . '/core/tpl/resource_add.tpl.php';
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
@ -218,8 +215,7 @@ else
|
|||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
$res=include dol_buildpath('/resource/core/tpl/resource_view.tpl.php');
|
$res=include DOL_DOCUMENT_ROOT . '/core/tpl/resource_view.tpl.php';
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user