<?php
/*
	[Office 515158] (C) 2009-2014 天生创想 Inc.
	$Id: mod_book mobile $
*/
(!defined('IN_TOA') || !defined('IN_ADMIN')) && exit('Access Denied!');
empty($do) && $do = 'list';
$type=getGP('type','G');
$type_name='图书管理';	
if ($do == 'list') {
	$num = $db->result("SELECT COUNT(*) AS num FROM ".DB_TABLEPRE."book  order by id desc");
    $sql = "SELECT * FROM ".DB_TABLEPRE."book ORDER BY id desc LIMIT 0,100";
	$result = $db->fetch_all($sql);
	include_once('template/book.php');

}elseif ($do == 'list1') {
	$num = $db->result("SELECT COUNT(*) AS num FROM ".DB_TABLEPRE."book_read where appperson='".$_USER->id."' order by id desc");
    $sql = "SELECT * FROM ".DB_TABLEPRE."book_read where appperson='".$_USER->id."' ORDER BY id desc LIMIT 0,100";
	$result = $db->fetch_all($sql);
	include_once('template/book1.php');

}elseif ($do == 'list2') {
	$num = $db->result("SELECT COUNT(*) AS num FROM ".DB_TABLEPRE."book_read where type='1' or type='3' order by id desc");
    $sql = "SELECT * FROM ".DB_TABLEPRE."book_read where type='1' or type='3' ORDER BY id desc LIMIT 0,100";
	$result = $db->fetch_all($sql);
	include_once('template/book2.php');

}elseif ($do == 'views') {
	$id = getGP('id','G','int');
	if($id!=''){
		if(getGP('keys','G')==1){
			$r = $db->fetch_one_array("SELECT * FROM ".DB_TABLEPRE."book where id='".$id."'   ORDER BY id desc limit 0,1");
			$appperson = $_USER->id;
			$examperson = '0';
			$appdate =get_date('Y-m-d H:i:s',PHP_TIME);
			$type ='1';
			$date =get_date('Y-m-d H:i:s',PHP_TIME);
			$book_read = array(
				'bookid' => $id,
				'booknumber' => $r['bookumber'],
				'bookname' => $r['bookname'],
				'appperson' => $appperson,
				'appdate' => $appdate,
				'type' => $type,
				'date' => $date
			);
			$book = array(
				'type' => $type
			);
			//写入主表信息
			insert_db('book_read',$book_read);
			update_db('book',$book, array('id' => $id));
			$content=serialize($book_read);
			$title='图书借阅';
			get_logadd($id,$content,$title,20,$_USER->id);
			$fromture='ture';
		}
		$row = $db->fetch_one_array("SELECT * FROM ".DB_TABLEPRE."book  WHERE id = '".$id."'");
		$sql = "SELECT appperson,examdate FROM ".DB_TABLEPRE."book_read where bookid='".$id."' and type=4 ORDER BY id desc LIMIT 0,100";
		$result = $db->fetch_all($sql);
	}
	include_once('template/book_view.php');
}elseif ($do == 'views1') {
	$id = getGP('id','G','int');
	if($id!=''){
		$row = $db->fetch_one_array("SELECT * FROM ".DB_TABLEPRE."book_read  WHERE id = '".$id."'");
	}
	include_once('template/book_view1.php');
}elseif ($do == 'views2') {
	$id = getGP('id','G','int');
	if($id!=''){
		if(getGP('keys','G')!=''){
			$keys = getGP('keys','G');
			$r = $db->fetch_one_array("SELECT * FROM ".DB_TABLEPRE."book_read where id='".$id."'   ORDER BY id desc limit 0,1");
			$book = array(
				'type' => $keys
				
			);
			update_db('book',$book, array('id' => $r['bookid']));
			
			$book_read = array(
				'type' => $keys,
				'examperson' => $_USER->id,
				'examdate' => get_date('Y-m-d H:i:s',PHP_TIME)
			);
			update_db('book_read',$book_read, array('id' => $id));
			$content=$keys;
			$title='图书审批';
			get_logadd($id,$content,$title,20,$_USER->id);
			$fromture='ture';
		}
		$row = $db->fetch_one_array("SELECT * FROM ".DB_TABLEPRE."book_read  WHERE id = '".$id."'");
	}
	include_once('template/book_view2.php');
}
?>