ILIAS  release_5-2 Revision v5.2.25-18-g3f80b828510
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
25include_once('./Services/Calendar/classes/class.ilCalendarUserSettings.php');
26include_once './Services/Calendar/classes/class.ilCalendarRecurrence.php';
27
38{
39 const REC_LIMITED = 2;
40 const REC_UNLIMITED = 1;
41
42 protected $lng;
43
44 protected $recurrence;
45 protected $user_settings;
46
48
49 protected $enabled_subforms = array(
54
62 public function __construct($a_title, $a_postvar)
63 {
64 global $lng,$tpl,$ilUser;
65
66 $this->lng = $lng;
67 $this->lng->loadLanguageModule('dateplaner');
68
69 $this->user_settings = ilCalendarUserSettings::_getInstanceByUserId($ilUser->getId());
70 $tpl->addJavascript("./Services/Calendar/js/recurrence_input.js");
71
73
74 parent::__construct($a_title,$a_postvar);
75 }
76
84 public function checkInput()
85 {
86 global $lng;
87
88 if(!$this->loadRecurrence())
89 {
90 return false;
91 }
92
93 if($_POST['frequence'] == 'NONE')
94 {
95 return true;
96 }
97
98 if(!isset($_POST['until_type']) or $_POST['until_type'] == REC_LIMITED)
99 {
100 if($_POST['count'] <= 0 or $_POST['count'] >= 100)
101 {
102 $this->setAlert($lng->txt("cal_rec_err_limit"));
103 return false;
104 }
105 }
106
107
108 return true;
109 }
110
116 protected function loadRecurrence()
117 {
118 if(!$this->getRecurrence() instanceof ilCalendarRecurrence)
119 {
120 return false;
121 }
122
123
124 switch($_POST['frequence'])
125 {
127 $this->getRecurrence()->setFrequenceType($_POST['frequence']);
128 $this->getRecurrence()->setInterval((int) $_POST['count_DAILY']);
129 break;
130
132 $this->getRecurrence()->setFrequenceType($_POST['frequence']);
133 $this->getRecurrence()->setInterval((int) $_POST['count_WEEKLY']);
134 if(is_array($_POST['byday_WEEKLY']))
135 {
136 $this->getRecurrence()->setBYDAY(ilUtil::stripSlashes(implode(',',$_POST['byday_WEEKLY'])));
137 }
138 break;
139
141 $this->getRecurrence()->setFrequenceType($_POST['frequence']);
142 $this->getRecurrence()->setInterval((int) $_POST['count_MONTHLY']);
143 switch((int) $_POST['subtype_MONTHLY'])
144 {
145 case 0:
146 // nothing to do;
147 break;
148
149 case 1:
150 switch((int) $_POST['monthly_byday_day'])
151 {
152 case 8:
153 // Weekday
154 $this->getRecurrence()->setBYSETPOS((int) $_POST['monthly_byday_num']);
155 $this->getRecurrence()->setBYDAY('MO,TU,WE,TH,FR');
156 break;
157
158 case 9:
159 // Day of month
160 $this->getRecurrence()->setBYMONTHDAY((int) $_POST['monthly_byday_num']);
161 break;
162
163 default:
164 $this->getRecurrence()->setBYDAY((int) $_POST['monthly_byday_num'].$_POST['monthly_byday_day']);
165 break;
166 }
167 break;
168
169 case 2:
170 $this->getRecurrence()->setBYMONTHDAY((int) $_POST['monthly_bymonthday']);
171 break;
172 }
173 break;
174
176 $this->getRecurrence()->setFrequenceType($_POST['frequence']);
177 $this->getRecurrence()->setInterval((int) $_POST['count_YEARLY']);
178 switch((int) $_POST['subtype_YEARLY'])
179 {
180 case 0:
181 // nothing to do;
182 break;
183
184 case 1:
185 $this->getRecurrence()->setBYMONTH((int) $_POST['yearly_bymonth_byday']);
186 $this->getRecurrence()->setBYDAY((int) $_POST['yearly_byday_num'].$_POST['yearly_byday']);
187 break;
188
189 case 2:
190 $this->getRecurrence()->setBYMONTH((int) $_POST['yearly_bymonth_by_monthday']);
191 $this->getRecurrence()->setBYMONTHDAY((int) $_POST['yearly_bymonthday']);
192 break;
193 }
194 break;
195 }
196
197 // UNTIL
198 switch((int) $_POST['until_type'])
199 {
200 case 1:
201 $this->getRecurrence()->setFrequenceUntilDate(null);
202 // nothing to do
203 break;
204
205 case 2:
206 $this->getRecurrence()->setFrequenceUntilDate(null);
207 $this->getRecurrence()->setFrequenceUntilCount((int) $_POST['count']);
208 break;
209
210 case 3:
211 $dt = new ilDateTimeInputGUI('','until_end');
212 $dt->setRequired(true);
213 if($dt->checkInput())
214 {
215 $this->getRecurrence()->setFrequenceUntilCount(0);
216 $this->getRecurrence()->setFrequenceUntilDate($dt->getDate());
217 }
218 else
219 {
220 return false;
221 }
222 break;
223 }
224
225 return true;
226 }
227
228
236 public function setRecurrence($a_rec)
237 {
238 $this->recurrence = $a_rec;
239 }
240
245 public function getRecurrence()
246 {
247 return $this->recurrence;
248 }
249
255 public function allowUnlimitedRecurrences($a_status)
256 {
257 $this->allow_unlimited_recurrences = $a_status;
258 }
259
265 {
267 }
268
276 public function setEnabledSubForms($a_sub_forms)
277 {
278 $this->enabled_subforms = $a_sub_forms;
279 }
280
287 public function getEnabledSubForms()
288 {
290 }
291
299 public function insert($a_tpl)
300 {
301 $tpl = new ilTemplate('tpl.recurrence_input.html',true,true,'Services/Calendar');
302
303 $options = array('NONE' => $this->lng->txt('cal_no_recurrence'));
304 if(in_array(IL_CAL_FREQ_DAILY, $this->getEnabledSubForms()))
305 {
306 $options[IL_CAL_FREQ_DAILY] = $this->lng->txt('cal_daily');
307 }
308 if(in_array(IL_CAL_FREQ_WEEKLY, $this->getEnabledSubForms()))
309 {
310 $options[IL_CAL_FREQ_WEEKLY] = $this->lng->txt('cal_weekly');
311 }
312 if(in_array(IL_CAL_FREQ_MONTHLY, $this->getEnabledSubForms()))
313 {
314 $options[IL_CAL_FREQ_MONTHLY] = $this->lng->txt('cal_monthly');
315 }
316 if(in_array(IL_CAL_FREQ_YEARLY, $this->getEnabledSubForms()))
317 {
318 $options[IL_CAL_FREQ_YEARLY] = $this->lng->txt('cal_yearly');
319 }
320
321 $tpl->setVariable('FREQUENCE',ilUtil::formSelect(
322 $this->recurrence->getFrequenceType(),
323 'frequence',
324 $options,
325 false,
326 true,
327 '',
328 '',
329 array('onchange' => 'ilHideFrequencies();','id' => 'il_recurrence_1')));
330
331 $tpl->setVariable('TXT_EVERY',$this->lng->txt('cal_every'));
332
333 // DAILY
334 if(in_array(IL_CAL_FREQ_DAILY, $this->getEnabledSubForms()))
335 {
336 $tpl->setVariable('TXT_DAILY_FREQ_UNIT',$this->lng->txt('cal_day_s'));
337 $tpl->setVariable('COUNT_DAILY_VAL',$this->recurrence->getInterval());
338 }
339
340 // WEEKLY
341 if(in_array(IL_CAL_FREQ_WEEKLY, $this->getEnabledSubForms()))
342 {
343 $tpl->setVariable('TXT_WEEKLY_FREQ_UNIT',$this->lng->txt('cal_week_s'));
344 $tpl->setVariable('COUNT_WEEKLY_VAL',$this->recurrence->getInterval());
346 }
347
348 // MONTHLY
349 if(in_array(IL_CAL_FREQ_MONTHLY, $this->getEnabledSubForms()))
350 {
351 $tpl->setVariable('TXT_MONTHLY_FREQ_UNIT',$this->lng->txt('cal_month_s'));
352 $tpl->setVariable('COUNT_MONTHLY_VAL',$this->recurrence->getInterval());
353 $tpl->setVariable('TXT_ON_THE',$this->lng->txt('cal_on_the'));
354 $tpl->setVariable('TXT_BYMONTHDAY',$this->lng->txt('cal_on_the'));
355 $tpl->setVariable('TXT_OF_THE_MONTH',$this->lng->txt('cal_of_the_month'));
358 }
359
360 // YEARLY
361 if(in_array(IL_CAL_FREQ_YEARLY, $this->getEnabledSubForms()))
362 {
363 $tpl->setVariable('TXT_YEARLY_FREQ_UNIT',$this->lng->txt('cal_year_s'));
364 $tpl->setVariable('COUNT_YEARLY_VAL',$this->recurrence->getInterval());
365 $tpl->setVariable('TXT_ON_THE',$this->lng->txt('cal_on_the'));
368 }
369
370 // UNTIL
372
373 $a_tpl->setCurrentBlock("prop_custom");
374 $a_tpl->setVariable("CUSTOM_CONTENT", $tpl->get());
375 $a_tpl->parseCurrentBlock();
376
377 }
378
385 protected function buildWeekDaySelection($tpl)
386 {
387 $days = array(0 => 'SU',1 => 'MO',2 => 'TU',3 => 'WE',4 => 'TH',5 => 'FR',6 => 'SA',7 => 'SU');
388
389 $checked_days = array();
390 foreach($this->recurrence->getBYDAYList() as $byday)
391 {
392 if(in_array($byday,$days))
393 {
394 $checked_days[] = $byday;
395 }
396 }
397
398 for($i = (int) $this->user_settings->getWeekStart();$i < 7 + (int) $this->user_settings->getWeekStart();$i++)
399 {
400 $tpl->setCurrentBlock('byday_simple');
401
402 if(in_array($days[$i],$checked_days))
403 {
404 $tpl->setVariable('BYDAY_WEEKLY_CHECKED','checked="checked"');
405 }
406 $tpl->setVariable('TXT_ON',$this->lng->txt('cal_on'));
407 $tpl->setVariable('BYDAY_WEEKLY_VAL',$days[$i]);
408 $tpl->setVariable('TXT_DAY_SHORT',ilCalendarUtil::_numericDayToString($i,false));
409 $tpl->parseCurrentBlock();
410 }
411
412 }
413
422 {
423 $byday_list = $this->recurrence->getBYDAYList();
424 $chosen_num_day = 1;
425 $chosen_day = 'MO';
426 $chosen = false;
427 foreach($byday_list as $byday)
428 {
429 if(preg_match('/^(-?\d)([A-Z][A-Z])/',$byday,$parsed) === 1)
430 {
431 $chosen = true;
432 $chosen_num_day = $parsed[1];
433 $chosen_day = $parsed[2];
434 }
435 }
436 // check for last day
437 if(count($this->recurrence->getBYMONTHDAYList()) == 1)
438 {
439 $bymonthday = $this->recurrence->getBYMONTHDAY();
440 if(in_array($bymonthday,array(1,2,3,4,5,-1)))
441 {
442 $chosen = true;
443 $chosen_num_day = $bymonthday;
444 $chosen_day = 9;
445 }
446 }
447 // Check for first, second... last weekday
448 if(count($this->recurrence->getBYSETPOSList()) == 1)
449 {
450 $bysetpos = $this->recurrence->getBYSETPOS();
451 if(in_array($bysetpos,array(1,2,3,4,5,-1)))
452 {
453 if($this->recurrence->getBYDAYList() == array('MO','TU','WE','TH','FR'))
454 {
455 $chosen = true;
456 $chosen_num_day = $bysetpos;
457 $chosen_day = 8;
458 }
459 }
460 }
461
462
463
464 if($chosen)
465 {
466 $tpl->setVariable('M_BYDAY_CHECKED','checked="checked"');
467 }
468
469 $num_options = array(
470 1 => $this->lng->txt('cal_first'),
471 2 => $this->lng->txt('cal_second'),
472 3 => $this->lng->txt('cal_third'),
473 4 => $this->lng->txt('cal_fourth'),
474 5 => $this->lng->txt('cal_fifth'),
475 -1 => $this->lng->txt('cal_last'));
476
477 $tpl->setVariable('SELECT_BYDAY_NUM_MONTHLY',ilUtil::formSelect(
478 $chosen_num_day,
479 'monthly_byday_num',
480 $num_options,
481 false,
482 true,
483 '',
484 '',
485 array('onchange' => "ilUpdateSubTypeSelection('sub_monthly_radio_1');")));
486
487 $days = array(0 => 'SU',1 => 'MO',2 => 'TU',3 => 'WE',4 => 'TH',5 => 'FR',6 => 'SA',7 => 'SU');
488
489 for($i = (int) $this->user_settings->getWeekStart();$i < 7 + (int) $this->user_settings->getWeekStart();$i++)
490 {
491 $days_select[$days[$i]] = ilCalendarUtil::_numericDayToString($i);
492 }
493 $days_select[8] = $this->lng->txt('cal_weekday');
494 $days_select[9] = $this->lng->txt('cal_day_of_month');
495 $tpl->setVariable('SEL_BYDAY_DAY_MONTHLY',ilUtil::formSelect(
496 $chosen_day,
497 'monthly_byday_day',
498 $days_select,
499 false,
500 true,
501 '',
502 '',
503 array('onchange' => "ilUpdateSubTypeSelection('sub_monthly_radio_1');")));
504 }
505
514 {
515 $tpl->setVariable('TXT_IN',$this->lng->txt('cal_in'));
516
517 $chosen_day = 1;
518 $chosen = false;
519 if(count($bymonthday = $this->recurrence->getBYMONTHDAYList()) == 1)
520 {
521 foreach($bymonthday as $mday)
522 {
523 if($mday > 0 and $mday < 32)
524 {
525 $chosen = true;
526 $chosen_day = $mday;
527 }
528 }
529 }
530
531 if($chosen)
532 {
533 $tpl->setVariable('M_BYMONTHDAY_CHECKED','checked="checked"');
534 }
535
536 for($i = 1; $i < 32;$i++)
537 {
538 $options[$i] = $i;
539 }
540 $tpl->setVariable('SELECT_BYMONTHDAY',ilUtil::formSelect(
541 $chosen_day,
542 'monthly_bymonthday',
543 $options,
544 false,
545 true,
546 '',
547 '',
548 array('onchange' => "ilUpdateSubTypeSelection('sub_monthly_radio_2');")));
549 }
550
559 {
560 $tpl->setVariable('TXT_Y_EVERY',$this->lng->txt('cal_every'));
561
562
563 $chosen = false;
564 $chosen_month = 1;
565 $chosen_day = 1;
566 foreach($this->recurrence->getBYMONTHList() as $month)
567 {
568 if($this->recurrence->getBYMONTHDAYList())
569 {
570 $chosen_month = $month;
571 $chosen = true;
572 break;
573 }
574 }
575 foreach($this->recurrence->getBYMONTHDAYList() as $day)
576 {
577 $chosen_day = $day;
578 }
579
580 for($i = 1; $i < 32;$i++)
581 {
582 $options[$i] = $i;
583 }
584 $tpl->setVariable('SELECT_BYMONTHDAY_NUM_YEARLY',ilUtil::formSelect(
585 $chosen_day,
586 'yearly_bymonthday',
587 $options,
588 false,
589 true,
590
591 '',
592 '',
593 array('onchange' => "ilUpdateSubTypeSelection('sub_yearly_radio_2');")));
594
595 $options = array();
596 for($m = 1;$m < 13;$m++)
597 {
599 }
600 $tpl->setVariable('SELECT_BYMONTH_YEARLY',ilUtil::formSelect(
601 $chosen_month,
602 'yearly_bymonth_by_monthday',
603 $options,
604 false,
605 true,
606 '',
607 '',
608 array('onchange' => "ilUpdateSubTypeSelection('sub_yearly_radio_2');")));
609
610
611 if($chosen)
612 {
613 $tpl->setVariable('Y_BYMONTHDAY_CHECKED','checked="checked"');
614 }
615
616 }
617
625 protected function buildYearlyByDaySelection($tpl)
626 {
627 $tpl->setVariable('TXT_ON_THE',$this->lng->txt('cal_on_the'));
628
629 $chosen_num_day = 1;
630 $chosen_day = 'MO';
631 $chosen = false;
632 foreach($this->recurrence->getBYDAYList() as $byday)
633 {
634 if(preg_match('/^(-?\d)([A-Z][A-Z])/',$byday,$parsed) === 1)
635 {
636 $chosen = true;
637 $chosen_num_day = $parsed[1];
638 $chosen_day = $parsed[2];
639 }
640 }
641
642
643 $num_options = array(
644 1 => $this->lng->txt('cal_first'),
645 2 => $this->lng->txt('cal_second'),
646 3 => $this->lng->txt('cal_third'),
647 4 => $this->lng->txt('cal_fourth'),
648 5 => $this->lng->txt('cal_fifth'),
649 -1 => $this->lng->txt('cal_last'));
650
651 $tpl->setVariable('SELECT_BYDAY_NUM_YEARLY',ilUtil::formSelect(
652 $chosen_num_day,
653 'yearly_byday_num',
654 $num_options,
655 false,
656 true,
657 '',
658 '',
659 array('onchange' => "ilUpdateSubTypeSelection('sub_yearly_radio_1');")));
660
661
662 $days = array(0 => 'SU',1 => 'MO',2 => 'TU',3 => 'WE',4 => 'TH',5 => 'FR',6 => 'SA',7 => 'SU');
663 for($i = (int) $this->user_settings->getWeekStart();$i < 7 + (int) $this->user_settings->getWeekStart();$i++)
664 {
665 $days_select[$days[$i]] = ilCalendarUtil::_numericDayToString($i);
666 }
667 $tpl->setVariable('SELECT_BYDAY_DAY_YEARLY',ilUtil::formSelect(
668 $chosen_day,
669 'yearly_byday',
670 $days_select,
671 false,
672 true,
673 '',
674 '',
675 array('onchange' => "ilUpdateSubTypeSelection('sub_yearly_radio_1');")));
676
677
678 $chosen = false;
679 $chosen_month = 1;
680 foreach($this->recurrence->getBYMONTHList() as $month)
681 {
682 if($this->recurrence->getBYMONTHDAYList())
683 {
684 $chosen_month = $month;
685 $chosen = true;
686 break;
687 }
688 }
689 $options = array();
690 for($m = 1;$m < 13;$m++)
691 {
693 }
694 $tpl->setVariable('SELECT_BYMONTH_BYDAY',ilUtil::formSelect(
695 $chosen_month,
696 'yearly_bymonth_byday',
697 $options,
698 false,
699 true,
700 '',
701 '',
702 array('onchange' => "ilUpdateSubTypeSelection('sub_yearly_radio_1');")));
703
704 }
705
713 protected function buildUntilSelection($tpl)
714 {
715
717 {
718 $tpl->setVariable('TXT_NO_ENDING',$this->lng->txt('cal_no_ending'));
719 }
720
721 $tpl->setVariable('TXT_UNTIL_CREATE',$this->lng->txt('cal_create'));
722 $tpl->setVariable('TXT_APPOINTMENTS',$this->lng->txt('cal_appointments'));
723
724 $tpl->setVariable('VAL_COUNT',$this->recurrence->getFrequenceUntilCount() ?
725 $this->recurrence->getFrequenceUntilCount() :
726 2);
727
728 if($this->recurrence->getFrequenceUntilDate())
729 {
730 $tpl->setVariable('UNTIL_END_CHECKED','checked="checked"');
731 }
732 elseif($this->recurrence->getFrequenceUntilCount() or !$this->isUnlimitedRecurrenceAllowed())
733 {
734 $tpl->setVariable('UNTIL_COUNT_CHECKED','checked="checked"');
735 }
736 else
737 {
738 $tpl->setVariable('UNTIL_NO_CHECKED','checked="checked"');
739 }
740
741 $tpl->setVariable('TXT_UNTIL_END',$this->lng->txt('cal_repeat_until'));
742 $dt = new ilDateTimeInputGUI('','until_end');
743 // no proper subform
744 // $dt->setRequired(true);
745 $dt->setDate(
746 $this->recurrence->getFrequenceUntilDate() ? $this->recurrence->getFrequenceUntilDate() : null);
747 $tpl->setVariable('UNTIL_END_DATE',$dt->getTableFilterHTML());
748 }
749}
750?>
global $tpl
Definition: ilias.php:8
$_POST["username"]
An exception for terminatinating execution or to throw for unit testing.
const IL_CAL_FREQ_YEARLY
const IL_CAL_FREQ_MONTHLY
const IL_CAL_FREQ_WEEKLY
static _getInstanceByUserId($a_user_id)
get singleton instance
static _numericDayToString($a_day, $a_long=true)
get
static _numericMonthToString($a_month, $a_long=true)
numeric month to string
This class represents a custom property in a property form.
This class represents a date/time property in a property form.
setAlert($a_alert)
Set Alert Text.
This class represents an input GUI for recurring events/appointments (course events or calendar appoi...
getEnabledSubForms()
get enabled subforms
setRecurrence($a_rec)
set recurrence object
buildYearlyByDaySelection($tpl)
@access protected
buildMonthlyByMonthDaySelection($tpl)
build monthly bymonthday selection
loadRecurrence()
load recurrence settings @access protected
buildWeekDaySelection($tpl)
build weekday checkboxes
buildYearlyByMonthDaySelection($tpl)
@access protected
buildUntilSelection($tpl)
build selection for ending date
allowUnlimitedRecurrences($a_status)
Allow unlimited recurrences.
buildMonthlyByDaySelection($tpl)
build monthly by day list (e.g second monday)
setEnabledSubForms($a_sub_forms)
set enabled subforms
__construct($a_title, $a_postvar)
Constructor.
isUnlimitedRecurrenceAllowed()
Check if unlimited recurrence is allowed.
special template class to simplify handling of ITX/PEAR
static stripSlashes($a_str, $a_strip_html=true, $a_allow="")
strip slashes if magic qoutes is enabled
static formSelect($selected, $varname, $options, $multiple=false, $direct_text=false, $size="0", $style_class="", $attribs="", $disabled=false)
Builds a select form field with options and shows the selected option first.
const IL_CAL_FREQ_DAILY
Model of calendar entry recurrcences.
if(!is_array($argv)) $options
$ilUser
Definition: imgupload.php:18