ILIAS  Release_4_0_x_branch Revision 61816
 All Data Structures Namespaces Files Functions Variables Groups Pages
class.ilObjSessionGUI.php
Go to the documentation of this file.
1 <?php
2 /* Copyright (c) 1998-2009 ILIAS open source, Extended GPL, see docs/LICENSE */
3 
4 include_once('./classes/class.ilObjectGUI.php');
5 include_once('./Modules/Session/classes/class.ilObjSession.php');
6 include_once('./Modules/Session/classes/class.ilSessionFile.php');
7 include_once './Services/PersonalDesktop/interfaces/interface.ilDesktopItemHandling.php';
8 
20 {
21 
22 
23  public $lng;
24  public $ctrl;
25  public $tpl;
26 
27  protected $course_ref_id = 0;
28  protected $course_obj_id = 0;
29 
30  protected $files = array();
31 
39  public function __construct($a_data, $a_id, $a_call_by_reference, $a_prepare_output = true)
40  {
41  global $ilCtrl, $lng, $tpl;
42 
43  $this->type = "sess";
44  parent::__construct($a_data,$a_id,$a_call_by_reference,$a_prepare_output);
45 
46  $this->lng = $lng;
47  $this->lng->loadLanguageModule("event");
48  $this->lng->loadLanguageModule('crs');
49  $this->lng->loadLanguageModule('trac');
50 
51  $this->tpl = $tpl;
52  $this->ctrl = $ilCtrl;
53  }
54 
55 
62  public function executeCommand()
63  {
64  global $ilUser,$ilCtrl;
65 
66  $next_class = $this->ctrl->getNextClass($this);
67  $cmd = $this->ctrl->getCmd();
68 
69 
70  $this->prepareOutput();
71  switch($next_class)
72  {
73  case "ilinfoscreengui":
74  $this->checkPermission("visible");
75  $this->infoScreen(); // forwards command
76  break;
77 
78  case 'ilpermissiongui':
79  $this->tabs_gui->setTabActive('perm_settings');
80  include_once("Services/AccessControl/classes/class.ilPermissionGUI.php");
81  $perm_gui = new ilPermissionGUI($this);
82  $ret = $this->ctrl->forwardCommand($perm_gui);
83  break;
84 
85  case 'ilcourseitemadministrationgui':
86  include_once 'Modules/Course/classes/class.ilCourseItemAdministrationGUI.php';
87  $this->tabs_gui->clearSubTabs();
88  $this->ctrl->setReturn($this,'info');
89  $item_adm_gui = new ilCourseItemAdministrationGUI($this->object,(int) $_REQUEST['item_id']);
90  $this->ctrl->forwardCommand($item_adm_gui);
91  break;
92 
93  case 'ilobjectcopygui':
94  include_once './Services/Object/classes/class.ilObjectCopyGUI.php';
95  $cp = new ilObjectCopyGUI($this);
96  $cp->setType('sess');
97  $this->ctrl->forwardCommand($cp);
98  break;
99 
100 
101 
102  default:
103  if(!$cmd)
104  {
105  $cmd = "infoScreen";
106  }
107  $cmd .= "Object";
108  if ($cmd != "infoScreenObject")
109  {
110  $this->checkPermission("read");
111  }
112  else
113  {
114  $this->checkPermission("visible");
115  }
116  $this->$cmd();
117 
118  break;
119  }
120  return true;
121  }
122 
126  protected function prepareOutput()
127  {
129 
130  if(!$this->getCreationMode())
131  {
132  $title = strlen($this->object->getTitle()) ? (': '.$this->object->getTitle()) : '';
133 
134  include_once './Modules/Session/classes/class.ilSessionAppointment.php';
135  $this->tpl->setTitle(
136  $this->object->getFirstAppointment()->appointmentToString().$title);
137  }
138  }
139 
147  public function registerObject()
148  {
149  global $ilUser;
150 
151  include_once 'Modules/Session/classes/class.ilEventParticipants.php';
152  ilEventParticipants::_register($ilUser->getId(),$this->object->getId());
153 
154  ilUtil::sendSuccess($this->lng->txt('event_registered'),true);
155  $this->ctrl->returnToParent($this);
156  }
157 
162  public function joinObject()
163  {
164  global $ilUser;
165 
166  $this->checkPermission('read');
167 
168  include_once './Modules/Session/classes/class.ilEventParticipants.php';
169 
170  if(ilEventParticipants::_isRegistered($ilUser->getId(),$this->object->getId()))
171  {
172  $_SESSION['sess_hide_info'] = true;
173  ilEventParticipants::_unregister($ilUser->getId(),$this->object->getId());
174  ilUtil::sendSuccess($this->lng->txt('event_unregistered'),true);
175  }
176  else
177  {
178  ilEventParticipants::_register($ilUser->getId(),$this->object->getId());
179  ilUtil::sendSuccess($this->lng->txt('event_registered'),true);
180  }
181 
182  $this->ctrl->redirect($this,'infoScreen');
183  }
184 
191  public function unregisterObject()
192  {
193  global $ilUser;
194 
195  include_once './Modules/Session/classes/class.ilEventParticipants.php';
196  ilEventParticipants::_unregister($ilUser->getId(),$this->object->getId());
197 
198  ilUtil::sendSuccess($this->lng->txt('event_unregistered'),true);
199  $this->ctrl->returnToParent($this);
200  }
201 
210  public static function _goto($a_target)
211  {
212  global $ilAccess,$ilErr,$lng;
213 
214  if($ilAccess->checkAccess('visible', "", $a_target))
215  {
216  $_GET["cmd"] = "infoScreen";
217  $_GET["ref_id"] = $a_target;
218  include("repository.php");
219  exit;
220  }
221  $ilErr->raiseError($lng->txt("msg_no_perm_read"), $ilErr->FATAL);
222  }
223 
227  public function addToDeskObject()
228  {
229  include_once './Services/PersonalDesktop/classes/class.ilDesktopItemGUI.php';
231  $this->infoScreenObject();
232  }
233 
237  public function removeFromDeskObject()
238  {
239  include_once './Services/PersonalDesktop/classes/class.ilDesktopItemGUI.php';
241  $this->infoScreenObject();
242  }
243 
244 
250  public function infoScreenObject()
251  {
252  $this->ctrl->setCmd("showSummary");
253  $this->ctrl->setCmdClass("ilinfoscreengui");
254  $this->infoScreen();
255  }
256 
260  function modifyItemGUI($a_item_list_gui,$a_item_data, $a_show_path)
261  {
262  global $tree;
263 
264  // if folder is in a course, modify item list gui according to course requirements
265  if ($course_ref_id = $tree->checkForParentType($this->object->getRefId(),'crs'))
266  {
267  include_once("./Modules/Course/classes/class.ilObjCourse.php");
268  include_once("./Modules/Course/classes/class.ilObjCourseGUI.php");
271  $a_item_list_gui,
272  get_class($this),
273  $a_item_data,
274  $a_show_path,
278  $this->object->getRefId());
279  }
280  }
281 
289  public function infoScreen()
290  {
291  global $ilAccess, $ilUser,$ilCtrl,$tree,$ilToolbar;
292 
293  $this->checkPermission('visible');
294  $this->tabs_gui->setTabActive('info_short');
295 
296  $appointment_obj = $this->object->getFirstAppointment();
297 
298  include_once("./Services/InfoScreen/classes/class.ilInfoScreenGUI.php");
299  $info = new ilInfoScreenGUI($this);
300 
301  if($this->object->enabledRegistration())
302  {
303  include_once './Modules/Session/classes/class.ilEventParticipants.php';
304  if(ilEventParticipants::_isRegistered($ilUser->getId(), $this->object->getId()))
305  {
306  $ilToolbar->addFormButton($this->lng->txt('event_unregister'),'join');
307  }
308  else
309  {
310  if(!isset($_SESSION['sess_hide_info']))
311  {
312  ilUtil::sendInfo($this->lng->txt('sess_join_info'));
313  }
314  $ilToolbar->addFormButton($this->lng->txt('join_session'),'join');
315  }
316  $ilToolbar->setFormAction($this->ctrl->getFormAction($this));
317  }
318 
319  // Session information
320  if(strlen($this->object->getLocation()) or strlen($this->object->getDetails()))
321  {
322  $info->addSection($this->lng->txt('event_section_information'));
323  }
324  if(strlen($location = $this->object->getLocation()))
325  {
326  $info->addProperty($this->lng->txt('event_location'),
327  nl2br($this->object->getLocation()));
328  }
329  if(strlen($this->object->getDetails()))
330  {
331  $info->addProperty($this->lng->txt('event_details_workflow'),
332  nl2br($this->object->getDetails()));
333  }
334 
335  // Tutor information
336  if($this->object->hasTutorSettings())
337  {
338  $info->addSection($this->lng->txt('event_tutor_data'));
339  if(strlen($fullname = $this->object->getName()))
340  {
341  $info->addProperty($this->lng->txt('event_lecturer'),
342  $fullname);
343  }
344  if(strlen($email = $this->object->getEmail()))
345  {
346  $info->addProperty($this->lng->txt('tutor_email'),
347  $email);
348  }
349  if(strlen($phone = $this->object->getPhone()))
350  {
351  $info->addProperty($this->lng->txt('tutor_phone'),
352  $phone);
353  }
354  }
355 
356  include_once './Modules/Session/classes/class.ilSessionObjectListGUIFactory.php';
357  include_once './Modules/Session/classes/class.ilEventItems.php';
358  include_once './Modules/Course/classes/class.ilCourseItems.php';
359 
360  $html = '';
361  $eventItems = new ilEventItems($this->object->getId());
362  foreach($eventItems->getItems() as $item_id)
363  {
364  $obj_id = ilObject::_lookupObjId($item_id);
366 
367 
369  $list_gui->setContainerObject($this);
370  $this->modifyItemGUI($list_gui, ilCourseItems::_getItem($item_id),false);
371 
372  $html .= $list_gui->getListItemHTML(
373  $item_id,
374  $obj_id,
377  );
378  }
379 
380  if(strlen($html))
381  {
382  $info->addSection($this->lng->txt('event_materials'));
383  $info->addProperty(
384  '&nbsp;',
385  $html);
386  }
387 
388  // forward the command
389  $this->ctrl->forwardCommand($info);
390 
391  }
392 
398  public function sendFileObject()
399  {
400  $file = new ilSessionFile((int) $_GET['file_id']);
401 
402  ilUtil::deliverFile($file->getAbsolutePath(),$file->getFileName(),$file->getFileType());
403  return true;
404  }
405 
406 
414  public function createObject()
415  {
416  if(!is_object($this->object))
417  {
418  $this->object = new ilObjSession();
419  }
420  $this->ctrl->setParameter($this,'new_type','sess');
421  $this->initForm('create');
422  $this->tpl->addBlockFile('ADM_CONTENT','adm_content','tpl.sess_create.html','Modules/Session');
423  $this->tpl->setVariable('EVENT_ADD_TABLE',$this->form->getHTML());
424  $this->fillCloneTemplate('DUPLICATE','sess');
425  }
426 
433  {
434  global $ilLog;
435 
436  $this->saveObject(false);
437 
438  $this->ctrl->setParameter($this,'ref_id',$this->object->getRefId());
439  $target = $this->ctrl->getLinkTarget($this,'materials');
440  $target = str_replace('new_type=','nt=',$target);
441  ilUtil::redirect($target);
442  }
443 
444 
452  public function saveObject($a_redirect_on_success = true)
453  {
454  global $ilErr,$ilUser;
455 
456  $this->object = new ilObjSession();
457 
458  $this->load();
459  $this->loadRecurrenceSettings();
460  $this->initForm('create');
461 
462  $ilErr->setMessage('');
463  if(!$this->form->checkInput()) {
464  $ilErr->setMessage($this->lng->txt('err_check_input'));
465  }
466 
467  $this->object->validate();
468  $this->object->getFirstAppointment()->validate();
469 
470  if(strlen($ilErr->getMessage()))
471  {
472  ilUtil::sendFailure($ilErr->getMessage().$_GET['ref_id']);
473  $this->createObject();
474  return false;
475  }
476  // Create session
477  $this->object->create();
478  $this->object->createReference();
479  $this->object->putInTree($_GET["ref_id"]);
480  $this->object->setPermissions($_GET["ref_id"]);
481 
482  // create appointment
483  $this->object->getFirstAppointment()->setSessionId($this->object->getId());
484  $this->object->getFirstAppointment()->create();
485 
486 
487  /*
488  foreach($this->files as $file_obj)
489  {
490  $file_obj->setSessionId($this->object->getEventId());
491  $file_obj->create();
492  }
493  */
494 
495  $this->handleFileUpload();
496 
497  $this->createRecurringSessions();
498 
499  // call crs items for creating a new entry for the new session
500  // Otherwise the sorting of sessions is wrong.
501  // TODO find a better solution
502  include_once './Modules/Course/classes/class.ilCourseItems.php';
503  $tmp_course = ilObjectFactory::getInstanceByRefId((int) $_GET['ref_id'],false);
504  $items = new ilCourseItems($tmp_course);
505 
506  if($a_redirect_on_success)
507  {
508  ilUtil::sendInfo($this->lng->txt('event_add_new_event'),true);
509  $this->ctrl->returnToParent($this);
510  }
511 
512  return true;
513 
514  }
515 
516  public function handleFileUpload()
517  {
518  global $tree;
519 
520  include_once './Modules/Session/classes/class.ilEventItems.php';
521  $ev = new ilEventItems($this->object->getId());
522  $items = $ev->getItems();
523 
524  $counter = 0;
525  while(true)
526  {
527  if(!isset($_FILES['files']['name'][$counter]))
528  {
529  break;
530  }
531  if(!strlen($_FILES['files']['name'][$counter]))
532  {
533  $counter++;
534  continue;
535  }
536 
537  include_once './Modules/File/classes/class.ilObjFile.php';
538  $file = new ilObjFile();
539  $file->setTitle(ilUtil::stripSlashes($_FILES['files']['name'][$counter]));
540  $file->setDescription('');
541  $file->setFileName(ilUtil::stripSlashes($_FILES['files']['name'][$counter]));
542  $file->setFileType($_FILES['files']['type'][$counter]);
543  $file->setFileSize($_FILES['files']['size'][$counter]);
544  $file->create();
545  $new_ref_id = $file->createReference();
546  $file->putInTree($tree->getParentId($this->object->getRefId()));
547  $file->setPermissions($tree->getParentId($this->object->getRefId()));
548  $file->createDirectory();
549  $file->getUploadFile(
550  $_FILES['files']['tmp_name'][$counter],
551  $_FILES['files']['name'][$counter]
552  );
553 
554  $items[] = $new_ref_id;
555  $counter++;
556 
557  }
558 
559  $ev->setItems($items);
560  $ev->update();
561  }
562 
563 
564 
572  protected function createRecurringSessions()
573  {
574  global $tree;
575 
576  if(!$this->rec->getFrequenceType())
577  {
578  return true;
579  }
580  include_once('./Services/Calendar/classes/class.ilCalendarRecurrenceCalculator.php');
581  $calc = new ilCalendarRecurrenceCalculator($this->object->getFirstAppointment(),$this->rec);
582 
583  $period_start = clone $this->object->getFirstAppointment()->getStart();
584 
585 
586  $period_end = clone $this->object->getFirstAppointment()->getStart();
587  $period_end->increment(IL_CAL_YEAR,5);
588  $date_list = $calc->calculateDateList($period_start,$period_end);
589 
590  $period_diff = $this->object->getFirstAppointment()->getEnd()->get(IL_CAL_UNIX) -
591  $this->object->getFirstAppointment()->getStart()->get(IL_CAL_UNIX);
592  $parent_id = $tree->getParentId($this->object->getRefId());
593 
594  include_once './Modules/Session/classes/class.ilEventItems.php';
595  $evi = new ilEventItems($this->object->getId());
596  $eitems = $evi->getItems();
597 
598  $counter = 0;
599  foreach($date_list->get() as $date)
600  {
601  if(!$counter++)
602  {
603  continue;
604  }
605 
606  $new_obj = $this->object->cloneObject($parent_id);
607  $new_obj->read();
608  $new_obj->getFirstAppointment()->setStartingTime($date->get(IL_CAL_UNIX));
609  $new_obj->getFirstAppointment()->setEndingTime($date->get(IL_CAL_UNIX) + $period_diff);
610  $new_obj->getFirstAppointment()->update();
611  $new_obj->update();
612 
613  $new_evi = new ilEventItems($new_obj->getId());
614  $new_evi->setItems($eitems);
615  $new_evi->update();
616  }
617  }
618 
619 
627  public function editObject()
628  {
629  $this->tabs_gui->setTabActive('edit_properties');
630 
631  $this->initForm('edit');
632  $this->tpl->addBlockFile('ADM_CONTENT','adm_content','tpl.sess_edit.html','Modules/Session');
633  $this->tpl->setVariable('EVENT_EDIT_TABLE',$this->form->getHTML());
634 
635  if(!count($this->object->getFiles()))
636  {
637  return true;
638  }
639  $rows = array();
640  foreach($this->object->getFiles() as $file)
641  {
642  $table_data['id'] = $file->getFileId();
643  $table_data['filename'] = $file->getFileName();
644  $table_data['filetype'] = $file->getFileType();
645  $table_data['filesize'] = $file->getFileSize();
646 
647  $rows[] = $table_data;
648  }
649 
650  include_once("./Modules/Session/classes/class.ilSessionFileTableGUI.php");
651  $table_gui = new ilSessionFileTableGUI($this, "edit");
652  $table_gui->setTitle($this->lng->txt("event_files"));
653  $table_gui->setData($rows);
654  $table_gui->addCommandButton("cancel", $this->lng->txt("cancel"));
655  $table_gui->addMultiCommand("confirmDeleteFiles", $this->lng->txt("delete"));
656  $table_gui->setSelectAllCheckbox("file_id");
657  $this->tpl->setVariable('EVENT_FILE_TABLE',$table_gui->getHTML());
658 
659  return true;
660  }
661 
669  public function updateObject()
670  {
671  global $ilErr;
672 
673  $this->load();
674  $this->initForm('edit');
675 
676  $ilErr->setMessage('');
677  if(!$this->form->checkInput())
678  {
679  $ilErr->setMessage($this->lng->txt('err_check_input'));
680  }
681  $this->object->validate();
682  $this->object->getFirstAppointment()->validate();
683 
684  if(strlen($ilErr->getMessage()))
685  {
686  ilUtil::sendFailure($ilErr->getMessage());
687  $this->editObject();
688  return false;
689  }
690  // Update event
691  $this->object->update();
692  $this->object->getFirstAppointment()->update();
693 
694  foreach($this->files as $file_obj)
695  {
696  $file_obj->setSessionId($this->object->getEventId());
697  $file_obj->create();
698  }
699 
700  $this->handleFileUpload();
701 
702  ilUtil::sendSuccess($this->lng->txt('event_updated'),true);
703  $this->ctrl->redirect($this,'edit');
704  #$this->object->initFiles();
705  #$this->editObject();
706  return true;
707  }
708 
716  public function confirmDeleteFilesObject()
717  {
718  $this->tabs_gui->setTabActive('edit_properties');
719 
720  if(!count($_POST['file_id']))
721  {
722  ilUtil::sendFailure($this->lng->txt('select_one'));
723  $this->editObject();
724  return false;
725  }
726 
727  include_once("Services/Utilities/classes/class.ilConfirmationGUI.php");
728  $c_gui = new ilConfirmationGUI();
729 
730  // set confirm/cancel commands
731  $c_gui->setFormAction($this->ctrl->getFormAction($this, "deleteFiles"));
732  $c_gui->setHeaderText($this->lng->txt("info_delete_sure"));
733  $c_gui->setCancel($this->lng->txt("cancel"), "edit");
734  $c_gui->setConfirm($this->lng->txt("confirm"), "deleteFiles");
735 
736  // add items to delete
737  foreach($_POST["file_id"] as $file_id)
738  {
739  $file = new ilSessionFile($file_id);
740  if($file->getSessionId() != $this->object->getEventId())
741  {
742  ilUtil::sendFailure($this->lng->txt('select_one'));
743  $this->edit();
744  return false;
745  }
746  $c_gui->addItem("file_id[]", $file_id, $file->getFileName());
747  }
748 
749  $this->tpl->setContent($c_gui->getHTML());
750  return true;
751  }
752 
760  public function deleteFilesObject()
761  {
762  if(!count($_POST['file_id']))
763  {
764  ilUtil::sendFailure($this->lng->txt('select_one'));
765  $this->editObject();
766  return false;
767  }
768  foreach($_POST['file_id'] as $id)
769  {
770  $file = new ilSessionFile($id);
771  $file->delete();
772  }
773  $this->object->initFiles();
774  $this->editObject();
775  return true;
776  }
777 
785  public function materialsObject()
786  {
787  global $tree, $objDefinition;
788 
789  $this->tabs_gui->setTabActive('crs_materials');
790 
791  include_once 'Modules/Session/classes/class.ilEventItems.php';
792  $this->event_items = new ilEventItems($this->object->getId());
793  $items = $this->event_items->getItems();
794 
795  $this->tpl->addBlockFile('ADM_CONTENT','adm_content','tpl.sess_materials.html','Modules/Session');
796  #$this->tpl->addBlockfile("BUTTONS", "buttons", "tpl.buttons.html");
797 
798  $this->tpl->setVariable("FORMACTION",$this->ctrl->getFormAction($this,'materials'));
799  $this->tpl->setVariable("COLL_TITLE_IMG",ilUtil::getImagePath('icon_sess.gif'));
800  $this->tpl->setVariable("COLL_TITLE_IMG_ALT",$this->lng->txt('events'));
801  $this->tpl->setVariable("TABLE_TITLE",$this->lng->txt('event_assign_materials_table'));
802  $this->tpl->setVariable("TABLE_INFO",$this->lng->txt('event_assign_materials_info'));
803 
804  $this->course_ref_id = $tree->checkForParentType($this->object->getRefId(),'crs');
805  if(!$this->course_ref_id)
806  {
807  ilUtil::sendFailure('No course object found. Aborting');
808  return true;
809  }
810  $nodes = $tree->getSubTree($tree->getNodeData($this->course_ref_id));
811  $counter = 1;
812  foreach($nodes as $node)
813  {
814  // No side blocks here
815  if ($objDefinition->isSideBlock($node['type']) or $node['type'] == 'sess')
816  {
817  continue;
818  }
819 
820  if($node['type'] == 'rolf')
821  {
822  continue;
823  }
824  if($counter++ == 1)
825  {
826  continue;
827  }
828  $this->tpl->setCurrentBlock("material_row");
829 
830  $this->tpl->setVariable('TYPE_IMG',ilUtil::getImagePath('icon_'.$node['type'].'_s.gif'));
831  $this->tpl->setVariable('IMG_ALT',$this->lng->txt('obj_'.$node['type']));
832  $this->tpl->setVariable("ROW_CLASS",ilUtil::switchColor($counter,'tblrow1','tblrow2'));
833  $this->tpl->setVariable("CHECK_COLL",ilUtil::formCheckbox(in_array($node['ref_id'],$items) ? 1 : 0,
834  'items[]',$node['ref_id']));
835  $this->tpl->setVariable("COLL_TITLE",$node['title']);
836 
837  if(strlen($node['description']))
838  {
839  $this->tpl->setVariable("COLL_DESC",$node['description']);
840  }
841  $this->tpl->setVariable("ASSIGNED_IMG_OK",in_array($node['ref_id'],$items) ?
842  ilUtil::getImagePath('icon_ok.gif') :
843  ilUtil::getImagePath('icon_not_ok.gif'));
844  $this->tpl->setVariable("ASSIGNED_STATUS",$this->lng->txt('event_material_assigned'));
845  $this->tpl->setVariable("COLL_PATH",$this->formatPath($node['ref_id']));
846  $this->tpl->parseCurrentBlock();
847  }
848 
849  $this->tpl->setVariable("SELECT_ROW",ilUtil::switchColor(++$counter,'tblrow1','tblrow2'));
850  $this->tpl->setVariable("SELECT_ALL",$this->lng->txt('select_all'));
851  $this->tpl->setVariable("IMG_ARROW",ilUtil::getImagePath('arrow_downright.gif'));
852  $this->tpl->setVariable("BTN_SAVE",$this->lng->txt('save'));
853  }
854 
862  public function saveMaterialsObject()
863  {
864  include_once './Modules/Session/classes/class.ilEventItems.php';
865 
866  $this->event_items = new ilEventItems($this->object->getId());
867  $this->event_items->setItems(is_array($_POST['items']) ? $_POST['items'] : array());
868  $this->event_items->update();
869 
870  ilUtil::sendSuccess($this->lng->txt('settings_saved'));
871  $this->materialsObject();
872  }
873 
878  protected function membersObject()
879  {
880  global $tree,$ilUser;
881 
882  $this->checkPermission('write');
883  $this->tabs_gui->setTabActive('event_edit_members');
884 
885  $this->tpl->addBlockFile('ADM_CONTENT', 'adm_content', 'tpl.sess_members.html', 'Modules/Session');
886 
887  include_once './Services/UIComponent/Toolbar/classes/class.ilToolbarGUI.php';
888  $toolbar = new ilToolbarGUI();
889  $toolbar->addButton(
890  $this->lng->txt('print'),
891  $this->ctrl->getLinkTarget($this,'printViewMembers'),
892  '_blank');
893  $toolbar->addButton($this->lng->txt('sess_gen_attendance_list'),
894  $this->ctrl->getLinkTarget($this,'attendanceList'));
895 
896  $this->tpl->setVariable('ACTION_BUTTONS',$toolbar->getHTML());
897 
898  $this->course_ref_id = $tree->checkForParentType($this->object->getRefId(),'crs');
899  $this->course_obj_id = ilObject::_lookupObjId($this->course_ref_id);
900  if(!$this->course_ref_id)
901  {
902  ilUtil::sendFailure('No course object found. Aborting');
903  return true;
904  }
905 
906  include_once './Modules/Course/classes/class.ilCourseParticipants.php';
907  include_once './Modules/Session/classes/class.ilEventParticipants.php';
908 
909  $members_obj = ilCourseParticipants::_getInstanceByObjId($this->course_obj_id);
910  $event_part = new ilEventParticipants($this->object->getId());
911 
912  // Save hide/show table settings
913  $this->setShowHidePrefs();
914 
915  // Admins
916  if(count($admins = $members_obj->getAdmins()))
917  {
918  include_once('./Modules/Session/classes/class.ilSessionParticipantsTableGUI.php');
919  if($ilUser->getPref('sess_admin_hide'))
920  {
922  $this->ctrl->setParameter($this,'admin_hide',0);
923  $table->addHeaderCommand($this->ctrl->getLinkTarget($this,'members'),
924  $this->lng->txt('show'),
925  '',
926  ilUtil::getImagePath('edit_add.png'));
927  $this->ctrl->clearParameters($this);
928  }
929  else
930  {
932  $this->ctrl->setParameter($this,'admin_hide',1);
933  $table->addHeaderCommand($this->ctrl->getLinkTarget($this,'members'),
934  $this->lng->txt('hide'),
935  '',
936  ilUtil::getImagePath('edit_remove.png'));
937  $this->ctrl->clearParameters($this);
938  }
939 
940  $table->addCommandButton('updateMembers',$this->lng->txt('save'));
941  $table->setTitle($this->lng->txt('event_tbl_admins'),'icon_usr.gif',$this->lng->txt('event_tbl_admins'));
942  $table->enableRegistration($this->object->enabledRegistration());
943  $table->setParticipants($admins);
944  $table->parse();
945  $this->tpl->setVariable('ADMINS',$table->getHTML());
946  }
947 
948  // Tutors
949  if(count($tutors = $members_obj->getTutors()))
950  {
951  include_once('./Modules/Session/classes/class.ilSessionParticipantsTableGUI.php');
952  if($ilUser->getPref('sess_tutor_hide'))
953  {
955  $this->ctrl->setParameter($this,'tutor_hide',0);
956  $table->addHeaderCommand($this->ctrl->getLinkTarget($this,'members'),
957  $this->lng->txt('show'),
958  '',
959  ilUtil::getImagePath('edit_add.png'));
960  $this->ctrl->clearParameters($this);
961  }
962  else
963  {
965  $this->ctrl->setParameter($this,'tutor_hide',1);
966  $table->addHeaderCommand($this->ctrl->getLinkTarget($this,'members'),
967  $this->lng->txt('hide'),
968  '',
969  ilUtil::getImagePath('edit_remove.png'));
970  $this->ctrl->clearParameters($this);
971  }
972  $table->addCommandButton('updateMembers',$this->lng->txt('save'));
973  $table->setTitle($this->lng->txt('event_tbl_tutors'),'icon_usr.gif',$this->lng->txt('event_tbl_admins'));
974  $table->enableRegistration($this->object->enabledRegistration());
975  $table->setParticipants($tutors);
976  $table->parse();
977  $this->tpl->setVariable('TUTORS',$table->getHTML());
978  }
979 
980  // Members
981  if(count($members = $members_obj->getMembers()))
982  {
983  include_once('./Modules/Session/classes/class.ilSessionParticipantsTableGUI.php');
984  if($ilUser->getPref('sess_member_hide'))
985  {
987  $this->ctrl->setParameter($this,'member_hide',0);
988  $table->addHeaderCommand($this->ctrl->getLinkTarget($this,'members'),
989  $this->lng->txt('show'),
990  '',
991  ilUtil::getImagePath('edit_add.png'));
992  $this->ctrl->clearParameters($this);
993  }
994  else
995  {
997  $this->ctrl->setParameter($this,'member_hide',1);
998  $table->addHeaderCommand($this->ctrl->getLinkTarget($this,'members'),
999  $this->lng->txt('hide'),
1000  '',
1001  ilUtil::getImagePath('edit_remove.png'));
1002  $this->ctrl->clearParameters($this);
1003  }
1004  $table->addCommandButton('updateMembers',$this->lng->txt('save'));
1005  $table->setTitle($this->lng->txt('event_tbl_members'),'icon_usr.gif',$this->lng->txt('event_tbl_admins'));
1006  $table->enableRegistration($this->object->enabledRegistration());
1007  $table->setParticipants($members);
1008  $table->parse();
1009  $this->tpl->setVariable('MEMBERS',$table->getHTML());
1010  }
1011 
1012 
1013 
1014 
1015 
1016  }
1017 
1024  public function setShowHidePrefs()
1025  {
1026  global $ilUser;
1027 
1028  if(isset($_GET['admin_hide']))
1029  {
1030  $ilUser->writePref('sess_admin_hide',(int) $_GET['admin_hide']);
1031  }
1032  if(isset($_GET['tutor_hide']))
1033  {
1034  $ilUser->writePref('sess_tutor_hide',(int) $_GET['tutor_hide']);
1035  }
1036  if(isset($_GET['member_hide']))
1037  {
1038  $ilUser->writePref('sess_member_hide',(int) $_GET['member_hide']);
1039  }
1040  }
1041 
1049  public function updateMembersObject()
1050  {
1051  global $tree;
1052 
1053  $this->checkPermission('write');
1054 
1055  include_once 'Modules/Course/classes/class.ilCourseParticipants.php';
1056  include_once 'Modules/Session/classes/class.ilEventParticipants.php';
1057 
1058  $this->course_ref_id = $tree->checkForParentType($this->object->getRefId(),'crs');
1059  $this->course_obj_id = ilObject::_lookupObjId($this->course_ref_id);
1060  if(!$this->course_ref_id)
1061  {
1062  ilUtil::sendFailure('No course object found. Aborting');
1063  return true;
1064  }
1065 
1066  $_POST['participants'] = is_array($_POST['participants']) ? $_POST['participants'] : array();
1067 
1068  $members_obj = ilCourseParticipants::_getInstanceByObjId($this->course_obj_id);
1069  $event_part = new ilEventParticipants($this->object->getId());
1070 
1071  $visible = $_POST['visible_participants'] ? $_POST['visible_participants'] : array();
1072  foreach($visible as $user)
1073  {
1074  $part = new ilEventParticipants($this->object->getId());
1075  $part->setUserId($user);
1076  $part->setMark(ilUtil::stripSlashes($_POST['mark'][$user]));
1077  $part->setComment(ilUtil::stripSlashes($_POST['comment'][$user]));
1078  $part->setParticipated(isset($_POST['participants'][$user]) ? true : false);
1079  $part->setRegistered(ilEventParticipants::_isRegistered($user,$this->object->getId()));
1080  $part->updateUser();
1081  }
1082  ilUtil::sendSuccess($this->lng->txt('settings_saved'));
1083  $this->membersObject();
1084  }
1085 
1092  public function attendanceListObject()
1093  {
1094  global $tpl,$ilTabs;
1095 
1096  $this->checkPermission('write');
1097 
1098  $ilTabs->setTabActive('event_edit_members');
1099 
1100  $this->initAttendanceForm();
1101  $tpl->setContent($this->form->getHTML());
1102 
1103  }
1104 
1111  protected function initAttendanceForm()
1112  {
1113  include_once('./Services/Form/classes/class.ilPropertyFormGUI.php');
1114 
1115  $this->form = new ilPropertyFormGUI();
1116  $this->form->setFormAction($this->ctrl->getFormAction($this));
1117  $this->form->setTarget('_blank');
1118  $this->form->setTitle($this->lng->txt('sess_gen_attendance_list'));
1119 
1120  $mark = new ilCheckboxInputGUI($this->lng->txt('trac_mark'),'show_mark');
1121  $mark->setOptionTitle($this->lng->txt('sess_gen_mark_title'));
1122  $mark->setValue(1);
1123  $this->form->addItem($mark);
1124 
1125  $comment = new ilCheckboxInputGUI($this->lng->txt('trac_comment'),'show_comment');
1126  $comment->setOptionTitle($this->lng->txt('sess_gen_comment'));
1127  $comment->setValue(1);
1128  $this->form->addItem($comment);
1129 
1130  $signature = new ilCheckboxInputGUI($this->lng->txt('sess_signature'),'show_signature');
1131  $signature->setOptionTitle($this->lng->txt('sess_gen_signature'));
1132  $signature->setValue(1);
1133  $this->form->addItem($signature);
1134 
1135  $part = new ilFormSectionHeaderGUI();
1136  $part->setTitle($this->lng->txt('event_participant_selection'));
1137  $this->form->addItem($part);
1138 
1139  // Admins
1140  $admin = new ilCheckboxInputGUI($this->lng->txt('event_tbl_admins'),'show_admins');
1141  $admin->setOptionTitle($this->lng->txt('event_inc_admins'));
1142  $admin->setValue(1);
1143  $this->form->addItem($admin);
1144 
1145  // Tutors
1146  $tutor = new ilCheckboxInputGUI($this->lng->txt('event_tbl_tutors'),'show_tutors');
1147  $tutor->setOptionTitle($this->lng->txt('event_inc_tutors'));
1148  $tutor->setValue(1);
1149  $this->form->addItem($tutor);
1150 
1151  // Members
1152  $member = new ilCheckboxInputGUI($this->lng->txt('event_tbl_members'),'show_members');
1153  $member->setOptionTitle($this->lng->txt('event_inc_members'));
1154  $member->setValue(1);
1155  $member->setChecked(true);
1156  $this->form->addItem($member);
1157 
1158  $this->form->addCommandButton('printAttendanceList',$this->lng->txt('sess_print_attendance_list'));
1159  #$this->form->addCommandButton('members', $this->lng->txt('cancel'));
1160 
1161  }
1162 
1168  protected function printAttendanceListObject()
1169  {
1170  global $ilErr,$ilAccess,$tree;
1171 
1172  include_once 'Modules/Session/classes/class.ilEventParticipants.php';
1173  include_once('./Modules/Course/classes/class.ilCourseParticipants.php');
1174 
1175  $this->checkPermission('write');
1176 
1177  $this->course_ref_id = $tree->checkForParentType($this->object->getRefId(),'crs');
1178  $this->course_obj_id = ilObject::_lookupObjId($this->course_ref_id);
1179  if(!$this->course_ref_id)
1180  {
1181  ilUtil::sendFailure('No course object found. Aborting');
1182  return true;
1183  }
1184 
1185  $members_obj = ilCourseParticipants::_getInstanceByObjId($this->course_obj_id);
1186  $event_app = $this->object->getFirstAppointment();
1187  $event_part = new ilEventParticipants($this->object->getId());
1188 
1189 
1190  $this->tpl = new ilTemplate('tpl.main.html',true,true);
1191  // load style sheet depending on user's settings
1192  $location_stylesheet = ilUtil::getStyleSheetLocation();
1193  $this->tpl->setVariable("LOCATION_STYLESHEET",$location_stylesheet);
1194 
1195  $tpl = new ilTemplate('tpl.sess_attendance_list_print.html',true,true,'Modules/Session');
1196 
1197  $tpl->setVariable("ATTENDANCE_LIST",$this->lng->txt('sess_attendance_list'));
1198  $tpl->setVariable("EVENT_NAME",$this->object->getTitle() ? ': '.$this->object->getTitle() : '');
1200  $tpl->setVariable("DATE",ilDatePresentation::formatPeriod($event_app->getStart(),$event_app->getEnd()));
1202 
1203  $tpl->setVariable("TXT_NAME",$this->lng->txt('name'));
1204  if($_POST['show_mark'])
1205  {
1206  $tpl->setVariable("TXT_MARK",$this->lng->txt('trac_mark'));
1207  }
1208  if($_POST['show_comment'])
1209  {
1210  $tpl->setVariable("TXT_COMMENT",$this->lng->txt('trac_comment'));
1211  }
1212  if($_POST['show_signature'])
1213  {
1214  $tpl->setVariable("TXT_SIGNATURE",$this->lng->txt('sess_signature'));
1215  }
1216 
1217  if($_POST['show_admins'])
1218  {
1219  $members = array_merge((array) $members,$members_obj->getAdmins());
1220  }
1221  if($_POST['show_tutors'])
1222  {
1223  $members = array_merge((array) $members,$members_obj->getTutors());
1224  }
1225  if($_POST['show_members'])
1226  {
1227  $members = array_merge((array) $members,$members_obj->getMembers());
1228  }
1229  $members = ilUtil::_sortIds((array) $members,'usr_data','lastname','usr_id');
1230 
1231  foreach($members as $user_id)
1232  {
1233  $user_data = $event_part->getUser($user_id);
1234 
1235  if($_POST['show_mark'])
1236  {
1237  $tpl->setVariable("MARK",$user_data['mark'] ? $user_data['mark'] : ' ');
1238  }
1239  if($_POST['show_comment'])
1240  {
1241  $tpl->setVariable("COMMENT",$user_data['comment'] ? $user_data['comment'] : ' ');
1242  }
1243  if($_POST['show_signature'])
1244  {
1245  $tpl->touchBlock('row_signature');
1246  }
1247 
1248  $tpl->setCurrentBlock("member_row");
1249  $name = ilObjUser::_lookupName($user_id);
1250  $tpl->setVariable("LASTNAME",$name['lastname']);
1251  $tpl->setVariable("FIRSTNAME",$name['firstname']);
1252  $tpl->setVariable("LOGIN",ilObjUser::_lookupLogin($user_id));
1253  $tpl->parseCurrentBlock();
1254  }
1255 
1256  $this->tpl->setVariable("CONTENT",$tpl->get());
1257  $this->tpl->setVariable("BODY_ATTRIBUTES",'onload="window.print()"');
1258  $this->tpl->show();
1259  exit;
1260  }
1261 
1262 
1270  public function printViewMembersObject()
1271  {
1272  include_once 'Modules/Session/classes/class.ilEventParticipants.php';
1273  include_once('./Modules/Course/classes/class.ilCourseParticipants.php');
1274 
1275  global $ilErr,$ilAccess,$tree,$ilUser;
1276 
1277  $this->course_ref_id = $tree->checkForParentType($this->object->getRefId(),'crs');
1278  $this->course_obj_id = ilObject::_lookupObjId($this->course_ref_id);
1279  if(!$this->course_ref_id)
1280  {
1281  ilUtil::sendFailure('No course object found. Aborting');
1282  return true;
1283  }
1284 
1285  $members_obj = ilCourseParticipants::_getInstanceByObjId($this->course_obj_id);
1286  $event_app = $this->object->getFirstAppointment();
1287  $event_part = new ilEventParticipants($this->object->getId());
1288 
1289  $this->tpl = new ilTemplate('tpl.main.html',true,true);
1290  // load style sheet depending on user's settings
1291  $location_stylesheet = ilUtil::getStyleSheetLocation();
1292  $this->tpl->setVariable("LOCATION_STYLESHEET",$location_stylesheet);
1293 
1294  $tpl = new ilTemplate('tpl.sess_members_print.html',true,true,'Modules/Session');
1295 
1296  #$tpl->setVariable("EVENT",$this->lng->txt('event'));
1297  $tpl->setVariable("EVENT_NAME",$this->object->getTitle() ? ': '.$this->object->getTitle() : $this->object->getTitle());
1299  $tpl->setVariable("DATE",ilDatePresentation::formatPeriod($event_app->getStart(),$event_app->getEnd()));
1301 
1302 
1303  if(!$ilUser->getPref('sess_admin_hide') and count($members_obj->getAdmins()))
1304  {
1305  $tmp['txt'] = $this->lng->txt('event_tbl_admins');
1306  $tmp['users'] = $members_obj->getAdmins();
1307 
1308  $participants[] = $tmp;
1309  }
1310  if(!$ilUser->getPref('sess_tutor_hide') and count($members_obj->getTutors()))
1311  {
1312  $tmp['txt'] = $this->lng->txt('event_tbl_tutors');
1313  $tmp['users'] = $members_obj->getTutors();
1314 
1315  $participants[] = $tmp;
1316  }
1317  if(!$ilUser->getPref('sess_member_hide') and count($members_obj->getMembers()))
1318  {
1319  $tmp['txt'] = $this->lng->txt('event_tbl_members');
1320  $tmp['users'] = $members_obj->getMembers();
1321 
1322  $participants[] = $tmp;
1323  }
1324 
1325  foreach((array) $participants as $participants_data)
1326  {
1327  $members = ilUtil::_sortIds($participants_data['users'],'usr_data','lastname','usr_id');
1328  foreach($members as $user_id)
1329  {
1330 
1331  $user_data = $event_part->getUser($user_id);
1332 
1333  if($this->object->enabledRegistration())
1334  {
1335  $tpl->setCurrentBlock("reg_col");
1336  $tpl->setVariable("REGISTERED",$event_part->isRegistered($user_id) ? "X" : "");
1337  $tpl->parseCurrentBlock();
1338  }
1339  $tpl->setVariable("COMMENT",$user_data['comment']);
1340 
1341  $tpl->setCurrentBlock("member_row");
1342  $name = ilObjUser::_lookupName($user_id);
1343  $tpl->setVariable("LASTNAME",$name['lastname']);
1344  $tpl->setVariable("FIRSTNAME",$name['firstname']);
1345  $tpl->setVariable("LOGIN",ilObjUser::_lookupLogin($user_id));
1346  $tpl->setVariable("MARK",$user_data['mark']);
1347  $tpl->setVariable("PARTICIPATED",$event_part->hasParticipated($user_id) ? "X" : "");
1348  $tpl->parseCurrentBlock();
1349  }
1350 
1351  $tpl->setCurrentBlock('part_group');
1352  $tpl->setVariable('GROUP_NAME',$participants_data['txt']);
1353  $tpl->setVariable("TXT_NAME",$this->lng->txt('name'));
1354  $tpl->setVariable("TXT_MARK",$this->lng->txt('trac_mark'));
1355  $tpl->setVariable("TXT_COMMENT",$this->lng->txt('trac_comment'));
1356  $tpl->setVariable("TXT_PARTICIPATED",$this->lng->txt('event_tbl_participated'));
1357  if($this->object->enabledRegistration())
1358  {
1359  $tpl->setVariable("TXT_REGISTERED",$this->lng->txt('event_tbl_registered'));
1360  }
1361  $tpl->parseCurrentBlock();
1362 
1363  }
1364 
1365  $this->tpl->setVariable("CONTENT",$tpl->get());
1366  $this->tpl->setVariable("BODY_ATTRIBUTES",'onload="window.print()"');
1367  $this->tpl->show();
1368  exit;
1369 
1370  }
1371 
1379  public function eventsListObject()
1380  {
1381  global $ilErr,$ilAccess, $ilUser,$tree;
1382 
1383  if(!$ilAccess->checkAccess('write','',$this->object->getRefId()))
1384  {
1385  $ilErr->raiseError($this->lng->txt('msg_no_perm_read'),$ilErr->MESSAGE);
1386  }
1387 
1388  $this->tpl->addBlockFile('ADM_CONTENT','adm_content','tpl.sess_list.html','Modules/Session');
1389  $this->__showButton($this->ctrl->getLinkTarget($this,'exportCSV'),$this->lng->txt('event_csv_export'));
1390 
1391  include_once 'Modules/Course/classes/class.ilCourseParticipants.php';
1392  include_once 'Modules/Session/classes/class.ilEventParticipants.php';
1393 
1394  $this->tpl->addBlockfile("EVENTS_TABLE","events_table", "tpl.table.html");
1395  $this->tpl->addBlockfile('TBL_CONTENT','tbl_content','tpl.sess_list_row.html','Modules/Session');
1396 
1397  $members_obj = ilCourseParticipants::_getInstanceByObjId($this->object->getId());
1398  $members = $members_obj->getParticipants();
1399  $members = ilUtil::_sortIds($members,'usr_data','lastname','usr_id');
1400 
1401  // Table
1402  $tbl = new ilTableGUI();
1403  $tbl->setTitle($this->lng->txt("event_overview"),
1404  'icon_usr.gif',
1405  $this->lng->txt('obj_usr'));
1406  $this->ctrl->setParameter($this,'offset',(int) $_GET['offset']);
1407 
1408  $course_ref_id = $tree->checkForParentType($this->object->getRefId(),'crs');
1409  $events = array();
1410  foreach($tree->getSubtree($tree->getNodeData($course_ref_id),false,'sess') as $event_id)
1411  {
1412  $tmp_event = ilObjectFactory::getInstanceByRefId($event_id,false);
1413  if(!is_object($tmp_event) or $tmp_event->getType() != 'sess')
1414  {
1415  continue;
1416  }
1417  $events[] = $tmp_event;
1418  }
1419 
1420  $headerNames = array();
1421  $headerVars = array();
1422  $colWidth = array();
1423 
1424  $headerNames[] = $this->lng->txt('name');
1425  $headerVars[] = "name";
1426  $colWidth[] = '20%';
1427 
1428  for ($i = 1; $i <= count($events); $i++)
1429  {
1430  $headerNames[] = $i;
1431  $headerVars[] = "event_".$i;
1432  $colWidth[] = 80/count($events)."%";
1433  }
1434 
1435  $this->tpl->setVariable("FORMACTION",$this->ctrl->getFormAction($this));
1436  $tbl->setHeaderNames($headerNames);
1437  $tbl->setHeaderVars($headerVars, $this->ctrl->getParameterArray($this,'eventsList'));
1438  $tbl->setColumnWidth($colWidth);
1439 
1440  $tbl->setOrderColumn($_GET["sort_by"]);
1441  $tbl->setOrderDirection($_GET["sort_order"]);
1442  $tbl->setOffset($_GET["offset"]);
1443  $tbl->setLimit($ilUser->getPref("hits_per_page"));
1444  $tbl->setMaxCount(count($members));
1445  $tbl->setFooter("tblfooter",$this->lng->txt("previous"),$this->lng->txt("next"));
1446 
1447  $sliced_users = array_slice($members,$_GET['offset'],$_SESSION['tbl_limit']);
1448  $tbl->disable('sort');
1449  $tbl->render();
1450 
1451  $counter = 0;
1452  foreach($sliced_users as $user_id)
1453  {
1454  foreach($events as $event_obj)
1455  {
1456  $this->tpl->setCurrentBlock("eventcols");
1457 
1458  $event_part = new ilEventParticipants($this->object->getId());
1459 
1460  {
1461  $this->tpl->setVariable("IMAGE_PARTICIPATED", $event_part->hasParticipated($user_id) ?
1462  ilUtil::getImagePath('icon_ok.gif') :
1463  ilUtil::getImagePath('icon_not_ok.gif'));
1464 
1465  $this->tpl->setVariable("PARTICIPATED", $event_part->hasParticipated($user_id) ?
1466  $this->lng->txt('event_participated') :
1467  $this->lng->txt('event_not_participated'));
1468  }
1469 
1470  $this->tpl->parseCurrentBlock();
1471  }
1472 
1473  $this->tpl->setCurrentBlock("tbl_content");
1474  $name = ilObjUser::_lookupName($user_id);
1475  $this->tpl->setVariable("CSS_ROW",ilUtil::switchColor($counter++,'tblrow1','tblrow2'));
1476  $this->tpl->setVariable("LASTNAME",$name['lastname']);
1477  $this->tpl->setVariable("FIRSTNAME",$name['firstname']);
1478  $this->tpl->setVariable("LOGIN",ilObjUser::_lookupLogin($user_id));
1479  $this->tpl->parseCurrentBlock();
1480  }
1481 
1482  $this->tpl->setVariable("HEAD_TXT_LEGEND", $this->lng->txt("legend"));
1483  $this->tpl->setVariable("HEAD_TXT_DIGIT", $this->lng->txt("event_digit"));
1484  $this->tpl->setVariable("HEAD_TXT_EVENT", $this->lng->txt("event"));
1485  $this->tpl->setVariable("HEAD_TXT_LOCATION", $this->lng->txt("event_location"));
1486  $this->tpl->setVariable("HEAD_TXT_DATE_TIME",$this->lng->txt("event_date_time"));
1487  $i = 1;
1488  foreach($events as $event_obj)
1489  {
1490  $this->tpl->setCurrentBlock("legend_loop");
1491  $this->tpl->setVariable("LEGEND_CSS_ROW",ilUtil::switchColor($counter++,'tblrow1','tblrow2'));
1492  $this->tpl->setVariable("LEGEND_DIGIT", $i++);
1493  $this->tpl->setVariable("LEGEND_EVENT_TITLE", $event_obj->getTitle());
1494  $this->tpl->setVariable("LEGEND_EVENT_DESCRIPTION", $event_obj->getDescription());
1495  $this->tpl->setVariable("LEGEND_EVENT_LOCATION", $event_obj->getLocation());
1496  $this->tpl->setVariable("LEGEND_EVENT_APPOINTMENT", $event_obj->getFirstAppointment()->appointmentToString());
1497  $this->tpl->parseCurrentBlock();
1498  }
1499 
1500  }
1501 
1507  protected function initForm($a_mode)
1508  {
1509  global $ilUser;
1510 
1511  if(is_object($this->form))
1512  {
1513  return true;
1514  }
1515 
1516  $this->lng->loadLanguageModule('dateplaner');
1517 
1518  include_once("./Services/Form/classes/class.ilPropertyFormGUI.php");
1519 
1520  include_once('./Services/YUI/classes/class.ilYuiUtil.php');
1522 
1523  $this->form = new ilPropertyFormGUI();
1524  $this->form->setMultipart(true);
1525  $this->form->setTableWidth('60%');
1526  $this->form->setFormAction($this->ctrl->getFormAction($this));
1527  $this->form->setMultipart(true);
1528 
1529  /*
1530  $full = new ilCheckboxInputGUI('','fulltime');
1531  $full->setChecked($this->object->getFirstAppointment()->enabledFulltime() ? true : false);
1532  $full->setOptionTitle($this->lng->txt('event_fulltime_info'));
1533  $full->setAdditionalAttributes('onchange="ilToggleSessionTime(this);"');
1534  #$this->form->addItem($full);
1535  */
1536 
1537  $this->lng->loadLanguageModule('dateplaner');
1538  include_once './Services/Form/classes/class.ilDateDurationInputGUI.php';
1539  #$this->tpl->addJavaScript('./Modules/Session/js/toggle_session_time.js');
1540  $this->tpl->addJavaScript('./Services/Form/js/date_duration.js');
1541  $dur = new ilDateDurationInputGUI($this->lng->txt('cal_fullday'),'event');
1542  $dur->setStartText($this->lng->txt('event_start_date'));
1543  $dur->setEndText($this->lng->txt('event_end_date'));
1544  $dur->enableToggleFullTime(
1545  $this->lng->txt('event_fulltime_info'),
1546  $this->object->getFirstAppointment()->enabledFulltime() ? true : false
1547  );
1548  $dur->setMinuteStepSize(5);
1549  $dur->setShowTime(true);
1550  $dur->setShowDate(true);
1551  $dur->setStart($this->object->getFirstAppointment()->getStart());
1552  $dur->setEnd($this->object->getFirstAppointment()->getEnd());
1553 
1554  $this->form->addItem($dur);
1555 
1556  /*
1557  // start
1558  $start = new ilDateTimeInputGUI($this->lng->txt('event_start_date'),'start');
1559  $start->setMinuteStepSize(5);
1560  $start->setDate($this->object->getFirstAppointment()->getStart());
1561  $start->setShowTime(true);
1562  #$this->form->addItem($start);
1563 
1564  // end
1565  $end = new ilDateTimeInputGUI($this->lng->txt('event_end_date'),'end');
1566  $end->setMinuteStepSize(5);
1567  $end->setDate($this->object->getFirstAppointment()->getEnd());
1568  $end->setShowTime(true);
1569  #$this->form->addItem($end);
1570  */
1571 
1572  // Recurrence
1573  if($a_mode == 'create')
1574  {
1575  if(!is_object($this->rec))
1576  {
1577  include_once('./Modules/Session/classes/class.ilEventRecurrence.php');
1578  $this->rec = new ilEventRecurrence();
1579  }
1580  include_once('./Services/Calendar/classes/Form/class.ilRecurrenceInputGUI.php');
1581  $rec = new ilRecurrenceInputGUI($this->lng->txt('cal_recurrences'),'frequence');
1582  $rec->enableUntilSelection(false);
1583  $rec->setRecurrence($this->rec);
1584  $this->form->addItem($rec);
1585  }
1586 
1588  $section->setTitle($this->lng->txt('event_section_information'));
1589  $this->form->addItem($section);
1590 
1591  // title
1592  $title = new ilTextInputGUI($this->lng->txt('event_title'),'title');
1593  $title->setValue($this->object->getTitle());
1594  $title->setSize(50);
1595  $title->setMaxLength(70);
1596  $this->form->addItem($title);
1597 
1598  // desc
1599  $desc = new ilTextAreaInputGUI($this->lng->txt('event_desc'),'desc');
1600  $desc->setValue($this->object->getLongDescription());
1601  $desc->setRows(4);
1602  $desc->setCols(50);
1603  $this->form->addItem($desc);
1604 
1605  // location
1606  $desc = new ilTextAreaInputGUI($this->lng->txt('event_location'),'location');
1607  $desc->setValue($this->object->getLocation());
1608  $desc->setRows(4);
1609  $desc->setCols(50);
1610  $this->form->addItem($desc);
1611 
1612  // workflow
1613  $details = new ilTextAreaInputGUI($this->lng->txt('event_details_workflow'),'details');
1614  $details->setValue($this->object->getDetails());
1615  $details->setCols(50);
1616  $details->setRows(4);
1617  $this->form->addItem($details);
1618 
1619  // section
1621  $section->setTitle($this->lng->txt('event_tutor_data'));
1622  $this->form->addItem($section);
1623 
1624  // name
1625  $tutor_name = new ilTextInputGUI($this->lng->txt('tutor_name'),'tutor_name');
1626  $tutor_name->setValue($this->object->getName());
1627  $tutor_name->setSize(20);
1628  $tutor_name->setMaxLength(70);
1629  $this->form->addItem($tutor_name);
1630 
1631  // email
1632  $tutor_email = new ilTextInputGUI($this->lng->txt('tutor_email'),'tutor_email');
1633  $tutor_email->setValue($this->object->getEmail());
1634  $tutor_email->setSize(20);
1635  $tutor_email->setMaxLength(70);
1636  $this->form->addItem($tutor_email);
1637 
1638  // phone
1639  $tutor_phone = new ilTextInputGUI($this->lng->txt('tutor_phone'),'tutor_phone');
1640  $tutor_phone->setValue($this->object->getPhone());
1641  $tutor_phone->setSize(20);
1642  $tutor_phone->setMaxLength(70);
1643  $this->form->addItem($tutor_phone);
1644 
1646  $section->setTitle($this->lng->txt('crs_further_settings'));
1647  $this->form->addItem($section);
1648 
1649  // registration
1650  $reg = new ilCheckboxInputGUI($this->lng->txt('event_registration'),'registration');
1651  $reg->setChecked($this->object->enabledRegistration() ? true : false);
1652  $reg->setOptionTitle($this->lng->txt('event_registration_info'));
1653  $this->form->addItem($reg);
1654 
1655 
1657  $section->setTitle($this->lng->txt('event_assign_files'));
1658  $this->form->addItem($section);
1659 
1660  $files = new ilFileWizardInputGUI($this->lng->txt('objs_file'),'files');
1661  $files->setFilenames(array(0 => ''));
1662  $this->form->addItem($files);
1663 
1664  switch($a_mode)
1665  {
1666  case 'create':
1667  $this->form->setTitle($this->lng->txt('event_table_create'));
1668  $this->form->setTitleIcon(ilUtil::getImagePath('icon_event.gif'));
1669 
1670  $this->form->addCommandButton('save',$this->lng->txt('event_btn_add'));
1671  $this->form->addCommandButton('saveAndAssignMaterials',$this->lng->txt('event_btn_add_edit'));
1672  $this->form->addCommandButton('cancel',$this->lng->txt('cancel'));
1673 
1674  return true;
1675 
1676  case 'edit':
1677  $this->form->setTitle($this->lng->txt('event_table_update'));
1678  $this->form->setTitleIcon(ilUtil::getImagePath('icon_event.gif'));
1679 
1680  $this->form->addCommandButton('update',$this->lng->txt('save'));
1681  $this->form->addCommandButton('cancel',$this->lng->txt('cancel'));
1682 
1683  return true;
1684  }
1685  return true;
1686  }
1687 
1695  protected function load()
1696  {
1697  global $ilUser;
1698 
1699  $this->object->getFirstAppointment()->setStartingTime($this->__toUnix($_POST['event']['start']['date'],$_POST['event']['start']['time']));
1700  $this->object->getFirstAppointment()->setEndingTime($this->__toUnix($_POST['event']['end']['date'],$_POST['event']['end']['time']));
1701  $this->object->getFirstAppointment()->toggleFullTime((bool) $_POST['event']['fulltime']);
1702 
1703  include_once('./Services/Calendar/classes/class.ilDate.php');
1704  if($this->object->getFirstAppointment()->isFullday())
1705  {
1706  $start = new ilDate($_POST['event']['start']['date']['y'].'-'.$_POST['event']['start']['date']['m'].'-'.$_POST['event']['start']['date']['d'],
1707  IL_CAL_DATE);
1708  $this->object->getFirstAppointment()->setStart($start);
1709 
1710  $end = new ilDate($_POST['event']['end']['date']['y'].'-'.$_POST['event']['end']['date']['m'].'-'.$_POST['event']['end']['date']['d'],
1711  IL_CAL_DATE);
1712  $this->object->getFirstAppointment()->setEnd($end);
1713  }
1714  else
1715  {
1716  $start_dt['year'] = (int) $_POST['event']['start']['date']['y'];
1717  $start_dt['mon'] = (int) $_POST['event']['start']['date']['m'];
1718  $start_dt['mday'] = (int) $_POST['event']['start']['date']['d'];
1719  $start_dt['hours'] = (int) $_POST['event']['start']['time']['h'];
1720  $start_dt['minutes'] = (int) $_POST['event']['start']['time']['m'];
1721 
1722  $start = new ilDateTime($start_dt,IL_CAL_FKT_GETDATE,$ilUser->getTimeZone());
1723  $this->object->getFirstAppointment()->setStart($start);
1724 
1725  $end_dt['year'] = (int) $_POST['event']['end']['date']['y'];
1726  $end_dt['mon'] = (int) $_POST['event']['end']['date']['m'];
1727  $end_dt['mday'] = (int) $_POST['event']['end']['date']['d'];
1728  $end_dt['hours'] = (int) $_POST['event']['end']['time']['h'];
1729  $end_dt['minutes'] = (int) $_POST['event']['end']['time']['m'];
1730  $end = new ilDateTime($end_dt,IL_CAL_FKT_GETDATE,$ilUser->getTimeZone());
1731  $this->object->getFirstAppointment()->setEnd($end);
1732  }
1733 
1734  $counter = 1;
1735  $this->files = array();
1736 
1737  foreach($_FILES as $name => $data)
1738  {
1739  if(!strlen($data['tmp_name']))
1740  {
1741  ++$counter;
1742  continue;
1743  }
1744  $filename = strlen($_POST['file_name'.$counter]) ?
1745  $_POST['file_name'.$counter] :
1746  $data['name'];
1747 
1748  $file = new ilSessionFile();
1749  $file->setFileName($filename);
1750  $file->setFileSize($data['size']);
1751  $file->setFileType($data['type']);
1752  $file->setTemporaryName($data['tmp_name']);
1753  $file->setErrorCode($data['error']);
1754  $this->files[] = $file;
1755  ++$counter;
1756  }
1757 
1758  $this->object->setTitle(ilUtil::stripSlashes($_POST['title']));
1759  $this->object->setDescription(ilUtil::stripSlashes($_POST['desc']));
1760  $this->object->setLocation(ilUtil::stripSlashes($_POST['location']));
1761  $this->object->setName(ilUtil::stripSlashes($_POST['tutor_name']));
1762  $this->object->setPhone(ilUtil::stripSlashes($_POST['tutor_phone']));
1763  $this->object->setEmail(ilUtil::stripSlashes($_POST['tutor_email']));
1764  $this->object->setDetails(ilUtil::stripSlashes($_POST['details']));
1765  $this->object->enableRegistration((int) $_POST['registration']);
1766  }
1767 
1774  protected function loadRecurrenceSettings()
1775  {
1776  include_once('./Modules/Session/classes/class.ilSessionRecurrence.php');
1777  $this->rec = new ilSessionRecurrence();
1778 
1779  switch($_POST['frequence'])
1780  {
1781  case IL_CAL_FREQ_DAILY:
1782  $this->rec->setFrequenceType($_POST['frequence']);
1783  $this->rec->setInterval((int) $_POST['count_DAILY']);
1784  break;
1785 
1786  case IL_CAL_FREQ_WEEKLY:
1787  $this->rec->setFrequenceType($_POST['frequence']);
1788  $this->rec->setInterval((int) $_POST['count_WEEKLY']);
1789  if(is_array($_POST['byday_WEEKLY']))
1790  {
1791  $this->rec->setBYDAY(ilUtil::stripSlashes(implode(',',$_POST['byday_WEEKLY'])));
1792  }
1793  break;
1794 
1795  case IL_CAL_FREQ_MONTHLY:
1796  $this->rec->setFrequenceType($_POST['frequence']);
1797  $this->rec->setInterval((int) $_POST['count_MONTHLY']);
1798  switch((int) $_POST['subtype_MONTHLY'])
1799  {
1800  case 0:
1801  // nothing to do;
1802  break;
1803 
1804  case 1:
1805  switch((int) $_POST['monthly_byday_day'])
1806  {
1807  case 8:
1808  // Weekday
1809  $this->rec->setBYSETPOS((int) $_POST['monthly_byday_num']);
1810  $this->rec->setBYDAY('MO,TU,WE,TH,FR');
1811  break;
1812 
1813  case 9:
1814  // Day of month
1815  $this->rec->setBYMONTHDAY((int) $_POST['monthly_byday_num']);
1816  break;
1817 
1818  default:
1819  $this->rec->setBYDAY((int) $_POST['monthly_byday_num'].$_POST['monthly_byday_day']);
1820  break;
1821  }
1822  break;
1823 
1824  case 2:
1825  $this->rec->setBYMONTHDAY((int) $_POST['monthly_bymonthday']);
1826  break;
1827  }
1828  break;
1829 
1830  case IL_CAL_FREQ_YEARLY:
1831  $this->rec->setFrequenceType($_POST['frequence']);
1832  $this->rec->setInterval((int) $_POST['count_YEARLY']);
1833  switch((int) $_POST['subtype_YEARLY'])
1834  {
1835  case 0:
1836  // nothing to do;
1837  break;
1838 
1839  case 1:
1840  $this->rec->setBYMONTH((int) $_POST['yearly_bymonth_byday']);
1841  $this->rec->setBYDAY((int) $_POST['yearly_byday_num'].$_POST['yearly_byday']);
1842  break;
1843 
1844  case 2:
1845  $this->rec->setBYMONTH((int) $_POST['yearly_bymonth_by_monthday']);
1846  $this->rec->setBYMONTHDAY((int) $_POST['yearly_bymonthday']);
1847  break;
1848  }
1849  break;
1850  }
1851 
1852  // UNTIL
1853  $this->rec->setFrequenceUntilCount((int) $_POST['count']);
1854  }
1855 
1856 
1864  protected function __toUnix($date,$time)
1865  {
1866  return mktime($time['h'],$time['m'],0,$date['m'],$date['d'],$date['y']);
1867  }
1868 
1875  protected function formatPath($a_ref_id)
1876  {
1877  global $tree;
1878 
1879  $path = $this->lng->txt('path') . ': ';
1880  $first = true;
1881  foreach($tree->getPathFull($a_ref_id,$this->course_ref_id) as $node)
1882  {
1883  if($node['ref_id'] != $a_ref_id)
1884  {
1885  if(!$first)
1886  {
1887  $path .= ' -> ';
1888  }
1889  $first = false;
1890  $path .= $node['title'];
1891  }
1892  }
1893  return $path;
1894  }
1895 
1902  public function addLocatorItems()
1903  {
1904  global $ilLocator;
1905 
1906  if (is_object($this->object))
1907  {
1908  $ilLocator->addItem($this->object->getTitle(), $this->ctrl->getLinkTarget($this, "infoScreen"), "", $_GET["ref_id"]);
1909  }
1910  }
1911 
1918  public function getTabs($tabs_gui)
1919  {
1920  global $ilAccess,$ilTabs,$tree;
1921 
1922  $parent_id = $tree->getParentId($this->object->getRefId());
1923 
1924  $tabs_gui->setBackTarget($this->lng->txt('back_to_crs_content'),'repository.php?ref_id='.$parent_id);
1925  $tabs_gui->addTarget('info_short',
1926  $this->ctrl->getLinkTarget($this,'infoScreen'));
1927 
1928  if($ilAccess->checkAccess('write','',$this->object->getRefId()))
1929  {
1930  $tabs_gui->addTarget('edit_properties',
1931  $this->ctrl->getLinkTarget($this,'edit'));
1932  $tabs_gui->addTarget('crs_materials',
1933  $this->ctrl->getLinkTarget($this,'materials'));
1934  $tabs_gui->addTarget('event_edit_members',
1935  $this->ctrl->getLinkTarget($this,'members'));
1936  }
1937  // edit permissions
1938  if ($ilAccess->checkAccess('edit_permission', "", $this->object->getRefId()))
1939  {
1940  $tabs_gui->addTarget("perm_settings",
1941  $this->ctrl->getLinkTargetByClass("ilpermissiongui", "perm"), array("perm","info","owner"), 'ilpermissiongui');
1942  }
1943 
1944  }
1945 
1946 }
1947 ?>