+ 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 "<a href='$link'>".$title."</a>";
+ }
+
+ function img($src='#void', $title='img', $options='width=64') {
+ $options = $options ? " $options" : '';
+ return "<img src='$src' alt='$title' title='$title'$options; />";
+ }
+
+ function input($name=false, $value=false, $type='text', $placeholder=false, $options=false, $prefix='') {
+ $html = T($prefix)."<input type='$type' ";
+ if($name) $html.= "name='$name' ";
+ if(!is_bool($value)) {
+ if($type == 'submit') $value = T($value);
+ $html.= "value='$value' ";
+ }
+ if($options) $html.= "$options ";
+ if($placeholder) $html.= "placeholder='$placeholder' ";
+ $html .= '/>';
+ return $html;
+ }
+
+ function form($action=false, $method=false, $inputs, $options=false) {
+ $action = $action ? " action='$action'" : '';
+ $method = $method ? " method='$method'" : '';
+ $options = $options ? " $options" : '';
+ $html = "<form$action$method$options>";
+ foreach($inputs as $input) $html .= call_user_func_array(array($this,'input'), $input);
+ $html .= "</form>";
+ return $html;
+ }
+
+ function select($name, $selectbox, $default=false) {
+ //echo('<pre>'); print_r($selectbox);
+ $html = "<select name='$name'>";
+
+ if($default) {
+ $value=$default; $title=$selectbox[$value];
+ $html .= "<option value='$value'>$value :: $title</option>";
+ unset($selectbox[$value]);
+ }
+ foreach($selectbox as $value => $title) {
+ $html .= "<option value='$value'>$value :: $title</option>";
+ }
+ $html .= "</select>";
+ return $html;
+ }
+
+ function ul($items,$tag=ul,$head='',$class=false) {
+ $class = $class ? " class='$class'" : '';
+ $html = "$head<$tag$class>";
+ foreach($items as $key => $value) {
+ $html .= '<li>';
+ if(is_numeric($key)) {
+ $html .= $value;
+ } else {
+ $html .= $this->link($key,$value);
+ }
+ $html .= '</li>';
+ }
+ $html .= "</$tag>";
+ return $html;
+ }
+
+ function div($html, $options) {
+ $options = $options ? " $options" : '';
+ return "<div$options>$html</div>";
+ }
+
+ function head($title=false,$charset='UTF-8',$more='') {
+ $title = $title ? "\n<title>$title</title>" : '';
+ $html= '<head>';
+ $html.= '<meta http-equiv="Content-Type" content="text/html; charset='.$charset.'" />'.$title.$more;
+ $html.= '</head>';
+ 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']),'<a><b><u><i>');
+ $instance = INSTANCE_ID != '' ? '/'.INSTANCE_ID : '';
+ //$title = T($title); //TODO
+
+ $html = $this->head("SōkoMan$title");
+ $html .= <<<EOF
+<h1><a href="$script/">SōkoMan</a><small>$instance$title</small></h1>
+
+<style type="text/css">
+* { font-family: arial; }
+
+.menu li {
+ float: left;
+ padding: 0.2em;
+}
+
+.menu * li {
+ float: none;
+}
+
+.menu * menu {
+ position: absolute;
+ padding: 0.2em;
+}
+
+.menu, .menu * menu {
+ list-style: none;
+}
+
+.menu * menu {
+ border: 1px solid orange;
+ display: none;
+ margin: 0;
+}
+
+.menu li:hover menu, .menu li:hover {
+ display: block;
+ background-color: yellow;
+}
+
+</style>
+
+<div>
+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 .= '<div style="float: right;">';
+
+ $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 .= '</div>';
+
+ $html .= <<<EOF
+</div>
+<hr style="clear: both;" />
+<div style="background-color:#FFDDDD;">
+ <font color="red">$message</font>
+</div>
+EOF;
+
+ return $html;