ILIAS  eassessment Revision 61809
 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  protected $user_id;
41  protected $tpl;
42  protected $ctrl;
43  protected $lng;
44 
45  protected $editable = false;
46  protected $visible = false;
47 
55  public function __construct($a_user_id,$seed)
56  {
57  global $lng,$ilCtrl;
58 
59  $this->user_id = $a_user_id;
60  $this->seed = $seed;
61  $this->lng = $lng;
62  $this->lng->loadLanguageModule('dateplaner');
63  $this->ctrl = $ilCtrl;
64  }
65 
73  public function executeCommand()
74  {
75  global $ilUser, $ilSetting,$tpl;
76 
77  $next_class = $this->ctrl->getNextClass($this);
78  $this->ctrl->saveParameter($this,'category_id');
79  switch($next_class)
80  {
81  case 'ilcalendarappointmentgui':
82  $this->ctrl->setReturn($this,'details');
83 
84  include_once('./Services/Calendar/classes/class.ilCalendarAppointmentGUI.php');
85  $app = new ilCalendarAppointmentGUI($this->seed,$this->seed, (int) $_GET['app_id']);
86  $this->ctrl->forwardCommand($app);
87  break;
88 
89  default:
90  $cmd = $this->ctrl->getCmd("show");
91  $this->$cmd();
92  if(!in_array($cmd, array("details", "askDeleteAppointments", "deleteAppointments")))
93  {
94  return true;
95  }
96  }
97  return false;
98  }
99 
106  protected function cancel()
107  {
108  $this->ctrl->returnToParent($this);
109  }
110 
117  protected function add()
118  {
119  global $tpl, $ilTabs;
120 
121  $ilTabs->clearTargets();
122  $ilTabs->setBackTarget($this->lng->txt("cal_back_to_list"), $this->ctrl->getLinkTarget($this, "manage"));
123 
124  $this->tpl = new ilTemplate('tpl.edit_category.html',true,true,'Services/Calendar');
125  $this->initFormCategory('create');
126  $this->tpl->setVariable('EDIT_CAT',$this->form->getHTML());
127  $tpl->setContent($this->tpl->get());
128  }
129 
135  protected function save()
136  {
137  global $ilUser;
138 
139  include_once('./Services/Calendar/classes/class.ilCalendarCategory.php');
140  $category = new ilCalendarCategory(0);
141  $category->setTitle(ilUtil::stripSlashes($_POST['title']));
142  $category->setColor('#'.ilUtil::stripSlashes($_POST['color']));
143 
144  if(isset($_POST['type']) and $_POST['type'] == ilCalendarCategory::TYPE_GLOBAL)
145  {
146  $category->setType((int) $_POST['type']);
147  $category->setObjId(0);
148  }
149  else
150  {
151  $category->setType(ilCalendarCategory::TYPE_USR);
152  $category->setObjId($ilUser->getId());
153  }
154 
155  if(!$category->validate())
156  {
157  ilUtil::sendFailure($this->lng->txt('fill_out_all_required_fields'));
158  $this->add();
159  return false;
160  }
161  $category->add();
162 
163  ilUtil::sendSuccess($this->lng->txt('settings_saved'),true);
164  // $this->ctrl->returnToParent($this);
165  $this->manage();
166  }
167 
174  protected function edit()
175  {
176  global $tpl, $ilTabs;
177 
178  if(!$_GET['category_id'])
179  {
180  ilUtil::sendFailure($this->lng->txt('select_one'),true);
181  $this->ctrl->returnToParent($this);
182  }
183 
184  $this->readPermissions();
185  $this->checkVisible();
186 
187  if(!$this->isEditable())
188  {
189  ilUtil::sendFailure($this->lng->txt('permission_denied'));
190  $this->manage();
191  return false;
192  }
193 
194  $ilTabs->clearTargets();
195  $ilTabs->setBackTarget($this->lng->txt("cal_back_to_list"), $this->ctrl->getLinkTarget($this, "manage"));
196 
197  $this->initFormCategory('edit');
198  $tpl->setContent($this->form->getHTML());
199  }
200 
207  protected function details()
208  {
209  global $tpl;
210 
211  if(!$_GET['category_id'])
212  {
213  ilUtil::sendFailure($this->lng->txt('select_one'),true);
214  $this->ctrl->returnToParent($this);
215  }
216 
217  $this->readPermissions();
218  $this->checkVisible();
219 
220  $category = new ilCalendarCategory((int) $_GET['category_id']);
221  if(!in_array($category->getType(), array(ilCalendarCategory::TYPE_CH, ilCalendarCategory::TYPE_BOOK)))
222  {
223  include_once "./Services/UIComponent/Toolbar/classes/class.ilToolbarGUI.php";
224  $toolbar = new ilToolbarGui();
225  $toolbar->addButton($this->lng->txt("cal_add_appointment"), $this->ctrl->getLinkTargetByClass("ilcalendarappointmentgui", "add"));
226  $toolbar = $toolbar->getHTML();
227  }
228 
229  // Non editable category
230  include_once("./Services/InfoScreen/classes/class.ilInfoScreenGUI.php");
231  $info = new ilInfoScreenGUI($this);
232  $info->setFormAction($this->ctrl->getFormAction($this));
233 
234  $info->addSection($this->lng->txt('cal_cal_details'));
235 
236  // Calendar Name
237  $info->addProperty($this->lng->txt('cal_calendar_name'),$category->getTitle());
238  switch($category->getType())
239  {
241  $info->addProperty($this->lng->txt('cal_cal_type'),$this->lng->txt('cal_type_personal'));
242  break;
243 
245  $info->addProperty($this->lng->txt('cal_cal_type'),$this->lng->txt('cal_type_system'));
246  break;
247 
249  $info->addProperty($this->lng->txt('cal_cal_type'),$this->lng->txt('cal_type_'.$category->getObjType()));
250 
251  $info->addSection($this->lng->txt('additional_info'));
252  $info->addProperty($this->lng->txt('perma_link'),$this->addReferenceLinks($category->getObjId()));
253  break;
254 
257  // nothing to do
258  break;
259  }
260 
261  $tpl->setContent($toolbar.$info->getHTML().$this->showAssignedAppointments());
262  }
263 
270  protected function update()
271  {
272  if(!$_GET['category_id'])
273  {
274  ilUtil::sendFailure($this->lng->txt('select_one'),true);
275  $this->ctrl->returnToParent($this);
276  }
277  $this->readPermissions();
278  if(!$this->isEditable())
279  {
280  ilUtil::sendFailure($this->lng->txt('permission_denied'));
281  $this->edit();
282  return false;
283  }
284 
285  include_once('./Services/Calendar/classes/class.ilCalendarCategory.php');
286  $category = new ilCalendarCategory((int) $_GET['category_id']);
287  $category->setTitle(ilUtil::stripSlashes($_POST['title']));
288  $category->setColor('#'.ilUtil::stripSlashes($_POST['color']));
289  $category->update();
290 
291  ilUtil::sendSuccess($this->lng->txt('settings_saved'),true);
292  // $this->ctrl->returnToParent($this);
293  $this->manage();
294  }
295 
302  protected function confirmDelete()
303  {
304  global $tpl;
305 
306  if(!$_POST['selected_cat_ids'])
307  {
308  ilUtil::sendFailure($this->lng->txt('select_one'),true);
309  $this->manage();
310  }
311 
312  /*
313  $this->readPermissions();
314  if(!$this->isEditable())
315  {
316  ilUtil::sendFailure($this->lng->txt('permission_denied'));
317  $this->manage();
318  return false;
319  }
320  */
321 
322  include_once('./Services/Utilities/classes/class.ilConfirmationGUI.php');
323  $confirmation_gui = new ilConfirmationGUI();
324 
325  $confirmation_gui->setFormAction($this->ctrl->getFormAction($this));
326  $confirmation_gui->setHeaderText($this->lng->txt('cal_del_cal_sure'));
327  $confirmation_gui->setConfirm($this->lng->txt('delete'),'delete');
328  $confirmation_gui->setCancel($this->lng->txt('cancel'),'manage');
329 
330  include_once('./Services/Calendar/classes/class.ilCalendarCategory.php');
331  foreach($_POST['selected_cat_ids'] as $cat_id)
332  {
333  $category = new ilCalendarCategory((int)$cat_id);
334  $confirmation_gui->addItem('category_id[]',$cat_id,$category->getTitle());
335  }
336 
337  $tpl->setContent($confirmation_gui->getHTML());
338  }
339 
347  protected function delete()
348  {
349  global $ilCtrl;
350 
351  if(!$_POST['category_id'])
352  {
353  ilUtil::sendFailure($this->lng->txt('select_one'),true);
354  $this->manage();
355  }
356 
357  /*
358  $this->readPermissions();
359  if(!$this->isEditable())
360  {
361  ilUtil::sendFailure($this->lng->txt('permission_denied'));
362  $this->edit();
363  return false;
364  }
365  */
366 
367  include_once('./Services/Calendar/classes/class.ilCalendarCategory.php');
368  foreach($_POST['category_id'] as $cat_id)
369  {
370  $category = new ilCalendarCategory((int)$cat_id);
371  $category->delete();
372  }
373 
374  ilUtil::sendSuccess($this->lng->txt('cal_cal_deleted'), true);
375  $ilCtrl->redirect($this, 'manage');
376  }
377 
378 
379 
387  public function saveSelection()
388  {
389  global $ilUser;
390 
391  include_once('./Services/Calendar/classes/class.ilCalendarCategories.php');
392  include_once('./Services/Calendar/classes/class.ilCalendarHidden.php');
393 
394  $selected_cat_ids = $_POST['selected_cat_ids'] ? $_POST['selected_cat_ids'] : array();
395  $shown_cat_ids = $_POST['shown_cat_ids'] ? $_POST['shown_cat_ids'] : array();
396 
397  $cats = ilCalendarCategories::_getInstance($ilUser->getId());
398  $cat_ids = $cats->getCategories();
399 
400  $hidden_cats = ilCalendarHidden::_getInstanceByUserId($ilUser->getId());
401  $hidden_cat_ids = $hidden_cats->getHidden();
402 
403  $hidden = array();
404 
405  foreach($hidden_cat_ids as $hidden_cat_id)
406  {
407  if( !in_array($hidden_cat_id,$shown_cat_ids) )
408  {
409  $hidden[] = $hidden_cat_id;
410  }
411  }
412 
413  foreach($shown_cat_ids as $shown_cat_id)
414  {
415  $shown_cat_id = (int)$shown_cat_id;
416  if( !in_array($shown_cat_id, $selected_cat_ids) )
417  {
418  $hidden[] = $shown_cat_id;
419  }
420  }
421 
422  $hidden_categories = ilCalendarHidden::_getInstanceByUserId($this->user_id);
423  $hidden_categories->hideSelected($hidden);
424  $hidden_categories->save();
425 
426  ilUtil::sendSuccess($this->lng->txt('settings_saved'),true);
427  $this->ctrl->returnToParent($this);
428  }
429 
437  public function showCategories()
438  {
439  include_once('./Services/Calendar/classes/class.ilCalendarCategoryTableGUI.php');
440  $table_gui = new ilCalendarCategoryTableGUI($this);
441  $nav_parameter = $table_gui->getNavParameter();
442 
443  if($_POST[$nav_parameter] != "")
444  {
445  if($_POST[$nav_parameter."1"] != $_POST[$nav_parameter])
446  {
447  $nav_value = $_POST[$nav_parameter."1"];
448  }
449  elseif($_POST[$nav_parameter."2"] != $_POST[$nav_parameter])
450  {
451  $nav_value = $_POST[$nav_parameter."2"];
452  }
453  }
454  else
455  {
456  $nav_value = $_GET[$nav_parameter];
457  }
458 
459  $_SESSION[$nav_parameter] = $nav_value;
460 
461  $this->ctrl->returnToParent($this);
462  }
463 
471  public function shareSearch()
472  {
473  global $tpl, $ilTabs;
474 
475  if(!$_GET['category_id'])
476  {
477  ilUtil::sendFailure($this->lng->txt('select_one'),true);
478  $this->ctrl->returnToParent($this);
479  }
480 
481  $this->readPermissions();
482  if(!$this->isEditable())
483  {
484  ilUtil::sendFailure($this->lng->txt('permission_denied'));
485  $this->manage();
486  return false;
487  }
488 
489  $ilTabs->clearTargets();
490  $ilTabs->setBackTarget($this->lng->txt("cal_back_to_list"), $this->ctrl->getLinkTarget($this, "manage"));
491 
492  $_SESSION['cal_query'] = '';
493 
494  $this->ctrl->saveParameter($this,'category_id');
495  $this->initFormSearch();
496 
497  include_once('./Services/Calendar/classes/class.ilCalendarSharedListTableGUI.php');
498  $table = new ilCalendarSharedListTableGUI($this,'shareSearch');
499  $table->setTitle($this->lng->txt('cal_shared_header'));
500  $table->setCalendarId((int) $_GET['category_id']);
501  $table->parse();
502  $tpl->setContent($this->form->getHTML().$table->getHTML());
503  }
504 
511  public function sharePerformSearch()
512  {
513  global $ilTabs;
514 
515  $this->lng->loadLanguageModule('search');
516 
517  if(!$_GET['category_id'])
518  {
519  ilUtil::sendFailure($this->lng->txt('select_one'),true);
520  $this->ctrl->returnToParent($this);
521  }
522  $this->ctrl->saveParameter($this,'category_id');
523 
524 
525  if(!isset($_POST['query']))
526  {
527  $query = $_SESSION['cal_query'];
528  $type = $_SESSION['cal_type'];
529  }
530  elseif($_POST['query'])
531  {
532  $query = $_SESSION['cal_query'] = $_POST['query'];
533  $type = $_SESSION['cal_type'] = $_POST['query_type'];
534  }
535 
536  if(!$query)
537  {
538  ilUtil::sendFailure($this->lng->txt('msg_no_search_string'));
539  $this->shareSearch();
540  return false;
541  }
542 
543 
544  include_once 'Services/Search/classes/class.ilQueryParser.php';
545  include_once 'Services/Search/classes/class.ilObjectSearchFactory.php';
546  include_once 'Services/Search/classes/class.ilSearchResult.php';
547 
548  $res_sum = new ilSearchResult();
549 
550  $query_parser = new ilQueryParser(ilUtil::stripSlashes($query));
551  $query_parser->setCombination(QP_COMBINATION_OR);
552  $query_parser->setMinWordLength(3);
553  $query_parser->parse();
554 
555 
556  switch($type)
557  {
558  case self::SEARCH_USER:
559  $search = ilObjectSearchFactory::_getUserSearchInstance($query_parser);
560  $search->enableActiveCheck(true);
561 
562  $search->setFields(array('login'));
563  $res = $search->performSearch();
564  $res_sum->mergeEntries($res);
565 
566  $search->setFields(array('firstname'));
567  $res = $search->performSearch();
568  $res_sum->mergeEntries($res);
569 
570  $search->setFields(array('lastname'));
571  $res = $search->performSearch();
572  $res_sum->mergeEntries($res);
573 
574  $res_sum->filter(ROOT_FOLDER_ID,QP_COMBINATION_OR);
575  break;
576 
577  case self::SEARCH_ROLE:
578 
579  include_once 'Services/Search/classes/Like/class.ilLikeObjectSearch.php';
580  $search = new ilLikeObjectSearch($query_parser);
581  $search->setFilter(array('role'));
582 
583  $res = $search->performSearch();
584  $res_sum->mergeEntries($res);
585 
586  $res_sum->filter(ROOT_FOLDER_ID,QP_COMBINATION_OR);
587  break;
588  }
589 
590  if(!count($res_sum->getResults()))
591  {
592  ilUtil::sendFailure($this->lng->txt('search_no_match'));
593  $this->shareSearch();
594  return true;
595  }
596 
597  $ilTabs->clearTargets();
598  $ilTabs->setBackTarget($this->lng->txt("cal_back_to_search"), $this->ctrl->getLinkTarget($this, "shareSearch"));
599 
600  switch($type)
601  {
602  case self::SEARCH_USER:
603  $this->showUserList($res_sum->getResultIds());
604  break;
605 
606  case self::SEARCH_ROLE:
607  $this->showRoleList($res_sum->getResultIds());
608  break;
609  }
610  }
611 
618  public function shareAssign()
619  {
620  global $ilUser;
621 
622  if(!$_GET['category_id'])
623  {
624  ilUtil::sendFailure($this->lng->txt('select_one'),true);
625  $this->ctrl->returnToParent($this);
626  }
627  if(!count($_POST['user_ids']))
628  {
629  ilUtil::sendFailure($this->lng->txt('select_one'));
630  $this->sharePerformSearch();
631  return false;
632  }
633 
634  $this->readPermissions();
635  if(!$this->isEditable())
636  {
637  ilUtil::sendFailure($this->lng->txt('permission_denied'));
638  $this->shareSearch();
639  return false;
640  }
641 
642 
643  include_once('./Services/Calendar/classes/class.ilCalendarShared.php');
644  $shared = new ilCalendarShared((int) $_GET['category_id']);
645 
646  foreach($_POST['user_ids'] as $user_id)
647  {
648  if($ilUser->getId() != $user_id)
649  {
650  $shared->share($user_id,ilCalendarShared::TYPE_USR);
651  }
652  }
653  ilUtil::sendSuccess($this->lng->txt('cal_shared_selected_usr'));
654  $this->shareSearch();
655  }
656 
664  public function shareAssignRoles()
665  {
666  global $ilUser;
667 
668  if(!$_GET['category_id'])
669  {
670  ilUtil::sendFailure($this->lng->txt('select_one'),true);
671  $this->ctrl->returnToParent($this);
672  }
673  if(!count($_POST['role_ids']))
674  {
675  ilUtil::sendFailure($this->lng->txt('select_one'));
676  $this->sharePerformSearch();
677  return false;
678  }
679 
680  $this->readPermissions();
681  if(!$this->isEditable())
682  {
683  ilUtil::sendFailure($this->lng->txt('permission_denied'));
684  $this->shareSearch();
685  return false;
686  }
687 
688  include_once('./Services/Calendar/classes/class.ilCalendarShared.php');
689  $shared = new ilCalendarShared((int) $_GET['category_id']);
690 
691  foreach($_POST['role_ids'] as $role_id)
692  {
693  $shared->share($role_id,ilCalendarShared::TYPE_ROLE);
694  }
695  ilUtil::sendSuccess($this->lng->txt('cal_shared_selected_usr'));
696  $this->shareSearch();
697  }
698 
706  public function shareDeassign()
707  {
708  if(!$_GET['category_id'])
709  {
710  ilUtil::sendFailure($this->lng->txt('select_one'),true);
711  $this->ctrl->returnToParent($this);
712  }
713  if(!count($_POST['obj_ids']))
714  {
715  ilUtil::sendFailure($this->lng->txt('select_one'));
716  $this->shareSearch();
717  return false;
718  }
719 
720  $this->readPermissions();
721  if(!$this->isEditable())
722  {
723  ilUtil::sendFailure($this->lng->txt('permission_denied'));
724  $this->shareSearch();
725  return false;
726  }
727 
728 
729  include_once('./Services/Calendar/classes/class.ilCalendarShared.php');
730  $shared = new ilCalendarShared((int) $_GET['category_id']);
731 
732  foreach($_POST['obj_ids'] as $obj_id)
733  {
734  $shared->stopSharing($obj_id);
735  }
736  ilUtil::sendSuccess($this->lng->txt('cal_unshared_selected_usr'));
737  $this->shareSearch();
738  return true;
739  }
740 
741 
749  protected function showUserList($a_ids = array())
750  {
751  global $tpl;
752 
753  include_once('./Services/Calendar/classes/class.ilCalendarSharedUserListTableGUI.php');
754 
755  $table = new ilCalendarSharedUserListTableGUI($this,'sharePerformSearch');
756  $table->setTitle($this->lng->txt('cal_share_search_usr_header'));
757  $table->setFormAction($this->ctrl->getFormAction($this));
758  $table->setUsers($a_ids);
759  $table->parse();
760 
761  // $table->addCommandButton('shareSearch',$this->lng->txt('search_new'));
762  // $table->addCommandButton('manage',$this->lng->txt('cancel'));
763 
764  $tpl->setContent($table->getHTML());
765  }
766 
774  protected function showRoleList($a_ids = array())
775  {
776  global $tpl;
777 
778  include_once('./Services/Calendar/classes/class.ilCalendarSharedRoleListTableGUI.php');
779 
780  $table = new ilCalendarSharedRoleListTableGUI($this,'sharePerformSearch');
781  $table->setTitle($this->lng->txt('cal_share_search_role_header'));
782  $table->setFormAction($this->ctrl->getFormAction($this));
783  $table->setRoles($a_ids);
784  $table->parse();
785 
786  // $table->addCommandButton('shareSearch',$this->lng->txt('search_new'));
787  // $table->addCommandButton('manage',$this->lng->txt('cancel'));
788 
789  $tpl->setContent($table->getHTML());
790  }
791 
799  protected function initFormSearch()
800  {
801  global $lng;
802 
803  $lng->loadLanguageModule('search');
804 
805  if(!is_object($this->form))
806  {
807  include_once('Services/Form/classes/class.ilPropertyFormGUI.php');
808  $this->form = new ilPropertyFormGUI();
809  $this->form->setFormAction($this->ctrl->getFormAction($this));
810  $this->form->setTitle($this->lng->txt('cal_share_search_header'));
811  }
812 
813  $type = new ilRadioGroupInputGUI($this->lng->txt('search_type'),'query_type');
814  $type->setValue($_POST['query_type'] ? $_POST['query_type'] : self::SEARCH_USER);
815  $type->setRequired(true);
816 
817  $user = new ilRadioOption($this->lng->txt('obj_user'),self::SEARCH_USER);
818  $type->addOption($user);
819 
820  $role = new ilRadioOption($this->lng->txt('obj_role'),self::SEARCH_ROLE);
821  $type->addOption($role);
822 
823  $this->form->addItem($type);
824 
825  $search = new ilTextInputGUI($this->lng->txt('cal_search'),'query');
826  $search->setValue($_POST['query']);
827  $search->setSize(16);
828  $search->setMaxLength(128);
829  $search->setRequired(true);
830  $search->setInfo($this->lng->txt('cal_search_info_share'));
831 
832  $this->form->addItem($search);
833  $this->form->addCommandButton('sharePerformSearch',$this->lng->txt('search'));
834  // $this->form->addCommandButton('manage',$this->lng->txt('cancel'));
835  }
836 
843  protected function initFormCategory($a_mode)
844  {
845  global $rbacsystem,$ilUser;
846 
847  include_once('./Services/Form/classes/class.ilPropertyFormGUI.php');
848  include_once('./Services/Calendar/classes/class.ilCalendarCategory.php');
849 
850  include_once('./Services/Calendar/classes/class.ilCalendarCategories.php');
851  $cat_info = ilCalendarCategories::_getInstance()->getCategoryInfo((int) $_GET['category_id']);
852 
853  $this->form = new ilPropertyFormGUI();
854  $this->form->setTableWidth('40%');
855  switch($a_mode)
856  {
857  case 'edit':
858  $category = new ilCalendarCategory((int) $_GET['category_id']);
859  $this->form->setTitle($this->lng->txt('cal_edit_category'));
860  $this->ctrl->saveParameter($this,array('seed','category_id'));
861  $this->form->setFormAction($this->ctrl->getFormAction($this));
862  if($this->isEditable())
863  {
864  $this->form->addCommandButton('update',$this->lng->txt('save'));
865 
866  /*
867  if($cat_info['type'] == ilCalendarCategory::TYPE_USR)
868  {
869  $this->form->addCommandButton('shareSearch',$this->lng->txt('cal_share'));
870  }
871  $this->form->addCommandButton('confirmDelete',$this->lng->txt('delete'));
872  */
873 
874  $this->form->addCommandButton('manage',$this->lng->txt('cancel'));
875  }
876  break;
877  case 'create':
878  $this->editable = true;
879  $category = new ilCalendarCategory(0);
880  $this->ctrl->saveParameter($this,array('category_id'));
881  $this->form->setFormAction($this->ctrl->getFormAction($this));
882  $this->form->setTitle($this->lng->txt('cal_add_category'));
883  $this->form->addCommandButton('save',$this->lng->txt('save'));
884  $this->form->addCommandButton('manage',$this->lng->txt('cancel'));
885  break;
886  }
887 
888  // Calendar name
889  $title = new ilTextInputGUI($this->lng->txt('cal_calendar_name'),'title');
890  if($a_mode == 'edit')
891  {
892  $title->setDisabled(!$this->isEditable());
893  }
894  $title->setRequired(true);
895  $title->setMaxLength(64);
896  $title->setSize(32);
897  $title->setValue($category->getTitle());
898  $this->form->addItem($title);
899 
900 
901  include_once('./Services/Calendar/classes/class.ilCalendarSettings.php');
902  if($a_mode == 'create' and $rbacsystem->checkAccess('edit_event',ilCalendarSettings::_getInstance()->getCalendarSettingsId()))
903  {
904  $type = new ilRadioGroupInputGUI($this->lng->txt('cal_cal_type'),'type');
905  $type->setValue($category->getType());
906  $type->setRequired(true);
907 
908  $opt = new ilRadioOption($this->lng->txt('cal_type_personal'),ilCalendarCategory::TYPE_USR);
909  $type->addOption($opt);
910 
911  $opt = new ilRadioOption($this->lng->txt('cal_type_system'),ilCalendarCategory::TYPE_GLOBAL);
912  $type->addOption($opt);
913  $type->setInfo($this->lng->txt('cal_type_info'));
914  $this->form->addItem($type);
915  }
916 
917 
918  $color = new ilColorPickerInputGUI($this->lng->txt('cal_calendar_color'),'color');
919  $color->setValue($category->getColor());
920  if(!$this->isEditable())
921  {
922  $color->setDisabled(true);
923  }
924  $color->setRequired(true);
925  $this->form->addItem($color);
926  }
927 
931  protected function unshare()
932  {
933  global $ilUser;
934 
935  if(!$_GET['category_id'])
936  {
937  ilUtil::sendFailure($this->lng->txt('select_one'),true);
938  $this->ctrl->returnToParent($this);
939  }
940 
941  $this->readPermissions();
942  $this->checkVisible();
943 
944  include_once('./Services/Calendar/classes/class.ilCalendarSharedStatus.php');
945  $status = new ilCalendarSharedStatus($ilUser->getId());
946 
947  include_once('./Services/Calendar/classes/class.ilCalendarShared.php');
948  if(!ilCalendarShared::isSharedWithUser($ilUser->getId(), $_GET['category_id']))
949  {
950  ilUtil::sendFailure($this->lng->txt('permission_denied'));
951  $this->inbox();
952  return false;
953  }
954  $status->decline($_GET['category_id']);
955 
956  ilUtil::sendSuccess($this->lng->txt('settings_saved'), true);
957  $this->ctrl->redirect($this, 'manage');
958  }
959 
966  protected function showAssignedAppointments()
967  {
968  include_once('./Services/Calendar/classes/class.ilCalendarCategoryTableGUI.php');
969  include_once('./Services/Calendar/classes/class.ilCalendarCategoryAssignments.php');
970  include_once('./Services/Calendar/classes/class.ilCalendarAppointmentsTableGUI.php');
971 
972  $table_gui = new ilCalendarAppointmentsTableGUI($this, 'details', (int)$_GET['category_id']);
973  $table_gui->setTitle($this->lng->txt('cal_assigned_appointments'));
974  $table_gui->setAppointments(
976  ilCalendarCategories::_getInstance()->getSubitemCategories((int) $_GET['category_id'])));
977  return $table_gui->getHTML();
978  }
979 
986  protected function askDeleteAppointments()
987  {
988  global $tpl;
989 
990  if(!count($_POST['appointments']))
991  {
992  ilUtil::sendFailure($this->lng->txt('select_one'));
993  $this->details();
994  return true;
995  }
996 
997  include_once('./Services/Utilities/classes/class.ilConfirmationGUI.php');
998  $confirmation_gui = new ilConfirmationGUI();
999 
1000  $this->ctrl->setParameter($this,'category_id',(int) $_GET['category_id']);
1001  $confirmation_gui->setFormAction($this->ctrl->getFormAction($this));
1002  $confirmation_gui->setHeaderText($this->lng->txt('cal_del_app_sure'));
1003  $confirmation_gui->setConfirm($this->lng->txt('delete'),'deleteAppointments');
1004  $confirmation_gui->setCancel($this->lng->txt('cancel'),'details');
1005 
1006  include_once('./Services/Calendar/classes/class.ilCalendarEntry.php');
1007  foreach($_POST['appointments'] as $app_id)
1008  {
1009  $app = new ilCalendarEntry($app_id);
1010  $confirmation_gui->addItem('appointments[]',(int) $app_id,$app->getTitle());
1011  }
1012 
1013  $tpl->setContent($confirmation_gui->getHTML());
1014  }
1015 
1022  protected function deleteAppointments()
1023  {
1024  if(!count($_POST['appointments']))
1025  {
1026  ilUtil::sendFailure($this->lng->txt('select_one'));
1027  $this->details();
1028  return true;
1029  }
1030  include_once('./Services/Calendar/classes/class.ilCalendarEntry.php');
1031  foreach($_POST['appointments'] as $app_id)
1032  {
1033  $app = new ilCalendarEntry($app_id);
1034  $app->delete();
1035 
1036  include_once('./Services/Calendar/classes/class.ilCalendarCategoryAssignments.php');
1038  }
1039 
1040  ilUtil::sendSuccess($this->lng->txt('settings_saved'));
1041  $this->details();
1042  return true;
1043 
1044  }
1045 
1046  public function getHTML()
1047  {
1048  global $ilUser;
1049 
1050  /*
1051  include_once('./Services/Calendar/classes/class.ilCalendarCategories.php');
1052  include_once('./Services/Calendar/classes/class.ilCalendarHidden.php');
1053 
1054  $hidden_cats = ilCalendarHidden::_getInstanceByUserId($ilUser->getId());
1055  $visible_cats = ilCalendarCategories::_getInstance($ilUser->getId());
1056  $visible_cat_ids = implode(',',array_diff($visible_cats->getCategories(),$hidden_cats->getHidden()));
1057  */
1058 
1059 
1060  include_once('./Services/Calendar/classes/class.ilCalendarCategoryTableGUI.php');
1061  $table_gui = new ilCalendarCategoryTableGUI($this);
1062 
1063  $title = $this->lng->txt('cal_table_categories');
1064  $title .= $this->appendCalendarSelection();
1065 
1066  $table_gui->setTitle($title);
1067  $table_gui->addMultiCommand('saveSelection',$this->lng->txt('show'));
1068  // $table_gui->addCommandButton('add',$this->lng->txt('add'));
1069  $table_gui->parse();
1070 
1071  return $table_gui->getHTML();
1072  }
1073 
1074 
1080  protected function appendCalendarSelection()
1081  {
1082  global $ilUser;
1083 
1084  $this->lng->loadLanguageModule('pd');
1085 
1086  $tpl = new ilTemplate('tpl.calendar_selection.html',true,true,'Services/Calendar');
1087  include_once('./Services/Calendar/classes/class.ilCalendarUserSettings.php');
1088  switch(ilCalendarUserSettings::_getInstance()->getCalendarSelectionType())
1089  {
1091  $tpl->setVariable('HTEXT',$this->lng->txt('pd_my_memberships'));
1092  $tpl->touchBlock('head_item');
1093  $tpl->touchBlock('head_delim');
1094  $tpl->touchBlock('head_item');
1095 
1096  $this->ctrl->setParameter($this,'calendar_mode',ilCalendarUserSettings::CAL_SELECTION_ITEMS);
1097  $tpl->setVariable('HHREF',$this->ctrl->getLinkTarget($this,'switchCalendarMode'));
1098  $tpl->setVariable('HLINK',$this->lng->txt('pd_my_offers'));
1099  $tpl->touchBlock('head_item');
1100  break;
1101 
1103  $this->ctrl->setParameter($this,'calendar_mode',ilCalendarUserSettings::CAL_SELECTION_MEMBERSHIP);
1104  $tpl->setVariable('HHREF',$this->ctrl->getLinkTarget($this,'switchCalendarMode'));
1105  $tpl->setVariable('HLINK',$this->lng->txt('pd_my_memberships'));
1106  $tpl->touchBlock('head_item');
1107  $tpl->touchBlock('head_delim');
1108  $tpl->touchBlock('head_item');
1109 
1110  $tpl->setVariable('HTEXT',$this->lng->txt('pd_my_offers'));
1111  $tpl->touchBlock('head_item');
1112  break;
1113 
1114 
1115  }
1116  return $tpl->get();
1117  }
1118 
1123  protected function switchCalendarMode()
1124  {
1125  include_once('./Services/Calendar/classes/class.ilCalendarUserSettings.php');
1126  ilCalendarUserSettings::_getInstance()->setCalendarSelectionType((int) $_GET['calendar_mode']);
1128 
1129  $this->ctrl->returnToParent($this);
1130 
1131  }
1132 
1133 
1141  private function readPermissions()
1142  {
1143  global $ilUser,$rbacsystem,$ilAccess;
1144 
1145  $this->editable = false;
1146  $this->visible = false;
1147 
1148  include_once('./Services/Calendar/classes/class.ilCalendarShared.php');
1149 
1150  $shared = ilCalendarShared::getSharedCalendarsForUser($ilUser->getId());
1151  $cat = new ilCalendarCategory((int) $_GET['category_id']);
1152  switch($cat->getType())
1153  {
1155  if($cat->getObjId() == $ilUser->getId())
1156  {
1157  $this->visible = true;
1158  $this->editable = true;
1159  }
1160  elseif(isset($shared[$cat->getCategoryID()]))
1161  {
1162  $this->visible = true;
1163  }
1164  break;
1165 
1167  $this->editable = $rbacsystem->checkAccess('edit_event',ilCalendarSettings::_getInstance()->getCalendarSettingsId());
1168  $this->visible = true;
1169  break;
1170 
1172  $this->editable = false;
1173 
1174  $refs = ilObject::_getAllReferences($cat->getObjId());
1175  foreach($refs as $ref)
1176  {
1177  if($ilAccess->checkAccess('read','',$ref))
1178  {
1179  $this->visible = true;
1180  break;
1181  }
1182  }
1183  break;
1184 
1187  $this->editable = $ilUser->getId() == $cat->getCategoryID();
1188  $this->visible = true;
1189  break;
1190  }
1191 
1192  }
1193 
1199  protected function checkVisible()
1200  {
1201  global $ilErr;
1202 
1203  if(!$this->visible)
1204  {
1205  $ilErr->raiseError($this->lng->txt('permission_denied'),$ilErr->FATAL);
1206  }
1207  }
1208 
1214  private function isEditable()
1215  {
1216  return $this->editable;
1217  }
1218 
1224  protected function addReferenceLinks($a_obj_id)
1225  {
1226  global $tree;
1227 
1228  $tpl = new ilTemplate('tpl.cal_reference_links.html',true,true,'Services/Calendar');
1229 
1230  foreach(ilObject::_getAllReferences($a_obj_id) as $ref_id => $ref_id)
1231  {
1232  include_once('./classes/class.ilLink.php');
1233 
1234  $parent_ref_id = $tree->getParentId($ref_id);
1235  $parent_obj_id = ilObject::_lookupObjId($parent_ref_id);
1236  $parent_type = ilObject::_lookupType($parent_obj_id);
1237  $parent_title = ilObject::_lookupTitle($parent_obj_id);
1238 
1239  $type = ilObject::_lookupType($a_obj_id);
1240  $title = ilObject::_lookupTitle($a_obj_id);
1241 
1242  $tpl->setCurrentBlock('reference');
1243  $tpl->setVariable('PIMG_SRC',ilUtil::getTypeIconPath($parent_type,$parent_obj_id,'tiny'));
1244  $tpl->setVariable('PIMG_ALT',$this->lng->txt('obj_'.$parent_type));
1245  $tpl->setVariable('PARENT_TITLE',$parent_title);
1246  $tpl->setVariable('PARENT_HREF',ilLink::_getLink($parent_ref_id));
1247 
1248  $tpl->setVariable('SRC',ilUtil::getTypeIconPath($type,$a_obj_id,'tiny'));
1249  $tpl->setVariable('ALT',$this->lng->txt('obj_'.$type));
1250  $tpl->setVariable('TITLE',$title);
1251  $tpl->setVariable('HREF',ilLink::_getLink($ref_id));
1252  $tpl->parseCurrentBlock();
1253  }
1254  return $tpl->get();
1255  }
1256 
1257  protected function manage()
1258  {
1259  global $lng, $ilCtrl, $tpl;
1260 
1261  include_once('./Services/Calendar/classes/class.ilCalendarManageTableGUI.php');
1262  $table_gui = new ilCalendarManageTableGUI($this);
1263  $table_gui->parse();
1264 
1265  include_once "./Services/UIComponent/Toolbar/classes/class.ilToolbarGUI.php";
1266  $toolbar = new ilToolbarGui();
1267  $toolbar->addButton($lng->txt("add"), $ilCtrl->getLinkTarget($this, "add"));
1268 
1269  $tpl->setContent($toolbar->getHTML().$table_gui->getHTML());
1270  }
1271 }
1272 ?>