Location: PHPKode > projects > Insecticida > insecticida_wiki/admin/groupadmin.php
<?
###################################################
#Copyright (C) 2001 Stuart Wigley (hide@address.com) 
#
#groupadmin.php 08/11/2001   
#
#This file is part of workbench.
#
#workbench 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.
#
#workbench 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 workbench; if not, write to the Free Software
#Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
#####################################################
session_start();
require_once("../config.php");
#if user has logged in get $login from session
if (($HTTP_SESSION_VARS["group"] == "1") && session_is_registered("login")){
	$login = $HTTP_SESSION_VARS["login"];
	require_once("$path/connect.php");
	require_once("$path/general.php"); 
	if ($HTTP_POST_VARS["newGroup"]){
		$query = mysql_query("select * from groups where grpName='".$HTTP_POST_VARS["grpName"]."'") or die (mysql_error());
		if (!mysql_num_rows($query)){
			mysql_query("INSERT INTO groups VALUES ('', '".$HTTP_POST_VARS["grpAssign"]."', '".$HTTP_POST_VARS["grpName"]."', '".$HTTP_POST_VARS["isHidden"]."')") or die (mysql_error());
			$query2 = mysql_query("select grpID from groups where grpName='".$HTTP_POST_VARS["grpName"]."'") or die (mysql_error());
			$result2 = mysql_fetch_array($query2);
			header("Location: $relative/admin/groupadmin.php?grpID=$result2[grpID]");
			exit;
			}
		else{
			header("Location: $relative/admin/groupadmin.php?new=1&theError=1");
			exit;
			}
		}
	elseif ($HTTP_POST_VARS["grpAssign"] && $HTTP_POST_VARS["isHidden"] && $HTTP_POST_VARS["grpName"]){
		$query = mysql_query("update groups set isHidden='".$HTTP_POST_VARS["isHidden"]."', grpAssign='".$HTTP_POST_VARS["grpAssign"]."', grpName='".$HTTP_POST_VARS["grpName"]."' where grpID='".$HTTP_POST_VARS["grpID"]."'");
		header("Location: $relative/admin/groupadmin.php?grpID=".$HTTP_POST_VARS["grpID"]."");
		exit;
		}
	include("$path/header.php");?>
    <table cellspacing="0" class="table3">
	 <tr class="rowtitle">
	  <td colspan="2"><h5>Manage Groups</h5></td>
	 </tr>
	 <tr>
	  <td colspan="2"><p>This Administration Tool allows you to create new groups and change existing groups. 
	  Choose an existing group from the list or click the New Group button.</p></td>
	 </tr>
	 <tr>
	  <td colspan="2"><hr></td>
	 </tr>
	 <tr>
	  <td colspan="2">
	  <form method="get" action="groupadmin.php" name="groupadmin">
		  <select name="grpID" onchange="this.form.submit()">
		   <option value="">Choose
		   <?
		   $query = mysql_query("select * from groups grpName") or die(mysql_error());
			while ($result = mysql_fetch_array($query)){
				if ($result[grpID] == $grpID){
					echo("<option value=\"$result[grpID]\" selected>$result[grpName]");
					}
				else{
					echo("<option value=\"$result[grpID]\">$result[grpName]");
					}
				} 
			?>
		   </select> or <input type="button" value="New Group" onclick="javascript:window.location='groupadmin.php?new=1'">
	   </form>
	  </td>
	  </tr>
	  <tr><td colspan="2"><hr></td></tr>
	  <form name="groupadmin2" method="post" action="groupadmin.php" onSubmit="return validateForm('groupadmin2');">
<?
if ($HTTP_GET_VARS["grpID"]){
	$query = mysql_query("select * from groups where grpID = '".$HTTP_GET_VARS["grpID"]."'") or die(mysql_error());
	$result = mysql_fetch_array($query);
	echo("<tr class=\"rowtitle\"><td colspan=\"2\"><h5>Group Details</h5></td></tr>");
	echo("<tr><td>Name</td><td><input type=\"text\" name=\"grpName\" size=\"20\" maxlength=\"50\" value=\"$result[grpName]\"></td></tr>");
	echo("<tr><td>Can issues be assigned to members of this group?</td><td><select name=\"grpAssign\">");
	if ($result[grpAssign] == "Y"){
		echo("<option value=\"Y\" selected>Yes</option><option value=\"N\">No</option>");
		}
	else{
		echo("<option value=\"Y\">Yes</option><option value=\"N\" selected>No</option>");
		}
	echo("</select></td></tr>");
	echo("<tr><td>Is this group hidden?</td><td><select name=\"isHidden\">");
	if ($result[isHidden] == "Y"){
		echo("<option value=\"Y\" selected>Yes</option><option value=\"N\">No</option>");
		}
	else{
		echo("<option value=\"Y\">Yes</option><option value=\"N\" selected>No</option>");
		}
	echo("</select></td></tr>");
	echo("<input type=\"hidden\" name=\"grpID\" value=\"".$HTTP_GET_VARS["grpID"]."\">");
	echo("<tr><td colspan=\"2\" align=\"center\"><input type=\"Submit\" value=\"Submit\"></td></tr>");
	}
elseif ($HTTP_GET_VARS["new"] == "1"){
	if ($HTTP_GET_VARS["theError"] == 1){
		echo("<tr><td colspan=\"2\"><strong>That group already exists. Please choose a different name.</strong></td></tr>");
		}
	echo("<tr><td>Name</td><td><input type=\"text\" name=\"grpName\" size=\"20\" maxlength=\"50\"></td></tr>");
	echo("<tr><td>Can issues be assigned to members of this group?</td><td><select name=\"grpAssign\">");
	echo("<option value=\"Y\" selected>Yes</option><option value=\"N\">No</option></select></td></tr>");
	echo("<tr><td>Is this group hidden?</td><td><select name=\"isHidden\">");
	echo("<option value=\"Y\">Yes</option><option value=\"N\" selected>No</option></select></td></tr>");
	echo("<tr><td>&nbsp;</td><td><input type=\"Submit\" value=\"Submit\"></td></tr>");
	echo("<input type=\"hidden\" name=\"newGroup\" value=\"1\">");
	}
?>	  </form>
	 </table>
  
<?include("$path/footer.php");
}
else{
	include("$path/login.php");
	}
?>
Return current item: Insecticida