/** * Run method with main page logic * * Read in the specified event from the database. * Populate template and display event details in the page. Allow admin preview of un-approved event * @access public */ public function run() { $session = Session::getInstance(); $user = $session->getUser(); $eventDAO = EventDAO::getInstance(); $attendDAO = AttendanceDAO::getInstance(); $title = ""; $event = $attending = $attend_array = null; $attend_count = null; if (!empty($_GET["id"]) && is_numeric($_GET["id"])) { $id = intval($_GET["id"]); $event = $eventDAO->load($id, array("joins" => true)); // Check if event is approved if ($event && $event->status == Event::APPROVED_STATUS) { $title .= " - {$event->title}"; if ($user) { $attending = $attendDAO->loadExists($event, $user); } $attend_count = $attendDAO->countByEvent($event); $attend_array = $attendDAO->allByEvent($event, array("joins" => true, "order" => "id DESC")); } else { if ($event && $session->getUser() && $session->getUser()->isAdmin()) { $title .= " - {$event->title}"; $attending = $attendDAO->loadExists($event, $user); $attend_count = $attendDAO->countByEvent($event); $attend_array = $attendDAO->allByEvent($event, array("joins" => true, "order" => "id DESC")); } else { $event = null; } } } $this->template->render(array("title" => "Event Details" . $title, "main_page" => "view_event_tpl.php", "session" => $session, "event" => $event, "attending" => $attending, "attend_array" => $attend_array, "attend_count" => $attend_count)); }
/** * Run method with main page logic * * Read in list of the latest published events and populate template with results. * Display results in the page. Pagination enabled * @access public */ public function run() { $PAGINATION_LIMIT = 10; $session = Session::getInstance(); $user = $session->getUser(); $eventDAO = EventDAO::getInstance(); $page = isset($_GET["page"]) && is_numeric($_GET["page"]) ? intval($_GET["page"]) : 1; $platform_id = isset($_GET["platform"]) && is_numeric($_GET["platform"]) ? intval($_GET["platform"]) : 0; if ($page < 1) { $page = 1; } $count = $paginator = $paginator_page = $queryVars = $current_platform = null; if ($platform_id <= 0) { $count = $eventDAO->countStatus(Event::APPROVED_STATUS); $paginator = new Paginator($count, $PAGINATION_LIMIT); $paginator_page = $paginator->getPage($page); $event_array = $eventDAO->allByStatus(Event::APPROVED_STATUS, array("order" => "{$eventDAO->getTableName()}.date DESC, {$eventDAO->getTableName()}.id DESC", "joins" => true, "limit" => $paginator_page)); } else { $count = $eventDAO->countPlatformStatus($platform_id, Event::APPROVED_STATUS); $paginator = new Paginator($count, $PAGINATION_LIMIT); $paginator_page = $paginator->getPage($page); $event_array = $eventDAO->allByPlatformStatus($platform_id, Event::APPROVED_STATUS, array("order" => "{$eventDAO->getTableName()}.date DESC, {$eventDAO->getTableName()}.id DESC", "joins" => true, "limit" => $paginator_page)); $queryVars = array("platform" => $platform_id); } $platformDAO = PlatformDAO::getInstance(); $platform_array = $platformDAO->all(); //print_r ($event_array); if ($platform_id > 0) { $current_platform = $platformDAO->load($platform_id); } $this->template->render(array("title" => "Event List", "main_page" => "event_list_tpl.php", "event_array" => $event_array, "session" => $session, "paginator_page" => $paginator_page, "sidebar_extra" => joinPath("fragments", "event_sidebar_tpl.php"), "platform_array" => $platform_array, "queryVars" => $queryVars, "current_platform" => $current_platform)); }
/** * Run method with main page logic * * Reads in events for a given month or current month if no parameters are passed. * Allow filtering by platform id. Populate template and display event data in a calendar view on the page. * @access public */ public function run() { $PAGINATION_LIMIT = 10; $session = Session::getInstance(); $user = $session->getUser(); $eventDAO = EventDAO::getInstance(); $platformDAO = PlatformDAO::getInstance(); //$page = (isset ($_GET["page"]) && is_numeric ($_GET["page"])) ? intval ($_GET["page"]) : 1; $platform_id = isset($_GET["platform"]) && is_numeric($_GET["platform"]) ? intval($_GET["platform"]) : 0; $month = isset($_GET["month"]) && is_numeric($_GET["month"]) ? intval($_GET["month"]) : 0; $year = isset($_GET["year"]) && is_numeric($_GET["year"]) ? intval($_GET["year"]) : 0; //if ($page < 1) { // $page = 1; //} $count = $paginator = $paginator_page = $event_array = $next_eventday = $prev_eventday = $current_platform = null; if ($platform_id > 0 && checkdate($month, 1, $year)) { $start = mktime(0, 0, 0, $month, 1, $year); $end = strtotime("+1 month", $start) - 1; //$count = $eventDAO->countPlatformStatusAndRange ($platform, Event::APPROVED_STATUS, $start, $end); //$paginator = new Paginator ($count, 3); //$paginator_page = $paginator->getPage ($page); $event_array = $eventDAO->allByPlatformStatusAndRange($platform_id, Event::APPROVED_STATUS, $start, $end, array("order" => "{$eventDAO->getTableName()}.date DESC, {$eventDAO->getTableName()}.id DESC", "joins" => true)); } else { if ($platform_id > 0) { $start = mktime(0, 0, 0, idate("m"), 1, idate("Y")); $end = strtotime("+1 month", $start) - 1; //$count = $eventDAO->countPlatformStatusAndRange ($platform, Event::APPROVED_STATUS, $start, $end); //$paginator = new Paginator ($count, 3); //$paginator_page = $paginator->getPage ($page); $event_array = $eventDAO->allByPlatformStatusAndRange($platform_id, Event::APPROVED_STATUS, $start, $end, array("order" => "{$eventDAO->getTableName()}.date DESC, {$eventDAO->getTableName()}.id DESC", "joins" => true)); } else { if (checkdate($month, 1, $year)) { $start = mktime(0, 0, 0, $month, 1, $year); $end = strtotime("+1 month", $start) - 1; //$count = $eventDAO->countStatus (Event::APPROVED_STATUS); //$paginator = new Paginator ($count, 3); //$paginator_page = $paginator->getPage ($page); $event_array = $eventDAO->allByStatusAndRange(Event::APPROVED_STATUS, $start, $end, array("order" => "{$eventDAO->getTableName()}.date DESC, {$eventDAO->getTableName()}.id DESC", "joins" => true)); } else { $start = mktime(0, 0, 0, idate("m"), 1, idate("Y")); $end = strtotime("+1 month", $start) - 1; //$count = $eventDAO->countStatus (Event::APPROVED_STATUS); //$paginator = new Paginator ($count, 3); //$paginator_page = $paginator->getPage ($page); $event_array = $eventDAO->allByStatusAndRange(Event::APPROVED_STATUS, $start, $end, array("order" => "{$eventDAO->getTableName()}.date DESC, {$eventDAO->getTableName()}.id DESC", "joins" => true)); } } } $next_eventday = $eventDAO->loadByNextDay($end, Event::APPROVED_STATUS); $prev_eventday = $eventDAO->loadByPreviousDay($start, Event::APPROVED_STATUS); if ($platform_id > 0) { $current_platform = $platformDAO->load($platform_id); } $platform_array = $platformDAO->all(); //print_r ($event_array); $this->template->render(array("title" => "Event Month Calendar - " . date("F", $start) . " " . date("Y", $start), "main_page" => "events_month_tpl.php", "event_array" => $event_array, "session" => $session, "start" => $start, "end" => $end, "next_eventday" => $next_eventday, "prev_eventday" => $prev_eventday, "sidebar_extra" => joinPath("fragments", "event_sidebar_tpl.php"), "platform_array" => $platform_array, "current_platform" => $current_platform)); }
/** * Run method with main page logic * * Populate template and display confirmation for event deletion. For POST request, * check user credentials, check if event exists and then delete entry from database. * Available to admins only * @access public */ public function run() { $session = Session::getInstance(); $user = $session->getUser(); // Check if user is an admin if (!$user || !$user->isAdmin()) { $session->setMessage("Do not have permission to access", Session::MESSAGE_ERROR); header("Location: " . BASE_URL); return; } $eventDAO = EventDAO::getInstance(); $delete_event = null; $form_errors = array(); $form_values = array("id" => ""); if (!empty($_POST)) { // Check if a number was passed for the id $id = isset($_POST["id"]) ? trim($_POST["id"]) : ""; if (empty($id)) { header("Location: " . BASE_URL); return; } else { if (is_numeric($id)) { $delete_event = $eventDAO->load($id); // Event exists. Delete if ($delete_event) { if ($eventDAO->delete($delete_event)) { $session->setMessage("Event deleted"); header("Location: " . BASE_URL); return; } else { $session->setMessage("Could not delete event", Session::MESSAGE_ERROR); } } } } } else { if (!empty($_GET)) { $id = isset($_GET["id"]) ? trim($_GET["id"]) : ""; if (empty($id)) { header("Location: " . BASE_URL); return; } else { if (is_numeric($id)) { $delete_event = $eventDAO->load($id); if ($delete_event) { $form_values["id"] = $delete_event->getId(); } } } } else { header("Location: " . BASE_URL); return; } } $this->template->render(array("title" => "Delete Event", "main_page" => "delete_event_tpl.php", "session" => $session, "delete_event" => $delete_event, "form_errors" => $form_errors, "form_values" => $form_values)); }
/** * Run method with main page logic * * Read latest approved event data from database. Alter output header so * client interprets sent text as RSS/XML. Send feed text * to client * @access public */ public function run() { $PAGINATION_LIMIT = 20; $eventDAO = EventDAO::getInstance(); $platform = isset($_GET["platform"]) && is_numeric($_GET["platform"]) ? intval($_GET["platform"]) : 0; $count = $paginator = $paginator_page = null; // Platform choice was made. Retrieve only events with platform id if ($platform <= 0) { $count = $eventDAO->countStatus(Event::APPROVED_STATUS); $paginator = new Paginator($count, $PAGINATION_LIMIT); $paginator_page = $paginator->getPage(1); $event_array = $eventDAO->allByStatus(Event::APPROVED_STATUS, array("order" => "{$eventDAO->getTableName()}.date DESC, {$eventDAO->getTableName()}.id DESC", "joins" => true, "limit" => $paginator_page)); } else { $count = $eventDAO->countPlatformStatus($platform, Event::APPROVED_STATUS); $paginator = new Paginator($count, $PAGINATION_LIMIT); $paginator_page = $paginator->getPage(1); $event_array = $eventDAO->allByPlatformStatus($platform, Event::APPROVED_STATUS, array("order" => "{$eventDAO->getTableName()}.date DESC, {$eventDAO->getTableName()}.id DESC", "joins" => true, "limit" => $paginator_page)); } //print_r ($event_array); // Alter header so client does not interpret output as HTML header("Content-Type: text/xml"); $this->template->render(array("title" => "Latest Events Feed", "event_array" => $event_array, "paginator_page" => $paginator_page)); }
/** * Run method with main page logic * * Populate template and Display form for editing an event entry. For POST requests, * check user credentials, check if event exists and then update entry in database. * Available to admins only * @access public */ public function run() { $session = Session::getInstance(); $user = $session->getUser(); //if (!$user || !$user->isAdmin ()) { if (!$user || !$user->validUser()) { $session->setMessage("Do not have permission to access", Session::MESSAGE_ERROR); header("Location: " . BASE_URL); return; } $form_errors = array(); $form_values = array("id" => "", "title" => "", "description" => "", "sanctioned" => "", "status" => "", "date" => "", "platform" => ""); $eventDAO = EventDAO::getInstance(); $event = null; if (!empty($_POST)) { $form_values["id"] = isset($_POST["id"]) && is_numeric($_POST["id"]) ? intval($_POST["id"]) : ""; $form_values["title"] = isset($_POST["title"]) ? trim($_POST["title"]) : ""; $form_values["description"] = isset($_POST["description"]) ? trim($_POST["description"]) : ""; $form_values["platform"] = isset($_POST["platform"]) ? trim($_POST["platform"]) : ""; $form_values["sanctioned"] = isset($_POST["sanctioned"]) ? trim($_POST["sanctioned"]) : ""; $form_values["status"] = isset($_POST["status"]) ? trim($_POST["status"]) : ""; $form_values["date"] = isset($_POST["date"]) ? trim($_POST["date"]) : ""; if (empty($form_values["id"])) { $form_errors["id"] = "No id specified"; } if (empty($form_values["title"])) { $form_errors["title"] = "No title specified"; } if (empty($form_values["description"])) { $form_errors["description"] = "No description specified"; } if (empty($form_values["platform"])) { $form_errors["platform"] = "No platform specified"; } else { if (!is_numeric($form_values["platform"])) { $form_errors["platform"] = "Platform choice must be an integer value"; } else { $platformDAO = PlatformDAO::getInstance(); $platform = $platformDAO->load($form_values["platform"]); if (!$platform) { $form_errors["platform"] = "Invalid platform specified"; } } } if ($user->isAdmin() && empty($form_values["sanctioned"])) { $form_errors["sanctioned"] = "No sanctioned flag specified"; } else { if ($user->isAdmin() && strcmp($form_values["sanctioned"], "true") != 0 && strcmp($form_values["sanctioned"], "false") != 0) { $form_errors["sanctioned"] = "sanctioned flag must be a boolean value"; } } if ($user->isAdmin() && empty($form_values["status"])) { $form_errors["status"] = "No status flag specified"; } else { if ($user->isAdmin() && !is_numeric($form_values["status"])) { $form_errors["status"] = "Status flag must be an integer value"; } else { if ($user->isAdmin()) { $status = intval($form_values["status"]); $tmp = new Event(); try { $tmp->setStatus($status); } catch (Exception $e) { $form_errors["status"] = "Invalid value for status"; } } } } if (empty($form_values["date"])) { $form_errors["date"] = "No date specified"; } else { if (strtotime($_POST["date"]) == 0) { $form_errors["date"] = "An invalid date was specified"; $form_values["date"] = ""; } } if (empty($form_errors)) { $event = $eventDAO->load($form_values["id"]); if ($event && ($user->isAdmin() || $event->getUserId() == $user->getId())) { $event->setTitle($form_values["title"]); $event->setDescription($form_values["description"]); $event->setPlatformId(intval($form_values["platform"])); if ($user->isAdmin() || $user->validUser() && $user->getUserType() == User::TRUSTED_TYPE) { $sanctioned_value = strcmp($form_values["sanctioned"], "true") == 0 ? true : false; $event->setSanctioned($sanctioned_value); $event->setStatus($form_values["status"]); } $pubtimestamp = strtotime($_POST["date"]); $event->setDate($pubtimestamp); $event->setUserId($user->id); //print_r ($event); if ($eventDAO->save($event)) { // Attempt to ignore for regular admin edits if ($event->getUserId() == $user->getId()) { require_once joinPath(INCLUDES_DIR, "models", "Attendance.php"); Attendance::emailAttendees($event, $user); } $session->setMessage("Event details saved"); header("Location: edit_event.php?id={$event->getId()}"); return; } else { $session->setMessage("Event details could not be saved", Session::MESSAGE_ERROR); } } } else { if (empty($form_errors["id"])) { $event = $eventDAO->load($form_values["id"]); } } } else { if (!empty($_GET)) { $form_values["id"] = isset($_GET["id"]) ? $_GET["id"] : ""; if (empty($form_values["id"])) { header("Location: " . BASE_URL); return; } else { $event = $eventDAO->load($form_values["id"]); // Event does not exist. Pass null to template if (!$event) { } else { if (!$user->isAdmin() && $event->userId != $user->id) { $session->setMessage("Do not have permission to edit page", Session::MESSAGE_ERROR); header("Location: " . BASE_URL); return; } else { $form_values["id"] = $event->getId(); $form_values["title"] = $event->getTitle(); $form_values["description"] = $event->getDescription(); $form_values["sanctioned"] = $event->getSanctioned() == true ? "true" : "false"; $form_values["status"] = $event->getStatus(); $form_values["date"] = strftime("%d %B %Y", $event->getDate()); $form_values["platform"] = $event->getPlatformId(); } } } } } $platformDAO = PlatformDAO::getInstance(); $platform_array = $platformDAO->all(); $this->template->render(array("title" => "Edit Event", "extra_header" => joinPath("headers", "jscal_header_tpl.php"), "main_page" => "edit_event_tpl.php", "session" => $session, "event" => $event, "form_values" => $form_values, "form_errors" => $form_errors, "platform_array" => $platform_array)); }
/** * Run method with main page logic * * Read in events from the database. Populate template and display an interface to administer event data * for allowing bulk deletion of events, deletion of a single * event, links to editing and viewing each event entry. * Available to admins only * @access public */ public function run() { $PAGINATION_LIMIT = 10; $session = Session::getInstance(); $user = $session->getUser(); // Check for admin user if (!$user || !$user->isAdmin()) { $session->setMessage("Do not have permission to access", Session::MESSAGE_ERROR); header("Location: " . BASE_URL); return; } $page = isset($_GET["page"]) && is_numeric($_GET["page"]) ? intval($_GET["page"]) : 1; if ($page < 1) { $page = 1; } $action = isset($_GET["action"]) ? trim($_GET["action"]) : ""; $eventDAO = EventDAO::getInstance(); $event_array = $paginator_page = null; $content_title = ""; // Check for POST request and necessary variable for deletion if (!empty($_POST) && !empty($_POST["ids"]) && !empty($_POST["action"]) && empty($_POST["domodstatus"])) { $action = isset($_POST["action"]) ? trim($_POST["action"]) : ""; if (!strcmp($action, "delete") == 0) { header("Location: " . BASE_URL); return; } $status = $eventDAO->deleteByIds($_POST["ids"]); if ($status) { $session->setMessage("Selected events deleted"); header("Location: {$_SERVER["PHP_SELF"]}"); return; } else { $session->setMessage("Deletion failed", Session::MESSAGE_ERROR); header("Location: {$_SERVER["PHP_SELF"]}"); return; } } else { if (!empty($_GET) && !empty($_GET["ids"]) && !empty($_GET["domodstatus"])) { $status = isset($_GET["status"]) ? trim($_GET["status"]) : ""; if (!empty($status)) { $status = intval($status); $tmp = new Event(); try { $tmp->setStatus($status); } catch (Exception $e) { $session->setMessage("Invalid status choice"); header("Location: {$_SERVER["PHP_SELF"]}"); return; } } $status = $eventDAO->saveStatusByIds($status, $_GET["ids"]); if ($status) { $session->setMessage("Selected events updated"); header("Location: {$_SERVER["PHP_SELF"]}"); return; } else { $session->setMessage("Update failed", Session::MESSAGE_ERROR); header("Location: {$_SERVER["PHP_SELF"]}"); return; } } else { if (strcmp($action, "delete") == 0 && !empty($_GET["ids"])) { $content_title = "Delete Events"; $event_array = $eventDAO->allByIds($_GET["ids"]); } else { if (strcmp($action, "delete") == 0) { } else { $count = $eventDAO->count(); $paginator = new Paginator($count, $PAGINATION_LIMIT); $paginator_page = $paginator->getPage($page); $event_array = $eventDAO->all(array("limit" => $paginator_page, "joins" => true)); } } } } $this->template->render(array("title" => "Admin - Event Options", "main_page" => "event_options_tpl.php", "session" => $session, "event_array" => $event_array, "paginator_page" => $paginator_page, "action" => $action, "content_title" => $content_title)); }
/** * Delete instances of a User entities with the ids specified in the ids array. LEFT JOIN clauses will be added to delete any associated attendance records, pages, articles and events * * @access public * @param array $ids Array containing int ids of User entities to delete * @param array $options (Optional) Read documentation on parseOptions for details * @return bool Return status of PDOStatement execute method */ public function deleteByIds($ids, $options = null) { if (!is_array($ids)) { throw new InvalidArgumentException("Must pass array of ids as the first parameter"); } // Import associated DAOs require_once "Attendance.php"; require_once "Page.php"; require_once "Article.php"; require_once "Event.php"; $attendDAO = AttendanceDAO::getInstance(); $pagesDAO = PageDAO::getInstance(); $articlesDAO = ArticleDAO::getInstance(); $eventsDAO = EventDAO::getInstance(); $str = ""; for ($i = 0; $i < count($ids) - 1; $i++) { $str .= "?,"; } $str .= "?"; // Use LEFT JOIN in case user does not have some entries $query = "DELETE FROM {$this->tableName}, {$attendDAO->getTableName()}, {$pagesDAO->getTableName()}, {$articlesDAO->getTableName()}, {$eventsDAO->getTableName()} USING {$this->tableName} LEFT JOIN {$attendDAO->getTableName()} ON {$this->tableName}.id = {$attendDAO->getTableName()}.userId LEFT JOIN {$pagesDAO->getTableName()} ON {$this->tableName}.id = {$pagesDAO->getTableName()}.userId LEFT JOIN {$articlesDAO->getTableName()} ON {$this->tableName}.id = {$articlesDAO->getTableName()}.userId LEFT JOIN {$eventsDAO->getTableName()} ON {$this->tableName}.id = {$eventsDAO->getTableName()}.userId WHERE {$this->tableName}.id IN ({$str})"; //echo $query; $stmt = self::$dbh->prepare($query); $params = $ids; $status = $stmt->execute($params); return $status; }
/** * Retrieve instance of an EventDAO or create one if it does * not exist. * * @access public * @static * @return EventDAO */ public static function getInstance() { if (!isset(self::$instance)) { self::$instance = new self(); } return self::$instance; }
/** * Run method with main page logic * * Populate template and display form for creating a new event entry. Regular users are allowed to create events but an * admin must approve them before they are visible on the site. Trusted users are allowed to create * events that will immediately be visible on the event calendar. For POST request, * validate form data and save information to database. Available to members only * @access public */ public function run() { $session = Session::getInstance(); $user = $session->getUser(); //if (!$user || !$user->isAdmin ()) { if (!$user || !$user->validUser()) { $session->setMessage("Do not have permission to access", Session::MESSAGE_ERROR); header("Location: " . BASE_URL); return; } $form_errors = array(); $form_values = array("title" => "", "description" => "", "sanctioned" => "", "status" => "", "date" => "", "platform" => ""); $eventDAO = EventDAO::getInstance(); //$event_array = $eventDAO->all (); if (!empty($_POST)) { $form_values["title"] = isset($_POST["title"]) ? trim($_POST["title"]) : ""; $form_values["description"] = isset($_POST["description"]) ? trim($_POST["description"]) : ""; $form_values["platform"] = isset($_POST["platform"]) ? trim($_POST["platform"]) : ""; $form_values["sanctioned"] = isset($_POST["sanctioned"]) ? trim($_POST["sanctioned"]) : ""; $form_values["status"] = isset($_POST["status"]) ? trim($_POST["status"]) : ""; $form_values["date"] = isset($_POST["date"]) ? trim($_POST["date"]) : ""; if (empty($form_values["title"])) { $form_errors["title"] = "No title specified"; } if (empty($form_values["description"])) { $form_errors["description"] = "No description specified"; } if (empty($form_values["platform"])) { $form_errors["platform"] = "No platform specified"; } else { if (!is_numeric($form_values["platform"])) { $form_errors["platform"] = "Platform choice must be an integer value"; } else { $platform = intval($form_values["platform"]); $tmp = new Event(); try { $tmp->setPlatformId($platform); } catch (Exception $e) { $form_errors["platform"] = "Invalid value for platform"; } } } if ($user->isAdmin() && empty($form_values["sanctioned"])) { $form_errors["sanctioned"] = "No sanctioned flag specified"; } else { if ($user->isAdmin() && strcmp($form_values["sanctioned"], "true") != 0 && strcmp($form_values["sanctioned"], "false") != 0) { $form_errors["sanctioned"] = "sanctioned flag must be a boolean value"; } } if ($user->isAdmin() && empty($form_values["status"])) { $form_errors["status"] = "No status flag specified"; } else { if ($user->isAdmin() && !is_numeric($form_values["status"])) { $form_errors["status"] = "Status flag must be an integer value"; } else { if ($user->isAdmin()) { $status = intval($form_values["status"]); $tmp = new Event(); try { $tmp->setStatus($status); } catch (Exception $e) { $form_errors["status"] = "Invalid value for status"; } } } } if (empty($form_values["date"])) { $form_errors["date"] = "No date specified"; } else { if (strtotime($_POST["date"]) == 0) { $form_errors["date"] = "An invalid date was specified"; $form_values["date"] = ""; } } if (empty($form_errors)) { $event = new Event(); $event->setTitle($form_values["title"]); $event->setDescription($form_values["description"]); $event->setPlatformId(intval($form_values["platform"])); if ($user->isAdmin() || $user->validUser() && $user->getUserType() == User::TRUSTED_TYPE) { $sanctioned_value = strcmp($form_values["sanctioned"], "true") == 0 ? true : false; $event->setSanctioned($sanctioned_value); $event->setStatus($form_values["status"]); } else { if ($user->validUser()) { $event->setSanctioned(false); $event->setStatus(Event::PENDING_STATUS); } } $pubtimestamp = strtotime($_POST["date"]); $event->setDate($pubtimestamp); $event->setUserId($user->id); //print_r ($event); if ($eventDAO->insert($event)) { $session->setMessage("Event details saved"); header("Location: edit_event.php?id={$event->id}"); return; } else { $session->setMessage("Event details could not be saved", Session::MESSAGE_ERROR); } } } $platformDAO = PlatformDAO::getInstance(); $platform_array = $platformDAO->all(); $this->template->render(array("title" => "Create Event", "extra_header" => joinPath("headers", "jscal_header_tpl.php"), "main_page" => "create_event_tpl.php", "session" => $session, "form_errors" => $form_errors, "form_values" => $form_values, "platform_array" => $platform_array)); }
/** * Parse the options array for limit clauses and order by clauses. The valid keys and value types are specified below. * limit - Page object. Will take values from a Paginator Page object and * set LIMIT and OFFSET portions of database query accordingly * * joins - bool. If true, an INNER JOIN will be done to retrieve the * Event associated with the platform * * order - string. Concatenate string with ORDER BY operator. * Will add table name to field if only associated with current table. * @access private * @param array &$options */ protected function parseOptions(&$options) { if (!is_array($options)) { throw new InvalidArgumentException("Options for a database access function must be in an array"); } if (array_key_exists("limit", $options) && $options["limit"] instanceof Page) { $this->query_limit .= $this->getLimitClause($options["limit"]); } if (array_key_exists("joins", $options) && $options["joins"] == true) { $eventDAO = EventDAO::getInstance(); $this->query_select .= ", " . $eventDAO->buildColumnString(); $this->query_joins .= " INNER JOIN (" . $eventDAO->getTableName() . ") ON (" . $eventDAO->getTableName() . ".platformId = " . $this->getTableName() . ".id) "; $this->select_columns = array_merge($this->select_columns, $eventDAO->buildColumnArray()); $this->joins = true; } if (array_key_exists("order", $options) && is_string($options["order"])) { // Reference to attendance member if (strpos($options["order"], ".") === false) { $this->query_order = "ORDER BY " . $this->tableName . "." . $options["order"]; } else { if (strpos($options["order"], "events.") === 0 && $this->joins) { $this->query_order = "ORDER BY " . $options["order"]; } else { throw new InvalidArgumentException("Invalid configuration for order option"); } } } }
/** * Run method with main page logic * * Reads in events for a given day or current day if no parameters are passed. * Allow filtering by platform id. Populate template and display event data on page. * @access public */ public function run() { $PAGINATION_LIMIT = 10; $session = Session::getInstance(); $user = $session->getUser(); $eventDAO = EventDAO::getInstance(); $page = isset($_GET["page"]) && is_numeric($_GET["page"]) ? intval($_GET["page"]) : 1; $platform_id = isset($_GET["platform"]) && is_numeric($_GET["platform"]) ? intval($_GET["platform"]) : 0; $month = isset($_GET["month"]) && is_numeric($_GET["month"]) ? intval($_GET["month"]) : 0; $day = isset($_GET["day"]) && is_numeric($_GET["day"]) ? intval($_GET["day"]) : 0; $year = isset($_GET["year"]) && is_numeric($_GET["year"]) ? intval($_GET["year"]) : 0; if ($page < 1) { $page = 1; } $count = $paginator = $paginator_page = $event_array = $next_eventday = $prev_eventday = $queryVars = $current_platform = null; if ($platform_id > 0 && checkdate($month, $day, $year)) { $start = mktime(0, 0, 0, $month, $day, $year); $end = strtotime("+1 day", $start) - 1; $count = $eventDAO->countPlatformStatusAndRange($platform_id, Event::APPROVED_STATUS, $start, $end); $paginator = new Paginator($count, $PAGINATION_LIMIT); $paginator_page = $paginator->getPage($page); $event_array = $eventDAO->allByPlatformStatusAndRange($platform_id, Event::APPROVED_STATUS, $start, $end, array("order" => "{$eventDAO->getTableName()}.date DESC, {$eventDAO->getTableName()}.id DESC", "joins" => true, "limit" => $paginator_page)); $queryVars = array("platform" => $platform_id); } else { if ($platform_id > 0) { $start = mktime(0, 0, 0); $end = strtotime("+1 day", $start) - 1; $count = $eventDAO->countPlatformStatusAndRange($platform_id, Event::APPROVED_STATUS, $start, $end); $paginator = new Paginator($count, $PAGINATION_LIMIT); $paginator_page = $paginator->getPage($page); $event_array = $eventDAO->allByPlatformStatusAndRange($platform_id, Event::APPROVED_STATUS, $start, $end, array("order" => "{$eventDAO->getTableName()}.date DESC, {$eventDAO->getTableName()}.id DESC", "joins" => true, "limit" => $paginator_page)); $queryVars = array("platform" => $platform_id); } else { if (checkdate($month, $day, $year)) { $start = mktime(0, 0, 0, $month, $day, $year); $end = strtotime("+1 day", $start) - 1; $count = $eventDAO->countStatusAndRange(Event::APPROVED_STATUS, $start, $end); $paginator = new Paginator($count, $PAGINATION_LIMIT); $paginator_page = $paginator->getPage($page); $event_array = $eventDAO->allByStatusAndRange(Event::APPROVED_STATUS, $start, $end, array("order" => "{$eventDAO->getTableName()}.date DESC, {$eventDAO->getTableName()}.id DESC", "joins" => true, "limit" => $paginator_page)); } else { $start = mktime(0, 0, 0); $end = strtotime("+1 day", $start) - 1; $count = $eventDAO->countStatusAndRange(Event::APPROVED_STATUS, $start, $end); $paginator = new Paginator($count, $PAGINATION_LIMIT); $paginator_page = $paginator->getPage($page); $event_array = $eventDAO->allByStatusAndRange(Event::APPROVED_STATUS, $start, $end, array("order" => "{$eventDAO->getTableName()}.date DESC, {$eventDAO->getTableName()}.id DESC", "joins" => true, "limit" => $paginator_page)); } } } $platformDAO = PlatformDAO::getInstance(); $platform_array = $platformDAO->all(); if ($platform_id > 0) { $current_platform = $platformDAO->load($platform_id); $next_eventday = $eventDAO->loadByNextDayPlatform($platform_id, $end, Event::APPROVED_STATUS); $prev_eventday = $eventDAO->loadByPreviousDayPlatform($platform_id, $start, Event::APPROVED_STATUS); } else { $next_eventday = $eventDAO->loadByNextDay($end, Event::APPROVED_STATUS); $prev_eventday = $eventDAO->loadByPreviousDay($start, Event::APPROVED_STATUS); } $this->template->render(array("title" => "Event List for day " . strftime(strftime("%B %d, %Y", $start)), "main_page" => "events_day_tpl.php", "event_array" => $event_array, "session" => $session, "paginator_page" => $paginator_page, "start" => $start, "end" => $end, "next_eventday" => $next_eventday, "prev_eventday" => $prev_eventday, "sidebar_extra" => joinPath("fragments", "event_sidebar_tpl.php"), "platform_array" => $platform_array, "queryVars" => $queryVars, "current_platform" => $current_platform)); }
/** * Run method with main page logic * * MEMBERS ONLY. POST requests only. Check that the user has a valid session and that a specified event exists. If true, * make sure that the user does not already have an Attendance record. If no record exists, * create new Attendance record and save it to database. * @access public */ public function run() { $session = Session::getInstance(); $user = $session->getUser(); if (!$user || !$user->validUser()) { $session->setMessage("Do not have permission to access", Session::MESSAGE_ERROR); header("Location: " . BASE_URL); return; } $eventDAO = EventDAO::getInstance(); $attendDAO = AttendanceDAO::getInstance(); if (!empty($_POST)) { $event_id = isset($_POST["eventid"]) && is_numeric($_POST["eventid"]) ? intval($_POST["eventid"]) : 0; $action = isset($_POST["action"]) ? $_POST["action"] : ""; if (empty($event_id) || $event_id < 0) { $session->setMessage("Invalid event id", Session::MESSAGE_ERROR); header("Location: " . BASE_URL); return; } $event = $eventDAO->load($event_id); if (!$event) { $session->setMessage("Event could not be found", Session::MESSAGE_ERROR); header("Location: " . BASE_URL); return; } if ($action && strcmp($action, "remove") == 0) { $attend = $attendDAO->loadExists($event, $user); if (!$attend) { $session->setMessage("You are not marked as attending", Session::MESSAGE_ERROR); header("Location: {$event->getAbsoluteUrl()}"); return; } if ($attendDAO->delete($attend)) { $session->setMessage("You are no longer as attending"); header("Location: {$event->getAbsoluteUrl()}"); return; } else { $session->setMessage("Request for attendance removal failed", Session::MESSAGE_ERROR); header("Location: {$event->getAbsoluteUrl()}"); return; } } else { $attend = $attendDAO->loadExists($event, $user); if ($attend) { $session->setMessage("You are already marked as attending", Session::MESSAGE_ERROR); header("Location: {$event->getAbsoluteUrl()}"); return; } $attend = new Attendance(); $attend->setEventId($event->id); $attend->setUserId($user->id); if ($attendDAO->insert($attend)) { $session->setMessage("You are now marked as attending"); header("Location: {$event->getAbsoluteUrl()}"); return; } else { $session->setMessage("Request for attendance failed", Session::MESSAGE_ERROR); header("Location: {$event->getAbsoluteUrl()}"); return; } } } header("Location: " . BASE_URL); return; }