forked from lirantal/daloradius
-
Notifications
You must be signed in to change notification settings - Fork 0
/
bill-payments-list.php
272 lines (216 loc) · 10.2 KB
/
bill-payments-list.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
<?php
/*
*********************************************************************************************************
* daloRADIUS - RADIUS Web Platform
* Copyright (C) 2007 - Liran Tal <[email protected]> All Rights Reserved.
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 2
* of the License, or (at your option) any later version.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*
*********************************************************************************************************
*
* Authors: Liran Tal <[email protected]>
* Filippo Lauria <[email protected]>
*
*********************************************************************************************************
*/
include("library/checklogin.php");
$operator = $_SESSION['operator_user'];
include('library/check_operator_perm.php');
include_once('library/config_read.php');
include_once("lang/main.php");
include("library/layout.php");
// init logging variables
$log = "visited page: ";
$logQuery = "performed query on page: ";
$logDebugSQL = "";
// set session's page variable
$_SESSION['PREV_LIST_PAGE'] = $_SERVER['REQUEST_URI'];
$cols = array(
"id" => t('all','ID'),
"invoice_id" => t('all','PaymentInvoiceID'),
t('all','PaymentAmount'),
t('all','PaymentDate'),
t('all','PaymentType'),
t('all','PaymentNotes')
);
$colspan = count($cols);
$half_colspan = intval($colspan / 2);
$param_cols = array();
foreach ($cols as $k => $v) { if (!is_int($k)) { $param_cols[$k] = $v; } }
// whenever possible we use a whitelist approach
$orderBy = (array_key_exists('orderBy', $_GET) && isset($_GET['orderBy']) &&
in_array($_GET['orderBy'], array_keys($param_cols)))
? $_GET['orderBy'] : array_keys($param_cols)[0];
$orderType = (array_key_exists('orderType', $_GET) && isset($_GET['orderType']) &&
in_array(strtolower($_GET['orderType']), array( "desc", "asc" )))
? strtolower($_GET['orderType']) : "desc";
$invoice_id = (array_key_exists('invoice_id', $_GET) && isset($_GET['invoice_id']) &&
preg_match('/^[0-9]+$/', $_GET['invoice_id']) !== false)
? $_GET['invoice_id'] : "";
$user_id = (array_key_exists('user_id', $_GET) && isset($_GET['user_id']) &&
preg_match('/^[0-9]+$/', $_GET['user_id']) !== false)
? $_GET['user_id'] : "";
$username = (array_key_exists('username', $_GET) && isset($_GET['username']))
? str_replace('%', '', $_GET['username']) : "";
$username_enc = (!empty($username)) ? htmlspecialchars($username, ENT_QUOTES, 'UTF-8') : "";
// feed the sidebar
$edit_username = $username_enc;
$edit_invoice_id = $invoice_id;
// print HTML prologue
$title = t('Intro','paymentslist.php');
$help = t('helpPage','paymentslist');
print_html_prologue($title, $langCode);
include("menu-bill-payments.php");
// start printing content
echo '<div id="contentnorightbar">';
print_title_and_help($title, $help);
include('library/opendb.php');
include('include/management/pages_common.php');
// if provided username, we'll need to turn that into the userbillinfo user id
if (!empty($username)) {
$sql = sprintf("SELECT id FROM %s WHERE username='%s'",
$configValues['CONFIG_DB_TBL_DALOUSERBILLINFO'],
$dbSocket->escapeSimple($username));
$res = $dbSocket->query($sql);
$logDebugSQL .= "$sql;\n";
$row = $res->fetchRow();
$user_id = intval($row[0]);
}
$sql_WHERE = array();
$sql_JOIN = "";
// if invoice_id then we need to lookup specific invoices
if (!empty($invoice_id)) {
$sql_WHERE[] = sprintf("p.invoice_id = %s", $dbSocket->escapeSimple($invoice_id));
}
// if we did get a user id let's make the sql query specific to payments by this user
if (isset($user_id) && !empty($user_id)) {
$sql_JOIN = sprintf("JOIN %s AS bi ON bi.id=p.invoice_id", $configValues['CONFIG_DB_TBL_DALOBILLINGINVOICE']);
$sql_WHERE[] = sprintf("bi.user_id = %s", $dbSocket->escapeSimple($user_id));
}
$sql = sprintf("SELECT p.id, p.invoice_id, p.amount, p.date, pt.value, p.notes
FROM %s AS p %s LEFT JOIN %s AS pt ON p.type_id=pt.id", $configValues['CONFIG_DB_TBL_DALOPAYMENTS'],
$sql_JOIN,
$configValues['CONFIG_DB_TBL_DALOPAYMENTTYPES']);
if (count($sql_WHERE) > 0) {
$sql .= " WHERE " . implode(" AND ", $sql_WHERE);
}
$res = $dbSocket->query($sql);
$numrows = $res->numRows();
if ($numrows > 0) {
/* START - Related to pages_numbering.php */
// when $numrows is set, $maxPage is calculated inside this include file
include('include/management/pages_numbering.php'); // must be included after opendb because it needs to read
// the CONFIG_IFACE_TABLES_LISTING variable from the config file
// here we decide if page numbers should be shown
$drawNumberLinks = strtolower($configValues['CONFIG_IFACE_TABLES_LISTING_NUM']) == "yes" && $maxPage > 1;
/* END */
// we execute and log the actual query
$sql .= sprintf(" ORDER BY %s %s LIMIT %s, %s", $orderBy, $orderType, $offset, $rowsPerPage);
$res = $dbSocket->query($sql);
$logDebugSQL .= "$sql;\n";
$per_page_numrows = $res->numRows();
// this can be passed as form attribute and
// printTableFormControls function parameter
$action = "bill-payments-del.php";
?>
<form name="listall" method="POST" action="<?= $action ?>">
<table border="0" class="table1">
<thead>
<?php
// page numbers are shown only if there is more than one page
if ($drawNumberLinks) {
echo '<tr style="background-color: white">';
printf('<td style="text-align: left" colspan="%s">go to page: ', $colspan);
setupNumbering($numrows, $rowsPerPage, $pageNum, $orderBy, $orderType);
echo '</td>' . '</tr>';
}
?>
<tr>
<th style="text-align: left" colspan="<?= $colspan ?>">
<?php
printTableFormControls('payment_id[]', $action);
?>
</th>
</tr>
<tr>
<?php
// second line of table header
printTableHead($cols, $orderBy, $orderType);
?>
</tr>
</thead>
<tbody>
<?php
$count = 1;
while ($row = $res->fetchRow()) {
$rowlen = count($row);
// escape row elements
for ($i = 0; $i < $rowlen; $i++) {
$row[$i] = htmlspecialchars($row[$i], ENT_QUOTES, 'UTF-8');
}
list($payment_id, $invoice_id, $amount, $date, $value, $notes) = $row;
$onclick = 'javascript:return false;';
$li_style = 'margin: 7px auto';
$tooltipText1 = '<ul style="list-style-type: none">'
. sprintf('<li style="%s"><a class="toolTip" href="bill-payments-edit.php?payment_id=%s">%s</a></li>',
$li_style, urlencode($payment_id), t('Tooltip','EditPayment'))
. sprintf('<li style="%s"><a class="toolTip" href="bill-payments-del.php?payment_id=%s">%s</a></li>',
$li_style, urlencode($payment_id), t('Tooltip','RemovePayment'))
. '</ul>';
$tooltipText2 = sprintf('<a class="toolTip" href="bill-invoice-edit.php?invoice_id=%s">%s</a>',
urlencode($invoice_id), t('Tooltip','InvoiceEdit'));
?>
<tr>
<td>
<input type="checkbox" name="payment_id[]" value="<?= $payment_id ?>" id="<?= "checkbox-$count" ?>">
<label for="<?= "checkbox-$count" ?>">
<a class="tablenovisit" href="#" onclick="<?= $onclick ?>" tooltipText='<?= $tooltipText1 ?>'>
<?= $payment_id ?>
</a>
</label>
</td>
<td>
<a class="tablenovisit" href="#" onclick="<?= $onclick ?>" tooltipText='<?= $tooltipText2 ?>'>
<?= $invoice_id ?>
</a>
</td>
<td class="money"><?= $amount ?></td>
<td><?= $date ?></td>
<td><?= $value ?></td>
<td><?= $notes ?></td>
</tr>
<?php
$count++;
}
?>
</tbody>
<?php
// tfoot
$links = setupLinks_str($pageNum, $maxPage, $orderBy, $orderType);
printTableFoot($per_page_numrows, $numrows, $colspan, $drawNumberLinks, $links);
?>
</table>
<input type="hidden" name="csrf_token" value="<?= dalo_csrf_token() ?>">
</form>
<?php
} else {
$failureMsg = "Nothing to display";
include_once("include/management/actionMessages.php");
}
include('library/closedb.php');
include('include/config/logging.php');
$inline_extra_js = "
var tooltipObj = new DHTMLgoodies_formTooltip();
tooltipObj.setTooltipPosition('right');
tooltipObj.setPageBgColor('#EEEEEE');
tooltipObj.setTooltipCornerSize(15);
tooltipObj.initFormFieldTooltip()";
print_footer_and_html_epilogue($inline_extra_js);
?>