<?php
$sub_menu = "550300";
include_once('./_common.php');

if ($is_admin != 'super')
    alert('최고관리자만 접근 가능합니다.');

// 고객관리테이블 생성

if(!sql_query(" DESCRIBE `okone_contact` ", false)) {
    sql_query(" CREATE TABLE IF NOT EXISTS `okone_contact` (
                  `me_id` int(11) NOT NULL AUTO_INCREMENT,
                  `me_name` varchar(80) NOT NULL DEFAULT '',
                  `me_email` varchar(100) NOT NULL DEFAULT '',
                  `me_tel` varchar(80) NOT NULL DEFAULT '',
                  `me_type` varchar(150) NOT NULL DEFAULT '',
                  `me_content` text NOT NULL,
                  `me_admin` text NOT NULL,
                  PRIMARY KEY (`me_id`)
                ) ENGINE=MyISAM DEFAULT CHARSET=utf8 ", true);
}

$g5['title'] = "okone 고객관리";
include_once(G5_ADMIN_PATH.'/admin.head.php');

$sql_common = " from `okone_contact` ";

// 테이블의 전체 레코드수만 얻음
$sql = " select count(*) as cnt " . $sql_common;
$row = sql_fetch($sql);
$total_count = $row['cnt'];

$rows = $config['cf_page_rows'];
$total_page  = ceil($total_count / $rows);  // 전체 페이지 계산
if ($page < 1) { $page = 1; } // 페이지가 없으면 첫 페이지 (1 페이지)
$from_record = ($page - 1) * $rows; // 시작 열을 구함

$sql = "select * $sql_common order by me_id limit $from_record, {$config['cf_page_rows']} ";
$result = sql_query($sql);
?>

<div class="local_ov01 local_ov">
    <?php if ($page > 1) {?><a href="<?php echo $_SERVER['SCRIPT_NAME']; ?>">처음으로</a><?php } ?>
    <span class="btn_ov01"><span class="ov_txt">전체 목록</span><span class="ov_num"> <?php echo $total_count; ?>건</span></span>
</div>

<div class="tbl_head01 tbl_wrap">
    <table>
    <caption><?php echo $g5['title']; ?> 목록</caption>
    <thead>
    <tr>
        <th scope="col">ID</th>
        <th scope="col">성명</th>
        <th scope="col">Email</th>
        <th scope="col">연락처</th>
        <th scope="col">문의종류</th>
        <th scope="col">관리</th>
    </tr>
    </thead>
    <tbody>
    <?php for ($i=0; $row=sql_fetch_array($result); $i++) {
        $bg = 'bg'.($i%2);
    ?>
    <tr class="<?php echo $bg; ?>">
        <td class="td_id"><?php echo $row['me_id']; ?></td>
        <td class="td_left"><?php echo htmlspecialchars2($row['me_name']); ?></td>
        <td class="td_left"><?php echo htmlspecialchars2($row['me_email']); ?></td>
        <td class="td_left"><?php echo htmlspecialchars2($row['me_tel']); ?></td>
        <td class="td_left"><?php echo htmlspecialchars2($row['me_type']); ?></td>
        <td class="td_mng td_mng_l">
            <a href="./contact_okone_form.php?w=u&amp;me_id=<?php echo $row['me_id']; ?>" class="btn btn_03">수정</a>
            <a href="./contact_okone_update.php?w=d&amp;me_id=<?php echo $row['me_id']; ?>" onclick="return delete_confirm(this);" class="btn btn_02">삭제</a>
        </td>
    </tr>
    <?php
    }
    if ($i == 0) {
        echo '<tr><td colspan="6" class="empty_table">자료가 한건도 없습니다.</td></tr>';
    }
    ?>
    </tbody>
    </table>
</div>

<?php echo get_paging(G5_IS_MOBILE ? $config['cf_mobile_pages'] : $config['cf_write_pages'], $page, $total_page, "{$_SERVER['SCRIPT_NAME']}?$qstr&amp;page="); ?>


<?php
include_once(G5_ADMIN_PATH.'/admin.tail.php');
?>
