From 35916247a3b7ed49d0dc758ebdf76cf636763d2c Mon Sep 17 00:00:00 2001 From: Thomas Mudrunka Date: Tue, 23 Aug 2011 06:51:03 +0200 Subject: [PATCH] Komplet prepsano (a prelozeno) menu, Prohloubena abstrakce generovani HTML kodu --- assistants/dispose.inc.php | 10 +-- assistants/go.inc.php | 1 + assistants/sell.inc.php | 10 +-- assistants/stats.inc.php | 10 +-- assistants/store.inc.php | 10 +-- index.php | 152 +++++++++++++++++++++---------------- lib/Locale.class.php | 6 ++ locale/cs/messages.inc.php | 25 ++++-- 8 files changed, 130 insertions(+), 94 deletions(-) diff --git a/assistants/dispose.inc.php b/assistants/dispose.inc.php index 691b258..fcaf7f2 100644 --- a/assistants/dispose.inc.php +++ b/assistants/dispose.inc.php @@ -1,12 +1,10 @@ -
- item_serial: - -
-html->form("$URL/2", 'GET', array( + array('serial','','text',false,'autofocus','item_serial:'), + array(false,'DISPOSE','submit') + )); break; case 2: $item_id = $this->db->map_unique('item_serial', $_GET['serial'], 'item_id', 'item'); diff --git a/assistants/go.inc.php b/assistants/go.inc.php index d488e5e..a052101 100644 --- a/assistants/go.inc.php +++ b/assistants/go.inc.php @@ -1,4 +1,5 @@ post_redirect_get('',"This assistant shouldn't be used like this"); $id=$_GET['q']; $barcode_prefix_regexp = '/^'.preg_replace('/\//', '\/', BARCODE_PREFIX).'/'; if(preg_match($barcode_prefix_regexp, $id)) $id=preg_replace($barcode_prefix_regexp, '', $id); diff --git a/assistants/sell.inc.php b/assistants/sell.inc.php index af7ef8b..4bdfbfd 100644 --- a/assistants/sell.inc.php +++ b/assistants/sell.inc.php @@ -5,12 +5,10 @@ //TODO: Reuse /item/$item_id/edit switch($SUBPATH[0]) { default: case 1: -?> -
- item_serial: - -
-html->form("$URL/2", 'GET', array( + array('serial','','text',false,'autofocus','item_serial:'), + array(false,'SELL','submit') + )); break; case 2: $item_id = $this->db->map_unique('item_serial', $_GET['serial'], 'item_id', 'item'); diff --git a/assistants/stats.inc.php b/assistants/stats.inc.php index e353128..6ccfb9f 100644 --- a/assistants/stats.inc.php +++ b/assistants/stats.inc.php @@ -5,13 +5,11 @@ if(isset($_GET['month'])) { $month = htmlspecialchars($_GET['month']); $month_sql = " AND DATE_FORMAT(item_valid_from, '%Y-%m') = ".$this->db->quote($_GET['month']); } -?> -
- YYYY-MM: - -
-html->form($URL, 'GET', array( + array('month',$month,'text',false,'autofocus','YYYY-MM:'), + array(false,'SELECT BY MONTH','submit') +)); if($month_sql == '') $month=''; $queries = array( //TODO: use build_query_select()!!! diff --git a/assistants/store.inc.php b/assistants/store.inc.php index 3e05919..cacee8f 100644 --- a/assistants/store.inc.php +++ b/assistants/store.inc.php @@ -1,12 +1,10 @@ -
- model_barcode: - -
-html->form("$URL/2", 'GET', array( + array('barcode','','text',false,'autofocus','model_barcode:'), + array(false,'STORE','submit') + )); break; case 2: $model_id = $this->db->map_unique('model_barcode', $_GET['barcode'], 'model_id', 'model'); diff --git a/index.php b/index.php index 9fd766b..ec062fa 100755 --- a/index.php +++ b/index.php @@ -58,7 +58,7 @@ class HTML { } function link($title='n/a', $link='#void', $internal=true) { - if($internal) $link = $this->internal_url($link); + if($internal && (!isset($link[0]) || $link[0] != '#')) $link = $this->internal_url($link); return "".T($title).""; } @@ -66,8 +66,8 @@ class HTML { return "$title"; } - function input($name=false, $value=false, $type='text', $placeholder=false, $options=false) { - $html = "'); 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"; + } } /** @@ -104,14 +135,15 @@ class HTML { * @package Sklad_HTML * @author Tomas Mudrunka */ -class Sklad_HTML extends HTML { +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 : ''; - return << SōkoMan$title @@ -153,63 +185,53 @@ class Sklad_HTML extends HTML {
    - -
  • Logout
  • -
  • Home
  • -
  • Assistants - -
  • stats
  • -
  • store
  • -
  • store-single
  • -
  • dispose
  • -
  • sell
  • -
  • ↓↓ BETA ↓↓
  • -
    -
  • -
  • List - -
  • item
  • -
  • model
  • -
  • category
  • -
  • producer
  • -
  • vendor
  • -
  • room
  • -
  • status
  • -
    -
  • -
  • New - -
  • item
  • -
  • model
  • -
  • category
  • -
  • producer
  • -
  • vendor
  • -
  • room
  • -
  • status
  • -
    -
  • -
    - -
    -
    - - -
    -
    - - -
    - -
    +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( + 'Logout' => '?logout', + 'Home' => '', + 0 => $this->ul($assistants,'menu',$this->link('Assistants','#')), + 1 => $this->ul($listable,'menu',$this->link('List','#')), + 2 => $this->ul($insertable,'menu',$this->link('New','#')) + ),'menu', '', 'menu'); + + $html .= '
    '; + + $html .= $this->form("$script/assistant/go", 'GET', array( + array('q','','text','smart id...'), + 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 internal_url($link) { @@ -281,7 +303,7 @@ EOF; if(!is_array($hidecols)) $hidecols = array('item_author', 'item_valid_from', 'item_valid_till'); //TODO Autodetect $action = $action ? " action='$action'" : false; - $html=""; + $html=""; //TODO: use $this->form() if($multi_insert) $html.='
    '; //$html.=$this->input('table', $class, 'hidden'); foreach($columns as $column) { @@ -635,15 +657,15 @@ class Sklad_UI { if($edit) { $html.= $this->render_form_edit($class, $id); $action = $_SERVER['SCRIPT_NAME']."/$class/$id/delete"; - $html.= "
    "; - $html.= $this->html->input(false, 'DELETE', 'submit'); - $html.= T('sure?').$this->html->input('sure', false, 'checkbox'); - $html.= '
    '; + $html.=$this->html->form($action,'POST',array( + array(false,'DELETE','submit'), + array('sure', false, 'checkbox', false, false, 'sure?') + )); $action = $_SERVER['SCRIPT_NAME']."/$class/$id/image"; - $html.= "
    "; - $html.= $this->html->input('image', false, 'file', false, 'size="30"'); - $html.= $this->html->input(false, 'IMAGE', 'submit'); - $html.='
    '; + $html.=$this->html->form($action,'POST',array( + array('image', false, 'file', false, 'size="30"'), + array(false, 'IMAGE', 'submit') + ), "enctype='multipart/form-data'"); } return $html; } diff --git a/lib/Locale.class.php b/lib/Locale.class.php index a8c3d97..169fd04 100755 --- a/lib/Locale.class.php +++ b/lib/Locale.class.php @@ -19,11 +19,17 @@ require_once(DIR_LOCALE.'/'.LOCALE_LANG.'/messages.inc.php'); +//Wrap regexes with slashes foreach($LOCALE_MESSAGES['regexp'] as $regexp => $replace) { $LOCALE_MESSAGES['regexp']['/'.$regexp.'/i'] = $LOCALE_MESSAGES['regexp'][$regexp]; unset($LOCALE_MESSAGES['regexp'][$regexp]); } +//Uppercase alternative +/*$LOCALE_MESSAGES['map'] = array_merge($LOCALE_MESSAGES['map'], + array_flip(array_map('strtoupper',array_flip(array_map('strtoupper',$LOCALE_MESSAGES['map'])))) +);*/ + /** * !!! IMPORTANT NOTICE: This is ugly hack !!! * !!! You should rather use PHP's internal gettext support !!! diff --git a/locale/cs/messages.inc.php b/locale/cs/messages.inc.php index aa4b516..679f450 100644 --- a/locale/cs/messages.inc.php +++ b/locale/cs/messages.inc.php @@ -25,6 +25,7 @@ $LOCALE_MESSAGES = array( 'model_name' => 'Model', 'model_descript' => 'Popis modelu', 'model_barcode' => 'Čárový kód modelu', + 'model_barcode:' => 'Čárový kód modelu:', 'model_price_out' => 'Doporučená cena', 'room_name' => 'Sklad', @@ -44,7 +45,7 @@ $LOCALE_MESSAGES = array( 'producer' => '[výrobce]', 'room' => '[sklad]', 'status' => '[stav]', - 'vendor' => '[výrobce]', + 'vendor' => '[prodejce]', 'category' => '[kategorie]', 'model' => '[model]', 'user' => '[uživatel]', @@ -60,17 +61,31 @@ $LOCALE_MESSAGES = array( 'SUM(' => 'SOUČET(', 'COUNT(' => 'POČET(', + 'Assistants' => 'Průvodci', + 'dispose' => 'vyskladnit', + 'sell' => 'prodat', + 'stats' => 'statistiky', + 'store' => 'naskladnit', + 'store-single' => 'naskladnit 1ks', + 'update' => 'UPRAVIT', 'insert' => 'VLOŽIT', 'delete' => 'SMAZAT', 'image' => 'OBRÁZEK', - //'filter' => 'filtr', + 'SELECT BY MONTH' => 'ZOBRAZIT MĚSÍC', + 'DISPOSE' => 'VYSKLADNIT', + 'SELL' => 'PRODAT', + 'STORE' => 'NASKLADNIT', + 'filter' => 'filtr', //'go' => 'jdi', 'sure?' => 'opravdu?', + 'Logout' => 'Odhlásit', + 'Home' => 'Domů', - 'edit' => 'upravit', - 'history' => 'historie', - 'new' => 'nový', + 'edit' => 'Upravit', + 'history' => 'Historie', + 'new' => 'Přidat', + 'List' => 'Vypsat', '' => '' ), -- 2.30.2