require_once "../includes/functions.php";
require_once "../includes/validation-functions.php";
?>

<?php 
$page = "assign-question.php";
?>

<?php 
include '../includes/layouts/header.php';
?>

<?php 
// If question does not exist, redirect back to Manage Questions Page
$id = isset($_GET["question_id"]) ? $_GET["question_id"] : "";
$question = get_question_by_id($id);
if (!$question) {
    redirect_to("manage-questions.php");
}
?>

<?php 
if (isset($_POST['submit-assign-question'])) {
    // The Assign Question Form was submitted
    $_POST = array_map('mysql_real_escape_string', $_POST);
    $quiz_name = $_POST['quiz_name'];
    $query = "SELECT * FROM quiz WHERE quiz_name = '{$quiz_name}' LIMIT 1";
    $result = mysqli_query($db, $query);
    if ($result && mysqli_affected_rows($db) == 1) {
        $row = mysqli_fetch_assoc($result);
        $quiz_id = $row["quiz_id"];
<?php

require_once "../includes/sessions.php";
require_once "../includes/db-connection.php";
require_once "../includes/functions.php";
?>

<?php 
$question = get_question_by_id($_GET["question_id"]);
if (!$question) {
    // Question id was missing or invalid or
    // could not be found in the database.
    $_SESSION["error_message"] = "Failed to delete question. Question does not exist.";
    redirect_to("manage-questions.php");
}
$id = $question["question_id"];
$query = "DELETE FROM question WHERE question_id = {$id} LIMIT 1";
$result = mysqli_query($db, $query);
if ($result && mysqli_affected_rows($db) == 1) {
    $query2 = "DELETE FROM answer WHERE question_id = {$id}";
    $result2 = mysqli_query($db, $query2);
    if ($result2) {
        $query3 = "DELETE FROM quiz_has_question WHERE question_id = {$id}";
        $result3 = mysqli_query($db, $query3);
        if ($result3) {
            // Success
            $_SESSION["message"] = "Successfully deleted question with id: {$id}.";
            redirect_to("manage-questions.php");
        }
    }
} else {
                    <a href="manage-quizzes.php" id="cancel-edit-quiz" name="cancel-edit-quiz" class="btn btn-default pull-right margin-right-10">Cancel</a>
              </form>
				
				
				
				
				
				
          </div>
          <div class="table-responsive">
            <table class="table table-bordered">
              <tbody>
                <?php 
$i = 1;
while ($row = mysqli_fetch_assoc($linked_questions)) {
    $current_question = get_question_by_id($row['question_id']);
    //pr($current_question);
    ?>
                    
                    <tr><td class="tbp-question-list-header">Question <?php 
    echo $i++;
    ?>
 <div style="float:right;"><i class="fa fa-minus"></i> <a href="remove-question.php?quiz_id=<?php 
    echo $quiz["quiz_id"];
    ?>
&question_id=<?php 
    echo $current_question['question_id'];
    ?>
" onclick="return confirm('Are you sure to remove this question');">Remove from Test</a></div><h4></td></tr>
                    <tr><td><h4 class="tbp-question-list-body"><?php 
    echo $current_question['question_text'];
 switch ($request[0]) {
     case 'questions':
         if ($requestSize == 1) {
             exit(get_questions());
         }
         if ($requestSize == 2) {
             if ($request[1] == "") {
                 // special case.
                 // http://localhost/cardboard-qr-marker-frontend/api.php/questions/
                 exit(get_questions());
             }
             exit(get_question_by_id($request[1]));
         }
         if ($requestSize == 3) {
             if ($request[2] == "") {
                 exit(get_question_by_id($request[1]));
             }
         }
         handle_error();
     case 'qrcodes':
         exit(get_qrcodes_by_id($request[1], 200));
     case 'qrcodesprint':
         exit(get_qrcodes_by_id($request[1], 400));
     case 'particleqrcode':
         exit(get_particlesystem_qrcode_by_id($request[1], 200));
     case 'particleqrcodeprint':
         exit(get_particlesystem_qrcode_by_id($request[1], 400));
     case 'questioncount':
         exit(get_question_count());
     case 'particlesystems':
         if ($requestSize == 1) {