<?php 

@session_start();


	if($_SESSION['SECEXP'] !=''){

	}else{
		header('Location:'.SITEURL);
	}
	
  
      	if(isset($_REQUEST['btnEdit'])){
			$sqlD = 'DELETE FROM '.$DB->pre.'percentage';
			$DB->dbQuery($sqlD);
			
			 $sqlI = 'INSERT INTO '.$DB->pre.'percentage set per="'.($_REQUEST['per']).'",dateAdded="'.date('Y-m-d H:i:s').'"';
			$msg = '';
			if($DB->dbQuery($sqlI)){
				$msg = 'Percentage Added Successfully...';
			}
		}
		
		if(isset($_REQUEST['btnPerWin'])){
      //echo "<pre>";

      //print_r($_REQUEST);
      foreach($_REQUEST['usersID'] as $k=>$U){
        $sqlU = 'UPDATE '.$DB->pre.'users SET remark="'.$_REQUEST['per'][$k].'" WHERE id="'.$U.'"';
        $DB->dbQuery($sqlU);
      }
      $msg1 = 'Personal Winning Set Successfully...';
    }
	  
?>
<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">
<style>
td a {
	font-weight: bold;
}
</style>

</head>

<body>
<div class="container" style="background:#fff;" >
  <div class="menus">
    <ul style="">
      <?php echo innerAdminMenu()?>
    </ul>
  </div>
  <div class="row" >
    <div class="a-form" style="width: 450px; float: left; background:#fff;" >
      <form action="<?php echo SITEURL?>/percentage" id="frmAgent" name="frmAgent" method="GET"  autocomplete="off">
        <div class="container">
        <?php 
			$sqlP = 'SELECT per FROM '.$DB->pre.'percentage';
			$P = $DB->dbRow($sqlP);
		?>
          <table>
            <tr>
              <td>Win Percentage</td>
              <td>
                  <input id="per" name="per" type="text" value="<?php echo ($P['per'])?>" required>
                  </td>
            </tr>
            <tr>
              <td><button class="btn" type="submit" id="btnEdit" name="btnEdit" style="background-color:#6F0">Update </button></td>
            </tr>
          </table>
        </div>
      </form>
    
      <p><?php echo $msg;?></p>
    </div>
  </div>
</div>
</br>
</br>
<div style="padding-top:53px;">
<form id="frmSetWin" name="frmSetWin" method="GET" action="<?php echo SITEURL?>/percentage">
<table border="1" width="100%" cellspacing="0" style="color:#fff;">
  <tr>
    <th>Name</th>
    <th>Percentage</th>
</tr>
<?php
  $sql = 'SELECT * FROM '.$DB->pre.'users WHERE userType="3" AND status="1" AND isActive="1"';
  $D = $DB->dbRows($sql);

  foreach($D as $D){
    ?>
    <tr>
    <td><?php echo $D['name']?><input id="userID<?php echo $D['id']?>" name="usersID[]" value="<?php echo $D['id']?>" type="hidden"></td>
    <td><input name="per[]" id="per<?php echo $D['id']?>" type="text" value="<?php echo intval($D['remark'])?>"></td>
  </tr>
    <?php
  }
?>
<tr>
    <td colspan="2" align="center">
      <input id="btnPerWin" name="btnPerWin" type="submit" value="Set Win" style="width: 100px;color: red;background-color: floralwhite;">
      <input id="btnPerCancel" name="btnPerCancel" type="button" value="Cancel" style="width: 100px;color: red;background-color: floralwhite;" onclick="location.href='<?php echo SITEURL?>/percentage'">
  </td>
    
</tr>
</table>
<p style="font-size: 20px;
color: #fff;"><?php echo $msg1;?></p>
</form>
</div>
</body>
</html>
