Don't like ads? PRO users don't see any ads ;-)
Guest

Untitled

By: a guest on Apr 25th, 2012  |  syntax: None  |  size: 6.32 KB  |  hits: 47  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1. <?php
  2.   if (isset($_GET['FinishTrade'])) { include("traded.php"); exit; }
  3.   session_start();
  4.  
  5.   include('config10.php');
  6.  
  7.   if(!isset($_SESSION['user'])){
  8.     header ("Location: login.php?LoginNeeded"); exit;
  9.   }
  10.  
  11.   require_once 'figg.php';
  12.  
  13.   $snorretje1 = mysql_query("SELECT * FROM `users` WHERE `username`='" . $_SESSION['user'] . "'");
  14.   $user = mysql_fetch_object($snorretje1);
  15.   $userID = $user->id;
  16.  
  17.   if(isSet($_GET['trainerID']) && isSet($_GET['action']) && $_GET['trainerID'] > 0 && $_GET['action'] == 'Trade') {
  18.     $trainerID  = intval($_GET['trainerID']);
  19.  
  20.     if($trainerID == $userID) { header('Location: trade.php?error=2'); exit; }
  21.  
  22.     if(isSet($_POST['submit'])) {
  23.    
  24.     $lastTrade = mysql_query("SELECT `tradeid` FROM trade ORDER BY `id` DESC");
  25.     if(mysql_num_rows($lastTrade)) {
  26.       $tradeID = mysql_fetch_object($lastTrade);
  27.       $tradeID = $tradeID->tradeid+1;
  28.     } else {
  29.       $tradeID = 1;
  30.     }
  31.       if(isSet($_POST['mytrade'])) { $tCount = 0;
  32.         $myQuery1 = "INSERT INTO `trade` (`from`, `tradee`, `pokid`,`tradeid`,`owner`) VALUES";
  33.  
  34.         foreach($_POST['mytrade'] AS $pokemon) { $tCount++;
  35.           $pokemon = intval($pokemon);
  36.           if($pokemon > 0) {
  37.             $queryArray[] = $pokemon;
  38.             $myQuery1 .= " ('{$userID}','{$trainerID}','{$pokemon}','{$tradeID}','{$userID}'),";
  39.           }
  40.         }
  41.       }
  42.  
  43.       if(isSet($_POST['othertrade'])) { $pCount = 0;
  44.         $otherQuery1 = "INSERT INTO `trade` (`from`, `tradee`, `pokid`,`tradeid`,`owner`) VALUES";
  45.  
  46.         foreach($_POST['othertrade'] AS $pokemon) { $pCount++;
  47.           $pokemon = intval($pokemon);
  48.           if($pokemon > 0) {
  49.             $queryArray[] = $pokemon;
  50.             $otherQuery1 .= " ('{$userID}','{$trainerID}','{$pokemon}','{$tradeID}','{$trainerID}'),";
  51.           }
  52.         }
  53.       }
  54.  
  55.       $queryArray = '\''.implode('\',\'',$queryArray).'\'';
  56.  
  57.       if($tCount > 0) {
  58.         $myQuery1 = substr_replace($myQuery1,';',-1);
  59.         mysql_query($myQuery1);
  60.       }
  61.  
  62.       if($pCount > 0) {
  63.         $otherQuery1 = substr_replace($otherQuery1,';',-1);
  64.         mysql_query($otherQuery1);
  65.       }
  66.  
  67.       $updatePoke = "UPDATE poke_owned SET traded=1 WHERE id IN ($queryArray)";
  68.       mysql_query($updatePoke);
  69.  
  70.       header('Location: trade.php?FinishTrade'); exit;
  71.     }
  72.  
  73.     $checkTrainer = mysql_query("SELECT `username` FROM users WHERE id=$trainerID LIMIT 1");
  74.     if(mysql_num_rows($checkTrainer)) {
  75.       $trainerInfo   = mysql_fetch_object($checkTrainer);
  76.       $myPokemon     = mysql_query("SELECT `id`,`name`,`level`,`gender` FROM `poke_owned` WHERE trainer='$user->username' AND `box`='1' ORDER BY `name` ASC");
  77.       $traderPokemon = mysql_query("SELECT `id`,`name`,`level`,`gender` FROM `poke_owned` WHERE trainer='$trainerInfo->username' AND `box`='1' ORDER BY `name` ASC");
  78.     } else {
  79.       header('Location: trade.php?error=1'); exit;
  80.     }
  81.   }
  82.  
  83. ?>
  84.  
  85. <?include("left_menu.php");?>
  86.  
  87. <div class="title">Trade Pok&eacute;mon</div>
  88. <div class="contentcontent">
  89. <center>
  90. <?/*#######################*/?>
  91.  
  92. <? if(isSet($_GET['trainerID']) && isSet($_GET['action']) && $_GET['trainerID'] > 0 && $_GET['action'] == 'Trade') { ?>
  93.  
  94.   <form action="trade.php?trainerID=<?=$trainerID;?>&action=Trade" method="POST">
  95.     <table class="w100">
  96.       <tr>
  97.         <td class="w50">
  98.           <p class="center">Your Pok&eacute;mon<br />
  99.             <select name="mytrade[]" multiple="multiple" size="20">
  100.               <option value="niks" selected>(No Pok&#233;mon)</option>
  101.               <? while($myPokemon1=mysql_fetch_object($myPokemon)){ ?><option value="<?=$myPokemon1->id?>"><?=$myPokemon1->name?> <?=$myPokemon1->gender?> (Level:<?=$myPokemon1->level?>)</option>
  102.               <? } ?>
  103.             </select>
  104.           </p>
  105.         </td>
  106.         <td class="w50">
  107.           <p class="center"><?=$trainerInfo->username?>&#39;s Pok&eacute;mon<br />
  108.             <select name="othertrade[]" multiple="multiple" size="20">
  109.               <option value="niks" selected>(No Pok&#233;mon)</option>
  110.               <? while($traderPokemon1=mysql_fetch_object($traderPokemon)){ ?><option value="<?=$traderPokemon1->id?>"><?=$traderPokemon1->name?> <?=$traderPokemon1->gender?> (Level:<?=$traderPokemon1->level?>)</option>
  111.               <? } ?>
  112.             </select>
  113.           </p>
  114.         </td>
  115.       </tr>
  116.     </table>
  117.     <input type="submit" name="submit" value="Trade">
  118.   <form>
  119.  
  120. <? } else { ?>
  121.  
  122.   Enter a trainer name, or part of it to search for them.<br><br>
  123.   <form name="form" action="trade.php" method="GET">
  124.     <input type="text" name="trainer" value="<? if(isSet($_GET['trainer'])) { echo $_GET['trainer']; } ?>" />
  125.     <input type="submit" name="Submit" value="Find Trainer" class="button" />
  126.   </form>
  127.  
  128. <?
  129.   if(isSet($_GET['error'])) {
  130.     $error = intval($_GET['error']);
  131.  
  132.     switch ($error){
  133.       case 1:
  134.         echo '<br> <span style="color: #990000;">You cannot trade with a user that doesn\'t exist.</span>';
  135.         break;
  136.       case 2:
  137.         echo '<br> <span style="color: #990000;">You cannot trade with yourself.</span>';
  138.         break;
  139.       default:
  140.     }
  141.   }
  142.  
  143.   if(isSet($_GET['trainer']) && isSet($_GET['Submit'])) {
  144.     $searchTerm = mysql_real_escape_string($_GET['trainer']);
  145.  
  146.     if(strlen($searchTerm) < 3) {
  147.       echo '<br> <span style="color: #990000;">You must enter at least 3 characters to find a trainer.</span>';
  148.     } else {
  149.       $doQuery = mysql_query("SELECT `id`,`username` FROM users WHERE username LIKE '%$searchTerm%' ORDER BY id DESC");
  150.  
  151.       if($tCount = mysql_num_rows($doQuery)) {
  152.         echo 'You search for "<strong>',$searchTerm,'</strong>", we found ',number_format($tCount),' trainers.<br><br>';
  153.         echo '<table cellpadding="3" cellspacing="0" border="0">';
  154.  
  155.         while($trainer = mysql_fetch_object($doQuery)) {
  156.           echo '<tr><td>';
  157.           echo $trainer->username;
  158.           echo '</td><td> - <a href="trade.php?trainerID=',$trainer->id,'&action=Trade">Trade?</a> </td></tr>';
  159.         }
  160.  
  161.         echo '</table>';
  162.       } else {
  163.         echo '<br> <span style="color: #990000;">We couldn\'t find any trainers for the characters entered. Try again.<span>';
  164.       }
  165.     }
  166. } ?>
  167.  
  168. <? } ?>
  169.  
  170. <?/*#######################*/?>
  171. <p>&nbsp;</p>
  172. </div>
  173.  
  174. <?include("right_menu.php");?>
  175.  
  176. </html>