<?php
/*
 *  최신글 설정 등록
 */
include_once './_common.php';
set_session("ask_delete_token", $token = uniqid(time()));
include_once './index.php';

if (!defined('_GNUBOARD_')) {
    exit;
}

include_once G5_PLUGIN_PATH . "/asktheme/_admin/head.php";
add_stylesheet('<link rel="stylesheet" href="' . G5_PLUGIN_URL . '/asktheme/plugin/' . $plugin['id'] . '/plugin_style.css">', 0);
//수정모드일때
if ($w == 'u' && $idx) {
    $sql = "select * from ask_plugin_indexgroup_child where aic_idx = '{$idx}'";
    $data = sql_fetch($sql);
    if (!$data) {
        alert('데이터가 없습니다.', './indexgroup_list.php');
        exit;
    }
}
?>
<div id="container">
    <div class="row">
        <div class="small-12 medium-12 large-12 columns">
            <div class="panel panel-default">
                <div class="panel-header">
                    <h1><?php echo $plugin['name'], $plugin['version']; ?> 2단계 HTML 등록하기</h1>
                </div>
                <div class="panel-body">
                    <form class="add_latest" action="./indexgroup_child_page_add_update.php"  onsubmit="return form_submit(this);" method="post" enctype="multipart/form-data" autocomplete="off" >
                        <?php
                        if ($parent_idx) {
                            echo "<input type='hidden' name='parent_idx' value='{$parent_idx}'>";
                        }
                        if ($w == 'u' && $idx) {
                            echo "<input type='hidden' name='w' value='u'>";
                            echo "<input type='hidden' name='aic_idx' value='{$data['aic_idx']}'>";
                            echo "<input type='hidden' name='parent_idx' value='{$data['aic_parent_idx']}'>";
                        }
                        ?>
                        <input type="hidden" name="pc_id" value="<?php echo $plugin['id'] ?>"/>
                        <input type="hidden" name="pc_name" value="<?php echo $plugin['name'] ?>"/>
                        <input type="hidden" name="popup" value="<?php echo $popup?>/">

                        <div class="responsetable write-table">
                            <div class="tb-body">
                                <div class="tb-row">
                                    <div class="tb-cell"><label for="aic_status">사용여부<strong class="sound-only">필수</strong></label></div>
                                    <div class="tb-cell">
                                        <?php
                                        if ($data['aic_status'] == '1') {
                                            $aic_use = "checked";
                                        } elseif ($data['aic_status'] == '0') {
                                            $aic_unuse = "checked";
                                        }
                                        ?>
                                        <label><input type="radio" name="aic_status" value="1" <?php echo $aic_use ?> class="indexgroup-start">사용하기</label>
                                        <label><input type="radio" name="aic_status" value="0" <?php echo $aic_unuse ?> class="indexgroup-stop">중지하기</label>
                                    </div>
                                </div>
                                <div class="tb-row">
                                    <div class="tb-cell"><label for="aic_row">HTML</label></div>
                                    <div class="tb-cell">
                                        <textarea rows="10" name="aic_html" class="input textarea tinyeditor" id="tinyeditor"><?php echo $data['aic_html'] ?></textarea>
                                    </div>
                                </div>
                                <div class="tb-row">
                                    <div class="tb-cell"><label for="">정렬</label></div>
                                    <div class="tb-cell">
                                        <input type="text" name="aic_sort" value="<?php echo $data['aic_sort'] ?>" size="20" class="input" placeholder="정렬용 숫자, 작은숫자가 먼저출력됨" />
                                    </div>
                                </div>
                                <div class="tb-row">
                                    <div class="tb-cell">

                                    </div>
                                    <div class="tb-cell">
                                        <div class="button-group float-left">
                                            <button type="submit" class="button primary submit"><i class="fa fa-check"></i> 확인</button>
                                            <?php if ($w == u && $idx) { ?>
                                                <a href='./indexgroup_add.php?w=u&idx=<?php echo $data['aic_parent_idx'] ?>' class="button"><i class="fa fa-link"></i> 상위 설정으로..</a>
                                            <?php } ?>
                                        </div>
                                        <?php if ($w == u && $idx) { ?>
                                            <div class="button-group float-right">
                                                <a href='./indexgroup_delete.php?idx=<?php echo $data['aic_idx'] ?>&type=child&amp;token=<?php echo $token?>' class="button danger delete"><i class="fa fa-trash"></i> 삭제</a>
                                                <a href='./indexgroup_child_page_add.php?parent_idx=<?php echo $data['aic_parent_idx'] ?>' class="button"><i class="fa fa-plus"></i> HTML 컨텐츠 추가등록</a>
                                            </div>
                                        <?php } ?>
                                    </div>
                                </div>
                            </div>
                        </div>
                        <!--responsetable-->
                    </form>
                </div>
                <div class="panel-footer">
                    &middot; HTML 페이지는 1열로만 등록됩니다. <br/>
                    &middot; 처음 또는 마지막으로 정열되게 사용하세요. 최신글 중간에 끼워넣지 마세요. 1칸에 최신글+HTML 조합은 되지 않습니다.
                </div>
            </div>
        </div>
    </div>
</div>
<script src="//cdn.tinymce.com/4/tinymce.min.js"></script>
<script>
                        tinymce.init({
                            selector: 'textarea',
                            height: 400,
                            plugins: [
                                'advlist autolink lists link image charmap print preview anchor',
                                'searchreplace visualblocks code fullscreen',
                                'insertdatetime media table contextmenu paste code'
                            ],
                            toolbar: 'insertfile undo redo | styleselect | bold italic | alignleft aligncenter alignright alignjustify | bullist numlist outdent indent | link image',
                            content_css: [
                                '//fast.fonts.net/cssapi/e6dc9b99-64fe-4292-ad98-6974f93cd2a2.css',
                                '//www.tinymce.com/css/codepen.min.css',
                                '/theme/asktheme/css/default.css',
                                '/theme/asktheme/css/font-awesome.min.css'
                            ],
                            valid_elements : '*[*]',
                            relative_urls: false,
                            remove_script_host: false
                        });
</script>
<script type="text/javascript">
    $(function () {
        $('.delete').click(function () {
            if (confirm('등록된 최신글 설정을 삭제하시겠습니까?')) {
                return true;
            } else {
                return false;
            }
        });
    });
    function form_submit(f) {
        //console.log(f);
        var use_status = $('input[name=aic_status]:checked').val();
        if (use_status === undefined) {
            alert('최신글 사용여부를 선택하세요');
            return false;
        }
        var editorContent = tinyMCE.get('tinyeditor').getContent();
        if (editorContent == '') {
            alert('HTML 컨텐츠를 입력하세요');
            return false;
        }
        /*
         if ($('textarea[name=aic_html]').val() == '') {
         alert('HTML 컨텐츠를 입력하세요');
         return false;
         }
         */
        if ($('input[name=aic_sort]').val() == '') {
            alert('정렬용 숫자를 입력하세요. 낮은 숫자가 먼저 출력됩니다.');
            return false;
        }
        return true;
    }
</script>
<?php
include_once G5_PLUGIN_PATH . "/asktheme/_admin/tail.php";

