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

if($mode=='edit') {
    $title      		= $result['title'];
    $title 				= htmlspecialchars($title);
    $content    		= $result['content'];
    $category_code  	= $result['category_code'];
    $press_idx  		= $result['press_idx'];
    $reporter_name  	= $result['reporter_name'];
    $reporter_email 	= $result['reporter_email'];
    $sub_title    		= $result['sub_title'];
    $sub_title 	        = htmlspecialchars($sub_title);
    $tag    			= $result['tag'];
    $org_url    		= $result['org_url'];
    $hit_count    		= $result['hit_count'];
    $share_count   		= $result['share_count'];
    $review_count1  	= $result['review_count1'];
    $review_count2  	= $result['review_count2'];
    $review_count3  	= $result['review_count3'];
    $review_count4  	= $result['review_count4'];
    $review_count5  	= $result['review_count5'];
    $is_auto_setting	= $result['is_auto_setting'];
    $display_date		= $result['display_date'];
	$org_main_img		= $result['main_img'];
	$life_type			= $result['life_type'];

	$category_code1		= substr($category_code, 0, 2);
	$category_code2		= substr($category_code, 0, 4);
	$category_code3		= substr($category_code, 0, 6);

	$arr_display_date  	= explode(' ', $display_date);
	$display_date		= $arr_display_date[0];
	$arr_display_time  	= explode(':', $arr_display_date[1]);
	$display_hour		= $arr_display_time[0];
	$display_min		= $arr_display_time[1];
	$display_sec		= $arr_display_time[2];

	$tag		= str_replace(' ', ',', $tag);

	foreach ($arr_theme as $val) {
		$arr_theme_reg[$val['theme_type']] = $val['rank'];
	}


} else {

    $head_title      = '';
	$title           = '';
	$theme_img		= '';
	$sub_content     = '';
	$content_idx     = '';

}

$arr_theme_rank = array();
foreach ($arr_theme as $val) {
    $arr_theme_rank[$val['rank']] = array('content_idx'=> $val['content_idx'], 'head_title'=>$val['head_title'], 'title'=>$val['title'], 'sub_title'=>$val['sub_title'], 'sub_content'=>$val['sub_content'], 'editor_name'=>$val['editor_name'], 'theme_img'=>$val['theme_img'], 'like_count'=>$val['like_count'], 'hit_count'=>$val['hit_count']);
}


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


<form name="input_form" id="input_form" action="/admin/life/life_theme_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_theme_type" name="search_theme_type" value="<?=$search_theme_type?>">
<input type="hidden" id="search_category_code1" name="search_category_code1" value="<?=$search_category_code1?>">
<input type="hidden" id="search_category_code2" name="search_category_code2" value="<?=$search_category_code2?>">
<input type="hidden" id="search_life_type" name="search_life_type" value="<?=$search_life_type?>">
<input type="hidden" id="sort" name="sort" value="<?=$sort?>">
<input type="hidden" id="page" name="page" value="<?=$page?>">
<input type="hidden" id="mode" name="mode" value="<?=$mode?>">
<input type="hidden" id="key" name="key">

<?
if($def_arr_life_theme[$search_theme_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>
            <?  foreach($def_arr_life_theme1 as $val) {?>
                    <input type="radio" name="theme_type" value="<?=$val['code']?>" onclick="change_theme_type('<?=$val['code']?>')" <? if($search_theme_type==$val['code']) { echo 'checked';}?>> <?=$val['name']?>&nbsp;&nbsp;
            <?  }?>
            </br>
            <div style="width:80px; float: left"><b>모바일섹션</b></div>
            <?  foreach($def_arr_life_theme2 as $val) {?>
                    <input type="radio" name="theme_type" value="<?=$val['code']?>" onclick="change_theme_type('<?=$val['code']?>')" <? if($search_theme_type==$val['code']) { echo 'checked';}?>> <?=$val['name']?>&nbsp;&nbsp;
            <?  }?>
        </td>
    </tr>

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

       $head_title      = '';
       $title           = '';
       $sub_title       = '';
       $theme_img       = '';
       $theme_img_txt   = '';
       $content_idx     = '';
       $editor_name     = '';
       $hit_count     = '';
       $like_count     = '';
       if(isset($arr_theme_rank[$i])== true) {
            $head_title = $arr_theme_rank[$i]['head_title'];
            $head_title = htmlspecialchars($head_title);
            $title      = $arr_theme_rank[$i]['title'];
            $title      = htmlspecialchars($title);
            $sub_title  = $arr_theme_rank[$i]['sub_title'];
            $sub_title  = htmlspecialchars($sub_title);
            $content_idx= $arr_theme_rank[$i]['content_idx'];
            $theme_img  = $arr_theme_rank[$i]['theme_img'];
            $editor_name= $arr_theme_rank[$i]['editor_name'];
            $hit_count  = $arr_theme_rank[$i]['hit_count'];
            $like_count = $arr_theme_rank[$i]['like_count'];
            if($theme_img!='') $theme_img_txt = '<img src="'.$theme_img.'" width=250>';
       }

       switch($search_theme_type) {
           case '11': $rowspan = '4';break;
           case '17': $rowspan = '4';break;
           case '19': $rowspan = '5';break;
           case '20': $rowspan = '4';break;
           case '21': $rowspan = '5';break;
           default : $rowspan = '3';break;

       }



?>

        <tr>
            <th rowspan="<?=$rowspan?>"><?=$i?>위</th>
            <td class="tl">
                <input type="hidden" name="content_idx<?=$i?>" id="content_idx<?=$i?>" value="<?=$content_idx?>">
                <?  if($search_theme_type=='11' || $search_theme_type=='16'  || $search_theme_type=='17' || $search_theme_type=='18' || $search_theme_type=='19' || $search_theme_type=='20' || $search_theme_type=='21') {?>
                    <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>
    <? if($search_theme_type=='11'){?>

        <tr>
            <td class="tl">
                <input type="text" name="sub_title<?=$i?>" id="sub_title<?=$i?>" placeholder="부제목" value="<?=$sub_title?>">
            </td>
        </tr>
   <? }

       if($search_theme_type=='17' || $search_theme_type=='19' ||$search_theme_type=='20'  || $search_theme_type=='21' ){?>

        <tr>
            <td class="tl">
                <input type="text" name="editor_name<?=$i?>" id="editor_name<?=$i?>" class="type02" placeholder="에디터" value="<?=$editor_name?>" readonly>
            </td>
        </tr>


    <?}

        if($search_theme_type=='19') {
     ?>
         <tr>
            <td class="tl">
                <input type="text" name="like_count<?=$i?>" id="like_count<?=$i?>" class="type03" placeholder="좋아요수" value="<?=$like_count?>">
            </td>
        </tr>


    <?
        }
            if($search_theme_type=='21') {
     ?>
         <tr>
            <td class="tl">
                <input type="text" name="hit_count<?=$i?>" id="hit_count<?=$i?>" class="type03" placeholder="조회수" value="<?=$hit_count?>">
            </td>
        </tr>


    <?
        }

    ?>
        <tr>
            <td class="tl">
                <div id="img_view<?=$i?>"><?=$theme_img_txt?></div>
                <input type="hidden" name="img<?=$i?>" id="img<?=$i?>">
                <input type="hidden" name="org_img<?=$i?>" id="org_img<?=$i?>" value="<?=$theme_img?>">
                <input type="file" name="theme_img<?=$i?>" id="theme_img<?=$i?>" class="input00" size="20">
            </td>
        </tr>
        <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:life_theme_list_reg_proc()">저장하기</a>
    <a href="/admin/life/life_theme_list/5/<?=$page?>?search_type=<?=$search_type?>&search_keyword=<?=$search_keyword?>&search_theme_type=<?=$search_theme_type?>&search_category_code1=<?=$search_category_code1?>&search_category_code2=<?=$search_category_code2?>&search_life_type=<?=$search_life_type?>&sort=<?=$sort?>">목록으로</a>

</div>

</form>

<? 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_theme_type(theme_code){
    $("#search_theme_type").val(theme_code);
    $("#input_form").attr("action", "/admin/life/life_theme_list_reg/5");
    $("#input_form").submit();
}

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


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

}

</script>