ILIAS  release_5-4 Revision v5.4.26-12-gabc799a52e6
class.ilExSubmissionFileGUI.php
Go to the documentation of this file.
1<?php
2/* Copyright (c) 1998-2010 ILIAS open source, Extended GPL, see docs/LICENSE */
3
13{
17 protected $toolbar;
18
22 protected $help;
23
27 protected $user;
28
32 protected $ui;
33
37 public function __construct(ilObjExercise $a_exercise, ilExSubmission $a_submission)
38 {
39 global $DIC;
40
41 parent::__construct($a_exercise, $a_submission);
42
43 $this->toolbar = $DIC->toolbar();
44 $this->help = $DIC["ilHelp"];
45 $this->user = $DIC->user();
46
47 $this->ui = $DIC->ui();
48 }
49
50 public function executeCommand()
51 {
53
54 if (!$this->submission->canView()) {
55 $this->returnToParentObject();
56 }
57
58 $class = $ilCtrl->getNextClass($this);
59 $cmd = $ilCtrl->getCmd("submissionScreen");
60
61 switch ($class) {
62 default:
63 $this->{$cmd . "Object"}();
64 break;
65 }
66 }
67
68 public static function getOverviewContent(ilInfoScreenGUI $a_info, ilExSubmission $a_submission)
69 {
70 global $DIC;
71
72 $lng = $DIC->language();
73 $ilCtrl = $DIC->ctrl();
74
75 $titles = array();
76 foreach ($a_submission->getFiles() as $file) {
77 $titles[] = $file["filetitle"];
78 }
79 $files_str = implode($titles, "<br>");
80 if ($files_str == "") {
81 $files_str = $lng->txt("message_no_delivered_files");
82 }
83
84 // no team == no submission
85 if (!$a_submission->hasNoTeamYet()) {
86 if ($a_submission->canSubmit()) {
87 $title = (count($titles) == 0
88 ? $lng->txt("exc_hand_in")
89 : $lng->txt("exc_edit_submission"));
90
91 $button = ilLinkButton::getInstance();
92 $button->setPrimary(true);
93 $button->setCaption($title, false);
94 $button->setUrl($ilCtrl->getLinkTargetByClass(array("ilExSubmissionGUI", "ilExSubmissionFileGUI"), "submissionScreen"));
95 $files_str .= "<br><br>" . $button->render();
96 } else {
97 if (count($titles) > 0) {
98 $button = ilLinkButton::getInstance();
99 $button->setCaption("already_delivered_files");
100 $button->setUrl($ilCtrl->getLinkTargetByClass(array("ilExSubmissionGUI", "ilExSubmissionFileGUI"), "submissionScreen"));
101 $files_str .= "<br><br>" . $button->render();
102 }
103 }
104 }
105
106 $a_info->addProperty($lng->txt("exc_files_returned"), $files_str);
107 }
108
114 public function submissionScreenObject()
115 {
116 $ilToolbar = $this->toolbar;
117 $ilHelp = $this->help;
119
120
121 $this->handleTabs();
122
123 $ilHelp->setScreenIdComponent("exc");
124 $ilHelp->setScreenId("submissions");
125
126 if (!$this->submission->canSubmit()) {
127 ilUtil::sendInfo($this->lng->txt("exercise_time_over"));
128 } else {
129 $max_files = $this->submission->getAssignment()->getMaxFile();
130
131 if ($this->submission->canAddFile()) {
132 // #15883 - extended deadline warning
133 $deadline = $this->assignment->getPersonalDeadline($ilUser->getId());
134 if ($deadline &&
135 time() > $deadline) {
137 $dl = sprintf($this->lng->txt("exc_late_submission_warning"), $dl);
138 $dl = '<span class="warning">' . $dl . '</span>';
139 $ilToolbar->addText($dl);
140 }
141
142 $b = $this->ui->factory()->button()->standard(
143 $this->lng->txt("file_add"),
144 $this->ctrl->getLinkTarget($this, "uploadForm")
145 );
146 $ilToolbar->addStickyItem($b);
147
148 if (!$max_files ||
149 $max_files > 1) {
150 $ilToolbar->addButton(
151 $this->lng->txt("header_zip"),
152 $this->ctrl->getLinkTarget($this, "uploadZipForm")
153 );
154 }
155 }
156
157 if ($max_files) {
158 ilUtil::sendInfo(sprintf($this->lng->txt("exc_max_file_reached"), $max_files));
159 }
160 }
161
162 include_once("./Modules/Exercise/classes/class.ilExcDeliveredFilesTableGUI.php");
163 $tab = new ilExcDeliveredFilesTableGUI($this, "submissionScreen", $this->submission);
164 $this->tpl->setContent($tab->getHTML());
165 }
166
170 public function uploadFormObject(ilPropertyFormGUI $a_form = null)
171 {
172 if (!$this->submission->canSubmit()) {
173 $this->ctrl->redirect($this, "submissionScreen");
174 }
175
176 $this->tabs_gui->clearTargets();
177 $this->tabs_gui->setBackTarget(
178 $this->lng->txt("back"),
179 $this->ctrl->getLinkTarget($this, "submissionScreen")
180 );
181
182 $ilHelp = $this->help;
183 $ilHelp->setScreenIdComponent("exc");
184 $ilHelp->setScreenId("upload_submission");
185
186 if (!$a_form) {
187 $a_form = $this->initUploadForm();
188 }
189 $this->tpl->setContent($a_form->getHTML());
190 }
191
195 public function uploadZipFormObject(ilPropertyFormGUI $a_form = null)
196 {
197 if (!$this->submission->canSubmit()) {
198 $this->ctrl->redirect($this, "submissionScreen");
199 }
200
201 $this->tabs_gui->clearTargets();
202 $this->tabs_gui->setBackTarget(
203 $this->lng->txt("back"),
204 $this->ctrl->getLinkTarget($this, "submissionScreen")
205 );
206
207 if (!$a_form) {
208 $a_form = $this->initZipUploadForm();
209 }
210 $this->tpl->setContent($a_form->getHTML());
211 }
212
216 protected function initUploadForm()
217 {
220
221 include_once("Services/Form/classes/class.ilPropertyFormGUI.php");
222 $form = new ilPropertyFormGUI();
223
224 // file input
225 include_once("./Services/Form/classes/class.ilFileWizardInputGUI.php");
226 $fi = new ilFileWizardInputGUI($lng->txt("file"), "deliver");
227 $fi->setFilenames(array(0 => ''));
228 $fi->setRequired(true);
229 $form->addItem($fi);
230
231 $form->addCommandButton("uploadFile", $lng->txt("upload"));
232 $form->addCommandButton("submissionScreen", $lng->txt("cancel"));
233
234 $form->setTitle($lng->txt("file_add"));
235 $form->setFormAction($ilCtrl->getFormAction($this, "uploadFile"));
236
237 return $form;
238 }
239
243 protected function initZipUploadForm()
244 {
247
248 include_once("Services/Form/classes/class.ilPropertyFormGUI.php");
249 $form = new ilPropertyFormGUI();
250
251 include_once("./Services/Form/classes/class.ilFileInputGUI.php");
252 $fi = new ilFileInputGUI($lng->txt("file"), "deliver");
253 $fi->setSuffixes(array("zip"));
254 $fi->setRequired(true);
255 $form->addItem($fi);
256
257 $form->addCommandButton("uploadZip", $lng->txt("upload"));
258 $form->addCommandButton("submissionScreen", $lng->txt("cancel"));
259
260 $form->setTitle($lng->txt("header_zip"));
261 $form->setFormAction($ilCtrl->getFormAction($this, "uploadZip"));
262
263 return $form;
264 }
265
269 public function uploadFileObject()
270 {
272
273 // #15322
274 if (!$this->submission->canSubmit()) {
275 ilUtil::sendInfo($this->lng->txt("exercise_time_over"), true);
276 } else {
277 $form = $this->initUploadForm();
278 if (!$form->checkInput()) {
279 return $this->uploadFormObject($form);
280 }
281
282 $success = false;
283 foreach ($_FILES["deliver"]["name"] as $k => $v) {
284 $file = array(
285 "name" => $_FILES["deliver"]["name"][$k],
286 "type" => $_FILES["deliver"]["type"][$k],
287 "tmp_name" => $_FILES["deliver"]["tmp_name"][$k],
288 "error" => $_FILES["deliver"]["error"][$k],
289 "size" => $_FILES["deliver"]["size"][$k],
290 );
291 if (!$this->submission->uploadFile($file)) {
292 ilUtil::sendFailure($this->lng->txt("exc_upload_error") . " [Single File]", true);
293 } else {
294 $success = true;
295 }
296 }
297
298 if ($success) {
299 ilUtil::sendSuccess($this->lng->txt("file_added"), true);
300 $this->handleNewUpload();
301 }
302 }
303
304 $ilCtrl->redirect($this, "submissionScreen");
305 }
306
310 public function uploadZipObject()
311 {
313
314 // #15322
315 if (!$this->submission->canSubmit()) {
316 ilUtil::sendInfo($this->lng->txt("exercise_time_over"), true);
317 } else {
318 $form = $this->initZipUploadForm();
319 if (!$form->checkInput()) {
320 return $this->uploadZipFormObject($form);
321 }
322
323 if (preg_match("/zip/", $_FILES["deliver"]["type"]) == 1) {
324 if ($this->submission->processUploadedZipFile($_FILES["deliver"]["tmp_name"])) {
325 ilUtil::sendSuccess($this->lng->txt("file_added"), true);
326 $this->handleNewUpload();
327 }
328 }
329 }
330
331 $ilCtrl->redirect($this, "submissionScreen");
332 }
333
338 {
342
343 if (!$this->submission->canSubmit()) {
344 ilUtil::sendFailure($this->lng->txt("exercise_time_over"), true);
345 $ilCtrl->redirect($this, "submissionScreen");
346 }
347
348 if (!is_array($_POST["delivered"]) || count($_POST["delivered"]) == 0) {
349 ilUtil::sendFailure($lng->txt("no_checkbox"), true);
350 $ilCtrl->redirect($this, "submissionScreen");
351 } else {
352 $this->tabs_gui->clearTargets();
353 $this->tabs_gui->setBackTarget(
354 $this->lng->txt("back"),
355 $this->ctrl->getLinkTarget($this, "submissionScreen")
356 );
357
358 include_once("./Services/Utilities/classes/class.ilConfirmationGUI.php");
359 $cgui = new ilConfirmationGUI();
360 $cgui->setFormAction($ilCtrl->getFormAction($this));
361 $cgui->setHeaderText($lng->txt("info_delete_sure"));
362 $cgui->setCancel($lng->txt("cancel"), "submissionScreen");
363 $cgui->setConfirm($lng->txt("delete"), "deleteDelivered");
364
365 $files = $this->submission->getFiles();
366
367 foreach ($_POST["delivered"] as $i) {
368 reset($files);
369 $title = "";
370 foreach ($files as $f) {
371 if ($f["returned_id"] == $i) {
372 $title = $f["filetitle"];
373 }
374 }
375 $cgui->addItem("delivered[]", $i, $title);
376 }
377
378 $tpl->setContent($cgui->getHTML());
379 }
380 }
381
388 public function deleteDeliveredObject()
389 {
391
392 if (!$this->submission->canSubmit()) {
393 ilUtil::sendFailure($this->lng->txt("exercise_time_over"), true);
394 } elseif (!count($_POST["delivered"])) {
395 ilUtil::sendFailure($this->lng->txt("please_select_a_delivered_file_to_delete"), true);
396 } else {
397 $this->submission->deleteSelectedFiles($_POST["delivered"]);
398 $this->handleRemovedUpload();
399
400 ilUtil::sendSuccess($this->lng->txt("exc_submitted_files_deleted"), true);
401 }
402 $ilCtrl->redirect($this, "submissionScreen");
403 }
404
408 public function downloadReturnedObject($a_only_new = false)
409 {
411
412 $peer_review_mask_filename = false;
413
414 if ($this->submission->canView()) {
415 $peer_review_mask_filename = $this->submission->hasPeerReviewAccess();
416 } else {
417 // no access
418 return;
419 }
420
421 $this->submission->downloadFiles(null, $a_only_new, $peer_review_mask_filename);
422 // we only get here, if no files have been found for download
423 if ($a_only_new) {
424 ilUtil::sendInfo($lng->txt("exc_all_new_files_offered_already"), true);
425 }
426 $this->returnToParentObject();
427 }
428
433 {
434 $this->downloadReturnedObject(true);
435 }
436
443 public function downloadObject()
444 {
446
447 $delivered_id = $_REQUEST["delivered"];
448
449 if (!$this->submission->canView()) {
450 $this->returnToParentObject();
451 }
452
453 if (!is_array($delivered_id) && $delivered_id > 0) {
454 $delivered_id = [$delivered_id];
455 }
456 if (is_array($delivered_id) && count($delivered_id) > 0) {
457 $this->submission->downloadFiles($delivered_id);
458 exit;
459 } else {
460 ilUtil::sendFailure($this->lng->txt("please_select_a_delivered_file_to_download"), true);
461 $ilCtrl->redirect($this, "submissionScreen");
462 }
463 }
464}
user()
Definition: user.php:4
$success
Definition: Utf8Test.php:86
exit
Definition: backend.php:16
$_POST["username"]
An exception for terminatinating execution or to throw for unit testing.
const IL_CAL_UNIX
Confirmation screen class.
static formatDate(ilDateTime $date, $a_skip_day=false, $a_include_wd=false, $include_seconds=false)
Format a date @access public.
@classDescription Date and time handling
Exercise submission base gui.
handleNewUpload($a_no_notifications=false)
uploadZipFormObject(ilPropertyFormGUI $a_form=null)
Display form for zip file upload.
confirmDeleteDeliveredObject()
Confirm deletion of delivered files.
static getOverviewContent(ilInfoScreenGUI $a_info, ilExSubmission $a_submission)
initZipUploadForm()
Init upload form form.
__construct(ilObjExercise $a_exercise, ilExSubmission $a_submission)
Constructor.
deleteDeliveredObject()
Delete file(s) submitted by user.
downloadNewReturnedObject()
Download newly submitted files of user.
downloadObject()
User downloads (own) submitted files.
initUploadForm()
Init upload form form.
submissionScreenObject()
Displays a form which allows members to deliver their solutions.
downloadReturnedObject($a_only_new=false)
Download submitted files of user.
uploadFormObject(ilPropertyFormGUI $a_form=null)
Display form for single file upload.
Exercise submission //TODO: This class has to much static methods related to delivered "files".
getFiles(array $a_file_ids=null, $a_only_valid=false, $a_min_timestamp=null)
Get submission items (not only files)
This class represents a file property in a property form.
This class represents a file wizard property in a property form.
Class ilInfoScreenGUI.
addProperty($a_name, $a_value, $a_link="")
add a property to current section
static getInstance()
Factory.
Class ilObjExercise.
This class represents a property form user interface.
static sendFailure($a_info="", $a_keep=false)
Send Failure Message to Screen.
static sendInfo($a_info="", $a_keep=false)
Send Info Message to Screen.
$i
Definition: disco.tpl.php:19
global $ilCtrl
Definition: ilias.php:18
$files
Definition: metarefresh.php:49
if(isset($_POST['submit'])) $form
global $DIC
Definition: saml.php:7
$ilUser
Definition: imgupload.php:18