<?php
ob_start();
session_start();
ini_set('display_errors', 1);
 require('../includes/cmain.inc.php');
if($_SESSION['logged_in'] != true) {
header("Location: index.php");
    exit();	
	  }
	if($_REQUEST['action']=='edit'){
		  $id=$_GET['id'];
		  $listQuery="SELECT * FROM tbl_blogcatp WHERE id='".$id."'";
	      $result=mysqli_query($conn,$listQuery);
	      $row=mysqli_fetch_assoc($result);
		  //print_r($row);exit();
		}
	if($_POST['Update']){
	$id=$_POST['id'];
	$catPName=ucwords($_POST['cat_name']);
	$status=$_POST['status'];
	$blogQuery= "update `tbl_blogcatp` set catP_Name='".addslashes($catPName)."', status='".addslashes($status)."' where id = '$id' ";
	//print_r($blogQuery);exit();
	$result=mysqli_query($conn,$blogQuery);
	//print_r($result);exit();
	header("Location: blog_cat.php");
	exit;
	}
     if($_POST['Add']){
	
	$catPName=ucwords($_POST['cat_name']);
	$status=$_POST['status'];
	$blogQuery= "INSERT INTO  tbl_blogcatp(catP_Name,status) VALUES('$catPName','$status')" ;
	//print_r($blogQuery);exit();
	$result=mysqli_query($conn,$blogQuery);
	//print_r($result);exit();
	header("Location: blog_cat.php");
	exit;
}
ob_end_flush();
?>

<!DOCTYPE html>
<html lang="en">
<head>
<title>Welcome Admin</title>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
  
<style>
.ck-editor__editable {
    height: 350px;
    width: 600px;
}
* {
  box-sizing: border-box;
}

body {
  font-family: Arial, Helvetica, sans-serif;
}

/* Style the header */
header {
  background-color: #888888;
  padding: 30px;
  text-align: center;
  font-size: 20px;
  color: white;
}

/* Create two columns/boxes that floats next to each other */
nav {
  float: left;
  width: 20%;
  height: 500px; /* only for demonstration, should be removed */
  background-color:#DCDCDC;
  padding: 20px;
}

/* Style the list inside the menu */
nav ul {
  list-style-type: none;
  padding: 0;
}

article {
  float: left;
  padding: 20px;
  width: 80%;
  font-size:10px;
  
  height: 500px; /* only for demonstration, should be removed */
}

/* Clear floats after the columns */
section::after {
  content: "";
  display: table;
  clear: both;
}

/* Style the footer */
footer {
  
  padding: 10px;
  text-align: center;
  color: white;
}


/* Responsive layout - makes the two columns/boxes stack on top of each other instead of next to each other, on small screens */
@media (max-width: 600px) {
  nav, article {
    width: 100%;
    height: auto;
  }
}
</style>

</head>
<body>

<header>
  <h2>Welcome Admin</h2>
</header>

<section>
  <nav>
    <ul>
       <li><a href="welcome.php">Home</a></li>
      <li><a href="service_list.php">Service List</a></li>
      <li><a href="logout.php">Logout</a></li>
    </ul>
  </nav>

  <article>
    <h1>Add/Edit Category</h1><h3>
	<form action="" method="POST" enctype="multipart/form-data">
	<div style="text-align:right"><a href="blog_cat.php" align="right">Back to Category List</a></div>
    <script type="text/javascript" src="ckeditor5-build-classic/ckeditor.js"></script>
	
	<table width="100%">
	<tr><td>Category Name:</td><td><input type="text" name="cat_name" style="width:240px" value="<?php echo isset($_GET['id'])? $row['catP_Name']:''; ?>" /></td></tr>
	<tr><td>Status:</td><td>
	<select id="status" name="status" style="width:240px">
           <option value="1" <?php echo $status == '1' ? 'selected' : ''; ?>>Active</option>
           <option value="0" <?php echo $status == '0' ? 'selected' : ''; ?>>Inactive</option>
    </select></td></tr>

        <tr><td>&nbsp;</td></tr>
	<input type="hidden" name="id" value="<?php echo isset($_GET['id'])? $_GET['id']:" "; ?>">
	<tr><td></td><td><input type="submit" name="<?php echo isset($_GET['id'])? 'Update':'Add'; ?>" value="<?php echo isset($_GET['id'])? "Update":"Save"; ?>" id=""/></td></tr>
	</table>
	
	</form>
    
  </article>
</section>

<script>
var submitButton = document.querySelector("#submit-button");

// Add a click event listener to the submit button
submitButton.addEventListener("click", function(event) {
    // Disable the submit button
    this.disabled = true;

    // Perform form submission or any other logic here
});
</script>

<footer>
  <p></p>
</footer>

</body>
</html>

