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

📄 group.class

📁 GForge 3.0 协作开发平台 支持CVS, mailing lists, bug tracking, message boards/forums, task management, perman
💻 CLASS
📖 第 1 页 / 共 3 页
字号:
<?php   /** *	Group object * *	Sets up database results and preferences for a group and abstracts this info. * *	Foundry.class and Project.class call this. * *	Project.class contains all the deprecated API from the old group.php file * *	DEPENDS on user.php being present and setup properly * *	GENERALLY YOU SHOULD NEVER INSTANTIATE THIS OBJECT DIRECTLY *	USE group_get_object() to instantiate properly * * @version   $Id: Group.class,v 1.22 2001/07/09 23:31:20 pfalcon Exp $ * @author Tim Perdue <tperdue@valinux.com> * @date 2000-08-28 * * This file is part of GForge. * * GForge is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * * GForge is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with GForge; if not, write to the Free Software * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA */require_once('common/tracker/ArtifactTypes.class');require_once('common/forum/Forum.class');require_once('common/frs/FRSPackage.class');require_once('common/docman/DocumentGroup.class');require_once('www/include/BaseLanguage.class');$GROUP_OBJ=array();/** *  group_get_object() - Get the group object. * *  group_get_object() is useful so you can pool group objects/save database queries *  You should always use this instead of instantiating the object directly. * *  You can now optionally pass in a db result handle. If you do, it re-uses that query *  to instantiate the objects. * *  IMPORTANT! That db result must contain all fields *  from groups table or you will have problems * *  @param		int		Required *  @param		int		Result set handle ("SELECT * FROM groups WHERE group_id=xx") *  @return a group object or false on failure */function &group_get_object($group_id,$res=false) {	//create a common set of group objects	//saves a little wear on the database	//automatically checks group_type and 	//returns appropriate object		global $GROUP_OBJ;	if (!isset($GROUP_OBJ["_".$group_id."_"])) {		if ($res) {			//the db result handle was passed in		} else {			$res=db_query("SELECT * FROM groups WHERE group_id='$group_id'");		}		if (!$res || db_numrows($res) < 1) {			$GROUP_OBJ["_".$group_id."_"]=false;		} else {			/*				check group type and set up object			*/			if (db_result($res,0,'type')==1) {				//project				$GROUP_OBJ["_".$group_id."_"]= new Group($group_id,$res);			} else {				//invalid				$GROUP_OBJ["_".$group_id."_"]=false;			}		}	}	return $GROUP_OBJ["_".$group_id."_"];}function &group_get_object_by_name($groupname) {	$res=db_query("SELECT * FROM groups WHERE unix_group_name='$groupname'");	return group_get_object(db_result($res,0,'group_id'),$res);}class Group extends Error {	/**	 * Associative array of data from db.	 * 	 * @var array $data_array.	 */	var $data_array;	/**	 * Permissions data row from db.	 * 	 * @var array $perm_data_array.	 */	var $perm_data_array;	/**	 * Whether the use is an admin/super user of this project.	 *	 * @var bool $is_admin.	 */	var $is_admin;	/**	 * Artifact types result handle.	 * 	 * @var int $types_res.	 */	var $types_res;	/**	 * Associative array of data for plugins.	 * 	 * @var array $plugins_array.	 */	var $plugins_array;	/**	 *	Group - Group object constructor - use group_get_object() to instantiate.	 *	 *	@param	int		Required - group_id of the group you want to instantiate.	 *	@param	int		Database result from select query.	 */	function Group($id=false, $res=false) {		$this->Error();		if (!$id) {			//setting up an empty object			//probably going to call create()			return true;		}		if (!$res) {			if (!$this->fetchData($id)) {				return false;			}		} else {			if (db_numrows($res) < 1) {				//function in class we extended				$this->setError('Group Not Found');				$this->data_array=array();				return false;			} else {				//set up an associative array for use by other functions				db_reset_result($res);				$this->data_array =& db_fetch_array($res);			}		}////	Need to add a check if this is not public, verify user is logged in and isMember//		return true;	}	/**	 *	fetchData - May need to refresh database fields if an update occurred.	 *	 *	@param	int	The group_id.	 */	function fetchData($group_id) {		$res = db_query("SELECT * FROM groups WHERE group_id='$group_id'");		if (!$res || db_numrows($res) < 1) {			$this->setError('fetchData():: '.db_error());			return false;		}		$this->data_array =& db_fetch_array($res);		return true;	}	/**	 *	create - Create new group.	 *	 *	This method should be called on empty Group object.	 *  	 *  @param	object	The User object.	 *  @param	string	The full name of the user.	 *  @param	string	The Unix name of the user.	 *  @param	string	The new group description.	 *  @param	int	The ID of the license to use.	 *  @param	string	The 'other' license to use if any.	 *  @param	string	The purpose of the group.	 */	function create(&$user, $full_name, $unix_name, $description, $license, $license_other, $purpose) {		// $user is ignored - anyone can create pending group		if ($this->getID()!=0) {			$this->setError("Group::create: Group object already exists");			return false;		}		srand((double)microtime()*1000000);		$random_num = rand(0,1000000);		db_begin();		$res = db_query("			INSERT INTO groups (				group_name,				is_public,				unix_group_name,				short_description,				http_domain,				homepage,				status,				unix_box,				cvs_box,				license,				register_purpose,				register_time,				license_other,				rand_hash			)			VALUES (				'".htmlspecialchars($full_name)."',				1,				'$unix_name',				'".htmlspecialchars($description)."',				'$unix_name.".$GLOBALS['sys_default_domain']."',				'$unix_name.".$GLOBALS['sys_default_domain']."',				'P',				'shell1',				'cvs1',				'$license',				'".htmlspecialchars($purpose)."',				".time().",				'".htmlspecialchars($license_other)."',				'".md5($random_num)."'			)		");		if (!$res || db_affected_rows($res) < 1) {			$this->setError('ERROR: Could not create group: '.db_error());			db_rollback();			return false;		}		$id = db_insertid($res, 'groups', 'group_id');		//		// Now, make the user an admin		//		$res = db_query("			INSERT INTO user_group (				user_id,				group_id,				admin_flags,				cvs_flags,				artifact_flags,				forum_flags			)			VALUES (				".$user->getID().",				'$id',				'A',				1,				2,				2			)		");		if (!$res || db_affected_rows($res) < 1) {			$this->setError('ERROR: Could not add admin to newly created group: '.db_error());			db_rollback();			return false;		}		if (!$this->fetchData($id)) {			db_rollback();			return false;		}		db_commit();		$this->sendNewProjectNotificationEmail();		return true;	}	/**	 *	updateAdmin - Update core properties of group object.	 *	 *	This function require site admin privilege.	 *	 *	@param	object	User requesting operation (for access control).	 *	@param	bool	Whether group is publicly accessible (0/1).	 *	@param	string	Project's license (string ident).	 *	@param	int		Group type (1-project, 2-foundry).	 *	@param	string	Machine on which group's home directory located.	 *	@param	string	Domain which serves group's WWW.	 *	@return status.	 *	@access public.	 */	function updateAdmin(&$user, $is_public, $license, $type, $unix_box, $http_domain) {		global $Language;		$perm =& $this->getPermission($user);		if (!$perm || !is_object($perm)) {			$this->setError($Language->getText('general','permnotget'));			return false;		}		if (!$perm->isSuperUser()) {			$this->setError($Language->getText('general','permdenied'));			return false;		}		db_begin();		$res = db_query("			UPDATE groups			SET is_public='$is_public',				license='$license',type='$type',				unix_box='$unix_box',http_domain='$http_domain'			WHERE group_id='".$this->getID()."'		");		if (!$res || db_affected_rows($res) < 1) {			$this->setError('ERROR: DB: Could not change group properties: '.db_error());			db_rollback();			return false;		}		// Log the audit trail		if ($is_public != $this->isPublic()) {			$this->addHistory('is_public', $this->isPublic());		}		if ($license != $this->data_array['license']) {			$this->addHistory('license', $this->data_array['license']);		}		if ($type != $this->data_array['type']) {			$this->addHistory('type', $this->data_array['type']);		}		if ($unix_box != $this->data_array['unix_box']) {			$this->addHistory('unix_box', $this->data_array['unix_box']);		}		if ($http_domain != $this->data_array['http_domain']) {			$this->addHistory('http_domain', $this->data_array['http_domain']);		}		if (!$this->fetchData($this->getID())) {			db_rollback();			return false;		}		db_commit();		return true;	}	/**	 *	update - Update number of common properties.	 *	 *	Unlike updateAdmin(), this function accessible to project admin.	 *	 *	@param	object	User requesting operation (for access control).	 *	@param	bool	Whether group is publicly accessible (0/1).	 *	@param	string	Project's license (string ident).	 *	@param	int		Group type (1-project, 2-foundry).	 *	@param	string	Machine on which group's home directory located.	 *	@param	string	Domain which serves group's WWW.	 *	@return int	status.	 *	@access public.	 */	function update(&$user, $group_name,$homepage,$short_description,$use_mail,$use_survey,$use_forum,		$use_pm,$use_pm_depend_box,$use_cvs,$use_news,$use_docman,		$new_doc_address,$send_all_docs,$logo_image_id,		$enable_pserver,$enable_anoncvs,		$use_ftp,$use_tracker,$use_frs,$use_stats) {		global $Language;		$perm =& $this->getPermission($user);		if (!$perm || !is_object($perm)) {			$this->setError($Language->getText('general','permnotget'));			return false;		}		if (!$perm->isAdmin()) {			$this->setError($Language->getText('general','permdenied'));			return false;		}		// Validate some values		if (!$group_name) {			$this->setError('Invalid Group Name');			return false;		}		if ($new_doc_address && !validate_email($new_doc_address)) {			$this->setError('New Doc Address Appeared Invalid');			return false;		}		// in the database, these all default to '1',		// so we have to explicity set 0		if (!$use_mail) {			$use_mail=0;		}		if (!$use_survey) {			$use_survey=0;		}		if (!$use_forum) {			$use_forum=0;		}		if (!$use_pm) {			$use_pm=0;		}		if (!$use_pm_depend) {			$use_pm_depend=0;		}		if (!$use_cvs) {			$use_cvs=0;		}		if (!$use_news) {			$use_news=0;		}		if (!$use_docman) {			$use_docman=0;		}		if (!$send_all_tasks) {			$send_all_tasks=0;		}		if (!$enable_pserver) {			$enable_pserver=0;		}		if (!$enable_anoncvs) {			$enable_anoncvs=0;		}		if (!$use_ftp) {			$use_ftp=0;		}		if (!$use_tracker) {			$use_tracker=0;		}		if (!$use_frs) {			$use_frs=0;		}		if (!$use_stats) {			$use_stats=0;		}		if (!$send_all_docs) {			$send_all_docs=0;		}		if (!$homepage) {			$homepage='http://'.$GLOBALS['sys_default_domain'].'/projects/'.$this->getUnixName().'/';		}		if (strlen($short_description)>255) {			$this->setError('Error updating project information: Maximum length for Project Description is 255 chars.');			return false;		}		db_begin();		//XXX not yet actived logo_image_id='$logo_image_id', 		$sql = "			UPDATE groups			SET 				group_name='".htmlspecialchars($group_name)."',				homepage='$homepage',				short_description='".htmlspecialchars($short_description)."',				use_mail='$use_mail',				use_survey='$use_survey',				use_forum='$use_forum',				use_pm='$use_pm',				use_pm_depend_box='$use_pm_depend_box',				use_cvs='$use_cvs',				use_news='$use_news',				use_docman='$use_docman',				new_doc_address='$new_doc_address',				send_all_docs='$send_all_docs',				enable_pserver='$enable_pserver',				enable_anoncvs='$enable_anoncvs',				use_ftp='$use_ftp',				use_tracker='$use_tracker',				use_frs='$use_frs',				use_stats='$use_stats'			WHERE group_id='".$this->getID()."'		";		$res = db_query($sql);		if (!$res || db_affected_rows($res) < 1) {			$this->setError('Error updating project information: '.db_error());			db_rollback();			return false;		}		// Log the audit trail		$this->addHistory('Changed Public Info', '');		if (!$this->fetchData($this->getID())) {			db_rollback();			return false;		}		db_commit();		return true;	}	/**	 *	getID - Simply return the group_id for this object.	 *	 *	@return int group_id.	 */	function getID() {		return $this->data_array['group_id'];	}	/**	 *	getType() - Foundry, project, etc.	 *	 *	@return	int	The type flag from the database.	 */	function getType() {		return $this->data_array['type'];	}	/**	 *	getStatus - the status code.	 *	 *	Statuses	char	include I,H,A,D.	 */	function getStatus() {		return $this->data_array['status'];	}	/**	 *	setStatus - set the status code.	 *	 *	Statuses include I,H,A,D.	 *	 *	@param	object	User requesting operation (for access control).	 *	@param	string	Status value.	 *	@return	boolean	success.	 *	@access public.

⌨️ 快捷键说明

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