<?php
/*
	[Office 515158] (C) 2009-2015 天生创想 Inc.
	$Id: mod_apps mobile $
*/
(!defined('IN_TOA') || !defined('IN_ADMIN')) && exit('Access Denied!');
$type_name='公文';	
empty($do) && $do = 'list';
if ($do == 'list') {
	include_once('template/apps.php');
}elseif ($do == 'listmy') {
	if ($tpltype = getGP('tpltype','G')) {
		$wheresql .= " AND tpltype='".$tpltype."'";
	}
	$num = $db->result("SELECT COUNT(*) AS num FROM ".DB_TABLEPRE."apps WHERE 1 $wheresql and uid='".$_USER->id."' order by id desc");
	$sql = "SELECT * FROM ".DB_TABLEPRE."apps WHERE 1 $wheresql and uid='".$_USER->id."' order by id desc LIMIT 100";
	$result = $db->fetch_all($sql);
	include_once('template/apps_my.php');
}elseif ($do == 'listkey') {
	$tpltype = getGP('tpltype','G');
	if($tpltype==''){
		$num = $db->result("SELECT COUNT(*) AS num FROM ".DB_TABLEPRE."apps a,".DB_TABLEPRE."app_personnel b WHERE 1 $wheresql and  a.id=b.appid and (b.pertype=0 or b.pertype=4) and b.name like '%".get_realname($_USER->id)."%' and a.type!=1 order by b.perid asc");
		$sql = "SELECT a.* FROM ".DB_TABLEPRE."apps a,".DB_TABLEPRE."app_personnel b WHERE 1 $wheresql and a.id=b.appid and (b.pertype=0 or b.pertype=4) and b.name like '%".get_realname($_USER->id)."%' and a.type!=1 order by b.perid asc LIMIT 100";
	}else{
		$num = $db->result("SELECT COUNT(*) AS num FROM ".DB_TABLEPRE."apps a,".DB_TABLEPRE."app_personnel b WHERE 1 $wheresql and a.id=b.appid and b.pertype!=0 and b.name like '%".get_realname($_USER->id)."%' order by b.perid desc");
		$sql = "SELECT a.* FROM ".DB_TABLEPRE."apps a,".DB_TABLEPRE."app_personnel b WHERE 1 $wheresql and a.id=b.appid and b.pertype<>'0' and b.name like '%".get_realname($_USER->id)."%' order by b.perid desc LIMIT 100";
	}
	$result = $db->fetch_all($sql);
	include_once('template/apps_listkey.php');
}elseif ($do == 'mana') {
	$num = $db->result("SELECT COUNT(*) AS num FROM ".DB_TABLEPRE."apps a,".DB_TABLEPRE."app_type b WHERE 1 ".$wheresql." and a.tplid=b.tplid and b.tpladmin like '%".get_realname($_USER->id)."%' order by a.id desc");
	$sql = "SELECT a.* FROM ".DB_TABLEPRE."apps a,".DB_TABLEPRE."app_type b WHERE 1 ".$wheresql." and a.tplid=b.tplid and b.tpladmin like '%".get_realname($_USER->id)."%' order by a.id desc LIMIT 100";
	$result = $db->fetch_all($sql);
	include_once('template/apps_mana.php');
}elseif ($do == 'views') {
	$appsid=getGP('appsid','G','int');
	$tpltype=getGP('tpltype','G','int');
	if($appsid!=''){
		$apps = $db->fetch_one_array("SELECT * FROM ".DB_TABLEPRE."apps  WHERE id = '".$appsid."'  ");
		$readnum = $db->result("SELECT COUNT(*) AS readnum FROM ".DB_TABLEPRE."app_read WHERE appid='".$appsid."' order by rid desc");
		$tpl = $db->fetch_one_array("SELECT * FROM ".DB_TABLEPRE."app_type  WHERE tplid = '".$apps['tplid']."'  ");
		include_once('template/apps_view.php');
	}
}
?>