ILIAS  Release_4_1_x_branch Revision 61804
 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 
37 {
45  var $object;
46 
47  var $tpl;
48  var $lng;
49  var $error;
51 
60 
64  var $prevent_rte_usage = false;
65 
69  function __construct()
70  {
71  global $lng, $tpl, $ilCtrl;
72 
73 
74  $this->lng =& $lng;
75  $this->tpl =& $tpl;
76  $this->ctrl =& $ilCtrl;
77  $this->ctrl->saveParameter($this, "q_id");
78 
79  include_once "./Modules/TestQuestionPool/classes/class.assQuestion.php";
80  $this->errormessage = $this->lng->txt("fill_out_all_required_fields");
81 
82  $this->selfassessmenteditingmode = false;
83  $this->new_id_listeners = array();
84  $this->new_id_listener_cnt = 0;
85  }
86 
90  function &executeCommand()
91  {
92  $cmd = $this->ctrl->getCmd("editQuestion");
93  $next_class = $this->ctrl->getNextClass($this);
94 
95  $cmd = $this->getCommand($cmd);
96 
97  switch($next_class)
98  {
99  default:
100  $ret =& $this->$cmd();
101  break;
102  }
103  return $ret;
104  }
105 
106  function getCommand($cmd)
107  {
108  return $cmd;
109  }
110 
114  function getType()
115  {
116  return $this->getQuestionType();
117  }
118 
125  function writePostData()
126  {
127  }
128 
132  function assessment()
133  {
134  $this->tpl->addBlockFile("CONTENT", "content", "tpl.il_as_qpl_content.html", "Modules/TestQuestionPool");
135  $this->tpl->addBlockFile("STATUSLINE", "statusline", "tpl.statusline.html");
136 
137  $total_of_answers = $this->object->getTotalAnswers();
138  $counter = 0;
139  $color_class = array("tblrow1", "tblrow2");
140  $this->tpl->addBlockFile("ADM_CONTENT", "adm_content", "tpl.il_as_qpl_assessment_of_questions.html", "Modules/TestQuestionPool");
141  if (!$total_of_answers)
142  {
143  $this->tpl->setCurrentBlock("emptyrow");
144  $this->tpl->setVariable("TXT_NO_ASSESSMENT", $this->lng->txt("qpl_assessment_no_assessment_of_questions"));
145  $this->tpl->setVariable("COLOR_CLASS", $color_class[$counter % 2]);
146  $this->tpl->parseCurrentBlock();
147  }
148  else
149  {
150  $this->tpl->setCurrentBlock("row");
151  $this->tpl->setVariable("TXT_RESULT", $this->lng->txt("qpl_assessment_total_of_answers"));
152  $this->tpl->setVariable("TXT_VALUE", $total_of_answers);
153  $this->tpl->setVariable("COLOR_CLASS", $color_class[$counter % 2]);
154  $counter++;
155  $this->tpl->parseCurrentBlock();
156  $this->tpl->setCurrentBlock("row");
157  $this->tpl->setVariable("TXT_RESULT", $this->lng->txt("qpl_assessment_total_of_right_answers"));
158  $this->tpl->setVariable("TXT_VALUE", sprintf("%2.2f", $this->object->_getTotalRightAnswers($_GET["q_id"]) * 100.0) . " %");
159  $this->tpl->setVariable("COLOR_CLASS", $color_class[$counter % 2]);
160  $this->tpl->parseCurrentBlock();
161  }
162 
163  $instances =& $this->object->getInstances();
164  $counter = 0;
165  foreach ($instances as $instance)
166  {
167  if (is_array($instance["refs"]))
168  {
169  foreach ($instance["refs"] as $ref_id)
170  {
171  $this->tpl->setCurrentBlock("references");
172  $this->tpl->setVariable("GOTO", "./goto.php?target=tst_" . $ref_id);
173  $this->tpl->setVariable("TEXT_GOTO", $this->lng->txt("perma_link"));
174  $this->tpl->parseCurrentBlock();
175  }
176  }
177  $this->tpl->setCurrentBlock("instance_row");
178  $this->tpl->setVariable("TEST_TITLE", $instance["title"]);
179  $this->tpl->setVariable("TEST_AUTHOR", $instance["author"]);
180  $this->tpl->setVariable("QUESTION_ID", $instance["question_id"]);
181  $this->tpl->setVariable("COLOR_CLASS", $color_class[$counter % 2]);
182  $counter++;
183  $this->tpl->parseCurrentBlock();
184  }
185  $this->tpl->setCurrentBlock("instances");
186  $this->tpl->setVariable("TEXT_TEST_TITLE", $this->lng->txt("title"));
187  $this->tpl->setVariable("TEXT_TEST_AUTHOR", $this->lng->txt("author"));
188  $this->tpl->setVariable("TEXT_TEST_LOCATION", $this->lng->txt("location"));
189  $this->tpl->setVariable("INSTANCES_TITLE", $this->lng->txt("question_instances_title"));
190  $this->tpl->parseCurrentBlock();
191 
192  $this->tpl->setCurrentBlock("adm_content");
193  $this->tpl->setVariable("TXT_QUESTION_TITLE", $this->lng->txt("question_cumulated_statistics"));
194  $this->tpl->setVariable("TXT_RESULT", $this->lng->txt("result"));
195  $this->tpl->setVariable("TXT_VALUE", $this->lng->txt("value"));
196  $this->tpl->parseCurrentBlock();
197  }
198 
208  function &_getQuestionGUI($question_type, $question_id = -1)
209  {
210  include_once "./Modules/TestQuestionPool/classes/class.assQuestion.php";
211  if ((!$question_type) and ($question_id > 0))
212  {
213  $question_type = assQuestion::getQuestionTypeFromDb($question_id);
214  }
215  if (strlen($question_type) == 0) return NULL;
216  $question_type_gui = $question_type . "GUI";
217  assQuestion::_includeClass($question_type, 1);
218  $question =& new $question_type_gui();
219  if ($question_id > 0)
220  {
221  $question->object->loadFromDb($question_id);
222  }
223  return $question;
224  }
225 
226  function _getGUIClassNameForId($a_q_id)
227  {
228  include_once "./Modules/TestQuestionPool/classes/class.assQuestion.php";
229  include_once "./Modules/TestQuestionPool/classes/class.assQuestionGUI.php";
230  $q_type = assQuestion::getQuestionTypeFromDb($a_q_id);
231  $class_name = assQuestionGUI::_getClassNameForQType($q_type);
232  return $class_name;
233  }
234 
235  function _getClassNameForQType($q_type)
236  {
237  return $q_type . "GUI";
238  }
239 
250  function &createQuestionGUI($question_type, $question_id = -1)
251  {
252  include_once "./Modules/TestQuestionPool/classes/class.assQuestionGUI.php";
253  $this->question =& assQuestionGUI::_getQuestionGUI($question_type, $question_id);
254  }
255 
260  {
261  $this->tpl->addBlockFile("CONTENT", "content", "tpl.il_as_qpl_content.html", "Modules/TestQuestionPool");
262  $this->tpl->addBlockFile("STATUSLINE", "statusline", "tpl.statusline.html");
263  $this->tpl->addBlockFile("ADM_CONTENT", "adm_content", "tpl.il_as_question.html", "Modules/TestQuestionPool");
264  }
265 
272  function getILIASPage($html = "")
273  {
274  include_once("./Services/COPage/classes/class.ilPageObject.php");
275  include_once("./Services/COPage/classes/class.ilPageObjectGUI.php");
276  //$page =& new ilPageObject("qpl", $this->object->getId());
277  $page_gui =& new ilPageObjectGUI("qpl", $this->object->getId());
278  $page_gui->setTemplateTargetVar($a_temp_var);
279  $page_gui->setEnabledInternalLinks(false);
280  $page_gui->setQuestionHTML(array($this->object->getId() => $html));
281  $page_gui->setFileDownloadLink("ilias.php?baseClass=ilObjTestGUI&cmd=downloadFile".
282  "&amp;ref_id=".$_GET["ref_id"]);
283  $page_gui->setFullscreenLink("ilias.php?baseClass=ilObjTestGUI&cmd=fullscreen".
284  "&amp;ref_id=".$_GET["ref_id"]);
285  $page_gui->setSourcecodeDownloadScript("ilias.php?baseClass=ilObjTestGUI&ref_id=".$_GET["ref_id"]);
286  $page_gui->setEnabledPageFocus(false);
287  $page_gui->setOutputMode("presentation");
288  $page_gui->setPresentationTitle("");
289  $presentation = $page_gui->presentation();
290  // bugfix for non XHTML conform img tags in ILIAS Learning Module Editor
291  $presentation = preg_replace("/src=\".\\//ims", "src=\"" . ILIAS_HTTP_PATH . "/", $presentation);
292  return $presentation;
293  }
294 
298  function outQuestionPage($a_temp_var, $a_postponed = false, $active_id = "", $html = "")
299  {
300  $postponed = "";
301  if ($a_postponed)
302  {
303  $postponed = " (" . $this->lng->txt("postponed") . ")";
304  }
305 
306  include_once("./Services/COPage/classes/class.ilPageObject.php");
307  include_once("./Services/COPage/classes/class.ilPageObjectGUI.php");
308  $this->lng->loadLanguageModule("content");
309  //$page =& new ilPageObject("qpl", $this->object->getId());
310  $page_gui =& new ilPageObjectGUI("qpl", $this->object->getId());
311  $page_gui->setTemplateTargetVar($a_temp_var);
312  $page_gui->setFileDownloadLink("ilias.php?baseClass=ilObjTestGUI&cmd=downloadFile".
313  "&amp;ref_id=".$_GET["ref_id"]);
314  $page_gui->setFullscreenLink("ilias.php?baseClass=ilObjTestGUI&cmd=fullscreen".
315  "&amp;ref_id=".$_GET["ref_id"]);
316  $page_gui->setEnabledPageFocus(false);
317  if (strlen($html))
318  {
319  $page_gui->setQuestionHTML(array($this->object->getId() => $html));
320  }
321  $page_gui->setSourcecodeDownloadScript("ilias.php?baseClass=ilObjTestGUI&ref_id=".$_GET["ref_id"]);
322  $page_gui->setOutputMode("presentation");
323 
324  include_once "./Modules/Test/classes/class.ilObjTest.php";
325  $title_output = ilObjTest::_getTitleOutput($active_id);
326  switch ($title_output)
327  {
328  case 1:
329  $page_gui->setPresentationTitle(sprintf($this->lng->txt("tst_position"), $this->getSequenceNumber(), $this->getQuestionCount())." - ".$this->object->getTitle().$postponed);
330  break;
331  case 2:
332  $page_gui->setPresentationTitle(sprintf($this->lng->txt("tst_position"), $this->getSequenceNumber(), $this->getQuestionCount()).$postponed);
333  break;
334  case 0:
335  default:
336  $maxpoints = $this->object->getMaximumPoints();
337  if ($maxpoints == 1)
338  {
339  $maxpoints = " (".$maxpoints." ".$this->lng->txt("point").")";
340  }
341  else
342  {
343  $maxpoints = " (".$maxpoints." ".$this->lng->txt("points").")";
344  }
345  $page_gui->setPresentationTitle(sprintf($this->lng->txt("tst_position"), $this->getSequenceNumber(), $this->getQuestionCount())." - ".$this->object->getTitle().$postponed.$maxpoints);
346  break;
347  }
348  $presentation = $page_gui->presentation();
349  if (strlen($maxpoints)) $presentation = str_replace($maxpoints, "<em>$maxpoints</em>", $presentation);
350  // bugfix for non XHTML conform img tags in ILIAS Learning Module Editor
351  $presentation = preg_replace("/src=\".\\//ims", "src=\"" . ILIAS_HTTP_PATH . "/", $presentation);
352  return $presentation;
353  }
354 
358  function cancel()
359  {
360  if ($_GET["calling_test"])
361  {
362  $_GET["ref_id"] = $_GET["calling_test"];
363  ilUtil::redirect("ilias.php?baseClass=ilObjTestGUI&cmd=questions&ref_id=".$_GET["calling_test"]);
364  }
365  elseif ($_GET["test_ref_id"])
366  {
367  $_GET["ref_id"] = $_GET["test_ref_id"];
368  ilUtil::redirect("ilias.php?baseClass=ilObjTestGUI&cmd=questions&ref_id=".$_GET["test_ref_id"]);
369  }
370  else
371  {
372  if ($_GET["q_id"] > 0)
373  {
374  $this->ctrl->setParameterByClass("ilpageobjectgui", "q_id", $_GET["q_id"]);
375  $this->ctrl->redirectByClass("ilpageobjectgui", "edit");
376  }
377  else
378  {
379  $this->ctrl->redirectByClass("ilobjquestionpoolgui", "questions");
380  }
381  }
382  }
383 
384  function originalSyncForm($return_to = "")
385  {
386  if (strlen($return_to))
387  {
388  $this->ctrl->setParameter($this, "return_to", $return_to);
389  }
390  $template = new ilTemplate("tpl.il_as_qpl_sync_original.html",TRUE, TRUE, "Modules/TestQuestionPool");
391  $template->setVariable("BUTTON_YES", $this->lng->txt("yes"));
392  $template->setVariable("BUTTON_NO", $this->lng->txt("no"));
393  $template->setVariable("FORM_ACTION", $this->ctrl->getFormAction($this));
394  $template->setVariable("TEXT_SYNC", $this->lng->txt("confirm_sync_questions"));
395  $this->tpl->setVariable("ADM_CONTENT", $template->get());
396  }
397 
398  function sync()
399  {
400  $original_id = $this->object->original_id;
401  if ($original_id)
402  {
403  $this->object->syncWithOriginal();
404  }
405  if (strlen($_GET["return_to"]))
406  {
407  $this->ctrl->redirect($this, $_GET["return_to"]);
408  }
409  else
410  {
411  $_GET["ref_id"] = $_GET["calling_test"];
412  ilUtil::redirect("ilias.php?baseClass=ilObjTestGUI&cmd=questions&ref_id=".$_GET["calling_test"]);
413  }
414  }
415 
416  function cancelSync()
417  {
418  if (strlen($_GET["return_to"]))
419  {
420  $this->ctrl->redirect($this, $_GET["return_to"]);
421  }
422  else
423  {
424  $_GET["ref_id"] = $_GET["calling_test"];
425  ilUtil::redirect("ilias.php?baseClass=ilObjTestGUI&cmd=questions&ref_id=".$_GET["calling_test"]);
426  }
427  }
428 
436  function saveFeedback()
437  {
438  global $ilUser;
439 
440  $originalexists = $this->object->_questionExists($this->object->original_id);
441  include_once "./Modules/TestQuestionPool/classes/class.assQuestion.php";
442  if ($_GET["calling_test"] && $originalexists && assQuestion::_isWriteable($this->object->original_id, $ilUser->getId()))
443  {
444  $this->originalSyncForm("feedback");
445  }
446  else
447  {
448  ilUtil::sendSuccess($this->lng->txt("msg_obj_modified"), false);
449  $this->feedback();
450  }
451  }
452 
456  function saveEdit()
457  {
458  global $ilUser;
459 
460  $result = $this->writePostData();
461  if ($result == 0)
462  {
463  $ilUser->setPref("tst_lastquestiontype", $this->object->getQuestionType());
464  $ilUser->writePref("tst_lastquestiontype", $this->object->getQuestionType());
465  $this->object->saveToDb();
466  $originalexists = $this->object->_questionExists($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->ctrl->redirect($this, "originalSyncForm");
471  }
472  elseif ($_GET["calling_test"])
473  {
474  $_GET["ref_id"] = $_GET["calling_test"];
475  ilUtil::redirect("ilias.php?baseClass=ilObjTestGUI&cmd=questions&ref_id=".$_GET["calling_test"]);
476  return;
477  }
478  elseif ($_GET["test_ref_id"])
479  {
480  include_once ("./Modules/Test/classes/class.ilObjTest.php");
481  $_GET["ref_id"] = $_GET["test_ref_id"];
482  $test =& new ilObjTest($_GET["test_ref_id"], true);
483  $test->insertQuestion($this->object->getId());
484  ilUtil::redirect("ilias.php?baseClass=ilObjTestGUI&cmd=questions&ref_id=".$_GET["test_ref_id"]);
485  }
486  else
487  {
488  $this->ctrl->setParameter($this, "q_id", $this->object->getId());
489  $this->editQuestion();
490  if (strcmp($_SESSION["info"], "") != 0)
491  {
492  ilUtil::sendSuccess($_SESSION["info"] . "<br />" . $this->lng->txt("msg_obj_modified"), false);
493  }
494  else
495  {
496  ilUtil::sendSuccess($this->lng->txt("msg_obj_modified"), false);
497  }
498  $this->ctrl->setParameterByClass("ilpageobjectgui", "q_id", $this->object->getId());
499  $this->ctrl->redirectByClass("ilpageobjectgui", "edit");
500  }
501  }
502  }
503 
507  function save()
508  {
509  global $ilUser;
510  $old_id = $_GET["q_id"];
511  $result = $this->writePostData();
512  if ($result == 0)
513  {
514  $ilUser->setPref("tst_lastquestiontype", $this->object->getQuestionType());
515  $ilUser->writePref("tst_lastquestiontype", $this->object->getQuestionType());
516  $this->object->saveToDb();
517  $originalexists = $this->object->_questionExists($this->object->original_id);
518  include_once "./Modules/TestQuestionPool/classes/class.assQuestion.php";
519  if ($_GET["calling_test"] && $originalexists && assQuestion::_isWriteable($this->object->original_id, $ilUser->getId()))
520  {
521  $this->ctrl->redirect($this, "originalSyncForm");
522  }
523  elseif ($_GET["calling_test"])
524  {
525  $_GET["ref_id"] = $_GET["calling_test"];
526  ilUtil::redirect("ilias.php?baseClass=ilObjTestGUI&cmd=questions&ref_id=".$_GET["calling_test"]);
527  return;
528  }
529  elseif ($_GET["test_ref_id"])
530  {
531  include_once ("./Modules/Test/classes/class.ilObjTest.php");
532  $_GET["ref_id"] = $_GET["test_ref_id"];
533  $test =& new ilObjTest($_GET["test_ref_id"], true);
534  $test->insertQuestion($this->object->getId());
535  ilUtil::redirect("ilias.php?baseClass=ilObjTestGUI&cmd=questions&ref_id=".$_GET["test_ref_id"]);
536  }
537  else
538  {
539  if ($this->object->getId() != $old_id)
540  {
541  // first save
542  $this->ctrl->setParameterByClass($_GET["cmdClass"], "q_id", $this->object->getId());
543  $this->ctrl->setParameterByClass($_GET["cmdClass"], "sel_question_types", $_GET["sel_question_types"]);
544  $this->callNewIdListeners($this->object->getId());
545  ilUtil::sendSuccess($this->lng->txt("msg_obj_modified"), true);
546  $this->ctrl->redirectByClass($_GET["cmdClass"], "editQuestion");
547  }
548  if (strcmp($_SESSION["info"], "") != 0)
549  {
550  ilUtil::sendSuccess($_SESSION["info"] . "<br />" . $this->lng->txt("msg_obj_modified"), true);
551  }
552  else
553  {
554  ilUtil::sendSuccess($this->lng->txt("msg_obj_modified"), true);
555  }
556  $this->ctrl->redirect($this, 'editQuestion');
557  }
558  }
559  }
560 
564  function apply()
565  {
566  $this->writePostData();
567  $this->object->saveToDb();
568  $this->ctrl->setParameter($this, "q_id", $this->object->getId());
569  $this->editQuestion();
570  }
571 
578  function getContextPath($cont_obj, $a_endnode_id, $a_startnode_id = 1)
579  {
580  $path = "";
581 
582  $tmpPath = $cont_obj->getLMTree()->getPathFull($a_endnode_id, $a_startnode_id);
583 
584  // count -1, to exclude the learning module itself
585  for ($i = 1; $i < (count($tmpPath) - 1); $i++)
586  {
587  if ($path != "")
588  {
589  $path .= " > ";
590  }
591 
592  $path .= $tmpPath[$i]["title"];
593  }
594 
595  return $path;
596  }
597 
598  function setSequenceNumber($nr)
599  {
600  $this->sequence_no = $nr;
601  }
602 
603  function getSequenceNumber()
604  {
605  return $this->sequence_no;
606  }
607 
608  function setQuestionCount($a_question_count)
609  {
610  $this->question_count = $a_question_count;
611  }
612 
613  function getQuestionCount()
614  {
615  return $this->question_count;
616  }
617 
618  function getErrorMessage()
619  {
620  return $this->errormessage;
621  }
622 
624  {
625  $this->errormessage = $errormessage;
626  }
627 
629  {
630  $this->errormessage .= ((strlen($this->errormessage)) ? "<br />" : "") . $errormessage;
631  }
632 
634  {
635  }
636 
645  function getQuestionType()
646  {
647  return $this->object->getQuestionType();
648  }
649 
657  public function getAsValueAttribute($a_value)
658  {
659  $result = "";
660  if (strlen($a_value))
661  {
662  $result = " value=\"$a_value\" ";
663  }
664  return $result;
665  }
666 
667  // scorm2004-start
672  function addNewIdListener(&$a_object, $a_method, $a_parameters = "")
673  {
674  $cnt = $this->new_id_listener_cnt;
675  $this->new_id_listeners[$cnt]["object"] =& $a_object;
676  $this->new_id_listeners[$cnt]["method"] = $a_method;
677  $this->new_id_listeners[$cnt]["parameters"] = $a_parameters;
678  $this->new_id_listener_cnt++;
679  }
680 
684  function callNewIdListeners($a_new_id)
685  {
686 
687  for ($i=0; $i<$this->new_id_listener_cnt; $i++)
688  {
689  $this->new_id_listeners[$i]["parameters"]["new_id"] = $a_new_id;
690  $object =& $this->new_id_listeners[$i]["object"];
691  $method = $this->new_id_listeners[$i]["method"];
692  $parameters = $this->new_id_listeners[$i]["parameters"];
693 //var_dump($object);
694 //var_dump($method);
695 //var_dump($parameters);
696 
697  $object->$method($parameters);
698  }
699  }
700 
706  function setSelfAssessmentEditingMode($a_selfassessmenteditingmode)
707  {
708  $this->selfassessmenteditingmode = $a_selfassessmenteditingmode;
709  }
710 
717  {
718  return $this->selfassessmenteditingmode;
719  }
720 
726  function setPreventRteUsage($a_val)
727  {
728  $this->prevent_rte_usage = $a_val;
729  }
730 
737  {
739  }
740 
746  function setDefaultNrOfTries($a_defaultnroftries)
747  {
748  $this->defaultnroftries = $a_defaultnroftries;
749  }
750 
757  {
758  return $this->defaultnroftries;
759  }
760 
765  {
766  $form->addCommandButton("save", $this->lng->txt("save"));
767  if (!$this->getSelfAssessmentEditingMode() && !$_GET["calling_test"]) $form->addCommandButton("saveEdit", $this->lng->txt("save_edit"));
768  }
769 
777  {
778  // title
779  $title = new ilTextInputGUI($this->lng->txt("title"), "title");
780  $title->setValue($this->object->getTitle());
781  $title->setRequired(TRUE);
782  $form->addItem($title);
783 
784  if (!$this->getSelfAssessmentEditingMode())
785  {
786  // author
787  $author = new ilTextInputGUI($this->lng->txt("author"), "author");
788  $author->setValue($this->object->getAuthor());
789  $author->setRequired(TRUE);
790  $form->addItem($author);
791 
792  // description
793  $description = new ilTextInputGUI($this->lng->txt("description"), "comment");
794  $description->setValue($this->object->getComment());
795  $description->setRequired(FALSE);
796  $form->addItem($description);
797  }
798  else
799  {
800  // author as hidden field
801  $hi = new ilHiddenInputGUI("author");
802  $author = ilUtil::prepareFormOutput($this->object->getAuthor());
803  if (trim($author) == "")
804  {
805  $author = "-";
806  }
807  $hi->setValue($author);
808  $form->addItem($hi);
809 
810  }
811 
812  // questiontext
813  $question = new ilTextAreaInputGUI($this->lng->txt("question"), "question");
814  $question->setValue($this->object->prepareTextareaOutput($this->object->getQuestion()));
815  $question->setRequired(TRUE);
816  $question->setRows(10);
817  $question->setCols(80);
818  if (!$this->getSelfAssessmentEditingMode())
819  {
820  $question->setUseRte(TRUE);
821  include_once "./Services/AdvancedEditing/classes/class.ilObjAdvancedEditing.php";
822  $question->setRteTags(ilObjAdvancedEditing::_getUsedHTMLTags("assessment"));
823  $question->addPlugin("latex");
824  $question->addButton("latex");
825  $question->addButton("pastelatex");
826  $question->setRTESupport($this->object->getId(), "qpl", "assessment");
827  }
828  $form->addItem($question);
829 
830  if (!$this->getSelfAssessmentEditingMode())
831  {
832  // duration
833  $duration = new ilDurationInputGUI($this->lng->txt("working_time"), "Estimated");
834  $duration->setShowHours(TRUE);
835  $duration->setShowMinutes(TRUE);
836  $duration->setShowSeconds(TRUE);
837  $ewt = $this->object->getEstimatedWorkingTime();
838  $duration->setHours($ewt["h"]);
839  $duration->setMinutes($ewt["m"]);
840  $duration->setSeconds($ewt["s"]);
841  $duration->setRequired(FALSE);
842  $form->addItem($duration);
843  }
844  else
845  {
846  // number of tries
847  if (strlen($this->object->getNrOfTries()))
848  {
849  $nr_tries = $this->object->getNrOfTries();
850  }
851  else
852  {
853  $nr_tries = $this->getDefaultNrOfTries();
854  }
855  if ($nr_tries <= 0)
856  {
857  $nr_tries = 1;
858  }
859  $ni = new ilNumberInputGUI($this->lng->txt("qst_nr_of_tries"), "nr_of_tries");
860  $ni->setValue($nr_tries);
861  $ni->setMinValue(1);
862  $ni->setSize(5);
863  $ni->setMaxLength(5);
864  $ni->setRequired(true);
865  $form->addItem($ni);
866  }
867  }
868 
879  function getAnswerFeedbackOutput($active_id, $pass)
880  {
881  $output = "";
882  include_once "./Modules/Test/classes/class.ilObjTest.php";
883  $manual_feedback = ilObjTest::getManualFeedback($active_id, $this->object->getId(), $pass);
884  if (strlen($manual_feedback))
885  {
886  return $manual_feedback;
887  }
888  $correct_feedback = $this->object->getFeedbackGeneric(1);
889  $incorrect_feedback = $this->object->getFeedbackGeneric(0);
890  if (strlen($correct_feedback.$incorrect_feedback))
891  {
892  $reached_points = $this->object->calculateReachedPoints($active_id, $pass);
893  $max_points = $this->object->getMaximumPoints();
894  if ($reached_points == $max_points)
895  {
896  $output = $correct_feedback;
897  }
898  else
899  {
900  $output = $incorrect_feedback;
901  }
902  }
903  return $this->object->prepareTextareaOutput($output, TRUE);
904  }
905 
911  function feedback($checkonly = false)
912  {
913  $save = (strcmp($this->ctrl->getCmd(), "saveFeedback") == 0) ? TRUE : FALSE;
914  include_once("./Services/Form/classes/class.ilPropertyFormGUI.php");
915  $form = new ilPropertyFormGUI();
916  $form->setFormAction($this->ctrl->getFormAction($this));
917  $form->setTitle($this->lng->txt('feedback_answers'));
918  $form->setTableWidth("100%");
919  $form->setId("feedback");
920 
921  $complete = new ilTextAreaInputGUI($this->lng->txt("feedback_complete_solution"), "feedback_complete");
922  $complete->setValue($this->object->prepareTextareaOutput($this->object->getFeedbackGeneric(1)));
923  $complete->setRequired(false);
924  $complete->setRows(10);
925  $complete->setCols(80);
926  if (!$this->getPreventRteUsage())
927  {
928  $complete->setUseRte(true);
929  }
930  include_once "./Services/AdvancedEditing/classes/class.ilObjAdvancedEditing.php";
931  $complete->setRteTags(ilObjAdvancedEditing::_getUsedHTMLTags("assessment"));
932  $complete->addPlugin("latex");
933  $complete->addButton("latex");
934  $complete->addButton("pastelatex");
935  $complete->setRTESupport($this->object->getId(), "qpl", "assessment");
936  $form->addItem($complete);
937 
938  $incomplete = new ilTextAreaInputGUI($this->lng->txt("feedback_incomplete_solution"), "feedback_incomplete");
939  $incomplete->setValue($this->object->prepareTextareaOutput($this->object->getFeedbackGeneric(0)));
940  $incomplete->setRequired(false);
941  $incomplete->setRows(10);
942  $incomplete->setCols(80);
943  if (!$this->getPreventRteUsage())
944  {
945  $incomplete->setUseRte(true);
946  }
947  include_once "./Services/AdvancedEditing/classes/class.ilObjAdvancedEditing.php";
948  $incomplete->setRteTags(ilObjAdvancedEditing::_getUsedHTMLTags("assessment"));
949  $incomplete->addPlugin("latex");
950  $incomplete->addButton("latex");
951  $incomplete->addButton("pastelatex");
952  $incomplete->setRTESupport($this->object->getId(), "qpl", "assessment");
953  $form->addItem($incomplete);
954 
955  global $ilAccess;
956  if ($ilAccess->checkAccess("write", "", $_GET['ref_id']) || $this->getSelfAssessmentEditingMode())
957  {
958  $form->addCommandButton("saveFeedback", $this->lng->txt("save"));
959  }
960 
961  if ($save)
962  {
963  $form->setValuesByPost();
964  $errors = !$form->checkInput();
965  $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
966  }
967  if (!$checkonly) $this->tpl->setVariable("ADM_CONTENT", $form->getHTML());
968  return $errors;
969  }
970 
971  public function outQuestionType()
972  {
973  include_once "./classes/class.ilTemplate.php";
974  $template = new ilTemplate("tpl.il_as_qpl_questiontype.html", TRUE, TRUE, "Modules/TestQuestionPool");
975  $count = $this->object->isInUse();
976  if ($count)
977  {
978  global $rbacsystem;
979  if ($rbacsystem->checkAccess("write", $_GET["ref_id"]))
980  {
981  $template->setCurrentBlock("infosign");
982  $template->setVariable("INFO_IMG_SRC", ilUtil::getImagePath("messagebox_tip.png"));
983  $template->setVariable("INFO_IMG_ALT", sprintf($this->lng->txt("qpl_question_is_in_use"), $count));
984  $template->setVariable("INFO_IMG_TITLE", sprintf($this->lng->txt("qpl_question_is_in_use"), $count));
985  $template->parseCurrentBlock();
986  }
987  }
988  $template->setVariable("TEXT_QUESTION_TYPE", assQuestion::_getQuestionTypeName($this->object->getQuestionType()));
989  return $template->get();
990  }
991 
997  public function suggestedsolution()
998  {
999  global $ilUser;
1000  global $ilAccess;
1001 
1002  if ($_POST["deleteSuggestedSolution"] == 1)
1003  {
1004  $this->object->deleteSuggestedSolutions();
1005  ilUtil::sendSuccess($this->lng->txt("msg_obj_modified"), true);
1006  $this->ctrl->redirect($this, "suggestedsolution");
1007  }
1008 
1009  $save = (is_array($_POST["cmd"]) && array_key_exists("suggestedsolution", $_POST["cmd"])) ? TRUE : FALSE;
1010  $output = "";
1011  $solution_array = $this->object->getSuggestedSolution(0);
1012  $options = array(
1013  "lm" => $this->lng->txt("obj_lm"),
1014  "st" => $this->lng->txt("obj_st"),
1015  "pg" => $this->lng->txt("obj_pg"),
1016  "git" => $this->lng->txt("glossary_term"),
1017  "file" => $this->lng->txt("fileDownload"),
1018  "text" => $this->lng->txt("solutionText")
1019  );
1020 
1021  if ((strcmp($_POST["solutiontype"], "file") == 0) && (strcmp($solution_array["type"], "file") != 0))
1022  {
1023  $solution_array = array(
1024  "type" => "file"
1025  );
1026  }
1027  elseif ((strcmp($_POST["solutiontype"], "text") == 0) && (strcmp($solution_array["type"], "text") != 0))
1028  {
1029  $solution_array = array(
1030  "type" => "text",
1031  "value" => $this->getSolutionOutput(0, NULL, FALSE, FALSE, TRUE, FALSE, TRUE)
1032  );
1033  }
1034  if ($save && strlen($_POST["filename"]))
1035  {
1036  $solution_array["value"]["filename"] = $_POST["filename"];
1037  }
1038  if ($save && strlen($_POST["solutiontext"]))
1039  {
1040  $solution_array["value"] = $_POST["solutiontext"];
1041  }
1042  include_once("./Services/Form/classes/class.ilPropertyFormGUI.php");
1043  if (count($solution_array))
1044  {
1045  $form = new ilPropertyFormGUI();
1046  $form->setFormAction($this->ctrl->getFormAction($this));
1047  $form->setTitle($this->lng->txt("solution_hint"));
1048  $form->setMultipart(TRUE);
1049  $form->setTableWidth("100%");
1050  $form->setId("suggestedsolutiondisplay");
1051 
1052  // suggested solution output
1053  include_once "./Modules/TestQuestionPool/classes/class.ilSolutionTitleInputGUI.php";
1054  $title = new ilSolutionTitleInputGUI($this->lng->txt("showSuggestedSolution"), "solutiontype");
1055  $template = new ilTemplate("tpl.il_as_qpl_suggested_solution_input_presentation.html", TRUE, TRUE, "Modules/TestQuestionPool");
1056  if (strlen($solution_array["internal_link"]))
1057  {
1058  $href = assQuestion::_getInternalLinkHref($solution_array["internal_link"]);
1059  $template->setCurrentBlock("preview");
1060  $template->setVariable("TEXT_SOLUTION", $this->lng->txt("solution_hint"));
1061  $template->setVariable("VALUE_SOLUTION", " <a href=\"$href\" target=\"content\">" . $this->lng->txt("view"). "</a> ");
1062  $template->parseCurrentBlock();
1063  }
1064  elseif ((strcmp($solution_array["type"], "file") == 0) && (is_array($solution_array["value"])))
1065  {
1066  $href = $this->object->getSuggestedSolutionPathWeb() . $solution_array["value"]["name"];
1067  $template->setCurrentBlock("preview");
1068  $template->setVariable("TEXT_SOLUTION", $this->lng->txt("solution_hint"));
1069  $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> ");
1070  $template->parseCurrentBlock();
1071  }
1072  $template->setVariable("TEXT_TYPE", $this->lng->txt("type"));
1073  $template->setVariable("VALUE_TYPE", $options[$solution_array["type"]]);
1074  $title->setHtml($template->get());
1075  $deletesolution = new ilCheckboxInputGUI("", "deleteSuggestedSolution");
1076  $deletesolution->setOptionTitle($this->lng->txt("deleteSuggestedSolution"));
1077  $title->addSubItem($deletesolution);
1078  $form->addItem($title);
1079 
1080  if (strcmp($solution_array["type"], "file") == 0)
1081  {
1082  // file
1083  $file = new ilFileInputGUI($this->lng->txt("fileDownload"), "file");
1084  $file->setRequired(TRUE);
1085  $file->enableFileNameSelection("filename");
1086  //$file->setSuffixes(array("doc","xls","png","jpg","gif","pdf"));
1087  if ($_FILES["file"]["tmp_name"])
1088  {
1089  if (!file_exists($this->object->getSuggestedSolutionPath())) ilUtil::makeDirParents($this->object->getSuggestedSolutionPath());
1090  $res = ilUtil::moveUploadedFile($_FILES["file"]["tmp_name"], $_FILES["file"]["name"], $this->object->getSuggestedSolutionPath() . $_FILES["file"]["name"]);
1091  if ($res)
1092  {
1093  // remove an old file download
1094  if (is_array($solution_array["value"])) @unlink($this->object->getSuggestedSolutionPath() . $solution_array["value"]["name"]);
1095  $file->setValue($_FILES["file"]["name"]);
1096  $this->object->saveSuggestedSolution("file", "", 0, array("name" => $_FILES["file"]["name"], "type" => $_FILES["file"]["type"], "size" => $_FILES["file"]["size"], "filename" => $_POST["filename"]));
1097  $originalexists = $this->object->_questionExistsInPool($this->object->original_id);
1098  if ($_GET["calling_test"] && $originalexists && assQuestion::_isWriteable($this->object->original_id, $ilUser->getId()))
1099  {
1100  return $this->originalSyncForm("suggestedsolution");
1101  }
1102  else
1103  {
1104  ilUtil::sendSuccess($this->lng->txt("suggested_solution_added_successfully"), TRUE);
1105  $this->ctrl->redirect($this, "suggestedsolution");
1106  }
1107  }
1108  else
1109  {
1110  ilUtil::sendInfo($res);
1111  }
1112  }
1113  else
1114  {
1115  if (is_array($solution_array["value"]))
1116  {
1117  $file->setValue($solution_array["value"]["name"]);
1118  $file->setFilename((strlen($solution_array["value"]["filename"])) ? $solution_array["value"]["filename"] : $solution_array["value"]["name"]);
1119  }
1120  }
1121  $form->addItem($file);
1122  $hidden = new ilHiddenInputGUI("solutiontype");
1123  $hidden->setValue("file");
1124  $form->addItem($hidden);
1125  }
1126  else if (strcmp($solution_array["type"], "text") == 0)
1127  {
1128  $question = new ilTextAreaInputGUI($this->lng->txt("solutionText"), "solutiontext");
1129  $question->setValue($this->object->prepareTextareaOutput($solution_array["value"]));
1130  $question->setRequired(TRUE);
1131  $question->setRows(10);
1132  $question->setCols(80);
1133  $question->setUseRte(TRUE);
1134  $question->addPlugin("latex");
1135  $question->addButton("latex");
1136  $question->setRTESupport($this->object->getId(), "qpl", "assessment");
1137  $hidden = new ilHiddenInputGUI("solutiontype");
1138  $hidden->setValue("text");
1139  $form->addItem($hidden);
1140  $form->addItem($question);
1141  }
1142  if ($ilAccess->checkAccess("write", "", $_GET['ref_id'])) $form->addCommandButton("suggestedsolution", $this->lng->txt("save"));
1143 
1144  if ($save)
1145  {
1146  if ($form->checkInput())
1147  {
1148  switch ($solution_array["type"])
1149  {
1150  case "file":
1151  $this->object->saveSuggestedSolution("file", "", 0, array("name" => $solution_array["value"]["name"], "type" => $solution_array["value"]["type"], "size" => $solution_array["value"]["size"], "filename" => $_POST["filename"]));
1152  break;
1153  case "text":
1154  $this->object->saveSuggestedSolution("text", "", 0, $solution_array["value"]);
1155  break;
1156  }
1157  $originalexists = $this->object->_questionExistsInPool($this->object->original_id);
1158  if ($_GET["calling_test"] && $originalexists && assQuestion::_isWriteable($this->object->original_id, $ilUser->getId()))
1159  {
1160  return $this->originalSyncForm("suggestedsolution");
1161  }
1162  else
1163  {
1164  ilUtil::sendSuccess($this->lng->txt("msg_obj_modified"), true);
1165  $this->ctrl->redirect($this, "suggestedsolution");
1166  }
1167  }
1168  }
1169  $output = $form->getHTML();
1170  }
1171 
1172  $savechange = (strcmp($this->ctrl->getCmd(), "saveSuggestedSolution") == 0) ? TRUE : FALSE;
1173 
1174  $changeoutput = "";
1175  if ($ilAccess->checkAccess("write", "", $_GET['ref_id']))
1176  {
1177  $formchange = new ilPropertyFormGUI();
1178  $formchange->setFormAction($this->ctrl->getFormAction($this));
1179  $formchange->setTitle((count($solution_array)) ? $this->lng->txt("changeSuggestedSolution") : $this->lng->txt("addSuggestedSolution"));
1180  $formchange->setMultipart(FALSE);
1181  $formchange->setTableWidth("100%");
1182  $formchange->setId("suggestedsolution");
1183 
1184  $solutiontype = new ilRadioMatrixInputGUI($this->lng->txt("suggestedSolutionType"), "solutiontype");
1185  $solutiontype->setOptions($options);
1186  if (count($solution_array))
1187  {
1188  $solutiontype->setValue($solution_array["type"]);
1189  }
1190  $solutiontype->setRequired(TRUE);
1191  $formchange->addItem($solutiontype);
1192 
1193  $formchange->addCommandButton("saveSuggestedSolution", $this->lng->txt("select"));
1194 
1195  if ($savechange)
1196  {
1197  $formchange->checkInput();
1198  }
1199  $changeoutput = $formchange->getHTML();
1200  }
1201 
1202  $this->tpl->setVariable("ADM_CONTENT", $changeoutput . $output);
1203  }
1204 
1205  public function outSolutionExplorer()
1206  {
1207  global $tree;
1208 
1209  include_once("./Modules/TestQuestionPool/classes/class.ilSolutionExplorer.php");
1210  $type = $_GET["link_new_type"];
1211  $search = $_GET["search_link_type"];
1212  $this->ctrl->setParameter($this, "link_new_type", $type);
1213  $this->ctrl->setParameter($this, "search_link_type", $search);
1214  $this->ctrl->saveParameter($this, array("subquestion_index", "link_new_type", "search_link_type"));
1215 
1216  ilUtil::sendInfo($this->lng->txt("select_object_to_link"));
1217 
1218  $exp = new ilSolutionExplorer($this->ctrl->getLinkTarget($this, 'suggestedsolution'), get_class($this));
1219 
1220  $exp->setExpand($_GET["expand"] ? $_GET["expand"] : $tree->getParentId($_GET["ref_id"]));
1221  $exp->setExpandTarget($this->ctrl->getLinkTarget($this, 'outSolutionExplorer'));
1222  $exp->setTargetGet("ref_id");
1223  $exp->setRefId($_GET["ref_id"]);
1224  $exp->addFilter($type);
1225  $exp->setSelectableType($type);
1226 
1227  // build html-output
1228  $exp->setOutput(0);
1229 
1230  $template = new ilTemplate("tpl.il_as_qpl_explorer.html", TRUE, TRUE, "Modules/TestQuestionPool");
1231  $template->setVariable("EXPLORER_TREE",$exp->getOutput());
1232  $template->setVariable("BUTTON_CANCEL",$this->lng->txt("cancel"));
1233  $template->setVariable("FORMACTION",$this->ctrl->getFormAction($this, "suggestedsolution"));
1234  $this->tpl->setVariable("ADM_CONTENT", $template->get());
1235  }
1236 
1237  public function saveSuggestedSolution()
1238  {
1239  global $tree;
1240 
1241  include_once("./Modules/TestQuestionPool/classes/class.ilSolutionExplorer.php");
1242  switch ($_POST["solutiontype"])
1243  {
1244  case "lm":
1245  $type = "lm";
1246  $search = "lm";
1247  break;
1248  case "git":
1249  $type = "glo";
1250  $search = "glo";
1251  break;
1252  case "st":
1253  $type = "lm";
1254  $search = "st";
1255  break;
1256  case "pg":
1257  $type = "lm";
1258  $search = "pg";
1259  break;
1260  case "file":
1261  case "text":
1262  return $this->suggestedsolution();
1263  break;
1264  default:
1265  return $this->suggestedsolution();
1266  break;
1267  }
1268  $this->ctrl->setParameter($this, "link_new_type", $type);
1269  $this->ctrl->setParameter($this, "search_link_type", $search);
1270  $this->ctrl->redirect($this, "outSolutionExplorer");
1271  }
1272 
1273  function cancelExplorer()
1274  {
1275  $this->ctrl->redirect($this, "suggestedsolution");
1276  }
1277 
1278  function outPageSelector()
1279  {
1280  include_once "./Modules/LearningModule/classes/class.ilLMPageObject.php";
1281  include_once("./Modules/LearningModule/classes/class.ilObjContentObjectGUI.php");
1282  $cont_obj_gui =& new ilObjContentObjectGUI("", $_GET["source_id"], true);
1283  $cont_obj = $cont_obj_gui->object;
1284  $pages = ilLMPageObject::getPageList($cont_obj->getId());
1285  $shownpages = array();
1286  $tree = $cont_obj->getLMTree();
1287  $chapters = $tree->getSubtree($tree->getNodeData($tree->getRootId()));
1288  $this->ctrl->setParameter($this, "q_id", $this->object->getId());
1289  $color_class = array("tblrow1", "tblrow2");
1290  $counter = 0;
1291  $template = new ilTemplate("tpl.il_as_qpl_internallink_selection.html", TRUE, TRUE, "Modules/TestQuestionPool");
1292  foreach ($chapters as $chapter)
1293  {
1294  $chapterpages = $tree->getChildsByType($chapter["obj_id"], "pg");
1295  foreach ($chapterpages as $page)
1296  {
1297  if($page["type"] == $_GET["search_link_type"])
1298  {
1299  array_push($shownpages, $page["obj_id"]);
1300  $template->setCurrentBlock("linktable_row");
1301  $template->setVariable("TEXT_LINK", $page["title"]);
1302  $template->setVariable("TEXT_ADD", $this->lng->txt("add"));
1303  $template->setVariable("LINK_HREF", $this->ctrl->getLinkTargetByClass(get_class($this), "add" . strtoupper($page["type"])) . "&" . $page["type"] . "=" . $page["obj_id"]);
1304  $template->setVariable("COLOR_CLASS", $color_class[$counter % 2]);
1305  if ($tree->isInTree($page["obj_id"]))
1306  {
1307  $path_str = $this->getContextPath($cont_obj, $page["obj_id"]);
1308  }
1309  else
1310  {
1311  $path_str = "---";
1312  }
1313  $template->setVariable("TEXT_DESCRIPTION", ilUtil::prepareFormOutput($path_str));
1314  $template->parseCurrentBlock();
1315  $counter++;
1316  }
1317  }
1318  }
1319  foreach ($pages as $page)
1320  {
1321  if (!in_array($page["obj_id"], $shownpages))
1322  {
1323  $template->setCurrentBlock("linktable_row");
1324  $template->setVariable("TEXT_LINK", $page["title"]);
1325  $template->setVariable("TEXT_ADD", $this->lng->txt("add"));
1326  $template->setVariable("LINK_HREF", $this->ctrl->getLinkTargetByClass(get_class($this), "add" . strtoupper($page["type"])) . "&" . $page["type"] . "=" . $page["obj_id"]);
1327  $template->setVariable("COLOR_CLASS", $color_class[$counter % 2]);
1328  $path_str = "---";
1329  $template->setVariable("TEXT_DESCRIPTION", ilUtil::prepareFormOutput($path_str));
1330  $template->parseCurrentBlock();
1331  $counter++;
1332  }
1333  }
1334  $template->setCurrentBlock("link_selection");
1335  $template->setVariable("BUTTON_CANCEL",$this->lng->txt("cancel"));
1336  $template->setVariable("TEXT_LINK_TYPE", $this->lng->txt("obj_" . $_GET["search_link_type"]));
1337  $template->setVariable("FORMACTION",$this->ctrl->getFormAction($this, "cancelExplorer"));
1338  $template->parseCurrentBlock();
1339  $this->tpl->setVariable("ADM_CONTENT", $template->get());
1340  }
1341 
1342  public function outChapterSelector()
1343  {
1344  $template = new ilTemplate("tpl.il_as_qpl_internallink_selection.html", TRUE, TRUE, "Modules/TestQuestionPool");
1345  $this->ctrl->setParameter($this, "q_id", $this->object->getId());
1346  $color_class = array("tblrow1", "tblrow2");
1347  $counter = 0;
1348  include_once("./Modules/LearningModule/classes/class.ilObjContentObjectGUI.php");
1349  $cont_obj_gui =& new ilObjContentObjectGUI("", $_GET["source_id"], true);
1350  $cont_obj = $cont_obj_gui->object;
1351  // get all chapters
1352  $ctree =& $cont_obj->getLMTree();
1353  $nodes = $ctree->getSubtree($ctree->getNodeData($ctree->getRootId()));
1354  foreach($nodes as $node)
1355  {
1356  if($node["type"] == $_GET["search_link_type"])
1357  {
1358  $template->setCurrentBlock("linktable_row");
1359  $template->setVariable("TEXT_LINK", $node["title"]);
1360  $template->setVariable("TEXT_ADD", $this->lng->txt("add"));
1361  $template->setVariable("LINK_HREF", $this->ctrl->getLinkTargetByClass(get_class($this), "add" . strtoupper($node["type"])) . "&" . $node["type"] . "=" . $node["obj_id"]);
1362  $template->setVariable("COLOR_CLASS", $color_class[$counter % 2]);
1363  $template->parseCurrentBlock();
1364  $counter++;
1365  }
1366  }
1367  $template->setCurrentBlock("link_selection");
1368  $template->setVariable("BUTTON_CANCEL",$this->lng->txt("cancel"));
1369  $template->setVariable("TEXT_LINK_TYPE", $this->lng->txt("obj_" . $_GET["search_link_type"]));
1370  $template->setVariable("FORMACTION",$this->ctrl->getFormAction($this, "cancelExplorer"));
1371  $template->parseCurrentBlock();
1372  $this->tpl->setVariable("ADM_CONTENT", $template->get());
1373  }
1374 
1375  public function outGlossarySelector()
1376  {
1377  $template = new ilTemplate("tpl.il_as_qpl_internallink_selection.html", TRUE, TRUE, "Modules/TestQuestionPool");
1378  $this->ctrl->setParameter($this, "q_id", $this->object->getId());
1379  $color_class = array("tblrow1", "tblrow2");
1380  $counter = 0;
1381  include_once "./Modules/Glossary/classes/class.ilObjGlossary.php";
1382  $glossary =& new ilObjGlossary($_GET["source_id"], true);
1383  // get all glossary items
1384  $terms = $glossary->getTermList();
1385  foreach($terms as $term)
1386  {
1387  $template->setCurrentBlock("linktable_row");
1388  $template->setVariable("TEXT_LINK", $term["term"]);
1389  $template->setVariable("TEXT_ADD", $this->lng->txt("add"));
1390  $template->setVariable("LINK_HREF", $this->ctrl->getLinkTargetByClass(get_class($this), "addGIT") . "&git=" . $term["id"]);
1391  $template->setVariable("COLOR_CLASS", $color_class[$counter % 2]);
1392  $template->parseCurrentBlock();
1393  $counter++;
1394  }
1395  $template->setCurrentBlock("link_selection");
1396  $template->setVariable("BUTTON_CANCEL",$this->lng->txt("cancel"));
1397  $template->setVariable("TEXT_LINK_TYPE", $this->lng->txt("glossary_term"));
1398  $template->setVariable("FORMACTION",$this->ctrl->getFormAction($this, "cancelExplorer"));
1399  $template->parseCurrentBlock();
1400  $this->tpl->setVariable("ADM_CONTENT", $template->get());
1401  }
1402 
1403  function linkChilds()
1404  {
1405  $this->ctrl->saveParameter($this, array("subquestion_index", "link_new_type", "search_link_type"));
1406  switch ($_GET["search_link_type"])
1407  {
1408  case "pg":
1409  return $this->outPageSelector();
1410  break;
1411  case "st":
1412  return $this->outChapterSelector();
1413  break;
1414  case "glo":
1415  return $this->outGlossarySelector();
1416  break;
1417  case "lm":
1418  $subquestion_index = ($_GET["subquestion_index"] > 0) ? $_GET["subquestion_index"] : 0;
1419  $this->object->saveSuggestedSolution("lm", "il__lm_" . $_GET["source_id"], $subquestion_index);
1420  ilUtil::sendSuccess($this->lng->txt("suggested_solution_added_successfully"), TRUE);
1421  $this->ctrl->redirect($this, "suggestedsolution");
1422  break;
1423  }
1424  }
1425 
1426  function addPG()
1427  {
1428  $subquestion_index = 0;
1429  if (strlen($_GET["subquestion_index"]) && $_GET["subquestion_index"] >= 0)
1430  {
1431  $subquestion_index = $_GET["subquestion_index"];
1432  }
1433  $this->object->saveSuggestedSolution("pg", "il__pg_" . $_GET["pg"], $subquestion_index);
1434  ilUtil::sendSuccess($this->lng->txt("suggested_solution_added_successfully"), TRUE);
1435  $this->ctrl->redirect($this, "suggestedsolution");
1436  }
1437 
1438  function addST()
1439  {
1440  $subquestion_index = 0;
1441  if (strlen($_GET["subquestion_index"]) && $_GET["subquestion_index"] >= 0)
1442  {
1443  $subquestion_index = $_GET["subquestion_index"];
1444  }
1445  $this->object->saveSuggestedSolution("st", "il__st_" . $_GET["st"], $subquestion_index);
1446  ilUtil::sendSuccess($this->lng->txt("suggested_solution_added_successfully"), TRUE);
1447  $this->ctrl->redirect($this, "suggestedsolution");
1448  }
1449 
1450  function addGIT()
1451  {
1452  $subquestion_index = 0;
1453  if (strlen($_GET["subquestion_index"]) && $_GET["subquestion_index"] >= 0)
1454  {
1455  $subquestion_index = $_GET["subquestion_index"];
1456  }
1457  $this->object->saveSuggestedSolution("git", "il__git_" . $_GET["git"], $subquestion_index);
1458  ilUtil::sendSuccess($this->lng->txt("suggested_solution_added_successfully"), TRUE);
1459  $this->ctrl->redirect($this, "suggestedsolution");
1460  }
1461 }
1462 ?>