ILIAS  release_4-3 Revision
 All Data Structures Namespaces Files Functions Variables Groups Pages
class.assQuestionGUI.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.ilTestExpressPage.php';
39 abstract class assQuestionGUI
40 {
48  var $object;
49 
50  var $tpl;
51  var $lng;
52  var $error;
54 
63 
67  var $prevent_rte_usage = false;
68 
72  function __construct()
73  {
74  global $lng, $tpl, $ilCtrl;
75 
76 
77  $this->lng =& $lng;
78  $this->tpl =& $tpl;
79  $this->ctrl =& $ilCtrl;
80  $this->ctrl->saveParameter($this, "q_id");
81  $this->ctrl->saveParameter($this, "prev_qid");
82  $this->ctrl->saveParameter($this, "calling_test");
83  $this->ctrl->saveParameterByClass('ilPageObjectGUI', 'test_express_mode');
84  $this->ctrl->saveParameterByClass('ilobjquestionpoolgui', 'test_express_mode');
85 
86  include_once "./Modules/TestQuestionPool/classes/class.assQuestion.php";
87  $this->errormessage = $this->lng->txt("fill_out_all_required_fields");
88 
89  $this->selfassessmenteditingmode = false;
90  $this->new_id_listeners = array();
91  $this->new_id_listener_cnt = 0;
92  }
93 
97  function &executeCommand()
98  {
99  $cmd = $this->ctrl->getCmd("editQuestion");
100  $next_class = $this->ctrl->getNextClass($this);
101 
102  $cmd = $this->getCommand($cmd);
103 
104  switch($next_class)
105  {
106  default:
107  $ret =& $this->$cmd();
108  break;
109  }
110  return $ret;
111  }
112 
113  function getCommand($cmd)
114  {
115  return $cmd;
116  }
117 
121  function getType()
122  {
123  return $this->getQuestionType();
124  }
125 
132  function writePostData()
133  {
134  }
135 
139  function assessment()
140  {
141  $this->tpl->addBlockFile("CONTENT", "content", "tpl.il_as_qpl_content.html", "Modules/TestQuestionPool");
142  $this->tpl->addBlockFile("STATUSLINE", "statusline", "tpl.statusline.html");
143 
144  $total_of_answers = $this->object->getTotalAnswers();
145  $counter = 0;
146  $color_class = array("tblrow1", "tblrow2");
147  $this->tpl->addBlockFile("ADM_CONTENT", "adm_content", "tpl.il_as_qpl_assessment_of_questions.html", "Modules/TestQuestionPool");
148  if (!$total_of_answers)
149  {
150  $this->tpl->setCurrentBlock("emptyrow");
151  $this->tpl->setVariable("TXT_NO_ASSESSMENT", $this->lng->txt("qpl_assessment_no_assessment_of_questions"));
152  $this->tpl->setVariable("COLOR_CLASS", $color_class[$counter % 2]);
153  $this->tpl->parseCurrentBlock();
154  }
155  else
156  {
157  $this->tpl->setCurrentBlock("row");
158  $this->tpl->setVariable("TXT_RESULT", $this->lng->txt("qpl_assessment_total_of_answers"));
159  $this->tpl->setVariable("TXT_VALUE", $total_of_answers);
160  $this->tpl->setVariable("COLOR_CLASS", $color_class[$counter % 2]);
161  $counter++;
162  $this->tpl->parseCurrentBlock();
163  $this->tpl->setCurrentBlock("row");
164  $this->tpl->setVariable("TXT_RESULT", $this->lng->txt("qpl_assessment_total_of_right_answers"));
165  $this->tpl->setVariable("TXT_VALUE", sprintf("%2.2f", $this->object->_getTotalRightAnswers($_GET["q_id"]) * 100.0) . " %");
166  $this->tpl->setVariable("COLOR_CLASS", $color_class[$counter % 2]);
167  $this->tpl->parseCurrentBlock();
168  }
169 
170  $instances =& $this->object->getInstances();
171  $counter = 0;
172  foreach ($instances as $instance)
173  {
174  if (is_array($instance["refs"]))
175  {
176  foreach ($instance["refs"] as $ref_id)
177  {
178  $this->tpl->setCurrentBlock("references");
179  $this->tpl->setVariable("GOTO", "./goto.php?target=tst_" . $ref_id);
180  $this->tpl->setVariable("TEXT_GOTO", $this->lng->txt("perma_link"));
181  $this->tpl->parseCurrentBlock();
182  }
183  }
184  $this->tpl->setCurrentBlock("instance_row");
185  $this->tpl->setVariable("TEST_TITLE", $instance["title"]);
186  $this->tpl->setVariable("TEST_AUTHOR", $instance["author"]);
187  $this->tpl->setVariable("QUESTION_ID", $instance["question_id"]);
188  $this->tpl->setVariable("COLOR_CLASS", $color_class[$counter % 2]);
189  $counter++;
190  $this->tpl->parseCurrentBlock();
191  }
192  $this->tpl->setCurrentBlock("instances");
193  $this->tpl->setVariable("TEXT_TEST_TITLE", $this->lng->txt("title"));
194  $this->tpl->setVariable("TEXT_TEST_AUTHOR", $this->lng->txt("author"));
195  $this->tpl->setVariable("TEXT_TEST_LOCATION", $this->lng->txt("location"));
196  $this->tpl->setVariable("INSTANCES_TITLE", $this->lng->txt("question_instances_title"));
197  $this->tpl->parseCurrentBlock();
198 
199  $this->tpl->setCurrentBlock("adm_content");
200  $this->tpl->setVariable("TXT_QUESTION_TITLE", $this->lng->txt("question_cumulated_statistics"));
201  $this->tpl->setVariable("TXT_RESULT", $this->lng->txt("result"));
202  $this->tpl->setVariable("TXT_VALUE", $this->lng->txt("value"));
203  $this->tpl->parseCurrentBlock();
204  }
205 
215  function &_getQuestionGUI($question_type, $question_id = -1)
216  {
217  include_once "./Modules/TestQuestionPool/classes/class.assQuestion.php";
218  if ((!$question_type) and ($question_id > 0))
219  {
220  $question_type = assQuestion::getQuestionTypeFromDb($question_id);
221  }
222  if (strlen($question_type) == 0) return NULL;
223  $question_type_gui = $question_type . "GUI";
224  assQuestion::_includeClass($question_type, 1);
225  $question =& new $question_type_gui();
226  if ($question_id > 0)
227  {
228  $question->object->loadFromDb($question_id);
229  }
230  return $question;
231  }
232 
233  function _getGUIClassNameForId($a_q_id)
234  {
235  include_once "./Modules/TestQuestionPool/classes/class.assQuestion.php";
236  include_once "./Modules/TestQuestionPool/classes/class.assQuestionGUI.php";
237  $q_type = assQuestion::getQuestionTypeFromDb($a_q_id);
238  $class_name = assQuestionGUI::_getClassNameForQType($q_type);
239  return $class_name;
240  }
241 
242  function _getClassNameForQType($q_type)
243  {
244  return $q_type . "GUI";
245  }
246 
257  function &createQuestionGUI($question_type, $question_id = -1)
258  {
259  include_once "./Modules/TestQuestionPool/classes/class.assQuestionGUI.php";
260  $this->question =& assQuestionGUI::_getQuestionGUI($question_type, $question_id);
261  }
262 
267  {
268  $this->tpl->addBlockFile("CONTENT", "content", "tpl.il_as_qpl_content.html", "Modules/TestQuestionPool");
269  $this->tpl->addBlockFile("STATUSLINE", "statusline", "tpl.statusline.html");
270  $this->tpl->addBlockFile("ADM_CONTENT", "adm_content", "tpl.il_as_question.html", "Modules/TestQuestionPool");
271  }
272 
279  function getILIASPage($html = "")
280  {
281  include_once("./Services/COPage/classes/class.ilPageObject.php");
282  include_once("./Services/COPage/classes/class.ilPageObjectGUI.php");
283  //$page =& new ilPageObject("qpl", $this->object->getId());
284  $page_gui =& new ilPageObjectGUI("qpl", $this->object->getId());
285  $page_gui->setTemplateTargetVar($a_temp_var);
286  $page_gui->setEnabledInternalLinks(false);
287  $page_gui->setQuestionHTML(array($this->object->getId() => $html));
288  $page_gui->setFileDownloadLink("ilias.php?baseClass=ilObjTestGUI&cmd=downloadFile".
289  "&amp;ref_id=".$_GET["ref_id"]);
290  $page_gui->setFullscreenLink("ilias.php?baseClass=ilObjTestGUI&cmd=fullscreen".
291  "&amp;ref_id=".$_GET["ref_id"]);
292  $page_gui->setSourcecodeDownloadScript("ilias.php?baseClass=ilObjTestGUI&ref_id=".$_GET["ref_id"]);
293  $page_gui->setEnabledPageFocus(false);
294  $page_gui->setOutputMode("presentation");
295  $page_gui->setPresentationTitle("");
296  $presentation = $page_gui->presentation();
297  // bugfix for non XHTML conform img tags in ILIAS Learning Module Editor
298  $presentation = preg_replace("/src=\".\\//ims", "src=\"" . ILIAS_HTTP_PATH . "/", $presentation);
299  return $presentation;
300  }
301 
305  function outQuestionPage($a_temp_var, $a_postponed = false, $active_id = "", $html = "")
306  {
307  $postponed = "";
308  if ($a_postponed)
309  {
310  $postponed = " (" . $this->lng->txt("postponed") . ")";
311  }
312 
313  include_once("./Services/COPage/classes/class.ilPageObject.php");
314  include_once("./Services/COPage/classes/class.ilPageObjectGUI.php");
315  $this->lng->loadLanguageModule("content");
316  //$page =& new ilPageObject("qpl", $this->object->getId());
317  $page_gui =& new ilPageObjectGUI("qpl", $this->object->getId());
318  $page_gui->setTemplateTargetVar($a_temp_var);
319  $page_gui->setFileDownloadLink("ilias.php?baseClass=ilObjTestGUI&cmd=downloadFile".
320  "&amp;ref_id=".$_GET["ref_id"]);
321  $page_gui->setFullscreenLink("ilias.php?baseClass=ilObjTestGUI&cmd=fullscreen".
322  "&amp;ref_id=".$_GET["ref_id"]);
323  $page_gui->setEnabledPageFocus(false);
324  if (strlen($html))
325  {
326  $page_gui->setQuestionHTML(array($this->object->getId() => $html));
327  }
328  $page_gui->setSourcecodeDownloadScript("ilias.php?baseClass=ilObjTestGUI&ref_id=".$_GET["ref_id"]);
329  $page_gui->setOutputMode("presentation");
330 
331  include_once "./Modules/Test/classes/class.ilObjTest.php";
332  $title_output = ilObjTest::_getTitleOutput($active_id);
333 
334  if( $this->object->areObligationsToBeConsidered() && ilObjTest::isQuestionObligatory($this->object->getId()) )
335  {
336  $obligatoryString = '([-_-])';
337  }
338  else
339  {
340  $obligatoryString = '';
341  }
342 
343  switch ($title_output)
344  {
345  case 1:
346  $page_gui->setPresentationTitle(sprintf($this->lng->txt("tst_position"), $this->getSequenceNumber(), $this->getQuestionCount())." - ".$this->object->getTitle().$postponed . $obligatoryString);
347  break;
348  case 2:
349  $page_gui->setPresentationTitle(sprintf($this->lng->txt("tst_position"), $this->getSequenceNumber(), $this->getQuestionCount()).$postponed . $obligatoryString);
350  break;
351  case 0:
352  default:
353  $maxpoints = $this->object->getMaximumPoints();
354  if ($maxpoints == 1)
355  {
356  $maxpoints = " (".$maxpoints." ".$this->lng->txt("point").")";
357  }
358  else
359  {
360  $maxpoints = " (".$maxpoints." ".$this->lng->txt("points").")";
361  }
362  $page_gui->setPresentationTitle(sprintf($this->lng->txt("tst_position"), $this->getSequenceNumber(), $this->getQuestionCount())." - ".$this->object->getTitle().$postponed.$maxpoints . $obligatoryString);
363  break;
364  }
365  $presentation = $page_gui->presentation();
366  if (strlen($maxpoints)) $presentation = str_replace($maxpoints, "<em>$maxpoints</em>", $presentation);
367  if (strlen($obligatoryString))
368  {
369  $replacement ='<br><span class="obligatory" style="font-size:small">'.
370  $this->lng->txt("tst_you_have_to_answer_this_question").'</span>';
371  $presentation = str_replace($obligatoryString, $replacement, $presentation);
372  }
373  // bugfix for non XHTML conform img tags in ILIAS Learning Module Editor
374  $presentation = preg_replace("/src=\".\\//ims", "src=\"" . ILIAS_HTTP_PATH . "/", $presentation);
375  return $presentation;
376  }
377 
381  function cancel()
382  {
383  if ($_GET["calling_test"])
384  {
385  $_GET["ref_id"] = $_GET["calling_test"];
386  ilUtil::redirect("ilias.php?baseClass=ilObjTestGUI&cmd=questions&ref_id=".$_GET["calling_test"]);
387  }
388  elseif ($_GET["test_ref_id"])
389  {
390  $_GET["ref_id"] = $_GET["test_ref_id"];
391  ilUtil::redirect("ilias.php?baseClass=ilObjTestGUI&cmd=questions&ref_id=".$_GET["test_ref_id"]);
392  }
393  else
394  {
395  if ($_GET["q_id"] > 0)
396  {
397  $this->ctrl->setParameterByClass("ilpageobjectgui", "q_id", $_GET["q_id"]);
398  $this->ctrl->redirectByClass("ilpageobjectgui", "edit");
399  }
400  else
401  {
402  $this->ctrl->redirectByClass("ilobjquestionpoolgui", "questions");
403  }
404  }
405  }
406 
407  function originalSyncForm($return_to = "")
408  {
409  if (strlen($return_to))
410  {
411  $this->ctrl->setParameter($this, "return_to", $return_to);
412  }
413  else if ($_REQUEST['return_to']) {
414  $this->ctrl->setParameter($this, "return_to", $_REQUEST['return_to']);
415  }
416  $template = new ilTemplate("tpl.il_as_qpl_sync_original.html",TRUE, TRUE, "Modules/TestQuestionPool");
417  $template->setVariable("BUTTON_YES", $this->lng->txt("yes"));
418  $template->setVariable("BUTTON_NO", $this->lng->txt("no"));
419  $template->setVariable("FORM_ACTION", $this->ctrl->getFormAction($this));
420  $template->setVariable("TEXT_SYNC", $this->lng->txt("confirm_sync_questions"));
421  $this->tpl->setVariable("ADM_CONTENT", $template->get());
422  }
423 
424  function sync()
425  {
426  $original_id = $this->object->original_id;
427  if ($original_id)
428  {
429  $this->object->syncWithOriginal();
430  }
431  if (strlen($_GET["return_to"]))
432  {
433  $this->ctrl->redirect($this, $_GET["return_to"]);
434  }
435  else
436  {
437  $_GET["ref_id"] = $_GET["calling_test"];
438  ilUtil::redirect("ilias.php?baseClass=ilObjTestGUI&cmd=questions&ref_id=".$_GET["calling_test"]);
439  }
440  }
441 
442  function cancelSync()
443  {
444  if (strlen($_GET["return_to"]))
445  {
446  $this->ctrl->redirect($this, $_GET["return_to"]);
447  }
448  else
449  {
450  $_GET["ref_id"] = $_GET["calling_test"];
451  ilUtil::redirect("ilias.php?baseClass=ilObjTestGUI&cmd=questions&ref_id=".$_GET["calling_test"]);
452  }
453  }
454 
462  function saveFeedback()
463  {
464  global $ilUser;
465 
466  $originalexists = $this->object->_questionExistsInPool($this->object->original_id);
467  include_once "./Modules/TestQuestionPool/classes/class.assQuestion.php";
468  if ($_GET["calling_test"] && $originalexists && assQuestion::_isWriteable($this->object->original_id, $ilUser->getId()))
469  {
470  $this->originalSyncForm("feedback");
471  }
472  else
473  {
474  ilUtil::sendSuccess($this->lng->txt("msg_obj_modified"), false);
475  $this->feedback();
476  }
477  }
478 
482  function saveEdit()
483  {
484  global $ilUser;
485 
486  $result = $this->writePostData();
487  if ($result == 0)
488  {
489  $ilUser->setPref("tst_lastquestiontype", $this->object->getQuestionType());
490  $ilUser->writePref("tst_lastquestiontype", $this->object->getQuestionType());
491  $this->object->saveToDb();
492  $originalexists = $this->object->_questionExists($this->object->original_id);
493  include_once "./Modules/TestQuestionPool/classes/class.assQuestion.php";
494  if ($_GET["calling_test"] && $originalexists && assQuestion::_isWriteable($this->object->original_id, $ilUser->getId()))
495  {
496  $this->ctrl->redirect($this, "originalSyncForm");
497  }
498  elseif ($_GET["calling_test"])
499  {
500  $_GET["ref_id"] = $_GET["calling_test"];
501  ilUtil::redirect("ilias.php?baseClass=ilObjTestGUI&cmd=questions&ref_id=".$_GET["calling_test"]);
502  return;
503  }
504  elseif ($_GET["test_ref_id"])
505  {
506  include_once ("./Modules/Test/classes/class.ilObjTest.php");
507  $_GET["ref_id"] = $_GET["test_ref_id"];
508  $test =& new ilObjTest($_GET["test_ref_id"], true);
509  $test->insertQuestion($this->object->getId());
510  ilUtil::redirect("ilias.php?baseClass=ilObjTestGUI&cmd=questions&ref_id=".$_GET["test_ref_id"]);
511  }
512  else
513  {
514  $this->ctrl->setParameter($this, "q_id", $this->object->getId());
515  $this->editQuestion();
516  if (strcmp($_SESSION["info"], "") != 0)
517  {
518  ilUtil::sendSuccess($_SESSION["info"] . "<br />" . $this->lng->txt("msg_obj_modified"), false);
519  }
520  else
521  {
522  ilUtil::sendSuccess($this->lng->txt("msg_obj_modified"), false);
523  }
524  $this->ctrl->setParameterByClass("ilpageobjectgui", "q_id", $this->object->getId());
525  $this->ctrl->redirectByClass("ilpageobjectgui", "edit");
526  }
527  }
528  }
529 
533  function save()
534  {
535  global $ilUser;
536  $old_id = $_GET["q_id"];
537  $result = $this->writePostData();
538 
539  if ($result == 0)
540  {
541  $ilUser->setPref("tst_lastquestiontype", $this->object->getQuestionType());
542  $ilUser->writePref("tst_lastquestiontype", $this->object->getQuestionType());
543  $this->object->saveToDb();
544  $originalexists = $this->object->_questionExistsInPool($this->object->original_id);
545 
546 
547 
548  include_once "./Modules/TestQuestionPool/classes/class.assQuestion.php";
549  if ($_GET["calling_test"] && $originalexists && assQuestion::_isWriteable($this->object->original_id, $ilUser->getId()))
550  {
551  $this->ctrl->setParameter($this, 'return_to', 'editQuestion');
552  $this->ctrl->redirect($this, "originalSyncForm");
553  return;
554  }
555  elseif ($_GET["calling_test"])
556  {
557  require_once 'Modules/Test/classes/class.ilObjTest.php';
558  $test = new ilObjTest($_GET["calling_test"]);
559  if (!assQuestion::_questionExistsInTest($this->object->getId(), $test->getTestId()))
560  {
561  include_once ("./Modules/Test/classes/class.ilObjTest.php");
562  $_GET["ref_id"] = $_GET["calling_test"];
563  $test =& new ilObjTest($_GET["calling_test"], true);
564  $new_id = $test->insertQuestion($this->object->getId());
565 
566  if(isset($_REQUEST['prev_qid'])) {
567  $test->moveQuestionAfter($this->object->getId() + 1, $_REQUEST['prev_qid']);
568  }
569 
570  $this->ctrl->setParameter($this, 'q_id', $new_id);
571  $this->ctrl->setParameter($this, 'calling_test', $_GET['calling_test']);
572  #$this->ctrl->setParameter($this, 'test_ref_id', false);
573  }
574  $this->ctrl->redirect($this, 'editQuestion');
575 
576  }
577  else
578  {
579  $this->callNewIdListeners($this->object->getId());
580 
581  if ($this->object->getId() != $old_id)
582  {
583  // first save
584  $this->ctrl->setParameterByClass($_GET["cmdClass"], "q_id", $this->object->getId());
585  $this->ctrl->setParameterByClass($_GET["cmdClass"], "sel_question_types", $_GET["sel_question_types"]);
586  ilUtil::sendSuccess($this->lng->txt("msg_obj_modified"), true);
587 
588  //global $___test_express_mode;
592  if($_REQUEST['prev_qid']) {
593  $test->moveQuestionAfter($_REQUEST['prev_qid'], $this->object->getId());
594  }
595  if(/*$___test_express_mode || */$_REQUEST['express_mode']) {
596 
597  include_once ("./Modules/Test/classes/class.ilObjTest.php");
598  $test =& new ilObjTest($_GET["ref_id"], true);
599  $test->insertQuestion($this->object->getId());
600  require_once 'Modules/Test/classes/class.ilTestExpressPage.php';
601  $_REQUEST['q_id'] = $this->object->getId();
603  }
604 
605  $this->ctrl->redirectByClass($_GET["cmdClass"], "editQuestion");
606  }
607  if (strcmp($_SESSION["info"], "") != 0)
608  {
609  ilUtil::sendSuccess($_SESSION["info"] . "<br />" . $this->lng->txt("msg_obj_modified"), true);
610  }
611  else
612  {
613  ilUtil::sendSuccess($this->lng->txt("msg_obj_modified"), true);
614  }
615  $this->ctrl->redirect($this, 'editQuestion');
616  }
617  }
618  }
619 
623  function saveReturn()
624  {
625  global $ilUser;
626  $old_id = $_GET["q_id"];
627  $result = $this->writePostData();
628  if ($result == 0)
629  {
630  $ilUser->setPref("tst_lastquestiontype", $this->object->getQuestionType());
631  $ilUser->writePref("tst_lastquestiontype", $this->object->getQuestionType());
632  $this->object->saveToDb();
633  $originalexists = $this->object->_questionExistsInPool($this->object->original_id);
634  include_once "./Modules/TestQuestionPool/classes/class.assQuestion.php";
635  if ($_GET["calling_test"] && $originalexists && assQuestion::_isWriteable($this->object->original_id, $ilUser->getId()))
636  {
637  $this->ctrl->redirect($this, "originalSyncForm");
638  return;
639  }
640  elseif ($_GET["calling_test"])
641  {
642  require_once 'Modules/Test/classes/class.ilObjTest.php';
643  $test = new ilObjTest($_GET["calling_test"]);
644  #var_dump(assQuestion::_questionExistsInTest($this->object->getId(), $test->getTestId()));
645  $q_id = $this->object->getId();
646  if (!assQuestion::_questionExistsInTest($this->object->getId(), $test->getTestId()))
647  {
648  include_once ("./Modules/Test/classes/class.ilObjTest.php");
649  $_GET["ref_id"] = $_GET["calling_test"];
650  $test =& new ilObjTest($_GET["calling_test"], true);
651  $new_id = $test->insertQuestion($this->object->getId());
652  $q_id = $new_id;
653  if(isset($_REQUEST['prev_qid'])) {
654  $test->moveQuestionAfter($this->object->getId() + 1, $_REQUEST['prev_qid']);
655  }
656 
657  $this->ctrl->setParameter($this, 'q_id', $new_id);
658  $this->ctrl->setParameter($this, 'calling_test', $_GET['calling_test']);
659  #$this->ctrl->setParameter($this, 'test_ref_id', false);
660 
661  }
662 
663  if(/*$___test_express_mode || */$_REQUEST['test_express_mode']) {
665  }
666  else
667  {
668  ilUtil::redirect("ilias.php?baseClass=ilObjTestGUI&cmd=questions&ref_id=".$_GET["calling_test"]);
669  }
670  }
671  else
672  {
673  if ($this->object->getId() != $old_id)
674  {
675  $this->callNewIdListeners($this->object->getId());
676  ilUtil::sendSuccess($this->lng->txt("msg_obj_modified"), true);
677  $this->ctrl->redirectByClass("ilobjquestionpoolgui", "questions");
678  }
679  if (strcmp($_SESSION["info"], "") != 0)
680  {
681  ilUtil::sendSuccess($_SESSION["info"] . "<br />" . $this->lng->txt("msg_obj_modified"), true);
682  }
683  else
684  {
685  ilUtil::sendSuccess($this->lng->txt("msg_obj_modified"), true);
686  }
687  $this->ctrl->redirectByClass("ilobjquestionpoolgui", "questions");
688  }
689  }
690  }
691 
695  function apply()
696  {
697  $this->writePostData();
698  $this->object->saveToDb();
699  $this->ctrl->setParameter($this, "q_id", $this->object->getId());
700  $this->editQuestion();
701  }
702 
709  function getContextPath($cont_obj, $a_endnode_id, $a_startnode_id = 1)
710  {
711  $path = "";
712 
713  $tmpPath = $cont_obj->getLMTree()->getPathFull($a_endnode_id, $a_startnode_id);
714 
715  // count -1, to exclude the learning module itself
716  for ($i = 1; $i < (count($tmpPath) - 1); $i++)
717  {
718  if ($path != "")
719  {
720  $path .= " > ";
721  }
722 
723  $path .= $tmpPath[$i]["title"];
724  }
725 
726  return $path;
727  }
728 
729  function setSequenceNumber($nr)
730  {
731  $this->sequence_no = $nr;
732  }
733 
734  function getSequenceNumber()
735  {
736  return $this->sequence_no;
737  }
738 
739  function setQuestionCount($a_question_count)
740  {
741  $this->question_count = $a_question_count;
742  }
743 
744  function getQuestionCount()
745  {
746  return $this->question_count;
747  }
748 
749  function getErrorMessage()
750  {
751  return $this->errormessage;
752  }
753 
755  {
756  $this->errormessage = $errormessage;
757  }
758 
760  {
761  $this->errormessage .= ((strlen($this->errormessage)) ? "<br />" : "") . $errormessage;
762  }
763 
765  {
766  }
767 
776  function getQuestionType()
777  {
778  return $this->object->getQuestionType();
779  }
780 
788  public function getAsValueAttribute($a_value)
789  {
790  $result = "";
791  if (strlen($a_value))
792  {
793  $result = " value=\"$a_value\" ";
794  }
795  return $result;
796  }
797 
798  // scorm2004-start
803  function addNewIdListener(&$a_object, $a_method, $a_parameters = "")
804  {
805  $cnt = $this->new_id_listener_cnt;
806  $this->new_id_listeners[$cnt]["object"] =& $a_object;
807  $this->new_id_listeners[$cnt]["method"] = $a_method;
808  $this->new_id_listeners[$cnt]["parameters"] = $a_parameters;
809  $this->new_id_listener_cnt++;
810  }
811 
815  function callNewIdListeners($a_new_id)
816  {
817 
818  for ($i=0; $i<$this->new_id_listener_cnt; $i++)
819  {
820  $this->new_id_listeners[$i]["parameters"]["new_id"] = $a_new_id;
821  $object =& $this->new_id_listeners[$i]["object"];
822  $method = $this->new_id_listeners[$i]["method"];
823  $parameters = $this->new_id_listeners[$i]["parameters"];
824 //var_dump($object);
825 //var_dump($method);
826 //var_dump($parameters);
827 
828  $object->$method($parameters);
829  }
830  }
831 
837  function setSelfAssessmentEditingMode($a_selfassessmenteditingmode)
838  {
839  $this->selfassessmenteditingmode = $a_selfassessmenteditingmode;
840  }
841 
848  {
849  return $this->selfassessmenteditingmode;
850  }
851 
857  function setPreventRteUsage($a_val)
858  {
859  $this->prevent_rte_usage = $a_val;
860  }
861 
868  {
870  }
871 
877  function setDefaultNrOfTries($a_defaultnroftries)
878  {
879  $this->defaultnroftries = $a_defaultnroftries;
880  }
881 
888  {
889  return $this->defaultnroftries;
890  }
891 
896  {
897  //if (!$this->getSelfAssessmentEditingMode() && !$_GET["calling_test"]) $form->addCommandButton("saveEdit", $this->lng->txt("save_edit"));
898  if(!$this->getSelfAssessmentEditingMode())
899  {
900  $form->addCommandButton("saveReturn", $this->lng->txt("save_return"));
901  }
902  $form->addCommandButton("save", $this->lng->txt("save"));
903  }
904 
912  {
913  // title
914  $title = new ilTextInputGUI($this->lng->txt("title"), "title");
915  $title->setValue($this->object->getTitle());
916  $title->setRequired(TRUE);
917  $form->addItem($title);
918 
919  if (!$this->getSelfAssessmentEditingMode())
920  {
921  // author
922  $author = new ilTextInputGUI($this->lng->txt("author"), "author");
923  $author->setValue($this->object->getAuthor());
924  $author->setRequired(TRUE);
925  $form->addItem($author);
926 
927  // description
928  $description = new ilTextInputGUI($this->lng->txt("description"), "comment");
929  $description->setValue($this->object->getComment());
930  $description->setRequired(FALSE);
931  $form->addItem($description);
932  }
933  else
934  {
935  // author as hidden field
936  $hi = new ilHiddenInputGUI("author");
937  $author = ilUtil::prepareFormOutput($this->object->getAuthor());
938  if (trim($author) == "")
939  {
940  $author = "-";
941  }
942  $hi->setValue($author);
943  $form->addItem($hi);
944 
945  }
946 
947  // questiontext
948  $question = new ilTextAreaInputGUI($this->lng->txt("question"), "question");
949  $question->setValue($this->object->prepareTextareaOutput($this->object->getQuestion()));
950  $question->setRequired(TRUE);
951  $question->setRows(10);
952  $question->setCols(80);
953  if (!$this->getSelfAssessmentEditingMode())
954  {
955  $question->setUseRte(TRUE);
956  include_once "./Services/AdvancedEditing/classes/class.ilObjAdvancedEditing.php";
957  $question->setRteTags(ilObjAdvancedEditing::_getUsedHTMLTags("assessment"));
958  $question->addPlugin("latex");
959  $question->addButton("latex");
960  $question->addButton("pastelatex");
961  $question->setRTESupport($this->object->getId(), "qpl", "assessment", null, false, '3.4.7');
962  }
963  else
964  {
965  $question->setRteTags(self::getSelfAssessmentTags());
966  $question->setUseTagsForRteOnly(false);
967  }
968  $form->addItem($question);
969 
970  if (!$this->getSelfAssessmentEditingMode())
971  {
972  // duration
973  $duration = new ilDurationInputGUI($this->lng->txt("working_time"), "Estimated");
974  $duration->setShowHours(TRUE);
975  $duration->setShowMinutes(TRUE);
976  $duration->setShowSeconds(TRUE);
977  $ewt = $this->object->getEstimatedWorkingTime();
978  $duration->setHours($ewt["h"]);
979  $duration->setMinutes($ewt["m"]);
980  $duration->setSeconds($ewt["s"]);
981  $duration->setRequired(FALSE);
982  $form->addItem($duration);
983  }
984  else
985  {
986  // number of tries
987  if (strlen($this->object->getNrOfTries()))
988  {
989  $nr_tries = $this->object->getNrOfTries();
990  }
991  else
992  {
993  $nr_tries = $this->getDefaultNrOfTries();
994  }
995  /*if ($nr_tries <= 0)
996  {
997  $nr_tries = 1;
998  }*/
999 
1000  if ($nr_tries < 0)
1001  {
1002  $nr_tries = 0;
1003  }
1004 
1005  $ni = new ilNumberInputGUI($this->lng->txt("qst_nr_of_tries"), "nr_of_tries");
1006  $ni->setValue($nr_tries);
1007  //$ni->setMinValue(1);
1008  $ni->setMinValue(0);
1009  $ni->setSize(5);
1010  $ni->setMaxLength(5);
1011  $ni->setRequired(true);
1012  $form->addItem($ni);
1013  }
1014  }
1015 
1021  {
1022  // set tags we allow in self assessment mode
1023  $st = ilUtil::getSecureTags();
1024 
1025  // we allow these tags, since they are typically used in the Tiny Assessment editor
1026  // and should not be deleted, if questions are copied from pools to learning modules
1027  $not_supported = array("img", "p");
1028  $tags = array();
1029  foreach ($st as $s)
1030  {
1031  if (!in_array($s, $not_supported))
1032  {
1033  $tags[] = $s;
1034  }
1035  }
1036 
1037  return $tags;
1038  }
1039 
1040 
1050  function getAnswerFeedbackOutput($active_id, $pass)
1051  {
1052  $output = "";
1053  include_once "./Modules/Test/classes/class.ilObjTest.php";
1054  $manual_feedback = ilObjTest::getManualFeedback($active_id, $this->object->getId(), $pass);
1055  if (strlen($manual_feedback))
1056  {
1057  return $manual_feedback;
1058  }
1059  $correct_feedback = $this->object->getFeedbackGeneric(1);
1060  $incorrect_feedback = $this->object->getFeedbackGeneric(0);
1061  if (strlen($correct_feedback.$incorrect_feedback))
1062  {
1063  $reached_points = $this->object->calculateReachedPoints($active_id, $pass);
1064  $max_points = $this->object->getMaximumPoints();
1065  if ($reached_points == $max_points)
1066  {
1067  $output = $correct_feedback;
1068  }
1069  else
1070  {
1071  $output = $incorrect_feedback;
1072  }
1073  }
1074  return $this->object->prepareTextareaOutput($output, TRUE);
1075  }
1076 
1086  function getGenericFeedbackOutput($active_id, $pass)
1087  {
1088  $output = "";
1089  include_once "./Modules/Test/classes/class.ilObjTest.php";
1090  $manual_feedback = ilObjTest::getManualFeedback($active_id, $this->object->getId(), $pass);
1091  if (strlen($manual_feedback))
1092  {
1093  return $manual_feedback;
1094  }
1095  $correct_feedback = $this->object->getFeedbackGeneric(1);
1096  $incorrect_feedback = $this->object->getFeedbackGeneric(0);
1097  if (strlen($correct_feedback.$incorrect_feedback))
1098  {
1099  $reached_points = $this->object->calculateReachedPoints($active_id, $pass);
1100  $max_points = $this->object->getMaximumPoints();
1101  if ($reached_points == $max_points)
1102  {
1103  $output = $correct_feedback;
1104  }
1105  else
1106  {
1107  $output = $incorrect_feedback;
1108  }
1109  }
1110  return $this->object->prepareTextareaOutput($output, TRUE);
1111  }
1112 
1124  abstract function getSpecificFeedbackOutput($active_id, $pass);
1125 
1131  function feedback($checkonly = false)
1132  {
1133  $save = (strcmp($this->ctrl->getCmd(), "saveFeedback") == 0) ? TRUE : FALSE;
1134  include_once("./Services/Form/classes/class.ilPropertyFormGUI.php");
1135  $form = new ilPropertyFormGUI();
1136  $form->setFormAction($this->ctrl->getFormAction($this));
1137  $form->setTitle($this->lng->txt('feedback_answers'));
1138  $form->setTableWidth("100%");
1139  $form->setId("feedback");
1140 
1141  $complete = new ilTextAreaInputGUI($this->lng->txt("feedback_complete_solution"), "feedback_complete");
1142  $complete->setValue($this->object->prepareTextareaOutput($this->object->getFeedbackGeneric(1)));
1143  $complete->setRequired(false);
1144  $complete->setRows(10);
1145  $complete->setCols(80);
1146  if (!$this->getPreventRteUsage())
1147  {
1148  $complete->setUseRte(true);
1149  }
1150  include_once "./Services/AdvancedEditing/classes/class.ilObjAdvancedEditing.php";
1151  $complete->setRteTags(ilObjAdvancedEditing::_getUsedHTMLTags("assessment"));
1152  $complete->addPlugin("latex");
1153  $complete->addButton("latex");
1154  $complete->addButton("pastelatex");
1155  $complete->setRTESupport($this->object->getId(), "qpl", "assessment", null, false, '3.4.7');
1156  $form->addItem($complete);
1157 
1158  $incomplete = new ilTextAreaInputGUI($this->lng->txt("feedback_incomplete_solution"), "feedback_incomplete");
1159  $incomplete->setValue($this->object->prepareTextareaOutput($this->object->getFeedbackGeneric(0)));
1160  $incomplete->setRequired(false);
1161  $incomplete->setRows(10);
1162  $incomplete->setCols(80);
1163  if (!$this->getPreventRteUsage())
1164  {
1165  $incomplete->setUseRte(true);
1166  }
1167  include_once "./Services/AdvancedEditing/classes/class.ilObjAdvancedEditing.php";
1168  $incomplete->setRteTags(ilObjAdvancedEditing::_getUsedHTMLTags("assessment"));
1169  $incomplete->addPlugin("latex");
1170  $incomplete->addButton("latex");
1171  $incomplete->addButton("pastelatex");
1172  $incomplete->setRTESupport($this->object->getId(), "qpl", "assessment", null, false, '3.4.7');
1173  $form->addItem($incomplete);
1174 
1175  global $ilAccess;
1176  if ($ilAccess->checkAccess("write", "", $_GET['ref_id']) || $this->getSelfAssessmentEditingMode())
1177  {
1178  $form->addCommandButton("saveFeedback", $this->lng->txt("save"));
1179  }
1180 
1181  if ($save)
1182  {
1183  $form->setValuesByPost();
1184  $errors = !$form->checkInput();
1185  $form->setValuesByPost(); // again, because checkInput now performs the whole stripSlashes handling and we need this if we don't want to have duplication of backslashes
1186  }
1187  if (!$checkonly) $this->tpl->setVariable("ADM_CONTENT", $form->getHTML());
1188  return $errors;
1189  }
1190 
1191  public function outQuestionType()
1192  {
1193  include_once "./Services/UICore/classes/class.ilTemplate.php";
1194  $template = new ilTemplate("tpl.il_as_qpl_questiontype.html", TRUE, TRUE, "Modules/TestQuestionPool");
1195  $count = $this->object->isInUse();
1196  if (assQuestion::_questionExistsInPool($this->object->getId()) && $count)
1197  {
1198  global $rbacsystem;
1199  if ($rbacsystem->checkAccess("write", $_GET["ref_id"]))
1200  {
1201  $template->setCurrentBlock("infosign");
1202  $template->setVariable("INFO_IMG_SRC", ilUtil::getImagePath("messagebox_tip.png"));
1203  $template->setVariable("INFO_IMG_ALT", sprintf($this->lng->txt("qpl_question_is_in_use"), $count));
1204  $template->setVariable("INFO_IMG_TITLE", sprintf($this->lng->txt("qpl_question_is_in_use"), $count));
1205  $template->parseCurrentBlock();
1206  }
1207  }
1208  $template->setVariable("TEXT_QUESTION_TYPE", assQuestion::_getQuestionTypeName($this->object->getQuestionType()));
1209  return $template->get();
1210  }
1211 
1217  public function suggestedsolution()
1218  {
1219  global $ilUser;
1220  global $ilAccess;
1221 
1222  if ($_POST["deleteSuggestedSolution"] == 1)
1223  {
1224  $this->object->deleteSuggestedSolutions();
1225  ilUtil::sendSuccess($this->lng->txt("msg_obj_modified"), true);
1226  $this->ctrl->redirect($this, "suggestedsolution");
1227  }
1228 
1229  $save = (is_array($_POST["cmd"]) && array_key_exists("suggestedsolution", $_POST["cmd"])) ? TRUE : FALSE;
1230  $output = "";
1231  $solution_array = $this->object->getSuggestedSolution(0);
1232  $options = array(
1233  "lm" => $this->lng->txt("obj_lm"),
1234  "st" => $this->lng->txt("obj_st"),
1235  "pg" => $this->lng->txt("obj_pg"),
1236  "git" => $this->lng->txt("glossary_term"),
1237  "file" => $this->lng->txt("fileDownload"),
1238  "text" => $this->lng->txt("solutionText")
1239  );
1240 
1241  if ((strcmp($_POST["solutiontype"], "file") == 0) && (strcmp($solution_array["type"], "file") != 0))
1242  {
1243  $solution_array = array(
1244  "type" => "file"
1245  );
1246  }
1247  elseif ((strcmp($_POST["solutiontype"], "text") == 0) && (strcmp($solution_array["type"], "text") != 0))
1248  {
1249  $solution_array = array(
1250  "type" => "text",
1251  "value" => $this->getSolutionOutput(0, NULL, FALSE, FALSE, TRUE, FALSE, TRUE)
1252  );
1253  }
1254  if ($save && strlen($_POST["filename"]))
1255  {
1256  $solution_array["value"]["filename"] = $_POST["filename"];
1257  }
1258  if ($save && strlen($_POST["solutiontext"]))
1259  {
1260  $solution_array["value"] = $_POST["solutiontext"];
1261  }
1262  include_once("./Services/Form/classes/class.ilPropertyFormGUI.php");
1263  if (count($solution_array))
1264  {
1265  $form = new ilPropertyFormGUI();
1266  $form->setFormAction($this->ctrl->getFormAction($this));
1267  $form->setTitle($this->lng->txt("solution_hint"));
1268  $form->setMultipart(TRUE);
1269  $form->setTableWidth("100%");
1270  $form->setId("suggestedsolutiondisplay");
1271 
1272  // suggested solution output
1273  include_once "./Modules/TestQuestionPool/classes/class.ilSolutionTitleInputGUI.php";
1274  $title = new ilSolutionTitleInputGUI($this->lng->txt("showSuggestedSolution"), "solutiontype");
1275  $template = new ilTemplate("tpl.il_as_qpl_suggested_solution_input_presentation.html", TRUE, TRUE, "Modules/TestQuestionPool");
1276  if (strlen($solution_array["internal_link"]))
1277  {
1278  $href = assQuestion::_getInternalLinkHref($solution_array["internal_link"]);
1279  $template->setCurrentBlock("preview");
1280  $template->setVariable("TEXT_SOLUTION", $this->lng->txt("solution_hint"));
1281  $template->setVariable("VALUE_SOLUTION", " <a href=\"$href\" target=\"content\">" . $this->lng->txt("view"). "</a> ");
1282  $template->parseCurrentBlock();
1283  }
1284  elseif ((strcmp($solution_array["type"], "file") == 0) && (is_array($solution_array["value"])))
1285  {
1286  $href = $this->object->getSuggestedSolutionPathWeb() . $solution_array["value"]["name"];
1287  $template->setCurrentBlock("preview");
1288  $template->setVariable("TEXT_SOLUTION", $this->lng->txt("solution_hint"));
1289  $template->setVariable("VALUE_SOLUTION", " <a href=\"$href\" target=\"content\">" . ilUtil::prepareFormOutput((strlen($solution_array["value"]["filename"])) ? $solution_array["value"]["filename"] : $solution_array["value"]["name"]). "</a> ");
1290  $template->parseCurrentBlock();
1291  }
1292  $template->setVariable("TEXT_TYPE", $this->lng->txt("type"));
1293  $template->setVariable("VALUE_TYPE", $options[$solution_array["type"]]);
1294  $title->setHtml($template->get());
1295  $deletesolution = new ilCheckboxInputGUI("", "deleteSuggestedSolution");
1296  $deletesolution->setOptionTitle($this->lng->txt("deleteSuggestedSolution"));
1297  $title->addSubItem($deletesolution);
1298  $form->addItem($title);
1299 
1300  if (strcmp($solution_array["type"], "file") == 0)
1301  {
1302  // file
1303  $file = new ilFileInputGUI($this->lng->txt("fileDownload"), "file");
1304  $file->setRequired(TRUE);
1305  $file->enableFileNameSelection("filename");
1306  //$file->setSuffixes(array("doc","xls","png","jpg","gif","pdf"));
1307  if( $_FILES["file"]["tmp_name"] && $file->checkInput() )
1308  {
1309  if (!file_exists($this->object->getSuggestedSolutionPath())) ilUtil::makeDirParents($this->object->getSuggestedSolutionPath());
1310 
1311  $res = ilUtil::moveUploadedFile($_FILES["file"]["tmp_name"], $_FILES["file"]["name"], $this->object->getSuggestedSolutionPath() . $_FILES["file"]["name"]);
1312  if ($res)
1313  {
1314  ilUtil::renameExecutables($this->object->getSuggestedSolutionPath());
1315 
1316  // remove an old file download
1317  if (is_array($solution_array["value"])) @unlink($this->object->getSuggestedSolutionPath() . $solution_array["value"]["name"]);
1318  $file->setValue($_FILES["file"]["name"]);
1319  $this->object->saveSuggestedSolution("file", "", 0, array("name" => $_FILES["file"]["name"], "type" => $_FILES["file"]["type"], "size" => $_FILES["file"]["size"], "filename" => $_POST["filename"]));
1320  $originalexists = $this->object->_questionExistsInPool($this->object->original_id);
1321  if ($_GET["calling_test"] && $originalexists && assQuestion::_isWriteable($this->object->original_id, $ilUser->getId()))
1322  {
1323  return $this->originalSyncForm("suggestedsolution");
1324  }
1325  else
1326  {
1327  ilUtil::sendSuccess($this->lng->txt("suggested_solution_added_successfully"), TRUE);
1328  $this->ctrl->redirect($this, "suggestedsolution");
1329  }
1330  }
1331  else
1332  {
1333  // BH: $res as info string? wtf? it holds a bool or something else!!?
1334  ilUtil::sendInfo($res);
1335  }
1336  }
1337  else
1338  {
1339  if (is_array($solution_array["value"]))
1340  {
1341  $file->setValue($solution_array["value"]["name"]);
1342  $file->setFilename((strlen($solution_array["value"]["filename"])) ? $solution_array["value"]["filename"] : $solution_array["value"]["name"]);
1343  }
1344  }
1345  $form->addItem($file);
1346  $hidden = new ilHiddenInputGUI("solutiontype");
1347  $hidden->setValue("file");
1348  $form->addItem($hidden);
1349  }
1350  else if (strcmp($solution_array["type"], "text") == 0)
1351  {
1352  $question = new ilTextAreaInputGUI($this->lng->txt("solutionText"), "solutiontext");
1353  $question->setValue($this->object->prepareTextareaOutput($solution_array["value"]));
1354  $question->setRequired(TRUE);
1355  $question->setRows(10);
1356  $question->setCols(80);
1357  $question->setUseRte(TRUE);
1358  $question->addPlugin("latex");
1359  $question->addButton("latex");
1360  $question->setRTESupport($this->object->getId(), "qpl", "assessment", null, false, '3.4.7');
1361  $hidden = new ilHiddenInputGUI("solutiontype");
1362  $hidden->setValue("text");
1363  $form->addItem($hidden);
1364  $form->addItem($question);
1365  }
1366  if ($ilAccess->checkAccess("write", "", $_GET['ref_id'])) $form->addCommandButton("suggestedsolution", $this->lng->txt("save"));
1367 
1368  if ($save)
1369  {
1370  if ($form->checkInput())
1371  {
1372  switch ($solution_array["type"])
1373  {
1374  case "file":
1375  $this->object->saveSuggestedSolution("file", "", 0, array("name" => $solution_array["value"]["name"], "type" => $solution_array["value"]["type"], "size" => $solution_array["value"]["size"], "filename" => $_POST["filename"]));
1376  break;
1377  case "text":
1378  $this->object->saveSuggestedSolution("text", "", 0, $solution_array["value"]);
1379  break;
1380  }
1381  $originalexists = $this->object->_questionExistsInPool($this->object->original_id);
1382  if ($_GET["calling_test"] && $originalexists && assQuestion::_isWriteable($this->object->original_id, $ilUser->getId()))
1383  {
1384  return $this->originalSyncForm("suggestedsolution");
1385  }
1386  else
1387  {
1388  ilUtil::sendSuccess($this->lng->txt("msg_obj_modified"), true);
1389  $this->ctrl->redirect($this, "suggestedsolution");
1390  }
1391  }
1392  }
1393  $output = $form->getHTML();
1394  }
1395 
1396  $savechange = (strcmp($this->ctrl->getCmd(), "saveSuggestedSolution") == 0) ? TRUE : FALSE;
1397 
1398  $changeoutput = "";
1399  if ($ilAccess->checkAccess("write", "", $_GET['ref_id']))
1400  {
1401  $formchange = new ilPropertyFormGUI();
1402  $formchange->setFormAction($this->ctrl->getFormAction($this));
1403  $formchange->setTitle((count($solution_array)) ? $this->lng->txt("changeSuggestedSolution") : $this->lng->txt("addSuggestedSolution"));
1404  $formchange->setMultipart(FALSE);
1405  $formchange->setTableWidth("100%");
1406  $formchange->setId("suggestedsolution");
1407 
1408  $solutiontype = new ilRadioMatrixInputGUI($this->lng->txt("suggestedSolutionType"), "solutiontype");
1409  $solutiontype->setOptions($options);
1410  if (count($solution_array))
1411  {
1412  $solutiontype->setValue($solution_array["type"]);
1413  }
1414  $solutiontype->setRequired(TRUE);
1415  $formchange->addItem($solutiontype);
1416 
1417  $formchange->addCommandButton("saveSuggestedSolution", $this->lng->txt("select"));
1418 
1419  if ($savechange)
1420  {
1421  $formchange->checkInput();
1422  }
1423  $changeoutput = $formchange->getHTML();
1424  }
1425 
1426  $this->tpl->setVariable("ADM_CONTENT", $changeoutput . $output);
1427  }
1428 
1429  public function outSolutionExplorer()
1430  {
1431  global $tree;
1432 
1433  include_once("./Modules/TestQuestionPool/classes/class.ilSolutionExplorer.php");
1434  $type = $_GET["link_new_type"];
1435  $search = $_GET["search_link_type"];
1436  $this->ctrl->setParameter($this, "link_new_type", $type);
1437  $this->ctrl->setParameter($this, "search_link_type", $search);
1438  $this->ctrl->saveParameter($this, array("subquestion_index", "link_new_type", "search_link_type"));
1439 
1440  ilUtil::sendInfo($this->lng->txt("select_object_to_link"));
1441 
1442  $parent_ref_id = $tree->getParentId($_GET["ref_id"]);
1443  $exp = new ilSolutionExplorer($this->ctrl->getLinkTarget($this, 'suggestedsolution'), get_class($this));
1444  $exp->setExpand($_GET['expand_sol'] ? $_GET['expand_sol'] : $parent_ref_id);
1445  $exp->setExpandTarget($this->ctrl->getLinkTarget($this, 'outSolutionExplorer'));
1446  $exp->setTargetGet("ref_id");
1447  $exp->setRefId($_GET["ref_id"]);
1448  $exp->addFilter($type);
1449  $exp->setSelectableType($type);
1450  if(isset($_GET['expandCurrentPath']) && $_GET['expandCurrentPath'])
1451  {
1452  $exp->expandPathByRefId($parent_ref_id);
1453  }
1454 
1455  // build html-output
1456  $exp->setOutput(0);
1457 
1458  $template = new ilTemplate("tpl.il_as_qpl_explorer.html", TRUE, TRUE, "Modules/TestQuestionPool");
1459  $template->setVariable("EXPLORER_TREE",$exp->getOutput());
1460  $template->setVariable("BUTTON_CANCEL",$this->lng->txt("cancel"));
1461  $template->setVariable("FORMACTION",$this->ctrl->getFormAction($this, "suggestedsolution"));
1462  $this->tpl->setVariable("ADM_CONTENT", $template->get());
1463  }
1464 
1465  public function saveSuggestedSolution()
1466  {
1467  global $tree;
1468 
1469  include_once("./Modules/TestQuestionPool/classes/class.ilSolutionExplorer.php");
1470  switch ($_POST["solutiontype"])
1471  {
1472  case "lm":
1473  $type = "lm";
1474  $search = "lm";
1475  break;
1476  case "git":
1477  $type = "glo";
1478  $search = "glo";
1479  break;
1480  case "st":
1481  $type = "lm";
1482  $search = "st";
1483  break;
1484  case "pg":
1485  $type = "lm";
1486  $search = "pg";
1487  break;
1488  case "file":
1489  case "text":
1490  return $this->suggestedsolution();
1491  break;
1492  default:
1493  return $this->suggestedsolution();
1494  break;
1495  }
1496  if(isset($_POST['solutiontype']))
1497  {
1498  $this->ctrl->setParameter($this, 'expandCurrentPath', 1);
1499  }
1500  $this->ctrl->setParameter($this, "link_new_type", $type);
1501  $this->ctrl->setParameter($this, "search_link_type", $search);
1502  $this->ctrl->redirect($this, "outSolutionExplorer");
1503  }
1504 
1505  function cancelExplorer()
1506  {
1507  $this->ctrl->redirect($this, "suggestedsolution");
1508  }
1509 
1510  function outPageSelector()
1511  {
1512  include_once "./Modules/LearningModule/classes/class.ilLMPageObject.php";
1513  include_once("./Modules/LearningModule/classes/class.ilObjContentObjectGUI.php");
1514  $cont_obj_gui =& new ilObjContentObjectGUI("", $_GET["source_id"], true);
1515  $cont_obj = $cont_obj_gui->object;
1516  $pages = ilLMPageObject::getPageList($cont_obj->getId());
1517  $shownpages = array();
1518  $tree = $cont_obj->getLMTree();
1519  $chapters = $tree->getSubtree($tree->getNodeData($tree->getRootId()));
1520  $this->ctrl->setParameter($this, "q_id", $this->object->getId());
1521  $color_class = array("tblrow1", "tblrow2");
1522  $counter = 0;
1523  $template = new ilTemplate("tpl.il_as_qpl_internallink_selection.html", TRUE, TRUE, "Modules/TestQuestionPool");
1524  foreach ($chapters as $chapter)
1525  {
1526  $chapterpages = $tree->getChildsByType($chapter["obj_id"], "pg");
1527  foreach ($chapterpages as $page)
1528  {
1529  if($page["type"] == $_GET["search_link_type"])
1530  {
1531  array_push($shownpages, $page["obj_id"]);
1532  $template->setCurrentBlock("linktable_row");
1533  $template->setVariable("TEXT_LINK", $page["title"]);
1534  $template->setVariable("TEXT_ADD", $this->lng->txt("add"));
1535  $template->setVariable("LINK_HREF", $this->ctrl->getLinkTargetByClass(get_class($this), "add" . strtoupper($page["type"])) . "&" . $page["type"] . "=" . $page["obj_id"]);
1536  $template->setVariable("COLOR_CLASS", $color_class[$counter % 2]);
1537  if ($tree->isInTree($page["obj_id"]))
1538  {
1539  $path_str = $this->getContextPath($cont_obj, $page["obj_id"]);
1540  }
1541  else
1542  {
1543  $path_str = "---";
1544  }
1545  $template->setVariable("TEXT_DESCRIPTION", ilUtil::prepareFormOutput($path_str));
1546  $template->parseCurrentBlock();
1547  $counter++;
1548  }
1549  }
1550  }
1551  foreach ($pages as $page)
1552  {
1553  if (!in_array($page["obj_id"], $shownpages))
1554  {
1555  $template->setCurrentBlock("linktable_row");
1556  $template->setVariable("TEXT_LINK", $page["title"]);
1557  $template->setVariable("TEXT_ADD", $this->lng->txt("add"));
1558  $template->setVariable("LINK_HREF", $this->ctrl->getLinkTargetByClass(get_class($this), "add" . strtoupper($page["type"])) . "&" . $page["type"] . "=" . $page["obj_id"]);
1559  $template->setVariable("COLOR_CLASS", $color_class[$counter % 2]);
1560  $path_str = "---";
1561  $template->setVariable("TEXT_DESCRIPTION", ilUtil::prepareFormOutput($path_str));
1562  $template->parseCurrentBlock();
1563  $counter++;
1564  }
1565  }
1566  $template->setCurrentBlock("link_selection");
1567  $template->setVariable("BUTTON_CANCEL",$this->lng->txt("cancel"));
1568  $template->setVariable("TEXT_LINK_TYPE", $this->lng->txt("obj_" . $_GET["search_link_type"]));
1569  $template->setVariable("FORMACTION",$this->ctrl->getFormAction($this, "cancelExplorer"));
1570  $template->parseCurrentBlock();
1571  $this->tpl->setVariable("ADM_CONTENT", $template->get());
1572  }
1573 
1574  public function outChapterSelector()
1575  {
1576  $template = new ilTemplate("tpl.il_as_qpl_internallink_selection.html", TRUE, TRUE, "Modules/TestQuestionPool");
1577  $this->ctrl->setParameter($this, "q_id", $this->object->getId());
1578  $color_class = array("tblrow1", "tblrow2");
1579  $counter = 0;
1580  include_once("./Modules/LearningModule/classes/class.ilObjContentObjectGUI.php");
1581  $cont_obj_gui =& new ilObjContentObjectGUI("", $_GET["source_id"], true);
1582  $cont_obj = $cont_obj_gui->object;
1583  // get all chapters
1584  $ctree =& $cont_obj->getLMTree();
1585  $nodes = $ctree->getSubtree($ctree->getNodeData($ctree->getRootId()));
1586  foreach($nodes as $node)
1587  {
1588  if($node["type"] == $_GET["search_link_type"])
1589  {
1590  $template->setCurrentBlock("linktable_row");
1591  $template->setVariable("TEXT_LINK", $node["title"]);
1592  $template->setVariable("TEXT_ADD", $this->lng->txt("add"));
1593  $template->setVariable("LINK_HREF", $this->ctrl->getLinkTargetByClass(get_class($this), "add" . strtoupper($node["type"])) . "&" . $node["type"] . "=" . $node["obj_id"]);
1594  $template->setVariable("COLOR_CLASS", $color_class[$counter % 2]);
1595  $template->parseCurrentBlock();
1596  $counter++;
1597  }
1598  }
1599  $template->setCurrentBlock("link_selection");
1600  $template->setVariable("BUTTON_CANCEL",$this->lng->txt("cancel"));
1601  $template->setVariable("TEXT_LINK_TYPE", $this->lng->txt("obj_" . $_GET["search_link_type"]));
1602  $template->setVariable("FORMACTION",$this->ctrl->getFormAction($this, "cancelExplorer"));
1603  $template->parseCurrentBlock();
1604  $this->tpl->setVariable("ADM_CONTENT", $template->get());
1605  }
1606 
1607  public function outGlossarySelector()
1608  {
1609  $template = new ilTemplate("tpl.il_as_qpl_internallink_selection.html", TRUE, TRUE, "Modules/TestQuestionPool");
1610  $this->ctrl->setParameter($this, "q_id", $this->object->getId());
1611  $color_class = array("tblrow1", "tblrow2");
1612  $counter = 0;
1613  include_once "./Modules/Glossary/classes/class.ilObjGlossary.php";
1614  $glossary =& new ilObjGlossary($_GET["source_id"], true);
1615  // get all glossary items
1616  $terms = $glossary->getTermList();
1617  foreach($terms as $term)
1618  {
1619  $template->setCurrentBlock("linktable_row");
1620  $template->setVariable("TEXT_LINK", $term["term"]);
1621  $template->setVariable("TEXT_ADD", $this->lng->txt("add"));
1622  $template->setVariable("LINK_HREF", $this->ctrl->getLinkTargetByClass(get_class($this), "addGIT") . "&git=" . $term["id"]);
1623  $template->setVariable("COLOR_CLASS", $color_class[$counter % 2]);
1624  $template->parseCurrentBlock();
1625  $counter++;
1626  }
1627  $template->setCurrentBlock("link_selection");
1628  $template->setVariable("BUTTON_CANCEL",$this->lng->txt("cancel"));
1629  $template->setVariable("TEXT_LINK_TYPE", $this->lng->txt("glossary_term"));
1630  $template->setVariable("FORMACTION",$this->ctrl->getFormAction($this, "cancelExplorer"));
1631  $template->parseCurrentBlock();
1632  $this->tpl->setVariable("ADM_CONTENT", $template->get());
1633  }
1634 
1635  function linkChilds()
1636  {
1637  $this->ctrl->saveParameter($this, array("subquestion_index", "link_new_type", "search_link_type"));
1638  switch ($_GET["search_link_type"])
1639  {
1640  case "pg":
1641  return $this->outPageSelector();
1642  break;
1643  case "st":
1644  return $this->outChapterSelector();
1645  break;
1646  case "glo":
1647  return $this->outGlossarySelector();
1648  break;
1649  case "lm":
1650  $subquestion_index = ($_GET["subquestion_index"] > 0) ? $_GET["subquestion_index"] : 0;
1651  $this->object->saveSuggestedSolution("lm", "il__lm_" . $_GET["source_id"], $subquestion_index);
1652  ilUtil::sendSuccess($this->lng->txt("suggested_solution_added_successfully"), TRUE);
1653  $this->ctrl->redirect($this, "suggestedsolution");
1654  break;
1655  }
1656  }
1657 
1658  function addPG()
1659  {
1660  $subquestion_index = 0;
1661  if (strlen($_GET["subquestion_index"]) && $_GET["subquestion_index"] >= 0)
1662  {
1663  $subquestion_index = $_GET["subquestion_index"];
1664  }
1665  $this->object->saveSuggestedSolution("pg", "il__pg_" . $_GET["pg"], $subquestion_index);
1666  ilUtil::sendSuccess($this->lng->txt("suggested_solution_added_successfully"), TRUE);
1667  $this->ctrl->redirect($this, "suggestedsolution");
1668  }
1669 
1670  function addST()
1671  {
1672  $subquestion_index = 0;
1673  if (strlen($_GET["subquestion_index"]) && $_GET["subquestion_index"] >= 0)
1674  {
1675  $subquestion_index = $_GET["subquestion_index"];
1676  }
1677  $this->object->saveSuggestedSolution("st", "il__st_" . $_GET["st"], $subquestion_index);
1678  ilUtil::sendSuccess($this->lng->txt("suggested_solution_added_successfully"), TRUE);
1679  $this->ctrl->redirect($this, "suggestedsolution");
1680  }
1681 
1682  function addGIT()
1683  {
1684  $subquestion_index = 0;
1685  if (strlen($_GET["subquestion_index"]) && $_GET["subquestion_index"] >= 0)
1686  {
1687  $subquestion_index = $_GET["subquestion_index"];
1688  }
1689  $this->object->saveSuggestedSolution("git", "il__git_" . $_GET["git"], $subquestion_index);
1690  ilUtil::sendSuccess($this->lng->txt("suggested_solution_added_successfully"), TRUE);
1691  $this->ctrl->redirect($this, "suggestedsolution");
1692  }
1693 
1694  function isSaveCommand()
1695  {
1696  return in_array($this->ctrl->getCmd(), array('save', 'saveEdit', 'saveReturn'));
1697  }
1698 
1699  public function setQuestionTabs()
1700  {
1701  }
1702 
1709  protected function addTab_QuestionHints(ilTabsGUI $tabs)
1710  {
1711  global $ilCtrl;
1712 
1713  require_once 'Modules/TestQuestionPool/classes/class.ilAssQuestionHintsGUI.php';
1714 
1715  $reflectionClass = null;
1716 
1717  switch( $ilCtrl->getCmdClass() )
1718  {
1719  case 'ilassquestionhintsgui':
1720 
1721  $reflectionClass = new ReflectionClass('ilAssQuestionHintsGUI');
1722  break;
1723 
1724  case 'ilassquestionhintgui':
1725 
1726  require_once 'Modules/TestQuestionPool/classes/class.ilAssQuestionHintGUI.php';
1727  $reflectionClass = new ReflectionClass('ilAssQuestionHintGUI');
1728  break;
1729  }
1730 
1731  $tabCommands = array();
1732 
1733  if( $reflectionClass instanceof ReflectionClass )
1734  foreach($reflectionClass->getConstants() as $constName => $constValue)
1735  if( substr($constName, 0, strlen('CMD_')) == 'CMD_' ) $tabCommands[] = $constValue;
1736 
1737  $tabLink = $ilCtrl->getLinkTargetByClass('ilAssQuestionHintsGUI', ilAssQuestionHintsGUI::CMD_SHOW_LIST);
1738 
1739  $tabs->addTarget('tst_question_hints_tab', $tabLink, $tabCommands, $ilCtrl->getCmdClass(), '');
1740  }
1741 
1742  abstract public function getSolutionOutput(
1743  $active_id,
1744  $pass = NULL,
1745  $graphicalOutput = FALSE,
1746  $result_output = FALSE,
1747  $show_question_only = TRUE,
1748  $show_feedback = FALSE,
1749  $show_correct_solution = FALSE,
1750  $show_manual_scoring = FALSE,
1751  $show_question_text = TRUE
1752  );
1753 
1754  public function isAutosaveable()
1755  {
1756  return $this->object->isAutosaveable();
1757  }
1758 
1759  public function showHints()
1760  {
1761  global $ilCtrl;
1762 
1763  $ilCtrl->redirectByClass('ilAssQuestionHintsGUI', ilAssQuestionHintsGUI::CMD_SHOW_LIST);
1764  }
1765 }