📄 user.class
字号:
"AND preference_name='$preference_name'"); if (db_affected_rows($result) < 1) { //echo db_error(); $result=db_query("INSERT INTO user_preferences (user_id,preference_name,preference_value,set_date) ". "VALUES ('". $this->getID() ."','$preference_name','$value','". time() ."')"); return $result; } } /** * getPreference - get a specific preference. * * @param string The unique field name for this preference. * @return the preference string or false on failure. */ function getPreference($preference_name) { $preference_name=strtolower(trim($preference_name)); /* First check to see if we have already fetched the preferences */ if ($this->user_pref) { //echo "\n\nPrefs were fetched already"; if ($this->user_pref["$preference_name"]) { //we have fetched prefs - return part of array return $this->user_pref["$preference_name"]; } else { //we have fetched prefs, but this pref hasn't been set return false; } } else { //we haven't returned prefs - go to the db $result=db_query("SELECT preference_name,preference_value FROM user_preferences ". "WHERE user_id='". $this->getID() ."'"); if (db_numrows($result) < 1) { //echo "\n\nNo Prefs Found"; return false; } else { $pref=array(); //iterate and put the results into an array for ($i=0; $i<db_numrows($result); $i++) { $pref["".db_result($result,$i,'preference_name').""]=db_result($result,$i,'preference_value'); } $this->user_pref =& $pref; if ($this->user_pref["$preference_name"]) { //we have fetched prefs - return part of array return $this->user_pref["$preference_name"]; } else { //we have fetched prefs, but this pref hasn't been set return false; } } } } /** * setUpUnixUID - Sets up this user's unix_uid for shell access. * * @return boolean success. */ function setUpUnixUID() { global $sys_database_type; if ($this->getUnixUID() > 1) { // // already have unix_uid // return true; } //get the next unix uid /* hack to simulate sequences in mysql */ if ($sys_database_type=='mysql') { $res=db_query("INSERT INTO unix_uids (id) values ('')"); $unixid=db_insertid($res,'unix_uids','id'); db_free_result($res); } else { $res=db_query("SELECT nextval('unix_uid_seq')"); $unixid=db_result($res,0,0); db_free_result($res); } if (!$unixid) { $this->setError('ERROR - Could Not Get Next Unix UID'); return false; } else { $res=db_query(" UPDATE users SET unix_status='A',unix_uid='$unixid' WHERE user_id='". $this->getID()."' "); if (!$res || db_affected_rows($res) < 1) { $this->setError('ERROR - Could Not Update User Account Flags: '.db_error()); return false; } else { $this->data_array['unix_uid'] = $unixid; return true; } } } /** * setPasswd - Changes user's password. * * @param string The plaintext password. * @return boolean success. */ function setPasswd($passwd) { if (!account_pwvalid($passwd)) { $this->setError('Error: '.$GLOBALS['register_error']); return false; } db_begin(); $unix_pw = account_genunixpw($passwd); $res=db_query(" UPDATE users SET user_pw='" . md5($passwd) . "', unix_pw='$unix_pw' WHERE user_id='".$this->getID()."' "); if (!$res || db_affected_rows($res) < 1) { $this->setError('ERROR - Could Not Change User Password: '.db_error()); db_rollback(); return false; } else { // Now change LDAP password, but only if corresponding // entry exists (i.e. if user have shell access) if (sf_ldap_check_user($this->getID())) { if (!sf_ldap_user_set_attribute($this->getID(),"userPassword",'{crypt}'.$unix_pw)) { $this->setError(sf_ldap_get_error_msg()); db_rollback(); return false; } } } db_commit(); return true; } /** * usesRatings - whether user participates in rating system. * * @return boolean success. */ function usesRatings() { return !$this->data_array['block_ratings']; } function getPlugins() { if (!isset($this->plugins_data)) { $this->plugins_data = array () ; $sql="SELECT user_plugin.plugin_id, plugins.plugin_name FROM user_plugin, plugins WHERE user_plugin.user_id=".$this->getID()." AND user_plugin.plugin_id = plugins.plugin_id" ; $res=db_query($sql); $rows = db_numrows($res); for ($i=0; $i<$rows; $i++) { $plugin_id = db_result($res,$i,'plugin_id'); $this->plugins_data[$plugin_id] = db_result($res,$i,'plugin_name'); } } return $this->plugins_data ; } function usesPlugin($pluginname) { $plugins_data = $this->getPlugins() ; foreach ($plugins_data as $p_name) { if ($p_name == $pluginname) { return true ; } } return false ; } function setPluginUse($pluginname, $val=true) { if ($val == $this->usesPlugin($pluginname)) { // State is already good, returning return true ; } $sql="SELECT plugin_id FROM plugins WHERE plugin_name = '" . $pluginname . "'" ; $res=db_query($sql); $rows = db_numrows($res); if ($rows == 0) { // Error: no plugin by that name return false ; } $plugin_id = db_result($res,0,'plugin_id'); // Invalidate cache unset ($this->plugins_data) ; if ($val) { $sql="INSERT INTO user_plugin (user_id, plugin_id) VALUES (". $this->getID() . ", ". $plugin_id .")" ; $res=db_query($sql); return $res ; } else { $sql="DELETE FROM user_plugin WHERE user_id = ". $this->getID() . " AND plugin_id = ". $plugin_id ; $res=db_query($sql); return $res ; } } /** * getMailingsPrefs - Get activity status for one of the site mailings. * * @param string The id of mailing ('mail_va' for community mailings, 'mail_siteupdates' for site mailings) * @return boolean success. */ function getMailingsPrefs($mailing_id) { if ($mailing_id=='va') { return $this->data_array['mail_va']; } else if ($mailing_id=='site') { return $this->data_array['mail_siteupdates']; } else { return 0; } } /** * unsubscribeFromMailings - Disable email notifications for user. * * @param boolean If false, disable general site mailings, else - all. * @return boolean success. */ function unsubscribeFromMailings($all=false) { $res1 = $res2 = $res3 = true; $res1 = db_query(" UPDATE users SET mail_siteupdates=0, mail_va=0 WHERE user_id='".$this->getID()."' "); if ($all) { $res2 = db_query(" DELETE FROM forum_monitored_forums WHERE user_id='".$this->getID()."' "); $res3 = db_query(" DELETE FROM filemodule_monitor WHERE user_id='".$this->getID()."' "); } return $res1 && $res2 && $res3; } /** * getThemeID - get the theme_id for this user from the theme_prefs table. * * @return int The theme_id. */ function getThemeID() { if (!$this->theme_id) { $res=db_query("SELECT * FROM theme_prefs WHERE user_id='".$this->getID()."'"); if (!$res || db_numrows($res) < 1) { $this->theme_id=1; } else { $this->theme_id=db_result($res,0,'user_theme'); } } return $this->theme_id; } /** * setThemeID - set the theme_id for this user in the theme_prefs table. * * @return boolean success. */ function setThemeID($id) { db_query("DELETE FROM theme_prefs WHERE user_id='".$this->getID()."'"); $result=db_query("INSERT INTO theme_prefs (user_id,user_theme) VALUES ('".$this->getID()."','$id')"); if (!$result || db_affected_rows($result) < 1) { $this->setError('Error inserting theme_pre: '.db_error()); return false; } else { return true; } } /** * getThemeID - get the theme_id for this user from the theme_prefs table. * * @return int The theme_id. */ function setUpTheme() { if (!$this->theme) { $res=db_query("SELECT * FROM themes WHERE theme_id='".$this->getThemeID()."'"); $this->theme=db_result($res,0,'dirname'); $GLOBALS['sys_theme']=db_result($res,0,'dirname'); } return $this->theme; }}/* EVERYTHING BELOW HERE IS DEPRECATED DO NOT USE FOR ANY NEW CODE*//** * user_ismember() - DEPRECATED; DO NOT USE! * * @param int The Group ID * @param int The Type * @deprecated * */function user_ismember($group_id,$type=0) { if (!session_loggedin()) { return false; } $project =& group_get_object($group_id); if (!$project || !is_object($project)) { return false; } $perm =& $project->getPermission( session_get_user() ); if (!$perm || !is_object($perm) || !$perm->isMember()) { return false; } $type=strtoupper($type); switch ($type) { case 'P2' : { //pm admin return $perm->isPMAdmin(); break; } case 'F2' : { //forum admin return $perm->isForumAdmin(); break; } case '0' : { //just in this group return $perm->isMember(); break; } case 'A' : { //admin for this group return $perm->isAdmin(); break; } case 'D1' : { //document editor return $perm->isDocEditor(); break; } default : { //fubar request return false; } } return false;}/** * user_getname() - DEPRECATED; DO NOT USE! * * @param int The User ID * @deprecated * */function user_getname($user_id = false) { // use current user if one is not passed in if (!$user_id) { if (session_loggedin()) { $user=&user_get_object(user_getid()); if ($user) { return $user->getUnixName(); } else { return 'Error getting user'; } } else { return 'No User Id'; } } else { $user=&user_get_object($user_id); if ($user) { return $user->getUnixName(); } else { return 'Invalid User'; } }}// Local Variables:// mode: php// c-file-style: "bsd"// End:?>
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -