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