commit | author | age
|
3e083b
|
1 |
<?php |
B |
2 |
|
|
3 |
/** |
|
4 |
* 调查程序 |
|
5 |
*/ |
|
6 |
|
|
7 |
define('IN_ECS', true); |
|
8 |
|
|
9 |
require(dirname(__FILE__) . '/includes/init.php'); |
|
10 |
require(ROOT_PATH . 'includes/cls_json.php'); |
|
11 |
|
|
12 |
if (!isset($_REQUEST['vote']) || !isset($_REQUEST['options']) || !isset($_REQUEST['type'])) |
|
13 |
{ |
|
14 |
ecs_header("Location: ./\n"); |
|
15 |
exit; |
|
16 |
} |
|
17 |
|
|
18 |
$res = array('error' => 0, 'message' => '', 'content' => ''); |
|
19 |
|
|
20 |
$vote_id = intval($_POST['vote']); |
|
21 |
$options = trim($_POST['options']); |
|
22 |
$type = intval($_POST['type']); |
|
23 |
$ip_address = real_ip(); |
|
24 |
|
|
25 |
if (vote_already_submited($vote_id, $ip_address)) |
|
26 |
{ |
|
27 |
$res['error'] = 1; |
|
28 |
$res['message'] = $_LANG['vote_ip_same']; |
|
29 |
} |
|
30 |
else |
|
31 |
{ |
|
32 |
save_vote($vote_id, $ip_address, $options); |
|
33 |
|
|
34 |
$vote = get_vote($vote_id); |
|
35 |
if (!empty($vote)) |
|
36 |
{ |
|
37 |
$smarty->assign('vote_id', $vote['id']); |
|
38 |
$smarty->assign('vote', $vote['content']); |
|
39 |
} |
|
40 |
|
|
41 |
$str = $smarty->fetch("library/vote.lbi"); |
|
42 |
|
|
43 |
$pattern = '/(?:<(\w+)[^>]*> .*?)?<div\s+id="ECS_VOTE">(.*)<\/div>(?:.*?<\/\1>)?/is'; |
|
44 |
|
|
45 |
if (preg_match($pattern, $str, $match)) |
|
46 |
{ |
|
47 |
$res['content'] = $match[2]; |
|
48 |
} |
|
49 |
$res['message'] = $_LANG['vote_success']; |
|
50 |
} |
|
51 |
|
|
52 |
$json = new JSON; |
|
53 |
|
|
54 |
echo $json->encode($res); |
|
55 |
|
|
56 |
/*------------------------------------------------------ */ |
|
57 |
//-- PRIVATE FUNCTION |
|
58 |
/*------------------------------------------------------ */ |
|
59 |
|
|
60 |
/** |
|
61 |
* 检查是否已经提交过投票 |
|
62 |
* |
|
63 |
* @access private |
|
64 |
* @param integer $vote_id |
|
65 |
* @param string $ip_address |
|
66 |
* @return boolean |
|
67 |
*/ |
|
68 |
function vote_already_submited($vote_id, $ip_address) |
|
69 |
{ |
|
70 |
$sql = "SELECT COUNT(*) FROM ".$GLOBALS['ecs']->table('vote_log')." ". |
|
71 |
"WHERE ip_address = '$ip_address' AND vote_id = '$vote_id' "; |
|
72 |
|
|
73 |
return ($GLOBALS['db']->GetOne($sql) > 0); |
|
74 |
} |
|
75 |
|
|
76 |
/** |
|
77 |
* 保存投票结果信息 |
|
78 |
* |
|
79 |
* @access public |
|
80 |
* @param integer $vote_id |
|
81 |
* @param string $ip_address |
|
82 |
* @param string $option_id |
|
83 |
* @return void |
|
84 |
*/ |
|
85 |
function save_vote($vote_id, $ip_address, $option_id) |
|
86 |
{ |
|
87 |
$sql = "INSERT INTO " . $GLOBALS['ecs']->table('vote_log') . " (vote_id, ip_address, vote_time) " . |
|
88 |
"VALUES ('$vote_id', '$ip_address', " . gmtime() .")"; |
|
89 |
$res = $GLOBALS['db']->query($sql); |
|
90 |
|
|
91 |
/* 更新投票主题的数量 */ |
|
92 |
$sql = "UPDATE " .$GLOBALS['ecs']->table('vote'). " SET ". |
|
93 |
"vote_count = vote_count + 1 ". |
|
94 |
"WHERE vote_id = '$vote_id'"; |
|
95 |
$GLOBALS['db']->query($sql); |
|
96 |
|
|
97 |
/* 更新投票选项的数量 */ |
|
98 |
$sql = "UPDATE " . $GLOBALS['ecs']->table('vote_option') . " SET " . |
|
99 |
"option_count = option_count + 1 " . |
|
100 |
"WHERE " . db_create_in($option_id, 'option_id'); |
|
101 |
$GLOBALS['db']->query($sql); |
|
102 |
} |
|
103 |
|
|
104 |
?> |