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

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

$g5['title'] = '자동레벨업관리';
$administrator = 1;
include_once(G5_ADMIN_PATH.'/admin.head.php');


$s = new SelectBox();
for($i=2;$i<=$member['mb_level'];$i++){
	$s->add($i, $i);
}

$amax = $btcfg['alevel_data'];

if(count($amax) > 0){
	krsort($amax);
	list($key) = each($amax);
	$s->selectedFromValue = $key;
	ksort($amax);
}
?>

<script type="text/javascript">
<!--
function setPointbox(){
	
	var data = alevel_data.split('|');
	
	var max = parseInt($('#alevel_max').val());
	
	$('#pointconf').empty();
	
	for(var i=0;i<max-1;i++){
		
		var li = $(document.createElement('li'));
		$('#pointconf').append(li);
		
		var lb_lev = $(document.createElement('label'));
		li.append(lb_lev);
		lb_lev.attr('for', 'level_' + i);
		lb_lev.text('레벨:');
		
		var lev = $(document.createElement('input'));
		li.append(lev);
		lev.attr('name', 'level[]');
		lev.attr('id', 'level_' + i);
		lev.attr('readonly', 'readonly');
		lev.addClass('level frm_input');
		lev.val(i+2);
		
		var lb_point = $(document.createElement('label'));
		li.append(lb_point);
		lb_point.attr('for', 'point_' + i);
		lb_point.text('포인트:');
		
		var point = $(document.createElement('input'));
		li.append(point);
		
		point.attr('name', 'point[]');
		point.attr('id', 'point_' + i);
		point.attr('title', '포인트');
		point.addClass('point frm_input');
		
		if(data.length-1 >= i){
			if(data[i].trim() != ''){
				var temp = data[i].split('#');
				lev.val(temp[0]);
				point.val(temp[1]);
			}
		}
	}
}

$(function(){
	$('#alevel_max').change(setPointbox);
	setPointbox();
});

var alevel_data = '<?php echo $btcfg['bc_alevel_data']?>';


function falevel_submit(f){
	if($('#bc_alevel_useup').is(':checked') || $('#bc_alevel_usedown').is(':checked')){
		for(var i=0;i<$('.level').size();i++){
			var level = $($('.level').get(i));
			var point = $($('.point').get(i));
			if(level.val().trim() == ''){
				alert('레벨값이 없습니다');
				level.focus();
				return false;
			}else if(point.val().trim() == ''){
				alert('포인트값을 입력해주세요');
				point.focus();
				return false;
			}
		}
	}
	return true;
}
//-->
</script>

<form name="falevelform" id="falevelform" action="./autolevel_update.php" method="post" onsubmit="return falevel_submit(this)">
<section>
    <div class="tbl_frm01 tbl_wrap">
    	<table>
        <caption>자동레벨업관리</caption>
        <colgroup>
            <col class="grid_2">
            <col class="grid_7">
        </colgroup>
        <tbody>
        <tr>
        	<th scope="row"><label>자동레벨업</label></th>
        	<td><span class="frm_info">회원의 포인트가 설정된 포인트 이상일 경우 자동으로 레벨업 시키려면 체크하세요</span>
        		<input type="checkbox" name="bc_alevel_useup" id="bc_alevel_useup" value="1" <?php echo $btcfg['bc_alevel_useup']=='1'? 'checked="checked"':'';?>>
        		<label for="bc_alevel_useup">사용함</label>
        	</td>
        </tr>
        <tr>
        	<th scope="row"><label>자동레벨다운</label></th>
        	<td><span class="frm_info">회원의 포인트가 설정된 포인트 이하일 경우 자동으로 레벨다운 시키시려면 체크하세요</span>
        		<input type="checkbox" name="bc_alevel_usedown" id="bc_alevel_usedown" value="1" <?php echo $btcfg['bc_alevel_usedown']=='1'? 'checked="checked"':'';?>>
        		<label for="bc_alevel_usedown">사용함</label>
        	</td>
        </tr>
        <tr class="dataarea">
        	<th scope="row"><label for="alevel_max">자동레벨업 사용여부</label></th>
        	<td><span class="frm_info">자동으로 레벨업 적용시킬 최대레벨을 선택해주세요</span>
        		<select name="alevel_max" id="alevel_max"><?php echo $s->getOption();?></select>
        	</td>
        </tr>
        <tr class="dataarea">
        	<th scope="row"><label>기준 포인트 설정</label></th>
        	<td>
        		<span class="frm_info">레벨에 해당하는 기준 포인트를 입력해 주세요.</span>
        		<ul id="pointconf"></ul>
        	</td>
        </tr>
    	</tbody>
    	</table>
    </div>
</section>

<div class="btn_confirm01 btn_confirm">
    <input type="submit" value="적용하기" class="btn_submit" accesskey="s">
</div>

</form>

<?php
include_once(G5_ADMIN_PATH.'/admin.tail.php');