<?php include 'loader.php'; ?>
<?php include 'inc/config.php'; ?>
<?php include 'inc/template_start.php'; ?>
<?php include 'inc/page_head.php'; ?>

<?php
$projeler = $db->query("SELECT * FROM " . DBPREFIX . "projeler ");
$projeler = $projeler->num_rows?$projeler->rows:array();

$proje_id = $func->get('proje_id')?$func->get('proje_id'):0;

?>

    <!-- Page content -->
    <div id="page-content">
        <!-- eCommerce Orders Header -->
        <div class="content-header">
            <ul class="nav-horizontal text-center">
                <li >
                    <a href="<?php echo SITE_ADMIN; ?>index.php"><i class="gi gi-shop_window"></i> Anasayfa</a>
                </li>
                <li class="active">
                    <a href="<?php echo SITE_ADMIN; ?>rooms.php"><i class="gi gi-notes_2"></i> Daireler</a>
                </li>
                <li >
                    <a href="<?php echo SITE_ADMIN; ?>projects.php"><i class="gi gi-settings"></i> Projeler</a>
                </li>
                <li >
                    <a href="<?php echo SITE_ADMIN; ?>customers.php"><i class="fa fa-user"></i> Müşteriler</a>
                </li>
                <li >
                    <a href="<?php echo SITE_ADMIN; ?>forms.php"><i class="gi gi-certificate"></i> Formlar</a>
                </li>
                <li >
                    <a href="<?php echo SITE_ADMIN; ?>crm.php"><i class="gi gi-notes"></i> Crm</a>
                </li>
                <li>
                    <a href="<?php echo SITE_ADMIN; ?>danisman.php"><i class="gi gi-stopwatch"></i> Danışmanlar</a>
                </li>
            </ul>
        </div>
        <!-- END eCommerce Orders Header -->

        <!-- All Orders Block -->
        <div class="block full">
            <!-- All Orders Title -->
            <div class="block-title">
                <div class="block-options pull-right">
                    Projeler:
                    <?php foreach ($projeler as $proje){ ?>
                        <a href="<?php echo SITE_ADMIN; ?>rooms.php?proje_id=<?php echo $proje['id']; ?>"  class="btn btn-alt btn-sm <?php echo $proje_id==$proje['id']?'btn-danger':'btn-warning'; ?>" data-toggle="tooltip" title="Settings"><i class="fa fa-plus"></i> <?php echo $proje['adi']; ?></a>

                    <?php } ?>

                    <a style="margin-left: 50px" href="<?php echo SITE_ADMIN; ?>/new_room.php?proje_id=<?php echo $proje_id; ?>" class="btn btn-alt btn-sm btn-success" data-toggle="tooltip" title="Settings"><i class="fa fa-plus"></i> Yeni Ekle</a>
                </div>
                <h2><strong>Tüm</strong> Daireler</h2>
            </div>
            <!-- END All Orders Title -->

            <!-- All Orders Content -->
            <table id="ecom-orders" class="table table-bordered table-striped table-vcenter">
                <thead>
                <tr>
                    <th class="text-center" style="width: 100px;">Sıra No</th>
                    <th class="text-center" style="width: 100px;">Daire No</th>
                    <th class="text-center" style="width: 100px;">Daire Türü</th>
                    <th class="visible-lg">Oda</th>
                    <th class="text-center visible-lg">Fiayt</th>
                    <th class="hidden-xs">Brüt M2</th>
                    <th class="text-right hidden-xs">Net M2</th>
                    <th class="text-right hidden-xs">Kat</th>
                    <th class="text-right hidden-xs">Blok</th>
                    <th class="text-right hidden-xs">Cephe</th>
                    <th class="text-right hidden-xs">Daire Tipi</th>
                    <th class="text-right hidden-xs">Teras, Bahçe, Balkon</th>
                    <th>Durum</th>
                    <th class="text-center">Eylem</th>
                </tr>
                </thead>
                <tbody>
                <?php

                $labels['1']['class']   = "label-danger";
                $labels['1']['text']    = "Satıldı";
                $labels['0']['class']   = "label-info";
                $labels['0']['text']    = "Satılık";
                $labels['2']['class']   = "label-success";
                $labels['2']['text']    = "Opsiyonlandı";
                $sql = $proje_id?" WHERE proje_id ='".$proje_id."'":"";
                $items = $db->query("SELECT * FROM " . DBPREFIX . "items ".$sql." ORDER BY daire_no ASC");
                ?>
                <?php foreach($items->rows as $item) { ?>
                    <tr id="order_id_<?php echo $item['id']; ?>">
                        <td class="text-center hidden-xs"><?php echo $item['id']; ?></td>
                        <td class="text-center"><?php echo $item['daire_no']; ?></td>
                        <td class="text-center"><?php echo $item['daire_turu']; ?></td>
                        <td class="visible-lg"><a href="javascript:void(0)"><?php echo $item['oda']; ?></a></td>
                        <td class="text-center visible-lg"><a href="javascript:void(0)"><?php echo $item['fiyat']; ?><?php echo $item['currency']; ?></a></td>
                        <td class="hidden-xs"><?php echo $item['brut_metre']; ?></td>
                        <td class="text-right hidden-xs"><?php echo $item['net_metre']; ?></td>
                        <td class="text-right hidden-xs"><?php echo $item['kat']; ?></td>
                        <td class="text-right hidden-xs"><?php echo $item['blok']; ?></td>
                        <td class="text-right hidden-xs"><?php echo $item['cephe']; ?></td>
                        <td class="text-right hidden-xs"><?php echo $item['daire_tipi']; ?></td>
                        <td class="text-right hidden-xs"><?php echo $item['diger_metre']; ?></td>
                        <td><span class="label<?php $rand = $item['durum']; echo ($labels[$rand]['class']) ? " " . $labels[$rand]['class'] : ""; ?>"><?php echo $labels[$rand]['text']; ?></span></td>
                        <td class="text-center">

                            <div class="btn-group btn-group-xs">
                                <a href="<?php echo SITE_ADMIN; ?>new_room.php?id=<?php echo $item['id']; ?>&proje_id=<?php echo $proje_id; ?>" data-toggle="tooltip" title="View" class="btn btn-default"><i class="fa fa-eye"></i></a>
                                <a href="javascript:void(0)" onclick="itemDelete('room',<?php echo $item['id']; ?>);" data-toggle="tooltip" title="Delete" class="btn btn-xs btn-danger"><i class="fa fa-times"></i></a>
                            </div>
                        </td>
                    </tr>
                <?php } ?>
                </tbody>
            </table>
            <!-- END All Orders Content -->
        </div>
        <!-- END All Orders Block -->
    </div>
    <!-- END Page Content -->

<?php include 'inc/page_footer.php'; ?>
<?php include 'inc/template_scripts.php'; ?>

    <!-- Load and execute javascript code used only in this page -->
    <script src="js/pages/ecomOrders.js"></script>
    <script>
        $(function(){ EcomOrders.init(); });

        $('#projeler').on('change',function (){
            location =  '<?php echo SITE_ADMIN; ?>rooms.php?proje_id='+$(this).val();
        });

    </script>

<?php include 'inc/template_end.php'; ?>