<?
require"ygl.php";
if(!isset($ses_user_id)||!isset($ses_user_psd)){errorview("对不起，你没有登陆！！");exit;}
$user_login_id=$ses_user_id;
$user_login_psd=$ses_user_psd;
read_user_zl($user_login_id);
$lines = file("user/$user_login_id.php");
while (list($tmpkey,$line) = each($lines))
   {
   $line=ereg_replace("\n","",$line);
   list($oo,$user_id,$username,$userpass1,$birth,$star,$usersex,$userblood,$userfrom,$userhobby,$userpage,$useroicq,$usericq,$usermail,$usermobi,$usertel,$useraddr,$usercode,$userly,$userdate)=split("\t",$line);
   }
if($userpass1!=$ses_user_psd){errorview("非法登陆！");exit;}
if($favpage=="main"||$favpage=="")favorites_main();
if($favpage=="add")add();
if($favpage=="fav_add")my_add();
if($favpage=="xiu")xiu();
if($favpage=="fav_xiu")fav_xiu();
if($favpage=="del")fav_del($del_no);
#####################################
function favorites_main()
{
global $user_login_id,$page,$perpage;
$ynhead2="1";
$title="收藏夹列表";
include"header.php";
if(file_exists("favorites/$user_login_id.php"))
$login_file=file("favorites/$user_login_id.php");
$size=count($login_file);
$ii=1; $j=$size;
while ($j>0) {
 $j=$j-$perpage;
}
print<<<EOT
<table width="750" border="1"  bordercolorlight="#B5E1F7" bordercolordark="#FFFFFF" align="center" cellpadding="0" cellspacing="0">
  <tr>
    <td colspan="4">
      <div align="right">共有 $size 个网站被收藏　　　　<a href=favorites.php?favpage=add>添加网站</a></div>
    </td>
    <td bgcolor="#B5E1F7">&nbsp;</td>
  </tr>
  <tr>
    <td width="197">
      <div align="center">网站名称</div>
    </td>
    <td width="356">
      <div align="center">备注</div>
    </td>
    <td width="89">
      <div align="center">登记时间</div>
    </td>
    <td width="46">
      <div align="center">修改</div>
    </td>
    <td width="50">
      <div align="center">删除</div>
    </td>
  </tr>
  <tr>
    <td colspan="5" height="4" bgcolor="#B5E1F7"></td>
  </tr>
EOT;

if ($page == "") {$page=$ii;}
$pages=$page-1;
$pages=$page*$perpage-$perpage;
for($i=$pages; $i<$pages+$perpage; $i++) {
 $linea=$login_file[$i];
 $linea=ereg_replace("\n", "", $linea);
 if ($linea != "") {
 $lines1a=file("favorites/$user_login_id.php");
 while (list($tmpkey, $line1a) = each($lines1a))
  {
  $line1=ereg_replace("\n", "", $line1);
  list($wzno,$wzname,$wzurl,$wzgen,$add_day)=split("\t",$linea);
   }
if($wzgen=="")$wzgen="&nbsp;";
      print"
  <tr>
    <td width=\"197\">
      <div align=\"center\"><a href=$wzurl target=_blank>$wzname</a></div>
    </td>
    <td width=\"356\">
      <div align=\"center\">$wzgen</div>
    </td>
    <td width=\"89\">
      <div align=\"center\">$add_day</div>
    </td>
    <td width=\"46\">
      <div align=\"center\"><a href=favorites.php?favpage=xiu&xiu_no=$wzno>修改</a></div>
    </td>
    <td width=\"50\">
      <div align=\"center\"><a href=favorites.php?favpage=del&del_no=$wzno>删除</a></div>
    </td>
  </tr>
 ";

 }
 }
 print"</table><div align=center>";
 $j=$size;
while ($j>0) {
 if ($page != $ii) {print "<a href=favorites.php?favpage=main&page=$ii>";};
 print "[$ii]";
 if ($page != $ii) {print "</a>";};
 $j=$j-$perpage;
 $ii++;
}
 print"</div>";
 include"footer.php";
exit;
}
######################
function add()
{
$ynhead2="1";
$title="添加网站";
include"header.php";
print<<<EOT
<form name="form1" method="post" action="favorites.php">
  <input type="hidden" name="favpage" value="fav_add">
  <table width="75%" border="1" cellspacing="0" cellpadding="0" bordercolorlight="#B5E1F7" bordercolordark="#FFFFFF" align="center">
    <tr>
      <td colspan="2" bgcolor="#B5E1F7"><b><font color="#000066">添加网站：</font></b></td>
    </tr>
    <tr>
      <td width="27%">
        <div align="center">网站名称：</div>
      </td>
      <td width="73%">
        <input type="text" name="wzname" size="40" class=text>
      </td>
    </tr>
    <tr>
      <td width="27%">
        <div align="center">网　　址：</div>
      </td>
      <td width="73%">
        <input type="text" name="wzurl" size="40" class=text>
      </td>
    </tr>
    <tr>
      <td width="27%">
        <div align="center">备　　注：</div>
      </td>
      <td width="73%">
        <input type="text" name="wzgen" size="40" class=text>
      </td>
    </tr>
    <tr>
      <td colspan="2">
        <div align="center"></div>
        <div align="center">
          <input type="submit" name="Submit" value="提  交" class=text>
          　　
          <input type="submit" name="Submit2" value="重　置" class=text>
        </div>
      </td>
    </tr>
  </table>
</form>
EOT;
include"footer.php";
exit;
}
######################
function xiu()
{
global $user_login_id,$xiu_no;
$data=file("favorites/$user_login_id.php");
for ($x=0;$x<=count($data);$x++){
$read_data=explode("\t",$data[$x]);
if ($read_data[0]==$xiu_no)$old_data=$data[$x];
$dis_data=explode("\t",$old_data);
}
$ynhead2="1";
$title="修改网站";
include"header.php";
print<<<EOT
<form name="form1" method="post" action="favorites.php">
  <input type="hidden" name="favpage" value="fav_xiu">
  <input type="hidden" name="xiu_no" size="40" value=$dis_data[0] class=text>
  <table width="75%" border="1" cellspacing="0" cellpadding="0" bordercolorlight="#B5E1F7" bordercolordark="#FFFFFF" align="center">
    <tr>
      <td colspan="2" bgcolor="#B5E1F7"><b><font color="#000066">修改网站：</font></b></td>
    </tr>
    <tr>
      <td width="27%">
        <div align="center">网站名称：</div>
      </td>
      <td width="73%">
        <input type="text" name="wzname" size="40" value=$dis_data[1] class=text>
      </td>
    </tr>
    <tr>
      <td width="27%">
        <div align="center">网　　址：</div>
      </td>
      <td width="73%">
        <input type="text" name="wzurl" size="40" value=$dis_data[2] class=text>
      </td>
    </tr>
    <tr>
      <td width="27%">
        <div align="center">备　　注：</div>
      </td>
      <td width="73%">
        <input type="text" name="wzgen" size="40" value=$dis_data[3] class=text>
      </td>
    </tr>
    <tr>
      <td colspan="2">
        <div align="center"></div>
        <div align="center">
          <input type="submit" name="Submit" value="提  交" class=text>
          　　
          <input type="submit" name="Submit2" value="重　置" class=text>
        </div>
      </td>
    </tr>
  </table>
</form>
EOT;
}
######################
function my_add()
{
global $user_login_id,$wzname,$wzurl,$wzgen,$todate;
                                if (empty($wzname)||empty($wzurl))
                                {
                                errorview("请认真填好网站资料！！");
                                exit;
                                }
                                $oldlist=read_file("favorites/$user_login_id.php");
                                $oldlist=explode("\n",$oldlist);
                                $listcount=count($oldlist);
                                for ($j=0;$j<$listcount;$j++)
                                        {
                                        $listdetail=explode("\t",$oldlist[$j]);
                                        }
                                $oldlist=implode("\n",$oldlist);
                                $new_line[0]=strftime("%Y%m%d%H%M%S");
                                $new_line[1]=$wzname;
                                $new_line[2]=$wzurl;
                                $new_line[3]=$wzgen;
                                $new_line[4]=$todate;
                                $newlist=implode("\t",$new_line)."\n".$oldlist;
                                //$newlist=push_heldtopics($newlist);
                                write_file("favorites/$user_login_id.php",$newlist); //ok, write to the list
                                $title="添加网站成功";
                                include"header.php";
                                print"
                                <table width=\"300\" border=\"1\" bordercolorlight=\"#B5E1F7\" bordercolordark=\"#FFFFFF\" align=\"center\" cellpadding=\"0\" cellspacing=\"0\">
                                 <tr>
                                  <td><div align=\"center\">
                                   <p>网站收藏成功!</p>
                            <p><a href=\"favorites.php\">点击返回</a></p>
                                </div></td> </tr> </table>
                                ";
                                include"footer.php";
                                exit;
}
################
function fav_xiu()
{
global $user_login_id,$xiu_no;
$hastitles = file("favorites/$user_login_id.php");
$ccc=count($hastitles);
$fp = fopen("favorites/$user_login_id.php","w");
for ($i=0;$i<$ccc;$i++){
 list($d_no,$d_name,$d_url,$d_gen,$d_date)=explode("\t",$hastitles[$i]);
 if($d_no != $xiu_no){fputs($fp,$hastitles[$i]);}
 }
 fclose($fp);
 my_add();
  }
###################
function fav_del($del_no)
{
global $user_login_id;
$hastitles = file("favorites/$user_login_id.php");
$ccc=count($hastitles);
$fp = fopen("favorites/$user_login_id.php","w");
for ($i=0;$i<$ccc;$i++){
 list($d_no,$d_name,$d_url,$d_gen,$d_date)=explode("\t",$hastitles[$i]);
 if($d_no != $del_no){fputs($fp,$hastitles[$i]);}
 }
 fclose($fp);
 $ynhead2="1";
 $title="删除网站成功";
 include"header.php";
 print"
<table width=\"300\" border=\"1\" bordercolorlight=\"#B5E1F7\" bordercolordark=\"#FFFFFF\" align=\"center\" cellpadding=\"0\" cellspacing=\"0\">
 <tr> <td><div align=\"center\"> <p>删除网站成功!</p> <p><a href=\"favorites.php\">点击返回</a></p>
</div></td> </tr> </table>
 ";
include"footer.php";
}
?>