[ Index ] |
|
Code source de WebCalendar 1.0.5 |
1 <?php 2 /** 3 * Does various initialization tasks and includes all needed files. 4 * 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. 8 * 9 * <b>Comments:</b> 10 * The following scripts do not use this file: 11 * - login.php 12 * - week_ssi.php 13 * - upcoming.php 14 * - tools/send_reminders.php 15 * 16 * How to use: 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 20 * 21 * What gets called: 22 * 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'; 33 * 34 * Also, for month.php, day.php, week.php, week_details.php: 35 * - {@link send_no_cache_header()}; 36 * 37 * @version $Id: init.php,v 1.53.2.1 2005/07/14 23:00:37 cknudsen Exp $ 38 * @package WebCalendar 39 * 40 */ 41 42 // Security Check 43 if ( empty ( $PHP_SELF ) && ! empty ( $_SERVER ) && 44 ! empty ( $_SERVER['PHP_SELF'] ) ) { 45 $PHP_SELF = $_SERVER['PHP_SELF']; 46 } 47 if ( ! empty ( $PHP_SELF ) && preg_match ( "/\/includes\//", $PHP_SELF ) ) { 48 die ( "You can't access this file directly!" ); 49 } 50 51 // Make sure another app in the same domain doesn't have a 'user' cookie 52 if ( empty ( $HTTP_GET_VARS ) ) $HTTP_GET_VARS = $_GET; 53 if ( empty ( $HTTP_POST_VARS ) ) $HTTP_POST_VARS = $_POST; 54 if ( ( ! empty ( $HTTP_GET_VARS ) && empty ( $HTTP_GET_VARS['user'] ) ) && 55 ( ! empty ( $HTTP_POST_VARS ) && empty ( $HTTP_POST_VARS['user'] ) ) && 56 isset ( $GLOBALS['user'] ) ) { 57 unset ( $GLOBALS['user'] ); 58 } 59 60 // Get script name 61 $self = $_SERVER['PHP_SELF']; 62 if ( empty ( $self ) ) 63 $self = $PHP_SELF; 64 preg_match ( "/\/(\w+\.php)/", $self, $match); 65 $SCRIPT = $match[1]; 66 67 // Several files need a no-cache header and some of the same code 68 $special = array('month.php', 'day.php', 'week.php', 'week_details.php', 'year.php'); 69 $DMW = in_array($SCRIPT, $special); 70 71 // Unset some variables that shouldn't be set 72 unset($user_inc); 73 74 include_once 'includes/config.php'; 75 include_once 'includes/php-dbi.php'; 76 include_once 'includes/functions.php'; 77 include_once "includes/$user_inc"; 78 include_once 'includes/validate.php'; 79 include_once 'includes/connect.php'; 80 81 load_global_settings (); 82 83 if ( empty ( $ovrd ) ) 84 load_user_preferences (); 85 86 include_once 'includes/translate.php'; 87 88 // error-check some commonly used form variable names 89 $id = getValue ( "id", "[0-9]+", true ); 90 $user = getValue ( "user", "[A-Za-z0-9_\.=@,\-]*", true ); 91 $date = getValue ( "date", "[0-9]+" ); 92 $year = getValue ( "year", "[0-9]+" ); 93 $month = getValue ( "month", "[0-9]+" ); 94 $hour = getValue ( "hour", "[0-9]+" ); 95 $minute = getValue ( "minute", "[0-9]+" ); 96 $cat_id = getValue ( "cat_id", "[0-9]+" ); 97 $friendly = getValue ( "friendly", "[01]" ); 98 if ( empty ( $public_access ) ) 99 $public_access = 'N'; 100 101 // Load if $SCRIPT is in $special array: 102 if ($DMW) { 103 104 // Tell the browser not to cache 105 send_no_cache_header (); 106 107 if ( $allow_view_other != 'Y' && ! $is_admin ) 108 $user = ""; 109 110 $can_add = ( $readonly == "N" || $is_admin == "Y" ); 111 if ( $public_access == "Y" && $login == "__public__" ) { 112 if ( $public_access_can_add != "Y" ) 113 $can_add = false; 114 if ( $public_access_others != "Y" ) 115 $user = ""; // security precaution 116 } 117 118 if ( $groups_enabled == "Y" && $user_sees_only_his_groups == "Y" && 119 ! $is_admin ) { 120 $valid_user = false; 121 $userlist = get_my_users(); 122 if ($nonuser_enabled == "Y" ) { 123 $nonusers = get_nonuser_cals (); 124 $userlist = array_merge($nonusers, $userlist); 125 } 126 for ( $i = 0; $i < count ( $userlist ); $i++ ) { 127 if ( $user == $userlist[$i]['cal_login'] ) $valid_user = true; 128 } 129 if ($valid_user == false) { 130 $user = ""; // security precaution 131 } 132 } 133 134 if ( ! empty ( $user ) ) { 135 $u_url = "user=$user&"; 136 user_load_variables ( $user, "user_" ); 137 if ( $user == "__public__" ) 138 $user_fullname = translate ( $PUBLIC_ACCESS_FULLNAME ); 139 } else { 140 $u_url = ""; 141 $user_fullname = $fullname; 142 if ( $login == "__public__" ) 143 $user_fullname = translate ( $PUBLIC_ACCESS_FULLNAME ); 144 } 145 146 set_today($date); 147 148 if ( $categories_enabled == "Y" ) { 149 if ( ! empty ( $cat_id ) ) { 150 $cat_id = $cat_id; 151 } elseif ( ! empty ( $CATEGORY_VIEW ) ) { 152 $cat_id = $CATEGORY_VIEW; 153 } else { 154 $cat_id = ''; 155 } 156 } else { 157 $cat_id = ''; 158 } 159 if ( empty ( $cat_id ) ) 160 $caturl = ""; 161 else 162 $caturl = "&cat_id=$cat_id"; 163 } 164 165 /** Maps page filenames to the id that page's <body> tag will have 166 * 167 * @global array $bodyid 168 */ 169 $bodyid = array( 170 "activity_log.php" => "activitylog", 171 "add_entry.php" => "addentry", 172 "admin.php" => "admin", 173 "adminhome.php" => "adminhome", 174 "approve_entry.php" => "approveentry", 175 "assistant_edit.php" => "assistantedit", 176 "category.php" => "category", 177 "day.php" => "day", 178 "del_entry.php" => "delentry", 179 "del_layer.php" => "dellayer", 180 "edit_entry.php" => "editentry", 181 "edit_layer.php" => "editlayer", 182 "edit_nonusers.php" => "editnonusers", 183 "edit_nonusers_handler.php" => "editnonusershandler", 184 "edit_report.php" => "editreport", 185 "edit_template.php" => "edittemplate", 186 "edit_user.php" => "edituser", 187 "edit_user_handler.php" => "edituserhandler", 188 "export.php" => "export", 189 "group_edit.php" => "groupedit", 190 "group_edit_handler.php" => "groupedithandler", 191 "groups.php" => "groups", 192 "help_admin.php" => "helpadmin", 193 "help_bug.php" => "helpbug", 194 "help_edit_entry.php" => "helpeditentry", 195 "help_import.php" => "helpimport", 196 "help_index.php" => "helpindex", 197 "help_layers.php" => "helplayers", 198 "help_pref.php" => "helppref", 199 "import.php" => "import", 200 "index.php" => "index", 201 "layers.php" => "layers", 202 "layers_toggle.php" => "layerstoggle", 203 "list_unapproved.php" => "listunapproved", 204 "login.php" => "login", 205 "month.php" => "month", 206 "nonusers.php" => "nonusers", 207 "pref.php" => "pref", 208 "publish.php" => "publish", 209 "purge.php" => "purge", 210 "reject_entry.php" => "rejectentry", 211 "report.php" => "report", 212 "search.php" => "search", 213 "select_user.php" => "selectuser", 214 "set_entry_cat.php" => "setentrycat", 215 "users.php" => "users", 216 "usersel.php" => "usersel", 217 "view_d.php" => "viewd", 218 "view_entry.php" => "viewentry", 219 "view_l.php" => "viewl", 220 "view_m.php" => "viewm", 221 "view_t.php" => "viewt", 222 "view_v.php" => "viewv", 223 "view_w.php" => "vieww", 224 "views.php" => "views", 225 "views_edit.php" => "viewsedit", 226 "week.php" => "week", 227 "week_details.php" => "weekdetails", 228 "week_ssi.php" => "weekssi", 229 "year.php" => "year" 230 ); 231 232 /** 233 * Prints the HTML header and opening HTML body tag. 234 * 235 * @param array $includes Array of additional files to include referenced 236 * from the includes directory 237 * @param string $HeadX Data to be printed inside the head tag (meta, 238 * script, etc) 239 * @param string $BodyX Data to be printed inside the Body tag (onload 240 * for example) 241 * @param bool $disbleCustom Do not include custom header? (useful for small 242 * popup windows, such as color selection) 243 * @param bool $disableStyle Do not include the standard css? 244 */ 245 function print_header($includes = '', $HeadX = '', $BodyX = '', 246 $disableCustom=false, $disableStyle=false) { 247 global $application_name; 248 global $FONTS,$WEEKENDBG,$THFG,$THBG,$PHP_SELF; 249 global $TABLECELLFG,$TODAYCELLBG,$TEXTCOLOR; 250 global $POPUP_FG,$BGCOLOR; 251 global $LANGUAGE; 252 global $CUSTOM_HEADER, $CUSTOM_SCRIPT; 253 global $friendly; 254 global $bodyid, $self; 255 $lang = ''; 256 if ( ! empty ( $LANGUAGE ) ) 257 $lang = languageToAbbrev ( $LANGUAGE ); 258 if ( empty ( $lang ) ) 259 $lang = 'en'; 260 261 // Start the header & specify the charset 262 // The charset is defined in the translation file 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" . 271 "<head>\n" . 272 "<meta http-equiv=\"Content-Type\" content=\"text/html; " . 273 "charset=$charset\" />\n"; 274 echo "<title>".translate($application_name)."</title>\n"; 275 } else { 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" . 281 "<head>\n" . 282 "<title>".translate($application_name)."</title>\n"; 283 } 284 } 285 286 // Any other includes? 287 if ( is_array ( $includes ) ) { 288 foreach( $includes as $inc ){ 289 include_once 'includes/'.$inc; 290 } 291 } 292 293 // Do we need anything else inside the header tag? 294 if ($HeadX) echo $HeadX."\n"; 295 296 // Include the styles 297 if ( ! $disableStyle ) { 298 include_once 'includes/styles.php'; 299 } 300 301 // Add custom script/stylesheet if enabled 302 if ( $CUSTOM_SCRIPT == 'Y' && ! $disableCustom ) { 303 $res = dbi_query ( 304 "SELECT cal_template_text FROM webcal_report_template " . 305 "WHERE cal_template_type = 'S' and cal_report_id = 0" ); 306 if ( $res ) { 307 if ( $row = dbi_fetch_row ( $res ) ) { 308 echo $row[0]; 309 } 310 dbi_free_result ( $res ); 311 } 312 } 313 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"; 320 321 // Link to favicon 322 echo "<link rel=\"shortcut icon\" href=\"favicon.ico\" type=\"image/x-icon\" />\n"; 323 324 // Finish the header 325 echo "</head>\n<body"; 326 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] . "\""; 331 332 // Add any extra parts to the <body> tag 333 if ( ! empty( $BodyX ) ) 334 echo " $BodyX"; 335 echo ">\n"; 336 337 // Add custom header if enabled 338 if ( $CUSTOM_HEADER == 'Y' && ! $disableCustom ) { 339 $res = dbi_query ( 340 "SELECT cal_template_text FROM webcal_report_template " . 341 "WHERE cal_template_type = 'H' and cal_report_id = 0" ); 342 if ( $res ) { 343 if ( $row = dbi_fetch_row ( $res ) ) { 344 echo $row[0]; 345 } 346 dbi_free_result ( $res ); 347 } 348 } 349 } 350 351 352 /** 353 * Prints the common trailer. 354 * 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.) 361 */ 362 function print_trailer ( $include_nav_links=true, $closeDb=true, 363 $disableCustom=false ) 364 { 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; 373 374 if ( $include_nav_links ) { 375 include_once "includes/trailer.php"; 376 } 377 378 // Add custom trailer if enabled 379 if ( $CUSTOM_TRAILER == 'Y' && ! $disableCustom && isset ( $c ) ) { 380 $res = dbi_query ( 381 "SELECT cal_template_text FROM webcal_report_template " . 382 "WHERE cal_template_type = 'T' and cal_report_id = 0" ); 383 if ( $res ) { 384 if ( $row = dbi_fetch_row ( $res ) ) { 385 echo $row[0]; 386 } 387 dbi_free_result ( $res ); 388 } 389 } 390 391 if ( $closeDb ) { 392 if ( isset ( $c ) ) 393 dbi_close ( $c ); 394 unset ( $c ); 395 } 396 } 397 ?>
titre
Description
Corps
titre
Description
Corps
titre
Description
Corps
titre
Corps
Généré le : Fri Nov 30 19:09:19 2007 | par Balluche grâce à PHPXref 0.7 |
![]() |