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

$arr_theme_rank = array();
foreach ($arr_theme as $val) {
    $arr_theme_rank[$val['rank']] = array('content_idx'=> $val['content_idx'], 'column_name'=>$val['column_name'],  'partner_idx'=>$val['partner_idx'], 'title'=>$val['title'], 'sub_content'=>$val['sub_content'], 'theme_img'=>$val['theme_img']);
}


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


<form name="input_form" id="input_form" action="/admin/column/column_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="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_column_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_column_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_column_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_column_theme[$search_theme_type]['count'];$i++) {

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

       $colspan = "4";
       if($search_theme_type == '7')    $colspan = "5";
       if($search_theme_type == '8')    $colspan = "3";


?>

    <tr>
        <th rowspan="<?=$colspan?>"><?=$i?>위</th>
        <td class="tl"><input type="text" name="column_name<?=$i?>" id="column_name<?=$i?>" class="type02" size="20" placeholder="칼럼명" value="<?=$column_name?>" readonly></td>
    </tr>
    <tr>
        <td class="tl">
            <input type="hidden" name="content_idx<?=$i?>" id="content_idx<?=$i?>" value="<?=$content_idx?>">
            <input type="text" name="title<?=$i?>" id="title<?=$i?>" class="input00" size="50" placeholder="제목을 입력해주세요." value="<?=$title?>">
        </td>
    </tr>
<?  if($search_theme_type == '7') {?>
    <tr>
        <td class="tl">
            <textarea id="sub_content<?=$i?>" name="sub_content<?=$i?>" placeholder="기사 간략 노출(3줄)" rows="3" cols="80"><?=$sub_content?></textarea>
        </td>
    </tr>

<?  }?>
<?  if($search_theme_type != '8') {?>
    <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:column_theme_list_reg_proc()">저장하기</a>
    <a href="/admin/column/column_theme_list/3/<?=$page?>?search_type=<?=$search_type?>&search_keyword=<?=$search_keyword?>&search_theme_type=<?=$search_theme_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/column/column_theme_list_reg/3");
    $("#input_form").submit();
}

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


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

}

</script>