示例#1
0
function showMessages($option)
{
    global $database, $mainframe, $my, $mosConfig_list_limit;
    $limit = $mainframe->getUserStateFromRequest("viewlistlimit", 'limit', $mosConfig_list_limit);
    $limitstart = $mainframe->getUserStateFromRequest("view{$option}limitstart", 'limitstart', 0);
    $search = $mainframe->getUserStateFromRequest("search{$option}", 'search', '');
    $search = $database->getEscaped(trim(strtolower($search)));
    $wheres = array();
    $wheres[] = " a.user_id_to='{$my->id}'";
    if (isset($search) && $search != "") {
        $wheres[] = "(u.username LIKE '%{$search}%' OR email LIKE '%{$search}%' OR u.name LIKE '%{$search}%')";
    }
    $database->setQuery("SELECT COUNT(*)" . "\nFROM #__messages AS a" . "\nINNER JOIN #__users AS u ON u.id = a.user_id_from" . ($wheres ? " WHERE " . implode(" AND ", $wheres) : ""));
    $total = $database->loadResult();
    require_once $GLOBALS['mosConfig_absolute_path'] . '/administrator/includes/pageNavigation.php';
    $pageNav = new mosPageNav($total, $limitstart, $limit);
    $database->setQuery("SELECT a.*, u.name AS user_from" . "\nFROM #__messages AS a" . "\nINNER JOIN #__users AS u ON u.id = a.user_id_from" . ($wheres ? " WHERE " . implode(" AND ", $wheres) : "") . "\nORDER BY date_time DESC" . "\nLIMIT {$pageNav->limitstart}, {$pageNav->limit}");
    $rows = $database->loadObjectList();
    if ($database->getErrorNum()) {
        echo $database->stderr();
        return false;
    }
    HTML_messages::showMessages($rows, $pageNav, $search, $option);
}
示例#2
0
function showMessages($option)
{
    global $mainframe;
    $db =& JFactory::getDBO();
    $user =& JFactory::getUser();
    $context = 'com_messages.list';
    $filter_order = $mainframe->getUserStateFromRequest($context . '.filter_order', 'filter_order', 'a.date_time', 'cmd');
    $filter_order_Dir = $mainframe->getUserStateFromRequest($context . '.filter_order_Dir', 'filter_order_Dir', 'DESC', 'word');
    $filter_state = $mainframe->getUserStateFromRequest($context . '.filter_state', 'filter_state', '', 'word');
    $limit = $mainframe->getUserStateFromRequest('global.list.limit', 'limit', $mainframe->getCfg('list_limit'), 'int');
    $limitstart = $mainframe->getUserStateFromRequest($context . '.limitstart', 'limitstart', 0, 'int');
    $search = $mainframe->getUserStateFromRequest($context . 'search', 'search', '', 'string');
    $search = JString::strtolower($search);
    $where = array();
    $where[] = ' a.user_id_to=' . (int) $user->get('id');
    if ($search != '') {
        $searchEscaped = $db->Quote('%' . $db->getEscaped($search, true) . '%', false);
        $where[] = '( a.subject LIKE ' . $searchEscaped . ' OR a.message LIKE ' . $searchEscaped . ' )';
    }
    if ($filter_state) {
        if ($filter_state == 'P') {
            $where[] = 'a.state = 1';
        } else {
            if ($filter_state == 'U') {
                $where[] = 'a.state = 0';
            }
        }
    }
    $where = count($where) ? ' WHERE ' . implode(' AND ', $where) : '';
    $orderby = ' ORDER BY ' . $filter_order . ' ' . $filter_order_Dir . ', a.date_time DESC';
    $query = 'SELECT COUNT(*)' . ' FROM #__messages AS a' . ' INNER JOIN #__users AS u ON u.id = a.user_id_from' . $where;
    $db->setQuery($query);
    $total = $db->loadResult();
    jimport('joomla.html.pagination');
    $pageNav = new JPagination($total, $limitstart, $limit);
    $query = 'SELECT a.*, u.name AS user_from' . ' FROM #__messages AS a' . ' INNER JOIN #__users AS u ON u.id = a.user_id_from' . $where . $orderby;
    $db->setQuery($query, $pageNav->limitstart, $pageNav->limit);
    $rows = $db->loadObjectList();
    if ($db->getErrorNum()) {
        echo $db->stderr();
        return false;
    }
    // state filter
    $lists['state'] = JHTML::_('grid.state', $filter_state, 'Read', 'Unread');
    // table ordering
    $lists['order_Dir'] = $filter_order_Dir;
    $lists['order'] = $filter_order;
    // search filter
    $lists['search'] = $search;
    HTML_messages::showMessages($rows, $pageNav, $option, $lists);
}