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

Modules/TestQuestionPool/classes/class.assTextSubsetGUI.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 "./Modules/TestQuestionPool/classes/class.assQuestionGUI.php";
00025 include_once "./Modules/Test/classes/inc.AssessmentConstants.php";
00026 
00037 class assTextSubsetGUI extends assQuestionGUI
00038 {
00047         function assTextSubsetGUI(
00048                         $id = -1
00049         )
00050         {
00051                 $this->assQuestionGUI();
00052                 include_once "./Modules/TestQuestionPool/classes/class.assTextSubset.php";
00053                 $this->object = new assTextSubset();
00054                 if ($id >= 0)
00055                 {
00056                         $this->object->loadFromDb($id);
00057                 }
00058         }
00059 
00060         function getCommand($cmd)
00061         {
00062                 return $cmd;
00063         }
00064 
00072         function editQuestion()
00073         {
00074                 $this->tpl->addJavascript("./Services/JavaScript/js/Basic.js");
00075                 $javascript = "<script type=\"text/javascript\">ilAddOnLoad(initialSelect);\n".
00076                         "function initialSelect() {\n%s\n}</script>";
00077                 // single response
00078                 $this->getQuestionTemplate();
00079                 $this->tpl->addBlockFile("QUESTION_DATA", "question_data", "tpl.il_as_qpl_textsubset.html", "Modules/TestQuestionPool");
00080                 // output of existing single response answers
00081                 for ($i = 0; $i < $this->object->getAnswerCount(); $i++)
00082                 {
00083                         $this->tpl->setCurrentBlock("answers");
00084                         $answer = $this->object->getAnswer($i);
00085                         $this->tpl->setVariable("VALUE_ANSWER_COUNTER", $answer->getOrder() + 1);
00086                         $this->tpl->setVariable("ANSWER_ORDER", $answer->getOrder());
00087                         $this->tpl->setVariable("VALUE_ANSWER", ilUtil::prepareFormOutput($answer->getAnswertext()));
00088                         $this->tpl->setVariable("VALUE_POINTS", ilUtil::prepareFormOutput($answer->getPoints()));
00089                         $this->tpl->parseCurrentBlock();
00090                 }
00091                 if ($this->object->getAnswerCount() > 0)
00092                 {
00093                         $this->tpl->setCurrentBlock("answersheading");
00094                         $this->tpl->setVariable("TEXT_ANSWER_TEXT", $this->lng->txt("answer_text"));
00095                         $this->tpl->setVariable("TEXT_POINTS", $this->lng->txt("points"));
00096                         $this->tpl->parseCurrentBlock();
00097                 }
00098 
00099                 $internallinks = array(
00100                         "lm" => $this->lng->txt("obj_lm"),
00101                         "st" => $this->lng->txt("obj_st"),
00102                         "pg" => $this->lng->txt("obj_pg"),
00103                         "glo" => $this->lng->txt("glossary_term")
00104                 );
00105                 foreach ($internallinks as $key => $value)
00106                 {
00107                         $this->tpl->setCurrentBlock("internallink");
00108                         $this->tpl->setVariable("TYPE_INTERNAL_LINK", $key);
00109                         $this->tpl->setVariable("TEXT_INTERNAL_LINK", $value);
00110                         $this->tpl->parseCurrentBlock();
00111                 }
00112                 
00113                 $this->tpl->setCurrentBlock("HeadContent");
00114                 if ($this->object->getAnswerCount() == 0)
00115                 {
00116                         $this->tpl->setVariable("CONTENT_BLOCK", sprintf($javascript, "document.frm_textsubset.title.focus();"));
00117                 }
00118                 else
00119                 {
00120                         switch ($this->ctrl->getCmd())
00121                         {
00122                                 case "add":
00123                                         $this->tpl->setVariable("CONTENT_BLOCK", sprintf($javascript, "document.frm_textsubset.answer_".($this->object->getAnswerCount() - $_POST["nrOfAnswers"]).".focus(); document.getElementById('answer_".($this->object->getAnswerCount() - $_POST["nrOfAnswers"])."').scrollIntoView(\"true\");"));
00124                                         break;
00125                                 case "":
00126                                         if ($this->object->getAnswerCount() == 0)
00127                                         {
00128                                                 $this->tpl->setVariable("CONTENT_BLOCK", sprintf($javascript, "document.frm_textsubset.title.focus();"));
00129                                         }
00130                                         else
00131                                         {
00132                                                 $this->tpl->setVariable("CONTENT_BLOCK", sprintf($javascript, "document.frm_textsubset.answer_".($this->object->getAnswerCount() - 1).".focus(); document.getElementById('answer_".($this->object->getAnswerCount() - 1)."').scrollIntoView(\"true\");"));
00133                                         }
00134                                         break;
00135                                 default:
00136                                         $this->tpl->setVariable("CONTENT_BLOCK", sprintf($javascript, "document.frm_textsubset.title.focus();"));
00137                                         break;
00138                         }
00139                 }
00140                 $this->tpl->parseCurrentBlock();
00141 
00142                 // Add text rating options
00143                 $text_options = array(
00144                         array("ci", $this->lng->txt("cloze_textgap_case_insensitive")),
00145                         array("cs", $this->lng->txt("cloze_textgap_case_sensitive")),
00146                         array("l1", sprintf($this->lng->txt("cloze_textgap_levenshtein_of"), "1")),
00147                         array("l2", sprintf($this->lng->txt("cloze_textgap_levenshtein_of"), "2")),
00148                         array("l3", sprintf($this->lng->txt("cloze_textgap_levenshtein_of"), "3")),
00149                         array("l4", sprintf($this->lng->txt("cloze_textgap_levenshtein_of"), "4")),
00150                         array("l5", sprintf($this->lng->txt("cloze_textgap_levenshtein_of"), "5"))
00151                 );
00152                 $text_rating = $this->object->getTextRating();
00153                 foreach ($text_options as $text_option)
00154                 {
00155                         $this->tpl->setCurrentBlock("text_rating");
00156                         $this->tpl->setVariable("RATING_VALUE", $text_option[0]);
00157                         $this->tpl->setVariable("RATING_TEXT", $text_option[1]);
00158                         if (strcmp($text_rating, $text_option[0]) == 0)
00159                         {
00160                                 $this->tpl->setVariable("SELECTED_RATING_VALUE", " selected=\"selected\"");
00161                         }
00162                         $this->tpl->parseCurrentBlock();
00163                 }
00164 
00165                 if ($this->object->getAnswerCount() > 0)
00166                 {
00167                         $this->tpl->setCurrentBlock("selectall");
00168                         $this->tpl->setVariable("SELECT_ALL", $this->lng->txt("select_all"));
00169                         $this->tpl->parseCurrentBlock();
00170                         $this->tpl->setCurrentBlock("existinganswers");
00171                         $this->tpl->setVariable("DELETE", $this->lng->txt("delete"));
00172                         $this->tpl->setVariable("MOVE", $this->lng->txt("move"));
00173                         $this->tpl->setVariable("ARROW", "<img src=\"" . ilUtil::getImagePath("arrow_downright.gif") . "\" alt=\"".$this->lng->txt("arrow_downright")."\">");
00174                         $this->tpl->parseCurrentBlock();
00175                 }
00176                 
00177                 for ($i = 1; $i < 10; $i++)
00178                 {
00179                         $this->tpl->setCurrentBlock("numbers");
00180                         $this->tpl->setVariable("VALUE_NUMBER", $i);
00181                         if ($i == 1)
00182                         {
00183                                 $this->tpl->setVariable("TEXT_NUMBER", $i . " " . $this->lng->txt("answer"));
00184                         }
00185                         else
00186                         {
00187                                 $this->tpl->setVariable("TEXT_NUMBER", $i . " " . $this->lng->txt("answers"));
00188                         }
00189                         $this->tpl->parseCurrentBlock();
00190                 }
00191 
00192                 $this->tpl->setCurrentBlock("question_data");
00193                 $this->tpl->setVariable("TEXTSUBSET_ID", $this->object->getId());
00194                 $this->tpl->setVariable("VALUE_TEXTSUBSET_TITLE", ilUtil::prepareFormOutput($this->object->getTitle()));
00195                 $this->tpl->setVariable("VALUE_TEXTSUBSET_COMMENT", ilUtil::prepareFormOutput($this->object->getComment()));
00196                 $this->tpl->setVariable("VALUE_TEXTSUBSET_AUTHOR", ilUtil::prepareFormOutput($this->object->getAuthor()));
00197                 $this->tpl->setVariable("VALUE_CORRECTANSWERS", $this->object->getCorrectAnswers());
00198                 $this->tpl->setVariable("VALUE_POINTS", $this->object->getMaximumPoints());
00199                 $questiontext = $this->object->getQuestion();
00200                 $this->tpl->setVariable("VALUE_QUESTION", ilUtil::prepareFormOutput($this->object->prepareTextareaOutput($questiontext)));
00201                 $this->tpl->setVariable("VALUE_ADD_ANSWER", $this->lng->txt("add"));
00202                 $this->tpl->setVariable("TEXT_TITLE", $this->lng->txt("title"));
00203                 $this->tpl->setVariable("TEXT_AUTHOR", $this->lng->txt("author"));
00204                 $this->tpl->setVariable("TEXT_COMMENT", $this->lng->txt("description"));
00205                 $this->tpl->setVariable("TEXT_QUESTION", $this->lng->txt("question"));
00206                 $this->tpl->setVariable("TEXT_SOLUTION_HINT", $this->lng->txt("solution_hint"));
00207                 $this->tpl->setVariable("TEXT_RATING", $this->lng->txt("text_rating"));
00208                 $this->tpl->setVariable("TEXT_POINTS", $this->lng->txt("maximum_points"));
00209                 $this->tpl->setVariable("TEXT_CORRECTANSWERS", $this->lng->txt("nr_of_correct_answers"));
00210                 
00211                 // estimated working time
00212                 $est_working_time = $this->object->getEstimatedWorkingTime();
00213                 $this->tpl->setVariable("TEXT_WORKING_TIME", $this->lng->txt("working_time"));
00214                 $this->tpl->setVariable("TIME_FORMAT", $this->lng->txt("time_format"));
00215                 $this->tpl->setVariable("VALUE_WORKING_TIME", ilUtil::makeTimeSelect("Estimated", false, $est_working_time[h], $est_working_time[m], $est_working_time[s]));
00216 
00217                 if (count($this->object->suggested_solutions))
00218                 {
00219                         $solution_array = $this->object->getSuggestedSolution(0);
00220                         include_once "./Modules/TestQuestionPool/classes/class.assQuestion.php";
00221                         $href = assQuestion::_getInternalLinkHref($solution_array["internal_link"]);
00222                         $this->tpl->setVariable("TEXT_VALUE_SOLUTION_HINT", " <a href=\"$href\" target=\"content\">" . $this->lng->txt("solution_hint"). "</a> ");
00223                         $this->tpl->setVariable("BUTTON_REMOVE_SOLUTION", $this->lng->txt("remove"));
00224                         $this->tpl->setVariable("BUTTON_ADD_SOLUTION", $this->lng->txt("change"));
00225                         $this->tpl->setVariable("VALUE_SOLUTION_HINT", $solution_array["internal_link"]);
00226                 }
00227                 else
00228                 {
00229                         $this->tpl->setVariable("BUTTON_ADD_SOLUTION", $this->lng->txt("add"));
00230                 }
00231                 $this->tpl->setVariable("SAVE",$this->lng->txt("save"));
00232                 $this->tpl->setVariable("SAVE_EDIT", $this->lng->txt("save_edit"));
00233                 $this->tpl->setVariable("CANCEL",$this->lng->txt("cancel"));
00234                 $this->tpl->setVariable("TXT_REQUIRED_FLD", $this->lng->txt("required_field"));
00235                 $this->ctrl->setParameter($this, "sel_question_types", "assTextSubset");
00236                 $this->tpl->setVariable("ACTION_TEXTSUBSET_TEST", $this->ctrl->getFormAction($this));
00237                 $this->tpl->setVariable("TEXT_QUESTION_TYPE", $this->lng->txt("assTextSubset"));
00238                 $this->outOtherQuestionData();
00239 
00240                 $this->tpl->parseCurrentBlock();
00241                 include_once "./Services/RTE/classes/class.ilRTE.php";
00242                 $rtestring = ilRTE::_getRTEClassname();
00243                 include_once "./Services/RTE/classes/class.$rtestring.php";
00244                 $rte = new $rtestring();
00245                 $rte->addPlugin("latex");
00246                 $rte->addButton("latex"); $rte->addButton("pastelatex");
00247                 include_once "./classes/class.ilObject.php";
00248                 $obj_id = $_GET["q_id"];
00249                 $obj_type = ilObject::_lookupType($_GET["ref_id"], TRUE);
00250                 $rte->addRTESupport($obj_id, $obj_type, "assessment");
00251 
00252                 $this->tpl->setCurrentBlock("adm_content");
00253                 //$this->tpl->setVariable("BODY_ATTRIBUTES", " onload=\"initialSelect();\""); 
00254                 $this->tpl->parseCurrentBlock();
00255         }
00256         
00260         function deleteAnswer()
00261         {
00262                 $this->writePostData();
00263                 $answers = $_POST["chb_answers"];
00264                 if (is_array($answers))
00265                 {
00266                         arsort($answers);
00267                         foreach ($answers as $answer)
00268                         {
00269                                 $this->object->deleteAnswer($answer);
00270                         }
00271                 }
00272                 $this->editQuestion();
00273         }
00274 
00278         function add()
00279         {
00280                 //$this->setObjectData();
00281                 $this->writePostData();
00282 
00283                 for ($i = 0; $i < $_POST["nrOfAnswers"]; $i++)
00284                 {
00285                         $this->object->addAnswer(
00286                                 "",
00287                                 1,
00288                                 count($this->object->answers)
00289                         );
00290                 }
00291 
00292                 $this->editQuestion();
00293         }
00294         
00295         function save()
00296         {
00297                 $unfilled_answer = false;
00298                 foreach ($_POST as $key => $value)
00299                 {
00300                         if (preg_match("/answer_(\d+)/", $key, $matches))
00301                         {
00302                                 if (!$value)
00303                                 {
00304                                         $unfilled_answer = true;
00305                                 }
00306                         }
00307                 }
00308                 if ($unfilled_answer)
00309                 {
00310                         ilUtil::sendInfo($this->lng->txt("qpl_answertext_fields_not_filled"));
00311                         $this->writePostData();
00312                         $this->editQuestion();
00313                 }
00314                 else
00315                 {
00316                         parent::save();
00317                 }
00318         }
00319         
00320         function saveEdit()
00321         {
00322                 $unfilled_answer = false;
00323                 foreach ($_POST as $key => $value)
00324                 {
00325                         if (preg_match("/answer_(\d+)/", $key, $matches))
00326                         {
00327                                 if (!$value)
00328                                 {
00329                                         $unfilled_answer = true;
00330                                 }
00331                         }
00332                 }
00333                 if ($unfilled_answer)
00334                 {
00335                         ilUtil::sendInfo($this->lng->txt("qpl_answertext_fields_not_filled"));
00336                         $this->writePostData();
00337                         $this->editQuestion();
00338                 }
00339                 else
00340                 {
00341                         parent::saveEdit();
00342                 }
00343         }
00344 
00348         function checkInput()
00349         {
00350                 $cmd = $this->ctrl->getCmd();
00351 
00352                 if ((!$_POST["title"]) or (!$_POST["author"]) or (!$_POST["question"]) or (!$_POST["correctanswers"]))
00353                 {
00354                         return false;
00355                 }
00356                 return true;
00357         }
00358 
00367         function writePostData()
00368         {
00369 //echo "here!"; exit;
00370 //echo "<br>assTextSubsetGUI->writePostData()";
00371                 $result = 0;
00372                 if (!$this->checkInput())
00373                 {
00374                         $result = 1;
00375                 }
00376 
00377                 if (($result) and (strcmp($this->ctrl->getCmd(), "add") == 0))
00378                 {
00379                         // You cannot add answers before you enter the required data
00380                         ilUtil::sendInfo($this->lng->txt("fill_out_all_required_fields_add_answer"));
00381                 }
00382 
00383                 $this->object->setTitle(ilUtil::stripSlashes($_POST["title"]));
00384                 $this->object->setAuthor(ilUtil::stripSlashes($_POST["author"]));
00385                 $this->object->setComment(ilUtil::stripSlashes($_POST["comment"]));
00386                 include_once "./classes/class.ilObjAdvancedEditing.php";
00387                 $questiontext = ilUtil::stripSlashes($_POST["question"], false, ilObjAdvancedEditing::_getUsedHTMLTagsAsString("assessment"));
00388                 $this->object->setQuestion($questiontext);
00389                 $this->object->setSuggestedSolution($_POST["solution_hint"], 0);
00390                 $this->object->setCorrectAnswers($_POST["correctanswers"]);
00391                 $this->object->setTextRating($_POST["text_rating"]);
00392 
00393                 $saved = $this->writeOtherPostData($result);
00394 
00395                 // Delete all existing answers and create new answers from the form data
00396                 $this->object->flushAnswers();
00397 
00398                 // Add all answers from the form into the object
00399                 foreach ($_POST as $key => $value)
00400                 {
00401                         if (preg_match("/answer_(\d+)/", $key, $matches))
00402                         {
00403                                 $this->object->addAnswer(
00404                                         ilUtil::stripSlashes($_POST["$key"]),
00405                                         ilUtil::stripSlashes($_POST["points_".$matches[1]]),
00406                                         ilUtil::stripSlashes($matches[1])
00407                                         );
00408                         }
00409                 }
00410 
00411                 // Set the question id from a hidden form parameter
00412                 if ($_POST["textsubset_id"] > 0)
00413                 {
00414                         $this->object->setId($_POST["textsubset_id"]);
00415                 }
00416 
00417                 $maximum_points = $this->object->getMaximumPoints();
00418                 if (($maximum_points <= 0) && (count($this->object->answers) > 0))
00419                 {
00420                         $result = 1;
00421                         $this->setErrorMessage($this->lng->txt("enter_enough_positive_points"));
00422                 }
00423                 $this->object->setPoints($maximum_points);
00424                 
00425                 if ($saved)
00426                 {
00427                         // If the question was saved automatically before an upload, we have to make
00428                         // sure, that the state after the upload is saved. Otherwise the user could be
00429                         // irritated, if he presses cancel, because he only has the question state before
00430                         // the upload process.
00431                         $this->object->saveToDb();
00432                         $this->ctrl->setParameter($this, "q_id", $this->object->getId());
00433                 }
00434 
00435                 return $result;
00436         }
00437         
00438         function outQuestionForTest($formaction, $active_id, $pass = NULL, $is_postponed = FALSE, $use_post_solutions = FALSE)
00439         {
00440                 $test_output = $this->getTestOutput($active_id, $pass, $is_postponed, $use_post_solutions); 
00441                 $this->tpl->setVariable("QUESTION_OUTPUT", $test_output);
00442                 $this->tpl->setVariable("FORMACTION", $formaction);
00443         }
00444 
00445         function getSolutionOutput($active_id, $pass = NULL, $graphicalOutput = FALSE, $result_output = FALSE, $show_question_only = TRUE, $show_feedback = FALSE)
00446         {
00447                 // get the solution of the user for the active pass or from the last pass if allowed
00448                 $solutions = array();
00449                 if ($active_id)
00450                 {
00451                         $solutions =& $this->object->getSolutionValues($active_id, $pass);
00452                 }
00453                 else
00454                 {
00455                         $rank = array();
00456                         foreach ($this->object->answers as $answer)
00457                         {
00458                                 if ($answer->getPoints() > 0)
00459                                 {
00460                                         if (!is_array($rank[$answer->getPoints()]))
00461                                         {
00462                                                 $rank[$answer->getPoints()] = array();
00463                                         }
00464                                         array_push($rank[$answer->getPoints()], $answer->getAnswertext());
00465                                 }
00466                         }
00467                         krsort($rank, SORT_NUMERIC);
00468                         foreach ($rank as $index => $bestsolutions)
00469                         {
00470                                 array_push($solutions, array("value1" => join(",", $bestsolutions), "points" => $index));
00471                         }
00472                 }
00473                 
00474                 // generate the question output
00475                 include_once "./classes/class.ilTemplate.php";
00476                 $template = new ilTemplate("tpl.il_as_qpl_textsubset_output_solution.html", TRUE, TRUE, "Modules/TestQuestionPool");
00477                 $solutiontemplate = new ilTemplate("tpl.il_as_tst_solution_output.html", TRUE, TRUE, "Modules/TestQuestionPool");
00478                 $available_answers =& $this->object->getAvailableAnswers();
00479                 for ($i = 0; $i < $this->object->getCorrectAnswers(); $i++)
00480                 {
00481                         if ((!$test_id) && (strcmp($solutions[$i]["value1"], "") == 0))
00482                         {
00483                         }
00484                         else
00485                         {
00486                                 if ($active_id)
00487                                 {
00488                                         if ($graphicalOutput)
00489                                         {
00490                                                 // output of ok/not ok icons for user entered solutions
00491                                                 $index = $this->object->isAnswerCorrect($available_answers, $solutions[$i]["value1"]);
00492                                                 $correct = FALSE;
00493                                                 if ($index !== FALSE)
00494                                                 {
00495                                                         unset($available_answers[$index]);
00496                                                         $correct = TRUE;
00497                                                 }
00498                                                 if ($correct)
00499                                                 {
00500                                                         $template->setCurrentBlock("icon_ok");
00501                                                         $template->setVariable("ICON_OK", ilUtil::getImagePath("icon_ok.gif"));
00502                                                         $template->setVariable("TEXT_OK", $this->lng->txt("answer_is_right"));
00503                                                         $template->parseCurrentBlock();
00504                                                 }
00505                                                 else
00506                                                 {
00507                                                         $template->setCurrentBlock("icon_ok");
00508                                                         $template->setVariable("ICON_NOT_OK", ilUtil::getImagePath("icon_not_ok.gif"));
00509                                                         $template->setVariable("TEXT_NOT_OK", $this->lng->txt("answer_is_wrong"));
00510                                                         $template->parseCurrentBlock();
00511                                                 }
00512                                         }
00513                                 }
00514                                 $template->setCurrentBlock("textsubset_row");
00515                                 $template->setVariable("SOLUTION", $solutions[$i]["value1"]);
00516                                 $template->setVariable("COUNTER", $i+1);
00517                                 if ($result_output)
00518                                 {
00519                                         $points = $solutions[$i]["points"];
00520                                         $resulttext = ($points == 1) ? "(%s " . $this->lng->txt("point") . ")" : "(%s " . $this->lng->txt("points") . ")"; 
00521                                         $template->setVariable("RESULT_OUTPUT", sprintf($resulttext, $points));
00522                                 }
00523                                 $template->parseCurrentBlock();
00524                         }
00525                 }
00526                 $questiontext = $this->object->getQuestion();
00527                 $template->setVariable("QUESTIONTEXT", $this->object->prepareTextareaOutput($questiontext, TRUE));
00528                 $questionoutput = $template->get();
00529                 $feedback = ($show_feedback) ? $this->getAnswerFeedbackOutput($active_id, $pass) : "";
00530                 if (strlen($feedback)) $solutiontemplate->setVariable("FEEDBACK", $feedback);
00531                 $solutiontemplate->setVariable("SOLUTION_OUTPUT", $questionoutput);
00532 
00533                 $solutionoutput = $solutiontemplate->get(); 
00534                 if (!$show_question_only)
00535                 {
00536                         // get page object output
00537                         $pageoutput = $this->getILIASPage();
00538                         $solutionoutput = "<div class=\"ilias_content\">" . preg_replace("/(<div( xmlns:xhtml\=\"http:\/\/www.w3.org\/1999\/xhtml\"){0,1} class\=\"ilc_Question\"><\/div>)/ims", "</div><div class=\"ilc_Question\">" . $solutionoutput . "</div><div class=\"ilias_content\">", $pageoutput) . "</div>";
00539                 }
00540                 return $solutionoutput;
00541         }
00542         
00543         function getPreview($show_question_only = FALSE)
00544         {
00545                 // generate the question output
00546                 include_once "./classes/class.ilTemplate.php";
00547                 $template = new ilTemplate("tpl.il_as_qpl_textsubset_output.html", TRUE, TRUE, "Modules/TestQuestionPool");
00548                 $width = $this->object->getMaxTextboxWidth();
00549                 for ($i = 0; $i < $this->object->getCorrectAnswers(); $i++)
00550                 {
00551                         $template->setCurrentBlock("textsubset_row");
00552                         $template->setVariable("COUNTER", $i+1);
00553                         $template->setVariable("TEXTFIELD_ID", sprintf("%02d", $i+1));
00554                         $template->setVariable("TEXTFIELD_SIZE", $width);
00555                         $template->parseCurrentBlock();
00556                 }
00557                 $questiontext = $this->object->getQuestion();
00558                 $template->setVariable("QUESTIONTEXT", $this->object->prepareTextareaOutput($questiontext, TRUE));
00559                 $questionoutput = $template->get();
00560                 if (!$show_question_only)
00561                 {
00562                         // get page object output
00563                         $pageoutput = $this->getILIASPage();
00564                         $questionoutput = preg_replace("/(<div( xmlns:xhtml\=\"http:\/\/www.w3.org\/1999\/xhtml\"){0,1} class\=\"ilc_Question\"><\/div>)/ims", $questionoutput, $pageoutput);
00565                 }
00566                 else
00567                 {
00568                         $questionoutput = preg_replace("/<div[^>]*?>(.*)<\/div>/is", "\\1", $questionoutput);
00569                 }
00570 
00571                 return $questionoutput;
00572         }
00573 
00574         function getTestOutput($active_id, $pass = NULL, $is_postponed = FALSE, $use_post_solutions = FALSE)
00575         {
00576                 // get page object output
00577                 $pageoutput = $this->outQuestionPage("", $is_postponed, $active_id);
00578 
00579                 // get the solution of the user for the active pass or from the last pass if allowed
00580                 $user_solution = "";
00581                 if ($active_id)
00582                 {
00583                         $solutions = NULL;
00584                         include_once "./Modules/Test/classes/class.ilObjTest.php";
00585                         if (!ilObjTest::_getUsePreviousAnswers($active_id, true))
00586                         {
00587                                 if (is_null($pass)) $pass = ilObjTest::_getPass($active_id);
00588                         }
00589                         $solutions =& $this->object->getSolutionValues($active_id, $pass);
00590                 }
00591                 
00592                 // generate the question output
00593                 include_once "./classes/class.ilTemplate.php";
00594                 $template = new ilTemplate("tpl.il_as_qpl_textsubset_output.html", TRUE, TRUE, "Modules/TestQuestionPool");
00595                 $width = $this->object->getMaxTextboxWidth();
00596                 for ($i = 0; $i < $this->object->getCorrectAnswers(); $i++)
00597                 {
00598                         $template->setCurrentBlock("textsubset_row");
00599                         foreach ($solutions as $idx => $solution_value)
00600                         {
00601                                 if ($idx == $i)
00602                                 {
00603                                         $template->setVariable("TEXTFIELD_VALUE", " value=\"" . $solution_value["value1"]."\"");
00604                                 }
00605                         }
00606                         $template->setVariable("COUNTER", $i+1);
00607                         $template->setVariable("TEXTFIELD_ID", sprintf("%02d", $i+1));
00608                         $template->setVariable("TEXTFIELD_SIZE", $width);
00609                         $template->parseCurrentBlock();
00610                 }
00611                 $questiontext = $this->object->getQuestion();
00612                 $template->setVariable("QUESTIONTEXT", $this->object->prepareTextareaOutput($questiontext, TRUE));
00613                 $questionoutput = $template->get();
00614                 $questionoutput = preg_replace("/(<div( xmlns:xhtml\=\"http:\/\/www.w3.org\/1999\/xhtml\"){0,1} class\=\"ilc_Question\"><\/div>)/ims", $questionoutput, $pageoutput);
00615                 return $questionoutput;
00616         }
00617 
00618         function addSuggestedSolution()
00619         {
00620                 $_SESSION["subquestion_index"] = 0;
00621                 if ($_POST["cmd"]["addSuggestedSolution"])
00622                 {
00623                         if ($this->writePostData())
00624                         {
00625                                 ilUtil::sendInfo($this->getErrorMessage());
00626                                 $this->editQuestion();
00627                                 return;
00628                         }
00629                         if (!$this->checkInput())
00630                         {
00631                                 ilUtil::sendInfo($this->lng->txt("fill_out_all_required_fields_add_answer"));
00632                                 $this->editQuestion();
00633                                 return;
00634                         }
00635                 }
00636                 $this->object->saveToDb();
00637                 $this->ctrl->setParameter($this, "q_id", $this->object->getId());
00638                 $this->tpl->setVariable("HEADER", $this->object->getTitle());
00639                 $this->getQuestionTemplate();
00640                 parent::addSuggestedSolution();
00641         }
00642         
00650         function saveFeedback()
00651         {
00652                 include_once "./classes/class.ilObjAdvancedEditing.php";
00653                 $this->object->saveFeedbackGeneric(0, ilUtil::stripSlashes($_POST["feedback_incomplete"], false, ilObjAdvancedEditing::_getUsedHTMLTagsAsString("assessment")));
00654                 $this->object->saveFeedbackGeneric(1, ilUtil::stripSlashes($_POST["feedback_complete"], false, ilObjAdvancedEditing::_getUsedHTMLTagsAsString("assessment")));
00655                 $this->object->cleanupMediaObjectUsage();
00656                 parent::saveFeedback();
00657         }
00658 
00666         function feedback()
00667         {
00668                 $this->tpl->addBlockFile("ADM_CONTENT", "feedback", "tpl.il_as_qpl_textsubset_feedback.html", "Modules/TestQuestionPool");
00669                 $this->tpl->setVariable("FEEDBACK_TEXT", $this->lng->txt("feedback"));
00670                 $this->tpl->setVariable("FEEDBACK_COMPLETE", $this->lng->txt("feedback_complete_solution"));
00671                 $this->tpl->setVariable("VALUE_FEEDBACK_COMPLETE", ilUtil::prepareFormOutput($this->object->prepareTextareaOutput($this->object->getFeedbackGeneric(1)), FALSE));
00672                 $this->tpl->setVariable("FEEDBACK_INCOMPLETE", $this->lng->txt("feedback_incomplete_solution"));
00673                 $this->tpl->setVariable("VALUE_FEEDBACK_INCOMPLETE", ilUtil::prepareFormOutput($this->object->prepareTextareaOutput($this->object->getFeedbackGeneric(0)), FALSE));
00674                 $this->tpl->setVariable("SAVE", $this->lng->txt("save"));
00675                 $this->tpl->setVariable("FORMACTION", $this->ctrl->getFormAction($this));
00676 
00677                 include_once "./Services/RTE/classes/class.ilRTE.php";
00678                 $rtestring = ilRTE::_getRTEClassname();
00679                 include_once "./Services/RTE/classes/class.$rtestring.php";
00680                 $rte = new $rtestring();
00681                 $rte->addPlugin("latex");
00682                 $rte->addButton("latex"); $rte->addButton("pastelatex");
00683                 include_once "./classes/class.ilObject.php";
00684                 $obj_id = $_GET["q_id"];
00685                 $obj_type = ilObject::_lookupType($_GET["ref_id"], TRUE);
00686                 $rte->addRTESupport($obj_id, $obj_type, "assessment");
00687         }
00688 
00696         function setQuestionTabs()
00697         {
00698                 global $rbacsystem, $ilTabs;
00699                 
00700                 $this->ctrl->setParameterByClass("ilpageobjectgui", "q_id", $_GET["q_id"]);
00701                 include_once "./Modules/TestQuestionPool/classes/class.assQuestion.php";
00702                 $q_type = $this->object->getQuestionType();
00703 
00704                 if (strlen($q_type))
00705                 {
00706                         $classname = $q_type . "GUI";
00707                         $this->ctrl->setParameterByClass(strtolower($classname), "sel_question_types", $q_type);
00708                         $this->ctrl->setParameterByClass(strtolower($classname), "q_id", $_GET["q_id"]);
00709                 }
00710 
00711                 if ($_GET["q_id"])
00712                 {
00713                         if ($rbacsystem->checkAccess('write', $_GET["ref_id"]))
00714                         {
00715                                 // edit page
00716                                 $ilTabs->addTarget("edit_content",
00717                                         $this->ctrl->getLinkTargetByClass("ilPageObjectGUI", "view"),
00718                                         array("view", "insert", "exec_pg"),
00719                                         "", "", $force_active);
00720                         }
00721         
00722                         // edit page
00723                         $ilTabs->addTarget("preview",
00724                                 $this->ctrl->getLinkTargetByClass("ilPageObjectGUI", "preview"),
00725                                 array("preview"),
00726                                 "ilPageObjectGUI", "", $force_active);
00727                 }
00728 
00729                 $force_active = false;
00730                 if ($rbacsystem->checkAccess('write', $_GET["ref_id"]))
00731                 {
00732                         $url = "";
00733                         if ($classname) $url = $this->ctrl->getLinkTargetByClass($classname, "editQuestion");
00734                         // edit question properties
00735                         $ilTabs->addTarget("edit_properties",
00736                                 $url,
00737                                 array("editQuestion", "save", "cancel", "addSuggestedSolution",
00738                                         "cancelExplorer", "linkChilds", "removeSuggestedSolution", "add", "deleteAnswer", 
00739                                         "saveEdit"),
00740                                 $classname, "", $force_active);
00741                 }
00742 
00743                 if ($_GET["q_id"])
00744                 {
00745                         $ilTabs->addTarget("feedback",
00746                                 $this->ctrl->getLinkTargetByClass($classname, "feedback"),
00747                                 array("feedback", "saveFeedback"),
00748                                 $classname, "");
00749                 }
00750                 
00751                 // Assessment of questions sub menu entry
00752                 if ($_GET["q_id"])
00753                 {
00754                         $ilTabs->addTarget("statistics",
00755                                 $this->ctrl->getLinkTargetByClass($classname, "assessment"),
00756                                 array("assessment"),
00757                                 $classname, "");
00758                 }
00759                 
00760                 if (($_GET["calling_test"] > 0) || ($_GET["test_ref_id"] > 0))
00761                 {
00762                         $ref_id = $_GET["calling_test"];
00763                         if (strlen($ref_id) == 0) $ref_id = $_GET["test_ref_id"];
00764                         $ilTabs->setBackTarget($this->lng->txt("backtocallingtest"), "ilias.php?baseClass=ilObjTestGUI&cmd=questions&ref_id=$ref_id");
00765                 }
00766                 else
00767                 {
00768                         $ilTabs->setBackTarget($this->lng->txt("qpl"), $this->ctrl->getLinkTargetByClass("ilobjquestionpoolgui", "questions"));
00769                 }
00770         }
00771 }
00772 ?>

Generated on Fri Dec 13 2013 17:56:54 for ILIAS Release_3_9_x_branch .rev 46835 by  doxygen 1.7.1