<?
if (!defined("_GNUBOARD_")) exit; // 개별 페이지 접근 불가

$g4[title] = "배너목록";

$g4_table         = "banner";	  
$g4_site_table    = $g4['table_prefix']."site_".$g4_table;  

           //////////////////////////////////////////////////////////

          //페이지 구현
           $sql = " select count(*) as cnt from {$g4_site_table} ";
           $row = sql_fetch($sql);
           $total_count = $row[cnt];

           $rows =  25;
           $total_page  = ceil($total_count / $rows);  // 전체 페이지 계산
           if (!$page) $page = 1; // 페이지가 없으면 첫 페이지 (1 페이지)
           $from_record = ($page - 1) * $rows; // 시작 열을 구함
  



           $sql          = " select * from {$g4_site_table} order by po_id desc limit $from_record, $rows ";
           $result       = sql_query($sql);
           $total_count  = mysql_num_rows($result);

           $write_pages  = get_paging($result, $page, $total_page, "?url=category&page=");
          ////////////////////////////////////////////////////////////

//전체 체크박스 on
$is_checkbox = 1;

//전체폭
$width = "100%";


$colspan = 5;
if ($is_checkbox) $colspan++;

/////////////////////

////////////////////////////////////////////////
//배너분류 업데이트
if($b_ch){
	//자료검사
	$banner_mct     = " where po_poll19 = 'banner' and po_cnt1 = '1' ";
	$banner_sql     = " select po_id,po_subject from $g4[table_prefix]site_bill $banner_mct ";
	$banner_row     = sql_fetch($banner_sql);

	//자료가 있다면 업데이트한다.
	if($banner_row[po_id]){
      sql_query(" update $g4[table_prefix]site_bill set po_subject = '$banner_sca' where po_id = '$banner_row[po_id]' ");
	}
	else{//자료가 없다면 신규등록한다.
      sql_query(" insert into $g4[table_prefix]site_bill set po_subject = '$banner_sca' , po_poll19 = 'banner', po_cnt1 = '1' ");
	}
}
    // 갤신된 sca에 다시 불러온다
    $banner_sca     = "";
	$b_ch           = "";
	$banner_mct     = " where po_poll19 = 'banner' and po_cnt1 = '1' ";
	$banner_sql     = " select po_id,po_subject  from $g4[table_prefix]site_bill $banner_mct ";
	$banner_row     = sql_fetch($banner_sql);
////////////////////////////////////////////////
?>

<table width=100% cellpadding=3 cellspacing=1>
<form name=fsearch method=get>
<tr>
    <td width=50% align=left><?=$listall?> (분류수 : <?=number_format($total_count)?>개)</td>
    <td width=50% align=right>
    </td>
</tr>
</form>
</table>

<table width=100% cellpadding=3 cellspacing=1>
<form action="./category_list.php?url=banner" method="post" style="margin:0px;">
<tr>
    <td width="70" align="right"><b>· 배너분류</b> : </td>
    <td>
	<input type=text class=ed style='width:80%;' name='banner_sca' value='<?=$banner_row[po_subject]?>'>
	<input type = "hidden" name = "b_ch" value = "1" />
	<input type="submit" name="formbutton1" value="확인">
	<?=help("사용예 - 분류1|분류2|분류3 .\n 끝자리는 공백이 없어야 합니다.", 50)?>
    </td>
</tr>
</form>
</table>


<table  width="<?=$width?>" align=center cellpadding=0 cellspacing=0>
<tr>
  <td>
    <form name="fcart_list" method="post" style="margin:0px;">
    <input type = "hidden" name = "save" value = "true" />

    <table width="100%" cellspacing="0" cellpadding="0">
    <colgroup width=30>
    <colgroup width=''>
    <colgroup width=90>
    <colgroup width=90>
    <colgroup width=50>

    <tr><td colspan='<?=$colspan?>' class='line1'></td></tr>
    <tr class='bgcol1 bold col1 ht center'>
                    <? if ($is_checkbox) { ?><td width=40><INPUT onclick="if (this.checked) all_checked(true); else all_checked(false);" type=checkbox></td><?}?>
					<td>제목</td>
	                <td>출력순서</td>
	                <td>분류</td>
					<td align="center"><a href="<?=$g4[admin_path]?>/category_list.php?url=banner_write"><img src='<?=$g4[admin_path]?>/img/icon_insert.gif' border=0 title='생성'></a></td>
	</tr>
    <tr><td colspan='<?=$colspan?>' class='line2'></td></tr>

    <!-- 목록 -->
    <?
    for($i=1;$i<count($list = sql_fetch_array($result));$i++) 
    {


        //$r_ca = "<span style='font-family:Tahoma;font-size:7pt;color:#ffffff;'>&nbsp;{$list[wr_reply]}</span>";
		//문자열의 길이반환
		$r_ca = strlen($list[wr_reply]);
		$r_ca = 10*$r_ca;

		


		?>
    <tr height="28" align="center">
                     <? if ($is_checkbox) { ?><td><input type=checkbox name=chk_wr_id[] value="<?=$list[po_id]?>"></td><? } ?>
					<td style='padding-left:<?=$r_ca?>px;' align="left"><a href="<?=$g4[admin_path]?>/category_list.php?url=banner_write&w=u&po_id=<?=$list[po_id]?>"><?=$list[po_subject]?></a></td>
					<td style='padding-left:<?=$r_ca?>px;' align="center"><?=$list[po_poll1]?></td> 
					<td><?=$list[po_poll3]?></td>
					<td align="center">
					<a href="<?=$g4[admin_path]?>/category_list.php?url=banner_write&w=u&po_id=<?=$list[po_id]?>"><img src='<?=$g4[admin_path]?>/img/icon_modify.gif' border=0 title='수정'></a>
					<a href="javascript:add_del('<?=$list[po_id]?>','<?=$list[po_subject]?>','po_id');"><img src='<?=$g4[admin_path]?>/img/icon_delete.gif' border=0 title='삭제'></a></td>
	</tr>
<tr><td></td>
    <td colspan="5" style='padding-left:10px;'>
<?if($list[po_poll19]){

    //파일 확장자 검색, 오류예방
    $path_info       =  pathinfo($list[po_poll19]);
    if($path_info["extension"] == 'swf'){
		?>
    <script>
    doc_write(flash_movie("<?=$g4[path]?>/data/file/banner/<?=$list[po_poll19]?>", "myfile", "<?=$list[po_cnt5]?>", "<?=$list[po_cnt6]?>", "transparent"));
    </script>
		<?
	}
	else{
     echo "<img src='$g4[path]/data/file/banner/$list[po_poll19]'  border='0'>";
	}
		}?>
    </td>
</tr>
    <tr><td height="5" colspan=<?=$colspan?>></td></tr>
	<?}?>	
    <? if ($total_count == 0) { echo "<tr><td colspan='$colspan' height=100 align=center>카테고리가 존재하지 않습니다.</td></tr>"; } ?>
    <tr><td height="1" colspan=<?=$colspan?> bgcolor="#dadada"></td></tr>
    </table>
    </form>
	<!--------페이지--------->
	<br><br>
    <table width="100%" height="50" cellspacing="0" cellpadding="0">
    <tr><td align="center"><?=$write_pages?></td></tr>
    </table>
	<br>
	<!--------페이지--------->
	<table width="100%" height="30" cellspacing="0" cellpadding="0">
    <tr><td>
        <? if ($is_checkbox) { ?>
            <a href="javascript:select_delete();">선택삭제</a>
        <? } ?>
	</td></tr>
    </table>
	<br>
	<!--------페이지--------->

  </td>
</tr>
</table>




<script language="javascript">




 function add_cate(se_01, se_02, se_03)
{ 
   url = g4_path+"/adm/banner/add.php?se_01="+se_01+"&se_02="+se_02+"&se_03="+se_03;
        
   win_open(url, "winFormmail", "left=100, top=100, width=680, height=580, scrollbars=1");

}

 function add_del(se_01, se_02, se_03)
{ 
    var f = document.fcart_list;

    str = "삭제";
    if (!confirm(se_02+" 를 정말 "+str+" 하시겠습니까?\n\n한번 "+str+"한 자료는 복구할 수 없습니다"))
        return;

    f.action = g4_path+"/adm/banner/banner_del.php?po_id="+se_01;
    f.submit();

}


// 선택한 게시물 삭제

 function all_checked(sw) {
  var f = document.fcart_list;

  for (var i=0; i<f.length; i++) {
  if (f.elements[i].name == "chk_wr_id[]")
      f.elements[i].checked = sw;
   }
}


function select_delete() {
    var f = document.fcart_list;

    str = "삭제";
    if (!check_confirm(str))
        return;

    if (!confirm("선택한 분류를 정말 "+str+" 하시겠습니까?\n\n한번 "+str+"한 자료는 복구할 수 없습니다"))
        return;

    f.action = g4_path+"/adm/banner/banner_del.php";
    f.submit();
}

function check_confirm(str) {
    var f = document.fcart_list;
    var chk_count = 0;

    for (var i=0; i<f.length; i++) {
        if (f.elements[i].name == "chk_wr_id[]" && f.elements[i].checked)
            chk_count++;
    }

    if (!chk_count) {
        alert(str + "할 게시물을 하나 이상 선택하세요.");
        return false;
    }
    return true;
}

</script>





