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

auth_check($auth[$sub_menu], "r");

$token = get_token();

$sql_common = " from $g4[point_table] ";

$sql_search = " where (1) ";
if ($stx) {
    $sql_search .= " and ( ";
    switch ($sfl) {
        case "mb_id" :
            $sql_search .= " ($sfl = '$stx') ";
            break;
        default : 
            $sql_search .= " ($sfl like '%$stx%') ";
            break;
    }
    $sql_search .= " ) ";
}

if (!$sst) {
    $sst  = "po_id";
    $sod = "desc";
}
$sql_order = " order by $sst $sod ";

$sql = " select count(*) as cnt
         $sql_common 
         $sql_search 
         $sql_order ";
$row = sql_fetch($sql);
$total_count = $row[cnt];

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

$sql = " select *
          $sql_common
          $sql_search
          $sql_order
          limit $from_record, $rows ";
$result = sql_query($sql);

$listall = "<a href='$_SERVER[PHP_SELF]'>처음</a>";

if ($sfl == "mb_id" && $stx)
    $mb = get_member($stx);

$g4[title] = "$zm_config[pointname]관리";
include_once ("./admin.head.php");

$colspan = 8;
?>

<script type="text/javascript" src="<?=$g4[path]?>/js/sideview.js"></script>
<script type="text/javascript">
var list_update_php = "";
var list_delete_php = "point_list_delete.php";
</script>

<script type="text/javascript">
function point_clear()
{
    if (confirm("$zm_config[pointname] 정리를 하시면 최근 50건 이전의 $zm_config[pointname] 부여 내역을 삭제하므로\n\n$zm_config[pointname] 부여 내역을 필요로 할때 찾지 못할 수도 있습니다.\n\n\n그래도 진행하시겠습니까?"))
    {
        document.location.href = "./point_clear.php?ok=1";
    }
}
</script>
<style>
.tbl_box	{ border:1px solid #CBCBCB; border-top:2px solid #989898; }
.tbl_box tr th	{ background:#F7F7F7; height:30px; border-right:1px solid #EFEFEF; border-bottom:1px solid #EFEFEF; }
.tbl_box tr th:last-child	{ border-right:0; }
.tbl_box tr td	{ padding:6px; border-right:1px solid #EFEFEF; border-bottom:1px solid #EFEFEF; }
.tbl_box tr td:last-child	{ border-right:0; }
.tbl_box tr:last-child td	{ border-bottom:0; }

span.member:hover	{ text-decoration:underline; }
</style>

<?=subtitle($listall)?>
<div class="subtitle_msg">
	건 수 : <?=number_format($total_count)?>
<? 
	if ($mb[mb_id]) 
		echo ", &nbsp;" . $mb[mb_id] ." 님 $zm_config[pointname] 합계 : " . number_format($mb[mb_point]);
	else {
		$row2 = sql_fetch(" select sum(po_point) as sum_point from $g4[point_table] ");
		echo ", &nbsp;전체 $zm_config[pointname] 합계 : " . number_format($row2[sum_point]);
	}
?>
<? if ($is_admin == "super") { ?><!-- <a href="javascript:point_clear();">$zm_config[pointname]정리</a> --><? } ?>
</div>

<div style="text-align:right; margin:-5px 0 8px 0;">
<form name=fsearch method=get>
<select name=sfl class=cssfl>
<option value='mb_id'>회원 아이디</option>
<option value='po_content'>내용</option>
</select>
<input type=text name=stx class=ed required itemname='검색어' value='<?=$stx?>'>
<input type=submit value="검색" class="bttn_search">
</form>
</div>

<form name=fpointlist method=post>
<input type=hidden name=sst   value='<?=$sst?>'>
<input type=hidden name=sod   value='<?=$sod?>'>
<input type=hidden name=sfl   value='<?=$sfl?>'>
<input type=hidden name=stx   value='<?=$stx?>'>
<input type=hidden name=page  value='<?=$page?>'>
<input type=hidden name=token value='<?=$token?>'>

<table width=100% cellpadding=0 cellspacing=0 class="tbl_box">
<colgroup width=30>
<colgroup width=100>
<colgroup width=80>
<colgroup width=80>
<colgroup width=140>
<colgroup width=''>
<colgroup width=100>
<colgroup width=100>
<tr>
    <th><input type=checkbox name=chkall value='1' onclick='check_all(this.form)'></th>
    <th><?=subject_sort_link('mb_id')?>회원아이디</a></th>
    <th>이름</th>
    <th>별명</th>
    <th><?=subject_sort_link('po_datetime')?>일시</a></th>
    <th><?=subject_sort_link('po_content')?><?=$zm_config[pointname]?> 내용</a></th>
    <th><?=subject_sort_link('po_point')?><?=$zm_config[pointname]?></a></th>
    <th><?=$zm_config[pointname]?> 합</th>
</tr>
<?
for ($i=0; $row=sql_fetch_array($result); $i++) 
{
    if ($row2[mb_id] != $row[mb_id])
    {
        $sql2 = " select mb_id, mb_name, mb_nick, mb_email, mb_homepage, mb_point from $g4[member_table] where mb_id = '$row[mb_id]' ";
        $row2 = sql_fetch($sql2);
    }

    $mb_nick = get_sideview($row[mb_id], $row2[mb_nick], $row2[mb_email], $row2[mb_homepage]);

    $link1 = $link2 = "";
    if (!preg_match("/^\@/", $row[po_rel_table]) && $row[po_rel_table])
    {
        $link1 = "<a href='$g4[bbs_path]/board.php?bo_table={$row[po_rel_table]}&wr_id={$row[po_rel_id]}' target=_blank>";
        $link2 = "</a>";
    }

    $list = $i%2;
    echo "
    <input type=hidden name=po_id[$i] value='$row[po_id]'>
    <input type=hidden name=mb_id[$i] value='$row[mb_id]'>
    <tr class='list$list col1 ht center'>
        <td><input type=checkbox name=chk[] value='$i'></td>
        <td align='left'> <a href='?sfl=mb_id&stx=$row[mb_id]'>$row[mb_id]</a></td>
        <td>$row2[mb_name]</td>
        <td>$mb_nick</td>
        <td>$row[po_datetime]</td>
        <td align=left>&nbsp;{$link1}$row[po_content]{$link2}</td>
        <td align=right>".number_format($row[po_point])."&nbsp;</td>
        <td align=right>".number_format($row2[mb_point])."&nbsp;</td>
    </tr> ";
} 

if ($i == 0)
    echo "<tr><td colspan='$colspan' align=center height=100 bgcolor=#ffffff>자료가 없습니다.</td></tr>";

echo "</table>";

$pagelist = get_paging($config[cf_write_pages], $page, $total_page, "$_SERVER[PHP_SELF]?$qstr&page=");
echo "<table width=100% cellpadding=3 cellspacing=1>";
echo "<tr><td width=50%>";
echo "<input type=button class='bttn_common' value='선택삭제' onclick=\"alert('{$zm_config[pointname]}를 삭제하면 회원에게서 다시 {$zm_config[pointname]}를 회수 합니다.'); btn_check(this.form, 'delete')\">";
echo "</td>";
echo "<td width=50% align=right>$pagelist</td></tr></table>\n";

if ($stx)
    echo "<script type='text/javascript'>document.fsearch.sfl.value = '$sfl';</script>\n";

if (strstr($sfl, "mb_id"))
    $mb_id = $stx;
else
    $mb_id = "";
?>
</form>

<script type='text/javascript'> document.fsearch.stx.focus(); </script>

<?$colspan=5?>
<p>
<form name=fpointlist2 method=post onsubmit="return fpointlist2_submit(this);" autocomplete="off">
<input type=hidden name=sfl   value='<?=$sfl?>'>
<input type=hidden name=stx   value='<?=$stx?>'>
<input type=hidden name=sst   value='<?=$sst?>'>
<input type=hidden name=sod   value='<?=$sod?>'>
<input type=hidden name=page  value='<?=$page?>'>
<input type=hidden name=token value='<?=$token?>'>
<table width=100% cellpadding=0 cellspacing=1 class=tbl_box>
<colgroup width=150>
<colgroup width=''>
<colgroup width=100>
<colgroup width=120>
<colgroup width=100>
<tr>
    <th>회원아이디</th>
    <th><?=$zm_config[pointname]?> 내용</th>
    <th><?=$zm_config[pointname]?></th>
    <th>관리자패스워드</th>
    <th>입력</th>
</tr>
<tr>
    <td><input type=text class=ed name=mb_id required itemname='회원아이디' value='<?=$mb_id?>'></td>
    <td><input type=text class=ed name=po_content required itemname='내용' style='width:90%;'></td>
    <td><input type=text class=ed name=po_point required itemname='<?=$zm_config[pointname]?>' size=10></td>
    <td><input type=password class=ed name=admin_password required itemname='관리자 비밀번호'></td>
    <td align="center"><input type=submit class=bttn_adj value='적용'></td>
</tr>
</form>
</table>

<script type="text/javascript">
function fpointlist2_submit(f)
{
    f.action = "./point_update.php";
    return true;
}
</script>

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