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