<?php  include_once('../config/db.php');  include_once('../config/check.php'); 

//if (filter_has_var(INPUT_POST, "edit")) 
//try{
         $id = $_POST['CLIENTEDIT']; 
              if($id == '')
                    {   header("location:allclients");   }

        else  {              
                $stmt = $conn->prepare("SELECT * FROM clients  WHERE id=?");
                $stmt->execute([$id]); $details = $stmt->fetch();                
                }
   //} catch(Exception $e) { echo 'Message: ' .$e->getMessage();} 

  if (filter_has_var(INPUT_POST, "submit")) 
     try{
            $date =            htmlspecialchars (strtoupper($_POST['date']));
            $date =            date("Y-m-d", strtotime($date));
    
            $cid =                htmlspecialchars ( strtoupper($_POST['cid']));          
            $type =                htmlspecialchars ( strtoupper($_POST['type']));          
            $entity =               htmlspecialchars ( strtoupper($_POST['entity']));          
            $name =                htmlspecialchars ( $_POST['name']);          
            $regno =               htmlspecialchars ( strtoupper($_POST['regno']));
           
            $phone =               htmlspecialchars ( $_POST['phone']);
            $email =               htmlspecialchars ($_POST['email']);
            $pin =                 htmlspecialchars  ( strtoupper($_POST['krapin']));
            $zrb=                 htmlspecialchars  ( strtoupper($_POST['zrb']));
            $website =             htmlspecialchars  ( $_POST['website']);
            $branch =              htmlspecialchars  ( $_POST['branch']);

            $address =             htmlspecialchars ( $_POST['address']);
            $location =            htmlspecialchars ( $_POST['location']);
            $country =             htmlspecialchars ( strtoupper($_POST['country']));
          
            
   $sql = "UPDATE bppartner SET type=:type,date=:date,entity=:entity,name=:name,regno=:regno,phone=:phone,email=:email,pin=:pin,zrb=:zrb,website=:website,branch=:branch,address=:address,location=:location,country=:country  WHERE id=:id " ;
   $stmt = $conn->prepare($sql)->execute([ 'type' => $type ,'date' => $date,'entity' => $entity,'name' => $name, 'regno' => $regno,'phone' => $phone, 
                                           'email' => $email,'pin' => $pin,'zrb' => $zrb, 'website' => $website,'branch'=>$branch,'address' => $address,
                                           'location' => $location,'country' => $country,'id'=>$cid  ]);

            header("location:customers.php");
        } catch(Exception $e) { echo 'Message: ' .$e->getMessage();}
        
?>
<!DOCTYPE html>
<html>
<head>
<?php include_once('../inc/slink.php');   ?>  
</head>
<body  <?php include_once('../inc/snav.php');   ?> >
<div class="wrapper">

  <!-- Main Header -->
    <header class="main-header">

    <!-- Logo -->
       <?php include_once('../inc/sbrand.php');   ?>

    <!-- Header Navbar -->
    <?php include_once('../inc/snavbar.php');   ?>

  </header>
 
  <!-- Left side column. contains the logo and sidebar -->
    <aside class="main-sidebar">

    <!-- sidebar: style can be found in sidebar.less -->
     <?php include_once('../inc/smenu.php');   ?>
    <!-- /.sidebar -->
  </aside>

  <!-- Content Wrapper. Contains page content -->
    <div class="content-wrapper">
      <section class="content-header" >
         <p class="listheaderedit" > <i class="fa fa-pencil" ></i> Edit Customer Details </p>
         
         <ol class="breadcrumb">
          
          <li> 
             <a href="customer" > <button class="btn  btn-sm btn-default " > <i class="fa fa-plus "></i>  New Customer </button>    </a>
             <a href="customers" > <button class="btn  btn-sm btn-default " > <i class="fa fa-bars "></i> View All Customers </button>    </a>
            </li>
                   
        </ol>
      </section>

        <!-- <section class="content-header">
          <h1>   <i class="fa fa-user-plus"></i> Add Business Partner    </h1>
            <ol class="breadcrumb">
            <li><a href="#"><i class="fa fa-dashboard"></i> </a></li>
            <li><a href="#"> </a></li>
            <li class="active"> </li>
            <li><a href="bppartnerl.php" class="btn btn-default btn-sm"> <i class="fa fa-bars"></i> View All Business Partner </a></li>
            </ol>
        </section> -->

        <section class="content container-fluid"  style="padding-top:0px;">
            <div class="box box-default box-xs">
                <div class="box-body">
                    <div class="row">
                        <form class="form-horizontal "  action="" method="post"  >
                                <div class="">
                                           
                                                             
                                            <div class="col-sm-3">
                                                <label> Group  </label>
                                                   <select class="form-control  js-example-basic-single  "  required="" name="type" 
                                                        style="width:100%" >
                                                            <?php  $stmt = $conn->prepare("SELECT id,name FROM groups   "); $stmt->execute();
                                                            foreach($stmt as $row)
                                                                {
                                                                    if( $row['id'] == $details["group_id"] )
                                                                            { ?>
                                                                                <option selected value="<?php echo $details["group_id"]  ?>" > 
                                                                                        <?php echo $row['name'] ?>  <option>
                                                                                <?php  }    
                                                                    else  { ?>
                                                                                    
                                                                                    <option  value="<?php echo $row['id']; ?>" > 
                                                                                            <?php echo $row['name'] ?>  <option>
                                                                                    <?php } 
                                                                    } 
                                                            ?>
                                                    </select>  
                                                
                                            </div>   
                                            
                                            <div class="col-sm-6">
                                                <label> Client_Full_Name   </label>
                                                <input type="text" class="form-control " name="name"  value="<?php  echo $details["name"]?>"  autocomplete="off">
                                            </div>                    

                                            <div class="col-sm-3">
                                                <label> System ID  </label>
                                                <input type="text" class="form-control " name="regno" value="<?php  echo $details["system_id"]?>"   autocomplete="off">   
                                            </div>
                                        
                                            <div class="col-sm-3">
                                                <label> Phone number </label>
                                                <input type="text" class="form-control " name="phone"  value="<?php  echo $details["phone"]?>"  autocomplete="off">   
                                            </div>
                                            <div class="col-sm-3">
                                                <label> Email Address </label>
                                                <input type="text" class="form-control " name="email"  value="<?php  echo $details["email"]?>"  autocomplete="off">   
                                            </div>
                                            
                                            <div class="col-sm-3">
                                                <label> National ID Number  </label>
                                                <input type="text" class="form-control " name="krapin"  value="<?php  echo $details["client_id"]?>"  autocomplete="off">   
                                            </div>
                                            <div class="col-sm-3">
                                                <label> Address  </label>
                                                <input type="text" class="form-control " name="zrb"  value="<?php  echo $details["address"]?>"  autocomplete="off">   
                                            </div>
                                            <!-- <div class="col-sm-3">
                                                <label> Location </label>
                                                <input type="text" class="form-control " name="website"  value="<?php  echo $details["location"]?>"  autocomplete="off">   
                                            </div> -->
                                                                                 
                                </div>
                        <!-- submit button -->
                                <div class="form-group">                              
                                    <div class="col-sm-offset-4 col-sm-10" style="padding:2rem;">
                                            <button type="submit"  name="submit" class="btn btn-default col-md-3 totalbtn">  <i class="fa fa-user-plus"></i>  Edit Customer Details  </button> </div>
                                </div> 
                        </form>
                    </div>
                </div>
            </div>

        </section>
    </div>
  <!-- /.content-wrapper -->
  
    <!-- Main Footer -->
    <footer class="main-footer">
        <?php  include_once('../inc/sfooter.php'); ?>
    </footer>
  
</div>
                         


<!-- REQUIRED JS SCRIPTS -->
<?php include_once('../inc/slinkjs.php') ?>

</body>
</html>