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