<?
/////////////////////////////////////////////////////
//  险情文章管理 1.0正式版本--php文本存储格式      //
//  作者：上海财经大学99国际工管    险情           //
//  email：indraw@sina.com                         //
//  qq：   30467826                                //
//  技术支持：http://shcj.51.net/wdb               //
//  最新演示：http://xqart.126.com                 //
//  2002/4/10                                      //
//  最新下载地址 http;//shcj.51.net/wdb            //
/////////////////////////////////////////////////////
/////////////////分页函数/////////////////////////////
 function page_menu($totalnum) {
global $p,$PHP_SELF, $form,$type,$title,$keyword,$text,$searchtype;

        $recnum = 20;
        $listnum = 10;
        $pagenum = $p;
        if(!$p){$pagenum = 1; $p = 1;}
         if($p > $listnum) {
                if ($p == 1) {
                        echo "\n";
                }
                else {
                        $PrevPage = $p-1;
                        echo "<a href=$PHP_SELF?form=$form&type=$type&p=1&text=$text&keyword=$keyword&title=$title&searchtype=$searchtype title=首页>[1]</a>\n";
                }
        }
        $term = $listnum;$f = 1;$l = $term;while ($f <= $totalnum) {
        if (($f <= $p) && ($p <= $l)) {
                $prevp = $f - 1;
                if ($prevp > 0) {
                        echo "<a href=$PHP_SELF?form=$form&type=$type&p=$prevp&text=$text&keyword=$keyword&title=$title&searchtype=$searchtype title=\"前 $listnum页\">[Prev]</a>-";
                }
                else {
                echo "\n";
                }
                if ($l <= $totalnum) {
                        for ($page = $f; $page <= $l; $page++) {
                                if ($page == $p) {
                                        echo "[<font color=red title=当前页>$page</font>]";
                                }
                                else {
                                        echo "<a href=$PHP_SELF?type=$type&p=$page&text=$text&keyword=$keyword&title=$title&searchtype=$searchtype title=$page页>[$page]</a>";
                                }
                        }
                }
                else {
                        for ($page = $f; $page <= $totalnum; $page++) {
                                if ($page == $p) {
                                        echo "[<font color=red title=当前页>$page</font>]";
                                }
                                else {
                                        echo "<a href=$PHP_SELF?form=$form&type=$type&p=$page&text=$text&keyword=$keyword&title=$title&searchtype=$searchtype  title=$page页>[$page]</a>";
                                }
                        }
                }
                $nextp = $l + 1;
                if ($nextp <= $totalnum) {
                        echo "-<a href=$PHP_SELF?form=$form&type=$type&p=$nextp&text=$text&keyword=$keyword&title=$title&searchtype=$searchtype title=\"后 $listnum页\">[Next]</a>";
                }
                else {
                        echo "";
                }
        }
        $f = $f + $term;
        $l = $l + $term;
        }
        if($nextp <= $totalnum){
                echo "<a href=$PHP_SELF?form=$form&type=$type&p=$totalnum&text=$text&keyword=$keyword&title=$title&searchtype=$searchtype title=尾页>[$totalnum]</a>\n";
        }
}
/////////////////安检函数/////////////////////////////
 function safe_cover($s) {
            $s=str_replace("|","│",$s);
            $s=str_replace("<","&lt",$s);
            $s=str_replace(">","&gt",$s);
            $s=str_replace("\$","￥",$s);
            $s=str_replace("\t","",$s);
            $s=str_replace("\n","<br>",$s);
            $s=str_replace("\r","",$s);
            $bad="他妈的|妈的|他爸的|操你妈|狗娘的|狗日的|shit|日你娘|日你妈|娘的|日你姐|fuck|龟儿子|龟孙子|兔崽子";
            $bad_array=explode("|",$bad);
            $co=count($bad_array)-1;
            for ($i=0;$i<=$co;$i++) {
                $s=str_replace($bad_array[$i],"xxx",$s);
                }
            return $s; }
/////////////////获取文件类型函数/////////////////////
 function get_file_type($type1)
{
        if ( !$type1 ) { $ftype = "unknown.gif "; return $ftype; }
            if( eregi($type1, "html")) { $ftype = "html.gif"; }
        elseif( eregi($type1, "exe")) { $ftype = "exe.gif"; }
        elseif( eregi($type1, "zip|gz|tar")) { $ftype = "zip.gif"; }
        elseif( eregi($type1, "rar")) { $ftype = "rar.gif"; }
        elseif( eregi($type1, "gif")) { $ftype = "gif.gif"; }
        elseif( eregi($type1, "php|php3|phtml|inc")) { $ftype = "php3.gif"; }
        elseif( eregi($type1, "jpeg|jpg")) { $ftype = "jpg.gif"; }
        elseif( eregi($type1, "bmp")) { $ftype = "bmp.gif"; }
        elseif( eregi($type1, "mid")) { $ftype = "mid.gif"; }
        elseif( eregi($type1, "wav")) { $ftype = "wav.gif"; }
        elseif( eregi($type1, "mp3")) { $ftype = "mp3.gif"; }
        elseif( eregi($type1, "ra")) { $ftype = "ra.gif"; }
        elseif( eregi($type1, "mpeg|asf|mpg|avi|asx|mov")) { $ftype = "mpeg.gif"; }
        elseif( eregi($type1, "doc")) { $ftype = "doc.gif"; }
        elseif( eregi($type1, "hwp")) { $ftype = "hwp.gif"; }
        elseif( eregi($type1, "xls")) { $ftype = "xls.gif"; }
        elseif( eregi($type1, "ppt")) { $ftype = "ppt.gif"; }
        elseif( eregi($type1, "cgi|pl|pm")) { $ftype = "cgi.gif"; }
        elseif( eregi($type1, "js|css|class")) { $ftype = "js.gif"; }
        elseif( eregi($type1, "swf")) { $ftype = "swf.gif"; }
        elseif( eregi($type1, "txt")) { $ftype = "text.gif"; }
        else { $ftype = "unknown.gif"; }
        return $ftype;
 }
/////////////////错误显示函数/////////////////////
function error_0($msg,$turn_page)    {
global $main_color,$fuse_color,$biankuang_color;
 echo "<div align=center><TABLE bgColor=$main_color border=0 cellSpacing=0 height=30 width=360>";
 echo "<TBODY>";
 echo "<TR>";
 echo "<TD vAlign=center width='100%' bgcolor=$main_color>&nbsp;「冰的中国」文章系统——<font color=red>执行错误</font></TD>";
 echo "</TR></TBODY></TABLE></DIV>";
 echo "<table align=center bgcolor=$main_color border=0 cellpadding=3 cellspacing=1 width='360'>";
 echo "<tbody>";
 echo "<tr bgcolor=$fuse_color>";
 echo "<td>注意：<br>&nbsp;&nbsp;&nbsp;&nbsp;<font color=red>*$msg</font></td>";
 echo "</tr>";
 echo "<tr bgcolor=$fuse_color>";
 echo "<td>";
 echo "<p align='right'> 若您有什么问题，请联系：<a HREF='http://www.icycn.com' TARGET='blank'>ICYCN.COM</a>&nbsp;&nbsp;<input name=Submit type=submit value=\"按此返回\" onClick=history.go(-1) class=border style=\"BACKGROUND-COLOR: $main_color; COLOR: #000000\">&nbsp;&nbsp;";
 echo "</p>";
 echo "</td> ";
 echo "</tr> ";
 echo "</tbody>";
 echo "</table>";
 echo "</td></tr>\n";
echo "<TR><TD colspan='2' vAlign=top width='100%'><P align=right class=small><A href='http://www.icycn.com'><FONTcolor=#000000>Powered by Xqart 1.0</FONT></A></P></TD></TR></TBODY></TABLE></DIV></TD></TR>";
echo "</table>\n";
echo "<hr width=735 color=$biankuang_color>\n";
 require("foot.php");
  }
/////////////////正确显示函数/////////////////////
function error_1($msg,$turn_page)    {
global $main_color,$fuse_color,$biankuang_color;
 echo "<div align=center><TABLE bgColor=$main_color border=0 cellSpacing=0 height=30 width=360>";
 echo "<TBODY>";
 echo "<TR>";
 echo "<TD vAlign=center width='100%' bgcolor='$main_color'>&nbsp;「冰的中国」文章系统——<font color=green>执行正确</font></TD>";
 echo "</TR></TBODY></TABLE></DIV>";
 echo "<table align=center bgcolor=$main_color border=0 cellpadding=3 cellspacing=1 width='360'>";
 echo "<tbody>";
 echo "<tr bgcolor='$fuse_color'>";
 echo "<td>注意：<br>&nbsp;&nbsp;&nbsp;&nbsp;<font color=green>*$msg</font></td>";
 echo "</tr>";
 echo "<tr bgcolor=$fuse_color>";
 echo "<td>";
 echo "<p align='right'> 若您有什么问题，请联系：<a HREF='http://www.icycn.com' TARGET='blank'>ICYCN.COM</a>&nbsp;&nbsp;<input name=Submit type=submit value=\"按此返回\" onClick=\"location.href='$turn_page'\" class=border style=\"BACKGROUND-COLOR: $main_color; COLOR: #000000\">&nbsp;&nbsp;";
 echo "</p>";
 echo "</td> ";
 echo "</tr> ";
 echo "</tbody>";
 echo "</table>";
 echo "</td></tr>\n";
echo "<TR><TD colspan='2' vAlign=top width='100%'><P align=right class=small><A href='http://www.icycn.com'><FONTcolor=#000000>Powered by Xqart 1.0</FONT></A></P></TD></TR></TBODY></TABLE></DIV></TD></TR>";
echo "</table>\n";
echo "<hr width=735 color=$biankuang_color>\n";
 require("foot.php");
}
function error_2($msg,$turn_page)    {
global $main_color,$fuse_color,$biankuang_color;
 echo "<div align=center><br><br><br><br><br><TABLE bgColor=$main_color border=0 cellSpacing=0 height=30 width=360>";
 echo "<TBODY>";
 echo "<TR>";
 echo "<TD vAlign=center width='100%' bgcolor='$main_color'>&nbsp;「冰的中国」文章系统——<font color=green>执行正确</font></TD>";
 echo "</TR></TBODY></TABLE></DIV>";
 echo "<table align=center bgcolor=$main_color border=0 cellpadding=3 cellspacing=1 width='360'>";
 echo "<tbody>";
 echo "<tr bgcolor='$fuse_color'>";
 echo "<td>注意：<br>&nbsp;&nbsp;&nbsp;&nbsp;<font color=green>*$msg</font></td>";
 echo "</tr>";
 echo "<tr bgcolor=$fuse_color>";
 echo "<td>";
 echo "<p align='right'> 若您有什么问题，请联系：<a HREF='http://www.icycn.com' TARGET='blank'>ICYCN.COM</a>&nbsp;&nbsp;<input name=Submit type=submit value=\"按此返回\" onClick=\"location.href='$turn_page'\" class=border style=\"BACKGROUND-COLOR: $main_color; COLOR: #000000\">&nbsp;&nbsp;";
 echo "</p>";
 echo "</td> ";
 echo "</tr> ";
 echo "</tbody>";
 echo "</table>";
 echo "</td></tr>\n";
echo "<TR><TD colspan='2' vAlign=top width='100%'><P align=right class=small><A href='http://www.icycn.com'><FONTcolor=#000000>Powered by XqArt 1.08</FONT></A></P></TD></TR></TBODY></TABLE></DIV></TD></TR>";
echo "</table>\n";
  }
////////////////////////头文件////////////////////////////////////////////////////
function head_form(){
global $main_color,$fuse_color,$web_title,$site_url;
echo "<LINK href=\"style.css\" type=text/css rel=stylesheet>";
echo "<title>文章管理</title>\n";
echo "<center>\n";
echo "<table border=0 bgcolor=#eeeeee cellspacing=1 cellpadding=3 width=100%>\n";
echo "<tr bgcolor=#eeeeee>\n";
echo "<td>\n";
echo "<img src=../images/arrow2.gif heigth=16>\n";
echo "<a href=index.php>文章首页</a>\n";
get_form_type();
echo "</td>\n";
echo "</tr>\n";
echo "<tr bgcolor=$fuse_color walign=middle>\n";
echo "<td>\n";
echo ">> 欢迎光临 <a href='$site_url'>$web_title</a> 文章管理中心\n";
echo "</td>\n";
echo "</tr>\n";
echo "</table>\n";
echo "<table border=0 cellpadding=10 cellspacing=0 style='border-collapse:collapse' bordercolor=$biankuang_color width=735>\n";
echo "<tr>\n";
echo "<td width=735 valign=bottom align=left>\n";
}

/////////////////////获取一级二级分类名称//////////////////////////////////////////////////
function get_form_type(){
global $get_type_name;
$file_sort=file("data/"."xq.php");
$i=0;
 while ($file_sort[$i]) {
        $file_name=explode("|",$file_sort[$i]);
        if ($file_name[0]=="form")
        echo "<img src=../images/arrow5.gif heigth=16>"."&nbsp;<a class=shadow2 href=listform.php?form=$file_name[1]>$file_name[2]"."</a>\n";
        else
        $get_type_name=$get_type_name."<option value=$file_name[1]>$file_name[2]</option>";
        $i++;
        }
}
/////////////////////获取一级分类名称//////////////////////////////////////////////////
function get_form(){
$file_sort=file("data/"."xq.php");
$i=0;
 while ($file_sort[$i]) {
        $file_name=explode("|",$file_sort[$i]);
        if ($file_name[0]=="form")
        echo "<img src=./images/dot.gif heigth=16>"."&nbsp;<a class=shadow2 href=listform.php?form=$file_name[1]>$file_name[2]"."</a>\n";
        $i++;
        }
}
/////////////////////获取二级分类名称///////////////////////////////////////////////////
function get_type(){
$file_sort=file("data/"."xq.php");
 $i=0;
 while ($file_sort[$i]) {
        $file_name=explode("|",$file_sort[$i]);
        if ($file_name[0]=="type"){
        echo "<option value=".$file_name[1].">".$file_name[2]."</option>\n";
        }
        $i++;
        }
}
//////////////////获取专题名称////////////////////////////////////////////////
function get_spe(){
$file_sort=file("data/xq.cgi");
$file_count=count($file_sort)-1;
for ($i=0;$i<=$file_count;$i++) {
        $file_name=explode("|",$file_sort[$i]);
        echo "<option value=".$file_name[1].">".$file_name[2]."</option>";
        }
}
/////////////////文件分行写入尾-写入最后一行，去掉最上面一行//////
function add_new_file($dir,$file_new,$file_num)    {
$file_typenew=file("$dir");
$file_typenew_count=count($file_typenew);

if ($file_typenew_count<$file_num) {
        $fp_typenew=fopen("$dir","a+");
        flock($fp_typenew,3);
        fwrite($fp_typenew,$file_new);
        fclose($fp_typenew);}

elseif ($file_typenew_count>=$file_num) {

       $fp_typenew=fopen("$dir","w");
        flock($fp_typenew,3);
          for ($i=1;$i<=$file_num-1;$i++) {
                fwrite($fp_typenew,$file_typenew[$i]);
                }
        fwrite($fp_typenew,$file_new);
        fclose($fp_typenew);
                                   }
  }
//////////////////////////////////////////////////
?>