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