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

$arr_etc_section_rank = array();
foreach ($arr_etc_section as $val) {
    $arr_etc_section_rank[$val['rank']] = array('content_idx'=> $val['content_idx'], 'content_type'=> $val['content_type'],'head_title'=>$val['head_title'], 'title'=>$val['title'], 'main_img'=>$val['main_img'], 'main_video'=>$val['main_video'], 'video_url'=>$val['video_url']);
}


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


<form name="input_form" id="input_form" action="/admin/etc_section/media_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_content_type" name="search_content_type" value="<?=$search_content_type?>">
<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">


<?
        if($def_arr_etc_section[$search_etc_section_type]['display']=='all') {
?>
    <span class="text_blue"><b>* 모바일과 공통 송출관리</b></span>
<?
}
?>

<div class="common_table news">
<table>
    <tr>
        <th>기타섹션</th>
        <td class="tl">
            <div style="width:80px; float: left"><b>PC섹션</b></div>
            <input type="radio" name="etc_section_type" value="2" onclick="change_etc_section_type('2')" <? if($search_etc_section_type==2) { echo 'checked';}?>> 인기포토&nbsp;&nbsp;
            <input type="radio" name="etc_section_type" value="1" onclick="change_etc_section_type('1')" <? if($search_etc_section_type==1) { echo 'checked';}?>> 인기영상&nbsp;&nbsp;
            <input type="radio" name="etc_section_type" value="4" onclick="change_etc_section_type('4')" <? if($search_etc_section_type==4) { echo 'checked';}?>> 카드뉴스&nbsp;&nbsp;
            </br>
            <div style="width:80px; float: left"><b>모바일섹션</b></div>
            <input type="radio" name="etc_section_type" value="3" onclick="change_etc_section_type('3')" <? if($search_etc_section_type==3) { echo 'checked';}?>> 은혜로운 영상&nbsp;&nbsp;

        </td>
    </tr>

<?
   for($i=1;$i<=$def_arr_etc_section[$search_etc_section_type]['count'];$i++) {

       $head_title      = '';
       $title           = '';
       $main_img        = '';
       $main_img_txt    = '';
       $main_video      = '';
       $main_video_txt  = '';
       $content_idx     = '';
       $content_type    = '';
       $content_name    = '';
       $video_url       = '';
       if(isset($arr_etc_section_rank[$i])== true) {
            $head_title     = $arr_etc_section_rank[$i]['head_title'];
            $head_title     = htmlspecialchars($head_title);
            $title          = $arr_etc_section_rank[$i]['title'];
            $title 	        = htmlspecialchars($title);
            $content_idx    = $arr_etc_section_rank[$i]['content_idx'];
            $main_img       = $arr_etc_section_rank[$i]['main_img'];
            $content_type   = $arr_etc_section_rank[$i]['content_type'];
            $video_url      = $arr_etc_section_rank[$i]['video_url'];
            $content_name   = $def_arr_content[$content_type];

            $video_url = str_replace('https://www.youtube.com/embed/','', $video_url);

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

       }

       switch($search_etc_section_type) {
           case '1': $rowspan = '5';break;
           case '2': $rowspan = '4';break;
           case '3': $rowspan = '5';break;
           case '4': $rowspan = '4';break;
           default : $rowspan = '4';break;

       }



?>


        <tr>
            <th rowspan="<?=$rowspan?>"><?=$i?>위</th>
            <td class="tl">
                <input type="hidden" name="content_type<?=$i?>" id="content_type<?=$i?>" value="<?=$content_type?>">
                <input type="hidden" name="content_idx<?=$i?>" id="content_idx<?=$i?>" value="<?=$content_idx?>">
                <input type="text" name="head_title<?=$i?>" id="head_title<?=$i?>" class="type02" size="20" placeholder="말머리" value="<?=$head_title?>">
                <input type="text" name="title<?=$i?>" id="title<?=$i?>" size="50" class="type00" placeholder="제목을 입력해주세요." value="<?=$title?>">
            </td>
        </tr>
        <tr>
            <td class="tl">
                <input type="text" name="content_name<?=$i?>" id="content_name<?=$i?>" class="type02" placeholder="카테고리" value="<?=$content_name?>" readonly>
            </td>
        </tr>
        <tr>
            <td class="tl">이미지첨부
                <div id="img_view<?=$i?>"><?=$main_img_txt?></div>
                <input type="hidden" name="img<?=$i?>" id="img<?=$i?>">
                <input type="hidden" name="org_img<?=$i?>" id="org_img<?=$i?>" value="<?=$main_img?>">
                <input type="file" name="main_img<?=$i?>" id="main_img<?=$i?>" class="input00" size="20" accept="image/*">
            </td>
        </tr>
    <? if($search_etc_section_type!='2' && $search_etc_section_type!='4') {?>

       <td class="tl">
            youtube url </br>https://youtu.be/<input type="text" name="video_url<?=$i?>" id="video_url<?=$i?>" class="input00" value="<?=$video_url?>" style="width:200px"> (키만 넣어주세요.)
        </td>

    <?  }?>


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

            </td>
        </tr>
<?



   }
?>

</table>
</div>


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

</div>

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


<script type="text/javascript">
function open_search_article(key){
    $("#key").val(key);
    $("#article_keyword").val('');
    commonLayerOpen('search_article');
    $("#article_keyword").focus();
}


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

var etc_count_count = "<?=$def_arr_etc_section[$search_etc_section_type]['count']?>";
function media_list_reg_proc(){
    for(i=1;i<=etc_count_count;i++) {
        if($("#title"+i).val()!='') {
            if($("#content_idx"+i).val()==''){
                alert("기사를 선택해주세요.");
                return false;
            }
            if($("#main_img"+i).val()=='' && $("#img"+i).val()=='' && $("#org_img"+i).val()=='') {
                alert("이미지를 입력해주세요.");
                return false;
            }

<?  if($search_etc_section_type!='2' && $search_etc_section_type!='4') {?>
            if($("#video_url"+i).val()=='') {
                alert("영상을 입력해주세요.");
                return false;
            }


<?  }?>
         }

    }

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

}

</script>