<?php
/*-----------引入檔案區--------------*/
include_once "header.php";
$xoopsOption['template_main'] = "tadnews_archive.tpl";
include_once XOOPS_ROOT_PATH . "/header.php";

/*-----------function區--------------*/

//列出月份
function month_list($now_date = "")
{
    global $xoopsDB, $xoopsTpl;

    $sql = "SELECT left(start_day,7) , count(*) FROM " . $xoopsDB->prefix("tad_news") . " WHERE enable='1' GROUP BY left(start_day,7) ORDER BY start_day DESC";

    $result = $xoopsDB->query($sql) or web_error($sql,__FILE__,__LINE__);
    $i = 1;
    while (list($ym, $count) = $xoopsDB->fetchRow($result)) {
        $opt[$i]['value']    = $ym;
        $opt[$i]['count']    = $count;
        $opt[$i]['text']     = str_replace("-", "" . _MD_TADNEWS_YEAR, $ym) . _MD_TADNEWS_MONTH;
        $opt[$i]['selected'] = $now_date == $ym ? "selected" : "";
        $i++;
    }

    $jquery = get_jquery();
    $xoopsTpl->assign("jquery", $jquery);
    $xoopsTpl->assign("opt", $opt);
}

//分月新聞
function archive($date = "")
{
    global $xoopsModuleConfig, $xoopsTpl, $interface_menu, $tadnews;

    if (empty($date)) {
        $date = date("Y-m");
    }

    //$tadnews->set_show_num($xoopsModuleConfig['show_num']);
    $tadnews->set_news_kind("news");
    $tadnews->set_show_mode('list');
    $tadnews->set_show_month($date);
    $tadnews->set_show_enable(1);
    $tadnews->get_news();
    $xoopsTpl->assign("toolbar", toolbar_bootstrap($interface_menu));
    $date_title = to_utf8(str_replace("-", "" . _MD_TADNEWS_YEAR . " ", $date) . _MD_TADNEWS_MONTH . _MD_TADNEWS_NEWS_TITLE);
    $xoopsTpl->assign("date_title", $date_title);
}

/*-----------執行動作判斷區----------*/
include_once $GLOBALS['xoops']->path('/modules/system/include/functions.php');
$op       = system_CleanVars($_REQUEST, 'op', '', 'string');
$files_sn = system_CleanVars($_REQUEST, 'files_sn', 0, 'int');
$date     = system_CleanVars($_REQUEST, 'date', date("Y-m"), 'string');
$date     = substr($date, 0, 7);

switch ($op) {

    //下載檔案
    case "tufdl":
        $TadUpFiles->add_file_counter($files_sn, false);
        exit;
        break;

    default:
        month_list($date);
        archive($date);
        break;
}

/*-----------秀出結果區--------------*/
$xoopsTpl->assign("toolbar", toolbar_bootstrap($interface_menu));
include_once XOOPS_ROOT_PATH . '/footer.php';
