<?php
/**
 * Open Source - Content Managment System
 * Next Generation v2
 * @Coder:  Mutzii
 * @copyright  Copyright (c) 2012-2013 by Mutzii
 * File: login.class.php
 * @Description: Login API

 */ 
class login
{
	  	public $sid;
		public $sname;
	   
	   public function start()
	   {
	     session_start();
		 
		 if(!$this->login()){
		    $_SESSION['gast'] = true;
         }		 
	   }
       
		
      public function session_login($nickname,$loginstatus) // Neue Session Erstellen
	   {		   
		  $this->sid   = session_id();
		  $this->sname = session_name();
		  
		   // Administrator
		   if($loginstatus == 1){
		   $_SESSION['admin'] = true;
		   $_SESSION['gast'] = false;
		   }
		   // Moderator
		   if($loginstatus == 2){
		   $_SESSION['mod'] = true;
		   $_SESSION['gast'] = false;
		   }
		   // Member
		   if($loginstatus == 3){
		   $_SESSION['user'] = true;
		   $_SESSION['gast'] = false;	
		   }	
                // Kunde 	
		   if($loginstatus == 4){
		   $_SESSION['kunde'] = true;
		   $_SESSION['gast'] = false;
		   }
			

		  
		    $_SESSION['username'] = $nickname;
		    $_SESSION['login']    = true;
	  	  		  
	   }
	   
	   public function login()
	   {
	      if(isset($_SESSION['login']) && $_SESSION['login'] == true)
		  {
             return true;
		  }else{
		     return false;
		  }
  	   
	   }
	   
	   
	   public function check_login()
	   {
	       if(isset($_SESSION['admin'])) {
		        return 1;
		   }
           if(isset($_SESSION['mod'])) {
		        return 2;
		   }		   
	       if(isset($_SESSION['user'])) {
		        return 3;
		   }
		   if(isset($_SESSION['kunde'])) {
		        return 4;
		   }
		   if(isset($_SESSION['gast'])) {
		        return 5;
		   }				     
	   }
	      
	   public function reload()
	   {     
          echo '<script type="text/javascript" language="JavaScript">  window.location.reload(); </script>';	   		  	   
	   }
	   
	   public function refresh()
	   {
	    echo '
	      <script type="text/javascript">
                     window.location.href = "?overlay=index";    
          </script>
	     ';
	   }
	   
	   public function logout()
	   {
	     session_destroy();
	   }
	  	   
	   public function print_sid()
	   {
	      echo $this->sid;
	   }
	   
	   public function PrintUser()
	   {
	      if(isset($_SESSION['username'])){
	        return $_SESSION['username'];
		  }
	   }


}
?>
