Hello everyone, I'm a very very basic php coder, because I'm in the stages of learning the language at the moment. This is my first mod I've made myself, but you may think its basic because you are all great coders anyhow :lol:
Just a word of warning: please do check through the codes before you try! I'm not sure if there are any errors in there so please be careful. If you spot any please post a correct version of it. I don't want to your games to be messed up.
UPDATE!!! If you have installed this mod, accept my apologies, but I have missed a few things. Re-install paperads.php and create the table. Again I'm sorry, but now this should work ok. Post if you spot an error, thanks. [21/02/08][20:29]
Well firstly create a file called: paperads.php
<?php
include "globals.php";
print <<<EOF
<h3>Paper Advertisements:</h2>
<center>
If you wish to advertise your website in <Your game name> newspaper you will have to choose an option from below
[list=1]
[*]1 month ad: £10
<form action="https://www.paypal.com/cgi-bin/webscr" method="post">
<input type=hidden name=cmd value=_xclick>
<input type="hidden" name="business" value="{$set['paypal']}">
<input type="hidden" name="item_name" value="{$domain}|PaperAd|1|{$userid}">
<input type="hidden" name="amount" value="10.00">
<input type="hidden" name="no_shipping" value="1">
<input type="hidden" name="return" value="http://{$domain}/paperaddone.php?action=done&type=standard">
<input type="hidden" name="cancel_return" value="http://{$domain}/paperaddone.php?action=cancel">
<input type="hidden" name="notify_url" value="http://{$domain}/ipn_paperads.php">
<input type="hidden" name="cn" value="Your Player ID">
<input type="hidden" name="currency_code" value="GBP">
<input type="hidden" name="tax" value="0">
<input type="image" src="https://www.paypal.com/en_US/i/btn/x-click-but21.gif" border="0" name="submit" alt="Make payments with PayPal - it's fast, free and secure!">
</form>
[*]3 month ad: £25
<form action="https://www.paypal.com/cgi-bin/webscr" method="post">
<input type=hidden name=cmd value=_xclick>
<input type="hidden" name="business" value="{$set['paypal']}">
<input type="hidden" name="item_name" value="{$domain}|PaperAd|2|{$userid}">
<input type="hidden" name="amount" value="25.00">
<input type="hidden" name="no_shipping" value="1">
<input type="hidden" name="return" value="http://{$domain}/paperaddone.php?action=done&type=standard">
<input type="hidden" name="cancel_return" value="http://{$domain}/paperaddone.php?action=cancel">
<input type="hidden" name="notify_url" value="http://{$domain}/ipn_paperads.php">
<input type="hidden" name="cn" value="Your Player ID">
<input type="hidden" name="currency_code" value="GBP">
<input type="hidden" name="tax" value="0">
<input type="image" src="https://www.paypal.com/en_US/i/btn/x-click-but21.gif" border="0" name="submit" alt="Make payments with PayPal - it's fast, free and secure!">
</form>
[*]5 month ad: £40
<form action="https://www.paypal.com/cgi-bin/webscr" method="post">
<input type=hidden name=cmd value=_xclick>
<input type="hidden" name="business" value="{$set['paypal']}">
<input type="hidden" name="item_name" value="{$domain}|PaperAd|3|{$userid}">
<input type="hidden" name="amount" value="40.00">
<input type="hidden" name="no_shipping" value="1">
<input type="hidden" name="return" value="http://{$domain}/paperaddone.php?action=done&type=standard">
<input type="hidden" name="cancel_return" value="http://{$domain}/paperaddone.php?action=cancel">
<input type="hidden" name="notify_url" value="http://{$domain}/ipn_paperads.php">
<input type="hidden" name="cn" value="Your Player ID">
<input type="hidden" name="currency_code" value="GBP">
<input type="hidden" name="tax" value="0">
<input type="image" src="https://www.paypal.com/en_US/i/btn/x-click-but21.gif" border="0" name="submit" alt="Make payments with PayPal - it's fast, free and secure!">
</form>
[*]6 month ad: £75
<form action="https://www.paypal.com/cgi-bin/webscr" method="post">
<input type=hidden name=cmd value=_xclick>
<input type="hidden" name="business" value="{$set['paypal']}">
<input type="hidden" name="item_name" value="{$domain}|PaperAd|4|{$userid}">
<input type="hidden" name="amount" value="75.00">
<input type="hidden" name="no_shipping" value="1">
<input type="hidden" name="return" value="http://{$domain}/paperaddone.php?action=done&type=standard">
<input type="hidden" name="cancel_return" value="http://{$domain}/paperaddone.php?action=cancel">
<input type="hidden" name="notify_url" value="http://{$domain}/ipn_paperads.php">
<input type="hidden" name="cn" value="Your Player ID">
<input type="hidden" name="currency_code" value="GBP">
<input type="hidden" name="tax" value="0">
<input type="image" src="https://www.paypal.com/en_US/i/btn/x-click-but21.gif" border="0" name="submit" alt="Make payments with PayPal - it's fast, free and secure!">
</form>
[*]8 month ad: £145
<form action="https://www.paypal.com/cgi-bin/webscr" method="post">
<input type=hidden name=cmd value=_xclick>
<input type="hidden" name="business" value="{$set['paypal']}">
<input type="hidden" name="item_name" value="{$domain}|PaperAd|5|{$userid}">
<input type="hidden" name="amount" value="145.00">
<input type="hidden" name="no_shipping" value="1">
<input type="hidden" name="return" value="http://{$domain}/paperaddone.php?action=done&type=standard">
<input type="hidden" name="cancel_return" value="http://{$domain}/paperaddone.php?action=cancel">
<input type="hidden" name="notify_url" value="http://{$domain}/ipn_paperads.php">
<input type="hidden" name="cn" value="Your Player ID">
<input type="hidden" name="currency_code" value="GBP">
<input type="hidden" name="tax" value="0">
<input type="image" src="https://www.paypal.com/en_US/i/btn/x-click-but21.gif" border="0" name="submit" alt="Make payments with PayPal - it's fast, free and secure!">
</form>
[*]10 month ad: £280
<form action="https://www.paypal.com/cgi-bin/webscr" method="post">
<input type=hidden name=cmd value=_xclick>
<input type="hidden" name="business" value="{$set['paypal']}">
<input type="hidden" name="item_name" value="{$domain}|PaperAd|6|{$userid}">
<input type="hidden" name="amount" value="280.00">
<input type="hidden" name="no_shipping" value="1">
<input type="hidden" name="return" value="http://{$domain}/paperaddone.php?action=done&type=standard">
<input type="hidden" name="cancel_return" value="http://{$domain}/paperaddone.php?action=cancel">
<input type="hidden" name="notify_url" value="http://{$domain}/ipn_paperads.php">
<input type="hidden" name="cn" value="Your Player ID">
<input type="hidden" name="currency_code" value="GBP">
<input type="hidden" name="tax" value="0">
<input type="image" src="https://www.paypal.com/en_US/i/btn/x-click-but21.gif" border="0" name="submit" alt="Make payments with PayPal - it's fast, free and secure!">
</form>
[*]1 year ad: £550
<form action="https://www.paypal.com/cgi-bin/webscr" method="post">
<input type=hidden name=cmd value=_xclick>
<input type="hidden" name="business" value="{$set['paypal']}">
<input type="hidden" name="item_name" value="{$domain}|PaperAd|7|{$userid}">
<input type="hidden" name="amount" value="550.00">
<input type="hidden" name="no_shipping" value="1">
<input type="hidden" name="return" value="http://{$domain}/paperaddone.php?action=done&type=standard">
<input type="hidden" name="cancel_return" value="http://{$domain}/paperaddone.php?action=cancel">
<input type="hidden" name="notify_url" value="http://{$domain}/ipn_paperads.php">
<input type="hidden" name="cn" value="Your Player ID">
<input type="hidden" name="currency_code" value="GBP">
<input type="hidden" name="tax" value="0">
<input type="image" src="https://www.paypal.com/en_US/i/btn/x-click-but21.gif" border="0" name="submit" alt="Make payments with PayPal - it's fast, free and secure!">
</form>
Once paid there are no refunds, so please be sure on which you want to choose. </p></center>
EOF;
$h->endpage();
?>
Then create another file: paperaddone.php
<?php
include "globals.php";
if($_GET['action'] == "cancel")
{
print "You have cancelled your advertisement.";
}
else if($_GET['action'] == "done")
{
if(!$_GET['tx'])
{
die ("Get a life.");
}
print "Thank you for your payment to {$set['game_name']}. Your transaction has been completed, and a receipt for your purchase has been emailed to you. You may log into your account at [url='http://www.paypal.com']www.paypal.com[/url] to view details of this transaction. Your ad should be in the newspaper within a few minutes, if not, contact an admin for assistance.";
}
$h->endpage();
?>
And finally: ipn_paperads.php
<?
include "config.php";
global $_CONFIG;
define("MONO_ON", 1);
require "class/class_db_{$_CONFIG['driver']}.php";
$db=new database;
$db->configure($_CONFIG['hostname'],
$_CONFIG['username'],
$_CONFIG['password'],
$_CONFIG['database'],
$_CONFIG['persistent']);
$db->connect();
$c=$db->connection_id;
require 'global_func.php';
$set=array();
$settq=$db->query("SELECT * FROM settings");
while($r=$db->fetch_row($settq))
{
$set[$r['conf_name']]=$r['conf_value'];
}
// read the post from PayPal system and add 'cmd'
$req = 'cmd=_notify-validate';
foreach ($_POST as $key => $value)
{
$value = urlencode(stripslashes($value));
$req .= "&$key=$value";
}
// post back to PayPal system to validate
$header .= "POST /cgi-bin/webscr HTTP/1.0\r\n";
$header .= "Content-Type: application/x-www-form-urlencoded\r\n";
$header .= "Content-Length: " . strlen($req) . "\r\n\r\n";
$fp = fsockopen ('www.paypal.com', 80, $errno, $errstr, 30);
// assign posted variables to local variables
$item_name = $_POST['item_name'];
$item_number = $_POST['item_number'];
$payment_status = $_POST['payment_status'];
$payment_amount = $_POST['mc_gross'];
$payment_currency = $_POST['mc_currency'];
$txn_id = $_POST['txn_id'];
$receiver_email = $_POST['receiver_email'];
$payer_email = $_POST['payer_email'];
if (!$fp)
{
// HTTP ERROR
}
else
{
fputs ($fp, $header . $req);
while (!feof($fp))
{
$res = fgets ($fp, 1024);
if (strcmp ($res, "VERIFIED") == 0)
{
// check the payment_status is Completed
if($payment_status != "Completed")
{
fclose ($fp);
die("");
}
if($db->num_rows($db->query("SELECT * FROM pas_accepted WHERE dpTXN='{$txn_id}'")) > 0)
{
fclose ($fp);
die("");
}
// check that txn_id has not been previously processed
// check that receiver_email is your Primary PayPal email
if($receiver_email != $set['paypal']) { fclose ($fp);die(""); }
// check that payment_amount/payment_currency are correct
if($payment_currency != "GBP")
{
fclose ($fp);
die("");
}
// parse for paperads
$paperads=explode('|',$item_name);
if(str_replace("www.","",$packr[0]) != str_replace("www.","",$_SERVER['HTTP_HOST']))
{
fclose($fp);
die("");
}
if($paperads[1] != "Paperads")
{
fclose($fp);
die("");
}
$pack=$paperads[2];
if(
$paperads != 1 and
$paperads != 2 and
$paperads != 3 and
$paperads != 4 and
$paperads != 5 and
$paperads != 6 and
$paperads != 7)
{
fclose($fp);
die("");
}
if(
(
$paperads == 1) && $payment_amount != "10.00")
{
fclose ($fp);
die("");
}
if($paperads == 2 && $payment_amount != "25.00")
{
fclose ($fp);
die("");
}
if($pack == 3 && $payment_amount != "40.00")
{
fclose ($fp);
die("");
}
if($pack == 4 && $payment_amount != "75.00")
{
fclose ($fp);
die("");
}
if($pack == 5 && $payment_amount != "145.00")
{
fclose ($fp);
die("");
}
if($pack == 6 && $payment_amount != "280.00")
{
fclose ($fp);
die("");
}
if($pack == 7 && $payment_amount != "550.00")
{
fclose ($fp);
die("");
}
// grab IDs
$buyer=$paperads[3];
$for=$buyer;
// process payment
event_add($for, "Your \${$payment_amount} PaperAd {$paperads} has been successfully gone through.", $c);
event_add if($ir['user_level']==2)
{
print "($ir['userid']== > ) has paid for {$paperads}. Mail this user for more information."
$db->query("INSERT INTO pas_accepted VALUES('', {$buyer}, {$for}, '$t', unix_timestamp(), '$txn_id')");
}
else if (strcmp ($res, "INVALID") == 0) {
}
}
fclose ($fp);
}
?>
Add this table in your SQL:
CREATE TABLE `pas_accepted` (
`paID` int(11) NOT NULL auto_increment,
`paBUYER` int(11) NOT NULL default '0',
`paFOR` int(11) NOT NULL default '0',
`paTYPE` varchar(255) NOT NULL default '',
`paTIME` int(11) NOT NULL default '0',
`paTXN` varchar(255) NOT NULL default '',
PRIMARY KEY (`paID`)
) ENGINE=MyISAM ;
As I've said before, I am new to these things, so there may be errors in the code. Please check carefully. :-)
When the payment has gone through you can post the persons website URL where ever you like in the newspaper.
I would say where the image "Paper Ads" is. Thats where I got the idea from :-)
Also, please dont flame me, but I would appreciate corrections and advice.
Thanks :)
PS - modify it all you like to fit your needs
Edit: You'll have to make a link to paperads.php
Sorry I forgot to mention that.. :lol: