<?php

	//include the cooltoolloader
	include('../core/config.php');
	
	//Proccess Login
	if(count($_POST)){
		$username = isset($_POST['username']) ? $_POST['username'] : false;
		$password = isset($_POST['password']) ? $_POST['password'] : false;
		$auto = isset($_POST['auto']) ? $_POST['auto'] : false;
		
		$user->login($username,$password,$auto);
		if($user->has_error()){
			$_SESSION['ErrorMsgs'] = $user->error();
			redirect($user->page_rel_path ."?page=login");
		} else {
			//always create unique sessionIds after a true login
			session_regenerate_id();
			//initiate an ec2 instance
			//upon sucessful login update uctivity table with initial activity
			//include the php-mysqli class
			include('../../PHP-MySQLi/MysqliDb.php');
			$insertData = array(
   				 'user_id' => $user->data['user_id'],
				 'login_time' => date("Y-m-d H:i:s"),
				 'last_ping_time' => date("Y-m-d H:i:s"),
				 'session_id' => session_id()
			);
			
			//create a new db object
			$db_uam = new Mysqlidb($settings['db']['dns'],$settings['db']['user'], $settings['db']['pass'], $settings['db']['name']);
			$db_uam->insert('usr_activity', $insertData);
			redirect($user->page_rel_path ."?page=instr");
		}
	} else {
		
		redirect($user->page_rel_path ."?page=login");	
	}
	
?>
