3 * This file loads configuration settings from the data file settings.php and
4 * sets up some needed variables.
6 * The settings.php file is created during installation using the web-based db
7 * setup page (install/index.php).
10 * DO NOT EDIT THIS FILE!
12 * (Versions 0.9.44 and older required users to edit this file to configure
13 * WebCalendar. Version 0.9.45 and later requires editing the settings.php
16 * @version $Id: config.php,v 1.53.2.15 2006/06/07 15:27:20 cknudsen Exp $
17 * @package WebCalendar
19 if ( empty ( $PHP_SELF ) && ! empty ( $_SERVER ) &&
20 ! empty ( $_SERVER['PHP_SELF'] ) ) {
21 $PHP_SELF = $_SERVER['PHP_SELF'];
23 if ( ! empty ( $PHP_SELF ) && preg_match ( "/\/includes\//", $PHP_SELF ) ) {
24 die ( "You can't access this file directly!" );
27 // Unset some variables in case the server has register_globals
28 // enabled. This will prevent users from settings these values
30 // http://localhost/calendar/month.php?includedir=http://xxx/bad-guy
31 unset ( $includedir );
33 unset ( $db_database );
35 unset ( $db_password );
36 unset ( $db_persistent );
37 unset ( $single_user_login );
40 unset ( $use_http_auth );
41 unset ( $single_user );
43 unset ( $includedir );
47 $PROGRAM_VERSION = "v1.0.4";
48 $PROGRAM_DATE = "07 Jun 2006";
49 $PROGRAM_NAME = "WebCalendar $PROGRAM_VERSION ($PROGRAM_DATE)";
50 $PROGRAM_URL = "http://webcalendar.sourceforge.net/";
52 $TROUBLE_URL = "docs/WebCalendar-SysAdmin.html#trouble";
55 * Prints a fatal error message to the user along with a link to the
56 * Troubleshooting section of the WebCalendar System Administrator's Guide.
58 * Execution is aborted.
60 * @param string $error The error message to display
62 * @internal We don't normally put functions in this file. But, since this
63 * file is included before some of the others, this function either
64 * goes here or we repeat this code in multiple files.
66 function die_miserable_death ( $error )
69 echo "<html><head><title>WebCalendar: Fatal Error</title></head>\n" .
70 "<body><h2>WebCalendar Error</h2>\n" .
71 "<p>$error</p>\n<hr />" .
72 "<p><a href=\"$TROUBLE_URL\" target=\"_blank\">" .
73 "Troubleshooting Help</a></p></body></html>\n";
79 // Open settings file to read
81 $settings_file = dirname(__FILE__) . "/settings.php";
82 //called from send_reminders.php
83 if ( ! empty ( $includedir ) )
84 $fd = @fopen ( "$includedir/settings.php", "rb", true );
86 $fd = @fopen ( "settings.php", "rb", true );
88 $fd = @fopen ( "includes/settings.php", "rb", true );
89 if ( ! $fd && file_exists ( $settings_file ) )
90 $fd = @fopen ( $settings_file, "rb", true );
91 if ( empty ( $fd ) ) {
92 // There is no settings.php file.
93 // Redirect user to install page if it exists.
94 if ( file_exists ( "install/index.php" ) ) {
95 Header ( "Location: install/index.php" );
98 die_miserable_death ( "Could not find settings.php file.<br />\n" .
99 "Please copy settings.php.orig to settings.php and modify for your " .
104 // We don't use fgets() since it seems to have problems with Mac-formatted
105 // text files. Instead, we read in the entire file, then split the lines
108 while ( ! feof ( $fd ) ) {
109 $data .= fgets ( $fd, 4096 );
113 // Replace any combination of carriage return (\r) and new line (\n)
114 // with a single new line.
115 $data = preg_replace ( "/[\r\n]+/", "\n", $data );
117 // Split the data into lines.
118 $configLines = explode ( "\n", $data );
120 for ( $n = 0; $n < count ( $configLines ); $n++ ) {
121 $buffer = $configLines[$n];
122 $buffer = trim ( $buffer, "\r\n " );
123 if ( preg_match ( "/^#/", $buffer ) )
125 if ( preg_match ( "/^<\?/", $buffer ) ) // start php code
127 if ( preg_match ( "/^\?>/", $buffer ) ) // end php code
129 if ( preg_match ( "/(\S+):\s*(\S+)/", $buffer, $matches ) ) {
130 $settings[$matches[1]] = $matches[2];
131 //echo "settings $matches[1] => $matches[2] <br>";
134 $configLines = $data = '';
136 // Extract db settings into global vars
137 $db_type = $settings['db_type'];
138 $db_host = $settings['db_host'];
139 $db_login = $settings['db_login'];
140 $db_password = $settings['db_password'];
141 $db_database = $settings['db_database'];
142 $db_persistent = preg_match ( "/(1|yes|true|on)/i",
143 $settings['db_persistent'] ) ? '1' : '0';
145 foreach ( array ( "db_type", "db_host", "db_login", "db_password" ) as $s ) {
146 if ( empty ( $settings[$s] ) ) {
147 die_miserable_death ( "Could not find <tt>$s</tt> defined in " .
148 "your <tt>settings.php</tt> file.\n" );
152 $readonly = preg_match ( "/(1|yes|true|on)/i",
153 $settings['readonly'] ) ? 'Y' : 'N';
156 $single_user = preg_match ( "/(1|yes|true|on)/i",
157 $settings['single_user'] ) ? 'Y' : 'N';
158 if ( $single_user == 'Y' )
159 $single_user_login = $settings['single_user_login'];
161 if ( $single_user == 'Y' && empty ( $single_user_login ) ) {
162 die_miserable_death ( "You must define <tt>single_user_login</tt> in " .
163 "the settings.php file.\n" );
167 $use_http_auth = preg_match ( "/(1|yes|true|on)/i",
168 $settings['use_http_auth'] ) ? true : false;
170 // Type of user authentication
171 $user_inc = $settings['user_inc'];
173 // We can add extra 'nonuser' calendars such as a corporate calendar,
174 // holiday calendar, departmental calendar, etc. We need a unique prefix
175 // for these calendars as not to get mixed up with real logins. This prefix
176 // should be a Maximum of 5 characters and should NOT change once set!
177 $NONUSER_PREFIX = '_NUC_';
179 // Language options The first is the name presented to users while
180 // the second is the filename (without the ".txt") that must exist
181 // in the translations subdirectory.
183 "Browser-defined" =>"none",
184 "English" =>"English-US",
185 "Basque" => "Basque",
186 "Bulgarian" => "Bulgarian",
187 "Catalan" => "Catalan",
188 "Chinese (Traditonal/Big5)" => "Chinese-Big5",
189 "Chinese (Simplified/GB2312)" => "Chinese-GB2312",
191 "Danish" => "Danish",
193 "Estonian" => "Estonian",
194 "Finnish" =>"Finnish",
196 "Galician" => "Galician",
199 "Holo (Taiwanese)" => "Holo-Big5",
200 "Hungarian" =>"Hungarian",
201 "Icelandic" => "Icelandic",
202 "Italian" => "Italian",
203 "Japanese(SHIFT JIS)" => "Japanese",
204 "Japanese(EUC-JP)" => "Japanese-eucjp",
205 "Japanese(UTF-8)" => "Japanese-utf8",
207 "Norwegian" => "Norwegian",
208 "Polish" => "Polish",
209 "Portuguese" =>"Portuguese",
210 "Portuguese/Brazil" => "Portuguese_BR",
211 "Romanian" => "Romanian",
212 "Russian" => "Russian",
213 "Spanish" =>"Spanish",
214 "Swedish" =>"Swedish",
215 "Turkish" =>"Turkish",
217 // add new languages here! (don't forget to add a comma at the end of
221 // If the user sets "Browser-defined" as their language setting, then
222 // use the $HTTP_ACCEPT_LANGUAGE settings to determine the language.
223 // The array below translates browser language abbreviations into
224 // our available language files.
225 // NOTE: These should all be lowercase on the left side even though
226 // the proper listing is like "en-US"!
227 // Not sure what the abbreviation is? Check out the following URL:
228 // http://www.geocities.com/click2speak/languages.html
229 $browser_languages = array (
233 "zh" => "Chinese-GB2312", // Simplified Chinese
234 "zh-cn" => "Chinese-GB2312",
235 "zh-tw" => "Chinese-Big5", // Traditional Chinese
237 "en" => "English-US",
238 "en-us" => "English-US",
239 "en-gb" => "English-US",
245 "fr-ch" =>"French", // French/Swiss
246 "fr-ca" =>"French", // French/Canada
249 "de-at" =>"German", // German/Austria
250 "de-ch" =>"German", // German/Switzerland
251 "de-de" =>"German", // German/German
252 "el" =>"Greek", // German/German
254 "zh-min-nan-tw" => "Holo-Big5",
257 "it-ch" => "Italian", // Italian/Switzerland
263 "pt-br" => "Portuguese_BR", // Portuguese/Brazil
272 // The following comments will be picked up by update_translation.pl so
273 // translators will be aware that they also need to translate language names.
275 // translate("English")
276 // translate("Basque")
277 // translate("Bulgarian")
278 // translate("Catalan")
279 // translate("Chinese (Traditonal/Big5)")
280 // translate("Chinese (Simplified/GB2312)")
281 // translate("Czech")
282 // translate("Danish")
283 // translate("Dutch")
284 // translate("Estonian")
285 // translate("Finnish")
286 // translate("French")
287 // translate("Galician")
288 // translate("German")
289 // translate("Greek")
290 // translate("Holo (Taiwanese)")
291 // translate("Hungarian")
292 // translate("Icelandic")
293 // translate("Italian")
294 // translate("Japanese")
295 // translate("Korean")
296 // translate("Norwegian")
297 // translate("Polish")
298 // translate("Portuguese")
299 // translate("Portuguese/Brazil")
300 // translate("Romanian")
301 // translate("Russian")
302 // translate("Spanish")
303 // translate("Swedish")
304 // translate("Turkish")
305 // translate("Welsh")
307 if ( $single_user != "Y" )
308 $single_user_login = "";
310 // Make sure magic quotes is enabled, since this app requires it.
311 if ( get_magic_quotes_gpc () == 0 ) {
314 $val = ob_get_contents ();
317 if ( preg_match ( "/>([^<>]*php.ini)</", $val, $matches ) ) {
318 $loc = "Please edit the following file and restart your server:" .
320 "<blockquote>\n<tt>" . $matches[1] . "</tt>\n</blockquote>\n";
322 die_miserable_death ( "You must reconfigure your <tt>php.ini</tt> file to " .
323 "have <span style=\"font-weight:bold;\">magic_quotes_gpc</span> set " .
324 " to <span style=\"font-weight:bold;\">ON</span>.<br /><br />\n" .