<?
	# resutils.php3

	Function ShowResource($whatrow)
	{
		Global $col,$print_row_tag,$sys_graphics;
		Global $sys_res_user1, $sys_res_user2, $sys_res_user3, $sys_res_user4, $sys_res_user5;
		Global $exp_accessories, $state, $sys_col, $exp_slips, $sys_datefmt;
		echo "<tr valign=top>";
		echo "<td bgcolor=\"$sys_col[bgwhite]\" rowspan=3>";
		if ($state[resset]=="acc")  {
			echo "<font size=2><a href=\"nbrowse.php3?f_resazoom=0\">";
		} else {
			echo "<font size=2><a href=\"nbrowse.php3?f_resrzoom=0\">";
		}
		echo "<img src=\"$sys_graphics/active-left.gif\" border=0></a>\n";
		echo "<p align=right>";
		echo "<a href=\"nbrowse.php3?resource=$print_row_tag&f_func=addacc\">Accessories</a><br>";
		echo "<a href=\"nbrowse.php3?resource=$print_row_tag&f_func=modres\">Modify</a><br>";
		echo "<a href=\"nbrowse.php3?resource=$print_row_tag&f_func=delres\">Delete</a><br>";
		echo "</p>";
		echo "</td>";
		echo "<td valign=top>";
		echo "<table>";
		echo "<tr><td><table bgcolor=\"$sys_col[bgmed]\">";
		echo "<tr><td>Tag:</td><td><b>$whatrow[r_tag]</b></td></tr>";
		echo "<tr><td>Parent:</td><td><b>" . CheckEmpty($whatrow[r_ptag], "No parent") . "</td></tr>";
		echo "<tr><td>Serial Number:</td><td><b>$whatrow[r_serno]</td></tr>";
		echo "<tr><td>Model:</td><td><b>$whatrow[r_model]</td></tr>";
		$cq = db_query("select cl_tag,cl_label from classes where cl_tag='$whatrow[r_class]'");
		if (db_numrows($cq)) {
			$cinfo = db_fetch_array($cq);
			echo "<tr><td>Class:</td><td><b>$cinfo[cl_label]</td></tr>";
		}
		echo "<tr><td>Location:</td><td><b>$whatrow[r_loc]</td></tr>";
		echo "<tr><td>Quantity On Hand:</td><td><b>$whatrow[r_qoh]</td></tr>";
		echo "<tr><td>Description:</td><td><b>$whatrow[r_desc]</td></tr>";
		$cq = db_query("select flag,label from resstatus where flag='$whatrow[r_status]'");
		if (db_numrows($cq)) {
			$cinfo = db_fetch_array($cq);
			echo "<tr><td>Status:</td><td><b>";
			echo "$cinfo[label]";
			echo "</td></tr>";
		}
		echo "</table></td>";
		echo "<td valign=top><table bgcolor=\"$sys_col[bgmed]\">";
		echo "<tr valign=top><td>Manufacturer<br>";
		echo "<b><a href=\"nbrowse.php3?f_stflag=M&f_mdataset=contacts&f_expand=1&f_tag=$whatrow[r_mctag]&f_contzoom=$whatrow[r_mctag]\">$whatrow[r_mctag]</a></b>\n";
		echo "</td>";
		echo "<td><b>";
		$cq = db_query("select * from contacts where tag='$whatrow[r_mctag]'");
		if (db_numrows($cq)) {
			$cinfo = db_fetch_array($cq);
			echo "$cinfo[name]<br>";
			echo "$cinfo[company]<br>";
		}
		$cphones = db_query("select * from phones where tag='$whatrow[r_mctag]' and main='1'");
		while ($cdata = db_fetch_array($cphones)) {
			echo "$cdata[label] phone: $cdata[number]</b><br>\n";
		}
		echo "</td></tr>";
		echo "<tr><td colspan=2><hr></td></tr>";
		echo "<tr><td>Contact:</td><td><b>" . CheckEmpty($whatrow[r_ctag], "No contact") . "</td></tr>";
		echo "<tr><td>Current Tech:</td><td><b>" . CheckEmpty($whatrow[r_currtech], "No technician") . "</td></tr>";
		if ("$sys_res_user1") {
			echo "<tr><td>$sys_res_user1:</td><td><b>$whatrow[r_u1val]</td></tr>";
		}
		if ("$sys_res_user2") {
			echo "<tr><td>$sys_res_user2:</td><td><b>$whatrow[r_u2val]</td></tr>";
		}
		if ("$sys_res_user3") {
			echo "<tr><td>$sys_res_user3:</td><td><b>$whatrow[r_u3val]</td></tr>";
		}
		if ("$sys_res_user4") {
			echo "<tr><td>$sys_res_user4:<td></td><td><b>$whatrow[r_u4val]</td></tr>";
		}
		if ("$sys_res_user5") {
			echo "<tr><td>$sys_res_user5:<td></td><td><b>$whatrow[r_u5val]</td></tr>";
		}
		echo "</tr>";
		echo "</table></td></tr>";

		# Show extended data for this element, if it exists...
		$eq = db_query("select element,esequence,elabel from eschema where etable='resources' and eflags like '%V%' order by esequence");
		while ($er = db_fetch_array($eq)) {
			echo "<tr><td>$er[elabel]</td><td>";
			$dquery=db_query("select bvalue from ebulk where btable='resources' and belement='$er[element]' and bkeyref='$whatrow[r_tag]'");
			if (db_numrows($dquery)) {
				echo db_result($dquery,0,"bvalue");
			}
			echo "</td></tr>";
		}

		echo "<tr><td colspan=2><hr></td></tr>";
		echo "</table>";
		echo "</td></tr>";
		echo "<tr><td>";
		$blah = db_query("select * from acclist,resources where al_parent='$whatrow[r_tag]' and al_acctag = r_tag");
		$tstring = sprintf("%1.0f",db_numrows($blah));
		if ($exp_accessories[$whatrow[r_tag]]) {
			echo "<table>";
			echo "<a href=\"nbrowse.php3?f_collapse=1&f_resource=${print_row_tag}&f_stflag=A\">";
			echo "<img src=\"${sys_graphics}/active-down.gif\" border=0>Accessories ($tstring)</a></td></tr>";
			echo "<tr>";
			echo "<td bgcolor=\"#808080\">&nbsp;</td>";
			echo "<td><font size=2><b>Tag</b></font></td>";
			echo "<td><font size=2><b>Manuf</b></font></td>";
			echo "<td><font size=2><b>Model</b></font></td>";
			echo "<td><font size=2><b>Description</b></font></td>";
			$accflip=1;
			while ($accrow=db_fetch_array($blah)) {
				$accbg = ($accflip) ? $sys_col[bgwhite] : $sys_col[bghigh] ;
				$accflip = (! $accflip) ;
				echo "<tr bgcolor=\"$accbg\">";
				echo "<td bgcolor=\"#808080\">&nbsp;</td>";
				echo "<td><font size=2>$accrow[al_acctag]</td>";
				echo "<td><font size=2>$accrow[r_mctag]</td>";
				echo "<td><font size=2>$accrow[r_model]</td>";
				echo "<td><font size=2>$accrow[r_desc]</td>";
				echo "</tr>";
			}
			echo "</table>";
		} else {
			echo "<a href=\"nbrowse.php3?f_expand=1&f_resource=${print_row_tag}&f_stflag=A\">";
			echo "<img src=\"${sys_graphics}/active-right.gif\" border=0>Accessories ($tstring)</a></td></tr>";
		}
		echo "</td></tr><tr><td>";
		$sq = db_query("select sid,status,o_date,currtech,problem from slips where resource='${print_row_tag}' order by sid");
		$slipcount = db_numrows($sq);
		if ($exp_slips[$whatrow[r_tag]]) {
			echo "<table>";
			echo "<a href=\"nbrowse.php3?f_collapse=1&f_resource=${print_row_tag}&f_stflag=S\">";
			echo "<img src=\"$sys_graphics/active-down.gif\" border=0>Slips ($slipcount)</a>";
			echo "<tr align=left>";
			echo "<td bgcolor=\"#808080\">&nbsp;</td>";
			echo "<td><font size=2><b>Slip</b></td>";
			echo "<td><font size=2><b>Status</b></td>";
			echo "<td><font size=2><b>Opened</b></td>";
			echo "<td><font size=2><b>Current Tech</b></td>";
			echo "<td><font size=2><b>Problem</b></td>";
			echo "</tr>\n";
			$sflipper=1;
			while ($sdata = db_fetch_array($sq)) {
				$sbgcol = ($sflipper) ? $sys_col[bgwhite] : $sys_col[bghigh] ;
				$sflipper = (! $sflipper) ;
				echo "<tr valign=top bgcolor=\"$sbgcol\">";
				echo "<td bgcolor=\"#808080\">&nbsp;</td>";
				echo "<td><font size=2>";
				echo "<a href=\"nbrowse.php3?f_mdataset=slips&f_slipzoom=$sdata[sid]&f_expand=1&f_sid=$sdata[sid]\">";
				echo "$sdata[sid]</a></td>";
				echo "<td><font size=2>$sdata[status]</td>";
				echo "<td><font size=2>".date("$sys_datefmt",$sdata[o_date])."</td>";
				echo "<td><font size=2>$sdata[currtech]&nbsp;</td>";
				echo "<td><font size=2>$sdata[problem]</td>";
				echo "</tr>\n";
			}
			#echo "</table></td></tr>";
			echo "</table>";
		} else {
			echo "<a href=\"nbrowse.php3?f_expand=1&f_resource=${print_row_tag}&f_stflag=S\">";
			echo "<img src=\"$sys_graphics/active-right.gif\" border=0>Slips ($slipcount)</a>";
		}
		echo "</td></tr>";
	}

	Function ResChooseContact($tagid,$flag,$comment) {
		Global $currow, $parentinfo, $sys_server;
		# snarfed gleefully from sliputils.php3.

		?>
			<i><? echo $comment ?></i><br>
			<select name="<? echo "a_$tagid" ?>">
			<option value="">&nbsp;
			<?
				if ("$flag" == "C") {
					# Sigh - another hack for Postgres - this should be a 	
					# a generalized function in db.php3.  some day...
					if ($sys_server == "postgresql") {
						$wclause = "where ISNULL ctype or ctype='C'";
					} else {
						$wclause = "where IsNull(ctype) or ctype='C'";
					}
				} else {
					$wclause = "where ctype='$flag'";
				}
				$orderclause = "order by name";
				$q = db_query("select tag,name,ctype from contacts $wclause $orderclause");
				if (db_numrows($q)) {
					while ($row=db_fetch_array($q)) {
						if ($row[tag] == $currow[$tagid]) {
							$sel = "selected";
						} else {
							$sel = "";
						}
						echo "<option value=\"$row[tag]\" $sel> $row[name] ($row[tag])\n";
					}
				} else {
					echo "<option value=\"\" Selected> None available";
				}
			?>
			</select>
		<?

	}

?>
