3 * SkladovySystem - Storage management system compatible with LMS
4 * Copyright (C) 2011 Tomas Mudrunka
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.
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.
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/>.
20 require_once('sklad.conf.php');
21 set_include_path(DIR_LIB
.PATH_SEPARATOR
.get_include_path());
23 require_once('Sklad_LMS-fake.class.php');
24 require_once('HTTP_Auth.class.php');
25 require_once('Locale.class.php');
26 require_once('Barcode.class.php');
29 * Trida poskytuje vseobecne funkce pro generovani HTML kodu
31 * Tato trida by nemela sama nic vypisovat (vyjma chybovych a debugovacich hlasek)!
34 * @author Tomas Mudrunka
39 foreach($row as $var) {
40 if(trim($var) == '') $var = ' ';
41 $html.="<td>$var</td>";
47 function table(&$table, $params='border=1') {
48 $html="<table $params>";
50 foreach($table as $row) {
52 $html.=$this->row(array_keys($row));
55 $html.=$this->row($row);
61 function link($title='n/a', $link='#void', $internal=true, $translate=true) {
62 if($internal && (!isset($link[0]) ||
$link[0] != '#')) $link = $this->internal_url($link);
63 if($translate) $title = T($title);
64 return "<a href='$link'>".$title."</a>";
67 function img($src='#void', $title='img', $options='width=64') {
68 $options = $options ?
" $options" : '';
69 return "<img src='$src' alt='$title' title='$title'$options; />";
72 function input($name=false, $value=false, $type='text', $placeholder=false, $options=false, $prefix='') {
73 $html = T($prefix)."<input type='$type' ";
74 if($name) $html.= "name='$name' ";
75 if(!is_bool($value)) {
76 if($type == 'submit') $value = T($value);
77 $html.= "value='$value' ";
79 if($options) $html.= "$options ";
80 if($placeholder) $html.= "placeholder='$placeholder' ";
85 function form($action=false, $method=false, $inputs, $options=false) {
86 $action = $action ?
" action='$action'" : '';
87 $method = $method ?
" method='$method'" : '';
88 $options = $options ?
" $options" : '';
89 $html = "<form$action$method$options>";
90 foreach($inputs as $input) $html .= call_user_func_array(array($this,'input'), $input);
95 function select($name, $selectbox, $default=false) {
96 //echo('<pre>'); print_r($selectbox);
97 $html = "<select name='$name'>";
100 $value=$default; $title=$selectbox[$value];
101 $html .= "<option value='$value'>$value :: $title</option>";
102 unset($selectbox[$value]);
104 foreach($selectbox as $value => $title) {
105 $html .= "<option value='$value'>$value :: $title</option>";
107 $html .= "</select>";
111 function ul($items,$tag=ul
,$head='',$class=false) {
112 $class = $class ?
" class='$class'" : '';
113 $html = "$head<$tag$class>";
114 foreach($items as $key => $value) {
116 if(is_numeric($key)) {
119 $html .= $this->link($key,$value);
127 function div($html, $options) {
128 $options = $options ?
" $options" : '';
129 return "<div$options>$html</div>";
134 * Trida poskytuje podpurne funkce pro generovani HTML kodu specificke pro sklad
136 * Tato trida by nemela sama nic vypisovat (vyjma chybovych a debugovacich hlasek)!
138 * @package Sklad_HTML
139 * @author Tomas Mudrunka
141 class Sklad_HTML
extends HTML
{ //TODO: Split into few more methods
142 function header($title='') {
144 $script = $_SERVER['SCRIPT_NAME'];
145 $search = htmlspecialchars(@trim
($_GET['q']));
146 $message = strip_tags(@trim
($_GET['message']),'<a><b><u><i>');
147 $instance = INSTANCE_ID
!= '' ?
'/'.INSTANCE_ID
: '';
148 //$title = T($title); //TODO
151 <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
152 <title>SōkoMan$title</title>
154 <h1><a href="$script/">SōkoMan</a><small>$instance$title</small></h1>
156 <style type="text/css">
157 * { font-family: arial; }
173 .menu, .menu * menu {
178 border: 1px solid orange;
183 .menu li:hover menu, .menu li:hover {
185 background-color: yellow;
194 foreach(scandir(DIR_ASSISTANTS
) as $item) {
195 if($item == '.' ||
$item == '..') continue;
196 $item = preg_replace('/\.inc\.php$/','',$item);
197 $assistants[$item] = "assistant/$item";
200 $tables=array('item','model','category','producer','vendor','room','status');
202 foreach($tables as $table) {
203 $listable[$table] = $table;
204 $insertable[$table] = "$table/new";
207 $html .= $this->ul(array(
208 'Logout' => '?logout',
210 0 => $this->ul($assistants,'menu',$this->link('Assistants','#')),
211 1 => $this->ul($listable,'menu',$this->link('List','#')),
212 2 => $this->ul($insertable,'menu',$this->link('New','#'))
213 ),'menu', '', 'menu');
215 $html .= '<div style="float: right;">';
217 $html .= $this->form("$script/assistant/go", 'GET', array(
218 array('q','','text','smart id...', 'autofocus'),
219 array(false,'go','submit')
220 ), 'style="float: left;"');
222 $html .= $this->form('?', 'GET', array(
223 array('q',$search,'text','regexp...'),
224 array(false,'filter','submit')
225 ), 'style="float: left;"');
231 <hr style="clear: both;" />
232 <div style="background-color:#FFDDDD;">
233 <font color="red">$message</font>
240 function internal_url($link) {
241 return $_SERVER['SCRIPT_NAME'].'/'.$link;
244 function table_add_images(&$table) {
245 $image = array('model_id');
246 foreach($table as $id => $row) {
247 foreach($image as $column) if(isset($table[$id][$column])) {
248 $type = @array_shift
(preg_split('/_/', $column));
249 $src=URL_IMAGES
."/$type/".$table[$id][$column].'.jpg';
250 $table[$id][$type.'_image']=$this->img($src, $table[$id][$column]);
255 function render_barcode($barcode,$opts=false) {
256 return $this->link($this->img($this->internal_url("barcode/$barcode"),$barcode,$opts),"barcode/$barcode",true,false);
259 function table_add_barcodes(&$table) {
260 $image = array('model_barcode', 'item_serial');
261 foreach($table as $id => $row) {
262 foreach($image as $column) if(isset($table[$id][$column])) {
263 $table[$id][$column]=$this->render_barcode($table[$id][$column]);
268 function table_collapse(&$table) {
270 'item_id' => 'item_id',
271 'model_id' => 'model_name',
272 'category_id' => 'category_name',
273 'producer_id' => 'producer_name',
274 'vendor_id' => 'vendor_name',
275 'room_id' => 'room_name',
276 'status_id' => 'status_name',
278 foreach($table as $id => $row) {
279 foreach($collapse as $link => $title)
280 if(isset($table[$id][$link]) && isset($row[$title])) {
281 $type = @array_shift
(preg_split('/_/', $link));
282 if($link != $title) unset($table[$id][$link]);
283 $table[$id][$title]=$this->link($row[$title], $type.'/'.$row[$link].'/');
288 function table_sort(&$table) {
289 $precedence = array('item_id', 'model_image', 'model_name','model_descript','category_name','status_name','room_name');
290 $table_sorted = array();
291 foreach($table as $id => $row) {
292 $table_sorted[$id] = array();
293 foreach($precedence as $column) if(isset($table[$id][$column])) {
294 $table_sorted[$id][T($column)]=$table[$id][$column];
295 unset($table[$id][$column]);
297 //$table_sorted[$id]=array_merge($table_sorted[$id],$table[$id]);
298 foreach($table[$id] as $key => $val) $table_sorted[$id][T($key)] = $val; //array_merge with T() translating
300 $table = $table_sorted;
303 function render_item_table($table) {
304 $this->table_add_images($table);
305 $this->table_add_barcodes($table);
306 $this->table_collapse($table);
307 $this->table_sort($table);
308 return $this->table($table);
311 function render_insert_form($class, $columns, $selectbox=array(), $current=false, $hidecols=false, $action=false, $multi_insert=true) {
312 //echo('<pre>'); print_r($selectbox);
313 //echo('<pre>'); print_r($current);
315 if(is_array($current)) {
317 $current = array_shift($current);
320 if(!is_array($hidecols)) $hidecols = array('item_author', 'item_valid_from', 'item_valid_till'); //TODO Autodetect
322 $action = $action ?
" action='$action'" : false;
323 $html="<form$action method='POST'>"; //TODO: use $this->form()
324 if($multi_insert) $html.='<div name="input_set" style="float:left; border:1px solid grey;">';
325 //$html.=$this->input('table', $class, 'hidden');
326 foreach($columns as $column) {
327 $html.=T($class).':<b>'.T($column['Field']).'</b>: ';
328 $name="values[$class][".$column['Field'].'][]';
329 $val = $update && isset($current[$column['Field']]) ?
$current[$column['Field']] : false;
331 case (preg_match('/auto_increment/', $column['Extra']) ||
in_array($column['Field'], $hidecols)):
333 $html.=$this->input($name, $val, 'hidden');
334 $html.=$val.'(AUTO)';
336 case isset($selectbox[$column['Field']]):
337 $html.=$this->select($name,$selectbox[$column['Field']],$val);
340 $html.=$this->input($name, $val);
347 //TODO, move to separate JS file
350 <span name="input_set_next"></span><br style="clear:both" />
352 function duplicate_element(what, where) {
353 document.getElementsByName(where)[0].outerHTML =
354 document.getElementsByName(what)[0].outerHTML
355 + document.getElementsByName(where)[0].outerHTML;
358 <a href='#' onClick="duplicate_element('input_set', 'input_set_next')">+</a>
362 $btn = is_array($current) ?
'UPDATE' : 'INSERT'; //TODO: $current may be set even when inserting...
363 $html.=$this->input(false, $btn, 'submit');
370 * Trida poskytuje rozhrani k databazi skladu
373 * @author Tomas Mudrunka
375 class Sklad_DB
extends PDO
{
376 function __construct() {
377 $this->lms
= new Sklad_LMS();
380 DB_DSN
, DB_USER
, DB_PASS
,
381 array(PDO
::MYSQL_ATTR_INIT_COMMAND
=> "SET NAMES utf8") //Force UTF8 for MySQL
385 function escape($str) {
386 return preg_replace('(^.|.$)', '', $this->quote($str)); //TODO HACK
389 function build_query_select($class, $id=false, $limit=false, $offset=0, $where=false, $search=false, $history=false, $order=false, $suffix_id='_id') {
392 'item' => array('model', 'category', 'producer', 'vendor', 'room', 'status'),
393 'model' => array('category', 'producer')
394 ); //TODO Autodetect using foreign keys?
395 $search_fields = array(
396 'item' => array('item_id','item_serial','model_name','model_barcode','model_descript','producer_name','vendor_name')
400 $class = $this->escape($class);
403 $sql="SELECT * FROM $class\n";
405 if(isset($join[$class])) foreach($join[$class] as $j) $sql .= "LEFT JOIN $j USING($j$suffix_id)\n";
408 $search = $this->quote($search);
409 if(!isset($search_fields[$class])) die(trigger_error(T("Can't search in $class table yet :-("))); //TODO: post_redirect_get
411 foreach($search_fields[$class] as $column) $sql_search .= "OR $column REGEXP $search ";
412 $where[] = "FALSE $sql_search";
413 } elseif($id) $where[] = "$class$suffix_id = $id";
414 if(!$history && $this->contains_history($class)) $where[] = $class.'_valid_till=0';
416 if($where) $sql .= 'WHERE ('.implode(') AND (', $where).")\n";
418 if(!$order) $order = $class.$suffix_id;
419 if($this->contains_history($class)) $order .= ",${class}_valid_from DESC";
420 $sql .= "ORDER BY $order\n";
423 $limit = $this->escape((int)$limit);
424 $offset = $this->escape((int)$offset);
425 $sql .= "LIMIT $offset,$limit\n";
431 function safe_query($sql, $fatal=true) {
432 $result = $this->query($sql);
434 $error = $this->errorInfo();
435 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>");
441 function translate_query_results($result) {
442 $translate_cols = array('status_name', 'item_valid_till'); //TODO: Hardcoded
443 foreach($result as $key => $row) {
444 foreach($translate_cols as $col) if(isset($result[$key][$col])){
445 $result[$key][$col] = T($result[$key][$col]);
451 function safe_query_fetch($sql, $fatal=true, $fetch_flags = PDO
::FETCH_ASSOC
, $translate=true) {
452 $result = $this->safe_query($sql, $fatal)->fetchAll($fetch_flags);
453 if($translate) $result = $this->translate_query_results($result);
458 function get_listing($class, $id=false, $limit=false, $offset=0, $where=false, $search=false, $history=false, $indexed=array(), $suffix_id='_id') {
459 $sql = $this->build_query_select($class, $id, $limit, $offset, $where, $search, $history);
460 $result = $this->safe_query_fetch($sql);
461 if(!$result ||
!is_array($indexed)) return $result;
463 foreach($result as $key => $row) $indexed[$row[$class.$suffix_id]]=$row;
467 function get_columns($class) {
468 $class = $this->escape($class);
469 $sql = "SHOW COLUMNS FROM $class;";
470 return $this->safe_query_fetch($sql);
473 function columns_get_selectbox($columns, $class=false, $suffix_id='_id', $suffix_name='_name') {
475 foreach($columns as $column) {
476 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)!
477 if($class && $column['Field'] == $class.$suffix_id) continue;
478 if(!preg_match('/'.$suffix_id.'$/', $column['Field'])) continue;
479 $table=preg_replace('/'.$suffix_id.'$/','',$column['Field']);
481 $history = $this->contains_history($table) ?
" WHERE ${table}_valid_till=0" : '';
482 $sql = "SELECT $table$suffix_id, $table$suffix_name FROM $table$history;"; //TODO use build_query_select()!!!
483 $result = $this->safe_query_fetch($sql, false);
484 if(!$result) continue;
485 foreach($result as $row) $selectbox[$table.$suffix_id][$row[$table.$suffix_id]]=$row[$table.$suffix_name];
487 //echo('<pre>'); print_r($selectbox);
488 return array_filter($selectbox, 'ksort');
491 function map_unique($key, $value, $select, $table) { //TODO: Guess $select and $table if not passed
492 $history = $this->contains_history($table) ?
" AND ${table}_valid_till=0" : '';
493 $value=$this->quote($value);
494 $sql = "SELECT $select FROM $table WHERE $key=$value$history LIMIT 1;"; //TODO use build_query_select()!!!
495 $result = $this->safe_query_fetch($sql);
496 if(isset($result[0][$select])) return $result[0][$select]; else die(trigger_error(T('Record not found!'))); //TODO post_redirect_get...
499 function contains_history($table) {
500 $history_tables = array('item'); //TODO Autodetect
501 return in_array($table, $history_tables);
504 function build_query_insert($table, $values, $replace=true, $suffix_id='_id') {
506 $history = $this->contains_history($table);
509 $table = $this->escape($table);
511 //Get list of POSTed columns
512 $columns_array = array_map(array($this,'escape'), array_keys($values[0]));
513 $columns = implode(',',$columns_array);
517 //echo('<pre>'); die(print_r($values));
520 $history_update=false; foreach($values as $row) if(is_numeric($row[$table.'_id'])) $history_update=true;
521 if($history_update) {
522 $sql .= "UPDATE $table";
523 $sql .= " SET ${table}_valid_till=NOW()";
524 $sql .= " WHERE ${table}_valid_till=0 AND (";
526 foreach($values as $row) {
527 $sql .= $or.' '.$table.'_id='.$row[$table.'_id'];
535 //Insert into table (columns)
536 $sql .= "INSERT INTO $table ($columns) VALUES ";
538 //Values (a,b,c),(d,e,f)
540 foreach($values as $row) {
541 $row_quoted = array_map(array($this,'quote'), $row); //Check
543 foreach($row as $column => $value) {
545 case $table.'_valid_from':
546 $row_quoted[$column] = 'NOW()';
548 case $table.'_valid_till':
549 $row_quoted[$column] = '0';
551 case $table.'_author':
552 $row_quoted[$column] = $this->lms
->get_authorized_user_id();
553 //die($this->lms->get_authorized_user_id().'=USER');
558 $sql .= $comma.'('.implode(',',$row_quoted).')';
564 foreach($columns_array as $col) {
565 if($col == $table.'_id' ||
$col == $table.'_valid_till') continue;
566 $on_duplicate[] = "$col=VALUES($col)";
568 $sql .= "\nON DUPLICATE KEY UPDATE ".implode(',', $on_duplicate);
576 function insert_or_update($table, $values, $replace=true) {
577 $sql = $this->build_query_insert($table, $values, $replace);
578 $this->safe_query($sql);
579 return $this->lastInsertId();
582 function insert_or_update_multitab($values, $replace=true) {
584 foreach($values as $table => $rows) $last = $this->insert_or_update($table, $rows, $replace);
588 function delete($table, $id, $suffix_id='_id') {
589 if($this->contains_history($table)) return false;
590 $key = $this->escape($table.$suffix_id);
591 $table = $this->escape($table);
592 $id = $this->quote($id);
593 return $this->safe_query("DELETE FROM $table WHERE $key = $id LIMIT 1;");
598 * Trida poskytuje high-level rozhrani k databazi skladu
600 * @package Sklad_DB_Abstract
601 * @author Tomas Mudrunka
603 class Sklad_DB_Abstract
extends Sklad_DB
{
608 * Trida implementuje uzivatelske rozhrani skladu
611 * $sklad = new Sklad_UI();
612 * $sklad->process_http_request();
615 * @author Tomas Mudrunka
618 function __construct() {
619 $this->db
= new Sklad_DB();
620 $this->html
= new Sklad_HTML();
623 function render_items($class, $id=false, $limit=false, $offset=0, $where=false, $search=false, $history=false) {
624 return $this->html
->render_item_table($this->db
->get_listing($class, $id, $limit, $offset, $where, $search, $history, false));
627 function render_form_add($class) {
628 $columns = $this->db
->get_columns($class);
629 $selectbox = $this->db
->columns_get_selectbox($columns, $class);
630 return $this->html
->render_insert_form($class, $columns, $selectbox);
633 function render_form_edit($class, $id) {
634 $columns = $this->db
->get_columns($class);
635 $selectbox = $this->db
->columns_get_selectbox($columns, $class);
636 $current = $this->db
->get_listing($class, $id, 1);
637 return $this->html
->render_insert_form($class, $columns, $selectbox, $current);
640 function render_single_record_details($class, $id) {
642 $id_prev = $id - 1 > 0 ?
$id - 1 : 0;
643 $get = $_SERVER['QUERY_STRING'] != '' ?
'?'.$_SERVER['QUERY_STRING'] : '';
645 $html.= $this->html
->link('<<', "$class/$id_prev/");
647 $html.= $this->html
->link('>>', "$class/$id_next/");
649 $html.= $this->html
->link('edit', "$class/$id/edit/");
650 if($this->db
->contains_history($class)) $html.= ' ][ '.$this->html
->link('history', "$class/$id/history/");
651 $html.='<br />'.$this->html
->render_barcode(BARCODE_PREFIX
.strtoupper("$class/$id"));
655 function render_listing_navigation($class, $id, $limit, $offset) {
656 $offset_next = $offset +
$limit;
657 $offset_prev = $offset - $limit > 0 ?
$offset - $limit : 0;
658 $get = $_SERVER['QUERY_STRING'] != '' ?
'?'.$_SERVER['QUERY_STRING'] : '';
660 $html.= $this->html
->link('<<', "$class/$id/$limit/$offset_prev/$get");
662 $html.= $this->html
->link('>>', "$class/$id/$limit/$offset_next/$get");
664 $html.= $this->html
->link('new', "$class/new/$get");
668 function render_listing_extensions($class, $id, $limit, $offset, $edit=false) {
670 if(is_numeric($id)) {
671 $html.=$this->render_single_record_details($class, $id);
673 $html.=$this->render_listing_navigation($class, '*', $limit, $offset);
676 $html.= $this->render_form_edit($class, $id);
677 $action = $_SERVER['SCRIPT_NAME']."/$class/$id/delete";
678 $html.=$this->html
->form($action,'POST',array(
679 array(false,'DELETE','submit'),
680 array('sure', false, 'checkbox', false, false, 'sure?')
682 $action = $_SERVER['SCRIPT_NAME']."/$class/$id/image";
683 $html.=$this->html
->form($action,'POST',array(
684 array('image', false, 'file', false, 'size="30"'),
685 array(false, 'IMAGE', 'submit')
686 ), "enctype='multipart/form-data'");
691 function check_auth() {
692 new HTTP_Auth('SkladovejSystem', true, array($this->db
->lms
,'check_auth'));
695 function post_redirect_get($location, $message='', $error=false) {
696 $url_args = $message != '' ?
'?message='.urlencode(T($message)) : '';
697 $location = $this->html
->internal_url($location).$url_args;
698 header('Location: '.$location);
699 if($error) trigger_error($message);
700 $location=htmlspecialchars($location);
702 "<meta http-equiv='refresh' content='0; url=$location'>".
703 T($message)."<br />Location: <a href='$location'>$location</a>"
707 function safe_include($dir,$name,$vars=array(),$ext='.inc.php') {
708 if(preg_match('/[^a-zA-Z0-9-]/',$name)) $this->post_redirect_get('', 'SAFE INCLUDE: Securityfuck.', true);
709 $filename="$dir/$name$ext";
710 if(!is_file($filename)) $this->post_redirect_get('', 'SAFE INCLUDE: Fuckfound.', true);
711 foreach($vars as $var => $val) $
$var=$val;
714 $out=ob_get_contents();
719 function process_http_request_post($action=false, $class=false, $id=false, $force_redirect=false) {
720 if($_SERVER['REQUEST_METHOD'] != 'POST') return;
721 //echo('<pre>'); //DEBUG (maybe todo remove), HEADERS ALREADY SENT!!!!
725 /* Tenhle foreach() prekopiruje promenne
726 * z: $_POST['values'][$table][$column][$id];
727 * do: $values[$table][$id][$column]
729 if(isset($_POST['values'])) {
731 foreach($_POST['values'] as $table => $columns) {
732 foreach($columns as $column => $ids) {
733 foreach($ids as $id => $val) $values[$table][$id][$column] = $val;
736 //die(print_r($values));
739 if($action) switch($action) {
743 if(!isset($replace)) $replace = true;
744 $table = $class ?
$class : 'item';
745 //print_r($values); //debug
746 $last = $this->db
->insert_or_update_multitab($values, $replace);
747 $last = $force_redirect ?
$force_redirect."?last=$last" : "$table/$last/";
748 $next = "$table/new/";
749 $message = $force_redirect ?
'' : 'Hotovo. Další záznam přidáte '.$this->html
->link('zde', $next).'.';
750 $this->post_redirect_get($last, $message);
753 if(!isset($_POST['sure']) ||
!$_POST['sure']) $this->post_redirect_get("$class/$id/edit", 'Sure user expected :-)');
754 $this->db
->delete($class, $id) ||
$this->post_redirect_get("$class/$id/edit", "V tabulce $class jentak neco mazat nebudes chlapecku :-P");
755 $this->post_redirect_get("$class", "Neco (pravdepodobne /$class/$id) bylo asi smazano. Fnuk :'-(");
758 $image_classes = array('model'); //TODO, use this more widely across the code
759 if(!in_array($class, $image_classes)) $this->post_redirect_get("$class/$id/edit", "Nekdo nechce k DB Tride '$class' prirazovat obrazky!");
760 $image_destination = DIR_IMAGES
."/$class/$id.jpg";
761 if($_FILES['image']['name'] == '') $this->post_redirect_get("$class/$id/edit", 'Everything has to be called somehow!', true);
762 if(move_uploaded_file($_FILES['image']['tmp_name'], $image_destination)) {
763 chmod ($image_destination, 0664);
764 $this->post_redirect_get("$class/$id", 'Image has been upbloated successfully :)');
765 } else $this->post_redirect_get("$class/$id/edit", 'File upload failed :(', true);
768 $this->post_redirect_get('', 'Nothin\' to do here my cutie :-*');
775 function process_http_request() {
778 @ini_set
('magic_quotes_gpc' , 'off');
779 if(get_magic_quotes_gpc()) {
780 die(trigger_error("Error: magic_quotes_gpc needs to be disabled! F00K!"));
783 $PATH_INFO=@trim
($_SERVER[PATH_INFO
]);
784 $PATH_CHUNKS = preg_split('/\//', $PATH_INFO);
786 if(!isset($PATH_CHUNKS[1])) $PATH_CHUNKS[1]='';
787 if($_SERVER['REQUEST_METHOD'] != 'POST' && $PATH_CHUNKS[1]!='barcode') echo $this->html
->header($PATH_INFO); //TODO: tyhle podminky naznacujou, ze je v navrhu nejaka drobna nedomyslenost...
788 switch($PATH_CHUNKS[1]) { //TODO: Move some branches to plugins if possible
790 die('Tell me why you cry');
792 case 'assistant': //assistant
793 $PATH_CHUNKS[3] = isset($PATH_CHUNKS[3]) ?
trim($PATH_CHUNKS[3]) : false;
794 $assistant_vars['SUBPATH'] = array_slice($PATH_CHUNKS, 3);
795 $assistant_vars['URL_INTERNAL'] = 'assistant/'.$PATH_CHUNKS[2];
796 $assistant_vars['URL'] = $_SERVER['SCRIPT_NAME'].'/'.$assistant_vars['URL_INTERNAL'];
797 echo $this->safe_include(DIR_ASSISTANTS
,$PATH_CHUNKS[2],$assistant_vars);
799 case 'barcode': //barcode
800 Barcode
::download_barcode(implode('/',array_slice($PATH_CHUNKS, 2)));
803 $search = (isset($_GET['q']) && trim($_GET['q']) != '') ?
trim($_GET['q']) : false;
804 $class = (isset($PATH_CHUNKS[1]) && $PATH_CHUNKS[1] != '') ?
$PATH_CHUNKS[1] : 'item';
805 if(!isset($PATH_CHUNKS[2])) $PATH_CHUNKS[2]='';
806 switch($PATH_CHUNKS[2]) {
808 $this->process_http_request_post($PATH_CHUNKS[2], $class);
809 echo $this->render_form_add($class);
812 $id = (isset($PATH_CHUNKS[2]) && is_numeric($PATH_CHUNKS[2]) ?
(int) $PATH_CHUNKS[2] : false);
813 if(!isset($PATH_CHUNKS[3])) $PATH_CHUNKS[3]='';
815 switch($PATH_CHUNKS[3]) {
816 case 'edit': //?/?/edit
817 case 'image': //?/?/image
818 case 'delete': //?/?/delete
819 $this->process_http_request_post($PATH_CHUNKS[3], $class, $id);
822 $history = $PATH_CHUNKS[3] == 'history' ?
true : false;
823 $limit = (int) (isset($PATH_CHUNKS[3]) ?
$PATH_CHUNKS[3] : '0');
824 $offset = (int) (isset($PATH_CHUNKS[4]) ?
$PATH_CHUNKS[4] : '0');
825 $where = false; //TODO get from URL
826 echo $this->render_items($class, $id, $limit, $offset, $where, $search, $history);
827 echo $this->render_listing_extensions($class, $id, $limit, $offset, $edit);
828 //print_r(array("<pre>",$_SERVER));
838 $sklad = new Sklad_UI();
839 $sklad->process_http_request();
This page took 0.93849 seconds and 5 git commands to generate.