root/trunk/inc/messages/sent.inc.php

Revision 21, 2.4 KB (checked in by alexx, 7 years ago)

Add pagination to friends list

Line 
1<?php
2/****************************************************** Open .node ***
3 * Description:   
4 * Status:        Stable.
5 * Author:        Alexandre Dath <alexandre@dotnode.com>
6 * $Id$
7 *
8 * Copyright (C) 2005 Alexandre Dath <alexandre@dotnode.com>
9 *
10 * This program is free software; you can redistribute it and/or modify
11 * it under the terms of the GNU General Public License as published by
12 * the Free Software Foundation; either version 2 of the License, or
13 * (at your option) any later version.
14 *
15 * This program is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18 * GNU General Public License for more details.
19 *
20 * You should have received a copy of the GNU General Public License
21 * along with this program; if not, write to the Free Software Foundation,
22 * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
23 ******************** http://opensource.ikse.net/projects/dotnode ***/
24
25include_once(INCLUDESPATH.'/pager.inc.php');
26
27$_SMARTY['Title'] =  'Messages';
28
29$nb_messages = $db->getOne('SELECT COUNT(id_mess) FROM message WHERE id_from=? AND box=?', array($_SESSION['my_id'],'send'));
30
31$pager =& Pager_dotnode::factory(null, array('totalItems' => $nb_messages));
32
33list($first_item, $last_item) = $pager->getOffsetByPageId();
34$limit_offset = $first_item-1;
35$limit_length = $last_item-$limit_offset;
36
37$messages_r = $db->query('SELECT id, id_mess, id_from, from_str, type, dest, subject, message, flag, date FROM message WHERE id_from=? AND box=? ORDER by date DESC LIMIT !,!', array($_SESSION['my_id'],'send', $limit_offset, $limit_length) );
38
39$cache=array();
40
41if(!DB::isError($messages_r) )
42while($message = $messages_r->fetchRow())
43{
44    $messages[$message['id_mess']] = $message;
45    if($message['dest'] == 'one')
46    {
47        if(!isset($cache[$message['id']]))
48        {
49            $to = $db->getRow('SELECT id, fname, lname FROM user WHERE id=?', array($message['id']));
50            $cache[$message['id']] = $to;
51        }
52        $messages[$message['id_mess']]['dest_str'] = $cache[$message['id']]['fname'].' '.$cache[$message['id']]['lname'];
53    }
54    else
55        $messages[$message['id_mess']]['dest_str'] = $labels['message']['dest'][$message['dest']];
56}
57else
58    error_log($_SERVER['HTTP_HOST'].' | '.__FILE__.' | '.$messages_r->getUserInfo());
59
60$_SMARTY['pager'] = $pager->getLinks();
61$_SMARTY['messages'] = $messages;
62?>
Note: See TracBrowser for help on using the browser.