<?php

$ipn_data = array (); /* array to hold POST values from AlertPay IPN */

include "config.php";

/* check the security code sent with the post to ensure that the post came from AlertPay */

$ap_sec_code = $_POST ['ap_securitycode'];

if ($seccode == $ap_sec_code) {

	$amount = $_POST ['ap_amount'];

	$userid = $_POST ['apc_1'];

	$item = $_POST ['ap_itemname'];
	$quantity = $_POST ['ap_quantity'];
	$query = "select * from members where userid='" . dbput ( $userid ) . "'";

	$result = mysql_query ( $query ) or

	die ( "Query failed" );

	$numrows = @ mysql_num_rows ( $result );

	if ($numrows == 1) {

		$user = mysql_fetch_array ( $result );
		if ($item != $sitename . " Membership " . $userid and $item != $sitename . " One-Time Offer") {
			if ($mpool == "1") {
				ppbuypool ( $userid, $payment_amount );
			}

			$projvcom = 0;
			$jvjvcom = 0;
			$superjvjvcom = 0;
			$prosupercom = 0;
			$jvsupercom = 0;
			$superjv2supercom = 0;
		}

		if ($item == $sitename . " One-Time Offer") {

			if ($mpool == "1") {
				ppbuypool ( $userid, $payment_amount );
			}

			$projvcom = 0;
			$jvjvcom = 0;
			$superjvjvcom = 0;
			$prosupercom = 0;
			$jvsupercom = 0;
			$superjv2supercom = 0;

			mysql_query ( "INSERT INTO transactions VALUES ('id', '" . dbput ( $userid ) . "','Payza Payment - OTO','" . time () . "','$amount\$')" );

			$sql = mysql_query ( "SELECT * FROM oto LIMIT 1" );

			$oto = mysql_fetch_array ( $sql );

			otocommission ( $user ['referid'], $userid, $oto );

			if ($oto ['points'])
				mysql_query ( "UPDATE members SET points=points+" . $oto ['points'] . " WHERE userid='" . dbput ( $userid ) . "'" );

			if ($oto ['banner_num'] and $oto ['banner_views']) {

				$count = $oto ['banner_num'];

				while ( $count > 0 ) {

					mysql_query ( "INSERT INTO `banners` ( `id` , `name` , `bannerurl` , `targeturl` , `userid` , `status` , `shown` , `clicks` , `max` , `added` )VALUES (NULL , '', '', '', '" . dbput ( $userid ) . "', '0', '0', '0', '" . $oto ['banner_views'] . "', '0')" );

					$count --;

				}

			}

			if ($oto ['button_num'] and $oto ['button_views']) {

				$count = $oto ['button_num'];

				while ( $count > 0 ) {

					mysql_query ( "INSERT INTO `buttons` ( `id` , `name` , `bannerurl` , `targeturl` , `userid` , `status` , `shown` , `clicks` , `max` , `added` )VALUES (NULL , '', '', '', '" . dbput ( $userid ) . "', '0', '0', '0', '" . $oto ['button_views'] . "', '0')" );

					$count --;

				}

			}

			if ($oto ['traffic_num'] and $oto ['traffic_views']) {

				$count = $oto ['traffic_num'];

				while ( $count > 0 ) {

					mysql_query ( "insert into tlinks (userid,paid) values('" . dbput ( $userid ) . "','" . $oto ['traffic_views'] . "')" );

					$count --;

				}

			}

			if ($oto ['ptc_num'] and $oto ['ptc_views']) {

				$count = $oto ['ptc_num'];

				while ( $count > 0 ) {

					mysql_query ( "insert into ptcads (userid,paid) values('" . dbput ( $userid ) . "','" . $oto ['ptc_views'] . "')" );

					$count --;

				}

			}

			if ($oto ['headline_num'] and $oto ['headline_views']) {

				$count = $oto ['headline_num'];
				while ( $count > 0 ) {
					mysql_query ( "insert into headlineads (userid,max) values('" . dbput ( $userid ) . "','" . $oto ['headline_views'] . "')" );
					$count --;
				}

			}

			if ($oto ['hotlink_num'] and $oto ['hotlink_views']) {

				$count = $oto ['hotlink_num'];

				while ( $count > 0 ) {

					mysql_query ( "insert into hotlinks (userid,max) values('" . dbput ( $userid ) . "','" . $oto ['hotlink_views'] . "')" );

					$count --;

				}

			}
			if ($oto ['hheadlinead_num'] and $oto ['hheadlinead_views']) {
				$count = $oto ['hheadlinead_num'];
				while ( $count > 0 ) {
					mysql_query ( "insert into hheadlineads (userid,max,purchase) values('" . dbput ( $userid ) . "','" . $oto ['hheadlinead_views'] . "',NOW())" );
					$count --;
				}
			}
			if ($oto ['hheaderad_num'] and $oto ['hheaderad_views']) {
				$count = $oto ['hheaderad_num'];
				while ( $count > 0 ) {
					mysql_query ( "insert into hheaderads (userid,max,purchase) values('" . dbput ( $userid ) . "','" . $oto ['hheaderad_views'] . "',NOW())" );
					$count --;
				}
			}
			if ($oto ['login_num'] and $oto ['login_views']) {

				$count = $oto ['login_num'];
				while ( $count > 0 ) {
					mysql_query ( "insert into loginads (userid,max) values('" . dbput ( $userid ) . "','" . $oto ['login_views'] . "')" );
					$count --;
				}
			}
			if ($oto ['topnav_num']) {

				$count = $oto ['topnav_num'];
				while ( $count > 0 ) {
					mysql_query ( "INSERT INTO `topnav` (`userid` , `date`) VALUES ('" . dbput ( $userid ) . "', '" . time () . "')" );

					$count --;
				}
			}

			if ($oto ['botnav_num']) {

				$count = $oto ['botnav_num'];
				while ( $count > 0 ) {
					mysql_query ( "INSERT INTO `botnav` (`userid` , `date`) VALUES ('" . dbput ( $userid ) . "', '" . time () . "')" );

					$count --;
				}
			}

			if ($oto ['solo_num']) {

				$count = $oto ['solo_num'];

				while ( $count > 0 ) {

					mysql_query ( "INSERT INTO `solos` (`id` ,`userid` ,`approved` ,`subject` ,`adbody` ,`sent` ,`added`) VALUES (NULL , '" . dbput ( $userid ) . "', '0', '', '', '0', '0')" );

					$count --;

				}

			}

			if ($oto ['cashsolo_num']) {

				$count = $oto ['cashsolo_num'];

				while ( $count > 0 ) {

					mysql_query ( "INSERT INTO `cashsolos` (`id` ,`userid` ,`approved` ,`subject` ,`adbody` ,`sent` ,`added`) VALUES (NULL , '" . dbput ( $userid ) . "', '0', '', '', '0', '0')" );

					$count --;

				}

			}
			if ($offer ['hpcsolo_num']) {

				$count = $offer ['hpcsolo_num'];

				while ( $count > 0 ) {

					mysql_query ( "INSERT INTO `hpcsolos` (`id` ,`userid` ,`approved` ,`subject` ,`adbody` ,`sent` ,`added`) VALUES (NULL , '" . dbput ( $userid ) . "', '0', '', '', '0', '0')" );

					$count --;

				}

			}
			if ($offer ['hpsolo_num']) {

				$count = $offer ['hpsolo_num'];

				while ( $count > 0 ) {

					mysql_query ( "INSERT INTO `hpsolos` (`id` ,`userid` ,`approved` ,`subject` ,`adbody` ,`sent` ,`added`) VALUES (NULL , '" . dbput ( $userid ) . "', '0', '', '', '0', '0')" );

					$count --;

				}

			}
			if ($offer ['snfsolo_num']) {

				$count = $offer ['snfsolo_num'];

				while ( $count > 0 ) {

					mysql_query ( "INSERT INTO `snfsolos` (`id` ,`userid` ,`approved` ,`subject` ,`adbody` ,`sent` ,`added`) VALUES (NULL , '" . dbput ( $userid ) . "', '0', '', '', '0', '0')" );

					$count --;

				}

			}
			if ($offer ['snfcsolo_num']) {

				$count = $offer ['snfcsolo_num'];

				while ( $count > 0 ) {

					mysql_query ( "INSERT INTO `snfcsolos` (`id` ,`userid` ,`approved` ,`subject` ,`adbody` ,`sent` ,`added`) VALUES (NULL , '" . dbput ( $userid ) . "', '0', '', '', '0', '0')" );

					$count --;

				}

			}

			if ($oto ['ssolo_num']) {

				$count = $oto ['ssolo_num'];

				while ( $count > 0 ) {

					mysql_query ( "INSERT INTO `supersolos` (userid, site) VALUES ('" . dbput ( $userid ) . "','treasure')" );

					$count --;

				}

			}

			if ($oto ['upgrade_pro'] == "1") {
				upgrade_jv ( $userid );
			}

			if ($oto ['upgrade_pro'] == "2") {
				upgrade_superjv ( $userid );
			}

		
		    
		    
		    
		} elseif ($item == $sitename . " Points " . $userid) {

			mysql_query ( "INSERT INTO transactions VALUES ('id', '" . dbput ( $userid ) . "','Payza Payment - 1000 points','" . time () . "','$amount\$')" );

			mysql_query ( "UPDATE members SET points=points+1000 WHERE userid = '" . dbput ( $userid ) . "'" );

		} elseif ($item == $sitename . " Solo Ad " . $userid) {
			mysql_query ( "INSERT INTO transactions VALUES ('id', '" . dbput ( $userid ) . "','Payza Payment - Solo Ad','" . time () . "','$amount\$')" );

			mysql_query ( "INSERT INTO `solos` (`id` ,`userid` ,`approved` ,`subject` ,`adbody` ,`sent` ,`added`) VALUES (NULL , '" . $userid . "', '0', '', '', '0', '0')" );

		} elseif ($item == $sitename . " Hot Headline Ad " . $userid) {
			$hheadlineadmaxhits = $_POST ['apc_2'];
			mysql_query ( "INSERT INTO transactions VALUES ('id','" . dbput ( $userid ) . "','Payza Payment - Hot Headline Ad $hheadlineadmaxhits Impressions','" . time () . "','$amount\$')" );
			while ( $quantity > 0 ) {
				mysql_query ( "insert into hheadlineads (userid,max,purchase) values('" . dbput ( $userid ) . "','$hheadlineadmaxhits',NOW())" );
				$quantity --;
			}
		} elseif ($item == $sitename . " Hot Header Ad " . $userid) {
			$hheaderadmaxhits = $_POST ['apc_2'];
			mysql_query ( "INSERT INTO transactions VALUES ('id','" . dbput ( $userid ) . "','Payza Payment - Hot Header Ad $hheaderadmaxhits Clicks','" . time () . "','$amount\$')" );
			while ( $quantity > 0 ) {
				mysql_query ( "insert into hheaderads (userid,max,purchase) values('" . dbput ( $userid ) . "','$hheaderadmaxhits',NOW())" );
				$quantity --;
			}
		} elseif ($item == $sitename . " Cash Solo " . $userid) {
			mysql_query ( "INSERT INTO transactions VALUES ('id', '" . dbput ( $userid ) . "','Payza Payment - Cash Solo','" . time () . "','$amount\$')" );

			mysql_query ( "INSERT INTO `cashsolos` (`id` ,`userid` ,`approved` ,`subject` ,`adbody` ,`sent` ,`added`) VALUES (NULL , '" . $userid . "', '0', '', '', '0', '0')" );

		} elseif ($item == $sitename . " High Priority Solo " . $userid) {
			mysql_query ( "INSERT INTO transactions VALUES ('id', '" . dbput ( $userid ) . "','Payza Payment - High Priority Solo','" . time () . "','$amount\$')" );

			mysql_query ( "INSERT INTO `hpsolos` (`id` ,`userid` ,`approved` ,`subject` ,`adbody` ,`sent` ,`added`) VALUES (NULL , '" . dbput ( $userid ) . "', '0', '', '', '0', '0')" );

		} elseif ($item == $sitename . " High Priority Cash Solo " . $userid) {
			mysql_query ( "INSERT INTO transactions VALUES ('id', '" . dbput ( $userid ) . "','Payza Payment - High Priority Cash Solo','" . time () . "','$amount\$')" );

			mysql_query ( "INSERT INTO `hpcsolos` (`id` ,`userid` ,`approved` ,`subject` ,`adbody` ,`sent` ,`added`) VALUES (NULL , '" . dbput ( $userid ) . "', '0', '', '', '0', '0')" );

		} elseif ($item == $sitename . " Set 'N Forget Solo " . $userid) {
			mysql_query ( "INSERT INTO transactions VALUES ('id', '" . dbput ( $userid ) . "','Payza Payment - Set 'N Forget Solo','" . time () . "','$amount\$')" );

			mysql_query ( "INSERT INTO `snfsolos` (`id` ,`userid` ,`approved` ,`subject` ,`adbody` ,`sent` ,`added`) VALUES (NULL , '" . dbput ( $userid ) . "', '0', '', '', '0', '0')" );

		} elseif ($item == $sitename . " Set 'N Forget Cash Solo " . $userid) {
			mysql_query ( "INSERT INTO transactions VALUES ('id', '" . dbput ( $userid ) . "','Payza Payment - Set 'N Forget Cash Solo','" . time () . "','$amount\$')" );

			mysql_query ( "INSERT INTO `snfcsolos` (`id` ,`userid` ,`approved` ,`subject` ,`adbody` ,`sent` ,`added`) VALUES (NULL , '" . dbput ( $userid ) . "', '0', '', '', '0', '0')" );

		} elseif ($item == $sitename . " Banner Ad " . $userid) {
			mysql_query ( "INSERT INTO transactions VALUES ('id', '" . dbput ( $userid ) . "','Payza Payment - Banner Impressions','" . time () . "','$amount\$')" );

			mysql_query ( "INSERT INTO `banners` ( `id` , `name` , `bannerurl` , `targeturl` , `userid` , `status` , `shown` , `clicks` , `max` , `added` )VALUES (NULL , '', '', '', '" . dbput ( $userid ) . "', '0', '0', '0', '1000', '0')" );

		} elseif ($item == $sitename . " Button Banner " . $userid) {

			mysql_query ( "INSERT INTO `buttons` ( `id` , `name` , `bannerurl` , `targeturl` , `userid` , `status` , `shown` , `clicks` , `max` , `added` )VALUES (NULL , '', '', '', '" . dbput ( $userid ) . "', '0', '0', '0', '1000', '0')" );

			mysql_query ( "INSERT INTO transactions VALUES ('id', '" . dbput ( $userid ) . "','Payza Payment - Button Banner Ad','" . time () . "','$amount\$')" );

		} elseif ($item == $sitename . " Top Navigation Link " . $userid) {
			mysql_query ( "INSERT INTO transactions VALUES ('id','" . dbput ( $userid ) . "','Payza Payment - Top Navigation link','" . time () . "','$amount\$')" );

			mysql_query ( "INSERT INTO `topnav` ( `userid` , `date`) VALUES ('" . dbput ( $userid ) . "', '" . time () . "')" );
		} elseif ($item == $sitename . " Bottom Navigation Link " . $userid) {
			mysql_query ( "INSERT INTO transactions VALUES ('id','" . $userid . "','Payza Payment - Bottom Navigation link','" . time () . "','$amount\$')" );

			mysql_query ( "INSERT INTO `botnav` ( `userid` , `date`) VALUES ('" . dbput ( $userid ) . "', '" . time () . "')" );
		}

		elseif ($item == $sitename . " Solo Footer Ad " . $userid) {

			mysql_query ( "INSERT INTO transactions VALUES ('id', '" . dbput ( $userid ) . "','Payza Payment - " . $quantity . " Solo Footer Ad','" . time () . "','$payment_amount\$')" );

			while ( $quantity > 0 ) {
				mysql_query ( "insert into footerads (userid,paid) values('" . dbput ( $userid ) . "','100')" );
				$quantity --;
			}

		} elseif ($item == $sitename . " Solo Header Ad " . $userid) {

			mysql_query ( "INSERT INTO transactions VALUES ('id', '" . dbput ( $userid ) . "','Payza Payment - " . $quantity . " Solo Header Ad','" . time () . "','$payment_amount\$')" );

			while ( $quantity > 0 ) {
				mysql_query ( "insert into headerads (userid,paid) values('" . dbput ( $userid ) . "','100')" );
				$quantity --;
			}

		} elseif ($item == $sitename . " Daily Bonus " . $userid) {

			$rented = $_POST ['apc_2'];
			mysql_query ( "insert into dailybonus (userid,rented) values('" . dbput ( $userid ) . "','$rented')" );

			mysql_query ( "INSERT INTO transactions VALUES ('id', '" . dbput ( $userid ) . "','Payza Payment - Daily Bonus $rented','" . time () . "','$amount\$')" );

			buycommission ( $info ['referid'], $amount );

		} elseif ($item == $sitename . " Login Ad " . $userid) {
			mysql_query ( "INSERT INTO transactions VALUES ('id','" . dbput ( $userid ) . "','Payza Payment - Login ad','" . time () . "','$amount\$')" );

			mysql_query ( "insert into loginads (userid,max) values('" . dbput ( $userid ) . "','1000')" );

		} elseif ($item == $sitename . " Traffic link 50 " . $userid) {
			mysql_query ( "INSERT INTO transactions VALUES ('id', '" . dbput ( $userid ) . "','Payza Payment - Traffic link 50','" . time () . "','$amount\$')" );

			mysql_query ( "insert into tlinks (userid,paid) values('" . dbput ( $userid ) . "','50')" );

		} elseif ($item == $sitename . " Traffic link 100 " . $userid) {
			mysql_query ( "INSERT INTO transactions VALUES ('id', '" . dbput ( $userid ) . "','Payza Payment - Traffic link 100','" . time () . "','$amount\$')" );

			mysql_query ( "insert into tlinks (userid,paid) values('" . dbput ( $userid ) . "','100')" );

		} elseif ($item == $sitename . " Traffic link 200 " . $userid) {
			mysql_query ( "INSERT INTO transactions VALUES ('id', '" . dbput ( $userid ) . "','Payza Payment -  Traffic link 200','" . time () . "','$amount\$')" );

			mysql_query ( "insert into tlinks (userid,paid) values('" . dbput ( $userid ) . "','200')" );

		} elseif ($item == $sitename . " PTC Link 50 " . $userid) {
			mysql_query ( "INSERT INTO transactions VALUES ('id', '" . dbput ( $userid ) . "','Payza Payment - PTC 50','" . time () . "','$amount\$')" );

			mysql_query ( "insert into ptcads (userid,paid) values('" . dbput ( $userid ) . "','50')" );

		} elseif ($item == $sitename . " PTC Link 100 " . $userid) {
			mysql_query ( "INSERT INTO transactions VALUES ('id', '" . dbput ( $userid ) . "','Payza Payment - PTC 100','" . time () . "','$amount\$')" );

			mysql_query ( "insert into ptcads (userid,paid) values('" . dbput ( $userid ) . "','100')" );

		} elseif ($item == $sitename . " PTC Link 200 " . $userid) {
			mysql_query ( "INSERT INTO transactions VALUES ('id', '" . dbput ( $userid ) . "','Payza Payment -  PTC 200','" . time () . "','$amount\$')" );

			mysql_query ( "insert into ptcads (userid,paid) values('" . dbput ( $userid ) . "','200')" );

		} elseif ($item == $sitename . " Hotlink 5000" . $userid) {
			mysql_query ( "INSERT INTO transactions VALUES ('id','" . dbput ( $userid ) . "','Payza Payment - Hotlink 5000','" . time () . "','$amount\$')" );

			mysql_query ( "insert into hotlinks (userid,max) values('" . dbput ( $userid ) . "','5000')" );

		} elseif ($item == $sitename . " Hotlink 10000 " . $userid) {
			mysql_query ( "INSERT INTO transactions VALUES ('id','" . dbput ( $userid ) . "','Payza Payment - Hotlink 10000','" . time () . "','$amount\$')" );

			mysql_query ( "insert into hotlinks (userid,max) values('" . dbput ( $userid ) . "','10000')" );

		} elseif ($item == $sitename . " Hotlink 20000 " . $userid) {
			mysql_query ( "INSERT INTO transactions VALUES ('id','" . dbput ( $userid ) . "','Payza Payment - Hotlink 20000','" . time () . "','$amount\$')" );

			mysql_query ( "insert into hotlinks (userid,max) values('" . dbput ( $userid ) . "','20000')" );

		} elseif ($item == $sitename . " Headline 5000" . $userid) {
			mysql_query ( "INSERT INTO transactions VALUES ('id','" . dbput ( $userid ) . "','Payza Payment - Headline 5000','" . time () . "','$amount\$')" );

			mysql_query ( "insert into headlineads (userid,max) values('" . dbput ( $userid ) . "','5000')" );

		} elseif ($item == $sitename . " Headline 10000 " . $userid) {
			mysql_query ( "INSERT INTO transactions VALUES ('id','" . dbput ( $userid ) . "','Payza Payment - Headline 10000','" . time () . "','$amount\$')" );

			mysql_query ( "insert into headlineads (userid,max) values('" . dbput ( $userid ) . "','10000')" );

		} elseif ($item == $sitename . " Headline 20000 " . $userid) {
			mysql_query ( "INSERT INTO transactions VALUES ('id','" . dbput ( $userid ) . "','Payza Payment - Headline 20000','" . time () . "','$amount\$')" );

			mysql_query ( "insert into headlineads (userid,max) values('" . dbput ( $userid ) . "','20000')" );

		} elseif ($item == $sitename . " Membership " . $userid) {

			mysql_query ( "INSERT INTO transactions VALUES ('id', '" . dbput ( $userid ) . "','Payza Payment - JV Member Upgrade','" . time () . "','$amount\$')" );

			upgrade_jv ( $userid );

		} elseif ($item == $sitename . " SUPER JV Membership " . $userid) {

			mysql_query ( "INSERT INTO transactions VALUES ('id', '" . dbput ( $userid ) . "','Payza Payment - SUPER JV Upgrade','" . time () . "','$amount\$')" );

			upgrade_superjv ( $userid );

		
		    
		    
		    
		} elseif ($item == $sitename . " Special Offer") {

			if ($mpool == "1") {
				ppbuypool ( $userid, $payment_amount );
			}

			buycommission ( $user ['referid'], $payment_amount );

			$projvcom = 0;
			$jvjvcom = 0;
			$superjvjvcom = 0;
			$prosupercom = 0;
			$jvsupercom = 0;
			$superjv2supercom = 0;

			mysql_query ( "INSERT INTO transactions VALUES ('id', '" . dbput ( $userid ) . "','Payza Payment - Special Offer','" . time () . "','$amount\$')" );

			$sql = mysql_query ( "SELECT * FROM offerpage LIMIT 1" );

			$offer = mysql_fetch_array ( $sql );

			if ($offer ['points'])
				mysql_query ( "UPDATE members SET points=points+" . $offer ['points'] . " WHERE userid='" . dbput ( $userid ) . "'" );

			if ($offer ['banner_num'] and $offer ['banner_views']) {

				$count = $offer ['banner_num'];

				while ( $count > 0 ) {

					mysql_query ( "INSERT INTO `banners` ( `id` , `name` , `bannerurl` , `targeturl` , `userid` , `status` , `shown` , `clicks` , `max` , `added` )VALUES (NULL , '', '', '', '" . dbput ( $userid ) . "', '0', '0', '0', '" . $offer ['banner_views'] . "', '0')" );

					$count --;

				}

			}

			if ($offer ['button_num'] and $offer ['button_views']) {

				$count = $offer ['button_num'];
				while ( $count > 0 ) {
					mysql_query ( "INSERT INTO `buttons` ( `id` , `name` , `bannerurl` , `targeturl` , `userid` , `status` , `shown` , `clicks` , `max` , `added` )VALUES (NULL , '', '', '', '" . dbput ( $userid ) . "', '0', '0', '0', '" . $offer ['button_views'] . "', '0')" );
					$count --;
				}
			}
			if ($offer ['traffic_num'] and $offer ['traffic_views']) {

				$count = $offer ['traffic_num'];

				while ( $count > 0 ) {

					mysql_query ( "insert into tlinks (userid,paid) values('" . dbput ( $userid ) . "','" . $offer ['traffic_views'] . "')" );

					$count --;

				}

			}

			if ($offer ['login_num'] and $offer ['login_views']) {

				$count = $offer ['login_num'];
				while ( $count > 0 ) {
					mysql_query ( "insert into loginads (userid,max) values('" . dbput ( $userid ) . "','" . $offer ['login_views'] . "')" );
					$count --;
				}
			}

			if ($offer ['hotlink_num'] and $offer ['hotlink_views']) {

				$count = $offer ['hotlink_num'];
				while ( $count > 0 ) {
					mysql_query ( "INSERT INTO hotlinks (userid,max,purchase) values('" . dbput ( $userid ) . "','" . $offer ['hotlink_views'] . "','" . time () . "')" );
					$count --;
				}
			}
			if ($offer ['headline_num'] and $offer ['headline_views']) {

				$count = $offer ['headline_num'];
				while ( $count > 0 ) {
					mysql_query ( "INSERT INTO headlineads (userid,max,purchase) values('" . dbput ( $userid ) . "','" . $offer ['headline_views'] . "','" . time () . "')" );
					$count --;
				}
			}
			if ($offer ['solo_num']) {

				$count = $offer ['solo_num'];

				while ( $count > 0 ) {

					mysql_query ( "INSERT INTO `solos` (`id` ,`userid` ,`approved` ,`subject` ,`adbody` ,`sent` ,`added`) VALUES (NULL , '" . dbput ( $userid ) . "', '0', '', '', '0', '0')" );

					$count --;

				}

			}

			if ($offer ['hheadlinead_num'] and $offer ['hheadlinead_views']) {
				$count = $offer ['hheadlinead_num'];
				while ( $count > 0 ) {
					mysql_query ( "insert into hheadlineads (userid,max,purchase) values('" . dbput ( $userid ) . "','" . $offer ['hheadlinead_views'] . "',NOW())" );
					$count --;
				}
			}
			if ($offer ['hheaderad_num'] and $offer ['hheaderad_views']) {
				$count = $offer ['hheaderad_num'];
				while ( $count > 0 ) {
					mysql_query ( "insert into hheaderads (userid,max,purchase) values('" . dbput ( $userid ) . "','" . $offer ['hheaderad_views'] . "',NOW())" );
					$count --;
				}
			}
			if ($offer ['cashsolo_num']) {

				$count = $offer ['cashsolo_num'];

				while ( $count > 0 ) {

					mysql_query ( "INSERT INTO `cashsolos` (`id` ,`userid` ,`approved` ,`subject` ,`adbody` ,`sent` ,`added`) VALUES (NULL , '" . dbput ( $userid ) . "', '0', '', '', '0', '0')" );

					$count --;

				}

			}
			if ($offer ['hpcsolo_num']) {

				$count = $offer ['hpcsolo_num'];

				while ( $count > 0 ) {

					mysql_query ( "INSERT INTO `hpcsolos` (`id` ,`userid` ,`approved` ,`subject` ,`adbody` ,`sent` ,`added`) VALUES (NULL , '" . dbput ( $userid ) . "', '0', '', '', '0', '0')" );

					$count --;

				}

			}
			if ($offer ['hpsolo_num']) {

				$count = $offer ['hpsolo_num'];

				while ( $count > 0 ) {

					mysql_query ( "INSERT INTO `hpsolos` (`id` ,`userid` ,`approved` ,`subject` ,`adbody` ,`sent` ,`added`) VALUES (NULL , '" . dbput ( $userid ) . "', '0', '', '', '0', '0')" );

					$count --;

				}

			}
			if ($offer ['snfsolo_num']) {

				$count = $offer ['snfsolo_num'];

				while ( $count > 0 ) {

					mysql_query ( "INSERT INTO `snfsolos` (`id` ,`userid` ,`approved` ,`subject` ,`adbody` ,`sent` ,`added`) VALUES (NULL , '" . dbput ( $userid ) . "', '0', '', '', '0', '0')" );

					$count --;

				}

			}
			if ($offer ['snfcsolo_num']) {

				$count = $offer ['snfcsolo_num'];

				while ( $count > 0 ) {

					mysql_query ( "INSERT INTO `snfcsolos` (`id` ,`userid` ,`approved` ,`subject` ,`adbody` ,`sent` ,`added`) VALUES (NULL , '" . dbput ( $userid ) . "', '0', '', '', '0', '0')" );

					$count --;

				}

			}

			if ($offer ['upgrade_pro'] == "1") {
				upgrade_jv ( $userid );
			}

			if ($offer ['upgrade_pro'] == "2") {
				upgrade_superjv ( $userid );
			}
			if ($offer ['ptc_num'] and $offer ['ptc_views']) {

				$count = $offer ['ptc_num'];

				while ( $count > 0 ) {

					mysql_query ( "insert into ptcads (userid,paid) values('" . dbput ( $userid ) . "','" . $offer ['ptc_views'] . "')" );

					$count --;

				}

			}

			if ($offer ['topnav_num']) {

				$count = $offer ['topnav_num'];
				while ( $count > 0 ) {
					mysql_query ( "INSERT INTO `topnav` (`userid` , `date`) VALUES ('" . dbput ( $userid ) . "', '" . time () . "')" );

					$count --;
				}
			}

			if ($offer ['botnav_num']) {

				$count = $offer ['botnav_num'];
				while ( $count > 0 ) {
					mysql_query ( "INSERT INTO `botnav` (`userid` , `date`) VALUES ('" . dbput ( $userid ) . "', '" . time () . "')" );

					$count --;
				}
			}

			if ($offer ['ssolo_num']) {

				$count = $offer ['ssolo_num'];

				while ( $count > 0 ) {

					mysql_query ( "INSERT INTO `supersolos` (userid, site) VALUES ('" . dbput ( $userid ) . "','treasure')" );

					$count --;

				}

			}
		}

		elseif ($item == $sitename . " Special Offer Ad Package") {

			mysql_query ( "INSERT INTO transactions VALUES ('id', '" . dbput ( $userid ) . "','Payza Payment - Special Offer Ad Package','" . time () . "','$amount\$')" );

			$sql = mysql_query ( "SELECT * FROM offerpage LIMIT 1" );

			$offer = mysql_fetch_array ( $sql );

			if ($offer ['points'])
				mysql_query ( "UPDATE members SET points=points+" . $offer ['points'] . " WHERE userid='" . dbput ( $userid ) . "'" );

			if ($offer ['banner_num'] and $offer ['banner_views']) {

				$count = $offer ['banner_num'];

				while ( $count > 0 ) {

					mysql_query ( "INSERT INTO `banners` ( `id` , `name` , `bannerurl` , `targeturl` , `userid` , `status` , `shown` , `clicks` , `max` , `added` )VALUES (NULL , '', '', '', '" . dbput ( $userid ) . "', '0', '0', '0', '" . $offer ['banner_views'] . "', '0')" );

					$count --;

				}

			}

			if ($offer ['button_num'] and $offer ['button_views']) {

				$count = $offer ['button_num'];
				while ( $count > 0 ) {
					mysql_query ( "INSERT INTO `buttons` ( `id` , `name` , `bannerurl` , `targeturl` , `userid` , `status` , `shown` , `clicks` , `max` , `added` )VALUES (NULL , '', '', '', '" . dbput ( $userid ) . "', '0', '0', '0', '" . $offer ['button_views'] . "', '0')" );
					$count --;
				}
			}
			if ($offer ['traffic_num'] and $offer ['traffic_views']) {

				$count = $offer ['traffic_num'];

				while ( $count > 0 ) {

					mysql_query ( "insert into tlinks (userid,paid) values('" . dbput ( $userid ) . "','" . $offer ['traffic_views'] . "')" );

					$count --;

				}

			}

			if ($offer ['login_num'] and $offer ['login_views']) {

				$count = $offer ['login_num'];
				while ( $count > 0 ) {
					mysql_query ( "insert into loginads (userid,max) values('" . dbput ( $userid ) . "','" . $offer ['login_views'] . "')" );
					$count --;
				}
			}
			if ($offer ['headline_num'] and $offer ['headline_views']) {

				$count = $offer ['headline_num'];
				while ( $count > 0 ) {
					mysql_query ( "insert into headlineads (userid,max) values('" . dbput ( $userid ) . "','" . $offer ['headline_views'] . "')" );
					$count --;
				}

			}

			if ($offer ['hotlink_num'] and $offer ['hotlink_views']) {

				$count = $offer ['hotlink_num'];
				while ( $count > 0 ) {
					mysql_query ( "INSERT INTO hotlinks (userid,max,purchase) values('" . dbput ( $userid ) . "','" . $offer ['hotlink_views'] . "','" . time () . "')" );
					$count --;
				}
			}
			if ($offer ['solo_num']) {

				$count = $offer ['solo_num'];

				while ( $count > 0 ) {

					mysql_query ( "INSERT INTO `solos` (`id` ,`userid` ,`approved` ,`subject` ,`adbody` ,`sent` ,`added`) VALUES (NULL , '" . dbput ( $userid ) . "', '0', '', '', '0', '0')" );

					$count --;

				}

			}

			if ($offer ['hheadlinead_num'] and $offer ['hheadlinead_views']) {
				$count = $offer ['hheadlinead_num'];
				while ( $count > 0 ) {
					mysql_query ( "insert into hheadlineads (userid,max,purchase) values('" . dbput ( $userid ) . "','" . $offer ['hheadlinead_views'] . "',NOW())" );
					$count --;
				}
			}
			if ($offer ['hheaderad_num'] and $offer ['hheaderad_views']) {
				$count = $offer ['hheaderad_num'];
				while ( $count > 0 ) {
					mysql_query ( "insert into hheaderads (userid,max,purchase) values('" . dbput ( $userid ) . "','" . $offer ['hheaderad_views'] . "',NOW())" );
					$count --;
				}
			}
			if ($offer ['cashsolo_num']) {

				$count = $offer ['cashsolo_num'];

				while ( $count > 0 ) {

					mysql_query ( "INSERT INTO `cashsolos` (`id` ,`userid` ,`approved` ,`subject` ,`adbody` ,`sent` ,`added`) VALUES (NULL , '" . dbput ( $userid ) . "', '0', '', '', '0', '0')" );

					$count --;

				}

			}
			if ($offer ['hpcsolo_num']) {

				$count = $offer ['hpcsolo_num'];

				while ( $count > 0 ) {

					mysql_query ( "INSERT INTO `hpcsolos` (`id` ,`userid` ,`approved` ,`subject` ,`adbody` ,`sent` ,`added`) VALUES (NULL , '" . dbput ( $userid ) . "', '0', '', '', '0', '0')" );

					$count --;

				}

			}
			if ($offer ['hpsolo_num']) {

				$count = $offer ['hpsolo_num'];

				while ( $count > 0 ) {

					mysql_query ( "INSERT INTO `hpsolos` (`id` ,`userid` ,`approved` ,`subject` ,`adbody` ,`sent` ,`added`) VALUES (NULL , '" . dbput ( $userid ) . "', '0', '', '', '0', '0')" );

					$count --;

				}

			}
			if ($offer ['snfsolo_num']) {

				$count = $offer ['snfsolo_num'];

				while ( $count > 0 ) {

					mysql_query ( "INSERT INTO `snfsolos` (`id` ,`userid` ,`approved` ,`subject` ,`adbody` ,`sent` ,`added`) VALUES (NULL , '" . dbput ( $userid ) . "', '0', '', '', '0', '0')" );

					$count --;

				}

			}
			if ($offer ['snfcsolo_num']) {

				$count = $offer ['snfcsolo_num'];

				while ( $count > 0 ) {

					mysql_query ( "INSERT INTO `snfcsolos` (`id` ,`userid` ,`approved` ,`subject` ,`adbody` ,`sent` ,`added`) VALUES (NULL , '" . dbput ( $userid ) . "', '0', '', '', '0', '0')" );

					$count --;

				}

			}

			if ($offer ['upgrade_pro'] == "1") {
				upgrade_jv ( $userid );
			}

			if ($offer ['upgrade_pro'] == "2") {
				upgrade_superjv ( $userid );
			}
			if ($offer ['ptc_num'] and $offer ['ptc_views']) {

				$count = $offer ['ptc_num'];

				while ( $count > 0 ) {

					mysql_query ( "insert into ptcads (userid,paid) values('" . dbput ( $userid ) . "','" . $offer ['ptc_views'] . "')" );

					$count --;

				}

			}

			if ($offer ['topnav_num']) {

				$count = $offer ['topnav_num'];
				while ( $count > 0 ) {
					mysql_query ( "INSERT INTO `topnav` (`userid` , `date`) VALUES ('" . dbput ( $userid ) . "', '" . time () . "')" );

					$count --;
				}
			}

			if ($offer ['botnav_num']) {

				$count = $offer ['botnav_num'];
				while ( $count > 0 ) {
					mysql_query ( "INSERT INTO `botnav` (`userid` , `date`) VALUES ('" . dbput ( $userid ) . "', '" . time () . "')" );

					$count --;
				
				    
				    
				    
				}
			}

			if ($offer ['ssolo_num']) {

				$count = $offer ['ssolo_num'];

				while ( $count > 0 ) {

					mysql_query ( "INSERT INTO `supersolos` (userid, site) VALUES ('" . dbput ( $userid ) . "','treasure')" );

					$count --;

				}

			}
			if ($item == $sitename . " Full Page Login Ad " . $userid) {

				$rented = $_POST ['apc_2'];

				mysql_query ( "insert into fullloginads (userid,rented) values('$userid','$rented')" );

				mysql_query ( "INSERT INTO transactions VALUES ('id', '" . $userid . "','Payza Payment - Full Page Login Ad','" . time () . "','$amount\$')" );

			}
		}

	}

} else {

/* Security code doesn't match. POST IS NOT FROM ALERTPAY.

	* Ignore post, or do whatever fraud catching that you would like.

	*/

}

?>