ILIAS  Release_3_10_x_branch Revision 61812
 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 
49  $id = -1
50  )
51  {
52  $this->assQuestionGUI();
53  include_once "./Modules/TestQuestionPool/classes/class.assOrderingQuestion.php";
54  $this->object = new assOrderingQuestion();
55  if ($id >= 0)
56  {
57  $this->object->loadFromDb($id);
58  }
59  }
60 
61  function getCommand($cmd)
62  {
63  if (substr($cmd, 0, 6) == "delete")
64  {
65  $cmd = "delete";
66  }
67  if (substr($cmd, 0, 6) == "upload")
68  {
69  $cmd = "upload";
70  }
71 
72  return $cmd;
73  }
74 
75 
83  function editQuestion($ok = true)
84  {
85  $multiline_answers = $this->object->getMultilineAnswerSetting();
86  $this->getQuestionTemplate();
87  $this->tpl->addBlockFile("QUESTION_DATA", "question_data", "tpl.il_as_qpl_ordering.html", "Modules/TestQuestionPool");
88 
89  // Output of existing answers
90  for ($i = 0; $i < $this->object->getAnswerCount(); $i++)
91  {
92  $this->tpl->setCurrentBlock("deletebutton");
93  $this->tpl->setVariable("DELETE", $this->lng->txt("delete"));
94  $this->tpl->setVariable("ANSWER_ORDER", $i);
95  $this->tpl->parseCurrentBlock();
96 
97  $thisanswer = $this->object->getAnswer($i);
98  if ($this->object->getOrderingType() == OQ_PICTURES)
99  {
100  $this->tpl->setCurrentBlock("order_pictures");
101  $this->tpl->setVariable("ANSWER_ORDER", $i);
102  $this->tpl->setVariable("VALUE_ANSWER_COUNTER", $thisanswer->getOrder() + 1);
103  $this->tpl->setVariable("TEXT_ANSWER_PICTURE", $this->lng->txt("answer_picture"));
104 
105  $filename = $thisanswer->getAnswertext();
106  $extension = "jpg";
107  if (preg_match("/.*\.(png|jpg|gif|jpeg)$/", $filename, $matches))
108  {
109  $extension = $matches[1];
110  }
111  if ($filename)
112  {
113  $imagepath = $this->object->getImagePathWeb() . $thisanswer->getAnswertext();
114  $this->tpl->setVariable("UPLOADED_IMAGE", "<img src=\"$imagepath.thumb.jpg\" alt=\"" . $thisanswer->getAnswertext() . "\" border=\"\" />");
115  $this->tpl->setVariable("IMAGE_FILENAME", ilUtil::prepareFormOutput($thisanswer->getAnswertext()));
116  $this->tpl->setVariable("VALUE_ANSWER", "");
117  //$thisanswer->getAnswertext()
118  }
119  $this->tpl->setVariable("UPLOAD", $this->lng->txt("upload"));
120  }
121  elseif ($this->object->getOrderingType() == OQ_TERMS)
122  {
123  if ($multiline_answers)
124  {
125  $this->tpl->setCurrentBlock("show_textarea");
126  $this->tpl->setVariable("ANSWER_ORDER", $i);
127  $this->tpl->setVariable("VALUE_ANSWER", ilUtil::prepareFormOutput($thisanswer->getAnswertext()));
128  $this->tpl->parseCurrentBlock();
129  }
130  else
131  {
132  $this->tpl->setCurrentBlock("show_textinput");
133  $this->tpl->setVariable("ANSWER_ORDER", $i);
134  $this->tpl->setVariable("VALUE_ANSWER", ilUtil::prepareFormOutput($thisanswer->getAnswertext()));
135  $this->tpl->parseCurrentBlock();
136  }
137  }
138  $this->tpl->parseCurrentBlock();
139 
140  $this->tpl->setCurrentBlock("answers");
141  $anchor = "#answer_" . ($thisanswer->getOrder() + 1);
142  $this->tpl->setVariable("ANSWER_ORDER", $thisanswer->getOrder());
143  $this->tpl->setVariable("TEXT_ANSWER", $this->lng->txt("answer"));
144  $this->tpl->setVariable("VALUE_ORDER", $thisanswer->getSolutionOrder());
145  $this->tpl->setVariable("VALUE_ORDERING_POINTS", $thisanswer->getPoints());
146  $this->tpl->parseCurrentBlock();
147  }
148 
149  if (($this->ctrl->getCmd() == "addItem") and ($ok))
150  {
151  $i = $this->object->getAnswerCount() - 1;
152  for ($j = 1; $j <= $_POST["itemcount"]; $j++)
153  {
154  if ($this->object->getOrderingType() == OQ_PICTURES)
155  {
156  $this->tpl->setCurrentBlock("order_pictures");
157  $this->tpl->setVariable("ANSWER_ORDER", $i+$j);
158  $this->tpl->setVariable("VALUE_ANSWER", "");
159  $this->tpl->setVariable("UPLOAD", $this->lng->txt("upload"));
160  }
161  elseif ($this->object->getOrderingType() == OQ_TERMS)
162  {
163  if ($multiline_answers)
164  {
165  $this->tpl->setCurrentBlock("show_textarea");
166  $this->tpl->setVariable("ANSWER_ORDER", $i+$j);
167  $this->tpl->parseCurrentBlock();
168  }
169  else
170  {
171  $this->tpl->setCurrentBlock("show_textinput");
172  $this->tpl->setVariable("ANSWER_ORDER", $i+$j);
173  $this->tpl->parseCurrentBlock();
174  }
175  }
176  $this->tpl->parseCurrentBlock();
177 
178  // Create an empty answer
179  $this->tpl->setCurrentBlock("answers");
180  //$this->tpl->setVariable("TEXT_ANSWER_TEXT", $this->lng->txt("answer_text"));
181  $this->tpl->setVariable("TEXT_ANSWER", $this->lng->txt("answer"));
182  $anchor = "#answer_" . ($this->object->getAnswerCount() + $j);
183  $this->tpl->setVariable("TEXT_SOLUTION_ORDER", $this->lng->txt("solution_order"));
184  $this->tpl->setVariable("TEXT_POINTS", $this->lng->txt("points"));
185  if ($this->object->getOrderingType() == OQ_PICTURES)
186  {
187  $this->tpl->setVariable("TEXT_ANSWER_PICTURE", $this->lng->txt("answer_picture"));
188  }
189  else
190  {
191  $this->tpl->setVariable("TEXT_ANSWER_TEXT", $this->lng->txt("answer_text"));
192  }
193  $this->tpl->setVariable("ANSWER_ORDER", $i+$j);
194  $this->tpl->setVariable("VALUE_ORDER", $this->object->getMaxSolutionOrder() + $j);
195  $this->tpl->setVariable("VALUE_ORDERING_POINTS", sprintf("%s", 0));
196  $this->tpl->parseCurrentBlock();
197  }
198  }
199  // call to other question data i.e. estimated working time block
200  if ($this->object->getAnswerCount())
201  {
202  $this->tpl->setCurrentBlock("answerheader");
203  $this->tpl->setVariable("TEXT_POINTS", $this->lng->txt("points"));
204  if ($this->object->getOrderingType() == OQ_PICTURES)
205  {
206  $this->tpl->setVariable("TEXT_ANSWER_PICTURE", $this->lng->txt("answer_picture"));
207  }
208  else
209  {
210  $this->tpl->setVariable("TEXT_ANSWER_TEXT", $this->lng->txt("answer_text"));
211  }
212  $this->tpl->setVariable("TEXT_SOLUTION_ORDER", $this->lng->txt("solution_order"));
213  $this->tpl->parseCurrentBlock();
214  }
215 
216  if ($this->object->getOrderingType() == OQ_TERMS)
217  {
218  if ($multiline_answers)
219  {
220  $this->tpl->setVariable("SELECTED_SHOW_MULTILINE_ANSWERS", " selected=\"selected\"");
221  }
222  $this->tpl->setVariable("TEXT_HIDE_MULTILINE_ANSWERS", $this->lng->txt("multiline_terms_hide"));
223  $this->tpl->setVariable("TEXT_SHOW_MULTILINE_ANSWERS", $this->lng->txt("multiline_terms_show"));
224  }
225 
226  $this->outOtherQuestionData();
227 
228  $internallinks = array(
229  "lm" => $this->lng->txt("obj_lm"),
230  "st" => $this->lng->txt("obj_st"),
231  "pg" => $this->lng->txt("obj_pg"),
232  "glo" => $this->lng->txt("glossary_term")
233  );
234  foreach ($internallinks as $key => $value)
235  {
236  $this->tpl->setCurrentBlock("internallink");
237  $this->tpl->setVariable("TYPE_INTERNAL_LINK", $key);
238  $this->tpl->setVariable("TEXT_INTERNAL_LINK", $value);
239  $this->tpl->parseCurrentBlock();
240  }
241 
242  $this->tpl->setCurrentBlock("HeadContent");
243  $this->tpl->addJavascript("./Services/JavaScript/js/Basic.js");
244  $javascript = "<script type=\"text/javascript\">ilAddOnLoad(initialSelect);\n".
245  "function initialSelect() {\n%s\n}</script>";
246  switch ($this->ctrl->getCmd())
247  {
248  case "addItem":
249  $this->tpl->setVariable("CONTENT_BLOCK", sprintf($javascript, "document.frm_ordering.answer_".($this->object->getAnswerCount()).".focus(); document.frm_ordering.answer_".($this->object->getAnswerCount()).".scrollIntoView(\"true\");"));
250  break;
251  default:
252  $this->tpl->setVariable("CONTENT_BLOCK", sprintf($javascript, "document.frm_ordering.title.focus();"));
253  break;
254  }
255  $this->tpl->parseCurrentBlock();
256  for ($a = 1; $a < 9; $a++)
257  {
258  $this->tpl->setCurrentBlock("itemcountvalues");
259  $this->tpl->setVariable("ITEMCOUNTVALUE", $a);
260  if ($a > 1)
261  {
262  $this->tpl->setVariable("TEXT_ANSWER", $this->lng->txt("answers"));
263  }
264  else
265  {
266  $this->tpl->setVariable("TEXT_ANSWER", $this->lng->txt("answer"));
267  }
268  $this->tpl->parseCurrentBlock();
269  }
270  $this->tpl->setCurrentBlock("question_data");
271  $this->tpl->setVariable("VALUE_ADD", $this->lng->txt("add"));
272  $this->tpl->setVariable("TEXT_TITLE", $this->lng->txt("title"));
273  $this->tpl->setVariable("TEXT_AUTHOR", $this->lng->txt("author"));
274  $this->tpl->setVariable("TEXT_COMMENT", $this->lng->txt("description"));
275  $this->tpl->setVariable("TEXT_QUESTION", $this->lng->txt("question"));
276  $this->tpl->setVariable("TEXT_SHUFFLE_ANSWERS", $this->lng->txt("shuffle_answers"));
277  $this->tpl->setVariable("TXT_YES", $this->lng->txt("yes"));
278  $this->tpl->setVariable("TXT_NO", $this->lng->txt("no"));
279  if ($this->object->getShuffle())
280  {
281  $this->tpl->setVariable("SELECTED_YES", " selected=\"selected\"");
282  }
283  else
284  {
285  $this->tpl->setVariable("SELECTED_NO", " selected=\"selected\"");
286  }
287  $this->tpl->setVariable("ORDERING_ID", $this->object->getId());
288  $this->tpl->setVariable("VALUE_ORDERING_TITLE", ilUtil::prepareFormOutput($this->object->getTitle()));
289  $this->tpl->setVariable("VALUE_ORDERING_COMMENT", ilUtil::prepareFormOutput($this->object->getComment()));
290  $this->tpl->setVariable("VALUE_ORDERING_AUTHOR", ilUtil::prepareFormOutput($this->object->getAuthor()));
291  $questiontext = $this->object->getQuestion();
292  $this->tpl->setVariable("VALUE_QUESTION", ilUtil::prepareFormOutput($this->object->prepareTextareaOutput($questiontext)));
293  $this->tpl->setVariable("TEXT_TYPE", $this->lng->txt("type"));
294  $this->tpl->setVariable("TEXT_TYPE_PICTURES", $this->lng->txt("order_pictures"));
295  $this->tpl->setVariable("TEXT_TYPE_TERMS", $this->lng->txt("order_terms"));
296  if ($this->object->getOrderingType() == OQ_TERMS)
297  {
298  $this->tpl->setVariable("SELECTED_TERMS", " selected=\"selected\"");
299  }
300  elseif ($this->object->getOrderingType() == OQ_PICTURES)
301  {
302  $this->tpl->setVariable("SELECTED_PICTURES", " selected=\"selected\"");
303  }
304 
305  $this->tpl->setVariable("TEXT_SOLUTION_HINT", $this->lng->txt("solution_hint"));
306  if (count($this->object->suggested_solutions))
307  {
308  $solution_array = $this->object->getSuggestedSolution(0);
309  include_once "./Modules/TestQuestionPool/classes/class.assQuestion.php";
310  $href = assQuestion::_getInternalLinkHref($solution_array["internal_link"]);
311  $this->tpl->setVariable("TEXT_VALUE_SOLUTION_HINT", " <a href=\"$href\" target=\"content\">" . $this->lng->txt("solution_hint"). "</a> ");
312  $this->tpl->setVariable("BUTTON_REMOVE_SOLUTION", $this->lng->txt("remove"));
313  $this->tpl->setVariable("BUTTON_ADD_SOLUTION", $this->lng->txt("change"));
314  $this->tpl->setVariable("VALUE_SOLUTION_HINT", $solution_array["internal_link"]);
315  }
316  else
317  {
318  $this->tpl->setVariable("BUTTON_ADD_SOLUTION", $this->lng->txt("add"));
319  }
320 
321  $this->tpl->setVariable("SAVE", $this->lng->txt("save"));
322  $this->tpl->setVariable("SAVE_EDIT", $this->lng->txt("save_edit"));
323  $this->tpl->setVariable("CANCEL", $this->lng->txt("cancel"));
324  $this->tpl->setVariable("SET_EDIT_MODE", $this->lng->txt("set_edit_mode"));
325  $this->ctrl->setParameter($this, "sel_question_types", "assOrderingQuestion");
326  $this->tpl->setVariable("TEXT_QUESTION_TYPE", $this->outQuestionType());
327  $this->tpl->setVariable("ACTION_ORDERING_QUESTION", $this->ctrl->getFormAction($this));
328  $this->tpl->setVariable("TXT_REQUIRED_FLD", $this->lng->txt("required_field"));
329  $this->tpl->parseCurrentBlock();
330 
331  if ($this->error)
332  {
333  ilUtil::sendInfo($this->error);
334  }
335  include_once "./Services/RTE/classes/class.ilRTE.php";
336  $rtestring = ilRTE::_getRTEClassname();
337  include_once "./Services/RTE/classes/class.$rtestring.php";
338  $rte = new $rtestring();
339  $rte->addPlugin("latex");
340  $rte->addButton("latex"); $rte->addButton("pastelatex");
341  include_once "./classes/class.ilObject.php";
342  $obj_id = $_GET["q_id"];
343  $obj_type = ilObject::_lookupType($_GET["ref_id"], TRUE);
344  $rte->addRTESupport($obj_id, $obj_type, "assessment");
345 
346  $this->tpl->setCurrentBlock("adm_content");
347  //$this->tpl->setVariable("BODY_ATTRIBUTES", " onload=\"initialSelect();\"");
348  $this->tpl->parseCurrentBlock();
349  }
350 
351 
352  function addItem()
353  {
354  $ok = true;
355  if (!$this->checkInput())
356  {
357  // You cannot add answers before you enter the required data
358  $this->error .= $this->lng->txt("fill_out_all_required_fields_add_answer") . "<br />";
359  $ok = false;
360  }
361  else
362  {
363  foreach ($_POST as $key => $value)
364  {
365  if (preg_match("/answer_(\d+)/", $key, $matches))
366  {
367  if ((!$value) && ($this->object->getOrderingType() == OQ_TERMS))
368  {
369  $ok = false;
370  }
371  if ($this->object->getOrderingType() == OQ_PICTURES)
372  {
373  if ((!$_FILES[$key]["tmp_name"]) && (!$value))
374  {
375  $ok = false;
376  }
377  }
378  }
379  }
380  }
381  if (!$ok)
382  {
383  $this->error .= $this->lng->txt("fill_out_all_answer_fields") . "<br />";
384  }
385 
386  $this->writePostData();
387  $this->editQuestion($ok);
388  }
389 
393  function delete()
394  {
395  $this->writePostData();
396 
397  // Delete an answer if the delete button was pressed
398  foreach ($_POST[cmd] as $key => $value)
399  {
400  if (preg_match("/delete_(\d+)/", $key, $matches))
401  {
402  $this->object->deleteAnswer($matches[1]);
403  }
404  }
405  //$this->ctrl->redirect($this, "editQuestion"); works only on save
406  $this->editQuestion();
407  }
408 
412  function upload()
413  {
414  $this->writePostData();
415  $this->editQuestion();
416  }
417 
426  function writePostData()
427  {
428  $result = 0;
429  $saved = false;
430 
431  // Delete all existing answers and create new answers from the form data
432  $this->object->flushAnswers();
433 
434  $this->object->setTitle(ilUtil::stripSlashes($_POST["title"]));
435  $this->object->setAuthor(ilUtil::stripSlashes($_POST["author"]));
436  $this->object->setComment(ilUtil::stripSlashes($_POST["comment"]));
437  include_once "./Services/AdvancedEditing/classes/class.ilObjAdvancedEditing.php";
438  $questiontext = ilUtil::stripSlashes($_POST["question"], false, ilObjAdvancedEditing::_getUsedHTMLTagsAsString("assessment"));
439  $this->object->setQuestion($questiontext);
440  $this->object->setSuggestedSolution($_POST["solution_hint"], 0);
441  $this->object->setShuffle($_POST["shuffle"]);
442 
443  // adding estimated working time
444  $saved = $saved | $this->writeOtherPostData($result);
445  $this->object->setOrderingType($_POST["ordering_type"]);
446  if ($this->object->getOrderingType() == OQ_TERMS)
447  {
448  $this->object->setMultilineAnswerSetting($_POST["multilineAnswers"]);
449  }
450 
451  // Add answers from the form
452  foreach ($_POST as $key => $value)
453  {
454  if (preg_match("/answer_(\d+)/", $key, $matches))
455  {
456  if ($this->object->getOrderingType() == OQ_PICTURES)
457  {
458  if ($_FILES[$key]["tmp_name"])
459  {
460  // upload the ordering picture
461  if ($this->object->getId() <= 0)
462  {
463  $this->object->saveToDb();
464  $saved = true;
465  $this->error .= $this->lng->txt("question_saved_for_upload") . "<br />";
466  }
467  $image_file = $this->object->createNewImageFileName($_FILES[$key]["name"]);
468  $upload_result = $this->object->setImageFile($image_file, $_FILES[$key]['tmp_name']);
469  switch ($upload_result)
470  {
471  case 0:
472  $_POST[$key] = $image_file;
473  break;
474  case 1:
475  $this->error .= $this->lng->txt("error_image_upload_wrong_format") . "<br />";
476  break;
477  case 2:
478  $this->error .= $this->lng->txt("error_image_upload_copy_file") . "<br />";
479  break;
480  }
481  }
482  }
483  $points = $_POST["points_$matches[1]"];
484  if ($points < 0)
485  {
486  $result = 1;
487  $this->setErrorMessage($this->lng->txt("negative_points_not_allowed"));
488  }
489  $answer = $_POST["$key"];
490  include_once "./Services/AdvancedEditing/classes/class.ilObjAdvancedEditing.php";
491  $answer = ilUtil::stripSlashes($answer, false, ilObjAdvancedEditing::_getUsedHTMLTagsAsString("assessment"));
492  $this->object->addAnswer(
493  $answer,
494  ilUtil::stripSlashes($points),
495  ilUtil::stripSlashes($matches[1]),
496  ilUtil::stripSlashes($_POST["order_$matches[1]"])
497  );
498  }
499  }
500  if ($saved)
501  {
502  // If the question was saved automatically before an upload, we have to make
503  // sure, that the state after the upload is saved. Otherwise the user could be
504  // irritated, if he presses cancel, because he only has the question state before
505  // the upload process.
506  $this->object->saveToDb();
507  $this->ctrl->setParameter($this, "q_id", $this->object->getId());
508  }
509  return $result;
510  }
511 
512  function outQuestionForTest($formaction, $active_id, $pass = NULL, $is_postponed = FALSE, $user_post_solution = FALSE)
513  {
514  $test_output = $this->getTestOutput($active_id, $pass, $is_postponed, $user_post_solution);
515  $this->tpl->setVariable("QUESTION_OUTPUT", $test_output);
516  $this->tpl->setVariable("FORMACTION", $formaction);
517  }
518 
519  function getSolutionOutput($active_id, $pass = NULL, $graphicalOutput = FALSE, $result_output = FALSE, $show_question_only = TRUE, $show_feedback = FALSE, $show_correct_solution = FALSE)
520  {
521  // shuffle output
522  $keys = array_keys($this->object->answers);
523 
524  // generate the question output
525  include_once "./classes/class.ilTemplate.php";
526  $template = new ilTemplate("tpl.il_as_qpl_ordering_output_solution.html", TRUE, TRUE, "Modules/TestQuestionPool");
527  $solutiontemplate = new ilTemplate("tpl.il_as_tst_solution_output.html",TRUE, TRUE, "Modules/TestQuestionPool");
528 
529  // get the solution of the user for the active pass or from the last pass if allowed
530  $solutions = array();
531  if (($active_id > 0) && (!$show_correct_solution))
532  {
533  $solutions =& $this->object->getSolutionValues($active_id, $pass);
534  }
535  else
536  {
537  foreach ($this->object->answers as $index => $answer)
538  {
539  array_push($solutions, array("value1" => $index, "value2" => $answer->getSolutionOrder()));
540  }
541  }
542  foreach ($keys as $idx)
543  {
544  $answer = $this->object->answers[$idx];
545  if (($active_id > 0) && (!$show_correct_solution))
546  {
547  if ($graphicalOutput)
548  {
549  $sol = array();
550  foreach ($solutions as $solution)
551  {
552  $sol[$solution["value1"]] = $solution["value2"];
553  }
554  asort($sol);
555  $sol = array_keys($sol);
556  $ans = array();
557  foreach ($this->object->answers as $k => $a)
558  {
559  $ans[$k] = $a->getSolutionOrder();
560  }
561  asort($ans);
562  $ans = array_keys($ans);
563  $ok = FALSE;
564  foreach ($ans as $arr_idx => $ans_idx)
565  {
566  if ($ans_idx == $idx)
567  {
568  if ($ans_idx == $sol[$arr_idx])
569  {
570  $ok = TRUE;
571  }
572  }
573  }
574  // output of ok/not ok icons for user entered solutions
575  if ($ok)
576  {
577  $template->setCurrentBlock("icon_ok");
578  $template->setVariable("ICON_OK", ilUtil::getImagePath("icon_ok.gif"));
579  $template->setVariable("TEXT_OK", $this->lng->txt("answer_is_right"));
580  $template->parseCurrentBlock();
581  }
582  else
583  {
584  $template->setCurrentBlock("icon_ok");
585  $template->setVariable("ICON_NOT_OK", ilUtil::getImagePath("icon_not_ok.gif"));
586  $template->setVariable("TEXT_NOT_OK", $this->lng->txt("answer_is_wrong"));
587  $template->parseCurrentBlock();
588  }
589  }
590  }
591  if ($this->object->getOrderingType() == OQ_PICTURES)
592  {
593  $template->setCurrentBlock("ordering_row_standard_pictures");
594  $template->setVariable("THUMB_HREF", $this->object->getImagePathWeb() . $answer->getAnswertext() . ".thumb.jpg");
595  list($width, $height, $type, $attr) = getimagesize($this->object->getImagePath() . $answer->getAnswertext(). ".thumb.jpg");
596  $template->setVariable("ATTR", $attr);
597  $template->setVariable("THUMB_ALT", $this->lng->txt("thumbnail"));
598  $template->setVariable("THUMB_TITLE", $this->lng->txt("enlarge"));
599  $template->parseCurrentBlock();
600  }
601  else
602  {
603  $template->setCurrentBlock("ordering_row_standard_text");
604  $template->setVariable("ANSWER_TEXT", $this->object->prepareTextareaOutput($answer->getAnswertext(), TRUE));
605  $template->parseCurrentBlock();
606  }
607  $template->setCurrentBlock("ordering_row_standard");
608  if ($result_output)
609  {
610  $answer = $this->object->answers[$idx];
611  $points = $answer->getPoints();
612  $resulttext = ($points == 1) ? "(%s " . $this->lng->txt("point") . ")" : "(%s " . $this->lng->txt("points") . ")";
613  $template->setVariable("RESULT_OUTPUT", sprintf($resulttext, $points));
614  }
615  foreach ($solutions as $solution)
616  {
617  if (strcmp($solution["value1"], $idx) == 0)
618  {
619  $template->setVariable("ANSWER_ORDER", $solution["value2"]);
620  }
621  }
622  $template->parseCurrentBlock();
623  }
624  $questiontext = $this->object->getQuestion();
625  $template->setVariable("QUESTIONTEXT", $this->object->prepareTextareaOutput($questiontext, TRUE));
626  $questionoutput = $template->get();
627  $feedback = ($show_feedback) ? $this->getAnswerFeedbackOutput($active_id, $pass) : "";
628  if (strlen($feedback)) $solutiontemplate->setVariable("FEEDBACK", $feedback);
629  $solutiontemplate->setVariable("SOLUTION_OUTPUT", $questionoutput);
630 
631  $solutionoutput = $solutiontemplate->get();
632  if (!$show_question_only)
633  {
634  // get page object output
635  $solutionoutput = $this->getILIASPage($solutionoutput);
636  }
637  return $solutionoutput;
638  }
639 
640  function getPreview($show_question_only = FALSE)
641  {
642  // shuffle output
643  $keys = array_keys($this->object->answers);
644  if ($this->object->getShuffle())
645  {
646  $keys = $this->object->pcArrayShuffle($keys);
647  }
648 
649  // generate the question output
650  include_once "./classes/class.ilTemplate.php";
651  $template = new ilTemplate("tpl.il_as_qpl_ordering_output.html", TRUE, TRUE, "Modules/TestQuestionPool");
652 
653  foreach ($keys as $idx)
654  {
655  $answer = $this->object->answers[$idx];
656  if ($this->object->getOrderingType() == OQ_PICTURES)
657  {
658  $template->setCurrentBlock("ordering_row_standard_pictures");
659  $template->setVariable("PICTURE_HREF", $this->object->getImagePathWeb() . $answer->getAnswertext());
660  $template->setVariable("THUMB_HREF", $this->object->getImagePathWeb() . $answer->getAnswertext() . ".thumb.jpg");
661  $template->setVariable("THUMB_ALT", $this->lng->txt("thumbnail"));
662  $template->setVariable("THUMB_TITLE", $this->lng->txt("enlarge"));
663  $template->setVariable("ANSWER_ID", $idx);
664  $template->parseCurrentBlock();
665  }
666  else
667  {
668  $template->setCurrentBlock("ordering_row_standard_text");
669  $template->setVariable("ANSWER_TEXT", $this->object->prepareTextareaOutput($answer->getAnswertext(), TRUE));
670  $template->setVariable("ANSWER_ID", $idx);
671  $template->parseCurrentBlock();
672  }
673  $template->setCurrentBlock("ordering_row_standard");
674  $template->setVariable("ANSWER_ID", $idx);
675  $template->parseCurrentBlock();
676  }
677 
678  $questiontext = $this->object->getQuestion();
679  $template->setVariable("QUESTIONTEXT", $this->object->prepareTextareaOutput($questiontext, TRUE));
680  $questionoutput = $template->get();
681  if (!$show_question_only)
682  {
683  // get page object output
684  $questionoutput = $this->getILIASPage($questionoutput);
685  }
686  return $questionoutput;
687  }
688 
689  function getTestOutput($active_id, $pass = NULL, $is_postponed = FALSE, $user_post_solution = FALSE)
690  {
691  // shuffle output
692  $keys = array();
693  if (is_array($user_post_solution))
694  {
695  $keys = $_SESSION["ordering_keys"];
696  }
697  else
698  {
699  $keys = array_keys($this->object->answers);
700  if ($this->object->getShuffle())
701  {
702  $keys = $this->object->pcArrayShuffle($keys);
703  }
704  }
705  $_SESSION["ordering_keys"] = $keys;
706 
707  // generate the question output
708  include_once "./classes/class.ilTemplate.php";
709 
710  $template = new ilTemplate("tpl.il_as_qpl_ordering_output.html", TRUE, TRUE, "Modules/TestQuestionPool");
711  if ($this->object->getOutputType() == OUTPUT_JAVASCRIPT)
712  {
713  // BEGIN: add javascript code for javascript enabled ordering questions
714  $this->tpl->addBlockFile("CONTENT_BLOCK", "head_content", "tpl.il_as_qpl_ordering_output_javascript.html", "Modules/TestQuestionPool");
715  $this->tpl->setCurrentBlock("head_content");
716  $this->tpl->setVariable("JS_LOCATION", "./Modules/TestQuestionPool/js/toolman/");
717  $this->tpl->parseCurrentBlock();
718  // END: add javascript code for javascript enabled ordering questions
719 
720  // BEGIN: add additional stylesheet for javascript enabled ordering questions
721  $this->tpl->setCurrentBlock("AdditionalStyle");
722  $this->tpl->setVariable("LOCATION_ADDITIONAL_STYLESHEET", ilUtil::getStyleSheetLocation("output", "test_javascript.css", "Modules/TestQuestionPool"));
723  $this->tpl->parseCurrentBlock();
724  // END: add additional stylesheet for javascript enabled ordering questions
725 
726  // BEGIN: onsubmit form action for javascript enabled ordering questions
727  $this->tpl->setVariable("ON_SUBMIT", "return saveOrder('orderlist');");
728  // END: onsubmit form action for javascript enabled ordering questions
729  }
730 
731  // get the solution of the user for the active pass or from the last pass if allowed
732  if ($active_id)
733  {
734  $solutions = NULL;
735  include_once "./Modules/Test/classes/class.ilObjTest.php";
736  if (!ilObjTest::_getUsePreviousAnswers($active_id, true))
737  {
738  if (is_null($pass)) $pass = ilObjTest::_getPass($active_id);
739  }
740  if (is_array($user_post_solution))
741  {
742  $solutions = array();
743  foreach ($user_post_solution as $key => $value)
744  {
745  if (preg_match("/order_(\d+)/", $key, $matches))
746  {
747  array_push($solutions, array("value1" => $matches[1], "value2" => $value));
748  }
749  }
750  }
751  else
752  {
753  $solutions =& $this->object->getSolutionValues($active_id, $pass);
754  }
755 
756  if ($this->object->getOutputType() == OUTPUT_JAVASCRIPT)
757  {
758  $solution_script .= "";
759  $jssolutions = array();
760  foreach ($solutions as $idx => $solution_value)
761  {
762  if ((strcmp($solution_value["value2"], "") != 0) && (strcmp($solution_value["value1"], "") != 0))
763  {
764  $jssolutions[$solution_value["value2"]] = $solution_value["value1"];
765  }
766  }
767  if (count($jssolutions))
768  {
769  ksort($jssolutions);
770  $js = "";
771  foreach ($jssolutions as $key => $value)
772  {
773  $js .= "initialorder.push($value);";
774  }
775  $js .= "restoreInitialOrder();";
776  }
777  if (strlen($js))
778  {
779  $template->setCurrentBlock("javascript_restore_order");
780  $template->setVariable("RESTORE_ORDER", $js);
781  $template->parseCurrentBlock();
782  }
783  }
784  }
785 
786  if ($this->object->getOutputType() != OUTPUT_JAVASCRIPT)
787  {
788  foreach ($keys as $idx)
789  {
790  $answer = $this->object->answers[$idx];
791  if ($this->object->getOrderingType() == OQ_PICTURES)
792  {
793  $template->setCurrentBlock("ordering_row_standard_pictures");
794  $template->setVariable("PICTURE_HREF", $this->object->getImagePathWeb() . $answer->getAnswertext());
795  $template->setVariable("THUMB_HREF", $this->object->getImagePathWeb() . $answer->getAnswertext() . ".thumb.jpg");
796  $template->setVariable("THUMB_ALT", $this->lng->txt("thumbnail"));
797  $template->setVariable("THUMB_TITLE", $this->lng->txt("enlarge"));
798  $template->setVariable("ANSWER_ID", $idx);
799  $template->parseCurrentBlock();
800  }
801  else
802  {
803  $template->setCurrentBlock("ordering_row_standard_text");
804  $template->setVariable("ANSWER_TEXT", $this->object->prepareTextareaOutput($answer->getAnswertext(), TRUE));
805  $template->setVariable("ANSWER_ID", $idx);
806  $template->parseCurrentBlock();
807  }
808  $template->setCurrentBlock("ordering_row_standard");
809  $template->setVariable("ANSWER_ID", $idx);
810  if (is_array($solutions))
811  {
812  foreach ($solutions as $solution)
813  {
814  if (($solution["value1"] == $idx) && (strlen($solution["value2"])))
815  {
816  $template->setVariable("ANSWER_ORDER", " value=\"" . $solution["value2"] . "\"");
817  }
818  }
819  }
820  $template->parseCurrentBlock();
821  }
822  }
823  else
824  {
825  foreach ($keys as $idx)
826  {
827  $answer = $this->object->answers[$idx];
828  if ($this->object->getOrderingType() == OQ_PICTURES)
829  {
830  $template->setCurrentBlock("ordering_row_javascript_pictures");
831  $template->setVariable("PICTURE_HREF", $this->object->getImagePathWeb() . $answer->getAnswertext());
832  $template->setVariable("THUMB_HREF", $this->object->getImagePathWeb() . $answer->getAnswertext() . ".thumb.jpg");
833  $template->setVariable("THUMB_ALT", $this->lng->txt("thumbnail"));
834  $template->setVariable("THUMB_TITLE", $this->lng->txt("thumbnail"));
835  $template->setVariable("ENLARGE_HREF", ilUtil::getImagePath("enlarge.gif", FALSE));
836  $template->setVariable("ENLARGE_ALT", $this->lng->txt("enlarge"));
837  $template->setVariable("ENLARGE_TITLE", $this->lng->txt("enlarge"));
838  $template->setVariable("ANSWER_ID", $idx);
839  $template->parseCurrentBlock();
840  }
841  else
842  {
843  $template->setCurrentBlock("ordering_row_javascript_text");
844  $template->setVariable("ANSWER_TEXT", $this->object->prepareTextareaOutput($answer->getAnswertext(), TRUE));
845  $template->setVariable("ANSWER_ID", $idx);
846  $template->parseCurrentBlock();
847  }
848  }
849  $template->setCurrentBlock("ordering_with_javascript");
850  if ($this->object->getOrderingType() == OQ_PICTURES)
851  {
852  $template->setVariable("RESET_POSITIONS", $this->lng->txt("reset_pictures"));
853  }
854  else
855  {
856  $template->setVariable("RESET_POSITIONS", $this->lng->txt("reset_definitions"));
857  }
858  $template->parseCurrentBlock();
859  }
860  $questiontext = $this->object->getQuestion();
861  $template->setVariable("QUESTIONTEXT", $this->object->prepareTextareaOutput($questiontext, TRUE));
862  $questionoutput = $template->get();
863  $pageoutput = $this->outQuestionPage("", $is_postponed, $active_id, $questionoutput);
864  return $pageoutput;
865  }
866 
870  function checkInput()
871  {
872  if ((!$_POST["title"]) or (!$_POST["author"]) or (!$_POST["question"]))
873  {
874  return false;
875  }
876  return true;
877  }
878 
880  {
881  $_SESSION["subquestion_index"] = 0;
882  if ($_POST["cmd"]["addSuggestedSolution"])
883  {
884  if ($this->writePostData())
885  {
887  $this->editQuestion();
888  return;
889  }
890  if (!$this->checkInput())
891  {
892  ilUtil::sendInfo($this->lng->txt("fill_out_all_required_fields_add_answer"));
893  $this->editQuestion();
894  return;
895  }
896  }
897  $this->object->saveToDb();
898  $this->ctrl->setParameter($this, "q_id", $this->object->getId());
899  $this->tpl->setVariable("HEADER", $this->object->getTitle());
900  $this->getQuestionTemplate();
902  }
903 
904  function editMode()
905  {
906  global $ilUser;
907 
908  if ($this->object->getOrderingType() == OQ_TERMS)
909  {
910  $this->object->setMultilineAnswerSetting($_POST["multilineAnswers"]);
911  }
912  $this->object->setOrderingType($_POST["ordering_type"]);
913  $this->writePostData();
914  $this->editQuestion();
915  }
916 
924  function saveFeedback()
925  {
926  include_once "./Services/AdvancedEditing/classes/class.ilObjAdvancedEditing.php";
927  $this->object->saveFeedbackGeneric(0, ilUtil::stripSlashes($_POST["feedback_incomplete"], false, ilObjAdvancedEditing::_getUsedHTMLTagsAsString("assessment")));
928  $this->object->saveFeedbackGeneric(1, ilUtil::stripSlashes($_POST["feedback_complete"], false, ilObjAdvancedEditing::_getUsedHTMLTagsAsString("assessment")));
929  $this->object->cleanupMediaObjectUsage();
931  }
932 
940  function feedback()
941  {
942  $this->tpl->addBlockFile("ADM_CONTENT", "feedback", "tpl.il_as_qpl_ordering_feedback.html", "Modules/TestQuestionPool");
943  $this->tpl->setVariable("FEEDBACK_TEXT", $this->lng->txt("feedback"));
944  $this->tpl->setVariable("FEEDBACK_COMPLETE", $this->lng->txt("feedback_complete_solution"));
945  $this->tpl->setVariable("VALUE_FEEDBACK_COMPLETE", ilUtil::prepareFormOutput($this->object->prepareTextareaOutput($this->object->getFeedbackGeneric(1)), FALSE));
946  $this->tpl->setVariable("FEEDBACK_INCOMPLETE", $this->lng->txt("feedback_incomplete_solution"));
947  $this->tpl->setVariable("VALUE_FEEDBACK_INCOMPLETE", ilUtil::prepareFormOutput($this->object->prepareTextareaOutput($this->object->getFeedbackGeneric(0)), FALSE));
948  global $rbacsystem;
949  if ($rbacsystem->checkAccess('write', $_GET["ref_id"]))
950  {
951  $this->tpl->setVariable("SAVE", $this->lng->txt("save"));
952  }
953  $this->tpl->setVariable("FORMACTION", $this->ctrl->getFormAction($this));
954 
955  include_once "./Services/RTE/classes/class.ilRTE.php";
956  $rtestring = ilRTE::_getRTEClassname();
957  include_once "./Services/RTE/classes/class.$rtestring.php";
958  $rte = new $rtestring();
959  $rte->addPlugin("latex");
960  $rte->addButton("latex"); $rte->addButton("pastelatex");
961  include_once "./classes/class.ilObject.php";
962  $obj_id = $_GET["q_id"];
963  $obj_type = ilObject::_lookupType($_GET["ref_id"], TRUE);
964  $rte->addRTESupport($obj_id, $obj_type, "assessment");
965  }
966 
974  function setQuestionTabs()
975  {
976  global $rbacsystem, $ilTabs;
977 
978  $this->ctrl->setParameterByClass("ilpageobjectgui", "q_id", $_GET["q_id"]);
979  include_once "./Modules/TestQuestionPool/classes/class.assQuestion.php";
980  $q_type = $this->object->getQuestionType();
981 
982  if (strlen($q_type))
983  {
984  $classname = $q_type . "GUI";
985  $this->ctrl->setParameterByClass(strtolower($classname), "sel_question_types", $q_type);
986  $this->ctrl->setParameterByClass(strtolower($classname), "q_id", $_GET["q_id"]);
987  }
988 
989  if ($_GET["q_id"])
990  {
991  if ($rbacsystem->checkAccess('write', $_GET["ref_id"]))
992  {
993  // edit page
994  $ilTabs->addTarget("edit_content",
995  $this->ctrl->getLinkTargetByClass("ilPageObjectGUI", "edit"),
996  array("edit", "insert", "exec_pg"),
997  "", "", $force_active);
998  }
999 
1000  // edit page
1001  $ilTabs->addTarget("preview",
1002  $this->ctrl->getLinkTargetByClass("ilPageObjectGUI", "preview"),
1003  array("preview"),
1004  "ilPageObjectGUI", "", $force_active);
1005  }
1006 
1007  $force_active = false;
1008  if ($rbacsystem->checkAccess('write', $_GET["ref_id"]))
1009  {
1010  $url = "";
1011  if ($classname) $url = $this->ctrl->getLinkTargetByClass($classname, "editQuestion");
1012  $commands = $_POST["cmd"];
1013  if (is_array($commands))
1014  {
1015  foreach ($commands as $key => $value)
1016  {
1017  if (preg_match("/^delete_.*/", $key, $matches))
1018  {
1019  $force_active = true;
1020  }
1021  }
1022  }
1023  // edit question properties
1024  $ilTabs->addTarget("edit_properties",
1025  $url,
1026  array("editQuestion", "save", "cancel", "addSuggestedSolution",
1027  "cancelExplorer", "linkChilds", "removeSuggestedSolution", "editMode", "addItem", "upload",
1028  "saveEdit"),
1029  $classname, "", $force_active);
1030  }
1031 
1032  if ($_GET["q_id"])
1033  {
1034  $ilTabs->addTarget("feedback",
1035  $this->ctrl->getLinkTargetByClass($classname, "feedback"),
1036  array("feedback", "saveFeedback"),
1037  $classname, "");
1038  }
1039 
1040  // Assessment of questions sub menu entry
1041  if ($_GET["q_id"])
1042  {
1043  $ilTabs->addTarget("statistics",
1044  $this->ctrl->getLinkTargetByClass($classname, "assessment"),
1045  array("assessment"),
1046  $classname, "");
1047  }
1048 
1049  if (($_GET["calling_test"] > 0) || ($_GET["test_ref_id"] > 0))
1050  {
1051  $ref_id = $_GET["calling_test"];
1052  if (strlen($ref_id) == 0) $ref_id = $_GET["test_ref_id"];
1053  $ilTabs->setBackTarget($this->lng->txt("backtocallingtest"), "ilias.php?baseClass=ilObjTestGUI&cmd=questions&ref_id=$ref_id");
1054  }
1055  else
1056  {
1057  $ilTabs->setBackTarget($this->lng->txt("qpl"), $this->ctrl->getLinkTargetByClass("ilobjquestionpoolgui", "questions"));
1058  }
1059  }
1060 }
1061 ?>