| version 1.157, 2004/12/27 03:10:27 |
version 1.158, 2004/12/27 17:57:54 |
|
|
| * http://platon.sk/projects/phpMyEdit/ |
* http://platon.sk/projects/phpMyEdit/ |
| */ |
*/ |
| |
|
| /* $Platon: phpMyEdit/phpMyEdit.class.php,v 1.156 2004/12/08 16:21:12 nepto Exp $ */ |
/* $Platon: phpMyEdit/phpMyEdit.class.php,v 1.157 2004/12/27 03:10:27 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. |
| Line 2347 function '.$this->js['prefix'].'filter_h |
|
| Line 2347 function '.$this->js['prefix'].'filter_h |
|
| // Preparing query |
// Preparing query |
| $query = ''; |
$query = ''; |
| $key_col_val = ''; |
$key_col_val = ''; |
| // prepare newvals 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 2370 function '.$this->js['prefix'].'filter_h |
|
| Line 2369 function '.$this->js['prefix'].'filter_h |
|
| return false; |
return false; |
| } |
} |
| // Real query (no additional query in this method) |
// Real query (no additional query in this method) |
| foreach($newvals as $fd => $val) { |
foreach ($newvals as $fd => $val) { |
| if($fd == '' ) continue; |
if ($fd == '') continue; |
| if ($this->col_has_sqlw($this->fdn[$fd])) { |
if ($this->col_has_sqlw($this->fdn[$fd])) { |
| $val_as = addslashes($val); |
$val_as = addslashes($val); |
| $val_qas = '"'.addslashes($val).'"'; |
$val_qas = '"'.addslashes($val).'"'; |
| Line 2428 function '.$this->js['prefix'].'filter_h |
|
| Line 2427 function '.$this->js['prefix'].'filter_h |
|
| $newvals = array(); |
$newvals = array(); |
| $oldvals = array(); |
$oldvals = array(); |
| $changed = array(); |
$changed = array(); |
| |
// Prepare query to retrieve oldvals |
| for ($k = 0; $k < $this->num_fds; $k++) { |
for ($k = 0; $k < $this->num_fds; $k++) { |
| if ($this->processed($k) && !$this->readonly($k)) { |
if ($this->processed($k) && !$this->readonly($k)) { |
| $fd = $this->fds[$k]; |
$fd = $this->fds[$k]; |
| $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 ($this->col_has_sqlw($k)) { |
if ($query_oldrec == '') { |
| $val = $newvals[$this->fds[$k]]; |
|
| $val_as = addslashes($val); |
|
| $val_qas = '"'.addslashes($val).'"'; |
|
| $newValue = $this->substituteVars( |
|
| $this->fdd[$k]['sqlw'], array( |
|
| 'val_qas' => $val_qas, |
|
| 'val_as' => $val_as, |
|
| 'val' => $val |
|
| )); |
|
| } else { |
|
| $newValue = $newvals[$this->fds[$k]]; |
|
| $newValue = "'".addslashes($newValue)."'"; |
|
| } |
|
| if ($query_real == '') { |
|
| $query_real = 'UPDATE '.$this->tb.' SET '.$fd.'='.$newValue; |
|
| $query_oldrec = 'SELECT '.$fd; |
$query_oldrec = 'SELECT '.$fd; |
| } else { |
} else { |
| $query_real .= ','.$fd.'='.$newValue; |
|
| $query_oldrec .= ','.$fd; |
$query_oldrec .= ','.$fd; |
| } |
} |
| } |
} |
| } |
} |
| $where_part = " WHERE (".$this->key.'='.$this->key_delim.$this->rec.$this->key_delim.')'; |
$where_part = " WHERE (".$this->key.'='.$this->key_delim.$this->rec.$this->key_delim.')'; |
| $query_real .= $where_part; |
|
| $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->tb . $where_part; |
| // Additional query (must go before real query) |
// Additional query (must go before real query) |
| Line 2465 function '.$this->js['prefix'].'filter_h |
|
| Line 2448 function '.$this->js['prefix'].'filter_h |
|
| $oldvals = @mysql_fetch_array($res, MYSQL_ASSOC); |
$oldvals = @mysql_fetch_array($res, MYSQL_ASSOC); |
| @mysql_free_result($res); |
@mysql_free_result($res); |
| // Creating array of changed keys ($changed) |
// Creating array of changed keys ($changed) |
| for ($k = 0; $k < $this->num_fds; $k++) { |
foreach ($newvals as $fd => $value) { |
| $key = $this->fds[$k]; |
if ($value != $oldvals[$fd]) |
| if (! $this->processed($k) || $this->readonly($k) || $oldvals[$key] == $newvals[$key]) { |
$changed[] = $fd; |
| continue; |
|
| } |
|
| $changed[] = $key; |
|
| } |
} |
| // Before trigger |
// Before trigger |
| if ($this->exec_triggers('update', 'before', $oldvals, $changed, $newvals) == false) { |
if ($this->exec_triggers('update', 'before', $oldvals, $changed, $newvals) == false) { |
| return false; |
return false; |
| } |
} |
| |
// Build the real query respecting changes to the newvals array |
| |
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_real == '') { |
| |
$query_real = 'UPDATE '.$this->tb.' SET '.$fd.'='.$value; |
| |
} else { |
| |
$query_real .= ','.$fd.'='.$value; |
| |
} |
| |
} |
| |
$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 = @mysql_affected_rows($this->dbh).' '.$this->labels['record changed']; |
| Line 2492 function '.$this->js['prefix'].'filter_h |
|
| Line 2494 function '.$this->js['prefix'].'filter_h |
|
| @mysql_free_result($res); |
@mysql_free_result($res); |
| // Creating array of changed keys ($changed) |
// Creating array of changed keys ($changed) |
| $changed = array(); |
$changed = array(); |
| for ($k = 0; $k < $this->num_fds; $k++) { |
foreach ($newvals as $fd => $value) { |
| $key = $this->fds[$k]; |
if ($value != $oldvals[$fd]) |
| if (! $this->processed($k) || $this->readonly($k) || $oldvals[$key] == $newvals[$key]) { |
$changed[] = $fd; |
| continue; |
|
| } |
|
| $changed[] = $key; |
|
| } |
} |
| // Notify list |
// Notify list |
| if (@$this->notify['update'] || @$this->notify['all']) { |
if (@$this->notify['update'] || @$this->notify['all']) { |