Location: PHPKode > projects > OpenDataCenter Network Management System > include/mainview_page/link/edit.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($edit))
{
?>
<form method="post" action="index.php?include=mainview&page=link&action=edit&edit=ok" name="edit_link">
	<fieldset class="form">
		<legend><img src="images/edit.gif" alt="Edit" align="top"> <?php echo TXT_EDIT_LINK; ?></legend>
		<?php
		
		switch ($what)
		{
			case 'interface_interface':
				echo "<label><b>".TXT_BETWEEN."</b></label>";
				echo "<select name=\"link1\" onchange=\"urlredirectdiv('ajax_view.php?what=link&value='+this.value+'&link=1','link1');\">
				<option value=\"2\">".TXT_INTERFACE."</option>
				<option value=\"1\">".TXT_PORT."</option>
			</select>
			<div id=\"link1\">";			
				$request=mysql_query("SELECT slot_id FROM $name_table_interface WHERE id=$id_interface1") or die ("ERROR!");

				while($tmp_request=mysql_fetch_array($request))
				{
					$slot_id1= $tmp_request['slot_id'];
					$request2=mysql_query("SELECT device_id FROM $name_table_slot WHERE id=$slot_id1") or die ("ERROR!");
					while($tmp_request2=mysql_fetch_array($request2))
					{
						$device_id1=$tmp_request2['device_id'];
					}				
				}					
				echo "<label>".TXT_DEVICE."</label>
				<select name='device' onchange=\"urlredirectdiv('ajax_view.php?what=add_slot&device_id='+this.value+'&link=1','slot1');\"><option value=\"null\">".TXT_SELECT_DEVICE."</option>";
				$request=mysql_query("SELECT name,id FROM $name_table_device ORDER BY name ASC") or die ("ERROR!");

				while($tmp_request=mysql_fetch_array($request))
				{
					if ($tmp_request['id']==$device_id1)
					{
						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=\"slot1\">";
				echo "<label>".TXT_SLOT."</label>
				<select name='slot' onchange=\"urlredirectdiv('ajax_view.php?what=add_interface&slot_id='+this.value+'&link=1','interface1');\"><option value=\"null\">".TXT_SELECT_SLOT."</option>";
				$request=mysql_query("SELECT name,id FROM $name_table_slot WHERE device_id=$device_id1 ORDER BY id,name ASC") or die ("ERROR!");
				while($tmp_request=mysql_fetch_array($request))
				{
					if ($tmp_request['id']==$slot_id1)
					{
						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=\"interface1\">";				
				echo "<label>".TXT_INTERFACE."</label>
				<select name='interface_1' readOnly>";
				$request=mysql_query("SELECT name,id,slot_id FROM $name_table_interface WHERE slot_id=$slot_id1") or die ("ERROR!");

				while($tmp_request=mysql_fetch_array($request))
				{
					if ($tmp_request['id']==$id_interface1)
					{
						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></div></div></div><input type=\"hidden\" name=\"old_interface_1\" value=\"$id_interface1\">";	
				
				echo "<label><b>".TXT_AND."</b></label>";
				echo "<select name=\"link2\" onchange=\"urlredirectdiv('ajax_view.php?what=link&value='+this.value+'&link=2','link2');\">
				<option value=\"2\">".TXT_INTERFACE."</option>
				<option value=\"1\">".TXT_PORT."</option>
			</select>
			<div id=\"link2\">";		
				$request=mysql_query("SELECT slot_id FROM $name_table_interface WHERE id=$id_interface2") or die ("ERROR!");

				while($tmp_request=mysql_fetch_array($request))
				{
					$slot_id2= $tmp_request['slot_id'];
					$request2=mysql_query("SELECT device_id FROM $name_table_slot WHERE id=$slot_id2") or die ("ERROR!");
					while($tmp_request2=mysql_fetch_array($request2))
					{
						$device_id2=$tmp_request2['device_id'];
					}				
				}					
				echo "<label>".TXT_DEVICE."</label>
				<select name='device' onchange=\"urlredirectdiv('ajax_view.php?what=add_slot&device_id='+this.value+'&link=2','slot2');\"><option value=\"null\">".TXT_SELECT_DEVICE."</option>";
				$request=mysql_query("SELECT name,id FROM $name_table_device ORDER BY name ASC") or die ("ERROR!");

				while($tmp_request=mysql_fetch_array($request))
				{
					if ($tmp_request['id']==$device_id2)
					{
						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=\"slot2\">";
				echo "<label>".TXT_SLOT."</label>
				<select name='slot' onchange=\"urlredirectdiv('ajax_view.php?what=add_interface&interface_id='+this.value+'&link=2','interface2');\"><option value=\"null\">".TXT_SELECT_SLOT."</option>";
				$request=mysql_query("SELECT name,id FROM $name_table_slot WHERE device_id=$device_id2 ORDER BY id,name ASC") or die ("ERROR!");
				while($tmp_request=mysql_fetch_array($request))
				{
					if ($tmp_request['id']==$slot_id2)
					{
						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=\"interface2\">";				
				echo "<label>".TXT_INTERFACE."</label>
				<select name='interface_2' readOnly>";
				$request=mysql_query("SELECT name,id,slot_id FROM $name_table_interface WHERE slot_id=$slot_id2") or die ("ERROR!");

				while($tmp_request=mysql_fetch_array($request))
				{
					if ($tmp_request['id']==$id_interface2)
					{
						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></div></div></div><input type=\"hidden\" name=\"old_interface_2\" value=\"$id_interface2\"><input type=\"hidden\" name=\"what\" value=\"interface_interface\">";
			break;
			
			case 'port_interface':
				echo "<label><b>".TXT_BETWEEN."</b></label>";
				echo "<select name=\"link1\" onchange=\"urlredirectdiv('ajax_view.php?what=link&value='+this.value+'&link=1','link1');\">
				<option value=\"1\">".TXT_PORT."</option>
				<option value=\"2\">".TXT_INTERFACE."</option>
			</select>
			<div id=\"link1\">";			
				$request=mysql_query("SELECT patch_panel_id FROM $name_table_port WHERE id=$id_port") or die ("ERROR!");

				while($tmp_request=mysql_fetch_array($request))
				{
					$patch_panel_id= $tmp_request['patch_panel_id'];
					$request2=mysql_query("SELECT rack_id FROM $name_table_patch_panel WHERE id=$patch_panel_id") or die ("ERROR!");
					while($tmp_request2=mysql_fetch_array($request2))
					{
						$rack_id=$tmp_request2['rack_id'];
					}				
				}					
				echo "<label>".TXT_RACK."</label>
				<select name='rack' onchange=\"urlredirectdiv('ajax_view.php?what=add_patch_panel&rack_id='+this.value+'&link=1','patch_panel1');\"><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)
					{
						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_panel1\">";
				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','port1');\"><option value=\"null\">".TXT_SELECT_PATCH_PANEL."</option>";
				$request=mysql_query("SELECT name,id FROM $name_table_patch_panel WHERE rack_id=$rack_id ORDER BY id,name ASC") or die ("ERROR!");
				while($tmp_request=mysql_fetch_array($request))
				{
					if ($tmp_request['id']==$patch_panel_id)
					{
						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=\"port1\">";				
				echo "<label>".TXT_PORT."</label>
				<select name='port_1' readOnly>";
				$request=mysql_query("SELECT name,id,patch_panel_id FROM $name_table_port WHERE patch_panel_id=$patch_panel_id") or die ("ERROR!");

				while($tmp_request=mysql_fetch_array($request))
				{
					if ($tmp_request['id']==$id_port)
					{
						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></div></div></div><input type=\"hidden\" name=\"old_port\" value=\"$id_port\">";	
				
				echo "<label><b>".TXT_ADD."</b></label>";
				echo "<select name=\"link2\" onchange=\"urlredirectdiv('ajax_view.php?what=link&value='+this.value+'&link=2','link2');\">
				<option value=\"2\">".TXT_INTERFACE."</option>
				<option value=\"1\">".TXT_PORT."</option>
			</select>
			<div id=\"link2\">";		
				$request=mysql_query("SELECT slot_id FROM $name_table_interface WHERE id=$id_interface") or die ("ERROR!");

				while($tmp_request=mysql_fetch_array($request))
				{
					$slot_id= $tmp_request['slot_id'];
					$request2=mysql_query("SELECT device_id FROM $name_table_slot WHERE id=$slot_id") or die ("ERROR!");
					while($tmp_request2=mysql_fetch_array($request2))
					{
						$device_id=$tmp_request2['device_id'];
					}				
				}					
				echo "<label>".TXT_DEVICE."</label>
				<select name='device' onchange=\"urlredirectdiv('ajax_view.php?what=add_slot&device_id='+this.value+'&link=2','slot');\"><option value=\"null\">".TXT_SELECT_DEVICE."</option>";
				$request=mysql_query("SELECT name,id FROM $name_table_device ORDER BY name ASC") or die ("ERROR!");

				while($tmp_request=mysql_fetch_array($request))
				{
					if ($tmp_request['id']==$device_id)
					{
						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=\"slot\">";
				echo "<label>".TXT_SLOT."</label>
				<select name='slot' onchange=\"urlredirectdiv('ajax_view.php?what=add_interface&slot_id='+this.value+'&link=2','interface');\"><option value=\"null\">".TXT_SELECT_SLOT."</option>";
				$request=mysql_query("SELECT name,id FROM $name_table_slot WHERE device_id=$device_id ORDER BY id,name ASC") or die ("ERROR!");
				while($tmp_request=mysql_fetch_array($request))
				{
					if ($tmp_request['id']==$slot_id)
					{
						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=\"interface\">";				
				echo "<label>".TXT_INTERFACE."</label>
				<select name='interface_2' readOnly>";
				$request=mysql_query("SELECT name,id,slot_id FROM $name_table_interface WHERE slot_id=$slot_id") or die ("ERROR!");

				while($tmp_request=mysql_fetch_array($request))
				{
					if ($tmp_request['id']==$id_interface)
					{
						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></div></div></div><input type=\"hidden\" name=\"old_interface\" value=\"$id_interface\"><input type=\"hidden\" name=\"what\" value=\"port_interface\">";			
			break;
			
			case 'port_port':
				echo "<label><b>".TXT_BETWEEN."</b></label>";
				echo "<select name=\"link1\" onchange=\"urlredirectdiv('ajax_view.php?what=link&value='+this.value+'&link=1','link1');\">
				<option value=\"1\">".TXT_PORT."</option>
				<option value=\"2\">".TXT_INTERFACE."</option>
			</select>
			<div id=\"link1\">";			
				$request=mysql_query("SELECT patch_panel_id FROM $name_table_port WHERE id=$id_port1") or die ("ERROR!");

				while($tmp_request=mysql_fetch_array($request))
				{
					$patch_panel_id1= $tmp_request['patch_panel_id'];
					$request2=mysql_query("SELECT rack_id FROM $name_table_patch_panel WHERE id=$patch_panel_id1") or die ("ERROR!");
					while($tmp_request2=mysql_fetch_array($request2))
					{
						$rack_id1=$tmp_request2['rack_id'];
					}				
				}					
				echo "<label>".TXT_RACK."</label>
				<select name='rack' onchange=\"urlredirectdiv('ajax_view.php?what=add_patch_panel&rack_id='+this.value+'&link=1','patch_panel1');\"><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_id1)
					{
						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_panel1\">";
				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','port1');\"><option value=\"null\">".TXT_SELECT_PATCH_PANEL."</option>";
				$request=mysql_query("SELECT name,id FROM $name_table_patch_panel WHERE rack_id=$rack_id1 ORDER BY id,name ASC") or die ("ERROR!");
				while($tmp_request=mysql_fetch_array($request))
				{
					if ($tmp_request['id']==$patch_panel_id1)
					{
						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=\"port1\">";				
				echo "<label>".TXT_PORT."</label>
				<select name='port_1' readOnly>";
				$request=mysql_query("SELECT name,id,patch_panel_id FROM $name_table_port WHERE patch_panel_id=$patch_panel_id1") or die ("ERROR!");

				while($tmp_request=mysql_fetch_array($request))
				{
					if ($tmp_request['id']==$id_port1)
					{
						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></div></div></div><input type=\"hidden\" name=\"old_port_1\" value=\"$id_port1\">";	
				
				echo "<label><b>".TXT_AND."</b></label>";
				echo "<select name=\"link2\" onchange=\"urlredirectdiv('ajax_view.php?what=link&value='+this.value+'&link=2','link2');\">
				<option value=\"1\">".TXT_PORT."</option>
				<option value=\"2\">".TXT_INTERFACE."</option>
			</select>
			<div id=\"link2\">";		
				$request=mysql_query("SELECT patch_panel_id FROM $name_table_port WHERE id=$id_port2") or die ("ERROR!");

				while($tmp_request=mysql_fetch_array($request))
				{
					$patch_panel_id2= $tmp_request['patch_panel_id'];
					$request2=mysql_query("SELECT rack_id FROM $name_table_patch_panel WHERE id=$patch_panel_id2") or die ("ERROR!");
					while($tmp_request2=mysql_fetch_array($request2))
					{
						$rack_id2=$tmp_request2['rack_id'];
					}				
				}					
				echo "<label>".TXT_RACK."</label>
				<select name='rack' onchange=\"urlredirectdiv('ajax_view.php?what=add_patch_panel&rack_id='+this.value+'&link=2','patch_panel2');\"><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_id2)
					{
						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_panel2\">";
				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','port2');\"><option value=\"null\">".TXT_SELECT_PATCH_PANEL."</option>";
				$request=mysql_query("SELECT name,id FROM $name_table_patch_panel WHERE rack_id=$rack_id2 ORDER BY id,name ASC") or die ("ERROR!");
				while($tmp_request=mysql_fetch_array($request))
				{
					if ($tmp_request['id']==$patch_panel_id2)
					{
						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=\"port2\">";				
				echo "<label>".TXT_PORT."</label>
				<select name='port_2' readOnly>";
				$request=mysql_query("SELECT name,id,patch_panel_id FROM $name_table_port WHERE patch_panel_id=$patch_panel_id1") or die ("ERROR!");

				while($tmp_request=mysql_fetch_array($request))
				{
					if ($tmp_request['id']==$id_port2)
					{
						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></div></div></div><input type=\"hidden\" name=\"old_port_2\" value=\"$id_port2\"><input type=\"hidden\" name=\"what\" value=\"port_port\">";
			break;
		}
		?>
		
		<br><br><input type="submit" name="submit" value="<?php echo TXT_EDIT; ?>"> <input type="button" value="<?php echo TXT_BACK; ?>" onClick="javascript:history.go(-1);">
	</fieldset>
</form>
<?php
}
else if ($edit=="ok")
{
	if ($link1=="1" && $link2=="1")
	{
		switch ($what)
		{
			case 'port_port':
				$query=mysql_query("DELETE FROM $name_table_link_port_port WHERE port_id=$old_port_1 AND port2_id=$old_port_2") or die ("ERROR!");
			break;
			
			case 'port_interface':
				$query=mysql_query("DELETE FROM $name_table_link_port_interface WHERE port_id=$old_port AND interface_id=$old_interface") or die ("ERROR!");
			break;
			
			case 'interface_interface':
				$query=mysql_query("DELETE FROM $name_table_link_interface_interface WHERE interface_id=$old_interface_1 AND interface2_id=$old_interface_2") or die ("ERROR!");
			break;			
		}
		
		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
		{
			$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);\">";
				echo TXT_BACK;
				echo "</a></center>";
				
				switch ($what)
				{
					case 'port_port':
						$query=mysql_query("INSERT INTO $name_table_link_port_port VALUES ('$old_port_1','$old_port_2')") or die ("ERROR!");
					break;
					
					case 'port_interface':
						$query=mysql_query("INSERT INTO $name_table_link_port_interface VALUES ('$old_port','$old_interface')") or die ("ERROR!");
					break;		
					
					case 'interface_interface':
						$query=mysql_query("INSERT INTO $name_table_link_interface_interface VALUES ('$old_interface_1','$old_interface_2')") or die ("ERROR!");
					break;					
				}				
				
			}
			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,"edit","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'].' - edit 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_EDIT_LINK_BETWEEN_PORT;
					echo "</div><br><br><a href=\"javascript:history.go(-2);\">";
					echo TXT_BACK;
					echo "</a></center>";
				}
			}
		}

	}
	else if (($link1=="1" && $link2=="2"))
	{
	
		switch ($what)
		{
			case 'port_port':
				$query=mysql_query("DELETE FROM $name_table_link_port_port WHERE port_id=$old_port_1 AND port2_id=$old_port_2") or die ("ERROR!");
			break;
			
			case 'port_interface':
				$query=mysql_query("DELETE FROM $name_table_link_port_interface WHERE port_id=$old_port AND interface_id=$old_interface") or die ("ERROR!");
			break;	
			
			case 'interface_interface':
				$query=mysql_query("DELETE FROM $name_table_link_interface_interface WHERE interface_id=$old_interface_1 AND interface2_id=$old_interface_2") or die ("ERROR!");
			break;				
		}	
		
		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
		{
			$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>";
				
				switch ($what)
				{
					case 'port_port':
						$query=mysql_query("INSERT INTO $name_table_link_port_port VALUES ('$old_port_1','$old_port_2')") or die ("ERROR!");
					break;
					
					case 'port_interface':
						$query=mysql_query("INSERT INTO $name_table_link_port_interface VALUES ('$old_port','$old_interface')") or die ("ERROR!");
					break;		

					case 'interface_interface':
						$query=mysql_query("INSERT INTO $name_table_link_interface_interface VALUES ('$old_interface_1','$old_interface_2')") or die ("ERROR!");
					break;	
				}		
			}
			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,"edit","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'].' - edit 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_EDIT_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_NOW;
					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=edit\">";
					echo TXT_EDIT_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"))
	{
		switch ($what)
		{
			case 'port_port':
				$query=mysql_query("DELETE FROM $name_table_link_port_port WHERE port_id=$old_port_1 AND port2_id=$old_port_2") or die ("ERROR!");
			break;
			
			case 'port_interface':
				$query=mysql_query("DELETE FROM $name_table_link_port_interface WHERE port_id=$old_port AND interface_id=$old_interface") or die ("ERROR!");
			break;			
			
			case 'interface_interface':
				$query=mysql_query("DELETE FROM $name_table_link_interface_interface WHERE interface_id=$old_interface_1 AND interface2_id=$old_interface_2") or die ("ERROR!");
			break;				
		}	
		
		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
		{
			$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_ONE_PORT_INTERFACE_ALREADY_LINKED;
				echo "</div><br><a href=\"javascript:history.go(-2);\">";
				echo TXT_BACK;
				echo "</a></center>";
				
				switch ($what)
				{
					case 'port_port':
						$query=mysql_query("INSERT INTO $name_table_link_port_port VALUES ('$old_port_1','$old_port_2')") or die ("ERROR!");
					break;
					
					case 'port_interface':
						$query=mysql_query("INSERT INTO $name_table_link_port_interface VALUES ('$old_port','$old_interface')") or die ("ERROR!");
					break;	

					case 'interface_interface':
						$query=mysql_query("INSERT INTO $name_table_link_interface_interface VALUES ('$old_interface_1','$old_interface_2')") or die ("ERROR!");
					break;					
				}						
				
			}
			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)
				{
					$currentdate = date('Y-m-d');
					$currenttime = date("H:i:s"); 
						
					user_log ($_SESSION['login'],$name_table_users,$name_table_users_log,"edit","link","between port $port_2 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'].' - edit link between port '.$port_2.' and interface '.$interface_2);
						$syslog->SetServer($arrayvalue);
						$syslog->Send();
					}	
				
					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_EDIT_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=edit\">";
					echo TXT_EDIT_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")
	{
		switch ($what)
		{
			case 'port_port':
				$query=mysql_query("DELETE FROM $name_table_link_port_port WHERE port_id=$old_port_1 AND port2_id=$old_port_2") or die ("ERROR!");
			break;
			
			case 'port_interface':
				$query=mysql_query("DELETE FROM $name_table_link_port_interface WHERE port_id=$old_port AND interface_id=$old_interface") or die ("ERROR!");
			break;		

			case 'interface_interface':
				$query=mysql_query("DELETE FROM $name_table_link_interface_interface WHERE interface_id=$old_interface_1 AND interface2_id=$old_interface_2") or die ("ERROR!");
			break;	
		}	
		
		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
		{
			$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>";
				
				switch ($what)
				{
					case 'port_port':
						$query=mysql_query("INSERT INTO $name_table_link_port_port VALUES ('$old_port_1','$old_port_2')") or die ("ERROR!");
					break;
					
					case 'port_interface':
						$query=mysql_query("INSERT INTO $name_table_link_port_interface VALUES ('$old_port','$old_interface')") or die ("ERROR!");
					break;		

					case 'interface_interface':
						$query=mysql_query("INSERT INTO $name_table_link_interface_interface VALUES ('$old_interface_1','$old_interface_2')") or die ("ERROR!");
					break;					
				}					
			}
			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,"edit","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'].' - edit 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_EDIT_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=edit\">";
						echo TXT_EDIT_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