Fix several problem with hook printFieldListWhere

This commit is contained in:
Laurent Destailleur 2017-06-09 10:12:01 +02:00
parent d6ba16d357
commit 929946ad47
4 changed files with 48 additions and 35 deletions

View File

@ -1284,7 +1284,7 @@ abstract class CommonObject
/** /**
* Load properties id_previous and id_next * Load properties id_previous and id_next
* *
* @param string $filter Optional filter * @param string $filter Optional filter. Example: " AND (t.field1 = 'aa' OR t.field2 = 'bb')"
* @param int $fieldid Name of field to use for the select MAX and MIN * @param int $fieldid Name of field to use for the select MAX and MIN
* @param int $nodbprefix Do not include DB prefix to forge table name * @param int $nodbprefix Do not include DB prefix to forge table name
* @return int <0 if KO, >0 if OK * @return int <0 if KO, >0 if OK
@ -1310,11 +1310,15 @@ abstract class CommonObject
if (empty($this->isnolinkedbythird) && !$user->rights->societe->client->voir) $sql.= " LEFT JOIN ".MAIN_DB_PREFIX."societe_commerciaux as sc ON ".$alias.".rowid = sc.fk_soc"; if (empty($this->isnolinkedbythird) && !$user->rights->societe->client->voir) $sql.= " LEFT JOIN ".MAIN_DB_PREFIX."societe_commerciaux as sc ON ".$alias.".rowid = sc.fk_soc";
$sql.= " WHERE te.".$fieldid." < '".$this->db->escape($this->ref)."'"; // ->ref must always be defined (set to id if field does not exists) $sql.= " WHERE te.".$fieldid." < '".$this->db->escape($this->ref)."'"; // ->ref must always be defined (set to id if field does not exists)
if (empty($this->isnolinkedbythird) && !$user->rights->societe->client->voir) $sql.= " AND sc.fk_user = " .$user->id; if (empty($this->isnolinkedbythird) && !$user->rights->societe->client->voir) $sql.= " AND sc.fk_user = " .$user->id;
if (! empty($filter)) $sql.=" AND ".$filter; if (! empty($filter))
{
if (! preg_match('/^\s*AND/i', $filter)) $sql.=" AND "; // For backward compatibility
$sql.=$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 == 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).')'; if (isset($this->ismultientitymanaged) && $this->ismultientitymanaged == 1) $sql.= ' AND te.entity IN ('.getEntity($this->element, 1).')';
//print $sql."<br>"; //print $filter.' '.$sql."<br>";
$result = $this->db->query($sql); $result = $this->db->query($sql);
if (! $result) if (! $result)
{ {

View File

@ -121,7 +121,7 @@ class HookManager
* All types can also return some values into an array ->results that will be finaly merged into this->resArray for caller. * All types can also return some values into an array ->results that will be finaly merged into this->resArray for caller.
* $this->error or this->errors are also defined by class called by this function if error. * $this->error or this->errors are also defined by class called by this function if error.
*/ */
function executeHooks($method, $parameters=false, &$object='', &$action='') function executeHooks($method, $parameters=array(), &$object='', &$action='')
{ {
if (! is_array($this->hooks) || empty($this->hooks)) return ''; if (! is_array($this->hooks) || empty($this->hooks)) return '';
@ -229,7 +229,7 @@ class HookManager
// Generic hooks that return a string or array (printLeftBlock, formAddObjectLine, formBuilddocOptions, ...) // Generic hooks that return a string or array (printLeftBlock, formAddObjectLine, formBuilddocOptions, ...)
else else
{ {
// TODO. this should be done into the method of hook by returning nothing // TODO. this test should be done into the method of hook by returning nothing
if (is_array($parameters) && ! empty($parameters['special_code']) && $parameters['special_code'] > 3 && $parameters['special_code'] != $actionclassinstance->module_number) continue; if (is_array($parameters) && ! empty($parameters['special_code']) && $parameters['special_code'] > 3 && $parameters['special_code'] != $actionclassinstance->module_number) continue;
//dol_syslog("Call method ".$method." of class ".get_class($actionclassinstance).", module=".$module.", hooktype=".$hooktype, LOG_DEBUG); //dol_syslog("Call method ".$method." of class ".get_class($actionclassinstance).", module=".$module.", hooktype=".$hooktype, LOG_DEBUG);
@ -237,7 +237,7 @@ class HookManager
if (! empty($actionclassinstance->results) && is_array($actionclassinstance->results)) $this->resArray =array_merge($this->resArray, $actionclassinstance->results); if (! empty($actionclassinstance->results) && is_array($actionclassinstance->results)) $this->resArray =array_merge($this->resArray, $actionclassinstance->results);
if (! empty($actionclassinstance->resprints)) $this->resPrint.=$actionclassinstance->resprints; if (! empty($actionclassinstance->resprints)) $this->resPrint.=$actionclassinstance->resprints;
// TODO dead code to remove (do not enable this, but fix hook instead): result must not be a string. we must use $actionclassinstance->resprints to return a string // TODO dead code to remove (do not enable this, but fix hook instead): result must not be a string but an int. you must use $actionclassinstance->resprints to return a string
if (! is_array($resaction) && ! is_numeric($resaction)) if (! is_array($resaction) && ! is_numeric($resaction))
{ {
dol_syslog('Error: Bug into hook '.$method.' of module class '.get_class($actionclassinstance).'. Method must not return a string but an int (0=OK, 1=Replace, -1=KO) and set string into ->resprints', LOG_ERR); dol_syslog('Error: Bug into hook '.$method.' of module class '.get_class($actionclassinstance).'. Method must not return a string but an int (0=OK, 1=Replace, -1=KO) and set string into ->resprints', LOG_ERR);

View File

@ -5683,7 +5683,7 @@ class Form
/** /**
* Return a HTML area with the reference of object and a navigation bar for a business object * Return a HTML area with the reference of object and a navigation bar for a business object
* To add a particular filter on select, you must set $object->next_prev_filter to SQL criteria. * Note: To add a particular filter on select, you can have $object->next_prev_filter set to add SQL criterias.
* *
* @param object $object Object to show. * @param object $object Object to show.
* @param string $paramid Name of parameter to use to name the id into the URL next/previous link. * @param string $paramid Name of parameter to use to name the id into the URL next/previous link.
@ -5701,12 +5701,20 @@ class Form
*/ */
function showrefnav($object,$paramid,$morehtml='',$shownav=1,$fieldid='rowid',$fieldref='ref',$morehtmlref='',$moreparam='',$nodbprefix=0,$morehtmlleft='',$morehtmlstatus='',$morehtmlright='') function showrefnav($object,$paramid,$morehtml='',$shownav=1,$fieldid='rowid',$fieldref='ref',$morehtmlref='',$moreparam='',$nodbprefix=0,$morehtmlleft='',$morehtmlstatus='',$morehtmlright='')
{ {
global $langs,$conf; global $langs,$conf,$hookmanager;
$ret=''; $ret='';
if (empty($fieldid)) $fieldid='rowid'; if (empty($fieldid)) $fieldid='rowid';
if (empty($fieldref)) $fieldref='ref'; if (empty($fieldref)) $fieldref='ref';
// Add where from hooks
if (is_object($hookmanager))
{
$parameters=array();
$reshook=$hookmanager->executeHooks('printFieldListWhere',$parameters, $object); // Note that $action and $object may have been modified by hook
$object->next_prev_filter.=$hookmanager->resPrint;
}
//print "paramid=$paramid,morehtml=$morehtml,shownav=$shownav,$fieldid,$fieldref,$morehtmlref,$moreparam"; //print "paramid=$paramid,morehtml=$morehtml,shownav=$shownav,$fieldid,$fieldref,$morehtmlref,$moreparam";
$object->load_previous_next_ref((isset($object->next_prev_filter)?$object->next_prev_filter:''),$fieldid,$nodbprefix); $object->load_previous_next_ref((isset($object->next_prev_filter)?$object->next_prev_filter:''),$fieldid,$nodbprefix);

View File

@ -972,7 +972,8 @@ function dol_get_fiche_end($notab=0)
} }
/** /**
* Show tab footer of a card * Show tab footer of a card.
* Note: $object->next_prev_filter can be set to restrict select to find next or previous record by $form->showrefnav.
* *
* @param object $object Object to show * @param object $object Object to show
* @param string $paramid Name of parameter to use to name the id into the URL next/previous link * @param string $paramid Name of parameter to use to name the id into the URL next/previous link