ILIAS  Release_3_10_x_branch Revision 61812
 All Data Structures Namespaces Files Functions Variables Groups Pages
class.ilTestOutputGUI.php
Go to the documentation of this file.
1 <?php
2 /*
3  +-----------------------------------------------------------------------------+
4  | ILIAS open source |
5  +-----------------------------------------------------------------------------+
6  | Copyright (c) 1998-2001 ILIAS open source, University of Cologne |
7  | |
8  | This program is free software; you can redistribute it and/or |
9  | modify it under the terms of the GNU General Public License |
10  | as published by the Free Software Foundation; either version 2 |
11  | of the License, or (at your option) any later version. |
12  | |
13  | This program is distributed in the hope that it will be useful, |
14  | but WITHOUT ANY WARRANTY; without even the implied warranty of |
15  | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
16  | GNU General Public License for more details. |
17  | |
18  | You should have received a copy of the GNU General Public License |
19  | along with this program; if not, write to the Free Software |
20  | Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. |
21  +-----------------------------------------------------------------------------+
22 */
23 
24 include_once "./Modules/Test/classes/inc.AssessmentConstants.php";
25 include_once "./Modules/Test/classes/class.ilTestServiceGUI.php";
26 
40 {
41  var $ref_id;
42 
44  var $sequence;
45  var $cmdCtrl;
48 
57  function ilTestOutputGUI($a_object)
58  {
59  parent::ilTestServiceGUI($a_object);
60  $this->ref_id = $_GET["ref_id"];
61  }
62 
63  /*
64  * Save tags for tagging gui
65  *
66  * Needed this function here because the test info page
67  * uses another class to send its form results
68  */
69  function saveTags()
70  {
71  include_once("./Services/Tagging/classes/class.ilTaggingGUI.php");
72  $tagging_gui = new ilTaggingGUI();
73  $tagging_gui->setObject($this->object->getId(), $this->object->getType());
74  $tagging_gui->saveInput();
75  $this->ctrl->redirectByClass("ilobjtestgui", "infoScreen");
76  }
77 
81  function &executeCommand()
82  {
83  global $ilUser;
84  $cmd = $this->ctrl->getCmd();
85  $next_class = $this->ctrl->getNextClass($this);
86  $this->ctrl->saveParameter($this, "sequence");
87  $this->ctrl->saveParameter($this, "active_id");
88 
89  if ($_GET["active_id"])
90  {
91  $this->object->setTestSession($_GET["active_id"]);
92  }
93  else
94  {
95  $this->object->setTestSession();
96  }
97  include_once "./Services/YUI/classes/class.ilYuiUtil.php";
99  $cmd = $this->getCommand($cmd);
100  switch($next_class)
101  {
102  default:
103  $ret =& $this->$cmd();
104  break;
105  }
106  return $ret;
107  }
108 
113  function updateWorkingTime()
114  {
115  if ($_SESSION["active_time_id"])
116  {
117  $this->object->updateWorkingTime($_SESSION["active_time_id"]);
118  }
119  }
120 
124  function saveQuestionSolution($force = FALSE)
125  {
126  $this->updateWorkingTime();
127  $this->saveResult = FALSE;
128  if (!$force)
129  {
130  $formtimestamp = $_POST["formtimestamp"];
131  if (strlen($formtimestamp) == 0) $formtimestamp = $_GET["formtimestamp"];
132  if ($formtimestamp != $_SESSION["formtimestamp"])
133  {
134  $_SESSION["formtimestamp"] = $formtimestamp;
135  }
136  else
137  {
138  return FALSE;
139  }
140  }
141  // save question solution
142  if ($this->canSaveResult() || $force)
143  {
144  // but only if the ending time is not reached
145  $q_id = $this->object->getTestSequence()->getQuestionForSequence($_GET["sequence"]);
146  if (is_numeric($q_id))
147  {
148  global $ilUser;
149 
150  $question_gui = $this->object->createQuestionGUI("", $q_id);
151  if ($this->object->getJavaScriptOutput())
152  {
153  $question_gui->object->setOutputType(OUTPUT_JAVASCRIPT);
154  }
155  $pass = NULL;
156  $active_id = $this->object->getTestSession()->getActiveId();
157  if ($this->object->isRandomTest())
158  {
159  $pass = $this->object->_getPass($active_id);
160  }
161  $this->saveResult = $question_gui->object->saveWorkingData($active_id, $pass);
162  }
163  }
164  if ($this->saveResult == FALSE)
165  {
166  $this->ctrl->setParameter($this, "save_error", "1");
167  $_SESSION["previouspost"] = $_POST;
168  }
169  return $this->saveResult;
170  }
171 
180  function canSaveResult()
181  {
182  return !$this->object->endingTimeReached() && !$this->isMaxProcessingTimeReached() && !$this->isNrOfTriesReached();
183  }
184 
193  {
194  $this->ctrl->redirectByClass("ilobjtestgui", "infoScreen");
195  }
196 
206  {
207  global $ilUser;
208  $active_id = $this->object->getTestSession()->getActiveId();
209  $starting_time = $this->object->getStartingTimeOfUser($active_id);
210  if ($starting_time === FALSE)
211  {
212  return FALSE;
213  }
214  else
215  {
216  return $this->object->isMaxProcessingTimeReached($starting_time);
217  }
218  }
219 
227  function outWorkingForm($sequence = "", $test_id, $postpone_allowed, $directfeedback = 0)
228  {
229  global $ilUser;
230 
231  if ($sequence < 1) $sequence = $this->object->getTestSequence()->getFirstSequence();
232  $active_time_id = $this->object->startWorkingTime($this->object->getTestSession()->getActiveId(), $this->object->getTestSession()->getPass());
233  $_SESSION["active_time_id"] = $active_time_id;
234 
235  include_once("./Services/Style/classes/class.ilObjStyleSheet.php");
236  $this->tpl->setCurrentBlock("ContentStyle");
237  $this->tpl->setVariable("LOCATION_CONTENT_STYLESHEET",
239  $this->tpl->parseCurrentBlock();
240 
241  // syntax style
242  $this->tpl->setCurrentBlock("SyntaxStyle");
243  $this->tpl->setVariable("LOCATION_SYNTAX_STYLESHEET",
245  $this->tpl->parseCurrentBlock();
246  $question_gui = $this->object->createQuestionGUI("", $this->object->getTestSequence()->getQuestionForSequence($sequence));
247  if ($this->object->getJavaScriptOutput())
248  {
249  $question_gui->object->setOutputType(OUTPUT_JAVASCRIPT);
250  }
251 
252  $is_postponed = $this->object->getTestSequence()->isPostponedQuestion($question_gui->object->getId());
253 
254  $this->ctrl->setParameter($this, "sequence", "$sequence");
255  $formaction = $this->ctrl->getFormAction($this, "gotoQuestion");
256 
257  $question_gui->setSequenceNumber($this->object->getTestSequence()->getPositionOfSequence($sequence));
258  $question_gui->setQuestionCount($this->object->getTestSequence()->getUserQuestionCount());
259  // output question
260  $user_post_solution = FALSE;
261  if (array_key_exists("previouspost", $_SESSION))
262  {
263  $user_post_solution = $_SESSION["previouspost"];
264  unset($_SESSION["previouspost"]);
265  }
266  $answer_feedback = FALSE;
267  if (($directfeedback) && ($this->object->getAnswerFeedback()))
268  {
269  $answer_feedback = TRUE;
270  }
271  global $ilNavigationHistory;
272  $ilNavigationHistory->addItem($_GET["ref_id"], $this->ctrl->getLinkTarget($this, "resume"), "tst");
273  $question_gui->outQuestionForTest($formaction, $this->object->getTestSession()->getActiveId(), NULL, $is_postponed, $user_post_solution, $answer_feedback);
274  if ($directfeedback)
275  {
276  if ($this->object->getInstantFeedbackSolution())
277  {
278  $solutionoutput = $question_gui->getSolutionOutput($this->object->getTestSession()->getActiveId(), NULL, FALSE, FALSE, FALSE, FALSE, TRUE);
279  $this->tpl->setCurrentBlock("solution_output");
280  $this->tpl->setVariable("CORRECT_SOLUTION", $this->lng->txt("tst_best_solution_is"));
281  $this->tpl->setVariable("QUESTION_FEEDBACK", $solutionoutput);
282  $this->tpl->parseCurrentBlock();
283  }
284  if ($this->object->getAnswerFeedbackPoints())
285  {
286  $this->tpl->setCurrentBlock("solution_output");
287  $this->tpl->setVariable("RECEIVED_POINTS_INFORMATION", sprintf($this->lng->txt("you_received_a_of_b_points"), $question_gui->object->calculateReachedPoints($this->object->getTestSession()->getActiveId(), NULL), $question_gui->object->getMaximumPoints()));
288  $this->tpl->parseCurrentBlock();
289  }
290  if ($this->object->getAnswerFeedback())
291  {
292  $this->tpl->setCurrentBlock("answer_feedback");
293  $this->tpl->setVariable("ANSWER_FEEDBACK", $question_gui->getAnswerFeedbackOutput($this->object->getTestSession()->getActiveId(), NULL));
294  $this->tpl->parseCurrentBlock();
295  }
296  }
297 
298  if ($sequence == $this->object->getTestSequence()->getFirstSequence())
299  {
300  $this->tpl->setCurrentBlock("prev");
301  $this->tpl->setVariable("BTN_PREV", "&lt;&lt; " . $this->lng->txt("save_introduction"));
302  $this->tpl->parseCurrentBlock();
303  $this->tpl->setCurrentBlock("prev_bottom");
304  $this->tpl->setVariable("BTN_PREV", "&lt;&lt; " . $this->lng->txt("save_introduction"));
305  $this->tpl->parseCurrentBlock();
306  }
307  else
308  {
309  $this->tpl->setCurrentBlock("prev");
310  $this->tpl->setVariable("BTN_PREV", "&lt;&lt; " . $this->lng->txt("save_previous"));
311  $this->tpl->parseCurrentBlock();
312  $this->tpl->setCurrentBlock("prev_bottom");
313  $this->tpl->setVariable("BTN_PREV", "&lt;&lt; " . $this->lng->txt("save_previous"));
314  $this->tpl->parseCurrentBlock();
315  }
316 
317  if ($postpone_allowed)
318  {
319  if (!$is_postponed)
320  {
321  if (!$finish)
322  {
323  $this->tpl->setCurrentBlock("postpone");
324  $this->tpl->setVariable("BTN_POSTPONE", $this->lng->txt("postpone"));
325  $this->tpl->parseCurrentBlock();
326  $this->tpl->setCurrentBlock("postpone_bottom");
327  $this->tpl->setVariable("BTN_POSTPONE", $this->lng->txt("postpone"));
328  $this->tpl->parseCurrentBlock();
329  }
330  }
331  }
332 
333  if ($this->object->getListOfQuestions())
334  {
335  if (!(($finish) && ($this->object->getListOfQuestionsEnd())))
336  {
337  $this->tpl->setCurrentBlock("summary");
338  $this->tpl->setVariable("BTN_SUMMARY", $this->lng->txt("question_summary"));
339  $this->tpl->parseCurrentBlock();
340  $this->tpl->setCurrentBlock("summary_bottom");
341  $this->tpl->setVariable("BTN_SUMMARY", $this->lng->txt("question_summary"));
342  $this->tpl->parseCurrentBlock();
343  }
344  }
345 
346  if ($this->object->getShowCancel())
347  {
348  $this->tpl->setCurrentBlock("cancel_test");
349  $this->tpl->setVariable("TEXT_CANCELTEST", $this->lng->txt("cancel_test"));
350  $this->tpl->setVariable("TEXT_ALTCANCELTEXT", $this->lng->txt("cancel_test"));
351  $this->tpl->setVariable("TEXT_TITLECANCELTEXT", $this->lng->txt("cancel_test"));
352  $this->tpl->setVariable("HREF_IMGCANCELTEST", $this->ctrl->getLinkTargetByClass(get_class($this), "outIntroductionPage") . "&cancelTest=true");
353  $this->tpl->setVariable("HREF_CANCELTEXT", $this->ctrl->getLinkTargetByClass(get_class($this), "outIntroductionPage") . "&cancelTest=true");
354  $this->tpl->setVariable("IMAGE_CANCEL", ilUtil::getImagePath("cancel.gif"));
355  $this->tpl->parseCurrentBlock();
356  }
357 
358  if ($this->object->getTestSequence()->getQuestionForSequence($this->object->getTestSequence()->getLastSequence()) == $question_gui->object->getId())
359  {
360  if ($this->object->getListOfQuestionsEnd())
361  {
362  $this->tpl->setCurrentBlock("next");
363  $this->tpl->setVariable("BTN_NEXT", $this->lng->txt("question_summary") . " &gt;&gt;");
364  $this->tpl->parseCurrentBlock();
365  $this->tpl->setCurrentBlock("next_bottom");
366  $this->tpl->setVariable("BTN_NEXT", $this->lng->txt("question_summary") . " &gt;&gt;");
367  $this->tpl->parseCurrentBlock();
368  }
369  else
370  {
371  $this->tpl->setCurrentBlock("next");
372  $this->tpl->setVariable("BTN_NEXT", $this->lng->txt("save_finish") . " &gt;&gt;");
373  $this->tpl->parseCurrentBlock();
374  $this->tpl->setCurrentBlock("next_bottom");
375  $this->tpl->setVariable("BTN_NEXT", $this->lng->txt("save_finish") . " &gt;&gt;");
376  $this->tpl->parseCurrentBlock();
377  }
378  }
379  else
380  {
381  $this->tpl->setCurrentBlock("next");
382  $this->tpl->setVariable("BTN_NEXT", $this->lng->txt("save_next") . " &gt;&gt;");
383  $this->tpl->parseCurrentBlock();
384  $this->tpl->setCurrentBlock("next_bottom");
385  $this->tpl->setVariable("BTN_NEXT", $this->lng->txt("save_next") . " &gt;&gt;");
386  $this->tpl->parseCurrentBlock();
387  }
388 
389  if ($this->object->getShowMarker())
390  {
391  include_once "./Modules/Test/classes/class.ilObjTest.php";
392  $solved_array = ilObjTest::_getSolvedQuestions($this->object->getTestSession()->getActiveId(), $question_gui->object->getId());
393  $solved = 0;
394 
395  if (count ($solved_array) > 0)
396  {
397  $solved = array_pop($solved_array);
398  $solved = $solved->solved;
399  }
400 
401  if ($solved==1)
402  {
403  $this->tpl->setCurrentBlock("ismarked");
404  $this->tpl->setVariable("TEXT_QUESTION_STATUS_LABEL", $this->lng->txt("tst_question_marked").":");
405  $this->tpl->setVariable("TEXT_RESET_MARK", $this->lng->txt("remove"));
406  $this->tpl->setVariable("ALT_MARKED", $this->lng->txt("tst_question_marked"));
407  $this->tpl->setVariable("TITLE_MARKED", $this->lng->txt("tst_question_marked"));
408  $this->tpl->setVariable("MARKED_SOURCE", ilUtil::getImagePath("marked.png"));
409  $this->tpl->parseCurrentBlock();
410  }
411  else
412  {
413  $this->tpl->setCurrentBlock("ismarked");
414  $this->tpl->setVariable("TEXT_MARK_QUESTION", $this->lng->txt("tst_question_mark"));
415  $this->tpl->parseCurrentBlock();
416  }
417  }
418 
419  if ($this->object->getJavaScriptOutput())
420  {
421  $this->tpl->setVariable("JAVASCRIPT_IMAGE", ilUtil::getImagePath("javascript_disable.png"));
422  $this->tpl->setVariable("JAVASCRIPT_IMAGE_ALT", $this->lng->txt("disable_javascript"));
423  $this->tpl->setVariable("JAVASCRIPT_IMAGE_TITLE", $this->lng->txt("disable_javascript"));
424  $this->ctrl->setParameter($this, "tst_javascript", "0");
425  $this->tpl->setVariable("JAVASCRIPT_URL", $this->ctrl->getLinkTarget($this, "gotoQuestion"));
426  }
427  else
428  {
429  $this->tpl->setVariable("JAVASCRIPT_IMAGE", ilUtil::getImagePath("javascript.png"));
430  $this->tpl->setVariable("JAVASCRIPT_IMAGE_ALT", $this->lng->txt("enable_javascript"));
431  $this->tpl->setVariable("JAVASCRIPT_IMAGE_TITLE", $this->lng->txt("enable_javascript"));
432  $this->ctrl->setParameter($this, "tst_javascript", "1");
433  $this->tpl->setVariable("JAVASCRIPT_URL", $this->ctrl->getLinkTarget($this, "gotoQuestion"));
434  }
435 
436  if ($question_gui->object->supportsJavascriptOutput())
437  {
438  $this->tpl->touchBlock("jsswitch");
439  }
440 
441  $this->tpl->addJavaScript(ilUtil::getJSLocation("autosave.js", "Modules/Test"));
442  $this->tpl->setVariable("AUTOSAVE_URL", $this->ctrl->getLinkTarget($this, "autosave"));
443 
444  $this->tpl->setCurrentBlock("adm_content");
445  //$this->tpl->setVariable("FORMACTION", $formaction);
446  $this->tpl->parseCurrentBlock();
447  }
448 
457  {
458  $this->tpl->addBlockFile($this->getContentBlockName(), "adm_content", "tpl.il_as_tst_password_protection.html", "Modules/Test");
459  $this->tpl->setVariable("FORMACTION", $this->ctrl->getFormAction($this, "checkPassword"));
460  $this->tpl->setVariable("PASSWORD_INTRODUCTION", $this->lng->txt("tst_password_introduction"));
461  $this->tpl->setVariable("TEXT_PASSWORD", $this->lng->txt("tst_password"));
462  $this->tpl->setVariable("SUBMIT", $this->lng->txt("submit"));
463  $this->tpl->parseCurrentBlock();
464  }
465 
473  function checkPassword()
474  {
475  if (strcmp($this->object->getPassword(), $_POST["password"]) == 0)
476  {
477  global $ilUser;
478  if ($_SESSION["AccountId"] != ANONYMOUS_USER_ID)
479  {
480  $ilUser->setPref("tst_password_".$this->object->getTestId(), $this->object->getPassword());
481  $ilUser->writePref("tst_password_".$this->object->getTestId(), $this->object->getPassword());
482  }
483  $this->ctrl->redirect($this, "start");
484  }
485  else
486  {
487  ilUtil::sendInfo($this->lng->txt("tst_password_entered_wrong_password"), true);
488  $this->ctrl->redirectByClass("ilobjtestgui", "infoScreen");
489  }
490  }
491 
499  function setAnonymousId()
500  {
501  if ($_SESSION["AccountId"] == ANONYMOUS_USER_ID)
502  {
503  $this->object->setAccessCodeSession($_POST["anonymous_id"]);
504  }
505  $this->ctrl->redirectByClass("ilobjtestgui", "infoScreen");
506  }
507 
516  function start()
517  {
518  if (strcmp($_SESSION["lock"], $_POST["lock"]) != 0)
519  {
520  $_SESSION["lock"] = $_POST["lock"];
521  $this->handleStartCommands();
522  $this->ctrl->redirect($this, "startTest");
523  }
524  else
525  {
526  $this->ctrl->redirectByClass("ilobjtestgui", "redirectToInfoScreen");
527  }
528  }
529 
535  function startTest()
536  {
537  if ($this->object->checkMaximumAllowedUsers() == FALSE)
538  {
540  }
541  if ($_SESSION["AccountId"] == ANONYMOUS_USER_ID)
542  {
543  $this->object->setAccessCodeSession($this->object->createNewAccessCode());
544  }
545  else
546  {
547  $this->object->unsetAccessCodeSession();
548  }
549  if (strlen($this->object->getPassword()))
550  {
551  global $ilUser;
552  global $rbacsystem;
553 
554  $pwd = $ilUser->getPref("tst_password_".$this->object->getTestId());
555  if ((strcmp($pwd, $this->object->getPassword()) != 0) && (!$rbacsystem->checkAccess("write", $this->object->getRefId())))
556  {
557  return $this->showPasswordProtectionPage();
558  }
559  }
560  if ($_SESSION["AccountId"] == ANONYMOUS_USER_ID)
561  {
562  $this->ctrl->redirect($this, "displayCode");
563  }
564  else
565  {
566  $this->ctrl->setParameter($this, "activecommand", "start");
567  $this->ctrl->redirect($this, "redirectQuestion");
568  }
569  }
570 
571  function displayCode()
572  {
573  $this->tpl->addBlockFile($this->getContentBlockName(), "adm_content", "tpl.il_as_tst_anonymous_code_presentation.html", "Modules/Test");
574  $this->tpl->setCurrentBlock("adm_content");
575  $this->tpl->setVariable("TEXT_ANONYMOUS_CODE_CREATED", $this->lng->txt("tst_access_code_created"));
576  $this->tpl->setVariable("TEXT_ANONYMOUS_CODE", $this->object->getAccessCodeSession());
577  $this->tpl->setVariable("FORMACTION", $this->ctrl->getFormAction($this));
578  $this->tpl->setVariable("CONTINUE", $this->lng->txt("continue_work"));
579  $this->tpl->parseCurrentBlock();
580  }
581 
582  function codeConfirmed()
583  {
584  $this->ctrl->setParameter($this, "activecommand", "start");
585  $this->ctrl->redirect($this, "redirectQuestion");
586  }
587 
595  function resume()
596  {
597  if ($this->object->checkMaximumAllowedUsers() == FALSE)
598  {
600  }
601  $this->handleStartCommands();
602  $this->ctrl->setParameter($this, "activecommand", "resume");
603  $this->ctrl->redirect($this, "redirectQuestion");
604  }
605 
614  {
615  global $ilUser;
616 
617  if ($_POST["chb_javascript"])
618  {
619  $ilUser->writePref("tst_javascript", 1);
620  }
621  else
622  {
623  $ilUser->writePref("tst_javascript", 0);
624  }
625 
626  // hide previous results
627  if ($this->object->getNrOfTries() != 1)
628  {
629  if ($this->object->getUsePreviousAnswers() == 1)
630  {
631  if ($_POST["chb_use_previous_answers"])
632  {
633  $ilUser->writePref("tst_use_previous_answers", 1);
634  }
635  else
636  {
637  $ilUser->writePref("tst_use_previous_answers", 0);
638  }
639  }
640  }
641 /* if ($this->object->getTestType() == TYPE_ONLINE_TEST)
642  {
643  global $ilias;
644  $ilias->auth->setIdle(0, false);
645  }*/
646  }
647 
656  function redirectQuestion()
657  {
658  global $ilUser;
659 
660  // check the test restrictions to access the test in case one
661  // of the test navigation commands was called by an external script
662  // e.g. $ilNavigationHistory
663  $executable = $this->object->isExecutable($ilUser->getId());
664  if (!$executable["executable"])
665  {
666  ilUtil::sendInfo($executable["errormessage"], TRUE);
667  $this->ctrl->redirectByClass("ilobjtestgui", "infoScreen");
668  }
669  switch ($_GET["activecommand"])
670  {
671  case "next":
672  $this->sequence = $this->calculateSequence();
673  if ($this->sequence === FALSE)
674  {
675  if ($this->object->getListOfQuestionsEnd())
676  {
677  $this->outQuestionSummary();
678  }
679  else
680  {
681  $this->ctrl->redirect($this, "finishTest");
682  }
683  }
684  else
685  {
686  $this->object->getTestSession()->setLastSequence($this->sequence);
687  $this->object->getTestSession()->saveToDb();
688  $this->outTestPage();
689  }
690  break;
691  case "previous":
692  $this->sequence = $this->calculateSequence();
693  $this->object->getTestSession()->setLastSequence($this->sequence);
694  $this->object->getTestSession()->saveToDb();
695  if ($this->sequence === FALSE)
696  {
697  $this->ctrl->redirect($this, "outIntroductionPage");
698  }
699  else
700  {
701  $this->outTestPage();
702  }
703  break;
704  case "postpone":
705  $this->sequence = $this->calculateSequence();
706  $nextSequence = $this->object->getTestSequence()->getNextSequence($this->sequence);
707  $this->object->getTestSequence()->postponeSequence($this->sequence);
708  $this->object->getTestSequence()->saveToDb();
709  $this->object->getTestSession()->setLastSequence($nextSequence);
710  $this->object->getTestSession()->saveToDb();
711  $this->sequence = $nextSequence;
712  $this->outTestPage();
713  break;
714  case "setmarked":
715  $this->sequence = $this->calculateSequence();
716  $this->object->getTestSession()->setLastSequence($this->sequence);
717  $this->object->getTestSession()->saveToDb();
718  $q_id = $this->object->getTestSequence()->getQuestionForSequence($_GET["sequence"]);
719  $this->object->setQuestionSetSolved(1, $q_id, $ilUser->getId());
720  $this->outTestPage();
721  break;
722  case "resetmarked":
723  $this->sequence = $this->calculateSequence();
724  $this->object->getTestSession()->setLastSequence($this->sequence);
725  $this->object->getTestSession()->saveToDb();
726  $q_id = $this->object->getTestSequence()->getQuestionForSequence($_GET["sequence"]);
727  $this->object->setQuestionSetSolved(0, $q_id, $ilUser->getId());
728  $this->outTestPage();
729  break;
730  case "directfeedback":
731  $this->sequence = $this->calculateSequence();
732  $this->object->getTestSession()->setLastSequence($this->sequence);
733  $this->object->getTestSession()->saveToDb();
734  $this->outTestPage();
735  break;
736  case "selectImagemapRegion":
737  $this->sequence = $this->calculateSequence();
738  $this->object->getTestSession()->setLastSequence($this->sequence);
739  $this->object->getTestSession()->saveToDb();
740  $this->outTestPage();
741  break;
742  case "summary":
743  $this->ctrl->redirect($this, "outQuestionSummary");
744  break;
745  case "start":
746  $_SESSION['tst_pass_finish'] = 0;
747  $this->object->createTestSession();
748  $active_id = $this->object->getTestSession()->getActiveId();
749  $this->ctrl->setParameter($this, "active_id", $active_id);
750  $shuffle = $this->object->getShuffleQuestions();
751  if ($this->object->isRandomTest())
752  {
753  $this->object->generateRandomQuestions($this->object->getTestSession()->getActiveId());
754  $this->object->loadQuestions();
755  $shuffle = FALSE; // shuffle is already done during the creation of the random questions
756  }
757  $this->object->createTestSequence($active_id, 0, $shuffle);
758  $active_time_id = $this->object->startWorkingTime($this->object->getTestSession()->getActiveId(), $this->object->getTestSession()->getPass());
759  $_SESSION["active_time_id"] = $active_time_id;
760  if ($this->object->getListOfQuestionsStart())
761  {
762  $this->ctrl->setParameter($this, "activecommand", "summary");
763  $this->ctrl->redirect($this, "redirectQuestion");
764  }
765  else
766  {
767  $this->ctrl->setParameter($this, "sequence", $this->sequence);
768  $this->ctrl->setParameter($this, "activecommand", "gotoquestion");
769  $this->ctrl->saveParameter($this, "tst_javascript");
770  $this->ctrl->redirect($this, "redirectQuestion");
771  }
772  break;
773  case "resume":
774  $_SESSION['tst_pass_finish'] = 0;
775  $active_id = $this->object->getTestSession()->getActiveId();
776  $this->ctrl->setParameter($this, "active_id", $active_id);
777 
778  if ($this->object->isRandomTest())
779  {
780  if (!$this->object->hasRandomQuestionsForPass($active_id, $this->object->getTestSession()->getPass()))
781  {
782  // create a new set of random questions
783  $this->object->generateRandomQuestions($active_id, $this->object->getTestSession()->getPass());
784  }
785  }
786 
787  $shuffle = $this->object->getShuffleQuestions();
788  if ($this->object->isRandomTest())
789  {
790  $shuffle = FALSE;
791  }
792  $this->object->createTestSequence($active_id, $this->object->getTestSession()->getPass(), $shuffle);
793 
794  $this->sequence = $this->object->getTestSession()->getLastSequence();
795  $active_time_id = $this->object->startWorkingTime($active_id, $this->object->getTestSession()->getPass());
796  $_SESSION["active_time_id"] = $active_time_id;
797  if ($this->object->getListOfQuestionsStart())
798  {
799  $this->ctrl->setParameter($this, "activecommand", "summary");
800  $this->ctrl->redirect($this, "redirectQuestion");
801  }
802  else
803  {
804  $this->ctrl->setParameter($this, "sequence", $this->sequence);
805  $this->ctrl->setParameter($this, "activecommand", "gotoquestion");
806  $this->ctrl->saveParameter($this, "tst_javascript");
807  $this->ctrl->redirect($this, "redirectQuestion");
808  }
809  break;
810  case "back":
811  case "gotoquestion":
812  default:
813  $_SESSION['tst_pass_finish'] = 0;
814  if (array_key_exists("tst_javascript", $_GET))
815  {
816  $ilUser->writePref("tst_javascript", $_GET["tst_javascript"]);
817  }
818  $this->sequence = $this->calculateSequence();
819  $this->object->getTestSession()->setLastSequence($this->sequence);
820  $this->object->getTestSession()->saveToDb();
821  $this->outTestPage();
822  break;
823  }
824  }
825 
833  function calculateSequence()
834  {
835  $sequence = $_GET["sequence"];
836  if (!$sequence) $sequence = $this->object->getTestSequence()->getFirstSequence();
837  if (array_key_exists("save_error", $_GET))
838  {
839  if ($_GET["save_error"] == 1)
840  {
841  return $sequence;
842  }
843  }
844  switch ($_GET["activecommand"])
845  {
846  case "next":
847  $sequence = $this->object->getTestSequence()->getNextSequence($sequence);
848  break;
849  case "previous":
850  $sequence = $this->object->getTestSequence()->getPreviousSequence($sequence);
851  break;
852  }
853  return $sequence;
854  }
855 
857  {
858  $this->tpl->addBlockFile($this->getContentBlockName(), "adm_content", "tpl.il_as_tst_redirect_autosave.html", "Modules/Test");
859  $this->tpl->setVariable("TEXT_REDIRECT", $this->lng->txt("redirectAfterSave"));
860  $this->tpl->setCurrentBlock("HeadContent");
861  $this->tpl->setVariable("CONTENT_BLOCK", "<meta http-equiv=\"refresh\" content=\"5; url=" . $this->ctrl->getLinkTarget($this, "redirectBack") . "\">");
862  $this->tpl->parseCurrentBlock();
863  }
864 
865  function autosave()
866  {
867  global $ilLog;
868  $result = "";
869  if (is_array($_POST) && count($_POST) > 0)
870  {
871  $res = $this->saveQuestionSolution(TRUE);
872  if ($res)
873  {
874  $result = $this->lng->txt("autosave_success");
875  }
876  else
877  {
878  $result = $this->lng->txt("autosave_failed");
879  }
880  }
881  if (!$this->canSaveResult())
882  {
883  // this was the last action in the test, saving is no longer allowed
884  $result = $this->ctrl->getLinkTarget($this, "redirectAfterAutosave");
885  }
886  echo $result;
887  exit;
888  }
889 
897  function next()
898  {
899  $this->saveQuestionSolution();
900  $this->ctrl->setParameter($this, "activecommand", "next");
901  $this->ctrl->redirect($this, "redirectQuestion");
902  }
903 
911  function previous()
912  {
913  $this->saveQuestionSolution();
914  $this->ctrl->setParameter($this, "activecommand", "previous");
915  $this->ctrl->redirect($this, "redirectQuestion");
916  }
917 
925  function postpone()
926  {
927  $this->saveQuestionSolution();
928  $this->ctrl->setParameter($this, "activecommand", "postpone");
929  $this->ctrl->redirect($this, "redirectQuestion");
930  }
931 
939  function summary()
940  {
941  $this->saveQuestionSolution();
942  if ($this->saveResult == FALSE)
943  {
944  $this->ctrl->setParameter($this, "activecommand", "");
945  $this->ctrl->redirect($this, "redirectQuestion");
946  }
947  else
948  {
949  $this->ctrl->setParameter($this, "activecommand", "summary");
950  $this->ctrl->redirect($this, "redirectQuestion");
951  }
952  }
953 
961  function setmarked()
962  {
963  $this->saveQuestionSolution();
964  $this->ctrl->setParameter($this, "activecommand", "setmarked");
965  $this->ctrl->redirect($this, "redirectQuestion");
966  }
967 
975  function resetmarked()
976  {
977  $this->saveQuestionSolution();
978  $this->ctrl->setParameter($this, "activecommand", "resetmarked");
979  $this->ctrl->redirect($this, "redirectQuestion");
980  }
981 
989  function directfeedback()
990  {
991  $this->saveQuestionSolution();
992  $this->ctrl->setParameter($this, "activecommand", "directfeedback");
993  $this->ctrl->redirect($this, "redirectQuestion");
994  }
995 
1004  {
1005  $this->saveQuestionSolution();
1006  $activecommand = "selectImagemapRegion";
1007  if (array_key_exists("cmd", $_POST))
1008  {
1009  $activecommand = key($_POST["cmd"]);
1010  }
1011  $this->ctrl->setParameter($this, "activecommand", $activecommand);
1012  $this->ctrl->redirect($this, "redirectQuestion");
1013  }
1014 
1022  function gotoQuestion()
1023  {
1024  if (is_array($_POST) && count($_POST) > 0) $this->saveQuestionSolution();
1025  $this->ctrl->setParameter($this, "sequence", $_GET["sequence"]);
1026  $this->ctrl->setParameter($this, "activecommand", "gotoquestion");
1027  $this->ctrl->saveParameter($this, "tst_javascript");
1028  $this->ctrl->redirect($this, "redirectQuestion");
1029  }
1030 
1038  function backFromSummary()
1039  {
1040  $this->ctrl->setParameter($this, "activecommand", "back");
1041  $this->ctrl->redirect($this, "redirectQuestion");
1042  }
1043 
1051  function confirmFinish()
1052  {
1053  $this->finishTest(false);
1054  }
1055 
1064  {
1065  global $ilUser;
1066 
1067  $template = new ilTemplate("tpl.il_as_tst_finish_confirmation.html", TRUE, TRUE, "Modules/Test");
1068  $template->setVariable("FINISH_QUESTION", $this->lng->txt("tst_finish_confirmation_question"));
1069  $template->setVariable("BUTTON_CONFIRM", $this->lng->txt("tst_finish_confirm_button"));
1070  if ($this->object->canShowSolutionPrintview($ilUser->getId()))
1071  {
1072  $template->setVariable("BUTTON_CANCEL", $this->lng->txt("tst_finish_confirm_list_of_answers_button"));
1073  }
1074  else
1075  {
1076  $template->setVariable("BUTTON_CANCEL", $this->lng->txt("tst_finish_confirm_cancel_button"));
1077  }
1078  $template->setVariable("FORMACTION", $this->ctrl->getFormAction($this));
1079  $this->tpl->setVariable($this->getContentBlockName(), $template->get());
1080  }
1081 
1089  function finishTest($confirm = true)
1090  {
1091  global $ilUser;
1092  global $ilias;
1093  global $ilAuth;
1094 
1095  unset($_SESSION["tst_next"]);
1096 
1097  $active_id = $this->object->getTestSession()->getActiveId();
1098  $actualpass = $this->object->_getPass($active_id);
1099  if (($actualpass == $this->object->getNrOfTries() - 1) && (!$confirm))
1100  {
1101  $this->object->setActiveTestSubmitted($ilUser->getId());
1102  $ilAuth->setIdle($ilias->ini->readVariable("session","expire"), false);
1103  $ilAuth->setExpire(0);
1104  }
1105 
1106  if (($confirm) && ($actualpass == $this->object->getNrOfTries() - 1))
1107  {
1108  if ($this->object->canShowSolutionPrintview($ilUser->getId()))
1109  {
1110  $template = new ilTemplate("tpl.il_as_tst_finish_navigation.html", TRUE, TRUE, "Modules/Test");
1111  $template->setVariable("BUTTON_FINISH", $this->lng->txt("btn_next"));
1112  $template->setVariable("BUTTON_CANCEL", $this->lng->txt("btn_previous"));
1113 
1114  $template_top = new ilTemplate("tpl.il_as_tst_list_of_answers_topbuttons.html", TRUE, TRUE, "Modules/Test");
1115  $template_top->setCurrentBlock("button_print");
1116  $template_top->setVariable("BUTTON_PRINT", $this->lng->txt("print"));
1117  $template_top->parseCurrentBlock();
1118 
1119  $this->showListOfAnswers($active_id, NULL, $template_top->get(), $template->get());
1120  return;
1121  }
1122  else
1123  {
1124  // show confirmation page
1125  return $this->confirmFinishTest();
1126  }
1127  }
1128 
1129  if (!$_SESSION['tst_pass_finish'])
1130  {
1131  if (!$_SESSION['tst_pass_finish']) $_SESSION['tst_pass_finish'] = 1;
1132  $this->object->getTestSession()->increasePass();
1133  $this->object->getTestSession()->setLastSequence(0);
1134  $this->object->getTestSession()->saveToDb();
1135  }
1136  $this->redirectBack();
1137  }
1138 
1139  public function redirectBack()
1140  {
1141  if (!$_GET["skipfinalstatement"])
1142  {
1143  if ($this->object->getShowFinalStatement())
1144  {
1145  $this->ctrl->redirect($this, "showFinalStatement");
1146  }
1147  }
1148  if($_GET['crs_show_result'])
1149  {
1150  $this->ctrl->redirectByClass("ilobjtestgui", "backToCourse");
1151  }
1152 
1153  if (!$this->object->canViewResults())
1154  {
1155  $this->outIntroductionPage();
1156  }
1157  else
1158  {
1159  $this->ctrl->redirectByClass("ilTestEvaluationGUI", "outUserResultsOverview");
1160  }
1161  }
1162 
1163  /*
1164  * Presents the final statement of a test
1165  */
1166  public function showFinalStatement()
1167  {
1168  $template = new ilTemplate("tpl.il_as_tst_final_statement.html", TRUE, TRUE, "Modules/Test");
1169  $this->ctrl->setParameter($this, "crs_show_result", $_GET['crs_show_result']);
1170  $this->ctrl->setParameter($this, "skipfinalstatement", 1);
1171  $template->setVariable("FORMACTION", $this->ctrl->getFormAction($this, "redirectBack"));
1172  $template->setVariable("FINALSTATEMENT", $this->object->getFinalStatement());
1173  $template->setVariable("BUTTON_CONTINUE", $this->lng->txt("btn_next"));
1174  $this->tpl->setVariable($this->getContentBlockName(), $template->get());
1175  }
1176 
1184  function outTestPage()
1185  {
1186  global $rbacsystem, $ilUser;
1187  $this->tpl->addBlockFile($this->getContentBlockName(), "adm_content", "tpl.il_as_tst_output.html", "Modules/Test");
1188  if (!$rbacsystem->checkAccess("read", $this->object->getRefId()))
1189  {
1190  // only with read access it is possible to run the test
1191  $this->ilias->raiseError($this->lng->txt("cannot_execute_test"),$this->ilias->error_obj->MESSAGE);
1192  }
1193 
1194  if ($this->isMaxProcessingTimeReached())
1195  {
1196  $this->maxProcessingTimeReached();
1197  return;
1198  }
1199 
1200  if ($this->object->endingTimeReached())
1201  {
1202  $this->endingTimeReached();
1203  return;
1204  }
1205 
1206  if ($this->object->getKioskMode())
1207  {
1208  ilUtil::sendInfo();
1209  if ($this->object->getShowKioskModeTitle())
1210  {
1211  $this->tpl->setCurrentBlock("kiosk_show_title");
1212  $this->tpl->setVariable("TEST_TITLE", $this->object->getTitle());
1213  $this->tpl->parseCurrentBlock();
1214  }
1215  if ($this->object->getShowKioskModeParticipant())
1216  {
1217  $this->tpl->setCurrentBlock("kiosk_show_participant");
1218  $this->tpl->setVariable("PARTICIPANT_NAME", $this->lng->txt("login_as") . " " . $ilUser->getFullname());
1219  $this->tpl->parseCurrentBlock();
1220  }
1221  }
1222 
1223  if (($this->object->getInstantFeedbackSolution() == 1) || ($this->object->getAnswerFeedback() == 1) || ($this->object->getAnswerFeedbackPoints() == 1))
1224  {
1225  $this->tpl->setCurrentBlock("direct_feedback");
1226  $this->tpl->setVariable("TEXT_DIRECT_FEEDBACK", $this->lng->txt("check"));
1227  $this->tpl->parseCurrentBlock();
1228  }
1229 
1230  $postpone = false;
1231  if ($this->object->getSequenceSettings() == TEST_POSTPONE)
1232  {
1233  $postpone = true;
1234  }
1235 
1236  if ($this->object->getEnableProcessingTime())
1237  {
1238  $this->outProcessingTime($this->object->getTestSession()->getActiveId());
1239  }
1240 
1241  $this->tpl->setVariable("FORM_TIMESTAMP", time());
1242  $directfeedback = 0;
1243  if (strcmp($_GET["activecommand"], "directfeedback") == 0) $directfeedback = 1;
1244  $this->outWorkingForm($this->sequence, $this->object->getTestId(), $postpone, $directfeedback, $show_summary);
1245  $this->tpl->setVariable("PAGETITLE", "- " . $this->object->getTitle());
1246  }
1247 
1256  {
1257  global $ilUser;
1258 
1259  // check if user is invited to participate
1260  $user = $this->object->getInvitedUsers($ilUser->getId());
1261  if (!is_array ($user) || count($user)!=1)
1262  {
1263  ilUtil::sendInfo($this->lng->txt("user_not_invited"), true);
1264  $this->ctrl->redirectByClass("ilobjtestgui", "backToRepository");
1265  }
1266 
1267  $user = array_pop($user);
1268  // check if client ip is set and if current remote addr is equal to stored client-ip
1269  if (strcmp($user->clientip,"")!=0 && strcmp($user->clientip,$_SERVER["REMOTE_ADDR"])!=0)
1270  {
1271  ilUtil::sendInfo($this->lng->txt("user_wrong_clientip"), true);
1272  $this->ctrl->redirectByClass("ilobjtestgui", "backToRepository");
1273  }
1274  }
1275 
1276 
1280  function isTestAccessible()
1281  {
1282  return !$this->isNrOfTriesReached()
1283  and !$this->isMaxProcessingTimeReached()
1284  and $this->object->startingTimeReached()
1285  and !$this->object->endingTimeReached();
1286  }
1287 
1292  {
1293  return $this->object->hasNrOfTriesRestriction() && $this->object->isNrOfTriesReached($this->object->getTestSession()->getPass());
1294  }
1295 
1303  function passDetails()
1304  {
1305  if (array_key_exists("pass", $_GET) && (strlen($_GET["pass"]) > 0))
1306  {
1307  $this->ctrl->saveParameter($this, "pass");
1308  $this->ctrl->saveParameter($this, "active_id");
1309  $this->outTestResults(false, $_GET["pass"]);
1310  }
1311  else
1312  {
1313  $this->outTestResults(false);
1314  }
1315  }
1316 
1322  function endingTimeReached()
1323  {
1324  ilUtil::sendInfo(sprintf($this->lng->txt("detail_ending_time_reached"), ilFormat::ftimestamp2datetimeDB($this->object->getEndingTime())));
1325  $this->object->getTestSession()->increasePass();
1326  $this->object->getTestSession()->setLastSequence(0);
1327  $this->object->getTestSession()->saveToDb();
1328  if (!$this->object->canViewResults())
1329  {
1330  $this->outIntroductionPage();
1331  }
1332  else
1333  {
1334  $this->ctrl->redirectByClass("ilTestEvaluationGUI", "outUserResultsOverview");
1335  }
1336  }
1337 
1346  {
1347  $this->outIntroductionPage();
1348  }
1349 
1356  {
1357  $this->tpl->addBlockFile($this->getContentBlockName(), "adm_content", "tpl.il_as_tst_submit_answers_confirm.html", "Modules/Test");
1358  $this->tpl->setCurrentBlock("adm_content");
1359  if ($this->object->isActiveTestSubmitted())
1360  {
1361  $this->tpl->setCurrentBlock("not_submit_allowed");
1362  $this->tpl->setVariable("TEXT_ALREADY_SUBMITTED", $this->lng->txt("tst_already_submitted"));
1363  $this->tpl->setVariable("BTN_OK", $this->lng->txt("tst_show_answer_sheet"));
1364  } else
1365  {
1366  $this->tpl->setCurrentBlock("submit_allowed");
1367  $this->tpl->setVariable("TEXT_CONFIRM_SUBMIT_RESULTS", $this->lng->txt("tst_confirm_submit_answers"));
1368  $this->tpl->setVariable("BTN_OK", $this->lng->txt("tst_submit_results"));
1369  }
1370  $this->tpl->setVariable("BTN_BACK", $this->lng->txt("back"));
1371  $this->tpl->setVariable("FORMACTION", $this->ctrl->getFormAction($this, "finalSubmission"));
1372  $this->tpl->parseCurrentBlock();
1373  }
1374 
1375  function outProcessingTime($active_id)
1376  {
1377  global $ilUser;
1378 
1379  $starting_time = $this->object->getStartingTimeOfUser($active_id);
1380  $processing_time = $this->object->getProcessingTimeInSeconds();
1381  $processing_time_minutes = floor($processing_time / 60);
1382  $processing_time_seconds = $processing_time - $processing_time_minutes * 60;
1383  $str_processing_time = "";
1384  if ($processing_time_minutes > 0)
1385  {
1386  $str_processing_time = $processing_time_minutes . " " . $this->lng->txt("minutes");
1387  }
1388  if ($processing_time_seconds > 0)
1389  {
1390  if (strlen($str_processing_time) > 0) $str_processing_time .= " " . $this->lng->txt("and") . " ";
1391  $str_processing_time .= $processing_time_seconds . " " . $this->lng->txt("seconds");
1392  }
1393  $time_left = $starting_time + $processing_time - mktime();
1394  $time_left_minutes = floor($time_left / 60);
1395  $time_left_seconds = $time_left - $time_left_minutes * 60;
1396  $str_time_left = "";
1397  if ($time_left_minutes > 0)
1398  {
1399  $str_time_left = $time_left_minutes . " " . $this->lng->txt("minutes");
1400  }
1401  if ($time_left < 300)
1402  {
1403  if ($time_left_seconds > 0)
1404  {
1405  if (strlen($str_time_left) > 0) $str_time_left .= " " . $this->lng->txt("and") . " ";
1406  $str_time_left .= $time_left_seconds . " " . $this->lng->txt("seconds");
1407  }
1408  }
1409  $date = getdate($starting_time);
1410  $formattedStartingTime = ilDatePresentation::formatDate(new ilDateTime($date,IL_CAL_FKT_GETDATE));
1411  /*
1412  $formattedStartingTime = ilFormat::formatDate(
1413  $date["year"]."-".
1414  sprintf("%02d", $date["mon"])."-".
1415  sprintf("%02d", $date["mday"])." ".
1416  sprintf("%02d", $date["hours"]).":".
1417  sprintf("%02d", $date["minutes"]).":".
1418  sprintf("%02d", $date["seconds"])
1419  );
1420  */
1421  $datenow = getdate();
1422  $this->tpl->setCurrentBlock("enableprocessingtime");
1423  $this->tpl->setVariable("USER_WORKING_TIME",
1424  sprintf(
1425  $this->lng->txt("tst_time_already_spent"),
1426  $formattedStartingTime,
1427  $str_processing_time
1428  )
1429  );
1430  $this->tpl->setVariable("USER_REMAINING_TIME", sprintf($this->lng->txt("tst_time_already_spent_left"), $str_time_left));
1431  $this->tpl->parseCurrentBlock();
1432  $template = new ilTemplate("tpl.workingtime.js.html", TRUE, TRUE, TRUE);
1433  $template->setVariable("STRING_MINUTE", $this->lng->txt("minute"));
1434  $template->setVariable("STRING_MINUTES", $this->lng->txt("minutes"));
1435  $template->setVariable("STRING_SECOND", $this->lng->txt("second"));
1436  $template->setVariable("STRING_SECONDS", $this->lng->txt("seconds"));
1437  $template->setVariable("STRING_TIMELEFT", $this->lng->txt("tst_time_already_spent_left"));
1438  $template->setVariable("AND", strtolower($this->lng->txt("and")));
1439  $template->setVariable("YEAR", $date["year"]);
1440  $template->setVariable("MONTH", $date["mon"]-1);
1441  $template->setVariable("DAY", $date["mday"]);
1442  $template->setVariable("HOUR", $date["hours"]);
1443  $template->setVariable("MINUTE", $date["minutes"]);
1444  $template->setVariable("SECOND", $date["seconds"]);
1445  if (preg_match("/(\d{4})(\d{2})(\d{2})(\d{2})(\d{2})(\d{2})/", $this->object->getEndingTime(), $matches))
1446  {
1447  $template->setVariable("ENDYEAR", $matches[1]);
1448  $template->setVariable("ENDMONTH", $matches[2]-1);
1449  $template->setVariable("ENDDAY", $matches[3]);
1450  $template->setVariable("ENDHOUR", $matches[4]);
1451  $template->setVariable("ENDMINUTE", $matches[5]);
1452  $template->setVariable("ENDSECOND", $matches[6]);
1453  }
1454  $template->setVariable("YEARNOW", $datenow["year"]);
1455  $template->setVariable("MONTHNOW", $datenow["mon"]-1);
1456  $template->setVariable("DAYNOW", $datenow["mday"]);
1457  $template->setVariable("HOURNOW", $datenow["hours"]);
1458  $template->setVariable("MINUTENOW", $datenow["minutes"]);
1459  $template->setVariable("SECONDNOW", $datenow["seconds"]);
1460  $template->setVariable("PTIME_M", $processing_time_minutes);
1461  $template->setVariable("PTIME_S", $processing_time_seconds);
1462 
1463  $this->tpl->setCurrentBlock("HeadContent");
1464  $this->tpl->setVariable("CONTENT_BLOCK", $template->get());
1465  $this->tpl->parseCurrentBlock();
1466  }
1467 
1474  {
1475  $active_id = $this->object->getTestSession()->getActiveId();
1476  $this->tpl->addBlockFile($this->getContentBlockName(), "adm_content", "tpl.il_as_tst_question_summary.html", "Modules/Test");
1477  $color_class = array ("tblrow1", "tblrow2");
1478  $counter = 0;
1479 
1480  $result_array = & $this->object->getTestSequence()->getSequenceSummary();
1481  $marked_questions = array();
1482  if ($this->object->getShowMarker())
1483  {
1484  include_once "./Modules/Test/classes/class.ilObjTest.php";
1485  $marked_questions = ilObjTest::_getSolvedQuestions($active_id);
1486  }
1487  foreach ($result_array as $key => $value)
1488  {
1489  if (preg_match("/\d+/", $key))
1490  {
1491  $this->tpl->setCurrentBlock("question");
1492  $this->tpl->setVariable("COLOR_CLASS", $color_class[$counter % 2]);
1493  $this->tpl->setVariable("VALUE_QUESTION_COUNTER", $value["nr"]);
1494  $this->ctrl->setParameter($this, "sequence", $value["sequence"]);
1495  $this->tpl->setVariable("VALUE_QUESTION_TITLE", "<a href=\"".$this->ctrl->getLinkTargetByClass(get_class($this), "gotoQuestion")."\">" . $this->object->getQuestionTitle($value["title"]) . "</a>");
1496  $this->ctrl->setParameter($this, "sequence", $_GET["sequence"]);
1497  if ($this->object->getListOfQuestionsDescription())
1498  {
1499  $this->tpl->setVariable("VALUE_QUESTION_DESCRIPTION", $value["description"]);
1500  }
1501  if ($value["worked_through"])
1502  {
1503  $this->tpl->setVariable("VALUE_WORKED_THROUGH", ilUtil::getImagePath("icon_ok.gif"));
1504  $this->tpl->setVariable("ALT_WORKED_THROUGH", $this->lng->txt("worked_through"));
1505  }
1506  else
1507  {
1508  $this->tpl->setVariable("VALUE_WORKED_THROUGH", ilUtil::getImagePath("icon_not_ok.gif"));
1509  $this->tpl->setVariable("ALT_WORKED_THROUGH", $this->lng->txt("not_worked_through"));
1510  }
1511  if ($value["postponed"])
1512  {
1513  $this->tpl->setVariable("VALUE_POSTPONED", $this->lng->txt("postponed"));
1514  }
1515  if (!$this->object->getTitleOutput())
1516  {
1517  $this->tpl->setVariable("VALUE_QUESTION_POINTS", $value["points"]."&nbsp;".$this->lng->txt("points_short"));
1518  }
1519  if (count($marked_questions))
1520  {
1521  if (array_key_exists($value["qid"], $marked_questions))
1522  {
1523  $obj = $marked_questions[$value["qid"]];
1524  if ($obj->solved == 1)
1525  {
1526  $this->tpl->setVariable("ALT_MARKED_IMAGE", $this->lng->txt("tst_question_marked"));
1527  $this->tpl->setVariable("TITLE_MARKED_IMAGE", $this->lng->txt("tst_question_marked"));
1528  $this->tpl->setVariable("MARKED_IMAGE", ilUtil::getImagePath("marked.png"));
1529  }
1530  }
1531  }
1532  $this->tpl->parseCurrentBlock();
1533  $counter ++;
1534  }
1535  }
1536 
1537  $this->tpl->setVariable("QUESTION_ACTION","actions");
1538  $this->tpl->setVariable("QUESTION_COUNTER", $this->lng->txt("tst_qst_order"));
1539  $this->tpl->setVariable("QUESTION_TITLE", $this->lng->txt("tst_question_title"));
1540  if (!$this->object->getTitleOutput())
1541  {
1542  $this->tpl->setVariable("QUESTION_POINTS", $this->lng->txt("tst_maximum_points"));
1543  }
1544  if ($this->object->getShowMarker())
1545  {
1546  $this->tpl->setVariable("TEXT_MARKED", $this->lng->txt("tst_question_marker"));
1547  }
1548  $this->tpl->setVariable("WORKED_THROUGH", $this->lng->txt("worked_through"));
1549  $this->tpl->setVariable("USER_FEEDBACK", $this->lng->txt("tst_qst_summary_text"));
1550  $this->tpl->setVariable("TXT_BACK", $this->lng->txt("back"));
1551  $this->tpl->setVariable("TXT_SHOW_AND_SUBMIT_ANSWERS", $this->lng->txt("save_finish"));
1552  $this->tpl->setVariable("FORMACTION", $this->ctrl->getFormAction($this, "backFromSummary"));
1553  $this->tpl->setVariable("TEXT_RESULTS", $this->lng->txt("question_summary"));
1554 
1555  if ($this->object->getEnableProcessingTime())
1556  $this->outProcessingTime($active_id);
1557  }
1558 
1560  {
1561  $this->tpl->addBlockFile($this->getContentBlockName(), "adm_content", "tpl.il_as_tst_max_allowed_users_reached.html", "Modules/Test");
1562  $this->tpl->setCurrentBlock("adm_content");
1563  $this->tpl->setVariable("MAX_ALLOWED_USERS_MESSAGE", sprintf($this->lng->txt("tst_max_allowed_users_message"), $this->object->getAllowedUsersTimeGap()));
1564  $this->tpl->setVariable("MAX_ALLOWED_USERS_HEADING", sprintf($this->lng->txt("tst_max_allowed_users_heading"), $this->object->getAllowedUsersTimeGap()));
1565  $this->tpl->setVariable("BACK_TO_INTRODUCTION", $this->lng->txt("tst_results_back_introduction"));
1566  $this->tpl->setVariable("FORMACTION", $this->ctrl->getFormAction($this));
1567  $this->tpl->parseCurrentBlock();
1568  }
1569 
1571  {
1572  global $ilUser;
1573  if ($this->object->canShowSolutionPrintview($ilUser->getId()))
1574  {
1575  $template = new ilTemplate("tpl.il_as_tst_finish_navigation.html", TRUE, TRUE, "Modules/Test");
1576  $template->setVariable("BUTTON_FINISH", $this->lng->txt("btn_next"));
1577  $template->setVariable("BUTTON_CANCEL", $this->lng->txt("btn_previous"));
1578 
1579  $template_top = new ilTemplate("tpl.il_as_tst_list_of_answers_topbuttons.html", TRUE, TRUE, "Modules/Test");
1580  $template_top->setCurrentBlock("button_print");
1581  $template_top->setVariable("BUTTON_PRINT", $this->lng->txt("print"));
1582  $template_top->parseCurrentBlock();
1583  $active_id = $this->object->getTestSession()->getActiveId();
1584  return $this->showListOfAnswers($active_id, NULL, $template_top->get(), $template->get());
1585  }
1586  else
1587  {
1588  $this->ctrl->redirect($this, "redirectQuestion");
1589  }
1590  }
1591 
1593  {
1594  $this->confirmFinishTest();
1595  }
1596 
1603  {
1604  $this->tpl->addBlockFile("ADM_CONTENT", "adm_content", "tpl.il_as_tst_correct_solution.html", "Modules/Test");
1605 
1606  include_once("./Services/Style/classes/class.ilObjStyleSheet.php");
1607  $this->tpl->setCurrentBlock("ContentStyle");
1608  $this->tpl->setVariable("LOCATION_CONTENT_STYLESHEET", ilObjStyleSheet::getContentStylePath(0));
1609  $this->tpl->parseCurrentBlock();
1610 
1611  $this->tpl->setCurrentBlock("SyntaxStyle");
1612  $this->tpl->setVariable("LOCATION_SYNTAX_STYLESHEET", ilObjStyleSheet::getSyntaxStylePath());
1613  $this->tpl->parseCurrentBlock();
1614 
1615  $this->tpl->addCss(ilUtil::getStyleSheetLocation("output", "test_print.css", "Modules/Test"), "print");
1616  if ($this->object->getShowSolutionAnswersOnly())
1617  {
1618  $this->tpl->addCss(ilUtil::getStyleSheetLocation("output", "test_print_hide_content.css", "Modules/Test"), "print");
1619  }
1620 
1621  $this->tpl->setCurrentBlock("adm_content");
1622  $solution = $this->getCorrectSolutionOutput($_GET["evaluation"], $_GET["active_id"], $_GET["pass"]);
1623  $this->tpl->setVariable("OUTPUT_SOLUTION", $solution);
1624  $this->tpl->setVariable("TEXT_BACK", $this->lng->txt("back"));
1625  $this->ctrl->saveParameter($this, "pass");
1626  $this->ctrl->saveParameter($this, "active_id");
1627  $this->tpl->setVariable("URL_BACK", $this->ctrl->getLinkTarget($this, "outUserResultsOverview"));
1628  $this->tpl->parseCurrentBlock();
1629  }
1630 
1640  function showListOfAnswers($active_id, $pass = NULL, $top_data = "", $bottom_data = "")
1641  {
1642  global $ilUser;
1643 
1644  $this->tpl->addBlockFile($this->getContentBlockName(), "adm_content", "tpl.il_as_tst_finish_list_of_answers.html", "Modules/Test");
1645 
1646  $result_array =& $this->object->getTestResult($active_id, $pass);
1647 
1648  $counter = 1;
1649  // output of questions with solutions
1650  foreach ($result_array as $question_data)
1651  {
1652  $question = $question_data["qid"];
1653  if (is_numeric($question))
1654  {
1655  $this->tpl->setCurrentBlock("printview_question");
1656  $question_gui = $this->object->createQuestionGUI("", $question);
1657  $template = new ilTemplate("tpl.il_as_qpl_question_printview.html", TRUE, TRUE, "Modules/TestQuestionPool");
1658  $template->setVariable("COUNTER_QUESTION", $counter.". ");
1659  $template->setVariable("QUESTION_TITLE", $question_gui->object->getTitle());
1660 
1661  $show_question_only = ($this->object->getShowSolutionAnswersOnly()) ? TRUE : FALSE;
1662  $result_output = $question_gui->getSolutionOutput($active_id, $pass, FALSE, FALSE, $show_question_only, $this->object->getShowSolutionFeedback());
1663  $template->setVariable("SOLUTION_OUTPUT", $result_output);
1664  $this->tpl->setVariable("QUESTION_OUTPUT", $template->get());
1665  $this->tpl->parseCurrentBlock();
1666  $counter ++;
1667  }
1668  }
1669 
1670  $this->tpl->addCss(ilUtil::getStyleSheetLocation("output", "test_print.css", "Modules/Test"), "print");
1671  if ($this->object->getShowSolutionAnswersOnly())
1672  {
1673  $this->tpl->addCss(ilUtil::getStyleSheetLocation("output", "test_print_hide_content.css", "Modules/Test"), "print");
1674  }
1675  if (strlen($top_data))
1676  {
1677  $this->tpl->setCurrentBlock("top_data");
1678  $this->tpl->setVariable("TOP_DATA", $top_data);
1679  $this->tpl->parseCurrentBlock();
1680  }
1681 
1682  if (strlen($bottom_data))
1683  {
1684  $this->tpl->setCurrentBlock("bottom_data");
1685  $this->tpl->setVariable("FORMACTION", $this->ctrl->getFormAction($this));
1686  $this->tpl->setVariable("BOTTOM_DATA", $bottom_data);
1687  $this->tpl->parseCurrentBlock();
1688  }
1689 
1690  $this->tpl->setCurrentBlock("adm_content");
1691  $this->tpl->setVariable("TXT_ANSWER_SHEET", $this->lng->txt("tst_list_of_answers"));
1692  $user_data = $this->getResultsUserdata($active_id, TRUE);
1693  $signature = $this->getResultsSignature();
1694  $this->tpl->setVariable("USER_DETAILS", $user_data);
1695  $this->tpl->setVariable("SIGNATURE", $signature);
1696  $this->tpl->setVariable("TITLE", $this->object->getTitle());
1697  $this->tpl->setVariable("TXT_TEST_PROLOG", $this->lng->txt("tst_your_answers"));
1698  $invited_user =& $this->object->getInvitedUsers($ilUser->getId());
1699  $pagetitle = $this->object->getTitle() . " - " . $this->lng->txt("clientip") .
1700  ": " . $invited_user[$ilUser->getId()]->clientip . " - " .
1701  $this->lng->txt("matriculation") . ": " .
1702  $invited_user[$ilUser->getId()]->matriculation;
1703  $this->tpl->setVariable("PAGETITLE", $pagetitle);
1704  $this->tpl->parseCurrentBlock();
1705  }
1706 
1713  private function getContentBlockName()
1714  {
1715  if ($this->object->getKioskMode())
1716  {
1717  $this->tpl->setVariable("BODY_CLASS", "kiosk");
1718  $this->tpl->setAddFooter(FALSE);
1719  return "CONTENT";
1720  }
1721  else
1722  {
1723  return "ADM_CONTENT";
1724  }
1725  }
1726 
1728  {
1729  $this->ctrl->redirectByClass("iltestevaluationgui", "outUserResultsOverview");
1730  }
1731 
1733  {
1734  $this->ctrl->redirectByClass("iltestevaluationgui", "outUserListOfAnswerPasses");
1735  }
1736 
1737 }
1738 ?>