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