Location: PHPKode > projects > OpenDataCenter Network Management System > include/mainview_page/device/delete.php
<?php
// ----------------------------------------------------------------------
// Copyright (C) 2007 by GREGORY LE BRAS
// ----------------------------------------------------------------------
// LICENSE
//
// This file is part of ODCNMS - Open DataCenter Network Management System
// 
// ODCNMS 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.
// 
// Foobar 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 Foobar; if not, write to the Free Software
// Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
// ----------------------------------------------------------------------
// Original Author of file: GREGORY LE BRAS - http://www.odcnms.org/
// ----------------------------------------------------------------------
?>
<?php
if (!isset($delete))
{
	$request=mysql_query("SELECT * FROM $name_table_device WHERE id=\"$_GET[id]\"") or die ("ERROR!");

	while($tmp_request=mysql_fetch_array($request))
	{
	
		$request_ip=mysql_query("SELECT ip FROM $name_table_ip_address WHERE id=\"$tmp_request[ip_address_id]\"") or die ("ERROR!") ;
		
		while ($tmp_request_ip=mysql_fetch_array($request_ip))
		{
			$addressarray= explode(".",$tmp_request_ip['ip']);
		}
?>
<form method="post" action="index.php?include=mainview&page=device&action=delete&delete=ok&id=<?php echo $id;?>" name="delete_device">
	<fieldset class="form">
		<legend><img src="images/delete.gif" alt="Delete" align="top"> <?php echo TXT_DELETE; ?> <?php echo TXT_DEVICE; ?></legend>
		<label><?php echo TXT_NAME; ?></label>
		<input type="text" name="name" size="50" value="<?php echo $tmp_request['name']; ?>" READONLY DISABLED><br>
		<label><?php echo TXT_MANUFACTURER; ?></label>
		<?php
			$request2=mysql_query("SELECT id,name,manufacturer_id FROM $name_table_model WHERE id=$tmp_request[model_id]") or die ("ERROR!");
			
			while($tmp_request2=mysql_fetch_array($request2))
			{
				$request3=mysql_query("SELECT id,name FROM $name_table_manufacturer WHERE id=$tmp_request2[manufacturer_id]") or die ("ERROR!");
				
				while($tmp_request3=mysql_fetch_array($request3))
				{
					echo "<input type=\"text\" name=\"manufacturer\" size=\"50\" value=\"$tmp_request3[name]\" readonly disabled>";
				}
			}
		?>
		<label><?php echo TXT_CATEGORY; ?></label>
		<?php
			$request2=mysql_query("SELECT id,name,category_id FROM $name_table_model WHERE id=$tmp_request[model_id]") or die ("ERROR!");
			
			while($tmp_request2=mysql_fetch_array($request2))
			{
				$request3=mysql_query("SELECT id,name FROM $name_table_category WHERE id=$tmp_request2[category_id]") or die ("ERROR!");
				
				while($tmp_request3=mysql_fetch_array($request3))
				{
					echo "<input type=\"text\" name=\"category\" size=\"50\" value=\"$tmp_request3[name]\" readonly disabled>";
				}
			}			
		?>
		<label><?php echo TXT_MODEL; ?></label>
		<?php
			$request2=mysql_query("SELECT id,name FROM $name_table_model WHERE id=$tmp_request[model_id]") or die ("ERROR!");
			
			while($tmp_request2=mysql_fetch_array($request2))
			{
				echo "<input type=\"text\" name=\"model\" size=\"50\" value=\"$tmp_request2[name]\" readonly disabled>";
			}		
		?>		
		<label><?php echo TXT_ADDRESS; ?></label>
		<input type="text" name="oct1" id="oct1" size="3" maxlength="3" value="<?php echo $addressarray[0]; ?>" onkeydown="keynext(event.keyCode,'oct2');if (event.keyCode==190) return false;" onKeyPress="return numbersonly(this, event);" DISABLED><span style="top: -6px;position:relative;">.</span><input type="text" name="oct2" id="oct2" onkeydown="keynext(event.keyCode,'oct3');if (event.keyCode==190) return false;" size="3" maxlength="3" value="<?php echo $addressarray[1]; ?>"onKeyPress="return numbersonly(this, event);" DISABLED><span style="top: -6px;position:relative;">.</span><input type="text" name="oct3" id="oct3" size="3" maxlength="3" value="<?php echo $addressarray[2]; ?>"onkeydown="keynext(event.keyCode,'oct4');if (event.keyCode==190) return false;" onKeyPress="return numbersonly(this, event);" DISABLED><span style="top: -6px;position:relative;">.</span><input type="text" name="oct4" id="oct4" size="3" maxlength="3" value="<?php echo $addressarray[3]; ?>" onKeyPress="return numbersonly(this, event);" DISABLED><br>		
		<label><?php echo TXT_DESCRIPTION; ?></label>
		<textarea name="description" rows="10" cols="50" READONLY DISABLED><?php echo $tmp_request['description']; ?></textarea><br>
		<input type="submit" name="submit" value="<?php echo TXT_DELETE_IT_ALL_ASSOCIATED_ITEMS; ?>" onClick="return confirmDeleteall('<?php echo TXT_DELETE_CONFIRMATION_DEVICE; ?>');"> <input type="button" value="Back" onClick="javascript:history.go(-1);">
	</fieldset>
</form>
 <script language="JavaScript" type="text/javascript">
	 var frmvalidator = new Validator("delete_device");
		 frmvalidator.addValidation("name","req","Please enter the name of the device");
		 frmvalidator.addValidation("name","maxlen=255",
"Max length for Name is 255");
</script>
<?php
	}
}
else if ($delete=="ok")
{
	$request=mysql_query("SELECT name FROM $name_table_device WHERE id=\"$id\"") or die ("ERROR!");

	while($tmp_request=mysql_fetch_array($request))
	{
		$name=$tmp_request['name'];
	}
	
	$request_slot=mysql_query("SELECT id FROM $name_table_slot WHERE device_id=\"$id\"") or die ("ERROR!");
	while($tmp_request_slot=mysql_fetch_array($request_slot))
	{
		$request_interface=mysql_query("SELECT id FROM $name_table_interface WHERE slot_id=\"$tmp_request_slot[id]\"") or die ("ERROR!");
		while($tmp_request_interface=mysql_fetch_array($request_interface))
		{
			$query4=mysql_query("DELETE FROM $name_table_link_interface_interface WHERE interface_id=$tmp_request_interface[id] OR interface2_id=$tmp_request_interface[id]");					
			$query5=mysql_query("DELETE FROM $name_table_link_port_interface WHERE interface_id=$tmp_request_interface[id]");					
		}
		$query6=mysql_query("DELETE FROM $name_table_interface WHERE slot_id=$tmp_request_slot[id]");
	}
	
	
	$query=mysql_query("DELETE FROM $name_table_device WHERE id=$id");
	$query2=mysql_query("DELETE FROM $name_table_slot WHERE device_id=$id");
	$query3=mysql_query("DELETE FROM $name_table_device_ip_address WHERE device_id=$id");
	$query4=mysql_query("DELETE FROM $name_table_vlan_device WHERE device_id=$id");

	if(!$query)
	{
		echo "<center><div id=\"status\" style=\"color:red\"><img src=\"images/warning.png\" alt=\"WARNING\"><br><br>";
		echo TXT_DATABASE_ERROR;
		echo "</div><br><a href=\"javascript:history.go(-2);\">";
		echo TXT_BACK;
		echo "</a></center>";
	}
	else
	{
		$currentdate = date('Y-m-d');
		$currenttime = date("H:i:s"); 
	
		user_log ($_SESSION['login'],$name_table_users,$name_table_users_log,"delete","device","$name ($id)",$mysql_hostname,$mysql_username,$mysql_password,$mysql_database);
		
		foreach ($syslog_server as $arrayvalue)
		{
			$syslog = new Syslog();
			$syslog->SetFacility(13);
			$syslog->SetSeverity(5);
			$syslog->SetProcess('odcnms');
			$syslog->SetHostname('');
			$syslog->SetFqdn('');
			$syslog->SetIpFrom('');		
			$syslog->SetContent($currentdate.' '.$currenttime.' user: '.$_SESSION['login'].' - delete device '.$name.'('.$id.')');
			$syslog->SetServer($arrayvalue);
			$syslog->Send();
		}
		
		echo "<center><div id=\"status\" style=\"color:green\"><img src=\"images/info.png\" alt=\"INFO\"><br><br>";
		echo TXT_SUCCESSFULLY_DELETE_DEVICE;
		echo "</div><br><a href=\"javascript:history.go(-2);\">";
		echo TXT_BACK;
		echo "</a></center>";
	}

}
else if ($delete=="multiple")
{
	foreach ($_POST['delAnn'] as $id)
	{
		$request=mysql_query("SELECT name FROM $name_table_device WHERE id=\"$id\"") or die ("ERROR!");

		while($tmp_request=mysql_fetch_array($request))
		{
			$name=$tmp_request['name'];
		}
		
		$request_slot=mysql_query("SELECT id FROM $name_table_slot WHERE device_id=\"$id\"") or die ("ERROR!");
		while($tmp_request_slot=mysql_fetch_array($request_slot))
		{
			$request_interface=mysql_query("SELECT id FROM $name_table_interface WHERE slot_id=\"$tmp_request_slot[id]\"") or die ("ERROR!");
			while($tmp_request_interface=mysql_fetch_array($request_interface))
			{
				$query4=mysql_query("DELETE FROM $name_table_link_interface_interface WHERE interface_id=$tmp_request_interface[id] OR interface2_id=$tmp_request_interface[id]");					
				$query5=mysql_query("DELETE FROM $name_table_link_port_interface WHERE interface_id=$tmp_request_interface[id]");					
			}
			$query6=mysql_query("DELETE FROM $name_table_interface WHERE slot_id=$tmp_request_slot[id]");
		}
		
	$query=mysql_query("DELETE FROM $name_table_device WHERE id=$id");
	$query2=mysql_query("DELETE FROM $name_table_slot WHERE device_id=$id");
	$query3=mysql_query("DELETE FROM $name_table_link_device_ip_address WHERE device_id=$id");
	$query4=mysql_query("DELETE FROM $name_table_link_vlan_device WHERE device_id=$id");
	
	$currentdate = date('Y-m-d');
	$currenttime = date("H:i:s"); 

	user_log ($_SESSION['login'],$name_table_users,$name_table_users_log,"delete","device","$name ($id)",$mysql_hostname,$mysql_username,$mysql_password,$mysql_database);
	
	foreach ($syslog_server as $arrayvalue)
	{
		$syslog = new Syslog();
		$syslog->SetFacility(13);
		$syslog->SetSeverity(5);
		$syslog->SetProcess('odcnms');
		$syslog->SetHostname('');
		$syslog->SetFqdn('');
		$syslog->SetIpFrom('');		
		$syslog->SetContent($currentdate.' '.$currenttime.' user: '.$_SESSION['login'].' - delete device '.$name.'('.$id.')');
		$syslog->SetServer($arrayvalue);
		$syslog->Send();
	}
	
	}

	if(!$query)
	{
		echo "<center><div id=\"status\" style=\"color:red\"><img src=\"images/warning.png\" alt=\"WARNING\"><br><br>";
		echo TXT_DATABASE_ERROR;
		echo "</div><br><a href=\"javascript:history.go(-2);\">";
		echo TXT_BACK;
		echo "</a></center>";
	}
	else
	{		
		echo "<center><div id=\"status\" style=\"color:green\"><img src=\"images/info.png\" alt=\"INFO\"><br><br>";
		echo TXT_SUCCESSFULLY_DELETE_DEVICE;
		echo "</div><br><a href=\"javascript:history.go(-2);\">";
		echo TXT_BACK;
		echo "</a></center>";
	}
		
}
?>
Return current item: OpenDataCenter Network Management System