<?php 
session_start();
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($_GET['func']) == TRUE) {

    if($_GET['func'] != "conf") {
        header("Location: " . $config_basedir ."admintrade.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>Users</h3>';
    $sql = mysql_query("SELECT COUNT(id) FROM logins ");
    $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 logins";
    $ordersres = mysql_query($orderssql);
    $numrows = mysql_num_rows($ordersres);

    if($numrows == 0)
    {
        echo "<strong>No Users</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>[<a href='adminmemberdetails.php?id=" . $row['id'] . "'>View</a>]</td>";
         echo "<td>" . date("D jS F Y g.iA", strtotime($row['date'])) . "</td>";
         echo "<td>". $row['country']."</td>";
         echo "<td>". $row['currency']."</td>";
         echo "<td>";

         if($row['verified'] == 0)
         {
             echo "Pending Verification";

             echo "</td>";
         }
         elseif ($row['verified'] == 1)
         {
             echo "Awaiting Your Verification";

             echo "</td>";
             echo "<td><a href='adminorders.php?func=conf&id=" . $row['id'] . "'> Verify</a></td>";
         }
 elseif ($row['verified'] == 2)
         {
     $veri="Verified";
     $user=$row['id'];
     $balance=mysql_query("SELECT * FROM logins WHERE id=$user");
     $nrow=mysql_fetch_assoc($balance);
     if (nrow['balance'] > 0){
         $veri="Verified and Deposited";
     }
     else{
         
     }
     echo "</td>";
         }

         echo "</tr>";	
     }

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

?><hr><div class="container" align="center">


</div>
<?php
require ("footer.php");
?>