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