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

$arr_ranking_list = array();
foreach ($arr_ranking as $val) {
    $arr_ranking_list[$val['rank']] = array('content_idx'=> $val['content_idx'], 'head_title'=>$val['head_title'], 'title'=>$val['title'], 'sub_content'=>$val['sub_content'], 'main_img'=>$val['main_img'], 'hit_count'=>$val['hit_count'], 'comment_count'=>$val['comment_count'], 'review_count1'=>$val['review_count1'], 'press_name'=>$val['press_name']);
}


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

?>


<form name="input_form" id="input_form" action="/admin/news/news_ranking_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_ranking_type" name="search_ranking_type" value="<?=$search_ranking_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_category_code3" name="search_category_code3" value="<?=$search_category_code3?>">
<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">
    
    
    

<div class="common_table">
<table>
    <tr>
        <th>테마</th>
        <td class="tl">

            <?  foreach($def_arr_ranking as $val) {?>
                    <input type="radio" name="ranking_type" value="<?=$val['code']?>" onclick="change_ranking_type('<?=$val['code']?>')" <? if($search_ranking_type==$val['code']) { echo 'checked';}?>> <?=$val['name']?>&nbsp;&nbsp;
            <?  }?>

        </td>
    </tr>

<?
   for($i=1;$i<=$def_arr_ranking[$search_ranking_type]['count'];$i++) {
       $head_title      = '';
       $title           = '';
       $sub_content     = '';
       $main_img        = '';
       $main_img_txt    = '';
       $content_idx     = '';
       $hit_count       = '';
       $review_count1   = '';
       $comment_count   = '';
       $press_name      = '';
       if(isset($arr_ranking_list[$i])== true) {
            $head_title     = $arr_ranking_list[$i]['head_title'];
            $head_title     = htmlspecialchars($head_title);
            $title          = $arr_ranking_list[$i]['title'];
            $title 		    = htmlspecialchars($title);
            $sub_content    = $arr_ranking_list[$i]['sub_content'];
            $sub_content    = htmlspecialchars($sub_content);
            $content_idx    = $arr_ranking_list[$i]['content_idx'];
            $hit_count      = $arr_ranking_list[$i]['hit_count'];
            $review_count1  = $arr_ranking_list[$i]['review_count1'];
            $comment_count  = $arr_ranking_list[$i]['comment_count'];
            $main_img       = $arr_ranking_list[$i]['main_img'];
            $press_name     = $arr_ranking_list[$i]['press_name'];
            if($main_img!='') $main_img_txt = '<img src="'.$main_img.'" width=250>';
       }

       $rowspan='6';
?>
    <tr>
        <th rowspan="<?=$rowspan?>"><?=$i?>위(썸네일)</th>
        <td class="tl">
            <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" placeholder="말머리" value="<?=$head_title?>"> <input type="text" name="title<?=$i?>" id="title<?=$i?>"  class="type00" placeholder="제목을 입력해주세요." value="<?=$title?>">
        </td>
    </tr>
    <tr>
        <td class="tl">
            <textarea id="content<?=$i?>" name="content<?=$i?>" placeholder="기사 간략 노출(2줄)" rows="2" cols="80"><?=$sub_content?></textarea>
        </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">
        </td>
    </tr>
   <tr>
        <td class="tl">
            <input type="text" name="press_name<?=$i?>" id="press_name<?=$i?>" class="type03" placeholder="언론사명" value="<?=$press_name?>" readonly>
        </td>
    </tr>
<?  if($search_ranking_type == '1') {?>

    <tr>
        <td class="tl">
            <input type="text" name="hit_count<?=$i?>" id="hit_count<?=$i?>" class="type03" placeholder="조회수" value="<?=$hit_count?>">
        </td>
    </tr>
<?  } else if($search_ranking_type == '2') {?>
    <tr>
        <td class="tl">
            <input type="text" name="comment_count<?=$i?>" id="comment_count<?=$i?>" class="type03" size="20" placeholder="댓글수" value="<?=$comment_count?>" readonly>
        </td>
    </tr>

<?  } else if($search_ranking_type == '3') {?>
  <tr>
        <td class="tl">
            <input type="text" name="review_count<?=$i?>" id="review_count<?=$i?>" class="type03" size="20" placeholder="공감수" value="<?=$review_count1?>">
        </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:news_ranking_list_reg_proc()">저장하기</a>
    <a href="/admin/news/news_ranking_list/2/<?=$page?>?search_type=<?=$search_type?>&search_keyword=<?=$search_keyword?>&search_ranking_type=<?=$search_ranking_type?>&search_category_code1=<?=$search_category_code1?>&search_category_code2=<?=$search_category_code2?>&search_category_code3=<?=$search_category_code3?>&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_ranking_type(ranking_code){
    $("#search_ranking_type").val(ranking_code);
    $("#input_form").attr("action", "/admin/news/news_ranking_list_reg/2");
    $("#input_form").submit();
}

var ranking_count = "<?=$def_arr_ranking[$search_ranking_type]['count']?>";
function news_ranking_list_reg_proc(){
    for(i=1;i<=ranking_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;
            }
        }
    }

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

}

</script>