X-Git-Url: https://git.harvie.cz/?a=blobdiff_plain;f=index.php;h=a019ae4b8b388520f6d28554e9323669037166dd;hb=ec106ddfe653ea6da6d65d537d38f19a9a7776e7;hp=d1d0942acba4f35bd998eb41a6884336ac481fc4;hpb=78bf26a53cfbad6b93122106f122e9e28171dbae;p=mirrors%2FSokoMan.git diff --git a/index.php b/index.php index d1d0942..a019ae4 100755 --- a/index.php +++ b/index.php @@ -18,71 +18,233 @@ */ require_once('sklad.conf.php'); +set_include_path(DIR_LIB.PATH_SEPARATOR.get_include_path()); + require_once('Sklad_LMS-fake.class.php'); require_once('HTTP_Auth.class.php'); +require_once('Locale.class.php'); +require_once('Barcode.class.php'); /** -* Trida poskytuje podpurne funkce pro generovani HTML kodu specificke pro sklad +* Trida poskytuje vseobecne funkce pro generovani HTML kodu * -* @package Sklad_HTML +* Tato trida by nemela sama nic vypisovat (vyjma chybovych a debugovacich hlasek)! +* +* @package HTML * @author Tomas Mudrunka */ -class Sklad_HTML { - function header_print($title='') { - $home = URL_HOME; - $script = $_SERVER['SCRIPT_NAME']; - $search = @trim($_GET['q']); - echo << - - -

SystémSklad$title

-
- -
  • Logout
  • -
  • Home
  • -
    -
    - - -
    - -
    -EOF; - } - - function row_print($row) { - echo(''); +class HTML { + function row($row) { + $html=''; foreach($row as $var) { if(trim($var) == '') $var = ' '; - echo("$var"); + $html.="$var"; } - echo(''); + $html.=''; + return $html; } - function table_print(&$table, $params='border=1') { - echo(""); + function table(&$table, $params='border=1') { + $html="
    "; $header=true; foreach($table as $row) { if($header) { - $this->row_print(array_keys($row)); + $html.=$this->row(array_keys($row)); $header=false; } - $this->row_print($row); + $html.=$this->row($row); } - echo('
    '); + $html.=''; + return $html; + } + + function link($title='n/a', $link='#void', $internal=true, $translate=true) { + if($internal && (!isset($link[0]) || $link[0] != '#')) $link = $this->internal_url($link); + if($translate) $title = T($title); + return "".$title.""; } - function link($title='n/a', $link='#void', $internal=true) { - if($internal) $link = $_SERVER['SCRIPT_NAME'].'/'.$link; - return "$title"; + function img($src='#void', $title='img', $options='width=64') { + $options = $options ? " $options" : ''; + return "$title"; + } + + function input($name=false, $value=false, $type='text', $placeholder=false, $options=false, $prefix='') { + $html = T($prefix)."'); print_r($selectbox); + $html = ""; + return $html; + } + + function ul($items,$tag=ul,$head='',$class=false) { + $class = $class ? " class='$class'" : ''; + $html = "$head<$tag$class>"; + foreach($items as $key => $value) { + $html .= '
  • '; + if(is_numeric($key)) { + $html .= $value; + } else { + $html .= $this->link($key,$value); + } + $html .= '
  • '; + } + $html .= ""; + return $html; + } + + function div($html, $options) { + $options = $options ? " $options" : ''; + return "$html"; + } + + function head($title=false,$charset='UTF-8',$more='') { + $title = $title ? "\n$title" : ''; + $html= ''; + $html.= ''.$title.$more; + $html.= ''; + return $html; + } +} + +/** +* Trida poskytuje podpurne funkce pro generovani HTML kodu specificke pro sklad +* +* Tato trida by nemela sama nic vypisovat (vyjma chybovych a debugovacich hlasek)! +* +* @package Sklad_HTML +* @author Tomas Mudrunka +*/ +class Sklad_HTML extends HTML { //TODO: Split into few more methods + function header($title='') { + $home = URL_HOME; + $script = $_SERVER['SCRIPT_NAME']; + $search = htmlspecialchars(@trim($_GET['q'])); + $message = strip_tags(@trim($_GET['message']),''); + $instance = INSTANCE_ID != '' ? '/'.INSTANCE_ID : ''; + //$title = T($title); //TODO + + $html = $this->head("SōkoMan$title"); + $html .= <<SōkoMan$instance$title + + + +
    +EOF; + + $assistants=array(); + foreach(scandir(DIR_ASSISTANTS) as $item) { + if($item == '.' || $item == '..') continue; + $item = preg_replace('/\.inc\.php$/','',$item); + $assistants[$item] = "assistant/$item"; + } + + $tables=array('item','model','category','producer','vendor','room','status'); + + foreach($tables as $table) { + $listable[$table] = $table; + $insertable[$table] = "$table/new"; + } + + $html .= $this->ul(array( + 'Home' => '', + 'Logout' => '?logout', + 0 => $this->ul($assistants,'menu',$this->link('Assistants','#')), + 1 => $this->ul($insertable,'menu',$this->link('New','#')), + 2 => $this->ul($listable,'menu',$this->link('List','#')) + ),'menu', '', 'menu'); + + $html .= '
    '; + + $html .= $this->form("$script/assistant/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 .= '
    '; + + $html .= << +
    +
    + $message +
    +EOF; + + return $html; } - function img($src='#void', $title='img') { - return "$title"; + function internal_url($link) { + return $_SERVER['SCRIPT_NAME'].'/'.$link; } function table_add_images(&$table) { @@ -96,6 +258,19 @@ EOF; } } + function render_barcode($barcode,$opts=false) { + return $this->link($this->img($this->internal_url("barcode/$barcode"),$barcode,$opts),"barcode/$barcode",true,false); + } + + function table_add_barcodes(&$table) { + $image = array('model_barcode', 'item_serial'); + foreach($table as $id => $row) { + foreach($image as $column) if(isset($table[$id][$column])) { + $table[$id][$column]=$this->render_barcode($table[$id][$column]); + } + } + } + function table_collapse(&$table) { $collapse = array( 'item_id' => 'item_id', @@ -108,7 +283,7 @@ EOF; ); foreach($table as $id => $row) { foreach($collapse as $link => $title) - if(isset($table[$id][$link])) { + 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].'/'); @@ -122,48 +297,24 @@ EOF; foreach($table as $id => $row) { $table_sorted[$id] = array(); foreach($precedence as $column) if(isset($table[$id][$column])) { - $table_sorted[$id][$column]=$table[$id][$column]; + $table_sorted[$id][T($column)]=$table[$id][$column]; unset($table[$id][$column]); } - $table_sorted[$id]=array_merge($table_sorted[$id],$table[$id]); + //$table_sorted[$id]=array_merge($table_sorted[$id],$table[$id]); + foreach($table[$id] as $key => $val) $table_sorted[$id][T($key)] = $val; //array_merge with T() translating } $table = $table_sorted; } - function print_item_table($table) { + function render_item_table($table) { $this->table_add_images($table); + $this->table_add_barcodes($table); $this->table_collapse($table); $this->table_sort($table); - return $this->table_print($table); + return $this->table($table); } - function input($name=false, $value=false, $type='text', $placeholder=false, $options=false) { - $html = "'); print_r($selectbox); - $html = ""; - return $html; - } - - function print_insert_form($class, $columns, $selectbox=array(), $current=false, $multi_insert=true) { + function render_insert_form($class, $columns, $selectbox=array(), $current=false, $hidecols=false, $action=false, $multi_insert=true) { //echo('
    '); print_r($selectbox);
     		//echo('
    '); print_r($current);
     		$update = false;
    @@ -172,33 +323,35 @@ EOF;
     			$current = array_shift($current);
     		}
     
    -		echo('
    '); - if($multi_insert) echo('
    '); - echo $this->input('table', $class, 'hidden'); + if(!is_array($hidecols)) $hidecols = array('item_author', 'item_valid_from', 'item_valid_till'); //TODO Autodetect + + $action = $action ? " action='$action'" : false; + $html=""; //TODO: use $this->form() + if($multi_insert) $html.='
    '; + //$html.=$this->input('table', $class, 'hidden'); foreach($columns as $column) { - echo($column['Field'].': '); - $name='value:'.$column['Field'].'[]'; + $html.=T($class).':'.T($column['Field']).': '; + $name="values[$class][".$column['Field'].'][]'; + $val = $update && isset($current[$column['Field']]) ? $current[$column['Field']] : false; switch(true) { - case preg_match('/auto_increment/', $column['Extra']): - $val = $update ? $current[$column['Field']] : ''; //opakuje se (skoro) zbytecne - echo $this->input($name, $val, 'hidden'); - echo($val.'(AUTO)'); + case (preg_match('/auto_increment/', $column['Extra']) || in_array($column['Field'], $hidecols)): + if(!$val) $val = ''; + $html.=$this->input($name, $val, 'hidden'); + $html.=$val.'(AUTO)'; break; case isset($selectbox[$column['Field']]): - $val = $update ? $current[$column['Field']] : false; - echo $this->select($name,$selectbox[$column['Field']],$val); //opakuje se + $html.=$this->select($name,$selectbox[$column['Field']],$val); break; default: - $val = $update ? $current[$column['Field']] : false; //opakuje se - echo $this->input($name, $val); + $html.=$this->input($name, $val); break; } - echo('
    '); + $html.='
    '; } if($multi_insert) { //TODO, move to separate JS file - echo <<