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
@ -3277,9 +3277,10 @@ abstract class CommonObject
|
||||
print '</table>';
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* 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
|
||||
*
|
||||
|
||||
@ -1,6 +1,45 @@
|
||||
<?php
|
||||
|
||||
|
||||
print '<div class="error">'.$langs->trans('NotAvailableYet').'</div>';
|
||||
print '<br />';
|
||||
//$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 .= '<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
|
||||
|
||||
@ -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 '<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 '<input type="hidden" name="token" value="'.$_SESSION['newtoken'].'" />';
|
||||
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="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">'.$form->selectyesno('busy',$linked_resource['busy']?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="tagtd">';
|
||||
print $langs->trans(ucfirst($object_resource->element));
|
||||
print $object_resource->type_label;
|
||||
print '</div>';
|
||||
|
||||
print '<div class="tagtd">';
|
||||
|
||||
@ -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')
|
||||
{
|
||||
|
||||
@ -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 = '<form action="'.$_SERVER["PHP_SELF"].'" method="POST">';
|
||||
$out.= '<input type="hidden" name="token" value="'.$_SESSION['newtoken'].'">';
|
||||
if ($outputmode != 2)
|
||||
{
|
||||
$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="id" value="'.$theme->id.'">';
|
||||
|
||||
@ -122,20 +125,23 @@ class FormResource
|
||||
}
|
||||
$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
|
||||
{
|
||||
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 '<select id="select'.$htmlname.'" class="flat select_'.$htmlname.'" name="'.$htmlname.'">';
|
||||
if ($empty) print '<option value=""> </option>';
|
||||
@ -167,10 +173,10 @@ class FormResource
|
||||
{
|
||||
foreach($resourcestat->cache_code_type_resource as $id => $arraytypes)
|
||||
{
|
||||
|
||||
|
||||
// We discard empty line if showempty is on because an empty line has already been output.
|
||||
if ($empty && empty($arraytypes['code'])) continue;
|
||||
|
||||
|
||||
if ($format == 0) print '<option value="'.$id.'"';
|
||||
if ($format == 1) print '<option value="'.$arraytypes['code'].'"';
|
||||
if ($format == 2) print '<option value="'.$arraytypes['code'].'"';
|
||||
@ -190,7 +196,7 @@ class FormResource
|
||||
print '</select>';
|
||||
if ($user->admin && ! $noadmininfo) print info_admin($langs->trans("YouCanChangeValuesForThisListFromDictionarySetup"),1);
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
@ -39,7 +39,7 @@ class Resource extends CommonObject
|
||||
|
||||
var $id;
|
||||
|
||||
|
||||
|
||||
var $resource_id;
|
||||
var $resource_type;
|
||||
var $element_id;
|
||||
@ -73,28 +73,28 @@ class Resource extends CommonObject
|
||||
{
|
||||
global $conf, $langs;
|
||||
$error=0;
|
||||
|
||||
|
||||
// Clean parameters
|
||||
|
||||
|
||||
if (isset($this->ref)) $this->ref=trim($this->ref);
|
||||
if (isset($this->description)) $this->description=trim($this->description);
|
||||
if (isset($this->fk_code_type_resource)) $this->fk_code_type_resource=trim($this->fk_code_type_resource);
|
||||
if (isset($this->note_public)) $this->note_public=trim($this->note_public);
|
||||
if (isset($this->note_private)) $this->note_private=trim($this->note_private);
|
||||
|
||||
|
||||
|
||||
|
||||
// Insert request
|
||||
$sql = "INSERT INTO ".MAIN_DB_PREFIX."resource(";
|
||||
|
||||
|
||||
$sql.= " entity,";
|
||||
$sql.= "ref,";
|
||||
$sql.= "description,";
|
||||
$sql.= "fk_code_type_resource,";
|
||||
$sql.= "note_public,";
|
||||
$sql.= "note_private";
|
||||
|
||||
|
||||
$sql.= ") VALUES (";
|
||||
|
||||
|
||||
$sql.= $conf->entity.", ";
|
||||
$sql.= " ".(! isset($this->ref)?'NULL':"'".$this->db->escape($this->ref)."'").",";
|
||||
$sql.= " ".(! isset($this->description)?'NULL':"'".$this->db->escape($this->description)."'").",";
|
||||
@ -103,21 +103,21 @@ class Resource extends CommonObject
|
||||
$sql.= " ".(! isset($this->note_private)?'NULL':"'".$this->db->escape($this->note_private)."'");
|
||||
|
||||
$sql.= ")";
|
||||
|
||||
|
||||
$this->db->begin();
|
||||
|
||||
|
||||
dol_syslog(get_class($this)."::create sql=".$sql, LOG_DEBUG);
|
||||
$resql=$this->db->query($sql);
|
||||
if (! $resql) {
|
||||
$error++; $this->errors[]="Error ".$this->db->lasterror();
|
||||
}
|
||||
|
||||
|
||||
if (! $error)
|
||||
{
|
||||
$this->id = $this->db->last_insert_id(MAIN_DB_PREFIX."place");
|
||||
|
||||
|
||||
if (! $notrigger)
|
||||
{
|
||||
{
|
||||
//// Call triggers
|
||||
//include_once DOL_DOCUMENT_ROOT . '/core/class/interfaces.class.php';
|
||||
//$interface=new Interfaces($this->db);
|
||||
@ -126,7 +126,7 @@ class Resource extends CommonObject
|
||||
//// End call triggers
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// Commit or rollback
|
||||
if ($error)
|
||||
{
|
||||
@ -144,7 +144,7 @@ class Resource extends CommonObject
|
||||
return $this->id;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Load object in memory from database
|
||||
*
|
||||
@ -167,7 +167,7 @@ class Resource extends CommonObject
|
||||
$sql.= " FROM ".MAIN_DB_PREFIX."resource 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);
|
||||
|
||||
|
||||
dol_syslog(get_class($this)."::fetch sql=".$sql, LOG_DEBUG);
|
||||
$resql=$this->db->query($sql);
|
||||
if ($resql)
|
||||
@ -175,19 +175,19 @@ class Resource extends CommonObject
|
||||
if ($this->db->num_rows($resql))
|
||||
{
|
||||
$obj = $this->db->fetch_object($resql);
|
||||
|
||||
|
||||
$this->id = $obj->rowid;
|
||||
$this->entity = $obj->entity;
|
||||
$this->ref = $obj->ref;
|
||||
$this->description = $obj->description;
|
||||
$this->fk_code_type_resource = $obj->fk_code_type_resource;
|
||||
$this->note_public = $obj->note_public;
|
||||
$this->note_private = $obj->note_private;
|
||||
$this->note_private = $obj->note_private;
|
||||
$this->type_label = $obj->type_label;
|
||||
|
||||
|
||||
}
|
||||
$this->db->free($resql);
|
||||
|
||||
|
||||
return $this->id;
|
||||
}
|
||||
else
|
||||
@ -197,7 +197,7 @@ class Resource extends CommonObject
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Update object into database
|
||||
*
|
||||
@ -209,12 +209,12 @@ class Resource extends CommonObject
|
||||
{
|
||||
global $conf, $langs;
|
||||
$error=0;
|
||||
|
||||
|
||||
// Clean parameters
|
||||
if (isset($this->ref)) $this->ref=trim($this->ref);
|
||||
if (isset($this->fk_code_type_resource)) $this->fk_code_type_resource=trim($this->fk_code_type_resource);
|
||||
if (isset($this->description)) $this->description=trim($this->description);
|
||||
|
||||
|
||||
// Update request
|
||||
$sql = "UPDATE ".MAIN_DB_PREFIX."resource SET";
|
||||
$sql.= " ref=".(isset($this->ref)?"'".$this->db->escape($this->ref)."'":"null").",";
|
||||
@ -222,20 +222,20 @@ class Resource extends CommonObject
|
||||
$sql.= " fk_code_type_resource=".(isset($this->fk_code_type_resource)?"'".$this->db->escape($this->fk_code_type_resource)."'":"null").",";
|
||||
$sql.= " tms=".(dol_strlen($this->tms)!=0 ? "'".$this->db->idate($this->tms)."'" : 'null')."";
|
||||
$sql.= " WHERE rowid=".$this->id;
|
||||
|
||||
|
||||
$this->db->begin();
|
||||
|
||||
|
||||
dol_syslog(get_class($this)."::update sql=".$sql, LOG_DEBUG);
|
||||
$resql = $this->db->query($sql);
|
||||
if (! $resql) { $error++; $this->errors[]="Error ".$this->db->lasterror(); }
|
||||
|
||||
|
||||
if (! $error)
|
||||
{
|
||||
if (! $notrigger)
|
||||
{
|
||||
// Uncomment this and change MYOBJECT to your own tag if you
|
||||
// want this action calls a trigger.
|
||||
|
||||
|
||||
//// Call triggers
|
||||
//include_once DOL_DOCUMENT_ROOT . '/core/class/interfaces.class.php';
|
||||
//$interface=new Interfaces($this->db);
|
||||
@ -244,7 +244,7 @@ class Resource extends CommonObject
|
||||
//// End call triggers
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// Commit or rollback
|
||||
if ($error)
|
||||
{
|
||||
@ -262,10 +262,10 @@ class Resource extends CommonObject
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Load object in memory from database
|
||||
*
|
||||
*
|
||||
* @param int $id id object
|
||||
* @return int <0 if KO, >0 if OK
|
||||
*/
|
||||
@ -319,7 +319,7 @@ class Resource extends CommonObject
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Load resource objects into $this->lines
|
||||
*
|
||||
@ -344,7 +344,7 @@ class Resource extends CommonObject
|
||||
$sql.= " FROM ".MAIN_DB_PREFIX."resource 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').")";
|
||||
|
||||
|
||||
//Manage filter
|
||||
if (!empty($filter)){
|
||||
foreach($filter as $key => $value) {
|
||||
@ -360,7 +360,7 @@ class Resource extends CommonObject
|
||||
$sql.= " ORDER BY $sortfield $sortorder ";
|
||||
if ($limit) $sql.= $this->db->plimit($limit+1,$offset);
|
||||
dol_syslog(get_class($this)."::fetch_all sql=".$sql, LOG_DEBUG);
|
||||
|
||||
|
||||
$resql=$this->db->query($sql);
|
||||
if ($resql)
|
||||
{
|
||||
@ -377,7 +377,7 @@ class Resource extends CommonObject
|
||||
$line->description = $obj->description;
|
||||
$line->fk_code_type_resource = $obj->fk_code_type_resource;
|
||||
$line->type_label = $obj->type_label;
|
||||
|
||||
|
||||
$this->lines[$i] = $line;
|
||||
$i++;
|
||||
}
|
||||
@ -390,7 +390,7 @@ class Resource extends CommonObject
|
||||
$this->error = $this->db->lasterror();
|
||||
return -1;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
@ -487,10 +487,10 @@ class Resource extends CommonObject
|
||||
function fetch_all_used($sortorder, $sortfield, $limit, $offset=1, $filter='')
|
||||
{
|
||||
global $conf;
|
||||
|
||||
|
||||
if ( ! $sortorder) $sortorder="ASC";
|
||||
if ( ! $sortfield) $sortfield="t.rowid";
|
||||
|
||||
|
||||
$sql="SELECT ";
|
||||
$sql.= " t.rowid,";
|
||||
$sql.= " t.resource_id,";
|
||||
@ -559,6 +559,8 @@ class Resource extends CommonObject
|
||||
* Fetch all resources available, declared by modules
|
||||
* Load available resource in array $this->available_resources
|
||||
*
|
||||
* note : deprecated, remplaced by hook getElementResources
|
||||
*
|
||||
* @return int number of available resources declared by modules
|
||||
*/
|
||||
function fetch_all_available() {
|
||||
@ -572,7 +574,7 @@ class Resource extends CommonObject
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Load properties id_previous and id_next
|
||||
*
|
||||
@ -583,18 +585,18 @@ class Resource extends CommonObject
|
||||
function load_previous_next_ref($filter,$fieldid)
|
||||
{
|
||||
global $conf, $user;
|
||||
|
||||
|
||||
if (! $this->table_element)
|
||||
{
|
||||
dol_print_error('',get_class($this)."::load_previous_next_ref was called on objet with property table_element not defined", LOG_ERR);
|
||||
return -1;
|
||||
}
|
||||
|
||||
|
||||
// this->ismultientitymanaged contains
|
||||
// 0=No test on entity, 1=Test with field entity, 2=Test with link by societe
|
||||
$alias = 's';
|
||||
|
||||
|
||||
|
||||
|
||||
$sql = "SELECT MAX(te.".$fieldid.")";
|
||||
$sql.= " FROM ".MAIN_DB_PREFIX.$this->table_element." as te";
|
||||
if (isset($this->ismultientitymanaged) && $this->ismultientitymanaged == 2 || ($this->element != 'societe' && empty($this->isnolinkedbythird) && empty($user->rights->societe->client->voir))) $sql.= ", ".MAIN_DB_PREFIX."societe as s"; // If we need to link to societe to limit select to entity
|
||||
@ -604,7 +606,7 @@ class Resource extends CommonObject
|
||||
if (! empty($filter)) $sql.=" AND ".$filter;
|
||||
if (isset($this->ismultientitymanaged) && $this->ismultientitymanaged == 2 || ($this->element != 'societe' && empty($this->isnolinkedbythird) && !$user->rights->societe->client->voir)) $sql.= ' AND te.fk_soc = s.rowid'; // If we need to link to societe to limit select to entity
|
||||
if (isset($this->ismultientitymanaged) && $this->ismultientitymanaged == 1) $sql.= ' AND te.entity IN ('.getEntity($this->element, 1).')';
|
||||
|
||||
|
||||
//print $sql."<br>";
|
||||
$result = $this->db->query($sql);
|
||||
if (! $result)
|
||||
@ -614,8 +616,8 @@ class Resource extends CommonObject
|
||||
}
|
||||
$row = $this->db->fetch_row($result);
|
||||
$this->ref_previous = $row[0];
|
||||
|
||||
|
||||
|
||||
|
||||
$sql = "SELECT MIN(te.".$fieldid.")";
|
||||
$sql.= " FROM ".MAIN_DB_PREFIX.$this->table_element." as te";
|
||||
if (isset($this->ismultientitymanaged) && $this->ismultientitymanaged == 2 || ($this->element != 'societe' && empty($this->isnolinkedbythird) && !$user->rights->societe->client->voir)) $sql.= ", ".MAIN_DB_PREFIX."societe as s"; // If we need to link to societe to limit select to entity
|
||||
@ -626,7 +628,7 @@ class Resource extends CommonObject
|
||||
if (isset($this->ismultientitymanaged) && $this->ismultientitymanaged == 2 || ($this->element != 'societe' && empty($this->isnolinkedbythird) && !$user->rights->societe->client->voir)) $sql.= ' AND te.fk_soc = s.rowid'; // If we need to link to societe to limit select to entity
|
||||
if (isset($this->ismultientitymanaged) && $this->ismultientitymanaged == 1) $sql.= ' AND te.entity IN ('.getEntity($this->element, 1).')';
|
||||
// Rem: Bug in some mysql version: SELECT MIN(rowid) FROM llx_socpeople WHERE rowid > 1 when one row in database with rowid=1, returns 1 instead of null
|
||||
|
||||
|
||||
//print $sql."<br>";
|
||||
$result = $this->db->query($sql);
|
||||
if (! $result)
|
||||
@ -636,7 +638,7 @@ class Resource extends CommonObject
|
||||
}
|
||||
$row = $this->db->fetch_row($result);
|
||||
$this->ref_next = $row[0];
|
||||
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
@ -670,7 +672,7 @@ class Resource extends CommonObject
|
||||
$sql.= " busy=".(isset($this->busy)?$this->busy:"null").",";
|
||||
$sql.= " mandatory=".(isset($this->mandatory)?$this->mandatory:"null").",";
|
||||
$sql.= " tms=".(dol_strlen($this->tms)!=0 ? "'".$this->db->idate($this->tms)."'" : 'null')."";
|
||||
|
||||
|
||||
$sql.= " WHERE rowid=".$this->id;
|
||||
|
||||
$this->db->begin();
|
||||
@ -725,7 +727,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 element_type='".$element."'";
|
||||
$sql.= " WHERE element_id='".$element_id."' AND resource_type='".$this->element."'";
|
||||
if($resource_type)
|
||||
$sql.=" AND resource_type LIKE '%".$resource_type."%'";
|
||||
$sql .= ' ORDER BY resource_type';
|
||||
@ -809,7 +811,7 @@ class Resource extends CommonObject
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Load in cache resource type code (setup in dictionary)
|
||||
*
|
||||
@ -818,9 +820,9 @@ class Resource extends CommonObject
|
||||
function load_cache_code_type_resource()
|
||||
{
|
||||
global $langs;
|
||||
|
||||
|
||||
if (count($this->cache_code_type_resource)) return 0; // Cache deja charge
|
||||
|
||||
|
||||
$sql = "SELECT rowid, code, label, active";
|
||||
$sql.= " FROM ".MAIN_DB_PREFIX."c_type_resource";
|
||||
$sql.= " WHERE active > 0";
|
||||
@ -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'));
|
||||
|
||||
$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
|
||||
|
||||
$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
|
||||
$ret = $object->fetch_all("ASC",'rowid',0);
|
||||
$ret = count($object->available_resources);
|
||||
if($ret == -1) {
|
||||
dol_print_error($db,$object->error);
|
||||
exit;
|
||||
@ -163,20 +168,18 @@ else
|
||||
|
||||
|
||||
print_fiche_titre($langs->trans('ResourcesLinkedToElement'),'','resource.png@resource');
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
foreach ($object->available_resources as $modresources => $resources)
|
||||
{
|
||||
$langs->load($modresources);
|
||||
$langs->load($resources);
|
||||
//print '<h2>'.$modresources.'</h2>';
|
||||
//var_dump($resources);
|
||||
|
||||
$resources=(array) $resources; // To be sure $resources is an array
|
||||
foreach($resources as $resource_obj)
|
||||
{
|
||||
$element_prop = getElementProperties($resource_obj);
|
||||
//var_dump($element_prop);
|
||||
|
||||
print_titre($langs->trans(ucfirst($element_prop['element']).'Singular'));
|
||||
|
||||
@ -190,20 +193,14 @@ else
|
||||
|
||||
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(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');
|
||||
|
||||
}
|
||||
else
|
||||
{
|
||||
$res=@include dol_buildpath('/resource/core/tpl/resource_add.tpl.php');
|
||||
|
||||
$res=include DOL_DOCUMENT_ROOT . '/core/tpl/resource_add.tpl.php';
|
||||
}
|
||||
}
|
||||
else
|
||||
@ -218,8 +215,7 @@ 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