00001 <?php
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024 include_once "./assessment/classes/class.assQuestionGUI.php";
00025 include_once "./assessment/classes/inc.AssessmentConstants.php";
00026
00038 class ASS_TextQuestionGUI extends ASS_QuestionGUI
00039 {
00048 function ASS_TextQuestionGUI(
00049 $id = -1
00050 )
00051 {
00052 $this->ASS_QuestionGUI();
00053 include_once "./assessment/classes/class.assTextQuestion.php";
00054 $this->object = new ASS_TextQuestion();
00055 if ($id >= 0)
00056 {
00057 $this->object->loadFromDb($id);
00058 }
00059 }
00060
00069 function getQuestionType()
00070 {
00071 return "qt_text";
00072 }
00073
00081 function editQuestion()
00082 {
00083
00084 $javascript = "<script type=\"text/javascript\">function initialSelect() {\n%s\n}</script>";
00085
00086 $this->getQuestionTemplate("qt_text");
00087 $this->tpl->addBlockFile("QUESTION_DATA", "question_data", "tpl.il_as_qpl_text_question.html", true);
00088
00089 $this->outOtherQuestionData();
00090
00091 $internallinks = array(
00092 "lm" => $this->lng->txt("obj_lm"),
00093 "st" => $this->lng->txt("obj_st"),
00094 "pg" => $this->lng->txt("obj_pg"),
00095 "glo" => $this->lng->txt("glossary_term")
00096 );
00097 foreach ($internallinks as $key => $value)
00098 {
00099 $this->tpl->setCurrentBlock("internallink");
00100 $this->tpl->setVariable("TYPE_INTERNAL_LINK", $key);
00101 $this->tpl->setVariable("TEXT_INTERNAL_LINK", $value);
00102 $this->tpl->parseCurrentBlock();
00103 }
00104
00105 $this->tpl->setCurrentBlock("HeadContent");
00106 $this->tpl->setVariable("CONTENT_BLOCK", sprintf($javascript, "document.frm_text_question.title.focus();"));
00107 $this->tpl->parseCurrentBlock();
00108 $this->tpl->setCurrentBlock("question_data");
00109 $this->tpl->setVariable("TEXT_QUESTION_ID", $this->object->getId());
00110 $this->tpl->setVariable("VALUE_TEXT_QUESTION_TITLE", htmlspecialchars($this->object->getTitle()));
00111 $this->tpl->setVariable("VALUE_TEXT_QUESTION_COMMENT", htmlspecialchars($this->object->getComment()));
00112 $this->tpl->setVariable("VALUE_TEXT_QUESTION_AUTHOR", htmlspecialchars($this->object->getAuthor()));
00113 $questiontext = $this->object->get_question();
00114 $questiontext = preg_replace("/<br \/>/", "\n", $questiontext);
00115 $this->tpl->setVariable("VALUE_QUESTION", htmlspecialchars($questiontext));
00116 $this->tpl->setVariable("VALUE_POINTS", htmlspecialchars($this->object->getPoints()));
00117 if ($this->object->getMaxNumOfChars())
00118 {
00119 $this->tpl->setVariable("VALUE_MAXCHARS", htmlspecialchars($this->object->getMaxNumOfChars()));
00120 }
00121 $this->tpl->setVariable("TEXT_TITLE", $this->lng->txt("title"));
00122 $this->tpl->setVariable("TEXT_AUTHOR", $this->lng->txt("author"));
00123 $this->tpl->setVariable("TEXT_COMMENT", $this->lng->txt("description"));
00124 $this->tpl->setVariable("TEXT_QUESTION", $this->lng->txt("question"));
00125 $this->tpl->setVariable("TEXT_MAXCHARS", $this->lng->txt("maxchars"));
00126 $this->tpl->setVariable("TEXT_POINTS", $this->lng->txt("points"));
00127 $this->tpl->setVariable("DESCRIPTION_MAXCHARS", $this->lng->txt("description_maxchars"));
00128 $this->tpl->setVariable("TEXT_SOLUTION_HINT", $this->lng->txt("solution_hint"));
00129 if (count($this->object->suggested_solutions))
00130 {
00131 $solution_array = $this->object->getSuggestedSolution(0);
00132 include_once "./assessment/classes/class.assQuestion.php";
00133 $href = ASS_Question::_getInternalLinkHref($solution_array["internal_link"]);
00134 $this->tpl->setVariable("TEXT_VALUE_SOLUTION_HINT", " <a href=\"$href\" target=\"content\">" . $this->lng->txt("solution_hint"). "</a> ");
00135 $this->tpl->setVariable("BUTTON_REMOVE_SOLUTION", $this->lng->txt("remove"));
00136 $this->tpl->setVariable("BUTTON_ADD_SOLUTION", $this->lng->txt("change"));
00137 $this->tpl->setVariable("VALUE_SOLUTION_HINT", $solution_array["internal_link"]);
00138 }
00139 else
00140 {
00141 $this->tpl->setVariable("BUTTON_ADD_SOLUTION", $this->lng->txt("add"));
00142 }
00143 $this->tpl->setVariable("SAVE",$this->lng->txt("save"));
00144 $this->tpl->setVariable("SAVE_EDIT", $this->lng->txt("save_edit"));
00145 $this->tpl->setVariable("CANCEL",$this->lng->txt("cancel"));
00146 $this->tpl->setVariable("TXT_REQUIRED_FLD", $this->lng->txt("required_field"));
00147 $this->ctrl->setParameter($this, "sel_question_types", "qt_text");
00148 $this->tpl->setVariable("TEXT_QUESTION_TYPE", $this->lng->txt("qt_text"));
00149 $this->tpl->setVariable("ACTION_TEXT_QUESTION", $this->ctrl->getFormAction($this));
00150
00151 $this->tpl->parseCurrentBlock();
00152
00153 $this->tpl->setCurrentBlock("adm_content");
00154 $this->tpl->setVariable("BODY_ATTRIBUTES", " onload=\"initialSelect();\"");
00155 $this->tpl->parseCurrentBlock();
00156 }
00157
00165 function outOtherQuestionData()
00166 {
00167 $this->tpl->setCurrentBlock("other_question_data");
00168 $est_working_time = $this->object->getEstimatedWorkingTime();
00169 $this->tpl->setVariable("TEXT_WORKING_TIME", $this->lng->txt("working_time"));
00170 $this->tpl->setVariable("TIME_FORMAT", $this->lng->txt("time_format"));
00171 $this->tpl->setVariable("VALUE_WORKING_TIME", ilUtil::makeTimeSelect("Estimated", false, $est_working_time[h], $est_working_time[m], $est_working_time[s]));
00172 $this->tpl->parseCurrentBlock();
00173 }
00174
00178 function checkInput()
00179 {
00180 $cmd = $this->ctrl->getCmd();
00181
00182 if ((!$_POST["title"]) or (!$_POST["author"]) or (!$_POST["question"]) or (!$_POST["points"]))
00183 {
00184 return false;
00185 }
00186 return true;
00187 }
00188
00197 function writePostData()
00198 {
00199 $result = 0;
00200 if ((!$_POST["title"]) or (!$_POST["author"]) or (!$_POST["question"]) or (!$_POST["points"]))
00201 {
00202 $result = 1;
00203 }
00204
00205 $this->object->setTitle(ilUtil::stripSlashes($_POST["title"]));
00206 $this->object->setAuthor(ilUtil::stripSlashes($_POST["author"]));
00207 $this->object->setComment(ilUtil::stripSlashes($_POST["comment"]));
00208 $questiontext = ilUtil::stripSlashes($_POST["question"], true, "<strong><em><code><cite>");
00209 $questiontext = preg_replace("/\n/", "<br />", $questiontext);
00210 $this->object->set_question($questiontext);
00211 $this->object->setPoints($_POST["points"]);
00212 $this->object->setSuggestedSolution($_POST["solution_hint"], 0);
00213 $this->object->setMaxNumOfChars($_POST["maxchars"]);
00214
00215 $saved = $this->writeOtherPostData($result);
00216
00217
00218 if ($_POST["text_question_id"] > 0)
00219 {
00220 $this->object->setId($_POST["text_question_id"]);
00221 }
00222
00223 return $result;
00224 }
00225
00226 function outAdditionalOutput()
00227 {
00228 if ($this->object->getMaxNumOfChars() > 0)
00229 {
00230 $this->tpl->addBlockFile("CONTENT_BLOCK", "charcounter", "tpl.charcounter.html", true);
00231 $this->tpl->setCurrentBlock("charcounter");
00232 $this->tpl->setVariable("CHARACTERS", $this->lng->txt("characters"));
00233 $this->tpl->parseCurrentBlock();
00234 }
00235 }
00251 function outWorkingForm(
00252 $test_id = "",
00253 $is_postponed = false,
00254 $showsolution = 0,
00255 $show_question_page = true,
00256 $show_solution_only = false,
00257 $ilUser = NULL,
00258 $pass = NULL,
00259 $mixpass = false
00260 )
00261 {
00262 if ($test_id) $this->outAdditionalOutput();
00263
00264 if (!is_object($ilUser))
00265 {
00266 global $ilUser;
00267 }
00268 $output = $this->outQuestionPage("", $is_postponed, $test_id);
00269
00270 if ($showsolution && !$show_solution_only)
00271 {
00272 $solutionintroduction = "<p>" . $this->lng->txt("tst_your_answer_was") . "</p>";
00273 $output = preg_replace("/(<div[^<]*?ilc_PageTitle.*?<\/div>)/", "\\1" . $solutionintroduction, $output);
00274 }
00275
00276 $solutionoutput = preg_replace("/.*?(<div[^<]*?ilc_Question.*?<\/div>).*/", "\\1", $output);
00277
00278 if (!$show_question_page)
00279 {
00280 $output = preg_replace("/.*?(<div[^<]*?ilc_Question.*?<\/div>).*/", "\\1", $output);
00281 }
00282
00283 if ($show_solution_only)
00284 {
00285 $output = preg_replace("/(<div[^<]*?ilc_Question[^>]*>.*?<\/div>)/", "", $output);
00286 }
00287
00288
00289 if ($test_id)
00290 {
00291 $solutions = NULL;
00292 include_once "./assessment/classes/class.ilObjTest.php";
00293 if ((!$showsolution) && ilObjTest::_getHidePreviousResults($test_id, true))
00294 {
00295 if ($show_question_page)
00296 {
00297 if (is_null($pass)) $pass = ilObjTest::_getPass($ilUser->id, $test_id);
00298 }
00299 }
00300 if ($mixpass) $pass = NULL;
00301 $solutions =& $this->object->getSolutionValues($test_id, $ilUser, $pass);
00302 foreach ($solutions as $idx => $solution_value)
00303 {
00304 $repl_str = $solution_value["value1"]."</textarea>";
00305 $output = str_replace("</textarea>", $repl_str, $output);
00306 }
00307
00308 if (!$show_question_page)
00309 $output = preg_replace ("/<textarea[^>]*>(.*?)<\/textarea>/s","[\\1]", $output);
00310
00311 }
00312 if ($showsolution)
00313 {
00314 $maxchars = "";
00315 if ($this->object->getMaxNumOfChars())
00316 {
00317 $maxchars = "<p>" . $this->lng->txt("maxchars") . ": " . $this->object->getMaxNumOfChars() . "</p>";
00318 }
00319 $solutionoutput = preg_replace("/(<textarea.*?)<\/div>/", $maxchars . "<p>" . $this->lng->txt("tst_no_solution_available") . "</p></div>", $solutionoutput);
00320 }
00321
00322 if ($this->object->getMaxNumOfChars())
00323 {
00324 $output = str_replace("<textarea", "<p class=\"quote\">" . sprintf($this->lng->txt("text_maximum_chars_allowed"), $this->object->getMaxNumOfChars()) . "</p><textarea", $output);
00325 }
00326
00327 if (!$showsolution)
00328 {
00329 $solutionoutput="";
00330 $received_points = "";
00331 }
00332 $this->tpl->setVariable("TEXT_QUESTION", $output.$solutionoutput.$received_points);
00333 }
00334
00335 function addSuggestedSolution()
00336 {
00337 $_SESSION["subquestion_index"] = 0;
00338 if ($_POST["cmd"]["addSuggestedSolution"])
00339 {
00340 $this->writePostData();
00341 if (!$this->checkInput())
00342 {
00343 sendInfo($this->lng->txt("fill_out_all_required_fields_add_answer"));
00344 $this->editQuestion();
00345 return;
00346 }
00347 }
00348 $this->object->saveToDb();
00349 $_GET["q_id"] = $this->object->getId();
00350 $this->tpl->setVariable("HEADER", $this->object->getTitle());
00351 $this->getQuestionTemplate("qt_text");
00352 parent::addSuggestedSolution();
00353 }
00354 }
00355 ?>