From c2ef7ba6acceac38e17bf435ccb7bcab182bdbb1 Mon Sep 17 00:00:00 2001 From: x2000habouzit Date: Mon, 31 Jul 2006 19:00:07 +0000 Subject: [PATCH] simplifications git-svn-id: svn+ssh://murphy/home/svn/platal/trunk@753 839d8a87-29fc-0310-9880-83ba4fa771e5 --- classes/CoreLogger.php | 20 ++-------- classes/LoggerView.php | 83 +++++++++++---------------------------- include/platal/globals.inc.php.in | 8 ---- templates/logger-view.tpl | 9 ++--- 4 files changed, 31 insertions(+), 89 deletions(-) diff --git a/classes/CoreLogger.php b/classes/CoreLogger.php index 49d2ce5..13df881 100644 --- a/classes/CoreLogger.php +++ b/classes/CoreLogger.php @@ -30,13 +30,6 @@ class CoreLogger { /** list of available actions */ var $actions; - /** db table holding the list of actions */ - var $table_actions; - /** db table holding the list of actions */ - var $table_events; - /** db table holding the list of actions */ - var $table_sessions; - /** The constructor, creates a new entry in the sessions table * * @param $uid the id of the logged user @@ -46,13 +39,6 @@ class CoreLogger { * @return VOID */ function CoreLogger($uid, $suid='', $auth='', $sauth='') { - global $globals; - - // read database table names from globals - $this->table_actions = $globals->table_log_actions; - $this->table_events = $globals->table_log_events; - $this->table_sessions = $globals->table_log_sessions; - // write the session entry $this->uid = $uid; $this->session = $this->writeSession($uid, $suid, $auth, $sauth); @@ -74,7 +60,7 @@ class CoreLogger { $ip = $_SERVER['REMOTE_ADDR']; $host = strtolower(gethostbyaddr($_SERVER['REMOTE_ADDR'])); $browser = (isset($_SERVER['HTTP_USER_AGENT']) ? $_SERVER['HTTP_USER_AGENT'] : ''); - $sql = "insert into {$this->table_sessions} set uid='$uid', host='$host', ip='$ip', browser='$browser'"; + $sql = "insert into logger.sessions set uid='$uid', host='$host', ip='$ip', browser='$browser'"; // optional parameters if ($suid) $sql .= ", suid='$suid'"; @@ -94,7 +80,7 @@ class CoreLogger { * @return actions the available actions */ function readActions() { - $res = XDB::iterRow("select id, text from {$this->table_actions}"); + $res = XDB::iterRow("select id, text from logger.actions"); while (list($action_id, $action_text) = $res->next()) { $actions[$action_text] = $action_id; @@ -112,7 +98,7 @@ class CoreLogger { */ function log($action, $data="") { if (isset($this->actions[$action])) { - XDB::execute("insert into {$this->table_events} + XDB::execute("insert into logger.events set session={?}, action={?}, data={?}", $this->session, $this->actions[$action], $data); } else { diff --git a/classes/LoggerView.php b/classes/LoggerView.php index b0d1967..86a55d7 100644 --- a/classes/LoggerView.php +++ b/classes/LoggerView.php @@ -18,12 +18,6 @@ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ - -/** A class for viewing user activity. - * Allows the examination of user sessions. Can produce a list of sessions - * matching by date, user, or authentication method, and can drill down to - * a detailed list of actions performed in a session. - */ class LoggerView { /** Retrieves the available days for a given year and month. * Obtain a list of days of the given month in the given year @@ -36,18 +30,17 @@ class LoggerView { */ function _getDays($year, $month) { - global $globals; - // give a 'no filter' option $months[0] = "----"; if ($year && $month) { - $day_max = Array(-1, 31, checkdate(2, 29, $year) ? 29 : 28 , 31, 30, 31, 30, 31, 31, 30, 31, 30, 31); + $day_max = Array(-1, 31, checkdate(2, 29, $year) ? 29 : 28 , 31, + 30, 31, 30, 31, 31, 30, 31, 30, 31); $res = XDB::query("SELECT YEAR (MAX(start)), YEAR (MIN(start)), MONTH(MAX(start)), MONTH(MIN(start)), DAYOFMONTH(MAX(start)), DAYOFMONTH(MIN(start)) - FROM {$globals->table_log_sessions}"); + FROM logger.sessions"); list($ymax, $ymin, $mmax, $mmin, $dmax, $dmin) = $res->fetchOneRow(); if (($year < $ymin) || ($year == $ymin && $month < $mmin)) { @@ -79,15 +72,13 @@ class LoggerView { */ function _getMonths($year) { - global $globals; - // give a 'no filter' option $months[0] = "----"; if ($year) { $res = XDB::query("SELECT YEAR (MAX(start)), YEAR (MIN(start)), MONTH(MAX(start)), MONTH(MIN(start)) - FROM {$globals->table_log_sessions}"); + FROM logger.sessions"); list($ymax, $ymin, $mmax, $mmin) = $res->fetchOneRow(); if (($year < $ymin) || ($year > $ymax)) { @@ -112,17 +103,16 @@ class LoggerView { * @return the matching username. * @private */ - function _getUsername($auth, $uid) { - global $globals; + function _getUsername($uid) { static $cache; - if (!isset($cache[$auth][$uid])) { + if (!isset($cache[$uid])) { $res = XDB::query('SELECT alias FROM aliases WHERE id = {?} AND type="a_vie"', $uid); - $cache[$auth][$uid] = $res->fetchOneCell(); + $cache[$uid] = $res->fetchOneCell(); } - return $cache[$auth][$uid]; + return $cache[$uid]; } @@ -134,13 +124,11 @@ class LoggerView { */ function _getYears() { - global $globals; - // give a 'no filter' option $years[0] = "----"; // retrieve available years - $res = XDB::query("select YEAR(MAX(start)), YEAR(MIN(start)) FROM {$globals->table_log_sessions}"); + $res = XDB::query("select YEAR(MAX(start)), YEAR(MIN(start)) FROM logger.sessions"); list($max, $min) = $res->fetchOneRow(); for($i = intval($min); $i<=$max; $i++) { @@ -156,20 +144,16 @@ class LoggerView { * @param $year INTEGER Only get log entries made during the given year. * @param $month INTEGER Only get log entries made during the given month. * @param $day INTEGER Only get log entries made during the given day. - * @param $auth INTEGER Only get log entries with the given authentication type. * @param $uid INTEGER Only get log entries referring to the given user ID. * * @return STRING the WHERE clause of a query, including the 'WHERE' keyword * @private */ - function _makeWhere($year, $month, $day, $auth, $uid) + function _makeWhere($year, $month, $day, $uid) { // start constructing the "where" clause $where = array(); - if ($auth) - array_push($where, "auth='$auth'"); - if ($uid) array_push($where, "uid='$uid'"); @@ -201,31 +185,27 @@ class LoggerView { /** Run the log viewer and fill out the Smarty variables for display. * * @param page the page that will display the viewer's data - * @param outputvar the Smarty variable to which we should assign the output - * @param template the template to use for display */ - function run(&$page, $outputvar='', $template='') + function run(&$page) { - global $globals; - if (isset($_REQUEST['logsess'])) { // we are viewing a session - $res = XDB::query("SELECT host, ip, browser, auth, uid, sauth, suid - FROM {$globals->table_log_sessions} + $res = XDB::query("SELECT host, ip, browser, uid, suid + FROM logger.sessions WHERE id =".$_REQUEST['logsess']); $sarr = $res->fetchOneAssoc(); - $sarr['username'] = $this->_getUsername($sarr['auth'], $sarr['uid']); + $sarr['username'] = $this->_getUsername($sarr['uid']); if ($sarr['suid']) { - $sarr['suer'] = $this->_getUsername($sarr['sauth'], $sarr['suid']); + $sarr['suer'] = $this->_getUsername($sarr['suid']); } $page->assign('session', $sarr); $res = XDB::iterator("SELECT a.text, e.data, UNIX_TIMESTAMP(e.stamp) AS stamp - FROM {$globals->table_log_events} AS e - LEFT JOIN {$globals->table_log_actions} AS a ON e.action=a.id + FROM logger.events AS e + LEFT JOIN logger.actions AS a ON e.action=a.id WHERE e.session='{$_REQUEST['logsess']}'"); while ($myarr = $res->next()) { $page->append('events', $myarr); @@ -234,7 +214,6 @@ class LoggerView { } else { // we are browsing the available sessions - $logauth = isset($_REQUEST['logauth']) ? $_REQUEST['logauth'] : ''; $loguser = isset($_REQUEST['loguser']) ? $_REQUEST['loguser'] : ''; $res = XDB::query('SELECT id FROM aliases WHERE alias={?}', @@ -267,41 +246,32 @@ class LoggerView { $page->assign('days', $this->_getDays($year, $month)); $page->assign('day', $day); - // retrieve available auths - $auths = array('all', 'native' => 'X.org'); - $page->assign('auths', $auths); - - $page->assign('logauth', $logauth); $page->assign('loguser', $loguser); // smarty assignments if ($loguid || $year) { // get the requested sessions - $where = $this->_makeWhere($year, $month, $day, $logauth, $loguid); - $select = "SELECT id, UNIX_TIMESTAMP(start) as start, auth, uid - FROM {$globals->table_log_sessions} AS s + $where = $this->_makeWhere($year, $month, $day, $loguid); + $select = "SELECT id, UNIX_TIMESTAMP(start) as start, uid + FROM logger.sessions AS s $where ORDER BY start DESC"; $res = XDB::iterator($select); $sessions = array(); while ($mysess = $res->next()) { - $mysess['username'] = $this->_getUsername($mysess['auth'], $mysess['uid']); - // pretty label for auth method - $mysess['lauth'] = $auths[$mysess['auth']]; - // summary of events + $mysess['username'] = $this->_getUsername($mysess['uid']); $mysess['events'] = array(); - $sessions[$mysess['id']] = $mysess; } array_reverse($sessions); // attach events $sql = "SELECT s.id, a.text - FROM {$globals->table_log_sessions} AS s - LEFT JOIN {$globals->table_log_events} AS e ON(e.session=s.id) - INNER JOIN {$globals->table_log_actions} AS a ON(a.id=e.action) + FROM logger.sessions AS s + LEFT JOIN logger.events AS e ON(e.session=s.id) + INNER JOIN logger.actions AS a ON(a.id=e.action) $where"; $res = XDB::iterator($sql); @@ -314,11 +284,6 @@ class LoggerView { } } - // if requested, assign the content to be displayed - if (!empty($outputvar)) { - $page->assign($outputvar, $page->fetch($template)); - } - $page->changeTpl('logger-view.tpl'); } diff --git a/include/platal/globals.inc.php.in b/include/platal/globals.inc.php.in index 660176e..adf834d 100644 --- a/include/platal/globals.inc.php.in +++ b/include/platal/globals.inc.php.in @@ -41,17 +41,9 @@ class PlatalGlobals var $dbuser = 'x4dat'; var $dbpwd = 'x4dat'; - var $table_log_actions = 'logger.actions'; - var $table_log_sessions = 'logger.sessions'; - var $table_log_events = 'logger.events'; - /** The class to use for session handling. */ var $session = 'DiogenesCoreSession'; - /** logger */ - var $tauth = array('native'=>'auth_user_md5'); - var $tlabel = array('native'=>'X.Org'); - /** paths */ var $baseurl; var $spoolroot; diff --git a/templates/logger-view.tpl b/templates/logger-view.tpl index 34a40b5..496616c 100644 --- a/templates/logger-view.tpl +++ b/templates/logger-view.tpl @@ -31,7 +31,7 @@ utilisateur {$session.username} {if $session.suer}(suid by {$session.suer}){/if} - [user's log] + [user's log] Hôte @@ -65,7 +65,7 @@
- + @@ -105,13 +104,13 @@ {foreach from=$sessions item=mysess} - + {/foreach} -- 2.1.4
{$msg_date}Date Année Utilisateur - {html_options name="logauth" options=$auths selected=$logauth}
{$mysess.start|date_format:"%x %X"}{$mysess.username} ({$mysess.lauth}){$mysess.username} {foreach from=$mysess.events item=myevent}{$myevent}
{/foreach}
session - user's log + user's log