ILIAS  eassessment Revision 61809
 All Data Structures Namespaces Files Functions Variables Groups Pages
class.assFlashQuestionGUI.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 
37 {
38  private $newUnitId;
39 
48  function __construct($id = -1)
49  {
51  include_once "./Modules/TestQuestionPool/classes/class.assFlashQuestion.php";
52  $this->object = new assFlashQuestion();
53  $this->newUnitId = null;
54  if ($id >= 0)
55  {
56  $this->object->loadFromDb($id);
57  }
58  }
59 
60  function getCommand($cmd)
61  {
62  if (preg_match("/suggestrange_(.*?)/", $cmd, $matches))
63  {
64  $cmd = "suggestRange";
65  }
66  return $cmd;
67  }
68 
74  function suggestRange()
75  {
76  if ($this->writePostData())
77  {
79  }
80  $this->editQuestion();
81  }
82 
89  function writePostData($always = false)
90  {
91  $hasErrors = (!$always) ? $this->editQuestion(true) : false;
92  if (!$hasErrors)
93  {
94  global $ilLog;
95  $this->setErrorMessage("");
96  if ($_POST['flash']['delete'] == 1)
97  {
98  $this->object->deleteApplet();
99  }
100  else
101  {
102  $this->object->setApplet($_POST['flash']['filename']);
103  }
104  if ($_FILES["flash"]["tmp_name"])
105  {
106  $this->object->deleteApplet();
107  $filename = $this->object->moveUploadedFile($_FILES["flash"]["tmp_name"], $_FILES["flash"]["name"]);
108  $this->object->setApplet($filename);
109  }
110  $this->object->clearParameters();
111  if (is_array($_POST["flash"]["flash_param_name"]))
112  {
113  foreach ($_POST['flash']['flash_param_name'] as $idx => $val)
114  {
115  $this->object->addParameter($val, $_POST['flash']['flash_param_value'][$idx]);
116  }
117  }
118  if (is_array($_POST['flash']['flash_param_delete']))
119  {
120  foreach ($_POST['flash']['flash_param_delete'] as $key => $value)
121  {
122  $this->object->removeParameter($_POST['flash']['flash_param_name'][$key]);
123  }
124  }
125  $this->object->setTitle($_POST["title"]);
126  $this->object->setAuthor($_POST["author"]);
127  $this->object->setComment($_POST["comment"]);
128  $questiontext = $_POST["question"];
129  $this->object->setQuestion($questiontext);
130  $this->object->setEstimatedWorkingTime(
131  $_POST["Estimated"]["hh"],
132  $_POST["Estimated"]["mm"],
133  $_POST["Estimated"]["ss"]
134  );
135  $this->object->setWidth($_POST["flash"]["width"]);
136  $this->object->setHeight($_POST["flash"]["height"]);
137  $this->object->setPoints($_POST["points"]);
138  return 0;
139  }
140  else
141  {
142  return 1;
143  }
144  }
145 
151  public function editQuestion($checkonly = FALSE)
152  {
153  $save = ((strcmp($this->ctrl->getCmd(), "save") == 0) || (strcmp($this->ctrl->getCmd(), "saveEdit") == 0)) ? TRUE : FALSE;
154  $this->getQuestionTemplate();
155 
156  include_once("./Services/Form/classes/class.ilPropertyFormGUI.php");
157  $form = new ilPropertyFormGUI();
158  $form->setFormAction($this->ctrl->getFormAction($this));
159  $form->setTitle($this->outQuestionType());
160  $form->setMultipart(TRUE);
161  $form->setTableWidth("100%");
162  $form->setId("flash");
163 
164  $this->addBasicQuestionFormProperties($form);
165 
166  // flash file
167  $flash = new ilFlashFileInputGUI($this->lng->txt("flashfile"), "flash");
168  $flash->setRequired(TRUE);
169  if (strlen($this->object->getApplet()))
170  {
171  $flash->setApplet($this->object->getApplet());
172  $flash->setAppletPathWeb($this->object->getFlashPathWeb());
173  }
174  $flash->setWidth($this->object->getWidth());
175  $flash->setHeight($this->object->getHeight());
176  $flash->setParameters($this->object->getParameters());
177  $form->addItem($flash);
178  if ($this->object->getId())
179  {
180  $hidden = new ilHiddenInputGUI("", "ID");
181  $hidden->setValue($this->object->getId());
182  $form->addItem($hidden);
183  }
184  // points
185  $points = new ilNumberInputGUI($this->lng->txt("points"), "points");
186  $points->setValue($this->object->getPoints());
187  $points->setRequired(TRUE);
188  $points->setSize(3);
189  $points->setMinValue(0.0);
190  $form->addItem($points);
191 
192  $this->addQuestionFormCommandButtons($form);
193 
194  $errors = false;
195 
196  if ($save)
197  {
198  $form->setValuesByPost();
199  $errors = !$form->checkInput();
200  $form->setValuesByPost(); // again, because checkInput now performs the whole stripSlashes handling and we need this if we don't want to have duplication of backslashes
201  if ($errors) $checkonly = false;
202  }
203 
204  if (!$checkonly) $this->tpl->setVariable("QUESTION_DATA", $form->getHTML());
205  return $errors;
206  }
207 
208  function flashAddParam()
209  {
210  $this->writePostData();
211  $this->object->addParameter("", "");
212  $this->editQuestion();
213  }
214 
215  function outQuestionForTest($formaction, $active_id, $pass = NULL, $is_postponed = FALSE, $use_post_solutions = FALSE, $show_feedback = FALSE)
216  {
217  $test_output = $this->getTestOutput($active_id, $pass, $is_postponed, $use_post_solutions, $show_feedback);
218  $this->tpl->setVariable("QUESTION_OUTPUT", $test_output);
219  $this->tpl->setVariable("FORMACTION", $formaction);
220  }
221 
236  $active_id,
237  $pass = NULL,
238  $graphicalOutput = FALSE,
239  $result_output = FALSE,
240  $show_question_only = TRUE,
241  $show_feedback = FALSE,
242  $show_correct_solution = FALSE,
243  $show_manual_scoring = FALSE
244  )
245  {
246  // get the solution of the user for the active pass or from the last pass if allowed
247  $template = new ilTemplate("tpl.il_as_qpl_flash_question_output_solution.html", TRUE, TRUE, "Modules/TestQuestionPool");
248 
249  $params = array();
250  if (is_array($this->object->getParameters()))
251  {
252  foreach ($this->object->getParameters() as $name => $value)
253  {
254  array_push($params, urlencode($name) . "=" . urlencode($value));
255  }
256  }
257 
258  array_push($params, "session_id=" . urlencode($_COOKIE["PHPSESSID"]));
259  array_push($params, "client=" . urlencode(CLIENT_ID));
260  array_push($params, "points_max=" . urlencode($this->object->getPoints()));
261  array_push($params, "server=" . urlencode(ilUtil::removeTrailingPathSeparators(ILIAS_HTTP_PATH) . "/webservice/soap/server.php?wsdl"));
262  if (!is_null($pass))
263  {
264  array_push($params, "pass=" . $pass);
265  }
266  else
267  {
268  include_once "./Modules/Test/classes/class.ilObjTest.php";
269  array_push($params, "pass=" . ilObjTest::_getPass($active_id));
270  }
271  if ($active_id)
272  {
273  array_push($params, "active_id=" . $active_id);
274  }
275  array_push($params, "question_id=" . $this->object->getId());
276 
277  if ($show_correct_solution)
278  {
279  array_push($params, "solution=correct");
280  }
281  else
282  {
283  array_push($params, "solution=user");
284  }
285 
286  if (($active_id > 0) && (!$show_correct_solution))
287  {
288  if ($graphicalOutput)
289  {
290  // output of ok/not ok icons for user entered solutions
291  $reached_points = $this->object->getReachedPoints($active_id, $pass);
292  if ($reached_points == $this->object->getMaximumPoints())
293  {
294  $template->setCurrentBlock("icon_ok");
295  $template->setVariable("ICON_OK", ilUtil::getImagePath("icon_ok.gif"));
296  $template->setVariable("TEXT_OK", $this->lng->txt("answer_is_right"));
297  $template->parseCurrentBlock();
298  }
299  else
300  {
301  $template->setCurrentBlock("icon_ok");
302  if ($reached_points > 0)
303  {
304  $template->setVariable("ICON_NOT_OK", ilUtil::getImagePath("icon_mostly_ok.gif"));
305  $template->setVariable("TEXT_NOT_OK", $this->lng->txt("answer_is_not_correct_but_positive"));
306  }
307  else
308  {
309  $template->setVariable("ICON_NOT_OK", ilUtil::getImagePath("icon_not_ok.gif"));
310  $template->setVariable("TEXT_NOT_OK", $this->lng->txt("answer_is_wrong"));
311  }
312  $template->parseCurrentBlock();
313  }
314  }
315  }
316 
317  if (count($params))
318  {
319  $template->setCurrentBlock("flash_vars");
320  $template->setVariable("FLASH_VARS", join($params, "&"));
321  $template->parseCurrentBlock();
322  $template->setCurrentBlock("applet_parameters");
323  $template->setVariable("PARAM_VALUE", join($params, "&"));
324  $template->parseCurrentBlock();
325  }
326  $template->setVariable("QUESTIONTEXT", $this->object->prepareTextareaOutput($this->object->getQuestion(), TRUE));
327  $template->setVariable("APPLET_WIDTH", $this->object->getWidth());
328  $template->setVariable("APPLET_HEIGHT", $this->object->getHeight());
329  $template->setVariable("ID", $this->object->getId());
330  $template->setVariable("APPLET_PATH", $this->object->getFlashPathWeb() . $this->object->getApplet());
331  $template->setVariable("APPLET_FILE", $this->object->getApplet());
332 
333  $questionoutput = $template->get();
334  $solutiontemplate = new ilTemplate("tpl.il_as_tst_solution_output.html",TRUE, TRUE, "Modules/TestQuestionPool");
335  $solutiontemplate->setVariable("SOLUTION_OUTPUT", $questionoutput);
336  $solutionoutput = $solutiontemplate->get();
337  if (!$show_question_only)
338  {
339  // get page object output
340  $solutionoutput = $this->getILIASPage($solutionoutput);
341  }
342  return $solutionoutput;
343  }
344 
345  function getPreview($show_question_only = FALSE)
346  {
347  $template = new ilTemplate("tpl.il_as_qpl_flash_question_output.html",TRUE, TRUE, "Modules/TestQuestionPool");
348  $params = array();
349  if (is_array($this->object->getParameters()))
350  {
351  foreach ($this->object->getParameters() as $name => $value)
352  {
353  array_push($params, urlencode($name) . "=" . urlencode($value));
354  }
355  }
356  if (count($params))
357  {
358  $template->setCurrentBlock("flash_vars");
359  $template->setVariable("FLASH_VARS", join($params, "&"));
360  $template->parseCurrentBlock();
361  $template->setCurrentBlock("applet_parameters");
362  $template->setVariable("PARAM_VALUE", join($params, "&"));
363  $template->parseCurrentBlock();
364  }
365  $template->setVariable("QUESTIONTEXT", $this->object->prepareTextareaOutput($this->object->getQuestion(), TRUE));
366  $template->setVariable("APPLET_WIDTH", $this->object->getWidth());
367  $template->setVariable("APPLET_HEIGHT", $this->object->getHeight());
368  $template->setVariable("ID", $this->object->getId());
369  $template->setVariable("APPLET_PATH", $this->object->getFlashPathWeb() . $this->object->getApplet());
370  $template->setVariable("APPLET_FILE", $this->object->getApplet());
371  $questionoutput = $template->get();
372  if (!$show_question_only)
373  {
374  // get page object output
375  $questionoutput = $this->getILIASPage($questionoutput);
376  }
377  return $questionoutput;
378  }
379 
380  function getTestOutput($active_id, $pass = NULL, $is_postponed = FALSE, $use_post_solutions = FALSE, $show_feedback = FALSE)
381  {
382  // generate the question output
383  $template = new ilTemplate("tpl.il_as_qpl_flash_question_output.html",TRUE, TRUE, "Modules/TestQuestionPool");
384  $params = array();
385  if (is_array($this->object->getParameters()))
386  {
387  foreach ($this->object->getParameters() as $name => $value)
388  {
389  array_push($params, urlencode($name) . "=" . urlencode($value));
390  }
391  }
392 
393  array_push($params, "session_id=" . urlencode($_COOKIE["PHPSESSID"]));
394  array_push($params, "client=" . urlencode(CLIENT_ID));
395  array_push($params, "points_max=" . urlencode($this->object->getPoints()));
396  array_push($params, "server=" . urlencode(ilUtil::removeTrailingPathSeparators(ILIAS_HTTP_PATH) . "/webservice/soap/server.php?wsdl"));
397  if (strlen($pass))
398  {
399  array_push($params, "pass=" . $pass);
400  }
401  else
402  {
403  include_once "./Modules/Test/classes/class.ilObjTest.php";
404  array_push($params, "pass=" . ilObjTest::_getPass($active_id));
405  }
406  if ($active_id)
407  {
408  array_push($params, "active_id=" . $active_id);
409  }
410  array_push($params, "question_id=" . $this->object->getId());
411 
412  if (count($params))
413  {
414  $template->setCurrentBlock("flash_vars");
415  $template->setVariable("FLASH_VARS", join($params, "&"));
416  $template->parseCurrentBlock();
417  $template->setCurrentBlock("applet_parameters");
418  $template->setVariable("PARAM_VALUE", join($params, "&"));
419  $template->parseCurrentBlock();
420  }
421  $template->setVariable("QUESTIONTEXT", $this->object->prepareTextareaOutput($this->object->getQuestion(), TRUE));
422  $template->setVariable("APPLET_WIDTH", $this->object->getWidth());
423  $template->setVariable("APPLET_HEIGHT", $this->object->getHeight());
424  $template->setVariable("ID", $this->object->getId());
425  $template->setVariable("APPLET_PATH", $this->object->getFlashPathWeb() . $this->object->getApplet());
426  $template->setVariable("APPLET_FILE", $this->object->getFlashPathWeb() . $this->object->getApplet());
427  $questionoutput = $template->get();
428 
429  $pageoutput = $this->outQuestionPage("", $is_postponed, $active_id, $questionoutput);
430  return $pageoutput;
431  }
432 
438  function saveFeedback()
439  {
440  include_once "./Services/AdvancedEditing/classes/class.ilObjAdvancedEditing.php";
441  $errors = $this->feedback(true);
442  $this->object->saveFeedbackGeneric(0, $_POST["feedback_incomplete"]);
443  $this->object->saveFeedbackGeneric(1, $_POST["feedback_complete"]);
444  $this->object->cleanupMediaObjectUsage();
446  }
447 
453  function setQuestionTabs()
454  {
455  global $rbacsystem, $ilTabs;
456 
457  $this->ctrl->setParameterByClass("ilpageobjectgui", "q_id", $_GET["q_id"]);
458  include_once "./Modules/TestQuestionPool/classes/class.assQuestion.php";
459  $q_type = $this->object->getQuestionType();
460 
461  if (strlen($q_type))
462  {
463  $classname = $q_type . "GUI";
464  $this->ctrl->setParameterByClass(strtolower($classname), "sel_question_types", $q_type);
465  $this->ctrl->setParameterByClass(strtolower($classname), "q_id", $_GET["q_id"]);
466  }
467 
468  if ($_GET["q_id"])
469  {
470  if ($rbacsystem->checkAccess('write', $_GET["ref_id"]))
471  {
472  // edit page
473  $ilTabs->addTarget("edit_content",
474  $this->ctrl->getLinkTargetByClass("ilPageObjectGUI", "edit"),
475  array("edit", "insert", "exec_pg"),
476  "", "", $force_active);
477  }
478 
479  // edit page
480  $ilTabs->addTarget("preview",
481  $this->ctrl->getLinkTargetByClass("ilPageObjectGUI", "preview"),
482  array("preview"),
483  "ilPageObjectGUI", "", $force_active);
484  }
485 
486  $force_active = false;
487  if ($rbacsystem->checkAccess('write', $_GET["ref_id"]))
488  {
489  $url = "";
490  if ($classname) $url = $this->ctrl->getLinkTargetByClass($classname, "editQuestion");
491  $commands = $_POST["cmd"];
492  if (is_array($commands))
493  {
494  foreach ($commands as $key => $value)
495  {
496  if (preg_match("/^suggestrange_.*/", $key, $matches))
497  {
498  $force_active = true;
499  }
500  }
501  }
502  // edit question properties
503  $ilTabs->addTarget("edit_properties",
504  $url,
505  array("editQuestion", "save", "flashAddParam", "saveEdit", "originalSyncForm"),
506  $classname, "", $force_active);
507  }
508 
509  if ($_GET["q_id"])
510  {
511  $ilTabs->addTarget("feedback",
512  $this->ctrl->getLinkTargetByClass($classname, "feedback"),
513  array("feedback", "saveFeedback"),
514  $classname, "");
515  }
516 
517  if ($_GET["q_id"])
518  {
519  $ilTabs->addTarget("solution_hint",
520  $this->ctrl->getLinkTargetByClass($classname, "suggestedsolution"),
521  array("suggestedsolution", "saveSuggestedSolution", "outSolutionExplorer", "cancel",
522  "addSuggestedSolution","cancelExplorer", "linkChilds", "removeSuggestedSolution"
523  ),
524  $classname,
525  ""
526  );
527  }
528 
529  // Assessment of questions sub menu entry
530  if ($_GET["q_id"])
531  {
532  $ilTabs->addTarget("statistics",
533  $this->ctrl->getLinkTargetByClass($classname, "assessment"),
534  array("assessment"),
535  $classname, "");
536  }
537 
538  if (($_GET["calling_test"] > 0) || ($_GET["test_ref_id"] > 0))
539  {
540  $ref_id = $_GET["calling_test"];
541  if (strlen($ref_id) == 0) $ref_id = $_GET["test_ref_id"];
542  $ilTabs->setBackTarget($this->lng->txt("backtocallingtest"), "ilias.php?baseClass=ilObjTestGUI&cmd=questions&ref_id=$ref_id");
543  }
544  else
545  {
546  $ilTabs->setBackTarget($this->lng->txt("qpl"), $this->ctrl->getLinkTargetByClass("ilobjquestionpoolgui", "questions"));
547  }
548  }
549 }
550 ?>