ILIAS  release_4-3 Revision
 All Data Structures Namespaces Files Functions Variables Groups Pages
class.assOrderingQuestionGUI.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 {
40  private $uploadAlert = null;
41 
50  function __construct($id = -1)
51  {
53  include_once "./Modules/TestQuestionPool/classes/class.assOrderingQuestion.php";
54  $this->object = new assOrderingQuestion();
55  if ($id >= 0)
56  {
57  $this->object->loadFromDb($id);
58  }
59  }
60 
61  function getCommand($cmd)
62  {
63  return $cmd;
64  }
65 
66  public function changeToPictures()
67  {
68  $this->writePostData(true, true);
69  $this->editQuestion();
70  }
71 
72  public function changeToText()
73  {
74  $this->writePostData(true, true);
75  $this->editQuestion();
76  }
77 
78  public function addanswers()
79  {
80  $this->writePostData(true);
81  $position = key($_POST["cmd"]["addanswers"]);
82  $this->object->addAnswer("", $position+1);
83  $this->editQuestion();
84  }
85 
86  public function removeimageanswers()
87  {
88  $this->writePostData(true);
89  $position = key($_POST['cmd']['removeimageanswers']);
90  $filename = $_POST['answers']['imagename'][$position];
91  $this->object->removeAnswerImage($position);
92  $this->editQuestion();
93  }
94 
95  public function removeanswers()
96  {
97  $this->writePostData(true);
98  $position = key($_POST["cmd"]["removeanswers"]);
99  $this->object->deleteAnswer($position);
100  $this->editQuestion();
101  }
102 
103  public function upanswers()
104  {
105  $this->writePostData(true);
106  $position = key($_POST["cmd"]["upanswers"]);
107  $this->object->moveAnswerUp($position);
108  $this->editQuestion();
109  }
110 
111  public function downanswers()
112  {
113  $this->writePostData(true);
114  $position = key($_POST["cmd"]["downanswers"]);
115  $this->object->moveAnswerDown($position);
116  $this->editQuestion();
117  }
118 
123  {
124  include_once "./Modules/TestQuestionPool/classes/class.ilImageWizardInputGUI.php";
125  $answers = new ilImageWizardInputGUI($this->lng->txt("answers"), "answers");
126  $answers->setRequired(TRUE);
127  $answers->setQuestionObject($this->object);
128  $answers->setInfo($this->lng->txt('ordering_answer_sequence_info'));
129  $answers->setAllowMove(TRUE);
130  $answervalues = array();
131  foreach ($this->object->getAnswers() as $index => $answervalue)
132  {
133  $answervalues[$index] = $answervalue->getAnswertext();
134  }
135  $answers->setValues($answervalues);
136  return $answers;
137  }
138 
139  public function uploadanswers()
140  {
142  if( !$inp->checkInput() )
143  {
144  $this->uploadAlert = $inp->getAlert();
145  }
146 
147  $this->writePostData(true);
148  $this->editQuestion();
149  }
150 
151  private function isUploadAnswersCommand()
152  {
153  return $this->ctrl->getCmd() == 'uploadanswers';
154  }
155 
162  function writePostData($always = false, $clear_answers = false)
163  {
164  $hasErrors = (!$always) ? $this->editQuestion(true) : false;
165  if (!$hasErrors)
166  {
167  $this->object->setTitle($_POST["title"]);
168  $this->object->setAuthor($_POST["author"]);
169  $this->object->setComment($_POST["comment"]);
170  include_once "./Services/AdvancedEditing/classes/class.ilObjAdvancedEditing.php";
171  $questiontext = $_POST["question"];
172  $this->object->setQuestion($questiontext);
173  $this->object->setThumbGeometry($_POST["thumb_geometry"]);
174  $this->object->setElementHeight($_POST["element_height"]);
175  if ($this->getSelfAssessmentEditingMode())
176  {
177  $this->object->setNrOfTries($_POST['nr_of_tries']);
178  }
179  // adding estimated working time
180  $this->object->setEstimatedWorkingTime(
181  $_POST["Estimated"]["hh"],
182  $_POST["Estimated"]["mm"],
183  $_POST["Estimated"]["ss"]
184  );
185  $ordering_type = $_POST["ordering_type"];
186  $this->object->setOrderingType($ordering_type);
187 
188  // Delete all existing answers and create new answers from the form data
189  $this->object->flushAnswers();
190  $saved = false;
191 
192  // add answers
193  if ($_POST['ordering_type'] == OQ_TERMS)
194  {
195  $answers = $_POST["answers"];
196  if (is_array($answers))
197  {
198  foreach ($answers as $index => $answer)
199  {
200  if($clear_answers)
201  {
202  $answer = "";
203  }
204  $this->object->addAnswer($answer);
205  }
206  }
207  }
208  else
209  {
210  foreach (array_keys($_POST['answers']['count']) as $index)
211  {
212  if($clear_answers)
213  {
214  $this->object->addAnswer("");
215  continue;
216  }
217 
218  $picturefile = $_POST['answers']['imagename'][$index];
219  $file_org_name = $_FILES['answers']['name']['image'][$index];
220  $file_temp_name = $_FILES['answers']['tmp_name']['image'][$index];
221 
222  // new file
223  if (strlen($file_temp_name))
224  {
225  // check suffix
226  $suffix = strtolower(array_pop(explode(".", $file_org_name)));
227  if(in_array($suffix, array("jpg", "jpeg", "png", "gif")))
228  {
229  // upload image
230  $filename = $this->object->createNewImageFileName($file_org_name);
231  $filename = $this->object->getEncryptedFilename($filename);
232  if ($this->object->setImageFile($file_temp_name, $filename, $picturefile))
233  {
234  $picturefile = $filename;
235  }
236  }
237  }
238 
239  $this->object->addAnswer($picturefile);
240  }
241  }
242  $this->object->setPoints($_POST["points"]);
243  return 0;
244  }
245  else
246  {
247  return 1;
248  }
249  }
250 
256  function editQuestion($checkonly = FALSE)
257  {
258  $save = $this->isSaveCommand();
259  $this->getQuestionTemplate();
260 
261  include_once("./Services/Form/classes/class.ilPropertyFormGUI.php");
262  $orderingtype = (array_key_exists('ordering_type', $_POST)) ? $_POST['ordering_type'] : $this->object->getOrderingType();
263  if (strcmp($this->ctrl->getCmd(), 'changeToText') == 0) $orderingtype = OQ_TERMS;
264  if (strcmp($this->ctrl->getCmd(), 'changeToPictures') == 0) $orderingtype = OQ_PICTURES;
265  $form = new ilPropertyFormGUI();
266  $form->setFormAction($this->ctrl->getFormAction($this));
267  $form->setTitle($this->outQuestionType());
268  $form->setMultipart(($orderingtype == OQ_PICTURES) ? TRUE : FALSE);
269  $form->setTableWidth("100%");
270  $form->setId("ordering");
271 
272  // Edit mode
273  $hidden = new ilHiddenInputGUI("ordering_type");
274  $hidden->setValue($orderingtype);
275  $form->addItem($hidden);
276 
277  // title, author, description, question, working time (assessment mode)
278  $this->addBasicQuestionFormProperties($form);
279 
280  if (!$this->getSelfAssessmentEditingMode())
281  {
282  $element_height = new ilNumberInputGUI($this->lng->txt("element_height"), "element_height");
283  $element_height->setValue($this->object->getElementHeight());
284  $element_height->setRequired(false);
285  $element_height->setMaxLength(6);
286  $element_height->setMinValue(20);
287  $element_height->setSize(6);
288  $element_height->setInfo($this->lng->txt("element_height_info"));
289  $form->addItem($element_height);
290  }
291 
292  if ($orderingtype == OQ_PICTURES)
293  {
294  $geometry = new ilNumberInputGUI($this->lng->txt("thumb_geometry"), "thumb_geometry");
295  $geometry->setValue($this->object->getThumbGeometry());
296  $geometry->setRequired(true);
297  $geometry->setMaxLength(6);
298  $geometry->setMinValue(20);
299  $geometry->setSize(6);
300  $geometry->setInfo($this->lng->txt("thumb_geometry_info"));
301  $form->addItem($geometry);
302  }
303  if (count($this->object->getAnswers()) == 0)
304  {
305  $this->object->addAnswer();
306  }
307  // Answers
308  if ($orderingtype == OQ_PICTURES)
309  {
310  $answerImageUpload = $this->getAnswerImageFileUploadWizardFormProperty();
311  if( $this->uploadAlert !== null )
312  {
313  $answerImageUpload->setAlert($this->uploadAlert);
314  }
315  $form->addItem($answerImageUpload);
316  }
317  else
318  {
319  $answers = new ilTextWizardInputGUI($this->lng->txt("answers"), "answers");
320  $answers->setRequired(TRUE);
321  $answers->setInfo($this->lng->txt('ordering_answer_sequence_info'));
322  $answers->setAllowMove(TRUE);
323  $answervalues = array();
324  foreach ($this->object->getAnswers() as $index => $answervalue)
325  {
326  $answervalues[$index] = $answervalue->getAnswertext();
327  }
328  ksort($answervalues);
329  $answers->setValues($answervalues);
330  $form->addItem($answers);
331  }
332  // points
333  $points = new ilNumberInputGUI($this->lng->txt("points"), "points");
334  $points->allowDecimals(true);
335  $points->setValue($this->object->getPoints());
336  $points->setRequired(TRUE);
337  $points->setSize(3);
338  $points->setMinValue(0);
339  $points->setMinvalueShouldBeGreater(true);
340  $form->addItem($points);
341 
342  if (true || !$this->getSelfAssessmentEditingMode())
343  {
344  if ($orderingtype == OQ_PICTURES)
345  {
346  $form->addCommandButton("changeToText", $this->lng->txt("order_terms"));
347  }
348  else
349  {
350  $form->addCommandButton("changeToPictures", $this->lng->txt("order_pictures"));
351  }
352  }
353 
354  $this->addQuestionFormCommandButtons($form);
355 
356  $errors = false;
357 
358  if ($save)
359  {
360  $form->setValuesByPost();
361  $errors = !$form->checkInput();
362  $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
363  if ($errors) $checkonly = false;
364  }
365 
366  if (!$checkonly) $this->tpl->setVariable("QUESTION_DATA", $form->getHTML());
367  return $errors;
368  }
369 
370  function outQuestionForTest($formaction, $active_id, $pass = NULL, $is_postponed = FALSE, $user_post_solution = FALSE)
371  {
372  $test_output = $this->getTestOutput($active_id, $pass, $is_postponed, $user_post_solution);
373  $this->tpl->setVariable("QUESTION_OUTPUT", $test_output);
374  $this->tpl->setVariable("FORMACTION", $formaction);
375  }
376 
391  $active_id,
392  $pass = NULL,
393  $graphicalOutput = FALSE,
394  $result_output = FALSE,
395  $show_question_only = TRUE,
396  $show_feedback = FALSE,
397  $show_correct_solution = FALSE,
398  $show_manual_scoring = FALSE,
399  $show_question_text = TRUE
400  )
401  {
402  // shuffle output
403  $keys = array_keys($this->object->answers);
404 
405  // generate the question output
406  include_once "./Services/UICore/classes/class.ilTemplate.php";
407  $template = new ilTemplate("tpl.il_as_qpl_ordering_output_solution.html", TRUE, TRUE, "Modules/TestQuestionPool");
408  $solutiontemplate = new ilTemplate("tpl.il_as_tst_solution_output.html",TRUE, TRUE, "Modules/TestQuestionPool");
409 
410  // get the solution of the user for the active pass or from the last pass if allowed
411  $solutions = array();
412  if (($active_id > 0) && (!$show_correct_solution))
413  {
414  $solutions =& $this->object->getSolutionValues($active_id, $pass);
415  }
416  else
417  {
418  foreach ($this->object->answers as $index => $answer)
419  {
420  array_push($solutions, array("value1" => $index, "value2" => $index+1));
421  }
422  }
423  foreach ($keys as $idx)
424  {
425  $answer = $this->object->answers[$idx];
426  if (($active_id > 0) && (!$show_correct_solution))
427  {
428  if ($graphicalOutput)
429  {
430  $sol = array();
431  foreach ($solutions as $solution)
432  {
433  $sol[$solution["value1"]] = $solution["value2"];
434  }
435  asort($sol);
436  $sol = array_keys($sol);
437  $ans = array();
438  foreach ($this->object->answers as $k => $a)
439  {
440  $ans[$k] = $k;
441  }
442  asort($ans);
443  $ans = array_keys($ans);
444  $ok = FALSE;
445  foreach ($ans as $arr_idx => $ans_idx)
446  {
447  if ($ans_idx == $idx)
448  {
449  if ($ans_idx == $sol[$arr_idx])
450  {
451  $ok = TRUE;
452  }
453  }
454  }
455  // output of ok/not ok icons for user entered solutions
456  if ($ok)
457  {
458  $template->setCurrentBlock("icon_ok");
459  $template->setVariable("ICON_OK", ilUtil::getImagePath("icon_ok.png"));
460  $template->setVariable("TEXT_OK", $this->lng->txt("answer_is_right"));
461  $template->parseCurrentBlock();
462  }
463  else
464  {
465  $template->setCurrentBlock("icon_ok");
466  $template->setVariable("ICON_NOT_OK", ilUtil::getImagePath("icon_not_ok.png"));
467  $template->setVariable("TEXT_NOT_OK", $this->lng->txt("answer_is_wrong"));
468  $template->parseCurrentBlock();
469  }
470  }
471  }
472  if ($this->object->getOrderingType() == OQ_PICTURES)
473  {
474  $template->setCurrentBlock("ordering_row_standard_pictures");
475  $thumbweb = $this->object->getImagePathWeb() . $this->object->getThumbPrefix() . $answer->getAnswertext();
476  $thumb = $this->object->getImagePath() . $this->object->getThumbPrefix() . $answer->getAnswertext();
477  if (!@file_exists($thumb)) $this->object->rebuildThumbnails();
478  $template->setVariable("THUMB_HREF", $thumbweb);
479  list($width, $height, $type, $attr) = getimagesize($thumb);
480  $template->setVariable("ATTR", $attr);
481  $template->setVariable("THUMB_ALT", $this->lng->txt("thumbnail"));
482  $template->setVariable("THUMB_TITLE", $this->lng->txt("enlarge"));
483  $template->parseCurrentBlock();
484  }
485  else
486  {
487  $template->setCurrentBlock("ordering_row_standard_text");
488  $template->setVariable("ANSWER_TEXT", $this->object->prepareTextareaOutput($answer->getAnswertext(), TRUE));
489  $template->parseCurrentBlock();
490  }
491  $template->setCurrentBlock("ordering_row_standard");
492  if ($result_output)
493  {
494  $answer = $this->object->answers[$idx];
495  $points = $answer->getPoints();
496  $resulttext = ($points == 1) ? "(%s " . $this->lng->txt("point") . ")" : "(%s " . $this->lng->txt("points") . ")";
497  $template->setVariable("RESULT_OUTPUT", sprintf($resulttext, $points));
498  }
499  foreach ($solutions as $solution)
500  {
501  if (strcmp($solution["value1"], $idx) == 0)
502  {
503  $template->setVariable("ANSWER_ORDER", $solution["value2"]);
504  }
505  }
506  $template->parseCurrentBlock();
507  }
508  $questiontext = $this->object->getQuestion();
509  if ($show_question_text==true)
510  {
511  $template->setVariable("QUESTIONTEXT", $this->object->prepareTextareaOutput($questiontext, TRUE));
512  }
513  $questionoutput = $template->get();
514  $feedback = ($show_feedback) ? $this->getAnswerFeedbackOutput($active_id, $pass) : "";
515  if (strlen($feedback)) $solutiontemplate->setVariable("FEEDBACK", $this->object->prepareTextareaOutput($feedback, true));
516  $solutiontemplate->setVariable("SOLUTION_OUTPUT", $questionoutput);
517 
518  $solutionoutput = $solutiontemplate->get();
519  if (!$show_question_only)
520  {
521  // get page object output
522  $solutionoutput = '<div class="ilc_question_Standard">'.$solutionoutput."</div>";
523  }
524  return $solutionoutput;
525  }
526 
527  function getPreview($show_question_only = FALSE)
528  {
529  global $ilUser;
530 
531  // shuffle output
532  $keys = array_keys($this->object->answers);
533  shuffle($keys);
534 
535  // generate the question output
536  include_once "./Services/UICore/classes/class.ilTemplate.php";
537  $template = new ilTemplate("tpl.il_as_qpl_ordering_output.html", TRUE, TRUE, "Modules/TestQuestionPool");
538 
539  $jsswitch = "";
540  if (strcmp($this->ctrl->getCmd(), 'preview') == 0)
541  {
542  if (array_key_exists('js', $_GET))
543  {
544  $ilUser->writePref('tst_javascript', $_GET['js']);
545  }
546  $jstemplate = new ilTemplate("tpl.il_as_qpl_javascript_switch.html", TRUE, TRUE, "Modules/TestQuestionPool");
547  if ($ilUser->getPref("tst_javascript") == 1)
548  {
549  $jstemplate->setVariable("JAVASCRIPT_IMAGE", ilUtil::getImagePath("javascript_disable.png"));
550  $jstemplate->setVariable("JAVASCRIPT_IMAGE_ALT", $this->lng->txt("disable_javascript"));
551  $jstemplate->setVariable("JAVASCRIPT_IMAGE_TITLE", $this->lng->txt("disable_javascript"));
552  $this->ctrl->setParameterByClass($this->ctrl->getCmdClass(), "js", "0");
553  $jstemplate->setVariable("JAVASCRIPT_URL", $this->ctrl->getLinkTargetByClass($this->ctrl->getCmdClass(), $this->ctrl->getCmd()));
554  }
555  else
556  {
557  $jstemplate->setVariable("JAVASCRIPT_IMAGE", ilUtil::getImagePath("javascript.png"));
558  $jstemplate->setVariable("JAVASCRIPT_IMAGE_ALT", $this->lng->txt("enable_javascript"));
559  $jstemplate->setVariable("JAVASCRIPT_IMAGE_TITLE", $this->lng->txt("enable_javascript"));
560  $this->ctrl->setParameterByClass($this->ctrl->getCmdClass(), "js", "1");
561  $jstemplate->setVariable("JAVASCRIPT_URL", $this->ctrl->getLinkTargetByClass($this->ctrl->getCmdClass(), $this->ctrl->getCmd()));
562  }
563  $jsswitch = $jstemplate->get();
564  if ($ilUser->getPref('tst_javascript')) $this->object->setOutputType(OUTPUT_JAVASCRIPT);
565  }
566 
567  if ($this->object->getOutputType() == OUTPUT_JAVASCRIPT)
568  {
569  // BEGIN: add javascript code for javascript enabled ordering questions
570  $this->tpl->addBlockFile("CONTENT_BLOCK", "head_content", "tpl.il_as_qpl_ordering_output_javascript.html", "Modules/TestQuestionPool");
571  $this->tpl->setCurrentBlock("head_content");
572  $this->tpl->setVariable("JS_LOCATION", "./Modules/TestQuestionPool/js/toolman/");
573  $this->tpl->parseCurrentBlock();
574  // END: add javascript code for javascript enabled ordering questions
575 
576  // BEGIN: add additional stylesheet for javascript enabled ordering questions
577  $this->tpl->setCurrentBlock("AdditionalStyle");
578  $this->tpl->setVariable("LOCATION_ADDITIONAL_STYLESHEET", ilUtil::getStyleSheetLocation("output", "test_javascript.css", "Modules/TestQuestionPool"));
579  $this->tpl->parseCurrentBlock();
580  // END: add additional stylesheet for javascript enabled ordering questions
581  }
582 
583  if ($this->object->getOutputType() != OUTPUT_JAVASCRIPT)
584  {
585  foreach ($keys as $idx)
586  {
587  $answer = $this->object->answers[$idx];
588  if ($this->object->getOrderingType() == OQ_PICTURES)
589  {
590  $template->setCurrentBlock("ordering_row_standard_pictures");
591  $template->setVariable("PICTURE_HREF", $this->object->getImagePathWeb() . $answer->getAnswertext());
592  $thumbweb = $this->object->getImagePathWeb() . $this->object->getThumbPrefix() . $answer->getAnswertext();
593  $thumb = $this->object->getImagePath() . $this->object->getThumbPrefix() . $answer->getAnswertext();
594  if (!@file_exists($thumb)) $this->object->rebuildThumbnails();
595  $template->setVariable("THUMB_HREF", $thumbweb);
596  $template->setVariable("THUMB_ALT", $this->lng->txt("thumbnail"));
597  $template->setVariable("THUMB_TITLE", $this->lng->txt("enlarge"));
598  $template->setVariable("ANSWER_ID", $answer->getRandomID());
599  $template->parseCurrentBlock();
600  }
601  else
602  {
603  $template->setCurrentBlock("ordering_row_standard_text");
604  $template->setVariable("ANSWER_TEXT", $this->object->prepareTextareaOutput($answer->getAnswertext(), TRUE));
605  $template->setVariable("ANSWER_ID", $answer->getRandomID());
606  $template->parseCurrentBlock();
607  }
608  $template->setCurrentBlock("ordering_row_standard");
609  $template->setVariable("ANSWER_ID", $answer->getRandomID());
610  $template->parseCurrentBlock();
611  }
612  }
613  else
614  {
615  foreach ($keys as $idx)
616  {
617  $answer = $this->object->answers[$idx];
618  if ($this->object->getOrderingType() == OQ_PICTURES)
619  {
620  $template->setCurrentBlock("ordering_row_javascript_pictures");
621  $template->setVariable("PICTURE_HREF", $this->object->getImagePathWeb() . $answer->getAnswertext());
622  $thumbweb = $this->object->getImagePathWeb() . $this->object->getThumbPrefix() . $answer->getAnswertext();
623  $thumb = $this->object->getImagePath() . $this->object->getThumbPrefix() . $answer->getAnswertext();
624  if (!@file_exists($thumb)) $this->object->rebuildThumbnails();
625  $template->setVariable("THUMB_HREF", $thumbweb);
626  $template->setVariable("THUMB_ALT", $this->lng->txt("thumbnail"));
627  $template->setVariable("THUMB_TITLE", $this->lng->txt("thumbnail"));
628  $template->setVariable("ENLARGE_HREF", ilUtil::getImagePath("enlarge.png", FALSE));
629  $template->setVariable("ENLARGE_ALT", $this->lng->txt("enlarge"));
630  $template->setVariable("ENLARGE_TITLE", $this->lng->txt("enlarge"));
631  $template->setVariable("ANSWER_ID", $answer->getRandomID());
632  $template->parseCurrentBlock();
633  }
634  else
635  {
636  $template->setCurrentBlock("ordering_row_javascript_text");
637  $template->setVariable("ANSWER_TEXT", $this->object->prepareTextareaOutput($answer->getAnswertext(), TRUE));
638  $template->setVariable("ANSWER_ID", $answer->getRandomID());
639  $template->parseCurrentBlock();
640  }
641  }
642  $template->setCurrentBlock("ordering_with_javascript");
643  if ($this->object->getOrderingType() == OQ_PICTURES)
644  {
645  $template->setVariable("RESET_POSITIONS", $this->lng->txt("reset_pictures"));
646  }
647  else
648  {
649  $template->setVariable("RESET_POSITIONS", $this->lng->txt("reset_definitions"));
650  }
651  $template->parseCurrentBlock();
652  }
653  $questiontext = $this->object->getQuestion();
654  $template->setVariable("QUESTIONTEXT", $this->object->prepareTextareaOutput($questiontext, TRUE));
655  $questionoutput = $jsswitch . $template->get();
656  if (!$show_question_only)
657  {
658  // get page object output
659  $questionoutput = $this->getILIASPage($questionoutput);
660  }
661  return $questionoutput;
662  }
663 
664  function getTestOutput($active_id, $pass = NULL, $is_postponed = FALSE, $user_post_solution = FALSE)
665  {
666  // shuffle output
667  $keys = array();
668  if (is_array($user_post_solution))
669  {
670  $keys = $_SESSION["ordering_keys"];
671  }
672  else
673  {
674  $keys = array_keys($this->object->answers);
675  shuffle($keys);
676  }
677  $_SESSION["ordering_keys"] = $keys;
678 
679  // generate the question output
680  include_once "./Services/UICore/classes/class.ilTemplate.php";
681 
682  $template = new ilTemplate("tpl.il_as_qpl_ordering_output.html", TRUE, TRUE, "Modules/TestQuestionPool");
683  if ($this->object->getOutputType() == OUTPUT_JAVASCRIPT)
684  {
685  // BEGIN: add javascript code for javascript enabled ordering questions
686  $this->tpl->addBlockFile("CONTENT_BLOCK", "head_content", "tpl.il_as_qpl_ordering_output_javascript.html", "Modules/TestQuestionPool");
687  $this->tpl->setCurrentBlock("head_content");
688  $this->tpl->setVariable("JS_LOCATION", "./Modules/TestQuestionPool/js/toolman/");
689  $this->tpl->parseCurrentBlock();
690  // END: add javascript code for javascript enabled ordering questions
691 
692  // BEGIN: add additional stylesheet for javascript enabled ordering questions
693  $this->tpl->setCurrentBlock("AdditionalStyle");
694  $this->tpl->setVariable("LOCATION_ADDITIONAL_STYLESHEET", ilUtil::getStyleSheetLocation("output", "test_javascript.css", "Modules/TestQuestionPool"));
695  $this->tpl->parseCurrentBlock();
696  // END: add additional stylesheet for javascript enabled ordering questions
697 
698  // BEGIN: onsubmit form action for javascript enabled ordering questions
699  $this->tpl->setVariable("ON_SUBMIT", "return saveOrder('orderlist');");
700  // END: onsubmit form action for javascript enabled ordering questions
701  }
702 
703  // get the solution of the user for the active pass or from the last pass if allowed
704  if ($active_id)
705  {
706  $solutions = NULL;
707  include_once "./Modules/Test/classes/class.ilObjTest.php";
708  if (!ilObjTest::_getUsePreviousAnswers($active_id, true))
709  {
710  if (is_null($pass)) $pass = ilObjTest::_getPass($active_id);
711  }
712  if (is_array($user_post_solution))
713  {
714  $solutions = array();
715  foreach ($user_post_solution as $key => $value)
716  {
717  if (preg_match("/order_(\d+)/", $key, $matches))
718  {
719  foreach ($this->object->getAnswers() as $answeridx => $answer)
720  {
721  if ($answer->getRandomID() == $matches[1])
722  {
723  array_push($solutions, array("value1" => $answeridx, "value2" => $value));
724  }
725  }
726  }
727  }
728  }
729  else
730  {
731  $solutions =& $this->object->getSolutionValues($active_id, $pass);
732  }
733 
734  if ($this->object->getOutputType() == OUTPUT_JAVASCRIPT)
735  {
736  $solution_script .= "";
737  $jssolutions = array();
738  foreach ($solutions as $idx => $solution_value)
739  {
740  if ((strcmp($solution_value["value2"], "") != 0) && (strcmp($solution_value["value1"], "") != 0))
741  {
742  $jssolutions[$solution_value["value2"]] = $solution_value["value1"];
743  }
744  }
745  if (count($jssolutions))
746  {
747  ksort($jssolutions);
748  $js = "";
749  foreach ($jssolutions as $key => $value)
750  {
751  if (is_object($this->object->getAnswer($value)))
752  {
753  $js .= "initialorder.push('id_" . $this->object->getAnswer($value)->getRandomID() . "');";
754  }
755  }
756  $js .= "restoreInitialOrder();";
757  }
758  if (strlen($js))
759  {
760  $template->setCurrentBlock("javascript_restore_order");
761  $template->setVariable("RESTORE_ORDER", $js);
762  $template->parseCurrentBlock();
763  }
764  }
765  }
766 
767  if ($this->object->getOutputType() != OUTPUT_JAVASCRIPT)
768  {
769  foreach ($keys as $idx)
770  {
771  $answer = $this->object->answers[$idx];
772  if ($this->object->getOrderingType() == OQ_PICTURES)
773  {
774  $template->setCurrentBlock("ordering_row_standard_pictures");
775  $template->setVariable("PICTURE_HREF", $this->object->getImagePathWeb() . $answer->getAnswertext());
776  $thumbweb = $this->object->getImagePathWeb() . $this->object->getThumbPrefix() . $answer->getAnswertext();
777  $thumb = $this->object->getImagePath() . $this->object->getThumbPrefix() . $answer->getAnswertext();
778  if (!@file_exists($thumb)) $this->object->rebuildThumbnails();
779  $template->setVariable("THUMB_HREF", $thumbweb);
780  $template->setVariable("THUMB_ALT", $this->lng->txt("thumbnail"));
781  $template->setVariable("THUMB_TITLE", $this->lng->txt("enlarge"));
782  $template->setVariable("ANSWER_ID", $answer->getRandomID());
783  $template->parseCurrentBlock();
784  }
785  else
786  {
787  $template->setCurrentBlock("ordering_row_standard_text");
788  $template->setVariable("ANSWER_TEXT", $this->object->prepareTextareaOutput($answer->getAnswertext(), TRUE));
789  $template->setVariable("ANSWER_ID", $answer->getRandomID());
790  $template->parseCurrentBlock();
791  }
792  $template->setCurrentBlock("ordering_row_standard");
793  $template->setVariable("ANSWER_ID", $answer->getRandomID());
794  if (is_array($solutions))
795  {
796  foreach ($solutions as $solution)
797  {
798  if (($solution["value1"] == $idx) && (strlen($solution["value2"])))
799  {
800  $template->setVariable("ANSWER_ORDER", " value=\"" . $solution["value2"] . "\"");
801  }
802  }
803  }
804  $template->parseCurrentBlock();
805  }
806  }
807  else
808  {
809  foreach ($keys as $idx)
810  {
811  $answer = $this->object->answers[$idx];
812  if ($this->object->getOrderingType() == OQ_PICTURES)
813  {
814  $template->setCurrentBlock("ordering_row_javascript_pictures");
815  $template->setVariable("PICTURE_HREF", $this->object->getImagePathWeb() . $answer->getAnswertext());
816  $thumbweb = $this->object->getImagePathWeb() . $this->object->getThumbPrefix() . $answer->getAnswertext();
817  $thumb = $this->object->getImagePath() . $this->object->getThumbPrefix() . $answer->getAnswertext();
818  if (!@file_exists($thumb)) $this->object->rebuildThumbnails();
819  $template->setVariable("THUMB_HREF", $thumbweb);
820  $template->setVariable("THUMB_ALT", $this->lng->txt("thumbnail"));
821  $template->setVariable("THUMB_TITLE", $this->lng->txt("thumbnail"));
822  $template->setVariable("ENLARGE_HREF", ilUtil::getImagePath("enlarge.png", FALSE));
823  $template->setVariable("ENLARGE_ALT", $this->lng->txt("enlarge"));
824  $template->setVariable("ENLARGE_TITLE", $this->lng->txt("enlarge"));
825  $template->setVariable("ANSWER_ID", $answer->getRandomID());
826  $template->parseCurrentBlock();
827  }
828  else
829  {
830  $template->setCurrentBlock("ordering_row_javascript_text");
831  $template->setVariable("ANSWER_TEXT", $this->object->prepareTextareaOutput($answer->getAnswertext(), TRUE));
832  $template->setVariable("ANSWER_ID", $answer->getRandomID());
833  $template->parseCurrentBlock();
834  }
835  }
836  $template->setCurrentBlock("ordering_with_javascript");
837  if ($this->object->getOrderingType() == OQ_PICTURES)
838  {
839  $template->setVariable("RESET_POSITIONS", $this->lng->txt("reset_pictures"));
840  }
841  else
842  {
843  $template->setVariable("RESET_POSITIONS", $this->lng->txt("reset_definitions"));
844  }
845  $template->parseCurrentBlock();
846  }
847  $questiontext = $this->object->getQuestion();
848  $template->setVariable("QUESTIONTEXT", $this->object->prepareTextareaOutput($questiontext, TRUE));
849  $questionoutput = $template->get();
850  $pageoutput = $this->outQuestionPage("", $is_postponed, $active_id, $questionoutput);
851  return $pageoutput;
852  }
853 
859  function saveFeedback()
860  {
861  include_once "./Services/AdvancedEditing/classes/class.ilObjAdvancedEditing.php";
862  $errors = $this->feedback(true);
863  $this->object->saveFeedbackGeneric(0, $_POST["feedback_incomplete"]);
864  $this->object->saveFeedbackGeneric(1, $_POST["feedback_complete"]);
865  $this->object->cleanupMediaObjectUsage();
867  }
868 
876  function setQuestionTabs()
877  {
878  global $rbacsystem, $ilTabs;
879 
880  $this->ctrl->setParameterByClass("ilpageobjectgui", "q_id", $_GET["q_id"]);
881  include_once "./Modules/TestQuestionPool/classes/class.assQuestion.php";
882  $q_type = $this->object->getQuestionType();
883 
884  if (strlen($q_type))
885  {
886  $classname = $q_type . "GUI";
887  $this->ctrl->setParameterByClass(strtolower($classname), "sel_question_types", $q_type);
888  $this->ctrl->setParameterByClass(strtolower($classname), "q_id", $_GET["q_id"]);
889  }
890 
891  if ($_GET["q_id"])
892  {
893  if ($rbacsystem->checkAccess('write', $_GET["ref_id"]))
894  {
895  // edit page
896  $ilTabs->addTarget("edit_page",
897  $this->ctrl->getLinkTargetByClass("ilPageObjectGUI", "edit"),
898  array("edit", "insert", "exec_pg"),
899  "", "", $force_active);
900  }
901 
902  // edit page
903  $ilTabs->addTarget("preview",
904  $this->ctrl->getLinkTargetByClass("ilPageObjectGUI", "preview"),
905  array("preview"),
906  "ilPageObjectGUI", "", $force_active);
907  }
908 
909  $force_active = false;
910  if ($rbacsystem->checkAccess('write', $_GET["ref_id"]))
911  {
912  $url = "";
913  if ($classname) $url = $this->ctrl->getLinkTargetByClass($classname, "editQuestion");
914  $commands = $_POST["cmd"];
915  if (is_array($commands))
916  {
917  foreach ($commands as $key => $value)
918  {
919  if (preg_match("/^delete_.*/", $key, $matches))
920  {
921  $force_active = true;
922  }
923  }
924  }
925  // edit question properties
926  $ilTabs->addTarget("edit_question",
927  $url,
928  array("editQuestion", "save", "saveEdit", "addanswers", "removeanswers", "changeToPictures", "uploadanswers", "changeToText", "upanswers", "downanswers", "originalSyncForm"),
929  $classname, "", $force_active);
930  }
931 
932  if ($_GET["q_id"])
933  {
934  $ilTabs->addTarget("feedback",
935  $this->ctrl->getLinkTargetByClass($classname, "feedback"),
936  array("feedback", "saveFeedback"),
937  $classname, "");
938  }
939 
940  // add tab for question hint within common class assQuestionGUI
941  $this->addTab_QuestionHints($ilTabs);
942 
943  if ($_GET["q_id"])
944  {
945  $ilTabs->addTarget("solution_hint",
946  $this->ctrl->getLinkTargetByClass($classname, "suggestedsolution"),
947  array("suggestedsolution", "saveSuggestedSolution", "outSolutionExplorer", "cancel",
948  "addSuggestedSolution","cancelExplorer", "linkChilds", "removeSuggestedSolution"
949  ),
950  $classname,
951  ""
952  );
953  }
954 
955  // Assessment of questions sub menu entry
956  if ($_GET["q_id"])
957  {
958  $ilTabs->addTarget("statistics",
959  $this->ctrl->getLinkTargetByClass($classname, "assessment"),
960  array("assessment"),
961  $classname, "");
962  }
963 
964  if (($_GET["calling_test"] > 0) || ($_GET["test_ref_id"] > 0))
965  {
966  $ref_id = $_GET["calling_test"];
967  if (strlen($ref_id) == 0) $ref_id = $_GET["test_ref_id"];
968 
969  global $___test_express_mode;
970 
971  if (!$_GET['test_express_mode'] && !$___test_express_mode) {
972  $ilTabs->setBackTarget($this->lng->txt("backtocallingtest"), "ilias.php?baseClass=ilObjTestGUI&cmd=questions&ref_id=$ref_id");
973  }
974  else {
976  $ilTabs->setBackTarget($this->lng->txt("backtocallingtest"), $link);
977  }
978  }
979  else
980  {
981  $ilTabs->setBackTarget($this->lng->txt("qpl"), $this->ctrl->getLinkTargetByClass("ilobjquestionpoolgui", "questions"));
982  }
983  }
984 
985  function getSpecificFeedbackOutput($active_id, $pass)
986  {
987  $output = "";
988  return $this->object->prepareTextareaOutput($output, TRUE);
989  }
990 
991 }