ILIAS  Release_4_1_x_branch Revision 61804
 All Data Structures Namespaces Files Functions Variables Groups Pages
class.assMultipleChoiceGUI.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/TestQuestionPool/classes/class.assQuestionGUI.php";
25 include_once "./Modules/Test/classes/inc.AssessmentConstants.php";
26 
38 {
40 
49  function __construct($id = -1)
50  {
52  include_once "./Modules/TestQuestionPool/classes/class.assMultipleChoice.php";
53  $this->object = new assMultipleChoice();
54  if ($id >= 0)
55  {
56  $this->object->loadFromDb($id);
57  }
58  }
59 
60  function getCommand($cmd)
61  {
62  return $cmd;
63  }
64 
71  function writePostData($always = false)
72  {
73  $hasErrors = (!$always) ? $this->editQuestion(true) : false;
74  if (!$hasErrors)
75  {
76  $this->object->setTitle($_POST["title"]);
77  $this->object->setAuthor($_POST["author"]);
78  $this->object->setComment($_POST["comment"]);
79  include_once "./Services/AdvancedEditing/classes/class.ilObjAdvancedEditing.php";
80  $questiontext = $_POST["question"];
81  $this->object->setQuestion($questiontext);
82  $this->object->setShuffle($_POST["shuffle"]);
83  $this->object->setEstimatedWorkingTime(
84  $_POST["Estimated"]["hh"],
85  $_POST["Estimated"]["mm"],
86  $_POST["Estimated"]["ss"]
87  );
88  if ($this->getSelfAssessmentEditingMode())
89  {
90  $this->object->setNrOfTries($_POST['nr_of_tries']);
91  }
92  $this->object->setMultilineAnswerSetting($_POST["types"]);
93  if (is_array($_POST['choice']['imagename']) && $_POST["types"] == 1)
94  {
95  $this->object->isSingleline = true;
96  ilUtil::sendInfo($this->lng->txt('info_answer_type_change'), true);
97  }
98  else
99  {
100  $this->object->isSingleline = ($_POST["types"] == 0) ? true : false;
101  }
102  $this->object->setThumbSize((strlen($_POST["thumb_size"])) ? $_POST["thumb_size"] : "");
103 
104  // Delete all existing answers and create new answers from the form data
105  $this->object->flushAnswers();
106  if ($this->object->isSingleline)
107  {
108  foreach ($_POST['choice']['answer'] as $index => $answer)
109  {
110  $filename = $_POST['choice']['imagename'][$index];
111  if (strlen($_FILES['choice']['name']['image'][$index]))
112  {
113  // upload image
114  $filename = $this->object->createNewImageFileName($_FILES['choice']['name']['image'][$index]);
115  $upload_result = $this->object->setImageFile($filename, $_FILES['choice']['tmp_name']['image'][$index]);
116  if ($upload_result != 0)
117  {
118  $filename = "";
119  }
120  }
121  $answertext = $answer;
122  $this->object->addAnswer($answertext, $_POST['choice']['points'][$index], $_POST['choice']['points_unchecked'][$index], $index, $filename);
123  }
124  }
125  else
126  {
127  foreach ($_POST['choice']['answer'] as $index => $answer)
128  {
129  $answertext = $answer;
130  $this->object->addAnswer($answertext, $_POST['choice']['points'][$index], $_POST['choice']['points_unchecked'][$index], $index);
131  }
132  }
133  return 0;
134  }
135  else
136  {
137  return 1;
138  }
139  }
140 
146  public function editQuestion($checkonly = FALSE)
147  {
148  $save = ((strcmp($this->ctrl->getCmd(), "save") == 0) || (strcmp($this->ctrl->getCmd(), "saveEdit") == 0)) ? TRUE : FALSE;
149  $this->getQuestionTemplate();
150 
151  include_once("./Services/Form/classes/class.ilPropertyFormGUI.php");
152  $form = new ilPropertyFormGUI();
153  $form->setFormAction($this->ctrl->getFormAction($this));
154  $form->setTitle($this->outQuestionType());
155  $isSingleline = ($this->object->lastChange == 0 && !array_key_exists('types', $_POST)) ? (($this->object->getMultilineAnswerSetting()) ? false : true) : $this->object->isSingleline;
156  if ($checkonly) $isSingleline = ($_POST['types'] == 0) ? true : false;
157  if ($isSingleline)
158  {
159  $form->setMultipart(TRUE);
160  }
161  else
162  {
163  $form->setMultipart(FALSE);
164  }
165  $form->setTableWidth("100%");
166  $form->setId("assmultiplechoice");
167 
168  // title, author, description, question, working time (assessment mode)
169  $this->addBasicQuestionFormProperties($form);
170 
171  // shuffle
172  $shuffle = new ilCheckboxInputGUI($this->lng->txt("shuffle_answers"), "shuffle");
173  $shuffle->setValue(1);
174  $shuffle->setChecked($this->object->getShuffle());
175  $shuffle->setRequired(FALSE);
176  $form->addItem($shuffle);
177 
178  if ($this->object->getId())
179  {
180  $hidden = new ilHiddenInputGUI("", "ID");
181  $hidden->setValue($this->object->getId());
182  $form->addItem($hidden);
183  }
184 
185  if (!$this->getSelfAssessmentEditingMode())
186  {
187  // Answer types
188  $types = new ilSelectInputGUI($this->lng->txt("answer_types"), "types");
189  $types->setRequired(false);
190  $types->setValue(($isSingleline) ? 0 : 1);
191  $types->setOptions(array(
192  0 => $this->lng->txt('answers_singleline'),
193  1 => $this->lng->txt('answers_multiline'),
194  ));
195  $form->addItem($types);
196  }
197 
198  if (($isSingleline) && (!$this->getSelfAssessmentEditingMode()))
199  {
200  // thumb size
201  $thumb_size = new ilNumberInputGUI($this->lng->txt("thumb_size"), "thumb_size");
202  $thumb_size->setMinValue(20);
203  $thumb_size->setDecimals(0);
204  $thumb_size->setSize(6);
205  $thumb_size->setInfo($this->lng->txt('thumb_size_info'));
206  $thumb_size->setValue($this->object->getThumbSize());
207  $thumb_size->setRequired(false);
208  $form->addItem($thumb_size);
209  }
210 
211  // Choices
212  include_once "./Modules/TestQuestionPool/classes/class.ilMultipleChoiceWizardInputGUI.php";
213  $choices = new ilMultipleChoiceWizardInputGUI($this->lng->txt("answers"), "choice");
214  if ($this->getSelfAssessmentEditingMode()) $choices->setHideImages(true);
215  $choices->setRequired(true);
216  $choices->setQuestionObject($this->object);
217  $choices->setSingleline($isSingleline);
218  $choices->setAllowMove(false);
219  if ($this->object->getAnswerCount() == 0) $this->object->addAnswer("", 0, 0, 0);
220  $choices->setValues($this->object->getAnswers());
221  $form->addItem($choices);
222 
223  $this->addQuestionFormCommandButtons($form);
224 
225  $errors = false;
226 
227  if ($save)
228  {
229  $form->setValuesByPost();
230  $errors = !$form->checkInput();
231  $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
232  if ($errors) $checkonly = false;
233  }
234 
235  if (!$checkonly) $this->tpl->setVariable("QUESTION_DATA", $form->getHTML());
236  return $errors;
237  }
238 
242  public function uploadchoice()
243  {
244  $this->writePostData(true);
245  $position = key($_POST['cmd']['uploadchoice']);
246  $this->editQuestion();
247  }
248 
252  public function removeimagechoice()
253  {
254  $this->writePostData(true);
255  $position = key($_POST['cmd']['removeimagechoice']);
256  $filename = $_POST['choice']['imagename'][$position];
257  $this->object->removeAnswerImage($position);
258  $this->editQuestion();
259  }
260 
264  public function addchoice()
265  {
266  $this->writePostData(true);
267  $position = key($_POST['cmd']['addchoice']);
268  $this->object->addAnswer("", 0, 0, $position+1);
269  $this->editQuestion();
270  }
271 
275  public function removechoice()
276  {
277  $this->writePostData(true);
278  $position = key($_POST['cmd']['removechoice']);
279  $this->object->deleteAnswer($position);
280  $this->editQuestion();
281  }
282 
283  function outQuestionForTest($formaction, $active_id, $pass = NULL, $is_postponed = FALSE, $use_post_solutions = FALSE, $show_feedback = FALSE)
284  {
285  $test_output = $this->getTestOutput($active_id, $pass, $is_postponed, $use_post_solutions, $show_feedback);
286  $this->tpl->setVariable("QUESTION_OUTPUT", $test_output);
287  $this->tpl->setVariable("FORMACTION", $formaction);
288  }
289 
304  $active_id,
305  $pass = NULL,
306  $graphicalOutput = FALSE,
307  $result_output = FALSE,
308  $show_question_only = TRUE,
309  $show_feedback = FALSE,
310  $show_correct_solution = FALSE,
311  $show_manual_scoring = FALSE
312  )
313  {
314  // shuffle output
315  $keys = $this->getChoiceKeys();
316 
317  // get the solution of the user for the active pass or from the last pass if allowed
318  $user_solution = array();
319  if (($active_id > 0) && (!$show_correct_solution))
320  {
321  $solutions =& $this->object->getSolutionValues($active_id, $pass);
322  foreach ($solutions as $idx => $solution_value)
323  {
324  array_push($user_solution, $solution_value["value1"]);
325  }
326  }
327  else
328  {
329  // take the correct solution instead of the user solution
330  foreach ($this->object->answers as $index => $answer)
331  {
332  $points_checked = $answer->getPointsChecked();
333  $points_unchecked = $answer->getPointsUnchecked();
334  if ($points_checked > $points_unchecked)
335  {
336  if ($points_checked > 0)
337  {
338  array_push($user_solution, $index);
339  }
340  }
341  }
342  }
343 
344  // generate the question output
345  include_once "./classes/class.ilTemplate.php";
346  $template = new ilTemplate("tpl.il_as_qpl_mc_mr_output_solution.html", TRUE, TRUE, "Modules/TestQuestionPool");
347  $solutiontemplate = new ilTemplate("tpl.il_as_tst_solution_output.html",TRUE, TRUE, "Modules/TestQuestionPool");
348  foreach ($keys as $answer_id)
349  {
350  $answer = $this->object->answers[$answer_id];
351  if (($active_id > 0) && (!$show_correct_solution))
352  {
353  if ($graphicalOutput)
354  {
355  // output of ok/not ok icons for user entered solutions
356  $ok = FALSE;
357  $checked = FALSE;
358  foreach ($user_solution as $mc_solution)
359  {
360  if (strcmp($mc_solution, $answer_id) == 0)
361  {
362  $checked = TRUE;
363  }
364  }
365  if ($checked)
366  {
367  if ($answer->getPointsChecked() > $answer->getPointsUnchecked())
368  {
369  $ok = TRUE;
370  }
371  else
372  {
373  $ok = FALSE;
374  }
375  }
376  else
377  {
378  if ($answer->getPointsChecked() > $answer->getPointsUnchecked())
379  {
380  $ok = FALSE;
381  }
382  else
383  {
384  $ok = TRUE;
385  }
386  }
387  if ($ok)
388  {
389  $template->setCurrentBlock("icon_ok");
390  $template->setVariable("ICON_OK", ilUtil::getImagePath("icon_ok.gif"));
391  $template->setVariable("TEXT_OK", $this->lng->txt("answer_is_right"));
392  $template->parseCurrentBlock();
393  }
394  else
395  {
396  $template->setCurrentBlock("icon_ok");
397  $template->setVariable("ICON_NOT_OK", ilUtil::getImagePath("icon_not_ok.gif"));
398  $template->setVariable("TEXT_NOT_OK", $this->lng->txt("answer_is_wrong"));
399  $template->parseCurrentBlock();
400  }
401  }
402  }
403  if (strlen($answer->getImage()))
404  {
405  $template->setCurrentBlock("answer_image");
406  if ($this->object->getThumbSize())
407  {
408  $template->setVariable("ANSWER_IMAGE_URL", $this->object->getImagePathWeb() . $this->object->getThumbPrefix() . $answer->getImage());
409  }
410  else
411  {
412  $template->setVariable("ANSWER_IMAGE_URL", $this->object->getImagePathWeb() . $answer->getImage());
413  }
414  $alt = $answer->getImage();
415  if (strlen($answer->getAnswertext()))
416  {
417  $alt = $answer->getAnswertext();
418  }
419  $alt = preg_replace("/<[^>]*?>/", "", $alt);
420  $template->setVariable("ANSWER_IMAGE_ALT", ilUtil::prepareFormOutput($alt));
421  $template->setVariable("ANSWER_IMAGE_TITLE", ilUtil::prepareFormOutput($alt));
422  $template->parseCurrentBlock();
423  }
424  if ($show_feedback)
425  {
426  foreach ($user_solution as $mc_solution)
427  {
428  if (strcmp($mc_solution, $answer_id) == 0)
429  {
430  $fb = $this->object->getFeedbackSingleAnswer($answer_id);
431  if (strlen($fb))
432  {
433  $template->setCurrentBlock("feedback");
434  $template->setVariable("FEEDBACK", $fb);
435  $template->parseCurrentBlock();
436  }
437  }
438  }
439  }
440  $template->setCurrentBlock("answer_row");
441  $template->setVariable("ANSWER_TEXT", $this->object->prepareTextareaOutput($answer->getAnswertext(), TRUE));
442  $checked = FALSE;
443  if ($result_output)
444  {
445  $pointschecked = $this->object->answers[$answer_id]->getPointsChecked();
446  $pointsunchecked = $this->object->answers[$answer_id]->getPointsUnchecked();
447  $resulttextchecked = ($pointschecked == 1) || ($pointschecked == -1) ? "%s " . $this->lng->txt("point") : "%s " . $this->lng->txt("points");
448  $resulttextunchecked = ($pointsunchecked == 1) || ($pointsunchecked == -1) ? "%s " . $this->lng->txt("point") : "%s " . $this->lng->txt("points");
449  $template->setVariable("RESULT_OUTPUT", sprintf("(" . $this->lng->txt("checkbox_checked") . " = $resulttextchecked, " . $this->lng->txt("checkbox_unchecked") . " = $resulttextunchecked)", $pointschecked, $pointsunchecked));
450  }
451  foreach ($user_solution as $mc_solution)
452  {
453  if (strcmp($mc_solution, $answer_id) == 0)
454  {
455  $template->setVariable("SOLUTION_IMAGE", ilUtil::getHtmlPath(ilUtil::getImagePath("checkbox_checked.gif")));
456  $template->setVariable("SOLUTION_ALT", $this->lng->txt("checked"));
457  $checked = TRUE;
458  }
459  }
460  if (!$checked)
461  {
462  $template->setVariable("SOLUTION_IMAGE", ilUtil::getHtmlPath(ilUtil::getImagePath("checkbox_unchecked.gif")));
463  $template->setVariable("SOLUTION_ALT", $this->lng->txt("unchecked"));
464  }
465  $template->parseCurrentBlock();
466  }
467  $questiontext = $this->object->getQuestion();
468  $template->setVariable("QUESTIONTEXT", $this->object->prepareTextareaOutput($questiontext, TRUE));
469  $questionoutput = $template->get();
470  $feedback = ($show_feedback) ? $this->getAnswerFeedbackOutput($active_id, $pass) : "";
471  if (strlen($feedback)) $solutiontemplate->setVariable("FEEDBACK", $feedback);
472  $solutiontemplate->setVariable("SOLUTION_OUTPUT", $questionoutput);
473 
474  $solutionoutput = $solutiontemplate->get();
475  if (!$show_question_only)
476  {
477  // get page object output
478  $solutionoutput = $this->getILIASPage($solutionoutput);
479  }
480  return $solutionoutput;
481  }
482 
483  function getPreview($show_question_only = FALSE)
484  {
485  // shuffle output
486  $keys = $this->getChoiceKeys();
487 
488  // generate the question output
489  include_once "./classes/class.ilTemplate.php";
490  $template = new ilTemplate("tpl.il_as_qpl_mc_mr_output.html", TRUE, TRUE, "Modules/TestQuestionPool");
491  foreach ($keys as $answer_id)
492  {
493  $answer = $this->object->answers[$answer_id];
494  if (strlen($answer->getImage()))
495  {
496  if ($this->object->getThumbSize())
497  {
498  $template->setCurrentBlock("preview");
499  $template->setVariable("URL_PREVIEW", $this->object->getImagePathWeb() . $answer->getImage());
500  $template->setVariable("TEXT_PREVIEW", $this->lng->txt('preview'));
501  $template->setVariable("IMG_PREVIEW", ilUtil::getImagePath('enlarge.gif'));
502  $template->setVariable("ANSWER_IMAGE_URL", $this->object->getImagePathWeb() . $this->object->getThumbPrefix() . $answer->getImage());
503  list($width, $height, $type, $attr) = getimagesize($this->object->getImagePath() . $answer->getImage());
504  $alt = $answer->getImage();
505  if (strlen($answer->getAnswertext()))
506  {
507  $alt = $answer->getAnswertext();
508  }
509  $alt = preg_replace("/<[^>]*?>/", "", $alt);
510  $template->setVariable("ANSWER_IMAGE_ALT", ilUtil::prepareFormOutput($alt));
511  $template->setVariable("ANSWER_IMAGE_TITLE", ilUtil::prepareFormOutput($alt));
512  $template->parseCurrentBlock();
513  }
514  else
515  {
516  $template->setCurrentBlock("answer_image");
517  $template->setVariable("ANSWER_IMAGE_URL", $this->object->getImagePathWeb() . $answer->getImage());
518  list($width, $height, $type, $attr) = getimagesize($this->object->getImagePath() . $answer->getImage());
519  $alt = $answer->getImage();
520  if (strlen($answer->getAnswertext()))
521  {
522  $alt = $answer->getAnswertext();
523  }
524  $alt = preg_replace("/<[^>]*?>/", "", $alt);
525  $template->setVariable("ATTR", $attr);
526  $template->setVariable("ANSWER_IMAGE_ALT", ilUtil::prepareFormOutput($alt));
527  $template->setVariable("ANSWER_IMAGE_TITLE", ilUtil::prepareFormOutput($alt));
528  $template->parseCurrentBlock();
529  }
530  }
531  $template->setCurrentBlock("answer_row");
532  $template->setVariable("ANSWER_ID", $answer_id);
533  $template->setVariable("ANSWER_TEXT", $this->object->prepareTextareaOutput($answer->getAnswertext(), TRUE));
534  $template->parseCurrentBlock();
535  }
536  $questiontext = $this->object->getQuestion();
537  $template->setVariable("QUESTIONTEXT", $this->object->prepareTextareaOutput($questiontext, TRUE));
538  $questionoutput = $template->get();
539  if (!$show_question_only)
540  {
541  // get page object output
542  $questionoutput = $this->getILIASPage($questionoutput);
543  }
544  return $questionoutput;
545  }
546 
547  function getTestOutput($active_id, $pass = NULL, $is_postponed = FALSE, $use_post_solutions = FALSE, $show_feedback = FALSE)
548  {
549  // shuffle output
550  $keys = $this->getChoiceKeys();
551 
552  // get the solution of the user for the active pass or from the last pass if allowed
553  $user_solution = array();
554  if ($active_id)
555  {
556  $solutions = NULL;
557  include_once "./Modules/Test/classes/class.ilObjTest.php";
558  if (!ilObjTest::_getUsePreviousAnswers($active_id, true))
559  {
560  if (is_null($pass)) $pass = ilObjTest::_getPass($active_id);
561  }
562  $solutions =& $this->object->getSolutionValues($active_id, $pass);
563  foreach ($solutions as $idx => $solution_value)
564  {
565  array_push($user_solution, $solution_value["value1"]);
566  }
567  }
568  // generate the question output
569  include_once "./classes/class.ilTemplate.php";
570  $template = new ilTemplate("tpl.il_as_qpl_mc_mr_output.html", TRUE, TRUE, "Modules/TestQuestionPool");
571  foreach ($keys as $answer_id)
572  {
573  $answer = $this->object->answers[$answer_id];
574  if (strlen($answer->getImage()))
575  {
576  if ($this->object->getThumbSize())
577  {
578  $template->setCurrentBlock("preview");
579  $template->setVariable("URL_PREVIEW", $this->object->getImagePathWeb() . $answer->getImage());
580  $template->setVariable("TEXT_PREVIEW", $this->lng->txt('preview'));
581  $template->setVariable("IMG_PREVIEW", ilUtil::getImagePath('enlarge.gif'));
582  $template->setVariable("ANSWER_IMAGE_URL", $this->object->getImagePathWeb() . $this->object->getThumbPrefix() . $answer->getImage());
583  list($width, $height, $type, $attr) = getimagesize($this->object->getImagePath() . $answer->getImage());
584  $alt = $answer->getImage();
585  if (strlen($answer->getAnswertext()))
586  {
587  $alt = $answer->getAnswertext();
588  }
589  $alt = preg_replace("/<[^>]*?>/", "", $alt);
590  $template->setVariable("ANSWER_IMAGE_ALT", ilUtil::prepareFormOutput($alt));
591  $template->setVariable("ANSWER_IMAGE_TITLE", ilUtil::prepareFormOutput($alt));
592  $template->parseCurrentBlock();
593  }
594  else
595  {
596  $template->setCurrentBlock("answer_image");
597  $template->setVariable("ANSWER_IMAGE_URL", $this->object->getImagePathWeb() . $answer->getImage());
598  list($width, $height, $type, $attr) = getimagesize($this->object->getImagePath() . $answer->getImage());
599  $alt = $answer->getImage();
600  if (strlen($answer->getAnswertext()))
601  {
602  $alt = $answer->getAnswertext();
603  }
604  $alt = preg_replace("/<[^>]*?>/", "", $alt);
605  $template->setVariable("ATTR", $attr);
606  $template->setVariable("ANSWER_IMAGE_ALT", ilUtil::prepareFormOutput($alt));
607  $template->setVariable("ANSWER_IMAGE_TITLE", ilUtil::prepareFormOutput($alt));
608  $template->parseCurrentBlock();
609  }
610  }
611 
612  foreach ($user_solution as $mc_solution)
613  {
614  if (strcmp($mc_solution, $answer_id) == 0)
615  {
616  if ($show_feedback)
617  {
618  $feedback = $this->object->getFeedbackSingleAnswer($answer_id);
619  if (strlen($feedback))
620  {
621  $template->setCurrentBlock("feedback");
622  $template->setVariable("FEEDBACK", $feedback);
623  $template->parseCurrentBlock();
624  }
625  }
626  }
627  }
628 
629  $template->setCurrentBlock("answer_row");
630  $template->setVariable("ANSWER_ID", $answer_id);
631  $template->setVariable("ANSWER_TEXT", $this->object->prepareTextareaOutput($answer->getAnswertext(), TRUE));
632  foreach ($user_solution as $mc_solution)
633  {
634  if (strcmp($mc_solution, $answer_id) == 0)
635  {
636  $template->setVariable("CHECKED_ANSWER", " checked=\"checked\"");
637  }
638  }
639  $template->parseCurrentBlock();
640  }
641  $questiontext = $this->object->getQuestion();
642  $template->setVariable("QUESTIONTEXT", $this->object->prepareTextareaOutput($questiontext, TRUE));
643  $questionoutput = $template->get();
644  $pageoutput = $this->outQuestionPage("", $is_postponed, $active_id, $questionoutput);
645  return $pageoutput;
646  }
647 
653  function saveFeedback()
654  {
655  include_once "./Services/AdvancedEditing/classes/class.ilObjAdvancedEditing.php";
656  $errors = $this->feedback(true);
657  $this->object->saveFeedbackGeneric(0, $_POST["feedback_incomplete"]);
658  $this->object->saveFeedbackGeneric(1, $_POST["feedback_complete"]);
659  foreach ($this->object->answers as $index => $answer)
660  {
661  $this->object->saveFeedbackSingleAnswer($index, $_POST["feedback_answer_$index"]);
662  }
663  $this->object->cleanupMediaObjectUsage();
665  }
666 
672  function feedback($checkonly = false)
673  {
674  $save = (strcmp($this->ctrl->getCmd(), "saveFeedback") == 0) ? TRUE : FALSE;
675  include_once("./Services/Form/classes/class.ilPropertyFormGUI.php");
676  $form = new ilPropertyFormGUI();
677  $form->setFormAction($this->ctrl->getFormAction($this));
678  $form->setTitle($this->lng->txt('feedback_answers'));
679  $form->setTableWidth("100%");
680  $form->setId("feedback");
681 
682  $complete = new ilTextAreaInputGUI($this->lng->txt("feedback_complete_solution"), "feedback_complete");
683  $complete->setValue($this->object->prepareTextareaOutput($this->object->getFeedbackGeneric(1)));
684  $complete->setRequired(false);
685  $complete->setRows(10);
686  $complete->setCols(80);
687  if (!$this->getPreventRteUsage())
688  {
689  $complete->setUseRte(true);
690  }
691  include_once "./Services/AdvancedEditing/classes/class.ilObjAdvancedEditing.php";
692  $complete->setRteTags(ilObjAdvancedEditing::_getUsedHTMLTags("assessment"));
693  $complete->addPlugin("latex");
694  $complete->addButton("latex");
695  $complete->addButton("pastelatex");
696  $complete->setRTESupport($this->object->getId(), "qpl", "assessment");
697  $form->addItem($complete);
698 
699  $incomplete = new ilTextAreaInputGUI($this->lng->txt("feedback_incomplete_solution"), "feedback_incomplete");
700  $incomplete->setValue($this->object->prepareTextareaOutput($this->object->getFeedbackGeneric(0)));
701  $incomplete->setRequired(false);
702  $incomplete->setRows(10);
703  $incomplete->setCols(80);
704  if (!$this->getPreventRteUsage())
705  {
706  $incomplete->setUseRte(true);
707  }
708  include_once "./Services/AdvancedEditing/classes/class.ilObjAdvancedEditing.php";
709  $incomplete->setRteTags(ilObjAdvancedEditing::_getUsedHTMLTags("assessment"));
710  $incomplete->addPlugin("latex");
711  $incomplete->addButton("latex");
712  $incomplete->addButton("pastelatex");
713  $incomplete->setRTESupport($this->object->getId(), "qpl", "assessment");
714  $form->addItem($incomplete);
715 
716  if (!$this->getSelfAssessmentEditingMode())
717  {
718  foreach ($this->object->answers as $index => $answer)
719  {
720  $answerobj = new ilTextAreaInputGUI($this->object->prepareTextareaOutput($answer->getAnswertext(), true), "feedback_answer_$index");
721  $answerobj->setValue($this->object->prepareTextareaOutput($this->object->getFeedbackSingleAnswer($index)));
722  $answerobj->setRequired(false);
723  $answerobj->setRows(10);
724  $answerobj->setCols(80);
725  $answerobj->setUseRte(true);
726  include_once "./Services/AdvancedEditing/classes/class.ilObjAdvancedEditing.php";
727  $answerobj->setRteTags(ilObjAdvancedEditing::_getUsedHTMLTags("assessment"));
728  $answerobj->addPlugin("latex");
729  $answerobj->addButton("latex");
730  $answerobj->addButton("pastelatex");
731  $answerobj->setRTESupport($this->object->getId(), "qpl", "assessment");
732  $form->addItem($answerobj);
733  }
734  }
735 
736  global $ilAccess;
737  if ($ilAccess->checkAccess("write", "", $_GET['ref_id']) || $this->getSelfAssessmentEditingMode())
738  {
739  $form->addCommandButton("saveFeedback", $this->lng->txt("save"));
740  }
741  if ($save)
742  {
743  $form->setValuesByPost();
744  $errors = !$form->checkInput();
745  $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
746  }
747  if (!$checkonly) $this->tpl->setVariable("ADM_CONTENT", $form->getHTML());
748  return $errors;
749  }
750 
756  function setQuestionTabs()
757  {
758  global $rbacsystem, $ilTabs;
759 
760  $this->ctrl->setParameterByClass("ilpageobjectgui", "q_id", $_GET["q_id"]);
761  include_once "./Modules/TestQuestionPool/classes/class.assQuestion.php";
762  $q_type = $this->object->getQuestionType();
763 
764  if (strlen($q_type))
765  {
766  $classname = $q_type . "GUI";
767  $this->ctrl->setParameterByClass(strtolower($classname), "sel_question_types", $q_type);
768  $this->ctrl->setParameterByClass(strtolower($classname), "q_id", $_GET["q_id"]);
769  }
770 
771  if ($_GET["q_id"])
772  {
773  if ($rbacsystem->checkAccess('write', $_GET["ref_id"]))
774  {
775  // edit page
776  $ilTabs->addTarget("edit_content",
777  $this->ctrl->getLinkTargetByClass("ilPageObjectGUI", "edit"),
778  array("edit", "insert", "exec_pg"),
779  "", "", $force_active);
780  }
781 
782  // edit page
783  $ilTabs->addTarget("preview",
784  $this->ctrl->getLinkTargetByClass("ilPageObjectGUI", "preview"),
785  array("preview"),
786  "ilPageObjectGUI", "", $force_active);
787  }
788  $force_active = false;
789  if ($rbacsystem->checkAccess('write', $_GET["ref_id"]))
790  {
791  $url = "";
792  if ($classname) $url = $this->ctrl->getLinkTargetByClass($classname, "editQuestion");
793  $force_active = false;
794  // edit question properties
795  $ilTabs->addTarget("edit_properties",
796  $url,
797  array("editQuestion", "save", "saveEdit", "addchoice", "removechoice", "removeimagechoice", "uploadchoice", "originalSyncForm"),
798  $classname, "", $force_active);
799  }
800 
801  if ($_GET["q_id"])
802  {
803  $ilTabs->addTarget("feedback",
804  $this->ctrl->getLinkTargetByClass($classname, "feedback"),
805  array("feedback", "saveFeedback"),
806  $classname, "");
807  }
808 
809  if ($_GET["q_id"])
810  {
811  $ilTabs->addTarget("solution_hint",
812  $this->ctrl->getLinkTargetByClass($classname, "suggestedsolution"),
813  array("suggestedsolution", "saveSuggestedSolution", "outSolutionExplorer", "cancel",
814  "addSuggestedSolution","cancelExplorer", "linkChilds", "removeSuggestedSolution"
815  ),
816  $classname,
817  ""
818  );
819  }
820 
821  // Assessment of questions sub menu entry
822  if ($_GET["q_id"])
823  {
824  $ilTabs->addTarget("statistics",
825  $this->ctrl->getLinkTargetByClass($classname, "assessment"),
826  array("assessment"),
827  $classname, "");
828  }
829 
830  if (($_GET["calling_test"] > 0) || ($_GET["test_ref_id"] > 0))
831  {
832  $ref_id = $_GET["calling_test"];
833  if (strlen($ref_id) == 0) $ref_id = $_GET["test_ref_id"];
834  $ilTabs->setBackTarget($this->lng->txt("backtocallingtest"), "ilias.php?baseClass=ilObjTestGUI&cmd=questions&ref_id=$ref_id");
835  }
836  else
837  {
838  $ilTabs->setBackTarget($this->lng->txt("qpl"), $this->ctrl->getLinkTargetByClass("ilobjquestionpoolgui", "questions"));
839  }
840  }
841 
842  /*
843  * Create the key index numbers for the array of choices
844  *
845  * @return array
846  */
847  function getChoiceKeys()
848  {
849  if (strcmp($_GET["activecommand"], "directfeedback") == 0)
850  {
851  if (is_array($_SESSION["choicekeys"])) $this->choiceKeys = $_SESSION["choicekeys"];
852  }
853  if (!is_array($this->choiceKeys))
854  {
855  $this->choiceKeys = array_keys($this->object->answers);
856  if ($this->object->getShuffle())
857  {
858  $this->choiceKeys = $this->object->pcArrayShuffle($this->choiceKeys);
859  }
860  }
861  $_SESSION["choicekeys"] = $this->choiceKeys;
862  return $this->choiceKeys;
863  }
864 }
865 ?>