<?php 
if ( !defined('ABSPATH') ) {exit;}
if(!is_user_logged_in()){
	wp_die('请登录系统');
}
global $wpdb;
if($_POST){
	if($_POST['delid']){
		$sql = "delete from $wpdb->erphpact where id=".$_POST['delid'];
		$result=$wpdb->query($sql);
		if(!$result)
		{
			echo "<div id=message><div class='error settings-error'><p>删除失败！</p></div></div>";
		}else{echo "<div id=message><div class='updated settings-error'><p>删除成功！</p></div></div>";}
	}
}
$totals = $wpdb->get_var("SELECT COUNT(id) FROM $wpdb->erphpact");
$perpage = 30;
$pages = ceil($totals / $perpage);
$page=isset($_GET['paged']) ?intval($_GET['paged']) :1;
$offset = $perpage*($page-1);
$results = $wpdb->get_results("select * from $wpdb->erphpact order by id desc limit $offset,$perpage");

?>
<div class="wrap">
	<h2>激活码列表</h2>
	<table class="wp-list-table widefat fixed posts">
            <thead>
            <tr>
				<th width="7%">序号</th>
				<th width="16%">激活码</th>
                <th width="40%">文章ID</th>
				<th width="30%">发放</th>
				<th width="7%">删除</th>
            </tr>
            </thead>
            <tbody>
			<?php 
				if($results){
					foreach($results as $result){
						echo '<tr>';
						echo '<td>'.$result->id.'</td>';
						echo '<td>'.$result->num.'</td>';
						echo '<td><a href="'.get_permalink($result->pid).'" target="_blank">'.get_the_title($result->pid).'</a></td>';
						echo '<td>'.getErphpActStatus($result->id).'</td>';
						echo "<td>";
						echo "<form method=post ><input type=hidden id=delid name=delid value=".$result->id."><input type=submit value=删除 class=button onclick=\"return confirm('确认删除?');\"></form>";
						echo "</td>";
						echo '</tr>';
					}
				}
			?>
			</tbody>
	</table>
<?php erphpact_admin_pagenavi($totals,$perpage);?>
</div>