⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 global.php

📁 某自制区政府网站源代码.数据库为Access,包含完整的数据库.
💻 PHP
字号:
<?php


// ------------------------------ -------- ------------------------------ //
//                           * function files *                           //
// ------------------------------ -------- ------------------------------ //


$path = "..";


// --------------------------- function ADDRECORD ---------------------------- //

function addrecord($title,$author,$fromsite,$text,$img,$download,$sortid,$isshow,$ishtml){
global $dbhost,$dbuser,$dbpasswd,$dbname,$ym_article_table;

if ($title==""):
echo "<center>\"文章标题\"不能为空.";
echo "<br><a href=javascript:history.back(1)>点击这里返回.</a>";
exit;

elseif ($text=="" && $img==""):
echo "<center>\"内容\"和\"图片\"不能同时为空.";
echo "<br><a href=javascript:history.back(1)>点击这里返回.</a>";
exit;

else:

$timenow = time();

$sql = "INSERT INTO $ym_article_table (title,author,fromsite,text,img,download,date,sortid,isshow,ishtml) VALUES ('$title','$author','$fromsite','$text','$img','$download','$timenow','$sortid','$isshow','$ishtml')";
mysql_db_query($dbname,$sql) or die ("添加文章失败!");

endif;

} // end addrecord


// --------------------------- function EDITRECORD ---------------------------- //

function editrecord($id,$title,$author,$fromsite,$text,$img,$download,$sortid,$today_view,$view,$isshow,$ishtml){
global $dbhost,$dbuser,$dbpasswd,$dbname,$ym_article_table;

if ($title==""):
echo "<center>\"文章标题\"不能为空.";
echo "<br><a href=javascript:history.back(1)>点击这里返回.</a>";
exit;

elseif ($text=="" && $img==""):
echo "<center>\"内容\"和\"图片\"不能同时为空.";
echo "<br><a href=javascript:history.back(1)>点击这里返回.</a>";
exit;

else:

$timenow = time();

$sql = "UPDATE $ym_article_table SET title='$title',author='$author',fromsite='$fromsite',text='$text',img='$img',download='$download',date='$timenow;',sortid='$sortid',today_view='$today_view',view='$view',isshow='$isshow',ishtml='$ishtml' WHERE id=$id";
mysql_db_query($dbname,$sql);

endif;

} // end editrecord


// --------------------------- function DELRECORD ---------------------------- //

function delrecord($id){
global $dbhost,$dbuser,$dbpasswd,$dbname,$ym_article_table;


$sql = "DELETE FROM $ym_article_table WHERE id=$id";
mysql_db_query($dbname,$sql);


} // end delrecord


// --------------------------- function ISSHOW_PASS ---------------------------- //

function isshow_pass($id){
global $dbhost,$dbuser,$dbpasswd,$dbname,$ym_article_table;


$sql = "UPDATE $ym_article_table SET isshow=1 WHERE id=$id";
mysql_db_query($dbname,$sql);


} // end isshow_pass


// --------------------------- function LIST_PAGES ---------------------------- //

function list_pages($type,$setpage,$setid){
global $dbhost,$dbuser,$dbpasswd,$dbname,$ym_article_table;
global $list_num,$list_page_num,$action;

if ($type>"0" && $type<"999999999"):
 $istype = "WHERE sortid=$type";
 if ($action == "wait"):
 $istype = $istype." && isshow=0";
 endif;
else:
 $type = 0;
 $istype = "";
 if ($action == "wait"):
 $istype = "WHERE isshow=0";
 endif;
endif;




$sql = "SELECT COUNT(*) AS rcnt FROM $ym_article_table $istype ORDER BY id DESC";
$result = mysql_db_query($dbname, $sql);
$row = mysql_fetch_array($result);

$num = $row[rcnt];


if (empty($setid)):
$setid = 0;
endif;

$sql = "SELECT * FROM $ym_article_table $istype ORDER BY id DESC LIMIT $setid, $list_num";
$result = mysql_db_query($dbname, $sql);


// 计算页数 
$pages = ceil($num/$list_num);
$page = ceil($pages/$list_page_num);

if ($setid > 0):
$setpage1 = ceil($setid/$list_num);
$setpage = ceil(($setpage1+1)/$list_page_num);
else:
$setpage = 1;
endif;

if ($pages > $list_page_num):
$pagenum = $list_page_num;
else:
$pagenum = $pages;
endif;

$issetid = ceil(($setid+1)/$list_num);
$issetpage = $issetid % $list_page_num;


// 第一页
if ($setpage > 1):
echo "<a title='第一页' href='list.php?action=".$action."&type=".$type."&setpage=1&setid=0'>[1]</a>...\n";
endif;

// 上一列
if ($setpage > 1):
$lastpage = $setpage-1;
$lastsetid = ($setpage-2)*$list_page_num*$list_num;
echo "<a title='上一列' href='list.php?action=".$action."&type=".$type."&setpage=".$lastpage."&setid=".$lastsetid."'>[<<]</a> - \n";
endif;

// 上一页
if ($setid > 0):

if ($issetpage == 1):
$newsetpage = $setpage-1;
else:
$newsetpage = $setpage;
endif;

$presetid = $setid-$list_num;
echo "<a title='上一页' href='list.php?action=".$action."&type=".$type."&setpage=".$newsetpage."&setid=".$presetid."'>[<]</a> \n";
endif;

// 列出页
$i1 = ($setpage-1)*$list_page_num;
for ($i=$i1; $i<($i1+$pagenum) && $i<$pages; $i++)
{
$newsetid=$list_num*$i;

if (($setid/$list_num) == $i):
echo "<b><font color=red>[".($i+1)."]</font></b> \n";
else:
echo "<a href='list.php?action=".$action."&type=".$type."&setpage=".$setpage."&setid=".$newsetid."'>[".($i+1)."]</a> \n";
endif;

}

// 下一页
if ($pages!=0 && ($setid/$list_num+1)!=$pages && ($setid/$list_num+1)<=$pages||$setid==1):

if ($list_page_num-$issetpage == 0 || $issetpage == 0):
$newsetpage = $setpage+1;
else:
$newsetpage = $setpage;
endif;

$newsetid = $setid+$list_num;
echo "<a title='下一页' href='list.php?action=".$action."&type=".$type."&setpage=".$newsetpage."&setid=".$newsetid."'>[>]</a> \n";
endif;

// 下一列
if ($pages!=0 && $pages>$list_page_num && $setpage<$page):
$nextpage = $setpage+1;
$nextsetid = $setpage*$list_page_num*$list_num;
echo "- <a title='下一列' href='list.php?action=".$action."&type=".$type."&setpage=".$nextpage."&setid=".$nextsetid."'>[>>]</a>\n";
endif;

// 最后一页
if ($pages>$list_page_num && $setpage<$page):
$lastpage = $list_num*($pages-1);
echo "...<a title='最后一页' href='list.php?action=".$action."&type=".$type."&setpage=".$page."&setid=".$lastpage."'>[".$pages."]</a>\n";
endif;



} // end list_pages


// --------------------------- function LIST_ARTICLE ---------------------------- //

function list_articles($type,$setid){
global $dbhost,$dbuser,$dbpasswd,$dbname,$ym_article_table,$ym_article_sort_table;
global $list_num,$action,$datetxt;


if ($type>"0" && $type<"999999999"):
 $istype = "WHERE sortid=$type";
 if ($action == "wait"):
 $istype = $istype." && isshow=0";
 endif;
else:
 $type = 0;
 $istype = "";
 if ($action == "wait"):
 $istype = "WHERE isshow=0";
 endif;
endif;



$sql = "SELECT COUNT(*) AS rcnt FROM $ym_article_table $istype ORDER BY id DESC";
$result = mysql_db_query($dbname, $sql);
$row = mysql_fetch_array($result);
$num = $row[rcnt];



$num = $row[rcnt];
if ($num <= 0):
echo "<center>未找到任何记录<br><br>";
endif;


if (empty($setid)):
$setid = 0;
endif;

$sql = "SELECT * FROM $ym_article_table $istype ORDER BY id DESC LIMIT $setid, $list_num";
$result = mysql_db_query($dbname, $sql);

while ($row=mysql_fetch_array($result)){

// 获取分类名称
$sort_sql = "SELECT * FROM $ym_article_sort_table WHERE id='$row[sortid]'";
$sort_result = mysql_db_query($dbname, $sort_sql);
$objresult = mysql_fetch_object($sort_result);
$sortname = $objresult->name;



// 显示列表记录
echo "<table border=0 cellpadding=3 cellspacing=0 width=100%>\n";

echo "<tr>\n";
echo "<td width=5%><b>$row[id]</b></td>\n";
echo "<td width=70%>[<a href=\"list.php?type=$row[sortid]&action=$action\">$sortname</a>] \n";
echo "<a href=\"./show.php?id=$row[id]\" title=\"点击查看\" target=_blank>$row[title]</a>\n";
$date = date($datetxt,$row[date]);
echo "<font color=#c0c0c0> -  $date</font></td>\n";
echo "<td width=25% align=right>\n";
if (!$row[isshow] == "1"):
echo "[<a href=\"./list.php?isshow=$row[id]&action=$action&type=$type\">通过</a>]";
endif;
echo "[<a href=\"./edit.php?id=$row[id]\">编辑</a>]";
echo "[<a href=\"./delete.php?id=$row[id]\">删除</a>]\n";
echo "</td>\n";
echo "</tr>\n";

echo "</table>\n";
echo "<br>\n";

} // while



} // end list_articles


// --------------------------- function ALL_AND_THIS ---------------------------- //

function all_and_this() {
global $dbhost,$dbuser,$dbpasswd,$dbname,$ym_article_table;
global $path,$type;



echo "<img src='../images/list.gif' width=16 heigth=16> 本类总数/文章总数:";

// 文章总数
$allsql = "SELECT COUNT(*) AS rcnt FROM $ym_article_table";
$allresult = mysql_db_query($dbname, $allsql);
$allrow = mysql_fetch_array($allresult);
$allnum = $allrow[rcnt];

// 本类总数
if ($type > "0" && $type < "999999999"):
$istype = "WHERE sortid=$type";
else:
$istype = "";
endif;

$thesql = "SELECT COUNT(*) AS rcnt FROM $ym_article_table $istype ORDER BY id DESC";
$theresult = mysql_db_query($dbname, $thesql);
$therow = mysql_fetch_array($theresult) or die ("数据库连接失败1");
$thenum = $therow[rcnt];

echo "<font color=#FF0000><b>".$thenum."</b>/<b>".$allnum."</b></font>\n";



} // end all_and_this


// --------------------------- function GOTO ---------------------------- //

function goto($type){
global $dbhost,$dbuser,$dbpasswd,$dbname,$ym_article_sort_table;
global $action;


$typesql = "SELECT COUNT(*) AS rcnt FROM $ym_article_sort_table ORDER BY id";
$typeresult = mysql_db_query($dbname, $typesql);
$typerow = mysql_fetch_array($typeresult);

$typesql = "SELECT * FROM $ym_article_sort_table ORDER BY id";
$typeresult = mysql_db_query($dbname, $typesql);


echo "<form>\n";
echo "<td width=140 align=right valign=bottom>\n";

echo "<img src='../images/goto.gif' width=16 heigth=16> ";
echo "<select name=go onChange='window.location=form.go.options[form.go.selectedIndex].value' size=1 style='color:#000000; border-style:solid; border-width:1; background-color:#efefef'>\n";
echo "<option value=list.php>文章列表</option>\n";
while ($typerow=mysql_fetch_array($typeresult)) {
if ($type == $typerow[id]):
echo "<option value='list.php?action=".$action."&type=".$typerow[id]."' selected>".$typerow[name]."</option>\n";
else:
echo "<option value='list.php?action=".$action."&type=".$typerow[id]."'>".$typerow[name]."</option>\n";
endif;
}

echo "</select></td></form>\n";



} // end goto


// --------------------------- function SEARCH ---------------------------- //

function search($keyword,$type,$title,$text){
global $dbhost,$dbuser,$dbpasswd,$dbname,$ym_article_table,$ym_article_sort_table,$datetxt;


// 如果类别为空, 类别为所有
if (empty($type)):
$type = 0;
endif;

// 判断搜索范围
if (!$title == 1):
$title = 0;
endif;

if (!$text == 1):
$text = 0;
endif;


// 如果关键字为空, 返回列表
if (empty($keyword)):
echo "<center><br>未输入关键字<br><br>";
echo "<a href=javascript:history.back(1)>点击这里返回</a>";
exit;
endif;


// 如果名称和简介均未选择, 返回列表
if ($title == 0 && $text == 0):
echo "<center><br>未选择搜索范围\"名称和简介\"<br><br>";
echo "<a href=javascript:history.back(1)>点击这里返回</a>";
exit;
endif;

// 类别语句
if ($type == 0):
$istype = "";
else:
$istype = "sortid=$type &&";
endif;

// 查询语句
if ($text == 0):
$issearch = "WHERE $istype title LIKE '%$keyword%'";
elseif ($title == 0):
$issearch = "WHERE $istype text LIKE '%$keyword%'";
else:
$issearch = "WHERE $istype (title LIKE '%$keyword%' || text LIKE '%$keyword%')";
endif;




$sql = "SELECT COUNT(*) AS rcnt FROM $ym_article_table $issearch ORDER BY id DESC";
$result = mysql_db_query($dbname, $sql);
$row = mysql_fetch_array($result);
$num = $row[rcnt];

$sql = "SELECT * FROM $ym_article_table $issearch ORDER BY id DESC";
$result = mysql_db_query($dbname, $sql);

// 如果记录为0, 显示
if ($num <=0):
echo "<center><br><a href=./list.php>未找到您需要的记录</a>";
echo "<a href=javascript:history.back(1)>点击这里返回</a>";
endif;

while ($row=mysql_fetch_array($result)){

// 获取分类名称
$sort_sql = "SELECT * FROM $ym_article_sort_table WHERE id='$row[sortid]'";
$sort_result = mysql_db_query($dbname, $sort_sql);
$objresult = mysql_fetch_object($sort_result);
$type = $objresult->name;


// 显示列表记录
echo "<table border=0 cellpadding=3 cellspacing=0 width=100%>\n";

echo "<tr>\n";
echo "<td width=5%><b>$row[id]</b></td>\n";
echo "<td width=70%>[<a href=\"list.php?type=$row[sortid]&action=$action\">$type</a>] \n";
echo "<a href=\"./show.php?id=$row[id]\" title=\"点击查看\" target=_blank>$row[title]</a>\n";
$date = date($datetxt,$row[date]);
echo "<font color=#c0c0c0> -  $date</font></td>\n";
echo "<td width=25% align=right>\n";
if (!$row[isshow] == "1"):
echo "[<a href=\"./list.php?isshow=$row[id]&action=$action&type=$type\">通过</a>]";
endif;
echo "[<a href=\"./edit.php?id=$row[id]\">编辑</a>]";
echo "[<a href=\"./delete.php?id=$row[id]\">删除</a>]\n";
echo "</td>\n";
echo "</tr>\n";

echo "</table>\n";
echo "<br>\n";

}



} // end search


// ------------------------------ function ADMINMENU ------------------------------ //

function adminmenu(){
global $dbhost,$dbuser,$dbpasswd,$dbname,$ym_article_user_table,$cookie_user;

// get mygroupid

$sql = "SELECT groupid FROM $ym_article_user_table WHERE username='$cookie_user'";
$result = mysql_db_query($dbname, $sql);
$objresult = mysql_fetch_object($result);
$mygroupid = $objresult->groupid;


echo "<table class=border border=1 cellpadding=3 cellspacing=0 bordercolor=#111111 width=95%>\n";
echo "<tr>\n";
echo "<td bgcolor=#EFEFEF width=100%><img src='../images/list.gif'> 控制面板</td>\n";
echo "</tr>\n";
echo "<tr>\n";
echo "<td class=shadow2 width=100% height=300 align=center valign=top><br>\n";


echo "<img src='../images/move.gif'> <b>文 章 管 理</b><br><br>\n";
echo "<img src='../images/edit.gif'> <a class=shadow2 href='./list.php'>文 章 列 表</a><br><br>\n";
echo "<img src='../images/edit.gif'> <a class=shadow2 href='./add.php'>添 加 文 章</a><br><br>\n";
echo "<img src='../images/edit.gif'> <a class=shadow2 href='./list.php?action=wait'>候 选 文 章</a><br><br>\n";
if ($mygroupid == "1"):
echo "<img src='../images/edit.gif'> <a class=shadow2 href='./move.php'>批 量 转 移</a><br><br>\n";
echo "<img src='../images/move.gif'> <b><a class=shadow2 href='./sort.php'>分 类 管 理</a></b><br><br>\n";
echo "<img src='../images/move.gif'> <b><a class=shadow2 class=shadow2 href='./user.php'>用 户 管 理</a></b><br><br>\n";
else:
echo "<img src='../images/move.gif'> <b><a class=shadow2 class=shadow2 href='./user.php'>修 改 密 码</a></b><br><br>\n";
endif;
echo "<img src='../images/move.gif'> <b><a class=shadow2 class=shadow2 href='./list.php?action=logout'>注 

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -