ILIAS  release_5-3 Revision v5.3.23-19-g915713cf615
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 
29 
33  public function __construct(ilObjExercise $a_exercise, ilExSubmission $a_submission)
34  {
35  global $DIC;
36 
37  parent::__construct($a_exercise, $a_submission);
38 
39  $this->toolbar = $DIC->toolbar();
40  $this->help = $DIC["ilHelp"];
41  $this->user = $DIC->user();
42  }
43 
44  public function executeCommand()
45  {
47 
48  if (!$this->submission->canView()) {
49  $this->returnToParentObject();
50  }
51 
52  $class = $ilCtrl->getNextClass($this);
53  $cmd = $ilCtrl->getCmd("submissionScreen");
54 
55  switch ($class) {
56  default:
57  $this->{$cmd . "Object"}();
58  break;
59  }
60  }
61 
62  public static function getOverviewContent(ilInfoScreenGUI $a_info, ilExSubmission $a_submission)
63  {
64  global $DIC;
65 
66  $lng = $DIC->language();
67  $ilCtrl = $DIC->ctrl();
68 
69  $titles = array();
70  foreach ($a_submission->getFiles() as $file) {
71  $titles[] = $file["filetitle"];
72  }
73  $files_str = implode($titles, "<br>");
74  if ($files_str == "") {
75  $files_str = $lng->txt("message_no_delivered_files");
76  }
77 
78  // no team == no submission
79  if (!$a_submission->hasNoTeamYet()) {
80  if ($a_submission->canSubmit()) {
81  $title = (count($titles) == 0
82  ? $lng->txt("exc_hand_in")
83  : $lng->txt("exc_edit_submission"));
84 
85  $button = ilLinkButton::getInstance();
86  $button->setPrimary(true);
87  $button->setCaption($title, false);
88  $button->setUrl($ilCtrl->getLinkTargetByClass(array("ilExSubmissionGUI", "ilExSubmissionFileGUI"), "submissionScreen"));
89  $files_str.= "<br><br>" . $button->render();
90  } else {
91  if (count($titles) > 0) {
92  $button = ilLinkButton::getInstance();
93  $button->setCaption("already_delivered_files");
94  $button->setUrl($ilCtrl->getLinkTargetByClass(array("ilExSubmissionGUI", "ilExSubmissionFileGUI"), "submissionScreen"));
95  $files_str.= "<br>" . $button->render();
96  }
97  }
98  }
99 
100  $a_info->addProperty($lng->txt("exc_files_returned"), $files_str);
101  }
102 
108  public function submissionScreenObject()
109  {
110  $ilToolbar = $this->toolbar;
111  $ilHelp = $this->help;
113 
114 
115  $this->handleTabs();
116 
117  $ilHelp->setScreenIdComponent("exc");
118  $ilHelp->setScreenId("submissions");
119 
120  if (!$this->submission->canSubmit()) {
121  ilUtil::sendInfo($this->lng->txt("exercise_time_over"));
122  } else {
123  $max_files = $this->submission->getAssignment()->getMaxFile();
124 
125  if ($this->submission->canAddFile()) {
126  // #15883 - extended deadline warning
127  $deadline = $this->assignment->getPersonalDeadline($ilUser->getId());
128  if ($deadline &&
129  time() > $deadline) {
131  $dl = sprintf($this->lng->txt("exc_late_submission_warning"), $dl);
132  $dl = '<span class="warning">' . $dl . '</span>';
133  $ilToolbar->addText($dl);
134  }
135 
136  $ilToolbar->addButton(
137  $this->lng->txt("file_add"),
138  $this->ctrl->getLinkTarget($this, "uploadForm")
139  );
140 
141  if (!$max_files ||
142  $max_files > 1) {
143  $ilToolbar->addButton(
144  $this->lng->txt("header_zip"),
145  $this->ctrl->getLinkTarget($this, "uploadZipForm")
146  );
147  }
148  }
149 
150  if ($max_files) {
151  ilUtil::sendInfo(sprintf($this->lng->txt("exc_max_file_reached"), $max_files));
152  }
153  }
154 
155  include_once("./Modules/Exercise/classes/class.ilExcDeliveredFilesTableGUI.php");
156  $tab = new ilExcDeliveredFilesTableGUI($this, "submissionScreen", $this->submission);
157  $this->tpl->setContent($tab->getHTML());
158  }
159 
163  public function uploadFormObject(ilPropertyFormGUI $a_form = null)
164  {
165  if (!$this->submission->canSubmit()) {
166  $this->ctrl->redirect($this, "submissionScreen");
167  }
168 
169  $this->tabs_gui->clearTargets();
170  $this->tabs_gui->setBackTarget(
171  $this->lng->txt("back"),
172  $this->ctrl->getLinkTarget($this, "submissionScreen")
173  );
174 
175  $ilHelp = $this->help;
176  $ilHelp->setScreenIdComponent("exc");
177  $ilHelp->setScreenId("upload_submission");
178 
179  if (!$a_form) {
180  $a_form = $this->initUploadForm();
181  }
182  $this->tpl->setContent($a_form->getHTML());
183  }
184 
188  public function uploadZipFormObject(ilPropertyFormGUI $a_form = null)
189  {
190  if (!$this->submission->canSubmit()) {
191  $this->ctrl->redirect($this, "submissionScreen");
192  }
193 
194  $this->tabs_gui->clearTargets();
195  $this->tabs_gui->setBackTarget(
196  $this->lng->txt("back"),
197  $this->ctrl->getLinkTarget($this, "submissionScreen")
198  );
199 
200  if (!$a_form) {
201  $a_form = $this->initZipUploadForm();
202  }
203  $this->tpl->setContent($a_form->getHTML());
204  }
205 
209  protected function initUploadForm()
210  {
211  $lng = $this->lng;
213 
214  include_once("Services/Form/classes/class.ilPropertyFormGUI.php");
215  $form = new ilPropertyFormGUI();
216 
217  // file input
218  include_once("./Services/Form/classes/class.ilFileWizardInputGUI.php");
219  $fi = new ilFileWizardInputGUI($lng->txt("file"), "deliver");
220  $fi->setFilenames(array(0 => ''));
221  $fi->setRequired(true);
222  $form->addItem($fi);
223 
224  $form->addCommandButton("uploadFile", $lng->txt("upload"));
225  $form->addCommandButton("submissionScreen", $lng->txt("cancel"));
226 
227  $form->setTitle($lng->txt("file_add"));
228  $form->setFormAction($ilCtrl->getFormAction($this, "uploadFile"));
229 
230  return $form;
231  }
232 
236  protected function initZipUploadForm()
237  {
238  $lng = $this->lng;
240 
241  include_once("Services/Form/classes/class.ilPropertyFormGUI.php");
242  $form = new ilPropertyFormGUI();
243 
244  include_once("./Services/Form/classes/class.ilFileInputGUI.php");
245  $fi = new ilFileInputGUI($lng->txt("file"), "deliver");
246  $fi->setSuffixes(array("zip"));
247  $fi->setRequired(true);
248  $form->addItem($fi);
249 
250  $form->addCommandButton("uploadZip", $lng->txt("upload"));
251  $form->addCommandButton("submissionScreen", $lng->txt("cancel"));
252 
253  $form->setTitle($lng->txt("header_zip"));
254  $form->setFormAction($ilCtrl->getFormAction($this, "uploadZip"));
255 
256  return $form;
257  }
258 
262  public function uploadFileObject()
263  {
265 
266  // #15322
267  if (!$this->submission->canSubmit()) {
268  ilUtil::sendInfo($this->lng->txt("exercise_time_over"), true);
269  } else {
270  $form = $this->initUploadForm();
271  if (!$form->checkInput()) {
272  return $this->uploadFormObject($form);
273  }
274 
275  $success = false;
276  foreach ($_FILES["deliver"]["name"] as $k => $v) {
277  $file = array(
278  "name" => $_FILES["deliver"]["name"][$k],
279  "type" => $_FILES["deliver"]["type"][$k],
280  "tmp_name" => $_FILES["deliver"]["tmp_name"][$k],
281  "error" => $_FILES["deliver"]["error"][$k],
282  "size" => $_FILES["deliver"]["size"][$k],
283  );
284  if (!$this->submission->uploadFile($file)) {
285  ilUtil::sendFailure($this->lng->txt("exc_upload_error") . " [Single File]", true);
286  } else {
287  $success = true;
288  }
289  }
290 
291  if ($success) {
292  ilUtil::sendSuccess($this->lng->txt("file_added"), true);
293  $this->handleNewUpload();
294  }
295  }
296 
297  $ilCtrl->redirect($this, "submissionScreen");
298  }
299 
303  public function uploadZipObject()
304  {
306 
307  // #15322
308  if (!$this->submission->canSubmit()) {
309  ilUtil::sendInfo($this->lng->txt("exercise_time_over"), true);
310  } else {
311  $form = $this->initZipUploadForm();
312  if (!$form->checkInput()) {
313  return $this->uploadZipFormObject($form);
314  }
315 
316  if (preg_match("/zip/", $_FILES["deliver"]["type"]) == 1) {
317  if ($this->submission->processUploadedZipFile($_FILES["deliver"]["tmp_name"])) {
318  ilUtil::sendSuccess($this->lng->txt("file_added"), true);
319  $this->handleNewUpload();
320  }
321  }
322  }
323 
324  $ilCtrl->redirect($this, "submissionScreen");
325  }
326 
331  {
333  $tpl = $this->tpl;
334  $lng = $this->lng;
335 
336  if (!$this->submission->canSubmit()) {
337  ilUtil::sendFailure($this->lng->txt("exercise_time_over"), true);
338  $ilCtrl->redirect($this, "submissionScreen");
339  }
340 
341  if (!is_array($_POST["delivered"]) || count($_POST["delivered"]) == 0) {
342  ilUtil::sendFailure($lng->txt("no_checkbox"), true);
343  $ilCtrl->redirect($this, "submissionScreen");
344  } else {
345  $this->tabs_gui->clearTargets();
346  $this->tabs_gui->setBackTarget(
347  $this->lng->txt("back"),
348  $this->ctrl->getLinkTarget($this, "submissionScreen")
349  );
350 
351  include_once("./Services/Utilities/classes/class.ilConfirmationGUI.php");
352  $cgui = new ilConfirmationGUI();
353  $cgui->setFormAction($ilCtrl->getFormAction($this));
354  $cgui->setHeaderText($lng->txt("info_delete_sure"));
355  $cgui->setCancel($lng->txt("cancel"), "submissionScreen");
356  $cgui->setConfirm($lng->txt("delete"), "deleteDelivered");
357 
358  $files = $this->submission->getFiles();
359 
360  foreach ($_POST["delivered"] as $i) {
361  reset($files);
362  $title = "";
363  foreach ($files as $f) {
364  if ($f["returned_id"] == $i) {
365  $title = $f["filetitle"];
366  }
367  }
368  $cgui->addItem("delivered[]", $i, $title);
369  }
370 
371  $tpl->setContent($cgui->getHTML());
372  }
373  }
374 
381  public function deleteDeliveredObject()
382  {
384 
385  if (!$this->submission->canSubmit()) {
386  ilUtil::sendFailure($this->lng->txt("exercise_time_over"), true);
387  } elseif (!count($_POST["delivered"])) {
388  ilUtil::sendFailure($this->lng->txt("please_select_a_delivered_file_to_delete"), true);
389  } else {
390  $this->submission->deleteSelectedFiles($_POST["delivered"]);
391  $this->handleRemovedUpload();
392 
393  ilUtil::sendSuccess($this->lng->txt("exc_submitted_files_deleted"), true);
394  }
395  $ilCtrl->redirect($this, "submissionScreen");
396  }
397 
401  public function downloadReturnedObject($a_only_new = false)
402  {
403  $lng = $this->lng;
404 
405  $peer_review_mask_filename = false;
406 
407  if ($this->submission->canView()) {
408  $peer_review_mask_filename = $this->submission->hasPeerReviewAccess();
409  } else {
410  // no access
411  return;
412  }
413 
414  $this->submission->downloadFiles(null, $a_only_new, $peer_review_mask_filename);
415  // we only get here, if no files have been found for download
416  if ($a_only_new) {
417  ilUtil::sendInfo($lng->txt("exc_all_new_files_offered_already"), true);
418  }
419  $this->returnToParentObject();
420  }
421 
425  public function downloadNewReturnedObject()
426  {
427  $this->downloadReturnedObject(true);
428  }
429 
436  public function downloadObject()
437  {
439 
440  $delivered_id = $_REQUEST["delivered"];
441 
442  if (!$this->submission->canView()) {
443  $this->returnToParentObject();
444  }
445 
446  if (!is_array($delivered_id) && $delivered_id > 0) {
447  $delivered_id = [$delivered_id];
448  }
449  if (is_array($delivered_id) && count($delivered_id) > 0) {
450  $this->submission->downloadFiles($delivered_id);
451  exit;
452  } else {
453  ilUtil::sendFailure($this->lng->txt("please_select_a_delivered_file_to_download"), true);
454  $ilCtrl->redirect($this, "submissionScreen");
455  }
456  }
457 }
$files
Definition: add-vimline.php:18
static sendSuccess($a_info="", $a_keep=false)
Send Success Message to Screen.
submissionScreenObject()
Displays a form which allows members to deliver their solutions.
downloadReturnedObject($a_only_new=false)
Download submitted files of user.
Class ilInfoScreenGUI.
This class represents a property form user interface.
global $DIC
Definition: saml.php:7
This class represents a file property in a property form.
downloadNewReturnedObject()
Download newly submitted files of user.
Exercise submission base gui.
static formatDate(ilDateTime $date, $a_skip_day=false, $a_include_wd=false)
Format a date public.
This class represents a file wizard property in a property form.
uploadFormObject(ilPropertyFormGUI $a_form=null)
Display form for single file upload.
static getOverviewContent(ilInfoScreenGUI $a_info, ilExSubmission $a_submission)
__construct(ilObjExercise $a_exercise, ilExSubmission $a_submission)
Constructor.
const IL_CAL_UNIX
user()
Definition: user.php:4
global $ilCtrl
Definition: ilias.php:18
static sendInfo($a_info="", $a_keep=false)
Send Info Message to Screen.
Class ilObjExercise.
downloadObject()
User downloads (own) submitted files.
$success
Definition: Utf8Test.php:86
handleNewUpload($a_no_notifications=false)
if(isset($_POST['submit'])) $form
initUploadForm()
Init upload form form.
Date and time handling
$ilUser
Definition: imgupload.php:18
Create styles array
The data for the language used.
static sendFailure($a_info="", $a_keep=false)
Send Failure Message to Screen.
confirmDeleteDeliveredObject()
Confirm deletion of delivered files.
setFilenames($a_filenames)
Set filenames.
addProperty($a_name, $a_value, $a_link="")
add a property to current section
$i
Definition: disco.tpl.php:19
Exercise submission.
Add data(end) time
Method that wraps PHPs time in order to allow simulations with the workflow.
if(!file_exists("$old.txt")) if($old===$new) if(file_exists("$new.txt")) $file
uploadZipFormObject(ilPropertyFormGUI $a_form=null)
Display form for zip file upload.
setSuffixes($a_suffixes)
Set Accepted Suffixes.
getFiles(array $a_file_ids=null, $a_only_valid=false, $a_min_timestamp=null)
$_POST["username"]
Confirmation screen class.
initZipUploadForm()
Init upload form form.
deleteDeliveredObject()
Delete file(s) submitted by user.