ILIAS  Release_4_4_x_branch Revision 61816
 All Data Structures Namespaces Files Functions Variables Groups Pages
class.ilCalendarInboxGUI.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 
24 include_once('Services/Calendar/classes/class.ilDate.php');
25 include_once('Services/Calendar/classes/class.ilCalendarHeaderNavigationGUI.php');
26 include_once('Services/Calendar/classes/class.ilCalendarUserSettings.php');
27 include_once('Services/Calendar/classes/class.ilCalendarAppointmentColors.php');
28 include_once('./Services/Calendar/classes/class.ilCalendarSchedule.php');
29 
30 
31 
42 {
43  protected $seed = null;
44  protected $user_settings = null;
45 
46  protected $lng;
47  protected $ctrl;
48  protected $tabs_gui;
49  protected $tpl;
50 
51  protected $timezone = 'UTC';
52 
60  public function __construct(ilDate $seed_date)
61  {
62  global $ilCtrl, $lng, $ilUser,$ilTabs,$tpl;
63 
64  $this->seed = $seed_date;
65 
66  $this->tpl = $tpl;
67  $this->lng = $lng;
68  $this->ctrl = $ilCtrl;
69  $this->tabs_gui = $ilTabs;
70 
71  $this->user_settings = ilCalendarUserSettings::_getInstanceByUserId($ilUser->getId());
72  $this->app_colors = new ilCalendarAppointmentColors($ilUser->getId());
73 
74  $this->timezone = $ilUser->getTimeZone();
75  }
76 
83  public function executeCommand()
84  {
85  global $ilCtrl,$tpl;
86 
87  $next_class = $ilCtrl->getNextClass();
88  switch($next_class)
89  {
90  case 'ilcalendarappointmentgui':
91  $this->ctrl->setReturn($this,'');
92  $this->tabs_gui->setSubTabActive($_SESSION['cal_last_tab']);
93 
94  include_once('./Services/Calendar/classes/class.ilCalendarAppointmentGUI.php');
95  $app = new ilCalendarAppointmentGUI($this->seed,$this->seed, (int) $_GET['app_id']);
96  $this->ctrl->forwardCommand($app);
97  break;
98 
99  default:
100  $cmd = $this->ctrl->getCmd("inbox");
101  $this->$cmd();
102  $tpl->setContent($this->tpl->get());
103  break;
104  }
105 
106  return true;
107  }
108 
115  protected function inbox()
116  {
117  global $ilCtrl;
118 
119  $this->tpl = new ilTemplate('tpl.inbox.html',true,true,'Services/Calendar');
120 
121 
122  include_once('./Services/Calendar/classes/class.ilCalendarInboxSharedTableGUI.php');
123  include_once('./Services/Calendar/classes/class.ilCalendarShared.php');
124 
125  $table = new ilCalendarInboxSharedTableGUI($this,'inbox');
126  $table->setCalendars(ilCalendarShared::getSharedCalendarsForUser());
127 
128  if($table->parse())
129  {
130  $this->tpl->setVariable('SHARED_CAL_TABLE',$table->getHTML());
131  }
132 
133  include_once('./Services/Calendar/classes/class.ilCalendarChangedAppointmentsTableGUI.php');
134 
135  $table_gui = new ilCalendarChangedAppointmentsTableGUI($this,'inbox');
136 
138  $schedule->setEventsLimit($table_gui->getLimit());
139  $schedule->addSubitemCalendars(true);
140  $schedule->calculate();
141 
142  if(isset($_GET['changed']))
143  {
144  $title = $this->lng->txt('cal_changed_events_header');
145  $events = $schedule->getChangedEvents(true);
146 
147  $ilCtrl->setParameter($this, 'changed', 1);
148  }
149  else
150  {
151  // type inbox will show upcoming events (today or later)
152  $title = $this->lng->txt('cal_upcoming_events_header');
153  //$events = $schedule->getEvents();
154  $events = $schedule->getScheduledEvents();
155  }
156 
157  $table_gui->setTitle($title);
158  $table_gui->setAppointments($events);
159 
160  $this->tpl->setVariable('CHANGED_TABLE',$table_gui->getHTML());
161 
162  }
163 
170  protected function acceptShared()
171  {
172  global $ilUser;
173 
174  if(!$_POST['cal_ids'] or !is_array($_POST['cal_ids']))
175  {
176  ilUtil::sendFailure($this->lng->txt('select_one'));
177  $this->inbox();
178  return false;
179  }
180 
181  include_once('./Services/Calendar/classes/class.ilCalendarSharedStatus.php');
182  $status = new ilCalendarSharedStatus($ilUser->getId());
183 
184  include_once('./Services/Calendar/classes/class.ilCalendarShared.php');
185  foreach($_POST['cal_ids'] as $calendar_id)
186  {
187  if(!ilCalendarShared::isSharedWithUser($ilUser->getId(),$calendar_id))
188  {
189  ilUtil::sendFailure($this->lng->txt('permission_denied'));
190  $this->inbox();
191  return false;
192  }
193  $status->accept($calendar_id);
194  }
195 
196  ilUtil::sendSuccess($this->lng->txt('settings_saved'),true);
197  // redfirect for loading new calendar+
198  $this->ctrl->redirect($this,'inbox');
199  return true;
200  }
201 
208  protected function declineShared()
209  {
210  global $ilUser;
211 
212  if(!$_POST['cal_ids'] or !is_array($_POST['cal_ids']))
213  {
214  ilUtil::sendFailure($this->lng->txt('select_one'));
215  $this->inbox();
216  return false;
217  }
218 
219  include_once('./Services/Calendar/classes/class.ilCalendarSharedStatus.php');
220  $status = new ilCalendarSharedStatus($ilUser->getId());
221 
222  include_once('./Services/Calendar/classes/class.ilCalendarShared.php');
223  foreach($_POST['cal_ids'] as $calendar_id)
224  {
225  if(!ilCalendarShared::isSharedWithUser($ilUser->getId(),$calendar_id))
226  {
227  ilUtil::sendFailure($this->lng->txt('permission_denied'));
228  $this->inbox();
229  return false;
230  }
231  $status->decline($calendar_id);
232  }
233 
234  ilUtil::sendSuccess($this->lng->txt('settings_saved'));
235  $this->inbox();
236  return true;
237  }
238 
239 }
240 ?>