From deac2b72545c65c85c8c81f09eaba7e06e8ac201 Mon Sep 17 00:00:00 2001 From: Chad Little Date: Wed, 14 Sep 2005 20:44:55 +0000 Subject: Multiple calendar selection patch. Needs formatting. --- day.php | 4 +++- functions/calendar_functions.php | 37 ++++++++++++++++++++++++++++--------- functions/init.inc.php | 34 ++++++++++++++++++++++++++++++---- month.php | 3 ++- templates/default/calendar_nav.tpl | 7 +++++++ templates/default/sidebar.tpl | 7 +++++++ week.php | 2 ++ 7 files changed, 79 insertions(+), 15 deletions(-) diff --git a/day.php b/day.php index 661b967..0936296 100644 --- a/day.php +++ b/day.php @@ -34,6 +34,7 @@ $list_months = list_months(); $list_weeks = list_weeks(); $list_jumps = list_jumps(); $list_calcolors = list_calcolors(); +$list_icals_pick = display_ical_list(availableCalendars($username, $password, $ALL_CALENDARS_COMBINED), TRUE); // login/logout $is_logged_in = ($username != '' && !$invalid_login) ? true : false; @@ -58,7 +59,7 @@ $page->replace_tags(array( 'cal' => $cal, 'getdate' => $getdate, 'cpath' => $cpath, - 'calendar_name' => $calendar_name, + 'calendar_name' => (is_array($calendar_name) ? "Multiple" : $calendar_name), 'current_view' => $current_view, 'display_date' => $display_date, 'sidebar_date' => $sidebar_date, @@ -76,6 +77,7 @@ $page->replace_tags(array( 'username' => $username, 'logout_querys' => $logout_querys, 'list_icals' => $list_icals, + 'list_icals_pick' => $list_icals_pick, 'list_years' => $list_years, 'list_months' => $list_months, 'list_weeks' => $list_weeks, diff --git a/functions/calendar_functions.php b/functions/calendar_functions.php index e04883d..ebe1634 100644 --- a/functions/calendar_functions.php +++ b/functions/calendar_functions.php @@ -76,33 +76,43 @@ function availableCalendars($username, $password, $cal_filename, $admin = false) // Otherwise just include the requested calendar. else { + if(!is_array($cal_filename)) { + $cal_filename_local = array($cal_filename); + } + else { + $cal_filename_local = $cal_filename; + } + + foreach($cal_filename_local as $c) { + // Make sure this is not a blacklisted calendar. We don't have // to remove a .ics suffix because it would not have been passed // in the argument. - if (in_array($cal_filename, $blacklisted_cals)) - exit(error($lang['l_error_restrictedcal'], $cal_filename)); + if (in_array($c, $blacklisted_cals)) + exit(error($lang['l_error_restrictedcal'], $c)); // If HTTP authenticated, make sure this calendar is available // to the user. if (isset($http_user)) { - if (!in_array($cal_filename, $apache_map[$http_user])) { + if (!in_array($c, $apache_map[$http_user])) { // Use the invalid calendar message so that the user is // not made aware of locked calendars. - exit(error($lang['l_error_invalidcal'], $cal_filename)); + exit(error($lang['l_error_invalidcal'], $c)); } } // Otherwise make sure this calendar is not locked. - else if (in_array($cal_filename, $locked_cals) && - !in_array($cal_filename, $unlocked_cals)) + else if (in_array($c, $locked_cals) && + !in_array($c, $unlocked_cals)) { // Use the invalid calendar message so that the user is // not made aware of locked calendars. - exit(error($lang['l_error_invalidcal'], $cal_filename)); + exit(error($lang['l_error_invalidcal'], $c)); } // Add this calendar. - array_push($calendars, "$calendar_path/$cal_filename.ics"); + array_push($calendars, "$calendar_path/$c.ics"); + } } // Return the sorted calendar list. @@ -139,7 +149,7 @@ function availableCalendarNames($username, $password, $cal_filename, $admin = fa // is not printed out by this function. // // $cals = The calendars (entire path, e.g. from availableCalendars). -function display_ical_list($cals) { +function display_ical_list($cals, $pick=FALSE) { global $cal, $ALL_CALENDARS_COMBINED, $current_view, $getdate, $calendar_lang, $all_cal_comb_lang; // Print each calendar option. @@ -177,6 +187,14 @@ function display_ical_list($cals) { // The submitted calendar will be encoded, and always use http:// // if it is a webcal. So that is how we perform the comparison when // trying to figure out if this is the selected calendar. + if($pick) { + if (in_array($cal_encoded_tmp, explode(",", $cal))) { + $return .= "\n"; + } else { + $return .= "\n"; + } + } + else { $cal_httpPrefix_tmp = str_replace('webcal://', 'http://', $cal_tmp); if ($cal_httpPrefix_tmp == urldecode($cal)) { $return .= ""; @@ -184,6 +202,7 @@ function display_ical_list($cals) { $return .= ""; } } + } // option to open all (non-web) calenders together if ($cal == $ALL_CALENDARS_COMBINED) { diff --git a/functions/init.inc.php b/functions/init.inc.php index 7c01cf2..b5f0018 100644 --- a/functions/init.inc.php +++ b/functions/init.inc.php @@ -80,8 +80,21 @@ if ($calendar_path == '') { } $is_webcal = FALSE; -if (isset($_GET['cal']) && $_GET['cal'] != '') { +if (isset($_GET['cal'])) { + //if we get a comma-separated list of calendars, split into array + if(stristr($_GET['cal'], ",")) { + $_GET['cal'] = explode(",", $_GET['cal']); + } + //if we have an array of calendard, decode each (though I'm not sure this is necessary) + if(is_array($_GET['cal'])) { + $cal_filename = array(); + foreach($_GET['cal'] as $c) { + $cal_filename[] = urldecode($c); + } + } + else { $cal_filename = urldecode($_GET['cal']); + } } else { if (isset($default_cal_check)) { if ($default_cal_check != $ALL_CALENDARS_COMBINED) { @@ -100,7 +113,7 @@ if (isset($_GET['cal']) && $_GET['cal'] != '') { } } -if (substr($cal_filename, 0, 7) == 'http://' || substr($cal_filename, 0, 8) == 'https://' || substr($cal_filename, 0, 9) == 'webcal://') { +if (!is_array($cal_filename) && (substr($cal_filename, 0, 7) == 'http://' || substr($cal_filename, 0, 8) == 'https://' || substr($cal_filename, 0, 9) == 'webcal://')) { $is_webcal = TRUE; $cal_webcalPrefix = str_replace('http://','webcal://',$cal_filename); $cal_httpPrefix = str_replace('webcal://','http://',$cal_filename); @@ -122,9 +135,22 @@ if ($is_webcal == TRUE) { exit(error($lang['l_error_remotecal'], $_GET['cal'])); } } else { - $cal_displayname = str_replace('32', ' ', $cal_filename); + $cal_displayname = str_replace('32', ' ', (is_array($cal_filename) ? implode(", ", $cal_filename) : $cal_filename)); + if(is_array($cal_filename)) { + $cal = array(); + $blacklisted = FALSE; + foreach($cal_filename as $c) { + $cal[] = urlencode($c); + if(in_array($c, $blacklisted_cals)) $blacklisted = TRUE; + } + $cal = implode(",", $cal); + } + else { $cal = urlencode($cal_filename); - if (in_array($cal_filename, $blacklisted_cals)) { + $blacklisted = in_array($cal_filename, $blacklisted_cals); + } + + if ($blacklisted) { exit(error($lang['l_error_restrictedcal'], $cal_filename)); } else { if (!isset($filename)) { diff --git a/month.php b/month.php index 87fb280..b2b38a3 100644 --- a/month.php +++ b/month.php @@ -48,6 +48,7 @@ $list_months = list_months(); $list_weeks = list_weeks(); $list_jumps = list_jumps(); $list_calcolors = list_calcolors(); +$list_icals_pick = display_ical_list(availableCalendars($username, $password, $ALL_CALENDARS_COMBINED), TRUE); $page = new Page(BASE.'templates/'.$template.'/month.tpl'); @@ -72,13 +73,13 @@ $page->replace_tags(array( 'rss_available' => '', 'rss_valid' => '', 'show_search' => $show_search, - 'show_search' => $show_search, 'next_month' => $next_month, 'prev_month' => $prev_month, 'show_goto' => '', 'is_logged_in' => '', 'list_jumps' => $list_jumps, 'list_icals' => $list_icals, + 'list_icals_pick' => $list_icals_pick, 'list_years' => $list_years, 'list_months' => $list_months, 'list_weeks' => $list_weeks, diff --git a/templates/default/calendar_nav.tpl b/templates/default/calendar_nav.tpl index 75fac01..c89468b 100644 --- a/templates/default/calendar_nav.tpl +++ b/templates/default/calendar_nav.tpl @@ -38,6 +38,13 @@ +
+
Pick Multiple:
+
+ +
+ +
diff --git a/templates/default/sidebar.tpl b/templates/default/sidebar.tpl index c7ebe0a..81b93f7 100644 --- a/templates/default/sidebar.tpl +++ b/templates/default/sidebar.tpl @@ -91,6 +91,13 @@ +
+
Pick Multiple:
+
+ +
+ +
diff --git a/week.php b/week.php index e19b175..1018b5b 100644 --- a/week.php +++ b/week.php @@ -36,6 +36,7 @@ $list_months = list_months(); $list_weeks = list_weeks(); $list_jumps = list_jumps(); $list_calcolors = list_calcolors(); +$list_icals_pick = display_ical_list(availableCalendars($username, $password, $ALL_CALENDARS_COMBINED), TRUE); // login/logout $is_logged_in = ($username != '' && !$invalid_login) ? true : false; @@ -80,6 +81,7 @@ $page->replace_tags(array( 'username' => $username, 'logout_querys' => $logout_querys, 'list_icals' => $list_icals, + 'list_icals_pick' => $list_icals_pick, 'list_years' => $list_years, 'list_months' => $list_months, 'list_weeks' => $list_weeks, -- cgit v1.2.3