<?php include 'loader.php'; ?>
<?php include 'inc/config.php'; ?>
<?php include 'inc/template_start.php'; ?>
<?php include 'inc/page_head.php'; ?>
<?php
if(!$user->isLogged()) $location->aredirect('login');
//if(!$func->get('reservation_id')) $location->aredirect('orders');
$room_info = [];
$path = '';

if($_SERVER['REQUEST_METHOD']=='POST') {
    //$func->prnt($func->post(),true);
    //echo '<pre>';print_r($_FILES);echo '</pre>'; die();

    if($func->get('id')) {
        $params = $func->post();



        $sql = [];
        foreach ($params as $key=>$param) {
            if($key=='fiyat'){
                $param = str_replace(',','.',$param);
            }
            $sql[]= $key." = '".$param."'";
        }
        $sql = implode(',',$sql);

        $db->query("UPDATE " . DBPREFIX . "danisman SET ".$sql." WHERE id='".$func->get('id')."'");
        $success->set('Danışman bilgileriniz başarıyla güncellenmiştir.');
    }else{
        $params = $func->post();
        $sql = [];
        foreach ($params as $key=>$param) {
            if($key=='fiyat'){
                $param = str_replace(',','.',$param);
            }
            $sql[]= $key." = '".$param."'";
        }
        $sql = implode(',',$sql);

        $db->query("INSERT INTO " . DBPREFIX . "danisman SET ".$sql);
        $success->set('Danışman başarıyla eklenmiştir.');
    }

    $location->aredirect('danisman');
}

if($func->get('id')) {
    $room_info = $db->query("SELECT * FROM " . DBPREFIX . "danisman WHERE id = '".$func->get('id')."'");
    $room_info = $room_info->row;
    $path = '?id='.$func->get('id');
    //echo '<pre>';print_r($room_info);echo '</pre>'; die();
}


?>
<!-- Page content -->
<div id="page-content">


    <div class="row">

        <div class="col-lg-12">
            <!-- Meta Data Block -->
            <div class="block">
                <!-- Meta Data Title -->
                <div class="block-title">
                    <h2><i class="fa fa-google"></i> <strong>Danışman</strong> Ekle/Düzenle</h2>
                </div>
                <!-- END Meta Data Title -->

                <!-- Meta Data Content -->
                <form action="<?php echo SITE_ADMIN; ?>danisman_edit.php<?php echo $path; ?>" method="post" class="form-horizontal form-bordered" enctype="multipart/form-data">

                    <div class="form-group">
                        <label class="col-md-3 control-label" for="product-meta-title">Firma Adı</label>
                        <div class="col-md-9">
                            <input type="text" required name="company_name" value="<?php echo $room_info?$room_info['company_name']:''; ?>" id="company_name" placeholder="Firma Adı" class="form-control">
                        </div>
                    </div>

                    <div class="form-group">
                        <label class="col-md-3 control-label" for="product-meta-title">İsim/Soyisim</label>
                        <div class="col-md-9">
                            <input type="text" id="name" name="name" value="<?php echo $room_info?$room_info['name']:''; ?>" class="form-control" placeholder="İsim/Soyisim">
                        </div>
                    </div>

                    <div class="form-group">
                        <label class="col-md-3 control-label" for="product-meta-title">Email</label>
                        <div class="col-md-9">
                            <input type="email" required name="email" value="<?php echo $room_info?$room_info['email']:''; ?>" id="email" placeholder="E-Mail" class="form-control">
                        </div>
                    </div>

                    <div class="form-group">
                        <label class="col-md-3 control-label" for="product-meta-title">Email</label>
                        <div class="col-md-9">
                            <textarea placeholder="Açıklama" name="message" id="message" class="form-control"><?php echo $room_info?$room_info['message']:''; ?></textarea>
                        </div>
                    </div>


                    <div class="form-group form-actions">
                        <div class="col-md-9 col-md-offset-3">
                            <button type="submit" class="btn btn-sm btn-primary"><i class="fa fa-floppy-o"></i> Kaydet</button>
                            <a href="<?php echo SITE_ADMIN; ?>danisman.php" class="btn btn-sm btn-warning"><i class="fa fa-repeat"></i> İptal</a>
                        </div>
                    </div>
                </form>
                <!-- END Meta Data Content -->
            </div>
            <!-- END Meta Data Block -->

        </div>
    </div>


</div>









<?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/ecomProducts.js"></script>
<script src="js/simple.money.format.js" type="text/javascript"></script>
<script>
    $(function(){ EcomProducts.init(); });
    $(document).ready(function () {
        $('input[name="fiyat"]').simpleMoneyFormat();
    });
</script>

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