Location: PHPKode > projects > Insecticida > insecticida_wiki/admin/bugadmin.php
<?
###################################################
#Copyright (C) 2001 Stuart Wigley (hide@address.com) 
#
#bugadmin.php 14/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["tableName"] && $HTTP_POST_VARS["theID"] && $HTTP_POST_VARS["theKey"]){
		$theQuery1 = "update ".$HTTP_POST_VARS["tableName"]." set ";
		$comma = " ";
		while (list ($key, $val) = each ($HTTP_POST_VARS)) {
			if (($key != "tableName") && ($key != "theID") && ($key != "theKey")){
				$theQuery2 .= "$comma $key='$val'";
				$comma = ",";
				}
			}
		$theQuery3 = "where ".$HTTP_POST_VARS["theKey"]."=".$HTTP_POST_VARS["theID"]."";
		$query = mysql_query("$theQuery1 $theQuery2 $theQuery3") or die(mysql_error());
		header("Location: $url/admin/bugadmin.php?tableName=".$HTTP_POST_VARS["tableName"]."");
		exit;
		}
	elseif ($HTTP_POST_VARS["tableName"] && $HTTP_POST_VARS["go"]){
		$theQuery1 = "insert into ".$HTTP_POST_VARS["tableName"]." values (";
		$comma = "'', ";
		while (list ($key, $val) = each ($HTTP_POST_VARS)) {
			if (($key != "tableName") && ($key != "go")){
				$theQuery2 .= "$comma '$val'";
				$comma = ",";
				}
			}
		$theQuery2 .= ")";
		$query = mysql_query("$theQuery1 $theQuery2") or die(mysql_error());
		header("Location: $url/admin/bugadmin.php?tableName=".$HTTP_POST_VARS["tableName"]."");
		exit;
		}
	include("$path/header.php");
?>
    <table cellspacing="0" class="table3">
	 <tr class="rowtitle">
	  <td><h5>Manage Issues</h5></td>
	 </tr>
	 <tr>
	  <td><p>This Administration Tool allows you to manage issue settings. You can add, edit and hide fields in four main
	  lookup tables. These tables describe where issues are found, their status, severity and also the other types of issue that 
	  workbench tracks. Choose a table from the drop-down list below.</p></td>
	 </tr>
	 <tr>
	  <td><hr></td>
	 </tr>
	 <tr>
	  <td>
	   <form action="bugadmin.php" method="get">
	    <select name="tableName" onchange="this.form.submit()">
		<option value="">Choose</option>
		<option value="foundIn"<?if ($HTTP_GET_VARS["tableName"]=="foundIn"){echo(" selected");}?>>Found In</option>
		<option value="type"<?if ($HTTP_GET_VARS["tableName"]=="type"){echo(" selected");}?>>Type</option>
		<option value="status"<?if ($HTTP_GET_VARS["tableName"]=="status"){echo(" selected");}?>>Status</option>
		<option value="severity"<?if ($HTTP_GET_VARS["tableName"]=="severity"){echo(" selected");}?>>Severity</option>
	    </select>
	   </form>
	  </td>
	 </tr>
	 <tr><td colspan="2"><hr></td></tr>
	 <?if ($HTTP_GET_VARS["tableName"] == "status"){?>
	 <tr>
	  <td><p class="warning">WARNING: Editing this table can seriously damage the integrity of workbench</p></td>
	 </tr>
	 <?}?>
	 <tr>
	 <td>
	  <table class="table1"><tr><td>
	 <form method="post" name="bugAdmin" action="bugadmin.php">
<?
if ($HTTP_GET_VARS["tableName"]){
	$query = mysql_query("select * from ".$HTTP_GET_VARS["tableName"]."") or die(mysql_error());
	$fields = mysql_num_fields($query);
	$cols = $fields +1;
	echo("<tr class=\"rowtitle\"><td colspan=\"$cols\"><h5>Listing table ".$HTTP_GET_VARS["tableName"]."</h5></td></tr>");
	echo("<tr>");
	for ($i = 1; $i<$fields; $i++)
	{
		echo("<td><strong>".mysql_field_name($query, $i)."</strong> ".mysql_field_type($query, $i)."(".mysql_field_len($query, $i).")</td>");
	}
	echo("<td><strong>Function</strong></td></tr>");
	while ($result = mysql_fetch_array($query))
	{
		echo("<tr>");
		for ($i=1; $i<$fields; $i++)
		{
			if (($HTTP_GET_VARS["action"] == "edit") && ($HTTP_GET_VARS["theID"] == $result[0]))
			{
				if (mysql_field_name($query, $i)=="isHidden")
				{
					if ($result[$i] == "Y")
					{
						echo("<td><select name=\"".mysql_field_name($query, $i)."\"><option value=\"N\">N</option><option value=\"Y\" selected>Y</option></select></td>\n");
					}
					else {
						echo("<td><select name=\"".mysql_field_name($query, $i)."\"><option value=\"N\" selected>N</option><option value=\"Y\">Y</option></select></td>\n");
					}
				}
				else {
					echo("<td><input type=\"text\" value=\"$result[$i]\" name=\"".mysql_field_name($query, $i)."\" size=\"20\" maxlength=\"".mysql_field_len($query, $i)."\"></td>\n");
				}
			}
			elseif (mysql_field_name($query, $i) == "sevColour")
			{
				echo("<td bgcolor=\"$result[$i]\">$result[$i]</td>");
			}
			else {
				echo("<td>$result[$i]</td>");
			}
			}
		if ( ($HTTP_GET_VARS["action"] == "edit") && 
			 ($HTTP_GET_VARS["theID"] == $result[0] ) )
		{
			echo("<td><input type=\"hidden\" name=\"tableName\" value=\"".$HTTP_GET_VARS["tableName"]."\"><input type=\"hidden\" name=\"theKey\" value=\"".mysql_field_name($query, 0)."\"><input type=\"hidden\" name=\"theID\" value=\"".$HTTP_GET_VARS["theID"]."\"><a href=\"javascript:document.forms[2].submit()\">Submit</a></td>");
		}
		else {
			echo("<td><a href=\"bugadmin.php?action=edit&theID=$result[0]&tableName=".$HTTP_GET_VARS["tableName"]."\">Edit</a></td>");
		}
		echo("</tr>");
	}
	if ($HTTP_GET_VARS["action"] == "insert")
	{
		echo("<tr>");
		for ($i=1; $i<$fields; $i++)
		{
			if (mysql_field_name($query, $i)=="isHidden")
			{
				echo("<td><select name=\"".mysql_field_name($query, $i)."\"><option value=\"N\" selected>N</option><option value=\"Y\">Y</option></select></td>\n");
			}
			else {
				echo("<td><input type=\"text\" name=\"".mysql_field_name($query, $i)."\" size=\"20\" maxlength=\"".mysql_field_len($query, $i)."\"></td>\n");
			}
		}
		echo("<td><input type=\"hidden\" name=\"tableName\" value=\"".$HTTP_GET_VARS["tableName"]."\"><input type=\"hidden\" name=\"go\" value=\"1\"><a href=\"javascript:document.forms[2].submit()\">Submit</a></td>");
		echo("</tr>");
	}
	else {
		echo("<tr><td colspan=\"$cols\"><a href=\"bugadmin.php?action=insert&tableName=".$HTTP_GET_VARS["tableName"]."\">Insert a New Row</a></td></tr>");
	}
}
?>   
</form>
		</td></tr></table>
       </td>
	  </tr>
	 </table>
  </td>
 </tr>
</table>
  
<?
	include("$path/footer.php");
}
else {
	include("$path/login.php");
}
?>
Return current item: Insecticida