<?
ob_start();
session_start();
 include("../include/db.inc.php"); 
   $db1=new db;
   $db1->open();
    mysql_query("SET NAMES 'utf8'");

		 // for new addition
		if(isset($_POST['Addnew_btn'])){
			$query=mysql_query("select * from t123go_voucher where voucher_name='".$_POST['txtCat']."'");
				if(mysql_num_rows($query)){
					$action=base64_encode("\t'".$_POST['txtCat']."' voucher already exists");
					header("location:add_voucher.php?action=".$action);
					}else{
					$code=substr(md5(time()),0,10);
					echo "insert into t123go_voucher(start_to,voucher_name,amount,valid_to,status,voucher_code)
					values('".$_POST['start_time']."','".$_POST['txtCat']."','".$_POST['total_price']."',
					'".$_POST['end_time']."','1','$code')";
					$sql_addqry=mysql_query("insert into t123go_voucher(start_to,voucher_name,amount,valid_to,status,voucher_code)
					values('".$_POST['start_time']."','".$_POST['txtCat']."','".$_POST['total_price']."',
					'".$_POST['end_time']."','1','$code')");
					$action=base64_encode('"'.$_POST['txtCat'].'" voucher has been added');
					header("location:add_voucher.php?action=".$action);
			}	
		}		
		
		// for edit  
			if(isset($_POST['edit_btn'])){
			$sql_qry=mysql_query("select * from t123go_voucher where voucher_name='".trim($_POST['txtCat2'])."' and vid!=".$_GET['id']);
			$category_exists=mysql_num_rows($sql_qry);		
			if($category_exists){
			header("location:add_voucher.php?id=".$_GET['id']."&action=".base64_encode("You edited voucher ' ".$_POST['txtCat2']." ' already exists"));
			}
			$sql_update="update t123go_voucher set start_to='".$_POST['start_time']."',voucher_name='".$_POST['txtCat2']."',
			amount='".$_POST['total_price']."',valid_to='".$_POST['end_time']."'
			where vid=".$_GET['id'];
			mysql_query($sql_update);		
			$action=base64_encode('"'.$_POST['txtCat2'].'" voucher has been edited');
			header("location:add_voucher.php?id=".$_GET['id']."&action=".$action);
    		}
			
			if($_GET['del']){  
		
		   $del_query=mysql_query("delete from t123go_voucher where vid=".$_GET['del']);
			
		}
			
			if($_GET['id']){
			$sql_qry1=mysql_query("select * from t123go_voucher where vid=".$_GET['id']);
			$myrec=mysql_fetch_array($sql_qry1);		
			$id_found=mysql_num_rows($sql_qry1);
			$curdat='CURDATE()';
			}
			$sql_qry2=mysql_query("select * from t123go_voucher order by voucher_name");
			$tot_found=mysql_num_rows($sql_qry2);
			
			
			
?>
 <!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>

<title>Money-Auctions Administion Console</title>
<link type="text/css" rel="stylesheet" href="<?=_BASEURLCSSNEW_?>/dhtmlgoodies_calendar.css?random=20051112" media="screen" />
<link href="<?=_BASEURL_?>/admin/index.css" rel="stylesheet" type="text/css" />
<script language="JavaScript" src="<?=_BASEURL_?>/js/common.js"></script>
<script language="javascript" src="<?=_BASEURL_?>/js/dhtmlgoodies_calendar.js?random=20060118"></script>
<link href="<?=_BASEURLCSSNEW_?>/stylesheet.css" rel="stylesheet" type="text/css">
<script language="JavaScript">
	function veiws(url){				
		window.open(url,'','width=600,height=670,top=5,left=180');		
	}
	function sortingby(){
		document.form2.submit();
	}	
</script>

<script language="JavaScript">
	function valform(){
	
	 
     if(document.addnewfrm.start_time.value=='')
	{
		 alert("Select Your Start Time");
		 document.addnewfrm.start_time.focus();
		return false;

	} 
	
	 if(document.addnewfrm.txtCat.value=='')
	{
		 alert("Enter Your Voucher Name");
		 document.addnewfrm.txtCat.focus();
		return false;

	} 
		 if(document.addnewfrm.total_price.value=='')
	{
		 alert("Enter Your Voucher Amount");
		 document.addnewfrm.total_price.focus();
		return false;

	} 
	
		 if(document.addnewfrm.combinable.value=='')
	{
		 alert("Enter Your Voucher combinable");
		 document.addnewfrm.combinable.focus();
		return false;

	} 
	
		 if(document.addnewfrm.end_time.value=='')
	{
		 alert("Enter Your Voucher end_time");
		 document.addnewfrm.end_time.focus();
		return false;

	} 
		var imgpath=document.addnewfrm.CatImage.value;
		var Img_len=imgpath.length;
		var ext=imgpath.substr(Img_len-3,3);
		ext = ext.toLowerCase()
		if(document.addnewfrm.txtCat.value.length<1){
			alert("Please enter package name");
			document.addnewfrm.txtCat.focus();
			return false;
		}
		if(document.addnewfrm.comment.value.length<1){
			alert("Please enter comment");
			document.addnewfrm.comment.focus();
			return false;
		}
		if(Img_len<1){
			alert("Please enter image path");
			document.addnewfrm.CatImage.focus();
			return false;			
		}else if(Img_len>0){
			if(ext!="jpg" && ext!="gif"){
			alert("Image must be gif or jpg");
			document.addnewfrm.CatImage.focus();
			return false;			
			}
		}
		 if(validfrm('addnewfrm','txtCat')==false){
			return false;
		}  
	}

</script>
<script language="JavaScript">
	function validfrm(frmname,ctrlname){		
		var check=existcheck(frmname,ctrlname);
		var ctrlval=eval("document."+frmname+"."+ctrlname+".value");
		if(check==false){
			alert("'"+ctrlval+"' is already exist");
			eval("document."+frmname+"."+ctrlname+".focus()");
			return false;
		}
	}
	
	
	function statusall(){
			var total=<?=$tot_found?>;
		if(document.form1.chkall.checked==true){
			for(var i=0; i<total; i++){
				eval("document.form1.st"+i+".checked=true");			
			}
		}else if(document.form1.chkall.checked==false){
			for(var i=0; i<total; i++){
				eval("document.form1.st"+i+".checked=false");			
			}		
		}	
	}		
</script>
<style type="text/css">
<!--
.style1 {color: #093A9C}
.style2 {color: #FE6905}
-->
</style>
</head>
<body bgcolor="#ffffff">
<div class="admin_wrapper">
  <div class="logo_show">
    <? include("minorlogout.php");?>
  </div>
  <div style="float:left; width:200px">
    <div class="topg_links_show">
      <? include("left.php");	?>
    </div>
    <div class="top_links_show">
      <? include("belowleft1.php");	?>
    </div>
  </div>
  <div style="float:left; width:800px">
    <div class="maximum"><br />
        <!--::::::::::::::::::::::::::::::::::::::::::::::::::::::::::header starts:::::::::::::::::::::::::::::::::::::::::::::::::::::-->
        <table width="100%" border="1" cellspacing="0" cellpadding="0" style="border-collapse:collapse; border-color:#ffffff">
          <tr>
            <td><? //include("header.php");?></td>
          </tr>
        </table>
      <!--::::::::::::::::::::::::::::::::::::::::::::::::::::::::::header ends:::::::::::::::::::::::::::::::::::::::::::::::::::::-->
        <!--::::::::::::::::::::::::::::::::::::::::::::::::::::::::::center starts:::::::::::::::::::::::::::::::::::::::::::::::::::::-->
        <div style="margin-top:5px">
          <table width="100%" border="0" cellspacing="0" cellpadding="0" height="100%" style="border-collapse:collapse; border-color:#D4D4D4">
            <tr height="417">
              <!--::::::::::::::::::::::::::::::::::::::::::::::::::::::::::left starts:::::::::::::::::::::::::::::::::::::::::::::::::::::-->
              <!--::::::::::::::::::::::::::::::::::::::::::::::::::::::::::left ends:::::::::::::::::::::::::::::::::::::::::::::::::::::-->
              <td width="81%" bgcolor="#FFFFFF" valign="top"><table width="98%" border="0" cellpadding="0" cellspacing="0" bgcolor="#FFFFFF" class="text3">
                  <tr>
                    <td align="center" valign="top"><table width="100%" border="0" cellspacing="0" cellpadding="0">
                      </table>
                        <br />
                        <table  width="100%" border="0" cellpadding="0" cellspacing="0" class="bodytxt">
                          <tr>
                            <td width="15" valign="top">&nbsp;</td>
                            <td valign="top"><br />
                                <table width="100%" border="0" cellpadding="0" cellspacing="0" class="bodytxt">
                                  <tr>
                                    <td width="33" valign="top"><img src="img/03.gif" width="33" height="23" /></td>
                                    <td background="img/bg01.gif"><table width="100%" border="0" cellspacing="0" cellpadding="0">
                                        <tr>
                                          <td width="20%"><strong>VOUCHER LIST</strong> </td>
                                          <td width="54%">&nbsp;</td>
                                          <td width="26%" align="right"><a href="add_voucher.php#new" class="link5">Add New</a> </td>
                                        </tr>
                                    </table></td
          >
                                    <td width="35"><img src="img/04.gif" width="35" height="23" /></td>
                                  </tr>
                                </table>
                              <table  width="100%" border="0" cellpadding="0" cellspacing="0" class="bodytxt">
                                  <tr>
                                    <td width="22" valign="top" background="img/tbl-left04.gif"><img src="img/tbl-left04.gif" width="22" height="13" /></td>
                                    <td valign="top" align="center"><? if($_GET['error_action']){ print "<font color='red'><strong>".base64_decode($_GET['error_action'])."</strong></font>";}else if($_GET['action']){ print "<strong>".base64_decode($_GET['action'])."</strong>";}
                if($tot_found){
             ?>
                                        <br />
                                        <form action="" method="post" enctype="multipart/form-data" name="form1">
                                          <table width="96%" border="1" cellspacing="1" cellpadding="1" style="border-collapse:collapse; border-color:#d66b6b">
                                            <tr bgcolor="#d66b6b">
                                              <td width="105" align="center" ><strong><font color="#FFFFFF">Start To</font></strong> </td>
                                              <td width="124" ><strong><font color="#FFFFFF">Voucher Name</font></strong></td>
                                              <td width="104" align="center"><strong><font color="#FFFFFF"> Amount</font></strong></td>
                                              <td width="138" align="center"><strong><font color="#FFFFFF"> Valid To</font></strong></td>
                                              <td width="43" ></td>
                                              <td width="49" height="20" align="center"><strong><font color="#FFFFFF">Delete</font></strong></td>
                                            </tr>
                                            <? $i=0;
				    while($myrow=mysql_fetch_array($sql_qry2)){
					if($i%2==0){$col='#E6E4E3';}else{$col='#FFFFFF';}
			        ?>
                                            <tr onmouseover="this.style.backgroundColor='#e1e1e1'" onmouseout="this.style.backgroundColor='#ffffff'">
                                              <td align="center" valign="top"><?=$myrow['start_to']?></td>
                                              <td ><? echo $myrow['voucher_name']?> </td>
                                              
                                              <td align="center"><?=$myrow['amount']?>
                                              </td>
                                              <td align="center"><?=$myrow['valid_to']?>
                                              </td>
                                              <td align="center" ><a href="add_voucher.php?id=<?=$myrow['vid']?>#edit" class="link5" title="Click To Edit">Edit</a></td>
                                              <td align="center"><table>
                                                  <tr>
                                                    <td><? //echo $htm->mkchkbox('d[]','del[]',0,$myrow['vid'])?></td>
                                                    <td><a href="add_voucher.php?del=<?=$myrow['vid']?>" onclick="return confirm('Are you sure to delete this Voucher ?');"><img src="../images/category/imgdelete.gif" border="0" /></a></td>
                                                  </tr>
                                              </table></td>
                                            </tr>
                                            <? $i++;}?>
                                          </table>
                                          <table width="96%" border="0" cellspacing="0" cellpadding="0">
                                            <tr bgcolor="#E6E4E3">
                                              <td align="center" bgcolor="#E6E4E3"><a href="member_voucher.php">SHOW MEMBER OF VOUCHER</a></td>
                                              <td align="center" bgcolor="#E6E4E3"><a href="member_voucher.php#new">ADD MEMBER IN VOUCHER</a></td>
                                            </tr>
                                          </table>
                                        </form>
                                      <? }else{ echo '<br><br><br><br><strong>No record found</strong><br><br><br><br>';} ?>
                                    </td>
                                    <td width="19" valign="top" background="img/tbl-right04.gif"><img src="img/tbl-right04.gif" width="19" height="9" /></td>
                                  </tr>
                                </table>
                              <table width="100%" border="0" cellpadding="0" cellspacing="0" class="bodytxt">
                                  <tr>
                                    <td width="33"><img src="img/tbl-bot01.gif" width="33" height="12" /></td>
                                    <td align="right" width="95%" background="img/tbl-bg.gif"></td>
                                    <td width="33"><img src="img/tbl-right05.gif" width="35" height="12" /></td>
                                  </tr>
                              </table></td>
                            <td width="15" valign="top">&nbsp;</td>
                          </tr>
                      </table></td>
                  </tr>
                </table>
                  <br />
                  <? 
	if($_GET['action']){ echo '<div align="center"><strong>'.base64_decode($_GET['action']).'</strong></div>';}
if(!$_GET['id'] && !$id_found){?>
                <a name="new"></a>
                  <table width="78%" border=0 cellpadding=0 cellspacing=0 align="center">
                    <tr>
                      <td><img border='0' src="border_img/circle_01.gif" width=36 height=35 alt="" /></td>
                      <td width="901" height="34" valign="top" ><table width="100%" border="0" cellspacing="0" cellpadding="0">
                          <tr>
                            <td align="center" width="11%" ><strong><font color="#003366">Add New</font></strong></td>
                            <td width="89%" background="border_img/circle_02.gif">&nbsp;</td>
                          </tr>
                      </table></td>
                      <td><img border='0' src="border_img/circle_03.gif" width=35 height=35 alt="" /></td>
                    </tr>
                    <tr>
                      <td width="36" background="border_img/circle_04.gif">&nbsp;</td>
                      <td align="left" valign="top"><form action="" method="post" enctype="multipart/form-data" name="addnewfrm" onsubmit="return valform(this)">
                          <table width="100%" border="0" cellspacing="1" cellpadding="1" bgcolor="#003366" >
                            <tr bgcolor="#E6F2FF">
                              <td height="20">Start To</td>
                              <td><input name="start_time" type="text" class="inputtext" size="40" maxlength="145" />
                                  <small>
                                  <input type="button" value="Cal" onclick="displayCalendar(document.addnewfrm.start_time,'yyyy/mm/dd hh:ii',this,true)" />
                                  </small></td>
                            </tr>
                            <tr bgcolor="#FFFFFF">
                              <td width="19%" height="20">Voucher Name</td>
                              <td width="72%"><input name="txtCat" type="text" class="inputtext" size="40" maxlength="70" /></td>
                            </tr>
                            <tr bgcolor="#E6F2FF">
                              <td height="20">Amount</td>
                              <td><input name="total_price" type="text" class="inputtext" size="40" maxlength="145" /></td>
                            </tr>
                            
                            <tr bgcolor="#FFFFFF">
                              <td height="20">Validate To</td>
                              <td><input name="end_time" type="text" class="inputtext" size="40" />
                                  <small>
                                  <input type="button" value="Cal" onclick="displayCalendar(document.addnewfrm.end_time,'yyyy/mm/dd hh:ii',this,true)" />
                                  </small></td>
                            </tr>
                            <tr bgcolor="#E6F2FF">
                              <td height="20">&nbsp;</td>
                              <td><input name="Addnew_btn" type="submit" class="inputtext" value="Save" style="padding-bottom:18px;" /></td>
                            </tr>
                          </table>
                      </form></td>
                      <td width="36" background="border_img/circle_06.gif">&nbsp;</td>
                    </tr>
                    <tr>
                      <td><img border='0' src="border_img/circle_07.gif" width=36 height=34 alt="" /></td>
                      <td height="34" background="border_img/circle_08.gif">&nbsp;</td>
                      <td><img border='0' src="border_img/circle_09.gif" width=35 height=34 alt="" /></td>
                    </tr>
                  </table>
                <? }else  if($_GET['id'] && $id_found){?>
                  <a name="edit"></a>
                  <table width="74%" border=0 cellpadding=0 cellspacing=0 align="center">
                    <tr>
                      <td><img border='0' src="border_img/circle_01.gif" width=36 height=35 alt="" /></td>
                      <td height="34" valign="top" ><table width="100%" border="0" cellspacing="0" cellpadding="0">
                          <tr>
                            <td width="14%"  align="center"><strong><font color="#003366">Edit Voucher</font></strong></td>
                            <td width="86%" background="border_img/circle_02.gif">&nbsp;</td>
                          </tr>
                      </table></td>
                      <td><img border='0' src="border_img/circle_03.gif" width=35 height=35 alt="" /></td>
                    </tr>
                    <tr>
                      <td width="36" background="border_img/circle_04.gif">&nbsp;</td>
                      <td align="left" valign="top"><form action="" method="post" enctype="multipart/form-data" name="editfrm" >
                          <table width="100%" border="0" cellspacing="1" cellpadding="1" bgcolor="#003366" >
                            <tr bgcolor="#E6F2FF">
                              <td height="20">Start To</td>
                              <td><input name="start_time" type="text" class="inputtext" size="40" maxlength="145" value="<?=$myrec['start_to']?>" /></td>
                            </tr>
                            <tr bgcolor="#FFFFFF">
                              <td width="19%" height="20">Voucher Name</td>
                              <td width="72%"><input name="txtCat2" type="text" class="inputtext" size="40" maxlength="70" value="<?=$myrec['voucher_name']?>" /></td>
                            </tr>
                           
                            <tr bgcolor="#E6F2FF">
                              <td height="20">Amount</td>
                              <td><input name="total_price" type="text" class="inputtext" size="40" maxlength="145" value="<?=$myrec['amount']?>" /></td>
                            </tr>
                            <tr bgcolor="#FFFFFF">
                              <td height="20">Valid To</td>
                              <td><input name="end_time" type="text" class="inputtext" size="40" maxlength="145" value="<?=$myrec['valid_to']?>" />
                                  <small>
                                  <input type="button" value="Cal" onclick="displayCalendar(document.editfrm.end_time,'yyyy/mm/dd hh:ii',this,true)" />
                                  </small></td>
                            </tr>
                            <tr bgcolor="#E6F2FF">
                              <td height="25">&nbsp;</td>
                              <td><input name="edit_btn" type="submit" class="inputtext" value="Save" style="padding-bottom:18px;" /></td>
                            </tr>
                          </table>
                      </form></td>
                      <td width="35" background="border_img/circle_06.gif">&nbsp;</td>
                    </tr>
                    <tr>
                      <td><img border='0' src="border_img/circle_07.gif" width=36 height=34 alt="" /></td>
                      <td height="34" background="border_img/circle_08.gif">&nbsp;</td>
                      <td><img border='0' src="border_img/circle_09.gif" width=35 height=34 alt="" /></td>
                    </tr>
                  </table>
                <? }?>
              </td>
            </tr>
          </table>
        </div>
      <!--::::::::::::::::::::::::::::::::::::::::::::::::::::::::::center ends:::::::::::::::::::::::::::::::::::::::::::::::::::::
::::::::::::::::::::::::::::::::::::::::::::::::::::::::::footer starts:::::::::::::::::::::::::::::::::::::::::::::::::::::-->
    </div>
  </div>
  <div class="bottom_links_show">
    <? include("footer.php");	?>
  </div>
</div>
<!--::::::::::::::::::::::::::::::::::::::::::::::::::::::::::footer ends:::::::::::::::::::::::::::::::::::::::::::::::::::::-->
</body>
</html>
