ILIAS  Release_4_1_x_branch Revision 61804
 All Data Structures Namespaces Files Functions Variables Groups Pages
class.ilTestOutputGUI.php
Go to the documentation of this file.
1 <?php
2 
3 /* Copyright (c) 1998-2010 ILIAS open source, Extended GPL, see docs/LICENSE */
4 
5 include_once "./Modules/Test/classes/inc.AssessmentConstants.php";
6 include_once "./Modules/Test/classes/class.ilTestServiceGUI.php";
7 
21 {
22  var $ref_id;
23 
25  var $sequence;
26  var $cmdCtrl;
29 
38  function ilTestOutputGUI($a_object)
39  {
40  parent::ilTestServiceGUI($a_object);
41  $this->ref_id = $_GET["ref_id"];
42  }
43 
44  /*
45  * Save tags for tagging gui
46  *
47  * Needed this function here because the test info page
48  * uses another class to send its form results
49  */
50  function saveTags()
51  {
52  include_once("./Services/Tagging/classes/class.ilTaggingGUI.php");
53  $tagging_gui = new ilTaggingGUI();
54  $tagging_gui->setObject($this->object->getId(), $this->object->getType());
55  $tagging_gui->saveInput();
56  $this->ctrl->redirectByClass("ilobjtestgui", "infoScreen");
57  }
58 
62  function &executeCommand()
63  {
64  global $ilUser;
65  $cmd = $this->ctrl->getCmd();
66  $next_class = $this->ctrl->getNextClass($this);
67  $this->ctrl->saveParameter($this, "sequence");
68  $this->ctrl->saveParameter($this, "active_id");
69  if (preg_match("/^gotoquestion_(\\d+)$/", $cmd, $matches))
70  {
71  $cmd = "gotoquestion";
72  if (strlen($matches[1]))
73  {
74  $this->ctrl->setParameter($this, 'gotosequence', $matches[1]);
75  }
76 
77  }
78  if ($_GET["active_id"])
79  {
80  $this->object->setTestSession($_GET["active_id"]);
81  }
82  else
83  {
84  $this->object->setTestSession();
85  }
86  include_once "./Services/YUI/classes/class.ilYuiUtil.php";
88  $cmd = $this->getCommand($cmd);
89  switch($next_class)
90  {
91  default:
92  $ret =& $this->$cmd();
93  break;
94  }
95  return $ret;
96  }
97 
102  function updateWorkingTime()
103  {
104  if ($_SESSION["active_time_id"])
105  {
106  $this->object->updateWorkingTime($_SESSION["active_time_id"]);
107  }
108  }
109 
113  function saveQuestionSolution($force = FALSE)
114  {
115  $this->updateWorkingTime();
116  $this->saveResult = FALSE;
117  if (!$force)
118  {
119  $formtimestamp = $_POST["formtimestamp"];
120  if (strlen($formtimestamp) == 0) $formtimestamp = $_GET["formtimestamp"];
121  if ($formtimestamp != $_SESSION["formtimestamp"])
122  {
123  $_SESSION["formtimestamp"] = $formtimestamp;
124  }
125  else
126  {
127  return FALSE;
128  }
129  }
130  // save question solution
131  if ($this->canSaveResult() || $force)
132  {
133  // but only if the ending time is not reached
134  $q_id = $this->object->getTestSequence()->getQuestionForSequence($_GET["sequence"]);
135  if (is_numeric($q_id))
136  {
137  global $ilUser;
138 
139  $question_gui = $this->object->createQuestionGUI("", $q_id);
140  if ($this->object->getJavaScriptOutput())
141  {
142  $question_gui->object->setOutputType(OUTPUT_JAVASCRIPT);
143  }
144  $pass = NULL;
145  $active_id = $this->object->getTestSession()->getActiveId();
146  if ($this->object->isRandomTest())
147  {
148  $pass = $this->object->_getPass($active_id);
149  }
150  $this->saveResult = $question_gui->object->saveWorkingData($active_id, $pass);
151 
152  // update learning progress (is done in ilTestSession)
153  //include_once("./Services/Tracking/classes/class.ilLPStatusWrapper.php");
154  //ilLPStatusWrapper::_updateStatus($this->object->getId(), $ilUser->getId());
155  }
156  }
157  if ($this->saveResult == FALSE)
158  {
159  $this->ctrl->setParameter($this, "save_error", "1");
160  $_SESSION["previouspost"] = $_POST;
161  }
162  return $this->saveResult;
163  }
164 
173  function canSaveResult()
174  {
175  return !$this->object->endingTimeReached() && !$this->isMaxProcessingTimeReached() && !$this->isNrOfTriesReached();
176  }
177 
186  {
187  $this->ctrl->redirectByClass("ilobjtestgui", "infoScreen");
188  }
189 
199  {
200  global $ilUser;
201  $active_id = $this->object->getTestSession()->getActiveId();
202  $starting_time = $this->object->getStartingTimeOfUser($active_id);
203  if ($starting_time === FALSE)
204  {
205  return FALSE;
206  }
207  else
208  {
209  return $this->object->isMaxProcessingTimeReached($starting_time);
210  }
211  }
212 
216  public function outWorkingForm($sequence = "", $test_id, $postpone_allowed, $directfeedback = 0)
217  {
218  global $ilUser;
219 
220  if ($sequence < 1) $sequence = $this->object->getTestSequence()->getFirstSequence();
221  $active_time_id = $this->object->startWorkingTime($this->object->getTestSession()->getActiveId(), $this->object->getTestSession()->getPass());
222  $_SESSION["active_time_id"] = $active_time_id;
223 
224  include_once("./Services/Style/classes/class.ilObjStyleSheet.php");
225  $this->tpl->setCurrentBlock("ContentStyle");
226  $this->tpl->setVariable("LOCATION_CONTENT_STYLESHEET",
228  $this->tpl->parseCurrentBlock();
229 
230  // syntax style
231  $this->tpl->setCurrentBlock("SyntaxStyle");
232  $this->tpl->setVariable("LOCATION_SYNTAX_STYLESHEET",
234  $this->tpl->parseCurrentBlock();
235 
236  if ($this->object->getListOfQuestions())
237  {
238  $show_side_list = $ilUser->getPref('side_list_of_questions');
239  $this->tpl->setCurrentBlock('view_sidelist');
240  $this->tpl->setVariable('IMAGE_SIDELIST', ($show_side_list) ? ilUtil::getImagePath('view_remove.png') : ilUtil::getImagePath('view_choose.png'));
241  $this->tpl->setVariable('TEXT_SIDELIST', ($show_side_list) ? $this->lng->txt('tst_hide_side_list') : $this->lng->txt('tst_show_side_list'));
242  $this->tpl->parseCurrentBlock();
243  if ($show_side_list)
244  {
245  $this->tpl->addCss(ilUtil::getStyleSheetLocation("output", "ta_split.css", "Modules/Test"), "screen");
246  $this->outQuestionSummary(false);
247  }
248  }
249 
250  $question_gui = $this->object->createQuestionGUI("", $this->object->getTestSequence()->getQuestionForSequence($sequence));
251  if ($this->object->getJavaScriptOutput())
252  {
253  $question_gui->object->setOutputType(OUTPUT_JAVASCRIPT);
254  }
255 
256  $is_postponed = $this->object->getTestSequence()->isPostponedQuestion($question_gui->object->getId());
257  $this->ctrl->setParameter($this, "sequence", "$sequence");
258  $formaction = $this->ctrl->getFormAction($this, "gotoQuestion");
259 
260  $question_gui->setSequenceNumber($this->object->getTestSequence()->getPositionOfSequence($sequence));
261  $question_gui->setQuestionCount($this->object->getTestSequence()->getUserQuestionCount());
262  // output question
263  $user_post_solution = FALSE;
264  if (array_key_exists("previouspost", $_SESSION))
265  {
266  $user_post_solution = $_SESSION["previouspost"];
267  unset($_SESSION["previouspost"]);
268  }
269  $answer_feedback = FALSE;
270  if (($directfeedback) && ($this->object->getAnswerFeedback()))
271  {
272  $answer_feedback = TRUE;
273  }
274  global $ilNavigationHistory;
275  $ilNavigationHistory->addItem($_GET["ref_id"], $this->ctrl->getLinkTarget($this, "resume"), "tst");
276  $question_gui->outQuestionForTest($formaction, $this->object->getTestSession()->getActiveId(), NULL, $is_postponed, $user_post_solution, $answer_feedback);
277  if ($directfeedback)
278  {
279  if ($this->object->getInstantFeedbackSolution())
280  {
281  $solutionoutput = $question_gui->getSolutionOutput($this->object->getTestSession()->getActiveId(), NULL, FALSE, FALSE, FALSE, FALSE, TRUE);
282  $this->tpl->setCurrentBlock("solution_output");
283  $this->tpl->setVariable("CORRECT_SOLUTION", $this->lng->txt("tst_best_solution_is"));
284  $this->tpl->setVariable("QUESTION_FEEDBACK", $solutionoutput);
285  $this->tpl->parseCurrentBlock();
286  }
287  if ($this->object->getAnswerFeedbackPoints())
288  {
289  $this->tpl->setCurrentBlock("solution_output");
290  $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()));
291  $this->tpl->parseCurrentBlock();
292  }
293  if ($this->object->getAnswerFeedback())
294  {
295  $this->tpl->setCurrentBlock("answer_feedback");
296  $this->tpl->setVariable("ANSWER_FEEDBACK", $question_gui->getAnswerFeedbackOutput($this->object->getTestSession()->getActiveId(), NULL));
297  $this->tpl->parseCurrentBlock();
298  }
299  }
300 
301  if ($sequence == $this->object->getTestSequence()->getFirstSequence())
302  {
303  $this->tpl->setCurrentBlock("prev");
304  $this->tpl->setVariable("BTN_PREV", "&lt;&lt; " . $this->lng->txt("save_introduction"));
305  $this->tpl->parseCurrentBlock();
306  $this->tpl->setCurrentBlock("prev_bottom");
307  $this->tpl->setVariable("BTN_PREV", "&lt;&lt; " . $this->lng->txt("save_introduction"));
308  $this->tpl->parseCurrentBlock();
309  }
310  else
311  {
312  $this->tpl->setCurrentBlock("prev");
313  $this->tpl->setVariable("BTN_PREV", "&lt;&lt; " . $this->lng->txt("save_previous"));
314  $this->tpl->parseCurrentBlock();
315  $this->tpl->setCurrentBlock("prev_bottom");
316  $this->tpl->setVariable("BTN_PREV", "&lt;&lt; " . $this->lng->txt("save_previous"));
317  $this->tpl->parseCurrentBlock();
318  }
319 
320  if ($postpone_allowed)
321  {
322  if (!$is_postponed)
323  {
324  if (!$finish)
325  {
326  $this->tpl->setCurrentBlock("postpone");
327  $this->tpl->setVariable("BTN_POSTPONE", $this->lng->txt("postpone"));
328  $this->tpl->parseCurrentBlock();
329  $this->tpl->setCurrentBlock("postpone_bottom");
330  $this->tpl->setVariable("BTN_POSTPONE", $this->lng->txt("postpone"));
331  $this->tpl->parseCurrentBlock();
332  }
333  }
334  }
335 
336  if ($this->object->getListOfQuestions())
337  {
338  if (!(($finish) && ($this->object->getListOfQuestionsEnd())))
339  {
340  $this->tpl->setCurrentBlock("summary");
341  $this->tpl->setVariable("BTN_SUMMARY", $this->lng->txt("question_summary"));
342  $this->tpl->parseCurrentBlock();
343  $this->tpl->setCurrentBlock("summary_bottom");
344  $this->tpl->setVariable("BTN_SUMMARY", $this->lng->txt("question_summary"));
345  $this->tpl->parseCurrentBlock();
346  }
347  }
348 
349  if ($this->object->getShowCancel())
350  {
351  $this->tpl->setCurrentBlock("cancel_test");
352  $this->tpl->setVariable("TEXT_CANCELTEST", $this->lng->txt("cancel_test"));
353  $this->tpl->setVariable("TEXT_ALTCANCELTEXT", $this->lng->txt("cancel_test"));
354  $this->tpl->setVariable("TEXT_TITLECANCELTEXT", $this->lng->txt("cancel_test"));
355  $this->tpl->setVariable("HREF_IMGCANCELTEST", $this->ctrl->getLinkTargetByClass(get_class($this), "outIntroductionPage") . "&cancelTest=true");
356  $this->tpl->setVariable("HREF_CANCELTEXT", $this->ctrl->getLinkTargetByClass(get_class($this), "outIntroductionPage") . "&cancelTest=true");
357  $this->tpl->setVariable("IMAGE_CANCEL", ilUtil::getImagePath("cancel.gif"));
358  $this->tpl->parseCurrentBlock();
359  }
360 
361  if ($this->object->getTestSequence()->getQuestionForSequence($this->object->getTestSequence()->getLastSequence()) == $question_gui->object->getId())
362  {
363  if ($this->object->getListOfQuestionsEnd())
364  {
365  $this->tpl->setCurrentBlock("next");
366  $this->tpl->setVariable("BTN_NEXT", $this->lng->txt("question_summary") . " &gt;&gt;");
367  $this->tpl->parseCurrentBlock();
368  $this->tpl->setCurrentBlock("next_bottom");
369  $this->tpl->setVariable("BTN_NEXT", $this->lng->txt("question_summary") . " &gt;&gt;");
370  $this->tpl->parseCurrentBlock();
371  }
372  else
373  {
374  $this->tpl->setCurrentBlock("next");
375  $this->tpl->setVariable("BTN_NEXT", $this->lng->txt("save_finish") . " &gt;&gt;");
376  $this->tpl->parseCurrentBlock();
377  $this->tpl->setCurrentBlock("next_bottom");
378  $this->tpl->setVariable("BTN_NEXT", $this->lng->txt("save_finish") . " &gt;&gt;");
379  $this->tpl->parseCurrentBlock();
380  }
381  }
382  else
383  {
384  $this->tpl->setCurrentBlock("next");
385  $this->tpl->setVariable("BTN_NEXT", $this->lng->txt("save_next") . " &gt;&gt;");
386  $this->tpl->parseCurrentBlock();
387  $this->tpl->setCurrentBlock("next_bottom");
388  $this->tpl->setVariable("BTN_NEXT", $this->lng->txt("save_next") . " &gt;&gt;");
389  $this->tpl->parseCurrentBlock();
390  }
391 
392  if ($this->object->getShowMarker())
393  {
394  include_once "./Modules/Test/classes/class.ilObjTest.php";
395  $solved_array = ilObjTest::_getSolvedQuestions($this->object->getTestSession()->getActiveId(), $question_gui->object->getId());
396  $solved = 0;
397 
398  if (count ($solved_array) > 0)
399  {
400  $solved = array_pop($solved_array);
401  $solved = $solved["solved"];
402  }
403 
404  if ($solved==1)
405  {
406  $this->tpl->setCurrentBlock("ismarked");
407  $this->tpl->setVariable("IMAGE_SET", ilUtil::getImagePath("marked.png"));
408  $this->tpl->setVariable("TEXT_SET", $this->lng->txt("tst_remove_mark"));
409  $this->tpl->parseCurrentBlock();
410  }
411  else
412  {
413  $this->tpl->setCurrentBlock("isnotmarked");
414  $this->tpl->setVariable("IMAGE_UNSET", ilUtil::getImagePath("marked_.png"));
415  $this->tpl->setVariable("TEXT_UNSET", $this->lng->txt("tst_question_mark"));
416  $this->tpl->parseCurrentBlock();
417  }
418  }
419 
420  if ($this->object->getJavaScriptOutput())
421  {
422  $this->tpl->setVariable("JAVASCRIPT_IMAGE", ilUtil::getImagePath("javascript_disable.png"));
423  $this->tpl->setVariable("JAVASCRIPT_IMAGE_ALT", $this->lng->txt("disable_javascript"));
424  $this->tpl->setVariable("JAVASCRIPT_IMAGE_TITLE", $this->lng->txt("disable_javascript"));
425  $this->ctrl->setParameter($this, "tst_javascript", "0");
426  $this->tpl->setVariable("JAVASCRIPT_URL", $this->ctrl->getLinkTarget($this, "gotoQuestion"));
427  }
428  else
429  {
430  $this->tpl->setVariable("JAVASCRIPT_IMAGE", ilUtil::getImagePath("javascript.png"));
431  $this->tpl->setVariable("JAVASCRIPT_IMAGE_ALT", $this->lng->txt("enable_javascript"));
432  $this->tpl->setVariable("JAVASCRIPT_IMAGE_TITLE", $this->lng->txt("enable_javascript"));
433  $this->ctrl->setParameter($this, "tst_javascript", "1");
434  $this->tpl->setVariable("JAVASCRIPT_URL", $this->ctrl->getLinkTarget($this, "gotoQuestion"));
435  }
436 
437  if ($question_gui->object->supportsJavascriptOutput())
438  {
439  $this->tpl->touchBlock("jsswitch");
440  }
441 
442  $this->tpl->addJavaScript(ilUtil::getJSLocation("autosave.js", "Modules/Test"));
443  $this->tpl->setVariable("AUTOSAVE_URL", $this->ctrl->getFormAction($this, "autosave", "", true));
444  }
445 
452  {
453  $template = new ilTemplate("tpl.il_as_tst_password_protection.html", TRUE, TRUE, "Modules/Test");
454  $template->setVariable("FORMACTION", $this->ctrl->getFormAction($this, "checkPassword"));
455  $template->setVariable("PASSWORD_INTRODUCTION", $this->lng->txt("tst_password_introduction"));
456  $template->setVariable("TEXT_PASSWORD", $this->lng->txt("tst_password"));
457  $template->setVariable("SUBMIT", $this->lng->txt("submit"));
458  $this->tpl->setVariable($this->getContentBlockName(), $template->get());
459  }
460 
466  function checkPassword()
467  {
468  if (strcmp($this->object->getPassword(), $_POST["password"]) == 0)
469  {
470  global $ilUser;
471  if ($_SESSION["AccountId"] != ANONYMOUS_USER_ID)
472  {
473  $ilUser->setPref("tst_password_".$this->object->getTestId(), $this->object->getPassword());
474  $ilUser->writePref("tst_password_".$this->object->getTestId(), $this->object->getPassword());
475  }
476  else
477  {
478  $_SESSION['tst_password_'.$this->object->getTestId()] = $this->object->getPassword();
479  }
480  $this->ctrl->redirect($this, "start");
481  }
482  else
483  {
484  ilUtil::sendFailure($this->lng->txt("tst_password_entered_wrong_password"), true);
485  $this->ctrl->redirectByClass("ilobjtestgui", "infoScreen");
486  }
487  }
488 
496  function setAnonymousId()
497  {
498  if ($_SESSION["AccountId"] == ANONYMOUS_USER_ID)
499  {
500  $this->object->setAccessCodeSession($_POST["anonymous_id"]);
501  }
502  $this->ctrl->redirectByClass("ilobjtestgui", "infoScreen");
503  }
504 
513  function start()
514  {
515  if (strcmp($_SESSION["lock"], $_POST["lock"]) != 0)
516  {
517  $_SESSION["lock"] = $_POST["lock"];
518  $this->handleStartCommands();
519  $this->ctrl->redirect($this, "startTest");
520  }
521  else
522  {
523  $this->ctrl->redirectByClass("ilobjtestgui", "redirectToInfoScreen");
524  }
525  }
526 
532  function startTest()
533  {
534  if ($this->object->checkMaximumAllowedUsers() == FALSE)
535  {
537  }
538  if ($_SESSION["AccountId"] == ANONYMOUS_USER_ID)
539  {
540  $this->object->setAccessCodeSession($this->object->createNewAccessCode());
541  }
542  else
543  {
544  $this->object->unsetAccessCodeSession();
545  }
546  if (strlen($this->object->getPassword()))
547  {
548  global $ilUser;
549  global $rbacsystem;
550 
551  $pwd = '';
552  if( $_SESSION["AccountId"] != ANONYMOUS_USER_ID )
553  {
554  $pwd = $ilUser->getPref("tst_password_".$this->object->getTestId());
555  }
556  elseif( isset($_SESSION['tst_password_'.$this->object->getTestId()]) )
557  {
558  $pwd = $_SESSION['tst_password_'.$this->object->getTestId()];
559  }
560 
561  if ((strcmp($pwd, $this->object->getPassword()) != 0) && (!$rbacsystem->checkAccess("write", $this->object->getRefId())))
562  {
563  return $this->showPasswordProtectionPage();
564  }
565  }
566  if ($_SESSION["AccountId"] == ANONYMOUS_USER_ID)
567  {
568  $this->ctrl->redirect($this, "displayCode");
569  }
570  else
571  {
572  $this->ctrl->setParameter($this, "activecommand", "start");
573  $this->ctrl->redirect($this, "redirectQuestion");
574  }
575  }
576 
577  function displayCode()
578  {
579  $this->tpl->addBlockFile($this->getContentBlockName(), "adm_content", "tpl.il_as_tst_anonymous_code_presentation.html", "Modules/Test");
580  $this->tpl->setCurrentBlock("adm_content");
581  $this->tpl->setVariable("TEXT_ANONYMOUS_CODE_CREATED", $this->lng->txt("tst_access_code_created"));
582  $this->tpl->setVariable("TEXT_ANONYMOUS_CODE", $this->object->getAccessCodeSession());
583  $this->tpl->setVariable("FORMACTION", $this->ctrl->getFormAction($this));
584  $this->tpl->setVariable("CONTINUE", $this->lng->txt("continue_work"));
585  $this->tpl->parseCurrentBlock();
586  }
587 
588  function codeConfirmed()
589  {
590  $this->ctrl->setParameter($this, "activecommand", "start");
591  $this->ctrl->redirect($this, "redirectQuestion");
592  }
593 
601  function resume()
602  {
603  if ($this->object->checkMaximumAllowedUsers() == FALSE)
604  {
606  }
607  $this->handleStartCommands();
608  $this->ctrl->setParameter($this, "activecommand", "resume");
609  $this->ctrl->redirect($this, "redirectQuestion");
610  }
611 
615  public function handleStartCommands()
616  {
617  global $ilUser;
618 
619  if ($_POST["chb_javascript"])
620  {
621  $ilUser->writePref("tst_javascript", 1);
622  }
623  else
624  {
625  $ilUser->writePref("tst_javascript", 0);
626  }
627 
628  // hide previous results
629  if ($this->object->getNrOfTries() != 1)
630  {
631  if ($this->object->getUsePreviousAnswers() == 1)
632  {
633  if ($_POST["chb_use_previous_answers"])
634  {
635  $ilUser->writePref("tst_use_previous_answers", 1);
636  }
637  else
638  {
639  $ilUser->writePref("tst_use_previous_answers", 0);
640  }
641  }
642  }
643 /* if ($this->object->getTestType() == TYPE_ONLINE_TEST)
644  {
645  global $ilias;
646  $ilias->auth->setIdle(0, false);
647  }*/
648  }
649 
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  $shuffle = $this->object->getShuffleQuestions();
787  if ($this->object->isRandomTest())
788  {
789  $shuffle = FALSE;
790  }
791  $this->object->createTestSequence($active_id, $this->object->getTestSession()->getPass(), $shuffle);
792 
793  $this->sequence = $this->object->getTestSession()->getLastSequence();
794  $active_time_id = $this->object->startWorkingTime($active_id, $this->object->getTestSession()->getPass());
795  $_SESSION["active_time_id"] = $active_time_id;
796  if ($this->object->getListOfQuestionsStart())
797  {
798  $this->ctrl->setParameter($this, "activecommand", "summary");
799  $this->ctrl->redirect($this, "redirectQuestion");
800  }
801  else
802  {
803  $this->ctrl->setParameter($this, "sequence", $this->sequence);
804  $this->ctrl->setParameter($this, "activecommand", "gotoquestion");
805  $this->ctrl->saveParameter($this, "tst_javascript");
806  $this->ctrl->redirect($this, "redirectQuestion");
807  }
808  break;
809  case "back":
810  case "gotoquestion":
811  default:
812  $_SESSION['tst_pass_finish'] = 0;
813  if (array_key_exists("tst_javascript", $_GET))
814  {
815  $ilUser->writePref("tst_javascript", $_GET["tst_javascript"]);
816  }
817  $this->sequence = $this->calculateSequence();
818  if (strlen($_GET['gotosequence'])) $this->sequence = $_GET['gotosequence'];
819  $this->object->getTestSession()->setLastSequence($this->sequence);
820  $this->object->getTestSession()->saveToDb();
821  $this->outTestPage();
822  break;
823  }
824  }
825 
831  function calculateSequence()
832  {
833  $sequence = $_GET["sequence"];
834  if (!$sequence) $sequence = $this->object->getTestSequence()->getFirstSequence();
835  if (array_key_exists("save_error", $_GET))
836  {
837  if ($_GET["save_error"] == 1)
838  {
839  return $sequence;
840  }
841  }
842  switch ($_GET["activecommand"])
843  {
844  case "next":
845  $sequence = $this->object->getTestSequence()->getNextSequence($sequence);
846  break;
847  case "previous":
848  $sequence = $this->object->getTestSequence()->getPreviousSequence($sequence);
849  break;
850  }
851  return $sequence;
852  }
853 
855  {
856  $this->tpl->addBlockFile($this->getContentBlockName(), "adm_content", "tpl.il_as_tst_redirect_autosave.html", "Modules/Test");
857  $this->tpl->setVariable("TEXT_REDIRECT", $this->lng->txt("redirectAfterSave"));
858  $this->tpl->setCurrentBlock("HeadContent");
859  $this->tpl->setVariable("CONTENT_BLOCK", "<meta http-equiv=\"refresh\" content=\"5; url=" . $this->ctrl->getLinkTarget($this, "redirectBack") . "\">");
860  $this->tpl->parseCurrentBlock();
861  }
862 
863  function autosave()
864  {
865  global $ilLog;
866  $result = "";
867  if (is_array($_POST) && count($_POST) > 0)
868  {
869  $res = $this->saveQuestionSolution(TRUE);
870  if ($res)
871  {
872  $result = $this->lng->txt("autosave_success");
873  }
874  else
875  {
876  $result = $this->lng->txt("autosave_failed");
877  }
878  }
879  if (!$this->canSaveResult())
880  {
881  // this was the last action in the test, saving is no longer allowed
882  $result = $this->ctrl->getLinkTarget($this, "redirectAfterAutosave", "", true);
883  }
884  echo $result;
885  exit;
886  }
887 
891  public function togglesidelist()
892  {
893  global $ilUser;
894 
895  $show_side_list = $ilUser->getPref('side_list_of_questions');
896  $ilUser->writePref('side_list_of_questions', !$show_side_list);
897  $this->saveQuestionSolution();
898  $this->ctrl->redirect($this, "redirectQuestion");
899  }
900 
908  function next()
909  {
910  $this->saveQuestionSolution();
911  $this->ctrl->setParameter($this, "activecommand", "next");
912  $this->ctrl->redirect($this, "redirectQuestion");
913  }
914 
922  function previous()
923  {
924  $this->saveQuestionSolution();
925  $this->ctrl->setParameter($this, "activecommand", "previous");
926  $this->ctrl->redirect($this, "redirectQuestion");
927  }
928 
936  function postpone()
937  {
938  $this->saveQuestionSolution();
939  $this->ctrl->setParameter($this, "activecommand", "postpone");
940  $this->ctrl->redirect($this, "redirectQuestion");
941  }
942 
950  function summary()
951  {
952  $this->saveQuestionSolution();
953  if ($this->saveResult == FALSE)
954  {
955  $this->ctrl->setParameter($this, "activecommand", "");
956  $this->ctrl->redirect($this, "redirectQuestion");
957  }
958  else
959  {
960  $this->ctrl->setParameter($this, "activecommand", "summary");
961  $this->ctrl->redirect($this, "redirectQuestion");
962  }
963  }
964 
972  function setmarked()
973  {
974  $this->saveQuestionSolution();
975  $this->ctrl->setParameter($this, "activecommand", "setmarked");
976  $this->ctrl->redirect($this, "redirectQuestion");
977  }
978 
986  function resetmarked()
987  {
988  $this->saveQuestionSolution();
989  $this->ctrl->setParameter($this, "activecommand", "resetmarked");
990  $this->ctrl->redirect($this, "redirectQuestion");
991  }
992 
1000  function directfeedback()
1001  {
1002  $this->saveQuestionSolution();
1003  $this->ctrl->setParameter($this, "activecommand", "directfeedback");
1004  $this->ctrl->redirect($this, "redirectQuestion");
1005  }
1006 
1015  {
1016  $this->saveQuestionSolution();
1017  $activecommand = "selectImagemapRegion";
1018  if (array_key_exists('cmd', $_POST))
1019  {
1020  $activecommand = key($_POST["cmd"]);
1021  }
1022  if (preg_match("/^gotoquestion_(\\d+)$/", $activecommand, $matches))
1023  {
1024  $activecommand = "gotoquestion";
1025  if (strlen($matches[1]))
1026  {
1027  $this->ctrl->setParameter($this, 'gotosequence', $matches[1]);
1028  }
1029  }
1030  if (strcmp($activecommand, "togglesidelist") == 0)
1031  {
1032  $this->togglesidelist();
1033  }
1034  else
1035  {
1036  $this->ctrl->setParameter($this, "activecommand", $activecommand);
1037  $this->ctrl->redirect($this, "redirectQuestion");
1038  }
1039  }
1040 
1048  function gotoQuestion()
1049  {
1050  if (is_array($_POST) && count($_POST) > 0) $this->saveQuestionSolution();
1051  $this->ctrl->setParameter($this, "sequence", $_GET["sequence"]);
1052  $this->ctrl->setParameter($this, "activecommand", "gotoquestion");
1053  $this->ctrl->saveParameter($this, "tst_javascript");
1054  if (strlen($_GET['qst_selection'])) $_SESSION['qst_selection'] = $_GET['qst_selection'];
1055  $this->ctrl->redirect($this, "redirectQuestion");
1056  }
1057 
1065  function backFromSummary()
1066  {
1067  $this->ctrl->setParameter($this, "activecommand", "back");
1068  $this->ctrl->redirect($this, "redirectQuestion");
1069  }
1070 
1078  function confirmFinish()
1079  {
1080  $this->finishTest(false);
1081  }
1082 
1091  {
1092  global $ilUser;
1093 
1094  $template = new ilTemplate("tpl.il_as_tst_finish_confirmation.html", TRUE, TRUE, "Modules/Test");
1095  $template->setVariable("FINISH_QUESTION", $this->lng->txt("tst_finish_confirmation_question"));
1096  $template->setVariable("BUTTON_CONFIRM", $this->lng->txt("tst_finish_confirm_button"));
1097  if ($this->object->canShowSolutionPrintview($ilUser->getId()))
1098  {
1099  $template->setVariable("BUTTON_CANCEL", $this->lng->txt("tst_finish_confirm_list_of_answers_button"));
1100  }
1101  else
1102  {
1103  $template->setVariable("BUTTON_CANCEL", $this->lng->txt("tst_finish_confirm_cancel_button"));
1104  }
1105  $template->setVariable("FORMACTION", $this->ctrl->getFormAction($this));
1106  $this->tpl->setVariable($this->getContentBlockName(), $template->get());
1107  }
1108 
1116  function finishTest($confirm = true)
1117  {
1118  global $ilUser;
1119  global $ilias;
1120  global $ilAuth;
1121 
1122  unset($_SESSION["tst_next"]);
1123 
1124  $active_id = $this->object->getTestSession()->getActiveId();
1125  $actualpass = $this->object->_getPass($active_id);
1126  if (($actualpass == $this->object->getNrOfTries() - 1) && (!$confirm))
1127  {
1128  $this->object->setActiveTestSubmitted($ilUser->getId());
1129  $ilAuth->setIdle($ilias->ini->readVariable("session","expire"), false);
1130  $ilAuth->setExpire(0);
1131  switch ($this->object->getMailNotification())
1132  {
1133  case 1:
1134  $this->object->sendSimpleNotification($active_id);
1135  break;
1136  case 2:
1137  $this->object->sendAdvancedNotification($active_id);
1138  break;
1139  }
1140  }
1141 
1142  if (($confirm) && ($actualpass == $this->object->getNrOfTries() - 1))
1143  {
1144  if ($this->object->canShowSolutionPrintview($ilUser->getId()))
1145  {
1146  $template = new ilTemplate("tpl.il_as_tst_finish_navigation.html", TRUE, TRUE, "Modules/Test");
1147  $template->setVariable("BUTTON_FINISH", $this->lng->txt("btn_next"));
1148  $template->setVariable("BUTTON_CANCEL", $this->lng->txt("btn_previous"));
1149 
1150  $template_top = new ilTemplate("tpl.il_as_tst_list_of_answers_topbuttons.html", TRUE, TRUE, "Modules/Test");
1151  $template_top->setCurrentBlock("button_print");
1152  $template_top->setVariable("BUTTON_PRINT", $this->lng->txt("print"));
1153  $template_top->parseCurrentBlock();
1154 
1155  $this->showListOfAnswers($active_id, NULL, $template_top->get(), $template->get());
1156  return;
1157  }
1158  else
1159  {
1160  // show confirmation page
1161  return $this->confirmFinishTest();
1162  }
1163  }
1164 
1165  if (!$_SESSION['tst_pass_finish'])
1166  {
1167  if (!$_SESSION['tst_pass_finish']) $_SESSION['tst_pass_finish'] = 1;
1168  if ($this->object->getMailNotificationType() == 1)
1169  {
1170  switch ($this->object->getMailNotification())
1171  {
1172  case 1:
1173  $this->object->sendSimpleNotification($active_id);
1174  break;
1175  case 2:
1176  $this->object->sendAdvancedNotification($active_id);
1177  break;
1178  }
1179  }
1180  $this->object->getTestSession()->increaseTestPass();
1181  }
1182  $this->redirectBack();
1183  }
1184 
1185  public function redirectBack()
1186  {
1187  if (!$_GET["skipfinalstatement"])
1188  {
1189  if ($this->object->getShowFinalStatement())
1190  {
1191  $this->ctrl->redirect($this, "showFinalStatement");
1192  }
1193  }
1194  if($_GET['crs_show_result'])
1195  {
1196  $this->ctrl->redirectByClass("ilobjtestgui", "backToCourse");
1197  }
1198 
1199  if (!$this->object->canViewResults())
1200  {
1201  $this->outIntroductionPage();
1202  }
1203  else
1204  {
1205  $this->ctrl->redirectByClass("ilTestEvaluationGUI", "outUserResultsOverview");
1206  }
1207  }
1208 
1209  /*
1210  * Presents the final statement of a test
1211  */
1212  public function showFinalStatement()
1213  {
1214  $template = new ilTemplate("tpl.il_as_tst_final_statement.html", TRUE, TRUE, "Modules/Test");
1215  $this->ctrl->setParameter($this, "crs_show_result", $_GET['crs_show_result']);
1216  $this->ctrl->setParameter($this, "skipfinalstatement", 1);
1217  $template->setVariable("FORMACTION", $this->ctrl->getFormAction($this, "redirectBack"));
1218  $template->setVariable("FINALSTATEMENT", $this->object->getFinalStatement());
1219  $template->setVariable("BUTTON_CONTINUE", $this->lng->txt("btn_next"));
1220  $this->tpl->setVariable($this->getContentBlockName(), $template->get());
1221  }
1222 
1223  private function getKioskHead()
1224  {
1225  global $ilUser;
1226 
1227  $template = new ilTemplate('tpl.il_as_tst_kiosk_head.html', true, true, 'Modules/Test');
1228  if ($this->object->getShowKioskModeTitle())
1229  {
1230  $template->setCurrentBlock("kiosk_show_title");
1231  $template->setVariable("TEST_TITLE", $this->object->getTitle());
1232  $template->parseCurrentBlock();
1233  }
1234  if ($this->object->getShowKioskModeParticipant())
1235  {
1236  $template->setCurrentBlock("kiosk_show_participant");
1237  $template->setVariable("PARTICIPANT_NAME", $this->lng->txt("login_as") . " " . $ilUser->getFullname());
1238  $template->parseCurrentBlock();
1239  }
1240  return $template->get();
1241  }
1242 
1246  function outTestPage()
1247  {
1248  global $rbacsystem, $ilUser;
1249 
1250  $this->tpl->addBlockFile($this->getContentBlockName(), "adm_content", "tpl.il_as_tst_output.html", "Modules/Test");
1251  if (!$rbacsystem->checkAccess("read", $this->object->getRefId()))
1252  {
1253  // only with read access it is possible to run the test
1254  $this->ilias->raiseError($this->lng->txt("cannot_execute_test"),$this->ilias->error_obj->MESSAGE);
1255  }
1256 
1257  if ($this->isMaxProcessingTimeReached())
1258  {
1259  $this->maxProcessingTimeReached();
1260  return;
1261  }
1262 
1263  if ($this->object->endingTimeReached())
1264  {
1265  $this->endingTimeReached();
1266  return;
1267  }
1268 
1269  if ($this->object->getKioskMode())
1270  {
1271  ilUtil::sendInfo();
1272  $head = $this->getKioskHead();
1273  if (strlen($head))
1274  {
1275  $this->tpl->setCurrentBlock("kiosk_options");
1276  $this->tpl->setVariable("KIOSK_HEAD", $head);
1277  $this->tpl->parseCurrentBlock();
1278  }
1279  }
1280 
1281  if (($this->object->getInstantFeedbackSolution() == 1) || ($this->object->getAnswerFeedback() == 1) || ($this->object->getAnswerFeedbackPoints() == 1))
1282  {
1283  $this->tpl->setCurrentBlock("direct_feedback");
1284  $this->tpl->setVariable("TEXT_DIRECT_FEEDBACK", $this->lng->txt("check"));
1285  $this->tpl->parseCurrentBlock();
1286  }
1287 
1288  $postpone = false;
1289  if ($this->object->getSequenceSettings() == TEST_POSTPONE)
1290  {
1291  $postpone = true;
1292  }
1293 
1294  if ($this->object->getEnableProcessingTime())
1295  {
1296  $this->outProcessingTime($this->object->getTestSession()->getActiveId());
1297  }
1298 
1299  $this->tpl->setVariable("FORM_TIMESTAMP", time());
1300  $directfeedback = 0;
1301  if (strcmp($_GET["activecommand"], "directfeedback") == 0) $directfeedback = 1;
1302  $this->outWorkingForm($this->sequence, $this->object->getTestId(), $postpone, $directfeedback, $show_summary);
1303  $this->tpl->setVariable("PAGETITLE", "- " . $this->object->getTitle());
1304  }
1305 
1314  {
1315  global $ilUser;
1316 
1317  // check if user is invited to participate
1318  $user = $this->object->getInvitedUsers($ilUser->getId());
1319  if (!is_array ($user) || count($user)!=1)
1320  {
1321  ilUtil::sendInfo($this->lng->txt("user_not_invited"), true);
1322  $this->ctrl->redirectByClass("ilobjtestgui", "backToRepository");
1323  }
1324 
1325  $user = array_pop($user);
1326  // check if client ip is set and if current remote addr is equal to stored client-ip
1327  if (strcmp($user["clientip"],"")!=0 && strcmp($user["clientip"],$_SERVER["REMOTE_ADDR"])!=0)
1328  {
1329  ilUtil::sendInfo($this->lng->txt("user_wrong_clientip"), true);
1330  $this->ctrl->redirectByClass("ilobjtestgui", "backToRepository");
1331  }
1332  }
1333 
1334 
1338  function isTestAccessible()
1339  {
1340  return !$this->isNrOfTriesReached()
1341  and !$this->isMaxProcessingTimeReached()
1342  and $this->object->startingTimeReached()
1343  and !$this->object->endingTimeReached();
1344  }
1345 
1350  {
1351  return $this->object->hasNrOfTriesRestriction() && $this->object->isNrOfTriesReached($this->object->getTestSession()->getPass());
1352  }
1353 
1361  function passDetails()
1362  {
1363  if (array_key_exists("pass", $_GET) && (strlen($_GET["pass"]) > 0))
1364  {
1365  $this->ctrl->saveParameter($this, "pass");
1366  $this->ctrl->saveParameter($this, "active_id");
1367  $this->outTestResults(false, $_GET["pass"]);
1368  }
1369  else
1370  {
1371  $this->outTestResults(false);
1372  }
1373  }
1374 
1380  function endingTimeReached()
1381  {
1382  ilUtil::sendInfo(sprintf($this->lng->txt("detail_ending_time_reached"), ilFormat::ftimestamp2datetimeDB($this->object->getEndingTime())));
1383  $this->object->getTestSession()->increasePass();
1384  $this->object->getTestSession()->setLastSequence(0);
1385  $this->object->getTestSession()->saveToDb();
1386  if (!$this->object->canViewResults())
1387  {
1388  $this->outIntroductionPage();
1389  }
1390  else
1391  {
1392  $this->ctrl->redirectByClass("ilTestEvaluationGUI", "outUserResultsOverview");
1393  }
1394  }
1395 
1404  {
1405  $this->outIntroductionPage();
1406  }
1407 
1414  {
1415  $this->tpl->addBlockFile($this->getContentBlockName(), "adm_content", "tpl.il_as_tst_submit_answers_confirm.html", "Modules/Test");
1416  $this->tpl->setCurrentBlock("adm_content");
1417  if ($this->object->isTestFinished($this->object->getTestSession()->getActiveId()))
1418  {
1419  $this->tpl->setCurrentBlock("not_submit_allowed");
1420  $this->tpl->setVariable("TEXT_ALREADY_SUBMITTED", $this->lng->txt("tst_already_submitted"));
1421  $this->tpl->setVariable("BTN_OK", $this->lng->txt("tst_show_answer_sheet"));
1422  } else
1423  {
1424  $this->tpl->setCurrentBlock("submit_allowed");
1425  $this->tpl->setVariable("TEXT_CONFIRM_SUBMIT_RESULTS", $this->lng->txt("tst_confirm_submit_answers"));
1426  $this->tpl->setVariable("BTN_OK", $this->lng->txt("tst_submit_results"));
1427  }
1428  $this->tpl->setVariable("BTN_BACK", $this->lng->txt("back"));
1429  $this->tpl->setVariable("FORMACTION", $this->ctrl->getFormAction($this, "finalSubmission"));
1430  $this->tpl->parseCurrentBlock();
1431  }
1432 
1433  function outProcessingTime($active_id)
1434  {
1435  global $ilUser;
1436 
1437  $starting_time = $this->object->getStartingTimeOfUser($active_id);
1438  $processing_time = $this->object->getProcessingTimeInSeconds();
1439  $processing_time_minutes = floor($processing_time / 60);
1440  $processing_time_seconds = $processing_time - $processing_time_minutes * 60;
1441  $str_processing_time = "";
1442  if ($processing_time_minutes > 0)
1443  {
1444  $str_processing_time = $processing_time_minutes . " " . $this->lng->txt("minutes");
1445  }
1446  if ($processing_time_seconds > 0)
1447  {
1448  if (strlen($str_processing_time) > 0) $str_processing_time .= " " . $this->lng->txt("and") . " ";
1449  $str_processing_time .= $processing_time_seconds . " " . $this->lng->txt("seconds");
1450  }
1451  $time_left = $starting_time + $processing_time - mktime();
1452  $time_left_minutes = floor($time_left / 60);
1453  $time_left_seconds = $time_left - $time_left_minutes * 60;
1454  $str_time_left = "";
1455  if ($time_left_minutes > 0)
1456  {
1457  $str_time_left = $time_left_minutes . " " . $this->lng->txt("minutes");
1458  }
1459  if ($time_left < 300)
1460  {
1461  if ($time_left_seconds > 0)
1462  {
1463  if (strlen($str_time_left) > 0) $str_time_left .= " " . $this->lng->txt("and") . " ";
1464  $str_time_left .= $time_left_seconds . " " . $this->lng->txt("seconds");
1465  }
1466  }
1467  $date = getdate($starting_time);
1468  $formattedStartingTime = ilDatePresentation::formatDate(new ilDateTime($date,IL_CAL_FKT_GETDATE));
1469  /*
1470  $formattedStartingTime = ilFormat::formatDate(
1471  $date["year"]."-".
1472  sprintf("%02d", $date["mon"])."-".
1473  sprintf("%02d", $date["mday"])." ".
1474  sprintf("%02d", $date["hours"]).":".
1475  sprintf("%02d", $date["minutes"]).":".
1476  sprintf("%02d", $date["seconds"])
1477  );
1478  */
1479  $datenow = getdate();
1480  $this->tpl->setCurrentBlock("enableprocessingtime");
1481  $this->tpl->setVariable("USER_WORKING_TIME",
1482  sprintf(
1483  $this->lng->txt("tst_time_already_spent"),
1484  $formattedStartingTime,
1485  $str_processing_time
1486  )
1487  );
1488  $this->tpl->setVariable("USER_REMAINING_TIME", sprintf($this->lng->txt("tst_time_already_spent_left"), $str_time_left));
1489  $this->tpl->parseCurrentBlock();
1490  $template = new ilTemplate("tpl.workingtime.js.html", TRUE, TRUE, TRUE);
1491  $template->setVariable("STRING_MINUTE", $this->lng->txt("minute"));
1492  $template->setVariable("STRING_MINUTES", $this->lng->txt("minutes"));
1493  $template->setVariable("STRING_SECOND", $this->lng->txt("second"));
1494  $template->setVariable("STRING_SECONDS", $this->lng->txt("seconds"));
1495  $template->setVariable("STRING_TIMELEFT", $this->lng->txt("tst_time_already_spent_left"));
1496  $template->setVariable("AND", strtolower($this->lng->txt("and")));
1497  $template->setVariable("YEAR", $date["year"]);
1498  $template->setVariable("MONTH", $date["mon"]-1);
1499  $template->setVariable("DAY", $date["mday"]);
1500  $template->setVariable("HOUR", $date["hours"]);
1501  $template->setVariable("MINUTE", $date["minutes"]);
1502  $template->setVariable("SECOND", $date["seconds"]);
1503  if (preg_match("/(\d{4})(\d{2})(\d{2})(\d{2})(\d{2})(\d{2})/", $this->object->getEndingTime(), $matches))
1504  {
1505  $template->setVariable("ENDYEAR", $matches[1]);
1506  $template->setVariable("ENDMONTH", $matches[2]-1);
1507  $template->setVariable("ENDDAY", $matches[3]);
1508  $template->setVariable("ENDHOUR", $matches[4]);
1509  $template->setVariable("ENDMINUTE", $matches[5]);
1510  $template->setVariable("ENDSECOND", $matches[6]);
1511  }
1512  $template->setVariable("YEARNOW", $datenow["year"]);
1513  $template->setVariable("MONTHNOW", $datenow["mon"]-1);
1514  $template->setVariable("DAYNOW", $datenow["mday"]);
1515  $template->setVariable("HOURNOW", $datenow["hours"]);
1516  $template->setVariable("MINUTENOW", $datenow["minutes"]);
1517  $template->setVariable("SECONDNOW", $datenow["seconds"]);
1518  $template->setVariable("PTIME_M", $processing_time_minutes);
1519  $template->setVariable("PTIME_S", $processing_time_seconds);
1520 
1521  $this->tpl->setCurrentBlock("HeadContent");
1522  $this->tpl->setVariable("CONTENT_BLOCK", $template->get());
1523  $this->tpl->parseCurrentBlock();
1524  }
1525 
1529  public function outQuestionSummary($fullpage = true)
1530  {
1531  if ($fullpage) $this->tpl->addBlockFile($this->getContentBlockName(), "adm_content", "tpl.il_as_tst_question_summary.html", "Modules/Test");
1532  $active_id = $this->object->getTestSession()->getActiveId();
1533  $result_array = & $this->object->getTestSequence()->getSequenceSummary();
1534  $marked_questions = array();
1535  if ($this->object->getKioskMode() && $fullpage)
1536  {
1537  $head = $this->getKioskHead();
1538  if (strlen($head))
1539  {
1540  $this->tpl->setCurrentBlock("kiosk_options");
1541  $this->tpl->setVariable("KIOSK_HEAD", $head);
1542  $this->tpl->parseCurrentBlock();
1543  }
1544  }
1545  if ($this->object->getShowMarker())
1546  {
1547  include_once "./Modules/Test/classes/class.ilObjTest.php";
1548  $marked_questions = ilObjTest::_getSolvedQuestions($active_id);
1549  }
1550  $data = array();
1551  foreach ($result_array as $key => $value)
1552  {
1553  $this->ctrl->setParameter($this, "sequence", $value["sequence"]);
1554  $href = $this->ctrl->getLinkTargetByClass(get_class($this), "gotoQuestion");
1555  $this->tpl->setVariable("VALUE_QUESTION_TITLE", "<a href=\"".$this->ctrl->getLinkTargetByClass(get_class($this), "gotoQuestion")."\">" . $this->object->getQuestionTitle($value["title"]) . "</a>");
1556  $this->ctrl->setParameter($this, "sequence", $_GET["sequence"]);
1557  $description = "";
1558  if ($this->object->getListOfQuestionsDescription())
1559  {
1560  $description = $value["description"];
1561  }
1562  $points = "";
1563  if (!$this->object->getTitleOutput())
1564  {
1565  $points = $value["points"]."&nbsp;".$this->lng->txt("points_short");
1566  }
1567  $marked = false;
1568  if (count($marked_questions))
1569  {
1570  if (array_key_exists($value["qid"], $marked_questions))
1571  {
1572  $obj = $marked_questions[$value["qid"]];
1573  if ($obj["solved"] == 1)
1574  {
1575  $marked = true;
1576  }
1577  }
1578  }
1579  array_push($data, array(
1580  'order' => $value["nr"],
1581  'href' => $href,
1582  'title' => $this->object->getQuestionTitle($value["title"]),
1583  'description' => $description,
1584  'worked_through' => ($value["worked_through"]) ? true : false,
1585  'postponed' => ($value["postponed"]) ? $this->lng->txt("postponed") : '',
1586  'points' => $points,
1587  'marked' => $marked,
1588  'sequence' => $value["sequence"]
1589  ));
1590  }
1591  $this->ctrl->setParameter($this, "sequence", $_GET["sequence"]);
1592  if ($fullpage)
1593  {
1594  include_once "./Modules/Test/classes/tables/class.ilListOfQuestionsTableGUI.php";
1595  $table_gui = new ilListOfQuestionsTableGUI($this, 'backFromSummary', !$this->object->getTitleOutput(), $this->object->getShowMarker());
1596  $table_gui->setData($data);
1597  $this->tpl->setVariable('TABLE_LIST_OF_QUESTIONS', $table_gui->getHTML());
1598  if ($this->object->getEnableProcessingTime()) $this->outProcessingTime($active_id);
1599  }
1600  else
1601  {
1602  $template = new ilTemplate('tpl.il_as_tst_list_of_questions_short.html', true, true, 'Modules/Test');
1603  foreach ($data as $row)
1604  {
1605  if (strlen($row['description']))
1606  {
1607  $template->setCurrentBlock('description');
1608  $template->setVariable("DESCRIPTION", $row['description']);
1609  $template->parseCurrentBlock();
1610  }
1611  $template->setCurrentBlock('item');
1612  $active = ($row['sequence'] == $this->sequence) ? ' active' : '';
1613  $template->setVariable('CLASS', ($row['walked_through']) ? ('answered'.$active) : ('unanswered'.$active));
1614  $template->setVariable('ITEM', ilUtil::prepareFormOutput($row['title']));
1615  $template->setVariable('SEQUENCE', $row['sequence']);
1616  $template->parseCurrentBlock();
1617  }
1618  $template->setVariable('LIST_OF_QUESTIONS', $this->lng->txt('list_of_questions'));
1619  $this->tpl->setVariable('LIST_OF_QUESTIONS', $template->get());
1620  }
1621  }
1622 
1624  {
1625  $this->tpl->addBlockFile($this->getContentBlockName(), "adm_content", "tpl.il_as_tst_max_allowed_users_reached.html", "Modules/Test");
1626  $this->tpl->setCurrentBlock("adm_content");
1627  $this->tpl->setVariable("MAX_ALLOWED_USERS_MESSAGE", sprintf($this->lng->txt("tst_max_allowed_users_message"), $this->object->getAllowedUsersTimeGap()));
1628  $this->tpl->setVariable("MAX_ALLOWED_USERS_HEADING", sprintf($this->lng->txt("tst_max_allowed_users_heading"), $this->object->getAllowedUsersTimeGap()));
1629  $this->tpl->setVariable("BACK_TO_INTRODUCTION", $this->lng->txt("tst_results_back_introduction"));
1630  $this->tpl->setVariable("FORMACTION", $this->ctrl->getFormAction($this));
1631  $this->tpl->parseCurrentBlock();
1632  }
1633 
1635  {
1636  global $ilUser;
1637  if ($this->object->canShowSolutionPrintview($ilUser->getId()))
1638  {
1639  $template = new ilTemplate("tpl.il_as_tst_finish_navigation.html", TRUE, TRUE, "Modules/Test");
1640  $template->setVariable("BUTTON_FINISH", $this->lng->txt("btn_next"));
1641  $template->setVariable("BUTTON_CANCEL", $this->lng->txt("btn_previous"));
1642 
1643  $template_top = new ilTemplate("tpl.il_as_tst_list_of_answers_topbuttons.html", TRUE, TRUE, "Modules/Test");
1644  $template_top->setCurrentBlock("button_print");
1645  $template_top->setVariable("BUTTON_PRINT", $this->lng->txt("print"));
1646  $template_top->parseCurrentBlock();
1647  $active_id = $this->object->getTestSession()->getActiveId();
1648  return $this->showListOfAnswers($active_id, NULL, $template_top->get(), $template->get());
1649  }
1650  else
1651  {
1652  $this->ctrl->redirect($this, 'gotoQuestion');
1653  }
1654  }
1655 
1657  {
1658  $this->confirmFinishTest();
1659  }
1660 
1667  {
1668  $this->tpl->addBlockFile("ADM_CONTENT", "adm_content", "tpl.il_as_tst_correct_solution.html", "Modules/Test");
1669 
1670  include_once("./Services/Style/classes/class.ilObjStyleSheet.php");
1671  $this->tpl->setCurrentBlock("ContentStyle");
1672  $this->tpl->setVariable("LOCATION_CONTENT_STYLESHEET", ilObjStyleSheet::getContentStylePath(0));
1673  $this->tpl->parseCurrentBlock();
1674 
1675  $this->tpl->setCurrentBlock("SyntaxStyle");
1676  $this->tpl->setVariable("LOCATION_SYNTAX_STYLESHEET", ilObjStyleSheet::getSyntaxStylePath());
1677  $this->tpl->parseCurrentBlock();
1678 
1679  $this->tpl->addCss(ilUtil::getStyleSheetLocation("output", "test_print.css", "Modules/Test"), "print");
1680  if ($this->object->getShowSolutionAnswersOnly())
1681  {
1682  $this->tpl->addCss(ilUtil::getStyleSheetLocation("output", "test_print_hide_content.css", "Modules/Test"), "print");
1683  }
1684 
1685  $this->tpl->setCurrentBlock("adm_content");
1686  $solution = $this->getCorrectSolutionOutput($_GET["evaluation"], $_GET["active_id"], $_GET["pass"]);
1687  $this->tpl->setVariable("OUTPUT_SOLUTION", $solution);
1688  $this->tpl->setVariable("TEXT_BACK", $this->lng->txt("back"));
1689  $this->ctrl->saveParameter($this, "pass");
1690  $this->ctrl->saveParameter($this, "active_id");
1691  $this->tpl->setVariable("URL_BACK", $this->ctrl->getLinkTarget($this, "outUserResultsOverview"));
1692  $this->tpl->parseCurrentBlock();
1693  }
1694 
1704  function showListOfAnswers($active_id, $pass = NULL, $top_data = "", $bottom_data = "")
1705  {
1706  global $ilUser;
1707 
1708  $this->tpl->addBlockFile($this->getContentBlockName(), "adm_content", "tpl.il_as_tst_finish_list_of_answers.html", "Modules/Test");
1709 
1710  $result_array =& $this->object->getTestResult($active_id, $pass);
1711 
1712  $counter = 1;
1713  // output of questions with solutions
1714  foreach ($result_array as $question_data)
1715  {
1716  $question = $question_data["qid"];
1717  if (is_numeric($question))
1718  {
1719  $this->tpl->setCurrentBlock("printview_question");
1720  $question_gui = $this->object->createQuestionGUI("", $question);
1721  $template = new ilTemplate("tpl.il_as_qpl_question_printview.html", TRUE, TRUE, "Modules/TestQuestionPool");
1722  $template->setVariable("COUNTER_QUESTION", $counter.". ");
1723  $template->setVariable("QUESTION_TITLE", $question_gui->object->getTitle());
1724 
1725  $show_question_only = ($this->object->getShowSolutionAnswersOnly()) ? TRUE : FALSE;
1726  $result_output = $question_gui->getSolutionOutput($active_id, $pass, FALSE, FALSE, $show_question_only, $this->object->getShowSolutionFeedback());
1727  $template->setVariable("SOLUTION_OUTPUT", $result_output);
1728  $this->tpl->setVariable("QUESTION_OUTPUT", $template->get());
1729  $this->tpl->parseCurrentBlock();
1730  $counter ++;
1731  }
1732  }
1733 
1734  $this->tpl->addCss(ilUtil::getStyleSheetLocation("output", "test_print.css", "Modules/Test"), "print");
1735  if ($this->object->getShowSolutionAnswersOnly())
1736  {
1737  $this->tpl->addCss(ilUtil::getStyleSheetLocation("output", "test_print_hide_content.css", "Modules/Test"), "print");
1738  }
1739  if (strlen($top_data))
1740  {
1741  $this->tpl->setCurrentBlock("top_data");
1742  $this->tpl->setVariable("TOP_DATA", $top_data);
1743  $this->tpl->parseCurrentBlock();
1744  }
1745 
1746  if (strlen($bottom_data))
1747  {
1748  $this->tpl->setCurrentBlock("bottom_data");
1749  $this->tpl->setVariable("FORMACTION", $this->ctrl->getFormAction($this));
1750  $this->tpl->setVariable("BOTTOM_DATA", $bottom_data);
1751  $this->tpl->parseCurrentBlock();
1752  }
1753 
1754  $this->tpl->setCurrentBlock("adm_content");
1755  $this->tpl->setVariable("TXT_ANSWER_SHEET", $this->lng->txt("tst_list_of_answers"));
1756  $user_data = $this->getResultsUserdata($active_id, TRUE);
1757  $signature = $this->getResultsSignature();
1758  $this->tpl->setVariable("USER_DETAILS", $user_data);
1759  $this->tpl->setVariable("SIGNATURE", $signature);
1760  $this->tpl->setVariable("TITLE", $this->object->getTitle());
1761  $this->tpl->setVariable("TXT_TEST_PROLOG", $this->lng->txt("tst_your_answers"));
1762  $invited_user =& $this->object->getInvitedUsers($ilUser->getId());
1763  $pagetitle = $this->object->getTitle() . " - " . $this->lng->txt("clientip") .
1764  ": " . $invited_user[$ilUser->getId()]["clientip"] . " - " .
1765  $this->lng->txt("matriculation") . ": " .
1766  $invited_user[$ilUser->getId()]["matriculation"];
1767  $this->tpl->setVariable("PAGETITLE", $pagetitle);
1768  $this->tpl->parseCurrentBlock();
1769  }
1770 
1777  private function getContentBlockName()
1778  {
1779  if ($this->object->getKioskMode())
1780  {
1781  $this->tpl->setBodyClass("kiosk");
1782  $this->tpl->setAddFooter(FALSE);
1783  return "CONTENT";
1784  }
1785  else
1786  {
1787  return "ADM_CONTENT";
1788  }
1789  }
1790 
1792  {
1793  $this->ctrl->redirectByClass("iltestevaluationgui", "outUserResultsOverview");
1794  }
1795 
1797  {
1798  $this->ctrl->redirectByClass("iltestevaluationgui", "outUserListOfAnswerPasses");
1799  }
1800 
1801 }
1802 ?>