Hledej polozku
[mirrors/SokoMan.git] / index.php
index ab5d70a34dd45148e778da211d1da191dc45737b..67f38433d2d94180567ac6d3767feaae392471d0 100755 (executable)
--- a/index.php
+++ b/index.php
@@ -1,7 +1,7 @@
 <?php
 /*
  * SkladovySystem - Storage management system compatible with LMS
- * Copyright (C) 2011  Tomas Mudrunka
+ * Copyright (C) 2011-2012  Tomas Mudrunka
  *
  * This program is free software: you can redistribute it and/or modify
  * it under the terms of the GNU Affero General Public License as
@@ -22,6 +22,7 @@ set_include_path(DIR_LIB.PATH_SEPARATOR.get_include_path());
 
 require_once('Sklad_Auth.class/common.php');
 require_once('HTTP_Auth.class.php');
+require_once('Query.class.php');
 require_once('Locale.class.php');
 require_once('Barcode.class.php');
 require_once('Fortune.php');
@@ -47,7 +48,7 @@ class HTML {
                        if(trim($var) == '') $var = '&nbsp;';
                        $rs = isset($rowspan[$id]) ? " rowspan='$rowspan[$id]'" : '';
                        $cs = isset($colspan[$id]) ? " colspan='$colspan[$id]'" : '';
-                       $html.="<$td$rs$cs$tdclass>$var</$td>";
+                       $html.="<$td$rs$cs$tdclass title='$id'>$var</$td>";
                        if(in_array($id,$break_after,true)) $html.='</tr>'."<tr$class_br$parameters>";
                }
                $html.='</tr>';
@@ -55,7 +56,7 @@ class HTML {
                return $html;
        }
 
-       function table(&$table,$colspan=array(),$rowspan=array(),$break_after=array(),$parity_class=array('tr_odd','tr_even'),$params='border=1',$row_classes_field='_row_classes') {
+       function table(&$table,$colspan=array(),$rowspan=array(),$break_after=array(),$orderby=false,$parity_class=array('tr_odd','tr_even'),$params='border=1',$row_classes_field='_row_classes') {
                $html="<table $params>";
                $header=true;
                $even=false;
@@ -63,8 +64,13 @@ class HTML {
                        $params = isset($row[$row_classes_field]) ? $row[$row_classes_field] : '';
                        unset($row[$row_classes_field]);
                        if($header) {
-                               $keys = array(); foreach($row as $key => $val) $keys[$key]=$key;
-                               $html.=$this->row(T($keys),'thead',false,'',$colspan,$rowspan,$break_after);
+                               $keys = array(); foreach($row as $key => $val) {
+                                       $order= $orderby ? '&nbsp;'.
+                                               $this->link('&uarr;', $orderby."[$key]=ASC").
+                                               $this->link('&darr;', $orderby."[$key]=DESC") : '';
+                                       $keys[$key]=T($key).$order;
+                               }
+                               $html.=$this->row($keys,'thead',false,'',$colspan,$rowspan,$break_after);
                                $header=false;
                        }
                        $class = $parity_class ? $parity_class[$even] : false;
@@ -301,7 +307,7 @@ EOF;
 
        $html .= $this->form("$script/item", 'GET', array(
                array('q',$search,'text','regexp...','autofocus'),
-               array(false,'search','submit')
+               array(false,'search item','submit')
        ), 'style="float: left;"');
 
        $html .= '</div>';
@@ -362,7 +368,7 @@ EOF;
                $insert_url = '%d/new?insert[%c]=%v';
                $relations = array( //TODO: Autodetect??? //TODO: Add [edit] link to all classes
                        'model' => array(
-                               'model_id' => array(array('item',$where_url),array('barcode',$where_url),array('edit','model/%v/edit/'),array('barcode',$insert_url)),
+                               'model_id' => array(array('item',$where_url),array('barcode',$where_url),array('edit','model/%v/edit/'),array('barcode',$insert_url,false,'add barcode')),
                                'model_barcode' => array(array('store','assistant/%d?barcode=%v')),
                                'barcode_name' => array(array('store','assistant/%d?barcode=%v')),
                                'model_name' => array(array('google','http://google.com/search?q=%v')) //TODO: add manufacturer to google query
@@ -404,7 +410,8 @@ EOF;
                                                        //$condition = $relations_conditions[$destination[2]]($table,$id);
                                                        if(!eval($relations_conditions[$destination[2]])) continue;
                                                }
-                                               @$table[$id][$class.$suffix_relations] .= $this->link($destination[0], $destination_url, !preg_match('/http/', $destination_url) ).',';
+                                               $destination_title = isset($destination[3]) ? $destination[3] : $destination[0];
+                                               @$table[$id][$class.$suffix_relations] .= $this->link($destination_title, $destination_url, !preg_match('/http/', $destination_url) ).',';
                                        }
                                }
                        }
@@ -472,7 +479,6 @@ EOF;
        }
 
        function render_item_table($table,$class=false) {
-
                $cellspan = array(
                        'break_after' => array(
                                'item' => array('category_name'),
@@ -499,7 +505,13 @@ EOF;
                $this->table_collapse($table);
                if($class) $this->table_hide_columns($table,$class);
                $this->table_sort($table);
-               return $this->table($table,$colspan,$rowspan,$break_after);
+
+               //Orderby:
+               $path = $_GET;
+               unset($path['orderby']);
+               $path = $_SERVER['PATH_INFO'].'?'.Query::build($path).'orderby';
+
+               return $this->table($table,$colspan,$rowspan,$break_after,$path);
        }
 
        function render_insert_inputs($class,$columns,$selectbox,$current,$hidecols,$update) {
@@ -685,7 +697,12 @@ class Sklad_DB extends PDO {
                $sql.=$group_by;
 
                //ORDER
-               if(!$order) $order = $class.$suffix_id.' DESC';
+               $orders=$order;
+               $order='';
+               if(is_array($orders)) foreach($orders as $column => $direction) {
+                       $order="$column $direction,";
+               }
+               $order .= $class.$suffix_id.' DESC';
                if($this->contains_history($class)) $order .= ",${class}_valid_from DESC";
                $sql .= "ORDER BY $order\n";
                //LIMIT/OFFSET
@@ -738,7 +755,8 @@ class Sklad_DB extends PDO {
        }
 
        function get_listing($class, $id=false, $limit=false, $offset=0, $where=false, $search=false, $history=false, $indexed=array(), $suffix_id='_id') {
-               $sql = $this->build_query_select($class, $id, $limit, $offset, $where, $search, $history);
+               $order = isset($_GET['orderby']) ? $_GET['orderby'] : false;
+               $sql = $this->build_query_select($class, $id, $limit, $offset, $where, $search, $history, $order);
                $result = $this->safe_query_fetch($sql);
                if(!$result || !is_array($indexed)) return $result;
 
This page took 0.175719 seconds and 4 git commands to generate.