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

assessment/classes/class.assMatchingQuestionGUI.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.assMatchingQuestion.php";
00026 
00038 class ASS_MatchingQuestionGUI extends ASS_QuestionGUI
00039 {
00048         function ASS_MatchingQuestionGUI(
00049                 $id = -1
00050         )
00051         {
00052                 $this->ASS_QuestionGUI();
00053                 $this->object = new ASS_MatchingQuestion();
00054                 if ($id >= 0)
00055                 {
00056                         $this->object->loadFromDb($id);
00057                 }
00058         }
00059 
00068         function getQuestionType()
00069         {
00070                 return "qt_matching";
00071         }
00072 
00073         function getCommand($cmd)
00074         {
00075                 if (substr($cmd, 0, 6) == "delete")
00076                 {
00077                         $cmd = "delete";
00078                 }
00079                 if (substr($cmd, 0, 6) == "upload")
00080                 {
00081                         $cmd = "upload";
00082                 }
00083 
00084                 return $cmd;
00085         }
00086 
00094         function editQuestion($has_error = 0)
00095         {
00096                 $this->tpl->setVariable("HEADER", $this->object->getTitle());
00097                 $this->getQuestionTemplate("qt_matching");
00098                 $this->tpl->addBlockFile("QUESTION_DATA", "question_data", "tpl.il_as_qpl_matching.html", true);
00099 
00100                 // Vorhandene Anworten ausgeben
00101                 for ($i = 0; $i < $this->object->get_matchingpair_count(); $i++)
00102                 {
00103                         $this->tpl->setCurrentBlock("deletebutton");
00104                         $this->tpl->setVariable("DELETE", $this->lng->txt("delete"));
00105                         $this->tpl->setVariable("ANSWER_ORDER", $i);
00106                         $this->tpl->parseCurrentBlock();
00107                         $thispair = $this->object->get_matchingpair($i);
00108                         if ($this->object->get_matching_type() == MT_TERMS_PICTURES)
00109                         {
00110                                 $this->tpl->setCurrentBlock("pictures");
00111                                 $this->tpl->setVariable("ANSWER_ORDER", $i);
00112                                 $this->tpl->setVariable("PICTURE_ID", $thispair->getPictureId());
00113                                 $filename = $thispair->getPicture();
00114                                 if ($filename)
00115                                 {
00116                                         $imagepath = $this->object->getImagePathWeb() . $thispair->getPicture();
00117                                         $this->tpl->setVariable("UPLOADED_IMAGE", "<img src=\"$imagepath.thumb.jpg\" alt=\"" . $this->lng->txt("qpl_display_fullsize_image") . "\" title=\"" . $this->lng->txt("qpl_display_fullsize_image") . "\" border=\"\" />");
00118                                         $this->tpl->setVariable("IMAGE_FILENAME", $thispair->getPicture());
00119                                         $this->tpl->setVariable("VALUE_PICTURE", $thispair->getPicture());
00120                                 }
00121                                 $this->tpl->setVariable("UPLOAD", $this->lng->txt("upload"));
00122                         }
00123                         elseif ($this->object->get_matching_type() == MT_TERMS_DEFINITIONS)
00124                         {
00125                                 $this->tpl->setCurrentBlock("definitions");
00126                                 $this->tpl->setVariable("ANSWER_ORDER", $i);
00127                                 $this->tpl->setVariable("DEFINITION_ID", $thispair->getDefinitionId());
00128                                 $this->tpl->setVariable("VALUE_DEFINITION", htmlspecialchars($thispair->getDefinition()));
00129                         }
00130                         $this->tpl->parseCurrentBlock();
00131                         $this->tpl->setCurrentBlock("answers");
00132                         $this->tpl->setVariable("VALUE_ANSWER_COUNTER", $i + 1);
00133                         $this->tpl->setVariable("TEXT_MATCHING_PAIR", $this->lng->txt("matching_pair"));
00134                         $this->tpl->setVariable("TEXT_MATCHES", $this->lng->txt("matches"));
00135                         $this->tpl->setVariable("ANSWER_ORDER", $i);
00136                         $this->tpl->setVariable("TERM_ID", $thispair->getTermId());
00137                         $this->tpl->setVariable("VALUE_TERM", htmlspecialchars($thispair->getTerm()));
00138                         $this->tpl->setVariable("TEXT_POINTS", $this->lng->txt("points"));
00139                         $this->tpl->setVariable("VALUE_MATCHINGPAIR_POINTS", sprintf("%d", $thispair->getPoints()));
00140                         $this->tpl->parseCurrentBlock();
00141                 }
00142                 // call to other question data i.e. estimated working time block
00143                 $this->outOtherQuestionData();
00144 
00145                 // Check the creation of new answer text fields
00146                 $allow_add_pair = 1;
00147                 foreach ($_POST as $key => $value)
00148                 {
00149                         if (preg_match("/(term|picture|definition)_(\d+)_(\d+)/", $key, $matches))
00150                         {
00151                                 if (!$value)
00152                                 {
00153                                         $allow_add_pair = 0;
00154                                 }
00155                         }
00156                 }
00157                 $add_random_id = "";
00158                 if (($this->ctrl->getCmd() == "addPair") and $allow_add_pair and (!$has_error))
00159                 {
00160                         // Template für neue Antwort erzeugen
00161                         if ($this->object->get_matching_type() == MT_TERMS_PICTURES)
00162                         {
00163                                 $this->tpl->setCurrentBlock("pictures");
00164                                 $this->tpl->setVariable("ANSWER_ORDER", $this->object->get_matchingpair_count());
00165                                 $this->tpl->setVariable("PICTURE_ID", $this->object->get_random_id());
00166                                 $this->tpl->setVariable("VALUE_PICTURE", "");
00167                                 $this->tpl->setVariable("UPLOAD", $this->lng->txt("upload"));
00168                         }
00169                         elseif ($this->object->get_matching_type() == MT_TERMS_DEFINITIONS)
00170                         {
00171                                 $this->tpl->setCurrentBlock("definitions");
00172                                 $this->tpl->setVariable("ANSWER_ORDER", $this->object->get_matchingpair_count());
00173                                 $this->tpl->setVariable("DEFINITION_ID", $this->object->get_random_id());
00174                                 $this->tpl->setVariable("VALUE_DEFINITION", "");
00175                         }
00176                         $this->tpl->parseCurrentBlock();
00177                         $this->tpl->setCurrentBlock("answers");
00178                         $this->tpl->setVariable("TEXT_MATCHING_PAIR", $this->lng->txt("matching_pair"));
00179                         $this->tpl->setVariable("VALUE_ANSWER_COUNTER", $this->object->get_matchingpair_count() + 1);
00180                         $this->tpl->setVariable("TEXT_MATCHES", $this->lng->txt("matches"));
00181                         $this->tpl->setVariable("ANSWER_ORDER", $this->object->get_matchingpair_count());
00182                         $add_random_id = $this->object->get_random_id();
00183                         $this->tpl->setVariable("TERM_ID", $add_random_id);
00184                         $this->tpl->setVariable("TEXT_POINTS", $this->lng->txt("points"));
00185                         $this->tpl->setVariable("VALUE_MATCHINGPAIR_POINTS", sprintf("%d", 0));
00186                         $this->tpl->parseCurrentBlock();
00187                 }
00188                 else if ($this->ctrl->getCmd() == "addPair")
00189                 {
00190                         $this->error .= $this->lng->txt("fill_out_all_matching_pairs") . "<br />";
00191                 }
00192 
00193                 $internallinks = array(
00194                         "lm" => $this->lng->txt("obj_lm"),
00195                         "st" => $this->lng->txt("obj_st"),
00196                         "pg" => $this->lng->txt("obj_pg"),
00197                         "glo" => $this->lng->txt("glossary_term")
00198                 );
00199                 foreach ($internallinks as $key => $value)
00200                 {
00201                         $this->tpl->setCurrentBlock("internallink");
00202                         $this->tpl->setVariable("TYPE_INTERNAL_LINK", $key);
00203                         $this->tpl->setVariable("TEXT_INTERNAL_LINK", $value);
00204                         $this->tpl->parseCurrentBlock();
00205                 }
00206                 
00207                 $this->tpl->setCurrentBlock("HeadContent");
00208                 $javascript = "<script type=\"text/javascript\">function initialSelect() {\n%s\n}</script>";
00209                 if (preg_match("/delete_(\d+)/", $this->ctrl->getCmd()))
00210                 {
00211                         if ($this->object->get_matchingpair_count() > 0)
00212                         {
00213                                 $thispair = $this->object->get_matchingpair($this->object->get_matchingpair_count()-1);
00214                                 $this->tpl->setVariable("CONTENT_BLOCK", sprintf($javascript, "document.frm_matching.term_".($this->object->get_matchingpair_count()-1)."_" . $thispair->getTermId().".focus(); document.frm_matching.term_".($this->object->get_matchingpair_count()-1)."_" . $thispair->getTermId().".scrollIntoView(\"true\");"));
00215                         }
00216                         else
00217                         {
00218                                 $this->tpl->setVariable("CONTENT_BLOCK", sprintf($javascript, "document.frm_matching.title.focus();"));
00219                         }
00220                 }
00221                 else
00222                 {
00223                         switch ($this->ctrl->getCmd())
00224                         {
00225                                 case "addPair":
00226                                         $this->tpl->setVariable("CONTENT_BLOCK", sprintf($javascript, "document.frm_matching.term_".($this->object->get_matchingpair_count())."_" . $add_random_id.".focus(); document.frm_matching.term_".($this->object->get_matchingpair_count())."_" . $add_random_id.".scrollIntoView(\"true\");"));
00227                                         break;
00228                                 default:
00229                                         $this->tpl->setVariable("CONTENT_BLOCK", sprintf($javascript, "document.frm_matching.title.focus();"));
00230                                         break;
00231                         }
00232                 }
00233                 $this->tpl->parseCurrentBlock();
00234                 $this->tpl->setCurrentBlock("question_data");
00235                 $this->tpl->setVariable("TEXT_TITLE", $this->lng->txt("title"));
00236                 $this->tpl->setVariable("TEXT_AUTHOR", $this->lng->txt("author"));
00237                 $this->tpl->setVariable("TEXT_COMMENT", $this->lng->txt("description"));
00238                 $this->tpl->setVariable("TEXT_QUESTION", $this->lng->txt("question"));
00239                 $this->tpl->setVariable("TEXT_SHUFFLE_ANSWERS", $this->lng->txt("shuffle_answers"));
00240                 $this->tpl->setVariable("TXT_YES", $this->lng->txt("yes"));
00241                 $this->tpl->setVariable("TXT_NO", $this->lng->txt("no"));
00242                 if ($this->object->getShuffle())
00243                 {
00244                         $this->tpl->setVariable("SELECTED_YES", " selected=\"selected\"");
00245                 }
00246                 else
00247                 {
00248                         $this->tpl->setVariable("SELECTED_NO", " selected=\"selected\"");
00249                 }
00250                 $this->tpl->setVariable("MATCHING_ID", $this->object->getId());
00251                 $this->tpl->setVariable("VALUE_MATCHING_TITLE", htmlspecialchars($this->object->getTitle()));
00252                 $this->tpl->setVariable("VALUE_MATCHING_COMMENT", htmlspecialchars($this->object->getComment()));
00253                 $this->tpl->setVariable("VALUE_MATCHING_AUTHOR", htmlspecialchars($this->object->getAuthor()));
00254                 $questiontext = $this->object->get_question();
00255                 $questiontext = preg_replace("/<br \/>/", "\n", $questiontext);
00256                 $this->tpl->setVariable("VALUE_QUESTION", htmlspecialchars($questiontext));
00257                 $this->tpl->setVariable("VALUE_ADD_ANSWER", $this->lng->txt("add_matching_pair"));
00258                 $this->tpl->setVariable("TEXT_TYPE", $this->lng->txt("type"));
00259                 $this->tpl->setVariable("TEXT_TYPE_TERMS_PICTURES", $this->lng->txt("match_terms_and_pictures"));
00260                 $this->tpl->setVariable("TEXT_TYPE_TERMS_DEFINITIONS", $this->lng->txt("match_terms_and_definitions"));
00261                 if ($this->object->get_matching_type() == MT_TERMS_DEFINITIONS)
00262                 {
00263                         $this->tpl->setVariable("SELECTED_DEFINITIONS", " selected=\"selected\"");
00264                 }
00265                 elseif ($this->object->get_matching_type() == MT_TERMS_PICTURES)
00266                 {
00267                         $this->tpl->setVariable("SELECTED_PICTURES", " selected=\"selected\"");
00268                 }
00269                 $this->tpl->setVariable("TEXT_SOLUTION_HINT", $this->lng->txt("solution_hint"));
00270                 if (count($this->object->suggested_solutions))
00271                 {
00272                         $solution_array = $this->object->getSuggestedSolution(0);
00273                         $href = ASS_Question::_getInternalLinkHref($solution_array["internal_link"]);
00274                         $this->tpl->setVariable("TEXT_VALUE_SOLUTION_HINT", " <a href=\"$href\" target=\"content\">" . $this->lng->txt("solution_hint"). "</a> ");
00275                         $this->tpl->setVariable("BUTTON_REMOVE_SOLUTION", $this->lng->txt("remove"));
00276                         $this->tpl->setVariable("BUTTON_ADD_SOLUTION", $this->lng->txt("change"));
00277                         $this->tpl->setVariable("VALUE_SOLUTION_HINT", $solution_array["internal_link"]);
00278                 }
00279                 else
00280                 {
00281                         $this->tpl->setVariable("BUTTON_ADD_SOLUTION", $this->lng->txt("add"));
00282                 }
00283                 $this->tpl->setVariable("SAVE", $this->lng->txt("save"));
00284                 $this->tpl->setVariable("SAVE_EDIT", $this->lng->txt("save_edit"));
00285                 $this->tpl->setVariable("CANCEL", $this->lng->txt("cancel"));
00286                 $this->tpl->setVariable("TXT_REQUIRED_FLD", $this->lng->txt("required_field"));
00287                 $this->ctrl->setParameter($this, "sel_question_types", "qt_matching");
00288                 $this->tpl->setVariable("ACTION_MATCHING_QUESTION",     $this->ctrl->getFormAction($this));
00289 
00290                 $this->tpl->parseCurrentBlock();
00291                 if ($this->error)
00292                 {
00293                         sendInfo($this->error);
00294                 }
00295                 $this->tpl->setCurrentBlock("adm_content");
00296                 $this->tpl->setVariable("BODY_ATTRIBUTES", " onload=\"initialSelect();\""); 
00297                 $this->tpl->parseCurrentBlock();
00298         }
00299 
00307         function outOtherQuestionData()
00308         {
00309                 $this->tpl->setCurrentBlock("other_question_data");
00310                 $est_working_time = $this->object->getEstimatedWorkingTime();
00311                 $this->tpl->setVariable("TEXT_WORKING_TIME", $this->lng->txt("working_time"));
00312                 $this->tpl->setVariable("TIME_FORMAT", $this->lng->txt("time_format"));
00313                 $this->tpl->setVariable("VALUE_WORKING_TIME", ilUtil::makeTimeSelect("Estimated", false, $est_working_time[h], $est_working_time[m], $est_working_time[s]));
00314                 $this->tpl->parseCurrentBlock();
00315         }
00316 
00317 
00321         function addPair()
00322         {
00323                 $result = $this->writePostData();
00324                 $this->editQuestion($result);
00325         }
00326 
00330         function upload()
00331         {
00332                 $this->writePostData();
00333                 $this->editQuestion();
00334         }
00335 
00336 
00340         function delete()
00341         {
00342                 $this->writePostData();
00343 
00344                 // Delete a matching pair if the delete button was pressed
00345                 foreach ($_POST["cmd"] as $key => $value)
00346                 {
00347                         if (preg_match("/delete_(\d+)/", $key, $matches))
00348                         {
00349                                 $this->object->delete_matchingpair($matches[1]);
00350                         }
00351                 }
00352                 $this->editQuestion();
00353         }
00354 
00363         function writePostData()
00364         {
00365                 $saved = false;
00366                 $result = 0;
00367 
00368                 if (!$this->checkInput())
00369                 {
00370                         $result = 1;
00371                 }
00372 
00373                 if (($result) and ($_POST["cmd"]["addPair"]))
00374                 {
00375                         // You cannot add matching pairs before you enter the required data
00376                         $this->error .= $this->lng->txt("fill_out_all_required_fields_add_matching") . "<br />";
00377                 }
00378 
00379                 $this->object->setTitle(ilUtil::stripSlashes($_POST["title"]));
00380                 $this->object->setAuthor(ilUtil::stripSlashes($_POST["author"]));
00381                 $this->object->setComment(ilUtil::stripSlashes($_POST["comment"]));
00382                 $questiontext = ilUtil::stripSlashes($_POST["question"], true, "<strong><em><code><cite>");
00383                 $questiontext = preg_replace("/\n/", "<br />", $questiontext);
00384                 $this->object->set_question($questiontext);
00385                 $this->object->setSuggestedSolution($_POST["solution_hint"], 0);
00386                 $this->object->setShuffle($_POST["shuffle"]);
00387                 // adding estimated working time
00388                 $saved = $saved | $this->writeOtherPostData($result);
00389                 $this->object->set_matching_type($_POST["matching_type"]);
00390 
00391                 // Delete all existing answers and create new answers from the form data
00392                 $this->object->flush_matchingpairs();
00393                 $saved = false;
00394 
00395                 // Add all answers from the form into the object
00396                 foreach ($_POST as $key => $value)
00397                 {
00398                         $matching_text = "";
00399                         if (preg_match("/term_(\d+)_(\d+)/", $key, $matches))
00400                         {
00401                                 // find out random id for term
00402                                 foreach ($_POST as $key2 => $value2)
00403                                 {
00404                                         if (preg_match("/(definition|picture)_$matches[1]_(\d+)/", $key2, $matches2))
00405                                         {
00406                                                 $matchingtext_id = $matches2[2];
00407                                                 if (strcmp($matches2[1], "definition") == 0)
00408                                                 {
00409                                                         $matching_text = $_POST["definition_$matches[1]_$matches2[2]"];
00410                                                 }
00411                                                 else
00412                                                 {
00413                                                         $matching_text = $_POST["picture_$matches[1]_$matches2[2]"];
00414                                                 }
00415                                         }
00416                                 }
00417                                 
00418                                 // save picture file if matching terms and pictures
00419                                 if ($this->object->get_matching_type() == MT_TERMS_PICTURES)
00420                                 {
00421                                         foreach ($_FILES as $key2 => $value2)
00422                                         {
00423                                                 if (preg_match("/picture_$matches[1]_(\d+)/", $key2, $matches2))
00424                                                 {
00425                                                         if ($value2["tmp_name"])
00426                                                         {
00427                                                                 // upload the matching picture
00428                                                                 if ($this->object->getId() <= 0)
00429                                                                 {
00430                                                                         $this->object->saveToDb();
00431                                                                         $saved = true;
00432                                                                         $this->error .= $this->lng->txt("question_saved_for_upload") . "<br />";
00433                                                                 }
00434                                                                 $upload_result = $this->object->set_image_file($value2['name'], $value2['tmp_name']);
00435                                                                 switch ($upload_result)
00436                                                                 {
00437                                                                         case 0:
00438                                                                                 $_POST["picture_$matches[1]_".$matches2[1]] = $value2['name'];
00439                                                                                 $matching_text = $value2['name'];
00440                                                                                 break;
00441                                                                         case 1:
00442                                                                                 $this->error .= $this->lng->txt("error_image_upload_wrong_format") . "<br />";
00443                                                                                 break;
00444                                                                         case 2:
00445                                                                                 $this->error .= $this->lng->txt("error_image_upload_copy_file") . "<br />";
00446                                                                                 break;
00447                                                                 }
00448                                                         }
00449                                                 }
00450                                         }
00451                                 }
00452                                 $points = $_POST["points_$matches[1]"];
00453                                 if (preg_match("/\d+/", $points))
00454                                 {
00455                                         if ($points < 0)
00456                                         {
00457                                                 $points = 0.0;
00458                                                 $this->error .= $this->lng->txt("negative_points_not_allowed") . "<br />";
00459                                         }
00460                                 }
00461                                 else
00462                                 {
00463                                         $points = 0.0;
00464                                 }
00465                                 $this->object->add_matchingpair(
00466                                         ilUtil::stripSlashes($_POST["$key"]),
00467                                         ilUtil::stripSlashes($matching_text),
00468                                         ilUtil::stripSlashes($points),
00469                                         ilUtil::stripSlashes($matches[2]),
00470                                         ilUtil::stripSlashes($matchingtext_id)
00471                                 );
00472                         }
00473                 }
00474 
00475                 if ($saved)
00476                 {
00477                         // If the question was saved automatically before an upload, we have to make
00478                         // sure, that the state after the upload is saved. Otherwise the user could be
00479                         // irritated, if he presses cancel, because he only has the question state before
00480                         // the upload process.
00481                         $this->object->saveToDb();
00482                         $_GET["q_id"] = $this->object->getId();
00483                 }
00484                 return $result;
00485         }
00486 
00494         function outWorkingForm($test_id = "", $is_postponed = false, $showsolution = 0)
00495         {
00496                 global $ilUser;
00497                 $output = $this->outQuestionPage("MATCHING_QUESTION", $is_postponed);
00498                 $output = preg_replace("/&#123;/", "{", $output);
00499                 $output = preg_replace("/&#125;/", "}", $output);
00500                 if ($this->object->getOutputType() == OUTPUT_HTML)
00501                 {
00502                         $solutionoutput = preg_replace("/.*?(<div[^<]*?ilc_Question.*?<\/div>).*/", "\\1", $output);
00503                         $solutionoutput = preg_replace("/\"match/", "\"solution_match", $solutionoutput);
00504                         $solutionoutput = preg_replace("/name\=\"sel_matching/", "name=\"solution_sel_matching", $solutionoutput);
00505                 }
00506                 else
00507                 {
00508                         $solutionoutput = "<table border=\"0\">\n";
00509                 }
00510 
00511                 // set solutions
00512                 $solution_script = "";
00513                 if ($test_id)
00514                 {
00515                         $solutions =& $this->object->getSolutionValues($test_id);
00516                         $solution_script .= "";//"resetValues();\n";
00517                         foreach ($solutions as $idx => $solution_value)
00518                         {
00519                                 if ($this->object->getOutputType() == OUTPUT_HTML)
00520                                 {
00521                                         $repl_str = "dummy=\"match".$solution_value->value2."_".$solution_value->value1."\"";
00522                                         $output = str_replace($repl_str, $repl_str." selected=\"selected\"", $output);
00523                                 }
00524                                 else
00525                                 {
00526                                         $output = str_replace("initial_value_" . $solution_value->value2, $solution_value->value1, $output);
00527                                         if (($solution_value->value2 > 1) && ($solution_value->value1 > 1))
00528                                         {
00529                                                 $solution_script .= "dd.elements.definition_" . $solution_value->value2 . ".moveTo(dd.elements.term_" . $solution_value->value1 . ".defx + 250, dd.elements.term_" . $solution_value->value1 . ".defy);\n";
00530                                                 if ($this->object->get_matching_type() == MT_TERMS_DEFINITIONS)
00531                                                 {
00532                                                         foreach ($this->object->matchingpairs as $pdx => $pair)
00533                                                         {
00534                                                                 if ($pair->getDefinitionId() == $solution_value->value2)
00535                                                                 {
00536                                                                         $solution_script .= "dd.elements.definition_" . $solution_value->value2 . ".write(\"<strong>" . $pair->getDefinition() . "</strong>\");\n";
00537                                                                 }
00538                                                         }
00539                                                 }
00540                                         }
00541                                 }
00542                         }
00543                 }
00544                 if ($this->object->getOutputType() == OUTPUT_JAVASCRIPT)
00545                 {
00546                         $output = str_replace("// solution_script", "", $output);
00547                         $this->tpl->setVariable("JS_INITIALIZE", "<script type=\"text/javascript\">\nfunction show_solution() {\n$solution_script\n}\n</script>\n");
00548                         $this->tpl->setVariable("BODY_ATTRIBUTES", " onload=\"show_solution();\"");
00549                 }
00550                 
00551                 if ($this->object->getOutputType() == OUTPUT_HTML)
00552                 {
00553                         foreach ($this->object->matchingpairs as $idx => $answer)
00554                         {
00555                                 $id = $answer->getDefinitionId()."_".$answer->getTermId();
00556                                 $repl_str = "dummy=\"solution_match".$id."\"";
00557                                 $solutionoutput = str_replace($repl_str, $repl_str." selected=\"selected\"", $solutionoutput);
00558                                 $solutionoutput = preg_replace("/(<tr.*?dummy=\"solution_match$id.*?)<\/tr>/", "\\1<td>" . "<em>(" . $answer->getPoints() . " " . $this->lng->txt("points") . ")</em>" . "</td></tr>", $solutionoutput);
00559                         }
00560                 }
00561                 else
00562                 {
00563                         foreach ($this->object->matchingpairs as $idx => $answer)
00564                         {
00565                                 if ($this->object->get_matching_type() == MT_TERMS_PICTURES)
00566                                 {
00567                                         $imagepath = $this->object->getImagePathWeb() . $answer->getPicture();
00568                                         $solutionoutput .= "<tr><td><div class=\"textbox\">" . $answer->getTerm() . "</div></td><td width=\"10\"></td><td><div class=\"imagebox\"><img src=\"" . $imagepath . ".thumb.jpg\" /></div></td></tr>\n";
00569                                         $size = GetImageSize ($this->object->getImagePath() . $answer->getPicture() . ".thumb.jpg");
00570                                         $sizeorig = GetImageSize ($this->object->getImagePath() . $answer->getPicture());
00571                                         if ($size[0] >= $sizeorig[0])
00572                                         {
00573                                                 // thumbnail is larger than original -> remove enlarge image
00574                                                 $output = preg_replace("/<a[^>]*?>\s*<img[^>]*?enlarge[^>]*?>\s*<\/a>/", "", $output);
00575                                         }
00576                                         // add the image size to the thumbnails
00577                                         $output = preg_replace("/(<img[^>]*?".$answer->getPicture()."\.thumb\.jpg[^>]*?)(\/{0,1}\s*)?>/", "\\1 " . $size[3] . "\\2", $output);
00578                                 }
00579                                 else
00580                                 {
00581                                         $solutionoutput .= "<tr><td><div class=\"textbox\">" . $answer->getTerm() . "</div></td><td width=\"10\"></td><td><div class=\"textbox\"><strong>" . $answer->getDefinition() . "</strong></div></td></tr>\n";
00582                                 }
00583                         }
00584                         $solutionoutput .= "</table>";
00585                 }
00586                 $solutionoutput = "<p>" . $this->lng->txt("correct_solution_is") . ":</p><p>$solutionoutput</p>";
00587                 if ($test_id) 
00588                 {
00589                         $received_points = "<p>" . sprintf($this->lng->txt("you_received_a_of_b_points"), $this->object->getReachedPoints($ilUser->id, $test_id), $this->object->getMaximumPoints()) . "</p>";
00590                 }
00591                 if (!$showsolution)
00592                 {
00593                         $solutionoutput = "";
00594                         $received_points = "";
00595                 }
00596                 if ($this->object->get_matching_type() == MT_TERMS_PICTURES)
00597                 {
00598                         $this->tpl->setCurrentBlock("adm_content");
00599                         $output = str_replace("textbox", "textboximage", $output);
00600                         $solutionoutput = str_replace("textbox", "textboximage", $solutionoutput);
00601                 }
00602                 $this->tpl->setVariable("MATCHING_QUESTION", $output.$solutionoutput.$received_points);
00603         }
00604 
00612         function outUserSolution($user_id, $test_id)
00613         {
00614                 $results = $this->object->getReachedInformation($user_id, $test_id);
00615                 foreach ($results as $key => $value)
00616                 {
00617                         $this->tpl->setCurrentBlock("tablerow");
00618                         if ($value["true"])
00619                         {
00620                                 $this->tpl->setVariable("ANSWER_IMAGE", ilUtil::getImagePath("right.png", true));
00621                                 $this->tpl->setVariable("ANSWER_IMAGE_TITLE", $this->lng->txt("answer_is_right"));
00622                         }
00623                         else
00624                         {
00625                                 $this->tpl->setVariable("ANSWER_IMAGE", ilUtil::getImagePath("wrong.png", true));
00626                                 $this->tpl->setVariable("ANSWER_IMAGE_TITLE", $this->lng->txt("answer_is_wrong"));
00627                         }
00628                         $term = "";
00629                         $definition = "";
00630                         foreach ($this->object->matchingpairs as $answerkey => $answer)
00631                         {
00632                                 if ($answer->getDefinitionId() == $value["definition"])
00633                                 {
00634                                         $definition = $answer->getDefinition();
00635                                 }
00636                                 if ($answer->getTermId() == $value["term"])
00637                                 {
00638                                         $term = $answer->getTerm();
00639                                 }
00640                         }
00641                         if ($this->object->get_matching_type() == MT_TERMS_PICTURES)
00642                         {
00643                                 $definition = $this->lng->txt("selected_image");
00644                         }
00645                         $this->tpl->setVariable("ANSWER_DESCRIPTION", "&quot;<em>" . $definition . "</em>&quot; " . $this->lng->txt("matches") . " &quot;<em>" . $term . "</em>&quot;");
00646                         $this->tpl->parseCurrentBlock();
00647                 }
00648         }
00649         
00653         function checkInput()
00654         {
00655                 if ((!$_POST["title"]) or (!$_POST["author"]) or (!$_POST["question"]))
00656                 {
00657                         return false;
00658                 }
00659                 return true;
00660         }
00661 
00662 
00663         function addSuggestedSolution()
00664         {
00665                 $_SESSION["subquestion_index"] = 0;
00666                 if ($_POST["cmd"]["addSuggestedSolution"])
00667                 {
00668                         $this->writePostData();
00669                         if (!$this->checkInput())
00670                         {
00671                                 sendInfo($this->lng->txt("fill_out_all_required_fields_add_answer"));
00672                                 $this->editQuestion();
00673                                 return;
00674                         }
00675                 }
00676                 $this->object->saveToDb();
00677                 $_GET["q_id"] = $this->object->getId();
00678                 $this->tpl->setVariable("HEADER", $this->object->getTitle());
00679                 $this->getQuestionTemplate("qt_matching");
00680                 parent::addSuggestedSolution();
00681         }
00682 }
00683 ?>

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