');
+ $fortune = fortune();
$instance = INSTANCE_ID != '' ? '/'.INSTANCE_ID : '';
$user_id = htmlspecialchars($user['id']);
$user_gid = htmlspecialchars($user['gid']);
@@ -181,6 +205,10 @@ td,body { background-color: white; }
table { background-color: orange; border: orange; }
a, a img { text-decoration:none; color: darkblue; border:none; }
li a, a:hover { text-decoration:underline; }
+.tr_even td { background-color: lemonchiffon; }
+.item_status_stored td { font-weight:bold; }
+.item_status_deleted td { text-decoration:line-through; }
+.item_status_destroyed td { font-style:italic; }
.menu li {
float: left;
@@ -219,8 +247,8 @@ EOF;
$assistants=array();
foreach(scandir(DIR_ASSISTANTS) as $item) {
if($item == '.' || $item == '..') continue;
- $item = preg_replace('/\.inc\.php$/','',$item);
- $assistants[$item] = "assistant/$item";
+ $item = preg_replace('/\.inc\.php$/','',$item,-1,$count);
+ if($count) $assistants[$item] = "assistant/$item";
}
$tables=array('item','model','category','producer','vendor','room','status');
@@ -240,16 +268,24 @@ EOF;
$html .= '';
- $html .= $this->form("$script/assistant/go", 'GET', array(
+ /*
+ //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 .= '
';
$html .= <<
$message
+
+$fortune
+
EOF;
return $html;
@@ -291,23 +330,38 @@ EOF;
}
}
+ function table_add_row_parameters(&$table, $param_col='_row_parameters') { //TODO: rename to table_add_row_classes()
+ $image = array('status_name' => ' item_status_');
+ foreach($table as $id => $row) {
+ foreach($image as $column => $param) if(isset($table[$id][$column])) {
+ @$table[$id][$param_col] .= $param.$table[$id][$column];
+ }
+ }
+ }
+
function table_add_relations(&$table, $class, $suffix_relations='_relations') {
$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))
+ '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','in_stock'),array('sell','assistant/%d?serial=%v','in_stock')),
+ 'item_id' => array(array('edit','item/%v/edit/'))
),
- 'category' => array('category_id' => array(array('item',$where_url), array('model',$where_url))),
+ '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))),
'vendor' => array('vendor_id' => array(array('item',$where_url))),
'room' => array('room_id' => array(array('item',$where_url))),
'status' => array('status_id' => array(array('item',$where_url)))
);
+ $relations_conditions=array(
+ 'in_stock' => 'return(@$table[$id]["status_name"] == "stored");',
+ 'not_sold' => 'return(@$table[$id]["status_name"] != "saled");',
+ 'not_sold_or_disposed' => 'return(@$table[$id]["status_name"] != "saled" && @$table[$id]["status_name"] != "disposed");'
+ );
foreach($table as $id => $row) {
foreach($row as $column => $value) {
if(isset($relations[$class][$column])) {
@@ -317,7 +371,11 @@ EOF;
array(urlencode($destination[0]),urlencode($column),urlencode($value)),
$destination[1]
);
- @$table[$id][$class.$suffix_relations] .= $this->link($destination[0], $destination_url, !isset($destination[2])).',';
+ 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).',';
}
}
}
@@ -333,19 +391,30 @@ EOF;
'vendor_id' => 'vendor_name',
'room_id' => 'room_name',
'status_id' => 'status_name',
+ 'item_author' => 'item_author_backend',
+ 'item_customer' => 'item_customer',
);
+
foreach($table as $id => $row) {
foreach($collapse as $link => $title)
if(isset($table[$id][$link]) && isset($row[$title])) {
$type = @array_shift(preg_split('/_/', $link));
if($link != $title) unset($table[$id][$link]);
- $table[$id][$title]=$this->link($row[$title], $type.'/'.$row[$link].'/');
+ switch($link) { //TODO: Move to array for easy configuration
+ case 'item_author':
+ case 'item_customer':
+ $table[$id][$title]=$this->link($row[$title], "?where[$link]==".$row[$link], false);
+ break;
+ default:
+ $table[$id][$title]=$this->link($row[$title], $type.'/'.$row[$link].'/');
+ break;
+ }
}
}
}
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();
@@ -359,16 +428,33 @@ EOF;
$table = $table_sorted;
}
+ function table_hide_columns(&$table, $class) { //TODO: Move to build_query_select() !!! :-)))
+ $fields_hide = array(
+ 'item' => array('model_descript','model_price_in','model_price_out','model_barcode','model_countable','model_reserve','model_eshop_hide','room_descript','room_author','producer_name','producer_note','vendor_note')
+ );
+ //print_r($table); die();
+ if(isset($fields_hide[$class])) foreach($table as $id => $row) {
+ foreach($fields_hide[$class] as $field) unset($table[$id][$field]);
+ }
+ }
+
function render_item_table($table,$class=false) {
+ if(empty($table)) return ''.T('holy primordial emptiness is all you can find here...').'
';
+ $this->table_add_row_parameters($table);
$this->table_add_images($table);
if($class) $this->table_add_relations($table,$class);
$this->table_add_barcodes($table);
$this->table_collapse($table);
+ if($class) $this->table_hide_columns($table,$class);
$this->table_sort($table);
return $this->table($table);
}
function render_insert_inputs($class,$columns,$selectbox,$current,$hidecols,$update) {
+ $textarea = array(
+ 'item' => array('item_note'),
+ 'model' => array('model_descript')
+ );
$html = '';
foreach($columns as $column) {
$html.=T($class).':'.T($column['Field']).': ';
@@ -376,13 +462,16 @@ EOF;
$val = $update && isset($current[$column['Field']]) ? $current[$column['Field']] : false;
switch(true) {
case (preg_match('/auto_increment/', $column['Extra']) || in_array($column['Field'], $hidecols)):
- if(!$val) $val = '';
+ if(is_bool($val) && !$val) $val = '';
$html.=$this->input($name, $val, 'hidden');
$html.=$val.'(AUTO)';
break;
case isset($selectbox[$column['Field']]):
$html.=$this->select($name,$selectbox[$column['Field']],$val);
break;
+ case isset($textarea[$class]) && in_array($column['Field'],$textarea[$class]):
+ $html.=$this->input($name, $val, 'textarea');
+ break;
default:
$html.=$this->input($name, $val);
break;
@@ -489,7 +578,7 @@ class Sklad_DB extends PDO {
'item' => array('model', 'category', 'producer', 'vendor', 'room', 'status'),
'model' => array('category', 'producer')
); //TODO Autodetect using foreign keys?
- $search_fields = array(
+ $fields_search = array(
'item' => array('item_id','item_serial','model_name','model_barcode','model_descript','producer_name','vendor_name'),
'model' => array('model_id','model_name','model_barcode','model_descript','producer_name')
); //TODO Autodetect
@@ -507,9 +596,9 @@ class Sklad_DB extends PDO {
//WHERE/REGEXP
if($search) {
$search = $this->quote($search);
- if(!isset($search_fields[$class])) die(trigger_error(T("Can't search in $class table yet :-("))); //TODO: post_redirect_get
+ if(!isset($fields_search[$class])) die(trigger_error(T("Can't search in $class table yet :-("))); //TODO: post_redirect_get
$sql_search = '';
- foreach($search_fields[$class] as $column) $sql_search .= "OR $column REGEXP $search ";
+ foreach($fields_search[$class] as $column) $sql_search .= "OR $column REGEXP $search ";
$where[] = "FALSE $sql_search";
} elseif($id) $where[] = "$class$suffix_id = $id";
if(!$history && $this->contains_history($class)) $where[] = $class.'_valid_till=0';
@@ -539,23 +628,33 @@ class Sklad_DB extends PDO {
return $result;
}
- function translate_query_results($result) {
- $translate_cols = array('status_name', 'item_valid_till'); //TODO: Hardcoded
+ function translate_query_results(&$result) {
+ $translate_cols = array('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,$suffix_backend='_backend') {
+ $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.$suffix_backend] = 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;
}
-
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);
$result = $this->safe_query_fetch($sql);
@@ -577,7 +676,9 @@ class Sklad_DB extends PDO {
function columns_get_selectbox($columns, $class=false, $suffix_id='_id', $suffix_name='_name') {
$selectbox=array( //TODO: Hardcoded...
- 'model_countable' => array(0 => 'no', 1 => 'yes')
+ 'model_countable' => array(0 => 'no', 1 => 'yes'),
+ 'model_eshop_hide' => array(0 => 'no', 1 => 'yes'),
+ 'vendor_id' => array('COMPULSORY' => 'select...')
);
foreach($columns as $column) {
if($column['Field'] == 'user_id') continue; //TODO HACK Blacklist: tabulka nemusi obsahovat *_name!!! momentalne se to tyka jen tabulky user (a item - u ty to nevadi)!
@@ -796,7 +897,7 @@ class Sklad_UI {
}
function check_auth() {
- new HTTP_Auth('SkladovejSystem', true, array($this->db->auth,'check_auth'));
+ new HTTP_Auth('WareHouse ['.BACKEND_AUTH.']', true, array($this->db->auth,'check_auth'));
}
function post_redirect_get($location, $message='', $error=false, $translate=true) {
@@ -827,7 +928,8 @@ class Sklad_UI {
function check_input_validity($field, $value='', $ruleset=0) {
$rules = array(0 => array(
'model_barcode' => '/./',
- 'item_serial' => '/./'
+ 'item_serial' => '/./',
+ 'vendor_id' => '/^[0-9]*$/'
));
if(isset($rules[$ruleset][$field]) && !preg_match($rules[$ruleset][$field], trim($value))) return false;
return true;
@@ -909,19 +1011,23 @@ class Sklad_UI {
$PATH_CHUNKS = preg_split('/\//', $PATH_INFO);
//Sephirot:
if(!isset($PATH_CHUNKS[1])) $PATH_CHUNKS[1]='';
- if($_SERVER['REQUEST_METHOD'] != 'POST' && $PATH_CHUNKS[1]!='barcode') //TODO: tyhle podminky naznacujou, ze je v navrhu nejaka drobna nedomyslenost...
+ if($_SERVER['REQUEST_METHOD'] != 'POST' && $PATH_CHUNKS[1]!='barcode' && $PATH_CHUNKS[1]!='api') //TODO: tyhle podminky naznacujou, ze je v navrhu nejaka drobna nedomyslenost...
echo $this->html->header($PATH_INFO,$this->db->auth->get_user());
switch($PATH_CHUNKS[1]) { //TODO: Move some branches to plugins if possible
case 'test': //test
die('Tell me why you cry');
break;
- case 'assistant': //assistant
+ case 'assistant': case 'api': //assistant|api
+ $incdirs = array(
+ 'assistant' => DIR_ASSISTANTS,
+ 'api' => DIR_APIS
+ );
$PATH_CHUNKS[3] = isset($PATH_CHUNKS[3]) ? trim($PATH_CHUNKS[3]) : false;
$assistant_vars['SUBPATH'] = array_slice($PATH_CHUNKS, 3);
$assistant_vars['URL_INTERNAL'] = 'assistant/'.$PATH_CHUNKS[2];
$assistant_vars['URL'] = $_SERVER['SCRIPT_NAME'].'/'.$assistant_vars['URL_INTERNAL'];
$assistant_vars['ASSISTANT'] = $PATH_CHUNKS[2];
- echo $this->safe_include(DIR_ASSISTANTS,$PATH_CHUNKS[2],$assistant_vars);
+ echo $this->safe_include($incdirs[$PATH_CHUNKS[1]],$PATH_CHUNKS[2],$assistant_vars);
break;
case 'barcode': //barcode
Barcode::download_barcode(implode('/',array_slice($PATH_CHUNKS, 2)));