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