Location: PHPKode > scripts > PHPBB Donation MOD with Paypal IPN > install_PayPal_IPN_Donation_MOD-v1.0.4.6/root/includes/acp/acp_lw_donors_config.php
<?php
/***************************************************************************
 *				acp_lw_donors_config.php
 *							
 *	begin				: 14/SEP/2004
 *	copyright			: Zou Xiong - Loewen Exchange
 *	email				: hide@address.com
 *
 *	version				: 1.0.3 - 30/DEC/2006
 *
 *  @license http://opensource.org/licenses/gpl-license.php GNU Public License
 *  
 ***************************************************************************/
/**
* @package acp
*/
class acp_lw_donors_config
{
	var $u_action;
	
	function main($id, $mode)
	{
		global $config, $db, $user, $auth, $template, $cache;
		global $phpbb_root_path, $phpbb_admin_path, $phpEx, $table_prefix;

		$this->tpl_name = 'acp_lw_donors_config';
		$this->page_title = 'ACP_LW_DONORS_CONFIG';
		
		$submit = isset($_POST['submit']) ? true : false;
		switch ($mode)
		{
			default:
				if ($submit)
				{
					// Get posting variables
					$user_account = request_var('user_account', ''); 
					$lw_money = request_var('lw_money', '0.0'); 
					$lw_date = request_var('lw_date', ''); 
					$txn_id = request_var('txn_id', ''); 
					$donor_pay_acct = request_var('donor_pay_acct', ''); 
			
					$sql = "SELECT * FROM " . USERS_TABLE . " WHERE username = '" . $user_account . "'";
					$user_id = ANONYMOUS;
					if ( ($result = $db->sql_query($sql)) )
					{
						if( ($lwuserdata = $db->sql_fetchrow($result)) )
						{
							if($lwuserdata['user_id'] > 0)
							{
								$user_id = $lwuserdata['user_id'];
							}
						}
					}
					$db->sql_freeresult($result);
					if($user_id > 0)
					{			
						if(intval($config['donate_to_points']) > 0)
						{			
							$sql = "UPDATE " . USERS_TABLE . " SET user_points = user_points + " . (intval(intval($config['donate_to_points']) * ($lw_money + 0.00))) . " WHERE user_id = " . $user_id;
							if ( !($result = $db->sql_query($sql)) )
							{
								//do nothing
							}
							
						}
						else if(intval($config['donate_to_posts']) > 0)
						{			
							$sql = "UPDATE " . USERS_TABLE . " SET user_posts = user_posts + " . (intval(intval($config['donate_to_posts']) * ($lw_money + 0.00))) . " WHERE user_id = " . $user_id;
							if ( !($result = $db->sql_query($sql)) )
							{
								//do nothing
							}
							
						}
						
						
						$sql = "SELECT SUM(lw_money) FROM " . ACCT_HIST_TABLE . " WHERE comment LIKE 'donate from%%' AND user_id = " . $user_id;
						$amount_donated = ($lw_money + 0.00);
						if($result = $db->sql_query($sql))
						{
							if($row = $db->sql_fetchrow($result))
							{
								$amount_donated = $amount_donated + $row["SUM(lw_money)"];
							}
						}
			
						$grptojoin = 0;
						if( intval($config['donate_to_grp_one']) > 0 
							&& ($config['to_grp_one_amount'] + 0.00) <= ($amount_donated) )
						{
							$grptojoin = intval($config['donate_to_grp_one']);
						}
						if(intval($config['donate_to_grp_two']) > 0 
							&& ($config['to_grp_two_amount'] + 0.00) <= ($amount_donated) 
							&& ($config['to_grp_one_amount'] + 0.00) < ($config['to_grp_two_amount'] + 0.00) )
						{
							$grptojoin = intval($config['donate_to_grp_two']);
						}
						if($grptojoin > 0)
						{
						   	$sql = "SELECT * FROM " . USER_GROUP_TABLE . " WHERE group_id = " . $grptojoin . " AND user_id = " . $user_id; 			
						   	// query database 
						   	$need_to_add = 1;
						   	if ( ($result = $db->sql_query($sql)) ) 
						   	{ 
							   	if ( $row = $db->sql_fetchrow($result) ) 
							   	{
			 						if($row['user_pending'] == 0)
			 						{
				 				   		$need_to_add = 0;
			 						}
			 						if($row['user_pending'] != 0)
			 						{
				 				   		$need_to_add = 2; //need update
			 						}
							   	}
						   	}
						   	 
						   	if($need_to_add == 1)
						   	{
								//add to the donor group
								$sql = "INSERT INTO " . USER_GROUP_TABLE . " (user_id, group_id, user_pending) VALUES ($user_id, $grptojoin, 0)";
						
								if( !($result = $db->sql_query($sql)) )
								{
									//do nothing
								}			
								//end add to the donor group
						   		
						   	}
						   	if($need_to_add == 2)
						   	{
								//update the donor group
								$sql = "UPDATE " . USER_GROUP_TABLE . " SET user_pending = 0 WHERE group_id = " . $grptojoin . " AND user_id = " . $user_id;
						
								if( !($result = $db->sql_query($sql)) )
								{
									//do nothing
								}			
								//end update the donor group
						   	}
						}
						
						if( intval($config['donor_rank_id']) > 0 )
						{
							$sql = "UPDATE " . USERS_TABLE . " SET user_rank = " . intval($config['donor_rank_id']) . " WHERE user_id = " . $user_id;
					
							if ( !($result = $db->sql_query($sql)) )
							{
								//do nothing
							}
							
						}
						
					}
			
					//date format YYYY/MM/DD hh:mm:ss
					$user_donate_date = time();
					if(strlen($lw_date) == strlen('YYYY/MM/DD hh:mm:ss'))
					{
						$user_donate_date = mktime(substr($lw_date, 11, 2), substr($lw_date, 14, 2), substr($lw_date, 17, 2), substr($lw_date, 5, 2), substr($lw_date, 8, 2), substr($lw_date, 0, 4));
					}
			
					$sql = "INSERT INTO " . ACCT_HIST_TABLE . "(user_id, lw_post_id, lw_money, lw_plus_minus, MNY_CURRENCY, lw_date, comment, lw_site, status, txn_id) VALUES(" . $user_id . ", 0, " . ($lw_money + 0.00) . ", -1, '" . str_replace("\'", "''", $config['paypal_currency_code']) . "', " . $user_donate_date . ", 'donate from " . str_replace("\'", "''", $donor_pay_acct) . ", Thank you!', '" . $table_prefix . "', 'Completed', '" . str_replace("\'", "''", $txn_id) . "')";
					if ( !($result = $db->sql_query($sql)) )
					{
						// Return a message...
						//$message = $user->lang['New_donor_record_error'] . "<br /><br />" . sprintf($user->lang['Click_return_add_donor'], "<a href=\"" . append_sid("admin_donors.$phpEx") . "\">", "</a>") . "<br /><br />" . sprintf($user->lang['Click_return_admin_index'], "<a href=\"" . append_sid("index.$phpEx?pane=right") . "\">", "</a>");
						$message = $user->lang['New_donor_record_error'];
					}	
					else
					{
			
						// Return a message...
						//$message = $user->lang['New_donor_record_added'] . "<br /><br />" . sprintf($user->lang['Click_return_add_donor'], "<a href=\"" . append_sid("admin_donors.$phpEx") . "\">", "</a>") . "<br /><br />" . sprintf($user->lang['Click_return_admin_index'], "<a href=\"" . append_sid("index.$phpEx?pane=right") . "\">", "</a>");
						$message = $user->lang['New_donor_record_added'];
					}
								
					trigger_error($message . adm_back_link($this->u_action));
				}
				
				$template->assign_vars(array(
					'L_DONOR_CONFIGURATION_TITLE' => $user->lang['L_DONOR_CONFIGURATION_TITLE'],
					'L_DONOR_CONFIGURATION_EXPLAIN' => $user->lang['L_DONOR_CONFIGURATION_EXPLAIN'],
					'L_DONOR_GENERAL_SETTINGS' => $user->lang['L_DONOR_GENERAL_SETTINGS'],
					'L_USER_ACCOUNT' => $user->lang['L_USER_ACCOUNT'],
					'L_DONATE_MONEY' => $user->lang['L_DONATE_MONEY'],
					'L_DONATE_DATE' => $user->lang['L_DONATE_DATE'],
					'L_DONATE_DATE_EXPLAIN' => $user->lang['L_DONATE_DATE_EXPLAIN'],
					'L_TRANSACTION_ID' => $user->lang['L_TRANSACTION_ID'],
					'L_DONOR_PAY_ACCOUNT' => $user->lang['L_DONOR_PAY_ACCOUNT'],
					'L_DONOR_PAY_ACCOUNT_EXPLAIN' => $user->lang['L_DONOR_PAY_ACCOUNT_EXPLAIN'],
		
					//'S_DONOR_CONFIG_ACTION' => append_sid("admin_donors.$phpEx"),
					'U_ACTION' => append_sid($phpbb_admin_path . $this->u_action),
					'S_HIDDEN_FIELDS' => '',
		
		
					'L_SUBMIT' => $user->lang['L_SUBMIT'],
					'L_RESET' => $user->lang['L_RESET'],
					)
				);
				
				
			break;
		}
	}
}

?>
Return current item: PHPBB Donation MOD with Paypal IPN