<?php include("includes/header.php");

	require("includes/function.php");
	require("language/language.php");

	
 
	$qry="SELECT * FROM tbl_category";
	$result=mysqli_query($mysqli,$qry);
	
	if(isset($_GET['cat_id']))
	{

		$img_res=mysqli_query($mysqli,'SELECT * FROM tbl_wallpaper WHERE cat_id=\''.$_GET['cat_id'].'\'');
    $img_res_row=mysqli_fetch_assoc($img_res);

    if($img_res_row['image']!="")
      {
        unlink('images/'.$img_res_row['image']);
        unlink('images/thumbs/'.$img_res_row['image']);
      }
 
    Delete('tbl_wallpaper','cat_id='.$_GET['cat_id'].'');
		

		$cat_res=mysqli_query($mysqli,'SELECT * FROM tbl_category WHERE cid=\''.$_GET['cat_id'].'\'');
		$cat_res_row=mysqli_fetch_assoc($cat_res);


		if($cat_res_row['category_image']!="")
	    {
	    	unlink('images/'.$cat_res_row['category_image']);
			  unlink('images/thumbs/'.$cat_res_row['category_image']);

		}
 
		Delete('tbl_category','cid='.$_GET['cat_id'].'');

      
		$_SESSION['msg']="12";
		header( "Location:category.php");
		exit;
		
	}	
	 
?>
                
    <div class="row">
      <div class="col-xs-12">
      <style>.add_btn_primary2 {
    float: right;
}
.add_btn_primary2 a {
    background-color: #1782de;
    box-shadow: 0 2px 3px rgba(9, 80, 119, 0.3);
    border: 2px solid #02006826;
    cursor: pointer;
    display: inline-block;
    font-size: 14px;
    text-align: center;
    vertical-align: middle;
    white-space: nowrap;
    border-radius: 10px;
    border-style: 1px solid;
    margin-bottom: 7px;
    transition: all 0.3s ease 0s;
    padding: 10px 30px;
    color: #ffffff;
}
.table-striped .category_img img {
    padding: 0px;
    width: 50px;
    border: 1px solid #ddd;
    height: 50px;
}

</style>
      <div class="add_btn_primary2"> <a href="add_category.php?add=yes">Add Category</a> </div>
        <div class="card mrg_bottom">
        <div class="page_title">Categories</div>
          <div class="row mrg-top">
            <div class="col-md-12">
               
              <div class="col-md-12 col-sm-12">
                <?php if(isset($_SESSION['msg'])){?> 
               	 <div class="alert alert-success alert-dismissible" role="alert"> <button type="button" class="close" data-dismiss="alert" aria-label="Close"><span aria-hidden="true">×</span></button>
                	<?php echo $client_lang[$_SESSION['msg']] ; ?></a> </div>
                <?php unset($_SESSION['msg']);}?>	
              </div>
            </div>
          </div>
          <div class="col-md-12 mrg-top">
            <table class="table table-striped table-bordered table-hover">
              <thead>
                <tr>                  
                  <th>Category Image</th>
                  <th>Category</th>
                  <th class="cat_action_list">Action</th>
                </tr>
              </thead>
              <tbody>
              	<?php	
						$i=0;
						while($row=mysqli_fetch_array($result))
						{					
				?>
               <style>
          a.btn1 {
          margin-right: 20px;
          color: #2196F3;
          }
          .btn1:hover {
            margin-right: 20px;
          color: #fa0000;
          }
        </style>
        <style>
          a.btn2 {
          margin-right: 20px;
          color: #fa0000;
          }
          .btn2:hover {
            margin-right: 20px;
          color: #2196F3;
          }

          h5.text {
    color: #1782de;
}
        </style>
                <tr>                 
                  <td><span class="category_img"><img src="images/thumbs/<?php echo $row['category_image'];?>" /></span></td>
                  <td><?php echo $row['category_name'];?></td>
                  <td><a href="add_category.php?cat_id=<?php echo $row['cid'];?>" class="btn1">Edit</a>
                    <a href="?cat_id=<?php echo $row['cid'];?>" class="btn2" onclick="return confirm('Are you sure you want to delete this category and related wallpaper?');">Delete</a></td>
                </tr>
                <?php
						
						$i++;
				     	}
				?> 
              </tbody>
            </table>
          </div>
           
          <div class="clearfix"></div>
        </div>
      </div>
    </div>
        
<?php include("includes/footer.php");?>       
