X-Git-Url: http://git.harvie.cz/?a=blobdiff_plain;ds=sidebyside;f=index.php;h=f4fd40c3afb65ca18508675fab17a4890363a0ec;hb=5b0075faa84afd5c1ffda52926ef12fdff0cd74e;hp=5c54331a1e53f5144f62b6da2eb544a8047c613b;hpb=933b760a1a2f81a454fd894950a80868b1ebd5de;p=mirrors%2FSokoMan.git diff --git a/index.php b/index.php index 5c54331..f4fd40c 100755 --- a/index.php +++ b/index.php @@ -167,7 +167,7 @@ class Sklad_HTML extends HTML { //TODO: Split into few more methods * { font-family: arial; } td,body { background-color: white; } table { background-color: orange; border: orange; } -a { text-decoration:none; color: darkblue; } +a, a img { text-decoration:none; color: darkblue; border:none; } li a, a:hover { text-decoration:underline; } .menu li { @@ -322,21 +322,8 @@ EOF; return $this->table($table); } - function render_insert_form($class, $columns, $selectbox=array(), $current=false, $hidecols=false, $action=false, $multi_insert=true) { - //echo('
'); print_r($selectbox);
-		//echo('
'); print_r($current);
-		$update = false;
-		if(is_array($current)) {
-			$update = true;
-			$current = array_shift($current);
-		}
-
-		if(!is_array($hidecols)) $hidecols = array('item_author', 'item_valid_from', 'item_valid_till'); //TODO Autodetect
-
-		$action = $action ? " action='$action'" : false;
-		$html=""; //TODO: use $this->form()
-		if($multi_insert) $html.='
'; - //$html.=$this->input('table', $class, 'hidden'); + function render_insert_inputs($class,$columns,$selectbox,$current,$hidecols,$update) { + $html = ''; foreach($columns as $column) { $html.=T($class).':'.T($column['Field']).': '; $name="values[$class][".$column['Field'].'][]'; @@ -356,24 +343,71 @@ EOF; } $html.='
'; } + return $html; + } - if($multi_insert) { //TODO, move to separate JS file - $html.=<< -
- - + -EOF; + function render_insert_form_multi($array) { + $html = ''; + $head=false; + + foreach($array as $key => $args) { + $parts=array('inputs'); + if(!$head) { $head = true; + $parts[]='head'; + } + if(!isset($array[$key+1])) { + $parts[]='foot'; + $hr = ''; + } else $hr = '
'; + //$args[] = false; + $args[] = $parts; + $html .= call_user_func_array(array($this, 'render_insert_form'), $args); + $html .= $hr; + } + return $html; + } + + function render_insert_form($class, $columns, $selectbox=array(), $current=false, $hidecols=false, $action=false, $multi_insert=true, $parts=false) { + $html = ''; + //print_r($parts); + //echo('
'); print_r($selectbox);
+		//echo('
'); print_r($current);
+		$update = false;
+		if(is_array($current)) {
+			$update = true;
+			$current = array_shift($current);
 		}
 
-		$btn = is_array($current) ? 'UPDATE' : 'INSERT'; //TODO: $current may be set even when inserting...
-		$html.=$this->input(false, $btn, 'submit');
-		$html.='';
+		if(!is_array($hidecols)) $hidecols = array();
+		$hidecols = array_merge($hidecols, array('item_author', 'item_valid_from', 'item_valid_till')); //TODO Autodetect
+
+		if(!is_array($parts) || in_array('head', $parts)) {
+			$action = $action ? " action='$action'" : false;
+			$html.=""; //TODO: use $this->form()
+			$html.='
'; + } + + if(!is_array($parts) || in_array('inputs', $parts)) + $html.=$this->render_insert_inputs($class,$columns,$selectbox,$current,$hidecols,$update); + + if(!is_array($parts) || in_array('foot', $parts)) { + $html .= '

'; + if($multi_insert) { //TODO, move to separate JS file + $html.=<< + function duplicate_element(what, where) { + var node = document.getElementsByName(what)[0]; + node.parentNode.appendChild(node.cloneNode(true)); + } + + + +EOF; + } + + $btn = is_array($current) ? 'UPDATE' : 'INSERT'; //TODO: $current may be set even when inserting... + $html.=$this->input(false, $btn, 'submit'); + $html.=''; + } return $html; } } @@ -476,10 +510,14 @@ class Sklad_DB extends PDO { return $indexed; } - function get_columns($class) { + function get_columns($class,$disable_cols=array()) { //TODO: Not sure if compatible with non-MySQL DBs $class = $this->escape($class); $sql = "SHOW COLUMNS FROM $class;"; - return $this->safe_query_fetch($sql); + $columns = $this->safe_query_fetch($sql); + /*foreach($columns as $colk => $col) foreach($col as $key => $val) { + if(in_array($col['Field'],$disable_cols)) $columns[$colk]['Extra']='auto_increment'; + }*/ + return $columns; } function columns_get_selectbox($columns, $class=false, $suffix_id='_id', $suffix_name='_name') { @@ -500,12 +538,12 @@ class Sklad_DB extends PDO { return array_filter($selectbox, 'ksort'); } - function map_unique($key, $value, $select, $table) { //TODO: Guess $select and $table if not passed + function map_unique($key, $value, $select, $table, $fatal=true) { //TODO: Guess $select and $table if not passed $history = $this->contains_history($table) ? " AND ${table}_valid_till=0" : ''; $value=$this->quote($value); $sql = "SELECT $select FROM $table WHERE $key=$value$history LIMIT 1;"; //TODO use build_query_select()!!! $result = $this->safe_query_fetch($sql); - if(isset($result[0][$select])) return $result[0][$select]; else die(trigger_error(T('Record not found!'))); //TODO post_redirect_get... + if(isset($result[0][$select])) return $result[0][$select]; else if($fatal) die(trigger_error(T('Record not found!'))); //TODO post_redirect_get... } function contains_history($table) { @@ -536,7 +574,7 @@ class Sklad_DB extends PDO { $sql .= " WHERE ${table}_valid_till=0 AND ("; $or = ''; foreach($values as $row) { - $sql .= $or.' '.$table.'_id='.$row[$table.'_id']; + $sql .= $or.' '.$table.'_id='.$this->quote($row[$table.'_id']); $or = ' OR'; } $sql .= " );\n\n";