<?php

/*
 * 사이드메뉴 플러그인
 */
if (!defined('_GNUBOARD_')) {
    exit;
}

function plugin_sidemenu($group_id) {
    global $g5;
    $cfg = get_plugin_config('sidemenu'); //플러그인 환경설정
    if (!$cfg) {
        //echo "플러그인 환경설정을 하세요!";
        return false;
    }
    //플러그인 미사용 중지
    if ($cfg['pc_use'] == 0) {
        return false;
    }
    if(!$group_id){
        return false;
    }
    $group_info = get_group($group_id);
    $me_code = ps_get_mecode($group_id);
    $str = "<div class='grid grid-pad'><div class='side_menu_wrap'><h2><a href='" . G5_BBS_URL . "/group.php?gr_id={$group_info['gr_id']}'>{$group_info['gr_subject']}</a></h2>";
    $sql2 = " select * from {$g5['menu_table']} where me_use = '1' and length(me_code) = '4' and substring(me_code, 1, 2) = '{$me_code}' order by me_order, me_id ";
    $result2 = sql_query($sql2);
    $str .= '<ul class="side_menu">' . PHP_EOL;
    for ($k = 0; $row2 = sql_fetch_array($result2); $k++) {
        $str .= "<li><a href='{$row2['me_link']}' target='_{$row2['me_target']}'>{$row2['me_name']}</a></li>" . PHP_EOL;
    }

    $str .= '</ul></div></div>' . PHP_EOL;
    if($k == 0){
        $str = '';
    }
    echo $str;
}

function ps_get_mecode($group_id){
    $sql = "select * from ask_plugin_sidemenu where as_gr_id = '{$group_id}' and as_status = '1'";
    $me_code = sql_fetch($sql);
    return $me_code['as_me_code'];
}
