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