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

📄 admin.users.php

📁 Joomla15 - 最新开源CMS
💻 PHP
📖 第 1 页 / 共 2 页
字号:
	$SiteName	= $mainframe->getCfg('sitename');

 	// Create a new JUser object
	$user = new JUser(JRequest::getVar( 'id', 0, 'post', 'int'));
	$original_gid = $user->get('gid');

	$post = JRequest::get('post');
	$post['username']	= JRequest::getVar('username', '', 'post', 'username');
	$post['password']	= JRequest::getVar('password', '', 'post', 'string', JREQUEST_ALLOWRAW);
	$post['password2']	= JRequest::getVar('password2', '', 'post', 'string', JREQUEST_ALLOWRAW);
	
	if (!$user->bind($post))
	{
		$mainframe->enqueueMessage('Cannot save the user information', 'message');
		$mainframe->enqueueMessage($user->getError(), 'error');
		//$mainframe->redirect( 'index.php?option=com_users', $user->getError() );
		//return false;
		JRequest::setVar( 'task', 'edit');
		return editUser();
	}

	// Are we dealing with a new user which we need to create?
	$isNew 	= ($user->get('id') < 1);
	if (!$isNew)
	{
		// if group has been changed and where original group was a Super Admin
		if ( $user->get('gid') != $original_gid && $original_gid == 25 )
		{
			// count number of active super admins
			$query = 'SELECT COUNT( id )'
			. ' FROM #__users'
			. ' WHERE gid = 25'
			. ' AND block = 0'
			;
			$db->setQuery( $query );
			$count = $db->loadResult();

			if ( $count <= 1 )
			{
				// disallow change if only one Super Admin exists
				$mainframe->redirect( 'index.php?option=com_users', JText::_('WARN_ONLY_SUPER') );
				return false;
			}
		}
	}

	/*
	 * Lets save the JUser object
	 */
	if (!$user->save())
	{
		$mainframe->enqueueMessage('Cannot save the user information', 'message');
		$mainframe->enqueueMessage($user->getError(), 'error');
		JRequest::setVar( 'task', 'edit');
		return editUser();
	}
	
	/*
	 * Change the user object in the session
	 */
	if ( $me->get('id') == $user->get('id') )
	{
		$session	= JFactory::getSession();
		$user->_bind($me);
		$session->set('user', $user);
	}


	/*
	 * Time for the email magic so get ready to sprinkle the magic dust...
	 */
	if ($isNew)
	{
		$adminEmail = $me->get('email');
		$adminName	= $me->get('name');

		$subject = JText::_('NEW_USER_MESSAGE_SUBJECT');
		$message = sprintf ( JText::_('NEW_USER_MESSAGE'), $user->get('name'), $SiteName, $mainframe->getSiteURL(), $user->get('username'), $user->password_clear );

		if ($MailFrom != '' && $FromName != '')
		{
			$adminName 	= $FromName;
			$adminEmail = $MailFrom;
		}
		JUtility::sendMail( $adminEmail, $adminName, $user->get('email'), $subject, $message );
	}

	switch ( $task ) {
		case 'apply':
			$msg = JText::sprintf( 'Successfully Saved changes to User', $user->get('name') );
			$mainframe->redirect( 'index.php?option=com_users&task=edit&cid[]='. $user->get('id'), $msg );
			break;

		case 'save':
		default:
			$msg = JText::sprintf( 'Successfully Saved User', $user->get('name') );
			$mainframe->redirect( 'index.php?option=com_users', $msg );
			break;
	}
}

/**
* Cancels an edit operation
*/
function cancelUser( )
{
	global $mainframe;

	$option = JRequest::getCmd( 'option');
	$mainframe->redirect( 'index.php?option='. $option .'&task=view' );
}

/**
* Delete selected users
*/
function removeUsers(  )
{
	global $mainframe;

	$db 			=& JFactory::getDBO();
	$currentUser 	=& JFactory::getUser();
	$acl			=& JFactory::getACL();
	$cid 			= JRequest::getVar( 'cid', array(), '', 'array' );

	JArrayHelper::toInteger( $cid );

	if (count( $cid ) < 1) {
		JError::raiseError(500, JText::_( 'Select a User to delete', true ) );
	}

	foreach ($cid as $id)
	{
		// check for a super admin ... can't delete them
		$objectID 	= $acl->get_object_id( 'users', $id, 'ARO' );
		$groups 	= $acl->get_object_groups( $objectID, 'ARO' );
		$this_group = strtolower( $acl->get_group_name( $groups[0], 'ARO' ) );

		$success = false;
		if ( $this_group == 'super administrator' )
		{
			$msg = JText::_( 'You cannot delete a Super Administrator' );
		}
		else if ( $id == $currentUser->get( 'id' ) )
		{
			$msg = JText::_( 'You cannot delete Yourself!' );
		}
		else if ( ( $this_group == 'administrator' ) && ( $currentUser->get( 'gid' ) == 24 ) )
		{
			$msg = JText::_( 'WARNDELETE' );
		}
		else
		{
			$user =& JUser::getInstance((int)$id);
			$count = 2;

			if ( $user->get( 'gid' ) == 25 )
			{
				// count number of active super admins
				$query = 'SELECT COUNT( id )'
				. ' FROM #__users'
				. ' WHERE gid = 25'
				. ' AND block = 0'
				;
				$db->setQuery( $query );
				$count = $db->loadResult();
			}

			if ( $count <= 1 && $user->get( 'gid' ) == 25 )
			{
				// cannot delete Super Admin where it is the only one that exists
				$msg = "You cannot delete this Super Administrator as it is the only active Super Administrator for your site";
			}
			else
			{
				// delete user
				$user->delete();
				$msg = '';

				JRequest::setVar( 'task', 'remove' );
				JRequest::setVar( 'cid', $id );

				// delete user acounts active sessions
				logoutUser();
			}
		}
	}

	$mainframe->redirect( 'index.php?option=com_users', $msg);
}

/**
* Blocks or Unblocks one or more user records
* @param integer 0 if unblock, 1 if blocking
*/
function changeUserBlock( $block = 1 )
{
	global $mainframe;

	$db 			=& JFactory::getDBO();
	$acl			=& JFactory::getACL();
	$currentUser 	=& JFactory::getUser();

	$cid 	= JRequest::getVar( 'cid', array(), '', 'array' );

	JArrayHelper::toInteger( $cid );

	if (count( $cid ) < 1) {
		$action = $block ? 'block' : 'unblock';
		JError::raiseError(500, JText::_( 'Select a User to '.$action, true ) );
	}
	foreach ($cid as $id)
	{
		// check for a super admin ... can't delete them
		$objectID 	= $acl->get_object_id( 'users', $id, 'ARO' );
		$groups 	= $acl->get_object_groups( $objectID, 'ARO' );
		$this_group = strtolower( $acl->get_group_name( $groups[0], 'ARO' ) );

		$success = false;
		if ( $this_group == 'super administrator' )
		{
			$msg = JText::_( 'You cannot block a Super Administrator' );
		}
		else if ( $id == $currentUser->get( 'id' ) )
		{
			$msg = JText::_( 'You cannot block Yourself!' );
		}
		else if ( ( $this_group == 'administrator' ) && ( $currentUser->get( 'gid' ) == 24 ) )
		{
			$msg = JText::_( 'WARNBLOCK' );
		}
		else
		{
			$user =& JUser::getInstance((int)$id);
			$count = 2;

			if ( $user->get( 'gid' ) == 25 )
			{
				// count number of active super admins
				$query = 'SELECT COUNT( id )'
				. ' FROM #__users'
				. ' WHERE gid = 25'
				. ' AND block = 0'
				;
				$db->setQuery( $query );
				$count = $db->loadResult();
			}

			if ( $count <= 1 && $user->get( 'gid' ) == 25 )
			{
				// cannot delete Super Admin where it is the only one that exists
				$msg = "You cannot block this Super Administrator as it is the only active Super Administrator for your site";
			}
			else
			{
				$user =& JUser::getInstance((int)$id);
				$user->block = $block;
				$user->save();
		
				if($block) 
				{
					JRequest::setVar( 'task', 'block' );
					JRequest::setVar( 'cid', array($id) );

					// delete user acounts active sessions
					logoutUser();
				}
			}
		}
	}
	
	$mainframe->redirect( 'index.php?option=com_users', $msg);
}

/**
 * logout selected users
*/
function logoutUser( )
{
	global $currentUser, $mainframe;

	$db		=& JFactory::getDBO();
	$task 	= JRequest::getCmd( 'task' );
	$cids 	= JRequest::getVar( 'cid', array(), '', 'array' );
	$client = JRequest::getVar( 'client', 0, '', 'int' );
	$id 	= JRequest::getVar( 'id', 0, '', 'int' );
	
	

	JArrayHelper::toInteger($cids);

	if ( count( $cids ) < 1 ) {
		$mainframe->redirect( 'index.php?option=com_users', JText::_( 'User Deleted' ) );
	}

	foreach($cids as $cid)
	{
		$options = array();
		
		if ($task == 'logout' || $task == 'block') {
			$options['clientid'][] = 0; //site
			$options['clientid'][] = 1; //administrator
		} else if ($task == 'flogout') {
			$options['clientid'][] = $client;
		}
		
		$mainframe->logout((int)$cid, $options);
	}


	$msg = JText::_( 'User Session Ended' );
	switch ( $task )
	{
		case 'flogout':
			$mainframe->redirect( 'index.php', $msg );
			break;

		case 'remove':
		case 'block':
			return;
			break;

		default:
			$mainframe->redirect( 'index.php?option=com_users', $msg );
			break;
	}
}
?>

⌨️ 快捷键说明

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