<?php
include_once ("./static_data/code.php");

$arr_life_etc_section_rank = array();
foreach ($arr_etc_section as $val) {
    $arr_life_etc_section_rank[$val['rank']] = array('idx'=> $val['idx'], 'category_idx'=> $val['category_idx'], 'channel_idx'=> $val['channel_idx'], 'editor_idx'=> $val['partner_idx']);
}
//
//echo "<pre>";
//
//var_dump($arr_etc_section_detail);


$arr_life_etc_section_detail_rank = array();
foreach ($arr_etc_section_detail as $val) {
    $arr_life_etc_section_detail_rank[$val['life_etc_section_idx']][$val['rank']] = array('main_img'=> $val['main_img'], 'head_title'=> $val['head_title'], 'title'=> $val['title'], 'content_idx'=> $val['content_idx'], 'hit_count'=>$val['hit_count'], 'editor_name'=>$val['editor_name']);
}

$menu_code = '68';
require_once (APPPATH.'views/skin/admin/_content_comm.php');


//exit();


?>


<form name="input_form" id="input_form" action="/admin/etc_section/editor_list_reg_proc" method="post" enctype="multipart/form-data">
<input type="hidden" name="idx" id="idx" value="<?=$idx?>">
<input type="hidden" id="search_type" name="search_type" value="<?=$search_type?>">
<input type="hidden" id="search_keyword" name="search_keyword" value="<?=$search_keyword?>">
<input type="hidden" id="search_category" name="search_category" value="<?=$search_category?>">
<input type="hidden" id="search_etc_section_type" name="search_etc_section_type" value="<?=$search_etc_section_type?>">
<input type="hidden" id="sort" name="sort" value="<?=$sort?>">
<input type="hidden" id="page" name="page" value="<?=$page?>">
<input type="hidden" id="key" name="key">
<input type="hidden" id="rank1" name="rank1">
<input type="hidden" id="rank2" name="rank2">



<div class="common_table news">
<table>
    <tr>
        <th>기타섹션</th>
        <td class="tl">
            <div style="width:80px; float: left"><b>모바일섹션</b></div>
            <?  foreach ($def_arr_editor_etc_section as $val) {    ?>
                    <input type="radio" name="etc_section_type" value="<?=$val['code']?>" onclick="change_etc_section_type('<?=$val['code']?>')" <? if($search_etc_section_type==$val['code']) { echo 'checked';}?>> <?=$val['name']?>&nbsp;&nbsp;
            <?  }?>
        </td>
    </tr>

<?
    for($i=1;$i<=$def_arr_editor_etc_section[$search_etc_section_type]['count'];$i++) {
        $category_code1         = '';
        $category_code2         = '';
        $life_etc_section_idx   = '';
        if(isset($arr_life_etc_section_rank[$i])== true) {
            $life_etc_section_idx   = $arr_life_etc_section_rank[$i]['idx'];
            $category_code1         = $arr_life_etc_section_rank[$i]['category_idx'];
            $category_code2         = $arr_life_etc_section_rank[$i]['channel_idx'];
            $category_code3         = $arr_life_etc_section_rank[$i]['editor_idx'];
       }


?>
    <tr><th colspan="2">에디터 <?=$i?>위</th></tr>
    <tr>
        <th>카테고리선택</th>
        <td class="tl">
            <select name="category1_<?=$i?>" id="category1_<?=$i?>" onchange="change_category(1, this.value, '<?=$i?>')" class="type01">
			    <option value="">선택</option>
	<?	if(count($arr_category1) > 0) {
			foreach ($arr_category1 as $val) {?>
					<option value="<?=$val['idx']?>" <? if($category_code1==$val['idx']) { echo 'selected'; }?>><?=$val['category_name']?></option>
	<?		}
		}	?>
		    </select>
        </td>
    </tr>
     <tr>
        <th>채널선택</th>
        <td class="tl">
            <select name="category2_<?=$i?>" id="category2_<?=$i?>" class="type01"  onchange="change_category(2, this.value, '<?=$i?>')">
			<option value="">선택</option>
	<?	if(count($arr_category2) > 0 && $category_code2!='') {
			foreach ($arr_category2 as $val) {?>
					<option value="<?=$val['idx']?>" <? if($category_code2==$val['idx']) { echo 'selected'; }?>><?=$val['channel_name']?></option>
	<?		}
		}	?>
		</select>
        </td>
    </tr>
    <tr>
        <th>에디터선택</th>
        <td class="tl">
            <select name="category3_<?=$i?>" id="category3_<?=$i?>" class="type01"  onchange="change_category(3, this.value, '<?=$i?>')">
			<option value="">선택</option>
	<?	if(count($arr_category3) > 0 && $category_code3!='') {
			foreach ($arr_category3 as $val) {?>
					<option value="<?=$val['idx']?>" <? if($category_code3==$val['idx']) { echo 'selected'; }?>><?=$val['partner_name']?></option>
	<?		}
		}	?>
		</select>
        </td>
    </tr>


<?
        for($z=1;$z<=$def_arr_editor_etc_section[$etc_section_type]['detail_count'];$z++) {
            $head_title     = '';
            $title          = '';
            $main_img_txt   = '';
            $main_img       = '';
            $hit_count      = '';
            $content_idx    = '';


            if(isset($arr_life_etc_section_detail_rank[$life_etc_section_idx][$z])== true) {
                $head_title     = $arr_life_etc_section_detail_rank[$life_etc_section_idx][$z]['head_title'];
                $head_title	    = htmlspecialchars($head_title);
                $title          = $arr_life_etc_section_detail_rank[$life_etc_section_idx][$z]['title'];
                $title	        = htmlspecialchars($title);
                $content_idx    = $arr_life_etc_section_detail_rank[$life_etc_section_idx][$z]['content_idx'];
                $main_img       = $arr_life_etc_section_detail_rank[$life_etc_section_idx][$z]['main_img'];
                $hit_count      = $arr_life_etc_section_detail_rank[$life_etc_section_idx][$z]['hit_count'];

                if($main_img!='') $main_img_txt = '<img src="'.$main_img.'" width=250>';

            }

             switch($etc_section_type) {
               case '4': $rowspan = '3';break;
               case '5': $rowspan = '4';break;
               case '6': $rowspan = '3';break;
               default : $rowspan = '3';break;

           }

?>

        <tr>
            <th rowspan="<?=$rowspan?>"><?=$z?>위</th>
            <td class="tl">
                <input type="hidden" name="content_idx_<?=$i?>_<?=$z?>" id="content_idx_<?=$i?>_<?=$z?>" value="<?=$content_idx?>">
                <input type="text" name="head_title_<?=$i?>_<?=$z?>" id="head_title_<?=$i?>_<?=$z?>" class="type02" size="20" placeholder="말머리" value="<?=$head_title?>">
                <input type="text" name="title_<?=$i?>_<?=$z?>" id="title_<?=$i?>_<?=$z?>" size="50" class="type00" placeholder="제목을 입력해주세요." value="<?=$title?>">
            </td>
        </tr>
        <tr>
            <td class="tl">이미지첨부
                <div id="img_view_<?=$i?>_<?=$z?>"><?=$main_img_txt?></div>
                <input type="hidden" name="img_<?=$i?>_<?=$z?>" id="img_<?=$i?>_<?=$z?>">
                <input type="hidden" name="org_img_<?=$i?>_<?=$z?>" id="org_img_<?=$i?>_<?=$z?>" value="<?=$main_img?>">
                <input type="file" name="main_img_<?=$i?>_<?=$z?>" id="main_img_<?=$i?>_<?=$z?>" class="input00" size="20" accept="image/*">
            </td>
        </tr>

<? if($etc_section_type== '5') {?>
      <tr>
            <td class="tl">
                <input type="text" name="hit_count_<?=$i?>_<?=$z?>" id="hit_count_<?=$i?>_<?=$z?>" class="type02" size="20" placeholder="조회수" value="<?=$hit_count?>">
            </td>
        </tr>
<?}?>


        <tr>
            <td class="tl">
                 <button type="button" class="btn_black" style="width:100px" onclick="open_search_article('<?=$i?>', '<?=$z?>');" style="cursor: pointer;">컨텐츠검색</button>

            </td>
        </tr>
<?



        }
    }
?>

</table>
</div>


<div class="write_btn tc">
    <a href="javascript:editor_list_reg_proc()">저장하기</a>
    <a href="/admin/etc_section/editor_list/6/<?=$page?>?search_type=<?=$search_type?>&search_keyword=<?=$search_keyword?>&search_category=<?=$search_category?>&search_etc_section_type=<?=$search_etc_section_type?>&sort=<?=$sort?>">목록으로</a>

</div>

</form>
<?
$content_type = '3';
require_once(APPPATH."views/admin/search/search_article_inc.php");
?>


<script type="text/javascript">
function change_category(depth, val, rank){

    reset(rank);

	if(depth ==  1) {

	    $('#category3_'+rank).empty();
        var option = "<option value=''>선택</option>";
        $('#category3_'+rank).append(option);



		var json_category = '<?=json_encode($arr_category2)?>';
		json_category = eval(json_category);

		$('#category2_'+rank).empty();
		$('#category2_'+rank).append(option);

		for(key in json_category) {
			if(json_category[key]['category_idx'] == val) {
				option = "<option value='"+json_category[key]['idx']+"'>"+json_category[key]['channel_name']+"</option>";
				$('#category2_'+rank).append(option);
			}
		}

	} else if(depth ==  2) {

	    $('#category3_'+rank).empty();
        var option = "<option value=''>선택</option>";
        $('#category3_'+rank).append(option);

		var json_category = '<?=json_encode($arr_category3)?>';
		json_category = eval(json_category);

		for(key in json_category) {
			if(json_category[key]['channel_idx'] == val) {
				option = $("<option value='"+json_category[key]['idx']+"'>"+json_category[key]['partner_name']+"</option>");
				$('#category3_'+rank).append(option);

			}
		}

	}
}


function open_search_article(rank1, rank2){
    $("#key").val("_"+rank1+'_'+rank2);
    $("#rank1").val(rank1);
    $("#rank2").val(rank2);
    if($("#category1_"+rank1).val()=='') {
        alert("카테고리를 선택해주세요.");
        return false;
    }
    if($("#category2_"+rank1).val()=='') {
        alert("채널을 선택해주세요.");
        return false;
    }
    if($("#category3_"+rank1).val()=='') {
        alert("에디터를 선택해주세요.");
        return false;
    }
    $("#article_keyword").val('');
    commonLayerOpen('search_article');
    $("#article_keyword").focus();
}


var etc_detail_count = "<?=$def_arr_editor_etc_section[$etc_section_type]['detail_count']?>";
function reset(rank){
    for(z=1;z<=etc_detail_count;z++) {
        $("#content_idx_"+rank+"_"+z).val('');
        $("#head_title_"+rank+"_"+z).val('');
        $("#title_"+rank+"_"+z).val('');
        $("#editor_name_"+rank+"_"+z).val('');
        $("#img_"+rank+"_"+z).val('');
        $("#org_img_"+rank+"_"+z).val('');
        $("#main_img_"+rank+"_"+z).val('');
        $("#img_view_"+rank+"_"+z).empty();
        $("#hit_count_"+rank+"_"+z).empty();
    }
}




function change_etc_section_type(val){
    $("#search_etc_section_type").val(val);
    $("#input_form").attr("action", "/admin/etc_section/editor_list_reg/6");
    $("#input_form").submit();
}

var etc_count = "<?=$def_arr_editor_etc_section[$etc_section_type]['count']?>";
var etc_detail_count = "<?=$def_arr_editor_etc_section[$etc_section_type]['detail_count']?>";
function editor_list_reg_proc(){
    for(i=1;i<=etc_count;i++) {
        if($("#category1_"+i).val()!='') {
            if($("#category2_"+i).val()==''){
                alert("채널을 선택해주세요.");
                return false;
            }
            if($("#category3_"+i).val()==''){
                alert("에디터를 선택해주세요.");
                return false;
            }
            for(z=1;z<=etc_detail_count;z++) {
                if($("#title_"+i+'_'+z).val()!='') {
                    if($("#content_idx_"+i+'_'+z).val()==''){
                        alert("기사를 선택해주세요.");
                        return false;
                    }
                    if($("#main_img_"+i+'_'+z).val()=='' && $("#img_"+i+'_'+z).val()=='' && $("#org_img_"+i+'_'+z).val()=='') {
                        alert("이미지를 입력해주세요.");
                        return false;
                    }
                }
            }
        }
    }


	$("#input_form").submit();

}

</script>
