<?php

/**
 * Call Center Home
 */

Slim::get('/',function() {
	redir_by_id("user_login");
})->name('index');

/**
 * user login
 */

Slim::get('/user/',function() {
	if (User::is_login()) {
		if ($_SESSION['user']['role'] == "management") {
			redir_by_id("admin_home");
		} else {
			redir_by_id($_SESSION['user']['role'] . "_home");
		}
		die();
	}
	Slim::render("user/login.html");
})->name('user_login');

Slim::post('/user/',function() {
	if (User::login($_POST['username'],$_POST['password'])) {
		// if ($_POST['role'] != "inbound" || $_POST['role'] != "management") {	/* reset chat state */
			// $d = ChatSession::getByUser($_SESSION['user']['id']);
			// if ($d != null) {
				// ChatSession::update($d['id'],array(
					// "chat_state"=>"1;1;1;1;1;0",
					// "chat_with"=>0
				// ));
			// } else {
				// ChatSession::create(array(
					// "id_user"=>$_SESSION['user']['id'],
					// "chat_state"=>"1;1;1;1;1;0"
				// );
			// }
		// }
		// if ($_POST['role'] == "management") {
			// redir_by_id('admin_home');
		// } else {
			redir_by_id($_SESSION['user']['role'].'_home');
		// }
	} else {
		Slim::flash("error","user atau password salah!");
		redir_by_id('user_login');
	}
});

/**
 * user logout
 */

Slim::get('/logout',function() {
	// if (User::is_login()) {
		// if ($_SESSION['user']['role'] == "inbound" || $_SESSION['user']['role'] == "outbound") {
			// AbsenAgent::create(array(
				// "id_agent"=>$_SESSION['user']['id'],
				// "role"=>$_SESSION['user']['role'],
				// "date"=>time(),
				// "activity"=>"logout"
			// ));
		// }
	// }
	User::logout();
	redir_by_id('user_login');
})->name('user_logout');

?>
