Location: PHPKode > projects > Myphpim > MyPhPim-01.05/groupadmin.php3
<?php

//****************************************************************************************
//                Copyright (C) 2000 Koen de Boeve
//
//        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 2
//        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; if not, write to the Free Software
//        Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
//
//        Version : MyPhPim-01.05
//        Author : Koen de Boeve
//        Contact: hide@address.com
//**************************************************************************************** 

include "conf/global_conf.inc";

session_start();

$html = new HtmlCl;
$form = new FormCl;
$db = new DB;

if ( $menu ) {
	switch ( $menu ) {
		case "setup" :
				
				$html->htmlheader ( "Group Configuration For $user", 0 );
				echo "$error<p>\n";
				echo "<hr noshade>\n";
				echo "<center><font size=+1>Create New Group </font></center><br>\n";
				echo "<table border=0>\n";
				$form->init ( "groupadmin.php3", "POST", "groupadmin" );
				echo "<tr>\n";
				echo "<td><font size=-1>New Group Name :</td><td><font size=+1 face=clean><small>";
				$form->text ( "groupname", "", 16, 16, 0 );
				echo "</small></font></td></tr><tr><td><font size=-1>Group should be visible to: </font></td><td><font size=-1>";
				$visible = array ( "members", "public" );
				$form->simpleselect ( "visible", $visible, $visible, "members" );
				echo "</font></td></tr><tr><td colspan=2 align=center><font size=-1>"; 
				$form->submit ( "menu", "Add Group" );
				echo "</font></td></tr>\n";
				$form->close();
				echo "</table>\n";
				echo "<hr noshade>\n";
				echo "<center><font size=+1>Group Details</font></center><br>\n";
				$query = "SELECT user_id FROM users WHERE user='$user'";
                                $result = $db->query ( $query );
                                $user_id = $db->result ( $result, 0, "user_id" );
				$query = "SELECT group_id, groupname FROM groups WHERE owner='$user_id'";	
				$result = $db->query ( $query );
				$numrows = $db->numrows ( $result );
				if ( $numrows == 0 ) {
					echo "No groups created yet<p>\n";
				} else {
					echo "<center><table border=0 cellspacing=0 cellpadding=0 width=80%>\n";
					$form->init ( "groupadmin.php3", "get", "groupadmin" );
					echo "<tr><td colspan=5 align=center>\n";
					echo "Select Group: <select name=group_id onChange=window.location.href=\"groupadmin.php3?menu=setup&group_id=\"+(options[selectedIndex].value)>\n";
					for ( $i = 0; $i < $numrows; $i++ ) {
						$groupids[$i] = $db->result ( $result, $i, "group_id" );
						$groupnames[$i] = $db->result ( $result, $i, "groupname" );
						if ( !$group_id ) { $group_id = $groupids[0]; }
						if ( $group_id == $groupids[$i] ) {
							echo "<option value=$groupids[$i] selected>$groupnames[$i]</option>\n";
						} else {	
							echo "<option value=$groupids[$i]>$groupnames[$i]</option>\n";
						}
					}
					echo "</select></td></tr><tr bgcolor=dimgray><td align=center><font color=white>UserList</font></td><td>&nbsp</td>
						<td align=center><font color=white>Users In Group</font></td>
						<td align=center><font color=white>Visible To</font></td>
						<td align=center>&nbsp</td>\n";
					echo "</tr><tr><td align=center>\n";
					$query = "SELECT user_id FROM groupmembers WHERE group_id=$group_id";
					$result = $db->query ( $query );
					$numrows = $db->numrows ( $result );
					for ( $i = 0; $i < $numrows; $i++ ) {
						$member_userid[$i] = $db->result ( $result, $i, "user_id" );
					}
					$num_memberuserids = count ( $member_userid );
					$query = "SELECT user_id, user FROM users ORDER BY user";
					$result = $db->query ( $query );
					$numrows = $db->numrows ( $result );
					$counter = 0;
					for ( $i = 0; $i < $numrows; $i++ ) {
						$users_userid[$i] = $db->result ( $result , $i, "user_id" );
						$users_user[$i] = $db->result ( $result, $i, "user" );
						$flag = 0;
						for ( $j = 0; $j < $num_memberuserids; $j++ ) {
							if ( $users_userid[$i] == $member_userid[$j] ) {
								$flag = 1;
							}
						}
						if ( $flag != 1 ) {
							$use_id[$counter] = $users_userid[$i];
							$use_user[$counter] = $users_user[$i];
							$counter++;
						}
					}
					$form->MultiSelect ( "arr_userid", $use_id, $use_user, "NO-ONE", 5 );
					echo "</td><td align=center><font size=-1>Add to group</font><br>\n";
					$form->submit ( "addtogroup", ">>>" );
					echo "<br><font size=-1>Delete From Group</font><br>\n";
					$form->submit ( "delfromgroup", "<<<" );
					echo "</td><td align=center>\n";
					for ( $i = 0; $i < $num_memberuserids; $i++ ) {
						$query = "SELECT user FROM users WHERE user_id=$member_userid[$i]";
						$result = $db->query ( $query );
						$member_name[$i] = $db->result ( $result, 0, "user" );
					}
					$form->MultiSelect ( "arr_gr_userid", $member_userid, $member_name, "NO-ONE", 5 );
					echo "</td><td align=center><center>\n";
					$query = "SELECT visible FROM groups WHERE group_id=$group_id";
					$result = $db->query ( $query );
					$vis = $db->result ( $result, 0, "visible" );
					$form->SimpleSelect ( "visible", $visible, $visible, $vis );
					echo "<br>\n";
					$form->submit ( "updvisible", "Change" );
					echo "</center></td><td align=center>\n";
					$form->submit ( "deletegroup", "Delete Group" );
					echo "</td>\n";
					echo "</tr>\n";
					$form->close();
					echo "</table></center>\n";
					echo "<hr noshade>\n";
				}
				$html->htmlfooter();
				break;;
		case "Add Group" :
				$query = "SELECT groupname FROM groups WHERE groupname='$groupname' ";
				$result = $db->query ( $query );
				$numrows = $db->numrows ( $result );
				if ( $numrows == 0 ) {
					$query = "SELECT user_id FROM users WHERE user='$user'";
					$result = $db->query ( $query );
					$user_id = $db->result ( $result, 0, "user_id" );
					$query = "INSERT INTO groups VALUES ( NULL, '$groupname', $user_id, '$visible' )";
					$result = $db->query ( $query );
					//echo "INSERT INTO groups VALUES ( NULL, '$groupname', $user_id, $visible )";
					//echo "http://$HTTP_SERVER_VARS[HTTP_HOST]/$basepath/groupadmin.php3?menu=setup\n";
					header ( "Location: http://$HTTP_SERVER_VARS[HTTP_HOST]/$basepath/groupadmin.php3?menu=setup" );
				} else {
					$error="Sorry+group+<b>$groupname</b>+allready+exists";
					//echo "http://$HTTP_SERVER_VARS[HTTP_HOST]/$basepath/groupadmin.php3?menu=setup\n";
					header ( "Location: http://$HTTP_SERVER_VARS[HTTP_HOST]/$basepath/groupadmin.php3?menu=setup&error=$error" );
				}
				break;;
				
	}
}
	if ( $updvisible ) {
		$query = "UPDATE groups SET visible='$visible' WHERE group_id=$group_id";
		$result = $db->query ( $query );
		header ( "Location: http://$HTTP_SERVER_VARS[HTTP_HOST]/$basepath/groupadmin.php3?menu=setup&group_id=$group_id" );
	}
	if ( $deletegroup ) {
		$query = "DELETE FROM groupmembers WHERE group_id=$group_id";
		$result = $db->query ( $query );
		$query = "DELETE FROM groups WHERE group_id=$group_id";
		$result = $db->query ( $query );
		header ( "Location: http://$HTTP_SERVER_VARS[HTTP_HOST]/$basepath/groupadmin.php3?menu=setup" );
	}
		
	if ( $addtogroup ) {
		$splitted = explode ( "&", $QUERY_STRING );
		$numsplitted = count ( $splitted ) ;
		for ( $i = 0 ; $i < $numsplitted; $i++ ) {
			if ( ereg ( "^arr_userid", $splitted[$i] ) ) {
				$parts = explode ( "=", $splitted[$i] );
				$query = "INSERT INTO groupmembers VALUES ( NULL, $group_id, $parts[1] )"; 
				$result = $db->query ( $query );
			}
		}
		header ( "Location: http://$HTTP_SERVER_VARS[HTTP_HOST]/$basepath/groupadmin.php3?menu=setup&group_id=$group_id" );
	}
	if ( $delfromgroup ) {
		$splitted = explode ( "&", $QUERY_STRING );
		$numsplitted = count ( $splitted ) ;
		for ( $i = 0 ; $i < $numsplitted; $i++ ) {
			if ( ereg ( "^arr_gr_userid", $splitted[$i] ) ) {
				$parts = explode ( "=", $splitted[$i] );
				$query = "DELETE FROM groupmembers WHERE user_id=$parts[1] AND group_id=$group_id"; 
				$result = $db->query ( $query );
			}
		}
		header ( "Location: http://$HTTP_SERVER_VARS[HTTP_HOST]/$basepath/groupadmin.php3?menu=setup&group_id=$group_id" );
	}
?>
Return current item: Myphpim