ILIAS  Release_3_10_x_branch Revision 61812
 All Data Structures Namespaces Files Functions Variables Groups Pages
class.ilObjExerciseGUI.php
Go to the documentation of this file.
1 <?php
2 /*
3  +-----------------------------------------------------------------------------+
4  | ILIAS open source |
5  +-----------------------------------------------------------------------------+
6  | Copyright (c) 1998-2001 ILIAS open source, University of Cologne |
7  | |
8  | This program is free software; you can redistribute it and/or |
9  | modify it under the terms of the GNU General Public License |
10  | as published by the Free Software Foundation; either version 2 |
11  | of the License, or (at your option) any later version. |
12  | |
13  | This program is distributed in the hope that it will be useful, |
14  | but WITHOUT ANY WARRANTY; without even the implied warranty of |
15  | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
16  | GNU General Public License for more details. |
17  | |
18  | You should have received a copy of the GNU General Public License |
19  | along with this program; if not, write to the Free Software |
20  | Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. |
21  +-----------------------------------------------------------------------------+
22 */
23 
24 
25 require_once "classes/class.ilObjectGUI.php";
26 
38 {
43  function ilObjExerciseGUI($a_data,$a_id,$a_call_by_reference,$a_prepare_output = true)
44  {
45  global $lng;
46 
47  $this->type = "exc";
48  $this->ilObjectGUI($a_data,$a_id,$a_call_by_reference,false);
49 
50  $lng->loadLanguageModule("exercise");
51  $this->ctrl->saveParameter($this, array("sort_by", "sort_order", "offset"));
52  }
53 
54  function getFiles()
55  {
56  return $this->files ? $this->files : array();
57  }
58 
59  function setFiles($a_files)
60  {
61  $this->files = $a_files;
62  }
63 
64  function createObject($a_reload = false)
65  {
66  global $tpl;
67 
68  $this->getTemplateFile("edit", "exc");
69 
70  if (!$a_reload)
71  {
72  $this->initPropertiesForm("create");
73  }
74  $this->tpl->setVariable("EDIT_FORM", $this->form_gui->getHtml());
75 
76  $this->fillCloneTemplate('DUPLICATE','exc');
77 return;
79 
80  $this->tpl->setVariable("INSTRUCTION",
81  ilUtil::prepareFormOutput($_SESSION["error_post_vars"]["Fobject"]["instruction"], true));
82 
83  // SET ADDITIONAL TEMPLATE VARIABLES
84  $this->tpl->setVariable("TXT_INSTRUCTION",$this->lng->txt("exc_instruction"));
85  $this->tpl->setVariable("TXT_EDIT_UNTIL",$this->lng->txt("exc_edit_until"));
86  $this->tpl->setVariable("TXT_HOUR",$this->lng->txt("time_h"));
87  $this->tpl->setVariable("TXT_DAY",$this->lng->txt("time_d"));
88  $this->tpl->setVariable("SELECT_HOUR",$this->__getDateSelect("hour",(int) date("H",time())));
89  $this->tpl->setVariable("SELECT_MINUTES",$this->__getDateSelect("minutes",(int) date("i",time())));
90  $this->tpl->setVariable("SELECT_DAY",$this->__getDateSelect("day",(int) date("d",time())));
91  $this->tpl->setVariable("SELECT_MONTH",$this->__getDateSelect("month",(int) date("m",time())));
92  $this->tpl->setVariable("SELECT_YEAR",$this->__getDateSelect("year",1));
93  $this->tpl->setVariable("CMD_CANCEL", "cancel");
94 
95  $this->fillCloneTemplate('DUPLICATE','exc');
96 
97  return true;
98  }
99 
100  function viewObject()
101  {
102  $this->infoScreenObject();
103  return;
104  global $rbacsystem,$ilUser;
105 
106  include_once 'Services/Tracking/classes/class.ilLearningProgress.php';
107  ilLearningProgress::_tracProgress($ilUser->getId(),$this->object->getId(),'exc');
108 
109 
110  if (strtolower($_GET["baseClass"]) == "iladministrationgui")
111  {
113  return;
114  }
115 
116  if (!$rbacsystem->checkAccess("read", $this->ref_id))
117  {
118  $this->ilias->raiseError($this->lng->txt("msg_no_perm_read"),$this->ilias->error_obj->MESSAGE);
119  }
120  $this->getTemplateFile("view", "exc");
121 
122  $this->tpl->setVariable("FORM_DOWNLOAD_ACTION", $this->ctrl->getFormAction($this, "downloadFile"));
123  $this->tpl->setVariable("TITLE_TXT",$this->lng->txt("title"));
124  $this->tpl->setVariable("TITLE",$this->object->getTitle());
125  $this->tpl->setVariable("TXT_HEADER",$this->lng->txt("exc_details"));
126  $this->tpl->setVariable("DESCRIPTION_TXT",$this->lng->txt("description"));
127  $this->tpl->setVariable("DESCRIPTION",$this->object->getDescription());
128  $this->tpl->setVariable("INSTRUCTION_TXT",$this->lng->txt("exc_instruction"));
129  $this->tpl->setVariable("INSTRUCTION",nl2br($this->object->getInstruction()));
130  $this->tpl->setVariable("EDIT_UNTIL_TXT",$this->lng->txt("exc_edit_until"));
131  $this->tpl->setVariable("EDIT_UNTIL",date("H:i, d.m.Y",$this->object->getTimestamp()));
132  $this->tpl->setVariable("TIME_TO_SEND_TXT",$this->lng->txt("exc_time_to_send"));
133 
134  if ($this->object->getTimestamp()-time() <= 0)
135  {
136  $this->tpl->setCurrentBlock("TIME_REACHED");
137  $this->tpl->setVariable("TIME_TO_SEND",$this->lng->txt("exc_time_over_short"));
138  $this->tpl->parseCurrentBlock();
139  }
140  else {
141  $timediff = ilUtil::int2array($this->object->getTimestamp()-time(),null);
142  $timestr = ilUtil::timearray2string($timediff);
143  $this->tpl->setCurrentBlock("TIME_NOT_REACHED");
144  $this->tpl->setVariable("TIME_TO_SEND",$timestr);
145  $this->tpl->parseCurrentBlock();
146  }
147 
148  $anyfiles = false;
149  foreach($this->object->getFiles() as $file)
150  {
151  $this->tpl->setCurrentBlock("FILES_ROW");
152  $this->tpl->setVariable("FILE_DATA",$file["name"]);
153  $this->tpl->setVariable("FILE_CHECK",ilUtil::formRadioButton(0,"file",urlencode($file["name"])));
154  $this->tpl->parseCurrentBlock();
155  $anyfiles = true;
156  }
157 
158  if ($anyfiles)
159  {
160  $this->tpl->setCurrentBlock("FILES");
161  $this->tpl->setVariable("FILES_TXT",$this->lng->txt("exc_files"));
162  $this->tpl->setVariable("TXT_DOWNLOAD",$this->lng->txt("download"));
163  $this->tpl->setVariable("IMG",ilUtil::getImagePath("arrow_downright.gif"));
164  $this->tpl->parseCurrentBlock();
165  }
166 
167  $this->tpl->setCurrentBlock("perma_link");
168  $this->tpl->setVariable("PERMA_LINK", ILIAS_HTTP_PATH.
169  "/goto.php?target=".
170  $this->object->getType().
171  "_".$this->object->getRefId()."&client_id=".CLIENT_ID);
172  $this->tpl->setVariable("TXT_PERMA_LINK", $this->lng->txt("perma_link"));
173  $this->tpl->setVariable("PERMA_TARGET", "_top");
174  $this->tpl->parseCurrentBlock();
175 
176  return true;
177  }
178 
184  function deliverObject()
185  {
186  global $ilUser;
187  require_once "./Services/Utilities/classes/class.ilUtil.php";
188 
189  $this->checkPermission("read");
190 
191  $this->tabs_gui->setTabActive("exc_your_submission");
192 
193  if (mktime() > $this->object->getTimestamp())
194  {
195  ilUtil::sendInfo($this->lng->txt("exercise_time_over"));
196  }
197 
198 
199  if ($_POST["cmd"]["delete"] && mktime() < $this->object->getTimestamp())
200  {
201  if (count($_POST["delivered"]))
202  {
203  $this->object->deleteDeliveredFiles($_POST["delivered"], $ilUser->id);
204  }
205  else
206  {
207  ilUtil::sendInfo($this->lng->txt("please_select_a_delivered_file_to_delete"));
208  }
209  }
210 
211  if ($_POST["cmd"]["download"])
212  {
213  if (count($_POST["delivered"]))
214  {
215  $this->object->members_obj->downloadSelectedFiles($_POST["delivered"],$ilUser->getId());
216  }
217  else
218  {
219  ilUtil::sendInfo($this->lng->txt("please_select_a_delivered_file_to_download"));
220  }
221  }
222 
223 
224  if (mktime() > $this->object->getTimestamp())
225  {
226  $this->getTemplateFile("delivered_files", "exc");
227  }
228  else
229  {
230  $this->getTemplateFile("deliver_file", "exc");
231  }
232 
233  $delivered_files = $this->object->getDeliveredFiles($ilUser->id);
234  $color_class = array("tblrow1", "tblrow2");
235  $counter = 0;
236  foreach ($delivered_files as $index => $file)
237  {
238  $this->tpl->setCurrentBlock("delivered_row");
239  $this->tpl->setVariable("COLOR_CLASS", $color_class[$counter % 2]);
240  $this->tpl->setVariable("FILE_ID", $file["returned_id"]);
241  $this->tpl->setVariable("DELIVERED_FILE", $file["filetitle"]);
242  /*
243  preg_match("/(\d{4})(\d{2})(\d{2})(\d{2})(\d{2})(\d{2})/", $file["timestamp14"], $matches);
244  $stamp = strtotime(sprintf("%04d-%02d-%02d %02d:%02d:%02d",
245  $matches[1], $matches[2], $matches[3],
246  $matches[4], $matches[5], $matches[6]));
247  $date = date($this->lng->text["lang_dateformat"] . " " . $this->lng->text["lang_timeformat"], $stamp);
248  */
249  $date = new ilDateTime($file['timestamp14'],IL_CAL_TIMESTAMP);
250  $this->tpl->setVariable("DELIVERED_DATE", ilDatePresentation::formatDate($date));
251  $this->tpl->parseCurrentBlock();
252  $counter++;
253  }
254  if (count($delivered_files))
255  {
256  $this->tpl->setCurrentBlock("footer_content");
257  $this->tpl->setVariable("ARROW_SIGN", ilUtil::getImagePath("arrow_downright.gif"));
258  $this->tpl->setVariable("BUTTON_DELETE", $this->lng->txt("delete"));
259  $this->tpl->setVariable("BUTTON_DOWNLOAD", $this->lng->txt("download"));
260  $this->tpl->parseCurrentBlock();
261  }
262  else
263  {
264  $this->tpl->setCurrentBlock("footer_empty");
265  $this->tpl->setVariable("TEXT_NO_DELIVERED_FILES",
266  $this->lng->txt("message_no_delivered_files"));
267  $this->tpl->parseCurrentBlock();
268  }
269 
270  $this->tpl->setCurrentBlock("delivered_files");
271  $this->tpl->setVariable("DELIVER_FORMACTION",
272  $this->ctrl->getLinkTarget($this, "deliver"));
273  $this->tpl->setVariable("TEXT_DATE", $this->lng->txt("date"));
274  $this->tpl->setVariable("TEXT_DELIVERED_FILENAME", $this->lng->txt("filename"));
275  $this->tpl->setVariable("TEXT_HEADING_DELIVERED_FILES", $this->lng->txt("already_delivered_files"));
276  $this->tpl->parseCurrentBlock();
277  $this->tpl->setCurrentBlock("adm_content");
278  $this->tpl->setVariable("FORMACTION",
279  $this->ctrl->getLinkTarget($this, "deliverFile"));
280  $this->tpl->setVariable("BUTTON_DELIVER", $this->lng->txt("upload"));
281  $this->tpl->setVariable("TEXT_FILENAME", $this->lng->txt("enter_filename_deliver"));
282  $this->tpl->setVariable("TXT_UPLOAD_FILE", $this->lng->txt("file_add"));
283  $this->tpl->setVariable("TXT_UPLOAD_ZIPFILE", $this->lng->txt("header_zip"));
284  $this->tpl->parseCurrentBlock();
285 
286  }
287 
288  function deliverFileObject()
289  {
290  global $ilUser, $lng;
291 
292  $this->checkPermission("read");
293 
294  $this->tabs_gui->setTabActive("view");
295  $this->tabs_gui->setTabActive("exc_your_submission");
296 
297  if (!empty($_POST["cmd"][deliverUnzip]) && preg_match("/zip/",$_FILES["deliver"]["type"]) == 1)
298  {
299  $this->object->processUploadedFile($_FILES["deliver"]["tmp_name"], "deliverFile", false);
300 
301  }
302  else
303  {
304  if(!$this->object->deliverFile($_FILES["deliver"], $ilUser->id))
305  {
306  ilUtil::sendInfo($this->lng->txt("exc_upload_error"),true);
307  }
308  }
309 
310 
311  $this->deliverObject();
312  }
313 
315  {
316  global $rbacsystem;
317 
318  $file = ($_POST["file"])
319  ? $_POST["file"]
320  : $_GET["file"];
321 
322  $this->checkPermission("read");
323 
324  if (!isset($file))
325  {
326  ilUtil::sendInfo($this->lng->txt("exc_select_one_file"),true);
327  $this->ctrl->redirect($this, "view");
328  }
329  $files = $this->object->getFiles();
330  $file_exist = false;
331 
332  foreach($this->object->getFiles() as $lfile)
333  {
334  if($lfile["name"] == urldecode($file))
335  {
336  $file_exist = true;
337  break;
338  }
339  }
340  if(!$file_exist)
341  {
342  echo "FILE DOES NOT EXIST";
343  exit;
344  }
345  ilUtil::deliverFile($this->object->file_obj->getAbsolutePath(urldecode($file)),
346  urldecode($file));
347 
348  return true;
349  }
350 
355  function saveObject()
356  {
357  global $rbacadmin;
358 
359  $this->initPropertiesForm("create");
360 
361  if ($this->form_gui->checkInput())
362  {
363  // always call parent method first to create an object_data entry & a reference
364  $newObj = parent::saveObject();
365 
366  // setup rolefolder & default local roles if needed (see ilObjForum & ilObjForumGUI for an example)
367  //$roles = $newObj->initDefaultRoles();
368 
369  // put here your object specific stuff
370 
371  $newObj->setTitle($this->form_gui->getInput("title"));
372  $newObj->setDescription($this->form_gui->getInput("desc"));
373  $newObj->setInstruction($this->form_gui->getInput("instruction"));
374  $edit_date =
375  $this->form_gui->getItemByPostVar("edit_date")->getDate();
376  $newObj->setTimestamp($edit_date->get(IL_CAL_UNIX));
377 
378  $newObj->saveData();
379  $newObj->update();
380 
381  // always send a message
382  ilUtil::sendInfo($this->lng->txt("exc_added"),true);
383  ilUtil::redirect("ilias.php?baseClass=ilExerciseHandlerGUI&ref_id=".$newObj->getRefId()."&cmd=edit");
384  }
385  else
386  {
387  $this->form_gui->setValuesByPost();
388  $this->createObject(true);
389  }
390  }
391 
392  function editObject()
393  {
394  global $rbacsystem, $tpl;
395 
396  $this->checkPermission("write");
397 
398  $this->getTemplateFile("edit", "exc");
399 
400  $this->initPropertiesForm("edit");
401  $this->getPropertiesValues();
402 
403  $this->tpl->setVariable("EDIT_FORM", $this->form_gui->getHtml());
404 
405  $this->tpl->setCurrentBlock("FILES");
406  $this->tpl->setVariable("TXT_HEADER_FILE",$this->lng->txt("file_add"));
407  $this->tpl->setVariable("TXT_FILE",$this->lng->txt("file"));
408  $this->tpl->setVariable("TXT_UPLOAD",$this->lng->txt("upload"));
409  $this->tpl->setVariable("FORMACTION_FILE", $this->ctrl->getFormAction($this));
410  $this->tpl->setVariable("TXT_HEADER_ZIP", $this->lng->txt("header_zip"));
411  $this->tpl->setVariable("CMD_FILE_SUBMIT","uploadFile");
412  $this->tpl->parseCurrentBlock();
413  }
414 
420  public function initPropertiesForm($a_mode = "create")
421  {
422  global $lng, $ilCtrl;
423 
424  // init form
425  $lng->loadLanguageModule("form");
426  include_once("./Services/Form/classes/class.ilPropertyFormGUI.php");
427  $this->form_gui = new ilPropertyFormGUI();
428  $this->form_gui->setTableWidth("60%");
429  if ($a_mode == "edit")
430  {
431  $this->form_gui->setTitle($lng->txt("exc_edit_exercise"));
432  }
433  else
434  {
435  $this->form_gui->setTitle($lng->txt("exc_new"));
436  }
437  $this->form_gui->setTitleIcon(ilUtil::getImagePath("icon_exc.gif"));
438  $this->form_gui->setFormAction($ilCtrl->getFormAction($this));
439 
440 
441  // on creation: Type
442  if ($a_mode == "create")
443  {
444  $type_input = new ilHiddenInputGUI("new_type");
445  $type_input->setValue("exc");
446  $this->form_gui->addItem($type_input);
447  }
448 
449  // Title
450  $title_input = new ilTextInputGUI($lng->txt("title"), "title");
451  $title_input->setRequired(true);
452  $title_input->setMaxLength(128);
453  $this->form_gui->addItem($title_input);
454 
455  // Description
456  $desc_input = new ilTextAreaInputGUI($lng->txt("desc"), "desc");
457  $this->form_gui->addItem($desc_input);
458 
459  // Work Instructions
460  $desc_input = new ilTextAreaInputGUI($lng->txt("exc_instruction"), "instruction");
461  $this->form_gui->addItem($desc_input);
462 
463  // Edit until...
464  $edit_date = new ilDateTimeInputGUI($lng->txt("exc_edit_until"), "edit_date");
465  //$dt_prop->setDate(new ilDateTime("2006-12-24 15:44:00", IL_CAL_DATETIME);
466  $edit_date->setShowTime(true);
467  //$dt_prop->setInfo("Info text for the start date.");
468  $this->form_gui->addItem($edit_date);
469 
470  // files
471  if ($a_mode == "edit")
472  {
473  if(count($files = $this->object->getFiles()))
474  {
475  // Files section header
476  $files_head = new ilFormSectionHeaderGUI();
477  $files_head->setTitle($lng->txt("files"));
478  $this->form_gui->addItem($files_head);
479 
480  foreach($files as $file)
481  {
482  $i++;
483  $file_cb = new ilCheckboxInputGUI($this->lng->txt("exc_ask_delete"),
484  "delete_file_".$i);
485  $file_cb->setOptionTitle($file["name"]);
486  $file_cb->setValue($file["name"]);
487  $this->form_gui->addItem($file_cb);
488  }
489  }
490  }
491 
492  // save and cancel commands
493  if ($a_mode == "create")
494  {
495  $this->form_gui->addCommandButton("save", $lng->txt("save"));
496  $this->form_gui->addCommandButton("cancel", $lng->txt("cancel"));
497  }
498  else
499  {
500  $this->form_gui->addCommandButton("update", $lng->txt("save"));
501  $this->form_gui->addCommandButton("cancelEdit", $lng->txt("cancel"));
502  }
503  }
504 
509  {
510  $values["title"] = $this->object->getTitle();
511  $values["desc"] = $this->object->getLongDescription();
512  $values["instruction"] = $this->object->getInstruction();
513  $this->form_gui->setValuesByArray($values);
514 
515 //echo "-".$this->object->getTimestamp()."-";
516  $edit_date = new ilDateTime($this->object->getTimestamp(), IL_CAL_UNIX);
517  $ed_item = $this->form_gui->getItemByPostVar("edit_date");
518  $ed_item->setDate($edit_date);
519  }
520 
524  function updateObject()
525  {
526  global $rbacsystem, $tpl;
527 
528  $this->checkPermission("write");
529 
530  $this->initPropertiesForm("edit");
531  if ($this->form_gui->checkInput())
532  {
533  $this->object->setTitle($this->form_gui->getInput("title"));
534  $this->object->setDescription($this->form_gui->getInput("desc"));
535  $this->object->setInstruction($this->form_gui->getInput("instruction"));
536  $edit_date =
537  $this->form_gui->getItemByPostVar("edit_date")->getDate();
538  $this->object->setTimestamp($edit_date->get(IL_CAL_UNIX));
539 
540  // delete files
541  $del_files = array();
542  foreach ($_POST as $k => $v)
543  {
544  if (substr($k, 0, 12) == "delete_file_" && $v != "")
545  {
546  $del_files[] = $v;
547  }
548  }
549 
550  $this->object->deleteFiles($del_files);
551 
552  $this->object->update();
553 
554  ilUtil::sendInfo($this->lng->txt("msg_obj_modified"),true);
555  $this->ctrl->redirect($this, "edit");
556  }
557  else
558  {
559  $this->form_gui->setValuesByPost();
560  $tpl->setContent($this->form_gui->getHTML());
561  }
562 
563 return;
564 
565  $this->object->setInstruction(ilUtil::stripSlashes($_POST["Fobject"]["instruction"]));
566  $this->object->setDate($_POST["d_hour"],$_POST["d_minutes"],$_POST["d_day"],
567  $_POST["d_month"],$_POST["d_year"]);
568  if($_POST["delete_file"])
569  {
570  $this->object->deleteFiles($_POST["delete_file"]);
571  }
572 
573  $this->object->setTitle(ilUtil::stripSlashes($_POST["Fobject"]["title"]));
574  $this->object->setDescription(ilUtil::stripSlashes($_POST["Fobject"]["desc"]));
575  $this->update = $this->object->update();
576 
577  ilUtil::sendInfo($this->lng->txt("msg_obj_modified"),true);
578 
579  $this->ctrl->redirect($this, "edit");
580  }
581 
582  function cancelEditObject()
583  {
584  ilUtil::sendInfo($this->lng->txt("msg_cancel"),true);
585  $this->ctrl->redirect($this, "view");
586  }
587 
588  function uploadZipObject()
589  {
590  global $rbacsystem;
591 
592  $this->checkPermission("write");
593 
594  if(!$this->object->addUploadedFile($_FILES["zipfile"], true))
595  {
596  ilUtil::sendInfo($this->lng->txt("exc_upload_error"),true);
597  }
598  $this->ctrl->redirect($this, "edit");
599 
600  }
601 
602  function uploadFileObject()
603  {
604  global $rbacsystem;
605 
606  $this->checkPermission("write");
607 
608  if(!$this->object->addUploadedFile($_FILES["file"]))
609  {
610  ilUtil::sendInfo($this->lng->txt("exc_upload_error"),true);
611  }
612  $this->ctrl->redirect($this, "edit");
613  }
614 
615 
620  {
621  global $rbacsystem;
622 
623  $this->checkPermission("write");
624 
625  if ($_POST["downloadReturned"])
626  {
627  $this->object->members_obj->deliverReturnedFiles(key($_POST["downloadReturned"]));
628  exit;
629  }
630  else
631  {
632  switch($_POST["action"])
633  {
634  case "save_status":
635  $users = $this->__saveStatus();
636  break;
637 
638  case "send_member":
639  if(!count($_POST["member"]))
640  {
641  ilUtil::sendInfo($this->lng->txt("select_one"),true);
642  }
643  else
644  {
645  $this->object->send($_POST["member"]);
646  ilUtil::sendInfo($this->lng->txt("exc_sent"),true);
647  }
648  break;
649 
650  case "redirectFeedbackMail":
652  /*
653  include_once('./Services/User/classes/class.ilObjUser.php');
654 
655  if (!count($_POST["member"]))
656  {
657  ilUtil::sendInfo($this->lng->txt("select_one"),true);
658  }
659  else
660  {
661  $recipients = "";
662  foreach($_POST["member"] as $rcpt => $value)
663  {
664  $user = new ilObjUser($rcpt,false);
665  $recipients = $recipients.$user->getLogin().",";
666  }
667 
668  ilUtil::redirect("ilias.php?baseClass=ilMailGUI&type=new&rcp_to=".$recipients);
669  }*/
670  break;
671 
672  case "delete_member":
673  $this->__deassignMembers();
674  break;
675  }
676  }
677  $this->ctrl->redirect($this, "members");
678  }
679 
684  {
685  $this->checkPermission("write");
686 
687  if (!$this->object->members_obj->deliverReturnedFiles($_GET["member_id"]))
688  {
689  $this->ctrl->redirect($this, "members");
690  }
691  exit;
692  }
693 
698  {
699  $this->checkPermission("write");
700 
701  if (!$this->object->members_obj->deliverReturnedFiles($_GET["member_id"], true))
702  {
703  $this->ctrl->redirect($this, "members");
704  }
705  exit;
706  }
707 
708  function addMembersObject()
709  {
710  global $ilAccess,$ilErr;
711 
712  $this->checkPermission("write");
713  if(!count($_POST['user']))
714  {
715  ilUtil::sendInfo($this->lng->txt("no_checkbox"));
716  return false;
717  }
718 
719  if(!$this->object->members_obj->assignMembers($_POST["user"]))
720  {
721  ilUtil::sendInfo($this->lng->txt("exc_members_already_assigned"));
722  return false;
723  }
724  else
725  {
726  ilUtil::sendInfo($this->lng->txt("exc_members_assigned"),true);
727  }
728  $this->ctrl->redirect($this, "members");
729  return false;
730  }
731 
732 
733  function membersObject()
734  {
735  global $rbacsystem, $tree;
736 
737  include_once 'Services/Tracking/classes/class.ilLPMarks.php';
738 
739  $this->checkPermission("write");
740 
741  //add template for buttons
742  $this->tpl->addBlockfile("BUTTONS", "buttons", "tpl.buttons.html");
743 
744  // add member button
745  $this->tpl->setCurrentBlock("btn_cell");
746  $this->tpl->setVariable("BTN_LINK",$this->ctrl->getLinkTargetByClass('ilRepositorySearchGUI','start'));
747  $this->tpl->setVariable("BTN_TXT",$this->lng->txt("add_member"));
748  $this->tpl->parseCurrentBlock();
749 
750  // add course members button, in case the exercise is inside a course
751  $parent_id = $tree->getParentId($_GET["ref_id"]);
752  $parent_obj_id = ilObject::_lookupObjId($parent_id);
753  $type = ilObject::_lookupType($parent_obj_id);
754  //$obj = new ilObject($parent_id, true);
755  //$type = $obj->getType();
756 
757  // search for a parent course
758  while ($parent_id != 1 && $type != "crs")
759  {
760  $parent_id = $tree->getParentId($parent_id);
761  $parent_obj_id = ilObject::_lookupObjId($parent_id);
762  $type = ilObject::_lookupType($parent_obj_id);
763 
764  //$obj = new ilObject($parent_id, true);
765  //$type = $obj->getType();
766  }
767 
768  if ($type == "crs")
769  {
770  $search_for_role = "il_crs_member_" . $parent_id;
771  $this->tpl->setCurrentBlock("btn_cell");
772 
773  $_SESSION['rep_query']['role']['title'] = $search_for_role;
774  $_SESSION['rep_search_type'] = 'role';
775 
776  $this->tpl->setVariable("BTN_LINK",$this->ctrl->getLinkTargetByClass('ilRepositorySearchGUI','performSearch'));
777  $this->lng->loadLanguageModule("exercise");
778  $this->tpl->setVariable("BTN_TXT",$this->lng->txt("exc_crs_add_members"));
779  $this->tpl->parseCurrentBlock();
780  }
781 
782 
783  $this->getTemplateFile("members","exc");
784 
785  if(!count($this->object->members_obj->getMembers()))
786  {
787  ilUtil::sendInfo($this->lng->txt("exc_no_members_assigned"));
788  }
789  else
790  {
791  // if we come from edit_comments action button
792  /*
793  if (!empty($_GET["comment_id"]))
794  {
795  //$tmp_obj = ilObjectFactory::getInstanceByObjId($_GET["comment_id"],false);
796  $tmp_obj = new ilObjUser($_GET["comment_id"]);
797  $this->tpl->setCurrentBlock("comments");
798  $this->tpl->setVariable("COMMENTS_FORMACTION",
799  $this->ctrl->setParameter();
800  $this->getFormAction("saveComments",
801  $this->ctrl->getLinkTarget($this, "saveComments")
802  "exercise.php?ref_id=".$_GET["ref_id"]."&member_id=".$_GET["comment_id"]."&cmd=saveComments&cmdClass=ilobjexercisegui&cmdNode=1&baseClass="));
803  $this->tpl->setVariable("NOTICE_VALUE", $this->getComments($_GET["comment_id"]));
804  $this->tpl->setVariable("MEMBER_PICTURE", $tmp_obj->getPersonalPicturePath("xsmall"));
805  $this->tpl->setVariable("MEMBER_ID", $_GET["comment_id"]);
806  $this->tpl->setVariable("SAVE_COMMENTS", $this->lng->txt("save"));
807  $this->tpl->setVariable("EDIT_COMMENTS", $this->lng->txt("edit_comments"));
808  $this->tpl->setVariable("MEMBER_LOGIN", $tmp_obj->getLastName().", ".$tmp_obj->getFirstName());
809 
810  $this->tpl->parseCurrentBlock();
811  }*/
812 
813  $counter = 0;
814  $members = $this->object->getMemberListData();
815 
816  include_once("./Services/Table/classes/class.ilTableGUI.php");
817  $tbl = new ilTableGUI();
818  $tbl->setSelectAllCheckbox("member");
819  $tbl->setFormName("cmd");
820  $tbl->enable("select_all");
821  $this->tpl->addBlockfile("MEMBER_TABLE", "term_table", "tpl.table.html");
822  $this->tpl->addBlockfile("TBL_CONTENT", "member_row", "tpl.exc_members_row.html", "Modules/Exercise");
823 
824  $sent_col = $this->object->_lookupAnyExerciseSent($this->object->getId());
825 
826  // SET FORMAACTION
827  $this->tpl->setCurrentBlock("tbl_form_header");
828 
829  $this->tpl->setVariable("FORMACTION", $this->ctrl->getLinkTarget($this, "updateMembers"));
830  $this->tpl->parseCurrentBlock();
831 
832  // SET FOOTER BUTTONS
833  $this->tpl->setCurrentBlock("tbl_action_row");
834 
835  $this->tpl->setVariable("COLUMN_COUNTS",6);
836  $this->tpl->setVariable("IMG_ARROW", ilUtil::getImagePath("arrow_downright.gif"));
837 
838  $actions = array("save_status" => $this->lng->txt("exc_save_changes"),
839  "redirectFeedbackMail" => $this->lng->txt("exc_send_mail"),
840  "send_member" => $this->lng->txt("exc_send_exercise"),
841  "delete_member" => $this->lng->txt("exc_deassign_members"));
842 
843  $this->tpl->setCurrentBlock("tbl_action_select");
844  $this->tpl->setVariable("SELECT_ACTION",ilUtil::formSelect(1,"action",$actions,false,true));
845  $this->tpl->setVariable("BTN_NAME","execute");
846  $this->tpl->setVariable("BTN_VALUE",$this->lng->txt("execute"));
847  $this->tpl->parseCurrentBlock();
848 
849  $this->tpl->setCurrentBlock("tbl_action_row");
850  $this->tpl->setVariable("COLUMN_COUNTS",10);
851  $this->tpl->setVariable("TPLPATH",$this->tpl->tplPath);
852  $this->tpl->parseCurrentBlock();
853 
854  // title & header columns
855  if ($sent_col)
856  {
857  $sent_str = $this->lng->txt("exc_exercise_sent");
858  }
859  else
860  {
861  $sent_str = "&nbsp;";
862  }
863  $tbl->setTitle($this->lng->txt("members"),"icon_usr.gif",
864  $this->lng->txt("exc_header_members"));
865  $tbl->setHeaderNames(array("", "", $this->lng->txt("name"),
866  $this->lng->txt("login"),
867  $sent_str,
868  $this->lng->txt("exc_submission"),
869  $this->lng->txt("exc_grading"),
870  $this->lng->txt("mail")
871  ));
872 
873  $tbl->setColumnWidth(array("1%", "1%", "", "", "", "", "", ""));
874  $cols = array("", "", "name", "login", "sent_time", "submission",
875  "status_time", "feedback_time");
876 
877  if (!$_GET["sort_by"])
878  {
879  $_GET["sort_by"] = "name";
880  }
881  if (!$_GET["sort_order"])
882  {
883  $_GET["sort_order"] = "asc";
884  }
885 
886  $header_params = $this->ctrl->getParameterArray($this);
887  unset($header_params["sort_by"]);
888  unset($header_params["sort_order"]);
889  unset($header_params["offset"]);
890  $header_params["cmd"] = "members";
891  $tbl->setHeaderVars($cols, $header_params);
892  $members = ilUtil::sortArray($members, $_GET["sort_by"], $_GET["sort_order"]);
893  $tbl->setOrderColumn($_GET["sort_by"]);
894  $tbl->setOrderDirection($_GET["sort_order"]);
895  $tbl->setOffset($_GET["offset"]);
896  $tbl->setLimit($_GET["limit"]);
897  $tbl->setMaxCount(count($members));
898  $tbl->setFooter("tblfooter",$this->lng->txt("previous"),$this->lng->txt("next"));
899  $members = array_slice($members, $_GET["offset"], $_GET["limit"]);
900  $tbl->render();
901 
902 
903  // new table
904  foreach ($members as $member)
905  {
906  include_once "./classes/class.ilObjectFactory.php";
907 
908  $member_id = $member["usr_id"];
909  if(!($mem_obj = ilObjectFactory::getInstanceByObjId($member_id,false)))
910  {
911  continue;
912  }
913 
914  // checkbox
915  $this->tpl->setCurrentBlock("member_row");
916  $this->tpl->setVariable("ROW_CSS",
917  ilUtil::switchColor($counter++,"tblrow1","tblrow2"));
918  $this->tpl->setVariable("VAL_CHKBOX",
919  ilUtil::formCheckbox(0,"member[$member_id]",1));
920  $this->tpl->setVariable("VAL_ID",
921  $member_id);
922 
923  // name and login
924  $this->tpl->setVariable("TXT_NAME",
925  $member["name"]);
926  $this->tpl->setVariable("TXT_LOGIN",
927  "[".$member["login"]."]");
928 
929  // image
930  $this->tpl->setVariable("USR_IMAGE",
931  $mem_obj->getPersonalPicturePath("xxsmall"));
932  $this->tpl->setVariable("USR_ALT", $this->lng->txt("personal_picture"));
933 
934  // mail sent
935  if ($this->object->members_obj->getStatusSentByMember($member_id))
936  {
937  if (($st = ilObjExercise::_lookupSentTime($this->object->getId(),
938  $member_id)) > 0)
939  {
940  $this->tpl->setVariable("TXT_MAIL_SENT",
941  sprintf($this->lng->txt("exc_sent_at"),
943  }
944  else
945  {
946  $this->tpl->setVariable("TXT_MAIL_SENT",
947  $this->lng->txt("sent"));
948  }
949  }
950 
951  // submission:
952  // see if files have been resubmmited after solved
953  $last_sub =
954  $this->object->getLastSubmission($member_id);
955 
956  if ($last_sub)
957  {
958  $last_sub = ilDatePresentation::formatDate(new ilDateTime($last_sub,IL_CAL_DATETIME));
959  }
960  else
961  {
962  $last_sub = "---";
963  }
964  if ($this->object->_lookupUpdatedSubmission($this->object->getId(), $member_id) == 1)
965  {
966  $last_sub = "<b>".$last_sub."</b>";
967  }
968  $this->tpl->setVariable("VAL_LAST_SUBMISSION", $last_sub);
969  $this->tpl->setVariable("TXT_LAST_SUBMISSION",
970  $this->lng->txt("exc_last_submission"));
971 
972  // nr of submitted files
973  $this->tpl->setVariable("TXT_SUBMITTED_FILES",
974  $this->lng->txt("exc_files_returned"));
975  $sub_cnt = count($this->object->getDeliveredFiles($member_id));
976  $new = $this->object->_lookupNewFiles($this->object->getId(), $member_id);
977  if (count($new) > 0)
978  {
979  $sub_cnt.= " ".sprintf($this->lng->txt("cnt_new"),count($new));
980  }
981  $this->tpl->setVariable("VAL_SUBMITTED_FILES",
982  $sub_cnt);
983 
984  // download command
985  $this->ctrl->setParameter($this, "member_id", $member_id);
986  if ($sub_cnt > 0)
987  {
988  $this->tpl->setCurrentBlock("download_link");
989  $this->tpl->setVariable("LINK_DOWNLOAD",
990  $this->ctrl->getLinkTarget($this, "downloadReturned"));
991  if (count($new) <= 0)
992  {
993  $this->tpl->setVariable("TXT_DOWNLOAD",
994  $this->lng->txt("exc_download_files"));
995  }
996  else
997  {
998  $this->tpl->setVariable("TXT_DOWNLOAD",
999  $this->lng->txt("exc_download_all"));
1000  }
1001  $this->tpl->parseCurrentBlock();
1002 
1003  // download new files only
1004  if (count($new) > 0)
1005  {
1006  $this->tpl->setCurrentBlock("download_link");
1007  $this->tpl->setVariable("LINK_NEW_DOWNLOAD",
1008  $this->ctrl->getLinkTarget($this, "downloadNewReturned"));
1009  $this->tpl->setVariable("TXT_NEW_DOWNLOAD",
1010  $this->lng->txt("exc_download_new"));
1011  $this->tpl->parseCurrentBlock();
1012  }
1013 
1014  $this->tpl->setCurrentBlock("member_row");
1015  }
1016 
1017  // note
1018  $this->tpl->setVariable("TXT_NOTE", $this->lng->txt("note"));
1019  $this->tpl->setVariable("NAME_NOTE",
1020  "notice[$member_id]");
1021  $this->tpl->setVariable("VAL_NOTE",
1022  ilUtil::prepareFormOutput($this->object->members_obj->getNoticeByMember($member_id)));
1023 
1024  // comment for learner
1025  $this->tpl->setVariable("TXT_LCOMMENT", $this->lng->txt("exc_comment_for_learner"));
1026  $this->tpl->setVariable("NAME_LCOMMENT",
1027  "lcomment[$member_id]");
1028  $lpcomment = ilLPMarks::_lookupComment($member_id,$this->object->getId());
1029  $this->tpl->setVariable("VAL_LCOMMENT",
1030  ilUtil::prepareFormOutput($lpcomment));
1031 
1032  // solved
1033  //$this->tpl->setVariable("CHKBOX_SOLVED",
1034  // ilUtil::formCheckbox($this->object->members_obj->getStatusByMember($member_id),"solved[$member_id]",1));
1035  $status = ilExerciseMembers::_lookupStatus($this->object->getId(), $member_id);
1036  $this->tpl->setVariable("SEL_".strtoupper($status), ' selected="selected" ');
1037  $this->tpl->setVariable("TXT_NOTGRADED", $this->lng->txt("exc_notgraded"));
1038  $this->tpl->setVariable("TXT_PASSED", $this->lng->txt("exc_passed"));
1039  $this->tpl->setVariable("TXT_FAILED", $this->lng->txt("exc_failed"));
1040  if (($sd = ilObjExercise::_lookupStatusTime($this->object->getId(), $member_id)) > 0)
1041  {
1042  $this->tpl->setCurrentBlock("status_date");
1043  $this->tpl->setVariable("TXT_LAST_CHANGE", $this->lng->txt("last_change"));
1044  $this->tpl->setVariable('VAL_STATUS_DATE',
1046  $this->tpl->parseCurrentBlock();
1047  $this->tpl->setCurrentBlock("member_row");
1048  }
1049  switch($status)
1050  {
1051  case "passed": $pic = "scorm/passed.gif"; break;
1052  case "failed": $pic = "scorm/failed.gif"; break;
1053  default: $pic = "scorm/not_attempted.gif"; break;
1054  }
1055  $this->tpl->setVariable("IMG_STATUS", ilUtil::getImagePath($pic));
1056  $this->tpl->setVariable("ALT_STATUS", $this->lng->txt("exc_".$status));
1057 
1058  // mark
1059  $this->tpl->setVariable("TXT_MARK", $this->lng->txt("exc_mark"));
1060  $this->tpl->setVariable("NAME_MARK",
1061  "mark[$member_id]");
1062  $mark = ilLPMarks::_lookupMark($member_id,$this->object->getId());
1063  $this->tpl->setVariable("VAL_MARK",
1064  ilUtil::prepareFormOutput($mark));
1065 
1066  // feedback
1067  $this->ctrl->setParameter($this, "member_id", $member_id);
1068  $this->tpl->setVariable("CHKBOX_FEEDBACK",
1069  ilUtil::formCheckbox($this->object->members_obj->getStatusFeedbackByMember($member_id),"feedback[$member_id]",1));
1070  if (($ft = ilObjExercise::_lookupFeedbackTime($this->object->getId(), $member_id)) > 0)
1071  {
1072  $this->tpl->setCurrentBlock("feedback_date");
1073  $this->tpl->setVariable("TXT_FEEDBACK_MAIL_SENT",
1074  sprintf($this->lng->txt("exc_sent_at"),
1076  $this->tpl->parseCurrentBlock();
1077  $this->tpl->setCurrentBlock("member_row");
1078  }
1079  $this->ctrl->setParameter($this, "rcp_to", $mem_obj->getLogin());
1080  $this->tpl->setVariable("LINK_FEEDBACK",
1081  $this->ctrl->getLinkTarget($this, "redirectFeedbackMail"));
1082  //"ilias.php?baseClass=ilMailGUI&type=new&rcp_to=".$mem_obj->getLogin());
1083  $this->tpl->setVariable("TXT_FEEDBACK",
1084  $this->lng->txt("exc_send_mail"));
1085  $this->ctrl->setParameter($this, "rcp_to", "");
1086 
1087  $this->tpl->parseCurrentBlock();
1088  }
1089 // $this->tpl->setCurrentBlock("tbl_content");
1090 // $this->tpl->parseCurrentBlock();
1091 
1092 
1093  //$this->__showMembersTableContent($this->__showMembersTable($f_result,$member_ids));
1094 
1095  if(count($this->object->members_obj->getAllDeliveredFiles()))
1096  {
1097  $this->tpl->addBlockFile("SPECIAL_BUTTONS", "special_buttons", "tpl.exc_download_all.html",
1098  "Modules/Exercise");
1099  $this->tpl->setCurrentBlock("download_all");
1100  $this->tpl->setVariable("BUTTON_DOWNLOAD_ALL", $this->lng->txt("download_all_returned_files"));
1101  $this->tpl->setVariable("FORMACTION",
1102  $this->ctrl->getLinkTarget($this, "downloadAll"));
1103  $this->tpl->parseCurrentBlock();
1104  }
1105  }
1106  }
1107 
1112  {
1113  $this->checkPermission("write");
1114 
1115  if ($_GET["member_id"] != "")
1116  {
1117  $this->object->members_obj->setStatusFeedbackForMember($_GET["member_id"], 1);
1118  ilUtil::redirect("ilias.php?baseClass=ilMailGUI&type=new&rcp_to=".urlencode($_GET["rcp_to"]));
1119  }
1120  else if(count($_POST["member"]) > 0)
1121  {
1122  include_once('./Services/User/classes/class.ilObjUser.php');
1123  $logins = array();
1124  foreach($_POST["member"] as $member => $val)
1125  {
1126  $logins[] = ilObjUser::_lookupLogin($member);
1127  $this->object->members_obj->setStatusFeedbackForMember($member, 1);
1128  }
1129  $logins = implode($logins, ",");
1130  ilUtil::redirect("ilias.php?baseClass=ilMailGUI&type=new&rcp_to=".$logins);
1131  }
1132 
1133  ilUtil::sendInfo($this->lng->txt("select_one"),true);
1134  $this->ctrl->redirect($this, "members");
1135  }
1136 
1141  {
1142  $this->checkPermission("write");
1143 
1144  $members = array();
1145 
1146  foreach($this->object->members_obj->getMembers() as $member_id)
1147  {
1148  // update download time
1149  $this->object->members_obj->updateTutorDownloadTime($member_id);
1150 
1151  // get member object (ilObjUser)
1152  if (ilObject::_exists($member_id))
1153  {
1154  $tmp_obj =& ilObjectFactory::getInstanceByObjId($member_id);
1155  $members[$member_id] = $tmp_obj->getFirstname() . " " . $tmp_obj->getLastname();
1156  unset($tmp_obj);
1157  }
1158  }
1159 
1160  $this->object->file_obj->downloadAllDeliveredFiles($members);
1161  }
1162 
1163  function newMembersObject()
1164  {
1165  global $rbacsystem;
1166 
1167  $this->checkPermission("write");
1168 
1169  // SEARCH CANCELED
1170  if(isset($_POST["cancel"]))
1171  {
1172  $this->ctrl->redirect($this, "members");
1173  }
1174 
1175  if(isset($_POST["select"]))
1176  {
1177  if(is_array($_POST["id"]))
1178  {
1179  if(!$this->object->members_obj->assignMembers($_POST["id"]))
1180  {
1181  ilUtil::sendInfo($this->lng->txt("exc_members_already_assigned"),true);
1182  }
1183  else
1184  {
1185  ilUtil::sendInfo($this->lng->txt("exc_members_assigned"),true);
1186  }
1187  $this->ctrl->redirect($this, "members");
1188  }
1189  }
1190  $show_search = true;
1191 
1192  $this->getTemplateFile("add_member","exc");
1193  $this->tpl->setVariable("F_ACTION",$this->ctrl->getLinkTarget($this, "newMembers"));
1194 
1195  if($_POST["search_str"])
1196  {
1197  $result = $this->__searchMembers(ilUtil::stripSlashes($_POST["search_str"]),$_POST["search_for"]);
1198 
1199  switch(count($result))
1200  {
1201  case 0:
1202  // SHOW ERROR MESSAGE
1203  ilUtil::sendInfo($this->lng->txt("cont_no_object_found"));
1204  break;
1205 
1206  case 1:
1207  $result = $this->__getMembersOfObject($result,$_POST["search_for"]);
1208  $this->__showMembersSelect($result);
1209  $show_search = false;
1210  break;
1211 
1212  default:
1213  if($_POST["search_for"] == 'usr')
1214  {
1215  $this->__showMembersSelect($result);
1216  }
1217  else
1218  {
1219  $this->__showObjectSelect($result,$_POST["search_for"]);
1220  }
1221  $show_search = false;
1222  break;
1223  }
1224  }
1225  if($_POST["obj_select"])
1226  {
1227  if(count($_POST["obj"]))
1228  {
1229  $result = $this->__getMembersOfObject($_POST["obj"],"grp");
1230  $this->__showMembersSelect($result);
1231  $show_search = false;
1232  }
1233  }
1234 
1235 
1236  if($show_search)
1237  {
1238  $this->lng->loadLanguageModule("content");
1239  $this->lng->loadLanguageModule("search");
1240 
1241  $search_for = array("usr" => $this->lng->txt("exc_users"),
1242  "grp" => $this->lng->txt("exc_groups"));
1243  #"role" => $this->lng->txt("!!Rollen"));
1244 
1245  $counter = 0;
1246  foreach($search_for as $key => $value)
1247  {
1248  $this->tpl->setCurrentBlock("USR_SEARCH_ROW");
1249  $this->tpl->setVariable("SEARCH_ROW_CHECK",
1250  ilUtil::formRadioButton(++$counter == 1 ? 1 : 0,"search_for",$key));
1251  $this->tpl->setVariable("SEARCH_ROW_TXT",$value);
1252  $this->tpl->parseCurrentBlock();
1253  }
1254  $this->tpl->setVariable("SEARCH_ASSIGN_USR",$this->lng->txt("add_member"));
1255  $this->tpl->setVariable("SEARCH_SEARCH_TERM",$this->lng->txt("search_search_term"));
1256  $this->tpl->setVariable("SEARCH_FOR",$this->lng->txt("exc_search_for"));
1257  $this->tpl->setVariable("BTN1_VALUE",$this->lng->txt("search"));
1258  $this->tpl->setVariable("BTN2_VALUE",$this->lng->txt("cancel"));
1259  }
1260  }
1261 
1262  function __getMembersOfObject($a_result,$a_type)
1263  {
1264 
1265  switch($a_type)
1266  {
1267  case "usr":
1268  return $a_result;
1269  case "grp":
1270  include_once "./Modules/Group/classes/class.ilObjGroup.php";
1271 
1272  $all_members = array();
1273  foreach($a_result as $group)
1274  {
1275  $tmp_grp_obj = ilObjectFactory::getInstanceByRefId($group["id"]);
1276 
1277  $members = $tmp_grp_obj->getGroupMemberIds();
1278  $all_members = array_merge($all_members,$members);
1279  }
1280  // FORMAT ARRAY
1281  $all_members = array_unique($all_members);
1282  foreach($all_members as $member)
1283  {
1284  $result[] = array("id" => $member);
1285  }
1286  return $result;
1287  }
1288  return true;
1289  }
1290 
1291  function __showObjectSelect($a_result,$a_type)
1292  {
1293  include_once "./classes/class.ilObjectFactory.php";
1294 
1295  foreach($a_result as $obj)
1296  {
1297  $tmp_obj =& ilObjectFactory::getInstanceByRefId($obj["id"]);
1298  $this->tpl->setCurrentBlock("OBJ_SELECT_ROW");
1299  $this->tpl->setVariable("OBJ_ROW_TITLE",$tmp_obj->getTitle());
1300  $this->tpl->setVariable("OBJ_ROW_ID",$tmp_obj->getRefId());
1301  $this->tpl->setVariable("OBJ_ROW_DESCRIPTION",$tmp_obj->getDescription());
1302  $this->tpl->parseCurrentBlock();
1303 
1304  unset($tmp_obj);
1305  }
1306  $this->tpl->setCurrentBlock("OBJ_SELECT");
1307  $this->tpl->setVariable("OBJ_SELECT_TITLE",$this->lng->txt("title"));
1308  $this->tpl->setVariable("OBJ_SELECT_DESCRIPTION",$this->lng->txt("description"));
1309 
1310  $this->tpl->setVariable("OBJ_BTN1_VALUE",$this->lng->txt("select"));
1311  $this->tpl->setVariable("OBJ_BTN2_VALUE",$this->lng->txt("cancel"));
1312  $this->tpl->parseCurrentBlock();
1313  }
1314 
1315  function __showMembersSelect($a_result)
1316  {
1317  include_once "./classes/class.ilObjectFactory.php";
1318  include_once "./Services/Utilities/classes/class.ilUtil.php";
1319 
1320  $ids = array();
1321  foreach($a_result as $user)
1322  {
1323  array_push($ids, $user["id"]);
1324 
1325  $tmp_obj =& ilObjectFactory::getInstanceByObjId($user["id"]);
1326 
1327  $this->tpl->setCurrentBlock("USR_SELECT_ROW");
1328  $this->tpl->setVariable("ROW_LOGIN",$tmp_obj->getLogin());
1329  $this->tpl->setVariable("NAME_ID","id_".$tmp_obj->getId());
1330  $this->tpl->setVariable("ROW_ID",$tmp_obj->getId());
1331  $this->tpl->setVariable("ROW_FIRSTNAME",$tmp_obj->getFirstname());
1332  $this->tpl->setVariable("ROW_LASTNAME",$tmp_obj->getLastname());
1333  $this->tpl->parseCurrentBlock();
1334 
1335  unset($tmp_obj);
1336  }
1337 
1338  $this->tpl->setCurrentBlock("USR_SELECT");
1339  $this->tpl->setVariable("SELECT_LOGIN",$this->lng->txt("login"));
1340  $this->tpl->setVariable("SELECT_FIRSTNAME",$this->lng->txt("firstname"));
1341  $this->tpl->setVariable("SELECT_LASTNAME",$this->lng->txt("lastname"));
1342 
1343  $this->tpl->setVariable("BTN1_VALUE",$this->lng->txt("assign"));
1344  $this->tpl->setVariable("BTN2_VALUE",$this->lng->txt("cancel"));
1345  $this->tpl->setVariable("JS_VARNAME","id");
1346  $this->tpl->setVariable("JS_ONCLICK",ilUtil::array_php2js($ids));
1347  $this->tpl->setVariable("TXT_CHECKALL",$this->lng->txt("check_all"));
1348  $this->tpl->setVariable("TXT_UNCHECKALL",$this->lng->txt("uncheck_all"));
1349 
1350  $this->tpl->parseCurrentBlock();
1351  }
1352  function __searchMembers($a_search_str,$a_search_for)
1353  {
1354  include_once("./classes/class.ilSearch.php");
1355 
1356  $this->lng->loadLanguageModule("content");
1357 
1358  $search =& new ilSearch($_SESSION["AccountId"]);
1359  $search->setPerformUpdate(false);
1360  $search->setSearchString(ilUtil::stripSlashes($_POST["search_str"]));
1361  $search->setCombination("and");
1362  $search->setSearchFor(array(0 => $a_search_for));
1363  $search->setSearchType('new');
1364 
1365  $message = '';
1366  if($search->validate($message))
1367  {
1368  $search->performSearch();
1369  }
1370  else
1371  {
1372  ilUtil::sendInfo($message,true);
1373  $this->ctrl->redirect($this, "newMembers");
1374  }
1375  return $search->getResultByType($a_search_for);
1376  }
1377 
1379  {
1380  if(is_array($_POST["member"]))
1381  {
1382  foreach($_POST["member"] as $usr_id => $member)
1383  {
1384  $this->object->members_obj->deassignMember($usr_id);
1385  }
1386  return true;
1387  }
1388  else
1389  {
1390  ilUtil::sendInfo($this->lng->txt("select_one"),true);
1391  return false;
1392  }
1393  }
1394 
1396  {
1397  $this->checkPermission("write");
1398 
1399  if(!isset($_POST['comments_value']))
1400  {
1401  continue;
1402  }
1403 
1404  $this->object->members_obj->setNoticeForMember($_GET["member_id"],
1405  ilUtil::stripSlashes($_POST["comments_value"]));
1406  ilUtil::sendInfo($this->lng->txt("exc_members_comments_saved"));
1407  $this->membersObject();
1408  }
1409 
1410  function getComments($member_id)
1411  {
1412  return $this->object->members_obj->getNoticeByMember($member_id);
1413  }
1414 
1415  function __saveStatus()
1416  {
1417  $this->checkPermission("write");
1418 
1419  include_once 'Services/Tracking/classes/class.ilLPMarks.php';
1420 
1421 //var_dump($_POST["member"]);
1422 //var_dump($_POST["id"]);
1423 
1424  $saved_for = array();
1425 
1426  foreach($_POST["id"] as $key => $value)
1427  {
1428  if (count($_POST["member"]) > 0 && $_POST["member"][$key] != "1")
1429  {
1430  continue;
1431  }
1432  else
1433  {
1434  if (count($_POST["member"]) > 0)
1435  {
1436  $uname = ilObjUser::_lookupName($key);
1437  $saved_for[] = $uname["lastname"].", ".$uname["firstname"];
1438  }
1439  }
1440 
1441  $this->object->members_obj->setStatusForMember($key, $_POST["status"][$key]);
1442  //$this->object->members_obj->setStatusFeedbackForMember($key, $_POST["feedback"][$key] ? 1 : 0);
1443  $this->object->members_obj->setNoticeForMember($key,ilUtil::stripSlashes($_POST["notice"][$key]));
1444 
1445  if (ilUtil::stripSlashes($_POST['mark'][$key]) !=
1446  ilLPMarks::_lookupMark($key, $this->object->getId()))
1447  {
1448  $this->object->members_obj->updateStatusTimeForMember($key);
1449  }
1450 
1451  // save mark and comment
1452  $marks_obj = new ilLPMarks($this->object->getId(),$key);
1453  $marks_obj->setMark(ilUtil::stripSlashes($_POST['mark'][$key]));
1454  $marks_obj->setComment(ilUtil::stripSlashes($_POST['lcomment'][$key]));
1455  $marks_obj->update();
1456  }
1457  if (count($saved_for) > 0)
1458  {
1459  $save_for_str = "(".implode($saved_for, " - ").")";
1460  }
1461  ilUtil::sendInfo($this->lng->txt("exc_status_saved")." ".$save_for_str,true);
1462  return true;
1463  }
1464 
1465  function __getDateSelect($a_type,$a_selected)
1466  {
1467  switch($a_type)
1468  {
1469  case "hour":
1470  for($i=0; $i<24; $i++)
1471  {
1472  $hours[$i] = $i < 10 ? "0".$i : $i;
1473  }
1474  return ilUtil::formSelect($a_selected,"d_hour",$hours,false,true);
1475 
1476  case "minutes":
1477  for($i=0;$i<60;$i++)
1478  {
1479  $minutes[$i] = $i < 10 ? "0".$i : $i;
1480  }
1481  return ilUtil::formSelect($a_selected,"d_minutes",$minutes,false,true);
1482 
1483  case "day":
1484  for($i=1; $i<32; $i++)
1485  {
1486  $days[$i] = $i < 10 ? "0".$i : $i;
1487  }
1488  return ilUtil::formSelect($a_selected,"d_day",$days,false,true);
1489 
1490  case "month":
1491  for($i=1; $i<13; $i++)
1492  {
1493  $month[$i] = $i < 10 ? "0".$i : $i;
1494  }
1495  return ilUtil::formSelect($a_selected,"d_month",$month,false,true);
1496 
1497  case "year":
1498  for($i = date("Y",time());$i < date("Y",time()) + 3;++$i)
1499  {
1500  $year[$i] = $i;
1501  }
1502  return ilUtil::formSelect($a_selected,"d_year",$year,false,true);
1503  }
1504  }
1505 
1506  function __filterAssignedUsers($a_result)
1507  {
1508  foreach($a_result as $user)
1509  {
1510  if(!$this->object->members_obj->isAssigned($user["id"]))
1511  {
1512  $filtered[] = $user;
1513  }
1514  }
1515 
1516  return $filtered ? $filtered : array();
1517  }
1518 
1524  function getTabs(&$tabs_gui)
1525  {
1526  global $ilAccess,$ilUser;
1527 
1528  $next_class = strtolower($this->ctrl->getNextClass());
1529  if ($ilAccess->checkAccess("visible", "", $this->object->getRefId()))
1530  {
1531  $force_active = ($next_class == "ilinfoscreengui")
1532  ? true
1533  : false;
1534  $tabs_gui->addTarget("info_short",
1535  $this->ctrl->getLinkTargetByClass("ilinfoscreengui", "showSummary"),
1536  "showSummary",
1537  "ilinfoscreengui", "", $force_active);
1538  }
1539 
1540  /*
1541  $tabs_gui->addTarget("view",
1542  $this->ctrl->getLinkTarget($this, 'view'),
1543  array("view",""), "");*/
1544 
1545  if ($ilAccess->checkAccess("read", "", $this->object->getRefId()))
1546  {
1547  $tabs_gui->addTarget("exc_your_submission",
1548  $this->ctrl->getLinkTarget($this, "deliver"),
1549  "deliver", "");
1550  }
1551 
1552  // edit properties
1553  if ($ilAccess->checkAccess("write", "", $this->ref_id))
1554  {
1555  $tabs_gui->addTarget("edit_properties",
1556  $this->ctrl->getLinkTarget($this, 'edit'),
1557  "edit", "");
1558 
1559  $tabs_gui->addTarget("members",
1560  $this->ctrl->getLinkTarget($this, 'members'),
1561  array("members", "newMembers", "newmembers"), "");
1562  }
1563 
1564  // learning progress
1565  $save_sort_order = $_GET["sort_order"]; // hack, because exercise sort parameters
1566  $save_sort_by = $_GET["sort_by"]; // must not be forwarded to learning progress
1567  $save_offset = $_GET["offset"];
1568  $_GET["offset"] = $_GET["sort_by"] = $_GET["sort_order"] = "";
1569 
1570  include_once './Services/Tracking/classes/class.ilLearningProgressAccess.php';
1571  if(ilLearningProgressAccess::checkAccess($this->object->getRefId()))
1572  {
1573  $tabs_gui->addTarget('learning_progress',
1574  $this->ctrl->getLinkTargetByClass(array('ilobjexercisegui','illearningprogressgui'),''),
1575  '',
1576  array('illplistofobjectsgui','illplistofsettingsgui','illearningprogressgui','illplistofprogressgui'));
1577  }
1578 
1579  $_GET["sort_order"] = $save_sort_order; // hack, part ii
1580  $_GET["sort_by"] = $save_sort_by;
1581  $_GET["offset"] = $save_offset;
1582 
1583  // permissions
1584  if ($ilAccess->checkAccess("edit_permission", "", $this->ref_id))
1585  {
1586  $tabs_gui->addTarget("perm_settings",
1587  $this->ctrl->getLinkTargetByClass(array(get_class($this),'ilpermissiongui'), "perm"),
1588  array("perm","info","owner"), 'ilpermissiongui');
1589  }
1590  }
1591 
1592  function &executeCommand()
1593  {
1594  global $ilUser;
1595 
1596  $next_class = $this->ctrl->getNextClass($this);
1597  $cmd = $this->ctrl->getCmd();
1598  $this->prepareOutput();
1599 
1600 //echo "-".$next_class."-".$cmd."-"; exit;
1601  switch($next_class)
1602  {
1603  case "ilinfoscreengui":
1604  $this->infoScreen(); // forwards command
1605  break;
1606 
1607  case 'ilpermissiongui':
1608  include_once("./classes/class.ilPermissionGUI.php");
1609  $perm_gui =& new ilPermissionGUI($this);
1610  $ret =& $this->ctrl->forwardCommand($perm_gui);
1611  break;
1612 
1613  case "illearningprogressgui":
1614  include_once './Services/Tracking/classes/class.ilLearningProgressGUI.php';
1615 
1616  $new_gui =& new ilLearningProgressGUI(LP_MODE_REPOSITORY,
1617  $this->object->getRefId(),
1618  $_GET['user_id'] ? $_GET['user_id'] : $ilUser->getId());
1619  $this->ctrl->forwardCommand($new_gui);
1620  $this->tabs_gui->setTabActive('learning_progress');
1621  break;
1622 
1623  case 'ilrepositorysearchgui':
1624  include_once('./Services/Search/classes/class.ilRepositorySearchGUI.php');
1625  $rep_search =& new ilRepositorySearchGUI();
1626  $rep_search->setCallback($this,'addMembersObject');
1627 
1628  // Set tabs
1629  $this->tabs_gui->setTabActive('members');
1630  $this->ctrl->setReturn($this,'members');
1631  $ret =& $this->ctrl->forwardCommand($rep_search);
1632  #$this->__setSubTabs('members');
1633  #$this->tabs_gui->setSubTabActive('members');
1634  break;
1635 
1636 
1637  default:
1638  if(!$cmd)
1639  {
1640  $cmd = "infoScreen";
1641  }
1642 
1643  $cmd .= "Object";
1644 
1645  $this->$cmd();
1646 
1647  break;
1648  }
1649 
1650  return true;
1651  }
1652 
1658  function infoScreenObject()
1659  {
1660  $this->ctrl->setCmd("showSummary");
1661  $this->ctrl->setCmdClass("ilinfoscreengui");
1662  $this->infoScreen();
1663  }
1664 
1668  function infoScreen()
1669  {
1670  global $ilAccess, $ilUser;
1671 
1672  $this->checkPermission("visible");
1673 
1674  include_once("./Services/InfoScreen/classes/class.ilInfoScreenGUI.php");
1675  $info = new ilInfoScreenGUI($this);
1676 
1677  $info->enablePrivateNotes();
1678 
1679  $info->enableNews();
1680  if ($ilAccess->checkAccess("write", "", $_GET["ref_id"]))
1681  {
1682  $info->enableNewsEditing();
1683  $info->setBlockProperty("news", "settings", true);
1684  }
1685 
1686  // standard meta data
1687  //$info->addMetaDataSections($this->object->getId(),0, $this->object->getType());
1688 
1689  // instructions
1690  $info->addSection($this->lng->txt("exc_instruction"));
1691  $info->addProperty("",
1692  nl2br($this->object->getInstruction()));
1693 
1694  // schedule
1695  $info->addSection($this->lng->txt("exc_schedule"));
1696  $info->addProperty($this->lng->txt("exc_edit_until"),
1697  ilDatePresentation::formatDate(new ilDateTime($this->object->getTimestamp(),IL_CAL_UNIX)));
1698 
1699  if ($this->object->getTimestamp()-time() <= 0)
1700  {
1701  $time_str = $this->lng->txt("exc_time_over_short");
1702  }
1703  else
1704  {
1705  $time_diff = ilUtil::int2array($this->object->getTimestamp()-time(),null);
1706  // BEGIN Usability: Never display seconds
1707  unset($time_diff['seconds']);
1708  // END Usability: Never display seconds
1709  // BEGIN Usability: Don't display minutes, if it takes days
1710  if (isset($time_diff['days']))
1711  {
1712  unset($time_diff['minutes']);
1713  }
1714  // END Usability: Don't display minutes, if it takes days
1715  // BEGIN Usability: Don't display hours, if it takes months
1716  if (isset($time_diff['months']))
1717  {
1718  unset($time_diff['hours']);
1719  }
1720  // END Usability: Don't display minutes, if it takes months
1721  $time_str = ilUtil::timearray2string($time_diff);
1722  }
1723  $info->addProperty($this->lng->txt("exc_time_to_send"),
1724  "<b>".$time_str."</b>");
1725 
1726  // download files
1727  if ($ilAccess->checkAccess("read", "", $this->ref_id))
1728  {
1729  $files = $this->object->getFiles();
1730  if (count($files) > 0)
1731  {
1732  $info->addSection($this->lng->txt("exc_files"));
1733  foreach($files as $file)
1734  {
1735  $this->ctrl->setParameter($this, "file", urlencode($file["name"]));
1736  $info->addProperty($file["name"],
1737  $this->lng->txt("download"),
1738  $this->ctrl->getLinkTarget($this, "downloadFile"));
1739  $this->ctrl->setParameter($this, "file", "");
1740  }
1741  }
1742  }
1743 
1744  // submission and feedback info only if read permission given
1745  if ($ilAccess->checkAccess("read", "", $this->ref_id))
1746  {
1747  // submission
1748  $info->addSection($this->lng->txt("exc_your_submission"));
1749  $delivered_files = $this->object->getDeliveredFiles($ilUser->id);
1750  $titles = array();
1751  foreach($delivered_files as $file)
1752  {
1753  $titles[] = $file["filetitle"];
1754  }
1755  $files_str = implode($titles, ", ");
1756  if ($files_str == "")
1757  {
1758  $files_str = $this->lng->txt("message_no_delivered_files");
1759  }
1760  $info->addProperty($this->lng->txt("exc_files_returned"),
1761  $files_str);
1762  $last_sub = $this->object->getLastSubmission($ilUser->getId());
1763  if ($last_sub)
1764  {
1765  $last_sub = ilDatePresentation::formatDate(new ilDateTime($last_sub,IL_CAL_DATETIME));
1766  }
1767  else
1768  {
1769  $last_sub = "---";
1770  }
1771 
1772  $info->addProperty($this->lng->txt("exc_last_submission"),
1773  $last_sub);
1774 
1775  // feedback from tutor
1776  include_once("Services/Tracking/classes/class.ilLPMarks.php");
1777  $lpcomment = ilLPMarks::_lookupComment($ilUser->getId(), $this->object->getId());
1778  $mark = ilLPMarks::_lookupMark($ilUser->getId(), $this->object->getId());
1779  $status = ilExerciseMembers::_lookupStatus($this->object->getId(), $ilUser->getId());
1780  if ($lpcomment != "" || $mark != "" || $status != "notgraded")
1781  {
1782  $info->addSection($this->lng->txt("exc_feedback_from_tutor"));
1783  if ($lpcomment != "")
1784  {
1785  $info->addProperty($this->lng->txt("exc_comment"),
1786  $lpcomment);
1787  }
1788  if ($mark != "")
1789  {
1790  $info->addProperty($this->lng->txt("exc_mark"),
1791  $mark);
1792  }
1793 
1794  if ($status == "")
1795  {
1796  $info->addProperty($this->lng->txt("status"),
1797  $this->lng->txt("message_no_delivered_files"));
1798  }
1799  else
1800  if ($status != "notgraded")
1801  {
1802  $info->addProperty($this->lng->txt("status"),
1803  $this->lng->txt("exc_".$status));
1804  }
1805  }
1806  }
1807 
1808  // forward the command
1809  $this->ctrl->forwardCommand($info);
1810  }
1811 
1812 
1818  function _goto($a_target)
1819  {
1820  global $rbacsystem, $ilErr, $lng, $ilAccess;
1821 
1822  if ($ilAccess->checkAccess("visible", "", $a_target))
1823  {
1824  $_GET["ref_id"] = $a_target;
1825  $_GET["cmd"] = "infoScreen";
1826  $_GET["baseClass"] = "ilExerciseHandlerGUI";
1827  include("ilias.php");
1828  exit;
1829  }
1830  else if ($ilAccess->checkAccess("read", "", ROOT_FOLDER_ID))
1831  {
1832  $_GET["cmd"] = "frameset";
1833  $_GET["target"] = "";
1834  $_GET["ref_id"] = ROOT_FOLDER_ID;
1835  ilUtil::sendInfo(sprintf($lng->txt("msg_no_perm_read_item"),
1836  ilObject::_lookupTitle(ilObject::_lookupObjId($a_target))), true);
1837  include("repository.php");
1838  exit;
1839  }
1840 
1841  $ilErr->raiseError($lng->txt("msg_no_perm_read"), $ilErr->FATAL);
1842  }
1843 
1847  function addLocatorItems()
1848  {
1849  global $ilLocator;
1850 
1851  if (is_object($this->object))
1852  {
1853  $ilLocator->addItem($this->object->getTitle(), $this->ctrl->getLinkTarget($this, "infoScreen"), "", $_GET["ref_id"]);
1854  }
1855  }
1856 
1857 } // END class.ilObjExerciseGUI
1858 ?>