📄 mainfile.inc
字号:
<?php
/**************************************************************************************
Simple Library System
Copyright (C) 2002 John Mark Matthews
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
For further information, contact:
John Matthews
jmatthews@exostrategy.com
***************************************************************************************/
function reg()
{
$num_args = func_num_args();
$vars = array();
if ($num_args >= 2) {
$method = strtoupper(func_get_arg(0));
if (!((($method != 'SESSION') && ($method != 'GET') && ($method != 'POST') && ($method != 'SERVER') && ($method != 'COOKIE') && ($method != 'ENV')))) {
$varname = "HTTP_{$method}_VARS";
global ${$varname};
for ($i = 1; $i < $num_args; $i++) {
$parameter = func_get_arg($i);
if (isset(${$varname}[$parameter])) {
global $$parameter;
$$parameter = ${$varname}[$parameter];
}
}
}
}
}
reg('SERVER', 'PHP_SELF');
error_reporting(1);
include("config.inc");
mysql_connect($lib_config["dbhost"], $lib_config["dbuname"], $lib_config["dbpass"]);
@mysql_select_db($lib_config["dbname"]) or die ("Unable to select database");
function OpenTable($border=0, $cellspacing=1, $cellpadding=1) {
echo "<table class='normal' align='left' border='$border' cellspacing='$cellspacing' cellpadding='$cellpadding'> ";
}
function CloseTable() {
echo "</table><br><br>";
}
function Row($x,$f="",$s="plain") {
global $row_count;
if($s!="plain") {
if(($row_count % 2)==0) {
$p = "<tr class='row_even' $f>".$x."</tr>" ;
}else{
$p = "<tr class='row_odd' $f> ".$x."</tr>";
}
$row_count++;
}else{
$p = "<tr $f> ".$x."</tr>";
}
return $p;
}
function Cell($x,$f="") { return ($f=="")?("<td align=left valign=top>".$x."</td>"):("<td $f>".$x."</td>"); }
function Paragraph($x,$f="") { return "<p $f>".$x."</p>"; }
function Bold($x) { return "<b>".$x."</b>"; }
function OpenLine() {
echo "<tr><td> ";
}
function CloseLine() {
echo "</td></tr> ";
}
function OpenRow($x) {
global $row_count;
if($x!="plain") {
if(($row_count % 2)==0) {
echo "<tr class='row_even'> ";
}else{
echo "<tr class='row_odd'> ";
}
$row_count++;
}else{
echo "<tr> ";
}
}
function CloseRow() {
echo "</tr>";
}
function OpenCell($more="") {
echo "<td $more>";
}
function CloseCell() {
echo "</td>";
}
function PrintCell($contents,$more="") {
echo "<td class='data' valign='top' $more>".$contents."</td>\n";
}
function PrintHeader($contents,$more="") {
echo "<th class='header' align=left $more>".$contents."</th>\n";
}
function MakeOption($isSelected, $value, $description) {
return "<option ".$isSelected." value='".$value."'>".$description."</option>";
}
function OpenForm($action="", $opt="") {
if($action=="") $action="'$PHP_SELF'";
echo "
<form method='post' action=$action $opt>\n
";
}
function CloseForm() {
echo "
</form>
";
}
function MakeSelectArray($sql,$array) {
$r = mysql_query($sql);
while (list($id, $value) = mysql_fetch_row($r)) {
$array[$id] = $value;
}
return $array;
}
function MakeSelect($name, $default, $select_array, $multi=0, $all_on=false) {
if($multi>0) {
$select_element = "<select multiple size=$multi name=".$name."> ";
}else{
$select_element = "<select name=".$name."> ";
}
while (list($key, $val) = each($select_array)) {
$select_element .= MakeOption(( ($all_on) || ($default == $key) || ($default[$key] > 0)) ? "selected" : "", $key, $val);
}
$select_element .= "</select>";
return $select_element;
}
function admin_menu() {
global $global_person_name;
global $lib_config;
echo "<table border=0 width=100%>";
PrintCell("<img src='./logo.gif' border=0>");
PrintCell("<a onMouseover=\"showtip(this,event,'Find Something!')\" onMouseout=\"hidetip()\" href='./find_item.php'><img src='a_menu1.gif' border=0></a>","width=65 valign=top");
PrintCell("<a onMouseover=\"showtip(this,event,'List All Requests!')\" onMouseout=\"hidetip()\" href='./view_requests.php'><img src='a_menu2.gif' border=0></a>","width=65 valign=top");
PrintCell("<a onMouseover=\"showtip(this,event,'List All Material!')\" onMouseout=\"hidetip()\" href='./find_item.php?item_type=-1'><img src='a_menu3.gif' border=0></a>","width=65 valign=top");
PrintCell("<a onMouseover=\"showtip(this,event,'List Checked Out Items!')\" onMouseout=\"hidetip()\" href='./find_item.php?item_type=-1&status=2'><img src='a_menu4.gif' border=0></a>","width=65 valign=top");
PrintCell("<a onMouseover=\"showtip(this,event,'Add a New Item!')\" onMouseout=\"hidetip()\" href='./add_item.php'><img src='a_menu5.gif' border=0></a>","width=65 valign=top");
PrintCell("<a onMouseover=\"showtip(this,event,'List Users!')\" onMouseout=\"hidetip()\" href='./users.php'><img src='a_menu6.gif' border=0></a>","width=65 valign=top");
PrintCell("<a onMouseover=\"showtip(this,event,'Logout!')\" onMouseout=\"hidetip()\" href='./logout.php'><img src='a_menu7.gif' border=0></a>","width=65 valign=top");
echo "<th align=right valign=top>".$lib_config["deftitle"]."<br>".$global_person_name."</th>
</tr></table>";
}
function user_menu() {
global $global_person_name;
global $global_login_id;
global $lib_config;
echo "<table border=0 width=100%>
<th align=left><img src='./logo.gif' border=0></th>
";
if($global_login_id) {
PrintCell("<a onMouseover=\"showtip(this,event,'Find Something!')\" onMouseout=\"hidetip()\" href='./find_item.php'><img src='u_menu1.gif' border=0></a>"," width=65 valign=top");
PrintCell("<a onMouseover=\"showtip(this,event,'List My Requests!')\" onMouseout=\"hidetip()\" href='./view_requests.php'><img src='u_menu2.gif' border=0></a>"," width=65 valign=top");
PrintCell("<a onMouseover=\"showtip(this,event,'List All Material!')\" onMouseout=\"hidetip()\" href='./find_item.php?item_type=-1'><img src='u_menu3.gif' border=0></a>","width=65 valign=top");
PrintCell("<a onMouseover=\"showtip(this,event,'List My Checked Out Items!')\" onMouseout=\"hidetip()\" href='./find_item.php?item_type=-1&status=2&view_login_id=$global_login_id'><img src='u_menu4.gif' border=0></a>","width=65 valign=top");
PrintCell("<a onMouseover=\"showtip(this,event,'Logout!')\" onMouseout=\"hidetip()\" href='./logout.php'><img src='u_menu5.gif' border=0></a>","width=65 valign=top");
}else{
PrintCell("<a href='./login.php'>Login</a>");
}
echo "<th align=right valign=top>".$lib_config["deftitle"]."<br>".$global_person_name."</th>
</tr></table>";
}
function menu() {
global $global_is_admin;
if($global_is_admin) {
admin_menu();
}else{
user_menu();
}
}
function format_mysql_datetime($mydatetime) {
$s = $mydatetime[0].$mydatetime[1].$mydatetime[2].$mydatetime[3];
$s.= "-".$mydatetime[4].$mydatetime[5];
$s.= "-".$mydatetime[6].$mydatetime[7];
$s.= " ".$mydatetime[8].$mydatetime[9];
$s.= ":".$mydatetime[10].$mydatetime[11];
return $s;
}
function format_blob($b) {
$b = htmlspecialchars($b);
$b = preg_replace("/(\015\012)|(\015)|(\012)/","<br />",$b);
$b = str_replace("<br /><br><br />","<br />",$b);
return $b." ";
}
function PrintItem($item_id) {
$sql = "select item_type_desc, status_desc, i.* from tbl_item i, tbl_item_type t, tbl_status s where ";
$sql.= " i.item_type=t.item_type and i.status=s.status ";
$sql.= " and item_id=$item_id";
$r=mysql_query($sql);
$line = mysql_fetch_array($r);
OpenTable(0,0,0);
echo"<tr class='row_even'><td class='data' width=60></td><td class='data' width=90></td><td class='data' width=100></td><td class='data' width=400></td></tr>\n";
echo"<tr class='row_even'><td class='header' valign='top' align=left colspan=2><img height=8 src='white_corner_8x8.gif' width=8></td>";
echo" <td class='header' valign='top' align=right colspan=1><img height=8 src='white_ULcorner_8x8.gif' width=8></td></tr>\n";
echo"<tr class='row_even'><td class='header' valign='top' colspan=3><b> ".$line["title"]."</b></td></tr>\n";
echo"<tr class='row_odd'><td class='data' height=2 colspan='3'></td></tr>\n";
echo"<tr class='row_odd'><td class='data' align=right valign=top colspan='4'><img height=8 src='white_ULcorner_8x8.gif' width=8></td></tr>\n";
echo"<tr class='row_odd'><td class='data' valign='top'><b> Status</b> </td><td class='data' colspan=3>".format_blob($line["status_desc"])."</td></tr>\n";
echo"<tr class='row_odd'><td class='data' height=4 colspan='4'></td></tr>\n";
echo"<tr class='row_odd'><td class='data' valign='top'><b> Type</b> </td><td class='data' colspan=3>".format_blob($line["item_type_desc"])."</td></tr>\n";
echo"<tr class='row_odd'><td class='data' height=4 colspan='4'></td></tr>\n";
echo"<tr class='row_odd'><td class='data' valign='top'><b> Author</b> </td><td class='data' colspan=3>".format_blob($line["author"])."</td></tr>\n";
echo"<tr class='row_odd'><td class='data' height=4 colspan='4'></td></tr>\n";
echo"<tr class='row_odd'><td class='data' valign='top'><b> Subject</b></td><td class='data' colspan=3>".format_blob($line["subject"])."</td></tr>\n";
echo"<tr class='row_odd'><td class='data' height=4 colspan='4'></td></tr>\n";
echo"<tr class='row_odd'><td class='data' valign='top'><b> Abstract</b></td><td class='data' colspan=3>".format_blob($line["abstract"])."</td></tr>\n";
echo"<tr class='row_odd'><td class='data' height=4 colspan='4'></td></tr>\n";
/*
echo"<tr class='row_even'><td class='data' valign='top'><b>Title</b> </td><td class='data' colspan=2><b>".$line["title"]."</b> <i>".$line["item_type_desc"]."</i> </td><td class='data'> (".$line["status_desc"].")</td></tr>\n";
echo"<tr class='row_even'><td class='data' valign='top'><b>Author</b> </td><td class='data' colspan=3>".format_blob($line["author"])."</td></tr>\n";
echo"<tr class='row_even'><td class='data' valign='top'><b>Subject</b></td><td class='data' colspan=3>".format_blob($line["subject"])."</td></tr>\n";
echo"<tr class='row_even'><td class='data' valign='top'><b>Abstract</b></td><td class='data' colspan=3>".format_blob($line["abstract"])."</td></tr>\n";
echo "<tr><td class='header' valign='top'><b>Status </b></td><td class='data' width=300>".$line["status_desc"]."</td></tr>";
echo "<tr><td class='header' valign='top'><b>Type </b></td><td class='data' >".$line["item_type_desc"]."</td></tr>";
echo "<tr><td class='header' valign='top'><b>Title </b></td><td class='data' >".$line["title"]."</td></tr>";
echo "<tr><td class='header' valign='top'><b>Author </b></td><td class='data' >".format_blob($line["author"])."</td></tr>";
echo "<tr><td class='header' valign='top'><b>Subject </b></td><td class='data' >".format_blob($line["subject"])."</td></tr>";
echo "<tr><td class='header' valign='top'><b>Abstract</b></td><td class='data' >".format_blob($line["abstract"])." </td></tr>";
*/
$sql = "select truncate(avg(grade),0) avg_grade, count(*) total_reviews from tbl_review where item_id=$item_id";
$r=mysql_query($sql);
$line = mysql_fetch_array($r);
if($line["total_reviews"]!=0) {
echo "<tr class='row_odd'><td colspan=2 valign='top'><b> Average Rating</b></td><td class='data' colspan=2>";
echo "<font color=#3333ff>";
for($i=1;$i<=$line["avg_grade"];$i++){
echo "*";
}
echo "</font>";
echo "<font color=#ccccdd>";
for($i=$line["avg_grade"]+1;$i<=5;$i++){
echo "*";
}
echo "</font>";
echo " </td></tr>";
echo"<tr class='row_odd'><td class='data' height=4 colspan='4'></td></tr>\n";
echo "<tr class='row_odd'><td colspan=2 valign='top'><b> Total Number of Ratings</b></td><td class='data' colspan=2 >".$line["total_reviews"]." </td></tr>";
echo"<tr class='row_odd'><td class='data' height=4 colspan='4'></td></tr>\n";
}
echo"<tr class='row_even'><td class='header' valign='top' align=left colspan=2><img height=8 src='white_BLcorner_8x8.gif' width=8></td>";
echo" <td class='header' valign='top' align=right colspan=2><img height=8 src='white_BRcorner_8x8.gif' width=8></td></tr>\n";
echo"<tr class='row_even'><td class='data' colspan='4'> </td></tr>\n";
CloseTable();
}
function format_mysql_date($mydate) {
return date("Y-m-d",strtotime($mydate));
}
function LinkToLogin($login_id, $txt, $edit=0) {
if($edit==0) {
return "
<a href='javascript:{newWin=window.open(\"./person.php?&login_id=$login_id\",\"large\",\"resizable,scrollbars=no,width=230,height=300\");newWin.focus();}'>
$txt
</a>";
}else{
return "
<a href='javascript:{newWin=window.open(\"./person.php?&option=EDIT&login_id=$login_id\",\"large\",\"resizable,scrollbars=no,width=400,height=350\");newWin.focus();}'>
$txt
</a>";
}
}
function LinkToItem($item_id, $txt,$x) {
if($x==1) {
return "
<a class='subtle' href='javascript:{newWin=window.open(\"./item.php?&item_id=$item_id\",\"large\",\"resizable,scrollbars=yes,width=690,height=800\");newWin.focus();}'>
$txt
</a>";
}else{
return "
<a href='javascript:{newWin=window.open(\"./item.php?&item_id=$item_id\",\"large\",\"resizable,scrollbars=yes,width=690,height=800\");newWin.focus();}'>
$txt
</a>".
LinkToReview($item_id);
}
}
function LinkToReview($item_id) {
return "
<a onMouseover=\"showtip(this,event,'Review This!')\" onMouseout=\"hidetip()\"href='javascript:{newWin=window.open(\"./make_review.php?&item_id=$item_id\",\"large\",\"resizable,scrollbars=yes,width=690,height=800\");newWin.focus();}'><img src='./review.gif' border=0></a>";
}
?>
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -