function storage_out($item_id,$buyer){
$success = "";
$user = clean_post($buyer);
$id = (int)($item_id);
$market_item = mssql_query("Select * from [Storage] where [id] = '".$id."'");
$market_pr = mssql_fetch_array($market_item);
$mycuritems = all_items($user,1200); // Check your warehouse Item column length and type it here -1920 for Season 2
$item = ItemInfoUser($market_pr['item']);
$slot = smartsearch($mycuritems, $item['x'], $item['y']);
$test = $slot * 20; // Change this to 32 instead of 20
$mynewitems = substr_replace($mycuritems, $market_pr['item'], ($test), 20); // Change this to 32 instead of 20
$message = array();
if((mssql_num_rows($market_item)) == 0){
$message[] = phrase_storage_invalid_item;
}
elseif(mssql_num_rows(mssql_query("Select * From MEMB_STAT WHERE ConnectStat=1 and memb___id='".$user."'")) != 0){
$message[] = phrase_leave_the_game;
}
elseif($market_pr['end_date'] != 'NULL'){
$message[] = phrase_storage_invalid_item;
}
elseif($slot == 1337){
$message[] = phrase_no_enough_space;
}
else{
$success = 1;
mssql_query("Update [warehouse] set [Items]=0x" . $mynewitems . " where [AccountId]='".$user."'");
mssql_query("Update [Storage] set end_date='".time()."', buyer_ip='".ip()."' where [id]='".$id."'");
$message[] = phrase_storage_the_item. "<span title=\"" . $item['name'] . " <br><br><img src=" . $item['thumb'] . "\" class=\"someClass\" >
<font style=\"font-size: 14px;color:#ff5c26\">" . $item['name'] . " </span></font>" . phrase_itemа_success_re;
refresh1();
}
message($message,$success);
}
function storage_in($item_serial,$item_id,$item_type){
include("configs/config.php");
if(isset($_SESSION['dt_username'])) {
$user = ($_SESSION['dt_username']);
$rez = mssql_fetch_array(mssql_query("Select [AccountId],[Items],[Money] from [warehouse] where [AccountID]='".$user."'"));
$is_online = mssql_fetch_array(mssql_query("Select [ConnectStat] from [MEMB_STAT] WHERE [memb___id]='".$user."'"));
$messages = array();
$wh_content = array();
$item_level = id_type($item_serial);
$itemtem = ItemInfoUser($item_serial);
$mycuritems = all_items($user,1200); // Check your warehouse Item column length and type it here -1920 for Season 2
$itemsa = array($mycuritems);
if (strlen($item_serial) != 20) { // Change this to 32 instead of 20
$messages[] = phrase_market_invalid_item;
}
elseif (in_array($item_id."/".$item_type,$option['storage_banned_items'])) {
$messages[] = phrase_market_banned_item;
}
elseif ($is_online['ConnectStat'] != 0) {
$messages[] = phrase_leave_the_game;
}
elseif (in_array($item_serial,$itemsa)) {
$messages[] = phrase_market_item_not_yours;
}
elseif ($rez['AccountId'] != $_SESSION['dt_username']) {
$messages[] = phrase_market_item_not_yours;
}
else{
if (preg_match("/{$item_serial}/", $mycuritems)) {
$empty = str_repeat("F",20); // Change this to 32 instead of 20
$mynewitems = str_replace($item_serial, $empty, $mycuritems);
$update_market = mssql_query("INSERT INTO [Storage]
([item_type],[item_id],[item],[seller],[start_date],[seller_ip],[name], [level],[skill],[luck],[options],[excellent]) VALUES
('".$item_level["level1"]."','".$item_level["level2"] . "','".$item_serial."','".$user."','".time()."','".ip()."','".$itemtem['name']."','".$itemtem['level']."','".$itemtem['srch_skill']."','".$itemtem['srch_luck']."','".$itemtem['opt']."','".$itemtem['exl']."')");
if(!$update_market){
$messages[] = phrase_market_error_contact_admin;
}
else{
mssql_query("Update [warehouse] set [Items]=0x" . $mynewitems . " WHERE [AccountId]='" . $user . "'");
$messages[] = phrase_storage_the_item ."<span style=\"text-shadow:1px 1px; font-size:12pt;cursor: pointer;\" title=\"".$itemtem['name']." <br><br><img src=".$itemtem['thumb']." \" class=\"someClass\" >
<font style=\"font-size: 14px;color:#ff5c26\">".$itemtem['name']." </span></font>". phrase_item_success_storage;
$success = 1;
}
}
else {
$messages[] .= phrase_storage_item_not_found;
}
}
message($messages,$success);
}
}
function smartsearch($whbin, $itemX, $itemY) {
if (substr($whbin, 0, 2) == '0x') {
$whbin = substr($whbin, 2);
}
$items = str_repeat('0', 120);
$itemsm = str_repeat('1', 120);
$i = 0;
while ($i < 120) {
$_item = substr($whbin, (20 * $i), 20); // Change this to 32 instead of 20
$level = substr($_item, 0, 1);
$level2 = substr($_item, 1, 1);
$level3 = substr($_item, 14, 2);
$level1 = hexdec(substr($level, 0, 1));
if (($level1 % 2) <> 0) {
$level2 = "1" . $level2;
$level1--;
}
if (hexdec($level3) >= 128) {
$level1 += 16;
}
$level1 /= 2;
$id = hexdec($level2);
$result = mssql_query("select [x],[y],[Name] from [DPWeb_JewelDeposit_Items] where [id]={$id} and [type]={$level1}");
$res = mssql_fetch_array($result);
$y = 0;
while ($y < $res['y']) {
$y++;
$x = 0;
while ($x < $res['x']) {
$items = substr_replace($items, '1', ($i + $x) + (($y - 1) * 8), 1);
$x++;
}
}
$i++;
}
$y = 0;
while ($y < $itemY) {
$y++;
$x = 0;
while ($x < $itemX) {
$x++;
$spacerq[$x + (8 * ($y - 1))] = true;
}
}
$walked = 0;
$i = 0;
while ($i < 120) {
if (isset($spacerq[$i])) {
$itemsm = substr_replace($itemsm, '0', $i - 1, 1);
$last = $i;
$walked++;
}
if ($walked == count($spacerq)) {
$i = 119;
}
$i++;
}
$useforlength = substr($itemsm, 0, $last);
$findslotlikethis = '#^' . str_replace('++', '+', str_replace('1', '+[0-1]+', $useforlength))."#";
$i = 0;
$nx = 0;
$ny = 0;
while ($i < 120) {
if ($nx == 8) {
$ny++;
$nx = 0;
}
if ((preg_match($findslotlikethis, substr($items, $i, strlen($useforlength)))) && ($itemX + $nx < 9) && ($itemY + $ny < 16)) {
return $i;
}
$i++;
$nx++;
}
return 1337;
}