po/src/admin.user.del.2.php

125 lines
4.2 KiB
PHP

<?php
// Copyright (C) 2002-2006 Balint Kis (balint@k-i-s.net)
// Copyright (C) 2005-2013 Solomon Peachy (pizza@shaftnet.org)
// This program is free software; you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation; either version 3 of the License, or
// (at your option) any later version.
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
// You should have received a copy of the GNU General Public License
// along with this program; if not, write to the Free Software
// Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
include_once "include/config.php";
include_once "include/site.php";
include_once "include/admin.php";
include_once "include/common.php";
$database = site_prolog(PO_USER_TYPE_ADMIN);
$user_id = pg_escape_string($database, $_REQUEST['user']);
/* First we nuke the user's photos and their associated records */
$result = nuke_photos($database, FALSE, $user_id);
pg_query($database, "begin");
if ($result) {
$result = pg_query($database, "delete from import_results where users = '$user_id'");
}
if ($result) {
// Nuke all photo ratings made by the user.
$result = pg_query($database, "delete from rating where users='$user_id'");
}
if ($result) {
// Empty out all albums owned by the user.
$result = pg_query($database, "delete from album_content where album in (select identifier from album where users='$user_id')");
}
if ($result) {
// Nuke all albums owned by the user.
$result = pg_query($database, "delete from album where users='$user_id'");
}
if ($result) {
// Nuke all folders owned by the user.
$result = pg_query($database, "delete from folder where users='$user_id'");
}
if ($result) {
// Nuke the user's preferences.
$result = pg_query($database, "delete from user_preferences where owner='$user_id'");
}
if ($result) {
// Nuke all datebook events owned by the user.
$result = pg_query($database, "delete from calendar where users='$user_id'");
}
if ($result) {
// Nuke all datebooks where the user is the client.
$result = pg_query($database, "update calendar set client = null where client='$user_id'");
}
if ($result) {
// Nuke all client records where the user is the client.
$result = pg_query($database, "delete from client where users='$user_id' or client='$user_id'");
}
/* Nuke all of the user's profile/equipment/etc */
if ($result) {
$result = pg_query($database, "update location set users=null where users='$user_id'");
}
if ($result) {
$result = pg_query($database, "update paper set last_modifying_users=null where last_modifying_users='$user_id'");
}
if ($result) {
$result = pg_query($database, "delete from film where users='$user_id'");
}
if ($result) {
$result = pg_query($database, "update film_type set last_modifying_users=null where last_modifying_users='$user_id'");
}
if ($result) {
$result = pg_query($database, "delete from camera where users='$user_id'");
}
if ($result) {
$result = pg_query($database, "update camera_type set last_modifying_users=null where last_modifying_users='$user_id'");
}
if ($result) {
$result = pg_query($database, "delete from equipment where users='$user_id'");
}
if ($result) {
$result = pg_query($database, "update camera_type set last_modifying_users=null where last_modifying_users='$user_id'");
}
if ($result) {
$result = pg_query($database, "update manufacturer set last_modifying_users=null where last_modifying_users='$user_id'");
}
/* Commit things */
if ($result) {
pg_query($database, "commit");
} else {
site_push_error($strings['errors_db_insert_failed']);
pg_query($database, "rollback");
}
/* Finally, nuke the user user record itself */
pg_query($database, "begin");
if ($result) {
$result = pg_query($database, "delete from users where identifier='$user_id'");
}
if ($result) {
pg_query($database, "commit");
} else {
site_push_error($strings['errors_db_insert_failed']);
pg_query($database, "rollback");
}
site_epilog($database);
header("Location: admin.php?selector=".$admin_data['users_n_clients']['idx']);
?>