<?php 
session_start();
ob_start();
include_once("../dbconnect.php");
$get_coupondata = mysql_fetch_array(mysql_query("select * from coupons where coupon_id =".$_GET['coupon_id']));
?>
<script type="text/javascript" src="tooltip/wz_tooltip.js"></script>
<SCRIPT LANGUAGE="JavaScript">
var cal1 = new CalendarPopup();
</SCRIPT>

	<style type="text/css" media="screen,projection">
			@import url(calendar.css);
		</style>
<script src="calendar.js" type="text/javascript" language="javascript"></script>
<script language="javascript" src="ajaxcoupon.js"></script>
<script language="javascript">
function checkcoupon()
{
	if(document.getElementById('coponname').value=="")
	{
		alert("Enter Coupon Name");
		document.getElementById('coponname').focus();
		return false;
	}
	if(document.getElementById('couponamt').value=="")
	{
		alert("Enter Coupon Amount");
		document.getElementById('couponamt').focus();
		return false;
	}
	if(document.getElementById('couponminamt').value=="")
	{
		alert("Enter Coupon Minimum Order");
		document.getElementById('couponminamt').focus();
		return false;
	}
	if(document.getElementById('couponstdate').value=="")
	{
		alert("Enter Coupon Start Date");
		document.getElementById('couponstdate').focus();
		return false;
	}
	if(document.getElementById('couponenddate').value=="")
	{
		alert("Enter Coupon End Date");
		document.getElementById('couponenddate').focus();
		return false;
	}
	return true;
}
</script>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>Welcome to B'Dazzled Swim</title>
<style type="text/css">
<!--
body {
	margin-left: 0px;
	margin-top: 0px;
	margin-right: 0px;
	margin-bottom: 0px;
}
-->
</style>
<script language="javascript" src="ajaxcoupon.js"></script>
<link href="stylesheet.css" rel="stylesheet" type="text/css" />

<script language="javascript" src="ajaxvalid.js"></script>

<!--calender files-->
<SCRIPT LANGUAGE="JavaScript">
var cal1 = new CalendarPopup();
</SCRIPT>
		<style type="text/css" media="screen,projection">
			@import url(calendar.css);
		</style>
		<script src="calendar.js" type="text/javascript" language="javascript"></script>
<!---->

</head>
<body >

<table width="1003" border="0" align="center" cellpadding="0" cellspacing="0">
  <tr>
    <td><table width="100%" border="0" align="center" cellpadding="0" cellspacing="0">
      <tr>
        <td valign="top"><table width="100%" border="0" align="center" cellpadding="0" cellspacing="0">
          <tr>
            <td><?php require_once("header.php"); ?></td>
          </tr>
          <tr>
            <td>&nbsp;</td>
          </tr>
          <tr>
            <td><table width="100%" border="0" align="center" cellpadding="0" cellspacing="0">



              <tr>
                <td>&nbsp;</td>
              </tr>
              <tr>
                <td>&nbsp;</td>
              </tr>
              <tr>
                <td valign="top"><table width="100%" border="0" cellspacing="0" cellpadding="0">
<?php $coupon=mysql_fetch_array(mysql_query("select * from coupons where coupon_id=".$_GET['coupon_id']));?>
                  <tr>
                    <td width="100%" valign="top" style="padding-right:1px;"><form action="dbcoupon.php?action=update" method="post" name="addcat" id="addcat" onSubmit="return catvalid();">
                      <table width="100%" class="OuterPanel">
                        <tbody>
                          <tr>
                            <td height="25" align="left" valign="top"><h1>Discount Coupon</h1></td>
                          </tr>
                          <tr>
                            <td class="Intro"><p>Coupon codes allow you to provide customers with discounts on products  available for purchase from your store. Fill out the form below to  create a unique coupon code</p></td>
                          </tr>
                          <?php  if($_SESSION['sessionmessage']!="") { ?>
                          <tr>
                            <td align="left" valign="middle" >&nbsp;</td>
                          </tr>
                          <tr>
                            <td align="center" valign="middle"><strong>
                              <?php  echo $_SESSION['sessionmessage']?>
                              </strong>
                              <?php  unset($_SESSION['sessionmessage']);?></td>
                          </tr>
                          <?php  } ?>
                          <tr>
                            <td><div>
                              <input name="submit" type="submit" class="FormButton" value="Update &amp; Exit" />
                              <input name="CancelButton1" value="Cancel" class="FormButton" onClick="ConfirmCancel()" type="button" /></td>
                          </tr>
                          <tr>
                            <td><table width="100%" cellpadding="5" cellspacing="5" class="Panel">
                              <tbody>
                                <tr>
                                  <td height="30" colspan="2" align="left" valign="middle" style="background:url(images/sub_heasd.gif) repeat-x left; border:#93A6B4 solid 1px; border-bottom:0px; border-top:0px;"><table width="100%" border="0" cellspacing="0" cellpadding="0">
                                    <tr>
                                      <td width="25" align="center" valign="middle"></td>
                                      <td  align="left" valign="middle"><strong>Coupon Details</strong></td>
                                    </tr>
                                  </table></td>
                                </tr>
                                <tr>
                                  <td width="24%" class="FieldLabel"><span class="Required">*</span>&nbsp;<strong>Name: </strong></td>
                                  <td width="76%" class="FieldLabel"><input name="coponname" type="text" class="Field750" id="coponname" size="25"  value="<?php  echo $get_coupondata[coupon_name]?>"/></td>
                                </tr>
                                <tr>
                                  <td class="FieldLabel"><strong>*Coupon Description </strong><br />
                                    &nbsp;&nbsp;&nbsp;&nbsp;(Customer can see)</td>
                                  <td class="FieldLabel"><textarea name="coupondesc" cols="35" rows="7"><?php  echo $get_coupondata[coupon_descr]?>
                    </textarea></td>
                                </tr>
                                <tr>
                                  <td class="FieldLabel"><strong>*Discount Amount</strong></td>
                                  <td><input name="couponamount" type="text" class="Field50" id="couponamount"  size="15" value="<?php  echo $get_coupondata[coupon_amt]?>"/>
                                    <select style="width: 50px;" class="Field100" name="coupontype" id="coupontype" type="text">
                                      <option value="1" <?php  if($get_coupondata[amttype]==1)  { echo "selected"; }?>>%</option>
                                      <option value="0" <?php  if($get_coupondata[amttype]==0)  { echo "selected"; }?>>$</option>
                                    </select>
                                    <img src="images/help.gif" width="24" height="16"  onmouseover="Tip('The total amount this coupon will deduct from each item in the order. Type in a value and then choose whether it a percentage or dollar-based discount.')" onMouseOut="UnTip()" />
                                    <div id="d2" style="display: none;"/></div></td>
                                </tr>
                                <tr>
                                  <td class="FieldLabel"><strong>*Minimum Purchase</strong></td>
                                  <td class="FieldLabel"><input name="couponminamt" type="text" class="Field750" id="couponminamt" size="15" value="<?php  echo $get_coupondata[coupon_min_amt]?>" />
                                    &nbsp;$</td>
                                </tr>
                                <tr>
                                  <td class="FieldLabel"><strong>*Coupon Code</strong></td>
                                  <td align="left" valign="top"><input type="text" name="couponcode" id="couponcode" value="<?php  echo $get_coupondata[coupon_code]?>" size="15" />
                                    &nbsp;&nbsp; leave blank for an auto generated one. </td>
                                </tr>
                                <tr>
                                  <td class="FieldLabel">*<strong>Start Date</strong></td>
                                  <td class="FieldLabel"><span class="style23">
                                    <input type="text" name="couponstdate" id="couponstdate" value="<?php  $st_date = explode(' ',$get_coupondata[coupon_start_date]); echo $st_date[0]; ?>" size="15" class="calendarSelectDate"   maxlength="30" tabindex="3" />
                                    <div id="calendarDiv"></div>
                                  </span></td>
                                </tr>
                                <tr>
                                  <td class="FieldLabel"><strong>* End Date</strong></td>
                                  <td class="FieldLabel"><span class="style23">
                                    <input type="text" name="couponenddate" id="couponenddate" value="<?php  $end_date = explode(' ',$get_coupondata[coupon_end_date]); echo $end_date[0]; ?>" size="15" class="calendarSelectDate"   maxlength="30" tabindex="3" />
                                    <div id="calendarDiv"></div>
                                  </span></td>
                                </tr>
                                <tr>
                                  <td class="FieldLabel">* <strong>Number of Uses</strong></td>
                                  <td class="FieldLabel"><input name="usage" type="text" class="Field750" id="usage" size="15" value="<?php  echo $get_coupondata[notimes]?>" /></td>
                                </tr>
                              </tbody>
                            </table>
                              <table width="100%" cellpadding="5" cellspacing="5" class="Panel">
                                <tbody>
                                  <tr>
                                    <td height="30" colspan="2" align="left" valign="middle" style="background:url(images/sub_heasd.gif) repeat-x left; border:#93A6B4 solid 1px; border-bottom:0px; border-top:0px;"><table width="100%" border="0" cellspacing="0" cellpadding="0">
                                      <tr>
                                        <td width="25" align="center" valign="middle"></td>
                                        <td  align="left" valign="middle"><strong>Coupon Applies to</strong></td>
                                      </tr>
                                    </table></td>
                                  </tr>
                                  <tr>
                                    <td width="24%" class="FieldLabel">*&nbsp;<strong>Customers: </strong></td>
                                    <td width="76%"><?php  $customers=mysql_query("select user_id,Email from register order by Fname");
				$user_str = explode(',',$get_coupondata[coupon_users]);
				?>
                                      <select name="customers[]" size="5" multiple="multiple" id="customers" >
                                        <?php  while($res=mysql_fetch_array($customers)) {?>
                                        <option value="<?php  echo $res[user_id]?>" <?php  for($i=0;$i<count($user_str);$i++) { if($user_str[$i]==$res[user_id]) { echo "selected"; }}?>>
                                          <?php  echo $res[Email]?>
                                          </option>
                                        <?php  } ?>
                                      </select>
                                      &nbsp;&nbsp;&nbsp;or
                                      <input type="checkbox" name="selectall" value="selectall" />
                                      Select All </td>
                                  </tr>
                                  <tr>
                                    <td class="FieldLabel"><input type="hidden" name="coupon_id" value="<?php  echo $_GET['coupon_id']?>" /></td>
                                    <td><input name="submit2" type="submit" class="FormButton" value="Update &amp; Exit" />
                                      <input name="CancelButton2" value="Cancel" class="FormButton" onClick="ConfirmCancel()" type="button" /></td>
                                  </tr>
                                  <tr>
                                    <td class="Gap">&nbsp;</td>
                                  </tr>
                                </tbody>
                              </table></td>
                          </tr>
                        </tbody>
                      </table>
                    </form></td>
                    <td width="0%" valign="top"><!---->
                      
                      <!----></td>
                  </tr>
                </table></td>
              </tr>
              <tr>
                <td>&nbsp;</td>
              </tr>
            </table></td>
          </tr>
          <tr>
            <td>&nbsp;</td>
          </tr>

          <tr>
            <td><?php require_once("footer.php"); ?></td>
          </tr>
          <tr>
            <td height="200">&nbsp; </td>
          </tr>
        </table></td>
      </tr>
    </table></td>
  </tr>
</table>
</body>
</html>
