/Branch_4_6dev/gforge/plugins/webcalendar/www/includes/functions.php
PHP | 5204 lines | 3337 code | 381 blank | 1486 comment | 1142 complexity | 9d32c58484ced9b4a4a052d06ed5e590 MD5 | raw file
Possible License(s): GPL-2.0, MPL-2.0-no-copyleft-exception
Large files files are truncated, but you can click here to view the full file
- <?php
- /**
- * All of WebCalendar's functions
- *
- * @author Craig Knudsen <cknudsen@cknudsen.com>
- * @copyright Craig Knudsen, <cknudsen@cknudsen.com>, http://www.k5n.us/cknudsen
- * @license http://www.gnu.org/licenses/gpl.html GNU GPL
- * @package WebCalendar
- */
- if ( empty ( $PHP_SELF ) && ! empty ( $_SERVER ) &&
- ! empty ( $_SERVER['PHP_SELF'] ) ) {
- $PHP_SELF = $_SERVER['PHP_SELF'];
- }
- if ( ! empty ( $PHP_SELF ) && preg_match ( "/\/includes\//", $PHP_SELF ) ) {
- die ( "You can't access this file directly!" );
- }
- /**#@+
- * Used for activity log
- * @global string
- */
- $LOG_CREATE = "C";
- $LOG_APPROVE = "A";
- $LOG_REJECT = "X";
- $LOG_UPDATE = "U";
- $LOG_DELETE = "D";
- $LOG_NOTIFICATION = "N";
- $LOG_REMINDER = "R";
- /**#@-*/
- /**
- *File to log
- *
- */
- global $log_file;
- $log_file="/var/lib/gforge/chroot/home/users/placoste/webcalendar/webcalendar.txt";
- /**
- * Number of seconds in a day
- *
- * @global int $ONE_DAY
- */
- $ONE_DAY = 86400;
- /**
- * Array containing the number of days in each month in a non-leap year
- *
- * @global array $days_per_month
- */
- $days_per_month = array ( 0, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 );
- /**
- * Array containing the number of days in each month in a leap year
- *
- * @global array $ldays_per_month
- */
- $ldays_per_month = array ( 0, 31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 );
- /**
- * Array of global variables which are not allowed to by set via HTTP GET/POST
- *
- * This is a security precaution to prevent users from overriding any global
- * variables
- *
- * @global array $noSet
- */
- $noSet = array (
- "is_admin" => 1,
- "db_type" => 1,
- "db_host" => 1,
- "db_login" => 1,
- "db_password" => 1,
- "db_persistent" => 1,
- "PROGRAM_NAME" => 1,
- "PROGRAM_URL" => 1,
- "readonly" => 1,
- "single_user" => 1,
- "single_user_login" => 1,
- "use_http_auth" => 1,
- "user_inc" => 1,
- "includedir" => 1,
- "NONUSER_PREFIX" => 1,
- "languages" => 1,
- "browser_languages" => 1,
- "pub_acc_enabled" => 1,
- "user_can_update_password" => 1,
- "admin_can_add_user" => 1,
- "admin_can_delete_user" => 1,
- );
- // This code is a temporary hack to make the application work when
- // register_globals is set to Off in php.ini (the default setting in
- // PHP 4.2.0 and after).
- if ( empty ( $HTTP_GET_VARS ) ) $HTTP_GET_VARS = $_GET;
- if ( ! empty ( $HTTP_GET_VARS ) ) {
- while (list($key, $val) = @each($HTTP_GET_VARS)) {
- // don't allow anything to have <script> in it...
- if ( ! is_array ( $val ) ) {
- if ( preg_match ( "/<\s*script/i", $val ) ) {
- echo "Security violation!"; exit;
- }
- }
- if ( $key == "login" ) {
- if ( strstr ( $PHP_SELF, "login.php" ) ) {
- //$GLOBALS[$key] = $val;
- $GLOBALS[$key] = $val;
- }
- } else {
- if ( empty ( $noSet[$key] ) ) {
- $GLOBALS[$key] = $val;
- //echo "XXX $key<br />\n";
- }
- }
- //echo "GET var '$key' = '$val' <br />\n";
- }
- reset ( $HTTP_GET_VARS );
- }
- if ( empty ( $HTTP_POST_VARS ) ) $HTTP_POST_VARS = $_POST;
- if ( ! empty ( $HTTP_POST_VARS ) ) {
- while (list($key, $val) = @each($HTTP_POST_VARS)) {
- // don't allow anything to have <script> in it... except 'template'
- if ( ! is_array ( $val ) && $key != 'template' ) {
- if ( preg_match ( "/<\s*script/i", $val ) ) {
- echo "Security violation!"; exit;
- }
- }
- if ( empty ( $noSet[$key] ) ) {
- $GLOBALS[$key] = $val;
- }
- }
- reset ( $HTTP_POST_VARS );
- }
- //while (list($key, $val) = @each($HTTP_POST_FILES)) {
- // $GLOBALS[$key] = $val;
- //}
- //while (list($key, $val) = @each($HTTP_SESSION_VARS)) {
- // $GLOBALS[$key] = $val;
- //}
- if ( empty ( $HTTP_COOKIE_VARS ) ) $HTTP_COOKIE_VARS = $_COOKIE;
- if ( ! empty ( $HTTP_COOKIE_VARS ) ) {
- while (list($key, $val) = @each($HTTP_COOKIE_VARS)) {
- if ( empty ( $noSet[$key] ) && substr($key,0,12) == "webcalendar_" ) {
- $GLOBALS[$key] = $val;
- }
- //echo "COOKIE var '$key' = '$val' <br />\n";
- }
- reset ( $HTTP_COOKIE_VARS );
- }
- // Don't allow a user to put "login=XXX" in the URL if they are not
- // coming from the login.php page.
- if ( empty ( $PHP_SELF ) && ! empty ( $_SERVER['PHP_SELF'] ) )
- $PHP_SELF = $_SERVER['PHP_SELF']; // backward compatibility
- if ( empty ( $PHP_SELF ) )
- $PHP_SELF = ''; // this happens when running send_reminders.php from CL
- if ( ! strstr ( $PHP_SELF, "login.php" ) && ! empty ( $GLOBALS["login"] ) ) {
- $GLOBALS["login"] = "";
- }
- // Define an array to use to jumble up the key: $offsets
- // We define a unique key to scramble the cookie we generate.
- // We use the admin install password that the user set to make
- // the salt unique for each WebCalendar install.
- if ( ! empty ( $settings ) && ! empty ( $settings['install_password'] ) ) {
- $salt = $settings['install_password'];
- } else {
- $salt = md5 ( $db_login );
- }
- $salt_len = strlen ( $salt );
- if ( ! empty ( $db_password ) ) {
- $salt2 = md5 ( $db_password );
- } else {
- $salt2 = md5 ( "oogabooga" );
- }
- $salt2_len = strlen ( $salt2 );
- $offsets = array ();
- for ( $i = 0; $i < $salt_len || $i < $salt2_len; $i++ ) {
- $offsets[$i] = 0;
- if ( $i < $salt_len )
- $offsets[$i] += ord ( substr ( $salt, $i, 1 ) );
- if ( $i < $salt2_len )
- $offsets[$i] += ord ( substr ( $salt2, $i, 1 ) );
- $offsets[$i] %= 128;
- }
- /* debugging code...
- for ( $i = 0; $i < count ( $offsets ); $i++ ) {
- echo "offset $i: $offsets[$i] <br />\n";
- }
- */
- function logs($logs_file, $msg){
- /*$log=fopen($logs_file,"a+");
- fputs($log,$msg."\n");
- fclose($log);*/
- }
- /*
- * Functions start here. All non-function code should be above this
- *
- * Note to developers:
- * Documentation is generated from the function comments below.
- * When adding/updating functions, please follow the following conventions
- * seen below. Your cooperation in this matter is appreciated :-)
- *
- * If you want your documentation to link to the db documentation,
- * just make sure you mention the db table name followed by "table"
- * on the same line. Here's an example:
- * Retrieve preferences from the webcal_user_pref table.
- *
- */
- /**
- * Gets the value resulting from an HTTP POST method.
- *
- * <b>Note:</b> The return value will be affected by the value of
- * <var>magic_quotes_gpc</var> in the php.ini file.
- *
- * @param string $name Name used in the HTML form
- *
- * @return string The value used in the HTML form
- *
- * @see getGetValue
- */
- function getPostValue ( $name ) {
- global $HTTP_POST_VARS;
- if ( isset ( $_POST ) && is_array ( $_POST ) && ! empty ( $_POST[$name] ) ) {
- $HTTP_POST_VARS[$name] = $_POST[$name];
- return $_POST[$name];
- } else if ( ! isset ( $HTTP_POST_VARS ) ) {
- return null;
- } else if ( ! isset ( $HTTP_POST_VARS[$name] ) ) {
- return null;
- }
- return ( $HTTP_POST_VARS[$name] );
- }
- /**
- * Gets the value resulting from an HTTP GET method.
- *
- * <b>Note:</b> The return value will be affected by the value of
- * <var>magic_quotes_gpc</var> in the php.ini file.
- *
- * If you need to enforce a specific input format (such as numeric input), then
- * use the {@link getValue()} function.
- *
- * @param string $name Name used in the HTML form or found in the URL
- *
- * @return string The value used in the HTML form (or URL)
- *
- * @see getPostValue
- */
- function getGetValue ( $name ) {
- global $HTTP_GET_VARS;
- if ( isset ( $_GET ) && is_array ( $_GET ) && ! empty ( $_GET[$name] ) ) {
- $HTTP_GET_VARS[$name] = $_GET[$name];
- return $_GET[$name];
- } else if ( ! isset ( $HTTP_GET_VARS ) ) {
- return null;
- } else if ( ! isset ( $HTTP_GET_VARS[$name] ) ) {
- return null;
- }
- return ( $HTTP_GET_VARS[$name] );
- }
- /**
- * Gets the value resulting from either HTTP GET method or HTTP POST method.
- *
- * <b>Note:</b> The return value will be affected by the value of
- * <var>magic_quotes_gpc</var> in the php.ini file.
- *
- * <b>Note:</b> If you need to get an integer value, yuou can use the
- * getIntValue function.
- *
- * @param string $name Name used in the HTML form or found in the URL
- * @param string $format A regular expression format that the input must match.
- * If the input does not match, an empty string is
- * returned and a warning is sent to the browser. If The
- * <var>$fatal</var> parameter is true, then execution
- * will also stop when the input does not match the
- * format.
- * @param bool $fatal Is it considered a fatal error requiring execution to
- * stop if the value retrieved does not match the format
- * regular expression?
- *
- * @return string The value used in the HTML form (or URL)
- *
- * @uses getGetValue
- * @uses getPostValue
- */
- function getValue ( $name, $format="", $fatal=false ) {
- $val = getPostValue ( $name );
- if ( ! isset ( $val ) )
- $val = getGetValue ( $name );
- // for older PHP versions...
- if ( ! isset ( $val ) && get_magic_quotes_gpc () == 1 &&
- ! empty ( $GLOBALS[$name] ) )
- $val = $GLOBALS[$name];
- if ( ! isset ( $val ) )
- return "";
- if ( ! empty ( $format ) && ! preg_match ( "/^" . $format . "$/", $val ) ) {
- // does not match
- if ( $fatal ) {
- die_miserable_death ( "Fatal Error: Invalid data format for $name" );
- }
- // ignore value
- return "";
- }
- return $val;
- }
- /**
- * Gets an integer value resulting from an HTTP GET or HTTP POST method.
- *
- * <b>Note:</b> The return value will be affected by the value of
- * <var>magic_quotes_gpc</var> in the php.ini file.
- *
- * @param string $name Name used in the HTML form or found in the URL
- * @param bool $fatal Is it considered a fatal error requiring execution to
- * stop if the value retrieved does not match the format
- * regular expression?
- *
- * @return string The value used in the HTML form (or URL)
- *
- * @uses getValue
- */
- function getIntValue ( $name, $fatal=false ) {
- $val = getValue ( $name, "-?[0-9]+", $fatal );
- return $val;
- }
- /**
- * Loads default system settings (which can be updated via admin.php).
- *
- * System settings are stored in the webcal_config table.
- *
- * <b>Note:</b> If the setting for <var>server_url</var> is not set, the value
- * will be calculated and stored in the database.
- *
- * @global string User's login name
- * @global bool Readonly
- * @global string HTTP hostname
- * @global int Server's port number
- * @global string Request string
- * @global array Server variables
- */
- function load_global_settings () {
- global $login, $readonly, $HTTP_HOST, $SERVER_PORT, $REQUEST_URI, $_SERVER;
- // Note: when running from the command line (send_reminders.php),
- // these variables are (obviously) not set.
- // TODO: This type of checking should be moved to a central locationm
- // like init.php.
- if ( isset ( $_SERVER ) && is_array ( $_SERVER ) ) {
- if ( empty ( $HTTP_HOST ) && isset ( $_SERVER["HTTP_POST"] ) )
- $HTTP_HOST = $_SERVER["HTTP_HOST"];
- if ( empty ( $SERVER_PORT ) && isset ( $_SERVER["SERVER_PORT"] ) )
- $SERVER_PORT = $_SERVER["SERVER_PORT"];
- if ( empty ( $REQUEST_URI ) && isset ( $_SERVER["REQUEST_URI"] ) )
- $REQUEST_URI = $_SERVER["REQUEST_URI"];
- }
- $res = dbi_query ( "SELECT cal_setting, cal_value FROM webcal_config" );
- if ( $res ) {
- while ( $row = dbi_fetch_row ( $res ) ) {
- $setting = $row[0];
- $value = $row[1];
- //echo "Setting '$setting' to '$value' <br />\n";
- $GLOBALS[$setting] = $value;
- }
- dbi_free_result ( $res );
- }
- // If app name not set.... default to "Title". This gets translated
- // later since this function is typically called before translate.php
- // is included.
- // Note: We usually use translate($application_name) instead of
- // translate("Title").
- if ( empty ( $GLOBALS["application_name"] ) )
- $GLOBALS["application_name"] = "Title";
- // If $server_url not set, then calculate one for them, then store it
- // in the database.
- if ( empty ( $GLOBALS["server_url"] ) ) {
- if ( ! empty ( $HTTP_HOST ) && ! empty ( $REQUEST_URI ) ) {
- $ptr = strrpos ( $REQUEST_URI, "/" );
- if ( $ptr > 0 ) {
- $uri = substr ( $REQUEST_URI, 0, $ptr + 1 );
- $server_url = "http://" . $HTTP_HOST;
- if ( ! empty ( $SERVER_PORT ) && $SERVER_PORT != 80 )
- $server_url .= ":" . $SERVER_PORT;
- $server_url .= $uri;
- dbi_query ( "INSERT INTO webcal_config ( cal_setting, cal_value ) ".
- "VALUES ( 'server_url', '$server_url' )" );
- $GLOBALS["server_url"] = $server_url;
- }
- }
- }
- // If no font settings, then set some
- if ( empty ( $GLOBALS["FONTS"] ) ) {
- if ( $GLOBALS["LANGUAGE"] == "Japanese" )
- $GLOBALS["FONTS"] = "Osaka, Arial, Helvetica, sans-serif";
- else
- $GLOBALS["FONTS"] = "Arial, Helvetica, sans-serif";
- }
- }
- /**
- * Gets the list of active plugins.
- *
- * Should be called after {@link load_global_settings()} and {@link load_user_preferences()}.
- *
- * @internal cek: ignored since I am not sure this will ever be used...
- *
- * @return array Active plugins
- *
- * @ignore
- */
- function get_plugin_list ( $include_disabled=false ) {
- // first get list of available plugins
- $sql = "SELECT cal_setting FROM webcal_config " .
- "WHERE cal_setting LIKE '%.plugin_status'";
- if ( ! $include_disabled )
- $sql .= " AND cal_value = 'Y'";
- $sql .= " ORDER BY cal_setting";
- $res = dbi_query ( $sql );
- $plugins = array ();
- if ( $res ) {
- while ( $row = dbi_fetch_row ( $res ) ) {
- $e = explode ( ".", $row[0] );
- if ( $e[0] != "" ) {
- $plugins[] = $e[0];
- }
- }
- dbi_free_result ( $res );
- } else {
- echo translate("Database error") . ": " . dbi_error (); exit;
- }
- if ( count ( $plugins ) == 0 ) {
- $plugins[] = "webcalendar";
- }
- return $plugins;
- }
- /**
- * Get plugins available to the current user.
- *
- * Do this by getting a list of all plugins that are not disabled by the
- * administrator and make sure this user has not disabled any of them.
- *
- * It's done this was so that when an admin adds a new plugin, it shows up on
- * each users system automatically (until they disable it).
- *
- * @return array Plugins available to current user
- *
- * @ignore
- */
- function get_user_plugin_list () {
- $ret = array ();
- $all_plugins = get_plugin_list ();
- for ( $i = 0; $i < count ( $all_plugins ); $i++ ) {
- if ( $GLOBALS[$all_plugins[$i] . ".disabled"] != "N" )
- $ret[] = $all_plugins[$i];
- }
- return $ret;
- }
- /**
- * Identify user's browser.
- *
- * Returned value will be one of:
- * - "Mozilla/5" = Mozilla (open source Mozilla 5.0)
- * - "Mozilla/[3,4]" = Netscape (3.X, 4.X)
- * - "MSIE 4" = MSIE (4.X)
- *
- * @return string String identifying browser
- *
- * @ignore
- */
- function get_web_browser () {
- if ( ereg ( "MSIE [0-9]", getenv ( "HTTP_USER_AGENT" ) ) )
- return "MSIE";
- if ( ereg ( "Mozilla/[234]", getenv ( "HTTP_USER_AGENT" ) ) )
- return "Netscape";
- if ( ereg ( "Mozilla/[5678]", getenv ( "HTTP_USER_AGENT" ) ) )
- return "Mozilla";
- return "Unknown";
- }
- /**
- * Logs a debug message.
- *
- * Generally, we do not leave calls to this function in the code. It is used
- * for debugging only.
- *
- * @param string $msg Text to be logged
- */
- function do_debug ( $msg ) {
- // log to /tmp/webcal-debug.log
- //error_log ( date ( "Y-m-d H:i:s" ) . "> $msg\n",
- // 3, "/tmp/webcal-debug.log" );
- //error_log ( date ( "Y-m-d H:i:s" ) . "> $msg\n",
- // 2, "sockieman:2000" );
- }
- /**
- * Gets user's preferred view.
- *
- * The user's preferred view is stored in the $STARTVIEW global variable. This
- * is loaded from the user preferences (or system settings if there are no user
- * prefererences.)
- *
- * @param string $indate Date to pass to preferred view in YYYYMMDD format
- * @param string $args Arguments to include in the URL (such as "user=joe")
- *
- * @return string URL of the user's preferred view
- */
- function get_preferred_view ( $indate="", $args="" ) {
- global $STARTVIEW, $thisdate;
- $url = empty ( $STARTVIEW ) ? "month.php" : $STARTVIEW;
- // We used to just store "month" in $STARTVIEW without the ".php"
- // This is just to prevent users from getting a "404 not found" if
- // they have not updated their preferences.
- if ( $url == "month" || $url == "day" || $url == "week" || $url == "year" )
- $url .= ".php";
- $url = str_replace ( '&', '&', $url );
- $url = str_replace ( '&', '&', $url );
- $xdate = empty ( $indate ) ? $thisdate : $indate;
- if ( ! empty ( $xdate ) ) {
- if ( strstr ( $url, "?" ) )
- $url .= '&' . "date=$xdate";
- else
- $url .= '?' . "date=$xdate";
- }
- if ( ! empty ( $args ) ) {
- if ( strstr ( $url, "?" ) )
- $url .= '&' . $args;
- else
- $url .= '?' . $args;
- }
- return $url;
- }
- /**
- * Sends a redirect to the user's preferred view.
- *
- * The user's preferred view is stored in the $STARTVIEW global variable. This
- * is loaded from the user preferences (or system settings if there are no user
- * prefererences.)
- *
- * @param string $indate Date to pass to preferred view in YYYYMMDD format
- * @param string $args Arguments to include in the URL (such as "user=joe")
- */
- function send_to_preferred_view ( $indate="", $args="" ) {
- $url = get_preferred_view ( $indate, $args );
- do_redirect ( $url );
- }
- /** Sends a redirect to the specified page.
- *
- * The database connection is closed and execution terminates in this function.
- *
- * <b>Note:</b> MS IIS/PWS has a bug in which it does not allow us to send a
- * cookie and a redirect in the same HTTP header. When we detect that the web
- * server is IIS, we accomplish the redirect using meta-refresh. See the
- * following for more info on the IIS bug:
- *
- * {@link http://www.faqts.com/knowledge_base/view.phtml/aid/9316/fid/4}
- *
- * @param string $url The page to redirect to. In theory, this should be an
- * absolute URL, but all browsers accept relative URLs (like
- * "month.php").
- *
- * @global string Type of webserver
- * @global array Server variables
- * @global resource Database connection
- */
- function do_redirect ( $url ) {
- //Debug
- //$log=fopen("/var/lib/gforge/chroot/home/users/placoste/webcalendar/webcalendar.txt","a+");
- //fputs($log,"####### functions.php #######\n------- do_redirect -------\n");
- //fclose($log);
- //Debug
-
- //Debug
- //$log=fopen("/var/lib/gforge/chroot/home/users/placoste/webcalendar/webcalendar.txt","a+");
- //fputs($log,"url : ".$url."\n");
- //fclose($log);
- //Debug
-
- global $SERVER_SOFTWARE, $_SERVER, $c;
- // Replace any '&' with '&' since we don't want that in the HTTP
- // header.
- $url = str_replace ( '&', '&', $url );
- if ( empty ( $SERVER_SOFTWARE ) )
- $SERVER_SOFTWARE = $_SERVER["SERVER_SOFTWARE"];
-
- //echo "SERVER_SOFTWARE = $SERVER_SOFTWARE <br />\n"; exit;
- if ( ( substr ( $SERVER_SOFTWARE, 0, 5 ) == "Micro" ) || ( substr ( $SERVER_SOFTWARE, 0, 3 ) == "WN/" ) ) {
-
- echo "<?xml version=\"1.0\" encoding=\"utf-8\"\n
- <!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.0 Transitional//EN\"\"DTD/xhtml1-transitional.dtd\">
- <html xmlns=\"http://www.w3.org/1999/xhtml\" xml:lang=\"en\" lang=\"en\">
- <head>\n
- <title>Redirect</title>\n
- <meta http-equiv=\"refresh\" content=\"0; url=\"".$url."\" />\n
- </head>\n
- <body>\n
- Redirecting to.. <a href=\"".$url."\">here</a>
- </body>\n
- </html>";
- }else {
-
- Header ( "Location: ".$url );
- print "<script>window.location.href=\"".$url."\";</script>" ;
- echo "<?xml version=\"1.0\" encoding=\"utf-8\"\n
- <!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.0 Transitional//EN\" \"DTD/xhtml1-transitional.dtd\">
- <html xmlns=\"http://www.w3.org/1999/xhtml\" xml:lang=\"en\" lang=\"en\">
- <head>\n
- <title>Redirect</title>\n
- </head>\n
- <body>\n
- Redirecting to ... <a href=\"".$url."\">here</a>.
- </body>\n
- </html>";
- }
-
- dbi_close ( $c );
-
- exit;
-
- }
- /**
- * Sends an HTTP login request to the browser and stops execution.
- */
- function send_http_login () {
- global $lang_file, $application_name;
- if ( strlen ( $lang_file ) ) {
- Header ( "WWW-Authenticate: Basic realm=\"" . translate("Title") . "\"");
- Header ( "HTTP/1.0 401 Unauthorized" );
- echo "<?xml version=\"1.0\" encoding=\"utf-8\"?>\n<!DOCTYPE html
- PUBLIC \"-//W3C//DTD XHTML 1.0 Transitional//EN\"
- \"DTD/xhtml1-transitional.dtd\">
- <html xmlns=\"http://www.w3.org/1999/xhtml\" xml:lang=\"en\" lang=\"en\">
- <head>\n<title>Unauthorized</title>\n</head>\n<body>\n" .
- "<h2>" . translate("Title") . "</h2>\n" .
- translate("You are not authorized") .
- "\n</body>\n</html>";
- } else {
- Header ( "WWW-Authenticate: Basic realm=\"WebCalendar\"");
- Header ( "HTTP/1.0 401 Unauthorized" );
- echo "<?xml version=\"1.0\" encoding=\"utf-8\"?>\n<!DOCTYPE html
- PUBLIC \"-//W3C//DTD XHTML 1.0 Transitional//EN\"
- \"DTD/xhtml1-transitional.dtd\">
- <html xmlns=\"http://www.w3.org/1999/xhtml\" xml:lang=\"en\" lang=\"en\">
- <head>\n<title>Unauthorized</title>\n</head>\n<body>\n" .
- "<h2>WebCalendar</h2>\n" .
- "You are not authorized" .
- "\n</body>\n</html>";
- }
- exit;
- }
- /**
- * Generates a cookie that saves the last calendar view.
- *
- * Cookie is based on the current <var>$REQUEST_URI</var>.
- *
- * We save this cookie so we can return to this same page after a user
- * edits/deletes/etc an event.
- *
- * @global string Request string
- */
- function remember_this_view () {
- global $REQUEST_URI;
- if ( empty ( $REQUEST_URI ) )
- $REQUEST_URI = $_SERVER["REQUEST_URI"];
- // do not use anything with friendly in the URI
- if ( strstr ( $REQUEST_URI, "friendly=" ) )
- return;
- SetCookie ( "webcalendar_last_view", $REQUEST_URI );
- }
- /**
- * Gets the last page stored using {@link remember_this_view()}.
- *
- * @return string The URL of the last view or an empty string if it cannot be
- * determined.
- *
- * @global array Cookies
- */
- function get_last_view () {
- global $HTTP_COOKIE_VARS;
- $val = '';
- if ( isset ( $_COOKIE["webcalendar_last_view"] ) ) {
- $HTTP_COOKIE_VARS["webcalendar_last_view"] = $_COOKIE["webcalendar_last_view"];
- $val = $_COOKIE["webcalendar_last_view"];
- } else if ( isset ( $HTTP_COOKIE_VARS["webcalendar_last_view"] ) ) {
- $val = $HTTP_COOKIE_VARS["webcalendar_last_view"];
- }
- $val = str_replace ( "&", "&", $val );
- return $val;
- }
- /**
- * Sends HTTP headers that tell the browser not to cache this page.
- *
- * Different browser use different mechanisms for this, so a series of HTTP
- * header directives are sent.
- *
- * <b>Note:</b> This function needs to be called before any HTML output is sent
- * to the browser.
- */
- function send_no_cache_header () {
- header ( "Expires: Mon, 26 Jul 1997 05:00:00 GMT" );
- header ( "Last-Modified: " . gmdate ( "D, d M Y H:i:s" ) . " GMT" );
- header ( "Cache-Control: no-store, no-cache, must-revalidate" );
- header ( "Cache-Control: post-check=0, pre-check=0", false );
- header ( "Pragma: no-cache" );
- }
- /**
- * Loads the current user's preferences as global variables from the webcal_user_pref table.
- *
- * Also loads the list of views for this user (not really a preference, but
- * this is a convenient place to put this...)
- *
- * <b>Notes:</b>
- * - If <var>$allow_color_customization</var> is set to 'N', then we ignore any
- * color preferences.
- * - Other default values will also be set if the user has not saved a
- * preference and no global value has been set by the administrator in the
- * system settings.
- */
- function load_user_preferences () {
- global $login, $browser, $views, $prefarray, $is_assistant,
- $has_boss, $user, $is_nonuser_admin, $allow_color_customization;
- $lang_found = false;
- $colors = array (
- "BGCOLOR" => 1,
- "H2COLOR" => 1,
- "THBG" => 1,
- "THFG" => 1,
- "CELLBG" => 1,
- "TODAYCELLBG" => 1,
- "WEEKENDBG" => 1,
- "POPUP_BG" => 1,
- "POPUP_FG" => 1,
- );
-
- $browser = get_web_browser ();
- $browser_lang = get_browser_language ();
- $prefarray = array ();
- // Note: default values are set in config.php
- $res = dbi_query (
- "SELECT cal_setting, cal_value FROM webcal_user_pref " .
- "WHERE cal_login = '$login'" );
- if ( $res ) {
- while ( $row = dbi_fetch_row ( $res ) ) {
- $setting = $row[0];
- $value = $row[1];
- if ( $allow_color_customization == 'N' ) {
- if ( isset ( $colors[$setting] ) )
- continue;
- }
- $sys_setting = "sys_" . $setting;
- // save system defaults
- if ( ! empty ( $GLOBALS[$setting] ) )
- $GLOBALS["sys_" . $setting] = $GLOBALS[$setting];
- $GLOBALS[$setting] = $value;
- $prefarray[$setting] = $value;
- if ( $setting == "LANGUAGE" )
- $lang_found = true;
- }
- dbi_free_result ( $res );
- }
- // get views for this user and global views
- $res = dbi_query (
- "SELECT cal_view_id, cal_name, cal_view_type, cal_is_global " .
- "FROM webcal_view " .
- "WHERE cal_owner = '$login' OR cal_is_global = 'Y' " .
- "ORDER BY cal_name" );
- if ( $res ) {
- $views = array ();
- while ( $row = dbi_fetch_row ( $res ) ) {
- if ( $row[2] == 'S' )
- $url = "view_t.php?timeb=1&id=$row[0]";
- else if ( $row[2] == 'T' )
- $url = "view_t.php?timeb=0&id=$row[0]";
- else
- $url = "view_" . strtolower ( $row[2] ) . ".php?id=$row[0]";
- $v = array (
- "cal_view_id" => $row[0],
- "cal_name" => $row[1],
- "cal_view_type" => $row[2],
- "cal_is_global" => $row[3],
- "url" => $url
- );
- $views[] = $v;
- }
- dbi_free_result ( $res );
- }
- // If user has not set a language preference, then use their browser
- // settings to figure it out, and save it in the database for future
- // use (email reminders).
- if ( ! $lang_found && strlen ( $login ) && $login != "__public__" ) {
- $LANGUAGE = $browser_lang;
- dbi_query ( "INSERT INTO webcal_user_pref " .
- "( cal_login, cal_setting, cal_value ) VALUES " .
- "( '$login', 'LANGUAGE', '$LANGUAGE' )" );
- }
- if ( empty ( $GLOBALS["DATE_FORMAT_MY"] ) )
- $GLOBALS["DATE_FORMAT_MY"] = "__month__ __yyyy__";
- if ( empty ( $GLOBALS["DATE_FORMAT_MD"] ) )
- $GLOBALS["DATE_FORMAT_MD"] = "__month__ __dd__";
- $is_assistant = empty ( $user ) ? false :
- user_is_assistant ( $login, $user );
- $has_boss = user_has_boss ( $login );
- $is_nonuser_admin = ($user) ? user_is_nonuser_admin ( $login, $user ) : false;
- if ( $is_nonuser_admin ) load_nonuser_preferences ($user);
- }
- /**
- * Gets the list of external users for an event from the webcal_entry_ext_user table in an HTML format.
- *
- * @param int $event_id Event ID
- * @param int $use_mailto When set to 1, email address will contain an href
- * link with a mailto URL.
- *
- * @return string The list of external users for an event formatte in HTML.
- */
- function event_get_external_users ( $event_id, $use_mailto=0 ) {
- global $error;
- $ret = "";
- $res = dbi_query ( "SELECT cal_fullname, cal_email " .
- "FROM webcal_entry_ext_user " .
- "WHERE cal_id = $event_id " .
- "ORDER by cal_fullname" );
- if ( $res ) {
- while ( $row = dbi_fetch_row ( $res ) ) {
- if ( strlen ( $ret ) )
- $ret .= "\n";
- // Remove [\d] if duplicate name
- $trow = trim( preg_replace( '/\[[\d]]/' , "", $row[0] ) );
- $ret .= $trow;
- if ( strlen ( $row[1] ) ) {
- if ( $use_mailto ) {
- $ret .= " <a href=\"mailto:$row[1]\"><" .
- htmlentities ( $row[1] ) . "></a>";
- } else {
- $ret .= " <". htmlentities ( $row[1] ) . ">";
- }
- }
- }
- dbi_free_result ( $res );
- } else {
- echo translate("Database error") .": " . dbi_error ();
- echo "<br />\nSQL:<br />\n$sql";
- exit;
- }
- return $ret;
- }
- /**
- * Adds something to the activity log for an event.
- *
- * The information will be saved to the webcal_entry_log table.
- *
- * @param int $event_id Event ID
- * @param string $user Username of user doing this
- * @param string $user_cal Username of user whose calendar is affected
- * @param string $type Type of activity we are logging:
- * - $LOG_CREATE
- * - $LOG_APPROVE
- * - $LOG_REJECT
- * - $LOG_UPDATE
- * - $LOG_DELETE
- * - $LOG_NOTIFICATION
- * - $LOG_REMINDER
- * @param string $text Text comment to add with activity log entry
- */
- function activity_log ( $event_id, $user, $user_cal, $type, $text ) {
- $next_id = 1;
- if ( empty ( $type ) ) {
- echo "Error: type not set for activity log!";
- // but don't exit since we may be in mid-transaction
- return;
- }
- $res = dbi_query ( "SELECT MAX(cal_log_id) FROM webcal_entry_log" );
- if ( $res ) {
- if ( $row = dbi_fetch_row ( $res ) ) {
- $next_id = $row[0] + 1;
- }
- dbi_free_result ( $res );
- }
- $date = date ( "Ymd" );
- $time = date ( "Gis" );
- $sql_text = empty ( $text ) ? "NULL" : "'$text'";
- $sql_user_cal = empty ( $user_cal ) ? "NULL" : "'$user_cal'";
- $sql = "INSERT INTO webcal_entry_log ( " .
- "cal_log_id, cal_entry_id, cal_login, cal_user_cal, cal_type, " .
- "cal_date, cal_time, cal_text ) VALUES ( $next_id, $event_id, " .
- "'$user', $sql_user_cal, '$type', $date, $time, $sql_text )";
- if ( ! dbi_query ( $sql ) ) {
- echo "Database error: " . dbi_error ();
- echo "<br />\nSQL:<br />\n$sql";
- exit;
- }
- }
- /**
- * Gets a list of users.
- *
- * If groups are enabled, this will restrict the list of users to only those
- * users who are in the same group(s) as the user (unless the user is an admin
- * user). We allow admin users to see all users because they can also edit
- * someone else's events (so they may need access to users who are not in the
- * same groups that they are in).
- *
- * @return array Array of users, where each element in the array is an array
- * with the following keys:
- * - cal_login
- * - cal_lastname
- * - cal_firstname
- * - cal_is_admin
- * - cal_is_admin
- * - cal_email
- * - cal_password
- * - cal_fullname
- */
- function get_my_users () {
- global $login, $is_admin, $groups_enabled, $user_sees_only_his_groups;
- if ( $groups_enabled == "Y" && $user_sees_only_his_groups == "Y" &&
- ! $is_admin ) {
- // get groups that current user is in
- $res = dbi_query ( "SELECT cal_group_id FROM webcal_group_user " .
- "WHERE cal_login = '$login'" );
- $groups = array ();
- if ( $res ) {
- while ( $row = dbi_fetch_row ( $res ) ) {
- $groups[] = $row[0];
- }
- dbi_fetch_row ( $res );
- }
- $u = user_get_users ();
- $u_byname = array ();
- for ( $i = 0; $i < count ( $u ); $i++ ) {
- $name = $u[$i]['cal_login'];
- $u_byname[$name] = $u[$i];
- }
- $ret = array ();
- if ( count ( $groups ) == 0 ) {
- // Eek. User is in no groups... Return only themselves
- $ret[] = $u_byname[$login];
- return $ret;
- }
- // get list of users in the same groups as current user
- $sql = "SELECT DISTINCT(webcal_group_user.cal_login), cal_lastname, cal_firstname from webcal_group_user " .
- "LEFT JOIN webcal_user ON webcal_group_user.cal_login = webcal_user.cal_login " .
- "WHERE cal_group_id ";
- if ( count ( $groups ) == 1 )
- $sql .= "= " . $groups[0];
- else {
- $sql .= "IN ( " . implode ( ", ", $groups ) . " )";
- }
- $sql .= " ORDER BY cal_lastname, cal_firstname, webcal_group_user.cal_login";
- //echo "SQL: $sql <br />\n";
- $res = dbi_query ( $sql );
- if ( $res ) {
- while ( $row = dbi_fetch_row ( $res ) ) {
- $ret[] = $u_byname[$row[0]];
- }
- dbi_free_result ( $res );
- }
- return $ret;
- } else {
- // groups not enabled... return all users
- //echo "No groups. ";
- return user_get_users ();
- }
- }
- /**
- * Gets a preference setting for the specified user.
- *
- * If no value is found in the database, then the system default setting will
- * be returned.
- *
- * @param string $user User login we are getting preference for
- * @param string $setting Name of the setting
- *
- * @return string The value found in the webcal_user_pref table for the
- * specified setting or the sytem default if no user settings
- * was found.
- */
- function get_pref_setting ( $user, $setting ) {
- $ret = '';
- // set default
- if ( ! isset ( $GLOBALS["sys_" .$setting] ) ) {
- // this could happen if the current user has not saved any pref. yet
- if ( ! empty ( $GLOBALS[$setting] ) )
- $ret = $GLOBALS[$setting];
- } else {
- $ret = $GLOBALS["sys_" .$setting];
- }
- $sql = "SELECT cal_value FROM webcal_user_pref " .
- "WHERE cal_login = '" . $user . "' AND " .
- "cal_setting = '" . $setting . "'";
- //echo "SQL: $sql <br />\n";
- $res = dbi_query ( $sql );
- if ( $res ) {
- if ( $row = dbi_fetch_row ( $res ) )
- $ret = $row[0];
- dbi_free_result ( $res );
- }
- return $ret;
- }
- /**
- * Gets browser-specified language preference.
- *
- * @return string Preferred language
- *
- * @ignore
- */
- function get_browser_language () {
- global $HTTP_ACCEPT_LANGUAGE, $browser_languages;
- $ret = "";
- if ( empty ( $HTTP_ACCEPT_LANGUAGE ) &&
- isset ( $_SERVER["HTTP_ACCEPT_LANGUAGE"] ) )
- $HTTP_ACCEPT_LANGUAGE = $_SERVER["HTTP_ACCEPT_LANGUAGE"];
- if ( empty ( $HTTP_ACCEPT_LANGUAGE ) ) {
- return "none";
- } else {
- $langs = explode ( ",", $HTTP_ACCEPT_LANGUAGE );
- for ( $i = 0; $i < count ( $langs ); $i++ ) {
- $l = strtolower ( trim ( ereg_replace(';.*', '', $langs[$i] ) ) );
- $ret .= "\"$l\" ";
- if ( ! empty ( $browser_languages[$l] ) ) {
- return $browser_languages[$l];
- }
- }
- }
- //if ( strlen ( $HTTP_ACCEPT_LANGUAGE ) )
- // return "none ($HTTP_ACCEPT_LANGUAGE not supported)";
- //else
- return "none";
- }
- /**
- * Loads current user's layer info into layer global variable.
- *
- * If the system setting <var>$allow_view_other</var> is not set to 'Y', then
- * we ignore all layer functionality. If <var>$force</var> is 0, we only load
- * layers if the current user preferences have layers turned on.
- *
- * @param string $user Username of user to load layers for
- * @param int $force If set to 1, then load layers for this user even if
- * user preferences have layers turned off.
- */
- function load_user_layers ($user="",$force=0) {
- global $login;
- global $layers;
- global $LAYERS_STATUS, $allow_view_other;
- if ( $user == "" )
- $user = $login;
- $layers = array ();
- if ( empty ( $allow_view_other ) || $allow_view_other != 'Y' )
- return; // not allowed to view others' calendars, so cannot use layers
- if ( $force || ( ! empty ( $LAYERS_STATUS ) && $LAYERS_STATUS != "N" ) ) {
- $res = dbi_query (
- "SELECT cal_layerid, cal_layeruser, cal_color, cal_dups " .
- "FROM webcal_user_layers " .
- "WHERE cal_login = '$user' ORDER BY cal_layerid" );
- if ( $res ) {
- $count = 1;
- while ( $row = dbi_fetch_row ( $res ) ) {
- $layers[$row[0]] = array (
- "cal_layerid" => $row[0],
- "cal_layeruser" => $row[1],
- "cal_color" => $row[2],
- "cal_dups" => $row[3]
- );
- $count++;
- }
- dbi_free_result ( $res );
- }
- } else {
- //echo "Not loading!";
- }
- }
- /**
- * Generates the HTML used in an event popup for the site_extras fields of an event.
- *
- * @param int $id Event ID
- *
- * @return string The HTML to be used within the event popup for any site_extra
- * fields found for the specified event
- */
- function site_extras_for_popup ( $id ) {
- global $site_extras_in_popup, $site_extras;
- // These are needed in case the site_extras.php file was already
- // included.
- global $EXTRA_TEXT, $EXTRA_MULTILINETEXT, $EXTRA_URL, $EXTRA_DATE,
- $EXTRA_EMAIL, $EXTRA_USER, $EXTRA_REMINDER, $EXTRA_SELECTLIST;
- global $EXTRA_REMINDER_WITH_DATE, $EXTRA_REMINDER_WITH_OFFSET,
- $EXTRA_REMINDER_DEFAULT_YES;
- $ret = '';
- if ( $site_extras_in_popup != 'Y' )
- return '';
- include_once 'includes/site_extras.php';
- $extras = get_site_extra_fields ( $id );
- for ( $i = 0; $i < count ( $site_extras ); $i++ ) {
- $extra_name = $site_extras[$i][0];
- $extra_type = $site_extras[$i][2];
- $extra_arg1 = $site_extras[$i][3];
- $extra_arg2 = $site_extras[$i][4];
- if ( ! empty ( $extras[$extra_name]['cal_name'] ) ) {
- $ret .= "<dt>" . translate ( $site_extras[$i][1] ) . ":</dt>\n<dd>";
- if ( $extra_type == $EXTRA_DATE ) {
- if ( $extras[$extra_name]['cal_date'] > 0 )
- $ret .= date_to_str ( $extras[$extra_name]['cal_date'] );
- } else if ( $extra_type == $EXTRA_TEXT ||
- $extra_type == $EXTRA_MULTILINETEXT ) {
- $ret .= nl2br ( $extras[$extra_name]['cal_data'] );
- } else if ( $extra_type == $EXTRA_REMINDER ) {
- if ( $extras[$extra_name]['cal_remind'] <= 0 )
- $ret .= translate ( "No" );
- else {
- $ret .= translate ( "Yes" );
- if ( ( $extra_arg2 & $EXTRA_REMINDER_WITH_DATE ) > 0 ) {
- $ret .= " - ";
- $ret .= date_to_str ( $extras[$extra_name]['cal_date'] );
- } else if ( ( $extra_arg2 & $EXTRA_REMINDER_WITH_OFFSET ) > 0 ) {
- $ret .= " - ";
- $minutes = $extras[$extra_name]['cal_data'];
- $d = (int) ( $minutes / ( 24 * 60 ) );
- $minutes -= ( $d * 24 * 60 );
- $h = (int) ( $minutes / 60 );
- $minutes -= ( $h * 60 );
- if ( $d > 0 )
- $ret .= $d . " " . translate("days") . " ";
- if ( $h > 0 )
- $ret .= $h . " " . translate("hours") . " ";
- if ( $minutes > 0 )
- $ret .= $minutes . " " . translate("minutes");
- $ret .= " " . translate("before event" );
- }
- }
- } else {
- $ret .= $extras[$extra_name]['cal_data'];
- }
- $ret .= "</dd>\n";
- }
- }
- return $ret;
- }
- /**
- * Builds the HTML for the event popup.
- *
- * @param string $popupid CSS id to use for event popup
- * @param string $user Username of user the event pertains to
- * @param string $description Event description
- * @param string $time Time of the event (already formatted in a display format)
- * @param string $site_extras HTML for any site_extras for this event
- *
- * @return string The HTML for the event popup
- */
- function build_event_popup ( $popupid, $user, $description, $time, $site_extras='' ) {
- global $login, $popup_fullnames, $popuptemp_fullname;
- $ret = "<dl id=\"$popupid\" class=\"popup\">\n";
- if ( empty ( $popup_fullnames ) )
- $popup_fullnames = array ();
-
- if ( $user != $login ) {
- if ( empty ( $popup_fullnames[$user] ) ) {
- user_load_variables ( $user, "popuptemp_" );
- $popup_fullnames[$user] = $popuptemp_fullname;
- }
- $ret .= "<dt>" . translate ("User") .
- ":</dt>\n<dd>$popup_fullnames[$user]</dd>\n";
- }
- if ( strlen ( $time ) )
- $ret .= "<dt>" . translate ("Time") . ":</dt>\n<dd>$time</dd>\n";
- $ret .= "<dt>" . translate ("Description") . ":</dt>\n<dd>";
- if ( ! empty ( $GLOBALS['allow_html_description'] ) &&
- $GLOBALS['allow_html_description'] == 'Y' ) {
- $str = str_replace ( "&", "&", $description );
- $str = str_replace ( "&amp;", "&", $str );
- // If there is no html found, then go ahead and replace
- // the line breaks ("\n") with the html break.
- if ( strstr ( $str, "<" ) && strstr ( $str, ">" ) ) {
- // found some html...
- $ret .= $str;
- } else {
- // no html, replace line breaks
- $ret .= nl2br ( $str );
- }
- } else {
- // html not allowed in description, escape everything
- $ret .= nl2br ( htmlspecialchars ( $description ) );
- }
- $ret .= "</dd>\n";
- if ( ! empty ( $site_extras ) )
- $ret .= $site_extras;
- $ret .= "</dl>\n";
- return $ret;
- }
- /**
- * Prints out a date selection box for use in a form.
- *
- * @param string $prefix Prefix to use in front of form element names
- * @param int $date Currently selected date (in YYYYMMDD format)
- *
- * @uses date_selection_html
- */
- function print_date_selection ( $prefix, $date ) {
- print date_selection_html ( $prefix, $date );
- }
- /**
- * Generate HTML for a date selection for use in a form.
- *
- * @param string $prefix Prefix to use in front of form element names
- * @param int $date Currently selected date (in YYYYMMDD format)
- *
- * @return string HTML for the selection box
- */
- function date_selection_html ( $prefix, $date ) {
- $ret = "";
- $num_years = 20;
- if ( strlen ( $date ) != 8 )
- $date = date ( "Ymd" );
- $thisyear = $year = substr ( $date, 0, 4 );
- $thismonth = $month = substr ( $date, 4, 2 );
- $thisday = $day = substr ( $date, 6, 2 );
- if ( $thisyear - date ( "Y" ) >= ( $num_years - 1 ) )
- $num_years = $thisyear - date ( "Y" ) + 2;
- $ret .= "<select name=\"" . $prefix . "day\">\n";
- for ( $i = 1; $i <= 31; $i++ )
- $ret .= "<option value=\"$i\"" .
- ( $i == $thisday ? " selected=\"selected\"" : "" ) . ">$i</option>\n";
- $ret .= "</select>\n<select name=\"" . $prefix . "month\">\n";
- for ( $i = 1; $i <= 12; $i++ ) {
- $m = month_short_name ( $i - 1 );
- $ret .= "<option value=\"$i\"" .
- ( $i == $thismonth ? " selected=\"selected\"" : "" ) . ">$m</option>\n";
- }
- $ret .= "</select>\n<select name=\"" . $prefix . "year\">\n";
- for ( $i = -10; $i < $num_years; $i++ ) {
- $y = $thisyear + $i;
- $ret .= "<option value=\"$y\"" .
- ( $y == $thisyear ? " selected=\"selected\"" : "" ) . ">$y</option>\n";
- }
- $ret .= "</select>\n";
- $ret .= "<input type=\"button\" onclick=\"selectDate( '" .
- $prefix . "day','" . $prefix . "month','" . $prefix . "year',$date, event)\" value=\"" .
- translate("Select") . "...\" />\n";
- return $ret;
- }
- /**
- * Prints out a minicalendar for a month.
- *
- * @todo Make day.php NOT be a special case
- *
- * @param int $thismonth Number of the month to print
- * @param int $thisyear Number of the year
- * @param bool $showyear Show the year in the calendar's title?
- * @param bool $show_weeknums Show week numbers to the left of each row?
- * @param string $minical_id id attribute for the minical table
- * @param string $month_link URL and query string for month link that should
- * come before the date specification (e.g.
- * month.php? or view_l.php?id=7&)
- */
- function display_small_month ( $thismonth, $thisyear, $showyear,
- $show_weeknums=false, $minical_id='', $month_link='month.php?', $info_type='&type_param=user' ) {
- global $WEEK_START, $user, $login, $boldDays, $get_unapproved;
- global $DISPLAY_WEEKNUMBER;
- global $SCRIPT, $thisday; // Needed for day.php
- global $caturl, $today;
- global $log_file;
-
- //Debug
- logs($log_file,"####### function.php #######\n------- display_small_month -------\n");
- if(isset($get_unapproved)){
- logs($log_file, "1\n");
- }else{
- logs($log_file, "0\n");
- }
- //Debug
-
- //Debug
- logs($log_file, "UNAPPROVED : ".$GLOBALS['DISPLAY_UNAPPROVED']." get_unapproved : ".($get_unapproved?"1":"0")."\n");
- //Debug
- if ( $user != $login && ! empty ( $user ) ) {
- $u_url = "user=$user" . "&";
- } else {
- $u_url = '';
- }
-
- $u_url .= $info_type."&";
- //start the minical table for each month
- echo "\n<table class=\"minical\"";
- if ( $minical_id != '' ) {
- echo " id=\"$minical_id\"";
- }
- echo ">\n";
- $monthstart = mktime(2,0,0,$thismonth,1,$thisyear);
- $monthend = mktime(2,0,0,$thismonth + 1,0,$thisyear);
- if ( $SCRIPT == 'day.php' ) {
- $month_ago = date ( "Ymd",
- mktime ( 3, 0, 0, $thismonth - 1, $thisday, $thisyear ) );
- $month_ahead = date ( "Ymd",
- mktime ( 3, 0, 0, $thismonth + 1, $thisday, $thisyear ) );
- echo "<caption>$thisday</caption>\n";
- echo "<thead>\n";
- echo "<tr class=\"monthnav\"><th colspan=\"7\">\n";
- echo "<a title=\"" .
- translate("Previous") . "\" class=\"prev\" href=\"day.php?" . $u_url .
- "date=$month_ago$caturl\"><img src=\"leftarrowsmall.gif\" alt=\"" .
- translate("Previous") . "\" /></a>\n";
- echo "<a title=\"" .
- translate("Next") . "\" class=\"next\" href=\"day.php?" . $u_url .
- "date=$month_ahead$caturl\"><img src=\"rightarrowsmall.gif\" alt=\"" .
- translate("Next") . "\" /></a>\n";
- echo month_name ( $thismonth - 1 );
- if ( $showyear != '' ) {
- echo " $thisyear";
- }
- echo "</th></tr>\n<tr>\n";
- } else { //not day script
- //print the month name
- echo "<caption><a href=\"{$month_link}{$u_url}year=$thisyear&month=$thismonth\">";
- echo month_name ( $thismonth - 1 ) .
- ( $showyear ? " $thisyear" : "" );
- echo "</a></caption>\n";
- echo "<thead>\n<tr>\n";
- }
- //determine if the week starts on sunday or monday
- if ( $WEEK_START == "1" ) {
- $wkstart = get_monday_before ( $thisyear, $thismonth, 1 );
- } else {
- $wkstart = get_sunday_before ( $thisyear, $thismonth, 1 );
- }
- //print the headers to display the day of the week (sun, mon, tues, etc.)
- // if we're showing week numbers we need an extra column
- if ( $show_weeknums && $DISPLAY_WEEKNUMBER == 'Y' )
- echo "<th class=\"empty\"> </th>\n";
- //if the week doesn't start on monday, print the day
- if ( $WEEK_START == 0 ) echo "<th>" .
- weekday_short_name ( 0 ) . "</th>\n";
- //cycle through each day of the week until gone
- for ( $i = 1; $i < 7; $i++ ) {
- echo "<th>" . weekday_short_name ( $i ) . "</th>\n";
- }
- //if the week DOES start on monday, print sunday
- if ( $WEEK_START == 1 )
- echo "<th>" . weekday_short_name ( 0 ) . "</th>\n";
- //end the header row
- echo "</tr>\n</thead>\n<tbody>\n";
- for ($i = $wkstart; date("Ymd",$i) <= date ("Ymd",$monthend);
- $i += (24 * 3600 * 7) ) {
- echo "<tr>\n";
- if ( $show_weeknums && $DISPLAY_WEEKNUMBER == 'Y' ) {
- echo "<td class=\"weeknumber\"><a href=\"week.php?" . $u_url .
- "date=".date("Ymd", $i)."\">(" . week_number($i) . ")</a></td>\n";
- }
- for ($j = 0; $j < 7; $j++) {
- $date = $i + ($j * 24 * 3600);
- $dateYmd = date ( "Ymd", $date );
- $hasEvents = false;
- if ( $boldDays ) {
- $ev = get_entries ( $user, $dateYmd, $get_unapproved );
- if ( count ( $ev ) > 0 ) {
- $hasEvents = true;
- } else {
- $rep = get_repeating_entries ( $user, $dateYmd, $get_unapproved );
- if ( count ( $rep ) > 0 )
- $hasEvents = true;
- }
- }
- if ( $dateYmd >= date ("Ymd",$monthstart) &&
- $dateYmd <= date ("Ymd",$monthend) ) {
- echo "<td";
- $wday = date ( 'w', $date );
- $class = '';
- //add class="weekend" if it's saturday or sunday
- if ( $wday == 0 || $wday == 6 ) {
- $class = "weekend";
- }
- //if the day being viewed is today's date AND script = day.php
- if ( $dateYmd == $thisyear . $thismonth . $thisday &&
- $SCRIPT == 'day.php' ) {
- //if it's also a weekend, add a space between class names to combine styles
- if ( $class != '' ) {
- $class .= ' ';
- }
- $class .= "selectedday";
- }
- if ( $hasEvents ) {
- if ( $class != '' ) {
- $class .= ' ';
- }
- $class .= "hasevents";
- }
- if ( $class != '' ) {
- echo " class=\"$class\"";
- }
- if ( date ( "Ymd", $date ) == date ( "Ymd", $today ) ){
- echo " id=\"today\"";
- }
- echo "><a href=\"day.php?" .$u_url . "date=" . $dateYmd .
- "\">";
- echo date ( "d", $date ) . "</a></td>\n";
- } else {
- echo "<td class=\"empty\"> </td>\n";
- }
- } // end for $j
- echo "</tr>\n";
- } // end for $i
- echo "</tbody>\n</table>\n";
- }
- /**
- * Prints the HTML for one day's events in the month view.
- *
- * @param int $id Event ID
- * @param int $date Date of event (relevant in repeating events) in
- * YYYYMMDD format
- * @param int $time Time (in HHMMSS format)
- * @param int $duration Event duration in minutes
- * @param string $name Event name
- * @param string $description Long description of event
- * @param string $status Event status
- * @param int $pri Event priority
- * @param string $access Event access
- * @param string $event_owner Username of user associated with this event
- * @param int $event_cat Category of event for <var>$event_owner</var>
- *
- * @staticvar int Used to ensure all event popups have a unique id
- *
- * @uses build_event_popup
- */
- function print_entry ( $id, $date, $time, $duration,
- $name, $description, $status,
- $pri, $access, $event_owner, $event_cat=-1 ) {
- global $eventinfo, $login, $user, $PHP_SELF, $TZ_OFFSET;
- static $key = 0;
-
- global $layers;
- if ( $login != $event_owner && strlen ( $event_owner ) ) {
- $class = "layerentry";
- } else {
- $class = "entry";
- if ( $status == "W" ) $class = "unapprovedentry";
- }
- // if we are looking at a view, then always use "entry"
- if ( strstr ( $PHP_SELF, "view_m.php" ) ||
- strstr ( $PHP_SELF, "view_w.php" ) ||
- strstr ( $PHP_SELF, "view_v.php" ) ||
- strstr ( $PHP_SELF, "view_t.php" ) )
- $class = "entry";
- if($GLOBALS['type_param'] == 'group'){
- $info_type = "&type_param=group&group_param=".$GLOBALS['group_param'];
- }else{
- $info_type = "&type_param=user";
- }
- if ( $pri == 3 ) echo "<strong>";
- $popupid = "eventinfo-$id-$key";
- $key++;
- echo "<a title=\"" .
- translate("View this entry") . "\" class=\"$class\" href=\"view_entry.php?id=$id&date=$date".$info_type;
- if ( strlen ( $user ) > 0 )
- echo "&user=" . $user;
- echo "\" onmouseover=\"window.status='" .
- translate("View this entry") .
- "'; show(event, '$popupid'); return true;\" onmouseout=\"window.status=''; hide('$popupid'); return true;\">";
- $icon = "circle.gif";
- $catIcon = '';
- if ( $event_cat > 0 ) {
- $catIcon = "icons/cat-" . $event_cat . ".gif";
- if ( ! file_exists ( $catIcon ) )
- $c…
Large files files are truncated, but you can click here to view the full file