Guest User

Untitled

a guest
Dec 31st, 2011
57
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
YAML 8.17 KB | None | 0 0
  1. <?php
  2.     session_start();
  3.     require 'config.php';
  4.     require 'itemInfo.php';
  5.     $isAdmin = $_SESSION['Admin'];
  6.     $canBuy = $_SESSION['canBuy'];
  7.     /*
  8.      * Script:   DataTables server-side script for PHP and MySQL
  9.      * Copyright: 2010 - Allan Jardine
  10.      * License:  GPL v2 or BSD (3-point)
  11.      */
  12.    
  13.     /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
  14.      * Easy set variables
  15.      */
  16.    
  17.     /* Array of database columns which should be read and sent back to DataTables. Use a space where
  18.      * you want to insert a non-database field (for example a counter or static image)
  19.      */
  20.     $aColumns = array( 'name', 'damage', 'player', 'quantity', 'price', 'id', 'created');
  21.    
  22.     /* Indexed column (used for fast and accurate table cardinality) */
  23.     $sIndexColumn = "id";
  24.    
  25.     /* DB table to use */
  26.     $sTable = "WA_Auctions";
  27.    
  28.     /* Database connection information */
  29.     $gaSql['user']       = $db_user;
  30.     $gaSql['password']   = $db_pass;
  31.     $gaSql['db']         = $db_database;
  32.     $gaSql['server']     = $db_host;
  33.    
  34.    
  35.     /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
  36.      * If you just want to use the basic configuration for DataTables with PHP server-side, there is
  37.      * no need to edit below this line
  38.      */
  39.    
  40.     /*
  41.      * MySQL connection
  42.      */
  43.     $gaSql['link'] =  mysql_pconnect( $gaSql['server'], $gaSql['user'], $gaSql['password']  ) or
  44.         die( 'Could not open connection to server' );
  45.    
  46.     mysql_select_db( $gaSql['db'], $gaSql['link'] ) or
  47.         die( 'Could not select database '. $gaSql['db'] );
  48.    
  49.    
  50.     /*
  51.      * Paging
  52.      */
  53.     $sLimit = "";
  54.     if ( isset( $_GET['iDisplayStart'] ) && $_GET['iDisplayLength'] != '-1' )
  55.     {
  56.         $sLimit = "LIMIT ".mysql_real_escape_string( $_GET['iDisplayStart'] ).", ".
  57.             mysql_real_escape_string( $_GET['iDisplayLength'] );
  58.     }
  59.    
  60.    
  61.     /*
  62.      * Ordering
  63.      */
  64.     if ( isset( $_GET['iSortCol_0'] ) )
  65.     {
  66.         $sOrder = "ORDER BY  ";
  67.         for ( $i=0 ; $i<intval( $_GET['iSortingCols'] ) ; $i++ )
  68.         {
  69.             if ( $_GET[ 'bSortable_'.intval($_GET['iSortCol_'.$i]) ] == "true" )
  70.             {
  71.                 $sOrder .= $aColumns[ intval( $_GET['iSortCol_'.$i] ) ]."
  72.                     ".mysql_real_escape_string( $_GET['sSortDir_'.$i] ) .", ";
  73.             }
  74.         }
  75.        
  76.         $sOrder = substr_replace( $sOrder, "", -2 );
  77.         if ( $sOrder == "ORDER BY" )
  78.         {
  79.             $sOrder = "";
  80.         }
  81.     }
  82.    
  83.    
  84.     /*
  85.      * Filtering
  86.      * NOTE this does not match the built-in DataTables filtering which does it
  87.      * word by word on any field. It's possible to do here, but concerned about efficiency
  88.      * on very large tables, and MySQL's regex functionality is very limited
  89.      */
  90.     $sWhere = "";
  91.     if (isset($_GET['sSearch'])){
  92.     if ( $_GET['sSearch'] != "" )
  93.     {
  94.         $sWhere = "WHERE (";
  95.         for ( $i=0 ; $i<count($aColumns) ; $i++ )
  96.         {
  97.             $sWhere .= $aColumns[$i]." LIKE '%".mysql_real_escape_string( $_GET['sSearch'] )."%' OR ";
  98.         }
  99.         $sWhere = substr_replace( $sWhere, "", -3 );
  100.         $sWhere .= ')';
  101.     }
  102.     }
  103.     /* Individual column filtering */
  104.     for ( $i=0 ; $i<count($aColumns) ; $i++ )
  105.     {
  106.         if (isset($_GET['bSearchable_'.$i])){
  107.         if ( $_GET['bSearchable_'.$i] == "true" && $_GET['sSearch_'.$i] != '' )
  108.         {
  109.             if ( $sWhere == "" )
  110.             {
  111.                 $sWhere = "WHERE ";
  112.             }
  113.             else
  114.             {
  115.                 $sWhere .= " AND ";
  116.             }
  117.             $sWhere .= $aColumns[$i]." LIKE '%".mysql_real_escape_string($_GET['sSearch_'.$i])."%' ";
  118.         }
  119.         }
  120.     }
  121.    
  122.    
  123.     /*
  124.      * SQL queries
  125.      * Get data to display
  126.      */
  127.     if (isset($sOrder)){
  128.     $sQuery = "
  129.         SELECT SQL_CALC_FOUND_ROWS ".str_replace(" , ", " ", implode(", ", $aColumns))."
  130.         FROM   $sTable
  131.         $sWhere
  132.         $sOrder
  133.         $sLimit
  134.     ";
  135.     }else{
  136.     $sQuery = "
  137.         SELECT SQL_CALC_FOUND_ROWS ".str_replace(" , ", " ", implode(", ", $aColumns))."
  138.         FROM   $sTable
  139.         $sWhere
  140.         $sLimit
  141.     ";
  142.    
  143.     }
  144.     $rResult = mysql_query( $sQuery, $gaSql['link'] ) or die(mysql_error());
  145.    
  146.     /* Data set length after filtering */
  147.     $sQuery = "
  148.         SELECT FOUND_ROWS()
  149.     ";
  150.     $rResultFilterTotal = mysql_query( $sQuery, $gaSql['link'] ) or die(mysql_error());
  151.     $aResultFilterTotal = mysql_fetch_array($rResultFilterTotal);
  152.     $iFilteredTotal = $aResultFilterTotal[0];
  153.    
  154.     /* Total data set length */
  155.     $sQuery = "
  156.         SELECT COUNT(".$sIndexColumn.")
  157.         FROM   $sTable
  158.     ";
  159.     $rResultTotal = mysql_query( $sQuery, $gaSql['link'] ) or die(mysql_error());
  160.     $aResultTotal = mysql_fetch_array($rResultTotal);
  161.     $iTotal = $aResultTotal[0];
  162.    
  163.     /*
  164.      * Output
  165.      */
  166.     if (isset($_GET['sEcho'])){
  167.     $output = array(
  168.         "sEcho" => intval($_GET['sEcho']),
  169.         "iTotalRecords" => $iTotal,
  170.         "iTotalDisplayRecords" => $iFilteredTotal,
  171.         "aaData" => array()
  172.     );
  173.     }
  174.     while ( $aRow = mysql_fetch_array( $rResult ) )
  175.     {
  176.         $row = array();
  177.         $timeCreated = $aRow[ $aColumns[6] ];
  178.         if( time() < $timeCreated + $auctionDurationSec){
  179.             $itemName = $aRow[ $aColumns[0] ];
  180.             $fullItemName = getItemName($aRow[ $aColumns[0] ], $aRow[ $aColumns[1] ]);
  181.             $itemDamage = $aRow[ $aColumns[1] ];
  182.             $marketPrice = getMarketPrice($aRow[ $aColumns[5] ], 1);
  183.             if ($marketPrice > 0)
  184.             {
  185.                 $marketPercent = round((($aRow[ $aColumns[4] ]/$marketPrice)*100), 1);
  186.             }
  187.             else
  188.             {
  189.                 $marketPercent = "N/A";
  190.             }
  191.             if ($marketPercent == "N/A")
  192.             {
  193.                 $marketPercent = 0;
  194.                 $grade = "gradeU";
  195.             }
  196.             else if ($marketPercent <= 50)
  197.             {
  198.                 $grade = "gradeA";
  199.             }
  200.             else if ($marketPercent <= 150)
  201.             {
  202.                 $grade = "gradeC";
  203.             }
  204.             else
  205.             {
  206.                 $grade = "gradeX";
  207.             }
  208.             $row['DT_RowClass'] = $grade;
  209.             $theId = $aRow[ $aColumns[5] ];
  210.             $tempString = "";
  211.             $queryEnchantLinks=mysql_query("SELECT enchId FROM WA_EnchantLinks WHERE itemId='$theId' AND itemTableId='1'");
  212.             //print_r(mysql_fetch_row($queryEnchantLinks));
  213.             while(list($enchId)= mysql_fetch_row($queryEnchantLinks))
  214.                 {
  215.                     $queryEnchants=mysql_query("SELECT * FROM WA_Enchantments WHERE id='$enchId'");
  216.                     while(list($id, $enchName, $enchantId, $level)= mysql_fetch_row($queryEnchants))
  217.                     {
  218.                         $tempString =$tempString."<br/>".getEnchName($enchantId)." - Level: ".$level;
  219.                     }
  220.                
  221.                 }
  222.             $row[] = "<a href='graph.php?name=".$aRow[ $aColumns[0] ]."&damage=".$aRow[ $aColumns[1] ]."'><img src=".getItemImage($aRow[ $aColumns[0] ], $aRow[ $aColumns[1] ])." alt=".$fullItemName."/><br/>".$fullItemName.$tempString."</a>";
  223.             $row[] = "<img width='32px' src='http://minotar.net/avatar/".$aRow[ $aColumns[2] ]."' /><br/>".$aRow[ $aColumns[2] ];
  224.             $row[] = date('d/m/Y H:i:s', $timeCreated + $auctionDurationSec);
  225.             $row[] = $aRow[ $aColumns[3] ];
  226.             $row[] = $aRow[ $aColumns[4] ];
  227.             $row[] = (((double)$aRow[ $aColumns[3] ])*((double)$aRow[ $aColumns[4] ]));
  228.             $row[] = $marketPercent;
  229.        
  230.             if ($canBuy == true){
  231.                 $row[] = "<form action='scripts/purchaseItem.php' method='post'><input type='text' name='Quantity' onKeyPress='return numbersonly(this, event)' class='input'><input type='hidden' name='ID' value='".$aRow[ $aColumns[5] ]."' /><input type='submit' value='Buy' class='button' /></form>";   
  232.             }else{
  233.                 $row[] = "Can't Buy";
  234.             }
  235.             if ($isAdmin == true){
  236.                 $row[] = "<td><a class='button' href='scripts/cancelAuctionAdmin.php?id=".$aRow[ $aColumns[5] ]."'>Cancel</a></td>";
  237.             }
  238.             $output['aaData'][] = $row;
  239.         }else
  240.         {
  241.             $user = $aRow[ $aColumns[2] ];
  242.             $id = $aRow[ $aColumns[5] ];
  243.             $itemName = $aRow[ $aColumns[0] ];
  244.             $itemDamage = $aRow[ $aColumns[1] ];
  245.             $itemQuantity = $aRow[ $aColumns[3] ];
  246.             $queryPlayerItems =mysql_query("SELECT * FROM WA_Items WHERE player='$user'");
  247.             $foundItem = false;
  248.             $stackId = 0;
  249.             $stackQuant = 0;
  250.             while(list($pid, $pitemName, $pitemDamage, $pitemOwner, $pitemQuantity)= mysql_fetch_row($queryPlayerItems))
  251.             {  
  252.                 if($itemName == $pitemName)
  253.                 {
  254.                     if ($pitemDamage == $itemDamage)
  255.                     {
  256.                         $foundItem = true;
  257.                         $stackId = $pid;
  258.                         $stackQuant = $pitemQuantity;
  259.                     }
  260.                 }
  261.             }
  262.             if ($foundItem == true)
  263.             {
  264.                 $newQuantity = $itemQuantity + $stackQuant;
  265.                 $itemQuery = mysql_query("UPDATE WA_Items SET quantity='$newQuantity' WHERE id='$stackId'");
  266.             }else
  267.             {
  268.                 $itemQuery = mysql_query("INSERT INTO WA_Items (name, damage, player, quantity) VALUES ('$itemName', '$itemDamage', '$user', '$itemQuantity')");
  269.             }
  270.             $itemDelete = mysql_query("DELETE FROM WA_Auctions WHERE id='$id'");
  271.         }
  272.     }
  273.     echo json_encode( $output );
  274. ?>
Advertisement
Add Comment
Please, Sign In to add comment