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

// v3.2.0
if(!in_array('deco_list', $amina_keys)) {
    sql_query(" alter table {$g5['amina_skin']} add deco_list varchar(255) default '' NOT NULL ", false);
    sql_query(" alter table {$g5['amina_skin']} add deco_view varchar(255) default '' NOT NULL ", false);
    sql_query(" alter table {$g5['amina_skin']} add deco_write varchar(255) default '' NOT NULL ", false);
}

// v3.2.4
if(!in_array('attach_skin', $amina_keys)) {
    sql_query(" alter table {$g5['amina_skin']} add attach_skin varchar(255) default '' NOT NULL ", false);
    sql_query(" alter table {$g5['amina_skin']} add attach_css varchar(255) default '' NOT NULL ", false);
    sql_query(" alter table {$g5['amina_skin']} add attach_set varchar(255) default '' NOT NULL ", false);
}

// ASR 1.0.0
if(!in_array('btn_css', $amina_keys)) {
	sql_query(" alter table {$g5['amina_skin']} add write_css varchar(255) default '' NOT NULL AFTER write_skin", false);
	sql_query(" alter table {$g5['amina_skin']} add write_set varchar(255) default '' NOT NULL AFTER write_css", false);
	sql_query(" alter table {$g5['amina_skin']} add btn_css varchar(255) default '' NOT NULL AFTER btn_skin", false);
}


//Load Skin Set Value
@include_once(AMINA_PATH.'/skin/addon/'.$addon_skin.'/set/set.save.php');
@include_once(AMINA_PATH.'/skin/info/'.$info_skin.'/set/set.save.php');
@include_once(AMINA_PATH.'/skin/list/'.$list_skin.'/set/set.save.php');
@include_once(AMINA_PATH.'/skin/view/'.$view_skin.'/set/set.save.php');
@include_once(AMINA_PATH.'/skin/sign/'.$sign_skin.'/set/set.save.php');
@include_once(AMINA_PATH.'/skin/tag/'.$tag_skin.'/set/set.save.php');
@include_once(AMINA_PATH.'/skin/attach/'.$attach_skin.'/set/set.save.php');
@include_once(AMINA_PATH.'/skin/write/'.$write_skin.'/set/set.save.php');

//Linked Tab
$linked_tab = '';
if($loc != "m") {
	for ($i=0; $i<count($linked_type); $i++) {
		if(!$linked_id[$i]) continue;
		$linked_tab .= $linked_type[$i].'|'.$linked_id[$i].'|'.$linked_name[$i].'|'.$linked_view[$i].'|'.$linked_post[$i].'|'.$linked_row[$i].'|'.$linked_opt[$i]."\n";
	}
}

$sql_common = " bo_table			= '$bo_table'
				, sca				= '$sca'
				, skin_type			= '$skin_type'
				, cate_skin			= '$cate_skin'
                , cate_css			= '$cate_css'
				, head_skin			= '$head_skin'
                , head_css			= '$head_css'
				, list_skin			= '$list_skin'
                , list_css			= '$list_css'
                , list_set			= '$list_set'
                , list_rows			= '$list_rows'
				, view_skin			= '$view_skin'
                , view_css			= '$view_css'
                , view_set			= '$view_set'
                , view_good			= '$view_good'
                , view_sns			= '$view_sns'
                , star_skin			= '$star_skin'
				, poll_skin			= '$poll_skin'
				, preview_skin		= '$preview_skin'
				, related_skin		= '$related_skin'
				, cmt_skin			= '$cmt_skin'
                , cmt_css			= '$cmt_css'
                , cmt_rows			= '$cmt_rows'
                , cmt_sns			= '$cmt_sns'
				, sign_skin			= '$sign_skin'
                , sign_css			= '$sign_css'
                , sign_set			= '$sign_set'
				, tag_skin			= '$tag_skin'
				, tag_css			= '$tag_css'
				, tag_set			= '$tag_set'
				, linked_tab		= '$linked_tab'
				, linked_skin		= '$linked_skin'
				, linked_css		= '$linked_css'
				, addon_skin		= '$addon_skin'
                , addon_css			= '$addon_css'
                , addon_set			= '$addon_set'
                , info_skin			= '$info_skin'
                , info_css			= '$info_css'
				, info_set			= '$info_set'
				, write_skin		= '$write_skin'
				, write_css			= '$write_css'
				, write_set			= '$write_set'
				, page_skin			= '$page_skin'
                , page_css			= '$page_css'
                , page_rows			= '$page_rows'
				, btn_skin			= '$btn_skin'
				, btn_css			= '$btn_css'
				, deco_list			= '$deco_list'
				, deco_view			= '$deco_view'
				, deco_write		= '$deco_write'
				, attach_skin		= '$attach_skin'
				, attach_css		= '$attach_css'
				, attach_set		= '$attach_set'
				";

// 등록하기
$row = sql_fetch(" select count(*) as cnt from {$g5['amina_skin']} where bo_table = '$bo_table' and skin_type = '$skin_type' and sca = '$sca' ");
if ($row['cnt']) {
	sql_query(" update {$g5['amina_skin']} set $sql_common where bo_table = '$bo_table' and skin_type = '$skin_type' and sca = '$sca' ");
} else {
    sql_query(" insert into {$g5['amina_skin']} set $sql_common ");
}

$s = "";
if(!$sca) { // 분류별 설정이 아닐 경우 같은 그룹내 게시판 동일 옵션 적용
	if ($chk_cate) $s .= " , cate_skin = '$cate_skin' , cate_css = '$cate_css' ";
	if ($chk_head) $s .= " , head_skin = '$head_skin' , head_css = '$head_css' ";
	if ($chk_list) $s .= " , list_skin = '$list_skin' , list_css = '$list_css' , list_set = '$list_set' , list_rows = '$list_rows'  ";
	if ($chk_view) $s .= " , view_skin = '$view_skin' , view_css = '$view_css' , view_set = '$view_set' , view_good = '$view_good' , view_sns = '$view_sns' , star_skin = '$star_skin' , poll_skin = '$poll_skin' , preview_skin = '$preview_skin' , related_skin = '$related_skin' ";
	if ($chk_cmt) $s .= " , cmt_skin = '$cmt_skin' , cmt_css = '$cmt_css' , cmt_sns = '$cmt_sns' , cmt_rows = '$cmt_rows' ";
	if ($chk_attach) $s .= " , attach_skin = '$attach_skin' , attach_css = '$attach_css' , attach_set = '$attach_set' ";
	if ($chk_sign) $s .= " , sign_skin = '$sign_skin' , sign_css = '$sign_css' , sign_set = '$sign_set' ";
	if ($chk_tag) $s .= " , tag_skin = '$tag_skin' , tag_css = '$tag_css' , tag_set = '$tag_set' ";
	if ($chk_linked) $s .= " , linked_skin = '$linked_skin', linked_css = '$linked_css', linked_tab = '$linked_tab' ";
	if ($chk_deco) $s .= " , deco_list = '$deco_list' , deco_view = '$deco_view' , deco_write = '$deco_write' ";
	if ($chk_addon) $s .= " , addon_skin = '$addon_skin' , addon_css = '$addon_css' , addon_set = '$addon_set' ";
	if ($chk_info) $s .= " , info_skin = '$info_skin' , info_css = '$info_css' , info_set = '$info_set' ";
	if ($chk_write) $s .= " , write_skin = '$write_skin' , write_css = '$write_css' , write_set = '$write_set' ";
	if ($chk_page) $s .= " , page_skin = '$page_skin' , page_css = '$page_css' , page_rows = '$page_rows' ";
	if ($chk_btn) $s .= " , btn_skin = '$btn_skin' , btn_css = '$btn_css' ";
}

if ($s){
    $sql = " select bo_table from {$g5['board_table']} where gr_id = '$gr_id' and bo_table != '$bo_table' order by bo_table ";
    $result = sql_query($sql);
    for ($i=0; $row=sql_fetch_array($result); $i++) {
		$row1 = sql_fetch(" select count(*) as cnt from {$g5['amina_skin']} where bo_table = '{$row['bo_table']}' and skin_type = '{$skin_type}' and sca = '' ");
		if ($row1['cnt']) {
			sql_query(" update {$g5['amina_skin']} set bo_table = bo_table , skin_type = '{$skin_type}', sca = '' {$s} where bo_table = '{$row['bo_table']}' and skin_type = '{$skin_type}' and sca = '' ");
		} else {
		    sql_query(" insert into {$g5['amina_skin']} set bo_table = '{$row['bo_table']}' , skin_type = '{$skin_type}', sca = '' {$s} ");
		}
    }	
}

?>
