<?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->redirect('admin/login');

$path = '';
$customer_info = array();
if($func->get('customer_id')) {
    $path = '?customer_id='.$func->get('customer_id');
    $customer_info = $db->query("SELECT * FROM " . DBPREFIX . "customer WHERE id='" . $func->get('customer_id') . "'");
    $customer_info = $customer_info->num_rows?$customer_info->row:array();
}
if($_SERVER['REQUEST_METHOD']=='POST') {
    $query = array();
    foreach ($func->post() as $key=>$item) {
        if($key=='password'){
            if(!empty($item)) {
                $query[] = $key . "='" . $db->escape(md5($item)) . "'";
            }
        }else{
            $query[] = $key."='".$db->escape($item)."'";
        }

    }
    if($func->get('customer_id')){
        $sql = "UPDATE " . DBPREFIX . "customer SET " . implode(',', $query)." WHERE id='".$func->get('customer_id')."'";
    }else {
        $query[] = "date_added='" . date('Y-m-d H:i:s') . "'";
        $sql = "INSERT INTO " . DBPREFIX . "customers SET " . implode(',', $query);
    }
    $db->query($sql);
    $location->redirect('admin/customers');
}
//echo '<pre>';print_r($_SERVER);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>Müşteri</strong> Ekle/Düzenle</h2>
                </div>
                <!-- END Meta Data Title -->

                <!-- Meta Data Content -->
                <form action="<?php echo SITE_ADMIN; ?>new_customer.php<?php echo $path; ?>" method="post" class="form-horizontal form-bordered">
                    <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="product-meta-title" name="name" value="<?php echo $customer_info?$customer_info['name']:''; ?>" class="form-control" placeholder="İsim/Soyisim..">
                        </div>
                    </div>
                    <div class="form-group">
                        <label class="col-md-3 control-label" for="product-telephone">Telefon</label>
                        <div class="col-md-9">
                            <input type="text" id="product-telephone" name="phone" value="<?php echo $customer_info?$customer_info['phone']:''; ?>" class="form-control" placeholder="Telefon Numarası">
                        </div>
                    </div>

                    <div class="form-group">
                        <label class="col-md-3 control-label" for="product-note">Meta Description</label>
                        <div class="col-md-9">
                            <input type="text" id="product-telephone" name="email" value="<?php echo $customer_info?$customer_info['email']:''; ?>" class="form-control" placeholder="email">
                        </div>
                    </div>

                    <div class="form-group">
                        <label class="col-md-3 control-label" for="product-note">Şifre</label>
                        <div class="col-md-9">
                            <input type="text" id="product-telephone" name="password" value="" class="form-control" placeholder="Parola">
                        </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> Save</button>
                            <a href="<?php echo SITE_ADMIN; ?>customers.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>$(function(){ EcomProducts.init(); });</script>

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