<?php
	class cMainPage extends cStudentPage
	{
    	 
    function __construct( $smarty, $db, $action, $postParams, $getParams )
    {
      parent::__construct( $smarty, $db, $action, $postParams, $getParams );
      $this->smarty->assign('badLogin',false);
    }
		
    function Process()
    {
      if ( $this->action === "login" )
      {
        $login=$this->postParams["login"];
        $password=$this->postParams["password"];
        $query = "SELECT U.id, U.name, U.surname FROM tUser AS U, tStudents AS S WHERE U.id = S.id AND ".
                 "U.login='".$this->postParams["login"]."' AND ".
                 "U.password=MD5(CONCAT(U.passPrefix,'".$this->postParams["password"]."'));";
        
				$result = $this->db->QueryToRow($query);
        if ( $result != 0 )                                         
        {
          $_SESSION["userId"] = $result["id"];
          $_SESSION["userType"] = "student";
          $_SESSION["userFullName"] = $result["surname"]." ".$result["name"];
          $this->bLoggedIn = true;
        }
        else
        {
          $this->smarty->assign('badLogin',true);
        }
      }
      else if ( $this->action === "logout" )
      {
          unset( $_SESSION["userId"] );
          unset( $_SESSION["userType"] );
          unset( $_SESSION["userFullName"] );
          $this->bLoggedIn = false;
      }
      return true;
    }
    
    function Draw()
    {
      $this->smarty->assign("content","home.tpl");
      parent::Draw();
    }
	}
?>
