ILIAS  Release_3_10_x_branch Revision 61812
 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 
50  $id = -1
51  )
52  {
53  include_once "./Modules/TestQuestionPool/classes/class.assImagemapQuestion.php";
54  $this->assQuestionGUI();
55  $this->object = new assImagemapQuestion();
56  if ($id >= 0)
57  {
58  $this->object->loadFromDb($id);
59  }
60  $assessmentSetting = new ilSetting("assessment");
61  $this->linecolor = (strlen($assessmentSetting->get("imap_line_color"))) ? "#" . $assessmentSetting->get("imap_line_color") : "#FF0000";
62 
63  }
64 
65  function getCommand($cmd)
66  {
67  if (isset($_POST["imagemap"]) ||
68  isset($_POST["imagemap_x"]) ||
69  isset($_POST["imagemap_y"]))
70  {
71  $this->ctrl->setCmd("getCoords");
72  $cmd = "getCoords";
73  }
74 
75  return $cmd;
76  }
77 
78 
86  function editQuestion()
87  {
88  include_once "./Modules/TestQuestionPool/classes/class.ilImagemapPreview.php";
89  //$this->tpl->setVariable("HEADER", $this->object->getTitle());
90  $this->getQuestionTemplate();
91  $this->tpl->addBlockFile("QUESTION_DATA", "question_data", "tpl.il_as_qpl_imagemap_question.html", "Modules/TestQuestionPool");
92  if (($this->ctrl->getCmd() == "addArea" or $this->ctrl->getCmd() == "getCoords") and ($this->ctrl->getCmd() != "saveShape"))
93  {
94  foreach ($this->object->coords as $key => $value)
95  {
96  $this->tpl->setCurrentBlock("hidden");
97  $this->tpl->setVariable("HIDDEN_NAME", "coords_$key");
98  $this->tpl->setVariable("HIDDEN_VALUE", $value);
99  $this->tpl->parseCurrentBlock();
100  }
101  $this->tpl->setCurrentBlock("hidden");
102  $this->tpl->setVariable("HIDDEN_NAME", "newarea");
103  $this->tpl->setVariable("HIDDEN_VALUE", $_POST["newarea"]);
104  $this->tpl->parseCurrentBlock();
105 
106  $preview = new ilImagemapPreview($this->object->getImagePath().$this->object->get_image_filename());
107  foreach ($this->object->answers as $index => $answer)
108  {
109  $preview->addArea($index, $answer->getArea(), $answer->getCoords(), $answer->getAnswertext(), "", "", true, $this->linecolor);
110  }
111  $hidearea = false;
112  $disabled_save = " disabled=\"disabled\"";
113  $coords = "";
114  switch ($_POST["newarea"])
115  {
116  case "rect":
117  if (count($this->object->coords) == 0)
118  {
119  ilUtil::sendInfo($this->lng->txt("rectangle_click_tl_corner"));
120  }
121  else if (count($this->object->coords) == 1)
122  {
123  ilUtil::sendInfo($this->lng->txt("rectangle_click_br_corner"));
124  $preview->addPoint($preview->getAreaCount(), join($this->object->coords, ","), TRUE, "blue");
125  }
126  else if (count($this->object->coords) == 2)
127  {
128  $coords = join($this->object->coords, ",");
129  $hidearea = true;
130  $disabled_save = "";
131  }
132  break;
133  case "circle":
134  if (count($this->object->coords) == 0)
135  {
136  ilUtil::sendInfo($this->lng->txt("circle_click_center"));
137  }
138  else if (count($this->object->coords) == 1)
139  {
140  ilUtil::sendInfo($this->lng->txt("circle_click_circle"));
141  $preview->addPoint($preview->getAreaCount(), join($this->object->coords, ","), TRUE, "blue");
142  }
143  else if (count($this->object->coords) == 2)
144  {
145  if (preg_match("/(\d+)\s*,\s*(\d+)\s+(\d+)\s*,\s*(\d+)/", $this->object->coords[0] . " " . $this->object->coords[1], $matches))
146  {
147  $coords = "$matches[1],$matches[2]," . (int)sqrt((($matches[3]-$matches[1])*($matches[3]-$matches[1]))+(($matches[4]-$matches[2])*($matches[4]-$matches[2])));
148  }
149  $hidearea = true;
150  $disabled_save = "";
151  }
152  break;
153  case "poly":
154  if (count($this->object->coords) == 0)
155  {
156  ilUtil::sendInfo($this->lng->txt("polygon_click_starting_point"));
157  }
158  else if (count($this->object->coords) == 1)
159  {
160  ilUtil::sendInfo($this->lng->txt("polygon_click_next_point"));
161  $preview->addPoint($preview->getAreaCount(), join($this->object->coords, ","), TRUE, "blue");
162  }
163  else if (count($this->object->coords) > 1)
164  {
165  ilUtil::sendInfo($this->lng->txt("polygon_click_next_or_save"));
166  $disabled_save = "";
167  $coords = join($this->object->coords, ",");
168  }
169  break;
170  }
171  if ($coords)
172  {
173  $preview->addArea($preview->getAreaCount(), $_POST["newarea"], $coords, $_POST["shapetitle"], "", "", true, "blue");
174  }
175  $preview->createPreview();
176  $imagepath = $this->object->getImagePathWeb() . $preview->getPreviewFilename($this->object->getImagePath(), $this->object->get_image_filename()) . "?img=" . time();
177  if (!$hidearea)
178  {
179  $this->tpl->setCurrentBlock("maparea");
180  $this->tpl->setVariable("IMAGE_SOURCE", "$imagepath");
181  $this->tpl->parseCurrentBlock();
182  }
183  else
184  {
185  $this->tpl->setCurrentBlock("imagearea");
186  $this->tpl->setVariable("IMAGE_SOURCE", "$imagepath");
187  $this->tpl->setVariable("ALT_IMAGE", $this->lng->txt("imagemap"));
188  $this->tpl->parseCurrentBlock();
189  }
190  $this->tpl->setCurrentBlock("imagemapeditor");
191  $this->tpl->setVariable("TEXT_IMAGEMAP", $this->lng->txt("imagemap"));
192  $this->tpl->setVariable("VALUE_SHAPETITLE", $_POST["shapetitle"]);
193  $this->tpl->setVariable("TEXT_SHAPETITLE", $this->lng->txt("name"));
194  $this->tpl->setVariable("CANCEL", $this->lng->txt("cancel"));
195  $this->tpl->setVariable("SAVE", $this->lng->txt("save"));
196  $this->tpl->setVariable("DISABLED_SAVE", $disabled_save);
197  $this->tpl->parseCurrentBlock();
198  $this->tpl->setCurrentBlock("adm_content");
199  $this->tpl->setVariable("IMAGEMAP_ID", $this->object->getId());
200  $this->ctrl->setParameter($this, "sel_question_types", "assImagemapQuestion");
201  $this->ctrl->setParameter($this, "editmap", "1");
202  $this->tpl->setVariable("ACTION_IMAGEMAP_QUESTION", $this->ctrl->getFormaction($this));
203  $this->tpl->parseCurrentBlock();
204  }
205  else
206  {
207  $tblrow = array("tblrow1top", "tblrow2top");
208  for ($i = 0; $i < $this->object->getAnswerCount(); $i++)
209  {
210  $this->tpl->setCurrentBlock("answers");
211  $answer = $this->object->getAnswer($i);
212  $this->tpl->setVariable("ANSWER_ORDER", $answer->getOrder());
213  $this->tpl->setVariable("VALUE_ANSWER", ilUtil::prepareFormOutput($answer->getAnswertext()));
214  $this->tpl->setVariable("TEXT_POINTS", $this->lng->txt("points"));
215  if ((strcmp($_GET["markarea"], "") != 0) && ($_GET["markarea"] == $i))
216  {
217  $this->tpl->setVariable("CLASS_FULLWIDTH", "fullwidth_marked");
218  }
219  else
220  {
221  $this->tpl->setVariable("CLASS_FULLWIDTH", "fullwidth");
222  }
223  $this->tpl->setVariable("VALUE_IMAGEMAP_POINTS", $answer->getPoints());
224  $this->tpl->setVariable("COLOR_CLASS", $tblrow[$i % 2]);
225  $coords = "";
226  switch ($answer->getArea())
227  {
228  case "poly":
229  case "rect":
230  $coords = preg_replace("/(\d+,\d+,)/", "\$1 ", $answer->getCoords());
231  break;
232  case "circle":
233  $coords = preg_replace("/(\d+,\d+,)/", "\$1 ", $answer->getCoords());
234  break;
235  }
236  $this->tpl->setVariable("COORDINATES", $coords);
237  $this->tpl->setVariable("AREA", $answer->getArea());
238  $this->tpl->setVariable("TEXT_SHAPE", strtoupper($answer->getArea()));
239  $this->tpl->parseCurrentBlock();
240  }
241  if ($this->object->getAnswerCount())
242  {
243  $this->tpl->setCurrentBlock("selectall");
244  $this->tpl->setVariable("SELECT_ALL", $this->lng->txt("select_all"));
245  $i++;
246  $this->tpl->setVariable("COLOR_CLASS", $tblrow[$i % 2]);
247  $this->tpl->parseCurrentBlock();
248  $this->tpl->setCurrentBlock("QFooter");
249  $this->tpl->setVariable("DELETE_AREA", $this->lng->txt("delete_area"));
250  $this->tpl->setVariable("ARROW", "<img src=\"" . ilUtil::getImagePath("arrow_downright.gif") . "\" alt=\"".$this->lng->txt("arrow_downright")."\"/>");
251  $this->tpl->parseCurrentBlock();
252  $this->tpl->setCurrentBlock("answerheader");
253  $this->tpl->setVariable("TEXT_NAME", $this->lng->txt("name"));
254  $this->tpl->setVariable("TEXT_TRUE", $this->lng->txt("true"));
255  $this->tpl->setVariable("TEXT_POINTS", $this->lng->txt("points"));
256  $this->tpl->setVariable("TEXT_SHAPE", $this->lng->txt("shape"));
257  $this->tpl->setVariable("TEXT_COORDINATES", $this->lng->txt("coordinates"));
258  $this->tpl->parseCurrentBlock();
259  }
260  // call to other question data i.e. estimated working time block
261  $this->outOtherQuestionData();
262  // image block
263 
264  $internallinks = array(
265  "lm" => $this->lng->txt("obj_lm"),
266  "st" => $this->lng->txt("obj_st"),
267  "pg" => $this->lng->txt("obj_pg"),
268  "glo" => $this->lng->txt("glossary_term")
269  );
270  foreach ($internallinks as $key => $value)
271  {
272  $this->tpl->setCurrentBlock("internallink");
273  $this->tpl->setVariable("TYPE_INTERNAL_LINK", $key);
274  $this->tpl->setVariable("TEXT_INTERNAL_LINK", $value);
275  $this->tpl->parseCurrentBlock();
276  }
277 
278  if (strcmp($this->object->get_image_filename(), "") != 0)
279  {
280  $this->tpl->setCurrentBlock("addarea");
281  $this->tpl->setVariable("ADD_AREA", $this->lng->txt("add_area"));
282  $this->tpl->setVariable("TEXT_RECT", $this->lng->txt("rectangle"));
283  $this->tpl->setVariable("TEXT_CIRCLE", $this->lng->txt("circle"));
284  $this->tpl->setVariable("TEXT_POLY", $this->lng->txt("polygon"));
285  if (array_key_exists("newarea", $_POST))
286  {
287  switch ($_POST["newarea"])
288  {
289  case "circle":
290  $this->tpl->setVariable("SELECTED_CIRCLE", " selected=\"selected\"");
291  break;
292  case "poly":
293  $this->tpl->setVariable("SELECTED_POLY", " selected=\"selected\"");
294  break;
295  case "rect":
296  $this->tpl->setVariable("SELECTED_RECT", " selected=\"selected\"");
297  break;
298  }
299  }
300  $this->tpl->parseCurrentBlock();
301  }
302  $this->tpl->setCurrentBlock("HeadContent");
303  $this->tpl->addJavascript("./Services/JavaScript/js/Basic.js");
304  $javascript = "<script type=\"text/javascript\">ilAddOnLoad(initialSelect);\n".
305  "function initialSelect() {\n%s\n}</script>";
306  if (strcmp($_GET["markarea"], "") != 0)
307  {
308  $this->tpl->setVariable("CONTENT_BLOCK", sprintf($javascript, "document.frm_imagemap.answer_".$_GET["markarea"].".focus(); document.frm_imagemap.answer_".$_GET["markarea"].".scrollIntoView(\"true\");"));
309  }
310  else
311  {
312  switch ($this->ctrl->getCmd())
313  {
314  case "saveShape":
315  case "deletearea":
316  if ($this->object->getAnswerCount() > 0)
317  {
318  $this->tpl->setVariable("CONTENT_BLOCK", sprintf($javascript, "document.frm_imagemap.answer_".($this->object->getAnswerCount() - 1).".focus(); document.frm_imagemap.answer_".($this->object->getAnswerCount() - 1).".scrollIntoView(\"true\");"));
319  }
320  else
321  {
322  $this->tpl->setVariable("CONTENT_BLOCK", sprintf($javascript, "document.frm_imagemap.title.focus();"));
323  }
324  break;
325  default:
326  $this->tpl->setVariable("CONTENT_BLOCK", sprintf($javascript, "document.frm_imagemap.title.focus();"));
327  break;
328  }
329  }
330  $this->tpl->parseCurrentBlock();
331  $this->tpl->setCurrentBlock("question_data");
332  $img = $this->object->get_image_filename();
333  $this->tpl->setVariable("TEXT_IMAGE", $this->lng->txt("image"));
334  if (!empty($img))
335  {
336  $this->tpl->setVariable("IMAGE_FILENAME", $img);
337  $this->tpl->setVariable("VALUE_IMAGE_UPLOAD", $this->lng->txt("change"));
338  $this->tpl->setCurrentBlock("imageupload");
339  //$this->tpl->setVariable("UPLOADED_IMAGE", $img);
340  $this->tpl->parse("imageupload");
341  $map = "";
342  if (count($this->object->answers))
343  {
344  $preview = new ilImagemapPreview($this->object->getImagePath() . $this->object->get_image_filename());
345  foreach ($this->object->answers as $index => $answer)
346  {
347  $preview->addArea($index, $answer->getArea(), $answer->getCoords(), $answer->getAnswertext(), $this->ctrl->getLinkTarget($this, "editQuestion") . "&markarea=$index", "", true, $this->linecolor);
348  }
349  $preview->createPreview();
350  $imagepath = $this->object->getImagePathWeb() . $preview->getPreviewFilename($this->object->getImagePath(), $this->object->get_image_filename());
351  $map = $preview->getImagemap("imagemap_" . $this->object->getId());
352  }
353  else
354  {
355  $imagepath = $this->object->getImagePathWeb() . $img;
356  }
357  $size = GetImageSize ($this->object->getImagePath() . $this->object->get_image_filename());
358  if ($map)
359  {
360  $this->tpl->setVariable("UPLOADED_IMAGE", "<img src=\"$imagepath\" alt=\"$img\" border=\"0\" " . $size[3] . " usemap=\"" . "#imagemap_" . $this->object->getId(). "\" />\n$map\n");
361  }
362  else
363  {
364  $this->tpl->setVariable("UPLOADED_IMAGE", "<img src=\"$imagepath\" alt=\"$img\" border=\"0\" " . $size[3] . " />");
365  }
366  }
367  else
368  {
369  $this->tpl->setVariable("VALUE_IMAGE_UPLOAD", $this->lng->txt("upload"));
370  }
371 
372  // imagemap block
373  $imgmap = $this->object->get_imagemap_filename();
374  $this->tpl->setVariable("TEXT_IMAGEMAP", $this->lng->txt("imagemap_file"));
375  $this->tpl->setVariable("VALUE_IMAGEMAP_UPLOAD", $this->lng->txt("add_imagemap"));
376  $this->tpl->setCurrentBlock("questioneditor");
377  $this->tpl->setVariable("VALUE_IMAGEMAP_TITLE", ilUtil::prepareFormOutput($this->object->getTitle()));
378  $this->tpl->setVariable("VALUE_IMAGEMAP_COMMENT", ilUtil::prepareFormOutput($this->object->getComment()));
379  $this->tpl->setVariable("VALUE_IMAGEMAP_AUTHOR", ilUtil::prepareFormOutput($this->object->getAuthor()));
380  $questiontext = $this->object->getQuestion();
381  $this->tpl->setVariable("VALUE_QUESTION", ilUtil::prepareFormOutput($this->object->prepareTextareaOutput($questiontext)));
382  $this->tpl->setVariable("TEXT_TITLE", $this->lng->txt("title"));
383  $this->tpl->setVariable("TEXT_AUTHOR", $this->lng->txt("author"));
384  $this->tpl->setVariable("TEXT_COMMENT", $this->lng->txt("description"));
385  $this->tpl->setVariable("TEXT_QUESTION", $this->lng->txt("question"));
386  $this->tpl->setVariable("TXT_REQUIRED_FLD", $this->lng->txt("required_field"));
387 
388  $this->tpl->setVariable("TEXT_SOLUTION_HINT", $this->lng->txt("solution_hint"));
389  if (count($this->object->suggested_solutions))
390  {
391  $solution_array = $this->object->getSuggestedSolution(0);
392  include_once "./Modules/TestQuestionPool/classes/class.assQuestion.php";
393  $href = assQuestion::_getInternalLinkHref($solution_array["internal_link"]);
394  $this->tpl->setVariable("TEXT_VALUE_SOLUTION_HINT", " <a href=\"$href\" target=\"content\">" . $this->lng->txt("solution_hint"). "</a> ");
395  $this->tpl->setVariable("BUTTON_REMOVE_SOLUTION", $this->lng->txt("remove"));
396  $this->tpl->setVariable("BUTTON_ADD_SOLUTION", $this->lng->txt("change"));
397  $this->tpl->setVariable("VALUE_SOLUTION_HINT", $solution_array["internal_link"]);
398  }
399  else
400  {
401  $this->tpl->setVariable("BUTTON_ADD_SOLUTION", $this->lng->txt("add"));
402  }
403 
404  $this->tpl->setVariable("SAVE",$this->lng->txt("save"));
405  $this->tpl->setVariable("SAVE_EDIT", $this->lng->txt("save_edit"));
406  $this->tpl->setVariable("CANCEL",$this->lng->txt("cancel"));
407  $this->tpl->setVariable("TEXT_QUESTION_TYPE", $this->outQuestionType());
408  $this->tpl->parseCurrentBlock();
409  $this->tpl->setCurrentBlock("adm_content");
410  $this->ctrl->setParameter($this, "sel_question_types", "assImagemapQuestion");
411  $this->tpl->setVariable("ACTION_IMAGEMAP_QUESTION", $this->ctrl->getFormaction($this));
412  $this->tpl->setVariable("IMAGEMAP_ID", $this->object->getId());
413  $this->tpl->parseCurrentBlock();
414  include_once "./Services/RTE/classes/class.ilRTE.php";
415  $rtestring = ilRTE::_getRTEClassname();
416  include_once "./Services/RTE/classes/class.$rtestring.php";
417  $rte = new $rtestring();
418  $rte->addPlugin("latex");
419  $rte->addButton("latex"); $rte->addButton("pastelatex");
420  include_once "./classes/class.ilObject.php";
421  $obj_id = $_GET["q_id"];
422  $obj_type = ilObject::_lookupType($_GET["ref_id"], TRUE);
423  $rte->addRTESupport($obj_id, $obj_type, "assessment");
424  $this->tpl->setCurrentBlock("adm_content");
425  //$this->tpl->setVariable("BODY_ATTRIBUTES", " onload=\"initialSelect();\"");
426  $this->tpl->parseCurrentBlock();
427  }
428  }
429 
430  function getCoords()
431  {
432  $this->writePostData();
433  $this->editQuestion();
434  }
435 
436  function back()
437  {
438  $this->editQuestion();
439  }
440 
441  function saveShape()
442  {
443  $this->save();
444  }
445 
446  function addArea()
447  {
448  $_SESSION["last_area"] = $_POST["newarea"];
449  if ($this->writePostData())
450  {
452  $this->ctrl->setCmd("");
453  }
454  $this->editQuestion();
455  }
456 
457  function uploadingImage()
458  {
459  if ($_GET["q_id"] < 1)
460  {
461  $this->save();
462  }
463  else
464  {
465  $this->writePostData();
466  $this->editQuestion();
467  }
468  }
469 
470  function uploadingImagemap()
471  {
472  if ($_GET["q_id"] < 1)
473  {
474  $this->save();
475  }
476  else
477  {
478  $this->writePostData();
479  $this->editQuestion();
480  }
481  }
482 
483  function deleteArea()
484  {
485  $this->writePostData();
486  $checked_areas = array();
487  foreach ($_POST as $key => $value)
488  {
489  if (preg_match("/cb_(\d+)/", $key, $matches))
490  {
491  array_push($checked_areas, $matches[1]);
492  }
493  }
494  rsort($checked_areas, SORT_NUMERIC);
495  foreach ($checked_areas as $index)
496  {
497  $this->object->deleteArea($index);
498  }
499  $this->editQuestion();
500  }
501 
510  function writePostData()
511  {
512  $result = 0;
513  $saved = false;
514 
515  if ($_GET["editmap"])
516  {
517  $this->object->coords = array();
518  foreach ($_POST as $key => $value)
519  {
520  if (preg_match("/coords_(\d+)/", $key, $matches))
521  {
522  $this->object->coords[$matches[1]] = $value;
523  }
524  }
525  if (isset($_POST["imagemap_x"]))
526  {
527  array_push($this->object->coords, $_POST["imagemap_x"] . "," . $_POST["imagemap_y"]);
528  }
529  if ($this->ctrl->getCmd() == "saveShape")
530  {
531  $coords = "";
532  switch ($_POST["newarea"])
533  {
534  case "rect":
535  $coords = join($this->object->coords, ",");
536  break;
537  case "circle":
538  if (preg_match("/(\d+)\s*,\s*(\d+)\s+(\d+)\s*,\s*(\d+)/", $this->object->coords[0] . " " . $this->object->coords[1], $matches))
539  {
540  $coords = "$matches[1],$matches[2]," . (int)sqrt((($matches[3]-$matches[1])*($matches[3]-$matches[1]))+(($matches[4]-$matches[2])*($matches[4]-$matches[2])));
541  }
542  break;
543  case "poly":
544  $coords = join($this->object->coords, ",");
545  break;
546  }
547  $this->object->addAnswer($_POST["shapetitle"], 0, count($this->object->answers), $coords, $_POST["newarea"]);
548  }
549  }
550  else
551  {
552  if (!$this->checkInput())
553  {
554  $result = 1;
555  }
556  $this->object->setTitle(ilUtil::stripSlashes($_POST["title"]));
557  $this->object->setAuthor(ilUtil::stripSlashes($_POST["author"]));
558  $this->object->setComment(ilUtil::stripSlashes($_POST["comment"]));
559  include_once "./Services/AdvancedEditing/classes/class.ilObjAdvancedEditing.php";
560  $questiontext = ilUtil::stripSlashes($_POST["question"], false, ilObjAdvancedEditing::_getUsedHTMLTagsAsString("assessment"));
561  $this->object->setQuestion($questiontext);
562  $this->object->setSuggestedSolution($_POST["solution_hint"], 0);
563  $this->object->setShuffle($_POST["shuffle"]);
564 
565  // adding estimated working time
566  $saved = $this->writeOtherPostData($result);
567 
568  if (($_POST["id"] > 0) or ($result != 1))
569  {
570  // Question is already saved, so imagemaps and images can be uploaded
571  //setting image file
572 
573  if (strlen($_FILES['imageName']['tmp_name']) == 0)
574  {
575  $this->object->setImageFilename(ilUtil::stripSlashes($_POST["uploaded_image"]));
576  }
577  else
578  {
579  if ($this->object->getId() <= 0)
580  {
581  $this->object->saveToDb();
582  $this->ctrl->setParameter($this, "q_id", $this->object->getId());
583  $saved = true;
584  ilUtil::sendInfo($this->lng->txt("question_saved_for_upload"));
585  }
586  $this->object->setImageFilename($_FILES['imageName']['name'], $_FILES['imageName']['tmp_name']);
587  }
588 
589  //setting imagemap
590  if (empty($_FILES['imagemapName']['tmp_name']))
591  {
592  $this->object->setImagemapFilename(ilUtil::stripSlashes($_POST['uploaded_imagemap']));
593  // Add all answers from the form into the object
594  $this->object->flushAnswers();
595  foreach ($_POST as $key => $value)
596  {
597  if (preg_match("/answer_(\d+)/", $key, $matches))
598  {
599  $points = $_POST["points_$matches[1]"];
600 
601  $this->object->addAnswer(
602  ilUtil::stripSlashes($_POST["$key"]),
603  ilUtil::stripSlashes($points),
604  $matches[1],
605  ilUtil::stripSlashes($_POST["coords_$matches[1]"]),
606  ilUtil::stripSlashes($_POST["area_$matches[1]"])
607  );
608  }
609  }
610  }
611  else
612  {
613  if ($this->object->getId() <= 0)
614  {
615  $this->object->saveToDb();
616  $this->ctrl->setParameter($this, "q_id", $this->object->getId());
617  $saved = TRUE;
618  ilUtil::sendInfo($this->lng->txt("question_saved_for_upload"), TRUE);
619  }
620  $this->object->setImagemapFilename($_FILES['imagemapName']['name'], $_FILES['imagemapName']['tmp_name']);
621  }
622  }
623  else
624  {
625  if (($this->ctrl->getCmd() == "uploadingImage") and (!empty($_FILES['imageName']['tmp_name'])))
626  {
627  ilUtil::sendInfo($this->lng->txt("fill_out_all_required_fields_upload_image"));
628  }
629  else if (($_POST["cmd"]["uploadingImagemap"]) and (!empty($_FILES['imagemapName']['tmp_name'])))
630  {
631  ilUtil::sendInfo($this->lng->txt("fill_out_all_required_fields_upload_imagemap"));
632  }
633  }
634  }
635  if ($this->ctrl->getCmd() == "addArea")
636  {
637  $this->object->saveToDb();
638  $saved = true;
639  }
640  if ($saved)
641  {
642  $this->ctrl->setParameter($this, "q_id", $this->object->getId());
643  }
644  return $result;
645  }
646 
647  function outQuestionForTest($formaction, $active_id, $pass = NULL, $is_postponed = FALSE, $use_post_solutions = FALSE, $show_feedback = FALSE)
648  {
649  $test_output = $this->getTestOutput($active_id, $pass, $is_postponed, $use_post_solutions, $show_feedback);
650  $this->tpl->setVariable("QUESTION_OUTPUT", $test_output);
651 
652  $this->ctrl->setParameterByClass("ilTestOutputGUI", "formtimestamp", time());
653  $formaction = $this->ctrl->getLinkTargetByClass("ilTestOutputGUI", "selectImagemapRegion");
654  include_once "./Modules/Test/classes/class.ilObjTest.php";
655  if (!ilObjTest::_getUsePreviousAnswers($active_id, true))
656  {
657  $pass = ilObjTest::_getPass($active_id);
658  $info =& $this->object->getSolutionValues($active_id, $pass);
659  }
660  else
661  {
662  $info =& $this->object->getSolutionValues($active_id, NULL);
663  }
664  if (count($info))
665  {
666  if (strcmp($info[0]["value1"], "") != 0)
667  {
668  $formaction .= "&selImage=" . $info[0]["value1"];
669  }
670  }
671  $this->tpl->setVariable("FORMACTION", $formaction);
672  }
673 
674  function getSolutionOutput($active_id, $pass = NULL, $graphicalOutput = FALSE, $result_output = FALSE, $show_question_only = TRUE, $show_feedback = FALSE, $show_correct_solution = FALSE)
675  {
676  $imagepath = $this->object->getImagePathWeb() . $this->object->get_image_filename();
677  $solutions = array();
678  if (($active_id > 0) && (!$show_correct_solution))
679  {
680  include_once "./Modules/Test/classes/class.ilObjTest.php";
681  if ((!$showsolution) && !ilObjTest::_getUsePreviousAnswers($active_id, true))
682  {
683  if (is_null($pass)) $pass = ilObjTest::_getPass($active_id);
684  }
685  $solutions =& $this->object->getSolutionValues($active_id, $pass);
686  }
687  else
688  {
689  $found_index = -1;
690  $max_points = 0;
691  foreach ($this->object->answers as $index => $answer)
692  {
693  if ($answer->getPoints() > $max_points)
694  {
695  $max_points = $answer->getPoints();
696  $found_index = $index;
697  }
698  }
699  array_push($solutions, array("value1" => $found_index));
700  }
701  $solution_id = -1;
702  if (is_array($solutions))
703  {
704  include_once "./Modules/TestQuestionPool/classes/class.ilImagemapPreview.php";
705  $preview = new ilImagemapPreview($this->object->getImagePath().$this->object->get_image_filename());
706  foreach ($solutions as $idx => $solution_value)
707  {
708  if (strcmp($solution_value["value1"], "") != 0)
709  {
710  $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);
711  $solution_id = $solution_value["value1"];
712  }
713  }
714  $preview->createPreview();
715  $imagepath = $this->object->getImagePathWeb() . $preview->getPreviewFilename($this->object->getImagePath(), $this->object->get_image_filename());
716  }
717 
718  // generate the question output
719  include_once "./classes/class.ilTemplate.php";
720  $template = new ilTemplate("tpl.il_as_qpl_imagemap_question_output_solution.html", TRUE, TRUE, "Modules/TestQuestionPool");
721  $solutiontemplate = new ilTemplate("tpl.il_as_tst_solution_output.html",TRUE, TRUE, "Modules/TestQuestionPool");
722  $questiontext = $this->object->getQuestion();
723  $template->setVariable("QUESTIONTEXT", $this->object->prepareTextareaOutput($questiontext, TRUE));
724  $template->setVariable("IMG_SRC", "$imagepath");
725  $template->setVariable("IMG_ALT", $this->lng->txt("imagemap"));
726  $template->setVariable("IMG_TITLE", $this->lng->txt("imagemap"));
727  if (($active_id > 0) && (!$show_correct_solution))
728  {
729  if ($graphicalOutput)
730  {
731  // output of ok/not ok icons for user entered solutions
732  $reached_points = $this->object->getReachedPoints($active_id, $pass);
733  if ($reached_points == $this->object->getMaximumPoints())
734  {
735  $template->setCurrentBlock("icon_ok");
736  $template->setVariable("ICON_OK", ilUtil::getImagePath("icon_ok.gif"));
737  $template->setVariable("TEXT_OK", $this->lng->txt("answer_is_right"));
738  $template->parseCurrentBlock();
739  }
740  else
741  {
742  $template->setCurrentBlock("icon_ok");
743  if ($reached_points > 0)
744  {
745  $template->setVariable("ICON_NOT_OK", ilUtil::getImagePath("icon_mostly_ok.gif"));
746  $template->setVariable("TEXT_NOT_OK", $this->lng->txt("answer_is_not_correct_but_positive"));
747  }
748  else
749  {
750  $template->setVariable("ICON_NOT_OK", ilUtil::getImagePath("icon_not_ok.gif"));
751  $template->setVariable("TEXT_NOT_OK", $this->lng->txt("answer_is_wrong"));
752  }
753  $template->parseCurrentBlock();
754  }
755  }
756  }
757 
758  if ($show_feedback)
759  {
760  $fb = $this->object->getFeedbackSingleAnswer($solution_id);
761  if (strlen($fb))
762  {
763  $template->setCurrentBlock("feedback");
764  $template->setVariable("FEEDBACK", $fb);
765  $template->parseCurrentBlock();
766  }
767  }
768 
769  $questionoutput = $template->get();
770  $feedback = ($show_feedback) ? $this->getAnswerFeedbackOutput($active_id, $pass) : "";
771  if (strlen($feedback)) $solutiontemplate->setVariable("FEEDBACK", $feedback);
772  $solutiontemplate->setVariable("SOLUTION_OUTPUT", $questionoutput);
773 
774  $solutionoutput = $solutiontemplate->get();
775  if (!$show_question_only)
776  {
777  // get page object output
778  $solutionoutput = $this->getILIASPage($solutionoutput);
779  }
780  return $solutionoutput;
781  }
782 
783  function getPreview($show_question_only = FALSE)
784  {
785  $imagepath = $this->object->getImagePathWeb() . $this->object->get_image_filename();
786  // generate the question output
787  include_once "./classes/class.ilTemplate.php";
788  $template = new ilTemplate("tpl.il_as_qpl_imagemap_question_output.html", TRUE, TRUE, "Modules/TestQuestionPool");
789  $formaction = "#";
790  foreach ($this->object->answers as $answer_id => $answer)
791  {
792  $template->setCurrentBlock("imagemap_area");
793  $template->setVariable("HREF_AREA", $formaction);
794  $template->setVariable("SHAPE", $answer->getArea());
795  $template->setVariable("COORDS", $answer->getCoords());
796  $template->setVariable("ALT", ilUtil::prepareFormOutput($answer->getAnswertext()));
797  $template->setVariable("TITLE", ilUtil::prepareFormOutput($answer->getAnswertext()));
798  $template->parseCurrentBlock();
799  }
800  $questiontext = $this->object->getQuestion();
801  $template->setVariable("QUESTIONTEXT", $this->object->prepareTextareaOutput($questiontext, TRUE));
802  $template->setVariable("IMG_SRC", "$imagepath");
803  $template->setVariable("IMG_ALT", $this->lng->txt("imagemap"));
804  $template->setVariable("IMG_TITLE", $this->lng->txt("imagemap"));
805  $questionoutput = $template->get();
806  if (!$show_question_only)
807  {
808  // get page object output
809  $questionoutput = $this->getILIASPage($questionoutput);
810  }
811  return $questionoutput;
812  }
813 
814  function getTestOutput($active_id, $pass = NULL, $is_postponed = FALSE, $use_post_solutions = FALSE, $show_feedback = FALSE)
815  {
816  // get the solution of the user for the active pass or from the last pass if allowed
817  $user_solution = "";
818  if ($active_id)
819  {
820  $solutions = NULL;
821  include_once "./Modules/Test/classes/class.ilObjTest.php";
822  if (!ilObjTest::_getUsePreviousAnswers($active_id, true))
823  {
824  if (is_null($pass)) $pass = ilObjTest::_getPass($active_id);
825  }
826  $solutions =& $this->object->getSolutionValues($active_id, $pass);
827  foreach ($solutions as $idx => $solution_value)
828  {
829  $user_solution = $solution_value["value1"];
830  }
831  }
832 
833  $imagepath = $this->object->getImagePathWeb() . $this->object->get_image_filename();
834  if ($active_id)
835  {
836  $solutions = NULL;
837  include_once "./Modules/Test/classes/class.ilObjTest.php";
838  if ((!$showsolution) && !ilObjTest::_getUsePreviousAnswers($active_id, true))
839  {
840  if (is_null($pass)) $pass = ilObjTest::_getPass($active_id);
841  }
842  $solutions =& $this->object->getSolutionValues($active_id, $pass);
843  include_once "./Modules/TestQuestionPool/classes/class.ilImagemapPreview.php";
844  $preview = new ilImagemapPreview($this->object->getImagePath().$this->object->get_image_filename());
845  foreach ($solutions as $idx => $solution_value)
846  {
847  if (strcmp($solution_value["value1"], "") != 0)
848  {
849  $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);
850  }
851  }
852  $preview->createPreview();
853  $imagepath = $this->object->getImagePathWeb() . $preview->getPreviewFilename($this->object->getImagePath(), $this->object->get_image_filename());
854  }
855 
856  // generate the question output
857  include_once "./classes/class.ilTemplate.php";
858  $template = new ilTemplate("tpl.il_as_qpl_imagemap_question_output.html", TRUE, TRUE, "Modules/TestQuestionPool");
859  $this->ctrl->setParameterByClass("ilTestOutputGUI", "formtimestamp", time());
860  $formaction = $this->ctrl->getLinkTargetByClass("ilTestOutputGUI", "selectImagemapRegion");
861  foreach ($this->object->answers as $answer_id => $answer)
862  {
863  $template->setCurrentBlock("imagemap_area");
864  $template->setVariable("HREF_AREA", $formaction . "&amp;selImage=$answer_id");
865  $template->setVariable("SHAPE", $answer->getArea());
866  $template->setVariable("COORDS", $answer->getCoords());
867  $template->setVariable("ALT", ilUtil::prepareFormOutput($answer->getAnswertext()));
868  $template->setVariable("TITLE", ilUtil::prepareFormOutput($answer->getAnswertext()));
869  $template->parseCurrentBlock();
870  if ($show_feedback)
871  {
872  if (strlen($user_solution) && $user_solution == $answer_id)
873  {
874  $feedback = $this->object->getFeedbackSingleAnswer($user_solution);
875  if (strlen($feedback))
876  {
877  $template->setCurrentBlock("feedback");
878  $template->setVariable("FEEDBACK", $feedback);
879  $template->parseCurrentBlock();
880  }
881  }
882  }
883  }
884  $questiontext = $this->object->getQuestion();
885  $template->setVariable("QUESTIONTEXT", $this->object->prepareTextareaOutput($questiontext, TRUE));
886  $template->setVariable("IMG_SRC", "$imagepath");
887  $template->setVariable("IMG_ALT", $this->lng->txt("imagemap"));
888  $template->setVariable("IMG_TITLE", $this->lng->txt("imagemap"));
889  $questionoutput = $template->get();
890  $pageoutput = $this->outQuestionPage("", $is_postponed, $active_id, $questionoutput);
891  return $pageoutput;
892  }
893 
897  function checkInput()
898  {
899  if ((!$_POST["title"]) or (!$_POST["author"]) or (!$_POST["question"]))
900  {
901  return false;
902  }
903  return true;
904  }
905 
907  {
908  $_SESSION["subquestion_index"] = 0;
909  if ($_POST["cmd"]["addSuggestedSolution"])
910  {
911  if ($this->writePostData())
912  {
914  $this->editQuestion();
915  return;
916  }
917  if (!$this->checkInput())
918  {
919  ilUtil::sendInfo($this->lng->txt("fill_out_all_required_fields_add_answer"));
920  $this->editQuestion();
921  return;
922  }
923  }
924  $this->object->saveToDb();
925  $this->ctrl->setParameter($this, "q_id", $this->object->getId());
926  $this->tpl->setVariable("HEADER", $this->object->getTitle());
927  $this->getQuestionTemplate();
929  }
930 
938  function saveFeedback()
939  {
940  include_once "./Services/AdvancedEditing/classes/class.ilObjAdvancedEditing.php";
941  $this->object->saveFeedbackGeneric(0, ilUtil::stripSlashes($_POST["feedback_incomplete"], false, ilObjAdvancedEditing::_getUsedHTMLTagsAsString("assessment")));
942  $this->object->saveFeedbackGeneric(1, ilUtil::stripSlashes($_POST["feedback_complete"], false, ilObjAdvancedEditing::_getUsedHTMLTagsAsString("assessment")));
943  foreach ($this->object->answers as $index => $answer)
944  {
945  $this->object->saveFeedbackSingleAnswer($index, ilUtil::stripSlashes($_POST["feedback_answer_$index"], false, ilObjAdvancedEditing::_getUsedHTMLTagsAsString("assessment")));
946  }
947  $this->object->cleanupMediaObjectUsage();
949  }
950 
958  function feedback()
959  {
960  $this->tpl->addBlockFile("ADM_CONTENT", "feedback", "tpl.il_as_qpl_imagemap_feedback.html", "Modules/TestQuestionPool");
961  foreach ($this->object->answers as $index => $answer)
962  {
963  $this->tpl->setCurrentBlock("feedback_answer");
964  $this->tpl->setVariable("FEEDBACK_TEXT_ANSWER", $this->lng->txt("feedback"));
965  $text = strtoupper($answer->getArea() . " (" . $answer->getCoords() . ")");
966  if (strlen($answer->getAnswertext()))
967  {
968  $text = $answer->getAnswertext() . ": " . $text;
969  }
970  $this->tpl->setVariable("ANSWER_TEXT", $this->object->prepareTextareaOutput($text, TRUE));
971  $this->tpl->setVariable("ANSWER_ID", $index);
972  $this->tpl->setVariable("VALUE_FEEDBACK_ANSWER", ilUtil::prepareFormOutput($this->object->prepareTextareaOutput($this->object->getFeedbackSingleAnswer($index)), FALSE));
973  $this->tpl->parseCurrentBlock();
974  }
975  $this->tpl->setVariable("FEEDBACK_TEXT", $this->lng->txt("feedback"));
976  $this->tpl->setVariable("FEEDBACK_COMPLETE", $this->lng->txt("feedback_complete_solution"));
977  $this->tpl->setVariable("VALUE_FEEDBACK_COMPLETE", ilUtil::prepareFormOutput($this->object->prepareTextareaOutput($this->object->getFeedbackGeneric(1)), FALSE));
978  $this->tpl->setVariable("FEEDBACK_INCOMPLETE", $this->lng->txt("feedback_incomplete_solution"));
979  $this->tpl->setVariable("VALUE_FEEDBACK_INCOMPLETE", ilUtil::prepareFormOutput($this->object->prepareTextareaOutput($this->object->getFeedbackGeneric(0)), FALSE));
980  $this->tpl->setVariable("FEEDBACK_ANSWERS", $this->lng->txt("feedback_answers"));
981  global $rbacsystem;
982  if ($rbacsystem->checkAccess('write', $_GET["ref_id"]))
983  {
984  $this->tpl->setVariable("SAVE", $this->lng->txt("save"));
985  }
986  $this->tpl->setVariable("FORMACTION", $this->ctrl->getFormAction($this));
987 
988  include_once "./Services/RTE/classes/class.ilRTE.php";
989  $rtestring = ilRTE::_getRTEClassname();
990  include_once "./Services/RTE/classes/class.$rtestring.php";
991  $rte = new $rtestring();
992  $rte->addPlugin("latex");
993  $rte->addButton("latex"); $rte->addButton("pastelatex");
994  include_once "./classes/class.ilObject.php";
995  $obj_id = $_GET["q_id"];
996  $obj_type = ilObject::_lookupType($_GET["ref_id"], TRUE);
997  $rte->addRTESupport($obj_id, $obj_type, "assessment");
998  }
999 
1007  function setQuestionTabs()
1008  {
1009  global $rbacsystem, $ilTabs;
1010 
1011  $this->ctrl->setParameterByClass("ilpageobjectgui", "q_id", $_GET["q_id"]);
1012  include_once "./Modules/TestQuestionPool/classes/class.assQuestion.php";
1013  $q_type = $this->object->getQuestionType();
1014 
1015  if (strlen($q_type))
1016  {
1017  $classname = $q_type . "GUI";
1018  $this->ctrl->setParameterByClass(strtolower($classname), "sel_question_types", $q_type);
1019  $this->ctrl->setParameterByClass(strtolower($classname), "q_id", $_GET["q_id"]);
1020  }
1021 
1022  if ($_GET["q_id"])
1023  {
1024  if ($rbacsystem->checkAccess('write', $_GET["ref_id"]))
1025  {
1026  // edit page
1027  $ilTabs->addTarget("edit_content",
1028  $this->ctrl->getLinkTargetByClass("ilPageObjectGUI", "edit"),
1029  array("edit", "insert", "exec_pg"),
1030  "", "", $force_active);
1031  }
1032 
1033  // edit page
1034  $ilTabs->addTarget("preview",
1035  $this->ctrl->getLinkTargetByClass("ilPageObjectGUI", "preview"),
1036  array("preview"),
1037  "ilPageObjectGUI", "", $force_active);
1038  }
1039 
1040  $force_active = false;
1041  if ($rbacsystem->checkAccess('write', $_GET["ref_id"]))
1042  {
1043  $url = "";
1044  if ($classname) $url = $this->ctrl->getLinkTargetByClass($classname, "editQuestion");
1045  if (array_key_exists("imagemap_x", $_POST))
1046  {
1047  $force_active = true;
1048  }
1049  // edit question properties
1050  $ilTabs->addTarget("edit_properties",
1051  $url,
1052  array("editQuestion", "save", "cancel", "addSuggestedSolution",
1053  "cancelExplorer", "linkChilds", "removeSuggestedSolution",
1054  "uploadingImage", "uploadingImagemap", "addArea",
1055  "deletearea", "saveShape", "back", "saveEdit"),
1056  $classname, "", $force_active);
1057  }
1058 
1059  if ($_GET["q_id"])
1060  {
1061  $ilTabs->addTarget("feedback",
1062  $this->ctrl->getLinkTargetByClass($classname, "feedback"),
1063  array("feedback", "saveFeedback"),
1064  $classname, "");
1065  }
1066 
1067  // Assessment of questions sub menu entry
1068  if ($_GET["q_id"])
1069  {
1070  $ilTabs->addTarget("statistics",
1071  $this->ctrl->getLinkTargetByClass($classname, "assessment"),
1072  array("assessment"),
1073  $classname, "");
1074  }
1075 
1076  if (($_GET["calling_test"] > 0) || ($_GET["test_ref_id"] > 0))
1077  {
1078  $ref_id = $_GET["calling_test"];
1079  if (strlen($ref_id) == 0) $ref_id = $_GET["test_ref_id"];
1080  $ilTabs->setBackTarget($this->lng->txt("backtocallingtest"), "ilias.php?baseClass=ilObjTestGUI&cmd=questions&ref_id=$ref_id");
1081  }
1082  else
1083  {
1084  $ilTabs->setBackTarget($this->lng->txt("qpl"), $this->ctrl->getLinkTargetByClass("ilobjquestionpoolgui", "questions"));
1085  }
1086  }
1087 }
1088 ?>