Location: PHPKode > projects > OpenDataCenter Network Management System > include/mainview_page/vlan/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))
{
$request_count_subnet=mysql_query("SELECT count(*) FROM $name_table_subnet") or die ("ERROR!");
$result_subnet = mysql_fetch_array($request_count_subnet);

if ($result_subnet[0]==0)
{
	echo "<center><div id=\"status\" style=\"color:red\"><img src=\"images/warning.png\" alt=\"WARNING\"><br><br>";
	echo TXT_CANT_ADD_VLAN_WITHOUT_SUBNET_BEFORE;
	echo "</div><br><a href=\"javascript:history.go(-2);\">";
	echo TXT_BACK;
	echo "</a></center>";	
}
else
{
?>
<script language="JavaScript">
var opt = new OptionTransfer("list1","list2");
opt.setAutoSort(true);
opt.setDelimiter(";");
opt.saveNewLeftOptions("subnet");
opt.saveRemovedLeftOptions("removed_subnet");
</script>
<form method="post" action="index.php?include=mainview&page=vlan&action=add&add=ok" name="add_vlan">
	<fieldset class="form">
		<legend><img src="images/add.gif" alt="Add" align="top"> <?php echo TXT_ADD; ?> <?php echo TXT_VLAN; ?></legend>
		<label><?php echo TXT_NAME; ?></label>
		<input type="text" name="name" size="50"><br>
		<label><?php echo TXT_NUMBER; ?></label>
		<input type="text" name="number" size="20" onKeyPress="return numbersonly(this, event);"><br>	
		<label><?php echo TXT_SUBNET; ?></label>
		<table border="0">
		<tr>
			<td>
			<select name="list1" multiple="multiple" size="10" onDblClick="opt.transferRight()">		
			</select>
			</td>
			<td align="center" valign="middle">
				<input name="left" value="<?php echo TXT_ADD; ?> &lt;&lt;" ONCLICK="opt.transferLeft()" type="button"><br><br>
				<input name="left" value="<?php echo TXT_ADD; ?> <?php echo TXT_ALL; ?> &lt;&lt;" ONCLICK="opt.transferAllLeft()" type="button"><br><br>
				<input name="right" value="<?php echo TXT_REMOVE; ?> &gt;&gt;" ONCLICK="opt.transferRight()" type="button"><br><br>
				<input name="right" value="<?php echo TXT_REMOVE; ?> <?php echo TXT_ALL; ?> &gt;&gt;" ONCLICK="opt.transferAllRight()" type="button">
			</td>
			<td>
			<select name="list2" multiple="multiple" size="10" onDblClick="opt.transferLeft()">
			<?php
				$request3=mysql_query("SELECT id,name FROM $name_table_subnet ORDER BY name ASC") or die ("ERROR!");

				while($tmp_request3=mysql_fetch_array($request3))
				{
					echo "<option value=\"$tmp_request3[id]\">$tmp_request3[name]</option>";
					array_push($subnet_array,$tmp_request3['id']);
				}
			?>
			</select>
			</td>
		</tr>
		</table>
		<label><?php echo TXT_DESCRIPTION; ?></label>
		<textarea name="description" rows="10" cols="50"></textarea><br>
		<input type="hidden" name="subnet" value="">
		<input type="hidden" name="removed_subnet" value="">		
		<input type="submit" name="submit" value="<?php echo TXT_ADD; ?>"> <input type="button" value="<?php echo TXT_BACK; ?>" onClick="javascript:history.go(-1);">
	</fieldset>
</form>
 <script language="JavaScript" type="text/javascript">
	 var frmvalidator = new Validator("add_vlan");
		 frmvalidator.addValidation("name","req","Please enter the name of the vlan");
		 frmvalidator.addValidation("name","maxlen=255",
"Max length for Name is 255");
		 frmvalidator.addValidation("number","req","Please enter the number of the vlan");
		 frmvalidator.addValidation("subnet","req","Please enter the subnet of the vlan");
</script>
<?php
}
}
else if ($add=="ok")
{
	$request_vlan=mysql_query("SELECT count(*) FROM $name_table_vlan WHERE number=\"$number\"") or die ("ERROR!");
	$data_vlan = mysql_fetch_array($request_vlan);

	if ($data_vlan[0] == 0)
	{
		$query=mysql_query("INSERT INTO $name_table_vlan VALUES ('',\"$number\",\"$name\",\"$description\")") 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
		{
			$vlan_id = mysql_insert_id();
			
			$subnet_value = explode (";", $_POST['subnet']);
		
			foreach ($subnet_value as $arrayvalue)
			{
				$request=mysql_query("SELECT count(*) FROM $name_table_link_subnet_vlan WHERE subnet_id=\"$arrayvalue\" and vlan_id=\"$vlan_id\"") or die ("ERROR!");
				$data = mysql_fetch_array($request);
				if ($data[0] == 0)
				{
					$query2=mysql_query("INSERT INTO $name_table_link_subnet_vlan VALUES (\"$arrayvalue\",\"$vlan_id\")") or die ("ERROR!");
				}
			}
		
			$currentdate = date('Y-m-d');
			$currenttime = date("H:i:s"); 
			
			user_log ($_SESSION['login'],$name_table_users,$name_table_users_log,"add","vlan","$name ($vlan_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 vlan '.$name.'('.$vlan_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_VLAN;
			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=vlan&action=add\">";
			echo TXT_ADD_ANOTHER_VLAN;
			echo "</option></select></form></div><br><br><a href=\"javascript:history.go(-2);\">";
			echo TXT_BACK;
			echo "</a></center>";
		}
	}
	else
	{
		echo "<center><div id=\"status\" style=\"color:red\"><img src=\"images/warning.png\" alt=\"WARNING\"><br><br>";
		echo TXT_VLAN_NUMBER_EXIST;
		echo "</div><br><a href=\"javascript:history.go(-2);\">";
		echo TXT_BACK;
		echo "</a></center>";
	}
}
?>
Return current item: OpenDataCenter Network Management System