include '../database.php';
header("Access-Control-Allow-Origin: *");
$query = $_GET['q'];
$class = $_GET['c'];
if ($query == null || $class == null) {
    echo "Error";
} else {
    if ($query == "new" && $class == "data") {
        getData($query);
    } else {
        if ($query == "cn" && $class == "data") {
            getClassData($query);
        } else {
            if ($query == "en" && $class == "data") {
                $query = $_GET['q'];
                getClassData($query);
            } else {
                if ($query == "new" && $class == "user") {
                    getUserData();
                } else {
                    if ($query == "cn" && $class == "user") {
                        getUserClassData($query);
                    } else {
                        if ($query == "en" && $class == "user") {
                            getUserClassData($query);
                        } else {
                            echo "Undefined";
                        }
                    }
                }
            }
	</div>
	<div class="form-group">
		<label class="control-label col-sm-2" for="deadline">Deadline:</label>
		<div class="col-sm-10">
			<input type="date" class="form-control" name="deadline" id="deadline"
				placeholder="Enter Deadline">
		</div>
	</div>
	<div class="form-group">
		<label class="control-label col-sm-2" for="class_id">Class:</label>
		<div class="col-sm-10">
		<!--	<input type="number" class="form-control" name="class_id" id="class_id"
				placeholder="Enter Class id"> -->
				<select class="form-control" id="class_id" name="class_id">
				<?php 
$result = getClassData();
if ($result != null) {
    foreach ($result as $key => $value) {
        echo "<option  value='" . $value['id'] . "'>" . $value['name'] . "</option>";
    }
}
?>
				</select>
		</div>
	</div>
	
	<div class="form-group">
		<div class="col-sm-offset-2 col-sm-10">
			<button id="submit" type="submit" class="btn btn-default">Submit</button>
		</div>
	</div>
 function getStudentsByClassId($class_id)
 {
     try {
         $db = DemoDB::getConnection();
         $sql = "SELECT * FROM Student WHERE class_id=:class_id";
         $stmt = $db->prepare($sql);
         $stmt->bindValue(":class_id", $class_id, PDO::PARAM_INT);
         $ok = $stmt->execute();
         $nb = $stmt->rowCount();
         $sbody = "{";
         if ($ok) {
             if ($nb == 0) {
                 $class_data = getClassData($_GET["class_id"]);
                 if (empty($class_data)) {
                     $this->exit_error(404, "class_idDoesNotExist");
                 }
             }
             if (isset($this->statusCode)) {
                 $this->statusCode = 200;
             }
             while ($row = $stmt->fetch(PDO::FETCH_ASSOC)) {
                 if ($row != null) {
                     if (isset($this->headers)) {
                         $this->headers[] = "Content-type: text/json; charset=utf-8";
                     }
                     // Produce utf8 encoded json
                     $sbody .= "\"" . $row["student_id"] . "\":" . json_encode($row) . ",";
                 } else {
                     $this->exit_error(404);
                 }
             }
             $sbody = rtrim($sbody, ",");
             $this->body = $sbody . "}";
         } else {
             $this->exit_error(500, print_r($db->errorInfo(), true));
         }
     } catch (PDOException $e) {
         $this->exit_error(500, $e->getMessage());
     }
 }