From e0568aca4c4fc5f5da72d0fa7fcef3d8499cb14a Mon Sep 17 00:00:00 2001 From: Thomas Mudrunka Date: Mon, 22 Oct 2012 19:17:04 +0200 Subject: [PATCH] Knihovna pro generovani query stringu, fix blbosti s orderby --- index.php | 14 +++++++------- lib/Query.class.php | 39 +++++++++++++++++++++++++++++++++++++++ 2 files changed, 46 insertions(+), 7 deletions(-) create mode 100755 lib/Query.class.php diff --git a/index.php b/index.php index b9860e3..ef5d5b5 100755 --- a/index.php +++ b/index.php @@ -1,7 +1,7 @@ array( 'item' => array('category_name'), @@ -506,12 +506,12 @@ EOF; if($class) $this->table_hide_columns($table,$class); $this->table_sort($table); - //TODO: orderbaj fixme (napsat funkci na pridavani/ubirani soucasnych URL parametru) - $get = $_SERVER['QUERY_STRING'] != '' ? '?'.$_SERVER['QUERY_STRING'] : ''; - $moreget = isset($get[0]) ? '&' : '?'; - $path=$_SERVER['PATH_INFO'].$get.$moreget; + //Orderby: + $path = $_GET; + unset($path['orderby']); + $path = '?'.Query::build($path).'orderby'; - return $this->table($table,$colspan,$rowspan,$break_after,$path.'orderby'); + return $this->table($table,$colspan,$rowspan,$break_after,$path); } function render_insert_inputs($class,$columns,$selectbox,$current,$hidecols,$update) { diff --git a/lib/Query.class.php b/lib/Query.class.php new file mode 100755 index 0000000..48a2bb0 --- /dev/null +++ b/lib/Query.class.php @@ -0,0 +1,39 @@ +. +*/ + +/** +* Trida implementuje funkce pro manipulaci s query stringem +* +* @package Query +* @author Tomas Mudrunka +*/ +class Query { + + static function build($query=array(),$prefix=false) { + $q=''; + if(is_array($query)) foreach($query as $key => $val) { + $pre = !$prefix ? $key : $prefix.'['.$key.']'; + $q.=Query::build($val,$pre); + } else { + return $prefix.'='.$query.'&'; + } + return $q; + } + +} -- 2.30.2