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

	#--------------------------------------------------------------------
	# $Id: delslip.php3,v 1.13 2000/03/03 16:56:58 shevett Exp $
	#--------------------------------------------------------------------
	

	# Delete a slip.
	#
	# $sid should have the slip id.
	#

if ($f_yesno <> "No") {
	if ($f_func == "delslip") { ?>
	
	<form method="post" action="nbrowse.php3">
	<input type=hidden name=f_process value="delslip">
	<input type=hidden name=sid value="<? echo $sid ?>">
	<tr bgcolor=#BBBBBB>
	<td width=100% bgcolor=#202020 align=center>
	<table width=50% bgcolor=#bbbbbb cellspacing=2>
		<tr>
			<td colspan=2 bgcolor=#909090 align=center>
				<font color=#ffffff>
				Are you sure you want to delete<br>
				Slip ID# <b><? echo "$sid"; ?></b>
			</td>
		</tr>
		<tr>
			<td bgcolor=#90FF90 align=center width=50%>
				<input type=submit name=f_yesno value="Yes">
			</td>
			<td bgcolor=#FF9090 align=center width=50%>
				<input type=submit name=f_yesno value="No">
			</td>
		</tr>
	</table>
	</form>
	</td>
	</tr>
	
	<?
	
	} else {
	
		if ($f_process == "delslip") {
	
			# what's our parent?
			$sq = db_query("select spid from slips where sid=$sid");
			$spid = db_result($sq,0,"spid");

			# Go ahead and delete bulk data and the slip itself...
			$tossit = db_query("delete from ebulk where browref=$sid");
			$result=db_query("delete from slips where sid=$sid");
			$count = db_affected_rows($result);
			
			# We keep a lot of state information in statelist, so toss
			# out anything from there...
			$stdata = db_query("delete from statelist where sl_table='slips'  and sl_column='$sid'");

			# Update state, setting slipzoom out as well.
			$foo=db_query("update state set slipzoom=0 where uid='$curruser'");

			# don't forget those pesky followups
			$foo=db_query("delete from followups where f_sid=$sid");

			# this slip may have data in the slipver table.  Kill that too
			$foo=db_query("delete from slipver where v_id=$sid");

			# If we had a parent, recalculate the parents children...
			if ($spid) {
				RecalcSlip($spid);
				$pstring="  Parent updated.";
			}

			# This is actually going to fudge the current inmemory 'state' list, so
			# reload it so we don't get the "no slips match display" error.

			$uquery = db_query("select * from state where uid='$curruser'");
			$state = db_fetch_array($uquery);

			$lastresult[0]=0;
			$lastresult[1]="Delete complete.  $count rows affected. $pstring ";
			
		} else {
			#
			# We shouldn't have gotten here.
			#
			
			$lastresult[0]=1;
			$lastresult[1]="Unexpected condition occured! [delslip.php3]";
		}
	}
}
	
	?>
