View Single Post
  #1  
Old 07-19-2011, 10:57 AM
Chibi_Chicken Chibi_Chicken is offline
Niwatori Kami
 
Join Date: Jun 2011
Posts: 63
Gender: Unknown/Other
Credits: 5,171
Chibi_Chicken is on a distinguished road
Default Promo code with Disposable keys

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 Code:
    if($row['whenisavail'] == "promo" and $promocode != $row['promocode']) {
        return 
"no";
    } 
And REPLACE with
PHP Code:
//------------
//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 Code:
$promocode $_GET["promocode"]; 
After Add
PHP Code:
//------------
//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 Code:
$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 Code:
//------------
//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 Code:
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 Code:
//--------------
//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 Code:
$promocode $_GET["promocode"]; 
After Add
PHP Code:
//------------
//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 Code:
        $canadopt canadopt($aid"showing"$promocode$row); // Feed an adoptable ID and showing, to show the adopt to guests... 
Replace with
PHP Code:
//------------
//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 Code:
    $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 Code:
//------------
//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 Code:
        $canadopt canadopt($aid"adopting"$promocode$row); 
And Replace with
PHP Code:
//------------
//promo mod
//-----------
        
$canadopt canadopt($aid"adopting"$promocode$row$pkey); 
//------------
//end promo mod
//----------- 
Next Find
PHP Code:
            $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 Code:
//------------
//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 Code:
$name $_GET["name"]; 
After Add
PHP Code:
//------------
//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 Code:
                $canadopt canadopt($aid"adopting"$promocode$row); 
Replace with
PHP Code:
//-----------
//promo mod
//-----------
                
$canadopt canadopt($aid"adopting"$promocode$row,$pkey);
//-----------
//end promo mod
//----------- 
Next find
PHP Code:
runquery("INSERT INTO ".$prefix."owned_adoptables VALUES ('', '$type', '$name','$loggedinname','0','0', '$code', '','$alts','fortrade','no', '$genders[$rand]','0')"); 
After Add
PHP Code:
//------------
//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 by Chibi_Chicken; 08-07-2011 at 05:47 PM. Reason: changes the code tags to php
Reply With Quote