function show($view, $loc = null, $title = '') { global $user; global $db; $template = new template('calendarmodule', $view, $loc); $template->assign('moduletitle', $title); $canviewapproval = false; $inapproval = false; if ($user) { $canviewapproval = pathos_permissions_check("approve", $loc) || pathos_permissions_check("manage_approval", $loc); } if ($db->countObjects("calendar", "location_data='" . serialize($loc) . "' AND approved!=1")) { foreach ($db->selectObjects("calendar", "location_data='" . serialize($loc) . "' AND approved!=1") as $c) { if ($c->poster == $user->id) { $canviewapproval = true; } } $inapproval = true; } $time = isset($_GET['time']) ? $_GET['time'] : time(); $template->assign("time", $time); $viewconfig = $template->viewparams; if ($viewconfig === null) { $viewconfig = array("type" => "default"); } if (!defined("SYS_DATETIME")) { require_once BASE . "subsystems/datetime.php"; } if (!defined('SYS_SORTING')) { require_once BASE . 'subsystems/sorting.php'; } if (!function_exists("pathos_sorting_byEventStartAscending")) { function pathos_sorting_byEventStartAscending($a, $b) { return $a->eventstart < $b->eventstart ? -1 : 1; } } if ($viewconfig['type'] == "minical") { $monthly = array(); $datesWithEvents = array(); $info = getdate(time()); $info = getdate(time()); // Grab non-day numbers only (before end of month) $week = 0; $currentweek = 0; $currentday = $info['mday']; $infofirst = getdate(mktime(12, 0, 0, $info['mon'], 1, $info['year'])); if ($infofirst['wday'] == 0) { $monthly[$week] = array(); } // initialize for non days for ($i = 0 - $infofirst['wday']; $i < 0; $i++) { $monthly[$week][$i] = array("number" => -1, "ts" => -1); } $weekday = $infofirst['wday']; // day number in grid. if 7+, switch weeks // Grab day counts $endofmonth = pathos_datetime_endOfMonthDay(time()); for ($i = 1; $i <= $endofmonth; $i++) { $start = mktime(0, 0, 0, $info['mon'], $i, $info['year']); if ($i == $info['mday']) { $currentweek = $week; } #$monthly[$week][$i] = array("ts"=>$start,"number"=>$db->countObjects("calendar","location_data='".serialize($loc)."' AND approved!=0 AND (eventstart >= $start AND eventend <= " . ($start+86399) . ")")); // NO WORKFLOW CONSIDERATIONS $monthly[$week][$i] = array("ts" => $start, "number" => $db->countObjects("eventdate", "location_data='" . serialize($loc) . "' AND date = {$start}")); if ($monthly[$week][$i]["number"] > 0) { $datesWithEvents[] = $i; } if ($weekday >= 6) { $week++; $monthly[$week] = array(); // allocate an array for the next week $weekday = 0; } else { $weekday++; } } // Grab non-day numbers only (after end of month) for ($i = 1; $weekday && $i <= 7 - $weekday; $i++) { $monthly[$week][$i + $endofmonth] = -1; } $template->assign("datesWithEvents", implode(",", $datesWithEvents)); $template->assign("monthly", $monthly); $template->assign("currentweek", $currentweek); $template->assign("currentday", $currentday); $template->assign("now", time()); } else { if ($viewconfig['type'] == "byday") { $startperiod = 0; $totaldays = 0; if ($viewconfig['range'] == "week") { $startperiod = pathos_datetime_startOfWeekTimestamp($time); $totaldays = 7; } else { $startperiod = pathos_datetime_startOfMonthTimestamp($time); $totaldays = pathos_datetime_endOfMonthDay($time); } $template->assign("prev_timestamp", $startperiod - 3600); $template->assign("next_timestamp", $startperiod + $totaldays * 86400 + 3600); $days = array(); for ($i = 0; $i < $totaldays; $i++) { $start = $startperiod + $i * 86400; #$days[$start] = $db->selectObjects("calendar","location_data='".serialize($loc)."' AND (eventstart >= $start AND eventend <= " . ($start+86399) . ") AND approved!=0"); $edates = $db->selectObjects("eventdate", "location_data='" . serialize($loc) . "' AND date = {$start}"); $days[$start] = calendarmodule::_getEventsForDates($edates); for ($j = 0; $j < count($days[$start]); $j++) { $thisloc = pathos_core_makeLocation($loc->mod, $loc->src, $days[$start][$j]->id); $days[$start][$j]->permissions = array("administrate" => pathos_permissions_check("administrate", $thisloc) || pathos_permissions_check("administrate", $loc), "edit" => pathos_permissions_check("edit", $thisloc) || pathos_permissions_check("edit", $loc), "delete" => pathos_permissions_check("delete", $thisloc) || pathos_permissions_check("delete", $loc)); } usort($days[$start], "pathos_sorting_byEventStartAscending"); } $template->assign("days", $days); } else { if ($viewconfig['type'] == "monthly") { $monthly = array(); $counts = array(); $info = getdate($time); $nowinfo = getdate(time()); if ($info['mon'] != $nowinfo['mon']) { $nowinfo['mday'] = -10; } // Grab non-day numbers only (before end of month) $week = 0; $currentweek = -1; $timefirst = mktime(12, 0, 0, $info['mon'], 1, $info['year']); $infofirst = getdate($timefirst); if ($infofirst['wday'] == 0) { $monthly[$week] = array(); // initialize for non days $counts[$week] = array(); } for ($i = 1 - $infofirst['wday']; $i < 1; $i++) { $monthly[$week][$i] = array(); $counts[$week][$i] = -1; } $weekday = $infofirst['wday']; // day number in grid. if 7+, switch weeks // Grab day counts $endofmonth = pathos_datetime_endOfMonthDay($time); for ($i = 1; $i <= $endofmonth; $i++) { $start = mktime(0, 0, 0, $info['mon'], $i, $info['year']); if ($i == $nowinfo['mday']) { $currentweek = $week; } #$monthly[$week][$i] = $db->selectObjects("calendar","location_data='".serialize($loc)."' AND (eventstart >= $start AND eventend <= " . ($start+86399) . ") AND approved!=0"); $dates = $db->selectObjects("eventdate", "location_data='" . serialize($loc) . "' AND date = {$start}"); $monthly[$week][$i] = calendarmodule::_getEventsForDates($dates); $counts[$week][$i] = count($monthly[$week][$i]); if ($weekday >= 6) { $week++; $monthly[$week] = array(); // allocate an array for the next week $counts[$week] = array(); $weekday = 0; } else { $weekday++; } } // Grab non-day numbers only (after end of month) for ($i = 1; $weekday && $i < 8 - $weekday; $i++) { $monthly[$week][$i + $endofmonth] = array(); $counts[$week][$i + $endofmonth] = -1; } $template->assign("currentweek", $currentweek); $template->assign("monthly", $monthly); $template->assign("counts", $counts); $template->assign("nextmonth", $timefirst + 86400 * 45); $template->assign("prevmonth", $timefirst - 86400 * 15); $template->assign("now", $timefirst); } else { if ($viewconfig['type'] == "administration") { // Check perms and return if cant view if ($viewconfig['type'] == "administration" && !$user) { return; } $continue = pathos_permissions_check("administrate", $loc) || pathos_permissions_check("post", $loc) || pathos_permissions_check("edit", $loc) || pathos_permissions_check("delete", $loc) || pathos_permissions_check("approve", $loc) || pathos_permissions_check("manage_approval", $loc) ? 1 : 0; $dates = $db->selectObjects("eventdate", "location_data='" . serialize($loc) . "'"); $items = calendarmodule::_getEventsForDates($dates); if (!$continue) { foreach ($items as $i) { $iloc = pathos_core_makeLocation($loc->mod, $loc->src, $i->id); if (pathos_permissions_check("edit", $iloc) || pathos_permissions_check("delete", $iloc) || pathos_permissions_check("administrate", $iloc)) { $continue = true; } } } if (!$continue) { return; } for ($i = 0; $i < count($items); $i++) { $thisloc = pathos_core_makeLocation($loc->mod, $loc->src, $items[$i]->id); if ($user && $items[$i]->poster == $user->id) { $canviewapproval = 1; } $items[$i]->permissions = array("administrate" => pathos_permissions_check("administrate", $thisloc) || pathos_permissions_check("administrate", $loc), "edit" => pathos_permissions_check("edit", $thisloc) || pathos_permissions_check("edit", $loc), "delete" => pathos_permissions_check("delete", $thisloc) || pathos_permissions_check("delete", $loc)); } usort($items, "pathos_sorting_byEventStartAscending"); $template->assign("items", $items); } else { if ($viewconfig['type'] == "default") { if (!isset($viewconfig['range'])) { $viewconfig['range'] = "all"; } $limit = ''; if (isset($template->viewconfig) && isset($template->viewconfig['num_events']) && $template->viewconfig['num_events'] != 0) { $limit = $db->limit($template->viewconfig['num_events'], 0); } $items = null; $dates = null; $day = pathos_datetime_startOfDayTimestamp(time()); $sort_asc = true; // For the getEventsForDates call switch ($viewconfig['range']) { case "all": #$items = $db->selectObjects("calendar","location_data='" . serialize($loc) . "' AND approved!=0"); $dates = $db->selectObjects("eventdate", "location_data='" . serialize($loc) . "'"); break; case "upcoming": #$items = $db->selectObjects("calendar","location_data='" . serialize($loc) . "' AND approved!=0 AND eventstart >= ".time()); $dates = $db->selectObjects("eventdate", "location_data='" . serialize($loc) . "' AND date > {$day} ORDER BY date ASC " . $limit); break; case "past": #$items = $db->selectObjects("calendar","location_data='" . serialize($loc) . "' AND approved!=0 AND eventstart < ".time()); $dates = $db->selectObjects("eventdate", "location_data='" . serialize($loc) . "' AND date < {$day} ORDER BY date DESC " . $limit); $sort_asc = false; break; case "today": #$items = $db->selectObjects("calendar","location_data='" . serialize($loc) . "' AND approved!=0 AND eventstart >= ".pathos_datetime_startOfDayTimestamp(time()) . " AND eventend <= " . (pathos_datetime_startOfDayTimestamp(time()) + 86400)); $dates = $db->selectObjects("eventdate", "location_data='" . serialize($loc) . "' AND date = {$day}"); break; case "next": #$items = array($db->selectObject("calendar","location_data='" . serialize($loc) . "' AND approved!=0 AND eventstart >= ".time())); $dates = array($db->selectObject("eventdate", "location_data='" . serialize($loc) . "' AND date >= {$day}")); break; case "month": #$items = $db->selectObjects("calendar","location_data='" . serialize($loc) . "' AND approved!=0 AND eventstart >= ".pathos_datetime_startOfMonthTimestamp(time()) . " AND eventend <= " . pathos_datetime_endOfMonthTimestamp(time())); $dates = $db->selectObjects("eventdate", "location_data='" . serialize($loc) . "' AND date >= " . pathos_datetime_startOfMonthTimestamp(time()) . " AND date <= " . pathos_datetime_endOfMonthTimestamp(time())); break; } $items = calendarmodule::_getEventsForDates($dates, $sort_asc); for ($i = 0; $i < count($items); $i++) { $thisloc = pathos_core_makeLocation($loc->mod, $loc->src, $items[$i]->id); if ($user && $items[$i]->poster == $user->id) { $canviewapproval = 1; } $items[$i]->permissions = array('administrate' => pathos_permissions_check('administrate', $thisloc) || pathos_permissions_check('administrate', $loc), 'edit' => pathos_permissions_check('edit', $thisloc) || pathos_permissions_check('edit', $loc), 'delete' => pathos_permissions_check('delete', $thisloc) || pathos_permissions_check('delete', $loc)); } $template->assign('items', $items); } } } } } $template->assign('in_approval', $inapproval); $template->assign('canview_approval_link', $canviewapproval); $template->register_permissions(array('administrate', 'configure', 'post', 'edit', 'delete', 'manage_approval', 'manage_categories', 'view'), $loc); $cats = $db->selectObjectsIndexedArray("category", "location_data='" . serialize($loc) . "'"); $cats[0] = null; $cats[0]->name = "<i>{#i18n_noitemsfound#}</i>"; $cats[0]->color = "#000000"; $template->assign("categories", $cats); $config = $db->selectObject("calendarmodule_config", "location_data='" . serialize($loc) . "'"); if (!$config) { $config->enable_categories = 0; } $template->assign("modconfig", $config); $template->output(); }
# 59 Temple Place, # Suite 330, # Boston, MA 02111-1307 USA # # $Id: view_month.php,v 1.7 2005/04/21 19:07:07 filetreefrog Exp $ ################################################## if (!defined('PATHOS')) { exit(''); } pathos_flow_set(SYS_FLOW_PUBLIC, SYS_FLOW_ACTION); if (!defined('SYS_DATETIME')) { require_once BASE . 'subsystems/datetime.php'; } $time = isset($_GET['month']) ? $_GET['month'] : time(); $start_month = pathos_datetime_startOfMonthTimestamp($time); $end_month = pathos_datetime_endOfMonthTimestamp($time); $where = "location_data='" . serialize($loc) . "' AND (is_draft = 0 OR poster = " . ($user ? $user->id : -1) . ") AND posted >= {$start_month} AND posted <= {$end_month}"; if (!pathos_permissions_check('view_private', $loc)) { $where .= ' AND is_private = 0'; } $config = $db->selectObject('weblogmodule_config', "location_data='" . serialize($loc) . "'"); if ($config == null) { $config->allow_comments = 1; } $posts = $db->selectObjects('weblog_post', $where); if (!defined('SYS_SORTING')) { require_once BASE . 'subsystems/sorting.php'; } for ($i = 0; $i < count($posts); $i++) { $ploc = pathos_core_makeLocation($loc->mod, $loc->src, $posts[$i]->id); $posts[$i]->permissions = array('administrate' => pathos_permissions_check('administrate', $ploc), 'edit' => pathos_permissions_check('edit', $ploc), 'delete' => pathos_permissions_check('delete', $ploc), 'comment' => pathos_permissions_check('comment', $ploc), 'edit_comments' => pathos_permissions_check('edit_comments', $ploc), 'delete_comments' => pathos_permissions_check('delete_comments', $ploc), 'view_private' => pathos_permissions_check('view_private', $ploc));
function show($view, $loc = null, $title = '') { $template = new template('weblogmodule', $view, $loc); global $db; global $user; $user_id = $user ? $user->id : -1; $config = $db->selectObject('weblogmodule_config', "location_data='" . serialize($loc) . "'"); if ($config == null) { $config->allow_comments = 1; $config->items_per_page = 10; } $viewconfig = array('type' => 'default'); if (is_readable($template->viewdir . "/{$view}.config")) { $viewconfig = (include $template->viewdir . "/{$view}.config"); } $where = '(is_draft = 0 OR poster = ' . $user_id . ") AND location_data='" . serialize($loc) . "'"; if (!pathos_permissions_check('view_private', $loc)) { $where .= ' AND is_private = 0'; } if ($viewconfig['type'] == 'monthlist') { $months = array(); $min_date = $db->min('weblog_post', 'posted', 'location_data', $where); $max_date = $db->max('weblog_post', 'posted', 'location_data', $where); $months = array(); if (!defined('SYS_DATETIME')) { require_once BASE . 'subsystems/datetime.php'; } $start_month = pathos_datetime_startOfMonthTimestamp($min_date); $end_month = pathos_datetime_endOfMonthTimestamp($min_date) + 86399; do { $count = $db->countObjects('weblog_post', $where . ' AND posted >= ' . $start_month . ' AND posted <= ' . $end_month); if ($count) { $months[$start_month] = $count; } $start_month = $end_month + 1; $end_month = pathos_datetime_endOfMonthTimestamp($start_month) + 86399; } while ($start_month < $max_date); $template->assign('months', array_reverse($months, true)); } else { if ($viewconfig['type'] == 'calendar') { if (!defined('SYS_DATETIME')) { require_once BASE . 'subsystems/datetime.php'; } $month_days = pathos_datetime_monthlyDaysTimestamp(time()); for ($i = 0; $i < count($month_days); $i++) { foreach ($month_days[$i] as $mday => $timestamp) { if ($mday > 0) { // Got a valid one. Go with it. $month_days[$i][$mday] = array('number' => $db->countObjects('weblog_post', $where . ' AND posted >= ' . $timestamp . ' AND posted < ' . strtotime('+1 day', $timestamp)), 'ts' => $timestamp); } } } $template->assign('days', $month_days); $template->assign('now', time()); } else { $total = $db->countObjects('weblog_post', $where); $posts = $db->selectObjects('weblog_post', $where . ' ORDER BY posted DESC ' . $db->limit($config->items_per_page, 0)); if (!defined('SYS_SORTING')) { require_once BASE . 'subsystems/sorting.php'; } for ($i = 0; $i < count($posts); $i++) { $ploc = pathos_core_makeLocation($loc->mod, $loc->src, $posts[$i]->id); $posts[$i]->permissions = array('administrate' => pathos_permissions_check('administrate', $ploc), 'edit' => pathos_permissions_check('edit', $ploc), 'delete' => pathos_permissions_check('delete', $ploc), 'comment' => pathos_permissions_check('comment', $ploc), 'edit_comments' => pathos_permissions_check('edit_comments', $ploc), 'delete_comments' => pathos_permissions_check('delete_comments', $ploc), 'view_private' => pathos_permissions_check('view_private', $ploc)); $comments = $db->selectObjects('weblog_comment', 'parent_id=' . $posts[$i]->id); usort($comments, 'pathos_sorting_byPostedDescending'); $posts[$i]->comments = $comments; } usort($posts, 'pathos_sorting_byPostedDescending'); $template->assign('posts', $posts); $template->assign('total_posts', $total); } } $template->register_permissions(array('administrate', 'configure', 'post', 'edit', 'delete', 'comment', 'edit_comments', 'delete_comments', 'view_private'), $loc); $template->assign('config', $config); $template->assign('moduletitle', $title); $template->output(); }
function pathos_datetime_monthlyDaysTimestamp($timestamp) { $month_start = pathos_datetime_startOfMonthTimestamp($timestamp); $month_end = pathos_datetime_endOfMonthTimestamp($timestamp); $start_info = getdate($month_start); $end_info = getdate($month_end); $days = array(array()); for ($i = -1 * $start_info['wday']; $i < 0; $i++) { $days[0][$i] = -1; } $week = 0; $wday = $start_info['wday']; $mday = 1; while ($month_start <= $month_end) { $days[$week][$mday++] = $month_start; // Advance up a day. $month_start = strtotime('+1 day', $month_start); // Bump the weekday counter $wday++; if ($wday == 7) { // Went off the end of the weekdays. // Add a week $week++; // Make a holding array for it $days[$week] = array(); // Reset $wday to 0 (Sunday); $wday = 0; } } for ($i = 1; $wday && $i <= 7 - $wday; $i++) { $days[$week][-1 * $i] = -1; } return $days; }