[insert_php]
//require_once(‘/wp-config.php’);
global $wpdb;
echo ‘
‘;
$shouldDrawBasicForm = true;
$didSuccessfulSearch = false;
function DrawTradeFormStart()
{
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 “
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 “
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 “
“;
}
}
//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 “
“.$whoseCards.” |
DrawCard($theType, $theNumber, null); $theCheckName = “TRADE”.$inUserID.”_”.$theType.”_”.$theNumber; |