ILIAS  Release_4_1_x_branch Revision 61804
 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  $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);
491  $solution_id = $solution_value["value1"];
492  }
493  }
494  $preview->createPreview();
495  $imagepath = $this->object->getImagePathWeb() . $preview->getPreviewFilename($this->object->getImagePath(), $this->object->getImageFilename());
496  }
497 
498  // generate the question output
499  include_once "./classes/class.ilTemplate.php";
500  $template = new ilTemplate("tpl.il_as_qpl_imagemap_question_output_solution.html", TRUE, TRUE, "Modules/TestQuestionPool");
501  $solutiontemplate = new ilTemplate("tpl.il_as_tst_solution_output.html",TRUE, TRUE, "Modules/TestQuestionPool");
502  $questiontext = $this->object->getQuestion();
503  $template->setVariable("QUESTIONTEXT", $this->object->prepareTextareaOutput($questiontext, TRUE));
504  $template->setVariable("IMG_SRC", "$imagepath");
505  $template->setVariable("IMG_ALT", $this->lng->txt("imagemap"));
506  $template->setVariable("IMG_TITLE", $this->lng->txt("imagemap"));
507  if (($active_id > 0) && (!$show_correct_solution))
508  {
509  if ($graphicalOutput)
510  {
511  // output of ok/not ok icons for user entered solutions
512  $reached_points = $this->object->getReachedPoints($active_id, $pass);
513  if ($reached_points == $this->object->getMaximumPoints())
514  {
515  $template->setCurrentBlock("icon_ok");
516  $template->setVariable("ICON_OK", ilUtil::getImagePath("icon_ok.gif"));
517  $template->setVariable("TEXT_OK", $this->lng->txt("answer_is_right"));
518  $template->parseCurrentBlock();
519  }
520  else
521  {
522  $template->setCurrentBlock("icon_ok");
523  if ($reached_points > 0)
524  {
525  $template->setVariable("ICON_NOT_OK", ilUtil::getImagePath("icon_mostly_ok.gif"));
526  $template->setVariable("TEXT_NOT_OK", $this->lng->txt("answer_is_not_correct_but_positive"));
527  }
528  else
529  {
530  $template->setVariable("ICON_NOT_OK", ilUtil::getImagePath("icon_not_ok.gif"));
531  $template->setVariable("TEXT_NOT_OK", $this->lng->txt("answer_is_wrong"));
532  }
533  $template->parseCurrentBlock();
534  }
535  }
536  }
537 
538  if ($show_feedback)
539  {
540  $fb = $this->object->getFeedbackSingleAnswer($solution_id);
541  if (strlen($fb))
542  {
543  $template->setCurrentBlock("feedback");
544  $template->setVariable("FEEDBACK", $fb);
545  $template->parseCurrentBlock();
546  }
547  }
548 
549  $questionoutput = $template->get();
550  $feedback = ($show_feedback) ? $this->getAnswerFeedbackOutput($active_id, $pass) : "";
551  if (strlen($feedback)) $solutiontemplate->setVariable("FEEDBACK", $feedback);
552  $solutiontemplate->setVariable("SOLUTION_OUTPUT", $questionoutput);
553 
554  $solutionoutput = $solutiontemplate->get();
555  if (!$show_question_only)
556  {
557  // get page object output
558  $solutionoutput = $this->getILIASPage($solutionoutput);
559  }
560  return $solutionoutput;
561  }
562 
563  function getPreview($show_question_only = FALSE)
564  {
565  $imagepath = $this->object->getImagePathWeb() . $this->object->getImageFilename();
566  // generate the question output
567  include_once "./classes/class.ilTemplate.php";
568  $template = new ilTemplate("tpl.il_as_qpl_imagemap_question_output.html", TRUE, TRUE, "Modules/TestQuestionPool");
569  $formaction = "#";
570  foreach ($this->object->answers as $answer_id => $answer)
571  {
572  $template->setCurrentBlock("imagemap_area");
573  $template->setVariable("HREF_AREA", $formaction);
574  $template->setVariable("SHAPE", $answer->getArea());
575  $template->setVariable("COORDS", $answer->getCoords());
576  $template->setVariable("ALT", ilUtil::prepareFormOutput($answer->getAnswertext()));
577  $template->setVariable("TITLE", ilUtil::prepareFormOutput($answer->getAnswertext()));
578  $template->parseCurrentBlock();
579  }
580  $questiontext = $this->object->getQuestion();
581  $template->setVariable("QUESTIONTEXT", $this->object->prepareTextareaOutput($questiontext, TRUE));
582  $template->setVariable("IMG_SRC", "$imagepath");
583  $template->setVariable("IMG_ALT", $this->lng->txt("imagemap"));
584  $template->setVariable("IMG_TITLE", $this->lng->txt("imagemap"));
585  $questionoutput = $template->get();
586  if (!$show_question_only)
587  {
588  // get page object output
589  $questionoutput = $this->getILIASPage($questionoutput);
590  }
591  return $questionoutput;
592  }
593 
594  function getTestOutput($active_id, $pass = NULL, $is_postponed = FALSE, $use_post_solutions = FALSE, $show_feedback = FALSE)
595  {
596  // get the solution of the user for the active pass or from the last pass if allowed
597  $user_solution = "";
598  if ($active_id)
599  {
600  $solutions = NULL;
601  include_once "./Modules/Test/classes/class.ilObjTest.php";
602  if (!ilObjTest::_getUsePreviousAnswers($active_id, true))
603  {
604  if (is_null($pass)) $pass = ilObjTest::_getPass($active_id);
605  }
606  $solutions =& $this->object->getSolutionValues($active_id, $pass);
607  foreach ($solutions as $idx => $solution_value)
608  {
609  $user_solution = $solution_value["value1"];
610  }
611  }
612 
613  $imagepath = $this->object->getImagePathWeb() . $this->object->getImageFilename();
614  if ($active_id)
615  {
616  $solutions = NULL;
617  include_once "./Modules/Test/classes/class.ilObjTest.php";
618  if ((!$showsolution) && !ilObjTest::_getUsePreviousAnswers($active_id, true))
619  {
620  if (is_null($pass)) $pass = ilObjTest::_getPass($active_id);
621  }
622  $solutions =& $this->object->getSolutionValues($active_id, $pass);
623  include_once "./Modules/TestQuestionPool/classes/class.ilImagemapPreview.php";
624  $preview = new ilImagemapPreview($this->object->getImagePath().$this->object->getImageFilename());
625  foreach ($solutions as $idx => $solution_value)
626  {
627  if (strcmp($solution_value["value1"], "") != 0)
628  {
629  $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);
630  }
631  }
632  $preview->createPreview();
633  $imagepath = $this->object->getImagePathWeb() . $preview->getPreviewFilename($this->object->getImagePath(), $this->object->getImageFilename());
634  }
635 
636  // generate the question output
637  include_once "./classes/class.ilTemplate.php";
638  $template = new ilTemplate("tpl.il_as_qpl_imagemap_question_output.html", TRUE, TRUE, "Modules/TestQuestionPool");
639  $this->ctrl->setParameterByClass("ilTestOutputGUI", "formtimestamp", time());
640  $formaction = $this->ctrl->getLinkTargetByClass("ilTestOutputGUI", "selectImagemapRegion");
641  foreach ($this->object->answers as $answer_id => $answer)
642  {
643  $template->setCurrentBlock("imagemap_area");
644  $template->setVariable("HREF_AREA", $formaction . "&amp;selImage=$answer_id");
645  $template->setVariable("SHAPE", $answer->getArea());
646  $template->setVariable("COORDS", $answer->getCoords());
647  $template->setVariable("ALT", ilUtil::prepareFormOutput($answer->getAnswertext()));
648  $template->setVariable("TITLE", ilUtil::prepareFormOutput($answer->getAnswertext()));
649  $template->parseCurrentBlock();
650  if ($show_feedback)
651  {
652  if (strlen($user_solution) && $user_solution == $answer_id)
653  {
654  $feedback = $this->object->getFeedbackSingleAnswer($user_solution);
655  if (strlen($feedback))
656  {
657  $template->setCurrentBlock("feedback");
658  $template->setVariable("FEEDBACK", $feedback);
659  $template->parseCurrentBlock();
660  }
661  }
662  }
663  }
664  $questiontext = $this->object->getQuestion();
665  $template->setVariable("QUESTIONTEXT", $this->object->prepareTextareaOutput($questiontext, TRUE));
666  $template->setVariable("IMG_SRC", "$imagepath");
667  $template->setVariable("IMG_ALT", $this->lng->txt("imagemap"));
668  $template->setVariable("IMG_TITLE", $this->lng->txt("imagemap"));
669  $questionoutput = $template->get();
670  $pageoutput = $this->outQuestionPage("", $is_postponed, $active_id, $questionoutput);
671  return $pageoutput;
672  }
673 
677  function saveFeedback()
678  {
679  include_once "./Services/AdvancedEditing/classes/class.ilObjAdvancedEditing.php";
680  $errors = $this->feedback(true);
681  $this->object->saveFeedbackGeneric(0, $_POST["feedback_incomplete"]);
682  $this->object->saveFeedbackGeneric(1, $_POST["feedback_complete"]);
683  foreach ($this->object->answers as $index => $answer)
684  {
685  $this->object->saveFeedbackSingleAnswer($index, $_POST["feedback_answer_$index"]);
686  }
687  $this->object->cleanupMediaObjectUsage();
689  }
690 
696  function feedback($checkonly = false)
697  {
698  $save = (strcmp($this->ctrl->getCmd(), "saveFeedback") == 0) ? TRUE : FALSE;
699  include_once("./Services/Form/classes/class.ilPropertyFormGUI.php");
700  $form = new ilPropertyFormGUI();
701  $form->setFormAction($this->ctrl->getFormAction($this));
702  $form->setTitle($this->lng->txt('feedback_answers'));
703  $form->setTableWidth("100%");
704  $form->setId("feedback");
705 
706  $complete = new ilTextAreaInputGUI($this->lng->txt("feedback_complete_solution"), "feedback_complete");
707  $complete->setValue($this->object->prepareTextareaOutput($this->object->getFeedbackGeneric(1)));
708  $complete->setRequired(false);
709  $complete->setRows(10);
710  $complete->setCols(80);
711  if (!$this->getPreventRteUsage())
712  {
713  $complete->setUseRte(true);
714  }
715  include_once "./Services/AdvancedEditing/classes/class.ilObjAdvancedEditing.php";
716  $complete->setRteTags(ilObjAdvancedEditing::_getUsedHTMLTags("assessment"));
717  $complete->addPlugin("latex");
718  $complete->addButton("latex");
719  $complete->addButton("pastelatex");
720  $complete->setRTESupport($this->object->getId(), "qpl", "assessment");
721  $form->addItem($complete);
722 
723  $incomplete = new ilTextAreaInputGUI($this->lng->txt("feedback_incomplete_solution"), "feedback_incomplete");
724  $incomplete->setValue($this->object->prepareTextareaOutput($this->object->getFeedbackGeneric(0)));
725  $incomplete->setRequired(false);
726  $incomplete->setRows(10);
727  $incomplete->setCols(80);
728  if (!$this->getPreventRteUsage())
729  {
730  $incomplete->setUseRte(true);
731  }
732  include_once "./Services/AdvancedEditing/classes/class.ilObjAdvancedEditing.php";
733  $incomplete->setRteTags(ilObjAdvancedEditing::_getUsedHTMLTags("assessment"));
734  $incomplete->addPlugin("latex");
735  $incomplete->addButton("latex");
736  $incomplete->addButton("pastelatex");
737  $incomplete->setRTESupport($this->object->getId(), "qpl", "assessment");
738  $form->addItem($incomplete);
739 
740  if (!$this->getSelfAssessmentEditingMode())
741  {
742  foreach ($this->object->answers as $index => $answer)
743  {
744  $text = $this->lng->txt('region') . " " . ($index+1);
745  if (strlen($answer->getAnswertext()))
746  {
747  $text = $answer->getAnswertext() . ": " . $text;
748  }
749  $answerobj = new ilTextAreaInputGUI($this->object->prepareTextareaOutput($text), "feedback_answer_$index");
750  $answerobj->setValue($this->object->prepareTextareaOutput($this->object->getFeedbackSingleAnswer($index)));
751  $answerobj->setRequired(false);
752  $answerobj->setRows(10);
753  $answerobj->setCols(80);
754  $answerobj->setUseRte(true);
755  include_once "./Services/AdvancedEditing/classes/class.ilObjAdvancedEditing.php";
756  $answerobj->setRteTags(ilObjAdvancedEditing::_getUsedHTMLTags("assessment"));
757  $answerobj->addPlugin("latex");
758  $answerobj->addButton("latex");
759  $answerobj->addButton("pastelatex");
760  $answerobj->setRTESupport($this->object->getId(), "qpl", "assessment");
761  $form->addItem($answerobj);
762  }
763  }
764 
765  global $ilAccess;
766  if ($ilAccess->checkAccess("write", "", $_GET['ref_id']) || $this->getSelfAssessmentEditingMode())
767  {
768  $form->addCommandButton("saveFeedback", $this->lng->txt("save"));
769  }
770 
771  if ($save)
772  {
773  $form->setValuesByPost();
774  $errors = !$form->checkInput();
775  $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
776  }
777  if (!$checkonly) $this->tpl->setVariable("ADM_CONTENT", $form->getHTML());
778  return $errors;
779  }
780 
784  public function setQuestionTabs()
785  {
786  global $rbacsystem, $ilTabs;
787 
788  $this->ctrl->setParameterByClass("ilpageobjectgui", "q_id", $_GET["q_id"]);
789  include_once "./Modules/TestQuestionPool/classes/class.assQuestion.php";
790  $q_type = $this->object->getQuestionType();
791 
792  if (strlen($q_type))
793  {
794  $classname = $q_type . "GUI";
795  $this->ctrl->setParameterByClass(strtolower($classname), "sel_question_types", $q_type);
796  $this->ctrl->setParameterByClass(strtolower($classname), "q_id", $_GET["q_id"]);
797  }
798 
799  if ($_GET["q_id"])
800  {
801  if ($rbacsystem->checkAccess('write', $_GET["ref_id"]))
802  {
803  // edit page
804  $ilTabs->addTarget("edit_content",
805  $this->ctrl->getLinkTargetByClass("ilPageObjectGUI", "edit"),
806  array("edit", "insert", "exec_pg"),
807  "", "", $force_active);
808  }
809 
810  // edit page
811  $ilTabs->addTarget("preview",
812  $this->ctrl->getLinkTargetByClass("ilPageObjectGUI", "preview"),
813  array("preview"),
814  "ilPageObjectGUI", "", $force_active);
815  }
816 
817  $force_active = false;
818  if ($rbacsystem->checkAccess('write', $_GET["ref_id"]))
819  {
820  $url = "";
821  if ($classname) $url = $this->ctrl->getLinkTargetByClass($classname, "editQuestion");
822  if (array_key_exists("imagemap_x", $_POST))
823  {
824  $force_active = true;
825  }
826  // edit question properties
827  $ilTabs->addTarget("edit_properties",
828  $url,
829  array("editQuestion", "save", "addArea", "addRect", "addCircle", "addPoly",
830  "uploadingImage", "uploadingImagemap", "areaEditor",
831  "removeArea", "saveShape", "saveEdit", "originalSyncForm"),
832  $classname, "", $force_active);
833  }
834 
835  if ($_GET["q_id"])
836  {
837  $ilTabs->addTarget("feedback",
838  $this->ctrl->getLinkTargetByClass($classname, "feedback"),
839  array("feedback", "saveFeedback"),
840  $classname, "");
841  }
842 
843  if ($_GET["q_id"])
844  {
845  $ilTabs->addTarget("solution_hint",
846  $this->ctrl->getLinkTargetByClass($classname, "suggestedsolution"),
847  array("suggestedsolution", "saveSuggestedSolution", "outSolutionExplorer", "cancel",
848  "addSuggestedSolution","cancelExplorer", "linkChilds", "removeSuggestedSolution"
849  ),
850  $classname,
851  ""
852  );
853  }
854 
855  // Assessment of questions sub menu entry
856  if ($_GET["q_id"])
857  {
858  $ilTabs->addTarget("statistics",
859  $this->ctrl->getLinkTargetByClass($classname, "assessment"),
860  array("assessment"),
861  $classname, "");
862  }
863 
864  if (($_GET["calling_test"] > 0) || ($_GET["test_ref_id"] > 0))
865  {
866  $ref_id = $_GET["calling_test"];
867  if (strlen($ref_id) == 0) $ref_id = $_GET["test_ref_id"];
868  $ilTabs->setBackTarget($this->lng->txt("backtocallingtest"), "ilias.php?baseClass=ilObjTestGUI&cmd=questions&ref_id=$ref_id");
869  }
870  else
871  {
872  $ilTabs->setBackTarget($this->lng->txt("qpl"), $this->ctrl->getLinkTargetByClass("ilobjquestionpoolgui", "questions"));
873  }
874  }
875 }
876 ?>