ILIAS  Release_4_0_x_branch Revision 61816
 All Data Structures Namespaces Files Functions Variables Groups Pages
class.ilCalendarUserSettingsGUI.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.ilCalendarUserSettings.php');
25 include_once('Services/Calendar/classes/class.ilCalendarSettings.php');
26 
37 {
38  protected $tpl;
39  protected $lng;
40  protected $user;
41  protected $settings;
42 
43 
51  public function __construct()
52  {
53  global $ilUser,$tpl,$lng,$ilCtrl;
54 
55  $this->tpl = $tpl;
56  $this->lng = $lng;
57  $this->lng->loadLanguageModule('dateplaner');
58  $this->lng->loadLanguageModule('jscalendar');
59 
60  $this->ctrl = $ilCtrl;
61 
62  $this->user = $ilUser;
63  $this->settings = ilCalendarSettings::_getInstance();
64  $this->user_settings = ilCalendarUserSettings::_getInstanceByUserId($this->user->getId());
65 
66  }
67 
68 
75  public function executeCommand()
76  {
77  global $ilUser, $ilSetting;
78 
79 
80  $next_class = $this->ctrl->getNextClass();
81 
82  switch($next_class)
83  {
84  default:
85  $cmd = $this->ctrl->getCmd("show");
86  $this->$cmd();
87  break;
88  }
89  return true;
90  }
91 
99  public function show()
100  {
101  $this->tpl->addBlockFile('ADM_CONTENT','adm_content','tpl.user_settings.html','Services/Calendar');
102 
103  $this->initSettingsForm();
104  $this->tpl->setVariable('CAL_SETTINGS',$this->form->getHTML());
105  }
106 
112  public function cancel()
113  {
114  $this->ctrl->returnToParent($this);
115  }
116 
123  public function save()
124  {
125 
126  $this->user_settings->setTimeZone($_POST['timezone']);
127  $this->user_settings->setWeekStart((int) $_POST['weekstart']);
128  $this->user_settings->setTimeFormat((int) $_POST['time_format']);
129  $this->user_settings->setDayStart((int) $_POST['dst']);
130  $this->user_settings->setDayEnd((int) $_POST['den']);
131 
132  if(((int) $_POST['den']) < (int) $_POST['dst'])
133  {
134  ilUtil::sendFailure($this->lng->txt('cal_dstart_dend_warn'));
135  $this->show();
136  return false;
137  }
138 
139  $this->user_settings->save();
140 
141  ilUtil::sendSuccess($this->lng->txt('settings_saved'),true);
142  $this->ctrl->returnToParent($this);
143  }
144 
151  public function initSettingsForm()
152  {
153  if(is_object($this->form))
154  {
155  return true;
156  }
157  include_once('Services/Calendar/classes/class.ilCalendarUtil.php');
158  include_once('Services/Form/classes/class.ilPropertyFormGUI.php');
159 
160  $this->form = new ilPropertyFormGUI();
161  $this->form->setFormAction($this->ctrl->getFormAction($this,'save'));
162  $this->form->setTitle($this->lng->txt('cal_user_settings'));
163  $this->form->addCommandButton('save',$this->lng->txt('save'));
164  $this->form->addCommandButton('cancel',$this->lng->txt('cancel'));
165 
166  $select = new ilSelectInputGUI($this->lng->txt('cal_user_timezone'),'timezone');
168  $select->setInfo($this->lng->txt('cal_timezone_info'));
169  $select->setValue($this->user_settings->getTimeZone());
170  $this->form->addItem($select);
171 
172  $select = new ilSelectInputGUI($this->lng->txt('cal_user_time_format'),'time_format');
173  $select->setOptions(array(
176  $select->setInfo($this->lng->txt('cal_time_format_info'));
177  $select->setValue($this->user_settings->getTimeFormat());
178  $this->form->addItem($select);
179 
180  // Week/Month View
181  $week_month = new ilFormSectionHeaderGUI();
182  $week_month->setTitle($this->lng->txt('cal_week_month_view'));
183  $this->form->addItem($week_month);
184 
185  $radio = new ilRadioGroupInputGUI($this->lng->txt('cal_week_start'),'weekstart');
186  $radio->setValue($this->user_settings->getWeekStart());
187 
188  $option = new ilRadioOption($this->lng->txt('l_su'),0);
189  $radio->addOption($option);
190  $option = new ilRadioOption($this->lng->txt('l_mo'),1);
191  $radio->addOption($option);
192  $this->form->addItem($radio);
193 
194  // Day/Week View
195  $week_month = new ilFormSectionHeaderGUI();
196  $week_month->setTitle($this->lng->txt('cal_day_week_view'));
197  $this->form->addItem($week_month);
198 
199  $day_start = new ilSelectInputGUI($this->lng->txt('cal_day_start'),'dst');
200  $day_start->setOptions(
201  ilCalendarUtil::getHourSelection($this->user_settings->getTimeFormat())
202  );
203  $day_start->setValue($this->user_settings->getDayStart());
204  $this->form->addItem($day_start);
205 
206  $day_end = new ilSelectInputGUI($this->lng->txt('cal_day_end'),'den');
207  $day_end->setOptions(
208  ilCalendarUtil::getHourSelection($this->user_settings->getTimeFormat())
209  );
210  $day_end->setValue($this->user_settings->getDayEnd());
211  $this->form->addItem($day_end);
212  }
213 }
214 
215 ?>