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