ILIAS  Release_4_0_x_branch Revision 61816
 All Data Structures Namespaces Files Functions Variables Groups Pages
class.assFileUploadGUI.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 {
46  function __construct($id = -1)
47  {
49  include_once "./Modules/TestQuestionPool/classes/class.assFileUpload.php";
50  $this->object = new assFileUpload();
51  $this->setErrorMessage($this->lng->txt("msg_form_save_error"));
52  if ($id >= 0)
53  {
54  $this->object->loadFromDb($id);
55  }
56  }
57 
58  function getCommand($cmd)
59  {
60  return $cmd;
61  }
62 
69  function writePostData($always = false)
70  {
71  $hasErrors = (!$always) ? $this->editQuestion(true) : false;
72  if (!$hasErrors)
73  {
74  $this->object->setTitle($_POST["title"]);
75  $this->object->setAuthor($_POST["author"]);
76  $this->object->setComment($_POST["comment"]);
77  include_once "./Services/AdvancedEditing/classes/class.ilObjAdvancedEditing.php";
78  $questiontext = $_POST["question"];
79  $this->object->setQuestion($questiontext);
80  $this->object->setPoints($_POST["points"]);
81  // adding estimated working time
82  $this->object->setEstimatedWorkingTime(
83  $_POST["Estimated"]["hh"],
84  $_POST["Estimated"]["mm"],
85  $_POST["Estimated"]["ss"]
86  );
87  $this->object->setMaxSize($_POST["maxsize"]);
88  $this->object->setAllowedExtensions($_POST["allowedextensions"]);
89  return 0;
90  }
91  else
92  {
93  return 1;
94  }
95  }
96 
102  public function editQuestion($checkonly = FALSE)
103  {
104  $save = ((strcmp($this->ctrl->getCmd(), "save") == 0) || (strcmp($this->ctrl->getCmd(), "saveEdit") == 0)) ? TRUE : FALSE;
105  $this->getQuestionTemplate();
106 
107  include_once("./Services/Form/classes/class.ilPropertyFormGUI.php");
108  $form = new ilPropertyFormGUI();
109  $form->setFormAction($this->ctrl->getFormAction($this));
110  $form->setTitle($this->outQuestionType());
111  $form->setMultipart(false);
112  $form->setTableWidth("100%");
113  $form->setId("assfileupload");
114 
115  $this->addBasicQuestionFormProperties($form);
116 
117  // maxsize
118  $maxsize = new ilNumberInputGUI($this->lng->txt("maxsize"), "maxsize");
119  $maxsize->setValue($this->object->getMaxSize());
120  $maxsize->setInfo($this->lng->txt("maxsize_info"));
121  $maxsize->setSize(10);
122  $maxsize->setMinValue(0);
123  $maxsize->setMaxValue($this->object->getMaxFilesizeInBytes());
124  $maxsize->setRequired(FALSE);
125  $form->addItem($maxsize);
126  // allowedextensions
127  $allowedextensions = new ilTextInputGUI($this->lng->txt("allowedextensions"), "allowedextensions");
128  $allowedextensions->setInfo($this->lng->txt("allowedextensions_info"));
129  $allowedextensions->setValue($this->object->getAllowedExtensions());
130  $allowedextensions->setRequired(FALSE);
131  $form->addItem($allowedextensions);
132  // points
133  $points = new ilNumberInputGUI($this->lng->txt("points"), "points");
134  $points->setValue($this->object->getPoints());
135  $points->setRequired(TRUE);
136  $points->setSize(3);
137  $points->setMinValue(0.0);
138  $form->addItem($points);
139 
140  $this->addQuestionFormCommandButtons($form);
141 
142  $errors = false;
143 
144  if ($save)
145  {
146  $form->setValuesByPost();
147  $errors = !$form->checkInput();
148  $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
149  if ($errors) $checkonly = false;
150  }
151 
152  if (!$checkonly) $this->tpl->setVariable("QUESTION_DATA", $form->getHTML());
153  return $errors;
154  }
155 
156  function outQuestionForTest($formaction, $active_id, $pass = NULL, $is_postponed = FALSE, $use_post_solutions = FALSE, $show_feedback = FALSE)
157  {
158  $test_output = $this->getTestOutput($active_id, $pass, $is_postponed, $use_post_solutions, $show_feedback);
159  $this->tpl->setVariable("QUESTION_OUTPUT", $test_output);
160  $this->tpl->setVariable("FORMACTION", $formaction);
161  $this->tpl->setVariable("ENCTYPE", 'enctype="multipart/form-data"');
162  }
163 
178  $active_id,
179  $pass = NULL,
180  $graphicalOutput = FALSE,
181  $result_output = FALSE,
182  $show_question_only = TRUE,
183  $show_feedback = FALSE,
184  $show_correct_solution = FALSE,
185  $show_manual_scoring = FALSE
186  )
187  {
188  // get the solution of the user for the active pass or from the last pass if allowed
189  $template = new ilTemplate("tpl.il_as_qpl_fileupload_output_solution.html", TRUE, TRUE, "Modules/TestQuestionPool");
190 
191  $solutionvalue = "";
192  if (($active_id > 0) && (!$show_correct_solution))
193  {
194  $solutions =& $this->object->getSolutionValues($active_id, $pass);
195  include_once "./Modules/Test/classes/class.ilObjTest.php";
196  if (!ilObjTest::_getUsePreviousAnswers($active_id, true))
197  {
198  if (is_null($pass)) $pass = ilObjTest::_getPass($active_id);
199  }
200  $solutions =& $this->object->getSolutionValues($active_id, $pass);
201 
202  $files = ($show_manual_scoring) ? $this->object->getUploadedFilesForWeb($active_id, $pass) : $this->object->getUploadedFiles($active_id, $pass);
203  if (count($files))
204  {
205  include_once "./Modules/TestQuestionPool/classes/tables/class.assFileUploadFileTableGUI.php";
206  $table_gui = new assFileUploadFileTableGUI("iltestoutputgui", 'gotoquestion');
207  $table_gui->setTitle($this->lng->txt('already_delivered_files'), 'icon_file.gif', $this->lng->txt('already_delivered_files'));
208  $table_gui->setData($files);
209  $table_gui->setRowTemplate("tpl.il_as_qpl_fileupload_file_view_row.html", "Modules/TestQuestionPool");
210  $table_gui->setSelectAllCheckbox("");
211  $table_gui->clearCommandButtons();
212  $table_gui->disable('select_all');
213  $table_gui->disable('numinfo');
214  $template->setCurrentBlock("files");
215  $template->setVariable('FILES', $table_gui->getHTML());
216  $template->parseCurrentBlock();
217  }
218  }
219 
220  if (($active_id > 0) && (!$show_correct_solution))
221  {
222  $reached_points = $this->object->getReachedPoints($active_id, $pass);
223  if ($graphicalOutput)
224  {
225  // output of ok/not ok icons for user entered solutions
226  if ($reached_points == $this->object->getMaximumPoints())
227  {
228  $template->setCurrentBlock("icon_ok");
229  $template->setVariable("ICON_OK", ilUtil::getImagePath("icon_ok.gif"));
230  $template->setVariable("TEXT_OK", $this->lng->txt("answer_is_right"));
231  $template->parseCurrentBlock();
232  }
233  else
234  {
235  $template->setCurrentBlock("icon_ok");
236  if ($reached_points > 0)
237  {
238  $template->setVariable("ICON_NOT_OK", ilUtil::getImagePath("icon_mostly_ok.gif"));
239  $template->setVariable("TEXT_NOT_OK", $this->lng->txt("answer_is_not_correct_but_positive"));
240  }
241  else
242  {
243  $template->setVariable("ICON_NOT_OK", ilUtil::getImagePath("icon_not_ok.gif"));
244  $template->setVariable("TEXT_NOT_OK", $this->lng->txt("answer_is_wrong"));
245  }
246  $template->parseCurrentBlock();
247  }
248  }
249  }
250  else
251  {
252  $reached_points = $this->object->getPoints();
253  }
254 
255  if ($result_output)
256  {
257  $resulttext = ($reached_points == 1) ? "(%s " . $this->lng->txt("point") . ")" : "(%s " . $this->lng->txt("points") . ")";
258  $template->setVariable("RESULT_OUTPUT", sprintf($resulttext, $reached_points));
259  }
260  $template->setVariable("QUESTIONTEXT", $this->object->prepareTextareaOutput($this->object->getQuestion(), TRUE));
261 
262  $questionoutput = $template->get();
263  $solutiontemplate = new ilTemplate("tpl.il_as_tst_solution_output.html",TRUE, TRUE, "Modules/TestQuestionPool");
264  $feedback = ($show_feedback) ? $this->getAnswerFeedbackOutput($active_id, $pass) : "";
265  if (strlen($feedback)) $solutiontemplate->setVariable("FEEDBACK", $feedback);
266  $solutiontemplate->setVariable("SOLUTION_OUTPUT", $questionoutput);
267  $solutionoutput = $solutiontemplate->get();
268  if (!$show_question_only)
269  {
270  // get page object output
271  $solutionoutput = $this->getILIASPage($solutionoutput);
272  }
273  return $solutionoutput;
274  }
275 
276  function getPreview($show_question_only = FALSE)
277  {
278  $template = new ilTemplate("tpl.il_as_qpl_fileupload_output.html",TRUE, TRUE, "Modules/TestQuestionPool");
279  if (strlen($this->object->getAllowedExtensions()))
280  {
281  $template->setCurrentBlock("allowed_extensions");
282  $template->setVariable("TXT_ALLOWED_EXTENSIONS", $this->object->prepareTextareaOutput($this->lng->txt("allowedextensions") . ": " . $this->object->getAllowedExtensions()));
283  $template->parseCurrentBlock();
284  }
285  $template->setVariable("QUESTIONTEXT", $this->object->prepareTextareaOutput($this->object->question, TRUE));
286  $template->setVariable("TEXT_UPLOAD", $this->object->prepareTextareaOutput($this->lng->txt('upload')));
287  $template->setVariable("TXT_UPLOAD_FILE", $this->object->prepareTextareaOutput($this->lng->txt('file_add')));
288  $template->setVariable("TXT_MAX_SIZE", $this->object->prepareTextareaOutput($this->lng->txt('file_notice') . ": " . $this->object->getMaxFilesizeAsString()));
289 
290  $questionoutput = $template->get();
291  if (!$show_question_only)
292  {
293  // get page object output
294  $questionoutput = $this->getILIASPage($questionoutput);
295  }
296  return $questionoutput;
297  }
298 
299  function getTestOutput($active_id, $pass = NULL, $is_postponed = FALSE, $use_post_solutions = FALSE, $show_feedback = FALSE)
300  {
301  // generate the question output
302  $template = new ilTemplate("tpl.il_as_qpl_fileupload_output.html",TRUE, TRUE, "Modules/TestQuestionPool");
303 
304  if ($active_id)
305  {
306  $solutions = NULL;
307  include_once "./Modules/Test/classes/class.ilObjTest.php";
308  if (!ilObjTest::_getUsePreviousAnswers($active_id, true))
309  {
310  if (is_null($pass)) $pass = ilObjTest::_getPass($active_id);
311  }
312  $solutions =& $this->object->getSolutionValues($active_id, $pass);
313 
314  $files = $this->object->getUploadedFiles($active_id, $pass);
315  if (count($files))
316  {
317  include_once "./Modules/TestQuestionPool/classes/tables/class.assFileUploadFileTableGUI.php";
318  $table_gui = new assFileUploadFileTableGUI("iltestoutputgui", 'gotoquestion');
319  $table_gui->setTitle($this->lng->txt('already_delivered_files'), 'icon_file.gif', $this->lng->txt('already_delivered_files'));
320  $table_gui->setData($files);
321  $template->setCurrentBlock("files");
322  $template->setVariable('FILES', $table_gui->getHTML());
323  $template->parseCurrentBlock();
324  }
325  }
326 
327  if (strlen($this->object->getAllowedExtensions()))
328  {
329  $template->setCurrentBlock("allowed_extensions");
330  $template->setVariable("TXT_ALLOWED_EXTENSIONS", $this->object->prepareTextareaOutput($this->lng->txt("allowedextensions") . ": " . $this->object->getAllowedExtensions()));
331  $template->parseCurrentBlock();
332  }
333  $template->setVariable("QUESTIONTEXT", $this->object->prepareTextareaOutput($this->object->question, TRUE));
334  $template->setVariable("TEXT_UPLOAD", $this->object->prepareTextareaOutput($this->lng->txt('upload')));
335  $template->setVariable("TXT_UPLOAD_FILE", $this->object->prepareTextareaOutput($this->lng->txt('file_add')));
336  $template->setVariable("TXT_MAX_SIZE", $this->object->prepareTextareaOutput($this->lng->txt('file_notice') . ": " . $this->object->getMaxFilesizeAsString()));
337 
338  $questionoutput = $template->get();
339  if (!$show_question_only)
340  {
341  // get page object output
342  $questionoutput = $this->getILIASPage($questionoutput);
343  }
344  $questionoutput = $template->get();
345  $pageoutput = $this->outQuestionPage("", $is_postponed, $active_id, $questionoutput);
346  return $pageoutput;
347  }
348 
354  function saveFeedback()
355  {
356  include_once "./Services/AdvancedEditing/classes/class.ilObjAdvancedEditing.php";
357  $errors = $this->feedback(true);
358  $this->object->saveFeedbackGeneric(0, $_POST["feedback_incomplete"]);
359  $this->object->saveFeedbackGeneric(1, $_POST["feedback_complete"]);
360  $this->object->cleanupMediaObjectUsage();
362  }
363 
369  function setQuestionTabs()
370  {
371  global $rbacsystem, $ilTabs;
372 
373  $this->ctrl->setParameterByClass("ilpageobjectgui", "q_id", $_GET["q_id"]);
374  include_once "./Modules/TestQuestionPool/classes/class.assQuestion.php";
375  $q_type = $this->object->getQuestionType();
376 
377  if (strlen($q_type))
378  {
379  $classname = $q_type . "GUI";
380  $this->ctrl->setParameterByClass(strtolower($classname), "sel_question_types", $q_type);
381  $this->ctrl->setParameterByClass(strtolower($classname), "q_id", $_GET["q_id"]);
382  }
383 
384  if ($_GET["q_id"])
385  {
386  if ($rbacsystem->checkAccess('write', $_GET["ref_id"]))
387  {
388  // edit page
389  $ilTabs->addTarget("edit_content",
390  $this->ctrl->getLinkTargetByClass("ilPageObjectGUI", "edit"),
391  array("edit", "insert", "exec_pg"),
392  "", "", $force_active);
393  }
394 
395  // edit page
396  $ilTabs->addTarget("preview",
397  $this->ctrl->getLinkTargetByClass("ilPageObjectGUI", "preview"),
398  array("preview"),
399  "ilPageObjectGUI", "", $force_active);
400  }
401 
402  $force_active = false;
403  if ($rbacsystem->checkAccess('write', $_GET["ref_id"]))
404  {
405  $url = "";
406  if ($classname) $url = $this->ctrl->getLinkTargetByClass($classname, "editQuestion");
407  // edit question properties
408  $ilTabs->addTarget("edit_properties",
409  $url,
410  array("editQuestion", "save", "cancel", "saveEdit"),
411  $classname, "");
412  }
413 
414  if ($_GET["q_id"])
415  {
416  $ilTabs->addTarget("feedback",
417  $this->ctrl->getLinkTargetByClass($classname, "feedback"),
418  array("feedback", "saveFeedback"),
419  $classname, "");
420  }
421 
422  if ($_GET["q_id"])
423  {
424  $ilTabs->addTarget("solution_hint",
425  $this->ctrl->getLinkTargetByClass($classname, "suggestedsolution"),
426  array("suggestedsolution", "saveSuggestedSolution", "outSolutionExplorer", "cancel",
427  "addSuggestedSolution","cancelExplorer", "linkChilds", "removeSuggestedSolution"
428  ),
429  $classname,
430  ""
431  );
432  }
433 
434  // Assessment of questions sub menu entry
435  if ($_GET["q_id"])
436  {
437  $ilTabs->addTarget("statistics",
438  $this->ctrl->getLinkTargetByClass($classname, "assessment"),
439  array("assessment"),
440  $classname, "");
441  }
442 
443  if (($_GET["calling_test"] > 0) || ($_GET["test_ref_id"] > 0))
444  {
445  $ref_id = $_GET["calling_test"];
446  if (strlen($ref_id) == 0) $ref_id = $_GET["test_ref_id"];
447  $ilTabs->setBackTarget($this->lng->txt("backtocallingtest"), "ilias.php?baseClass=ilObjTestGUI&cmd=questions&ref_id=$ref_id");
448  }
449  else
450  {
451  $ilTabs->setBackTarget($this->lng->txt("qpl"), $this->ctrl->getLinkTargetByClass("ilobjquestionpoolgui", "questions"));
452  }
453  }
454 }
455 ?>