| version 1.140, 2004/04/20 17:47:28 |
version 1.141, 2004/04/20 18:12:41 |
|
|
| * http://platon.sk/projects/phpMyEdit/ |
* http://platon.sk/projects/phpMyEdit/ |
| */ |
*/ |
| |
|
| /* $Platon: phpMyEdit/phpMyEdit.class.php,v 1.139 2004/04/20 14:21:57 nepto Exp $ */ |
/* $Platon: phpMyEdit/phpMyEdit.class.php,v 1.140 2004/04/20 17:47:28 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. |
|
|
| var $fm; // first record to display |
var $fm; // first record to display |
| var $fl; // is the filter row displayed (boolean) |
var $fl; // is the filter row displayed (boolean) |
| var $fds; // sql field names |
var $fds; // sql field names |
| |
var $fdn; // sql field names => $k |
| var $num_fds; // number of fields |
var $num_fds; // number of fields |
| var $options; // options for users: ACDFVPI |
var $options; // options for users: ACDFVPI |
| var $fdd; // field definitions |
var $fdd; // field definitions |
| Line 2267 function phpMyEdit_filter_handler(theFor |
|
| Line 2268 function phpMyEdit_filter_handler(theFor |
|
| // Preparing query |
// Preparing query |
| $query = ''; |
$query = ''; |
| $key_col_val = ''; |
$key_col_val = ''; |
| for ($k = 0; $k < $this->num_fds; $k++) { |
// prepare newvals array |
| if ($this->processed($k)) { |
|
| } |
|
| } |
|
| $vals_quoted = array(); |
|
| $newvals = array(); |
$newvals = array(); |
| for ($k = 0; $k < $this->num_fds; $k++) { |
for ($k = 0; $k < $this->num_fds; $k++) { |
| if ($this->processed($k)) { |
if ($this->processed($k)) { |
| Line 2279 function phpMyEdit_filter_handler(theFor |
|
| Line 2276 function phpMyEdit_filter_handler(theFor |
|
| if ($this->readonly($k)) { |
if ($this->readonly($k)) { |
| $fn = (string) @$this->fdd[$k]['default']; |
$fn = (string) @$this->fdd[$k]['default']; |
| } else { |
} else { |
| $fn = $this->get_cgi_var($this->fds[$k]); |
$fn = $this->get_cgi_var($fd); |
| } |
} |
| if ($fd == $this->key) { |
if ($fd == $this->key) { |
| $key_col_val = $fn; |
$key_col_val = $fn; |
| } |
} |
| if ($query == '') { |
$newvals[$fd] = is_array($fn) ? join(',',$fn) : $fn; |
| $query = 'INSERT INTO '.$this->tb.' ('.$fd; // ) |
|
| } else { |
|
| $query .= ','.$fd; |
|
| } |
|
| $newvals[$this->fds[$k]] = is_array($fn) ? join(',',$fn) : $fn; |
|
| if ($this->col_has_sqlw($k)) { |
|
| $val = $newvals[$this->fds[$k]]; |
|
| $val_as = addslashes($val); |
|
| $val_qas = '"'.addslashes($val).'"'; |
|
| $vals_quoted[$k] = $this->substituteVars( |
|
| $this->fdd[$k]['sqlw'], array( |
|
| 'val_qas' => $val_qas, |
|
| 'val_as' => $val_as, |
|
| 'val' => $val |
|
| )); |
|
| } else { |
|
| $vals_quoted[$k] = addslashes($newvals[$this->fds[$k]]); |
|
| $vals_quoted[$k] = "'".$vals_quoted[$k]."'"; |
|
| } |
|
| } |
} |
| } |
} |
| // Creating array of changed keys ($changed) |
// Creating array of changed keys ($changed) |
| $changed = array_keys($newvals); |
$changed = array_keys($newvals); |
| // Before trigger |
// Before trigger, newvals can be efectively changed |
| if (isset($this->triggers['insert']['before'])) { |
if (isset($this->triggers['insert']['before'])) { |
| $ret = include($this->triggers['insert']['before']); |
$ret = include($this->triggers['insert']['before']); |
| if ($ret == false) { |
if ($ret == false) { |
| Line 2316 function phpMyEdit_filter_handler(theFor |
|
| Line 2294 function phpMyEdit_filter_handler(theFor |
|
| } |
} |
| } |
} |
| // Real query (no additional query in this method) |
// Real query (no additional query in this method) |
| $query .= ') VALUES ('.join(',',$vals_quoted).')'; // ) |
foreach($newvals as $fd => $val) { |
| |
if($fd == '' ) continue; |
| |
if ($this->col_has_sqlw($this->fdn[$fd])) { |
| |
$val_as = addslashes($val); |
| |
$val_qas = '"'.addslashes($val).'"'; |
| |
$value = $this->substituteVars( |
| |
$this->fdd[$this->fdn[$fd]]['sqlw'], array( |
| |
'val_qas' => $val_qas, |
| |
'val_as' => $val_as, |
| |
'val' => $val |
| |
)); |
| |
} else { |
| |
$value = "'".addslashes($val)."'"; |
| |
} |
| |
if ($query == '') { |
| |
$query = 'INSERT INTO `'.$this->tb.'` (`'.$fd.'`'; // ) |
| |
$query2 = ') VALUES ('.$value.''; |
| |
} else { |
| |
$query .= ', `'.$fd.'`'; |
| |
$query2 .= ', '.$value.''; |
| |
} |
| |
} |
| |
$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 = @mysql_affected_rows($this->dbh).' '.$this->labels['record added']; |
| if (! $res) { |
if (! $res) { |
| Line 2626 function phpMyEdit_filter_handler(theFor |
|
| Line 2626 function phpMyEdit_filter_handler(theFor |
|
| $field_num = 0; |
$field_num = 0; |
| $num_fields_displayed = 0; |
$num_fields_displayed = 0; |
| $this->fds = array(); |
$this->fds = array(); |
| |
$this->fdn = array(); |
| $this->displayed = array(); |
$this->displayed = array(); |
| $this->guidance = false; |
$this->guidance = false; |
| foreach (array_keys($this->fdd) as $key) { |
foreach (array_keys($this->fdd) as $key) { |
| Line 2633 function phpMyEdit_filter_handler(theFor |
|
| Line 2634 function phpMyEdit_filter_handler(theFor |
|
| continue; |
continue; |
| } |
} |
| $this->fds[$field_num] = $key; |
$this->fds[$field_num] = $key; |
| |
$this->fdn[$key] = $field_num; |
| /* We must use here displayed() function, because displayed[] array |
/* We must use here displayed() function, because displayed[] array |
| is not created yet. We will simultaneously create that array as well. */ |
is not created yet. We will simultaneously create that array as well. */ |
| if ($this->displayed[$field_num] = $this->displayed($field_num)) { |
if ($this->displayed[$field_num] = $this->displayed($field_num)) { |