<?php
	class cMainPage extends cAdminPage
	{
    	 
    function __construct( $smarty, $db, $action, $post, $get  )
    {
      parent::__construct( $smarty, $db, $action, $post, $get  );
      $this->smarty->assign('badLogin',false);
    }
		
    function Process()
    {
      if ( $this->action === "login" )
      {
        $query = "SELECT tU.id FROM tUser AS tU, tAdmins AS tA WHERE tU.id = tA.id AND ".
                 "tU.login='".$this->postParams["login"]."' AND ".
                 "tU.password=MD5(CONCAT(tU.passPrefix,'".$this->postParams["password"]."'));";
        
        $result = $this->db->QueryToRow($query);
        if ( $result != 0 )
        {
          $_SESSION["userID"] = $result["id"];
          $_SESSION["userType"] = "admin";
          $this->bLoggedIn = true;
        }
        else
        {
          $this->smarty->assign('error',"Zadali ste nesprávne prihlasovacie údaje!");
        }
      }
      else if ( $this->action === "logout" )
      {
          unset( $_SESSION["userID"] );
          unset( $_SESSION["userType"] );
          $this->bLoggedIn = false;
      }
      return true;
    }
    
    function Draw()
    {
      $this->smarty->assign("title", "Úvodná stránka");
      $this->smarty->assign("content","home.tpl");
      parent::Draw();
    }
	}
?>
