<h1><center>Special Lucky Box</center></h1>
<p>
<?php
if ( $__TOKEN = "hardcodeshitbykernstudios")
{
$conn = sqlsrv_connect($__CONFIG['SQLHost'], array("Database"=>$__CONFIG['SQLDB'], "UID"=>$__CONFIG['SQLUID'], "PWD"=>$__CONFIG['SQLPWD']));
 if(!isset($_SESSION['nEMID']))
 {
  showMessage( 'info', 'Session terminated!' );
 }else{
  if (isset($_POST['Submit']))
  {
   $conn = sqlsrv_connect($__CONFIG['SQLHost'], array("Database"=>$__CONFIG['SQLDB'], "UID"=>$__CONFIG['SQLUID'], "PWD"=>$__CONFIG['SQLPWD']));
   $AccountCoins = sqlsrv_query($conn, "SELECT * FROM OdinAccounts..tAccounts WHERE nEMID = '".$_SESSION['nEMID']."' AND nAGPoints >= '1000';");
   $accountFetch = sqlsrv_fetch_array($AccountCoins);
   if (sqlsrv_has_rows($AccountCoins) == 1)
   {
   $selectBoxItemes = sqlsrv_query($conn, "SELECT * FROM OdinAccounts..tBox2 Where sEnabled = 1;");
   if (sqlsrv_has_rows($selectBoxItemes) == 1)
   {
    $count2 = sqlsrv_query($conn, "SELECT * FROM OdinAccounts..tBox2", array(), array("Scrollable"=>"buffered"));
    $count = sqlsrv_num_rows($count2);
    $randome = mt_rand(1, $count);
    if ($randome >= 8)
    {
     $randome2 = mt_rand(0, 7);
     $randome = $randome - $randome2;
     $selectedItem = sqlsrv_query($conn, "SELECT * FROM OdinAccounts..tBox2 WHERE No = '$randome';");
     $item  = sqlsrv_fetch_array($selectedItem);
	
	$orderNumber = mssql_escape_string($item['goodsNo']);
    $insertItem = sqlsrv_query($conn, "INSERT INTO OdinAccounts..tPurchases (nAGID, nPrice, nGoodsNo, nQuantity, nUsed, sIP, nIsGift, nStatus) VALUES('".$_SESSION['nEMID']."', '1000', '".$orderNumber."', '1', '0', '".getRemoteIP()."', '0', '2');" );
	If ($insertItem){
	 showMessage( 'success', '<center>You have earned: '.$item['description'].'<br /> <br /> <img src="/images/mall/'.$item['img'].'.png" />');
	 showMessage( 'success', 'The Item is now in your Cashshop Inventory!', 10, 'index.php?module=LuckySB');
    }
	else
	{
	showMessage( 'error', 'Can not Translate the Item into your Invertory!', 3, 'index.php?module=LuckySB');
	sqlsrv_query($conn, "UPDATE OdinAccounts..tAccounts SET nAGPoints = nAGPoints + '1000' WHERE nEMID = '".$_SESSION['nEMID']."';");
	}
	}
    else
    {
	 $UpdateCoins = sqlsrv_query($conn, "UPDATE OdinAccounts..tAccounts SET nAGPoints = nAGPoints - '1000' WHERE nEMID = '".$_SESSION['nEMID']."';");
	 If ($UpdateCoins){
		$selectedItem = sqlsrv_query($conn, "SELECT * FROM OdinAccounts..tBox2 WHERE No = '$randome';");
		$item  = sqlsrv_fetch_array($selectedItem);  
		$orderNumber = mssql_escape_string($item['goodsNo']);
		$insertItem = sqlsrv_query($conn, "INSERT INTO OdinAccounts..tPurchases (nAGID, nPrice, nGoodsNo, nQuantity, nUsed, sIP, nIsGift, nStatus) VALUES('".$_SESSION['nEMID']."', '1000', '".$orderNumber."', '1', '0', '".getRemoteIP()."', '0', '2');" );
	 }else {showMessage( 'error', 'Error cant Update the Coins!!!', 3, 'index.php?module=LuckySB');}
    If ($insertItem){
	 showMessage( 'success', '<center>You have earned: '.$item['description'].'<br /> <br /> <img src="/v3/images/mall/'.$item['img'].'.png" />');
	 showMessage( 'success', 'The Item is now in your Cashshop Inventory!', 10, 'index.php?module=LuckySB');
    }
	else
	{
	showMessage( 'error', 'Can not Translate the Item into your Invertory!', 3, 'index.php?module=LuckySB');
	sqlsrv_query($conn, "UPDATE OdinAccounts..tAccounts SET nAGPoints = nAGPoints + '1000' WHERE nEMID = '".$_SESSION['nEMID']."';");
	}
		 
	}
	}
   else
   {
    showMessage( 'error', 'Sorry :( No Special Lucky Box Items available!', 3, '?module=LuckyB');
   } 
   }
   else
   {
    showMessage( 'error', 'Sorry :( You can play with a minimum of 1000 Coins!', 3, '?module=LuckyB');
   } 
  }
  else
  {
   ?>
   <center>
   Welcome to our Special Lucky Box! One round = 1000 Coins! Currently you have <?php $AccountCoins = sqlsrv_query($conn, "SELECT * FROM OdinAccounts..tAccounts WHERE nEMID = '".$_SESSION['nEMID']."';"); $accountFetch = sqlsrv_fetch_array($AccountCoins); echo $accountFetch['nAGPoints'].' Coins' ; ?>
   </center>
   <br />
   <br />
   <form method="post">
   <table width="400px">
    <tr>
	 <center>
     Good Luck :) <br></br>
     <input type="submit" name="Submit" class="myButton" value="Submit" />
	  </center>
    </tr>
   </table>
   </form>
   <center>
   <br>
  Special Lucky Box Items:
   <?php include('LuckyItems2.php'); ?>
   </center>
   <?php
  }
 }
}
?>