<?php
include(dirname(__FILE__)."/require.php");
if($ppurview[32]!=1)
  jump("jump.php?id=25&jump=main.php");
$phpcolor->table="link";
$phpcolor->where="id = '".$_GET['id']."'";
if(isset($_GET['action']) and $_GET['action'] == "del" and isset($_GET['id']))
{
  $phpcolor->delete();
  jump("jump.php?id=24&jump=link.php");
}
if(isset($_GET['action']) and $_GET['action'] == "adddo")
{
  if($_POST['name']=="" || $_POST['link']=="" || $_POST['queue']=="" || ($_POST['type']==1 && $_POST['picture']==""))
    jump("jump.php?id=2&jump=link.php?action=add");
  $phpcolor->field="name, link, picture, type, queue";
  $phpcolor->where="'".$_POST['name']."', '".$_POST['link']."', '".$_POST['picture']."', '".$_POST['type']."', '".$_POST['queue']."'";
  $phpcolor->write();
  jump("jump.php?id=24&jump=link.php");
}
if(isset($_GET['action']) and $_GET['action'] == "editdo" and isset($_GET['id']))
{
  if($_POST['name']=="" || $_POST['link']=="" || $_POST['queue']=="" || ($_POST['type']==1 && $_POST['picture']==""))
    jump("jump.php?id=2&jump=link.php?action=edit=and=id=".$_GET['id']);
  $phpcolor->field="name='".$_POST['name']."',link='".$_POST['link']."',picture='".$_POST['picture']."',type='".$_POST['type']."',queue='".$_POST['queue']."'";
  $phpcolor->upgrade();
  jump("jump.php?id=24&jump=link.php");
}
if(isset($_GET['action']) and $_GET['action'] == "add")
  $tpl -> display("link_add.htm");
elseif(isset($_GET['action']) and $_GET['action'] == "edit" and isset($_GET['id']))
{
  $phpcolor->field="*";
  $link=$phpcolor->exist(1);
  $tpl -> assign("link", $link);
  $tpl -> display("link_edit.htm");
}
else
{
  if(!isset($_GET['page']))
    $_GET['page']=0;
  $phpcolor->field="*";
  $phpcolor->where="1=1";
  $count = $phpcolor->exist(2);
  $phpcolor->where="1=1 order by queue limit ".($_GET['page']*20).",20";
  $link=$phpcolor->assignment();
  $page=pages($count,20,$_GET['page'],'link','','','0');
  for($count=0;$count<count($link);$count++)
  {
    if($link[$count]['type']==0)
      $link[$count]['type']="不显示";
    elseif($link[$count]['type']==1)
      $link[$count]['type']="图片链接";
    else
      $link[$count]['type']="文字链接";
  }
  $tpl -> assign("link", $link);
  $tpl -> assign("page", $page);
  $tpl -> display("link.htm");
}
?>