【php开源代码栏目提醒】:网学会员鉴于大家对php开源代码十分关注,论文会员在此为大家搜集整理了“tbl_replace.php”一文,供大家参考学习
<?php
/* $Id: tbl_replace.php,v 2.36.2.1 2006/02/12 14:15:56 lem9 Exp $ */
// vim: expandtab sw=4 ts=4 sts=4:
/**
* Gets some core libraries
*/
require_once('./libraries/common.lib.php');
// Check parameters
PMA_checkParameters(array('db', 'table', 'goto'));
PMA_DBI_select_db($db);
/**
* Initializes some variables
*/
// Defines the url to return in case of success of the query
if (isset($sql_query)) {
$sql_query = urldecode($sql_query);
}
if (!isset($dontlimitchars)) {
$dontlimitchars = 0;
}
if (!isset($pos)) {
$pos = 0;
}
$is_gotofile = FALSE;
if (isset($after_insert) && $after_insert == 'new_insert') {
$goto = 'tbl_change.php?'
. PMA_generate_common_url($db, $table, '&')
. '&goto=' . urlencode($goto)
. '&pos=' . $pos
. '&session_max_rows=' . $session_max_rows
. '&disp_direction=' . $disp_direction
. '&repeat_cells=' . $repeat_cells
. '&dontlimitchars=' . $dontlimitchars
. '&after_insert=' . $after_insert
. (empty($sql_query) ? '' : '&sql_query=' . urlencode($sql_query));
} elseif (isset($after_insert) && $after_insert == 'same_insert') {
$goto = 'tbl_change.php?'
. PMA_generate_common_url($db, $table, '&')
. '&goto=' . urlencode($goto)
. '&pos=' . $pos
. '&session_max_rows=' . $session_max_rows
. '&disp_direction=' . $disp_direction
. '&repeat_cells=' . $repeat_cells
. '&dontlimitchars=' . $dontlimitchars
. '&after_insert=' . $after_insert
. (empty($sql_query) ? '' : '&sql_query=' . urlencode($sql_query));
if (isset($primary_key)) {
foreach ($primary_key AS $pk) {
$goto .= '&primary_key[]=' . $pk;
}
}
} elseif (isset($after_insert) && $after_insert == 'edit_next') {
$goto = 'tbl_change.php?'
. PMA_generate_common_url($db, $table, '&')
. '&goto=' . urlencode($goto)
. '&pos=' . $pos
. '&session_max_rows=' . $session_max_rows
. '&disp_direction=' . $disp_direction
. '&repeat_cells=' . $repeat_cells
. '&dontlimitchars=' . $dontlimitchars
. '&after_insert=' . $after_insert
. (empty($
sql_query) ? '' : '&sql_query=' . urlencode($sql_query));
if (isset($primary_key)) {
foreach ($primary_key AS $pk) {
$local_query = 'SELECT * FROM ' . PMA_backquote($table) . ' WHERE ' . str_replace('` =', '` >', urldecode($pk)) . ' LIMIT 1;';
$res = PMA_DBI_query($local_query);
$row = PMA_DBI_fetch_row($res);
$meta = PMA_DBI_get_fields_meta($res);
$goto .= '&primary_key[]=' . urlencode(PMA_getUvaCondition($res, count($row), $meta, $row));
}
}
} elseif ($goto == 'sql.php') {
$goto = 'sql.php?'
. PMA_generate_common_url($db, $table, '&')
. '&pos=' . $pos
. '&session_max_rows=' . $session_max_rows
. '&disp_direction=' . $disp_direction
. '&repeat_cells=' . $repeat_cells
. '&dontlimitchars=' . $dontlimitchars
. '&sql_query=' . urlencode($sql_query);
} elseif (!empty($goto)) {
// Security checkings
$is_gotofile = preg_replace('@^([^?]+).*$@', '\\1', $goto);
if (!@file_exists('./' . $is_gotofile)) {
$goto = (! isset($table) || ! strlen($table)) ? 'db_details.php' : 'tbl_properties.php';
$is_gotofile = TRUE;
} else {
$is_gotofile = ($is_gotofile == $goto);
}
}
// Defines the url to return in case of failure of the query
if (isset($err_url)) {
$err_url = urldecode($err_url);
} else {
$err_url = str_replace('&', '&', $goto)
. (empty($primary_key) ? '' : '&primary_key=' . (is_array($primary_key) ? $primary_key[0] : $primary_key));
}
// Misc
$seen_binary = FALSE;
/**
* Prepares the update/insert of a row
*/
if (isset($primary_key)) {
// we were editing something => use primary key
$loop_array = (is_array($primary_key) ? $primary_key : array(0 => $primary_key));
$using_key = TRUE;
$is_insert = ($submit_type == $strInsertAsNewRow);
} else {
// new row => use indexes
$loop_array = array();
for ($i = 0; $i < $cfg['InsertRows']; $i++) $loop_array[$i] = $i;
$using_key = FALSE;
$is_insert = TRUE;
}
$query = array();
$message = '';
foreach ($loop_array AS $primary_key_index => $enc_primary_key) {
// skip fields to be ignored
if (!$using_key && isset($GLOBALS['insert_ignore_' . $enc_primary_key])) {
continue;
}
// Restore the "primary key" to a convenient format
$primary_key = urldecode($enc_primary_key);
// Defines the SET part of the sql query
$valuelist = '';
$fieldlist = '';
// Map multi-edit keys to single-level arrays, dependent on how we got the fields
$me_fields = isset($fields['multi_edit']) && isset($fields['multi_