/** * Get a list of group pages * * @param string $rtrn What data to return * @param array $filters Filters to apply to data retrieval * @param boolean $boolean Clear cached data? * @return mixed */ public function events($rtrn = 'list', $filters = array(), $clear = false) { switch (strtolower($rtrn)) { case 'count': if (!$this->_events_count || $clear) { $tbl = new Tables\Event($this->_db); $this->_events_count = $tbl->count($filters); } return $this->_events_count; break; case 'repeating': if (!$this->_events_repeating instanceof ItemList || $clear) { // var to hold repeating data $repeats = array(); // add repeating filters $filters['repeating'] = true; // capture publish up/down // remove for now as we want all events that have a repeating rule $start = Date::of($filters['publish_up']); $end = Date::of($filters['publish_down']); unset($filters['publish_up']); unset($filters['publish_down']); // find any events that match our filters $tbl = new Tables\Event($this->_db); if ($results = $tbl->find($filters)) { foreach ($results as $key => $result) { $start = Date::of($result->publish_up); // get the repeating & pass start date $rule = new \Recurr\Rule($result->repeating_rule, $start); // define constraint that date must be between event publish_up & end $constraint = new \Recurr\Transformer\Constraint\BetweenConstraint($start, $end); // create transformmer & generate occurances $transformer = new \Recurr\Transformer\ArrayTransformer(); $occurrences = $transformer->transform($rule, null, $constraint); // calculate diff so we can create down $diff = new DateInterval('P0Y0DT0H0M'); if ($result->publish_down != '0000-00-00 00:00:00') { $diff = date_diff(Date::of($result->publish_up), Date::of($result->publish_down)); } // create new event for each reoccurrence foreach ($occurrences as $occurrence) { $event = clone $result; $event->publish_up = $occurrence->getStart()->format('Y-m-d H:i:s'); $event->publish_down = $occurrence->getStart()->add($diff)->format('Y-m-d H:i:s'); $repeats[] = new Event($event); } } } $this->_events_repeating = new ItemList($repeats); } return $this->_events_repeating; break; case 'list': default: if (!$this->_events instanceof ItemList || $clear) { $tbl = new Tables\Event($this->_db); if ($results = $tbl->find($filters)) { foreach ($results as $key => $result) { $results[$key] = new Event($result); } } $this->_events = new ItemList($results); } return $this->_events; break; } }
/** * Save an event * * @return void */ public function saveTask() { // Check if they are logged in if (User::isGuest()) { $this->loginTask(); return; } // good ol' form validation Request::checkToken(); Request::checkHoneypot() or die('Invalid Field Data Detected. Please try again.'); $offset = $this->offset; // Incoming $start_time = Request::getVar('start_time', '08:00', 'post'); $start_time = $start_time ? $start_time : '08:00'; $start_pm = Request::getInt('start_pm', 0, 'post'); $end_time = Request::getVar('end_time', '17:00', 'post'); $end_time = $end_time ? $end_time : '17:00'; $end_pm = Request::getInt('end_pm', 0, 'post'); $time_zone = Request::getVar('time_zone', -5, 'post'); $tags = Request::getVar('tags', '', 'post'); // Bind the posted data to an event object $row = new Event($this->database); if (!$row->bind($_POST)) { throw new Exception($row->getError(), 500); } // New entry or existing? if ($row->id) { $state = 'edit'; // Existing - update modified info $row->modified = strftime("%Y-%m-%d %H:%M:%S", time() + $offset * 60 * 60); if (User::get('id')) { $row->modified_by = User::get('id'); } } else { $state = 'add'; // New - set created info $row->created = strftime("%Y-%m-%d %H:%M:%S", time() + $offset * 60 * 60); if (User::get('id')) { $row->created_by = User::get('id'); } } // Set some fields and do some cleanup work if ($row->catid) { $row->catid = intval($row->catid); } //$row->title = htmlentities($row->title); $row->content = $_POST['econtent']; $row->content = \Hubzero\Utility\Sanitize::clean($row->content); // Get the custom fields defined in the events configuration if (isset($_POST['fields'])) { $fields = $_POST['fields']; $fields = array_map('trim', $fields); // Wrap up the content of the field and attach it to the event content $fs = $this->config->fields; foreach ($fields as $param => $value) { if (trim($value) != '') { $row->content .= '<ef:' . $param . '>' . $this->_clean($value) . '</ef:' . $param . '>'; } else { foreach ($fs as $f) { if ($f[0] == $param && end($f) == 1) { throw new Exception(Lang::txt('EVENTS_REQUIRED_FIELD_CHECK', $f[1]), 500); } } } } } // Clean adresse $row->adresse_info = $this->_clean($row->adresse_info); // Clean contact $row->contact_info = $this->_clean($row->contact_info); // Clean extra $row->extra_info = $this->_clean($row->extra_info); // Prepend http:// to URLs without it if ($row->extra_info != NULL) { if (substr($row->extra_info, 0, 7) != 'http://' && substr($row->extra_info, 0, 8) != 'https://') { $row->extra_info = 'http://' . $row->extra_info; } } // Reformat the time into 24hr format if necessary if ($this->config->getCfg('calUseStdTime') == 'YES') { list($hrs, $mins) = explode(':', $start_time); $hrs = intval($hrs); $mins = intval($mins); if ($hrs != 12 && $start_pm) { $hrs += 12; } else { if ($hrs == 12 && !$start_pm) { $hrs = 0; } } if ($hrs < 10) { $hrs = '0' . $hrs; } if ($mins < 10) { $mins = '0' . $mins; } $start_time = $hrs . ':' . $mins; list($hrs, $mins) = explode(':', $end_time); $hrs = intval($hrs); $mins = intval($mins); if ($hrs != 12 && $end_pm) { $hrs += 12; } else { if ($hrs == 12 && !$end_pm) { $hrs = 0; } } if ($hrs < 10) { $hrs = '0' . $hrs; } if ($mins < 10) { $mins = '0' . $mins; } $end_time = $hrs . ':' . $mins; } // hack to fix where timezones cant be found by offset int // really need to figure datetimes out switch ($row->time_zone) { case -12: $tz = 'Pacific/Kwajalein'; break; case -9.5: $tz = 'Pacific/Marquesa'; break; case -3.5: $tz = 'Canada/Newfoundland'; break; case -2: $tz = 'America/Noronha'; break; case 3.5: $tz = 'Asia/Tehran'; break; case 4.5: $tz = 'Asia/Kabul'; break; case 6: $tz = 'Asia/Dhaka'; break; case 6.5: $tz = 'Asia/Rangoon'; break; case 8.75: $tz = 'Asia/Shanghai'; break; case 9.5: $tz = 'Australia/Adelaide'; break; case 11: $tz = 'Asia/Vladivostok'; break; case 11.5: $tz = 'Asia/Vladivostok'; break; case 13: $tz = 'Pacific/Tongatapu'; break; case 14: $tz = 'Pacific/Kiritimati'; break; default: $tz = timezone_name_from_abbr('', $row->time_zone * 3600, NULL); } // create publish up date time string $rpup = $row->publish_up; $publishtime = date('Y-m-d 00:00:00'); if ($row->publish_up) { $publishtime = $row->publish_up . ' ' . $start_time . ':00'; $row->publish_up = \Date::of($publishtime)->toSql(); } // create publish down date/time string $publishtime = date('Y-m-d 00:00:00'); if ($row->publish_down) { $publishtime = $row->publish_down . ' ' . $end_time . ':00'; $row->publish_down = \Date::of($publishtime)->toSql(); } // Always unpublish if no Publisher otherwise publish automatically if ($this->config->getCfg('adminlevel')) { $row->state = 0; } else { $row->state = 1; } $row->state = 1; // Verify that the event doesn't start after it ends or ends before it starts. $pubdow = strtotime($row->publish_down); $pubup = strtotime($row->publish_up); if ($pubdow <= $pubup) { // Set the error message $this->setError(Lang::txt('EVENTS_EVENT_MUST_END_AFTER_START')); // Fall through to the edit view $this->editTask($row); return; } //set the scope to be regular events $row->scope = 'event'; if (!$row->check()) { // Set the error message $this->setError($row->getError()); $this->tags = $tags; // Fall through to the edit view $this->editTask($row); return; } if (!$row->store()) { // Set the error message $this->setError($row->getError()); $this->tags = $tags; // Fall through to the edit view $this->editTask($row); return; } $row->checkin(); // Save the tags $rt = new Tags($row->id); $rt->setTags($tags, User::get('id')); // Build the message to be e-mailed if ($state == 'add') { $subject = '[' . Config::get('sitename') . ' ' . Lang::txt('EVENTS_CAL_LANG_CAL_TITLE') . '] - ' . Lang::txt('EVENTS_CAL_LANG_MAIL_ADDED'); $eview = new View(array('name' => 'emails', 'layout' => 'created')); } else { $subject = '[' . Config::get('sitename') . ' ' . Lang::txt('EVENTS_CAL_LANG_CAL_TITLE') . '] - ' . Lang::txt('EVENTS_CAL_LANG_MAIL_ADDED'); $eview = new View(array('name' => 'emails', 'layout' => 'edited')); } $eview->option = $this->_option; $eview->sitename = Config::get('sitename'); $eview->user = User::getInstance(); $eview->row = $row; $message = $eview->loadTemplate(); $message = str_replace("\n", "\r\n", $message); // Send the e-mail $this->_sendMail(Config::get('sitename'), Config::get('mailfrom'), $subject, $message); // Redirect to the details page for the event we just created App::redirect(Route::url('index.php?option=' . $this->_option . '&task=details&id=' . $row->id)); }
/** * Remove one or more entries for an event * * @return void */ public function removeTask() { // Incoming $ids = Request::getVar('id', array()); if (!is_array($ids)) { $ids = array(); } // Make sure we have an ID if (empty($ids)) { App::redirect(Route::url('index.php?option=' . $this->_option . '&controller=' . $this->_controller, false)); return; } // Instantiate an event object $event = new Event($this->database); // Instantiate a page object $ep = new Page($this->database); // Instantiate a respondent object $er = new Respondent(array()); // Loop through the IDs and unpublish the event foreach ($ids as $id) { // Instantiate an event tags object $rt = new Tags($id); // Delete tags on this event $rt->removeAll(); // Delete the event $event->delete($id); // Delete any associated pages $ep->deletePages($id); // Delete any associated respondents $er->deleteRespondents($id); } // Redirect App::redirect(Route::url('index.php?option=' . $this->_option . '&controller=' . $this->_controller, false), Lang::txt('COM_EVENTS_CAL_LANG_REMOVED')); }