<?php
include(dirname(__FILE__)."/require.php");
if($ppurview[49]!=1)
  jump("jump.php?id=25&jump=main.php");
$phpcolor->table="book_sql";
if(isset($_GET['action']) and $_GET['action'] == "del" and isset($_GET['id']))
{
  $phpcolor->field="*";
  $phpcolor->where="id='".$_GET['id']."'";
  $phpcolor->delete();
  jump("jump.php?id=24&jump=book_sql.php");
}
elseif(isset($_GET['action']) and $_GET['action'] == "add")
  $tpl -> display("book_sql_add.htm");
elseif(isset($_GET['action']) and $_GET['action'] == "adddo")
{
  if($_POST['did']=="" || $_POST['sqlhost']=="" || $_POST['sqldb']=="" || $_POST['sqluser']=="" || $_POST['sqlpw']=="")
    jump("jump.php?id=2&jump=book_sql.php?action=add");
  $phpcolor->field="*";
  $phpcolor->where="did='".$_POST['did']."'";
  if($phpcolor->exist(2))
    jump("jump.php?id=4&jump=book_sql.php?action=add");
  $phpcolor->field="did, sqlhost, sqldb, sqluser, sqlpw";
  $phpcolor->where="'".$_POST['did']."', '".$_POST['sqlhost']."', '".$_POST['sqldb']."', '".$_POST['sqluser']."', '".$_POST['sqlpw']."'";
  $phpcolor->write();
  jump("jump.php?id=24&jump=book_sql.php");
}
elseif(isset($_GET['action']) and $_GET['action'] == "edit" and isset($_GET['id']))
{
  $phpcolor->field="*";
  $phpcolor->where="id='".$_GET['id']."'";
  $booksql=$phpcolor->exist(1);
  $tpl -> assign("booksql", $booksql);
  $tpl -> display("book_sql_edit.htm");
}
elseif(isset($_GET['action']) and $_GET['action'] == "editdo" and isset($_GET['id']))
{
  if($_POST['did']=="" || $_POST['sqlhost']=="" || $_POST['sqldb']=="" || $_POST['sqluser']=="" || $_POST['sqlpw']=="")
    jump("jump.php?id=2&jump=book_sql.php?action=edit=and=id=".$_GET['id']);
  $phpcolor->field="did='".$_POST['did']."',sqlhost='".$_POST['sqlhost']."',sqldb='".$_POST['sqldb']."',sqluser='".$_POST['sqluser']."',sqlpw='".$_POST['sqlpw']."'";
  $phpcolor->where="id='".$_GET['id']."'";
  $phpcolor->upgrade();
  jump("jump.php?id=24&jump=book_sql.php");
}
else
{
  if(!isset($_GET['page']))
    $_GET['page']=0;
  $phpcolor->field="*";
  $phpcolor->where="1=1";
  $count = $phpcolor->exist(2);
  $phpcolor->where="1=1 order by did limit ".($_GET['page']*30).",30";
  $booksql=$phpcolor->assignment();
  $page=pages($count,'30',$_GET['page'],'book_sql','','','0');
  for($count=0;$count<count($booksql);$count++)
  {
    $phpcolor->table="book";
    $phpcolor->field="*";
	for($i=0;$i<=9;$i++)
    {
      $phpcolor->where="sqldata='".$booksql[$count]['did']."' and sqltable='".$i."'";
      $rs=$phpcolor->exist(2);
      $booksql[$count]['table'.$i] = $rs;
	}
  }
  $tpl -> assign("booksql", $booksql);
  $tpl -> assign("page", $page);
  $tpl -> display("book_sql.htm");
}
?>