<?php
/*
 *  슬라이더 페이지 등록
 */
include_once './_common.php';
set_session("ask_delete_token", $token = uniqid(time()));
include_once './index.php';
$asktheme_upload_url = G5_DATA_URL . "/asktheme_attach";

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_cslider where ac_idx = '{$idx}'";
    $data = sql_fetch($sql);
    if (!$data) {
        alert('데이터가 없습니다.', './slider_list.php');
    }
}
?>
<div id="container">
    <div class="ask-row grid">
        <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']; ?> 등록하기</h1>
                </div>
                <div class="panel-body">
                    <form class="add_banner" action="./slider_child_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='ac_idx' value='{$data['ac_idx']}'>";
                            echo "<input type='hidden' name='parent_idx' value='{$data['ac_parent_idx']}'>";
                        }
                        ?>
                        <input type="hidden" name="pc_id" value="<?php echo $plugin['id'] ?>"/>
                        <input type="hidden" name="pc_name" value="<?php echo $plugin['name'] ?>"/>

                        <div class="responsetable write-table">
                            <div class="tb-body">
                                <div class="tb-row">
                                    <div class="tb-cell"><label for="ab_status">페이지 사용여부<strong class="sound-only">필수</strong></label></div>
                                    <div class="tb-cell">
                                        <?php
                                        if ($data['ac_status'] == '1') {
                                            $ac_use = "checked";
                                        } elseif ($data['ac_status'] == '0') {
                                            $ac_unuse = "checked";
                                        }
                                        ?>
                                        <label><input type="radio" name="ac_status" value="1" <?php echo $ac_use ?> class="slider-start">사용하기</label>
                                        <label><input type="radio" name="ac_status" value="0" <?php echo $ac_unuse ?> class="slider-stop">중지하기</label>
                                    </div>
                                </div>
                                <div class="tb-row">
                                    <div class="tb-cell"><label for="ac_subject">제목<strong class="sound-only">필수</strong></label></div>
                                    <div class="tb-cell">
                                        <input type="text" name="ac_subject" value="<?php echo $data['ac_subject'] ?>" size="50" class="input" placeholder="슬라이더 제목"/>
                                    </div>
                                </div>
                                <div class="tb-row">
                                    <div class="tb-cell"><label for="ac_content">내용<strong class="sound-only">필수</strong></label></div>
                                    <div class="tb-cell">
                                        <textarea name='ac_content' rows="5" class="textarea" placeholder="내용을 입력하세요."><?php echo $data['ac_content'] ?></textarea>
                                    </div>
                                </div>

                                <div class="tb-row">
                                    <div class="tb-cell"><label for="ac_image">이미지<strong class="sound-only">필수</strong></label></div>
                                    <div class="tb-cell">
                                        <input type="file" name="ac_image" value="" class="input" accept="image/*"/>
                                        <div class="text text-default help">
                                            이미지 크기는 256*256, PNG를 이용하세요.
                                            <?php if ($data['ac_image_name']) { ?>
                                                <div><img src='<?php echo "{$asktheme_upload_url}/{$data['ac_image_name']}"; ?>'></div>
                                            <?php } ?>
                                        </div>
                                    </div>
                                </div>

                                <div class="tb-row">
                                    <div class="tb-cell"><label for="ac_link">슬라이더 링크</label></div>
                                    <div class="tb-cell">
                                        <input type="url" name="ac_link" value="<?php echo $data['ac_link'] ?>" size="50" class="input" placeholder="http를 포함한 전체주소를 넣으세요." />
                                        <div class="text text-default help">
                                            링크가 없으면 비워두세요.
                                        </div>
                                    </div>
                                </div>
                                <div class="tb-row">
                                    <div class="tb-cell"><label for="">정렬</label></div>
                                    <div class="tb-cell">
                                        <input type="text" name="ac_sort" value="<?php echo $data['ac_sort'] ?>" size="50" class="input" placeholder="정렬용 숫자, 작은숫자가 먼저출력됨" />
                                    </div>
                                </div>
                                <div class="tb-row">
                                    <div class="tb-cell show-for-medium">

                                    </div>
                                    <div class="tb-cell clearfix">
                                        <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='./slider_add.php?w=u&idx=<?php echo $data['ac_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='./slider_delete.php?idx=<?php echo $data['ac_idx'] ?>&type=child&amp;token=<?php echo $token?>' class="button danger delete"><i class="fa fa-trash"></i> 삭제</a>
                                                <a href='./slider_child_add.php?parent_idx=<?php echo $data['ac_parent_idx'] ?>' class="button"><i class="fa fa-plus"></i> 페이지 추가등록</a>
                                            </div>
                                        <?php } ?>
                                    </div>
                                </div>
                            </div>
                        </div>
                        <!--responsetable-->
                    </form>
                </div>
                <div class="panel-footer">
                    페이지를 여러개 등록하면 슬라이드 수가 늘어납니다.
                </div>
            </div>
        </div>
    </div>
</div>
<script type="text/javascript">
    $(function () {
        $('.delete').click(function () {
            if (confirm('페이지를 삭제하시겠습니까?')) {
                return true;
            } else {
                return false;
            }
        });
    });
    function form_submit(f) {
        //console.log(f);
        var use_slider = $('input[name=ac_status]:checked').val();
        if (use_slider === undefined) {
            alert('페이지 사용여부를 선택하세요');
            return false;
        }

        if ($('input[name=ac_subject]').val() === '') {
            alert('제목을 입력하세요.');
            $('input[name=ac_subject]').css('background-color', '#faff6d');
            return false;
        }
        if ($('textarea[name=ac_content]').val() === '') {
            alert('내용을 입력하세요.');
            $('textarea[name=ac_content]').css('background-color', '#faff6d');
            return false;
        }

        if ($('input[name=w]').val() === undefined) {
            if ($('input[name=ac_image]').val() === '') {
                alert('슬라이드 이미지를 등록하세요.');
                $('input[name=ac_image]').css('background-color', '#faff6d');
                return false;
            }
        }

        return true;
    }
</script>
<?php
include_once G5_PLUGIN_PATH . "/asktheme/_admin/tail.php";

