<?php
include_once("../include/main.inc.php");
check_session('MyCpanel','index.php');

################ Paging Starts From Here ##################
@extract($_REQUEST);
$start = (intval($start)==0 or $start=="")?$start=0:$start;
$pagesize = intval($pagesize)==0?$pagesize=20:$pagesize;

$heading="Manage Meta Details";
$record_type="Meta Details";
$script_name="manage_meta_tags.php";
$table_name="meta_tags_tbl";
####################################################

if($id=="add_record" && $pageName!="") {
	$numCnt=getCount($table_name," where pageName='$pageName'");
	if ($numCnt > 0) {
		$_SESSION[session_message]=$record_type.' already exist';
	}
	else {
		$sql=mysql_query("insert into $table_name (pageName, pageTitle, pageKeywords, pageDescription)values('$pageName', '$pageTitle', '$pageKeywords', '$pageDescription')");
		$_SESSION[session_message]='New '.$record_type.' successfully added';
	}
	header("Location: ".SITE_ADMIN_URL."/".$script_name."?start=".$start."&pagesize=".$pagesize);
	exit;	
}

if($id=="update_record" && $pageName!="") {
	updateTable($table_name," pageName='$pageName', pageTitle='$pageTitle', pageKeywords='$pageKeywords', pageDescription='$pageDescription' where slno='$recordID'");
	$_SESSION[session_message]=$record_type.' has been updated successfully';
	header("Location: ".SITE_ADMIN_URL."/".$script_name."?start=".$start."&pagesize=".$pagesize);
	exit;	
}

if ($action=="Activate") {
	if(sizeof($cid)==0) {
		$_SESSION[session_message]='Please select some record(s) first.';
		header("Location: ".SITE_ADMIN_URL."/".$script_name."?start=".$start."&pagesize=".$pagesize);
		exit;
	}
	for ($x=0; $x < sizeof($cid); $x++) {
		updateTable($table_name," status='Y' where slno='$cid[$x]'");		
	}
	$_SESSION[session_message]='Selected record(s) activated successfully.';
	header("Location: ".SITE_ADMIN_URL."/".$script_name."?start=".$start."&pagesize=".$pagesize);
	exit;
}

if ($action=="Deactivate") {
	if(sizeof($cid)==0) {
		$_SESSION[session_message]='Please select some record(s) first.';
		header("Location: ".SITE_ADMIN_URL."/".$script_name."?start=".$start."&pagesize=".$pagesize);
		exit;
	}
	for ($x=0; $x < sizeof($cid); $x++) {
		updateTable($table_name," status='N' where slno='$cid[$x]'");
	}
	$_SESSION[session_message]='Selected record(s) deactivated successfully.';
	header("Location: ".SITE_ADMIN_URL."/".$script_name."?start=".$start."&pagesize=".$pagesize);
	exit;
}

if($action=="Delete") {
	if(sizeof($cid)==0) {
		$_SESSION[session_message]='Please select some record(s) first.';
		header("Location: ".SITE_ADMIN_URL."/".$script_name."?start=".$start."&pagesize=".$pagesize);
		exit;
	}
	for ($x=0; $x < sizeof($cid); $x++) {
		db_query("delete from $table_name where slno='$cid[$x]'");
	}
	$_SESSION[session_message]='Selected record(s) deactivated successfully.';
	header("Location: ".SITE_ADMIN_URL."/".$script_name."?start=".$start."&pagesize=".$pagesize);
	exit;	
}

if($id=="delete_record") {
	db_query("delete from $table_name where slno='$recordID'");
	$_SESSION[session_message]=$record_type.' has been deleted successfully';
	header("Location: ".SITE_ADMIN_URL."/".$script_name."?start=$start&pagesize=$pagesize");
	exit;
}

admin_header();
?>
<table width="99%" border="0" align="center" cellpadding="0" cellspacing="0" valign="top">
 <tr>
	<td align="left" width="50%" class="myTitle"><?=$heading;?></td>
	<td align="right">
	 <form name="pgimg_form" action="<?=$PHP_SELF?>" method="post" style="margin:0px;padding:0px;">
	 <table width="98%" border="0" align="center" cellpadding="0" cellspacing="0" valign="top">
	  <tr>
	   <td align="right">Records Per Page:
	    <select name="pagesize" onchange="this.form.submit();">
	     <option value="0">Select</option>
	     <?php
	     foreach($_GLOBALS[pgsize_arr] as $val) {
		     if(trim($pagesize)==trim($val)) {
			     echo '<option value="'.$val.'" selected>'.$val.'</option>';
		     }
		     else{
			     echo '<option value="'.$val.'">'.$val.'</option>';
		     }
	     }
	     ?>
	    </select>
	    <?php
	    if (strlen($keyword)) {
		    ?>
		    <input type="hidden" name="keyword" value="<?=$keyword;?>">
		    <?php
	    }
	    ?>
		 </td>
		</tr>
	 </table>
	 </form>
	</td>
 </tr>
</table>
<hr size="2" width="99%" color="#DA251C">

<?php
$cond="";
if (strlen($keyword)) {
	?>
	<br/>
	<div style="width:99%;">
	 <div style="float:left;"><strong>Search For :</strong> <?=$keyword;?></div>
	 <div style="float:right;"><a href="javascript:history.go(-1);"><strong>Go Back</strong></a></div>
	</div> 
	<?php
	$cond=" and (pageName like '%$keyword%' or pageTitle like '%$keyword%' or pageKeywords like '%$keyword%' or pageDescription like '%$keyword%')";
}
$qry1= db_query("select * from $table_name where 1 $cond");
$reccnt = NumRows($qry1);
$qry= db_query("select * from $table_name where 1 $cond order by slno desc limit $start, $pagesize");
echo pageNavigation($reccnt,$pagesize,$start);
print_message();
?>

<form name="srch" method="post" action="" style="display:inline" enctype="multipart/form-data">
<table width="100%"  border="0" cellpadding="0" cellspacing="2" class="lightBorder">
 <tr>
  <td align="right"><b>Search </b> [by Script Name, Page Title, Page Keyword, Page Description etc.] :-
   <input type="text" name="keyword" value="" size="40">
   <input type="submit" class="button" value="GO">
   <input type="hidden" name="start" value="<?=$start;?>">
   <input type="hidden" name="pagesize" value="<?=$pagesize;?>">
  </td>
 </tr>   
</table>
</form><br/>

<form name="formn" method="post" action="" enctype="multipart/form-data" onsubmit="return validate(this);">
<table width="99%" border="0" cellpadding="2" cellspacing="2" class="lightBorder">
 <?php
 if($reccnt>0) {
	 ?>
	 <tr height="25" bgcolor="#EAEAEA">
	  <td width="5%" class="PadFive" align="center"><strong>S.No.</strong></td>
	  <td class="PadFive" width="20%" align="left"><strong>Page Name</strong></td>
	  <td class="PadFive" width="65%" align="left"><strong>Meta Details</strong></td>	  
	  <td class="PadFive" width="10%" align="center"><strong>Options</strong></td>
	 </tr>
	 <?php
	 $sl=$start+1;
	 while($arr=mysql_fetch_array($qry)) {
		 $arr=ms_htmlentities_decode($arr);
		 if($sl%2!=0) {
			 $color="#f0f0f0";
		 }
		 else{
			 $color="#f9f9f9";
		 }
		 if ($arr[status]=="Y") {
			 $status="Active";
		 }
		 else {
			 $status="Inactive";
		 }
		 ?>		 
		 <tr bgcolor="<?=$color;?>">
		  <td align="center" valign="top"> <!-- <input type="checkbox" name="cid[]" value="<?=$arr[slno]; ?>" class="NoStyle"> !--> <strong><?=$sl;?>.</strong></td>
		  <td align="left" valign="top"><?=$arr[pageName];?></td>
		  <td align="left" valign="top"><strong>Page Title : </strong><? echo $arr[pageTitle];
		   if (strlen($arr[pageDescription])) {
			   ?>
			   <br><strong>Page Description : </strong><?=$arr[pageDescription];?>
			   <?php
		   }
		   if (strlen($arr[pageKeywords])) {
			   ?>
			   <br><strong>Page Keywords : </strong><?=$arr[pageKeywords];?>
			   <?php
		   }
		   ?>
		  </td>
		  <td align="center" valign="top">
		   <a href="<?=$script_name;?>?id=edit_record&start=<?=$start;?>&recordID=<?=$arr[slno];?>&pagesize=<?=$pagesize?>#bot"><img src="<?=SITE_ADMIN_URL?>/images/edit.gif" alt="Edit This <?=$record_type;?>" title="Edit This <?=$record_type;?>" border="0"></a>
		   <?php
		   if ($arr[pageName]!="default") {
			   ?>
			   &nbsp;<a href="<?=$script_name;?>?id=delete_record&start=<?=$start;?>&recordID=<?=$arr[slno];?>&pagesize=<?=$pagesize?>" onClick="return confirm('Are you sure to delete this record...');"><img src="<?=SITE_ADMIN_URL?>/images/cancel.gif" alt="Delete This <?=$record_type;?>" border="0">
			   <?php
		   }
		   ?>
		  </td>
		 </tr>
		 <?php
		 $sl++;
	 }
	 ?>
	 <!--
	 <tr><td colspan=5 bgcolor="#EAEAEA" valign="top" height="20"></td></tr>
	 <tr>
	  <td colspan=5 colspan=4 bgcolor="#EAEAEA" valign="top">
	   <input type="submit"  class="button" name="action" value="Delete"  onclick="return chkdelete();">
	   <input type="hidden" name="start" value="<?=$start;?>">
	   <input type="hidden" name="pagesize" value="<?=$pagesize;?>">
	  </td>
	 </tr>
	 !-->
	 <?php
 }
 else{
	echo '<tr><td><b>No Record Found........</b></td></tr>';	
 }
 ?>
</table></form><br />
<table width="96%" align="center" cellpadding="0" cellspacing="0" border="0">
 <tr><td align="right"><input type="button" onclick="window.location.href='<?=SITE_ADMIN_URL;?>/<?=$script_name;?>?id=add_new#bot'" value="Add New <?=$record_type;?>" class="button"></td></tr>
</table>

<?php
if ($id == "add_new" || $id == "edit_record") {
	?>
	<a name="bot"></a>
	<br/><br/>
	<form name="memberFrm" method=post action="<?=$script_name;?>" enctype="multipart/form-data" onsubmit="return validate(this);">
	<table width="99%"  border="0" cellpadding="2" cellspacing="2" class="lightBorder">
	 <?php
	 if($recordID=="" || $id!="edit_record") {
		 ?>
		 <tr bgcolor="#EAEAEA"><td colspan="2" align="left" class="PadFive" height="20"><b><a name="bot">Add New <?=$record_type;?></a></b></td></tr>
		 <?php
	 }
	 else {
		 ?>
		 <tr bgcolor="#EAEAEA">
		  <td align="left" class="PadFive" height="20"><b>Edit <?=$record_type;?></b></td>
		  <td align="right" class="PadFive" height="20"><a href="<?=$script_name;?>"><b>Add New <?=$record_type;?></b></a></td>
		 </tr>
		 <?php
	 }
	 $res=getResult($table_name," where slno='$_GET[recordID]'");
	 @extract($res);
	 ?>
	 <tr bgcolor="#f9f9f9">
	  <td class="brdrbtm" valign="top" width="15%"><b>Page Name *</b></td>  
	  <td class="brdrbtm"><input type="text" name="pageName" size="80" value="<?=$pageName;?>" id="NOBLANK~Please enter page name.~DM~" /><br><strong>Please enter page name without extension ie. index, about_us, contact_us etc</strong></td>
	 </tr> 
	 <tr bgcolor="#f0f0f0">
	  <td class="brdrbtm" valign="top"><b>Page Title *</b></td>
	  <td class="brdrbtm"><textarea name="pageTitle" cols="120" rows="3" id="NOBLANK~Please enter page title.~DM~"><?=$pageTitle;?></textarea></td>
	 </tr>
	 <tr bgcolor="#f0f0f0">
	  <td class="brdrbtm" valign="top"><b>Page Description</b></td>
	  <td class="brdrbtm"><textarea name="pageDescription" cols="120" rows="7" id1="NOBLANK~Please enter page description.~DM~"><?=$pageDescription;?></textarea></td>
	 </tr>
	 <tr bgcolor="#f0f0f0">
	  <td class="brdrbtm" valign="top"><b>Page Keywords</b></td>
	  <td class="brdrbtm"><textarea name="pageKeywords" cols="120" rows="7" id1="NOBLANK~Please enter page keywords.~DM~"><?=$pageKeywords;?></textarea></td>
	 </tr>
	 <tr bgcolor="#f9f9f9">
	  <td class="brdrbtm"></td>
	  <td class="brdrbtm">
	   <?php
	   if($recordID!="") {
		   ?>
		   <input type="submit" name="submit" value="Update <?=$record_type;?>" class="button">
		   <input type="hidden" name="recordID" value="<?=$slno;?>">
		   <input type="hidden" name="id" value="update_record">
		   <?php	   
	   }
	   else{
		   ?>
		   <input type="submit" name="submit" value="Add New <?=$record_type;?>" class="button" onclick="return chk_regDate();">
		   <input type="hidden" name="id" value="add_record">
		   <?php
	   }
	   ?>
	   <input type="hidden" name="start" value="<?=$start;?>">
	   <input type="hidden" name="pagesize" value="<?=$pagesize;?>">
	  </td>
	 </tr> 
	</table>
	</form>
	<?php
}

admin_footer();
exit;
?>