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

assessment/classes/class.assTextQuestionGUI.php

Go to the documentation of this file.
00001 <?php
00002  /*
00003    +----------------------------------------------------------------------------+
00004    | ILIAS open source                                                          |
00005    +----------------------------------------------------------------------------+
00006    | Copyright (c) 1998-2001 ILIAS open source, University of Cologne           |
00007    |                                                                            |
00008    | This program is free software; you can redistribute it and/or              |
00009    | modify it under the terms of the GNU General Public License                |
00010    | as published by the Free Software Foundation; either version 2             |
00011    | of the License, or (at your option) any later version.                     |
00012    |                                                                            |
00013    | This program is distributed in the hope that it will be useful,            |
00014    | but WITHOUT ANY WARRANTY; without even the implied warranty of             |
00015    | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the              |
00016    | GNU General Public License for more details.                               |
00017    |                                                                            |
00018    | You should have received a copy of the GNU General Public License          |
00019    | along with this program; if not, write to the Free Software                |
00020    | Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. |
00021    +----------------------------------------------------------------------------+
00022 */
00023 
00024 require_once "./assessment/classes/class.assQuestionGUI.php";
00025 require_once "./assessment/classes/class.assTextQuestion.php";
00026 
00038 class ASS_TextQuestionGUI extends ASS_QuestionGUI
00039 {
00048         function ASS_TextQuestionGUI(
00049                         $id = -1
00050         )
00051         {
00052                 $this->ASS_QuestionGUI();
00053                 $this->object = new ASS_TextQuestion();
00054                 if ($id >= 0)
00055                 {
00056                         $this->object->loadFromDb($id);
00057                 }
00058         }
00059 
00068         function getQuestionType()
00069         {
00070                 return "qt_text";
00071         }
00072 
00080         function editQuestion()
00081         {
00082                 $this->tpl->setVariable("HEADER", $this->object->getTitle());
00083                 $javascript = "<script type=\"text/javascript\">function initialSelect() {\n%s\n}</script>";
00084                 // single response
00085                 $this->getQuestionTemplate("qt_text");
00086                 $this->tpl->addBlockFile("QUESTION_DATA", "question_data", "tpl.il_as_qpl_text_question.html", true);
00087                 // call to other question data i.e. estimated working time block
00088                 $this->outOtherQuestionData();
00089 
00090                 $internallinks = array(
00091                         "lm" => $this->lng->txt("obj_lm"),
00092                         "st" => $this->lng->txt("obj_st"),
00093                         "pg" => $this->lng->txt("obj_pg"),
00094                         "glo" => $this->lng->txt("glossary_term")
00095                 );
00096                 foreach ($internallinks as $key => $value)
00097                 {
00098                         $this->tpl->setCurrentBlock("internallink");
00099                         $this->tpl->setVariable("TYPE_INTERNAL_LINK", $key);
00100                         $this->tpl->setVariable("TEXT_INTERNAL_LINK", $value);
00101                         $this->tpl->parseCurrentBlock();
00102                 }
00103                 
00104                 $this->tpl->setCurrentBlock("HeadContent");
00105                 $this->tpl->setVariable("CONTENT_BLOCK", sprintf($javascript, "document.frm_text_question.title.focus();"));
00106                 $this->tpl->parseCurrentBlock();
00107                 $this->tpl->setCurrentBlock("question_data");
00108                 $this->tpl->setVariable("TEXT_QUESTION_ID", $this->object->getId());
00109                 $this->tpl->setVariable("VALUE_TEXT_QUESTION_TITLE", htmlspecialchars($this->object->getTitle()));
00110                 $this->tpl->setVariable("VALUE_TEXT_QUESTION_COMMENT", htmlspecialchars($this->object->getComment()));
00111                 $this->tpl->setVariable("VALUE_TEXT_QUESTION_AUTHOR", htmlspecialchars($this->object->getAuthor()));
00112                 $questiontext = $this->object->get_question();
00113                 $questiontext = preg_replace("/<br \/>/", "\n", $questiontext);
00114                 $this->tpl->setVariable("VALUE_QUESTION", htmlspecialchars($questiontext));
00115                 $this->tpl->setVariable("VALUE_POINTS", htmlspecialchars($this->object->getPoints()));
00116                 if ($this->object->getMaxNumOfChars())
00117                 {
00118                         $this->tpl->setVariable("VALUE_MAXCHARS", htmlspecialchars($this->object->getMaxNumOfChars()));
00119                 }
00120                 $this->tpl->setVariable("TEXT_TITLE", $this->lng->txt("title"));
00121                 $this->tpl->setVariable("TEXT_AUTHOR", $this->lng->txt("author"));
00122                 $this->tpl->setVariable("TEXT_COMMENT", $this->lng->txt("description"));
00123                 $this->tpl->setVariable("TEXT_QUESTION", $this->lng->txt("question"));
00124                 $this->tpl->setVariable("TEXT_MAXCHARS", $this->lng->txt("maxchars"));
00125                 $this->tpl->setVariable("TEXT_POINTS", $this->lng->txt("points"));
00126                 $this->tpl->setVariable("DESCRIPTION_MAXCHARS", $this->lng->txt("description_maxchars"));
00127                 $this->tpl->setVariable("TEXT_SOLUTION_HINT", $this->lng->txt("solution_hint"));
00128                 if (count($this->object->suggested_solutions))
00129                 {
00130                         $solution_array = $this->object->getSuggestedSolution(0);
00131                         $href = ASS_Question::_getInternalLinkHref($solution_array["internal_link"]);
00132                         $this->tpl->setVariable("TEXT_VALUE_SOLUTION_HINT", " <a href=\"$href\" target=\"content\">" . $this->lng->txt("solution_hint"). "</a> ");
00133                         $this->tpl->setVariable("BUTTON_REMOVE_SOLUTION", $this->lng->txt("remove"));
00134                         $this->tpl->setVariable("BUTTON_ADD_SOLUTION", $this->lng->txt("change"));
00135                         $this->tpl->setVariable("VALUE_SOLUTION_HINT", $solution_array["internal_link"]);
00136                 }
00137                 else
00138                 {
00139                         $this->tpl->setVariable("BUTTON_ADD_SOLUTION", $this->lng->txt("add"));
00140                 }
00141                 $this->tpl->setVariable("SAVE",$this->lng->txt("save"));
00142                 $this->tpl->setVariable("SAVE_EDIT", $this->lng->txt("save_edit"));
00143                 $this->tpl->setVariable("CANCEL",$this->lng->txt("cancel"));
00144                 $this->tpl->setVariable("TXT_REQUIRED_FLD", $this->lng->txt("required_field"));
00145                 $this->ctrl->setParameter($this, "sel_question_types", "qt_text");
00146                 $this->tpl->setVariable("ACTION_TEXT_QUESTION", $this->ctrl->getFormAction($this));
00147 
00148                 $this->tpl->parseCurrentBlock();
00149 
00150                 $this->tpl->setCurrentBlock("adm_content");
00151                 $this->tpl->setVariable("BODY_ATTRIBUTES", " onload=\"initialSelect();\""); 
00152                 $this->tpl->parseCurrentBlock();
00153         }
00154 
00162         function outOtherQuestionData()
00163         {
00164                 $this->tpl->setCurrentBlock("other_question_data");
00165                 $est_working_time = $this->object->getEstimatedWorkingTime();
00166                 $this->tpl->setVariable("TEXT_WORKING_TIME", $this->lng->txt("working_time"));
00167                 $this->tpl->setVariable("TIME_FORMAT", $this->lng->txt("time_format"));
00168                 $this->tpl->setVariable("VALUE_WORKING_TIME", ilUtil::makeTimeSelect("Estimated", false, $est_working_time[h], $est_working_time[m], $est_working_time[s]));
00169                 $this->tpl->parseCurrentBlock();
00170         }
00171 
00175         function checkInput()
00176         {
00177                 $cmd = $this->ctrl->getCmd();
00178 
00179                 if ((!$_POST["title"]) or (!$_POST["author"]) or (!$_POST["question"]) or (!$_POST["points"]))
00180                 {
00181                         return false;
00182                 }
00183                 return true;
00184         }
00185 
00194         function writePostData()
00195         {
00196                 $result = 0;
00197                 if ((!$_POST["title"]) or (!$_POST["author"]) or (!$_POST["question"]) or (!$_POST["points"]))
00198                 {
00199                         $result = 1;
00200                 }
00201 
00202                 $this->object->setTitle(ilUtil::stripSlashes($_POST["title"]));
00203                 $this->object->setAuthor(ilUtil::stripSlashes($_POST["author"]));
00204                 $this->object->setComment(ilUtil::stripSlashes($_POST["comment"]));
00205                 $questiontext = ilUtil::stripSlashes($_POST["question"], true, "<strong><em><code><cite>");
00206                 $questiontext = preg_replace("/\n/", "<br />", $questiontext);
00207                 $this->object->set_question($questiontext);
00208                 $this->object->setPoints($_POST["points"]);
00209                 $this->object->setSuggestedSolution($_POST["solution_hint"], 0);
00210                 $this->object->setMaxNumOfChars($_POST["maxchars"]);
00211 
00212                 $saved = $this->writeOtherPostData($result);
00213 
00214                 // Set the question id from a hidden form parameter
00215                 if ($_POST["text_question_id"] > 0)
00216                 {
00217                         $this->object->setId($_POST["text_question_id"]);
00218                 }
00219                 
00220                 return $result;
00221         }
00222 
00230         function outWorkingForm($test_id = "", $is_postponed = false, $showsolution = 0)
00231         {
00232                 global $ilUser;
00233                 $output = $this->outQuestionPage("", $is_postponed);
00234                 // set solutions
00235                 if ($test_id)
00236                 {
00237                         $solutions =& $this->object->getSolutionValues($test_id);
00238                         foreach ($solutions as $idx => $solution_value)
00239                         {
00240                                 $repl_str = $solution_value->value1."</textarea>";
00241                                 $output = str_replace("</textarea>", $repl_str, $output);
00242                         }
00243                         $reached_points = $this->object->getReachedPoints($ilUser->id, $test_id);
00244                         $received_points = "<p>" . sprintf($this->lng->txt("you_received_a_of_b_points"), $reached_points, $this->object->getMaximumPoints());
00245                         $received_points .= "</p>";
00246                 }
00247                 if ($this->object->getMaxNumOfChars())
00248                 {
00249                         $output = str_replace("</textarea>", "</textarea><p>" . sprintf($this->lng->txt("text_maximum_chars_allowed"), $this->object->getMaxNumOfChars()) . "</p>", $output);
00250                 }
00251                 if (!$showsolution)
00252                 {
00253                         $received_points = "";
00254                 }
00255                 $this->tpl->setVariable("TEXT_QUESTION", $output.$received_points);
00256         }
00257 
00265         function outUserSolution($user_id, $test_id)
00266         {
00267         }
00268         
00269         function addSuggestedSolution()
00270         {
00271                 $_SESSION["subquestion_index"] = 0;
00272                 if ($_POST["cmd"]["addSuggestedSolution"])
00273                 {
00274                         $this->writePostData();
00275                         if (!$this->checkInput())
00276                         {
00277                                 sendInfo($this->lng->txt("fill_out_all_required_fields_add_answer"));
00278                                 $this->editQuestion();
00279                                 return;
00280                         }
00281                 }
00282                 $this->object->saveToDb();
00283                 $_GET["q_id"] = $this->object->getId();
00284                 $this->tpl->setVariable("HEADER", $this->object->getTitle());
00285                 $this->getQuestionTemplate("qt_text");
00286                 parent::addSuggestedSolution();
00287         }
00288 }
00289 ?>

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