<?php defined('SYSPATH') or die('No direct script access.');

class Controller_Profile extends Controller {

	public function action_index(){
		if(Auth::instance()->get_user()){
			$view = View::factory("profile");
			$this->request->response = $view;
			//Request::instance()->redirect("main/act");
		}
		else
			Request::instance()->redirect("");
	}
		
	public function action_change_settings(){
		if(Auth::instance()->get_user()){
			
			#Allow only users to see change email page
			$view  = View::factory("settings");
			$this->request->response = $view;
		}
		else
			Request::instance()->redirect("");
	}
	
	public function action_info(){
		$me = Auth::instance()->get_user();
		if($me){
			
			#Allow only users to see change email page
			$department_model 	= Model::factory('department');
			$university_model 	= Model::factory('university');
		    
			$universities_arr 	= $university_model->getUniversities();
			$departments_arr  	= $department_model->getDepartments();
		    
			$data = array(
				    "universities_arr" 	=> $universities_arr,
				    "departments_arr"	=> $departments_arr);
			
			$view = View::factory("information", $data);
			$this->request->response = $view;
		}
		else
			Request::instance()->redirect("");
	}
	
	public function action_change_info(){
		$me = Auth::instance()->get_user();
		#Allow only users to see change email page
		if($me){
			if($_POST){
				$me->university_id = $_POST['university'];
				$me->department_id = $_POST['department'];
				$me->save();
				$this->action_info();
			}
			else
				Request::instance()->redirect("");
		}
		else
			Request::instance()->redirect("");
	}
}