Example #1
0
            <div class="span4">
	      <form action="check.php" method="post">
		<?php 
include $_SERVER['DOCUMENT_ROOT'] . "/config.php";
echo "<input type=\"hidden\" name=\"id\" value=\"" . sanitize($_GET['id']) . "\">";
?>
		<table cellspacing="0" class="table table-striped">
		   <?php 
$problemset_id = sanitize($_GET['id']);
$user = $_COOKIE['user_id'];
$query = "select * from " . $problemset_id . ";";
$mysqli = new mysqli("localhost", "root", "8PaHucre", "nuptse_questions");
$result = $mysqli->query($query);
$rowcount = $result->num_rows;
setUnansweredQuestions($problemset_id, $user, $rowcount);
$isExpired = checkExpiryDate($problemset_id, $user, $rowcount);
for ($i = 1; $i <= $rowcount; $i++) {
    $row = $result->fetch_assoc();
    parse_str($row['users_status'], $users_status);
    if (array_key_exists($user, $users_status)) {
        if ((int) $users_status[$user] == 4) {
            echo "<tr><td>" . $i . "</td><td>Incorrect after 2 attempts</td><td><button class=\"btn btn-small btn-primary disabled\" type=\"button\" id=\"question\" name=\"question\" value=\"" . $i . "\">Submitted</button></td></tr>\n";
        } else {
            if ((int) $users_status[$user] == 6) {
                echo "<tr><td>" . $i . "</td><td>Question Expired</td><td><button class=\"btn btn-small btn-primary disabled\" type=\"button\" id=\"question\" name=\"question\" value=\"" . $i . "\">Submitted</button></td></tr>\n";
            } else {
                if ((int) $users_status[$user] % 2 == 1) {
                    echo "<tr><td>" . $i . "</td><td>Correct after " . ceil((double) $users_status[$user] / 2) . " attempt(s)</td><td><button class=\"btn btn-small btn-primary disabled\" type=\"button\" id=\"question\" name=\"question\" value=\"" . $i . "\">Submitted</button></td></tr>\n";
                } else {
                    if ((int) $users_status[$user] == 2 and $isExpired == false) {
                        echo "<tr><td>" . $i . "</td><td><input type=\"text\" id=\"answer" . $i . "\" name=\"answer" . $i . "\" placeholder=\"Enter Answer\" autocomplete=\"off\"></td><td><button class=\"btn btn-small btn-primary btn-danger\" type=\"submit\" id=\"question\" name=\"question\" value=\"" . $i . "\">Try Again</button></td></tr>\n";
Example #2
0
<?php

include 'viewer/lib.php';
//path to file
if (isset($_COOKIE['user_id'])) {
    $id = $_GET['id'];
    $query = "select id from {$id};";
    $mysqli = new mysqli("localhost", "root", "8PaHucre", "nuptse_questions");
    $result = $mysqli->query($query) or die(mysql_error());
    $resultData = $result->fetch_array(MYSQLI_ASSOC);
    if (checkExpiryDate("{$id}", $_COOKIE['user_id'], $resultData['TOTALFOUND']) == true) {
        $filedir = "answers/{$id}" . "ans.pdf";
    } else {
        $filedir = "answers/attempted.pdf";
    }
} else {
    $filedir = "answers/attempted.pdf";
}
//name of file (can be whatever you like--i.e. doesn't have to be the same as actual file--whatever you name it is what the user will see)
$filename = "{$id} Answers";
//see http://www.w3schools.com/media/media_mimeref.asp for full list of mime types
$mimetype = 'application/pdf';
//see http://php.net/file_get_contents
$data = file_get_contents($filedir);
// see http://php.net/strlen
$size = strlen($data);
//trigger HTTP request - see http://php.net/header
header("Content-Disposition: attachment; filename = {$filename}");
header("Content-Length: {$size}");
header("Content-Type: {$mimetype}");
//see http://php.net/echo