Fix user methods like deleting accounts

This commit is contained in:
patrick 2025-01-30 03:29:35 +00:00
parent 51650c4f34
commit 1ced97807c
2 changed files with 11 additions and 10 deletions

View File

@ -217,9 +217,9 @@ function user_load($user, $uid = false)
$q->execute();
if ($q->rowCount() != 1) {
echo "Query [$query] returned " . $q->rowCount() . " rows\n";
/*echo "Query [$query] returned " . $q->rowCount() . " rows\n";
echo '<pre>';
print_r(debug_backtrace());
print_r(debug_backtrace());*/
return false;
}
@ -690,14 +690,14 @@ 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($table, $key, $val, $newval)
{
global $config, $pdo;
$nullfields = array('deleteddatetime'); /* Fields that can be null */
$q = $pdo->prepare("SELECT * FROM $db WHERE $key='$val'");
$nullfields = array('id','sex','deleteddatetime'); /* Fields that can be null */
$q = $pdo->prepare("SELECT * FROM $table WHERE $key='$val'");
$q->execute();
if ($q->rowCount() != 1) {
echo "ERROR duplicating row in $db: $key=$val NOT FOUND.\n";
echo "ERROR duplicating row in $table: $key=$val NOT FOUND.\n";
exit;
}
$i = $q->fetch(PDO::FETCH_ASSOC);
@ -715,12 +715,12 @@ function user_dupe_row($db, $key, $val, $newval)
$keys = '`' . join('`,`', array_keys($i)) . '`';
$vals = join(',', array_values($i));
$q = "INSERT INTO $db ($keys) VALUES ($vals)";
$q = "INSERT INTO $table ($keys) VALUES ($vals)";
$r = $pdo->prepare($q);
$r->execute();
show_pdo_errors_if_any($pdo);
$id = $pdo->errorInfo();
$id = $pdo->lastInsertId();
return $id;
}
@ -748,13 +748,14 @@ function user_dupe($u, $new_year)
echo "Cannot duplicate user ID {$u['id']}, they are deleted. Undelete them first.\n";
exit;
}
print ($r->year);
if ($r->year == $new_year) {
echo "Cannot duplicate user ID {$u['id']}, they already exist in year $new_year\n";
exit;
}
$id = user_dupe_row('users', 'id', $u['id'], NULL);
$q = $pdo->prepare("UPDATE users SET year = $new_year WHERE id = $id");
$q->execute();
/* Load the new user */

View File

@ -68,7 +68,7 @@ switch (get_value_from_array($_GET, 'action')) {
// okay here we go, lets get rid of them completely, since this is what theyve asked for
message_push(happy(i18n('Account successfully deleted. Goodbye')));
user_delete($u);
if ($_SESSION['embed'] == true)
if (get_value_from_array($_SESSION, 'embed') == true)
display_messages();
else
header('location: user_login.php?action=logout');