<!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" />
<title>Ajent Create User </title>

<link rel="stylesheet" type="text/css" href="<?php echo SITEURL?>/css/style.css">

</head>

<body style="background-color: rgb(204, 238, 150);">
	<div class="container">
		<div class="row inline">
			<div class="navstyle">
				<li>Date 
					<input type="date" name="Date">
					to 
					<input type="date" name="Date">
					&nbsp;
					<button class="btn" type="button" name="Screen">Screen </button>
					<button class="btn" type="button" name="Screen">Print </button>
					<button class="btn" type="button" name="Screen">Exit </button>

						

						<a href="login.html"><img src="<?php echo SITEURL?>/images/admin.jpg"></a>
<!--
						<a href="login.html" id="login-btn">login</a>
-->				</li>

				
            </div>
        </div>
        <div class="row inline" style="float: left; width: 72%; background-color: white; min-height: 500px;">
        <?php
			$sql = 'SELECT userCode FROM '.$DB->pre.'users WHERE id="'.intval($_REQUEST['id']).'"';
			$D = $DB->dbrow($sql);
        	
			$sqlB = 'SELECT balance FROM '.$DB->pre.'balance WHERE userCode="'.strtoupper($D['userCode']).'" ORDER BY balanceID DESC limit 0,1';
			$B = $DB->dbRow($sqlB);
			
		?>
            <h4 style="text-align: center;">Ajent Balance : <?php echo $B['balance']?> </h4>
			<div class="menus">
        <ul>
           <?php echo innerAdminMenu();?>
      </ul>
		    </div>

		<?php
				
                	$userID = '';
					$name = '';
					$pass = '';
					$mobNo = '';
					$userType = '';
					$underHead = '';
					$winRate = '';
					$commi = '';
					$bonus = '';
					$limit = '';
					$remark = '';
					$act = '';
					
					if(intval($_REQUEST['userID'])){
							echo $sqlU = 'SELECT * FROM '.$DB->pre.'users WHERE id="'.$_REQUEST['userID'].'"';
							$U = $DB->dbRow($sqlU);
							$userID = $U['userCode'];
							$name = $U['name'];
							$pass = $U['password'];
							$mobNo = $U['mobile'];
							$userType = $U['userType'];
							$underHead = $U['underHead'];
							$winRate = $U['winrate'];
							$commi = $U['commission'];
							$bonus = $U['bonus'];
							$limit = $U['limit'];
							$remark = $U['remark'];
							$act = $U['isActive'];
					}
					
					
					
					
                
				$msg = '';
					if(isset($_REQUEST['btnAgent'])){
						
						
						$sql = 'SELECT id FROM '.$DB->pre.'users WHERE userCode="'.strtolower($_REQUEST['userCode']).'"';
						$data = $DB->dbRow($sql);
						$str = array('str'=>'OK');
						if(count($data) > 0){
								$msg = '<p style="width:91%;background-color: #d92424;height: 20px;padding: 10px;color: #fff;font-weight: bold;">UserID all ready exits...</p>';
						}else{
						
							date_default_timezone_set('Asia/Kolkata');
							
							$sqlW = 'SELECT winrate,bonus,`limit`,commission FROM '.$DB->pre.'users WHERE id="'.$_REQUEST['id'].'"';
							$W = $DB->dbRow($sqlW);
							$msg = '<p style="width:91%;background-color: #d92424;height: 20px;padding: 10px;color: #fff;font-weight: bold;">Please put less values than Underhead</p>';
							if(($_REQUEST['winrate'] < $W['winrate']) && ($_REQUEST['bonus'] < $W['bonus']) && ($_REQUEST['limit'] < $W['limit']) && $_REQUEST['commission'] < $W['commission']){
						
							$_REQUEST['dateAdded'] = date('Y-m-d H:i:s');	
						
							$DB->table = $DB->pre."users";
							$DB->data  = $_REQUEST;
							$sql = 'INSERT INTO '.$DB->pre.'users SET userCode="'.$_REQUEST['userCode'].'",name="'.$_REQUEST['name'].'",`password`="'.$_REQUEST['password'].'",mobile="'.$_REQUEST['mobile'].'",userType="'.$_REQUEST['userType'].'",underHead="'.$_REQUEST['underHead'].'",winrate="'.$_REQUEST['winrate'].'",commission="'.$_REQUEST['commission'].'",bonus="'.$_REQUEST['bonus'].'",`limit`="'.$_REQUEST['limit'].'",remark="'.$_REQUEST['remark'].'",createdBy="'.$_REQUEST['hideUserID'].'",dateAdded="'.date('Y-m-d H:i:s').'",isActive="'.$_REQUEST['isActive'].'"';
							
							if($DB->dbQuery($sql)){
								$msg = '<p style="width:91%;background-color: #d92424;height: 20px;padding: 10px;color: #fff;font-weight: bold;">Agent Added Successfully...</p>';
							}
							}
						}
					}
				if(isset($_REQUEST['btnEdit'])){
						
						//echo $_REQUEST['userID'];
						$DB->table = $DB->pre."users";
						$DB->data  = $_REQUEST;
						$pkID = intval($_REQUEST['hideUserID']);
						$sqlU = "UPDATE `mx_users` SET `userCode`='".$_REQUEST['userCode']."',`name`='".$_REQUEST['name']."',`password`='".$_REQUEST['password']."',`mobile`='".$_REQUEST['mobile']."',`userType`='".$_REQUEST['userType']."',`underHead`='".$_REQUEST['underHead']."',`winrate`='".$_REQUEST['winrate']."',`commission`='".$_REQUEST['commission']."',`bonus`='".$_REQUEST['bonus']."',`limit`='".$_REQUEST['limit']."',`remark`='".$_REQUEST['remark']."',`isActive`='".$_REQUEST['isActive']."' WHERE id='".$pkID."'";
						if($DB->dbQuery($sqlU)){
								$msg = '<p style="width:91%;background-color: #d92424;height: 20px;padding: 10px;color: #fff;font-weight: bold;">User updated Successfully</p>';
						}
					}
				
				
					
				?>

		<div class="row">
			<div id="ajent_table02" style="width: 939*px;text-align: center !important;">
            	<div class="a-form" style="width: 0%; float: left;">
				
                    <form action="<?php echo SITEURL?>/lottery-agent/create-agent" id="frmAgent" name="frmAgent" method="GET"  autocomplete="off">
				  <div class="container">
                  <table>
                  <tr>
                  	<td>User ID</td>
                    <td><input id="userCode" name="userCode" type="text" value="<?php echo $userID?>" required>
                    <input id="hideUserID" name="hideUserID" type="hidden" value="<?php echo $_REQUEST['id'];?>">
                   <input id="hideUserID" name="hideUserID" type="hidden" value="<?php echo $_REQUEST['userID'];?>">
                    <input id="u" name="u" value="<?php echo $_REQUEST['u']?>" type="hidden">
                    <input id="flag" name="flag" value="1" type="hidden">
					<input id="u" name="u" value="<?php echo $_REQUEST['u']?>" type="hidden">
                    <input id="id" name="id" value="<?php echo $_REQUEST['id']?>" type="hidden">
                    </td>
                  </tr>
                  <tr>
                  	<td>Name</td>
                    <td><input id="name" name="name" type="text" value="<?php echo $name;?>" required></td>
                  </tr>
                  <tr>
                  	<td>Password</td>
                    <td><input id="password" name="password" type="text" value="<?php echo $pass?>" required></td>
                  </tr>
                  <tr>
                  	<td>Mobile No</td>
                    <td><input id="mobile" name="mobile" type="text" value="<?php echo $mobNo?>" required></td>
                  </tr>
                  
                  <tr>
                  	<td><b>User Type</b></td>
                    <td>
                    <label for="UserType">:</label>
                        <select name="userType" id="userType">
                        	<?php
                            	if(intval($userType)){
									if($userType == '1'){
										echo "<option value='1'>Admin</option>";
									}
									if($userType == '2'){
										echo "<option value='2'>Agent</option>";
									}	
									if($userType == '3'){
										echo "<option value='3'>Retailer</option>";
									}
								}
							?>
                        	
                          	<option value="2">Agent</option>
                          	<option value="3">Retailer</option>
                        </select> 
                    </td>
                  </tr>
                  
                                    
                  
                  
                  
                  
                  <tr>
                  	<td>Win Rate</td>
                    <td>
                    <select id="winrate" name="winrate" required>
                    		<?php
                            	if(intval($winRate)){
									if($winRate == '90'){
										echo "<option value='90'>90</option>";
									}
									if($winRate == '80'){
										echo "<option value='80'>80</option>";
									}	
									if($winRate == '70'){
										echo "<option value='70'>70</option>";
									}
								}
							?>
                    	<option value="">-Select Rate-</option>
                        <option value="90">90-90</option>
                        <option value="80">80-80</option>
                        <option value="70">70-70</option>
                    </select>
                    </td>
                  </tr>
                  <tr>
                  	<td><b>Under Head</b></td>
                    <td>
                    <label for="UserType">:</label>
                        <select name="underHead" id="underHead">
                        	<?php

                            	if($underHead !=''){
								?>
                                <?php echo getTableDD($DB->pre."users","id","userCode",$underHead," status='1' AND isActive='1'");?>
                                <?php
								}
							?>
                            <option value="">-Select UnderHead -</option>
                            
                            <option value="<?php echo $_REQUEST['id']?>"><?php echo $_REQUEST['u']?></option>
                          	
                        </select> 
                    </td>
                  </tr>
                  <tr>
                  	<td>Commition%</td>
                    <td><input id="commission" name="commission" type="text" value="<?php echo $commi?>" required></td>
                  </tr>
                  
                  <tr>

                  	<td>Bonus%</td>
                    <td><input id="bonus" name="bonus" type="text" value="<?php echo $bonus?>" required></td>
                  </tr>
                  
                  <tr>
                  	<td>Limit</td>
                    <td><input id="limit" name="limit" type="text" value="<?php echo $limit?>" required></td>
                  </tr>
                  
                  <tr>
                  	<td><b>Remark</b></td>
                    <td><input id="remark" name="remark" type="text" value="<?php echo $remark?>" required></td>
                  </tr>
                  
                  <tr>
                    	<td>
                    		<label class="container" id="idactive">
  							<input value="1" id="isActive" name="isActive" type="checkbox" <?php echo ($act=='1'?'checked="checked"':'');?>>
  								<span class="checkmark"></span> is Active
							</label>
                     	</td>
                  </tr>
                  
                  <tr>
                  <td colspan="2">					
                    <button class="btn" type="submit" id="btnAgent" name="btnAgent" style="background-color:#6F0">Save </button>
                    <button class="btn" type="submit" id="btnEdit" name="btnEdit" style="background-color:#6F0">Update </button>
					<button class="btn" type="reset" name="Clear" style="background-color:#FF0">Clear </button>
                    <button class="btn" type="submit" name="Delete" style="background-color:#F00">Delete </button>
                  </td>
                  
                  
                  
                   
                  </tr>
                  <tr>
                  	<td colspan="2"><?php  echo $msg;?></td>
                  </tr>
                  
                  </table>
				    </div>
				</form>
                
                </div>
                

                <div id="ajent_table02" style="width: 70%; float: right; ">
                    <table border="1px">
                      <tr>
                        <th>Sr.No. </th>
                        <th>User ID </th>
                        <th>Agent </th>
                        <th>Active </th>
                        <th>Created </th>
                        <th>Play </th>
                        <th>Win </th>
                        <th>Comm </th>
                      </tr>
                      <?php
                      	$sql = 'SELECT * FROM '.$DB->pre.'users WHERE status="1"  AND underHead="'.$_REQUEST['id'].'"';
						$D = $DB->dbRows($sql);
						$sqlN = 'SELECT userCode,id FROM '.$DB->pre.'users WHERE id="'.$_REQUEST['id'].'"';
						$N = $DB->dbRow($sqlN);
						foreach($D as $k=>$D){
					  
					  ?>
                      <tr>
                        <td><?php echo ($k+1)?></td>
                        <td><a href="<?php echo SITEURL?>/lottery-agent/create-agent/?userID=<?php echo $D['id']?>&u=<?php echo $_REQUEST['u']?>&flag=<?php echo $_REQUEST['flag']?>&id=<?php echo $_REQUEST['id']?>"><?php echo $D['userCode']?></a></td>
                        <td>MH2021 </td>                    
                        <td>User </td>                    
                        <td>23-01-2021 15:28:74 </td>                    
                        <td>0 </td>                    
                        <td>0 </td>                    
                        <td>0 </td>                   
                      </tr>
                      <?php 
					  	$sql1 = 'SELECT * FROM '.$DB->pre.'users WHERE status="1"  AND underHead="'.$D['id'].'"';
						$D1 = $DB->dbRows($sql1);
						if(count($D1) > 0){
							foreach($D1 as $D1){
								?>
                                <tr>
                        <td><?php echo ($k+1)?></td>
                        <td><?php echo $D1['userCode']?></td>
                        <td>MH2021 </td>                    
                        <td>User </td>                    
                        <td>23-01-2021 15:28:74 </td>                    
                        <td>0 </td>                    
                        <td>0 </td>                    
                        <td>0 </td>                   
                      </tr>
                                <?php
							}
						}
					  
					  } ?>
                      
                    </table>
    
                </div>


			</div>
				
			
		</div>
        </div>

        <div class="right_display" style="float: right; width: 27%; background-color: rgb(255, 255, 255);  min-height: 500px;">
        <div class="right_display" style="margin-left: 20px; width: 80%;">
            <table class="right_display_table">
                <tr>
                    <th>Agnet Code :</th>
                    <th>KA 1234 </th>
                </tr>
                <tr>
                    <th>Date Form :</th>
                    <th>23-01-2021 </th>
                </tr>
                <tr>
                    <th>Date to :</th>
                    <th>23-01-2021 </th>
                </tr>
            </table>

            <hr>

            <table width="90%" style="margin-left: 10px; margin-bottom: 10px;" >
                <tr>
                    <td style="text-align: left;">Sale </td>
                    <td style="text-align: right;">0 </td>
                </tr>
                <tr>
                    <td style="text-align: left;">Wining </td>
                    <td style="text-align: right;">0 </td>
                </tr>
            </table>

            <hr>

            <table width="90%" style="margin-left: 10px; margin-bottom: 10px;" >
                <tr>
                    <td style="text-align: left;">Net Amount </td>
                    <td style="text-align: right;">0 </td>
                </tr>
                <tr>
                    <td style="text-align: left;">Bonus </td>
                    <td style="text-align: right;">0 </td>
                </tr>
            </table>

            <hr>
            <table width="90%" style="margin-left: 10px; margin-bottom: 10px;" >
                <tr>
                    <td style="text-align: left;">Net to Pay </td>
                    <td style="text-align: right;">0 </td>
                </tr>
            </table>

            <hr>
        </div>
        </div>
	</div>

</body>
</html>
