Location: PHPKode > projects > O - OpenSource GroupWare > osgw/osgw/classes/class.tracker.php
<?php
/**************************************************************************
   This program is free software; you can redistribute it and/or modify
   it under the terms of the GNU General Public License as published by
   the Free Software Foundation; either version 2 of the License, or
   (at your option) any later version.

   @Authors:	Ryan Thompson(hide@address.com)
***************************************************************************/

class tracker
{
	function create_tracker($user_id)
	{
		GLOBAL $O, $db;
	
		$time = time();
		$sql = "INSERT INTO o_tracker (user_id, last_action, last_action_time)
			VALUES('$user_id','Account Created','$time')";
		$db->query($sql);

	}

	function create_user_security($user_id)
	{
		GLOBAL $O, $db;
		$time = time();
		$sql = "INSERT INTO o_user_security (user_id, password_change, password_expire, expire_type) 
			VALUES ($user_id, $time, 356, 'days')";
		$db->query($sql);
	}
	
	
	function login_fail($username)
	{
		GLOBAL $O, $db;
		$sql = "SELECT o_user_security.* FROM o_user_security 
			LEFT JOIN o_users ON o_users.user_id=o_user_security.user_id WHERE o_users.username='$username'";
		$db->query($sql);
		$db->fetch_results();
		$time = time();
		$values = $db->record;
		$con_fails = $values['consecutive_fails']+1;
		$total_fails = $values['failed_logins']+1;

		$sql_tmp = "UPDATE o_user_security SET failed_logins='$total_fails',
			consecutive_fails='$con_fails',last_fail='$time'";
		
		$sql = "SELECT value FROM o_settings WHERE setting_id='4'";
		$db->query($sql);
		$db->fetch_results();
		if($values['consecutive_fails'] >= $db->record['value'])
		{
			$sql_tmp .= ",disabled='$time'";
		}

		$sql_tmp .= "WHERE user_id='$values[user_id]'";

		$db->query($sql_tmp);

	}

	function login_success($user_id)
	{
		GLOBAL $O, $db, $user;
		$browser = $user->get_user_agent();
		$ip_address = $user->get_user_ip();
		$time = time();
		$last_action = "Login";
		
		
		$sql = "UPDATE o_tracker SET last_login='$time',browser='$browser',
			ip_address='$ip_address',last_action='$last_action',
			last_action_time='$time' WHERE user_id='$user_id'";
		$db->query($sql);
		
		$sql = "SELECT total_login FROM o_user_security WHERE user_id='$user_id'";
		$db->query($sql);
		$db->fetch_results();

		$total_logins = $db->record['total_login'] + 1;


		$sql = "UPDATE o_user_security SET total_login='$total_logins', consecutive_fails='0' WHERE user_id='$user_id'";
		$db->query($sql);
		return TRUE;
	}
	
	function update_tracker($location, $user_id)
	{
		GLOBAL $O, $db;
		$now = time();
		$location = $_SERVER['SCRIPT_NAME'];
		$sql = "UPDATE o_tracker SET last_action='$location', last_action_time='$now' WHERE user_id='$user_id'";
		$db->query($sql);
	}
		
}

?>
Return current item: O - OpenSource GroupWare