From 13929bc46fecad5cc0d371a7784bb5fe7ee68ecb Mon Sep 17 00:00:00 2001 From: Laurent Destailleur Date: Wed, 9 Apr 2014 13:19:31 +0200 Subject: [PATCH] New: showrefnav can be used with tables without prefix. --- htdocs/core/class/commonobject.class.php | 11 ++++++----- htdocs/core/class/html.form.class.php | 6 ++++-- 2 files changed, 10 insertions(+), 7 deletions(-) diff --git a/htdocs/core/class/commonobject.class.php b/htdocs/core/class/commonobject.class.php index 8efd364dbf4..ba4094c2a14 100644 --- a/htdocs/core/class/commonobject.class.php +++ b/htdocs/core/class/commonobject.class.php @@ -816,9 +816,10 @@ abstract class CommonObject * * @param string $filter Optional filter * @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 * @return int <0 if KO, >0 if OK */ - function load_previous_next_ref($filter,$fieldid) + function load_previous_next_ref($filter,$fieldid,$nodbprefix=0) { global $conf, $user; @@ -834,7 +835,7 @@ abstract class CommonObject if ($this->element == 'societe') $alias = 'te'; $sql = "SELECT MAX(te.".$fieldid.")"; - $sql.= " FROM ".MAIN_DB_PREFIX.$this->table_element." as te"; + $sql.= " FROM ".(empty($nodbprefix)?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 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)."'"; @@ -847,7 +848,7 @@ abstract class CommonObject $result = $this->db->query($sql); if (! $result) { - $this->error=$this->db->error(); + $this->error=$this->db->lasterror(); return -1; } $row = $this->db->fetch_row($result); @@ -855,7 +856,7 @@ abstract class CommonObject $sql = "SELECT MIN(te.".$fieldid.")"; - $sql.= " FROM ".MAIN_DB_PREFIX.$this->table_element." as te"; + $sql.= " FROM ".(empty($nodbprefix)?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 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)."'"; @@ -869,7 +870,7 @@ abstract class CommonObject $result = $this->db->query($sql); if (! $result) { - $this->error=$this->db->error(); + $this->error=$this->db->lasterror(); return -2; } $row = $this->db->fetch_row($result); diff --git a/htdocs/core/class/html.form.class.php b/htdocs/core/class/html.form.class.php index f42d85b5871..4d082960d5d 100644 --- a/htdocs/core/class/html.form.class.php +++ b/htdocs/core/class/html.form.class.php @@ -4023,9 +4023,10 @@ class Form * @param string $fieldref Nom du champ objet ref (object->ref) a utiliser pour select next et previous * @param string $morehtmlref Code html supplementaire a afficher apres ref * @param string $moreparam More param to add in nav link url. + * @param int $nodbprefix Do not include DB prefix to forge table name * @return tring Portion HTML avec ref + boutons nav */ - function showrefnav($object,$paramid,$morehtml='',$shownav=1,$fieldid='rowid',$fieldref='ref',$morehtmlref='',$moreparam='') + function showrefnav($object,$paramid,$morehtml='',$shownav=1,$fieldid='rowid',$fieldref='ref',$morehtmlref='',$moreparam='',$nodbprefix=0) { global $langs,$conf; @@ -4034,7 +4035,8 @@ class Form if (empty($fieldref)) $fieldref='ref'; //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); + $object->load_previous_next_ref((isset($object->next_prev_filter)?$object->next_prev_filter:''),$fieldid,$nodbprefix); + $previous_ref = $object->ref_previous?''.(empty($conf->dol_use_jmobile)?img_picto($langs->trans("Previous"),'previous.png'):' ').'':''; $next_ref = $object->ref_next?''.(empty($conf->dol_use_jmobile)?img_picto($langs->trans("Next"),'next.png'):' ').'':'';