<?php
@session_start();
if($_SESSION['SECEXP'] !=''){

	}else{
		header('Location:'.SITEURL);
	}
?>
<!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=utf-8" />
<meta http-equiv="X-UA-Compatible" content="IE=11" >
<!--[if IE 7]>
<link rel="stylesheet" type="text/css" href="<?php echo SITEURL?>/css/ie7.css">
<![endif]-->
<!--[if IE 8]>
<link rel="stylesheet" type="text/css" href="<?php echo SITEURL?>/css/ie7.css">
<![endif]-->
<link rel="stylesheet" type="text/css" href="<?php echo SITEURL?>/css/ie7.css">
</head>

<body>
	<div class="container">
		<div class="menus">
          <ul style="">
              <?php echo innerAdminMenu()?>
          </ul>
        </div>

		<div class="row">
			<div class="a-form" style="width: 250px; padding:10px; float: left; background-color: #6F9;">
            	<form id="frmBarcode" name="frmBarcode" method="GET" action="<?php echo SITEURL?>/barcode">
                	<div class="container">
                    	<table>
                        	<tr>
                            	<td>TRN Number</td>
                                <td><input id="trnno" name="trnno" type="text"></td>
                            </tr>
                            <tr>
                            	<td>Barcode No.</td>
                                <td><input id="barcodeno" name="barcodeno" type="text"></td>
                            </tr>
                            <tr>
                            	<td>User Id</td>
                                <td><input id="userid" name="userid" type="text"></td>
                            </tr>
                            <tr>
                            	<td>Date :</td>
                                <td><input id="ticketDate" name="ticketDate" type="date"></td>
                            </tr>
                            <tr>
                            	<td>Time : </td>
                                <td><input id="tme" name="tme" type="text">
                                <input id="u" name="u" type="hidden" value="<?php echo $_REQUEST['u']?>">
                                <input id="flag" name="flag" type="hidden" value="<?php echo $_REQUEST['flag']?>">
                                <input id="id" name="id" type="hidden" value="<?php echo $_SESSION['id']?>">
                                
                                </td>
                            </tr>
                            <tr>
                            	<td><button id="search" name="search" type="submit">Search </button></td>
                                <td><button name="reset" type="reset">Reset </button></td>
                            </tr>                            
                        </table>
                    </div>
                </form>
			</div>
            
            <?php
                   
				   
				   if(isset($_REQUEST['search'])){
					   ?>
                       <div class="a-form" style="width: 1040px; padding:10px; float: right; background-color: #FF6; border:1px solid black;">
            	<table border="1" width="100%" cellspacing="0" cellpadding="0">
                <tr>
                	<th>Type </th>
                    <th>User ID</th>
                    <th>Date </th>
                    <th>Time </th>
                    <th>TRN No </th>
                    <th>Barcode </th>
                    <th>Point </th>
                    <th>Win Amt.</th>
                    </tr>
                       <?php
					   $where = '';
					if($_REQUEST['trnno']){
						$where .= ' AND tranID="'.$_REQUEST['trno'].'"';
					}
					if($_REQUEST['barcodeno']){
						$where .= ' AND barcode="'.$_REQUEST['barcodeno'].'"';
					}
					if($_REQUEST['userid']){
						$sqlU = 'SELECT id FROM '.$DB->pre.'users WHERE userCode="'.$_REQUEST['userid'].'"';
						$where .= ' AND uID="'.$U['id'].'"';
					}
					if($_REQUEST['ticketDate']){
							$where .= ' AND lotdate="'.$_REQUEST['ticketDate'].'"';
					}
					if($_REQUEST['tme']){
						$where .= ' AND lotTime="'.$_REQUEST['tme'].'"';
					}
					
					$sqlL = 'SELECT * FROM '.$DB->pre.'lottary WHERE status="1" '.$where;
					$L = $DB->dbRows($sqlL);
					if(count($L)>0){
						foreach($L as $L){
							$sqlU = 'SELECT userCode FROM '.$DB->pre.'users WHERE id="'.$L['uID'].'"';
							$U = $DB->dbRow($sqlU);
					
			?>
            
                    
                    <tr>
                    	<td>Ticket</td>
                        <td><?php echo $U['userCode'] ?></td>
                        <td><?php echo $L['lotdate']?></td>
                        <td><?php echo $L['lotTime']?></td>
                        <td><?php echo $L['tranID']?></td>
                        <td><?php echo $L['barcode']?></td>
                        <td><?php echo $L['qtytot']?></td>
                        <td><?php echo getWinAmount($L['barcode'])?></td>
                        
                    </tr>
                    
            </div>
            <?php 
					}
				   }
				   ?>
                   </table>
                   <?php
				   }
				   
				   
				   function getWinAmount($barcode){
					   global $DB;
					   $sql = 'SELECT * FROM '.$DB->pre.'result_win WHERE barcode="'.$L['barcode'].'"';
					   $L = $DB->dbRow($sql);
					   
					   $sqlW = 'SELECT winrate FROM '.$DB->pre.'users WHERE id="'.$L['uID'].'"';
					   $W = $DB->dbRow($sqlW);
					   
					   echo (($L['point']*$W['winrate'])*$L['cv']);
					   
					   
					   
					   
				   }
			?>
				
			
		</div>

	</div>

</body>
</html>
