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