View Single Post
  #1  
Old 03-26-2012, 04:36 PM
SilverDragonTears's Avatar
SilverDragonTears SilverDragonTears is offline
I am your Nemesis.
 
Join Date: Jun 2011
Posts: 1,113
Gender: Female
Credits: 84,493
SilverDragonTears is on a distinguished road
Default trade not working on new version of Mys

You put in stuff and it just stays on the trade page like you simply refreshed it.

PHP Code:
<?php

include("functions/functions.php");
include(
"functions/functions_users.php");
include(
"functions/functions_adopts.php");
include(
"functions/functions_friends.php");
include(
"functions/functions_items.php");
include(
"inc/lang.php");
include(
"inc/bbcode.php");

//***************//
//  START SCRIPT //
//***************//

if($isloggedin == "yes"){

// First let's make sure we are installed...

$userstatus getuserstatus($loggedinname);
if(
$userstatus['cantrade'] == "no"){

$article_title "You do not have permission to trade";
$article_content "It appears that an admin has banned your right to trade on this site, send him/her a PM to learn the details.";

}

else{

$enab grabanysetting("enabletrades");

if(
$enab == "yes"){

// Get our post variables...

$adoptwanted $_POST["adoptwanted"];
$adoptgiven $_POST["adoptgiven"];
$itemgiven $_POST["itemgiven"];
$cashgiven $_POST["cashgiven"];
$message $_POST["message"];

$cashenabled grabanysetting("cashenabled");
$cashname grabanysetting("cost");
$tradecost grabanysetting("tradecost");
$tradeoffercost grabanysetting("tradeoffercost");
$mycash getcash($loggedinname);

// Now we are going to check if we have posted an adoptable we wish to trade...

if(is_numeric($adoptwanted)){

// Attempt to execute the trade...

///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
//                                                                                         //
// WE ARE ATTEMPTING TO RUN A TRADE HERE...                                                             //
//                                                                                         //
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

// >>> >>> >>> >>>

    // Set a flag and error message...

    
$flag 0;
    
$error "";
    
    
// First we make sure that the adoptable the user wants actually exists...

    
$num 0;

    if (!empty(
$adoptwanted)){
        
$stmt $adopts->query("SELECT * FROM {$prefix}owned_adoptables WHERE aid='$adoptwanted' and tradestatus='fortrade'");
      
$row $stmt->fetchObject();
    }

    if(!
is_object($row)){
      
$flag++;
      
$error "The adoptable that you want either does not exist or is not available for trading.";
    }
    
// Now we check that if the user entered in an adoptable to give away they actually own it and wish to trade it...

    
if (!empty($adoptgiven)){
      
$stmt $adopts->query("SELECT * FROM {$prefix}owned_adoptables WHERE aid='$adoptgiven' and owner='$loggedinname' and tradestatus='fortrade'");
      
$row $stmt->fetchObject();

      if(!
is_object($row)){
        
$flag++;
        
$error "The adoptable you selected to give the other user either does not exist, does not belong to you or is not set as available for trade.    
        As a safety precaution all adoptables must be set with the Trading Enabled setting before they can be used in trades."
;
      }
    }
    else{
      
$flag++;
      
$error "You have not selected an adoptable to give to your trade partner in exchange...";
    }
    
    if(!empty(
$itemgiven)){
      
// Check if the item offered actually belong to the owner...
      
$stmt2 $adopts->query("SELECT * FROM {$prefix}inventory WHERE iid='$itemgiven'");
      
$item $stmt2->fetchObject();

      if(!
is_object($item)){
        
// The item does not exist at all...
        
$flag++;
        
$error "The item you are offering does not seem to exist at all.";
      }
      if(
is_object($item) and $item->owner != $loggedinname){
        
// The item belongs to someone else, now we have a hacking attempt!
        
$flag++;
        
$adopts->query("UPDATE {$prefix}users SET usergroup='5' WHERE username='{$loggedinname}'");
        
$adopts->query("UPDATE {$prefix}users_status SET cantrade='no' WHERE username='{$loggedinname}'");  
        
$error "You have selected an item that belongs to someone else. You've been banned for this action, please contact an admin for further assistance.";
      }
    }
    
// Now if the user has entered in a cash amount make sure they have the money to cover the transaction with the other user...

    
if($cashenabled == "yes"){

    
$moneyleft $mycash $cashgiven;

      if(
$moneyleft 0){
        
$flag++;
        
$error "You do not have enough ".$cashname." to cover the payment amount you have selected to pay the other user.  Please either earn more ".$cashname." or decrease your payment amount.";
      }
    
    
// Now check that the user can cover the site's transaction offer fee...

    
$moneyleft $moneyleft $tradeoffercost;

    if(
$moneyleft 0){
        
$flag++;
        
$error "You do not have enough ".$cashname." to cover the cost of making this trade offer.";
    }


    }

    
// On the very last, we check if the trade partner accepts trades with friends only...
    
    
    
    // Ok, I think we are all done...

    
if($flag 0){

    
$article_title "Trade Error";
    
$article_content $error;

    }
    else{

    
// Dispatch the trade offer...
    // First we log the trade in the _trades database table...

    
$time date('Y-m-d-m-s');
    
    
$adopts->query("INSERT INTO {$prefix}trades (id, userrequestingtrade, tradetype, adoptableoffered, itemoffered, cashoffered, adoptabledesired, custommessage, offerstatus)
                                         VALUES ('', '
$loggedinname', '$time','$adoptgiven','$itemgiven','$cashgiven','$adoptwanted', '$message', 'pending')");
    
    
// Now we need to create a new PM to the user receiving the trade to let them know a trade is available for them...

    
$stmt $adopts->query("SELECT * FROM {$prefix}owned_adoptables WHERE tradestatus='fortrade' and aid='$adoptwanted'"); 
    
$adoptable $stmt->fetchObject();
    
$toname=$adoptable->owner//The person we send a PM to...


    // Now we need to fetch the ID of this trade so the user can pull it up easily...

    
$stmt $adopts->query("SELECT * FROM {$prefix}trades WHERE userrequestingtrade='$loggedinname' and adoptabledesired='$adoptwanted' and tradetype='$time'");
    
$trade $stmt->fetchObject(); 

    
// Now we send the PM to $toname...

    
$mtitle "You have received a trade request from {$loggedinname}!";
    
$mtext "You have received a trade request from {$loggedinname}!  They want to take one of your adoptables off of your hands and give you something in return.
    To see the details of this trade request and to accept or reject it, please visit the trade redemption center to check out your trade offer."
;    

    
$date date('Y-m-d');
    
$stmt $adopts->query("SELECT * FROM {$prefix}users WHERE username='$toname'");
    
$partner $stmt->fetchObject(); 
    
$loggedinid usernametouid ($loggedinname);
    
    if(
$partner->friends == ""$actionpassed "no";
    else{
      
$friendidlist explode(",",$partner->friends);
      
$actionpassed "no";
      foreach(
$friendidlist as $friend){
        if(
$friend == $loggedinid$actionpassed "yes"
      }
    }
    
    if(
$partner->tradestatus == and $actionpassed == "no"){
        
$adopts->query("DELETE FROM {$prefix}trades WHERE userrequestingtrade='$loggedinname' and adoptabledesired='$adoptwanted' and tradetype='$time'");
        
$article_title "An error has occurred...";
        
$article_content "It appears that your trade partner only accepts trade requests from his/her friends.";    
    }
    else{
    
$query "INSERT INTO {$prefix}messages (id, fromuser, touser, status, datesent, messagetitle, messagetext)
                                     VALUES ('', '
$loggedinname', '$toname','unread','$date','$mtitle', '$mtext')";
    
$adopts->query($query);

    
// Now we update the trades table with the other person's username...

    
$adopts->query("UPDATE {$prefix}trades SET tradeto='{$toname}' WHERE id='{$trade->id}' and userrequestingtrade='{$loggedinname}'");

    
// Now we are all done...
    // Let's show a thank you page to the user...

    
$article_title "Your Trade Offer Has Been Sent";
    
$article_content "Your trade offer has been sent successfully!  If you need to cancel this trade request you can do this on the My Trades page.
    You will be notified via PM when this trade is either accepted or rejected."
;    
    } 
    }

}
else{

// Show the informational page...
// Allow a custom introduction...

$pagecontent getsitecontent("tradetext");
$custom_title $pagecontent[title];
$custom_content $pagecontent[content];
$custom_content bbconvert($custom_content); // BBCODE conversion
$custom_content nl2br($custom_content);

if(
$custom_title != "" and $custom_content != ""){

$article_title $custom_title;
$article_content $custom_content;

}
else{

$article_title "The Trade Station";
$article_content "Welcome to the Trade Station.  Here you can trade one of your adoptables for an adoptable owned by someone else.  
To trade adoptables, you will need to know the ID of the adoptable you wish to receive.  You can find the adoptable ID by searching adoptables.  
Once you know the ID of the adoptable you want, simply fill out the form below to begin the trade.<br>
<b><a href='redeem.php'>Go to Redeem Center to see trade offers</a></b><br> 
<b><a href='mytrades.php'> Visit My trade page to manage trade proposals</a></b><br> 
<b><a href='search.php'> Search for an available adoptable for trade</a></b><br>"

// Custom Content IF

// Take in a param...

$gid $_GET["id"];
$gid preg_replace("/[^a-zA-Z0-9\\040.]/"""$gid);
$gid secure($gid);

// GET THE DATABASE INFO...

$adoptoffered "";
$itemoffered "";

$stmt $adopts->query("SELECT * FROM {$prefix}owned_adoptables WHERE owner='$loggedinname' and tradestatus='fortrade'");
while(
$row $stmt->fetchObject()) {

  
$aid=$row->aid//The adoptable's ID
  
$name=$row->name;
  
$adoptoffered .= "<option value='{$aid}'>{$name}</option>";
}

$stmt2 $adopts->query("SELECT * FROM {$prefix}inventory WHERE owner='$loggedinname' and status='available'");
while(
$row2 $stmt2->fetchObject()) {
  
$iid=$row2->iid//The item's ID
  
$iname=$row2->itemname;
  
$itemoffered .= "<option value='{$iid}'>{$iname}</option>";
}



// END DATABASE INFO

if($cashenabled == "yes"){

$article_content $article_content."<br><br><u>{$cashname} Based Settings:</u><br><br>
Your 
{$cashname}{$mycash}<br>
Amount of 
{$cashname} required to make a trade offer: {$tradeoffercost}<br>
Amount of 
{$cashname} required to complete a trade: {$tradecost}<br><br>
<img src='templates/icons/warning.gif' border=0> WARNING: If you do not have enough 
{$cashname} to cover the cost of this trade when the other user attempts to complete the trade the trade will fail!";

}

$article_content $article_content."<br><form name='form1' method='post' action='trade.php'>
  <p>The ID of the adoptable you wish to receive: 
    <input name='adoptwanted' type='text' id='adoptwanted' size='6' maxlength='6' value='
{$gid}'>
</p>
  <p>The adoptable you are willing to give as a part of this trade:<br> 
    <select name='adoptgiven' id='adoptgiven'>
      <option value='none' selected>No Adoptable Selected</option>
    
{$adoptoffered}
    </select>
</p>
  <p>Only the adoptables that you have set to Trading Enabled will be shown here. <a href='myadopts.php' target='_blank'>Click here</a> to manage your adoptables. </p>
  <p>The item you are willing to give as a part of this trade:<br> 
    <select name='itemgiven' id='itemgiven'>
      <option value='none' selected>No Item Selected</option>
    
{$itemoffered}
    </select></p>"
;

if(
$cashenabled == "yes"){

$article_content $article_content." <p>HINT: You can leave the above setting blank if you wish to trade only {$cashname} for your desired adoptable.</p>
  <p>The 
{$cashname} amount you wish to trade for this adoptable: 
    <input name='cashgiven' type='text' id='cashgiven' value='0' size='10' maxlength='10'>
</p>"
;

}

$article_content $article_content." <p>You can leave a short (150 character) message to the user about this trade: 
    <input name='message' type='text' id='message' maxlength='150'>
  </p>
  <p>
    <input type='submit' name='Submit' value='Submit Trade Request'> 
  </p>
</form>"
;

// Is Numeric IF

// Is Enabled IF

else{

$article_title "Trading Not Enabled";
$article_content "Trading is either not enabled or not currently available for your site.";


}

}

}

else{

$article_title "Registered Members Only";
$article_content "Only registered site members may use the trade system.  Please <a href='login.php'>Log In</a> or <a href='register.php'>Register</a> to use this feature.";

}



//***************//
//  OUTPUT PAGE  //
//***************//

echo showpage($article_title$article_content$date);

?>
__________________

Check out SilvaTales
Reply With Quote