24 include_once
"./classes/class.ilObjectAccess.php";
25 include_once
"./Modules/Test/classes/inc.AssessmentConstants.php";
56 function _checkAccess($a_cmd, $a_permission, $a_ref_id, $a_obj_id, $a_user_id =
"")
58 global $ilUser,
$lng, $rbacsystem, $ilAccess;
61 $a_user_id = $ilUser->getId();
64 switch ($a_permission)
69 (!$rbacsystem->checkAccess(
'write', $a_ref_id)))
108 $query = sprintf(
"SELECT SUM(qpl_questions.points) AS maxpoints FROM tst_test_random_question, qpl_questions, tst_active WHERE tst_active.active_id = tst_test_random_question.active_fi AND tst_test_random_question.question_fi = qpl_questions.question_id AND tst_active.test_fi = %s AND tst_test_random_question.pass = %s AND tst_active.user_fi = %s",
109 $ilDB->quote($test_id .
""),
110 $ilDB->quote(
$pass .
""),
111 $ilDB->quote($user_id .
"")
113 $result = $ilDB->query($query);
114 if ($result->numRows())
116 $row = $result->fetchRow(MDB2_FETCHMODE_ASSOC);
117 $max = $row[
"maxpoints"];
122 $query = sprintf(
"SELECT SUM(qpl_questions.points) AS maxpoints FROM tst_test_question, qpl_questions WHERE tst_test_question.question_fi = qpl_questions.question_id AND tst_test_question.test_fi = %s",
123 $ilDB->quote($test_id .
"")
125 $result = $ilDB->query($query);
126 if ($result->numRows())
128 $row = $result->fetchRow(MDB2_FETCHMODE_ASSOC);
129 $max = $row[
"maxpoints"];
147 $query = sprintf(
"SELECT tst_test_pass_result.*, tst_tests.pass_scoring, tst_tests.random_test, tst_tests.test_id FROM tst_test_pass_result, tst_active, tst_tests, object_data WHERE object_data.obj_id = tst_tests.obj_fi AND tst_active.test_fi = tst_tests.test_id AND tst_active.user_fi = %s AND object_data.obj_id = %s AND tst_test_pass_result.active_fi = tst_active.active_id ORDER BY tst_test_pass_result.pass",
148 $ilDB->quote($user_id .
""),
149 $ilDB->quote($a_obj_id .
"")
151 $result = $ilDB->query($query);
153 while ($row = $result->fetchRow(MDB2_FETCHMODE_ASSOC))
155 array_push($points, $row);
159 if ($points[0][
"pass_scoring"] == 0)
161 $reached = $points[count($points)-1][
"points"];
165 include_once
"./Modules/Test/classes/class.ilTestEvaluationData.php";
166 include_once
"./Modules/Test/classes/class.ilObjTest.php";
170 $p =
$data->getParticipants();
173 $user = $p[$points[count($points)-1][
"active_fi"]];
176 $max =
$user->getMaxpoints();
183 foreach ($points as $row)
185 if ($row[
"points"] > $reached)
190 include_once
"./Modules/Test/classes/class.ilTestEvaluationData.php";
191 include_once
"./Modules/Test/classes/class.ilObjTest.php";
195 $p =
$data->getParticipants();
198 $user = $p[$points[count($points)-1][
"active_fi"]];
201 $max =
$user->getMaxpoints();
205 $reached = $row[
"points"];
209 include_once
"./Modules/Test/classes/class.assMarkSchema.php";
210 $percentage = (!$max) ? 0 : ($reached / $max) * 100.0;
212 return ($mark[
"passed"]) ? TRUE : FALSE;
224 $a_usr_id = $a_usr_id ? $a_usr_id : $ilUser->getId();
260 array(
"permission" =>
"read",
"cmd" =>
"infoScreen",
"lang_var" =>
"tst_run",
262 array(
"permission" =>
"write",
"cmd" =>
"",
"lang_var" =>
"edit"),
263 array(
"permission" =>
"tst_statistics",
"cmd" =>
"outEvaluation",
"lang_var" =>
"tst_statistical_evaluation")
280 $q = sprintf(
"SELECT * FROM tst_tests WHERE obj_fi=%s",
281 $ilDB->quote($a_obj_id)
284 if ($result->numRows() == 1)
286 $row = $result->fetchRow(MDB2_FETCHMODE_OBJECT);
310 $query = sprintf(
"SELECT active_id FROM tst_active WHERE user_fi = %s AND test_fi = %s AND tries > '0'",
311 $ilDB->quote($a_user_id .
""),
314 $res = $ilDB->query($query);
316 return $res->numRows() ?
true :
false;
332 $query = sprintf(
"SELECT test_id FROM tst_tests WHERE obj_fi = %s",
333 $ilDB->quote($object_id .
"")
335 $result = $ilDB->query($query);
336 if ($result->numRows())
338 $row = $result->fetchRow(MDB2_FETCHMODE_ASSOC);
339 $test_id = $row[
"test_id"];
350 $questions = array();
353 $query = sprintf(
"SELECT test_fi FROM tst_active WHERE active_id = %s",
354 $ilDB->quote($active_id .
"")
356 $result = $ilDB->query($query);
358 if ($result->numRows())
360 $row = $result->fetchRow(MDB2_FETCHMODE_ASSOC);
361 $test_id = $row[
"test_fi"];
367 $query = sprintf(
"SELECT qpl_questions.question_id, qpl_questions.points FROM qpl_questions, tst_test_question WHERE tst_test_question.question_fi = qpl_questions.question_id AND tst_test_question.test_fi = %s ORDER BY tst_test_question.sequence",
368 $ilDB->quote($test_id .
"")
370 $result = $ilDB->query($query);
371 if ($result->numRows())
374 while ($row = $result->fetchRow(MDB2_FETCHMODE_ASSOC))
376 array_push($questions, $row);
382 $query = sprintf(
"SELECT qpl_questions.question_id, qpl_questions.points FROM qpl_questions, tst_test_random_question WHERE tst_test_random_question.question_fi = qpl_questions.question_id AND tst_test_random_question.active_fi = %s AND tst_test_random_question.pass = %s ORDER BY tst_test_random_question.sequence",
383 $ilDB->quote($active_id .
""),
384 $ilDB->quote(
$pass .
"")
386 $result = $ilDB->query($query);
387 if ($result->numRows())
389 while ($row = $result->fetchRow(MDB2_FETCHMODE_ASSOC))
391 array_push($questions, $row);
411 $query = sprintf(
"SELECT tst_mark.*, tst_tests.* FROM tst_tests, tst_mark WHERE tst_mark.test_fi = tst_tests.test_id AND tst_tests.test_id = %s",
412 $ilDB->quote($test_id .
"")
414 $result = $ilDB->query($query);
415 $found = $result->numRows();
418 $row = $result->fetchRow(MDB2_FETCHMODE_ASSOC);
420 if ((strlen($row[
"title"])) &&
421 (strlen($row[
"author"])) &&
445 if ((
$test->getTitle()) and (
$test->author) and (count(
$test->mark_schema->mark_steps)) and (count(
$test->questions)))
467 $query = sprintf(
"SELECT * FROM tst_tests WHERE test_id = %s",
468 $ilDB->quote($test_id .
"")
470 $result = $ilDB->query($query);
471 if (!$result->numRows())
475 $test = $result->fetchRow(MDB2_FETCHMODE_ASSOC);
495 if (
$test[
"random_test"] == 1)
497 if (
$test[
"random_question_count"] > 0)
499 $num =
$test[
"random_question_count"];
503 $query = sprintf(
"SELECT SUM(num_of_q) AS questioncount FROM tst_test_random WHERE test_fi = %s ORDER BY test_random_id",
504 $ilDB->quote($test_id .
"")
506 $result = $ilDB->query($query);
507 if ($result->numRows())
509 $row = $result->fetchRow(MDB2_FETCHMODE_ASSOC);
510 $num = $row[
"questioncount"];
516 $query = sprintf(
"SELECT test_question_id FROM tst_test_question WHERE test_fi = %s",
517 $ilDB->quote($test_id .
"")
519 $result = $ilDB->query($query);
520 $num = $result->numRows();
537 $query = sprintf(
"SELECT tst_tests.* FROM tst_tests WHERE tst_tests.obj_fi = %s",
538 $ilDB->quote($a_test_id .
"")
540 $result = $ilDB->query($query);
541 if ($result->numRows())
543 $row = $result->fetchRow(MDB2_FETCHMODE_ASSOC);
544 if ($row[
"fixed_participants"])
546 $query = sprintf(
"SELECT * FROM tst_invited_user WHERE test_fi = %s AND user_fi = %s",
547 $ilDB->quote($row[
"test_id"] .
""),
548 $ilDB->quote($a_user_id .
"")
550 $result = $ilDB->query($query);
551 if ($result->numRows())
553 $row = $result->fetchRow(MDB2_FETCHMODE_ASSOC);
554 if (trim($row[
'clientip']) !=
"")
556 $row[
'clientip'] = preg_replace(
"/[^0-9.?*,:]+/",
"",$row[
'clientip']);
557 $row[
'clientip'] = str_replace(
".",
"\\.",$row[
'clientip']);
558 $row[
'clientip'] = str_replace(Array(
"?",
"*",
","), Array(
"[0-9]",
"[0-9]*",
"|"), $row[
'clientip']);
559 if (!preg_match(
"/^".$row[
'clientip'].
"$/", $_SERVER[
"REMOTE_ADDR"]))
561 return $lng->txt(
"tst_user_wrong_clientip");
575 return $lng->txt(
"tst_user_not_invited");
600 $statement = $ilDB->prepare(
"SELECT user_fi, test_fi FROM tst_active WHERE active_id = ?",
605 $result = $ilDB->execute($statement,
610 $row = $ilDB->fetchAssoc(
$result);
611 $user_id = $row[
"user_fi"];
612 $test_id = $row[
"test_fi"];
614 $statement = $ilDB->prepare(
"SELECT obj_fi FROM tst_tests WHERE test_id = ?",
619 $result = $ilDB->execute($statement,
624 $row = $ilDB->fetchAssoc(
$result);
625 $obj_id = $row[
"obj_fi"];
627 include_once
"./Modules/Test/classes/class.ilObjTest.php";
630 include_once
'./Services/User/classes/class.ilObjUser.php';
634 if (strlen($uname[
"firstname"].$uname[
"lastname"]) == 0)
636 $name = $lng->txt(
"deleted_user");
640 if ($user_id == ANONYMOUS_USER_ID)
646 $name = trim($uname[
"lastname"] .
", " . $uname[
"firstname"] .
" " . $uname[
"title"]);
650 $name = $lng->txt(
"anonymous");
676 $passed_users = array();
677 $query = sprintf(
"SELECT tst_active.user_fi FROM tst_active, tst_tests WHERE tst_tests.test_id = tst_active.test_fi AND tst_tests.obj_fi = %s",
678 $ilDB->quote($a_obj_id .
"")
680 $userresult = $ilDB->query($query);
681 if ($userresult->numRows())
683 while ($userrow = $userresult->fetchRow(MDB2_FETCHMODE_ASSOC))
685 $user_id = $userrow[
"user_fi"];
686 $query = sprintf(
"SELECT tst_test_pass_result.*, tst_tests.pass_scoring, tst_tests.random_test, tst_tests.test_id FROM tst_test_pass_result, tst_active, tst_tests, object_data WHERE object_data.obj_id = tst_tests.obj_fi AND tst_active.test_fi = tst_tests.test_id AND tst_active.user_fi = %s AND object_data.obj_id = %s AND tst_test_pass_result.active_fi = tst_active.active_id ORDER BY tst_test_pass_result.pass",
687 $ilDB->quote($user_id .
""),
688 $ilDB->quote($a_obj_id .
"")
690 $result = $ilDB->query($query);
692 while ($row = $result->fetchRow(MDB2_FETCHMODE_ASSOC))
694 array_push($points, $row);
698 if ($points[0][
"pass_scoring"] == 0)
700 $reached = $points[count($points)-1][
"points"];
704 include_once
"./Modules/Test/classes/class.ilTestEvaluationData.php";
705 include_once
"./Modules/Test/classes/class.ilObjTest.php";
709 $p =
$data->getParticipants();
712 $user = $p[$points[count($points)-1][
"active_fi"]];
715 $max =
$user->getMaxpoints();
722 foreach ($points as $row)
724 if ($row[
"points"] > $reached)
729 include_once
"./Modules/Test/classes/class.ilTestEvaluationData.php";
730 include_once
"./Modules/Test/classes/class.ilObjTest.php";
734 $p =
$data->getParticipants();
737 $user = $p[$points[count($points)-1][
"active_fi"]];
740 $max =
$user->getMaxpoints();
744 $reached = $row[
"points"];
748 include_once
"./Modules/Test/classes/class.assMarkSchema.php";
749 $percentage = (!$max) ? 0 : ($reached / $max) * 100.0;
751 array_push($passed_users,
753 "user_id" => $user_id,
754 "max_points" => $max,
755 "reached_points" => $reached,
756 "mark_short" => $mark[
"short_name"],
757 "mark_official" => $mark[
"official_name"],
758 "passed" => ($mark[
"passed"]) ? TRUE : FALSE,
759 "failed" => (!$mark[
"passed"]) ? TRUE : FALSE
764 return $passed_users;
774 $t_arr = explode(
"_", $a_target);
776 if ($t_arr[0] !=
"tst" || ((
int) $t_arr[1]) <= 0)
781 if ($ilAccess->checkAccess(
"visible",
"", $t_arr[1]))