<?php
class PagesController extends AppController {

	var $name = 'Pages';
	var $helpers = array('Html','Form', 'Time');
	var $uses = array();
	
	
	function beforeFilter() {
	  $this->Auth->allow('home', 'validate_emailaccess', 'logout_usr', 'refuse_emailaccess');
	  parent::beforeFilter();  
	}

 
	function display() {

	}


	function home() {
		$this->layout = 'home';	
	}
	
	
	function validate_emailaccess () {
		# First time the page is loaded - right after an Employee has been selected
		if (!empty($this->params['named']['f08n']) && !empty($this->params['named']['wtf']) && !empty($this->params['named']['udans'])) {	
			$eval_check = $this->params['named']['wtf'];
			$ana_usr = $this->params['named']['udans'];
			$emp_id = $this->params['named']['f08n'];			

			if ($ana_usr == '00c383efdccfff3c654bf5f91b4a12bd5ee2fe56') {
				$unhashedPw = 'ano77mous-ny';
				$usernamexz = 'usranony';
				
				# assuming $password is the clear text password
				$this->data['User']['password'] = $this->Auth->password($unhashedPw);
				$this->data['User']['username'] = $usernamexz;

				# do the login
				$login = $this->Auth->login($this->data);
				
				# $login is true is login went well. Now we can redirect the user to any page:
				if($login){

					#########################NEW FUNCTION USING FLASH HERE############################

					$this->flash('Sera redirigido(a) a su cuestionario en 5 segundos, o bien, presione AQUI </br></br>You will be redirected to your test in 5 seconds, please click HERE if your browser does not redirect you.','/employees/verify_empinfo/wtf:'.$eval_check.'/f08n:'.$emp_id, 5);

					############################ENDS HERE#########################

					//#####OLD LINE####$this->redirect('/employees/verify_empinfo/wtf:'.$eval_check.'/f08n:'.$emp_id); 
					########################################################################

				} else {				
					//echo 'not login';
				}
			} else {
			}
		}				
	}	
	
	
	function refuse_emailaccess () {
		if (!empty($this->params['named']['f08n']) && !empty($this->params['named']['ouqstapw']) && !empty($this->params['named']['udans'])) {	
			$eval_check = $this->params['named']['ouqstapw'];
			$ana_usr = $this->params['named']['udans'];
			$emp_id = $this->params['named']['f08n'];			

			if ($ana_usr == '00c383efdccfff3c654bf5f91b4a12bd5ee2fe56') {
				$unhashedPw = 'ano77mous-ny';
				$usernamexz = 'usranony';
				# assuming $password is the clear text password
				$this->data['User']['password'] = $this->Auth->password($unhashedPw);
				$this->data['User']['username'] = $usernamexz;

				# do the login
				$login = $this->Auth->login($this->data);
				
				# $login is true is login went well.Now we can redirect the user to any page:
				if($login){
				# echo 'login-ok';

					#########################NEW FUNCTION USING FLASH HERE############################

					$this->flash('Please follow THIS link to refuse your test | Suivez CE LIEN pour annuler votre test','/evaluations/refuse_test/ouqstapw:'.$eval_check.'/f08n:'.$emp_id); 

					############################ENDS HERE#########################

				} else {				
				//echo 'not login';	
				}
			} else {
			}		
		}				
	}	
	
	
	function logout_usr () {

		# do the logout
		$logout = $this->Auth->logout();
		
		if($logout){
			$messageString = __('La información fué procesada, gracias.', true); 
		} else {				
			$messageError = __('Error de fin de sesión.', true); 
		}			
		$this->set(compact('messageString'));	
	}	
	
	
	function data_mngt() {
       // $this->layout = 'main_index';

	}
	
	function tables_mngt() {
		//$this->layout = 'default';
	}

	
	function quest_forms() {
	
	}	
	
	
	function interp_tables() {

	}	
	
	
	function report() {

	}		
}
?>