<?php
if(!$_GET['a'])
{
$page = (int) $_GET['page'];
if($page == '') { $page = 1; }
$RowPerPage = 100;
$startRows = ($page-1)*$RowPerPage+0;
//1 day True/Fasle
if ($pcw['market']['days'] == True)
{
if(isset($_GET['usersearch']))
{
$usernametofind=$_GET[searchuser];
//Plasmen code
$get_seller_acccc_name = mssql_query("SELECT TOP 1 Name,AccountID FROM [Character] where Name = '".$usernametofind."' order by gresets desc, Resets desc");
$get_seller_acccc_name = mssql_fetch_row($get_seller_acccc_name);
$check = mssql_query("SELECT TOP 1 Name,AccountID FROM [Character] where AccountID = '".$get_seller_acccc_name[1]."' order by gresets desc, Resets desc, cLevel desc");
$check = mssql_fetch_row($check);
if($get_seller_acccc_name[0] == $check[0]) {$user=$get_seller_acccc_name[1];}
else {$user="";}
//Plasmen code end
$items = mssql_query("SELECT * FROM SMarket WHERE ((opt = 1) AND ((buyer is null) OR buyer='') AND (username='$user') ) ORDER BY timer DESC");
}
elseif(isset($_GET['itemsearch']))
{
$itemnametofind=$_GET[searchitem];
$items = mssql_query("SELECT * FROM SMarket WHERE
(((opt = 1) AND ((buyer is null) OR buyer=''))
and
(
(exists
( SELECT * FROM WebShop WHERE ( (name like '%".$itemnametofind."%')
and (SMarket.cat_id=WebShop.type) and (SMarket.item_id=WebShop.id) and (SMarket.sticklevel=WebShop.stickLevel) ) )
)
or
(exists
(SELECT * FROM WebShop WHERE ((name like '%".$itemnametofind."%')
and (SMarket.cat_id=WebShop.type) and (SMarket.item_id=WebShop.id) and (WebShop.stickLevel=0)
)))
)
)
ORDER BY timer DESC");
}
elseif(isset($_GET['showsold']))
{
$items = mssql_query("SELECT * FROM SMarket WHERE ((opt = 1) AND ((buyer is not null) or buyer!='' ) AND username='".secure($_COOKIE['username'])."') ORDER BY timer DESC");
}
else {$items = mssql_query("SELECT * FROM SMarket WHERE ((opt = 1) AND ((buyer is null) OR buyer='')) ORDER BY timer DESC");}
}
elseif ($pcw['market']['days'] == False){ $items = mssql_query("SELECT * FROM SMarket WHERE timer > ".(time()-86400)." AND opt = 1 ORDER BY timer DESC"); }
$num_of_rows = mssql_num_rows($items);
@mssql_data_seek($items,$startRows);
$total_pages = ceil($num_of_rows/$RowPerPage);
//Show market list if not adding item
echo "
<form method='request'>";
//Променливи
$acc = $_COOKIE['username'];
//Заявки
$query=mssql_query("SELECT * FROM MEMB_CREDITS WHERE memb___id='$acc'");
$memb_credits=mssql_fetch_array($query);
$query=mssql_query("SELECT * from votetop where userche='$acc'");
$votetop=mssql_fetch_array($query);
$query=mssql_query("SELECT * from SMS_LOG where memb___id='$acc'");
$sms_log=mssql_fetch_array($query);
echo "<input type='submit' name='Add' value='Add new item in market' OnClick=\"ajax('market&a=true')\" > ";
echo "<input type='submit' name='showsold' id='showsold' value='Show my sold items' OnClick=\"ajax('market&showsold=true&'+doc('searchitem'))\">
</form>
<form method='request'>
Search items from user : <input type='text' maxlength='10' name='searchuser' id='searchuser'>
<input type='submit' value='Search' name='usersearch' OnClick=\"ajax('market&usersearch=true&'+doc('searchuser'))\" >
</form>
<form method='request'>
Search items by item name : <input type='text' maxlength='50' name='searchitem' id='searchitem' >
<input type='submit' value='Search' name='itemsearch' OnClick=\"ajax('market&itemsearch=true&'+doc('searchitem'))\" >
</form>
";
if ($pcw['market']['add_item'] == 0) echo "";
else echo" <br />Every offer requre <span>".$pcw['market']['add_item']." credits</span> to show in market list<br /><br />";
if(isset($_GET['itemsearch']))
{
echo "<br><span align='center' style='color:orange; ' >Results for items containing: <font color=red>".$itemnametofind."</font></span><br>";
}
echo " <table>
<tr>
<td width='80'>By</td>
<td width='400'>Item</td>
<td>Credits</td>
<td width='50' align='right'>";
if(isset($_GET['showsold'])) {echo "Buyer";}
else {echo "Buy";}
echo "</td></tr>";
$total=0;
for($i=0; $i<$RowPerPage; $i++)
{
$item = mssql_fetch_array($items);
$it = ItemInfo($item['itemhex'],true);
if(!$item){ break; }
$rank = $i + $startRows+1;
$admin = (in_array($_COOKIE['username'],explode(',',$pcw['config']['admins']))) ? " OnClick = \"var dell = confirm('Are you sure you want to delete this item?!'); if (dell!=false) { ajax('market&ad=$item[id]') }\"" : "";
if ($memb_credits[active] == 1 || $votetop[broivotes] >20|| $sms_log[smscount] >0) {
$option = ($item['username'] == $_COOKIE['username']) ? "<img style='cursor:pointer' src='images/delete.png' alt='Remove from market' title='Remove from market' OnClick=\"var delll = confirm('Are you sure you want to delete this item?!'); if (delll!=false) { ajax('market&d=$item[id]') } \">" : "<img style='cursor:pointer' src='images/buy.png' alt='Buy this item' title='Buy this item' OnClick=\"var buy = confirm('Are you sure you want to buy this item?!'); if (buy!=false) { ajax('market&it=$item[id]') }\">";
}
else {
$option = ($item['username'] == $_COOKIE['username']) ? "<img style='cursor:pointer' src='images/delete.png' alt='Remove from market' title='Remove from market' OnClick=\"var delll = confirm('Are you sure you want to delete this item?!'); if (delll!=false) { ajax('market&d=$item[id]') } \">" : "<img style='cursor:pointer' src='images/buy.png' alt='Buy this item' title='Buy this item' OnClick=\"alert ('You need minimum 21 votes or 1 SMS to use this function.') \">";
}
//Plasmen code
$get_seller_acccc_name = mssql_query("SELECT TOP 1 Name,AccountID FROM [Character] where Name = '".$item[username]."' order by gresets desc, Resets desc");
$get_seller_acccc_name = mssql_fetch_row($get_seller_acccc_name);
$check = mssql_query("SELECT TOP 1 Name,AccountID FROM [Character] where AccountID = '".$item[username]."' order by gresets desc, Resets desc, cLevel desc");
$check = mssql_fetch_row($check);
if($get_seller_acccc_name[0] == $check[0]) {$user=$get_seller_acccc_name[1];}
else {$user="";}
//Plasmen code end
$total = $total + $item[credits];
if(isset($_GET['showsold'])) {
echo "
<tr>
<td>".($check[0])."</td>
<td><span style='cursor:pointer;color:$it[color]' $it[nfo]$admin>$it[name]$it[hp]</span></td>
<td>$item[credits]</td>
<td align='center'>$item[buyer]</td>
</tr>";}
else {
echo "
<tr>
<td>".($check[0])."</td>
<td><span style='cursor:pointer;color:$it[color]' $it[nfo]$admin>$it[name]$it[hp]</span></td>
<td>$item[credits]</td>
<td align='center'>$option</td>
</tr>";}
}
if(isset($_GET['showsold'])) {
echo "
<tr>
<td></td>
<td><center>Total:</span></td>
<td>$total</td>
<td align='center'></td>
</tr>";}
echo "</table><br />".rankings($page,$num_of_rows,$total_pages,$startRows,$rank,"market&page=")."";
}
else
{
//Adding Items from Warehouse
mssql_query("declare @items varbinary(1920); set @items = (SELECT [items] FROM [warehouse] WHERE [AccountId]='".secure($_COOKIE['username'])."'); print @items;");
$current_items = mssql_get_last_message();
$user_items = substr($current_items,2);
echo "<span align='center' style='color:orange; cursor:pointer' OnClick=\"ajax('market&a=true')\">Refresh warehouse</span><br />To put item(s) for sell item must be in your warehouse and account to be offline.<br />";
if ($pcw['market']['add_item'] == 0) echo"";
else echo "
Every offer requre <span>".$pcw['market']['add_item']." credits</span> to show in market list<br />";
$i = -1;
while($i<119)
{
$item = ItemInfo(substr($user_items,(32*$i),32));
if(@$item['name'])
{
echo "<img OnClick=\"prom('$i')\" src='$item[thumb]'$item[nfo]>";
}
$i++;
}
//Adding Items from WebWare
$cur_item = mssql_query("SELECT [hex] FROM [SBank] WHERE [username]='".secure($_COOKIE['username'])."'");
echo "<span align='center' style='color:orange; cursor:pointer' OnClick=\"ajax('market&a=true')\"><br>Refresh web warehouse</span><br />To put item(s) for sell item must be in your warehouse and account to be offline.<br />";
if ($pcw['market']['add_item'] == 0) echo"";
else echo "
Every offer requre <span>".$pcw['market']['add_item']." credits</span> to show in market list<br />";
for($iWebWare=0; $iWebWare<mssql_num_rows($cur_item) ; $iWebWare++)
{
$cur_item_out = mssql_fetch_array($cur_item);
$item = ItemInfo($cur_item_out[0]);
$hexofitem = $cur_item_out[0];
if(@$item['name'])
{
echo "<img OnClick=\"promWebWare('$hexofitem')\" src='$item[thumb]'$item[nfo]>";
}
}
}
?>