ILIAS  Release_4_1_x_branch Revision 61804
 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  // points
294  $points = new ilNumberInputGUI($this->lng->txt("points"), "points");
295  $points->setValue($this->object->getPoints());
296  $points->setRequired(TRUE);
297  $points->setSize(3);
298  $points->setMinValue(0);
299  $points->setMinvalueShouldBeGreater(true);
300  $form->addItem($points);
301 
302  $this->addQuestionFormCommandButtons($form);
303  if (!$this->getSelfAssessmentEditingMode())
304  {
305  if ($orderingtype == OQ_PICTURES)
306  {
307  $form->addCommandButton("changeToText", $this->lng->txt("order_terms"));
308  }
309  else
310  {
311  $form->addCommandButton("changeToPictures", $this->lng->txt("order_pictures"));
312  }
313  }
314 
315  $errors = false;
316 
317  if ($save)
318  {
319  $form->setValuesByPost();
320  $errors = !$form->checkInput();
321  $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
322  if ($errors) $checkonly = false;
323  }
324 
325  if (!$checkonly) $this->tpl->setVariable("QUESTION_DATA", $form->getHTML());
326  return $errors;
327  }
328 
329  function outQuestionForTest($formaction, $active_id, $pass = NULL, $is_postponed = FALSE, $user_post_solution = FALSE)
330  {
331  $test_output = $this->getTestOutput($active_id, $pass, $is_postponed, $user_post_solution);
332  $this->tpl->setVariable("QUESTION_OUTPUT", $test_output);
333  $this->tpl->setVariable("FORMACTION", $formaction);
334  }
335 
350  $active_id,
351  $pass = NULL,
352  $graphicalOutput = FALSE,
353  $result_output = FALSE,
354  $show_question_only = TRUE,
355  $show_feedback = FALSE,
356  $show_correct_solution = FALSE,
357  $show_manual_scoring = FALSE
358  )
359  {
360  // shuffle output
361  $keys = array_keys($this->object->answers);
362 
363  // generate the question output
364  include_once "./classes/class.ilTemplate.php";
365  $template = new ilTemplate("tpl.il_as_qpl_ordering_output_solution.html", TRUE, TRUE, "Modules/TestQuestionPool");
366  $solutiontemplate = new ilTemplate("tpl.il_as_tst_solution_output.html",TRUE, TRUE, "Modules/TestQuestionPool");
367 
368  // get the solution of the user for the active pass or from the last pass if allowed
369  $solutions = array();
370  if (($active_id > 0) && (!$show_correct_solution))
371  {
372  $solutions =& $this->object->getSolutionValues($active_id, $pass);
373  }
374  else
375  {
376  foreach ($this->object->answers as $index => $answer)
377  {
378  array_push($solutions, array("value1" => $index, "value2" => $index+1));
379  }
380  }
381  foreach ($keys as $idx)
382  {
383  $answer = $this->object->answers[$idx];
384  if (($active_id > 0) && (!$show_correct_solution))
385  {
386  if ($graphicalOutput)
387  {
388  $sol = array();
389  foreach ($solutions as $solution)
390  {
391  $sol[$solution["value1"]] = $solution["value2"];
392  }
393  asort($sol);
394  $sol = array_keys($sol);
395  $ans = array();
396  foreach ($this->object->answers as $k => $a)
397  {
398  $ans[$k] = $k;
399  }
400  asort($ans);
401  $ans = array_keys($ans);
402  $ok = FALSE;
403  foreach ($ans as $arr_idx => $ans_idx)
404  {
405  if ($ans_idx == $idx)
406  {
407  if ($ans_idx == $sol[$arr_idx])
408  {
409  $ok = TRUE;
410  }
411  }
412  }
413  // output of ok/not ok icons for user entered solutions
414  if ($ok)
415  {
416  $template->setCurrentBlock("icon_ok");
417  $template->setVariable("ICON_OK", ilUtil::getImagePath("icon_ok.gif"));
418  $template->setVariable("TEXT_OK", $this->lng->txt("answer_is_right"));
419  $template->parseCurrentBlock();
420  }
421  else
422  {
423  $template->setCurrentBlock("icon_ok");
424  $template->setVariable("ICON_NOT_OK", ilUtil::getImagePath("icon_not_ok.gif"));
425  $template->setVariable("TEXT_NOT_OK", $this->lng->txt("answer_is_wrong"));
426  $template->parseCurrentBlock();
427  }
428  }
429  }
430  if ($this->object->getOrderingType() == OQ_PICTURES)
431  {
432  $template->setCurrentBlock("ordering_row_standard_pictures");
433  $thumbweb = $this->object->getImagePathWeb() . $this->object->getThumbPrefix() . $answer->getAnswertext();
434  $thumb = $this->object->getImagePath() . $this->object->getThumbPrefix() . $answer->getAnswertext();
435  if (!@file_exists($thumb)) $this->object->rebuildThumbnails();
436  $template->setVariable("THUMB_HREF", $thumbweb);
437  list($width, $height, $type, $attr) = getimagesize($thumb);
438  $template->setVariable("ATTR", $attr);
439  $template->setVariable("THUMB_ALT", $this->lng->txt("thumbnail"));
440  $template->setVariable("THUMB_TITLE", $this->lng->txt("enlarge"));
441  $template->parseCurrentBlock();
442  }
443  else
444  {
445  $template->setCurrentBlock("ordering_row_standard_text");
446  $template->setVariable("ANSWER_TEXT", $this->object->prepareTextareaOutput($answer->getAnswertext(), TRUE));
447  $template->parseCurrentBlock();
448  }
449  $template->setCurrentBlock("ordering_row_standard");
450  if ($result_output)
451  {
452  $answer = $this->object->answers[$idx];
453  $points = $answer->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  foreach ($solutions as $solution)
458  {
459  if (strcmp($solution["value1"], $idx) == 0)
460  {
461  $template->setVariable("ANSWER_ORDER", $solution["value2"]);
462  }
463  }
464  $template->parseCurrentBlock();
465  }
466  $questiontext = $this->object->getQuestion();
467  $template->setVariable("QUESTIONTEXT", $this->object->prepareTextareaOutput($questiontext, TRUE));
468  $questionoutput = $template->get();
469  $feedback = ($show_feedback) ? $this->getAnswerFeedbackOutput($active_id, $pass) : "";
470  if (strlen($feedback)) $solutiontemplate->setVariable("FEEDBACK", $feedback);
471  $solutiontemplate->setVariable("SOLUTION_OUTPUT", $questionoutput);
472 
473  $solutionoutput = $solutiontemplate->get();
474  if (!$show_question_only)
475  {
476  // get page object output
477  $solutionoutput = $this->getILIASPage($solutionoutput);
478  }
479  return $solutionoutput;
480  }
481 
482  function getPreview($show_question_only = FALSE)
483  {
484  global $ilUser;
485 
486  // shuffle output
487  $keys = array_keys($this->object->answers);
488  shuffle($keys);
489 
490  // generate the question output
491  include_once "./classes/class.ilTemplate.php";
492  $template = new ilTemplate("tpl.il_as_qpl_ordering_output.html", TRUE, TRUE, "Modules/TestQuestionPool");
493 
494  $jsswitch = "";
495  if (strcmp($this->ctrl->getCmd(), 'preview') == 0)
496  {
497  if (array_key_exists('js', $_GET))
498  {
499  $ilUser->writePref('tst_javascript', $_GET['js']);
500  }
501  $jstemplate = new ilTemplate("tpl.il_as_qpl_javascript_switch.html", TRUE, TRUE, "Modules/TestQuestionPool");
502  if ($ilUser->getPref("tst_javascript") == 1)
503  {
504  $jstemplate->setVariable("JAVASCRIPT_IMAGE", ilUtil::getImagePath("javascript_disable.png"));
505  $jstemplate->setVariable("JAVASCRIPT_IMAGE_ALT", $this->lng->txt("disable_javascript"));
506  $jstemplate->setVariable("JAVASCRIPT_IMAGE_TITLE", $this->lng->txt("disable_javascript"));
507  $this->ctrl->setParameterByClass($this->ctrl->getCmdClass(), "js", "0");
508  $jstemplate->setVariable("JAVASCRIPT_URL", $this->ctrl->getLinkTargetByClass($this->ctrl->getCmdClass(), $this->ctrl->getCmd()));
509  }
510  else
511  {
512  $jstemplate->setVariable("JAVASCRIPT_IMAGE", ilUtil::getImagePath("javascript.png"));
513  $jstemplate->setVariable("JAVASCRIPT_IMAGE_ALT", $this->lng->txt("enable_javascript"));
514  $jstemplate->setVariable("JAVASCRIPT_IMAGE_TITLE", $this->lng->txt("enable_javascript"));
515  $this->ctrl->setParameterByClass($this->ctrl->getCmdClass(), "js", "1");
516  $jstemplate->setVariable("JAVASCRIPT_URL", $this->ctrl->getLinkTargetByClass($this->ctrl->getCmdClass(), $this->ctrl->getCmd()));
517  }
518  $jsswitch = $jstemplate->get();
519  if ($ilUser->getPref('tst_javascript')) $this->object->setOutputType(OUTPUT_JAVASCRIPT);
520  }
521 
522  if ($this->object->getOutputType() == OUTPUT_JAVASCRIPT)
523  {
524  // BEGIN: add javascript code for javascript enabled ordering questions
525  $this->tpl->addBlockFile("CONTENT_BLOCK", "head_content", "tpl.il_as_qpl_ordering_output_javascript.html", "Modules/TestQuestionPool");
526  $this->tpl->setCurrentBlock("head_content");
527  $this->tpl->setVariable("JS_LOCATION", "./Modules/TestQuestionPool/js/toolman/");
528  $this->tpl->parseCurrentBlock();
529  // END: add javascript code for javascript enabled ordering questions
530 
531  // BEGIN: add additional stylesheet for javascript enabled ordering questions
532  $this->tpl->setCurrentBlock("AdditionalStyle");
533  $this->tpl->setVariable("LOCATION_ADDITIONAL_STYLESHEET", ilUtil::getStyleSheetLocation("output", "test_javascript.css", "Modules/TestQuestionPool"));
534  $this->tpl->parseCurrentBlock();
535  // END: add additional stylesheet for javascript enabled ordering questions
536  }
537 
538  if ($this->object->getOutputType() != OUTPUT_JAVASCRIPT)
539  {
540  foreach ($keys as $idx)
541  {
542  $answer = $this->object->answers[$idx];
543  if ($this->object->getOrderingType() == OQ_PICTURES)
544  {
545  $template->setCurrentBlock("ordering_row_standard_pictures");
546  $template->setVariable("PICTURE_HREF", $this->object->getImagePathWeb() . $answer->getAnswertext());
547  $thumbweb = $this->object->getImagePathWeb() . $this->object->getThumbPrefix() . $answer->getAnswertext();
548  $thumb = $this->object->getImagePath() . $this->object->getThumbPrefix() . $answer->getAnswertext();
549  if (!@file_exists($thumb)) $this->object->rebuildThumbnails();
550  $template->setVariable("THUMB_HREF", $thumbweb);
551  $template->setVariable("THUMB_ALT", $this->lng->txt("thumbnail"));
552  $template->setVariable("THUMB_TITLE", $this->lng->txt("enlarge"));
553  $template->setVariable("ANSWER_ID", $answer->getRandomID());
554  $template->parseCurrentBlock();
555  }
556  else
557  {
558  $template->setCurrentBlock("ordering_row_standard_text");
559  $template->setVariable("ANSWER_TEXT", $this->object->prepareTextareaOutput($answer->getAnswertext(), TRUE));
560  $template->setVariable("ANSWER_ID", $answer->getRandomID());
561  $template->parseCurrentBlock();
562  }
563  $template->setCurrentBlock("ordering_row_standard");
564  $template->setVariable("ANSWER_ID", $answer->getRandomID());
565  $template->parseCurrentBlock();
566  }
567  }
568  else
569  {
570  foreach ($keys as $idx)
571  {
572  $answer = $this->object->answers[$idx];
573  if ($this->object->getOrderingType() == OQ_PICTURES)
574  {
575  $template->setCurrentBlock("ordering_row_javascript_pictures");
576  $template->setVariable("PICTURE_HREF", $this->object->getImagePathWeb() . $answer->getAnswertext());
577  $thumbweb = $this->object->getImagePathWeb() . $this->object->getThumbPrefix() . $answer->getAnswertext();
578  $thumb = $this->object->getImagePath() . $this->object->getThumbPrefix() . $answer->getAnswertext();
579  if (!@file_exists($thumb)) $this->object->rebuildThumbnails();
580  $template->setVariable("THUMB_HREF", $thumbweb);
581  $template->setVariable("THUMB_ALT", $this->lng->txt("thumbnail"));
582  $template->setVariable("THUMB_TITLE", $this->lng->txt("thumbnail"));
583  $template->setVariable("ENLARGE_HREF", ilUtil::getImagePath("enlarge.gif", FALSE));
584  $template->setVariable("ENLARGE_ALT", $this->lng->txt("enlarge"));
585  $template->setVariable("ENLARGE_TITLE", $this->lng->txt("enlarge"));
586  $template->setVariable("ANSWER_ID", $answer->getRandomID());
587  $template->parseCurrentBlock();
588  }
589  else
590  {
591  $template->setCurrentBlock("ordering_row_javascript_text");
592  $template->setVariable("ANSWER_TEXT", $this->object->prepareTextareaOutput($answer->getAnswertext(), TRUE));
593  $template->setVariable("ANSWER_ID", $answer->getRandomID());
594  $template->parseCurrentBlock();
595  }
596  }
597  $template->setCurrentBlock("ordering_with_javascript");
598  if ($this->object->getOrderingType() == OQ_PICTURES)
599  {
600  $template->setVariable("RESET_POSITIONS", $this->lng->txt("reset_pictures"));
601  }
602  else
603  {
604  $template->setVariable("RESET_POSITIONS", $this->lng->txt("reset_definitions"));
605  }
606  $template->parseCurrentBlock();
607  }
608  $questiontext = $this->object->getQuestion();
609  $template->setVariable("QUESTIONTEXT", $this->object->prepareTextareaOutput($questiontext, TRUE));
610  $questionoutput = $jsswitch . $template->get();
611  if (!$show_question_only)
612  {
613  // get page object output
614  $questionoutput = $this->getILIASPage($questionoutput);
615  }
616  return $questionoutput;
617  }
618 
619  function getTestOutput($active_id, $pass = NULL, $is_postponed = FALSE, $user_post_solution = FALSE)
620  {
621  // shuffle output
622  $keys = array();
623  if (is_array($user_post_solution))
624  {
625  $keys = $_SESSION["ordering_keys"];
626  }
627  else
628  {
629  $keys = array_keys($this->object->answers);
630  shuffle($keys);
631  }
632  $_SESSION["ordering_keys"] = $keys;
633 
634  // generate the question output
635  include_once "./classes/class.ilTemplate.php";
636 
637  $template = new ilTemplate("tpl.il_as_qpl_ordering_output.html", TRUE, TRUE, "Modules/TestQuestionPool");
638  if ($this->object->getOutputType() == OUTPUT_JAVASCRIPT)
639  {
640  // BEGIN: add javascript code for javascript enabled ordering questions
641  $this->tpl->addBlockFile("CONTENT_BLOCK", "head_content", "tpl.il_as_qpl_ordering_output_javascript.html", "Modules/TestQuestionPool");
642  $this->tpl->setCurrentBlock("head_content");
643  $this->tpl->setVariable("JS_LOCATION", "./Modules/TestQuestionPool/js/toolman/");
644  $this->tpl->parseCurrentBlock();
645  // END: add javascript code for javascript enabled ordering questions
646 
647  // BEGIN: add additional stylesheet for javascript enabled ordering questions
648  $this->tpl->setCurrentBlock("AdditionalStyle");
649  $this->tpl->setVariable("LOCATION_ADDITIONAL_STYLESHEET", ilUtil::getStyleSheetLocation("output", "test_javascript.css", "Modules/TestQuestionPool"));
650  $this->tpl->parseCurrentBlock();
651  // END: add additional stylesheet for javascript enabled ordering questions
652 
653  // BEGIN: onsubmit form action for javascript enabled ordering questions
654  $this->tpl->setVariable("ON_SUBMIT", "return saveOrder('orderlist');");
655  // END: onsubmit form action for javascript enabled ordering questions
656  }
657 
658  // get the solution of the user for the active pass or from the last pass if allowed
659  if ($active_id)
660  {
661  $solutions = NULL;
662  include_once "./Modules/Test/classes/class.ilObjTest.php";
663  if (!ilObjTest::_getUsePreviousAnswers($active_id, true))
664  {
665  if (is_null($pass)) $pass = ilObjTest::_getPass($active_id);
666  }
667  if (is_array($user_post_solution))
668  {
669  $solutions = array();
670  foreach ($user_post_solution as $key => $value)
671  {
672  if (preg_match("/order_(\d+)/", $key, $matches))
673  {
674  foreach ($this->object->getAnswers() as $answeridx => $answer)
675  {
676  if ($answer->getRandomID() == $matches[1])
677  {
678  array_push($solutions, array("value1" => $answeridx, "value2" => $value));
679  }
680  }
681  }
682  }
683  }
684  else
685  {
686  $solutions =& $this->object->getSolutionValues($active_id, $pass);
687  }
688 
689  if ($this->object->getOutputType() == OUTPUT_JAVASCRIPT)
690  {
691  $solution_script .= "";
692  $jssolutions = array();
693  foreach ($solutions as $idx => $solution_value)
694  {
695  if ((strcmp($solution_value["value2"], "") != 0) && (strcmp($solution_value["value1"], "") != 0))
696  {
697  $jssolutions[$solution_value["value2"]] = $solution_value["value1"];
698  }
699  }
700  if (count($jssolutions))
701  {
702  ksort($jssolutions);
703  $js = "";
704  foreach ($jssolutions as $key => $value)
705  {
706  if (is_object($this->object->getAnswer($value)))
707  {
708  $js .= "initialorder.push('id_" . $this->object->getAnswer($value)->getRandomID() . "');";
709  }
710  }
711  $js .= "restoreInitialOrder();";
712  }
713  if (strlen($js))
714  {
715  $template->setCurrentBlock("javascript_restore_order");
716  $template->setVariable("RESTORE_ORDER", $js);
717  $template->parseCurrentBlock();
718  }
719  }
720  }
721 
722  if ($this->object->getOutputType() != OUTPUT_JAVASCRIPT)
723  {
724  foreach ($keys as $idx)
725  {
726  $answer = $this->object->answers[$idx];
727  if ($this->object->getOrderingType() == OQ_PICTURES)
728  {
729  $template->setCurrentBlock("ordering_row_standard_pictures");
730  $template->setVariable("PICTURE_HREF", $this->object->getImagePathWeb() . $answer->getAnswertext());
731  $thumbweb = $this->object->getImagePathWeb() . $this->object->getThumbPrefix() . $answer->getAnswertext();
732  $thumb = $this->object->getImagePath() . $this->object->getThumbPrefix() . $answer->getAnswertext();
733  if (!@file_exists($thumb)) $this->object->rebuildThumbnails();
734  $template->setVariable("THUMB_HREF", $thumbweb);
735  $template->setVariable("THUMB_ALT", $this->lng->txt("thumbnail"));
736  $template->setVariable("THUMB_TITLE", $this->lng->txt("enlarge"));
737  $template->setVariable("ANSWER_ID", $answer->getRandomID());
738  $template->parseCurrentBlock();
739  }
740  else
741  {
742  $template->setCurrentBlock("ordering_row_standard_text");
743  $template->setVariable("ANSWER_TEXT", $this->object->prepareTextareaOutput($answer->getAnswertext(), TRUE));
744  $template->setVariable("ANSWER_ID", $answer->getRandomID());
745  $template->parseCurrentBlock();
746  }
747  $template->setCurrentBlock("ordering_row_standard");
748  $template->setVariable("ANSWER_ID", $answer->getRandomID());
749  if (is_array($solutions))
750  {
751  foreach ($solutions as $solution)
752  {
753  if (($solution["value1"] == $idx) && (strlen($solution["value2"])))
754  {
755  $template->setVariable("ANSWER_ORDER", " value=\"" . $solution["value2"] . "\"");
756  }
757  }
758  }
759  $template->parseCurrentBlock();
760  }
761  }
762  else
763  {
764  foreach ($keys as $idx)
765  {
766  $answer = $this->object->answers[$idx];
767  if ($this->object->getOrderingType() == OQ_PICTURES)
768  {
769  $template->setCurrentBlock("ordering_row_javascript_pictures");
770  $template->setVariable("PICTURE_HREF", $this->object->getImagePathWeb() . $answer->getAnswertext());
771  $thumbweb = $this->object->getImagePathWeb() . $this->object->getThumbPrefix() . $answer->getAnswertext();
772  $thumb = $this->object->getImagePath() . $this->object->getThumbPrefix() . $answer->getAnswertext();
773  if (!@file_exists($thumb)) $this->object->rebuildThumbnails();
774  $template->setVariable("THUMB_HREF", $thumbweb);
775  $template->setVariable("THUMB_ALT", $this->lng->txt("thumbnail"));
776  $template->setVariable("THUMB_TITLE", $this->lng->txt("thumbnail"));
777  $template->setVariable("ENLARGE_HREF", ilUtil::getImagePath("enlarge.gif", FALSE));
778  $template->setVariable("ENLARGE_ALT", $this->lng->txt("enlarge"));
779  $template->setVariable("ENLARGE_TITLE", $this->lng->txt("enlarge"));
780  $template->setVariable("ANSWER_ID", $answer->getRandomID());
781  $template->parseCurrentBlock();
782  }
783  else
784  {
785  $template->setCurrentBlock("ordering_row_javascript_text");
786  $template->setVariable("ANSWER_TEXT", $this->object->prepareTextareaOutput($answer->getAnswertext(), TRUE));
787  $template->setVariable("ANSWER_ID", $answer->getRandomID());
788  $template->parseCurrentBlock();
789  }
790  }
791  $template->setCurrentBlock("ordering_with_javascript");
792  if ($this->object->getOrderingType() == OQ_PICTURES)
793  {
794  $template->setVariable("RESET_POSITIONS", $this->lng->txt("reset_pictures"));
795  }
796  else
797  {
798  $template->setVariable("RESET_POSITIONS", $this->lng->txt("reset_definitions"));
799  }
800  $template->parseCurrentBlock();
801  }
802  $questiontext = $this->object->getQuestion();
803  $template->setVariable("QUESTIONTEXT", $this->object->prepareTextareaOutput($questiontext, TRUE));
804  $questionoutput = $template->get();
805  $pageoutput = $this->outQuestionPage("", $is_postponed, $active_id, $questionoutput);
806  return $pageoutput;
807  }
808 
814  function saveFeedback()
815  {
816  include_once "./Services/AdvancedEditing/classes/class.ilObjAdvancedEditing.php";
817  $errors = $this->feedback(true);
818  $this->object->saveFeedbackGeneric(0, $_POST["feedback_incomplete"]);
819  $this->object->saveFeedbackGeneric(1, $_POST["feedback_complete"]);
820  $this->object->cleanupMediaObjectUsage();
822  }
823 
829  function setQuestionTabs()
830  {
831  global $rbacsystem, $ilTabs;
832 
833  $this->ctrl->setParameterByClass("ilpageobjectgui", "q_id", $_GET["q_id"]);
834  include_once "./Modules/TestQuestionPool/classes/class.assQuestion.php";
835  $q_type = $this->object->getQuestionType();
836 
837  if (strlen($q_type))
838  {
839  $classname = $q_type . "GUI";
840  $this->ctrl->setParameterByClass(strtolower($classname), "sel_question_types", $q_type);
841  $this->ctrl->setParameterByClass(strtolower($classname), "q_id", $_GET["q_id"]);
842  }
843 
844  if ($_GET["q_id"])
845  {
846  if ($rbacsystem->checkAccess('write', $_GET["ref_id"]))
847  {
848  // edit page
849  $ilTabs->addTarget("edit_content",
850  $this->ctrl->getLinkTargetByClass("ilPageObjectGUI", "edit"),
851  array("edit", "insert", "exec_pg"),
852  "", "", $force_active);
853  }
854 
855  // edit page
856  $ilTabs->addTarget("preview",
857  $this->ctrl->getLinkTargetByClass("ilPageObjectGUI", "preview"),
858  array("preview"),
859  "ilPageObjectGUI", "", $force_active);
860  }
861 
862  $force_active = false;
863  if ($rbacsystem->checkAccess('write', $_GET["ref_id"]))
864  {
865  $url = "";
866  if ($classname) $url = $this->ctrl->getLinkTargetByClass($classname, "editQuestion");
867  $commands = $_POST["cmd"];
868  if (is_array($commands))
869  {
870  foreach ($commands as $key => $value)
871  {
872  if (preg_match("/^delete_.*/", $key, $matches))
873  {
874  $force_active = true;
875  }
876  }
877  }
878  // edit question properties
879  $ilTabs->addTarget("edit_properties",
880  $url,
881  array("editQuestion", "save", "saveEdit", "addanswers", "removeanswers", "changeToPictures", "uploadanswers", "changeToText", "upanswers", "downanswers", "originalSyncForm"),
882  $classname, "", $force_active);
883  }
884 
885  if ($_GET["q_id"])
886  {
887  $ilTabs->addTarget("feedback",
888  $this->ctrl->getLinkTargetByClass($classname, "feedback"),
889  array("feedback", "saveFeedback"),
890  $classname, "");
891  }
892 
893  if ($_GET["q_id"])
894  {
895  $ilTabs->addTarget("solution_hint",
896  $this->ctrl->getLinkTargetByClass($classname, "suggestedsolution"),
897  array("suggestedsolution", "saveSuggestedSolution", "outSolutionExplorer", "cancel",
898  "addSuggestedSolution","cancelExplorer", "linkChilds", "removeSuggestedSolution"
899  ),
900  $classname,
901  ""
902  );
903  }
904 
905  // Assessment of questions sub menu entry
906  if ($_GET["q_id"])
907  {
908  $ilTabs->addTarget("statistics",
909  $this->ctrl->getLinkTargetByClass($classname, "assessment"),
910  array("assessment"),
911  $classname, "");
912  }
913 
914  if (($_GET["calling_test"] > 0) || ($_GET["test_ref_id"] > 0))
915  {
916  $ref_id = $_GET["calling_test"];
917  if (strlen($ref_id) == 0) $ref_id = $_GET["test_ref_id"];
918  $ilTabs->setBackTarget($this->lng->txt("backtocallingtest"), "ilias.php?baseClass=ilObjTestGUI&cmd=questions&ref_id=$ref_id");
919  }
920  else
921  {
922  $ilTabs->setBackTarget($this->lng->txt("qpl"), $this->ctrl->getLinkTargetByClass("ilobjquestionpoolgui", "questions"));
923  }
924  }
925 }
926 ?>