ILIAS  Release_4_0_x_branch Revision 61816
 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  if (preg_match("/^gotoquestion_(\\d+)$/", $cmd, $matches))
89  {
90  $cmd = "gotoquestion";
91  if (strlen($matches[1]))
92  {
93  $this->ctrl->setParameter($this, 'gotosequence', $matches[1]);
94  }
95 
96  }
97  if ($_GET["active_id"])
98  {
99  $this->object->setTestSession($_GET["active_id"]);
100  }
101  else
102  {
103  $this->object->setTestSession();
104  }
105  include_once "./Services/YUI/classes/class.ilYuiUtil.php";
107  $cmd = $this->getCommand($cmd);
108  switch($next_class)
109  {
110  default:
111  $ret =& $this->$cmd();
112  break;
113  }
114  return $ret;
115  }
116 
121  function updateWorkingTime()
122  {
123  if ($_SESSION["active_time_id"])
124  {
125  $this->object->updateWorkingTime($_SESSION["active_time_id"]);
126  }
127  }
128 
132  function saveQuestionSolution($force = FALSE)
133  {
134  $this->updateWorkingTime();
135  $this->saveResult = FALSE;
136  if (!$force)
137  {
138  $formtimestamp = $_POST["formtimestamp"];
139  if (strlen($formtimestamp) == 0) $formtimestamp = $_GET["formtimestamp"];
140  if ($formtimestamp != $_SESSION["formtimestamp"])
141  {
142  $_SESSION["formtimestamp"] = $formtimestamp;
143  }
144  else
145  {
146  return FALSE;
147  }
148  }
149  // save question solution
150  if ($this->canSaveResult() || $force)
151  {
152  // but only if the ending time is not reached
153  $q_id = $this->object->getTestSequence()->getQuestionForSequence($_GET["sequence"]);
154  if (is_numeric($q_id))
155  {
156  global $ilUser;
157 
158  $question_gui = $this->object->createQuestionGUI("", $q_id);
159  if ($this->object->getJavaScriptOutput())
160  {
161  $question_gui->object->setOutputType(OUTPUT_JAVASCRIPT);
162  }
163  $pass = NULL;
164  $active_id = $this->object->getTestSession()->getActiveId();
165  if ($this->object->isRandomTest())
166  {
167  $pass = $this->object->_getPass($active_id);
168  }
169  $this->saveResult = $question_gui->object->saveWorkingData($active_id, $pass);
170  }
171  }
172  if ($this->saveResult == FALSE)
173  {
174  $this->ctrl->setParameter($this, "save_error", "1");
175  $_SESSION["previouspost"] = $_POST;
176  }
177  return $this->saveResult;
178  }
179 
188  function canSaveResult()
189  {
190  return !$this->object->endingTimeReached() && !$this->isMaxProcessingTimeReached() && !$this->isNrOfTriesReached();
191  }
192 
201  {
202  $this->ctrl->redirectByClass("ilobjtestgui", "infoScreen");
203  }
204 
214  {
215  global $ilUser;
216  $active_id = $this->object->getTestSession()->getActiveId();
217  $starting_time = $this->object->getStartingTimeOfUser($active_id);
218  if ($starting_time === FALSE)
219  {
220  return FALSE;
221  }
222  else
223  {
224  return $this->object->isMaxProcessingTimeReached($starting_time);
225  }
226  }
227 
231  public function outWorkingForm($sequence = "", $test_id, $postpone_allowed, $directfeedback = 0)
232  {
233  global $ilUser;
234 
235  if ($sequence < 1) $sequence = $this->object->getTestSequence()->getFirstSequence();
236  $active_time_id = $this->object->startWorkingTime($this->object->getTestSession()->getActiveId(), $this->object->getTestSession()->getPass());
237  $_SESSION["active_time_id"] = $active_time_id;
238 
239  include_once("./Services/Style/classes/class.ilObjStyleSheet.php");
240  $this->tpl->setCurrentBlock("ContentStyle");
241  $this->tpl->setVariable("LOCATION_CONTENT_STYLESHEET",
243  $this->tpl->parseCurrentBlock();
244 
245  // syntax style
246  $this->tpl->setCurrentBlock("SyntaxStyle");
247  $this->tpl->setVariable("LOCATION_SYNTAX_STYLESHEET",
249  $this->tpl->parseCurrentBlock();
250 
251  if ($this->object->getListOfQuestions())
252  {
253  $show_side_list = $ilUser->getPref('side_list_of_questions');
254  $this->tpl->setCurrentBlock('view_sidelist');
255  $this->tpl->setVariable('IMAGE_SIDELIST', ($show_side_list) ? ilUtil::getImagePath('view_remove.png') : ilUtil::getImagePath('view_choose.png'));
256  $this->tpl->setVariable('TEXT_SIDELIST', ($show_side_list) ? $this->lng->txt('tst_hide_side_list') : $this->lng->txt('tst_show_side_list'));
257  $this->tpl->parseCurrentBlock();
258  if ($show_side_list)
259  {
260  $this->tpl->addCss(ilUtil::getStyleSheetLocation("output", "ta_split.css", "Modules/Test"), "screen");
261  $this->outQuestionSummary(false);
262  }
263  }
264 
265  $question_gui = $this->object->createQuestionGUI("", $this->object->getTestSequence()->getQuestionForSequence($sequence));
266  if ($this->object->getJavaScriptOutput())
267  {
268  $question_gui->object->setOutputType(OUTPUT_JAVASCRIPT);
269  }
270 
271  $is_postponed = $this->object->getTestSequence()->isPostponedQuestion($question_gui->object->getId());
272  $this->ctrl->setParameter($this, "sequence", "$sequence");
273  $formaction = $this->ctrl->getFormAction($this, "gotoQuestion");
274 
275  $question_gui->setSequenceNumber($this->object->getTestSequence()->getPositionOfSequence($sequence));
276  $question_gui->setQuestionCount($this->object->getTestSequence()->getUserQuestionCount());
277  // output question
278  $user_post_solution = FALSE;
279  if (array_key_exists("previouspost", $_SESSION))
280  {
281  $user_post_solution = $_SESSION["previouspost"];
282  unset($_SESSION["previouspost"]);
283  }
284  $answer_feedback = FALSE;
285  if (($directfeedback) && ($this->object->getAnswerFeedback()))
286  {
287  $answer_feedback = TRUE;
288  }
289  global $ilNavigationHistory;
290  $ilNavigationHistory->addItem($_GET["ref_id"], $this->ctrl->getLinkTarget($this, "resume"), "tst");
291  $question_gui->outQuestionForTest($formaction, $this->object->getTestSession()->getActiveId(), NULL, $is_postponed, $user_post_solution, $answer_feedback);
292  if ($directfeedback)
293  {
294  if ($this->object->getInstantFeedbackSolution())
295  {
296  $solutionoutput = $question_gui->getSolutionOutput($this->object->getTestSession()->getActiveId(), NULL, FALSE, FALSE, FALSE, FALSE, TRUE);
297  $this->tpl->setCurrentBlock("solution_output");
298  $this->tpl->setVariable("CORRECT_SOLUTION", $this->lng->txt("tst_best_solution_is"));
299  $this->tpl->setVariable("QUESTION_FEEDBACK", $solutionoutput);
300  $this->tpl->parseCurrentBlock();
301  }
302  if ($this->object->getAnswerFeedbackPoints())
303  {
304  $this->tpl->setCurrentBlock("solution_output");
305  $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()));
306  $this->tpl->parseCurrentBlock();
307  }
308  if ($this->object->getAnswerFeedback())
309  {
310  $this->tpl->setCurrentBlock("answer_feedback");
311  $this->tpl->setVariable("ANSWER_FEEDBACK", $question_gui->getAnswerFeedbackOutput($this->object->getTestSession()->getActiveId(), NULL));
312  $this->tpl->parseCurrentBlock();
313  }
314  }
315 
316  if ($sequence == $this->object->getTestSequence()->getFirstSequence())
317  {
318  $this->tpl->setCurrentBlock("prev");
319  $this->tpl->setVariable("BTN_PREV", "&lt;&lt; " . $this->lng->txt("save_introduction"));
320  $this->tpl->parseCurrentBlock();
321  $this->tpl->setCurrentBlock("prev_bottom");
322  $this->tpl->setVariable("BTN_PREV", "&lt;&lt; " . $this->lng->txt("save_introduction"));
323  $this->tpl->parseCurrentBlock();
324  }
325  else
326  {
327  $this->tpl->setCurrentBlock("prev");
328  $this->tpl->setVariable("BTN_PREV", "&lt;&lt; " . $this->lng->txt("save_previous"));
329  $this->tpl->parseCurrentBlock();
330  $this->tpl->setCurrentBlock("prev_bottom");
331  $this->tpl->setVariable("BTN_PREV", "&lt;&lt; " . $this->lng->txt("save_previous"));
332  $this->tpl->parseCurrentBlock();
333  }
334 
335  if ($postpone_allowed)
336  {
337  if (!$is_postponed)
338  {
339  if (!$finish)
340  {
341  $this->tpl->setCurrentBlock("postpone");
342  $this->tpl->setVariable("BTN_POSTPONE", $this->lng->txt("postpone"));
343  $this->tpl->parseCurrentBlock();
344  $this->tpl->setCurrentBlock("postpone_bottom");
345  $this->tpl->setVariable("BTN_POSTPONE", $this->lng->txt("postpone"));
346  $this->tpl->parseCurrentBlock();
347  }
348  }
349  }
350 
351  if ($this->object->getListOfQuestions())
352  {
353  if (!(($finish) && ($this->object->getListOfQuestionsEnd())))
354  {
355  $this->tpl->setCurrentBlock("summary");
356  $this->tpl->setVariable("BTN_SUMMARY", $this->lng->txt("question_summary"));
357  $this->tpl->parseCurrentBlock();
358  $this->tpl->setCurrentBlock("summary_bottom");
359  $this->tpl->setVariable("BTN_SUMMARY", $this->lng->txt("question_summary"));
360  $this->tpl->parseCurrentBlock();
361  }
362  }
363 
364  if ($this->object->getShowCancel())
365  {
366  $this->tpl->setCurrentBlock("cancel_test");
367  $this->tpl->setVariable("TEXT_CANCELTEST", $this->lng->txt("cancel_test"));
368  $this->tpl->setVariable("TEXT_ALTCANCELTEXT", $this->lng->txt("cancel_test"));
369  $this->tpl->setVariable("TEXT_TITLECANCELTEXT", $this->lng->txt("cancel_test"));
370  $this->tpl->setVariable("HREF_IMGCANCELTEST", $this->ctrl->getLinkTargetByClass(get_class($this), "outIntroductionPage") . "&cancelTest=true");
371  $this->tpl->setVariable("HREF_CANCELTEXT", $this->ctrl->getLinkTargetByClass(get_class($this), "outIntroductionPage") . "&cancelTest=true");
372  $this->tpl->setVariable("IMAGE_CANCEL", ilUtil::getImagePath("cancel.gif"));
373  $this->tpl->parseCurrentBlock();
374  }
375 
376  if ($this->object->getTestSequence()->getQuestionForSequence($this->object->getTestSequence()->getLastSequence()) == $question_gui->object->getId())
377  {
378  if ($this->object->getListOfQuestionsEnd())
379  {
380  $this->tpl->setCurrentBlock("next");
381  $this->tpl->setVariable("BTN_NEXT", $this->lng->txt("question_summary") . " &gt;&gt;");
382  $this->tpl->parseCurrentBlock();
383  $this->tpl->setCurrentBlock("next_bottom");
384  $this->tpl->setVariable("BTN_NEXT", $this->lng->txt("question_summary") . " &gt;&gt;");
385  $this->tpl->parseCurrentBlock();
386  }
387  else
388  {
389  $this->tpl->setCurrentBlock("next");
390  $this->tpl->setVariable("BTN_NEXT", $this->lng->txt("save_finish") . " &gt;&gt;");
391  $this->tpl->parseCurrentBlock();
392  $this->tpl->setCurrentBlock("next_bottom");
393  $this->tpl->setVariable("BTN_NEXT", $this->lng->txt("save_finish") . " &gt;&gt;");
394  $this->tpl->parseCurrentBlock();
395  }
396  }
397  else
398  {
399  $this->tpl->setCurrentBlock("next");
400  $this->tpl->setVariable("BTN_NEXT", $this->lng->txt("save_next") . " &gt;&gt;");
401  $this->tpl->parseCurrentBlock();
402  $this->tpl->setCurrentBlock("next_bottom");
403  $this->tpl->setVariable("BTN_NEXT", $this->lng->txt("save_next") . " &gt;&gt;");
404  $this->tpl->parseCurrentBlock();
405  }
406 
407  if ($this->object->getShowMarker())
408  {
409  include_once "./Modules/Test/classes/class.ilObjTest.php";
410  $solved_array = ilObjTest::_getSolvedQuestions($this->object->getTestSession()->getActiveId(), $question_gui->object->getId());
411  $solved = 0;
412 
413  if (count ($solved_array) > 0)
414  {
415  $solved = array_pop($solved_array);
416  $solved = $solved["solved"];
417  }
418 
419  if ($solved==1)
420  {
421  $this->tpl->setCurrentBlock("ismarked");
422  $this->tpl->setVariable("IMAGE_SET", ilUtil::getImagePath("marked.png"));
423  $this->tpl->setVariable("TEXT_SET", $this->lng->txt("tst_remove_mark"));
424  $this->tpl->parseCurrentBlock();
425  }
426  else
427  {
428  $this->tpl->setCurrentBlock("isnotmarked");
429  $this->tpl->setVariable("IMAGE_UNSET", ilUtil::getImagePath("marked_.png"));
430  $this->tpl->setVariable("TEXT_UNSET", $this->lng->txt("tst_question_mark"));
431  $this->tpl->parseCurrentBlock();
432  }
433  }
434 
435  if ($this->object->getJavaScriptOutput())
436  {
437  $this->tpl->setVariable("JAVASCRIPT_IMAGE", ilUtil::getImagePath("javascript_disable.png"));
438  $this->tpl->setVariable("JAVASCRIPT_IMAGE_ALT", $this->lng->txt("disable_javascript"));
439  $this->tpl->setVariable("JAVASCRIPT_IMAGE_TITLE", $this->lng->txt("disable_javascript"));
440  $this->ctrl->setParameter($this, "tst_javascript", "0");
441  $this->tpl->setVariable("JAVASCRIPT_URL", $this->ctrl->getLinkTarget($this, "gotoQuestion"));
442  }
443  else
444  {
445  $this->tpl->setVariable("JAVASCRIPT_IMAGE", ilUtil::getImagePath("javascript.png"));
446  $this->tpl->setVariable("JAVASCRIPT_IMAGE_ALT", $this->lng->txt("enable_javascript"));
447  $this->tpl->setVariable("JAVASCRIPT_IMAGE_TITLE", $this->lng->txt("enable_javascript"));
448  $this->ctrl->setParameter($this, "tst_javascript", "1");
449  $this->tpl->setVariable("JAVASCRIPT_URL", $this->ctrl->getLinkTarget($this, "gotoQuestion"));
450  }
451 
452  if ($question_gui->object->supportsJavascriptOutput())
453  {
454  $this->tpl->touchBlock("jsswitch");
455  }
456 
457  $this->tpl->addJavaScript(ilUtil::getJSLocation("autosave.js", "Modules/Test"));
458  $this->tpl->setVariable("AUTOSAVE_URL", $this->ctrl->getLinkTarget($this, "autosave"));
459  }
460 
467  {
468  $template = new ilTemplate("tpl.il_as_tst_password_protection.html", TRUE, TRUE, "Modules/Test");
469  $template->setVariable("FORMACTION", $this->ctrl->getFormAction($this, "checkPassword"));
470  $template->setVariable("PASSWORD_INTRODUCTION", $this->lng->txt("tst_password_introduction"));
471  $template->setVariable("TEXT_PASSWORD", $this->lng->txt("tst_password"));
472  $template->setVariable("SUBMIT", $this->lng->txt("submit"));
473  $this->tpl->setVariable($this->getContentBlockName(), $template->get());
474  }
475 
481  function checkPassword()
482  {
483  if (strcmp($this->object->getPassword(), $_POST["password"]) == 0)
484  {
485  global $ilUser;
486  if ($_SESSION["AccountId"] != ANONYMOUS_USER_ID)
487  {
488  $ilUser->setPref("tst_password_".$this->object->getTestId(), $this->object->getPassword());
489  $ilUser->writePref("tst_password_".$this->object->getTestId(), $this->object->getPassword());
490  }
491  $this->ctrl->redirect($this, "start");
492  }
493  else
494  {
495  ilUtil::sendFailure($this->lng->txt("tst_password_entered_wrong_password"), true);
496  $this->ctrl->redirectByClass("ilobjtestgui", "infoScreen");
497  }
498  }
499 
507  function setAnonymousId()
508  {
509  if ($_SESSION["AccountId"] == ANONYMOUS_USER_ID)
510  {
511  $this->object->setAccessCodeSession($_POST["anonymous_id"]);
512  }
513  $this->ctrl->redirectByClass("ilobjtestgui", "infoScreen");
514  }
515 
524  function start()
525  {
526  if (strcmp($_SESSION["lock"], $_POST["lock"]) != 0)
527  {
528  $_SESSION["lock"] = $_POST["lock"];
529  $this->handleStartCommands();
530  $this->ctrl->redirect($this, "startTest");
531  }
532  else
533  {
534  $this->ctrl->redirectByClass("ilobjtestgui", "redirectToInfoScreen");
535  }
536  }
537 
543  function startTest()
544  {
545  if ($this->object->checkMaximumAllowedUsers() == FALSE)
546  {
548  }
549  if ($_SESSION["AccountId"] == ANONYMOUS_USER_ID)
550  {
551  $this->object->setAccessCodeSession($this->object->createNewAccessCode());
552  }
553  else
554  {
555  $this->object->unsetAccessCodeSession();
556  }
557  if (strlen($this->object->getPassword()))
558  {
559  global $ilUser;
560  global $rbacsystem;
561 
562  $pwd = $ilUser->getPref("tst_password_".$this->object->getTestId());
563  if ((strcmp($pwd, $this->object->getPassword()) != 0) && (!$rbacsystem->checkAccess("write", $this->object->getRefId())))
564  {
565  return $this->showPasswordProtectionPage();
566  }
567  }
568  if ($_SESSION["AccountId"] == ANONYMOUS_USER_ID)
569  {
570  $this->ctrl->redirect($this, "displayCode");
571  }
572  else
573  {
574  $this->ctrl->setParameter($this, "activecommand", "start");
575  $this->ctrl->redirect($this, "redirectQuestion");
576  }
577  }
578 
579  function displayCode()
580  {
581  $this->tpl->addBlockFile($this->getContentBlockName(), "adm_content", "tpl.il_as_tst_anonymous_code_presentation.html", "Modules/Test");
582  $this->tpl->setCurrentBlock("adm_content");
583  $this->tpl->setVariable("TEXT_ANONYMOUS_CODE_CREATED", $this->lng->txt("tst_access_code_created"));
584  $this->tpl->setVariable("TEXT_ANONYMOUS_CODE", $this->object->getAccessCodeSession());
585  $this->tpl->setVariable("FORMACTION", $this->ctrl->getFormAction($this));
586  $this->tpl->setVariable("CONTINUE", $this->lng->txt("continue_work"));
587  $this->tpl->parseCurrentBlock();
588  }
589 
590  function codeConfirmed()
591  {
592  $this->ctrl->setParameter($this, "activecommand", "start");
593  $this->ctrl->redirect($this, "redirectQuestion");
594  }
595 
603  function resume()
604  {
605  if ($this->object->checkMaximumAllowedUsers() == FALSE)
606  {
608  }
609  $this->handleStartCommands();
610  $this->ctrl->setParameter($this, "activecommand", "resume");
611  $this->ctrl->redirect($this, "redirectQuestion");
612  }
613 
617  public function handleStartCommands()
618  {
619  global $ilUser;
620 
621  if ($_POST["chb_javascript"])
622  {
623  $ilUser->writePref("tst_javascript", 1);
624  }
625  else
626  {
627  $ilUser->writePref("tst_javascript", 0);
628  }
629 
630  // hide previous results
631  if ($this->object->getNrOfTries() != 1)
632  {
633  if ($this->object->getUsePreviousAnswers() == 1)
634  {
635  if ($_POST["chb_use_previous_answers"])
636  {
637  $ilUser->writePref("tst_use_previous_answers", 1);
638  }
639  else
640  {
641  $ilUser->writePref("tst_use_previous_answers", 0);
642  }
643  }
644  }
645 /* if ($this->object->getTestType() == TYPE_ONLINE_TEST)
646  {
647  global $ilias;
648  $ilias->auth->setIdle(0, false);
649  }*/
650  }
651 
660  function redirectQuestion()
661  {
662  global $ilUser;
663 
664  // check the test restrictions to access the test in case one
665  // of the test navigation commands was called by an external script
666  // e.g. $ilNavigationHistory
667  $executable = $this->object->isExecutable($ilUser->getId());
668  if (!$executable["executable"])
669  {
670  ilUtil::sendInfo($executable["errormessage"], TRUE);
671  $this->ctrl->redirectByClass("ilobjtestgui", "infoScreen");
672  }
673  switch ($_GET["activecommand"])
674  {
675  case "next":
676  $this->sequence = $this->calculateSequence();
677  if ($this->sequence === FALSE)
678  {
679  if ($this->object->getListOfQuestionsEnd())
680  {
681  $this->outQuestionSummary();
682  }
683  else
684  {
685  $this->ctrl->redirect($this, "finishTest");
686  }
687  }
688  else
689  {
690  $this->object->getTestSession()->setLastSequence($this->sequence);
691  $this->object->getTestSession()->saveToDb();
692  $this->outTestPage();
693  }
694  break;
695  case "previous":
696  $this->sequence = $this->calculateSequence();
697  $this->object->getTestSession()->setLastSequence($this->sequence);
698  $this->object->getTestSession()->saveToDb();
699  if ($this->sequence === FALSE)
700  {
701  $this->ctrl->redirect($this, "outIntroductionPage");
702  }
703  else
704  {
705  $this->outTestPage();
706  }
707  break;
708  case "postpone":
709  $this->sequence = $this->calculateSequence();
710  $nextSequence = $this->object->getTestSequence()->getNextSequence($this->sequence);
711  $this->object->getTestSequence()->postponeSequence($this->sequence);
712  $this->object->getTestSequence()->saveToDb();
713  $this->object->getTestSession()->setLastSequence($nextSequence);
714  $this->object->getTestSession()->saveToDb();
715  $this->sequence = $nextSequence;
716  $this->outTestPage();
717  break;
718  case "setmarked":
719  $this->sequence = $this->calculateSequence();
720  $this->object->getTestSession()->setLastSequence($this->sequence);
721  $this->object->getTestSession()->saveToDb();
722  $q_id = $this->object->getTestSequence()->getQuestionForSequence($_GET["sequence"]);
723  $this->object->setQuestionSetSolved(1, $q_id, $ilUser->getId());
724  $this->outTestPage();
725  break;
726  case "resetmarked":
727  $this->sequence = $this->calculateSequence();
728  $this->object->getTestSession()->setLastSequence($this->sequence);
729  $this->object->getTestSession()->saveToDb();
730  $q_id = $this->object->getTestSequence()->getQuestionForSequence($_GET["sequence"]);
731  $this->object->setQuestionSetSolved(0, $q_id, $ilUser->getId());
732  $this->outTestPage();
733  break;
734  case "directfeedback":
735  $this->sequence = $this->calculateSequence();
736  $this->object->getTestSession()->setLastSequence($this->sequence);
737  $this->object->getTestSession()->saveToDb();
738  $this->outTestPage();
739  break;
740  case "selectImagemapRegion":
741  $this->sequence = $this->calculateSequence();
742  $this->object->getTestSession()->setLastSequence($this->sequence);
743  $this->object->getTestSession()->saveToDb();
744  $this->outTestPage();
745  break;
746  case "summary":
747  $this->ctrl->redirect($this, "outQuestionSummary");
748  break;
749  case "start":
750  $_SESSION['tst_pass_finish'] = 0;
751  $this->object->createTestSession();
752  $active_id = $this->object->getTestSession()->getActiveId();
753  $this->ctrl->setParameter($this, "active_id", $active_id);
754  $shuffle = $this->object->getShuffleQuestions();
755  if ($this->object->isRandomTest())
756  {
757  $this->object->generateRandomQuestions($this->object->getTestSession()->getActiveId());
758  $this->object->loadQuestions();
759  $shuffle = FALSE; // shuffle is already done during the creation of the random questions
760  }
761  $this->object->createTestSequence($active_id, 0, $shuffle);
762  $active_time_id = $this->object->startWorkingTime($this->object->getTestSession()->getActiveId(), $this->object->getTestSession()->getPass());
763  $_SESSION["active_time_id"] = $active_time_id;
764  if ($this->object->getListOfQuestionsStart())
765  {
766  $this->ctrl->setParameter($this, "activecommand", "summary");
767  $this->ctrl->redirect($this, "redirectQuestion");
768  }
769  else
770  {
771  $this->ctrl->setParameter($this, "sequence", $this->sequence);
772  $this->ctrl->setParameter($this, "activecommand", "gotoquestion");
773  $this->ctrl->saveParameter($this, "tst_javascript");
774  $this->ctrl->redirect($this, "redirectQuestion");
775  }
776  break;
777  case "resume":
778  $_SESSION['tst_pass_finish'] = 0;
779  $active_id = $this->object->getTestSession()->getActiveId();
780  $this->ctrl->setParameter($this, "active_id", $active_id);
781 
782  if ($this->object->isRandomTest())
783  {
784  if (!$this->object->hasRandomQuestionsForPass($active_id, $this->object->getTestSession()->getPass()))
785  {
786  // create a new set of random questions
787  $this->object->generateRandomQuestions($active_id, $this->object->getTestSession()->getPass());
788  }
789  }
790  $shuffle = $this->object->getShuffleQuestions();
791  if ($this->object->isRandomTest())
792  {
793  $shuffle = FALSE;
794  }
795  $this->object->createTestSequence($active_id, $this->object->getTestSession()->getPass(), $shuffle);
796 
797  $this->sequence = $this->object->getTestSession()->getLastSequence();
798  $active_time_id = $this->object->startWorkingTime($active_id, $this->object->getTestSession()->getPass());
799  $_SESSION["active_time_id"] = $active_time_id;
800  if ($this->object->getListOfQuestionsStart())
801  {
802  $this->ctrl->setParameter($this, "activecommand", "summary");
803  $this->ctrl->redirect($this, "redirectQuestion");
804  }
805  else
806  {
807  $this->ctrl->setParameter($this, "sequence", $this->sequence);
808  $this->ctrl->setParameter($this, "activecommand", "gotoquestion");
809  $this->ctrl->saveParameter($this, "tst_javascript");
810  $this->ctrl->redirect($this, "redirectQuestion");
811  }
812  break;
813  case "back":
814  case "gotoquestion":
815  default:
816  $_SESSION['tst_pass_finish'] = 0;
817  if (array_key_exists("tst_javascript", $_GET))
818  {
819  $ilUser->writePref("tst_javascript", $_GET["tst_javascript"]);
820  }
821  $this->sequence = $this->calculateSequence();
822  if (strlen($_GET['gotosequence'])) $this->sequence = $_GET['gotosequence'];
823  $this->object->getTestSession()->setLastSequence($this->sequence);
824  $this->object->getTestSession()->saveToDb();
825  $this->outTestPage();
826  break;
827  }
828  }
829 
837  function calculateSequence()
838  {
839  $sequence = $_GET["sequence"];
840  if (!$sequence) $sequence = $this->object->getTestSequence()->getFirstSequence();
841  if (array_key_exists("save_error", $_GET))
842  {
843  if ($_GET["save_error"] == 1)
844  {
845  return $sequence;
846  }
847  }
848  switch ($_GET["activecommand"])
849  {
850  case "next":
851  $sequence = $this->object->getTestSequence()->getNextSequence($sequence);
852  break;
853  case "previous":
854  $sequence = $this->object->getTestSequence()->getPreviousSequence($sequence);
855  break;
856  }
857  return $sequence;
858  }
859 
861  {
862  $this->tpl->addBlockFile($this->getContentBlockName(), "adm_content", "tpl.il_as_tst_redirect_autosave.html", "Modules/Test");
863  $this->tpl->setVariable("TEXT_REDIRECT", $this->lng->txt("redirectAfterSave"));
864  $this->tpl->setCurrentBlock("HeadContent");
865  $this->tpl->setVariable("CONTENT_BLOCK", "<meta http-equiv=\"refresh\" content=\"5; url=" . $this->ctrl->getLinkTarget($this, "redirectBack") . "\">");
866  $this->tpl->parseCurrentBlock();
867  }
868 
869  function autosave()
870  {
871  global $ilLog;
872  $result = "";
873  if (is_array($_POST) && count($_POST) > 0)
874  {
875  $res = $this->saveQuestionSolution(TRUE);
876  if ($res)
877  {
878  $result = $this->lng->txt("autosave_success");
879  }
880  else
881  {
882  $result = $this->lng->txt("autosave_failed");
883  }
884  }
885  if (!$this->canSaveResult())
886  {
887  // this was the last action in the test, saving is no longer allowed
888  $result = $this->ctrl->getLinkTarget($this, "redirectAfterAutosave");
889  }
890  echo $result;
891  exit;
892  }
893 
897  public function togglesidelist()
898  {
899  global $ilUser;
900 
901  $show_side_list = $ilUser->getPref('side_list_of_questions');
902  $ilUser->writePref('side_list_of_questions', !$show_side_list);
903  $this->saveQuestionSolution();
904  $this->ctrl->redirect($this, "redirectQuestion");
905  }
906 
914  function next()
915  {
916  $this->saveQuestionSolution();
917  $this->ctrl->setParameter($this, "activecommand", "next");
918  $this->ctrl->redirect($this, "redirectQuestion");
919  }
920 
928  function previous()
929  {
930  $this->saveQuestionSolution();
931  $this->ctrl->setParameter($this, "activecommand", "previous");
932  $this->ctrl->redirect($this, "redirectQuestion");
933  }
934 
942  function postpone()
943  {
944  $this->saveQuestionSolution();
945  $this->ctrl->setParameter($this, "activecommand", "postpone");
946  $this->ctrl->redirect($this, "redirectQuestion");
947  }
948 
956  function summary()
957  {
958  $this->saveQuestionSolution();
959  if ($this->saveResult == FALSE)
960  {
961  $this->ctrl->setParameter($this, "activecommand", "");
962  $this->ctrl->redirect($this, "redirectQuestion");
963  }
964  else
965  {
966  $this->ctrl->setParameter($this, "activecommand", "summary");
967  $this->ctrl->redirect($this, "redirectQuestion");
968  }
969  }
970 
978  function setmarked()
979  {
980  $this->saveQuestionSolution();
981  $this->ctrl->setParameter($this, "activecommand", "setmarked");
982  $this->ctrl->redirect($this, "redirectQuestion");
983  }
984 
992  function resetmarked()
993  {
994  $this->saveQuestionSolution();
995  $this->ctrl->setParameter($this, "activecommand", "resetmarked");
996  $this->ctrl->redirect($this, "redirectQuestion");
997  }
998 
1006  function directfeedback()
1007  {
1008  $this->saveQuestionSolution();
1009  $this->ctrl->setParameter($this, "activecommand", "directfeedback");
1010  $this->ctrl->redirect($this, "redirectQuestion");
1011  }
1012 
1021  {
1022  $this->saveQuestionSolution();
1023  $activecommand = "selectImagemapRegion";
1024  if (array_key_exists("cmd", $_POST))
1025  {
1026  $activecommand = key($_POST["cmd"]);
1027  }
1028  $this->ctrl->setParameter($this, "activecommand", $activecommand);
1029  $this->ctrl->redirect($this, "redirectQuestion");
1030  }
1031 
1039  function gotoQuestion()
1040  {
1041  if (is_array($_POST) && count($_POST) > 0) $this->saveQuestionSolution();
1042  $this->ctrl->setParameter($this, "sequence", $_GET["sequence"]);
1043  $this->ctrl->setParameter($this, "activecommand", "gotoquestion");
1044  $this->ctrl->saveParameter($this, "tst_javascript");
1045  if (strlen($_GET['qst_selection'])) $_SESSION['qst_selection'] = $_GET['qst_selection'];
1046  $this->ctrl->redirect($this, "redirectQuestion");
1047  }
1048 
1056  function backFromSummary()
1057  {
1058  $this->ctrl->setParameter($this, "activecommand", "back");
1059  $this->ctrl->redirect($this, "redirectQuestion");
1060  }
1061 
1069  function confirmFinish()
1070  {
1071  $this->finishTest(false);
1072  }
1073 
1082  {
1083  global $ilUser;
1084 
1085  $template = new ilTemplate("tpl.il_as_tst_finish_confirmation.html", TRUE, TRUE, "Modules/Test");
1086  $template->setVariable("FINISH_QUESTION", $this->lng->txt("tst_finish_confirmation_question"));
1087  $template->setVariable("BUTTON_CONFIRM", $this->lng->txt("tst_finish_confirm_button"));
1088  if ($this->object->canShowSolutionPrintview($ilUser->getId()))
1089  {
1090  $template->setVariable("BUTTON_CANCEL", $this->lng->txt("tst_finish_confirm_list_of_answers_button"));
1091  }
1092  else
1093  {
1094  $template->setVariable("BUTTON_CANCEL", $this->lng->txt("tst_finish_confirm_cancel_button"));
1095  }
1096  $template->setVariable("FORMACTION", $this->ctrl->getFormAction($this));
1097  $this->tpl->setVariable($this->getContentBlockName(), $template->get());
1098  }
1099 
1107  function finishTest($confirm = true)
1108  {
1109  global $ilUser;
1110  global $ilias;
1111  global $ilAuth;
1112 
1113  unset($_SESSION["tst_next"]);
1114 
1115  $active_id = $this->object->getTestSession()->getActiveId();
1116  $actualpass = $this->object->_getPass($active_id);
1117  if (($actualpass == $this->object->getNrOfTries() - 1) && (!$confirm))
1118  {
1119  $this->object->setActiveTestSubmitted($ilUser->getId());
1120  $ilAuth->setIdle($ilias->ini->readVariable("session","expire"), false);
1121  $ilAuth->setExpire(0);
1122  switch ($this->object->getMailNotification())
1123  {
1124  case 1:
1125  $this->object->sendSimpleNotification($active_id);
1126  break;
1127  case 2:
1128  $this->object->sendAdvancedNotification($active_id);
1129  break;
1130  }
1131  }
1132 
1133  if (($confirm) && ($actualpass == $this->object->getNrOfTries() - 1))
1134  {
1135  if ($this->object->canShowSolutionPrintview($ilUser->getId()))
1136  {
1137  $template = new ilTemplate("tpl.il_as_tst_finish_navigation.html", TRUE, TRUE, "Modules/Test");
1138  $template->setVariable("BUTTON_FINISH", $this->lng->txt("btn_next"));
1139  $template->setVariable("BUTTON_CANCEL", $this->lng->txt("btn_previous"));
1140 
1141  $template_top = new ilTemplate("tpl.il_as_tst_list_of_answers_topbuttons.html", TRUE, TRUE, "Modules/Test");
1142  $template_top->setCurrentBlock("button_print");
1143  $template_top->setVariable("BUTTON_PRINT", $this->lng->txt("print"));
1144  $template_top->parseCurrentBlock();
1145 
1146  $this->showListOfAnswers($active_id, NULL, $template_top->get(), $template->get());
1147  return;
1148  }
1149  else
1150  {
1151  // show confirmation page
1152  return $this->confirmFinishTest();
1153  }
1154  }
1155 
1156  if (!$_SESSION['tst_pass_finish'])
1157  {
1158  if (!$_SESSION['tst_pass_finish']) $_SESSION['tst_pass_finish'] = 1;
1159  $this->object->getTestSession()->increaseTestPass();
1160  }
1161  $this->redirectBack();
1162  }
1163 
1164  public function redirectBack()
1165  {
1166  if (!$_GET["skipfinalstatement"])
1167  {
1168  if ($this->object->getShowFinalStatement())
1169  {
1170  $this->ctrl->redirect($this, "showFinalStatement");
1171  }
1172  }
1173  if($_GET['crs_show_result'])
1174  {
1175  $this->ctrl->redirectByClass("ilobjtestgui", "backToCourse");
1176  }
1177 
1178  if (!$this->object->canViewResults())
1179  {
1180  $this->outIntroductionPage();
1181  }
1182  else
1183  {
1184  $this->ctrl->redirectByClass("ilTestEvaluationGUI", "outUserResultsOverview");
1185  }
1186  }
1187 
1188  /*
1189  * Presents the final statement of a test
1190  */
1191  public function showFinalStatement()
1192  {
1193  $template = new ilTemplate("tpl.il_as_tst_final_statement.html", TRUE, TRUE, "Modules/Test");
1194  $this->ctrl->setParameter($this, "crs_show_result", $_GET['crs_show_result']);
1195  $this->ctrl->setParameter($this, "skipfinalstatement", 1);
1196  $template->setVariable("FORMACTION", $this->ctrl->getFormAction($this, "redirectBack"));
1197  $template->setVariable("FINALSTATEMENT", $this->object->getFinalStatement());
1198  $template->setVariable("BUTTON_CONTINUE", $this->lng->txt("btn_next"));
1199  $this->tpl->setVariable($this->getContentBlockName(), $template->get());
1200  }
1201 
1202  private function getKioskHead()
1203  {
1204  global $ilUser;
1205 
1206  $template = new ilTemplate('tpl.il_as_tst_kiosk_head.html', true, true, 'Modules/Test');
1207  if ($this->object->getShowKioskModeTitle())
1208  {
1209  $template->setCurrentBlock("kiosk_show_title");
1210  $template->setVariable("TEST_TITLE", $this->object->getTitle());
1211  $template->parseCurrentBlock();
1212  }
1213  if ($this->object->getShowKioskModeParticipant())
1214  {
1215  $template->setCurrentBlock("kiosk_show_participant");
1216  $template->setVariable("PARTICIPANT_NAME", $this->lng->txt("login_as") . " " . $ilUser->getFullname());
1217  $template->parseCurrentBlock();
1218  }
1219  return $template->get();
1220  }
1221 
1225  function outTestPage()
1226  {
1227  global $rbacsystem, $ilUser;
1228 
1229  $this->tpl->addBlockFile($this->getContentBlockName(), "adm_content", "tpl.il_as_tst_output.html", "Modules/Test");
1230  if (!$rbacsystem->checkAccess("read", $this->object->getRefId()))
1231  {
1232  // only with read access it is possible to run the test
1233  $this->ilias->raiseError($this->lng->txt("cannot_execute_test"),$this->ilias->error_obj->MESSAGE);
1234  }
1235 
1236  if ($this->isMaxProcessingTimeReached())
1237  {
1238  $this->maxProcessingTimeReached();
1239  return;
1240  }
1241 
1242  if ($this->object->endingTimeReached())
1243  {
1244  $this->endingTimeReached();
1245  return;
1246  }
1247 
1248  if ($this->object->getKioskMode())
1249  {
1250  ilUtil::sendInfo();
1251  $head = $this->getKioskHead();
1252  if (strlen($head))
1253  {
1254  $this->tpl->setCurrentBlock("kiosk_options");
1255  $this->tpl->setVariable("KIOSK_HEAD", $head);
1256  $this->tpl->parseCurrentBlock();
1257  }
1258  }
1259 
1260  if (($this->object->getInstantFeedbackSolution() == 1) || ($this->object->getAnswerFeedback() == 1) || ($this->object->getAnswerFeedbackPoints() == 1))
1261  {
1262  $this->tpl->setCurrentBlock("direct_feedback");
1263  $this->tpl->setVariable("TEXT_DIRECT_FEEDBACK", $this->lng->txt("check"));
1264  $this->tpl->parseCurrentBlock();
1265  }
1266 
1267  $postpone = false;
1268  if ($this->object->getSequenceSettings() == TEST_POSTPONE)
1269  {
1270  $postpone = true;
1271  }
1272 
1273  if ($this->object->getEnableProcessingTime())
1274  {
1275  $this->outProcessingTime($this->object->getTestSession()->getActiveId());
1276  }
1277 
1278  $this->tpl->setVariable("FORM_TIMESTAMP", time());
1279  $directfeedback = 0;
1280  if (strcmp($_GET["activecommand"], "directfeedback") == 0) $directfeedback = 1;
1281  $this->outWorkingForm($this->sequence, $this->object->getTestId(), $postpone, $directfeedback, $show_summary);
1282  $this->tpl->setVariable("PAGETITLE", "- " . $this->object->getTitle());
1283  }
1284 
1293  {
1294  global $ilUser;
1295 
1296  // check if user is invited to participate
1297  $user = $this->object->getInvitedUsers($ilUser->getId());
1298  if (!is_array ($user) || count($user)!=1)
1299  {
1300  ilUtil::sendInfo($this->lng->txt("user_not_invited"), true);
1301  $this->ctrl->redirectByClass("ilobjtestgui", "backToRepository");
1302  }
1303 
1304  $user = array_pop($user);
1305  // check if client ip is set and if current remote addr is equal to stored client-ip
1306  if (strcmp($user["clientip"],"")!=0 && strcmp($user["clientip"],$_SERVER["REMOTE_ADDR"])!=0)
1307  {
1308  ilUtil::sendInfo($this->lng->txt("user_wrong_clientip"), true);
1309  $this->ctrl->redirectByClass("ilobjtestgui", "backToRepository");
1310  }
1311  }
1312 
1313 
1317  function isTestAccessible()
1318  {
1319  return !$this->isNrOfTriesReached()
1320  and !$this->isMaxProcessingTimeReached()
1321  and $this->object->startingTimeReached()
1322  and !$this->object->endingTimeReached();
1323  }
1324 
1329  {
1330  return $this->object->hasNrOfTriesRestriction() && $this->object->isNrOfTriesReached($this->object->getTestSession()->getPass());
1331  }
1332 
1340  function passDetails()
1341  {
1342  if (array_key_exists("pass", $_GET) && (strlen($_GET["pass"]) > 0))
1343  {
1344  $this->ctrl->saveParameter($this, "pass");
1345  $this->ctrl->saveParameter($this, "active_id");
1346  $this->outTestResults(false, $_GET["pass"]);
1347  }
1348  else
1349  {
1350  $this->outTestResults(false);
1351  }
1352  }
1353 
1359  function endingTimeReached()
1360  {
1361  ilUtil::sendInfo(sprintf($this->lng->txt("detail_ending_time_reached"), ilFormat::ftimestamp2datetimeDB($this->object->getEndingTime())));
1362  $this->object->getTestSession()->increasePass();
1363  $this->object->getTestSession()->setLastSequence(0);
1364  $this->object->getTestSession()->saveToDb();
1365  if (!$this->object->canViewResults())
1366  {
1367  $this->outIntroductionPage();
1368  }
1369  else
1370  {
1371  $this->ctrl->redirectByClass("ilTestEvaluationGUI", "outUserResultsOverview");
1372  }
1373  }
1374 
1383  {
1384  $this->outIntroductionPage();
1385  }
1386 
1393  {
1394  $this->tpl->addBlockFile($this->getContentBlockName(), "adm_content", "tpl.il_as_tst_submit_answers_confirm.html", "Modules/Test");
1395  $this->tpl->setCurrentBlock("adm_content");
1396  if ($this->object->isTestFinished($this->object->getTestSession()->getActiveId()))
1397  {
1398  $this->tpl->setCurrentBlock("not_submit_allowed");
1399  $this->tpl->setVariable("TEXT_ALREADY_SUBMITTED", $this->lng->txt("tst_already_submitted"));
1400  $this->tpl->setVariable("BTN_OK", $this->lng->txt("tst_show_answer_sheet"));
1401  } else
1402  {
1403  $this->tpl->setCurrentBlock("submit_allowed");
1404  $this->tpl->setVariable("TEXT_CONFIRM_SUBMIT_RESULTS", $this->lng->txt("tst_confirm_submit_answers"));
1405  $this->tpl->setVariable("BTN_OK", $this->lng->txt("tst_submit_results"));
1406  }
1407  $this->tpl->setVariable("BTN_BACK", $this->lng->txt("back"));
1408  $this->tpl->setVariable("FORMACTION", $this->ctrl->getFormAction($this, "finalSubmission"));
1409  $this->tpl->parseCurrentBlock();
1410  }
1411 
1412  function outProcessingTime($active_id)
1413  {
1414  global $ilUser;
1415 
1416  $starting_time = $this->object->getStartingTimeOfUser($active_id);
1417  $processing_time = $this->object->getProcessingTimeInSeconds();
1418  $processing_time_minutes = floor($processing_time / 60);
1419  $processing_time_seconds = $processing_time - $processing_time_minutes * 60;
1420  $str_processing_time = "";
1421  if ($processing_time_minutes > 0)
1422  {
1423  $str_processing_time = $processing_time_minutes . " " . $this->lng->txt("minutes");
1424  }
1425  if ($processing_time_seconds > 0)
1426  {
1427  if (strlen($str_processing_time) > 0) $str_processing_time .= " " . $this->lng->txt("and") . " ";
1428  $str_processing_time .= $processing_time_seconds . " " . $this->lng->txt("seconds");
1429  }
1430  $time_left = $starting_time + $processing_time - mktime();
1431  $time_left_minutes = floor($time_left / 60);
1432  $time_left_seconds = $time_left - $time_left_minutes * 60;
1433  $str_time_left = "";
1434  if ($time_left_minutes > 0)
1435  {
1436  $str_time_left = $time_left_minutes . " " . $this->lng->txt("minutes");
1437  }
1438  if ($time_left < 300)
1439  {
1440  if ($time_left_seconds > 0)
1441  {
1442  if (strlen($str_time_left) > 0) $str_time_left .= " " . $this->lng->txt("and") . " ";
1443  $str_time_left .= $time_left_seconds . " " . $this->lng->txt("seconds");
1444  }
1445  }
1446  $date = getdate($starting_time);
1447  $formattedStartingTime = ilDatePresentation::formatDate(new ilDateTime($date,IL_CAL_FKT_GETDATE));
1448  /*
1449  $formattedStartingTime = ilFormat::formatDate(
1450  $date["year"]."-".
1451  sprintf("%02d", $date["mon"])."-".
1452  sprintf("%02d", $date["mday"])." ".
1453  sprintf("%02d", $date["hours"]).":".
1454  sprintf("%02d", $date["minutes"]).":".
1455  sprintf("%02d", $date["seconds"])
1456  );
1457  */
1458  $datenow = getdate();
1459  $this->tpl->setCurrentBlock("enableprocessingtime");
1460  $this->tpl->setVariable("USER_WORKING_TIME",
1461  sprintf(
1462  $this->lng->txt("tst_time_already_spent"),
1463  $formattedStartingTime,
1464  $str_processing_time
1465  )
1466  );
1467  $this->tpl->setVariable("USER_REMAINING_TIME", sprintf($this->lng->txt("tst_time_already_spent_left"), $str_time_left));
1468  $this->tpl->parseCurrentBlock();
1469  $template = new ilTemplate("tpl.workingtime.js.html", TRUE, TRUE, TRUE);
1470  $template->setVariable("STRING_MINUTE", $this->lng->txt("minute"));
1471  $template->setVariable("STRING_MINUTES", $this->lng->txt("minutes"));
1472  $template->setVariable("STRING_SECOND", $this->lng->txt("second"));
1473  $template->setVariable("STRING_SECONDS", $this->lng->txt("seconds"));
1474  $template->setVariable("STRING_TIMELEFT", $this->lng->txt("tst_time_already_spent_left"));
1475  $template->setVariable("AND", strtolower($this->lng->txt("and")));
1476  $template->setVariable("YEAR", $date["year"]);
1477  $template->setVariable("MONTH", $date["mon"]-1);
1478  $template->setVariable("DAY", $date["mday"]);
1479  $template->setVariable("HOUR", $date["hours"]);
1480  $template->setVariable("MINUTE", $date["minutes"]);
1481  $template->setVariable("SECOND", $date["seconds"]);
1482  if (preg_match("/(\d{4})(\d{2})(\d{2})(\d{2})(\d{2})(\d{2})/", $this->object->getEndingTime(), $matches))
1483  {
1484  $template->setVariable("ENDYEAR", $matches[1]);
1485  $template->setVariable("ENDMONTH", $matches[2]-1);
1486  $template->setVariable("ENDDAY", $matches[3]);
1487  $template->setVariable("ENDHOUR", $matches[4]);
1488  $template->setVariable("ENDMINUTE", $matches[5]);
1489  $template->setVariable("ENDSECOND", $matches[6]);
1490  }
1491  $template->setVariable("YEARNOW", $datenow["year"]);
1492  $template->setVariable("MONTHNOW", $datenow["mon"]-1);
1493  $template->setVariable("DAYNOW", $datenow["mday"]);
1494  $template->setVariable("HOURNOW", $datenow["hours"]);
1495  $template->setVariable("MINUTENOW", $datenow["minutes"]);
1496  $template->setVariable("SECONDNOW", $datenow["seconds"]);
1497  $template->setVariable("PTIME_M", $processing_time_minutes);
1498  $template->setVariable("PTIME_S", $processing_time_seconds);
1499 
1500  $this->tpl->setCurrentBlock("HeadContent");
1501  $this->tpl->setVariable("CONTENT_BLOCK", $template->get());
1502  $this->tpl->parseCurrentBlock();
1503  }
1504 
1508  public function outQuestionSummary($fullpage = true)
1509  {
1510  if ($fullpage) $this->tpl->addBlockFile($this->getContentBlockName(), "adm_content", "tpl.il_as_tst_question_summary.html", "Modules/Test");
1511  $active_id = $this->object->getTestSession()->getActiveId();
1512  $result_array = & $this->object->getTestSequence()->getSequenceSummary();
1513  $marked_questions = array();
1514  if ($this->object->getKioskMode() && $fullpage)
1515  {
1516  $head = $this->getKioskHead();
1517  if (strlen($head))
1518  {
1519  $this->tpl->setCurrentBlock("kiosk_options");
1520  $this->tpl->setVariable("KIOSK_HEAD", $head);
1521  $this->tpl->parseCurrentBlock();
1522  }
1523  }
1524  if ($this->object->getShowMarker())
1525  {
1526  include_once "./Modules/Test/classes/class.ilObjTest.php";
1527  $marked_questions = ilObjTest::_getSolvedQuestions($active_id);
1528  }
1529  $data = array();
1530  foreach ($result_array as $key => $value)
1531  {
1532  $this->ctrl->setParameter($this, "sequence", $value["sequence"]);
1533  $href = $this->ctrl->getLinkTargetByClass(get_class($this), "gotoQuestion");
1534  $this->tpl->setVariable("VALUE_QUESTION_TITLE", "<a href=\"".$this->ctrl->getLinkTargetByClass(get_class($this), "gotoQuestion")."\">" . $this->object->getQuestionTitle($value["title"]) . "</a>");
1535  $this->ctrl->setParameter($this, "sequence", $_GET["sequence"]);
1536  $description = "";
1537  if ($this->object->getListOfQuestionsDescription())
1538  {
1539  $description = $value["description"];
1540  }
1541  $points = "";
1542  if (!$this->object->getTitleOutput())
1543  {
1544  $points = $value["points"]."&nbsp;".$this->lng->txt("points_short");
1545  }
1546  $marked = false;
1547  if (count($marked_questions))
1548  {
1549  if (array_key_exists($value["qid"], $marked_questions))
1550  {
1551  $obj = $marked_questions[$value["qid"]];
1552  if ($obj["solved"] == 1)
1553  {
1554  $marked = true;
1555  }
1556  }
1557  }
1558  array_push($data, array(
1559  'order' => $value["nr"],
1560  'href' => $href,
1561  'title' => $this->object->getQuestionTitle($value["title"]),
1562  'description' => $description,
1563  'worked_through' => ($value["worked_through"]) ? true : false,
1564  'postponed' => ($value["postponed"]) ? $this->lng->txt("postponed") : '',
1565  'points' => $points,
1566  'marked' => $marked,
1567  'sequence' => $value["sequence"]
1568  ));
1569  }
1570  $this->ctrl->setParameter($this, "sequence", $_GET["sequence"]);
1571  if ($fullpage)
1572  {
1573  include_once "./Modules/Test/classes/tables/class.ilListOfQuestionsTableGUI.php";
1574  $table_gui = new ilListOfQuestionsTableGUI($this, 'backFromSummary', !$this->object->getTitleOutput(), $this->object->getShowMarker());
1575  $table_gui->setData($data);
1576  $this->tpl->setVariable('TABLE_LIST_OF_QUESTIONS', $table_gui->getHTML());
1577  if ($this->object->getEnableProcessingTime()) $this->outProcessingTime($active_id);
1578  }
1579  else
1580  {
1581  $template = new ilTemplate('tpl.il_as_tst_list_of_questions_short.html', true, true, 'Modules/Test');
1582  foreach ($data as $row)
1583  {
1584  if (strlen($row['description']))
1585  {
1586  $template->setCurrentBlock('description');
1587  $template->setVariable("DESCRIPTION", $row['description']);
1588  $template->parseCurrentBlock();
1589  }
1590  $template->setCurrentBlock('item');
1591  $active = ($row['sequence'] == $this->sequence) ? ' active' : '';
1592  $template->setVariable('CLASS', ($row['walked_through']) ? ('answered'.$active) : ('unanswered'.$active));
1593  $template->setVariable('ITEM', ilUtil::prepareFormOutput($row['title']));
1594  $template->setVariable('SEQUENCE', $row['sequence']);
1595  $template->parseCurrentBlock();
1596  }
1597  $template->setVariable('LIST_OF_QUESTIONS', $this->lng->txt('list_of_questions'));
1598  $this->tpl->setVariable('LIST_OF_QUESTIONS', $template->get());
1599  }
1600  }
1601 
1603  {
1604  $this->tpl->addBlockFile($this->getContentBlockName(), "adm_content", "tpl.il_as_tst_max_allowed_users_reached.html", "Modules/Test");
1605  $this->tpl->setCurrentBlock("adm_content");
1606  $this->tpl->setVariable("MAX_ALLOWED_USERS_MESSAGE", sprintf($this->lng->txt("tst_max_allowed_users_message"), $this->object->getAllowedUsersTimeGap()));
1607  $this->tpl->setVariable("MAX_ALLOWED_USERS_HEADING", sprintf($this->lng->txt("tst_max_allowed_users_heading"), $this->object->getAllowedUsersTimeGap()));
1608  $this->tpl->setVariable("BACK_TO_INTRODUCTION", $this->lng->txt("tst_results_back_introduction"));
1609  $this->tpl->setVariable("FORMACTION", $this->ctrl->getFormAction($this));
1610  $this->tpl->parseCurrentBlock();
1611  }
1612 
1614  {
1615  global $ilUser;
1616  if ($this->object->canShowSolutionPrintview($ilUser->getId()))
1617  {
1618  $template = new ilTemplate("tpl.il_as_tst_finish_navigation.html", TRUE, TRUE, "Modules/Test");
1619  $template->setVariable("BUTTON_FINISH", $this->lng->txt("btn_next"));
1620  $template->setVariable("BUTTON_CANCEL", $this->lng->txt("btn_previous"));
1621 
1622  $template_top = new ilTemplate("tpl.il_as_tst_list_of_answers_topbuttons.html", TRUE, TRUE, "Modules/Test");
1623  $template_top->setCurrentBlock("button_print");
1624  $template_top->setVariable("BUTTON_PRINT", $this->lng->txt("print"));
1625  $template_top->parseCurrentBlock();
1626  $active_id = $this->object->getTestSession()->getActiveId();
1627  return $this->showListOfAnswers($active_id, NULL, $template_top->get(), $template->get());
1628  }
1629  else
1630  {
1631  $this->ctrl->redirect($this, 'gotoQuestion');
1632  }
1633  }
1634 
1636  {
1637  $this->confirmFinishTest();
1638  }
1639 
1646  {
1647  $this->tpl->addBlockFile("ADM_CONTENT", "adm_content", "tpl.il_as_tst_correct_solution.html", "Modules/Test");
1648 
1649  include_once("./Services/Style/classes/class.ilObjStyleSheet.php");
1650  $this->tpl->setCurrentBlock("ContentStyle");
1651  $this->tpl->setVariable("LOCATION_CONTENT_STYLESHEET", ilObjStyleSheet::getContentStylePath(0));
1652  $this->tpl->parseCurrentBlock();
1653 
1654  $this->tpl->setCurrentBlock("SyntaxStyle");
1655  $this->tpl->setVariable("LOCATION_SYNTAX_STYLESHEET", ilObjStyleSheet::getSyntaxStylePath());
1656  $this->tpl->parseCurrentBlock();
1657 
1658  $this->tpl->addCss(ilUtil::getStyleSheetLocation("output", "test_print.css", "Modules/Test"), "print");
1659  if ($this->object->getShowSolutionAnswersOnly())
1660  {
1661  $this->tpl->addCss(ilUtil::getStyleSheetLocation("output", "test_print_hide_content.css", "Modules/Test"), "print");
1662  }
1663 
1664  $this->tpl->setCurrentBlock("adm_content");
1665  $solution = $this->getCorrectSolutionOutput($_GET["evaluation"], $_GET["active_id"], $_GET["pass"]);
1666  $this->tpl->setVariable("OUTPUT_SOLUTION", $solution);
1667  $this->tpl->setVariable("TEXT_BACK", $this->lng->txt("back"));
1668  $this->ctrl->saveParameter($this, "pass");
1669  $this->ctrl->saveParameter($this, "active_id");
1670  $this->tpl->setVariable("URL_BACK", $this->ctrl->getLinkTarget($this, "outUserResultsOverview"));
1671  $this->tpl->parseCurrentBlock();
1672  }
1673 
1683  function showListOfAnswers($active_id, $pass = NULL, $top_data = "", $bottom_data = "")
1684  {
1685  global $ilUser;
1686 
1687  $this->tpl->addBlockFile($this->getContentBlockName(), "adm_content", "tpl.il_as_tst_finish_list_of_answers.html", "Modules/Test");
1688 
1689  $result_array =& $this->object->getTestResult($active_id, $pass);
1690 
1691  $counter = 1;
1692  // output of questions with solutions
1693  foreach ($result_array as $question_data)
1694  {
1695  $question = $question_data["qid"];
1696  if (is_numeric($question))
1697  {
1698  $this->tpl->setCurrentBlock("printview_question");
1699  $question_gui = $this->object->createQuestionGUI("", $question);
1700  $template = new ilTemplate("tpl.il_as_qpl_question_printview.html", TRUE, TRUE, "Modules/TestQuestionPool");
1701  $template->setVariable("COUNTER_QUESTION", $counter.". ");
1702  $template->setVariable("QUESTION_TITLE", $question_gui->object->getTitle());
1703 
1704  $show_question_only = ($this->object->getShowSolutionAnswersOnly()) ? TRUE : FALSE;
1705  $result_output = $question_gui->getSolutionOutput($active_id, $pass, FALSE, FALSE, $show_question_only, $this->object->getShowSolutionFeedback());
1706  $template->setVariable("SOLUTION_OUTPUT", $result_output);
1707  $this->tpl->setVariable("QUESTION_OUTPUT", $template->get());
1708  $this->tpl->parseCurrentBlock();
1709  $counter ++;
1710  }
1711  }
1712 
1713  $this->tpl->addCss(ilUtil::getStyleSheetLocation("output", "test_print.css", "Modules/Test"), "print");
1714  if ($this->object->getShowSolutionAnswersOnly())
1715  {
1716  $this->tpl->addCss(ilUtil::getStyleSheetLocation("output", "test_print_hide_content.css", "Modules/Test"), "print");
1717  }
1718  if (strlen($top_data))
1719  {
1720  $this->tpl->setCurrentBlock("top_data");
1721  $this->tpl->setVariable("TOP_DATA", $top_data);
1722  $this->tpl->parseCurrentBlock();
1723  }
1724 
1725  if (strlen($bottom_data))
1726  {
1727  $this->tpl->setCurrentBlock("bottom_data");
1728  $this->tpl->setVariable("FORMACTION", $this->ctrl->getFormAction($this));
1729  $this->tpl->setVariable("BOTTOM_DATA", $bottom_data);
1730  $this->tpl->parseCurrentBlock();
1731  }
1732 
1733  $this->tpl->setCurrentBlock("adm_content");
1734  $this->tpl->setVariable("TXT_ANSWER_SHEET", $this->lng->txt("tst_list_of_answers"));
1735  $user_data = $this->getResultsUserdata($active_id, TRUE);
1736  $signature = $this->getResultsSignature();
1737  $this->tpl->setVariable("USER_DETAILS", $user_data);
1738  $this->tpl->setVariable("SIGNATURE", $signature);
1739  $this->tpl->setVariable("TITLE", $this->object->getTitle());
1740  $this->tpl->setVariable("TXT_TEST_PROLOG", $this->lng->txt("tst_your_answers"));
1741  $invited_user =& $this->object->getInvitedUsers($ilUser->getId());
1742  $pagetitle = $this->object->getTitle() . " - " . $this->lng->txt("clientip") .
1743  ": " . $invited_user[$ilUser->getId()]["clientip"] . " - " .
1744  $this->lng->txt("matriculation") . ": " .
1745  $invited_user[$ilUser->getId()]["matriculation"];
1746  $this->tpl->setVariable("PAGETITLE", $pagetitle);
1747  $this->tpl->parseCurrentBlock();
1748  }
1749 
1756  private function getContentBlockName()
1757  {
1758  if ($this->object->getKioskMode())
1759  {
1760  $this->tpl->setBodyClass("kiosk");
1761  $this->tpl->setAddFooter(FALSE);
1762  return "CONTENT";
1763  }
1764  else
1765  {
1766  return "ADM_CONTENT";
1767  }
1768  }
1769 
1771  {
1772  $this->ctrl->redirectByClass("iltestevaluationgui", "outUserResultsOverview");
1773  }
1774 
1776  {
1777  $this->ctrl->redirectByClass("iltestevaluationgui", "outUserListOfAnswerPasses");
1778  }
1779 
1780 }
1781 ?>