<?
	#---------------------------------------------------------------------#
	# This source code is (c)2000 White Pajamas, Inc                      #
	# see http://www.stonekeep.com/license.html for licensing information #
	#---------------------------------------------------------------------#

	#--------------------------------------------------------------------
	# $Id: modres.php3,v 1.29 2000/12/14 19:13:51 shevett Exp $
	#--------------------------------------------------------------------
	
	#--------------------------------------------------------------------
	# Modify a resource.  This is to be called from within the normal 
	# html structure.... it should build it's own layout within that big row.
	#--------------------------------------------------------------------

	include "./resutils.php3";
	include "./sliputils.php3";

?>

<?
	$col[bghigh]='#dddddd';
	$col[bglow]='#808080';
	$col[back]='#000000';
	
	# pull out current tag...
	
	$result = db_query("select * from resources where r_tag='$resource'");
	$currow = db_fetch_array($result);

	Function CloseRow()
	{
		echo "</tr>";
	}

	Function OpenRow()
	{
		Global $col;
		echo "<tr bgcolor=$col[bghigh] valign=top>\n";
	}

	Function CellInfo($tinfo) 
	{
		Global $col;
		echo "<td bgcolor=$col[bglow]>\n";
		echo "$tinfo\n";
		echo "</td>\n";
	}

	Function CellQuery($label,$iname,$default)
	{
		Global $col,$currow;
		echo "<td bgcolor=$col[bglow]>\n";
		echo "<i>$label</i><br>\n";
		if ($currow[$iname]) {
			$dispval = $currow[$iname];
		} else {
			$dispval = $default;
		}
		echo "<input type=text name=a_$iname value=\"$dispval\">\n";
		echo "</td>\n";
	}

?>

	<form method="post" action="nbrowse.php3">
	<input type=hidden name="f_process" value="postres">
	<input type=hidden name="a_r_qoh" value="0">
	<tr bgcolor=#BBBBCB>
	<td width=100% bgcolor=<? echo $col[back] ?>>
	<table bgcolor=<? echo $col[bghigh] ?> cellspacing=2 align=center>
	<tr>
		<td align=center colspan=2>
			<?
				if ($f_func == "addres") {
					echo "Add a new resource";
					echo "<input type=hidden name=\"f_resflag\" value=\"add\">";
				} else {
					echo "Modify Resource Tag $resource \n";
					echo "<input type=hidden name=\"a_r_tag\" value=\"$resource\">\n";
					echo "<input type=hidden name=\"f_resflag\" value=\"mod\">";
				}
			?> 
		</td>
	</tr>
	<?
		if ($f_func == "addres") { 
			OpenRow();
				CellQuery("Resource Tag","r_tag",""); 
				CellInfo("The new resource tag ID.  This identifer<br> can contain any letters or numbers,<br> but must be unique across all Resources."); 
			CloseRow();
		} else {
			echo "<input type=\"hidden\" name=\"r_tag\" value=\"$resource\">";
		}
		OpenRow();
	?>
		<td bgcolor=<? echo $col[bglow] ?>>
			<i>Parent...</i><br>
			<select name="a_r_ptag">
			<option value="0">None.
			<?
				$q = db_query("select r_tag, r_serno, r_mctag, r_model, r_desc, r_status from resources where r_multi=0 and r_tag<>'$currow[r_tag]' order by r_model");
				while ($row=db_fetch_array($q)) {
					$txt="$row[r_tag] - ($row[r_serno]) $row[r_manuf] $row[r_model] $row[r_desc]";
					$txt = substr($txt,0,30);
					$sel="";
					if ($row[r_tag] == $currow[r_ptag]) {
						$sel="selected";
					}
					echo "<option $sel value=\"$row[r_tag]\"> $txt\n";
				}
			?>
			</select>
		</td>
	<?
		CellInfo("Select the resource that will be the 'parent'<br>for this item. (In the case of<br>an Accessory, this column is ignored.)<br>");
	CloseRow();
	OpenRow();

	?>
		<td bgcolor=<? echo $col[bglow] ?>>
			<i>Status...</i><br>
			<select name="a_r_status">
			<option value="0">None.
			<?
				$q = db_query("select flag,label from resstatus order by label");
				while ($row=db_fetch_array($q)) {
					$txt="$row[label]";
					$txt = substr($txt,0,20);
					$sel="";
					if ($row[flag] == $currow[r_status]) {
						$sel="selected";
					}
					echo "<option $sel value=\"$row[flag]\"> $txt\n";
				}
			?>
			</select>
		</td>
	<?
		CellInfo("Select the status of the resource");
	CloseRow();

	OpenRow();
		CellQuery("Serial Number","r_serno","");
		CellInfo("The Serial number of the item. Note this is<br>ignored for ACCESSORIES.");
	CloseRow();

	OpenRow();
		echo "<td bgcolor=\"$col[bglow]\">\n";
		echo "<i>Accessory?</i><br>\n";
		echo "<select name=\"a_r_multi\">\n";
		$sel = ($currow[r_multi]) ? "selected" : "";
		echo "<option value=\"0\">No\n";
		echo "<option value=\"1\" $sel>Yes\n";
		echo "</select>\n";
		echo "</td>\n";
		CellInfo("Is this item an Accessory?  (IE, is it tracked <br>by quantity, not serial number)");
	CloseRow();

	OpenRow();
		CellQuery("Quantity On Hand","r_qoh","1");
		CellInfo("Number of these items on hand. Note this is<br>only applicable for ACCESSORIES. For<br>normal Resources, it is ignored.");
	CloseRow();

	OpenRow();
		CellQuery("Location","r_loc","");
		CellInfo("The location");
	CloseRow();

	OpenRow();
		echo "<td bgcolor=$col[bglow]>\n";
		ResChooseContact('r_mctag','M',"Manufacturer");
		echo "</td>";
		CellInfo("The Contact Tag for the manufacturer");
	CloseRow();

	OpenRow();
		CellQuery("Model","r_model","");
		CellInfo("The Model of the item");
	CloseRow();

	OpenRow();
		CellQuery("Description","r_desc","");
		CellInfo("Description");
	CloseRow();

	OpenRow();
		echo "<td bgcolor=$col[bglow]>\n";
		ResChooseContact('r_ctag','C',"User Contact");
		echo "</td>";
		CellInfo("Who is the Contact for this item?");
	CloseRow();

	OpenRow();
		echo "<td bgcolor=\"$col[bglow]\">\n";
		echo "<i>Class code</i><br>\n";
		echo "<select name=\"a_r_class\">\n";
		$q = db_query("select * from classes");
		while ($row=db_fetch_array($q)) {
			$sel="";
			if ($row[cl_tag] == $currow[r_class]) {
				$sel="selected";
			}
			echo "<option $sel value=\"$row[cl_tag]\"> $row[cl_label]\n";
		}
		echo "</select>\n";
		echo "</td>\n";
		CellInfo("What class does this machine belong to?");
	CloseRow();

	OpenRow();
		echo "<td bgcolor=\"$col[bglow]\">\n";
		ChooseCurrtech("Current Tech","a_r_currtech");
		echo "</td>";
		CellInfo("Who is the current tech for this item?");
	CloseRow();

	if ("$sys_res_user1") {
		OpenRow();
			CellQuery("$sys_res_user1","r_u1val","");
			CellInfo("$sys_res_user1");
		CloseRow();
	}
	if ("$sys_res_user2") {
		OpenRow();
			CellQuery("$sys_res_user2","r_u2val","");
			CellInfo("$sys_res_user2");
		CloseRow();
	}
	if ("$sys_res_user3") {
		OpenRow();
			CellQuery("$sys_res_user3","r_u3val","");
			CellInfo("$sys_res_user3");
		CloseRow();
	}
	if ("$sys_res_user4") {
		OpenRow();
			CellQuery("$sys_res_user4","r_u4val","");
			CellInfo("$sys_res_user4");
		CloseRow();
	}
	if ("$sys_res_user5") {
		OpenRow();
			CellQuery("$sys_res_user5","r_u5val","");
			CellInfo("$sys_res_user5");
		CloseRow();
	}
	?>
	
	<tr bgcolor=<?echo "$col[bghigh]";?>>
		<td colspan=4 bgcolor=<? echo "$col[bglow]"; ?>>
			<?
				$dquery=db_query("select belement,bvalue from ebulk where btable='resources' and bkeyref='$resource'");
				while ($ddata=db_fetch_array($dquery)) {
					$edata[$ddata[belement]] = $ddata[bvalue] ;
				}
				ShowExtras("resources",$edata);
			?>
		</td>
	</tr>

	<tr bgcolor=#000000>
		<td colspan=4>
	<?  
		PostBar("Post Modifications"); 
	?>
		</td>
	</tr>
	</table>
	</td>
	</tr>
