Example #1
0
<?php

/*
	[Discuz!] (C)2001-2009 Comsenz Inc.
	This is NOT a freeware, use is subject to license terms

	$Id: magic_up.inc.php 16688 2008-11-14 06:41:07Z cnteacher $
*/
if (!defined('IN_DISCUZ')) {
    exit('Access Denied');
}
$getmagicdata = $magicperm['presentcontent'];
if (submitcheck('usesubmit')) {
    foreach ($getmagicdata as $getmagicid => $magicdata) {
        $totalweight = $magicdata['num'] * $magicdata['weight'];
        getmagic($getmagicid, $magicdata['num'], $magicdata['weight'], $totalweight, $discuz_uid, 0, 1);
    }
    usemagic($magicid, $magic['num']);
    updatemagiclog($magicid, '2', '1', '0', $tid);
    updatemagicthreadlog($tid, $magicid, $magic['identifier']);
    showmessage('magics_operation_succeed', '', 1);
}
function showmagic()
{
    global $lang;
    magicshowtips($lang['NEW_info'], $lang['option']);
}
Example #2
0
     } else {
         $magicnum = intval($_GET['magicnum']);
         $magic['weight'] = $magic['weight'] * $magicnum;
         $totalprice = $magic['discountprice'] * $magicnum;
         if (getuserprofile('extcredits' . $magic['credit']) < $totalprice) {
             if ($_G['setting']['ec_ratio'] && $_G['setting']['creditstrans'][0] == $magic['credit']) {
                 showmessage('magics_credits_no_enough_and_charge', '', array('credit' => $_G['setting']['extcredits'][$magic['credit']]['title']));
             } else {
                 showmessage('magics_credits_no_enough', '', array('credit' => $_G['setting']['extcredits'][$magic['credit']]['title']));
             }
         } elseif ($magic['num'] < $magicnum) {
             showmessage('magics_num_no_enough');
         } elseif (!$magicnum || $magicnum < 0) {
             showmessage('magics_num_invalid');
         }
         getmagic($magic['magicid'], $magicnum, $magic['weight'], $totalweight, $_G['uid'], $_G['group']['maxmagicsweight']);
         updatemagiclog($magic['magicid'], '1', $magicnum, $magic['price'] . '|' . $magic['credit'], $_G['uid']);
         C::t('common_magic')->update_salevolume($magic['magicid'], $magicnum);
         updatemembercount($_G['uid'], array($magic['credit'] => -$totalprice), true, 'BMC', $magic['magicid']);
         showmessage('magics_buy_succeed', 'home.php?mod=magic&action=mybox', array('magicname' => $magic['name'], 'num' => $magicnum, 'credit' => $totalprice . ' ' . $_G['setting']['extcredits'][$magic['credit']]['unit'] . $_G['setting']['extcredits'][$magic['credit']]['title']));
     }
 } elseif ($operation == 'give') {
     if ($_G['group']['allowmagics'] < 2) {
         showmessage('magics_nopermission');
     }
     $magic = C::t('common_magic')->fetch_by_identifier($_GET['mid']);
     if (!$magic || !$magic['available']) {
         showmessage('magics_nonexistence');
     }
     $magic['discountprice'] = $_G['group']['magicsdiscount'] ? intval($magic['price'] * ($_G['group']['magicsdiscount'] / 10)) : intval($magic['price']);
     $magic['pic'] = strtolower($magic['identifier']) . ".gif";
function givemagic($username, $magicid, $magicnum, $totalnum, $totalprice, $givemessage, $magicarray)
{
    global $_G;
    $member = C::t('common_member')->fetch_by_username($username);
    if (!$member) {
        showmessage('magics_target_member_nonexistence');
    } elseif ($member['uid'] == $_G['uid']) {
        showmessage('magics_give_myself');
    }
    $member = array_merge(C::t('common_usergroup_field')->fetch($member['groupid']), $member);
    $totalweight = getmagicweight($member['uid'], $magicarray);
    $magicweight = $magicarray[$magicid]['weight'] * $magicnum;
    if ($magicarray[$magicid]['weight'] && $magicweight + $totalweight > $member['maxmagicsweight']) {
        $num = floor(($member['maxmagicsweight'] - $totalweight) / $magicarray[$magicid]['weight']);
        $num = max(0, $num);
        showmessage('magics_give_weight_range_invalid', '', array('num' => $num));
    }
    getmagic($magicid, $magicnum, $magicweight, $totalweight, $member['uid'], $member['maxmagicsweight']);
    notification_add($member['uid'], 'magic', 'magics_receive', array('magicname' => $magicarray[$magicid]['name'], 'msg' => $givemessage));
    updatemagiclog($magicid, '3', $magicnum, $magicarray[$magicid]['price'], $member['uid']);
    if (empty($totalprice)) {
        usemagic($magicid, $totalnum, $magicnum);
        showmessage('magics_give_succeed', 'home.php?mod=magic&action=mybox', array('toname' => $username, 'num' => $magicnum, 'magicname' => $magicarray[$magicid]['name']));
    }
}
Example #4
0
function givemagic($username, $magicid, $magicnum, $totalnum, $totalprice)
{
    global $db, $tablepre, $discuz_uid, $discuz_user, $creditstrans, $creditstransextra, $magicarray;
    $member = $db->fetch_first("SELECT m.uid, m.username, u.maxmagicsweight FROM {$tablepre}members m LEFT JOIN {$tablepre}usergroups u ON u.groupid=m.groupid WHERE m.username='******'");
    if (!$member) {
        showmessage('magics_target_nonexistence');
    } elseif ($member['uid'] == $discuz_uid) {
        showmessage('magics_give_myself');
    }
    $totalweight = getmagicweight($member['uid'], $magicarray);
    $magicweight = $magicarray[$magicid]['weight'] * $magicnum;
    getmagic($magicid, $magicnum, $magicweight, $totalweight, $member['uid'], $member['maxmagicsweight']);
    sendpm($member['uid'], 'magics_receive_subject', 'magics_receive_message', 0);
    updatemagiclog($magicid, '3', $magicnum, $magicarray[$magicid]['price'], '0', '0', $member['uid']);
    if (empty($totalprice)) {
        usemagic($magicid, $totalnum, $magicnum);
        showmessage('magics_give_succeed', '', 1);
    }
}
Example #5
0
function givemagic($username, $magicid, $magicnum, $totalnum, $totalprice, $givemessage, $magicarray)
{
    global $_G;
    $member = DB::fetch_first("SELECT m.uid, m.username, u.maxmagicsweight FROM " . DB::table('common_member') . " m LEFT JOIN " . DB::table('common_usergroup_field') . " u ON u.groupid=m.groupid WHERE m.username='******'");
    if (!$member) {
        showmessage('magics_target_nonexistence');
    } elseif ($member['uid'] == $_G['uid']) {
        showmessage('magics_give_myself');
    }
    $totalweight = getmagicweight($member['uid'], $magicarray);
    $magicweight = $magicarray[$magicid]['weight'] * $magicnum;
    if ($magicarray[$magicid]['weight'] && $magicweight + $totalweight > $member['maxmagicsweight']) {
        $num = floor(($member['maxmagicsweight'] - $totalweight) / $magicarray[$magicid]['weight']);
        $num = max(0, $num);
        showmessage('magics_give_weight_range_invalid', '', array('num' => $num));
    }
    getmagic($magicid, $magicnum, $magicweight, $totalweight, $member['uid'], $member['maxmagicsweight']);
    notification_add($member['uid'], 'magic', 'magics_receive', array('magicname' => $magicarray[$magicid]['name'], 'msg' => $givemessage));
    updatemagiclog($magicid, '3', $magicnum, $magicarray[$magicid]['price'], $member['uid']);
    if (empty($totalprice)) {
        usemagic($magicid, $totalnum, $magicnum);
        showmessage('magics_give_succeed', 'home.php?mod=magic&action=mybox', array('toname' => $username, 'num' => $magicnum, 'magicname' => $magicarray[$magicid]['name']));
    }
}
Example #6
0
            }
            getmagic($magic['magicid'], $magicnum, $magicweight, $totalweight, $discuz_uid, $maxmagicsweight);
            $totalcredit = floor($magicprice * (1 - $creditstax));
            $db->query("UPDATE {$tablepre}members SET extcredits{$creditstrans}=extcredits{$creditstrans}+'{$totalcredit}' WHERE uid='{$magic['uid']}'");
            $db->query("UPDATE {$tablepre}members SET extcredits{$creditstrans}=extcredits{$creditstrans}+(-'{$magicprice}') WHERE uid='{$discuz_uid}'");
            sendpm($magic['uid'], 'magics_sell_subject', 'magics_sell_message');
            updatemagiclog($magic['magicid'], '5', $magicnum, $magic['price'], '0', $discuz_uid);
            marketmagicnum($magic['mid'], $magic['num'], $magicnum);
            showmessage('magics_succeed', 'magic.php?action=market');
        }
        if (submitcheck('downsubmit')) {
            if ($magic['num'] < $magicnum || $magicnum < 0) {
                showmessage('magics_amount_no_enough');
            }
            $magic['weight'] = $magic['weight'] * $magicnum;
            getmagic($magic['magicid'], $magicnum, $magic['weight'], $totalweight, $discuz_uid, $maxmagicsweight);
            updatemagiclog($magic['magicid'], '6', $magicnum, '0', '0', $discuz_uid);
            marketmagicnum($magic['mid'], $magic['num'], $magicnum);
            showmessage('magics_succeed', 'magic.php?action=market');
        }
        include template('magic_market');
    }
} elseif ($action == 'log') {
    $discuz_action = 173;
    $loglist = array();
    if ($operation == 'uselog') {
        $query = $db->query("SELECT COUNT(*) FROM {$tablepre}magiclog WHERE action='2' AND uid='{$discuz_uid}'");
        $multipage = multi($db->result($query, 0), $tpp, $page, 'magic.php?action=log&amp;operation=uselog');
        $query = $db->query("SELECT ml.*, me.username FROM {$tablepre}magiclog ml\r\n\t\t\tLEFT JOIN {$tablepre}members me ON me.uid=ml.uid\r\n\t\t\tWHERE ml.action='2' AND ml.uid='{$discuz_uid}' ORDER BY ml.dateline DESC\r\n\t\t\tLIMIT {$start_limit}, {$tpp}");
        while ($log = $db->fetch_array($query)) {
            $log['dateline'] = gmdate("{$dateformat} {$timeformat}", $log['dateline'] + $timeoffset * 3600);