ILIAS  Release_5_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 /* 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 
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  {
56  require_once 'Services/Form/classes/class.ilPropertyFormGUI.php';
59  $this->saveTaxonomyAssignments();
60  return 0;
61  }
62  return 1;
63  }
64 
66  {
67  $this->object->setPoints( $_POST["points"] );
68  $this->object->setMaxSize( $_POST["maxsize"] );
69  $this->object->setAllowedExtensions( $_POST["allowedextensions"] );
70  $this->object->setCompletionBySubmission( $_POST['completion_by_submission'] == 1 ? true : false );
71  }
72 
78  public function editQuestion($checkonly = FALSE)
79  {
80  $save = $this->isSaveCommand();
81  $this->getQuestionTemplate();
82 
83  include_once("./Services/Form/classes/class.ilPropertyFormGUI.php");
84  $form = new ilPropertyFormGUI();
85  $form->setFormAction($this->ctrl->getFormAction($this));
86  $form->setTitle($this->outQuestionType());
87  $form->setMultipart(false);
88  $form->setTableWidth("100%");
89  $form->setId("assfileupload");
90 
91  $this->addBasicQuestionFormProperties($form);
92  $this->populateQuestionSpecificFormPart( $form );
93 
94  $this->populateTaxonomyFormSection($form);
95  $this->addQuestionFormCommandButtons($form);
96 
97  $errors = false;
98 
99  if ($save)
100  {
101  $form->setValuesByPost();
102  $errors = !$form->checkInput();
103  $form->setValuesByPost(); // again, because checkInput now performs the whole stripSlashes handling and
104  // we need this if we don't want to have duplication of backslashes
105  if ($errors) $checkonly = false;
106  }
107 
108  if (!$checkonly) $this->tpl->setVariable("QUESTION_DATA", $form->getHTML());
109  return $errors;
110  }
111 
113  {
114  // maxsize
115  $maxsize = new ilNumberInputGUI($this->lng->txt( "maxsize" ), "maxsize");
116  $maxsize->setValue( $this->object->getMaxSize() );
117  $maxsize->setInfo( $this->lng->txt( "maxsize_info" ) );
118  $maxsize->setSize( 10 );
119  $maxsize->setMinValue( 0 );
120  $maxsize->setMaxValue( $this->determineMaxFilesize() );
121  $maxsize->setRequired( FALSE );
122  $form->addItem( $maxsize );
123 
124  // allowedextensions
125  $allowedextensions = new ilTextInputGUI($this->lng->txt( "allowedextensions" ), "allowedextensions");
126  $allowedextensions->setInfo( $this->lng->txt( "allowedextensions_info" ) );
127  $allowedextensions->setValue( $this->object->getAllowedExtensions() );
128  $allowedextensions->setRequired( FALSE );
129  $form->addItem( $allowedextensions );
130 
131  // points
132  $points = new ilNumberInputGUI($this->lng->txt( "points" ), "points");
133  $points->allowDecimals(true);
134  $points->setValue( is_numeric( $this->object->getPoints() ) && $this->object->getPoints(
135  ) >= 0 ? $this->object->getPoints() : ''
136  );
137  $points->setRequired( TRUE );
138  $points->setSize( 3 );
139  $points->setMinValue( 0.0 );
140  $points->setMinvalueShouldBeGreater( false );
141  $form->addItem( $points );
142 
143  $subcompl = new ilCheckboxInputGUI($this->lng->txt( 'ass_completion_by_submission'
144  ), 'completion_by_submission');
145  $subcompl->setInfo( $this->lng->txt( 'ass_completion_by_submission_info' ) );
146  $subcompl->setValue( 1 );
147  $subcompl->setChecked( $this->object->isCompletionBySubmissionEnabled() );
148  $form->addItem( $subcompl );
149  return $form;
150  }
151 
155  public function determineMaxFilesize()
156  {
157  //mbecker: Quick fix for mantis bug 8595: Change size file
158  $upload_max_filesize = get_cfg_var( "upload_max_filesize" );
159  // get the value for the maximal post data from the php.ini (if available)
160  $post_max_size = get_cfg_var( "post_max_size" );
161 
162  //convert from short-string representation to "real" bytes
163  $multiplier_a = array( "K" => 1024, "M" => 1024 * 1024, "G" => 1024 * 1024 * 1024 );
164  $umf_parts = preg_split( "/(\d+)([K|G|M])/",
165  $upload_max_filesize,
166  -1,
167  PREG_SPLIT_DELIM_CAPTURE | PREG_SPLIT_NO_EMPTY
168  );
169  $pms_parts = preg_split( "/(\d+)([K|G|M])/",
170  $post_max_size,
171  -1,
172  PREG_SPLIT_DELIM_CAPTURE | PREG_SPLIT_NO_EMPTY
173  );
174 
175  if (count( $umf_parts ) == 2)
176  {
177  $upload_max_filesize = $umf_parts[0] * $multiplier_a[$umf_parts[1]];
178  }
179 
180  if (count( $pms_parts ) == 2)
181  {
182  $post_max_size = $pms_parts[0] * $multiplier_a[$pms_parts[1]];
183  }
184 
185  // use the smaller one as limit
186  $max_filesize = min( $upload_max_filesize, $post_max_size );
187 
188  if (!$max_filesize)
189  {
190  $max_filesize = max( $upload_max_filesize, $post_max_size );
191  return $max_filesize;
192  }
193  return $max_filesize;
194  }
195 
210  $active_id,
211  $pass = NULL,
212  $graphicalOutput = FALSE,
213  $result_output = FALSE,
214  $show_question_only = TRUE,
215  $show_feedback = FALSE,
216  $show_correct_solution = FALSE,
217  $show_manual_scoring = FALSE,
218  $show_question_text = TRUE
219  )
220  {
221  // get the solution of the user for the active pass or from the last pass if allowed
222  $template = new ilTemplate("tpl.il_as_qpl_fileupload_output_solution.html", TRUE, TRUE, "Modules/TestQuestionPool");
223 
224  $solutionvalue = "";
225  if (($active_id > 0) && (!$show_correct_solution))
226  {
227  $solutions =& $this->object->getSolutionValues($active_id, $pass);
228  include_once "./Modules/Test/classes/class.ilObjTest.php";
229  if (!ilObjTest::_getUsePreviousAnswers($active_id, true))
230  {
231  if (is_null($pass)) $pass = ilObjTest::_getPass($active_id);
232  }
233  $solutions =& $this->object->getSolutionValues($active_id, $pass);
234 
235  $files = ($show_manual_scoring) ? $this->object->getUploadedFilesForWeb($active_id, $pass) : $this->object->getUploadedFiles($active_id, $pass);
236  if (count($files))
237  {
238  include_once "./Modules/TestQuestionPool/classes/tables/class.assFileUploadFileTableGUI.php";
239  $table_gui = new assFileUploadFileTableGUI($this->getTargetGuiClass(), 'gotoquestion');
240  $table_gui->setTitle($this->lng->txt('already_delivered_files'), 'icon_file.svg', $this->lng->txt('already_delivered_files'));
241  $table_gui->setData($files);
242  $table_gui->setRowTemplate("tpl.il_as_qpl_fileupload_file_view_row.html", "Modules/TestQuestionPool");
243  $table_gui->setSelectAllCheckbox("");
244  $table_gui->clearCommandButtons();
245  $table_gui->disable('select_all');
246  $table_gui->disable('numinfo');
247  $template->setCurrentBlock("files");
248  $template->setVariable('FILES', $table_gui->getHTML());
249  $template->parseCurrentBlock();
250  }
251  }
252 
253  if (($active_id > 0) && (!$show_correct_solution))
254  {
255  $reached_points = $this->object->getReachedPoints($active_id, $pass);
256  if ($graphicalOutput)
257  {
258  // output of ok/not ok icons for user entered solutions
259  if ($reached_points == $this->object->getMaximumPoints())
260  {
261  $template->setCurrentBlock("icon_ok");
262  $template->setVariable("ICON_OK", ilUtil::getImagePath("icon_ok.svg"));
263  $template->setVariable("TEXT_OK", $this->lng->txt("answer_is_right"));
264  $template->parseCurrentBlock();
265  }
266  else
267  {
268  $template->setCurrentBlock("icon_ok");
269  if ($reached_points > 0)
270  {
271  $template->setVariable("ICON_NOT_OK", ilUtil::getImagePath("icon_mostly_ok.svg"));
272  $template->setVariable("TEXT_NOT_OK", $this->lng->txt("answer_is_not_correct_but_positive"));
273  }
274  else
275  {
276  $template->setVariable("ICON_NOT_OK", ilUtil::getImagePath("icon_not_ok.svg"));
277  $template->setVariable("TEXT_NOT_OK", $this->lng->txt("answer_is_wrong"));
278  }
279  $template->parseCurrentBlock();
280  }
281  }
282  }
283  else
284  {
285  $reached_points = $this->object->getPoints();
286  }
287 
288  if ($result_output)
289  {
290  $resulttext = ($reached_points == 1) ? "(%s " . $this->lng->txt("point") . ")" : "(%s " . $this->lng->txt("points") . ")";
291  $template->setVariable("RESULT_OUTPUT", sprintf($resulttext, $reached_points));
292  }
293  if ($show_question_text==true)
294  {
295  $template->setVariable("QUESTIONTEXT", $this->object->prepareTextareaOutput($this->object->getQuestion(), TRUE));
296  }
297  $questionoutput = $template->get();
298  $solutiontemplate = new ilTemplate("tpl.il_as_tst_solution_output.html",TRUE, TRUE, "Modules/TestQuestionPool");
299  $feedback = ($show_feedback) ? $this->getAnswerFeedbackOutput($active_id, $pass) : "";
300  if (strlen($feedback)) $solutiontemplate->setVariable("FEEDBACK", $feedback);
301  $solutiontemplate->setVariable("SOLUTION_OUTPUT", $questionoutput);
302  $solutionoutput = $solutiontemplate->get();
303  if (!$show_question_only)
304  {
305  // get page object output
306  $solutionoutput = $this->getILIASPage($solutionoutput);
307  }
308  return $solutionoutput;
309  }
310 
311  function getPreview($show_question_only = FALSE, $showInlineFeedback = false)
312  {
313  $template = new ilTemplate("tpl.il_as_qpl_fileupload_output.html",TRUE, TRUE, "Modules/TestQuestionPool");
314 
315  if( is_object($this->getPreviewSession()) )
316  {
317  $files = $this->object->getPreviewFileUploads($this->getPreviewSession());
318  if (count($files))
319  {
320  include_once "./Modules/TestQuestionPool/classes/tables/class.assFileUploadFileTableGUI.php";
321  $table_gui = new assFileUploadFileTableGUI(null , $this->getQuestionActionCmd(), 'ilAssQuestionPreview');
322  $table_gui->setTitle($this->lng->txt('already_delivered_files'), 'icon_file.svg', $this->lng->txt('already_delivered_files'));
323  $table_gui->setData($files);
324  $template->setCurrentBlock("files");
325  $template->setVariable('FILES', $table_gui->getHTML());
326  $template->parseCurrentBlock();
327  }
328  }
329 
330  if (strlen($this->object->getAllowedExtensions()))
331  {
332  $template->setCurrentBlock("allowed_extensions");
333  $template->setVariable("TXT_ALLOWED_EXTENSIONS", $this->object->prepareTextareaOutput($this->lng->txt("allowedextensions") . ": " . $this->object->getAllowedExtensions()));
334  $template->parseCurrentBlock();
335  }
336  $template->setVariable("QUESTIONTEXT", $this->object->prepareTextareaOutput($this->object->question, TRUE));
337  $template->setVariable("CMD_UPLOAD", $this->getQuestionActionCmd());
338  $template->setVariable("TEXT_UPLOAD", $this->object->prepareTextareaOutput($this->lng->txt('upload')));
339  $template->setVariable("TXT_UPLOAD_FILE", $this->object->prepareTextareaOutput($this->lng->txt('file_add')));
340  $template->setVariable("TXT_MAX_SIZE", $this->object->prepareTextareaOutput($this->lng->txt('file_notice') . " " . $this->object->getMaxFilesizeAsString()));
341 
342  $questionoutput = $template->get();
343  if (!$show_question_only)
344  {
345  // get page object output
346  $questionoutput = $this->getILIASPage($questionoutput);
347  }
348  return $questionoutput;
349  }
350 
351  function getTestOutput($active_id, $pass = NULL, $is_postponed = FALSE, $use_post_solutions = FALSE, $show_feedback = FALSE)
352  {
353  // generate the question output
354  $template = new ilTemplate("tpl.il_as_qpl_fileupload_output.html",TRUE, TRUE, "Modules/TestQuestionPool");
355 
356  if ($active_id)
357  {
358  $solutions = NULL;
359  include_once "./Modules/Test/classes/class.ilObjTest.php";
360  if (!ilObjTest::_getUsePreviousAnswers($active_id, true))
361  {
362  if (is_null($pass)) $pass = ilObjTest::_getPass($active_id);
363  }
364  $solutions =& $this->object->getSolutionValues($active_id, $pass);
365 
366  $files = $this->object->getUploadedFiles($active_id, $pass);
367  if (count($files))
368  {
369  include_once "./Modules/TestQuestionPool/classes/tables/class.assFileUploadFileTableGUI.php";
370  $table_gui = new assFileUploadFileTableGUI(null , $this->getQuestionActionCmd());
371  $table_gui->setTitle($this->lng->txt('already_delivered_files'), 'icon_file.svg', $this->lng->txt('already_delivered_files'));
372  $table_gui->setData($files);
373  $template->setCurrentBlock("files");
374  $template->setVariable('FILES', $table_gui->getHTML());
375  $template->parseCurrentBlock();
376  }
377  }
378 
379  if (strlen($this->object->getAllowedExtensions()))
380  {
381  $template->setCurrentBlock("allowed_extensions");
382  $template->setVariable("TXT_ALLOWED_EXTENSIONS", $this->object->prepareTextareaOutput($this->lng->txt("allowedextensions") . ": " . $this->object->getAllowedExtensions()));
383  $template->parseCurrentBlock();
384  }
385  $template->setVariable("QUESTIONTEXT", $this->object->prepareTextareaOutput($this->object->question, TRUE));
386  $template->setVariable("CMD_UPLOAD", $this->getQuestionActionCmd());
387  $template->setVariable("TEXT_UPLOAD", $this->object->prepareTextareaOutput($this->lng->txt('upload')));
388  $template->setVariable("TXT_UPLOAD_FILE", $this->object->prepareTextareaOutput($this->lng->txt('file_add')));
389  $template->setVariable("TXT_MAX_SIZE", $this->object->prepareTextareaOutput($this->lng->txt('file_notice') . " " . $this->object->getMaxFilesizeAsString()));
390 
391  $questionoutput = $template->get();
392  if (!$show_question_only)
393  {
394  // get page object output
395  $questionoutput = $this->getILIASPage($questionoutput);
396  }
397  $questionoutput = $template->get();
398  $pageoutput = $this->outQuestionPage("", $is_postponed, $active_id, $questionoutput);
399  return $pageoutput;
400  }
401 
409  function setQuestionTabs()
410  {
411  global $rbacsystem, $ilTabs;
412 
413  $ilTabs->clearTargets();
414 
415  $this->ctrl->setParameterByClass("ilAssQuestionPageGUI", "q_id", $_GET["q_id"]);
416  include_once "./Modules/TestQuestionPool/classes/class.assQuestion.php";
417  $q_type = $this->object->getQuestionType();
418 
419  if (strlen($q_type))
420  {
421  $classname = $q_type . "GUI";
422  $this->ctrl->setParameterByClass(strtolower($classname), "sel_question_types", $q_type);
423  $this->ctrl->setParameterByClass(strtolower($classname), "q_id", $_GET["q_id"]);
424  }
425 
426  if ($_GET["q_id"])
427  {
428  if ($rbacsystem->checkAccess('write', $_GET["ref_id"]))
429  {
430  // edit page
431  $ilTabs->addTarget("edit_page",
432  $this->ctrl->getLinkTargetByClass("ilAssQuestionPageGUI", "edit"),
433  array("edit", "insert", "exec_pg"),
434  "", "", $force_active);
435  }
436 
437  $this->addTab_QuestionPreview($ilTabs);
438  }
439 
440  $force_active = false;
441  if ($rbacsystem->checkAccess('write', $_GET["ref_id"]))
442  {
443  $url = "";
444  if ($classname) $url = $this->ctrl->getLinkTargetByClass($classname, "editQuestion");
445  // edit question properties
446  $ilTabs->addTarget("edit_question",
447  $url,
448  array("editQuestion", "save", "cancel", "saveEdit"),
449  $classname, "");
450  }
451 
452  // add tab for question feedback within common class assQuestionGUI
453  $this->addTab_QuestionFeedback($ilTabs);
454 
455  // add tab for question hint within common class assQuestionGUI
456  $this->addTab_QuestionHints($ilTabs);
457 
458  // add tab for question's suggested solution within common class assQuestionGUI
459  $this->addTab_SuggestedSolution($ilTabs, $classname);
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 
525  protected function getFormEncodingType()
526  {
528  }
529 }