17 require_once SQ_INCLUDE_PATH.
'/asset_edit/asset_edit_fns.inc';
18 require_once SQ_FUDGE_PATH.
'/datetime_field/datetime_field.inc';
42 $this->static_screens[
'details'][
'force_unlock'] = FALSE;
59 $occurrence_end_ts = (isset($_REQUEST[
'SQ_CALENDAR_DATE']) && (!$asset->getEndDate())) ? strtotime($_REQUEST[
'SQ_CALENDAR_DATE'].
' '.($asset->getEndTime() ? $asset->getEndTime() :
'12:00:00 GMT')) : FALSE;
60 $end_disabled_code = (($asset->getEndTime() || $asset->getEndDate()) || (isset($_REQUEST[
'SQ_CALENDAR_DURATION']))) ?
'' :
'disabled="disabled"';
61 $end_disabled_array = $end_disabled_code ? Array(
'disabled'=>
'disabled') : Array();
63 $duration_units =
'i';
64 if ($d = ($asset->getDuration() / 60)) $duration = $d;
65 if (isset($_REQUEST[
'SQ_CALENDAR_DURATION'])) {
66 list($duration, $duration_units) = explode(
'_', $_REQUEST[
'SQ_CALENDAR_DURATION']);
69 $duration = $duration / 60;
70 $duration_units =
'h';
72 $duration = $duration / 24;
73 $duration_units =
'd';
78 <script type=
"text/javascript" src=
"<?php echo sq_web_path('data').'/asset_types/calendar_event/js/date_chooser.js'?>"></script>
81 <table border=
"0" cellpadding=
"0" cellspacing=
"0" style=
"margin-bottom: 1ex">
83 <td
class=
"sq-backend-data" style=
"vertical-align: bottom; white-space: nowrap"> <?php echo translate(
'cal_event_occurs_on') ?>
84 <?php $this->
printDateChooser($prefix.
'_start', (isset($_REQUEST[
'SQ_CALENDAR_DATE']) && !$asset->id) ? strtotime($_REQUEST[
'SQ_CALENDAR_DATE']) : ($asset->getStartDate() ? iso8601_ts($asset->attr(
'start_date')) : 0), $attributes+Array(
'onkeypress'=>
'processKeyEvent(this)',
'onfocus'=>
'currentField=this',
'onblur'=>
'currentField=null; oldField=this; setTimeout(\'processStartDateBlur(oldField, \\\''.$prefix.
'\\\')\', 10);')); ?>
86 <td
class=
"sq-backend-data" style=
"white-space: nowrap">
87 <?php $this->
printTimeChooser($prefix.
'_start', isset($_REQUEST[
'SQ_CALENDAR_TIME']) ? strtotime($_REQUEST[
'SQ_CALENDAR_TIME']) : ($asset->getStartTime() ? iso8601_ts($asset->attr(
'start_date')) : FALSE), $attributes+Array(
'onkeypress'=>
'processKeyEvent(this)',
'onfocus'=>
'currentField=this',
'onblur'=>
'currentField=null; oldField=this; setTimeout(\'processStartDateBlur(oldField, \\\''.$prefix.
'\\\')\', 10);'), Array(
'onclick'=>
'if (isChecked(\''.$prefix.
'_end_enabled\')) { if (this.checked) enableTimeField(\''.$prefix.
'_end\'); else disableTimeField(\''.$prefix.
'_end\'); } else { if (this.checked) { checkBox(\''.$prefix.
'_end_time_enabled\'); } else { uncheckBox(\''.$prefix.
'_end_time_enabled\'); } } ')); ?>
93 <table border=
"0" cellpadding=
"0" cellspacing=
"0">
95 <td
class=
"sq-backend-data" style=
"white-space: nowrap">
96 <?php $checked = $asset->getEndDate() || isset($_REQUEST[
'SQ_CALENDAR_DURATION']); ?>
97 <input name=
"<?php echo $prefix ?>_end_enabled" id=
"<?php echo $prefix ?>_end_enabled" type=
"checkbox" <?php
if ($checked) echo
' checked="checked" '; ?> onclick=
"processEndClick(this, '<?php echo $prefix; ?>');"/> runs
100 <td
class=
"sq-backend-data" style=
"white-space: nowrap">
101 <input type=
"radio" value=
"duration" id=
"<?php echo $prefix; ?>_duration_enabled" name=
"<?php echo $prefix; ?>_end_type" <?php
if (!$asset->id) echo
'checked="checked"'; ?> <?php echo $end_disabled_code; ?> /> <?php echo strtolower(translate(
'for')); ?>
103 <td colspan=
"2" class=
"sq-backend-data" style=
"white-space: nowrap">
104 <?php text_box($prefix.
'_duration', $duration, 2, 0, 0,
'onclick="checkBox(\''.$prefix.
'_duration_enabled\'); checkBox(\''.$prefix.
'_start_time_enabled\'); enableTimeField(\''.$prefix.
'_start\');" onblur="updateDurationValuesByPrefix(\''.$prefix.
'\')
" '.$end_disabled_code);
105 combo_box($prefix.'_duration_units', Array('i' => translate('minutes'), 'h' => translate('hours'), 'd' => translate('days')), FALSE, $duration_units, 0, 'onclick="checkBox(\
''.$prefix.
'_duration_enabled\'); checkBox(\''.$prefix.
'_start_time_enabled\'); enableTimeField(\''.$prefix.
'_start\');" onblur="updateDurationValuesByPrefix(\''.$prefix.
'\')
" '.$end_disabled_code); ?>
111 <td class="sq-backend-data
" style="white-space: nowrap
">
112 <input type="radio
" <?php if ($asset->id) echo 'checked="checked
"'; ?> value="date
" id="<?php echo $prefix; ?>_end_date_enabled
" name="<?php echo $prefix; ?>_end_type
" <?php echo $end_disabled_code; ?> /> <?php echo strtolower(translate('until')); ?>
114 <td class="sq-backend-data
" style="white-space: nowrap
">
115 <?php $this->printDateChooser($prefix.'_end', $occurrence_end_ts ? $occurrence_end_ts : ($asset->getEndDate() ? iso8601_ts($asset->attr('end_date')) : FALSE), $attributes+Array('onclick'=>'checkBox(\''.$prefix.'_end_date_enabled\');', 'onkeypress'=>'processKeyEvent(this)', 'onfocus'=>'currentField=this', 'onblur'=>'currentField=null; oldField=this; setTimeout(\'processEndDateBlur(oldField, \\\''.$prefix.'\\\')\', 10);')+$end_disabled_array); ?>
117 <td class="sq-backend-data
" style="white-space: nowrap
">
118 <?php $this->printTimeChooser($prefix.'_end', ($asset->getEndTime() ? iso8601_ts($asset->attr('end_date')) : ($asset->getStartTime() ? 0 : FALSE)), $attributes+Array('onclick'=>'checkBox(\''.$prefix.'_end_date_enabled\');', 'onkeypress'=>'processKeyEvent(this)', 'onfocus'=>'currentField=this', 'onblur'=>'currentField=null; oldField=this; setTimeout(\'processEndDateBlur(oldField, \\\''.$prefix.'\\\')\', 10);')+$end_disabled_array, Array('onclick'=>'if (this.checked) { checkBox(\''.$prefix.'_end_date_enabled\'); enableTimeField(\''.$prefix.'_start\'); } else disableTimeField(\''.$prefix.'_start\');')+$end_disabled_array); ?>
124 hidden_field($prefix.'_start_end_chooser_printed', 1);
127 }//end paintStartEndChooser()
139 function _validateDateTimeFields($prefix, $component)
141 if (isset($_REQUEST[$prefix.$component.'_time_enabled'])) {
142 // interpret AM/PM values and covert to 24hr time
143 if ($_REQUEST[$prefix.$component.'_is_pm']) {
144 if ($_REQUEST[$prefix.$component.'_hours'] != 12) {
145 $_REQUEST[$prefix.$component.'_hours'] += 12;
148 if ($_REQUEST[$prefix.$component.'_hours'] == 12) {
149 $_REQUEST[$prefix.$component.'_hours'] = 0;
152 $_REQUEST[$prefix.$component.'_hours'] = (int)$_REQUEST[$prefix.$component.'_hours'];
153 if (($_REQUEST[$prefix.$component.'_hours'] < 0) || ($_REQUEST[$prefix.$component.'_hours'] > 23)) {
154 trigger_localised_error('CAL0001', E_USER_WARNING, $_REQUEST[$prefix.$component.'_hours']);
157 $_REQUEST[$prefix.$component.'_minutes'] = (int)$_REQUEST[$prefix.$component.'_minutes'];
158 if (($_REQUEST[$prefix.$component.'_minutes'] < 0) || ($_REQUEST[$prefix.$component.'_minutes'] > 59)) {
159 trigger_localised_error('CAL0002', E_USER_WARNING, $_REQUEST[$prefix.$component.'_minutes']);
163 if (isset($_REQUEST[$prefix.$component.'_year'])) {
164 $_REQUEST[$prefix.$component.'_year'] = (int)$_REQUEST[$prefix.$component.'_year'];
165 if (($_REQUEST[$prefix.$component.'_year'] < 1900) || ($_REQUEST[$prefix.$component.'_year'] > 2100)) {
166 trigger_localised_error('CAL0003', E_USER_WARNING, $_REQUEST[$prefix.$component.'_year']);
169 $_REQUEST[$prefix.$component.'_month'] = (int)$_REQUEST[$prefix.$component.'_month'];
170 if (($_REQUEST[$prefix.$component.'_month'] < 1) || ($_REQUEST[$prefix.$component.'_month'] > 12)) {
171 trigger_localised_error('CAL0004', E_USER_WARNING, $_REQUEST[$prefix.$component.'_month']);
174 $_REQUEST[$prefix.$component.'_day'] = (int)$_REQUEST[$prefix.$component.'_day'];
175 if (($_REQUEST[$prefix.$component.'_day'] < 1) || ($_REQUEST[$prefix.$component.'_day'] > 31)) {
176 trigger_localised_error('CAL0005', E_USER_WARNING, $_REQUEST[$prefix.$component.'_day']);
182 }//end _validateDateTimeFields()
197 function processStartEndChooser(&$asset, &$o, $prefix)
199 if (isset($_REQUEST[$prefix.'_start_end_chooser_printed'])) {
200 $values = $this->getStartEndChooserResult($prefix);
201 if (FALSE === $values) return FALSE;
203 $res &= $asset->setAttrValue('start_date', $values['start']);
204 $res &= $asset->setAttrValue('end_date', $values['end']);
211 }//end processStartEndChooser()
224 function getStartEndChooserResult($prefix)
226 // begin with the start time
227 if (!$this->_validateDateTimeFields($prefix, '_start')) {
230 $start_date_value = $_REQUEST[$prefix.'_start_year'].'-'.sprintf("%02d
", $_REQUEST[$prefix.'_start_month']).'-'.sprintf("%02d
", $_REQUEST[$prefix.'_start_day']).' ';
231 if (isset($_REQUEST[$prefix.'_start_time_enabled'])) {
232 $start_date_value .= sprintf("%02d
", $_REQUEST[$prefix.'_start_hours']).':'
233 .sprintf("%02d
", $_REQUEST[$prefix.'_start_minutes']).':00';
235 $start_date_value .= '--:--:--';
238 // the end is more complex...
239 if (isset($_REQUEST[$prefix.'_end_enabled'])) {
240 if (!isset($_REQUEST[$prefix.'_end_type'])) {
241 trigger_localised_error('CAL0006', E_USER_WARNING);
244 if ($_REQUEST[$prefix.'_end_type'] == 'duration') {
245 if (!isset($_REQUEST[$prefix.'_duration'])) {
246 trigger_localised_error('CAL0007', E_USER_WARNING);
249 $start_ts = iso8601_ts($start_date_value);
250 switch ($_REQUEST[$prefix.'_duration_units']) {
252 $end_ts = $start_ts + ((int)$_REQUEST[$prefix.'_duration'] * 60);
255 $end_ts = $start_ts + ((int)$_REQUEST[$prefix.'_duration'] * 60 * 60);
258 if (isset($_REQUEST[$prefix.'_start_time_enabled'])) {
259 $end_ts = $start_ts + ((int)$_REQUEST[$prefix.'_duration'] * 60 * 60 * 24);
261 // if no start time, the duration is the number of days covered
262 $end_ts = $start_ts + (((int)$_REQUEST[$prefix.'_duration'] - 1) * 60 * 60 * 24);
266 $end_date_value = ts_iso8601($end_ts);
267 if (!isset($_REQUEST[$prefix.'_start_time_enabled'])) {
268 $end_date_value = substr($end_date_value, 0, 10).' --:--:--';
271 if (!$this->_validateDateTimeFields($prefix, '_end')) {
274 if (isset($_REQUEST[$prefix.'_end_time_enabled']) && isset($_REQUEST[$prefix.'_start_time_enabled'])) {
275 $end_date_value = $_REQUEST[$prefix.'_end_year'].'-'
276 .sprintf("%02d
", $_REQUEST[$prefix.'_end_month']).'-'
277 .sprintf("%02d
", $_REQUEST[$prefix.'_end_day']).' '
278 .sprintf("%02d
", $_REQUEST[$prefix.'_end_hours']).':'
279 .sprintf("%02d
", $_REQUEST[$prefix.'_end_minutes']).':00';
281 $end_date_value = $_REQUEST[$prefix.'_end_year'].'-'
282 .sprintf("%02d
", $_REQUEST[$prefix.'_end_month']).'-'
283 .sprintf("%02d
", $_REQUEST[$prefix.'_end_day']).' '
288 $end_date_value = '---------- --:--:--';
290 return Array('start' => $start_date_value, 'end' => $end_date_value);
292 }//end getStartEndChooserResult()
305 function printDateChooser($prefix, $timestamp=0, $attributes=Array())
307 $select_attributes = $attributes;
308 unset($select_attributes['onkeypress']);
310 foreach ($attributes as $name => $value) {
311 $attrs_code .= ' '.$name.'="'.$value.'"';
313 if ($timestamp === FALSE) {
314 if(!isset($attributes['disabled'])){
315 $attrs_code .= ' disabled="disabled
"';
318 if (!$timestamp) $timestamp = time();
320 <input class="sq-form-field
" style="width: 5ex
" type="text
" name="<?php echo $prefix; ?>_day
" id="<?php echo $prefix; ?>_day
" size="2
" value="<?php echo date(
'j', $timestamp); ?>
" <?php echo $attrs_code ?> />
322 <select class="sq-form-field
" name="<?php echo $prefix; ?>_month
" id="<?php echo $prefix; ?>_month
" <?php echo $attrs_code; ?>>
324 $currentMonth = date('n', $timestamp);
325 foreach (range(1, 12) as $monthNumber) {
326 echo ' <option '.(($monthNumber == $currentMonth) ? ' selected="selected
" ' : '').'value="'.$monthNumber.'">'.DateTime_Field::shortMonth($monthNumber)."</option>\n
";
331 <input class="sq-form-field
" type="text
" name="<?php echo $prefix; ?>_year
" id="<?php echo $prefix; ?>_year
" size="5
" value="<?php echo date(
'Y', $timestamp); ?>
" <?php echo $attrs_code; ?> />
335 }//end printDateChooser()
349 function printTimeChooser($prefix, $timestamp, $attributes=Array(), $checkbox_attributes=Array())
352 foreach ($attributes as $name => $value) {
353 $attrs_code .= ' '.$name.'="'.$value.'"';
355 if ($timestamp === FALSE) {
356 if(!isset($attributes['disabled'])){
357 $attrs_code .= ' disabled="disabled
"';
360 $checked_text = ($timestamp !== FALSE) ? 'checked="checked
"' : '';
361 if (!$timestamp) $timestamp = time();
363 if (!isset($checkbox_attributes['onclick'])) {
364 $checkbox_attributes['onclick'] = '';
366 $checkbox_attributes['onclick'] = 'if (this.checked) { enableTimeField(\''.$prefix.'\'); } else { disableTimeField(\''.$prefix.'\'); } '.$checkbox_attributes['onclick'];
367 $checkbox_attrs_code = '';
368 foreach ($checkbox_attributes as $name => $value) {
369 $checkbox_attrs_code .= ' '.$name.'="'.$value.'"';
372 <input class="sq-form-field
" type="checkbox
" <?php echo $checked_text ?> value="1
" name="<?php echo $prefix; ?>_time_enabled
" id="<?php echo $prefix; ?>_time_enabled
" <?php echo $checkbox_attrs_code; ?> />at
374 <input class="sq-form-field
" style="width: 5ex
" type="text
" name="<?php echo $prefix; ?>_hours
" id="<?php echo $prefix; ?>_hours
" size="2
" maxlength="2
" value="<?php echo date(
'g', $timestamp); ?>
" <?php echo $attrs_code; ?> /> :
376 <input class="sq-form-field
" style="width: 5ex
" type="text
" name="<?php echo $prefix; ?>_minutes
" id="<?php echo $prefix; ?>_minutes
" size="2
" maxlength="2
" value="<?php echo date(
'i', $timestamp); ?>
" <?php echo $attrs_code; ?> />
378 <select class="sq-form-field
" name="<?php echo $prefix; ?>_is_pm
" id="<?php echo $prefix; ?>_is_pm
" <?php echo $attrs_code; ?> >
379 <option value="0
" <?php echo (date('a', $timestamp)=='am') ? ' selected="selected
" ' : ''; ?>>am</option>
380 <option value="1
" <?php echo (date('a', $timestamp)=='pm') ? ' selected="selected
" ' : ''; ?>>pm</option>
385 }//end printTimeChooser()