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

assessment/classes/class.assClozeTestGUI.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 include_once "./assessment/classes/class.assQuestionGUI.php";
00025 
00037 class ASS_ClozeTestGUI extends ASS_QuestionGUI
00038 {
00047         function ASS_ClozeTestGUI(
00048                         $id = -1
00049         )
00050         {
00051                 $this->ASS_QuestionGUI();
00052                 include_once "./assessment/classes/class.assClozeTest.php";
00053                 $this->object = new ASS_ClozeTest();
00054                 if ($id >= 0)
00055                 {
00056                         $this->object->loadFromDb($id);
00057                 }
00058         }
00059 
00068         function getQuestionType()
00069         {
00070                 return "qt_cloze";
00071         }
00072 
00073 
00074         function getCommand($cmd)
00075         {
00076                 if (substr($cmd, 0, 6) == "delete")
00077                 {
00078                         $cmd = "delete";
00079                 }
00080                 if (substr($cmd, 0, 10) == "addTextGap")
00081                 {
00082                         $cmd = "addTextGap";
00083                 }
00084                 if (substr($cmd, 0, 12) == "addSelectGap")
00085                 {
00086                         $cmd = "addSelectGap";
00087                 }
00088                 if (substr($cmd, 0, 20) == "addSuggestedSolution")
00089                 {
00090                         $cmd = "addSuggestedSolution";
00091                 }
00092                 if (substr($cmd, 0, 23) == "removeSuggestedSolution")
00093                 {
00094                         $cmd = "removeSuggestedSolution";
00095                 }
00096 
00097                 return $cmd;
00098         }
00099 
00100 
00108         function editQuestion()
00109         {
00110                 include_once "./assessment/classes/class.assQuestion.php";
00111                 $internallinks = array(
00112                         "lm" => $this->lng->txt("obj_lm"),
00113                         "st" => $this->lng->txt("obj_st"),
00114                         "pg" => $this->lng->txt("obj_pg"),
00115                         "glo" => $this->lng->txt("glossary_term")
00116                 );
00117                 //$this->tpl->setVariable("HEADER", $this->object->getTitle());
00118                 $this->getQuestionTemplate("qt_cloze");
00119                 $this->tpl->addBlockFile("QUESTION_DATA", "question_data", "tpl.il_as_qpl_cloze_question.html", true);
00120                 for ($i = 0; $i < $this->object->get_gap_count(); $i++)
00121                 {
00122                         $gap = $this->object->get_gap($i);
00123                         if ($gap[0]->get_cloze_type() == CLOZE_TEXT)
00124                         {
00125                                 $this->tpl->setCurrentBlock("textgap_value");
00126                                 foreach ($gap as $key => $value)
00127                                 {
00128                                         $this->tpl->setVariable("TEXT_VALUE", $this->lng->txt("value"));
00129                                         $this->tpl->setVariable("VALUE_TEXT_GAP", htmlspecialchars($value->get_answertext()));
00130                                         $this->tpl->setVariable("VALUE_GAP_COUNTER", "$i" . "_" . "$key");
00131                                         $this->tpl->setVariable("VALUE_GAP", $i);
00132                                         $this->tpl->setVariable("VALUE_INDEX", $key);
00133                                         $this->tpl->setVariable("VALUE_STATUS_COUNTER", $key);
00134                                         $this->tpl->setVariable("VALUE_GAP", $i);
00135                                         $this->tpl->setVariable("TEXT_POINTS", $this->lng->txt("points"));
00136                                         $this->tpl->setVariable("VALUE_TEXT_GAP_POINTS", sprintf("%d", $value->get_points()));
00137                                         $this->tpl->setVariable("DELETE", $this->lng->txt("delete"));
00138                                         $this->tpl->parseCurrentBlock();
00139                                 }
00140 
00141                                 foreach ($internallinks as $key => $value)
00142                                 {
00143                                         $this->tpl->setCurrentBlock("textgap_internallink");
00144                                         $this->tpl->setVariable("TYPE_INTERNAL_LINK", $key);
00145                                         $this->tpl->setVariable("TEXT_INTERNAL_LINK", $value);
00146                                         $this->tpl->parseCurrentBlock();
00147                                 }
00148 
00149                                 $this->tpl->setCurrentBlock("textgap_suggested_solution");
00150                                 $this->tpl->setVariable("TEXT_SOLUTION_HINT", $this->lng->txt("solution_hint"));
00151                                 if (array_key_exists($i, $this->object->suggested_solutions))
00152                                 {
00153                                         $solution_array = $this->object->getSuggestedSolution($i);
00154                                         $href = ASS_Question::_getInternalLinkHref($solution_array["internal_link"]);
00155                                         $this->tpl->setVariable("TEXT_VALUE_SOLUTION_HINT", " <a href=\"$href\" target=\"content\">" . $this->lng->txt("solution_hint"). "</a> ");
00156                                         $this->tpl->setVariable("BUTTON_REMOVE_SOLUTION", $this->lng->txt("remove"));
00157                                         $this->tpl->setVariable("VALUE_GAP_COUNTER_REMOVE", $i);
00158                                         $this->tpl->setVariable("BUTTON_ADD_SOLUTION", $this->lng->txt("change"));
00159                                         $this->tpl->setVariable("VALUE_SOLUTION_HINT", $solution_array["internal_link"]);
00160                                 }
00161                                 else
00162                                 {
00163                                         $this->tpl->setVariable("BUTTON_ADD_SOLUTION", $this->lng->txt("add"));
00164                                 }
00165                                 $this->tpl->setVariable("VALUE_GAP_COUNTER", $i);
00166                                 $this->tpl->parseCurrentBlock();
00167                                 $this->tpl->setCurrentBlock("textgap");
00168                                 $this->tpl->setVariable("ADD_TEXT_GAP", $this->lng->txt("add_gap"));
00169                                 $this->tpl->setVariable("VALUE_GAP_COUNTER", "$i");
00170                                 $this->tpl->parseCurrentBlock();
00171                         }
00172                         elseif ($gap[0]->get_cloze_type() == CLOZE_SELECT)
00173                         {
00174                                 $this->tpl->setCurrentBlock("selectgap_value");
00175                                 foreach ($gap as $key => $value)
00176                                 {
00177                                         $this->tpl->setVariable("TEXT_VALUE", $this->lng->txt("value"));
00178                                         $this->tpl->setVariable("VALUE_SELECT_GAP", htmlspecialchars($value->get_answertext()));
00179                                         $this->tpl->setVariable("VALUE_GAP_COUNTER", "$i" . "_" . "$key");
00180                                         $this->tpl->setVariable("VALUE_GAP", $i);
00181                                         $this->tpl->setVariable("VALUE_INDEX", $key);
00182                                         $this->tpl->setVariable("VALUE_STATUS_COUNTER", $key);
00183                                         $this->tpl->setVariable("VALUE_GAP", $i);
00184                                         $this->tpl->setVariable("TEXT_POINTS", $this->lng->txt("points"));
00185                                         $this->tpl->setVariable("VALUE_SELECT_GAP_POINTS", sprintf("%d", $value->get_points()));
00186                                         $this->tpl->setVariable("DELETE", $this->lng->txt("delete"));
00187                                         $this->tpl->parseCurrentBlock();
00188                                 }
00189 
00190                                 foreach ($internallinks as $key => $value)
00191                                 {
00192                                         $this->tpl->setCurrentBlock("selectgap_internallink");
00193                                         $this->tpl->setVariable("TYPE_INTERNAL_LINK", $key);
00194                                         $this->tpl->setVariable("TEXT_INTERNAL_LINK", $value);
00195                                         $this->tpl->parseCurrentBlock();
00196                                 }
00197 
00198                                 $this->tpl->setCurrentBlock("selectgap_suggested_solution");
00199                                 $this->tpl->setVariable("TEXT_SOLUTION_HINT", $this->lng->txt("solution_hint"));
00200                                 if (array_key_exists($i, $this->object->suggested_solutions))
00201                                 {
00202                                         $solution_array = $this->object->getSuggestedSolution($i);
00203                                         $href = ASS_Question::_getInternalLinkHref($solution_array["internal_link"]);
00204                                         $this->tpl->setVariable("TEXT_VALUE_SOLUTION_HINT", " <a href=\"$href\" target=\"content\">" . $this->lng->txt("solution_hint"). "</a> ");
00205                                         $this->tpl->setVariable("BUTTON_REMOVE_SOLUTION", $this->lng->txt("remove"));
00206                                         $this->tpl->setVariable("VALUE_GAP_COUNTER_REMOVE", $i);
00207                                         $this->tpl->setVariable("BUTTON_ADD_SOLUTION", $this->lng->txt("change"));
00208                                         $this->tpl->setVariable("VALUE_SOLUTION_HINT", $solution_array["internal_link"]);
00209                                 }
00210                                 else
00211                                 {
00212                                         $this->tpl->setVariable("BUTTON_ADD_SOLUTION", $this->lng->txt("add"));
00213                                 }
00214                                 $this->tpl->setVariable("VALUE_GAP_COUNTER", $i);
00215                                 $this->tpl->parseCurrentBlock();
00216                                 $this->tpl->setCurrentBlock("selectgap");
00217                                 $this->tpl->setVariable("ADD_SELECT_GAP", $this->lng->txt("add_gap"));
00218                                 $this->tpl->setVariable("TEXT_SHUFFLE_ANSWERS", $this->lng->txt("shuffle_answers"));
00219                                 $this->tpl->setVariable("VALUE_GAP_COUNTER", "$i");
00220                                 if ($gap[0]->get_shuffle())
00221                                 {
00222                                         $this->tpl->setVariable("SELECTED_YES", " selected=\"selected\"");
00223                                 }
00224                                 else
00225                                 {
00226                                         $this->tpl->setVariable("SELECTED_NO", " selected=\"selected\"");
00227                                 }
00228                                 $this->tpl->setVariable("TXT_YES", $this->lng->txt("yes"));
00229                                 $this->tpl->setVariable("TXT_NO", $this->lng->txt("no"));
00230                                 $this->tpl->parseCurrentBlock();
00231                         }
00232                         $this->tpl->setCurrentBlock("answer_row");
00233                         $name = $gap[0]->get_name();
00234                         if (!$name)
00235                         {
00236                                 $name = $this->lng->txt("gap") . " " . ($i+1);
00237                         }
00238                         $this->tpl->setVariable("TEXT_GAP_NAME", $name);
00239                         $this->tpl->setVariable("TEXT_TYPE", $this->lng->txt("type"));
00240                         if ($gap[0]->get_cloze_type() == CLOZE_SELECT)
00241                         {
00242                                 $this->tpl->setVariable("SELECTED_SELECT_GAP", " selected=\"selected\"");
00243                         }
00244                         else
00245                         {
00246                                 $this->tpl->setVariable("SELECTED_TEXT_GAP", " selected=\"selected\"");
00247                         }
00248                         $this->tpl->setVariable("TEXT_TEXT_GAP", $this->lng->txt("text_gap"));
00249                         $this->tpl->setVariable("TEXT_SELECT_GAP", $this->lng->txt("select_gap"));
00250                         $this->tpl->setVariable("VALUE_GAP_COUNTER", $i);
00251                         $this->tpl->parseCurrentBlock();
00252                 }
00253 
00254                 // call to other question data i.e. estimated working time block
00255                 $this->outOtherQuestionData();
00256 
00257                 $this->tpl->setCurrentBlock("HeadContent");
00258                 $javascript = "<script type=\"text/javascript\">function initialSelect() {\n%s\n}</script>";
00259                 if (preg_match("/addTextGap_(\d+)/", $this->ctrl->getCmd(), $matches))
00260                 {
00261                         $this->tpl->setVariable("CONTENT_BLOCK", sprintf($javascript, "document.frm_cloze_test.textgap_" . $matches[1] . "_" .(count($this->object->gaps[$matches[1]]) - 1).".focus(); document.frm_cloze_test.textgap_" . $matches[1] . "_" .(count($this->object->gaps[$matches[1]]) - 1).".scrollIntoView(\"true\");"));
00262                 }
00263                 else if (preg_match("/addSelectGap_(\d+)/", $this->ctrl->getCmd(), $matches))
00264                 {
00265                         $this->tpl->setVariable("CONTENT_BLOCK", sprintf($javascript, "document.frm_cloze_test.selectgap_" . $matches[1] . "_" .(count($this->object->gaps[$matches[1]]) - 1).".focus(); document.frm_cloze_test.selectgap_" . $matches[1] . "_" .(count($this->object->gaps[$matches[1]]) - 1).".scrollIntoView(\"true\");"));
00266                 }
00267                 else
00268                 {
00269                         $this->tpl->setVariable("CONTENT_BLOCK", sprintf($javascript, "document.frm_cloze_test.title.focus();"));
00270                 }
00271                 $this->tpl->parseCurrentBlock();
00272                 
00273                 // Add textgap rating options
00274                 $textgap_options = array(
00275                         array("ci", $this->lng->txt("cloze_textgap_case_insensitive")),
00276                         array("cs", $this->lng->txt("cloze_textgap_case_sensitive")),
00277                         array("l1", sprintf($this->lng->txt("cloze_textgap_levenshtein_of"), "1")),
00278                         array("l2", sprintf($this->lng->txt("cloze_textgap_levenshtein_of"), "2")),
00279                         array("l3", sprintf($this->lng->txt("cloze_textgap_levenshtein_of"), "3")),
00280                         array("l4", sprintf($this->lng->txt("cloze_textgap_levenshtein_of"), "4")),
00281                         array("l5", sprintf($this->lng->txt("cloze_textgap_levenshtein_of"), "5"))
00282                 );
00283                 $textgap_rating = $this->object->getTextgapRating();
00284                 foreach ($textgap_options as $textgap_option)
00285                 {
00286                         $this->tpl->setCurrentBlock("textgap_rating");
00287                         $this->tpl->setVariable("TEXTGAP_VALUE", $textgap_option[0]);
00288                         $this->tpl->setVariable("TEXTGAP_TEXT", $textgap_option[1]);
00289                         if (strcmp($textgap_rating, $textgap_option[0]) == 0)
00290                         {
00291                                 $this->tpl->setVariable("SELECTED_TEXTGAP_VALUE", " selected=\"selected\"");
00292                         }
00293                         $this->tpl->parseCurrentBlock();
00294                 }
00295                 
00296                 $this->tpl->setCurrentBlock("question_data");
00297                 $this->tpl->setVariable("VALUE_CLOZE_TITLE", htmlspecialchars($this->object->getTitle()));
00298                 $this->tpl->setVariable("VALUE_CLOZE_COMMENT", htmlspecialchars($this->object->getComment()));
00299                 $this->tpl->setVariable("VALUE_CLOZE_AUTHOR", htmlspecialchars($this->object->getAuthor()));
00300                 $cloze_text = $this->object->get_cloze_text();
00301                 $cloze_text = preg_replace("/<br \/>/", "\n", $cloze_text);
00302                 $this->tpl->setVariable("VALUE_CLOZE_TEXT", $cloze_text);
00303                 $this->tpl->setVariable("TEXT_CREATE_GAPS", $this->lng->txt("create_gaps"));
00304                 $this->tpl->setVariable("CLOZE_ID", $this->object->getId());
00305 
00306                 $this->tpl->setVariable("TEXT_TITLE", $this->lng->txt("title"));
00307                 $this->tpl->setVariable("TEXT_AUTHOR", $this->lng->txt("author"));
00308                 $this->tpl->setVariable("TEXT_COMMENT", $this->lng->txt("description"));
00309                 $this->tpl->setVariable("TEXT_CLOZE_TEXT", $this->lng->txt("cloze_text"));
00310                 $this->tpl->setVariable("TEXT_CLOSE_HINT", htmlspecialchars($this->lng->txt("close_text_hint")));
00311                 $this->tpl->setVariable("TEXTGAP_RATING", $this->lng->txt("cloze_textgap_rating"));
00312                 $this->tpl->setVariable("TEXT_GAP_DEFINITION", $this->lng->txt("gap_definition"));
00313                 $this->tpl->setVariable("SAVE",$this->lng->txt("save"));
00314                 $this->tpl->setVariable("SAVE_EDIT", $this->lng->txt("save_edit"));
00315                 $this->tpl->setVariable("CANCEL",$this->lng->txt("cancel"));
00316                 $this->ctrl->setParameter($this, "sel_question_types", "qt_cloze");
00317                 $this->tpl->setVariable("TEXT_QUESTION_TYPE", $this->lng->txt("qt_cloze"));
00318                 $this->tpl->setVariable("ACTION_CLOZE_TEST", $this->ctrl->getFormAction($this));
00319                 $this->tpl->setVariable("TXT_REQUIRED_FLD", $this->lng->txt("required_field"));
00320                 $this->tpl->parseCurrentBlock();
00321 
00322                 $this->tpl->setCurrentBlock("adm_content");
00323                 $this->tpl->setVariable("BODY_ATTRIBUTES", " onload=\"initialSelect();\""); 
00324                 $this->tpl->parseCurrentBlock();
00325         }
00326 
00334         function outOtherQuestionData()
00335         {
00336                 $colspan = " colspan=\"4\"";
00337 
00338                 $this->tpl->setCurrentBlock("other_question_data");
00339                 $est_working_time = $this->object->getEstimatedWorkingTime();
00340                 $this->tpl->setVariable("TEXT_WORKING_TIME", $this->lng->txt("working_time"));
00341                 $this->tpl->setVariable("TIME_FORMAT", $this->lng->txt("time_format"));
00342                 $this->tpl->setVariable("VALUE_WORKING_TIME", ilUtil::makeTimeSelect("Estimated", false, $est_working_time[h], $est_working_time[m], $est_working_time[s]));
00343                 $this->tpl->parseCurrentBlock();
00344         }
00345 
00354         function writePostData()
00355         {
00356                 $result = 0;
00357                 $saved = false;
00358 
00359                 // Delete all existing gaps and create new gaps from the form data
00360                 $this->object->flush_gaps();
00361 
00362                 if (!$this->checkInput())
00363                 {
00364                         $result = 1;
00365                 }
00366 
00367                 if (($result) and ($_POST["cmd"]["add"]))
00368                 {
00369                         // You cannot create gaps before you enter the required data
00370                         sendInfo($this->lng->txt("fill_out_all_required_fields_create_gaps"));
00371                         $_POST["cmd"]["add"] = "";
00372                 }
00373 
00374                 $this->object->setTitle(ilUtil::stripSlashes($_POST["title"]));
00375                 $this->object->setAuthor(ilUtil::stripSlashes($_POST["author"]));
00376                 $this->object->setComment(ilUtil::stripSlashes($_POST["comment"]));
00377                 $this->object->setTextgapRating($_POST["textgap_rating"]);
00378                 $cloze_text = ilUtil::stripSlashes($_POST["clozetext"], true, "<strong><em><code><cite><gap>");
00379                 $cloze_text = preg_replace("/\n/", "<br />", $cloze_text);
00380                 $this->object->set_cloze_text($cloze_text);
00381                 // adding estimated working time
00382                 $saved = $saved | $this->writeOtherPostData($result);
00383                 $this->object->suggested_solutions = array();
00384                 foreach ($_POST as $key => $value)
00385                 {
00386                         if (preg_match("/^solution_hint_(\d+)/", $key, $matches))
00387                         {
00388                                 if ($value)
00389                                 {
00390                                         $this->object->setSuggestedSolution($value, $matches[1]);
00391                                 }
00392                         }
00393                 }
00394                 
00395                 if ($this->ctrl->getCmd() != "createGaps")
00396                 {
00397                         $this->setGapValues();
00398                         $this->setShuffleState();
00399 
00400                         foreach ($_POST as $key => $value)
00401                         {
00402                                 // Set the cloze type of the gap
00403                                 if (preg_match("/clozetype_(\d+)/", $key, $matches))
00404                                 {
00405                                         $this->object->set_cloze_type($matches[1], $value);
00406                                 }
00407                         }
00408                 }
00409 
00410                 $this->object->update_all_gap_params();
00411                 if ($saved)
00412                 {
00413                         // If the question was saved automatically before an upload, we have to make
00414                         // sure, that the state after the upload is saved. Otherwise the user could be
00415                         // irritated, if he presses cancel, because he only has the question state before
00416                         // the upload process.
00417                         $this->object->saveToDb();
00418                         $_GET["q_id"] = $this->object->getId();
00419                 }
00420                 return $result;
00421         }
00422 
00426         function delete()
00427         {
00428                 $this->writePostData();
00429                 foreach ($_POST["cmd"] as $key => $value)
00430                 {
00431                         // Check, if one of the gap values was deleted
00432                         if (preg_match("/delete_(\d+)_(\d+)/", $key, $matches))
00433                         {
00434                                 $selectgap = "selectgap_" . $matches[1] . "_" . $matches[2];
00435                                 $this->object->delete_answertext_by_index($matches[1], $matches[2]);
00436                         }
00437                 }
00438                 $this->editQuestion();
00439         }
00440 
00441         function addSelectGap()
00442         {
00443                 $this->writePostData();
00444 
00445                 $len = strlen("addSelectGap_");
00446                 $i = substr($this->ctrl->getCmd(), $len);
00447                 $this->object->set_answertext(
00448                         ilUtil::stripSlashes($i),
00449                         ilUtil::stripSlashes($this->object->get_gap_text_count($i)),
00450                         "",
00451                         1
00452                 );
00453 
00454                 $this->editQuestion();
00455         }
00456 
00457         function addTextGap()
00458         {
00459                 $this->writePostData();
00460 
00461                 $len = strlen("addTextGap_");
00462                 $i = substr($this->ctrl->getCmd(), $len);
00463                 $this->object->set_answertext(
00464                         ilUtil::stripSlashes($i),
00465                         ilUtil::stripSlashes($this->object->get_gap_text_count($i)),
00466                         "",
00467                         1
00468                 );
00469 
00470                 $this->editQuestion();
00471         }
00472 
00473         function setGapValues($a_apply_text = true)
00474         {
00475 //echo "<br>SETGapValues:$a_apply_text:";
00476                 foreach ($_POST as $key => $value)
00477                 {
00478                         // Set gap values
00479                         if (preg_match("/textgap_(\d+)_(\d+)/", $key, $matches))
00480                         {
00481                                 $answer_array = $this->object->get_gap($matches[1]);
00482                                 if (strlen($value) > 0)
00483                                 {
00484                                         // Only change gap values <> empty string
00485                                         if (array_key_exists($matches[2], $answer_array))
00486                                         {
00487                                                 if ($a_apply_text)
00488                                                 {
00489                                                         if (strcmp($value, $answer_array[$matches[2]]->get_answertext()) != 0)
00490                                                         {
00491                                                                 $this->object->set_answertext(
00492                                                                         ilUtil::stripSlashes($matches[1]),
00493                                                                         ilUtil::stripSlashes($matches[2]),
00494                                                                         ilUtil::stripSlashes($value)
00495                                                                 );
00496                                                         }
00497                                                         if (preg_match("/\d+/", $_POST["points_$matches[1]_$matches[2]"]))
00498                                                         {
00499                                                                 $points = $_POST["points_$matches[1]_$matches[2]"];
00500                                                                 if ($points < 0)
00501                                                                 {
00502                                                                         $points = 0.0;
00503                                                                         sendInfo($this->lng->txt("negative_points_not_allowed"), true);
00504                                                                 }
00505                                                         }
00506                                                         else
00507                                                         {
00508                                                                 $points = 0.0;
00509                                                         }
00510                                                         $this->object->set_single_answer_points($matches[1], $matches[2], $points);
00511                                                         $this->object->set_single_answer_state($matches[1], $matches[2], 1);
00512                                                 }
00513                                                 else
00514                                                 {
00515                                                         if (strcmp($value, $answer_array[$matches[2]]->get_answertext()) == 0)
00516                                                         {
00517                                                                 $points = $_POST["points_$matches[1]_$matches[2]"];
00518                                                                 if ($points < 0)
00519                                                                 {
00520                                                                         $points = 0.0;
00521                                                                         sendInfo($this->lng->txt("negative_points_not_allowed"), true);
00522                                                                 }
00523                                                                 $this->object->set_single_answer_points($matches[1], $matches[2], $points);
00524                                                                 $this->object->set_single_answer_state($matches[1], $matches[2], 1);
00525                                                         }
00526                                                 }
00527                                         }
00528                                 }
00529                                 else
00530                                 {
00531                                         // Display errormessage: You've tried to set an gap value to an empty string!
00532                                 }
00533                         }
00534 
00535                         if (preg_match("/selectgap_(\d+)_(\d+)/", $key, $matches))
00536                         {
00537                                 $answer_array = $this->object->get_gap($matches[1]);
00538                                 if (strlen($value) > 0)
00539                                 {
00540                                         // Only change gap values <> empty string
00541                                         if (array_key_exists($matches[2], $answer_array))
00542                                         {
00543                                                 if (strcmp($value, $answer_array[$matches[2]]->get_answertext()) != 0)
00544                                                 {
00545                                                         if ($a_apply_text)
00546                                                         {
00547                                                                 $this->object->set_answertext(
00548                                                                         ilUtil::stripSlashes($matches[1]),
00549                                                                         ilUtil::stripSlashes($matches[2]),
00550                                                                         ilUtil::stripSlashes($value)
00551                                                                 );
00552                                                         }
00553                                                 }
00554                                                 if (preg_match("/\d+/", $_POST["points_$matches[1]_$matches[2]"]))
00555                                                 {
00556                                                         $points = $_POST["points_$matches[1]_$matches[2]"];
00557                                                         if ($points < 0)
00558                                                         {
00559                                                                 $points = 0.0;
00560                                                                 sendInfo($this->lng->txt("negative_points_not_allowed"), true);
00561                                                         }
00562                                                 }
00563                                                 else
00564                                                 {
00565                                                         $points = 0.0;
00566                                                 }
00567                                                 $this->object->set_single_answer_points($matches[1], $matches[2], $points);
00568                                                 $this->object->set_single_answer_state($matches[1], $matches[2], 1);
00569                                         }
00570                                 }
00571                                 else
00572                                 {
00573                                         // Display errormessage: You've tried to set an gap value to an empty string!
00574                                 }
00575                         }
00576                 }
00577         }
00578 
00579         function setShuffleState()
00580         {
00581                 foreach ($_POST as $key => $value)
00582                 {
00583                         // Set select gap shuffle state
00584                         if (preg_match("/^shuffle_(\d+)$/", $key, $matches))
00585                         {
00586                                 $this->object->set_gap_shuffle($matches[1], $value);
00587                         }
00588                 }
00589         }
00590 
00594         function createGaps()
00595         {
00596                 $this->writePostData();
00597 
00598                 $this->setGapValues(false);
00599                 $this->setShuffleState();
00600                 $this->object->update_all_gap_params();
00601                 $this->editQuestion();
00602         }
00603 
00604 
00620         function outWorkingForm(
00621                 $test_id = "", 
00622                 $is_postponed = false, 
00623                 $showsolution = 0, 
00624                 $show_question_page = true, 
00625                 $show_solution_only = false, 
00626                 $ilUser = null, 
00627                 $pass = NULL, 
00628                 $mixpass = false
00629         )
00630         {
00631                 if (!is_object($ilUser)) 
00632                 {
00633                         global $ilUser;
00634                 }
00635                 
00636                 $output = $this->outQuestionPage(($show_solution_only)?"":"CLOZE_TEST", $is_postponed, $test_id);
00637                 
00638                 if ($showsolution && !$show_solution_only)
00639                 {
00640                         $solutionintroduction = "<p>" . $this->lng->txt("tst_your_answer_was") . "</p>";
00641                         $output = preg_replace("/(<div[^<]*?ilc_PageTitle.*?<\/div>)/", "\\1" . $solutionintroduction, $output);
00642                 }
00643                 $solutionoutput = preg_replace("/.*?(<div[^<]*?ilc_Question.*?<\/div>).*/", "\\1", $output);
00644                 $solutionoutput = preg_replace("/\"tgap/", "\"solution_tgap", $solutionoutput);
00645                 $solutionoutput = preg_replace("/\"sgap/", "\"solution_sgap", $solutionoutput);
00646                 $solutionoutput = preg_replace("/name=\"gap/", "name=\"solution_gap", $solutionoutput);
00647                 
00648                 // if wants question only then strip everything around question element
00649                 if (!$show_question_page) 
00650                 {
00651                         $output = preg_replace("/.*?(<div[^<]*?ilc_Question.*?<\/div>).*/", "\\1", $output);
00652                 }
00653                 
00654                 // if wants solution only then strip the question element from output
00655                 if ($show_solution_only) 
00656                 {
00657                         $output = preg_replace("/(<div[^<]*?ilc_Question[^>]*>.*?<\/div>)/", "", $output);
00658                 }
00659 
00660                 // set solutions
00661                 if ($test_id)
00662                 {
00663                         $solutions = NULL;
00664                         include_once "./assessment/classes/class.ilObjTest.php";
00665                         if ((!$showsolution) && ilObjTest::_getHidePreviousResults($test_id, true))
00666                         {
00667                                 if ($show_question_page)
00668                                 {
00669                                         if (is_null($pass)) $pass = ilObjTest::_getPass($ilUser->id, $test_id);
00670                                 }
00671                         }
00672                         if ($mixpass) $pass = NULL;
00673                         $solutions =& $this->object->getSolutionValues($test_id, $ilUser, $pass);
00674         
00675                         if (is_array($solutions)) 
00676                         {
00677                                 foreach ($solutions as $idx => $solution_value)
00678                                 {
00679                                         // text gaps
00680                                         
00681                                         $repl_str = "dummy=\"tgap_".$solution_value["value1"]."\"";
00682                                         //
00683                                         if (!$show_question_page)
00684                                         {
00685                                                 $output = $this->replaceInputElements($repl_str, $solution_value["value2"], $output,"[","]");                                           
00686                                         }
00687                                         else 
00688                                                 $output = str_replace($repl_str, $repl_str." value=\"".ilUtil::prepareFormOutput($solution_value["value2"])."\"", $output);
00689                                         
00690                                         // select gaps
00691                                         $repl_str = "dummy=\"sgap_".$solution_value["value1"]."_".$solution_value["value2"]."\"";
00692                                         
00693                                         if (!$show_question_page) 
00694                                         {
00695                                                 $output = $this->replaceSelectElements("gap_".$solution_value["value1"], $repl_str, $output,"[","]"); 
00696                                         } else 
00697                                                 $output = str_replace($repl_str, $repl_str." selected=\"selected\"", $output);
00698                                         //echo "<br>".$repl_str;
00699                                 }
00700                         }
00701                         // now replace all empty inputs and selects with an []
00702                         if (!$show_question_page) 
00703                         {
00704                                 $output = $this->removeFormElements($output);
00705                         }
00706                 }
00707 
00708                 if($showsolution)
00709                 {                       
00710                                                 
00711                         foreach ($this->object->gaps as $idx => $gap)
00712                         {
00713                                 $solution_value = "";
00714                                 if (is_array($solutions)) 
00715                                 {
00716                                         foreach ($solutions as $solidx => $solvalue)
00717                                         {
00718                                                 if ($solvalue["value1"] == $idx)
00719                                                 {
00720                                                         $solution_value = $solvalue["value2"];
00721                                                 }
00722                                         }
00723                                 }
00724                                 if ($gap[0]->get_cloze_type() == CLOZE_SELECT)
00725                                 {
00726                                         $maxpoints = 0;
00727                                         $maxindex = -1;
00728                                         $sol_points = array();
00729                                         foreach ($gap as $answeridx => $answer)
00730                                         {
00731                                                 if ($answer->get_points() > $maxpoints)
00732                                                 {
00733                                                         $maxpoints = $answer->get_points();
00734                                                         $maxindex = $answeridx;
00735                                                 }
00736                                                 if ($show_solution_only && $answer->get_points()>0) 
00737                                                 {                                                       
00738                                                         $regexp = "/<select name=\"solution_gap_$idx\">.*?<option[^>]*dummy=\"solution_sgap_".$idx."_".$answeridx."\">(.*?)<\/option>.*?<\/select>/";
00739                                                         preg_match ($regexp, $solutionoutput, $matches);
00740                                                         $sol_points [] = $matches[1]." <em>(".$answer->get_points()." ".$this->lng->txt("points_short").")</em>";
00741                                                 }
00742                                         }
00743                                                                                                                         
00744                                         if ($this->object->suggested_solutions[$idx])
00745                                         {
00746                                                 if ($showsolution)
00747                                                 {
00748                                                         $href = $this->object->_getInternalLinkHref($this->object->suggested_solutions[$idx]["internal_link"]);
00749                                                         $output = preg_replace("/(<select name\=\"gap_$idx\">.*?<\/select>)/is", "\\1" . " [<a href=\"$href\" target=\"_blank\">".$this->lng->txt("solution_hint")."</a>] " , $output);
00750                                                 }
00751                                         }
00752                                         
00753                                         if (count ($sol_points)<=1)
00754                                                 $solutionoutput = preg_replace("/(<select name\=\"solution_gap_$idx\">.*?<\/select>)/is", "\\1" . " <em>(" . $maxpoints . " " . $this->lng->txt("points") . ")</em> " , $solutionoutput);
00755                                         
00756                                         if ($maxindex > -1)
00757                                         {
00758                                                 $repl_str = "dummy=\"solution_sgap_$idx" . "_$maxindex\"";
00759                                                 if (!$show_solution_only)
00760                                                         $solutionoutput = str_replace($repl_str, $repl_str." selected=\"selected\"", $solutionoutput);
00761                                                 else 
00762                                                 {
00763                                                         if (count ($sol_points)>1) 
00764                                                         {
00765                                                                 $solutionoutput = preg_replace ("/<select[^>]*name=\"solution_gap_$idx\">.*?<\/select>/i","<span class=\"textanswer\">[".join($sol_points,", ")."]</span>",$solutionoutput); 
00766                                                         } else 
00767                                                                 $solutionoutput = $this->replaceSelectElements("solution_gap_$idx",$repl_str, $solutionoutput,"[","]" );
00768                                                 }
00769                                         }
00770                                         
00771                                 }
00772                                 else
00773                                 {
00774                                         
00775                                         $repl_str = "dummy=\"solution_tgap_$idx\"";                                     
00776                                         $pvals = array();
00777                                         foreach ($gap as $answeridx => $answer)
00778                                         {
00779                                                 array_push($pvals, $answer->get_answertext());
00780                                         }
00781                                         $possible_values = join($pvals, " " . $this->lng->txt("or") . " ");
00782                                         
00783                                         $solutionoutput = preg_replace("/(<input[^<]*?dummy\=\"solution_tgap_$idx\"" . "[^>]*?>)/i", "\\1" . " <em>(" . $gap[0]->get_points() . " " . $this->lng->txt("points") . ")</em> ", $solutionoutput);
00784                                         
00785                                         if ($this->object->suggested_solutions[$idx])
00786                                         {
00787                                                 if ($showsolution)
00788                                                 {
00789                                                         $href = $this->object->_getInternalLinkHref($this->object->suggested_solutions[$idx]["internal_link"]);
00790                                                         $output = preg_replace("/(<input[^<]*?dummy\=\"tgap_$idx\"" . "[^>]*?>)/is", "\\1" . " [<a href=\"$href\" target=\"_blank\">".$this->lng->txt("solution_hint")."</a>] " , $output);
00791                                                 }
00792                                         }
00793                                          
00794                                         if (!$show_solution_only)
00795                                                 $solutionoutput = str_replace($repl_str, $repl_str." value=\"$possible_values\"", $solutionoutput);
00796                                         else 
00797                                                 $solutionoutput = $this->replaceInputElements($repl_str, $possible_values, $solutionoutput,"[","]");                                    
00798                                 }
00799                         }
00800         
00801                         if (!$show_solution_only)
00802                         {
00803                                 $solutionoutput = "<p>" . $this->lng->txt("correct_solution_is") . ":</p><p>$solutionoutput</p>";
00804                         }
00805 
00806                         if ($test_id) 
00807                         {
00808                                 $reached_points = $this->object->getReachedPoints($ilUser->id, $test_id);
00809                                 $received_points = "<p>" . sprintf($this->lng->txt("you_received_a_of_b_points"), $reached_points, $this->object->getMaximumPoints());
00810                                 $count_comment = "";
00811                                 if ($reached_points == 0)
00812                                 {
00813                                         $count_comment = $this->object->getSolutionCommentCountSystem($test_id);
00814                                         if (strlen($count_comment))
00815                                         {
00816                                                 if (strlen($mc_comment) == 0)
00817                                                 {
00818                                                         $count_comment = "<span class=\"asterisk\">*</span><br /><br /><span class=\"asterisk\">*</span>$count_comment";
00819                                                 }
00820                                                 else
00821                                                 {
00822                                                         $count_comment = "<br /><span class=\"asterisk\">*</span>$count_comment";
00823                                                 }
00824                                         }
00825                                 }
00826                                 $received_points .= $count_comment;
00827                                 $received_points .= "</p>";
00828                         }
00829                         if ($show_solution_only== true) 
00830                         {
00831                                 $received_points = "";
00832                         }
00833                 }
00834                 if (!$showsolution) 
00835                 {
00836                         $solutionoutput="";
00837                         $received_points = "";
00838                 }
00839                 
00840                 $this->tpl->setVariable("CLOZE_TEST", $output.$solutionoutput.$received_points);
00841                 return;
00842         }
00843 
00847         function checkInput()
00848         {
00849                 if ((!$_POST["title"]) or (!$_POST["author"]) or (!$_POST["clozetext"]))
00850                 {
00851                         return false;
00852                 }
00853                 return true;
00854         }
00855 
00856 
00857         function addSuggestedSolution()
00858         {
00859                 $addForGap = -1;
00860                 if (array_key_exists("cmd", $_POST))
00861                 {
00862                         foreach ($_POST["cmd"] as $key => $value)
00863                         {
00864                                 if (preg_match("/addSuggestedSolution_(\d+)/", $key, $matches))
00865                                 {
00866                                         $addForGap = $matches[1];
00867                                 }
00868                         }
00869                 }
00870                 if ($addForGap > -1)
00871                 {
00872                         $this->writePostData();
00873                         if (!$this->checkInput())
00874                         {
00875                                 sendInfo($this->lng->txt("fill_out_all_required_fields_add_answer"));
00876                                 $this->editQuestion();
00877                                 return;
00878                         }
00879                         $_POST["internalLinkType"] = $_POST["internalLinkType_$addForGap"];
00880                         $_SESSION["subquestion_index"] = $addForGap;
00881                 }
00882                 $this->object->saveToDb();
00883                 $_GET["q_id"] = $this->object->getId();
00884                 $this->tpl->setVariable("HEADER", $this->object->getTitle());
00885                 $this->getQuestionTemplate("qt_cloze");
00886                 parent::addSuggestedSolution();
00887         }
00888 
00889         function removeSuggestedSolution()
00890         {
00891                 $removeFromGap = -1;
00892                 foreach ($_POST["cmd"] as $key => $value)
00893                 {
00894                         if (preg_match("/removeSuggestedSolution_(\d+)/", $key, $matches))
00895                         {
00896                                 $removeFromGap = $matches[1];
00897                         }
00898                 }
00899                 if ($removeFromGap > -1)
00900                 {
00901                         unset($this->object->suggested_solutions[$removeFromGap]);
00902                 }
00903                 $this->object->saveToDb();
00904                 $this->editQuestion();
00905         }
00906 
00907 }
00908 ?>

Generated on Fri Dec 13 2013 11:57:52 for ILIAS Release_3_6_x_branch .rev 46809 by  doxygen 1.7.1