Pokemon Trading Post

[insert_php]
//require_once(‘/wp-config.php’);

global $wpdb;
echo ‘

‘;
echo ‘‘;
echo ‘‘;
echo ‘

‘;

$shouldDrawBasicForm = true;
$didSuccessfulSearch = false;

function DrawTradeFormStart()
{
echo “

“;
echo ““;
}

function DrawTradeFormEnd()
{
echo ““;
echo “

“;
}

function DrawCurrentTradeOffers()
{
global $wpdb;
$user = wp_get_current_user();
$theUserID = $user->data->ID;

// show trades people are offering me
echo “Trade offers from other people
“;
$theSearchArray = $wpdb-> get_results (‘select * from montrades where destid=’.$theUserID);
if(!is_null($theSearchArray) || (sizeof($theSearchArray) == 0))
{
foreach($theSearchArray as $theSearchItem)
{
$theUserInfo = $wpdb->get_row(‘select user_nicename, ID from wp_xvywdt_users where ID=’.$theSearchItem->originid);
echo “

“;
$theItems = explode(“,”, $theSearchItem->destlist);
foreach ($theItems as $item)
{
$theType = substr($item, 0, 4);
$theID = substr($item, 4);

echo “

“;
//echo $theSearchItem-> destlist.” for “.$theSearchItem->originlist.”
“;
}
echo “

“;
$theItems = explode(“,”, $theSearchItem->originlist);
foreach ($theItems as $item)
{
$theType = substr($item, 0, 4);
$theID = substr($item, 4);

echo “

“;
//echo $theSearchItem-> destlist.” for “.$theSearchItem->originlist.”
“;
}
echo “

From “.$theUserInfo->user_nicename.”
“;
DrawCard($theType, $theID, 128);
echo “
for… “;
DrawCard($theType, $theID, 128);
echo “

“;
}
}
else
{
echo “You currently have no trade offers from other people.
“;
}

echo “
My trade offers to other people
“;
$theSearchArray = $wpdb-> get_results (‘select * from montrades where originid=’.$theUserID);
if(!is_null($theSearchArray) || (sizeof($theSearchArray) == 0))
{
foreach($theSearchArray as $theSearchItem)
{
$theUserInfo = $wpdb->get_row(‘select user_nicename, ID from wp_xvywdt_users where ID=’.$theSearchItem->destid);
echo “

“;
$theItems = explode(“,”, $theSearchItem->originlist);
foreach ($theItems as $item)
{
$theType = substr($item, 0, 4);
$theID = substr($item, 4);

echo “

“;
//echo $theSearchItem->originlist.” for “.$theSearchItem->destlist.”
“;
}
echo “

“;
$theItems = explode(“,”, $theSearchItem->destlist);
foreach ($theItems as $item)
{
$theType = substr($item, 0, 4);
$theID = substr($item, 4);

echo “

“;
//echo $theSearchItem->originlist.” for “.$theSearchItem->destlist.”
“;
}
echo “

To “.$theUserInfo->user_nicename.”
“;
DrawCard($theType, $theID, 128);
echo “
for… “;
DrawCard($theType, $theID, 128);
echo “

“;
}
}
else
{
echo “You currently have no trade offers.
“;
}

}

DrawCurrentTradeOffers();

if(isset($_POST[“confirm”]))
{
$user = wp_get_current_user();
$theUserID = $user->data->ID;

if($theUserID == $_POST[‘originid’])
{
$theTimeVal = $wpdb->get_row(“SELECT CURRENT_TIMESTAMP”);
foreach ($theTimeVal as $value)
{
$theVal = $value;
break;
}
$wpdb->insert(‘montrades’, array(created=> $theVal, ‘originid’ => “”.$_POST[‘originid’].””, ‘destid’=> “”.$_POST[‘destid’].””, originlist => $_POST[‘originlist’], destlist => $_POST[‘destlist’], accepted => “0”, completed => “0”));
}
else
{
// the originating user id is not equal to our actual id
}
}
// if the user did a trade post
else if(isset($_POST[“trade”]))
{
$user = wp_get_current_user();
$theUserID = $user->data->ID;
$theirID = 0;

echo “Trade proposed:
“;

$myArray = array();
$theirArray = array();
var_dump($_POST);
foreach($_POST as $tradeKey => $tradeItem)
{
if(strncmp(“TRADE”, $tradeKey, 5) == 0)
{
if($tradeItem == “on”)
{
$theData = substr($tradeKey, 5);
$theDataArray = explode(“_”, $theData);
$thisID = $theDataArray[0];
$thisType = $theDataArray[1];
$thisNumber = $theDataArray[2];
if($thisID == $theUserID)
{
$myArray[sizeof($myArray)] = $theDataArray;
}
else
{
$theirArray[sizeof($myArray)] = $theDataArray;
$theirID = $thisID;
}
}
}
}
// only if the user has a valid trade — items in my array and their array
if((sizeof($myArray) > 0) && (sizeof($theirArray) > 0))
{
echo “

“;
echo ““;
echo ““;
echo ““;

$shouldDrawBasicForm = false;
echo “

“;
$originlist = “”;
$destlist = “”;
foreach ($myArray as $itemArray)
{
if(strlen($originlist > 0))
$originlist .= “,”;
$originlist .= $itemArray[1].$itemArray[2];
echo “

“;
}
foreach ($theirArray as $itemArray)
{
if(strlen($destlist > 0))
$destlist .= “,”;
$destlist .= $itemArray[1].$itemArray[2];
echo “

“;
}
echo ““;
echo ““;
echo “

“;
if(sizeof($myArray) == 1)
$cardsString = “card”;
else
$cardsString = “cards”;
echo “You are offering (“.sizeof($myArray).” “.$cardsString.”)…“;
echo “
“;
if(sizeof($theirArray) == 1)
$cardsString = “card”;
else
$cardsString = “cards”;
echo “For (“.sizeof($theirArray).” “.$cardsString.”)…“;
echo “
“;
DrawCard($itemArray[1], $itemArray[2], 128);
echo “
“;
DrawCard($itemArray[1], $itemArray[2], 128);
echo “

“;
echo “Do you want to send this offer to the other user?
“;
echo “                        “;
echo ““;
echo “

“;
}
}
//if the user did a pokesearch post
else if(isset($_POST[“pokesearch”]))
{
$user = wp_get_current_user();
$theUserID = $user->data->ID;
$theSearchArray = $wpdb-> get_results (‘select * from monbase where name rlike “‘.$_POST[‘pokesearch’].'”‘);
DrawTradeFormStart();
$didSuccessfulSearch = true;
foreach($theSearchArray as $theItem)
{
$theIdentifier = sprintf(“%s%03d”, $theItem->type, (int)$theItem->id);
$theUserSearchArray = $wpdb->get_results(‘select * from monpoke where cards rlike “‘.$theIdentifier.'” and userid!=’.$theUserID);
foreach($theUserSearchArray as $theUserItem)
{
$theUserInfo = $wpdb->get_row(‘select user_nicename, ID from wp_xvywdt_users where ID=’.$theUserItem->userid);
echo $theUserInfo->user_nicename;
DrawCards(“User #”.$theUserInfo->ID.”‘s Cards”, $theUserInfo->ID, true);

//echo $theUserItem->userid.”:”.$theUserItem->cards.”
“;
}
}
}

if($shouldDrawBasicForm)
{
DrawBasicForm(($didSuccessfulSearch ? true : false));
if($didSuccessfulSearch)
DrawTradeFormEnd();
}

function GetTypeString($inType)
{
if($inType == “xyev”)
return “XY Evolutions”;
else if($inType == “xyst”)
return “XY Steam Siege”;
else if($inType == “xyfc”)
return “XY Fates Collide”;
else if($inType == “smoo”)
return “Sun and Moon”;
else if($inType == “smgr”)
return “Sun and Moon Guardians Rising”;
}

function GetTypeAbbreviation($cardID)
{
$theType = substr($cardID, 0, 4);
return $theType;
}

function GetCardNumber($cardID)
{
$theNumber = substr($cardID, 4, 3);
return $theNumber;
}

// if the user isn’t posting, they’re wanting to see the basic form with their cards
function DrawBasicForm($inDrawForm)
{
// code is 4 character type + 3 digit number like xyev008
$theItems = “xyev023,xyst042,xyfc100,smgr142,smoo101”;
$user = wp_get_current_user();
$theUserID = $user->data->ID;
//$wpdb->insert(‘monpoke’, array(‘userid’ => 1, ‘cards’=>$theItems));

//$wpdb->replace(‘monpoke’, array(‘userid’ => 1, ‘cards’=>$theItems));

DrawCards(null, $theUserID, $inDrawForm);
echo “

“;
}

function DrawCard($inType, $inID, $inWidth)
{
global $wpdb;
$theFilePath = “/home/dh_rxtumv/legendesque.com/pokemon/”.$inType.”/”.$inID.”.jpg”;

if(!is_null($inWidth))
{
$theScaleString = ‘width=”‘.$inWidth.'”‘;
// $theScaleString = ‘style=”-webkit-transform: scale(‘.$inScale.’); -moz-transform: scale(‘.$inScale.’); -ms-transform: scale(‘.$inScale.’); -o-transform: scale(‘.$inScale.’);” ‘;
}
else
{
$theScaleString = “”;
}

if(file_exists($theFilePath))
echo ““;
else
echo ““;

echo ““.GetTypeString($inType).” #”.(int)$inID.”
“;
$theLink2 = $wpdb->get_row (‘select * from monbase where type=”‘.$inType.'” and id=”‘.$inID.'”‘);
$theRarity = $theLink2->rarity;
if($theLink2 != null)
echo ““.$theLink2->name.” – “.$theRarity.”
“;
}

function DrawCards($inWhoseCards, $inUserID, $inDrawForm)
{
global $wpdb;
$theUserID = “”.$inUserID;
$theLink = $wpdb->get_row (‘select * from monpoke where userid=’.$theUserID);

$theIndex = 1;

$theArray = explode(“,”, $theLink->cards);
echo “
“;
echo “

“;
if(!is_null($inWhoseCards))
$whoseCards = ““.$inWhoseCards.”“;
else
$whoseCards = “My Cards“;
echo “

“;
foreach($theArray as $item)
{
if(($theIndex % 4) == 1)
{
echo “

“;
}
//echo $item.”
“;
$theType = GetTypeAbbreviation($item);
$theNumber = GetCardNumber($item);
echo “

“;
if(($theIndex % 4) == 0)
{
echo “

“;
}
++$theIndex;
}
}

[/insert_php]

Privacy Overview

This website uses cookies so that we can provide you with the best user experience possible. Cookie information is stored in your browser and performs functions such as recognising you when you return to our website and helping our team to understand which sections of the website you find most interesting and useful.

“.$whoseCards.”
“;
DrawCard($theType, $theNumber, null);

$theCheckName = “TRADE”.$inUserID.”_”.$theType.”_”.$theNumber;
if($inDrawForm)
echo ““;
echo “