ILIAS  Release_3_10_x_branch Revision 61812
 All Data Structures Namespaces Files Functions Variables Groups Pages
class.assNumericGUI.php
Go to the documentation of this file.
1 <?php
2  /*
3  +----------------------------------------------------------------------------+
4  | ILIAS open source |
5  +----------------------------------------------------------------------------+
6  | Copyright (c) 1998-2001 ILIAS open source, University of Cologne |
7  | |
8  | This program is free software; you can redistribute it and/or |
9  | modify it under the terms of the GNU General Public License |
10  | as published by the Free Software Foundation; either version 2 |
11  | of the License, or (at your option) any later version. |
12  | |
13  | This program is distributed in the hope that it will be useful, |
14  | but WITHOUT ANY WARRANTY; without even the implied warranty of |
15  | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
16  | GNU General Public License for more details. |
17  | |
18  | You should have received a copy of the GNU General Public License |
19  | along with this program; if not, write to the Free Software |
20  | Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. |
21  +----------------------------------------------------------------------------+
22 */
23 
24 include_once "./Modules/TestQuestionPool/classes/class.assQuestionGUI.php";
25 include_once "./Modules/Test/classes/inc.AssessmentConstants.php";
26 
39 {
48  function assNumericGUI(
49  $id = -1
50  )
51  {
52  $this->assQuestionGUI();
53  include_once "./Modules/TestQuestionPool/classes/class.assNumeric.php";
54  $this->object = new assNumeric();
55  if ($id >= 0)
56  {
57  $this->object->loadFromDb($id);
58  }
59  }
60 
61  function getCommand($cmd)
62  {
63  if (substr($cmd, 0, 6) == "delete")
64  {
65  $cmd = "delete";
66  }
67 
68  return $cmd;
69  }
70 
71 
79  function editQuestion()
80  {
81  $this->tpl->addJavascript("./Services/JavaScript/js/Basic.js");
82  $javascript = "<script type=\"text/javascript\">ilAddOnLoad(initialSelect);\n".
83  "function initialSelect() {\n%s\n}</script>";
84  $this->getQuestionTemplate();
85  $this->tpl->addBlockFile("QUESTION_DATA", "question_data", "tpl.il_as_qpl_numeric.html", "Modules/TestQuestionPool");
86  // call to other question data i.e. estimated working time block
87  $this->outOtherQuestionData();
88 
89  $internallinks = array(
90  "lm" => $this->lng->txt("obj_lm"),
91  "st" => $this->lng->txt("obj_st"),
92  "pg" => $this->lng->txt("obj_pg"),
93  "glo" => $this->lng->txt("glossary_term")
94  );
95  foreach ($internallinks as $key => $value)
96  {
97  $this->tpl->setCurrentBlock("internallink");
98  $this->tpl->setVariable("TYPE_INTERNAL_LINK", $key);
99  $this->tpl->setVariable("TEXT_INTERNAL_LINK", $value);
100  $this->tpl->parseCurrentBlock();
101  }
102 
103  if ($this->object->getRangeCount() == 0)
104  {
105  $this->object->addRange(0.0, 0.0, 0);
106  }
107 
108  $counter = 0;
109  foreach ($this->object->ranges as $range)
110  {
111  $this->tpl->setCurrentBlock("ranges");
112  $this->tpl->setVariable("COUNTER", $counter);
113  $this->tpl->setVariable("TEXT_RANGE", $this->lng->txt("range"));
114  if (strlen($range->getPoints())) $this->tpl->setVariable("VALUE_POINTS", " value=\"" . $range->getPoints() . "\"");
115  if (strlen($range->getLowerLimit())) $this->tpl->setVariable("VALUE_LOWER_LIMIT", " value=\"" . $range->getLowerLimit() . "\"");
116  if (strlen($range->getUpperLimit())) $this->tpl->setVariable("VALUE_UPPER_LIMIT", " value=\"" . $range->getUpperLimit() . "\"");
117  $this->tpl->setVariable("TEXT_RANGE_LOWER_LIMIT", $this->lng->txt("range_lower_limit"));
118  $this->tpl->setVariable("TEXT_RANGE_UPPER_LIMIT", $this->lng->txt("range_upper_limit"));
119  $this->tpl->setVariable("TEXT_POINTS", $this->lng->txt("points"));
120  $this->tpl->parseCurrentBlock();
121  $counter++;
122  }
123 
124  $this->tpl->setCurrentBlock("question_data");
125  $this->tpl->setVariable("NUMERIC_ID", $this->object->getId());
126  $this->tpl->setVariable("VALUE_NUMERIC_TITLE", ilUtil::prepareFormOutput($this->object->getTitle()));
127  $this->tpl->setVariable("VALUE_NUMERIC_COMMENT", ilUtil::prepareFormOutput($this->object->getComment()));
128  $this->tpl->setVariable("VALUE_NUMERIC_AUTHOR", ilUtil::prepareFormOutput($this->object->getAuthor()));
129  $questiontext = $this->object->getQuestion();
130  $this->tpl->setVariable("VALUE_QUESTION", ilUtil::prepareFormOutput($this->object->prepareTextareaOutput($questiontext)));
131  $this->tpl->setVariable("TEXT_TITLE", $this->lng->txt("title"));
132  $this->tpl->setVariable("TEXT_AUTHOR", $this->lng->txt("author"));
133  $this->tpl->setVariable("TEXT_COMMENT", $this->lng->txt("description"));
134  $this->tpl->setVariable("TEXT_QUESTION", $this->lng->txt("question"));
135  $this->tpl->setVariable("TEXT_SOLUTION_HINT", $this->lng->txt("solution_hint"));
136  $this->tpl->setVariable("TEXT_MAXCHARS", $this->lng->txt("maxchars"));
137  $this->tpl->setVariable("VALUE_MAXCHARS", $this->object->getMaxChars());
138  if (count($this->object->suggested_solutions))
139  {
140  $solution_array = $this->object->getSuggestedSolution(0);
141  include_once "./Modules/TestQuestionPool/classes/class.assQuestion.php";
142  $href = assQuestion::_getInternalLinkHref($solution_array["internal_link"]);
143  $this->tpl->setVariable("TEXT_VALUE_SOLUTION_HINT", " <a href=\"$href\" target=\"content\">" . $this->lng->txt("solution_hint"). "</a> ");
144  $this->tpl->setVariable("BUTTON_REMOVE_SOLUTION", $this->lng->txt("remove"));
145  $this->tpl->setVariable("BUTTON_ADD_SOLUTION", $this->lng->txt("change"));
146  $this->tpl->setVariable("VALUE_SOLUTION_HINT", $solution_array["internal_link"]);
147  }
148  else
149  {
150  $this->tpl->setVariable("BUTTON_ADD_SOLUTION", $this->lng->txt("add"));
151  }
152  $this->tpl->setVariable("SAVE",$this->lng->txt("save"));
153  $this->tpl->setVariable("SAVE_EDIT", $this->lng->txt("save_edit"));
154  $this->tpl->setVariable("CANCEL",$this->lng->txt("cancel"));
155  $this->tpl->setVariable("TXT_REQUIRED_FLD", $this->lng->txt("required_field"));
156  $this->ctrl->setParameter($this, "sel_question_types", "assNumeric");
157  $this->tpl->setVariable("FORMACTION", $this->ctrl->getFormAction($this));
158  $this->tpl->setVariable("TEXT_QUESTION_TYPE", $this->outQuestionType());
159  include_once "./Services/RTE/classes/class.ilRTE.php";
160  $rtestring = ilRTE::_getRTEClassname();
161  include_once "./Services/RTE/classes/class.$rtestring.php";
162  $rte = new $rtestring();
163  $rte->addPlugin("latex");
164  $rte->addButton("latex"); $rte->addButton("pastelatex");
165  include_once "./classes/class.ilObject.php";
166  $obj_id = $_GET["q_id"];
167  $obj_type = ilObject::_lookupType($_GET["ref_id"], TRUE);
168  $rte->addRTESupport($obj_id, $obj_type, "assessment");
169 
170  $this->tpl->parseCurrentBlock();
171  $this->tpl->setCurrentBlock("adm_content");
172  // $this->tpl->setVariable("BODY_ATTRIBUTES", " onload=\"initialSelect();\"");
173  $this->tpl->parseCurrentBlock();
174  }
175 
179  function checkInput()
180  {
181  $cmd = $this->ctrl->getCmd();
182 
183  if ((!$_POST["title"]) or (!$_POST["author"]) or (!$_POST["question"]))
184  {
185 //echo "<br>checkInput1:FALSE";
186  return false;
187  }
188  foreach ($_POST as $key => $value)
189  {
190  if (preg_match("/range_(\d+)/", $key, $matches))
191  {
192  if (!$value)
193  {
194 //echo "<br>checkInput2:FALSE";
195  return false;
196  }
197  }
198  }
199 
200  return true;
201  }
202 
212  function checkRange()
213  {
214  include_once "./Services/Math/classes/class.EvalMath.php";
215  $eval = new EvalMath();
216  $eval->suppress_errors = TRUE;
217  if (($eval->e($_POST["rang_lower_limit"]) !== FALSE) AND ($eval->e($_POST ["range_upper_limit"]) !== FALSE))
218  {
219  if ($eval->e($_POST["rang_lower_limit"]) < $eval->e($_POST["range_upper_limit"]))
220  {
221  return TRUE;
222  }
223  else
224  {
225  return FALSE;
226  }
227  }
228  else
229  {
230  return FALSE;
231  }
232  }
233 
242  function writePostData()
243  {
244  include_once "./Services/Math/classes/class.EvalMath.php";
245  $eval = new EvalMath();
246  $eval->suppress_errors = TRUE;
247 
248  $saved = false;
249  $result = 0;
250  if ((!$_POST["title"]) or (!$_POST["author"]) or (!$_POST["question"]) or (!$_POST["maxchars"]))
251  {
252  $result = 1;
253  }
254 
255  $this->object->setTitle(ilUtil::stripSlashes($_POST["title"]));
256  $this->object->setAuthor(ilUtil::stripSlashes($_POST["author"]));
257  $this->object->setComment(ilUtil::stripSlashes($_POST["comment"]));
258  include_once "./Services/AdvancedEditing/classes/class.ilObjAdvancedEditing.php";
259  $questiontext = ilUtil::stripSlashes($_POST["question"], false, ilObjAdvancedEditing::_getUsedHTMLTagsAsString("assessment"));
260  $this->object->setQuestion($questiontext);
261  $this->object->setSuggestedSolution($_POST["solution_hint"], 0);
262  $this->object->setShuffle($_POST["shuffle"]);
263  $this->object->setMaxChars($_POST["maxchars"]);
264 
265  // adding estimated working time
266  $saved = $saved | $this->writeOtherPostData($result);
267 
268  // Delete all existing ranges and create new answers from the form data
269  $this->object->flushRanges();
270 
271  // Add all answers from the form into the object
272 
273  // ...for Numeric with single response
274  foreach ($_POST as $key => $value)
275  {
276  if (preg_match("/lowerlimit_(\d+)/", $key, $matches))
277  {
278  $points = $_POST["points_$matches[1]"];
279  if ($points < 0)
280  {
281  $result = 1;
282  $this->setErrorMessage($this->lng->txt("negative_points_not_allowed"));
283  }
284  $lowerlimit = str_replace(",", ".", $_POST["lowerlimit_".$matches[1]]);
285  if (strlen($lowerlimit) == 0) $lowerlimit = 0.0;
286  if ($eval->e($lowerlimit) === FALSE)
287  {
288  $this->setErrorMessage($this->lng->txt("value_is_not_a_numeric_value"));
289  $result = 1;
290  }
291  $upperlimit = str_replace(",", ".", $_POST["upperlimit_".$matches[1]]);
292  if (strlen($upperlimit) == 0) $upperlimit = 0.0;
293  if ($eval->e($upperlimit) === FALSE)
294  {
295  $this->setErrorMessage($this->lng->txt("value_is_not_a_numeric_value"));
296  $result = 1;
297  }
298  $this->object->addRange(
299  $lowerlimit,
300  $upperlimit,
301  $points,
302  $matches[1]
303  );
304  }
305  }
306 
307  if ($saved)
308  {
309  // If the question was saved automatically before an upload, we have to make
310  // sure, that the state after the upload is saved. Otherwise the user could be
311  // irritated, if he presses cancel, because he only has the question state before
312  // the upload process.
313  $this->object->saveToDb();
314  $this->ctrl->setParameter($this, "q_id", $this->object->getId());
315  }
316 
317  return $result;
318  }
319 
320  function outQuestionForTest($formaction, $active_id, $pass = NULL, $is_postponed = FALSE, $use_post_solutions = FALSE)
321  {
322  $test_output = $this->getTestOutput($active_id, $pass, $is_postponed, $use_post_solutions);
323  $this->tpl->setVariable("QUESTION_OUTPUT", $test_output);
324  $this->tpl->setVariable("FORMACTION", $formaction);
325  }
326 
327  function getSolutionOutput($active_id, $pass = NULL, $graphicalOutput = FALSE, $result_output = FALSE, $show_question_only = TRUE, $show_feedback = FALSE, $show_correct_solution = FALSE)
328  {
329  // get the solution of the user for the active pass or from the last pass if allowed
330  $solutions = array();
331  if (($active_id > 0) && (!$show_correct_solution))
332  {
333  $solutions =& $this->object->getSolutionValues($active_id, $pass);
334  }
335  else
336  {
337  foreach ($this->object->ranges as $key => $range)
338  {
339  array_push($solutions, array("value1" => sprintf($this->lng->txt("value_between_x_and_y"), $range->getLowerLimit(), $range->getUpperLimit())));
340  }
341  }
342 
343  // generate the question output
344  include_once "./classes/class.ilTemplate.php";
345  $template = new ilTemplate("tpl.il_as_qpl_numeric_output_solution.html", TRUE, TRUE, "Modules/TestQuestionPool");
346  $solutiontemplate = new ilTemplate("tpl.il_as_tst_solution_output.html",TRUE, TRUE, "Modules/TestQuestionPool");
347  if (is_array($solutions))
348  {
349  if (($active_id > 0) && (!$show_correct_solution))
350  {
351  if ($graphicalOutput)
352  {
353  // output of ok/not ok icons for user entered solutions
354  if ($this->object->getReachedPoints($active_id, $pass) == $this->object->getMaximumPoints())
355  {
356  $template->setCurrentBlock("icon_ok");
357  $template->setVariable("ICON_OK", ilUtil::getImagePath("icon_ok.gif"));
358  $template->setVariable("TEXT_OK", $this->lng->txt("answer_is_right"));
359  $template->parseCurrentBlock();
360  }
361  else
362  {
363  $template->setCurrentBlock("icon_ok");
364  $template->setVariable("ICON_NOT_OK", ilUtil::getImagePath("icon_not_ok.gif"));
365  $template->setVariable("TEXT_NOT_OK", $this->lng->txt("answer_is_wrong"));
366  $template->parseCurrentBlock();
367  }
368  }
369  }
370  foreach ($solutions as $solution)
371  {
372  $template->setVariable("NUMERIC_VALUE", $solution["value1"]);
373  }
374  if (count($solutions) == 0)
375  {
376  $template->setVariable("NUMERIC_VALUE", "&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;");
377  }
378  }
379  $template->setVariable("NUMERIC_SIZE", $this->object->getMaxChars());
380  $questiontext = $this->object->getQuestion();
381  $template->setVariable("QUESTIONTEXT", $this->object->prepareTextareaOutput($questiontext, TRUE));
382  $questionoutput = $template->get();
383  $feedback = ($show_feedback) ? $this->getAnswerFeedbackOutput($active_id, $pass) : "";
384  if (strlen($feedback)) $solutiontemplate->setVariable("FEEDBACK", $feedback);
385  $solutiontemplate->setVariable("SOLUTION_OUTPUT", $questionoutput);
386 
387  $solutionoutput = $solutiontemplate->get();
388  if (!$show_question_only)
389  {
390  // get page object output
391  $solutionoutput = $this->getILIASPage($solutionoutput);
392  }
393  return $solutionoutput;
394  }
395 
396  function getPreview($show_question_only = FALSE)
397  {
398  // generate the question output
399  include_once "./classes/class.ilTemplate.php";
400  $template = new ilTemplate("tpl.il_as_qpl_numeric_output.html", TRUE, TRUE, "Modules/TestQuestionPool");
401  $template->setVariable("NUMERIC_SIZE", $this->object->getMaxChars());
402  $questiontext = $this->object->getQuestion();
403  $template->setVariable("QUESTIONTEXT", $this->object->prepareTextareaOutput($questiontext, TRUE));
404  $questionoutput = $template->get();
405  if (!$show_question_only)
406  {
407  // get page object output
408  $questionoutput = $this->getILIASPage($questionoutput);
409  }
410  return $questionoutput;
411  }
412 
413  function getTestOutput($active_id, $pass = NULL, $is_postponed = FALSE, $use_post_solutions = FALSE)
414  {
415  // get the solution of the user for the active pass or from the last pass if allowed
416  if ($active_id)
417  {
418  $solutions = NULL;
419  include_once "./Modules/Test/classes/class.ilObjTest.php";
420  if (!ilObjTest::_getUsePreviousAnswers($active_id, true))
421  {
422  if (is_null($pass)) $pass = ilObjTest::_getPass($active_id);
423  }
424  $solutions =& $this->object->getSolutionValues($active_id, $pass);
425  }
426 
427  // generate the question output
428  include_once "./classes/class.ilTemplate.php";
429  $template = new ilTemplate("tpl.il_as_qpl_numeric_output.html", TRUE, TRUE, "Modules/TestQuestionPool");
430  if (is_array($solutions))
431  {
432  foreach ($solutions as $solution)
433  {
434  $template->setVariable("NUMERIC_VALUE", " value=\"".$solution["value1"]."\"");
435  }
436  }
437  $template->setVariable("NUMERIC_SIZE", $this->object->getMaxChars());
438  $questiontext = $this->object->getQuestion();
439  $template->setVariable("QUESTIONTEXT", $this->object->prepareTextareaOutput($questiontext, TRUE));
440  $questionoutput = $template->get();
441  $pageoutput = $this->outQuestionPage("", $is_postponed, $active_id, $questionoutput);
442  return $pageoutput;
443  }
444 
446  {
447  $_SESSION["subquestion_index"] = 0;
448  if ($_POST["cmd"]["addSuggestedSolution"])
449  {
450  if ($this->writePostData())
451  {
453  $this->editQuestion();
454  return;
455  }
456  if (!$this->checkInput())
457  {
458  ilUtil::sendInfo($this->lng->txt("fill_out_all_required_fields_add_answer"));
459  $this->editQuestion();
460  return;
461  }
462  }
463  $this->object->saveToDb();
464  $this->ctrl->setParameter($this, "q_id", $this->object->getId());
465  $this->tpl->setVariable("HEADER", $this->object->getTitle());
466  $this->getQuestionTemplate();
468  }
469 
477  function saveFeedback()
478  {
479  include_once "./Services/AdvancedEditing/classes/class.ilObjAdvancedEditing.php";
480  $this->object->saveFeedbackGeneric(0, ilUtil::stripSlashes($_POST["feedback_incomplete"], false, ilObjAdvancedEditing::_getUsedHTMLTagsAsString("assessment")));
481  $this->object->saveFeedbackGeneric(1, ilUtil::stripSlashes($_POST["feedback_complete"], false, ilObjAdvancedEditing::_getUsedHTMLTagsAsString("assessment")));
482  $this->object->cleanupMediaObjectUsage();
484  }
485 
493  function feedback()
494  {
495  $this->tpl->addBlockFile("ADM_CONTENT", "feedback", "tpl.il_as_qpl_numeric_feedback.html", "Modules/TestQuestionPool");
496  $this->tpl->setVariable("FEEDBACK_TEXT", $this->lng->txt("feedback"));
497  $this->tpl->setVariable("FEEDBACK_COMPLETE", $this->lng->txt("feedback_complete_solution"));
498  $this->tpl->setVariable("VALUE_FEEDBACK_COMPLETE", ilUtil::prepareFormOutput($this->object->prepareTextareaOutput($this->object->getFeedbackGeneric(1)), FALSE));
499  $this->tpl->setVariable("FEEDBACK_INCOMPLETE", $this->lng->txt("feedback_incomplete_solution"));
500  $this->tpl->setVariable("VALUE_FEEDBACK_INCOMPLETE", ilUtil::prepareFormOutput($this->object->prepareTextareaOutput($this->object->getFeedbackGeneric(0)), FALSE));
501  global $rbacsystem;
502  if ($rbacsystem->checkAccess('write', $_GET["ref_id"]))
503  {
504  $this->tpl->setVariable("SAVE", $this->lng->txt("save"));
505  }
506  $this->tpl->setVariable("FORMACTION", $this->ctrl->getFormAction($this));
507 
508  include_once "./Services/RTE/classes/class.ilRTE.php";
509  $rtestring = ilRTE::_getRTEClassname();
510  include_once "./Services/RTE/classes/class.$rtestring.php";
511  $rte = new $rtestring();
512  $rte->addPlugin("latex");
513  $rte->addButton("latex"); $rte->addButton("pastelatex");
514  include_once "./classes/class.ilObject.php";
515  $obj_id = $_GET["q_id"];
516  $obj_type = ilObject::_lookupType($_GET["ref_id"], TRUE);
517  $rte->addRTESupport($obj_id, $obj_type, "assessment");
518  }
519 
527  function setQuestionTabs()
528  {
529  global $rbacsystem, $ilTabs;
530 
531  $this->ctrl->setParameterByClass("ilpageobjectgui", "q_id", $_GET["q_id"]);
532  include_once "./Modules/TestQuestionPool/classes/class.assQuestion.php";
533  $q_type = $this->object->getQuestionType();
534 
535  if (strlen($q_type))
536  {
537  $classname = $q_type . "GUI";
538  $this->ctrl->setParameterByClass(strtolower($classname), "sel_question_types", $q_type);
539  $this->ctrl->setParameterByClass(strtolower($classname), "q_id", $_GET["q_id"]);
540  }
541 
542  if ($_GET["q_id"])
543  {
544  if ($rbacsystem->checkAccess('write', $_GET["ref_id"]))
545  {
546  // edit page
547  $ilTabs->addTarget("edit_content",
548  $this->ctrl->getLinkTargetByClass("ilPageObjectGUI", "edit"),
549  array("edit", "insert", "exec_pg"),
550  "", "", $force_active);
551  }
552 
553  // edit page
554  $ilTabs->addTarget("preview",
555  $this->ctrl->getLinkTargetByClass("ilPageObjectGUI", "preview"),
556  array("preview"),
557  "ilPageObjectGUI", "", $force_active);
558  }
559 
560  $force_active = false;
561  if ($rbacsystem->checkAccess('write', $_GET["ref_id"]))
562  {
563  $url = "";
564  if ($classname) $url = $this->ctrl->getLinkTargetByClass($classname, "editQuestion");
565  // edit question properties
566  $ilTabs->addTarget("edit_properties",
567  $url,
568  array("editQuestion", "save", "cancel", "addSuggestedSolution",
569  "cancelExplorer", "linkChilds", "removeSuggestedSolution",
570  "saveEdit"),
571  $classname, "", $force_active);
572  }
573 
574  if ($_GET["q_id"])
575  {
576  $ilTabs->addTarget("feedback",
577  $this->ctrl->getLinkTargetByClass($classname, "feedback"),
578  array("feedback", "saveFeedback"),
579  $classname, "");
580  }
581 
582  // Assessment of questions sub menu entry
583  if ($_GET["q_id"])
584  {
585  $ilTabs->addTarget("statistics",
586  $this->ctrl->getLinkTargetByClass($classname, "assessment"),
587  array("assessment"),
588  $classname, "");
589  }
590 
591  if (($_GET["calling_test"] > 0) || ($_GET["test_ref_id"] > 0))
592  {
593  $ref_id = $_GET["calling_test"];
594  if (strlen($ref_id) == 0) $ref_id = $_GET["test_ref_id"];
595  $ilTabs->setBackTarget($this->lng->txt("backtocallingtest"), "ilias.php?baseClass=ilObjTestGUI&cmd=questions&ref_id=$ref_id");
596  }
597  else
598  {
599  $ilTabs->setBackTarget($this->lng->txt("qpl"), $this->ctrl->getLinkTargetByClass("ilobjquestionpoolgui", "questions"));
600  }
601  }
602 }
603 ?>