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

// v3.0.2
if(!in_array('editor', $amina_keys)) {
    sql_query(" alter table {$g4['amina']} add editor tinyint(4) default '0' NOT NULL ", false);
	sql_query(" alter table {$g4['amina']} add resize tinyint(4) default '0' NOT NULL ", false);
}

// v3.0.3
if(!in_array('uploader', $amina_keys)) {
    sql_query(" alter table {$g4['amina']} add uploader tinyint(4) default '0' NOT NULL ", false);
}

// v3.1.0
if(!in_array('move', $amina_keys)) {
    sql_query(" alter table {$g4['amina']} add move tinyint(4) default '0' NOT NULL ", false);
	sql_query(" alter table {$g4['amina']} add move_bo varchar(20) default '' NOT NULL ", false);
    sql_query(" alter table {$g4['amina']} add move_ca varchar(255) default '' NOT NULL ", false);
	sql_query(" alter table {$g4['amina']} add move_term smallint(6) default '0' NOT NULL ", false);
	sql_query(" alter table {$g4['amina']} add move_hit smallint(6) default '0' NOT NULL ", false);
	sql_query(" alter table {$g4['amina']} add move_cmt smallint(6) default '0' NOT NULL ", false);
    sql_query(" alter table {$g4['amina']} add move_good tinyint(4) default '0' NOT NULL ", false);
	sql_query(" alter table {$g4['amina']} add move_cnt smallint(6) default '0' NOT NULL ", false);

    sql_query(" alter table {$g4['amina']} add wm tinyint(4) default '0' NOT NULL ", false);
    sql_query(" alter table {$g4['amina']} add wm_file varchar(255) default '' NOT NULL ", false);
	sql_query(" alter table {$g4['amina']} add wm_loc varchar(20) default '' NOT NULL ", false);
	sql_query(" alter table {$g4['amina']} add wm_x smallint(6) default '0' NOT NULL ", false);
	sql_query(" alter table {$g4['amina']} add wm_y smallint(6) default '0' NOT NULL ", false);
}

// v3.1.4
if(!in_array('limit_down_cmt', $amina_keys)) {
    sql_query(" alter table {$g4['amina']} add limit_down_cmt tinyint(4) default '0' NOT NULL ", false);
    sql_query(" alter table {$g4['amina']} add limit_down_good tinyint(4) default '0' NOT NULL ", false);
    sql_query(" alter table {$g4['amina']} add limit_down_star tinyint(4) default '0' NOT NULL ", false);
    sql_query(" alter table {$g4['amina']} add limit_down_poll tinyint(4) default '0' NOT NULL ", false);
    sql_query(" alter table {$g4['amina']} add limit_good_down tinyint(4) default '0' NOT NULL ", false);
    sql_query(" alter table {$g4['amina']} add limit_good_cmt tinyint(4) default '0' NOT NULL ", false);
    sql_query(" alter table {$g4['amina']} add limit_good_star tinyint(4) default '0' NOT NULL ", false);
    sql_query(" alter table {$g4['amina']} add limit_good_poll tinyint(4) default '0' NOT NULL ", false);
    sql_query(" alter table {$g4['amina']} add limit_poll_down tinyint(4) default '0' NOT NULL ", false);
    sql_query(" alter table {$g4['amina']} add limit_poll_cmt tinyint(4) default '0' NOT NULL ", false);
    sql_query(" alter table {$g4['amina']} add limit_poll_good tinyint(4) default '0' NOT NULL ", false);
    sql_query(" alter table {$g4['amina']} add limit_poll_star tinyint(4) default '0' NOT NULL ", false);
    sql_query(" alter table {$g4['amina']} add limit_star_down tinyint(4) default '0' NOT NULL ", false);
    sql_query(" alter table {$g4['amina']} add limit_star_cmt tinyint(4) default '0' NOT NULL ", false);
    sql_query(" alter table {$g4['amina']} add limit_star_good tinyint(4) default '0' NOT NULL ", false);
    sql_query(" alter table {$g4['amina']} add limit_star_poll tinyint(4) default '0' NOT NULL ", false);
}

// v3.1.5
if(!in_array('lucky_rate', $amina_keys)) {
	sql_query(" alter table {$g4['amina']} add move_star smallint(6) default '0' NOT NULL ", false);
    sql_query(" alter table {$g4['amina']} add move_score decimal(4,2) default '0' NOT NULL ", false);
	sql_query(" alter table {$g4['amina']} add lucky_rate smallint(6) default '0' NOT NULL ", false);
    sql_query(" alter table {$g4['amina']} add lucky_point smallint(6) default '0' NOT NULL ", false);
}

// v3.1.7
if(!in_array('daum_view', $amina_keys)) {
    sql_query(" alter table {$g4['amina']} add auto_sns tinyint(4) default '0' NOT NULL ", false);
    sql_query(" alter table {$g4['amina']} add daum_view tinyint(4) default '0' NOT NULL ", false);
}

// v3.2.5
if(!in_array('syndi', $amina_keys)) {
    sql_query(" alter table {$g4['amina']} add autosave tinyint(4) default '0' NOT NULL ", false);
    sql_query(" alter table {$g4['amina']} add mileage tinyint(4) default '0' NOT NULL ", false);
    sql_query(" alter table {$g4['amina']} add syndi tinyint(4) default '0' NOT NULL ", false);
}

//Chk Resize - Quality Range 1 ~ 100
if($upimg_quality > 100) {
	$upimg_quality = 100;
} else if($upimg_quality < 1) {
	$upimg_quality = 1;
} 

$emo_cnt = get_emo_cnt(AMINA_PATH.'/skin/emo/'.$emo_skin);

$sql_common = " bo_table			= '$bo_table'
                , gr_id				= '$gr_id'
				, bo_type			= '$bo_type'
				, auto_rss			= '$auto_rss'
                , video				= '$video'
				, google_map		= '$google_map'
				, view_code			= '$view_code'
				, poll_level		= '$poll_level'
				, poll_point		= '$poll_point'
				, tag				= '$tag'
				, tag_mb			= '$tag_mb'
				, nameless_write	= '$nameless_write'
				, nameless_cmt		= '$nameless_cmt'
				, nameless_head		= '$nameless_head'
				, nameless_tail		= '$nameless_tail'
                , view_photo		= '$view_photo'
				, cmt_photo			= '$cmt_photo'
                , emo_skin			= '$emo_skin'
                , emo_cnt			= '$emo_cnt'
				, limit_post		= '$limit_post'
                , limit_post_cnt	= '$limit_post_cnt'
				, limit_cmt			= '$limit_cmt'
                , limit_date		= '$limit_date'
				, shingo			= '$shingo'
                , upimg_size		= '$upimg_size'
                , upimg_quality		= '$upimg_quality'
				, good_point		= '$good_point'
                , good_repoint		= '$good_repoint'
                , star				= '$star'
                , star_color		= '$star_color'
                , star_point		= '$star_point'
                , star_repoint		= '$star_repoint'
				, cmt_cool			= '$cmt_cool'
				, cmt_cool_txt		= '$cmt_cool_txt'
				, cmt_bad_txt		= '$cmt_bad_txt'
				, cmt_good			= '$cmt_good'
				, cmt_best			= '$cmt_best'
				, cmt_good_txt		= '$cmt_good_txt'
				, cmt_good_point	= '$cmt_good_point'
				, cmt_good_repoint	= '$cmt_good_repoint'
				, cmt_choice		= '$cmt_choice'
				, cmt_choice_return	= '$cmt_choice_return'
				, cmt_choice_txt	= '$cmt_choice_txt'
				, po_view			= '$po_view'
				, po_view_cnt		= '$po_view_cnt'
				, po_view_day		= '$po_view_day'
				, po_view_time		= '$po_view_time'
				, po_view_term		= '$po_view_term'
				, po_view_fee		= '$po_view_fee'
				, po_view_free		= '$po_view_free'
				, po_view_level		= '$po_view_level'
				, po_down			= '$po_down'
				, po_down_cnt		= '$po_down_cnt'
				, po_down_day		= '$po_down_day'
				, po_down_time		= '$po_down_time'
				, po_down_term		= '$po_down_term'
				, po_down_fee		= '$po_down_fee'
				, po_down_free		= '$po_down_free'
				, po_down_level		= '$po_down_level'
				, editor			= '$editor'
				, resize			= '$resize'
				, uploader			= '$uploader'
				, move				= '$move'
				, move_bo			= '$move_bo'
				, move_ca			= '$move_ca'
				, move_term			= '$move_term'
				, move_hit			= '$move_hit'
				, move_cmt			= '$move_cmt'
				, move_good			= '$move_good'
				, move_cnt			= '$move_cnt'
				, move_star			= '$move_star'
				, move_score		= '$move_score'
				, lucky_rate		= '$lucky_rate'
				, lucky_point		= '$lucky_point'
				, wm				= '$wm'
				, wm_file			= '$wm_file'
				, wm_loc			= '$wm_loc'
				, wm_x				= '$wm_x'
				, wm_y				= '$wm_y'
				, limit_down_cmt	= '$limit_down_cmt'
				, limit_down_star	= '$limit_down_star'
				, limit_down_poll	= '$limit_down_poll'
				, limit_down_good	= '$limit_down_good'
				, limit_good_cmt	= '$limit_good_cmt'
				, limit_good_star	= '$limit_good_star'
				, limit_good_poll	= '$limit_good_poll'
				, limit_good_down	= '$limit_good_down'
				, limit_star_cmt	= '$limit_star_cmt'
				, limit_star_poll	= '$limit_star_poll'
				, limit_star_down	= '$limit_star_down'
				, limit_star_good	= '$limit_star_good'
				, limit_poll_cmt	= '$limit_poll_cmt'
				, limit_poll_star	= '$limit_poll_star'
				, limit_poll_down	= '$limit_poll_down'
				, limit_poll_good	= '$limit_poll_good'
				, auto_sns			= '$auto_sns'
				, daum_view			= '$daum_view'
				, autosave			= '$autosave'
				, mileage			= '$mileage'
				, syndi				= '$syndi'
				";

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

// 공지글 순서변경
if($chk_notice) sql_query(" update {$g4['board_table']} set bo_notice = '$bo_notice' where bo_table = '$bo_table' ");

// 같은 그룹내 게시판 동일 옵션 적용
$s = "";
if ($chk_type) $s .= " , bo_type = '$bo_type' ";
if ($chk_rss) $s .= " , auto_rss = '$auto_rss' ";
if ($chk_sns) $s .= " , auto_sns = '$auto_sns' ";
if ($chk_syndi) $s .= " , syndi = '$syndi' ";
if ($chk_daum_view) $s .= " , daum_view = '$daum_view' ";
if ($chk_editor) $s .= " , editor = '$editor' ";
if ($chk_autosave) $s .= " , autosave = '$autosave' ";
if ($chk_uploader) $s .= " , uploader = '$uploader' ";
if ($chk_video) $s .= " , video = '$video' ";
if ($chk_map) $s .= " , google_map = '$google_map' ";
if ($chk_code) $s .= " , view_code = '$view_code' ";
if ($chk_poll) $s .= " , poll_level = '$poll_level' , poll_point = '$poll_point' ";
if ($chk_tag) $s .= " , tag = '$tag' , tag_mb = '$tag_mb' ";
if ($chk_nameless) $s .= " , nameless_write = '$nameless_write' , nameless_cmt = '$nameless_cmt' , nameless_head = '$nameless_head', nameless_tail = '$nameless_tail' ";
if ($chk_photo) $s .= " , view_photo = '$view_photo' , cmt_photo = '$cmt_photo' , emo_skin = '$emo_skin' , emo_cnt = '$emo_cnt' ";
if ($chk_wm) $s .= " , wm = '$wm' , wm_file = '$wm_file' , wm_loc = '$wm_loc' , wm_x = '$wm_x' , wm_y = '$wm_y' ";
if ($chk_shingo) $s .= " , shingo = '$shingo' ";
if ($chk_resize) $s .= " , resize = '$resize' , upimg_size = '$upimg_size' , upimg_quality = '$upimg_quality' ";
if ($chk_limit) $s .= " , limit_post = '$limit_post' , limit_post_cnt = '$limit_post_cnt' ";
if ($chk_point) $s .= " , limit_cmt = '$limit_cmt' , limit_date = '$limit_date' ";
if ($chk_limit_down) $s .= " , limit_down_cmt = '$limit_down_cmt' , limit_down_star = '$limit_down_star' , limit_down_poll = '$limit_down_poll' , limit_down_good = '$limit_down_good' ";
if ($chk_limit_good) $s .= " , limit_good_cmt = '$limit_good_cmt' , limit_good_star = '$limit_good_star' , limit_good_poll = '$limit_good_poll' , limit_good_down = '$limit_good_down' ";
if ($chk_limit_star) $s .= " , limit_star_cmt = '$limit_star_cmt' , limit_star_poll = '$limit_star_poll' , limit_star_down = '$limit_star_down' , limit_star_good = '$limit_star_good' ";
if ($chk_limit_poll) $s .= " , limit_poll_cmt = '$limit_poll_cmt' , limit_poll_star = '$limit_poll_star' , limit_poll_down = '$limit_poll_down' , limit_poll_good = '$limit_poll_good' ";
if ($chk_move) $s .= " , move = '$move' , move_bo = '$move_bo' , move_ca = '$move_ca' , move_term = '$move_term' , move_hit = '$move_hit' , move_cmt = '$move_cmt' , move_good = '$move_good' , move_cnt = '$move_cnt' , move_star = '$move_star' , move_score = '$move_score' ";
if ($chk_good) $s .= " , good_point = '$good_point' , good_repoint = '$good_repoint' ";
if ($chk_lucky) $s .= " , lucky_rate = '$lucky_rate' , lucky_point = '$lucky_point' ";
if ($chk_star) $s .= " , star = '$star' , star_color = '$star_color' , star_point = '$star_point' , star_repoint = '$star_repoint' ";
if ($chk_cool) $s .= " , cmt_cool = '$cmt_cool' , cmt_cool_txt = '$cmt_cool_txt' , cmt_bad_txt = '$cmt_bad_txt' ";
if ($chk_cgood) $s .= " , cmt_good = '$cmt_good' , cmt_best = '$cmt_best' , cmt_good_txt = '$cmt_good_txt' , cmt_good_point = '$cmt_good_point' , cmt_good_repoint = '$cmt_good_repoint' ";
if ($chk_choice) $s .= " , cmt_choice = '$cmt_choice' , cmt_choice_return = '$cmt_choice_return' , cmt_choice_txt = '$cmt_choice_txt' ";
if ($chk_mileage) $s .= " , mileage = '$mileage' ";
if ($chk_po_view) {
		$s .= " , po_view = '$po_view' , po_view_cnt = '$po_view_cnt' , po_view_day = '$po_view_day' , po_view_time = '$po_view_time' , po_view_term = '$po_view_term' , po_view_fee = '$po_view_fee' , po_view_free = '$po_view_free' , po_view_level = '$po_view_level' ";
}
if ($chk_po_down) {
		$s .= " , po_down = '$po_down' , po_down_cnt = '$po_down_cnt' , po_down_day = '$po_down_day' , po_down_time = '$po_down_time' , po_down_term = '$po_down_term' , po_down_fee = '$po_down_fee' , po_down_free = '$po_down_free' , po_down_level = '$po_down_level' ";
}

if ($s){
    $sql = " select bo_table from {$g4['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 {$g4['amina']} where bo_table = '{$row['bo_table']}' ");
		if ($row1[cnt]) {
			sql_query(" update {$g4['amina']} set bo_table = bo_table, gr_id = gr_id {$s} where bo_table = '{$row['bo_table']}' ");
		} else {
		    sql_query(" insert into {$g4['amina']} set bo_table = '{$row['bo_table']}', gr_id = '$gr_id' {$s} ");
		}
    }	
}

?>
