<?php
global $wpdb,$custom_post_meta_db_table_name;
//$srch_arr = array(' ',"'",'"','/','*','&','!','`','=','(',')','%','$','#','@','^','+');
//$rplc_arr = array('_','','','','','','','','','','','','','','','','');
//str_replace($srch_arr,$rplc_arr,$admin_title),
if($_REQUEST['act']=='del')
{
	$cid = $_REQUEST['cid'];
	$wpdb->query("delete from $custom_post_meta_db_table_name where cid=\"$cid\"");
	$url = get_option('siteurl').'/wp-admin/admin.php';
	echo '<form action="'.$url.'" method="get" id="frm_bulk_upload" name="frm_bulk_upload">
	<input type="hidden" value="custom" name="page"><input type="hidden" value="act" name="del"><input type="hidden" value="msg" name="delsuccess">
	</form>
	<script>document.frm_bulk_upload.submit();</script>
	';exit;	
}elseif($_REQUEST['act']=='edit')
{
	include_once(TEMPLATEPATH . '/admin/admin_manage_custom_fields_edit.php');
	exit;	
}
?>
<script>
function confirm_delete(c_id)
{
	if(!confirm('<?php _e('Are you sure, want to delete this information?');?>'))
	{
		return false;
	}else
	{
		window.location.href="<?php echo get_option('siteurl');?>/wp-admin/admin.php?page=custom&act=del&cid="+c_id;	
	}
}
</script>
<style>
h2 {
	color:#464646;
	font-family:Georgia, "Times New Roman", "Bitstream Charter", Times, serif;
	font-size:24px;
	font-size-adjust:none;
	font-stretch:normal;
	font-style:italic;
	font-variant:normal;
	font-weight:normal;
	line-height:35px;
	margin:0;
	padding:14px 15px 3px 0;
	text-shadow:0 1px 0 #FFFFFF;
}
</style>
<h2><?php _e('Manage Post Custom Fields')?></h2>
<?php if($message){?>
<div class="updated fade below-h2" id="message" style="background-color: rgb(255, 251, 204);" >
  <p><?php _e($message);?> </p>
</div>
<?php }?>
<table width="100%"  class="widefat post fixed" >
  <thead>
    <tr>
      <th width="150"><strong><?php _e('Admin Title');?></strong></th>
      <th width="150"><strong><?php _e('Front Title');?></strong></th>
      <th width="100" align="center"><strong><?php _e('Type');?></strong></th>
      <th width="150" align="center"><strong><?php _e('HTML Variable Name');?></strong></th>
      <th width="150" align="center"><strong><?php _e('Default Value');?></strong></th>
      <th width="100" align="center"><strong><?php _e('Display Order');?></strong></th>
      <th width="85" align="center"><strong><?php _e('Is Active');?></strong></th>
      <th width="85" align="center"><strong><?php _e('On List');?></strong></th>
      <th width="85" align="center"><strong><?php _e('On Detail');?></strong></th>
      <th><?php _e('Action');?></th>
    </tr>
<?php
$post_meta_info = $wpdb->get_results("select * from $custom_post_meta_db_table_name");
if($post_meta_info){
	foreach($post_meta_info as $post_meta_info_obj){
	?>
     <tr>
      <td><?php echo $post_meta_info_obj->admin_title;?></td>
      <td><?php echo $post_meta_info_obj->site_title;?></td>
      <td><?php echo $post_meta_info_obj->ctype;?></td>
      <td><?php echo $post_meta_info_obj->htmlvar_name;?></td>
      <td><?php echo $post_meta_info_obj->default_value;?></td>
      <td><?php echo $post_meta_info_obj->sort_order;?></td>
      <td><?php echo $post_meta_info_obj->is_active;?></td>
      <td><?php echo $post_meta_info_obj->show_on_listing;?></td>
      <td><?php echo $post_meta_info_obj->show_on_detail;?></td>
      <td>
	  <a href="<?php echo get_option('siteurl');?>/wp-admin/admin.php?page=custom&act=edit&cid=<?php echo $post_meta_info_obj->cid;?>"><?php _e('Edit');?></a> | 
	  <a href="javascript:void(0);" onclick="return confirm_delete('<?php echo $post_meta_info_obj->cid;?>');"><?php _e('Delete');?></a>
      </td>
      </tr>
    <?php	
	}
}else
{
?>
     <tr><td colspan="10"><?php _e('No Custom fields available.');?></td></tr>
<?php		
}
?>
  </thead>
</table>