ILIAS  Release_4_1_x_branch Revision 61804
 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 
134  $schedule = new ilCalendarSchedule($this->seed,ilCalendarSchedule::TYPE_INBOX);
135  if(isset($_GET['changed']))
136  {
137  $title = $this->lng->txt('cal_changed_events_header');
138  $events = $schedule->getChangedEvents(true);
139 
140  $ilCtrl->setParameter($this, 'changed', 1);
141  }
142  else
143  {
144  // type inbox will show upcoming events (today or later)
145  $title = $this->lng->txt('cal_upcoming_events_header');
146  $events = $schedule->getEvents();
147  }
148 
149  include_once('./Services/Calendar/classes/class.ilCalendarChangedAppointmentsTableGUI.php');
150 
151  $table_gui = new ilCalendarChangedAppointmentsTableGUI($this,'inbox');
152  $table_gui->setTitle($title);
153  $table_gui->setAppointments($events);
154 
155  $this->tpl->setVariable('CHANGED_TABLE',$table_gui->getHTML());
156 
157  }
158 
165  protected function acceptShared()
166  {
167  global $ilUser;
168 
169  if(!$_POST['cal_ids'] or !is_array($_POST['cal_ids']))
170  {
171  ilUtil::sendFailure($this->lng->txt('select_one'));
172  $this->inbox();
173  return false;
174  }
175 
176  include_once('./Services/Calendar/classes/class.ilCalendarSharedStatus.php');
177  $status = new ilCalendarSharedStatus($ilUser->getId());
178 
179  include_once('./Services/Calendar/classes/class.ilCalendarShared.php');
180  foreach($_POST['cal_ids'] as $calendar_id)
181  {
182  if(!ilCalendarShared::isSharedWithUser($ilUser->getId(),$calendar_id))
183  {
184  ilUtil::sendFailure($this->lng->txt('permission_denied'));
185  $this->inbox();
186  return false;
187  }
188  $status->accept($calendar_id);
189  }
190 
191  ilUtil::sendSuccess($this->lng->txt('settings_saved'),true);
192  // redfirect for loading new calendar+
193  $this->ctrl->redirect($this,'inbox');
194  return true;
195  }
196 
203  protected function declineShared()
204  {
205  global $ilUser;
206 
207  if(!$_POST['cal_ids'] or !is_array($_POST['cal_ids']))
208  {
209  ilUtil::sendFailure($this->lng->txt('select_one'));
210  $this->inbox();
211  return false;
212  }
213 
214  include_once('./Services/Calendar/classes/class.ilCalendarSharedStatus.php');
215  $status = new ilCalendarSharedStatus($ilUser->getId());
216 
217  include_once('./Services/Calendar/classes/class.ilCalendarShared.php');
218  foreach($_POST['cal_ids'] as $calendar_id)
219  {
220  if(!ilCalendarShared::isSharedWithUser($ilUser->getId(),$calendar_id))
221  {
222  ilUtil::sendFailure($this->lng->txt('permission_denied'));
223  $this->inbox();
224  return false;
225  }
226  $status->decline($calendar_id);
227  }
228 
229  ilUtil::sendSuccess($this->lng->txt('settings_saved'));
230  $this->inbox();
231  return true;
232  }
233 
234 }
235 ?>