[ Index ]

Source Code Reference for V1.00

title

Body

[close]

/modules/admin/ -> vw_usr_sessions.php (source)

   1  <?php /* $Id: vw_usr_sessions.php 139 2008-04-05 14:21:51Z pedroix $ $URL: https://web2project.svn.sourceforge.net/svnroot/web2project/trunk/modules/admin/vw_usr_sessions.php $ */
   2  if (!defined('W2P_BASE_DIR')) {
   3      die('You should not access this file directly.');
   4  }
   5  
   6  global $w2Pconfig, $canEdit, $canDelete, $stub, $where, $orderby;
   7  
   8  /*

   9  * Flag value to determine if "logout user" button should show. 

  10  * Could be determined by a configuration value in the future.

  11  */
  12  $logoutUserFlag = true;
  13  
  14  if ($_GET['out_user_id'] && $_GET['out_name'] && $canEdit && $canDelete) {
  15      $boot_user_id = w2PgetParam($_GET, 'out_user_id', null);
  16      $boot_user_name = $_GET['out_name'];
  17      $details = $boot_user_name . ' by ' . $AppUI->user_first_name . ' ' . $AppUI->user_last_name;
  18  
  19      // one session or many?

  20      if ($_GET['out_session'] && $_GET['out_user_log_id']) {
  21          $boot_user_session = $_GET['out_session'];
  22          $boot_user_log_id = w2PgetParam($_GET, 'out_user_log_id', null);
  23          $boot_query_row = false;
  24      } else
  25          if ($canEdit && $canDelete && $logoutUserFlag) {
  26              // query for all sessions open for a given user

  27              $r = new DBQuery;
  28              $r->addTable('sessions', 's');
  29              $r->addQuery('DISTINCT(session_id), user_access_log_id');
  30              $r->addJoin('user_access_log', 'ual', 'session_user = user_access_log_id');
  31              $r->addWhere('user_id = ' . (int)$boot_user_id);
  32              $r->addOrder('user_access_log_id');
  33  
  34              //execute query and fetch results

  35              $r->exec();
  36              $boot_query_row = $r->fetchRow();
  37              if ($boot_query_row) {
  38                  $boot_user_session = $boot_query_row['session_id'];
  39                  $boot_user_log_id = $boot_query_row['user_access_log_id'];
  40              }
  41          }
  42  
  43      do {
  44          if ($boot_user_id == $AppUI->user_id && $boot_user_session == $_COOKIE['PHPSESSID']) {
  45              $AppUI->resetPlace();
  46              $AppUI->redirect('logout=-1');
  47          } else {
  48              addHistory('login', $boot_user_id, 'logout', $details);
  49              w2PsessionDestroy($boot_user_session, $boot_user_log_id);
  50          }
  51  
  52          if ($boot_query_row) {
  53              $boot_query_row = $r->fetchRow();
  54              if ($boot_query_row) {
  55                  $boot_user_session = $boot_query_row['session_id'];
  56                  $boot_user_log_id = $boot_query_row['user_access_log_id'];
  57              } else {
  58                  $r->clear();
  59              }
  60          }
  61  
  62      } while ($boot_query_row);
  63  
  64      $msg = $boot_user_name . ' logged out by ' . $AppUI->user_first_name . ' ' . $AppUI->user_last_name;
  65      $AppUI->setMsg($msg, UI_MSG_OK);
  66      $AppUI->redirect('m=admin&tab=3');
  67  }
  68  
  69  $q = new DBQuery;
  70  $q->addTable('sessions', 's');
  71  $q->addQuery('DISTINCT(session_id), user_access_log_id, u.user_id as u_user_id, user_username, contact_last_name, contact_first_name, company_name, contact_company, date_time_in, user_ip');
  72  
  73  $q->addJoin('user_access_log', 'ual', 'session_user = user_access_log_id');
  74  $q->addJoin('users', 'u', 'ual.user_id = u.user_id');
  75  $q->addJoin('contacts', 'con', 'u.user_contact = contact_id');
  76  $q->addJoin('companies', 'com', 'contact_company = company_id');
  77  $q->addOrder($orderby);
  78  $rows = $q->loadList();
  79  $q->clear();
  80  
  81  $tab = w2PgetParam($_REQUEST, 'tab', 0);
  82  
  83  ?>
  84  
  85  <table cellpadding="2" cellspacing="1" border="0" width="100%" class="tbl">
  86    <tr>
  87      <th colspan="2">&nbsp; <?php echo $AppUI->_('sort by'); ?>:&nbsp;</th>
  88      <th width="150"><a href="?m=admin&a=index&orderby=user_username" class="hdr"><?php echo $AppUI->_('Login Name'); ?></a></th>
  89      <th><a href="?m=admin&a=index&orderby=contact_last_name" class="hdr"><?php echo $AppUI->_('Real Name'); ?></a></th>
  90      <th><a href="?m=admin&a=index&orderby=contact_company" class="hdr"><?php echo $AppUI->_('Company'); ?></a></th>
  91      <th><a href="?m=admin&a=index&orderby=date_time_in" class="hdr"><?php echo $AppUI->_('Date Time IN'); ?></a></th>
  92      <th><a href="?m=admin&a=index&orderby=user_ip" class="hdr"><?php echo $AppUI->_('Internet Address'); ?></a></th>
  93    </tr>
  94  
  95  <?php
  96  foreach ($rows as $row) {
  97      $s = '<tr>';
  98      $s .= '<td align="center" nowrap="nowrap">';
  99      if ($canEdit && $canDelete) {
 100          $s .= '<input type="button" class="button" value="' . $AppUI->_('logout_session') . '" onclick="javascript:window.location=\'./index.php?m=admin&tab=3&out_session=' . $row['session_id'] . '&out_user_log_id=' . $row['user_access_log_id'] . '&out_user_id=' . $row['u_user_id'] . '&out_name=' . $row['contact_first_name'] . '%20' . $row['contact_last_name'] . '\';"></input>';
 101      }
 102      $s .= '</td><td align="center" nowrap="nowrap">';
 103      if ($canEdit && $canDelete && $logoutUserFlag) {
 104          $s .= '<input type="button" class=button value="' . $AppUI->_('logout_user') . '" onclick="javascript:window.location=\'./index.php?m=admin&tab=3&out_user_id=' . $row['u_user_id'] . '&out_name=' . $row['contact_first_name'] . '%20' . $row['contact_last_name'] . '\';"></input>';
 105      }
 106      $s .= '</td><td><a href="./index.php?m=admin&a=viewuser&user_id=' . $row['u_user_id'] . '">' . $row['user_username'] . '</a></td><td>';
 107      if ($row['contact_first_name'] || $row['contact_last_name']) {
 108          $s .= ($row['contact_first_name'] . ' ' . $row['contact_last_name']);
 109      } else {
 110          $s .= ('<span style="font-style: italic">unknown</span>');
 111      }
 112      $s .= '</td><td><a href="./index.php?m=companies&a=view&company_id=' . $row['contact_company'] . '">' . $row['company_name'] . '</a></td>';
 113      $s .= '<td>' . $row['date_time_in'] . '</td><td>' . $row['user_ip'] . '</td></tr>';
 114      echo $s;
 115  }
 116  ?>
 117  </table>


Generated: Wed Jan 7 03:00:01 2009 Cross-referenced by PHPXref 0.7