home_medal.php
6.34 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
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
<?php
/**
* [Discuz!] (C)2001-2099 Comsenz Inc.
* This is NOT a freeware, use is subject to license terms
*
* $Id: home_medal.php 28887 2012-03-16 10:17:38Z monkey $
*/
if(!defined('IN_DISCUZ')) {
exit('Access Denied');
}
loadcache('medals');
if(!$_G['uid'] && $_GET['action']) {
showmessage('not_loggedin', NULL, array(), array('login' => 1));
}
$_G['mnid'] = 'mn_common';
$medallist = $medallogs = array();
$tpp = 10;
$page = max(1, intval($_GET['page']));
$start_limit = ($page - 1) * $tpp;
if(empty($_GET['action'])) {
include libfile('function/forum');
$medalcredits = array();
foreach(C::t('forum_medal')->fetch_all_data(1) as $medal) {
$medal['permission'] = medalformulaperm(serialize(array('medal' => dunserialize($medal['permission']))), 1);
if($medal['price']) {
$medal['credit'] = $medal['credit'] ? $medal['credit'] : $_G['setting']['creditstransextra'][3];
$medalcredits[$medal['credit']] = $medal['credit'];
}
$medallist[$medal['medalid']] = $medal;
}
$memberfieldforum = C::t('common_member_field_forum')->fetch($_G['uid']);
$membermedal = $memberfieldforum['medals'] ? explode("\t", $memberfieldforum['medals']) : array();
$membermedal = array_map('intval', $membermedal);
$lastmedals = $uids = array();
foreach(C::t('forum_medallog')->fetch_all_lastmedal(10) as $id => $lastmedal) {
$lastmedal['dateline'] = dgmdate($lastmedal['dateline'], 'u');
$lastmedals[$id] = $lastmedal;
$uids[] = $lastmedal['uid'];
}
$lastmedalusers = C::t('common_member')->fetch_all($uids);
$mymedals = C::t('common_member_medal')->fetch_all_by_uid($_G['uid']);
} elseif($_GET['action'] == 'confirm') {
include libfile('function/forum');
$medal = C::t('forum_medal')->fetch($_GET['medalid']);
$medal['permission'] = medalformulaperm(serialize(array('medal' => dunserialize($medal['permission']))), 1);
if($medal['price']) {
$medal['credit'] = $medal['credit'] ? $medal['credit'] : $_G['setting']['creditstransextra'][3];
$medalcredits[$medal['credit']] = $medal['credit'];
}
include template('home/space_medal_float');
} elseif($_GET['action'] == 'apply' && submitcheck('medalsubmit')) {
$medalid = intval($_GET['medalid']);
$_G['forum_formulamessage'] = $_G['forum_usermsg'] = $medalnew = '';
$medal = C::t('forum_medal')->fetch($medalid);
if(!$medal['type']) {
showmessage('medal_apply_invalid');
}
if(C::t('common_member_medal')->count_by_uid_medalid($_G['uid'], $medalid)) {
showmessage('medal_apply_existence', 'home.php?mod=medal');
}
$applysucceed = FALSE;
$medalpermission = $medal['permission'] ? dunserialize($medal['permission']) : '';
if($medalpermission[0] || $medalpermission['usergroupallow']) {
include libfile('function/forum');
medalformulaperm(serialize(array('medal' => $medalpermission)), 1);
if($_G['forum_formulamessage']) {
showmessage('medal_permforum_nopermission', 'home.php?mod=medal', array('formulamessage' => $_G['forum_formulamessage'], 'usermsg' => $_G['forum_usermsg']));
} else {
$applysucceed = TRUE;
}
} else {
$applysucceed = TRUE;
}
if($applysucceed) {
$expiration = empty($medal['expiration'])? 0 : TIMESTAMP + $medal['expiration'] * 86400;
if($medal['type'] == 1) {
if($medal['price']) {
$medal['credit'] = $medal['credit'] ? $medal['credit'] : $_G['setting']['creditstransextra'][3];
if($medal['price'] > getuserprofile('extcredits'.$medal['credit'])) {
showmessage('medal_not_get_credit', '', array('credit' => $_G['setting']['extcredits'][$medal[credit]][title]));
}
updatemembercount($_G['uid'], array($medal['credit'] => -$medal['price']), true, 'BME', $medal['medalid']);
}
$memberfieldforum = C::t('common_member_field_forum')->fetch($_G['uid']);
$usermedal = $memberfieldforum;
unset($memberfieldforum);
$medal['medalid'] = $medal['medalid'].(empty($expiration) ? '' : '|'.$expiration);
$medalnew = $usermedal['medals'] ? $usermedal['medals']."\t".$medal['medalid'] : $medal['medalid'];
C::t('common_member_field_forum')->update($_G['uid'], array('medals' => $medalnew));
C::t('common_member_medal')->insert(array('uid' => $_G['uid'], 'medalid' => $medal['medalid']), 0, 1);
$medalmessage = 'medal_get_succeed';
} else {
if(C::t('forum_medallog')->count_by_verify_medalid($_G['uid'], $medal['medalid'])) {
showmessage('medal_apply_existence', 'home.php?mod=medal');
}
$medalmessage = 'medal_apply_succeed';
manage_addnotify('verifymedal');
}
C::t('forum_medallog')->insert(array(
'uid' => $_G['uid'],
'medalid' => $medalid,
'type' => $medal['type'],
'dateline' => TIMESTAMP,
'expiration' => $expiration,
'status' => ($expiration ? 1 : 0),
));
showmessage($medalmessage, 'home.php?mod=medal', array('medalname' => $medal['name']));
}
} elseif($_GET['action'] == 'log') {
include libfile('function/forum');
foreach(C::t('forum_medal')->fetch_all_data(1) as $medal) {
$medallist[$medal['medalid']] = $medal;
}
$memberfieldforum = C::t('common_member_field_forum')->fetch($_G['uid']);
$membermedal = $memberfieldforum['medals'] ? explode("\t", $memberfieldforum['medals']) : array();
foreach($membermedal as $k => $medal) {
if(!in_array($medal, array_keys($medallist))) {
unset($membermedal[$k]);
}
}
$medalcount = count($membermedal);
if(!empty($membermedal)) {
$mymedal = array();
foreach($membermedal as $medalid) {
if($medalpos = strpos($medalid, '|')) {
$medalid = substr($medalid, 0, $medalpos);
}
$mymedal['name'] = $_G['cache']['medals'][$medalid]['name'];
$mymedal['image'] = $medallist[$medalid]['image'];
$mymedals[] = $mymedal;
}
}
$medallognum = C::t('forum_medallog')->count_by_uid($_G['uid']);
$multipage = multi($medallognum, $tpp, $page, "home.php?mod=medal&action=log");
foreach(C::t('forum_medallog')->fetch_all_by_uid($_G['uid'], $start_limit, $tpp) as $medallog) {
$medallog['name'] = $_G['cache']['medals'][$medallog['medalid']]['name'];
$medallog['dateline'] = dgmdate($medallog['dateline']);
$medallog['expiration'] = !empty($medallog['expiration']) ? dgmdate($medallog['expiration']) : '';
$medallogs[] = $medallog;
}
} else {
showmessage('undefined_action');
}
$navtitle = lang('core', 'title_medals_list');
include template('home/space_medal');
?>