module.php
5.45 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
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
<?php
/**
* 砸蛋抽奖模块
*
* [WeEngine System] Copyright (c) 2013 WE7.CC
*/
defined('IN_IA') or exit('Access Denied');
class We7_eggModule extends WeModule {
public $tablename = 'egg_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));
$award = pdo_fetchall("SELECT * FROM " . tablename('egg_award') . " WHERE rid = :rid ORDER BY `id` ASC", array(':rid' => $rid));
if (!empty($award)) {
foreach ($award as &$pointer) {
if (!empty($pointer['activation_code'])) {
$pointer['activation_code'] = implode("\n", (array)iunserializer($pointer['activation_code']));
}
}
}
} else {
$reply = array(
'periodlottery' => 1,
'maxlottery' => 1,
'starttime' => TIMESTAMP,
'endtime' => TIMESTAMP + 7 * 86400
);
}
load()->func('tpl');
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,
'uniacid' => $_W['uniacid'],
'title' => $_GPC['title'],
'picture' => $_GPC['picture'],
'description' => $_GPC['description'],
'periodlottery' => intval($_GPC['periodlottery']),
'maxlottery' => intval($_GPC['maxlottery']),
'maxaward' => intval($_GPC['maxaward']),
'rule' => htmlspecialchars_decode($_GPC['rule']),
'default_tips' => $_GPC['default_tips'],
'hitcredit' => intval($_GPC['hitcredit']),
'misscredit' => intval($_GPC['misscredit']),
'starttime' => strtotime($_GPC['time']['start']),
'endtime' => strtotime($_GPC['time']['end'])
);
if (empty($id)) {
pdo_insert($this->tablename, $insert);
} else {
if (!empty($_GPC['picture']) && $_GPC['picture'] != $_GPC['picture-old']) {
load()->func('file');
file_delete($_GPC['picture-old']);
} else {
unset($insert['picture']);
}
pdo_update($this->tablename, $insert, array('id' => $id));
}
if (!empty($_GPC['award-title'])) {
foreach ($_GPC['award-title'] as $index => $title) {
if (empty($title)) {
continue;
}
$update = array(
'title' => $title,
'description' => $_GPC['award-description'][$index],
'probalilty' => $_GPC['award-probalilty'][$index],
'total' => $_GPC['award-total'][$index],
'activation_code' => '',
'activation_url' => '',
);
if (empty($update['inkind']) && !empty($_GPC['award-activation-code'][$index])) {
$activationcode = explode("\n", $_GPC['award-activation-code'][$index]);
$update['activation_code'] = iserializer($activationcode);
// $update['total'] = count($activationcode);
$update['activation_url'] = $_GPC['award-activation-url'][$index];
}
pdo_update('egg_award', $update, array('id' => $index));
}
}
//处理添加
if (!empty($_GPC['award-title-new'])) {
foreach ($_GPC['award-title-new'] as $index => $title) {
if (empty($title)) {
continue;
}
$insert = array(
'rid' => $rid,
'title' => $title,
'description' => $_GPC['award-description-new'][$index],
'probalilty' => $_GPC['award-probalilty-new'][$index],
'inkind' => intval($_GPC['award-inkind-new'][$index]),
'total' => intval($_GPC['award-total-new'][$index]),
'activation_code' => '',
'activation_url' => '',
);
if (empty($insert['inkind'])) {
$activationcode = explode("\n", $_GPC['award-activation-code-new'][$index]);
$insert['activation_code'] = iserializer($activationcode);
// $insert['total'] = count($activationcode);
$insert['activation_url'] = $_GPC['award-activation-url-new'][$index];
}
pdo_insert('egg_award', $insert);
}
}
}
public function ruleDeleted($rid = 0) {
global $_W;
load()->func('file');
$replies = pdo_fetchall("SELECT id, picture FROM " . tablename($this->tablename) . " WHERE rid = '$rid'");
$deleteid = array();
if (!empty($replies)) {
foreach ($replies as $index => $row) {
file_delete($row['picture']);
$deleteid[] = $row['id'];
}
}
pdo_delete($this->tablename, "id IN ('" . implode("','", $deleteid) . "')");
pdo_delete('egg_winner', array('rid' => $rid));
pdo_delete('egg_award', array('rid' => $rid));
return true;
}
}