ILIAS  release_4-3 Revision
 All Data Structures Namespaces Files Functions Variables Groups Pages
class.ilObjExerciseGUI.php
Go to the documentation of this file.
1 <?php
2 
3 /* Copyright (c) 1998-2010 ILIAS open source, Extended GPL, see docs/LICENSE */
4 
5 require_once "./Services/Object/classes/class.ilObjectGUI.php";
6 
23 {
28  function ilObjExerciseGUI($a_data,$a_id,$a_call_by_reference,$a_prepare_output = true)
29  {
30  global $lng;
31 
32  $this->type = "exc";
33  $this->ilObjectGUI($a_data,$a_id,$a_call_by_reference,false);
34 
35  $lng->loadLanguageModule("exercise");
36  $lng->loadLanguageModule("exc");
37  $this->ctrl->saveParameter($this,
38  array("ass_id", "part_id", "fsmode"));
39 
40  if ($_GET["ass_id"] > 0)
41  {
42  include_once("./Modules/Exercise/classes/class.ilExAssignment.php");
43  $this->ass = new ilExAssignment((int) $_GET["ass_id"]);
44  }
45  }
46 
47  function getFiles()
48  {
49  return $this->files ? $this->files : array();
50  }
51 
52  function setFiles($a_files)
53  {
54  $this->files = $a_files;
55  }
56 
57  function executeCommand()
58  {
59  global $ilUser,$ilCtrl, $ilTabs, $lng;
60 
61  $next_class = $this->ctrl->getNextClass($this);
62  $cmd = $this->ctrl->getCmd();
63  $this->prepareOutput();
64 
65 //echo "-".$next_class."-".$cmd."-"; exit;
66  switch($next_class)
67  {
68  case "ilfilesystemgui":
69  $this->checkPermission("write");
70 
71  if ($_GET["fsmode"] == "feedback" ||
72  $_GET["fsmode"] == "feedbackpart") // feedback files
73  {
74  $ilCtrl->saveParameter($this, array("member_id"));
75  //$this->setAssignmentHeader();
76  //$ilTabs->activateTab("ass_files");
77  $ilTabs->clearTargets();
78 
79  if ($_GET["fsmode"] != "feedbackpart")
80  {
81  $ilTabs->setBackTarget($lng->txt("back"),
82  $ilCtrl->getLinkTarget($this, "members"));
83  }
84  else
85  {
86  $ilTabs->setBackTarget($lng->txt("back"),
87  $ilCtrl->getLinkTarget($this, "showParticipant"));
88  }
89  include_once("./Modules/Exercise/classes/class.ilFSStorageExercise.php");
90  $fstorage = new ilFSStorageExercise($this->object->getId(), (int) $_GET["ass_id"]);
91  $fstorage->create();
92 
93  include_once("./Services/User/classes/class.ilUserUtil.php");
94  $noti_rec_ids = array();
95  if($this->ass->getType() == ilExAssignment::TYPE_UPLOAD_TEAM)
96  {
97  $team_id = $this->ass->getTeamId((int) $_GET["member_id"]);
98  $feedback_id = "t".$team_id;
99  $fs_title = array();
100  foreach($this->ass->getTeamMembers($team_id) as $team_user_id)
101  {
102  $fs_title[] = ilUserUtil::getNamePresentation($team_user_id, false, false, "", true);
103  $noti_rec_ids[] = $team_user_id;
104  }
105  $fs_title = implode(" / ", $fs_title);
106  }
107  else
108  {
109  $feedback_id = $noti_rec_ids = (int) $_GET["member_id"];
110  $fs_title = ilUserUtil::getNamePresentation((int) $_GET["member_id"], false, false, "", true);
111  }
112 
113  include_once("./Services/FileSystem/classes/class.ilFileSystemGUI.php");
114  $fs_gui = new ilFileSystemGUI($fstorage->getFeedbackPath($feedback_id));
115  $fs_gui->setTableId("excfbfil".(int)$_GET["ass_id"]."_".$feedback_id);
116  $fs_gui->setAllowDirectories(false);
117  $fs_gui->setTitle($lng->txt("exc_fb_files")." - ".
118  ilExAssignment::lookupTitle((int) $_GET["ass_id"])." - ".
119  $fs_title);
120  $pcommand = $fs_gui->getLastPerformedCommand();
121  if (is_array($pcommand) && $pcommand["cmd"] == "create_file")
122  {
123  $this->object->sendFeedbackFileNotification($pcommand["name"],
124  $noti_rec_ids, (int) $_GET["ass_id"]);
125  }
126  $ret = $this->ctrl->forwardCommand($fs_gui);
127  }
128  else // assignment files
129  {
130  $this->setAssignmentHeader();
131  $ilTabs->activateTab("ass_files");
132  include_once("./Modules/Exercise/classes/class.ilFSStorageExercise.php");
133  $fstorage = new ilFSStorageExercise($this->object->getId(), (int) $_GET["ass_id"]);
134  $fstorage->create();
135  include_once("./Services/FileSystem/classes/class.ilFileSystemGUI.php");
136  $fs_gui = new ilFileSystemGUI($fstorage->getPath());
137  $fs_gui->setTableId("excassfil".$_GET["ass_id"]);
138  $fs_gui->setAllowDirectories(false);
139  $ret = $this->ctrl->forwardCommand($fs_gui);
140  }
141  break;
142 
143  case "ilinfoscreengui":
144  $ilTabs->activateTab("info");
145  $this->infoScreen(); // forwards command
146  break;
147 
148  case 'ilpermissiongui':
149  $ilTabs->activateTab("permissions");
150  include_once("Services/AccessControl/classes/class.ilPermissionGUI.php");
151  $perm_gui =& new ilPermissionGUI($this);
152  $ret =& $this->ctrl->forwardCommand($perm_gui);
153  break;
154 
155  case "illearningprogressgui":
156  $ilTabs->activateTab("learning_progress");
157  include_once './Services/Tracking/classes/class.ilLearningProgressGUI.php';
158 
160  $this->object->getRefId(),
161  $_GET['user_id'] ? $_GET['user_id'] : $ilUser->getId());
162  $this->ctrl->forwardCommand($new_gui);
163  $this->tabs_gui->setTabActive('learning_progress');
164  break;
165 
166  case 'ilrepositorysearchgui':
167  $ilTabs->activateTab("grades");
168  include_once('./Services/Search/classes/class.ilRepositorySearchGUI.php');
169  $rep_search = new ilRepositorySearchGUI();
170  if(!$_REQUEST["ctx"])
171  {
172  $rep_search->setTitle($this->lng->txt("exc_add_participant"));
173  $rep_search->setCallback($this,'addMembersObject');
174 
175  // Set tabs
176  $this->tabs_gui->setTabActive('members');
177  $this->ctrl->setReturn($this,'members');
178 
179  #$this->__setSubTabs('members');
180  #$this->tabs_gui->setSubTabActive('members');
181  }
182  else
183  {
184  $this->ctrl->saveParameterByClass('ilRepositorySearchGUI', 'ctx', 1);
185 
186  $rep_search->setTitle($this->lng->txt("exc_team_member_add"));
187  $rep_search->setCallback($this,'addTeamMemberActionObject');
188 
189  // Set tabs
190  $this->initTeamSubmission("submissionScreenTeam");
191  $this->ctrl->setReturn($this,'submissionScreenTeam');
192  }
193  $ret =& $this->ctrl->forwardCommand($rep_search);
194  break;
195 
196  case 'ilobjectcopygui':
197  $ilCtrl->saveParameter($this, 'new_type');
198  $ilCtrl->setReturnByClass(get_class($this),'create');
199 
200  include_once './Services/Object/classes/class.ilObjectCopyGUI.php';
201  $cp = new ilObjectCopyGUI($this);
202  $cp->setType('exc');
203  $this->ctrl->forwardCommand($cp);
204  break;
205 
206  case "ilexportgui":
207  $ilTabs->activateTab("export");
208  include_once("./Services/Export/classes/class.ilExportGUI.php");
209  $exp_gui = new ilExportGUI($this);
210  $exp_gui->addFormat("xml");
211  $ret = $this->ctrl->forwardCommand($exp_gui);
212 // $this->tpl->show();
213  break;
214  case 'ilshoppurchasegui':
215  include_once './Services/Payment/classes/class.ilShopPurchaseGUI.php';
216  $sp = new ilShopPurchaseGUI($_GET['ref_id']);
217 
218  $this->ctrl->forwardCommand($sp);
219  break;
220 
221  case "ilcommonactiondispatchergui":
222  include_once("Services/Object/classes/class.ilCommonActionDispatcherGUI.php");
224  $this->ctrl->forwardCommand($gui);
225  break;
226 
227  case "ilcertificategui":
228  $this->setSettingsSubTabs();
229  $this->tabs_gui->activateTab("settings");
230  $this->tabs_gui->activateSubTab("certificate");
231  include_once "./Services/Certificate/classes/class.ilCertificateGUI.php";
232  include_once "./Modules/Exercise/classes/class.ilExerciseCertificateAdapter.php";
233  $output_gui = new ilCertificateGUI(new ilExerciseCertificateAdapter($this->object));
234  $this->ctrl->forwardCommand($output_gui);
235  break;
236 
237  default:
238  if(!$cmd)
239  {
240  $cmd = "infoScreen";
241  }
242 
243  $cmd .= "Object";
244 
245  $this->$cmd();
246 
247  break;
248  }
249 
250  $this->addHeaderAction();
251 
252  return true;
253  }
254 
255  function viewObject()
256  {
257  $this->infoScreenObject();
258  }
259 
266  function downloadObject()
267  {
268  global $ilUser, $ilCtrl;
269 
270  $this->checkPermission("read");
271  if (count($_REQUEST["delivered"]))
272  {
273  if(!is_array($_REQUEST["delivered"]))
274  {
275  $_REQUEST["delivered"] = array($_REQUEST["delivered"]);
276  }
277  ilExAssignment::downloadSelectedFiles($this->object->getId(), (int) $_GET["ass_id"],
278  $ilUser->getId(), $_REQUEST["delivered"]);
279  exit;
280  }
281  else
282  {
283  ilUtil::sendFailure($this->lng->txt("please_select_a_delivered_file_to_download"), true);
284  $ilCtrl->redirect($this, "submissionScreen");
285  }
286  }
287 
292  {
293  global $ilCtrl, $tpl, $lng, $ilUser;
294 
295  $this->checkPermission("read");
296 
297  $this->tabs_gui->clearTargets();
298  $this->tabs_gui->setBackTarget($this->lng->txt("back"),
299  $this->ctrl->getLinkTarget($this, "submissionScreen"));
300 
301  // $this->tabs_gui->setTabActive("content");
302  // $this->addContentSubTabs("content");
303 
304  if (mktime() > $this->ass->getDeadline() && ($this->ass->getDeadline() != 0))
305  {
306  ilUtil::sendFailure($this->lng->txt("exercise_time_over"), true);
307  $ilCtrl->redirect($this, "submissionScreen");
308  }
309 
310  if (!is_array($_POST["delivered"]) || count($_POST["delivered"]) == 0)
311  {
312  ilUtil::sendFailure($lng->txt("no_checkbox"), true);
313  $ilCtrl->redirect($this, "submissionScreen");
314  }
315  else
316  {
317  include_once("./Services/Utilities/classes/class.ilConfirmationGUI.php");
318  $cgui = new ilConfirmationGUI();
319  $cgui->setFormAction($ilCtrl->getFormAction($this));
320  $cgui->setHeaderText($lng->txt("info_delete_sure"));
321  $cgui->setCancel($lng->txt("cancel"), "submissionScreen");
322  $cgui->setConfirm($lng->txt("delete"), "deleteDelivered");
323 
324  $files = ilExAssignment::getDeliveredFiles($this->object->getId(), (int) $_GET["ass_id"],
325  $ilUser->getId());
326 //var_dump($files);
327  foreach ($_POST["delivered"] as $i)
328  {
329  reset ($files);
330  $title = "";
331  foreach ($files as $f)
332  {
333  if ($f["returned_id"] == $i)
334  {
335  $title = $f["filetitle"];
336  }
337  }
338  $cgui->addItem("delivered[]", $i, $title);
339  }
340 
341  $tpl->setContent($cgui->getHTML());
342  }
343  }
344 
352  {
353  global $ilUser, $ilCtrl;
354 
355  $this->checkPermission("read");
356 
357  if (mktime() > $this->ass->getDeadline() && ($this->ass->getDeadline() != 0))
358  {
359  ilUtil::sendFailure($this->lng->txt("exercise_time_over"), true);
360  $ilCtrl->redirect($this, "submissionScreen");
361  }
362 
363  if (count($_POST["delivered"]) && (mktime() < $this->ass->getDeadline() ||
364  $this->ass->getDeadline() == 0))
365  {
366  $this->object->deleteDeliveredFiles($this->object->getId(), (int) $_GET["ass_id"],
367  $_POST["delivered"], $ilUser->id);
368 
369  $this->object->handleSubmission((int)$_GET['ass_id']);
370 
371  ilUtil::sendSuccess($this->lng->txt("exc_submitted_files_deleted"), true);
372  }
373  else
374  {
375  ilUtil::sendFailure($this->lng->txt("please_select_a_delivered_file_to_delete"), true);
376  }
377  $ilCtrl->redirect($this, "submissionScreen");
378  }
379 
386  {
387  global $ilToolbar;
388 
389  $this->initTeamSubmission("showOverview", false);
390  $this->tabs_gui->activateTab("submissions");
391 
392  // $this->tabs_gui->setTabActive("content");
393  // $this->addContentSubTabs("content");
394 
395  if (mktime() > $this->ass->getDeadline() && ($this->ass->getDeadline() != 0))
396  {
397  ilUtil::sendInfo($this->lng->txt("exercise_time_over"));
398  }
399  else
400  {
401  $ilToolbar->addButton($this->lng->txt("file_add"),
402  $this->ctrl->getLinkTarget($this, "uploadForm"));
403 
404  $ilToolbar->addButton($this->lng->txt("header_zip"),
405  $this->ctrl->getLinkTarget($this, "uploadZipForm"));
406  }
407 
408  include_once("./Modules/Exercise/classes/class.ilExcDeliveredFilesTableGUI.php");
409  $tab = new ilExcDeliveredFilesTableGUI($this, "submissionScreen", $this->object, $_GET["ass_id"]);
410  $this->tpl->setContent($tab->getHTML());
411  }
412 
416  public function uploadFormObject()
417  {
418  if (mktime() < $this->ass->getDeadline() || ($this->ass->getDeadline() == 0))
419  {
420  $this->tabs_gui->clearTargets();
421  $this->tabs_gui->setBackTarget($this->lng->txt("back"),
422  $this->ctrl->getLinkTarget($this, "submissionScreen"));
423 
424  $this->initUploadForm();
425  $this->tpl->setContent($this->form->getHTML());
426  }
427  else
428  {
429  $this->ctrl->redirect($this, "submissionScreen");
430  }
431  }
432 
436  public function uploadZipFormObject()
437  {
438  if (mktime() < $this->ass->getDeadline() || ($this->ass->getDeadline() == 0))
439  {
440  $this->tabs_gui->clearTargets();
441  $this->tabs_gui->setBackTarget($this->lng->txt("back"),
442  $this->ctrl->getLinkTarget($this, "submissionScreen"));
443 
444  $this->initZipUploadForm();
445  $this->tpl->setContent($this->form->getHTML());
446  }
447  else
448  {
449  $this->ctrl->redirect($this, "submissionScreen");
450  }
451  }
452 
456  public function initUploadForm()
457  {
458  global $lng, $ilCtrl;
459 
460  include_once("Services/Form/classes/class.ilPropertyFormGUI.php");
461  $this->form = new ilPropertyFormGUI();
462 
463  // file input
464  include_once("./Services/Form/classes/class.ilFileWizardInputGUI.php");
465  $fi = new ilFileWizardInputGUI($lng->txt("file"), "deliver");
466  $fi->setFilenames(array(0 => ''));
467  //$fi->setInfo($lng->txt(""));
468  $this->form->addItem($fi);
469 
470  $this->form->addCommandButton("deliverFile", $lng->txt("upload"));
471  $this->form->addCommandButton("submissionScreen", $lng->txt("cancel"));
472 
473  $this->form->setTitle($lng->txt("file_add"));
474  $this->form->setFormAction($ilCtrl->getFormAction($this));
475  }
476 
480  public function initZipUploadForm()
481  {
482  global $lng, $ilCtrl;
483 
484  include_once("Services/Form/classes/class.ilPropertyFormGUI.php");
485  $this->form = new ilPropertyFormGUI();
486 
487  // desc
488  include_once("./Services/Form/classes/class.ilFileInputGUI.php");
489  $fi = new ilFileInputGUI($lng->txt("file"), "deliver");
490  $fi->setSuffixes(array("zip"));
491  $this->form->addItem($fi);
492 
493  $this->form->addCommandButton("deliverUnzip", $lng->txt("upload"));
494  $this->form->addCommandButton("submissionScreen", $lng->txt("cancel"));
495 
496  $this->form->setTitle($lng->txt("header_zip"));
497  $this->form->setFormAction($ilCtrl->getFormAction($this));
498  }
499 
503  function deliverFileObject()
504  {
505  global $ilUser, $lng, $ilCtrl;
506 
507  $this->checkPermission("read");
508 
509  $success = false;
510  foreach ($_FILES["deliver"]["name"] as $k => $v)
511  {
512  $file = array(
513  "name" => $_FILES["deliver"]["name"][$k],
514  "type" => $_FILES["deliver"]["type"][$k],
515  "tmp_name" => $_FILES["deliver"]["tmp_name"][$k],
516  "error" => $_FILES["deliver"]["error"][$k],
517  "size" => $_FILES["deliver"]["size"][$k],
518  );
519  if(!$this->object->deliverFile($file, (int) $_GET["ass_id"], $ilUser->id))
520  {
521  ilUtil::sendFailure($this->lng->txt("exc_upload_error"), true);
522  }
523  else
524  {
525  $success = true;
526  }
527  }
528 
529  if($success)
530  {
531  $this->sendNotifications((int)$_GET["ass_id"]);
532  $this->object->handleSubmission((int)$_GET['ass_id']);
533  }
534  $ilCtrl->redirect($this, "submissionScreen");
535  }
536 
541  {
542  global $ilCtrl;
543 
544  $this->checkPermission("read");
545 
546  if (preg_match("/zip/",$_FILES["deliver"]["type"]) == 1)
547  {
548  if($this->object->processUploadedFile($_FILES["deliver"]["tmp_name"], "deliverFile", false,
549  (int) $_GET["ass_id"]))
550  {
551  $this->sendNotifications((int)$_GET["ass_id"]);
552  $this->object->handleSubmission((int)$_GET['ass_id']);
553  }
554  }
555 
556  $ilCtrl->redirect($this, "submissionScreen");
557  }
558 
563  {
564  global $rbacsystem, $ilUser;
565 
566  $file = $_REQUEST["file"];
567 
568  // check read permission
569  $this->checkPermission("read");
570 
571  if (!isset($file))
572  {
573  ilUtil::sendFailure($this->lng->txt("exc_select_one_file"),true);
574  $this->ctrl->redirect($this, "view");
575  }
576 
577  $ass = new ilExAssignment((int) $_GET["ass_id"]);
578 
579  if($ass->getType() == ilExAssignment::TYPE_UPLOAD_TEAM)
580  {
581  $feedback_id = "t".$ass->getTeamId($ilUser->getId());
582  }
583  else
584  {
585  $feedback_id = $ilUser->getId();
586  }
587 
588  // check, whether file belongs to assignment
589  include_once("./Modules/Exercise/classes/class.ilFSStorageExercise.php");
590  $storage = new ilFSStorageExercise($this->object->getId(), (int) $_GET["ass_id"]);
591  $files = $storage->getFeedbackFiles($feedback_id);
592  $file_exist = false;
593  foreach($files as $fb_file)
594  {
595  if($fb_file == $file)
596  {
597  $file_exist = true;
598  break;
599  }
600  }
601  if(!$file_exist)
602  {
603  echo "FILE DOES NOT EXIST";
604  exit;
605  }
606 
607  // check whether assignment as already started
608  $not_started_yet = false;
609  if ($ass->getStartTime() > 0 && time() - $ass->getStartTime() <= 0)
610  {
611  $not_started_yet = true;
612  }
613 
614  // deliver file
615  if (!$not_started_yet)
616  {
617  $p = $storage->getFeedbackFilePath($feedback_id, $file);
619  }
620 
621  return true;
622  }
623 
628  {
629  global $rbacsystem;
630 
631  $file = $_REQUEST["file"];
632 
633  // check read permission
634  $this->checkPermission("read");
635 
636  if (!isset($file))
637  {
638  ilUtil::sendFailure($this->lng->txt("exc_select_one_file"),true);
639  $this->ctrl->redirect($this, "view");
640  }
641 
642  // check, whether file belongs to assignment
643  include_once("./Modules/Exercise/classes/class.ilExAssignment.php");
644  $files = ilExAssignment::getFiles($this->object->getId(), (int) $_GET["ass_id"]);
645  $file_exist = false;
646  foreach($files as $lfile)
647  {
648  if($lfile["name"] == $file)
649  {
650  $file_exist = true;
651  break;
652  }
653  }
654  if(!$file_exist)
655  {
656  echo "FILE DOES NOT EXIST";
657  exit;
658  }
659 
660  // check whether assignment as already started
661  $ass = new ilExAssignment((int) $_GET["ass_id"]);
662  $not_started_yet = false;
663  if ($ass->getStartTime() > 0 && time() - $ass->getStartTime() <= 0)
664  {
665  $not_started_yet = true;
666  }
667 
668  // deliver file
669  if (!$not_started_yet)
670  {
671  include_once("./Modules/Exercise/classes/class.ilFSStorageExercise.php");
672  $storage = new ilFSStorageExercise($this->object->getId(), (int) $_GET["ass_id"]);
673  $p = $storage->getAssignmentFilePath($file);
675  }
676 
677  return true;
678  }
679 
680  protected function afterSave(ilObject $a_new_object)
681  {
682  $a_new_object->saveData();
683 
684  ilUtil::sendSuccess($this->lng->txt("exc_added"), true);
685  ilUtil::redirect("ilias.php?baseClass=ilExerciseHandlerGUI&ref_id=".$a_new_object->getRefId()."&cmd=addAssignment");
686  }
687 
691  protected function initEditCustomForm(ilPropertyFormGUI $a_form)
692  {
693  $a_form->setTitle($this->lng->txt("exc_edit_exercise"));
694 
695 
696  // show submissions
697  $cb = new ilCheckboxInputGUI($this->lng->txt("exc_show_submissions"), "show_submissions");
698  $cb->setInfo($this->lng->txt("exc_show_submissions_info"));
699  $a_form->addItem($cb);
700 
701 
702  // pass mode
703  $radg = new ilRadioGroupInputGUI($this->lng->txt("exc_pass_mode"), "pass_mode");
704 
705  $op1 = new ilRadioOption($this->lng->txt("exc_pass_all"), "all",
706  $this->lng->txt("exc_pass_all_info"));
707  $radg->addOption($op1);
708  $op2 = new ilRadioOption($this->lng->txt("exc_pass_minimum_nr"), "nr",
709  $this->lng->txt("exc_pass_minimum_nr_info"));
710  $radg->addOption($op2);
711 
712  // minimum number of assignments to pass
713  $ni = new ilNumberInputGUI($this->lng->txt("exc_min_nr"), "pass_nr");
714  $ni->setSize(4);
715  $ni->setMaxLength(4);
716  $ni->setRequired(true);
717  include_once("./Modules/Exercise/classes/class.ilExAssignment.php");
718  $mand = ilExAssignment::countMandatory($this->object->getId());
719  $min = max($mand, 1);
720  $ni->setMinValue($min);
721  $op2->addSubItem($ni);
722 
723  $a_form->addItem($radg);
724 
725  $cbox = new ilCheckboxInputGUI($this->lng->txt("exc_submission_notification"), "notification");
726  $cbox->setInfo($this->lng->txt("exc_submission_notification_info"));
727  $a_form->addItem($cbox);
728 
729  $subcompl = new ilCheckboxInputGUI($this->lng->txt('exc_completion_by_submission'), 'completion_by_submission');
730  $subcompl->setInfo($this->lng->txt('exc_completion_by_submission_info'));
731  $subcompl->setValue(1);
732  $a_form->addItem($subcompl);
733  }
734 
738  protected function getEditFormCustomValues(array &$a_values)
739  {
740  global $ilUser;
741 
742  $a_values["desc"] = $this->object->getLongDescription();
743  $a_values["show_submissions"] = $this->object->getShowSubmissions();
744  $a_values["pass_mode"] = $this->object->getPassMode();
745  if ($a_values["pass_mode"] == "nr")
746  {
747  $a_values["pass_nr"] = $this->object->getPassNr();
748  }
749 
750  include_once "./Services/Notification/classes/class.ilNotification.php";
751  $a_values["notification"] = ilNotification::hasNotification(
753  $this->object->getId());
754 
755  $a_values['completion_by_submission'] = $this->object->isCompletionBySubmissionEnabled();
756  }
757 
758  protected function updateCustom(ilPropertyFormGUI $a_form)
759  {
760  global $ilUser;
761  $this->object->setShowSubmissions($a_form->getInput("show_submissions"));
762  $this->object->setPassMode($a_form->getInput("pass_mode"));
763  if ($this->object->getPassMode() == "nr")
764  {
765  $this->object->setPassNr($a_form->getInput("pass_nr"));
766  }
767 
768  $this->object->setCompletionBySubmission($a_form->getInput('completion_by_submission') == 1 ? true : false);
769 
770  include_once "./Services/Notification/classes/class.ilNotification.php";
772  $ilUser->getId(), $this->object->getId(),
773  (bool)$a_form->getInput("notification"));
774  }
775 
776  function cancelEditObject()
777  {
778  $this->ctrl->redirect($this, "view");
779  }
780 
781  function uploadZipObject()
782  {
783  global $rbacsystem;
784 
785  $this->checkPermission("write");
786 
787  if(!$this->object->addUploadedFile($_FILES["zipfile"], true))
788  {
789  ilUtil::sendFailure($this->lng->txt("exc_upload_error"),true);
790  }
791  $this->ctrl->redirect($this, "edit");
792 
793  }
794 
795  function uploadFileObject()
796  {
797  global $rbacsystem;
798 
799  $this->checkPermission("write");
800 
801  if(!$this->object->addUploadedFile($_FILES["file"]))
802  {
803  ilUtil::sendFailure($this->lng->txt("exc_upload_error"),true);
804  }
805  $this->ctrl->redirect($this, "edit");
806  }
807 
808 
813  {
814  global $rbacsystem;
815 
816  $this->checkPermission("write");
817 
818  if ($_POST["downloadReturned"])
819  {
820  $this->object->members_obj->deliverReturnedFiles(key($_POST["downloadReturned"]));
821  exit;
822  }
823  else
824  {
825  switch($_POST["action"])
826  {
827  case "save_status":
828  $this->saveStatusObject();
829  break;
830 
831  case "send_member":
832  $this->sendMembersObject();
833  break;
834 
835  case "redirectFeedbackMail":
837  break;
838 
839  case "delete_member":
840  $this->deassignMembersObject();
841  break;
842  }
843  }
844  }
845 
850  {
851  global $ilAccess;
852 
853  if ($ilAccess->checkAccess("read", "", $this->object->getRefId()) &&
854  $this->object->getShowSubmissions() &&
855  $this->object->getTimestamp() - time() <= 0)
856  {
857  // ok: read access + public submissions
858  }
859  else
860  {
861  $this->checkPermission("write");
862  }
863 
865  $this->object->getId(), (int) $_GET["ass_id"], (int) $_GET["member_id"]))
866  {
867  $this->ctrl->redirect($this, "members");
868  }
869  exit;
870  }
871 
876  {
877  $this->checkPermission("write");
878 
880  $this->object->getId(), (int) $_GET["ass_id"], (int) $_GET["member_id"], true))
881  {
882  $this->ctrl->redirect($this, "members");
883  }
884  exit;
885  }
886 
891  {
892  if(!strlen(trim($_POST['user_login'])))
893  {
894  ilUtil::sendFailure($this->lng->txt('msg_no_search_string'));
895  $this->membersObject();
896  return false;
897  }
898  $users = explode(',', $_POST['user_login']);
899 
900  $user_ids = array();
901  foreach($users as $user)
902  {
903  $user_id = ilObjUser::_lookupId($user);
904 
905  if(!$user_id)
906  {
907  ilUtil::sendFailure($this->lng->txt('user_not_known'));
908 
909  // add team member
910  if($_REQUEST['ctx'])
911  {
912  return $this->submissionScreenTeamObject();
913  }
914  else
915  {
916  return $this->membersObject();
917  }
918  }
919 
920  $user_ids[] = $user_id;
921  }
922 
923  if($_REQUEST['ctx'])
924  {
925  return $this->addTeamMemberActionObject($user_ids);
926  }
927 
928  if(!$this->addMembersObject($user_ids));
929  {
930  $this->membersObject();
931  return false;
932  }
933  return true;
934  }
935 
939  function addMembersObject($a_user_ids = array())
940  {
941  global $ilAccess,$ilErr;
942 
943  $this->checkPermission("write");
944  if(!count($a_user_ids))
945  {
946  ilUtil::sendFailure($this->lng->txt("no_checkbox"));
947  return false;
948  }
949 
950  if(!$this->object->members_obj->assignMembers($a_user_ids))
951  {
952  ilUtil::sendFailure($this->lng->txt("exc_members_already_assigned"));
953  return false;
954  }
955  else
956  {
957  // #9946 - create team for new user(s) for each team upload assignment
958  foreach(ilExAssignment::getAssignmentDataOfExercise($this->object->getId()) as $ass)
959  {
960  if($ass["type"] == ilExAssignment::TYPE_UPLOAD_TEAM)
961  {
962  $ass_obj = new ilExAssignment($ass["id"]);
963  foreach($a_user_ids as $user_id)
964  {
965  $ass_obj->getTeamId($user_id, true);
966  }
967  }
968  }
969 
970  ilUtil::sendSuccess($this->lng->txt("exc_members_assigned"),true);
971  }
972 //exit;
973  $this->ctrl->redirect($this, "members");
974  return true;
975  }
976 
977 
981  function membersObject()
982  {
983  global $rbacsystem, $tree, $tpl, $ilToolbar, $ilCtrl, $ilTabs, $lng;
984 
985  $ilTabs->activateTab("grades");
986 
987  include_once 'Services/Tracking/classes/class.ilLPMarks.php';
988 
989  $this->checkPermission("write");
990  $this->addSubmissionSubTabs("assignment");
991 
992  // assignment selection
993  include_once("./Modules/Exercise/classes/class.ilExAssignment.php");
994  $ass = ilExAssignment::getAssignmentDataOfExercise($this->object->getId());
995 
996  if ($_GET["ass_id"] == "")
997  {
998  $a = current($ass);
999  $_GET["ass_id"] = $a["id"];
1000  }
1001 
1002  reset($ass);
1003  if (count($ass) > 1)
1004  {
1005  $options = array();
1006  foreach ($ass as $a)
1007  {
1008  $options[$a["id"]] = $a["title"];
1009  }
1010  include_once("./Services/Form/classes/class.ilSelectInputGUI.php");
1011  $si = new ilSelectInputGUI($this->lng->txt(""), "ass_id");
1012  $si->setOptions($options);
1013  $si->setValue($_GET["ass_id"]);
1014  $ilToolbar->addInputItem($si);
1015 
1016  $ilToolbar->setFormAction($ilCtrl->getFormAction($this));
1017  $ilToolbar->addFormButton($this->lng->txt("exc_select_ass"),
1018  "selectAssignment");
1019  $ilToolbar->addSeparator();
1020  }
1021 
1022  // add member
1023  include_once './Services/Search/classes/class.ilRepositorySearchGUI.php';
1025  $this,
1026  $ilToolbar,
1027  array(
1028  'auto_complete_name' => $lng->txt('user'),
1029  'submit_name' => $lng->txt('add')
1030  )
1031  );
1032 
1033  $ilToolbar->addSpacer();
1034 
1035  $ilToolbar->addButton(
1036  $lng->txt("exc_search_users"),
1037  $this->ctrl->getLinkTargetByClass('ilRepositorySearchGUI',''));
1038  $ilToolbar->setFormAction($ilCtrl->getFormAction($this));
1039 
1040  // add course members button, in case the exercise is inside a course
1041  $parent_id = $tree->getParentId($_GET["ref_id"]);
1042  $parent_obj_id = ilObject::_lookupObjId($parent_id);
1043  $type = ilObject::_lookupType($parent_obj_id);
1044  while ($parent_id != 1 && $type != "crs")
1045  {
1046  $parent_id = $tree->getParentId($parent_id);
1047  $parent_obj_id = ilObject::_lookupObjId($parent_id);
1048  $type = ilObject::_lookupType($parent_obj_id);
1049  }
1050  if ($type == "crs")
1051  {
1052  $this->ctrl->setParameterByClass('ilRepositorySearchGUI', "list_obj", $parent_obj_id);
1053  $this->lng->loadLanguageModule("exercise");
1054 
1055  $ilToolbar->addButton($this->lng->txt("exc_crs_add_members"),
1056  $this->ctrl->getLinkTargetByClass('ilRepositorySearchGUI','listUsers'));
1057  }
1058 
1059  if (count($ass) > 0)
1060  {
1061  include_once("./Modules/Exercise/classes/class.ilExerciseMemberTableGUI.php");
1062  $exc_tab = new ilExerciseMemberTableGUI($this, "members", $this->object, $_GET["ass_id"]);
1063  $tpl->setContent($exc_tab->getHTML());
1064  }
1065  else
1066  {
1067  ilUtil::sendInfo($lng->txt("exc_no_assignments_available"));
1068  }
1069  return;
1070  }
1071 
1076  {
1077  global $ilTabs;
1078 
1079  $ilTabs->activateTab("grades");
1080 
1081  $_GET["ass_id"] = ilUtil::stripSlashes($_POST["ass_id"]);
1082  $this->membersObject();
1083  }
1084 
1089  {
1090  global $rbacsystem, $tree, $tpl, $ilToolbar, $ilCtrl, $ilTabs, $lng;
1091 
1092  $this->checkPermission("write");
1093 
1094  $ilTabs->activateTab("grades");
1095  $this->addSubmissionSubTabs("participant");
1096 
1097  // participant selection
1098  include_once("./Modules/Exercise/classes/class.ilExAssignment.php");
1099  $ass = ilExAssignment::getAssignmentDataOfExercise($this->object->getId());
1100  $members = $this->object->members_obj->getMembers();
1101 
1102  if (count($members) == 0)
1103  {
1104  ilUtil::sendInfo($lng->txt("exc_no_participants"));
1105  return;
1106  }
1107 
1108  $mems = array();
1109  foreach ($members as $mem_id)
1110  {
1111  if (ilObject::_lookupType($mem_id) == "usr")
1112  {
1113  include_once("./Services/User/classes/class.ilObjUser.php");
1114  $name = ilObjUser::_lookupName($mem_id);
1115  $mems[$mem_id] = $name;
1116  }
1117  }
1118 
1119  $mems = ilUtil::sortArray($mems, "lastname", "asc", false, true);
1120 
1121  if ($_GET["part_id"] == "" && count($mems) > 0)
1122  {
1123  $_GET["part_id"] = key($mems);
1124  }
1125 
1126  reset($mems);
1127  if (count($mems) > 1)
1128  {
1129  $options = array();
1130  foreach ($mems as $k => $m)
1131  {
1132  $options[$k] =
1133  $m["lastname"].", ".$m["firstname"]." [".$m["login"]."]";
1134  }
1135  include_once("./Services/Form/classes/class.ilSelectInputGUI.php");
1136  $si = new ilSelectInputGUI($this->lng->txt(""), "part_id");
1137  $si->setOptions($options);
1138  $si->setValue($_GET["part_id"]);
1139  $ilToolbar->addInputItem($si);
1140 
1141  $ilToolbar->setFormAction($ilCtrl->getFormAction($this));
1142  $ilToolbar->addFormButton($this->lng->txt("exc_select_part"),
1143  "selectParticipant");
1144  }
1145 
1146  if (count($mems) > 0)
1147  {
1148  include_once("./Modules/Exercise/classes/class.ilExParticipantTableGUI.php");
1149  $part_tab = new ilExParticipantTableGUI($this, "showParticipant",
1150  $this->object, $_GET["part_id"]);
1151  $tpl->setContent($part_tab->getHTML());
1152  }
1153  else
1154  {
1155  ilUtil::sendInfo($this->lng->txt("exc_no_assignments_available"));
1156  }
1157  }
1158 
1163  {
1164  global $ilTabs;
1165 
1166  $ilTabs->activateTab("grades");
1167 
1168  $_GET["part_id"] = ilUtil::stripSlashes($_POST["part_id"]);
1169  $this->showParticipantObject();
1170  }
1171 
1176  {
1177  global $rbacsystem, $tree, $tpl, $ilToolbar, $ilCtrl, $ilTabs, $lng;
1178 
1179  $this->checkPermission("write");
1180 
1181  $ilTabs->activateTab("grades");
1182  $this->addSubmissionSubTabs("grades");
1183 
1184  include_once("./Modules/Exercise/classes/class.ilExAssignment.php");
1185  $mem_obj = new ilExerciseMembers($this->object);
1186  $mems = $mem_obj->getMembers();
1187 
1188  if (count($mems) > 0)
1189  {
1190  $ilToolbar->addButton($lng->txt("exc_export_excel"),
1191  $ilCtrl->getLinkTarget($this, "exportExcel"));
1192  }
1193 
1194  include_once("./Modules/Exercise/classes/class.ilExGradesTableGUI.php");
1195  $grades_tab = new ilExGradesTableGUI($this, "showGradesOverview",
1196  $this->object, $mem_obj);
1197  $tpl->setContent($grades_tab->getHTML());
1198  }
1199 
1204  {
1205  $this->checkPermission("write");
1206 
1207  $members = array();
1208 
1209  if ($_GET["member_id"] != "")
1210  {
1211  if($this->ass->getType() == ilExAssignment::TYPE_UPLOAD_TEAM)
1212  {
1213  $members = ilExAssignment::getTeamMembersByAssignmentId($this->ass->getId(), $_GET["member_id"]);
1214  }
1215  else
1216  {
1217  $members = array($_GET["member_id"]);
1218  }
1219  }
1220  else if(count($_POST["member"]) > 0)
1221  {
1222  if($this->ass->getType() == ilExAssignment::TYPE_UPLOAD_TEAM)
1223  {
1224  foreach(array_keys($_POST["member"]) as $user_id)
1225  {
1226  $members = array_merge($members, ilExAssignment::getTeamMembersByAssignmentId($this->ass->getId(), $user_id));
1227  }
1228  $members = array_unique($members);
1229  }
1230  else
1231  {
1232  $members = array_keys($_POST["member"]);
1233  }
1234  }
1235 
1236  if($members)
1237  {
1238  $logins = array();
1239  foreach($members as $user_id)
1240  {
1241  ilExAssignment::updateStatusFeedbackForUser($this->ass->getId(), $user_id, 1);
1242  $logins[] = ilObjUser::_lookupLogin($user_id);
1243  }
1244  $logins = implode($logins, ",");
1245 
1246  require_once 'Services/Mail/classes/class.ilMailFormCall.php';
1247  ilUtil::redirect(ilMailFormCall::getRedirectTarget($this, 'members', array(), array('type' => 'new', 'rcp_to' => $logins)));
1248  }
1249 
1250  ilUtil::sendFailure($this->lng->txt("no_checkbox"),true);
1251  $this->ctrl->redirect($this, "members");
1252  }
1253 
1258  {
1259  $this->checkPermission("write");
1260 
1261  $members = array();
1262 
1263  foreach($this->object->members_obj->getMembers() as $member_id)
1264  {
1265  // update download time
1266  ilExAssignment::updateTutorDownloadTime($this->object->getId(),
1267  (int) $_GET["ass_id"], $member_id);
1268 
1269  // get member object (ilObjUser)
1270  if (ilObject::_exists($member_id))
1271  {
1272  $tmp_obj =& ilObjectFactory::getInstanceByObjId($member_id);
1273  $members[$member_id] = $tmp_obj->getFirstname() . " " . $tmp_obj->getLastname();
1274  unset($tmp_obj);
1275  }
1276  }
1277 
1278  ilExAssignment::downloadAllDeliveredFiles($this->object->getId(),
1279  (int) $_GET["ass_id"], $members);
1280  exit;
1281  }
1282 
1283 
1284  function __getMembersOfObject($a_result,$a_type)
1285  {
1286 
1287  switch($a_type)
1288  {
1289  case "usr":
1290  return $a_result;
1291  case "grp":
1292  include_once "./Modules/Group/classes/class.ilObjGroup.php";
1293 
1294  $all_members = array();
1295  foreach($a_result as $group)
1296  {
1297  $tmp_grp_obj = ilObjectFactory::getInstanceByRefId($group["id"]);
1298 
1299  $members = $tmp_grp_obj->getGroupMemberIds();
1300  $all_members = array_merge($all_members,$members);
1301  }
1302  // FORMAT ARRAY
1303  $all_members = array_unique($all_members);
1304  foreach($all_members as $member)
1305  {
1306  $result[] = array("id" => $member);
1307  }
1308  return $result;
1309  }
1310  return true;
1311  }
1312 
1313  function __showObjectSelect($a_result,$a_type)
1314  {
1315  include_once "./Services/Object/classes/class.ilObjectFactory.php";
1316 
1317  foreach($a_result as $obj)
1318  {
1319  $tmp_obj =& ilObjectFactory::getInstanceByRefId($obj["id"]);
1320  $this->tpl->setCurrentBlock("OBJ_SELECT_ROW");
1321  $this->tpl->setVariable("OBJ_ROW_TITLE",$tmp_obj->getTitle());
1322  $this->tpl->setVariable("OBJ_ROW_ID",$tmp_obj->getRefId());
1323  $this->tpl->setVariable("OBJ_ROW_DESCRIPTION",$tmp_obj->getDescription());
1324  $this->tpl->parseCurrentBlock();
1325 
1326  unset($tmp_obj);
1327  }
1328  $this->tpl->setCurrentBlock("OBJ_SELECT");
1329  $this->tpl->setVariable("OBJ_SELECT_TITLE",$this->lng->txt("title"));
1330  $this->tpl->setVariable("OBJ_SELECT_DESCRIPTION",$this->lng->txt("description"));
1331 
1332  $this->tpl->setVariable("OBJ_BTN1_VALUE",$this->lng->txt("select"));
1333  $this->tpl->setVariable("OBJ_BTN2_VALUE",$this->lng->txt("cancel"));
1334  $this->tpl->parseCurrentBlock();
1335  }
1336 
1341  {
1342  global $ilCtrl;
1343 
1344  $this->checkPermission("write");
1345 
1346  if(!count($_POST["member"]))
1347  {
1348  ilUtil::sendFailure($this->lng->txt("no_checkbox"),true);
1349  }
1350  else
1351  {
1352  // team upload?
1353  if($this->ass->getType() == ilExAssignment::TYPE_UPLOAD_TEAM)
1354  {
1355  $members = array();
1356  foreach($_POST["member"] as $user_id => $value)
1357  {
1358  $tmembers = ilExAssignment::getTeamMembersByAssignmentId($this->ass->getId(), $user_id);
1359  foreach($tmembers as $tuser_id)
1360  {
1361  $members[$tuser_id] = 1;
1362  }
1363  }
1364  }
1365  else
1366  {
1367  $members = $_POST["member"];
1368  }
1369 
1370  $this->object->sendAssignment($this->object->getId(),
1371  (int) $_GET["ass_id"], $members);
1372 
1373  ilUtil::sendSuccess($this->lng->txt("exc_sent"),true);
1374  }
1375  $ilCtrl->redirect($this, "members");
1376  }
1377 
1382  {
1383  global $ilCtrl, $tpl, $lng, $ilTabs;
1384 
1385  $this->checkPermission("write");
1386  $ilTabs->activateTab("grades");
1387 
1388  if (!is_array($_POST["member"]) || count($_POST["member"]) == 0)
1389  {
1390  ilUtil::sendFailure($lng->txt("no_checkbox"), true);
1391  $ilCtrl->redirect($this, "members");
1392  }
1393  else
1394  {
1395  include_once("./Services/Utilities/classes/class.ilConfirmationGUI.php");
1396  $cgui = new ilConfirmationGUI();
1397  $cgui->setFormAction($ilCtrl->getFormAction($this));
1398  $cgui->setHeaderText($lng->txt("exc_msg_sure_to_deassign_participant"));
1399  $cgui->setCancel($lng->txt("cancel"), "members");
1400  $cgui->setConfirm($lng->txt("remove"), "deassignMembers");
1401 
1402  // team upload?
1403  if($this->ass->getType() == ilExAssignment::TYPE_UPLOAD_TEAM)
1404  {
1405  $members = array();
1406  foreach($_POST["member"] as $user_id => $value)
1407  {
1408  $tmembers = ilExAssignment::getTeamMembersByAssignmentId($this->ass->getId(), $user_id);
1409  foreach($tmembers as $tuser_id)
1410  {
1411  $members[$tuser_id] = 1;
1412  }
1413  }
1414  }
1415  else
1416  {
1417  $members = $_POST["member"];
1418  }
1419 
1420  include_once("./Services/User/classes/class.ilUserUtil.php");
1421  foreach ($members as $k => $m)
1422  {
1423  $cgui->addItem("member[$k]", $m,
1424  ilUserUtil::getNamePresentation((int) $k, false, false, "", true));
1425  }
1426 
1427  $tpl->setContent($cgui->getHTML());
1428  }
1429  }
1430 
1435  {
1436  global $ilCtrl, $lng;
1437 
1438  $this->checkPermission("write");
1439 
1440  if(is_array($_POST["member"]))
1441  {
1442  foreach($_POST["member"] as $usr_id => $member)
1443  {
1444  $this->object->members_obj->deassignMember((int) $usr_id);
1445  }
1446  ilUtil::sendSuccess($lng->txt("exc_msg_participants_removed"), true);
1447  $ilCtrl->redirect($this, "members");
1448  }
1449  else
1450  {
1451  ilUtil::sendFailure($this->lng->txt("no_checkbox"),true);
1452  $ilCtrl->redirect($this, "members");
1453  }
1454  }
1455 
1457  {
1458  $this->checkPermission("write");
1459 
1460  if(!isset($_POST['comments_value']))
1461  {
1462  continue;
1463  }
1464 
1465  $this->object->members_obj->setNoticeForMember($_GET["member_id"],
1466  ilUtil::stripSlashes($_POST["comments_value"]));
1467  ilUtil::sendSuccess($this->lng->txt("exc_members_comments_saved"));
1468  $this->membersObject();
1469  }
1470 
1471 
1476  {
1477  $this->saveStatusObject(true);
1478  }
1479 
1480 
1484  function saveStatusObject($a_part_view = false)
1485  {
1486  global $ilCtrl;
1487 
1488  $this->checkPermission("write");
1489 
1490  include_once("./Modules/Exercise/classes/class.ilExAssignment.php");
1491 
1492 // include_once 'Services/Tracking/classes/class.ilLPMarks.php';
1493 
1494  $saved_for = array();
1495 
1496  foreach($_POST["id"] as $key => $value)
1497  {
1498  if (!$a_part_view)
1499  {
1500  if (count($_POST["member"]) > 0 && $_POST["member"][$key] != "1")
1501  {
1502  continue;
1503  }
1504  else
1505  {
1506  if (count($_POST["member"]) > 0)
1507  {
1508  $uname = ilObjUser::_lookupName($key);
1509  $saved_for[] = $uname["lastname"].", ".$uname["firstname"];
1510  }
1511  }
1512  }
1513  if (!$a_part_view)
1514  {
1515  $ass_id = (int) $_GET["ass_id"];
1516  $user_id = (int) $key;
1517  }
1518  else
1519  {
1520  $ass_id = (int) $key;
1521  $user_id = (int) $_GET["part_id"];
1522  }
1523 
1524  // team upload?
1525  if(is_object($this->ass) and $this->ass->getType() == ilExAssignment::TYPE_UPLOAD_TEAM)
1526  {
1527  $team_id = $this->ass->getTeamId($user_id);
1528  $user_ids = $this->ass->getTeamMembers($team_id);
1529 
1530  if (count($_POST["member"]) > 0)
1531  {
1532  foreach($user_ids as $user_id)
1533  {
1534  if($user_id != $key)
1535  {
1536  $uname = ilObjUser::_lookupName($user_id);
1537  $saved_for[] = $uname["lastname"].", ".$uname["firstname"];
1538  }
1539  }
1540  }
1541  }
1542  else
1543  {
1544  $user_ids = array($user_id);
1545  }
1546 
1547  foreach($user_ids as $user_id)
1548  {
1549  ilExAssignment::updateStatusOfUser($ass_id, $user_id,
1550  ilUtil::stripSlashes($_POST["status"][$key]));
1551  ilExAssignment::updateNoticeForUser($ass_id, $user_id,
1552  ilUtil::stripSlashes($_POST["notice"][$key]));
1553 
1554  if (ilUtil::stripSlashes($_POST['mark'][$key]) !=
1555  ilExAssignment::lookupMarkOfUser($ass_id, $user_id))
1556  {
1557  ilExAssignment::updateStatusTimeOfUser($ass_id, $user_id);
1558  }
1559 
1560  ilExAssignment::updateMarkOfUser($ass_id, $user_id,
1561  ilUtil::stripSlashes($_POST['mark'][$key]));
1562  ilExAssignment::updateCommentForUser($ass_id, $user_id,
1563  ilUtil::stripSlashes($_POST['lcomment'][$key]));
1564  }
1565  }
1566 
1567  if (count($saved_for) > 0)
1568  {
1569  $save_for_str = "(".implode($saved_for, " - ").")";
1570  }
1571  ilUtil::sendSuccess($this->lng->txt("exc_status_saved")." ".$save_for_str,true);
1572  if (!$a_part_view)
1573  {
1574  $ilCtrl->redirect($this, "members");
1575  }
1576  else
1577  {
1578  $ilCtrl->redirect($this, "showParticipant");
1579  }
1580  }
1581 
1582  function __getDateSelect($a_type,$a_selected)
1583  {
1584  switch($a_type)
1585  {
1586  case "hour":
1587  for($i=0; $i<24; $i++)
1588  {
1589  $hours[$i] = $i < 10 ? "0".$i : $i;
1590  }
1591  return ilUtil::formSelect($a_selected,"d_hour",$hours,false,true);
1592 
1593  case "minutes":
1594  for($i=0;$i<60;$i++)
1595  {
1596  $minutes[$i] = $i < 10 ? "0".$i : $i;
1597  }
1598  return ilUtil::formSelect($a_selected,"d_minutes",$minutes,false,true);
1599 
1600  case "day":
1601  for($i=1; $i<32; $i++)
1602  {
1603  $days[$i] = $i < 10 ? "0".$i : $i;
1604  }
1605  return ilUtil::formSelect($a_selected,"d_day",$days,false,true);
1606 
1607  case "month":
1608  for($i=1; $i<13; $i++)
1609  {
1610  $month[$i] = $i < 10 ? "0".$i : $i;
1611  }
1612  return ilUtil::formSelect($a_selected,"d_month",$month,false,true);
1613 
1614  case "year":
1615  for($i = date("Y",time());$i < date("Y",time()) + 3;++$i)
1616  {
1617  $year[$i] = $i;
1618  }
1619  return ilUtil::formSelect($a_selected,"d_year",$year,false,true);
1620  }
1621  }
1622 
1623  function __filterAssignedUsers($a_result)
1624  {
1625  foreach($a_result as $user)
1626  {
1627  if(!$this->object->members_obj->isAssigned($user["id"]))
1628  {
1629  $filtered[] = $user;
1630  }
1631  }
1632 
1633  return $filtered ? $filtered : array();
1634  }
1635 
1641  function addSubmissionSubTabs($a_activate)
1642  {
1643  global $ilTabs, $lng, $ilCtrl;
1644 
1645  $ilTabs->addSubTab("assignment", $lng->txt("exc_assignment_view"),
1646  $ilCtrl->getLinkTarget($this, "members"));
1647  $ilTabs->addSubTab("participant", $lng->txt("exc_participant_view"),
1648  $ilCtrl->getLinkTarget($this, "showParticipant"));
1649  $ilTabs->addSubTab("grades", $lng->txt("exc_grades_overview"),
1650  $ilCtrl->getLinkTarget($this, "showGradesOverview"));
1651  $ilTabs->activateSubTab($a_activate);
1652  }
1653 
1659  function addContentSubTabs($a_activate)
1660  {
1661  global $ilTabs, $lng, $ilCtrl, $ilAccess;
1662 
1663  $ilTabs->addSubTab("content", $lng->txt("view"),
1664  $ilCtrl->getLinkTarget($this, "showOverview"));
1665  if ($ilAccess->checkAccess("write", "", $this->ref_id))
1666  {
1667  $ilTabs->addSubTab("list_assignments", $lng->txt("edit"),
1668  $ilCtrl->getLinkTarget($this, "listAssignments"));
1669  }
1670  $ilTabs->activateSubTab($a_activate);
1671  }
1672 
1673 
1679  function getTabs($tabs_gui)
1680  {
1681  global $ilAccess, $ilUser, $lng, $ilHelp;
1682 
1683  $ilHelp->setScreenIdComponent("exc");
1684 
1685  if ($ilAccess->checkAccess("read", "", $this->object->getRefId()))
1686  {
1687  $tabs_gui->addTab("content",
1688  $lng->txt("exc_assignments"),
1689  $this->ctrl->getLinkTarget($this, "showOverview"));
1690  }
1691 
1692  $next_class = strtolower($this->ctrl->getNextClass());
1693  if ($ilAccess->checkAccess("visible", "", $this->object->getRefId()))
1694  {
1695  $tabs_gui->addTab("info",
1696  $lng->txt("info_short"),
1697  $this->ctrl->getLinkTargetByClass("ilinfoscreengui", "showSummary"));
1698  }
1699 
1700  // edit properties
1701  if ($ilAccess->checkAccess("write", "", $this->ref_id))
1702  {
1703  /*$tabs_gui->addTab("assignments",
1704  $lng->txt("exc_edit_assignments"),
1705  $this->ctrl->getLinkTarget($this, 'listAssignments'));*/
1706 
1707  $tabs_gui->addTab("settings",
1708  $lng->txt("settings"),
1709  $this->ctrl->getLinkTarget($this, 'edit'));
1710 
1711  $tabs_gui->addTab("grades",
1712  $lng->txt("exc_submissions_and_grades"),
1713  $this->ctrl->getLinkTarget($this, 'members'));
1714  }
1715 
1716  // learning progress
1717  $save_sort_order = $_GET["sort_order"]; // hack, because exercise sort parameters
1718  $save_sort_by = $_GET["sort_by"]; // must not be forwarded to learning progress
1719  $save_offset = $_GET["offset"];
1720  $_GET["offset"] = $_GET["sort_by"] = $_GET["sort_order"] = "";
1721 
1722  include_once './Services/Tracking/classes/class.ilLearningProgressAccess.php';
1723  if(ilLearningProgressAccess::checkAccess($this->object->getRefId()))
1724  {
1725  $tabs_gui->addTab('learning_progress',
1726  $lng->txt('learning_progress'),
1727  $this->ctrl->getLinkTargetByClass(array('ilobjexercisegui','illearningprogressgui'),''));
1728  }
1729 
1730  $_GET["sort_order"] = $save_sort_order; // hack, part ii
1731  $_GET["sort_by"] = $save_sort_by;
1732  $_GET["offset"] = $save_offset;
1733 
1734  // export
1735  if ($ilAccess->checkAccess("write", "", $this->object->getRefId()))
1736  {
1737  $tabs_gui->addTab("export",
1738  $lng->txt("export"),
1739  $this->ctrl->getLinkTargetByClass("ilexportgui", ""));
1740  }
1741 
1742 
1743  // permissions
1744  if ($ilAccess->checkAccess("edit_permission", "", $this->ref_id))
1745  {
1746  $tabs_gui->addTab('permissions',
1747  $lng->txt("perm_settings"),
1748  $this->ctrl->getLinkTargetByClass(array(get_class($this),'ilpermissiongui'), "perm"));
1749  }
1750  }
1751 
1757  function infoScreenObject()
1758  {
1759  $this->ctrl->setCmd("showSummary");
1760  $this->ctrl->setCmdClass("ilinfoscreengui");
1761  $this->infoScreen();
1762  }
1763 
1767  function infoScreen()
1768  {
1769  global $ilAccess, $ilUser, $ilTabs, $lng;
1770 
1771  $ilTabs->activateTab("info");
1772 
1773  $this->checkPermission("visible");
1774 
1775  include_once("./Services/InfoScreen/classes/class.ilInfoScreenGUI.php");
1776  $info = new ilInfoScreenGUI($this);
1777 
1778  $info->enablePrivateNotes();
1779 
1780  $info->enableNews();
1781  if ($ilAccess->checkAccess("write", "", $_GET["ref_id"]))
1782  {
1783  $info->enableNewsEditing();
1784  $info->setBlockProperty("news", "settings", true);
1785  }
1786 
1787  // standard meta data
1788  //$info->addMetaDataSections($this->object->getId(),0, $this->object->getType());
1789 
1790  // instructions
1791  $info->addSection($this->lng->txt("exc_overview"));
1792  include_once("./Modules/Exercise/classes/class.ilExAssignment.php");
1793  $ass = ilExAssignment::getAssignmentDataOfExercise($this->object->getId());
1794  $cnt = 0;
1795  $mcnt = 0;
1796  foreach ($ass as $a)
1797  {
1798  $cnt++;
1799  if ($a["mandatory"])
1800  {
1801  $mcnt++;
1802  }
1803  }
1804  $info->addProperty($lng->txt("exc_assignments"), $cnt);
1805  $info->addProperty($lng->txt("exc_mandatory"), $mcnt);
1806  if ($this->object->getPassMode() != "nr")
1807  {
1808  $info->addProperty($lng->txt("exc_pass_mode"),
1809  $lng->txt("exc_msg_all_mandatory_ass"));
1810  }
1811  else
1812  {
1813  $info->addProperty($lng->txt("exc_pass_mode"),
1814  sprintf($lng->txt("exc_msg_min_number_ass"), $this->object->getPassNr()));
1815  }
1816 
1817  // feedback from tutor
1818  include_once("Services/Tracking/classes/class.ilLPMarks.php");
1819  if ($ilAccess->checkAccess("read", "", $this->ref_id))
1820  {
1821  $lpcomment = ilLPMarks::_lookupComment($ilUser->getId(), $this->object->getId());
1822  $mark = ilLPMarks::_lookupMark($ilUser->getId(), $this->object->getId());
1823  //$status = ilExerciseMembers::_lookupStatus($this->object->getId(), $ilUser->getId());
1824  $st = $this->object->determinStatusOfUser($ilUser->getId());
1825  $status = $st["overall_status"];
1826  if ($lpcomment != "" || $mark != "" || $status != "notgraded")
1827  {
1828  $info->addSection($this->lng->txt("exc_feedback_from_tutor"));
1829  if ($lpcomment != "")
1830  {
1831  $info->addProperty($this->lng->txt("exc_comment"),
1832  $lpcomment);
1833  }
1834  if ($mark != "")
1835  {
1836  $info->addProperty($this->lng->txt("exc_mark"),
1837  $mark);
1838  }
1839 
1840  //if ($status == "")
1841  //{
1842  // $info->addProperty($this->lng->txt("status"),
1843  // $this->lng->txt("message_no_delivered_files"));
1844  //}
1845  //else
1846  if ($status != "notgraded")
1847  {
1848  $img = '<img border="0" src="'.ilUtil::getImagePath("scorm/".$status.".png").'" '.
1849  ' alt="'.$lng->txt("exc_".$status).'" title="'.$lng->txt("exc_".$status).
1850  '" style="vertical-align:middle;"/>';
1851 
1852  $add = "";
1853  if ($st["failed_a_mandatory"])
1854  {
1855  $add = " (".$lng->txt("exc_msg_failed_mandatory").")";
1856  }
1857  else if ($status == "failed")
1858  {
1859  $add = " (".$lng->txt("exc_msg_missed_minimum_number").")";
1860  }
1861  $info->addProperty($this->lng->txt("status"),
1862  $img." ".$this->lng->txt("exc_".$status).$add);
1863  }
1864  }
1865  }
1866 
1867  // forward the command
1868  $this->ctrl->forwardCommand($info);
1869  }
1870 
1871  function editObject()
1872  {
1873  $this->setSettingsSubTabs();
1874  $this->tabs_gui->activateSubTab("edit");
1875  return parent::editObject();
1876  }
1877 
1878  protected function setSettingsSubTabs()
1879  {
1880  $this->tabs_gui->addSubTab("edit",
1881  $this->lng->txt("general_settings"),
1882  $this->ctrl->getLinkTarget($this, "edit"));
1883 
1884  include_once "Services/Certificate/classes/class.ilCertificate.php";
1886  {
1887  $this->tabs_gui->addSubTab("certificate",
1888  $this->lng->txt("certificate"),
1889  $this->ctrl->getLinkTarget($this, "certificate"));
1890  }
1891  }
1892 
1898  function _goto($a_target)
1899  {
1900  global $rbacsystem, $ilErr, $lng, $ilAccess;
1901 
1902  if ($ilAccess->checkAccess("read", "", $a_target))
1903  {
1904  $_GET["ref_id"] = $a_target;
1905  $_GET["cmd"] = "showOverview";
1906  $_GET["baseClass"] = "ilExerciseHandlerGUI";
1907  include("ilias.php");
1908  exit;
1909  }
1910  else if ($ilAccess->checkAccess("visible", "", $a_target))
1911  {
1912  $_GET["ref_id"] = $a_target;
1913  $_GET["cmd"] = "infoScreen";
1914  $_GET["baseClass"] = "ilExerciseHandlerGUI";
1915  include("ilias.php");
1916  exit;
1917  }
1918  else if ($ilAccess->checkAccess("read", "", ROOT_FOLDER_ID))
1919  {
1920  ilUtil::sendFailure(sprintf($lng->txt("msg_no_perm_read_item"),
1921  ilObject::_lookupTitle(ilObject::_lookupObjId($a_target))), true);
1923  }
1924 
1925  $ilErr->raiseError($lng->txt("msg_no_perm_read"), $ilErr->FATAL);
1926  }
1927 
1931  function addLocatorItems()
1932  {
1933  global $ilLocator;
1934 
1935  if (is_object($this->object))
1936  {
1937  $ilLocator->addItem($this->object->getTitle(), $this->ctrl->getLinkTarget($this, "infoScreen"), "", $_GET["ref_id"]);
1938  }
1939  }
1940 
1944 
1949  {
1950  global $tpl, $ilTabs, $ilToolbar, $lng, $ilCtrl;
1951 
1952  $this->checkPermission("write");
1953 
1954  $ilTabs->activateTab("content");
1955  $this->addContentSubTabs("list_assignments");
1956 
1957  $ilToolbar->addButton($lng->txt("exc_add_assignment"),
1958  $ilCtrl->getLinkTarget($this, "addAssignment"));
1959 
1960  include_once("./Modules/Exercise/classes/class.ilAssignmentsTableGUI.php");
1961  $t = new ilAssignmentsTableGUI($this, "listAssignments", $this->object);
1962  $tpl->setContent($t->getHTML());
1963  }
1964 
1969  {
1970  global $tpl, $ilTabs;
1971 
1972  $this->checkPermission("write");
1973 
1974  $ilTabs->activateTab("content");
1975  $this->addContentSubTabs("list_assignments");
1976 
1977  $this->initAssignmentForm("create");
1978  $tpl->setContent($this->form->getHTML());
1979  }
1980 
1986  public function initAssignmentForm($a_mode = "create")
1987  {
1988  global $lng, $ilCtrl, $ilSetting;
1989 
1990  // init form
1991  $lng->loadLanguageModule("form");
1992  include_once("./Services/Form/classes/class.ilPropertyFormGUI.php");
1993  $this->form = new ilPropertyFormGUI();
1994  $this->form->setTableWidth("600px");
1995  if ($a_mode == "edit")
1996  {
1997  $this->form->setTitle($lng->txt("exc_edit_assignment"));
1998  }
1999  else
2000  {
2001  $this->form->setTitle($lng->txt("exc_new_assignment"));
2002  }
2003  $this->form->setFormAction($ilCtrl->getFormAction($this));
2004 
2005  // type
2006  include_once("./Modules/Exercise/classes/class.ilExAssignment.php");
2007  $types = array(ilExAssignment::TYPE_UPLOAD => $this->lng->txt("exc_type_upload"),
2008  ilExAssignment::TYPE_UPLOAD_TEAM => $this->lng->txt("exc_type_upload_team"));
2009  if(!$ilSetting->get('disable_wsp_blogs'))
2010  {
2011  $types[ilExAssignment::TYPE_BLOG] = $this->lng->txt("exc_type_blog");
2012  }
2013  if($ilSetting->get('user_portfolios'))
2014  {
2015  $types[ilExAssignment::TYPE_PORTFOLIO] = $this->lng->txt("exc_type_portfolio");
2016  }
2017  if(sizeof($types) > 1)
2018  {
2019  $ty = new ilSelectInputGUI($this->lng->txt("type"), "type");
2020  $ty->setOptions($types);
2021  $ty->setRequired(true);
2022  }
2023  else
2024  {
2025  $ty = new ilHiddenInputGUI("type");
2026  $ty->setValue(ilExAssignment::TYPE_UPLOAD);
2027  }
2028  $this->form->addItem($ty);
2029 
2030  // title
2031  $ti = new ilTextInputGUI($this->lng->txt("title"), "title");
2032  $ti->setMaxLength(200);
2033  $ti->setRequired(true);
2034  $this->form->addItem($ti);
2035 
2036  // start time y/n
2037  $cb = new ilCheckboxInputGUI($this->lng->txt("exc_start_time"), "start_time_cb");
2038  $this->form->addItem($cb);
2039 
2040  // start time
2041  $edit_date = new ilDateTimeInputGUI("", "start_time");
2042  $edit_date->setShowTime(true);
2043  $cb->addSubItem($edit_date);
2044 
2045 
2046  // deadline y/n
2047  $dcb = new ilCheckboxInputGUI($this->lng->txt("exc_deadline"), "deadline_cb");
2048  $dcb->setChecked(true);
2049  $this->form->addItem($dcb);
2050 
2051  // Deadline
2052  $edit_date = new ilDateTimeInputGUI($lng->txt(""), "deadline");
2053  $edit_date->setShowTime(true);
2054  $dcb->addSubItem($edit_date);
2055 
2056  // mandatory
2057  $cb = new ilCheckboxInputGUI($this->lng->txt("exc_mandatory"), "mandatory");
2058  $cb->setInfo($this->lng->txt("exc_mandatory_info"));
2059  $cb->setChecked(true);
2060  $this->form->addItem($cb);
2061 
2062  // Work Instructions
2063  $desc_input = new ilTextAreaInputGUI($lng->txt("exc_instruction"), "instruction");
2064  $desc_input->setRows(5);
2065  $this->form->addItem($desc_input);
2066 
2067  // files
2068  if ($a_mode == "create")
2069  {
2070  $files = new ilFileWizardInputGUI($this->lng->txt('objs_file'),'files');
2071  $files->setFilenames(array(0 => ''));
2072  $this->form->addItem($files);
2073  }
2074 
2075  // save and cancel commands
2076  if ($a_mode == "create")
2077  {
2078  $this->form->addCommandButton("saveAssignment", $lng->txt("save"));
2079  $this->form->addCommandButton("listAssignments", $lng->txt("cancel"));
2080  }
2081  else
2082  {
2083  $this->form->addCommandButton("updateAssignment", $lng->txt("save"));
2084  $this->form->addCommandButton("listAssignments", $lng->txt("cancel"));
2085  }
2086  }
2087 
2092  public function saveAssignmentObject()
2093  {
2094  global $tpl, $lng, $ilCtrl, $ilTabs;
2095 
2096  $this->checkPermission("write");
2097 
2098  $ilTabs->activateTab("content");
2099  $this->addContentSubTabs("list_assignments");
2100 
2101  $this->initAssignmentForm("create");
2102  if ($this->form->checkInput())
2103  {
2104  include_once("./Modules/Exercise/classes/class.ilExAssignment.php");
2105 
2106  // additional checks
2107  if ($_POST["start_time_cb"] && $_POST["deadline_cb"])
2108  {
2109  // check whether start date is before end date
2110  $start_date =
2111  $this->form->getItemByPostVar("start_time")->getDate();
2112  $end_date =
2113  $this->form->getItemByPostVar("deadline")->getDate();
2114  if ($start_date->get(IL_CAL_UNIX) >=
2115  $end_date->get(IL_CAL_UNIX))
2116  {
2117  ilUtil::sendFailure($lng->txt("form_input_not_valid"), true);
2118  $this->form->getItemByPostVar("start_time")
2119  ->setAlert($lng->txt("exc_start_date_should_be_before_end_date"));
2120  $this->form->getItemByPostVar("deadline")
2121  ->setAlert($lng->txt("exc_start_date_should_be_before_end_date"));
2122  $this->form->setValuesByPost();
2123  $tpl->setContent($this->form->getHtml());
2124  return;
2125  }
2126  }
2127 
2128  $ass = new ilExAssignment();
2129  $ass->setTitle($_POST["title"]);
2130  $ass->setInstruction($_POST["instruction"]);
2131  $ass->setExerciseId($this->object->getId());
2132  $ass->setMandatory($_POST["mandatory"]);
2133  $ass->setType($_POST["type"]);
2134 
2135  if ($_POST["start_time_cb"])
2136  {
2137  $date =
2138  $this->form->getItemByPostVar("start_time")->getDate();
2139  $ass->setStartTime($date->get(IL_CAL_UNIX));
2140  }
2141  else
2142  {
2143  $ass->setStartTime(null);
2144  }
2145 
2146  // deadline
2147  if ($_POST["deadline_cb"])
2148  {
2149  $date =
2150  $this->form->getItemByPostVar("deadline")->getDate();
2151  $ass->setDeadline($date->get(IL_CAL_UNIX));
2152  }
2153  else
2154  {
2155  $ass->setDeadline(null);
2156  }
2157 
2158  $ass->save();
2159 
2160  // save files
2161  $ass->uploadAssignmentFiles($_FILES["files"]);
2162 
2163 
2164  ilUtil::sendSuccess($lng->txt("msg_obj_modified"), true);
2165  $ilCtrl->redirect($this, "listAssignments");
2166  }
2167  else
2168  {
2169  $this->form->setValuesByPost();
2170  $tpl->setContent($this->form->getHtml());
2171  }
2172  }
2173 
2178  {
2179  global $tpl, $ilTabs, $tpl;
2180 
2181  $this->checkPermission("write");
2182 
2183  $this->setAssignmentHeader();
2184  $ilTabs->activateTab("ass_settings");
2185 
2186  $this->initAssignmentForm("edit");
2187  $this->getAssignmentValues();
2188  $tpl->setContent($this->form->getHTML());
2189  }
2190 
2195  public function getAssignmentValues()
2196  {
2197  $values = array();
2198 
2199  $ass = new ilExAssignment($_GET["ass_id"]);
2200  $values["title"] = $ass->getTitle();
2201  if ($ass->getStartTime() > 0)
2202  {
2203  $values["start_time_cb"] = true;
2204  }
2205  $values["mandatory"] = $ass->getMandatory();
2206  $values["instruction"] = $ass->getInstruction();
2207  $values["type"] = $ass->getType();
2208  if ($ass->getDeadline() > 0)
2209  {
2210  $values["deadline_cb"] = true;
2211  }
2212  $this->form->setValuesByArray($values);
2213 
2214  if ($ass->getDeadline() > 0)
2215  {
2216  $edit_date = new ilDateTime($ass->getDeadline(), IL_CAL_UNIX);
2217  $ed_item = $this->form->getItemByPostVar("deadline");
2218  $ed_item->setDate($edit_date);
2219  }
2220 
2221  if ($ass->getStartTime() > 0)
2222  {
2223  $edit_date = new ilDateTime($ass->getStartTime(), IL_CAL_UNIX);
2224  $ed_item = $this->form->getItemByPostVar("start_time");
2225  $ed_item->setDate($edit_date);
2226  }
2227 
2228  // if there are any submissions we cannot change type anymore
2229  if(sizeof(ilExAssignment::getAllDeliveredFiles($this->object->getId(), $ass->getId())))
2230  {
2231  $this->form->getItemByPostVar("type")->setDisabled(true);
2232  }
2233 
2234  }
2235 
2240  public function updateAssignmentObject()
2241  {
2242  global $tpl, $lng, $ilCtrl, $ilTabs;
2243 
2244  $this->checkPermission("write");
2245 
2246  $ilTabs->activateTab("content");
2247  $this->addContentSubTabs("list_assignments");
2248 
2249  $this->initAssignmentForm("edit");
2250  if ($this->form->checkInput())
2251  {
2252  include_once("./Modules/Exercise/classes/class.ilExAssignment.php");
2253 
2254  // additional checks
2255  if ($_POST["start_time_cb"] && $_POST["deadline_cb"])
2256  {
2257  // check whether start date is before end date
2258  $start_date =
2259  $this->form->getItemByPostVar("start_time")->getDate();
2260  $end_date =
2261  $this->form->getItemByPostVar("deadline")->getDate();
2262  if ($start_date->get(IL_CAL_UNIX) >=
2263  $end_date->get(IL_CAL_UNIX))
2264  {
2265  ilUtil::sendFailure($lng->txt("form_input_not_valid"), true);
2266  $this->form->getItemByPostVar("start_time")
2267  ->setAlert($lng->txt("exc_start_date_should_be_before_end_date"));
2268  $this->form->getItemByPostVar("deadline")
2269  ->setAlert($lng->txt("exc_start_date_should_be_before_end_date"));
2270  $this->form->setValuesByPost();
2271  $tpl->setContent($this->form->getHtml());
2272  return;
2273  }
2274  }
2275 
2276 
2277  $ass = new ilExAssignment($_GET["ass_id"]);
2278  $ass->setTitle($_POST["title"]);
2279  $ass->setInstruction($_POST["instruction"]);
2280  $ass->setExerciseId($this->object->getId());
2281  $ass->setMandatory($_POST["mandatory"]);
2282  $ass->setType($_POST["type"]);
2283 
2284  if ($_POST["start_time_cb"])
2285  {
2286  $date =
2287  $this->form->getItemByPostVar("start_time")->getDate();
2288  $ass->setStartTime($date->get(IL_CAL_UNIX));
2289  }
2290  else
2291  {
2292  $ass->setStartTime(null);
2293  }
2294 
2295  // deadline
2296  if ($_POST["deadline_cb"])
2297  {
2298  $date =
2299  $this->form->getItemByPostVar("deadline")->getDate();
2300  $ass->setDeadline($date->get(IL_CAL_UNIX));
2301  }
2302  else
2303  {
2304  $ass->setDeadline(null);
2305  }
2306 
2307  $ass->update();
2308  ilUtil::sendSuccess($lng->txt("msg_obj_modified"), true);
2309  $ilCtrl->redirect($this, "listAssignments");
2310  }
2311  else
2312  {
2313  $this->form->setValuesByPost();
2314  $tpl->setContent($this->form->getHtml());
2315  }
2316  }
2317 
2318 
2323  {
2324  global $ilCtrl, $tpl, $lng, $ilTabs;
2325 
2326  $this->checkPermission("write");
2327 
2328  $ilTabs->activateTab("content");
2329  $this->addContentSubTabs("list_assignments");
2330 
2331  if (!is_array($_POST["id"]) || count($_POST["id"]) == 0)
2332  {
2333  ilUtil::sendInfo($lng->txt("no_checkbox"), true);
2334  $ilCtrl->redirect($this, "listAssignments");
2335  }
2336  else
2337  {
2338  include_once("./Services/Utilities/classes/class.ilConfirmationGUI.php");
2339  $cgui = new ilConfirmationGUI();
2340  $cgui->setFormAction($ilCtrl->getFormAction($this));
2341  $cgui->setHeaderText($lng->txt("exc_conf_del_assignments"));
2342  $cgui->setCancel($lng->txt("cancel"), "listAssignments");
2343  $cgui->setConfirm($lng->txt("delete"), "deleteAssignments");
2344 
2345  include_once("./Modules/Exercise/classes/class.ilExAssignment.php");
2346 
2347  foreach ($_POST["id"] as $i)
2348  {
2349  $cgui->addItem("id[]", $i, ilExAssignment::lookupTitle($i));
2350  }
2351 
2352  $tpl->setContent($cgui->getHTML());
2353  }
2354  }
2355 
2360  {
2361  global $ilDB, $ilCtrl, $lng;
2362 
2363  $this->checkPermission("write");
2364 
2365  $delete = false;
2366  if (is_array($_POST["id"]))
2367  {
2368  include_once("./Modules/Exercise/classes/class.ilExAssignment.php");
2369  foreach($_POST["id"] as $id)
2370  {
2371  $ass = new ilExAssignment(ilUtil::stripSlashes($id));
2372  $ass->delete();
2373  $delete = true;
2374  }
2375  }
2376 
2377  if ($delete)
2378  {
2379  ilUtil::sendSuccess($lng->txt("exc_assignments_deleted"), true);
2380  }
2381  $ilCtrl->redirect($this, "listAssignments");
2382  }
2383 
2388  {
2389  global $lng, $ilCtrl;
2390 
2391  $this->checkPermission("write");
2392 
2393  include_once("./Modules/Exercise/classes/class.ilExAssignment.php");
2394  ilExAssignment::saveAssOrderOfExercise($this->object->getId(), $_POST["order"]);
2395 
2396  ilUtil::sendSuccess($lng->txt("exc_saved_order"), true);
2397  $ilCtrl->redirect($this, "listAssignments");
2398  }
2399 
2404  {
2405  global $lng, $ilCtrl;
2406 
2407  $this->checkPermission("write");
2408 
2409  include_once("./Modules/Exercise/classes/class.ilExAssignment.php");
2410  ilExAssignment::orderAssByDeadline($this->object->getId());
2411 
2412  ilUtil::sendSuccess($lng->txt("exc_saved_order"), true);
2413  $ilCtrl->redirect($this, "listAssignments");
2414  }
2415 
2420  {
2421  global $ilTabs, $lng, $ilCtrl, $tpl, $ilHelp;
2422 
2423  include_once("./Modules/Exercise/classes/class.ilExAssignment.php");
2424  $tpl->setTitle(ilExAssignment::lookupTitle($_GET["ass_id"]));
2425  $tpl->setDescription("");
2426 
2427  $ilTabs->clearTargets();
2428  $ilHelp->setScreenIdComponent("exc");
2429 
2430  $ilTabs->setBackTarget($lng->txt("back"),
2431  $ilCtrl->getLinkTarget($this, "listAssignments"));
2432 
2433  $ilTabs->addTab("ass_settings",
2434  $lng->txt("settings"),
2435  $ilCtrl->getLinkTarget($this, "editAssignment"));
2436 
2437  $ilTabs->addTab("ass_files",
2438  $lng->txt("files"),
2439  $ilCtrl->getLinkTargetByClass("ilfilesystemgui", "listFiles"));
2440 
2441  }
2442 
2443 
2447 
2452  {
2453  global $tpl, $ilTabs, $ilUser, $ilToolbar;
2454 
2455  $this->checkPermission("read");
2456 
2457  include_once("./Services/Tracking/classes/class.ilLearningProgress.php");
2458  ilLearningProgress::_tracProgress($ilUser->getId(),$this->object->getId(),
2459  $this->object->getRefId(), 'exc');
2460 
2461  $ilTabs->activateTab("content");
2462  $this->addContentSubTabs("content");
2463 
2464  // show certificate?
2465  if($this->object->hasUserCertificate($ilUser->getId()))
2466  {
2467  include_once "./Modules/Exercise/classes/class.ilExerciseCertificateAdapter.php";
2468  include_once "./Services/Certificate/classes/class.ilCertificate.php";
2469  $adapter = new ilExerciseCertificateAdapter($this->object);
2470  if(ilCertificate::_isComplete($adapter))
2471  {
2472  $ilToolbar->addButton($this->lng->txt("certificate"),
2473  $this->ctrl->getLinkTarget($this, "outCertificate"));
2474  }
2475  }
2476 
2477  include_once("./Modules/Exercise/classes/class.ilExAssignment.php");
2478  include_once("./Services/Accordion/classes/class.ilAccordionGUI.php");
2479  $acc = new ilAccordionGUI();
2480  $acc->setId("exc_ow_".$this->object->getId());
2481  $ass_data = ilExAssignment::getAssignmentDataOfExercise($this->object->getId());
2482  include_once("./Modules/Exercise/classes/class.ilExAssignmentGUI.php");
2483  $ass_gui = new ilExAssignmentGUI($this->object);
2484 
2485  foreach ($ass_data as $ass)
2486  {
2487  $acc->addItem($ass_gui->getOverviewHeader($ass),
2488  $ass_gui->getOverviewBody($ass));
2489  }
2490 
2491  if (count($ass_data) < 2)
2492  {
2493  $acc->setBehaviour("FirstOpen");
2494  }
2495  else
2496  {
2497  $acc->setBehaviour("OneOpenSession");
2498  }
2499 
2500 
2501  $tpl->setContent($acc->getHTML());
2502  }
2503 
2508  {
2509  global $tpl, $ilTabs;
2510 
2511  $this->checkPermission("read");
2512 
2513  $ilTabs->activateTab("content");
2514  $this->addContentSubTabs("content");
2515 
2516  include_once("./Modules/Exercise/classes/class.ilPublicSubmissionsTableGUI.php");
2517  $tab = new ilPublicSubmissionsTableGUI($this, "listPublicSubmissions",
2518  $this->object, (int) $_GET["ass_id"]);
2519  $tpl->setContent($tab->getHTML());
2520  }
2521 
2526  {
2527  $this->checkPermission("write");
2528  $this->object->exportGradesExcel();
2529  exit;
2530  }
2531 
2535  function saveGradesObject()
2536  {
2537  global $ilCtrl, $lng;
2538 
2539  $this->checkPermission("write");
2540  include_once 'Services/Tracking/classes/class.ilLPMarks.php';
2541 
2542  if (is_array($_POST["lcomment"]))
2543  {
2544  foreach ($_POST["lcomment"] as $k => $v)
2545  {
2546  $marks_obj = new ilLPMarks($this->object->getId(), (int) $k);
2547  $marks_obj->setComment(ilUtil::stripSlashes($v));
2548  $marks_obj->setMark(ilUtil::stripSlashes($_POST["mark"][$k]));
2549  $marks_obj->update();
2550  }
2551  }
2552  ilUtil::sendSuccess($lng->txt("exc_msg_saved_grades"), true);
2553  $ilCtrl->redirect($this, "showGradesOverview");
2554  }
2555 
2560  protected function sendNotifications($assignment_id)
2561  {
2562  include_once "./Services/Notification/classes/class.ilNotification.php";
2564 
2565  include_once "./Modules/Exercise/classes/class.ilExerciseMailNotification.php";
2566  $not = new ilExerciseMailNotification();
2568  $not->setAssignmentId($assignment_id);
2569  $not->setRefId($this->ref_id);
2570  $not->setRecipients($users);
2571  $not->send();
2572  }
2573 
2574  protected function createBlogObject()
2575  {
2576  global $ilUser;
2577 
2578  $this->checkPermission("read");
2579 
2580  // $this->tabs_gui->setBackTarget($this->lng->txt("back"), $this->ctrl->getLinkTarget($this, "showOverview"));
2581 
2582  $this->tabs_gui->setTabActive("content");
2583  $this->addContentSubTabs("content");
2584 
2585  if (mktime() > $this->ass->getDeadline() && ($this->ass->getDeadline() != 0))
2586  {
2587  ilUtil::sendInfo($this->lng->txt("exercise_time_over"));
2588  }
2589 
2590  $tpl = new ilTemplate("tpl.exc_select_resource.html", true, true, "Modules/Exercise");
2591  $tpl->setVariable("TXT_TITLE", $this->lng->txt("exc_create_blog").": ".$this->ass->getTitle());
2592  $tpl->setVariable("TREE", $this->renderWorkspaceExplorer("createBlog"));
2593  $tpl->setVariable("FORM_ACTION", $this->ctrl->getFormAction($this));
2594  $tpl->setVariable("TXT_SUBMIT", $this->lng->txt("save"));
2595  $tpl->setVariable("TXT_CANCEL", $this->lng->txt("cancel"));
2596  $tpl->setVariable("CMD_SUBMIT", "saveBlog");
2597  $tpl->setVariable("CMD_CANCEL", "showOverview");
2598 
2599  ilUtil::sendInfo($this->lng->txt("exc_create_blog_select_info"));
2600 
2601  $this->tpl->setContent($tpl->get());
2602  }
2603 
2604  protected function selectBlogObject()
2605  {
2606  global $ilUser;
2607 
2608  $this->checkPermission("read");
2609 
2610  $this->tabs_gui->clearTargets();
2611  $this->tabs_gui->setBackTarget($this->lng->txt("back"), $this->ctrl->getLinkTarget($this, "showOverview"));
2612 
2613  // $this->tabs_gui->setTabActive("content");
2614  // $this->addContentSubTabs("content");
2615 
2616  if (mktime() > $this->ass->getDeadline() && ($this->ass->getDeadline() != 0))
2617  {
2618  ilUtil::sendInfo($this->lng->txt("exercise_time_over"));
2619  }
2620 
2621  $tpl = new ilTemplate("tpl.exc_select_resource.html", true, true, "Modules/Exercise");
2622  $tpl->setVariable("TXT_TITLE", $this->lng->txt("exc_select_blog").": ".$this->ass->getTitle());
2623  $tpl->setVariable("TREE", $this->renderWorkspaceExplorer("selectBlog"));
2624  $tpl->setVariable("FORM_ACTION", $this->ctrl->getFormAction($this));
2625  $tpl->setVariable("TXT_SUBMIT", $this->lng->txt("save"));
2626  $tpl->setVariable("TXT_CANCEL", $this->lng->txt("cancel"));
2627  $tpl->setVariable("CMD_SUBMIT", "setSelectedBlog");
2628  $tpl->setVariable("CMD_CANCEL", "showOverview");
2629 
2630  ilUtil::sendInfo($this->lng->txt("exc_select_blog_info"));
2631 
2632  $this->tpl->setContent($tpl->get());
2633  }
2634 
2635  protected function saveBlogObject()
2636  {
2637  global $ilUser;
2638 
2639  if(!$_POST["node"])
2640  {
2641  ilUtil::sendFailure($this->lng->txt("select_one"));
2642  return $this->createBlogObject();
2643  }
2644 
2645  $parent_node = $_POST["node"];
2646 
2647  include_once "Modules/Blog/classes/class.ilObjBlog.php";
2648  include_once "Services/PersonalWorkspace/classes/class.ilWorkspaceTree.php";
2649  include_once "Services/PersonalWorkspace/classes/class.ilWorkspaceAccessHandler.php";
2650 
2651  $blog = new ilObjBlog();
2652  $blog->setTitle($this->object->getTitle()." - ".$this->ass->getTitle());
2653  $blog->create();
2654 
2655  $tree = new ilWorkspaceTree($ilUser->getId());
2656 
2657  $node_id = $tree->insertObject($parent_node, $blog->getId());
2658 
2659  $access_handler = new ilWorkspaceAccessHandler($tree);
2660  $access_handler->setPermissions($parent_node, $node_id);
2661 
2662  $this->object->addResourceObject($node_id, $this->ass->getId(), $ilUser->getId());
2663 
2664  ilUtil::sendSuccess($this->lng->txt("exc_blog_created"), true);
2665  $this->ctrl->redirect($this, "showOverview");
2666  }
2667 
2668  protected function setSelectedBlogObject()
2669  {
2670  global $ilUser;
2671 
2672  if($_POST["node"])
2673  {
2674  include_once "Services/PersonalWorkspace/classes/class.ilWorkspaceTree.php";
2675  $tree = new ilWorkspaceTree($ilUser->getId());
2676  $node = $tree->getNodeData($_POST["node"]);
2677  if($node && $node["type"] == "blog")
2678  {
2679  $this->removeExistingSubmissions();
2680  $this->object->addResourceObject($node["wsp_id"], $this->ass->getId(), $ilUser->getId());
2681 
2682  ilUtil::sendSuccess($this->lng->txt("exc_blog_selected"), true);
2683  $this->ctrl->setParameter($this, "blog_id", $node["wsp_id"]);
2684  $this->ctrl->redirect($this, "askDirectionSubmission");
2685  }
2686  }
2687 
2688  ilUtil::sendFailure($this->lng->txt("select_one"));
2689  return $this->selectPortfolioObject();
2690  }
2691 
2695  public function removeExistingSubmissions()
2696  {
2697  global $ilUser;
2698 
2699  $submitted = ilExAssignment::getDeliveredFiles($this->ass->getExerciseId(), $this->ass->getId(), $ilUser->getId());
2700  if($submitted)
2701  {
2702  $files = array();
2703  foreach($submitted as $item)
2704  {
2705  $files[] = $item["returned_id"];
2706  }
2707  ilExAssignment::deleteDeliveredFiles($this->ass->getExerciseId(), $this->ass->getId(), $files, $ilUser->getId());
2708  }
2709  }
2710 
2711  protected function askDirectionSubmissionObject()
2712  {
2713  global $tpl;
2714 
2715  $this->tabs_gui->setTabActive("content");
2716  $this->addContentSubTabs("content");
2717 
2718  include_once "Services/Utilities/classes/class.ilConfirmationGUI.php";
2719  $conf = new ilConfirmationGUI();
2720 
2721 
2722  if($_REQUEST["blog_id"])
2723  {
2724  $this->ctrl->setParameter($this, "blog_id", $_REQUEST["blog_id"]);
2725  $txt = $this->lng->txt("exc_direct_submit_blog");
2726  }
2727  else
2728  {
2729  $this->ctrl->setParameter($this, "prtf_id", $_REQUEST["prtf_id"]);
2730  $txt = $this->lng->txt("exc_direct_submit_portfolio");
2731  }
2732  $conf->setFormAction($this->ctrl->getFormAction($this, "directSubmit"));
2733 
2734  $conf->setHeaderText($txt);
2735  $conf->setConfirm($this->lng->txt("submit"), "directSubmit");
2736  $conf->setCancel($this->lng->txt("cancel"), "showOverview");
2737 
2738  $tpl->setContent($conf->getHTML());
2739  }
2740 
2741  protected function directSubmitObject()
2742  {
2743  global $ilUser;
2744 
2745  $success = false;
2746 
2747  // submit current version of blog
2748  if($_REQUEST["blog_id"])
2749  {
2750  $success = $this->submitBlog($_REQUEST["blog_id"]);
2751  $this->ctrl->setParameter($this, "blog_id", "");
2752  }
2753  // submit current version of portfolio
2754  else if($_REQUEST["prtf_id"])
2755  {
2756  $success = $this->submitPortfolio($_REQUEST["prtf_id"]);
2757  $this->ctrl->setParameter($this, "prtf_id", "");
2758  }
2759 
2760  if($success)
2761  {
2762  ilUtil::sendSuccess($this->lng->txt("settings_saved"), true);
2763  }
2764  else
2765  {
2766  ilUtil::sendFailure($this->lng->txt("msg_failed"), true);
2767  }
2768  $this->ctrl->redirect($this, "showOverview");
2769  }
2770 
2777  function submitBlog($a_blog_id)
2778  {
2779  global $ilUser;
2780 
2781  if($this->object && $this->ass)
2782  {
2783  $blog_id = $a_blog_id;
2784 
2785  include_once "Modules/Blog/classes/class.ilObjBlogGUI.php";
2786  $blog_gui = new ilObjBlogGUI($blog_id, ilObjBlogGUI::WORKSPACE_NODE_ID);
2787  if($blog_gui->object)
2788  {
2789  $file = $blog_gui->buildExportFile();
2790  $size = filesize($file);
2791  if($size)
2792  {
2793  $this->removeExistingSubmissions();
2794 
2795  $meta = array(
2796  "name" => $blog_id,
2797  "tmp_name" => $file,
2798  "size" => $size
2799  );
2800  $this->object->deliverFile($meta, $this->ass->getId(), $ilUser->getId(), true);
2801 
2802  $this->sendNotifications($this->ass->getId());
2803  $this->object->handleSubmission($this->ass->getId());
2804  return true;
2805  }
2806  }
2807  }
2808  return false;
2809  }
2810 
2817  function submitPortfolio($a_portfolio_id)
2818  {
2819  global $ilUser;
2820 
2821  if($this->object && $this->ass)
2822  {
2823  $prtf_id = $a_portfolio_id;
2824 
2825  include_once "Services/Portfolio/classes/class.ilObjPortfolio.php";
2826  $prtf = new ilObjPortfolio($prtf_id, false);
2827  if($prtf->getTitle())
2828  {
2829  include_once "Services/Portfolio/classes/class.ilPortfolioHTMLExport.php";
2830  $export = new ilPortfolioHTMLExport(null, $prtf);
2831  $file = $export->buildExportFile();
2832  $size = filesize($file);
2833  if($size)
2834  {
2835  $this->removeExistingSubmissions();
2836 
2837  $meta = array(
2838  "name" => $prtf_id,
2839  "tmp_name" => $file,
2840  "size" => $size
2841  );
2842  $this->object->deliverFile($meta, $this->ass->getId(), $ilUser->getId(), true);
2843 
2844  $this->sendNotifications($this->ass->getId());
2845  $this->object->handleSubmission($this->ass->getId());
2846  return true;
2847  }
2848  }
2849  }
2850  return false;
2851  }
2852 
2853  protected function selectPortfolioObject()
2854  {
2855  global $ilUser;
2856 
2857  $this->checkPermission("read");
2858 
2859  $this->tabs_gui->clearTargets();
2860  $this->tabs_gui->setBackTarget($this->lng->txt("back"), $this->ctrl->getLinkTarget($this, "showOverview"));
2861 
2862  // $this->tabs_gui->setTabActive("content");
2863  // $this->addContentSubTabs("content");
2864 
2865  if (mktime() > $this->ass->getDeadline() && ($this->ass->getDeadline() != 0))
2866  {
2867  ilUtil::sendInfo($this->lng->txt("exercise_time_over"));
2868  }
2869 
2870  $tpl = new ilTemplate("tpl.exc_select_resource.html", true, true, "Modules/Exercise");
2871 
2872  include_once "Services/Portfolio/classes/class.ilObjPortfolio.php";
2873  $portfolios = ilObjPortfolio::getPortfoliosOfUser($ilUser->getId());
2874  if($portfolios)
2875  {
2876  $tpl->setCurrentBlock("item");
2877  foreach($portfolios as $portfolio)
2878  {
2879  $tpl->setVariable("ITEM_ID", $portfolio["id"]);
2880  $tpl->setVariable("ITEM_TITLE", $portfolio["title"]);
2881  $tpl->parseCurrentBlock();
2882  }
2883  }
2884 
2885  $tpl->setVariable("TXT_TITLE", $this->lng->txt("exc_select_portfolio").": ".$this->ass->getTitle());
2886  $tpl->setVariable("FORM_ACTION", $this->ctrl->getFormAction($this));
2887  $tpl->setVariable("TXT_SUBMIT", $this->lng->txt("save"));
2888  $tpl->setVariable("TXT_CANCEL", $this->lng->txt("cancel"));
2889  $tpl->setVariable("CMD_SUBMIT", "setSelectedPortfolio");
2890  $tpl->setVariable("CMD_CANCEL", "showOverview");
2891 
2892  ilUtil::sendInfo($this->lng->txt("exc_select_portfolio_info"));
2893 
2894  $this->tpl->setContent($tpl->get());
2895  }
2896 
2897  protected function createPortfolioObject()
2898  {
2899  global $ilUser;
2900 
2901  $this->checkPermission("read");
2902 
2903  include_once "Services/Portfolio/classes/class.ilObjPortfolio.php";
2904  $portfolio = new ilObjPortfolio();
2905  $portfolio->setTitle($this->object->getTitle()." - ".$this->ass->getTitle());
2906  $portfolio->create();
2907 
2908  $this->object->addResourceObject($portfolio->getId(), $this->ass->getId(), $ilUser->getId());
2909 
2910  ilUtil::sendSuccess($this->lng->txt("exc_portfolio_created"), true);
2911  $this->ctrl->redirect($this, "showOverview");
2912  }
2913 
2914  protected function setSelectedPortfolioObject()
2915  {
2916  global $ilUser;
2917 
2918  if($_POST["item"])
2919  {
2920  $this->removeExistingSubmissions();
2921  $this->object->addResourceObject($_POST["item"], $this->ass->getId(), $ilUser->getId());
2922 
2923  ilUtil::sendSuccess($this->lng->txt("exc_portfolio_selected"), true);
2924  $this->ctrl->setParameter($this, "prtf_id", $_POST["item"]);
2925  $this->ctrl->redirect($this, "askDirectionSubmission");
2926  }
2927 
2928  ilUtil::sendFailure($this->lng->txt("select_one"));
2929  return $this->selectPortfolioObject();
2930  }
2931 
2932  protected function renderWorkspaceExplorer($a_cmd)
2933  {
2934  global $ilUser;
2935 
2936  include_once "Services/PersonalWorkspace/classes/class.ilWorkspaceTree.php";
2937  include_once "Services/PersonalWorkspace/classes/class.ilWorkspaceAccessHandler.php";
2938  require_once 'Services/PersonalWorkspace/classes/class.ilWorkspaceExplorer.php';
2939 
2940  $tree = new ilWorkspaceTree($ilUser->getId());
2941  $access_handler = new ilWorkspaceAccessHandler($tree);
2943  'exc_wspexpand', $tree, $access_handler);
2944  $exp->setTargetGet('wsp_id');
2945 
2946  if($a_cmd == "selectBlog")
2947  {
2948  $exp->removeAllFormItemTypes();
2949  $exp->addFilter('blog');
2950  $exp->addFormItemForType('blog');
2951  }
2952 
2953  if($_GET['exc_wspexpand'] == '')
2954  {
2955  // not really used as session is already set [see above]
2956  $expanded = $tree->readRootId();
2957  }
2958  else
2959  {
2960  $expanded = $_GET['exc_wspexpand'];
2961  }
2962 
2963  $exp->setExpandTarget($this->ctrl->getLinkTarget($this, $a_cmd));
2964  $exp->setPostVar('node');
2965  $exp->setExpand($expanded);
2966  $exp->setOutput(0);
2967 
2968  return $exp->getOutput();
2969  }
2970 
2972  {
2973  $this->setSettingsSubTabs();
2974  $this->tabs_gui->activateTab("settings");
2975  $this->tabs_gui->activateSubTab("certificate");
2976 
2977  include_once "./Services/Certificate/classes/class.ilCertificateGUI.php";
2978  include_once "./Modules/Exercise/classes/class.ilExerciseCertificateAdapter.php";
2979  $output_gui = new ilCertificateGUI(new ilExerciseCertificateAdapter($this->object));
2980  $output_gui->certificateEditor();
2981  }
2982 
2984  {
2985  global $ilUser;
2986 
2987  if($this->object->hasUserCertificate($ilUser->getId()))
2988  {
2989  ilUtil::sendFailure($this->lng->txt("msg_failed"));
2990  $this->showOverviewObject();
2991  }
2992 
2993  include_once "./Services/Certificate/classes/class.ilCertificate.php";
2994  include_once "./Modules/Exercise/classes/class.ilExerciseCertificateAdapter.php";
2995  $certificate = new ilCertificate(new ilExerciseCertificateAdapter($this->object));
2996  $certificate->outCertificate(array("user_id" => $ilUser->getId()));
2997  }
2998 
2999  protected function initTeamSubmission($a_back_cmd, $a_mandatory_team = true)
3000  {
3001  global $ilUser, $ilHelp;
3002 
3003  $this->checkPermission("read");
3004 
3005  if($a_mandatory_team && $this->ass->getType() != ilExAssignment::TYPE_UPLOAD_TEAM)
3006  {
3007  $this->ctrl->redirect($this, "submissionScreen");
3008  }
3009 
3010  $this->tabs_gui->clearTargets();
3011  $ilHelp->setScreenIdComponent("exc");
3012  $this->tabs_gui->setBackTarget($this->lng->txt("back"),
3013  $this->ctrl->getLinkTarget($this, $a_back_cmd));
3014 
3015  if($this->ass->getType() == ilExAssignment::TYPE_UPLOAD_TEAM)
3016  {
3017  $this->tabs_gui->addTab("submissions", $this->lng->txt("files"),
3018  $this->ctrl->getLinkTarget($this, "submissionScreen"));
3019 
3020  $this->tabs_gui->addTab("team", $this->lng->txt("exc_team"),
3021  $this->ctrl->getLinkTarget($this, "submissionScreenTeam"));
3022 
3023  $this->tabs_gui->addTab("log", $this->lng->txt("exc_team_log"),
3024  $this->ctrl->getLinkTarget($this, "submissionScreenTeamLog"));
3025 
3026  $this->tabs_gui->activateTab("team");
3027 
3028  $team_id = $this->ass->getTeamId($ilUser->getId());
3029 
3030  if(!$team_id)
3031  {
3032  $team_id = $this->ass->getTeamId($ilUser->getId(), true);
3033 
3034  // #12337
3035  if (!$this->object->members_obj->isAssigned($ilUser->getId()))
3036  {
3037  $this->object->members_obj->assignMember($ilUser->getId());
3038  }
3039  }
3040 
3041  return $team_id;
3042  }
3043  else
3044  {
3045  $ilHelp->setScreenId("submissions");
3046  }
3047  }
3048 
3055  {
3056  global $ilToolbar;
3057 
3058  $team_id = $this->initTeamSubmission("showOverview");
3059 
3060  // $this->tabs_gui->setTabActive("content");
3061  // $this->addContentSubTabs("content");
3062 
3063  // #13414
3064  $read_only = (mktime() > $this->ass->getDeadline() && ($this->ass->getDeadline() != 0));
3065 
3066  if ($read_only)
3067  {
3068  ilUtil::sendInfo($this->lng->txt("exercise_time_over"));
3069  }
3070  else
3071  {
3072  $this->ctrl->setParameterByClass('ilRepositorySearchGUI', 'ctx', 1);
3073  $this->ctrl->setParameter($this, 'ctx', 1);
3074 
3075  // add member
3076  include_once './Services/Search/classes/class.ilRepositorySearchGUI.php';
3078  $this,
3079  $ilToolbar,
3080  array(
3081  'auto_complete_name' => $this->lng->txt('user'),
3082  'submit_name' => $this->lng->txt('add')
3083  )
3084  );
3085 
3086  $ilToolbar->addSpacer();
3087 
3088  $ilToolbar->addButton(
3089  $this->lng->txt("exc_search_users"),
3090  $this->ctrl->getLinkTargetByClass('ilRepositorySearchGUI',''));
3091  $ilToolbar->setFormAction($this->ctrl->getFormAction($this));
3092 
3093  $parent_container_id = $this->object->getParentContainerId();
3094  if ($parent_container_id)
3095  {
3096  $this->ctrl->setParameterByClass('ilRepositorySearchGUI', "list_obj", $parent_container_id);
3097  $this->lng->loadLanguageModule("exercise");
3098 
3099  $ilToolbar->addSpacer();
3100 
3101  /*
3102  $ilToolbar->addButton($this->lng->txt("exc_crs_add_members"),
3103  $this->ctrl->getLinkTargetByClass('ilRepositorySearchGUI','listUsers'));
3104  */
3105  $ilToolbar->addButton($this->lng->txt("exc_team_member_container_add"),
3106  $this->ctrl->getLinkTarget($this, "addTeamMemberContainer"));
3107  }
3108  }
3109 
3110  include_once "Modules/Exercise/classes/class.ilExAssignmentTeamTableGUI.php";
3111  $tbl = new ilExAssignmentTeamTableGUI($this, "submissionScreenTeam",
3112  ilExAssignmentTeamTableGUI::MODE_EDIT, $team_id, $this->ass, null, $read_only);
3113 
3114  $this->tpl->setContent($tbl->getHTML());
3115  }
3116 
3118  {
3119  $team_id = $this->initTeamSubmission("submissionScreenTeam");
3120 
3121  $members = $this->object->getParentMemberIds();
3122  if(!$members)
3123  {
3124  $this->ctrl->redirect($this, "submissionScreenTeam");
3125  }
3126 
3127  include_once "Modules/Exercise/classes/class.ilExAssignmentTeamTableGUI.php";
3128  $tbl = new ilExAssignmentTeamTableGUI($this, "addTeamMemberContainer",
3129  ilExAssignmentTeamTableGUI::MODE_ADD, $team_id, $this->ass, $members);
3130 
3131  $this->tpl->setContent($tbl->getHTML());
3132  }
3133 
3135  {
3136  global $ilUser;
3137 
3138  $ids = $_POST["id"];
3139 
3140  if(!sizeof($ids))
3141  {
3142  ilUtil::sendFailure($this->lng->txt("select_one"), true);
3143  $this->ctrl->redirect($this, "submissionScreenTeam");
3144  }
3145 
3146  $team_id = $this->ass->getTeamId($ilUser->getId());
3147  $has_files = $this->ass->getDeliveredFiles($this->object->getId(),
3148  $this->ass->getId(),
3149  $ilUser->getId());
3150 
3151  foreach($ids as $user_id)
3152  {
3153  $this->ass->addTeamMember($team_id, $user_id, $this->ref_id);
3154 
3155  // see ilObjExercise::deliverFile()
3156  if($has_files)
3157  {
3158  if (!$this->object->members_obj->isAssigned($user_id))
3159  {
3160  $this->object->members_obj->assignMember($user_id);
3161  }
3162  ilExAssignment::updateStatusReturnedForUser($this->ass->getId(), $user_id, 1);
3163  ilExerciseMembers::_writeReturned($this->object->getId(), $user_id, 1);
3164  }
3165 
3166  // :TODO: log, notification
3167  }
3168 
3169  ilUtil::sendSuccess($this->lng->txt("settings_saved"), true);
3170  $this->ctrl->redirect($this, "submissionScreenTeam");
3171  }
3172 
3173  public function addTeamMemberActionObject($a_user_ids = array())
3174  {
3175  global $ilUser;
3176 
3177  $this->checkPermission("read");
3178 
3179  if(!count($a_user_ids))
3180  {
3181  ilUtil::sendFailure($this->lng->txt("no_checkbox"));
3182  return false;
3183  }
3184 
3185  $team_id = $this->ass->getTeamId($ilUser->getId());
3186  $has_files = $this->ass->getDeliveredFiles($this->object->getId(),
3187  $this->ass->getId(),
3188  $ilUser->getId());
3189  $all_members = $this->ass->getMembersOfAllTeams();
3190  $members = $this->ass->getTeamMembers($team_id);
3191 
3192  foreach($a_user_ids as $user_id)
3193  {
3194  if(!in_array($user_id, $all_members))
3195  {
3196  $this->ass->addTeamMember($team_id, $user_id, $this->ref_id);
3197 
3198  // see ilObjExercise::deliverFile()
3199  if($has_files)
3200  {
3201  if (!$this->object->members_obj->isAssigned($user_id))
3202  {
3203  $this->object->members_obj->assignMember($user_id);
3204  }
3205  ilExAssignment::updateStatusReturnedForUser($this->ass->getId(), $user_id, 1);
3206  ilExerciseMembers::_writeReturned($this->object->getId(), $user_id, 1);
3207  }
3208 
3209  // :TODO: log, notification
3210  }
3211  else if(!in_array($user_id, $members))
3212  {
3213  ilUtil::sendFailure($this->lng->txt("exc_members_already_assigned"), true);
3214  }
3215  }
3216 
3217  ilUtil::sendSuccess($this->lng->txt("settings_saved"), true);
3218  $this->ctrl->redirect($this, "submissionScreenTeam");
3219  }
3220 
3222  {
3223  global $ilUser, $tpl;
3224 
3225  $ids = $_POST["id"];
3226 
3227  if(!sizeof($ids))
3228  {
3229  ilUtil::sendFailure($this->lng->txt("select_one"), true);
3230  $this->ctrl->redirect($this, "submissionScreenTeam");
3231  }
3232 
3233  $team_id = $this->ass->getTeamId($ilUser->getId());
3234  $members = $this->ass->getTeamMembers($team_id);
3235 
3236  $team_deleted = false;
3237  if(sizeof($members) <= sizeof($ids))
3238  {
3239  if(sizeof($members) == 1 && $members[0] == $ilUser->getId())
3240  {
3241  // direct team deletion - no confirmation
3242  return $this->removeTeamMemberObject();
3243  }
3244  else
3245  {
3246  ilUtil::sendFailure($this->lng->txt("exc_team_at_least_one"), true);
3247  $this->ctrl->redirect($this, "submissionScreenTeam");
3248  }
3249  }
3250 
3251  // #11957
3252 
3253  $team_id = $this->initTeamSubmission("showOverview");
3254 
3255  include_once("./Services/Utilities/classes/class.ilConfirmationGUI.php");
3256  $cgui = new ilConfirmationGUI();
3257  $cgui->setFormAction($this->ctrl->getFormAction($this));
3258  $cgui->setHeaderText($this->lng->txt("exc_team_member_remove_sure"));
3259  $cgui->setCancel($this->lng->txt("cancel"), "submissionScreenTeam");
3260  $cgui->setConfirm($this->lng->txt("remove"), "removeTeamMember");
3261 
3262  $files = ilExAssignment::getDeliveredFiles($this->ass->getExerciseId(),
3263  $this->ass->getId(), $ilUser->getId());
3264 
3265  include_once "Services/User/classes/class.ilUserUtil.php";
3266 
3267  foreach($ids as $id)
3268  {
3269  $details = array();
3270  foreach ($files as $file)
3271  {
3272  if($file["owner_id"] == $id)
3273  {
3274  $details[] = $file["filetitle"];
3275  }
3276  }
3277  $uname = ilUserUtil::getNamePresentation($id);
3278  if(sizeof($details))
3279  {
3280  $uname .= ": ".implode(", ", $details);
3281  }
3282  $cgui->addItem("id[]", $id, $uname);
3283  }
3284 
3285  $tpl->setContent($cgui->getHTML());
3286  }
3287 
3288  public function removeTeamMemberObject()
3289  {
3290  global $ilUser;
3291 
3292  $ids = $_POST["id"];
3293 
3294  if(!sizeof($ids))
3295  {
3296  ilUtil::sendFailure($this->lng->txt("select_one"), true);
3297  $this->ctrl->redirect($this, "submissionScreenTeam");
3298  }
3299 
3300  $team_id = $this->ass->getTeamId($ilUser->getId());
3301  $members = $this->ass->getTeamMembers($team_id);
3302 
3303  $team_deleted = false;
3304  if(sizeof($members) <= sizeof($ids))
3305  {
3306  if(sizeof($members) == 1 && $members[0] == $ilUser->getId())
3307  {
3308  $team_deleted = true;
3309  }
3310  else
3311  {
3312  ilUtil::sendFailure($this->lng->txt("exc_team_at_least_one"), true);
3313  $this->ctrl->redirect($this, "submissionScreenTeam");
3314  }
3315  }
3316 
3317  foreach($ids as $user_id)
3318  {
3319  $this->ass->removeTeamMember($team_id, $user_id, $this->ref_id);
3320 
3321  ilExAssignment::updateStatusReturnedForUser($this->ass->getId(), $user_id, 0);
3322  ilExerciseMembers::_writeReturned($this->object->getId(), $user_id, 0);
3323 
3324  // :TODO: log, notification
3325  }
3326 
3327  ilUtil::sendSuccess($this->lng->txt("settings_saved"), true);
3328 
3329  if(!$team_deleted)
3330  {
3331  $this->ctrl->redirect($this, "submissionScreenTeam");
3332  }
3333  else
3334  {
3335  $this->ctrl->redirect($this, "showOverview");
3336  }
3337  }
3338 
3340  {
3341  $team_id = $this->initTeamSubmission("showOverview");
3342  $this->tabs_gui->activateTab("log");
3343 
3344  include_once "Modules/Exercise/classes/class.ilExAssignmentTeamLogTableGUI.php";
3345  $tbl = new ilExAssignmentTeamLogTableGUI($this, "submissionScreenTeamLog",
3346  $team_id);
3347 
3348  $this->tpl->setContent($tbl->getHTML());
3349  }
3350 
3352  {
3353  if(isset($_GET["lmem"]))
3354  {
3355  $user_id = $_GET["lmem"];
3356  $cmd = "members";
3357  }
3358  else
3359  {
3360  $user_id = $_GET["lpart"];
3361  $cmd = "showParticipant";
3362  }
3363  if($user_id)
3364  {
3365  $this->ass->getTeamId($user_id, true);
3366  ilUtil::sendSuccess($this->lng->txt("settings_saved"), true);
3367  }
3368  $this->ctrl->redirect($this, $cmd);
3369  }
3370 
3372  {
3373  $this->checkPermission("write");
3374  $this->tabs_gui->activateTab("grades");
3375 
3376  if(isset($_GET["lmem"]))
3377  {
3378  $this->addSubmissionSubTabs("assignment");
3379 
3380  $this->tabs_gui->setBackTarget($this->lng->txt("back"),
3381  $this->ctrl->getLinkTarget($this, "members"));
3382 
3383  $team_id = ilExAssignment::getTeamIdByAssignment($this->ass->getId(), (int)$_GET["lmem"]);
3384 
3385  $this->ctrl->saveParameter($this, "lmem");
3386  }
3387  else
3388  {
3389  $this->addSubmissionSubTabs("participant");
3390 
3391  $this->tabs_gui->setBackTarget($this->lng->txt("back"),
3392  $this->ctrl->getLinkTarget($this, "showParticipant"));
3393 
3394  $team_id = ilExAssignment::getTeamIdByAssignment($this->ass->getId(), (int)$_GET["lpart"]);
3395 
3396  $this->ctrl->saveParameter($this, "lpart");
3397  }
3398 
3399  include_once "Modules/Exercise/classes/class.ilExAssignmentTeamLogTableGUI.php";
3400  $tbl = new ilExAssignmentTeamLogTableGUI($this, "showTeamLog",
3401  $team_id);
3402 
3403  $this->tpl->setContent($tbl->getHTML());
3404  }
3405 }
3406 
3407 ?>