ILIAS  release_4-3 Revision
 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 
38 {
47  function __construct($id = -1)
48  {
50  include_once "./Modules/TestQuestionPool/classes/class.assFileUpload.php";
51  $this->object = new assFileUpload();
52  $this->setErrorMessage($this->lng->txt("msg_form_save_error"));
53  if ($id >= 0)
54  {
55  $this->object->loadFromDb($id);
56  }
57  }
58 
59  function getCommand($cmd)
60  {
61  return $cmd;
62  }
63 
70  function writePostData($always = false)
71  {
72  $hasErrors = (!$always) ? $this->editQuestion(true) : false;
73  if (!$hasErrors)
74  {
75  $this->object->setTitle($_POST["title"]);
76  $this->object->setAuthor($_POST["author"]);
77  $this->object->setComment($_POST["comment"]);
78  include_once "./Services/AdvancedEditing/classes/class.ilObjAdvancedEditing.php";
79  $questiontext = $_POST["question"];
80  $this->object->setQuestion($questiontext);
81  $this->object->setPoints($_POST["points"]);
82  // adding estimated working time
83  $this->object->setEstimatedWorkingTime(
84  $_POST["Estimated"]["hh"],
85  $_POST["Estimated"]["mm"],
86  $_POST["Estimated"]["ss"]
87  );
88  $this->object->setMaxSize($_POST["maxsize"]);
89  $this->object->setAllowedExtensions($_POST["allowedextensions"]);
90  $this->object->setCompletionBySubmission($_POST['completion_by_submission'] == 1 ? true : false);
91  return 0;
92  }
93  else
94  {
95  return 1;
96  }
97  }
98 
104  public function editQuestion($checkonly = FALSE)
105  {
106  $save = $this->isSaveCommand();
107  $this->getQuestionTemplate();
108 
109  include_once("./Services/Form/classes/class.ilPropertyFormGUI.php");
110  $form = new ilPropertyFormGUI();
111  $form->setFormAction($this->ctrl->getFormAction($this));
112  $form->setTitle($this->outQuestionType());
113  $form->setMultipart(false);
114  $form->setTableWidth("100%");
115  $form->setId("assfileupload");
116 
117  $this->addBasicQuestionFormProperties($form);
118 
119  // maxsize
120  $maxsize = new ilNumberInputGUI($this->lng->txt("maxsize"), "maxsize");
121  $maxsize->setValue($this->object->getMaxSize());
122  $maxsize->setInfo($this->lng->txt("maxsize_info"));
123  $maxsize->setSize(10);
124  $maxsize->setMinValue(0);
125 
126  //mbecker: Quick fix for mantis bug 8595: Change size file
127  $umf = get_cfg_var("upload_max_filesize");
128  // get the value for the maximal post data from the php.ini (if available)
129  $pms = get_cfg_var("post_max_size");
130 
131  //convert from short-string representation to "real" bytes
132  $multiplier_a=array("K"=>1024, "M"=>1024*1024, "G"=>1024*1024*1024);
133 
134  $umf_parts=preg_split("/(\d+)([K|G|M])/", $umf, -1, PREG_SPLIT_DELIM_CAPTURE|PREG_SPLIT_NO_EMPTY);
135  $pms_parts=preg_split("/(\d+)([K|G|M])/", $pms, -1, PREG_SPLIT_DELIM_CAPTURE|PREG_SPLIT_NO_EMPTY);
136 
137  if (count($umf_parts) == 2) { $umf = $umf_parts[0]*$multiplier_a[$umf_parts[1]]; }
138  if (count($pms_parts) == 2) { $pms = $pms_parts[0]*$multiplier_a[$pms_parts[1]]; }
139 
140  // use the smaller one as limit
141  $max_filesize = min($umf, $pms);
142 
143  if (!$max_filesize) $max_filesize=max($umf, $pms);
144 
145  $maxsize->setMaxValue($max_filesize);
146  // end quick fix
147 
148  $maxsize->setRequired(FALSE);
149  $form->addItem($maxsize);
150  // allowedextensions
151  $allowedextensions = new ilTextInputGUI($this->lng->txt("allowedextensions"), "allowedextensions");
152  $allowedextensions->setInfo($this->lng->txt("allowedextensions_info"));
153  $allowedextensions->setValue($this->object->getAllowedExtensions());
154  $allowedextensions->setRequired(FALSE);
155  $form->addItem($allowedextensions);
156  // points
157  $points = new ilNumberInputGUI($this->lng->txt("points"), "points");
158  $points->setValue(is_numeric($this->object->getPoints()) && $this->object->getPoints() >= 0 ? $this->object->getPoints() : '');
159  $points->setRequired(TRUE);
160  $points->setSize(3);
161  $points->setMinValue(0.0);
162  $points->setMinvalueShouldBeGreater(false);
163  $form->addItem($points);
164 
165  $subcompl = new ilCheckboxInputGUI($this->lng->txt('ass_completion_by_submission'), 'completion_by_submission');
166  $subcompl->setInfo($this->lng->txt('ass_completion_by_submission_info'));
167  $subcompl->setValue(1);
168  $subcompl->setChecked($this->object->isCompletionBySubmissionEnabled());
169  $form->addItem($subcompl);
170 
171  $this->addQuestionFormCommandButtons($form);
172 
173  $errors = false;
174 
175  if ($save)
176  {
177  $form->setValuesByPost();
178  $errors = !$form->checkInput();
179  $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
180  if ($errors) $checkonly = false;
181  }
182 
183  if (!$checkonly) $this->tpl->setVariable("QUESTION_DATA", $form->getHTML());
184  return $errors;
185  }
186 
187  function outQuestionForTest($formaction, $active_id, $pass = NULL, $is_postponed = FALSE, $use_post_solutions = FALSE, $show_feedback = FALSE)
188  {
189  $test_output = $this->getTestOutput($active_id, $pass, $is_postponed, $use_post_solutions, $show_feedback);
190  $this->tpl->setVariable("QUESTION_OUTPUT", $test_output);
191  $this->tpl->setVariable("FORMACTION", $formaction);
192  $this->tpl->setVariable("ENCTYPE", 'enctype="multipart/form-data"');
193  }
194 
209  $active_id,
210  $pass = NULL,
211  $graphicalOutput = FALSE,
212  $result_output = FALSE,
213  $show_question_only = TRUE,
214  $show_feedback = FALSE,
215  $show_correct_solution = FALSE,
216  $show_manual_scoring = FALSE,
217  $show_question_text = TRUE
218  )
219  {
220  // get the solution of the user for the active pass or from the last pass if allowed
221  $template = new ilTemplate("tpl.il_as_qpl_fileupload_output_solution.html", TRUE, TRUE, "Modules/TestQuestionPool");
222 
223  $solutionvalue = "";
224  if (($active_id > 0) && (!$show_correct_solution))
225  {
226  $solutions =& $this->object->getSolutionValues($active_id, $pass);
227  include_once "./Modules/Test/classes/class.ilObjTest.php";
228  if (!ilObjTest::_getUsePreviousAnswers($active_id, true))
229  {
230  if (is_null($pass)) $pass = ilObjTest::_getPass($active_id);
231  }
232  $solutions =& $this->object->getSolutionValues($active_id, $pass);
233 
234  $files = ($show_manual_scoring) ? $this->object->getUploadedFilesForWeb($active_id, $pass) : $this->object->getUploadedFiles($active_id, $pass);
235  if (count($files))
236  {
237  include_once "./Modules/TestQuestionPool/classes/tables/class.assFileUploadFileTableGUI.php";
238  $table_gui = new assFileUploadFileTableGUI("iltestoutputgui", 'gotoquestion');
239  $table_gui->setTitle($this->lng->txt('already_delivered_files'), 'icon_file.png', $this->lng->txt('already_delivered_files'));
240  $table_gui->setData($files);
241  $table_gui->setRowTemplate("tpl.il_as_qpl_fileupload_file_view_row.html", "Modules/TestQuestionPool");
242  $table_gui->setSelectAllCheckbox("");
243  $table_gui->clearCommandButtons();
244  $table_gui->disable('select_all');
245  $table_gui->disable('numinfo');
246  $template->setCurrentBlock("files");
247  $template->setVariable('FILES', $table_gui->getHTML());
248  $template->parseCurrentBlock();
249  }
250  }
251 
252  if (($active_id > 0) && (!$show_correct_solution))
253  {
254  $reached_points = $this->object->getReachedPoints($active_id, $pass);
255  if ($graphicalOutput)
256  {
257  // output of ok/not ok icons for user entered solutions
258  if ($reached_points == $this->object->getMaximumPoints())
259  {
260  $template->setCurrentBlock("icon_ok");
261  $template->setVariable("ICON_OK", ilUtil::getImagePath("icon_ok.png"));
262  $template->setVariable("TEXT_OK", $this->lng->txt("answer_is_right"));
263  $template->parseCurrentBlock();
264  }
265  else
266  {
267  $template->setCurrentBlock("icon_ok");
268  if ($reached_points > 0)
269  {
270  $template->setVariable("ICON_NOT_OK", ilUtil::getImagePath("icon_mostly_ok.png"));
271  $template->setVariable("TEXT_NOT_OK", $this->lng->txt("answer_is_not_correct_but_positive"));
272  }
273  else
274  {
275  $template->setVariable("ICON_NOT_OK", ilUtil::getImagePath("icon_not_ok.png"));
276  $template->setVariable("TEXT_NOT_OK", $this->lng->txt("answer_is_wrong"));
277  }
278  $template->parseCurrentBlock();
279  }
280  }
281  }
282  else
283  {
284  $reached_points = $this->object->getPoints();
285  }
286 
287  if ($result_output)
288  {
289  $resulttext = ($reached_points == 1) ? "(%s " . $this->lng->txt("point") . ")" : "(%s " . $this->lng->txt("points") . ")";
290  $template->setVariable("RESULT_OUTPUT", sprintf($resulttext, $reached_points));
291  }
292  if ($show_question_text==true)
293  {
294  $template->setVariable("QUESTIONTEXT", $this->object->prepareTextareaOutput($this->object->getQuestion(), TRUE));
295  }
296  $questionoutput = $template->get();
297  $solutiontemplate = new ilTemplate("tpl.il_as_tst_solution_output.html",TRUE, TRUE, "Modules/TestQuestionPool");
298  $feedback = ($show_feedback) ? $this->getAnswerFeedbackOutput($active_id, $pass) : "";
299  if (strlen($feedback)) $solutiontemplate->setVariable("FEEDBACK", $this->object->prepareTextareaOutput($feedback, true));
300  $solutiontemplate->setVariable("SOLUTION_OUTPUT", $questionoutput);
301  $solutionoutput = $solutiontemplate->get();
302  if (!$show_question_only)
303  {
304  // get page object output
305  $solutionoutput = '<div class="ilc_question_Standard">'.$solutionoutput."</div>";
306  }
307  return $solutionoutput;
308  }
309 
310  function getPreview($show_question_only = FALSE)
311  {
312  $template = new ilTemplate("tpl.il_as_qpl_fileupload_output.html",TRUE, TRUE, "Modules/TestQuestionPool");
313  if (strlen($this->object->getAllowedExtensions()))
314  {
315  $template->setCurrentBlock("allowed_extensions");
316  $template->setVariable("TXT_ALLOWED_EXTENSIONS", $this->object->prepareTextareaOutput($this->lng->txt("allowedextensions") . ": " . $this->object->getAllowedExtensions()));
317  $template->parseCurrentBlock();
318  }
319  $template->setVariable("QUESTIONTEXT", $this->object->prepareTextareaOutput($this->object->question, TRUE));
320  $template->setVariable("TEXT_UPLOAD", $this->object->prepareTextareaOutput($this->lng->txt('upload')));
321  $template->setVariable("TXT_UPLOAD_FILE", $this->object->prepareTextareaOutput($this->lng->txt('file_add')));
322  $template->setVariable("TXT_MAX_SIZE", $this->object->prepareTextareaOutput($this->lng->txt('file_notice') . ": " . $this->object->getMaxFilesizeAsString()));
323 
324  $questionoutput = $template->get();
325  if (!$show_question_only)
326  {
327  // get page object output
328  $questionoutput = $this->getILIASPage($questionoutput);
329  }
330  return $questionoutput;
331  }
332 
333  function getTestOutput($active_id, $pass = NULL, $is_postponed = FALSE, $use_post_solutions = FALSE, $show_feedback = FALSE)
334  {
335  // generate the question output
336  $template = new ilTemplate("tpl.il_as_qpl_fileupload_output.html",TRUE, TRUE, "Modules/TestQuestionPool");
337 
338  if ($active_id)
339  {
340  $solutions = NULL;
341  include_once "./Modules/Test/classes/class.ilObjTest.php";
342  if (!ilObjTest::_getUsePreviousAnswers($active_id, true))
343  {
344  if (is_null($pass)) $pass = ilObjTest::_getPass($active_id);
345  }
346  $solutions =& $this->object->getSolutionValues($active_id, $pass);
347 
348  $files = $this->object->getUploadedFiles($active_id, $pass);
349  if (count($files))
350  {
351  include_once "./Modules/TestQuestionPool/classes/tables/class.assFileUploadFileTableGUI.php";
352  $table_gui = new assFileUploadFileTableGUI("iltestoutputgui", 'gotoquestion');
353  $table_gui->setTitle($this->lng->txt('already_delivered_files'), 'icon_file.png', $this->lng->txt('already_delivered_files'));
354  $table_gui->setData($files);
355  $template->setCurrentBlock("files");
356  $template->setVariable('FILES', $table_gui->getHTML());
357  $template->parseCurrentBlock();
358  }
359  }
360 
361  if (strlen($this->object->getAllowedExtensions()))
362  {
363  $template->setCurrentBlock("allowed_extensions");
364  $template->setVariable("TXT_ALLOWED_EXTENSIONS", $this->object->prepareTextareaOutput($this->lng->txt("allowedextensions") . ": " . $this->object->getAllowedExtensions()));
365  $template->parseCurrentBlock();
366  }
367  $template->setVariable("QUESTIONTEXT", $this->object->prepareTextareaOutput($this->object->question, TRUE));
368  $template->setVariable("TEXT_UPLOAD", $this->object->prepareTextareaOutput($this->lng->txt('upload')));
369  $template->setVariable("TXT_UPLOAD_FILE", $this->object->prepareTextareaOutput($this->lng->txt('file_add')));
370  $template->setVariable("TXT_MAX_SIZE", $this->object->prepareTextareaOutput($this->lng->txt('file_notice') . ": " . $this->object->getMaxFilesizeAsString()));
371 
372  $questionoutput = $template->get();
373  if (!$show_question_only)
374  {
375  // get page object output
376  $questionoutput = $this->getILIASPage($questionoutput);
377  }
378  $questionoutput = $template->get();
379  $pageoutput = $this->outQuestionPage("", $is_postponed, $active_id, $questionoutput);
380  return $pageoutput;
381  }
382 
388  function saveFeedback()
389  {
390  include_once "./Services/AdvancedEditing/classes/class.ilObjAdvancedEditing.php";
391  $errors = $this->feedback(true);
392  $this->object->saveFeedbackGeneric(0, $_POST["feedback_incomplete"]);
393  $this->object->saveFeedbackGeneric(1, $_POST["feedback_complete"]);
394  $this->object->cleanupMediaObjectUsage();
396  }
397 
405  function setQuestionTabs()
406  {
407  global $rbacsystem, $ilTabs;
408 
409  $this->ctrl->setParameterByClass("ilpageobjectgui", "q_id", $_GET["q_id"]);
410  include_once "./Modules/TestQuestionPool/classes/class.assQuestion.php";
411  $q_type = $this->object->getQuestionType();
412 
413  if (strlen($q_type))
414  {
415  $classname = $q_type . "GUI";
416  $this->ctrl->setParameterByClass(strtolower($classname), "sel_question_types", $q_type);
417  $this->ctrl->setParameterByClass(strtolower($classname), "q_id", $_GET["q_id"]);
418  }
419 
420  if ($_GET["q_id"])
421  {
422  if ($rbacsystem->checkAccess('write', $_GET["ref_id"]))
423  {
424  // edit page
425  $ilTabs->addTarget("edit_page",
426  $this->ctrl->getLinkTargetByClass("ilPageObjectGUI", "edit"),
427  array("edit", "insert", "exec_pg"),
428  "", "", $force_active);
429  }
430 
431  // edit page
432  $ilTabs->addTarget("preview",
433  $this->ctrl->getLinkTargetByClass("ilPageObjectGUI", "preview"),
434  array("preview"),
435  "ilPageObjectGUI", "", $force_active);
436  }
437 
438  $force_active = false;
439  if ($rbacsystem->checkAccess('write', $_GET["ref_id"]))
440  {
441  $url = "";
442  if ($classname) $url = $this->ctrl->getLinkTargetByClass($classname, "editQuestion");
443  // edit question properties
444  $ilTabs->addTarget("edit_question",
445  $url,
446  array("editQuestion", "save", "cancel", "saveEdit"),
447  $classname, "");
448  }
449 
450  if ($_GET["q_id"])
451  {
452  $ilTabs->addTarget("feedback",
453  $this->ctrl->getLinkTargetByClass($classname, "feedback"),
454  array("feedback", "saveFeedback"),
455  $classname, "");
456  }
457 
458  // add tab for question hint within common class assQuestionGUI
459  $this->addTab_QuestionHints($ilTabs);
460 
461  if ($_GET["q_id"])
462  {
463  $ilTabs->addTarget("solution_hint",
464  $this->ctrl->getLinkTargetByClass($classname, "suggestedsolution"),
465  array("suggestedsolution", "saveSuggestedSolution", "outSolutionExplorer", "cancel",
466  "addSuggestedSolution","cancelExplorer", "linkChilds", "removeSuggestedSolution"
467  ),
468  $classname,
469  ""
470  );
471  }
472 
473  // Assessment of questions sub menu entry
474  if ($_GET["q_id"])
475  {
476  $ilTabs->addTarget("statistics",
477  $this->ctrl->getLinkTargetByClass($classname, "assessment"),
478  array("assessment"),
479  $classname, "");
480  }
481 
482  if (($_GET["calling_test"] > 0) || ($_GET["test_ref_id"] > 0))
483  {
484  $ref_id = $_GET["calling_test"];
485  if (strlen($ref_id) == 0) $ref_id = $_GET["test_ref_id"];
486 
487  global $___test_express_mode;
488 
489  if (!$_GET['test_express_mode'] && !$___test_express_mode) {
490  $ilTabs->setBackTarget($this->lng->txt("backtocallingtest"), "ilias.php?baseClass=ilObjTestGUI&cmd=questions&ref_id=$ref_id");
491  }
492  else {
494  $ilTabs->setBackTarget($this->lng->txt("backtocallingtest"), $link);
495  }
496  }
497  else
498  {
499  $ilTabs->setBackTarget($this->lng->txt("qpl"), $this->ctrl->getLinkTargetByClass("ilobjquestionpoolgui", "questions"));
500  }
501  }
502 
503  function getSpecificFeedbackOutput($active_id, $pass)
504  {
505  $output = "";
506  return $this->object->prepareTextareaOutput($output, TRUE);
507  }
508 }