Pokus o preklad username na userid
[mirrors/SokoMan.git] / index.php
index caf25a0ef3039c92e95f2ea419b87abbc7565589..d6c7e5750e1476c26f199601a45b9852e67e9f3c 100755 (executable)
--- a/index.php
+++ b/index.php
@@ -262,16 +262,24 @@ EOF;
 
        $html .= '<div style="float: right;">';
 
+       /*
+       //TODO: Do we really need this?
        $html .= $this->form("$script/api/go", 'GET', array(
                array('q','','text','smart id...', 'autofocus'),
                array(false,'go','submit')
        ), 'style="float: left;"');
+       */
 
        $html .= $this->form('?', 'GET', array(
                array('q',$search,'text','regexp...'),
                array(false,'filter','submit')
        ), 'style="float: left;"');
 
+       $html .= $this->form("$script/item", 'GET', array(
+               array('q',$search,'text','regexp...','autofocus'),
+               array(false,'search','submit')
+       ), 'style="float: left;"');
+
        $html .= '</div>';
 
        $html .= <<<EOF
@@ -320,12 +328,13 @@ EOF;
                $where_url = '%d/?where[%c]==%v';
                $relations = array( //TODO: Autodetect???
                        'model' => array(
-                               'model_id' => array(array('item',$where_url)),
+                               'model_id' => array(array('item',$where_url),array('edit','model/%v/edit/')),
                                'model_barcode' => array(array('store','assistant/%d?barcode=%v')),
                                'model_name' => array(array('google','http://google.com/search?q=%v',true)) //TODO: add manufacturer to google query
                        ),
                        'item' => array(
-                               'item_serial' => array(array('dispose','assistant/%d?serial=%v'),array('sell','assistant/%d?serial=%v'))
+                               'item_serial' => array(array('dispose','assistant/%d?serial=%v','not_sold'),array('sell','assistant/%d?serial=%v','not_sold')),
+                               'item_id' => array(array('edit','item/%v/edit/'))
                        ),
                        'category' => array('category_id' => array(array('item',$where_url), array('model',$where_url))),
                        'producer' => array('producer_id' => array(array('item',$where_url), array('model',$where_url))),
@@ -333,6 +342,10 @@ EOF;
                        'room' => array('room_id' => array(array('item',$where_url))),
                        'status' => array('status_id' => array(array('item',$where_url)))
                );
+               $relations_conditions=array(
+                       //'not_sold' => function(&$table,$id,$class=false,$column=false) { return(@$table[$id]['status_id'] != 3); }
+                       'not_sold' => 'return(@$table[$id]["status_id"] != 3);'
+               );
                foreach($table as $id => $row) {
                        foreach($row as $column => $value) {
                                if(isset($relations[$class][$column])) {
@@ -342,6 +355,10 @@ EOF;
                                                        array(urlencode($destination[0]),urlencode($column),urlencode($value)),
                                                        $destination[1]
                                                );
+                                               if(isset($destination[2]) && isset($relations_conditions[$destination[2]])) {
+                                                       //$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, !isset($destination[2])).',';
                                        }
                                }
@@ -370,7 +387,7 @@ EOF;
        }
 
        function table_sort(&$table) {
-               $precedence = array('item_id', 'model_image', 'model_name','model_descript','category_name','status_name','room_name');
+               $precedence = array('item_id', 'model_image', 'model_name','model_descript','category_name','status_name','room_name','item_quantity','item_price_in','item_price_out','model_price_in','model_price_out','item_relations','model_relations');
                $table_sorted = array();
                foreach($table as $id => $row) {
                        $table_sorted[$id] = array();
@@ -583,19 +600,30 @@ class Sklad_DB extends PDO {
                return $result;
        }
 
-       function translate_query_results($result) {
+       function translate_query_results(&$result) {
                $translate_cols = array('status_name', 'item_valid_till'); //TODO: Hardcoded
                foreach($result as $key => $row) {
                        foreach($translate_cols as $col) if(isset($result[$key][$col])){
                                $result[$key][$col] = T($result[$key][$col]);
                        }
                }
-               return $result;
+       }
+
+       function load_backend_data_to_query_results(&$result) {
+               $translate_cols = array(
+                       'item_author' => 'return($this->auth->get_username_by_id($result[$key][$col]));'
+               ); //TODO: Hardcoded
+               foreach($result as $key => $row) {
+                       foreach($translate_cols as $col => $backend) if(isset($result[$key][$col])){
+                               $result[$key][$col] = eval($backend);
+                       }
+               }
        }
 
        function safe_query_fetch($sql, $fatal=true, $fetch_flags = PDO::FETCH_ASSOC, $translate=true) {
                $result = $this->safe_query($sql, $fatal)->fetchAll($fetch_flags);
-               if($translate) $result = $this->translate_query_results($result);
+               $this->load_backend_data_to_query_results($result);
+               if($translate) $this->translate_query_results($result);
                return $result;
        }
 
This page took 0.134253 seconds and 4 git commands to generate.