<?
/*************************************************************************************
* sqladmin v2.0 - an sql administration user interface for the web *
* copyright (c) 1997-98 alessandro ve.net <ave.net@scdi.org> *
*************************************************************************************
* this library is free software; you can redistribute it and/or *
* modify it under the terms of the gnu library general public *
* license as published by the free software foundation; either *
* version 2 of the license, or (at your option) any later version. *
* *
* this library 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 *
* library general public license for more details. *
* *
* you should have received a copy of the gnu library general public *
* license along with this library; if not, write to the *
* free software foundation, inc., 59 temple place - suite 330, *
* boston, ma 02111-1307, usa. *
*************************************************************************************/
/* todo:
* - add sort order.
* - add simple view.
* - add some documentation.
*/
/* limitations:
* - works only with msql.
*/
/* history:
* - 97-11-05 (ave.net) corrected a bug with quote.
* - 98-01-01 (ave.net) added a sortcolumn parameter to
* administrationtable function.
* - 98-03-14 (ave.net) added function addtable to enable users to
* add (but not modify) en entry to the database.
* - 98-05-19 (ave.net) submitted to px.
* - 98-10-11 (ave.net) now sqladmin works with php3. the php2 version
* will not be mainteained anymore.
* - 98-10-11 (ave.net) sqladmin is now distributed under the lgpl
* instead of mpl.
*/
function escapeforhtml ($string)
{
$result = $string;
//$result = ereg_replace ("\"", """, $result);
$result = ereg_replace ("<", "<", $result);
$result = ereg_replace (">", ">", $result);
return $result;
}
function displaytuple ($fieldsnumber, $fieldnames,
$fieldlengths, $values, $mode)
{
$result = "";
$result .= "<form method=\"post\"><table border><tr>" .
"<td bgcolor=\"#ccccff\">";
$result .= "<table cellspacing=\"0\" cellpadding=\"0\">";
$fieldindex = 0;
while ($fieldindex < $fieldsnumber)
{
$result .= "<tr><td>" . $fieldnames [$fieldindex] . "</td><td>";
if ($fieldlengths [$fieldindex] <= 128)
{
$result .= "<input type=\"text\" name=\"" .
$fieldnames [$fieldindex] . "\" value=\"" .
$values [$fieldindex] . "\" size=\"64\">";
}
else
{
$result .= "<textarea name=\"" .
$fieldnames [$fieldindex] . "\"" .
" cols=\"64\" rows=\"10\" wrap=\"virtual\">" .
escapeforhtml ($values [$fieldindex]) . "</textarea>";
}
$result .= "<input type=\"hidden\" name=\"old-" .
$fieldnames [$fieldindex] .
"\" value=\"" . escapeforhtml ($values [$fieldindex]) . "\">" .
"</td></tr>";
$fieldindex++;
}
$result .= "<tr><td align=\"center\" colspan=\"2\">";
if ($mode == "modify")
{
$result .= "<input type=\"submit\" name=\"remove\" value=\"remove\">";
$result .= "<input type=\"submit\" name=\"update\" value=\"update\">";
}
else
{ $result .= "<input type=\"submit\" name=\"add\" value=\"add\">"; }
$result .= "</table></td></tr></table></form>";
return $result;
}
function fieldfromtype ($text, $type)
{
if ($type == "int" $type == "uint" $type == "real")
{ $result = $text; }
else
{ $result = "'" . addslashes ($text) . "'"; }
return $result;
}
function executemsql ($database, $command)
{
/*echo "<tt>" . $command . "</tt><hr>";*/
msql ($database, $command);
}
function handleremove ($database, $table, $fieldsnumber,
$fieldnames, $fieldlengths, $fieldtypes)
{
global $remove;
if ($remove != "")
{
$command = "delete from " . $table . " where ";
$fieldindex = 0;
while ($fieldindex < $fieldsnumber)
{
$fieldname = "old-" . $fieldnames [$fieldindex];
global $$fieldname;
$command .= $fieldnames [$fieldindex] . "=" .
fieldfromtype ($$fieldname, $fieldtypes [$fieldindex]);
if ($fieldindex != $fieldsnumber - 1)
{ $command .= " and "; }
$fieldindex++;
}
executemsql ($database, $command);
}
}
function handleupdate ($database, $table, $fieldsnumber,
$fieldnames, $fieldlengths, $fieldtypes)
{
global $update;
if ($update != "")
{
$command = "update " . $table . " set ";
$fieldindex = 0;
while ($fieldindex < $fieldsnumber)
{
$fieldname = $fieldnames [$fieldindex];
global $$fieldname;
$command .= $fieldname . "=" .
fieldfromtype ($$fieldname, $fieldtypes [$fieldindex]);
if ($fieldindex != $fieldsnumber - 1)
{ $command .= ", "; }
$fieldindex++;
}
$command .= " where ";
$fieldindex = 0;
while ($fieldindex < $fieldsnumber)
{
$fieldname = "old-" . $fieldnames [$fieldindex];
global $$fieldname;
$command .= $fieldnames [$fieldindex] . "=" .
fieldfromtype ($$fieldname, $fieldtypes [$fieldindex]);
if ($fieldindex != $fieldsnumber - 1)
{ $command .= " and "; }
$fieldindex++;
}
executemsql ($database, $command);
}
}
function handleadd ($database, $table, $fieldsnumber,
$fieldnames, $fieldlengths, $fieldtypes)
{
global $add;
if ($add != "")
{
$command = "insert into " . $table . " (";
$fieldindex = 0;
while ($fieldindex < $fieldsnumber)
{
$command .= $fieldnames [$fieldindex];
if ($fieldindex != $fieldsnumber - 1)
{ $command .= ", "; }
$fieldindex++;
}
$command .= ") values (";
$fieldindex = 0;
while ($fieldindex < $fieldsnumber)
{
$fieldname = $fieldnames [$fieldindex];
global $$fieldname;
$command .= fieldfromtype ($$fieldname, $fieldtypes [$fieldindex]);
if ($fieldindex != $fieldsnumber - 1)
{ $command .= ", "; }
$fieldindex++;
}
$command .= ")";
executemsql ($database, $command);
}
}
function displayremoveupdate ($database, $table, $sortcolumn,
$fieldsnumber, $fieldnames, $fieldlengths)
{
$result = "";
if ($sortcolumn != "")
{ $sortcolumn = " order by " . $sortcolumn; }
$msqlresult = msql ($database, "select * from " . $table . $sortcolumn);
$tuplesnumber = msql_numrows ($msqlresult);
$tupleindex = 0;
while ($tupleindex < $tuplesnumber)
{
$fieldindex = 0;
while ($fieldindex < $fieldsnumber)
{
$values [$fieldindex] = msql_result ($msqlresult, $tupleindex,
$fieldnames [$fieldindex]);
$fieldindex++;
}
$result .= displaytuple ($fieldsnumber, $fieldnames,
$fieldlengths, $values, "modify");
$tupleindex++;
}
return $result;
}
function displayadd ($fieldsnumber, $fieldnames, $fieldlengths)
{
$result = "";
$fieldindex = 0;
while ($fieldindex < $fieldsnumber)
{
$values [$fieldindex] = "";
$fieldindex++;
}
$result .= displaytuple ($fieldsnumber, $fieldnames,
$fieldlengths, $values, "add");
msql_close ();
return $result;
}
function administrationtable ($database, $table, $sortcolumn)
{
$result = "";
msql_connect ( "localhost");
$msqlresult = msql ($database, "select * from " . $table);
$fieldsnumber = msql_numfields ($msqlresult);
$msqlresult = msql_listfields ($database, $table);
$fieldindex = 0;
while ($fieldindex < $fieldsnumber)
{
$fieldnames [$fieldindex] = msql_fieldname ($msqlresult, $fieldindex);
$fieldlengths [$fieldindex] = msql_fieldlen ($msqlresult, $fieldindex);
$fieldtypes [$fieldindex] = msql_fieldtype ($msqlresult, $fieldindex);
$fieldindex++;
}
handleremove ($database, $table, $fieldsnumber, $fieldnames, $fieldlengths, $fieldtypes);
handleupdate ($database, $table, $fieldsnumber, $fieldnames, $fieldlengths, $fieldtypes);
handleadd ($database, $table, $fieldsnumber, $fieldnames, $fieldlengths, $fieldtypes);
$result .= displayremoveupdate ($database, $table, $sortcolumn, $fieldsnumber, $fieldnames,
$fieldlengths);
$result .= displayadd ($fieldsnumber, $fieldnames, $fieldlengths);
return $result;
}
function addtable ($database, $table)
{
$result = "";
msql_connect ( "localhost");
$msqlresult = msql ($database, "select * from " . $table);
$fieldsnumber = msql_numfields ($msqlresult);
$msqlresult = msql_listfields ($database, $table);
$fieldindex = 0;
while ($fieldindex < $fieldsnumber)
{
$fieldnames [$fieldindex] = msql_fieldname ($msqlresult, $fieldindex);
$fieldlengths [$fieldindex] = msql_fieldlen ($msqlresult, $fieldindex);
$fieldtypes [$fieldindex] = msql_fieldtype ($msqlresult, $fieldindex);
$fieldindex++;
}
handleadd ($database, $table, $fieldsnumber, $fieldnames, $fieldlengths, $fieldtypes);
$result .= displayadd ($fieldsnumber, $fieldnames, $fieldlengths);
return $result;
}
?>
Java Asp PHP .Net XML C/C++ CGI VB Jsp J2ee J2se J2me EJB Servlet Tomcat Resin Struts Weblogic Eclipse ANT GUI JMS Web servise IDEA Webphere Hibernate Spring Jboss Applet Swing Socket Javamail Perl Ajax P2P 安全 模式 框架 测试 开源 游戏
Windows XP Windows 2000 Windows 2003 Windows Me Windows 9.x Linux UNIX 注册表 操作系统 服务器 应用服务器