| version 1.4, 2006/09/16 23:01:13 |
version 1.5, 2007/09/02 23:08:44 |
|
|
| * http://platon.sk/projects/phpMyEdit/ |
* http://platon.sk/projects/phpMyEdit/ |
| */ |
*/ |
| |
|
| /* $Platon: phpMyEdit/phpMyEdit.class.php,v 1.188 2006-09-08 16:30:31 michal Exp $ */ |
/* $Platon: phpMyEdit/phpMyEdit.class.php,v 1.199 2007-09-02 21:48:32 nepto Exp $ */ |
| |
|
| /* This is a generic table editing program. The table and fields to be |
/* This is a generic table editing program. The table and fields to be |
| edited are defined in the calling program. |
edited are defined in the calling program. |
| |
|
| This program works in three passes. |
This program works in three passes. |
| * Pass 1 (the last part of the program) displays the selected MySQL |
* Pass 1 (the last part of the program) displays the selected SQL |
| table in a scrolling table on the screen. Radio buttons are used to |
table in a scrolling table on the screen. Radio buttons are used to |
| select a record for editing or deletion. If the user chooses Add, |
select a record for editing or deletion. If the user chooses Add, |
| Change, Copy, View or Delete buttons. |
Change, Copy, View or Delete buttons. |
|
|
| var $pw; // password |
var $pw; // password |
| var $tb; // table |
var $tb; // table |
| var $db; // database |
var $db; // database |
| var $dbp; // database with point |
var $dbp; // database with point and delimiters |
| var $dbh; // database handle |
var $dbh; // database handle |
| var $close_dbh; // if database handle should be closed |
var $close_dbh; // if database handle should be closed |
| |
|
|
|
| var $navigation; // navigation style |
var $navigation; // navigation style |
| var $tabs; // TAB names |
var $tabs; // TAB names |
| var $timer = null; // phpMyEdit_timer object |
var $timer = null; // phpMyEdit_timer object |
| |
var $sd; var $ed; // sql start and end delimiters '`' in case of MySQL |
| |
|
| // Predefined variables |
// Predefined variables |
| var $comp_ops = array('<'=>'<','<='=>'<=','='=>'=','>='=>'>=','>'=>'>'); |
var $comp_ops = array('<'=>'<','<='=>'<=','='=>'=','>='=>'>=','>'=>'>'); |
|
|
| } |
} |
| } /* }}} */ |
} /* }}} */ |
| |
|
| |
/* |
| |
* sql functions |
| |
*/ |
| |
function sql_connect() /* {{{ */ |
| |
{ |
| |
$this->dbh = @ini_get('allow_persistent') |
| |
? @mysql_pconnect($this->hn, $this->un, $this->pw) |
| |
: @mysql_connect($this->hn, $this->un, $this->pw); |
| |
} /* }}} */ |
| |
|
| |
|
| |
function sql_disconnect() /* {{{ */ |
| |
{ |
| |
if ($this->close_dbh) { |
| |
@mysql_close($this->dbh); |
| |
$this->dbh = null; |
| |
} |
| |
} /* }}} */ |
| |
|
| |
function sql_fetch(&$res, $type = 'a') /* {{{ */ |
| |
{ |
| |
if($type == 'n') $type = MYSQL_NUM; |
| |
else $type = MYSQL_ASSOC; |
| |
return @mysql_fetch_array($res, $type); |
| |
} /* }}} */ |
| |
|
| |
function sql_free_result(&$res) /* {{{ */ |
| |
{ |
| |
return @mysql_free_result($res); |
| |
} /* }}} */ |
| |
|
| |
function sql_affected_rows(&$dbh) /* {{{ */ |
| |
{ |
| |
return @mysql_affected_rows($dbh); |
| |
} /* }}} */ |
| |
|
| |
function sql_field_len(&$res,$field) /* {{{ */ |
| |
{ |
| |
return @mysql_field_len($res, $field); |
| |
} /* }}} */ |
| |
|
| |
function sql_insert_id() /* {{{ */ |
| |
{ |
| |
return mysql_insert_id($this->dbh); |
| |
} /* }}} */ |
| |
|
| |
function sql_limit($start, $more) /* {{{ */ |
| |
{ |
| |
return ' LIMIT '.$start.', '.$more.' '; |
| |
} /* }}} */ |
| |
|
| |
function sql_delimiter() /* {{{ */ |
| |
{ |
| |
$this->sd = '`'; $this->ed='`'; |
| |
return $this->sd; |
| |
} /* }}} */ |
| |
|
| |
|
| function myquery($qry, $line = 0, $debug = 0) /* {{{ */ |
function myquery($qry, $line = 0, $debug = 0) /* {{{ */ |
| { |
{ |
| global $debug_query; |
global $debug_query; |
| if ($debug_query || $debug) { |
if ($debug_query || $debug) { |
| $line = intval($line); |
$line = intval($line); |
| echo '<h4>MySQL query at line ',$line,'</h4>',htmlspecialchars($qry),'<hr />',"\n"; |
echo '<h4>MySQL query at line ',$line,'</h4>',htmlspecialchars($qry),'<hr size="1" />',"\n"; |
| } |
} |
| if (isset($this->db)) { |
if (isset($this->db)) { |
| $ret = @mysql_db_query($this->db, $qry, $this->dbh); |
$ret = @mysql_db_query($this->db, $qry, $this->dbh); |
|
|
| } |
} |
| if (! $ret) { |
if (! $ret) { |
| echo '<h4>MySQL error ',mysql_errno($this->dbh),'</h4>'; |
echo '<h4>MySQL error ',mysql_errno($this->dbh),'</h4>'; |
| echo htmlspecialchars(mysql_error($this->dbh)),'<hr />',"\n"; |
echo htmlspecialchars(mysql_error($this->dbh)),'<hr size="1" />',"\n"; |
| } |
} |
| return $ret; |
return $ret; |
| } /* }}} */ |
} /* }}} */ |
| |
|
| |
/* end of sql functions */ |
| |
|
| function make_language_labels($language) /* {{{ */ |
function make_language_labels($language) /* {{{ */ |
| { |
{ |
| // just try the first language and variant |
// just try the first language and variant |
|
|
| function set_values_from_table($field_num, $strict = false) /* {{{ */ |
function set_values_from_table($field_num, $strict = false) /* {{{ */ |
| { |
{ |
| $db = &$this->fdd[$field_num]['values']['db']; |
$db = &$this->fdd[$field_num]['values']['db']; |
| $table = &$this->fdd[$field_num]['values']['table']; |
$table = $this->sd.$this->fdd[$field_num]['values']['table'].$this->ed; |
| $key = &$this->fdd[$field_num]['values']['column']; |
$key = &$this->fdd[$field_num]['values']['column']; |
| $desc = &$this->fdd[$field_num]['values']['description']; |
$desc = &$this->fdd[$field_num]['values']['description']; |
| $dbp = isset($db) ? "$db." : $this->dbp; |
$dbp = isset($db) ? $this->sd.$db.$this->ed.'.' : $this->dbp; |
| $qparts['type'] = 'select'; |
$qparts['type'] = 'select'; |
| if ($table) { |
if ($table != $this->sd.$this->ed) { |
| $qparts['select'] = 'DISTINCT '.$table.'.'.$key; |
$qparts['select'] = 'DISTINCT '.$table.'.'.$this->sd.$key.$this->ed; |
| if ($desc && is_array($desc) && is_array($desc['columns'])) { |
if ($desc && is_array($desc) && is_array($desc['columns'])) { |
| $qparts['select'] .= ',CONCAT('; // ) |
$qparts['select'] .= ',CONCAT('; // ) |
| $num_cols = sizeof($desc['columns']); |
$num_cols = sizeof($desc['columns']); |
|
|
| } |
} |
| foreach ($desc['columns'] as $key => $val) { |
foreach ($desc['columns'] as $key => $val) { |
| if ($val) { |
if ($val) { |
| $qparts['select'] .= 'IFNULL('.$val.',"")'; |
$qparts['select'] .= 'IFNULL(CAST('.$this->sd.$val.$this->ed.' AS CHAR),"")'; |
| if ($desc['divs'][$key]) { |
if ($desc['divs'][$key]) { |
| $qparts['select'] .= ',"'.addslashes($desc['divs'][$key]).'"'; |
$qparts['select'] .= ',"'.addslashes($desc['divs'][$key]).'"'; |
| } |
} |
|
|
| } |
} |
| } |
} |
| $qparts['select']{strlen($qparts['select']) - 1} = ')'; |
$qparts['select']{strlen($qparts['select']) - 1} = ')'; |
| $qparts['select'] .= ' AS PMEalias'.$field_num; |
$qparts['select'] .= ' AS '.$this->sd.'PMEalias'.$field_num.$this->ed; |
| $qparts['orderby'] = 'PMEalias'.$field_num; |
$qparts['orderby'] = $this->sd.'PMEalias'.$field_num.$this->ed; |
| } else if ($desc && is_array($desc)) { |
} else if ($desc && is_array($desc)) { |
| // TODO |
// TODO |
| } else if ($desc) { |
} else if ($desc) { |
| $qparts['select'] .= ','.$table.'.'.$desc; |
$qparts['select'] .= ','.$table.'.'.$this->sd.$desc.$this->ed; |
| $qparts['orderby'] = $desc; |
$qparts['orderby'] = $this->sd.$desc.$this->ed; |
| } else if ($key) { |
} else if ($key) { |
| $qparts['orderby'] = $key; |
$qparts['orderby'] = $this->sd.$key.$this->ed; |
| } |
} |
| $qparts['from'] = "$dbp$table"; |
$qparts['from'] = $dbp.$table; |
| $ar = array( |
$ar = array( |
| 'table' => $table, |
'table' => $table, |
| 'column' => $column, |
'column' => $column, |
|
|
| } else { /* simple value extraction */ |
} else { /* simple value extraction */ |
| $key = &$this->fds[$field_num]; |
$key = &$this->fds[$field_num]; |
| $this->virtual($field_num) && $key = $this->fqn($field_num); |
$this->virtual($field_num) && $key = $this->fqn($field_num); |
| $qparts['select'] = 'DISTINCT '.$key.' AS PMEkey'; |
$qparts['select'] = 'DISTINCT '.$this->sd.$key.$this->ed.' AS PMEkey'; |
| $qparts['orderby'] = 'PMEkey'; |
$qparts['orderby'] = 'PMEkey'; |
| $qparts['from'] = $this->dbp.$this->tb; |
$qparts['from'] = $this->dbp.$this->sd.$this->tb.$this->ed; |
| } |
} |
| $values = array(); |
$values = array(); |
| $res = $this->myquery($this->get_SQL_query($qparts), __LINE__); |
$res = $this->myquery($this->get_SQL_query($qparts), __LINE__); |
| while ($row = @mysql_fetch_array($res, MYSQL_NUM)) { |
while ($row = $this->sql_fetch($res, 'n')) { |
| $values[$row[0]] = $desc ? $row[1] : $row[0]; |
$values[$row[0]] = $desc ? $row[1] : $row[0]; |
| } |
} |
| return $values; |
return $values; |
|
|
| if ($this->add_operation() |
if ($this->add_operation() |
| || $this->copy_operation() |
|| $this->copy_operation() |
| || $this->change_operation()) { |
|| $this->change_operation()) { |
| $ret = 'PMEtable0.'.$this->fds[$field]; |
$ret = $this->sd.'PMEtable0'.$this->ed.'.'.$this->sd.$this->fds[$field].$this->ed; |
| } else { |
} else { |
| if ($this->fdd[$this->fds[$field]]['values']['description'] && ! $dont_desc) { |
if ($this->fdd[$this->fds[$field]]['values']['description'] && ! $dont_desc) { |
| $desc = &$this->fdd[$this->fds[$field]]['values']['description']; |
$desc = &$this->fdd[$this->fds[$field]]['values']['description']; |
|
|
| } |
} |
| foreach ($desc['columns'] as $key => $val) { |
foreach ($desc['columns'] as $key => $val) { |
| if ($val) { |
if ($val) { |
| $ret .= 'PMEjoin'.$field.'.'.$val; |
$ret .= 'IFNULL(CAST('.$this->sd.'PMEjoin'.$field.$this->ed.'.'.$this->sd.$val.$this->ed.' AS CHAR),"")'; |
| if ($desc['divs'][$key]) { |
if ($desc['divs'][$key]) { |
| $ret .= ',"'.addslashes($desc['divs'][$key]).'"'; |
$ret .= ',"'.addslashes($desc['divs'][$key]).'"'; |
| } |
} |
|
|
| } else if (is_array($desc)) { |
} else if (is_array($desc)) { |
| // TODO |
// TODO |
| } else { |
} else { |
| $ret = 'PMEjoin'.$field.'.'.$this->fdd[$this->fds[$field]]['values']['description']; |
$ret = 'PMEjoin'.$field.'.'.$this->sd.$this->fdd[$this->fds[$field]]['values']['description'].$this->ed; |
| } |
} |
| // TODO: remove me |
// TODO: remove me |
| } elseif (0 && $this->fdd[$this->fds[$field]]['values']['column'] && ! $dont_cols) { |
} elseif (0 && $this->fdd[$this->fds[$field]]['values']['column'] && ! $dont_cols) { |
| $ret = 'PMEjoin'.$field.'.'.$this->fdd[$this->fds[$field]]['values']['column']; |
$ret = 'PMEjoin'.$field.'.'.$this->fdd[$this->fds[$field]]['values']['column']; |
| } else { |
} else { |
| $ret = 'PMEtable0.'.$this->fds[$field]; |
$ret = $this->sd.'PMEtable0'.$this->ed.'.'.$this->sd.$this->fds[$field].$this->ed; |
| } |
} |
| // TODO: not neccessary, remove me! |
// TODO: not neccessary, remove me! |
| if (is_array($this->fdd[$this->fds[$field]]['values2'])) { |
if (is_array($this->fdd[$this->fds[$field]]['values2'])) { |
|
|
| return $ret; |
return $ret; |
| } /* }}} */ |
} /* }}} */ |
| |
|
| |
function get_SQL_main_list_query($qparts) /* {{{ */ |
| |
{ |
| |
return $this->get_SQL_query($qparts); |
| |
} /* }}} */ |
| |
|
| |
|
| |
|
| function get_SQL_query($parts) /* {{{ */ |
function get_SQL_query($parts) /* {{{ */ |
| { |
{ |
| foreach ($parts as $k => $v) { |
foreach ($parts as $k => $v) { |
|
|
| if (! $this->displayed[$k] && $k != $this->key_num) { |
if (! $this->displayed[$k] && $k != $this->key_num) { |
| continue; |
continue; |
| } |
} |
| $fields[] = $this->fqn($k).' AS qf'.$k; |
$fields[] = $this->fqn($k).' AS '.$this->sd.'qf'.$k.$this->ed; // no delimiters here, or maybe some yes |
| if ($this->col_has_values($k)) { |
if ($this->col_has_values($k)) { |
| $fields[] = $this->fqn($k, true, true).' AS qf'.$k.'_idx'; |
$fields[] = $this->fqn($k, true, true).' AS '.$this->sd.'qf'.$k.'_idx'.$this->ed; |
| } |
} |
| if ($this->col_has_datemask($k)) { |
if ($this->col_has_datemask($k)) { |
| $fields[] = 'UNIX_TIMESTAMP('.$this->fqn($k).') AS qf'.$k.'_timestamp'; |
$fields[] = 'UNIX_TIMESTAMP('.$this->fqn($k).') AS '.$this->sd.'qf'.$k.'_timestamp'.$this->ed; |
| } |
} |
| } |
} |
| return join(',', $fields); |
return join(',', $fields); |
|
|
| |
|
| function get_SQL_join_clause() /* {{{ */ |
function get_SQL_join_clause() /* {{{ */ |
| { |
{ |
| $main_table = 'PMEtable0'; |
$main_table = $this->sd.'PMEtable0'.$this->ed; |
| $join_clause = $this->tb." AS $main_table"; |
$join_clause = $this->sd.$this->tb.$this->ed." AS $main_table"; |
| for ($k = 0, $numfds = sizeof($this->fds); $k < $numfds; $k++) { |
for ($k = 0, $numfds = sizeof($this->fds); $k < $numfds; $k++) { |
| $main_column = $this->fds[$k]; |
$main_column = $this->fds[$k]; |
| if($this->fdd[$main_column]['values']['db']) { |
if($this->fdd[$main_column]['values']['db']) { |
| $dbp = $this->fdd[$main_column]['values']['db'].'.'; |
$dbp = $this->sd.$this->fdd[$main_column]['values']['db'].$this->ed.'.'; |
| } else { |
} else { |
| $dbp = $this->dbp; |
$dbp = $this->dbp; |
| } |
} |
| $table = @$this->fdd[$main_column]['values']['table']; |
$table = $this->sd.$this->fdd[$main_column]['values']['table'].$this->ed; |
| $join_column = @$this->fdd[$main_column]['values']['column']; |
$join_column = $this->sd.$this->fdd[$main_column]['values']['column'].$this->ed; |
| $join_desc = @$this->fdd[$main_column]['values']['description']; |
$join_desc = $this->sd.$this->fdd[$main_column]['values']['description'].$this->ed; |
| if ($join_desc != '' && $join_column != '') { |
if ($join_desc != $this->sd.$this->ed && $join_column != $this->sd.$this->ed) { |
| $join_table = 'PMEjoin'.$k; |
$join_table = $this->sd.'PMEjoin'.$k.$this->ed; |
| $ar = array( |
$ar = array( |
| 'main_table' => $main_table, |
'main_table' => $main_table, |
| 'main_column' => $main_column, |
'main_column' => $this->sd.$main_column.$this->ed, |
| 'join_table' => $join_table, |
'join_table' => $join_table, |
| 'join_column' => $join_column, |
'join_column' => $join_column, |
| 'join_description' => $join_desc); |
'join_description' => $join_desc); |
| $join_clause .= " LEFT OUTER JOIN $dbp$table AS $join_table ON ("; |
$join_clause .= " LEFT OUTER JOIN $dbp".$table." AS $join_table ON ("; |
| $join_clause .= isset($this->fdd[$main_column]['values']['join']) |
$join_clause .= isset($this->fdd[$main_column]['values']['join']) |
| ? $this->substituteVars($this->fdd[$main_column]['values']['join'], $ar) |
? $this->substituteVars($this->fdd[$main_column]['values']['join'], $ar) |
| : "$join_table.$join_column = $main_table.$main_column"; |
: "$join_table.$join_column = $main_table.".$this->sd.$main_column.$this->ed; |
| if (isset($this->fdd[$main_column]['values']['filters'])) { |
if (isset($this->fdd[$main_column]['values']['filters'])) { |
| $join_clause .= ' AND '; |
$join_clause .= ' AND '; |
| $join_clause .= $this->substituteVars($this->fdd[$main_column]['values']['filters'], $ar); |
$join_clause .= $this->substituteVars($this->fdd[$main_column]['values']['filters'], $ar); |
| Line 834 function '.$this->js['prefix'].'form_con |
|
| Line 902 function '.$this->js['prefix'].'form_con |
|
| } |
} |
| } |
} |
| |
|
| /* Multiple selects have their name like ``name[]''. |
/* Multiple selects have their name like ''name[]''. |
| It is not possible to work with them directly, because |
It is not possible to work with them directly, because |
| theForm.name[].something will result into JavaScript |
theForm.name[].something will result into JavaScript |
| syntax error. Following search algorithm is provided |
syntax error. Following search algorithm is provided |
| Line 980 function '.$this->js['prefix'].'filter_h |
|
| Line 1048 function '.$this->js['prefix'].'filter_h |
|
| } |
} |
| } elseif (isset ($this->fdd[$k]['textarea'])) { |
} elseif (isset ($this->fdd[$k]['textarea'])) { |
| echo '<textarea class="',$css_class_name,'" name="',$this->cgi['prefix']['data'].$this->fds[$k],'"'; |
echo '<textarea class="',$css_class_name,'" name="',$this->cgi['prefix']['data'].$this->fds[$k],'"'; |
| echo ($this->readonly($k) ? ' disabled="disabled"' : ''); |
echo ($this->readonly($k) ? ' disabled' : ''); |
| if (intval($this->fdd[$k]['textarea']['rows']) > 0) { |
if (intval($this->fdd[$k]['textarea']['rows']) > 0) { |
| echo ' rows="',$this->fdd[$k]['textarea']['rows'],'"'; |
echo ' rows="',$this->fdd[$k]['textarea']['rows'],'"'; |
| } |
} |
| Line 1000 function '.$this->js['prefix'].'filter_h |
|
| Line 1068 function '.$this->js['prefix'].'filter_h |
|
| echo include($this->fdd[$k]['php']); |
echo include($this->fdd[$k]['php']); |
| } else { |
} else { |
| // Simple edit box required |
// Simple edit box required |
| $size_ml_props = ''; |
$len_props = ''; |
| $maxlen = intval($this->fdd[$k]['maxlen']); |
$maxlen = intval($this->fdd[$k]['maxlen']); |
| $size = isset($this->fdd[$k]['size']) ? $this->fdd[$k]['size'] : min($maxlen, 60); |
$size = isset($this->fdd[$k]['size']) ? $this->fdd[$k]['size'] : min($maxlen, 60); |
| $size && $size_ml_props .= ' size="'.$size.'"'; |
if ($size > 0) { |
| $maxlen && $size_ml_props .= ' maxlength="'.$maxlen.'"'; |
$len_props .= ' size="'.$size.'"'; |
| |
} |
| |
if ($maxlen > 0) { |
| |
$len_props .= ' maxlength="'.$maxlen.'"'; |
| |
} |
| echo '<input class="',$css_class_name,'" '; |
echo '<input class="',$css_class_name,'" '; |
| echo ($this->password($k) ? 'type="password"' : 'type="text"'); |
echo ($this->password($k) ? 'type="password"' : 'type="text"'); |
| echo ($this->readonly($k) ? ' disabled="disabled"' : ''); |
echo ($this->readonly($k) ? ' disabled' : ''); |
| echo ' name="',$this->cgi['prefix']['data'].$this->fds[$k],'"'; |
echo ' name="',$this->cgi['prefix']['data'].$this->fds[$k],'"'; |
| echo $size_ml_props,' value="'; |
echo $len_props,' value="'; |
| if($escape) echo htmlspecialchars($this->fdd[$k]['default']); |
if($escape) echo htmlspecialchars($this->fdd[$k]['default']); |
| else echo $this->fdd[$k]['default']; |
else echo $this->fdd[$k]['default']; |
| echo '" />'; |
echo '" />'; |
| Line 1037 function '.$this->js['prefix'].'filter_h |
|
| Line 1109 function '.$this->js['prefix'].'filter_h |
|
| .$this->key_delim.$this->rec.$this->key_delim.')'; |
.$this->key_delim.$this->rec.$this->key_delim.')'; |
| |
|
| $res = $this->myquery($this->get_SQL_query($qparts),__LINE__); |
$res = $this->myquery($this->get_SQL_query($qparts),__LINE__); |
| if (! ($row = @mysql_fetch_array($res, MYSQL_ASSOC))) { |
if (! ($row = $this->sql_fetch($res))) { |
| return false; |
return false; |
| } |
} |
| for ($tab = 0, $k = 0; $k < $this->num_fds; $k++) { |
for ($tab = 0, $k = 0; $k < $this->num_fds; $k++) { |
| Line 1124 function '.$this->js['prefix'].'filter_h |
|
| Line 1196 function '.$this->js['prefix'].'filter_h |
|
| } |
} |
| } elseif (isset($this->fdd[$k]['textarea'])) { |
} elseif (isset($this->fdd[$k]['textarea'])) { |
| echo '<textarea class="',$css_class_name,'" name="',$this->cgi['prefix']['data'].$this->fds[$k],'"'; |
echo '<textarea class="',$css_class_name,'" name="',$this->cgi['prefix']['data'].$this->fds[$k],'"'; |
| echo ($this->readonly($k) ? ' disabled="disabled"' : ''); |
echo ($this->readonly($k) ? ' disabled' : ''); |
| if (intval($this->fdd[$k]['textarea']['rows']) > 0) { |
if (intval($this->fdd[$k]['textarea']['rows']) > 0) { |
| echo ' rows="',$this->fdd[$k]['textarea']['rows'],'"'; |
echo ' rows="',$this->fdd[$k]['textarea']['rows'],'"'; |
| } |
} |
| Line 1143 function '.$this->js['prefix'].'filter_h |
|
| Line 1215 function '.$this->js['prefix'].'filter_h |
|
| } elseif ($this->col_has_php($k)) { |
} elseif ($this->col_has_php($k)) { |
| echo include($this->fdd[$k]['php']); |
echo include($this->fdd[$k]['php']); |
| } else { |
} else { |
| $size_ml_props = ''; |
$len_props = ''; |
| $maxlen = intval($this->fdd[$k]['maxlen']); |
$maxlen = intval($this->fdd[$k]['maxlen']); |
| $size = isset($this->fdd[$k]['size']) ? $this->fdd[$k]['size'] : min($maxlen, 60); |
$size = isset($this->fdd[$k]['size']) ? $this->fdd[$k]['size'] : min($maxlen, 60); |
| $size && $size_ml_props .= ' size="'.$size.'"'; |
if ($size > 0) { |
| $maxlen && $size_ml_props .= ' maxlength="'.$maxlen.'"'; |
$len_props .= ' size="'.$size.'"'; |
| echo '<input class="',$css_class_name,'" type="text" '; |
} |
| echo ($this->readonly($k) ? 'disabled="disabled" ' : ''); |
if ($maxlen > 0) { |
| echo 'name="',$this->cgi['prefix']['data'].$this->fds[$k],'" value="'; |
$len_props .= ' maxlength="'.$maxlen.'"'; |
| |
} |
| |
echo '<input class="',$css_class_name,'" type="text"'; |
| |
echo ($this->readonly($k) ? ' disabled' : ''); |
| |
echo ' name="',$this->cgi['prefix']['data'].$this->fds[$k],'" value="'; |
| if($escape) echo htmlspecialchars($row["qf$k"]); |
if($escape) echo htmlspecialchars($row["qf$k"]); |
| else echo $row["qf$k"]; |
else echo $row["qf$k"]; |
| echo '" />',"\n"; |
echo '"',$len_props,' />',"\n"; |
| } |
} |
| echo '</td>',"\n"; |
echo '</td>',"\n"; |
| } /* }}} */ |
} /* }}} */ |
| Line 1163 function '.$this->js['prefix'].'filter_h |
|
| Line 1239 function '.$this->js['prefix'].'filter_h |
|
| $css_postfix = @$this->fdd[$k]['css']['postfix']; |
$css_postfix = @$this->fdd[$k]['css']['postfix']; |
| echo '<td class="',$this->getCSSclass('value', null, true, $css_postfix),'"'; |
echo '<td class="',$this->getCSSclass('value', null, true, $css_postfix),'"'; |
| echo $this->getColAttributes($k),">\n"; |
echo $this->getColAttributes($k),">\n"; |
| $size_ml_props = ''; |
$len_props = ''; |
| $maxlen = intval($this->fdd[$k]['maxlen']); |
$maxlen = intval($this->fdd[$k]['maxlen']); |
| $size = isset($this->fdd[$k]['size']) ? $this->fdd[$k]['size'] : min($maxlen, 60); |
$size = isset($this->fdd[$k]['size']) ? $this->fdd[$k]['size'] : min($maxlen, 60); |
| $size && $size_ml_props .= ' size="'.$size.'"'; |
if ($size > 0) { |
| $maxlen && $size_ml_props .= ' maxlength="'.$maxlen.'"'; |
$len_props .= ' size="'.$size.'"'; |
| echo '<input class="',$this->getCSSclass('value', null, true, $css_postfix),'" type="password" '; |
} |
| echo ($this->readonly($k) ? 'disabled="disabled" ' : ''); |
if ($maxlen > 0) { |
| echo 'name="',$this->cgi['prefix']['data'].$this->fds[$k],'" value="'; |
$len_props .= ' maxlength="'.$maxlen.'"'; |
| echo htmlspecialchars($row["qf$k"]),'" ',$size_ml_props,' />',"\n"; |
} |
| |
echo '<input class="',$this->getCSSclass('value', null, true, $css_postfix),'" type="password"'; |
| |
echo ($this->readonly($k) ? ' disabled' : ''); |
| |
echo ' name="',$this->cgi['prefix']['data'].$this->fds[$k],'" value="'; |
| |
echo htmlspecialchars($row["qf$k"]),'"',$len_props,' />',"\n"; |
| echo '</td>',"\n"; |
echo '</td>',"\n"; |
| } /* }}} */ |
} /* }}} */ |
| |
|
| Line 1395 function '.$this->js['prefix'].'filter_h |
|
| Line 1475 function '.$this->js['prefix'].'filter_h |
|
| { |
{ |
| // Note that <input disabled> isn't valid HTML, but most browsers support it |
// Note that <input disabled> isn't valid HTML, but most browsers support it |
| if($disabled == -1) return; |
if($disabled == -1) return; |
| $markdisabled = $disabled ? ' disabled="disabled"' : ''; |
$markdisabled = $disabled ? ' disabled' : ''; |
| $ret = '<input'.$markdisabled.' type="submit" class="'.$css_class_name |
$ret = '<input'.$markdisabled.' type="submit" class="'.$css_class_name |
| .'" name="'.$this->cgi['prefix']['sys'].ltrim($markdisabled).$name |
.'" name="'.$this->cgi['prefix']['sys'].ltrim($markdisabled).$name |
| .'" value="'.(isset($this->labels[$label]) ? $this->labels[$label] : $label); |
.'" value="'.(isset($this->labels[$label]) ? $this->labels[$label] : $label); |
| Line 1455 function '.$this->js['prefix'].'filter_h |
|
| Line 1535 function '.$this->js['prefix'].'filter_h |
|
| $selected = explode(',', $selected); |
$selected = explode(',', $selected); |
| } |
} |
| } |
} |
| $ret .= '"'.($readonly ? ' disabled="disabled"' : '').$js.'>'."\n"; |
$ret .= '"'.($readonly ? ' disabled ' : ' ').$js.">\n"; |
| if (! is_array($selected)) { |
if (! is_array($selected)) { |
| $selected = $selected === null ? array() : array($selected); |
$selected = $selected === null ? array() : array($selected); |
| } |
} |
| $found = false; |
$found = false; |
| foreach ($kv_array as $key => $value) { |
foreach ($kv_array as $key => $value) { |
| $ret .= '<option value="'.htmlspecialchars($key).'"'; |
$ret .= '<option value="'.htmlspecialchars($key).'"'; |
| if ((! $found || $multiple) && in_array((string) $key, $selected, 1) |
if ((! $found || $multiple) && in_array(/* (string) see #446 */ $key, $selected, 1) |
| || (count($selected) == 0 && ! $found && ! $multiple)) { |
|| (count($selected) == 0 && ! $found && ! $multiple)) { |
| $ret .= ' selected="selected"'; |
$ret .= ' selected="selected"'; |
| $found = true; |
$found = true; |
| Line 1511 function '.$this->js['prefix'].'filter_h |
|
| Line 1591 function '.$this->js['prefix'].'filter_h |
|
| $found = true; |
$found = true; |
| } |
} |
| if ($readonly) { |
if ($readonly) { |
| $ret .= ' disabled="disabled"'; |
$ret .= ' disabled'; |
| } |
} |
| $strip_tags && $value = strip_tags($value); |
$strip_tags && $value = strip_tags($value); |
| $escape && $value = htmlspecialchars($value); |
$escape && $value = htmlspecialchars($value); |
| Line 1774 function '.$this->js['prefix'].'filter_h |
|
| Line 1854 function '.$this->js['prefix'].'filter_h |
|
| { |
{ |
| if (($but_str = $this->display_buttons($position)) === null) |
if (($but_str = $this->display_buttons($position)) === null) |
| return; |
return; |
| if($position == 'down') echo '<hr class="'.$this->getCSSclass('hr', 'down').'" />'."\n"; |
if($position == 'down') echo '<hr size="1" class="'.$this->getCSSclass('hr', 'down').'" />'."\n"; |
| echo '<table summary="navigation" class="',$this->getCSSclass('navigation', $position),'">',"\n"; |
echo '<table summary="navigation" class="',$this->getCSSclass('navigation', $position),'">',"\n"; |
| echo '<tr class="',$this->getCSSclass('navigation', $position),'">',"\n"; |
echo '<tr class="',$this->getCSSclass('navigation', $position),'">',"\n"; |
| echo '<td class="',$this->getCSSclass('buttons', $position),'">',"\n"; |
echo '<td class="',$this->getCSSclass('buttons', $position),'">',"\n"; |
| Line 1799 function '.$this->js['prefix'].'filter_h |
|
| Line 1879 function '.$this->js['prefix'].'filter_h |
|
| echo ' ',$this->labels['Records'],': ',$this->total_recs; |
echo ' ',$this->labels['Records'],': ',$this->total_recs; |
| if($this->display['num_pages'] || $this->display['num_records']) echo '</td>'; |
if($this->display['num_pages'] || $this->display['num_records']) echo '</td>'; |
| echo '</tr></table>',"\n"; |
echo '</tr></table>',"\n"; |
| if($position == 'up') echo '<hr class="'.$this->getCSSclass('hr', 'up').'" />'."\n"; |
if($position == 'up') echo '<hr size="1" class="'.$this->getCSSclass('hr', 'up').'" />'."\n"; |
| } /* }}} */ |
} /* }}} */ |
| |
|
| /* |
/* |
| Line 1811 function '.$this->js['prefix'].'filter_h |
|
| Line 1891 function '.$this->js['prefix'].'filter_h |
|
| return; |
return; |
| if ($position == 'down') { |
if ($position == 'down') { |
| if ($this->tabs_enabled()) $this->display_tab_labels('down'); |
if ($this->tabs_enabled()) $this->display_tab_labels('down'); |
| echo '<hr class="',$this->getCSSclass('hr', 'down'),'" />',"\n"; |
echo '<hr size="1" class="',$this->getCSSclass('hr', 'down'),'" />',"\n"; |
| } |
} |
| echo '<table summary="navigation" class="',$this->getCSSclass('navigation', $position),'">',"\n"; |
echo '<table summary="navigation" class="',$this->getCSSclass('navigation', $position),'">',"\n"; |
| echo '<tr class="',$this->getCSSclass('navigation', $position),'">',"\n"; |
echo '<tr class="',$this->getCSSclass('navigation', $position),'">',"\n"; |
| Line 1825 function '.$this->js['prefix'].'filter_h |
|
| Line 1905 function '.$this->js['prefix'].'filter_h |
|
| echo '</tr></table>',"\n"; |
echo '</tr></table>',"\n"; |
| if ($position == 'up') { |
if ($position == 'up') { |
| if ($this->tabs_enabled()) $this->display_tab_labels('up'); |
if ($this->tabs_enabled()) $this->display_tab_labels('up'); |
| echo '<hr class="',$this->getCSSclass('hr', 'up'),'" />',"\n"; |
echo '<hr size="1" class="',$this->getCSSclass('hr', 'up'),'" />',"\n"; |
| } |
} |
| } /* }}} */ |
} /* }}} */ |
| |
|
| Line 1847 function '.$this->js['prefix'].'filter_h |
|
| Line 1927 function '.$this->js['prefix'].'filter_h |
|
| { |
{ |
| if (is_array($name)) { |
if (is_array($name)) { |
| if (isset($name['code'])) return $name['code']; |
if (isset($name['code'])) return $name['code']; |
| return $this->htmlSubmit($name['name'], $name['value'], $name['css'], $name['disabled'], $name['js']); |
return $this->htmlSubmit($name['name'], $name['value'], $name['css'], $name['js_validation'], $name['disabled'], $name['js']); |
| } |
} |
| $disabled = 1; // show disabled by default |
$disabled = 1; // show disabled by default |
| if ($name[0] == '+') { $name = substr($name, 1); $disabled = 0; } // always show disabled as enabled |
if ($name[0] == '+') { $name = substr($name, 1); $disabled = 0; } // always show disabled as enabled |
| Line 1943 function '.$this->js['prefix'].'filter_h |
|
| Line 2023 function '.$this->js['prefix'].'filter_h |
|
| 'select' => 'count(*)', |
'select' => 'count(*)', |
| 'from' => $this->get_SQL_join_clause(), |
'from' => $this->get_SQL_join_clause(), |
| 'where' => $this->get_SQL_where_from_query_opts()); |
'where' => $this->get_SQL_where_from_query_opts()); |
| $res = $this->myquery($this->get_SQL_query($count_parts), __LINE__); |
$res = $this->myquery($this->get_SQL_main_list_query($count_parts), __LINE__); |
| $row = @mysql_fetch_array($res, MYSQL_NUM); |
$row = $this->sql_fetch($res, 'n'); |
| $this->total_recs = $row[0]; |
$this->total_recs = $row[0]; |
| } /* }}} */ |
} /* }}} */ |
| |
|
| Line 1980 function '.$this->js['prefix'].'filter_h |
|
| Line 2060 function '.$this->js['prefix'].'filter_h |
|
| echo '[<b>',htmlspecialchars($this->qfn),'</b>]'; |
echo '[<b>',htmlspecialchars($this->qfn),'</b>]'; |
| echo '[<b>',htmlspecialchars($this->prev_qfn),'</b>]<br />'; |
echo '[<b>',htmlspecialchars($this->prev_qfn),'</b>]<br />'; |
| echo 'comparsion <u>',($this->qfn == $this->prev_qfn ? 'proved' : 'failed'),'</u>'; |
echo 'comparsion <u>',($this->qfn == $this->prev_qfn ? 'proved' : 'failed'),'</u>'; |
| echo '<hr />'; |
echo '<hr size="1" />'; |
| } |
} |
| /* |
/* |
| * If user is allowed to Change/Delete records, we need an extra column |
* If user is allowed to Change/Delete records, we need an extra column |
| Line 1991 function '.$this->js['prefix'].'filter_h |
|
| Line 2071 function '.$this->js['prefix'].'filter_h |
|
| // Are we doing a listall? |
// Are we doing a listall? |
| $listall = $this->inc <= 0; |
$listall = $this->inc <= 0; |
| /* |
/* |
| * Display the MySQL table in an HTML table |
* Display the SQL table in an HTML table |
| */ |
*/ |
| $this->form_begin(); |
$this->form_begin(); |
| echo $this->get_origvars_html($this->get_sfn_cgi_vars()); |
echo $this->get_origvars_html($this->get_sfn_cgi_vars()); |
| Line 2101 function '.$this->js['prefix'].'filter_h |
|
| Line 2181 function '.$this->js['prefix'].'filter_h |
|
| $qparts['orderby'] = join(',', $sort_fields); |
$qparts['orderby'] = join(',', $sort_fields); |
| } |
} |
| } |
} |
| $qparts['limit'] = $listall ? '' : $this->fm.','.$this->inc; |
$qparts['limit'] = $listall ? '' : $this->sql_limit($this->fm,$this->inc); |
| |
|
| /* |
/* |
| * Main list_table() query |
* Main list_table() query |
| * |
* |
| * Each row of the HTML table is one record from the SQL query. We must |
* Each row of the HTML table is one record from the SQL query. We must |
| * perform this query before filter printing, because we want to use |
* perform this query before filter printing, because we want to use |
| * mysql_field_len() function. We will also fetch the first row to get |
* $this->sql_field_len() function. We will also fetch the first row to get |
| * the field names. |
* the field names. |
| */ |
*/ |
| $query = $this->get_SQL_query($qparts); |
$query = $this->get_SQL_main_list_query($qparts); |
| $res = $this->myquery($query, __LINE__); |
$res = $this->myquery($query, __LINE__); |
| if ($res == false) { |
if ($res == false) { |
| $this->error('invalid SQL query', $query); |
$this->error('invalid SQL query', $query); |
| return false; |
return false; |
| } |
} |
| $row = @mysql_fetch_array($res, MYSQL_ASSOC); |
$row = $this->sql_fetch($res); |
| |
|
| /* FILTER {{{ |
/* FILTER {{{ |
| * |
* |
| Line 2136 function '.$this->js['prefix'].'filter_h |
|
| Line 2216 function '.$this->js['prefix'].'filter_h |
|
| $this->error('invalid SQL query', $query); |
$this->error('invalid SQL query', $query); |
| return false; |
return false; |
| } |
} |
| $filter_row = @mysql_fetch_array($res, MYSQL_ASSOC); |
$filter_row = $this->sql_fetch($res); |
| } |
} |
| /* Variable $fields is used to get index of particular field in |
/* Variable $fields is used to get index of particular field in |
| result. That index can be passed in example to mysql_field_len() |
result. That index can be passed in example to $this->sql_field_len() |
| function. Use field names as indexes to $fields array. */ |
function. Use field names as indexes to $fields array. */ |
| if (is_array($filter_row)) { |
if (is_array($filter_row)) { |
| $fields = array_flip(array_keys($filter_row)); |
$fields = array_flip(array_keys($filter_row)); |
| Line 2188 function '.$this->js['prefix'].'filter_h |
|
| Line 2268 function '.$this->js['prefix'].'filter_h |
|
| echo $this->htmlSelect($this->cgi['prefix']['sys'].$l.'_id', $css_class_name, |
echo $this->htmlSelect($this->cgi['prefix']['sys'].$l.'_id', $css_class_name, |
| $vals, $selected, $multiple, $readonly, $strip_tags, $escape); |
$vals, $selected, $multiple, $readonly, $strip_tags, $escape); |
| } elseif ($this->fdd[$fd]['select'] == 'N' || $this->fdd[$fd]['select'] == 'T') { |
} elseif ($this->fdd[$fd]['select'] == 'N' || $this->fdd[$fd]['select'] == 'T') { |
| $size_ml_props = ''; |
$len_props = ''; |
| $maxlen = intval($this->fdd[$k]['maxlen']); |
$maxlen = intval($this->fdd[$k]['maxlen']); |
| $maxlen > 0 || $maxlen = intval(@mysql_field_len($res, $fields["qf$k"])); |
$maxlen > 0 || $maxlen = intval($this->sql_field_len($res, $fields["qf$k"])); |
| $size = isset($this->fdd[$k]['size']) ? $this->fdd[$k]['size'] |
$size = isset($this->fdd[$k]['size']) ? $this->fdd[$k]['size'] |
| : ($maxlen < 30 ? min($maxlen, 8) : 12); |
: ($maxlen < 30 ? min($maxlen, 8) : 12); |
| $size && $size_ml_props .= ' size="'.$size.'"'; |
$len_props .= ' size="'.$size.'"'; |
| $maxlen && $size_ml_props .= ' maxlength="'.$maxlen.'"'; |
$len_props .= ' maxlength="'.$maxlen.'"'; |
| if ($this->fdd[$fd]['select'] == 'N') { |
if ($this->fdd[$fd]['select'] == 'N') { |
| $mc = in_array($mc, $this->comp_ops) ? $mc : '='; |
$mc = in_array($mc, $this->comp_ops) ? $mc : '='; |
| echo $this->htmlSelect($this->cgi['prefix']['sys'].$l.'_comp', |
echo $this->htmlSelect($this->cgi['prefix']['sys'].$l.'_comp', |
| $css_class_name, $this->comp_ops, $mc); |
$css_class_name, $this->comp_ops, $mc); |
| } |
} |
| echo '<input class="',$css_class_name,'" value="',htmlspecialchars(@$m); |
echo '<input class="',$css_class_name,'" value="',htmlspecialchars(@$m); |
| echo '" type="text" name="'.$this->cgi['prefix']['sys'].'qf'.$k.'"',$size_ml_props; |
echo '" type="text" name="'.$this->cgi['prefix']['sys'].'qf'.$k.'"',$len_props; |
| echo ' onkeypress="return '.$this->js['prefix'].'filter_handler(this.form, event);" />'; |
echo ' onkeypress="return '.$this->js['prefix'].'filter_handler(this.form, event);" />'; |
| } else { |
} else { |
| echo ' '; |
echo ' '; |
| Line 2273 function '.$this->js['prefix'].'filter_h |
|
| Line 2353 function '.$this->js['prefix'].'filter_h |
|
| $fetched = true; |
$fetched = true; |
| $first = true; |
$first = true; |
| $rowCount = 0; |
$rowCount = 0; |
| while ((!$fetched && ($row = @mysql_fetch_array($res, MYSQL_ASSOC)) != false) |
while ((!$fetched && ($row = $this->sql_fetch($res)) != false) |
| || ($fetched && $row != false)) { |
|| ($fetched && $row != false)) { |
| $fetched = false; |
$fetched = false; |
| echo '<tr class="',$this->getCSSclass('row', null, 'next'),'">',"\n"; |
echo '<tr class="',$this->getCSSclass('row', null, 'next'),'">',"\n"; |
| Line 2366 function '.$this->js['prefix'].'filter_h |
|
| Line 2446 function '.$this->js['prefix'].'filter_h |
|
| echo ' /></td>',"\n"; |
echo ' /></td>',"\n"; |
| } |
} |
| } elseif ($this->filter_enabled()) { |
} elseif ($this->filter_enabled()) { |
| echo '<td class="',$css_class_name,'" colspan=',$sys_cols,'> </td>',"\n"; |
echo '<td class="',$css_class_name,'" colspan="',$sys_cols,'"> </td>',"\n"; |
| } |
} |
| } /* }}} */ |
} /* }}} */ |
| for ($k = 0; $k < $this->num_fds; $k++) { /* {{{ */ |
for ($k = 0; $k < $this->num_fds; $k++) { /* {{{ */ |
| Line 2402 function '.$this->js['prefix'].'filter_h |
|
| Line 2482 function '.$this->js['prefix'].'filter_h |
|
| $qp['where'] = $this->get_SQL_where_from_query_opts(); |
$qp['where'] = $this->get_SQL_where_from_query_opts(); |
| $tot_query = $this->get_SQL_query($qp); |
$tot_query = $this->get_SQL_query($qp); |
| $totals_result = $this->myquery($tot_query,__LINE__); |
$totals_result = $this->myquery($tot_query,__LINE__); |
| $tot_row = @mysql_fetch_array($totals_result, MYSQL_ASSOC); |
$tot_row = $this->sql_fetch($totals_result); |
| //} |
//} |
| $qp_aggr = $qp; |
$qp_aggr = $qp; |
| echo "\n",'<tr class="TODO-class">',"\n",'<td class="TODO-class"> </td>',"\n"; |
echo "\n",'<tr class="TODO-class">',"\n",'<td class="TODO-class"> </td>',"\n"; |
| Line 2538 function '.$this->js['prefix'].'filter_h |
|
| Line 2618 function '.$this->js['prefix'].'filter_h |
|
| $value = "'".addslashes($val)."'"; |
$value = "'".addslashes($val)."'"; |
| } |
} |
| if ($query == '') { |
if ($query == '') { |
| $query = 'INSERT INTO `'.$this->tb.'` (`'.$fd.'`'; // ) |
$query = 'INSERT INTO '.$this->sd.$this->tb.$this->ed.' ('.$this->sd.$fd.$this->ed.''; // ) |
| $query2 = ') VALUES ('.$value.''; |
$query2 = ') VALUES ('.$value.''; |
| } else { |
} else { |
| $query .= ', `'.$fd.'`'; |
$query .= ', '.$this->sd.$fd.$this->ed.''; |
| $query2 .= ', '.$value.''; |
$query2 .= ', '.$value.''; |
| } |
} |
| } |
} |
| $query .= $query2.')'; |
$query .= $query2.')'; |
| $res = $this->myquery($query, __LINE__); |
$res = $this->myquery($query, __LINE__); |
| $this->message = @mysql_affected_rows($this->dbh).' '.$this->labels['record added']; |
$this->message = $this->sql_affected_rows($this->dbh).' '.$this->labels['record added']; |
| if (! $res) { |
if (! $res) { |
| return false; |
return false; |
| } |
} |
| $this->rec = mysql_insert_id($this->dbh); |
$this->rec = $this->sql_insert_id(); |
| // Notify list |
// Notify list |
| if (@$this->notify['insert'] || @$this->notify['all']) { |
if (@$this->notify['insert'] || @$this->notify['all']) { |
| $this->email_notify(false, $newvals); |
$this->email_notify(false, $newvals); |
| Line 2588 function '.$this->js['prefix'].'filter_h |
|
| Line 2668 function '.$this->js['prefix'].'filter_h |
|
| $fn = $this->get_data_cgi_var($fd); |
$fn = $this->get_data_cgi_var($fd); |
| $newvals[$this->fds[$k]] = is_array($fn) ? join(',',$fn) : $fn; |
$newvals[$this->fds[$k]] = is_array($fn) ? join(',',$fn) : $fn; |
| if ($query_oldrec == '') { |
if ($query_oldrec == '') { |
| $query_oldrec = 'SELECT '.$fd; |
$query_oldrec = 'SELECT '.$this->sd.$fd.$this->ed; |
| } else { |
} else { |
| $query_oldrec .= ','.$fd; |
$query_oldrec .= ','.$this->sd.$fd.$this->ed; |
| } |
} |
| } |
} |
| } |
} |
| $where_part = " WHERE (".$this->key.'='.$this->key_delim.$this->rec.$this->key_delim.')'; |
$where_part = " WHERE (".$this->sd.$this->key.$this->ed.'='.$this->key_delim.$this->rec.$this->key_delim.')'; |
| $query_newrec = $query_oldrec.' FROM ' . $this->tb; |
$query_newrec = $query_oldrec.' FROM ' . $this->tb; |
| $query_oldrec .= ' FROM ' . $this->tb . $where_part; |
$query_oldrec .= ' FROM ' . $this->sd.$this->tb.$this->ed . $where_part; |
| // Additional query (must go before real query) |
// Additional query (must go before real query) |
| $res = $this->myquery($query_oldrec, __LINE__); |
$res = $this->myquery($query_oldrec, __LINE__); |
| $oldvals = @mysql_fetch_array($res, MYSQL_ASSOC); |
$oldvals = $this->sql_fetch($res); |
| @mysql_free_result($res); |
$this->sql_free_result($res); |
| // Creating array of changed keys ($changed) |
// Creating array of changed keys ($changed) |
| foreach ($newvals as $fd => $value) { |
foreach ($newvals as $fd => $value) { |
| if ($value != $oldvals[$fd]) |
if ($value != $oldvals[$fd]) |
| Line 2626 function '.$this->js['prefix'].'filter_h |
|
| Line 2706 function '.$this->js['prefix'].'filter_h |
|
| $value = "'".addslashes($val)."'"; |
$value = "'".addslashes($val)."'"; |
| } |
} |
| if ($query_real == '') { |
if ($query_real == '') { |
| $query_real = 'UPDATE '.$this->tb.' SET '.$fd.'='.$value; |
$query_real = 'UPDATE '.$this->sd.$this->tb.$this->ed.' SET '.$this->sd.$fd.$this->ed.'='.$value; |
| } else { |
} else { |
| $query_real .= ','.$fd.'='.$value; |
$query_real .= ','.$this->sd.$fd.$this->ed.'='.$value; |
| } |
} |
| } |
} |
| $query_real .= $where_part; |
$query_real .= $where_part; |
| // Real query |
// Real query |
| $res = $this->myquery($query_real, __LINE__); |
$res = $this->myquery($query_real, __LINE__); |
| $this->message = @mysql_affected_rows($this->dbh).' '.$this->labels['record changed']; |
$this->message = $this->sql_affected_rows($this->dbh).' '.$this->labels['record changed']; |
| if (! $res) { |
if (! $res) { |
| return false; |
return false; |
| } |
} |
| Line 2644 function '.$this->js['prefix'].'filter_h |
|
| Line 2724 function '.$this->js['prefix'].'filter_h |
|
| } |
} |
| $query_newrec .= ' WHERE ('.$this->key.'='.$this->key_delim.$this->rec.$this->key_delim.')'; |
$query_newrec .= ' WHERE ('.$this->key.'='.$this->key_delim.$this->rec.$this->key_delim.')'; |
| $res = $this->myquery($query_newrec, __LINE__); |
$res = $this->myquery($query_newrec, __LINE__); |
| $newvals = @mysql_fetch_array($res, MYSQL_ASSOC); |
$newvals = $this->sql_fetch($res); |
| @mysql_free_result($res); |
$this->sql_free_result($res); |
| // Creating array of changed keys ($changed) |
// Creating array of changed keys ($changed) |
| $changed = array(); |
$changed = array(); |
| foreach ($newvals as $fd => $value) { |
foreach ($newvals as $fd => $value) { |
| Line 2681 function '.$this->js['prefix'].'filter_h |
|
| Line 2761 function '.$this->js['prefix'].'filter_h |
|
| function do_delete_record() /* {{{ */ |
function do_delete_record() /* {{{ */ |
| { |
{ |
| // Additional query |
// Additional query |
| $query = 'SELECT * FROM '.$this->tb.' WHERE ('.$this->key.' = ' |
$query = 'SELECT * FROM '.$this->sd.$this->tb.$this->ed.' WHERE ('.$this->sd.$this->key.$this->ed.' = ' |
| .$this->key_delim.$this->rec.$this->key_delim.')'; // ) |
.$this->key_delim.$this->rec.$this->key_delim.')'; // ) |
| $res = $this->myquery($query, __LINE__); |
$res = $this->myquery($query, __LINE__); |
| $oldvals = @mysql_fetch_array($res, MYSQL_ASSOC); |
$oldvals = $this->sql_fetch($res); |
| @mysql_free_result($res); |
$this->sql_free_result($res); |
| // Creating array of changed keys ($changed) |
// Creating array of changed keys ($changed) |
| $changed = array_keys($oldvals); |
$changed = is_array($oldvals) ? array_keys($oldvals) : array(); |
| $newvals = array(); |
$newvals = array(); |
| // Before trigger |
// Before trigger |
| if ($this->exec_triggers('delete', 'before', $oldvals, $changed, $newvals) == false) { |
if ($this->exec_triggers('delete', 'before', $oldvals, $changed, $newvals) == false) { |
| Line 2697 function '.$this->js['prefix'].'filter_h |
|
| Line 2777 function '.$this->js['prefix'].'filter_h |
|
| $query = 'DELETE FROM '.$this->tb.' WHERE ('.$this->key.' = ' |
$query = 'DELETE FROM '.$this->tb.' WHERE ('.$this->key.' = ' |
| .$this->key_delim.$this->rec.$this->key_delim.')'; // ) |
.$this->key_delim.$this->rec.$this->key_delim.')'; // ) |
| $res = $this->myquery($query, __LINE__); |
$res = $this->myquery($query, __LINE__); |
| $this->message = @mysql_affected_rows($this->dbh).' '.$this->labels['record deleted']; |
$this->message = $this->sql_affected_rows($this->dbh).' '.$this->labels['record deleted']; |
| if (! $res) { |
if (! $res) { |
| return false; |
return false; |
| } |
} |
| Line 2749 function '.$this->js['prefix'].'filter_h |
|
| Line 2829 function '.$this->js['prefix'].'filter_h |
|
| $addr = $this->get_server_var('REMOTE_ADDR'); |
$addr = $this->get_server_var('REMOTE_ADDR'); |
| $user = $this->get_server_var('REMOTE_USER'); |
$user = $this->get_server_var('REMOTE_USER'); |
| $body = 'This notification e-mail was automatically generated by phpMyEdit.'."\n\n".$body; |
$body = 'This notification e-mail was automatically generated by phpMyEdit.'."\n\n".$body; |
| $body .= ' table '.$this->tb.' in MySQL database '.$this->db.' on '.$this->page_name; |
$body .= ' table '.$this->tb.' in SQL database '.$this->db.' on '.$this->page_name; |
| $body .= ' by '.($user == '' ? 'unknown user' : "user $user").' from '.$addr; |
$body .= ' by '.($user == '' ? 'unknown user' : "user $user").' from '.$addr; |
| $body .= ' at '.date('d/M/Y H:i').' with the following fields:'."\n\n"; |
$body .= ' at '.date('d/M/Y H:i').' with the following fields:'."\n\n"; |
| $i = 1; |
$i = 1; |
| Line 2768 function '.$this->js['prefix'].'filter_h |
|
| Line 2848 function '.$this->js['prefix'].'filter_h |
|
| $i++; |
$i++; |
| } |
} |
| $body .= "\n--\r\n"; // \r is needed for signature separating |
$body .= "\n--\r\n"; // \r is needed for signature separating |
| $body .= "phpMyEdit\ninstant MySQL table editor and code generator\n"; |
$body .= "phpMyEdit\ninstant SQL table editor and code generator\n"; |
| $body .= "http://platon.sk/projects/phpMyEdit/\n\n"; |
$body .= "http://platon.sk/projects/phpMyEdit/\n\n"; |
| $subject = @$this->notify['prefix'].$subject.' '.$this->dbp.$this->tb; |
$subject = @$this->notify['prefix'].$subject.' '.$this->dbp.$this->tb; |
| $subject = trim($subject); // just for sure |
$subject = trim($subject); // just for sure |
| Line 2968 function '.$this->js['prefix'].'filter_h |
|
| Line 3048 function '.$this->js['prefix'].'filter_h |
|
| { |
{ |
| echo '<h1>phpMyEdit error: ',htmlspecialchars($message),'</h1>',"\n"; |
echo '<h1>phpMyEdit error: ',htmlspecialchars($message),'</h1>',"\n"; |
| if ($additional_info != '') { |
if ($additional_info != '') { |
| echo '<hr />',htmlspecialchars($additional_info); |
echo '<hr size="1" />',htmlspecialchars($additional_info); |
| } |
} |
| return false; |
return false; |
| } /* }}} */ |
} /* }}} */ |
| Line 2989 function '.$this->js['prefix'].'filter_h |
|
| Line 3069 function '.$this->js['prefix'].'filter_h |
|
| $this->error('no table defined'); |
$this->error('no table defined'); |
| return false; |
return false; |
| } |
} |
| $this->dbh = @ini_get('allow_persistent') |
$this->sql_connect(); |
| ? @mysql_pconnect($this->hn, $this->un, $this->pw) |
|
| : @mysql_connect($this->hn, $this->un, $this->pw); |
|
| if (!$this->dbh) { |
if (!$this->dbh) { |
| $this->error('could not connect to MySQL'); |
$this->error('could not connect to SQL'); |
| return false; |
return false; |
| } |
} |
| return true; |
return true; |
| } /* }}} */ |
} /* }}} */ |
| |
|
| /* |
|
| * Database disconnection function |
|
| */ |
|
| function disconnect() /* {{{ */ |
|
| { |
|
| if ($this->close_dbh) { |
|
| @mysql_close($this->dbh); |
|
| $this->dbh = null; |
|
| } |
|
| } /* }}} */ |
|
| |
|
| /* |
/* |
| * The workhorse |
* The workhorse |
| */ |
*/ |
| Line 3106 function '.$this->js['prefix'].'filter_h |
|
| Line 3173 function '.$this->js['prefix'].'filter_h |
|
| |
|
| /* |
/* |
| * ====================================================================== |
* ====================================================================== |
| * Pass 1 and Pass 3: display the MySQL table in a scrolling window on |
* Pass 1 and Pass 3: display the SQL table in a scrolling window on |
| * the screen (skip this step in 'Add More' mode) |
* the screen (skip this step in 'Add More' mode) |
| * ====================================================================== |
* ====================================================================== |
| */ |
*/ |
| Line 3114 function '.$this->js['prefix'].'filter_h |
|
| Line 3181 function '.$this->js['prefix'].'filter_h |
|
| $this->list_table(); |
$this->list_table(); |
| } |
} |
| |
|
| $this->disconnect(); |
$this->sql_disconnect(); |
| if ($this->display['time'] && $this->timer != null) { |
if ($this->display['time'] && $this->timer != null) { |
| echo $this->timer->end(),' miliseconds'; |
echo $this->timer->end(),' miliseconds'; |
| } |
} |
| Line 3128 function '.$this->js['prefix'].'filter_h |
|
| Line 3195 function '.$this->js['prefix'].'filter_h |
|
| // Set desirable error reporting level |
// Set desirable error reporting level |
| $error_reporting = error_reporting(E_ALL & ~E_NOTICE); |
$error_reporting = error_reporting(E_ALL & ~E_NOTICE); |
| // Database handle variables |
// Database handle variables |
| |
$this->sql_delimiter(); |
| if (isset($opts['dbh'])) { |
if (isset($opts['dbh'])) { |
| $this->close_dbh = false; |
$this->close_dbh = false; |
| $this->dbh = $opts['dbh']; |
$this->dbh = $opts['dbh']; |
| Line 3135 function '.$this->js['prefix'].'filter_h |
|
| Line 3203 function '.$this->js['prefix'].'filter_h |
|
| } else { |
} else { |
| $this->close_dbh = true; |
$this->close_dbh = true; |
| $this->dbh = null; |
$this->dbh = null; |
| $this->dbp = $opts['db'].'.'; |
$this->dbp = $this->sd.$opts['db'].$this->ed.'.'; |
| $this->hn = $opts['hn']; |
$this->hn = $opts['hn']; |
| $this->un = $opts['un']; |
$this->un = $opts['un']; |
| $this->pw = $opts['pw']; |
$this->pw = $opts['pw']; |
| Line 3150 function '.$this->js['prefix'].'filter_h |
|
| Line 3218 function '.$this->js['prefix'].'filter_h |
|
| $this->fdd = $opts['fdd']; |
$this->fdd = $opts['fdd']; |
| $this->multiple = intval($opts['multiple']); |
$this->multiple = intval($opts['multiple']); |
| $this->multiple <= 0 && $this->multiple = 2; |
$this->multiple <= 0 && $this->multiple = 2; |
| $this->filters = @$opts['filters']; |
$this->filters = is_array(@$opts['filters']) ? join(' AND ', $opts['filters']) : @$opts['filters']; |
| $this->triggers = @$opts['triggers']; |
$this->triggers = @$opts['triggers']; |
| $this->notify = @$opts['notify']; |
$this->notify = @$opts['notify']; |
| $this->logtable = @$opts['logtable']; |
$this->logtable = @$opts['logtable']; |