-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathdomain_counts.php
270 lines (228 loc) · 9.27 KB
/
domain_counts.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
<?php
/*
FusionPBX
Version: MPL 1.1
The contents of this file are subject to the Mozilla Public License Version
1.1 (the "License"); you may not use this file except in compliance with
the License. You may obtain a copy of the License at
http://www.mozilla.org/MPL/
Software distributed under the License is distributed on an "AS IS" basis,
WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
for the specific language governing rights and limitations under the
License.
The Original Code is FusionPBX
The Initial Developer of the Original Code is
Mark J Crane <[email protected]>
Portions created by the Initial Developer are Copyright (C) 2008-2025
the Initial Developer. All Rights Reserved.
Contributor(s):
KonradSC <[email protected]>
*/
//includes files
require_once dirname(__DIR__, 2) . "/resources/require.php";
require_once "resources/check_auth.php";
require_once "resources/paging.php";
//check permissions
if (permission_exists('domain_counts_view')) {
//access granted
}
else {
echo "access denied";
exit;
}
//add multi-lingual support
$language = new text;
$text = $language->get();
//get the settings
$settings = new settings(['database' => $database, 'domain_uuid' => $_SESSION['domain_uuid'] ?? '', 'user_uuid' => $_SESSION['user_uuid'] ?? '']);
//get the http values and set them as variables
$order_by = check_str($_GET["order_by"]);
$order = check_str($_GET["order"]);
//handle search term
$search = check_str($_GET["search"]);
if (strlen($search) > 0) {
$sql_mod = "WHERE d.domain_name like '%".$search."%' ";
}
if (strlen($order_by) < 1) {
$order_by = "domain_name";
$order = "ASC";
}
//get all the counts from the database
$sql = "SELECT \n";
$sql .= "d.domain_uuid, \n";
$sql .= "d.domain_name, \n";
$sql .= "d.domain_description, \n";
//extension
$sql .= "(\n";
$sql .= "select count(*) from v_extensions \n";
$sql .= "where domain_uuid = d.domain_uuid\n";
$sql .= ") as extension_count, \n";
//users
$sql .= "(\n";
$sql .= "select count(*) from v_users \n";
$sql .= "where domain_uuid = d.domain_uuid\n";
$sql .= ") as user_count, \n";
//devices
$sql .= "(\n";
$sql .= "select count(*) from v_devices \n";
$sql .= "where domain_uuid = d.domain_uuid\n";
$sql .= ") as device_count, \n";
//destinations
$sql .= "(\n";
$sql .= "select count(*) from v_destinations \n";
$sql .= "where domain_uuid = d.domain_uuid\n";
$sql .= ") as destination_count, \n";
//faxes
$sql .= "(\n";
$sql .= "select count(*) from v_fax \n";
$sql .= "where domain_uuid = d.domain_uuid\n";
$sql .= ") as fax_count, \n";
//ivr
$sql .= "(\n";
$sql .= "select count(*) from v_ivr_menus \n";
$sql .= "where domain_uuid = d.domain_uuid\n";
$sql .= ") as ivr_count, \n";
//voicemail
$sql .= "(\n";
$sql .= "select count(*) from v_voicemails \n";
$sql .= "where domain_uuid = d.domain_uuid\n";
$sql .= ") as voicemail_count, \n";
//ring_group
$sql .= "(\n";
$sql .= "select count(*) from v_ring_groups \n";
$sql .= "where domain_uuid = d.domain_uuid\n";
$sql .= ") as ring_group_count, \n";
//call_center_queues
$sql .= "(\n";
$sql .= "select count(*) from v_call_center_queues \n";
$sql .= "where domain_uuid = d.domain_uuid\n";
$sql .= ") as cc_queue_count, \n";
//contacts
$sql .= "(\n";
$sql .= "select count(*) from v_contacts \n";
$sql .= "where domain_uuid = d.domain_uuid\n";
$sql .= ") as contact_count, \n";
//accountcodes
$sql .= "(\n";
$sql .= "select count(DISTINCT accountcode) from v_extensions \n";
$sql .= "where domain_uuid = d.domain_uuid\n";
$sql .= ") as accountcode_count \n";
$sql .= "FROM v_domains as d \n";
$sql .= $sql_mod; //add search mod from above
$sql .= "ORDER BY ".$order_by." ".$order." \n";
$database = new database;
$domain_counts = $database->select($sql, null);
//lookup the domain count
$database = new database;
$database->table = "v_domains";
$where[1]["name"] = "domain_uuid";
$where[1]["operator"] = "=";
$where[1]["value"] = "*";
$numeric_domain_counts = $database->count();
unset($database,$result);
//set the http header
if ($_REQUEST['type'] == "csv") {
//set the headers
header('Content-type: application/octet-binary');
header("Content-Disposition: attachment; filename=domain-counts_" . date("Y-m-d") . ".csv");
//show the column names on the first line
$z = 0;
foreach($domain_counts[1] as $key => $val) {
if ($z == 0) {
echo '"'.$key.'"';
}
else {
echo ',"'.$key.'"';
}
$z++;
}
echo "\n";
//add the values to the csv
$x = 0;
foreach($domain_counts as $domains) {
$z = 0;
foreach($domains as $key => $val) {
if ($z == 0) {
echo '"'.$domain_counts[$x][$key].'"';
}
else {
echo ',"'.$domain_counts[$x][$key].'"';
}
$z++;
}
echo "\n";
$x++;
}
exit;
}
//additional includes
require_once "resources/header.php";
$document['title'] = $text['title-domain_counts'];
//set the alternating styles
$c = 0;
$row_style["0"] = "row_style0";
$row_style["1"] = "row_style1";
//show the content
echo "<div class='action_bar' id='action_bar'>\n";
if (permission_exists('domain_counts_view_all')) {
echo " <div class='heading'><b>".$text['header-domain_counts']."</b><div class='count'>".number_format($numeric_domain_counts)."</div></div>\n";
} else if (permission_exists('domain_counts_view_domain')) {
echo " <div class='heading'><b>".$text['header-domain_counts']."</b></div><br>\n";
}
echo " <div class='actions'>\n";
echo " <form method='get' action=''>\n";
echo button::create(['type'=>'button','label'=>$text['button-export'],'icon'=>$settings->get('theme', 'button_icon_export'),'style'=>'margin-right: 15px;','onclick'=>"window.location='domain_counts.php?".(!empty($_SERVER["QUERY_STRING"]) ? $_SERVER["QUERY_STRING"]."&type=csv';" : "type=csv';")]);
if (permission_exists('domain_counts_view_all')) {
echo " <input type='text' class='txt' style='width: 150px' name='search' id='search' value=\"".escape($search)."\" placeholder=\"".$text['label-search']."\" onkeydown=''>";
echo button::create(['label'=>$text['button-search'],'icon'=>$settings->get('theme', 'button_icon_search'),'type'=>'submit','id'=>'btn_search']);
}
# if ($paging_controls_mini != '') {
# echo "<span style='margin-left: 15px;'>".$paging_controls_mini."</span>\n";
# }
echo " </form>\n";
echo " </div>\n";
echo " <div style='clear: both;'></div>\n";
echo "</div>\n";
echo $text['description-domain_counts']."\n";
echo "<br /><br />\n";
echo "<form name='frm' method='post' action='domain_counts_delete.php'>\n";
echo "<div class='card'>\n";
echo "<table class='tr_hover' width='100%' border='0' cellpadding='0' cellspacing='0'>\n";
echo "<tr>\n";
echo th_order_by('domain_name', $text['label-domain_name'], $order_by, $order);
echo th_order_by('extension_count', $text['label-extensions'], $order_by,$order);
echo th_order_by('user_count', $text['label-users'], $order_by, $order);
echo th_order_by('device_count', $text['label-devices'], $order_by, $order);
echo th_order_by('destination_count', $text['label-destinations'], $order_by, $order);
echo th_order_by('fax_count', $text['label-faxes'], $order_by, $order);
echo th_order_by('ivr_count', $text['label-ivrs'], $order_by, $order);
echo th_order_by('voicemail_count', $text['label-voicemails'], $order_by, $order);
echo th_order_by('ring_group_count', $text['label-ring_groups'], $order_by, $order);
echo th_order_by('cc_queue_count', $text['label-cc_queues'], $order_by, $order);
echo th_order_by('contact_count', $text['label-contacts'], $order_by, $order);
echo th_order_by('accountcode_count', $text['label-accountcodes'], $order_by, $order);
echo "</tr>\n";
if (isset($domain_counts)) foreach ($domain_counts as $key => $row) {
if (permission_exists('domain_counts_view_all') || (permission_exists('domain_counts_view_domain') && $_SESSION['domain_name'] == $row['domain_name']) ) {
echo " <td valign='top' class='".$row_style[$c]."'>".escape($row['domain_name'])."</td>\n";
echo " <td valign='top' class='".$row_style[$c]."'>".escape($row['extension_count'])." </td>\n";
echo " <td valign='top' class='".$row_style[$c]."'>".escape($row['user_count'])." </td>\n";
echo " <td valign='top' class='".$row_style[$c]."'>".escape($row['device_count'])." </td>\n";
echo " <td valign='top' class='".$row_style[$c]."'>".escape($row['destination_count'])." </td>\n";
echo " <td valign='top' class='".$row_style[$c]."'>".escape($row['fax_count'])." </td>\n";
echo " <td valign='top' class='".$row_style[$c]."'>".escape($row['ivr_count'])." </td>\n";
echo " <td valign='top' class='".$row_style[$c]."'>".escape($row['voicemail_count'])." </td>\n";
echo " <td valign='top' class='".$row_style[$c]."'>".escape($row['ring_group_count'])." </td>\n";
echo " <td valign='top' class='".$row_style[$c]."'>".escape($row['cc_queue_count'])." </td>\n";
echo " <td valign='top' class='".$row_style[$c]."'>".escape($row['contact_count'])." </td>\n";
echo " <td valign='top' class='".$row_style[$c]."'><a href='domain_counts_accountcodes.php?id=".escape($row['domain_uuid'])."'>".escape($row['accountcode_count'])." </td>\n";
echo "</tr>\n";
$c = ($c==0) ? 1 : 0;
}
}
echo "</table>\n";
echo "</div>\n";
echo "</form>\n";
//show the footer
require_once "resources/footer.php";
?>