diff --git a/htdocs/core/class/listview.class.php b/htdocs/core/class/listview.class.php index 11a948472e4..38645dbca0a 100644 --- a/htdocs/core/class/listview.class.php +++ b/htdocs/core/class/listview.class.php @@ -200,52 +200,51 @@ class Listview } else { - if(strpos($value,'%')===false) $value = '%'.$value.'%'; - $TSQLMore[]=$sKey." LIKE '".addslashes($value)."'" ; + if(strpos($value,'%')===false) $value = '%'.$value.'%'; + $TSQLMore[]=$sKey." LIKE '".addslashes($value)."'" ; } return true; } - private function search($sql,&$TParam) { - + + /** + * @param $sql + * @param $TParam + * @return string + */ + private function search($sql, &$TParam) + { $ListPOST = GETPOST('Listview'); - if(!empty($ListPOST[$this->id]['search'])) { + if(!empty($ListPOST[$this->id]['search'])) + { $sqlGROUPBY=''; - if(strpos($sql,'GROUP BY')!==false) { //TODO regex + if(strpos($sql,'GROUP BY')!==false) + { list($sql, $sqlGROUPBY) = explode('GROUP BY', $sql); } - if(strpos($sql,'WHERE ')===false)$sql.=' WHERE 1 '; //TODO regex - //TODO $value = GETPOST('Listview_'.$this->id.'_search_'.$key) ? mktime(0,0,0, (int)GETPOST('Listview_'.$this->id.'_search_'.$key.'month'), (int)GETPOST('Listview_'.$this->id.'_search_'.$key.'day'), (int)GETPOST('Listview_'.$this->id.'_search_'.$key.'year') ) : ''; + if(strpos($sql,'WHERE ')===false) $sql.=' WHERE 1 '; - foreach($ListPOST[$this->id]['search'] as $key=>$value) + foreach($ListPOST[$this->id]['search'] as $key => $value) { $TsKey = $this->getSearchKey($key, $TParam); - - //if (!empty($value)) var_dump($TsKey, $TsBindKey, '=================================='); $TSQLMore = array(); $allow_is_null = $this->getSearchNull($key,$TParam); - $search_on_null = false; //TODO useless foreach ($TsKey as $i => &$sKey) { if($allow_is_null && !empty($ListPOST[$this->id]['search_on_null'][$key])) { $TSQLMore[] = $sKey.' IS NULL '; - $search_on_null = true; - $value = ''; } - elseif($allow_is_null) + + // Do not use empty() function, statut 0 exist + if($value != '') { - null; - } - - if($value!='') { // pas empty car biensûr le statut = 0 existe dans de nombreux cas - if(isset($TParam['type'][$key]) && ($TParam['type'][$key]==='date' || $TParam['type'][$key]==='datetime')) { $this->addSqlFromTypeDate($TSQLMore, $value, $sKey); @@ -265,15 +264,18 @@ class Listview } if($sqlGROUPBY!='') $sql.=' GROUP BY '.$sqlGROUPBY; - } - return $sql; } - public function render($sql,$TParam=array()) { - + /** + * @param $sql + * @param array $TParam + * @return string + */ + public function render($sql, $TParam=array()) + { $THeader=array(); $TField=array(); @@ -286,11 +288,16 @@ class Listview list($TTotal, $TTotalGroup)=$this->get_total($TField, $TParam); - return $this->renderList($THeader, $TField,$TTotal,$TTotalGroup, $TParam); - + return $this->renderList($THeader, $TField,$TTotal,$TTotalGroup, $TParam); } - private function setSearch(&$THeader, &$TParam) { + /** + * @param $THeader + * @param $TParam + * @return array + */ + private function setSearch(&$THeader, &$TParam) + { global $langs, $form; if(empty($TParam['search'])) return array(); @@ -299,32 +306,33 @@ class Listview $nb_search_in_bar = 0; - if(!empty($TParam['search'])) { - foreach($THeader as $key=>$libelle) { // init + if(!empty($TParam['search'])) + { + foreach($THeader as $key => $libelle) + { if(empty($TSearch[$key]))$TSearch[$key]=''; } } $ListPOST = GETPOST('Listview'); - - foreach($TParam['search'] as $key=>$param_search) { - + foreach($TParam['search'] as $key => $param_search) + { $value = isset($ListPOST[$this->id]['search'][$key]) ? $ListPOST[$this->id]['search'][$key] : ''; $typeRecherche = (is_array($param_search) && isset($param_search['recherche'])) ? $param_search['recherche'] : $param_search; - if(is_array($typeRecherche)) { + if(is_array($typeRecherche)) + { $fsearch=$form->selectarray('Listview['.$this->id.'][search]['.$key.']', $typeRecherche,$value,1); } - else if($typeRecherche==='calendar') { - + else if($typeRecherche==='calendar') + { $value = GETPOST('Listview_'.$this->id.'_search_'.$key) ? mktime(0,0,0, (int)GETPOST('Listview_'.$this->id.'_search_'.$key.'month'), (int)GETPOST('Listview_'.$this->id.'_search_'.$key.'day'), (int)GETPOST('Listview_'.$this->id.'_search_'.$key.'year') ) : ''; $fsearch = $form->select_date($value, 'Listview_'.$this->id.'_search_'.$key,0, 0, 1, "", 1, 0, 1); - //$fsearch=$form->calendrier('','Listview['.$this->id.'][search]['.$key.']',$value,10,10,' listviewtbs="calendar" '); } - else if($typeRecherche==='calendars') { - + else if($typeRecherche==='calendars') + { $value_start = GETPOST('Listview_'.$this->id.'_search_'.$key.'_start') ? mktime(0,0,0, (int)GETPOST('Listview_'.$this->id.'_search_'.$key.'_startmonth'), (int)GETPOST('Listview_'.$this->id.'_search_'.$key.'_startday'), (int)GETPOST('Listview_'.$this->id.'_search_'.$key.'_startyear') ) : ''; $value_end = GETPOST('Listview_'.$this->id.'_search_'.$key.'_end') ? mktime(0,0,0, (int)GETPOST('Listview_'.$this->id.'_search_'.$key.'_endmonth'), (int)GETPOST('Listview_'.$this->id.'_search_'.$key.'_endday'), (int)GETPOST('Listview_'.$this->id.'_search_'.$key.'_endyear') ) : ''; @@ -332,96 +340,113 @@ class Listview . $form->select_date($value_end, 'Listview_'.$this->id.'_search_'.$key.'_end',0, 0, 1, "", 1, 0, 1); } - else if(is_string($typeRecherche)) { + else if(is_string($typeRecherche)) + { $fsearch=$TParam['search'][$key]; } - else { + else + { $fsearch=''; } - if(!empty($param_search['allow_is_null'])) { + if(!empty($param_search['allow_is_null'])) + { $valueNull = isset($ListPOST[$this->id]['search_on_null'][$key]) ? 1 : 0; $fsearch.=' '.$form->checkbox1('', 'Listview['.$this->id.'][search_on_null]['.$key.']',1, $valueNull,' onclick=" if($(this).is(\':checked\')){ $(this).prev().val(\'\'); }" ').img_help(1, $langs->trans('SearchOnNUllValue')); } - - if(!empty($THeader[$key])) { + if(!empty($THeader[$key])) + { $TSearch[$key] = $fsearch; $nb_search_in_bar++; } - else { + else + { $label = !empty($TParam['title'][$key]) ? $TParam['title'][$key] : $key ; $TParam['list']['head_search'].='