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