ILIAS  Release_4_2_x_branch Revision 61807
 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  $save = $this->isSaveCommand();
155  $this->getQuestionTemplate();
156 
157  include_once("./Services/Form/classes/class.ilPropertyFormGUI.php");
158  $form = new ilPropertyFormGUI();
159  $form->setFormAction($this->ctrl->getFormAction($this));
160  $form->setTitle($this->outQuestionType());
161  $form->setMultipart(TRUE);
162  $form->setTableWidth("100%");
163  $form->setId("flash");
164 
165  $this->addBasicQuestionFormProperties($form);
166 
167  // flash file
168  $flash = new ilFlashFileInputGUI($this->lng->txt("flashfile"), "flash");
169  $flash->setRequired(TRUE);
170  if (strlen($this->object->getApplet()))
171  {
172  $flash->setApplet($this->object->getApplet());
173  $flash->setAppletPathWeb($this->object->getFlashPathWeb());
174  }
175  $flash->setWidth($this->object->getWidth());
176  $flash->setHeight($this->object->getHeight());
177  $flash->setParameters($this->object->getParameters());
178  $form->addItem($flash);
179  if ($this->object->getId())
180  {
181  $hidden = new ilHiddenInputGUI("", "ID");
182  $hidden->setValue($this->object->getId());
183  $form->addItem($hidden);
184  }
185  // points
186  $points = new ilNumberInputGUI($this->lng->txt("points"), "points");
187  $points->setValue($this->object->getPoints());
188  $points->setRequired(TRUE);
189  $points->setSize(3);
190  $points->setMinValue(0.0);
191  $form->addItem($points);
192 
193  $this->addQuestionFormCommandButtons($form);
194 
195  $errors = false;
196 
197  if ($save)
198  {
199  $form->setValuesByPost();
200  $errors = !$form->checkInput();
201  $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
202  if ($errors) $checkonly = false;
203  }
204 
205  if (!$checkonly) $this->tpl->setVariable("QUESTION_DATA", $form->getHTML());
206  return $errors;
207  }
208 
209  function flashAddParam()
210  {
211  $this->writePostData();
212  $this->object->addParameter("", "");
213  $this->editQuestion();
214  }
215 
216  function outQuestionForTest($formaction, $active_id, $pass = NULL, $is_postponed = FALSE, $use_post_solutions = FALSE, $show_feedback = FALSE)
217  {
218  $test_output = $this->getTestOutput($active_id, $pass, $is_postponed, $use_post_solutions, $show_feedback);
219  $this->tpl->setVariable("QUESTION_OUTPUT", $test_output);
220  $this->tpl->setVariable("FORMACTION", $formaction);
221  }
222 
237  $active_id,
238  $pass = NULL,
239  $graphicalOutput = FALSE,
240  $result_output = FALSE,
241  $show_question_only = TRUE,
242  $show_feedback = FALSE,
243  $show_correct_solution = FALSE,
244  $show_manual_scoring = FALSE
245  )
246  {
247  // get the solution of the user for the active pass or from the last pass if allowed
248  $template = new ilTemplate("tpl.il_as_qpl_flash_question_output_solution.html", TRUE, TRUE, "Modules/TestQuestionPool");
249 
250  $params = array();
251  if (is_array($this->object->getParameters()))
252  {
253  foreach ($this->object->getParameters() as $name => $value)
254  {
255  array_push($params, urlencode($name) . "=" . urlencode($value));
256  }
257  }
258 
259  array_push($params, "session_id=" . urlencode($_COOKIE["PHPSESSID"]));
260  array_push($params, "client=" . urlencode(CLIENT_ID));
261  array_push($params, "points_max=" . urlencode($this->object->getPoints()));
262  array_push($params, "server=" . urlencode(ilUtil::removeTrailingPathSeparators(ILIAS_HTTP_PATH) . "/webservice/soap/server.php?wsdl"));
263  if (!is_null($pass))
264  {
265  array_push($params, "pass=" . $pass);
266  }
267  else
268  {
269  include_once "./Modules/Test/classes/class.ilObjTest.php";
270  array_push($params, "pass=" . ilObjTest::_getPass($active_id));
271  }
272  if ($active_id)
273  {
274  array_push($params, "active_id=" . $active_id);
275  }
276  array_push($params, "question_id=" . $this->object->getId());
277 
278  if ($show_correct_solution)
279  {
280  array_push($params, "solution=correct");
281  }
282  else
283  {
284  array_push($params, "solution=user");
285  }
286 
287  if (($active_id > 0) && (!$show_correct_solution))
288  {
289  if ($graphicalOutput)
290  {
291  // output of ok/not ok icons for user entered solutions
292  $reached_points = $this->object->getReachedPoints($active_id, $pass);
293  if ($reached_points == $this->object->getMaximumPoints())
294  {
295  $template->setCurrentBlock("icon_ok");
296  $template->setVariable("ICON_OK", ilUtil::getImagePath("icon_ok.gif"));
297  $template->setVariable("TEXT_OK", $this->lng->txt("answer_is_right"));
298  $template->parseCurrentBlock();
299  }
300  else
301  {
302  $template->setCurrentBlock("icon_ok");
303  if ($reached_points > 0)
304  {
305  $template->setVariable("ICON_NOT_OK", ilUtil::getImagePath("icon_mostly_ok.gif"));
306  $template->setVariable("TEXT_NOT_OK", $this->lng->txt("answer_is_not_correct_but_positive"));
307  }
308  else
309  {
310  $template->setVariable("ICON_NOT_OK", ilUtil::getImagePath("icon_not_ok.gif"));
311  $template->setVariable("TEXT_NOT_OK", $this->lng->txt("answer_is_wrong"));
312  }
313  $template->parseCurrentBlock();
314  }
315  }
316  }
317 
318  if (count($params))
319  {
320  $template->setCurrentBlock("flash_vars");
321  $template->setVariable("FLASH_VARS", join($params, "&"));
322  $template->parseCurrentBlock();
323  $template->setCurrentBlock("applet_parameters");
324  $template->setVariable("PARAM_VALUE", join($params, "&"));
325  $template->parseCurrentBlock();
326  }
327  $template->setVariable("QUESTIONTEXT", $this->object->prepareTextareaOutput($this->object->getQuestion(), TRUE));
328  $template->setVariable("APPLET_WIDTH", $this->object->getWidth());
329  $template->setVariable("APPLET_HEIGHT", $this->object->getHeight());
330  $template->setVariable("ID", $this->object->getId());
331  $template->setVariable("APPLET_PATH", $this->object->getFlashPathWeb() . $this->object->getApplet());
332  $template->setVariable("APPLET_FILE", $this->object->getApplet());
333 
334  $questionoutput = $template->get();
335  $solutiontemplate = new ilTemplate("tpl.il_as_tst_solution_output.html",TRUE, TRUE, "Modules/TestQuestionPool");
336  $solutiontemplate->setVariable("SOLUTION_OUTPUT", $questionoutput);
337  $solutionoutput = $solutiontemplate->get();
338  if (!$show_question_only)
339  {
340  // get page object output
341  $solutionoutput = $this->getILIASPage($solutionoutput);
342  }
343  return $solutionoutput;
344  }
345 
346  function getPreview($show_question_only = FALSE)
347  {
348  $template = new ilTemplate("tpl.il_as_qpl_flash_question_output.html",TRUE, TRUE, "Modules/TestQuestionPool");
349  $params = array();
350  if (is_array($this->object->getParameters()))
351  {
352  foreach ($this->object->getParameters() as $name => $value)
353  {
354  array_push($params, urlencode($name) . "=" . urlencode($value));
355  }
356  }
357  if (count($params))
358  {
359  $template->setCurrentBlock("flash_vars");
360  $template->setVariable("FLASH_VARS", join($params, "&"));
361  $template->parseCurrentBlock();
362  $template->setCurrentBlock("applet_parameters");
363  $template->setVariable("PARAM_VALUE", join($params, "&"));
364  $template->parseCurrentBlock();
365  }
366  $template->setVariable("QUESTIONTEXT", $this->object->prepareTextareaOutput($this->object->getQuestion(), TRUE));
367  $template->setVariable("APPLET_WIDTH", $this->object->getWidth());
368  $template->setVariable("APPLET_HEIGHT", $this->object->getHeight());
369  $template->setVariable("ID", $this->object->getId());
370  $template->setVariable("APPLET_PATH", $this->object->getFlashPathWeb() . $this->object->getApplet());
371  $template->setVariable("APPLET_FILE", $this->object->getApplet());
372  $questionoutput = $template->get();
373  if (!$show_question_only)
374  {
375  // get page object output
376  $questionoutput = $this->getILIASPage($questionoutput);
377  }
378  return $questionoutput;
379  }
380 
381  function getTestOutput($active_id, $pass = NULL, $is_postponed = FALSE, $use_post_solutions = FALSE, $show_feedback = FALSE)
382  {
383  // generate the question output
384  $template = new ilTemplate("tpl.il_as_qpl_flash_question_output.html",TRUE, TRUE, "Modules/TestQuestionPool");
385  $params = array();
386  if (is_array($this->object->getParameters()))
387  {
388  foreach ($this->object->getParameters() as $name => $value)
389  {
390  array_push($params, urlencode($name) . "=" . urlencode($value));
391  }
392  }
393 
394  array_push($params, "session_id=" . urlencode($_COOKIE["PHPSESSID"]));
395  array_push($params, "client=" . urlencode(CLIENT_ID));
396  array_push($params, "points_max=" . urlencode($this->object->getPoints()));
397  array_push($params, "server=" . urlencode(ilUtil::removeTrailingPathSeparators(ILIAS_HTTP_PATH) . "/webservice/soap/server.php?wsdl"));
398  if (strlen($pass))
399  {
400  array_push($params, "pass=" . $pass);
401  }
402  else
403  {
404  include_once "./Modules/Test/classes/class.ilObjTest.php";
405  array_push($params, "pass=" . ilObjTest::_getPass($active_id));
406  }
407  if ($active_id)
408  {
409  array_push($params, "active_id=" . $active_id);
410  }
411  array_push($params, "question_id=" . $this->object->getId());
412 
413  if (count($params))
414  {
415  $template->setCurrentBlock("flash_vars");
416  $template->setVariable("FLASH_VARS", join($params, "&"));
417  $template->parseCurrentBlock();
418  $template->setCurrentBlock("applet_parameters");
419  $template->setVariable("PARAM_VALUE", join($params, "&"));
420  $template->parseCurrentBlock();
421  }
422  $template->setVariable("QUESTIONTEXT", $this->object->prepareTextareaOutput($this->object->getQuestion(), TRUE));
423  $template->setVariable("APPLET_WIDTH", $this->object->getWidth());
424  $template->setVariable("APPLET_HEIGHT", $this->object->getHeight());
425  $template->setVariable("ID", $this->object->getId());
426  $template->setVariable("APPLET_PATH", $this->object->getFlashPathWeb() . $this->object->getApplet());
427  $template->setVariable("APPLET_FILE", $this->object->getFlashPathWeb() . $this->object->getApplet());
428  $questionoutput = $template->get();
429 
430  $pageoutput = $this->outQuestionPage("", $is_postponed, $active_id, $questionoutput);
431  return $pageoutput;
432  }
433 
439  function saveFeedback()
440  {
441  include_once "./Services/AdvancedEditing/classes/class.ilObjAdvancedEditing.php";
442  $errors = $this->feedback(true);
443  $this->object->saveFeedbackGeneric(0, $_POST["feedback_incomplete"]);
444  $this->object->saveFeedbackGeneric(1, $_POST["feedback_complete"]);
445  $this->object->cleanupMediaObjectUsage();
447  }
448 
454  function setQuestionTabs()
455  {
456  global $rbacsystem, $ilTabs;
457 
458  $this->ctrl->setParameterByClass("ilpageobjectgui", "q_id", $_GET["q_id"]);
459  include_once "./Modules/TestQuestionPool/classes/class.assQuestion.php";
460  $q_type = $this->object->getQuestionType();
461 
462  if (strlen($q_type))
463  {
464  $classname = $q_type . "GUI";
465  $this->ctrl->setParameterByClass(strtolower($classname), "sel_question_types", $q_type);
466  $this->ctrl->setParameterByClass(strtolower($classname), "q_id", $_GET["q_id"]);
467  }
468 
469  if ($_GET["q_id"])
470  {
471  if ($rbacsystem->checkAccess('write', $_GET["ref_id"]))
472  {
473  // edit page
474  $ilTabs->addTarget("edit_content",
475  $this->ctrl->getLinkTargetByClass("ilPageObjectGUI", "edit"),
476  array("edit", "insert", "exec_pg"),
477  "", "", $force_active);
478  }
479 
480  // edit page
481  $ilTabs->addTarget("preview",
482  $this->ctrl->getLinkTargetByClass("ilPageObjectGUI", "preview"),
483  array("preview"),
484  "ilPageObjectGUI", "", $force_active);
485  }
486 
487  $force_active = false;
488  if ($rbacsystem->checkAccess('write', $_GET["ref_id"]))
489  {
490  $url = "";
491  if ($classname) $url = $this->ctrl->getLinkTargetByClass($classname, "editQuestion");
492  $commands = $_POST["cmd"];
493  if (is_array($commands))
494  {
495  foreach ($commands as $key => $value)
496  {
497  if (preg_match("/^suggestrange_.*/", $key, $matches))
498  {
499  $force_active = true;
500  }
501  }
502  }
503  // edit question properties
504  $ilTabs->addTarget("edit_properties",
505  $url,
506  array("editQuestion", "save", "flashAddParam", "saveEdit", "originalSyncForm"),
507  $classname, "", $force_active);
508  }
509 
510  if ($_GET["q_id"])
511  {
512  $ilTabs->addTarget("feedback",
513  $this->ctrl->getLinkTargetByClass($classname, "feedback"),
514  array("feedback", "saveFeedback"),
515  $classname, "");
516  }
517 
518  if ($_GET["q_id"])
519  {
520  $ilTabs->addTarget("solution_hint",
521  $this->ctrl->getLinkTargetByClass($classname, "suggestedsolution"),
522  array("suggestedsolution", "saveSuggestedSolution", "outSolutionExplorer", "cancel",
523  "addSuggestedSolution","cancelExplorer", "linkChilds", "removeSuggestedSolution"
524  ),
525  $classname,
526  ""
527  );
528  }
529 
530  // Assessment of questions sub menu entry
531  if ($_GET["q_id"])
532  {
533  $ilTabs->addTarget("statistics",
534  $this->ctrl->getLinkTargetByClass($classname, "assessment"),
535  array("assessment"),
536  $classname, "");
537  }
538 
539  if (($_GET["calling_test"] > 0) || ($_GET["test_ref_id"] > 0))
540  {
541  $ref_id = $_GET["calling_test"];
542  if (strlen($ref_id) == 0) $ref_id = $_GET["test_ref_id"];
543 
544  global $___test_express_mode;
545 
546  if (!$_GET['test_express_mode'] && !$___test_express_mode) {
547  $ilTabs->setBackTarget($this->lng->txt("backtocallingtest"), "ilias.php?baseClass=ilObjTestGUI&cmd=questions&ref_id=$ref_id");
548  }
549  else {
551  $ilTabs->setBackTarget($this->lng->txt("backtocallingtest"), $link);
552  }
553  }
554  else
555  {
556  $ilTabs->setBackTarget($this->lng->txt("qpl"), $this->ctrl->getLinkTargetByClass("ilobjquestionpoolgui", "questions"));
557  }
558  }
559 }
560 ?>