tce_functions_test_stats.php 65.4 KB
Newer Older
nicolaasuni's avatar
9.0.026    
nicolaasuni committed
1
2
3
4
<?php
//============================================================+
// File name   : tce_functions_test_stats.php
// Begin       : 2004-06-10
tecnickcom's avatar
tecnickcom committed
5
// Last Update : 2014-01-27
nick's avatar
nick committed
6
//
nicolaasuni's avatar
9.0.026    
nicolaasuni committed
7
8
9
10
11
12
// Description : Statistical functions for test results.
//
// 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:
tecnickcom's avatar
tecnickcom committed
18
//    Copyright (C) 2004-2014 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
 * Statistical functions for test results.
 * @package com.tecnick.tcexam.shared
 * @author Nicola Asuni
 * @since 2004-06-10
 */

/**
Nicola Asuni's avatar
Nicola Asuni committed
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
* Returns statistic array for the test-user
* @param $test_id (int) test ID.
* @param $user_id (int) user ID - if greater than zero, filter stats for the specified user.
* @param $testuser_id (int) test-user ID - if greater than zero, filter stats for the specified test-user.
* return $data array containing test-user statistics.
*/
function F_getUserTestStat($test_id, $user_id=0, $testuser_id=0) {
	require_once('../config/tce_config.php');
	require_once('../../shared/code/tce_functions_test.php');
	global $db, $l;
	$test_id = intval($test_id);
	$user_id = intval($user_id);
	$testuser_id = intval($testuser_id);
	// get test data array
	$data = F_getTestData($test_id);
	$data += F_getUserTestTotals($test_id, $user_id, $testuser_id);
	return $data;
nick's avatar
nick committed
48
}
nicolaasuni's avatar
9.0.026    
nicolaasuni committed
49
50

/**
Nicola Asuni's avatar
Nicola Asuni committed
51
52
53
54
55
56
57
* Returns test-user totals
* @param $test_id (int) test ID.
* @param $user_id (int) user ID - if greater than zero, filter stats for the specified user.
* @param $testuser_id (int) test-user ID - if greater than zero, filter stats for the specified test-user.
* return $data array containing test-user statistics.
*/
function F_getUserTestTotals($test_id, $user_id=0, $testuser_id=0) {
nicolaasuni's avatar
9.0.026    
nicolaasuni committed
58
	require_once('../config/tce_config.php');
Nicola Asuni's avatar
Nicola Asuni committed
59
	require_once('../../shared/code/tce_functions_test.php');
nicolaasuni's avatar
9.0.026    
nicolaasuni committed
60
61
62
	global $db, $l;
	$test_id = intval($test_id);
	$user_id = intval($user_id);
Nicola Asuni's avatar
Nicola Asuni committed
63
64
65
66
67
68
69
70
71
72
73
74
75
	$testuser_id = intval($testuser_id);
	// get test data array
	$data = array();
	// additional info
	if (($test_id > 0) AND ($user_id > 0) AND ($testuser_id > 0)) {
		// get user totals
		$sqlu = 'SELECT SUM(testlog_score) AS total_score, MAX(testlog_change_time) AS test_end_time, testuser_id, testuser_creation_time, testuser_status, testuser_comment
		FROM '.K_TABLE_TEST_USER.', '.K_TABLE_TESTS_LOGS.'
		WHERE testlog_testuser_id=testuser_id
			AND testuser_id='.$testuser_id.'
			AND testuser_test_id='.$test_id.'
			AND testuser_user_id='.$user_id.'
			AND testuser_status>0
Nicola Asuni's avatar
Nicola Asuni committed
76
77
78
		GROUP BY testuser_id, testuser_creation_time, testuser_status, testuser_comment';
		if ($ru = F_db_query($sqlu, $db)) {
			if ($mu = F_db_fetch_array($ru)) {
Nicola Asuni's avatar
Nicola Asuni committed
79
80
81
82
83
84
85
86
87
88
				$data['testuser_id'] = $mu['testuser_id'];
				$data['user_score'] = $mu['total_score'];
				$data['user_test_start_time'] = $mu['testuser_creation_time'];
				$data['user_test_end_time'] = $mu['test_end_time'];
				$data['testuser_status'] = $mu['testuser_status'];
				$data['user_comment'] = $mu['testuser_comment'];
			}
		} else {
			F_display_db_error();
		}
nicolaasuni's avatar
9.0.026    
nicolaasuni committed
89
	}
Nicola Asuni's avatar
Nicola Asuni committed
90
	return $data;
nicolaasuni's avatar
9.0.026    
nicolaasuni committed
91
92
93
}

/**
Nicola Asuni's avatar
Nicola Asuni committed
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
* Returns statistic array for the selected test.
* @param $test_id (int) test ID.
* @param $group_id (int) group ID - if greater than zero, filter stats for the specified user group.
* @param $user_id (int) user ID - if greater than zero, filter stats for the specified user.
* @param $startdate (int) start date ID - if greater than zero, filter stats for the specified starting date
* @param $enddate (int) end date ID - if greater than zero, filter stats for the specified ending date
* @param $testuser_id (int) test-user ID - if greater than zero, filter stats for the specified test-user.
* @param $pubmode (boolean) If true filter the results for the public interface.
* return $data array containing test statistics.
*/
function F_getTestStat($test_id, $group_id=0, $user_id=0, $startdate=0, $enddate=0, $testuser_id=0, $pubmode=false) {
	$data = F_getRawTestStat($test_id, $group_id, $user_id, $startdate, $enddate, $testuser_id, array(), $pubmode);
	if (isset($data['qstats']['recurrence'])) {
		$data = F_normalizeTestStatAverages($data);
	}
	return $data;
}

/**
* Returns raw statistic array for the selected test.
* @param $test_id (int) test ID.
* @param $group_id (int) group ID - if greater than zero, filter stats for the specified user group.
* @param $user_id (int) user ID - if greater than zero, filter stats for the specified user.
* @param $startdate (int) start date ID - if greater than zero, filter stats for the specified starting date
* @param $enddate (int) end date ID - if greater than zero, filter stats for the specified ending date
* @param $testuser_id (int) test-user ID - if greater than zero, filter stats for the specified test-user.
* @param $data (array) Array of existing data to be merged with the current one.
* @param $pubmode (boolean) If true filter the results for the public interface.
* return $data array containing test statistics.
*/
function F_getRawTestStat($test_id, $group_id=0, $user_id=0, $startdate=0, $enddate=0, $testuser_id=0, $data=array(), $pubmode=false) {
nicolaasuni's avatar
9.0.026    
nicolaasuni committed
125
	require_once('../config/tce_config.php');
Nicola Asuni's avatar
Nicola Asuni committed
126
127
	require_once('../../shared/code/tce_functions_authorization.php');
	require_once('../../shared/code/tce_functions_test.php');
nicolaasuni's avatar
9.0.026    
nicolaasuni committed
128
129
	global $db, $l;
	$test_id = intval($test_id);
Nicola Asuni's avatar
Nicola Asuni committed
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
	$group_id = intval($group_id);
	$user_id = intval($user_id);
	$testuser_id = intval($testuser_id);
	// query to calculate total number of questions
	$sqltot = K_TABLE_TEST_USER.', '.K_TABLE_TESTS_LOGS;
	$sqltb = K_TABLE_TEST_USER.', '.K_TABLE_TESTS_LOGS.', '.K_TABLE_ANSWERS.', '.K_TABLE_LOG_ANSWER;
	$sqlm = K_TABLE_TEST_USER.', '.K_TABLE_TESTS_LOGS.', '.K_TABLE_QUESTIONS.', '.K_TABLE_SUBJECTS.', '.K_TABLE_MODULES.'';
	// apply filters
	$sqlw = 'WHERE testlog_testuser_id=testuser_id';
	$sqlansw = 'WHERE logansw_answer_id=answer_id AND logansw_testlog_id=testlog_id AND testlog_testuser_id=testuser_id';
	if ($test_id > 0) {
		$sqlw .= ' AND testuser_test_id='.$test_id.'';
		$sqlansw .= ' AND testuser_test_id='.$test_id.'';
	} elseif ($pubmode) {
		$test_ids_results = F_getTestIDResults($test_id, $user_id);
		$sqlw .= ' AND testuser_test_id IN ('.$test_ids_results.')';
		$sqlansw .= ' AND testuser_test_id IN ('.$test_ids_results.')';
	}
	if ($user_id > 0) {
		$sqltot .= ', '.K_TABLE_USERS;
		$sqltb .= ', '.K_TABLE_USERS;
		$sqlm .= ', '.K_TABLE_USERS;
		$sqlw .= ' AND testuser_user_id=user_id AND user_id='.$user_id.'';
		$sqlansw .= ' AND testuser_user_id=user_id AND user_id='.$user_id.'';
		if ($testuser_id > 0) {
			$sqlw .= ' AND testuser_id='.$testuser_id.'';
			$sqlansw .= ' AND testuser_id='.$testuser_id.'';
nicolaasuni's avatar
9.0.026    
nicolaasuni committed
157
		}
Nicola Asuni's avatar
Nicola Asuni committed
158
159
160
161
162
163
	} elseif ($group_id > 0) {
		$sqltot .= ', '.K_TABLE_USERS.', '.K_TABLE_USERGROUP;
		$sqltb .= ', '.K_TABLE_USERS.', '.K_TABLE_USERGROUP;
		$sqlm .= ', '.K_TABLE_USERS.', '.K_TABLE_USERGROUP;
		$sqlw .= ' AND testuser_user_id=user_id AND usrgrp_user_id=user_id AND usrgrp_group_id='.$group_id.'';
		$sqlansw .= ' AND testuser_user_id=user_id AND usrgrp_user_id=user_id AND usrgrp_group_id='.$group_id.'';
nicolaasuni's avatar
9.0.026    
nicolaasuni committed
164
	}
Nicola Asuni's avatar
Nicola Asuni committed
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
	if (!empty($startdate)) {
		$startdate_time = strtotime($startdate);
		$startdate = date(K_TIMESTAMP_FORMAT, $startdate_time);
		$sqlw .= ' AND testuser_creation_time>=\''.$startdate.'\'';
		$sqlansw .= ' AND testuser_creation_time>=\''.$startdate.'\'';
	}
	if (!empty($enddate)) {
		$enddate_time = strtotime($enddate);
		$enddate = date(K_TIMESTAMP_FORMAT, $enddate_time);
		$sqlw .= ' AND testuser_creation_time<=\''.$enddate.'\'';
		$sqlansw .= ' AND testuser_creation_time<=\''.$enddate.'\'';
	}
	// check if a specific test is selected or not
	if ($test_id == 0) {
		$test_ids = array();
		$sqlt = 'SELECT testuser_test_id FROM '.$sqltot.' '.$sqlw.' GROUP BY testuser_test_id ORDER BY testuser_test_id';
		if ($rt = F_db_query($sqlt, $db)) {
tecnickcom's avatar
tecnickcom committed
182
			while ($mt = F_db_fetch_assoc($rt)) {
tecnickcom's avatar
tecnickcom committed
183
184
185
				// check user's authorization
				if (F_isAuthorizedUser(K_TABLE_TESTS, 'test_id', $mt['testuser_test_id'], 'test_user_id')) {
					$test_ids[] = $mt['testuser_test_id'];
Nicola Asuni's avatar
Nicola Asuni committed
186
				}
tecnickcom's avatar
tecnickcom committed
187
			}
Nicola Asuni's avatar
Nicola Asuni committed
188
189
190
191
192
193
		} else {
			F_display_db_error();
		}
		foreach ($test_ids as $tid) {
			// select test IDs
			$data =  F_getRawTestStat($tid, $group_id, $user_id, $startdate, $enddate, $testuser_id, $data);
nicolaasuni's avatar
9.0.026    
nicolaasuni committed
194
		}
Nicola Asuni's avatar
Nicola Asuni committed
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
		return $data;
	}
	$testdata = F_getTestData($test_id);
	// array to be returned
	if (!isset($data['qstats'])) {
		// total number of questions
		$data['qstats'] = array(
			'recurrence' => 0,
			'recurrence_perc' => 0,
			'average_score' => 0,
			'average_score_perc' => 0,
			'average_time' => 0,
			'right' => 0,
			'right_perc' => 0,
			'wrong' => 0,
			'wrong_perc' => 0,
			'unanswered' => 0,
			'unanswered_perc' => 0,
			'undisplayed' => 0,
			'undisplayed_perc' => 0,
			'unrated' => 0,
			'unrated_perc' => 0,
			'qnum' => 0,
			'module' => array());
	}
	$sql = 'SELECT
		module_id,
		subject_id,
		question_id,
		module_name,
		subject_name,
		subject_description,
		question_description,';
	if (($user_id > 0) AND ($testuser_id > 0)) {
		$sql .= ' testlog_score,
			testlog_user_ip,
			testlog_display_time,
			testlog_change_time,
			testlog_reaction_time,
			testlog_answer_text,
			question_type,
			question_explanation,';
	}
	$sql .= ' COUNT(question_id) AS recurrence,
		AVG(testlog_score) AS average_score,
		AVG(testlog_change_time - testlog_display_time) AS average_time,
		MIN(question_type) AS question_type,
		MIN(question_difficulty) AS question_difficulty';
	$sql .= ' FROM '.$sqlm;
	$sql .= ' WHERE testlog_testuser_id=testuser_id AND question_id=testlog_question_id AND subject_id=question_subject_id AND module_id=subject_module_id';
	if ($test_id > 0) {
		$sql .= ' AND testuser_test_id='.$test_id.'';
	}
	if ($testuser_id > 0) {
		$sql .= ' AND testuser_id='.$testuser_id.'';
	}
	if ($user_id > 0) {
		$sql .= ' AND testuser_user_id=user_id AND user_id='.$user_id.'';
	} elseif ($group_id > 0) {
		$sql .= ' AND testuser_user_id=user_id AND usrgrp_user_id=user_id AND usrgrp_group_id='.$group_id.'';
	}
	if (!empty($startdate)) {
		$sql .= ' AND testuser_creation_time>=\''.$startdate.'\'';
	}
	if (!empty($enddate)) {
		$sql .= ' AND testuser_creation_time<=\''.$enddate.'\'';
	}
	$sql .= ' GROUP BY module_id, subject_id, question_id, module_name, subject_name, subject_description, question_description';
	if (($user_id > 0) AND ($testuser_id > 0)) {
Nicola Asuni's avatar
Nicola Asuni committed
264
		$sql .= ', testlog_score, testlog_user_ip, testlog_display_time, testlog_change_time, testlog_reaction_time, testlog_answer_text, question_type, question_explanation';
nicolaasuni's avatar
9.0.026    
nicolaasuni committed
265
	} else {
Nicola Asuni's avatar
Nicola Asuni committed
266
		$sql .= ' ORDER BY module_name, subject_name, question_description';
nicolaasuni's avatar
9.0.026    
nicolaasuni committed
267
	}
Nicola Asuni's avatar
Nicola Asuni committed
268
	if ($r = F_db_query($sql, $db)) {
tecnickcom's avatar
tecnickcom committed
269
		while ($m = F_db_fetch_array($r)) {
Nicola Asuni's avatar
Nicola Asuni committed
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
			if (!isset($data['qstats']['module']['\''.$m['module_id'].'\''])) {
				$data['qstats']['module']['\''.$m['module_id'].'\''] = array(
					'id' => $m['module_id'],
					'name' => $m['module_name'],
					'recurrence' => 0,
					'recurrence_perc' => 0,
					'average_score' => 0,
					'average_score_perc' => 0,
					'average_time' => 0,
					'right' => 0,
					'right_perc' => 0,
					'wrong' => 0,
					'wrong_perc' => 0,
					'unanswered' => 0,
					'unanswered_perc' => 0,
					'undisplayed' => 0,
					'undisplayed_perc' => 0,
					'unrated' => 0,
					'unrated_perc' => 0,
					'qnum' => 0,
					'subject' => array());
			}
			if (!isset($data['qstats']['module']['\''.$m['module_id'].'\'']['subject']['\''.$m['subject_id'].'\''])) {
				$data['qstats']['module']['\''.$m['module_id'].'\'']['subject']['\''.$m['subject_id'].'\''] = array(
					'id' => $m['subject_id'],
					'name' => $m['subject_name'],
					'description' => $m['subject_description'],
					'recurrence' => 0,
					'recurrence_perc' => 0,
					'average_score' => 0,
					'average_score_perc' => 0,
					'average_time' => 0,
					'right' => 0,
					'right_perc' => 0,
					'wrong' => 0,
					'wrong_perc' => 0,
					'unanswered' => 0,
					'unanswered_perc' => 0,
					'undisplayed' => 0,
					'undisplayed_perc' => 0,
					'unrated' => 0,
					'unrated_perc' => 0,
					'qnum' => 0,
					'question' => array());
			}
			$question_max_score = ($testdata['test_score_right'] * $m['question_difficulty']);
			$question_half_score = ($question_max_score / 2);
			$qright = F_count_rows($sqltot, $sqlw.' AND testlog_question_id='.$m['question_id'].' AND testlog_score>'.$question_half_score.'');
			$qwrong = F_count_rows($sqltot, $sqlw.' AND testlog_question_id='.$m['question_id'].' AND testlog_score<='.$question_half_score.'');
			$qunanswered = F_count_rows($sqltot, $sqlw.' AND testlog_question_id='.$m['question_id'].' AND testlog_change_time IS NULL');
			$qundisplayed = F_count_rows($sqltot, $sqlw.' AND testlog_question_id='.$m['question_id'].' AND testlog_display_time IS NULL');
			$qunrated = F_count_rows($sqltot, $sqlw.' AND testlog_question_id='.$m['question_id'].' AND testlog_score IS NULL');
			if (stripos($m['average_time'], ':') !== FALSE) {
				// PostgreSQL returns formatted time, while MySQL returns the number of seconds
				$m['average_time'] = strtotime($m['average_time']);
			}
			$num_all_answers = F_count_rows($sqltb, $sqlansw.' AND testlog_question_id='.$m['question_id']);
			if (!isset($data['qstats']['module']['\''.$m['module_id'].'\'']['subject']['\''.$m['subject_id'].'\'']['question']['\''.$m['question_id'].'\''])) {
				$data['qstats']['module']['\''.$m['module_id'].'\'']['subject']['\''.$m['subject_id'].'\'']['question']['\''.$m['question_id'].'\''] = array(
					'id' => $m['question_id'],
					'description' => $m['question_description'],
					'type' => $m['question_type'],
					'difficulty' => $m['question_difficulty'],
					'recurrence' => 0,
					'recurrence_perc' => 0,
					'average_score' => 0,
					'average_score_perc' => 0,
					'average_time' => 0,
					'right' => 0,
					'right_perc' => 0,
					'wrong' => 0,
					'wrong_perc' => 0,
					'unanswered' => 0,
					'unanswered_perc' => 0,
					'undisplayed' => 0,
					'undisplayed_perc' => 0,
					'unrated' => 0,
					'unrated_perc' => 0,
					'qnum' => 0,
					'anum' => 0,
					'answer' => array());
			}
nick's avatar
nick committed
352

Nicola Asuni's avatar
Nicola Asuni committed
353
			// average score ratio
tecnickcom's avatar
tecnickcom committed
354
355
356
357
358
			if ($question_max_score > 0) {
				$average_score_perc = ($m['average_score'] / $question_max_score);
			} else {
				$average_score_perc = 0;
			}
nick's avatar
nick committed
359

Nicola Asuni's avatar
Nicola Asuni committed
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
			// sum values for questions
			$data['qstats']['module']['\''.$m['module_id'].'\'']['subject']['\''.$m['subject_id'].'\'']['question']['\''.$m['question_id'].'\'']['qnum'] += 1;
			$data['qstats']['module']['\''.$m['module_id'].'\'']['subject']['\''.$m['subject_id'].'\'']['question']['\''.$m['question_id'].'\'']['recurrence'] += $m['recurrence'];
			$data['qstats']['module']['\''.$m['module_id'].'\'']['subject']['\''.$m['subject_id'].'\'']['question']['\''.$m['question_id'].'\'']['average_score'] += $m['average_score'];
			$data['qstats']['module']['\''.$m['module_id'].'\'']['subject']['\''.$m['subject_id'].'\'']['question']['\''.$m['question_id'].'\'']['average_score_perc'] += $average_score_perc;
			$data['qstats']['module']['\''.$m['module_id'].'\'']['subject']['\''.$m['subject_id'].'\'']['question']['\''.$m['question_id'].'\'']['average_time'] += $m['average_time'];
			$data['qstats']['module']['\''.$m['module_id'].'\'']['subject']['\''.$m['subject_id'].'\'']['question']['\''.$m['question_id'].'\'']['right'] += $qright;
			$data['qstats']['module']['\''.$m['module_id'].'\'']['subject']['\''.$m['subject_id'].'\'']['question']['\''.$m['question_id'].'\'']['wrong'] += $qwrong;
			$data['qstats']['module']['\''.$m['module_id'].'\'']['subject']['\''.$m['subject_id'].'\'']['question']['\''.$m['question_id'].'\'']['unanswered'] += $qunanswered;
			$data['qstats']['module']['\''.$m['module_id'].'\'']['subject']['\''.$m['subject_id'].'\'']['question']['\''.$m['question_id'].'\'']['undisplayed'] += $qundisplayed;
			$data['qstats']['module']['\''.$m['module_id'].'\'']['subject']['\''.$m['subject_id'].'\'']['question']['\''.$m['question_id'].'\'']['unrated'] += $qunrated;
			$data['qstats']['module']['\''.$m['module_id'].'\'']['subject']['\''.$m['subject_id'].'\'']['question']['\''.$m['question_id'].'\'']['anum'] += $num_all_answers;

			// sum values for subject
			$data['qstats']['module']['\''.$m['module_id'].'\'']['subject']['\''.$m['subject_id'].'\'']['qnum'] += 1;
			$data['qstats']['module']['\''.$m['module_id'].'\'']['subject']['\''.$m['subject_id'].'\'']['recurrence'] += $m['recurrence'];
			$data['qstats']['module']['\''.$m['module_id'].'\'']['subject']['\''.$m['subject_id'].'\'']['average_score'] += $m['average_score'];
			$data['qstats']['module']['\''.$m['module_id'].'\'']['subject']['\''.$m['subject_id'].'\'']['average_score_perc'] += $average_score_perc;
			$data['qstats']['module']['\''.$m['module_id'].'\'']['subject']['\''.$m['subject_id'].'\'']['average_time'] += $m['average_time'];
			$data['qstats']['module']['\''.$m['module_id'].'\'']['subject']['\''.$m['subject_id'].'\'']['right'] += $qright;
			$data['qstats']['module']['\''.$m['module_id'].'\'']['subject']['\''.$m['subject_id'].'\'']['wrong'] += $qwrong;
			$data['qstats']['module']['\''.$m['module_id'].'\'']['subject']['\''.$m['subject_id'].'\'']['unanswered'] += $qunanswered;
			$data['qstats']['module']['\''.$m['module_id'].'\'']['subject']['\''.$m['subject_id'].'\'']['undisplayed'] += $qundisplayed;
			$data['qstats']['module']['\''.$m['module_id'].'\'']['subject']['\''.$m['subject_id'].'\'']['unrated'] += $qunrated;

			// sum values for module
			$data['qstats']['module']['\''.$m['module_id'].'\'']['qnum'] += 1;
			$data['qstats']['module']['\''.$m['module_id'].'\'']['recurrence'] += $m['recurrence'];
			$data['qstats']['module']['\''.$m['module_id'].'\'']['average_score'] += $m['average_score'];
			$data['qstats']['module']['\''.$m['module_id'].'\'']['average_score_perc'] += $average_score_perc;
			$data['qstats']['module']['\''.$m['module_id'].'\'']['average_time'] += $m['average_time'];
			$data['qstats']['module']['\''.$m['module_id'].'\'']['right'] += $qright;
			$data['qstats']['module']['\''.$m['module_id'].'\'']['wrong'] += $qwrong;
			$data['qstats']['module']['\''.$m['module_id'].'\'']['unanswered'] += $qunanswered;
			$data['qstats']['module']['\''.$m['module_id'].'\'']['undisplayed'] += $qundisplayed;
			$data['qstats']['module']['\''.$m['module_id'].'\'']['unrated'] += $qunrated;
nick's avatar
nick committed
396

Nicola Asuni's avatar
Nicola Asuni committed
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
			// sum totals
			$data['qstats']['qnum'] += 1;
			$data['qstats']['recurrence'] += $m['recurrence'];
			$data['qstats']['average_score'] += $m['average_score'];
			$data['qstats']['average_score_perc'] += $average_score_perc;
			$data['qstats']['average_time'] += $m['average_time'];
			$data['qstats']['right'] += $qright;
			$data['qstats']['wrong'] += $qwrong;
			$data['qstats']['unanswered'] += $qunanswered;
			$data['qstats']['undisplayed'] += $qundisplayed;
			$data['qstats']['unrated'] += $qunrated;

			// get answer statistics
			$sqlaa = 'SELECT answer_id, answer_description, COUNT(answer_id) AS recurrence';
			if (($user_id > 0) AND ($testuser_id > 0)) {
				$sqlaa .= ', logansw_position, logansw_selected, answer_isright, answer_position, answer_explanation';
			}
			$sqlaa .= ' FROM '.$sqltb.'';
			$sqlaw = ' WHERE testlog_testuser_id=testuser_id
					AND logansw_testlog_id=testlog_id
					AND answer_id=logansw_answer_id
					AND answer_question_id='.$m['question_id'].'';
			if ($test_id > 0) {
				$sqlaw .= ' AND testuser_test_id='.$test_id.'';
			}
			if ($user_id > 0) {
				$sqlaw .= ' AND testuser_user_id='.$user_id.'';
			}
			if ($testuser_id > 0) {
				$sqlaw .= ' AND testuser_id='.$testuser_id.'';
			}
			if ($user_id > 0) {
				$sqlaw .= ' AND testuser_user_id=user_id AND user_id='.$user_id.'';
			} elseif ($group_id > 0) {
				$sqlaw .= ' AND testuser_user_id=user_id AND usrgrp_user_id=user_id AND usrgrp_group_id='.$group_id.'';
			}
			if (!empty($startdate)) {
				$sql .= ' AND testuser_creation_time>=\''.$startdate.'\'';
			}
			if (!empty($enddate)) {
				$sql.= ' AND testuser_creation_time<=\''.$enddate.'\'';
			}
			$sqlab = ' GROUP BY answer_id, answer_description';

			if (($user_id > 0) AND ($testuser_id > 0)) {
				$sqlab .= ', logansw_position, logansw_selected, answer_isright, answer_position, answer_explanation';
			}
			$sqlab .= ' ORDER BY answer_description';
			$sqla = $sqlaa.$sqlaw.$sqlab;
			if ($ra = F_db_query($sqla, $db)) {
tecnickcom's avatar
tecnickcom committed
447
				while ($ma = F_db_fetch_array($ra)) {
Nicola Asuni's avatar
Nicola Asuni committed
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477

					$aright = F_count_rows($sqltb, $sqlaw.' AND answer_id='.$ma['answer_id'].' AND ((answer_isright=\'0\' AND logansw_selected=0) OR (answer_isright=\'1\' AND logansw_selected=1) OR (answer_position IS NOT NULL AND logansw_position IS NOT NULL AND answer_position=logansw_position))');
					$awrong = F_count_rows($sqltb, $sqlaw.' AND answer_id='.$ma['answer_id'].' AND ((answer_isright=\'0\' AND logansw_selected=1) OR (answer_isright=\'1\' AND logansw_selected=0) OR (answer_position IS NOT NULL AND answer_position!=logansw_position))');
					$aunanswered = F_count_rows($sqltb, $sqlaw.' AND answer_id='.$ma['answer_id'].' AND logansw_selected=-1');
					if (!isset($data['qstats']['module']['\''.$m['module_id'].'\'']['subject']['\''.$m['subject_id'].'\'']['question']['\''.$m['question_id'].'\'']['answer']['\''.$ma['answer_id'].'\''])) {
							$data['qstats']['module']['\''.$m['module_id'].'\'']['subject']['\''.$m['subject_id'].'\'']['question']['\''.$m['question_id'].'\'']['answer']['\''.$ma['answer_id'].'\''] = array(
							'id' => $ma['answer_id'],
							'description' => $ma['answer_description'],
							'recurrence' => 0,
							'recurrence_perc' => 0,
							'right' => 0,
							'right_perc' => 0,
							'wrong' => 0,
							'wrong_perc' => 0,
							'unanswered' => 0,
							'unanswered_perc' => 0);
					}

					$data['qstats']['module']['\''.$m['module_id'].'\'']['subject']['\''.$m['subject_id'].'\'']['question']['\''.$m['question_id'].'\'']['answer']['\''.$ma['answer_id'].'\'']['recurrence'] += $ma['recurrence'];
					$data['qstats']['module']['\''.$m['module_id'].'\'']['subject']['\''.$m['subject_id'].'\'']['question']['\''.$m['question_id'].'\'']['answer']['\''.$ma['answer_id'].'\'']['right'] += $aright;
					$data['qstats']['module']['\''.$m['module_id'].'\'']['subject']['\''.$m['subject_id'].'\'']['question']['\''.$m['question_id'].'\'']['answer']['\''.$ma['answer_id'].'\'']['wrong'] += $awrong;
					$data['qstats']['module']['\''.$m['module_id'].'\'']['subject']['\''.$m['subject_id'].'\'']['question']['\''.$m['question_id'].'\'']['answer']['\''.$ma['answer_id'].'\'']['unanswered'] += $aunanswered;
				}
			} else {
				F_display_db_error();
			}
		}
	} else {
		F_display_db_error();
	}
nicolaasuni's avatar
9.0.026    
nicolaasuni committed
478
479
480
481
	return $data;
}

/**
Nicola Asuni's avatar
Nicola Asuni committed
482
483
484
 * Calculate average values from TestStat array
 * @param $data (array) Raw data array.
 * return $data (array) Processed array.
nicolaasuni's avatar
9.0.026    
nicolaasuni committed
485
 */
Nicola Asuni's avatar
Nicola Asuni committed
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
function F_normalizeTestStatAverages($data) {
	if (!isset($data['qstats']['recurrence']) OR ($data['qstats']['recurrence'] <= 0)) {
		return $data;
	}
	// calculate totals and average values
	$data['qstats']['recurrence_perc'] = 100;
	$data['qstats']['average_score'] = ($data['qstats']['average_score'] / $data['qstats']['qnum']);
	$data['qstats']['average_score_perc'] = round(100 * $data['qstats']['average_score_perc'] / $data['qstats']['recurrence']);
	$data['qstats']['average_time'] = ($data['qstats']['average_time'] / $data['qstats']['qnum']);
	$data['qstats']['right_perc'] = round(100 * $data['qstats']['right'] / $data['qstats']['recurrence']);
	$data['qstats']['wrong_perc'] = round(100 * $data['qstats']['wrong'] / $data['qstats']['recurrence']);
	$data['qstats']['unanswered_perc'] = round(100 * $data['qstats']['unanswered'] / $data['qstats']['recurrence']);
	$data['qstats']['undisplayed_perc'] = round(100 * $data['qstats']['undisplayed'] / $data['qstats']['recurrence']);
	$data['qstats']['unrated_perc'] = round(100 * $data['qstats']['unrated'] / $data['qstats']['recurrence']);
	foreach ($data['qstats']['module'] AS $mk => $mv) {
		$data['qstats']['module'][$mk]['recurrence_perc'] = round(100 * $mv['recurrence'] / $data['qstats']['recurrence']);
		$data['qstats']['module'][$mk]['average_score'] = ($mv['average_score'] / $mv['qnum']);
		$data['qstats']['module'][$mk]['average_score_perc'] = round(100 * $mv['average_score_perc'] / $mv['recurrence']);
		$data['qstats']['module'][$mk]['average_time'] = ($mv['average_time'] / $mv['qnum']);
		$data['qstats']['module'][$mk]['right_perc'] = round(100 * $mv['right'] / $mv['recurrence']);
		$data['qstats']['module'][$mk]['wrong_perc'] = round(100 * $mv['wrong'] / $mv['recurrence']);
		$data['qstats']['module'][$mk]['unanswered_perc'] = round(100 * $mv['unanswered'] / $mv['recurrence']);
		$data['qstats']['module'][$mk]['undisplayed_perc'] = round(100 * $mv['undisplayed'] / $mv['recurrence']);
		$data['qstats']['module'][$mk]['unrated_perc'] = round(100 * $mv['unrated'] / $mv['recurrence']);
		foreach ($mv['subject'] AS $sk => $sv) {
			$data['qstats']['module'][$mk]['subject'][$sk]['recurrence_perc'] = round(100 * $sv['recurrence'] / $data['qstats']['recurrence']);
			$data['qstats']['module'][$mk]['subject'][$sk]['average_score'] = ($sv['average_score'] / $sv['qnum']);
			$data['qstats']['module'][$mk]['subject'][$sk]['average_score_perc'] = round(100 * $sv['average_score_perc'] / $sv['recurrence']);
			$data['qstats']['module'][$mk]['subject'][$sk]['average_time'] = ($sv['average_time'] / $sv['qnum']);
			$data['qstats']['module'][$mk]['subject'][$sk]['right_perc'] = round(100 * $sv['right'] / $sv['recurrence']);
			$data['qstats']['module'][$mk]['subject'][$sk]['wrong_perc'] = round(100 * $sv['wrong'] / $sv['recurrence']);
			$data['qstats']['module'][$mk]['subject'][$sk]['unanswered_perc'] = round(100 * $sv['unanswered'] / $sv['recurrence']);
			$data['qstats']['module'][$mk]['subject'][$sk]['undisplayed_perc'] = round(100 * $sv['undisplayed'] / $sv['recurrence']);
			$data['qstats']['module'][$mk]['subject'][$sk]['unrated_perc'] = round(100 * $sv['unrated'] / $sv['recurrence']);
			foreach ($sv['question'] AS $qk => $qv) {
				$data['qstats']['module'][$mk]['subject'][$sk]['question'][$qk]['recurrence_perc'] = round(100 * $qv['recurrence'] / $data['qstats']['recurrence']);
				$data['qstats']['module'][$mk]['subject'][$sk]['question'][$qk]['average_score'] = ($qv['average_score'] / $qv['qnum']);
				$data['qstats']['module'][$mk]['subject'][$sk]['question'][$qk]['average_score_perc'] = round(100 * $qv['average_score_perc'] / $qv['recurrence']);
				$data['qstats']['module'][$mk]['subject'][$sk]['question'][$qk]['average_time'] = ($qv['average_time'] / $qv['qnum']);
				$data['qstats']['module'][$mk]['subject'][$sk]['question'][$qk]['right_perc'] = round(100 * $qv['right'] / $qv['recurrence']);
				$data['qstats']['module'][$mk]['subject'][$sk]['question'][$qk]['wrong_perc'] = round(100 * $qv['wrong'] / $qv['recurrence']);
				$data['qstats']['module'][$mk]['subject'][$sk]['question'][$qk]['unanswered_perc'] = round(100 * $qv['unanswered'] / $qv['recurrence']);
				$data['qstats']['module'][$mk]['subject'][$sk]['question'][$qk]['undisplayed_perc'] = round(100 * $qv['undisplayed'] / $qv['recurrence']);
				$data['qstats']['module'][$mk]['subject'][$sk]['question'][$qk]['unrated_perc'] = round(100 * $qv['unrated'] / $qv['recurrence']);
				foreach ($qv['answer'] AS $ak => $av) {
					$data['qstats']['module'][$mk]['subject'][$sk]['question'][$qk]['answer'][$ak]['recurrence_perc'] = round(100 * $av['recurrence'] / $qv['anum']);
					$data['qstats']['module'][$mk]['subject'][$sk]['question'][$qk]['answer'][$ak]['right_perc'] = round(100 * $av['right'] / $av['recurrence']);
					$data['qstats']['module'][$mk]['subject'][$sk]['question'][$qk]['answer'][$ak]['wrong_perc'] = round(100 * $av['wrong'] / $av['recurrence']);
					$data['qstats']['module'][$mk]['subject'][$sk]['question'][$qk]['answer'][$ak]['unanswered_perc'] = round(100 * $av['unanswered'] / $av['recurrence']);
				}
			}
		}
	}
	return $data;
}

/**
* Returns test stats as HTML table
* @param $test_id (int) test ID.
* @param $group_id (int) group ID - if greater than zero, filter stats for the specified user group.
* @param $user_id (int) user ID - if greater than zero, filter stats for the specified user.
* @param $startdate (int) start date ID - if greater than zero, filter stats for the specified starting date
* @param $enddate (int) end date ID - if greater than zero, filter stats for the specified ending date
* @param $testuser_id (int) test-user ID - if greater than zero, filter stats for the specified test-user.
* @param $ts (array) array of stats to print (leave empty to automatically generate new data).
tecnickcom's avatar
tecnickcom committed
551
* @param $display_mode display (int) mode: 0 = disabled; 1 = minimum; 2 = module; 3 = subject; 4 = question; 5 = answer.
Nicola Asuni's avatar
Nicola Asuni committed
552
553
554
* @param $pubmode (boolean) If true filter the results for the public interface.
* return $data string containing HTML table.
*/
tecnickcom's avatar
tecnickcom committed
555
556
557
558
function F_printTestStat($test_id, $group_id=0, $user_id=0, $startdate=0, $enddate=0, $testuser_id=0, $ts=array(), $display_mode=2, $pubmode=false) {
	if ($display_mode < 2) {
		return;
	}
nicolaasuni's avatar
9.0.026    
nicolaasuni committed
559
	require_once('../config/tce_config.php');
Nicola Asuni's avatar
Nicola Asuni committed
560
	require_once('../../shared/code/tce_functions_tcecode.php');
nicolaasuni's avatar
9.0.026    
nicolaasuni committed
561
	global $db, $l;
Nicola Asuni's avatar
Nicola Asuni committed
562
563
564
	if (empty($ts['qstats']['recurrence'])) {
		return;
	}
nicolaasuni's avatar
9.0.026    
nicolaasuni committed
565
566
	$test_id = intval($test_id);
	$user_id = intval($user_id);
Nicola Asuni's avatar
Nicola Asuni committed
567
568
569
570
571
572
573
574
575
576
577
578
579
	$testuser_id = intval($testuser_id);
	if (empty($ts)) {
		// get statistics array
		$ts = F_getTestStat($test_id, $group_id, $user_id, $startdate, $enddate, $testuser_id, $pubmode);
	}
	if ($l['a_meta_dir'] == 'rtl') {
		$txtdir = 'right';
	} else {
		$txtdir = 'left';
	}
	$ret = '';
	$ret .= '<table class="userselect">'.K_NEWLINE;
	$ret .= '<tr><td colspan="12" style="background-color:#DDDDDD;"><strong>'.$l['w_statistics'].' ['.$l['w_all'].' + '.$l['w_module'].'';
tecnickcom's avatar
tecnickcom committed
580
	if ($display_mode > 2) {
Nicola Asuni's avatar
Nicola Asuni committed
581
		$ret .= ' + '.$l['w_subject'].'';
tecnickcom's avatar
tecnickcom committed
582
		if ($display_mode > 3) {
Nicola Asuni's avatar
Nicola Asuni committed
583
			$ret .= ' + '.$l['w_question'].'';
tecnickcom's avatar
tecnickcom committed
584
			if ($display_mode > 4) {
Nicola Asuni's avatar
Nicola Asuni committed
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
				$ret .= ' + '.$l['w_answer'].'';
			}
		}
	}
	$ret .= ']</strong></td></tr>'.K_NEWLINE;
	$ret .= '<tr>'.K_NEWLINE;
	$ret .= '<th title="'.$l['w_module'].'">M#</th>'.K_NEWLINE;
	$ret .= '<th title="'.$l['w_subject'].'">S#</th>'.K_NEWLINE;
	$ret .= '<th title="'.$l['w_question'].'">Q#</th>'.K_NEWLINE;
	$ret .= '<th title="'.$l['w_answer'].'">A#</th>'.K_NEWLINE;
	$ret .= '<th title="'.$l['h_question_recurrence'].'">'.$l['w_recurrence'].'</th>'.K_NEWLINE;
	$ret .= '<th title="'.$l['h_score_average'].'">'.$l['w_score'].'</th>'.K_NEWLINE;
	$ret .= '<th title="'.$l['h_answer_time'].'">'.$l['w_answer_time'].'</th>'.K_NEWLINE;
	$ret .= '<th title="'.$l['h_answers_right'].'">'.$l['w_answers_right'].'</th>'.K_NEWLINE;
	$ret .= '<th title="'.$l['h_answers_wrong'].'">'.$l['w_answers_wrong'].'</th>'.K_NEWLINE;
	$ret .= '<th title="'.$l['h_questions_unanswered'].'">'.$l['w_questions_unanswered'].'</th>'.K_NEWLINE;
	$ret .= '<th title="'.$l['h_questions_undisplayed'].'">'.$l['w_questions_undisplayed'].'</th>'.K_NEWLINE;
	$ret .= '<th title="'.$l['h_questions_unrated'].'">'.$l['w_questions_unrated'].'</th>'.K_NEWLINE;
	$ret .= '</tr>'.K_NEWLINE;
	$ret .= '<tr style="background-color:#FFEEEE;">';
	$ret .= '<td colspan="4">'.$l['w_all'].'</td>'.K_NEWLINE;
	$ret .= '<td class="numeric">'.$ts['qstats']['recurrence'].' '.F_formatPercentage($ts['qstats']['recurrence_perc'], false).'</td>'.K_NEWLINE;
	$ret .= '<td class="numeric">'.($ts['qstats']['average_score_perc']).'%</td>'.K_NEWLINE;
	$ret .= '<td class="numeric">&nbsp;'.date('i:s', $ts['qstats']['average_time']).'</td>'.K_NEWLINE;
	$ret .= '<td class="numeric">'.$ts['qstats']['right'].' '.F_formatPercentage($ts['qstats']['right_perc'], false).'</td>'.K_NEWLINE;
	$ret .= '<td class="numeric">'.$ts['qstats']['wrong'].' '.F_formatPercentage($ts['qstats']['wrong_perc'], false).'</td>'.K_NEWLINE;
	$ret .= '<td class="numeric">'.$ts['qstats']['unanswered'].' '.F_formatPercentage($ts['qstats']['unanswered_perc'], false).'</td>'.K_NEWLINE;
	$ret .= '<td class="numeric">'.$ts['qstats']['undisplayed'].' '.F_formatPercentage($ts['qstats']['undisplayed_perc'], false).'</td>'.K_NEWLINE;
	$ret .= '<td class="numeric">'.$ts['qstats']['unrated'].' '.F_formatPercentage($ts['qstats']['unrated_perc'], false).'</td>'.K_NEWLINE;
	$ret .= '</tr>'.K_NEWLINE;
	$num_module = 0;
	foreach ($ts['qstats']['module'] as $module) {
		$num_module++;
		$ret .= '<tr style="background-color:#DDEEFF;">';
		if ($pubmode) {
			$ret .= '<td rowspan="2" valign="middle"><strong>M'.$num_module.'</strong></td>'.K_NEWLINE;
		} else {
			$ret .= '<td rowspan="2" valign="middle"><a href="tce_edit_module.php?module_id='.$module['id'].'" title="'.$l['t_modules_editor'].'"><strong>M'.$num_module.'</strong></a></td>'.K_NEWLINE;
		}
		$ret .= '<td rowspan="2" colspan="3">&nbsp;</td>'.K_NEWLINE;
		$ret .= '<td class="numeric">'.$module['recurrence'].' '.F_formatPercentage($module['recurrence_perc'], false).'</td>'.K_NEWLINE;
		$ret .= '<td class="numeric">'.($module['average_score_perc']).'%</td>'.K_NEWLINE;
		$ret .= '<td class="numeric">&nbsp;'.date('i:s', $module['average_time']).'</td>'.K_NEWLINE;
		$ret .= '<td class="numeric">'.$module['right'].' '.F_formatPercentage($module['right_perc'], false).'</td>'.K_NEWLINE;
		$ret .= '<td class="numeric">'.$module['wrong'].' '.F_formatPercentage($module['wrong_perc'], false).'</td>'.K_NEWLINE;
		$ret .= '<td class="numeric">'.$module['unanswered'].' '.F_formatPercentage($module['unanswered_perc'], false).'</td>'.K_NEWLINE;
		$ret .= '<td class="numeric">'.$module['undisplayed'].' '.F_formatPercentage($module['undisplayed_perc'], false).'</td>'.K_NEWLINE;
		$ret .= '<td class="numeric">'.$module['unrated'].' '.F_formatPercentage($module['unrated_perc'], false).'</td>'.K_NEWLINE;
		$ret .= '</tr>'.K_NEWLINE;
		$ret .= '<tr>';
		$ret .= '<td colspan="8" align="'.$txtdir.'" style="background-color:white;">'.F_decode_tcecode($module['name']).'</td>';
		$ret .= '</tr>'.K_NEWLINE;
tecnickcom's avatar
tecnickcom committed
637
		if ($display_mode > 2) {
Nicola Asuni's avatar
Nicola Asuni committed
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
			$num_subject = 0;
			foreach ($module['subject'] as $subject) {
				$num_subject++;
				$ret .= '<tr style="background-color:#DDFFDD;">';
				$ret .= '<td rowspan="2" style="background-color:#DDEEFF;">M'.$num_module.'</td>'.K_NEWLINE;
				if ($pubmode) {
					$ret .= '<td rowspan="2" valign="middle"><strong>S'.$num_subject.'</strong></td>'.K_NEWLINE;
				} else {
					$ret .= '<td rowspan="2" valign="middle"><a href="tce_edit_subject.php?subject_id='.$subject['id'].'" title="'.$l['t_subjects_editor'].'"><strong>S'.$num_subject.'</strong></a></td>'.K_NEWLINE;
				}
				$ret .= '<td rowspan="2" colspan="2">&nbsp;</td>'.K_NEWLINE;
				$ret .= '<td class="numeric">'.$subject['recurrence'].' '.F_formatPercentage($subject['recurrence_perc'], false).'</td>'.K_NEWLINE;
				$ret .= '<td class="numeric">'.($subject['average_score_perc']).'%</td>'.K_NEWLINE;
				$ret .= '<td class="numeric">&nbsp;'.date('i:s', $subject['average_time']).'</td>'.K_NEWLINE;
				$ret .= '<td class="numeric">'.$subject['right'].' '.F_formatPercentage($subject['right_perc'], false).'</td>'.K_NEWLINE;
				$ret .= '<td class="numeric">'.$subject['wrong'].' '.F_formatPercentage($subject['wrong_perc'], false).'</td>'.K_NEWLINE;
				$ret .= '<td class="numeric">'.$subject['unanswered'].' '.F_formatPercentage($subject['unanswered_perc'], false).'</td>'.K_NEWLINE;
				$ret .= '<td class="numeric">'.$subject['undisplayed'].' '.F_formatPercentage($subject['undisplayed_perc'], false).'</td>'.K_NEWLINE;
				$ret .= '<td class="numeric">'.$subject['unrated'].' '.F_formatPercentage($subject['unrated_perc'], false).'</td>'.K_NEWLINE;
				$ret .= '</tr>'.K_NEWLINE;
				$ret .= '<tr>';
				$ret .= '<td colspan="8" align="'.$txtdir.'" style="background-color:white;">'.F_decode_tcecode($subject['name']).'</td>';
				$ret .= '</tr>'.K_NEWLINE;
tecnickcom's avatar
tecnickcom committed
661
				if ($display_mode > 3) {
Nicola Asuni's avatar
Nicola Asuni committed
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
					$num_question = 0;
					foreach ($subject['question'] as $question) {
						$num_question++;
						$ret .= '<tr style="background-color:#FFFACD;">';
						$ret .= '<td rowspan="2" style="background-color:#DDEEFF;">M'.$num_module.'</td>'.K_NEWLINE;
						$ret .= '<td rowspan="2" style="background-color:#DDFFDD;">S'.$num_subject.'</td>'.K_NEWLINE;
						if ($pubmode) {
							$ret .= '<td rowspan="2" valign="middle"><strong>Q'.$num_question.'</strong></td>'.K_NEWLINE;
						} else {
							$ret .= '<td rowspan="2" valign="middle"><a href="tce_edit_question.php?question_id='.$question['id'].'" title="'.$l['t_questions_editor'].'"><strong>Q'.$num_question.'</strong></a></td>'.K_NEWLINE;
						}
						$ret .= '<td rowspan="2">&nbsp;</td>'.K_NEWLINE;
						$ret .= '<td class="numeric">'.$question['recurrence'].' '.F_formatPercentage($question['recurrence_perc'], false).'</td>'.K_NEWLINE;
						$ret .= '<td class="numeric">'.($question['average_score_perc']).'%</td>'.K_NEWLINE;
						$ret .= '<td class="numeric">&nbsp;'.date('i:s', $question['average_time']).'</td>'.K_NEWLINE;
						$ret .= '<td class="numeric">'.$question['right'].' '.F_formatPercentage($question['right_perc'], false).'</td>'.K_NEWLINE;
						$ret .= '<td class="numeric">'.$question['wrong'].' '.F_formatPercentage($question['wrong_perc'], false).'</td>'.K_NEWLINE;
						$ret .= '<td class="numeric">'.$question['unanswered'].' '.F_formatPercentage($question['unanswered_perc'], false).'</td>'.K_NEWLINE;
						$ret .= '<td class="numeric">'.$question['undisplayed'].' '.F_formatPercentage($question['undisplayed_perc'], false).'</td>'.K_NEWLINE;
						$ret .= '<td class="numeric">'.$question['unrated'].' '.F_formatPercentage($question['unrated_perc'], false).'</td>'.K_NEWLINE;
						$ret .= '</tr>'.K_NEWLINE;
						$ret .= '<tr>';
						$ret .= '<td colspan="8" align="'.$txtdir.'" style="background-color:white;">'.F_decode_tcecode($question['description']).'</td>';
						$ret .= '</tr>'.K_NEWLINE;
tecnickcom's avatar
tecnickcom committed
686
						if ($display_mode > 4) {
Nicola Asuni's avatar
Nicola Asuni committed
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
							$num_answer = 0;
							foreach ($question['answer'] as $answer) {
								$num_answer++;
								$ret .= '<tr style="">';
								$ret .= '<td rowspan="2" style="background-color:#DDEEFF;">M'.$num_module.'</td>'.K_NEWLINE;
								$ret .= '<td rowspan="2" style="background-color:#DDFFDD;">S'.$num_subject.'</td>'.K_NEWLINE;
								$ret .= '<td rowspan="2" style="background-color:#FFFACD;">Q'.$num_question.'</td>'.K_NEWLINE;
								if ($pubmode) {
									$ret .= '<td rowspan="2" valign="middle"><strong>A'.$num_answer.'</strong></td>'.K_NEWLINE;
								} else {
									$ret .= '<td rowspan="2" valign="middle"><a href="tce_edit_answer.php?answer_id='.$answer['id'].'" title="'.$l['t_answers_editor'].'"><strong>A'.$num_answer.'</strong></a></td>'.K_NEWLINE;
								}
								$ret .= '<td class="numeric">'.$answer['recurrence'].' '.F_formatPercentage($answer['recurrence_perc'], false).'</td>'.K_NEWLINE;
								$ret .= '<td class="numeric">&nbsp;</td>'.K_NEWLINE;
								$ret .= '<td class="numeric">&nbsp;</td>'.K_NEWLINE;
								$ret .= '<td class="numeric">'.$answer['right'].' '.F_formatPercentage($answer['right_perc'], false).'</td>'.K_NEWLINE;
								$ret .= '<td class="numeric">'.$answer['wrong'].' '.F_formatPercentage($answer['wrong_perc'], false).'</td>'.K_NEWLINE;
								$ret .= '<td class="numeric">'.$answer['unanswered'].' '.F_formatPercentage($answer['unanswered_perc'], false).'</td>'.K_NEWLINE;
								$ret .= '<td class="numeric">&nbsp;</td>'.K_NEWLINE;
								$ret .= '<td class="numeric">&nbsp;</td>'.K_NEWLINE;
								$ret .= '</tr>'.K_NEWLINE;
								$ret .= '<tr>';
								$ret .= '<td colspan="8" align="'.$txtdir.'" style="background-color:white;">'.F_decode_tcecode($answer['description']).'</td>';
								$ret .= '</tr>'.K_NEWLINE;
							} // end for answer
						}
					} // end for question
				}
			} // end for subject
		}
	} // end for module
	$ret .= '</table>'.K_NEWLINE;
	return $ret;
}
nick's avatar
nick committed
721

Nicola Asuni's avatar
Nicola Asuni committed
722
723
724
725
726
727
728
/**
* Returns test stats as HTML table
* @param $data (array) Array containing test statistics.
* @param $nextorderdir (int) next order direction.
* @param $order_field (string) order fields.
* @param $filter (string) filter string for URLs.
* @param $pubmode (boolean) If true filter the results for the public interface.
tecnickcom's avatar
tecnickcom committed
729
* @param $stats (int) 2 = full stats; 1 = user stats; 0 = disabled stats;
Nicola Asuni's avatar
Nicola Asuni committed
730
731
* return HTML table string.
*/
tecnickcom's avatar
tecnickcom committed
732
function F_printTestResultStat($data, $nextorderdir, $order_field, $filter, $pubmode=false, $stats=1) {
Nicola Asuni's avatar
Nicola Asuni committed
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
	require_once('../config/tce_config.php');
	global $db, $l;
	if (empty($data['num_records'])) {
		return;
	}
	if ($l['a_meta_dir'] == 'rtl') {
		$tdalignr = 'left';
		$tdalign = 'right';
	} else {
		$tdalignr = 'right';
		$tdalign = 'left';
	}
	$ret = '';
	$ret .= '<table class="userselect">'.K_NEWLINE;
	$ret .= '<tr>'.K_NEWLINE;
	$ret .= '<th>&nbsp;</th>'.K_NEWLINE;
	$ret .= '<th>#</th>'.K_NEWLINE;
	$ret .= F_select_table_header_element('testuser_creation_time', $nextorderdir, $l['h_time_begin'], $l['w_time_begin'], $order_field, $filter);
	//$ret .= F_select_table_header_element('testuser_end_time', $nextorderdir, $l['h_time_end'], $l['w_time_end'], $order_field, $filter);
	$ret .= '<th title="'.$l['h_test_time'].'">'.$l['w_time'].'</th>'.K_NEWLINE;
	$ret .= F_select_table_header_element('testuser_test_id', $nextorderdir, $l['h_test'], $l['w_test'], $order_field, $filter);
	if (!$pubmode) {
		$ret .= F_select_table_header_element('user_name', $nextorderdir, $l['h_login_name'], $l['w_user'], $order_field, $filter);
		$ret .= F_select_table_header_element('user_lastname', $nextorderdir, $l['h_lastname'], $l['w_lastname'], $order_field, $filter);
		$ret .= F_select_table_header_element('user_firstname', $nextorderdir, $l['h_firstname'], $l['w_firstname'], $order_field, $filter);
758
		$ret .= F_select_table_header_element('user_regcode', $nextorderdir, $l['h_regcode'], $l['w_regcode'], $order_field, $filter);
User expired's avatar
User expired committed
759
		$ret .= F_select_table_header_element('user_studykey', $nextorderdir, $l['h_studykey'], $l['w_studykey'], $order_field, $filter);
Nicola Asuni's avatar
Nicola Asuni committed
760
761
	}
	$ret .= F_select_table_header_element('total_score', $nextorderdir, $l['h_score_total'], $l['w_score'], $order_field, $filter);
762
	$ret .= F_select_table_header_element('total_score', $nextorderdir, $l['h_score_total'], ' %', $order_field, $filter);
tecnickcom's avatar
tecnickcom committed
763
764
765
766
767
768
769
	if ($stats > 0) {
		$ret .= '<th title="'.$l['h_answers_right'].'">'.$l['w_answers_right'].'</th>'.K_NEWLINE;
		$ret .= '<th title="'.$l['h_answers_wrong'].'">'.$l['w_answers_wrong'].'</th>'.K_NEWLINE;
		$ret .= '<th title="'.$l['h_questions_unanswered'].'">'.$l['w_questions_unanswered'].'</th>'.K_NEWLINE;
		$ret .= '<th title="'.$l['h_questions_undisplayed'].'">'.$l['w_questions_undisplayed'].'</th>'.K_NEWLINE;
		$ret .= '<th title="'.$l['h_questions_unrated'].'">'.$l['w_questions_unrated'].'</th>'.K_NEWLINE;
	}
Nicola Asuni's avatar
Nicola Asuni committed
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
	$ret .= '<th title="'.$l['w_status'].' ('.$l['w_time'].' ['.$l['w_minutes'].'])">'.$l['w_status'].' ('.$l['w_time'].' ['.$l['w_minutes'].'])</th>'.K_NEWLINE;
	$ret .= '<th title="'.$l['h_testcomment'].'">'.$l['w_comment'].'</th>'.K_NEWLINE;
	$ret .= '</tr>'.K_NEWLINE;
	foreach ($data['testuser'] as $tu) {
		$ret .= '<tr>';
		$ret .= '<td>';
		$ret .= '<input type="checkbox" name="testuserid'.$tu['num'].'" id="testuserid'.$tu['num'].'" value="'.$tu['id'].'" title="'.$l['w_select'].'"';
		if (isset($_REQUEST['checkall']) AND ($_REQUEST['checkall'] == 1)) {
			$ret .= ' checked="checked"';
		}
		$ret .= ' />';
		$ret .= '</td>'.K_NEWLINE;
		if (!$pubmode OR F_getBoolean($tu['test']['test_report_to_users'])) {
			$ret .= '<td><a href="tce_show_result_user.php?testuser_id='.$tu['id'].'&amp;test_id='.$tu['test']['test_id'].'&amp;user_id='.$tu['user_id'].'" title="'.$l['h_view_details'].'">'.$tu['num'].'</a></td>'.K_NEWLINE;
		} else {
			$ret .= '<td>'.$tu['num'].'</td>'.K_NEWLINE;
		}
		$ret .= '<td style="text-align:center;">'.$tu['testuser_creation_time'].'</td>'.K_NEWLINE;
		//$ret .= '<td style="text-align:center;">'.$tu['testuser_end_time'].'</td>'.K_NEWLINE;
		$ret .= '<td style="text-align:center;">'.$tu['time_diff'].'</td>'.K_NEWLINE;
Nicola Asuni's avatar
Nicola Asuni committed
790
791
		$passmsg = '';
		if ($tu['passmsg'] === true) {
Nicola Asuni's avatar
Nicola Asuni committed
792
			$passmsg = ' title="'.$l['w_passed'].'" style="background-color:#BBFFBB;"';
Nicola Asuni's avatar
Nicola Asuni committed
793
		} elseif ($tu['passmsg'] === false) {
Nicola Asuni's avatar
Nicola Asuni committed
794
795
796
797
798
799
800
801
802
			$passmsg = ' title="'.$l['w_not_passed'].'" style="background-color:#FFBBBB;"';
		}
		if ($pubmode) {
			$ret .= '<td style="text-align:'.$tdalign.';">'.$tu['test']['test_name'].'</td>'.K_NEWLINE;
		} else {
			$ret .= '<td style="text-align:'.$tdalign.';"><a href="tce_edit_test.php?test_id='.$tu['test']['test_id'].'">'.$tu['test']['test_name'].'</a></td>'.K_NEWLINE;
			$ret .= '<td style="text-align:'.$tdalign.';"><a href="tce_edit_user.php?user_id='.$tu['user_id'].'">'.$tu['user_name'].'</a></td>'.K_NEWLINE;
			$ret .= '<td style="text-align:'.$tdalign.';">&nbsp;'.$tu['user_lastname'].'</td>'.K_NEWLINE;
			$ret .= '<td style="text-align:'.$tdalign.';">&nbsp;'.$tu['user_firstname'].'</td>'.K_NEWLINE;
803
			$ret .= '<td style="text-align:'.$tdalign.';">&nbsp;'.$tu['user_regnumber'].'</td>'.K_NEWLINE;
User expired's avatar
User expired committed
804
			$ret .= '<td style="text-align:'.$tdalign.';">&nbsp;'.$tu['user_studykey'].'</td>'.K_NEWLINE;
Nicola Asuni's avatar
Nicola Asuni committed
805
		}
806
807
		$ret .= '<td'.$passmsg.' class="numeric">'.F_formatFloat($tu['total_score'], false).'</td>'.K_NEWLINE;
		$ret .= '<td'.$passmsg.' class="numeric">'.F_formatPercentage_woBrackets($tu['total_score_perc'], false).'</td>'.K_NEWLINE;
tecnickcom's avatar
tecnickcom committed
808
809
810
811
812
813
814
		if ($stats > 0) {
			$ret .= '<td class="numeric">'.$tu['right'].'&nbsp;'.F_formatPercentage($tu['right_perc'], false).'</td>'.K_NEWLINE;
			$ret .= '<td class="numeric">'.$tu['wrong'].'&nbsp;'.F_formatPercentage($tu['wrong_perc'], false).'</td>'.K_NEWLINE;
			$ret .= '<td class="numeric">'.$tu['unanswered'].'&nbsp;'.F_formatPercentage($tu['unanswered_perc'], false).'</td>'.K_NEWLINE;
			$ret .= '<td class="numeric">'.$tu['undisplayed'].'&nbsp;'.F_formatPercentage($tu['undisplayed_perc'], false).'</td>'.K_NEWLINE;
			$ret .= '<td class="numeric">'.$tu['unrated'].'&nbsp;'.F_formatPercentage($tu['unrated_perc'], false).'</td>'.K_NEWLINE;
		}
Nicola Asuni's avatar
Nicola Asuni committed
815
816
817
818
		if ($tu['locked']) {
			$ret .= '<td style="background-color:#FFBBBB;">'.$l['w_locked'];
		} else {
			$ret .= '<td style="background-color:#BBFFBB;">'.$l['w_unlocked'];
nicolaasuni's avatar
9.0.026    
nicolaasuni committed
819
		}
Nicola Asuni's avatar
Nicola Asuni committed
820
821
822
823
824
825
826
827
828
829
830
831
		if ($tu['remaining_time'] < 0) {
			$ret .= ' ('.$tu['remaining_time'].')';
		}
		$ret .= '</td>'.K_NEWLINE;
		if (!empty($tu['user_comment'])) {
			$ret .= '<td title="'.substr(F_compact_string(htmlspecialchars($tu['user_comment'], ENT_NOQUOTES, $l['a_meta_charset'])), 0, 255).'">'.$l['w_yes'].'</td>'.K_NEWLINE;
		} else {
			$ret .= '<td>&nbsp;</td>'.K_NEWLINE;
		}
		$ret .= '</tr>'.K_NEWLINE;
	}
	$ret .= '<tr>';
User expired's avatar
User expired committed
832
	$colspan = 19;
Nicola Asuni's avatar
Nicola Asuni committed
833
	if ($pubmode) {
tecnickcom's avatar
tecnickcom committed
834
		$colspan -= 3;
Nicola Asuni's avatar
Nicola Asuni committed
835
	}
tecnickcom's avatar
tecnickcom committed
836
837
838
839
	if ($stats == 0) {
		$colspan -= 5;
	}
	$ret .= '<td colspan="'.$colspan.'" style="text-align:'.$tdalign.';font-weight:bold;padding-right:10px;padding-left:10px;';
Nicola Asuni's avatar
Nicola Asuni committed
840
841
842
843
	if ($data['passed_perc'] > 50) {
		$ret .= ' background-color:#BBFFBB;"';
	} else {
		$ret .= ' background-color:#FFBBBB;"';
nicolaasuni's avatar
9.0.026    
nicolaasuni committed
844
	}
Nicola Asuni's avatar
Nicola Asuni committed
845
846
847
848
849
850
851
852
	$ret .= '>'.$l['w_passed'].': '.$data['passed'].' '.F_formatPercentage($data['passed_perc'], false).'</td>'.K_NEWLINE;
	$ret .= '</tr>';
	// print statistics
	$printstat = array('mean', 'median', 'mode', 'standard_deviation', 'skewness', 'kurtosi');
	$noperc = array('skewness', 'kurtosi');
	foreach ($data['statistics'] as $row => $col) {
		if (in_array($row, $printstat)) {
			$ret .= '<tr>';
User expired's avatar
User expired committed
853
			$scolspan = 9;
Nicola Asuni's avatar
Nicola Asuni committed
854
			if ($pubmode) {
tecnickcom's avatar
tecnickcom committed
855
				$scolspan -= 3;
Nicola Asuni's avatar
Nicola Asuni committed
856
			}
tecnickcom's avatar
tecnickcom committed
857
			$ret .= '<th colspan="'.$scolspan.'" style="text-align:'.$tdalignr.';">'.$l['w_'.$row].'</th>'.K_NEWLINE;
858
			$ret .='<td>&nbsp;</td><td>&nbsp;</td>';	//2 dummy cols
Nicola Asuni's avatar
Nicola Asuni committed
859
860
			if (in_array($row, $noperc)) {
				$ret .= '<td class="numeric">'.F_formatFloat($col['score_perc']).'</td>'.K_NEWLINE;
tecnickcom's avatar
tecnickcom committed
861
862
863
864
865
866
867
				if ($stats > 0) {
					$ret .= '<td class="numeric">'.F_formatFloat($col['right_perc']).'</td>'.K_NEWLINE;
					$ret .= '<td class="numeric">'.F_formatFloat($col['wrong_perc']).'</td>'.K_NEWLINE;
					$ret .= '<td class="numeric">'.F_formatFloat($col['unanswered_perc']).'</td>'.K_NEWLINE;
					$ret .= '<td class="numeric">'.F_formatFloat($col['undisplayed_perc']).'</td>'.K_NEWLINE;
					$ret .= '<td class="numeric">'.F_formatFloat($col['unrated_perc']).'</td>'.K_NEWLINE;
				}
Nicola Asuni's avatar
Nicola Asuni committed
868
869
			} else {
				$ret .= '<td class="numeric">'.round($col['score_perc']).'%</td>'.K_NEWLINE;
tecnickcom's avatar
tecnickcom committed
870
871
872
873
874
875
876
				if ($stats > 0) {
					$ret .= '<td class="numeric">'.round($col['right_perc']).'%</td>'.K_NEWLINE;
					$ret .= '<td class="numeric">'.round($col['wrong_perc']).'%</td>'.K_NEWLINE;
					$ret .= '<td class="numeric">'.round($col['unanswered_perc']).'%</td>'.K_NEWLINE;
					$ret .= '<td class="numeric">'.round($col['undisplayed_perc']).'%</td>'.K_NEWLINE;
					$ret .= '<td class="numeric">'.round($col['unrated_perc']).'%</td>'.K_NEWLINE;
				}
Nicola Asuni's avatar
Nicola Asuni committed
877
878
879
880
881
882
883
884
			}
			$ret .= '<td colspan="2">&nbsp;</td>'.K_NEWLINE;
			$ret .= '</tr>';
		}
	}
	$ret .= '</table>'.K_NEWLINE;
	return $ret;
}
nick's avatar
nick committed
885

Nicola Asuni's avatar
Nicola Asuni committed
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
/**
* Returns user test stats as HTML table
* @param $testuser_id (int) test-user ID - if greater than zero, filter stats for the specified test-user.
* return $data string containing HTML table.
*/
function F_printUserTestStat($testuser_id) {
	require_once('../config/tce_config.php');
	require_once('../../shared/code/tce_functions_tcecode.php');
	global $db, $l;
	$testuser_id = intval($testuser_id);

	$ret = '';

	// display user questions
	$sql = 'SELECT *
		FROM '.K_TABLE_QUESTIONS.', '.K_TABLE_TESTS_LOGS.', '.K_TABLE_SUBJECTS.', '.K_TABLE_MODULES.'
		WHERE question_id=testlog_question_id
			AND testlog_testuser_id='.$testuser_id.'
			AND question_subject_id=subject_id
			AND subject_module_id=module_id
		ORDER BY testlog_id';
Nicola Asuni's avatar
Nicola Asuni committed
907
	if ($r = F_db_query($sql, $db)) {
Nicola Asuni's avatar
Nicola Asuni committed
908
		$ret .= '<ol class="question">'.K_NEWLINE;
tecnickcom's avatar
tecnickcom committed
909
		while ($m = F_db_fetch_array($r)) {
Nicola Asuni's avatar
Nicola Asuni committed
910
			$ret .= '<li>'.K_NEWLINE;
911
912
913
914
915
916
917
918

			//get test_id
			$sqla =  'SELECT testuser_test_id FROM '.K_TABLE_TEST_USER. ' WHERE testuser_id='. $testuser_id;
			$ra = F_db_query($sqla, $db);
			$ma = F_db_fetch_array($ra);
			$testdata = F_getTestData($ma['testuser_test_id']);
			$question_max_score = ($testdata['test_score_right'] * $m['question_difficulty']);

Nicola Asuni's avatar
Nicola Asuni committed
919
			// display question stats
920
			$ret .= '<strong>['.$m['testlog_score'].'/'.$question_max_score .']'.K_NEWLINE;
Nicola Asuni's avatar
Nicola Asuni committed
921
			$ret .= ' (';
922
			$ret .= 'IP:'.ip6toip4($m['testlog_user_ip']).K_NEWLINE;
Nicola Asuni's avatar
Nicola Asuni committed
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
			if (isset($m['testlog_display_time']) AND (strlen($m['testlog_display_time']) > 0)) {
				$ret .= ' | '.substr($m['testlog_display_time'], 11, 8).K_NEWLINE;
			} else {
				$ret .= ' | --:--:--'.K_NEWLINE;
			}
			if (isset($m['testlog_change_time']) AND (strlen($m['testlog_change_time']) > 0)) {
				$ret .= ' | '.substr($m['testlog_change_time'], 11, 8).K_NEWLINE;
			} else {
				$ret .= ' | --:--:--'.K_NEWLINE;
			}
			if (isset($m['testlog_display_time']) AND isset($m['testlog_change_time'])) {
				$ret .= ' | '.date('i:s', (strtotime($m['testlog_change_time']) - strtotime($m['testlog_display_time']))).'';
			} else {
				$ret .= ' | --:--'.K_NEWLINE;
			}
			if (isset($m['testlog_reaction_time']) AND ($m['testlog_reaction_time'] > 0)) {
				$ret .= ' | '.($m['testlog_reaction_time']/1000).'';
			} else {
				$ret .= ' | ------'.K_NEWLINE;
			}
			$ret .= ')</strong>'.K_NEWLINE;
			$ret .= '<br />'.K_NEWLINE;
			// display question description
			$ret .= F_decode_tcecode($m['question_description']).K_NEWLINE;
			if (K_ENABLE_QUESTION_EXPLANATION AND !empty($m['question_explanation'])) {
				$ret .= '<br /><span class="explanation">'.$l['w_explanation'].':</span><br />'.F_decode_tcecode($m['question_explanation']).''.K_NEWLINE;
			}
			if ($m['question_type'] == 3) {
				// TEXT
				$ret .= '<ul class="answer"><li>'.K_NEWLINE;
				$ret .= F_decode_tcecode($m['testlog_answer_text']);
				$ret .= '&nbsp;</li></ul>'.K_NEWLINE;
			} else {
				$ret .= '<ol class="answer">'.K_NEWLINE;
				// display each answer option
				$sqla = 'SELECT *
					FROM '.K_TABLE_LOG_ANSWER.', '.K_TABLE_ANSWERS.'
					WHERE logansw_answer_id=answer_id
						AND logansw_testlog_id=\''.$m['testlog_id'].'\'
					ORDER BY logansw_order';
Nicola Asuni's avatar
Nicola Asuni committed
963
				if ($ra = F_db_query($sqla, $db)) {
tecnickcom's avatar
tecnickcom committed
964
					while ($ma = F_db_fetch_array($ra)) {
Nicola Asuni's avatar
Nicola Asuni committed
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
						$ret .= '<li>';
						if ($m['question_type'] == 4) {
							// ORDER
							if ($ma['logansw_position'] > 0) {
								if ($ma['logansw_position'] == $ma['answer_position']) {
									$ret .= '<acronym title="'.$l['h_answer_right'].'" class="okbox">'.$ma['logansw_position'].'</acronym>';
								} else {
									$ret .= '<acronym title="'.$l['h_answer_wrong'].'" class="nobox">'.$ma['logansw_position'].'</acronym>';
								}
							} else {
								$ret .= '<acronym title="'.$l['m_unanswered'].'" class="offbox">&nbsp;</acronym>';
							}
						} elseif ($ma['logansw_selected'] > 0) {
							if (F_getBoolean($ma['answer_isright'])) {
								$ret .= '<acronym title="'.$l['h_answer_right'].'" class="okbox">x</acronym>';
							} else {
								$ret .= '<acronym title="'.$l['h_answer_wrong'].'" class="nobox">x</acronym>';
							}
						} elseif ($m['question_type'] == 1) {
							// MCSA
							$ret .= '<acronym title="-" class="offbox">&nbsp;</acronym>';
						} else {
							if ($ma['logansw_selected'] == 0) {
								if (F_getBoolean($ma['answer_isright'])) {
									$ret .= '<acronym title="'.$l['h_answer_wrong'].'" class="nobox">&nbsp;</acronym>';
								} else {
									$ret .= '<acronym title="'.$l['h_answer_right'].'" class="okbox">&nbsp;</acronym>';
								}
							} else {
								$ret .= '<acronym title="'.$l['m_unanswered'].'" class="offbox">&nbsp;</acronym>';
							}
						}
						$ret .= '&nbsp;';
						if ($m['question_type'] == 4) {
							$ret .= '<acronym title="'.$l['w_position'].'" class="onbox">'.$ma['answer_position'].'</acronym>';
						} elseif (F_getBoolean($ma['answer_isright'])) {
For faster browsing, not all history is shown. View entire blame