File: upcoming.php

package info (click to toggle)
webcalendar 0.9.45-4sarge7
  • links: PTS
  • area: main
  • in suites: sarge
  • size: 2,888 kB
  • ctags: 4,775
  • sloc: php: 16,990; sql: 1,272; perl: 777; sh: 120; makefile: 45
file content (221 lines) | stat: -rw-r--r-- 6,245 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
<?php
/*
 * $Id: upcoming.php,v 1.9 2004/11/14 17:01:15 cknudsen Exp $
 *
 * Description:
 *	This script is intended to be used outside of normal WebCalendar
 *	use, typically as an iframe in another page.
 *
 *	You must have public access enabled in System Settings to use this
 *	page (unless you modify the $public_must_be_enabled setting below
 *	in this file).
 *
 *	Typically, this is how you would reference this page from another:
 *
 *	<iframe height="250" width="300"
 *	 scrolling="yes" src="upcoming.php"></iframe>
 *
 *	By default (if you do not edit this file), events for the public
 *	calendar will be loaded for either:
 *	  - the next 30 days
 *	  - the next 10 events
 *
 * Input parameters:
 *	You can override settings by changing the URL parameters:
 *	  - days: number of days ahead to look for events
 *	  - cat_id: specify a category id to filter on
 *	  - user: login name of calendar to display (instead of public
 *	    user), if allowed by System Settings.  You must have the
 *	    following System Settings configured for this:
 *	      Allow viewing other user's calendars: Yes
 *	      Public access can view others: Yes
 *
 * Security:
 *	TBD
 */

include "includes/config.php";
include "includes/php-dbi.php";
include "includes/functions.php";
include "includes/$user_inc";
include "includes/connect.php";

load_global_settings ();

include "includes/translate.php";


/********************************************************************
 *
 * Configurable settings for this file.  You may change the settings
 * below to change the default settings.
 * This settings will likely move into the System Settings in the
 * web admin interface in a future release.
 *
 *******************************************************************/

// Change this to false if you still want to access this page even
// though you do not have public access enabled.
$public_must_be_enabled = true;

// Do we include a link to view the event?  If so, what target
// should we use.
$display_link = true;
$link_target = '_top';


// Default time window of events to load
// Can override with "upcoming.php?num=60"
$numDays = 30;

// Max number of events to display
$maxEvents = 10;

// Login of calendar user to use
// '__public__' is the login name for the public user
$username = '__public__';

// Allow the URL to override the user setting such as
// "upcoming.php?user=craig"
$allow_user_override = false;

// Load layers
$load_layers = true;

// Load just a specified category (by its id)
// Leave blank to not filter on category (unless specified in URL)
// Can override in URL with "upcoming.php?cat_id=4"
$cat_id = '';

// End configurable settings...

// Set for use elsewhere as a global
$login = $username;
load_user_preferences ();


if ( $public_must_be_enabled && $public_access != 'Y' ) {
  etranslate ( "You are not authorized" ) . ".";
  print "</body>\n</html>";
  exit;
}

if ( $allow_user_override ) {
  $u = getValue ( "user", "[A-Za-z0-9_\.=@,\-]+", true );
  if ( ! empty ( $u ) ) {
    $username = $u;
    $login = $u;
    // We also set $login since some functions assume that it is set.
  }
}

$cat_id = '';
if ( $categories_enabled == 'Y' ) {
  $x = getIntValue ( "cat_id", true );
  if ( ! empty ( $x ) )
    $cat_id = $x;
}

if ( $load_layers ) {
  load_user_layers ( $username );
}

//load_user_categories ();

// Calculate date range
$date = getIntValue ( "date", true );
if ( empty ( $date ) || strlen ( $date ) != 8 ) {
  // If no date specified, start with today
  $date = date ( "Ymd" );
}
$thisyear = substr ( $date, 0, 4 );
$thismonth = substr ( $date, 4, 2 );
$thisday = substr ( $date, 6, 2 );

$startTime = mktime ( 3, 0, 0, $thismonth, $thisday, $thisyear );

$x = getIntValue ( "days", true );
if ( ! empty ( $x ) )
  $numDays = $x;
// Don't let a malicious user specify more than 365 days
if ( $numDays > 365 )
  $numDays = 365;

$endTime = mktime ( 3, 0, 0, $thismonth, $thisday + $numDays,
  $thisyear );
$endDate = date ( "Ymd", $endTime );


/* Pre-Load the repeated events for quckier access */
$repeated_events = read_repeated_events ( $username, $cat_id, $date );

/* Pre-load the non-repeating events for quicker access */
$events = read_events ( $username, $date, $endDate, $cat_id );

// Print header without custom header and no style sheet
?><html>
<head>
<title>Upcoming Events</title>
</head>
<body>
<?php
print "<dl>\n";

print "<!-- \nstartTime: $startTime\nendTime: $endTime\nstartDate: $date\nnumDays: $numDays\nuser: $username\nevents: " . 
	count ( $events ) . "\nrevents: " . 
	count ( $revents ) . " -->\n";

$numEvents = 0;
for ( $i = $startTime; date ( "Ymd", $i ) <= date ( "Ymd", $endTime ) &&
  $numEvents < $maxEvents; $i += ( 24 * 3600 ) ) {
  $d = date ( "Ymd", $i );
  $entries = get_entries ( $username, $d );
  $rentries = get_repeating_entries ( $username, $d );
  print "<!-- $d " . count ( $entries ) . "/" . count ( $rentries ) . " -->\n";

  if ( count ( $entries ) > 0 || count ( $rentries ) > 0 ) {
    print "<!-- XXX -->\n";
    print "<dt>" . date_to_str ( $d ) . "</dt>\n<dd>";
    for ( $j = 0; $j < count ( $entries ) && $numEvents < $maxEvents; $j++ ) {
      print_upcoming_event ( $entries[$j] );
      $numEvents++;
    }
    for ( $j = 0; $j < count ( $rentries ) && $numEvents < $maxEvents; $j++ ) {
      print_upcoming_event ( $rentries[$j] );
      $numEvents++;
    }
    print "</dd>\n";
  }
}

print "</dl>\n";

print "</body>\n</html>";


// Print the details of an upcoming event
function print_upcoming_event ( $e ) {
  global $display_link, $link_target, $server_url;

  if ( $display_link && ! empty ( $server_url ) ) {
    print "<a title\"" . 
    	htmlentities ( $e['cal_name'] ) . "\" href=\"" . 
	$server_url . "view_entry.php?id=" . 
	$e['cal_id'] . "&amp;date=" . 
	$e['cal_date'] . "\"";
    if ( ! empty ( $link_target ) )
	print " target=\"$link_target\"";
    print ">";
  }
  print htmlentities ( $e['cal_name'] );
  if ( $display_link && ! empty ( $server_url ) ) {
    print "</a>";
  }
  if ( $e['cal_duration'] == 24 * 60 ) {
    print " (" . translate("All day event") . ")\n";
  } else if ( $e['cal_time'] != -1 ) {
    print " (" . display_time ( $e['cal_time'] ) . ")\n";
  }
  print "<br />\n";
}
?>