tce_functions_users_online.php 5.18 KB
Newer Older
nicolaasuni's avatar
9.0.026    
nicolaasuni committed
1
2
3
4
<?php
//============================================================+
// File name   : tce_functions_levels.php
// Begin       : 2001-10-18
Nick's avatar
Nick committed
5
// Last Update : 2011-05-24
nick's avatar
nick committed
6
//
nicolaasuni's avatar
9.0.026    
nicolaasuni committed
7
8
9
10
11
12
// Description : Functions to display online users' data.
//
// Author: Nicola Asuni
//
// (c) Copyright:
//               Nicola Asuni
Nick's avatar
Nick committed
13
//               Tecnick.com LTD
nicolaasuni's avatar
9.0.026    
nicolaasuni committed
14
15
16
//               www.tecnick.com
//               info@tecnick.com
//
nick's avatar
nick committed
17
// License:
Nick's avatar
Nick committed
18
//    Copyright (C) 2004-2010  Nicola Asuni - Tecnick.com LTD
nicolaasuni's avatar
9.0.026    
nicolaasuni committed
19
20
21
22
//    See LICENSE.TXT file for more information.
//============================================================+

/**
nick's avatar
nick committed
23
 * @file
nicolaasuni's avatar
9.0.026    
nicolaasuni committed
24
25
26
27
28
29
30
31
32
33
 * Functions to display online users' data.
 * @package com.tecnick.tcexam.admin
 * @author Nicola Asuni
 * @since 2001-10-18
 */

/**
 * Display online users form using F_list_online_users function.
 * @author Nicola Asuni
 * @since 2001-10-18
nick's avatar
nick committed
34
35
36
37
38
 * @param $wherequery (string) users selection query
 * @param $order_field (string) order by column name
 * @param $orderdir (string) oreder direction
 * @param $firstrow (string) number of first row to display
 * @param $rowsperpage (string) number of rows per page
nicolaasuni's avatar
9.0.026    
nicolaasuni committed
39
40
41
42
43
44
45
46
47
48
49
50
51
 * @return false in case of empty database, true otherwise
 */
function F_show_online_users($wherequery, $order_field, $orderdir, $firstrow, $rowsperpage) {
	global $l;
	require_once('../config/tce_config.php');
	F_list_online_users($wherequery, $order_field, $orderdir, $firstrow, $rowsperpage);
	return true;
}

/**
 * Display online users.
 * @author Nicola Asuni
 * @since 2001-10-18
nick's avatar
nick committed
52
53
54
55
56
 * @param $wherequery (string) users selection query
 * @param $order_field (string) order by column name
 * @param $orderdir (int) oreder direction
 * @param $firstrow (int) number of first row to display
 * @param $rowsperpage (int) number of rows per page
nicolaasuni's avatar
9.0.026    
nicolaasuni committed
57
58
59
60
61
62
 * @return false in case of empty database, true otherwise
 */
function F_list_online_users($wherequery, $order_field, $orderdir, $firstrow, $rowsperpage) {
	global $l, $db;
	require_once('../config/tce_config.php');
	require_once('../../shared/code/tce_functions_page.php');
nick's avatar
nick committed
63
64
	require_once('tce_functions_user_select.php');
	
nicolaasuni's avatar
9.0.026    
nicolaasuni committed
65
66
	//initialize variables
	$orderdir = intval($orderdir);
Nick's avatar
Nick committed
67
68
	$firstrow = intval($firstrow);
	$rowsperpage = intval($rowsperpage);
Nick's avatar
Nick committed
69
70
71
72
73
	
	// order fields for SQL query
	if (empty($order_field) OR (!in_array($order_field, array('cpsession_id', 'cpsession_data')))) {
		$order_field = 'cpsession_expiry';
	}
nick's avatar
nick committed
74
75
76
77
78
79
	if($orderdir == 0) {
		$nextorderdir = 1;
		$full_order_field = $order_field;
	} else {
		$nextorderdir = 0;
		$full_order_field = $order_field.' DESC';
nicolaasuni's avatar
9.0.026    
nicolaasuni committed
80
	}
nick's avatar
nick committed
81

nicolaasuni's avatar
9.0.026    
nicolaasuni committed
82
83
84
85
	if(!F_count_rows(K_TABLE_SESSIONS)) { //if the table is void (no items) display message
		echo '<h2>'.$l['m_databasempty'].'</h2>';
		return FALSE;
	}
nick's avatar
nick committed
86

nicolaasuni's avatar
9.0.026    
nicolaasuni committed
87
	if (empty($wherequery)) {
nicolaasuni's avatar
9.0.029    
nicolaasuni committed
88
		$sql = 'SELECT * FROM '.K_TABLE_SESSIONS.' ORDER BY '.$full_order_field.'';
nicolaasuni's avatar
9.0.026    
nicolaasuni committed
89
	} else {
tecnickcom's avatar
tecnickcom committed
90
		$wherequery = F_escape_sql($db, $wherequery);
nicolaasuni's avatar
9.0.029    
nicolaasuni committed
91
92
93
94
95
96
		$sql = 'SELECT * FROM '.K_TABLE_SESSIONS.' '.$wherequery.' ORDER BY '.$full_order_field.'';
	}
	if (K_DATABASE_TYPE == 'ORACLE') {
		$sql = 'SELECT * FROM ('.$sql.') WHERE rownum BETWEEN '.$firstrow.' AND '.($firstrow + $rowsperpage).'';
	} else {
		$sql .= ' LIMIT '.$rowsperpage.' OFFSET '.$firstrow.'';
nicolaasuni's avatar
9.0.026    
nicolaasuni committed
97
	}
nick's avatar
nick committed
98

nicolaasuni's avatar
9.0.026    
nicolaasuni committed
99
100
101
	echo '<div class="container">'.K_NEWLINE;
	echo '<table class="userselect">'.K_NEWLINE;
	echo '<tr>'.K_NEWLINE;
102
	echo '<th>'.'#'.'</th>'.K_NEWLINE;			//ESM 150317
nicolaasuni's avatar
9.0.026    
nicolaasuni committed
103
104
105
106
	echo '<th>'.$l['w_user'].'</th>'.K_NEWLINE;
	echo '<th>'.$l['w_level'].'</th>'.K_NEWLINE;
	echo '<th>'.$l['w_ip'].'</th>'.K_NEWLINE;
	echo '</tr>'.K_NEWLINE;
107
	$i=$firstrow;				//ESM 150317
nicolaasuni's avatar
9.0.026    
nicolaasuni committed
108
109
	if($r = F_db_query($sql, $db)) {
		while($m = F_db_fetch_array($r)) {
nick's avatar
nick committed
110

nicolaasuni's avatar
9.0.026    
nicolaasuni committed
111
112
			$this_session = F_session_string_to_array($m['cpsession_data']);
			echo '<tr>';
113
			$i++; echo "<td>$i</td>";			//ESM 150317
nicolaasuni's avatar
9.0.026    
nicolaasuni committed
114
			echo '<td align="left">';
nick's avatar
nick committed
115
			$user_str = '';
nicolaasuni's avatar
9.0.026    
nicolaasuni committed
116
			if ($this_session['session_user_lastname']) {
nick's avatar
nick committed
117
				$user_str .= urldecode($this_session['session_user_lastname']).', ';
nicolaasuni's avatar
9.0.026    
nicolaasuni committed
118
119
			}
			if ($this_session['session_user_firstname']) {
nick's avatar
nick committed
120
121
122
123
124
125
126
				$user_str .= urldecode($this_session['session_user_firstname']).'';
			}
			$user_str .= ' ('.urldecode($this_session['session_user_name']).')';
			if (F_isAuthorizedEditorForUser($this_session['session_user_id'])) {
				echo '<a href="tce_edit_user.php?user_id='.$this_session['session_user_id'].'">'.$user_str.'</a>';
			} else {
				echo $user_str;
nicolaasuni's avatar
9.0.026    
nicolaasuni committed
127
128
			}
			echo '</td>';
nick's avatar
nick committed
129
			echo '<td>'.$this_session['session_user_level'].'</td>';
Ewald's avatar
Ewald committed
130
			echo '<td>'.ip6toip4($this_session['session_user_ip']).'</td>';
nicolaasuni's avatar
9.0.026    
nicolaasuni committed
131
132
133
134
135
136
			echo '</tr>'.K_NEWLINE;
		}
	} else {
		F_display_db_error();
	}
	echo '</table>'.K_NEWLINE;
nick's avatar
nick committed
137

138

nicolaasuni's avatar
9.0.026    
nicolaasuni committed
139
140
	// --- ------------------------------------------------------
	// --- page jump
Nick's avatar
Nick committed
141
142
143
144
145
146
147
	if ($rowsperpage > 0) {
		$sql = 'SELECT count(*) AS total FROM '.K_TABLE_SESSIONS.' '.$wherequery.'';
		if (!empty($order_field)) {$param_array = '&amp;order_field='.urlencode($order_field).'';}
		if (!empty($orderdir)) {$param_array .= '&amp;orderdir='.$orderdir.'';}
		$param_array .= '&amp;submitted=1';
		F_show_page_navigator($_SERVER['SCRIPT_NAME'], $sql, $firstrow, $rowsperpage, $param_array);
	}
nicolaasuni's avatar
9.0.026    
nicolaasuni committed
148
149
150
151
152
153
	echo '<div class="pagehelp">'.$l['hp_online_users'].'</div>'.K_NEWLINE;
	echo '</div>'.K_NEWLINE;
	return TRUE;
}

//============================================================+
nick's avatar
nick committed
154
// END OF FILE
nicolaasuni's avatar
9.0.026    
nicolaasuni committed
155
//============================================================+