forked from science-ation/science-ation
- Fix the user dupe code, now that username,year is unique
This commit is contained in:
parent
65e5bfc0fa
commit
d5676576a7
10
user.inc.php
10
user.inc.php
@ -457,8 +457,10 @@ function user_purge($u, $type=false)
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/* Duplicate a row in the users table, or any one of the users_* tables. */
|
||||||
function user_dupe_row($db, $key, $val, $newval)
|
function user_dupe_row($db, $key, $val, $newval)
|
||||||
{
|
{
|
||||||
|
$nullfields = array('deleteddatetime'); /* Fields that can be null */
|
||||||
$q = mysql_query("SELECT * FROM $db WHERE $key='$val'");
|
$q = mysql_query("SELECT * FROM $db WHERE $key='$val'");
|
||||||
if(mysql_num_rows($q) != 1) {
|
if(mysql_num_rows($q) != 1) {
|
||||||
echo "ERROR duplicating row in $db: $key=$val NOT FOUND.\n";
|
echo "ERROR duplicating row in $db: $key=$val NOT FOUND.\n";
|
||||||
@ -468,8 +470,10 @@ function user_dupe_row($db, $key, $val, $newval)
|
|||||||
$i[$key] = $newval;
|
$i[$key] = $newval;
|
||||||
|
|
||||||
foreach($i as $k=>$v) {
|
foreach($i as $k=>$v) {
|
||||||
if($v == NULL)
|
if($v == NULL && in_array($k, $nullfields))
|
||||||
$i[$k] = 'NULL';
|
$i[$k] = NULL;
|
||||||
|
else if($k == 'year')
|
||||||
|
$i[$k] = $config['FAIRYEAR'];
|
||||||
else
|
else
|
||||||
$i[$k] = '\''.mysql_escape_string($v).'\'';
|
$i[$k] = '\''.mysql_escape_string($v).'\'';
|
||||||
}
|
}
|
||||||
@ -478,7 +482,7 @@ function user_dupe_row($db, $key, $val, $newval)
|
|||||||
$vals = join(',', array_values($i));
|
$vals = join(',', array_values($i));
|
||||||
|
|
||||||
$q = "INSERT INTO $db ($keys) VALUES ($vals)";
|
$q = "INSERT INTO $db ($keys) VALUES ($vals)";
|
||||||
echo "Dupe Query: [$q]";
|
// echo "Dupe Query: [$q]";
|
||||||
$r = mysql_query($q);
|
$r = mysql_query($q);
|
||||||
echo mysql_error();
|
echo mysql_error();
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user