simplifications
authorx2000habouzit <x2000habouzit@839d8a87-29fc-0310-9880-83ba4fa771e5>
Mon, 31 Jul 2006 19:00:07 +0000 (19:00 +0000)
committerx2000habouzit <x2000habouzit@839d8a87-29fc-0310-9880-83ba4fa771e5>
Mon, 31 Jul 2006 19:00:07 +0000 (19:00 +0000)
git-svn-id: svn+ssh://murphy/home/svn/platal/trunk@753 839d8a87-29fc-0310-9880-83ba4fa771e5

classes/CoreLogger.php
classes/LoggerView.php
include/platal/globals.inc.php.in
templates/logger-view.tpl

index 49d2ce5..13df881 100644 (file)
@@ -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 {
index b0d1967..86a55d7 100644 (file)
  * 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');
     }
 
index 660176e..adf834d 100644 (file)
@@ -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;
index 34a40b5..496616c 100644 (file)
@@ -31,7 +31,7 @@
 <tr class="impair">
   <td class="titre">utilisateur</td>
   <td>{$session.username} {if $session.suer}(suid by {$session.suer}){/if}
-  [<a href="{$platal->ns}admin/logger?logauth={$session.auth}&amp;loguser={$session.username}">user's log</a>]</td>
+  [<a href="{$platal->ns}admin/logger?loguser={$session.username}">user's log</a>]</td>
 </tr>
 <tr class="pair">
   <td class="titre">Hôte</td>
@@ -65,7 +65,7 @@
 <form method="post" action="{$platal->ns}admin/logger">
 <table class="bicol">
 <tr>
-  <td><strong>{$msg_date}</strong></td>
+  <td><strong>Date</strong></td>
   <td>
     Année
     <select name="year" onchange="this.form.submit()">
@@ -85,7 +85,6 @@
   <td><strong>Utilisateur</strong></td>
   <td>
     <input type="text" name="loguser" value="{$loguser}" />
-    {html_options name="logauth" options=$auths selected=$logauth}
     <input type="submit" />
   </td>
 </tr>
 {foreach from=$sessions item=mysess}
   <tr class="{cycle values="impair,pair"}">
     <td>{$mysess.start|date_format:"%x %X"}</td>
-    <td><strong>{$mysess.username}</strong> <span class="smaller">({$mysess.lauth})</span></td>
+    <td><strong>{$mysess.username}</strong></td>
     <td>
       {foreach from=$mysess.events item=myevent}{$myevent}<br />{/foreach}
     </td>
     <td class="action">
       <a href="admin/logger?logsess={$mysess.id}">session</a>
-      <a href="admin/logger?logauth={$mysess.auth}&amp;loguser={$mysess.username}">user's log</a>
+      <a href="admin/logger?loguser={$mysess.username}">user's log</a>
     </td>
   </tr>
   {/foreach}