<?php
/*
	[Office 515158] (C) 2009-2014 天生创想 Inc.
	$Id: mod_file 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."file  order by id desc");
    $sql = "SELECT * FROM ".DB_TABLEPRE."file ORDER BY id desc LIMIT 0,100";
	$result = $db->fetch_all($sql);
	include_once('template/file.php');

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

}elseif ($do == 'list2') {
	$num = $db->result("SELECT COUNT(*) AS num FROM ".DB_TABLEPRE."file_read where type='1' or type='3' order by id desc");
    $sql = "SELECT * FROM ".DB_TABLEPRE."file_read where type='1' or type='3' ORDER BY id desc LIMIT 0,100";
	$result = $db->fetch_all($sql);
	include_once('template/file2.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."file where id='".$id."'   ORDER BY id desc limit 0,1");
			$filenumber = $r[filenumber];
			$filename = $r[filename];
			$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);
			$file_read = array(
				'fileid' => $id,
				'filenumber' => $filenumber,
				'filename' => $filename,
				'appperson' => $appperson,
				'appdate' => $appdate,
				'type' => $type,
				'date' => $date
			);
			$file = array(
				'type' => $type
			);
			//写入主表信息
			insert_db('file_read',$file_read);
			update_db('file',$file, array('id' => $id));
			$content=serialize($file_read);
			$title='档案借阅';
			get_logadd($id,$content,$title,20,$_USER->id);
			$fromture='ture';
		}
		$row = $db->fetch_one_array("SELECT * FROM ".DB_TABLEPRE."file  WHERE id = '".$id."'");
		$sql = "SELECT appperson,examdate FROM ".DB_TABLEPRE."file_read where fileid='".$id."' and type=4 ORDER BY id desc LIMIT 0,100";
		$result = $db->fetch_all($sql);
	}
	include_once('template/file_view.php');
}elseif ($do == 'views1') {
	$id = getGP('id','G','int');
	if($id!=''){
		$row = $db->fetch_one_array("SELECT * FROM ".DB_TABLEPRE."file_read  WHERE id = '".$id."'");
	}
	include_once('template/file_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."file_read where id='".$id."'   ORDER BY id desc limit 0,1");
			$file = array(
				'type' => $keys
				
			);
			update_db('file',$file, array('id' => $r['fileid']));
			
			$file_read = array(
				'type' => $keys,
				'examperson' => $_USER->id,
				'examdate' => get_date('Y-m-d H:i:s',PHP_TIME)
			);
			update_db('file_read',$file_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."file_read  WHERE id = '".$id."'");
	}
	include_once('template/file_view2.php');
}
?>