ILIAS  Release_4_2_x_branch Revision 61807
 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 "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  include_once("./classes/class.ilFileSystemGUI.php");
93  $fs_gui = new ilFileSystemGUI($fstorage->getFeedbackPath((int) $_GET["member_id"]));
94  $fs_gui->setTableId("excfbfil".(int)$_GET["ass_id"]."_".(int)$_GET["member_id"]);
95  $fs_gui->setAllowDirectories(false);
96  include_once("./Services/User/classes/class.ilUserUtil.php");
97  $fs_gui->setTitle($lng->txt("exc_fb_files")." - ".
98  ilExAssignment::lookupTitle((int) $_GET["ass_id"])." - ".
99  ilUserUtil::getNamePresentation((int) $_GET["member_id"], false, false, "", true));
100  $pcommand = $fs_gui->getLastPerformedCommand();
101  if ($pcommand["cmd"] == "create_file")
102  {
103  $this->object->sendFeedbackFileNotification($pcommand["name"], (int) $_GET["member_id"],
104  (int) $_GET["ass_id"]);
105  }
106  $ret = $this->ctrl->forwardCommand($fs_gui);
107  }
108  else // assignment files
109  {
110  $this->setAssignmentHeader();
111  $ilTabs->activateTab("ass_files");
112  include_once("./Modules/Exercise/classes/class.ilFSStorageExercise.php");
113  $fstorage = new ilFSStorageExercise($this->object->getId(), (int) $_GET["ass_id"]);
114  $fstorage->create();
115  include_once("./classes/class.ilFileSystemGUI.php");
116  $fs_gui = new ilFileSystemGUI($fstorage->getPath());
117  $fs_gui->setTableId("excassfil".$_GET["ass_id"]);
118  $fs_gui->setAllowDirectories(false);
119  $ret = $this->ctrl->forwardCommand($fs_gui);
120  }
121  break;
122 
123  case "ilinfoscreengui":
124  $ilTabs->activateTab("info");
125  $this->infoScreen(); // forwards command
126  break;
127 
128  case 'ilpermissiongui':
129  $ilTabs->activateTab("permissions");
130  include_once("Services/AccessControl/classes/class.ilPermissionGUI.php");
131  $perm_gui =& new ilPermissionGUI($this);
132  $ret =& $this->ctrl->forwardCommand($perm_gui);
133  break;
134 
135  case "illearningprogressgui":
136  $ilTabs->activateTab("learning_progress");
137  include_once './Services/Tracking/classes/class.ilLearningProgressGUI.php';
138 
140  $this->object->getRefId(),
141  $_GET['user_id'] ? $_GET['user_id'] : $ilUser->getId());
142  $this->ctrl->forwardCommand($new_gui);
143  $this->tabs_gui->setTabActive('learning_progress');
144  break;
145 
146  case 'ilrepositorysearchgui':
147  $ilTabs->activateTab("grades");
148  include_once('./Services/Search/classes/class.ilRepositorySearchGUI.php');
149  $rep_search = new ilRepositorySearchGUI();
150  $rep_search->setTitle($this->lng->txt("exc_add_participant"));
151  $rep_search->setCallback($this,'addMembersObject');
152 
153  // Set tabs
154  $this->tabs_gui->setTabActive('members');
155  $this->ctrl->setReturn($this,'members');
156  $ret =& $this->ctrl->forwardCommand($rep_search);
157  #$this->__setSubTabs('members');
158  #$this->tabs_gui->setSubTabActive('members');
159  break;
160 
161  case 'ilobjectcopygui':
162  $ilCtrl->saveParameter($this, 'new_type');
163  $ilCtrl->setReturnByClass(get_class($this),'create');
164 
165  include_once './Services/Object/classes/class.ilObjectCopyGUI.php';
166  $cp = new ilObjectCopyGUI($this);
167  $cp->setType('exc');
168  $this->ctrl->forwardCommand($cp);
169  break;
170 
171  case "ilexportgui":
172  $ilTabs->activateTab("export");
173  include_once("./Services/Export/classes/class.ilExportGUI.php");
174  $exp_gui = new ilExportGUI($this);
175  $exp_gui->addFormat("xml");
176  $ret = $this->ctrl->forwardCommand($exp_gui);
177 // $this->tpl->show();
178  break;
179  case 'ilshoppurchasegui':
180  include_once './Services/Payment/classes/class.ilShopPurchaseGUI.php';
181  $sp = new ilShopPurchaseGUI($_GET['ref_id']);
182 
183  $this->ctrl->forwardCommand($sp);
184  break;
185 
186  case "ilcommonactiondispatchergui":
187  include_once("Services/Object/classes/class.ilCommonActionDispatcherGUI.php");
189  $this->ctrl->forwardCommand($gui);
190  break;
191 
192  case "ilcertificategui":
193  $this->setSettingsSubTabs();
194  $this->tabs_gui->activateTab("settings");
195  $this->tabs_gui->activateSubTab("certificate");
196  include_once "./Services/Certificate/classes/class.ilCertificateGUI.php";
197  include_once "./Modules/Exercise/classes/class.ilExerciseCertificateAdapter.php";
198  $output_gui = new ilCertificateGUI(new ilExerciseCertificateAdapter($this->object));
199  $this->ctrl->forwardCommand($output_gui);
200  break;
201 
202  default:
203  if(!$cmd)
204  {
205  $cmd = "infoScreen";
206  }
207 
208  $cmd .= "Object";
209 
210  $this->$cmd();
211 
212  break;
213  }
214 
215  $this->addHeaderAction();
216 
217  return true;
218  }
219 
220  function viewObject()
221  {
222  $this->infoScreenObject();
223  }
224 
231  function downloadObject()
232  {
233  global $ilUser, $ilCtrl;
234 
235  $this->checkPermission("read");
236  if (count($_REQUEST["delivered"]))
237  {
238  if(!is_array($_REQUEST["delivered"]))
239  {
240  $_REQUEST["delivered"] = array($_REQUEST["delivered"]);
241  }
242  ilExAssignment::downloadSelectedFiles($this->object->getId(), (int) $_GET["ass_id"],
243  $ilUser->getId(), $_REQUEST["delivered"]);
244  exit;
245  }
246  else
247  {
248  ilUtil::sendFailure($this->lng->txt("please_select_a_delivered_file_to_download"), true);
249  $ilCtrl->redirect($this, "submissionScreen");
250  }
251  }
252 
257  {
258  global $ilCtrl, $tpl, $lng, $ilUser;
259 
260  $this->checkPermission("read");
261 
262  $this->tabs_gui->setTabActive("content");
263  $this->addContentSubTabs("content");
264 
265  if (mktime() > $this->ass->getDeadline())
266  {
267  ilUtil::sendFailure($this->lng->txt("exercise_time_over"), true);
268  $ilCtrl->redirect($this, "submissionScreen");
269  }
270 
271  if (!is_array($_POST["delivered"]) || count($_POST["delivered"]) == 0)
272  {
273  ilUtil::sendFailure($lng->txt("no_checkbox"), true);
274  $ilCtrl->redirect($this, "submissionScreen");
275  }
276  else
277  {
278  include_once("./Services/Utilities/classes/class.ilConfirmationGUI.php");
279  $cgui = new ilConfirmationGUI();
280  $cgui->setFormAction($ilCtrl->getFormAction($this));
281  $cgui->setHeaderText($lng->txt("info_delete_sure"));
282  $cgui->setCancel($lng->txt("cancel"), "submissionScreen");
283  $cgui->setConfirm($lng->txt("delete"), "deleteDelivered");
284 
285  $files = ilExAssignment::getDeliveredFiles($this->object->getId(), (int) $_GET["ass_id"],
286  $ilUser->getId());
287 //var_dump($files);
288  foreach ($_POST["delivered"] as $i)
289  {
290  reset ($files);
291  $title = "";
292  foreach ($files as $f)
293  {
294  if ($f["returned_id"] == $i)
295  {
296  $title = $f["filetitle"];
297  }
298  }
299  $cgui->addItem("delivered[]", $i, $title);
300  }
301 
302  $tpl->setContent($cgui->getHTML());
303  }
304  }
305 
313  {
314  global $ilUser, $ilCtrl;
315 
316  $this->checkPermission("read");
317 
318  if (mktime() > $this->ass->getDeadline())
319  {
320  ilUtil::sendFailure($this->lng->txt("exercise_time_over"), true);
321  $ilCtrl->redirect($this, "submissionScreen");
322  }
323 
324  if (count($_POST["delivered"]) && mktime() < $this->ass->getDeadline())
325  {
326  $this->object->deleteDeliveredFiles($this->object->getId(), (int) $_GET["ass_id"],
327  $_POST["delivered"], $ilUser->id);
328 
329  $this->object->handleSubmission((int)$_GET['ass_id']);
330 
331  ilUtil::sendSuccess($this->lng->txt("exc_submitted_files_deleted"), true);
332  }
333  else
334  {
335  ilUtil::sendFailure($this->lng->txt("please_select_a_delivered_file_to_delete"), true);
336  }
337  $ilCtrl->redirect($this, "submissionScreen");
338  }
339 
346  {
347  global $ilUser;
348  require_once "./Services/Utilities/classes/class.ilUtil.php";
349 
350  $this->checkPermission("read");
351 
352  $this->tabs_gui->setTabActive("content");
353  $this->addContentSubTabs("content");
354 
355  if (mktime() > $this->ass->getDeadline())
356  {
357  ilUtil::sendInfo($this->lng->txt("exercise_time_over"));
358  }
359 
360  $this->getTemplateFile("deliver_file", "exc");
361 
362  include_once("./Modules/Exercise/classes/class.ilExcDeliveredFilesTableGUI.php");
363  $tab = new ilExcDeliveredFilesTableGUI($this, "deliver", $this->object, $_GET["ass_id"]);
364  $this->tpl->setVariable("DELIVERED_FILES_TABLE", $tab->getHTML());
365 
366  if (mktime() < $this->ass->getDeadline())
367  {
368  $this->initUploadForm();
369  $this->tpl->setVariable("UPLOAD_SINGLE_FORM", $this->form->getHTML());
370 
371  $this->initZipUploadForm();
372  $this->tpl->setVariable("UPLOAD_MULTI_FORM", $this->form->getHTML());
373  }
374  }
375 
379  public function initUploadForm()
380  {
381  global $lng, $ilCtrl;
382 
383  include_once("Services/Form/classes/class.ilPropertyFormGUI.php");
384  $this->form = new ilPropertyFormGUI();
385 
386  // file input
387  include_once("./Services/Form/classes/class.ilFileWizardInputGUI.php");
388  $fi = new ilFileWizardInputGUI($lng->txt("file"), "deliver");
389  $fi->setFilenames(array(0 => ''));
390  //$fi->setInfo($lng->txt(""));
391  $this->form->addItem($fi);
392 
393  $this->form->addCommandButton("deliverFile", $lng->txt("upload"));
394 
395  $this->form->setTitle($lng->txt("file_add"));
396  $this->form->setFormAction($ilCtrl->getFormAction($this));
397  }
398 
402  public function initZipUploadForm()
403  {
404  global $lng, $ilCtrl;
405 
406  include_once("Services/Form/classes/class.ilPropertyFormGUI.php");
407  $this->form = new ilPropertyFormGUI();
408 
409  // desc
410  include_once("./Services/Form/classes/class.ilFileInputGUI.php");
411  $fi = new ilFileInputGUI($lng->txt("file"), "deliver");
412  $fi->setSuffixes(array("zip"));
413  $this->form->addItem($fi);
414 
415  $this->form->addCommandButton("deliverUnzip", $lng->txt("upload"));
416 
417  $this->form->setTitle($lng->txt("header_zip"));
418  $this->form->setFormAction($ilCtrl->getFormAction($this));
419  }
420 
424  function deliverFileObject()
425  {
426  global $ilUser, $lng, $ilCtrl;
427 
428  $this->checkPermission("read");
429 
430  $success = false;
431  foreach ($_FILES["deliver"]["name"] as $k => $v)
432  {
433  $file = array(
434  "name" => $_FILES["deliver"]["name"][$k],
435  "type" => $_FILES["deliver"]["type"][$k],
436  "tmp_name" => $_FILES["deliver"]["tmp_name"][$k],
437  "error" => $_FILES["deliver"]["error"][$k],
438  "size" => $_FILES["deliver"]["size"][$k],
439  );
440  if(!$this->object->deliverFile($file, (int) $_GET["ass_id"], $ilUser->id))
441  {
442  ilUtil::sendFailure($this->lng->txt("exc_upload_error"), true);
443  }
444  else
445  {
446  $success = true;
447  }
448  }
449 
450  if($success)
451  {
452  $this->sendNotifications((int)$_GET["ass_id"]);
453  $this->object->handleSubmission((int)$_GET['ass_id']);
454  }
455  $ilCtrl->redirect($this, "submissionScreen");
456  }
457 
462  {
463  global $ilCtrl;
464 
465  $this->checkPermission("read");
466 
467  if (preg_match("/zip/",$_FILES["deliver"]["type"]) == 1)
468  {
469  if($this->object->processUploadedFile($_FILES["deliver"]["tmp_name"], "deliverFile", false,
470  (int) $_GET["ass_id"]))
471  {
472  $this->sendNotifications((int)$_GET["ass_id"]);
473  $this->object->handleSubmission((int)$_GET['ass_id']);
474  }
475  }
476 
477  $ilCtrl->redirect($this, "submissionScreen");
478  }
479 
484  {
485  global $rbacsystem, $ilUser;
486 
487  $file = ($_POST["file"])
488  ? $_POST["file"]
489  : $_GET["file"];
490 
491  // check read permission
492  $this->checkPermission("read");
493 
494  if (!isset($file))
495  {
496  ilUtil::sendFailure($this->lng->txt("exc_select_one_file"),true);
497  $this->ctrl->redirect($this, "view");
498  }
499 
500  // check, whether file belongs to assignment
501  include_once("./Modules/Exercise/classes/class.ilFSStorageExercise.php");
502  $storage = new ilFSStorageExercise($this->object->getId(), (int) $_GET["ass_id"]);
503  $files = $storage->getFeedbackFiles($ilUser->getId());
504  $file_exist = false;
505  foreach($files as $fb_file)
506  {
507  if($fb_file == urldecode($file))
508  {
509  $file_exist = true;
510  break;
511  }
512  }
513  if(!$file_exist)
514  {
515  echo "FILE DOES NOT EXIST";
516  exit;
517  }
518 
519  // check whether assignment as already started
520  $ass = new ilExAssignment((int) $_GET["ass_id"]);
521  $not_started_yet = false;
522  if ($ass->getStartTime() > 0 && time() - $ass->getStartTime() <= 0)
523  {
524  $not_started_yet = true;
525  }
526 
527  // deliver file
528  if (!$not_started_yet)
529  {
530  $p = $storage->getFeedbackFilePath($ilUser->getId(), urldecode($file));
531  ilUtil::deliverFile($p, urldecode($file));
532  }
533 
534  return true;
535  }
536 
541  {
542  global $rbacsystem;
543 
544  $file = ($_POST["file"])
545  ? $_POST["file"]
546  : $_GET["file"];
547 
548  // check read permission
549  $this->checkPermission("read");
550 
551  if (!isset($file))
552  {
553  ilUtil::sendFailure($this->lng->txt("exc_select_one_file"),true);
554  $this->ctrl->redirect($this, "view");
555  }
556 
557  // check, whether file belongs to assignment
558  include_once("./Modules/Exercise/classes/class.ilExAssignment.php");
559  $files = ilExAssignment::getFiles($this->object->getId(), (int) $_GET["ass_id"]);
560  $file_exist = false;
561  foreach($files as $lfile)
562  {
563  if($lfile["name"] == urldecode($file))
564  {
565  $file_exist = true;
566  break;
567  }
568  }
569  if(!$file_exist)
570  {
571  echo "FILE DOES NOT EXIST";
572  exit;
573  }
574 
575  // check whether assignment as already started
576  $ass = new ilExAssignment((int) $_GET["ass_id"]);
577  $not_started_yet = false;
578  if ($ass->getStartTime() > 0 && time() - $ass->getStartTime() <= 0)
579  {
580  $not_started_yet = true;
581  }
582 
583  // deliver file
584  if (!$not_started_yet)
585  {
586  include_once("./Modules/Exercise/classes/class.ilFSStorageExercise.php");
587  $storage = new ilFSStorageExercise($this->object->getId(), (int) $_GET["ass_id"]);
588  $p = $storage->getAssignmentFilePath(urldecode($file));
589  ilUtil::deliverFile($p, urldecode($file));
590  }
591 
592  return true;
593  }
594 
595  protected function afterSave(ilObject $a_new_object)
596  {
597  $a_new_object->saveData();
598 
599  ilUtil::sendSuccess($this->lng->txt("exc_added"), true);
600  ilUtil::redirect("ilias.php?baseClass=ilExerciseHandlerGUI&ref_id=".$a_new_object->getRefId()."&cmd=addAssignment");
601  }
602 
606  protected function initEditCustomForm(ilPropertyFormGUI $a_form)
607  {
608  $a_form->setTitle($this->lng->txt("exc_edit_exercise"));
609 
610 
611  // show submissions
612  $cb = new ilCheckboxInputGUI($this->lng->txt("exc_show_submissions"), "show_submissions");
613  $cb->setInfo($this->lng->txt("exc_show_submissions_info"));
614  $a_form->addItem($cb);
615 
616 
617  // pass mode
618  $radg = new ilRadioGroupInputGUI($this->lng->txt("exc_pass_mode"), "pass_mode");
619 
620  $op1 = new ilRadioOption($this->lng->txt("exc_pass_all"), "all",
621  $this->lng->txt("exc_pass_all_info"));
622  $radg->addOption($op1);
623  $op2 = new ilRadioOption($this->lng->txt("exc_pass_minimum_nr"), "nr",
624  $this->lng->txt("exc_pass_minimum_nr_info"));
625  $radg->addOption($op2);
626 
627  // minimum number of assignments to pass
628  $ni = new ilNumberInputGUI($this->lng->txt("exc_min_nr"), "pass_nr");
629  $ni->setSize(4);
630  $ni->setMaxLength(4);
631  $ni->setRequired(true);
632  include_once("./Modules/Exercise/classes/class.ilExAssignment.php");
633  $mand = ilExAssignment::countMandatory($this->object->getId());
634  $min = max($mand, 1);
635  $ni->setMinValue($min);
636  $op2->addSubItem($ni);
637 
638  $a_form->addItem($radg);
639 
640  $cbox = new ilCheckboxInputGUI($this->lng->txt("exc_submission_notification"), "notification");
641  $cbox->setInfo($this->lng->txt("exc_submission_notification_info"));
642  $a_form->addItem($cbox);
643 
644  $subcompl = new ilCheckboxInputGUI($this->lng->txt('exc_completion_by_submission'), 'completion_by_submission');
645  $subcompl->setInfo($this->lng->txt('exc_completion_by_submission_info'));
646  $subcompl->setValue(1);
647  $a_form->addItem($subcompl);
648  }
649 
653  protected function getEditFormCustomValues(array &$a_values)
654  {
655  global $ilUser;
656 
657  $a_values["desc"] = $this->object->getLongDescription();
658  $a_values["show_submissions"] = $this->object->getShowSubmissions();
659  $a_values["pass_mode"] = $this->object->getPassMode();
660  if ($a_values["pass_mode"] == "nr")
661  {
662  $a_values["pass_nr"] = $this->object->getPassNr();
663  }
664 
665  include_once "./Services/Notification/classes/class.ilNotification.php";
666  $a_values["notification"] = ilNotification::hasNotification(
668  $this->object->getId());
669 
670  $a_values['completion_by_submission'] = $this->object->isCompletionBySubmissionEnabled();
671  }
672 
673  protected function updateCustom(ilPropertyFormGUI $a_form)
674  {
675  global $ilUser;
676  $this->object->setShowSubmissions($a_form->getInput("show_submissions"));
677  $this->object->setPassMode($a_form->getInput("pass_mode"));
678  if ($this->object->getPassMode() == "nr")
679  {
680  $this->object->setPassNr($a_form->getInput("pass_nr"));
681  }
682 
683  $this->object->setCompletionBySubmission($a_form->getInput('completion_by_submission') == 1 ? true : false);
684 
685  include_once "./Services/Notification/classes/class.ilNotification.php";
687  $ilUser->getId(), $this->object->getId(),
688  (bool)$a_form->getInput("notification"));
689  }
690 
691  function cancelEditObject()
692  {
693  $this->ctrl->redirect($this, "view");
694  }
695 
696  function uploadZipObject()
697  {
698  global $rbacsystem;
699 
700  $this->checkPermission("write");
701 
702  if(!$this->object->addUploadedFile($_FILES["zipfile"], true))
703  {
704  ilUtil::sendFailure($this->lng->txt("exc_upload_error"),true);
705  }
706  $this->ctrl->redirect($this, "edit");
707 
708  }
709 
710  function uploadFileObject()
711  {
712  global $rbacsystem;
713 
714  $this->checkPermission("write");
715 
716  if(!$this->object->addUploadedFile($_FILES["file"]))
717  {
718  ilUtil::sendFailure($this->lng->txt("exc_upload_error"),true);
719  }
720  $this->ctrl->redirect($this, "edit");
721  }
722 
723 
728  {
729  global $rbacsystem;
730 
731  $this->checkPermission("write");
732 
733  if ($_POST["downloadReturned"])
734  {
735  $this->object->members_obj->deliverReturnedFiles(key($_POST["downloadReturned"]));
736  exit;
737  }
738  else
739  {
740  switch($_POST["action"])
741  {
742  case "save_status":
743  $this->saveStatusObject();
744  break;
745 
746  case "send_member":
747  $this->sendMembersObject();
748  break;
749 
750  case "redirectFeedbackMail":
752  break;
753 
754  case "delete_member":
755  $this->deassignMembersObject();
756  break;
757  }
758  }
759  }
760 
765  {
766  global $ilAccess;
767 
768  if ($ilAccess->checkAccess("read", "", $this->object->getRefId()) &&
769  $this->object->getShowSubmissions() &&
770  $this->object->getTimestamp() - time() <= 0)
771  {
772  // ok: read access + public submissions
773  }
774  else
775  {
776  $this->checkPermission("write");
777  }
778 
780  $this->object->getId(), (int) $_GET["ass_id"], (int) $_GET["member_id"]))
781  {
782  $this->ctrl->redirect($this, "members");
783  }
784  exit;
785  }
786 
791  {
792  $this->checkPermission("write");
793 
795  $this->object->getId(), (int) $_GET["ass_id"], (int) $_GET["member_id"], true))
796  {
797  $this->ctrl->redirect($this, "members");
798  }
799  exit;
800  }
801 
806  {
807  if(!strlen(trim($_POST['user_login'])))
808  {
809  ilUtil::sendFailure($this->lng->txt('msg_no_search_string'));
810  $this->membersObject();
811  return false;
812  }
813  $users = explode(',', $_POST['user_login']);
814 
815  $user_ids = array();
816  foreach($users as $user)
817  {
818  $user_id = ilObjUser::_lookupId($user);
819 
820  if(!$user_id)
821  {
822  ilUtil::sendFailure($this->lng->txt('user_not_known'));
823  return $this->membersObject();
824  }
825  $user_ids[] = $user_id;
826  }
827 
828  if(!$this->addMembersObject($user_ids));
829  {
830  $this->membersObject();
831  return false;
832  }
833  return true;
834  }
835 
839  function addMembersObject($a_user_ids = array())
840  {
841  global $ilAccess,$ilErr;
842 
843  $this->checkPermission("write");
844  if(!count($a_user_ids))
845  {
846  ilUtil::sendFailure($this->lng->txt("no_checkbox"));
847  return false;
848  }
849 
850  if(!$this->object->members_obj->assignMembers($a_user_ids))
851  {
852  ilUtil::sendFailure($this->lng->txt("exc_members_already_assigned"));
853  return false;
854  }
855  else
856  {
857  ilUtil::sendSuccess($this->lng->txt("exc_members_assigned"),true);
858  }
859 //exit;
860  $this->ctrl->redirect($this, "members");
861  return true;
862  }
863 
864 
868  function membersObject()
869  {
870  global $rbacsystem, $tree, $tpl, $ilToolbar, $ilCtrl, $ilTabs, $lng;
871 
872  $ilTabs->activateTab("grades");
873 
874  include_once 'Services/Tracking/classes/class.ilLPMarks.php';
875 
876  $this->checkPermission("write");
877  $this->addSubmissionSubTabs("assignment");
878 
879  // assignment selection
880  include_once("./Modules/Exercise/classes/class.ilExAssignment.php");
881  $ass = ilExAssignment::getAssignmentDataOfExercise($this->object->getId());
882 
883  if ($_GET["ass_id"] == "")
884  {
885  $a = current($ass);
886  $_GET["ass_id"] = $a["id"];
887  }
888 
889  reset($ass);
890  if (count($ass) > 1)
891  {
892  $options = array();
893  foreach ($ass as $a)
894  {
895  $options[$a["id"]] = $a["title"];
896  }
897  include_once("./Services/Form/classes/class.ilSelectInputGUI.php");
898  $si = new ilSelectInputGUI($this->lng->txt(""), "ass_id");
899  $si->setOptions($options);
900  $si->setValue($_GET["ass_id"]);
901  $ilToolbar->addInputItem($si);
902 
903  $ilToolbar->setFormAction($ilCtrl->getFormAction($this));
904  $ilToolbar->addFormButton($this->lng->txt("exc_select_ass"),
905  "selectAssignment");
906  $ilToolbar->addSeparator();
907  }
908 
909  // add member
910  include_once './Services/Search/classes/class.ilRepositorySearchGUI.php';
912  $this,
913  $ilToolbar,
914  array(
915  'auto_complete_name' => $lng->txt('user'),
916  'submit_name' => $lng->txt('add')
917  )
918  );
919 
920  $ilToolbar->addSpacer();
921 
922  $ilToolbar->addButton(
923  $lng->txt("exc_search_users"),
924  $this->ctrl->getLinkTargetByClass('ilRepositorySearchGUI',''));
925  $ilToolbar->setFormAction($ilCtrl->getFormAction($this));
926 
927  // add course members button, in case the exercise is inside a course
928  $parent_id = $tree->getParentId($_GET["ref_id"]);
929  $parent_obj_id = ilObject::_lookupObjId($parent_id);
930  $type = ilObject::_lookupType($parent_obj_id);
931  while ($parent_id != 1 && $type != "crs")
932  {
933  $parent_id = $tree->getParentId($parent_id);
934  $parent_obj_id = ilObject::_lookupObjId($parent_id);
935  $type = ilObject::_lookupType($parent_obj_id);
936  }
937  if ($type == "crs")
938  {
939  $this->ctrl->setParameterByClass('ilRepositorySearchGUI', "list_obj", $parent_obj_id);
940  $this->lng->loadLanguageModule("exercise");
941 
942  $ilToolbar->addButton($this->lng->txt("exc_crs_add_members"),
943  $this->ctrl->getLinkTargetByClass('ilRepositorySearchGUI','listUsers'));
944  }
945 
946  if (count($ass) > 0)
947  {
948  include_once("./Modules/Exercise/classes/class.ilExerciseMemberTableGUI.php");
949  $exc_tab = new ilExerciseMemberTableGUI($this, "members", $this->object, $_GET["ass_id"]);
950  $tpl->setContent($exc_tab->getHTML());
951  }
952  else
953  {
954  ilUtil::sendInfo($lng->txt("exc_no_assignments_available"));
955  }
956  return;
957  }
958 
963  {
964  global $ilTabs;
965 
966  $ilTabs->activateTab("grades");
967 
968  $_GET["ass_id"] = ilUtil::stripSlashes($_POST["ass_id"]);
969  $this->membersObject();
970  }
971 
976  {
977  global $rbacsystem, $tree, $tpl, $ilToolbar, $ilCtrl, $ilTabs, $lng;
978 
979  $this->checkPermission("write");
980 
981  $ilTabs->activateTab("grades");
982  $this->addSubmissionSubTabs("participant");
983 
984  // participant selection
985  include_once("./Modules/Exercise/classes/class.ilExAssignment.php");
986  $ass = ilExAssignment::getAssignmentDataOfExercise($this->object->getId());
987  $members = $this->object->members_obj->getMembers();
988 
989  if (count($members) == 0)
990  {
991  ilUtil::sendInfo($lng->txt("exc_no_participants"));
992  return;
993  }
994 
995  $mems = array();
996  foreach ($members as $mem_id)
997  {
998  if (ilObject::_lookupType($mem_id) == "usr")
999  {
1000  include_once("./Services/User/classes/class.ilObjUser.php");
1001  $name = ilObjUser::_lookupName($mem_id);
1002  $mems[$mem_id] = $name;
1003  }
1004  }
1005 
1006  $mems = ilUtil::sortArray($mems, "lastname", "asc", false, true);
1007 
1008  if ($_GET["part_id"] == "" && count($mems) > 0)
1009  {
1010  $_GET["part_id"] = key($mems);
1011  }
1012 
1013  reset($mems);
1014  if (count($mems) > 1)
1015  {
1016  $options = array();
1017  foreach ($mems as $k => $m)
1018  {
1019  $options[$k] =
1020  $m["lastname"].", ".$m["firstname"]." [".$m["login"]."]";
1021  }
1022  include_once("./Services/Form/classes/class.ilSelectInputGUI.php");
1023  $si = new ilSelectInputGUI($this->lng->txt(""), "part_id");
1024  $si->setOptions($options);
1025  $si->setValue($_GET["part_id"]);
1026  $ilToolbar->addInputItem($si);
1027 
1028  $ilToolbar->setFormAction($ilCtrl->getFormAction($this));
1029  $ilToolbar->addFormButton($this->lng->txt("exc_select_part"),
1030  "selectParticipant");
1031  }
1032 
1033  if (count($mems) > 0)
1034  {
1035  include_once("./Modules/Exercise/classes/class.ilExParticipantTableGUI.php");
1036  $part_tab = new ilExParticipantTableGUI($this, "showParticipant",
1037  $this->object, $_GET["part_id"]);
1038  $tpl->setContent($part_tab->getHTML());
1039  }
1040  else
1041  {
1042  ilUtil::sendInfo($this->lng->txt("exc_no_assignments_available"));
1043  }
1044  }
1045 
1050  {
1051  global $ilTabs;
1052 
1053  $ilTabs->activateTab("grades");
1054 
1055  $_GET["part_id"] = ilUtil::stripSlashes($_POST["part_id"]);
1056  $this->showParticipantObject();
1057  }
1058 
1063  {
1064  global $rbacsystem, $tree, $tpl, $ilToolbar, $ilCtrl, $ilTabs, $lng;
1065 
1066  $this->checkPermission("write");
1067 
1068  $ilTabs->activateTab("grades");
1069  $this->addSubmissionSubTabs("grades");
1070 
1071  include_once("./Modules/Exercise/classes/class.ilExAssignment.php");
1072  $mem_obj = new ilExerciseMembers($this->object);
1073  $mems = $mem_obj->getMembers();
1074 
1075  if (count($mems) > 0)
1076  {
1077  $ilToolbar->addButton($lng->txt("exc_export_excel"),
1078  $ilCtrl->getLinkTarget($this, "exportExcel"));
1079  }
1080 
1081  include_once("./Modules/Exercise/classes/class.ilExGradesTableGUI.php");
1082  $grades_tab = new ilExGradesTableGUI($this, "showGradesOverview",
1083  $this->object, $mem_obj);
1084  $tpl->setContent($grades_tab->getHTML());
1085  }
1086 
1091  {
1092  $this->checkPermission("write");
1093 
1094  if ($_GET["member_id"] != "")
1095  {
1096  ilExAssignment::updateStatusFeedbackForUser((int) $_GET["ass_id"], (int) $_GET["member_id"], 1);
1097  $login = ilObjUser::_lookupLogin((int) $_GET["member_id"]);
1098 
1099  require_once 'Services/Mail/classes/class.ilMailFormCall.php';
1100  ilUtil::redirect(ilMailFormCall::_getRedirectTarget($this, 'members', array(), array('type' => 'new', 'rcp_to' => urlencode($login))));
1101  }
1102  else if(count($_POST["member"]) > 0)
1103  {
1104  include_once('./Services/User/classes/class.ilObjUser.php');
1105  $logins = array();
1106  foreach($_POST["member"] as $member => $val)
1107  {
1108  $logins[] = ilObjUser::_lookupLogin($member);
1109  ilExAssignment::updateStatusFeedbackForUser((int) $_GET["ass_id"], $member, 1);
1110  }
1111  $logins = implode($logins, ",");
1112 
1113  require_once 'Services/Mail/classes/class.ilMailFormCall.php';
1114  ilUtil::redirect(ilMailFormCall::_getRedirectTarget($this, 'members', array(), array('type' => 'new', 'rcp_to' => $logins)));
1115  }
1116 
1117  ilUtil::sendFailure($this->lng->txt("no_checkbox"),true);
1118  $this->ctrl->redirect($this, "members");
1119  }
1120 
1125  {
1126  $this->checkPermission("write");
1127 
1128  $members = array();
1129 
1130  foreach($this->object->members_obj->getMembers() as $member_id)
1131  {
1132  // update download time
1133  ilExAssignment::updateTutorDownloadTime($this->object->getId(),
1134  (int) $_GET["ass_id"], $member_id);
1135 
1136  // get member object (ilObjUser)
1137  if (ilObject::_exists($member_id))
1138  {
1139  $tmp_obj =& ilObjectFactory::getInstanceByObjId($member_id);
1140  $members[$member_id] = $tmp_obj->getFirstname() . " " . $tmp_obj->getLastname();
1141  unset($tmp_obj);
1142  }
1143  }
1144 
1145  ilExAssignment::downloadAllDeliveredFiles($this->object->getId(),
1146  (int) $_GET["ass_id"], $members);
1147  exit;
1148  }
1149 
1150 
1151  function __getMembersOfObject($a_result,$a_type)
1152  {
1153 
1154  switch($a_type)
1155  {
1156  case "usr":
1157  return $a_result;
1158  case "grp":
1159  include_once "./Modules/Group/classes/class.ilObjGroup.php";
1160 
1161  $all_members = array();
1162  foreach($a_result as $group)
1163  {
1164  $tmp_grp_obj = ilObjectFactory::getInstanceByRefId($group["id"]);
1165 
1166  $members = $tmp_grp_obj->getGroupMemberIds();
1167  $all_members = array_merge($all_members,$members);
1168  }
1169  // FORMAT ARRAY
1170  $all_members = array_unique($all_members);
1171  foreach($all_members as $member)
1172  {
1173  $result[] = array("id" => $member);
1174  }
1175  return $result;
1176  }
1177  return true;
1178  }
1179 
1180  function __showObjectSelect($a_result,$a_type)
1181  {
1182  include_once "./classes/class.ilObjectFactory.php";
1183 
1184  foreach($a_result as $obj)
1185  {
1186  $tmp_obj =& ilObjectFactory::getInstanceByRefId($obj["id"]);
1187  $this->tpl->setCurrentBlock("OBJ_SELECT_ROW");
1188  $this->tpl->setVariable("OBJ_ROW_TITLE",$tmp_obj->getTitle());
1189  $this->tpl->setVariable("OBJ_ROW_ID",$tmp_obj->getRefId());
1190  $this->tpl->setVariable("OBJ_ROW_DESCRIPTION",$tmp_obj->getDescription());
1191  $this->tpl->parseCurrentBlock();
1192 
1193  unset($tmp_obj);
1194  }
1195  $this->tpl->setCurrentBlock("OBJ_SELECT");
1196  $this->tpl->setVariable("OBJ_SELECT_TITLE",$this->lng->txt("title"));
1197  $this->tpl->setVariable("OBJ_SELECT_DESCRIPTION",$this->lng->txt("description"));
1198 
1199  $this->tpl->setVariable("OBJ_BTN1_VALUE",$this->lng->txt("select"));
1200  $this->tpl->setVariable("OBJ_BTN2_VALUE",$this->lng->txt("cancel"));
1201  $this->tpl->parseCurrentBlock();
1202  }
1203 
1208  {
1209  global $ilCtrl;
1210 
1211  $this->checkPermission("write");
1212 
1213  if(!count($_POST["member"]))
1214  {
1215  ilUtil::sendFailure($this->lng->txt("no_checkbox"),true);
1216  }
1217  else
1218  {
1219  $this->object->sendAssignment($this->object->getId(),
1220  (int) $_GET["ass_id"], $_POST["member"]);
1221  ilUtil::sendSuccess($this->lng->txt("exc_sent"),true);
1222  }
1223  $ilCtrl->redirect($this, "members");
1224  }
1225 
1230  {
1231  global $ilCtrl, $tpl, $lng, $ilTabs;
1232 
1233  $this->checkPermission("write");
1234  $ilTabs->activateTab("grades");
1235 
1236  if (!is_array($_POST["member"]) || count($_POST["member"]) == 0)
1237  {
1238  ilUtil::sendFailure($lng->txt("no_checkbox"), true);
1239  $ilCtrl->redirect($this, "members");
1240  }
1241  else
1242  {
1243  include_once("./Services/Utilities/classes/class.ilConfirmationGUI.php");
1244  $cgui = new ilConfirmationGUI();
1245  $cgui->setFormAction($ilCtrl->getFormAction($this));
1246  $cgui->setHeaderText($lng->txt("exc_msg_sure_to_deassign_participant"));
1247  $cgui->setCancel($lng->txt("cancel"), "members");
1248  $cgui->setConfirm($lng->txt("remove"), "deassignMembers");
1249 
1250  include_once("./Services/User/classes/class.ilUserUtil.php");
1251  foreach ($_POST["member"] as $k => $m)
1252  {
1253  $cgui->addItem("member[$k]", $m,
1254  ilUserUtil::getNamePresentation((int) $k, false, false, "", true));
1255  }
1256 
1257  $tpl->setContent($cgui->getHTML());
1258  }
1259  }
1260 
1265  {
1266  global $ilCtrl, $lng;
1267 
1268  $this->checkPermission("write");
1269 
1270  if(is_array($_POST["member"]))
1271  {
1272  foreach($_POST["member"] as $usr_id => $member)
1273  {
1274  $this->object->members_obj->deassignMember((int) $usr_id);
1275  }
1276  ilUtil::sendSuccess($lng->txt("exc_msg_participants_removed"), true);
1277  $ilCtrl->redirect($this, "members");
1278  }
1279  else
1280  {
1281  ilUtil::sendFailure($this->lng->txt("no_checkbox"),true);
1282  $ilCtrl->redirect($this, "members");
1283  }
1284  }
1285 
1287  {
1288  $this->checkPermission("write");
1289 
1290  if(!isset($_POST['comments_value']))
1291  {
1292  continue;
1293  }
1294 
1295  $this->object->members_obj->setNoticeForMember($_GET["member_id"],
1296  ilUtil::stripSlashes($_POST["comments_value"]));
1297  ilUtil::sendSuccess($this->lng->txt("exc_members_comments_saved"));
1298  $this->membersObject();
1299  }
1300 
1301 
1306  {
1307  $this->saveStatusObject(true);
1308  }
1309 
1310 
1314  function saveStatusObject($a_part_view = false)
1315  {
1316  global $ilCtrl;
1317 
1318  $this->checkPermission("write");
1319 
1320  include_once("./Modules/Exercise/classes/class.ilExAssignment.php");
1321 
1322 // include_once 'Services/Tracking/classes/class.ilLPMarks.php';
1323 
1324  $saved_for = array();
1325 
1326  foreach($_POST["id"] as $key => $value)
1327  {
1328  if (!$a_part_view)
1329  {
1330  if (count($_POST["member"]) > 0 && $_POST["member"][$key] != "1")
1331  {
1332  continue;
1333  }
1334  else
1335  {
1336  if (count($_POST["member"]) > 0)
1337  {
1338  $uname = ilObjUser::_lookupName($key);
1339  $saved_for[] = $uname["lastname"].", ".$uname["firstname"];
1340  }
1341  }
1342  }
1343  if (!$a_part_view)
1344  {
1345  $ass_id = (int) $_GET["ass_id"];
1346  $user_id = (int) $key;
1347  }
1348  else
1349  {
1350  $ass_id = (int) $key;
1351  $user_id = (int) $_GET["part_id"];
1352  }
1353  ilExAssignment::updateStatusOfUser($ass_id, $user_id,
1354  ilUtil::stripSlashes($_POST["status"][$key]));
1355  ilExAssignment::updateNoticeForUser($ass_id, $user_id,
1356  ilUtil::stripSlashes($_POST["notice"][$key]));
1357 
1358  if (ilUtil::stripSlashes($_POST['mark'][$key]) !=
1359  ilExAssignment::lookupMarkOfUser($ass_id, $user_id))
1360  {
1361  ilExAssignment::updateStatusTimeOfUser($ass_id, $user_id);
1362  }
1363 
1364  ilExAssignment::updateMarkOfUser($ass_id, $user_id,
1365  ilUtil::stripSlashes($_POST['mark'][$key]));
1366  ilExAssignment::updateCommentForUser($ass_id, $user_id,
1367  ilUtil::stripSlashes($_POST['lcomment'][$key]));
1368 
1369  }
1370  if (count($saved_for) > 0)
1371  {
1372  $save_for_str = "(".implode($saved_for, " - ").")";
1373  }
1374  ilUtil::sendSuccess($this->lng->txt("exc_status_saved")." ".$save_for_str,true);
1375  if (!$a_part_view)
1376  {
1377  $ilCtrl->redirect($this, "members");
1378  }
1379  else
1380  {
1381  $ilCtrl->redirect($this, "showParticipant");
1382  }
1383  }
1384 
1385  function __getDateSelect($a_type,$a_selected)
1386  {
1387  switch($a_type)
1388  {
1389  case "hour":
1390  for($i=0; $i<24; $i++)
1391  {
1392  $hours[$i] = $i < 10 ? "0".$i : $i;
1393  }
1394  return ilUtil::formSelect($a_selected,"d_hour",$hours,false,true);
1395 
1396  case "minutes":
1397  for($i=0;$i<60;$i++)
1398  {
1399  $minutes[$i] = $i < 10 ? "0".$i : $i;
1400  }
1401  return ilUtil::formSelect($a_selected,"d_minutes",$minutes,false,true);
1402 
1403  case "day":
1404  for($i=1; $i<32; $i++)
1405  {
1406  $days[$i] = $i < 10 ? "0".$i : $i;
1407  }
1408  return ilUtil::formSelect($a_selected,"d_day",$days,false,true);
1409 
1410  case "month":
1411  for($i=1; $i<13; $i++)
1412  {
1413  $month[$i] = $i < 10 ? "0".$i : $i;
1414  }
1415  return ilUtil::formSelect($a_selected,"d_month",$month,false,true);
1416 
1417  case "year":
1418  for($i = date("Y",time());$i < date("Y",time()) + 3;++$i)
1419  {
1420  $year[$i] = $i;
1421  }
1422  return ilUtil::formSelect($a_selected,"d_year",$year,false,true);
1423  }
1424  }
1425 
1426  function __filterAssignedUsers($a_result)
1427  {
1428  foreach($a_result as $user)
1429  {
1430  if(!$this->object->members_obj->isAssigned($user["id"]))
1431  {
1432  $filtered[] = $user;
1433  }
1434  }
1435 
1436  return $filtered ? $filtered : array();
1437  }
1438 
1444  function addSubmissionSubTabs($a_activate)
1445  {
1446  global $ilTabs, $lng, $ilCtrl;
1447 
1448  $ilTabs->addSubTab("assignment", $lng->txt("exc_assignment_view"),
1449  $ilCtrl->getLinkTarget($this, "members"));
1450  $ilTabs->addSubTab("participant", $lng->txt("exc_participant_view"),
1451  $ilCtrl->getLinkTarget($this, "showParticipant"));
1452  $ilTabs->addSubTab("grades", $lng->txt("exc_grades_overview"),
1453  $ilCtrl->getLinkTarget($this, "showGradesOverview"));
1454  $ilTabs->activateSubTab($a_activate);
1455  }
1456 
1462  function addContentSubTabs($a_activate)
1463  {
1464  global $ilTabs, $lng, $ilCtrl, $ilAccess;
1465 
1466  $ilTabs->addSubTab("content", $lng->txt("view"),
1467  $ilCtrl->getLinkTarget($this, "showOverview"));
1468  if ($ilAccess->checkAccess("write", "", $this->ref_id))
1469  {
1470  $ilTabs->addSubTab("list_assignments", $lng->txt("edit"),
1471  $ilCtrl->getLinkTarget($this, "listAssignments"));
1472  }
1473  $ilTabs->activateSubTab($a_activate);
1474  }
1475 
1476 
1482  function getTabs($tabs_gui)
1483  {
1484  global $ilAccess, $ilUser, $lng;
1485 
1486  if ($ilAccess->checkAccess("read", "", $this->object->getRefId()))
1487  {
1488  $tabs_gui->addTab("content",
1489  $lng->txt("exc_assignments"),
1490  $this->ctrl->getLinkTarget($this, "showOverview"));
1491  }
1492 
1493  $next_class = strtolower($this->ctrl->getNextClass());
1494  if ($ilAccess->checkAccess("visible", "", $this->object->getRefId()))
1495  {
1496  $tabs_gui->addTab("info",
1497  $lng->txt("info_short"),
1498  $this->ctrl->getLinkTargetByClass("ilinfoscreengui", "showSummary"));
1499  }
1500 
1501  // edit properties
1502  if ($ilAccess->checkAccess("write", "", $this->ref_id))
1503  {
1504  /*$tabs_gui->addTab("assignments",
1505  $lng->txt("exc_edit_assignments"),
1506  $this->ctrl->getLinkTarget($this, 'listAssignments'));*/
1507 
1508  $tabs_gui->addTab("settings",
1509  $lng->txt("settings"),
1510  $this->ctrl->getLinkTarget($this, 'edit'));
1511 
1512  $tabs_gui->addTab("grades",
1513  $lng->txt("exc_submissions_and_grades"),
1514  $this->ctrl->getLinkTarget($this, 'members'));
1515  }
1516 
1517  // learning progress
1518  $save_sort_order = $_GET["sort_order"]; // hack, because exercise sort parameters
1519  $save_sort_by = $_GET["sort_by"]; // must not be forwarded to learning progress
1520  $save_offset = $_GET["offset"];
1521  $_GET["offset"] = $_GET["sort_by"] = $_GET["sort_order"] = "";
1522 
1523  include_once './Services/Tracking/classes/class.ilLearningProgressAccess.php';
1524  if(ilLearningProgressAccess::checkAccess($this->object->getRefId()))
1525  {
1526  $tabs_gui->addTab('learning_progress',
1527  $lng->txt('learning_progress'),
1528  $this->ctrl->getLinkTargetByClass(array('ilobjexercisegui','illearningprogressgui'),''));
1529  }
1530 
1531  $_GET["sort_order"] = $save_sort_order; // hack, part ii
1532  $_GET["sort_by"] = $save_sort_by;
1533  $_GET["offset"] = $save_offset;
1534 
1535  // export
1536  if ($ilAccess->checkAccess("write", "", $this->object->getRefId()))
1537  {
1538  $tabs_gui->addTab("export",
1539  $lng->txt("export"),
1540  $this->ctrl->getLinkTargetByClass("ilexportgui", ""));
1541  }
1542 
1543 
1544  // permissions
1545  if ($ilAccess->checkAccess("edit_permission", "", $this->ref_id))
1546  {
1547  $tabs_gui->addTab('permissions',
1548  $lng->txt("perm_settings"),
1549  $this->ctrl->getLinkTargetByClass(array(get_class($this),'ilpermissiongui'), "perm"));
1550  }
1551  }
1552 
1558  function infoScreenObject()
1559  {
1560  $this->ctrl->setCmd("showSummary");
1561  $this->ctrl->setCmdClass("ilinfoscreengui");
1562  $this->infoScreen();
1563  }
1564 
1568  function infoScreen()
1569  {
1570  global $ilAccess, $ilUser, $ilTabs, $lng;
1571 
1572  $ilTabs->activateTab("info");
1573 
1574  $this->checkPermission("visible");
1575 
1576  include_once("./Services/InfoScreen/classes/class.ilInfoScreenGUI.php");
1577  $info = new ilInfoScreenGUI($this);
1578 
1579  $info->enablePrivateNotes();
1580 
1581  $info->enableNews();
1582  if ($ilAccess->checkAccess("write", "", $_GET["ref_id"]))
1583  {
1584  $info->enableNewsEditing();
1585  $info->setBlockProperty("news", "settings", true);
1586  }
1587 
1588  // standard meta data
1589  //$info->addMetaDataSections($this->object->getId(),0, $this->object->getType());
1590 
1591  // instructions
1592  $info->addSection($this->lng->txt("exc_overview"));
1593  include_once("./Modules/Exercise/classes/class.ilExAssignment.php");
1594  $ass = ilExAssignment::getAssignmentDataOfExercise($this->object->getId());
1595  $cnt = 0;
1596  $mcnt = 0;
1597  foreach ($ass as $a)
1598  {
1599  $cnt++;
1600  if ($a["mandatory"])
1601  {
1602  $mcnt++;
1603  }
1604  }
1605  $info->addProperty($lng->txt("exc_assignments"), $cnt);
1606  $info->addProperty($lng->txt("exc_mandatory"), $mcnt);
1607  if ($this->object->getPassMode() != "nr")
1608  {
1609  $info->addProperty($lng->txt("exc_pass_mode"),
1610  $lng->txt("exc_msg_all_mandatory_ass"));
1611  }
1612  else
1613  {
1614  $info->addProperty($lng->txt("exc_pass_mode"),
1615  sprintf($lng->txt("exc_msg_min_number_ass"), $this->object->getPassNr()));
1616  }
1617 
1618  // feedback from tutor
1619  include_once("Services/Tracking/classes/class.ilLPMarks.php");
1620  if ($ilAccess->checkAccess("read", "", $this->ref_id))
1621  {
1622  $lpcomment = ilLPMarks::_lookupComment($ilUser->getId(), $this->object->getId());
1623  $mark = ilLPMarks::_lookupMark($ilUser->getId(), $this->object->getId());
1624  //$status = ilExerciseMembers::_lookupStatus($this->object->getId(), $ilUser->getId());
1625  $st = $this->object->determinStatusOfUser($ilUser->getId());
1626  $status = $st["overall_status"];
1627  if ($lpcomment != "" || $mark != "" || $status != "notgraded")
1628  {
1629  $info->addSection($this->lng->txt("exc_feedback_from_tutor"));
1630  if ($lpcomment != "")
1631  {
1632  $info->addProperty($this->lng->txt("exc_comment"),
1633  $lpcomment);
1634  }
1635  if ($mark != "")
1636  {
1637  $info->addProperty($this->lng->txt("exc_mark"),
1638  $mark);
1639  }
1640 
1641  //if ($status == "")
1642  //{
1643  // $info->addProperty($this->lng->txt("status"),
1644  // $this->lng->txt("message_no_delivered_files"));
1645  //}
1646  //else
1647  if ($status != "notgraded")
1648  {
1649  $img = '<img border="0" src="'.ilUtil::getImagePath("scorm/".$status.".gif").'" '.
1650  ' alt="'.$lng->txt("exc_".$status).'" title="'.$lng->txt("exc_".$status).
1651  '" style="vertical-align:middle;"/>';
1652 
1653  $add = "";
1654  if ($st["failed_a_mandatory"])
1655  {
1656  $add = " (".$lng->txt("exc_msg_failed_mandatory").")";
1657  }
1658  else if ($status == "failed")
1659  {
1660  $add = " (".$lng->txt("exc_msg_missed_minimum_number").")";
1661  }
1662  $info->addProperty($this->lng->txt("status"),
1663  $img." ".$this->lng->txt("exc_".$status).$add);
1664  }
1665  }
1666  }
1667 
1668  // forward the command
1669  $this->ctrl->forwardCommand($info);
1670  }
1671 
1672  function editObject()
1673  {
1674  $this->setSettingsSubTabs();
1675  $this->tabs_gui->activateSubTab("edit");
1676  return parent::editObject();
1677  }
1678 
1679  protected function setSettingsSubTabs()
1680  {
1681  $this->tabs_gui->addSubTab("edit",
1682  $this->lng->txt("general_settings"),
1683  $this->ctrl->getLinkTarget($this, "edit"));
1684 
1685  include_once './Services/WebServices/RPC/classes/class.ilRPCServerSettings.php';
1686  if(ilRPCServerSettings::getInstance()->isEnabled())
1687  {
1688  $this->tabs_gui->addSubTab("certificate",
1689  $this->lng->txt("certificate"),
1690  $this->ctrl->getLinkTarget($this, "certificate"));
1691  }
1692  }
1693 
1699  function _goto($a_target)
1700  {
1701  global $rbacsystem, $ilErr, $lng, $ilAccess;
1702 
1703  if ($ilAccess->checkAccess("read", "", $a_target))
1704  {
1705  $_GET["ref_id"] = $a_target;
1706  $_GET["cmd"] = "showOverview";
1707  $_GET["baseClass"] = "ilExerciseHandlerGUI";
1708  include("ilias.php");
1709  exit;
1710  }
1711  else if ($ilAccess->checkAccess("visible", "", $a_target))
1712  {
1713  $_GET["ref_id"] = $a_target;
1714  $_GET["cmd"] = "infoScreen";
1715  $_GET["baseClass"] = "ilExerciseHandlerGUI";
1716  include("ilias.php");
1717  exit;
1718  }
1719  else if ($ilAccess->checkAccess("read", "", ROOT_FOLDER_ID))
1720  {
1721  $_GET["cmd"] = "frameset";
1722  $_GET["target"] = "";
1723  $_GET["ref_id"] = ROOT_FOLDER_ID;
1724  ilUtil::sendFailure(sprintf($lng->txt("msg_no_perm_read_item"),
1725  ilObject::_lookupTitle(ilObject::_lookupObjId($a_target))), true);
1726  include("repository.php");
1727  exit;
1728  }
1729 
1730  $ilErr->raiseError($lng->txt("msg_no_perm_read"), $ilErr->FATAL);
1731  }
1732 
1736  function addLocatorItems()
1737  {
1738  global $ilLocator;
1739 
1740  if (is_object($this->object))
1741  {
1742  $ilLocator->addItem($this->object->getTitle(), $this->ctrl->getLinkTarget($this, "infoScreen"), "", $_GET["ref_id"]);
1743  }
1744  }
1745 
1749 
1754  {
1755  global $tpl, $ilTabs, $ilToolbar, $lng, $ilCtrl;
1756 
1757  $this->checkPermission("write");
1758 
1759  $ilTabs->activateTab("content");
1760  $this->addContentSubTabs("list_assignments");
1761 
1762  $ilToolbar->addButton($lng->txt("exc_add_assignment"),
1763  $ilCtrl->getLinkTarget($this, "addAssignment"));
1764 
1765  include_once("./Modules/Exercise/classes/class.ilAssignmentsTableGUI.php");
1766  $t = new ilAssignmentsTableGUI($this, "listAssignments", $this->object);
1767  $tpl->setContent($t->getHTML());
1768  }
1769 
1774  {
1775  global $tpl, $ilTabs;
1776 
1777  $this->checkPermission("write");
1778 
1779  $ilTabs->activateTab("content");
1780  $this->addContentSubTabs("list_assignments");
1781 
1782  $this->initAssignmentForm("create");
1783  $tpl->setContent($this->form->getHTML());
1784  }
1785 
1791  public function initAssignmentForm($a_mode = "create")
1792  {
1793  global $lng, $ilCtrl, $ilSetting;
1794 
1795  // init form
1796  $lng->loadLanguageModule("form");
1797  include_once("./Services/Form/classes/class.ilPropertyFormGUI.php");
1798  $this->form = new ilPropertyFormGUI();
1799  $this->form->setTableWidth("600px");
1800  if ($a_mode == "edit")
1801  {
1802  $this->form->setTitle($lng->txt("exc_edit_assignment"));
1803  }
1804  else
1805  {
1806  $this->form->setTitle($lng->txt("exc_new_assignment"));
1807  }
1808  $this->form->setFormAction($ilCtrl->getFormAction($this));
1809 
1810  // type
1811  include_once("./Modules/Exercise/classes/class.ilExAssignment.php");
1812  $types = array(ilExAssignment::TYPE_UPLOAD => $this->lng->txt("exc_type_upload"));
1813  if(!$ilSetting->get('disable_wsp_blogs'))
1814  {
1815  $types[ilExAssignment::TYPE_BLOG] = $this->lng->txt("exc_type_blog");
1816  }
1817  if($ilSetting->get('user_portfolios'))
1818  {
1819  $types[ilExAssignment::TYPE_PORTFOLIO] = $this->lng->txt("exc_type_portfolio");
1820  }
1821  if(sizeof($types) > 1)
1822  {
1823  $ty = new ilSelectInputGUI($this->lng->txt("type"), "type");
1824  $ty->setOptions($types);
1825  $ty->setRequired(true);
1826  }
1827  else
1828  {
1829  $ty = new ilHiddenInputGUI("type");
1830  $ty->setValue(ilExAssignment::TYPE_UPLOAD);
1831  }
1832  $this->form->addItem($ty);
1833 
1834  // title
1835  $ti = new ilTextInputGUI($this->lng->txt("title"), "title");
1836  $ti->setMaxLength(200);
1837  $ti->setRequired(true);
1838  $this->form->addItem($ti);
1839 
1840  // start time y/n
1841  $cb = new ilCheckboxInputGUI($this->lng->txt("exc_start_time"), "start_time_cb");
1842  $this->form->addItem($cb);
1843 
1844  // start time
1845  $edit_date = new ilDateTimeInputGUI("", "start_time");
1846  $edit_date->setShowTime(true);
1847  $cb->addSubItem($edit_date);
1848 
1849  // Deadline
1850  $edit_date = new ilDateTimeInputGUI($lng->txt("exc_deadline"), "deadline");
1851  $edit_date->setShowTime(true);
1852  $edit_date->setRequired(true);
1853  $this->form->addItem($edit_date);
1854 
1855  // mandatory
1856  $cb = new ilCheckboxInputGUI($this->lng->txt("exc_mandatory"), "mandatory");
1857  $cb->setInfo($this->lng->txt("exc_mandatory_info"));
1858  $cb->setChecked(true);
1859  $this->form->addItem($cb);
1860 
1861  // Work Instructions
1862  $desc_input = new ilTextAreaInputGUI($lng->txt("exc_instruction"), "instruction");
1863  $desc_input->setRows(5);
1864  $this->form->addItem($desc_input);
1865 
1866  // files
1867  if ($a_mode == "create")
1868  {
1869  $files = new ilFileWizardInputGUI($this->lng->txt('objs_file'),'files');
1870  $files->setFilenames(array(0 => ''));
1871  $this->form->addItem($files);
1872  }
1873 
1874  // save and cancel commands
1875  if ($a_mode == "create")
1876  {
1877  $this->form->addCommandButton("saveAssignment", $lng->txt("save"));
1878  $this->form->addCommandButton("listAssignments", $lng->txt("cancel"));
1879  }
1880  else
1881  {
1882  $this->form->addCommandButton("updateAssignment", $lng->txt("save"));
1883  $this->form->addCommandButton("listAssignments", $lng->txt("cancel"));
1884  }
1885  }
1886 
1891  public function saveAssignmentObject()
1892  {
1893  global $tpl, $lng, $ilCtrl, $ilTabs;
1894 
1895  $this->checkPermission("write");
1896 
1897  $ilTabs->activateTab("content");
1898  $this->addContentSubTabs("list_assignments");
1899 
1900  $this->initAssignmentForm("create");
1901  if ($this->form->checkInput())
1902  {
1903  include_once("./Modules/Exercise/classes/class.ilExAssignment.php");
1904 
1905  // additional checks
1906  if ($_POST["start_time_cb"])
1907  {
1908  // check whether start date is before end date
1909  $start_date =
1910  $this->form->getItemByPostVar("start_time")->getDate();
1911  $end_date =
1912  $this->form->getItemByPostVar("deadline")->getDate();
1913  if ($start_date->get(IL_CAL_UNIX) >=
1914  $end_date->get(IL_CAL_UNIX))
1915  {
1916  ilUtil::sendFailure($lng->txt("form_input_not_valid"), true);
1917  $this->form->getItemByPostVar("start_time")
1918  ->setAlert($lng->txt("exc_start_date_should_be_before_end_date"));
1919  $this->form->getItemByPostVar("deadline")
1920  ->setAlert($lng->txt("exc_start_date_should_be_before_end_date"));
1921  $this->form->setValuesByPost();
1922  $tpl->setContent($this->form->getHtml());
1923  return;
1924  }
1925  }
1926 
1927  $ass = new ilExAssignment();
1928  $ass->setTitle($_POST["title"]);
1929  $ass->setInstruction($_POST["instruction"]);
1930  $ass->setExerciseId($this->object->getId());
1931  $ass->setMandatory($_POST["mandatory"]);
1932  $ass->setType($_POST["type"]);
1933 
1934  if ($_POST["start_time_cb"])
1935  {
1936  $date =
1937  $this->form->getItemByPostVar("start_time")->getDate();
1938  $ass->setStartTime($date->get(IL_CAL_UNIX));
1939  }
1940  else
1941  {
1942  $ass->setStartTime(null);
1943  }
1944 
1945  // deadline
1946  $date =
1947  $this->form->getItemByPostVar("deadline")->getDate();
1948  $ass->setDeadline($date->get(IL_CAL_UNIX));
1949 
1950  $ass->save();
1951 
1952  // save files
1953  $ass->uploadAssignmentFiles($_FILES["files"]);
1954 
1955 
1956  ilUtil::sendSuccess($lng->txt("msg_obj_modified"), true);
1957  $ilCtrl->redirect($this, "listAssignments");
1958  }
1959  else
1960  {
1961  $this->form->setValuesByPost();
1962  $tpl->setContent($this->form->getHtml());
1963  }
1964  }
1965 
1970  {
1971  global $tpl, $ilTabs, $tpl;
1972 
1973  $this->checkPermission("write");
1974 
1975  $this->setAssignmentHeader();
1976  $ilTabs->activateTab("ass_settings");
1977 
1978  $this->initAssignmentForm("edit");
1979  $this->getAssignmentValues();
1980  $tpl->setContent($this->form->getHTML());
1981  }
1982 
1987  public function getAssignmentValues()
1988  {
1989  $values = array();
1990 
1991  $ass = new ilExAssignment($_GET["ass_id"]);
1992  $values["title"] = $ass->getTitle();
1993  if ($ass->getStartTime() > 0)
1994  {
1995  $values["start_time_cb"] = true;
1996  }
1997  $values["mandatory"] = $ass->getMandatory();
1998  $values["instruction"] = $ass->getInstruction();
1999  $values["type"] = $ass->getType();
2000 
2001  $this->form->setValuesByArray($values);
2002 
2003  $edit_date = new ilDateTime($ass->getDeadline(), IL_CAL_UNIX);
2004  $ed_item = $this->form->getItemByPostVar("deadline");
2005  $ed_item->setDate($edit_date);
2006 
2007  if ($ass->getStartTime() > 0)
2008  {
2009  $edit_date = new ilDateTime($ass->getStartTime(), IL_CAL_UNIX);
2010  $ed_item = $this->form->getItemByPostVar("start_time");
2011  $ed_item->setDate($edit_date);
2012  }
2013 
2014  // if there are any submissions we cannot change type anymore
2015  if(sizeof(ilExAssignment::getAllDeliveredFiles($this->object->getId(), $ass->getId())))
2016  {
2017  $this->form->getItemByPostVar("type")->setDisabled(true);
2018  }
2019 
2020  }
2021 
2026  public function updateAssignmentObject()
2027  {
2028  global $tpl, $lng, $ilCtrl, $ilTabs;
2029 
2030  $this->checkPermission("write");
2031 
2032  $ilTabs->activateTab("content");
2033  $this->addContentSubTabs("list_assignments");
2034 
2035  $this->initAssignmentForm("edit");
2036  if ($this->form->checkInput())
2037  {
2038  include_once("./Modules/Exercise/classes/class.ilExAssignment.php");
2039 
2040  // additional checks
2041  if ($_POST["start_time_cb"])
2042  {
2043  // check whether start date is before end date
2044  $start_date =
2045  $this->form->getItemByPostVar("start_time")->getDate();
2046  $end_date =
2047  $this->form->getItemByPostVar("deadline")->getDate();
2048  if ($start_date->get(IL_CAL_UNIX) >=
2049  $end_date->get(IL_CAL_UNIX))
2050  {
2051  ilUtil::sendFailure($lng->txt("form_input_not_valid"), true);
2052  $this->form->getItemByPostVar("start_time")
2053  ->setAlert($lng->txt("exc_start_date_should_be_before_end_date"));
2054  $this->form->getItemByPostVar("deadline")
2055  ->setAlert($lng->txt("exc_start_date_should_be_before_end_date"));
2056  $this->form->setValuesByPost();
2057  $tpl->setContent($this->form->getHtml());
2058  return;
2059  }
2060  }
2061 
2062 
2063  $ass = new ilExAssignment($_GET["ass_id"]);
2064  $ass->setTitle($_POST["title"]);
2065  $ass->setInstruction($_POST["instruction"]);
2066  $ass->setExerciseId($this->object->getId());
2067  $ass->setMandatory($_POST["mandatory"]);
2068  $ass->setType($_POST["type"]);
2069 
2070  if ($_POST["start_time_cb"])
2071  {
2072  $date =
2073  $this->form->getItemByPostVar("start_time")->getDate();
2074  $ass->setStartTime($date->get(IL_CAL_UNIX));
2075  }
2076  else
2077  {
2078  $ass->setStartTime(null);
2079  }
2080 
2081  // deadline
2082  $date =
2083  $this->form->getItemByPostVar("deadline")->getDate();
2084  $ass->setDeadline($date->get(IL_CAL_UNIX));
2085 
2086  $ass->update();
2087  ilUtil::sendSuccess($lng->txt("msg_obj_modified"), true);
2088  $ilCtrl->redirect($this, "listAssignments");
2089  }
2090  else
2091  {
2092  $this->form->setValuesByPost();
2093  $tpl->setContent($this->form->getHtml());
2094  }
2095  }
2096 
2097 
2102  {
2103  global $ilCtrl, $tpl, $lng, $ilTabs;
2104 
2105  $this->checkPermission("write");
2106 
2107  $ilTabs->activateTab("content");
2108  $this->addContentSubTabs("list_assignments");
2109 
2110  if (!is_array($_POST["id"]) || count($_POST["id"]) == 0)
2111  {
2112  ilUtil::sendInfo($lng->txt("no_checkbox"), true);
2113  $ilCtrl->redirect($this, "listAssignments");
2114  }
2115  else
2116  {
2117  include_once("./Services/Utilities/classes/class.ilConfirmationGUI.php");
2118  $cgui = new ilConfirmationGUI();
2119  $cgui->setFormAction($ilCtrl->getFormAction($this));
2120  $cgui->setHeaderText($lng->txt("exc_conf_del_assignments"));
2121  $cgui->setCancel($lng->txt("cancel"), "listAssignments");
2122  $cgui->setConfirm($lng->txt("delete"), "deleteAssignments");
2123 
2124  include_once("./Modules/Exercise/classes/class.ilExAssignment.php");
2125 
2126  foreach ($_POST["id"] as $i)
2127  {
2128  $cgui->addItem("id[]", $i, ilExAssignment::lookupTitle($i));
2129  }
2130 
2131  $tpl->setContent($cgui->getHTML());
2132  }
2133  }
2134 
2139  {
2140  global $ilDB, $ilCtrl, $lng;
2141 
2142  $this->checkPermission("write");
2143 
2144  $delete = false;
2145  if (is_array($_POST["id"]))
2146  {
2147  include_once("./Modules/Exercise/classes/class.ilExAssignment.php");
2148  foreach($_POST["id"] as $id)
2149  {
2150  $ass = new ilExAssignment(ilUtil::stripSlashes($id));
2151  $ass->delete();
2152  $delete = true;
2153  }
2154  }
2155 
2156  if ($delete)
2157  {
2158  ilUtil::sendSuccess($lng->txt("exc_assignments_deleted"), true);
2159  }
2160  $ilCtrl->redirect($this, "listAssignments");
2161  }
2162 
2167  {
2168  global $lng, $ilCtrl;
2169 
2170  $this->checkPermission("write");
2171 
2172  include_once("./Modules/Exercise/classes/class.ilExAssignment.php");
2173  ilExAssignment::saveAssOrderOfExercise($this->object->getId(), $_POST["order"]);
2174 
2175  ilUtil::sendSuccess($lng->txt("exc_saved_order"), true);
2176  $ilCtrl->redirect($this, "listAssignments");
2177  }
2178 
2183  {
2184  global $lng, $ilCtrl;
2185 
2186  $this->checkPermission("write");
2187 
2188  include_once("./Modules/Exercise/classes/class.ilExAssignment.php");
2189  ilExAssignment::orderAssByDeadline($this->object->getId());
2190 
2191  ilUtil::sendSuccess($lng->txt("exc_saved_order"), true);
2192  $ilCtrl->redirect($this, "listAssignments");
2193  }
2194 
2199  {
2200  global $ilTabs, $lng, $ilCtrl, $tpl;
2201 
2202  include_once("./Modules/Exercise/classes/class.ilExAssignment.php");
2203  $tpl->setTitle(ilExAssignment::lookupTitle($_GET["ass_id"]));
2204  $tpl->setDescription("");
2205 
2206  $ilTabs->clearTargets();
2207 
2208  $ilTabs->setBackTarget($lng->txt("back"),
2209  $ilCtrl->getLinkTarget($this, "listAssignments"));
2210 
2211  $ilTabs->addTab("ass_settings",
2212  $lng->txt("settings"),
2213  $ilCtrl->getLinkTarget($this, "editAssignment"));
2214 
2215  $ilTabs->addTab("ass_files",
2216  $lng->txt("files"),
2217  $ilCtrl->getLinkTargetByClass("ilfilesystemgui", "listFiles"));
2218 
2219  }
2220 
2221 
2225 
2230  {
2231  global $tpl, $ilTabs, $ilUser, $ilToolbar;
2232 
2233  $this->checkPermission("read");
2234 
2235  include_once("./Services/Tracking/classes/class.ilLearningProgress.php");
2236  ilLearningProgress::_tracProgress($ilUser->getId(),$this->object->getId(),
2237  $this->object->getRefId(), 'exc');
2238 
2239  $ilTabs->activateTab("content");
2240  $this->addContentSubTabs("content");
2241 
2242  // show certificate?
2243  if($this->object->hasUserCertificate($ilUser->getId()))
2244  {
2245  include_once "./Modules/Exercise/classes/class.ilExerciseCertificateAdapter.php";
2246  include_once "./Services/Certificate/classes/class.ilCertificate.php";
2247  $adapter = new ilExerciseCertificateAdapter($this->object);
2248  if(ilCertificate::_isComplete($adapter))
2249  {
2250  $ilToolbar->addButton($this->lng->txt("certificate"),
2251  $this->ctrl->getLinkTarget($this, "outCertificate"));
2252  }
2253  }
2254 
2255  include_once("./Modules/Exercise/classes/class.ilExAssignment.php");
2256  include_once("./Services/Accordion/classes/class.ilAccordionGUI.php");
2257  $acc = new ilAccordionGUI();
2258  $acc->setBehaviour("OneOpenSession");
2259  $acc->setId("exc_ow_".$this->object->getId());
2260  $ass_data = ilExAssignment::getAssignmentDataOfExercise($this->object->getId());
2261  include_once("./Modules/Exercise/classes/class.ilExAssignmentGUI.php");
2262  $ass_gui = new ilExAssignmentGUI($this->object);
2263 
2264  foreach ($ass_data as $ass)
2265  {
2266  $acc->addItem($ass_gui->getOverviewHeader($ass),
2267  $ass_gui->getOverviewBody($ass));
2268  }
2269 
2270  $tpl->setContent($acc->getHTML());
2271  }
2272 
2277  {
2278  global $tpl, $ilTabs;
2279 
2280  $this->checkPermission("read");
2281 
2282  $ilTabs->activateTab("content");
2283  $this->addContentSubTabs("content");
2284 
2285  include_once("./Modules/Exercise/classes/class.ilPublicSubmissionsTableGUI.php");
2286  $tab = new ilPublicSubmissionsTableGUI($this, "listPublicSubmissions",
2287  $this->object, (int) $_GET["ass_id"]);
2288  $tpl->setContent($tab->getHTML());
2289  }
2290 
2295  {
2296  $this->checkPermission("write");
2297  $this->object->exportGradesExcel();
2298  exit;
2299  }
2300 
2304  function saveGradesObject()
2305  {
2306  global $ilCtrl, $lng;
2307 
2308  $this->checkPermission("write");
2309  include_once 'Services/Tracking/classes/class.ilLPMarks.php';
2310 
2311  if (is_array($_POST["lcomment"]))
2312  {
2313  foreach ($_POST["lcomment"] as $k => $v)
2314  {
2315  $marks_obj = new ilLPMarks($this->object->getId(), (int) $k);
2316  $marks_obj->setComment(ilUtil::stripSlashes($v));
2317  $marks_obj->setMark(ilUtil::stripSlashes($_POST["mark"][$k]));
2318  $marks_obj->update();
2319  }
2320  }
2321  ilUtil::sendSuccess($lng->txt("exc_msg_saved_grades"), true);
2322  $ilCtrl->redirect($this, "showGradesOverview");
2323  }
2324 
2329  protected function sendNotifications($assignment_id)
2330  {
2331  include_once "./Services/Notification/classes/class.ilNotification.php";
2333 
2334  include_once "./Modules/Exercise/classes/class.ilExerciseMailNotification.php";
2335  $not = new ilExerciseMailNotification();
2337  $not->setAssignmentId($assignment_id);
2338  $not->setRefId($this->ref_id);
2339  $not->setRecipients($users);
2340  $not->send();
2341  }
2342 
2343  protected function createBlogObject()
2344  {
2345  global $ilUser;
2346 
2347  $this->checkPermission("read");
2348 
2349  // $this->tabs_gui->setBackTarget($this->lng->txt("back"), $this->ctrl->getLinkTarget($this, "showOverview"));
2350 
2351  $this->tabs_gui->setTabActive("content");
2352  $this->addContentSubTabs("content");
2353 
2354  if (mktime() > $this->ass->getDeadline())
2355  {
2356  ilUtil::sendInfo($this->lng->txt("exercise_time_over"));
2357  }
2358 
2359  $tpl = new ilTemplate("tpl.exc_select_resource.html", true, true, "Modules/Exercise");
2360  $tpl->setVariable("TXT_TITLE", $this->lng->txt("exc_create_blog").": ".$this->ass->getTitle());
2361  $tpl->setVariable("TREE", $this->renderWorkspaceExplorer("createBlog"));
2362  $tpl->setVariable("FORM_ACTION", $this->ctrl->getFormAction($this));
2363  $tpl->setVariable("TXT_SUBMIT", $this->lng->txt("save"));
2364  $tpl->setVariable("TXT_CANCEL", $this->lng->txt("cancel"));
2365  $tpl->setVariable("CMD_SUBMIT", "saveBlog");
2366  $tpl->setVariable("CMD_CANCEL", "showOverview");
2367 
2368  ilUtil::sendInfo($this->lng->txt("exc_create_blog_select_info"));
2369 
2370  $this->tpl->setContent($tpl->get());
2371  }
2372 
2373  protected function selectBlogObject()
2374  {
2375  global $ilUser;
2376 
2377  $this->checkPermission("read");
2378 
2379  // $this->tabs_gui->setBackTarget($this->lng->txt("back"), $this->ctrl->getLinkTarget($this, "showOverview"));
2380 
2381  $this->tabs_gui->setTabActive("content");
2382  $this->addContentSubTabs("content");
2383 
2384  if (mktime() > $this->ass->getDeadline())
2385  {
2386  ilUtil::sendInfo($this->lng->txt("exercise_time_over"));
2387  }
2388 
2389  $tpl = new ilTemplate("tpl.exc_select_resource.html", true, true, "Modules/Exercise");
2390  $tpl->setVariable("TXT_TITLE", $this->lng->txt("exc_select_blog").": ".$this->ass->getTitle());
2391  $tpl->setVariable("TREE", $this->renderWorkspaceExplorer("selectBlog"));
2392  $tpl->setVariable("FORM_ACTION", $this->ctrl->getFormAction($this));
2393  $tpl->setVariable("TXT_SUBMIT", $this->lng->txt("save"));
2394  $tpl->setVariable("TXT_CANCEL", $this->lng->txt("cancel"));
2395  $tpl->setVariable("CMD_SUBMIT", "setSelectedBlog");
2396  $tpl->setVariable("CMD_CANCEL", "showOverview");
2397 
2398  ilUtil::sendInfo($this->lng->txt("exc_select_blog_info"));
2399 
2400  $this->tpl->setContent($tpl->get());
2401  }
2402 
2403  protected function saveBlogObject()
2404  {
2405  global $ilUser;
2406 
2407  if(!$_POST["node"])
2408  {
2409  ilUtil::sendFailure($this->lng->txt("select_one"));
2410  return $this->createBlogObject();
2411  }
2412 
2413  $parent_node = $_POST["node"];
2414 
2415  include_once "Modules/Blog/classes/class.ilObjBlog.php";
2416  include_once "Services/PersonalWorkspace/classes/class.ilWorkspaceTree.php";
2417  include_once "Services/PersonalWorkspace/classes/class.ilWorkspaceAccessHandler.php";
2418 
2419  $blog = new ilObjBlog();
2420  $blog->setTitle($this->object->getTitle()." - ".$this->ass->getTitle());
2421  $blog->create();
2422 
2423  $tree = new ilWorkspaceTree($ilUser->getId());
2424 
2425  $node_id = $tree->insertObject($parent_node, $blog->getId());
2426 
2427  $access_handler = new ilWorkspaceAccessHandler($tree);
2428  $access_handler->setPermissions($parent_node, $node_id);
2429 
2430  $this->object->addResourceObject($node_id, $this->ass->getId(), $ilUser->getId());
2431 
2432  ilUtil::sendSuccess($this->lng->txt("exc_blog_created"), true);
2433  $this->ctrl->redirect($this, "showOverview");
2434  }
2435 
2436  protected function setSelectedBlogObject()
2437  {
2438  global $ilUser;
2439 
2440  if($_POST["node"])
2441  {
2442  include_once "Services/PersonalWorkspace/classes/class.ilWorkspaceTree.php";
2443  $tree = new ilWorkspaceTree($ilUser->getId());
2444  $node = $tree->getNodeData($_POST["node"]);
2445  if($node && $node["type"] == "blog")
2446  {
2447  $this->removeExistingSubmissions();
2448  $this->object->addResourceObject($node["wsp_id"], $this->ass->getId(), $ilUser->getId());
2449 
2450  ilUtil::sendSuccess($this->lng->txt("exc_blog_selected"), true);
2451  $this->ctrl->setParameter($this, "blog_id", $node["wsp_id"]);
2452  $this->ctrl->redirect($this, "askDirectionSubmission");
2453  }
2454  }
2455 
2456  ilUtil::sendFailure($this->lng->txt("select_one"));
2457  return $this->selectPortfolioObject();
2458  }
2459 
2463  public function removeExistingSubmissions()
2464  {
2465  global $ilUser;
2466 
2467  $submitted = ilExAssignment::getDeliveredFiles($this->ass->getExerciseId(), $this->ass->getId(), $ilUser->getId());
2468  if($submitted)
2469  {
2470  $files = array();
2471  foreach($submitted as $item)
2472  {
2473  $files[] = $item["returned_id"];
2474  }
2475  ilExAssignment::deleteDeliveredFiles($this->ass->getExerciseId(), $this->ass->getId(), $files, $ilUser->getId());
2476  }
2477  }
2478 
2479  protected function askDirectionSubmissionObject()
2480  {
2481  global $tpl;
2482 
2483  $this->tabs_gui->setTabActive("content");
2484  $this->addContentSubTabs("content");
2485 
2486  include_once "Services/Utilities/classes/class.ilConfirmationGUI.php";
2487  $conf = new ilConfirmationGUI();
2488 
2489 
2490  if($_REQUEST["blog_id"])
2491  {
2492  $this->ctrl->setParameter($this, "blog_id", $_REQUEST["blog_id"]);
2493  $txt = $this->lng->txt("exc_direct_submit_blog");
2494  }
2495  else
2496  {
2497  $this->ctrl->setParameter($this, "prtf_id", $_REQUEST["prtf_id"]);
2498  $txt = $this->lng->txt("exc_direct_submit_portfolio");
2499  }
2500  $conf->setFormAction($this->ctrl->getFormAction($this, "directSubmit"));
2501 
2502  $conf->setHeaderText($txt);
2503  $conf->setConfirm($this->lng->txt("submit"), "directSubmit");
2504  $conf->setCancel($this->lng->txt("cancel"), "showOverview");
2505 
2506  $tpl->setContent($conf->getHTML());
2507  }
2508 
2509  protected function directSubmitObject()
2510  {
2511  global $ilUser;
2512 
2513  $success = false;
2514 
2515  // submit current version of blog
2516  if($_REQUEST["blog_id"])
2517  {
2518  $success = $this->submitBlog($_REQUEST["blog_id"]);
2519  $this->ctrl->setParameter($this, "blog_id", "");
2520  }
2521  // submit current version of portfolio
2522  else if($_REQUEST["prtf_id"])
2523  {
2524  $success = $this->submitPortfolio($_REQUEST["prtf_id"]);
2525  $this->ctrl->setParameter($this, "prtf_id", "");
2526  }
2527 
2528  if($success)
2529  {
2530  ilUtil::sendSuccess($this->lng->txt("settings_saved"), true);
2531  }
2532  else
2533  {
2534  ilUtil::sendFailure($this->lng->txt("msg_failed"), true);
2535  }
2536  $this->ctrl->redirect($this, "showOverview");
2537  }
2538 
2545  function submitBlog($a_blog_id)
2546  {
2547  global $ilUser;
2548 
2549  if($this->object && $this->ass)
2550  {
2551  $blog_id = $a_blog_id;
2552 
2553  include_once "Modules/Blog/classes/class.ilObjBlogGUI.php";
2554  $blog_gui = new ilObjBlogGUI($blog_id, ilObjBlogGUI::WORKSPACE_NODE_ID);
2555  if($blog_gui->object)
2556  {
2557  $file = $blog_gui->buildExportFile();
2558  $size = filesize($file);
2559  if($size)
2560  {
2561  $this->removeExistingSubmissions();
2562 
2563  $meta = array(
2564  "name" => $blog_id,
2565  "tmp_name" => $file,
2566  "size" => $size
2567  );
2568  $this->object->deliverFile($meta, $this->ass->getId(), $ilUser->getId(), true);
2569 
2570  $this->sendNotifications($this->ass->getId());
2571  $this->object->handleSubmission($this->ass->getId());
2572  return true;
2573  }
2574  }
2575  }
2576  return false;
2577  }
2578 
2585  function submitPortfolio($a_portfolio_id)
2586  {
2587  global $ilUser;
2588 
2589  if($this->object && $this->ass)
2590  {
2591  $prtf_id = $a_portfolio_id;
2592 
2593  include_once "Services/Portfolio/classes/class.ilObjPortfolio.php";
2594  $prtf = new ilObjPortfolio($prtf_id, false);
2595  if($prtf->getTitle())
2596  {
2597  include_once "Services/Portfolio/classes/class.ilPortfolioHTMLExport.php";
2598  $export = new ilPortfolioHTMLExport(null, $prtf);
2599  $file = $export->buildExportFile();
2600  $size = filesize($file);
2601  if($size)
2602  {
2603  $this->removeExistingSubmissions();
2604 
2605  $meta = array(
2606  "name" => $prtf_id,
2607  "tmp_name" => $file,
2608  "size" => $size
2609  );
2610  $this->object->deliverFile($meta, $this->ass->getId(), $ilUser->getId(), true);
2611 
2612  $this->sendNotifications($this->ass->getId());
2613  $this->object->handleSubmission($this->ass->getId());
2614  return true;
2615  }
2616  }
2617  }
2618  return false;
2619  }
2620 
2621  protected function selectPortfolioObject()
2622  {
2623  global $ilUser;
2624 
2625  $this->checkPermission("read");
2626 
2627  // $this->tabs_gui->setBackTarget($this->lng->txt("back"), $this->ctrl->getLinkTarget($this, "showOverview"));
2628 
2629  $this->tabs_gui->setTabActive("content");
2630  $this->addContentSubTabs("content");
2631 
2632  if (mktime() > $this->ass->getDeadline())
2633  {
2634  ilUtil::sendInfo($this->lng->txt("exercise_time_over"));
2635  }
2636 
2637  $tpl = new ilTemplate("tpl.exc_select_resource.html", true, true, "Modules/Exercise");
2638 
2639  include_once "Services/Portfolio/classes/class.ilObjPortfolio.php";
2640  $portfolios = ilObjPortfolio::getPortfoliosOfUser($ilUser->getId());
2641  if($portfolios)
2642  {
2643  $tpl->setCurrentBlock("item");
2644  foreach($portfolios as $portfolio)
2645  {
2646  $tpl->setVariable("ITEM_ID", $portfolio["id"]);
2647  $tpl->setVariable("ITEM_TITLE", $portfolio["title"]);
2648  $tpl->parseCurrentBlock();
2649  }
2650  }
2651 
2652  $tpl->setVariable("TXT_TITLE", $this->lng->txt("exc_select_portfolio").": ".$this->ass->getTitle());
2653  $tpl->setVariable("FORM_ACTION", $this->ctrl->getFormAction($this));
2654  $tpl->setVariable("TXT_SUBMIT", $this->lng->txt("save"));
2655  $tpl->setVariable("TXT_CANCEL", $this->lng->txt("cancel"));
2656  $tpl->setVariable("CMD_SUBMIT", "setSelectedPortfolio");
2657  $tpl->setVariable("CMD_CANCEL", "showOverview");
2658 
2659  ilUtil::sendInfo($this->lng->txt("exc_select_portfolio_info"));
2660 
2661  $this->tpl->setContent($tpl->get());
2662  }
2663 
2664  protected function createPortfolioObject()
2665  {
2666  global $ilUser;
2667 
2668  $this->checkPermission("read");
2669 
2670  include_once "Services/Portfolio/classes/class.ilObjPortfolio.php";
2671  $portfolio = new ilObjPortfolio();
2672  $portfolio->setTitle($this->object->getTitle()." - ".$this->ass->getTitle());
2673  $portfolio->create();
2674 
2675  $this->object->addResourceObject($portfolio->getId(), $this->ass->getId(), $ilUser->getId());
2676 
2677  ilUtil::sendSuccess($this->lng->txt("exc_portfolio_created"), true);
2678  $this->ctrl->redirect($this, "showOverview");
2679  }
2680 
2681  protected function setSelectedPortfolioObject()
2682  {
2683  global $ilUser;
2684 
2685  if($_POST["item"])
2686  {
2687  $this->removeExistingSubmissions();
2688  $this->object->addResourceObject($_POST["item"], $this->ass->getId(), $ilUser->getId());
2689 
2690  ilUtil::sendSuccess($this->lng->txt("exc_portfolio_selected"), true);
2691  $this->ctrl->setParameter($this, "prtf_id", $_POST["item"]);
2692  $this->ctrl->redirect($this, "askDirectionSubmission");
2693  }
2694 
2695  ilUtil::sendFailure($this->lng->txt("select_one"));
2696  return $this->selectPortfolioObject();
2697  }
2698 
2699  protected function renderWorkspaceExplorer($a_cmd)
2700  {
2701  global $ilUser;
2702 
2703  include_once "Services/PersonalWorkspace/classes/class.ilWorkspaceTree.php";
2704  include_once "Services/PersonalWorkspace/classes/class.ilWorkspaceAccessHandler.php";
2705  require_once 'Services/PersonalWorkspace/classes/class.ilWorkspaceExplorer.php';
2706 
2707  $tree = new ilWorkspaceTree($ilUser->getId());
2708  $access_handler = new ilWorkspaceAccessHandler($tree);
2710  'exc_wspexpand', $tree, $access_handler);
2711  $exp->setTargetGet('wsp_id');
2712 
2713  if($a_cmd == "selectBlog")
2714  {
2715  $exp->removeAllFormItemTypes();
2716  $exp->addFilter('blog');
2717  $exp->addFormItemForType('blog');
2718  }
2719 
2720  if($_GET['exc_wspexpand'] == '')
2721  {
2722  // not really used as session is already set [see above]
2723  $expanded = $tree->readRootId();
2724  }
2725  else
2726  {
2727  $expanded = $_GET['exc_wspexpand'];
2728  }
2729 
2730  $exp->setExpandTarget($this->ctrl->getLinkTarget($this, $a_cmd));
2731  $exp->setPostVar('node');
2732  $exp->setExpand($expanded);
2733  $exp->setOutput(0);
2734 
2735  return $exp->getOutput();
2736  }
2737 
2739  {
2740  $this->setSettingsSubTabs();
2741  $this->tabs_gui->activateTab("settings");
2742  $this->tabs_gui->activateSubTab("certificate");
2743 
2744  include_once "./Services/Certificate/classes/class.ilCertificateGUI.php";
2745  include_once "./Modules/Exercise/classes/class.ilExerciseCertificateAdapter.php";
2746  $output_gui = new ilCertificateGUI(new ilExerciseCertificateAdapter($this->object));
2747  $output_gui->certificateEditor();
2748  }
2749 
2751  {
2752  global $ilUser;
2753 
2754  if($this->object->hasUserCertificate($ilUser->getId()))
2755  {
2756  ilUtil::sendFailure($this->lng->txt("msg_failed"));
2757  $this->showOverviewObject();
2758  }
2759 
2760  include_once "./Services/Certificate/classes/class.ilCertificate.php";
2761  include_once "./Modules/Exercise/classes/class.ilExerciseCertificateAdapter.php";
2762  $certificate = new ilCertificate(new ilExerciseCertificateAdapter($this->object));
2763  $certificate->outCertificate(array("user_id" => $ilUser->getId()));
2764  }
2765 }
2766 
2767 ?>