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