function doAction($action) { global $vbulletin, $vbphrase, $KBANK_HOOK_NAME; if ($action == 'use') { if ($this->ready2Enable()) { $item_new = array('status' => KBANK_ITEM_USED_WAITING, 'expire_time' => iif($this->data['options']['duration'] > 0, TIMENOW + $this->data['options']['duration'] * 24 * 60 * 60, -1)); $vbulletin->db->query_write(fetch_query_sql($item_new, 'kbank_items', "WHERE itemid = {$this->data[itemid]}")); if ($this->isAvatarItem and !$this->isSigPicItem) { $vbulletin->url = "profile.php?" . $vbulletin->session->vars['sessionurl'] . "do=editavatar"; } else { if (!$this->isAvatarItem and $this->isSigPicItem) { $vbulletin->url = "profile.php?" . $vbulletin->session->vars['sessionurl'] . "do=editsignature"; } else { $vbulletin->url = "profile.php?" . $vbulletin->session->vars['sessionurl']; } } eval(print_standard_redirect('kbank_use_successful')); } } if ($action == 'work' && $KBANK_HOOK_NAME == KBANK_GLOBAL_START && THIS_SCRIPT == 'profile') { global $permissions; $this->do_permissions($permissions, $this->itemtypedata['options']); //Update for later use (?) $vbulletin->userinfo['permissions'] = $permissions; } if ($action == 'work_expired') { global $vbphrase, $kbank_profile_images; $donow = true; $actionStatus = true; echo "Processing item ID#{$this->data[itemid]}<br/>"; //Search for activating item if (!isset($kbank_profile_images[$this->data['userid']])) { $kbank_profile_images[$this->data['userid']] = array(); $itemtypes = $vbulletin->db->query_read("\n\t\t\t\t\t\tSELECT \n\t\t\t\t\t\t\titems.itemid AS itemid\n\t\t\t\t\t\t\t, itemtypes.options AS itemtypeoptions\n\t\t\t\t\t\tFROM `" . TABLE_PREFIX . "kbank_items` AS items\n\t\t\t\t\t\tINNER JOIN `" . TABLE_PREFIX . "kbank_itemtypes` AS itemtypes ON (itemtypes.itemtypeid = items.type)\n\t\t\t\t\t\tWHERE itemtypes.filename = 'profile_images.kbank.php'\n\t\t\t\t\t\t\tAND items.status = " . KBANK_ITEM_USED_WAITING . "\n\t\t\t\t\t\t\tAND (items.expire_time > " . TIMENOW . "\n\t\t\t\t\t\t\t\tOR items.expire_time < 0)\n\t\t\t\t\t\t\tAND items.userid = {$this->data['userid']}\n\t\t\t\t\t"); while ($itemtype = $vbulletin->db->fetch_array($itemtypes)) { $tmp = unserialize($itemtype['itemtypeoptions']); foreach ($this->vars as $var) { $kbank_profile_images[$this->data['userid']][$var] = max($kbank_profile_images[$this->data['userid']][$var], $tmp[$var]); } } } //Check for activating item $donow = false; foreach ($this->vars as $var) { if ($kbank_profile_images[$this->data['userid']][$var] < $this->itemtypedata['options'][$var]) { $donow = true; } } if (!$donow) { //Found other stuff can handle everything echo 'User have other item(s), nothing to do now!<br/>'; } $status = array(); $message = array(); if ($donow) { $owner = fetch_userinfo($this->data['userid']); cache_permissions($owner, false); //Apply activating options to owner permissions; $this->do_permissions($owner['permissions'], $kbank_profile_images[$this->data['userid']]); foreach (array('Avatar', 'SigPic') as $type) { //If this item is this type eval('$work = iif($this->is' . $type . 'Item,true,false);'); switch ($type) { case 'Avatar': $table = 'customavatar'; $fullname = 'avatar'; $bits = $vbulletin->bf_ugp_genericpermissions; $permkey = 'genericpermissions'; $canuse = 'canuseavatar'; $dm = 'Userpic_Avatar'; break; case 'SigPic': $table = 'sigpic'; $fullname = 'sigpic'; $bits = $vbulletin->bf_ugp_signaturepermissions; $permkey = 'signaturepermissions'; $canuse = 'cansigpic'; $dm = 'Userpic_Sigpic'; break; } if ($work) { $removenow = false; $updatedone = false; $message[$type] = ''; $status[$type] = 'none'; //Check if user using system avatar if ($type == 'Avatar' and $owner['avatarid'] != 0) { //Check for System Avatar (only check with type = avatar) echo 'User using System Avatar, do nothing!<br/>'; } else { //Check for custom image if ($customimg = $vbulletin->db->query_first("\n\t\t\t\t\t\t\t\t\tSELECT filedata, dateline, filename, filesize\n\t\t\t\t\t\t\t\t\tFROM `" . TABLE_PREFIX . $table . "`\n\t\t\t\t\t\t\t\t\tWHERE userid = " . intval($owner['userid']) . "\n\t\t\t\t\t\t\t\t\tORDER BY dateline DESC\n\t\t\t\t\t\t\t\t\tLIMIT 1\n\t\t\t\t\t\t\t\t")) { $extension = trim(substr(strrchr(strtolower($customimg['filename']), '.'), 1)); $tmp_filename = DIR . "/includes/tmp_profile_images_{$customimg['dateline']}.{$extension}"; $tmp_file = fopen($tmp_filename, 'w'); fwrite($tmp_file, $customimg['filedata']); fclose($tmp_file); require_once DIR . '/includes/class_image.php'; $image =& vB_Image::fetch_library($vbulletin); $imginfo = $image->fetch_image_info($tmp_filename); if (!($owner['permissions'][$permkey] & $bits[$canuse])) { //Check if user can use Avatar/SigPic echo "User doesn't have permission to use {$type}<br/>"; $removenow = true; } else { if (!($owner['permissions'][$permkey] & $bits['cananimate' . $fullname]) and $imginfo['scenes'] > 1) { //gif, we will not process this one! remove now echo "GIF image found! Remove now!<br/>"; $removenow = true; } else { if ($owner['permissions'][$fullname . 'maxwidth'] < $imginfo[0] or $owner['permissions'][$fullname . 'maxheight'] < $imginfo[1] or $owner['permissions'][$fullname . 'maxsize'] < $customimg['filesize']) { //Check if current custom image exceed user permission options echo "{$type} need to be updated/removed!<br/>"; if ($newimg = $image->fetch_thumbnail(basename($tmp_filename), $tmp_filename, $owner['permissions'][$fullname . 'maxwidth'], $owner['permissions'][$fullname . 'maxheight'], $vbulletin->options['thumbquality'])) { //Trying to update with smaller size echo 'Updating with smaller size! ' . $owner['permissions'][$fullname . 'maxwidth'] . 'x' . $owner['permissions'][$fullname . 'maxheight'] . '<br/>'; $status[$type] = 'update'; $data =& datamanager_init($dm, $vbulletin, ERRTYPE_STANDARD, 'userpic'); $data->set('userid', $owner['userid']); $data->set('dateline', TIMENOW); $data->set('filename', $customimg['filename']); $data->set('width', $newimg['width']); $data->set('height', $newimg['height']); $data->setr('filedata', $newimg['filedata']); if ($newimg['width'] <= $owner['permissions'][$fullname . 'maxwidth'] and $newimg['height'] <= $owner['permissions'][$fullname . 'maxheight'] and $newimg['filesize'] <= $owner['permissions'][$fullname . 'maxsize'] and $data->save()) { $updatedone = true; } else { $removenow = true; } } else { $removenow = true; } } else { echo "{$type} Size Is Okie, do nothing!<br/>"; } } } //Send PM if ($updatedone) { $message[$type] = construct_phrase($vbphrase['kbank_pm_profile_images_message_update'], $newimg['width'], $newimg['height'], $type); } if ($removenow) { //Just remove record echo 'Just remove!<br/>'; $status[$type] = 'remove'; $vbulletin->db->query_write("\n\t\t\t\t\t\t\t\t\t\t\tDELETE FROM `" . TABLE_PREFIX . $table . "`\n\t\t\t\t\t\t\t\t\t\t\tWHERE userid = " . intval($owner['userid']) . "\n\t\t\t\t\t\t\t\t\t\t"); $message[$type] = construct_phrase($vbphrase['kbank_pm_profile_images_message_remove'], $type); } @unlink($tmp_filename); } else { echo "No Custom {$type} found, do nothing!<br/>"; } } } } if (isset($message['Avatar']) or isset($message['SigPic'])) { //Send PM $from = array('userid' => 1, 'username' => $vbphrase['kbank'], 'permissions' => array('pmsendmax' => 5)); $to =& $owner; $subject = $vbphrase['kbank_pm_profile_images_subject']; $message = construct_phrase($vbphrase['kbank_pm_profile_images_message'], $this->data['name'], vbdate($vbulletin->options['dateformat'] . ' ' . $vbulletin->options['timeformat'], $this->data['expire_time']), implode(', ', $message), $vbulletin->options['bburl'] . '/' . $vbulletin->kbank['phpfile'] . '?do=myitems', $vbulletin->options['bburl'] . '/usercp.php'); $result = kbank_sendPM($from, $to, $subject, $message, false); } } $vbulletin->db->query_write("\n\t\t\t\t\tUPDATE `" . TABLE_PREFIX . "kbank_items`\n\t\t\t\t\tSET status = " . KBANK_ITEM_USED . "\n\t\t\t\t\tWHERE itemid = {$this->data['itemid']}\n\t\t\t\t"); if (count($status) == 2) { //Really? Item with both options for Avatar & SigPic. Nothing's impossible! return "Avatar: {$status['Avatar']}; SigPic: {$status['SigPic']}"; } else { foreach ($status as $tmp) { return $tmp; } } } return parent::doAction($action); }
} else { if ($item['userid'] and $to = $vbulletin->db->query_first("\n\t\t\t\tSELECT username, usergroupid, membergroupids\n\t\t\t\tFROM `" . TABLE_PREFIX . "user`\n\t\t\t\tWHERE userid = {$item['userid']}\n\t\t\t") and havePerm($to, KBANK_PERM_COMPANY, true)) { //Seller is a Company, apply Item Tax $taxrate = $vbulletin->kbank['ItemTax']; //If not, apply tax as normal Donate Tax } } $result = transferMoney($userinfo['userid'], $item['userid'], $item['price'], "buy_item_{$item['itemid']}", $userinfo[$vbulletin->kbank['field']], true, false, $taxrate, false, 0, array('banklogs_itemname' => iif($item['userid'] == 0, 'items', 'other'))); if ($result === true) { if ($to) { //send PM $myitems_links = $vbulletin->options['bburl'] . '/' . $vbulletin->kbank['phpfile'] . '?do=myitems'; $from = $userinfo; $message = construct_phrase($vbphrase['kbank_buy_pm_message'], $item['name'], $item['price'], $userinfo['username'], $myitems_link); $subject = $vbphrase['kbank_buy_pm_subject']; $pm_result = kbank_sendPM($from, $to, $subject, $message, false); if ($pm_result !== true) { $errors[$itemid][] = $pm_result; } } } else { $errors[$itemid][] = $result; continue; } //Update total for later use $userinfo[$vbulletin->kbank['field']] -= $vbulletin->kbank['lastTransfered']; if ($item['status'] == KBANK_ITEM_SELLING) { //$item_new_tmp =& newItem($item['itemid'],$item); $item_new = array('expire_time' => $item_obj->data['expire_time']); $item_obj->doAction('buy'); foreach ($item_obj->data as $key => $val) {
function logTransfer($from, $to, $amount, $comment_org, $autopm = true, $tax = 0, $postid = 0) { global $vbulletin, $vbphrase; $result = true; if (is_array($comment_org)) { $comment = serialize($comment_org); } else { $comment = $comment_org; } $donation = array('from' => intval($from), 'to' => intval($to), 'amount' => intval($amount), 'tax' => intval($tax), 'time' => TIMENOW, 'comment' => $comment, 'postid' => intval($postid)); $vbulletin->db->query_write(fetch_query_sql($donation, 'kbank_donations')); if ($to > 0 and $autopm and $vbulletin->kbank['PMLimit'] != 0 and abs($amount) > $vbulletin->kbank['PMLimit'] and $userto = $vbulletin->db->query_first("\n\t\t\tSELECT username\n\t\t\tFROM `" . TABLE_PREFIX . "user`\n\t\t\tWHERE userid = {$to}")) { //send PM $from = $vbulletin->userinfo; if (is_array($comment_org)) { $comment = $comment_org['comment']; } $message = construct_phrase($vbphrase['kbank_donate_pm_message'], $amount, $comment, $vbulletin->options['bburl'] . '/' . $vbulletin->kbank['phpfile'] . '?do=history'); $subject = $vbphrase['kbank_donate_pm_subject']; $result = kbank_sendPM($from, $userto, $subject, $message, false); } return $result; }
function ap_doHistory($postid, $points, $reason) { if (!is_numeric($postid) or $postid <= 0) { exit; } //Error free! global $vbulletin, $vbphrase, $messages; $more_query = array('to' => '', 'from' => ''); //Get user's profile $user = $vbulletin->db->query_first("\n\t\tSELECT \n\t\t\tpost.userid AS userid, \n\t\t\tuser.username AS username,\n\t\t\tuser.{$vbulletin->kbank['field']} AS total, \n\t\t\tuser.usergroupid AS usergroupid,\n\t\t\tuser.membergroupids AS membergroupids,\n\t\t\tuser.displaygroupid AS displaygroupid,\n\t\t\tuser.usertitle AS usertitle,\n\t\t\tuser.customtitle AS customtitle\n\t\tFROM `" . TABLE_PREFIX . "post` AS post\n\t\tINNER JOIN `" . TABLE_PREFIX . "user` AS user ON (user.userid = post.userid)\n\t\tWHERE postid = '{$postid}';"); DEVDEBUG('[kBank Award] ap_doHistory query the database'); //Check for new usergroup moving $newug = 0; foreach ($vbulletin->kbank['award']['listMove2GroupIDs'] as $rule) { $tmp = explode(':', $rule); $result_tmp = 12345; @eval('$result_tmp = (' . ($user['total'] + $points) . $tmp[0] . ');'); if ($result_tmp !== 12345) { if ($result_tmp !== true and $result_tmp !== false) { $result_tmp = 12345; @eval('$result_tmp = (' . ($user['total'] + $points) . '<' . $tmp[0] . ');'); if ($result_tmp === 12345 or $result_tmp !== true or $result_tmp !== false) { $result_tmp = false; } } } else { $result_tmp = false; } if ($result_tmp) { $newug = $tmp[1]; } } if ($newug != 0 and !is_member_of($user, $vbulletin->kbank['award']['permCanRemoveGroupIDs']) and !is_member_of($user, $newug)) { $more_query['to'] .= " ,usergroupid = {$newug}"; } else { $newug = 0; } //Done with finding new usergroup //Add ban record if needed (if new group is a ban group) if ($newug) { //Find 'is ban group' groups $querygroups = array(); foreach ($vbulletin->usergroupcache as $usergroupid => $usergroup) { if (!($usergroup['genericoptions'] & $vbulletin->bf_ugp_genericoptions['isnotbannedgroup'])) { $querygroups[] = $usergroupid; } } if (in_array($newug, $querygroups)) { $adminid = $vbulletin->userinfo['userid']; if (!$vbulletin->db->query_first("\n\t\t\t\t\tSELECT * FROM `" . TABLE_PREFIX . "userban`\n\t\t\t\t\tWHERE userid = {$user['userid']}\n\t\t\t\t")) { $vbulletin->db->query("\n\t\t\t\t\tINSERT INTO `" . TABLE_PREFIX . "userban`\n\t\t\t\t\t(userid, usergroupid, displaygroupid, usertitle, customtitle, adminid, bandate, liftdate, reason)\n\t\t\t\t\tVALUES (\n\t\t\t\t\t\t{$user['userid']}\n\t\t\t\t\t\t,{$user['usergroupid']}\n\t\t\t\t\t\t,{$user['displaygroupid']}\n\t\t\t\t\t\t,'{$user['usertitle']}'\n\t\t\t\t\t\t,{$user['customtitle']}\n\t\t\t\t\t\t,{$adminid}\n\t\t\t\t\t\t," . TIMENOW . "\n\t\t\t\t\t\t,0\n\t\t\t\t\t\t,'{$vbphrase['kbank_award_bank_rupted']}'\n\t\t\t\t\t);"); DEVDEBUG('[kBank Award] ap_doHistory query the database 2 times'); } $more_query['to'] .= " ,usertitle = '{$vbphrase['kbank_award_bank_rupted']}'"; } } //Adjust counter $more_query['to'] .= iif($reason != AWARD_REMOVE, " ,{$vbulletin->kbank['award']['awardedtimes']} = {$vbulletin->kbank['award']['awardedtimes']} + 1", " ,{$vbulletin->kbank['award']['awardedtimes']} = {$vbulletin->kbank['award']['awardedtimes']} - 1") . " ,{$vbulletin->kbank['award']['awardedamount']} = {$vbulletin->kbank['award']['awardedamount']} + {$points}"; //Specified itemname for banklogs $more_query['banklogs'] = array('itemname' => 'post'); //Update database $result = transferMoney(0, $user['userid'], $points, array('adminid' => $vbulletin->userinfo['userid'], 'comment' => $reason), null, true, false, KBANK_NO_TAX, false, $postid, $more_query); //Send PM to user (if action done successfully) if ($result === true and $vbulletin->kbank['award']['sendPM']) { //build title,message $url = $vbulletin->options['bburl']; if ($reason != AWARD_REMOVE) { $title = $vbphrase['kbank_award_PM_title']; $text = construct_phrase($vbphrase['kbank_award_PM_text'], "{$url}/showthread.php?p={$postid}", $points, $reason, "{$url}/member.php?u={$vbulletin->userinfo['userid']}", $vbulletin->userinfo['username'], $vbulletin->kbank['name']); } else { $title = $vbphrase['kbank_award_PM_title_deleted']; $text = construct_phrase($vbphrase['kbank_award_PM_text_deleted'], "{$url}/showthread.php?p={$postid}", "{$url}/member.php?u={$vbulletin->userinfo['userid']}", $vbulletin->userinfo['username']); } if ($newug != 0) { $text .= construct_phrase($vbphrase['kbank_award_usergroup_moved'], $newug); $messages[] = construct_phrase($vbphrase['kbank_award_usergroup_moved_for_admin'], $newug, $user['username']); } $result = kbank_sendPM($vbulletin->userinfo, $user, $title, $text, false); } return $result; }