ILIAS  Release_4_1_x_branch Revision 61804
 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 
229  if ($save)
230  {
231  $form->setValuesByPost();
232  $errors = !$form->checkInput();
233  $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
234  if ($errors) $checkonly = false;
235  }
236 
237  if (!$checkonly) $this->tpl->setVariable("QUESTION_DATA", $form->getHTML());
238  return $errors;
239  }
240 
244  public function uploadchoice()
245  {
246  $this->writePostData(true);
247  $position = key($_POST['cmd']['uploadchoice']);
248  $this->editQuestion();
249  }
250 
254  public function removeimagechoice()
255  {
256  $this->writePostData(true);
257  $position = key($_POST['cmd']['removeimagechoice']);
258  $filename = $_POST['choice']['imagename'][$position];
259  $this->object->removeAnswerImage($position);
260  $this->editQuestion();
261  }
262 
266  public function addchoice()
267  {
268  $this->writePostData(true);
269  $position = key($_POST['cmd']['addchoice']);
270  $this->object->addAnswer("", 0, $position+1);
271  $this->editQuestion();
272  }
273 
277  public function removechoice()
278  {
279  $this->writePostData(true);
280  $position = key($_POST['cmd']['removechoice']);
281  $this->object->deleteAnswer($position);
282  $this->editQuestion();
283  }
284 
285  function outQuestionForTest($formaction, $active_id, $pass = NULL, $is_postponed = FALSE, $use_post_solutions = FALSE, $show_feedback = FALSE)
286  {
287  $test_output = $this->getTestOutput($active_id, $pass, $is_postponed, $use_post_solutions, $show_feedback);
288  $this->tpl->setVariable("QUESTION_OUTPUT", $test_output);
289  $this->tpl->setVariable("FORMACTION", $formaction);
290  }
291 
306  $active_id,
307  $pass = NULL,
308  $graphicalOutput = FALSE,
309  $result_output = FALSE,
310  $show_question_only = TRUE,
311  $show_feedback = FALSE,
312  $show_correct_solution = FALSE,
313  $show_manual_scoring = FALSE
314  )
315  {
316  // shuffle output
317  $keys = $this->getChoiceKeys();
318 
319  // get the solution of the user for the active pass or from the last pass if allowed
320  $user_solution = "";
321  if (($active_id > 0) && (!$show_correct_solution))
322  {
323  $solutions =& $this->object->getSolutionValues($active_id, $pass);
324  foreach ($solutions as $idx => $solution_value)
325  {
326  $user_solution = $solution_value["value1"];
327  }
328  }
329  else
330  {
331  $found_index = -1;
332  $max_points = 0;
333  foreach ($this->object->answers as $index => $answer)
334  {
335  if ($answer->getPoints() > $max_points)
336  {
337  $max_points = $answer->getPoints();
338  $found_index = $index;
339  }
340  }
341  $user_solution = $found_index;
342  }
343  // generate the question output
344  include_once "./classes/class.ilTemplate.php";
345  $template = new ilTemplate("tpl.il_as_qpl_mc_sr_output_solution.html", TRUE, TRUE, "Modules/TestQuestionPool");
346  $solutiontemplate = new ilTemplate("tpl.il_as_tst_solution_output.html",TRUE, TRUE, "Modules/TestQuestionPool");
347  foreach ($keys as $answer_id)
348  {
349  $answer = $this->object->answers[$answer_id];
350  if (($active_id > 0) && (!$show_correct_solution))
351  {
352  if ($graphicalOutput)
353  {
354  // output of ok/not ok icons for user entered solutions
355  $ok = FALSE;
356  if (strcmp($user_solution, $answer_id) == 0)
357  {
358  if ($answer->getPoints() == $this->object->getMaximumPoints())
359  {
360  $ok = TRUE;
361  }
362  else
363  {
364  $ok = FALSE;
365  }
366  if ($ok)
367  {
368  $template->setCurrentBlock("icon_ok");
369  $template->setVariable("ICON_OK", ilUtil::getImagePath("icon_ok.gif"));
370  $template->setVariable("TEXT_OK", $this->lng->txt("answer_is_right"));
371  $template->parseCurrentBlock();
372  }
373  else
374  {
375  $template->setCurrentBlock("icon_not_ok");
376  if ($answer->getPoints() > 0)
377  {
378  $template->setVariable("ICON_NOT_OK", ilUtil::getImagePath("icon_mostly_ok.gif"));
379  $template->setVariable("TEXT_NOT_OK", $this->lng->txt("answer_is_not_correct_but_positive"));
380  }
381  else
382  {
383  $template->setVariable("ICON_NOT_OK", ilUtil::getImagePath("icon_not_ok.gif"));
384  $template->setVariable("TEXT_NOT_OK", $this->lng->txt("answer_is_wrong"));
385  }
386  $template->parseCurrentBlock();
387  }
388  }
389  if (strlen($user_solution) == 0)
390  {
391  $template->setCurrentBlock("icon_not_ok");
392  $template->setVariable("ICON_NOT_OK", ilUtil::getImagePath("icon_not_ok.gif"));
393  $template->setVariable("TEXT_NOT_OK", $this->lng->txt("answer_is_wrong"));
394  $template->parseCurrentBlock();
395  }
396  }
397  }
398  if (strlen($answer->getImage()))
399  {
400  $template->setCurrentBlock("answer_image");
401  if ($this->object->getThumbSize())
402  {
403  $template->setVariable("ANSWER_IMAGE_URL", $this->object->getImagePathWeb() . $this->object->getThumbPrefix() . $answer->getImage());
404  }
405  else
406  {
407  $template->setVariable("ANSWER_IMAGE_URL", $this->object->getImagePathWeb() . $answer->getImage());
408  }
409  $alt = $answer->getImage();
410  if (strlen($answer->getAnswertext()))
411  {
412  $alt = $answer->getAnswertext();
413  }
414  $alt = preg_replace("/<[^>]*?>/", "", $alt);
415  $template->setVariable("ANSWER_IMAGE_ALT", ilUtil::prepareFormOutput($alt));
416  $template->setVariable("ANSWER_IMAGE_TITLE", ilUtil::prepareFormOutput($alt));
417  $template->parseCurrentBlock();
418  }
419  if ($show_feedback)
420  {
421  if (strcmp($user_solution, $answer_id) == 0)
422  {
423  $fb = $this->object->getFeedbackSingleAnswer($answer_id);
424  if (strlen($fb))
425  {
426  $template->setCurrentBlock("feedback");
427  $template->setVariable("FEEDBACK", $fb);
428  $template->parseCurrentBlock();
429  }
430  }
431  }
432  $template->setCurrentBlock("answer_row");
433  $template->setVariable("ANSWER_TEXT", $this->object->prepareTextareaOutput($answer->getAnswertext(), TRUE));
434  if (strcmp($user_solution, $answer_id) == 0)
435  {
436  $template->setVariable("SOLUTION_IMAGE", ilUtil::getHtmlPath(ilUtil::getImagePath("radiobutton_checked.gif")));
437  $template->setVariable("SOLUTION_ALT", $this->lng->txt("checked"));
438  }
439  else
440  {
441  $template->setVariable("SOLUTION_IMAGE", ilUtil::getHtmlPath(ilUtil::getImagePath("radiobutton_unchecked.gif")));
442  $template->setVariable("SOLUTION_ALT", $this->lng->txt("unchecked"));
443  }
444  if ($result_output)
445  {
446  $points = $this->object->answers[$answer_id]->getPoints();
447  $resulttext = ($points == 1) ? "(%s " . $this->lng->txt("point") . ")" : "(%s " . $this->lng->txt("points") . ")";
448  $template->setVariable("RESULT_OUTPUT", sprintf($resulttext, $points));
449  }
450  $template->parseCurrentBlock();
451  }
452  $questiontext = $this->object->getQuestion();
453  $template->setVariable("QUESTIONTEXT", $this->object->prepareTextareaOutput($questiontext, TRUE));
454  $questionoutput = $template->get();
455  $feedback = ($show_feedback) ? $this->getAnswerFeedbackOutput($active_id, $pass) : "";
456  if (strlen($feedback)) $solutiontemplate->setVariable("FEEDBACK", $feedback);
457  $solutiontemplate->setVariable("SOLUTION_OUTPUT", $questionoutput);
458 
459  $solutionoutput = $solutiontemplate->get();
460  if (!$show_question_only)
461  {
462  // get page object output
463  $solutionoutput = $this->getILIASPage($solutionoutput);
464  }
465  return $solutionoutput;
466  }
467 
468  function getPreview($show_question_only = FALSE)
469  {
470  $keys = $this->getChoiceKeys();
471 
472  // generate the question output
473  include_once "./classes/class.ilTemplate.php";
474  $template = new ilTemplate("tpl.il_as_qpl_mc_sr_output.html", TRUE, TRUE, "Modules/TestQuestionPool");
475  foreach ($keys as $answer_id)
476  {
477  $answer = $this->object->answers[$answer_id];
478  if (strlen($answer->getImage()))
479  {
480  if ($this->object->getThumbSize())
481  {
482  $template->setCurrentBlock("preview");
483  $template->setVariable("URL_PREVIEW", $this->object->getImagePathWeb() . $answer->getImage());
484  $template->setVariable("TEXT_PREVIEW", $this->lng->txt('preview'));
485  $template->setVariable("IMG_PREVIEW", ilUtil::getImagePath('enlarge.gif'));
486  $template->setVariable("ANSWER_IMAGE_URL", $this->object->getImagePathWeb() . $this->object->getThumbPrefix() . $answer->getImage());
487  list($width, $height, $type, $attr) = getimagesize($this->object->getImagePath() . $answer->getImage());
488  $alt = $answer->getImage();
489  if (strlen($answer->getAnswertext()))
490  {
491  $alt = $answer->getAnswertext();
492  }
493  $alt = preg_replace("/<[^>]*?>/", "", $alt);
494  $template->setVariable("ANSWER_IMAGE_ALT", ilUtil::prepareFormOutput($alt));
495  $template->setVariable("ANSWER_IMAGE_TITLE", ilUtil::prepareFormOutput($alt));
496  $template->parseCurrentBlock();
497  }
498  else
499  {
500  $template->setCurrentBlock("answer_image");
501  $template->setVariable("ANSWER_IMAGE_URL", $this->object->getImagePathWeb() . $answer->getImage());
502  list($width, $height, $type, $attr) = getimagesize($this->object->getImagePath() . $answer->getImage());
503  $alt = $answer->getImage();
504  if (strlen($answer->getAnswertext()))
505  {
506  $alt = $answer->getAnswertext();
507  }
508  $alt = preg_replace("/<[^>]*?>/", "", $alt);
509  $template->setVariable("ATTR", $attr);
510  $template->setVariable("ANSWER_IMAGE_ALT", ilUtil::prepareFormOutput($alt));
511  $template->setVariable("ANSWER_IMAGE_TITLE", ilUtil::prepareFormOutput($alt));
512  $template->parseCurrentBlock();
513  }
514  }
515  $template->setCurrentBlock("answer_row");
516  $template->setVariable("ANSWER_ID", $answer_id);
517  $template->setVariable("ANSWER_TEXT", $this->object->prepareTextareaOutput($answer->getAnswertext(), TRUE));
518  $template->parseCurrentBlock();
519  }
520  $questiontext = $this->object->getQuestion();
521  $template->setVariable("QUESTIONTEXT", $this->object->prepareTextareaOutput($questiontext, TRUE));
522  $questionoutput = $template->get();
523  if (!$show_question_only)
524  {
525  // get page object output
526  $questionoutput = $this->getILIASPage($questionoutput);
527  }
528  return $questionoutput;
529  }
530 
531  function getTestOutput($active_id, $pass = NULL, $is_postponed = FALSE, $use_post_solutions = FALSE, $show_feedback = FALSE)
532  {
533  $keys = $this->getChoiceKeys();
534 
535  // get the solution of the user for the active pass or from the last pass if allowed
536  $user_solution = "";
537  if ($active_id)
538  {
539  $solutions = NULL;
540  include_once "./Modules/Test/classes/class.ilObjTest.php";
541  if (!ilObjTest::_getUsePreviousAnswers($active_id, true))
542  {
543  if (is_null($pass)) $pass = ilObjTest::_getPass($active_id);
544  }
545  $solutions =& $this->object->getSolutionValues($active_id, $pass);
546  foreach ($solutions as $idx => $solution_value)
547  {
548  $user_solution = $solution_value["value1"];
549  }
550  }
551 
552  // generate the question output
553  include_once "./classes/class.ilTemplate.php";
554  $template = new ilTemplate("tpl.il_as_qpl_mc_sr_output.html", TRUE, TRUE, "Modules/TestQuestionPool");
555  foreach ($keys as $answer_id)
556  {
557  $answer = $this->object->answers[$answer_id];
558  if (strlen($answer->getImage()))
559  {
560  if ($this->object->getThumbSize())
561  {
562  $template->setCurrentBlock("preview");
563  $template->setVariable("URL_PREVIEW", $this->object->getImagePathWeb() . $answer->getImage());
564  $template->setVariable("TEXT_PREVIEW", $this->lng->txt('preview'));
565  $template->setVariable("IMG_PREVIEW", ilUtil::getImagePath('enlarge.gif'));
566  $template->setVariable("ANSWER_IMAGE_URL", $this->object->getImagePathWeb() . $this->object->getThumbPrefix() . $answer->getImage());
567  list($width, $height, $type, $attr) = getimagesize($this->object->getImagePath() . $answer->getImage());
568  $alt = $answer->getImage();
569  if (strlen($answer->getAnswertext()))
570  {
571  $alt = $answer->getAnswertext();
572  }
573  $alt = preg_replace("/<[^>]*?>/", "", $alt);
574  $template->setVariable("ANSWER_IMAGE_ALT", ilUtil::prepareFormOutput($alt));
575  $template->setVariable("ANSWER_IMAGE_TITLE", ilUtil::prepareFormOutput($alt));
576  $template->parseCurrentBlock();
577  }
578  else
579  {
580  $template->setCurrentBlock("answer_image");
581  $template->setVariable("ANSWER_IMAGE_URL", $this->object->getImagePathWeb() . $answer->getImage());
582  list($width, $height, $type, $attr) = getimagesize($this->object->getImagePath() . $answer->getImage());
583  $alt = $answer->getImage();
584  if (strlen($answer->getAnswertext()))
585  {
586  $alt = $answer->getAnswertext();
587  }
588  $alt = preg_replace("/<[^>]*?>/", "", $alt);
589  $template->setVariable("ATTR", $attr);
590  $template->setVariable("ANSWER_IMAGE_ALT", ilUtil::prepareFormOutput($alt));
591  $template->setVariable("ANSWER_IMAGE_TITLE", ilUtil::prepareFormOutput($alt));
592  $template->parseCurrentBlock();
593  }
594  }
595  if ($show_feedback)
596  {
597  if (strcmp($user_solution, $answer_id) == 0)
598  {
599  $feedback = $this->object->getFeedbackSingleAnswer($answer_id);
600  if (strlen($feedback))
601  {
602  $template->setCurrentBlock("feedback");
603  $template->setVariable("FEEDBACK", $this->object->prepareTextareaOutput($feedback, TRUE));
604  $template->parseCurrentBlock();
605  }
606  }
607  }
608  $template->setCurrentBlock("answer_row");
609  $template->setVariable("ANSWER_ID", $answer_id);
610  $template->setVariable("ANSWER_TEXT", $this->object->prepareTextareaOutput($answer->getAnswertext(), TRUE));
611  if (strcmp($user_solution, $answer_id) == 0)
612  {
613  $template->setVariable("CHECKED_ANSWER", " checked=\"checked\"");
614  }
615  $template->parseCurrentBlock();
616  }
617  $questiontext = $this->object->getQuestion();
618  $template->setVariable("QUESTIONTEXT", $this->object->prepareTextareaOutput($questiontext, TRUE));
619  $questionoutput = $template->get();
620  $pageoutput = $this->outQuestionPage("", $is_postponed, $active_id, $questionoutput);
621  return $pageoutput;
622  }
623 
629  function saveFeedback()
630  {
631  include_once "./Services/AdvancedEditing/classes/class.ilObjAdvancedEditing.php";
632  $errors = $this->feedback(true);
633  $this->object->saveFeedbackGeneric(0, $_POST["feedback_incomplete"]);
634  $this->object->saveFeedbackGeneric(1, $_POST["feedback_complete"]);
635  foreach ($this->object->answers as $index => $answer)
636  {
637  $this->object->saveFeedbackSingleAnswer($index, $_POST["feedback_answer_$index"]);
638  }
639  $this->object->cleanupMediaObjectUsage();
641  }
642 
648  function feedback($checkonly = false)
649  {
650  $save = (strcmp($this->ctrl->getCmd(), "saveFeedback") == 0) ? TRUE : FALSE;
651  include_once("./Services/Form/classes/class.ilPropertyFormGUI.php");
652  $form = new ilPropertyFormGUI();
653  $form->setFormAction($this->ctrl->getFormAction($this));
654  $form->setTitle($this->lng->txt('feedback_answers'));
655  $form->setTableWidth("100%");
656  $form->setId("feedback");
657 
658  $complete = new ilTextAreaInputGUI($this->lng->txt("feedback_complete_solution"), "feedback_complete");
659  $complete->setValue($this->object->prepareTextareaOutput($this->object->getFeedbackGeneric(1)));
660  $complete->setRequired(false);
661  $complete->setRows(10);
662  $complete->setCols(80);
663  if (!$this->getPreventRteUsage())
664  {
665  $complete->setUseRte(true);
666  }
667  include_once "./Services/AdvancedEditing/classes/class.ilObjAdvancedEditing.php";
668  $complete->setRteTags(ilObjAdvancedEditing::_getUsedHTMLTags("assessment"));
669  $complete->addPlugin("latex");
670  $complete->addButton("latex");
671  $complete->addButton("pastelatex");
672  $complete->setRTESupport($this->object->getId(), "qpl", "assessment");
673  $form->addItem($complete);
674 
675  $incomplete = new ilTextAreaInputGUI($this->lng->txt("feedback_incomplete_solution"), "feedback_incomplete");
676  $incomplete->setValue($this->object->prepareTextareaOutput($this->object->getFeedbackGeneric(0)));
677  $incomplete->setRequired(false);
678  $incomplete->setRows(10);
679  $incomplete->setCols(80);
680  if (!$this->getPreventRteUsage())
681  {
682  $incomplete->setUseRte(true);
683  }
684  include_once "./Services/AdvancedEditing/classes/class.ilObjAdvancedEditing.php";
685  $incomplete->setRteTags(ilObjAdvancedEditing::_getUsedHTMLTags("assessment"));
686  $incomplete->addPlugin("latex");
687  $incomplete->addButton("latex");
688  $incomplete->addButton("pastelatex");
689  $incomplete->setRTESupport($this->object->getId(), "qpl", "assessment");
690  $form->addItem($incomplete);
691 
692  if (!$this->getSelfAssessmentEditingMode())
693  {
694  foreach ($this->object->answers as $index => $answer)
695  {
696  $answerobj = new ilTextAreaInputGUI($this->object->prepareTextareaOutput($answer->getAnswertext(), true), "feedback_answer_$index");
697  $answerobj->setValue($this->object->prepareTextareaOutput($this->object->getFeedbackSingleAnswer($index)));
698  $answerobj->setRequired(false);
699  $answerobj->setRows(10);
700  $answerobj->setCols(80);
701  $answerobj->setUseRte(true);
702  include_once "./Services/AdvancedEditing/classes/class.ilObjAdvancedEditing.php";
703  $answerobj->setRteTags(ilObjAdvancedEditing::_getUsedHTMLTags("assessment"));
704  $answerobj->addPlugin("latex");
705  $answerobj->addButton("latex");
706  $answerobj->addButton("pastelatex");
707  $answerobj->setRTESupport($this->object->getId(), "qpl", "assessment");
708  $form->addItem($answerobj);
709  }
710  }
711 
712  global $ilAccess;
713  if ($ilAccess->checkAccess("write", "", $_GET['ref_id']) || $this->getSelfAssessmentEditingMode())
714  {
715  $form->addCommandButton("saveFeedback", $this->lng->txt("save"));
716  }
717  if ($save)
718  {
719  $form->setValuesByPost();
720  $errors = !$form->checkInput();
721  $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
722  }
723  if (!$checkonly) $this->tpl->setVariable("ADM_CONTENT", $form->getHTML());
724  return $errors;
725  }
726 
732  function setQuestionTabs()
733  {
734  global $rbacsystem, $ilTabs;
735 
736  $this->ctrl->setParameterByClass("ilpageobjectgui", "q_id", $_GET["q_id"]);
737  include_once "./Modules/TestQuestionPool/classes/class.assQuestion.php";
738  $q_type = $this->object->getQuestionType();
739 
740  if (strlen($q_type))
741  {
742  $classname = $q_type . "GUI";
743  $this->ctrl->setParameterByClass(strtolower($classname), "sel_question_types", $q_type);
744  $this->ctrl->setParameterByClass(strtolower($classname), "q_id", $_GET["q_id"]);
745  }
746 
747  if ($_GET["q_id"])
748  {
749  if ($rbacsystem->checkAccess('write', $_GET["ref_id"]))
750  {
751  // edit page
752  $ilTabs->addTarget("edit_content",
753  $this->ctrl->getLinkTargetByClass("ilPageObjectGUI", "edit"),
754  array("edit", "insert", "exec_pg"),
755  "", "", $force_active);
756  }
757 
758  // edit page
759  $ilTabs->addTarget("preview",
760  $this->ctrl->getLinkTargetByClass("ilPageObjectGUI", "preview"),
761  array("preview"),
762  "ilPageObjectGUI", "", $force_active);
763  }
764 
765  $force_active = false;
766  if ($rbacsystem->checkAccess('write', $_GET["ref_id"]))
767  {
768  $url = "";
769  if ($classname) $url = $this->ctrl->getLinkTargetByClass($classname, "editQuestion");
770  // edit question properties
771  $ilTabs->addTarget("edit_properties",
772  $url,
773  array("editQuestion", "save", "saveEdit", "addchoice", "removechoice", "removeimagechoice", "uploadchoice", "originalSyncForm"),
774  $classname, "", $force_active);
775  }
776 
777  if ($_GET["q_id"])
778  {
779  $ilTabs->addTarget("feedback",
780  $this->ctrl->getLinkTargetByClass($classname, "feedback"),
781  array("feedback", "saveFeedback"),
782  $classname, "");
783  }
784 
785  if ($_GET["q_id"])
786  {
787  $ilTabs->addTarget("solution_hint",
788  $this->ctrl->getLinkTargetByClass($classname, "suggestedsolution"),
789  array("suggestedsolution", "saveSuggestedSolution", "outSolutionExplorer", "cancel",
790  "addSuggestedSolution","cancelExplorer", "linkChilds", "removeSuggestedSolution"
791  ),
792  $classname,
793  ""
794  );
795  }
796 
797  // Assessment of questions sub menu entry
798  if ($_GET["q_id"])
799  {
800  $ilTabs->addTarget("statistics",
801  $this->ctrl->getLinkTargetByClass($classname, "assessment"),
802  array("assessment"),
803  $classname, "");
804  }
805 
806  if (($_GET["calling_test"] > 0) || ($_GET["test_ref_id"] > 0))
807  {
808  $ref_id = $_GET["calling_test"];
809  if (strlen($ref_id) == 0) $ref_id = $_GET["test_ref_id"];
810  $ilTabs->setBackTarget($this->lng->txt("backtocallingtest"), "ilias.php?baseClass=ilObjTestGUI&cmd=questions&ref_id=$ref_id");
811  }
812  else
813  {
814  $ilTabs->setBackTarget($this->lng->txt("qpl"), $this->ctrl->getLinkTargetByClass("ilobjquestionpoolgui", "questions"));
815  }
816  }
817 
818  /*
819  * Create the key index numbers for the array of choices
820  *
821  * @return array
822  */
823  function getChoiceKeys()
824  {
825  if (strcmp($_GET["activecommand"], "directfeedback") == 0)
826  {
827  if (is_array($_SESSION["choicekeys"])) $this->choiceKeys = $_SESSION["choicekeys"];
828  }
829  if (!is_array($this->choiceKeys))
830  {
831  $this->choiceKeys = array_keys($this->object->answers);
832  if ($this->object->getShuffle())
833  {
834  $this->choiceKeys = $this->object->pcArrayShuffle($this->choiceKeys);
835  }
836  }
837  $_SESSION["choicekeys"] = $this->choiceKeys;
838  return $this->choiceKeys;
839  }
840 
841 
842 }
843 ?>