Location: PHPKode > projects > Internet Task Management System > itms_mysql_build_0111/group_delete.php
<?php

/*
 * ITMS ValleyData source file version 1.0 May 11, 2001
 *
 * Displays a group delete confirmation, and executes the group removal
 *
 *
 * Internet Task Management System: An online system used for recording information about and assigning tasks and processes.
 * Copyright (C) 2001  ValleyData Programming Group
 *
 * 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 2 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., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
 *
 * See file named "gpl.txt" included with source code or
 * visit http://www.gnu.org/copyleft/gpl.txt on the internet.
 */
$title="Group Management - Delete";

include("header.php");

include("adminonly.php");

/*
 * All users will be removed from the deleted group as well
 */

$delete_group_name = get_group_name($delete_group);

$group_array = get_all_other_groups($delete_group);
if($group_array)
foreach ($group_array as $group) // For each user other than yourself, add the user to the list
{
	$group_options .= "<option value=\"" . $group["gid"] . "\">" . $group["groupname"] . "</option>\n";
}

$confirm_html = <<<CONFIRM
<table>
<tr>
	<tr>
		<td>
            <FORM METHOD=POST ACTION="group_delete.php">
			Reassign tasks and processes owned by $delete_group_name to group:
			<SELECT NAME="group_to_reassign">
			$group_options
			</SELECT>
			<INPUT TYPE="hidden" name="delete_now" value="$delete_group_name">
            <INPUT TYPE="hidden" name="delete_group" value="$delete_group">
			<INPUT TYPE="submit" value="Delete Group">
            <INPUT TYPE="button" value="Cancel" onClick="location='group_mgt.php'">
            </FORM>
		</td>
	</tr>
</table>
CONFIRM;

if(isset($delete_now)) //if they are sure they want to delete the group
{
    db_open();
    db_use();
	$query_reassign_tasks = "UPDATE task_types SET owner='$group_to_reassign' WHERE owner='$delete_group'";
	$query_reassign_processes = "UPDATE processes SET owner='$group_to_reassign' WHERE owner='$delete_group'";
	if(db_query($query_reassign_tasks) && db_query($query_reassign_processes))
	{
		$reassign_group_name = get_group_name($group_to_reassign);
		message_box("Tasks and processes owned by $delete_group_name have been sucessfully reassigned to $reassign_group_name");
	}
    $query = "DELETE FROM groups WHERE gid='$delete_group'";
    $query_users = "DELETE FROM user_groups WHERE gid='$delete_group'";
    if(db_query($query) && db_query($query_users)) //delete the group and remove all the users from the group
    {
        message_box("Group: $delete_group_name has been sucessfully removed");
    }
    else
    {
        message_box("Couldn't remove group: $delete_group_name");
    }
    print("<form>\n");
    print("<INPUT TYPE=\"button\" value=\"Ok\" onClick=\"location='group_mgt.php'\">");
    print("</form>\n");
} 
else if(!isset($cancel) && !isset($delete_now)) //if we need to confirm the delete
{
    message_box("Are You sure you want to delete " . $delete_group_name . " from ITMS?", "warning");
    print($confirm_html);
}

include("footer.php");

?>
Return current item: Internet Task Management System