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

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

$token		= get_token();
include_once("$g4[path]/head.sub.php");
?>
<script type="text/javascript" src="<?=$g4[path]?>/js/sideview.js"></script>
<style type="text/css">
td, span, div, a, textarea	{ font-family:Dotum; font-size:11px; letter-spacing:0px; }
#info_box	{ border:1px solid #8397BF; background-color:#F8F8FB; color:#4C596E; text-align:left; padding:5px; margin:4px 12px 4px 12px;  }

.group_list	{ position:relative; margin:0 auto; padding:3px; width:33%; line-height:200%; text-align:left; float:left; }
.line		{ border-top:1px solid #EFEFEF; clear:both; }
.btnsetup	{ vertical-align:middle; cursor:pointer; _cursor /**/:hand; }
.info		{ padding:10px; color:#515151; line-height:160%; }
.fbold		{ font-weight:bold; color:#FF0000; }
.left-pad1	{ padding-left:20px; }
.left-pad2	{ padding-left:50px; }
.left-pad3	{ padding-left:80px; }
.level_1	{ color:#373737; font-size:13px; font-weight:bold; }
.level_2	{ color:#373737; font-size:12px; }
.level_3	{ color:#A2A2A2; font-size:11px; }
.group_bg1	{ background-color:#FFFFFF; }
.group_bg2	{ background-color:#F7F7F7; }
.msg		{ color:#B2B2B2; }

.grpreg_box select	{ height:20px; }
.mdate		{ color:#AAAAAA; text-align:center; }

td a:hover	{ text-decoration:underline; }
td a		{ color:#2A2A2A; font-size:12px; }
</style>
<link rel="stylesheet" href="<?=$g4[path]?>/adm/admin.style.css" type="text/css">
<?
$g4[title] = "지음빌더 레이아웃 구성";
include_once ("./admin.head.php");

//-- 함수. 분류 읽기 ----------------------------
function read_group($level, $uprecno){
	global $zmb, $g4;

	if($uprecno) $s_where	= "and db_up_recno='$uprecno'";
	$rs_group	= sql_query("select * from $zmb[table_builder_config] where db_level='$level' and db_menu_reg='1' $s_where order by db_rank asc, db_recno desc");

	$group_list	= array();
	$i		= 0;
	while($rd = sql_fetch_array($rs_group)) {
		$group_list[$i][recno]		= $rd[db_recno];
		$group_list[$i][level]		= $rd[db_level];
		$group_list[$i][uprecno]	= $rd[db_up_recno];
		$group_list[$i][rank]		= $rd[db_rank];
		$group_list[$i][groupname]	= $rd[db_group_name];
		$group_list[$i][groupexplain]	= $rd[db_group_explain];
		$group_list[$i][more]		= $rd[db_more];
		$group_list[$i][index_skin]	= $rd[db_index_skin];
		$group_list[$i][layout_skin]	= $rd[db_layout_skin];
		$group_list[$i][pagename]	= $rd[db_pagename];
		$group_list[$i][target]		= $rd[db_target];
		$group_list[$i][link_type]	= $rd[db_link_type];
		$group_list[$i][href]		= $rd[db_href];
		$group_list[$i][subdomain]	= $rd[db_subdomain];
		$group_list[$i][datetime]	= substr($rd[db_datetime], 5, 11);

		if($group_list[$i][link_type] == "1"){									//-- 게시판
			$group_list[$i][skin_url]	= $rd[db_layout_skin];
			$group_list[$i][board]		= $rd[db_board];
			$group_list[$i][skin_dir]	= "skin/zm.layout/";					//-- 스킨이 있는 위치
		}elseif($group_list[$i][link_type] == "2"){								//-- 페이지
			$group_list[$i][skin_url]	= $rd[db_layout_skin] . "/" . $group_list[$i][pagename];
			$group_list[$i][skin_dir]	= "skin/zm.layout/";
		}elseif($group_list[$i][link_type] == "3"){								//-- URL
			if(strlen($rd[db_href]) > 40)	$group_list[$i][skin_url]	= "...".substr($rd[db_href], strlen($rd[db_href])-40, 40);
			else							$group_list[$i][skin_url]	= $rd[db_href];
			$group_list[$i][skin_dir]	= "";
		}elseif($group_list[$i][link_type] == "0") {
			$group_list[$i][skin_dir]	= "skin/zm.index/";
		}

		$group_list[$i][go_href]		= zm_conv_url($rd[db_recno]);

		$sw		= 1;
		$group_list[$i][btnimage]	= "./img/btn_setup.gif";
		if(!$group_list[$i][href] ||  !$group_list[$i][groupname]) $sw = 0;
		//-- 인덱스
		if(($group_list[$i][link_type] == "0") && (!$group_list[$i][href] || !$group_list[$i][index_skin])) $sw = 0;
		//-- 게시판
		if($group_list[$i][link_type] == "1") {
			$table_info	= sql_fetch("select * from $g4[board_table] where bo_table='{$group_list[$i][board]}'");

			if(!$group_list[$i][href] || !$group_list[$i][layout_skin] || !$group_list[$i][board] || !$table_info[bo_include_head] || !$table_info[bo_include_tail]) $sw	= 0;
		}
		//-- 일반페이지
		if(($group_list[$i][link_type] == "2") && (!$group_list[$i][href] || !$group_list[$i][layout_skin])) $sw = 0;
		//-- URL
		if(($group_list[$i][link_type] == "3") && (!$group_list[$i][href])) $sw = 0;


		if(!$sw) $group_list[$i][btnimage]	= "./img/btn_setup_on.gif";
		
		//-- level이 99이면 회원가입
		if($group_list[$i][level] == "99") {
			if($group_list[$i][layout_skin]) {
				$group_list[$i][btnimage]	= "./img/btn_setup.gif";
			}else{
				$group_list[$i][btnimage]	= "./img/btn_setup_on.gif";
			}
		}

		$i++;
	}

	return $group_list;
}

$index_exist= read_group(0, "");			//-- 인덱스 정보
$group_1	= read_group(1, "");			//-- 메뉴 그룹
$group_2	= read_group(2, "$g_1_r");		//-- 중분류 정보
$group_3	= read_group(3, "");			//-- 소분류 정보
$member_skin = read_group(99, "");			//-- 회원가입

//-- 회원가입 스킨 정보가 없으면 생성 -----------
$rd_mem	= sql_fetch("select * from $zmb[table_builder_config] where db_level='99'");
if(!$rd_mem[db_recno]) {
	$member_skins	= get_skin_dir("zm.member");			//-- 회원가입 스킨
	$topmenu_skins	= get_skin_dir("zm.topmenu");			//-- Topmenu 스킨
	$bottom_skins	= get_skin_dir("zm.bottom");			//-- Bottom 스킨

	$sql	= "insert into $zmb[table_builder_config] set db_level='99', db_menu_reg='1', db_group_name='회원가입', db_group_explain='회원가입', db_layout_skin='$member_skins[0]', db_datetime='".date("Y-m-d H:i:s")."'";
	sql_query($sql);
}


$colspan	= 7;
?>
<?=subtitle("메뉴 구성")?>
<form name="group_list">
<table class="grpreg_box">
<tr>
<? if($index_exist[0][recno]) :				//-- INDEX가 있으면 그룹분류 등록 ?>
	<td>&nbsp;&nbsp;&nbsp;
	<!-- 메뉴그룹 등록 -->
		<select name="sel_index_recno">
		<option>INDEX</option>
		</select>→
		<input size=15 name="in_group_1" value="" onKeyPress="if(event.keyCode==13) return false;"> 
		<input type="button" value="메뉴그룹 등록" class="btn1" onClick="reg_group('1', '<?=$index_exist[0][recno]?>', document.group_list.in_group_1.value)">
	</td>
<? endif; 

   if($group_1[0][recno]) :					//-- 메뉴그룹 있으면 중분류 등록 가능 ?>
	<td>&nbsp;&nbsp;&nbsp;
	<!-- 중분류 등록 -->
		<select name="sel_group_1" onChange="zm_gourl('?g_1_r='+this.value);">
		<option value="">- 메뉴그룹 -</option>
<?	for($i = 0; $i < count($group_1); $i++) : 
		if($g_1_r == $group_1[$i][recno]) $sel_g1 = "selected"; else $sel_g1 = ""; ?>
		<option value="<?=$group_1[$i][recno]?>" <?=$sel_g1?>><?=$group_1[$i][groupname]?></option>
<?	endfor; ?>
		</select> →
		<input size=15 name="in_group_2" value="<?=$g_2_n?>" onKeyPress="if(event.keyCode==13) return false;">
		<input type="button" value="중분류 등록" class="btn1" onClick="reg_group('2', document.group_list.sel_group_1.value, document.group_list.in_group_2.value)">
	</td>
<? endif; 

   if($group_2[0][recno]) :					//-- 중분류 있으면 중분류 등록 가능 ?>
	<td>&nbsp;&nbsp;&nbsp;
	<!-- 소분류 등록 -->
		<select name="sel_group_2" onChange="zm_gourl('?g_1_r=<?=$g_1_r?>&g_2_r='+this.value);">
		<option value="">- 중분류 -</option>
<?	for($i = 0; $i < count($group_2); $i++) :
		if($g_2_r == $group_2[$i][recno]) $sel_g2 = "selected"; else $sel_g2 = ""; ?>
		<option value="<?=$group_2[$i][recno]?>" <?=$sel_g2?>><?=$group_2[$i][groupname]?></option>
<?	endfor; ?>
		</select> →
		<input size=15 name="in_group_3" value="" onKeyPress="if(event.keyCode==13) return false;"> 
		<input type="button" value="소분류 등록" class="btn1" onClick="reg_group('3', document.group_list.sel_group_2.value, document.group_list.in_group_3.value)">
	</td>
<? endif; 

   if(!$index_exist[0][recno]) :									//-- INDEX가 없으면 등록 ?>
	<td>&nbsp;&nbsp;&nbsp;
		<input size=15 name="in_group" value="INDEX" readonly> 
		<input type="button" value="등록" class="btn1" onClick="reg_group('0', '', document.group_list.in_group.value)">
	</td>
<? endif; ?>
</tr>
</table>

<table width=100% cellpadding=0 cellspacing=0 border=0 align="center">
<colgroup width=30%>
<colgroup width=28%>
<colgroup width=10%>
<colgroup width=8%>
<colgroup width=6%>
<colgroup width=8%>
<colgroup width=10%>
<tr><td colspan='<?=$colspan?>' class='line2'></td></tr>
<tr class='bgcol1 bold ht center'>
    <td>INDEX > 메뉴그룹 > 중분류 > 소분류</td>
	<td>스킨 / PAGE / URL</td>
	<td>게시판</td>
	<td>출력순위▲</td>
	<td>더보기</td>
	<td>Sub domain</td>
	<td>수정일</td>
</tr>
<tr><td colspan='<?=$colspan?>' class='line2'></td></tr>
<tr class='ht'>
	<td>
		<img src="<?=$member_skin[0][btnimage]?>" class="btnsetup" onClick="zm_gourl('./zm.builder_write.php?recno=<?=$member_skin[0][recno]?>');"> 회원가입
	</td>
	<td><a href="<?=$member_skin[0][go_href]?>" target="_blank"><span class="msg">skin/zm.member/</span><?=$member_skin[0][layout_skin]?></a></td>
	<td></td>
	<td></td>
	<td></td>
	<td></td>
	<td class="mdate"><?=$index_exist[0][datetime]?></td>
</tr>
<tr><td colspan='<?=$colspan?>' class='line2'></td></tr>
<tr class='ht'>
	<td>
<?	if($index_exist[0][recno]) : ?>
		<img src="<?=$index_exist[0][btnimage]?>" class="btnsetup" onClick="zm_gourl('./zm.builder_write.php?recno=<?=$index_exist[0][recno]?>');"> INDEX
<?	else : ?>
		<center>INDEX를 등록하세요.</center>
<?	endif; ?>
	</td>
	<td><a href="<?=$index_exist[0][go_href]?>" target="_blank"><span class="msg"><?=$index_exist[0][skin_dir]?></span><?=$index_exist[0][index_skin]?></a></td>
	<td><?=$index_exist[0][board]?></td>
	<td align="right">0</td>
	<td align="center"></td>
	<td></td>
	<td class="mdate"><?=$index_exist[0][datetime]?></td>
</tr>
<tr><td colspan='<?=$colspan?>' class='line2'></td></tr>
<!-- 메뉴그룹 -->
<? for($i = 0; $i < count($group_1); $i++) : ?>
<tr class='ht <?=($i%2)?"group_bg1":"group_bg2"?>' onMouseOver="this.style.backgroundColor='#FFFFE0'" onMouseOut="this.style.backgroundColor=''">
	<td class="left-pad1">
	<span>└&nbsp;<img src="<?=$group_1[$i][btnimage]?>" class="btnsetup" onClick="zm_gourl('./zm.builder_write.php?recno=<?=$group_1[$i][recno]?>');"></span>
	<span class="<?=($g_1_r == $group_1[$i][recno])?"fbold":"level_1"?>"><font color="<?=($group_1[$i][more])?"#6E6E6E":""?>"><?=$group_1[$i][groupname]?></font></span>
	</td>
	<td><a href="<?=$group_1[$i][go_href]?>" target="_blank"><span class="msg"><?=$group_1[$i][skin_dir]?></span><?=$group_1[$i][skin_url]?></a></td>
	<td><?=$group_1[$i][board]?></td>
	<td align="right"><?=$group_1[$i][rank]?></td>
	<td align="center"><?=($group_1[$i][more])?"√":""?></td>
	<td><?=$group_1[$i][subdomain]?> <? if($group_1[$i][subdomain] && $group_1[$i][href]) : ?><a href="<?=$group_1[$i][go_href]?>" target="_blank" title="<?=$group_1[$i][go_href]?>"><img src="./img/icon_preview.gif" align="absmiddle"></a><? endif; ?></td>
	<td class="mdate"><?=$group_1[$i][datetime]?></td>
</tr>
	<!-- 중분류 -->
<?	$group_2_	= read_group("2", $group_1[$i][recno]);
	for($j = 0; $j < count($group_2_); $j++) : ?>
	<tr class='ht <?=($i%2)?"group_bg1":"group_bg2"?>' onMouseOver="this.style.backgroundColor='#FFFFE0'" onMouseOut="this.style.backgroundColor=''">
		<td class="left-pad2">
		<span>└&nbsp;<img src="<?=$group_2_[$j][btnimage]?>" class="btnsetup" onClick="zm_gourl('./zm.builder_write.php?recno=<?=$group_2_[$j][recno]?>');"></span>
		<span class="<?=($g_2_r == $group_2_[$j][recno])?"fbold":"level_2"?>"><?=$group_2_[$j][groupname]?></span>
		</td>
		<td><a href="<?=$group_2_[$j][go_href]?>" target="_blank"><span class="msg"><?=$group_2_[$j][skin_dir]?></span><?=$group_2_[$j][skin_url]?></a></td>
		<td><?=$group_2_[$j][board]?></td>
		<td align="right"><?=$group_2_[$j][rank]?></td>
		<td align="center"><?=($group_2_[$j][more])?"√":""?></td>
		<td><span class="msg"><?=$group_2_[$j][subdomain]?></span></td>
		<td class="mdate"><?=$group_2_[$j][datetime]?></td>
	</tr>
		<!-- 소분류 -->
<?		$group_3_	= read_group("3", $group_2_[$j][recno]);
		for($k = 0; $k < count($group_3_); $k++) : ?>
		<tr class='ht <?=($i%2)?"group_bg1":"group_bg2"?>' onMouseOver="this.style.backgroundColor='#FFFFE0'" onMouseOut="this.style.backgroundColor=''">
			<td class="left-pad3">
			<span>└&nbsp;<img src="<?=$group_3_[$k][btnimage]?>" class="btnsetup" onClick="zm_gourl('./zm.builder_write.php?recno=<?=$group_3_[$k][recno]?>');"></span>
			<span class="<?=($g_3_r == $group_3_[$k][recno])?"fbold":"level_3"?>"><?=$group_3_[$k][groupname]?></span>
			</td>
			<td><a href="<?=$group_3_[$k][go_href]?>" target="_blank"><span class="msg"><?=$group_3_[$k][skin_dir]?></span><?=$group_3_[$k][skin_url]?></a></td>
			<td><?=$group_3_[$k][board]?></td>
			<td align="right"><?=$group_3_[$k][rank]?></td>
			<td align="center"><?=($group_3_[$k][more])?"√":""?></td>
			<td><span class="msg"><?=$group_3_[$k][subdomain]?></span></td>
			<td class="mdate"><?=$group_3_[$k][datetime]?></td>
		</tr>
<?		endfor; //-- 소분류 ?>
<?	endfor; //-- 중분류 ?>
<tr><td colspan='<?=$colspan?>' class='line2'></td></tr>
<? endfor; //-- 메뉴그룹 ?>
</table>
</form>

<div class="info">아이콘이 <img src="./img/btn_setup.gif" class="btnsetup">이면 스킨이나 메뉴 셋업 정보가 정상적으로 설정 되었음.<br>
아이콘이 <img src="./img/btn_setup_on.gif" class="btnsetup">이면 스킨이나 연결 주소 등 필요한 정보가 부족해 추가 설정 필요. <b>아이콘</b>을 <b>클릭</b>하면 <b>설정</b> 할 수 있습니다.<br>
<font color="#2F64C3"><u><b>Sub domain</b>은 서버 환경에 따라 지원되지 않을 수 있으니</u></font> 미리보기 <img src="./img/icon_preview.gif" align="absmiddle">로 확인 하시기 바랍니다.<br>
출력순위▲ : 숫자가 작은 것 부터 출력 되며 숫자가 같을 때는 나중에 등록한 것이 먼저 출력.<br>
하나의 메뉴(버튼)에는 하나의 게시판만 연결 할 수 있습니다.
</div>

<form name="form_group" method="post" enctype="multipart/form-data">
<input type="hidden" name="mode" value="save">
<input type="hidden" name="level" value="">
<input type="hidden" name="uprecno" value="">
<input type="hidden" name="group_name" value="">
<input type="hidden" name="group_skin" value="">
</form>


<script language="javascript">
//-- reg_group(등록할 메뉴 레벨, 상위 레벨 레코드 번호, 분류명, 스킨명)
function reg_group(level, uprecno, gname) {
	var f	= document.form_group;

	f.level.value	= level;
	f.uprecno.value	= uprecno;
	f.group_name.value	= gname;

	if(!gname) { alert("분류명을 입력 해 주세요."); return false; }
	if((level != '0') && !uprecno) { alert("상위 분류(메뉴)를 선택해 주세요."); return false; }
	
	f.action		= "./zm.builder_process.php";
	f.submit();
}


</script>
<?
include_once ("./admin.tail.php");
?>
</body>
</html>