Guest User

userlist

a guest
May 29th, 2013
95
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 8.53 KB | None | 0 0
  1. <?php
  2. require_once('authenticate.php');
  3. include_once('includes/header.inc.php');
  4. include_once('includes/navigation.inc.php');
  5. //variable for email used in login
  6. $email = $_SESSION['email'];
  7. //selects profile in database that correlates with $email variable
  8. $result = mysql_query("SELECT * FROM users WHERE email='$email'") or die(mysql_error());
  9. $row = mysql_fetch_array($result);
  10. //variable check for admin value in database
  11. $admin = $row['admin'];
  12. //if the user is an admin he will proceed
  13. if ($admin == '1') {
  14. $idQuery = "SELECT * FROM users ORDER BY id LIMIT 0, 20";
  15. $id_result = mysql_query($idQuery, $dbhandle);
  16. if (isset($_GET["page"])) { $page  = $_GET["page"]; } else { $page=1; };
  17. $start_from = ($page-1) * 20;
  18. $columnname = "";
  19.             if ($_GET['columnname']) {
  20.             $columnname = $_GET['columnname'];
  21.             } else {
  22.                 $columnname = "ID";
  23.             }
  24.             $order = "";
  25.             if ($_GET['order']) {
  26.             $order = $_GET['order'];
  27.             } else {
  28.                 $order = "";
  29.             }
  30.             if ($order == "") {
  31.             $order = "ASC"; }
  32.             elseif ($order == "ASC") {
  33.             $order = "DESC";}
  34.             elseif ($order == "DESC") {
  35.             $order = "ASC";}
  36.             if ($columnname == "")
  37.             {$columnname = "id"; }
  38.             $query = mysql_query("SELECT * FROM users ORDER BY $columnname $order LIMIT $start_from, 20");
  39.             $sqlr = "SELECT COUNT(id) FROM users";
  40.             $rs_result = mysql_query($sqlr,$dbhandle);
  41.             $rowr = mysql_fetch_row($rs_result);
  42.             $total_records = $rowr[0];
  43.             $total_pages = ceil($total_records / 20);
  44.            
  45.             function sanitizez($data)   {
  46.             $data=trim($data);
  47.             $data=htmlspecialchars($data);
  48.             $data=mysql_real_escape_string($data);
  49.             return $data;
  50.             }
  51.            
  52.                 function HashPassword($input)   {
  53.                 //Credits: http://crackstation.net/hashing-security.html
  54.                 //This is secure hashing the consist of strong hash algorithm sha 256 and using highly random salt
  55.                     $salt = bin2hex(mcrypt_create_iv(32, MCRYPT_DEV_URANDOM));
  56.                     $hash = hash("sha256", $salt . $input);
  57.                     $final = $salt . $hash;
  58.                     return $final;
  59.                 }
  60. ?>
  61. <h2>User List</h2>
  62. <div id="userlist">
  63. <div class="row title">
  64.     <div class="column id no-border">
  65.         <a href="?columnname=id&order=asc"><h2 title="Arrange User ID in numerical order - This is active by default" alt="Arrange User ID in numerical order - This is active by default" class="tt-n">User ID</h2></a>
  66.     </div>
  67.     <div class="column email no-border">
  68.         <a href="?columnname=email&order=asc"><h2 title="Arrange list by Email Address in alphabetical order" alt="Arrange list by Email Address in alphabetical order" class="tt-n">Email Address</h2></a>
  69.     </div>
  70.     <div class="column loginattempt no-border">
  71.         <a href="?columnname=loginattempt&order=desc"><h2 title="Arrange list by the greatest number of Login Attempts to the least" alt="Arrange list by the greatest number of Login Attempts to the least" class="tt-n">Login Attempts</h2></a>
  72.     </div>
  73.     <div class="column admin no-border">
  74.         <a href="?columnname=admin&order=desc"><h2 title="Arrange list by those who have Admin privileges to those who don't" alt="Arrange list by those who have Admin privileges to those who don't" class="tt-n">Admin</h2></a>
  75.     </div>
  76. </div>
  77. <?php while ($queryf = mysql_fetch_array($query)) { ?>
  78. <div class="row">
  79.     <div class="column id">
  80.         <h5><?php echo $queryf['id']; ?></h5>
  81.     </div>
  82.     <div class="column email">
  83.         <?php echo $queryf['email']; ?>
  84.     </div>
  85.     <div class="column loginattempt">
  86.         <h5><?php echo $queryf['loginattempt']; ?></h5>
  87.     </div>
  88.     <div class="column admin">
  89.         <?php
  90.         $rowid = $queryf['id'];
  91.         $emailr = $queryf['email'];
  92.         if ($queryf['admin'] == '1') {
  93.             if(!empty($_POST['submit-id'.$rowid.''])){
  94.                 $adminYes = "UPDATE users SET admin = '0' where email = '$emailr'";
  95.                 mysql_query($adminYes);
  96.         }
  97.         echo '<form action="" method="post">
  98.         <input name="submit-id'.$rowid.'" type="submit" class="btnLogin tt-ul" value="Enabled" title="Clicking will remove admin privileges from: '; echo $emailr; echo '" />
  99.         </form>';
  100.         } else {
  101.                 echo '<form action="" method="post" id="confirm">';
  102.                     if(!empty($_POST['submit-id'.$rowid.''])){
  103.                         $adminNo = "UPDATE users SET admin = '1' where email = '$emailr'";
  104.                         mysql_query($adminNo);
  105.                     }
  106.                     echo '<input name="submit-id'.$rowid.'" type="submit" class="btnLogin tt-ul" value="Disabled" title="Clicking will grant admin privileges to: ';echo $emailr;echo '" />
  107.                     </form>';
  108.                 }
  109.         ?>
  110.     </div>
  111.     <div class="column editprofile"><a href="" title="Edit profile: <?php echo $emailr ?>" alt="Edit Profile" class="edit-profile tt-ul">Edit Profile</a></div>
  112.     <div class="column deleteprofile">
  113.         <form onsubmit="return false;" action="" method="post">
  114.             <input name="submit" type="submit" class="btnLogin tt-ul" value="Delete" title="Clicking will delete profile: <?php echo $emailr; ?>" />
  115.         </form>
  116.     </div>
  117.     </div>
  118.     <div class="row hide-id">
  119.         <h2>Profile: <?php echo $emailr ?></h2>
  120.         <ul id="settings">
  121.         <a href="" style="width:150px"><li title="Change this user's password" alt="Change Password" class="tt-w">Change Password</li></a>
  122.         <div class="hide-form">
  123.         <?php
  124.         $newpassword = sanitizez($_REQUEST['np-'.$rowid.'']);   {
  125.             $hashedpassword = HashPassword($newpassword);
  126.         }
  127.         $sql = "UPDATE users SET password = '$hashedpassword' where email = '$emailr'";
  128.         mysql_query($sql);
  129.         ?>
  130.             <form class="box login" action="index.php" method="post">
  131.             <fieldset class="boxBody">
  132.             <label lang="en" for="newpassword">New Password:</label>
  133.             <input type="password" name="newpassword" id="newpassword" tabindex="1" title="Must be alphanumeric and greater than 8 characters" class="tt-w" />
  134.             <label lang="en" for="cpassword">Confirm Password:</label>
  135.             <input type="password" name="cpassword" id="cpassword" tabindex="2" title="Re-type password" class="tt-w" />
  136.             </fieldset>
  137.             <footer>
  138.             <input lang="en" name="np-<?php echo $rowid ?>" type="submit" class="btnLogin" value="Change Password" tabindex="3" />
  139.             </footer>
  140.             </form>
  141.         </div>
  142.         <a href="" style="width:170px"><li title="Update this user's email address" alt="Update Email Address" class="tt-w">Update Email Address</li></a>
  143.         <div class="hide-form">
  144.                 <form class="box login" action="?go=updated" method="post">
  145.                 <fieldset class="boxBody">
  146.                 <label lang="en" for="newpassword">New Email Address:</label>
  147.                 <input type="text" name="newpassword" id="newpassword" tabindex="1" title="Using [email protected] format" class="tt-w" />
  148.                 <label lang="en" for="cpassword">Confirm Email Address:</label>
  149.                 <input type="text" name="cpassword" id="cpassword" tabindex="2" title="Re-type email address" class="tt-w" />
  150.                 </fieldset>
  151.                 <footer>
  152.                 <input lang="en" name="submit" type="submit" class="btnLogin" value="Update Email Address" tabindex="3" />
  153.                 </footer>
  154.                 </form>
  155.         </div>
  156.         <?php
  157.         if ($queryf['loginattempt'] <= '5') {
  158.             if(!empty($_POST['lattempt-id'.$rowid.''])){
  159.                 $banUser = "UPDATE users SET loginattempt = '9' where email = '$emailr'";
  160.                 mysql_query($banUser);
  161.         }
  162.         echo '<form action="" method="post">
  163.               <input name="lattempt-id'.$rowid.'" type="submit" class="tt-w" value="Ban User" title="Click to ban this user" />
  164.               </form>
  165.               <div class="hide-form">';
  166.         } else {
  167.             if ($queryf['loginattempt'] >= '6') {
  168.                 if(!empty($_POST['lattempt-id'.$rowid.''])){
  169.                     $unbanUser = "UPDATE users SET loginattempt = '0' where email = '$emailr'";
  170.                     mysql_query($unbanUser);
  171.                 }
  172.                 echo '<form action="" method="post" id="confirm">
  173.                 <input name="lattempt-id'.$rowid.'" type="submit" class="tt-w" value="Unban User" title="Click to unban user" />
  174.                 </form>';
  175.             }
  176.         }
  177.         ?>
  178.         </ul>
  179.     </div>
  180. <?php
  181. }
  182.     echo '<div id="pages"><p style="float:left;margin-right: 5px;">Pages: </p>';
  183.     for ($i=1; $i<=$total_pages; $i++) {
  184.     echo "<a href='?page=".$i."'><div title='Go to page ".$i."' class='tt-ul pagenumbers'>".$i."</div></a>";   
  185.     };
  186. echo '</div>';
  187. echo '<p style="font-style:italic;float:left;margin: 10px 0 0 -30px">The database has a total of '.$total_records.' profiles.</p>';
  188. $row = mysql_fetch_assoc($id_result);
  189. ?>
  190. </div>
  191. <?php
  192. } else {
  193. echo '<h2>Restricted Access</h2><p align="center">Only Administrators can access this page. Please log in to your account to proceed.</p>';
  194. }
  195. include_once('includes/footer.inc.php');
  196. ?>
Advertisement
Add Comment
Please, Sign In to add comment