Location: PHPKode > projects > OpenDataCenter Network Management System > include/mainview_page/model/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=model&action=add&add=ok" name="add_model">
	<fieldset class="form">
		<legend><img src="images/add.gif" alt="Add" align="top"> <?php echo TXT_ADD; ?> <?php echo TXT_MODEL; ?></legend>
		<label><?php echo TXT_NAME; ?></label>
		<input type="text" name="name" size="50"><br>
		<label><?php echo TXT_MANUFACTURER; ?></label>
		<select name="manufacturer" id="manufacturer" size="1">
			<option value="null"><?php echo TXT_SELECT_MANUFACTURER; ?></option>
		<?php
		$request=mysql_query("select id,name FROM $name_table_manufacturer") or die ("ERROR!");

		while($tmp_request=mysql_fetch_array($request))
		{
			if ($manufacturer_ident == $tmp_request['id'])
			{
				echo "<option value=\"$tmp_request[id]\" SELECTED>$tmp_request[name]</option>";
			}
			else
			{
				echo "<option value=\"$tmp_request[id]\">$tmp_request[name]</option>";
			}
		}
		?>
		</select>
		<label><?php echo TXT_CATEGORY; ?></label>		
		<select name="category" id="category" size="1">
			<option value="null"><?php echo TXT_SELECT_CATEGORY; ?></option>
		<?php
		$request=mysql_query("select id,name FROM $name_table_category") or die ("ERROR!");

		while($tmp_request=mysql_fetch_array($request))
		{
			if ($category_ident == $tmp_request['id'])
			{
				echo "<option value=\"$tmp_request[id]\" SELECTED>$tmp_request[name]</option>";
			}
			else
			{
				echo "<option value=\"$tmp_request[id]\">$tmp_request[name]</option>";
			}
		}
		?>
		</select>
		<label><?php echo TXT_LAYER; ?></label>
		<select id="layer" name="layer" size="1">
			<option value="null"><?php echo TXT_SELECT_LAYER; ?></option>
			<option value="1">2</option>
			<option value="2">2+</option>
			<option value="3">3+</option>
		</select>		
		<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="null"><?php echo TXT_SELECT_HEIGHT; ?></option>		
			<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>Number of slot(s) available</label>
		<input type="text" name="number_slot" id="number_slot" size="3" maxlength="3" onKeyPress="return numbersonly(this, event)"> <input type="button" value="Add" onclick="javascript:urlredirectdiv('ajax_view.php?what=addslots&nb_slot='+number_slot.value,'slotdiv');document.getElementById('slotdiv').style.display='block';" id="add_slot_button">
		<div id="slotdiv" style="display:none;"></div></div><br>	
		<label><?php echo TXT_DESCRIPTION; ?></label>
		<textarea name="description" rows="10" cols="50"></textarea><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>
 <script language="JavaScript" type="text/javascript">
	 var frmvalidator = new Validator("add_model");
		 frmvalidator.addValidation("name","req","Please enter the name of the model");
		 frmvalidator.addValidation("manufacturer","dontselect=0","Please enter the manufacturer of the model");
		 frmvalidator.addValidation("category","dontselect=0","Please enter the category of the model");
		 frmvalidator.addValidation("layer","dontselect=0","Please enter the layer of the model");
		 frmvalidator.addValidation("height","dontselect=0","Please enter the height of the model");
		 frmvalidator.addValidation("number_slot","req","Please enter the number of slot(s) available on the model");
		 frmvalidator.addValidation("name","maxlen=255",
"Max length for Name is 255");
</script>
<?php
}
else if ($add=="ok")
{
  if ($height=="other")
  {
    $query=mysql_query("INSERT INTO $name_table_model VALUES ('',\"$manufacturer\", \"$category\", \"$name\",\"$layer\",\"$other_height\", \"$description\")") or die ("ERROR!");  
  }
  else
  {
    $query=mysql_query("INSERT INTO $name_table_model VALUES ('',\"$manufacturer\", \"$category\", \"$name\",\"$layer\",\"$height\", \"$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
	{
		$model_id = mysql_insert_id();
		
		for ($i=1;$i < ($number_slot+1); $i++)
		{
			$interface_density = $_POST['interface_density_'.$i];
			$interface_type = $_POST['interface_type_'.$i];
			$interface_speed = $_POST['interface_speed_'.$i];
      
      if ($interface_density == "other")
      {
        $other_interface_density = $_POST['other_interface_density_'.$i];
        if ($interface_speed == "other")
        {
          $other_interface_speed = $_POST['other_interface_speed_'.$i];
          $query2=mysql_query("INSERT INTO $name_table_model_slot VALUES ('',\"$model_id\",\"$i\", \"$other_interface_density\", \"$interface_type\",\"$other_interface_speed\")") or die ("ERROR!");
        }
        else
        {
          $query2=mysql_query("INSERT INTO $name_table_model_slot VALUES ('',\"$model_id\",\"$i\", \"$other_interface_density\", \"$interface_type\",\"$interface_speed\")") or die ("ERROR!");
        }
      }
      else
      {
        if ($interface_speed == "other")
        {
          $other_interface_speed = $_POST['other_interface_speed_'.$i];
          $query2=mysql_query("INSERT INTO $name_table_model_slot VALUES ('',\"$model_id\",\"$i\", \"$interface_density\", \"$interface_type\",\"$other_interface_speed\")") or die ("ERROR!");
        }
        else
        {
          $query2=mysql_query("INSERT INTO $name_table_model_slot VALUES ('',\"$model_id\",\"$i\", \"$interface_density\", \"$interface_type\",\"$interface_speed\")") 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","model","$name ($model_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 model '.$name.'('.$model_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_MODEL;
		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=model&action=add\">";
		echo TXT_ADD_ANOTHER_MODEL;
		echo "</option><option value=\"index.php?include=mainview&page=device&action=add&model_ident=$model_id\">";
		echo TXT_ADD_ASSOCIATED_DEVICE;
		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