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