Skip to content

Commit

Permalink
added agenda view
Browse files Browse the repository at this point in the history
  • Loading branch information
yllohy committed Oct 18, 2010
1 parent ac58b91 commit 28ff9e3
Show file tree
Hide file tree
Showing 12 changed files with 892 additions and 196 deletions.
149 changes: 149 additions & 0 deletions agenda.php
@@ -0,0 +1,149 @@
<?php

$current_view = 'print';
$printview = 'agenda';

if (!defined('BASE')) define('BASE', './');
require_once(BASE.'functions/date_functions.php');
require_once(BASE.'functions/init.inc.php');


// agenda.php will display all events
// between $start_time and $end_time
// If they are not both set, use a default value of +/- two weeks
// around the current date.
if (!isset($start_time) || !isset($end_time))
{
$start_time = strtotime("-2 weeks");
$end_time = strtotime("+2 weeks");
}

$mArray_begin = $start_time;
$mArray_end = $end_time;

//setlocale(LC_TIME, 'de_DE');

// override $timeFormat in english.inc.php. Check out: http://www.php.net/manual/en/function.date.php
$timeFormat = 'G';
$dateFormat_day = '%A, %d.%m.%Y';

$days = 14; if (isset($_GET['days'])) $days = $_GET['days'];
$table_width = 800; if (isset($_GET['table_width'])) $table_width = $_GET['table_width'];



$parse_month = date ("Ym", strtotime($getdate));
$events_week = 0;
$unix_time = strtotime($getdate);

$start_date = date("Y-m-d", $start_time);
$end_date = date("Y-m-d", $end_time);
$display_date = "$start_date - $end_date";

// application specific: set summer/winter term
$start_year = date("Y", $start_time);
$end_year = date("Y", $end_time);
if( $start_year == $end_year )
{
$nice_display_date = "Sommer $start_year";
}
else
{
$nice_display_date = "Winter $start_year/$end_year";
}

$week_start = date("Ymd", $start_time);
$week_end = date("Ymd", $end_time);
$next_day = date("Ymd", strtotime("+$days days", $unix_time));
$prev_day = date("Ymd", strtotime("-$days days", $unix_time));
$today = date('Ymd', time() + $second_offset);

require_once(BASE.'functions/ical_parser.php');
require_once(BASE.'functions/list_functions.php');
require_once(BASE.'functions/template.php');
header("Content-Type: text/html; charset=$charset");


$page = new Page(BASE.'templates/'.$template.'/agenda.tpl');

$page->replace_files(array(
'header' => BASE.'templates/'.$phpiCal_config->template.'/header.tpl',
'event_js' => BASE.'functions/event.js',
'footer' => BASE.'templates/'.$phpiCal_config->template.'/footer.tpl',
'sidebar' => BASE.'templates/'.$phpiCal_config->template.'/sidebar.tpl',
'search_box' => BASE.'templates/'.$phpiCal_config->template.'/search_box.tpl'
));

$page->replace_tags(array(
'version' => $phpiCal_config->phpicalendar_version,
'charset' => $phpiCal_config->charset,
'default_path' => $phpiCal_config->default_path,
'template' => $phpiCal_config->template,
'cal' => $cal,
'getdate' => $getdate,
'getcpath' => "&cpath=$cpath",
'cpath' => $cpath,
'calendar_name' => $cal_displayname,
'calendar_desc' => $cal_displaydesc,
'current_view' => $current_view,
'display_date' => $display_date,
'nice_display_date' => $nice_display_date,
'sidebar_date' => $sidebar_date,
'rss_powered' => $rss_powered,
'rss_available' => '',
'rss_valid' => '',
'show_search' => $phpiCal_config->show_search,
'next_day' => $next_day,
'prev_day' => $prev_day,
'show_goto' => '',
'show_user_login' => $show_user_login,
'invalid_login' => $invalid_login,
'login_querys' => $login_querys,
'is_logged_in' => $is_logged_in,
'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,
'list_jumps' => $list_jumps,
'legend' => $list_calcolors,
# 'style_select' => $style_select,
'l_goprint' => $lang['l_goprint'],
'l_preferences' => $lang['l_preferences'],
'l_calendar' => $lang['l_calendar'],
'l_legend' => $lang['l_legend'],
'l_tomorrows' => $lang['l_tomorrows'],
'l_jump' => $lang['l_jump'],
'l_todo' => $lang['l_todo'],
'l_prev' => $lang['l_prev'],
'l_next' => $lang['l_next'],
'l_day' => $lang['l_day'],
'l_week' => $lang['l_week'],
'l_month' => $lang['l_month'],
'l_year' => $lang['l_year'],
'l_pick_multiple' => $lang['l_pick_multiple'],
'l_powered_by' => $lang['l_powered_by'],
'l_subscribe' => $lang['l_subscribe'],
'l_download' => $lang['l_download'],
'l_search' => $lang['l_search'],
'l_this_site_is' => $lang['l_this_site_is'],


'days' => $days,
'today' => $today,
'table_width' => $table_width,
'l_time' => $lang['l_time'],
'l_summary' => $lang['l_summary'],
'l_description' => $lang['l_description'],
'l_location' => $lang['l_location'],
'l_no_results' => $lang['l_no_results']
));

$page->draw_agenda($page);
$page->draw_subscribe($page);

$page->output();

?>
46 changes: 46 additions & 0 deletions calendars/agenda_test.ics
@@ -0,0 +1,46 @@
BEGIN:VCALENDAR
PRODID:-//Mozilla.org/NONSGML Mozilla Calendar V1.1//EN
VERSION:2.0
X-WR-CALDESC:This is a calendar that can be used to test the agenda view o
f PHPicalendar. Every week
X-WR-CALDESC:John Doe and Jane Miles give example talks each Monday and Friday
X-LIC-ERROR;X-LIC-ERRORTYPE=PROPERTY-PARSE-ERROR:Parse error in property n
ame: at 11
X-WR-CALNAME:agenda_test
X-WR-TIMEZONE:Europe/Paris
BEGIN:VEVENT
CREATED:20091006T181725Z
LAST-MODIFIED:20101018T122624Z
DTSTAMP:20101018T122624Z
UID:KOrganizer-1543547939.852
SUMMARY:Jane Miles - Friday Talk Without Description Text
ORGANIZER;CN=Orga nizer:mailto:organizer@example.com
RRULE:FREQ=WEEKLY;BYDAY=FR
DTSTART:20091016T090000Z
DTEND:20091016T110000Z
TRANSP:OPAQUE
LOCATION:Room 42
SEQUENCE:1
X-MOZ-GENERATION:1
END:VEVENT
BEGIN:VEVENT
CREATED:20091006T181635Z
LAST-MODIFIED:20101018T122534Z
DTSTAMP:20101018T122534Z
UID:KOrganizer-546062779.549
SUMMARY:John Doe - Title of his Monday Talk
ORGANIZER;CN=Orga nizer:mailto:organizer@example.com
RRULE:FREQ=WEEKLY;BYDAY=MO
DTSTART:20091005T090000Z
DTEND:20091005T110000Z
SEQUENCE:1
DESCRIPTION:This is an example event. The speaker \"John Doe\" gives a tal
k with title \"Title of his Talk\" every week on Monday.\n\nIn agenda view
\, PHPicalendar splits the string \"John Doe - Title of his Talk\" into th
e name and the title. The text written here provides more information abou
t the talk and is contained in the event description.
TRANSP:OPAQUE
X-MOZ-SEND-INVITATIONS:TRUE
X-MOZ-GENERATION:2
END:VEVENT
END:VCALENDAR
2 changes: 1 addition & 1 deletion config.inc.php
Expand Up @@ -51,7 +51,7 @@
# 'language' => 'Spanish',
# 'default_cal' => 'US Holidays', // Exact filename of calendar without .ics.
# 'template' => 'green', // Template support: change this to have a different "skin" for your installation.
# 'default_view' => 'year', // Default view for calendars' => 'day', 'week', 'month', 'year'
# 'default_view' => 'year', // Default view for calendars' => 'day', 'week', 'month', 'year', 'agenda'
# 'printview_default' => 'yes', // Set print view as the default view. Uses'default_view (listed above).
# 'gridLength' => 10, // Grid size in day and week views. Allowed values are 1,2,3,4,10,12,15,20,30,60. Default is 15
# 'minical_view' => 'current', // Where do the mini-calendars go when clicked?' => 'day', 'week', 'month', 'current'
Expand Down
2 changes: 1 addition & 1 deletion default_config.php
Expand Up @@ -11,7 +11,7 @@ private function __construct(){
// Define some magic strings.
$this->ALL_CALENDARS_COMBINED = 'all_calendars_combined971';
$this->template = 'default'; // Template support
$this->default_view = 'day'; // Default view for calendars = 'day', 'week', 'month', 'year'
$this->default_view = 'day'; // Default view for calendars = 'day', 'week', 'month', 'year', 'agenda'
$this->minical_view = 'current'; // Where do the mini-calendars go when clicked? = 'day', 'week', 'month', 'current'
$this->default_cal = $this->ALL_CALENDARS_COMBINED; // Exact filename of calendar without .ics. Or set to $this->ALL_CALENDARS_COMBINED to open all calenders combined into one.
$this->language = 'English'; // Language support - 'English', 'Polish', 'German', 'French', 'Dutch', 'Danish', 'Italian', 'Japanese', 'Norwegian', 'Spanish', 'Swedish', 'Portuguese', 'Catalan', 'Traditional_Chinese', 'Esperanto', 'Korean'
Expand Down
57 changes: 29 additions & 28 deletions functions/date_functions.php
Expand Up @@ -133,7 +133,7 @@ function dateOfWeek($Ymd, $day) {
return $ret;
}

// function to compare to dates in Ymd and return the number of weeks
// function to compare to dates in Ymd and return the number of weeks
// that differ between them. requires dateOfWeek()
function weekCompare($now, $then) {
global $week_start_day;
Expand All @@ -145,7 +145,7 @@ function weekCompare($now, $then) {
return $diff_weeks;
}

// function to compare to dates in Ymd and return the number of days
// function to compare to dates in Ymd and return the number of days
// that differ between them.
function dayCompare($now, $then) {
$seconds_now = strtotime($now);
Expand All @@ -154,11 +154,11 @@ function dayCompare($now, $then) {
$diff_minutes = $diff_seconds/60;
$diff_hours = $diff_minutes/60;
$diff_days = round($diff_hours/24);

return $diff_days;
}

// function to compare to dates in Ymd and return the number of months
// function to compare to dates in Ymd and return the number of months
// that differ between them.
function monthCompare($now, $then) {
ereg ("([0-9]{4})([0-9]{2})([0-9]{2})", $now, $date_now);
Expand Down Expand Up @@ -194,21 +194,22 @@ function localizeDate($format, $timestamp) {
$year = date("Y", $timestamp);
$month = date("n", $timestamp)-1;
$day = date("j", $timestamp);
$dayofweek = date("w", $timestamp);
$dayofweek = date("w", $timestamp);
$weeknumber = date("W", $timestamp);
$replacements = array(
'%Y' => $year,
'%e' => $day,
'%B' => $monthsofyear_lang[$month],
'%b' => $monthsofyearshort_lang[$month],
'%A' => $daysofweek_lang[$dayofweek],
'%a' => $daysofweekshort_lang[$dayofweek],
'%W' => $weeknumber,
'%d' => sprintf("%02d", $day)
);
$date = str_replace(array_keys($replacements), array_values($replacements), $format);
return $date;

$replacements = array(
'%Y' => $year,
'%e' => $day,
'%B' => $monthsofyear_lang[$month],
'%b' => $monthsofyearshort_lang[$month],
'%A' => $daysofweek_lang[$dayofweek],
'%a' => $daysofweekshort_lang[$dayofweek],
'%W' => $weeknumber,
'%d' => sprintf("%02d", $day),
'%m' => sprintf("%02d", $month+1)# $month is from 0 to 11
);
$date = str_replace(array_keys($replacements), array_values($replacements), $format);
return $date;

}
// calcOffset takes an offset (ie, -0500) and returns it in the number of seconds
function calcOffset($offset_str) {
Expand Down Expand Up @@ -290,7 +291,7 @@ function makeTitle($arr, $time) {
$length is the length of one line
$link_class is a css class
$pre_text and $post_text are to add tags around the link text (e.g. <b> or<i>)
$title is the tooltip for the link
*/
function openevent($event_date, $time, $uid, $arr, $lines = 0, $length = 0, $link_class = '', $pre_text = '', $post_text = '') {
Expand All @@ -313,7 +314,7 @@ function openevent($event_date, $time, $uid, $arr, $lines = 0, $length = 0, $lin
$full_event_text = $event_text;
$event_text = strip_tags($event_text, '<b><i><u><img>');
}

if (!empty($link_class)) $link_class = ' class="'.$link_class.'"';

if (!empty($event_text)) {
Expand Down Expand Up @@ -352,8 +353,8 @@ function openevent($event_date, $time, $uid, $arr, $lines = 0, $length = 0, $lin
$data = A string representing a date-time per RFC2445.
$property = The property being examined, e.g. DTSTART, DTEND.
$field = The full field being examined, e.g. DTSTART;TZID=US/Pacific
See:http://phpicalendar.org/documentation/index.php/Property_Value_Data_Types#4.3.5___Date-Time
See:http://phpicalendar.org/documentation/index.php/Property_Value_Data_Types#4.3.5___Date-Time
*/
function extractDateTime($data, $property, $field) {
global $tz_array, $phpiCal_config, $calendar_tz;
Expand All @@ -368,14 +369,14 @@ function extractDateTime($data, $property, $field) {
} elseif ($zulu_time) {
$tz_dt = 'GMT';
}

// Extract date-only values.
if ((preg_match('/^'.$property.';VALUE=DATE:/i', $field)) || (ereg ('^([0-9]{4})([0-9]{2})([0-9]{2})$', $data))) {
// Pull out the date value. Minimum year is 1970.
ereg ('([0-9]{4})([0-9]{2})([0-9]{2})', $data, $dt_check);
if ($dt_check[1] < 1970) {
if ($dt_check[1] < 1970) {
$dt_check[1] = '1970';
}
}
# convert to date-time
$data = $dt_check[1].$dt_check[2].$dt_check[3]."T000000";
$time = '';
Expand All @@ -385,7 +386,7 @@ function extractDateTime($data, $property, $field) {
// Pull out the date and time values. Minimum year is 1970.
preg_match ('/([0-9]{4})([0-9]{2})([0-9]{2})T{0,1}([0-9]{0,2})([0-9]{0,2})/', $data, $regs);
if (!isset ($regs[1])) return;
if ($regs[1] < 1970) {
if ($regs[1] < 1970) {
$regs[1] = '1970';
}
$date = $regs[1] . $regs[2] . $regs[3];
Expand All @@ -407,7 +408,7 @@ function extractDateTime($data, $property, $field) {
#echo "offset_tmp $offset_tmp, server_offset_tmp $server_offset_tmp, $unixtime =".date("Ymd His",$unixtime)." $time<br>";
$date = date('Ymd', $unixtime);
if ($allday == '') $time = date('Hi', $unixtime);

// Return the results.
return array($unixtime, $date, $time, $allday, $tz_dt);
}
Expand All @@ -425,4 +426,4 @@ function match_tz($data){
if (strpos(" $data",$key) > 0) return $key;
}
return $data;
}?>
}?>
10 changes: 8 additions & 2 deletions functions/ical_parser.php
Expand Up @@ -416,6 +416,11 @@
$master_array['calendar_name'] = $actual_calname;
$cal_displaynames[$cal_key] = $actual_calname; #correct the default calname based on filename
break;
case 'X-WR-CALDESC':
$actual_caldesc = $data;
$master_array['calendar_desc'] = $actual_caldesc;
$cal_displaydescs[$cal_key] = $actual_caldesc; #correct the default caldesc based on filename
break;
case 'X-WR-TIMEZONE':
$calendar_tz = $data;
$master_array['calendar_tz'] = $calendar_tz;
Expand Down Expand Up @@ -513,7 +518,7 @@
// sort the sub (day) arrays so the times are in order
foreach (array_keys($master_array) as $k) {
if (isset($master_array[$k]) && is_array($master_array[$k])) {
ksort($master_array[$k]);
krsort($master_array[$k]);
reset($master_array[$k]);
}
}
Expand Down Expand Up @@ -542,6 +547,7 @@
}
*/
$cal_displayname = urldecode(implode(', ', $cal_displaynames)); #reset this with the correct names
$cal_displaydesc = urldecode(implode(', ', $cal_displaydescs)); #reset this with the correct descs
$template_started = getmicrotime();


Expand All @@ -559,4 +565,4 @@
//print_r($cal_filelist);
//print_r($tz_array);
#print '</pre>';
?>
?>

0 comments on commit 28ff9e3

Please sign in to comment.