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