case 'download':
     if ($log_type_id >= 0 && $log_type_id <= 19) {
         // download event logs
         xoonips_eventlog_download($is_post, $log_type_id);
     } else {
         if ($log_type_id == 20 || $log_type_id == 21) {
             // download registered data
             xoonips_eventlog_download_registered_list($is_post, $log_type_id);
         } else {
             die('invalid log type id');
         }
     }
     break;
 case 'graphview':
     // show graph view page
     $time_range = xoonips_eventlog_get_request_date($is_post, false);
     $start_time = $time_range['StartDate']['value'];
     $end_time = $time_range['EndDate']['value'];
     if ($start_time > $end_time) {
         die('invalid time range');
     }
     $breadcrumbs[] = array('name' => _MD_XOONIPS_BREADCRUMBS_EVENTLOG_GRAPH);
     $xoopsOption['template_main'] = 'xoonips_event_graph.html';
     include XOOPS_ROOT_PATH . '/header.php';
     $xoopsTpl->assign('xoops_breadcrumbs', $breadcrumbs);
     $xoopsTpl->assign('log_type_id', $log_type_id);
     $xoopsTpl->assign('start_time', $start_time);
     $xoopsTpl->assign('end_time', $end_time);
     include XOOPS_ROOT_PATH . '/footer.php';
     break;
 case 'graph':
/**
 * draw graph
 *
 * @access public
 * @param int $log_type_id log type id
 */
function xoonips_eventlog_graph($log_type_id)
{
    if ($log_type_id < 1 || $log_type_id > 14) {
        die('invalid log type id');
    }
    $time_range = xoonips_eventlog_get_request_date(false, false);
    $start_time = $time_range['StartDate']['value'];
    $end_time = $time_range['EndDate']['value'];
    $start_label = $time_range['StartDate']['label'];
    $end_label = $time_range['EndDate']['label'];
    if ($start_time > $end_time) {
        die('invalid time range');
    }
    $st_year = date('Y', $start_time);
    $st_month = date('m', $start_time);
    $en_year = date('Y', $end_time);
    $en_month = date('m', $end_time);
    if ($st_year == $en_year && $st_month == $en_month) {
        $xlabel = sprintf('%04d.%02d', $st_year, $st_month);
    } else {
        $xlabel = sprintf('%04d.%02d-%04d.%02d', $st_year, $st_month, $en_year, $en_month);
    }
    $xlabel_sub = array('day' => _MD_XOONIPS_EVENTLOG_DAYS_LABEL, 'total' => _MD_XOONIPS_EVENTLOG_DAYS_LABEL, 'month' => _MD_XOONIPS_EVENTLOG_MONTHS_LABEL, 'domain' => _MD_XOONIPS_EVENTLOG_DOMAINS_LABEL);
    // get operating conditions
    list($suffix, $event_type_id, $query_type, $csv_title, $title) = _xoonips_eventlog_logtype2vars($log_type_id);
    $xlabel .= '[' . $xlabel_sub[$query_type] . ']';
    // create data
    $objs =& _xoonips_eventlog_get($start_time, $end_time, $event_type_id, $query_type);
    $ydata = array();
    $xdata = array();
    switch ($query_type) {
        case 'day':
        case 'total':
            $logs = array();
            foreach ($objs as $obj) {
                $event_date = $obj->getExtraVar('event_date');
                $event_count = $obj->getExtraVar('cnt');
                $logs[$event_date] = $event_count;
            }
            // prepare for days
            $days = intval(($end_time - $start_time) / 86400);
            // create access log of all days from $arr variable
            $amount = 0;
            for ($i = 0; $i < $days; $i++) {
                $label = date('Y-m-d', $start_time + 86400 * $i);
                list($year, $month, $day) = explode('-', $label);
                // get access count if given.
                $count = array_key_exists($label, $logs) ? $logs[$label] : 0;
                $amount += intval($count);
                // create x label
                if ($days < 70) {
                    $day_label = strval(intval($day));
                } else {
                    if ($days < 190) {
                        if ($day == '01') {
                            $day_label = $year . '.' . $month;
                        } else {
                            $day_label = '';
                        }
                    } else {
                        if ($day == '01' && intval($month) % 3 == 1) {
                            $day_label = $year . '.' . $month;
                        } else {
                            $day_label = '';
                        }
                    }
                }
                // set data
                $xdata[] = $day_label;
                $ydata[] = $query_type == 'total' ? $amount : $count;
            }
            break;
        case 'month':
            $logs = array();
            foreach ($objs as $obj) {
                $event_month = $obj->getExtraVar('event_month');
                $event_count = $obj->getExtraVar('cnt');
                $logs[$event_month] = $event_count;
            }
            // get each day, month, year
            $month_arr = array('01', '02', '03', '04', '05', '06', '07', '08', '09', '10', '11', '12');
            // calc months
            $years = intval($en_year) - intval($st_year);
            if ($years <= 0) {
                $months = intval($en_month) - intval($st_month) + 1;
            } else {
                $months = intval($en_month) - intval($st_month) + 1 + $years * 12;
            }
            $amount = 0;
            for ($i = 0; $i < $months; $i++) {
                $tmp = $st_month + $i - 1;
                $month = $tmp % 12 + 1;
                $year = $st_year + intval($tmp / 12);
                // create x label
                $month_label = $year . '-' . $month_arr[$month - 1];
                // get access count if given.
                if (array_key_exists($month_label, $logs)) {
                    $count = $logs[$month_label];
                } else {
                    $count = 0;
                }
                $amount += $count;
                $xdata[] = $month_label;
                $ydata[] = $is_total ? $amount : $count;
            }
            break;
        case 'domain':
            $logs = array();
            foreach ($objs as $obj) {
                $remote_host = $obj->getVar('remote_host', 'n');
                $event_count = $obj->getExtraVar('cnt');
                $event_domain = _xoonips_eventlog_get_domain($remote_host);
                if (isset($logs[$event_domain])) {
                    $logs[$event_domain] += $event_count;
                } else {
                    $logs[$event_domain] = $event_count;
                }
            }
            if (count($logs) > 0) {
                arsort($logs, SORT_NUMERIC);
            }
            foreach ($logs as $domain => $value) {
                $xdata[] = $domain;
                $ydata[] = $value;
            }
    }
    _xoonips_eventlog_graph_draw($xdata, $ydata, $title, $xlabel, $query_type);
    exit;
}