ILIAS  Release_3_10_x_branch Revision 61812
 All Data Structures Namespaces Files Functions Variables Groups Pages
class.assJavaAppletGUI.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 {
47  function assJavaAppletGUI(
48  $id = -1
49  )
50  {
51  $this->assQuestionGUI();
52  include_once "./Modules/TestQuestionPool/classes/class.assJavaApplet.php";
53  $this->object = new assJavaApplet();
54  if ($id >= 0)
55  {
56  $this->object->loadFromDb($id);
57  }
58  }
59 
60  function getCommand($cmd)
61  {
62  if (substr($cmd, 0, 6) == "delete")
63  {
64  $cmd = "delete";
65  }
66  return $cmd;
67  }
68 
76  function editQuestion()
77  {
78  $this->getQuestionTemplate();
79  $this->tpl->addBlockFile("QUESTION_DATA", "question_data", "tpl.il_as_qpl_javaapplet_question.html", "Modules/TestQuestionPool");
80  if ($this->error)
81  {
82  ilUtil::sendInfo($this->error);
83  }
84  // call to other question data i.e. estimated working time block
85  $this->outOtherQuestionData();
86  // image block
87  $this->tpl->setCurrentBlock("post_save");
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  $this->tpl->setVariable("TEXT_SOLUTION_HINT", $this->lng->txt("solution_hint"));
104  if (count($this->object->suggested_solutions))
105  {
106  $solution_array = $this->object->getSuggestedSolution(0);
107  include_once "./Modules/TestQuestionPool/classes/class.assQuestion.php";
108  $href = assQuestion::_getInternalLinkHref($solution_array["internal_link"]);
109  $this->tpl->setVariable("TEXT_VALUE_SOLUTION_HINT", " <a href=\"$href\" target=\"content\">" . $this->lng->txt("solution_hint"). "</a> ");
110  $this->tpl->setVariable("BUTTON_REMOVE_SOLUTION", $this->lng->txt("remove"));
111  $this->tpl->setVariable("BUTTON_ADD_SOLUTION", $this->lng->txt("change"));
112  $this->tpl->setVariable("VALUE_SOLUTION_HINT", $solution_array["internal_link"]);
113  }
114  else
115  {
116  $this->tpl->setVariable("BUTTON_ADD_SOLUTION", $this->lng->txt("add"));
117  }
118 
119  // java applet block
120  $javaapplet = $this->object->getJavaAppletFilename();
121  $this->tpl->setVariable("TEXT_JAVAAPPLET", $this->lng->txt("javaapplet"));
122  if (!empty($javaapplet))
123  {
124  $this->tpl->setVariable("JAVAAPPLET_FILENAME", $javaapplet);
125  $this->tpl->setVariable("VALUE_JAVAAPPLET_UPLOAD", $this->lng->txt("change"));
126  $this->tpl->setCurrentBlock("javaappletupload");
127  $this->tpl->setVariable("UPLOADED_JAVAAPPLET", $javaapplet);
128  $this->tpl->parse("javaappletupload");
129  $this->tpl->setCurrentBlock("delete_applet");
130  $this->tpl->setVariable("VALUE_JAVAAPPLET_DELETE", $this->lng->txt("delete"));
131  $this->tpl->parseCurrentBlock();
132  }
133  else
134  {
135  $this->tpl->setVariable("VALUE_JAVAAPPLET_UPLOAD", $this->lng->txt("upload"));
136  }
137  $this->tpl->setVariable("TEXT_POINTS", $this->lng->txt("available_points"));
138  $this->tpl->setVariable("VALUE_APPLET_POINTS", $this->object->getPoints());
139  $this->tpl->parseCurrentBlock();
140 
141 
142  if ((strlen($this->object->getTitle()) > 0) && (strlen($this->object->getAuthor()) > 0) && (strlen($this->object->getQuestion()) > 0) && strlen($this->object->getPoints()))
143  {
144  $emptyname = 0;
145  for ($i = 0; $i < $this->object->getParameterCount(); $i++)
146  {
147  // create template for existing applet parameters
148  $this->tpl->setCurrentBlock("delete_parameter");
149  $this->tpl->setVariable("VALUE_DELETE_PARAMETER", $this->lng->txt("delete"));
150  $this->tpl->setVariable("DELETE_PARAMETER_COUNT", $i);
151  $this->tpl->parseCurrentBlock();
152  $this->tpl->setCurrentBlock("applet_parameter");
153  $this->tpl->setVariable("PARAM_PARAM", $this->lng->txt("applet_parameter") . " " . ($i+1));
154  $this->tpl->setVariable("PARAM_NAME", $this->lng->txt("name"));
155  $this->tpl->setVariable("PARAM_VALUE", $this->lng->txt("value"));
156  $param = $this->object->getParameter($i);
157  $this->tpl->setVariable("PARAM_NAME_VALUE", $param["name"]);
158  $this->tpl->setVariable("PARAM_VALUE_VALUE", $param["value"]);
159  $this->tpl->setVariable("PARAM_COUNTER", $i);
160  $this->tpl->parseCurrentBlock();
161  if (!$param["name"])
162  {
163  $emptyname = 1;
164  }
165  }
166  if ($this->ctrl->getCmd() == "addParameter")
167  {
168  if ($emptyname == 0)
169  {
170  // create template for new applet parameter
171  $this->tpl->setCurrentBlock("applet_parameter");
172  $this->tpl->setVariable("PARAM_PARAM", $this->lng->txt("applet_new_parameter"));
173  $this->tpl->setVariable("PARAM_NAME", $this->lng->txt("name"));
174  $this->tpl->setVariable("PARAM_VALUE", $this->lng->txt("value"));
175  $this->tpl->setVariable("PARAM_COUNTER", $this->object->getParameterCount());
176  $this->tpl->parseCurrentBlock();
177  }
178  else
179  {
180  ilUtil::sendInfo($this->lng->txt("too_many_empty_parameters"));
181  }
182  }
183  if (!strlen($javaapplet))
184  {
185  $this->tpl->setVariable("TEXT_ARCHIVE", $this->lng->txt("archive"));
186  $this->tpl->setVariable("VALUE_ARCHIVE", $this->object->getJavaArchive());
187  $this->tpl->setVariable("TEXT_CODEBASE", $this->lng->txt("codebase"));
188  $this->tpl->setVariable("VALUE_CODEBASE", $this->object->getJavaCodebase());
189  }
190 
191  $this->tpl->setCurrentBlock("appletcode");
192  $this->tpl->setVariable("APPLET_ATTRIBUTES", $this->lng->txt("applet_attributes"));
193  $this->tpl->setVariable("TEXT_CODE", $this->lng->txt("code"));
194  $this->tpl->setVariable("TEXT_WIDTH", $this->lng->txt("width"));
195  $this->tpl->setVariable("TEXT_HEIGHT", $this->lng->txt("height"));
196  $this->tpl->setVariable("VALUE_CODE", $this->object->getJavaCode());
197  $this->tpl->setVariable("VALUE_WIDTH", $this->object->getJavaWidth());
198  $this->tpl->setVariable("VALUE_HEIGHT", $this->object->getJavaHeight());
199  $this->tpl->setVariable("APPLET_PARAMETERS", $this->lng->txt("applet_parameters"));
200  $this->tpl->setVariable("VALUE_ADD_PARAMETER", $this->lng->txt("add_applet_parameter"));
201  $this->tpl->parseCurrentBlock();
202  }
203 
204  $this->tpl->setCurrentBlock("HeadContent");
205  $this->tpl->addJavascript("./Services/JavaScript/js/Basic.js");
206  $javascript = "<script type=\"text/javascript\">ilAddOnLoad(initialSelect);\n".
207  "function initialSelect() {\n%s\n}</script>";
208  $this->tpl->setVariable("CONTENT_BLOCK", sprintf($javascript, "document.frm_javaapplet.title.focus();"));
209  $this->tpl->parseCurrentBlock();
210  $this->tpl->setCurrentBlock("question_data");
211  $this->tpl->setVariable("JAVAAPPLET_ID", $this->object->getId());
212  $this->tpl->setVariable("VALUE_JAVAAPPLET_TITLE", ilUtil::prepareFormOutput($this->object->getTitle()));
213  $this->tpl->setVariable("VALUE_JAVAAPPLET_COMMENT", ilUtil::prepareFormOutput($this->object->getComment()));
214  $this->tpl->setVariable("VALUE_JAVAAPPLET_AUTHOR", ilUtil::prepareFormOutput($this->object->getAuthor()));
215  $questiontext = $this->object->getQuestion();
216  $this->tpl->setVariable("VALUE_QUESTION", ilUtil::prepareFormOutput($this->object->prepareTextareaOutput($questiontext)));
217  $this->tpl->setVariable("TEXT_TITLE", $this->lng->txt("title"));
218  $this->tpl->setVariable("TEXT_AUTHOR", $this->lng->txt("author"));
219  $this->tpl->setVariable("TEXT_COMMENT", $this->lng->txt("description"));
220  $this->tpl->setVariable("TEXT_QUESTION", $this->lng->txt("question"));
221  $this->tpl->setVariable("TXT_REQUIRED_FLD", $this->lng->txt("required_field"));
222 
223  $this->tpl->setVariable("SAVE",$this->lng->txt("save"));
224  $this->tpl->setVariable("SAVE_EDIT", $this->lng->txt("save_edit"));
225  $this->tpl->setVariable("CANCEL",$this->lng->txt("cancel"));
226  $this->ctrl->setParameter($this, "sel_question_types", "assJavaApplet");
227  $this->tpl->setVariable("TEXT_QUESTION_TYPE", $this->outQuestionType());
228  $formaction = $this->ctrl->getFormaction($this);
229  if ($this->object->getId() > 0)
230  {
231  if (!preg_match("/q_id\=\d+/", $formaction))
232  {
233  $formaction = str_replace("q_id=", "q_id=" . $this->object->getId(), $formaction);
234  }
235  }
236  $this->tpl->setVariable("ACTION_JAVAAPPLET_QUESTION", $formaction);
237  $this->tpl->parseCurrentBlock();
238  include_once "./Services/RTE/classes/class.ilRTE.php";
239  $rtestring = ilRTE::_getRTEClassname();
240  include_once "./Services/RTE/classes/class.$rtestring.php";
241  $rte = new $rtestring();
242  $rte->addPlugin("latex");
243  $rte->addButton("latex"); $rte->addButton("pastelatex");
244  include_once "./classes/class.ilObject.php";
245  $obj_id = $_GET["q_id"];
246  $obj_type = ilObject::_lookupType($_GET["ref_id"], TRUE);
247  $rte->addRTESupport($obj_id, $obj_type, "assessment");
248 
249  $this->tpl->setCurrentBlock("adm_content");
250  //$this->tpl->setVariable("BODY_ATTRIBUTES", " onload=\"initialSelect();\"");
251  $this->tpl->parseCurrentBlock();
252 
253  }
254 
255 
260  {
261  $result = $this->writePostData();
262  if ($result == 0)
263  {
264  $this->object->saveToDb();
265  $this->ctrl->setParameter($this, "q_id", $this->object->getId());
266  }
267  $this->editQuestion();
268  }
269 
270 
274  function removeJavaapplet()
275  {
276  $this->object->deleteJavaAppletFilename();
277  $this->object->saveToDb();
278  $this->editQuestion();
279  }
280 
284  function addParameter()
285  {
286  $this->writePostData();
287  $this->editQuestion();
288  }
289 
293  function delete()
294  {
295  $this->writePostData();
296  $this->editQuestion();
297  }
298 
307  function writePostData()
308  {
309  $result = 0;
310  $saved = false;
311  if (!$this->checkInput())
312  {
313  $result = 1;
314  }
315 
316  $this->object->setTitle(ilUtil::stripSlashes($_POST["title"]));
317  $this->object->setAuthor(ilUtil::stripSlashes($_POST["author"]));
318  $this->object->setComment(ilUtil::stripSlashes($_POST["comment"]));
319  include_once "./Services/AdvancedEditing/classes/class.ilObjAdvancedEditing.php";
320  $questiontext = ilUtil::stripSlashes($_POST["question"], false, ilObjAdvancedEditing::_getUsedHTMLTagsAsString("assessment"));
321  $this->object->setQuestion($questiontext);
322  $this->object->setSuggestedSolution($_POST["solution_hint"], 0);
323  $this->object->setShuffle($_POST["shuffle"]);
324  $this->object->setPoints($_POST["applet_points"]);
325  if ($_POST["applet_points"] < 0)
326  {
327  $result = 1;
328  $this->setErrorMessage($this->lng->txt("negative_points_not_allowed"));
329  }
330  // adding estimated working time
331  $saved = $saved | $this->writeOtherPostData($result);
332 
333  if ($result == 0)
334  {
335  //setting java applet
336  if (empty($_FILES['javaappletName']['tmp_name']))
337  {
338  $this->object->setJavaAppletFilename(ilUtil::stripSlashes($_POST['uploaded_javaapplet']));
339  }
340  else
341  {
342  if ($this->object->getId() < 1)
343  {
344  $saved = 1;
345  $this->object->saveToDb();
346  }
347  $this->object->setJavaAppletFilename($_FILES['javaappletName']['name'], $_FILES['javaappletName']['tmp_name']);
348  }
349  if ((strlen($this->object->getTitle()) > 0) && (strlen($this->object->getAuthor()) > 0) && (strlen($this->object->getQuestion()) > 0) && ($this->object->getPoints() > 0) && array_key_exists("java_height", $_POST))
350  {
351  $this->object->setJavaCode($_POST["java_code"]);
352  $this->object->setJavaCodebase($_POST["java_codebase"]);
353  $this->object->setJavaArchive($_POST["java_archive"]);
354  $this->object->setJavaWidth($_POST["java_width"]);
355  $this->object->setJavaHeight($_POST["java_height"]);
356  if ((!$_POST["java_width"]) or (!$_POST["java_height"])) $result = 1;
357  $this->object->flushParams();
358  foreach ($_POST as $key => $value)
359  {
360  if (preg_match("/param_name_(\d+)/", $key, $matches))
361  {
362  $this->object->addParameterAtIndex($matches[1], $value, $_POST["param_value_$matches[1]"]);
363  }
364  }
365  if (preg_match("/delete_(\d+)/", $this->ctrl->getCmd(), $matches))
366  {
367  $this->object->removeParameter($_POST["param_name_$matches[1]"]);
368  }
369  }
370  }
371  if ($saved)
372  {
373  $this->object->saveToDb();
374  $this->ctrl->setParameter($this, "q_id", $this->object->getId());
375  $this->error .= $this->lng->txt("question_saved_for_upload");
376  }
377  return $result;
378  }
379 
380  function outQuestionForTest($formaction, $active_id, $pass = NULL, $is_postponed = FALSE, $use_post_solutions = FALSE)
381  {
382  $test_output = $this->getTestOutput($active_id, $pass, $is_postponed, $use_post_solutions);
383  $this->tpl->setVariable("QUESTION_OUTPUT", $test_output);
384  $this->tpl->setVariable("FORMACTION", $formaction);
385  }
386 
387  function getSolutionOutput($active_id, $pass = NULL, $graphicalOutput = FALSE, $result_output = FALSE, $show_question_only = TRUE, $show_feedback = FALSE, $show_correct_solution = FALSE)
388  {
389  $userdata = $this->object->getActiveUserData($active_id);
390 
391  // generate the question output
392  include_once "./classes/class.ilTemplate.php";
393  include_once "./Modules/Test/classes/class.ilObjTest.php";
394  $template = new ilTemplate("tpl.il_as_qpl_javaapplet_question_output_solution.html", TRUE, TRUE, "Modules/TestQuestionPool");
395  $solutiontemplate = new ilTemplate("tpl.il_as_tst_solution_output.html",TRUE, TRUE, "Modules/TestQuestionPool");
396  if (strlen($userdata["test_id"]))
397  {
398  $template->setCurrentBlock("appletparam");
399  $template->setVariable("PARAM_NAME", "test_type");
401  {
402  $template->setVariable("PARAM_VALUE", "0");
403  }
404  else
405  {
406  $template->setVariable("PARAM_VALUE", "1");
407  }
408  $template->parseCurrentBlock();
409  }
410  if (strlen($userdata["test_id"]))
411  {
412  $template->setCurrentBlock("appletparam");
413  $template->setVariable("PARAM_NAME", "test_id");
414  $template->setVariable("PARAM_VALUE", $userdata["test_id"]);
415  $template->parseCurrentBlock();
416  }
417  $template->setCurrentBlock("appletparam");
418  $template->setVariable("PARAM_NAME", "active_id");
419  $template->setVariable("PARAM_VALUE", $active_id);
420  $template->parseCurrentBlock();
421  $template->setCurrentBlock("appletparam");
422  $template->setVariable("PARAM_NAME", "question_id");
423  $template->setVariable("PARAM_VALUE", $this->object->getId());
424  $template->parseCurrentBlock();
425  if (strlen($userdata["user_id"]))
426  {
427  $template->setCurrentBlock("appletparam");
428  $template->setVariable("PARAM_NAME", "user_id");
429  $template->setVariable("PARAM_VALUE", $userdata["user_id"]);
430  $template->parseCurrentBlock();
431  }
432  $template->setCurrentBlock("appletparam");
433  $template->setVariable("PARAM_NAME", "points_max");
434  $template->setVariable("PARAM_VALUE", $this->object->getPoints());
435  $template->parseCurrentBlock();
436  $template->setCurrentBlock("appletparam");
437  $template->setVariable("PARAM_NAME", "session_id");
438  $template->setVariable("PARAM_VALUE", $_COOKIE["PHPSESSID"]);
439  $template->parseCurrentBlock();
440  $template->setCurrentBlock("appletparam");
441  $template->setVariable("PARAM_NAME", "client");
442  $template->setVariable("PARAM_VALUE", CLIENT_ID);
443  $template->parseCurrentBlock();
444  $template->setCurrentBlock("appletparam");
445  $template->setVariable("PARAM_NAME", "pass");
446  $actualpass = ilObjTest::_getPass($active_id);
447  $template->setVariable("PARAM_VALUE", $actualpass);
448  $template->parseCurrentBlock();
449  // additional parameters
450  for ($i = 0; $i < $this->object->getParameterCount(); $i++)
451  {
452  $parameter = $this->object->getParameter($i);
453  $template->setCurrentBlock("appletparam");
454  $template->setVariable("PARAM_NAME", $parameter["name"]);
455  $template->setVariable("PARAM_VALUE", $parameter["value"]);
456  $template->parseCurrentBlock();
457  }
458 
459  if (($active_id > 0) && (!$show_correct_solution))
460  {
461  $solutions = NULL;
462  include_once "./Modules/Test/classes/class.ilObjTest.php";
463  $info = $this->object->getReachedInformation($active_id, $pass);
464  foreach ($info as $kk => $infodata)
465  {
466  $template->setCurrentBlock("appletparam");
467  $template->setVariable("PARAM_NAME", "value_" . $infodata["order"] . "_1");
468  $template->setVariable("PARAM_VALUE", $infodata["value1"]);
469  $template->parseCurrentBlock();
470  $template->setCurrentBlock("appletparam");
471  $template->setVariable("PARAM_NAME", "value_" . $infodata["order"] . "_2");
472  $template->setVariable("PARAM_VALUE", $infodata["value2"]);
473  $template->parseCurrentBlock();
474  }
475  }
476 
477  $questiontext = $this->object->getQuestion();
478  $template->setVariable("QUESTIONTEXT", $this->object->prepareTextareaOutput($questiontext, TRUE));
479  $template->setVariable("APPLET_WIDTH", $this->object->getJavaWidth());
480  $template->setVariable("APPLET_HEIGHT", $this->object->getJavaHeight());
481  $template->setVariable("APPLET_CODE", $this->object->getJavaCode());
482  if (strlen($this->object->getJavaArchive()) > 0)
483  {
484  $template->setVariable("APPLET_ARCHIVE", " archive=\"".$this->object->getJavaArchive()."\"");
485  }
486  else
487  {
488  if (strpos($this->object->getJavaAppletFilename(), ".jar") !== FALSE)
489  {
490  $template->setVariable("APPLET_ARCHIVE", " archive=\"".$this->object->getJavaPathWeb().$this->object->getJavaAppletFilename()."\"");
491  }
492  }
493  if (strlen($this->object->getJavaCodebase()) > 0)
494  {
495  $template->setVariable("APPLET_CODEBASE", " codebase=\"".$this->object->getJavaCodebase()."\"");
496  }
497  else
498  {
499  if (strpos($this->object->getJavaAppletFilename(), ".class") !== FALSE)
500  {
501  $template->setVariable("APPLET_CODEBASE", " codebase=\"".$this->object->getJavaPathWeb()."\"");
502  }
503  }
504  if (($active_id > 0) && (!$show_correct_solution))
505  {
506  if ($graphicalOutput)
507  {
508  // output of ok/not ok icons for user entered solutions
509  $reached_points = $this->object->getReachedPoints($active_id, $pass);
510  if ($reached_points == $this->object->getMaximumPoints())
511  {
512  $template->setCurrentBlock("icon_ok");
513  $template->setVariable("ICON_OK", ilUtil::getImagePath("icon_ok.gif"));
514  $template->setVariable("TEXT_OK", $this->lng->txt("answer_is_right"));
515  $template->parseCurrentBlock();
516  }
517  else
518  {
519  $template->setCurrentBlock("icon_ok");
520  if ($reached_points > 0)
521  {
522  $template->setVariable("ICON_NOT_OK", ilUtil::getImagePath("icon_mostly_ok.gif"));
523  $template->setVariable("TEXT_NOT_OK", $this->lng->txt("answer_is_not_correct_but_positive"));
524  }
525  else
526  {
527  $template->setVariable("ICON_NOT_OK", ilUtil::getImagePath("icon_not_ok.gif"));
528  $template->setVariable("TEXT_NOT_OK", $this->lng->txt("answer_is_wrong"));
529  }
530  $template->parseCurrentBlock();
531  }
532  }
533  }
534  $questionoutput = $template->get();
535  $feedback = ($show_feedback) ? $this->getAnswerFeedbackOutput($active_id, $pass) : "";
536  if (strlen($feedback)) $solutiontemplate->setVariable("FEEDBACK", $feedback);
537  $solutiontemplate->setVariable("SOLUTION_OUTPUT", $questionoutput);
538 
539  $solutionoutput = $solutiontemplate->get();
540  if (!$show_question_only)
541  {
542  // get page object output
543  $solutionoutput = $this->getILIASPage($solutionoutput);
544  }
545  return $solutionoutput;
546  }
547 
548  function getPreview($show_question_only = FALSE)
549  {
550  // generate the question output
551  include_once "./classes/class.ilTemplate.php";
552  $template = new ilTemplate("tpl.il_as_qpl_javaapplet_question_output.html", TRUE, TRUE, "Modules/TestQuestionPool");
553  $template->setCurrentBlock("appletparam");
554  $template->setVariable("PARAM_NAME", "question_id");
555  $template->setVariable("PARAM_VALUE", $this->object->getId());
556  $template->parseCurrentBlock();
557  $template->setCurrentBlock("appletparam");
558  $template->setVariable("PARAM_NAME", "points_max");
559  $template->setVariable("PARAM_VALUE", $this->object->getPoints());
560  $template->parseCurrentBlock();
561  $template->setCurrentBlock("appletparam");
562  $template->setVariable("PARAM_NAME", "session_id");
563  $template->setVariable("PARAM_VALUE", $_COOKIE["PHPSESSID"]);
564  $template->parseCurrentBlock();
565  $template->setCurrentBlock("appletparam");
566  $template->setVariable("PARAM_NAME", "client");
567  $template->setVariable("PARAM_VALUE", CLIENT_ID);
568  $template->parseCurrentBlock();
569  // additional parameters
570  for ($i = 0; $i < $this->object->getParameterCount(); $i++)
571  {
572  $parameter = $this->object->getParameter($i);
573  $template->setCurrentBlock("appletparam");
574  $template->setVariable("PARAM_NAME", $parameter["name"]);
575  $template->setVariable("PARAM_VALUE", $parameter["value"]);
576  $template->parseCurrentBlock();
577  }
578 
579  $questiontext = $this->object->getQuestion();
580  $template->setVariable("QUESTIONTEXT", $this->object->prepareTextareaOutput($questiontext, TRUE));
581  $template->setVariable("APPLET_WIDTH", $this->object->getJavaWidth());
582  $template->setVariable("APPLET_HEIGHT", $this->object->getJavaHeight());
583  $template->setVariable("APPLET_CODE", $this->object->getJavaCode());
584  if (strlen($this->object->getJavaArchive()) > 0)
585  {
586  $template->setVariable("APPLET_ARCHIVE", " archive=\"".$this->object->getJavaArchive()."\"");
587  }
588  else
589  {
590  if (strpos($this->object->getJavaAppletFilename(), ".jar") !== FALSE)
591  {
592  $template->setVariable("APPLET_ARCHIVE", " archive=\"".$this->object->getJavaPathWeb().$this->object->getJavaAppletFilename()."\"");
593  }
594  }
595  if (strlen($this->object->getJavaCodebase()) > 0)
596  {
597  $template->setVariable("APPLET_CODEBASE", " codebase=\"".$this->object->getJavaCodebase()."\"");
598  }
599  else
600  {
601  if (strpos($this->object->getJavaAppletFilename(), ".class") !== FALSE)
602  {
603  $template->setVariable("APPLET_CODEBASE", " codebase=\"".$this->object->getJavaPathWeb()."\"");
604  }
605  }
606  $questionoutput = $template->get();
607  if (!$show_question_only)
608  {
609  // get page object output
610  $questionoutput = $this->getILIASPage($questionoutput);
611  }
612  return $questionoutput;
613  }
614 
615  function getTestOutput($active_id, $pass = NULL, $is_postponed = FALSE, $use_post_solutions = FALSE)
616  {
617  $userdata = $this->object->getActiveUserData($active_id);
618  // generate the question output
619  include_once "./classes/class.ilTemplate.php";
620  $template = new ilTemplate("tpl.il_as_qpl_javaapplet_question_output.html", TRUE, TRUE, "Modules/TestQuestionPool");
621  $template->setCurrentBlock("appletparam");
622  $template->setVariable("PARAM_NAME", "test_type");
623  include_once "./Modules/Test/classes/class.ilObjTest.php";
625  {
626  $template->setVariable("PARAM_VALUE", "0");
627  }
628  else
629  {
630  $template->setVariable("PARAM_VALUE", "1");
631  }
632  $template->parseCurrentBlock();
633  $template->setCurrentBlock("appletparam");
634  $template->setVariable("PARAM_NAME", "active_id");
635  $template->setVariable("PARAM_VALUE", $active_id);
636  $template->parseCurrentBlock();
637  $template->setCurrentBlock("appletparam");
638  $template->setVariable("PARAM_NAME", "test_id");
639  $template->setVariable("PARAM_VALUE", $userdata["test_id"]);
640  $template->parseCurrentBlock();
641  $template->setCurrentBlock("appletparam");
642  $template->setVariable("PARAM_NAME", "question_id");
643  $template->setVariable("PARAM_VALUE", $this->object->getId());
644  $template->parseCurrentBlock();
645  $template->setCurrentBlock("appletparam");
646  $template->setVariable("PARAM_NAME", "user_id");
647  $template->setVariable("PARAM_VALUE", $userdata["user_id"]);
648  $template->parseCurrentBlock();
649  $template->setCurrentBlock("appletparam");
650  $template->setVariable("PARAM_NAME", "points_max");
651  $template->setVariable("PARAM_VALUE", $this->object->getPoints());
652  $template->parseCurrentBlock();
653  $template->setCurrentBlock("appletparam");
654  $template->setVariable("PARAM_NAME", "session_id");
655  $template->setVariable("PARAM_VALUE", $_COOKIE["PHPSESSID"]);
656  $template->parseCurrentBlock();
657  $template->setCurrentBlock("appletparam");
658  $template->setVariable("PARAM_NAME", "client");
659  $template->setVariable("PARAM_VALUE", CLIENT_ID);
660  $template->parseCurrentBlock();
661  $template->setCurrentBlock("appletparam");
662  $template->setVariable("PARAM_NAME", "pass");
663  $actualpass = ilObjTest::_getPass($active_id);
664  $template->setVariable("PARAM_VALUE", $actualpass);
665  $template->parseCurrentBlock();
666  $template->setCurrentBlock("appletparam");
667  $template->setVariable("PARAM_NAME", "post_url");
668  $template->setVariable("PARAM_VALUE", ilUtil::removeTrailingPathSeparators(ILIAS_HTTP_PATH) . "/Modules/TestQuestionPool/save_question_post_data.php");
669  $template->parseCurrentBlock();
670  // additional parameters
671  for ($i = 0; $i < $this->object->getParameterCount(); $i++)
672  {
673  $parameter = $this->object->getParameter($i);
674  $template->setCurrentBlock("appletparam");
675  $template->setVariable("PARAM_NAME", $parameter["name"]);
676  $template->setVariable("PARAM_VALUE", $parameter["value"]);
677  $template->parseCurrentBlock();
678  }
679 
680  if ($active_id)
681  {
682  $solutions = NULL;
683  include_once "./Modules/Test/classes/class.ilObjTest.php";
684  if (!ilObjTest::_getUsePreviousAnswers($active_id, true))
685  {
686  if (is_null($pass)) $pass = ilObjTest::_getPass($active_id);
687  }
688  $info = $this->object->getReachedInformation($active_id, $pass);
689  foreach ($info as $kk => $infodata)
690  {
691  $template->setCurrentBlock("appletparam");
692  $template->setVariable("PARAM_NAME", "value_" . $infodata["order"] . "_1");
693  $template->setVariable("PARAM_VALUE", $infodata["value1"]);
694  $template->parseCurrentBlock();
695  $template->setCurrentBlock("appletparam");
696  $template->setVariable("PARAM_NAME", "value_" . $infodata["order"] . "_2");
697  $template->setVariable("PARAM_VALUE", $infodata["value2"]);
698  $template->parseCurrentBlock();
699  }
700  include_once './Services/Administration/classes/class.ilSetting.php';
701  $soapSetting = new ilSetting();
702  if ($soapSetting->get("soap_user_administration") == 1)
703  {
704  $template->setCurrentBlock("appletparam");
705  $template->setVariable("PARAM_NAME", "server");
706  $template->setVariable("PARAM_VALUE", ilUtil::removeTrailingPathSeparators(ILIAS_HTTP_PATH) . "/webservice/soap/server.php");
707  }
708  }
709 
710  $questiontext = $this->object->getQuestion();
711  $template->setVariable("QUESTIONTEXT", $this->object->prepareTextareaOutput($questiontext, TRUE));
712  $template->setVariable("APPLET_WIDTH", $this->object->getJavaWidth());
713  $template->setVariable("APPLET_HEIGHT", $this->object->getJavaHeight());
714  $template->setVariable("APPLET_CODE", $this->object->getJavaCode());
715  if (strlen($this->object->getJavaArchive()) > 0)
716  {
717  $template->setVariable("APPLET_ARCHIVE", " archive=\"".$this->object->getJavaArchive()."\"");
718  }
719  else
720  {
721  if (strpos($this->object->getJavaAppletFilename(), ".jar") !== FALSE)
722  {
723  $template->setVariable("APPLET_ARCHIVE", " archive=\"".$this->object->getJavaPathWeb().$this->object->getJavaAppletFilename()."\"");
724  }
725  }
726  if (strlen($this->object->getJavaCodebase()) > 0)
727  {
728  $template->setVariable("APPLET_CODEBASE", " codebase=\"".$this->object->getJavaCodebase()."\"");
729  }
730  else
731  {
732  if (strpos($this->object->getJavaAppletFilename(), ".class") !== FALSE)
733  {
734  $template->setVariable("APPLET_CODEBASE", " codebase=\"".$this->object->getJavaPathWeb()."\"");
735  }
736  }
737  $questionoutput = $template->get();
738  $pageoutput = $this->outQuestionPage("", $is_postponed, $active_id, $questionoutput);
739  return $pageoutput;
740  }
741 
745  function checkInput()
746  {
747  if ((strlen($_POST["title"]) == 0) or (strlen($_POST["author"]) == 0) or (strlen($_POST["question"]) == 0) or (strlen($_POST["applet_points"]) == 0))
748  {
749  $this->error .= $this->lng->txt("fill_out_all_required_fields");
750  return false;
751  }
752  return true;
753  }
754 
755 
757  {
758  $_SESSION["subquestion_index"] = 0;
759  if ($_POST["cmd"]["addSuggestedSolution"])
760  {
761  if ($this->writePostData())
762  {
764  $this->editQuestion();
765  return;
766  }
767  if ($result != 0)
768  {
769  $this->editQuestion();
770  return;
771  }
772  }
773  $this->object->saveToDb();
774  $this->ctrl->setParameter($this, "q_id", $this->object->getId());
775  $this->tpl->setVariable("HEADER", $this->object->getTitle());
776  $this->getQuestionTemplate();
778  }
779 
787  function saveFeedback()
788  {
789  include_once "./Services/AdvancedEditing/classes/class.ilObjAdvancedEditing.php";
790  $this->object->saveFeedbackGeneric(0, ilUtil::stripSlashes($_POST["feedback_incomplete"], false, ilObjAdvancedEditing::_getUsedHTMLTagsAsString("assessment")));
791  $this->object->saveFeedbackGeneric(1, ilUtil::stripSlashes($_POST["feedback_complete"], false, ilObjAdvancedEditing::_getUsedHTMLTagsAsString("assessment")));
792  $this->object->cleanupMediaObjectUsage();
794  }
795 
803  function feedback()
804  {
805  $this->tpl->addBlockFile("ADM_CONTENT", "feedback", "tpl.il_as_qpl_javaapplet_question_feedback.html", "Modules/TestQuestionPool");
806  $this->tpl->setVariable("FEEDBACK_TEXT", $this->lng->txt("feedback"));
807  $this->tpl->setVariable("FEEDBACK_COMPLETE", $this->lng->txt("feedback_complete_solution"));
808  $this->tpl->setVariable("VALUE_FEEDBACK_COMPLETE", ilUtil::prepareFormOutput($this->object->prepareTextareaOutput($this->object->getFeedbackGeneric(1)), FALSE));
809  $this->tpl->setVariable("FEEDBACK_INCOMPLETE", $this->lng->txt("feedback_incomplete_solution"));
810  $this->tpl->setVariable("VALUE_FEEDBACK_INCOMPLETE", ilUtil::prepareFormOutput($this->object->prepareTextareaOutput($this->object->getFeedbackGeneric(0)), FALSE));
811  global $rbacsystem;
812  if ($rbacsystem->checkAccess('write', $_GET["ref_id"]))
813  {
814  $this->tpl->setVariable("SAVE", $this->lng->txt("save"));
815  }
816  $this->tpl->setVariable("FORMACTION", $this->ctrl->getFormAction($this));
817 
818  include_once "./Services/RTE/classes/class.ilRTE.php";
819  $rtestring = ilRTE::_getRTEClassname();
820  include_once "./Services/RTE/classes/class.$rtestring.php";
821  $rte = new $rtestring();
822  $rte->addPlugin("latex");
823  $rte->addButton("latex"); $rte->addButton("pastelatex");
824  include_once "./classes/class.ilObject.php";
825  $obj_id = $_GET["q_id"];
826  $obj_type = ilObject::_lookupType($_GET["ref_id"], TRUE);
827  $rte->addRTESupport($obj_id, $obj_type, "assessment");
828  }
829 
837  function setQuestionTabs()
838  {
839  global $rbacsystem, $ilTabs;
840 
841  $this->ctrl->setParameterByClass("ilpageobjectgui", "q_id", $_GET["q_id"]);
842  include_once "./Modules/TestQuestionPool/classes/class.assQuestion.php";
843  $q_type = $this->object->getQuestionType();
844 
845  if (strlen($q_type))
846  {
847  $classname = $q_type . "GUI";
848  $this->ctrl->setParameterByClass(strtolower($classname), "sel_question_types", $q_type);
849  $this->ctrl->setParameterByClass(strtolower($classname), "q_id", $_GET["q_id"]);
850  }
851 
852  if ($_GET["q_id"])
853  {
854  if ($rbacsystem->checkAccess('write', $_GET["ref_id"]))
855  {
856  // edit page
857  $ilTabs->addTarget("edit_content",
858  $this->ctrl->getLinkTargetByClass("ilPageObjectGUI", "edit"),
859  array("edit", "insert", "exec_pg"),
860  "", "", $force_active);
861  }
862 
863  // edit page
864  $ilTabs->addTarget("preview",
865  $this->ctrl->getLinkTargetByClass("ilPageObjectGUI", "preview"),
866  array("preview"),
867  "ilPageObjectGUI", "", $force_active);
868  }
869 
870  $force_active = false;
871  if ($rbacsystem->checkAccess('write', $_GET["ref_id"]))
872  {
873  $url = "";
874  if ($classname) $url = $this->ctrl->getLinkTargetByClass($classname, "editQuestion");
875  $commands = $_POST["cmd"];
876  if (is_array($commands))
877  {
878  foreach ($commands as $key => $value)
879  {
880  if (preg_match("/^delete_.*/", $key, $matches))
881  {
882  $force_active = true;
883  }
884  }
885  }
886  // edit question properties
887  $ilTabs->addTarget("edit_properties",
888  $url,
889  array("editQuestion", "save", "cancel", "addSuggestedSolution",
890  "cancelExplorer", "linkChilds", "removeSuggestedSolution",
891  "uploadingJavaapplet", "addParameter",
892  "saveEdit"),
893  $classname, "", $force_active);
894  }
895 
896  if ($_GET["q_id"])
897  {
898  $ilTabs->addTarget("feedback",
899  $this->ctrl->getLinkTargetByClass($classname, "feedback"),
900  array("feedback", "saveFeedback"),
901  $classname, "");
902  }
903 
904  // Assessment of questions sub menu entry
905  if ($_GET["q_id"])
906  {
907  $ilTabs->addTarget("statistics",
908  $this->ctrl->getLinkTargetByClass($classname, "assessment"),
909  array("assessment"),
910  $classname, "");
911  }
912 
913  if (($_GET["calling_test"] > 0) || ($_GET["test_ref_id"] > 0))
914  {
915  $ref_id = $_GET["calling_test"];
916  if (strlen($ref_id) == 0) $ref_id = $_GET["test_ref_id"];
917  $ilTabs->setBackTarget($this->lng->txt("backtocallingtest"), "ilias.php?baseClass=ilObjTestGUI&cmd=questions&ref_id=$ref_id");
918  }
919  else
920  {
921  $ilTabs->setBackTarget($this->lng->txt("qpl"), $this->ctrl->getLinkTargetByClass("ilobjquestionpoolgui", "questions"));
922  }
923  }
924 }
925 ?>