<?php
	class cCourseDetailPage extends cStudentPage
	{  	 
    function Process()
    {
      return true;
    }

		function Draw()
    {
      if ( !$this->bLoggedIn )
      {
        $this->smarty->display("login.tpl");
      }
      else
      {
	      $courseId = $this->getParams["itemId"];
	
				// vyber z databazy informacie o skuske...
	      $query = "SELECT C.name, C.description, C.questionCount, C.id_demoTest, S.ptsFull, S.ptsEmpty, S.ptsPartial, S.ptsBad, S.A, S.B, S.C, S.D, S.E 
									FROM tCourse AS C 
									INNER JOIN tCourseToUser AS CU ON CU.id_course = C.id 
									INNER JOIN tUser AS U ON U.id=CU.id_user
									INNER JOIN tScale AS S ON S.id=C.id_scale
									WHERE U.id='".$_SESSION['userId']."' AND C.id='$courseId';";
	      $this->AssignQueryResult($query,'course','noarray');
	
				// vyber z databazy zoznam terminov...
	      $query = "SELECT DISTINCT E.id AS examId, E.date, COALESCE(T.mark,'N/A') AS mark, E.state
									FROM tExam AS E 
									INNER JOIN tExamToUser AS EU ON EU.id_exam = E.id
									INNER JOIN tUser AS U ON U.id = EU.id_user
									INNER JOIN tCourseToUser AS CU ON U.id = CU.id_user
									LEFT JOIN tTest AS T ON (T.id_exam = E.id AND T.id_user = U.id)
									WHERE U.id = '".$_SESSION['userId']."' AND E.id_course = '$courseId' AND CU.id_course = '$courseId';";
	      $query = "SELECT E.id AS examId, E.date, COALESCE(T.mark,'N/A') AS mark, E.state
									FROM tExam AS E 
									INNER JOIN tExamToUser AS EU ON EU.id_exam = E.id
									INNER JOIN tUser AS U ON U.id = EU.id_user
									LEFT JOIN tTest AS T ON (T.id_exam = E.id AND T.id_user = U.id)
									WHERE U.id = '".$_SESSION['userId']."' AND E.id_course = '$courseId';";
				$this->AssignQueryResult($query,'exams','array');
	
				// vyber z databazy vysledne znamky...
	      $query = "SELECT MAX(E.date), T.mark 
									FROM tExam AS E 
									INNER JOIN tExamToUser AS EU ON EU.id_exam = E.id 
									INNER JOIN tUser AS U ON U.id = EU.id_user
									INNER JOIN tCourseToUser AS CU ON U.id = CU.id_user
									INNER JOIN tTest AS T ON (T.id_exam = E.id AND T.id_user = U.id)
									WHERE U.id = '".$_SESSION['userId']."' AND E.id_course = '$courseId' AND CU.id_course = '$courseId' AND E.state='finished'
									GROUP BY U.id;";
	      $this->AssignQueryResult($query,'finalMark','noarray');
	
	      $this->smarty->assign("content", "courseDetail.tpl");
	      parent::Draw();
	    }
    }
	}
?>
