<?php
	/*
	** File: UPDATE_COUPON
	** Description: edit an individual coupon
	** Version: $Revision: 1.4 $
	** Created: 11/2/99
	** Author: Chris Bellew
	** Email: chris@clearink.com
	** CVS Author: $Author: leon $
	** Last Revised: $Date: 1999/12/09 23:23:24 $
	**
	** Log : $Log: UPDATE_COUPON,v $
	** Log : Revision 1.4  1999/12/09 23:23:24  leon
	** Log : Changed ActionResults use so that it's an array instead of a
	** Log : continually-growing string.  Note the little function in standard_library
	** Log : for printing out all the action results.
	** Log :
	** Log : Revision 1.3  1999/12/07 21:44:39  leon
	** Log : Small tweak.  This file needs a bit of attention.
	** Log :
	** Log : Revision 1.2  1999/11/15 19:43:17  leon
	** Log : localized coupon modules.
	** Log :
	** Log : Revision 1.1  1999/11/02 20:35:42  leon
	** Log : Cleaned up coupon code a bit.
	** Log :
	** Log : Revision 1.1  1999/11/02 18:23:05  chris
	** Log : Added support for coupons.
	** Log :
	*/

	//assume there will be a problem
	$SCREEN = "edit_coupon";
	
	
	$coupon = $ID;
	
	$DollarOff = intval($DollarOff);
	$PercentageOff = intval($PercentageOff);
	
	if( !$UserInfo["Permission"]["Administrate"] )
	{
		$ActionResults[] = L_UPDATECOUPON_DENIED;
	}
	elseif($Name == "")
	{
		$ActionResults[] = L_UPDATECOUPON_NEEDNAME;
	}
	elseif(($DollarOff == "") && ($PercentageOff == ""))
	{
		$ActionResults[] = L_UPDATECOUPON_NEEDOFF;
	}
	elseif( (($DollarOff != "") && ($PercentageOff != "")) && (($DollarOff <> "0.00") && ($PercentageOff <> "0.00")))
	{
		$ActionResults[] = L_UPDATECOUPON_NOTBOTH;
	}
	else
	{
		//everything checked out, so user can go back to admin screen
		$SCREEN = "admin_coupon";
		
		if($StartDay < 10)
		{
			$StartDay = "0" . $StartDay;
		}
		if($EndDay < 10)
		{
			$EndDay = "0" . $EndDay;
		}
		$StartDate = $StartYear . $StartMonth . $StartDay;
		$EndDate = $EndYear . $EndMonth . $EndDay;

		$Query = "UPDATE coupon ";
		$Query .= "SET Name = '" . $Name . "', DollarOff = '" . $DollarOff . "', ";
		$Query .= "PercentageOff = '" . $PercentageOff . "', MinAmountPurchased = '" . $MinAmountPurchased . "', ";
		$Query .= "StartDate = '" . $StartDate . "', EndDate = '" . $EndDate . "', NeverExpires = '" . $NeverExpires . "', Combineable = '" . $Combineable . "', DisplayPrecedence = " . $DisplayPrecedence . " ";
		$Query .= "WHERE ID = " . $ID;

		print("<!-- Query is $Query -->\n");

		if ( !($DatabaseResult = mysql_query($Query, $DatabaseLink)) )
		{
			print("<!-- " . mysql_errno() . ":  " . mysql_error() . 
				"   Query was $Query -->\n");
			$continueScript = FALSE;
		}
		else
		{
			$ActionResults[] = L_UPDATECOUPON_SUCCESS;
		}
	}

?>
