<?php

error_reporting(E_ALL ^ E_DEPRECATED);
date_default_timezone_set('Indian/Maldives');
require_once '../config.php';
require_once BASE_PATH . '/login_handler.php';
require_once BASE_PATH . '/medoo.min.php';
//check login status
$login = new LoginHandler($config);
if (!$login->is_logged_in()) {
    $login->redirect_login('Please login');
}
if ($login->get_user_type() != 'prof') {
    $login->not_authorized_error();
}
if (isset($_GET['operation'])) {
    header('Content-Type: text/csv; charset=utf-8');
    header('Content-Disposition: attachment; filename=' . date('j\\-m\\-Y\\-\\f\\e\\e\\d\\b\\a\\c\\k') . '.csv');
    $con = mysql_connect($config['db']['server'], $config['db']['username'], $config['db']['password']);
    //change configs
    $db = mysql_select_db($config['db']['database_name'], $con);
    //change database
    $c_id = $_GET['courseid'];
    $result = mysql_query("SELECT * FROM questions WHERE courseid='{$c_id}'") or die(mysql_error());
    $t = 0;
    while ($row = mysql_fetch_array($result)) {
        $question[] = $row['question'];
        $q_id[] = $row['q_id'];
        $type[] = $row['type'];
        $t++;
    }