ILIAS  Release_4_4_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->setExportTimeZoneType((int) $_POST['export_tz']);
128  $this->user_settings->setWeekStart((int) $_POST['weekstart']);
129  $this->user_settings->setDateFormat((int) $_POST['date_format']);
130  $this->user_settings->setTimeFormat((int) $_POST['time_format']);
131  $this->user_settings->setDayStart((int) $_POST['dst']);
132  $this->user_settings->setDayEnd((int) $_POST['den']);
133 
134  if(((int) $_POST['den']) < (int) $_POST['dst'])
135  {
136  ilUtil::sendFailure($this->lng->txt('cal_dstart_dend_warn'));
137  $this->show();
138  return false;
139  }
140 
141  $this->user_settings->save();
142 
143  ilUtil::sendSuccess($this->lng->txt('settings_saved'),true);
144  $this->ctrl->returnToParent($this);
145  }
146 
153  public function initSettingsForm()
154  {
155  if(is_object($this->form))
156  {
157  return true;
158  }
159  include_once('Services/Calendar/classes/class.ilCalendarUtil.php');
160  include_once('Services/Form/classes/class.ilPropertyFormGUI.php');
161 
162  $this->form = new ilPropertyFormGUI();
163  $this->form->setFormAction($this->ctrl->getFormAction($this,'save'));
164  $this->form->setTitle($this->lng->txt('cal_user_settings'));
165  $this->form->addCommandButton('save',$this->lng->txt('save'));
166  $this->form->addCommandButton('cancel',$this->lng->txt('cancel'));
167 
168  $select = new ilSelectInputGUI($this->lng->txt('cal_user_timezone'),'timezone');
170  $select->setInfo($this->lng->txt('cal_timezone_info'));
171  $select->setValue($this->user_settings->getTimeZone());
172  $this->form->addItem($select);
173 
174  $export_type = new ilRadioGroupInputGUI($this->lng->txt('cal_export_timezone'),'export_tz');
175  $export_type->setValue($this->user_settings->getExportTimeZoneType());
176 
177  $export_tz = new ilRadioOption($this->lng->txt('cal_export_timezone_tz'), ilCalendarUserSettings::CAL_EXPORT_TZ_TZ);
178  $export_type->addOption($export_tz);
179  $export_utc = new ilRadioOption($this->lng->txt('cal_export_timezone_utc'), ilCalendarUserSettings::CAL_EXPORT_TZ_UTC);
180  $export_type->addOption($export_utc);
181  $this->form->addItem($export_type);
182 
183  $year = date("Y");
184  $select = new ilSelectInputGUI($this->lng->txt('cal_user_date_format'),'date_format');
185  $select->setOptions(array(
186  ilCalendarSettings::DATE_FORMAT_DMY => '31.10.'.$year,
187  ilCalendarSettings::DATE_FORMAT_YMD => $year."-10-31",
188  ilCalendarSettings::DATE_FORMAT_MDY => "10/31/".$year));
189  $select->setInfo($this->lng->txt('cal_date_format_info'));
190  $select->setValue($this->user_settings->getDateFormat());
191  $this->form->addItem($select);
192 
193  $select = new ilSelectInputGUI($this->lng->txt('cal_user_time_format'),'time_format');
194  $select->setOptions(array(
197  $select->setInfo($this->lng->txt('cal_time_format_info'));
198  $select->setValue($this->user_settings->getTimeFormat());
199  $this->form->addItem($select);
200 
201  // Week/Month View
202  $week_month = new ilFormSectionHeaderGUI();
203  $week_month->setTitle($this->lng->txt('cal_week_month_view'));
204  $this->form->addItem($week_month);
205 
206  $radio = new ilRadioGroupInputGUI($this->lng->txt('cal_week_start'),'weekstart');
207  $radio->setValue($this->user_settings->getWeekStart());
208 
209  $option = new ilRadioOption($this->lng->txt('l_su'),0);
210  $radio->addOption($option);
211  $option = new ilRadioOption($this->lng->txt('l_mo'),1);
212  $radio->addOption($option);
213  $this->form->addItem($radio);
214 
215  // Day/Week View
216  $week_month = new ilFormSectionHeaderGUI();
217  $week_month->setTitle($this->lng->txt('cal_day_week_view'));
218  $this->form->addItem($week_month);
219 
220  $day_start = new ilSelectInputGUI($this->lng->txt('cal_day_start'),'dst');
221  $day_start->setOptions(
222  ilCalendarUtil::getHourSelection($this->user_settings->getTimeFormat())
223  );
224  $day_start->setValue($this->user_settings->getDayStart());
225  $this->form->addItem($day_start);
226 
227  $day_end = new ilSelectInputGUI($this->lng->txt('cal_day_end'),'den');
228  $day_end->setOptions(
229  ilCalendarUtil::getHourSelection($this->user_settings->getTimeFormat())
230  );
231  $day_end->setValue($this->user_settings->getDayEnd());
232  $this->form->addItem($day_end);
233  }
234 }
235 
236 ?>