4 * This script is intended to be used outside of normal WebCalendar
5 * use, typically as an iframe in another page.
7 * You must have public access enabled in System Settings to use this
8 * page (unless you modify the $public_must_be_enabled setting below
11 * Typically, this is how you would reference this page from another:
13 * <iframe height="250" width="300"
14 * scrolling="yes" src="upcoming.php"></iframe>
16 * By default (if you do not edit this file), events for the public
17 * calendar will be loaded for either:
19 * - the next 10 events
22 * You can override settings by changing the URL parameters:
23 * - days: number of days ahead to look for events
24 * - cat_id: specify a category id to filter on
25 * - user: login name of calendar to display (instead of public
26 * user), if allowed by System Settings. You must have the
27 * following System Settings configured for this:
28 * Allow viewing other user's calendars: Yes
29 * Public access can view others: Yes
35 include "includes/config.php";
36 include "includes/php-dbi.php";
37 include "includes/functions.php";
38 include "includes/$user_inc";
39 include "includes/connect.php";
41 load_global_settings ();
45 * Configurable settings for this file. You may change the settings
46 * below to change the default settings.
47 * This settings will likely move into the System Settings in the
48 * web admin interface in a future release.
52 // Change this to false if you still want to access this page even
53 // though you do not have public access enabled.
54 $public_must_be_enabled = true;
56 // Do we include a link to view the event? If so, what target
59 $link_target = '_top';
62 // Default time window of events to load
63 // Can override with "upcoming.php?days=60"
66 // Max number of events to display
69 // Login of calendar user to use
70 // '__public__' is the login name for the public user
71 $username = '__public__';
73 // Allow the URL to override the user setting such as
74 // "upcoming.php?user=craig"
75 $allow_user_override = false;
80 // Load just a specified category (by its id)
81 // Leave blank to not filter on category (unless specified in URL)
82 // Can override in URL with "upcoming.php?cat_id=4"
85 // End configurable settings...
87 // Set for use elsewhere as a global
89 // Load user preferences for DISPLAY_UNAPPROVED
90 load_user_preferences ();
91 $get_unapproved = ! empty ( $DISPLAY_UNAPPROVED ) && $DISPLAY_UNAPPROVED == 'Y';
93 include "includes/translate.php";
96 if ( $public_must_be_enabled && $public_access != 'Y' ) {
97 $error = translate ( "You are not authorized" ) . ".";
100 if ( $allow_user_override ) {
101 $u = getValue ( "user", "[A-Za-z0-9_\.=@,\-]+", true );
102 if ( ! empty ( $u ) ) {
105 // We also set $login since some functions assume that it is set.
110 if ( $categories_enabled == 'Y' ) {
111 $x = getIntValue ( "cat_id", true );
112 if ( ! empty ( $x ) ) {
117 if ( $load_layers ) {
118 load_user_layers ( $username );
121 //load_user_categories ();
123 // Calculate date range
124 $date = getIntValue ( "date", true );
125 if ( empty ( $date ) || strlen ( $date ) != 8 ) {
126 // If no date specified, start with today
127 $date = date ( "Ymd" );
129 $thisyear = substr ( $date, 0, 4 );
130 $thismonth = substr ( $date, 4, 2 );
131 $thisday = substr ( $date, 6, 2 );
133 $startTime = mktime ( 3, 0, 0, $thismonth, $thisday, $thisyear );
135 $x = getIntValue ( "days", true );
136 if ( ! empty ( $x ) ) {
139 // Don't let a malicious user specify more than 365 days
140 if ( $numDays > 365 ) {
143 $endTime = mktime ( 3, 0, 0, $thismonth, $thisday + $numDays,
145 $endDate = date ( "Ymd", $endTime );
148 /* Pre-Load the repeated events for quckier access */
149 $repeated_events = read_repeated_events ( $username, $cat_id, $date );
151 /* Pre-load the non-repeating events for quicker access */
152 $events = read_events ( $username, $date, $endDate, $cat_id );
154 // Print header without custom header and no style sheet
155 if ( ! empty ( $LANGUAGE ) ) {
156 $charset = translate ( "charset" );
157 $lang = languageToAbbrev ( ( $LANGUAGE == "Browser-defined" ||
158 $LANGUAGE == "none" )? $lang : $LANGUAGE );
159 if ( $charset != "charset" ) {
160 echo "<?xml version=\"1.0\" encoding=\"$charset\"?>\n" .
161 "<!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.0 Transitional//EN\" " .
162 "\"DTD/xhtml1-transitional.dtd\">\n" .
163 "<html xmlns=\"http://www.w3.org/1999/xhtml\" " .
164 "xml:lang=\"$lang\" lang=\"$lang\">\n" .
166 "<meta http-equiv=\"Content-Type\" content=\"text/html; " .
167 "charset=$charset\" />\n";
169 echo "<?xml version=\"1.0\" encoding=\"iso-8859-1\"?>\n" .
170 "<!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.0 Transitional//EN\" " .
171 "\"DTD/xhtml1-transitional.dtd\">\n" .
172 "<html xmlns=\"http://www.w3.org/1999/xhtml\" " .
173 "xml:lang=\"en\" lang=\"en\">\n" .
178 $charset = "iso-8859-1";
180 echo "<title>".translate($application_name)."</title>\n";
186 if ( ! empty ( $error ) ) {
187 echo "<h2>" . translate ( "Error" ) .
189 echo "\n<br /><br />\n</body></html>";
194 print "<!-- \nstartTime: $startTime\nendTime: $endTime\nstartDate: " .
195 "$date\nnumDays: $numDays\nuser: $username\nevents: " .
196 count ( $events ) . "\nrepeated_events: " .
197 count ( $repeated_events ) . " -->\n";
200 for ( $i = $startTime; date ( "Ymd", $i ) <= date ( "Ymd", $endTime ) &&
201 $numEvents < $maxEvents; $i += ( 24 * 3600 ) ) {
202 $d = date ( "Ymd", $i );
203 $entries = get_entries ( $username, $d, $get_unapproved );
204 $rentries = get_repeating_entries ( $username, $d, $get_unapproved );
205 print "<!-- $d " . count ( $entries ) . "/" . count ( $rentries ) . " -->\n";
207 if ( count ( $entries ) > 0 || count ( $rentries ) > 0 ) {
208 print "<!-- XXX -->\n";
209 print "<dt>" . date_to_str ( $d ) . "</dt>\n<dd>";
210 for ( $j = 0; $j < count ( $entries ) && $numEvents < $maxEvents; $j++ ) {
211 print_upcoming_event ( $entries[$j] );
214 for ( $j = 0; $j < count ( $rentries ) && $numEvents < $maxEvents; $j++ ) {
215 print_upcoming_event ( $rentries[$j] );
224 print "</body>\n</html>";
227 // Print the details of an upcoming event
228 function print_upcoming_event ( $e ) {
229 global $display_link, $link_target, $server_url, $charset;
231 if ( $e['cal_access'] == 'P' ) {
232 if ( $display_link && ! empty ( $server_url ) ) {
233 print "<a title=\"" .
234 $e['cal_name'] . "\" href=\"" .
235 $server_url . "view_entry.php?id=" .
236 $e['cal_id'] . "&date=" .
237 $e['cal_date'] . "\"";
238 if ( ! empty ( $link_target ) ) {
239 print " target=\"$link_target\"";
243 print $e['cal_name'];
245 print "[" . translate("Confidential") . "]";
248 if ( $display_link && ! empty ( $server_url ) ) {
251 if ( $e['cal_duration'] == 24 * 60 ) {
252 print " (" . translate("All day event") . ")\n";
253 } else if ( $e['cal_time'] != -1 ) {
254 print " (" . display_time ( $e['cal_time'] ) . ")\n";