function Validate() { // Ready output data $duration = Academic_time::Difference($event->StartTime, $event->EndTime, array('days', 'hours', 'minutes')); $start = new Academic_time(time()); $eventinfo = array('summary' => '', 'description' => '', 'location' => '', 'category' => '', 'allday' => false, 'start' => array('monthday' => $start->DayOfMonth(), 'month' => $start->Month(), 'year' => $start->Year(), 'time' => $start->Hour() . ':' . $start->Minute(), 'yearday' => $start->DayOfYear(), 'day' => $start->DayOfWeek(), 'monthweek' => (int) (($start->DayOfMonth() + 6) / 7)), 'duration' => array('days' => $duration['days'], 'time' => $duration['hours'] . ':' . $duration['minutes'])); $data = array('SimpleRecur' => $rset_arr, 'FailRedirect' => '/' . $tail, 'Path' => $this->mPaths, 'EventCategories' => $categories, 'FormPrefix' => $prefix, 'EventInfo' => $eventinfo); }
function src_event_edit() { if (!CheckPermissions($this->mPermission)) { return; } // Get data from uri resolution. $source_id = $this->mData['SourceId']; $event_id = $this->mData['EventId']; $occurrence_specified = array_key_exists('OccurrenceId', $this->mData); if ($occurrence_specified) { $occurrence_id = $this->mData['OccurrenceId']; } else { $occurrence_id = NULL; } // Validate the source if (!$this->_GetSource()) { return; } $this->load->library('calendar_view_edit_simple'); $this->pages_model->SetPageCode('calendar_event_edit'); // Get the redirect url tail $args = func_get_args(); $tail = implode('/', $args); $get_action = ''; if (isset($_GET['action'])) { $get_action = $_GET['action']; } // Fetch the specified event $calendar_data = new CalendarData(); $this->mMainSource->FetchEvent($calendar_data, $source_id, $event_id); $events = $calendar_data->GetEvents(); if (array_key_exists(0, $events)) { $event = $events[0]; // Find the occurrence $found_occurrence = NULL; if (NULL !== $occurrence_id) { foreach ($event->Occurrences as $key => $occurrence) { if ($occurrence->SourceOccurrenceId == $occurrence_id) { $found_occurrence =& $event->Occurrences[$key]; break; } } if (NULL === $found_occurrence) { $this->messages->AddMessage('warning', 'The event occurrence with id ' . $occurrence_id . ' does not belong to the event with id ' . $event_id . '.'); redirect($this->mPaths->EventInfo($event) . '/' . $tail); return; } } if (NULL === $occurrence_id) { // default to the only occurrence if there is only one. if (count($event->Occurrences) == 1) { $found_occurrence =& $event->Occurrences[0]; $occurrence_id = $found_occurrence->SourceOccurrenceId; } } // Get the buttons from post data $prefix = 'eved'; $return_button = isset($_POST[$prefix . '_return']); if (false !== $event && $event->ReadOnly) { $return_button = TRUE; $this->messages->AddMessage('error', 'You do not have permission to make changes to this event.'); } if ($return_button) { // REDIRECT if ($occurrence_specified) { $path = $this->mPaths->OccurrenceInfo($found_occurrence); } else { $path = $this->mPaths->EventInfo($event); } return redirect($path . '/' . $tail); } $input_summary = $this->input->post($prefix . '_summary'); $errors = array(); $process_input = false; // Read the recurrence data if (isset($_POST[$prefix . '_recur_simple']) and isset($_POST[$prefix . '_start']) and isset($_POST[$prefix . '_duration']) and isset($_POST[$prefix . '_inex'])) { $rset_arr = $_POST[$prefix . '_recur_simple']; $rset = Calendar_view_edit_simple::validate_recurrence_set_data(!(isset($_POST[$prefix . '_allday']) && $_POST[$prefix . '_allday']), $_POST[$prefix . '_start'], $_POST[$prefix . '_duration'], $_POST[$prefix . '_recur_simple'], $_POST[$prefix . '_inex'], $errors); } // Fill it in if none supplied /// @todo Fix that the new rset doesn't have the same rrule ids, so theres a deletion/insertion instead of update. if (!isset($rset_arr)) { $rset = $event->GetRecurrenceSet(); if ((isset($_POST['evview_delete']) || 'delete' == $get_action) && NULL !== $found_occurrence) { $inex_date = array($found_occurrence->StartTime->Format('Ymd') => array(NULL => NULL)); $rset->RemoveRDates($inex_date); $rset->AddExDates($inex_date); $process_input = true; $_POST[$prefix . '_save'] = true; $input_valid = true; } elseif (isset($_POST['evview_delete_all']) || 'delete_all' == $get_action) { $rset->ClearRecurrence(); $process_input = true; $_POST[$prefix . '_save'] = true; $input_valid = true; } elseif ((isset($_POST['evview_restore']) || 'restore' == $get_action) && NULL !== $found_occurrence) { $inex_date = array($found_occurrence->StartTime->Format('Ymd') => array(NULL => NULL)); $rset->RemoveExDates($inex_date); $rset->AddRDates($inex_date); $process_input = true; $_POST[$prefix . '_save'] = true; $input_valid = true; } $rset_arr = Calendar_view_edit_simple::transform_recur_for_view($rset, $errors); } // Always fill in the inex info again, ignoring input from form. $inex_arr = Calendar_view_edit_simple::transform_inex_for_view($rset, $errors); list($start, $end) = $rset->GetStartEnd(); $categories = $this->mSource->GetAllCategories(); $input = array('name' => $event->Name, 'description' => $event->Description, 'location_name' => $event->LocationDescription, 'category' => 0, 'time_associated' => $event->TimeAssociated); if (isset($categories[$event->Category])) { $input['category'] = $categories[$event->Category]['id']; } $input_summary = $this->input->post($prefix . '_summary'); $confirm_list = NULL; if (false !== $input_summary) { $input_valid = true; $process_input = true; // Get more post data $input['name'] = $input_summary; if (strlen($input['name']) <= 3 or strlen($input['name']) >= 256) { $input_valid = false; $this->messages->AddMessage('error', 'Event summary is too long or too short.'); } $input_description = $this->input->post($prefix . '_description'); if (false !== $input_description) { $input['description'] = $input_description; if (strlen($input['name']) > 65535) { $input_valid = false; $this->messages->AddMessage('error', 'Event description is too long.'); } } $input_category = $this->input->post($prefix . '_category'); if (false !== $input_category) { $input['category'] = $input_category; } $input_location = $this->input->post($prefix . '_location'); if (false !== $input_location) { $input['location_name'] = $input_location; if (strlen($input['location_name']) > 50) { $input_valid = false; $this->messages->AddMessage('error', 'Event location is too long.'); } } $input['time_associated'] = $this->input->post($prefix . '_allday') === false; } if ($process_input) { // at this point $start and $end are still plain timestamps $input['recur'] = $rset; if ($input_valid && empty($errors)) { if (isset($_POST[$prefix . '_save'])) { $confirm_list = $this->mMainSource->GetEventRecurChanges($event, $rset); if (isset($confirm_list['draft']) && !$this->mMainSource->IsSupported('publish')) { unset($confirm_list['draft']); } if (empty($confirm_list)) { $_POST[$prefix . '_confirm']['confirm_btn'] = 'Confirm'; } } if (isset($_POST[$prefix . '_confirm']['confirm_btn'])) { if (NULL === $confirm_list) { $confirm_list = $this->mMainSource->GetEventRecurChanges($event, $rset); } // Make the change $messages = $this->mMainSource->AmmendEvent($event, $input); $this->messages->AddMessages($messages); if (!array_key_exists('error', $messages) || empty($messages['error'])) { // Success $this->messages->AddMessage('success', 'Event updated'); // Publish the specified occurrences. $publish_occurrences = array(); foreach (array('create', 'draft') as $namespace) { if (isset($_POST[$prefix . '_confirm'][$namespace . '_publish'])) { foreach ($_POST[$prefix . '_confirm'][$namespace . '_publish'] as $day => $dummy) { if (isset($confirm_list[$namespace][$day])) { $publish_occurrences[] = $confirm_list[$namespace][$day]['start_time']; } } } } if (!empty($publish_occurrences)) { $published = $this->mSource->PublishOccurrences($event, $publish_occurrences); $desired = count($publish_occurrences); if ($published < $desired) { $message_type = 'warning'; } else { $message_type = 'success'; } $this->messages->Addmessage($message_type, "{$published} out of {$desired} occurrences were published."); } // changes have been made including possible deletion. // if the redirection results in event not found, we // want it to redirect straight back to the tail. $_SESSION['calendar']['modded'][$event_id] = 1; // REDIRECT if ($occurrence_specified) { $path = $this->mPaths->OccurrenceInfo($found_occurrence); } else { $path = $this->mPaths->EventInfo($event); } return redirect($path . '/' . $tail); } } } } // Ready output data $start = new Academic_time($start); $end = new Academic_time($end); $eventinfo = array('summary' => $input['name'], 'description' => $input['description'], 'location' => $input['location_name'], 'category' => $input['category'], 'allday' => !$input['time_associated'], 'start' => array('monthday' => $start->DayOfMonth(), 'month' => $start->Month(), 'year' => $start->Year(), 'time' => $start->Hour() . ':' . $start->Minute(), 'yearday' => $start->DayOfYear(), 'day' => $start->DayOfWeek(), 'monthweek' => (int) (($start->DayOfMonth() + 6) / 7)), 'duration' => Calendar_view_edit_simple::calculate_duration($start, $end)); if ($this->events_model->IsVip()) { $help_xhtml = $this->pages_model->GetPropertyWikitext('help_vip'); } else { $help_xhtml = $this->pages_model->GetPropertyWikitext('help_personal'); } $data = array('SimpleRecur' => $rset_arr, 'InExDates' => $inex_arr, 'FailRedirect' => '/' . $tail, 'Path' => $this->mPaths, 'EventCategories' => $categories, 'FormPrefix' => $prefix, 'EventInfo' => $eventinfo, 'Help' => $help_xhtml, 'CanPublish' => $this->mMainSource->IsSupported('publish'), 'Create' => false, 'SuccessRedirect' => false); if (is_array($confirm_list)) { $data['Confirms'] = $confirm_list; if (isset($_POST[$prefix . '_confirm'])) { $data['Confirm'] = $_POST[$prefix . '_confirm']; } else { $data['Confirm'] = NULL; } } foreach ($errors as $error) { $this->messages->AddMessage('error', $error['text']); } $this->SetupTabs('', $start); $this->main_frame->SetTitleParameters(array('source' => $this->mSource->GetSourceName(), 'event' => $event->Name)); $this->main_frame->IncludeCss('stylesheets/calendar.css'); $this->main_frame->IncludeJs('javascript/simple_ajax.js'); $this->main_frame->IncludeJs('javascript/css_classes.js'); $this->main_frame->IncludeJs('javascript/calendar_edit.js'); $this->main_frame->SetContent(new FramesView('calendar/event_edit', $data)); } else { // Event not in list $this->ErrorNotAccessible($tail); } $this->main_frame->Load(); }
protected function _Load() { $value = $this->value; if (null === $value) { $value = Academic_time::NewToday(); } else { $value = new Academic_time($value); } ?> <div class="input_date_display"<?php ?> onclick="<?php echo xml_escape('return input_date_click("' . $this->name . '");'); ?> "<?php ?> ><?php if ($this->date) { ?> <span class="day" id="<?php echo $this->id . '__day'; ?> "><?php echo $value->Format('l'); ?> </span> <?php ?> week <span class="week" id="<?php echo $this->id . '__wk'; ?> "><?php echo $value->AcademicWeek(); ?> </span> <?php ?> of <span class="term" id="<?php echo $this->id . '__term'; ?> "><?php echo ucfirst($value->AcademicTermNameUnique()); echo ' ' . $value->StartOfTerm()->Year(); ?> </span> <?php } if ($this->time) { ?> at <span class="hour" id="<?php echo $this->id . '__hr'; ?> "><?php echo $value->Hour(); ?> </span><?php ?> :<span class="minute" id="<?php echo $this->id . '__min'; ?> "><?php echo $value->Minute(); ?> </span> <?php } ?> </div><?php $days = array('Mon', 'Tue', 'Wed', 'Thu', 'Fri', 'Sat', 'Sun'); ?> <div class="input_date_selector"<?php ?> id="<?php echo $this->id . '__selector'; ?> "<?php ?> ><?php // Init script ?> <script type="text/javascript"><?php echo xml_escape('onLoadFunctions.push(function() {' . 'input_date_init(' . js_literalise($this->name) . ');' . '});', false); ?> </script><?php ?> <div><?php // Day of the week ?> <select id="<?php echo $this->id . '__day_select'; ?> "<?php ?> name="<?php echo $this->name . '[day]'; ?> "<?php ?> onchange="<?php echo xml_escape('return input_date_day_changed("' . $this->name . '");'); ?> "<?php ?> ><?php foreach ($days as $val => $day) { ?> <option value="<?php echo $val; ?> "<?php if ($val == $value->DayOfWeek(1)) { ?> selected="selected"<?php } ?> ><?php echo $day; ?> </option><?php } ?> </select><?php // Week of the term ?> <span>week</span><?php ?> <select id="<?php echo $this->id . '__wk_select'; ?> "<?php ?> name="<?php echo $this->name . '[wk]'; ?> "<?php ?> onchange="<?php echo xml_escape('return input_date_day_changed("' . $this->name . '");'); ?> "<?php ?> ><?php $weeks = $value->AcademicTermWeeks(); for ($wk = 1; $wk <= $weeks; ++$wk) { ?> <option value="<?php echo $wk; ?> "<?php if ($wk == $value->AcademicWeek()) { ?> selected="selected"<?php } ?> ><?php echo $wk; ?> </option><?php } ?> </select><?php // Term ?> <span>of</span><?php ?> <select id="<?php echo $this->id . '__term_select'; ?> "<?php ?> name="<?php echo $this->name . '[term]'; ?> "<?php ?> onchange="<?php echo xml_escape('return input_date_term_changed("' . $this->name . '");'); ?> "<?php ?> ><?php $sel_year = $value->AcademicYear(); $sel_term = $value->AcademicTerm(); $year = $sel_year; $term = 0; ?> <option value="earlier">(more)</option><?php for ($i = 0; $i < 6; ++$i) { $cur = new Academic_time(Academic_time::StartOfAcademicTerm($year, $term)); ?> <option value="<?php echo "{$year}-{$term}"; ?> "<?php if ($term == $sel_term && $year == $sel_year) { ?> selected="selected"<?php } ?> ><?php echo xml_escape(ucfirst($cur->AcademicTermNameUnique()) . ' ' . $cur->Year()); ?> </option><?php ++$term; if ($term == 6) { $term = 0; ++$year; } } ?> <option value="later">(more)</option><?php ?> </select><?php // Time of day if ($this->time) { ?> <span>at</span><?php ?> <select id="<?php echo $this->id . '__hr_select'; ?> "<?php ?> name="<?php echo $this->name . '[hr]'; ?> "<?php ?> onchange="<?php echo xml_escape('return input_date_time_changed("' . $this->name . '");'); ?> "<?php ?> ><?php for ($hr = 0; $hr < 24; ++$hr) { ?> <option value="<?php echo $hr; ?> "<?php if ($hr == $value->Hour()) { ?> selected="selected"<?php } ?> ><?php echo sprintf('%02d', $hr); ?> </option><?php } ?> </select><?php ?> <span>:</span><?php ?> <select id="<?php echo $this->id . '__min_select'; ?> "<?php ?> name="<?php echo $this->name . '[min]'; ?> "<?php ?> onchange="<?php echo xml_escape('return input_date_time_changed("' . $this->name . '");'); ?> "<?php ?> ><?php $minute = $value->Minute(); $minute_interval = 5; for ($min = 0; $min < 60; $min += $minute_interval) { ?> <option value="<?php echo $min; ?> "<?php if ($min <= $minute && $min + $minute_interval > $minute) { ?> selected="selected"<?php } ?> ><?php echo sprintf('%02d', $min); ?> </option><?php } ?> </select><?php } // Close button ?> <input type="button" value="x"<?php ?> onclick="<?php echo xml_escape('return input_selector_click("' . $this->name . '__selector");'); ?> "<?php ?> /><?php ?> </div><?php ?> <div><?php ?> <table class="recur-cal cal-text"><?php // Days along the top ?> <tr><?php ?> <th /><?php foreach ($days as $day) { ?> <th><?php echo xml_escape($day); ?> </th><?php } ?> </tr><?php $cur = $value->MondayWeek1OfTerm(); $sel = $value->Midnight()->Timestamp(); $today = Academic_time::NewToday()->Timestamp(); $last_month = 0; $term = $cur->AcademicTerm(); for ($wk = 1; $cur->AcademicTerm() == $term; ++$wk) { ?> <tr id="<?php echo $this->id . '__wk_' . $wk; ?> "><?php ?> <th><?php echo $wk; ?> </th><?php for ($dy = 0; $dy < 7; ++$dy) { $month = $cur->Month(); $ts = $cur->Timestamp(); $classes = array(); if ($ts < $today) { $classes[] = "pa"; } if ($month % 2 == 0) { $classes[] = "ev"; } if ($ts == $today) { $classes[] = "tod"; } if ($ts == $sel) { $classes[] = "sel"; } if ($dy >= 5) { $classes[] = "we"; } ?> <td class="<?php echo join(' ', $classes); ?> "<?php ?> id="<?php echo $this->id . '__' . $cur->AcademicWeek() . '_' . $cur->Format('D'); ?> "<?php ?> onclick="<?php echo xml_escape('return input_date_change(' . js_literalise($this->name) . ',' . js_literalise($wk) . ',' . js_literalise($dy) . ');'); ?> "<?php ?> ><?php if ($month != $last_month) { echo xml_escape($cur->Format('M')) . ' '; $last_month = $month; } echo xml_escape($cur->Format('j')); ?> </td><?php $cur = $cur->Adjust('+1day'); } ?> </tr><?php } ?> </table><?php ?> </div><?php ?> </div><?php }