<? include_once("../includes/cmain.inc.php");
$headerTitleName = "Add New Blog";
if(isset($_REQUEST['action']) && $_REQUEST['action']=='delete'){
     $page_id=$_REQUEST['page_id'];
	 $sql3 = "delete from `tbl_blogcatp` where id in ($page_id)";
	 db_query($sql3);
	 set_session_msg("Blog Category Data have been deleted successfully");
	 header("Location: ".$_SERVER['HTTP_REFERER']);
	 exit;
}


$page_id = $_REQUEST['page_id'] ?? '';
$id = '1';
if(is_post_back()) {
   // print_r($_POST['catP_Name']);exit();
	if($page_id!='') {		 		
		$sql = "update `tbl_blogcatp` set catP_Name='".addslashes(ucfirst($catP_Name))."', status='".addslashes($status)."' where id = $page_id";
		db_query($sql);
		set_session_msg("blog popular category updated successfully.");	
	    header("Location: blog_cat.php");
	} else{	
	$check = db_query("SELECT * FROM tbl_blogcatp WHERE catP_Name ='".$_POST['catP_Name']."'" );
	if(mysqli_num_rows($check) >0){
		set_session_msg("Already Exist Data!");
	}else{
	   if(isset($_POST['catP_Name']) !=""){
		$sql = "insert into `tbl_blogcatp` set catP_Name='".addslashes(ucfirst($_POST['catP_Name']))."', status='".addslashes($_POST['status'])."'";
		db_query($sql);
		set_session_msg("New blog popular category created successfully.");
		
	   }else{
		 set_session_msg("There Should be any category name !");
	   }
	   header("Location: blog_cat.php");
	   exit;
	}
	}
}

if($page_id!='') {
	$sql = "select * from `tbl_blogcatp` where id = '$page_id'";
	$results = db_query($sql);
	if ($line_raw = mysqli_fetch_array($results)) {
		
		@extract($line_raw);
	}
}
?>
<link href="styles.css" rel="stylesheet" type="text/css">
<? include("top.inc.php");?>
<table width="100%" border="0" cellspacing="0" cellpadding="0">
  <tr> <td id="pageHead"><div id="txtPageHead">Add/Edit - Blog Categaries</div></td></tr>
</table>
<script type="text/javascript" src="fckeditor/fckeditor.js"></script>
<table width="100%" border="0" cellspacing="0" cellpadding="0">
   <tr><td height="15"><div align="center"><span class="msg"><?=display_sess_msg();?></span></div><br /></td></tr>
   <tr><td  colspan="2" height="30" align="right" style="padding-right:20px"><a href="blog_list.php" class="redcolor"><strong>Back To Blog List</strong></a></td>
  </tr>      
</table>
<table width="50%" align="left">
    <tr><td>
	<form method="post" enctype="multipart/form-data" name="form1" id="form1" onSubmit="return validate(this);">
     <table width="80%" align="center" border=0 cellpadding="0"  cellspacing="0" class="text">
    	 
     
    
       
        <tr>
		  <td class="lables"><b>Popular Category</b></td>
          <td class="feildstxt"><input type="text" style="width:300px;" value="<?=stripslashes($catP_Name ?? '')?>" name="catP_Name" id="catP_Name"/></td>
        </tr>
        
		<tr><td>&nbsp;</td></tr>
		<tr>
		  <td class="lables"><b>Status</b></td>
          <td class="feildstxt"><select name="status" id="status">
          <option value="1" <?php if(isset($status)=='1'){ echo 'selected="selected"'; } ?>>Active</option>
          <option value="0" <?php if(isset($status)=='0'){ echo 'selected="selected"'; } ?>>InActive</option>          
          </select></td>
        </tr>
        <tr><td>&nbsp;</td></tr>
      
        <tr>
        <td align="left" class="lables">&nbsp;</td>
        <td align="left" class="feildstxt"><input class="button" type="submit" name="submit" value="Save"></td>
        </tr>
        <tr><td height="25">&nbsp;</td></tr>
    </table>
    </form>
    </td>
	</tr>
</table>  
<table width="50%" align="left">
</table>
 
<?php 
$start = isset($start) ? intval($start) : 0;
$pagesize = isset($pagesize) ?intval($pagesize) :100;
$columns = "select * ";
$sql = " from `tbl_blogcatp` ";
$sql .= " where 1 ";
//$order_by == '' ? $order_by = '`tbl_blogcatp`.id' : true;
//$order_by2 == '' ? $order_by2 = 'DESC' : true;
$sql_count = "select count(*) ".$sql; 
$sql .= "order by id DESC ";
$sql .= "limit $start, $pagesize ";
$sql = $columns.$sql;
$result = db_query($sql);
$reccnt = db_scalar($sql_count);
?>
<table width="100%" border="0" cellspacing="0" cellpadding="0">
  <tr> <td id="pageHead"><div id="txtPageHead">List - Blog Categaries</div></td></tr>
</table>
<table width="100%" border="0" cellspacing="0" cellpadding="0">
  <tr>
    <td id="content">
      <? if(mysqli_num_rows($result)==0){?>
      <div class="msg">Sorry, no records found.</div>
      <? } else{ ?>
      <div align="right"> Showing Records: <?= $start+1?> to   <?=($reccnt<$start+$pagesize)?($reccnt-$start):($start+$pagesize)?>    of   <?=$reccnt?> </div>
      <form method="post" name="form1" id="form1" onSubmit="confirm_submit(this)">
        <table width="100%"  border="0" cellpadding="0" cellspacing="1" class="tableList">
          <tr>
          <th align="center" width="5%">SL</th>
          <th align="left" width="20%" style="padding-left:10px;">Category Name</th>
          <th align="center" width="8%">Status</th>
          <th align="center" width="8%">Edit</th>
          <th align="center" width="5%">Delete</th>
          </tr>
      <? 
		if($start==0){
			$cnt=0;
		}
		else{
			$cnt=$start;
		}
		while ($line_raw = mysqli_fetch_array($result)) {
			$cnt++;
		$line = ms_display_value($line_raw);
		@extract($line);
	//	$css = ($css=='trOdd')?'trEven':'trOdd';
		$css=isset($css) ? (($css=='trOdd')?'trEven':'trOdd'): 'trOdd';
	   ?>

<tr class="<?=$css?>">
<td  valign="top" align="center"><?=stripslashes($id)?></td>
<td align="left" valign="middle" style="padding-left:10px;"><?=stripslashes($catP_Name)?></td>
<td align="center" valign="middle"><?php if($status=='1'){ echo 'Active'; }else{ echo '<span style="color:red;">InActive</span>'; } ?></td>
<td align="center" valign="top"><a href="blog_cat.php?page_id=<?=$id?>&start=<?=$start?>"><img src="images/icons/edit.png" alt="Edit" width="16" height="16" border="0" /></a></td>
<td align="center" valign="top"><a href="blog_cat.php?page_id=<?=$id?>&start=<?=$start?>&action=delete" onclick="return stdel_confirm();"><img src="images/icons/trash-20.png" alt="Edit" width="16" height="16" border="0" /></a></td>
</tr>
<? }?>        
</table>
 </form>
<? }?>
<? include("paging.inc.php");?>    </td>
</tr>
</table> 
<script>
function stdel_confirm(){  return confirm("Are you sure want to delete?"); }
</script>
<? include("bottom.inc.php");?>