function module_event()
{
    $option = JRequest::getVar('option');
    $mainframe = JFactory::getApplication();
    $db = JFactory::getDBO();
    $cal = JRequest::getVar('cal', 0);
    $cal = JRequest::getVar('cal', 0);
    if ($cal == '') {
        $cal = 0;
    }
    $filter_order = $mainframe->getUserStateFromRequest($option . 'filter_order_note', 'filter_order_note', 'id', 'cmd');
    $filter_order_Dir = $mainframe->getUserStateFromRequest($option . 'filter_order_Dir_note', 'filter_order_Dir_note', '', 'word');
    $filter_state = $mainframe->getUserStateFromRequest($option . 'filter_state_note', 'filter_state_note', '', 'word');
    $search_note = $mainframe->getUserStateFromRequest($option . 'search_note', 'search_note', '', 'string');
    $search_note = JString::strtolower($search_note);
    $limit = $mainframe->getUserStateFromRequest('global.list.limit', 'limit', $mainframe->getCfg('list_limit'), 'int');
    $limitstart = $mainframe->getUserStateFromRequest($option . '.limitstart', 'limitstart', 0, 'int');
    $lists = array();
    $where = array();
    $lists['search_note'] = $mainframe->getUserStateFromRequest($option . 'search_note', 'search_note', '', 'string');
    $lists['search_note'] = JString::strtolower($lists['search_note']);
    $lists['startdate'] = JRequest::getVar('startdate', "");
    $lists['enddate'] = JRequest::getVar('enddate', "");
    if ($lists['search_note']) {
        $where[] = ' se.title LIKE "%' . $db->escape($search_note) . '%" AND se.calendar="' . $cal . '" AND se.published="1"';
    }
    if ($lists['search_note']) {
        if ($lists['startdate'] != '') {
            $where[] = "  `date`>='" . $db->escape($lists['startdate']) . "' ";
        }
        if ($lists['enddate'] != '') {
            $where[] = "  `date`<='" . $db->escape($lists['enddate']) . "' ";
        }
    } else {
        if ($lists['startdate'] != '') {
            $where[] = "  `event_day`>='" . $db->escape($lists['startdate']) . "' AND calendar='" . $cal . "' ";
        }
        if ($lists['enddate'] != '') {
            $where[] = "  `event_day`<='" . $db->escape($lists['enddate']) . "' AND calendar='" . $cal . "'  ";
        }
    }
    $filter = '';
    $filter = count($where) ? ' WHERE ' . implode(' AND ', $where) : '';
    if (count($where) == 0) {
        $filter .= ' WHERE calendar=' . $cal . ' AND published="1"';
    }
    if ($filter_order == 'id') {
        $orderby = ' ORDER BY id ' . $filter_order_Dir;
    } else {
        $orderby = ' ORDER BY ' . $filter_order . ' ' . $filter_order_Dir . ', id';
    }
    // get the total number of records
    $query = 'SELECT COUNT(*)' . ' FROM #__spidercalendar_event ' . $filter;
    $db->setQuery($query);
    $total = $db->loadResult();
    jimport('joomla.html.pagination');
    $pageNav = new JPagination($total, $limitstart, $limit);
    $query = "SELECT * FROM #__spidercalendar_event  " . $filter . $orderby;
    $db->setQuery($query, $pageNav->limitstart, $pageNav->limit);
    $rows = $db->loadObjectList();
    if ($db->getErrorNum()) {
        echo $db->stderr();
        return false;
    }
    // table ordering
    $lists['order_Dir'] = $filter_order_Dir;
    $lists['order'] = $filter_order;
    // search filter
    $lists['search_note'] = $search_note;
    // display function
    if ($cal != 0) {
        HTML_contact::module_event($rows, $pageNav, $lists);
    } else {
        echo '<div style="text-align:center;"><p style="font-size:25px">Please select calendar</p><div>';
    }
}