+require_once('Locale.class.php');
+require_once('Barcode.class.php');
+require_once('Fortune.php');
+
+/**
+* Trida poskytuje vseobecne funkce pro generovani HTML kodu
+*
+* Tato trida by nemela sama nic vypisovat (vyjma chybovych a debugovacich hlasek)!
+*
+* @package HTML
+* @author Tomas Mudrunka
+*/
+class HTML {
+ function row($row,$type=false,$class=false,$parameters='') {
+ $html = '';
+ $class = $class ? $class=" class='$class' " : '';
+ if($type) $html.="<$type>";
+ $html.="<tr$class$parameters>";
+ $td = $type == 'thead' ? 'th' : 'td';
+ foreach($row as $var) {
+ if(trim($var) == '') $var = ' ';
+ $html.="<$td>$var</$td>";
+ }
+ $html.='</tr>';
+ if($type) $html.="</$type>";
+ return $html;
+ }
+
+ function table(&$table, $parity_class=array('tr_odd','tr_even'), $params='border=1', $row_params_field='_row_parameters') {
+ $html="<table $params>";
+ $header=true;
+ $even=false;
+ foreach($table as $row) {
+ $params = isset($row[$row_params_field]) ? $row[$row_params_field] : '';
+ unset($row[$row_params_field]);
+ if($header) {
+ $html.=$this->row(array_keys($row),'thead');
+ $header=false;
+ }
+ $class = $parity_class ? $parity_class[$even] : false;
+ $html.=$this->row($row,false,$class.$params);
+ $even = !$even;
+ }
+ $html.='</table>';
+ 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 "<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 img_link($src, $link='#void', $title='img_link', $internal=true, $translate=true, $options='width=64') {
+ return $this->link($this->img($src,$title,$options),$link,$internal,$translate);
+ }
+
+ function textarea($name=false, $value='', $placeholder=false, $options=false, $prefix='') {
+ $html = T($prefix)."<textarea";
+ if($name) $html.= " name='$name'";
+ if($options) $html.= " $options";
+ if($placeholder) $html.= " placeholder='$placeholder'";
+ $html .= ">$value</textarea>";
+ return $html;
+ }
+
+ function input($name=false, $value=false, $type='text', $placeholder=false, $options=false, $prefix='') {
+ if($type == 'textarea') return $this->textarea($name, $value, $placeholder, $options, $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(!is_bool($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 favicon($url='/favicon.ico') {
+ return '<link rel="shortcut icon" href="'.$url.'" /><link href="'.$url.'" rel="icon" type="image/gif" />';
+
+ }
+
+ 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.= $this->favicon(dirname($_SERVER['SCRIPT_NAME']).'/favicon.ico');
+ $html.= '</head>';
+ return $html;
+ }
+}