<?php
$sub_menu = "200900";
include_once("./_common.php");

auth_check($auth[$sub_menu], "w");

$token = get_token();

$html_title = "투표";
if ($w == "")
    $html_title .= " 생성";
else if ($w == "u") {
    $html_title .= " 수정";
    $sql = " select * from $g4[poll_table] where po_id = '$po_id' ";
    $po = sql_fetch($sql);
} else
    alert("w 값이 제대로 넘어오지 않았습니다.");

$g4[title] = $html_title;
include_once("./admin.head.php");
?>
<div class='row'>
    <div class="col-sm-12">
        <?php echo subtitle($html_title)?>
        <form name=fpoll method=post onsubmit="return fpoll_check(this);" enctype="multipart/form-data" class="form-horizontal" role='form'>
            <input type='hidden' name='po_id' value='<?php echo $po_id ?>'>
            <input type='hidden' name='w'     value='<?php echo $w ?>'>
            <input type='hidden' name='sfl'   value='<?php echo $sfl ?>'>
            <input type='hidden' name='stx'   value='<?php echo $stx ?>'>
            <input type='hidden' name='sst'   value='<?php echo $sst ?>'>
            <input type='hidden' name='sod'   value='<?php echo $sod ?>'>
            <input type='hidden' name='page'  value='<?php echo $page ?>'>
            <input type='hidden' name='token' value='<?php echo $token ?>'>
            <div class='form-group'>
                <label class='control-label col-sm-2'>
                    투표 제목
                </label>
                <div class='col-sm-10'>
                    <input type='text' class='form-control' name='po_subject' required itemname='투표 제목' value='<?php echo $po['po_subject'] ?>' maxlength="125" placeholder="투표제목">
                </div>
            </div>
            <?php
                for ($i = 1; $i <= 9; $i++) {
                    $required = "";
                    $itemname = "";
                    if ($i == 1 || $i == 2) {
                        $required = "required";
                        $itemname = "itemname='항목$i'";
                    }

                    $po_poll = get_text($po["po_poll" . $i]);
            ?>
            <div class='form-group'>
                <label class='control-label col-sm-2'>
                    항목<?php echo $i?>
                </label>
                <div class='col-sm-10'>
                    <input type="text" name="po_poll<?php echo $i?>" <?php echo $required?> <?php echo $itemname?> value="<?php echo $po_poll?>" class='form-inline' maxlength="125">
                    <label>투표수 <input type="text" class='form-inline' name="po_cnt<?php echo $i?>" size='5' value="<?php echo $po["po_cnt" . $i]?>"></label>
                </div>
            </div>
            <?php } ?>
            
            <div class='form-group'>
                <label class='control-label col-sm-2'>
                    기타의견
                </label>
                <div class='col-sm-10'>
                    <input type='text' class='form-control' name='po_etc' value='<?php echo get_text($po[po_etc]) ?>' maxlength="125">
                </div>
            </div>
             
            <div class='form-group'>
                <label class='control-label col-sm-2'>
                    투표권한
                </label>
                <div class='col-sm-10'>
                    <?php echo get_member_level_select("po_level", 1, 10, $po['po_level']) ?>이상 투표할 수 있음
                </div>
            </div>
            <div class='form-group'>
                <label class='control-label col-sm-2'>
                    포인트
                </label>
                <div class='col-sm-10'>
                    <input type='text' class='form-inline' name='po_point' size='10' value='<?php echo $po[po_point] ?>'> 점 (투표한 회원에게 부여함)
                </div>
            </div>
            <?php if ($w == "u") { ?>
            <div class='form-group'>
                <label class='control-label col-sm-2'>
                    투표시작일
                </label>
                <div class='col-sm-10'>
                    <input type="text" class='form-control' name="po_date" size='10' maxlength=10 value="<?php echo $po[po_date] ?>">
                </div>
            </div>
            <div class='form-group'>
                <label class='control-label col-sm-2'>
                    투표참가 IP
                </label>
                <div class='col-sm-10'>
                    <textarea class='form-control' name="po_ips" rows='10' readonly><?php echo preg_replace("/\n/", " / ", $po[po_ips]) ?></textarea>
                </div>
            </div>
            <div class='form-group'>
                <label class='control-label col-sm-2'>
                    투표참가 회원
                </label>
                <div class='col-sm-10'>
                    <textarea class='form-control' name="mb_ids" rows='10' readonly><?php echo preg_replace("/\n/", " / ", $po[mb_ids]) ?></textarea>
                </div>
            </div> 
            <?php } ?>
            <div class='col-sm-offset-2'>
                <button type="submit" class='btn btn-primary'>확인</button>
                <input type='button' class='pull-right btn btn-default' value='목록' onclick="document.location.href = './poll_list.php?<?php echo $qstr ?>';">
            </div>
        </form>

        <script type='text/javascript'>
            function fpoll_check(f)
            {
                f.action = './poll_form_update.php';
                return true;
            }
        </script>
    </div>
</div>
<?php
include_once("./admin.tail.php");
?>
