<?php
/*
	[Office 515158] (C) 2009-2014 天生创想 Inc.
	$Id: mod_app_option mobile $
*/
(!defined('IN_TOA') || !defined('IN_ADMIN')) && exit('Access Denied!');
empty($do) && $do = 'list';
$type=getGP('type','G');
if($type==''){
	$type=1;
}
$type_name='投票管理';	
if ($do == 'list') {
	if($type=='2'){
		$wheresql .= " where untildate>='".get_date('Y-m-d H:i:s',PHP_TIME)."' and (uid='".$_USER->id."' or user like '%".get_realname($_USER->id)."%' or user='')";
	}elseif($type=='3'){
		$wheresql .= " where untildate<='".get_date('Y-m-d H:i:s',PHP_TIME)."' and (uid='".$_USER->id."' or user like '%".get_realname($_USER->id)."%' or user='')";
	}else{
		$wheresql .= " where (uid='".$_USER->id."' or user like '%".get_realname($_USER->id)."%' or user='')";
	}
	$num = $db->result("SELECT COUNT(*) AS num FROM ".DB_TABLEPRE."app ".$wheresql." order by id desc");
    $sql = "SELECT * FROM ".DB_TABLEPRE."app ".$wheresql." ORDER BY id desc LIMIT 0,200";
	$result = $db->fetch_all($sql);
	include_once('template/app_option.php');

}elseif ($do == 'views') {
	$app_id = getGP('id','G','int');
	$type = getGP('type','G','int');
	if($app_id!=''){
		$row = $db->fetch_one_array("SELECT * FROM ".DB_TABLEPRE."app  WHERE id = '".$app_id."'");
		$sql="SELECT * FROM ".DB_TABLEPRE."app_log  WHERE app_id = '".$app_id."' and user='".$_USER->id."' ";
		$app_log = $db->fetch_one_array($sql);
		if($app_log["user"]==''){
			$name='在线投票';
		}else{
			$name='查看投票记录';
		}
		$sql = "SELECT * FROM ".DB_TABLEPRE."app_option where app_id='".$app_id."'  ORDER BY id Asc";
		$result = $db->fetch_all($sql);
		$sql = "SELECT * FROM ".DB_TABLEPRE."app_log where app_id='".$app_id."'  ORDER BY id Asc";
		$relog = $db->fetch_all($sql);
	}
	include_once('template/app_option_view.php');
}elseif ($do == 'add') {
	if($_POST['view']!=''){
		$app_id = getGP('app_id','P');
		$app_option_id = getGP('app_option_id','P');
		$user = $_USER->id;
		$content = getGP('content','P');
		$date = get_date('Y-m-d H:i:s',PHP_TIME);
		if(!getGP('app_option_id','P')){
			echo '投票选项不能为空！';
		}
		$type = getGP('type','P');
		$app_log = array(
			'app_id' => $app_id,
			'app_option_id' => $app_option_id,
			'user' => $user,
			'content' => $content,
			'date' => $date
		);
		insert_db('app_log',$app_log);
		$id=$db->insert_id();
		$content=serialize($app_log);
		$title='参与投票';
		get_logadd($id,$content,$title,31,$_USER->id);
		$formlist='true';
	}else{
		$app_id = getGP('id','G','int');
		$type = getGP('type','G','int');
		if($app_id!=''){
			$sql = "SELECT * FROM ".DB_TABLEPRE."app_option where app_id='".$app_id."'  ORDER BY id Asc";
			$result = $db->fetch_all($sql);
		}
	}
	include_once('template/app_option_add.php');

}
?>