• Main Page
  • Related Pages
  • Namespaces
  • Data Structures
  • Files
  • File List
  • Globals

assessment/classes/class.assImagemapQuestionGUI.php

Go to the documentation of this file.
00001 <?php
00002  /*
00003    +----------------------------------------------------------------------------+
00004    | ILIAS open source                                                          |
00005    +----------------------------------------------------------------------------+
00006    | Copyright (c) 1998-2001 ILIAS open source, University of Cologne           |
00007    |                                                                            |
00008    | This program is free software; you can redistribute it and/or              |
00009    | modify it under the terms of the GNU General Public License                |
00010    | as published by the Free Software Foundation; either version 2             |
00011    | of the License, or (at your option) any later version.                     |
00012    |                                                                            |
00013    | This program is distributed in the hope that it will be useful,            |
00014    | but WITHOUT ANY WARRANTY; without even the implied warranty of             |
00015    | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the              |
00016    | GNU General Public License for more details.                               |
00017    |                                                                            |
00018    | You should have received a copy of the GNU General Public License          |
00019    | along with this program; if not, write to the Free Software                |
00020    | Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. |
00021    +----------------------------------------------------------------------------+
00022 */
00023 
00024 require_once "./assessment/classes/class.assQuestionGUI.php";
00025 require_once "./assessment/classes/class.assImagemapQuestion.php";
00026 require_once "./assessment/classes/class.ilImagemapPreview.php";
00027 
00039 class ASS_ImagemapQuestionGUI extends ASS_QuestionGUI
00040 {
00049         function ASS_ImagemapQuestionGUI(
00050                         $id = -1
00051         )
00052         {
00053                 $this->ASS_QuestionGUI();
00054                 $this->object = new ASS_ImagemapQuestion();
00055                 if ($id >= 0)
00056                 {
00057                         $this->object->loadFromDb($id);
00058                 }
00059         }
00060 
00069         function getQuestionType()
00070         {
00071                 return "qt_imagemap";
00072         }
00073 
00074         function getCommand($cmd)
00075         {
00076                 if (isset($_POST["imagemap"]) ||
00077                 isset($_POST["imagemap_x"]) ||
00078                 isset($_POST["imagemap_y"]))
00079                 {
00080                         $this->ctrl->setCmd("getCoords");
00081                         $cmd = "getCoords";
00082                 }
00083 
00084                 return $cmd;
00085         }
00086 
00087 
00095         function editQuestion()
00096         {
00097                 $this->tpl->setVariable("HEADER", $this->object->getTitle());
00098                 $this->getQuestionTemplate("qt_imagemap");
00099                 $this->tpl->addBlockFile("QUESTION_DATA", "question_data", "tpl.il_as_qpl_imagemap_question.html", true);
00100                 if (($this->ctrl->getCmd() == "addArea" or $this->ctrl->getCmd() == "getCoords") and ($this->ctrl->getCmd() != "saveShape"))
00101                 {
00102                         foreach ($this->object->coords as $key => $value)
00103                         {
00104                                 $this->tpl->setCurrentBlock("hidden");
00105                                 $this->tpl->setVariable("HIDDEN_NAME", "coords_$key");
00106                                 $this->tpl->setVariable("HIDDEN_VALUE", $value);
00107                                 $this->tpl->parseCurrentBlock();
00108                         }
00109                         $this->tpl->setCurrentBlock("hidden");
00110                         $this->tpl->setVariable("HIDDEN_NAME", "newarea");
00111                         $this->tpl->setVariable("HIDDEN_VALUE", $_POST["newarea"]);
00112                         $this->tpl->parseCurrentBlock();
00113 
00114                         $preview = new ilImagemapPreview($this->object->getImagePath().$this->object->get_image_filename());
00115                         foreach ($this->object->answers as $index => $answer)
00116                         {
00117                                 $preview->addArea($answer->get_area(), $answer->get_coords(), $answer->get_answertext(), "", "", true);
00118                         }
00119                         $hidearea = false;
00120                         $disabled_save = " disabled=\"disabled\"";
00121                         $coords = "";
00122                         switch ($_POST["newarea"])
00123                         {
00124                                 case "rect":
00125                                         if (count($this->object->coords) == 0)
00126                                         {
00127                                                 sendInfo($this->lng->txt("rectangle_click_tl_corner"));
00128                                         }
00129                                         else if (count($this->object->coords) == 1)
00130                                         {
00131                                                 sendInfo($this->lng->txt("rectangle_click_br_corner"));
00132                                         }
00133                                         else if (count($this->object->coords) == 2)
00134                                         {
00135                                                 $coords = join($this->object->coords, ",");
00136                                                 $hidearea = true;
00137                                                 $disabled_save = "";
00138                                         }
00139                                         break;
00140                                 case "circle":
00141                                         if (count($this->object->coords) == 0)
00142                                         {
00143                                                 sendInfo($this->lng->txt("circle_click_center"));
00144                                         }
00145                                         else if (count($this->object->coords) == 1)
00146                                         {
00147                                                 sendInfo($this->lng->txt("circle_click_circle"));
00148                                         }
00149                                         else if (count($this->object->coords) == 2)
00150                                         {
00151                                                 if (preg_match("/(\d+)\s*,\s*(\d+)\s+(\d+)\s*,\s*(\d+)/", $this->object->coords[0] . " " . $this->object->coords[1], $matches))
00152                                                 {
00153                                                         $coords = "$matches[1],$matches[2]," . (int)sqrt((($matches[3]-$matches[1])*($matches[3]-$matches[1]))+(($matches[4]-$matches[2])*($matches[4]-$matches[2])));
00154                                                 }
00155                                                 $hidearea = true;
00156                                                 $disabled_save = "";
00157                                         }
00158                                         break;
00159                                 case "poly":
00160                                         if (count($this->object->coords) == 0)
00161                                         {
00162                                                 sendInfo($this->lng->txt("polygon_click_starting_point"));
00163                                         }
00164                                         else if (count($this->object->coords) == 1)
00165                                         {
00166                                                 sendInfo($this->lng->txt("polygon_click_next_point"));
00167                                         }
00168                                         else if (count($this->object->coords) > 1)
00169                                         {
00170                                                 sendInfo($this->lng->txt("polygon_click_next_or_save"));
00171                                                 $disabled_save = "";
00172                                                 $coords = join($this->object->coords, ",");
00173                                         }
00174                                         break;
00175                         }
00176                         if ($coords)
00177                         {
00178                                 $preview->addArea($_POST["newarea"], $coords, $_POST["shapetitle"], "", "", true, "blue");
00179                         }
00180                         $preview->createPreview();
00181 
00182                         if (count($preview->areas))
00183                         {
00184                                 $imagepath = "displaytempimage.php?gfx=" . $preview->getPreviewFilename();
00185                         }
00186                         else
00187                         {
00188                                 $imagepath = $this->object->getImagePathWeb() . $this->object->get_image_filename();
00189                         }
00190                         if (!$hidearea)
00191                         {
00192                                 $this->tpl->setCurrentBlock("maparea");
00193                                 $this->tpl->setVariable("IMAGE_SOURCE", "$imagepath");
00194                                 $this->tpl->parseCurrentBlock();
00195                         }
00196                         else
00197                         {
00198                                 $this->tpl->setCurrentBlock("imagearea");
00199                                 $this->tpl->setVariable("IMAGE_SOURCE", "$imagepath");
00200                                 $this->tpl->setVariable("ALT_IMAGE", $this->lng->txt("imagemap"));
00201                                 $this->tpl->parseCurrentBlock();
00202                         }
00203                         $this->tpl->setCurrentBlock("imagemapeditor");
00204                         $this->tpl->setVariable("TEXT_IMAGEMAP", $this->lng->txt("imagemap"));
00205                         $this->tpl->setVariable("VALUE_SHAPETITLE", $_POST["shapetitle"]);
00206                         $this->tpl->setVariable("TEXT_SHAPETITLE", $this->lng->txt("name"));
00207                         $this->tpl->setVariable("CANCEL", $this->lng->txt("cancel"));
00208                         $this->tpl->setVariable("SAVE", $this->lng->txt("save"));
00209                         $this->tpl->setVariable("DISABLED_SAVE", $disabled_save);
00210                         $this->tpl->parseCurrentBlock();
00211                         $this->tpl->setCurrentBlock("adm_content");
00212                         $this->tpl->setVariable("IMAGEMAP_ID", $this->object->getId());
00213                         $this->ctrl->setParameter($this, "sel_question_types", "qt_imagemap");
00214                         $this->ctrl->setParameter($this, "editmap", "1");
00215                         $this->tpl->setVariable("ACTION_IMAGEMAP_QUESTION",     $this->ctrl->getFormaction($this));
00216                         $this->tpl->parseCurrentBlock();
00217                 }
00218                 else
00219                 {
00220                         if ($this->object->get_answer_count())
00221                         {
00222                                 $this->tpl->setCurrentBlock("QFooter");
00223                                 $this->tpl->setVariable("DELETE_AREA", $this->lng->txt("delete_area"));
00224                                 $this->tpl->setVariable("ARROW", "<img src=\"" . ilUtil::getImagePath("arrow_downright.gif") . "\" />");
00225                                 $this->tpl->parseCurrentBlock();
00226                                 $this->tpl->setCurrentBlock("answerheader");
00227                                 $this->tpl->setVariable("TEXT_NAME", $this->lng->txt("name"));
00228                                 $this->tpl->setVariable("TEXT_TRUE", $this->lng->txt("true"));
00229                                 $this->tpl->setVariable("TEXT_POINTS", $this->lng->txt("points"));
00230                                 $this->tpl->setVariable("TEXT_SHAPE", $this->lng->txt("shape"));
00231                                 $this->tpl->setVariable("TEXT_COORDINATES", $this->lng->txt("coordinates"));
00232                                 $this->tpl->parseCurrentBlock();
00233                         }
00234                         $tblrow = array("tblrow1", "tblrow2");
00235                         for ($i = 0; $i < $this->object->get_answer_count(); $i++)
00236                         {
00237                                 $this->tpl->setCurrentBlock("answers");
00238                                 $answer = $this->object->get_answer($i);
00239                                 $this->tpl->setVariable("ANSWER_ORDER", $answer->get_order());
00240                                 $this->tpl->setVariable("VALUE_ANSWER", htmlspecialchars($answer->get_answertext()));
00241                                 $this->tpl->setVariable("TEXT_POINTS", $this->lng->txt("points"));
00242                                 if ((strcmp($_GET["markarea"], "") != 0) && ($_GET["markarea"] == $i))
00243                                 {
00244                                         $this->tpl->setVariable("CLASS_FULLWIDTH", "fullwidth_marked");
00245                                 }
00246                                 else
00247                                 {
00248                                         $this->tpl->setVariable("CLASS_FULLWIDTH", "fullwidth");
00249                                 }
00250                                 $this->tpl->setVariable("VALUE_IMAGEMAP_POINTS", $answer->get_points());
00251                                 $this->tpl->setVariable("COLOR_CLASS", $tblrow[$i % 2]);
00252                                 $coords = "";
00253                                 switch ($answer->get_area())
00254                                 {
00255                                         case "poly":
00256                                         case "rect":
00257                                                 $coords = preg_replace("/(\d+,\d+,)/", "\$1 ", $answer->get_coords());
00258                                                 break;
00259                                         case "circle":
00260                                                 $coords = preg_replace("/(\d+,\d+,)/", "\$1 ", $answer->get_coords());
00261                                                 break;
00262                                 }
00263                                 $this->tpl->setVariable("COORDINATES", $coords);
00264                                 $this->tpl->setVariable("AREA", $answer->get_area());
00265                                 $this->tpl->setVariable("TEXT_SHAPE", strtoupper($answer->get_area()));
00266                                 $this->tpl->parseCurrentBlock();
00267                         }
00268                         // call to other question data i.e. estimated working time block
00269                         $this->outOtherQuestionData();
00270                         // image block
00271 
00272                         $internallinks = array(
00273                                 "lm" => $this->lng->txt("obj_lm"),
00274                                 "st" => $this->lng->txt("obj_st"),
00275                                 "pg" => $this->lng->txt("obj_pg"),
00276                                 "glo" => $this->lng->txt("glossary_term")
00277                         );
00278                         foreach ($internallinks as $key => $value)
00279                         {
00280                                 $this->tpl->setCurrentBlock("internallink");
00281                                 $this->tpl->setVariable("TYPE_INTERNAL_LINK", $key);
00282                                 $this->tpl->setVariable("TEXT_INTERNAL_LINK", $value);
00283                                 $this->tpl->parseCurrentBlock();
00284                         }
00285 
00286                         if (strcmp($this->object->get_image_filename(), "") != 0)
00287                         {
00288                                 $this->tpl->setCurrentBlock("addarea");
00289                                 $this->tpl->setVariable("ADD_AREA", $this->lng->txt("add_area"));
00290                                 $this->tpl->setVariable("TEXT_RECT", $this->lng->txt("rectangle"));
00291                                 $this->tpl->setVariable("TEXT_CIRCLE", $this->lng->txt("circle"));
00292                                 $this->tpl->setVariable("TEXT_POLY", $this->lng->txt("polygon"));
00293                                 if (array_key_exists("newarea", $_POST))
00294                                 {
00295                                         switch ($_POST["newarea"])
00296                                         {
00297                                                 case "circle":
00298                                                         $this->tpl->setVariable("SELECTED_CIRCLE", " selected=\"selected\"");
00299                                                         break;
00300                                                 case "poly":
00301                                                         $this->tpl->setVariable("SELECTED_POLY", " selected=\"selected\"");
00302                                                         break;
00303                                                 case "rect":
00304                                                         $this->tpl->setVariable("SELECTED_RECT", " selected=\"selected\"");
00305                                                         break;
00306                                         }
00307                                 }
00308                                 $this->tpl->parseCurrentBlock();
00309                         }
00310                         $this->tpl->setCurrentBlock("HeadContent");
00311                         $javascript = "<script type=\"text/javascript\">function initialSelect() {\n%s\n}</script>";
00312                         if (strcmp($_GET["markarea"], "") != 0)
00313                         {
00314                                 $this->tpl->setVariable("CONTENT_BLOCK", sprintf($javascript, "document.frm_imagemap.answer_".$_GET["markarea"].".focus(); document.frm_imagemap.answer_".$_GET["markarea"].".scrollIntoView(\"true\");"));
00315                         }
00316                         else
00317                         {
00318                                 switch ($this->ctrl->getCmd())
00319                                 {
00320                                         case "saveShape":
00321                                         case "deletearea":
00322                                                 if ($this->object->get_answer_count() > 0)
00323                                                 {
00324                                                         $this->tpl->setVariable("CONTENT_BLOCK", sprintf($javascript, "document.frm_imagemap.answer_".($this->object->get_answer_count() - 1).".focus(); document.frm_imagemap.answer_".($this->object->get_answer_count() - 1).".scrollIntoView(\"true\");"));
00325                                                 }
00326                                                 else
00327                                                 {
00328                                                         $this->tpl->setVariable("CONTENT_BLOCK", sprintf($javascript, "document.frm_imagemap.title.focus();"));
00329                                                 }
00330                                                 break;
00331                                         default:
00332                                                 $this->tpl->setVariable("CONTENT_BLOCK", sprintf($javascript, "document.frm_imagemap.title.focus();"));
00333                                                 break;
00334                                 }
00335                         }
00336                         $this->tpl->parseCurrentBlock();
00337                         $this->tpl->setCurrentBlock("question_data");
00338                         $img = $this->object->get_image_filename();
00339                         $this->tpl->setVariable("TEXT_IMAGE", $this->lng->txt("image"));
00340                         if (!empty($img))
00341                         {
00342                                 $this->tpl->setVariable("IMAGE_FILENAME", $img);
00343                                 $this->tpl->setVariable("VALUE_IMAGE_UPLOAD", $this->lng->txt("change"));
00344                                 $this->tpl->setCurrentBlock("imageupload");
00345                                 //$this->tpl->setVariable("UPLOADED_IMAGE", $img);
00346                                 $this->tpl->parse("imageupload");
00347                                 $map = "";
00348                                 if (count($this->object->answers))
00349                                 {
00350                                         $preview = new ilImagemapPreview($this->object->getImagePath() . $this->object->get_image_filename());
00351                                         foreach ($this->object->answers as $index => $answer)
00352                                         {
00353                                                 $preview->addArea($answer->get_area(), $answer->get_coords(), $answer->get_answertext(), $this->ctrl->getLinkTarget($this, "editQuestion") . "&markarea=$index", "", true);
00354                                         }
00355                                         $preview->createPreview();
00356                                         $imagepath = "displaytempimage.php?gfx=" . $preview->getPreviewFilename();
00357                                         $map = $preview->getImagemap("imagemap_" . $this->object->getId());
00358                                 }
00359                                 else
00360                                 {
00361                                         $imagepath = $this->object->getImagePathWeb() . $img;
00362                                 }
00363                                 $size = GetImageSize ($this->object->getImagePath() . $this->object->get_image_filename());
00364                                 if ($map)
00365                                 {
00366                                         $this->tpl->setVariable("UPLOADED_IMAGE", "<img src=\"$imagepath\" alt=\"$img\" border=\"0\" " . $size[3] . " usemap=\"" . "#imagemap_" . $this->object->getId(). "\" />\n$map\n");
00367                                 }
00368                                 else
00369                                 {
00370                                         $this->tpl->setVariable("UPLOADED_IMAGE", "<img src=\"$imagepath\" alt=\"$img\" border=\"0\" " . $size[3] . " />");
00371                                 }
00372                         }
00373                         else
00374                         {
00375                                 $this->tpl->setVariable("VALUE_IMAGE_UPLOAD", $this->lng->txt("upload"));
00376                         }
00377 
00378                         // imagemap block
00379                         $imgmap = $this->object->get_imagemap_filename();
00380                         $this->tpl->setVariable("TEXT_IMAGEMAP", $this->lng->txt("imagemap_file"));
00381                         $this->tpl->setVariable("VALUE_IMAGEMAP_UPLOAD", $this->lng->txt("add_imagemap"));
00382                         $this->tpl->setCurrentBlock("questioneditor");
00383                         $this->tpl->setVariable("VALUE_IMAGEMAP_TITLE", htmlspecialchars($this->object->getTitle()));
00384                         $this->tpl->setVariable("VALUE_IMAGEMAP_COMMENT", htmlspecialchars($this->object->getComment()));
00385                         $this->tpl->setVariable("VALUE_IMAGEMAP_AUTHOR", htmlspecialchars($this->object->getAuthor()));
00386                         $questiontext = $this->object->get_question();
00387                         $questiontext = preg_replace("/<br \/>/", "\n", $questiontext);
00388                         $this->tpl->setVariable("VALUE_QUESTION", htmlspecialchars($questiontext));
00389                         $this->tpl->setVariable("TEXT_TITLE", $this->lng->txt("title"));
00390                         $this->tpl->setVariable("TEXT_AUTHOR", $this->lng->txt("author"));
00391                         $this->tpl->setVariable("TEXT_COMMENT", $this->lng->txt("description"));
00392                         $this->tpl->setVariable("TEXT_QUESTION", $this->lng->txt("question"));
00393                         $this->tpl->setVariable("TXT_REQUIRED_FLD", $this->lng->txt("required_field"));
00394 
00395                         $this->tpl->setVariable("TEXT_SOLUTION_HINT", $this->lng->txt("solution_hint"));
00396                         if (count($this->object->suggested_solutions))
00397                         {
00398                                 $solution_array = $this->object->getSuggestedSolution(0);
00399                                 $href = ASS_Question::_getInternalLinkHref($solution_array["internal_link"]);
00400                                 $this->tpl->setVariable("TEXT_VALUE_SOLUTION_HINT", " <a href=\"$href\" target=\"content\">" . $this->lng->txt("solution_hint"). "</a> ");
00401                                 $this->tpl->setVariable("BUTTON_REMOVE_SOLUTION", $this->lng->txt("remove"));
00402                                 $this->tpl->setVariable("BUTTON_ADD_SOLUTION", $this->lng->txt("change"));
00403                                 $this->tpl->setVariable("VALUE_SOLUTION_HINT", $solution_array["internal_link"]);
00404                         }
00405                         else
00406                         {
00407                                 $this->tpl->setVariable("BUTTON_ADD_SOLUTION", $this->lng->txt("add"));
00408                         }
00409 
00410                         $this->tpl->setVariable("SAVE",$this->lng->txt("save"));
00411                         $this->tpl->setVariable("SAVE_EDIT", $this->lng->txt("save_edit"));
00412                         $this->tpl->setVariable("CANCEL",$this->lng->txt("cancel"));
00413                         $this->tpl->parseCurrentBlock();
00414                         $this->tpl->setCurrentBlock("adm_content");
00415                         $this->ctrl->setParameter($this, "sel_question_types", "qt_imagemap");
00416                         $this->tpl->setVariable("ACTION_IMAGEMAP_QUESTION",     $this->ctrl->getFormaction($this));
00417                         $this->tpl->setVariable("IMAGEMAP_ID", $this->object->getId());
00418                         $this->tpl->parseCurrentBlock();
00419                 }
00420 
00421                 $this->tpl->setCurrentBlock("adm_content");
00422                 $this->tpl->setVariable("BODY_ATTRIBUTES", " onload=\"initialSelect();\""); 
00423                 $this->tpl->parseCurrentBlock();
00424         }
00425 
00433         function outOtherQuestionData()
00434         {
00435                 $this->tpl->setCurrentBlock("other_question_data");
00436                 $est_working_time = $this->object->getEstimatedWorkingTime();
00437                 $this->tpl->setVariable("TEXT_WORKING_TIME", $this->lng->txt("working_time"));
00438                 $this->tpl->setVariable("TIME_FORMAT", $this->lng->txt("time_format"));
00439                 $this->tpl->setVariable("VALUE_WORKING_TIME", ilUtil::makeTimeSelect("Estimated", false, $est_working_time[h], $est_working_time[m], $est_working_time[s]));
00440                 $this->tpl->parseCurrentBlock();
00441         }
00442 
00443         function getCoords()
00444         {
00445                 $this->writePostData();
00446                 $this->editQuestion();
00447         }
00448 
00449         function back()
00450         {
00451                 $this->editQuestion();
00452         }
00453 
00454         function saveShape()
00455         {
00456                 $this->save();
00457         }
00458 
00459         function addArea()
00460         {
00461                 $_SESSION["last_area"] = $_POST["newarea"];
00462                 $this->writePostData();
00463                 $this->editQuestion();
00464         }
00465 
00466         function uploadingImage()
00467         {
00468                 $this->writePostData();
00469                 $this->editQuestion();
00470         }
00471 
00472         function uploadingImagemap()
00473         {
00474                 $this->writePostData();
00475                 $this->editQuestion();
00476         }
00477 
00478         function deleteArea()
00479         {
00480                 $this->writePostData();
00481                 $checked_areas = array();
00482                 foreach ($_POST as $key => $value)
00483                 {
00484                         if (preg_match("/cb_(\d+)/", $key, $matches))
00485                         {
00486                                 array_push($checked_areas, $matches[1]);
00487                         }
00488                 }
00489                 rsort($checked_areas, SORT_NUMERIC);
00490                 foreach ($checked_areas as $index)
00491                 {
00492                         $this->object->deleteArea($index);
00493                 }
00494                 $this->editQuestion();
00495         }
00496 
00505         function writePostData()
00506         {
00507                 $result = 0;
00508                 $saved = false;
00509 
00510                 if ($_GET["editmap"])
00511                 {
00512                         $this->object->coords = array();
00513                         foreach ($_POST as $key => $value)
00514                         {
00515                                 if (preg_match("/coords_(\d+)/", $key, $matches))
00516                                 {
00517                                         $this->object->coords[$matches[1]] = $value;
00518                                 }
00519                         }
00520                         if (isset($_POST["imagemap_x"]))
00521                         {
00522                                 array_push($this->object->coords, $_POST["imagemap_x"] . "," . $_POST["imagemap_y"]);
00523                         }
00524                         if ($this->ctrl->getCmd() == "saveShape")
00525                         {
00526                                 $coords = "";
00527                                 switch ($_POST["newarea"])
00528                                 {
00529                                         case "rect":
00530                                                 $coords = join($this->object->coords, ",");
00531                                                 break;
00532                                         case "circle":
00533                                                 if (preg_match("/(\d+)\s*,\s*(\d+)\s+(\d+)\s*,\s*(\d+)/", $this->object->coords[0] . " " . $this->object->coords[1], $matches))
00534                                                 {
00535                                                         $coords = "$matches[1],$matches[2]," . (int)sqrt((($matches[3]-$matches[1])*($matches[3]-$matches[1]))+(($matches[4]-$matches[2])*($matches[4]-$matches[2])));
00536                                                 }
00537                                                 break;
00538                                         case "poly":
00539                                                 $coords = join($this->object->coords, ",");
00540                                                 break;
00541                                 }
00542                                 $this->object->add_answer($_POST["shapetitle"], 0, false, count($this->object->answers), $coords, $_POST["newarea"]);
00543                         }
00544                 }
00545                 else
00546                 {
00547                         if (!$this->checkInput())
00548                         {
00549                                 $result = 1;
00550                         }
00551                         $this->object->setTitle(ilUtil::stripSlashes($_POST["title"]));
00552                         $this->object->setAuthor(ilUtil::stripSlashes($_POST["author"]));
00553                         $this->object->setComment(ilUtil::stripSlashes($_POST["comment"]));
00554                         $questiontext = ilUtil::stripSlashes($_POST["question"], true, "<strong><em><code><cite>");
00555                         $questiontext = preg_replace("/\n/", "<br />", $questiontext);
00556                         $this->object->set_question($questiontext);
00557                         $this->object->setSuggestedSolution($_POST["solution_hint"], 0);
00558                         $this->object->setShuffle($_POST["shuffle"]);
00559 
00560                         // adding estimated working time
00561                         $saved = $this->writeOtherPostData($result);
00562 
00563                         if (($_POST["id"] > 0) or ($result != 1))
00564                         {
00565                                 // Question is already saved, so imagemaps and images can be uploaded
00566                                 //setting image file
00567                                 if (empty($_FILES['imageName']['tmp_name']))
00568                                 {
00569                                         $this->object->set_image_filename(ilUtil::stripSlashes($_POST["uploaded_image"]));
00570                                 }
00571                                 else
00572                                 {
00573                                         if ($this->object->getId() <= 0)
00574                                         {
00575                                                 $this->object->saveToDb();
00576                                                 $_GET["q_id"] = $this->object->getId();
00577                                                 $saved = true;
00578                                                 sendInfo($this->lng->txt("question_saved_for_upload"));
00579                                         }
00580                                         $this->object->set_image_filename($_FILES['imageName']['name'], $_FILES['imageName']['tmp_name']);
00581                                 }
00582 
00583                                 //setting imagemap
00584                                 if (empty($_FILES['imagemapName']['tmp_name']))
00585                                 {
00586                                         $this->object->set_imagemap_filename(ilUtil::stripSlashes($_POST['uploaded_imagemap']));
00587                                         // Add all answers from the form into the object
00588                                         $this->object->flush_answers();
00589                                         foreach ($_POST as $key => $value)
00590                                         {
00591                                                 if (preg_match("/answer_(\d+)/", $key, $matches))
00592                                                 {
00593                                                         $points = $_POST["points_$matches[1]"];
00594                                                         if (preg_match("/\d+/", $points))
00595                                                         {
00596                                                                 if ($points < 0)
00597                                                                 {
00598                                                                         $points = 0.0;
00599                                                                         sendInfo($this->lng->txt("negative_points_not_allowed"), true);
00600                                                                 }
00601                                                         }
00602                                                         else
00603                                                         {
00604                                                                 $points = 0.0;
00605                                                         }
00606 
00607 
00608                                                         $this->object->add_answer(
00609                                                                 ilUtil::stripSlashes($_POST["$key"]),
00610                                                                 ilUtil::stripSlashes($points),
00611                                                                 1,
00612                                                                 $matches[1],
00613                                                                 ilUtil::stripSlashes($_POST["coords_$matches[1]"]),
00614                                                                 ilUtil::stripSlashes($_POST["area_$matches[1]"])
00615                                                         );
00616                                                 }
00617                                         }
00618                                 }
00619                                 else
00620                                 {
00621                                         if ($this->object->getId() <= 0)
00622                                         {
00623                                                 $this->object->saveToDb();
00624                                                 $_GET["q_id"] = $this->object->getId();
00625                                                 $saved = true;
00626                                                 sendInfo($this->lng->txt("question_saved_for_upload"));
00627                                         }
00628                                         $this->object->set_imagemap_filename($_FILES['imagemapName']['name'], $_FILES['imagemapName']['tmp_name']);
00629                                 }
00630                         }
00631                         else
00632                         {
00633                                 if (($this->ctrl->getCmd() == "uploadingImage") and (!empty($_FILES['imageName']['tmp_name'])))
00634                                 {
00635                                         sendInfo($this->lng->txt("fill_out_all_required_fields_upload_image"));
00636                                 }
00637                                 else if (($_POST["cmd"]["uploadingImagemap"]) and (!empty($_FILES['imagemapName']['tmp_name'])))
00638                                 {
00639                                         sendInfo($this->lng->txt("fill_out_all_required_fields_upload_imagemap"));
00640                                 }
00641                         }
00642                 }
00643                 if ($this->ctrl->getCmd() == "addArea")
00644                 {
00645                         $this->object->saveToDb();
00646                         $saved = true;
00647                 }
00648                 if ($saved)
00649                 {
00650                         $_GET["q_id"] = $this->object->getId();
00651                 }
00652                 return $result;
00653         }
00654 
00662         function outWorkingForm($test_id = "", $is_postponed = false, $showsolution = 0, &$formaction)
00663         {
00664                 global $ilUser;
00665                 $output = $this->outQuestionPage("IMAGEMAP_QUESTION", $is_postponed);
00666 //              preg_match("/(<div[^<]*?ilc_Question.*?<\/div>)/is", $output, $matches);
00667 //              $solutionoutput = $matches[1];
00668                 $solutionoutput = preg_replace("/.*?(<div[^<]*?ilc_Question.*?<\/div>).*/", "\\1", $output);
00669                 $solutionoutput = preg_replace("/\"map/", "\"solution_map", $solutionoutput);
00670                 $solutionoutput = preg_replace("/qmap/", "solution_qmap", $solutionoutput);
00671                 // set solutions
00672                 if ($test_id)
00673                 {
00674                         $solutions =& $this->object->getSolutionValues($test_id);
00675                         $preview = new ilImagemapPreview($this->object->getImagePath().$this->object->get_image_filename());
00676                         foreach ($solutions as $idx => $solution_value)
00677                         {
00678                                 if (strcmp($solution_value->value1, "") != 0)
00679                                 {
00680                                         $preview->addArea($this->object->answers[$solution_value->value1]->get_area(), $this->object->answers[$solution_value->value1]->get_coords(), $this->object->answers[$solution_value->value1]->get_answertext(), "", "", true);
00681                                 }
00682                         }
00683                         $preview->createPreview();
00684                         if (count($preview->areas))
00685                         {
00686                                 $imagepath = "displaytempimage.php?gfx=" . $preview->getPreviewFilename();
00687                                 $output = preg_replace("/usemap\=\"#qmap\" src\=\"([^\"]*?)\"/", "usemap=\"#qmap\" src=\"$imagepath\"", $output);
00688                         }
00689                 }
00690                 
00691                 $maxpoints = 0;
00692                 $maxindex = -1;
00693                 foreach ($this->object->answers as $idx => $answer)
00694                 {
00695                         if ($answer->get_points() > $maxpoints)
00696                         {
00697                                 $maxpoints = $answer->get_points();
00698                                 $maxindex = $idx;
00699                         }
00700                         if (!array_key_exists("evaluation", $_GET))
00701                         {
00702                                 $output = preg_replace("/nohref id\=\"map$idx\"/", "href=\"$formaction&selImage=$idx\"", $output);
00703                         }
00704                 }
00705                 if ($maxindex > -1)
00706                 {
00707                         $answer = $this->object->answers[$maxindex];
00708                         $preview = new ilImagemapPreview($this->object->getImagePath().$this->object->get_image_filename());
00709                         $preview->addArea($answer->get_area(), $answer->get_coords(), $answer->get_answertext(), "", "", true);
00710                         $preview->createPreview();
00711                         if (count($preview->areas))
00712                         {
00713                                 $imagepath = "displaytempimage.php?gfx=" . $preview->getPreviewFilename();
00714                                 $solutionoutput = preg_replace("/usemap\=\"#solution_qmap\" src\=\"([^\"]*?)\"/", "usemap=\"#solution_qmap\" src=\"$imagepath\"", $solutionoutput);
00715                         }
00716                 }
00717 
00718                 $solutionoutput = "<p>" . $this->lng->txt("correct_solution_is") . ":</p><p>$solutionoutput</p>";
00719                 if ($test_id) 
00720                 {
00721                         $received_points = "<p>" . sprintf($this->lng->txt("you_received_a_of_b_points"), $this->object->getReachedPoints($ilUser->id, $test_id), $this->object->getMaximumPoints()) . "</p>";
00722                 }
00723                 if (!$showsolution)
00724                 {
00725                         $solutionoutput = "";
00726                         $received_points = "";
00727                 }
00728                 $this->tpl->setVariable("IMAGEMAP_QUESTION", $output.$solutionoutput.$received_points);
00729         }
00730 
00738         function outUserSolution($user_id, $test_id)
00739         {
00740         }
00741         
00745         function checkInput()
00746         {
00747                 if ((!$_POST["title"]) or (!$_POST["author"]) or (!$_POST["question"]))
00748                 {
00749                         return false;
00750                 }
00751                 return true;
00752         }
00753 
00754         function addSuggestedSolution()
00755         {
00756                 $_SESSION["subquestion_index"] = 0;
00757                 if ($_POST["cmd"]["addSuggestedSolution"])
00758                 {
00759                         $this->writePostData();
00760                         if (!$this->checkInput())
00761                         {
00762                                 sendInfo($this->lng->txt("fill_out_all_required_fields_add_answer"));
00763                                 $this->editQuestion();
00764                                 return;
00765                         }
00766                 }
00767                 $this->object->saveToDb();
00768                 $_GET["q_id"] = $this->object->getId();
00769                 $this->tpl->setVariable("HEADER", $this->object->getTitle());
00770                 $this->getQuestionTemplate("qt_imagemap");
00771                 parent::addSuggestedSolution();
00772         }
00773 }
00774 ?>

Generated on Fri Dec 13 2013 09:06:32 for ILIAS Release_3_4_x_branch .rev 46804 by  doxygen 1.7.1