<?php
	class cCourseInformationPage extends cTeacherPage
	{
    	 
    function __construct( $smarty, $db, $action, $postParams, $getParams )
    {
      parent::__construct( $smarty, $db, $action, $postParams, $getParams );
      $this->menu=new cCourseTeacherMenu;
      if (isset($this->getParams["courseID"]) && ($this->getParams["courseID"]!=="")) 
      {
        $this->menu->GenerateMenu("&amp;courseID=".$this->getParams["courseID"]);
      }
      else
      {
        $this->menu->GenerateMenu("");
      }
      $menuItem=$this->menu->GetItemByLabel("info o predmete");
      $menuItem->bSelected=true;
    }
		
    function Process()
    {
      if ($this->bLoggedInAsTeacher && ($this->IsTeacherToCourse())) 
      {
        if ($this->action==="save")
        {
          $this->getParams["courseID"]=mysql_real_escape_string($this->getParams["courseID"]);
          if (isset($this->postParams["description"]) && ($this->postParams["description"]!=="") &&
              isset($this->postParams["duration"]) && ($this->postParams["duration"]!=="")) 
          {
            $this->postParams["description"]=mysql_real_escape_string($this->postParams["description"]);
            $this->postParams["duration"]=mysql_real_escape_string($this->postParams["duration"]);
            $query = "UPDATE tCourse SET description='".htmlspecialchars($this->postParams["description"])."', ".
                     "duration=".$this->postParams["duration"]." WHERE id=".$this->getParams["courseID"].";";
            
            $result = $this->db->Query($query);
            if ( $result )
            {
              $this->smarty->assign("saved", true);
            }
          }
        }
      }
      return true;
    }
    
    function Draw()
    {
      if ($this->bLoggedInAsTeacher && ($this->IsTeacherToCourse())) 
      {
        if (isset($this->getParams["courseID"]) && ($this->getParams["courseID"]!=="")) 
        {
          $this->getParams["courseID"]=mysql_real_escape_string($this->getParams["courseID"]);
          $query = "SELECT tC.name, tC.description, tC.duration FROM tCourse AS tC ".
                   "WHERE tC.id=".$this->getParams["courseID"].";";
          
          $result = $this->db->QueryToRow($query);
          if ( $result != 0 )
          {
            $this->smarty->assign("description", $result);
            $this->smarty->assign("courseID", $this->getParams["courseID"]);
          }
        }
      }
      else
      {
        $this->bAccessDenied=true;
      }
      $this->smarty->assign("course", $this->CourseName());
      $this->smarty->assign("content","courseInformation.tpl");
      parent::Draw();
    }
	}
?>
