Subversion Repositories ALCASAR

Rev

Rev 356 | Rev 1805 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log

Rev Author Line No. Line
324 richard 1
<?php
2
 
3
require('/etc/freeradius-web/config.php');
4
require('../lib/functions.php');
5
require('../lib/sql/functions.php');
6
require('../lib/acctshow.php');
7
 
8
if (is_file("../lib/sql/drivers/$config[sql_type]/functions.php"))
9
	include_once("../lib/sql/drivers/$config[sql_type]/functions.php");
10
else{
11
	echo <<<EOM
12
<html>
13
<head>
14
<title>G&eacute;n&eacute;rateur de rapports de comptes</title>
15
<meta http-equiv="Content-Type" content="text/html; charset=$config[general_charset]">
16
<link rel="stylesheet" href="/css/style.css">
17
</head>
18
<body>
19
<center>
20
<b>Could not include SQL library functions. Aborting</b>
21
</body>
22
</html>
23
EOM;
24
	exit();
25
}
26
 
27
$operators=array( '=','<', '>', '<=', '>=', 'regexp', 'like' );
28
if ($config[sql_type] == 'pg'){
29
	$operators=array( '=','<', '>', '<=', '>=', '~', 'like', '~*', '~~*', '<<=' );
30
}
31
 
32
$link = @da_sql_pconnect ($config) or die('cannot connect to sql databse');
33
$fields = @da_sql_list_fields($config[sql_accounting_table],$link,$config);
34
$no_fields = @da_sql_num_fields($fields,$config);
35
 
36
unset($items);
37
 
38
for($i=0;$i<$no_fields;$i++){
39
	$key = strtolower(@da_sql_field_name($fields,$i,$config));
40
	$val = $sql_attrs[$key][desc];
41
	if ($val == '')
42
		continue;
43
	$show = $sql_attrs[$key][show];
44
	$selected[$key] = ($show == 'yes') ? 'selected' : '';
45
	$items[$key] = "$val";
46
}
47
asort($items);
48
 
49
class Qi {
50
	var $name;
51
	var $item;
52
	var $_item;
53
	var $operator;
54
	var $type;
55
	var $typestr;
56
	var $value;
57
	function Qi($name,$item,$operator) {
58
				$this->name=$name;
59
				$this->item=$item;
60
				$this->operator=$operator;
61
	}
62
 
63
	function show() {	global $operators;
64
				global $items;
65
		$nam = $this->item;
66
			echo <<<EOM
67
	<tr><td align=left>
68
	<i>$items[$nam]</i>
69
	<input type=hidden name="item_of_$this->name" value="$this->item">
70
	</td><td align=left>
71
	<select name=operator_of_$this->name>
72
EOM;
73
		foreach($operators as $operator){
74
			if($this->operator == $operator)
75
				$selected=" selected ";
76
			else
77
				$selected='';
78
			print("<option value=\"$operator\" $selected>$operator</option>\n");
79
		 }
80
	echo <<<EOM
81
	</select>
82
	</td><td align=left>
83
	<input name="value_of_$this->name" type=text value="$this->value">
84
	</td><td align=left>
85
	<input type=hidden name="delete_$this->name" value=0>
86
	<input type=submit class=button size=5 value=del onclick="this.form.delete_$this->name.value=1">
87
	</td></tr>
88
EOM;
89
	}
90
 
91
	function get($designator) {  	global ${"item_of_$designator"};
92
			global ${"value_of_$designator"};
93
			global ${"operator_of_$designator"};
94
			if(${"item_of_$designator"}){
95
				$this->value= ${"value_of_$designator"};
96
				$this->operator=${"operator_of_$designator"};
97
				$this->item=${"item_of_$designator"};
98
			}
99
		}
100
	function query(){
101
		global $operators;
102
		global $items;
103
		return $items[$this->item]."  $this->operator  '$this->value'";
104
	}
105
}
106
 
107
?>
108
<html>
109
<head>
110
<title>Journal des connexions</title>
111
<meta http-equiv="Content-Type" content="text/html; charset=<?php echo $config[general_charset]?>">
112
<link rel="stylesheet" href="/css/style.css">
113
</head>
114
<body>
115
<TABLE width="100%" border="0" cellspacing="0" cellpadding="0">
116
	<tr><th>Journal des connexions</th></tr>
356 richard 117
	<tr bgcolor="#FFCC66"><td><img src="/images/pix.gif" width="1" height="2">
118
	</td></tr>
324 richard 119
</TABLE>
356 richard 120
<TABLE width="100%" border="1" cellspacing="0" cellpadding="1">
121
<tr><td>
324 richard 122
<?php
123
if(!$queryflag) {
124
	echo <<<EOM
125
<form method=post>
126
<table border=0 width=740 cellpadding=1 cellspacing=1>
127
<tr>
128
<td>
129
<b>Afficher les attributs suivants :</b><br>
130
<select name="accounting_show_attrs[]" size=5 multiple>
131
EOM;
132
foreach($items as $key => $val)
133
	echo <<<EOM
134
<option $selected[$key] value="$key">$val</option>
135
EOM;
136
 
137
echo <<<EOM
138
</select>
139
<br><br>
140
<b>Class&eacute; par :</b><br>
141
<select name="order_by">
142
EOM;
143
 
144
foreach($items as $key => $val)
145
	if ($val == 'username')
146
		echo <<<EOM
147
	<option selected value="$key">$val</option>
148
EOM;
149
	else
150
	echo <<<EOM
151
<option value="$key">$val</option>
152
EOM;
153
 
154
echo <<<EOM
155
</select>
156
<br><br>
157
<b>Nbr. Max. de r&eacute;sultats retourn&eacute;s :</b><br>
158
<input name=maxresults value=$config[sql_row_limit] size=5>
159
</td>
160
<td valign=top>
161
<input type=hidden name=add value=0>
162
<table border=0 width=340 cellpadding=1 cellspacing=1>
163
<tr><td>
164
<b>Crit&egrave;re de s&eacute;lection :</b>
165
</td></tr>
166
<tr><td>
167
<select name=item_name onchange="this.form.add.value=1;this.form.submit()">
168
<option>--Attribute--</option>
169
EOM;
170
 
171
foreach($items as $key => $val)
172
	print("<option value=\"$key\">$val</option>");
173
 
174
echo <<<EOM
175
</select>
176
</td></tr>
177
EOM;
178
 
179
$number=1;
180
$offset=0;
181
while (${"item_of_w$number"}) {
182
	if(${"delete_w$number"}==1) {$offset=1;$number++;}
183
		else {
184
		$designator=$number-$offset;
185
		${"w$designator"} = new Qi("w$designator","","");
186
		${"w$designator"}->get("w$number");
187
		${"w$designator"}->show();
188
		$number++;
189
		}
190
	}
191
if($add==1) {
192
	${"w$number"} = new Qi("w$number","$item_name","$operators[0]");
193
	${"w$number"}->show();
194
	}
195
echo <<<EOM
196
</table>
197
</td>
198
<tr>
199
<td>
200
<input type=hidden name=queryflag value=0>
201
<br><input type=submit class=button onclick="this.form.queryflag.value=1">
202
</td>
203
</tr>
204
</table>
205
</form>
356 richard 206
</table>
324 richard 207
</body>
208
</html>
209
EOM;
210
 
211
}
212
 
213
if ($queryflag == 1){
214
$i = 1;
215
while (${"item_of_w$i"}){
216
	$op_found = 0;
217
	foreach ($operators as $operator){
218
		if (${"operator_of_w$i"} == $operator){
219
			$op_found = 1;
220
			break;
221
		}
222
	}
223
	if (!$op_found)
224
		die("L'op&eacute;ration demand&eacute; n'est pas valide. Sortie anormale.");
225
	${"item_of_w$i"} = preg_replace('/\s/','',${"item_of_w$i"});
226
	${"value_of_w$i"} = da_sql_escape_string(${"value_of_w$i"});
227
	$where .= ($i == 1) ? ' WHERE ' . ${"item_of_w$i"} . ' ' . ${"operator_of_w$i"} . " '" . ${"value_of_w$i"} . "'" :
228
				' AND ' . ${"item_of_w$i"} . ' ' . ${"operator_of_w$i"} . " '" . ${"value_of_w$i"} . "'" ;
229
	$i++;
230
}
231
 
232
$order = ($order_by != '') ? "$order_by" : 'username';
233
 
234
if (preg_match("/[\s;]/",$order))
235
	die("ORDER BY pattern is illegal. Exiting abnornally.");
236
 
237
if (!is_numeric($maxresults))
238
	die("Max Results is not in numeric form. Exiting abnormally.");
239
 
240
unset($query_view);
241
foreach ($accounting_show_attrs as $val)
242
	$query_view .= $val . ',';
243
$query_view = ereg_replace(',$','',$query_view);
244
unset($sql_extra_query);
245
if ($config[sql_accounting_extra_query] != '')
246
	$sql_extra_query = xlat($config[sql_accounting_extra_query],$login,$config);
247
	$sql_extra_query = da_sql_escape_string($sql_extra_query);
248
$query="SELECT " . da_sql_limit($maxresults,0,$config) . " $query_view FROM $config[sql_accounting_table]
249
	$where $sql_extra_query " . da_sql_limit($maxresults,1,$config) .
486 franck 250
	" ORDER BY $order DESC " . da_sql_limit($maxresults,2,$config) . ";";
324 richard 251
 
252
echo <<<EOM
253
	<table border=0 width=100% cellpadding=12 cellspacing=0 bgcolor="#ffffd0" valign=top>
254
	<tr><td>
255
<p>
256
	<table border=1 bordercolordark=#ffffe0 bordercolorlight=#000000 width=100% cellpadding=2 cellspacing=0 bgcolor="#ffffe0" valign=top>
257
	<tr bgcolor="#d0ddb0">
258
	</tr>
259
EOM;
260
foreach($accounting_show_attrs as $val){
261
	$desc = $sql_attrs[$val][desc];
262
	echo "<th>$desc</th>\n";
263
}
264
echo "</tr>\n";
265
 
266
	$search = @da_sql_query($link,$config,$query);
267
	if ($search){
268
		while( $row = @da_sql_fetch_array($search,$config) ){
269
			$num++;
270
			echo "<tr align=center>\n";
271
			foreach($accounting_show_attrs as $val){
272
				$info = $row[$val];
273
				if ($info == '')
274
					$info = '-';
275
				$info = $sql_attrs[$val][func]($info);
276
				if ($val == 'username'){
277
					$Info = urlencode($info);
278
					$info = "<a href=\"user_admin.php?login=$Info\" title=\"Edit user $info\">$info<a/>";
279
				}
280
				echo <<<EOM
281
			<td>$info</td>
282
EOM;
283
			}
284
			echo "</tr>\n";
285
		}
286
	}
287
	else
288
		echo "<b>Database query failed: " . da_sql_error($link,$config) . "</b><br>\n";
289
echo <<<EOM
290
	</table>
291
	</td></tr>
292
	</table>
293
</td></tr>
294
</table>
356 richard 295
</table>
324 richard 296
</body>
297
</html>
298
EOM;
299
}
300
?>