ILIAS  release_5-1 Revision 5.0.0-5477-g43f3e3fab5f
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 {
14  public function executeCommand()
15  {
16  global $ilCtrl;
17 
18  if(!$this->submission->canView())
19  {
20  $this->returnToParentObject();
21  }
22 
23  $class = $ilCtrl->getNextClass($this);
24  $cmd = $ilCtrl->getCmd("submissionScreen");
25 
26  switch($class)
27  {
28  default:
29  $this->{$cmd."Object"}();
30  break;
31  }
32  }
33 
34  public static function getOverviewContent(ilInfoScreenGUI $a_info, ilExSubmission $a_submission)
35  {
36  global $lng, $ilCtrl;
37 
38  $titles = array();
39  foreach($a_submission->getFiles() as $file)
40  {
41  $titles[] = $file["filetitle"];
42  }
43  $files_str = implode($titles, ", ");
44  if ($files_str == "")
45  {
46  $files_str = $lng->txt("message_no_delivered_files");
47  }
48 
49  // no team == no submission
50  if(!$a_submission->hasNoTeamYet())
51  {
52  if ($a_submission->canSubmit())
53  {
54  $title = (count($titles) == 0
55  ? $lng->txt("exc_hand_in")
56  : $lng->txt("exc_edit_submission"));
57 
58  $button = ilLinkButton::getInstance();
59  $button->setPrimary(true);
60  $button->setCaption($title, false);
61  $button->setUrl($ilCtrl->getLinkTargetByClass(array("ilExSubmissionGUI", "ilExSubmissionFileGUI"), "submissionScreen"));
62  $files_str.= " ".$button->render();
63  }
64  else
65  {
66  if (count($titles) > 0)
67  {
68  $button = ilLinkButton::getInstance();
69  $button->setCaption("already_delivered_files");
70  $button->setUrl($ilCtrl->getLinkTargetByClass(array("ilExSubmissionGUI", "ilExSubmissionFileGUI"), "submissionScreen"));
71  $files_str.= " ".$button->render();
72  }
73  }
74  }
75 
76  $a_info->addProperty($lng->txt("exc_files_returned"), $files_str);
77  }
78 
85  {
86  global $ilToolbar, $ilHelp;
87 
88 
89  $this->handleTabs();
90 
91  $ilHelp->setScreenIdComponent("exc");
92  $ilHelp->setScreenId("submissions");
93 
94  if (!$this->submission->canSubmit())
95  {
96  ilUtil::sendInfo($this->lng->txt("exercise_time_over"));
97  }
98  else
99  {
100  $max_files = $this->submission->getAssignment()->getMaxFile();
101 
102  if($this->submission->canAddFile())
103  {
104  $ilToolbar->addButton($this->lng->txt("file_add"),
105  $this->ctrl->getLinkTarget($this, "uploadForm"));
106 
107  if(!$max_files ||
108  $max_files > 1)
109  {
110  $ilToolbar->addButton($this->lng->txt("header_zip"),
111  $this->ctrl->getLinkTarget($this, "uploadZipForm"));
112  }
113 
114  // #15883 - extended deadline warning
115  if($this->assignment->getDeadline() &&
116  time() > $this->assignment->getDeadline())
117  {
118  $dl = ilDatePresentation::formatDate(new ilDateTime($this->assignment->getDeadline(),IL_CAL_UNIX));
119  $dl = sprintf($this->lng->txt("exc_late_submission_warning"), $dl);
120  $dl = '<span class="warning">'.$dl.'</span>';
121  $ilToolbar->addText($dl);
122  }
123  }
124 
125  if($max_files)
126  {
127  ilUtil::sendInfo(sprintf($this->lng->txt("exc_max_file_reached"), $max_files));
128  }
129  }
130 
131  include_once("./Modules/Exercise/classes/class.ilExcDeliveredFilesTableGUI.php");
132  $tab = new ilExcDeliveredFilesTableGUI($this, "submissionScreen", $this->submission);
133  $this->tpl->setContent($tab->getHTML());
134  }
135 
139  public function uploadFormObject(ilPropertyFormGUI $a_form = null)
140  {
141  if (!$this->submission->canSubmit())
142  {
143  $this->ctrl->redirect($this, "submissionScreen");
144  }
145 
146  $this->tabs_gui->clearTargets();
147  $this->tabs_gui->setBackTarget($this->lng->txt("back"),
148  $this->ctrl->getLinkTarget($this, "submissionScreen"));
149 
150  global $ilHelp;
151  $ilHelp->setScreenIdComponent("exc");
152  $ilHelp->setScreenId("upload_submission");
153 
154  if(!$a_form)
155  {
156  $a_form = $this->initUploadForm();
157  }
158  $this->tpl->setContent($a_form->getHTML());
159  }
160 
164  public function uploadZipFormObject(ilPropertyFormGUI $a_form = null)
165  {
166  if (!$this->submission->canSubmit())
167  {
168  $this->ctrl->redirect($this, "submissionScreen");
169  }
170 
171  $this->tabs_gui->clearTargets();
172  $this->tabs_gui->setBackTarget($this->lng->txt("back"),
173  $this->ctrl->getLinkTarget($this, "submissionScreen"));
174 
175  if(!$a_form)
176  {
177  $a_form = $this->initZipUploadForm();
178  }
179  $this->tpl->setContent($a_form->getHTML());
180  }
181 
185  protected function initUploadForm()
186  {
187  global $lng, $ilCtrl;
188 
189  include_once("Services/Form/classes/class.ilPropertyFormGUI.php");
190  $form = new ilPropertyFormGUI();
191 
192  // file input
193  include_once("./Services/Form/classes/class.ilFileWizardInputGUI.php");
194  $fi = new ilFileWizardInputGUI($lng->txt("file"), "deliver");
195  $fi->setFilenames(array(0 => ''));
196  $fi->setRequired(true);
197  $form->addItem($fi);
198 
199  $form->addCommandButton("uploadFile", $lng->txt("upload"));
200  $form->addCommandButton("submissionScreen", $lng->txt("cancel"));
201 
202  $form->setTitle($lng->txt("file_add"));
203  $form->setFormAction($ilCtrl->getFormAction($this, "uploadFile"));
204  return $form;
205  }
206 
210  protected function initZipUploadForm()
211  {
212  global $lng, $ilCtrl;
213 
214  include_once("Services/Form/classes/class.ilPropertyFormGUI.php");
215  $form = new ilPropertyFormGUI();
216 
217  include_once("./Services/Form/classes/class.ilFileInputGUI.php");
218  $fi = new ilFileInputGUI($lng->txt("file"), "deliver");
219  $fi->setRequired(true);
220  $fi->setSuffixes(array("zip"));
221  $form->addItem($fi);
222 
223  $form->addCommandButton("uploadZip", $lng->txt("upload"));
224  $form->addCommandButton("submissionScreen", $lng->txt("cancel"));
225 
226  $form->setTitle($lng->txt("header_zip"));
227  $form->setFormAction($ilCtrl->getFormAction($this, "uploadZip"));
228 
229  return $form;
230  }
231 
235  function uploadFileObject()
236  {
237  global $ilCtrl;
238 
239  // #15322
240  if (!$this->submission->canSubmit())
241  {
242  ilUtil::sendInfo($this->lng->txt("exercise_time_over"), true);
243  }
244  else
245  {
246  $form = $this->initUploadForm();
247  if(!$form->checkInput())
248  {
249  return $this->uploadFormObject($form);
250  }
251 
252  $success = false;
253  foreach ($_FILES["deliver"]["name"] as $k => $v)
254  {
255  $file = array(
256  "name" => $_FILES["deliver"]["name"][$k],
257  "type" => $_FILES["deliver"]["type"][$k],
258  "tmp_name" => $_FILES["deliver"]["tmp_name"][$k],
259  "error" => $_FILES["deliver"]["error"][$k],
260  "size" => $_FILES["deliver"]["size"][$k],
261  );
262  if(!$this->submission->uploadFile($file))
263  {
264  ilUtil::sendFailure($this->lng->txt("exc_upload_error"), true);
265  }
266  else
267  {
268  $success = true;
269  }
270  }
271 
272  if($success)
273  {
274  ilUtil::sendSuccess($this->lng->txt("file_added"), true);
275  $this->handleNewUpload();
276  }
277  }
278 
279  $ilCtrl->redirect($this, "submissionScreen");
280  }
281 
285  function uploadZipObject()
286  {
287  global $ilCtrl;
288 
289  // #15322
290  if (!$this->submission->canSubmit())
291  {
292  ilUtil::sendInfo($this->lng->txt("exercise_time_over"), true);
293  }
294  else
295  {
296  $form = $this->initZipUploadForm();
297  if(!$form->checkInput())
298  {
299  return $this->uploadZipFormObject($form);
300  }
301 
302  if (preg_match("/zip/",$_FILES["deliver"]["type"]) == 1)
303  {
304  if($this->submission->processUploadedZipFile($_FILES["deliver"]["tmp_name"]))
305  {
306  ilUtil::sendSuccess($this->lng->txt("file_added"), true);
307  $this->handleNewUpload();
308  }
309  }
310  }
311 
312  $ilCtrl->redirect($this, "submissionScreen");
313  }
314 
319  {
320  global $ilCtrl, $tpl, $lng;
321 
322  if (!$this->submission->canSubmit())
323  {
324  ilUtil::sendFailure($this->lng->txt("exercise_time_over"), true);
325  $ilCtrl->redirect($this, "submissionScreen");
326  }
327 
328  if (!is_array($_POST["delivered"]) || count($_POST["delivered"]) == 0)
329  {
330  ilUtil::sendFailure($lng->txt("no_checkbox"), true);
331  $ilCtrl->redirect($this, "submissionScreen");
332  }
333  else
334  {
335  $this->tabs_gui->clearTargets();
336  $this->tabs_gui->setBackTarget($this->lng->txt("back"),
337  $this->ctrl->getLinkTarget($this, "submissionScreen"));
338 
339  include_once("./Services/Utilities/classes/class.ilConfirmationGUI.php");
340  $cgui = new ilConfirmationGUI();
341  $cgui->setFormAction($ilCtrl->getFormAction($this));
342  $cgui->setHeaderText($lng->txt("info_delete_sure"));
343  $cgui->setCancel($lng->txt("cancel"), "submissionScreen");
344  $cgui->setConfirm($lng->txt("delete"), "deleteDelivered");
345 
346  $files = $this->submission->getFiles();
347 
348  foreach ($_POST["delivered"] as $i)
349  {
350  reset ($files);
351  $title = "";
352  foreach ($files as $f)
353  {
354  if ($f["returned_id"] == $i)
355  {
356  $title = $f["filetitle"];
357  }
358  }
359  $cgui->addItem("delivered[]", $i, $title);
360  }
361 
362  $tpl->setContent($cgui->getHTML());
363  }
364  }
365 
373  {
374  global $ilCtrl;
375 
376  if (!$this->submission->canSubmit())
377  {
378  ilUtil::sendFailure($this->lng->txt("exercise_time_over"), true);
379  }
380  else if (!count($_POST["delivered"]))
381  {
382  ilUtil::sendFailure($this->lng->txt("please_select_a_delivered_file_to_delete"), true);
383  }
384  else
385  {
386  $this->submission->deleteSelectedFiles($_POST["delivered"]);
387  $this->handleRemovedUpload();
388 
389  ilUtil::sendSuccess($this->lng->txt("exc_submitted_files_deleted"), true);
390  }
391  $ilCtrl->redirect($this, "submissionScreen");
392  }
393 
397  function downloadReturnedObject($a_only_new = false)
398  {
399  $peer_review_mask_filename = false;
400 
401  if($this->submission->canView())
402  {
403  $peer_review_mask_filename = $this->submission->hasPeerReviewAccess();
404  }
405  else
406  {
407  // no access
408  return;
409  }
410 
411  $this->submission->downloadFiles(null, $a_only_new, $peer_review_mask_filename);
412  $this->returnToParentObject();
413  }
414 
419  {
420  $this->downloadReturnedObject(true);
421  }
422 
429  function downloadObject()
430  {
431  global $ilCtrl;
432 
433  if(!$this->submission->canView())
434  {
435  $this->returnToParentObject();
436  }
437 
438  if (count($_REQUEST["delivered"]))
439  {
440  if(!is_array($_REQUEST["delivered"]))
441  {
442  $_REQUEST["delivered"] = array($_REQUEST["delivered"]);
443  }
444  $this->submission->downloadFiles($_REQUEST["delivered"]);
445  exit;
446  }
447  else
448  {
449  ilUtil::sendFailure($this->lng->txt("please_select_a_delivered_file_to_download"), true);
450  $ilCtrl->redirect($this, "submissionScreen");
451  }
452  }
453 }
static sendSuccess($a_info="", $a_keep=false)
Send Success Message to Screen.
print $file
submissionScreenObject()
Displays a form which allows members to deliver their solutions.
downloadReturnedObject($a_only_new=false)
Download submitted files of user.
exit
Definition: login.php:54
Class ilInfoScreenGUI.
$_POST['username']
Definition: cron.php:12
This class represents a property form user interface.
This class represents a file property in a property form.
downloadNewReturnedObject()
Download newly submitted files of user.
Exercise submission base gui.
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)
$cmd
Definition: sahs_server.php:35
const IL_CAL_UNIX
global $tpl
Definition: ilias.php:8
global $ilCtrl
Definition: ilias.php:18
static sendInfo($a_info="", $a_keep=false)
Send Info Message to Screen.
downloadObject()
User downloads (own) submitted files.
$success
Definition: Utf8Test.php:87
handleNewUpload($a_no_notifications=false)
static formatDate(ilDateTime $date)
Format a date public.
initUploadForm()
Init upload form form.
Date and time handling
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
global $lng
Definition: privfeed.php:40
Exercise submission.
if($_REQUEST['ilias_path']) define('ILIAS_HTTP_PATH' $_REQUEST['ilias_path']
Definition: index.php:7
uploadZipFormObject(ilPropertyFormGUI $a_form=null)
Display form for zip file upload.
getFiles(array $a_file_ids=null, $a_only_valid=false, $a_min_timestamp=null)
setRequired($a_required)
Set Required.
Confirmation screen class.
initZipUploadForm()
Init upload form form.
deleteDeliveredObject()
Delete file(s) submitted by user.