<?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($extt=="jpg"||$extt=="png")

     {

         $category_name = ucwords(strtolower($_POST['category_name']));

        if(mysqli_query($link,"UPDATE `tbl_category` SET `cate_name`='$category_name',`category_image`='$fnn',cate_desc='$about_text' WHERE cat_id=$id"))

        {

         move_uploaded_file($tmp,"../uploaded/$fnn");

         unlink("../uploaded/$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',cate_desc='$about_text' 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);

   

   }

   

   

   ?>

<section id="page-title" class="row">

   <div class="col-md-8">

      <h1>Dashboard</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">Dashboard</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="">Product 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 :277 X 190 pixels)</label>

          <input type="hidden" name="himage" value="<?=$arr['category_image'];?>">

          <img src="../uploaded/<?=$arr['category_image'];?>" width="100px" height="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>

<script>

   CKEDITOR.replace(ckeditor1)  

</script>

<!-- / container-fluid -->

<?php include('site-footer.php'); ?>