<?php
require_once '_admin_setting.php';
require_once NSO_INC_PATH . 'Pager.php';
$nsoPostFormFileName = 'product_form.php';

$cat = $_GET['cat'];
$cat = empty($cat) ? $nsoDefaultPostCatId : $cat;

$sql = "SELECT * FROM categories WHERE id = {$cat}";
$category = $nsodb->get_row($sql);
$categoryName = $category->name;

$sql = "SELECT posts.id as id, title, date, date_update
		FROM posts, rel_post_cat
		WHERE posts.id = post_id
		AND `cat_id` = {$cat}
		AND `status` <> 'deleted' ORDER BY date DESC";
$pager = new Pager($nsodb, $sql, 20);
$rsPost = $pager->getResults();
$totalRow = $pager->getTotalRow();

addHeaderJavascript('javascripts/post_list.js');
require_once '_top.php';
require_once '_header.php';
require_once '_menuPane.php';
?>
<div id="godContentContainer">
    <div class="content_part">
        <div class="title">
            <h2><?php echo $categoryName?><span class="title_info">（共有<strong><?php echo $totalRow; ?></strong>篇）</span></h2>
        </div>
        <div id="topToolbar" class="toolbar">
            <div class="tool_button quick_filter_button">
                <div class="button"><input type="checkbox" class="checkall" /><span class="check_list"></span><span class="deco_left"></span><span class="deco_right"></span></div>
            </div>
            <div class="tool_button">
                <div class="button delete_button">删除所选<span class="deco_left"></span><span class="deco_right"></span></div>
            </div>
            <?php if ($cat != $nsoProductCatId):?>
            <div class="tool_button">
                <div class="button add_button">增加<span class="deco_left"></span><span class="deco_right"></span></div>
            </div>
            <?php endif;?>
            <!--
            <div class="tool_button">
                <div class="button savesort_button">保存排序<span class="deco_left"></span><span class="deco_right"></span></div>
            </div>
             -->
            <div class="pager_navigation"><?php echo $pager->getNavigation(); ?></div>
        </div>
        <div class="infobar">
            <div class="message_box">正在处理...</div>
        </div>
        <div class="content">
            <div class="table_content">
                <table>
                    <tbody>
                    <?php if ($rsPost) : foreach ($rsPost as $post) : $updateUrl = "{$nsoPostFormFileName}?cat={$cat}&id={$post['id']}";?>
                    	<tr id="post-<?php echo $post['id']?>">
                            <td class="drag_icon"></td>
                            <td class="checkbox"><input type="checkbox" value="<?php echo $post['id']?>" /></td>
                            <td class="title"><a href="<?php echo $updateUrl?>"><?php echo $post['title']?></a></td>
                            <td class="date"><?php echo date('m月d日', strtotime($post['date']))?></td>
                            <td class="action">
                                <a href="<?php echo $updateUrl?>" class="edit">编辑</a>
                                <a href="post_edit_action.php?action=delete&id=<?php echo $post['id']?>" class="delete">删除</a>
                            </td>
                        </tr>
                     <?php endforeach; endif;?>
                     </tbody>
                </table>
            </div>
        </div>
        <div style="display: none">
            <div id="hiddenParamCatId"><?php echo $cat;?></div>
            <div id="hiddenParamPostFormFileName"><?php echo $nsoPostFormFileName?></div>
        </div>
    </div>
</div>
<?php include_once '_bottom.php';?>