0"; dbi_query ( $sql ); } if (!isset($uid)) { $uid = 0; } $login = false; if (check_permissions($uid, "access webcal") && $PUBLIC_ACCESS == 'Y') { $login = '__public__'; } if (check_permissions($uid, "login to webcal")) { $login = $uid; } if ($app_same_db != '1') $c = dbi_connect($db_host, $db_login, $db_password, $db_database); /* Prints debug information print "
"; print_r( 'uid='.$uid."\nlogin=".$login."\n"); global $cached_users; print_r ($cached_users); print ""; exit; */ return $login; } // Checks a given Drupal user id to see if they have a certain permission // Precondition: Assumes that the database is already connected // Returns: true if the user has the permission, false if they dont function check_permissions($uid, $permission) { global $cached_users; global $app_permission_table, $app_users_roles_table; if ($uid == 1) { return true; } if (empty ($cached_users[$permission])) { $rids = array(); $res = dbi_query("SELECT rid, perm FROM $app_permission_table"); if ($res) { while ($row = dbi_fetch_row($res)) { if (strpos($row[1], $permission) !== FALSE) { $rids[] = $row[0]; } } dbi_free_result ( $res ); } $cached_users[$permission] = array (); //echo "role ids for '$permission'= "; //print_r ($rids); // check if anonymous users or all authenticated users have the permission if (in_array(1, $rids) || (in_array(2, $rids) && $uid != 0)) { $cached_users[$permission][] = "*"; } else { // Get all the user ids that have the permission and add them to the cached users array $rid_string = implode(',', $rids); if ($rid_string) { $res = dbi_query("SELECT uid FROM $app_users_roles_table WHERE rid IN ($rid_string)"); if ($res) { while ($row = dbi_fetch_row($res)) { $cached_users[$permission][] = $row[0]; } dbi_free_result ( $res ); } } } } foreach ($cached_users[$permission] as $certain_user) { if ($certain_user == $uid || $certain_user == "*") return true; } return false; } // Gets a list of Drupal users with permission to login to WebCalendar // Returns: An array containing information about all Drupal users who have // permission to login to WebCalendar function user_get_users () { global $PUBLIC_ACCESS, $PUBLIC_ACCESS_FULLNAME, $app_user_table, $app_session_table; global $app_host, $app_login, $app_pass, $app_db, $app_same_db; global $c, $db_host, $db_login, $db_password, $db_database; $count = 0; $ret = array (); if ( $PUBLIC_ACCESS == 'Y' ) $ret[$count++] = array ( 'cal_login' => '__public__', 'cal_lastname' => '', 'cal_firstname' => '', 'cal_is_admin' => 'N', 'cal_email' => '', 'cal_password' => '', 'cal_fullname' => $PUBLIC_ACCESS_FULLNAME ); // if application is in a separate db, we have to connect to it if ($app_same_db != '1') $c = dbi_connect($app_host, $app_login, $app_pass, $app_db); $sql = "SELECT uid, name, mail FROM $app_user_table WHERE uid <> '0' ORDER BY uid"; $res = dbi_query ( $sql ); if ( $res ) { while ( $row = dbi_fetch_row ( $res ) ) { list($fname, $lname) = split (" ",$row[1]); if (check_permissions($row[0], 'login to webcal')) { $ret[$count++] = array ( "cal_login" => $row[0], "cal_lastname" => $lname, "cal_firstname" => $fname, "cal_is_admin" => check_permissions($row[0], 'webcal admin'), "cal_email" => $row[2], "cal_fullname" => $row[1] ); } } dbi_free_result ( $res ); } // if application is in a separate db, we have to connect back to the webcal db if ($app_same_db != '1') $c = dbi_connect($db_host, $db_login, $db_password, $db_database); return $ret; } // Load info about a user (first name, last name, admin) and set globally. // params: // $user - user login // $prefix - variable prefix to use // Returns: true if no errors occured, false if db errors occured function user_load_variables ($login, $prefix) { global $PUBLIC_ACCESS_FULLNAME, $NONUSER_PREFIX; global $app_host, $app_login, $app_pass, $app_db, $app_user_table; global $c, $db_host, $db_login, $db_password, $db_database, $app_same_db; if ($NONUSER_PREFIX && substr($login, 0, strlen($NONUSER_PREFIX)) == $NONUSER_PREFIX) { nonuser_load_variables ($login, $prefix); return true; } if ( $login == '__public__' ) { $GLOBALS[$prefix . 'login'] = $login; $GLOBALS[$prefix . 'firstname'] = ''; $GLOBALS[$prefix . 'lastname'] = ''; $GLOBALS[$prefix . 'is_admin'] = 'N'; $GLOBALS[$prefix . 'email'] = ''; $GLOBALS[$prefix . 'fullname'] = $PUBLIC_ACCESS_FULLNAME; $GLOBALS[$prefix . 'password'] = ''; return true; } // if application is in a separate db, we have to connect to it if ($app_same_db != '1') $c = dbi_connect($app_host, $app_login, $app_pass, $app_db); $res = dbi_query ("SELECT uid, name, mail FROM $app_user_table WHERE uid = $login"); if ($res) { if ($row = dbi_fetch_row($res)) { list($fname, $lname) = split (" ",$row[1]); $GLOBALS[$prefix . 'login'] = $login; $GLOBALS[$prefix . 'firstname'] = $fname; $GLOBALS[$prefix . 'lastname'] = $lname; $GLOBALS[$prefix . 'is_admin'] = check_permissions($row[0], 'webcal admin'); $GLOBALS[$prefix . 'email'] = $row[2]; $GLOBALS[$prefix . 'fullname'] = $row[1]; } dbi_free_result($res); } else { $error = db_error(); return false; } // if application is in a separate db, we have to connect back to the webcal db if ($app_same_db != '1') $c = dbi_connect($db_host, $db_login, $db_password, $db_database); return true; } // Redirect the user to the application's login screen function app_login_screen($return = '') { global $app_url, $app_in_iframe; if (empty($return) && $app_in_iframe) { $return = "webcal"; } if (!empty($return)) { $return = "?destination=$return"; } $login_page = $app_url . "user" . $return; if ($app_in_iframe) { echo ""; exit; } header("Location: $login_page"); exit; } /********************************************************************* * * Functions that are unchanged from other user-app files * ********************************************************************/ // Delete a user from the webcalendar tables. (NOT from the application) // We assume that we've already checked to make sure this user doesn't // have events still in the database. // params: // $user - user to delete function user_delete_user ($user) { global $error; $error = 'User admin not supported.'; return false; } // Functions we don't use with this file: function user_update_user ( $user, $firstname, $lastname, $email, $admin ) { global $error; $error = 'User admin not supported.'; return false; } function user_update_user_password ( $user, $password ) { global $error; $error = 'User admin not supported.'; return false; } function user_add_user ( $user, $password, $firstname, $lastname, $email, $admin ) { global $error; $error = 'User admin not supported.'; return false; } ?>