Location: PHPKode > projects > OpenDataCenter Network Management System > include/mainview_page/link/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=link&action=add&add=ok" name="add_link">
	<fieldset class="form">
		<legend><img src="images/add.gif" alt="Add" align="top"> <?php echo TXT_ADD_LINK; ?></legend>
		<label><b><?php echo TXT_BETWEEN; ?></b></label>
		<?php
		if ((isset($id_patch_panel_1)) && (isset($id_patch_panel_2)))
		{
		
		$request1=mysql_query("SELECT rack_id FROM $name_table_patch_panel WHERE id=$id_patch_panel_1") or die ("ERROR!");

		while($tmp_request1=mysql_fetch_array($request1))
		{
			$rack_id_1=$tmp_request1['rack_id'];
		}
		
		$request2=mysql_query("SELECT rack_id FROM $name_table_patch_panel WHERE id=$id_patch_panel_2") or die ("ERROR!");

		while($tmp_request2=mysql_fetch_array($request2))
		{
			$rack_id_2=$tmp_request2['rack_id'];
		}		
		
		?>
			<select name="link1" onchange="javascript:urlredirectdiv('ajax_view.php?what=link&value='+this.value+'&link=1','link1');">
				<option value="null"><?php echo TXT_SELECT_LINK; ?></option>
				<option value="1" selected><?php echo TXT_PORT; ?></option>
				<option value="2"><?php echo TXT_INTERFACE; ?></option>
			</select>
			<div id="link1">
		<?php
			echo "<label>Rack</label>
				<select name='rack' onchange=\"urlredirectdiv('ajax_view.php?what=add_patch_panel&rack_id='+this.value+'&link=1','patch_panel');\"><option value=\"null\">".TXT_SELECT_RACK."</option>";
				$request=mysql_query("SELECT name,id FROM $name_table_rack ORDER BY name ASC") or die ("ERROR!");

				while($tmp_request=mysql_fetch_array($request))
				{
					if ($tmp_request['id']==$rack_id_1)
					{
						echo "<option value=\"$tmp_request[id]\" selected>$tmp_request[name]</option>\n";
					}
					else
					{
						echo "<option value=\"$tmp_request[id]\">$tmp_request[name]</option>\n";
					}
				}
				echo "</select><div id=\"patch_panel\">";
		
			echo "<label>".TXT_PATCH_PANEL."</label>
			<select name='patch_panel' onchange=\"urlredirectdiv('ajax_view.php?what=add_port&patch_panel_id='+this.value+'&link=1','port');\"><option value=\"null\">".TXT_SELECT_PATCH_PANEL."</option>";
			$request=mysql_query("SELECT name,id FROM $name_table_patch_panel WHERE rack_id=$rack_id_1") or die ("ERROR!");

			while($tmp_request=mysql_fetch_array($request))
			{
				if ($tmp_request['id']==$id_patch_panel_1)
				{
					echo "<option value=\"$tmp_request[id]\" selected>$tmp_request[name]</option>\n";
				}
				else
				{
					echo "<option value=\"$tmp_request[id]\">$tmp_request[name]</option>\n";
				}
			}
			echo "</select><div id=\"port\">
			<label>".TXT_PORT."</label>
			<select name='port_1' readOnly>";
			$request=mysql_query("SELECT name,id FROM $name_table_port WHERE patch_panel_id=$id_patch_panel_1 ORDER BY id ASC") or die ("ERROR!");

			while($tmp_request=mysql_fetch_array($request))
			{
				echo "<option value=\"$tmp_request[id]\">$tmp_request[name]</option>\n";
			}
			echo "</select><input type=\"hidden\" name=\"link1\" value=\"1\"></div></div></div>";		
			
			?>
			<br><label><b><?php echo TXT_AND; ?></b></label>
			<select name="link2" onchange="urlredirectdiv('ajax_view.php?what=link&value='+this.value+'&link=2','link2');">
				<option value="null">Select a link</option>
				<option value="1" selected>Port</option>
				<option value="2">Interface</option>
			</select>
			<div id="link2">
		<?php
			echo "<label>".TXT_RACK."</label>
				<select name='rack' onchange=\"urlredirectdiv('ajax_view.php?what=add_patch_panel&rack_id='+this.value+'&link=2','patch_panel');\"><option value=\"null\">".TXT_SELECT_RACK."</option>";
				$request=mysql_query("SELECT name,id FROM $name_table_rack ORDER BY name ASC") or die ("ERROR!");

				while($tmp_request=mysql_fetch_array($request))
				{
					if ($tmp_request['id']==$rack_id_2)
					{
						echo "<option value=\"$tmp_request[id]\" selected>$tmp_request[name]</option>\n";
					}
					else
					{
						echo "<option value=\"$tmp_request[id]\">$tmp_request[name]</option>\n";
					}
				}
				echo "</select><div id=\"patch_panel\">";
		
			echo "<label>".TXT_PATCH_PANEL."</label>
			<select name='patch_panel' onchange=\"urlredirectdiv('ajax_view.php?what=add_port&patch_panel_id='+this.value+'&link=2','port');\"><option value=\"null\">".TXT_SELECT_PATCH_PANEL."</option>";
			$request=mysql_query("SELECT name,id FROM $name_table_patch_panel WHERE rack_id=$rack_id_2") or die ("ERROR!");

			while($tmp_request=mysql_fetch_array($request))
			{
				if ($tmp_request['id']==$id_patch_panel_2)
				{
					echo "<option value=\"$tmp_request[id]\" selected>$tmp_request[name]</option>\n";
				}
				else
				{
					echo "<option value=\"$tmp_request[id]\">$tmp_request[name]</option>\n";
				}
			}
			echo "</select><div id=\"port\">
			<label>".TXT_PORT."</label>
			<select name='port_2' readOnly>";
			$request=mysql_query("SELECT name,id FROM $name_table_port WHERE patch_panel_id=$id_patch_panel_2 ORDER BY id ASC") or die ("ERROR!");

			while($tmp_request=mysql_fetch_array($request))
			{
				echo "<option value=\"$tmp_request[id]\">$tmp_request[name]</option>\n";
			}
			echo "</select><input type=\"hidden\" name=\"link2\" value=\"1\"></div></div></div>";					
		}
		else
		{
			if (isset($id_interface))
			{
				echo "<label>".TXT_INTERFACE."</label>
				<select name='interface_1' readOnly>";
				$request=mysql_query("SELECT name,id FROM $name_table_interface WHERE id=$id_interface") or die ("ERROR!");

				while($tmp_request=mysql_fetch_array($request))
				{
					echo "<option value=\"$tmp_request[id]\" selected>$tmp_request[name]</option>\n";
				}
				echo "</select><input type=\"hidden\" name=\"link1\" value=\"2\">";
			}
			else if (isset($id_port))
			{
				echo "<label>".TXT_PORT."</label>
				<select name='port_1' readOnly>";
				$request=mysql_query("SELECT name,id FROM $name_table_port WHERE id=$id_port") or die ("ERROR!");

				while($tmp_request=mysql_fetch_array($request))
				{
					echo "<option value=\"$tmp_request[id]\" selected>$tmp_request[name]</option>\n";
				}
				echo "</select><input type=\"hidden\" name=\"link1\" value=\"1\">";		
			}
			else
			{
			?>
				<select name="link1" onchange="javascript:urlredirectdiv('ajax_view.php?what=link&value='+this.value+'&link=1','link10');">
					<option value="null"><?php echo TXT_SELECT_LINK; ?></option>
					<option value="1"><?php echo TXT_PORT; ?></option>
					<option value="2"><?php echo TXT_INTERFACE; ?></option>
				</select>
				<div id="link10"></div><br>		
			<?php
			}
		?>
		<label><b><?php echo TXT_AND; ?></b></label>
		<select name="link2" onchange="urlredirectdiv('ajax_view.php?what=link&value='+this.value+'&link=2','link20');">
			<option value="null"><?php echo TXT_SELECT_LINK; ?></option>		
			<option value="1"><?php echo TXT_PORT; ?></option>
			<option value="2"><?php echo TXT_INTERFACE; ?></option>		
		</select>		
		<div id="link20"></div>
		<?php		
		}
		?>		
		<br><br><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>
<?php
}
else if ($add=="ok")
{
	if ($link1=="1" && $link2=="1")
	{
		$requestcount=mysql_query("SELECT count(*) FROM $name_table_link_port_port WHERE (port_id=$port_1 OR port_id=$port_2) OR (port2_id=$port_1 OR port2_id=$port_2)") or die ("ERROR!");
		$count_port = mysql_fetch_array($requestcount);
		
		if ($count_port[0] > 0)
		{
			echo "<center><div id=\"status\" style=\"color:red\"><img src=\"images/warning.png\" alt=\"WARNING\"><br><br>";
			echo TXT_ONE_PORT_ALREADY_LINKED;
			echo "</div><br><a href=\"javascript:history.go(-2);\">Back</a></center>";
			
		}
		else if ($count_port[0] == 0)
		{
			$query=mysql_query("INSERT INTO $name_table_link_port_port VALUES ('$port_1','$port_2')") 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
				{
					$currentdate = date('Y-m-d');
					$currenttime = date("H:i:s"); 
						
					user_log ($_SESSION['login'],$name_table_users,$name_table_users_log,"add","link","between port $port_1 and port $port_2",$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 link between port '.$port_1.' and port '.$port_2);
						$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_LINK_BETWEEN_PORT;
					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=link&action=add\">";
					echo TXT_ADD_ANOTHER_LINK;
					echo "</option></select></form></div><br><br><a href=\"javascript:history.go(-2);\">";
					echo TXT_BACK;
					echo "</a></center>";
				}
		}

	}
	else if (($link1=="1" && $link2=="2"))
	{
		$requestcount_port_interface=mysql_query("SELECT count(*) FROM $name_table_link_port_interface WHERE port_id=$port_1 OR interface_id=$interface_2") or die ("ERROR!");
		$count_port_interface = mysql_fetch_array($requestcount_port_interface);
		
		$requestcount_port=mysql_query("SELECT count(*) FROM $name_table_link_port_port WHERE port_id=$port_1 OR port2_id=$port_1") or die ("ERROR!");
		$count_port = mysql_fetch_array($requestcount_port);
		
		$requestcount_interface=mysql_query("SELECT count(*) FROM $name_table_link_interface_interface WHERE interface_id=$interface_2 OR interface2_id=$interface_2") or die ("ERROR!");
		$count_interface = mysql_fetch_array($requestcount_interface);
		
		if (($count_port_interface[0] > 0) || ($count_port[0] > 0) || ($count_interface[0] > 0))
		{
			echo "<center><div id=\"status\" style=\"color:red\"><img src=\"images/warning.png\" alt=\"WARNING\"><br><br>";
			echo TXT_ONE_PORT_INTERFACE_ALREADY_LINKED;
			echo "</div><br><a href=\"javascript:history.go(-2);\">";
			echo TXT_BACK;
			echo "</a></center>";
		}
		else if (($count_port_interface[0] == 0) || ($count_port[0] == 0) || ($count_interface[0] == 0))
		{
			$query=mysql_query("INSERT INTO $name_table_link_port_interface VALUES ('$port_1','$interface_2')") 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
			{
					$currentdate = date('Y-m-d');
					$currenttime = date("H:i:s"); 
						
					user_log ($_SESSION['login'],$name_table_users,$name_table_users_log,"add","link","between port $port_1 and interface $interface_2",$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 link between port '.$port_1.' and interface '.$interface_2);
						$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_LINK_BETWEEN_INTERFACE_PORT;
				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=link&action=add\">";
				echo TXT_ADD_ANOTHER_LINK;
				echo "</option></select></form></div><br><br><a href=\"javascript:history.go(-2);\">";
				echo TXT_BACK;
				echo "</a></center>";
			}
		}		
	}
	else if (($link1=="2" && $link2=="1"))
	{
		$requestcount_port_interface=mysql_query("SELECT count(*) FROM $name_table_link_port_interface WHERE port_id=$port_2 OR interface_id=$interface_1") or die ("ERROR!");
		$count_port_interface = mysql_fetch_array($requestcount_port_interface);
		
		$requestcount_port=mysql_query("SELECT count(*) FROM $name_table_link_port_port WHERE port_id=$port_2 OR port2_id=$port_2") or die ("ERROR!");
		$count_port = mysql_fetch_array($requestcount_port);
		
		$requestcount_interface=mysql_query("SELECT count(*) FROM $name_table_link_interface_interface WHERE interface_id=$interface_1 OR interface2_id=$interface_1") or die ("ERROR!");
		$count_interface = mysql_fetch_array($requestcount_interface);
		
		if (($count_port_interface[0] > 0) || ($count_port[0] > 0) || ($count_interface[0] > 0))
		{
			echo "<center><div id=\"status\" style=\"color:red\"><img src=\"images/warning.png\" alt=\"WARNING\"><br><br>";
			echo TXT_SUCCESSFULLY_ADD_LINK_BETWEEN_INTERFACE_PORT;
			echo "</div><br><a href=\"javascript:history.go(-2);\">";
			echo TXT_BACK;
			echo "</a></center>";
		}
		else if (($count_port_interface[0] == 0) || ($count_port[0] == 0) || ($count_interface[0] == 0))
		{
			$query=mysql_query("INSERT INTO $name_table_link_port_interface VALUES ('$port_2','$interface_1')") 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
			{
				$currentdate = date('Y-m-d');
				$currenttime = date("H:i:s"); 
					
				user_log ($_SESSION['login'],$name_table_users,$name_table_users_log,"add","link","between port $port_2 and interface $interface_1",$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 link between port '.$port_2.' and interface '.$interface_1);
					$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_LINK_BETWEEN_INTERFACE_PORT;
				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=link&action=add\">";
				echo TXT_ADD_ANOTHER_LINK;
				echo "</option></select></form></div><br><br><a href=\"javascript:history.go(-2);\">";
				echo TXT_BACK;
				echo "</a></center>";
			}
		}		
	}
	else if ($link1=="2" && $link2=="2")
	{
		$requestcount=mysql_query("SELECT count(*) FROM $name_table_link_interface_interface WHERE (interface_id=$interface_1 OR interface_id=$interface_2) OR (interface2_id=$interface_1 OR interface2_id=$interface_2)") or die ("ERROR!");
		$count_interface = mysql_fetch_array($requestcount);
		
		if ($count_interface[0] > 0)
		{
			echo "<center><div id=\"status\" style=\"color:red\"><img src=\"images/warning.png\" alt=\"WARNING\"><br><br>";
			echo TXT_ONE_INTERFACE_ALREADY_LINKED;
			echo "</div><br><a href=\"javascript:history.go(-2);\">";
			echo TXT_BACK;
			echo "</a></center>";
			
		}
		else if ($count_interface[0] == 0)
		{
			$query=mysql_query("INSERT INTO $name_table_link_interface_interface VALUES ('$interface_1','$interface_2')") 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
				{
				$currentdate = date('Y-m-d');
				$currenttime = date("H:i:s"); 
					
				user_log ($_SESSION['login'],$name_table_users,$name_table_users_log,"add","link","between interface $interface_1 and interface $interface_2",$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 link between interface '.$interface_1.' and interface '.$interface_2);
					$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_LINK_BETWEEN_INTERFACE;
					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=link&action=add\">";
					echo TXT_ADD_ANOTHER_LINK;
					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