@@ -181,9 +181,56 @@ public function getSearchSQL($sql_where = '')
181181 foreach ($ this ->listDef ['item ' ] as $ i ) {
182182 $ field = $ i ['field ' ];
183183 $ table = $ i ['table ' ];
184+
185+ $ searchval = $ _SESSION ['search ' ][$ list_name ][$ search_prefix .$ field ];
186+ // format user date format to MySQL date format 0000-00-00
187+ if ($ i ['datatype ' ] == 'DATE ' && $ this ->lng ('conf_format_dateshort ' ) != 'Y-m-d ' ){
188+ $ dateformat = preg_replace ("@[^Ymd]@ " , "" , $ this ->lng ('conf_format_dateshort ' ));
189+ $ yearpos = strpos ($ dateformat , 'Y ' ) + 1 ;
190+ $ monthpos = strpos ($ dateformat , 'm ' ) + 1 ;
191+ $ daypos = strpos ($ dateformat , 'd ' ) + 1 ;
192+
193+ $ full_date_trans = array ('Y ' => '((?:19|20)\d\d) ' ,
194+ 'm ' => '(0[1-9]|1[012]) ' ,
195+ 'd ' => '(0[1-9]|[12][0-9]|3[01]) '
196+ );
197+ // d.m.Y Y/m/d
198+ $ full_date_regex = strtr (preg_replace ("@[^Ymd]@ " , "[^0-9] " , $ this ->lng ('conf_format_dateshort ' )), $ full_date_trans );
199+ //echo $full_date_regex;
200+
201+ if (preg_match ("@^\d+$@ " , $ _SESSION ['search ' ][$ list_name ][$ search_prefix .$ field ])) { // we just have digits
202+ $ searchval = $ _SESSION ['search ' ][$ list_name ][$ search_prefix .$ field ];
203+ } elseif (preg_match ("@^[^0-9]?\d+[^0-9]?$@ " , $ _SESSION ['search ' ][$ list_name ][$ search_prefix .$ field ])){ // 10. or .10.
204+ $ searchval = preg_replace ("@[^0-9]@ " , "" , $ _SESSION ['search ' ][$ list_name ][$ search_prefix .$ field ]);
205+ } elseif (preg_match ("@^[^0-9]?(\d{1,2})[^0-9]((?:19|20)\d\d)$@ " , $ _SESSION ['search ' ][$ list_name ][$ search_prefix .$ field ], $ matches )){ // 10.2013
206+ $ month = $ matches [1 ];
207+ $ year = $ matches [2 ];
208+ $ searchval = $ year .'- ' .$ month ;
209+ } elseif (preg_match ("@^((?:19|20)\d\d)[^0-9](\d{1,2})[^0-9]?$@ " , $ _SESSION ['search ' ][$ list_name ][$ search_prefix .$ field ], $ matches )){ // 2013-10
210+ $ month = $ matches [2 ];
211+ $ year = $ matches [1 ];
212+ $ searchval = $ year .'- ' .$ month ;
213+ } elseif (preg_match ("@^[^0-9]?(\d{1,2})[^0-9](\d{1,2})[^0-9]?$@ " , $ _SESSION ['search ' ][$ list_name ][$ search_prefix .$ field ], $ matches )){ // 04.10.
214+ if ($ monthpos < $ daypos ){
215+ $ month = $ matches [1 ];
216+ $ day = $ matches [2 ];
217+ } else {
218+ $ month = $ matches [2 ];
219+ $ day = $ matches [1 ];
220+ }
221+ $ searchval = $ month .'- ' .$ day ;
222+ } elseif (preg_match ("@^ " .$ full_date_regex ."$@ " , $ _SESSION ['search ' ][$ list_name ][$ search_prefix .$ field ], $ matches )) {
223+ //print_r($matches);
224+ $ day = $ matches [$ daypos ];
225+ $ month = $ matches [$ monthpos ];
226+ $ year = $ matches [$ yearpos ];
227+ $ searchval = $ year .'- ' .$ month .'- ' .$ day ;
228+ }
229+ }
230+
184231 // if($_REQUEST[$search_prefix.$field] != '') $sql_where .= " $field ".$i["op"]." '".$i["prefix"].$_REQUEST[$search_prefix.$field].$i["suffix"]."' and";
185- if (isset ($ _SESSION [ ' search ' ][ $ list_name ][ $ search_prefix . $ field ] ) && $ _SESSION [ ' search ' ][ $ list_name ][ $ search_prefix . $ field ] != '' ){
186- $ sql_where .= " " .($ table != '' ? $ table .'. ' : $ this ->listDef ['table ' ].'. ' )."$ field " .$ i ['op ' ]." ' " .$ app ->db ->quote ($ i ['prefix ' ].$ _SESSION [ ' search ' ][ $ list_name ][ $ search_prefix . $ field ] .$ i ['suffix ' ])."' and " ;
232+ if (isset ($ searchval ) && $ searchval != '' ){
233+ $ sql_where .= " " .($ table != '' ? $ table .'. ' : $ this ->listDef ['table ' ].'. ' )."$ field " .$ i ['op ' ]." ' " .$ app ->db ->quote ($ i ['prefix ' ].$ searchval .$ i ['suffix ' ])."' and " ;
187234 }
188235 }
189236 }
0 commit comments