ILIAS  eassessment Revision 61809
 All Data Structures Namespaces Files Functions Variables Groups Pages
class.assImagemapQuestionGUI.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  private $linecolor;
40 
49  function __construct($id = -1)
50  {
52  include_once "./Modules/TestQuestionPool/classes/class.assImagemapQuestion.php";
53  $this->object = new assImagemapQuestion();
54  if ($id >= 0)
55  {
56  $this->object->loadFromDb($id);
57  }
58  $assessmentSetting = new ilSetting("assessment");
59  $this->linecolor = (strlen($assessmentSetting->get("imap_line_color"))) ? "#" . $assessmentSetting->get("imap_line_color") : "#FF0000";
60 
61  }
62 
63  function getCommand($cmd)
64  {
65  if (isset($_POST["imagemap"]) ||
66  isset($_POST["imagemap_x"]) ||
67  isset($_POST["imagemap_y"]))
68  {
69  $this->ctrl->setCmd("getCoords");
70  $cmd = "getCoords";
71  }
72 
73  return $cmd;
74  }
75 
82  function writePostData($always = false)
83  {
84  $hasErrors = (!$always) ? $this->editQuestion(true) : false;
85  if (!$hasErrors)
86  {
87  $this->object->setTitle($_POST["title"]);
88  $this->object->setAuthor($_POST["author"]);
89  $this->object->setComment($_POST["comment"]);
90  include_once "./Services/AdvancedEditing/classes/class.ilObjAdvancedEditing.php";
91  $questiontext = $_POST["question"];
92  $this->object->setQuestion($questiontext);
93  if ($this->getSelfAssessmentEditingMode())
94  {
95  $this->object->setNrOfTries($_POST['nr_of_tries']);
96  }
97  $this->object->setEstimatedWorkingTime(
98  $_POST["Estimated"]["hh"],
99  $_POST["Estimated"]["mm"],
100  $_POST["Estimated"]["ss"]
101  );
102 
103  if ($_POST['image_delete'])
104  {
105  $this->object->deleteImage();
106  }
107  else
108  {
109  if (strlen($_FILES['image']['tmp_name']) == 0)
110  {
111  $this->object->setImageFilename($_POST["image_name"]);
112  }
113  }
114  if (strlen($_FILES['image']['tmp_name']))
115  {
116  if ($this->getSelfAssessmentEditingMode() && $this->object->getId() < 1) $this->object->createNewQuestion();
117  $this->object->setImageFilename($_FILES['image']['name'], $_FILES['image']['tmp_name']);
118  }
119 
120  if (!$_POST['image_delete'])
121  {
122  $this->object->flushAnswers();
123  if (is_array($_POST['image']['coords']['name']))
124  {
125  foreach ($_POST['image']['coords']['name'] as $idx => $name)
126  {
127  $this->object->addAnswer($name, $_POST['image']['coords']['points'][$idx], $idx, $_POST['image']['coords']['coords'][$idx], $_POST['image']['coords']['shape'][$idx]);
128  }
129  }
130  if (strlen($_FILES['imagemapfile']['tmp_name']))
131  {
132  if ($this->getSelfAssessmentEditingMode() && $this->object->getId() < 1) $this->object->createNewQuestion();
133  $this->object->uploadImagemap($_FILES['imagemapfile']['tmp_name']);
134  }
135  }
136  return 0;
137  }
138  else
139  {
140  return 1;
141  }
142  }
143 
149  public function editQuestion($checkonly = FALSE)
150  {
151  $save = ((strcmp($this->ctrl->getCmd(), "save") == 0) || (strcmp($this->ctrl->getCmd(), "saveEdit") == 0)) ? TRUE : FALSE;
152  $this->getQuestionTemplate();
153 
154  include_once("./Services/Form/classes/class.ilPropertyFormGUI.php");
155  $form = new ilPropertyFormGUI();
156  $form->setFormAction($this->ctrl->getFormAction($this));
157  $form->setTitle($this->outQuestionType());
158  $form->setMultipart(TRUE);
159  $form->setTableWidth("100%");
160  $form->setId("assimagemap");
161 
162  // title, author, description, question, working time (assessment mode)
163  $this->addBasicQuestionFormProperties($form);
164 
165  // image
166  include_once "./Modules/TestQuestionPool/classes/class.ilImagemapFileInputGUI.php";
167  $image = new ilImagemapFileInputGUI($this->lng->txt('image'), 'image');
168  $image->setRequired(true);
169 
170  if (strlen($this->object->getImageFilename()))
171  {
172  $image->setImage($this->object->getImagePathWeb() . $this->object->getImageFilename());
173  $image->setValue($this->object->getImageFilename());
174  $image->setAreas($this->object->getAnswers());
175  $assessmentSetting = new ilSetting("assessment");
176  $linecolor = (strlen($assessmentSetting->get("imap_line_color"))) ? "\"#" . $assessmentSetting->get("imap_line_color") . "\"" : "\"#FF0000\"";
177  $image->setLineColor($linecolor);
178  $image->setImagePath($this->object->getImagePath());
179  $image->setImagePathWeb($this->object->getImagePathWeb());
180  }
181  $form->addItem($image);
182 
183  // imagemapfile
184  $imagemapfile = new ilFileInputGUI($this->lng->txt('add_imagemap'), 'imagemapfile');
185  $imagemapfile->setRequired(false);
186  $form->addItem($imagemapfile);
187 
188  $this->addQuestionFormCommandButtons($form);
189 
190  $errors = false;
191 
192  if ($save)
193  {
194  $form->setValuesByPost();
195  $errors = !$form->checkInput();
196  $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
197  if ($errors) $checkonly = false;
198  }
199 
200  if (!$checkonly) $this->tpl->setVariable("QUESTION_DATA", $form->getHTML());
201  return $errors;
202  }
203 
204  function addRect()
205  {
206  $this->areaEditor('rect');
207  }
208 
209  function addCircle()
210  {
211  $this->areaEditor('circle');
212  }
213 
214  function addPoly()
215  {
216  $this->areaEditor('poly');
217  }
218 
222  public function saveShape()
223  {
224  $coords = "";
225  switch ($_POST["shape"])
226  {
227  case "rect":
228  $coords = join($_POST['image']['mapcoords'], ",");
229  ilUtil::sendSuccess($this->lng->txt('msg_rect_added'), true);
230  break;
231  case "circle":
232  if (preg_match("/(\d+)\s*,\s*(\d+)\s+(\d+)\s*,\s*(\d+)/", $_POST['image']['mapcoords'][0] . " " . $_POST['image']['mapcoords'][1], $matches))
233  {
234  $coords = "$matches[1],$matches[2]," . (int)sqrt((($matches[3]-$matches[1])*($matches[3]-$matches[1]))+(($matches[4]-$matches[2])*($matches[4]-$matches[2])));
235  }
236  ilUtil::sendSuccess($this->lng->txt('msg_circle_added'), true);
237  break;
238  case "poly":
239  $coords = join($_POST['image']['mapcoords'], ",");
240  ilUtil::sendSuccess($this->lng->txt('msg_poly_added'), true);
241  break;
242  }
243  $this->object->addAnswer($_POST["shapetitle"], 0, count($this->object->getAnswers()), $coords, $_POST["shape"]);
244  $this->object->saveToDb();
245  $this->ctrl->redirect($this, 'editQuestion');
246  }
247 
248  public function areaEditor($shape = '')
249  {
250  $shape = (strlen($shape)) ? $shape : $_POST['shape'];
251  include_once "./Modules/TestQuestionPool/classes/class.ilImagemapPreview.php";
252  $this->getQuestionTemplate();
253  $this->tpl->addBlockFile("QUESTION_DATA", "question_data", "tpl.il_as_qpl_imagemap_question.html", "Modules/TestQuestionPool");
254  $coords = array();
255  if (is_array($_POST['image']['mapcoords']))
256  {
257  foreach ($_POST['image']['mapcoords'] as $value)
258  {
259  array_push($coords, $value);
260  }
261  }
262  if (is_array($_POST['cmd']['areaEditor']['image']))
263  {
264  array_push($coords, $_POST['cmd']['areaEditor']['image'][0] . "," . $_POST['cmd']['areaEditor']['image'][1]);
265  }
266  foreach ($coords as $value)
267  {
268  $this->tpl->setCurrentBlock("hidden");
269  $this->tpl->setVariable("HIDDEN_NAME", 'image[mapcoords][]');
270  $this->tpl->setVariable("HIDDEN_VALUE", $value);
271  $this->tpl->parseCurrentBlock();
272  }
273 
274  $this->tpl->setCurrentBlock("hidden");
275  $this->tpl->setVariable("HIDDEN_NAME", 'shape');
276  $this->tpl->setVariable("HIDDEN_VALUE", $shape);
277  $this->tpl->parseCurrentBlock();
278 
279  $preview = new ilImagemapPreview($this->object->getImagePath().$this->object->getImageFilename());
280  foreach ($this->object->answers as $index => $answer)
281  {
282  $preview->addArea($index, $answer->getArea(), $answer->getCoords(), $answer->getAnswertext(), "", "", true, $this->linecolor);
283  }
284  $hidearea = false;
285  $disabled_save = " disabled=\"disabled\"";
286  $c = "";
287  switch ($shape)
288  {
289  case "rect":
290  if (count($coords) == 0)
291  {
292  ilUtil::sendInfo($this->lng->txt("rectangle_click_tl_corner"));
293  }
294  else if (count($coords) == 1)
295  {
296  ilUtil::sendInfo($this->lng->txt("rectangle_click_br_corner"));
297  $preview->addPoint($preview->getAreaCount(), join($coords, ","), TRUE, "blue");
298  }
299  else if (count($coords) == 2)
300  {
301  $c = join($coords, ",");
302  $hidearea = true;
303  $disabled_save = "";
304  }
305  break;
306  case "circle":
307  if (count($coords) == 0)
308  {
309  ilUtil::sendInfo($this->lng->txt("circle_click_center"));
310  }
311  else if (count($coords) == 1)
312  {
313  ilUtil::sendInfo($this->lng->txt("circle_click_circle"));
314  $preview->addPoint($preview->getAreaCount(), join($coords, ","), TRUE, "blue");
315  }
316  else if (count($coords) == 2)
317  {
318  if (preg_match("/(\d+)\s*,\s*(\d+)\s+(\d+)\s*,\s*(\d+)/", $coords[0] . " " . $coords[1], $matches))
319  {
320  $c = "$matches[1],$matches[2]," . (int)sqrt((($matches[3]-$matches[1])*($matches[3]-$matches[1]))+(($matches[4]-$matches[2])*($matches[4]-$matches[2])));
321  }
322  $hidearea = true;
323  $disabled_save = "";
324  }
325  break;
326  case "poly":
327  if (count($coords) == 0)
328  {
329  ilUtil::sendInfo($this->lng->txt("polygon_click_starting_point"));
330  }
331  else if (count($coords) == 1)
332  {
333  ilUtil::sendInfo($this->lng->txt("polygon_click_next_point"));
334  $preview->addPoint($preview->getAreaCount(), join($coords, ","), TRUE, "blue");
335  }
336  else if (count($coords) > 1)
337  {
338  ilUtil::sendInfo($this->lng->txt("polygon_click_next_or_save"));
339  $disabled_save = "";
340  $c = join($coords, ",");
341  }
342  break;
343  }
344  if (strlen($c))
345  {
346  $preview->addArea($preview->getAreaCount(), $shape, $c, $_POST["shapetitle"], "", "", true, "blue");
347  }
348  $preview->createPreview();
349  $imagepath = $this->object->getImagePathWeb() . $preview->getPreviewFilename($this->object->getImagePath(), $this->object->getImageFilename()) . "?img=" . time();
350  if (!$hidearea)
351  {
352  $this->tpl->setCurrentBlock("maparea");
353  $this->tpl->setVariable("IMAGE_SOURCE", "$imagepath");
354  $this->tpl->setVariable("IMAGEMAP_NAME", "image");
355  $this->tpl->parseCurrentBlock();
356  }
357  else
358  {
359  $this->tpl->setCurrentBlock("imagearea");
360  $this->tpl->setVariable("IMAGE_SOURCE", "$imagepath");
361  $this->tpl->setVariable("ALT_IMAGE", $this->lng->txt("imagemap"));
362  $this->tpl->parseCurrentBlock();
363  }
364 
365  if (strlen($_POST['shapetitle']))
366  {
367  $this->tpl->setCurrentBlock("shapetitle");
368  $this->tpl->setVariable("VALUE_SHAPETITLE", $_POST["shapetitle"]);
369  $this->tpl->parseCurrentBlock();
370  }
371 
372  $this->tpl->setVariable("TEXT_IMAGEMAP", $this->lng->txt("imagemap"));
373  $this->tpl->setVariable("TEXT_SHAPETITLE", $this->lng->txt("name"));
374  $this->tpl->setVariable("CANCEL", $this->lng->txt("cancel"));
375  $this->tpl->setVariable("SAVE", $this->lng->txt("save"));
376  $this->tpl->setVariable("DISABLED_SAVE", $disabled_save);
377  switch ($shape)
378  {
379  case "rect":
380  $this->tpl->setVariable("FORMACTION", $this->ctrl->getFormaction($this, 'addRect'));
381  break;
382  case 'circle':
383  $this->tpl->setVariable("FORMACTION", $this->ctrl->getFormaction($this, 'addCircle'));
384  break;
385  case 'poly':
386  $this->tpl->setVariable("FORMACTION", $this->ctrl->getFormaction($this, 'addPoly'));
387  break;
388  }
389  }
390 
391  function removeArea()
392  {
393  $this->writePostData(true);
394  $position = key($_POST['cmd']['removeArea']['image']);
395  $this->object->deleteArea($position);
396  $this->editQuestion();
397  }
398 
399  function back()
400  {
401  ilUtil::sendInfo($this->lng->txt('msg_cancel'), true);
402  $this->ctrl->redirect($this, 'editQuestion');
403  }
404 
405  function outQuestionForTest($formaction, $active_id, $pass = NULL, $is_postponed = FALSE, $use_post_solutions = FALSE, $show_feedback = FALSE)
406  {
407  $test_output = $this->getTestOutput($active_id, $pass, $is_postponed, $use_post_solutions, $show_feedback);
408  $this->tpl->setVariable("QUESTION_OUTPUT", $test_output);
409 
410  $this->ctrl->setParameterByClass("ilTestOutputGUI", "formtimestamp", time());
411  $formaction = $this->ctrl->getLinkTargetByClass("ilTestOutputGUI", "selectImagemapRegion");
412  include_once "./Modules/Test/classes/class.ilObjTest.php";
413  if (!ilObjTest::_getUsePreviousAnswers($active_id, true))
414  {
415  $pass = ilObjTest::_getPass($active_id);
416  $info =& $this->object->getSolutionValues($active_id, $pass);
417  }
418  else
419  {
420  $info =& $this->object->getSolutionValues($active_id, NULL);
421  }
422  if (count($info))
423  {
424  if (strcmp($info[0]["value1"], "") != 0)
425  {
426  $formaction .= "&selImage=" . $info[0]["value1"];
427  }
428  }
429  $this->tpl->setVariable("FORMACTION", $formaction);
430  }
431 
446  $active_id,
447  $pass = NULL,
448  $graphicalOutput = FALSE,
449  $result_output = FALSE,
450  $show_question_only = TRUE,
451  $show_feedback = FALSE,
452  $show_correct_solution = FALSE,
453  $show_manual_scoring = FALSE
454  )
455  {
456  $imagepath = $this->object->getImagePathWeb() . $this->object->getImageFilename();
457  $solutions = array();
458  if (($active_id > 0) && (!$show_correct_solution))
459  {
460  include_once "./Modules/Test/classes/class.ilObjTest.php";
461  if ((!$showsolution) && !ilObjTest::_getUsePreviousAnswers($active_id, true))
462  {
463  if (is_null($pass)) $pass = ilObjTest::_getPass($active_id);
464  }
465  $solutions =& $this->object->getSolutionValues($active_id, $pass);
466  }
467  else
468  {
469  $found_index = -1;
470  $max_points = 0;
471  foreach ($this->object->answers as $index => $answer)
472  {
473  if ($answer->getPoints() > $max_points)
474  {
475  $max_points = $answer->getPoints();
476  $found_index = $index;
477  }
478  }
479  array_push($solutions, array("value1" => $found_index));
480  }
481  $solution_id = -1;
482  if (is_array($solutions))
483  {
484  include_once "./Modules/TestQuestionPool/classes/class.ilImagemapPreview.php";
485  $preview = new ilImagemapPreview($this->object->getImagePath().$this->object->getImageFilename());
486  foreach ($solutions as $idx => $solution_value)
487  {
488  if (strcmp($solution_value["value1"], "") != 0)
489  {
490  if (array_key_exists($solution_value["value1"], $this->object->answers))
491  {
492  $preview->addArea($solution_value["value1"], $this->object->answers[$solution_value["value1"]]->getArea(), $this->object->answers[$solution_value["value1"]]->getCoords(), $this->object->answers[$solution_value["value1"]]->getAnswertext(), "", "", true, $this->linecolor);
493  $solution_id = $solution_value["value1"];
494  }
495  }
496  }
497  $preview->createPreview();
498  $imagepath = $this->object->getImagePathWeb() . $preview->getPreviewFilename($this->object->getImagePath(), $this->object->getImageFilename());
499  }
500 
501  // generate the question output
502  include_once "./classes/class.ilTemplate.php";
503  $template = new ilTemplate("tpl.il_as_qpl_imagemap_question_output_solution.html", TRUE, TRUE, "Modules/TestQuestionPool");
504  $solutiontemplate = new ilTemplate("tpl.il_as_tst_solution_output.html",TRUE, TRUE, "Modules/TestQuestionPool");
505  $questiontext = $this->object->getQuestion();
506  $template->setVariable("QUESTIONTEXT", $this->object->prepareTextareaOutput($questiontext, TRUE));
507  $template->setVariable("IMG_SRC", "$imagepath");
508  $template->setVariable("IMG_ALT", $this->lng->txt("imagemap"));
509  $template->setVariable("IMG_TITLE", $this->lng->txt("imagemap"));
510  if (($active_id > 0) && (!$show_correct_solution))
511  {
512  if ($graphicalOutput)
513  {
514  // output of ok/not ok icons for user entered solutions
515  $reached_points = $this->object->getReachedPoints($active_id, $pass);
516  if ($reached_points == $this->object->getMaximumPoints())
517  {
518  $template->setCurrentBlock("icon_ok");
519  $template->setVariable("ICON_OK", ilUtil::getImagePath("icon_ok.gif"));
520  $template->setVariable("TEXT_OK", $this->lng->txt("answer_is_right"));
521  $template->parseCurrentBlock();
522  }
523  else
524  {
525  $template->setCurrentBlock("icon_ok");
526  if ($reached_points > 0)
527  {
528  $template->setVariable("ICON_NOT_OK", ilUtil::getImagePath("icon_mostly_ok.gif"));
529  $template->setVariable("TEXT_NOT_OK", $this->lng->txt("answer_is_not_correct_but_positive"));
530  }
531  else
532  {
533  $template->setVariable("ICON_NOT_OK", ilUtil::getImagePath("icon_not_ok.gif"));
534  $template->setVariable("TEXT_NOT_OK", $this->lng->txt("answer_is_wrong"));
535  }
536  $template->parseCurrentBlock();
537  }
538  }
539  }
540 
541  if ($show_feedback)
542  {
543  $fb = $this->object->getFeedbackSingleAnswer($solution_id);
544  if (strlen($fb))
545  {
546  $template->setCurrentBlock("feedback");
547  $template->setVariable("FEEDBACK", $fb);
548  $template->parseCurrentBlock();
549  }
550  }
551 
552  $questionoutput = $template->get();
553  $feedback = ($show_feedback) ? $this->getAnswerFeedbackOutput($active_id, $pass) : "";
554  if (strlen($feedback)) $solutiontemplate->setVariable("FEEDBACK", $feedback);
555  $solutiontemplate->setVariable("SOLUTION_OUTPUT", $questionoutput);
556 
557  $solutionoutput = $solutiontemplate->get();
558  if (!$show_question_only)
559  {
560  // get page object output
561  $solutionoutput = $this->getILIASPage($solutionoutput);
562  }
563  return $solutionoutput;
564  }
565 
566  function getPreview($show_question_only = FALSE)
567  {
568  $imagepath = $this->object->getImagePathWeb() . $this->object->getImageFilename();
569  // generate the question output
570  include_once "./classes/class.ilTemplate.php";
571  $template = new ilTemplate("tpl.il_as_qpl_imagemap_question_output.html", TRUE, TRUE, "Modules/TestQuestionPool");
572  $formaction = "#";
573  foreach ($this->object->answers as $answer_id => $answer)
574  {
575  $template->setCurrentBlock("imagemap_area");
576  $template->setVariable("HREF_AREA", $formaction);
577  $template->setVariable("SHAPE", $answer->getArea());
578  $template->setVariable("COORDS", $answer->getCoords());
579  $template->setVariable("ALT", ilUtil::prepareFormOutput($answer->getAnswertext()));
580  $template->setVariable("TITLE", ilUtil::prepareFormOutput($answer->getAnswertext()));
581  $template->parseCurrentBlock();
582  }
583  $questiontext = $this->object->getQuestion();
584  $template->setVariable("QUESTIONTEXT", $this->object->prepareTextareaOutput($questiontext, TRUE));
585  $template->setVariable("IMG_SRC", "$imagepath");
586  $template->setVariable("IMG_ALT", $this->lng->txt("imagemap"));
587  $template->setVariable("IMG_TITLE", $this->lng->txt("imagemap"));
588  $questionoutput = $template->get();
589  if (!$show_question_only)
590  {
591  // get page object output
592  $questionoutput = $this->getILIASPage($questionoutput);
593  }
594  return $questionoutput;
595  }
596 
597  function getTestOutput($active_id, $pass = NULL, $is_postponed = FALSE, $use_post_solutions = FALSE, $show_feedback = FALSE)
598  {
599  // get the solution of the user for the active pass or from the last pass if allowed
600  $user_solution = "";
601  if ($active_id)
602  {
603  $solutions = NULL;
604  include_once "./Modules/Test/classes/class.ilObjTest.php";
605  if (!ilObjTest::_getUsePreviousAnswers($active_id, true))
606  {
607  if (is_null($pass)) $pass = ilObjTest::_getPass($active_id);
608  }
609  $solutions =& $this->object->getSolutionValues($active_id, $pass);
610  foreach ($solutions as $idx => $solution_value)
611  {
612  $user_solution = $solution_value["value1"];
613  }
614  }
615 
616  $imagepath = $this->object->getImagePathWeb() . $this->object->getImageFilename();
617  if ($active_id)
618  {
619  $solutions = NULL;
620  include_once "./Modules/Test/classes/class.ilObjTest.php";
621  if ((!$showsolution) && !ilObjTest::_getUsePreviousAnswers($active_id, true))
622  {
623  if (is_null($pass)) $pass = ilObjTest::_getPass($active_id);
624  }
625  $solutions =& $this->object->getSolutionValues($active_id, $pass);
626  include_once "./Modules/TestQuestionPool/classes/class.ilImagemapPreview.php";
627  $preview = new ilImagemapPreview($this->object->getImagePath().$this->object->getImageFilename());
628  foreach ($solutions as $idx => $solution_value)
629  {
630  if (strcmp($solution_value["value1"], "") != 0)
631  {
632  $preview->addArea($solution_value["value1"], $this->object->answers[$solution_value["value1"]]->getArea(), $this->object->answers[$solution_value["value1"]]->getCoords(), $this->object->answers[$solution_value["value1"]]->getAnswertext(), "", "", true, $this->linecolor);
633  }
634  }
635  $preview->createPreview();
636  $imagepath = $this->object->getImagePathWeb() . $preview->getPreviewFilename($this->object->getImagePath(), $this->object->getImageFilename());
637  }
638 
639  // generate the question output
640  include_once "./classes/class.ilTemplate.php";
641  $template = new ilTemplate("tpl.il_as_qpl_imagemap_question_output.html", TRUE, TRUE, "Modules/TestQuestionPool");
642  $this->ctrl->setParameterByClass("ilTestOutputGUI", "formtimestamp", time());
643  $formaction = $this->ctrl->getLinkTargetByClass("ilTestOutputGUI", "selectImagemapRegion");
644  foreach ($this->object->answers as $answer_id => $answer)
645  {
646  $template->setCurrentBlock("imagemap_area");
647  $template->setVariable("HREF_AREA", $formaction . "&amp;selImage=$answer_id");
648  $template->setVariable("SHAPE", $answer->getArea());
649  $template->setVariable("COORDS", $answer->getCoords());
650  $template->setVariable("ALT", ilUtil::prepareFormOutput($answer->getAnswertext()));
651  $template->setVariable("TITLE", ilUtil::prepareFormOutput($answer->getAnswertext()));
652  $template->parseCurrentBlock();
653  if ($show_feedback)
654  {
655  if (strlen($user_solution) && $user_solution == $answer_id)
656  {
657  $feedback = $this->object->getFeedbackSingleAnswer($user_solution);
658  if (strlen($feedback))
659  {
660  $template->setCurrentBlock("feedback");
661  $template->setVariable("FEEDBACK", $feedback);
662  $template->parseCurrentBlock();
663  }
664  }
665  }
666  }
667  $questiontext = $this->object->getQuestion();
668  $template->setVariable("QUESTIONTEXT", $this->object->prepareTextareaOutput($questiontext, TRUE));
669  $template->setVariable("IMG_SRC", "$imagepath");
670  $template->setVariable("IMG_ALT", $this->lng->txt("imagemap"));
671  $template->setVariable("IMG_TITLE", $this->lng->txt("imagemap"));
672  $questionoutput = $template->get();
673  $pageoutput = $this->outQuestionPage("", $is_postponed, $active_id, $questionoutput);
674  return $pageoutput;
675  }
676 
680  function saveFeedback()
681  {
682  include_once "./Services/AdvancedEditing/classes/class.ilObjAdvancedEditing.php";
683  $errors = $this->feedback(true);
684  $this->object->saveFeedbackGeneric(0, $_POST["feedback_incomplete"]);
685  $this->object->saveFeedbackGeneric(1, $_POST["feedback_complete"]);
686  foreach ($this->object->answers as $index => $answer)
687  {
688  $this->object->saveFeedbackSingleAnswer($index, $_POST["feedback_answer_$index"]);
689  }
690  $this->object->cleanupMediaObjectUsage();
692  }
693 
699  function feedback($checkonly = false)
700  {
701  $save = (strcmp($this->ctrl->getCmd(), "saveFeedback") == 0) ? TRUE : FALSE;
702  include_once("./Services/Form/classes/class.ilPropertyFormGUI.php");
703  $form = new ilPropertyFormGUI();
704  $form->setFormAction($this->ctrl->getFormAction($this));
705  $form->setTitle($this->lng->txt('feedback_answers'));
706  $form->setTableWidth("100%");
707  $form->setId("feedback");
708 
709  $complete = new ilTextAreaInputGUI($this->lng->txt("feedback_complete_solution"), "feedback_complete");
710  $complete->setValue($this->object->prepareTextareaOutput($this->object->getFeedbackGeneric(1)));
711  $complete->setRequired(false);
712  $complete->setRows(10);
713  $complete->setCols(80);
714  if (!$this->getPreventRteUsage())
715  {
716  $complete->setUseRte(true);
717  }
718  include_once "./Services/AdvancedEditing/classes/class.ilObjAdvancedEditing.php";
719  $complete->setRteTags(ilObjAdvancedEditing::_getUsedHTMLTags("assessment"));
720  $complete->addPlugin("latex");
721  $complete->addButton("latex");
722  $complete->addButton("pastelatex");
723  $complete->setRTESupport($this->object->getId(), "qpl", "assessment");
724  $form->addItem($complete);
725 
726  $incomplete = new ilTextAreaInputGUI($this->lng->txt("feedback_incomplete_solution"), "feedback_incomplete");
727  $incomplete->setValue($this->object->prepareTextareaOutput($this->object->getFeedbackGeneric(0)));
728  $incomplete->setRequired(false);
729  $incomplete->setRows(10);
730  $incomplete->setCols(80);
731  if (!$this->getPreventRteUsage())
732  {
733  $incomplete->setUseRte(true);
734  }
735  include_once "./Services/AdvancedEditing/classes/class.ilObjAdvancedEditing.php";
736  $incomplete->setRteTags(ilObjAdvancedEditing::_getUsedHTMLTags("assessment"));
737  $incomplete->addPlugin("latex");
738  $incomplete->addButton("latex");
739  $incomplete->addButton("pastelatex");
740  $incomplete->setRTESupport($this->object->getId(), "qpl", "assessment");
741  $form->addItem($incomplete);
742 
743  if (!$this->getSelfAssessmentEditingMode())
744  {
745  foreach ($this->object->answers as $index => $answer)
746  {
747  $text = $this->lng->txt('region') . " " . ($index+1);
748  if (strlen($answer->getAnswertext()))
749  {
750  $text = $answer->getAnswertext() . ": " . $text;
751  }
752  $answerobj = new ilTextAreaInputGUI($this->object->prepareTextareaOutput($text), "feedback_answer_$index");
753  $answerobj->setValue($this->object->prepareTextareaOutput($this->object->getFeedbackSingleAnswer($index)));
754  $answerobj->setRequired(false);
755  $answerobj->setRows(10);
756  $answerobj->setCols(80);
757  $answerobj->setUseRte(true);
758  include_once "./Services/AdvancedEditing/classes/class.ilObjAdvancedEditing.php";
759  $answerobj->setRteTags(ilObjAdvancedEditing::_getUsedHTMLTags("assessment"));
760  $answerobj->addPlugin("latex");
761  $answerobj->addButton("latex");
762  $answerobj->addButton("pastelatex");
763  $answerobj->setRTESupport($this->object->getId(), "qpl", "assessment");
764  $form->addItem($answerobj);
765  }
766  }
767 
768  global $ilAccess;
769  if ($ilAccess->checkAccess("write", "", $_GET['ref_id']) || $this->getSelfAssessmentEditingMode())
770  {
771  $form->addCommandButton("saveFeedback", $this->lng->txt("save"));
772  }
773 
774  if ($save)
775  {
776  $form->setValuesByPost();
777  $errors = !$form->checkInput();
778  $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
779  }
780  if (!$checkonly) $this->tpl->setVariable("ADM_CONTENT", $form->getHTML());
781  return $errors;
782  }
783 
787  public function setQuestionTabs()
788  {
789  global $rbacsystem, $ilTabs;
790 
791  $this->ctrl->setParameterByClass("ilpageobjectgui", "q_id", $_GET["q_id"]);
792  include_once "./Modules/TestQuestionPool/classes/class.assQuestion.php";
793  $q_type = $this->object->getQuestionType();
794 
795  if (strlen($q_type))
796  {
797  $classname = $q_type . "GUI";
798  $this->ctrl->setParameterByClass(strtolower($classname), "sel_question_types", $q_type);
799  $this->ctrl->setParameterByClass(strtolower($classname), "q_id", $_GET["q_id"]);
800  }
801 
802  if ($_GET["q_id"])
803  {
804  if ($rbacsystem->checkAccess('write', $_GET["ref_id"]))
805  {
806  // edit page
807  $ilTabs->addTarget("edit_content",
808  $this->ctrl->getLinkTargetByClass("ilPageObjectGUI", "edit"),
809  array("edit", "insert", "exec_pg"),
810  "", "", $force_active);
811  }
812 
813  // edit page
814  $ilTabs->addTarget("preview",
815  $this->ctrl->getLinkTargetByClass("ilPageObjectGUI", "preview"),
816  array("preview"),
817  "ilPageObjectGUI", "", $force_active);
818  }
819 
820  $force_active = false;
821  if ($rbacsystem->checkAccess('write', $_GET["ref_id"]))
822  {
823  $url = "";
824  if ($classname) $url = $this->ctrl->getLinkTargetByClass($classname, "editQuestion");
825  if (array_key_exists("imagemap_x", $_POST))
826  {
827  $force_active = true;
828  }
829  // edit question properties
830  $ilTabs->addTarget("edit_properties",
831  $url,
832  array("editQuestion", "save", "addArea", "addRect", "addCircle", "addPoly",
833  "uploadingImage", "uploadingImagemap", "areaEditor",
834  "removeArea", "saveShape", "saveEdit", "originalSyncForm"),
835  $classname, "", $force_active);
836  }
837 
838  if ($_GET["q_id"])
839  {
840  $ilTabs->addTarget("feedback",
841  $this->ctrl->getLinkTargetByClass($classname, "feedback"),
842  array("feedback", "saveFeedback"),
843  $classname, "");
844  }
845 
846  if ($_GET["q_id"])
847  {
848  $ilTabs->addTarget("solution_hint",
849  $this->ctrl->getLinkTargetByClass($classname, "suggestedsolution"),
850  array("suggestedsolution", "saveSuggestedSolution", "outSolutionExplorer", "cancel",
851  "addSuggestedSolution","cancelExplorer", "linkChilds", "removeSuggestedSolution"
852  ),
853  $classname,
854  ""
855  );
856  }
857 
858  // Assessment of questions sub menu entry
859  if ($_GET["q_id"])
860  {
861  $ilTabs->addTarget("statistics",
862  $this->ctrl->getLinkTargetByClass($classname, "assessment"),
863  array("assessment"),
864  $classname, "");
865  }
866 
867  if (($_GET["calling_test"] > 0) || ($_GET["test_ref_id"] > 0))
868  {
869  $ref_id = $_GET["calling_test"];
870  if (strlen($ref_id) == 0) $ref_id = $_GET["test_ref_id"];
871  $ilTabs->setBackTarget($this->lng->txt("backtocallingtest"), "ilias.php?baseClass=ilObjTestGUI&cmd=questions&ref_id=$ref_id");
872  }
873  else
874  {
875  $ilTabs->setBackTarget($this->lng->txt("qpl"), $this->ctrl->getLinkTargetByClass("ilobjquestionpoolgui", "questions"));
876  }
877  }
878 }
879 ?>