ILIAS  Release_4_0_x_branch Revision 61816
 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-2009 ILIAS open source, Extended GPL, see docs/LICENSE */
4 
5 require_once "classes/class.ilObjectGUI.php";
6 
19 {
24  function ilObjExerciseGUI($a_data,$a_id,$a_call_by_reference,$a_prepare_output = true)
25  {
26  global $lng;
27 
28  $this->type = "exc";
29  $this->ilObjectGUI($a_data,$a_id,$a_call_by_reference,false);
30 
31  $lng->loadLanguageModule("exercise");
32  $this->ctrl->saveParameter($this, array("sort_by", "sort_order", "offset"));
33  }
34 
35  function getFiles()
36  {
37  return $this->files ? $this->files : array();
38  }
39 
40  function setFiles($a_files)
41  {
42  $this->files = $a_files;
43  }
44 
45  function createObject($a_reload = false)
46  {
47  global $tpl;
48 
49  $this->getTemplateFile("edit", "exc");
50 
51  if (!$a_reload)
52  {
53  $this->initPropertiesForm("create");
54  }
55  $this->tpl->setVariable("EDIT_FORM", $this->form_gui->getHtml());
56 
57  $this->fillCloneTemplate('DUPLICATE','exc');
58  }
59 
60  function viewObject()
61  {
62  $this->infoScreenObject();
63  return;
64  global $rbacsystem,$ilUser;
65 
66  include_once 'Services/Tracking/classes/class.ilLearningProgress.php';
67  ilLearningProgress::_tracProgress($ilUser->getId(),$this->object->getId(),'exc');
68 
69 
70  if (strtolower($_GET["baseClass"]) == "iladministrationgui")
71  {
73  return;
74  }
75 
76  if (!$rbacsystem->checkAccess("read", $this->ref_id))
77  {
78  $this->ilias->raiseError($this->lng->txt("msg_no_perm_read"),$this->ilias->error_obj->MESSAGE);
79  }
80  $this->getTemplateFile("view", "exc");
81 
82  $this->tpl->setVariable("FORM_DOWNLOAD_ACTION", $this->ctrl->getFormAction($this, "downloadFile"));
83  $this->tpl->setVariable("TITLE_TXT",$this->lng->txt("title"));
84  $this->tpl->setVariable("TITLE",$this->object->getTitle());
85  $this->tpl->setVariable("TXT_HEADER",$this->lng->txt("exc_details"));
86  $this->tpl->setVariable("DESCRIPTION_TXT",$this->lng->txt("description"));
87  $this->tpl->setVariable("DESCRIPTION",$this->object->getDescription());
88  $this->tpl->setVariable("INSTRUCTION_TXT",$this->lng->txt("exc_instruction"));
89  $this->tpl->setVariable("INSTRUCTION",nl2br($this->object->getInstruction()));
90  $this->tpl->setVariable("EDIT_UNTIL_TXT",$this->lng->txt("exc_edit_until"));
91  $this->tpl->setVariable("EDIT_UNTIL",date("H:i, d.m.Y",$this->object->getTimestamp()));
92  $this->tpl->setVariable("TIME_TO_SEND_TXT",$this->lng->txt("exc_time_to_send"));
93 
94  if ($this->object->getTimestamp()-time() <= 0)
95  {
96  $this->tpl->setCurrentBlock("TIME_REACHED");
97  $this->tpl->setVariable("TIME_TO_SEND",$this->lng->txt("exc_time_over_short"));
98  $this->tpl->parseCurrentBlock();
99  }
100  else {
101  $timediff = ilUtil::int2array($this->object->getTimestamp()-time(),null);
102  $timestr = ilUtil::timearray2string($timediff);
103  $this->tpl->setCurrentBlock("TIME_NOT_REACHED");
104  $this->tpl->setVariable("TIME_TO_SEND",$timestr);
105  $this->tpl->parseCurrentBlock();
106  }
107 
108  $anyfiles = false;
109  foreach($this->object->getFiles() as $file)
110  {
111  $this->tpl->setCurrentBlock("FILES_ROW");
112  $this->tpl->setVariable("FILE_DATA",$file["name"]);
113  $this->tpl->setVariable("FILE_CHECK",ilUtil::formRadioButton(0,"file",urlencode($file["name"])));
114  $this->tpl->parseCurrentBlock();
115  $anyfiles = true;
116  }
117 
118  if ($anyfiles)
119  {
120  $this->tpl->setCurrentBlock("FILES");
121  $this->tpl->setVariable("FILES_TXT",$this->lng->txt("exc_files"));
122  $this->tpl->setVariable("TXT_DOWNLOAD",$this->lng->txt("download"));
123  $this->tpl->setVariable("IMG",ilUtil::getImagePath("arrow_downright.gif"));
124  $this->tpl->parseCurrentBlock();
125  }
126 
127  $this->tpl->setCurrentBlock("perma_link");
128  $this->tpl->setVariable("PERMA_LINK", ILIAS_HTTP_PATH.
129  "/goto.php?target=".
130  $this->object->getType().
131  "_".$this->object->getRefId()."&client_id=".CLIENT_ID);
132  $this->tpl->setVariable("TXT_PERMA_LINK", $this->lng->txt("perma_link"));
133  $this->tpl->setVariable("PERMA_TARGET", "_top");
134  $this->tpl->parseCurrentBlock();
135 
136  return true;
137  }
138 
145  function downloadObject()
146  {
147  global $ilUser, $ilCtrl;
148 
149  $this->checkPermission("read");
150  if (count($_POST["delivered"]))
151  {
152  $this->object->members_obj->downloadSelectedFiles($_POST["delivered"],$ilUser->getId());
153  exit;
154  }
155  else
156  {
157  ilUtil::sendFailure($this->lng->txt("please_select_a_delivered_file_to_download"), true);
158  $ilCtrl->redirect($this, "deliver");
159  }
160  }
161 
169  {
170  global $ilUser, $ilCtrl;
171 
172  $this->checkPermission("read");
173 
174  if (mktime() > $this->object->getTimestamp())
175  {
176  ilUtil::sendFailure($this->lng->txt("exercise_time_over"), true);
177  $ilCtrl->redirect($this, "deliver");
178  }
179 
180  if (count($_POST["delivered"]) && mktime() < $this->object->getTimestamp())
181  {
182  $this->object->deleteDeliveredFiles($_POST["delivered"], $ilUser->id);
183  }
184  else
185  {
186  ilUtil::sendFailure($this->lng->txt("please_select_a_delivered_file_to_delete"), true);
187  }
188  $ilCtrl->redirect($this, "deliver");
189  }
190 
196  function deliverObject()
197  {
198  global $ilUser;
199  require_once "./Services/Utilities/classes/class.ilUtil.php";
200 
201  $this->checkPermission("read");
202 
203  $this->tabs_gui->setTabActive("exc_your_submission");
204 
205  if (mktime() > $this->object->getTimestamp())
206  {
207  ilUtil::sendInfo($this->lng->txt("exercise_time_over"));
208  }
209 
210  $this->getTemplateFile("deliver_file", "exc");
211 
212  include_once("./Modules/Exercise/classes/class.ilExcDeliveredFilesTableGUI.php");
213  $tab = new ilExcDeliveredFilesTableGUI($this, "deliver", $this->object);
214  $this->tpl->setVariable("DELIVERED_FILES_TABLE", $tab->getHTML());
215 
216  if (mktime() < $this->object->getTimestamp())
217  {
218  $this->initUploadForm();
219  $this->tpl->setVariable("UPLOAD_SINGLE_FORM", $this->form->getHTML());
220 
221  $this->initZipUploadForm();
222  $this->tpl->setVariable("UPLOAD_MULTI_FORM", $this->form->getHTML());
223  }
224  }
225 
229  public function initUploadForm()
230  {
231  global $lng, $ilCtrl;
232 
233  include_once("Services/Form/classes/class.ilPropertyFormGUI.php");
234  $this->form = new ilPropertyFormGUI();
235 
236  // file input
237  include_once("./Services/Form/classes/class.ilFileWizardInputGUI.php");
238  $fi = new ilFileWizardInputGUI($lng->txt("file"), "deliver");
239  $fi->setFilenames(array(0 => ''));
240  //$fi->setInfo($lng->txt(""));
241  $this->form->addItem($fi);
242 
243  $this->form->addCommandButton("deliverFile", $lng->txt("upload"));
244 
245  $this->form->setTitle($lng->txt("file_add"));
246  $this->form->setFormAction($ilCtrl->getFormAction($this));
247  }
248 
252  public function initZipUploadForm()
253  {
254  global $lng, $ilCtrl;
255 
256  include_once("Services/Form/classes/class.ilPropertyFormGUI.php");
257  $this->form = new ilPropertyFormGUI();
258 
259  // desc
260  include_once("./Services/Form/classes/class.ilFileInputGUI.php");
261  $fi = new ilFileInputGUI($lng->txt("file"), "deliver");
262  $fi->setSuffixes(array("zip"));
263  $this->form->addItem($fi);
264 
265  $this->form->addCommandButton("deliverUnzip", $lng->txt("upload"));
266 
267  $this->form->setTitle($lng->txt("header_zip"));
268  $this->form->setFormAction($ilCtrl->getFormAction($this));
269  }
270 
274  function deliverFileObject()
275  {
276  global $ilUser, $lng, $ilCtrl;
277 
278  foreach ($_FILES["deliver"]["name"] as $k => $v)
279  {
280  $file = array(
281  "name" => $_FILES["deliver"]["name"][$k],
282  "type" => $_FILES["deliver"]["type"][$k],
283  "tmp_name" => $_FILES["deliver"]["tmp_name"][$k],
284  "error" => $_FILES["deliver"]["error"][$k],
285  "size" => $_FILES["deliver"]["size"][$k],
286  );
287  if(!$this->object->deliverFile($file, $ilUser->id))
288  {
289  ilUtil::sendFailure($this->lng->txt("exc_upload_error"), true);
290  }
291  }
292 
293  $ilCtrl->redirect($this, "deliver");
294  }
295 
300  {
301  global $ilCtrl;
302 
303  $this->checkPermission("read");
304 
305  if (preg_match("/zip/",$_FILES["deliver"]["type"]) == 1)
306  {
307  $this->object->processUploadedFile($_FILES["deliver"]["tmp_name"], "deliverFile", false);
308  }
309 
310  $ilCtrl->redirect($this, "deliver");
311 
312  }
313 
318  {
319  global $rbacsystem;
320 
321  $file = ($_POST["file"])
322  ? $_POST["file"]
323  : $_GET["file"];
324 
325  $this->checkPermission("read");
326 
327  if (!isset($file))
328  {
329  ilUtil::sendFailure($this->lng->txt("exc_select_one_file"),true);
330  $this->ctrl->redirect($this, "view");
331  }
332  $files = $this->object->getFiles();
333  $file_exist = false;
334 
335  foreach($this->object->getFiles() as $lfile)
336  {
337  if($lfile["name"] == urldecode($file))
338  {
339  $file_exist = true;
340  break;
341  }
342  }
343  if(!$file_exist)
344  {
345  echo "FILE DOES NOT EXIST";
346  exit;
347  }
348  ilUtil::deliverFile($this->object->file_obj->getAbsolutePath(urldecode($file)),
349  urldecode($file));
350 
351  return true;
352  }
353 
358  function saveObject()
359  {
360  global $rbacadmin;
361 
362  $this->initPropertiesForm("create");
363 
364  if ($this->form_gui->checkInput())
365  {
366  // always call parent method first to create an object_data entry & a reference
367  $newObj = parent::saveObject();
368 
369  // setup rolefolder & default local roles if needed (see ilObjForum & ilObjForumGUI for an example)
370  //$roles = $newObj->initDefaultRoles();
371 
372  // put here your object specific stuff
373 
374  $newObj->setTitle($this->form_gui->getInput("title"));
375  $newObj->setDescription($this->form_gui->getInput("desc"));
376  $newObj->setInstruction($this->form_gui->getInput("instruction"));
377  $edit_date =
378  $this->form_gui->getItemByPostVar("edit_date")->getDate();
379  $newObj->setTimestamp($edit_date->get(IL_CAL_UNIX));
380 
381  $newObj->saveData();
382  $newObj->update();
383 
384  // always send a message
385  ilUtil::sendSuccess($this->lng->txt("exc_added"),true);
386  ilUtil::redirect("ilias.php?baseClass=ilExerciseHandlerGUI&ref_id=".$newObj->getRefId()."&cmd=edit");
387  }
388  else
389  {
390  $this->form_gui->setValuesByPost();
391  $this->createObject(true);
392  }
393  }
394 
395  function editObject()
396  {
397  global $rbacsystem, $tpl;
398 
399  $this->checkPermission("write");
400 
401  $this->getTemplateFile("edit", "exc");
402 
403  $this->initPropertiesForm("edit");
404  $this->getPropertiesValues();
405 
406  $this->tpl->setVariable("EDIT_FORM", $this->form_gui->getHtml());
407 
408  $this->tpl->setCurrentBlock("FILES");
409  $this->tpl->setVariable("TXT_HEADER_FILE",$this->lng->txt("file_add"));
410  $this->tpl->setVariable("TXT_FILE",$this->lng->txt("file"));
411  $this->tpl->setVariable("TXT_UPLOAD",$this->lng->txt("upload"));
412  $this->tpl->setVariable("FORMACTION_FILE", $this->ctrl->getFormAction($this));
413  $this->tpl->setVariable("TXT_HEADER_ZIP", $this->lng->txt("header_zip"));
414  $this->tpl->setVariable("CMD_FILE_SUBMIT","uploadFile");
415  $this->tpl->parseCurrentBlock();
416  }
417 
423  public function initPropertiesForm($a_mode = "create")
424  {
425  global $lng, $ilCtrl;
426 
427  // init form
428  $lng->loadLanguageModule("form");
429  include_once("./Services/Form/classes/class.ilPropertyFormGUI.php");
430  $this->form_gui = new ilPropertyFormGUI();
431  $this->form_gui->setTableWidth("60%");
432  if ($a_mode == "edit")
433  {
434  $this->form_gui->setTitle($lng->txt("exc_edit_exercise"));
435  }
436  else
437  {
438  $this->form_gui->setTitle($lng->txt("exc_new"));
439  }
440  $this->form_gui->setTitleIcon(ilUtil::getImagePath("icon_exc.gif"));
441  $this->form_gui->setFormAction($ilCtrl->getFormAction($this));
442 
443 
444  // on creation: Type
445  if ($a_mode == "create")
446  {
447  $type_input = new ilHiddenInputGUI("new_type");
448  $type_input->setValue("exc");
449  $this->form_gui->addItem($type_input);
450  }
451 
452  // Title
453  $title_input = new ilTextInputGUI($lng->txt("title"), "title");
454  $title_input->setRequired(true);
455  $title_input->setMaxLength(128);
456  $this->form_gui->addItem($title_input);
457 
458  // Description
459  $desc_input = new ilTextAreaInputGUI($lng->txt("desc"), "desc");
460  $this->form_gui->addItem($desc_input);
461 
462  // Work Instructions
463  $desc_input = new ilTextAreaInputGUI($lng->txt("exc_instruction"), "instruction");
464  $this->form_gui->addItem($desc_input);
465 
466  // Edit until...
467  $edit_date = new ilDateTimeInputGUI($lng->txt("exc_edit_until"), "edit_date");
468  //$dt_prop->setDate(new ilDateTime("2006-12-24 15:44:00", IL_CAL_DATETIME);
469  $edit_date->setShowTime(true);
470  //$dt_prop->setInfo("Info text for the start date.");
471  $this->form_gui->addItem($edit_date);
472 
473  // files
474  if ($a_mode == "edit")
475  {
476  if(count($files = $this->object->getFiles()))
477  {
478  // Files section header
479  $files_head = new ilFormSectionHeaderGUI();
480  $files_head->setTitle($lng->txt("files"));
481  $this->form_gui->addItem($files_head);
482 
483  foreach($files as $file)
484  {
485  $i++;
486  $file_cb = new ilCheckboxInputGUI($this->lng->txt("exc_ask_delete"),
487  "delete_file_".$i);
488  $file_cb->setOptionTitle($file["name"]);
489  $file_cb->setValue($file["name"]);
490  $this->form_gui->addItem($file_cb);
491  }
492  }
493  }
494 
495  // save and cancel commands
496  if ($a_mode == "create")
497  {
498  $this->form_gui->addCommandButton("save", $lng->txt("save"));
499  $this->form_gui->addCommandButton("cancel", $lng->txt("cancel"));
500  }
501  else
502  {
503  $this->form_gui->addCommandButton("update", $lng->txt("save"));
504  $this->form_gui->addCommandButton("cancelEdit", $lng->txt("cancel"));
505  }
506  }
507 
512  {
513  $values["title"] = $this->object->getTitle();
514  $values["desc"] = $this->object->getLongDescription();
515  $values["instruction"] = $this->object->getInstruction();
516  $this->form_gui->setValuesByArray($values);
517 
518 //echo "-".$this->object->getTimestamp()."-";
519  $edit_date = new ilDateTime($this->object->getTimestamp(), IL_CAL_UNIX);
520  $ed_item = $this->form_gui->getItemByPostVar("edit_date");
521  $ed_item->setDate($edit_date);
522  }
523 
527  function updateObject()
528  {
529  global $rbacsystem, $tpl;
530 
531  $this->checkPermission("write");
532 
533  $this->initPropertiesForm("edit");
534  if ($this->form_gui->checkInput())
535  {
536  $this->object->setTitle($this->form_gui->getInput("title"));
537  $this->object->setDescription($this->form_gui->getInput("desc"));
538  $this->object->setInstruction($this->form_gui->getInput("instruction"));
539  $edit_date =
540  $this->form_gui->getItemByPostVar("edit_date")->getDate();
541  $this->object->setTimestamp($edit_date->get(IL_CAL_UNIX));
542 
543  // delete files
544  $del_files = array();
545  foreach ($_POST as $k => $v)
546  {
547  if (substr($k, 0, 12) == "delete_file_" && $v != "")
548  {
549  $del_files[] = $v;
550  }
551  }
552 
553  $this->object->deleteFiles($del_files);
554 
555  $this->object->update();
556 
557  ilUtil::sendSuccess($this->lng->txt("msg_obj_modified"),true);
558  $this->ctrl->redirect($this, "edit");
559  }
560  else
561  {
562  $this->form_gui->setValuesByPost();
563  $tpl->setContent($this->form_gui->getHTML());
564  }
565 
566  return;
567 
568  $this->object->setInstruction(ilUtil::stripSlashes($_POST["Fobject"]["instruction"]));
569  $this->object->setDate($_POST["d_hour"],$_POST["d_minutes"],$_POST["d_day"],
570  $_POST["d_month"],$_POST["d_year"]);
571  if($_POST["delete_file"])
572  {
573  $this->object->deleteFiles($_POST["delete_file"]);
574  }
575 
576  $this->object->setTitle(ilUtil::stripSlashes($_POST["Fobject"]["title"]));
577  $this->object->setDescription(ilUtil::stripSlashes($_POST["Fobject"]["desc"]));
578  $this->update = $this->object->update();
579 
580  ilUtil::sendSuccess($this->lng->txt("msg_obj_modified"),true);
581 
582  $this->ctrl->redirect($this, "edit");
583  }
584 
585  function cancelEditObject()
586  {
587  $this->ctrl->redirect($this, "view");
588  }
589 
590  function uploadZipObject()
591  {
592  global $rbacsystem;
593 
594  $this->checkPermission("write");
595 
596  if(!$this->object->addUploadedFile($_FILES["zipfile"], true))
597  {
598  ilUtil::sendFailure($this->lng->txt("exc_upload_error"),true);
599  }
600  $this->ctrl->redirect($this, "edit");
601 
602  }
603 
604  function uploadFileObject()
605  {
606  global $rbacsystem;
607 
608  $this->checkPermission("write");
609 
610  if(!$this->object->addUploadedFile($_FILES["file"]))
611  {
612  ilUtil::sendFailure($this->lng->txt("exc_upload_error"),true);
613  }
614  $this->ctrl->redirect($this, "edit");
615  }
616 
617 
622  {
623  global $rbacsystem;
624 
625  $this->checkPermission("write");
626 
627  if ($_POST["downloadReturned"])
628  {
629  $this->object->members_obj->deliverReturnedFiles(key($_POST["downloadReturned"]));
630  exit;
631  }
632  else
633  {
634  switch($_POST["action"])
635  {
636  case "save_status":
637  $this->saveStatusObject();
638  break;
639 
640  case "send_member":
641  $this->sendMembersObject();
642  break;
643 
644  case "redirectFeedbackMail":
646  break;
647 
648  case "delete_member":
649  $this->deassignMembersObject();
650  break;
651  }
652  }
653  }
654 
659  {
660  $this->checkPermission("write");
661 
662  if (!$this->object->members_obj->deliverReturnedFiles($_GET["member_id"]))
663  {
664  $this->ctrl->redirect($this, "members");
665  }
666  exit;
667  }
668 
673  {
674  $this->checkPermission("write");
675 
676  if (!$this->object->members_obj->deliverReturnedFiles($_GET["member_id"], true))
677  {
678  $this->ctrl->redirect($this, "members");
679  }
680  exit;
681  }
682 
683  function addMembersObject()
684  {
685  global $ilAccess,$ilErr;
686 
687  $this->checkPermission("write");
688  if(!count($_POST['user']))
689  {
690  ilUtil::sendFailure($this->lng->txt("no_checkbox"));
691  return false;
692  }
693 
694  if(!$this->object->members_obj->assignMembers($_POST["user"]))
695  {
696  ilUtil::sendFailure($this->lng->txt("exc_members_already_assigned"));
697  return false;
698  }
699  else
700  {
701  ilUtil::sendSuccess($this->lng->txt("exc_members_assigned"),true);
702  }
703  $this->ctrl->redirect($this, "members");
704  return false;
705  }
706 
707 
708  function membersObject()
709  {
710  global $rbacsystem, $tree, $tpl;
711 
712  include_once 'Services/Tracking/classes/class.ilLPMarks.php';
713 
714  $this->checkPermission("write");
715 
716  //add template for buttons
717  $this->tpl->addBlockfile("BUTTONS", "buttons", "tpl.buttons.html");
718 
719  // add member button
720  $this->tpl->setCurrentBlock("btn_cell");
721  $this->tpl->setVariable("BTN_LINK",$this->ctrl->getLinkTargetByClass('ilRepositorySearchGUI','start'));
722  $this->tpl->setVariable("BTN_TXT",$this->lng->txt("add_member"));
723  $this->tpl->parseCurrentBlock();
724 
725  // add course members button, in case the exercise is inside a course
726  $parent_id = $tree->getParentId($_GET["ref_id"]);
727  $parent_obj_id = ilObject::_lookupObjId($parent_id);
728  $type = ilObject::_lookupType($parent_obj_id);
729  while ($parent_id != 1 && $type != "crs")
730  {
731  $parent_id = $tree->getParentId($parent_id);
732  $parent_obj_id = ilObject::_lookupObjId($parent_id);
733  $type = ilObject::_lookupType($parent_obj_id);
734  }
735 
736  if ($type == "crs")
737  {
738 // $search_for_role = "il_crs_member_" . $parent_id;
739  $this->tpl->setCurrentBlock("btn_cell");
740 
741 // $_SESSION['rep_query']['role']['title'] = $search_for_role;
742 // $_SESSION['rep_search_type'] = 'role';
743 
744  // fixed bug 5535
745  $this->ctrl->setParameterByClass('ilRepositorySearchGUI', "list_obj", $parent_obj_id);
746  $this->tpl->setVariable("BTN_LINK",$this->ctrl->getLinkTargetByClass('ilRepositorySearchGUI','listUsers'));
747  //$this->tpl->setVariable("BTN_LINK",$this->ctrl->getLinkTargetByClass('ilRepositorySearchGUI','performSearch'));
748  $this->lng->loadLanguageModule("exercise");
749  $this->tpl->setVariable("BTN_TXT",$this->lng->txt("exc_crs_add_members"));
750  $this->tpl->parseCurrentBlock();
751  }
752 
753  include_once("./Modules/Exercise/classes/class.ilExerciseMemberTableGUI.php");
754  $exc_tab = new ilExerciseMemberTableGUI($this, "members", $this->object);
755  $tpl->setContent($exc_tab->getHTML());
756  return;
757  }
758 
759 
764  {
765  $this->checkPermission("write");
766 
767  if ($_GET["member_id"] != "")
768  {
769  $this->object->members_obj->setStatusFeedbackForMember($_GET["member_id"], 1);
770  $login = ilObjUser::_lookupLogin((int) $_GET["member_id"]);
771  ilUtil::redirect("ilias.php?baseClass=ilMailGUI&type=new&rcp_to=".urlencode($login));
772  }
773  else if(count($_POST["member"]) > 0)
774  {
775  include_once('./Services/User/classes/class.ilObjUser.php');
776  $logins = array();
777  foreach($_POST["member"] as $member => $val)
778  {
779  $logins[] = ilObjUser::_lookupLogin($member);
780  $this->object->members_obj->setStatusFeedbackForMember($member, 1);
781  }
782  $logins = implode($logins, ",");
783  ilUtil::redirect("ilias.php?baseClass=ilMailGUI&type=new&rcp_to=".$logins);
784  }
785 
786  ilUtil::sendFailure($this->lng->txt("no_checkbox"),true);
787  $this->ctrl->redirect($this, "members");
788  }
789 
793  function downloadAllObject()
794  {
795  $this->checkPermission("write");
796 
797  $members = array();
798 
799  foreach($this->object->members_obj->getMembers() as $member_id)
800  {
801  // update download time
802  $this->object->members_obj->updateTutorDownloadTime($member_id);
803 
804  // get member object (ilObjUser)
805  if (ilObject::_exists($member_id))
806  {
807  $tmp_obj =& ilObjectFactory::getInstanceByObjId($member_id);
808  $members[$member_id] = $tmp_obj->getFirstname() . " " . $tmp_obj->getLastname();
809  unset($tmp_obj);
810  }
811  }
812 
813  $this->object->file_obj->downloadAllDeliveredFiles($members);
814  }
815 
816 
817  function __getMembersOfObject($a_result,$a_type)
818  {
819 
820  switch($a_type)
821  {
822  case "usr":
823  return $a_result;
824  case "grp":
825  include_once "./Modules/Group/classes/class.ilObjGroup.php";
826 
827  $all_members = array();
828  foreach($a_result as $group)
829  {
830  $tmp_grp_obj = ilObjectFactory::getInstanceByRefId($group["id"]);
831 
832  $members = $tmp_grp_obj->getGroupMemberIds();
833  $all_members = array_merge($all_members,$members);
834  }
835  // FORMAT ARRAY
836  $all_members = array_unique($all_members);
837  foreach($all_members as $member)
838  {
839  $result[] = array("id" => $member);
840  }
841  return $result;
842  }
843  return true;
844  }
845 
846  function __showObjectSelect($a_result,$a_type)
847  {
848  include_once "./classes/class.ilObjectFactory.php";
849 
850  foreach($a_result as $obj)
851  {
852  $tmp_obj =& ilObjectFactory::getInstanceByRefId($obj["id"]);
853  $this->tpl->setCurrentBlock("OBJ_SELECT_ROW");
854  $this->tpl->setVariable("OBJ_ROW_TITLE",$tmp_obj->getTitle());
855  $this->tpl->setVariable("OBJ_ROW_ID",$tmp_obj->getRefId());
856  $this->tpl->setVariable("OBJ_ROW_DESCRIPTION",$tmp_obj->getDescription());
857  $this->tpl->parseCurrentBlock();
858 
859  unset($tmp_obj);
860  }
861  $this->tpl->setCurrentBlock("OBJ_SELECT");
862  $this->tpl->setVariable("OBJ_SELECT_TITLE",$this->lng->txt("title"));
863  $this->tpl->setVariable("OBJ_SELECT_DESCRIPTION",$this->lng->txt("description"));
864 
865  $this->tpl->setVariable("OBJ_BTN1_VALUE",$this->lng->txt("select"));
866  $this->tpl->setVariable("OBJ_BTN2_VALUE",$this->lng->txt("cancel"));
867  $this->tpl->parseCurrentBlock();
868  }
869 
873  function sendMembersObject()
874  {
875  global $ilCtrl;
876 
877  if(!count($_POST["member"]))
878  {
879  ilUtil::sendFailure($this->lng->txt("no_checkbox"),true);
880  }
881  else
882  {
883  $this->object->send($_POST["member"]);
884  ilUtil::sendSuccess($this->lng->txt("exc_sent"),true);
885  }
886  $ilCtrl->redirect($this, "members");
887  }
888 
893  {
894  global $ilCtrl;
895 
896  $this->checkPermission("write");
897 
898  if(is_array($_POST["member"]))
899  {
900  foreach($_POST["member"] as $usr_id => $member)
901  {
902  $this->object->members_obj->deassignMember($usr_id);
903  }
904  $ilCtrl->redirect($this, "members");
905  }
906  else
907  {
908  ilUtil::sendFailure($this->lng->txt("no_checkbox"),true);
909  $ilCtrl->redirect($this, "members");
910  }
911  }
912 
913  function saveCommentsObject()
914  {
915  $this->checkPermission("write");
916 
917  if(!isset($_POST['comments_value']))
918  {
919  continue;
920  }
921 
922  $this->object->members_obj->setNoticeForMember($_GET["member_id"],
923  ilUtil::stripSlashes($_POST["comments_value"]));
924  ilUtil::sendSuccess($this->lng->txt("exc_members_comments_saved"));
925  $this->membersObject();
926  }
927 
928  function getComments($member_id)
929  {
930  return $this->object->members_obj->getNoticeByMember($member_id);
931  }
932 
936  function saveStatusObject()
937  {
938  global $ilCtrl;
939 
940  $this->checkPermission("write");
941 
942  include_once 'Services/Tracking/classes/class.ilLPMarks.php';
943 
944  $saved_for = array();
945 
946  foreach($_POST["id"] as $key => $value)
947  {
948  if (count($_POST["member"]) > 0 && $_POST["member"][$key] != "1")
949  {
950  continue;
951  }
952  else
953  {
954  if (count($_POST["member"]) > 0)
955  {
956  $uname = ilObjUser::_lookupName($key);
957  $saved_for[] = $uname["lastname"].", ".$uname["firstname"];
958  }
959  }
960 
961  $this->object->members_obj->setStatusForMember($key, $_POST["status"][$key]);
962  //$this->object->members_obj->setStatusFeedbackForMember($key, $_POST["feedback"][$key] ? 1 : 0);
963  $this->object->members_obj->setNoticeForMember($key,ilUtil::stripSlashes($_POST["notice"][$key]));
964 
965  if (ilUtil::stripSlashes($_POST['mark'][$key]) !=
966  ilLPMarks::_lookupMark($key, $this->object->getId()))
967  {
968  $this->object->members_obj->updateStatusTimeForMember($key);
969  }
970 
971  // save mark and comment
972  $marks_obj = new ilLPMarks($this->object->getId(),$key);
973  $marks_obj->setMark(ilUtil::stripSlashes($_POST['mark'][$key]));
974  $marks_obj->setComment(ilUtil::stripSlashes($_POST['lcomment'][$key]));
975  $marks_obj->update();
976  }
977  if (count($saved_for) > 0)
978  {
979  $save_for_str = "(".implode($saved_for, " - ").")";
980  }
981  ilUtil::sendSuccess($this->lng->txt("exc_status_saved")." ".$save_for_str,true);
982  $ilCtrl->redirect($this, "members");
983  }
984 
985  function __getDateSelect($a_type,$a_selected)
986  {
987  switch($a_type)
988  {
989  case "hour":
990  for($i=0; $i<24; $i++)
991  {
992  $hours[$i] = $i < 10 ? "0".$i : $i;
993  }
994  return ilUtil::formSelect($a_selected,"d_hour",$hours,false,true);
995 
996  case "minutes":
997  for($i=0;$i<60;$i++)
998  {
999  $minutes[$i] = $i < 10 ? "0".$i : $i;
1000  }
1001  return ilUtil::formSelect($a_selected,"d_minutes",$minutes,false,true);
1002 
1003  case "day":
1004  for($i=1; $i<32; $i++)
1005  {
1006  $days[$i] = $i < 10 ? "0".$i : $i;
1007  }
1008  return ilUtil::formSelect($a_selected,"d_day",$days,false,true);
1009 
1010  case "month":
1011  for($i=1; $i<13; $i++)
1012  {
1013  $month[$i] = $i < 10 ? "0".$i : $i;
1014  }
1015  return ilUtil::formSelect($a_selected,"d_month",$month,false,true);
1016 
1017  case "year":
1018  for($i = date("Y",time());$i < date("Y",time()) + 3;++$i)
1019  {
1020  $year[$i] = $i;
1021  }
1022  return ilUtil::formSelect($a_selected,"d_year",$year,false,true);
1023  }
1024  }
1025 
1026  function __filterAssignedUsers($a_result)
1027  {
1028  foreach($a_result as $user)
1029  {
1030  if(!$this->object->members_obj->isAssigned($user["id"]))
1031  {
1032  $filtered[] = $user;
1033  }
1034  }
1035 
1036  return $filtered ? $filtered : array();
1037  }
1038 
1044  function getTabs(&$tabs_gui)
1045  {
1046  global $ilAccess,$ilUser;
1047 
1048  $next_class = strtolower($this->ctrl->getNextClass());
1049  if ($ilAccess->checkAccess("visible", "", $this->object->getRefId()))
1050  {
1051  $force_active = ($next_class == "ilinfoscreengui")
1052  ? true
1053  : false;
1054  $tabs_gui->addTarget("info_short",
1055  $this->ctrl->getLinkTargetByClass("ilinfoscreengui", "showSummary"),
1056  "showSummary",
1057  "ilinfoscreengui", "", $force_active);
1058  }
1059 
1060  /*
1061  $tabs_gui->addTarget("view",
1062  $this->ctrl->getLinkTarget($this, 'view'),
1063  array("view",""), "");*/
1064 
1065  if ($ilAccess->checkAccess("read", "", $this->object->getRefId()))
1066  {
1067  $tabs_gui->addTarget("exc_your_submission",
1068  $this->ctrl->getLinkTarget($this, "deliver"),
1069  "deliver", "");
1070  }
1071 
1072  // edit properties
1073  if ($ilAccess->checkAccess("write", "", $this->ref_id))
1074  {
1075  $tabs_gui->addTarget("edit_properties",
1076  $this->ctrl->getLinkTarget($this, 'edit'),
1077  "edit", "");
1078 
1079  $tabs_gui->addTarget("members",
1080  $this->ctrl->getLinkTarget($this, 'members'),
1081  array("members", "newMembers", "newmembers"), "");
1082  }
1083 
1084  // learning progress
1085  $save_sort_order = $_GET["sort_order"]; // hack, because exercise sort parameters
1086  $save_sort_by = $_GET["sort_by"]; // must not be forwarded to learning progress
1087  $save_offset = $_GET["offset"];
1088  $_GET["offset"] = $_GET["sort_by"] = $_GET["sort_order"] = "";
1089 
1090  include_once './Services/Tracking/classes/class.ilLearningProgressAccess.php';
1091  if(ilLearningProgressAccess::checkAccess($this->object->getRefId()))
1092  {
1093  $tabs_gui->addTarget('learning_progress',
1094  $this->ctrl->getLinkTargetByClass(array('ilobjexercisegui','illearningprogressgui'),''),
1095  '',
1096  array('illplistofobjectsgui','illplistofsettingsgui','illearningprogressgui','illplistofprogressgui'));
1097  }
1098 
1099  $_GET["sort_order"] = $save_sort_order; // hack, part ii
1100  $_GET["sort_by"] = $save_sort_by;
1101  $_GET["offset"] = $save_offset;
1102 
1103  // permissions
1104  if ($ilAccess->checkAccess("edit_permission", "", $this->ref_id))
1105  {
1106  $tabs_gui->addTarget("perm_settings",
1107  $this->ctrl->getLinkTargetByClass(array(get_class($this),'ilpermissiongui'), "perm"),
1108  array("perm","info","owner"), 'ilpermissiongui');
1109  }
1110  }
1111 
1112  function &executeCommand()
1113  {
1114  global $ilUser,$ilCtrl;
1115 
1116  $next_class = $this->ctrl->getNextClass($this);
1117  $cmd = $this->ctrl->getCmd();
1118  $this->prepareOutput();
1119 
1120 //echo "-".$next_class."-".$cmd."-"; exit;
1121  switch($next_class)
1122  {
1123  case "ilinfoscreengui":
1124  $this->infoScreen(); // forwards command
1125  break;
1126 
1127  case 'ilpermissiongui':
1128  include_once("Services/AccessControl/classes/class.ilPermissionGUI.php");
1129  $perm_gui =& new ilPermissionGUI($this);
1130  $ret =& $this->ctrl->forwardCommand($perm_gui);
1131  break;
1132 
1133  case "illearningprogressgui":
1134  include_once './Services/Tracking/classes/class.ilLearningProgressGUI.php';
1135 
1136  $new_gui =& new ilLearningProgressGUI(LP_MODE_REPOSITORY,
1137  $this->object->getRefId(),
1138  $_GET['user_id'] ? $_GET['user_id'] : $ilUser->getId());
1139  $this->ctrl->forwardCommand($new_gui);
1140  $this->tabs_gui->setTabActive('learning_progress');
1141  break;
1142 
1143  case 'ilrepositorysearchgui':
1144  include_once('./Services/Search/classes/class.ilRepositorySearchGUI.php');
1145  $rep_search =& new ilRepositorySearchGUI();
1146  $rep_search->setCallback($this,'addMembersObject');
1147 
1148  // Set tabs
1149  $this->tabs_gui->setTabActive('members');
1150  $this->ctrl->setReturn($this,'members');
1151  $ret =& $this->ctrl->forwardCommand($rep_search);
1152  #$this->__setSubTabs('members');
1153  #$this->tabs_gui->setSubTabActive('members');
1154  break;
1155 
1156  case 'ilobjectcopygui':
1157  $ilCtrl->saveParameter($this, 'new_type');
1158  $ilCtrl->setReturnByClass(get_class($this),'create');
1159 
1160  include_once './Services/Object/classes/class.ilObjectCopyGUI.php';
1161  $cp = new ilObjectCopyGUI($this);
1162  $cp->setType('exc');
1163  $this->ctrl->forwardCommand($cp);
1164  break;
1165 
1166  default:
1167  if(!$cmd)
1168  {
1169  $cmd = "infoScreen";
1170  }
1171 
1172  $cmd .= "Object";
1173 
1174  $this->$cmd();
1175 
1176  break;
1177  }
1178 
1179  return true;
1180  }
1181 
1187  function infoScreenObject()
1188  {
1189  $this->ctrl->setCmd("showSummary");
1190  $this->ctrl->setCmdClass("ilinfoscreengui");
1191  $this->infoScreen();
1192  }
1193 
1197  function infoScreen()
1198  {
1199  global $ilAccess, $ilUser;
1200 
1201  $this->checkPermission("visible");
1202 
1203  include_once("./Services/InfoScreen/classes/class.ilInfoScreenGUI.php");
1204  $info = new ilInfoScreenGUI($this);
1205 
1206  $info->enablePrivateNotes();
1207 
1208  $info->enableNews();
1209  if ($ilAccess->checkAccess("write", "", $_GET["ref_id"]))
1210  {
1211  $info->enableNewsEditing();
1212  $info->setBlockProperty("news", "settings", true);
1213  }
1214 
1215  // standard meta data
1216  //$info->addMetaDataSections($this->object->getId(),0, $this->object->getType());
1217 
1218  // instructions
1219  $info->addSection($this->lng->txt("exc_instruction"));
1220  $info->addProperty("",
1221  nl2br($this->object->getInstruction()));
1222 
1223  // schedule
1224  $info->addSection($this->lng->txt("exc_schedule"));
1225  $info->addProperty($this->lng->txt("exc_edit_until"),
1226  ilDatePresentation::formatDate(new ilDateTime($this->object->getTimestamp(),IL_CAL_UNIX)));
1227 
1228  if ($this->object->getTimestamp()-time() <= 0)
1229  {
1230  $time_str = $this->lng->txt("exc_time_over_short");
1231  }
1232  else
1233  {
1234  $time_diff = ilUtil::int2array($this->object->getTimestamp()-time(),null);
1235  // BEGIN Usability: Never display seconds
1236  unset($time_diff['seconds']);
1237  // END Usability: Never display seconds
1238  // BEGIN Usability: Don't display minutes, if it takes days
1239  if (isset($time_diff['days']))
1240  {
1241  unset($time_diff['minutes']);
1242  }
1243  // END Usability: Don't display minutes, if it takes days
1244  // BEGIN Usability: Don't display hours, if it takes months
1245  if (isset($time_diff['months']))
1246  {
1247  unset($time_diff['hours']);
1248  }
1249  // END Usability: Don't display minutes, if it takes months
1250  $time_str = ilUtil::timearray2string($time_diff);
1251  }
1252  $info->addProperty($this->lng->txt("exc_time_to_send"),
1253  "<b>".$time_str."</b>");
1254 
1255  // download files
1256  if ($ilAccess->checkAccess("read", "", $this->ref_id))
1257  {
1258  $files = $this->object->getFiles();
1259  if (count($files) > 0)
1260  {
1261  $info->addSection($this->lng->txt("exc_files"));
1262  foreach($files as $file)
1263  {
1264  $this->ctrl->setParameter($this, "file", urlencode($file["name"]));
1265  $info->addProperty($file["name"],
1266  $this->lng->txt("download"),
1267  $this->ctrl->getLinkTarget($this, "downloadFile"));
1268  $this->ctrl->setParameter($this, "file", "");
1269  }
1270  }
1271  }
1272 
1273  // submission and feedback info only if read permission given
1274  if ($ilAccess->checkAccess("read", "", $this->ref_id))
1275  {
1276  // submission
1277  $info->addSection($this->lng->txt("exc_your_submission"));
1278  $delivered_files = $this->object->getDeliveredFiles($ilUser->id);
1279  $titles = array();
1280  foreach($delivered_files as $file)
1281  {
1282  $titles[] = $file["filetitle"];
1283  }
1284  $files_str = implode($titles, ", ");
1285  if ($files_str == "")
1286  {
1287  $files_str = $this->lng->txt("message_no_delivered_files");
1288  }
1289  $info->addProperty($this->lng->txt("exc_files_returned"),
1290  $files_str);
1291  $last_sub = $this->object->getLastSubmission($ilUser->getId());
1292  if ($last_sub)
1293  {
1294  $last_sub = ilDatePresentation::formatDate(new ilDateTime($last_sub,IL_CAL_DATETIME));
1295  }
1296  else
1297  {
1298  $last_sub = "---";
1299  }
1300 
1301  $info->addProperty($this->lng->txt("exc_last_submission"),
1302  $last_sub);
1303 
1304  // feedback from tutor
1305  include_once("Services/Tracking/classes/class.ilLPMarks.php");
1306  $lpcomment = ilLPMarks::_lookupComment($ilUser->getId(), $this->object->getId());
1307  $mark = ilLPMarks::_lookupMark($ilUser->getId(), $this->object->getId());
1308  $status = ilExerciseMembers::_lookupStatus($this->object->getId(), $ilUser->getId());
1309  if ($lpcomment != "" || $mark != "" || $status != "notgraded")
1310  {
1311  $info->addSection($this->lng->txt("exc_feedback_from_tutor"));
1312  if ($lpcomment != "")
1313  {
1314  $info->addProperty($this->lng->txt("exc_comment"),
1315  $lpcomment);
1316  }
1317  if ($mark != "")
1318  {
1319  $info->addProperty($this->lng->txt("exc_mark"),
1320  $mark);
1321  }
1322 
1323  if ($status == "")
1324  {
1325  $info->addProperty($this->lng->txt("status"),
1326  $this->lng->txt("message_no_delivered_files"));
1327  }
1328  else
1329  if ($status != "notgraded")
1330  {
1331  $info->addProperty($this->lng->txt("status"),
1332  $this->lng->txt("exc_".$status));
1333  }
1334  }
1335  }
1336 
1337  // forward the command
1338  $this->ctrl->forwardCommand($info);
1339  }
1340 
1341 
1347  function _goto($a_target)
1348  {
1349  global $rbacsystem, $ilErr, $lng, $ilAccess;
1350 
1351  if ($ilAccess->checkAccess("visible", "", $a_target))
1352  {
1353  $_GET["ref_id"] = $a_target;
1354  $_GET["cmd"] = "infoScreen";
1355  $_GET["baseClass"] = "ilExerciseHandlerGUI";
1356  include("ilias.php");
1357  exit;
1358  }
1359  else if ($ilAccess->checkAccess("read", "", ROOT_FOLDER_ID))
1360  {
1361  $_GET["cmd"] = "frameset";
1362  $_GET["target"] = "";
1363  $_GET["ref_id"] = ROOT_FOLDER_ID;
1364  ilUtil::sendFailure(sprintf($lng->txt("msg_no_perm_read_item"),
1365  ilObject::_lookupTitle(ilObject::_lookupObjId($a_target))), true);
1366  include("repository.php");
1367  exit;
1368  }
1369 
1370  $ilErr->raiseError($lng->txt("msg_no_perm_read"), $ilErr->FATAL);
1371  }
1372 
1376  function addLocatorItems()
1377  {
1378  global $ilLocator;
1379 
1380  if (is_object($this->object))
1381  {
1382  $ilLocator->addItem($this->object->getTitle(), $this->ctrl->getLinkTarget($this, "infoScreen"), "", $_GET["ref_id"]);
1383  }
1384  }
1385 
1386 } // END class.ilObjExerciseGUI
1387 
1388 ?>