<?php 
session_start();
$success="";
if(isset($_SESSION['SESS_ADMINLOGGEDIN']) == FALSE) {
    header("Location: " . $config_basedir."adminlogin.php");
}
require("config.php");
require("db.php");
require("functions.php");
require("aheader.php");
?>
<?php
if(isset($_POST['asset'])){
    $logid = mysql_real_escape_string($_POST['logid']);
    $asset = mysql_real_escape_string($_POST['asset']);
    $options = mysql_real_escape_string($_POST['options']);
    $invested = mysql_real_escape_string($_POST['invested']);
    $entryr = mysql_real_escape_string($_POST['entryr']);
    $rate = mysql_real_escape_string($_POST['rate']);
    $entryt = mysql_real_escape_string($_POST['entryt']);
    $expiryt = mysql_real_escape_string($_POST['expiryt']);
    $status = mysql_real_escape_string($_POST['status']);
    $returnr = mysql_real_escape_string($_POST['return']);
    $sql = mysql_query("INSERT INTO trade (log_id,asset,optionr,invested,entryrate,rate,entrytime,expirytime,status,returnr) 
VALUES('$logid', '$asset' ,'$options','$invested','$entryr','$rate','$entryt','$expiryt','$status','$returnr')") or die (mysql_error());     
    header("location: request.php"); 
$success="<div class='success' align='center' style='margin-bottom:50px;'><img src='images/download.png'>Request Successful</div>";
}

if(isset($_GET['func']) == TRUE) {

    if($_GET['func'] != "conf") {
        header("Location: " . $config_basedir ."adminorders.php");
    }
    $validid = pf_validate_number($_GET['id'], "redirect", $config_basedir);
    $funcsql = "UPDATE logins SET verify = 2 WHERE id = " . $_GET['id'];
    mysql_query($funcsql);
    header("Location: " . $config_basedir . "admintrade.php");
}
else {
    echo '<hr><div class="container" align="center" style="margin-top:20px;">


        <h3>Trade History</h3>';
    $sql = mysql_query("SELECT COUNT(id) FROM trade ");
    $row = mysql_fetch_row($sql);
    // Here we have the total row count
    $rows = $row[0];
    // This is the number of results we want displayed per page
    $page_rows = 10;
    // This tells us the page number of our last page
    $last = ceil($rows/$page_rows);
    // This makes sure $last cannot be less than 1
    if($last < 1){
        $last = 1;
    }
    // Establish the $pagenum variable
    $pagenum = 1;
    // Get pagenum from URL vars if it is present, else it is = 1
    if(isset($_GET['pn'])){
        $pagenum = preg_replace('#[^0-9]#', '', $_GET['pn']);
    }
    // This makes sure the page number isn't below 1, or more than our $last page
    if ($pagenum < 1) { 
        $pagenum = 1; 
    } else if ($pagenum > $last) { 
        $pagenum = $last; 
    }
    // This sets the range of rows to query for the chosen $pagenum
    $limit = 'LIMIT ' .($pagenum - 1) * $page_rows .',' .$page_rows; 

    $orderssql = "SELECT * FROM trade";
    $ordersres = mysql_query($orderssql);
    $numrows = mysql_num_rows($ordersres);

    if($numrows == 0)
    {
        echo "<strong>No History</strong>";
    }
    else

    {			$textline1 = "Results (<b>$rows</b>)";
     $textline2 = "Page <b>$pagenum</b> of <b>$last</b>";
     // Establish the $paginationCtrls variable
     $paginationCtrls = '';
     // If there is more than 1 page worth of results
     if($last != 1){
         /* First we check if we are on page one. If we are then we don't need a link to 
the previous page or the first page so we do nothing. If we aren't then we
generate links to the first page, and to the previous page. */

         if ($pagenum > 1) {
             $previous = $pagenum - 1;
             $paginationCtrls .= '<a class="btn-page" href="'.$_SERVER['PHP_SELF'].'?pn='.$previous.'">Prev</a>  ';
             // Render clickable number links that should appear on the left of the target page number

             for($i = $pagenum-2; $i < $pagenum; $i++){

                 if($i > 0){
                     $paginationCtrls .= '<a class="btn-page" href="'.$_SERVER['PHP_SELF'].'?pn='.$i.'">'.$i.'</a>&nbsp; ';
                 }
             }

         }

         // Render the target page number, but without it being a link
         $paginationCtrls .= ''.$pagenum.'&nbsp; ';
         // Render clickable number links that should appear on the right of the target page number
         for($i = $pagenum+1; $i <= $last; $i++){
             $paginationCtrls .= '<a class="btn-page" href="'.$_SERVER['PHP_SELF'].'?pn='.$i.'">'.$i.'</a>  ';
             if($i >= $pagenum+2){
                 break;
             }
         }

         if ($pagenum <= $last-3) {
             $paginationCtrls .= '<a class="btn-page" href="'.$_SERVER['PHP_SELF'].'?pn='.$last.'">&gt;&gt;</a>  ';

         }
         // This does the same as above, only checking if we are on the last page, and then generating the "Next"
         if ($pagenum != $last) {
             $next = $pagenum + 1;
             $paginationCtrls .= '  <a class="btn-page" href="'.$_SERVER['PHP_SELF'].'?pn='.$next.'">Next</a> ';

         }


     }
     $list = '';	
     echo "<table cellspacing=400>";

     while($row = mysql_fetch_assoc($ordersres))
     {
         echo "<tr>";
         echo "<td>". $row['id']."</td>";
         echo "<td>". $row['log_id']."</td>";
         echo "<td>". $row['asset']."</td>";
         echo "<td>";
             if($row['optionr']==1){
                 echo "Call";
             }else{
                 echo "Put";
             }
             
          echo   "</td>";
         echo "<td>". $row['invested']."</td>";
         echo "<td>". $row['entryrate']."</td>";
         echo "<td>". $row['rate']."</td>";
         echo "<td>" . date(" jS F Y g.iA", strtotime($row['entrytime'])) . "</td>";
         echo "<td>" . date(" jS F Y g.iA", strtotime($row['expirytime'])) . "</td>";
         echo "<td>";
         if($row['status']==1){
             echo "Won";
         }else{
             echo "Lost";
         }

         echo   "</td>";
         echo "<td>". $row['returnr']."</td>";
         

         echo "</tr>";	
     }

    }
    echo "</table>";
    echo "</div></div>";
}

?>
<?php echo $success;
?>
<form action="" enctype="multipart/form-data" name="myForm" id="myform" method="post" ><div class="container" align="center">
    <div class="col-md-5" align="right"><label for="details" style="margin-top:12px;">Log Id :</label></div><div class="col-md-7" align="left">
    <input type="number" name="logid" id="details" min="1"/>
    </div></div><div class="container" align="center">
    <div class="col-md-5" align="right"><label for="details" style="margin-top:12px;">Asset :</label></div><div class="col-md-7" align="left">
    <select name="asset" class="" id="category" required="required">
    <option value="AUD/USD">AUD/USD</option>
    <option value="EUR/GBP">EUR/GBP</option>
    <option value="EUR/AUD">EUR/AUD</option>
    <option value="EUR/JPY">EUR/JPY</option>
    <option value="EUR/USD">EUR/USD</option>
    <option value="GBP/JPY">GBP/JPY</option>
    <option value="GBP/USD">GBP/USD</option>
    <option value="USD/CAD">USD/CAD</option>
    <option value="USD/CHF">USD/CHF</option>
    <option value="USD/JPY">USD/JPY</option>
    <option value="ALPHABETHICAL_INC">ALPHABETICAL Inc C(Google)</option>
    <option value="APPLE">APPLE</option>
    <option value="RTS">RTS F-SEP16</option>
    <option value="GOLD/EUR">GOLD/EUR</option> 
    </select>
    </div></div><div class="container" align="center">
    <div class="col-md-5" align="right"><label for="details" style="margin-top:12px;">Options :</label></div><div class="col-md-7" align="left">
    <select name="options" class="" id="category" required="required">
    <option value="1">CALL</option>
    <option value="2">PUT</option>
    </select>
    </div></div><div class="container" align="center">
    <div class="col-md-5" align="right"><label for="details" style="margin-top:12px;">Invested :</label></div><div class="col-md-7" align="left">
    <input type="number" name="invested" id="details" min="1"/>
    </div></div><div class="container" align="center">
    <div class="col-md-5" align="right"><label for="details" style="margin-top:12px;">Entry Rate :</label></div><div class="col-md-7" align="left">
    <input type="number" name="entryr" id="details" min="1"/>
    </div></div><div class="container" align="center">
    <div class="col-md-5" align="right"><label for="details" style="margin-top:12px;">Rate :</label></div><div class="col-md-7" align="left">
    <input type="number" name="rate" id="details" min="1"/>
    </div></div><div class="container" align="center">
    <div class="col-md-5" align="right"><label for="details" style="margin-top:12px;">Entry Time :</label></div><div class="col-md-7" align="left">
    <input type="datetime-local" name="entryt" id="details" min="1"/>
    </div></div><div class="container" align="center">
    <div class="col-md-5" align="right"><label for="details" style="margin-top:12px;">Expiry Time :</label></div><div class="col-md-7" align="left">
    <input type="datetime-local" name="expiryt" id="details" min="1"/>
    </div></div><div class="container" align="center">
    <div class="col-md-5" align="right"><label for="details" style="margin-top:12px;">Status :</label></div><div class="col-md-7" align="left">
    <select name="status" class="" id="category" required="required">
        <option value="1">WON</option>
        <option value="2">LOST</option>
    </select>
    </div></div><div class="container" align="center">
    <div class="col-md-5" align="right"><label for="details" style="margin-top:12px;">Return :</label></div><div class="col-md-7" align="left">
    <input type="number" name="return" id="details" min="1"/>
    </div></div><div clas="container" align="center"><div class="col span-3-of-3"><label>
    <input type="submit" name="button" id="btn-mlogin" value="Set" style="background: green !important"/>
    </label></div></div>
</form>
<br><br><br><br>
<?php
require ("footer.php");
?>