Permalink
Newer
Older
100644 131 lines (111 sloc) 3.56 KB
1
<?php
2
/**
3
* Copyright (C) 2005, 2006, 2007, 2008 Brice Burgess <bhb@iceburg.net>
4
*
5
* This file is part of poMMo (http://www.pommo.org)
6
*
7
* poMMo is free software; you can redistribute it and/or modify
8
* it under the terms of the GNU General Public License as published
9
* by the Free Software Foundation; either version 2, or any later version.
10
*
11
* poMMo is distributed in the hope that it will be useful,
12
* but WITHOUT ANY WARRANTY; without even the implied warranty
13
* of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See
14
* the GNU General Public License for more details.
15
*
16
* You should have received a copy of the GNU General Public License
17
* along with program; see the file docs/LICENSE. If not, write to the
18
* Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
19
*/
20
21
/**********************************
22
INITIALIZATION METHODS
23
*********************************/
24
require ('../bootstrap.php');
25
require_once(Pommo::$_baseDir.'classes/Pommo_Groups.php');
27
Pommo::init();
28
$logger = Pommo::$_logger;
29
$dbo = Pommo::$_dbo;
30
31
// Remember the Page State
32
$state = Pommo_Api::stateInit('subscribers_manage');
33
34
// Fetch group + member IDs
35
$group = new Pommo_Groups($state['group'], $state['status'], $state['search']);
36
37
/**********************************
38
JSON OUTPUT INITIALIZATION
39
*********************************/
40
require_once(Pommo::$_baseDir.'classes/Pommo_Json.php');
41
$json = new Pommo_Json();
42
43
/**********************************
44
PAGINATION AND ORDERING
45
*********************************/
46
47
// Get and Remember the requested number of rows
48
if(!empty($_REQUEST['page']) && (
49
is_numeric($_REQUEST['rows']) && (
50
$_REQUEST['rows'] > 0 &&
51
$_REQUEST['rows'] <= 1000
52
)
53
))
54
$state['limit'] = $_REQUEST['rows'];
55
56
// Get and Remember the requested page
57
if(!empty($_REQUEST['page']) && (
58
is_numeric($_REQUEST['page']) &&
59
$_REQUEST['page'] <= $state['pages']
60
))
61
$state['page'] = $_REQUEST['page'];
62
63
// Get and Remember the sort column
64
if(!empty($_REQUEST['sidx']) && (
65
preg_match('/d\d+/',$_REQUEST['sidx']) ||
66
$_REQUEST['sidx'] == 'email' ||
67
$_REQUEST['sidx'] == 'ip' ||
68
$_REQUEST['sidx'] == 'registered' ||
69
$_REQUEST['sidx'] == 'touched'
70
))
71
$state['sort'] = $_REQUEST['sidx'];
72
// Get and Remember the sort order
73
if(!empty($_REQUEST['sord']) && (
74
$_REQUEST['sord'] == 'asc' ||
75
$_REQUEST['sord'] == 'desc'
76
))
77
$state['order'] = $_REQUEST['sord'];
78
79
// Calculate the offset
80
$start = $state['limit']*$state['page']-$state['limit'];
81
if($start < 0)
82
$start = 0;
83
84
85
/**********************************
86
RECORD RETREVIAL
87
*********************************/
88
// Normalize sort column to match DB column
89
if ($state['sort'] == 'registered' || $state['sort'] == 'touched')
90
$state['sort'] = 'time_'.$state['sort'];
91
elseif (substr($state['sort'],0,1) == 'd')
92
$state['sort'] = substr($state['sort'],1);
94
// fetch subscribers for this page
95
$subscribers = $group->members(array(
96
'sort' => $state['sort'],
97
'order' => $state['order'],
98
'limit' => $state['limit'],
99
'offset' => $start));
101
/**********************************
102
OUTPUT FORMATTING
103
*********************************/
104
// format subscribers for JSON output to jqGrid
105
$subOut = array();
106
107
foreach($subscribers as $s) {
108
$sub = array(
109
'id' => $s['id'],
110
'email' => $s['email'],
111
'touched' => $s['touched'],
112
'registered' => $s['registered'],
113
'ip' => $s['ip']
114
);
115
116
foreach($s['data'] as $key => $d)
117
$sub['d'.$key] = $d;
118
119
array_push($subOut,$sub);
120
}
121
122
$json->add(array(
123
'page' => $state['page'],
124
'total' => $state['pages'],
125
'records' => $group->_tally,
126
'rows' => $subOut
127
)
128
);
129
$json->serve();
130