From 2d2fd172e1548dd24e1719accd0b856cff6a31a0 Mon Sep 17 00:00:00 2001 From: Falko Timme <ft@falkotimme.com> Date: Fri, 18 Oct 2013 12:20:13 -0400 Subject: [PATCH] - Added funtion to convert currency formatted numbers back to floating numbers. - Improved getSearchSQL() function so that users can use their native date format so search for dates in lists. --- interface/lib/classes/listform.inc.php | 139 ++++++++++++++++++++++++++++++++++++++++++---- 1 files changed, 126 insertions(+), 13 deletions(-) diff --git a/interface/lib/classes/listform.inc.php b/interface/lib/classes/listform.inc.php index 6128022..68d89b3 100644 --- a/interface/lib/classes/listform.inc.php +++ b/interface/lib/classes/listform.inc.php @@ -180,9 +180,57 @@ if(@is_array($this->listDef['item'])) { foreach($this->listDef['item'] as $i) { $field = $i['field']; + $table = $i['table']; + + $searchval = $_SESSION['search'][$list_name][$search_prefix.$field]; + // format user date format to MySQL date format 0000-00-00 + if($i['datatype'] == 'DATE' && $this->lng('conf_format_dateshort') != 'Y-m-d'){ + $dateformat = preg_replace("@[^Ymd]@", "", $this->lng('conf_format_dateshort')); + $yearpos = strpos($dateformat, 'Y') + 1; + $monthpos = strpos($dateformat, 'm') + 1; + $daypos = strpos($dateformat, 'd') + 1; + + $full_date_trans = array ('Y' => '((?:19|20)\d\d)', + 'm' => '(0[1-9]|1[012])', + 'd' => '(0[1-9]|[12][0-9]|3[01])' + ); + // d.m.Y Y/m/d + $full_date_regex = strtr(preg_replace("@[^Ymd]@", "[^0-9]", $this->lng('conf_format_dateshort')), $full_date_trans); + //echo $full_date_regex; + + if (preg_match("@^\d+$@", $_SESSION['search'][$list_name][$search_prefix.$field])) { // we just have digits + $searchval = $_SESSION['search'][$list_name][$search_prefix.$field]; + } elseif(preg_match("@^[^0-9]?\d+[^0-9]?$@", $_SESSION['search'][$list_name][$search_prefix.$field])){ // 10. or .10. + $searchval = preg_replace("@[^0-9]@", "", $_SESSION['search'][$list_name][$search_prefix.$field]); + } elseif(preg_match("@^[^0-9]?(\d{1,2})[^0-9]((?:19|20)\d\d)$@", $_SESSION['search'][$list_name][$search_prefix.$field], $matches)){ // 10.2013 + $month = $matches[1]; + $year = $matches[2]; + $searchval = $year.'-'.$month; + } elseif(preg_match("@^((?:19|20)\d\d)[^0-9](\d{1,2})[^0-9]?$@", $_SESSION['search'][$list_name][$search_prefix.$field], $matches)){ // 2013-10 + $month = $matches[2]; + $year = $matches[1]; + $searchval = $year.'-'.$month; + } 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. + if($monthpos < $daypos){ + $month = $matches[1]; + $day = $matches[2]; + } else { + $month = $matches[2]; + $day = $matches[1]; + } + $searchval = $month.'-'.$day; + } elseif (preg_match("@^".$full_date_regex."$@", $_SESSION['search'][$list_name][$search_prefix.$field], $matches)) { + //print_r($matches); + $day = $matches[$daypos]; + $month = $matches[$monthpos]; + $year = $matches[$yearpos]; + $searchval = $year.'-'.$month.'-'.$day; + } + } + // if($_REQUEST[$search_prefix.$field] != '') $sql_where .= " $field ".$i["op"]." '".$i["prefix"].$_REQUEST[$search_prefix.$field].$i["suffix"]."' and"; - if(isset($_SESSION['search'][$list_name][$search_prefix.$field]) && $_SESSION['search'][$list_name][$search_prefix.$field] != ''){ - $sql_where .= " $field ".$i['op']." '".$app->db->quote($i['prefix'].$_SESSION['search'][$list_name][$search_prefix.$field].$i['suffix'])."' and"; + if(isset($searchval) && $searchval != ''){ + $sql_where .= " ".($table != ''? $table.'.' : $this->listDef['table'].'.')."$field ".$i['op']." '".$app->db->quote($i['prefix'].$searchval.$i['suffix'])."' and"; } } } @@ -192,11 +240,16 @@ public function getPagingSQL($sql_where = '1') { global $app, $conf; - - //* Add Global Limit from selectbox - if(!empty($_POST['search_limit']) AND $app->functions->intval($_POST['search_limit'])){ + + //* Add Global Limit from selectbox + if(!empty($_POST['search_limit']) AND $app->functions->intval($_POST['search_limit']) > 0){ $_SESSION['search']['limit'] = $app->functions->intval($_POST['search_limit']); } + + //if(preg_match('{^[0-9]$}',$_SESSION['search']['limit'])){ + // $_SESSION['search']['limit'] = 15; + //} + if(intval($_SESSION['search']['limit']) < 1) $_SESSION['search']['limit'] = 15; //* Get Config variables $list_name = $this->listDef['name']; @@ -216,7 +269,7 @@ if($this->searchChanged == 1) $_SESSION['search'][$list_name]['page'] = 0; $sql_von = $app->functions->intval($_SESSION['search'][$list_name]['page'] * $records_per_page); - $record_count = $app->db->queryOneRecord("SELECT count(*) AS anzahl FROM $table WHERE $sql_where"); + $record_count = $app->db->queryOneRecord("SELECT count(*) AS anzahl FROM $table".($app->listform->listDef['additional_tables'] != ''? ','.$app->listform->listDef['additional_tables'] : '')." WHERE $sql_where"); $pages = $app->functions->intval(($record_count['anzahl'] - 1) / $records_per_page); @@ -243,21 +296,65 @@ public function getPagingHTML($vars) { global $app; - $content = '<a href="'."javascript:loadContent('".$vars['list_file'].'?page=0'.$vars['page_params']."');".'">' - .'<img src="themes/'.$_SESSION['s']['theme'].'/icons/x16/arrow_stop_180.png"></a> '; + + // we want to show at max 17 page numbers (8 left, current, 8 right) + $show_pages_count = 17; + + $show_pages = array(0); // first page + if($vars['pages'] > 0) $show_pages[] = $vars['pages']; // last page + for($p = $vars['page'] - 2; $p <= $vars['page'] + 2; $p++) { // surrounding pages + if($p > 0 && $p < $vars['pages']) $show_pages[] = $p; + } + + $l_start = $vars['page'] - 13; + $l_start -= ($l_start % 10) + 1; + $h_end = $vars['page'] + 23; + $h_end -= ($h_end % 10) + 1; + for($p = $l_start; $p <= $h_end; $p += 10) { // surrounding pages + if($p > 0 && $p < $vars['pages'] && !in_array($p, $show_pages, true) && count($show_pages) < $show_pages_count) $show_pages[] = $p; + } + + $l_start = $vars['page'] - 503; + $l_start -= ($l_start % 100) + 1; + $h_end = $vars['page'] + 603; + $h_end -= ($h_end % 100) + 1; + for($p = $l_start; $p <= $h_end; $p += 100) { // surrounding pages + if($p > 0 && $p < $vars['pages'] && !in_array($p, $show_pages, true) && count($show_pages) < $show_pages_count) $show_pages[] = $p; + } + + $l_start = $vars['page'] - 203; + $l_start -= ($l_start % 25) + 1; + $h_end = $vars['page'] + 228; + $h_end -= ($h_end % 25) + 1; + for($p = $l_start; $p <= $h_end; $p += 25) { // surrounding pages + if($p > 0 && $p < $vars['pages'] && abs($p - $vars['page']) > 30 && !in_array($p, $show_pages, true) && count($show_pages) < $show_pages_count) $show_pages[] = $p; + } + + sort($show_pages); + $show_pages = array_unique($show_pages); + //* Show Back if(isset($vars['show_page_back']) && $vars['show_page_back'] == 1){ - $content .= '<a href="'."javascript:loadContent('".$vars['list_file'].'?page='.$vars['last_page'].$vars['page_params']."');".'">' + $content = '<a class="btn-page first-page" href="'."javascript:loadContent('".$vars['list_file'].'?page=0'.$vars['page_params']."');".'">' + .'<img src="themes/'.$_SESSION['s']['theme'].'/icons/x16/arrow_stop_180.png"></a> '; + $content .= '<a class="btn-page previous-page" href="'."javascript:loadContent('".$vars['list_file'].'?page='.$vars['last_page'].$vars['page_params']."');".'">' .'<img src="themes/'.$_SESSION['s']['theme'].'/icons/x16/arrow_180.png"></a> '; } - $content .= ' '.$this->lng('page_txt').' '.$vars['next_page'].' '.$this->lng('page_of_txt').' '.$vars['max_pages'].' '; + $content .= ' '.$this->lng('page_txt').' '; + $prev = -1; + foreach($show_pages as $p) { + if($prev != -1 && $p > $prev + 1) $content .= '<span class="page-spacer">...</span>'; + $content .= '<a class="link-page' . ($p == $vars['page'] ? ' current-page' : '') . '" href="'."javascript:loadContent('".$vars['list_file'].'?page='.$p.$vars['page_params']."');".'">'. ($p+1) .'</a>'; + $prev = $p; + } + //.$vars['next_page'].' '.$this->lng('page_of_txt').' '.$vars['max_pages'].' '; //* Show Next if(isset($vars['show_page_next']) && $vars['show_page_next'] == 1){ - $content .= '<a href="'."javascript:loadContent('".$vars['list_file'].'?page='.$vars['next_page'].$vars['page_params']."');".'">' + $content .= '<a class="btn-page next-page" href="'."javascript:loadContent('".$vars['list_file'].'?page='.$vars['next_page'].$vars['page_params']."');".'">' .'<img src="themes/'.$_SESSION['s']['theme'].'/icons/x16/arrow.png"></a> '; - } - $content .= '<a href="'."javascript:loadContent('".$vars['list_file'].'?page='.$vars['pages'].$vars['page_params']."');".'">' + $content .= '<a class="btn-page last-page" href="'."javascript:loadContent('".$vars['list_file'].'?page='.$vars['pages'].$vars['page_params']."');".'">' .'<img src="themes/'.$_SESSION['s']['theme'].'/icons/x16/arrow_stop.png"></a>'; + } return $content; } @@ -310,6 +407,16 @@ $record[$key] = date($this->lng('conf_format_dateshort'), $record[$key]); } else { $record[$key] = date($this->lng('conf_format_dateshort'), strtotime($record[$key])); + } + } + break; + case 'DATETIMETSTAMP': + if ($record[$key] > 0) { + // is value int? + if (preg_match("/^[0-9]+[\.]?[0-9]*$/", $record[$key], $p)) { + $record[$key] = date($this->lng('conf_format_datetime'), $record[$key]); + } else { + $record[$key] = date($this->lng('conf_format_datetime'), strtotime($record[$key])); } } break; @@ -378,6 +485,12 @@ $record[$key] = date('Y-m-d',strtotime($record[$key])); } break; + + case 'DATETIMETSTAMP': + if($record[$key] > 0) { + $record[$key] = date('Y-m-d H:i:s',strtotime($record[$key])); + } + break; case 'DATE': if($record[$key] != '' && $record[$key] != '0000-00-00') { -- Gitblit v1.9.1