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>";
132 function head($title=false,$charset='UTF-8',$more='') {
133 $title = $title ?
"\n<title>$title</title>" : '';
135 $html.= '<meta http-equiv="Content-Type" content="text/html; charset='.$charset.'" />'.$title.$more;
142 * Trida poskytuje podpurne funkce pro generovani HTML kodu specificke pro sklad
144 * Tato trida by nemela sama nic vypisovat (vyjma chybovych a debugovacich hlasek)!
146 * @package Sklad_HTML
147 * @author Tomas Mudrunka
149 class Sklad_HTML
extends HTML
{ //TODO: Split into few more methods
150 function header($title='') {
152 $script = $_SERVER['SCRIPT_NAME'];
153 $search = htmlspecialchars(@trim
($_GET['q']));
154 $message = strip_tags(@trim
($_GET['message']),'<a><b><u><i>');
155 $instance = INSTANCE_ID
!= '' ?
'/'.INSTANCE_ID
: '';
156 //$title = T($title); //TODO
158 $html = $this->head("SōkoMan$title");
160 <h1><a href="$script/">SōkoMan</a><small>$instance$title</small></h1>
162 <style type="text/css">
163 * { font-family: arial; }
179 .menu, .menu * menu {
184 border: 1px solid orange;
189 .menu li:hover menu, .menu li:hover {
191 background-color: yellow;
200 foreach(scandir(DIR_ASSISTANTS
) as $item) {
201 if($item == '.' ||
$item == '..') continue;
202 $item = preg_replace('/\.inc\.php$/','',$item);
203 $assistants[$item] = "assistant/$item";
206 $tables=array('item','model','category','producer','vendor','room','status');
208 foreach($tables as $table) {
209 $listable[$table] = $table;
210 $insertable[$table] = "$table/new";
213 $html .= $this->ul(array(
215 'Logout' => '?logout',
216 0 => $this->ul($assistants,'menu',$this->link('Assistants','#')),
217 1 => $this->ul($insertable,'menu',$this->link('New','#')),
218 2 => $this->ul($listable,'menu',$this->link('List','#'))
219 ),'menu', '', 'menu');
221 $html .= '<div style="float: right;">';
223 $html .= $this->form("$script/assistant/go", 'GET', array(
224 array('q','','text','smart id...', 'autofocus'),
225 array(false,'go','submit')
226 ), 'style="float: left;"');
228 $html .= $this->form('?', 'GET', array(
229 array('q',$search,'text','regexp...'),
230 array(false,'filter','submit')
231 ), 'style="float: left;"');
237 <hr style="clear: both;" />
238 <div style="background-color:#FFDDDD;">
239 <font color="red">$message</font>
246 function internal_url($link) {
247 return $_SERVER['SCRIPT_NAME'].'/'.$link;
250 function table_add_images(&$table) {
251 $image = array('model_id');
252 foreach($table as $id => $row) {
253 foreach($image as $column) if(isset($table[$id][$column])) {
254 $type = @array_shift
(preg_split('/_/', $column));
255 $src=URL_IMAGES
."/$type/".$table[$id][$column].'.jpg';
256 $table[$id][$type.'_image']=$this->img($src, $table[$id][$column]);
261 function render_barcode($barcode,$opts=false) {
262 return $this->link($this->img($this->internal_url("barcode/$barcode"),$barcode,$opts),"barcode/$barcode",true,false);
265 function table_add_barcodes(&$table) {
266 $image = array('model_barcode', 'item_serial');
267 foreach($table as $id => $row) {
268 foreach($image as $column) if(isset($table[$id][$column])) {
269 $table[$id][$column]=$this->render_barcode($table[$id][$column]);
274 function table_collapse(&$table) {
276 'item_id' => 'item_id',
277 'model_id' => 'model_name',
278 'category_id' => 'category_name',
279 'producer_id' => 'producer_name',
280 'vendor_id' => 'vendor_name',
281 'room_id' => 'room_name',
282 'status_id' => 'status_name',
284 foreach($table as $id => $row) {
285 foreach($collapse as $link => $title)
286 if(isset($table[$id][$link]) && isset($row[$title])) {
287 $type = @array_shift
(preg_split('/_/', $link));
288 if($link != $title) unset($table[$id][$link]);
289 $table[$id][$title]=$this->link($row[$title], $type.'/'.$row[$link].'/');
294 function table_sort(&$table) {
295 $precedence = array('item_id', 'model_image', 'model_name','model_descript','category_name','status_name','room_name');
296 $table_sorted = array();
297 foreach($table as $id => $row) {
298 $table_sorted[$id] = array();
299 foreach($precedence as $column) if(isset($table[$id][$column])) {
300 $table_sorted[$id][T($column)]=$table[$id][$column];
301 unset($table[$id][$column]);
303 //$table_sorted[$id]=array_merge($table_sorted[$id],$table[$id]);
304 foreach($table[$id] as $key => $val) $table_sorted[$id][T($key)] = $val; //array_merge with T() translating
306 $table = $table_sorted;
309 function render_item_table($table) {
310 $this->table_add_images($table);
311 $this->table_add_barcodes($table);
312 $this->table_collapse($table);
313 $this->table_sort($table);
314 return $this->table($table);
317 function render_insert_form($class, $columns, $selectbox=array(), $current=false, $hidecols=false, $action=false, $multi_insert=true) {
318 //echo('<pre>'); print_r($selectbox);
319 //echo('<pre>'); print_r($current);
321 if(is_array($current)) {
323 $current = array_shift($current);
326 if(!is_array($hidecols)) $hidecols = array('item_author', 'item_valid_from', 'item_valid_till'); //TODO Autodetect
328 $action = $action ?
" action='$action'" : false;
329 $html="<form$action method='POST'>"; //TODO: use $this->form()
330 if($multi_insert) $html.='<span><div name="input_set" style="float:left; border:1px solid grey; padding: 1px; margin: 1px;">';
331 //$html.=$this->input('table', $class, 'hidden');
332 foreach($columns as $column) {
333 $html.=T($class).':<b>'.T($column['Field']).'</b>: ';
334 $name="values[$class][".$column['Field'].'][]';
335 $val = $update && isset($current[$column['Field']]) ?
$current[$column['Field']] : false;
337 case (preg_match('/auto_increment/', $column['Extra']) ||
in_array($column['Field'], $hidecols)):
339 $html.=$this->input($name, $val, 'hidden');
340 $html.=$val.'(AUTO)';
342 case isset($selectbox[$column['Field']]):
343 $html.=$this->select($name,$selectbox[$column['Field']],$val);
346 $html.=$this->input($name, $val);
352 if($multi_insert) { //TODO, move to separate JS file
355 <br style="clear:both" />
357 function duplicate_element(what, where) {
358 var node = document.getElementsByName(what)[0];
359 node.parentNode.appendChild(node.cloneNode(true));
362 <a href='#' onClick="duplicate_element('input_set')">+</a>
366 $btn = is_array($current) ?
'UPDATE' : 'INSERT'; //TODO: $current may be set even when inserting...
367 $html.=$this->input(false, $btn, 'submit');
374 * Trida poskytuje rozhrani k databazi skladu
377 * @author Tomas Mudrunka
379 class Sklad_DB
extends PDO
{
380 function __construct() {
381 $this->lms
= new Sklad_LMS();
384 DB_DSN
, DB_USER
, DB_PASS
,
385 array(PDO
::MYSQL_ATTR_INIT_COMMAND
=> "SET NAMES utf8") //Force UTF8 for MySQL
389 function escape($str) {
390 return preg_replace('(^.|.$)', '', $this->quote($str)); //TODO HACK
393 function build_query_select($class, $id=false, $limit=false, $offset=0, $where=false, $search=false, $history=false, $order=false, $suffix_id='_id') {
396 'item' => array('model', 'category', 'producer', 'vendor', 'room', 'status'),
397 'model' => array('category', 'producer')
398 ); //TODO Autodetect using foreign keys?
399 $search_fields = array(
400 'item' => array('item_id','item_serial','model_name','model_barcode','model_descript','producer_name','vendor_name')
404 $class = $this->escape($class);
407 $sql="SELECT * FROM $class\n";
409 if(isset($join[$class])) foreach($join[$class] as $j) $sql .= "LEFT JOIN $j USING($j$suffix_id)\n";
412 $search = $this->quote($search);
413 if(!isset($search_fields[$class])) die(trigger_error(T("Can't search in $class table yet :-("))); //TODO: post_redirect_get
415 foreach($search_fields[$class] as $column) $sql_search .= "OR $column REGEXP $search ";
416 $where[] = "FALSE $sql_search";
417 } elseif($id) $where[] = "$class$suffix_id = $id";
418 if(!$history && $this->contains_history($class)) $where[] = $class.'_valid_till=0';
420 if($where) $sql .= 'WHERE ('.implode(') AND (', $where).")\n";
422 if(!$order) $order = $class.$suffix_id;
423 if($this->contains_history($class)) $order .= ",${class}_valid_from DESC";
424 $sql .= "ORDER BY $order\n";
427 $limit = $this->escape((int)$limit);
428 $offset = $this->escape((int)$offset);
429 $sql .= "LIMIT $offset,$limit\n";
435 function safe_query($sql, $fatal=true) {
436 $result = $this->query($sql);
438 $error = $this->errorInfo();
439 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>");
445 function translate_query_results($result) {
446 $translate_cols = array('status_name', 'item_valid_till'); //TODO: Hardcoded
447 foreach($result as $key => $row) {
448 foreach($translate_cols as $col) if(isset($result[$key][$col])){
449 $result[$key][$col] = T($result[$key][$col]);
455 function safe_query_fetch($sql, $fatal=true, $fetch_flags = PDO
::FETCH_ASSOC
, $translate=true) {
456 $result = $this->safe_query($sql, $fatal)->fetchAll($fetch_flags);
457 if($translate) $result = $this->translate_query_results($result);
462 function get_listing($class, $id=false, $limit=false, $offset=0, $where=false, $search=false, $history=false, $indexed=array(), $suffix_id='_id') {
463 $sql = $this->build_query_select($class, $id, $limit, $offset, $where, $search, $history);
464 $result = $this->safe_query_fetch($sql);
465 if(!$result ||
!is_array($indexed)) return $result;
467 foreach($result as $key => $row) $indexed[$row[$class.$suffix_id]]=$row;
471 function get_columns($class) {
472 $class = $this->escape($class);
473 $sql = "SHOW COLUMNS FROM $class;";
474 return $this->safe_query_fetch($sql);
477 function columns_get_selectbox($columns, $class=false, $suffix_id='_id', $suffix_name='_name') {
479 foreach($columns as $column) {
480 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)!
481 if($class && $column['Field'] == $class.$suffix_id) continue;
482 if(!preg_match('/'.$suffix_id.'$/', $column['Field'])) continue;
483 $table=preg_replace('/'.$suffix_id.'$/','',$column['Field']);
485 $history = $this->contains_history($table) ?
" WHERE ${table}_valid_till=0" : '';
486 $sql = "SELECT $table$suffix_id, $table$suffix_name FROM $table$history;"; //TODO use build_query_select()!!!
487 $result = $this->safe_query_fetch($sql, false);
488 if(!$result) continue;
489 foreach($result as $row) $selectbox[$table.$suffix_id][$row[$table.$suffix_id]]=$row[$table.$suffix_name];
491 //echo('<pre>'); print_r($selectbox);
492 return array_filter($selectbox, 'ksort');
495 function map_unique($key, $value, $select, $table) { //TODO: Guess $select and $table if not passed
496 $history = $this->contains_history($table) ?
" AND ${table}_valid_till=0" : '';
497 $value=$this->quote($value);
498 $sql = "SELECT $select FROM $table WHERE $key=$value$history LIMIT 1;"; //TODO use build_query_select()!!!
499 $result = $this->safe_query_fetch($sql);
500 if(isset($result[0][$select])) return $result[0][$select]; else die(trigger_error(T('Record not found!'))); //TODO post_redirect_get...
503 function contains_history($table) {
504 $history_tables = array('item'); //TODO Autodetect
505 return in_array($table, $history_tables);
508 function build_query_insert($table, $values, $replace=true, $suffix_id='_id') {
510 $history = $this->contains_history($table);
513 $table = $this->escape($table);
515 //Get list of POSTed columns
516 $columns_array = array_map(array($this,'escape'), array_keys($values[0]));
517 $columns = implode(',',$columns_array);
521 //echo('<pre>'); die(print_r($values));
524 $history_update=false; foreach($values as $row) if(is_numeric($row[$table.'_id'])) $history_update=true;
525 if($history_update) {
526 $sql .= "UPDATE $table";
527 $sql .= " SET ${table}_valid_till=NOW()";
528 $sql .= " WHERE ${table}_valid_till=0 AND (";
530 foreach($values as $row) {
531 $sql .= $or.' '.$table.'_id='.$row[$table.'_id'];
539 //Insert into table (columns)
540 $sql .= "INSERT INTO $table ($columns) VALUES ";
542 //Values (a,b,c),(d,e,f)
544 foreach($values as $row) {
545 $row_quoted = array_map(array($this,'quote'), $row); //Check
547 foreach($row as $column => $value) {
549 case $table.'_valid_from':
550 $row_quoted[$column] = 'NOW()';
552 case $table.'_valid_till':
553 $row_quoted[$column] = '0';
555 case $table.'_author':
556 $row_quoted[$column] = $this->lms
->get_authorized_user_id();
557 //die($this->lms->get_authorized_user_id().'=USER');
562 $sql .= $comma.'('.implode(',',$row_quoted).')';
568 foreach($columns_array as $col) {
569 if($col == $table.'_id' ||
$col == $table.'_valid_till') continue;
570 $on_duplicate[] = "$col=VALUES($col)";
572 $sql .= "\nON DUPLICATE KEY UPDATE ".implode(',', $on_duplicate);
580 function insert_or_update($table, $values, $replace=true) {
581 $sql = $this->build_query_insert($table, $values, $replace);
582 $this->safe_query($sql);
583 return $this->lastInsertId();
586 function insert_or_update_multitab($values, $replace=true) {
588 foreach($values as $table => $rows) $last = $this->insert_or_update($table, $rows, $replace);
592 function delete($table, $id, $suffix_id='_id') {
593 if($this->contains_history($table)) return false;
594 $key = $this->escape($table.$suffix_id);
595 $table = $this->escape($table);
596 $id = $this->quote($id);
597 return $this->safe_query("DELETE FROM $table WHERE $key = $id LIMIT 1;");
602 * Trida poskytuje high-level rozhrani k databazi skladu
604 * @package Sklad_DB_Abstract
605 * @author Tomas Mudrunka
607 class Sklad_DB_Abstract
extends Sklad_DB
{
612 * Trida implementuje uzivatelske rozhrani skladu
615 * $sklad = new Sklad_UI();
616 * $sklad->process_http_request();
619 * @author Tomas Mudrunka
622 function __construct() {
623 $this->db
= new Sklad_DB();
624 $this->html
= new Sklad_HTML();
627 function render_items($class, $id=false, $limit=false, $offset=0, $where=false, $search=false, $history=false) {
628 return $this->html
->render_item_table($this->db
->get_listing($class, $id, $limit, $offset, $where, $search, $history, false));
631 function render_form_add($class) {
632 $columns = $this->db
->get_columns($class);
633 $selectbox = $this->db
->columns_get_selectbox($columns, $class);
634 return $this->html
->render_insert_form($class, $columns, $selectbox);
637 function render_form_edit($class, $id) {
638 $columns = $this->db
->get_columns($class);
639 $selectbox = $this->db
->columns_get_selectbox($columns, $class);
640 $current = $this->db
->get_listing($class, $id, 1);
641 return $this->html
->render_insert_form($class, $columns, $selectbox, $current);
644 function render_single_record_details($class, $id) {
646 $id_prev = $id - 1 > 0 ?
$id - 1 : 0;
647 $get = $_SERVER['QUERY_STRING'] != '' ?
'?'.$_SERVER['QUERY_STRING'] : '';
649 $html.= $this->html
->link('<<', "$class/$id_prev/");
651 $html.= $this->html
->link('>>', "$class/$id_next/");
653 $html.='<span style="float:right;">'.$this->html
->render_barcode(BARCODE_PREFIX
.strtoupper("$class/$id")).'</span>';
654 $html.= $this->html
->link('edit', "$class/$id/edit/");
655 if($this->db
->contains_history($class)) $html.= ' ][ '.$this->html
->link('history', "$class/$id/history/");
659 function render_listing_navigation($class, $id, $limit, $offset) {
660 $offset_next = $offset +
$limit;
661 $offset_prev = $offset - $limit > 0 ?
$offset - $limit : 0;
662 $get = $_SERVER['QUERY_STRING'] != '' ?
'?'.$_SERVER['QUERY_STRING'] : '';
664 $html.= $this->html
->link('<<', "$class/$id/$limit/$offset_prev/$get");
666 $html.= $this->html
->link('>>', "$class/$id/$limit/$offset_next/$get");
668 $html.= $this->html
->link('new', "$class/new/$get");
672 function render_listing_extensions($class, $id, $limit, $offset, $edit=false) {
674 if(is_numeric($id)) {
675 $html.=$this->render_single_record_details($class, $id);
677 $html.=$this->render_listing_navigation($class, '*', $limit, $offset);
680 $html.= $this->render_form_edit($class, $id);
681 $action = $_SERVER['SCRIPT_NAME']."/$class/$id/delete";
682 $html.=$this->html
->form($action,'POST',array(
683 array(false,'DELETE','submit'),
684 array('sure', false, 'checkbox', false, false, 'sure?')
686 $action = $_SERVER['SCRIPT_NAME']."/$class/$id/image";
687 $html.=$this->html
->form($action,'POST',array(
688 array('image', false, 'file', false, 'size="30"'),
689 array(false, 'IMAGE', 'submit')
690 ), "enctype='multipart/form-data'");
695 function check_auth() {
696 new HTTP_Auth('SkladovejSystem', true, array($this->db
->lms
,'check_auth'));
699 function post_redirect_get($location, $message='', $error=false) {
700 $url_args = $message != '' ?
'?message='.urlencode(T($message)) : '';
701 $location = $this->html
->internal_url($location).$url_args;
702 header('Location: '.$location);
703 if($error) trigger_error($message);
704 $location=htmlspecialchars($location);
706 "<meta http-equiv='refresh' content='0; url=$location'>".
707 T($message)."<br />Location: <a href='$location'>$location</a>"
711 function safe_include($dir,$name,$vars=array(),$ext='.inc.php') {
712 if(preg_match('/[^a-zA-Z0-9-]/',$name)) $this->post_redirect_get('', 'SAFE INCLUDE: Securityfuck.', true);
713 $filename="$dir/$name$ext";
714 if(!is_file($filename)) $this->post_redirect_get('', 'SAFE INCLUDE: Fuckfound.', true);
715 foreach($vars as $var => $val) $
$var=$val;
718 $out=ob_get_contents();
723 function process_http_request_post($action=false, $class=false, $id=false, $force_redirect=false) {
724 if($_SERVER['REQUEST_METHOD'] != 'POST') return;
725 //echo('<pre>'); //DEBUG (maybe todo remove), HEADERS ALREADY SENT!!!!
729 /* Tenhle foreach() prekopiruje promenne
730 * z: $_POST['values'][$table][$column][$id];
731 * do: $values[$table][$id][$column]
733 if(isset($_POST['values'])) {
735 foreach($_POST['values'] as $table => $columns) {
736 foreach($columns as $column => $ids) {
737 foreach($ids as $id => $val) $values[$table][$id][$column] = $val;
740 //die(print_r($values));
743 if($action) switch($action) {
747 if(!isset($replace)) $replace = true;
748 $table = $class ?
$class : 'item';
749 //print_r($values); //debug
750 $last = $this->db
->insert_or_update_multitab($values, $replace);
751 $last = $force_redirect ?
$force_redirect."?last=$last" : "$table/$last/";
752 $next = "$table/new/";
753 $message = $force_redirect ?
'' : 'Hotovo. Další záznam přidáte '.$this->html
->link('zde', $next).'.';
754 $this->post_redirect_get($last, $message);
757 if(!isset($_POST['sure']) ||
!$_POST['sure']) $this->post_redirect_get("$class/$id/edit", 'Sure user expected :-)');
758 $this->db
->delete($class, $id) ||
$this->post_redirect_get("$class/$id/edit", "V tabulce $class jentak neco mazat nebudes chlapecku :-P");
759 $this->post_redirect_get("$class", "Neco (pravdepodobne /$class/$id) bylo asi smazano. Fnuk :'-(");
762 $image_classes = array('model'); //TODO, use this more widely across the code
763 if(!in_array($class, $image_classes)) $this->post_redirect_get("$class/$id/edit", "Nekdo nechce k DB Tride '$class' prirazovat obrazky!");
764 $image_destination = DIR_IMAGES
."/$class/$id.jpg";
765 if($_FILES['image']['name'] == '') $this->post_redirect_get("$class/$id/edit", 'Everything has to be called somehow!', true);
766 if(move_uploaded_file($_FILES['image']['tmp_name'], $image_destination)) {
767 chmod ($image_destination, 0664);
768 $this->post_redirect_get("$class/$id", 'Image has been upbloated successfully :)');
769 } else $this->post_redirect_get("$class/$id/edit", 'File upload failed :(', true);
772 $this->post_redirect_get('', 'Nothin\' to do here my cutie :-*');
779 function process_http_request() {
782 @ini_set
('magic_quotes_gpc' , 'off');
783 if(get_magic_quotes_gpc()) {
784 die(trigger_error("Error: magic_quotes_gpc needs to be disabled! F00K!"));
787 $PATH_INFO=@trim
($_SERVER[PATH_INFO
]);
788 $PATH_CHUNKS = preg_split('/\//', $PATH_INFO);
790 if(!isset($PATH_CHUNKS[1])) $PATH_CHUNKS[1]='';
791 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...
792 switch($PATH_CHUNKS[1]) { //TODO: Move some branches to plugins if possible
794 die('Tell me why you cry');
796 case 'assistant': //assistant
797 $PATH_CHUNKS[3] = isset($PATH_CHUNKS[3]) ?
trim($PATH_CHUNKS[3]) : false;
798 $assistant_vars['SUBPATH'] = array_slice($PATH_CHUNKS, 3);
799 $assistant_vars['URL_INTERNAL'] = 'assistant/'.$PATH_CHUNKS[2];
800 $assistant_vars['URL'] = $_SERVER['SCRIPT_NAME'].'/'.$assistant_vars['URL_INTERNAL'];
801 echo $this->safe_include(DIR_ASSISTANTS
,$PATH_CHUNKS[2],$assistant_vars);
803 case 'barcode': //barcode
804 Barcode
::download_barcode(implode('/',array_slice($PATH_CHUNKS, 2)));
807 $search = (isset($_GET['q']) && trim($_GET['q']) != '') ?
trim($_GET['q']) : false;
808 $class = (isset($PATH_CHUNKS[1]) && $PATH_CHUNKS[1] != '') ?
$PATH_CHUNKS[1] : 'item';
809 if(!isset($PATH_CHUNKS[2])) $PATH_CHUNKS[2]='';
810 switch($PATH_CHUNKS[2]) {
812 $this->process_http_request_post($PATH_CHUNKS[2], $class);
813 echo $this->render_form_add($class);
816 $id = (isset($PATH_CHUNKS[2]) && is_numeric($PATH_CHUNKS[2]) ?
(int) $PATH_CHUNKS[2] : false);
817 if(!isset($PATH_CHUNKS[3])) $PATH_CHUNKS[3]='';
819 switch($PATH_CHUNKS[3]) {
820 case 'edit': //?/?/edit
821 case 'image': //?/?/image
822 case 'delete': //?/?/delete
823 $this->process_http_request_post($PATH_CHUNKS[3], $class, $id);
826 $history = $PATH_CHUNKS[3] == 'history' ?
true : false;
827 $limit = (int) (isset($PATH_CHUNKS[3]) ?
$PATH_CHUNKS[3] : '0');
828 $offset = (int) (isset($PATH_CHUNKS[4]) ?
$PATH_CHUNKS[4] : '0');
829 $where = false; //TODO get from URL
830 echo $this->render_items($class, $id, $limit, $offset, $where, $search, $history);
831 echo $this->render_listing_extensions($class, $id, $limit, $offset, $edit);
832 //print_r(array("<pre>",$_SERVER));
842 $sklad = new Sklad_UI();
843 $sklad->process_http_request();
845 echo('<br style="clear:both;" /><hr />');
This page took 0.9558 seconds and 5 git commands to generate.