<?php
if ($vbulletin->GPC['userid'])
{
	$userInfo = fetch_userinfo($vbulletin->GPC['userid'], 0, 0, 1);
	$vbulletin->input->clean_gpc('p', 'currency', TYPE_ARRAY_NUM);
	
	foreach ((array)VBSHOP::$cache['currency'] as $currencyid => $currency)
	{
		if (!isset($vbulletin->GPC['currency'][$currencyid]))
		{
			// Ignore this currency
			continue;
		}
		
		if ($userInfo[$currency['pointscolumn']] == $vbulletin->GPC['currency'][$currencyid])
		{
			// No change in points
			continue;
		}
		
		// We're done with the error checking
		$db->query_write("
			UPDATE " . TABLE_PREFIX . $currency['pointstable'] . "
			SET " . $currency['pointscolumn'] . " = " . doubleval($vbulletin->GPC['currency'][$currencyid]) . "
			WHERE userid = " . intval($vbulletin->GPC['userid'])
		);
		
		$info = array(
			'currencyid' 	=> $currencyid,
			'amount' 		=> $vbulletin->GPC['currency'][$currencyid]
		);
		
		// init data manager
		$dm =& VBSHOP::initDataManager('Transactionlog', $vbulletin, ERRTYPE_ARRAY);
			$dm->set('userid', 		$vbulletin->userinfo['userid']);
			$dm->set('recipient', 	$vbulletin->GPC['userid']);
			$dm->set('ipaddress', 	IPADDRESS);
			$dm->set('action', 		'pointsadjust');
			$dm->set('info', 		$info);
		$dm->save();
		unset($dm);	
	}
}
?>