ILIAS  release_4-3 Revision
 All Data Structures Namespaces Files Functions Variables Groups Pages
class.ilCalendarCategoryGUI.php
Go to the documentation of this file.
1 <?php
2 /*
3  +-----------------------------------------------------------------------------+
4  | ILIAS open source |
5  +-----------------------------------------------------------------------------+
6  | Copyright (c) 1998-2006 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 
36 {
37  const SEARCH_USER = 1;
38  const SEARCH_ROLE = 2;
39 
40  const VIEW_MANAGE = 1;
41 
42  protected $user_id;
43  protected $tpl;
44  protected $ctrl;
45  protected $lng;
46 
47  protected $editable = false;
48  protected $visible = false;
49 
57  public function __construct($a_user_id,$seed)
58  {
59  global $lng,$ilCtrl;
60 
61  $this->user_id = $a_user_id;
62  $this->seed = $seed;
63  $this->lng = $lng;
64  $this->lng->loadLanguageModule('dateplaner');
65  $this->ctrl = $ilCtrl;
66  }
67 
75  public function executeCommand()
76  {
77  global $ilUser, $ilSetting,$tpl;
78 
79  $next_class = $this->ctrl->getNextClass($this);
80  $this->ctrl->saveParameter($this,'category_id');
81  $this->ctrl->setParameter($this,'seed',$this->seed->get(IL_CAL_DATE));
82  switch($next_class)
83  {
84  case 'ilcalendarappointmentgui':
85  $this->ctrl->setReturn($this,'details');
86 
87  include_once('./Services/Calendar/classes/class.ilCalendarAppointmentGUI.php');
88  $app = new ilCalendarAppointmentGUI($this->seed,$this->seed, (int) $_GET['app_id']);
89  $this->ctrl->forwardCommand($app);
90  break;
91 
92  default:
93  $cmd = $this->ctrl->getCmd("show");
94  $this->$cmd();
95  if(!in_array($cmd, array("details", "askDeleteAppointments", "deleteAppointments")))
96  {
97  return true;
98  }
99  }
100  return false;
101  }
102 
109  protected function cancel()
110  {
111  $this->ctrl->returnToParent($this);
112  }
113 
120  protected function add()
121  {
122  global $tpl, $ilTabs;
123 
124  $ilTabs->clearTargets();
125 
126  if($_REQUEST['backv'] == self::VIEW_MANAGE)
127  {
128  $back = 'manage';
129  }
130  else
131  {
132  $back = 'cancel';
133  }
134 
135  $ilTabs->setBackTarget($this->lng->txt("cal_back_to_list"), $this->ctrl->getLinkTarget($this, $back));
136 
137  $this->tpl = new ilTemplate('tpl.edit_category.html',true,true,'Services/Calendar');
138  $this->initFormCategory('create');
139  $this->tpl->setVariable('EDIT_CAT',$this->form->getHTML());
140  $tpl->setContent($this->tpl->get());
141  }
142 
148  protected function save()
149  {
150  global $ilUser;
151 
152  include_once('./Services/Calendar/classes/class.ilCalendarCategory.php');
153  $category = new ilCalendarCategory(0);
154  $category->setTitle(ilUtil::stripSlashes($_POST['title']));
155  $category->setColor('#'.ilUtil::stripSlashes($_POST['color']));
156  $category->setLocationType((int) $_POST['type_rl']);
157  $category->setRemoteUrl(ilUtil::stripSlashes($_POST['remote_url']));
158  $category->setRemoteUser(ilUtil::stripSlashes($_POST['remote_user']));
159  $category->setRemotePass(ilUtil::stripSlashes($_POST['remote_pass']));
160 
161  if(isset($_POST['type']) and $_POST['type'] == ilCalendarCategory::TYPE_GLOBAL)
162  {
163  $category->setType((int) $_POST['type']);
164  $category->setObjId(0);
165  }
166  else
167  {
168  $category->setType(ilCalendarCategory::TYPE_USR);
169  $category->setObjId($ilUser->getId());
170  }
171 
172  if(!$category->validate())
173  {
174  ilUtil::sendFailure($this->lng->txt('err_check_input'));
175  $this->add();
176  return false;
177  }
178  $category->add();
179 
180 
181  try {
182 
183  if($category->getLocationType() == ilCalendarCategory::LTYPE_REMOTE)
184  {
185  $this->doSynchronisation($category);
186  }
187  }
188  catch(Exception $e)
189  {
190  // Delete calendar if creation failed
191  $category->delete();
192  ilUtil::sendFailure($e->getMessage());
193  $this->manage();
194  return true;
195  }
196 
197  ilUtil::sendSuccess($this->lng->txt('settings_saved'),true);
198  // $this->ctrl->returnToParent($this);
199  $this->manage(true);
200  }
201 
208  protected function edit()
209  {
210  global $tpl, $ilTabs;
211 
212  if(!$_GET['category_id'])
213  {
214  ilUtil::sendFailure($this->lng->txt('select_one'),true);
215  $this->ctrl->returnToParent($this);
216  }
217 
218  $this->readPermissions();
219  $this->checkVisible();
220 
221  if(!$this->isEditable())
222  {
223  ilUtil::sendFailure($this->lng->txt('permission_denied'));
224  $this->manage();
225  return false;
226  }
227 
228  $ilTabs->clearTargets();
229  $ilTabs->setBackTarget($this->lng->txt("cal_back_to_list"), $this->ctrl->getLinkTarget($this, "manage"));
230 
231  $this->initFormCategory('edit');
232  $tpl->setContent($this->form->getHTML());
233  }
234 
241  protected function details()
242  {
243  global $tpl;
244 
245  if(!$_GET['category_id'])
246  {
247  ilUtil::sendFailure($this->lng->txt('select_one'),true);
248  $this->ctrl->returnToParent($this);
249  }
250 
251  $this->readPermissions();
252  $this->checkVisible();
253 
254  $category = new ilCalendarCategory((int) $_GET['category_id']);
255  if(!in_array($category->getType(), array(ilCalendarCategory::TYPE_CH, ilCalendarCategory::TYPE_BOOK)))
256  {
257  include_once "./Services/UIComponent/Toolbar/classes/class.ilToolbarGUI.php";
258  $toolbar = new ilToolbarGui();
259  $toolbar->addButton($this->lng->txt("cal_add_appointment"), $this->ctrl->getLinkTargetByClass("ilcalendarappointmentgui", "add"));
260 
261  if(!in_array($category->getType(), array(ilCalendarCategory::TYPE_CH, ilCalendarCategory::TYPE_BOOK)))
262  {
263  $toolbar->addButton($this->lng->txt("cal_import_appointments"), $this->ctrl->getLinkTarget($this, "importAppointments"));
264  }
265  $toolbar = $toolbar->getHTML();
266  }
267 
268  // Non editable category
269  include_once("./Services/InfoScreen/classes/class.ilInfoScreenGUI.php");
270  $info = new ilInfoScreenGUI($this);
271  $info->setFormAction($this->ctrl->getFormAction($this));
272 
273  $info->addSection($this->lng->txt('cal_cal_details'));
274 
275  // Calendar Name
276  $info->addProperty($this->lng->txt('cal_calendar_name'),$category->getTitle());
277  switch($category->getType())
278  {
280  $info->addProperty($this->lng->txt('cal_cal_type'),$this->lng->txt('cal_type_personal'));
281  break;
282 
284  $info->addProperty($this->lng->txt('cal_cal_type'),$this->lng->txt('cal_type_system'));
285  break;
286 
288  $info->addProperty($this->lng->txt('cal_cal_type'),$this->lng->txt('cal_type_'.$category->getObjType()));
289 
290  $info->addSection($this->lng->txt('additional_info'));
291  $info->addProperty($this->lng->txt('perma_link'),$this->addReferenceLinks($category->getObjId()));
292  break;
293 
296  // nothing to do
297  break;
298  }
299 
300  // Ical link
301  $this->ctrl->setParameterByClass('ilcalendarsubscriptiongui','cal_id',(int) $_GET['category_id']);
302  $info->addProperty(
303  $this->lng->txt('cal_ical_infoscreen'),
304  '<img src="'.ilUtil::getImagePath('ical.png','Services/Calendar').'" />',
305  $this->ctrl->getLinkTargetByClass(array('ilcalendarpresentationgui','ilcalendarsubscriptiongui'))
306  );
307 
308  $tpl->setContent($toolbar.$info->getHTML().$this->showAssignedAppointments());
309  }
310 
311  protected function synchroniseCalendar()
312  {
313  if(!$_GET['category_id'])
314  {
315  ilUtil::sendFailure($this->lng->txt('select_one'),true);
316  $this->ctrl->returnToParent($this);
317  }
318 
319  $category = new ilCalendarCategory((int) $_GET['category_id']);
320 
321  try {
322  $this->doSynchronisation($category);
323  }
324  catch(Exception $e) {
325  ilUtil::sendFailure($e->getMessage(),true);
326  $this->ctrl->redirect($this,'manage');
327  }
328  ilUtil::sendSuccess($this->lng->txt('cal_cal_sync_success'),true);
329  $this->ctrl->redirect($this,'manage');
330  }
331 
336  protected function doSynchronisation(ilCalendarCategory $category)
337  {
338  include_once './Services/Calendar/classes/class.ilCalendarRemoteReader.php';
339  $remote = new ilCalendarRemoteReader($category->getRemoteUrl());
340  $remote->setUser($category->getRemoteUser());
341  $remote->setPass($category->getRemotePass());
342  $remote->read();
343  $remote->import($category);
344  }
345 
352  protected function update()
353  {
354  if(!$_GET['category_id'])
355  {
356  ilUtil::sendFailure($this->lng->txt('select_one'),true);
357  $this->ctrl->returnToParent($this);
358  }
359  $this->readPermissions();
360  if(!$this->isEditable())
361  {
362  ilUtil::sendFailure($this->lng->txt('permission_denied'));
363  $this->edit();
364  return false;
365  }
366 
367  include_once('./Services/Calendar/classes/class.ilCalendarCategory.php');
368  $category = new ilCalendarCategory((int) $_GET['category_id']);
369  $category->setTitle(ilUtil::stripSlashes($_POST['title']));
370  $category->setColor('#'.ilUtil::stripSlashes($_POST['color']));
371  $category->update();
372 
373  ilUtil::sendSuccess($this->lng->txt('settings_saved'),true);
374  // $this->ctrl->returnToParent($this);
375  $this->manage();
376  }
377 
384  protected function confirmDelete()
385  {
386  global $tpl;
387 
388  if(!$_POST['selected_cat_ids'])
389  {
390  ilUtil::sendFailure($this->lng->txt('select_one'),true);
391  $this->manage();
392  }
393 
394  /*
395  $this->readPermissions();
396  if(!$this->isEditable())
397  {
398  ilUtil::sendFailure($this->lng->txt('permission_denied'));
399  $this->manage();
400  return false;
401  }
402  */
403 
404  include_once('./Services/Utilities/classes/class.ilConfirmationGUI.php');
405  $confirmation_gui = new ilConfirmationGUI();
406 
407  $confirmation_gui->setFormAction($this->ctrl->getFormAction($this));
408  $confirmation_gui->setHeaderText($this->lng->txt('cal_del_cal_sure'));
409  $confirmation_gui->setConfirm($this->lng->txt('delete'),'delete');
410  $confirmation_gui->setCancel($this->lng->txt('cancel'),'manage');
411 
412  include_once('./Services/Calendar/classes/class.ilCalendarCategory.php');
413  foreach($_POST['selected_cat_ids'] as $cat_id)
414  {
415  $category = new ilCalendarCategory((int)$cat_id);
416  $confirmation_gui->addItem('category_id[]',$cat_id,$category->getTitle());
417  }
418 
419  $tpl->setContent($confirmation_gui->getHTML());
420  }
421 
429  protected function delete()
430  {
431  global $ilCtrl;
432 
433  if(!$_POST['category_id'])
434  {
435  ilUtil::sendFailure($this->lng->txt('select_one'),true);
436  $this->manage();
437  }
438 
439  /*
440  $this->readPermissions();
441  if(!$this->isEditable())
442  {
443  ilUtil::sendFailure($this->lng->txt('permission_denied'));
444  $this->edit();
445  return false;
446  }
447  */
448 
449  include_once('./Services/Calendar/classes/class.ilCalendarCategory.php');
450  foreach($_POST['category_id'] as $cat_id)
451  {
452  $category = new ilCalendarCategory((int)$cat_id);
453  $category->delete();
454  }
455 
456  ilUtil::sendSuccess($this->lng->txt('cal_cal_deleted'), true);
457  $ilCtrl->redirect($this, 'manage');
458  }
459 
460 
461 
469  public function saveSelection()
470  {
471  global $ilUser;
472 
473  include_once('./Services/Calendar/classes/class.ilCalendarCategories.php');
474  include_once('./Services/Calendar/classes/class.ilCalendarHidden.php');
475 
476  $selected_cat_ids = $_POST['selected_cat_ids'] ? $_POST['selected_cat_ids'] : array();
477  $shown_cat_ids = $_POST['shown_cat_ids'] ? $_POST['shown_cat_ids'] : array();
478 
479  $cats = ilCalendarCategories::_getInstance($ilUser->getId());
480  $cat_ids = $cats->getCategories();
481 
482  $hidden_cats = ilCalendarHidden::_getInstanceByUserId($ilUser->getId());
483  $hidden_cat_ids = $hidden_cats->getHidden();
484 
485  $hidden = array();
486 
487  foreach($hidden_cat_ids as $hidden_cat_id)
488  {
489  if( !in_array($hidden_cat_id,$shown_cat_ids) )
490  {
491  $hidden[] = $hidden_cat_id;
492  }
493  }
494 
495  foreach($shown_cat_ids as $shown_cat_id)
496  {
497  $shown_cat_id = (int)$shown_cat_id;
498  if( !in_array($shown_cat_id, $selected_cat_ids) )
499  {
500  $hidden[] = $shown_cat_id;
501  }
502  }
503 
504  $hidden_categories = ilCalendarHidden::_getInstanceByUserId($this->user_id);
505  $hidden_categories->hideSelected($hidden);
506  $hidden_categories->save();
507 
508  ilUtil::sendSuccess($this->lng->txt('settings_saved'),true);
509  $this->ctrl->returnToParent($this);
510  }
511 
519  public function showCategories()
520  {
521  include_once('./Services/Calendar/classes/class.ilCalendarCategoryTableGUI.php');
522  $table_gui = new ilCalendarCategoryTableGUI($this,$this->seed);
523  $nav_parameter = $table_gui->getNavParameter();
524 
525  if($_POST[$nav_parameter] != "")
526  {
527  if($_POST[$nav_parameter."1"] != $_POST[$nav_parameter])
528  {
529  $nav_value = $_POST[$nav_parameter."1"];
530  }
531  elseif($_POST[$nav_parameter."2"] != $_POST[$nav_parameter])
532  {
533  $nav_value = $_POST[$nav_parameter."2"];
534  }
535  }
536  else
537  {
538  $nav_value = $_GET[$nav_parameter];
539  }
540 
541  $_SESSION[$nav_parameter] = $nav_value;
542 
543  $this->ctrl->returnToParent($this);
544  }
545 
553  public function shareSearch()
554  {
555  global $tpl, $ilTabs;
556 
557  if(!$_GET['category_id'])
558  {
559  ilUtil::sendFailure($this->lng->txt('select_one'),true);
560  $this->ctrl->returnToParent($this);
561  }
562 
563  $this->readPermissions();
564  if(!$this->isEditable())
565  {
566  ilUtil::sendFailure($this->lng->txt('permission_denied'));
567  $this->manage();
568  return false;
569  }
570 
571  $ilTabs->clearTargets();
572  $ilTabs->setBackTarget($this->lng->txt("cal_back_to_list"), $this->ctrl->getLinkTarget($this, "manage"));
573 
574  $_SESSION['cal_query'] = '';
575 
576  $this->ctrl->saveParameter($this,'category_id');
577  $this->initFormSearch();
578 
579  include_once('./Services/Calendar/classes/class.ilCalendarSharedListTableGUI.php');
580  $table = new ilCalendarSharedListTableGUI($this,'shareSearch');
581  $table->setTitle($this->lng->txt('cal_shared_header'));
582  $table->setCalendarId((int) $_GET['category_id']);
583  $table->parse();
584 
585  $tpl->setContent($this->form->getHTML().'<br />'.$table->getHTML());
586  }
587 
594  public function sharePerformSearch()
595  {
596  global $ilTabs;
597 
598  $this->lng->loadLanguageModule('search');
599 
600  if(!$_GET['category_id'])
601  {
602  ilUtil::sendFailure($this->lng->txt('select_one'),true);
603  $this->ctrl->returnToParent($this);
604  }
605  $this->ctrl->saveParameter($this,'category_id');
606 
607 
608  if(!isset($_POST['query']))
609  {
610  $query = $_SESSION['cal_query'];
611  $type = $_SESSION['cal_type'];
612  }
613  elseif($_POST['query'])
614  {
615  $query = $_SESSION['cal_query'] = $_POST['query'];
616  $type = $_SESSION['cal_type'] = $_POST['query_type'];
617  }
618 
619  if(!$query)
620  {
621  ilUtil::sendFailure($this->lng->txt('msg_no_search_string'));
622  $this->shareSearch();
623  return false;
624  }
625 
626 
627  include_once 'Services/Search/classes/class.ilQueryParser.php';
628  include_once 'Services/Search/classes/class.ilObjectSearchFactory.php';
629  include_once 'Services/Search/classes/class.ilSearchResult.php';
630 
631  $res_sum = new ilSearchResult();
632 
633  $query_parser = new ilQueryParser(ilUtil::stripSlashes($query));
634  $query_parser->setCombination(QP_COMBINATION_OR);
635  $query_parser->setMinWordLength(3);
636  $query_parser->parse();
637 
638 
639  switch($type)
640  {
641  case self::SEARCH_USER:
642  $search = ilObjectSearchFactory::_getUserSearchInstance($query_parser);
643  $search->enableActiveCheck(true);
644 
645  $search->setFields(array('login'));
646  $res = $search->performSearch();
647  $res_sum->mergeEntries($res);
648 
649  $search->setFields(array('firstname'));
650  $res = $search->performSearch();
651  $res_sum->mergeEntries($res);
652 
653  $search->setFields(array('lastname'));
654  $res = $search->performSearch();
655  $res_sum->mergeEntries($res);
656 
657  $res_sum->filter(ROOT_FOLDER_ID,QP_COMBINATION_OR);
658  break;
659 
660  case self::SEARCH_ROLE:
661 
662  include_once 'Services/Search/classes/Like/class.ilLikeObjectSearch.php';
663  $search = new ilLikeObjectSearch($query_parser);
664  $search->setFilter(array('role'));
665 
666  $res = $search->performSearch();
667  $res_sum->mergeEntries($res);
668 
669  $res_sum->filter(ROOT_FOLDER_ID,QP_COMBINATION_OR);
670  break;
671  }
672 
673  if(!count($res_sum->getResults()))
674  {
675  ilUtil::sendFailure($this->lng->txt('search_no_match'));
676  $this->shareSearch();
677  return true;
678  }
679 
680  $ilTabs->clearTargets();
681  $ilTabs->setBackTarget($this->lng->txt("cal_back_to_search"), $this->ctrl->getLinkTarget($this, "shareSearch"));
682 
683  switch($type)
684  {
685  case self::SEARCH_USER:
686  $this->showUserList($res_sum->getResultIds());
687  break;
688 
689  case self::SEARCH_ROLE:
690  $this->showRoleList($res_sum->getResultIds());
691  break;
692  }
693  }
694 
701  public function shareAssign()
702  {
703  global $ilUser;
704 
705  if(!$_GET['category_id'])
706  {
707  ilUtil::sendFailure($this->lng->txt('select_one'),true);
708  $this->ctrl->returnToParent($this);
709  }
710  if(!count($_POST['user_ids']))
711  {
712  ilUtil::sendFailure($this->lng->txt('select_one'));
713  $this->sharePerformSearch();
714  return false;
715  }
716 
717  $this->readPermissions();
718  if(!$this->isEditable())
719  {
720  ilUtil::sendFailure($this->lng->txt('permission_denied'));
721  $this->shareSearch();
722  return false;
723  }
724 
725 
726  include_once('./Services/Calendar/classes/class.ilCalendarShared.php');
727  $shared = new ilCalendarShared((int) $_GET['category_id']);
728 
729  foreach($_POST['user_ids'] as $user_id)
730  {
731  if($ilUser->getId() != $user_id)
732  {
733  $shared->share($user_id,ilCalendarShared::TYPE_USR);
734  }
735  }
736  ilUtil::sendSuccess($this->lng->txt('cal_shared_selected_usr'));
737  $this->shareSearch();
738  }
739 
747  public function shareAssignRoles()
748  {
749  global $ilUser;
750 
751  if(!$_GET['category_id'])
752  {
753  ilUtil::sendFailure($this->lng->txt('select_one'),true);
754  $this->ctrl->returnToParent($this);
755  }
756  if(!count($_POST['role_ids']))
757  {
758  ilUtil::sendFailure($this->lng->txt('select_one'));
759  $this->sharePerformSearch();
760  return false;
761  }
762 
763  $this->readPermissions();
764  if(!$this->isEditable())
765  {
766  ilUtil::sendFailure($this->lng->txt('permission_denied'));
767  $this->shareSearch();
768  return false;
769  }
770 
771  include_once('./Services/Calendar/classes/class.ilCalendarShared.php');
772  $shared = new ilCalendarShared((int) $_GET['category_id']);
773 
774  foreach($_POST['role_ids'] as $role_id)
775  {
776  $shared->share($role_id,ilCalendarShared::TYPE_ROLE);
777  }
778  ilUtil::sendSuccess($this->lng->txt('cal_shared_selected_usr'));
779  $this->shareSearch();
780  }
781 
789  public function shareDeassign()
790  {
791  if(!$_GET['category_id'])
792  {
793  ilUtil::sendFailure($this->lng->txt('select_one'),true);
794  $this->ctrl->returnToParent($this);
795  }
796  if(!count($_POST['obj_ids']))
797  {
798  ilUtil::sendFailure($this->lng->txt('select_one'));
799  $this->shareSearch();
800  return false;
801  }
802 
803  $this->readPermissions();
804  if(!$this->isEditable())
805  {
806  ilUtil::sendFailure($this->lng->txt('permission_denied'));
807  $this->shareSearch();
808  return false;
809  }
810 
811 
812  include_once('./Services/Calendar/classes/class.ilCalendarShared.php');
813  $shared = new ilCalendarShared((int) $_GET['category_id']);
814 
815  foreach($_POST['obj_ids'] as $obj_id)
816  {
817  $shared->stopSharing($obj_id);
818  }
819  ilUtil::sendSuccess($this->lng->txt('cal_unshared_selected_usr'));
820  $this->shareSearch();
821  return true;
822  }
823 
824 
832  protected function showUserList($a_ids = array())
833  {
834  global $tpl;
835 
836  include_once('./Services/Calendar/classes/class.ilCalendarSharedUserListTableGUI.php');
837 
838  $table = new ilCalendarSharedUserListTableGUI($this,'sharePerformSearch');
839  $table->setTitle($this->lng->txt('cal_share_search_usr_header'));
840  $table->setFormAction($this->ctrl->getFormAction($this));
841  $table->setUsers($a_ids);
842  $table->parse();
843 
844  // $table->addCommandButton('shareSearch',$this->lng->txt('search_new'));
845  // $table->addCommandButton('manage',$this->lng->txt('cancel'));
846 
847  $tpl->setContent($table->getHTML());
848  }
849 
857  protected function showRoleList($a_ids = array())
858  {
859  global $tpl;
860 
861  include_once('./Services/Calendar/classes/class.ilCalendarSharedRoleListTableGUI.php');
862 
863  $table = new ilCalendarSharedRoleListTableGUI($this,'sharePerformSearch');
864  $table->setTitle($this->lng->txt('cal_share_search_role_header'));
865  $table->setFormAction($this->ctrl->getFormAction($this));
866  $table->setRoles($a_ids);
867  $table->parse();
868 
869  // $table->addCommandButton('shareSearch',$this->lng->txt('search_new'));
870  // $table->addCommandButton('manage',$this->lng->txt('cancel'));
871 
872  $tpl->setContent($table->getHTML());
873  }
874 
882  protected function initFormSearch()
883  {
884  global $lng;
885 
886  $lng->loadLanguageModule('search');
887 
888  if(!is_object($this->form))
889  {
890  include_once('Services/Form/classes/class.ilPropertyFormGUI.php');
891  $this->form = new ilPropertyFormGUI();
892  $this->form->setFormAction($this->ctrl->getFormAction($this));
893  $this->form->setTitle($this->lng->txt('cal_share_search_header'));
894  }
895 
896  $type = new ilRadioGroupInputGUI($this->lng->txt('search_type'),'query_type');
897  $type->setValue($_POST['query_type'] ? $_POST['query_type'] : self::SEARCH_USER);
898  $type->setRequired(true);
899 
900  $user = new ilRadioOption($this->lng->txt('obj_user'),self::SEARCH_USER);
901  $type->addOption($user);
902 
903  $role = new ilRadioOption($this->lng->txt('obj_role'),self::SEARCH_ROLE);
904  $type->addOption($role);
905 
906  $this->form->addItem($type);
907 
908  $search = new ilTextInputGUI($this->lng->txt('cal_search'),'query');
909  $search->setValue($_POST['query']);
910  $search->setSize(16);
911  $search->setMaxLength(128);
912  $search->setRequired(true);
913  $search->setInfo($this->lng->txt('cal_search_info_share'));
914 
915  $this->form->addItem($search);
916  $this->form->addCommandButton('sharePerformSearch',$this->lng->txt('search'));
917  // $this->form->addCommandButton('manage',$this->lng->txt('cancel'));
918  }
919 
926  protected function initFormCategory($a_mode)
927  {
928  global $rbacsystem,$ilUser;
929 
930  include_once('./Services/Form/classes/class.ilPropertyFormGUI.php');
931  include_once('./Services/Calendar/classes/class.ilCalendarCategory.php');
932 
933  include_once('./Services/Calendar/classes/class.ilCalendarCategories.php');
934  $cat_info = ilCalendarCategories::_getInstance()->getCategoryInfo((int) $_GET['category_id']);
935 
936  $this->form = new ilPropertyFormGUI();
937  #$this->form->setTableWidth('40%');
938  switch($a_mode)
939  {
940  case 'edit':
941  $category = new ilCalendarCategory((int) $_GET['category_id']);
942  $this->form->setTitle($this->lng->txt('cal_edit_category'));
943  $this->ctrl->saveParameter($this,array('seed','category_id'));
944  $this->form->setFormAction($this->ctrl->getFormAction($this));
945  if($this->isEditable())
946  {
947  $this->form->addCommandButton('update',$this->lng->txt('save'));
948 
949  /*
950  if($cat_info['type'] == ilCalendarCategory::TYPE_USR)
951  {
952  $this->form->addCommandButton('shareSearch',$this->lng->txt('cal_share'));
953  }
954  $this->form->addCommandButton('confirmDelete',$this->lng->txt('delete'));
955  */
956 
957  $this->form->addCommandButton('manage',$this->lng->txt('cancel'));
958  }
959  break;
960  case 'create':
961  $this->editable = true;
962  $category = new ilCalendarCategory(0);
963  $this->ctrl->saveParameter($this,array('category_id'));
964  $this->form->setFormAction($this->ctrl->getFormAction($this));
965  $this->form->setTitle($this->lng->txt('cal_add_category'));
966  $this->form->addCommandButton('save',$this->lng->txt('save'));
967  $this->form->addCommandButton('manage',$this->lng->txt('cancel'));
968  break;
969  }
970 
971  // Calendar name
972  $title = new ilTextInputGUI($this->lng->txt('cal_calendar_name'),'title');
973  if($a_mode == 'edit')
974  {
975  $title->setDisabled(!$this->isEditable());
976  }
977  $title->setRequired(true);
978  $title->setMaxLength(64);
979  $title->setSize(32);
980  $title->setValue($category->getTitle());
981  $this->form->addItem($title);
982 
983 
984  include_once('./Services/Calendar/classes/class.ilCalendarSettings.php');
985  if($a_mode == 'create' and $rbacsystem->checkAccess('edit_event',ilCalendarSettings::_getInstance()->getCalendarSettingsId()))
986  {
987  $type = new ilRadioGroupInputGUI($this->lng->txt('cal_cal_type'),'type');
988  $type->setValue($category->getType());
989  $type->setRequired(true);
990 
991  $opt = new ilRadioOption($this->lng->txt('cal_type_personal'),ilCalendarCategory::TYPE_USR);
992  $type->addOption($opt);
993 
994  $opt = new ilRadioOption($this->lng->txt('cal_type_system'),ilCalendarCategory::TYPE_GLOBAL);
995  $type->addOption($opt);
996  $type->setInfo($this->lng->txt('cal_type_info'));
997  $this->form->addItem($type);
998  }
999 
1000 
1001  $color = new ilColorPickerInputGUI($this->lng->txt('cal_calendar_color'),'color');
1002  $color->setValue($category->getColor());
1003  if(!$this->isEditable())
1004  {
1005  $color->setDisabled(true);
1006  }
1007  $color->setRequired(true);
1008  $this->form->addItem($color);
1009 
1010  $location = new ilRadioGroupInputGUI($this->lng->txt('cal_type_rl'), 'type_rl');
1011  $location->setDisabled($a_mode == 'edit');
1012  $location_local = new ilRadioOption($this->lng->txt('cal_type_local'), ilCalendarCategory::LTYPE_LOCAL);
1013  $location->addOption($location_local);
1014  $location_remote = new ilRadioOption($this->lng->txt('cal_type_remote'), ilCalendarCategory::LTYPE_REMOTE);
1015  $location->addOption($location_remote);
1016  $location->setValue($category->getLocationType());
1017 
1018 
1019  $url = new ilTextInputGUI($this->lng->txt('cal_remote_url'), 'remote_url');
1020  $url->setDisabled($a_mode == 'edit');
1021  $url->setValue($category->getRemoteUrl());
1022  $url->setMaxLength(500);
1023  $url->setSize(60);
1024  $url->setRequired(true);
1025  $location_remote->addSubItem($url);
1026 
1027  $user = new ilTextInputGUI($this->lng->txt('username'),'remote_user');
1028  $user->setDisabled($a_mode == 'edit');
1029  $user->setValue($category->getRemoteUser());
1030  $user->setMaxLength(50);
1031  $user->setSize(20);
1032  $user->setRequired(false);
1033  $location_remote->addSubItem($user);
1034 
1035  $pass = new ilPasswordInputGUI($this->lng->txt('password'),'remote_pass');
1036  $pass->setDisabled($a_mode == 'edit');
1037  $pass->setValue($category->getRemotePass());
1038  $pass->setMaxLength(50);
1039  $pass->setSize(20);
1040  $pass->setRetype(false);
1041  $pass->setInfo($this->lng->txt('remote_pass_info'));
1042  $location_remote->addSubItem($pass);
1043 
1044  $this->form->addItem($location);
1045 
1046  }
1047 
1051  protected function unshare()
1052  {
1053  global $ilUser;
1054 
1055  if(!$_GET['category_id'])
1056  {
1057  ilUtil::sendFailure($this->lng->txt('select_one'),true);
1058  $this->ctrl->returnToParent($this);
1059  }
1060 
1061  $this->readPermissions();
1062  $this->checkVisible();
1063 
1064  include_once('./Services/Calendar/classes/class.ilCalendarSharedStatus.php');
1065  $status = new ilCalendarSharedStatus($ilUser->getId());
1066 
1067  include_once('./Services/Calendar/classes/class.ilCalendarShared.php');
1068  if(!ilCalendarShared::isSharedWithUser($ilUser->getId(), $_GET['category_id']))
1069  {
1070  ilUtil::sendFailure($this->lng->txt('permission_denied'));
1071  $this->inbox();
1072  return false;
1073  }
1074  $status->decline($_GET['category_id']);
1075 
1076  ilUtil::sendSuccess($this->lng->txt('settings_saved'), true);
1077  $this->ctrl->redirect($this, 'manage');
1078  }
1079 
1086  protected function showAssignedAppointments()
1087  {
1088  include_once('./Services/Calendar/classes/class.ilCalendarCategoryTableGUI.php');
1089  include_once('./Services/Calendar/classes/class.ilCalendarCategoryAssignments.php');
1090  include_once('./Services/Calendar/classes/class.ilCalendarAppointmentsTableGUI.php');
1091 
1092  $table_gui = new ilCalendarAppointmentsTableGUI($this, 'details', (int)$_GET['category_id']);
1093  $table_gui->setTitle($this->lng->txt('cal_assigned_appointments'));
1094  $table_gui->setAppointments(
1096  ilCalendarCategories::_getInstance()->getSubitemCategories((int) $_GET['category_id'])));
1097  return $table_gui->getHTML();
1098  }
1099 
1106  protected function askDeleteAppointments()
1107  {
1108  global $tpl;
1109 
1110  if(!count($_POST['appointments']))
1111  {
1112  ilUtil::sendFailure($this->lng->txt('select_one'));
1113  $this->details();
1114  return true;
1115  }
1116 
1117  include_once('./Services/Utilities/classes/class.ilConfirmationGUI.php');
1118  $confirmation_gui = new ilConfirmationGUI();
1119 
1120  $this->ctrl->setParameter($this,'category_id',(int) $_GET['category_id']);
1121  $confirmation_gui->setFormAction($this->ctrl->getFormAction($this));
1122  $confirmation_gui->setHeaderText($this->lng->txt('cal_del_app_sure'));
1123  $confirmation_gui->setConfirm($this->lng->txt('delete'),'deleteAppointments');
1124  $confirmation_gui->setCancel($this->lng->txt('cancel'),'details');
1125 
1126  include_once('./Services/Calendar/classes/class.ilCalendarEntry.php');
1127  foreach($_POST['appointments'] as $app_id)
1128  {
1129  $app = new ilCalendarEntry($app_id);
1130  $confirmation_gui->addItem('appointments[]',(int) $app_id,$app->getTitle());
1131  }
1132 
1133  $tpl->setContent($confirmation_gui->getHTML());
1134  }
1135 
1142  protected function deleteAppointments()
1143  {
1144  if(!count($_POST['appointments']))
1145  {
1146  ilUtil::sendFailure($this->lng->txt('select_one'));
1147  $this->details();
1148  return true;
1149  }
1150  include_once('./Services/Calendar/classes/class.ilCalendarEntry.php');
1151  foreach($_POST['appointments'] as $app_id)
1152  {
1153  $app = new ilCalendarEntry($app_id);
1154  $app->delete();
1155 
1156  include_once('./Services/Calendar/classes/class.ilCalendarCategoryAssignments.php');
1158  }
1159 
1160  ilUtil::sendSuccess($this->lng->txt('settings_saved'));
1161  $this->details();
1162  return true;
1163 
1164  }
1165 
1166  public function getHTML()
1167  {
1168  global $ilUser, $ilCtrl;
1169 
1170  include_once("./Services/Calendar/classes/class.ilCalendarSelectionBlockGUI.php");
1171  $block_gui = new ilCalendarSelectionBlockGUI($this->seed);
1172  $html = $ilCtrl->getHTML($block_gui);
1173  return $html;
1174  }
1175 
1176 
1182  protected function appendCalendarSelection()
1183  {
1184  global $ilUser;
1185 
1186  $this->lng->loadLanguageModule('pd');
1187 
1188  $tpl = new ilTemplate('tpl.calendar_selection.html',true,true,'Services/Calendar');
1189  include_once('./Services/Calendar/classes/class.ilCalendarUserSettings.php');
1190  switch(ilCalendarUserSettings::_getInstance()->getCalendarSelectionType())
1191  {
1193  $tpl->setVariable('HTEXT',$this->lng->txt('pd_my_memberships'));
1194  $tpl->touchBlock('head_item');
1195  $tpl->touchBlock('head_delim');
1196  $tpl->touchBlock('head_item');
1197 
1198  $this->ctrl->setParameter($this,'calendar_mode',ilCalendarUserSettings::CAL_SELECTION_ITEMS);
1199  $this->ctrl->setParameter($this,'seed',$this->seed->get(IL_CAL_DATE));
1200  $tpl->setVariable('HHREF',$this->ctrl->getLinkTarget($this,'switchCalendarMode'));
1201  $tpl->setVariable('HLINK',$this->lng->txt('pd_my_offers'));
1202  $tpl->touchBlock('head_item');
1203  break;
1204 
1206  $this->ctrl->setParameter($this,'calendar_mode',ilCalendarUserSettings::CAL_SELECTION_MEMBERSHIP);
1207  $this->ctrl->setParameter($this,'seed',$this->seed->get(IL_CAL_DATE));
1208  $tpl->setVariable('HHREF',$this->ctrl->getLinkTarget($this,'switchCalendarMode'));
1209  $tpl->setVariable('HLINK',$this->lng->txt('pd_my_memberships'));
1210  $tpl->touchBlock('head_item');
1211  $tpl->touchBlock('head_delim');
1212  $tpl->touchBlock('head_item');
1213 
1214  $tpl->setVariable('HTEXT',$this->lng->txt('pd_my_offers'));
1215  $tpl->touchBlock('head_item');
1216  break;
1217 
1218 
1219  }
1220  return $tpl->get();
1221  }
1222 
1227  protected function switchCalendarMode()
1228  {
1229  include_once('./Services/Calendar/classes/class.ilCalendarUserSettings.php');
1230  ilCalendarUserSettings::_getInstance()->setCalendarSelectionType((int) $_GET['calendar_mode']);
1232 
1233  $this->ctrl->returnToParent($this);
1234 
1235  }
1236 
1237 
1245  private function readPermissions()
1246  {
1247  global $ilUser,$rbacsystem,$ilAccess;
1248 
1249  $this->editable = false;
1250  $this->visible = false;
1251  $this->importable = false;
1252 
1253  include_once('./Services/Calendar/classes/class.ilCalendarShared.php');
1254 
1255  $shared = ilCalendarShared::getSharedCalendarsForUser($ilUser->getId());
1256  $cat = new ilCalendarCategory((int) $_GET['category_id']);
1257 
1258  switch($cat->getType())
1259  {
1261 
1262  if($cat->getObjId() == $ilUser->getId())
1263  {
1264  $this->visible = true;
1265  $this->editable = true;
1266  $this->importable = true;
1267  }
1268  elseif(isset($shared[$cat->getCategoryID()]))
1269  {
1270  $this->visible = true;
1271  }
1272  break;
1273 
1275  $this->importable = $this->editable = $rbacsystem->checkAccess('edit_event',ilCalendarSettings::_getInstance()->getCalendarSettingsId());
1276  $this->visible = true;
1277  break;
1278 
1280  $this->editable = false;
1281 
1282  $refs = ilObject::_getAllReferences($cat->getObjId());
1283  foreach($refs as $ref)
1284  {
1285  if($ilAccess->checkAccess('read','',$ref))
1286  {
1287  $this->visible = true;
1288  }
1289  if($ilAccess->checkAccess('edit_event','',$ref))
1290  {
1291  $this->importable = true;
1292  }
1293  }
1294  break;
1295 
1298  $this->editable = $ilUser->getId() == $cat->getCategoryID();
1299  $this->visible = true;
1300  $this->importable = false;
1301  break;
1302  }
1303 
1304  }
1305 
1311  protected function checkVisible()
1312  {
1313  global $ilErr;
1314 
1315  if(!$this->visible)
1316  {
1317  $ilErr->raiseError($this->lng->txt('permission_denied'),$ilErr->FATAL);
1318  }
1319  }
1320 
1326  private function isEditable()
1327  {
1328  return $this->editable;
1329  }
1330 
1331  protected function isImportable()
1332  {
1333  return $this->importable;
1334  }
1335 
1336 
1342  protected function addReferenceLinks($a_obj_id)
1343  {
1344  global $tree;
1345 
1346  $tpl = new ilTemplate('tpl.cal_reference_links.html',true,true,'Services/Calendar');
1347 
1348  foreach(ilObject::_getAllReferences($a_obj_id) as $ref_id => $ref_id)
1349  {
1350  include_once('./Services/Link/classes/class.ilLink.php');
1351 
1352  $parent_ref_id = $tree->getParentId($ref_id);
1353  $parent_obj_id = ilObject::_lookupObjId($parent_ref_id);
1354  $parent_type = ilObject::_lookupType($parent_obj_id);
1355  $parent_title = ilObject::_lookupTitle($parent_obj_id);
1356 
1357  $type = ilObject::_lookupType($a_obj_id);
1358  $title = ilObject::_lookupTitle($a_obj_id);
1359 
1360  $tpl->setCurrentBlock('reference');
1361  $tpl->setVariable('PIMG_SRC',ilUtil::getTypeIconPath($parent_type,$parent_obj_id,'tiny'));
1362  $tpl->setVariable('PIMG_ALT',$this->lng->txt('obj_'.$parent_type));
1363  $tpl->setVariable('PARENT_TITLE',$parent_title);
1364  $tpl->setVariable('PARENT_HREF',ilLink::_getLink($parent_ref_id));
1365 
1366  $tpl->setVariable('SRC',ilUtil::getTypeIconPath($type,$a_obj_id,'tiny'));
1367  $tpl->setVariable('ALT',$this->lng->txt('obj_'.$type));
1368  $tpl->setVariable('TITLE',$title);
1369  $tpl->setVariable('HREF',ilLink::_getLink($ref_id));
1370  $tpl->parseCurrentBlock();
1371  }
1372  return $tpl->get();
1373  }
1374 
1381  protected function manage($a_reset_offsets = false)
1382  {
1383  global $lng, $ilCtrl, $tpl;
1384 
1385  include_once('./Services/Calendar/classes/class.ilCalendarManageTableGUI.php');
1386  $table_gui = new ilCalendarManageTableGUI($this);
1387 
1388  if($a_reset_offsets)
1389  {
1390  $table_gui->resetToDefaults();
1391  }
1392 
1393  $table_gui->parse();
1394 
1395  include_once "./Services/UIComponent/Toolbar/classes/class.ilToolbarGUI.php";
1396  $toolbar = new ilToolbarGui();
1397  $ilCtrl->setParameter($this,'backv',self::VIEW_MANAGE);
1398  $toolbar->addButton($lng->txt("cal_add_calendar"), $ilCtrl->getLinkTarget($this, "add"));
1399 
1400  $tpl->setContent($toolbar->getHTML().$table_gui->getHTML());
1401  }
1402 
1406  protected function importAppointments(ilPropertyFormGUI $form = null)
1407  {
1408  global $ilTabs, $tpl;
1409 
1410  if(!$_GET['category_id'])
1411  {
1412  ilUtil::sendFailure($this->lng->txt('select_one'),true);
1413  $this->ctrl->returnToParent($this);
1414  }
1415 
1416  $this->ctrl->setParameter($this,'category_id',(int) $_GET['category_id']);
1417 
1418  // Check permissions
1419  $this->readPermissions();
1420  $this->checkVisible();
1421 
1422  if(!$this->isImportable())
1423  {
1424  ilUtil::sendFailure($this->lng->txt('permission_denied'));
1425  $this->manage();
1426  return false;
1427  }
1428 
1429  $ilTabs->clearTargets();
1430  $ilTabs->setBackTarget($this->lng->txt("cal_back_to_list"), $this->ctrl->getLinkTarget($this, "manage"));
1431 
1432 
1433  if(!$form instanceof ilPropertyFormGUI)
1434  {
1435  $form = $this->initImportForm();
1436  }
1437  $tpl->setContent($form->getHTML());
1438  }
1439 
1443  protected function initImportForm()
1444  {
1445  include_once './Services/Form/classes/class.ilPropertyFormGUI.php';
1446  $form = new ilPropertyFormGUI();
1447  $form->setTitle($this->lng->txt('cal_import_tbl'));
1448  $form->setFormAction($this->ctrl->getFormAction($this));
1449 
1450  $form->addCommandButton('uploadAppointments',$this->lng->txt('import'));
1451 
1452  $ics = new ilFileInputGUI($this->lng->txt('cal_import_file'), 'file');
1453  $ics->setALlowDeletion(false);
1454  $ics->setSuffixes(array('ics'));
1455  $ics->setInfo($this->lng->txt('cal_import_file_info'));
1456  $form->addItem($ics);
1457 
1458  return $form;
1459  }
1460 
1464  protected function uploadAppointments()
1465  {
1466  // @todo permission check
1467 
1468  $form = $this->initImportForm();
1469  if($form->checkInput())
1470  {
1471  $file = $form->getInput('file');
1472  $tmp = ilUtil::ilTempnam();
1473 
1474  ilUtil::moveUploadedFile($file['tmp_name'], $file['name'], $tmp);
1475 
1476  $num = $this->doImportFile($tmp, (int) $_REQUEST['category_id']);
1477 
1478  ilUtil::sendSuccess(sprintf($this->lng->txt('cal_imported_success'), (int) $num),true);
1479  $this->ctrl->redirect($this,'manage');
1480  }
1481 
1482  ilUtil::sendFailure($this->lng->txt('cal_err_file_upload'),true);
1483  $this->initImportForm($form);
1484  }
1485 
1491  protected function doImportFile($file, $category_id)
1492  {
1493  include_once './Services/Calendar/classes/../classes/iCal/class.ilICalParser.php';
1494  include_once './Services/Calendar/classes/class.ilCalendarCategoryAssignments.php';
1495 
1496  $GLOBALS['ilLog']->write(__METHOD__.': Starting ical import...');
1497 
1498  $assigned_before = ilCalendarCategoryAssignments::lookupNumberOfAssignedAppointments(array($category_id));
1499 
1501  $parser->setCategoryId($category_id);
1502  $parser->parse();
1503 
1504  $assigned_after = ilCalendarCategoryAssignments::lookupNumberOfAssignedAppointments(array($category_id));
1505 
1506  return $assigned_after - $assigned_before;
1507  }
1508 }
1509 ?>