ILIAS  Release_4_0_x_branch Revision 61816
 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 
280  }
281 
282  if (($active_id > 0) && (!$show_correct_solution))
283  {
284  if ($graphicalOutput)
285  {
286  // output of ok/not ok icons for user entered solutions
287  $reached_points = $this->object->getReachedPoints($active_id, $pass);
288  if ($reached_points == $this->object->getMaximumPoints())
289  {
290  $template->setCurrentBlock("icon_ok");
291  $template->setVariable("ICON_OK", ilUtil::getImagePath("icon_ok.gif"));
292  $template->setVariable("TEXT_OK", $this->lng->txt("answer_is_right"));
293  $template->parseCurrentBlock();
294  }
295  else
296  {
297  $template->setCurrentBlock("icon_ok");
298  if ($reached_points > 0)
299  {
300  $template->setVariable("ICON_NOT_OK", ilUtil::getImagePath("icon_mostly_ok.gif"));
301  $template->setVariable("TEXT_NOT_OK", $this->lng->txt("answer_is_not_correct_but_positive"));
302  }
303  else
304  {
305  $template->setVariable("ICON_NOT_OK", ilUtil::getImagePath("icon_not_ok.gif"));
306  $template->setVariable("TEXT_NOT_OK", $this->lng->txt("answer_is_wrong"));
307  }
308  $template->parseCurrentBlock();
309  }
310  }
311  }
312 
313  if (count($params))
314  {
315  $template->setCurrentBlock("flash_vars");
316  $template->setVariable("FLASH_VARS", join($params, "&"));
317  $template->parseCurrentBlock();
318  $template->setCurrentBlock("applet_parameters");
319  $template->setVariable("PARAM_VALUE", join($params, "&"));
320  $template->parseCurrentBlock();
321  }
322  $template->setVariable("QUESTIONTEXT", $this->object->prepareTextareaOutput($this->object->getQuestion(), TRUE));
323  $template->setVariable("APPLET_WIDTH", $this->object->getWidth());
324  $template->setVariable("APPLET_HEIGHT", $this->object->getHeight());
325  $template->setVariable("ID", $this->object->getId());
326  $template->setVariable("APPLET_PATH", $this->object->getFlashPathWeb() . $this->object->getApplet());
327  $template->setVariable("APPLET_FILE", $this->object->getApplet());
328 
329  $questionoutput = $template->get();
330  $solutiontemplate = new ilTemplate("tpl.il_as_tst_solution_output.html",TRUE, TRUE, "Modules/TestQuestionPool");
331  $solutiontemplate->setVariable("SOLUTION_OUTPUT", $questionoutput);
332  $solutionoutput = $solutiontemplate->get();
333  if (!$show_question_only)
334  {
335  // get page object output
336  $solutionoutput = $this->getILIASPage($solutionoutput);
337  }
338  return $solutionoutput;
339  }
340 
341  function getPreview($show_question_only = FALSE)
342  {
343  $template = new ilTemplate("tpl.il_as_qpl_flash_question_output.html",TRUE, TRUE, "Modules/TestQuestionPool");
344  $params = array();
345  if (is_array($this->object->getParameters()))
346  {
347  foreach ($this->object->getParameters() as $name => $value)
348  {
349  array_push($params, urlencode($name) . "=" . urlencode($value));
350  }
351  }
352  if (count($params))
353  {
354  $template->setCurrentBlock("flash_vars");
355  $template->setVariable("FLASH_VARS", join($params, "&"));
356  $template->parseCurrentBlock();
357  $template->setCurrentBlock("applet_parameters");
358  $template->setVariable("PARAM_VALUE", join($params, "&"));
359  $template->parseCurrentBlock();
360  }
361  $template->setVariable("QUESTIONTEXT", $this->object->prepareTextareaOutput($this->object->getQuestion(), TRUE));
362  $template->setVariable("APPLET_WIDTH", $this->object->getWidth());
363  $template->setVariable("APPLET_HEIGHT", $this->object->getHeight());
364  $template->setVariable("ID", $this->object->getId());
365  $template->setVariable("APPLET_PATH", $this->object->getFlashPathWeb() . $this->object->getApplet());
366  $template->setVariable("APPLET_FILE", $this->object->getApplet());
367  $questionoutput = $template->get();
368  if (!$show_question_only)
369  {
370  // get page object output
371  $questionoutput = $this->getILIASPage($questionoutput);
372  }
373  return $questionoutput;
374  }
375 
376  function getTestOutput($active_id, $pass = NULL, $is_postponed = FALSE, $use_post_solutions = FALSE, $show_feedback = FALSE)
377  {
378  // generate the question output
379  $template = new ilTemplate("tpl.il_as_qpl_flash_question_output.html",TRUE, TRUE, "Modules/TestQuestionPool");
380  $params = array();
381  if (is_array($this->object->getParameters()))
382  {
383  foreach ($this->object->getParameters() as $name => $value)
384  {
385  array_push($params, urlencode($name) . "=" . urlencode($value));
386  }
387  }
388 
389  array_push($params, "session_id=" . urlencode($_COOKIE["PHPSESSID"]));
390  array_push($params, "client=" . urlencode(CLIENT_ID));
391  array_push($params, "points_max=" . urlencode($this->object->getPoints()));
392  array_push($params, "server=" . urlencode(ilUtil::removeTrailingPathSeparators(ILIAS_HTTP_PATH) . "/webservice/soap/server.php?wsdl"));
393  if (strlen($pass))
394  {
395  array_push($params, "pass=" . $pass);
396  }
397  else
398  {
399  include_once "./Modules/Test/classes/class.ilObjTest.php";
400  array_push($params, "pass=" . ilObjTest::_getPass($active_id));
401  }
402  if ($active_id)
403  {
404  array_push($params, "active_id=" . $active_id);
405  }
406  array_push($params, "question_id=" . $this->object->getId());
407 
408  if (count($params))
409  {
410  $template->setCurrentBlock("flash_vars");
411  $template->setVariable("FLASH_VARS", join($params, "&"));
412  $template->parseCurrentBlock();
413  $template->setCurrentBlock("applet_parameters");
414  $template->setVariable("PARAM_VALUE", join($params, "&"));
415  $template->parseCurrentBlock();
416  }
417  $template->setVariable("QUESTIONTEXT", $this->object->prepareTextareaOutput($this->object->getQuestion(), TRUE));
418  $template->setVariable("APPLET_WIDTH", $this->object->getWidth());
419  $template->setVariable("APPLET_HEIGHT", $this->object->getHeight());
420  $template->setVariable("ID", $this->object->getId());
421  $template->setVariable("APPLET_PATH", $this->object->getFlashPathWeb() . $this->object->getApplet());
422  $template->setVariable("APPLET_FILE", $this->object->getFlashPathWeb() . $this->object->getApplet());
423  $questionoutput = $template->get();
424 
425  $pageoutput = $this->outQuestionPage("", $is_postponed, $active_id, $questionoutput);
426  return $pageoutput;
427  }
428 
434  function saveFeedback()
435  {
436  include_once "./Services/AdvancedEditing/classes/class.ilObjAdvancedEditing.php";
437  $errors = $this->feedback(true);
438  $this->object->saveFeedbackGeneric(0, $_POST["feedback_incomplete"]);
439  $this->object->saveFeedbackGeneric(1, $_POST["feedback_complete"]);
440  $this->object->cleanupMediaObjectUsage();
442  }
443 
449  function setQuestionTabs()
450  {
451  global $rbacsystem, $ilTabs;
452 
453  $this->ctrl->setParameterByClass("ilpageobjectgui", "q_id", $_GET["q_id"]);
454  include_once "./Modules/TestQuestionPool/classes/class.assQuestion.php";
455  $q_type = $this->object->getQuestionType();
456 
457  if (strlen($q_type))
458  {
459  $classname = $q_type . "GUI";
460  $this->ctrl->setParameterByClass(strtolower($classname), "sel_question_types", $q_type);
461  $this->ctrl->setParameterByClass(strtolower($classname), "q_id", $_GET["q_id"]);
462  }
463 
464  if ($_GET["q_id"])
465  {
466  if ($rbacsystem->checkAccess('write', $_GET["ref_id"]))
467  {
468  // edit page
469  $ilTabs->addTarget("edit_content",
470  $this->ctrl->getLinkTargetByClass("ilPageObjectGUI", "edit"),
471  array("edit", "insert", "exec_pg"),
472  "", "", $force_active);
473  }
474 
475  // edit page
476  $ilTabs->addTarget("preview",
477  $this->ctrl->getLinkTargetByClass("ilPageObjectGUI", "preview"),
478  array("preview"),
479  "ilPageObjectGUI", "", $force_active);
480  }
481 
482  $force_active = false;
483  if ($rbacsystem->checkAccess('write', $_GET["ref_id"]))
484  {
485  $url = "";
486  if ($classname) $url = $this->ctrl->getLinkTargetByClass($classname, "editQuestion");
487  $commands = $_POST["cmd"];
488  if (is_array($commands))
489  {
490  foreach ($commands as $key => $value)
491  {
492  if (preg_match("/^suggestrange_.*/", $key, $matches))
493  {
494  $force_active = true;
495  }
496  }
497  }
498  // edit question properties
499  $ilTabs->addTarget("edit_properties",
500  $url,
501  array("editQuestion", "save", "flashAddParam", "saveEdit", "originalSyncForm"),
502  $classname, "", $force_active);
503  }
504 
505  if ($_GET["q_id"])
506  {
507  $ilTabs->addTarget("feedback",
508  $this->ctrl->getLinkTargetByClass($classname, "feedback"),
509  array("feedback", "saveFeedback"),
510  $classname, "");
511  }
512 
513  if ($_GET["q_id"])
514  {
515  $ilTabs->addTarget("solution_hint",
516  $this->ctrl->getLinkTargetByClass($classname, "suggestedsolution"),
517  array("suggestedsolution", "saveSuggestedSolution", "outSolutionExplorer", "cancel",
518  "addSuggestedSolution","cancelExplorer", "linkChilds", "removeSuggestedSolution"
519  ),
520  $classname,
521  ""
522  );
523  }
524 
525  // Assessment of questions sub menu entry
526  if ($_GET["q_id"])
527  {
528  $ilTabs->addTarget("statistics",
529  $this->ctrl->getLinkTargetByClass($classname, "assessment"),
530  array("assessment"),
531  $classname, "");
532  }
533 
534  if (($_GET["calling_test"] > 0) || ($_GET["test_ref_id"] > 0))
535  {
536  $ref_id = $_GET["calling_test"];
537  if (strlen($ref_id) == 0) $ref_id = $_GET["test_ref_id"];
538  $ilTabs->setBackTarget($this->lng->txt("backtocallingtest"), "ilias.php?baseClass=ilObjTestGUI&cmd=questions&ref_id=$ref_id");
539  }
540  else
541  {
542  $ilTabs->setBackTarget($this->lng->txt("qpl"), $this->ctrl->getLinkTargetByClass("ilobjquestionpoolgui", "questions"));
543  }
544  }
545 }
546 ?>