ILIAS  Release_3_10_x_branch Revision 61812
 All Data Structures Namespaces Files Functions Variables Groups Pages
class.ilRecurrenceInputGUI.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 
25 include_once('./Services/Calendar/classes/class.ilCalendarUserSettings.php');
26 
37 {
38  const REC_LIMITED = 2;
39  const REC_UNLIMITED = 1;
40 
41  protected $lng;
42 
43  protected $recurrence;
44  protected $user_settings;
45 
46  protected $until_selection = true;
47 
48  protected $enabled_subforms = array(
53 
61  public function __construct($a_title, $a_postvar)
62  {
63  global $lng,$tpl,$ilUser;
64 
65  $this->lng = $lng;
66  $this->lng->loadLanguageModule('dateplaner');
67 
68  $this->user_settings = ilCalendarUserSettings::_getInstanceByUserId($ilUser->getId());
69  $tpl->addJavascript("./Services/Calendar/js/recurrence_input.js");
70 
71  parent::__construct($a_title,$a_postvar);
72  }
73 
81  public function checkInput()
82  {
83  global $lng;
84 
85  if($_POST['frequence'] == 'NONE')
86  {
87  return true;
88  }
89 
90  if(!isset($_POST['until_type']) or $_POST['until_type'] == REC_LIMITED)
91  {
92  if($_POST['count'] <= 0 or $_POST['count'] >= 100)
93  {
94  $this->setAlert($lng->txt("cal_rec_err_limit"));
95  return false;
96  }
97  }
98 
99  return true;
100  }
101 
109  public function setRecurrence($a_rec)
110  {
111  $this->recurrence = $a_rec;
112  }
113 
120  public function enableUntilSelection($a_enabled)
121  {
122  $this->until_selection = $a_enabled;
123  }
124 
131  public function enabledUntilSelection()
132  {
133  return (bool) $this->until_selection;
134  }
135 
136 
144  public function setEnabledSubForms($a_sub_forms)
145  {
146  $this->enabled_subforms = $a_sub_forms;
147  }
148 
155  public function getEnabledSubForms()
156  {
158  }
159 
167  public function insert($a_tpl)
168  {
169  $tpl = new ilTemplate('tpl.recurrence_input.html',true,true,'Services/Calendar');
170  $options = array('NONE' => $this->lng->txt('cal_no_recurrences'),
171  IL_CAL_FREQ_DAILY => $this->lng->txt('cal_daily'),
172  IL_CAL_FREQ_WEEKLY=> $this->lng->txt('cal_weekly'),
173  IL_CAL_FREQ_MONTHLY => $this->lng->txt('cal_monthly'),
174  IL_CAL_FREQ_YEARLY => $this->lng->txt('cal_yearly'));
175  $tpl->setVariable('FREQUENCE',ilUtil::formSelect(
176  $this->recurrence->getFrequenceType(),
177  'frequence',
178  $options,
179  false,
180  true,
181  '',
182  '',
183  array('onchange' => 'ilHideFrequencies();','id' => 'il_recurrence_1')));
184 
185  $tpl->setVariable('TXT_EVERY',$this->lng->txt('cal_every'));
186 
187  // DAILY
188  $tpl->setVariable('TXT_DAILY_FREQ_UNIT',$this->lng->txt('cal_day_s'));
189  $tpl->setVariable('COUNT_DAILY_VAL',$this->recurrence->getInterval());
190 
191  // WEEKLY
192  $tpl->setVariable('TXT_WEEKLY_FREQ_UNIT',$this->lng->txt('cal_week_s'));
193  $tpl->setVariable('COUNT_WEEKLY_VAL',$this->recurrence->getInterval());
194  $this->buildWeekDaySelection($tpl);
195 
196  // MONTHLY
197  $tpl->setVariable('TXT_MONTHLY_FREQ_UNIT',$this->lng->txt('cal_month_s'));
198  $tpl->setVariable('COUNT_MONTHLY_VAL',$this->recurrence->getInterval());
199  $tpl->setVariable('TXT_ON_THE',$this->lng->txt('cal_on_the'));
200  $tpl->setVariable('TXT_BYMONTHDAY',$this->lng->txt('cal_on_the'));
201  $tpl->setVariable('TXT_OF_THE_MONTH',$this->lng->txt('cal_of_the_month'));
204 
205  // YEARLY
206  $tpl->setVariable('TXT_YEARLY_FREQ_UNIT',$this->lng->txt('cal_year_s'));
207  $tpl->setVariable('COUNT_YEARLY_VAL',$this->recurrence->getInterval());
208  $tpl->setVariable('TXT_ON_THE',$this->lng->txt('cal_on_the'));
211 
212  // UNTIL
213  $this->buildUntilSelection($tpl);
214 
215  $a_tpl->setCurrentBlock("prop_custom");
216  $a_tpl->setVariable("CUSTOM_CONTENT", $tpl->get());
217  $a_tpl->parseCurrentBlock();
218 
219  }
220 
227  protected function buildWeekDaySelection($tpl)
228  {
229  $days = array(0 => 'SU',1 => 'MO',2 => 'TU',3 => 'WE',4 => 'TH',5 => 'FR',6 => 'SA',7 => 'SU');
230 
231  $checked_days = array();
232  foreach($this->recurrence->getBYDAYList() as $byday)
233  {
234  if(in_array($byday,$days))
235  {
236  $checked_days[] = $byday;
237  }
238  }
239 
240  for($i = (int) $this->user_settings->getWeekStart();$i < 7 + (int) $this->user_settings->getWeekStart();$i++)
241  {
242  $tpl->setCurrentBlock('byday_simple');
243 
244  if(in_array($days[$i],$checked_days))
245  {
246  $tpl->setVariable('BYDAY_WEEKLY_CHECKED','checked="checked"');
247  }
248  $tpl->setVariable('TXT_ON',$this->lng->txt('cal_on'));
249  $tpl->setVariable('BYDAY_WEEKLY_VAL',$days[$i]);
250  $tpl->setVariable('TXT_DAY_SHORT',ilCalendarUtil::_numericDayToString($i,false));
251  $tpl->parseCurrentBlock();
252  }
253 
254  }
255 
263  protected function buildMonthlyByDaySelection($tpl)
264  {
265  $byday_list = $this->recurrence->getBYDAYList();
266  $chosen_num_day = 1;
267  $chosen_day = 'MO';
268  $chosen = false;
269  foreach($byday_list as $byday)
270  {
271  if(preg_match('/^(-?\d)([A-Z][A-Z])/',$byday,$parsed) === 1)
272  {
273  $chosen = true;
274  $chosen_num_day = $parsed[1];
275  $chosen_day = $parsed[2];
276  }
277  }
278  // check for last day
279  if(count($this->recurrence->getBYMONTHDAYList()) == 1)
280  {
281  $bymonthday = $this->recurrence->getBYMONTHDAY();
282  if(in_array($bymonthday,array(1,2,3,4,5,-1)))
283  {
284  $chosen = true;
285  $chosen_num_day = $bymonthday;
286  $chosen_day = 9;
287  }
288  }
289  // Check for first, second... last weekday
290  if(count($this->recurrence->getBYSETPOSList()) == 1)
291  {
292  $bysetpos = $this->recurrence->getBYSETPOS();
293  if(in_array($bysetpos,array(1,2,3,4,5,-1)))
294  {
295  if($this->recurrence->getBYDAYList() == array('MO','TU','WE','TH','FR'))
296  {
297  $chosen = true;
298  $chosen_num_day = $bysetpos;
299  $chosen_day = 8;
300  }
301  }
302  }
303 
304 
305 
306  if($chosen)
307  {
308  $tpl->setVariable('M_BYDAY_CHECKED','checked="checked"');
309  }
310 
311  $num_options = array(
312  1 => $this->lng->txt('cal_first'),
313  2 => $this->lng->txt('cal_second'),
314  3 => $this->lng->txt('cal_third'),
315  4 => $this->lng->txt('cal_fourth'),
316  5 => $this->lng->txt('cal_fifth'),
317  -1 => $this->lng->txt('cal_last'));
318 
319  $tpl->setVariable('SELECT_BYDAY_NUM_MONTHLY',ilUtil::formSelect(
320  $chosen_num_day,
321  'monthly_byday_num',
322  $num_options,
323  false,
324  true,
325  '',
326  '',
327  array('onchange' => "ilUpdateSubTypeSelection('sub_monthly_radio_1');")));
328 
329  $days = array(0 => 'SU',1 => 'MO',2 => 'TU',3 => 'WE',4 => 'TH',5 => 'FR',6 => 'SA',7 => 'SU');
330 
331  for($i = (int) $this->user_settings->getWeekStart();$i < 7 + (int) $this->user_settings->getWeekStart();$i++)
332  {
333  $days_select[$days[$i]] = ilCalendarUtil::_numericDayToString($i);
334  }
335  $days_select[8] = $this->lng->txt('cal_weekday');
336  $days_select[9] = $this->lng->txt('cal_day_of_month');
337  $tpl->setVariable('SEL_BYDAY_DAY_MONTHLY',ilUtil::formSelect(
338  $chosen_day,
339  'monthly_byday_day',
340  $days_select,
341  false,
342  true,
343  '',
344  '',
345  array('onchange' => "ilUpdateSubTypeSelection('sub_monthly_radio_1');")));
346  }
347 
356  {
357  $tpl->setVariable('TXT_IN',$this->lng->txt('cal_in'));
358 
359  $chosen_day = 1;
360  $chosen = false;
361  if(count($bymonthday = $this->recurrence->getBYMONTHDAYList()) == 1)
362  {
363  foreach($bymonthday as $mday)
364  {
365  if($mday > 0 and $mday < 32)
366  {
367  $chosen = true;
368  $chosen_day = $mday;
369  }
370  }
371  }
372 
373  if($chosen)
374  {
375  $tpl->setVariable('M_BYMONTHDAY_CHECKED','checked="checked"');
376  }
377 
378  for($i = 1; $i < 32;$i++)
379  {
380  $options[$i] = $i;
381  }
382  $tpl->setVariable('SELECT_BYMONTHDAY',ilUtil::formSelect(
383  $chosen_day,
384  'monthly_bymonthday',
385  $options,
386  false,
387  true,
388  '',
389  '',
390  array('onchange' => "ilUpdateSubTypeSelection('sub_monthly_radio_2');")));
391  }
392 
401  {
402  $tpl->setVariable('TXT_Y_EVERY',$this->lng->txt('cal_every'));
403 
404 
405  $chosen = false;
406  $chosen_month = 1;
407  $chosen_day = 1;
408  foreach($this->recurrence->getBYMONTHList() as $month)
409  {
410  if($this->recurrence->getBYMONTHDAYList())
411  {
412  $chosen_month = $month;
413  $chosen = true;
414  break;
415  }
416  }
417  foreach($this->recurrence->getBYMONTHDAYList() as $day)
418  {
419  $chosen_day = $day;
420  }
421 
422  for($i = 1; $i < 32;$i++)
423  {
424  $options[$i] = $i;
425  }
426  $tpl->setVariable('SELECT_BYMONTHDAY_NUM_YEARLY',ilUtil::formSelect(
427  $chosen_day,
428  'yearly_bymonthday',
429  $options,
430  false,
431  true,
432 
433  '',
434  '',
435  array('onchange' => "ilUpdateSubTypeSelection('sub_yearly_radio_2');")));
436 
437  $options = array();
438  for($m = 1;$m < 13;$m++)
439  {
440  $options[$m] = ilCalendarUtil::_numericMonthToString($m);
441  }
442  $tpl->setVariable('SELECT_BYMONTH_YEARLY',ilUtil::formSelect(
443  $chosen_month,
444  'yearly_bymonth_by_monthday',
445  $options,
446  false,
447  true,
448  '',
449  '',
450  array('onchange' => "ilUpdateSubTypeSelection('sub_yearly_radio_2');")));
451 
452 
453  if($chosen)
454  {
455  $tpl->setVariable('Y_BYMONTHDAY_CHECKED','checked="checked"');
456  }
457 
458  }
459 
467  protected function buildYearlyByDaySelection($tpl)
468  {
469  $tpl->setVariable('TXT_ON_THE',$this->lng->txt('cal_on_the'));
470 
471  $chosen_num_day = 1;
472  $chosen_day = 'MO';
473  $chosen = false;
474  foreach($this->recurrence->getBYDAYList() as $byday)
475  {
476  if(preg_match('/^(-?\d)([A-Z][A-Z])/',$byday,$parsed) === 1)
477  {
478  $chosen = true;
479  $chosen_num_day = $parsed[1];
480  $chosen_day = $parsed[2];
481  }
482  }
483 
484 
485  $num_options = array(
486  1 => $this->lng->txt('cal_first'),
487  2 => $this->lng->txt('cal_second'),
488  3 => $this->lng->txt('cal_third'),
489  4 => $this->lng->txt('cal_fourth'),
490  5 => $this->lng->txt('cal_fifth'),
491  -1 => $this->lng->txt('cal_last'));
492 
493  $tpl->setVariable('SELECT_BYDAY_NUM_YEARLY',ilUtil::formSelect(
494  $chosen_num_day,
495  'yearly_byday_num',
496  $num_options,
497  false,
498  true,
499  '',
500  '',
501  array('onchange' => "ilUpdateSubTypeSelection('sub_yearly_radio_1');")));
502 
503 
504  $days = array(0 => 'SU',1 => 'MO',2 => 'TU',3 => 'WE',4 => 'TH',5 => 'FR',6 => 'SA',7 => 'SU');
505  for($i = (int) $this->user_settings->getWeekStart();$i < 7 + (int) $this->user_settings->getWeekStart();$i++)
506  {
507  $days_select[$days[$i]] = ilCalendarUtil::_numericDayToString($i);
508  }
509  $tpl->setVariable('SELECT_BYDAY_DAY_YEARLY',ilUtil::formSelect(
510  $chosen_day,
511  'yearly_byday',
512  $days_select,
513  false,
514  true,
515  '',
516  '',
517  array('onchange' => "ilUpdateSubTypeSelection('sub_yearly_radio_1');")));
518 
519 
520  $chosen = false;
521  $chosen_month = 1;
522  foreach($this->recurrence->getBYMONTHList() as $month)
523  {
524  if($this->recurrence->getBYMONTHDAYList())
525  {
526  $chosen_month = $month;
527  $chosen = true;
528  break;
529  }
530  }
531  $options = array();
532  for($m = 1;$m < 13;$m++)
533  {
534  $options[$m] = ilCalendarUtil::_numericMonthToString($m);
535  }
536  $tpl->setVariable('SELECT_BYMONTH_BYDAY',ilUtil::formSelect(
537  $chosen_month,
538  'yearly_bymonth_byday',
539  $options,
540  false,
541  true,
542  '',
543  '',
544  array('onchange' => "ilUpdateSubTypeSelection('sub_yearly_radio_1');")));
545 
546  }
547 
555  protected function buildUntilSelection($tpl)
556  {
557 
558  if($this->enabledUntilSelection())
559  {
560  $tpl->setVariable('TXT_NO_ENDING',$this->lng->txt('cal_no_ending'));
561  $tpl->setVariable('TXT_UNTIL_CREATE',$this->lng->txt('cal_create'));
562  $tpl->setVariable('TXT_APPOINTMENTS',$this->lng->txt('cal_appointments'));
563 
564  $tpl->setVariable('VAL_COUNT',$this->recurrence->getFrequenceUntilCount() ?
565  $this->recurrence->getFrequenceUntilCount() :
566  2);
567  if($this->recurrence->getFrequenceUntilCount())
568  {
569  $tpl->setVariable('UNTIL_COUNT_CHECKED','checked="checked"');
570  }
571  else
572  {
573  $tpl->setVariable('UNTIL_NO_CHECKED','checked="checked"');
574  }
575  }
576  else
577  {
578  $tpl->setVariable('TXT_FIXED_UNTIL_CREATE',$this->lng->txt('cal_create'));
579  $tpl->setVariable('TXT_FIXED_APPOINTMENTS',$this->lng->txt('cal_appointments'));
580 
581  $tpl->setVariable('VAL_FIXED_COUNT',$this->recurrence->getFrequenceUntilCount() ?
582  $this->recurrence->getFrequenceUntilCount() :
583  5);
584 
585  }
586  }
587 }
588 ?>