Squiz Matrix  4.12.2
 All Data Structures Namespaces Functions Variables Pages
calendar_event_recurring_edit_fns.inc
1 <?php
18 require_once dirname(__FILE__).'/../../calendar_event/calendar_event_edit_fns.inc';
19 
32 {
33 
34 
40  {
41  $this->Asset_Edit_Fns();
42  $this->static_screens['details']['force_unlock'] = FALSE;
43 
44  }//end constructor
45 
46 
57  function paintFrequencyField(&$asset, &$o, $prefix)
58  {
59  $freq = $asset->attr('frequency');
60  if (!$freq) $freq = ' ';
61  $stop_date_attr =& $asset->getAttribute('stop_date');
62  if (($stopdate = $stop_date_attr->getTimestamp()) == -1) {
63  $stopdate = FALSE;
64  }
65 
66  if ($asset->writeAccess('attributes')) {
67  ?>
68  <script type="text/javascript" src="<?php echo sq_web_path('data').'/asset_types/calendar_event_recurring/js/frequency_chooser.js'?>"></script>
69 
70  <table border="0" cellpadding="0" cellspacing="0" width="100%" style="white-space: nowrap">
71  <tr style="height: 11ex">
72 
73  <!-- Overall Frequency Types -->
74  <td style="width: 12ex; vertical-align: top">
75 
76  <input type="radio" <?php echo ((($freq{0} == 'D') || !$freq) ? 'checked="checked" ' : '') ?> name="<?php echo $prefix; ?>_frequency" id="<?php echo $prefix; ?>_frequency_daily" value="daily" onkeypress="this.click();" onclick="showFreqOptions('<?php echo $prefix; ?>', 'Daily'); checkBox('<?php echo $prefix?>_frequency_type_DED');" />
77  <label for="<?php echo $prefix; ?>_frequency_daily">Daily</label>
78  <br />
79 
80  <input type="radio" <?php echo (($freq{0} == 'W') ? 'checked="checked" ' : '') ?> name="<?php echo $prefix; ?>_frequency" id="<?php echo $prefix; ?>_frequency_weekly" value="weekly" onkeypress="this.click();" onclick="showFreqOptions('<?php echo $prefix; ?>', 'Weekly'); checkBox('<?php echo $prefix?>_frequency_type_WEW');" />
81  <label for="<?php echo $prefix; ?>_frequency_weekly">Weekly</label>
82  <br />
83 
84  <input type="radio" <?php echo (($freq{0} == 'M') ? 'checked="checked" ' : '') ?> name="<?php echo $prefix; ?>_frequency" id="<?php echo $prefix; ?>_frequency_monthly" value="monthly" onkeypress="this.click();" onclick="showFreqOptions('<?php echo $prefix; ?>', 'Monthly'); checkBox('<?php echo $prefix?>_frequency_type_M');" />
85  <label for="<?php echo $prefix; ?>_frequency_monthly">Monthly</label>
86  <br />&nbsp;<br />
87 
88  </td>
89 
90  <td style="vertical-align: top; ">
91 
92  <!-- Daily Options -->
93  <div id="<?php echo $prefix; ?>DailyOptions" style="display: <?php echo (($freq{0} == 'D') ? 'block' : 'none') ?>">
94  <input type="radio" <?php echo ((($freq == 'DED') || !$freq) ? 'checked="checked" ' : '')?> name="<?php echo $prefix; ?>_frequency_type" id="<?php echo $prefix; ?>_frequency_type_DED" value="DED" /><?php echo translate('cal_event_every_day'); ?>
95  <?php
96  // Every 'X' days textbox
97  ob_start(); ?>
98  <input type="text" size="2" value="<?php echo trim(substr($freq, 3)); ?>" name="<?php echo $prefix; ?>_num_days" onkeypress="this.click();" onclick="checkBox('<?php echo $prefix?>_frequency_type_DEDx');" />
99  <?php $x_days_tb = ob_get_contents();
100  ob_end_clean(); ?>
101  <br /><input type="radio" <?php echo ((($freq != 'DED') && (substr($freq, 0, 3) == 'DED')) ? 'checked="checked" ' : '')?> name="<?php echo $prefix; ?>_frequency_type" id="<?php echo $prefix; ?>_frequency_type_DEDx" value="DEDx" /><?php echo translate('cal_event_every_x_days', $x_days_tb); ?>
102  <br /><input type="radio" <?php echo (((substr($freq, 0, 3) == 'DWD')) ? 'checked="checked" ' : '')?> name="<?php echo $prefix; ?>_frequency_type" id="<?php echo $prefix; ?>_frequency_type_DWD" value="DWD" /><?php echo translate('cal_event_every_weekday'); ?>
103  <br /><input type="radio" <?php echo (((substr($freq, 0, 3) == 'DWE')) ? 'checked="checked" ' : '')?> name="<?php echo $prefix; ?>_frequency_type" id="<?php echo $prefix; ?>_frequency_type_DWE" value="DWE" /><?php echo translate('cal_event_every_weekend'); ?>
104  </div>
105 
106  <!-- Weekly Options -->
107  <div id="<?php echo $prefix; ?>WeeklyOptions" style="display: <?php echo (($freq{0} == 'W') ? 'block' : 'none') ?>">
108  <?php
109  // link to weekday on Week links
110  ob_start(); ?>
111  <a href="javascript: document.getElementById('<?php echo $prefix ?>_start_day').focus();" id="<?php echo $prefix ?>_week_day"></a>
112  <?php $week_link = ob_get_contents();
113  ob_end_clean();
114 
115  // link to weekday on Every 'X' Weeks link
116  ob_start(); ?>
117  <a id="<?php echo $prefix ?>_week_day_4" href="javascript: document.getElementById('<?php echo $prefix ?>_start_day').focus();"></a>
118  <?php $x_weeks_link = ob_get_contents();
119  ob_end_clean();
120 
121  // Every 'X' weeks textbox
122  ob_start(); ?>
123  <input type="text" size="2" value="<?php echo substr($freq, 3); ?>" name="<?php echo $prefix ?>_num_weeks" onkeypress="this.click();" onclick="checkBox('<?php echo $prefix?>_frequency_type_WEWx');" />
124  <?php $x_weeks_tb = ob_get_contents();
125  ob_end_clean(); ?>
126  <input type="radio" <?php echo ((($freq == 'WEW') || !$freq) ? 'checked="checked" ' : '')?> name="<?php echo $prefix; ?>_frequency_type" id="<?php echo $prefix; ?>_frequency_type_WEW" value="WEW" /><?php echo translate('cal_event_every_week', $week_link); ?>
127  <br /><input type="radio" <?php echo ((($freq != 'WEW') && (substr($freq,0,3) == 'WEW')) ? 'checked="checked" ' : '')?> name="<?php echo $prefix; ?>_frequency_type" id="<?php echo $prefix; ?>_frequency_type_WEWx" value="WEWx" /><?php echo translate('cal_event_every_x_weeks', $x_weeks_tb, $x_weeks_link); ?>
128  </div>
129 
130  <!-- Monthly options -->
131  <table border="0" cellpadding="0" cellspacing="0" id="<?php echo $prefix; ?>MonthlyOptions" style="display: <?php echo (($freq{0} == 'M') ? 'block' : 'none') ?>"><tr>
132 
133  <td style="width: 25ex; vertical-align: top">
134  <?php
135  // Every 'X' months textbox
136  ob_start(); ?>
137  <input type="text" size="2" value="<?php echo substr($freq, 3); ?>" name="<?php echo $prefix ?>_num_months" onkeypress="this.click();" onclick="checkBox('<?php echo $prefix?>_frequency_type_Mx');" />
138  <?php $x_months_tb = ob_get_contents();
139  ob_end_clean();
140  ?>
141  <input type="radio" <?php echo ((($freq{0}=='M') && (strlen($freq) == 3)) ? 'checked="checked" ' : ''); ?> name="<?php echo $prefix; ?>_frequency_type" id="<?php echo $prefix; ?>_frequency_type_M" value="M"><?php echo translate('cal_event_every_month'); ?>
142  <br /><input type="radio" <?php echo ((($freq{0}=='M') && (strlen($freq) != 3)) ? 'checked="checked" ' : ''); ?> name="<?php echo $prefix; ?>_frequency_type" id="<?php echo $prefix; ?>_frequency_type_Mx" value="Mx"><?php echo translate('cal_event_every_x_months', $x_months_tb); ?>
143  </td>
144  <td style="width: 60ex">
145  <?php
146  // link to day number on Every 'X' Months on Day link
147  ob_start(); ?>
148  <a href="javascript: document.getElementById('<?php echo $prefix ?>_start_day').focus();" id="<?php echo $prefix; ?>_month_date_ord"></a>
149  <?php $mfn_month_link = ob_get_contents();
150  ob_end_clean(); ?>
151 
152  <input type="radio" <?php echo ((($freq{0} != 'M') || (substr($freq, 0, 3) == 'MFN')) ? 'checked="checked" ' : ''); ?> name="<?php echo $prefix; ?>_monthly_type" value="MFN" /><?php echo translate('cal_event_month_on_day', $mfn_month_link) ?><span id="<?php echo $prefix; ?>_month_date_warning" style="display: none"><?php echo translate('cal_event_when_it_exists') ?></span><br />
153 
154  <?php
155  // link to day number on Every 'X' Months on Weekday link
156  ob_start(); ?>
157  <a href="javascript: document.getElementById('<?php echo $prefix ?>_start_day').focus();" id="<?php echo $prefix; ?>_month_week_ord"></a>
158  <?php $mfw_month_link = ob_get_contents();
159  ob_end_clean();
160 
161  // link to weekday on Every 'X' Months on Weekday link
162  ob_start(); ?>
163  <a href="javascript: document.getElementById('<?php echo $prefix ?>_start_day').focus();" id="<?php echo $prefix; ?>_week_day_2"></a>
164  <?php $mfw_day_link = ob_get_contents();
165  ob_end_clean(); ?>
166  <input type="radio" <?php echo ((substr($freq, 0, 3) == 'MFW') ? 'checked="checked" ' : ''); ?>name="<?php echo $prefix; ?>_monthly_type" value="MFW" /><?php echo translate('cal_event_month_on_weekday', $mfw_month_link, $mfw_day_link) ?> <span id="<?php echo $prefix; ?>_month_week_warning" style="display: none"><?php echo translate('cal_event_when_it_exists') ?></span><br />
167 
168  <?php
169  // link to day number on Every 'X' Months on Last Day link
170  ob_start(); ?>
171  <a href="javascript: document.getElementById('<?php echo $prefix ?>_start_day').focus();" id="<?php echo $prefix; ?>_reverse_month_date_ord"></a><a href="javascript: document.getElementById('<?php echo $prefix ?>_start_day').focus();"><?php echo translate('last') ?></a>
172  <?php $mrn_month_link = ob_get_contents();
173  ob_end_clean(); ?>
174  <input type="radio" <?php echo ((substr($freq, 0, 3) == 'MRN') ? 'checked="checked" ' : ''); ?> name="<?php echo $prefix; ?>_monthly_type" value="MRN" /><?php echo translate('cal_event_month_on_last_day', $mrn_month_link) ?> <span id="<?php echo $prefix ?>_reverse_month_date_warning" style="display: none"><?php echo translate('cal_event_when_it_exists') ?></span><br />
175 
176  <?php
177  // link to day number on Every 'X' Months on Last Weekday link
178  ob_start(); ?>
179  <a href="javascript: document.getElementById('<?php echo $prefix ?>_start_day').focus();" id="<?php echo $prefix; ?>_reverse_month_week_ord"></a><a href="javascript: document.getElementById('<?php echo $prefix ?>_start_day').focus();"><?php echo translate('last') ?></a>
180  <?php $mrw_month_link = ob_get_contents();
181  ob_end_clean();
182 
183  // link to weekday on Every 'X' Months on Weekday link
184  ob_start(); ?>
185  <a href="javascript: document.getElementById('<?php echo $prefix ?>_start_day').focus();" id="<?php echo $prefix; ?>_week_day_3"></a>
186  <?php $mrw_day_link = ob_get_contents();
187  ob_end_clean(); ?>
188  <input type="radio" <?php echo ((substr($freq, 0, 3) == 'MRW') ? 'checked="checked" ' : ''); ?> name="<?php echo $prefix; ?>_monthly_type" value="MRW" /><?php echo translate('cal_event_month_on_last_weekday', $mrw_month_link, $mrw_day_link) ?> <span id="<?php echo $prefix; ?>_reverse_month_week_warning" style="display: none"><?php echo translate('cal_event_when_it_exists') ?></span>
189  </td>
190  </tr></table>
191 
192  </td>
193  </tr>
194 
195  <tr>
196  <!-- Stop Date -->
197  <td colspan="2">
198  <?php
199  ob_start();
200  parent::printDateChooser($prefix.'_stop', $stopdate);
201  $date_chooser = ob_get_contents();
202  ob_end_clean(); ?>
203  <input type="radio" name="<?php echo $prefix; ?>_stop_date_selected" value="0" <?php echo ($stopdate ? '' : 'checked="checked" '); ?> onkeypress="this.click();" onclick="disableDateField('<?php echo $prefix; ?>_stop')" /><?php echo ucfirst(translate('cal_event_recur_until_further_notice')); ?>
204  <br /><input type="radio" <?php echo ($stopdate ? 'checked="checked" ' : ''); ?> name="<?php echo $prefix; ?>_stop_date_selected" value="1" onkeypress="this.click();" onclick="enableDateField('<?php echo $prefix; ?>_stop')" /><?php echo ucfirst(translate('cal_event_recur_until_date', '')).$date_chooser; ?>
205  </td>
206  </tr>
207 
208  </table>
209 
210  <script type="text/javascript"><!--
211  //<![CDATA[
212  updateValues('<?php echo $prefix; ?>');
213  //]]> -->
214  </script>
215  <?php
216 
217  hidden_field($prefix.'_frequency_field_printed', 1);
218 
219  } else {
220  echo $asset->getFriendlyFrequency();
221  }
222 
223  return TRUE;
224 
225  }//end paintFrequencyField()
226 
227 
238  function processFrequencyField(&$asset, &$o, $prefix)
239  {
240  // Do not process further if the Frequency Field interface is not printed to the user.
241  // This can occur when a Simple Edit Layout does not include this field.
242  if (!(isset($_REQUEST[$prefix.'_frequency_field_printed']) && ($_REQUEST[$prefix.'_frequency_field_printed'] == 1))) {
243  return FALSE;
244  }
245 
246  $res = TRUE;
247  if (isset($_REQUEST[$prefix.'_stop_date_selected']) && ($_REQUEST[$prefix.'_stop_date_selected'])) {
248  $_REQUEST[$prefix.'_stop_year'] = (int)$_REQUEST[$prefix.'_stop_year'];
249  if (($_REQUEST[$prefix.'_stop_year'] < 1900) || ($_REQUEST[$prefix.'_stop_year'] > 2100)) {
250  trigger_localised_error('CAL0039', E_USER_WARNING);
251  return FALSE;
252  }
253  $_REQUEST[$prefix.'_stop_month'] = (int)$_REQUEST[$prefix.'_stop_month'];
254  if (($_REQUEST[$prefix.'_stop_month'] < 1) || ($_REQUEST[$prefix.'_stop_month'] > 12)) {
255  trigger_localised_error('CAL0040', E_USER_WARNING);
256  return FALSE;
257  }
258  $_REQUEST[$prefix.'_stop_day'] = (int)$_REQUEST[$prefix.'_stop_day'];
259  if (($_REQUEST[$prefix.'_stop_day'] < 1) || ($_REQUEST[$prefix.'_stop_day'] > 31)) {
260  trigger_localised_error('CAL0041', E_USER_WARNING);
261  return FALSE;
262  }
263  $res &= $asset->setAttrValue('stop_date', sprintf('%04d-%02d-%02d', $_REQUEST[$prefix.'_stop_year'], $_REQUEST[$prefix.'_stop_month'], $_REQUEST[$prefix.'_stop_day']).' --:--:--');
264  } else {
265  $res &= $asset->setAttrValue('stop_date', '---------- --:--:--');
266  }
267  $interval = '';
268 
269  // do this so it doesn't give undefined index errors in the switch if nothing is set
270  if (empty($_REQUEST[$prefix.'_frequency_type'])) {
271  $_REQUEST[$prefix.'_frequency_type'] = '';
272  }
273 
274  switch ($_REQUEST[$prefix.'_frequency_type']) {
275  case 'DED':
276  case 'DWD':
277  case 'DWE':
278  case 'WEW':
279  $frequency = $_REQUEST[$prefix.'_frequency_type'];
280  break;
281 
282  case 'DEDx':
283  if ((($interval = (int)$_REQUEST[$prefix.'_num_days']) > 0)) {
284  $frequency = 'DED'.$interval;
285  } else {
286  trigger_localised_error('CAL0042', E_USER_WARNING);
287  return FALSE;
288  }
289  break;
290 
291  case 'WEWx':
292  if ((($interval = (int)$_REQUEST[$prefix.'_num_weeks']) > 0)) {
293  $frequency = 'WEW'.$interval;
294  } else {
295  trigger_localised_error('CAL0043', E_USER_WARNING);
296  return FALSE;
297  }
298  break;
299 
300  case 'M':
301  if (isset($_REQUEST[$prefix.'_monthly_type']) && in_array($_REQUEST[$prefix.'_monthly_type'], Array('MFN', 'MFW', 'MRN', 'MRW'))) {
302  $frequency = $_REQUEST[$prefix.'_monthly_type'];
303  } else {
304  trigger_localised_error('CAL0044', E_USER_WARNING);
305  return FALSE;
306  }
307  break;
308 
309  case 'Mx':
310  if (in_array($_REQUEST[$prefix.'_monthly_type'], Array('MFN', 'MFW', 'MRN', 'MRW'))) {
311  if ((($interval = (int)$_REQUEST[$prefix.'_num_months']) > 0)) {
312  $frequency = $_REQUEST[$prefix.'_monthly_type'].$interval;
313  } else {
314  trigger_localised_error('CAL0045', E_USER_WARNING);
315  return FALSE;
316  }
317  } else {
318  trigger_localised_error('CAL0046', E_USER_WARNING);
319  return FALSE;
320  }
321  break;
322 
323  default:
324  return FALSE;
325  break;
326  }//end switch
327  $res &= $asset->setAttrValue('frequency', $frequency);
328  return $res;
329 
330  }//end processFrequencyField()
331 
332 
343  function paintRecurringStartEndChooser(&$asset, &$o, $prefix)
344  {
345  if ($asset->writeAccess('attributes')) {
346  $this->paintStartEndChooser($asset, $prefix, Array('onchange'=>'updateValues(\''.$prefix.'\');', 'onkeyup'=>'updateValues(\''.$prefix.'\');'));
347  } else {
348  echo $asset->getFriendlyDatesAndTimes();
349  }
350  return TRUE;
351 
352  }//end paintRecurringStartEndChooser()
353 
354 
365  function processRecurringStartEndChooser(&$asset, &$o, $prefix)
366  {
367  $this->processStartEndChooser($asset, $o, $prefix);
368 
369  }//end processRecurringStartEndChooser()
370 
371 
372 }//end class
373 
374 ?>