<?php
/**
* Copyright (C) 2004 - 2006, John Tarlton.
*
* This file is part of AstWebPanel - A web management user interface for Asterisk.
*
* AstWebPanel is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License version 2 as
* published by the Free Software Foundation. See the LICENSE file distributed
* with AstWebPanel.
*
* Database access object.
*/
require_once('./php/dbase.php');
/* Database access object for the 'sessionlog' table
*/
class SessionLog
{
var $rows;
var $numrows;
/* $start, $end are timestamps in the format: 'YYYY-MM-DD HH24:MI:SS'
*/
function get($start, $end, $user)
{
global $db;
$query = "SELECT to_char(time, 'YYYY-MM-DD HH24:MI:SS') AS strtime, username, action FROM sessionlog WHERE time >= '$start' AND time < '$end' AND username LIKE '$user%'";
$this->rows = $db->query($query);
$this->numrows = $this->rows->numRows();
}
function getLastLogin($username)
{
global $db;
$query = "SELECT to_char(time, 'YYYY-MM-DD HH24:MI:SS') AS strtime
FROM sessionlog
WHERE username = ? AND action LIKE 'Login%' ORDER BY time DESC LIMIT 1 OFFSET 1";
$stmt = $db->prepare($query);
$querydata = array($username);
$result = $db->execute($stmt, $querydata);
if ( $result->numRows() == 1 )
{
$row = $result->fetchRow();
return $row['strtime'];
}
return '';
}
function update($username, $action)
{
global $db;
$query = "INSERT INTO sessionlog (username, action) VALUES (?, ?)";
$stmt = $db->prepare($query);
$querydata = array($username, $action);
$result = $db->execute($stmt, $querydata);
return DB::isError ($result);
}
}
?>