<?php
if (!defined('_GNUBOARD_')) exit; // 개별 페이지 접근 불가
if (!defined('G5_IS_ADMIN')) define('G5_IS_ADMIN', true);

include_once(G5_ADMIN_PATH.'/admin.lib.php');

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

if ($bo_table && !$board['bo_table']) {
	alert("존재하지 않은 게시판 입니다.");
}

if ($is_admin == "group") {
	if ($member['mb_id'] != $group['gr_admin']) {
		alert("그룹이 틀립니다.");
	}
}

if ($is_admin != "super") {
    $group = get_group($board['gr_id']);
    $is_admin = is_admin($member['mb_id']);
}

function amina_skin($mode, $type, $skin_id, $skin_val, $css_val='', $set_val='') {
	global $g5;

	$arr = array();
	$set = array();

	$str = '';
	if($mode == "set") {
		$set_skin_path = AMINA_PATH.'/skin/'.$type.'/'.$skin_val.'/set';
		$set_skin_url = AMINA_URL.'/skin/'.$type.'/'.$skin_val.'/set';

		if(file_exists($set_skin_path.'/set.form.php')) {
		    ob_start();
		    include $set_skin_path.'/set.form.php';
		    $str .= ob_get_contents();
		    ob_end_clean();
		} 

	} else if ($mode == "css" || $mode == "deco") {
		if($mode == "deco") {
			$set_skin_path = AMINA_PATH.'/skin/deco/'.$type.'/';
		} else {
			$set_skin_path = AMINA_PATH.'/skin/'.$type.'/'.$skin_val.'/';
		}

		$handle = opendir($set_skin_path);
		while ($file = readdir($handle)) {
			if (preg_match("/^(.*)\.css/", $file, $matches)) {
				$arr[] = str_replace(".css","",$matches[0]); //파일명만 가져오기
			}
	    }
	    closedir($handle);

	    sort($arr);

		$str .= '<select name="'.$skin_id.'" class="w120">'."\n";
	    foreach($arr as $key=>$value) {
			$chk_sel = '';
			if($css_val == $arr[$key]) $chk_sel = ' selected';
			$str .= '<option value="'.$arr[$key].'"'.$chk_sel.'>'.$arr[$key].'</option>'."\n";
	    }
		$str .= '</select>'."\n";
	} else {
		$set_skin_path = AMINA_PATH.'/skin/'.$type.'/';

		$handle = opendir($set_skin_path);
	    while ($file = readdir($handle)) {
	        if($file == "."||$file == "..") continue;
	        if (is_dir($set_skin_path.$file)) $arr[] = $file;
	    }
	    closedir($handle);
	    sort($arr);

		$change = '';
		if($css_val || $set_val) $change = " onchange=\"amina_skin(this.value, '{$type}', '{$skin_id}', '{$css_val}', '{$set_val}');\"";

		$str .= '<select name="'.$skin_id.'"'.$change.' class="w120">'."\n";
	    foreach($arr as $key=>$value) {
			$chk_sel = '';
			if($skin_val == $arr[$key]) $chk_sel = ' selected';
			$str .= '<option value="'.$arr[$key].'"'.$chk_sel.'>'.$arr[$key].'</option>'."\n";
	    }
		$str .= '</select>'."\n";
	}

	return $str;
}

// Emo Count Function
function get_emo_cnt($dirname) {
	$i = 0;
	if(!is_dir($dirname)) return $i;
	$handle = opendir($dirname);
    while ($file = readdir($handle)) {
		if(preg_match("/(\.gif)/i", $file, $matches)) $i++;
    }
    closedir($handle);

    return $i;
}

// Chk Boxk
function get_chk($chk_name, $loc, $sca) {

	$chkbox = '*';
	if($loc == "func") {
		$chkbox = '<input type="checkbox" name="'.$chk_name.'" value="1">';
	} else {
		if(!$sca) $chkbox = '<input type="checkbox" name="'.$chk_name.'" value="1">';
	}

	return $chkbox;
}

// Chk Field
function amina_chk_field($type, $field) { //DB 테이블에 필드 존재여부 체크
	global $g5, $bo_table;

	$chk_field = false;

	//필드 체크
	if($type == "rss") {
		$sql = " select * from {$g5['board_new_table']} limit 1";
	} else if($type == "amina") {
		$sql = " select * from {$g5['amina']} limit 1";
	}

	if($sql) {
		$result=sql_query($sql, false); 
		$row = sql_fetch($sql, false);
		for($i=0; $i < count($row); $i++){ 
			$fname[$i] = mysql_field_name($result, $i);
			if($field == $fname[$i]) return $field;
		} 
	}

	return $chk_field;
}

//Load Config
$setting = array();

if(!$is_amina_setup) {
	if($loc == "func") {
		$setting = sql_fetch(" select * from {$g5['amina']} where bo_table='$bo_table' ", false);
	} else if($loc == "m") {
		if($sca) {
			$setting = sql_fetch(" select * from {$g5['amina_skin']} where bo_table='$bo_table' and skin_type = '3' and sca = '$sca' ", false);
		} else {
			$setting = sql_fetch(" select * from {$g5['amina_skin']} where bo_table='$bo_table' and skin_type = '2' and sca = '' ", false);
		}
	} else {
		if($sca) {
			$setting = sql_fetch(" select * from {$g5['amina_skin']} where bo_table='$bo_table' and skin_type = '1' and sca = '$sca' ", false);
		} else {
			$setting = sql_fetch(" select * from {$g5['amina_skin']} where bo_table='$bo_table' and skin_type = '0' and sca = '' ", false);
		}
	}
}

?>