<?php
/*
	[Office 515158] (C) 2009-2015 天生创想 Inc.
	$Id: mod_appsflow mobile $
*/
(!defined('IN_TOA') || !defined('IN_ADMIN')) && exit('Access Denied!');
empty($do) && $do = 'list';
if(getGP('tpltype','G')!=''){
	$tpltype=getGP('tpltype','G');
}else{
	$tpltype=getGP('tpltype','P');
}
if ($do == 'list') {
	if ($tpltype=='1') {
		$wheresql .= " AND b.readdate!=''";
	}elseif($tpltype=='2') {
		$wheresql .= " AND b.readdate is Null";
	}
	$num = $db->result("SELECT COUNT(*) AS num FROM ".DB_TABLEPRE."apps a,".DB_TABLEPRE."app_read b WHERE 1 $wheresql and a.id=b.appid and b.readuid='".$_USER->id."' order by b.readdate asc");
	$sql = "SELECT a.title,a.number,a.id as appid,b.* FROM ".DB_TABLEPRE."apps a,".DB_TABLEPRE."app_read b WHERE 1 $wheresql and a.id=b.appid and b.readuid='".$_USER->id."' order by b.readdate asc LIMIT 100";
	$result = $db->fetch_all($sql);
	include_once('template/appsreadlist.php');

}elseif ($do == 'views') {
	$appsid=getGP('appsid','G','int');
	$tpltype=getGP('tpltype','G','int');
	if(getGP('readtype','G','int')!='1'){
		$db->query("update ".DB_TABLEPRE."app_read set readdate='".get_date('Y-m-d H:i:s',PHP_TIME)."' WHERE readuid='".$_USER->id."' and rid = '".getGP('rid','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');
	}
}
?>