/** * 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 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)); }
/** * 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 * User and Platform associated with the event * * 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) { $userDAO = UserDAO::getInstance(); $platformDAO = PlatformDAO::getInstance(); $this->query_select .= ", " . $userDAO->buildColumnString() . ", {$platformDAO->buildColumnString()}"; $this->query_joins .= " INNER JOIN (" . $userDAO->getTableName() . ", {$platformDAO->getTableName()}) ON (" . $userDAO->getTableName() . ".id = " . $this->getTableName() . ".userId AND {$platformDAO->getTableName()}.id = {$this->tableName}.platformId) "; $this->select_columns = array_merge($this->select_columns, $userDAO->buildColumnArray()); $this->select_columns = array_merge($this->select_columns, $platformDAO->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"], "users.") === 0 && $this->joins) { $this->query_order = "ORDER BY " . $options["order"]; } else { $this->query_order = "ORDER BY " . $options["order"]; } } //else { // throw new InvalidArgumentException ("Invalid configuration for order option"); //} } }
/** * 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)); }
/** * Retrieve instance of an PlatformDAO or create one if it does * not exist. * * @access public * @static * @return PlatformDAO */ public static function getInstance() { if (!isset(self::$instance)) { self::$instance = new self(); } return self::$instance; }
/** * 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)); }