0 ) { $can_view = true; $is_my_event = true; } dbi_free_result ( $res ); } if ( ($login != "__public__") && ($public_access_others == "Y") ) { $can_view = true; } if ( ! $can_view ) { $check_group = false; // if not a participant in the event, must be allowed to look at // other user's calendar. if ( $login == "__public__" ) { if ( $public_access_others == "Y" ) { $check_group = true; } } else { if ( $allow_view_other == "Y" ) { $check_group = true; } } // If $check_group is true now, it means this user can look at the // event only if they are in the same group as some of the people in // the event. // This gets kind of tricky. If there is a participant from a different // group, do we still show it? For now, the answer is no. // This could be configurable somehow, but how many lines of text would // it need in the admin page to describe this scenario? Would confuse // 99.9% of users. // In summary, make sure at least one event participant is in one of // this user's groups. $my_users = get_my_users (); if ( is_array ( $my_users ) ) { $sql = "SELECT webcal_entry.cal_id FROM webcal_entry, " . "webcal_entry_user WHERE webcal_entry.cal_id = " . "webcal_entry_user.cal_id AND webcal_entry.cal_id = $id " . "AND webcal_entry_user.cal_login IN ( "; for ( $i = 0; $i < count ( $my_users ); $i++ ) { if ( $i > 0 ) { $sql .= ", "; } $sql .= "'" . $my_users[$i]['cal_login'] . "'"; } $sql .= " )"; $res = dbi_query ( $sql ); if ( $res ) { $row = dbi_fetch_row ( $res ); if ( $row && $row[0] > 0 ) { $can_view = true; } dbi_free_result ( $res ); } } // If we didn't indicate we need to check groups, then this user // can't view this event. if ( ! $check_group ) { $can_view = false; } } } // If they still cannot view, make sure they are not looking at a nonuser // calendar event where the nonuser is the _only_ participant. if ( empty ( $error ) && ! $can_view && ! empty ( $nonuser_enabled ) && $nonuser_enabled == 'Y' ) { $nonusers = get_nonuser_cals (); $nonuser_lookup = array (); for ( $i = 0; $i < count ( $nonusers ); $i++ ) { $nonuser_lookup[$nonusers[$i]['cal_login']] = 1; } $sql = "SELECT cal_login FROM webcal_entry_user " . "WHERE cal_id = $id AND cal_status in ('A','W')"; $res = dbi_query ( $sql ); $found_nonuser_cal = false; $found_reg_user = false; if ( $res ) { while ( $row = dbi_fetch_row ( $res ) ) { if ( ! empty ( $nonuser_lookup[$row[0]] ) ) { $found_nonuser_cal = true; } else { $found_reg_user = true; } } dbi_free_result ( $res ); } // Does this event contain only nonuser calendars as participants? // If so, then grant access. if ( $found_nonuser_cal && ! $found_reg_user ) { $can_view = true; } } if ( empty ( $error ) && ! $can_view ) { $error = translate ( "You are not authorized" ); } if ( ! empty ( $year ) ) { $thisyear = $year; } if ( ! empty ( $month ) ) { $thismonth = $month; } $pri[1] = translate("Low"); $pri[2] = translate("Medium"); $pri[3] = translate("High"); $unapproved = FALSE; // Make sure this is not a continuation event. // If it is, redirect the user to the original event. $ext_id = -1; if ( empty ( $error ) ) { $res = dbi_query ( "SELECT cal_ext_for_id FROM webcal_entry " . "WHERE cal_id = $id" ); if ( $res ) { if ( $row = dbi_fetch_row ( $res ) ) { $ext_id = $row[0]; } dbi_free_result ( $res ); } else { // db error... ignore it, I guess. } } if ( $ext_id > 0 ) { $url = "view_entry.php?id=$ext_id"; if ( $date != "" ) { $url .= "&date=$date"; } if ( $user != "" ) { $url .= "&user=$user"; } if ( $cat_id != "" ) { $url .= "&cat_id=$cat_id"; } do_redirect ( $url ); } print_header(); if ( ! empty ( $error ) ) { echo "