⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 group.class

📁 GForge 3.0 协作开发平台 支持CVS, mailing lists, bug tracking, message boards/forums, task management, perman
💻 CLASS
📖 第 1 页 / 共 3 页
字号:
						return false;					}				} else {					//					//	User already had unix account					//					if (!sf_ldap_check_create_user($form_newuid)) {						$this->setError(sf_ldap_get_error_msg());						db_rollback();						return false;					}				}				//				//	Create this user's row in the user_group table				//				$res=db_query("INSERT INTO user_group 					(user_id,group_id,admin_flags,forum_flags,project_flags,					doc_flags,cvs_flags,member_role,release_flags,artifact_flags)					VALUES ('$form_newuid','". $this->getID() ."','','0','0','0','1','100','0','0')");				//verify the insert worked				if (!$res || db_affected_rows($res) < 1) {					$this->setError('ERROR: Could Not Add User To Group');					db_rollback();					return false;				}				//				//	set up their ldap info				//				if (!sf_ldap_group_add_user($this->getID(),$form_newuid)) {					$this->setError(sf_ldap_get_error_msg());					db_rollback();					return false;				}			} else {				//				//	user was already a member				//	make sure they are set up with a unix_uid,				//	LDAP entry and membership				//				$user=&user_get_object($form_newuid,$res_newuser);				if (!$user->setUpUnixUID()) {					$this->setError('ERROR: could not set up unix_uid for user: '.$user->getErrorMessage());					db_rollback();					return false;				} else {					$user->fetchData($user->getID());					if (!sf_ldap_check_create_user($form_newuid)) {						$this->setError(sf_ldap_get_error_msg());						db_rollback();						return false;					}						if (!sf_ldap_group_add_user($this->getID(),$form_newuid)) {						$this->setError(sf_ldap_get_error_msg());						db_rollback();						return false;					}					db_commit();					return true;				}			}		} else {			//			//	user doesn't exist			//			$this->setError('ERROR: User does not exist on SourceForge');			db_rollback();			return false;		}		//		//	audit trail		//		$this->addHistory('Added User',$user_unix_name);		db_commit();		return true;	}	/**	 *  removeUser - controls removing a user from a group.	 * 	 *  Users can remove themselves.	 *	 *  @param	int		The ID of the user to remove.	 *	@return	boolean	success.	 */ 	function removeUser($user_id) {		if ($user_id==user_getid()) {			//users can remove themselves			//everyone else must be a project admin		} else {			$perm =& $this->getPermission( session_get_user() );			if (!$perm || !is_object($perm) || !$perm->isAdmin()) {				$this->setError('You Are Not An Admin For This Group');				return false;			}		}				$res=db_query("SELECT * FROM user_group ".			"WHERE group_id='".$this->getID()."' AND user_id='$user_id' AND admin_flags = 'A'");		if (db_numrows($res) > 0) {			$this->setError('Cannot remove admin');			return false;		}		db_begin();		$res=db_query("DELETE FROM user_group ".			"WHERE group_id='".$this->getID()."' AND user_id='$user_id' AND admin_flags <> 'A'");		if (!$res || db_affected_rows($res) < 1) {			$this->setError('ERROR: DB: User not removed.');			db_rollback();			return false;		} else {			//			//	remove them from artifact types			//			db_query("DELETE FROM artifact_perm 				WHERE group_artifact_id 				IN (SELECT group_artifact_id 				FROM artifact_group_list 				WHERE group_id='".$this->getID()."') 				AND user_id='$user_id'");			if (!sf_ldap_group_remove_user($this->getID(),$user_id)) {				$this->setError(sf_ldap_get_error_msg());				db_rollback();				return false;			}			//audit trail			$this->addHistory('removed user',$user_id);		}		db_commit();		return true;	}	/**	 	 *  updateUser - controls updating a user's perms in this group.	 *	 *  @param	int		The ID of the user.	 *  @param	string	The admin flag for the user.	 *  @param	int		The forum flag for the user.	 *  @param	int		The project flag for the user.	 *  @param	int		The doc flag for the user.	 *  @param	int		The CVS flag for the user.	 *  @param	int		The release flag for the user.	 *	@param	int		The member role for the user.	 *	@param	int		The artifact flags for the user.	 *	@return	boolean	success.	 */	 	function updateUser($user_id,$admin_flags='',$forum_flags=0,$project_flags=1,$doc_flags=0,$cvs_flags=1,$release_flags=1,$member_role=100,$artifact_flags=0) {	$perm =& $this->getPermission( session_get_user() );	if (!$perm || !is_object($perm) || !$perm->isAdmin()) {			$this->setError('You Are Not An Admin For This Group');			return false;		}		if (user_getid() == $user_id) {			$admin_flags='A';		}		$release_flags = ((!$release_flags) ? "0" : $release_flags);		db_begin();		$res = db_query("UPDATE user_group SET			admin_flags='$admin_flags',			forum_flags='$forum_flags',			project_flags='$project_flags', 			doc_flags='$doc_flags', 			cvs_flags='$cvs_flags', 			release_flags='$release_flags', 			artifact_flags='$artifact_flags', 			member_role='$member_role' 			WHERE user_id='$user_id' AND group_id='". $this->getID() ."'");		if (!$res || db_affected_rows($res) < 1) {			$this->setError('ERROR: Could Not Change Member Permissions: '.db_error());			db_rollback();			return false;		}		//		//	If user acquired admin access to CVS,		//	one to be given normal shell on CVS machine,		//	else - restricted.		//		if ($cvs_flags>1) {			if (!sf_ldap_user_set_attribute($user_id,"debSfCvsShell","/bin/bash")) {				$this->setError(sf_ldap_get_error_msg());				db_rollback();				return false;			}		} else {			if (!sf_ldap_user_set_attribute($user_id,"debSfCvsShell","/bin/cvssh")) {				$this->setError(sf_ldap_get_error_msg());				db_rollback();				return false;			}		}		//		//	If user acquired at least commit access to CVS,		//	one to be promoted to CVS group, else, demoted.		//		if ($cvs_flags>0) {			if (!sf_ldap_group_add_user($this->getID(),$user_id,1)) {				$this->setError(sf_ldap_get_error_msg());				db_rollback();				return false;			}		} else {			if (!sf_ldap_group_remove_user($this->getID(),$user_id,1)) {				$this->setError(sf_ldap_get_error_msg());				db_rollback();				return false;			}		}		db_commit();		return true;	}	/**	 *	addHistory - Makes an audit trail entry for this project.	 *	 *  @param	string	The name of the field.	 *  @param	string	The Old Value for this $field_name.	 *	@return database result handle.	 *	@access public.	 */	function addHistory($field_name, $old_value) {		$sql="			INSERT INTO group_history(group_id,field_name,old_value,mod_by,date) 			VALUES ('". $this->getID() ."','$field_name','$old_value','". user_getid() ."','".time()."')		";		return db_query($sql);	}		  	/**	 *	activateUsers - Make sure that group members have unix accounts.	 *	 *	Setup unix accounts for group members. Can be called even	 *	if members are already active. 	 *	 *	@access private.	 */	function activateUsers() {		/*			Activate member(s) of the project		*/		$member_res = db_query("			SELECT *			FROM users,user_group			WHERE user_group.group_id='".$this->getID()."'			AND users.user_id=user_group.user_id		");		$rows = db_numrows($member_res);		if ($rows > 0) {			for ($i=0; $i<$rows; $i++) {				$member =& user_get_object(db_result($member_res,$i,'user_id'));				if (!$member || !is_object($member)) {					$this->setError('Error getting member object');					return false;				} else if ($member->isError()) {					$this->setError('Error getting member object: '.$member->getErrorMessage());					return false;				}				if (!$this->addUser($member->getUnixName())) {					return false;				}			}		 }		 return true;	}	/**	 *	approve - Approve pending project.	 *	 *	@param	object	The User object who is doing the updating.	 *	@access public	 */	function approve(&$user) {		if ($this->getStatus()=='A') {			$this->setError("Group already active");			return false;		}		db_begin();		// Step 1: Activate group and create LDAP entries		if (!$this->setStatus($user, 'A')) {			db_rollback();			return false;		}		//		//		//	Forum Integration		//		//		// Step 2: Setup forums for this group		$f = new Forum($this);		if (!$f->create('Open Discussion','General Discussion',1,'',1,0)) {			$this->setError($f->getErrorMessage());			db_rollback();			return false;		}		$f = new Forum($this);		if (!$f->create('Help','Get Public Help',1,'',1,0)) {			$this->setError($f->getErrorMessage());			db_rollback();			return false;		}		$f = new Forum($this);		if (!$f->create('Developers','Project Developer Discussion',0,'',1,0)) {			$this->setError($f->getErrorMessage());			db_rollback();			return false;		}		//		//		//	Doc Mgr Integration		//		//		$dg = new DocumentGroup($this);		if (!$dg->create('Uncategorized Submissions')) {			$this->setError($dg->getErrorMessage());			db_rollback();			return false;		}		//		//		//	FRS integration		//		//		// Step 4: Setup default filerelease package		$frs = new FRSPackage($this);		if (!$frs->create($this->getUnixName())) {			$this->setError($frs->getErrorMessage());			return false;		}		db_commit();		$this->sendApprovalEmail();		$this->addHistory('approved', 'x');		return true;	}	/**	 *	sendApprovalEmail - Send new project email.	 *	 *	@return	boolean	success.	 *	@access public.	 */	function sendApprovalEmail() {		global $Language;		$res_admins = db_query("			SELECT users.user_name,users.email			FROM users,user_group			WHERE users.user_id=user_group.user_id			AND user_group.group_id='".$this->getID()."'			AND user_group.admin_flags='A'		");		if (db_numrows($res_admins) < 1) {			$this->setEror("Group does not have any administrators.");			return false;		}		// send one email per admin		while ($row_admins = db_fetch_array($res_admins)) {			//																			   $1					  $2					$3							  $4						  $5						$6			$message=stripcslashes($Language->getText('classgroup', 'acceptedproject', array($this->getPublicName(), $this->getUnixName(), $GLOBALS['sys_default_domain'], $GLOBALS['sys_shell_host'], $GLOBALS['sys_cvs_host'], $this->getID(), $GLOBALS['sys_name'])));				util_send_message($row_admins['email'], $Language->getText('classgroup', 'acceptedprojecttitle', array($GLOBALS['sys_name'])), $message);		}		return true;	}	/**	 *	sendRejectionEmail - Send project rejection email.	 *	 *	This function sends out a rejection message to a user who	 *	registered a project.	 *	 *	@param	int	The id of the response to use.	 *	@param	string	The rejection message.	 *	@return completion status.	 *	@access public.	 */	function sendRejectionEmail($response_id, $message="zxcv") {		global $Language;		// Get the email addr of the user who wants to register the project.		$email = db_result(db_query("			SELECT u.email AS email			FROM users u, user_group ug			WHERE ug.group_id='".$this->getID()."'			AND u.user_id=ug.user_id;		"), 0, "email");			$response=stripcslashes($Language->getText('classgroup', 'rejectedproject', array($this->getPublicName(), $this->getUnixName(), $GLOBALS['sys_name'])));		// Check to see if they want to send a custom rejection response		if ($response_id == 0) {			$response .= $message;		} else {			$response .= db_result(db_query("				SELECT response_text				FROM canned_responses				WHERE response_id='$response_id'			"), 0, "response_text");		}		util_send_message($email, $Language->getText('classgroup', 'rejectedprojecttitle', array($GLOBALS['sys_name'])), $response);		return true;	}	/**	 *	sendNewProjectNotificationEmail - Send new project notification email.	 *	 *	This function sends out a notification email to the	 *	SourceForge admin user when a new project is	 *	submitted.	 *	 *	@return	boolean	success.	 *	@access public.	 */	function sendNewProjectNotificationEmail() {		global $Language;	  // Get the admin(s) email	  $admin_email='';	  //$res = db_query("SELECT email AS admin_email		  //				FROM users		  //			   WHERE user_name='admin';");	  $res = db_query("SELECT users.email AS admin_email	 			FROM users,user_group				WHERE group_id=1 				AND user_group.admin_flags='A'				AND users.user_id=user_group.user_id;");	  if (db_numrows($res) < 1) {		$this->setError("There is no administrator to send the mail.");		return false;	  } else {	  	for ($i=0; $i<db_numrows($res) ; $i++) {			$admin_email .= db_result($res,$i,'admin_email').', ';	  	}	  }	  // Get the email of the user who wants to register the project	  $res = db_query("SELECT u.email AS email						   FROM users u, user_group ug						   WHERE ug.group_id='".$this->getID()."' AND u.user_id=ug.user_id;");	  if (db_numrows($res) < 1) {		$this->setError("Cound not find user who has submitted the project.");		return false;	  } else {		$email = db_result($res, 0, "email");	  }	  	  $message=stripcslashes($Language->getText('classgroup', 'newprojectnotification', array($GLOBALS['sys_name'], $this->getPublicName(), $this->getRegistrationPurpose(), $this->getLicense(), $GLOBALS['sys_default_domain'])));	  util_send_message($admin_email, $Language->getText('classgroup', 'newprojectnotificationtitle', array($GLOBALS['sys_name'])), $message, $email);	  return true;	}}/** * group_getname() - get the group name * * @param	   int	 The group ID * @deprecated * */function group_getname ($group_id = 0) {	$grp = &group_get_object($group_id);	if ($grp) {		return $grp->getPublicName();	} else {		return 'Invalid';	}}/** * group_getunixname() - get the unixname for a group * * @param	   int	 The group ID * @deprecated * */function group_getunixname ($group_id) {	$grp = &group_get_object($group_id);	if ($grp) {		return $grp->getUnixName();	} else {		return 'Invalid';	}}/** * group_get_result() - Get the group object result ID. * * @param	   int	 The group ID * @deprecated * */function &group_get_result($group_id=0) {	$grp = &group_get_object($group_id);	if ($grp) {		return $grp->getData();	} else {		return 0;	}}?>

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -