voicemail_msgs.php 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298
  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) 2008-2012
  17. the Initial Developer. All Rights Reserved.
  18. Contributor(s):
  19. Mark J Crane <[email protected]>
  20. */
  21. include "root.php";
  22. require "resources/require.php";
  23. require_once "resources/check_auth.php";
  24. if (permission_exists('voicemail_view')) {
  25. //access granted
  26. }
  27. else {
  28. echo "access denied";
  29. exit;
  30. }
  31. //add multi-lingual support
  32. $language = new text;
  33. $text = $language->get();
  34. //download the voicemail
  35. if ($_GET['a'] == "download") {
  36. //pdo voicemail database connection
  37. include "resources/pdo_vm.php";
  38. session_cache_limiter('public');
  39. $uuid = $_GET["uuid"];
  40. $sql = "select * from voicemail_msgs ";
  41. $sql .= "where domain = '".$_SESSION['domain_name']."' ";
  42. $sql .= "and uuid = '$uuid' ";
  43. $prep_statement = $db->prepare(check_sql($sql));
  44. $prep_statement->execute();
  45. $result = $prep_statement->fetchAll(PDO::FETCH_NAMED);
  46. foreach ($result as &$row) {
  47. $created_epoch = $row["created_epoch"];
  48. $read_epoch = $row["read_epoch"];
  49. $username = $row["username"];
  50. $uuid = $row["uuid"];
  51. $cid_name = $row["cid_name"];
  52. $cid_number = $row["cid_number"];
  53. $in_folder = $row["in_folder"];
  54. $file_path = $row["file_path"];
  55. $message_len = $row["message_len"];
  56. $flags = $row["flags"];
  57. $read_flags = $row["read_flags"];
  58. break; //limit to 1 row
  59. }
  60. unset ($prep_statement);
  61. if ($_GET['type'] = "vm") {
  62. if (file_exists($file_path)) {
  63. $fd = fopen($file_path, "rb");
  64. if ($_GET['t'] == "bin") {
  65. header("Content-Type: application/force-download");
  66. header("Content-Type: application/octet-stream");
  67. header("Content-Type: application/download");
  68. header("Content-Description: File Transfer");
  69. $file_ext = substr($file_path, -3);
  70. if ($file_ext == "wav") {
  71. header('Content-Disposition: attachment; filename="voicemail.wav"');
  72. }
  73. if ($file_ext == "mp3") {
  74. header('Content-Disposition: attachment; filename="voicemail.mp3"');
  75. }
  76. }
  77. else {
  78. $file_ext = substr($file_path, -3);
  79. if ($file_ext == "wav") {
  80. header("Content-Type: audio/x-wav");
  81. }
  82. if ($file_ext == "mp3") {
  83. header("Content-Type: audio/mp3");
  84. }
  85. }
  86. header("Cache-Control: no-cache, must-revalidate"); // HTTP/1.1
  87. header("Expires: Sat, 26 Jul 1997 05:00:00 GMT"); // date in the past
  88. header("Content-Length: " . filesize($file_path));
  89. fpassthru($fd);
  90. }
  91. return;
  92. }
  93. }
  94. //get the includes
  95. require "resources/require.php";
  96. require_once "resources/header.php";
  97. require_once "resources/paging.php";
  98. //get the http values and set them as variables
  99. if (isset($_GET["order_by"])) {
  100. $order_by = check_str($_GET["order_by"]);
  101. $order = check_str($_GET["order"]);
  102. }
  103. else {
  104. $order_by = '';
  105. $order = '';
  106. }
  107. //pdo voicemail database connection
  108. include "resources/pdo_vm.php";
  109. //show the content
  110. echo "<div align='center'>";
  111. echo "<table width='100%' border='0' cellpadding='0' cellspacing='2'>\n";
  112. echo "<tr class='border'>\n";
  113. echo " <td align=\"center\">\n";
  114. echo " <br>";
  115. echo "<table width='100%' border='0'>\n";
  116. echo "<tr>\n";
  117. echo "<td align='left' width='50%' nowrap><b>".$text['title']."</b></td>\n";
  118. echo "<td align='left' width='50%' align='right'>&nbsp;</td>\n";
  119. echo "</tr>\n";
  120. echo "<tr>\n";
  121. echo "<td colspan='2' align='left'>\n";
  122. echo "".$text['description']." \n";
  123. if (if_group("admin") || if_group("superadmin")) {
  124. echo "".$text['description-2']." \n";
  125. echo "".$text['description-3']." \n";
  126. echo " <br />\n";
  127. echo " <br />\n";
  128. }
  129. echo "</td>\n";
  130. echo "</tr>\n";
  131. echo "</table>\n";
  132. $tmp_msg_header = '';
  133. $tmp_msg_header .= "<tr>\n";
  134. $tmp_msg_header .= th_order_by('created_epoch', $text['label-created'], $order_by, $order);
  135. //$tmp_msg_header .= th_order_by('read_epoch', 'Read', $order_by, $order);
  136. //$tmp_msg_header .= th_order_by('username', 'Ext', $order_by, $order);
  137. //$tmp_msg_header .= th_order_by('domain', 'Domain', $order_by, $order);
  138. //$tmp_msg_header .= th_order_by('uuid', 'UUID', $order_by, $order);
  139. $tmp_msg_header .= th_order_by('cid_name', $text['label-caller-id-name'], $order_by, $order);
  140. $tmp_msg_header .= th_order_by('cid_number', $text['label-caller-id-number'], $order_by, $order);
  141. $tmp_msg_header .= th_order_by('in_folder', $text['label-folder'], $order_by, $order);
  142. //$tmp_msg_header .= "<th>Options</th>\n";
  143. //$tmp_msg_header .= th_order_by('file_path', 'File Path', $order_by, $order);
  144. $tmp_msg_header .= th_order_by('message_len', $text['label-length'], $order_by, $order);
  145. $tmp_msg_header .= "<th nowrap>".$text['label-size']."</th>\n";
  146. //$tmp_msg_header .= th_order_by('flags', 'Flags', $order_by, $order);
  147. //$tmp_msg_header .= th_order_by('read_flags', 'Read Flags', $order_by, $order);
  148. $tmp_msg_header .= "<td align='right' width='22'>\n";
  149. //$tmp_msg_header .= " <input type='button' class='btn' name='' alt='add' onclick=\"window.location='voicemail_msgs_edit.php'\" value='+'>\n";
  150. $tmp_msg_header .= "</td>\n";
  151. $tmp_msg_header .= "<tr>\n";
  152. echo "<div align='center'>\n";
  153. echo "<table width='100%' border='0' cellpadding='2' cellspacing='0'>\n";
  154. if (!isset($_SESSION['user']['extension'])) {
  155. echo $tmp_msg_header;
  156. }
  157. else {
  158. foreach ($_SESSION['user']['extension'] as $value) {
  159. if (strlen($value['user']) > 0) {
  160. echo "<tr><td colspan='5' align='left'>\n";
  161. echo " <br />\n";
  162. echo " <b>".$text['table-mailbox'].": ".$value['user']."</b>&nbsp;\n";
  163. echo " \n";
  164. echo "</td>\n";
  165. echo "<td valign='bottom' align='right'>\n";
  166. echo " <input type='button' class='btn' name='' alt='greetings' onclick=\"window.location='".PROJECT_PATH."/app/voicemail_greetings/voicemail_greetings.php?id=".$value['user']."'\" value='".$text['button-greetings']."'>\n";
  167. echo " <input type='button' class='btn' name='' alt='settings' onclick=\"window.location='voicemail_msgs_password.php?id=".$value['extension_uuid']."'\" value='".$text['button-settings']."'>\n";
  168. echo "</td>\n";
  169. echo "</tr>\n";
  170. echo $tmp_msg_header;
  171. $sql = "select * from voicemail_msgs ";
  172. if (count($_SESSION['domains']) > 1) {
  173. $sql .= "where domain = '".$_SESSION['domain_name']."' ";
  174. $sql .= "and username = '".$value['user']."' ";
  175. }
  176. else {
  177. $sql .= "where username = '".$value['user']."' ";
  178. }
  179. if (isset($order_by)) {
  180. if (strlen($order_by) > 0) {
  181. $sql .= "order by $order_by $order ";
  182. }
  183. }
  184. $prep_statement = $db->prepare(check_sql($sql));
  185. $prep_statement->execute();
  186. $result = $prep_statement->fetchAll(PDO::FETCH_NAMED);
  187. $result_count = count($result);
  188. unset ($prep_statement, $sql);
  189. $c = 0;
  190. $row_style["0"] = "row_style0";
  191. $row_style["1"] = "row_style1";
  192. if ($result_count > 0) {
  193. $prevextension = '';
  194. foreach($result as $row) {
  195. $extension_uuid = '';
  196. foreach($_SESSION['user']['extension'] as $value) {
  197. if ($value['user'] == $row['username']) {
  198. $extension_uuid = $value['extension_uuid'];
  199. break;
  200. }
  201. }
  202. $tmp_filesize = filesize($row['file_path']);
  203. $tmp_filesize = byte_convert($tmp_filesize);
  204. $file_ext = substr($row['file_path'], -3);
  205. $tmp_message_len = $row['message_len'];
  206. if ($tmp_message_len < 60 ) {
  207. $tmp_message_len = $tmp_message_len. " sec";
  208. }
  209. else {
  210. $tmp_message_len = round(($tmp_message_len/60), 2). " min";
  211. }
  212. if ($row['read_epoch'] == 0) {
  213. $style = "style=\"font-weight: bold;\"";
  214. }
  215. else {
  216. $style = "";
  217. }
  218. echo "<tr >\n";
  219. echo " <td valign='top' class='".$row_style[$c]."' $style nowrap=\"nowrap\">";
  220. echo date("j M Y g:i a",$row['created_epoch']);
  221. echo "</td>\n";
  222. //echo " <td valign='top' class='".$row_style[$c]."'>".$row['read_epoch']."</td>\n";
  223. //echo " <td valign='top' class='".$row_style[$c]."'>".$row['username']."</td>\n";
  224. //echo " <td valign='top' class='".$row_style[$c]."'>".$row['domain']."</td>\n";
  225. //echo " <td valign='top' class='".$row_style[$c]."'>".$row['uuid']."</td>\n";
  226. echo " <td valign='top' class='".$row_style[$c]."' $style nowrap=\"nowrap\">".$row['cid_name']."</td>\n";
  227. echo " <td valign='top' class='".$row_style[$c]."' $style>".$row['cid_number']."</td>\n";
  228. echo " <td valign='top' class='".$row_style[$c]."' $style>".$row['in_folder']."</td>\n";
  229. echo " <td valign='top' class='".$row_style[$c]."' $style>\n";
  230. echo " <a href=\"javascript:void(0);\" onclick=\"window.open('voicemail_msgs_play.php?a=download&type=vm&uuid=".$row['uuid']."&id=".$row['username']."&ext=".$file_ext."&desc=".urlencode($row['cid_name']." ".$row['cid_number'])."', 'play',' width=420,height=40,menubar=no,status=no,toolbar=no')\">\n";
  231. echo " $tmp_message_len";
  232. echo " </a>";
  233. echo " </td>\n";
  234. //echo " <td valign='top' class='".$row_style[$c]."'>".$row[flags]."&nbsp;</td>\n";
  235. //echo " <td valign='top' class='".$row_style[$c]."'>".$row[read_flags]."</td>\n";
  236. echo " <td valign='top' class='".$row_style[$c]."' $style nowrap=\"nowrap\">";
  237. echo " <a href=\"voicemail_msgs.php?a=download&type=vm&t=bin&uuid=".$row['uuid']."\">\n";
  238. echo $tmp_filesize;
  239. echo " </a>";
  240. echo "</td>\n";
  241. echo " <td valign='top' align='center' nowrap>\n";
  242. //echo " <a href='voicemail_msgs_edit.php?id=".$row[voicemail_msg_id]."' alt='edit'>$v_link_label_edit</a>\n";
  243. echo " &nbsp;&nbsp;<a href='voicemail_msgs_delete.php?uuid=".$row['uuid']."&id=".$row['username']."' alt='delete message' title='delete message' onclick=\"return confirm('".$text['confirm-delete']."')\">$v_link_label_delete</a>\n";
  244. echo " </td>\n";
  245. echo "</tr>\n";
  246. $prevextension = $row['username'];
  247. unset($tmp_message_len, $tmp_filesize);
  248. if ($c==0) { $c=1; } else { $c=0; }
  249. } //end foreach
  250. unset($sql, $result, $row_count);
  251. } //end if results
  252. }
  253. }
  254. }
  255. echo "</table>";
  256. echo "</div>";
  257. echo "<br><br>";
  258. echo "<br><br>";
  259. echo "</td>";
  260. echo "</tr>";
  261. echo "</table>";
  262. echo "</div>";
  263. echo "<br><br>";
  264. //show the footer
  265. require "resources/require.php";
  266. require_once "resources/footer.php";
  267. ?>