message_summary.php 8.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228
  1. <?php
  2. /*
  3. FusionPBX
  4. Version: MPL 1.1
  5. The contents of this file are subject to the Mozilla Public License Version
  6. 1.1 (the "License"); you may not use this file except in compliance with
  7. the License. You may obtain a copy of the License at
  8. http://www.mozilla.org/MPL/
  9. Software distributed under the License is distributed on an "AS IS" basis,
  10. WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
  11. for the specific language governing rights and limitations under the
  12. License.
  13. The Original Code is FusionPBX
  14. The Initial Developer of the Original Code is
  15. Mark J Crane <[email protected]>
  16. Portions created by the Initial Developer are Copyright (C) 2023-2024
  17. the Initial Developer. All Rights Reserved.
  18. Contributor(s):
  19. Mark J Crane <[email protected]>
  20. */
  21. //includes files
  22. require_once dirname(__DIR__, 2) . "/resources/require.php";
  23. require_once "resources/check_auth.php";
  24. //require_once "resources/paging.php";
  25. //check permissions
  26. if (permission_exists('message_view')) {
  27. //access granted
  28. }
  29. else {
  30. echo "access denied";
  31. exit;
  32. }
  33. //add multi-lingual support
  34. $language = new text;
  35. $text = $language->get();
  36. //retrieve submitted data
  37. if (!empty($_REQUEST)) {
  38. $quick_select = $_REQUEST['quick_select'];
  39. $message_date_begin = $_REQUEST['message_date_begin'];
  40. $message_date_end = $_REQUEST['message_date_end'];
  41. }
  42. else {
  43. $quick_select = 3; //set default
  44. }
  45. //get the summary
  46. $message = new messages;
  47. if (!empty($quick_select)) {
  48. $message->quick_select = $quick_select;
  49. }
  50. else {
  51. $message->message_date_begin = $message_date_begin ?? '';
  52. $message->message_date_end = $message_date_end ?? '';
  53. }
  54. $summary = $message->message_summary();
  55. // view_array($summary); exit;
  56. //set the http header
  57. if (!empty($_REQUEST['type']) && $_REQUEST['type'] == "csv") {
  58. //set the headers
  59. header('Content-type: application/octet-binary');
  60. header('Content-Disposition: attachment; filename=message-summary.csv');
  61. //show the column names on the first line
  62. $z = 0;
  63. if (!empty($summary) && is_array($summary)) {
  64. foreach ($summary[0] as $key => $val) {
  65. if ($z == 0) {
  66. echo '"'.$key.'"';
  67. }
  68. else {
  69. echo ',"'.$key.'"';
  70. }
  71. $z++;
  72. }
  73. echo "\n";
  74. }
  75. //add the values to the csv
  76. $x = 0;
  77. if (!empty($summary) && is_array($summary)) {
  78. foreach ($summary as $users) {
  79. $z = 0;
  80. foreach ($users as $key => $val) {
  81. if ($z == 0) {
  82. echo '"'.$summary[$x][$key].'"';
  83. }
  84. else {
  85. echo ',"'.$summary[$x][$key].'"';
  86. }
  87. $z++;
  88. }
  89. echo "\n";
  90. $x++;
  91. }
  92. }
  93. exit;
  94. }
  95. //include the header
  96. $document['title'] = $text['title-message_summary'];
  97. require_once "resources/header.php";
  98. //css grid adjustment
  99. echo "<style>\n";
  100. echo " div.form_grid {\n";
  101. echo " grid-template-columns: repeat(auto-fill, minmax(350px, 1fr));\n";
  102. echo " }\n";
  103. echo "</style>\n";
  104. //show the content
  105. echo "<div class='action_bar' id='action_bar'>\n";
  106. echo " <div class='heading'><b>".$text['title-message_summary']."</b></div>\n";
  107. echo " <div class='actions'>\n";
  108. if (permission_exists('message_summary_all') && $_GET['show'] != 'all') {
  109. 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']);
  110. }
  111. 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']);
  112. 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']);
  113. 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();"]);
  114. echo " </div>\n";
  115. echo " <div style='clear: both;'></div>\n";
  116. echo "</div>\n";
  117. if (permission_exists('message_search')) {
  118. echo "<form name='frm' id='frm' method='get' autocomplete='off'>\n";
  119. echo "<div class='card' style='margin-bottom: 30px;'>\n";
  120. echo "<div class='form_grid'>\n";
  121. echo " <div class='form_set'>\n";
  122. echo " <div class='label'>\n";
  123. echo " ".$text['label-preset']."\n";
  124. echo " </div>\n";
  125. echo " <div class='field'>\n";
  126. 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";
  127. echo " <option value=''></option>\n";
  128. echo " <option value='1' ".($quick_select == 1 ? "selected='selected'" : null).">".$text['option-last_seven_days']."</option>\n";
  129. echo " <option value='2' ".($quick_select == 2 ? "selected='selected'" : null).">".$text['option-last_hour']."</option>\n";
  130. echo " <option value='3' ".($quick_select == 3 ? "selected='selected'" : null).">".$text['option-today']."</option>\n";
  131. echo " <option value='4' ".($quick_select == 4 ? "selected='selected'" : null).">".$text['option-yesterday']."</option>\n";
  132. echo " <option value='5' ".($quick_select == 5 ? "selected='selected'" : null).">".$text['option-this_week']."</option>\n";
  133. echo " <option value='6' ".($quick_select == 6 ? "selected='selected'" : null).">".$text['option-this_month']."</option>\n";
  134. echo " <option value='7' ".($quick_select == 7 ? "selected='selected'" : null).">".$text['option-this_year']."</option>\n";
  135. echo " </select>\n";
  136. echo " </div>\n";
  137. echo " </div>\n";
  138. echo " <div class='form_set'>\n";
  139. echo " <div class='label'>\n";
  140. echo " ".$text['label-start_date_time']."\n";
  141. echo " </div>\n";
  142. echo " <div class='field'>\n";
  143. 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";
  144. echo " </div>\n";
  145. echo " </div>\n";
  146. echo " <div class='form_set'>\n";
  147. echo " <div class='label'>\n";
  148. echo " ".$text['label-end_date_time']."\n";
  149. echo " </div>\n";
  150. echo " <div class='field'>\n";
  151. 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";
  152. echo " </div>\n";
  153. echo " </div>\n";
  154. echo "</div>\n";
  155. echo "</div>\n";
  156. if (!empty($_GET['show']) && $_GET['show'] == 'all' && permission_exists('message_summary_all')) {
  157. echo "<input type='hidden' name='show' value='all'>";
  158. }
  159. echo "</form>";
  160. }
  161. //show the results
  162. echo "<div class='card'>\n";
  163. echo "<table class='list'>\n";
  164. echo " <tr class='list-header'>\n";
  165. if (!empty($_GET['show']) && $_GET['show'] === "all" && permission_exists('message_summary_all')) {
  166. echo " <th>".$text['label-domain']."</th>\n";
  167. }
  168. echo " <th>".$text['label-message_destination']."</th>\n";
  169. echo " <th class='center'>".$text['label-message_read']."</th>\n";
  170. echo " <th class='center'>".$text['label-message_unread']."</th>\n";
  171. echo " <th class='center'>".$text['label-message_received']."</th>\n";
  172. echo " <th class='center'>".$text['label-message_sent']."</th>\n";
  173. echo " <th class='hide-sm-dn'>".$text['label-message_description']."</th>\n";
  174. echo " </tr>\n";
  175. if (!empty($summary) && is_array($summary)) {
  176. foreach ($summary as $key => $row) {
  177. echo "<tr class='list-row'>\n";
  178. if (!empty($_GET['show']) && $_GET['show'] === "all" && permission_exists('message_summary_all')) {
  179. echo " <td style=\"cursor: default\">".escape($row['domain_name'])."</td>\n";
  180. }
  181. echo " <td style=\"cursor: default\">".escape($row['destination'])."</td>\n";
  182. echo " <td class='center' style=\"cursor: default\">".escape($row['message_read'])."&nbsp;</td>\n";
  183. echo " <td class='center' style=\"cursor: default\">".escape($row['message_unread'])."&nbsp;</td>\n";
  184. echo " <td class='center' style=\"cursor: default\">".escape($row['message_received'])."&nbsp;</td>\n";
  185. echo " <td class='center' style=\"cursor: default\">".escape($row['message_sent'])."&nbsp;</td>\n";
  186. echo " <td class='description overflow hide-sm-dn' style=\"cursor: default\">".escape($row['destination_description'])."&nbsp;</td>\n";
  187. echo "</tr>\n";
  188. }
  189. }
  190. echo "</table>\n";
  191. echo "</div>\n";
  192. echo "<br />\n";
  193. //show the footer
  194. require_once "resources/footer.php";
  195. ?>