Location: PHPKode > projects > Network Traffic Monitor > online/delete.php
<?php

#Network Traffic Monitor is an application to monitor the network traffic on all SNMP managable devices.
#
#Copyright (c) 2004, Daimler Trust nv <hide@address.com> - Jan Van Hees <hide@address.com>
# 
#This file is part of Network Traffic Monitor.
#
#    Network Traffic Monitor 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.
#
#    Network Traffic Monitor 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 Network Traffic Monitor; if not, write to the Free Software
#    Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
/*
* This script takes care of all delete statements
* first check which object type has 2 b deleted
* Then define a query 4 every delete statement
*/
require_once("../auth.php");
require_once ("../config.php");
require_once ("HTML/Template/IT.php");
require_once "HTML/Table.php";
if($_POST['port']){
	header("Location: error.php");
	exit;
}
$type = $_GET['type'];
$id = $_GET['i'];
$con = $_GET['con'];

$db = dbLogin();

$tpl = new HTML_Template_IT(TEMPLATEDIR);
$tpl->loadTemplatefile("delete.tpl");

switch ($type){
	case 'user':{
			$tpl->setVariable("type", "User");
			$sql = "DELETE FROM users where uid='$id' ";
			$what = $db->getOne("SELECT fullname FROM USERS WHERE uid='$id'");	
			$conflict = 0;
			$script="userlist.php";
		}//case user
	break;
	case 'company': {
			$tpl->setVariable("type", "Company");
			$sql = "DELETE FROM company WHERE cid='$id'";
			$what = $db->getOne("SELECT compname FROM company WHERE cid='$id'");
			$conflict = 0;
			$script="firms.php";
		}//case company
	break;
	case 'switch':{
			$tpl->setVariable("type", "company");
			$sql = "DELETE FROM devices WHERE did='$id'";
			$what = $db->getOne("SELECT devicename FROM devices WHERE did='$id'");
			$conflict=0;
			$script="switch.php";
		}//case switch
	break;
	case 'port':{
			$tpl->setVariable("type", "Port");
			$sql = "DELETE FROM ports WHERE pid='$id'";
			$what = $db->getOne("SELECT portname FROM ports WHERE pid='$id'");
			$conflict=0;
			$script="devices.php";
		}//case port
	break;
	case 'group':{
			$tpl->setVariable("type", "group");
			# if a group is deleted, all linked ports should be deleted 2
			# 2 take care of all those deletes @ once: call a stored procedure
			$sql = "SELECT delete_group($id)";
			$what = $db->getOne("SELECT groupname FROM groups WHERE gid='$id'");
			$conflict=0;
			$script="groups.php";
		}//case group
	break;
	case 'speed':{
			$tpl->setVariable("type", "Speed");
			$sql = "DELETE FROM speed WHERE spid='$id'";
			$conflict=0;
			$script="bandwith.php";
		}//case speed
	break;

}//switch

if($con=="yes"){
	$error = $db->query($sql) or die;
	
	if($type == "group") $error=1;
	if($error != 1){
		$tpl->setVariable("message", $error->getMessage());
	}//if error
	else{
		if($conflict == 0)
			$tpl->setVariable("message", "$what deleted");
		else
			$tpl->setVariable("message", $conflict);
	}//else

	header("Location: $script");
	exit();
}//confirm = yes
else{
	$tpl->setVariable("message", "Delete $type $what?");
	$tpl->setVariable("confirm", "<a href=\"delete.php?type=$type&i=$id&con=yes\">Yes</a> &nbsp; <a href=\"home.php\">No</a>");
}//not confirmed yet

$content = $tpl->get();
fillFrame($db, $content);



dblogout($db);

?>  
Return current item: Network Traffic Monitor