Fork of FusionPBX but with LDAP kinda working
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

670 lines
29 KiB

2 years ago
  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 <markjcrane@fusionpbx.com>
  16. Portions created by the Initial Developer are Copyright (C) 2008-2019
  17. the Initial Developer. All Rights Reserved.
  18. Contributor(s):
  19. Mark J Crane <markjcrane@fusionpbx.com>
  20. */
  21. //includes
  22. include "root.php";
  23. require_once "resources/require.php";
  24. require_once "resources/check_auth.php";
  25. //check permissions
  26. if (!permission_exists('voicemail_greeting_view') || (!permission_exists('voicemail_view') && !extension_assigned($_REQUEST["id"]))) {
  27. echo "access denied";
  28. return;
  29. }
  30. //add multi-lingual support
  31. $language = new text;
  32. $text = $language->get();
  33. //get the http get values and set them as php variables
  34. $voicemail_id = $_REQUEST["id"];
  35. $order_by = $_GET["order_by"];
  36. $order = $_GET["order"];
  37. //set the back button url
  38. $_SESSION['back'][$_SERVER['PHP_SELF']] = ($_GET['back'] != '') ? urldecode($_GET['back']) : $_SESSION['back'][$_SERVER['PHP_SELF']];
  39. //define order by default
  40. if ($order_by == '') {
  41. $order_by = "greeting_name";
  42. $order = "asc";
  43. }
  44. //used (above) to search the array to determine if an extension is assigned to the user
  45. function extension_assigned($number) {
  46. foreach ($_SESSION['user']['extension'] as $row) {
  47. if ((is_numeric($row['number_alias']) && $row['number_alias'] == $number) || $row['user'] == $number) {
  48. return true;
  49. }
  50. }
  51. return false;
  52. }
  53. //get currently selected greeting
  54. $sql = "select greeting_id from v_voicemails ";
  55. $sql .= "where domain_uuid = :domain_uuid ";
  56. $sql .= "and voicemail_id = :voicemail_id ";
  57. $parameters['domain_uuid'] = $domain_uuid;
  58. $parameters['voicemail_id'] = $voicemail_id;
  59. $database = new database;
  60. $selected_greeting_id = $database->select($sql, $parameters, 'column');
  61. unset($sql, $parameters);
  62. //define greeting directory
  63. $v_greeting_dir = $_SESSION['switch']['storage']['dir'].'/voicemail/default/'.$_SESSION['domains'][$domain_uuid]['domain_name'].'/'.$voicemail_id;
  64. //download the greeting
  65. if ($_GET['a'] == "download" && (permission_exists('voicemail_greeting_play') || permission_exists('voicemail_greeting_download'))) {
  66. if ($_GET['type'] == "rec") {
  67. $voicemail_greeting_uuid = $_GET['uuid'];
  68. //get voicemail greeting details from db
  69. $sql = "select greeting_filename, greeting_base64, greeting_id ";
  70. $sql .= "from v_voicemail_greetings ";
  71. $sql .= "where domain_uuid = :domain_uuid ";
  72. $sql .= "and voicemail_greeting_uuid = :voicemail_greeting_uuid ";
  73. $parameters['domain_uuid'] = $domain_uuid;
  74. $parameters['voicemail_greeting_uuid'] = $voicemail_greeting_uuid;
  75. $database = new database;
  76. $row = $database->select($sql, $parameters, 'row');
  77. if (is_array($row) && @sizeof($row) != 0) {
  78. $greeting_filename = $row['greeting_filename'];
  79. $greeting_id = $row['greeting_id'];
  80. if ($_SESSION['voicemail']['storage_type']['text'] == 'base64' && $row['greeting_base64'] != '') {
  81. $greeting_decoded = base64_decode($row['greeting_base64']);
  82. file_put_contents($v_greeting_dir.'/'.$greeting_filename, $greeting_decoded);
  83. }
  84. }
  85. unset($sql, $row, $greeting_decoded);
  86. if (file_exists($v_greeting_dir.'/'.$greeting_filename)) {
  87. //content-range
  88. if (isset($_SERVER['HTTP_RANGE']) && $_GET['t'] != "bin") {
  89. range_download($v_greeting_dir.'/'.$greeting_filename);
  90. }
  91. $fd = fopen($v_greeting_dir.'/'.$greeting_filename, "rb");
  92. if ($_GET['t'] == "bin") {
  93. header("Content-Type: application/force-download");
  94. header("Content-Type: application/octet-stream");
  95. header("Content-Type: application/download");
  96. header("Content-Description: File Transfer");
  97. }
  98. else {
  99. $file_ext = pathinfo($greeting_filename, PATHINFO_EXTENSION);
  100. switch ($file_ext) {
  101. case "wav" : header("Content-Type: audio/x-wav"); break;
  102. case "mp3" : header("Content-Type: audio/mpeg"); break;
  103. case "ogg" : header("Content-Type: audio/ogg"); break;
  104. }
  105. }
  106. header('Content-Disposition: attachment; filename="'.$greeting_filename.'"');
  107. header("Cache-Control: no-cache, must-revalidate"); // HTTP/1.1
  108. header("Expires: Sat, 26 Jul 1997 05:00:00 GMT"); // Date in the past
  109. if ($_GET['t'] == "bin") {
  110. header("Content-Length: ".filesize($v_greeting_dir.'/'.$greeting_filename));
  111. }
  112. ob_clean();
  113. fpassthru($fd);
  114. }
  115. //if base64, remove temp greeting file (if not currently selected greeting)
  116. if ($_SESSION['voicemail']['storage_type']['text'] == 'base64' && $row['greeting_base64'] != '') {
  117. if ($greeting_id != $selected_greeting_id) {
  118. @unlink($v_greeting_dir.'/'.$greeting_filename);
  119. }
  120. }
  121. }
  122. exit;
  123. }
  124. //upload the greeting
  125. if (
  126. $_POST['a'] == "upload"
  127. && permission_exists('voicemail_greeting_upload')
  128. && $_POST['type'] == 'rec'
  129. && is_uploaded_file($_FILES['file']['tmp_name'])
  130. ) {
  131. //validate the token
  132. $token = new token;
  133. if (!$token->validate($_SERVER['PHP_SELF'])) {
  134. message::add($text['message-invalid_token'],'negative');
  135. header('Location: voicemail_greetings.php?id='.urlencode($voicemail_id));
  136. exit;
  137. }
  138. //get the file extension
  139. $file_ext = substr($_FILES['file']['name'], -4);
  140. //check file extension
  141. if ($file_ext == '.wav' || $file_ext == '.mp3') {
  142. //find the next available
  143. for ($i = 1; $i < 10; $i++) {
  144. //set the file name
  145. $file_name = 'greeting_'.$i.$file_ext;
  146. //check the database
  147. if (is_uuid($domain_uuid) && is_numeric($voicemail_id) ) {
  148. $sql = "select count(*) from v_voicemail_greetings ";
  149. $sql .= "where domain_uuid = :domain_uuid ";
  150. $sql .= "and voicemail_id = :voicemail_id ";
  151. $sql .= "and greeting_filename = :greeting_filename ";
  152. $parameters['domain_uuid'] = $domain_uuid;
  153. $parameters['voicemail_id'] = $voicemail_id;
  154. $parameters['greeting_filename'] = $file_name;
  155. $database = new database;
  156. $num_rows = $database->select($sql, $parameters, 'column');
  157. unset($sql, $parameters);
  158. if ($num_rows == 0 && !file_exists($v_greeting_dir.'/'.$file_name)) {
  159. //move the uploaded greeting
  160. mkdir($v_greeting_dir, 0770, false);
  161. if ($file_ext == '.wav' || $file_ext == '.mp3') {
  162. move_uploaded_file($_FILES['file']['tmp_name'], $v_greeting_dir.'/'.$file_name);
  163. }
  164. //set newly uploaded greeting as active greeting for voicemail box
  165. $sql = "update v_voicemails ";
  166. $sql .= "set greeting_id = :greeting_id ";
  167. $sql .= "where domain_uuid = :domain_uuid ";
  168. $sql .= "and voicemail_id = :voicemail_id ";
  169. $parameters['greeting_id'] = $i;
  170. $parameters['domain_uuid'] = $domain_uuid;
  171. $parameters['voicemail_id'] = $voicemail_id;
  172. $database = new database;
  173. $database->execute($sql, $parameters);
  174. unset($sql, $parameters);
  175. //set message
  176. message::add($text['message-uploaded'].": ".$_FILES['file']['name']);
  177. //found available id, exit;
  178. break;
  179. }
  180. else {
  181. continue;
  182. }
  183. unset($num_rows);
  184. }
  185. }
  186. }
  187. //set the file name to be inserted as the greeting description
  188. $greeting_description = base64_encode($_FILES['file']['name']);
  189. header("Location: voicemail_greetings.php?id=".urlencode($voicemail_id)."&order_by=".urlencode($order_by)."&order=".urlencode($order)."&gd=".$greeting_description);
  190. exit;
  191. }
  192. //check the permission
  193. if (permission_exists('voicemail_greeting_view')) {
  194. //access granted
  195. }
  196. else {
  197. echo "access denied";
  198. exit;
  199. }
  200. //set the greeting
  201. if ($_REQUEST['action'] == "set") {
  202. //save the greeting_id to a variable
  203. $greeting_id = $_REQUEST['greeting_id'];
  204. //set the greeting_id
  205. $sql = "update v_voicemails ";
  206. $sql .= "set greeting_id = :greeting_id ";
  207. $sql .= "where domain_uuid = :domain_uuid ";
  208. $sql .= "and voicemail_id = :voicemail_id ";
  209. $parameters['greeting_id'] = $greeting_id;
  210. $parameters['domain_uuid'] = $domain_uuid;
  211. $parameters['voicemail_id'] = $voicemail_id;
  212. $database = new database;
  213. $database->execute($sql, $parameters);
  214. unset($sql, $parameters);
  215. //set message
  216. message::add($text['message-greeting_selected']);
  217. //redirect
  218. header("Location: voicemail_greetings.php?id=".$voicemail_id."&order_by=".$order_by."&order=".$order);
  219. exit;
  220. }
  221. //get existing greetings
  222. $sql = "select voicemail_greeting_uuid, greeting_filename, greeting_base64 ";
  223. $sql .= "from v_voicemail_greetings ";
  224. $sql .= "where domain_uuid = :domain_uuid ";
  225. $sql .= "and voicemail_id = :voicemail_id ";
  226. $parameters['domain_uuid'] = $domain_uuid;
  227. $parameters['voicemail_id'] = $voicemail_id;
  228. $database = new database;
  229. $result = $database->select($sql, $parameters, 'all');
  230. unset($sql, $parameters);
  231. if (is_array($result) && @sizeof($result) != 0) {
  232. foreach ($result as $x => &$row) {
  233. $array_greetings[$row['voicemail_greeting_uuid']] = $row['greeting_filename'];
  234. $array_base64_exists[$row['voicemail_greeting_uuid']] = ($row['greeting_base64'] != '') ? true : false;
  235. //if not base64, convert back to local files and remove base64 from db
  236. if ($_SESSION['voicemail']['storage_type']['text'] != 'base64' && $row['greeting_base64'] != '') {
  237. if (file_exists($v_greeting_dir.'/'.$row['greeting_filename'])) {
  238. @unlink($v_greeting_dir.'/'.$row['greeting_filename']);
  239. }
  240. $greeting_decoded = base64_decode($row['greeting_base64']);
  241. file_put_contents($v_greeting_dir.'/'.$row['greeting_filename'], $greeting_decoded);
  242. //build array
  243. $array['voicemail_greetings'][$x]['voicemail_greeting_uuid'] = $row['voicemail_greeting_uuid'];
  244. $array['voicemail_greetings'][$x]['greeting_base64'] = null;
  245. }
  246. }
  247. if (is_array($array) && @sizeof($array) != 0) {
  248. //grant temporary permissions
  249. $p = new permissions;
  250. $p->add('voicemail_greeting_edit', 'temp');
  251. //execute update
  252. $database = new database;
  253. $database->app_name = 'voicemail_greetings';
  254. $database->app_uuid = 'e4b4fbee-9e4d-8e46-3810-91ba663db0c2';
  255. $database->save($array);
  256. unset($array);
  257. //revoke temporary permissions
  258. $p->delete('voicemail_greeting_edit', 'temp');
  259. }
  260. }
  261. unset($result, $row);
  262. //add greetings to the database
  263. if (is_dir($v_greeting_dir.'/')) {
  264. if ($dh = opendir($v_greeting_dir.'/')) {
  265. $x = 0;
  266. //prepare for temporary permissions
  267. $p = new permissions;
  268. while (($file = readdir($dh)) !== false) {
  269. if (filetype($v_greeting_dir."/".$file) == "file" && substr($file, 0, 8) == "greeting" && substr($file, 10, 4) != ".tmp") {
  270. $greeting_number = preg_replace('{\D}', '', $file);
  271. if (!is_array($array_greetings) || !in_array($file, $array_greetings)) {
  272. //file not found, add to database
  273. $greeting_name = $text['label-greeting'].' '.$greeting_number;
  274. $greeting_description = base64_decode($_GET['gd']);
  275. $voicemail_greeting_uuid = uuid();
  276. //build insert array
  277. $array['voicemail_greetings'][$x]['voicemail_greeting_uuid'] = $voicemail_greeting_uuid;
  278. $array['voicemail_greetings'][$x]['domain_uuid'] = $domain_uuid;
  279. $array['voicemail_greetings'][$x]['voicemail_id'] = $voicemail_id;
  280. $array['voicemail_greetings'][$x]['greeting_name'] = $greeting_name;
  281. $array['voicemail_greetings'][$x]['greeting_filename'] = $file;
  282. $array['voicemail_greetings'][$x]['greeting_description'] = $greeting_description;
  283. if ($_SESSION['voicemail']['storage_type']['text'] == 'base64') {
  284. $array['voicemail_greetings'][$x]['greeting_base64'] = base64_encode(file_get_contents($v_greeting_dir.'/'.$file));
  285. }
  286. $array['voicemail_greetings'][$x]['greeting_id'] = $greeting_number;
  287. $x++;
  288. //grant temporary permissions
  289. $p->add('voicemail_greeting_add', 'temp');
  290. }
  291. else {
  292. //file found, check if base64 present
  293. if ($_SESSION['voicemail']['storage_type']['text'] == 'base64') {
  294. $found_greeting_uuid = array_search($file, $array_greetings);
  295. if (!$array_base64_exists[$found_greeting_uuid]) {
  296. //build update array
  297. $array['voicemail_greetings'][$x]['voicemail_greeting_uuid'] = $found_greeting_uuid;
  298. $array['voicemail_greetings'][$x]['greeting_base64'] = base64_encode(file_get_contents($v_greeting_dir.'/'.$file));
  299. $x++;
  300. //grant temporary permissions
  301. $p->add('voicemail_greeting_edit', 'temp');
  302. }
  303. }
  304. }
  305. //if base64, remove local file (unless currently selected greeting)
  306. if ($_SESSION['voicemail']['storage_type']['text'] == 'base64' && file_exists($v_greeting_dir.'/'.$file)) {
  307. if ($greeting_number != $selected_greeting_id) {
  308. @unlink($v_greeting_dir.'/'.$file);
  309. }
  310. }
  311. }
  312. }
  313. if (is_array($array) && @sizeof($array) != 0) {
  314. //execute inserts/updates
  315. $database = new database;
  316. $database->app_name = 'voicemail_greetings';
  317. $database->app_uuid = 'e4b4fbee-9e4d-8e46-3810-91ba663db0c2';
  318. $database->save($array);
  319. unset($array);
  320. //revoke temporary permissions
  321. $p->delete('voicemail_greeting_add', 'temp');
  322. $p->delete('voicemail_greeting_edit', 'temp');
  323. }
  324. closedir($dh);
  325. }
  326. }
  327. //get the http post data
  328. if (is_array($_POST['voicemail_greetings'])) {
  329. $action = $_POST['action'];
  330. $voicemail_id = $_POST['voicemail_id'];
  331. $voicemail_greetings = $_POST['voicemail_greetings'];
  332. }
  333. //process the http post data by action
  334. if ($action != '' && is_array($voicemail_greetings) && @sizeof($voicemail_greetings) != 0) {
  335. switch ($action) {
  336. case 'delete':
  337. if (permission_exists('voicemail_greeting_delete')) {
  338. $obj = new voicemail_greetings;
  339. $obj->voicemail_id = $voicemail_id;
  340. $obj->delete($voicemail_greetings);
  341. }
  342. break;
  343. }
  344. header('Location: voicemail_greetings.php?id='.urlencode($voicemail_id).'&back='.urlencode(PROJECT_PATH.'/app/voicemails/voicemails.php'));
  345. exit;
  346. }
  347. //get the greetings list
  348. if ($_SESSION['voicemail']['storage_type']['text'] == 'base64') {
  349. switch ($db_type) {
  350. case 'pgsql': $sql_file_size = ", length(decode(greeting_base64,'base64')) as greeting_size "; break;
  351. case 'mysql': $sql_file_size = ", length(from_base64(greeting_base64)) as greeting_size "; break;
  352. }
  353. }
  354. $sql = "select * ".$sql_file_size." from v_voicemail_greetings ";
  355. $sql .= "where domain_uuid = :domain_uuid ";
  356. $sql .= "and voicemail_id = :voicemail_id ";
  357. $sql .= order_by($order_by, $order);
  358. $parameters['domain_uuid'] = $domain_uuid;
  359. $parameters['voicemail_id'] = $voicemail_id;
  360. $database = new database;
  361. $greetings = $database->select($sql, $parameters, 'all');
  362. $num_rows = is_array($greetings) ? @sizeof($greetings) : 0;
  363. unset($sql, $parameters);
  364. //create token
  365. $object = new token;
  366. $token = $object->create($_SERVER['PHP_SELF']);
  367. //include the header
  368. $document['title'] = $text['title'];
  369. require_once "resources/header.php";
  370. //file type check script
  371. echo "<script language='JavaScript' type='text/javascript'>\n";
  372. echo " function check_file_type(file_input) {\n";
  373. echo " file_ext = file_input.value.substr((~-file_input.value.lastIndexOf('.') >>> 0) + 2);\n";
  374. echo " if (file_ext != 'mp3' && file_ext != 'wav' && file_ext != 'ogg' && file_ext != '') {\n";
  375. echo " display_message(\"".$text['message-unsupported_file_type']."\", 'negative', '2750');\n";
  376. echo " document.getElementById('form_upload').reset();\n";
  377. echo " }\n";
  378. echo " }\n";
  379. echo "</script>";
  380. //show the content
  381. echo "<div class='action_bar' id='action_bar'>\n";
  382. echo " <div class='heading'><b>".$text['title']." (".$num_rows.")</b></div>\n";
  383. echo " <div class='actions'>\n";
  384. echo button::create(['type'=>'button','label'=>$text['button-back'],'icon'=>$_SESSION['theme']['button_icon_back'],'id'=>'btn_back','style'=>'margin-right: 15px;','link'=>$_SESSION['back'][$_SERVER['PHP_SELF']]]);
  385. if (permission_exists('voicemail_greeting_upload')) {
  386. echo "<form id='form_upload' class='inline' method='post' enctype='multipart/form-data'>\n";
  387. echo "<input name='a' type='hidden' value='upload'>\n";
  388. echo "<input type='hidden' name='id' value='".escape($voicemail_id)."'>\n";
  389. echo "<input type='hidden' name='type' value='rec'>\n";
  390. echo "<input type='hidden' name='".$token['name']."' value='".$token['hash']."'>\n";
  391. echo button::create(['type'=>'button','label'=>$text['button-add'],'icon'=>$_SESSION['theme']['button_icon_add'],'id'=>'btn_add','onclick'=>"$(this).fadeOut(250, function(){ $('span#form_upload').fadeIn(250); document.getElementById('ulfile').click(); });"]);
  392. echo "<span id='form_upload' style='display: none;'>";
  393. echo button::create(['label'=>$text['button-cancel'],'icon'=>$_SESSION['theme']['button_icon_cancel'],'type'=>'button','id'=>'btn_upload_cancel','onclick'=>"$('span#form_upload').fadeOut(250, function(){ document.getElementById('form_upload').reset(); $('#btn_add').fadeIn(250) });"]);
  394. echo "<input type='text' class='txt' style='width: 100px; cursor: pointer;' id='filename' placeholder='Select...' onclick=\"document.getElementById('ulfile').click(); this.blur();\" onfocus='this.blur();'>";
  395. echo "<input type='file' id='ulfile' name='file' style='display: none;' accept='.wav,.mp3,.ogg' onchange=\"document.getElementById('filename').value = this.files.item(0).name; check_file_type(this);\">";
  396. echo button::create(['type'=>'submit','label'=>$text['button-upload'],'icon'=>$_SESSION['theme']['button_icon_upload']]);
  397. echo "</span>\n";
  398. echo "</form>";
  399. }
  400. if (permission_exists('voicemail_greeting_delete') && $greetings) {
  401. echo button::create(['type'=>'button','label'=>$text['button-delete'],'icon'=>$_SESSION['theme']['button_icon_delete'],'name'=>'btn_delete','onclick'=>"modal_open('modal-delete','btn_delete');"]);
  402. }
  403. echo " </div>\n";
  404. echo " <div style='clear: both;'></div>\n";
  405. echo "</div>\n";
  406. if (permission_exists('voicemail_greeting_delete') && $greetings) {
  407. echo modal::create(['id'=>'modal-delete','type'=>'delete','actions'=>button::create(['type'=>'button','label'=>$text['button-continue'],'icon'=>'check','id'=>'btn_delete','style'=>'float: right; margin-left: 15px;','collapse'=>'never','onclick'=>"modal_close(); list_action_set('delete'); list_form_submit('form_list');"])]);
  408. }
  409. echo $text['description']." <strong>".escape($voicemail_id)."</strong>\n";
  410. echo "<br /><br />\n";
  411. echo "<form id='form_list' method='post'>\n";
  412. echo "<input type='hidden' id='action' name='action' value=''>\n";
  413. echo "<input type='hidden' id='voicemail_id' name='voicemail_id' value='".escape($voicemail_id)."'>\n";
  414. echo "<table class='list'>\n";
  415. echo "<tr class='list-header'>\n";
  416. $col_count = 0;
  417. if (permission_exists('voicemail_greeting_delete')) {
  418. echo " <th class='checkbox'>\n";
  419. echo " <input type='checkbox' id='checkbox_all' name='checkbox_all' onclick='list_all_toggle();' ".($greetings ?: "style='visibility: hidden;'").">\n";
  420. echo " </th>\n";
  421. $col_count++;
  422. }
  423. echo "<th class='shrink center'>".$text['label-selected']."</th>\n";
  424. $col_count++;
  425. echo th_order_by('greeting_id', $text['label-number'], $order_by, $order, null, "class='center shrink'", "id=".urlencode($voicemail_id));
  426. $col_count++;
  427. echo th_order_by('greeting_name', $text['label-name'], $order_by, $order, null, null, "id=".urlencode($voicemail_id));
  428. $col_count++;
  429. if ($_SESSION['voicemail']['storage_type']['text'] != 'base64') {
  430. echo th_order_by('greeting_filename', $text['label-filename'], $order_by, $order, null, "class='hide-sm-dn'", "id=".urlencode($voicemail_id));
  431. $col_count++;
  432. }
  433. if (permission_exists('voicemail_greeting_play') || permission_exists('voicemail_greeting_download')) {
  434. echo "<th class='center'>".$text['label-tools']."</th>\n";
  435. $col_count++;
  436. }
  437. echo "<th class='center no-wrap hide-xs'>".$text['label-size']."</th>\n";
  438. $col_count++;
  439. if ($_SESSION['voicemail']['storage_type']['text'] != 'base64') {
  440. echo "<th class='center no-wrap hide-xs'>".$text['label-uploaded']."</th>\n";
  441. $col_count++;
  442. }
  443. echo th_order_by('greeting_description', $text['label-description'], $order_by, $order, null, "class='hide-sm-dn pct-25'", "id=".urlencode($voicemail_id));
  444. if (permission_exists('voicemail_greeting_edit') && $_SESSION['theme']['list_row_edit_button']['boolean'] == 'true') {
  445. echo " <td class='action-button'>&nbsp;</td>\n";
  446. }
  447. echo "</tr>\n";
  448. if (is_array($greetings) && @sizeof($greetings) != 0) {
  449. $x = 0;
  450. foreach ($greetings as $row) {
  451. //playback progress bar
  452. if (permission_exists('voicemail_greeting_play')) {
  453. echo "<tr class='list-row' id='recording_progress_bar_".escape($row['voicemail_greeting_uuid'])."' style='display: none;'><td class='playback_progress_bar_background' style='padding: 0; border: none;' colspan='".$col_count."'><span class='playback_progress_bar' id='recording_progress_".escape($row['voicemail_greeting_uuid'])."'></span></td><td class='description hide-sm-dn' style='border-bottom: none !important;'></td></tr>\n";
  454. echo "<tr class='list-row' style='display: none;'><td></td></tr>\n"; // dummy row to maintain alternating background color
  455. }
  456. if (permission_exists('voicemail_greeting_edit')) {
  457. $list_row_url = "voicemail_greeting_edit.php?id=".urlencode($row['voicemail_greeting_uuid'])."&voicemail_id=".urlencode($voicemail_id);
  458. }
  459. echo "<tr class='list-row' href='".$list_row_url."'>\n";
  460. if (permission_exists('voicemail_greeting_delete')) {
  461. echo " <td class='checkbox'>\n";
  462. echo " <input type='checkbox' name='voicemail_greetings[$x][checked]' id='checkbox_".$x."' value='true' onclick=\"if (!this.checked) { document.getElementById('checkbox_all').checked = false; }\">\n";
  463. echo " <input type='hidden' name='voicemail_greetings[$x][uuid]' value='".escape($row['voicemail_greeting_uuid'])."' />\n";
  464. echo " </td>\n";
  465. }
  466. echo " <td class='center no-link'>";
  467. $selected = ($row['greeting_id'] == $selected_greeting_id) ? true : false;
  468. echo "<input type='radio' onclick=\"window.location='".PROJECT_PATH."/app/voicemail_greetings/voicemail_greetings.php?id=".escape($voicemail_id)."&greeting_id=".escape($row['greeting_id'])."&action=set&order_by=".$order_by."&order=".$order."';\" name='greeting_id' value='".escape($row['greeting_id'])."' ".(($selected) ? "checked='checked'" : null)." style='display: block; width: 20px; height: auto; margin: auto calc(50% - 10px);'>\n";
  469. echo " </td>\n";
  470. echo " <td class='center'>".escape($row['greeting_id'])."</td>\n";
  471. echo " <td class='no-wrap'>";
  472. if (permission_exists('voicemail_greeting_edit')) {
  473. echo "<a href='".$list_row_url."' title=\"".$text['button-edit']."\">".escape($row['greeting_name'])."</a>";
  474. }
  475. else {
  476. echo escape($row['greeting_name']);
  477. }
  478. echo " </td>\n";
  479. if ($_SESSION['voicemail']['storage_type']['text'] != 'base64') {
  480. echo " <td class='hide-sm-dn'>".escape($row['greeting_filename'])."</td>\n";
  481. }
  482. if (permission_exists('voicemail_greeting_play') || permission_exists('voicemail_greeting_download')) {
  483. echo " <td class='middle button center no-link no-wrap'>";
  484. if (permission_exists('voicemail_greeting_play')) {
  485. $greeting_file_path = $row['greeting_filename'];
  486. $greeting_file_name = strtolower(pathinfo($greeting_file_path, PATHINFO_BASENAME));
  487. $greeting_file_ext = pathinfo($greeting_file_name, PATHINFO_EXTENSION);
  488. switch ($greeting_file_ext) {
  489. case "wav" : $greeting_type = "audio/wav"; break;
  490. case "mp3" : $greeting_type = "audio/mpeg"; break;
  491. case "ogg" : $greeting_type = "audio/ogg"; break;
  492. }
  493. echo "<audio id='recording_audio_".escape($row['voicemail_greeting_uuid'])."' style='display: none;' preload='none' ontimeupdate=\"update_progress('".escape($row['voicemail_greeting_uuid'])."')\" onended=\"recording_reset('".escape($row['voicemail_greeting_uuid'])."');\" src=\"voicemail_greetings.php?id=".escape($voicemail_id)."&a=download&type=rec&uuid=".escape($row['voicemail_greeting_uuid'])."\" type='".$greeting_type."'></audio>";
  494. echo button::create(['type'=>'button','title'=>$text['label-play'].' / '.$text['label-pause'],'icon'=>$_SESSION['theme']['button_icon_play'],'id'=>'recording_button_'.escape($row['voicemail_greeting_uuid']),'onclick'=>"recording_play('".escape($row['voicemail_greeting_uuid'])."')"]);
  495. }
  496. if (permission_exists('voicemail_greeting_download')) {
  497. echo button::create(['type'=>'button','title'=>$text['label-download'],'icon'=>$_SESSION['theme']['button_icon_download'],'link'=>"voicemail_greetings.php?a=download&type=rec&t=bin&id=".urlencode($voicemail_id)."&uuid=".escape($row['voicemail_greeting_uuid'])]);
  498. }
  499. echo " </td>\n";
  500. }
  501. if ($_SESSION['voicemail']['storage_type']['text'] == 'base64') {
  502. $file_size = byte_convert($row['greeting_size']);
  503. echo " <td class='center no-wrap hide-xs'>".$file_size."</td>\n";
  504. }
  505. else {
  506. $file_size = byte_convert(filesize($v_greeting_dir.'/'.$row['greeting_filename']));
  507. $file_date = date("M d, Y H:i:s", filemtime($v_greeting_dir.'/'.$row['greeting_filename']));
  508. echo " <td class='center no-wrap hide-xs'>".$file_size."</td>\n";
  509. echo " <td class='center no-wrap hide-xs'>".$file_date."</td>\n";
  510. }
  511. echo " <td class='description overflow hide-sm-dn'>".escape($row['greeting_description'])."&nbsp;</td>\n";
  512. if (permission_exists('voicemail_greeting_edit') && $_SESSION['theme']['list_row_edit_button']['boolean'] == 'true') {
  513. echo " <td class='action-button'>";
  514. echo button::create(['type'=>'button','title'=>$text['button-edit'],'icon'=>$_SESSION['theme']['button_icon_edit'],'link'=>$list_row_url]);
  515. echo " </td>\n";
  516. }
  517. echo "</tr>\n";
  518. $x++;
  519. }
  520. unset($greetings);
  521. }
  522. echo "</table>\n";
  523. echo "<br />\n";
  524. echo "<input type='hidden' name='".$token['name']."' value='".$token['hash']."'>\n";
  525. echo "</form>\n";
  526. //include the footer
  527. require_once "resources/footer.php";
  528. //define the download function (helps safari play audio sources)
  529. function range_download($file) {
  530. $fp = @fopen($file, 'rb');
  531. $size = filesize($file); // File size
  532. $length = $size; // Content length
  533. $start = 0; // Start byte
  534. $end = $size - 1; // End byte
  535. // Now that we've gotten so far without errors we send the accept range header
  536. /* At the moment we only support single ranges.
  537. * Multiple ranges requires some more work to ensure it works correctly
  538. * and comply with the spesifications: http://www.w3.org/Protocols/rfc2616/rfc2616-sec19.html#sec19.2
  539. *
  540. * Multirange support annouces itself with:
  541. * header('Accept-Ranges: bytes');
  542. *
  543. * Multirange content must be sent with multipart/byteranges mediatype,
  544. * (mediatype = mimetype)
  545. * as well as a boundry header to indicate the various chunks of data.
  546. */
  547. header("Accept-Ranges: 0-$length");
  548. // header('Accept-Ranges: bytes');
  549. // multipart/byteranges
  550. // http://www.w3.org/Protocols/rfc2616/rfc2616-sec19.html#sec19.2
  551. if (isset($_SERVER['HTTP_RANGE'])) {
  552. $c_start = $start;
  553. $c_end = $end;
  554. // Extract the range string
  555. list(, $range) = explode('=', $_SERVER['HTTP_RANGE'], 2);
  556. // Make sure the client hasn't sent us a multibyte range
  557. if (strpos($range, ',') !== false) {
  558. // (?) Shoud this be issued here, or should the first
  559. // range be used? Or should the header be ignored and
  560. // we output the whole content?
  561. header('HTTP/1.1 416 Requested Range Not Satisfiable');
  562. header("Content-Range: bytes $start-$end/$size");
  563. // (?) Echo some info to the client?
  564. exit;
  565. }
  566. // If the range starts with an '-' we start from the beginning
  567. // If not, we forward the file pointer
  568. // And make sure to get the end byte if spesified
  569. if ($range0 == '-') {
  570. // The n-number of the last bytes is requested
  571. $c_start = $size - substr($range, 1);
  572. }
  573. else {
  574. $range = explode('-', $range);
  575. $c_start = $range[0];
  576. $c_end = (isset($range[1]) && is_numeric($range[1])) ? $range[1] : $size;
  577. }
  578. /* Check the range and make sure it's treated according to the specs.
  579. * http://www.w3.org/Protocols/rfc2616/rfc2616-sec14.html
  580. */
  581. // End bytes can not be larger than $end.
  582. $c_end = ($c_end > $end) ? $end : $c_end;
  583. // Validate the requested range and return an error if it's not correct.
  584. if ($c_start > $c_end || $c_start > $size - 1 || $c_end >= $size) {
  585. header('HTTP/1.1 416 Requested Range Not Satisfiable');
  586. header("Content-Range: bytes $start-$end/$size");
  587. // (?) Echo some info to the client?
  588. exit;
  589. }
  590. $start = $c_start;
  591. $end = $c_end;
  592. $length = $end - $start + 1; // Calculate new content length
  593. fseek($fp, $start);
  594. header('HTTP/1.1 206 Partial Content');
  595. }
  596. // Notify the client the byte range we'll be outputting
  597. header("Content-Range: bytes $start-$end/$size");
  598. header("Content-Length: $length");
  599. // Start buffered download
  600. $buffer = 1024 * 8;
  601. while(!feof($fp) && ($p = ftell($fp)) <= $end) {
  602. if ($p + $buffer > $end) {
  603. // In case we're only outputtin a chunk, make sure we don't
  604. // read past the length
  605. $buffer = $end - $p + 1;
  606. }
  607. set_time_limit(0); // Reset time limit for big files
  608. echo fread($fp, $buffer);
  609. flush(); // Free up memory. Otherwise large files will trigger PHP's memory limit.
  610. }
  611. fclose($fp);
  612. }
  613. ?>