<?php
//------------------------------------------------------------------------------
// RC 목록을 출력한다.
//------------------------------------------------------------------------------

// 인클루드
require_once( "../inc/session.php" );
require_once( "../inc/common.inc" );      // 공통 함수 모음
require_once( "../inc/db_pgsql.inc" ); // 데이터베이스 인터페이스

// 쿠키확인
//$suid = $HTTP_COOKIE_VARS[SUID];
$suid = $_COOKIE[SUID];

if ($suid != "guru222")
{
	AlertBack("전체관리자만 접근할 수 있습니다.");
    exit;
}

$AdminLevel = 1; 

$page = $_REQUEST["page"];
$sch  = $_REQUEST["sch"];

// 검색모드인가 아닌가 판정.
if( !eregi("[^[:space:]]+", $sch) )
	$schmode = 0;
else
{
	$schmode = 1;
	$enc_sch = urlencode( $sch );
}

// 한 페이지에 출력할 레코드 개수
$REC_PER_PAGING = 10;

// 한 페이지에 출력할 페이지바로가기 개수
$PAGELINK_PER_PAGING = 10;

$objConn = new DB_Sql;
?>

<html>
<head><title>System Administration</title><meta HTTP-EQUIV="Content-Type" CONTENT="text/html; charset=euc-kr"><link href="../css/style.css" rel="stylesheet" type="text/css"><script language="javascript" type="text/javascript"></script><style>BODY,TABLE,TR,TD {font-size:12px;}select{behavior: url('../css/selectbox.htc');}TD{line-height:150%;}</style>
<link rel="stylesheet" href="img/style.css" type="text/css">
</head>

<script language="javascript">
function check_rcid(rcid, rcname, arrange)
{
	window.open("rc_server_pop.html?rc_name="+rcname+"&rc_id="+rcid+"&arrange="+arrange, "rc_id_popup", "width=500, height=400, resizable");
}

function check_service(rcid)
{
   window.open("rc_service_pop.html?rc_id="+rcid, "rc_id_popup", "width=500, height=400, resizable, scrollbars");
}

function winopen_update()
{
	if (confirm("모든 서버 목록이 갱신됩니다. 진행 하시겠습니까?"))
		window.open("../servListUpdate.html", "slu_popup", "width=400, height=100");
	else
		return;
}

function winopen_raid()
{
	//window.open("http://sh-raid.solbox.com/index.html", "_blank");
	//window.open("http://cc-raid.ktsh.co.kr/index.html", "_blank");
	//window.open("http://cs-raid.ktcdn.co.kr/index.html", "_blank");
	window.open("http://cs-raid.x-cdn.com/index.html", "_blank");
}

function DoDel(arrange)
{
	if ( confirm("RC에 포함된 모든 서버목록이 삭제됩니다. 진행 하시겠습니까?") )
		document.location.href("rc_delete.html?arrange="+arrange);
	else
		return;
}
</script>

<body bgcolor="#FFFFFF" leftmargin="0" topmargin="0" marginwidth="0" marginheight="0">

<?php
	require_once( "../inc/top_1.html" );
?>

<table width="100%" border="0" cellpadding="0" cellspacing="0">
  <tr>
    <td>
      <table width="100%" border="0" cellpadding="0" cellspacing="0">
		<tr>
          <td width="169" bgcolor="#F1F1F1" valign="top">
		   <table width=100% border=0 cellpadding=0 cellspacing=0>
              <tr height=12>
                <td></td>
              </tr>
              <tr height=1>
                <td bgcolor="#B9B9B9"></td>
              </tr>
              <!-- menu title -->
              <tr height=30>
                <td align=center class="LeftMenuTitle"> RC Management </td>
              </tr>
              <tr height=1>
                <td bgcolor="#B9B9B9"></td>
              </tr>
              <!-- submenu -->
              <tr height=30>
                <td align=center class=LeftMenu style="padding-top:10;padding-bottom:10"><a href='javascript:winopen_update();'><img src='img/Btnupdate.gif' border='0'></a></td>
              </tr>
              <tr height=30>
                <td align=center class=LeftMenu bgcolor=#CDCDCD><a href='<?=$_SERVER[PHP_SELF]?>'>RC
                  목록</a></td>
              </tr>
              <tr height=30>
                <td align=center class=LeftMenu height="17"><a href='rc_add.html'>RC
                  추가</a></td>
              </tr>
              <tr height=30>
                <td align=center class=LeftMenu height="50">&nbsp;</td>
              </tr>
              <tr height=1>
                <td bgcolor="#B9B9B9"></td>
              </tr>
              <!-- menu title -->
              <tr height=30>
                <td align=center class="LeftMenuTitle"> SMS Management </td>
              </tr>
              <tr height=1>
                <td bgcolor="#B9B9B9"></td>
              </tr>
              <tr height=30>
                <td align=center class=LeftMenu><a href='sms_list.html'>수신 목록</a></td>
              </tr>
			  <tr height=30>
				<td align=center class=LeftMenu height="50">&nbsp;</td>
			  </tr>
			  <tr height=1>
				<td bgcolor="#B9B9B9"></td>
			  </tr>
			  <tr height=30>
				<td align=center class="LeftMenuTitle"> Monitor Page </td>
			  </tr>
			  <tr height=1>
				<td bgcolor="#B9B9B9"></td>
			  </tr>
			  <tr height=20>
				<td align=center class=LeftMenu><a href='../monitor.html'>서버 상태</a></td>
			  </tr>
			  <tr height=20>
				<td align=center class=LeftMenu><a href="javascript:winopen_raid();">RAID 상태</a></td>
			  </tr>
            </table> 
          </td>
          <td width="1" bgcolor="#CECECE"></td>
          <td width="30" bgcolor="#FFFFFF"></td>
          <td>
            <table width="100%" border="0" cellpadding="0" cellspacing="0">
              <tr height="12">
                <td></td>
              </tr>
              <tr height="28">
                <td class="ContentSummary">>> RC Management</td>
              </tr>
              <tr height="1">
                <td height="1" background="<?echo("$DOC_ROOT")?>/image/bg_line_dash.gif"></td>
              </tr>
              <tr height="24">
                <td></td>
              </tr>
              <tr>
                <td valign="top">

                  <!-- CONTENT TABLE START -->
                  <table width="100%" border="0" cellpadding="0" cellspacing="0">
                    <tr>
                      <!-- LEFT CELL START -->
                      <td valign="top">
                        <!-- content subtitle -->
                        <table width="100%" border="0" cellpadding="0" cellspacing="0" class="ContentSubtitle">
                          <tr>
                            <td width="10" height="25"><img src="<?echo("$DOC_ROOT")?>/image/icon_arrow.gif"></td>
                            <td>RC 목록</td>
                          </tr>
                        </table>
                        
						<?php
                        // 총레코드 수
                        $strSQL = " SELECT COUNT(rcid) FROM t_rms_rc_index " . 
                                  " WHERE deleted_yn = 'N' ";
                        if( $schmode )
                        {
                            $strSQL = $strSQL . " AND rcid LIKE '%$sch%'";
                        }
                        
                        $objConn->query( $strSQL );
                        if( $objConn->nf() != 0 ) 
                        {
                            $objConn->next_record();
                            $total_record = $objConn->f(0);
                        }
                        
                        // 전체페이징 수
                        $total_page = ceil( $total_record / $REC_PER_PAGING );
                        
                        // 페이징 기본값 1
                        if( !$page ) 
                        {
                            $page = 1;
                        }
                        
                        // 해당 페이지의 첫번째레코드와 마지막레코드 번호 계산
                        if( $total_record == 0 )
                        {
                            $first = 1;
                            $last  = 0;
                        } 
                        else 
                        {
                            $first = $REC_PER_PAGING * ($page-1);
                            $last  = $REC_PER_PAGING * $page;
                        }
                        
                        // 현재 페이징의 레코드셋 취득
                        $strSQL = " SELECT " . 
                                  " rcid, rc_name, arrange, reg_datetime, update_datetime " .
                                  " FROM t_rms_rc_index " . 
                                  " WHERE deleted_yn = 'N' ";
                        if( $schmode )	
                        {
                            $strSQL = $strSQL . " AND rcid LIKE '%$sch%'";
                        }
                        $strSQL = $strSQL . " ORDER BY reg_datetime DESC LIMIT $REC_PER_PAGING OFFSET $first";
                        $objConn->query( $strSQL );
                        
                        // 일련번호 계산
                        $rec_num = $total_record - $REC_PER_PAGING * ($page - 1);
                        ?>
                        
                        <!-- RC 목록 TABLE START -->
                        <table width="100%" border="0" cellpadding="0" cellspacing="0" class="ContentTable">
                          <tr>
                            <td colspan="6" height="2" bgcolor="#B9B9B9"></td>
                          </tr>
                          
                          <tr>
                            <td height="27" align="center" bgcolor="#F6F5F2" class="ContentListTitle">RC No.</td>
                            <td height="27" align="center" bgcolor="#F6F5F2" class="ContentListTitle">RC ID.</td>
                            <td width="23%" align="center" bgcolor="#F6F5F2" class="ContentListTitle">RC 이름</td>
                            <td width="23%" align="center" bgcolor="#F6F5F2" class="ContentListTitle">관리</td>
                            <td width="17%" align="center" bgcolor="#F6F5F2" class="ContentListTitle">생성일</td>
                            <td width="17%" align="center" bgcolor="#F6F5F2" class="ContentListTitle">최근변경일</td>
                            <td align="center" bgcolor="#F6F5F2" class="ContentListTitle"><!--로그관리--></td>
                          </tr>
                          <tr>
                            <td colspan="6" height="1" bgcolor="E1E1E1"></td>
                          </tr>
                          
                          <!-- 목록 START -->
                          <?php
                          if( $objConn->nf() != 0 ) 
                          {
                              while( $objConn->next_record() )
                              {
                                  $val_rc_id    = $objConn->f("rcid");
                                  $val_rc_name  = $objConn->f("rc_name");
								  $arrange		= $objConn->f("arrange");
                                  //$val_sp_svc_max_stg_size = $objConn->f("sp_svc_max_stg_size"); // 단위는 메가바이트.
                                  $val_reg_datetime        = $objConn->f("reg_datetime");
                                  $val_update_datetime     = $objConn->f("update_datetime");
                          ?>
                          <tr>
                            <td height="27" align="center" bgcolor="#FDFCFC"><?echo("$rec_num")?></td>
                            <td height="27" align="center" bgcolor="#FDFCFC"><?echo("$val_rc_id")?></td>
                            <td width="23%" align="center" bgcolor="#FDFCFC"><a href="javascript:check_rcid('<?=$val_rc_id?>', '<?=$val_rc_name?>', '<?=$arrange?>')"><b><?echo("$val_rc_name")?></b></a></td>
                            <td width="23%" align="center" bgcolor="#FDFCFC"><a href="rc_modify.html?arrange=<?=$arrange?>">수정</a>&nbsp;&nbsp;<a href="javascript:DoDel('<?=$arrange?>');">삭제</a>&nbsp;&nbsp;<a href="javascript:check_service('<?=$val_rc_id?>')">서비스</a></td>
                            <td width="17%" align="center" bgcolor="#FDFCFC"><?echo("$val_reg_datetime")?></td>
                            <td width="17%" align="center" bgcolor="#FDFCFC"><?echo("$val_update_datetime")?></td>
                            <td align="center" bgcolor="#FDFCFC">
							<!--
							<a href="<?echo("$DOC_ROOT")?>/rcmng/rc_deletelog_process.html?key=<?echo("$val_rc_id")?>"><img src="<?echo("$DOC_ROOT")?>/image/icon_delete_log.gif" border="0"></a>
							-->
							</td>

                          </tr>
                          <tr>
                            <td colspan="6" height="1" bgcolor="#E1E1E1"></td>
                          </tr>
                         
						  <?php
                                  $rec_num--;
                              }
                          }
                          ?>
                          <!-- 목록 END -->
                          
                          <!-- page selecter -->
                          <tr>
                            <td colspan="6" height="25" bgcolor="#F6F5F2" align="center">
                            <?php
                            $total_block = ceil( $total_page / $PAGELINK_PER_PAGING );
                            $block       = ceil( $page / $PAGELINK_PER_PAGING );
                            
                            $first_page = ($block-1) * $PAGELINK_PER_PAGING;
                            $last_page  = $block * $PAGELINK_PER_PAGING;
                            
                            if( $block >= $total_block )
                            {
                                $last_page = $total_page;
                            }
                            
                            // 이전페이지블록 링크
                            if( $block > 1 )
                            {
                                $val_page = $first_page;
                                echo("<a href=\"$_SERVER[PHP_SELF]?page=$val_page&sch=$enc_sch\"> <img src='../image/arrow_left1.gif' width='11' height='10' border='0'> </a>");
                            }
                            else
                            {
                                echo("<img src='../image/arrow_left1.gif' width='11' height='10' border='0'>&nbsp;");
                            }
                            
                            // 페이지 이동 링크 표시
                            for( $direct_page = $first_page+1; $direct_page <= $last_page; $direct_page++ ) 
                            {
                                if( $page == $direct_page ) 
                                {
                                    echo("&nbsp;<b>$direct_page</b>");
                                } 
                                else 
                                {
                                    echo("&nbsp;<a href=\"".$_SERVER[PHP_SELF]."?page=$direct_page&sch=$enc_sch\">$direct_page</a>");
                                }
                            }
                            
                            // 다음페이지블록 링크
                            if($block < $total_block) 
                            {
                                $val_page = $last_page+1;
                                echo("<a href=\"".$_SERVER[PHP_SELF]."?page=$val_page&sch=$enc_sch\"> <img src='../image/arrow_right1.gif' width='11' height='10' border='0'> </a>");
                            }
                            else
                            {
                                echo("&nbsp;&nbsp;<img src='../image/arrow_right1.gif' width='11' height='10' border='0'>");
                            }
                            ?>
                            </td>
                          </tr>
                          <tr>
                            <td colspan="6" height="2" bgcolor="#B9B9B9"></td>
                          </tr>
                          
                        </table>
                        <!-- RC 목록 TABLE END -->
                  
                        <!-- divider -->
                        <table width="100%" border="0" cellpadding="0" cellspacing="0">
                          <tr>
                            <td height="20"></td>
                          </tr>
                        </table>
                  
                        <!-- search panel -->
                        <form method="post" action="<?= $_SERVER[PHP_SELF] ?>" onSubmit="return check_submit(this);">
                        <table width="100%" border="0" cellpadding="0" cellspacing="0" class="ContentTable">
                          <tr>
                            <td height="30" align=center>
                              RC 이름 검색 <input type="text" maxLength="32" name="sch" style="BACKGROUND-COLOR:#FAFAFA; border:1px solid #cccccc; HEIGHT:21px; WIDTH:150px" value=""> <input type="image" src="<?echo("$DOC_ROOT")?>/image/icon_search.gif" alt="검색" border="0" width="58" height="21" align="absmiddle">
                            </td>
                          </tr>
                        </table>
                        </form>
                        
                        <!-- divider -->
                        <table width="100%" border="0" cellpadding="0" cellspacing="0">
                          <tr>
                            <td height="25"></td>
                          </tr>
                        </table>
                  
                      </td>
                      <!-- LEFT CELL END -->
                  
                    </tr>
                  </table>
                  <!-- CONTENT TABLE END -->
                
                </td>
              </tr>
            </table>
          </td>
          <td width="30" bgcolor="#FFFFFF"></td>
        </tr>
      </table>
    </td>
  </tr>
  
  <tr>
    <td>
      <?php
      require_once( "../inc/foot.html" );
      ?>
    </td>
  </tr>
  
</table>

</body>

</html>

<?php
$objConn->close();
?>
