1<?php
2	/**************************************************************************\
3	* phpGroupWare - Administration                                            *
4	* http://www.phpgroupware.org                                              *
5	* --------------------------------------------                             *
6	*  This program is free software; you can redistribute it and/or modify it *
7	*  under the terms of the GNU General Public License as published by the   *
8	*  Free Software Foundation; either version 2 of the License, or (at your  *
9	*  option) any later version.                                              *
10	\**************************************************************************/
11
12	/* $Id: class.soaccess_history.inc.php 16695 2006-04-24 15:35:29Z skwashd $ */
13
14	class soaccess_history
15	{
16		var $db;
17
18		function soaccess_history()
19		{
20			$this->db =& $GLOBALS['phpgw']->db;
21		}
22
23		function test_account_id($account_id)
24		{
25			$account_id = (int)$account_id;
26			if ($account_id)
27			{
28				return " WHERE account_id = $account_id";
29			}
30		}
31
32		function list_history($account_id,$start,$order,$sort)
33		{
34			$where = $this->test_account_id($account_id);
35
36			$this->db->limit_query("SELECT loginid,ip,li,lo,account_id,sessionid FROM phpgw_access_log $where ORDER BY li desc",$start,__LINE__,__FILE__);
37			while ($this->db->next_record())
38			{
39				$records[] = array(
40					'loginid'    => $this->db->f('loginid'),
41					'ip'         => $this->db->f('ip'),
42					'li'         => $this->db->f('li'),
43					'lo'         => $this->db->f('lo'),
44					'account_id' => $this->db->f('account_id'),
45					'sessionid'  => $this->db->f('sessionid')
46				);
47			}
48			return $records;
49		}
50
51		function total($account_id)
52		{
53			$where = $this->test_account_id($account_id);
54
55			$this->db->query("SELECT COUNT(*) from phpgw_access_log $where", __LINE__, __FILE__);
56			$this->db->next_record();
57
58			return $this->db->f(0);
59		}
60
61		function return_logged_out()
62		{
63			$this->db->query("SELECT COUNT(*) FROM phpgw_access_log WHERE lo !=0", __LINE__, __FILE__);
64			$this->db->next_record();
65
66			return $this->db->f(0);
67		}
68	}
69