ILIAS  release_5-1 Revision 5.0.0-5477-g43f3e3fab5f
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
4require_once './Modules/TestQuestionPool/classes/class.assQuestionGUI.php';
5require_once './Modules/Test/classes/inc.AssessmentConstants.php';
6require_once './Modules/TestQuestionPool/interfaces/interface.ilGuiQuestionScoringAdjustable.php';
7
23{
32 public function __construct($id = -1)
33 {
34 parent::__construct();
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';
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
93
94 $this->populateTaxonomyFormSection($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 include_once "./Modules/TestQuestionPool/classes/tables/class.assFileUploadFileTableGUI.php";
237 $table_gui = new assFileUploadFileTableGUI($this->getTargetGuiClass(), 'gotoquestion');
238 $table_gui->setTitle($this->lng->txt('already_delivered_files'), 'icon_file.svg', $this->lng->txt('already_delivered_files'));
239 $table_gui->setData($files);
240 $table_gui->init();
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 if (strlen($this->object->getAllowedExtensions()))
252 {
253 $template->setCurrentBlock("allowed_extensions");
254 $template->setVariable("TXT_ALLOWED_EXTENSIONS", $this->object->prepareTextareaOutput($this->lng->txt("allowedextensions") . ": " . $this->object->getAllowedExtensions()));
255 $template->parseCurrentBlock();
256 }
257 $template->setVariable("CMD_UPLOAD", $this->getQuestionActionCmd());
258 $template->setVariable("TEXT_UPLOAD", $this->object->prepareTextareaOutput($this->lng->txt('upload')));
259 $template->setVariable("TXT_UPLOAD_FILE", $this->object->prepareTextareaOutput($this->lng->txt('file_add')));
260 $template->setVariable("TXT_MAX_SIZE", $this->object->prepareTextareaOutput($this->lng->txt('file_notice') . " " . $this->object->getMaxFilesizeAsString()));
261
262 if (($active_id > 0) && (!$show_correct_solution))
263 {
264 $reached_points = $this->object->getReachedPoints($active_id, $pass);
265 if ($graphicalOutput)
266 {
267 // output of ok/not ok icons for user entered solutions
268 if ($reached_points == $this->object->getMaximumPoints())
269 {
270 $template->setCurrentBlock("icon_ok");
271 $template->setVariable("ICON_OK", ilUtil::getImagePath("icon_ok.svg"));
272 $template->setVariable("TEXT_OK", $this->lng->txt("answer_is_right"));
273 $template->parseCurrentBlock();
274 }
275 else
276 {
277 $template->setCurrentBlock("icon_ok");
278 if ($reached_points > 0)
279 {
280 $template->setVariable("ICON_NOT_OK", ilUtil::getImagePath("icon_mostly_ok.svg"));
281 $template->setVariable("TEXT_NOT_OK", $this->lng->txt("answer_is_not_correct_but_positive"));
282 }
283 else
284 {
285 $template->setVariable("ICON_NOT_OK", ilUtil::getImagePath("icon_not_ok.svg"));
286 $template->setVariable("TEXT_NOT_OK", $this->lng->txt("answer_is_wrong"));
287 }
288 $template->parseCurrentBlock();
289 }
290 }
291 }
292 else
293 {
294 $reached_points = $this->object->getPoints();
295 }
296
297 if ($result_output)
298 {
299 $resulttext = ($reached_points == 1) ? "(%s " . $this->lng->txt("point") . ")" : "(%s " . $this->lng->txt("points") . ")";
300 $template->setVariable("RESULT_OUTPUT", sprintf($resulttext, $reached_points));
301 }
302 if ($show_question_text==true)
303 {
304 $template->setVariable("QUESTIONTEXT", $this->object->prepareTextareaOutput($this->object->getQuestion(), TRUE));
305 }
306 $questionoutput = $template->get();
307 $solutiontemplate = new ilTemplate("tpl.il_as_tst_solution_output.html",TRUE, TRUE, "Modules/TestQuestionPool");
308 $feedback = ($show_feedback && !$this->isTestPresentationContext()) ? $this->getAnswerFeedbackOutput($active_id, $pass) : "";
309 if (strlen($feedback))
310 {
311 $cssClass = ( $this->hasCorrectSolution($active_id, $pass) ?
313 );
314
315 $solutiontemplate->setVariable("ILC_FB_CSS_CLASS", $cssClass);
316 $solutiontemplate->setVariable("FEEDBACK", $this->object->prepareTextareaOutput( $feedback, true ));
317 }
318 $solutiontemplate->setVariable("SOLUTION_OUTPUT", $questionoutput);
319 $solutionoutput = $solutiontemplate->get();
320 if (!$show_question_only)
321 {
322 // get page object output
323 $solutionoutput = $this->getILIASPage($solutionoutput);
324 }
325 return $solutionoutput;
326 }
327
328 function getPreview($show_question_only = FALSE, $showInlineFeedback = false)
329 {
330 $template = new ilTemplate("tpl.il_as_qpl_fileupload_output.html",TRUE, TRUE, "Modules/TestQuestionPool");
331
332 if( is_object($this->getPreviewSession()) )
333 {
334 $files = $this->object->getPreviewFileUploads($this->getPreviewSession());
335 include_once "./Modules/TestQuestionPool/classes/tables/class.assFileUploadFileTableGUI.php";
336 $table_gui = new assFileUploadFileTableGUI(null , $this->getQuestionActionCmd(), 'ilAssQuestionPreview');
337 $table_gui->setTitle($this->lng->txt('already_delivered_files'), 'icon_file.svg', $this->lng->txt('already_delivered_files'));
338 $table_gui->setData($files);
339 $table_gui->init();
340 $template->setCurrentBlock("files");
341 $template->setVariable('FILES', $table_gui->getHTML());
342 $template->parseCurrentBlock();
343 }
344
345 if (strlen($this->object->getAllowedExtensions()))
346 {
347 $template->setCurrentBlock("allowed_extensions");
348 $template->setVariable("TXT_ALLOWED_EXTENSIONS", $this->object->prepareTextareaOutput($this->lng->txt("allowedextensions") . ": " . $this->object->getAllowedExtensions()));
349 $template->parseCurrentBlock();
350 }
351 $template->setVariable("QUESTIONTEXT", $this->object->prepareTextareaOutput($this->object->question, TRUE));
352 $template->setVariable("CMD_UPLOAD", $this->getQuestionActionCmd());
353 $template->setVariable("TEXT_UPLOAD", $this->object->prepareTextareaOutput($this->lng->txt('upload')));
354 $template->setVariable("TXT_UPLOAD_FILE", $this->object->prepareTextareaOutput($this->lng->txt('file_add')));
355 $template->setVariable("TXT_MAX_SIZE", $this->object->prepareTextareaOutput($this->lng->txt('file_notice') . " " . $this->object->getMaxFilesizeAsString()));
356
357 $questionoutput = $template->get();
358 if (!$show_question_only)
359 {
360 // get page object output
361 $questionoutput = $this->getILIASPage($questionoutput);
362 }
363 return $questionoutput;
364 }
365
366 // hey: prevPassSolutions - pass will be always available from now on
367 function getTestOutput($active_id, $pass, $is_postponed = FALSE, $use_post_solutions = FALSE, $show_feedback = FALSE)
368 // hey.
369 {
370 // generate the question output
371 $template = new ilTemplate("tpl.il_as_qpl_fileupload_output.html",TRUE, TRUE, "Modules/TestQuestionPool");
372
373 if ($active_id)
374 {
375 // hey: prevPassSolutions - obsolete due to central check
376 #$solutions = NULL;
377 #include_once "./Modules/Test/classes/class.ilObjTest.php";
378 #if (!ilObjTest::_getUsePreviousAnswers($active_id, true))
379 #{
380 # if (is_null($pass)) $pass = ilObjTest::_getPass($active_id);
381 #}
382 $files = $this->getTestOutputSolutions($active_id, $pass);
383 // hey.
384 include_once "./Modules/TestQuestionPool/classes/tables/class.assFileUploadFileTableGUI.php";
385 $table_gui = new assFileUploadFileTableGUI(null , $this->getQuestionActionCmd());
386 $table_gui->setTitle($this->lng->txt('already_delivered_files'), 'icon_file.svg', $this->lng->txt('already_delivered_files'));
387 $table_gui->setData($files);
388 $table_gui->init();
389 $template->setCurrentBlock("files");
390 $template->setVariable('FILES', $table_gui->getHTML());
391 $template->parseCurrentBlock();
392 }
393
394 if (strlen($this->object->getAllowedExtensions()))
395 {
396 $template->setCurrentBlock("allowed_extensions");
397 $template->setVariable("TXT_ALLOWED_EXTENSIONS", $this->object->prepareTextareaOutput($this->lng->txt("allowedextensions") . ": " . $this->object->getAllowedExtensions()));
398 $template->parseCurrentBlock();
399 }
400 $template->setVariable("QUESTIONTEXT", $this->object->prepareTextareaOutput($this->object->question, TRUE));
401 $template->setVariable("CMD_UPLOAD", $this->getQuestionActionCmd());
402 $template->setVariable("TEXT_UPLOAD", $this->object->prepareTextareaOutput($this->lng->txt('upload')));
403 $template->setVariable("TXT_UPLOAD_FILE", $this->object->prepareTextareaOutput($this->lng->txt('file_add')));
404 $template->setVariable("TXT_MAX_SIZE", $this->object->prepareTextareaOutput($this->lng->txt('file_notice') . " " . $this->object->getMaxFilesizeAsString()));
405
406 $questionoutput = $template->get();
407 if (!$show_question_only)
408 {
409 // get page object output
410 $questionoutput = $this->getILIASPage($questionoutput);
411 }
412 $questionoutput = $template->get();
413 $pageoutput = $this->outQuestionPage("", $is_postponed, $active_id, $questionoutput);
414 return $pageoutput;
415 }
416
425 {
426 global $rbacsystem, $ilTabs;
427
428 $ilTabs->clearTargets();
429
430 $this->ctrl->setParameterByClass("ilAssQuestionPageGUI", "q_id", $_GET["q_id"]);
431 include_once "./Modules/TestQuestionPool/classes/class.assQuestion.php";
432 $q_type = $this->object->getQuestionType();
433
434 if (strlen($q_type))
435 {
436 $classname = $q_type . "GUI";
437 $this->ctrl->setParameterByClass(strtolower($classname), "sel_question_types", $q_type);
438 $this->ctrl->setParameterByClass(strtolower($classname), "q_id", $_GET["q_id"]);
439 }
440
441 if ($_GET["q_id"])
442 {
443 if ($rbacsystem->checkAccess('write', $_GET["ref_id"]))
444 {
445 // edit page
446 $ilTabs->addTarget("edit_page",
447 $this->ctrl->getLinkTargetByClass("ilAssQuestionPageGUI", "edit"),
448 array("edit", "insert", "exec_pg"),
449 "", "", $force_active);
450 }
451
452 $this->addTab_QuestionPreview($ilTabs);
453 }
454
455 $force_active = false;
456 if ($rbacsystem->checkAccess('write', $_GET["ref_id"]))
457 {
458 $url = "";
459 if ($classname) $url = $this->ctrl->getLinkTargetByClass($classname, "editQuestion");
460 // edit question properties
461 $ilTabs->addTarget("edit_question",
462 $url,
463 array("editQuestion", "save", "cancel", "saveEdit"),
464 $classname, "");
465 }
466
467 // add tab for question feedback within common class assQuestionGUI
468 $this->addTab_QuestionFeedback($ilTabs);
469
470 // add tab for question hint within common class assQuestionGUI
471 $this->addTab_QuestionHints($ilTabs);
472
473 // add tab for question's suggested solution within common class assQuestionGUI
474 $this->addTab_SuggestedSolution($ilTabs, $classname);
475
476 // Assessment of questions sub menu entry
477 if ($_GET["q_id"])
478 {
479 $ilTabs->addTarget("statistics",
480 $this->ctrl->getLinkTargetByClass($classname, "assessment"),
481 array("assessment"),
482 $classname, "");
483 }
484
485 if (($_GET["calling_test"] > 0) || ($_GET["test_ref_id"] > 0))
486 {
487 $ref_id = $_GET["calling_test"];
488 if (strlen($ref_id) == 0) $ref_id = $_GET["test_ref_id"];
489
490 global $___test_express_mode;
491
492 if (!$_GET['test_express_mode'] && !$___test_express_mode) {
493 $ilTabs->setBackTarget($this->lng->txt("backtocallingtest"), "ilias.php?baseClass=ilObjTestGUI&cmd=questions&ref_id=$ref_id");
494 }
495 else {
497 $ilTabs->setBackTarget($this->lng->txt("backtocallingtest"), $link);
498 }
499 }
500 else
501 {
502 $ilTabs->setBackTarget($this->lng->txt("qpl"), $this->ctrl->getLinkTargetByClass("ilobjquestionpoolgui", "questions"));
503 }
504 }
505
506 function getSpecificFeedbackOutput($active_id, $pass)
507 {
508 $output = "";
509 return $this->object->prepareTextareaOutput($output, TRUE);
510 }
511
522 {
523 return array();
524 }
525
534 public function getAggregatedAnswersView($relevant_answers)
535 {
536 // Empty implementation here since a feasible way to aggregate answer is not known.
537 return ''; //print_r($relevant_answers,true);
538 }
539
540 public function getFormEncodingType()
541 {
543 }
544}
$_GET["client_id"]
The assFileUploadGUI class encapsulates the GUI representation for file upload questions.
getSolutionOutput( $active_id, $pass=NULL, $graphicalOutput=FALSE, $result_output=FALSE, $show_question_only=TRUE, $show_feedback=FALSE, $show_correct_solution=FALSE, $show_manual_scoring=FALSE, $show_question_text=TRUE)
Get the question solution output.
setQuestionTabs()
Sets the ILIAS tabs for this question type.
getTestOutput($active_id, $pass, $is_postponed=FALSE, $use_post_solutions=FALSE, $show_feedback=FALSE)
writePostData($always=false)
Evaluates a posted edit form and writes the form data in the question object.
getSpecificFeedbackOutput($active_id, $pass)
Returns the answer specific feedback for the question.
getAfterParticipationSuppressionQuestionPostVars()
Returns a list of postvars which will be suppressed in the form output when used in scoring adjustmen...
getAggregatedAnswersView($relevant_answers)
Returns an html string containing a question specific representation of the answers so far given in t...
getPreview($show_question_only=FALSE, $showInlineFeedback=false)
writeQuestionSpecificPostData(ilPropertyFormGUI $form)
Extracts the question specific values from $_POST and applies them to the data object.
__construct($id=-1)
assFileUploadGUI constructor
editQuestion($checkonly=FALSE)
Creates an output of the edit form for the question.
populateQuestionSpecificFormPart(ilPropertyFormGUI $form)
Adds the question specific forms parts to a question property form gui.
Class for file upload questions.
Basic GUI class for assessment questions.
populateTaxonomyFormSection(ilPropertyFormGUI $form)
setErrorMessage($errormessage)
addTab_QuestionHints(ilTabsGUI $tabs)
adds the hints tab to ilTabsGUI
addQuestionFormCommandButtons($form)
Add the command buttons of a question properties form.
getILIASPage($html="")
Returns the ILIAS Page around a question.
getQuestionTemplate()
get question template
addTab_SuggestedSolution(ilTabsGUI $tabs, $classname)
getTestOutputSolutions($activeId, $pass)
outQuestionPage($a_temp_var, $a_postponed=false, $active_id="", $html="")
output question page
hasCorrectSolution($activeId, $passIndex)
addTab_QuestionFeedback(ilTabsGUI $tabs)
adds the feedback tab to ilTabsGUI
addBasicQuestionFormProperties($form)
Add basic question form properties: assessment: title, author, description, question,...
addTab_QuestionPreview(ilTabsGUI $tabsGUI)
getAnswerFeedbackOutput($active_id, $pass)
Returns the answer generic feedback depending on the results of the question.
This class represents a checkbox property in a property form.
This class represents a number property in a property form.
_getUsePreviousAnswers($active_id, $user_active_user_setting=false)
Returns if the previous results should be hidden for a learner.
_getPass($active_id)
Retrieves the actual pass of a given user for a given test.
This class represents a property form user interface.
addItem($a_item)
Add Item (Property, SectionHeader).
special template class to simplify handling of ITX/PEAR
static getReturnToPageLink($q_id=null)
This class represents a text property in a property form.
static getImagePath($img, $module_path="", $mode="output", $offline=false)
get image path (for images located in a template directory)
$_POST['username']
Definition: cron.php:12
Interface ilGuiQuestionScoringAdjustable.
$ref_id
Definition: sahs_server.php:39
echo;exit;}function LogoutNotification($SessionID) { global $ilDB; $q="SELECT session_id, data FROM usr_session WHERE expires > (\w+)\|/" PREG_SPLIT_NO_EMPTY PREG_SPLIT_DELIM_CAPTURE
$url
Definition: shib_logout.php:72
$errors