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

}elseif ($do == 'views') {
	$id = getGP('id','G','int');
	if($id!=''){
		$row = $db->fetch_one_array("SELECT * FROM ".DB_TABLEPRE."office_goods  WHERE id = '".$id."'");
	}
	include_once('template/goods_view.php');
}elseif ($do == 'add') {
	if($_POST['view']!=''){
		$id = getGP('id','P','int');
		$goods_type = getGP('goods_type','P');
		$title=getGP('title','P');
		$specification=getGP('specification','P');
		$unit=getGP('unit','P');
		$price=getGP('price','P');
		$number=getGP('number','P');
		$content=getGP('content','P');
		$recorduser=getGP('recorduser','P');
		$department=getGP('department','P');
		$recordnum=getGP('recordnum','P');
		$office_goods_record = array(
			'goods_type' => $goods_type,
			'title' => $title,
			'specification' => $specification,
			'unit' => $unit,
			'price' => $price,
			'number' => $number,
			'content' => $content,
			'recorduser' => $_USER->id,
			'department' => $department,
			'type' => 1,
			'officegoods' => $id,
			'recordnum' => $recordnum,
			'date' => get_date('Y-m-d H:i:s',PHP_TIME),
			'uid' => $_USER->id
		);
		insert_db('office_goods_record',$office_goods_record);
		$formlist='true';
		$_title['name']='办公用品领用';
	}else{
		$id = getGP('id','G','int');
		if($id!=''){
			$row = $db->fetch_one_array("SELECT * FROM ".DB_TABLEPRE."office_goods  WHERE id = '".$id."'");
			$_title['name']='办公用品领用';
		}
	}
	include_once('template/goods_add.php');

}elseif ($do == 'goods_view') {
	$id = getGP('id','G','int');
	if($id!=''){
		$row = $db->fetch_one_array("SELECT * FROM ".DB_TABLEPRE."office_goods_record  WHERE id = '".$id."'");
		$_title['name']='我的领用信息';
		include_once('template/goods_views_id.php');
	}else{
		$num = $db->result("SELECT COUNT(*) AS num FROM ".DB_TABLEPRE."office_goods_record where recorduser = '".$_USER->id."' order by id desc");
		$sql = "SELECT * FROM ".DB_TABLEPRE."office_goods_record where recorduser = '".$_USER->id."' ORDER BY id desc LIMIT 0,200";
		$result = $db->fetch_all($sql);
		include_once('template/goods_views.php');
	}

}elseif ($do == 'goods_view_key') {
	$id = getGP('id','G','int');
	if($id!=''){
		$row = $db->fetch_one_array("SELECT * FROM ".DB_TABLEPRE."office_goods_record  WHERE id = '".$id."'");
		$_title['name']='审批'.get_realname($row['recorduser']).'的领用信息';
		include_once('template/goods_view_key_id.php');
	}else{
		$key1 = $db->result("SELECT * FROM ".DB_TABLEPRE."office_goods_key where examination like '%".get_realname($_USER->id)."%'  ");
		if($key1["examination"]!=''){
			$num = $db->result("SELECT COUNT(*) AS num FROM ".DB_TABLEPRE."office_goods_record where type = '1' order by id desc");
			$sql = "SELECT * FROM ".DB_TABLEPRE."office_goods_record where type = '1' ORDER BY id desc LIMIT 0,200";
			$result = $db->fetch_all($sql);
			$_title['name']='办公用品审批';
		}else{
			$_title['name']='无权限!';
		}
		include_once('template/goods_view_key.php');
	}

}elseif ($do == 'goods_view_key_add') {
    $id = getGP('id','G','int');
	$key1 = getGP('key1','G','int');
	$office_goods_record = array(
		'type' => $key1,
		'examination' => get_realname($_USER->id)
	);
	update_db('office_goods_record',$office_goods_record, array('id' => $id));
	$row = $db->fetch_one_array("SELECT * FROM ".DB_TABLEPRE."office_goods_record  WHERE id = '".$id."'");
	$_title['name']='审批成功';
	include_once('template/goods_view_key_id.php');
}
?>