3 * Does various initialization tasks and includes all needed files.
5 * This page is included by most WebCalendar pages as the only include file.
6 * This greatly simplifies the other PHP pages since they don't need to worry
7 * about what files it includes.
10 * The following scripts do not use this file:
14 * - tools/send_reminders.php
17 * 1. call include_once 'includes/init.php'; at the top of your script.
18 * 2. call any other functions or includes not in this file that you need
19 * 3. call the print_header function with proper arguments
23 * - include_once 'includes/config.php';
24 * - include_once 'includes/php-dbi.php';
25 * - include_once 'includes/functions.php';
26 * - include_once "includes/$user_inc";
27 * - include_once 'includes/validate.php';
28 * - include_once 'includes/connect.php';
29 * - {@link load_global_settings()};
30 * - {@link load_user_preferences()};
31 * - include_once 'includes/translate.php';
32 * - include_once 'includes/styles.php';
34 * Also, for month.php, day.php, week.php, week_details.php:
35 * - {@link send_no_cache_header()};
37 * @package WebCalendar
42 if ( empty ( $PHP_SELF ) && ! empty ( $_SERVER ) &&
43 ! empty ( $_SERVER['PHP_SELF'] ) ) {
44 $PHP_SELF = $_SERVER['PHP_SELF'];
46 if ( ! empty ( $PHP_SELF ) && preg_match ( "/\/includes\//", $PHP_SELF ) ) {
47 die ( "You can't access this file directly!" );
50 // Make sure another app in the same domain doesn't have a 'user' cookie
51 if ( empty ( $HTTP_GET_VARS ) ) $HTTP_GET_VARS = $_GET;
52 if ( empty ( $HTTP_POST_VARS ) ) $HTTP_POST_VARS = $_POST;
53 if ( ( ! empty ( $HTTP_GET_VARS ) && empty ( $HTTP_GET_VARS['user'] ) ) &&
54 ( ! empty ( $HTTP_POST_VARS ) && empty ( $HTTP_POST_VARS['user'] ) ) &&
55 isset ( $GLOBALS['user'] ) ) {
56 unset ( $GLOBALS['user'] );
60 $self = $_SERVER['PHP_SELF'];
61 if ( empty ( $self ) )
63 preg_match ( "/\/(\w+\.php)/", $self, $match);
66 // Several files need a no-cache header and some of the same code
67 $special = array('month.php', 'day.php', 'week.php', 'week_details.php', 'year.php');
68 $DMW = in_array($SCRIPT, $special);
70 // Unset some variables that shouldn't be set
73 include_once 'includes/config.php';
74 include_once 'includes/php-dbi.php';
75 include_once 'includes/functions.php';
76 include_once "includes/$user_inc";
77 include_once 'includes/validate.php';
78 include_once 'includes/connect.php';
80 load_global_settings ();
82 if ( empty ( $ovrd ) )
83 load_user_preferences ();
85 include_once 'includes/translate.php';
87 // error-check some commonly used form variable names
88 $id = getValue ( "id", "[0-9]+", true );
89 $user = getValue ( "user", "[A-Za-z0-9_\.=@,\-]*", true );
90 $date = getValue ( "date", "[0-9]+" );
91 $year = getValue ( "year", "[0-9]+" );
92 $month = getValue ( "month", "[0-9]+" );
93 $hour = getValue ( "hour", "[0-9]+" );
94 $minute = getValue ( "minute", "[0-9]+" );
95 $cat_id = getValue ( "cat_id", "[0-9]+" );
96 $friendly = getValue ( "friendly", "[01]" );
97 if ( empty ( $public_access ) )
100 // Load if $SCRIPT is in $special array:
103 // Tell the browser not to cache
104 send_no_cache_header ();
106 if ( $allow_view_other != 'Y' && ! $is_admin )
109 $can_add = ( $readonly == "N" || $is_admin == "Y" );
110 if ( $public_access == "Y" && $login == "__public__" ) {
111 if ( $public_access_can_add != "Y" )
113 if ( $public_access_others != "Y" )
114 $user = ""; // security precaution
117 if ( $groups_enabled == "Y" && $user_sees_only_his_groups == "Y" &&
120 $userlist = get_my_users();
121 if ($nonuser_enabled == "Y" ) {
122 $nonusers = get_nonuser_cals ();
123 $userlist = array_merge($nonusers, $userlist);
125 for ( $i = 0; $i < count ( $userlist ); $i++ ) {
126 if ( $user == $userlist[$i]['cal_login'] ) $valid_user = true;
128 if ($valid_user == false) {
129 $user = ""; // security precaution
133 if ( ! empty ( $user ) ) {
134 $u_url = "user=$user&";
135 user_load_variables ( $user, "user_" );
136 if ( $user == "__public__" )
137 $user_fullname = translate ( $PUBLIC_ACCESS_FULLNAME );
140 $user_fullname = $fullname;
141 if ( $login == "__public__" )
142 $user_fullname = translate ( $PUBLIC_ACCESS_FULLNAME );
147 if ( $categories_enabled == "Y" ) {
148 if ( ! empty ( $cat_id ) ) {
150 } elseif ( ! empty ( $CATEGORY_VIEW ) ) {
151 $cat_id = $CATEGORY_VIEW;
158 if ( empty ( $cat_id ) )
161 $caturl = "&cat_id=$cat_id";
164 /** Maps page filenames to the id that page's <body> tag will have
166 * @global array $bodyid
169 "activity_log.php" => "activitylog",
170 "add_entry.php" => "addentry",
171 "admin.php" => "admin",
172 "adminhome.php" => "adminhome",
173 "approve_entry.php" => "approveentry",
174 "assistant_edit.php" => "assistantedit",
175 "category.php" => "category",
177 "del_entry.php" => "delentry",
178 "del_layer.php" => "dellayer",
179 "edit_entry.php" => "editentry",
180 "edit_layer.php" => "editlayer",
181 "edit_nonusers.php" => "editnonusers",
182 "edit_nonusers_handler.php" => "editnonusershandler",
183 "edit_report.php" => "editreport",
184 "edit_template.php" => "edittemplate",
185 "edit_user.php" => "edituser",
186 "edit_user_handler.php" => "edituserhandler",
187 "export.php" => "export",
188 "group_edit.php" => "groupedit",
189 "group_edit_handler.php" => "groupedithandler",
190 "groups.php" => "groups",
191 "help_admin.php" => "helpadmin",
192 "help_bug.php" => "helpbug",
193 "help_edit_entry.php" => "helpeditentry",
194 "help_import.php" => "helpimport",
195 "help_index.php" => "helpindex",
196 "help_layers.php" => "helplayers",
197 "help_pref.php" => "helppref",
198 "import.php" => "import",
199 "index.php" => "index",
200 "layers.php" => "layers",
201 "layers_toggle.php" => "layerstoggle",
202 "list_unapproved.php" => "listunapproved",
203 "login.php" => "login",
204 "month.php" => "month",
205 "nonusers.php" => "nonusers",
206 "pref.php" => "pref",
207 "publish.php" => "publish",
208 "purge.php" => "purge",
209 "reject_entry.php" => "rejectentry",
210 "report.php" => "report",
211 "search.php" => "search",
212 "select_user.php" => "selectuser",
213 "set_entry_cat.php" => "setentrycat",
214 "users.php" => "users",
215 "usersel.php" => "usersel",
216 "view_d.php" => "viewd",
217 "view_entry.php" => "viewentry",
218 "view_l.php" => "viewl",
219 "view_m.php" => "viewm",
220 "view_t.php" => "viewt",
221 "view_v.php" => "viewv",
222 "view_w.php" => "vieww",
223 "views.php" => "views",
224 "views_edit.php" => "viewsedit",
225 "week.php" => "week",
226 "week_details.php" => "weekdetails",
227 "week_ssi.php" => "weekssi",
232 * Prints the HTML header and opening HTML body tag.
234 * @param array $includes Array of additional files to include referenced
235 * from the includes directory
236 * @param string $HeadX Data to be printed inside the head tag (meta,
238 * @param string $BodyX Data to be printed inside the Body tag (onload
240 * @param bool $disbleCustom Do not include custom header? (useful for small
241 * popup windows, such as color selection)
242 * @param bool $disableStyle Do not include the standard css?
244 function print_header($includes = '', $HeadX = '', $BodyX = '',
245 $disableCustom=false, $disableStyle=false) {
246 global $application_name;
247 global $FONTS,$WEEKENDBG,$THFG,$THBG,$PHP_SELF;
248 global $TABLECELLFG,$TODAYCELLBG,$TEXTCOLOR;
249 global $POPUP_FG,$BGCOLOR;
251 global $CUSTOM_HEADER, $CUSTOM_SCRIPT;
253 global $bodyid, $self;
255 if ( ! empty ( $LANGUAGE ) )
256 $lang = languageToAbbrev ( $LANGUAGE );
257 if ( empty ( $lang ) )
260 // Start the header & specify the charset
261 // The charset is defined in the translation file
262 // TODO: set language properly
263 if ( ! empty ( $LANGUAGE ) ) {
264 $charset = translate ( "charset" );
265 if ( $charset != "charset" ) {
266 echo "<?xml version=\"1.0\" encoding=\"$charset\"?>\n" .
267 "<!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.0 Transitional//EN\" " .
268 "\"DTD/xhtml1-transitional.dtd\">\n" .
269 "<html xmlns=\"http://www.w3.org/1999/xhtml\" " .
270 "xml:lang=\"$lang\" lang=\"$lang\">\n" .
272 "<meta http-equiv=\"Content-Type\" content=\"text/html; " .
273 "charset=$charset\" />\n";
274 echo "<title>".translate($application_name)."</title>\n";
276 echo "<?xml version=\"1.0\" encoding=\"iso-8859-1\"?>\n" .
277 "<!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.0 Transitional//EN\" " .
278 "\"DTD/xhtml1-transitional.dtd\">\n" .
279 "<html xmlns=\"http://www.w3.org/1999/xhtml\" " .
280 "xml:lang=\"en\" lang=\"en\">\n" .
282 "<title>".translate($application_name)."</title>\n";
286 // Any other includes?
287 if ( is_array ( $includes ) ) {
288 foreach( $includes as $inc ){
289 include_once 'includes/'.$inc;
293 // Do we need anything else inside the header tag?
294 if ($HeadX) echo $HeadX."\n";
296 // Include the styles
297 if ( ! $disableStyle ) {
298 include_once 'includes/styles.php';
301 // Add custom script/stylesheet if enabled
302 if ( $CUSTOM_SCRIPT == 'Y' && ! $disableCustom ) {
304 "SELECT cal_template_text FROM webcal_report_template " .
305 "WHERE cal_template_type = 'S' and cal_report_id = 0" );
307 if ( $row = dbi_fetch_row ( $res ) ) {
310 dbi_free_result ( $res );
314 // Include includes/print_styles.css as a media="print" stylesheet. When the
315 // user clicks on the "Printer Friendly" link, $friendly will be non-empty,
316 // including this as a normal stylesheet so they can see how it will look
317 // when printed. This maintains backwards-compatibility for browsers that
318 // don't support media="print" stylesheets
319 echo "<link rel=\"stylesheet\" type=\"text/css\"" . ( empty ( $friendly ) ? " media=\"print\"" : "" ) . " href=\"includes/print_styles.css\" />\n";
322 echo "<link rel=\"shortcut icon\" href=\"favicon.ico\" type=\"image/x-icon\" />\n";
325 echo "</head>\n<body";
327 // Find the filename of this page and give the <body> tag the corresponding id
328 $thisPage = substr($self, strrpos($self, '/') + 1);
329 if ( isset( $bodyid[$thisPage] ) )
330 echo " id=\"" . $bodyid[$thisPage] . "\"";
332 // Add any extra parts to the <body> tag
333 if ( ! empty( $BodyX ) )
337 // Add custom header if enabled
338 if ( $CUSTOM_HEADER == 'Y' && ! $disableCustom ) {
340 "SELECT cal_template_text FROM webcal_report_template " .
341 "WHERE cal_template_type = 'H' and cal_report_id = 0" );
343 if ( $row = dbi_fetch_row ( $res ) ) {
346 dbi_free_result ( $res );
353 * Prints the common trailer.
355 * @param bool $include_nav_links Should the standard navigation links be
356 * included in the trailer?
357 * @param bool $closeDb Close the database connection when finished?
358 * @param bool $disableCustom Disable the custom trailer the administrator
359 * has setup? (This is useful for small popup
360 * windows and pages being used in an iframe.)
362 function print_trailer ( $include_nav_links=true, $closeDb=true,
363 $disableCustom=false )
365 global $CUSTOM_TRAILER, $c, $STARTVIEW;
366 global $login, $user, $cat_id, $categories_enabled, $thisyear,
367 $thismonth, $thisday, $DATE_FORMAT_MY, $WEEK_START, $DATE_FORMAT_MD,
368 $readonly, $is_admin, $public_access, $public_access_can_add,
369 $single_user, $use_http_auth, $login_return_path, $require_approvals,
370 $is_nonuser_admin, $public_access_others, $allow_view_other,
371 $views, $reports_enabled, $LAYER_STATUS, $nonuser_enabled,
372 $groups_enabled, $fullname, $has_boss;
374 if ( $include_nav_links ) {
375 include_once "includes/trailer.php";
378 // Add custom trailer if enabled
379 if ( $CUSTOM_TRAILER == 'Y' && ! $disableCustom && isset ( $c ) ) {
381 "SELECT cal_template_text FROM webcal_report_template " .
382 "WHERE cal_template_type = 'T' and cal_report_id = 0" );
384 if ( $row = dbi_fetch_row ( $res ) ) {
387 dbi_free_result ( $res );