Ejemplo n.º 1
0
function show_calendar()
{
    $option = JRequest::getVar('option');
    $mainframe = JFactory::getApplication();
    $db = JFactory::getDBO();
    $filter_order = $mainframe->getUserStateFromRequest($option . 'filter_order_calendar', 'filter_order_calendar', 'id', 'cmd');
    //$filter_order='id';
    $filter_order_Dir = $mainframe->getUserStateFromRequest($option . 'filter_order_Dir_calendar', 'filter_order_Dir_calendar', 'desc', 'word');
    $search_calendar = $mainframe->getUserStateFromRequest($option . 'search_calendar', 'search_calendar', '', 'string');
    $search_calendar = JString::strtolower($search_calendar);
    $limit = $mainframe->getUserStateFromRequest('global.list.limit', 'limit', $mainframe->getCfg('list_limit'), 'int');
    $limitstart = $mainframe->getUserStateFromRequest($option . '.limitstart', 'limitstart', 0, 'int');
    $where = array();
    if ($search_calendar) {
        $where[] = 'title LIKE "%' . $db->escape($search_calendar) . '%"';
    }
    $where = count($where) ? ' WHERE ' . implode(' AND ', $where) : '';
    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_calendar" . $where;
    $db->setQuery($query);
    $total = $db->loadResult();
    jimport('joomla.html.pagination');
    $pageNav = new JPagination($total, $limitstart, $limit);
    $query = "SELECT * FROM #__spidercalendar_calendar" . $where . $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_calendar filter
    $lists['search_calendar'] = $search_calendar;
    // display function
    HTML_contact::show_calendar($rows, $pageNav, $lists);
}