survey_seahorse

Software Engineering Project - Fall 2018
Log | Files | Refs | README

archive.php (2059B)


      1 <html>
      2 <?php
      3 include_once 'res/session.php';
      4 include_once 'config.php';
      5 include 'res/navbar.php';
      6 
      7 echo '<link rel="stylesheet" href="res/style.css">';
      8 echo  '<div class="survey-directory">';
      9 
     10 $block = $_SESSION['blocked'];
     11 if ($block == 51) {
     12     header("Location: res/nope.php");
     13     exit();
     14 }
     15 
     16 $date = date("Y-m-d");
     17 $sql = "SELECT COUNT(*) FROM survey WHERE expiration_date < '$date';";
     18 $result = mysqli_query($connect, $sql);
     19 $r = mysqli_fetch_row($result);
     20 $number_rows = $r[0];
     21 $rows_page = 3;
     22 $total_pages = ceil($number_rows / $rows_page);
     23 
     24 if (isset($_GET['page']) && is_numeric($_GET['page'])) {
     25     $page = (int) $_GET['page'];
     26 } else {
     27     $page = 1;
     28 }
     29 
     30 $offset = ($page - 1) * $rows_page;
     31 $sql = "SELECT * FROM survey WHERE expiration_date < '$date' LIMIT $offset, $rows_page;";
     32 $result = mysqli_query($connect, $sql);
     33 
     34 while ($row = mysqli_fetch_assoc($result)) {
     35     $expire = $row['expiration_date'];
     36     $sid = $row['survey_id'];
     37     $title = $row['title'];
     38     $url = "takesurvey.php?sid=" . $sid;
     39     $qr = "res/qrgen.php?sid=" . $sid;
     40     echo "Survey ID: ", $row['survey_id'], "<br>";
     41     echo "Title: <a href='$url'> $title </a> <br>";
     42     echo "By: ", $row['author'], "<br>";
     43     echo "Description: ", $row['description'], "<br>";
     44     echo "Access code: ", $row['access_code'], "<br>";
     45     echo "<a href='$qr'> QR Code </a> <br><br>";
     46 }
     47 
     48 /* generate page links */
     49 
     50 $range = 3;
     51 
     52 if ($page > 1) {
     53    echo " <a href='{$_SERVER['PHP_SELF']}?page=1'><<</a> ";
     54    $prevpage = $page - 1;
     55    echo " <a href='{$_SERVER['PHP_SELF']}?page=$prevpage'><</a> ";
     56 }
     57 
     58 for ($x = ($page - $range); $x < (($page + $range) + 1); $x++) {
     59    if (($x > 0) && ($x <= $total_pages)) {
     60       if ($x == $page) {
     61          echo " [<b>$x</b>] ";
     62       } else {
     63          echo " <a href='{$_SERVER['PHP_SELF']}?page=$x'>$x</a> ";
     64       }
     65    }
     66 }
     67 
     68 if ($page != $total_pages) {
     69    $nextpage = $page + 1;
     70    echo " <a href='{$_SERVER['PHP_SELF']}?page=$nextpage'>></a> ";
     71    echo " <a href='{$_SERVER['PHP_SELF']}?page=$total_pages'>>></a> ";
     72 }
     73 
     74 exit();
     75 ?>
     76 </div>
     77 </html>