<?php
$sub_menu = "900300";
include_once("./_common.php");
@include_once(G5_PLUGIN_PATH."/sms5/JSON.php");

if( !function_exists('json_encode') ) {
    function json_encode($data) {
        $json = new Services_JSON();
        return( $json->encode($data) );
    }
}

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

$lev = array();

for ($i=1; $i<=10; $i++)
{
    $lev[$i] = 0;
}

$qry = sql_query("select mb_level, count(*) as cnt from {$g5['member_table']} where mb_sms=1 and not (mb_hp='') group by mb_level");

while ($row = sql_fetch_array($qry))
{
    $lev[$row['mb_level']] = $row['cnt'];
}
$str_json = array();
$tmp_str = '';
$tmp_str .= '
<div class="table-responsive">
    <table class="table table-bordered table-striped">
    <thead>
    <tr>
        <th scope="col">권한</th>
        <th scope="col">수신가능</th>
        <th scope="col">추가</th>
    </tr>
    </thead>
    <tbody>';
    for ($i=1; $i<=10; $i++) {
        //$bg = 'bg'.($line++%2);
        $tmp_str .= '
        <tr>
            <td>'.$i.' 레벨</td>
            <td>'.number_format($lev[$i]).'</td>
            <td><button type="button" class="btn btn-default" onclick="sms_obj.level_add('.$i.', \''.number_format($lev[$i]).'\')">추가</button></td>
        </tr>';
    }
$tmp_str .= '
    </tbody>
    </table>
</div>';

$str_json['html'] = $tmp_str;
echo json_encode($str_json);
?>