Location: PHPKode > projects > OpenDataCenter Network Management System > include/mainview_page/patch_panel/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=patch_panel&action=add&add=ok" name="add_patch_panel">
	<fieldset class="form">
		<legend><img src="images/add.gif" alt="Add" align="top"> <?php echo TXT_ADD; ?> <?php echo TXT_PATCH_PANEL; ?></legend>
		<table width="180px" cellpadding="0" cellspacing="0">
			<tr>
				<td width="50%">
				<label><?php echo TXT_FROM; ?> <?php echo TXT_RACK; ?></label>
				<select name="rack_1">
					<?php
					if (isset($rack_id))
					{
						$request=mysql_query("SELECT name,id FROM $name_table_rack WHERE id!=\"$rack_id\" ORDER BY name ASC") or die ("ERROR!");

						while($tmp_request=mysql_fetch_array($request))
						{
							echo "<option value=\"$tmp_request[id]\">$tmp_request[name]</option>\n";
						}
						
						$request2=mysql_query("SELECT name,id FROM $name_table_rack WHERE id=\"$rack_id\"") or die ("ERROR!");
						
						while($tmp_request2=mysql_fetch_array($request2))
						{
							echo "<option value=\"$tmp_request2[id]\" SELECTED>$tmp_request2[name]</option>\n";				
						}
					}
					else
					{
						$request=mysql_query("SELECT name,id FROM $name_table_rack ORDER BY name ASC") or die ("ERROR!");

						while($tmp_request=mysql_fetch_array($request))
						{
							echo "<option value=\"$tmp_request[id]\">$tmp_request[name]</option>\n";
						}
					}
					?>
				</select>
				</td>
				<td width="50%">
				<label><?php echo TXT_TO; ?> <?php echo TXT_RACK; ?></label>
				<select name="rack_2">
					<?php
					$request=mysql_query("SELECT name,id FROM $name_table_rack ORDER BY name ASC") or die ("ERROR!");

					while($tmp_request=mysql_fetch_array($request))
					{
						echo "<option value=\"$tmp_request[id]\">$tmp_request[name]</option>\n";
					}
					?>
				</select>				
				</td>
			</tr>
		</table>
		<label><?php echo TXT_PORT_DENSITY; ?></label>
		<select name="port_density" id="port_density" onchange="javascript:urlredirectdiv('ajax_view.php?what=ajaxportdensity&port_id='+this.value,'ajaxportdensity');">
			<option value="6">6 <?php echo TXT_PORTS; ?></option>
			<option value="12">12 <?php echo TXT_PORTS; ?></option>
			<option value="16">16 <?php echo TXT_PORTS; ?></option>
			<option value="24">24 <?php echo TXT_PORTS; ?></option>
			<option value="32">32 <?php echo TXT_PORTS; ?></option>
			<option value="48">48 <?php echo TXT_PORTS; ?></option>
			<option value="96">96 <?php echo TXT_PORTS; ?></option>
			<option value="other"><?php echo TXT_OTHER; ?>...</option>
		</select>
    <div id="ajaxportdensity"></div>    
		<label><?php echo TXT_PORT_START_NUMBER; ?></label>
		<input type="text" name="port_start_number" size="5" value="1" onKeyPress="return numbersonly(this, event);"><br>		
		<label><?php echo TXT_HEIGHT; ?></label>
		<select name="height" id="height" onchange="javascript:urlredirectdiv('ajax_view.php?what=ajaxheight&height_id='+this.value,'ajaxheight');">
			<option value="1">1 U</option>
			<option value="2">2 U</option>
			<option value="4">4 U</option>
			<option value="other"><?php echo TXT_OTHER; ?>...</option>      
		</select>
    <div id="ajaxheight"></div>    
		<label><?php echo TXT_NAME; ?></label>
		<input type="text" name="name" size="50"><br>
		<label><?php echo TXT_DESCRIPTION; ?></label>
		<textarea name="description" rows="10" cols="50"></textarea><br>
		<?php
		if (isset($rack_id))
		{
			echo "<input type=\"hidden\" name=\"rack_id\" value=\"$rack_id\">";
		}
		?>
		<input type="submit" name="submit" value="<?php echo TXT_ADD_CREATE_ASSOCIATED_PORTS; ?>"> <input type="button" value="Back" onClick="javascript:history.go(-1);">
	</fieldset>
</form>
 <script language="JavaScript" type="text/javascript">
	 var frmvalidator = new Validator("add_patch_panel");
		 frmvalidator.addValidation("rack_1","req","Please enter the rack 1 of the patch panel");
		 frmvalidator.addValidation("rack_2","req","Please enter the rack 2 of the patch panel");
		 frmvalidator.addValidation("port_start_number","req","Please enter the port start number of the patch panel");
		 frmvalidator.addValidation("port_density","req","Please enter the port density of the patch panel");
		 frmvalidator.addValidation("height","req","Please enter the height of the patch panel");
		 frmvalidator.addValidation("name","req","Please enter the name of the patch panel");
		 frmvalidator.addValidation("name","maxlen=255",
"Max length for Name is 255");
</script>
<?php
}
else if ($add=="ok")
{
	if ($rack_1==$rack_2)
	{
		echo "<center><div id=\"status\" style=\"color:red\"><img src=\"images/warning.png\" alt=\"WARNING\"><br><br>";
		echo TXT_SAME_RACKS_ERROR;
		echo "</div><br><a href=\"javascript:history.go(-2);\">";
		echo TXT_BACK;
		echo "</a></center>";
	}
	else
	{
		$port_start_number_2 = $port_start_number;
		
    if ($height=="other")
    {
      if ($port_density=="other")
      {
        $query_rack_1=mysql_query("INSERT INTO $name_table_patch_panel VALUES ('',\"$rack_1\",\"$other_port_density\",\"$other_height\",\"$name\",\"$description\")") or die ("ERROR!");
      }
      else
      {
        $query_rack_1=mysql_query("INSERT INTO $name_table_patch_panel VALUES ('',\"$rack_1\",\"$port_density\",\"$other_height\",\"$name\",\"$description\")") or die ("ERROR!");      
      }
    }
    else
    {
      if ($port_density=="other")
      {
        $query_rack_1=mysql_query("INSERT INTO $name_table_patch_panel VALUES ('',\"$rack_1\",\"$other_port_density\",\"$height\",\"$name\",\"$description\")") or die ("ERROR!");
      }
      else
      {
        $query_rack_1=mysql_query("INSERT INTO $name_table_patch_panel VALUES ('',\"$rack_1\",\"$port_density\",\"$height\",\"$name\",\"$description\")") or die ("ERROR!");        
      }
    }
		$patch_panel_id = mysql_insert_id();
		$port_density_counter = 1;
    
    if ($port_density=="other")
    {
  		while ($port_density_counter <= $other_port_density)
  		{
  			$query2=mysql_query("INSERT INTO $name_table_port VALUES ('',\"$patch_panel_id\",\"$port_start_number\",\"\")") or die ("ERROR!");
  			$port_density_counter++;
  			$port_start_number++;
  		}
  		
      if ($height=="other")
      {
        $query_rack_2=mysql_query("INSERT INTO $name_table_patch_panel VALUES ('',\"$rack_2\",\"$other_port_density\",\"$other_height\",\"$name\",\"$description\")") or die ("ERROR!");
      }
      else
      {
        $query_rack_2=mysql_query("INSERT INTO $name_table_patch_panel VALUES ('',\"$rack_2\",\"$other_port_density\",\"$height\",\"$name\",\"$description\")") or die ("ERROR!");
      }
      
  		$patch_panel_id2 = mysql_insert_id();
  		$port_density_counter2 = 1;
  		while ($port_density_counter2 <= $other_port_density)
  		{
  			$query2=mysql_query("INSERT INTO $name_table_port VALUES ('',\"$patch_panel_id2\",\"$port_start_number_2\",\"\")") or die ("ERROR!");
  			$port_density_counter2++;
  			$port_start_number_2++;
  		}
    }
    else
    {
      while ($port_density_counter <= $port_density)
  		{
  			$query2=mysql_query("INSERT INTO $name_table_port VALUES ('',\"$patch_panel_id\",\"$port_start_number\",\"\")") or die ("ERROR!");
  			$port_density_counter++;
  			$port_start_number++;
  		}
  		
      if ($height=="other")
      {
        $query_rack_2=mysql_query("INSERT INTO $name_table_patch_panel VALUES ('',\"$rack_2\",\"$port_density\",\"$other_height\",\"$name\",\"$description\")") or die ("ERROR!");
      }
      else
      {
        $query_rack_2=mysql_query("INSERT INTO $name_table_patch_panel VALUES ('',\"$rack_2\",\"$port_density\",\"$height\",\"$name\",\"$description\")") or die ("ERROR!");
      }
      
  		$patch_panel_id2 = mysql_insert_id();
  		$port_density_counter2 = 1;
  		while ($port_density_counter2 <= $port_density)
  		{
  			$query2=mysql_query("INSERT INTO $name_table_port VALUES ('',\"$patch_panel_id2\",\"$port_start_number_2\",\"\")") or die ("ERROR!");
  			$port_density_counter2++;
  			$port_start_number_2++;
  		}    
    }
			
		if((!$query_rack_1) && (!$query_rack_2))
		{
			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","patch panel","$patch_panel_id and $patch_panel_id2",$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 patch panel '.$patch_panel_id.' and '.$patch_panel_id2);
				$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_PATCH_PANEL;
			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=patch_panel&action=add";
			if (isset($rack_id))
			{
				echo "&rack_id=$rack_id";
			}
			echo "\">Add another patch panel</option><option value=\"index.php?include=mainview&page=link&action=add&id_patch_panel_1=$patch_panel_id&id_patch_panel_2=$patch_panel_id2\">";
			echo TXT_EDIT_LINKS_BETWEEN_PATCH_PANEL_PORTS;
			echo "</option></select></form></div><br><br><a href=\"javascript:history.go(-2);\">Back</a></center>";
		}
	}
}
?>
Return current item: OpenDataCenter Network Management System