Thread: Add-On Releases - vBookie for vBulletin 4
View Single Post
  #757  
Old 01-15-2012, 02:16 PM
acast acast is offline
 
Join Date: Aug 2008
Posts: 179
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Edit: It is working the code por Functions_vbookie.php to integrate vbbux in Custom.

Code:
<?php
// Last updated version 4.0.7 19-02-2010 10:07


function vbookie_get_user_bet_count($item_id=0)
{
	global $vbulletin;

	$user_n_bets_placed_result = $vbulletin->db->query_first("
		SELECT COUNT(bet_id) AS user_n_bets_placed
		FROM " . TABLE_PREFIX . "vbookie_bets_placed
		WHERE userid = " . $vbulletin->userinfo['userid'] . " AND item_id = $item_id
	");
	
	return (int)$user_n_bets_placed_result['user_n_bets_placed'];

}

function vbookie_get_user_cash()
{
	global $vbulletin;

	switch ($vbulletin->options['vbookiecash'])
	{
		case 'vCash':
			$cash = (int)$vbulletin->userinfo['vbookie_cash'];
			break;
		case 'uCash':
			$cash = (int)$vbulletin->userinfo['ucash'];
			break;
		case 'eBux':
			$cash = (int)$vbulletin->userinfo['ebux'];
			break;
		case 'vbCredits':
			$cash = (int)$vbulletin->userinfo['credits'];
			break;
		case 'Reputation':
			$cash = (int)$vbulletin->userinfo['reputation'];
			break;
		case 'Custom':
			$cash = (int)$vbulletin->userinfo['vbbux'];
			break;
		
	}
	
	return $cash;
}

function vbookie_take_user_cash($amount)
{
	global $vbulletin;

	switch ($vbulletin->options['vbookiecash'])
	{
		case 'vCash':
			$vbulletin->db->query_write("UPDATE " . TABLE_PREFIX . "user SET vbookie_cash=vbookie_cash-$amount WHERE userid=" . $vbulletin->userinfo['userid']);	
			break;
		case 'uCash':
			$vbulletin->db->query_write("UPDATE " . TABLE_PREFIX . "user SET ucash=ucash-$amount WHERE userid=" . $vbulletin->userinfo['userid']);	
			break;
		case 'eBux':
			$vbulletin->db->query_write("UPDATE " . TABLE_PREFIX . "user SET ebux=ebux-$amount WHERE userid=" . $vbulletin->userinfo['userid']);	
			$cash = (int)$vbulletin->userinfo['ebux'];
			break;
		case 'vbCredits':
			$vbulletin->db->query_write("UPDATE " . TABLE_PREFIX . "user SET credits=credits-$amount WHERE userid=" . $vbulletin->userinfo['userid']);	
			$cash = (int)$vbulletin->userinfo['credits'];
			break;
		case 'Reputation':
			$vbulletin->db->query_write("UPDATE " . TABLE_PREFIX . "user SET reputation=reputation-$amount WHERE userid=" . $vbulletin->userinfo['userid']);	
			$cash = (int)$vbulletin->userinfo['reputation'];
			break;
		case 'Custom':
			$vbulletin->db->query_write("UPDATE " . TABLE_PREFIX . "user SET vbbux=vbbux-$amount WHERE userid=" . $vbulletin->userinfo['userid']);	
			$cash = (int)$vbulletin->userinfo['vbbux'];
			break;
		
	}
}

function vbookie_give_user_cash($userid, $amount)
{
	global $vbulletin;

	switch ($vbulletin->options['vbookiecash'])
	{
		case 'vCash':
			$vbulletin->db->query_write("UPDATE " . TABLE_PREFIX . "user SET vbookie_cash=vbookie_cash+$amount WHERE userid=$userid");	
			break;
		case 'uCash':
			$vbulletin->db->query_write("UPDATE " . TABLE_PREFIX . "user SET ucash=ucash+$amount WHERE userid=$userid");	
			break;
		case 'eBux':
			$vbulletin->db->query_write("UPDATE " . TABLE_PREFIX . "user SET ebux=ebux+$amount WHERE userid=$userid");	
			$cash = (int)$vbulletin->userinfo['ebux'];
			break;
		case 'vbCredits':
			$vbulletin->db->query_write("UPDATE " . TABLE_PREFIX . "user SET credits=credits+$amount WHERE userid=$userid");	
			$cash = (int)$vbulletin->userinfo['credits'];
			break;
		case 'Reputation':
			$vbulletin->db->query_write("UPDATE " . TABLE_PREFIX . "user SET reputation=reputation+$amount WHERE userid=$userid");	
			$cash = (int)$vbulletin->userinfo['reputation'];
			break;
		case 'Custom':
			$vbulletin->db->query_write("UPDATE " . TABLE_PREFIX . "user SET vbbux=vbbux+$amount WHERE userid=$userid");	
			$cash = (int)$vbulletin->userinfo['vbbux'];
			break;
		
	}
}

function vbookie_abandon_event($item_id=0)
{
	global $vbulletin;

	if ((int)$item_id)
	{
		$q = "UPDATE ". TABLE_PREFIX . "vbookie_items SET item_status='ABANDONED' WHERE item_id=$item_id";
		$vbulletin->db->query($q);

		// update running totals
		$q = "UPDATE " . TABLE_PREFIX . "vbookie_item_options SET option_amount_staked=0, option_n_bets_placed=0 WHERE item_id=$item_id";	
		$vbulletin->db->query($q);

		// update running totals
		$q = "UPDATE " . TABLE_PREFIX . "vbookie_items SET item_n_bets_placed=0, item_amount_staked=0 WHERE item_id=$item_id";	
		$vbulletin->db->query($q);

		$result = $vbulletin->db->query_read("SELECT p.userid, p.bet_amount_placed FROM " . TABLE_PREFIX . "vbookie_bets_placed AS p LEFT JOIN " . TABLE_PREFIX . "user AS u ON(u.userid = p.userid) WHERE p.item_id=$item_id");

		while ($bet = $vbulletin->db->fetch_array($result)) 
		{
			// pay the money back
			vbookie_give_user_cash($bet['userid'], $bet['bet_amount_placed']);
		}
	}
}

function vbookie_get_richest()
{
	global $vbulletin;

	switch ($vbulletin->options['vbookiecash'])
	{
		case 'vCash':
			$q = "SELECT username, vbookie_cash AS cash FROM " . TABLE_PREFIX . "user ORDER BY cash DESC LIMIT 5";	
			break;
		case 'uCash':
			$q = "SELECT username, ucash AS cash FROM " . TABLE_PREFIX . "user ORDER BY cash DESC LIMIT 5";	
			break;
		case 'eBux':
			$q = "SELECT username, ebux AS cash FROM " . TABLE_PREFIX . "user ORDER BY cash DESC LIMIT 5";	
			break;
		case 'vbCredits':
			$q = "SELECT username, credits AS cash FROM " . TABLE_PREFIX . "user ORDER BY cash DESC LIMIT 5";	
			break;
		case 'Reputation':
			$q = "SELECT username, reputation AS cash FROM " . TABLE_PREFIX . "user ORDER BY cash DESC LIMIT 5";	
			break;
		case 'Custom':
			$q = "SELECT username, vbbux AS cash FROM " . TABLE_PREFIX . "user ORDER BY cash DESC LIMIT 5";	
			break;
	
	}

	return $vbulletin->db->query_read($q);
}

function vbookie_do_charity()
{
	global $vbulletin;


	if ($vbulletin->options['vbookiegivetopoor'])
	{
		switch ($vbulletin->options['vbookiecash'])
		{
			case 'vCash':
				$vbulletin->db->query_write("UPDATE " . TABLE_PREFIX . "user SET vbookie_cash=" . $vbulletin->options['vbookiegivetopoor'] . " WHERE vbookie_cash < " . $vbulletin->options['vbookiegivetopoor']);	
				break;
			case 'uCash':
				$vbulletin->db->query_write("UPDATE " . TABLE_PREFIX . "user SET ucash=" . $vbulletin->options['vbookiegivetopoor'] . " WHERE ucash < " . $vbulletin->options['vbookiegivetopoor']);	
				break;
			case 'eBux':
				$vbulletin->db->query_write("UPDATE " . TABLE_PREFIX . "user SET ebux=" . $vbulletin->options['vbookiegivetopoor'] . " WHERE ebux < " . $vbulletin->options['vbookiegivetopoor']);	
				break;
			case 'vbCredits':
				$vbulletin->db->query_write("UPDATE " . TABLE_PREFIX . "user SET credits=" . $vbulletin->options['vbookiegivetopoor'] . " WHERE credits < " . $vbulletin->options['vbookiegivetopoor']);	
				break;
			case 'Reputation':
				$vbulletin->db->query_write("UPDATE " . TABLE_PREFIX . "user SET reputation=" . $vbulletin->options['vbookiegivetopoor'] . " WHERE reputation < " . $vbulletin->options['vbookiegivetopoor']);	
				break;
			case 'Custom':
				$vbulletin->db->query_write("UPDATE " . TABLE_PREFIX . "user SET vbbux=" . $vbulletin->options['vbookiegivetopoor'] . " WHERE vbbux < " . $vbulletin->options['vbookiegivetopoor']);	
				break;
		
		}
	}
}

function vbookie_delete_event($eventinfo)
{
	global $vbulletin;
	($hook = vBulletinHook::fetch_hook('vbookie_delete_event')) ? eval($hook) : false;
	// if we're deleting an event that has bets on it but hasn't yet been settled,
	// we must give people their money back.
	if ($eventinfo['item_status'] == 'OPEN' OR $eventinfo['item_status'] == 'CLOSED')
	{
		// abandon the bet
		vbookie_abandon_event($eventinfo['item_id']);
	}

	$vbulletin->db->query_write("DELETE FROM ". TABLE_PREFIX . "vbookie_bets_placed WHERE item_id=$eventinfo[item_id]");
	$vbulletin->db->query_write("DELETE FROM ". TABLE_PREFIX . "vbookie_item_options WHERE item_id=$eventinfo[item_id]");
	$vbulletin->db->query_write("DELETE FROM ". TABLE_PREFIX . "vbookie_items WHERE item_id=$eventinfo[item_id]");

	// update the thread this was attached to to remove the event.
	$vbulletin->db->query_write("UPDATE " . TABLE_PREFIX . "thread SET vbookie_item_id=0 WHERE vbookie_item_id=$eventinfo[item_id]");
}

function vbookie_reset_vcash($amount)
{
	global $vbulletin;
		$q = "UPDATE " . TABLE_PREFIX . "user SET vbookie_cash =".$amount;	
	return $vbulletin->db->query($q);
		
	
}

function vbookie_set_default_vcash($amount)
{
	global $vbulletin;
		$q = "ALTER TABLE " . TABLE_PREFIX . "user CHANGE COLUMN vbookie_cash vbookie_cash BIGINT(20) UNSIGNED NULL DEFAULT ".$amount;	
	return $vbulletin->db->query($q);
}

function vbookie_give_users_vcash($amount)
{
	global $vbulletin;
		$q="UPDATE " . TABLE_PREFIX . "user SET vbookie_cash=vbookie_cash+$amount";
	return $vbulletin->db->query($q);

}
// Additional pay/debit bookie
function vbookie_take_bookie_cash($userid, $amount)
{
	global $vbulletin;

	$bookie = $vbulletin->db->query_first("SELECT * FROM " . TABLE_PREFIX . "user WHERE userid=$userid");

	switch ($vbulletin->options['vbookiecash'])
	{
		case 'vCash':
		
		
			if($amount > $bookie['vbookie_cash'])
			{
				$vbulletin->db->query_write("UPDATE " . TABLE_PREFIX . "user SET vbookie_cash=0 WHERE userid=$userid");
			}
			else
			{
				$vbulletin->db->query_write("UPDATE " . TABLE_PREFIX . "user SET vbookie_cash=vbookie_cash-$amount WHERE userid=$userid");
			}
			break;
		case 'uCash':
			if($amount > $bookie['ucash'])
			{
				$vbulletin->db->query_write("UPDATE " . TABLE_PREFIX . "user SET ucash=0 WHERE userid=$userid");
			}
			else
			{
				$vbulletin->db->query_write("UPDATE " . TABLE_PREFIX . "user SET ucash=ucash-$amount WHERE userid=$userid");
			}
			break;
		case 'eBux':
			if($amount > $bookie['ebux'])
			{
				$vbulletin->db->query_write("UPDATE " . TABLE_PREFIX . "user SET ebux=0 WHERE userid=$userid");
			}
			else
			{
				$vbulletin->db->query_write("UPDATE " . TABLE_PREFIX . "user SET ebux=ebux-$amount WHERE userid=$userid");
			}
			break;
		case 'Custom':
				if($amount > $bookie['vbbux'])
			{
				$vbulletin->db->query_write("UPDATE " . TABLE_PREFIX . "user SET vbbux=0 WHERE userid=$userid");
			}
			else
			{
				$vbulletin->db->query_write("UPDATE " . TABLE_PREFIX . "user SET vbbux=vbbux-$amount WHERE userid=$userid");
			}
			break;
	}
}
?>
Reply With Quote
 
X vBulletin 3.8.12 by vBS Debug Information
  • Page Generation 0.01303 seconds
  • Memory Usage 1,825KB
  • Queries Executed 11 (?)
More Information
Template Usage:
  • (1)SHOWTHREAD_SHOWPOST
  • (1)ad_footer_end
  • (1)ad_footer_start
  • (1)ad_header_end
  • (1)ad_header_logo
  • (1)ad_navbar_below
  • (1)bbcode_code
  • (1)footer
  • (1)gobutton
  • (1)header
  • (1)headinclude
  • (6)option
  • (1)post_thanks_box
  • (1)post_thanks_button
  • (1)post_thanks_javascript
  • (1)post_thanks_navbar_search
  • (1)post_thanks_postbit_info
  • (1)postbit
  • (1)postbit_onlinestatus
  • (1)postbit_wrapper
  • (1)spacer_close
  • (1)spacer_open 

Phrase Groups Available:
  • global
  • postbit
  • reputationlevel
  • showthread
Included Files:
  • ./showpost.php
  • ./global.php
  • ./includes/init.php
  • ./includes/class_core.php
  • ./includes/config.php
  • ./includes/functions.php
  • ./includes/class_hook.php
  • ./includes/modsystem_functions.php
  • ./includes/functions_bigthree.php
  • ./includes/class_postbit.php
  • ./includes/class_bbcode.php
  • ./includes/functions_reputation.php
  • ./includes/functions_post_thanks.php 

Hooks Called:
  • init_startup
  • init_startup_session_setup_start
  • init_startup_session_setup_complete
  • cache_permissions
  • fetch_postinfo_query
  • fetch_postinfo
  • fetch_threadinfo_query
  • fetch_threadinfo
  • fetch_foruminfo
  • style_fetch
  • cache_templates
  • global_start
  • parse_templates
  • global_setup_complete
  • showpost_start
  • bbcode_fetch_tags
  • bbcode_create
  • postbit_factory
  • showpost_post
  • postbit_display_start
  • post_thanks_function_post_thanks_off_start
  • post_thanks_function_post_thanks_off_end
  • post_thanks_function_fetch_thanks_start
  • post_thanks_function_fetch_thanks_end
  • post_thanks_function_thanked_already_start
  • post_thanks_function_thanked_already_end
  • fetch_musername
  • postbit_imicons
  • bbcode_parse_start
  • bbcode_parse_complete_precache
  • bbcode_parse_complete
  • postbit_display_complete
  • post_thanks_function_can_thank_this_post_start
  • showpost_complete