<?php
include_once('./_common.php');

include_once(AMINA_PATH.'/lib/head.lib.php');

if (!$bo_table) {
	alert_close("값이 넘어오지 않았습니다.");
}

//설문조사
$is_poll = false;
if($is_admin || $amina['poll_level'] == 1 || ($amina['poll_level'] > 1 && $member['mb_level'] >= $amina['poll_level'])) {
	;
} else {
	alert_close("설문을 등록할 권한이 없습니다.");
}

$tr = G5_IS_MOBILE ? '</tr><tr>' : '';

?>
<!doctype html>
<html lang="ko">
<head>
<meta charset="utf-8">
<? if (G5_IS_MOBILE) {?>
<meta name="viewport" content="width=device-width,initial-scale=1.0,minimum-scale=0,maximum-scale=10,user-scalable=yes">
<meta name="HandheldFriendly" content="true">
<meta name="format-detection" content="telephone=no">
<? } ?>
<title>설문조사</title>
<style>
	body { background:#efefef; margin:0; padding:0; font:normal 12px dotum; -webkit-text-size-adjust:100%; }
	.poll_tbl { width:100%; background:#fff; border-collapse:collapse; border:0px; padding:0px; margin:0px; } 
	.poll_tbl th { width:70px; border:0px; border-bottom:1px solid #ddd; padding:7px 15px; background-color: #f5f5f5; font-weight:bold; text-align:left; }
	.poll_tbl td { border:0px; border-bottom:1px solid #ddd; padding:7px 10px; }
	input[type=text] { border:1px solid #ddd; border-radius:0;-webkit-appearance:none; }
	.title { padding:12px; text-align:center; font:bold 14px verdana; color:gold; background:#333 !important; border:0px; }
	.wr_t { width:40px; }
	.wr_max { width:98%; }
	.win-submit { cursor:pointer; padding:15px; text-align:center; font:bold 12px dotum; color:white; background:#333; border:0px; }
	.win-close { cursor:pointer; padding:15px; text-align:right; font:normal 12px dotum; border:0px; }
</style>
<script>
	function addLoadEvent(func) {
		var oldonload = window.onload;
		if (typeof window.onload != 'function') {
			window.onload = func;
		} else {
			window.onload = function() {
				if (oldonload) {
					oldonload();
				}
				func();
			}
		}
	}

	function initialize() {

		document.getElementById("poll_subject").value = opener.document.fwrite.poll_subject.value;
		document.getElementById("poll_y").value = opener.document.fwrite.poll_y.value;
		document.getElementById("poll_m").value = opener.document.fwrite.poll_m.value;
		document.getElementById("poll_d").value = opener.document.fwrite.poll_d.value;
		document.getElementById("poll_h").value = opener.document.fwrite.poll_h.value;
		document.getElementById("poll_i").value = opener.document.fwrite.poll_i.value;
		if(opener.document.fwrite.poll_level.value) {
			document.getElementById("poll_level").checked = true;
		}
		if(opener.document.fwrite.poll_location.value) {
			document.getElementById("poll_location").checked = true;
		}
		document.getElementById("poll_point").value = opener.document.fwrite.poll_point.value;
		document.getElementById("poll_item1").value = opener.document.fwrite.poll_item1.value;
		document.getElementById("poll_item2").value = opener.document.fwrite.poll_item2.value;
		document.getElementById("poll_item3").value = opener.document.fwrite.poll_item3.value;
		document.getElementById("poll_item4").value = opener.document.fwrite.poll_item4.value;
		document.getElementById("poll_item5").value = opener.document.fwrite.poll_item5.value;
		document.getElementById("poll_item6").value = opener.document.fwrite.poll_item6.value;
		document.getElementById("poll_item7").value = opener.document.fwrite.poll_item7.value;
		document.getElementById("poll_item8").value = opener.document.fwrite.poll_item8.value;
		document.getElementById("poll_item9").value = opener.document.fwrite.poll_item9.value;
	}
</script>
</head>
<body>
<div class="title">설문조사 설정하기</div>

<table border=0 class="poll_tbl">
<tr>
<th><label for="poll_subject">설문제목</label></th>
<?=$tr?>
<td><input type="text" size="40" id="poll_subject" name="poll_subject" itemname="설문제목" value="" class="wr_max"></td>
</tr>

<tr>
<th><label for="poll_date">설문기간</label></th>
<?=$tr?>
<td>
	<input type="text" size="4" id="poll_y" name="poll_y" value="" class="wr_t"> 년
	<input type="text" size="2" id="poll_m" name="poll_m" value="" class="wr_t"> 월
	<input type="text" size="2" id="poll_d" name="poll_d" value="" class="wr_t"> 일
	<input type="text" size="2" id="poll_h" name="poll_h" value="" class="wr_t"> 시
	<input type="text" size="2" id="poll_i" name="poll_i" value="" class="wr_t"> 분 까지
</td>
</tr>

<tr>
<th><label>설문옵션</label></th>
<?=$tr?>
<td>
	<input type="checkbox" id="poll_level" name="poll_level" value="1">
	<label for="poll_level">회원만 투표</label>

	<input type="checkbox" id="poll_location" name="poll_location" value="1">
	<label for="poll_location">본문상단 출력</label>
</td>
</tr>
<? if($is_admin) { ?>
	<tr>
	<th><label for="poll_point">참여시 적립 MP</label></th>
	<?=$tr?>
	<td>
		<input type="text" size="4" id="poll_point" name="poll_point" itemname="참여시 적립 MP" value="" class="wr_t">
		<label for="poll_point">MP(관리자전용)</label>
	</td>
	</tr>
<? } else { ?>
		<input type="hidden" id="poll_point" name="poll_point" itemname="참여시 적립 MP" value="">
<? } ?>
<tr>
<th><label for="poll_item1">항목 01</label></th>
<?=$tr?>
<td><input type="text" size="40" id="poll_item1" name="poll_item1" itemname="항목1" value="" class="wr_max"></td>
</tr>
<tr>
<th><label for="poll_item2">항목 02</label></th>
<?=$tr?>
<td><input type="text" size="40" id="poll_item2" name="poll_item2" itemname="항목2" value="" class="wr_max"></td>
</tr>
<tr>
<th><label for="poll_item3">항목 03</label></th>
<?=$tr?>
<td><input type="text" size="40" id="poll_item3" name="poll_item3" itemname="항목3" value="" class="wr_max"></td>
</tr>
<tr>
<th><label for="poll_item4">항목 04</label></th>
<?=$tr?>
<td><input type="text" size="40" id="poll_item4" name="poll_item4" itemname="항목4" value="" class="wr_max"></td>
</tr>
<tr>
<th><label for="poll_item5">항목 05</label></th>
<?=$tr?>
<td><input type="text" size="40" id="poll_item5" name="poll_item5" itemname="항목5" value="" class="wr_max"></td>
</tr>
<tr>
<th><label for="poll_item6">항목 06</label></th>
<?=$tr?>
<td><input type="text" size="40" id="poll_item6" name="poll_item6" itemname="항목6" value="" class="wr_max"></td>
</tr>
<tr>
<th><label for="poll_item7">항목 07</label></th>
<?=$tr?>
<td><input type="text" size="40" id="poll_item7" name="poll_item7" itemname="항목7" value="" class="wr_max"></td>
</tr>
<tr>
<th><label for="poll_item8">항목 08</label></th>
<?=$tr?>
<td><input type="text" size="40" id="poll_item8" name="poll_item8" itemname="항목8" value="" class="wr_max"></td>
</tr>
<tr>
<th><label for="poll_item9">항목 09</label></th>
<?=$tr?>
<td><input type="text" size="40" id="poll_item9" name="poll_item9" itemname="항목9" value="" class="wr_max"></td>
</tr>
</table>

<div class="win-submit" onclick="javascript:poll_submit();">등록하기</div>

<div class="win-close" onclick="javascript:window.close();">창닫기</div>

<script> 

	function move_center() {
		var sw = screen.width;
	    var sh = screen.height;
		var cw = document.body.clientWidth;
	    var ch = document.body.clientHeight;
	    var top  = sh / 2 - ch / 2 - 100;
		var left = sw / 2 - cw / 2;
	    moveTo(left, top);
	}

	function poll_submit() {

		opener.document.fwrite.poll_subject.value = document.getElementById("poll_subject").value;
		opener.document.fwrite.poll_y.value = document.getElementById("poll_y").value;
		opener.document.fwrite.poll_m.value = document.getElementById("poll_m").value;
		opener.document.fwrite.poll_d.value = document.getElementById("poll_d").value;
		opener.document.fwrite.poll_h.value = document.getElementById("poll_h").value;
		opener.document.fwrite.poll_i.value = document.getElementById("poll_i").value;

		if(document.getElementById("poll_level").checked == true) {
			opener.document.fwrite.poll_level.value = '1';
		} else {
			opener.document.fwrite.poll_level.value = '';
		}

		if(document.getElementById("poll_location").checked == true) {
			opener.document.fwrite.poll_location.value = '1';
		} else {
			opener.document.fwrite.poll_location.value = '';
		}

		opener.document.fwrite.poll_point.value = document.getElementById("poll_point").value;
		opener.document.fwrite.poll_item1.value = document.getElementById("poll_item1").value;
		opener.document.fwrite.poll_item2.value = document.getElementById("poll_item2").value;
		opener.document.fwrite.poll_item3.value = document.getElementById("poll_item3").value;
		opener.document.fwrite.poll_item4.value = document.getElementById("poll_item4").value;
		opener.document.fwrite.poll_item5.value = document.getElementById("poll_item5").value;
		opener.document.fwrite.poll_item6.value = document.getElementById("poll_item6").value;
		opener.document.fwrite.poll_item7.value = document.getElementById("poll_item7").value;
		opener.document.fwrite.poll_item8.value = document.getElementById("poll_item8").value;
		opener.document.fwrite.poll_item9.value = document.getElementById("poll_item9").value;
		opener.document.fwrite.poll_open.value = "설문수정";
		window.close();
    }

	addLoadEvent(function() {
		move_center();
		initialize();
	});
</script>
</body>
</html>