<?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($sub))
   { 
     if($_FILES['att']['name']!="")
     {
         $category_name = ucwords(strtolower($_POST['category_name']));
        if(mysqli_query($link,"UPDATE `tbl_category` SET `cate_name`='$category_name',category_image='$fnn' WHERE cat_id=$id"))
        {
         move_uploaded_file($tmp,"../category-image/$fnn");
         unlink("../category-image/$himage");
         $msg = "<p style='color:green;'>Category Update!!!!</p>";
        }
        else
        {
         $msg = "<p style='color:red;'>Category Not Save Try Again!!!!</p>";
        }
     }
     else
     {
        $category_name = ucwords(strtolower($_POST['category_name']));
       if(mysqli_query($link,"UPDATE `tbl_category` SET `cate_name`='$category_name' WHERE cat_id=$id"))
        {
         move_uploaded_file($tmp,"../uploaded/$fnn");
         $msg = "<p style='color:green;'>Category Update!!!!</p>";
        }
     }
    
   }
   ?>
<?php
   if(isset($_GET['edit']))
   {
     $id = $_GET['edit'];
     $sel = mysqli_query($link,"select * from tbl_category where cat_id=$id");
     $arr =  mysqli_fetch_assoc($sel);
   }
   ?>
   <div class="container-fluid textsss">
<section id="page-title" class="row">
   <div class="col-md-8">
      <h1>Category</h1>
      <p class="lead">Update your Category below</strong>.</p>
   </div>
   <div class="col-md-4">
      <!-- <ol class="breadcrumb pull-right no-margin-bottom">
         <li><a href="dashboard.php">Category</a></li>
         <li class="active">Add Category</li>
      </ol> -->
   </div>
</section>
<!-- / PAGE TITLE -->
<div class="container-fluid">
  <form method="post" enctype="multipart/form-data">
   <div class="row">
      <div class="col-md-12">
        <a href="update-category.php" class="btn btn-primary">Back</a>
      </div>
      <div class="col-md-6">
        <div class="form-group">
          <label class="text-danger"><?=$msg;?></label><br>
          <label for="">Services Category</label>
          <input type="text" class="form-control" name="category_name" value="<?=$arr['cate_name']?>" placeholder="Enter Your Category Name">
        </div>
        <div class="form-group" align="left">
          <label for="">Image for Category Page (Size : 160 X 160 pixels)</label>
          <input type="hidden" name="himage" value="<?=$arr['category_image'];?>">
          <img src="../category-image/<?=$arr['category_image'];?>" style="margin-bottom: 27px; height: 100px; width: 100px;">
          <input type="file" class="form-control" name="att" placeholder="Enter Your Category Image" >
        </div> 
      </div>
       <!-- <div class="col-md-12">
        <div class="form-group">
          <textarea class="form-control" id="ckeditor1" name="about_text"><?=$arr['cate_desc']?></textarea>
        </div>
      </div> --> 
      <div class="col-md-12">
        <div class="form-group">
          <input type="submit" class="btn btn-primary" name="sub" value="SUBMIT">
        </div>
      </div>
   </div>
   </form>
</div>
</div>
<script>
   CKEDITOR.replace(ckeditor1)  
</script>
<!-- / container-fluid -->
<?php include('site-footer.php'); ?>