magic_gift.php
2.59 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
<?php
/**
* [Discuz!] (C)2001-2099 Comsenz Inc.
* This is NOT a freeware, use is subject to license terms
*
* $Id: magic_gift.php 26749 2011-12-22 07:38:37Z chenmengshu $
*/
if(!defined('IN_DISCUZ')) {
exit('Access Denied');
}
class magic_gift {
var $version = '1.0';
var $name = 'gift_name';
var $description = 'gift_desc';
var $price = '20';
var $weight = '20';
var $useevent = 0;
var $targetgroupperm = false;
var $copyright = '<a href="http://www.comsenz.com" target="_blank">Comsenz Inc.</a>';
var $magic = array();
var $parameters = array();
function getsetting(&$magic) {
$settings = array();
return $settings;
}
function setsetting(&$magicnew, &$parameters) {
}
function usesubmit() {
global $_G;
$info = array(
'credits' => intval($_POST['credits']),
'percredit' => intval($_POST['percredit']),
'credittype' => $_GET['credittype'],
'left' => intval($_POST['credits']),
'magicid' => intval($this->magic['magicid']),
'receiver' => array()
);
if($info['credits'] < 1) {
showmessage(lang('magic/gift', 'gift_bad_credits_input'));
}
if($info['percredit'] < 1 || $info['percredit'] > $info['credits']) {
showmessage(lang('magic/gift', 'gift_bad_percredit_input'));
}
$member = array();
if(preg_match('/^extcredits[1-8]$/', $info['credittype'])) {
$member = C::t('common_member_count')->fetch($_G['uid']);
if($member[$info['credittype']] < $info['credits']) {
showmessage(lang('magic/gift', 'gift_credits_out_of_own'));
}
$extcredits = str_replace('extcredits', '', $info['credittype']);
updatemembercount($_G['uid'], array($extcredits => -$info['credits']), 1, 'BGC', $this->magic['magicid']);
} else {
showmessage(lang('magic/gift', 'gift_bad_credittype_input'));
}
C::t('common_member_field_home')->update($_G['uid'], array('magicgift' => serialize($info)));
usemagic($this->magic['magicid'], $this->magic['num']);
updatemagiclog($this->magic['magicid'], '2', '1', '0', '0', 'uid', $_G['uid']);
showmessage(lang('magic/gift', 'gift_succeed'), dreferer(), array(), array('alert' => 'right', 'showdialog' => 1, 'locationtime' => true));
}
function show() {
global $_G;
$num = !empty($this->parameters['num']) ? intval($this->parameters['num']) : 10;
magicshowtips(lang('magic/gift', 'gift_info', array('num'=>$num)));
$extcredits = array();
foreach($_G['setting']['extcredits'] as $id => $credit) {
$extcredits['extcredits'.$id] = $credit['title'];
}
$op = 'show';
include template('home/magic_gift');
}
}
?>