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

$head_title         = $result['head_title'];
$head_title 		= htmlspecialchars($head_title);
$title              = $result['title'];
$title 		        = htmlspecialchars($title);
$content_idx        = $result['content_idx'];
$main_img           = $result['main_img'];
$etc_section_type   = $result['etc_section_type'];
$content_type       = $result['content_type'];
$video_url          = $result['video_url'];
$rank               = $result['rank'];
$content_name       = $def_arr_content[$content_type];
$video_url = str_replace('https://www.youtube.com/embed/','', $video_url);

$main_img_txt = '';
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;

}

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

<form name="input_form" id="input_form" action="/admin/etc_section/media_edit_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_ranking_type" name="search_content_type" value="<?=$search_content_type?>">
<input type="hidden" id="search_category_code1" 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">


<div class="common_table news">
<h2 class="subtitle"><?=$def_arr_etc_section[$etc_section_type]['name']?></h2>
<table>
    <tr>
            <th rowspan="<?=$rowspan?>"><?=$rank?>위</th>
            <td class="tl">
                <input type="hidden" name="content_type" id="content_type" value="<?=$content_type?>">
                <input type="hidden" name="content_idx" id="content_idx" value="<?=$content_idx?>">
                <input type="text" name="head_title" id="head_title" class="type02" size="20" placeholder="말머리" value="<?=$head_title?>">
                <input type="text" name="title" id="title" size="50" class="type00" placeholder="제목을 입력해주세요." value="<?=$title?>">
            </td>
        </tr>
        <tr>
            <td class="tl">
                <input type="text" name="content_name" id="content_name" class="type02" placeholder="카테고리" value="<?=$content_name?>" readonly>
            </td>
        </tr>
        <tr>
            <td class="tl">이미지첨부
                <div id="img_view"><?=$main_img_txt?></div>
                <input type="hidden" name="img" id="img">
                <input type="hidden" name="org_img" id="org_img" value="<?=$main_img?>">
                <input type="file" name="main_img" id="main_img" class="input00" size="20" accept="image/*">
            </td>
        </tr>
    <? if($etc_section_type!='2' && $etc_section_type!='4') {?>
        <tr>
            <td class="tl">
                youtube url </br>https://youtu.be/<input type="text" name="video_url" id="video_url" class="input00" value="<?=$video_url?>" style="width:200px"> (키만 넣어주세요.)
            </td>
        </tr>
    <?  }?>


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

            </td>
        </tr>

</table>
</div>
<div class="write_btn tc">
	<a href="javascript:media_edit_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 media_edit_proc(){
    if($("#title").val()!='') {
        if($("#content_idx").val()==''){
            alert("기사를 선택해주세요.");
            return false;
        }
        if($("#main_img").val()=='' && $("#img").val()=='' && $("#org_img").val()=='') {
            alert("메인이미지를 입력해주세요.");
            return false;
        }
<?  if($etc_section_type!='2' && $etc_section_type!='4') {?>
        if($("#video_url").val()=='') {
            alert("영상을 입력해주세요.");
            return false;
        }

<?  }?>


    }





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

}

</script>