<?

	#---------------------------------------------------------------------#
	# This source code is (c)2000 Dave Belfer-Shevett - shevett@pobox.com #
	# see http://www.stonekeep.com/license.html for licensing information #
	#---------------------------------------------------------------------#

	#----------------------------------------------------------------------
	# $Id: slips.php3,v 1.148 2000/12/01 22:55:02 shevett Exp $
	#----------------------------------------------------------------------
	
	# called from nbrowse.php3 to display the slips according to current
	# settings.

	include "./sliputils.php3";
	include "./acl.php3";

	# If we're showing status codes, this'll make things a little chattier.

	$scquery=db_query("select * from status");
	while ($row=db_fetch_array($scquery)) {
		$code = $row[flag];
		$value = $row[label];
		$scarray[$code] = $value;
	}

	#------------------------------------------------------------------------
	# time to figure out the select clause to get the slips we want.

	$wclause = GenWhere();
	$jclause = ($sys_bugtrack) ? "left join slipver on slips.sid=slipver.v_id" : "";

	if ($state[slipzoom] > 0) {
		$qstring = "select * from slips where sid=$state[slipzoom]";
	} else {
		# Are filters turned on?  If so, grab the current slip filter out of statelist.
		if ($state[filters] <> 0) {
			$fq = db_query("select sl_column from statelist where sl_login='$curruser' and sl_table='slips' and sl_flags='FILT'");
			$filtid = db_result($fq,0,0);
			$filtq = db_query("select fselect from filters where _rowid=$filtid");
			$wclause=stripslashes(db_result($filtq,0,0));
			$wclause=ereg_replace( "USERNAME", "'$curruser'", $wclause );
		}
		$oclause = (ereg('.*order.*',$wclause)) ? "" : GenOrder("slips");
		if ("$server" != "postgresql") {
			$qstring = "select * from slips $jclause $wclause $oclause";
		} else {
			if ("$jclause" == "") {
				$qstring = "select * from slips $wclause $oclause";
			} else {
				# PostgreSQL version < 7 does not do outer joins.  I *think* 7.0 does.
				# Note that if the left join changes, so does this command.
				$qstring = "select * from slips, slipver ";
				if ("$wclause" != "") {
					$qstring .= " $wclause and ";
				} else {
					$qstring .= " where ";
				}
				$qstring .=" slips.sid=slipver.v_id "
									." union "
									."select slips.*, null, null, null, null, null, null, null, null "
									."  from slips ";
				if ("$wclause" != "") {
					$qstring .= " $wclause and ";
				} else {
					$qstring .= " where ";
				}
				$qstring .= " slips.sid not in "
									."       (select slips.sid from slips, slipver ";
				if ("$wclause" != "") {
					$qstring .= " $wclause and ";
				} else {
					$qstring .= " where ";
				}
				$qstring .=" slips.sid=slipver.v_id) $oclause";
			}
		}
	}

	#-------------------------------------------------------------------------
	# cool, got it.  dump the debug if appropriate...

	if ($prefs[opt_debug]) {
		echo "<font color=\"#ffffff\">Query string is $qstring<br>prefs[opt_t_priority] is $prefs[opt_t_priority]</font><br>";
	}

	# fire off the query...

	$result = db_query("$qstring");
	LogIt("DEBUG","slips.php3","SLIPS QUERY is $qstring");
	if (db_numrows($result) == 0) {
		Message("No slips available. <br>Either table is empty or<br>current Filter is too restrictive.");
	} else {
		$nr = db_numrows($result);
		LoadColinfo();
		if (! $state[slipzoom]) {
			echo "<tr bgcolor=\"#bbbbbb\">";
			echo "<th>[$nr]$opt_simpslips</th>";
			echo "$Colheader";
			echo "</tr>";
			echo "<tr bgcolor=\"#202020\"></tr>";
		}
	}
	
	#
	# Load the current statelist up
	#
	
	$stq = db_query("select * from statelist where sl_login='$curruser' and sl_table='slips'");
	while ($std = db_fetch_array($stq)) {
		switch ($std[sl_flags]) {
			case 'M' : {
				$exp_main[$std[sl_column]] = 1;
				break;;
			}
			case 'C' : {
				$exp_children[$std[sl_column]] = 1;
				break;;
			}
			case 'F' : {
				$exp_follow[$std[sl_column]] = 1;
				break;;
			}
			case 'O' : {
				$exp_contacts[$std[sl_column]] = 1;
				break;;
			}
			case 'V' : {
				$exp_versions[$std[sl_column]] = 1;
				break;;
			}
		}
	}
			
	$ShowSlipCounter = 0;
	$ShowSlipMax = ($prefs[opt_mxslips]) ? $prefs[opt_mxslips] : $sys_numshownslips ;
	$ShowSlipAll = db_numrows($result);
	$ShowSlipBar = 0;
	$flipper		= 0;

	while ($row=db_fetch_array($result)) {
#		if($sys_enableacl) {
#			$row[spolicy] = 1;
#			$acl_is_owner = 1;
#		}
		if ($row[currtech] == "$curruser") {
			$acl_is_owner = 1;
		}

		if (!$state[slipzoom] > 0) {
			if($sys_groupstatus && !$prefs[opt_viewgroup] && $row[status] == "$sys_groupstatus") {
				continue;
			}
		}

		# Check it
		if(!ACL_CanView($row[spolicy])) {
			# Can't view this one
			continue;
		}

		#
		# Check to see if we just want parents listed
		#

		if($sys_justparents && $row[spid] != 0) {
			# Its not a top level, but this
			# doesn't happen with zoomed items.
			if (!$state[slipzoom]) {
				# Ignore it, it isn't a parent
				continue;
			}
		}
	
		#
		# Does this slip have any children?
		#
		
		$childcount=$row[num_children];
		$followcount=$row[num_follows];

		if (! $state[slipzoom]) {
			# If we've gotten to this point, then we're really going to display this
			# slip.  start counting rows.

			$ShowSlipCounter++;

			# Are we running through slips we shouldn't display?

			if ($ShowSlipCounter < $state[sbgn]) {
				continue;
			}

			# Have we reached the max we can display?
	
			if ($ShowSlipCounter > $ShowSlipMax+$state[sbgn]) {
				continue;
			}
		}

		# Figure out what the row bg color should be.
		if ($prefs[opt_pricols]) {
			$bgcol = $sys_col[$row[priority]];
		} else {
			if ($state[slipzoom]) {
				$bgcol = $sys_col[zoomborderbg];
			} else {
				$bgcol = ($flipper) ? $sys_col[flip1] : $sys_col[flip2] ;
				$flipper = (! $flipper) ;
			}
		}
 		echo "<tr valign=top>\n";
		echo "<td width=\"2%\" bgcolor=\"$bgcol\">\n";
		if ($exp_main[$row[sid]]) {
			if ($row[sid] == $state[slipzoom]) {
				echo "<a href=\"nbrowse.php3?f_expand=1&f_sid=$row[spid]&f_stflag=M&f_slipzoom=$row[spid]&f_collapse=$row[sid]\">";
				$arrowmsg = ($row[spid]==0) ? "View all slips" : "View parent Slip (slip #$row[spid])";
				echo "<img src=\"$sys_graphics/active-up.gif\" border=0 alt=\"$arrowmsg\"></a>\n";
				echo "<a href=\"nbrowse.php3?f_slipzoom=0&f_collapse=$row[sid]&f_stflag=M\">";
				echo "<img src=\"$sys_graphics/active-left.gif\" border=0 alt=\"Collapse current\"></a>\n";
			} else {
				echo "<a href=\"nbrowse.php3?f_collapse=$row[sid]&f_sid=$row[sid]&f_stflag=M\">";
				echo "<img src=\"$sys_graphics/active-down.gif\" border=0 alt=\"Collapse\"></a>\n";
			}
		} else {
			if ($row[sid] == $state[slipzoom]) {
				echo "<a href=\"nbrowse.php3?f_expand=1&f_sid=$row[spid]&f_stflag=M&f_slipzoom=$row[spid]&f_collapse=$row[sid]\">";
				echo "<img src=\"$sys_graphics/active-up.gif\" border=0 alt=\"Go to parent\"></a>\n";
			} else {
				echo "<a href=\"nbrowse.php3?f_expand=1&f_sid=$row[sid]&f_stflag=M\">";
				echo "<img src=\"$sys_graphics/active-right.gif\" border=0 alt=\"Expand\"></a>\n";
			}
		}
		echo "</td>";
#		echo "</td><td width=2% bgcolor=\"$bgcol"\">";
#		echo "<img src=\"graphics/ulbev-blue.gif\" width=10 height=10 border=0><br>";
#		echo "<img src=\"graphics/llbev-blue.gif\" width=10 height=10 border=0><br>";
#		echo "</td>\n";
		
		echo "<td width=\"8%\" nowrap bgcolor=\"$bgcol\">\n";
		echo "<font size=2><a href=\"nbrowse.php3?f_expand=1&f_sid=$row[sid]&f_stflag=M&f_slipzoom=$row[sid]\">$row[sid]</a>\n";
		if (($childcount > 0) or ($followcount > 0))  {
			echo "<br>";
			echo "<font color=\"#000000\">";
			echo "CH: $childcount, FO: $followcount";
		}
		if ($exp_main[$row[sid]]) {
			echo "<p align=right>";
			if (ACL_CheckPermission($curruser,$row[spolicy],"follow")) {
				echo "<a href=\"nbrowse.php3?sid=$row[sid]&amp;timespent=$row[timespent]&is_public=$row[is_public]&f_func=addfollow\">Add Followup</a><br>";
			}
			if (ACL_CheckPermission($curruser,$row[spolicy],"child")) {
				echo "<a href=\"nbrowse.php3?sid=$row[sid]&f_func=addchild\">Add Child</a><br>";
			}
			echo "<a href=\"nbrowse.php3?sid=$row[sid]&f_func=attachmenu\">Attachments</a><br>";
			if (ACL_CheckPermission($curruser,$row[spolicy],"modify")) {
				echo "<a href=\"nbrowse.php3?sid=$row[sid]&f_func=modslip\">Modify</a><br>";
				if ($sys_bugtrack) {
					echo "<a href=\"nbrowse.php3?sid=$row[sid]&f_func=modver\">Edit Version Info</a><br>";
				}
			}
			if(ACL_CanClose($row[spolicy])) {
				echo "<a href=\"nbrowse.php3?sid=$row[sid]&is_public=$row[is_public]&f_func=closeslip\">Close</a><br>";
			}
			if (ACL_CheckPermission($curruser,$row[spolicy],"delete")) {
				echo "<a href=\"nbrowse.php3?sid=$row[sid]&f_func=delslip\">Delete</a>";
			}
			echo "<hr>";
			echo "<a href=\"nbrowse.php3?f_func=sendmail&sid=$row[sid]\">Email...</a><br>";
			if ("$sys_showstats") {
				echo "<hr>\n";
				echo "Children Statistics:<br>\n";
				$st_codes = db_query("select * from status");
				while ($strow=db_fetch_array($st_codes)) {
					$statq = db_query("select count(*) from slips where spid=$row[sid] and status='$strow[flag]'");
					$nr = db_result($statq,0,0);
					echo "$strow[label] $nr<br>";
				}
			}
				
			echo "</p>";
		}
		echo "</font></td>\n";

		if ($exp_main[$row[sid]]) {
			?>
			<td colspan=<? echo SizeOf($cscol)?> bgcolor="<? echo $sys_col[detailbg] ?>">
			<table width="100%" cellspacing=1>
				<tr bgcolor="<? echo $sys_col[detailbg] ?>" valign=top>
					<td width="50%">
						<? 
							echo "<table border=0 cellspacing=0 width=\"100%\">";
							echo "<tr valign=top bgcolor=\"$sys_col[detailbg]\">";
							echo "<td><font color=\"$sys_col[detailfg]\">Problem</td>";
							echo "<td><font color=\"$sys_col[detailfg]\"><b>" . htmlspecialchars(stripslashes($row[problem])) . "</b>";
							echo "</td></tr>";
							if ($row[spid] > 0) {
								echo "<tr bgcolor=\"$sys_col[detailbg]\"><td><font size=2 color=\"$sys_col[detailfg]\">Child of</td>";
								echo "<td bgcolor=\"$sys_col[detailbg]\"><font size=2 color=\"$sys_col[detailfg]\">";
								$pq = db_query("select problem from slips where sid=$row[spid]");
								if (db_numrows($pq)) {
#									echo "<a href=\"nbrowse.php3?f_expand=1&f_sid=$row[sid]&f_stflag=M&f_slipzoom=1\">";
									echo "<a href=\"nbrowse.php3?f_expand=1&f_sid=$row[spid]&f_stflag=M&f_slipzoom=$row[spid]&f_collapse=$row[sid]\">$row[spid]</a> - ";
#									echo "<a href=\"nbrowse.php3?f_expand=1&f_sid=$row[spid]&f_stflag=M&f_slipzoom=1\">";
#									echo "$row[spid]</a> - ";
									$pproblem = htmlspecialchars(stripslashes(db_result($pq,0,0)));
								} else {
									$pproblem = "(Parent slip no longer in system.)";
								}
								echo "$pproblem";
								echo "</td></tr>";
							}
							echo "<tr bgcolor=\"$sys_col[detailbg]\">";
							echo "<td colspan=2><font color=\"$sys_col[detailfg]\"><hr></td>";
							echo "</tr>";
							$stval = $row[status];
							echo "<tr bgcolor=\"$sys_col[detailbg]\"><td width=\"25%\"><font color=\"$sys_col[detailfg]\">Status:</td>";
							echo "<td><font color=\"$sys_col[detailfg]\"><b>$scarray[$stval]</b>";
							if ($sys_showage) {
								$howlong = (time() - $row[l_activity]) / 60 / 60;
								if ($howlong > 24) {
									$howlong = ($howlong / 24);
									echo "<font size=2> (".sprintf("%0.0f",${howlong})." days)";
								} else {
									echo "<font size=2> (".sprintf("%0.0f",${howlong})." hours)";
								}
							}
							echo "</b></td></tr>";
							echo "<tr bgcolor=\"$sys_col[detailbg]\">";
							echo "<td><font color=\"$sys_col[detailfg]\">Priority:</td>";
							echo "<td><font color=\"$sys_col[detailfg]\"><b>$row[priority]</b><br></td>";
							echo "</tr>";
							if ($row[group] != '') {
								echo "<tr bgcolor=\"$sys_col[detailbg]\">";
								echo "<td><font color=\"$sys_col[detailfg]\">Group:</td>";
								echo "<td><font color=\"$sys_col[detailfg]<b>$row[grp]</b><br></td>";
								echo "</tr>";
							}
							echo "<tr bgcolor=\"$sys_col[detailbg]\">";
							echo "<td><font color=\"$sys_col[detailfg]\">Public?:</td>";
							echo "<td><font color=\"$sys_col[detailfg]\"><b>";
							echo ($row[is_public] == "1") ? "Yes" : "No";
							echo "</b></td>";
							echo "</tr>";
							if ($row[resource] != '') {
								echo "<tr><td>Resource:</td>";
								echo "<td><b>$row[resource]</b><br>";
							}
							echo "</table>";
							echo "</font>";
							echo "</td>";
							
							echo "<td width=\"50%\" align=right>";
							echo "<table width=\"100%\" border=0>";
							if (IsSet($sys_link)) {
								echo "<tr bgcolor=\"$sys_col[detailbg]\">";
								echo "<td colspan=2>";
								echo "$sys_linktext : ";
								echo "<a href=\"";
								echo sprintf("$sys_link",$row[sid]);
								echo "\">Go!</a>";
								echo "</td>";
								echo "</tr>";
							}
						?>
						<tr bgcolor="<? echo $sys_col[detailbg] ?>">
							<td colspan=2>
								<?
									echo "<font color=\"$sys_col[detailfg]\">";
									if ($sys_enableacl) {
										echo "Policy number: <b>";
										if ($row[spolicy]) {
											echo $row[spolicy];
											echo " (";
											echo ACL_GetPolicyName($row[spolicy]);
											echo ")</b><hr>\n";
										} else {
											echo "None.</b><hr>";
										}
									}
									echo "Assigned to: <b>$row[currtech]</b><br>";
									echo "Opened on: <b>".date("$sys_datefmt",$row[o_date])."</b>";
									echo " by <b>$row[o_tech]</b><br>";
									if ($row[status] == "$sys_closedflag") { 
										echo "Closed on: <b>".date("$sys_datefmt",$row[c_date])."</b>";
										echo " by <b>$row[c_tech]</b><br>";
									}
									if ($row[l_activity] > 0) { 
										echo "Last activity: <b>".date("$sys_datefmt",$row[l_activity])."</b>";
										echo " by <b>$row[l_tech]</b><br>";
									}
									if ($sys_schedule) {  
										echo "Schedule open date: <b>";
										echo ($row[so_date]) ? date("$sys_datefmt",$row[so_date]) : "None Specified.";
										echo "</b><br>";
										echo "Schedule close date: <b>";
										echo ($row[sc_date]) ? date("$sys_datefmt",$row[sc_date]) : "None Specified.";
										echo "</b><br>";
									}
									if ($row[timespent] > 0) { 
										echo "Time Spent: <b>$row[timespent] </b>";
										echo ($row[timespent] == '') ? "" : " <i>minutes</i>";
										echo "<br>";
									}
								?>
								</font>
							</td>
						</tr>
							
						<?
							$exttable = "slips" ;
							$extrow		=	$row[sid] ;
							include "./showext.php3";
						?>
						</table>
					</td>
				</tr>
				<tr><td colspan=2><hr></td></tr>
				<tr bgcolor="<? echo $sys_col[detailbg] ?>"#202020"></tr>
				<tr bgcolor="<? echo $sys_col[detailbg] ?>"#bbbbbb">
					<td colspan=2>
					<?
						echo "<font color=\"$sys_col[detailfg]\">";
			
						echo ereg_replace("\n","<br>",htmlspecialchars(stripslashes($row[summary]))); 
					?>
					</td>
				</tr>
				<tr><td colspan=2><hr></tr>
				<tr bgcolor="<? echo $sys_col[detailbg] ?>">
					<td colspan=2 bgcolor="<? echo $sys_col[detailbg] ?>">
						<font color="<? echo $sys_col[detailfg]?>">
						<?
							#
							# Handle children of this slip...
							#
							if ($exp_children[$row[sid]]) {
								if ("$prefs[opt_zoomignore]") {
									$wc = "";
								} else {
									$wc = "$wclause";
								}
								$connector = ("$wc") ? "and" : "where";
								$qstring ="select * from slips $wc $connector spid=$row[sid] $oclause";
								LogIt("DEBUG","slips.php3","Child query is $qstring");
								$chresult=db_query("$qstring");
								echo "<table width=\"100%\" cellpadding=1 cellspacing=1>";
								echo "<tr><td colspan=" . SizeOf($cscol) .">";
								echo "<a href=\"nbrowse.php3?f_collapse=$row[sid]&f_stflag=C&f_sid=$row[sid]\">";
								echo "<img src=\"$sys_graphics/active-down.gif\" border=0 alt=\"Collapse Children listing\">Children ($childcount)</a>";
								echo "</td></tr>";
								echo "<tr>$Colheader</tr>";
								while ($chrow=db_fetch_array($chresult)) {
									echo "<tr valign=top>";
									if ($prefs[opt_pricols]) {
										$l_bgcolor = $sys_col[$chrow[priority]];
									} else {
										$l_bgcolor = $bgcol;
									}
									echo "<td bgcolor=\"$l_bgcolor\">";
									echo "<a href=\"nbrowse.php3?f_expand=1&f_sid=$chrow[sid]&f_slipzoom=$chrow[sid]&f_stflag=C\">";
									echo "$chrow[sid]";
									echo "</a>";
									echo "</td>";
									for ($l = 0; $l < SizeOf($cscol) ; $l++) {
										echo "<td bgcolor=\"$l_bgcolor\">";
										echo "<font color=\"#000000\" size=2>";
										$z = $chrow[$cscol[$l]] ;
										if (ereg("D",$csflags[$l])) {
											$z = ($z > 0) ? date("$sys_datefmt",$z) : "";
										}
										if ($cscol[$l] == "status") {
											$z = $scarray[$z];
										}
										if ("$z") {
											echo  htmlspecialchars(stripslashes("$z"));
										} else {
											echo "&nbsp;";
										}
										echo "</td>\n";
									}
									echo "</tr>";
								}

								echo "</table>";
							} else { 
								if ($childcount > 0) {
									echo "<a href=\"nbrowse.php3?f_expand=1&f_sid=$row[sid]&f_stflag=C\">";
	
									echo "<img src=\"$sys_graphics/active-right.gif\" border=0 alt=\"Display children list\">Children ($childcount)</a><br>";
								}
							}
							# 
							# If we're doing bugtracking stuff, show that data here.
							#
							if ($sys_bugtrack) {
								$binfo = db_query("select * from slipver where v_id=$row[sid]");
								$bdata = db_fetch_array($binfo);
								$ctext = "None";
								if (db_numrows($binfo)) {
									$ctext = "Pr:<b>$bdata[v_prod]</b> ".
										"M:<b>$bdata[v_mod]</b> ".
										"Pl:<b>$bdata[v_plat]</b> ".
										"F:<b>$bdata[v_foundin]</b> ".
										"T:<b>$bdata[v_target]</b> ".
										"V:<b>$bdata[v_verify]</b> ".
										"R:<b>$bdata[v_resolve]</b>";
								}
								if ($exp_versions[$row[sid]]) {
									echo "<a href=\"nbrowse.php3?f_collapse=$row[sid]&f_stflag=V&f_sid=$row[sid]\">";
									echo "<img src=\"$sys_graphics/active-down.gif\" border=0 alt=\"Collapse Version info\">";
									echo "</a>Version information";
									echo "<table border=0 bgcolor=#bbbbbb>";
									echo "<tr bgcolor=\"#000000\">";
									echo "<th bgcolor=\"#808080\">&nbsp;</th>\n";
									echo "<th bgcolor=\"#bbbbbb\">Label</th>";
									echo "<th bgcolor=\"#bbbbbb\">Value</th>";
									echo "</tr>";
									$fbgcol = ($fflipper) ? $sys_col[flip1] : $sys_col[flip2] ;
									
									echo "<tr bgcolor=#808080><td>&nbsp;</td><td bgcolor=$sys_col[bgwhite]>Product</td><td bgcolor=$sys_col[bgwhite]>$bdata[v_prod]</td></tr>\n";
									echo "<tr bgcolor=#808080><td>&nbsp;</td><td bgcolor=$sys_col[bghigh]>Module</td><td bgcolor=$sys_col[bghigh]>$bdata[v_mod]</td></tr>\n";
									echo "<tr bgcolor=#808080><td>&nbsp;</td><td bgcolor=$sys_col[bgwhite]>Platform</td><td bgcolor=$sys_col[bgwhite]>$bdata[v_plat]</td></tr>\n";
									echo "<tr bgcolor=#808080><td>&nbsp;</td><td bgcolor=$sys_col[bghigh]>Found in</td><td bgcolor=$sys_col[bghigh]>$bdata[v_foundin]</td></tr>\n";
									echo "<tr bgcolor=#808080><td>&nbsp;</td><td bgcolor=$sys_col[bgwhite]>To be fixed in</td><td bgcolor=$sys_col[bgwhite]>$bdata[v_target]</td></tr>\n";
									echo "<tr bgcolor=#808080><td>&nbsp;</td><td bgcolor=$sys_col[bghigh]>Verified fixed in</td><td bgcolor=$sys_col[bghigh]>$bdata[v_verify]</td></tr>\n";
									echo "<tr bgcolor=#808080><td>&nbsp;</td><td bgcolor=$sys_col[bgwhite]>Resolution code</td><td bgcolor=$sys_col[bgwhite]>$bdata[v_resolve]</td></tr>\n";
									echo "</table>";
								} else {
									echo "<a href=\"nbrowse.php3?f_expand=1&f_stflag=V&f_sid=$row[sid]\">";
									echo "<img src=\"$sys_graphics/active-right.gif\" border=0 alt=\"Expand Version info\">";
									echo "</a>Version info: $ctext<br>";
								}
							}
	
							#
							# Show Contact information based on collapse status for this slip.
							#
							$cinfo = db_query("select * from contacts where tag='$row[ctag]' ");
							$cdata = db_fetch_array($cinfo);
							if (db_numrows($cinfo)) {
								$ctext = "<a href=\"nbrowse.php3?f_stflag=M&f_mdataset=contacts&f_expand=1&f_tag=$row[ctag]&f_contzoom=$row[ctag]\">$row[ctag]</a> ($cdata[name])</a>\n";
							} else {
								$ctext="None";
							}
							if ($exp_contacts[$row[sid]]) {
								echo "<a href=\"nbrowse.php3?f_collapse=$row[sid]&f_stflag=O&f_sid=$row[sid]\">";
								echo "<img src=\"$sys_graphics/active-down.gif\" border=0 alt=\"Collapse Contact info\">";
								echo "</a>Contact(s): $ctext<br>";
								echo "<table border=0 bgcolor=#bbbbbb>";
								echo "<tr><td bgcolor=#808080>&nbsp;</td><td>Company</td><td><b>$cdata[company]</b></td></tr>\n";
								echo "<tr><td bgcolor=#808080>&nbsp;</td><td>Email</td><td><b>$cdata[email]</b></td></tr>\n";
								if (! empty($row[caddlabel])) {
									$caddr = db_query("select * from addresses where tag='$row[ctag]' and label='$row[caddlabel]'");
								} else {
									$caddr = db_query("select * from addresses where tag='$row[ctag]' and main='1'");
								}
								while ($adata = db_fetch_array($caddr)) {
									echo "<tr><td bgcolor=#808080>&nbsp;</td><td>$adata[label] address:</td><td>";
									echo "$adata[address1]<br>\n";
									if ($adata[address2]) {
										echo "$adata[address2]<br>";
									}
									echo "$adata[city], $adata[state] &nbsp; $adata[pcode]";
									echo "</td></tr>";
								}
								if (Empty($row[cphonelabel])) {
									$cphones = db_query("select * from phones where tag='$row[ctag]' and main='1'");
								} else {
									$cphones = db_query("select * from phones where tag='$row[ctag]' and label='$row[cphonelabel]'");
								}
								while ($cdata = db_fetch_array($cphones)) {
									echo "<tr>";
									echo "<td bgcolor=#808080>&nbsp;</td>";
									echo "<td>$cdata[label] phone</td>";
									echo "<td><b>$cdata[number]</b></td>";
									echo "</tr>\n";
								}
								echo "</table>";
							} else {
								echo "<a href=\"nbrowse.php3?f_expand=1&f_stflag=O&f_sid=$row[sid]\">";
								echo "<img src=\"$sys_graphics/active-right.gif\" border=0 alt=\"Expand Contact info\">";
								echo "</a>Contact(s): $ctext<br>";
							}
							
							#
							# Handle followups of this slip...
							#
							if ($exp_follow[$row[sid]]) {
								$fflipper=0;
								echo "<a href=\"nbrowse.php3?f_collapse=$row[sid]&f_stflag=F&f_sid=$row[sid]\">";
								echo "<img src=\"$sys_graphics/active-down.gif\" border=0 alt=\"Collapse Followup listing\">Followups ($followcount)</a><br>";
								$foresult=db_query("select * from followups where f_sid=$row[sid] order by f_seq desc");
								echo "<table border=0>";
								echo "<tr bgcolor=\"#000000\">";
								echo "<th bgcolor=\"#808080\">&nbsp;</th>\n";
								echo "<th bgcolor=\"#bbbbbb\">Seq</th>";
								echo "<th bgcolor=\"#bbbbbb\">Tech</th>";
								echo "<th bgcolor=\"#bbbbbb\">Date</th>";
								echo "<th bgcolor=\"#bbbbbb\">Text</th>";
								echo "<th bgcolor=\"#bbbbbb\">Time</th>";
								echo "<th bgcolor=\"#bbbbbb\">Pub?</th>";
								echo "<th bgcolor=\"#bbbbbb\">UGen?</th>";

								# The followups table may have extended data.  Check it out.

								$eq = db_query("select elabel,eflags from eschema where etable='followups' and eflags like '%V%'");
								if (db_numrows($eq) > 0) {
									while ($erow=db_fetch_array($eq)) {
										echo "<th bgcolor=\"#bbbbbb\">$erow[elabel]</th>";
									}
								}
								echo "</tr>";
								while ($forow=db_fetch_array($foresult)) {
									$fbgcol = ($fflipper) ? $sys_col[flip1] : $sys_col[flip2] ;
									$fflipper = (! $fflipper) ;
									echo "<tr bgcolor=\"#000000\" valign=top>";
									echo "<td bgcolor=\"#808080\">&nbsp;</td>\n";
									echo "<td bgcolor=\"$fbgcol\">$forow[f_seq]</td>";
									echo "<td bgcolor=\"$fbgcol\">$forow[f_tech]</td>";
									echo "<td bgcolor=\"$fbgcol\">";
									echo date("$sys_datefmt",$forow[f_date]);
									echo "</td>";
									$tmptext=htmlspecialchars(stripslashes($forow[f_text]));
									$tmptext=ereg_replace("\n","<br>",$tmptext);
									echo "<td bgcolor=\"$fbgcol\">$tmptext</td>";
									echo "<td bgcolor=\"$fbgcol\">$forow[f_time]";
									echo ($forow[f_time] == '') ? "&nbsp" : " min";
									echo "</td>";
									echo "<td bgcolor=\"$fbgcol\">";
									echo ($forow[f_public]) ? "Yes" : "No";
									echo "</td>";
									echo "<td bgcolor=\"$fbgcol\">";
									echo ($forow[f_usergen]) ? "Yes" : "No";
									echo "</td>";

									# If the followups table has extended data, check, and
									# only show those columns that are flagged with a V.

									$eq = db_query("select element,esequence from eschema where etable='followups' and eflags like '%V%' order by esequence");
									if (db_numrows($eq) > 0) {
										$elname = db_result($eq,0,'element');
										$dquery=db_query("select bvalue from ebulk where btable='followups' and belement='$elname' and browref=$row[sid] and bvalue like '$forow[f_seq]:%'");
										echo "<td bgcolor=\"#bbbbbb\">";
										if (db_numrows($dquery)) {
											echo db_result($dquery,0,"ebulk.bvalue");
										}
										echo "</td>";
									}

									echo "</tr>\n";
								}
								echo "</table>";
							} else {
								if ($followcount > 0) {
									echo "<a href=\"nbrowse.php3?f_expand=1&f_sid=$row[sid]&f_stflag=F\">";
									echo "<img src=\"$sys_graphics/active-right.gif\" border=0 alt=\"Show Followup listing\">Followups ($followcount)</a><br>";
								}
							}
					
						?>
						</font>
					</td>
				</tr>
				</table>
			</td>
		<? } else {
			for ($l = 0; $l < SizeOf($cscol) ; $l++) {
				$leavealone = 0;
				echo "<td bgcolor=\"$bgcol\">";
				echo "<font color=\"#000000\" size=2>";
				$z = $row[$cscol[$l]] ;
				if (ereg("D",$csflags[$l])) {
					$z = ($z > 0) ? date("$sys_datefmt",$z) : "";
				}
				if ($cscol[$l] == "status") {
					$z = $scarray[$z];
					# should we show how old this slip is?
					if ($sys_showage) {
						$howlong = (time() - $row[o_date]) / 60 / 60;
						if ($howlong > 24) {
							$howlong = ($howlong / 24);
							$z = $z . "(O:".sprintf("%0.0f",${howlong})."d";
						} else {
							$z = $z . "(O:".sprintf("%0.0f",${howlong})."h";
						}
					}
					if ($sys_showmod && $row[l_activity] && ($row[l_activity] - $row[o_date]) > 0) {
						if($sys_showage) {
							$z = $z . " ";
						} else {
							$z = $z . "(";
						}
	
						$howlong = (time() - $row[l_activity]) / 60 / 60;
						if ($howlong > 24) {
							$howlong = ($howlong / 24);
							$z = $z . "M:".sprintf("%0.0f",${howlong})."d";
						} else {
							$z = $z . "M:".sprintf("%0.0f",${howlong})."h";
						}
					}
					if($sys_showage || ($sys_showmod && $row[l_activity] && ($row[l_activity] - $row[o_date]) > 0)) {
						$z = $z . ")";
					}

					if ($sys_boldold || $sys_boldmod) {
						if ((time() - $row[o_date]) > $sys_boldold || (time() - $row[l_activity]) > $sys_boldmod) {
							$z = "<b>" . $z . "</b>";
							$leavealone = 1;
						}
					}

				}
				if ($sys_boldcurrtech) {
					if (($cscol[$l] == "currtech") && ($curruser == $z)) {
						$z = "<b>" . $z . "</b>";
						$leavealone = 1;
					}
				}
				if ("$z" && ($leavealone != 1)) {
					echo htmlspecialchars(stripslashes("$z"));
				} else if ($leavealone == 1) {
					echo $z;
				} else {
					echo "&nbsp;";
				}
				echo "</font></td>\n";
			}
		}
		echo "</tr>\n";
		
		if ((($ShowSlipCounter == $ShowSlipMax + $state[sbgn]) || ($ShowSlipCounter == $ShowSlipAll)) && (! $ShowSlipBar)) {
			$ShowSlipBar=1;
			$ccount = SizeOf($cscol) + 2;
			$prevset = $ShowSlipCounter - (2 * $ShowSlipMax);
			echo "<tr></tr>\n";
 			echo "<tr valign=top>\n";
			echo "<td colspan=$ccount bgcolor=#cccccc align=center>";
			echo "<table width=100% bgcolor=#cccccc><tr align=top>";
			echo "<td width=33% align=left><font size=2>";
			if ($prevset < 0) { 
				$prevset = 0; 
			}
			if ($state[sbgn] > 0) {
				echo "<a href=\"nbrowse.php3?f_topslip=$prevset\">Prev ";
				echo "<img src=\"$sys_graphics/active-left.gif\" border=0 alt=\"Previous Set\"></a>";
			}
			echo "</td>";
			echo "<td width=33% align=center><font size=2>$state[sbgn] - $ShowSlipCounter displayed out of $ShowSlipAll</td>";
			$nextset = $ShowSlipCounter;
			echo "<td width=33% align=right><font size=2>";
			if ($ShowSlipCounter <> $ShowSlipAll) {
				echo "<a href=\"nbrowse.php3?f_topslip=$nextset\">";
				echo "<img src=\"$sys_graphics/active-right.gif\" border=0 alt=\"Next Set\"> Next</a> ";
			}
			echo "</td>";
			echo "</tr>";
			echo "</table></td></tr>";
			continue;
		}

}

?>
