-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathmessage_summary.php
228 lines (195 loc) · 8.91 KB
/
message_summary.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
<?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) 2023-2024
the Initial Developer. All Rights Reserved.
Contributor(s):
Mark J Crane <[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('message_view')) {
//access granted
}
else {
echo "access denied";
exit;
}
//add multi-lingual support
$language = new text;
$text = $language->get();
//retrieve submitted data
if (!empty($_REQUEST)) {
$quick_select = $_REQUEST['quick_select'];
$message_date_begin = $_REQUEST['message_date_begin'];
$message_date_end = $_REQUEST['message_date_end'];
}
else {
$quick_select = 3; //set default
}
//get the summary
$message = new messages;
if (!empty($quick_select)) {
$message->quick_select = $quick_select;
}
else {
$message->message_date_begin = $message_date_begin ?? '';
$message->message_date_end = $message_date_end ?? '';
}
$summary = $message->message_summary();
// view_array($summary); exit;
//set the http header
if (!empty($_REQUEST['type']) && $_REQUEST['type'] == "csv") {
//set the headers
header('Content-type: application/octet-binary');
header('Content-Disposition: attachment; filename=message-summary.csv');
//show the column names on the first line
$z = 0;
if (!empty($summary) && is_array($summary)) {
foreach ($summary[0] as $key => $val) {
if ($z == 0) {
echo '"'.$key.'"';
}
else {
echo ',"'.$key.'"';
}
$z++;
}
echo "\n";
}
//add the values to the csv
$x = 0;
if (!empty($summary) && is_array($summary)) {
foreach ($summary as $users) {
$z = 0;
foreach ($users as $key => $val) {
if ($z == 0) {
echo '"'.$summary[$x][$key].'"';
}
else {
echo ',"'.$summary[$x][$key].'"';
}
$z++;
}
echo "\n";
$x++;
}
}
exit;
}
//include the header
$document['title'] = $text['title-message_summary'];
require_once "resources/header.php";
//css grid adjustment
echo "<style>\n";
echo " div.form_grid {\n";
echo " grid-template-columns: repeat(auto-fill, minmax(350px, 1fr));\n";
echo " }\n";
echo "</style>\n";
//show the content
echo "<div class='action_bar' id='action_bar'>\n";
echo " <div class='heading'><b>".$text['title-message_summary']."</b></div>\n";
echo " <div class='actions'>\n";
if (permission_exists('message_summary_all') && $_GET['show'] != 'all') {
echo button::create(['type'=>'button','label'=>$text['button-show_all'],'icon'=>$_SESSION['theme']['button_icon_all'],'collapse'=>'hide-sm-dn','link'=>'message_summary.php?show=all']);
}
echo button::create(['type'=>'button','label'=>$text['button-download_csv'],'icon'=>$_SESSION['theme']['button_icon_download'],'collapse'=>'hide-sm-dn','link'=>'message_summary.php?'.(!empty($_SERVER["QUERY_STRING"]) ? $_SERVER["QUERY_STRING"].'&' : null).'type=csv']);
echo button::create(['type'=>'button','label'=>$text['button-reset'],'icon'=>$_SESSION['theme']['button_icon_reset'],'collapse'=>'hide-xs','style'=>'margin-left: 15px;','link'=>'message_summary.php']);
echo button::create(['type'=>'button','label'=>$text['button-update'],'icon'=>$_SESSION['theme']['button_icon_save'],'id'=>'btn_save','collapse'=>'hide-xs','onclick'=>"document.getElementById('frm').submit();"]);
echo " </div>\n";
echo " <div style='clear: both;'></div>\n";
echo "</div>\n";
if (permission_exists('message_search')) {
echo "<form name='frm' id='frm' method='get' autocomplete='off'>\n";
echo "<div class='card' style='margin-bottom: 30px;'>\n";
echo "<div class='form_grid'>\n";
echo " <div class='form_set'>\n";
echo " <div class='label'>\n";
echo " ".$text['label-preset']."\n";
echo " </div>\n";
echo " <div class='field'>\n";
echo " <select class='formfld' name='quick_select' id='quick_select' onchange=\"if (this.selectedIndex != 0) { document.getElementById('message_date_begin').value = ''; document.getElementById('message_date_end').value = ''; document.getElementById('frm').submit(); }\">\n";
echo " <option value=''></option>\n";
echo " <option value='1' ".($quick_select == 1 ? "selected='selected'" : null).">".$text['option-last_seven_days']."</option>\n";
echo " <option value='2' ".($quick_select == 2 ? "selected='selected'" : null).">".$text['option-last_hour']."</option>\n";
echo " <option value='3' ".($quick_select == 3 ? "selected='selected'" : null).">".$text['option-today']."</option>\n";
echo " <option value='4' ".($quick_select == 4 ? "selected='selected'" : null).">".$text['option-yesterday']."</option>\n";
echo " <option value='5' ".($quick_select == 5 ? "selected='selected'" : null).">".$text['option-this_week']."</option>\n";
echo " <option value='6' ".($quick_select == 6 ? "selected='selected'" : null).">".$text['option-this_month']."</option>\n";
echo " <option value='7' ".($quick_select == 7 ? "selected='selected'" : null).">".$text['option-this_year']."</option>\n";
echo " </select>\n";
echo " </div>\n";
echo " </div>\n";
echo " <div class='form_set'>\n";
echo " <div class='label'>\n";
echo " ".$text['label-start_date_time']."\n";
echo " </div>\n";
echo " <div class='field'>\n";
echo " <input type='text' class='formfld datetimepicker' data-toggle='datetimepicker' data-target='#message_date_begin' onblur=\"$(this).datetimepicker('hide');$('#quick_select option').removeAttr('selected');\" style='min-width: 115px; width: 115px; max-width: 115px;' name='message_date_begin' id='message_date_begin' placeholder='".$text['label-from']."' value='".escape($message_date_begin ?? '')."'>\n";
echo " </div>\n";
echo " </div>\n";
echo " <div class='form_set'>\n";
echo " <div class='label'>\n";
echo " ".$text['label-end_date_time']."\n";
echo " </div>\n";
echo " <div class='field'>\n";
echo " <input type='text' class='formfld datetimepicker' data-toggle='datetimepicker' data-target='#message_date_end' onblur=\"$(this).datetimepicker('hide');$('#quick_select option').removeAttr('selected');\" style='min-width: 115px; width: 115px; max-width: 115px;' name='message_date_end' id='message_date_end' placeholder='".$text['label-to']."' value='".escape($message_date_end ?? '')."'>\n";
echo " </div>\n";
echo " </div>\n";
echo "</div>\n";
echo "</div>\n";
if (!empty($_GET['show']) && $_GET['show'] == 'all' && permission_exists('message_summary_all')) {
echo "<input type='hidden' name='show' value='all'>";
}
echo "</form>";
}
//show the results
echo "<div class='card'>\n";
echo "<table class='list'>\n";
echo " <tr class='list-header'>\n";
if (!empty($_GET['show']) && $_GET['show'] === "all" && permission_exists('message_summary_all')) {
echo " <th>".$text['label-domain']."</th>\n";
}
echo " <th>".$text['label-message_destination']."</th>\n";
echo " <th class='center'>".$text['label-message_read']."</th>\n";
echo " <th class='center'>".$text['label-message_unread']."</th>\n";
echo " <th class='center'>".$text['label-message_received']."</th>\n";
echo " <th class='center'>".$text['label-message_sent']."</th>\n";
echo " <th class='hide-sm-dn'>".$text['label-message_description']."</th>\n";
echo " </tr>\n";
if (!empty($summary) && is_array($summary)) {
foreach ($summary as $key => $row) {
echo "<tr class='list-row'>\n";
if (!empty($_GET['show']) && $_GET['show'] === "all" && permission_exists('message_summary_all')) {
echo " <td style=\"cursor: default\">".escape($row['domain_name'])."</td>\n";
}
echo " <td style=\"cursor: default\">".escape($row['destination'])."</td>\n";
echo " <td class='center' style=\"cursor: default\">".escape($row['message_read'])." </td>\n";
echo " <td class='center' style=\"cursor: default\">".escape($row['message_unread'])." </td>\n";
echo " <td class='center' style=\"cursor: default\">".escape($row['message_received'])." </td>\n";
echo " <td class='center' style=\"cursor: default\">".escape($row['message_sent'])." </td>\n";
echo " <td class='description overflow hide-sm-dn' style=\"cursor: default\">".escape($row['destination_description'])." </td>\n";
echo "</tr>\n";
}
}
echo "</table>\n";
echo "</div>\n";
echo "<br />\n";
//show the footer
require_once "resources/footer.php";
?>