ILIAS  Release_4_0_x_branch Revision 61816
 All Data Structures Namespaces Files Functions Variables Groups Pages
class.assMatchingQuestionGUI.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 {
47  function __construct($id = -1)
48  {
50  include_once "./Modules/TestQuestionPool/classes/class.assMatchingQuestion.php";
51  $this->object = new assMatchingQuestion();
52  $this->setErrorMessage($this->lng->txt("msg_form_save_error"));
53  if ($id >= 0)
54  {
55  $this->object->loadFromDb($id);
56  }
57  }
58 
59  function getCommand($cmd)
60  {
61  return $cmd;
62  }
63 
70  function writePostData($always = false)
71  {
72  $hasErrors = (!$always) ? $this->editQuestion(true) : false;
73  if (!$hasErrors)
74  {
75  $this->object->setTitle($_POST["title"]);
76  $this->object->setAuthor($_POST["author"]);
77  $this->object->setComment($_POST["comment"]);
78  include_once "./Services/AdvancedEditing/classes/class.ilObjAdvancedEditing.php";
79  $questiontext = $_POST["question"];
80  $this->object->setQuestion($questiontext);
81  if (!$this->getSelfAssessmentEditingMode())
82  {
83  $this->object->setShuffle($_POST["shuffle"]);
84  }
85  else
86  {
87  $this->object->setShuffle(1);
88  }
89  $this->object->setThumbGeometry($_POST["thumb_geometry"]);
90  $this->object->setElementHeight($_POST["element_height"]);
91  if ($this->getSelfAssessmentEditingMode())
92  {
93  $this->object->setNrOfTries($_POST['nr_of_tries']);
94  }
95  // adding estimated working time
96  $this->object->setEstimatedWorkingTime(
97  $_POST["Estimated"]["hh"],
98  $_POST["Estimated"]["mm"],
99  $_POST["Estimated"]["ss"]
100  );
101 
102  // Delete all existing answers and create new answers from the form data
103  $this->object->flushMatchingPairs();
104  $this->object->flushTerms();
105  $this->object->flushDefinitions();
106  $saved = false;
107 
108  // add terms
109  include_once "./Modules/TestQuestionPool/classes/class.assAnswerMatchingTerm.php";
110  foreach ($_POST['terms']['answer'] as $index => $answer)
111  {
112  $filename = $_POST['terms']['imagename'][$index];
113  if (strlen($_FILES['terms']['name']['image'][$index]))
114  {
115  // upload the new file
116  $name = $_FILES['terms']['name']['image'][$index];
117  if ($this->object->setImageFile($_FILES['terms']['tmp_name']['image'][$index], $this->object->getEncryptedFilename($name)))
118  {
119  $filename = $this->object->getEncryptedFilename($name);
120  }
121  else
122  {
123  $filename = "";
124  }
125  }
126  $this->object->addTerm(new assAnswerMatchingTerm($answer, $filename, $_POST['terms']['identifier'][$index]));
127  }
128  // add definitions
129  include_once "./Modules/TestQuestionPool/classes/class.assAnswerMatchingDefinition.php";
130  foreach ($_POST['definitions']['answer'] as $index => $answer)
131  {
132  $filename = $_POST['definitions']['imagename'][$index];
133  if (strlen($_FILES['definitions']['name']['image'][$index]))
134  {
135  // upload the new file
136  $name = $_FILES['definitions']['name']['image'][$index];
137  if ($this->object->setImageFile($_FILES['definitions']['tmp_name']['image'][$index], $this->object->getEncryptedFilename($name)))
138  {
139  $filename = $this->object->getEncryptedFilename($name);
140  }
141  else
142  {
143  $filename = "";
144  }
145  }
146  $this->object->addDefinition(new assAnswerMatchingDefinition($answer, $filename, $_POST['definitions']['identifier'][$index]));
147  }
148 
149  // add matching pairs
150  if (is_array($_POST['pairs']['points']))
151  {
152  include_once "./Modules/TestQuestionPool/classes/class.assAnswerMatchingPair.php";
153  foreach ($_POST['pairs']['points'] as $index => $points)
154  {
155  $term_id = $_POST['pairs']['term'][$index];
156  $definition_id = $_POST['pairs']['definition'][$index];
157  $this->object->addMatchingPair($this->object->getTermWithIdentifier($term_id), $this->object->getDefinitionWithIdentifier($definition_id), $points);
158  }
159  }
160  return 0;
161  }
162  else
163  {
164  return 1;
165  }
166  }
167 
171  public function uploadterms()
172  {
173  $this->writePostData(true);
174  $position = key($_POST['cmd']['uploadterms']);
175  $this->editQuestion();
176  }
177 
181  public function removeimageterms()
182  {
183  $this->writePostData(true);
184  $position = key($_POST['cmd']['removeimageterms']);
185  $filename = $_POST['terms']['imagename'][$position];
186  $this->object->removeTermImage($position);
187  $this->editQuestion();
188  }
189 
193  public function uploaddefinitions()
194  {
195  $this->writePostData(true);
196  $position = key($_POST['cmd']['uploaddefinitions']);
197  $this->editQuestion();
198  }
199 
203  public function removeimagedefinitions()
204  {
205  $this->writePostData(true);
206  $position = key($_POST['cmd']['removeimagedefinitions']);
207  $filename = $_POST['definitions']['imagename'][$position];
208  $this->object->removeDefinitionImage($position);
209  $this->editQuestion();
210  }
211 
212  public function addterms()
213  {
214  $this->writePostData();
215  $position = key($_POST["cmd"]["addterms"]);
216  $this->object->insertTerm($position+1);
217  $this->editQuestion();
218  }
219 
220  public function removeterms()
221  {
222  $this->writePostData();
223  $position = key($_POST["cmd"]["removeterms"]);
224  $this->object->deleteTerm($position);
225  $this->editQuestion();
226  }
227 
228  public function adddefinitions()
229  {
230  $this->writePostData();
231  $position = key($_POST["cmd"]["adddefinitions"]);
232  $this->object->insertDefinition($position+1);
233  $this->editQuestion();
234  }
235 
236  public function removedefinitions()
237  {
238  $this->writePostData();
239  $position = key($_POST["cmd"]["removedefinitions"]);
240  $this->object->deleteDefinition($position);
241  $this->editQuestion();
242  }
243 
244  public function addpairs()
245  {
246  $this->writePostData();
247  $position = key($_POST["cmd"]["addpairs"]);
248  $this->object->insertMatchingPair($position+1);
249  $this->editQuestion();
250  }
251 
252  public function removepairs()
253  {
254  $this->writePostData();
255  $position = key($_POST["cmd"]["removepairs"]);
256  $this->object->deleteMatchingPair($position);
257  $this->editQuestion();
258  }
259 
265  function editQuestion($checkonly = FALSE)
266  {
267  $save = ((strcmp($this->ctrl->getCmd(), "save") == 0) || (strcmp($this->ctrl->getCmd(), "saveEdit") == 0)) ? TRUE : FALSE;
268  $this->getQuestionTemplate();
269 
270  include_once("./Services/Form/classes/class.ilPropertyFormGUI.php");
271  $form = new ilPropertyFormGUI();
272  $form->setFormAction($this->ctrl->getFormAction($this));
273  $form->setTitle($this->outQuestionType());
274  $form->setMultipart(true);
275  $form->setTableWidth("100%");
276  $form->setId("matching");
277 
278  // Edit mode
279  $hidden = new ilHiddenInputGUI("matching_type");
280  $hidden->setValue($matchingtype);
281  $form->addItem($hidden);
282 
283  // title, author, description, question, working time (assessment mode)
284  $this->addBasicQuestionFormProperties($form);
285 
286  if (!$this->getSelfAssessmentEditingMode())
287  {
288  // shuffle
289  $shuffle = new ilSelectInputGUI($this->lng->txt("shuffle_answers"), "shuffle");
290  $shuffle_options = array(
291  0 => $this->lng->txt("no"),
292  1 => $this->lng->txt("matching_shuffle_terms_definitions"),
293  2 => $this->lng->txt("matching_shuffle_terms"),
294  3 => $this->lng->txt("matching_shuffle_definitions")
295  );
296  $shuffle->setOptions($shuffle_options);
297  $shuffle->setValue($this->object->getShuffle());
298  $shuffle->setRequired(FALSE);
299  $form->addItem($shuffle);
300 
301  $element_height = new ilNumberInputGUI($this->lng->txt("element_height"), "element_height");
302  $element_height->setValue($this->object->getElementHeight());
303  $element_height->setRequired(false);
304  $element_height->setMaxLength(6);
305  $element_height->setMinValue(20);
306  $element_height->setSize(6);
307  $element_height->setInfo($this->lng->txt("element_height_info"));
308  $form->addItem($element_height);
309 
310  $geometry = new ilNumberInputGUI($this->lng->txt("thumb_geometry"), "thumb_geometry");
311  $geometry->setValue($this->object->getThumbGeometry());
312  $geometry->setRequired(true);
313  $geometry->setMaxLength(6);
314  $geometry->setMinValue(20);
315  $geometry->setSize(6);
316  $geometry->setInfo($this->lng->txt("thumb_geometry_info"));
317  $form->addItem($geometry);
318  }
319 
320  // Definitions
321  include_once "./Modules/TestQuestionPool/classes/class.ilMatchingWizardInputGUI.php";
322  $definitions = new ilMatchingWizardInputGUI($this->lng->txt("definitions"), "definitions");
323  if ($this->getSelfAssessmentEditingMode()) $definitions->setHideImages(true);
324  $definitions->setRequired(true);
325  $definitions->setQuestionObject($this->object);
326  $definitions->setTextName($this->lng->txt('definition_text'));
327  $definitions->setImageName($this->lng->txt('definition_image'));
328  include_once "./Modules/TestQuestionPool/classes/class.assAnswerMatchingDefinition.php";
329  if (!count($this->object->getDefinitions())) $this->object->addDefinition(new assAnswerMatchingDefinition());
330  $definitionvalues = $this->object->getDefinitions();
331  $definitions->setValues($definitionvalues);
332  $form->addItem($definitions);
333 
334  // Terms
335  include_once "./Modules/TestQuestionPool/classes/class.ilMatchingWizardInputGUI.php";
336  $terms = new ilMatchingWizardInputGUI($this->lng->txt("terms"), "terms");
337  if ($this->getSelfAssessmentEditingMode()) $terms->setHideImages(true);
338  $terms->setRequired(true);
339  $terms->setQuestionObject($this->object);
340  $terms->setTextName($this->lng->txt('term_text'));
341  $terms->setImageName($this->lng->txt('term_image'));
342  include_once "./Modules/TestQuestionPool/classes/class.assAnswerMatchingTerm.php";
343  if (!count($this->object->getTerms())) $this->object->addTerm(new assAnswerMatchingTerm());
344  $termvalues = $this->object->getTerms();
345  $terms->setValues($termvalues);
346  $form->addItem($terms);
347 
348  // Matching Pairs
349  include_once "./Modules/TestQuestionPool/classes/class.ilMatchingPairWizardInputGUI.php";
350  $pairs = new ilMatchingPairWizardInputGUI($this->lng->txt('matching_pairs'), 'pairs');
351  $pairs->setRequired(true);
352  $pairs->setTerms($this->object->getTerms());
353  $pairs->setDefinitions($this->object->getDefinitions());
354  include_once "./Modules/TestQuestionPool/classes/class.assAnswerMatchingPair.php";
355  if (count($this->object->getMatchingPairs()) == 0)
356  {
357  $this->object->addMatchingPair(new assAnswerMatchingPair($termvalues[0], $definitionvalues[0], 0));
358  }
359  $pairs->setPairs($this->object->getMatchingPairs());
360  $form->addItem($pairs);
361 
362  $this->addQuestionFormCommandButtons($form);
363 
364  $errors = false;
365 
366  if ($save)
367  {
368  $form->setValuesByPost();
369  $errors = !$form->checkInput();
370  $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
371  if ((!$errors) && (count($terms->getValues()) < (count($definitions->getValues()))))
372  {
373  $errors = true;
374  $terms->setAlert($this->lng->txt("msg_number_of_terms_too_low"));
375  ilUtil::sendFailure($this->lng->txt('form_input_not_valid'));
376  }
377  if ($errors) $checkonly = false;
378  }
379 
380  if (!$checkonly) $this->tpl->setVariable("QUESTION_DATA", $form->getHTML());
381  return $errors;
382  }
383 
384  function outQuestionForTest($formaction, $active_id, $pass = NULL, $is_postponed = FALSE, $user_post_solution = FALSE)
385  {
386  $test_output = $this->getTestOutput($active_id, $pass, $is_postponed, $user_post_solution);
387  $this->tpl->setVariable("QUESTION_OUTPUT", $test_output);
388  $this->tpl->setVariable("FORMACTION", $formaction);
389  }
390 
405  $active_id,
406  $pass = NULL,
407  $graphicalOutput = FALSE,
408  $result_output = FALSE,
409  $show_question_only = TRUE,
410  $show_feedback = FALSE,
411  $show_correct_solution = FALSE,
412  $show_manual_scoring = FALSE
413  )
414  {
415  // generate the question output
416  include_once "./classes/class.ilTemplate.php";
417  $template = new ilTemplate("tpl.il_as_qpl_matching_output_solution.html", TRUE, TRUE, "Modules/TestQuestionPool");
418  $solutiontemplate = new ilTemplate("tpl.il_as_tst_solution_output.html",TRUE, TRUE, "Modules/TestQuestionPool");
419 
420  $solutions = array();
421  if (($active_id > 0) && (!$show_correct_solution))
422  {
423  include_once "./Modules/Test/classes/class.ilObjTest.php";
424  $solutions =& $this->object->getSolutionValues($active_id, $pass);
425  $solution_script .= "";
426  }
427  else
428  {
429  foreach ($this->object->getMatchingPairs() as $pair)
430  {
431  array_push($solutions, array("value1" => $pair->term->identifier, "value2" => $pair->definition->identifier));
432  }
433  }
434 
435  $i = 0;
436  foreach ($solutions as $solution)
437  {
438  $definition = $this->object->getDefinitionWithIdentifier($solution['value2']);
439  $term = $this->object->getTermWithIdentifier($solution['value1']);
440 
441  if (is_object($definition))
442  {
443  if (strlen($definition->picture))
444  {
445  $template->setCurrentBlock('definition_image');
446  $template->setVariable('ANSWER_IMAGE_URL', $this->object->getImagePathWeb() . $this->object->getThumbPrefix() . $definition->picture);
447  $template->setVariable('ANSWER_IMAGE_ALT', (strlen($definition->text)) ? $this->object->prepareTextareaOutput($definition->text, TRUE) : ilUtil::prepareFormOutput($definition->picture));
448  $template->setVariable('ANSWER_IMAGE_TITLE', (strlen($definition->text)) ? $this->object->prepareTextareaOutput($definition->text, TRUE) : ilUtil::prepareFormOutput($definition->picture));
449  $template->setVariable('URL_PREVIEW', $this->object->getImagePathWeb() . $definition->picture);
450  $template->setVariable("TEXT_PREVIEW", $this->lng->txt('preview'));
451  $template->setVariable("IMG_PREVIEW", ilUtil::getImagePath('enlarge.gif'));
452  $template->setVariable("TEXT_DEFINITION", (strlen($definition->text)) ? $this->lng->txt('definition') . ' ' . ($i+1) . ': ' . $this->object->prepareTextareaOutput($definition->text, TRUE) : $this->lng->txt('definition') . ' ' . ($i+1));
453  $template->parseCurrentBlock();
454  }
455  else
456  {
457  $template->setCurrentBlock('definition_text');
458  $template->setVariable("DEFINITION", ilUtil::htmlentitiesOutsideHTMLTags($this->object->prepareTextareaOutput($definition->text, TRUE)));
459  $template->parseCurrentBlock();
460  }
461  }
462  if (is_object($term))
463  {
464  if (strlen($term->picture))
465  {
466  $template->setCurrentBlock('term_image');
467  $template->setVariable('ANSWER_IMAGE_URL', $this->object->getImagePathWeb() . $this->object->getThumbPrefix() . $term->picture);
468  $template->setVariable('ANSWER_IMAGE_ALT', (strlen($term->text)) ? $this->object->prepareTextareaOutput($term->text, TRUE) : ilUtil::prepareFormOutput($term->picture));
469  $template->setVariable('ANSWER_IMAGE_TITLE', (strlen($term->text)) ? $this->object->prepareTextareaOutput($term->text, TRUE) : ilUtil::prepareFormOutput($term->picture));
470  $template->setVariable('URL_PREVIEW', $this->object->getImagePathWeb() . $term->picture);
471  $template->setVariable("TEXT_PREVIEW", $this->lng->txt('preview'));
472  $template->setVariable("TEXT_TERM", (strlen($term->text)) ? $this->lng->txt('term') . ' ' . ($i+1) . ': ' . $this->object->prepareTextareaOutput($term->text, TRUE) : $this->lng->txt('term') . ' ' . ($i+1));
473  $template->setVariable("IMG_PREVIEW", ilUtil::getImagePath('enlarge.gif'));
474  $template->parseCurrentBlock();
475  }
476  else
477  {
478  $template->setCurrentBlock('term_text');
479  $template->setVariable("TERM", ilUtil::htmlentitiesOutsideHTMLTags($this->object->prepareTextareaOutput($term->text, TRUE)));
480  $template->parseCurrentBlock();
481  }
482  $i++;
483  }
484  if (($active_id > 0) && (!$show_correct_solution))
485  {
486  if ($graphicalOutput)
487  {
488  // output of ok/not ok icons for user entered solutions
489  $ok = FALSE;
490  foreach ($this->object->getMatchingPairs() as $pair)
491  {
492  if (is_object($term)) if (($pair->definition->identifier == $definition->identifier) && ($pair->term->identifier == $term->identifier)) $ok = true;
493  }
494  if ($ok)
495  {
496  $template->setCurrentBlock("icon_ok");
497  $template->setVariable("ICON_OK", ilUtil::getImagePath("icon_ok.gif"));
498  $template->setVariable("TEXT_OK", $this->lng->txt("answer_is_right"));
499  $template->parseCurrentBlock();
500  }
501  else
502  {
503  $template->setCurrentBlock("icon_ok");
504  $template->setVariable("ICON_NOT_OK", ilUtil::getImagePath("icon_not_ok.gif"));
505  $template->setVariable("TEXT_NOT_OK", $this->lng->txt("answer_is_wrong"));
506  $template->parseCurrentBlock();
507  }
508  }
509  }
510 
511  if ($result_output)
512  {
513  $points = 0.0;
514  foreach ($this->object->getMatchingPairs() as $pair)
515  {
516  foreach ($solutions as $solution)
517  {
518  if (($solution['value2'] == $pair->definition->identifier) && ($solution['value1'] == $pair->term->identifier))
519  {
520  $points = $pair->points;
521  }
522  }
523  }
524  $resulttext = ($points == 1) ? "(%s " . $this->lng->txt("point") . ")" : "(%s " . $this->lng->txt("points") . ")";
525  $template->setCurrentBlock("result_output");
526  $template->setVariable("RESULT_OUTPUT", sprintf($resulttext, $points));
527  $template->parseCurrentBlock();
528  }
529 
530  $template->setCurrentBlock("row");
531  if ($this->object->getEstimatedElementHeight() > 0)
532  {
533  $template->setVariable("ELEMENT_HEIGHT", " style=\"height: " . $this->object->getEstimatedElementHeight() . "px;\"");
534  }
535  $template->setVariable("TEXT_MATCHES", $this->lng->txt("matches"));
536  $template->parseCurrentBlock();
537  }
538 
539  $questiontext = $this->object->getQuestion();
540  $template->setVariable("QUESTIONTEXT", $this->object->prepareTextareaOutput($questiontext, TRUE));
541  $questionoutput = $template->get();
542  $feedback = ($show_feedback) ? $this->getAnswerFeedbackOutput($active_id, $pass) : "";
543  if (strlen($feedback)) $solutiontemplate->setVariable("FEEDBACK", $feedback);
544  $solutiontemplate->setVariable("SOLUTION_OUTPUT", $questionoutput);
545 
546  $solutionoutput = $solutiontemplate->get();
547  if (!$show_question_only)
548  {
549  // get page object output
550  $solutionoutput = $this->getILIASPage($solutionoutput);
551  }
552  return $solutionoutput;
553  }
554 
555  public function getPreviewJS($show_question_only = FALSE)
556  {
557  global $ilUser;
558 
559  // generate the question output
560  include_once "./classes/class.ilTemplate.php";
561  $template = new ilTemplate("tpl.il_as_qpl_matching_output_js.html", TRUE, TRUE, "Modules/TestQuestionPool");
562 
563  $jsswitch = "";
564  if (strcmp($this->ctrl->getCmd(), 'preview') == 0)
565  {
566  if (array_key_exists('js', $_GET))
567  {
568  $ilUser->writePref('tst_javascript', $_GET['js']);
569  }
570  $jstemplate = new ilTemplate("tpl.il_as_qpl_javascript_switch.html", TRUE, TRUE, "Modules/TestQuestionPool");
571  if ($ilUser->getPref("tst_javascript") == 1)
572  {
573  $jstemplate->setVariable("JAVASCRIPT_IMAGE", ilUtil::getImagePath("javascript_disable.png"));
574  $jstemplate->setVariable("JAVASCRIPT_IMAGE_ALT", $this->lng->txt("disable_javascript"));
575  $jstemplate->setVariable("JAVASCRIPT_IMAGE_TITLE", $this->lng->txt("disable_javascript"));
576  $this->ctrl->setParameterByClass($this->ctrl->getCmdClass(), "js", "0");
577  $jstemplate->setVariable("JAVASCRIPT_URL", $this->ctrl->getLinkTargetByClass($this->ctrl->getCmdClass(), $this->ctrl->getCmd()));
578  }
579  else
580  {
581  $jstemplate->setVariable("JAVASCRIPT_IMAGE", ilUtil::getImagePath("javascript.png"));
582  $jstemplate->setVariable("JAVASCRIPT_IMAGE_ALT", $this->lng->txt("enable_javascript"));
583  $jstemplate->setVariable("JAVASCRIPT_IMAGE_TITLE", $this->lng->txt("enable_javascript"));
584  $this->ctrl->setParameterByClass($this->ctrl->getCmdClass(), "js", "1");
585  $jstemplate->setVariable("JAVASCRIPT_URL", $this->ctrl->getLinkTargetByClass($this->ctrl->getCmdClass(), $this->ctrl->getCmd()));
586  }
587  $jsswitch = $jstemplate->get();
588  if ($ilUser->getPref('tst_javascript')) $this->object->setOutputType(OUTPUT_JAVASCRIPT);
589  }
590 
591  // shuffle output
592  $terms = $this->object->getTerms();
593  $definitions = $this->object->getDefinitions();
594  switch ($this->object->getShuffle())
595  {
596  case 1:
597  $terms = $this->object->pcArrayShuffle($terms);
598  $definitions = $this->object->pcArrayShuffle($definitions);
599  break;
600  case 2:
601  $terms = $this->object->pcArrayShuffle($terms);
602  break;
603  case 3:
604  $definitions = $this->object->pcArrayShuffle($definitions);
605  break;
606  }
607 
608  include_once "./Services/YUI/classes/class.ilYuiUtil.php";
610 
611  // create definitions
612  $counter = 0;
613  foreach ($definitions as $definition)
614  {
615  if (strlen($definition->picture))
616  {
617  $template->setCurrentBlock("definition_picture");
618  $template->setVariable("DEFINITION_ID", $definition->identifier);
619  $template->setVariable("IMAGE_HREF", $this->object->getImagePathWeb() . $definition->picture);
620  $thumbweb = $this->object->getImagePathWeb() . $this->object->getThumbPrefix() . $definition->picture;
621  $thumb = $this->object->getImagePath() . $this->object->getThumbPrefix() . $definition->picture;
622  if (!@file_exists($thumb)) $this->object->rebuildThumbnails();
623  $template->setVariable("THUMBNAIL_HREF", $thumbweb);
624  $template->setVariable("THUMB_ALT", $this->lng->txt("image"));
625  $template->setVariable("THUMB_TITLE", $this->lng->txt("image"));
626  $template->setVariable("TEXT_DEFINITION", (strlen($definition->text)) ? ilUtil::htmlentitiesOutsideHTMLTags($this->object->prepareTextareaOutput($definition->text, TRUE)) : '');
627  $template->setVariable("TEXT_PREVIEW", $this->lng->txt('preview'));
628  $template->setVariable("IMG_PREVIEW", ilUtil::getImagePath('enlarge.gif'));
629  $template->parseCurrentBlock();
630  }
631  else
632  {
633  $template->setCurrentBlock("definition_text");
634  $template->setVariable("DEFINITION", ilUtil::htmlentitiesOutsideHTMLTags($this->object->prepareTextareaOutput($definition->text, TRUE)));
635  $template->parseCurrentBlock();
636  }
637 
638  $template->setCurrentBlock("droparea");
639  $template->setVariable("ID_DROPAREA", $definition->identifier);
640  $template->setVariable("QUESTION_ID", $this->object->getId());
641  if ($this->object->getEstimatedElementHeight() > 0)
642  {
643  $template->setVariable("ELEMENT_HEIGHT", " style=\"height: " . $this->object->getEstimatedElementHeight() . "px;\"");
644  }
645  $template->parseCurrentBlock();
646 
647  $template->setCurrentBlock("init_dropareas");
648  $template->setVariable("COUNTER", $counter++);
649  $template->setVariable("ID_DROPAREA", $definition->identifier);
650  $template->parseCurrentBlock();
651  }
652 
653 
654  // create terms
655  $counter = 0;
656  foreach ($terms as $term)
657  {
658  if (strlen($term->picture))
659  {
660  $template->setCurrentBlock("term_picture");
661  $template->setVariable("TERM_ID", $term->identifier);
662  $template->setVariable("IMAGE_HREF", $this->object->getImagePathWeb() . $term->picture);
663  $thumbweb = $this->object->getImagePathWeb() . $this->object->getThumbPrefix() . $term->picture;
664  $thumb = $this->object->getImagePath() . $this->object->getThumbPrefix() . $term->picture;
665  if (!@file_exists($thumb)) $this->object->rebuildThumbnails();
666  $template->setVariable("THUMBNAIL_HREF", $thumbweb);
667  $template->setVariable("THUMB_ALT", $this->lng->txt("image"));
668  $template->setVariable("THUMB_TITLE", $this->lng->txt("image"));
669  $template->setVariable("TEXT_PREVIEW", $this->lng->txt('preview'));
670  $template->setVariable("TEXT_TERM", (strlen($term->text)) ? ilUtil::htmlentitiesOutsideHTMLTags($this->object->prepareTextareaOutput($term->text, TRUE)) : '');
671  $template->setVariable("IMG_PREVIEW", ilUtil::getImagePath('enlarge.gif'));
672  $template->parseCurrentBlock();
673  }
674  else
675  {
676  $template->setCurrentBlock("term_text");
677  include_once "./Services/AdvancedEditing/classes/class.ilObjAdvancedEditing.php";
678  $template->setVariable("TERM_TEXT", ilUtil::htmlentitiesOutsideHTMLTags($this->object->prepareTextareaOutput($term->text, TRUE)));
679  $template->parseCurrentBlock();
680  }
681  $template->setCurrentBlock("draggable");
682  $template->setVariable("ID_DRAGGABLE", $term->identifier);
683  if ($this->object->getEstimatedElementHeight() > 0)
684  {
685  $template->setVariable("ELEMENT_HEIGHT", " style=\"height: " . $this->object->getEstimatedElementHeight() . "px;\"");
686  }
687  $template->parseCurrentBlock();
688 
689  $template->setCurrentBlock("init_draggables");
690  $template->setVariable("COUNTER", $counter++);
691  $template->setVariable("ID_DRAGGABLE", $term->identifier);
692  $template->parseCurrentBlock();
693  }
694 
695  $template->setVariable("RESET_BUTTON", $this->lng->txt("reset_terms"));
696 
697  $this->tpl->setVariable("LOCATION_ADDITIONAL_STYLESHEET", ilUtil::getStyleSheetLocation("output", "test_javascript.css", "Modules/TestQuestionPool"));
698 
699  $questiontext = $this->object->getQuestion();
700  $template->setVariable("QUESTIONTEXT", $this->object->prepareTextareaOutput($questiontext, TRUE));
701  $questionoutput = $jsswitch . $template->get();
702  if (!$show_question_only)
703  {
704  // get page object output
705  $questionoutput = $this->getILIASPage($questionoutput);
706  }
707  return $questionoutput;
708  }
709 
710  public function getPreview($show_question_only = FALSE)
711  {
712  global $ilUser;
713 
714  // generate the question output
715  include_once "./classes/class.ilTemplate.php";
716  $template = new ilTemplate("tpl.il_as_qpl_matching_output.html", TRUE, TRUE, "Modules/TestQuestionPool");
717 
718  $jsswitch = "";
719  if (strcmp($this->ctrl->getCmd(), 'preview') == 0)
720  {
721  if (array_key_exists('js', $_GET))
722  {
723  $ilUser->writePref('tst_javascript', $_GET['js']);
724  }
725  $jstemplate = new ilTemplate("tpl.il_as_qpl_javascript_switch.html", TRUE, TRUE, "Modules/TestQuestionPool");
726  if ($ilUser->getPref("tst_javascript") == 1)
727  {
728  $jstemplate->setVariable("JAVASCRIPT_IMAGE", ilUtil::getImagePath("javascript_disable.png"));
729  $jstemplate->setVariable("JAVASCRIPT_IMAGE_ALT", $this->lng->txt("disable_javascript"));
730  $jstemplate->setVariable("JAVASCRIPT_IMAGE_TITLE", $this->lng->txt("disable_javascript"));
731  $this->ctrl->setParameterByClass($this->ctrl->getCmdClass(), "js", "0");
732  $jstemplate->setVariable("JAVASCRIPT_URL", $this->ctrl->getLinkTargetByClass($this->ctrl->getCmdClass(), $this->ctrl->getCmd()));
733  }
734  else
735  {
736  $jstemplate->setVariable("JAVASCRIPT_IMAGE", ilUtil::getImagePath("javascript.png"));
737  $jstemplate->setVariable("JAVASCRIPT_IMAGE_ALT", $this->lng->txt("enable_javascript"));
738  $jstemplate->setVariable("JAVASCRIPT_IMAGE_TITLE", $this->lng->txt("enable_javascript"));
739  $this->ctrl->setParameterByClass($this->ctrl->getCmdClass(), "js", "1");
740  $jstemplate->setVariable("JAVASCRIPT_URL", $this->ctrl->getLinkTargetByClass($this->ctrl->getCmdClass(), $this->ctrl->getCmd()));
741  }
742  $jsswitch = $jstemplate->get();
743  if ($ilUser->getPref('tst_javascript')) $this->object->setOutputType(OUTPUT_JAVASCRIPT);
744  }
745 
746  if ($this->object->getOutputType() == OUTPUT_JAVASCRIPT)
747  {
748  return $this->getPreviewJS($show_question_only);
749  }
750 
751  // shuffle output
752  $terms = $this->object->getTerms();
753  $definitions = $this->object->getDefinitions();
754  switch ($this->object->getShuffle())
755  {
756  case 1:
757  $terms = $this->object->pcArrayShuffle($terms);
758  $definitions = $this->object->pcArrayShuffle($definitions);
759  break;
760  case 2:
761  $terms = $this->object->pcArrayShuffle($terms);
762  break;
763  case 3:
764  $definitions = $this->object->pcArrayShuffle($definitions);
765  break;
766  }
767 
768  for ($i = 0; $i < count($definitions); $i++)
769  {
770  $definition = $definitions[$i];
771  if (is_object($definition))
772  {
773  if (strlen($definition->picture))
774  {
775  $template->setCurrentBlock('definition_image');
776  $thumb = $this->object->getImagePath() . $this->object->getThumbPrefix() . $definition->picture;
777  if (!@file_exists($thumb)) $this->object->rebuildThumbnails();
778  $template->setVariable('ANSWER_IMAGE_URL', $this->object->getImagePathWeb() . $this->object->getThumbPrefix() . $definition->picture);
779  $template->setVariable('ANSWER_IMAGE_ALT', (strlen($definition->text)) ? $this->object->prepareTextareaOutput($definition->text, TRUE) : ilUtil::prepareFormOutput($definition->picture));
780  $template->setVariable('ANSWER_IMAGE_TITLE', (strlen($definition->text)) ? $this->object->prepareTextareaOutput($definition->text, TRUE) : ilUtil::prepareFormOutput($definition->picture));
781  $template->setVariable('URL_PREVIEW', $this->object->getImagePathWeb() . $definition->picture);
782  $template->setVariable("TEXT_PREVIEW", $this->lng->txt('preview'));
783  $template->setVariable("IMG_PREVIEW", ilUtil::getImagePath('enlarge.gif'));
784  $template->setVariable("TEXT_DEFINITION", (strlen($definition->text)) ? $this->lng->txt('definition') . ' ' . ($i+1) . ': ' . ilUtil::htmlentitiesOutsideHTMLTags($this->object->prepareTextareaOutput($definition->text, TRUE)) : $this->lng->txt('definition') . ' ' . ($i+1));
785  $template->parseCurrentBlock();
786  }
787  else
788  {
789  $template->setCurrentBlock('definition_text');
790  $template->setVariable("DEFINITION", ilUtil::htmlentitiesOutsideHTMLTags($this->object->prepareTextareaOutput($definition->text, TRUE)));
791  $template->parseCurrentBlock();
792  }
793  }
794 
795  $template->setCurrentBlock('option');
796  $template->setVariable("VALUE_OPTION", 0);
797  $template->setVariable("TEXT_OPTION", ilUtil::prepareFormOutput($this->lng->txt('please_select')));
798  $template->parseCurrentBlock();
799  $j = 1;
800  foreach ($terms as $term)
801  {
802  $template->setCurrentBlock('option');
803  $template->setVariable("VALUE_OPTION", $term->identifier);
804  $template->setVariable("TEXT_OPTION", (strlen($term->text)) ? $this->lng->txt('term') . ' ' . ($j) . ': ' . $this->object->prepareTextareaOutput($term->text, TRUE) : $this->lng->txt('term') . ' ' . ($j));
805  $template->parseCurrentBlock();
806  $j++;
807  }
808 
809  $template->setCurrentBlock('row');
810  $template->setVariable("TEXT_MATCHES", $this->lng->txt("matches"));
811  if ($this->object->getEstimatedElementHeight() > 0)
812  {
813  $template->setVariable("ELEMENT_HEIGHT", " style=\"height: " . $this->object->getEstimatedElementHeight() . "px;\"");
814  }
815  $template->setVariable("QUESTION_ID", $this->object->getId());
816  $template->setVariable("DEFINITION_ID", $definition->identifier);
817  $template->parseCurrentBlock();
818  }
819 
820  $i = 0;
821  foreach ($terms as $term)
822  {
823  if (strlen($term->picture))
824  {
825  $template->setCurrentBlock('term_image');
826  $thumb = $this->object->getImagePath() . $this->object->getThumbPrefix() . $term->picture;
827  if (!@file_exists($thumb)) $this->object->rebuildThumbnails();
828  $template->setVariable('ANSWER_IMAGE_URL', $this->object->getImagePathWeb() . $this->object->getThumbPrefix() . $term->picture);
829  $template->setVariable('ANSWER_IMAGE_ALT', (strlen($term->text)) ? $this->object->prepareTextareaOutput($term->text, TRUE) : ilUtil::prepareFormOutput($term->picture));
830  $template->setVariable('ANSWER_IMAGE_TITLE', (strlen($term->text)) ? $this->object->prepareTextareaOutput($term->text, TRUE) : ilUtil::prepareFormOutput($term->picture));
831  $template->setVariable('URL_PREVIEW', $this->object->getImagePathWeb() . $term->picture);
832  $template->setVariable("TEXT_PREVIEW", $this->lng->txt('preview'));
833  $template->setVariable("TEXT_TERM", (strlen($term->text)) ? $this->lng->txt('term') . ' ' . ($i+1) . ': ' . ilUtil::htmlentitiesOutsideHTMLTags($this->object->prepareTextareaOutput($term->text, TRUE)) : $this->lng->txt('term') . ' ' . ($i+1));
834  $template->setVariable("IMG_PREVIEW", ilUtil::getImagePath('enlarge.gif'));
835  $template->parseCurrentBlock();
836  }
837  else
838  {
839  $template->setCurrentBlock('term_text');
840  $template->setVariable("TERM", ilUtil::htmlentitiesOutsideHTMLTags($this->object->prepareTextareaOutput($term->text, TRUE)));
841  $template->parseCurrentBlock();
842  }
843  $template->touchBlock('terms');
844  $i++;
845  }
846 
847  $questiontext = $this->object->getQuestion();
848  $template->setVariable("QUESTIONTEXT", $this->object->prepareTextareaOutput($questiontext, TRUE));
849  $template->setVariable("TEXT_TERMS", ilUtil::prepareFormOutput($this->lng->txt('available_terms')));
850  $template->setVariable('TEXT_SELECTION', ilUtil::prepareFormOutput($this->lng->txt('selection')));
851  $questionoutput = $jsswitch . $template->get();
852  if (!$show_question_only)
853  {
854  // get page object output
855  $questionoutput = $this->getILIASPage($questionoutput);
856  }
857  return $questionoutput;
858  }
859 
860  protected function sortDefinitionsBySolution($solution)
861  {
862  $neworder = array();
863  foreach ($solution as $solution_values)
864  {
865  $id = $solution_values['value2'];
866  array_push($neworder, $this->object->getDefinitionWithIdentifier($id));
867  }
868  return $neworder;
869  }
870 
871  function getTestOutputJS($active_id, $pass = NULL, $is_postponed = FALSE, $user_post_solution = FALSE)
872  {
873  // generate the question output
874  include_once "./classes/class.ilTemplate.php";
875  $template = new ilTemplate("tpl.il_as_qpl_matching_output_js.html", TRUE, TRUE, "Modules/TestQuestionPool");
876 
877  if ($active_id)
878  {
879  $solutions = NULL;
880  include_once "./Modules/Test/classes/class.ilObjTest.php";
881  if (!ilObjTest::_getUsePreviousAnswers($active_id, true))
882  {
883  if (is_null($pass)) $pass = ilObjTest::_getPass($active_id);
884  }
885  if (is_array($user_post_solution))
886  {
887  $solutions = array();
888  foreach ($user_post_solution['matching'][$this->object->getId()] as $definition => $term)
889  {
890  array_push($solutions, array("value1" => $term, "value2" => $definition));
891  }
892  }
893  else
894  {
895  $solutions =& $this->object->getSolutionValues($active_id, $pass);
896  }
897 
898  foreach ($solutions as $idx => $solution_value)
899  {
900  if ($this->object->getOutputType() == OUTPUT_JAVASCRIPT)
901  {
902  if (($solution_value["value2"] > -1) && ($solution_value["value1"] > -1))
903  {
904  $template->setCurrentBlock("restoreposition");
905  $template->setVariable("TERM_ID", $solution_value["value1"]);
906  $template->setVariable("PICTURE_DEFINITION_ID", $solution_value["value2"]);
907  $template->parseCurrentBlock();
908  }
909  }
910  }
911  }
912 
913  // shuffle output
914  $terms = $this->object->getTerms();
915  $definitions = $this->object->getDefinitions();
916  switch ($this->object->getShuffle())
917  {
918  case 1:
919  $terms = $this->object->pcArrayShuffle($terms);
920  if (count($solutions))
921  {
922  $definitions = $this->sortDefinitionsBySolution($solutions);
923  }
924  else
925  {
926  $definitions = $this->object->pcArrayShuffle($definitions);
927  }
928  break;
929  case 2:
930  $terms = $this->object->pcArrayShuffle($terms);
931  break;
932  case 3:
933  if (count($solutions))
934  {
935  $definitions = $this->sortDefinitionsBySolution($solutions);
936  }
937  else
938  {
939  $definitions = $this->object->pcArrayShuffle($definitions);
940  }
941  break;
942  }
943 
944  include_once "./Services/YUI/classes/class.ilYuiUtil.php";
946 
947  // create definitions
948  $counter = 0;
949  foreach ($definitions as $definition)
950  {
951  if (strlen($definition->picture))
952  {
953  $template->setCurrentBlock("definition_picture");
954  $template->setVariable("DEFINITION_ID", $definition->identifier);
955  $template->setVariable("IMAGE_HREF", $this->object->getImagePathWeb() . $definition->picture);
956  $thumbweb = $this->object->getImagePathWeb() . $this->object->getThumbPrefix() . $definition->picture;
957  $thumb = $this->object->getImagePath() . $this->object->getThumbPrefix() . $definition->picture;
958  if (!@file_exists($thumb)) $this->object->rebuildThumbnails();
959  $template->setVariable("THUMBNAIL_HREF", $thumbweb);
960  $template->setVariable("THUMB_ALT", $this->lng->txt("image"));
961  $template->setVariable("THUMB_TITLE", $this->lng->txt("image"));
962  $template->setVariable("TEXT_DEFINITION", (strlen($definition->text)) ? ilUtil::prepareFormOutput($definition->text) : '');
963  $template->setVariable("TEXT_PREVIEW", $this->lng->txt('preview'));
964  $template->setVariable("IMG_PREVIEW", ilUtil::getImagePath('enlarge.gif'));
965  $template->parseCurrentBlock();
966  }
967  else
968  {
969  $template->setCurrentBlock("definition_text");
970  $template->setVariable("DEFINITION", ilUtil::htmlentitiesOutsideHTMLTags($this->object->prepareTextareaOutput($definition->text, true)));
971  $template->parseCurrentBlock();
972  }
973 
974  $template->setCurrentBlock("droparea");
975  $template->setVariable("ID_DROPAREA", $definition->identifier);
976  $template->setVariable("QUESTION_ID", $this->object->getId());
977  if ($this->object->getEstimatedElementHeight() > 0)
978  {
979  $template->setVariable("ELEMENT_HEIGHT", " style=\"height: " . $this->object->getEstimatedElementHeight() . "px;\"");
980  }
981  $template->parseCurrentBlock();
982 
983  $template->setCurrentBlock("init_dropareas");
984  $template->setVariable("COUNTER", $counter++);
985  $template->setVariable("ID_DROPAREA", $definition->identifier);
986  $template->parseCurrentBlock();
987  }
988 
989 
990  // create terms
991  $counter = 0;
992  foreach ($terms as $term)
993  {
994  if (strlen($term->picture))
995  {
996  $template->setCurrentBlock("term_picture");
997  $template->setVariable("TERM_ID", $term->identifier);
998  $template->setVariable("IMAGE_HREF", $this->object->getImagePathWeb() . $term->picture);
999  $thumbweb = $this->object->getImagePathWeb() . $this->object->getThumbPrefix() . $term->picture;
1000  $thumb = $this->object->getImagePath() . $this->object->getThumbPrefix() . $term->picture;
1001  if (!@file_exists($thumb)) $this->object->rebuildThumbnails();
1002  $template->setVariable("THUMBNAIL_HREF", $thumbweb);
1003  $template->setVariable("THUMB_ALT", $this->lng->txt("image"));
1004  $template->setVariable("THUMB_TITLE", $this->lng->txt("image"));
1005  $template->setVariable("TEXT_PREVIEW", $this->lng->txt('preview'));
1006  $template->setVariable("TEXT_TERM", (strlen($term->text)) ? ilUtil::prepareFormOutput($term->text) : '');
1007  $template->setVariable("IMG_PREVIEW", ilUtil::getImagePath('enlarge.gif'));
1008  $template->parseCurrentBlock();
1009  }
1010  else
1011  {
1012  $template->setCurrentBlock("term_text");
1013  $template->setVariable("TERM_TEXT", ilUtil::htmlentitiesOutsideHTMLTags($this->object->prepareTextareaOutput($term->text, true)));
1014  $template->parseCurrentBlock();
1015  }
1016  $template->setCurrentBlock("draggable");
1017  $template->setVariable("ID_DRAGGABLE", $term->identifier);
1018  if ($this->object->getEstimatedElementHeight() > 0)
1019  {
1020  $template->setVariable("ELEMENT_HEIGHT", " style=\"height: " . $this->object->getEstimatedElementHeight() . "px;\"");
1021  }
1022  $template->parseCurrentBlock();
1023 
1024  $template->setCurrentBlock("init_draggables");
1025  $template->setVariable("COUNTER", $counter++);
1026  $template->setVariable("ID_DRAGGABLE", $term->identifier);
1027  $template->parseCurrentBlock();
1028  }
1029 
1030  $template->setVariable("RESET_BUTTON", $this->lng->txt("reset_terms"));
1031 
1032  $this->tpl->setVariable("LOCATION_ADDITIONAL_STYLESHEET", ilUtil::getStyleSheetLocation("output", "test_javascript.css", "Modules/TestQuestionPool"));
1033 
1034  $questiontext = $this->object->getQuestion();
1035  $template->setVariable("QUESTIONTEXT", $this->object->prepareTextareaOutput($questiontext, TRUE));
1036  $questionoutput = $template->get();
1037  $pageoutput = $this->outQuestionPage("", $is_postponed, $active_id, $questionoutput);
1038  return $pageoutput;
1039  }
1040 
1041  function getTestOutput($active_id, $pass = NULL, $is_postponed = FALSE, $user_post_solution = FALSE)
1042  {
1043  if ($this->object->getOutputType() == OUTPUT_JAVASCRIPT)
1044  {
1045  return $this->getTestOutputJS($active_id, $pass, $is_postponed, $user_post_solution);
1046  }
1047  // generate the question output
1048  include_once "./classes/class.ilTemplate.php";
1049  $template = new ilTemplate("tpl.il_as_qpl_matching_output.html", TRUE, TRUE, "Modules/TestQuestionPool");
1050 
1051  if ($active_id)
1052  {
1053  $solutions = NULL;
1054  include_once "./Modules/Test/classes/class.ilObjTest.php";
1055  if (!ilObjTest::_getUsePreviousAnswers($active_id, true))
1056  {
1057  if (is_null($pass)) $pass = ilObjTest::_getPass($active_id);
1058  }
1059  if (is_array($user_post_solution))
1060  {
1061  $solutions = array();
1062  foreach ($user_post_solution['matching'][$this->object->getId()] as $definition => $term)
1063  {
1064  array_push($solutions, array("value1" => $term, "value2" => $definition));
1065  }
1066  }
1067  else
1068  {
1069  $solutions =& $this->object->getSolutionValues($active_id, $pass);
1070  }
1071  }
1072 
1073 
1074  // shuffle output
1075  $terms = $this->object->getTerms();
1076  $definitions = $this->object->getDefinitions();
1077  switch ($this->object->getShuffle())
1078  {
1079  case 1:
1080  $terms = $this->object->pcArrayShuffle($terms);
1081  if (count($solutions))
1082  {
1083  $definitions = $this->sortDefinitionsBySolution($solutions);
1084  }
1085  else
1086  {
1087  $definitions = $this->object->pcArrayShuffle($definitions);
1088  }
1089  break;
1090  case 2:
1091  $terms = $this->object->pcArrayShuffle($terms);
1092  break;
1093  case 3:
1094  if (count($solutions))
1095  {
1096  $definitions = $this->sortDefinitionsBySolution($solutions);
1097  }
1098  else
1099  {
1100  $definitions = $this->object->pcArrayShuffle($definitions);
1101  }
1102  break;
1103  }
1104  $maxcount = max(count($terms), count($definitions));
1105  for ($i = 0; $i < count($definitions); $i++)
1106  {
1107  $definition = $definitions[$i];
1108  if (is_object($definition))
1109  {
1110  if (strlen($definition->picture))
1111  {
1112  $template->setCurrentBlock('definition_image');
1113  $template->setVariable('ANSWER_IMAGE_URL', $this->object->getImagePathWeb() . $this->object->getThumbPrefix() . $definition->picture);
1114  $template->setVariable('ANSWER_IMAGE_ALT', (strlen($definition->text)) ? ilUtil::prepareFormOutput($definition->text) : ilUtil::prepareFormOutput($definition->picture));
1115  $template->setVariable('ANSWER_IMAGE_TITLE', (strlen($definition->text)) ? ilUtil::prepareFormOutput($definition->text) : ilUtil::prepareFormOutput($definition->picture));
1116  $template->setVariable('URL_PREVIEW', $this->object->getImagePathWeb() . $definition->picture);
1117  $template->setVariable("TEXT_PREVIEW", $this->lng->txt('preview'));
1118  $template->setVariable("IMG_PREVIEW", ilUtil::getImagePath('enlarge.gif'));
1119  $template->setVariable("TEXT_DEFINITION", (strlen($definition->text)) ? $this->lng->txt('definition') . ' ' . ($i+1) . ': ' . ilUtil::prepareFormOutput($definition->text) : $this->lng->txt('definition') . ' ' . ($i+1));
1120  $template->parseCurrentBlock();
1121  }
1122  else
1123  {
1124  $template->setCurrentBlock('definition_text');
1125  $template->setVariable("DEFINITION", ilUtil::htmlentitiesOutsideHTMLTags($this->object->prepareTextareaOutput($definition->text, true)));
1126  $template->parseCurrentBlock();
1127  }
1128  }
1129 
1130  $template->setCurrentBlock('option');
1131  $template->setVariable("VALUE_OPTION", 0);
1132  $template->setVariable("TEXT_OPTION", ilUtil::prepareFormOutput($this->lng->txt('please_select')));
1133  $template->parseCurrentBlock();
1134  $j = 1;
1135  foreach ($terms as $term)
1136  {
1137  $template->setCurrentBlock('option');
1138  $template->setVariable("VALUE_OPTION", $term->identifier);
1139  $template->setVariable("TEXT_OPTION", (strlen($term->text)) ? $this->lng->txt('term') . ' ' . ($j) . ': ' . ilUtil::prepareFormOutput($term->text) : $this->lng->txt('term') . ' ' . ($j));
1140  foreach ($solutions as $solution)
1141  {
1142  if ($solution["value1"] == $term->identifier && $solution["value2"] == $definition->identifier)
1143  {
1144  $template->setVariable("SELECTED_OPTION", " selected=\"selected\"");
1145  }
1146  }
1147  $template->parseCurrentBlock();
1148  $j++;
1149  }
1150 
1151  $template->setCurrentBlock('row');
1152  $template->setVariable("TEXT_MATCHES", $this->lng->txt("matches"));
1153  if ($this->object->getEstimatedElementHeight() > 0)
1154  {
1155  $template->setVariable("ELEMENT_HEIGHT", " style=\"height: " . $this->object->getEstimatedElementHeight() . "px;\"");
1156  }
1157  $template->setVariable("QUESTION_ID", $this->object->getId());
1158  $template->setVariable("DEFINITION_ID", $definition->identifier);
1159  $template->parseCurrentBlock();
1160  }
1161 
1162  foreach ($terms as $term)
1163  {
1164  if (strlen($term->picture))
1165  {
1166  $template->setCurrentBlock('term_image');
1167  $template->setVariable('ANSWER_IMAGE_URL', $this->object->getImagePathWeb() . $this->object->getThumbPrefix() . $term->picture);
1168  $template->setVariable('ANSWER_IMAGE_ALT', (strlen($term->text)) ? ilUtil::prepareFormOutput($term->text) : ilUtil::prepareFormOutput($term->picture));
1169  $template->setVariable('ANSWER_IMAGE_TITLE', (strlen($term->text)) ? ilUtil::prepareFormOutput($term->text) : ilUtil::prepareFormOutput($term->picture));
1170  $template->setVariable('URL_PREVIEW', $this->object->getImagePathWeb() . $term->picture);
1171  $template->setVariable("TEXT_PREVIEW", $this->lng->txt('preview'));
1172  $template->setVariable("TEXT_TERM", (strlen($term->text)) ? $this->lng->txt('term') . ' ' . ($i+1) . ': ' . ilUtil::prepareFormOutput($term->text) : $this->lng->txt('term') . ' ' . ($i+1));
1173  $template->setVariable("IMG_PREVIEW", ilUtil::getImagePath('enlarge.gif'));
1174  $template->parseCurrentBlock();
1175  }
1176  else
1177  {
1178  $template->setCurrentBlock('term_text');
1179  $template->setVariable("TERM", ilUtil::htmlentitiesOutsideHTMLTags($this->object->prepareTextareaOutput($term->text, true)));
1180  $template->parseCurrentBlock();
1181  }
1182  $template->touchBlock('terms');
1183  }
1184 
1185  $questiontext = $this->object->getQuestion();
1186  $template->setVariable("QUESTIONTEXT", $this->object->prepareTextareaOutput($questiontext, TRUE));
1187  $template->setVariable("TEXT_TERMS", ilUtil::prepareFormOutput($this->lng->txt('available_terms')));
1188  $template->setVariable('TEXT_SELECTION', ilUtil::prepareFormOutput($this->lng->txt('selection')));
1189 
1190  $questiontext = $this->object->getQuestion();
1191  $template->setVariable("QUESTIONTEXT", $this->object->prepareTextareaOutput($questiontext, TRUE));
1192  $questionoutput = $template->get();
1193  $pageoutput = $this->outQuestionPage("", $is_postponed, $active_id, $questionoutput);
1194  return $pageoutput;
1195 
1196  }
1197 
1201  function checkInput()
1202  {
1203  if ((!$_POST["title"]) or (!$_POST["author"]) or (!$_POST["question"]))
1204  {
1205  return false;
1206  }
1207  return true;
1208  }
1209 
1210 
1214  function saveFeedback()
1215  {
1216  include_once "./Services/AdvancedEditing/classes/class.ilObjAdvancedEditing.php";
1217  $errors = $this->feedback(true);
1218  $this->object->saveFeedbackGeneric(0, $_POST["feedback_incomplete"]);
1219  $this->object->saveFeedbackGeneric(1, $_POST["feedback_complete"]);
1220  $this->object->cleanupMediaObjectUsage();
1222  }
1223 
1229  function setQuestionTabs()
1230  {
1231  global $rbacsystem, $ilTabs;
1232 
1233  $this->ctrl->setParameterByClass("ilpageobjectgui", "q_id", $_GET["q_id"]);
1234  include_once "./Modules/TestQuestionPool/classes/class.assQuestion.php";
1235  $q_type = $this->object->getQuestionType();
1236 
1237  if (strlen($q_type))
1238  {
1239  $classname = $q_type . "GUI";
1240  $this->ctrl->setParameterByClass(strtolower($classname), "sel_question_types", $q_type);
1241  $this->ctrl->setParameterByClass(strtolower($classname), "q_id", $_GET["q_id"]);
1242  }
1243 
1244  if ($_GET["q_id"])
1245  {
1246  if ($rbacsystem->checkAccess('write', $_GET["ref_id"]))
1247  {
1248  // edit page
1249  $ilTabs->addTarget("edit_content",
1250  $this->ctrl->getLinkTargetByClass("ilPageObjectGUI", "edit"),
1251  array("edit", "insert", "exec_pg"),
1252  "", "", $force_active);
1253  }
1254 
1255  // edit page
1256  $ilTabs->addTarget("preview",
1257  $this->ctrl->getLinkTargetByClass("ilPageObjectGUI", "preview"),
1258  array("preview"),
1259  "ilPageObjectGUI", "", $force_active);
1260  }
1261 
1262  $force_active = false;
1263  if ($rbacsystem->checkAccess('write', $_GET["ref_id"]))
1264  {
1265  $url = "";
1266  if ($classname) $url = $this->ctrl->getLinkTargetByClass($classname, "editQuestion");
1267  // edit question properties
1268  $ilTabs->addTarget("edit_properties",
1269  $url,
1270  array("editQuestion", "save", "saveEdit", "removeimageterms", "uploadterms", "removeimagedefinitions", "uploaddefinitions",
1271  "addpairs", "removepairs", "addterms", "removeterms", "adddefinitions", "removedefinitions", "originalSyncForm"),
1272  $classname, "", $force_active);
1273  }
1274 
1275  if ($_GET["q_id"])
1276  {
1277  $ilTabs->addTarget("feedback",
1278  $this->ctrl->getLinkTargetByClass($classname, "feedback"),
1279  array("feedback", "saveFeedback"),
1280  $classname, "");
1281  }
1282 
1283  if ($_GET["q_id"])
1284  {
1285  $ilTabs->addTarget("solution_hint",
1286  $this->ctrl->getLinkTargetByClass($classname, "suggestedsolution"),
1287  array("suggestedsolution", "saveSuggestedSolution", "outSolutionExplorer", "cancel",
1288  "addSuggestedSolution","cancelExplorer", "linkChilds", "removeSuggestedSolution"
1289  ),
1290  $classname,
1291  ""
1292  );
1293  }
1294 
1295  // Assessment of questions sub menu entry
1296  if ($_GET["q_id"])
1297  {
1298  $ilTabs->addTarget("statistics",
1299  $this->ctrl->getLinkTargetByClass($classname, "assessment"),
1300  array("assessment"),
1301  $classname, "");
1302  }
1303 
1304  if (($_GET["calling_test"] > 0) || ($_GET["test_ref_id"] > 0))
1305  {
1306  $ref_id = $_GET["calling_test"];
1307  if (strlen($ref_id) == 0) $ref_id = $_GET["test_ref_id"];
1308  $ilTabs->setBackTarget($this->lng->txt("backtocallingtest"), "ilias.php?baseClass=ilObjTestGUI&cmd=questions&ref_id=$ref_id");
1309  }
1310  else
1311  {
1312  $ilTabs->setBackTarget($this->lng->txt("qpl"), $this->ctrl->getLinkTargetByClass("ilobjquestionpoolgui", "questions"));
1313  }
1314  }
1315 }
1316 ?>