userid and $user_object->pass # # # ---------------------------------------------------- # # _ex_auth_get_user(&$user_object) # # set values in $user_object, return value is ignored # # $user_object as passed will have either, userid, or # id set. This function MUST set: # # $user_object->id - the unique id for this user # - must be a number > 0 # # $user_object->userid - the userid of this user, # - e.g. jsmith # # this function may optionally and is encurated to set: # # $user_object->name - the common name of ther user # - e.g. Joe Smith # # $user_object->email - the primary e-mail address of # - this user # # if no user is found, set all of the user's attributes # to null. # # -------------------------------------------------- # # _ex_auth_get_users_by_id($ids, $associative = false) # # return an array of users that have ids in $ids # # This should return an array of 'key' => values for id, # userid, name, and email. # # $.g. $users = array(); # # for each user in ($ids) # # $user[] = array('name' => $uname, 'userid' => $userid, 'id' => $uid, 'email' => $email); # # return $users; # # if $associative is true, the array returned must # have the users' ids as it's key. E.g. # # for each user in ($ids) # # $user[$uid] = array('name' => $uname, 'userid' => $userid, 'id' => $uid, 'email' => $email); # # return $users; # # # ------------------------------------------------ # # _ex_auth_search_users($key = false, $search_str, $anchor_start = false, $associative = false) # # search and return an array of users and their attributes. # the attributes that must be, or rmay be set follow the same # rules as _ex_auth_get_user # # where $key is the field to search: # # "name" - search users' names # "userid" - search userids # false (default) - search both userids and users' names # # $search_str is the string to search, this contains # no wildcard characters. If your authentication # method requires wildcards, this function is # expected to add them # # $anchor_start if this is true, a wildcard character # is only appended to the end of the string. If # false (default) prepend and append wildcards # # $associative indicates that the function must return # an array of associative arrays with the user's # id as the key. E.g. a searrch that returned 2 # users may set by: # # -- for each user returned from search.. # $users[$user['id']] = array('userid' => $user['unique_id'],'name' => $user['name']); # # return $users; # # ------------------------------------------------- # # _ex_auth_list_chars($key) # # search and return a list characters that there are # user entrires for. If your installation consists of 2 # users; bob and joe, this function would return an array # containing 'b' and 'j'. The characters retruned MUST be # lower case. # # $key is the field to search: # # "name" - search users' names # "userid" - search userid # # # If your installation is full of users that range from # a - z, you may just return an array containing a-z # using: # # return array_map("strtolower", $GLOBALS['_cal_alphabet']); # ######################################################### ###################################### # ### AUTHENTICATE A USER # ##################################### function _ex_auth_login(&$u) { global $nuke_opts; list($p) = _ex_auth_nuke_query("select user_password from {$nuke_opts['prefix']}_users where username = '". $u->userid ."'"); $p = $p['user_password']; # changed by timo; does it make sense? if($p != md5($u->pass) && $p != $u->pass) return 0; return 1; } ####################### # ### SET A SINGLE USER # ######################## function _ex_auth_get_user(&$u) { global $nuke_opts; # GET ALL VALUES FOR USER ########################### if($u->id) $cond = " user_id = ". $u->id; else if($u->userid) $cond = " username = '". $u->userid ."'"; else return 1; list($user) = _ex_auth_nuke_query("select username, name, user_id, user_email from {$nuke_opts['prefix']}_users where $cond"); $u->email = $user['user_email']; $u->name = $user['name']; $u->id = $user['user_id']; $u->userid = $user['username']; if($u->userid == $nuke_opts['admin']) $u->admin = 1; return 1; } ############################################### # ### GET USERS BY ID # ############################################### function _ex_auth_get_users_by_id($ids, $associative = false) { global $nuke_opts; if(!is_array($ids) || count($ids) < 1) return array(); $users = array(); $nusers = _ex_auth_nuke_query("select username, name, user_id, user_email from {$nuke_opts['prefix']}_users where user_id in (". join(",",$ids) .")"); # GRAB EACH USER ################### foreach($nusers as $nu) { if($associative) { $users[$nu['user_id']] = array('name' => $nu['name'], 'userid' => $nu['username'], 'email' => $nu['user_email']); } else { $users[] = array('id' => $nu['user_id'], 'name' => $nu['name'], 'userid' => $nu['username'], 'email' => $nu['user_email']); } } return $users; } ################################################ # ### RETURN A LIST OF USERS THAT MATCH A QUERY # ################################################ function _ex_auth_search_users($key = false, $search_str, $anchor_start = false, $associative = false) { global $nuke_opts; # SEARCH OPTIONS ####################### $search_str = ($anchor_start ? "" : "%") . $search_str ."%"; switch($key) { case 'name': $cond = " name like '{$search_str}'"; break; case 'userid': $cond = " username like '{$search_str}'"; break; default: $cond = " name like '{$search_str}' or username like '{$search_str}'"; } # always exclude anonymous user $cond .= " and user_id > 1"; # GET ALL ENTRIES THAT MATCH ################################ $nusers = _ex_auth_nuke_query("select username, name, user_id, user_email from {$nuke_opts['prefix']}_users where $cond"); $users = array(); # GRAB EACH USER ################### foreach($nusers as $nu) { if($associative) { $users[$nu['user_id']] = array('name' => $nu['name'], 'userid' => $nu['username'], 'email' => $nu['user_email']); } else { $users[] = array('id' => $nu['user_id'], 'name' => $nu['name'], 'userid' => $nu['username'], 'email' => $nu['user_email']); } } return $users; } ############################################################# # ### RETURN A LIST OF CHARACTERS THERE ENTRIES FOR # ############################################################ # if you have a large LDAP database and this is expensive, # you may simply return an array consisting of a-z as keys # return array( 'a' => 1, 'b' => 1, 'c' => 1, 'd' => 1 ... etc..) function _ex_auth_list_chars($key) { global $nuke_opts; $chars = array(); # SELECT USERNAME OR NAME $key = ($key == 'name' ? "name" : "username"); $nchars = _ex_auth_nuke_query("select distinct(lower({$key})) as 'c' from {$nuke_opts['prefix']}_users where user_id > 1"); # GRAB EACH CHAR ################### foreach($nchars as $nc) { if(!strlen(trim($nc['c']))) $nc['c'] = '_'; $chars[] = substr($nc['c'], 0, 1); } if(count($chars)) $chars = array_flip($chars); return $chars; } #################################### # ### INTERNAL SQL QUERY FUNCTION # #################################### function _ex_auth_nuke_query($sql = null) { global $nuke_opts; $nuke_opts['conn_id'] or _ex_auth_nuke_connect(); _ex_auth_nuke_set_db(); $nuke_opts['conn_id']->sql_query($sql); echo(mysql_error()); $rows = array(); while(($arr = $nuke_opts['conn_id']->sql_fetchrowset($res))) { $rows += $arr; } _ex_auth_nuke_set_db(false); return $rows; } ################################# # ### INTERNAL CONNECT FUNCTION # ################################ function _ex_auth_nuke_connect() { global $nuke_opts; $old_inc = set_include_path($nuke_opts['path']); $db = ''; include($nuke_opts['path'] ."/config.php"); require_once($nuke_opts['path'] ."/db/db.php"); set_include_path($old_inc); $nuke_opts['conn_id'] = &$db; $nuke_opts['prefix'] = $user_prefix; _ex_auth_nuke_set_db(false); } ############################### # ### INTERNAL SET DB FUNCTION # ############################### function _ex_auth_nuke_set_db($use_nuke = true) { global $nuke_opts; # MUST SWITCH BETWEEN DATABASES IF USING THE # SAME TPPE OF DB DRIVER ############################################## if(@constant("SQL_LAYER") == @constant("_CAL_SQL_DRIVER_")) { # MySQL check if(_CAL_SQL_DRIVER_ == "mysql") { mysql_select_db(($use_nuke ? $nuke_opts['conn_id']->dbname : _CAL_DBNAME_)); } } } #################################### ### GET/SET CONFIG OPTIONS ######## #################################### { $old_inc = set_include_path($nuke_opts['path']); include($nuke_opts['path'] ."/config.php"); set_include_path($old_inc); $GLOBALS['nuke_opts']['prefix'] = $user_prefix; } ?>