<?php
#    IRM - The Information Resource Manager
#    Copyright (C) 1999 Yann Ramin
#
#    This program 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.
#
#    This program 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 (in file COPYING) for more details.
#
#    You should have received a copy of the GNU General Public License
#    along with this program; if not, write to the Free Software
#    Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
#
################################################################################

include("../include/irm.inc");
require_once 'lib/Config.php';
require_once 'include/i18n.php';

AuthCheck("tech");
commonHeader(_("Computers") . " - " . _("Add Form"));
if (@$_REQUEST['add'] == 1) 
{
  PRINT "<h3>" . _("Computer Added Successfully") . "</h3>";
  PRINT "<hr noshade>";
}
	
$DB = Config::Database();

if ($withtemplate == 1) 
{
	$templID = $ID;
	
	$qID = $DB->getTextValue($ID);
	$query = "SELECT * FROM templates WHERE (ID = $qID)";
	$result = $DB->getRow($query);

  	$templname = $result["templname"];
  	$name = $result["name"];
  	$type = $result["type"];
  	$os = $result["os"];
  	$osver = $result["osver"];
  	$processor = $result["processor"];
  	$processor_speed = $result["processor_speed"];
  	$location = $result["location"];
  	$serial = $result["serial"];
  	$otherserial = $result["otherserial"];
  	$ramtype = $result["ramtype"];
  	$ram = $result["ram"];
  	$network = $result["network"];
  	$ip = $result["ip"];
  	$mac = $result["mac"];
  	$hdspace = $result["hdspace"];
  	$comments = $result["comments"];
	$contact = $result['contact'];
	$contact_num = $result['contact_num'];
  	$new_date = date("Y-m-d H:i:s");
  	$flags_server = $result["flags_server"];
	$flags_surplus = @$result["flags_surplus"];
  	$iface = $result["iface"];
}

printf(_("Use this form to add a computer from template \"%s\":"),$templname);
PRINT "<br>";
PRINT '<table width=100% border=1 noshade>
	<form method=post action="'.Config::AbsLoc('users/computers-add.php').'">
	<tr bgcolor=#CCCCCC><td colspan=2>
	<font face="Arial, Helvetica">';
$new_date = date("Y-m-d H:i:s"); 
PRINT "<strong>";
printf(_("New Computer from \"%s\""),$templname);
PRINT "</strong>";
PRINT "</font></td></tr>";
PRINT "<tr bgcolor=#DDDDDD><td><font face=\"Arial, Helvetica\"> ";
__("Name:");
PRINT "<br><input type=text name=name value=\"$name\" size=24><br>";
__("Requested IRM ID (optional):");
PRINT "<br> <input type=text name=reqID size=3></font></td><td><font face=\"Arial, Helvetica\"> ";
__("Type");
PRINT ":<br>";
Dropdown_value("dropdown_type", "type", $type);
PRINT "</font></td></tr>";
PRINT "<tr bgcolor=#DDDDDD><td><font face=\"Arial, Helvetica\">";
__("Location");
PRINT ":<br>";
Dropdown_value("dropdown_locations", "location", $location);
PRINT "</font></td><td><font face=\"Arial, Helvetica\">";
__("OS:");
PRINT "<br>";
Dropdown_value("dropdown_os", "os", $os);
PRINT "</font></td></tr>";
PRINT "<tr bgcolor=#DDDDDD><td><font face=\"Arial, Helvetica\">";
__("OS Version");
PRINT ":<br><input type=text size=5 name=osver value=\"$osver\"> </font></td>
	<td><font face=\"Arial, Helvetica\">";
__("Processor");
PRINT ":<br>";
Dropdown_value("dropdown_processor", "processor", $processor);

PRINT "</font></td></tr>";
PRINT "<tr bgcolor=#DDDDDD><td><font face=\"Arial, Helvetica\">";
__("Processor Speed");
PRINT ":<br><input type=text name=processor_speed size=4 value=\"$processor_speed\"></font></td>
	<td><font face=\"Arial, Helvetica\">";
__("Serial Number");
PRINT ":<br><input type=text name=serial size=35 value=\"$serial\"></font> </td></tr>";
PRINT "<tr bgcolor=#DDDDDD><td><font face=\"Arial, Helvetica\">";
__("Other Serial Number");
PRINT ":<br><input type=text size=25 name=otherserial value=\"$otherserial\"></font></td>
	<td><font face=\"Arial, Helvetica\">";
__("Hard Drive Space (in gigabytes)");
PRINT ":<br><input type=text name=hdspace size=5 value=\"$hdspace\"></font> </td></tr>";
PRINT "<tr bgcolor=#DDDDDD><td><font face=\"Arial, Helvetica\">";
__("RAM Type");
PRINT ":<br>";
Dropdown_value("dropdown_ram", "ramtype", $ramtype);
PRINT "</font></td><td><font face=\"Arial, Helvetica\">";
__("RAM Amount (in MB)");
PRINT ":<br><input type=text name=ram value=\"$ram\" size=5></font></td></tr>";
PRINT "<tr bgcolor=#DDDDDD><td><font face=\"Arial, Helvetica\">";
__("Network Card Brand/Type");
PRINT ":<br>";
Dropdown_value("dropdown_network", "network", $network);
PRINT "</font></td><td><font face=\"Arial, Helvetica\">";
__("IP Address");
PRINT ":<br> <input type=text name=ip value=\"$ip\" size=16></font> </td></tr>";
PRINT "<tr bgcolor=#DDDDDD><td><font face=\"Arial, Helvetica\">";
__("MAC/Network Address");
PRINT ":<br><input type=text name=mac value=\"$mac\"></font> </td><td>";
__("Comments");
PRINT ":<br><textarea cols=20 rows=5 name=comments wrap=soft>$comments</textarea></font></td></tr>";
PRINT "<tr bgcolor=#DDDDDD><td><font face=\"Arial, Helvetica\">";
__("Contact Person");
PRINT ":<br><input type=text name=contact size=20 value=\"$contact\"></font></td><td><font face=\"Arial, Helvetica\">";
__("Contact Number");
PRINT ":<br><input type=text name=contact_num value=\"$contact_num\"></font></td></tr>";
PRINT "<tr bgcolor=#DDDDDD><td colspan=2><font face=\"Arial, Helvetica\"> ";
__("Network Interface: ");
Dropdown_value("dropdown_iface", "iface", $iface);
PRINT "<br><input type=checkbox name=iface_do value=yes checked> ";
__("Add a port of this type.");
PRINT "</td></tr>"; 		
PRINT "<tr bgcolor=#DDDDDD><td colspan=2><font face=\"Arial, Helvetica\"> ";
__("Flags");
PRINT ":<br>";

  if ($flags_server == 1) {
  	PRINT "<input type=checkbox name=flags_server value=yes checked>";
  } else {
  	PRINT "<input type=checkbox name=flags_server value=yes>";
  }

  PRINT " " . _("Server (constant running)") . "</font></td></tr>";

  PRINT "<tr bgcolor=#DDDDDD><td colspan=2><font face=\"Arial, Helvetica\"> ";
  __("Flags");
	PRINT ":<br>";
   if ($flags_surplus == 1) {
        PRINT "<input type=checkbox name=flags_surplus value=yes checked>";
   } else {
        PRINT "<input type=checkbox name=flags_surplus value=yes>";
   }

	PRINT " " . _("Surplus") . "</font></td></tr>";
	    
PRINT "<tr bgcolor=#DDDDD0><td colspan=2 align=center><font face=\"Arial, Helvetica\">";
__("Added On: ");
PRINT "$new_date <input type=hidden name=date_mod value=\"$new_date\"></td></tr>";
PRINT "<tr bgcolor=#CCCCCC><td><input type=hidden name=templID value=$templID>
		<input type=submit value=Add></td><td>
		<input type=Reset value=Reset></form></td></tr></table>";
PRINT "<br>";
