Promo code with Disposable keys

Forum
Last Post
Threads / Messages

Chibi_Chicken

Niwatori Kami
Member
Joined
Jun 11, 2011
Messages
63
Points
0
Mysidian Dollar
3,168
Lets say you have an adoptable that you want to limit to the users, with this mod you can assign a key with that promo code and when they enter it and adopt
the pet. It will delete the key so they can cant get more than the one pet.
Since the new version of Mysidia may be coming out in a few months with a new modding system, I am just going to release this as a how to find and replace.

The files you need to edit are
functions.php - You will be modifying the canadopt.
adopt.php - You will be adding another input value and altering a function call and some form values that are sent out
doadopt.php - You will be adding another input value and altering a function call and adding a sql query to remove the key
promo.php - You will be adding another input value and altering how it checks the promo code if it is valid


To start off with run this Sql command:
CREATE TABLE adopts_promo_keys (id INT NOT NULL AUTO_INCREMENT PRIMARY KEY, promo_code varchar(50), promo_key varchar(50));

This is where you will add in any keys that you want users to have when adopting pets.

next open up inc/functions.php
find
PHP:
	if($row['whenisavail'] == "promo" and $promocode != $row['promocode']) {
		return "no";
	}
And REPLACE with
PHP:
//------------
//promo mod
//-----------	
	if($row['whenisavail'] == "promo"){
		//we are using promo codes so now we need to get the key and check if the promo and key match else return false
		$query = "SELECT * FROM ".$GLOBALS['prefix']."promo_keys WHERE promo_code='$promocode' 	AND promo_key='$pkey'";
		$result = @mysql_query($query);
		$num = @mysql_numrows($result);
		
		if($num<1){
			return "no";
		}
	
	}
//------------
//end promo mod
//-----------

Save and close.
Next open up promo.php

Find
PHP:
$promocode = $_GET["promocode"];

After Add
PHP:
//------------
//promo mod
//-----------
if (!empty($_POST['promokey']) || !empty($_GET['promokey']))
{
	$pkey = (!empty($_POST['promokey'])) ? $_POST['promokey'] : $_GET['promokey'];
}
else
{
	$pkey = '';
}
//------------
//end promo mod
//-----------

Next Find
PHP:
$article_content = $lang_enter_code."<br><form name='form1' method='get' action='promo.php'>
  <p>Your Promo Code: 
    <input name='promocode' type='text' id='promocode'>
</p>
  <p>
    <input type='submit' name='Submit' value='Submit'>
</p>
</form>";

And REPLACE with
PHP:
//------------
//promo mod
//-----------
$article_content = $lang_enter_code."<br><form name='form1' method='get' action='promo.php'>
  <p>Your Promo Code: 
    <input name='promocode' type='text' id='promocode'>
</p>
  
  <p>Your Promo Key: 
    <input name='promokey' type='text' id='promokey'>
</p>

  <p>
    <input type='submit' name='Submit' value='Submit'>
</p>
</form>";
//--------------
//end promo mod
//--------------

Next Find
PHP:
if($num > 0){

// There is a match

$article_title = $showingtitle;
$article_content = $lang_promo_avail."<br>";

//Loop out code
$i=0;
while ($i < $num) {

$aid=@mysql_result($result,$i,"id"); //The adoptable's ID
$type=@mysql_result($result,$i,"type");
$description=@mysql_result($result,$i,"description");
$eggimage=@mysql_result($result,$i,"eggimage");

$article_content = $article_content."<p><b><u><a href='adopt.php?id=".$aid."&promocode=".$promocode."'>".$type.":</a></u></b></p>
<p><a href='adopt.php?id=".$aid."&promocode=".$promocode."'><img src='".$eggimage."' border='0'></a></p>";

	if($isloggedin == "yes"){
	$article_content = $article_content."<p><b><a href='adopt.php?id=".$aid."&promocode=".$promocode."'><img src='templates/icons/add.gif' border=0> Adopt ".$type."</a></b></p>";
	}
	else{
	$article_content = $article_content."<p><img src='templates/icons/no.gif' border=0> <b>".$guesterror."</b></p>";
	}

$i++;
}

}

And REPLACE with
PHP:
//--------------
//promo mod
//--------------
if($num > 0){

// There is a match

//now check if their is a key with the promo code

$query = "SELECT * FROM ".$prefix."promo_keys WHERE promo_code='$promocode' AND promo_key='$pkey'";
$result2 = runquery($query);
$num2 = mysql_numrows($result2);

if($num2 > 0){
//we have both a promo code and a key that match so display the pets to the user to adopt

$article_title = $showingtitle;
$article_content = $lang_promo_avail."<br>";

//Loop out code
$i=0;
while ($i < $num) {

$aid=@mysql_result($result,$i,"id"); //The adoptable's ID
$type=@mysql_result($result,$i,"type");
$description=@mysql_result($result,$i,"description");
$eggimage=@mysql_result($result,$i,"eggimage");

$article_content = $article_content."<p><b><u><a href='adopt.php?id=".$aid."&promocode=".$promocode."&promokey=".$pkey."'>".$type.":</a></u></b></p>
<p><a href='adopt.php?id=".$aid."&promocode=".$promocode."&promokey=".$pkey."'><img src='".$eggimage."' border='0'></a></p>";

	if($isloggedin == "yes"){
	$article_content = $article_content."<p><b><a href='adopt.php?id=".$aid."&promocode=".$promocode."&promokey=".$pkey."'><img src='templates/icons/add.gif' border=0> Adopt ".$type."</a></b></p>";
	}
	else{
	$article_content = $article_content."<p><img src='templates/icons/no.gif' border=0> <b>".$guesterror."</b></p>";
	}

$i++;
}
}
else{

// their was no key with the promo code so display the error to the user

$article_title = $lang_promo_fail_title;
$article_content = $lang_promo_fail;

}
//--------------
//end promo mod
//--------------

Save and close that file now open adopt.php

Find
PHP:
$promocode = $_GET["promocode"];
After Add
PHP:
//------------
//promo mod
//-----------
if (!empty($_POST['promokey']) || !empty($_GET['promokey']))
{
	$pkey = (!empty($_POST['promokey'])) ? $_POST['promokey'] : $_GET['promokey'];
}
else
{
	$pkey = '';
}
//------------
//end promo mod
//-----------

Next Find
PHP:
		$canadopt = canadopt($aid, "showing", $promocode, $row); // Feed an adoptable ID and showing, to show the adopt to guests...

Replace with
PHP:
//------------
//promo mod
//-----------
		$canadopt = canadopt($aid, "showing", $promocode, $row, $pkey); // Feed an adoptable ID and showing, to show the adopt to guests...
//------------
//end promo mod
//-----------

Next Find

PHP:
	$article_content .= "</table>
	<h3>Adopt</h3>
			  <p>Adoptable Name: <input name='name' type='text' id='name' />
				<input name='promocode' type='hidden' id='promocode' value='".$promocode."'>
			  </p>
			  <p>
				<input type='submit' name='Submit' value='Adopt Me'>
			</p>
	</form>";

Repace with

PHP:
//------------
//promo mod
//-----------	
	$article_content .= "</table>
	<h3>Adopt</h3>
			  <p>Adoptable Name: <input name='name' type='text' id='name' />
				<input name='promocode' type='hidden' id='promocode' value='".$promocode."'>
				<input name='promokey' type='hidden' id='promokey' value='".$pkey."'>
				</p>
			  <p>
				<input type='submit' name='Submit' value='Adopt Me'>
			</p>
	</form>";
//------------
//end promo mod
//-----------

Next Find
PHP:
		$canadopt = canadopt($aid, "adopting", $promocode, $row);

And Replace with
PHP:
//------------
//promo mod
//-----------
		$canadopt = canadopt($aid, "adopting", $promocode, $row, $pkey); 
//------------
//end promo mod
//-----------

Next Find
PHP:
			$article_content = $article_content."<br><img src='".$eggimage."' border='0'><br>
			<form name='form1' method='get' action='doadopt.php'>
			  <p>Adoptable Name: 
				<input name='name' type='text' id='name'>
				<input name='id' type='hidden' id='id' value='".$id."'>
				<input name='promocode' type='hidden' id='promocode' value='".$promocode."'>
			  </p>
			  <p>
				<input type='submit' name='Submit' value='Adopt Me'>
			</p>
			</form>";

REPLACE with
PHP:
//------------
//promo mod
//-----------
			$article_content = $article_content."<br><img src='".$eggimage."' border='0'><br>
			<form name='form1' method='get' action='doadopt.php'>
			  <p>Adoptable Name: 
				<input name='name' type='text' id='name'>
				<input name='id' type='hidden' id='id' value='".$id."'>
				<input name='promocode' type='hidden' id='promocode' value='".$promocode."'>
				<input name='promokey' type='hidden' id='promokey' value='".$pkey."'>
			  </p>
			  <p>
				<input type='submit' name='Submit' value='Adopt Me'>
			</p>
			</form>";
//------------
//end promo mod
//-----------

Save and close, Open doadopt.php

Find
PHP:
$name = $_GET["name"];
After Add
PHP:
//------------
//promo mod
//-----------
if (!empty($_POST['promokey']) || !empty($_GET['promokey']))
{
	$pkey = (!empty($_POST['promokey'])) ? $_POST['promokey'] : $_GET['promokey'];
}
else
{
	$pkey = '';
}
//------------
//end promo mod
//-----------
Next Find
PHP:
				$canadopt = canadopt($aid, "adopting", $promocode, $row);
Replace with
PHP:
//-----------
//promo mod
//-----------
				$canadopt = canadopt($aid, "adopting", $promocode, $row,$pkey);
//-----------
//end promo mod
//-----------
Next find
PHP:
runquery("INSERT INTO ".$prefix."owned_adoptables VALUES ('', '$type', '$name','$loggedinname','0','0', '$code', '','$alts','fortrade','no', '$genders[$rand]','0')");
After Add
PHP:
//------------
//promo mod
//-----------
						//now we need to remove the key from the db so that they cant adopt another pet
						$query = "DELETE FROM ".$prefix."promo_keys WHERE promo_code='$promocode' AND promo_key='$pkey'";
						echo $query;
						runquery($query);
//------------
//end promo mod
//-----------

Save and you are done modding.

With this mod even if the user has the promo code they cant adopt or view the pet. If more than one pet has the same promo code to it then it will display all of them for the user to adopt. To add keys you need to use PhpMyAdmin.
Any questions or comments please post them here.
 
Last edited:
mm.. I like this.... I just don't have a host and i don't know how to install the mys script onto the host
 

Similar threads

Users who are viewing this thread

  • Forum Contains New Posts
  • Forum Contains No New Posts

Forum statistics

Threads
4,280
Messages
33,130
Members
1,603
Latest member
Monako
BETA

Latest Threads

Latest Posts

Top