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