<?php
	class cEvaluationPage 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("testy");
      $menuItem->bExpanded=true;
      $menuItem=$menuItem->GetItemByLabel("hodnotenie");
      $menuItem->bSelected=true;
    }
		
    function Process()
    {
      if ($this->bLoggedInAsTeacher && ($this->IsTeacherToCourse())) 
      {
        if ($this->action==="saveChanges")
        {
          $this->getParams["courseID"]=mysql_real_escape_string($this->getParams["courseID"]);
          $query = "SELECT tS.id FROM tScale AS tS, tCourse AS tC ".
                   "WHERE tS.id=tC.id_scale AND tC.id=".$this->getParams["courseID"].";";
          
          $result = $this->db->QueryToRow($query);
          if ( $result != 0 )
          {
            $this->postParams["ptsFull"]=mysql_real_escape_string($this->postParams["ptsFull"]);
            $this->postParams["ptsEmpty"]=mysql_real_escape_string($this->postParams["ptsEmpty"]);
            $this->postParams["ptsPartial"]=mysql_real_escape_string($this->postParams["ptsPartial"]);
            $this->postParams["ptsBad"]=mysql_real_escape_string($this->postParams["ptsBad"]);
            $this->postParams["A"]=mysql_real_escape_string($this->postParams["A"]);
            $this->postParams["B"]=mysql_real_escape_string($this->postParams["B"]);
            $this->postParams["C"]=mysql_real_escape_string($this->postParams["C"]);
            $this->postParams["D"]=mysql_real_escape_string($this->postParams["D"]);
            $this->postParams["E"]=mysql_real_escape_string($this->postParams["E"]);
            $query2 = "UPDATE tScale SET ptsFull=".$this->postParams["ptsFull"].", ".
                      "ptsEmpty=".$this->postParams["ptsEmpty"].", ".
                      "ptsPartial=".$this->postParams["ptsPartial"].", ".
                      "ptsBad=".$this->postParams["ptsBad"].", ".
                      "A=".$this->postParams["A"].", ".
                      "B=".$this->postParams["B"].", ".
                      "C=".$this->postParams["C"].", ".
                      "D=".$this->postParams["D"].", ".
                      "E=".$this->postParams["E"]." ".
                      "WHERE id=".$result["id"].";";
                     
            $result2=$this->db->Query($query2);
            if ($result2!=0) {
              $this->smarty->assign("changesSaved", 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 tS.* FROM tScale AS tS, tCourse AS tC ".
                   "WHERE tS.id=tC.id_scale AND tC.id=".$this->getParams["courseID"].";";
          
          $result = $this->db->QueryToRow($query);
          if ( $result != 0 )
          {
            $this->smarty->assign("scale", $result);
          }
          $this->smarty->assign("courseID", $this->getParams["courseID"]);
        }
      }
      else
      {
        $this->bAccessDenied=true;
      }
      $this->smarty->assign("course", $this->CourseName());
      $this->smarty->assign("content","evaluation.tpl");
      parent::Draw();
    }
	}
?>
