<?php
require_once '_admin_setting.php';

$thaAction = 'add';
$theId = trim($_GET['id']);
$theId = is_numeric($theId) ? $theId : '';
$theCat = trim($_GET['cat']);
$date = $updateDate = date('Y-m-d H:i:s');
$categories = getCategoriesByParent($theCat);

$thePostData = array();

if ($theId) {
    $thePost = new Posts($theId);
    $date = $thePost->getDate();
    if ($thePost) {
        $theRelFiles = $thePost->getRelFiles();

        $theCats = $thePost->getCategories();
        if ($theCats) :
            $theRelCats = array_keys($theCats);
        endif;

        $thePostData = $thePost->getData();

        $thaAction = 'update';
    }
}

addHeaderCss('swfupload/style/swfupload.css');
addHeaderJavascript('../javascripts/jquery/jquery.form.js');
addHeaderJavascript($nsoCkeditorJavascripts, $nsoSwfuploadScripts);
addHeaderJavascript('javascripts/post_form.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 getCategoryName($theCat)?></h2></div>
        <div id="topToolbar" class="toolbar">
            <div class="tool_button">
                <div class="button save_button">保存<span class="deco_left"></span><span class="deco_right"></span></div>
            </div>
            <?php if ($theCat != $nsoAboutCatId):?>
            <div class="tool_button">
                <div class="button addnew_button">新增<span class="deco_left"></span><span class="deco_right"></span></div>
            </div>
            <?php endif;?>
        </div>
        <div class="infobar">
            <div class="message_box">正在保存...</div>
        </div>
        <div class="content">
            <div class="form_content">
                <form id="postForm" action="post_edit_action.php" method="post">
                    <table>
                        <tbody>
                            <tr>
                                <td class="label"><?php __t('title', $theCat)?></td>
                                <td>
                                    <div class="form_element form_element_title">
                                        <input class="input_title" type="text" name="post-title" value="<?php echo $thePostData['title'];?>" />
                                    </div>
                                </td>
                            </tr>
                            <?php if ($theCat == 8 || $theCat == $nsoDownloadCatId):?>
                            <tr>
                                <td class="label"><?php __t('subtitle', $theCat)?></td>
                                <td>
                                    <div class="form_element">
                                        <input type="text" name="post-subtitle" value="<?php echo $thePostData['subtitle'];?>" />
                                    </div>
                                </td>
                            </tr>
                            <?php endif;?>
                            <?php if ($theCat == $nsoNewsCatId || $theCat == $nsoKnowledgeCatId || $theCat == $nsoResolutionCatId || $theCat == 10 || $theCat == $nsoDownloadCatId) :?>
                            <tr>
                                <td class="label">分类</td>
                                <td>
                                    <div class="form_element form_element_category form_checkboxs">
                                        <?php outputCategories($categories, $theRelCats)?>
                                    </div>
                                </td>
                            </tr>
                            <?php endif; ?>
                            <?php if ($theCat == 9):?>
                            <tr>
                                <td class="label">简介</td>
                                <td class="editor">
                                    <textarea class="editor" name="post-preview"><?php echo $thePostData['preview'];?></textarea>
                                </td>
                            </tr>
                            <?php endif;?>
                            <?php if ($theCat != $nsoDownloadCatId):?>
                            <tr>
                                <td class="label">内容</td>
                                <td class="editor">
                                    <textarea class="editor" name="post-content"><?php echo $thePostData['content'];?></textarea>
                                </td>
                            </tr>
                            <?php endif;?>
                            <?php if ($theCat != $nsoAboutCatId):?>
                            <tr>
                                <td class="label">日期</td>
                                <td>
                                    <div class="form_element form_element_datetime">
                                        <div><label>初稿时间</label><input name="post-date" value="<?php echo $date?>" /></div>
                                        <div><label>更新时间</label><input name="post-date_update" value="<?php echo $updateDate?>" /></div>
                                    </div>
                                </td>
                            </tr>
                            <?php endif;?>
                        </tbody>
                    </table>
                    <div class="line"></div>
                    <?php if ($theCat != $nsoAboutCatId && $theCat != $nsoNewsCatId && $theCat != 30 && $theCat != 31):?>
                    <table>
                        <tbody>
                            <tr>
                                <td></td>
                                <td class="tip"> - 独立于文章内容的文件都可以作为附件添加；<br /> - 添加后的附件请在下拉菜单选择附件类型，以方便程序调用显示；</td>
                            </tr>
                            <tr>
                                <td class="label">附件</td>
                                <td>
                                    <!-- Copy the DIV HTML as follow to reuse Swfupoad in quick. -->
                                    <div id="swfuploadContainer">
                                        <span id="swfuploadButtonPlaceholder"></span>
                                        <span id="swfuploadCancelButton" onclick="cancelQueue(swfupload);">取消全部</span>
                                        <!-- #swfuploadFileRelTypeOptionHtml.html()主要给JS调用 -->
                                        <div id="swfuploadFileRelTypeOptionHtml" style="display: none;"><?php outputSwfuploadFileTypeOptions('post');?></div>
                                        <div id="swfuploadUploadProgress"><?php outputPostRelFilesHtml($theRelFiles);?></div>
                                    </div>
                                    <!-- End Copy -->
                                </td>
                            </tr>
                        </tbody>
                    </table>
                    <?php endif;?>
                    <input type="hidden" name="category-cat_id[]" value="<?php echo $theCat?>" />
                    <input type="hidden" name="id" value="<?php echo $theId?>" id="form-post-id-input" />
                    <input type="hidden" name="action" value="<?php echo $thaAction?>" id="form-action-input" />
                </form>
            </div>
        </div>
        <div style="display:none">
            <div id="hiddenParamAddNewPostUri"><?php $addNewUri = explode('&', $_SERVER['REQUEST_URI']); echo $addNewUri[0];?></div>
        </div>
    </div>
</div>
<?php include_once '_bottom.php'; ?>