Location: PHPKode > projects > NetworX - Social networking Service > group_manage_groups.php
<?php
/*
NetworX - open-source social networks platform
Copyright (C) 2009 SocialABC, Inc. http://www.socialabc.com
This program 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 3 of the License, or (at your option) any later version.
This program 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 this program in a file called LICENSE; if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/ 

include('includes/application_top.php');
if ($user->isAuthorised())
{
	$group = new Group($_GET['group_id']);
	if ($group->GroupID != -1)
	{
        $template->setGlobalVariable('_GroupID', $group->GroupID);
		if (isset($_POST['submited']))
		{
			switch ($_POST['submited'])
			{					
				case 'add_group':
				
					$_SESSION['connect_group_users'] = array('GroupID' => $group->GroupID);
					cmn_redirect('group_register.php');
					break;
					
				case 'delete_group':
				
					if (is_array(@$_POST['GroupID']))
					{
						foreach ($_POST['GroupID'] as $groupID)
						{
							$group = new Group($groupID);
							$group->delete();
						}
					}
					break;
					
				case 'save':
				
					if (is_array(@$_POST['GroupPermissions']))
					{
						foreach ($_POST['GroupPermissions'] as $grpID => $grpPermissions)
						{
							$grp = new Group($grpID);
							$grp->GroupPermissions = intval($grpPermissions);
							$grp->saveToDB();
							
							if (@is_array($_POST['UserID'][$grp->GroupID]))
							{
								$posted  = $_POST['UserID'][$grp->GroupID];
								$members = $grp->getGroupMembers();
								foreach ($members as $member)
								{
									if (isset($posted[$member->UserID]))
									{
										unset($posted[$member->UserID]);
									}
									else
									{
										$grp->removeMember($member->UserID);
									}
								}
								
								foreach ($posted as $userID)
								{
									$grp->addMember($userID);
								}
							}
							
							if (@is_array($_POST['GroupID'][$grp->GroupID]))
							{
								$posted  = $_POST['GroupID'][$grp->GroupID];
								$members = $grp->getSubgroups();
								foreach ($members as $member)
								{
									if (isset($posted[$member->GroupID]))
									{
										unset($posted[$member->GroupID]);
									}
									else
									{
										$grp->removeSubgroup($member->GroupID);
									}
								}
								
								foreach ($posted as $grpID)
								{
									$grp->addGroup($grpID);
								}
							}
						}
					}
			}
		}
		
		
		$users = $group->getGroupMembers();
		foreach ($users as $member)
		{
			$template->setVariable('UserID', $member->UserID);
			$template->setVariable('UserEmail', $member->UserEmail);
			$template->parse('user');
		}
		
		$groups = $group->getSubgroups();
		foreach ($groups as $group)
		{
			$template->setVariable('GroupID', $group->GroupID);
			$template->setVariable('GroupName', $group->GroupName);
			$template->setVariable('GroupPermissions', $group->GroupPermissions);
			$template->parse('group');

			$template->setVariable('GroupID', $group->GroupID);
			$template->setVariable('GroupName', $group->GroupName);
			$template->parse('group_delete');
			
			$users = $group->getGroupMembers();  
			foreach ($users as $member)
			{
				$template->setVariable('GroupID', $group->GroupID);
				$template->setVariable('UserID', $member->UserID);
				$template->setVariable('UserEmail', $member->UserEmail);
				$template->parse('member_user');
			}
			
			$subgroups = $group->getSubgroups();
			foreach ($subgroups as $subgroup)
			{
				$template->setVariable('GroupID', $group->GroupID);
				$template->setVariable('SubGroupID', $subgroup->GroupID);
				$template->setVariable('SubGroupName', $subgroup->GroupName);
				$template->parse('member_group');   
			}
		}
	}
}
else
{
    cmn_unathorized_action();
}
include('includes/application_bottom.php');
?>
Return current item: NetworX - Social networking Service