<?php
include("../../db.php");
header('Content-Type: application/json');

$session = $_REQUEST['session'];
$assignment_id = $_REQUEST['assignment_id'];

$allFiles = array();
$status = 0;
$msg = 'Info needed...!';

$parentPath = "https://" . $_SERVER['HTTP_HOST'] . "/uploads/";

if (($session != null && $session != '') && ($assignment_id != null && $assignment_id != '')) {
    $allFiles = $db->getRows("SELECT * FROM assignment_files WHERE assignment_id = '$assignment_id' AND session = '$session'");

    foreach ($allFiles as $key => $value){
        $allFiles[$key]['file_path'] = getPath($value['type'], $value['name']);
    }

    $status = 1;
    $msg = 'Query executed';
}

echo json_encode(array("status" => "$status", "data" => $allFiles, "msg" => $msg));


function getPath($type, $file)
{
    global $parentPath;

    switch ($type) {
        case "key_terms": return $parentPath."keyterms/".$file;

        case "mind_map": return $parentPath."mindmap/".$file;

        case "key_notes": return $parentPath."keynotes/".$file;

        case "practical_projects": return $parentPath."practicalprojects/".$file;

        case "youtube_link": return $file;

        default: return "";
    }
}