<?php include('inc/header.php'); ?>
<h1>Suche - Inventar</h1>
<div class="container">
    <div class="backend_button">
        <a href="javascript:history.back();">Gehe zurück</a>
    </div>
    <script type="text/javascript">
        function xUpdateInventoryDetail(id, amount, name, serial, flag, command, cost, level, job) {
            document.getElementById('Detail_ID').textContent 		= id;
            document.getElementById('Detail_Amount').textContent 	= amount;
            document.getElementById('Detail_Name').textContent 		= name;
            document.getElementById('Detail_Serial').textContent 	= serial;
            document.getElementById('Detail_Flag').textContent 		= flag;
            document.getElementById('Detail_Command').textContent 	= command;
            document.getElementById('Detail_Cost').textContent 		= cost;
            document.getElementById('Detail_Level').textContent 	= level;
            document.getElementById('Detail_Job').textContent 		= job;
        }
        function xUpdateInventory(slot, id) {
            var sel = document.getElementById('Slot_' + slot);
            sel.style.backgroundImage = 'url(../images/item/' + id + ')';
            sel.style.backgroundPosition = 'center center';
            sel.style.backgroundRepeat = 'no-repeat';
        }
    </script>
    <style type="text/css">


        .InventoryBox {
            float: left;
            background: url(../images/inventory/WndInventory3D.png) repeat left center;
            width: 240px;
            height: 560px;
        }
        .InventoryBox h3 {font-size: 16px; padding: 5px; margin: 0px; border-bottom: 1px solid #dcdcdc;}

        .InventoryItemLeft {
            position: relative ;
            top: 30px;
            left: 15px;
            width: 31px;
            height: 31px;
            margin-bottom: 17px;
        }
        .InventoryItemRight {
            float: right;
            position: relative ;
            top: 33px;
            right: 20px;
            width: 31px;
            height: 31px;
            margin-bottom: 17px;
        }
        .InventoryItemMiddleTop {
            float: left;
            position: relative ;
            top: 25px;
            left: 56px;
            width: 22px;
            height: 22px;
            margin-right: 4px;
            background-size: cover;
        }
        .InventoryItemMiddleBottom {
            float: left;
            position: relative ;
            top: -7px;
            left: 58px;
            width: 28px;
            height: 28px;
            margin-right: 3px;
            background-size: cover;
        }
        .InventoryItemSlotBox {
            float: left;
            top: 4px;
            position: relative ;
            left: 17px;
            width: 31px;
            height: 31px;
            margin-right: 2px;
            margin-bottom: 1px;
        }
        .InventoryPenyaBox {
            top: 32px;
            position: relative ;
            left: 105px;
            color: #009ACD;
            font-weight: bold;
            width: 100px;
            height: 17px;
            padding-top: 1px;
            padding-left: 4px;
        }

        #ItemDetailBox {
            width: calc(100% - 240px - 20px);
            padding: 5px 10px;
            float: left;
        }
        #ItemDetailBox h3 {font-size: 16px; padding: 5px; margin: 0px; border-bottom: 1px solid #dcdcdc;}

        #ItemDetailBox table tr td {
            width: 50%;
        }
    </style>
<?php

function Binding($flag) {
    $byFlag = array( 0 => '-', 2 => 'Seelengebunden', 4 => 'Event' );
    return $byFlag[$flag];
}
function MouseOverInfo($id) {
    global $m_Inventory_detail_info;
    if(!empty( $m_Inventory_detail_info[$id]['m_dwItemId'])) {
        return ' onMouseOver="xUpdateInventoryDetail( \''.$m_Inventory_detail_info[$id]['m_dwItemId'].'\',
                                                      \''.$m_Inventory_detail_info[$id]['m_nItemNum'].'\',
                                                      \''.str_replace("'", "\'", utf8_encode(getItemName($m_Inventory_detail_info[$id]['m_dwItemId'], 'name'))).'\',
                                                      \''.$m_Inventory_detail_info[$id]['m_liSerialNumber'].'\',
                                                      \''.Binding($m_Inventory_detail_info[$id]['m_byFlag']).'\',
                                                      \''.str_replace('"', '', utf8_encode(getItemName($m_Inventory_detail_info[$id]['m_dwItemId'], 'description'))).'\',
                                                      \''.getItemName($m_Inventory_detail_info[$id]['m_dwItemId'], 'Cost').'\',
                                                      \''.getItemName($m_Inventory_detail_info[$id]['m_dwItemId'], 'requiredLvl').'\',
                                                      \''.getItemName($m_Inventory_detail_info[$id]['m_dwItemId'], 'requiredJob').'\'
                                                        )"';
    }
    else {
        return ' onMouseOver="xUpdateInventoryDetail( \'\',
                                                      \'\',
                                                      \'\',
                                                      \'\',
                                                      \'\',
                                                      \'\',
                                                      \'\',
                                                      \'\',
                                                      \'\'
        )"';
    }
}
function getSlotOfItem($m_dwObjId, $m_apIndex) {
    $count = 0;
    while (list(, $dwObjId) = each($m_apIndex)) {
        if($m_dwObjId == $dwObjId)
            return $count;
        $count++;
    }
}

$m_Inventory = explode('/', odbc_result(odbc_exec($odbc_connect, 'SELECT [m_Inventory] FROM [' . $_CONFIG['db_databases']['chr'] . '].dbo.[INVENTORY_TBL] WHERE [m_idPlayer] = ' . mssql_escape_string($_GET['characterID'])), 'm_Inventory'));
$m_apIndex = explode('/', odbc_result(odbc_exec($odbc_connect, 'SELECT [m_apIndex] FROM [' . $_CONFIG['db_databases']['chr'] . '].dbo.[INVENTORY_TBL] WHERE [m_idPlayer] = ' . mssql_escape_string($_GET['characterID'])), 'm_apIndex'));
$m_Inventory_detail = array();
$m_Inventory_detail_info = array();

for($i = 0; $i < count($m_Inventory); $i++) {

    $arr = explode(',', $m_Inventory[$i]);

    if($arr[0] != '$') {
        $m_Inventory_detail[] = array(
            'm_dwObjId' => $arr[0],
            'm_dwItemId' => $arr[1],
            'bEquip' => $arr[2],
            'nTrade' => $arr[3],
            'm_szItemText' => $arr[4],
            'm_nItemNum' => $arr[5],
            'm_nRepairNumber' => $arr[6],
            'm_nHitPoint' => $arr[7],
            'nMaxHitPoint' => $arr[8],
            'nMaterial' => $arr[9],
            'm_byFlag' => $arr[10],
            'm_liSerialNumber' => $arr[11],
            'm_nAbilityOption' => $arr[12]
        );
        $m_Inventory_detail_info[getSlotOfItem($arr[0], $m_apIndex)] = array(
            'm_dwObjId' => $arr[0],
            'm_dwItemId' => $arr[1],
            'bEquip' => $arr[2],
            'nTrade' => $arr[3],
            'm_szItemText' => $arr[4],
            'm_nItemNum' => $arr[5],
            'm_nRepairNumber' => $arr[6],
            'm_nHitPoint' => $arr[7],
            'nMaxHitPoint' => $arr[8],
            'nMaterial' => $arr[9],
            'm_byFlag' => $arr[10],
            'm_liSerialNumber' => $arr[11],
            'm_nAbilityOption' => $arr[12]
        );
    }
}

echo '
    <div class="InventoryBox">
        <div class="InventoryItemMiddleTop" id="Slot_62"'.MouseOverInfo(62) . '></div>
        <div class="InventoryItemMiddleTop" id="Slot_64"'.MouseOverInfo(64) . '></div>
        <div class="InventoryItemMiddleTop" id="Slot_61"'.MouseOverInfo(61) . '></div>
        <div class="InventoryItemMiddleTop" id="Slot_65"'.MouseOverInfo(65) . '></div>
        <div class="InventoryItemMiddleTop" id="Slot_63"'.MouseOverInfo(63) . '></div>
        <div class="InventoryItemRight" id="Slot_48"'.MouseOverInfo(48) . '></div>
        <div class="InventoryItemLeft" id="Slot_52"'.MouseOverInfo(52) . '></div>
        <div class="InventoryItemRight" id="Slot_44"'.MouseOverInfo(44) . '></div>
        <div class="InventoryItemLeft" id="Slot_51"'.MouseOverInfo(51) . '></div>
        <div class="InventoryItemRight" id="Slot_46"'.MouseOverInfo(46) . '></div>
        <div class="InventoryItemLeft" id="Slot_67"'.MouseOverInfo(67) . '></div>
        <div class="InventoryItemRight" id="Slot_47"'.MouseOverInfo(47) . '></div>
        <div class="InventoryItemLeft" id="Slot_50"'.MouseOverInfo(50) . '></div>
        <div class="InventoryItemRight" id="Slot_55"'.MouseOverInfo(55) . '></div>
        <div class="InventoryItemLeft" id="Slot_54"'.MouseOverInfo(54) . '></div>
        <div class="InventoryItemMiddleBottom" id="Slot_68"'.MouseOverInfo(68) . '></div>
        <div class="InventoryItemMiddleBottom" id="Slot_69"'.MouseOverInfo(69) . '></div>
        <div class="InventoryItemMiddleBottom" id="Slot_70"'.MouseOverInfo(70) . '></div>
        <div class="InventoryItemMiddleBottom" id="Slot_71"'.MouseOverInfo(71) . '></div>';

$slot = 0;
for($i=0; $i < 7; $i++) {
    echo '
        <div style="clear:both;"></div>
        <div class="InventoryItemSlotBox" id="Slot_'.($slot+0).'"'.MouseOverInfo($slot+0) . '></div>
        <div class="InventoryItemSlotBox" id="Slot_'.($slot+1).'"'.MouseOverInfo($slot+1) . '></div>
        <div class="InventoryItemSlotBox" id="Slot_'.($slot+2).'"'.MouseOverInfo($slot+2) . '></div>
        <div class="InventoryItemSlotBox" id="Slot_'.($slot+3).'"'.MouseOverInfo($slot+3) . '></div>
        <div class="InventoryItemSlotBox" id="Slot_'.($slot+4).'"'.MouseOverInfo($slot+4) . '></div>
        <div class="InventoryItemSlotBox" id="Slot_'.($slot+5).'"'.MouseOverInfo($slot+5) . '></div>';
    $slot += 6;
}


if(isset($m_Inventory_detail)) {
    for( $i = 0; $i < sizeof( $m_Inventory_detail ); $i++ ) {
        $strItemIcon = str_replace('.dds', '.png', getItemName($m_Inventory_detail[$i]['m_dwItemId'], 'image'));
        if(!file_exists('../images/item/' . $strItemIcon)) {
            $strItemIcon = 'Itm_SysSysQueRainbowBlue.png';
        }
        echo '<script type="text/javascript">
           xUpdateInventory('.getSlotOfItem( $m_Inventory_detail[$i]['m_dwObjId'], $m_apIndex ).', \'' . $strItemIcon . '\');</script>';
    }
}
echo $counter;

echo '
        <div style="clear:both;"></div>
        <div class="InventoryPenyaBox">'.number_format(odbc_result(odbc_exec($odbc_connect, 'SELECT [m_dwGold] FROM [' . $_CONFIG['db_databases']['chr'] . '].[dbo].[CHARACTER_TBL] WHERE [m_idPlayer] = ' . mssql_escape_string($_GET['characterID'])), 'm_dwGold'), 0, '',',').'</div>
    </div>';
echo '
    <div id="ItemDetailBox">
        <h3>Item Detail</h3>
        <table>
            <tr>
                <td><b>Serial:</b></td>
                <td><span id="Detail_Serial">-</span></td>
            </tr>
            <tr>
                <td><b>Name:</b></td>
                <td><span id="Detail_Name">-</span></td>
            </tr>
            <tr>
                <td><b>ID:</b></td>
                <td><span id="Detail_ID">-</span></td>
            </tr>
            <tr>
                <td><b>Anzahl:</b></td>
                <td><span id="Detail_Amount">-</span></td>
            </tr>
            <tr>
                <td><b>Preis:</b></td>
                <td><span id="Detail_Cost">-</span></td>
            </tr>
            <tr>
                <td><b>Bindung:</b></td>
                <td><span id="Detail_Flag">-</span></td>
            </tr>
            <tr>
                <td><b>Level:</b></td>
                <td><span id="Detail_Level">-</span></td>
            </tr>
            <tr>
                <td><b>Job:</b></td>
                <td><span id="Detail_Job">-</span></td>
            </tr>
            <tr>
                <td valign="top"><b>Beschreibung:</b></td>
                <td><span id="Detail_Command">-</span></td>
            </tr>
        </table>
    </div>';

?>
<br style="clear: both;" />
</div>
<?php include('inc/footer.php'); ?>