<?php include('site-header.php'); ?>
  <!-- end of LOGO CONTAINER -->
  <!-- - - - - - - - - - - - - -->
  <!-- start of SIDEBAR        -->
  <!-- - - - - - - - - - - - - -->
  <?php include('left-nevigation.php'); ?>
  <!-- - - - - - - - - - - - - -->
  <!-- end of SIDEBAR          -->
  <!-- - - - - - - - - - - - - -->
    <script src="ckeditor/ckeditor.js"></script>  
<main id="playground">
    <!-- - - - - - - - - - - - - -->
    <!-- start of TOP NAVIGATION -->
    <!-- - - - - - - - - - - - - -->
     <?php include('site-top-header.php'); ?>
    <!-- - - - - - - - - - - - - -->
    <!-- end of TOP NAVIGATION   -->
    <!-- - - - - - - - - - - - - -->
    <!-- PAGE TITLE --> 
    <?php
extract($_POST);
$tmp = $_FILES['att']['tmp_name'];
$fn = $_FILES['att']['name'];
$ext = explode(".",$fn);
$extt = end($ext);
$fnn = rand().".$extt";
$id =$_GET['edit'];
if(isset($upd))
{
  if($extt="jpg"||$extt="png")
  {
    if(move_uploaded_file($tmp, "../product-image/$fnn"))
    {
      $que = "UPDATE  tbl_product SET pro_category='$category_name', `pro_name`='$pro_name',`pro_desc`='$about_text', `pro_image`='$fnn' WHERE pro_id=$id";
      if(mysqli_query($link,$que))
      {
        unlink("../product-image/$himage");
        $msg = "<p style='color:green;'>Save Product Successfully!!!</p>";
      }
    }
    else
    {
      $que = "UPDATE  tbl_product SET pro_category='$category_name', `pro_name`='$pro_name',`pro_desc`='$about_text'  WHERE pro_id=$id";
      if(mysqli_query($link,$que))
      {
        $msg = "<p style='color:green;'>Save Product Successfully!!!</p>";
      }
    }
  }
  else
  {
    $msg = "<p style='color:red;'>Only png Or jpg File Uploaded!!!</p>";
  }
}


?>
    <section id="page-title" class="row">
      <div class="col-md-8">
        <h1>Dashboard</h1>
        <p class="lead">Add your product below</strong>.</p>
      </div>
      <div class="col-md-4">
        <ol class="breadcrumb pull-right no-margin-bottom">
        
          <li><a href="dashboard.php">Dashboard</a></li>
          <li class="active">Add Products</li>
        </ol>
      </div>
    </section>
    <!-- / PAGE TITLE -->
    <?php
  if(isset($_GET['edit']))
  {
    $id = $_GET['edit'];
    $sel = mysqli_query($link,"select * from tbl_product where pro_id=$id");
    $arr =  mysqli_fetch_assoc($sel);
    $cat = $arr['pro_category'];
    $sel1 = mysqli_query($link,"select * from tbl_category where cat_id=$cat");
    $arr1 = mysqli_fetch_assoc($sel1);

  }
  ?>
    <section>

      <div class="container-fluid">
        <div class="">
        <a href="show-product.php" class="btn btn-primary">Back</a>
      </div>
        <div class="row">
          <form method="post" enctype="multipart/form-data">
            <div class="col-md-6">
              <div class="form-group">
                <label><?=@$msg;?></label><br>
                <label>Product Name:</label><br>
                <input class="form-control" type="text"  name="pro_name" value="<?=$arr['pro_name'];?>">
                <label>Image:</label>
                <label>Image for Category Page (Size : 840 X 520 pixels)</label>
                <img src="../product-image/<?=$arr['pro_image'];?>" width="100px" height="100px">
                <input type="hidden" value="<?=$arr['pro_image']?>" name="himage">
                <input type="file" name="att" value="<?=$arr['pro_image']?>">
              </div>
            </div>
            <div class="col-md-6">
              <div class="form-group">
                <label>product Category:</label>
                <select class="form-control" name="category_name">
                  <option value="<?=$arr1['cat_id'];?>"><?=$arr1['cate_name'];?></option>
                  <?php
                  $sel2 =mysqli_query($link,"select * from tbl_category");
                  while($arr2 = mysqli_fetch_assoc($sel2))
                  {
                  ?>
                  
                  <option value="<?=$arr2['cat_id'];?>"><?=$arr2['cate_name'];?></option>
                  <?php
                  }
                  ?>
                </select>
              </div>
            </div>
            <div class="col-md-12">
              <div class="form-group">

                <label>Description Here</label><br>
                <textarea class="form-control" id="ckeditor1" name="about_text" style="width:100%"><?=$arr['pro_desc'];?></textarea>
              </div>
            </div>
            <div class="col-md-5">    
            </div>
            <div class="col-md-2">

              <div class="form-group">
                <input class="btn btn-primary text-center" type="submit" name="upd" value="SUBMIT">
              </div>
            </div>
            <div class="col-md-5">
            </div>

          </form>
        </div>
      </div>
    </section>

  <script> CKEDITOR.replace(ckeditor1)</script>
  <script src="ckeditor/ckeditor.js">
    
  </script>

    
    <!-- / container-fluid -->
 <?php include('site-footer.php'); ?>