Location: PHPKode > projects > OpenDataCenter Network Management System > include/mainview_page/ip_address/add.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($add))
{
?>
<form method="post" action="index.php?include=mainview&page=ip_address&action=add&add=ok" name="add_ip_address">
	<fieldset class="form" style="min-width:1000px;">
		<legend><img src="images/add.gif" alt="Add" align="top"> <?php echo TXT_ADD; ?> <?php echo TXT_IP_ADDRESS; ?></legend>
		<?php
		if (!isset($subnet_id))
		{
		?>
		<label><?php echo TXT_NETWORK; ?></label>
		<select name="network" id="network" size="1" onchange="javascript:urlredirectdiv('ajax_view.php?what=ajaxsubnet&network_id='+this.value,'ajaxsubnetarea');">
			<option value="null"><?php echo TXT_SELECT_NETWORK_SEGMENT; ?></option>
		<?php
		$request=mysql_query("select id,name FROM $name_table_network") or die ("ERROR!");

		while($tmp_request=mysql_fetch_array($request))
		{
			echo "<option value=\"$tmp_request[id]\">$tmp_request[name]</option>";
		}
		?>
		</select>
		<div id="ajaxsubnetarea"></div>
		<div id="ajaxipaddressarea"></div>
		<?php
		}
		else
		{
		?>
		<label><?php echo TXT_SUBNET; ?></label>
		<select name="subnet" id="subnet" size="1" onchange="javascript:urlredirectdiv('ajax_view.php?what=ajaxipaddress&subnet_id='+this.value,'ajaxipaddressarea');document.getElementById('oldaddressdiv').style.display='none';">
			<option value="null"><?php echo TXT_SELECT_SUBNET; ?></option>
		<?php
		$request=mysql_query("select id,name FROM $name_table_subnet") or die ("ERROR!");

		while($tmp_request=mysql_fetch_array($request))
		{
			if ($subnet_id == $tmp_request['id'])
			{
				echo "<option value=\"$tmp_request[id]\" SELECTED>$tmp_request[name]</option>";
				$request2=mysql_query("select id,address,mask FROM $name_table_subnet WHERE id=$tmp_request[id]") or die ("ERROR!");

				while($tmp_request2=mysql_fetch_array($request2))
				{
					$addressarray = explode(".", $tmp_request2['address']);
				}
			}
			else
			{
				echo "<option value=\"$tmp_request[id]\">$tmp_request[name]</option>";
			}
		}
		?>
		</select>
		<div id="ajaxipaddressarea"></div>
		<div id="oldaddressdiv">
		<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);"><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);"><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);"><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);"><br>
		</div>
		<?php
		}
		?>
		<label><?php echo TXT_MAC_ADDRESS; ?> <font size="1">(xxxx.xxxx.xxxx format)</font></label>
		<input type="text" name="mac1" id="mac1" size="4" maxlength="4" onkeydown="keynext(event.keyCode,'mac2');if (event.keyCode==190) return false;"><span style="top: -6px;position:relative;">.</span><input type="text" name="mac2" id="mac2" onkeydown="keynext(event.keyCode,'mac3');if (event.keyCode==190) return false;" size="4" maxlength="4"><span style="top: -6px;position:relative;">.</span><input type="text" name="mac3" id="mac3" size="4" maxlength="4" onkeydown="keynext(event.keyCode,'mac4');if (event.keyCode==190) return false;"><br>
		<label style="clear:left;"><?php echo TXT_STATUS; ?></label>
		<select name="status" size="1">
			<option value="0"><?php echo TXT_ASSIGNED; ?></option>
			<option value="1"><?php echo TXT_UNUSED; ?></option>
			<option value="2"><?php echo TXT_RESERVED; ?></option>
		</select>		
		<label><?php echo TXT_NAME; ?></label>
		<input type="text" name="name" size="50"><br>
		<label style="clear:left;"><?php echo TXT_DESCRIPTION; ?></label>
		<textarea name="description" rows="5" cols="50"></textarea><br>
		<input type="hidden" name="customer" value="">
		<input type="submit" name="submit" value="<?php echo TXT_ADD; ?>">
		<input type="button" name="Cancel" value="<?php echo TXT_CANCEL; ?>" onclick="javascript:history.go(-1);">
	</fieldset>
</form>
<br><center><a href="javascript:history.go(-1);"><?php echo TXT_BACK; ?></a></center>
<script language="JavaScript" type="text/javascript">
	 var frmvalidator = new Validator("add_ip_address");
		 frmvalidator.addValidation("network","dontselect=0","Please select the network of the ip address");
		 frmvalidator.addValidation("mac1","req","Please enter the MAC of the ip address");		 
		 frmvalidator.addValidation("mac2","req","Please enter the MAC of the ip address");		 
		 frmvalidator.addValidation("mac3","req","Please enter the MAC of the ip address");		 
		 frmvalidator.addValidation("name","req","Please enter the name of the ip address");		 
</script>
<?php
}
else if ($add=="ok")
{

	$address = $oct1.".".$oct2.".".$oct3.".".$oct4;
	$mac = $mac1.".".$mac2.".".$mac3;

	$query=mysql_query("INSERT INTO $name_table_ip_address VALUES ('',\"$subnet\",\"$address\",\"$mac\",\"$name\",\"$description\",\"$status\")") or die ("ERROR!");
		
	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
	{
		$ip_address_id = mysql_insert_id();
		
		$currentdate = date('Y-m-d');
		$currenttime = date("H:i:s"); 
		
		user_log ($_SESSION['login'],$name_table_users,$name_table_users_log,"add","ip address","$address ($ip_address_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'].' - add ip address '.$address.'('.$ip_address_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_ADD_IP_ADDRESS;
		echo "</div><br><div id=\"status\" style=\"color:blue\"><img src=\"images/question.gif\" alt=\"INFO\"><br><br>";
		echo TXT_WHAT_DO_YOU_WANT_TO_DO;
		echo "<form name=\"option_after\"><select name=\"select\" onchange=\"goto(this.form);\" class=\"form\"><option value=\"\">-------";
		echo TXT_CHOOSE_SELECTION;
		echo "-------</option><option value=\"index.php?include=mainview&page=ip_address&action=add\">";
		echo TXT_ADD_ANOTHER_IP_ADDRESS;
		echo "</option></select></form></div><br><br><a href=\"javascript:history.go(-2);\">";
		echo TXT_BACK;
		echo "</a></center>";
	} 
}
?>
Return current item: OpenDataCenter Network Management System