module.php
4.25 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
<?php
/**
* 投票系统
*
* [WeEngine System] Copyright (c) 2013 WE7.CC
*/
defined('IN_IA') or exit('Access Denied');
class Ewei_voteModule extends WeModule
{
public $name = 'Vote';
public $title = '投票系统';
public $ability = '';
public $tablename = 'vote_reply';
public function fieldsFormDisplay($rid = 0) {
global $_W;
if (!empty($rid)) {
$reply = pdo_fetch("SELECT * FROM " . tablename($this->tablename) . " WHERE rid = :rid ORDER BY `id` DESC", array(':rid' => $rid));
$options = pdo_fetchall("select * from " . tablename('vote_option') . " where rid=:rid order by id asc", array(':rid' => $rid));
foreach ($options as &$o) {
$o['type'] = $reply['isimg'] == '1' ? 'image' : 'text';
}
unset($o);
}
if (!$reply) {
$now = time();
$reply = array(
"starttime" => $now,
"endtime" => strtotime(date("Y-m-d H:i", $now + 7 * 24 * 3600)),
"share_title" => "欢迎参加投票活动",
"share_desc" => "亲,欢迎参加投票活动! 亲,需要绑定账号才可以参加哦",
"share_txt" => "<p>1. 关注微信公众账号\"()\"</p><p>2. 发送消息\"投票\", 点击返回的消息即可参加</p>",
);
}
include $this->template('form');
}
public function fieldsFormValidate($rid = 0) {
return true;
}
public function fieldsFormSubmit($rid = 0) {
global $_GPC, $_W;
$id = intval($_GPC['reply_id']);
$insert = array(
'rid' => $rid,
'weid' => $_W['uniacid'],
'title' => $_GPC['title'],
'description' => $_GPC['description'],
'votetype' => $_GPC['votetype'],
'votelimit' => $_GPC['votelimit'],
'votetimes' => $_GPC['votetimes'],
'votetotal' => $_GPC['votetotal'],
'isimg' => $_GPC['isimg'],
'share_title' => $_GPC['share_title'],
'share_desc' => preg_replace('/\s/i', '', str_replace(' ', '', cutstr(str_replace(' ', '', ihtmlspecialchars(strip_tags($_GPC['share_desc']))), 60))),
'share_url' => $_GPC['share_url'],
'share_txt' => $_GPC['share_txt'],
'starttime' => strtotime($_GPC['datelimit']['start']),
'endtime' => strtotime($_GPC['datelimit']['end'])
);
if (!empty($_GPC['thumb'])) {
$insert['thumb'] = $_GPC['thumb'];
load()->func('file');
file_delete($_GPC['thumb-old']);
}
if (empty($id)) {
if ($insert['starttime'] <= TIMESTAMP) {
$insert['isshow'] = 1;
} else {
$insert['isshow'] = 0;
}
$id = pdo_insert($this->tablename, $insert);
} else {
pdo_update($this->tablename, $insert, array('id' => $id));
}
$options = array();
$option_ids = $_POST['option_id'];
$option_titles = $_POST['option_title'];
$option_thumb_olds = $_POST['option_thumb_old'];
$files = $_FILES;
$len = count($option_ids);
$ids = array();
for ($i = 0; $i < $len; $i++) {
$item_id = $option_ids[$i];
$a = array(
"title" => $option_titles[$i],
"rid" => $rid,
"thumb" => $_GPC['option_thumb_' . $item_id]
);
if ((int)$item_id == 0) {
pdo_insert("vote_option", $a);
$item_id = pdo_insertid();
} else {
pdo_update("vote_option", $a, array('id' => $item_id));
}
$ids[] = $item_id;
}
if (!empty($ids)) {
pdo_query("delete from " . tablename('vote_option') . " where rid = $rid and id not in ( " . implode(',', $ids) . ")");
}
return true;
}
public function ruleDeleted($rid = 0) {
pdo_delete('vote_reply', array('rid' => $rid));
pdo_delete('vote_fans', array('rid' => $rid));
pdo_delete('vote_option', array('rid' => $rid));
return true;
}
public function settingsDisplay($settings) {message('请升级系统到最新版本');}
}