Pokus o vyreseni tabulky co ujizdi pri nacitani obrazku
[mirrors/SokoMan.git] / index.php
CommitLineData
cdfce7c2
TM
1<?php
2/*
3 * SkladovySystem - Storage management system compatible with LMS
78bf26a5 4 * Copyright (C) 2011 Tomas Mudrunka
cdfce7c2
TM
5 *
6 * This program is free software: you can redistribute it and/or modify
7 * it under the terms of the GNU Affero General Public License as
8 * published by the Free Software Foundation, either version 3 of the
9 * License, or (at your option) any later version.
10 *
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU Affero General Public License for more details.
15 *
16 * You should have received a copy of the GNU Affero General Public License
17 * along with this program. If not, see <http://www.gnu.org/licenses/>.
18 */
19
20require_once('sklad.conf.php');
5f093236
TM
21set_include_path(DIR_LIB.PATH_SEPARATOR.get_include_path());
22
63747dad 23require_once('Sklad_Auth.class/common.php');
cdfce7c2 24require_once('HTTP_Auth.class.php');
326a9fc9 25require_once('Locale.class.php');
81ab8aef 26require_once('Barcode.class.php');
958f1e84 27require_once('Fortune.php');
cdfce7c2 28
0a027cc7
TM
29/**
30* Trida poskytuje vseobecne funkce pro generovani HTML kodu
31*
32* Tato trida by nemela sama nic vypisovat (vyjma chybovych a debugovacich hlasek)!
33*
34* @package HTML
35* @author Tomas Mudrunka
36*/
37class HTML {
7df1effb 38 function row($row,$type=false,$class=false,$parameters='') {
933b760a 39 $html = '';
1b9304b8 40 $class = $class ? $class=" class='$class' " : '';
933b760a 41 if($type) $html.="<$type>";
7df1effb 42 $html.="<tr$class$parameters>";
933b760a 43 $td = $type == 'thead' ? 'th' : 'td';
842cb193
TM
44 foreach($row as $id => $var) {
45 $tdclass = " class='cell_$id'";
0a027cc7 46 if(trim($var) == '') $var = '&nbsp;';
842cb193 47 $html.="<$td$tdclass>$var</$td>";
0a027cc7
TM
48 }
49 $html.='</tr>';
933b760a 50 if($type) $html.="</$type>";
0a027cc7
TM
51 return $html;
52 }
53
7df1effb 54 function table(&$table, $parity_class=array('tr_odd','tr_even'), $params='border=1', $row_params_field='_row_parameters') {
0a027cc7
TM
55 $html="<table $params>";
56 $header=true;
1b9304b8 57 $even=false;
0a027cc7 58 foreach($table as $row) {
03e3ff25
TM
59 $params = isset($row[$row_params_field]) ? $row[$row_params_field] : '';
60 unset($row[$row_params_field]);
0a027cc7 61 if($header) {
842cb193 62 $html.=$this->row(T(array_keys($row)),'thead');
0a027cc7
TM
63 $header=false;
64 }
1b9304b8 65 $class = $parity_class ? $parity_class[$even] : false;
7df1effb 66 $html.=$this->row($row,false,$class.$params);
1b9304b8 67 $even = !$even;
0a027cc7
TM
68 }
69 $html.='</table>';
70 return $html;
71 }
72
81ab8aef 73 function link($title='n/a', $link='#void', $internal=true, $translate=true) {
35916247 74 if($internal && (!isset($link[0]) || $link[0] != '#')) $link = $this->internal_url($link);
81ab8aef
TM
75 if($translate) $title = T($title);
76 return "<a href='$link'>".$title."</a>";
0a027cc7
TM
77 }
78
32e14fd3 79 function img($src='#void', $title='img', $options='height=64') {
81ab8aef
TM
80 $options = $options ? " $options" : '';
81 return "<img src='$src' alt='$title' title='$title'$options; />";
0a027cc7
TM
82 }
83
32e14fd3 84 function img_link($src, $link='#void', $title='img_link', $internal=true, $translate=true, $options='height=64') {
6f7943a0
TM
85 return $this->link($this->img($src,$title,$options),$link,$internal,$translate);
86 }
87
0f7fe034
TM
88 function textarea($name=false, $value='', $placeholder=false, $options=false, $prefix='') {
89 $html = T($prefix)."<textarea";
90 if($name) $html.= " name='$name'";
91 if($options) $html.= " $options";
92 if($placeholder) $html.= " placeholder='$placeholder'";
93 $html .= ">$value</textarea>";
94 return $html;
95 }
96
35916247 97 function input($name=false, $value=false, $type='text', $placeholder=false, $options=false, $prefix='') {
120e3b45 98 if($type == 'textarea') return $this->textarea($name, $value, $placeholder, $options, $prefix);
35916247 99 $html = T($prefix)."<input type='$type' ";
0a027cc7 100 if($name) $html.= "name='$name' ";
326a9fc9
TM
101 if(!is_bool($value)) {
102 if($type == 'submit') $value = T($value);
103 $html.= "value='$value' ";
104 }
0a027cc7
TM
105 if($options) $html.= "$options ";
106 if($placeholder) $html.= "placeholder='$placeholder' ";
107 $html .= '/>';
108 return $html;
109 }
110
35916247
TM
111 function form($action=false, $method=false, $inputs, $options=false) {
112 $action = $action ? " action='$action'" : '';
113 $method = $method ? " method='$method'" : '';
114 $options = $options ? " $options" : '';
115 $html = "<form$action$method$options>";
116 foreach($inputs as $input) $html .= call_user_func_array(array($this,'input'), $input);
117 $html .= "</form>";
118 return $html;
119 }
120
0a027cc7
TM
121 function select($name, $selectbox, $default=false) {
122 //echo('<pre>'); print_r($selectbox);
123 $html = "<select name='$name'>";
124
90638f10 125 if(!is_bool($default)) {
0a027cc7
TM
126 $value=$default; $title=$selectbox[$value];
127 $html .= "<option value='$value'>$value :: $title</option>";
128 unset($selectbox[$value]);
129 }
130 foreach($selectbox as $value => $title) {
131 $html .= "<option value='$value'>$value :: $title</option>";
132 }
133 $html .= "</select>";
134 return $html;
135 }
35916247
TM
136
137 function ul($items,$tag=ul,$head='',$class=false) {
138 $class = $class ? " class='$class'" : '';
139 $html = "$head<$tag$class>";
140 foreach($items as $key => $value) {
141 $html .= '<li>';
142 if(is_numeric($key)) {
143 $html .= $value;
144 } else {
145 $html .= $this->link($key,$value);
146 }
147 $html .= '</li>';
148 }
149 $html .= "</$tag>";
150 return $html;
151 }
152
153 function div($html, $options) {
154 $options = $options ? " $options" : '';
155 return "<div$options>$html</div>";
156 }
ec106ddf 157
25b3e809
TM
158 function favicon($url='/favicon.ico') {
159 return '<link rel="shortcut icon" href="'.$url.'" /><link href="'.$url.'" rel="icon" type="image/gif" />';
160
161 }
162
ec106ddf
TM
163 function head($title=false,$charset='UTF-8',$more='') {
164 $title = $title ? "\n<title>$title</title>" : '';
165 $html= '<head>';
166 $html.= '<meta http-equiv="Content-Type" content="text/html; charset='.$charset.'" />'.$title.$more;
25b3e809 167 $html.= $this->favicon(dirname($_SERVER['SCRIPT_NAME']).'/favicon.ico');
ec106ddf
TM
168 $html.= '</head>';
169 return $html;
170 }
0a027cc7
TM
171}
172
78bf26a5
TM
173/**
174* Trida poskytuje podpurne funkce pro generovani HTML kodu specificke pro sklad
175*
fc5c5b8b
TM
176* Tato trida by nemela sama nic vypisovat (vyjma chybovych a debugovacich hlasek)!
177*
78bf26a5
TM
178* @package Sklad_HTML
179* @author Tomas Mudrunka
180*/
35916247 181class Sklad_HTML extends HTML { //TODO: Split into few more methods
e9f6461f 182 function header($title='', $user=array()) {
cdfce7c2
TM
183 $home = URL_HOME;
184 $script = $_SERVER['SCRIPT_NAME'];
d9384cb5 185 $search = htmlspecialchars(@trim($_GET['q']));
a8bbdc31 186 $message = strip_tags(@trim($_GET['message']),'<a><b><u><i><br>');
958f1e84 187 $fortune = fortune();
ac2ed3a1 188 $instance = INSTANCE_ID != '' ? '/'.INSTANCE_ID : '';
e9f6461f
TM
189 $user_id = htmlspecialchars($user['id']);
190 $user_gid = htmlspecialchars($user['gid']);
191 $user_name = htmlspecialchars($user['name']);
40eef626 192 $time = date('r');
35916247 193 //$title = T($title); //TODO
ec106ddf
TM
194
195 $html = $this->head("SōkoMan$title");
196 $html .= <<<EOF
6d98215b 197<h1 style="display: inline;"><a href="$script/">SōkoMan</a><small>$instance$title</small></h1>
40eef626
TM
198<div style="float:right; text-align:right;">
199 Logged in as <b>$user_name</b> [UID: <b>$user_id</b>; GID: <b>$user_gid</b>]<br />
200 Page loaded at $time
201</div>
c9759229
TM
202
203<style type="text/css">
ac2ed3a1 204* { font-family: arial; }
933b760a
TM
205td,body { background-color: white; }
206table { background-color: orange; border: orange; }
d0e7939c 207a, a img { text-decoration:none; color: darkblue; border:none; }
933b760a 208li a, a:hover { text-decoration:underline; }
1b9304b8 209.tr_even td { background-color: lemonchiffon; }
7df1effb 210.item_status_stored td { font-weight:bold; }
80457ef3
TM
211.item_status_deleted td { text-decoration:line-through; }
212.item_status_destroyed td { font-style:italic; }
842cb193
TM
213/* table, table * { table-layout:fixed; width:100%; overflow:hidden; word-wrap:break-word; } */
214/* td { position:absolute; } */
32e14fd3 215.cell_model_name { }
842cb193 216
ac2ed3a1 217
7bcd6b42 218.menu li {
c9759229 219 float: left;
7bcd6b42
TM
220 padding: 0.2em;
221}
222
223.menu * li {
224 float: none;
c9759229
TM
225}
226
227.menu * menu {
228 position: absolute;
7bcd6b42 229 padding: 0.2em;
c9759229
TM
230}
231
232.menu, .menu * menu {
233 list-style: none;
234}
235
236.menu * menu {
7bcd6b42 237 border: 1px solid orange;
c9759229
TM
238 display: none;
239 margin: 0;
240}
241
7bcd6b42 242.menu li:hover menu, .menu li:hover {
c9759229 243 display: block;
7bcd6b42 244 background-color: yellow;
c9759229 245}
7bcd6b42 246
c9759229
TM
247</style>
248
cdfce7c2 249<div>
35916247
TM
250EOF;
251
252 $assistants=array();
253 foreach(scandir(DIR_ASSISTANTS) as $item) {
254 if($item == '.' || $item == '..') continue;
de42ea13
TM
255 $item = preg_replace('/\.inc\.php$/','',$item,-1,$count);
256 if($count) $assistants[$item] = "assistant/$item";
35916247
TM
257 }
258
259 $tables=array('item','model','category','producer','vendor','room','status');
260
261 foreach($tables as $table) {
262 $listable[$table] = $table;
263 $insertable[$table] = "$table/new";
264 }
265
266 $html .= $this->ul(array(
35916247 267 'Home' => '',
ec106ddf 268 'Logout' => '?logout',
35916247 269 0 => $this->ul($assistants,'menu',$this->link('Assistants','#')),
ec106ddf
TM
270 1 => $this->ul($insertable,'menu',$this->link('New','#')),
271 2 => $this->ul($listable,'menu',$this->link('List','#'))
35916247
TM
272 ),'menu', '', 'menu');
273
274 $html .= '<div style="float: right;">';
275
bf9a965c
TM
276 /*
277 //TODO: Do we really need this?
88c38b26 278 $html .= $this->form("$script/api/go", 'GET', array(
81ab8aef 279 array('q','','text','smart id...', 'autofocus'),
35916247
TM
280 array(false,'go','submit')
281 ), 'style="float: left;"');
bf9a965c 282 */
35916247
TM
283
284 $html .= $this->form('?', 'GET', array(
285 array('q',$search,'text','regexp...'),
286 array(false,'filter','submit')
287 ), 'style="float: left;"');
288
bf9a965c
TM
289 $html .= $this->form("$script/item", 'GET', array(
290 array('q',$search,'text','regexp...','autofocus'),
291 array(false,'search','submit')
292 ), 'style="float: left;"');
293
35916247
TM
294 $html .= '</div>';
295
296 $html .= <<<EOF
cdfce7c2 297</div>
c9759229 298<hr style="clear: both;" />
d9384cb5
TM
299<div style="background-color:#FFDDDD;">
300 <font color="red">$message</font>
301</div>
958f1e84 302<div style="text-align:right; color:darkgreen;">
41e57f9e
TM
303$fortune
304</div>
cdfce7c2 305EOF;
35916247
TM
306
307 return $html;
cdfce7c2
TM
308 }
309
d9384cb5
TM
310 function internal_url($link) {
311 return $_SERVER['SCRIPT_NAME'].'/'.$link;
312 }
313
cdfce7c2
TM
314 function table_add_images(&$table) {
315 $image = array('model_id');
316 foreach($table as $id => $row) {
317 foreach($image as $column) if(isset($table[$id][$column])) {
318 $type = @array_shift(preg_split('/_/', $column));
319 $src=URL_IMAGES."/$type/".$table[$id][$column].'.jpg';
6f7943a0 320 $table[$id][$type.'_image']=$this->img_link($src, $src, $table[$id][$column], false, false);
cdfce7c2
TM
321 }
322 }
323 }
324
81ab8aef 325 function render_barcode($barcode,$opts=false) {
6f7943a0 326 return $this->img_link($this->internal_url("barcode/$barcode"),$this->internal_url("barcode/$barcode"),$barcode,false,false,$opts);
81ab8aef
TM
327 }
328
329 function table_add_barcodes(&$table) {
330 $image = array('model_barcode', 'item_serial');
331 foreach($table as $id => $row) {
332 foreach($image as $column) if(isset($table[$id][$column])) {
333 $table[$id][$column]=$this->render_barcode($table[$id][$column]);
334 }
335 }
336 }
337
7df1effb
TM
338 function table_add_row_parameters(&$table, $param_col='_row_parameters') { //TODO: rename to table_add_row_classes()
339 $image = array('status_name' => ' item_status_');
340 foreach($table as $id => $row) {
341 foreach($image as $column => $param) if(isset($table[$id][$column])) {
342 @$table[$id][$param_col] .= $param.$table[$id][$column];
343 }
344 }
345 }
346
d6975011 347 function table_add_relations(&$table, $class, $suffix_relations='_relations') {
aaafc8b7 348 $where_url = '%d/?where[%c]==%v';
d6975011 349 $relations = array( //TODO: Autodetect???
aaafc8b7 350 'model' => array(
9c310625 351 'model_id' => array(array('item',$where_url),array('edit','model/%v/edit/')),
d516a31d 352 'model_barcode' => array(array('store','assistant/%d?barcode=%v')),
41e57f9e 353 'model_name' => array(array('google','http://google.com/search?q=%v',true)) //TODO: add manufacturer to google query
aaafc8b7 354 ),
4ece8e80 355 'item' => array(
d1686e10 356 'item_serial' => array(array('dispose','assistant/%d?serial=%v','in_stock'),array('sell','assistant/%d?serial=%v','in_stock')),
6265a8d4 357 'item_id' => array(array('edit','item/%v/edit/'))
4ece8e80 358 ),
d7d9ce39 359 'category' => array('category_id' => array(array('item',$where_url), array('model',$where_url))),
0646d9ef 360 'producer' => array('producer_id' => array(array('item',$where_url), array('model',$where_url))),
aaafc8b7
TM
361 'vendor' => array('vendor_id' => array(array('item',$where_url))),
362 'room' => array('room_id' => array(array('item',$where_url))),
363 'status' => array('status_id' => array(array('item',$where_url)))
d6975011 364 );
6265a8d4 365 $relations_conditions=array(
d1686e10
TM
366 'in_stock' => 'return(@$table[$id]["status_name"] == "stored");',
367 'not_sold' => 'return(@$table[$id]["status_name"] != "saled");',
368 'not_sold_or_disposed' => 'return(@$table[$id]["status_name"] != "saled" && @$table[$id]["status_name"] != "disposed");'
6265a8d4 369 );
d6975011
TM
370 foreach($table as $id => $row) {
371 foreach($row as $column => $value) {
372 if(isset($relations[$class][$column])) {
373 foreach($relations[$class][$column] as $destination) {
aaafc8b7
TM
374 $destination_url = str_replace(
375 array('%d','%c','%v'),
d516a31d 376 array(urlencode($destination[0]),urlencode($column),urlencode($value)),
aaafc8b7
TM
377 $destination[1]
378 );
9c310625 379 if(isset($destination[2]) && isset($relations_conditions[$destination[2]])) {
e9482e8a
TM
380 //$condition = $relations_conditions[$destination[2]]($table,$id);
381 if(!eval($relations_conditions[$destination[2]])) continue;
6265a8d4 382 }
2195f218 383 @$table[$id][$class.$suffix_relations] .= $this->link($destination[0], $destination_url).',';
d6975011
TM
384 }
385 }
386 }
387 }
388 }
389
cdfce7c2
TM
390 function table_collapse(&$table) {
391 $collapse = array(
392 'item_id' => 'item_id',
393 'model_id' => 'model_name',
394 'category_id' => 'category_name',
395 'producer_id' => 'producer_name',
396 'vendor_id' => 'vendor_name',
397 'room_id' => 'room_name',
398 'status_id' => 'status_name',
d7d9ce39 399 'item_author' => 'item_author_backend',
a278a425 400 'item_customer' => 'item_customer',
cdfce7c2 401 );
d7d9ce39 402
cdfce7c2
TM
403 foreach($table as $id => $row) {
404 foreach($collapse as $link => $title)
fff6ce40 405 if(isset($table[$id][$link]) && isset($row[$title])) {
cdfce7c2
TM
406 $type = @array_shift(preg_split('/_/', $link));
407 if($link != $title) unset($table[$id][$link]);
d7d9ce39
TM
408 switch($link) { //TODO: Move to array for easy configuration
409 case 'item_author':
a278a425
TM
410 case 'item_customer':
411 $table[$id][$title]=$this->link($row[$title], "?where[$link]==".$row[$link], false);
d7d9ce39
TM
412 break;
413 default:
414 $table[$id][$title]=$this->link($row[$title], $type.'/'.$row[$link].'/');
415 break;
416 }
cdfce7c2
TM
417 }
418 }
419 }
420
421 function table_sort(&$table) {
9c310625 422 $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');
cdfce7c2
TM
423 $table_sorted = array();
424 foreach($table as $id => $row) {
425 $table_sorted[$id] = array();
426 foreach($precedence as $column) if(isset($table[$id][$column])) {
842cb193 427 $table_sorted[$id][$column]=$table[$id][$column];
cdfce7c2
TM
428 unset($table[$id][$column]);
429 }
842cb193
TM
430 $table_sorted[$id]=array_merge($table_sorted[$id],$table[$id]);
431 //foreach($table[$id] as $key => $val) $table_sorted[$id][T($key)] = $val; //array_merge with T() translating
cdfce7c2
TM
432 }
433 $table = $table_sorted;
434 }
435
ecaeb1d6
TM
436 function table_hide_columns(&$table, $class) { //TODO: Move to build_query_select() !!! :-)))
437 $fields_hide = array(
438 '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')
439 );
440 //print_r($table); die();
441 if(isset($fields_hide[$class])) foreach($table as $id => $row) {
442 foreach($fields_hide[$class] as $field) unset($table[$id][$field]);
443 }
444 }
445
d6975011 446 function render_item_table($table,$class=false) {
8ca87ee3 447 if(empty($table)) return '<h3>'.T('holy primordial emptiness is all you can find here...').'</h3><br />';
7df1effb 448 $this->table_add_row_parameters($table);
cdfce7c2 449 $this->table_add_images($table);
d6975011 450 if($class) $this->table_add_relations($table,$class);
aaafc8b7 451 $this->table_add_barcodes($table);
cdfce7c2 452 $this->table_collapse($table);
ecaeb1d6 453 if($class) $this->table_hide_columns($table,$class);
cdfce7c2 454 $this->table_sort($table);
fc5c5b8b 455 return $this->table($table);
cdfce7c2
TM
456 }
457
d0e7939c 458 function render_insert_inputs($class,$columns,$selectbox,$current,$hidecols,$update) {
120e3b45
TM
459 $textarea = array(
460 'item' => array('item_note'),
461 'model' => array('model_descript')
462 );
d0e7939c 463 $html = '';
cdfce7c2 464 foreach($columns as $column) {
326a9fc9 465 $html.=T($class).':<b>'.T($column['Field']).'</b>: ';
7d20381f 466 $name="values[$class][".$column['Field'].'][]';
16261142 467 $val = $update && isset($current[$column['Field']]) ? $current[$column['Field']] : false;
cdfce7c2 468 switch(true) {
a084118b 469 case (preg_match('/auto_increment/', $column['Extra']) || in_array($column['Field'], $hidecols)):
90638f10 470 if(is_bool($val) && !$val) $val = '';
fc5c5b8b
TM
471 $html.=$this->input($name, $val, 'hidden');
472 $html.=$val.'(AUTO)';
cdfce7c2
TM
473 break;
474 case isset($selectbox[$column['Field']]):
e9cb8cea 475 $html.=$this->select($name,$selectbox[$column['Field']],$val);
cdfce7c2 476 break;
120e3b45
TM
477 case isset($textarea[$class]) && in_array($column['Field'],$textarea[$class]):
478 $html.=$this->input($name, $val, 'textarea');
479 break;
480 default:
fc5c5b8b 481 $html.=$this->input($name, $val);
cdfce7c2
TM
482 break;
483 }
fc5c5b8b 484 $html.='<br />';
cdfce7c2 485 }
d0e7939c
TM
486 return $html;
487 }
cdfce7c2 488
d0e7939c
TM
489 function render_insert_form_multi($array) {
490 $html = '';
491 $head=false;
492
493 foreach($array as $key => $args) {
494 $parts=array('inputs');
495 if(!$head) { $head = true;
496 $parts[]='head';
497 }
498 if(!isset($array[$key+1])) {
499 $parts[]='foot';
5b0075fa
TM
500 $hr = '';
501 } else $hr = '<hr />';
502 //$args[] = false;
d0e7939c 503 $args[] = $parts;
f5baa075 504
d0e7939c 505 $html .= call_user_func_array(array($this, 'render_insert_form'), $args);
5b0075fa 506 $html .= $hr;
d0e7939c
TM
507 }
508 return $html;
509 }
510
511 function render_insert_form($class, $columns, $selectbox=array(), $current=false, $hidecols=false, $action=false, $multi_insert=true, $parts=false) {
512 $html = '';
513 //print_r($parts);
514 //echo('<pre>'); print_r($selectbox);
515 //echo('<pre>'); print_r($current);
516 $update = false;
517 if(is_array($current)) {
518 $update = true;
519 $current = array_shift($current);
520 }
521
522 if(!is_array($hidecols)) $hidecols = array();
523 $hidecols = array_merge($hidecols, array('item_author', 'item_valid_from', 'item_valid_till')); //TODO Autodetect
524
525 if(!is_array($parts) || in_array('head', $parts)) {
526 $action = $action ? " action='$action'" : false;
527 $html.="<form$action method='POST'>"; //TODO: use $this->form()
5b0075fa 528 $html.='<span><div name="input_set" style="float:left; border:1px solid grey; padding: 1px; margin: 1px;">';
cdfce7c2
TM
529 }
530
d0e7939c
TM
531 if(!is_array($parts) || in_array('inputs', $parts))
532 $html.=$this->render_insert_inputs($class,$columns,$selectbox,$current,$hidecols,$update);
533
534 if(!is_array($parts) || in_array('foot', $parts)) {
5b0075fa 535 $html .= '</div></span><br style="clear:both" />';
d0e7939c
TM
536 if($multi_insert) { //TODO, move to separate JS file
537 $html.=<<<EOF
d0e7939c
TM
538 <script>
539 function duplicate_element(what, where) {
540 var node = document.getElementsByName(what)[0];
541 node.parentNode.appendChild(node.cloneNode(true));
542 }
543 </script>
544 <a href='#' onClick="duplicate_element('input_set')">+</a>
545EOF;
546 }
547
548 $btn = is_array($current) ? 'UPDATE' : 'INSERT'; //TODO: $current may be set even when inserting...
549 $html.=$this->input(false, $btn, 'submit');
550 $html.='</form>';
551 }
fc5c5b8b 552 return $html;
cdfce7c2
TM
553 }
554}
555
78bf26a5
TM
556/**
557* Trida poskytuje rozhrani k databazi skladu
558*
559* @package Sklad_DB
560* @author Tomas Mudrunka
561*/
cdfce7c2
TM
562class Sklad_DB extends PDO {
563 function __construct() {
63747dad 564 $this->auth = new Sklad_Auth();
cdfce7c2
TM
565
566 parent::__construct(
567 DB_DSN, DB_USER, DB_PASS,
568 array(PDO::MYSQL_ATTR_INIT_COMMAND => "SET NAMES utf8") //Force UTF8 for MySQL
569 );
570 }
571
572 function escape($str) {
573 return preg_replace('(^.|.$)', '', $this->quote($str)); //TODO HACK
574 }
575
382324d3
TM
576 function quote_identifier($str) {
577 return '`'.$this->escape($str).'`'; //TODO HACK
578 }
579
cb8a6861 580 function build_query_select($class, $id=false, $limit=false, $offset=0, $where=false, $search=false, $history=false, $order=false, $suffix_id='_id') {
2bedfdac 581 //Configuration
cdfce7c2
TM
582 $join = array(
583 'item' => array('model', 'category', 'producer', 'vendor', 'room', 'status'),
584 'model' => array('category', 'producer')
9ea191cb 585 ); //TODO Autodetect using foreign keys?
ecaeb1d6 586 $fields_search = array(
0646d9ef
TM
587 'item' => array('item_id','item_serial','model_name','model_barcode','model_descript','producer_name','vendor_name'),
588 'model' => array('model_id','model_name','model_barcode','model_descript','producer_name')
9ea191cb 589 ); //TODO Autodetect
2bedfdac 590
d9d47bd3
TM
591 //Init
592 if(is_array($where)) foreach($where as $key => $value) $where[$key] = $key.' '.$value; //TODO: escape SQLi!!!
593
2bedfdac
TM
594 //Escaping
595 $class = $this->escape($class);
596
597 //SELECT
382324d3 598 $sql="SELECT * FROM `$class`\n";
2bedfdac 599 //JOIN
382324d3 600 if(isset($join[$class])) foreach($join[$class] as $j) $sql .= "LEFT JOIN `$j` USING($j$suffix_id)\n";
2bedfdac 601 //WHERE/REGEXP
cdfce7c2
TM
602 if($search) {
603 $search = $this->quote($search);
ecaeb1d6 604 if(!isset($fields_search[$class])) die(trigger_error(T("Can't search in $class table yet :-("))); //TODO: post_redirect_get
5895162b 605 $sql_search = '';
ecaeb1d6 606 foreach($fields_search[$class] as $column) $sql_search .= "OR $column REGEXP $search ";
5895162b 607 $where[] = "FALSE $sql_search";
cb8a6861
TM
608 } elseif($id) $where[] = "$class$suffix_id = $id";
609 if(!$history && $this->contains_history($class)) $where[] = $class.'_valid_till=0';
610
5895162b 611 if($where) $sql .= 'WHERE ('.implode(') AND (', $where).")\n";
117817be 612 //ORDER
fd479ff5 613 if(!$order) $order = $class.$suffix_id.' DESC';
117817be
TM
614 if($this->contains_history($class)) $order .= ",${class}_valid_from DESC";
615 $sql .= "ORDER BY $order\n";
2bedfdac 616 //LIMIT/OFFSET
cdfce7c2
TM
617 if($limit) {
618 $limit = $this->escape((int)$limit);
619 $offset = $this->escape((int)$offset);
620 $sql .= "LIMIT $offset,$limit\n";
621 }
2bedfdac 622
cdfce7c2
TM
623 return $sql;
624 }
625
66b6f4d6 626 function safe_query($sql, $fatal=true) {
cdfce7c2
TM
627 $result = $this->query($sql);
628 if(!$result) {
2bedfdac 629 $error = $this->errorInfo();
66b6f4d6
TM
630 trigger_error("<font color=red><b>QUERY FAILED ($error[0],$error[1]): </b>$error[2]<br /><br /><b>QUERY:</b>\n<pre>$sql</pre></font>");
631 if($fatal) die();
cdfce7c2
TM
632 }
633 return $result;
634 }
635
d9601e5d 636 function translate_query_results(&$result) {
d1686e10 637 $translate_cols = array('item_valid_till'); //TODO: Hardcoded
326a9fc9
TM
638 foreach($result as $key => $row) {
639 foreach($translate_cols as $col) if(isset($result[$key][$col])){
640 $result[$key][$col] = T($result[$key][$col]);
641 }
642 }
d9601e5d
TM
643 }
644
d7d9ce39 645 function load_backend_data_to_query_results(&$result,$suffix_backend='_backend') {
d9601e5d
TM
646 $translate_cols = array(
647 'item_author' => 'return($this->auth->get_username_by_id($result[$key][$col]));'
648 ); //TODO: Hardcoded
649 foreach($result as $key => $row) {
650 foreach($translate_cols as $col => $backend) if(isset($result[$key][$col])){
d7d9ce39 651 $result[$key][$col.$suffix_backend] = eval($backend);
d9601e5d
TM
652 }
653 }
326a9fc9
TM
654 }
655
656 function safe_query_fetch($sql, $fatal=true, $fetch_flags = PDO::FETCH_ASSOC, $translate=true) {
657 $result = $this->safe_query($sql, $fatal)->fetchAll($fetch_flags);
d9601e5d
TM
658 $this->load_backend_data_to_query_results($result);
659 if($translate) $this->translate_query_results($result);
326a9fc9
TM
660 return $result;
661 }
662
cb8a6861
TM
663 function get_listing($class, $id=false, $limit=false, $offset=0, $where=false, $search=false, $history=false, $indexed=array(), $suffix_id='_id') {
664 $sql = $this->build_query_select($class, $id, $limit, $offset, $where, $search, $history);
326a9fc9 665 $result = $this->safe_query_fetch($sql);
cdfce7c2
TM
666 if(!$result || !is_array($indexed)) return $result;
667
668 foreach($result as $key => $row) $indexed[$row[$class.$suffix_id]]=$row;
669 return $indexed;
670 }
671
d0e7939c 672 function get_columns($class,$disable_cols=array()) { //TODO: Not sure if compatible with non-MySQL DBs
cdfce7c2
TM
673 $class = $this->escape($class);
674 $sql = "SHOW COLUMNS FROM $class;";
d0e7939c
TM
675 $columns = $this->safe_query_fetch($sql);
676 /*foreach($columns as $colk => $col) foreach($col as $key => $val) {
677 if(in_array($col['Field'],$disable_cols)) $columns[$colk]['Extra']='auto_increment';
678 }*/
679 return $columns;
cdfce7c2
TM
680 }
681
682 function columns_get_selectbox($columns, $class=false, $suffix_id='_id', $suffix_name='_name') {
1c99d83b 683 $selectbox=array( //TODO: Hardcoded...
41e57f9e 684 'model_countable' => array(0 => 'no', 1 => 'yes'),
3e939604
TM
685 'model_eshop_hide' => array(0 => 'no', 1 => 'yes'),
686 'vendor_id' => array('COMPULSORY' => 'select...')
1c99d83b 687 );
cdfce7c2 688 foreach($columns as $column) {
66b6f4d6 689 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)!
cdfce7c2
TM
690 if($class && $column['Field'] == $class.$suffix_id) continue;
691 if(!preg_match('/'.$suffix_id.'$/', $column['Field'])) continue;
692 $table=preg_replace('/'.$suffix_id.'$/','',$column['Field']);
66b6f4d6 693
117817be 694 $history = $this->contains_history($table) ? " WHERE ${table}_valid_till=0" : '';
b4dcae05 695 $sql = "SELECT $table$suffix_id, $table$suffix_name FROM $table$history;"; //TODO use build_query_select()!!!
326a9fc9 696 $result = $this->safe_query_fetch($sql, false);
66b6f4d6 697 if(!$result) continue;
cdfce7c2
TM
698 foreach($result as $row) $selectbox[$table.$suffix_id][$row[$table.$suffix_id]]=$row[$table.$suffix_name];
699 }
700 //echo('<pre>'); print_r($selectbox);
66b6f4d6 701 return array_filter($selectbox, 'ksort');
9ea191cb
TM
702 }
703
d0e7939c 704 function map_unique($key, $value, $select, $table, $fatal=true) { //TODO: Guess $select and $table if not passed
16261142
TM
705 $history = $this->contains_history($table) ? " AND ${table}_valid_till=0" : '';
706 $value=$this->quote($value);
707 $sql = "SELECT $select FROM $table WHERE $key=$value$history LIMIT 1;"; //TODO use build_query_select()!!!
326a9fc9 708 $result = $this->safe_query_fetch($sql);
d0e7939c 709 if(isset($result[0][$select])) return $result[0][$select]; else if($fatal) die(trigger_error(T('Record not found!'))); //TODO post_redirect_get...
16261142
TM
710 }
711
9ea191cb
TM
712 function contains_history($table) {
713 $history_tables = array('item'); //TODO Autodetect
714 return in_array($table, $history_tables);
cdfce7c2
TM
715 }
716
717 function build_query_insert($table, $values, $replace=true, $suffix_id='_id') {
b66fadbb
TM
718 //Init
719 $history = $this->contains_history($table);
720
9ea191cb 721 //Escaping
cdfce7c2
TM
722 $table = $this->escape($table);
723
724 //Get list of POSTed columns
aa3fd0a8
TM
725 $columns_array = array_map(array($this,'escape'), array_keys($values[0]));
726 $columns = implode(',',$columns_array);
cdfce7c2 727
9fb856ba 728 //Build query
b66fadbb 729 $sql = '';
b66fadbb
TM
730 //echo('<pre>'); die(print_r($values));
731
732 if($history) {
733 $history_update=false; foreach($values as $row) if(is_numeric($row[$table.'_id'])) $history_update=true;
734 if($history_update) {
735 $sql .= "UPDATE $table";
117817be
TM
736 $sql .= " SET ${table}_valid_till=NOW()";
737 $sql .= " WHERE ${table}_valid_till=0 AND (";
b66fadbb
TM
738 $or = '';
739 foreach($values as $row) {
5b0075fa 740 $sql .= $or.' '.$table.'_id='.$this->quote($row[$table.'_id']);
b66fadbb
TM
741 $or = ' OR';
742 }
743 $sql .= " );\n\n";
744 $replace = false;
745 }
746 }
747
cdfce7c2 748 //Insert into table (columns)
aa3fd0a8 749 $sql .= "INSERT INTO $table ($columns) VALUES ";
cdfce7c2
TM
750
751 //Values (a,b,c),(d,e,f)
752 $comma='';
753 foreach($values as $row) {
9fb856ba
TM
754 $row_quoted = array_map(array($this,'quote'), $row); //Check
755 if($history) {
b66fadbb
TM
756 foreach($row as $column => $value) {
757 switch($column) {
758 case $table.'_valid_from':
759 $row_quoted[$column] = 'NOW()';
760 break;
761 case $table.'_valid_till':
762 $row_quoted[$column] = '0';
763 break;
9fb856ba 764 case $table.'_author':
e9f6461f
TM
765 $row_quoted[$column] = $this->auth->get_user_id();
766 //die($this->auth->get_user_id().'=USER');
b66fadbb 767 break;
b66fadbb
TM
768 }
769 }
770 }
771 $sql .= $comma.'('.implode(',',$row_quoted).')';
cdfce7c2
TM
772 $comma = ',';
773 }
774
aa3fd0a8
TM
775 //On duplicate key
776 if($replace) {
777 foreach($columns_array as $col) {
778 if($col == $table.'_id' || $col == $table.'_valid_till') continue;
779 $on_duplicate[] = "$col=VALUES($col)";
780 }
781 $sql .= "\nON DUPLICATE KEY UPDATE ".implode(',', $on_duplicate);
782 }
783
cdfce7c2
TM
784 //Terminate
785 $sql .= ';';
786 return $sql;
787 }
788
b4dcae05
TM
789 function insert_or_update($table, $values, $replace=true) {
790 $sql = $this->build_query_insert($table, $values, $replace);
cdfce7c2
TM
791 $this->safe_query($sql);
792 return $this->lastInsertId();
793 }
794
b4dcae05 795 function insert_or_update_multitab($values, $replace=true) {
371a86f4 796 $last=false;
b4dcae05 797 foreach($values as $table => $rows) $last = $this->insert_or_update($table, $rows, $replace);
371a86f4
TM
798 return $last;
799 }
800
cdfce7c2 801 function delete($table, $id, $suffix_id='_id') {
64f31c54 802 if($this->contains_history($table)) return false;
cdfce7c2
TM
803 $key = $this->escape($table.$suffix_id);
804 $table = $this->escape($table);
805 $id = $this->quote($id);
806 return $this->safe_query("DELETE FROM $table WHERE $key = $id LIMIT 1;");
807 }
808}
809
0a027cc7
TM
810/**
811* Trida poskytuje high-level rozhrani k databazi skladu
812*
813* @package Sklad_DB_Abstract
814* @author Tomas Mudrunka
815*/
816class Sklad_DB_Abstract extends Sklad_DB {
817 //TODO Code
818}
819
78bf26a5
TM
820/**
821* Trida implementuje uzivatelske rozhrani skladu
822*
823* Example usage:
824* $sklad = new Sklad_UI();
825* $sklad->process_http_request();
826*
827* @package Sklad_UI
828* @author Tomas Mudrunka
829*/
cdfce7c2
TM
830class Sklad_UI {
831 function __construct() {
832 $this->db = new Sklad_DB();
833 $this->html = new Sklad_HTML();
834 }
835
cb8a6861 836 function render_items($class, $id=false, $limit=false, $offset=0, $where=false, $search=false, $history=false) {
d6975011 837 return $this->html->render_item_table($this->db->get_listing($class, $id, $limit, $offset, $where, $search, $history, false),$class);
cdfce7c2
TM
838 }
839
a25f85f8 840 function render_form_add($class) {
cdfce7c2
TM
841 $columns = $this->db->get_columns($class);
842 $selectbox = $this->db->columns_get_selectbox($columns, $class);
a25f85f8 843 return $this->html->render_insert_form($class, $columns, $selectbox);
cdfce7c2
TM
844 }
845
f5baa075 846 function render_form_edit($class, $id, $multi_insert) {
cdfce7c2
TM
847 $columns = $this->db->get_columns($class);
848 $selectbox = $this->db->columns_get_selectbox($columns, $class);
117817be 849 $current = $this->db->get_listing($class, $id, 1);
f5baa075 850 return $this->html->render_insert_form($class, $columns, $selectbox, $current, false, false, $multi_insert);
cdfce7c2
TM
851 }
852
a25f85f8 853 function render_single_record_details($class, $id) {
cdfce7c2
TM
854 $id_next = $id + 1;
855 $id_prev = $id - 1 > 0 ? $id - 1 : 0;
856 $get = $_SERVER['QUERY_STRING'] != '' ? '?'.$_SERVER['QUERY_STRING'] : '';
a25f85f8
TM
857 $html='';
858 $html.= $this->html->link('<<', "$class/$id_prev/");
859 $html.= '-';
860 $html.= $this->html->link('>>', "$class/$id_next/");
861 $html.= '<br />';
54694117 862 $html.='<span style="float:right;">'.$this->html->render_barcode(BARCODE_PREFIX.strtoupper("$class/$id")).'</span>';
a25f85f8 863 $html.= $this->html->link('edit', "$class/$id/edit/");
9fb856ba 864 if($this->db->contains_history($class)) $html.= ' ][ '.$this->html->link('history', "$class/$id/history/");
a25f85f8 865 return $html;
cdfce7c2
TM
866 }
867
a25f85f8 868 function render_listing_navigation($class, $id, $limit, $offset) {
cdfce7c2
TM
869 $offset_next = $offset + $limit;
870 $offset_prev = $offset - $limit > 0 ? $offset - $limit : 0;
871 $get = $_SERVER['QUERY_STRING'] != '' ? '?'.$_SERVER['QUERY_STRING'] : '';
a25f85f8
TM
872 $html='';
873 $html.= $this->html->link('<<', "$class/$id/$limit/$offset_prev/$get");
874 $html.= '-';
875 $html.= $this->html->link('>>', "$class/$id/$limit/$offset_next/$get");
876 $html.= '<br />';
877 $html.= $this->html->link('new', "$class/new/$get");
878 return $html;
cdfce7c2
TM
879 }
880
a25f85f8
TM
881 function render_listing_extensions($class, $id, $limit, $offset, $edit=false) {
882 $html='';
cdfce7c2 883 if(is_numeric($id)) {
a25f85f8 884 $html.=$this->render_single_record_details($class, $id);
cdfce7c2 885 } else {
a25f85f8 886 $html.=$this->render_listing_navigation($class, '*', $limit, $offset);
cdfce7c2
TM
887 }
888 if($edit) {
f5baa075 889 $html.= $this->render_form_edit($class, $id, false);
cdfce7c2 890 $action = $_SERVER['SCRIPT_NAME']."/$class/$id/delete";
35916247
TM
891 $html.=$this->html->form($action,'POST',array(
892 array(false,'DELETE','submit'),
893 array('sure', false, 'checkbox', false, false, 'sure?')
894 ));
cdfce7c2 895 $action = $_SERVER['SCRIPT_NAME']."/$class/$id/image";
35916247
TM
896 $html.=$this->html->form($action,'POST',array(
897 array('image', false, 'file', false, 'size="30"'),
898 array(false, 'IMAGE', 'submit')
899 ), "enctype='multipart/form-data'");
cdfce7c2 900 }
a25f85f8 901 return $html;
cdfce7c2
TM
902 }
903
904 function check_auth() {
042a4988 905 new HTTP_Auth('WareHouse ['.BACKEND_AUTH.']', true, array($this->db->auth,'check_auth'));
cdfce7c2
TM
906 }
907
a8bbdc31
TM
908 function post_redirect_get($location, $message='', $error=false, $translate=true) {
909 $messaget = $translate ? T($message) : $message;
910 $url_args = $messaget != '' ? '?message='.urlencode($messaget) : '';
8acef003 911 $location = $this->html->internal_url($location).$url_args;
1f74892d 912 header('Location: '.$location);
64f31c54 913 if($error) trigger_error($message);
7efdf72a
TM
914 $location=htmlspecialchars($location);
915 die(
916 "<meta http-equiv='refresh' content='0; url=$location'>".
a8bbdc31 917 $messaget."<br />Location: <a href='$location'>$location</a>"
7efdf72a 918 );
cdfce7c2
TM
919 }
920
623c65e2 921 function safe_include($dir,$name,$vars=array(),$ext='.inc.php') {
64f31c54 922 if(preg_match('/[^a-zA-Z0-9-]/',$name)) $this->post_redirect_get('', 'SAFE INCLUDE: Securityfuck.', true);
3e6c412e 923 $filename="$dir/$name$ext";
64f31c54 924 if(!is_file($filename)) $this->post_redirect_get('', 'SAFE INCLUDE: Fuckfound.', true);
623c65e2 925 foreach($vars as $var => $val) $$var=$val;
3e6c412e
TM
926 ob_start();
927 include($filename);
928 $out=ob_get_contents();
929 ob_end_clean();
930 return $out;
931 }
932
a8bbdc31
TM
933 function check_input_validity($field, $value='', $ruleset=0) {
934 $rules = array(0 => array(
935 'model_barcode' => '/./',
3e939604
TM
936 'item_serial' => '/./',
937 'vendor_id' => '/^[0-9]*$/'
a8bbdc31
TM
938 ));
939 if(isset($rules[$ruleset][$field]) && !preg_match($rules[$ruleset][$field], trim($value))) return false;
940 return true;
941 }
942
bda4a4be 943 function process_http_request_post($action=false, $class=false, $id=false, $force_redirect=false) {
cdfce7c2 944 if($_SERVER['REQUEST_METHOD'] != 'POST') return;
1f74892d 945 //echo('<pre>'); //DEBUG (maybe todo remove), HEADERS ALREADY SENT!!!!
cdfce7c2
TM
946
947 //SephirPOST:
371a86f4
TM
948
949 /* Tenhle foreach() prekopiruje promenne
7d20381f 950 * z: $_POST['values'][$table][$column][$id];
371a86f4
TM
951 * do: $values[$table][$id][$column]
952 */
7d20381f
TM
953 if(isset($_POST['values'])) {
954 $values=array();
955 foreach($_POST['values'] as $table => $columns) {
956 foreach($columns as $column => $ids) {
a8bbdc31
TM
957 foreach($ids as $id => $val) {
958 $values[$table][$id][$column] = trim($val);
959 if(!$this->check_input_validity($column,$val)) {
960 $message = "Spatny vstup: $column [$id] = \"$val\"; ". //XSS
961 $this->html->link('GO BACK', 'javascript:history.back()', false, false);
962 $this->post_redirect_get('', $message, false, false);
963 }
964 }
7d20381f 965 }
cdfce7c2 966 }
7d20381f 967 //die(print_r($values));
cdfce7c2
TM
968 }
969
970 if($action) switch($action) {
971 case 'new':
b4dcae05 972 $replace = false;
cdfce7c2 973 case 'edit':
b4dcae05 974 if(!isset($replace)) $replace = true;
64f31c54 975 $table = $class ? $class : 'item';
cdfce7c2 976 //print_r($values); //debug
b4dcae05 977 $last = $this->db->insert_or_update_multitab($values, $replace);
bda4a4be 978 $last = $force_redirect ? $force_redirect."?last=$last" : "$table/$last/";
d9384cb5 979 $next = "$table/new/";
bda4a4be
TM
980 $message = $force_redirect ? '' : 'Hotovo. Další záznam přidáte '.$this->html->link('zde', $next).'.';
981 $this->post_redirect_get($last, $message);
cdfce7c2
TM
982 break;
983 case 'delete':
64f31c54
TM
984 if(!isset($_POST['sure']) || !$_POST['sure']) $this->post_redirect_get("$class/$id/edit", 'Sure user expected :-)');
985 $this->db->delete($class, $id) || $this->post_redirect_get("$class/$id/edit", "V tabulce $class jentak neco mazat nebudes chlapecku :-P");
1f74892d 986 $this->post_redirect_get("$class", "Neco (pravdepodobne /$class/$id) bylo asi smazano. Fnuk :'-(");
cdfce7c2
TM
987 break;
988 case 'image':
989 $image_classes = array('model'); //TODO, use this more widely across the code
64f31c54 990 if(!in_array($class, $image_classes)) $this->post_redirect_get("$class/$id/edit", "Nekdo nechce k DB Tride '$class' prirazovat obrazky!");
cdfce7c2 991 $image_destination = DIR_IMAGES."/$class/$id.jpg";
326a9fc9 992 if($_FILES['image']['name'] == '') $this->post_redirect_get("$class/$id/edit", 'Everything has to be called somehow!', true);
cdfce7c2 993 if(move_uploaded_file($_FILES['image']['tmp_name'], $image_destination)) {
1f74892d 994 chmod ($image_destination, 0664);
326a9fc9
TM
995 $this->post_redirect_get("$class/$id", 'Image has been upbloated successfully :)');
996 } else $this->post_redirect_get("$class/$id/edit", 'File upload failed :(', true);
cdfce7c2
TM
997 break;
998 default:
326a9fc9 999 $this->post_redirect_get('', 'Nothin\' to do here my cutie :-*');
cdfce7c2
TM
1000 break;
1001 }
1002
1003 die('POSTed pyčo!');
1004 }
1005
1006 function process_http_request() {
1007 $this->check_auth();
1008
1009 @ini_set('magic_quotes_gpc' , 'off');
1010 if(get_magic_quotes_gpc()) {
1011 die(trigger_error("Error: magic_quotes_gpc needs to be disabled! F00K!"));
1012 }
1013
1014 $PATH_INFO=@trim($_SERVER[PATH_INFO]);
a5094502 1015 if($PATH_INFO == '' || $PATH_INFO == '/') $PATH_INFO = FRONTEND_PAGE_WELCOME;
cdfce7c2 1016 $PATH_CHUNKS = preg_split('/\//', $PATH_INFO);
81ab8aef 1017 //Sephirot:
cdfce7c2 1018 if(!isset($PATH_CHUNKS[1])) $PATH_CHUNKS[1]='';
88c38b26 1019 if($_SERVER['REQUEST_METHOD'] != 'POST' && $PATH_CHUNKS[1]!='barcode' && $PATH_CHUNKS[1]!='api') //TODO: tyhle podminky naznacujou, ze je v navrhu nejaka drobna nedomyslenost...
e9f6461f 1020 echo $this->html->header($PATH_INFO,$this->db->auth->get_user());
81ab8aef 1021 switch($PATH_CHUNKS[1]) { //TODO: Move some branches to plugins if possible
cdfce7c2
TM
1022 case 'test': //test
1023 die('Tell me why you cry');
1024 break;
88c38b26
TM
1025 case 'assistant': case 'api': //assistant|api
1026 $incdirs = array(
1027 'assistant' => DIR_ASSISTANTS,
1028 'api' => DIR_APIS
1029 );
de77377e
TM
1030 $PATH_CHUNKS[3] = isset($PATH_CHUNKS[3]) ? trim($PATH_CHUNKS[3]) : false;
1031 $assistant_vars['SUBPATH'] = array_slice($PATH_CHUNKS, 3);
1032 $assistant_vars['URL_INTERNAL'] = 'assistant/'.$PATH_CHUNKS[2];
1033 $assistant_vars['URL'] = $_SERVER['SCRIPT_NAME'].'/'.$assistant_vars['URL_INTERNAL'];
5ef6c52f 1034 $assistant_vars['ASSISTANT'] = $PATH_CHUNKS[2];
88c38b26 1035 echo $this->safe_include($incdirs[$PATH_CHUNKS[1]],$PATH_CHUNKS[2],$assistant_vars);
3e6c412e 1036 break;
81ab8aef
TM
1037 case 'barcode': //barcode
1038 Barcode::download_barcode(implode('/',array_slice($PATH_CHUNKS, 2)));
1039 break;
cdfce7c2
TM
1040 default: //?
1041 $search = (isset($_GET['q']) && trim($_GET['q']) != '') ? trim($_GET['q']) : false;
1042 $class = (isset($PATH_CHUNKS[1]) && $PATH_CHUNKS[1] != '') ? $PATH_CHUNKS[1] : 'item';
1043 if(!isset($PATH_CHUNKS[2])) $PATH_CHUNKS[2]='';
1044 switch($PATH_CHUNKS[2]) {
1045 case 'new': //?/new
1046 $this->process_http_request_post($PATH_CHUNKS[2], $class);
a25f85f8 1047 echo $this->render_form_add($class);
cdfce7c2
TM
1048 break;
1049 default: //?/?
1050 $id = (isset($PATH_CHUNKS[2]) && is_numeric($PATH_CHUNKS[2]) ? (int) $PATH_CHUNKS[2] : false);
1051 if(!isset($PATH_CHUNKS[3])) $PATH_CHUNKS[3]='';
1052 $edit=false;
1053 switch($PATH_CHUNKS[3]) {
1054 case 'edit': //?/?/edit
9fb856ba
TM
1055 case 'image': //?/?/image
1056 case 'delete': //?/?/delete
cdfce7c2
TM
1057 $this->process_http_request_post($PATH_CHUNKS[3], $class, $id);
1058 $edit=true;
1059 default: //?/?/?
9fb856ba 1060 $history = $PATH_CHUNKS[3] == 'history' ? true : false;
2415a365
TM
1061 $limit = is_numeric($PATH_CHUNKS[3]) ? (int) $PATH_CHUNKS[3] : FRONTEND_LISTING_LIMIT;
1062 $offset = isset($PATH_CHUNKS[4]) ? (int) $PATH_CHUNKS[4] : 0;
d9d47bd3 1063 $where = @is_array($_GET['where']) ? $_GET['where'] : false;
cb8a6861 1064 echo $this->render_items($class, $id, $limit, $offset, $where, $search, $history);
a25f85f8 1065 echo $this->render_listing_extensions($class, $id, $limit, $offset, $edit);
cdfce7c2
TM
1066 //print_r(array("<pre>",$_SERVER));
1067 break;
1068 }
1069 break;
1070 }
1071 break;
1072 }
1073 }
1074}
1075
1076$sklad = new Sklad_UI();
1077$sklad->process_http_request();
1078
54694117 1079echo('<br style="clear:both;" /><hr />');
This page took 1.065471 seconds and 4 git commands to generate.