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