• 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                                 $pfile = $preview->getPreviewFilename();
00185                                 if (strlen($pfile) == 0)
00186                                 {
00187                                         sendInfo($this->lng->txt("qpl_imagemap_preview_missing"));
00188                                         $imagepath = $this->object->getImagePathWeb() . $this->object->get_image_filename();
00189                                 }
00190                                 else
00191                                 {
00192                                         $imagepath = "displaytempimage.php?gfx=" . $pfile;
00193                                 }
00194                         }
00195                         else
00196                         {
00197                                 $imagepath = $this->object->getImagePathWeb() . $this->object->get_image_filename();
00198                         }
00199                         if (!$hidearea)
00200                         {
00201                                 $this->tpl->setCurrentBlock("maparea");
00202                                 $this->tpl->setVariable("IMAGE_SOURCE", "$imagepath");
00203                                 $this->tpl->parseCurrentBlock();
00204                         }
00205                         else
00206                         {
00207                                 $this->tpl->setCurrentBlock("imagearea");
00208                                 $this->tpl->setVariable("IMAGE_SOURCE", "$imagepath");
00209                                 $this->tpl->setVariable("ALT_IMAGE", $this->lng->txt("imagemap"));
00210                                 $this->tpl->parseCurrentBlock();
00211                         }
00212                         $this->tpl->setCurrentBlock("imagemapeditor");
00213                         $this->tpl->setVariable("TEXT_IMAGEMAP", $this->lng->txt("imagemap"));
00214                         $this->tpl->setVariable("VALUE_SHAPETITLE", $_POST["shapetitle"]);
00215                         $this->tpl->setVariable("TEXT_SHAPETITLE", $this->lng->txt("name"));
00216                         $this->tpl->setVariable("CANCEL", $this->lng->txt("cancel"));
00217                         $this->tpl->setVariable("SAVE", $this->lng->txt("save"));
00218                         $this->tpl->setVariable("DISABLED_SAVE", $disabled_save);
00219                         $this->tpl->parseCurrentBlock();
00220                         $this->tpl->setCurrentBlock("adm_content");
00221                         $this->tpl->setVariable("IMAGEMAP_ID", $this->object->getId());
00222                         $this->ctrl->setParameter($this, "sel_question_types", "qt_imagemap");
00223                         $this->ctrl->setParameter($this, "editmap", "1");
00224                         $this->tpl->setVariable("ACTION_IMAGEMAP_QUESTION",     $this->ctrl->getFormaction($this));
00225                         $this->tpl->parseCurrentBlock();
00226                 }
00227                 else
00228                 {
00229                         if ($this->object->get_answer_count())
00230                         {
00231                                 $this->tpl->setCurrentBlock("QFooter");
00232                                 $this->tpl->setVariable("DELETE_AREA", $this->lng->txt("delete_area"));
00233                                 $this->tpl->setVariable("ARROW", "<img src=\"" . ilUtil::getImagePath("arrow_downright.gif") . "\" />");
00234                                 $this->tpl->parseCurrentBlock();
00235                                 $this->tpl->setCurrentBlock("answerheader");
00236                                 $this->tpl->setVariable("TEXT_NAME", $this->lng->txt("name"));
00237                                 $this->tpl->setVariable("TEXT_TRUE", $this->lng->txt("true"));
00238                                 $this->tpl->setVariable("TEXT_POINTS", $this->lng->txt("points"));
00239                                 $this->tpl->setVariable("TEXT_SHAPE", $this->lng->txt("shape"));
00240                                 $this->tpl->setVariable("TEXT_COORDINATES", $this->lng->txt("coordinates"));
00241                                 $this->tpl->parseCurrentBlock();
00242                         }
00243                         $tblrow = array("tblrow1", "tblrow2");
00244                         for ($i = 0; $i < $this->object->get_answer_count(); $i++)
00245                         {
00246                                 $this->tpl->setCurrentBlock("answers");
00247                                 $answer = $this->object->get_answer($i);
00248                                 $this->tpl->setVariable("ANSWER_ORDER", $answer->get_order());
00249                                 $this->tpl->setVariable("VALUE_ANSWER", htmlspecialchars($answer->get_answertext()));
00250                                 $this->tpl->setVariable("TEXT_POINTS", $this->lng->txt("points"));
00251                                 if ((strcmp($_GET["markarea"], "") != 0) && ($_GET["markarea"] == $i))
00252                                 {
00253                                         $this->tpl->setVariable("CLASS_FULLWIDTH", "fullwidth_marked");
00254                                 }
00255                                 else
00256                                 {
00257                                         $this->tpl->setVariable("CLASS_FULLWIDTH", "fullwidth");
00258                                 }
00259                                 $this->tpl->setVariable("VALUE_IMAGEMAP_POINTS", $answer->get_points());
00260                                 $this->tpl->setVariable("COLOR_CLASS", $tblrow[$i % 2]);
00261                                 $coords = "";
00262                                 switch ($answer->get_area())
00263                                 {
00264                                         case "poly":
00265                                         case "rect":
00266                                                 $coords = preg_replace("/(\d+,\d+,)/", "\$1 ", $answer->get_coords());
00267                                                 break;
00268                                         case "circle":
00269                                                 $coords = preg_replace("/(\d+,\d+,)/", "\$1 ", $answer->get_coords());
00270                                                 break;
00271                                 }
00272                                 $this->tpl->setVariable("COORDINATES", $coords);
00273                                 $this->tpl->setVariable("AREA", $answer->get_area());
00274                                 $this->tpl->setVariable("TEXT_SHAPE", strtoupper($answer->get_area()));
00275                                 $this->tpl->parseCurrentBlock();
00276                         }
00277                         // call to other question data i.e. estimated working time block
00278                         $this->outOtherQuestionData();
00279                         // image block
00280 
00281                         $internallinks = array(
00282                                 "lm" => $this->lng->txt("obj_lm"),
00283                                 "st" => $this->lng->txt("obj_st"),
00284                                 "pg" => $this->lng->txt("obj_pg"),
00285                                 "glo" => $this->lng->txt("glossary_term")
00286                         );
00287                         foreach ($internallinks as $key => $value)
00288                         {
00289                                 $this->tpl->setCurrentBlock("internallink");
00290                                 $this->tpl->setVariable("TYPE_INTERNAL_LINK", $key);
00291                                 $this->tpl->setVariable("TEXT_INTERNAL_LINK", $value);
00292                                 $this->tpl->parseCurrentBlock();
00293                         }
00294 
00295                         if (strcmp($this->object->get_image_filename(), "") != 0)
00296                         {
00297                                 $this->tpl->setCurrentBlock("addarea");
00298                                 $this->tpl->setVariable("ADD_AREA", $this->lng->txt("add_area"));
00299                                 $this->tpl->setVariable("TEXT_RECT", $this->lng->txt("rectangle"));
00300                                 $this->tpl->setVariable("TEXT_CIRCLE", $this->lng->txt("circle"));
00301                                 $this->tpl->setVariable("TEXT_POLY", $this->lng->txt("polygon"));
00302                                 if (array_key_exists("newarea", $_POST))
00303                                 {
00304                                         switch ($_POST["newarea"])
00305                                         {
00306                                                 case "circle":
00307                                                         $this->tpl->setVariable("SELECTED_CIRCLE", " selected=\"selected\"");
00308                                                         break;
00309                                                 case "poly":
00310                                                         $this->tpl->setVariable("SELECTED_POLY", " selected=\"selected\"");
00311                                                         break;
00312                                                 case "rect":
00313                                                         $this->tpl->setVariable("SELECTED_RECT", " selected=\"selected\"");
00314                                                         break;
00315                                         }
00316                                 }
00317                                 $this->tpl->parseCurrentBlock();
00318                         }
00319                         $this->tpl->setCurrentBlock("HeadContent");
00320                         $javascript = "<script type=\"text/javascript\">function initialSelect() {\n%s\n}</script>";
00321                         if (strcmp($_GET["markarea"], "") != 0)
00322                         {
00323                                 $this->tpl->setVariable("CONTENT_BLOCK", sprintf($javascript, "document.frm_imagemap.answer_".$_GET["markarea"].".focus(); document.frm_imagemap.answer_".$_GET["markarea"].".scrollIntoView(\"true\");"));
00324                         }
00325                         else
00326                         {
00327                                 switch ($this->ctrl->getCmd())
00328                                 {
00329                                         case "saveShape":
00330                                         case "deletearea":
00331                                                 if ($this->object->get_answer_count() > 0)
00332                                                 {
00333                                                         $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\");"));
00334                                                 }
00335                                                 else
00336                                                 {
00337                                                         $this->tpl->setVariable("CONTENT_BLOCK", sprintf($javascript, "document.frm_imagemap.title.focus();"));
00338                                                 }
00339                                                 break;
00340                                         default:
00341                                                 $this->tpl->setVariable("CONTENT_BLOCK", sprintf($javascript, "document.frm_imagemap.title.focus();"));
00342                                                 break;
00343                                 }
00344                         }
00345                         $this->tpl->parseCurrentBlock();
00346                         $this->tpl->setCurrentBlock("question_data");
00347                         $img = $this->object->get_image_filename();
00348                         $this->tpl->setVariable("TEXT_IMAGE", $this->lng->txt("image"));
00349                         if (!empty($img))
00350                         {
00351                                 $this->tpl->setVariable("IMAGE_FILENAME", $img);
00352                                 $this->tpl->setVariable("VALUE_IMAGE_UPLOAD", $this->lng->txt("change"));
00353                                 $this->tpl->setCurrentBlock("imageupload");
00354                                 //$this->tpl->setVariable("UPLOADED_IMAGE", $img);
00355                                 $this->tpl->parse("imageupload");
00356                                 $map = "";
00357                                 if (count($this->object->answers))
00358                                 {
00359                                         $preview = new ilImagemapPreview($this->object->getImagePath() . $this->object->get_image_filename());
00360                                         foreach ($this->object->answers as $index => $answer)
00361                                         {
00362                                                 $preview->addArea($answer->get_area(), $answer->get_coords(), $answer->get_answertext(), $this->ctrl->getLinkTarget($this, "editQuestion") . "&markarea=$index", "", true);
00363                                         }
00364                                         $preview->createPreview();
00365                                         $pfile = $preview->getPreviewFilename();
00366                                         if (strlen($pfile) == 0)
00367                                         {
00368                                                 sendInfo($this->lng->txt("qpl_imagemap_preview_missing"));
00369                                                 $imagepath = $this->object->getImagePathWeb() . $this->object->get_image_filename();
00370                                         }
00371                                         else
00372                                         {
00373                                                 $imagepath = "displaytempimage.php?gfx=" . $pfile;
00374                                         }
00375                                         $map = $preview->getImagemap("imagemap_" . $this->object->getId());
00376                                 }
00377                                 else
00378                                 {
00379                                         $imagepath = $this->object->getImagePathWeb() . $img;
00380                                 }
00381                                 $size = GetImageSize ($this->object->getImagePath() . $this->object->get_image_filename());
00382                                 if ($map)
00383                                 {
00384                                         $this->tpl->setVariable("UPLOADED_IMAGE", "<img src=\"$imagepath\" alt=\"$img\" border=\"0\" " . $size[3] . " usemap=\"" . "#imagemap_" . $this->object->getId(). "\" />\n$map\n");
00385                                 }
00386                                 else
00387                                 {
00388                                         $this->tpl->setVariable("UPLOADED_IMAGE", "<img src=\"$imagepath\" alt=\"$img\" border=\"0\" " . $size[3] . " />");
00389                                 }
00390                         }
00391                         else
00392                         {
00393                                 $this->tpl->setVariable("VALUE_IMAGE_UPLOAD", $this->lng->txt("upload"));
00394                         }
00395 
00396                         // imagemap block
00397                         $imgmap = $this->object->get_imagemap_filename();
00398                         $this->tpl->setVariable("TEXT_IMAGEMAP", $this->lng->txt("imagemap_file"));
00399                         $this->tpl->setVariable("VALUE_IMAGEMAP_UPLOAD", $this->lng->txt("add_imagemap"));
00400                         $this->tpl->setCurrentBlock("questioneditor");
00401                         $this->tpl->setVariable("VALUE_IMAGEMAP_TITLE", htmlspecialchars($this->object->getTitle()));
00402                         $this->tpl->setVariable("VALUE_IMAGEMAP_COMMENT", htmlspecialchars($this->object->getComment()));
00403                         $this->tpl->setVariable("VALUE_IMAGEMAP_AUTHOR", htmlspecialchars($this->object->getAuthor()));
00404                         $questiontext = $this->object->get_question();
00405                         $questiontext = preg_replace("/<br \/>/", "\n", $questiontext);
00406                         $this->tpl->setVariable("VALUE_QUESTION", htmlspecialchars($questiontext));
00407                         $this->tpl->setVariable("TEXT_TITLE", $this->lng->txt("title"));
00408                         $this->tpl->setVariable("TEXT_AUTHOR", $this->lng->txt("author"));
00409                         $this->tpl->setVariable("TEXT_COMMENT", $this->lng->txt("description"));
00410                         $this->tpl->setVariable("TEXT_QUESTION", $this->lng->txt("question"));
00411                         $this->tpl->setVariable("TXT_REQUIRED_FLD", $this->lng->txt("required_field"));
00412 
00413                         $this->tpl->setVariable("TEXT_SOLUTION_HINT", $this->lng->txt("solution_hint"));
00414                         if (count($this->object->suggested_solutions))
00415                         {
00416                                 $solution_array = $this->object->getSuggestedSolution(0);
00417                                 $href = ASS_Question::_getInternalLinkHref($solution_array["internal_link"]);
00418                                 $this->tpl->setVariable("TEXT_VALUE_SOLUTION_HINT", " <a href=\"$href\" target=\"content\">" . $this->lng->txt("solution_hint"). "</a> ");
00419                                 $this->tpl->setVariable("BUTTON_REMOVE_SOLUTION", $this->lng->txt("remove"));
00420                                 $this->tpl->setVariable("BUTTON_ADD_SOLUTION", $this->lng->txt("change"));
00421                                 $this->tpl->setVariable("VALUE_SOLUTION_HINT", $solution_array["internal_link"]);
00422                         }
00423                         else
00424                         {
00425                                 $this->tpl->setVariable("BUTTON_ADD_SOLUTION", $this->lng->txt("add"));
00426                         }
00427 
00428                         $this->tpl->setVariable("SAVE",$this->lng->txt("save"));
00429                         $this->tpl->setVariable("SAVE_EDIT", $this->lng->txt("save_edit"));
00430                         $this->tpl->setVariable("CANCEL",$this->lng->txt("cancel"));
00431                         $this->tpl->parseCurrentBlock();
00432                         $this->tpl->setCurrentBlock("adm_content");
00433                         $this->ctrl->setParameter($this, "sel_question_types", "qt_imagemap");
00434                         $this->tpl->setVariable("ACTION_IMAGEMAP_QUESTION",     $this->ctrl->getFormaction($this));
00435                         $this->tpl->setVariable("IMAGEMAP_ID", $this->object->getId());
00436                         $this->tpl->parseCurrentBlock();
00437 
00438                         $this->tpl->setCurrentBlock("adm_content");
00439                         $this->tpl->setVariable("BODY_ATTRIBUTES", " onload=\"initialSelect();\""); 
00440                         $this->tpl->parseCurrentBlock();
00441                 }
00442         }
00443 
00451         function outOtherQuestionData()
00452         {
00453                 $this->tpl->setCurrentBlock("other_question_data");
00454                 $est_working_time = $this->object->getEstimatedWorkingTime();
00455                 $this->tpl->setVariable("TEXT_WORKING_TIME", $this->lng->txt("working_time"));
00456                 $this->tpl->setVariable("TIME_FORMAT", $this->lng->txt("time_format"));
00457                 $this->tpl->setVariable("VALUE_WORKING_TIME", ilUtil::makeTimeSelect("Estimated", false, $est_working_time[h], $est_working_time[m], $est_working_time[s]));
00458                 $this->tpl->parseCurrentBlock();
00459         }
00460 
00461         function getCoords()
00462         {
00463                 $this->writePostData();
00464                 $this->editQuestion();
00465         }
00466 
00467         function back()
00468         {
00469                 $this->editQuestion();
00470         }
00471 
00472         function saveShape()
00473         {
00474                 $this->save();
00475         }
00476 
00477         function addArea()
00478         {
00479                 $_SESSION["last_area"] = $_POST["newarea"];
00480                 $this->writePostData();
00481                 $this->editQuestion();
00482         }
00483 
00484         function uploadingImage()
00485         {
00486                 $this->writePostData();
00487                 $this->editQuestion();
00488         }
00489 
00490         function uploadingImagemap()
00491         {
00492                 $this->writePostData();
00493                 $this->editQuestion();
00494         }
00495 
00496         function deleteArea()
00497         {
00498                 $this->writePostData();
00499                 $checked_areas = array();
00500                 foreach ($_POST as $key => $value)
00501                 {
00502                         if (preg_match("/cb_(\d+)/", $key, $matches))
00503                         {
00504                                 array_push($checked_areas, $matches[1]);
00505                         }
00506                 }
00507                 rsort($checked_areas, SORT_NUMERIC);
00508                 foreach ($checked_areas as $index)
00509                 {
00510                         $this->object->deleteArea($index);
00511                 }
00512                 $this->editQuestion();
00513         }
00514 
00523         function writePostData()
00524         {
00525                 $result = 0;
00526                 $saved = false;
00527 
00528                 if ($_GET["editmap"])
00529                 {
00530                         $this->object->coords = array();
00531                         foreach ($_POST as $key => $value)
00532                         {
00533                                 if (preg_match("/coords_(\d+)/", $key, $matches))
00534                                 {
00535                                         $this->object->coords[$matches[1]] = $value;
00536                                 }
00537                         }
00538                         if (isset($_POST["imagemap_x"]))
00539                         {
00540                                 array_push($this->object->coords, $_POST["imagemap_x"] . "," . $_POST["imagemap_y"]);
00541                         }
00542                         if ($this->ctrl->getCmd() == "saveShape")
00543                         {
00544                                 $coords = "";
00545                                 switch ($_POST["newarea"])
00546                                 {
00547                                         case "rect":
00548                                                 $coords = join($this->object->coords, ",");
00549                                                 break;
00550                                         case "circle":
00551                                                 if (preg_match("/(\d+)\s*,\s*(\d+)\s+(\d+)\s*,\s*(\d+)/", $this->object->coords[0] . " " . $this->object->coords[1], $matches))
00552                                                 {
00553                                                         $coords = "$matches[1],$matches[2]," . (int)sqrt((($matches[3]-$matches[1])*($matches[3]-$matches[1]))+(($matches[4]-$matches[2])*($matches[4]-$matches[2])));
00554                                                 }
00555                                                 break;
00556                                         case "poly":
00557                                                 $coords = join($this->object->coords, ",");
00558                                                 break;
00559                                 }
00560                                 $this->object->add_answer($_POST["shapetitle"], 0, false, count($this->object->answers), $coords, $_POST["newarea"]);
00561                         }
00562                 }
00563                 else
00564                 {
00565                         if (!$this->checkInput())
00566                         {
00567                                 $result = 1;
00568                         }
00569                         $this->object->setTitle(ilUtil::stripSlashes($_POST["title"]));
00570                         $this->object->setAuthor(ilUtil::stripSlashes($_POST["author"]));
00571                         $this->object->setComment(ilUtil::stripSlashes($_POST["comment"]));
00572                         $questiontext = ilUtil::stripSlashes($_POST["question"], true, "<strong><em><code><cite>");
00573                         $questiontext = preg_replace("/\n/", "<br />", $questiontext);
00574                         $this->object->set_question($questiontext);
00575                         $this->object->setSuggestedSolution($_POST["solution_hint"], 0);
00576                         $this->object->setShuffle($_POST["shuffle"]);
00577 
00578                         // adding estimated working time
00579                         $saved = $this->writeOtherPostData($result);
00580 
00581                         if (($_POST["id"] > 0) or ($result != 1))
00582                         {
00583                                 // Question is already saved, so imagemaps and images can be uploaded
00584                                 //setting image file
00585                                 if (empty($_FILES['imageName']['tmp_name']))
00586                                 {
00587                                         $this->object->set_image_filename(ilUtil::stripSlashes($_POST["uploaded_image"]));
00588                                 }
00589                                 else
00590                                 {
00591                                         if ($this->object->getId() <= 0)
00592                                         {
00593                                                 $this->object->saveToDb();
00594                                                 $_GET["q_id"] = $this->object->getId();
00595                                                 $saved = true;
00596                                                 sendInfo($this->lng->txt("question_saved_for_upload"));
00597                                         }
00598                                         $this->object->set_image_filename($_FILES['imageName']['name'], $_FILES['imageName']['tmp_name']);
00599                                 }
00600 
00601                                 //setting imagemap
00602                                 if (empty($_FILES['imagemapName']['tmp_name']))
00603                                 {
00604                                         $this->object->set_imagemap_filename(ilUtil::stripSlashes($_POST['uploaded_imagemap']));
00605                                         // Add all answers from the form into the object
00606                                         $this->object->flush_answers();
00607                                         foreach ($_POST as $key => $value)
00608                                         {
00609                                                 if (preg_match("/answer_(\d+)/", $key, $matches))
00610                                                 {
00611                                                         $points = $_POST["points_$matches[1]"];
00612                                                         if (preg_match("/\d+/", $points))
00613                                                         {
00614                                                                 if ($points < 0)
00615                                                                 {
00616                                                                         $points = 0.0;
00617                                                                         sendInfo($this->lng->txt("negative_points_not_allowed"), true);
00618                                                                 }
00619                                                         }
00620                                                         else
00621                                                         {
00622                                                                 $points = 0.0;
00623                                                         }
00624 
00625 
00626                                                         $this->object->add_answer(
00627                                                                 ilUtil::stripSlashes($_POST["$key"]),
00628                                                                 ilUtil::stripSlashes($points),
00629                                                                 1,
00630                                                                 $matches[1],
00631                                                                 ilUtil::stripSlashes($_POST["coords_$matches[1]"]),
00632                                                                 ilUtil::stripSlashes($_POST["area_$matches[1]"])
00633                                                         );
00634                                                 }
00635                                         }
00636                                 }
00637                                 else
00638                                 {
00639                                         if ($this->object->getId() <= 0)
00640                                         {
00641                                                 $this->object->saveToDb();
00642                                                 $_GET["q_id"] = $this->object->getId();
00643                                                 $saved = true;
00644                                                 sendInfo($this->lng->txt("question_saved_for_upload"));
00645                                         }
00646                                         $this->object->set_imagemap_filename($_FILES['imagemapName']['name'], $_FILES['imagemapName']['tmp_name']);
00647                                 }
00648                         }
00649                         else
00650                         {
00651                                 if (($this->ctrl->getCmd() == "uploadingImage") and (!empty($_FILES['imageName']['tmp_name'])))
00652                                 {
00653                                         sendInfo($this->lng->txt("fill_out_all_required_fields_upload_image"));
00654                                 }
00655                                 else if (($_POST["cmd"]["uploadingImagemap"]) and (!empty($_FILES['imagemapName']['tmp_name'])))
00656                                 {
00657                                         sendInfo($this->lng->txt("fill_out_all_required_fields_upload_imagemap"));
00658                                 }
00659                         }
00660                 }
00661                 if ($this->ctrl->getCmd() == "addArea")
00662                 {
00663                         $this->object->saveToDb();
00664                         $saved = true;
00665                 }
00666                 if ($saved)
00667                 {
00668                         $_GET["q_id"] = $this->object->getId();
00669                 }
00670                 return $result;
00671         }
00672 
00680         function outWorkingForm($test_id = "", $is_postponed = false, $showsolution = 0, &$formaction, $show_question_page=true, $show_solution_only = false, $ilUser = null)
00681         {
00682                 if (!is_object($ilUser)) {
00683                         global $ilUser;
00684                 }
00685                 $output = $this->outQuestionPage(($show_solution_only)?"":"IMAGEMAP_QUESTION", $is_postponed,"", !$show_question_page);
00686 //              preg_match("/(<div[^<]*?ilc_Question.*?<\/div>)/is", $output, $matches);
00687 //              $solutionoutput = $matches[1];
00688 
00689                 if ($showsolution)
00690                 {
00691                         $solutionintroduction = "<p>" . $this->lng->txt("tst_your_answer_was") . "</p>";
00692                         $output = preg_replace("/(<div[^<]*?ilc_PageTitle.*?<\/div>)/", "\\1" . $solutionintroduction, $output);
00693                 }
00694                 $solutionoutput = preg_replace("/.*?(<div[^<]*?ilc_Question.*?<\/div>).*/", "\\1", $output);
00695                 $solutionoutput = preg_replace("/\"map/", "\"solution_map", $solutionoutput);
00696                 $solutionoutput = preg_replace("/qmap/", "solution_qmap", $solutionoutput);
00697 
00698                 if (!$show_question_page)
00699                         $output = preg_replace("/.*?(<div[^<]*?ilc_Question.*?<\/div>).*/", "\\1", $output);
00700                         
00701                 // if wants solution only then strip the question element from output
00702                 if ($show_solution_only) {
00703                         $output = preg_replace("/(<div[^<]*?ilc_Question[^>]*>.*?<\/div>)/", "", $output);
00704                 }
00705                         
00706                         
00707                 // set solutions
00708                 if ($test_id)
00709                 {
00710                         $solutions =& $this->object->getSolutionValues($test_id, $ilUser);
00711                         $preview = new ilImagemapPreview($this->object->getImagePath().$this->object->get_image_filename());
00712                         foreach ($solutions as $idx => $solution_value)
00713                         {
00714                                 if (strcmp($solution_value->value1, "") != 0)
00715                                 {
00716                                         $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);
00717                                 }
00718                         }
00719                         $preview->createPreview();
00720                         if (count($preview->areas))
00721                         {
00722                                 $pfile = $preview->getPreviewFilename();
00723                                 if (strlen($pfile) == 0)
00724                                 {
00725                                         sendInfo($this->lng->txt("qpl_imagemap_preview_missing"));
00726                                         $imagepath = $this->object->getImagePathWeb() . $this->object->get_image_filename();
00727                                 }
00728                                 else
00729                                 {
00730                                         $imagepath = "displaytempimage.php?gfx=" . $pfile;
00731                                 }
00732                                 $output = preg_replace("/usemap\=\"#qmap\" src\=\"([^\"]*?)\"/", "usemap=\"#qmap\" src=\"$imagepath\"", $output);
00733                         }
00734                 }
00735                 
00736                 $maxpoints = 0;
00737                 $maxindex = -1;
00738                 foreach ($this->object->answers as $idx => $answer)
00739                 {
00740                         if ($answer->get_points() > $maxpoints)
00741                         {
00742                                 $maxpoints = $answer->get_points();
00743                                 $maxindex = $idx;
00744                         }
00745                         if (!array_key_exists("evaluation", $_GET))
00746                         {
00747                                 $output = preg_replace("/nohref id\=\"map$idx\"/", "href=\"$formaction&selImage=$idx\"", $output);
00748                         }
00749                 }
00750                 if ($maxindex > -1)
00751                 {
00752                         $answer = $this->object->answers[$maxindex];
00753                         $preview = new ilImagemapPreview($this->object->getImagePath().$this->object->get_image_filename());
00754                         $preview->addArea($answer->get_area(), $answer->get_coords(), $answer->get_answertext(), "", "", true);
00755                         $preview->createPreview();
00756                         if (count($preview->areas))
00757                         {
00758                                 $pfile = $preview->getPreviewFilename();
00759                                 if (strlen($pfile) == 0)
00760                                 {
00761                                         sendInfo($this->lng->txt("qpl_imagemap_preview_missing"));
00762                                         $imagepath = $this->object->getImagePathWeb() . $this->object->get_image_filename();
00763                                 }
00764                                 else
00765                                 {
00766                                         $imagepath = "displaytempimage.php?gfx=" . $pfile;
00767                                 }
00768                                 $solutionoutput = preg_replace("/usemap\=\"#solution_qmap\" src\=\"([^\"]*?)\"/", "usemap=\"#solution_qmap\" src=\"$imagepath\"", $solutionoutput);
00769                         }
00770                 }
00771 
00772                 $solutionoutput = "<p>" . $this->lng->txt("correct_solution_is") . ":</p><p>$solutionoutput</p>";
00773                 if ($test_id) 
00774                 {
00775                         $reached_points = $this->object->getReachedPoints($ilUser->id, $test_id);
00776                         $received_points = "<p>" . sprintf($this->lng->txt("you_received_a_of_b_points"), $reached_points, $this->object->getMaximumPoints());
00777                         $count_comment = "";
00778                         if ($reached_points == 0)
00779                         {
00780                                 $count_comment = $this->object->getSolutionCommentCountSystem($test_id);
00781                                 if (strlen($count_comment))
00782                                 {
00783                                         if (strlen($mc_comment) == 0)
00784                                         {
00785                                                 $count_comment = "<span class=\"asterisk\">*</span><br /><br /><span class=\"asterisk\">*</span>$count_comment";
00786                                         }
00787                                         else
00788                                         {
00789                                                 $count_comment = "<br /><span class=\"asterisk\">*</span>$count_comment";
00790                                         }
00791                                 }
00792                         }
00793                         $received_points .= $count_comment;
00794                         $received_points .= "</p>";
00795                 }
00796                 if (!$showsolution)
00797                 {
00798                         $solutionoutput = "";
00799                         $received_points = "";
00800                 }
00801                 $this->tpl->setVariable("IMAGEMAP_QUESTION", $output.$solutionoutput.$received_points);
00802         }
00803 
00811         function outUserSolution($user_id, $test_id)
00812         {
00813         }
00814         
00818         function checkInput()
00819         {
00820                 if ((!$_POST["title"]) or (!$_POST["author"]) or (!$_POST["question"]))
00821                 {
00822                         return false;
00823                 }
00824                 return true;
00825         }
00826 
00827         function addSuggestedSolution()
00828         {
00829                 $_SESSION["subquestion_index"] = 0;
00830                 if ($_POST["cmd"]["addSuggestedSolution"])
00831                 {
00832                         $this->writePostData();
00833                         if (!$this->checkInput())
00834                         {
00835                                 sendInfo($this->lng->txt("fill_out_all_required_fields_add_answer"));
00836                                 $this->editQuestion();
00837                                 return;
00838                         }
00839                 }
00840                 $this->object->saveToDb();
00841                 $_GET["q_id"] = $this->object->getId();
00842                 $this->tpl->setVariable("HEADER", $this->object->getTitle());
00843                 $this->getQuestionTemplate("qt_imagemap");
00844                 parent::addSuggestedSolution();
00845         }
00846 }
00847 ?>

Generated on Fri Dec 13 2013 10:18:25 for ILIAS Release_3_5_x_branch .rev 46805 by  doxygen 1.7.1