survey_seahorse

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

commit 2e0bcbe34cdf3b83b9784d0e48989bfe0f74d127
parent 73f3d44b6dea11307a6af945fe218429b93ea205
Author: John Kubach <johnkubach@gmail.com>
Date:   Wed, 19 Dec 2018 17:46:46 -0500

add survey archive

Diffstat:
Awebsite/archive.php | 73+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Mwebsite/directory.php | 6++++--
Mwebsite/index.php | 1+
3 files changed, 78 insertions(+), 2 deletions(-)

diff --git a/website/archive.php b/website/archive.php @@ -0,0 +1,73 @@ +<html> +<?php + session_start(); +ini_set('display_errors', 'On'); +error_reporting(E_ALL | E_STRICT); +include_once 'config.php'; +include 'res/navbar.php'; + +echo '<link rel="stylesheet" href="res/style.css">'; +echo '<div class="survey-directory">'; + +$date = date("Y-m-d"); +$sql = "SELECT COUNT(*) FROM survey WHERE expiration_date < '$date';"; +$result = mysqli_query($connect, $sql); +$r = mysqli_fetch_row($result); +$number_rows = $r[0]; +$rows_page = 3; +$total_pages = ceil($number_rows / $rows_page); + +if (isset($_GET['page']) && is_numeric($_GET['page'])) { + $page = (int) $_GET['page']; +} else { + $page = 1; +} + +$offset = ($page - 1) * $rows_page; +$sql = "SELECT * FROM survey WHERE expiration_date < '$date' LIMIT $offset, $rows_page;"; +$result = mysqli_query($connect, $sql); + +while ($row = mysqli_fetch_assoc($result)) { + $expire = $row['expiration_date']; + $sid = $row['survey_id']; + $title = $row['title']; + $url = "takesurvey.php?sid=" . $sid; + $qr = "res/qrgen.php?sid=" . $sid; + echo "Survey ID: ", $row['survey_id'], "<br>"; + echo "Title: <a href='$url'> $title </a> <br>"; + echo "By: ", $row['author'], "<br>"; + echo "Description: ", $row['description'], "<br>"; + echo "Access code: ", $row['access_code'], "<br>"; + echo "<a href='$qr'> QR Code </a> <br><br>"; +} + +/* generate page links */ + +$range = 3; + +if ($page > 1) { + echo " <a href='{$_SERVER['PHP_SELF']}?page=1'><<</a> "; + $prevpage = $page - 1; + echo " <a href='{$_SERVER['PHP_SELF']}?page=$prevpage'><</a> "; +} + +for ($x = ($page - $range); $x < (($page + $range) + 1); $x++) { + if (($x > 0) && ($x <= $total_pages)) { + if ($x == $page) { + echo " [<b>$x</b>] "; + } else { + echo " <a href='{$_SERVER['PHP_SELF']}?page=$x'>$x</a> "; + } + } +} + +if ($page != $total_pages) { + $nextpage = $page + 1; + echo " <a href='{$_SERVER['PHP_SELF']}?page=$nextpage'>></a> "; + echo " <a href='{$_SERVER['PHP_SELF']}?page=$total_pages'>>></a> "; +} + +exit(); +?> +</div> +</html> diff --git a/website/directory.php b/website/directory.php @@ -9,7 +9,8 @@ include 'res/navbar.php'; echo '<link rel="stylesheet" href="res/style.css">'; echo '<div class="survey-directory">'; -$sql = "SELECT COUNT(*) FROM survey;"; +$date = date("Y-m-d"); +$sql = "SELECT COUNT(*) FROM survey WHERE expiration_date >= '$date';"; $result = mysqli_query($connect, $sql); $r = mysqli_fetch_row($result); $number_rows = $r[0]; @@ -23,10 +24,11 @@ if (isset($_GET['page']) && is_numeric($_GET['page'])) { } $offset = ($page - 1) * $rows_page; -$sql = "SELECT * FROM survey LIMIT $offset, $rows_page;"; +$sql = "SELECT * FROM survey WHERE expiration_date >= '$date' LIMIT $offset, $rows_page;"; $result = mysqli_query($connect, $sql); while ($row = mysqli_fetch_assoc($result)) { + $expire = $row['expiration_date']; $sid = $row['survey_id']; $title = $row['title']; $url = "takesurvey.php?sid=" . $sid; diff --git a/website/index.php b/website/index.php @@ -45,6 +45,7 @@ if (isset($message)) { <a href="createsurvey.php"> Create Survey </a> <br>--> <a href="findsurvey.php"> Find a Survey </a> <a href="directory.php"> Survey Directory</a> + <a href="archive.php"> Survey Archive</a> <?php if (isset($_SESSION['uid'])) {