ringbacks.php 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159
  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) 2016
  17. the Initial Developer. All Rights Reserved.
  18. Contributor(s):
  19. Mark J Crane <[email protected]>
  20. Matthew Vale <[email protected]>
  21. */
  22. if (!class_exists('ringbacks')) {
  23. class ringbacks {
  24. //define variables
  25. public $db;
  26. private $ringbacks;
  27. private $music_list;
  28. private $recordings_list;
  29. private $default_ringback_label;
  30. //class constructor
  31. public function __construct() {
  32. //connect to the database if not connected
  33. if (!$this->db) {
  34. require_once "resources/classes/database.php";
  35. $database = new database;
  36. $database->connect();
  37. $this->db = $database->db;
  38. }
  39. //add multi-lingual support
  40. $language = new text;
  41. $text = $language->get();
  42. //get the ringback types
  43. $sql = "select * from v_vars ";
  44. $sql .= "where var_cat = 'Ringtones' ";
  45. $sql .= "and var_name LIKE '%-ring' ";
  46. $sql .= "order by var_name asc ";
  47. $prep_statement = $this->db->prepare(check_sql($sql));
  48. $prep_statement->execute();
  49. $ringbacks = $prep_statement->fetchAll(PDO::FETCH_NAMED);
  50. unset ($prep_statement, $sql);
  51. foreach($ringbacks as $ringback) {
  52. $ringback = $ringback['var_name'];
  53. $label = $text['label-'.$ringback];
  54. if ($label == "") {
  55. $label = $ringback;
  56. }
  57. $ringback_list[$ringback] = $label;
  58. }
  59. $this->ringbacks = $ringback_list;
  60. unset($ringback_list);
  61. //get the default_ringback label
  62. /*
  63. $sql = "select * from v_vars where var_name = 'ringback' ";
  64. $prep_statement = $this->db->prepare(check_sql($sql));
  65. $prep_statement->execute();
  66. $result = $prep_statement->fetch();
  67. unset ($prep_statement, $sql);
  68. $default_ringback = (string) $result['var_value'];
  69. $default_ringback = preg_replace('/\A\$\${/',"",$default_ringback);
  70. $default_ringback = preg_replace('/}\z/',"",$default_ringback);
  71. #$label = $text['label-'.$default_ringback];
  72. #if($label == "") {
  73. $label = $default_ringback;
  74. #}
  75. $this->default_ringback_label = $label;
  76. unset($results, $default_ringback, $label);
  77. */
  78. //get music on hold and recordings
  79. if (is_dir($_SERVER["PROJECT_ROOT"].'/app/music_on_hold')) {
  80. require_once "app/music_on_hold/resources/classes/switch_music_on_hold.php";
  81. $music = new switch_music_on_hold;
  82. $this->music_list = $music->get();
  83. }
  84. if (is_dir($_SERVER["PROJECT_ROOT"].'/app/recordings')) {
  85. require_once "app/recordings/resources/classes/switch_recordings.php";
  86. $recordings = new switch_recordings;
  87. $this->recordings_list = $recordings->list_recordings();
  88. }
  89. }
  90. public function select ($name, $selected) {
  91. //add multi-lingual support
  92. $language = new text;
  93. $text = $language->get();
  94. //start the select
  95. $select = "<select class='formfld' name='".$name."' id='".$name."' style='width: auto;'>\n";
  96. //music list
  97. if (count($this->music_list) > 0) {
  98. $select .= " <optgroup label='".$text['label-music_on_hold']."'>\n";
  99. $previous_name = '';
  100. foreach($this->music_list as $row) {
  101. if ($previous_name != $row['music_on_hold_name']) {
  102. $name = '';
  103. if (strlen($row['domain_uuid']) > 0) {
  104. $name = $row['domain_name'].'/';
  105. }
  106. $name .= $row['music_on_hold_name'];
  107. $select .= " <option value='local_stream://".$name."' ".(($selected == "local_stream://".$name) ? 'selected="selected"' : null).">".$row['music_on_hold_name']."</option>\n";
  108. }
  109. $previous_name = $row['music_on_hold_name'];
  110. }
  111. $select .= " </optgroup>\n";
  112. }
  113. //recordings
  114. if (sizeof($this->recordings_list) > 0) {
  115. $select .= " <optgroup label='".$text['label-recordings']."'>";
  116. foreach($this->recordings_list as $recording_value => $recording_name){
  117. $select .= " <option value='".$recording_value."' ".(($selected == $recording_value) ? 'selected="selected"' : '').">".$recording_name."</option>\n";
  118. }
  119. $select .= " </optgroup>\n";
  120. }
  121. //ringbacks
  122. if (sizeof($this->ringbacks) > 0) {
  123. $selected_ringback = $selected;
  124. $selected_ringback = preg_replace('/\A\${/',"",$selected_ringback);
  125. $selected_ringback = preg_replace('/}\z/',"",$selected_ringback);
  126. $select .= " <optgroup label='".$text['label-ringback']."'>";
  127. //$select .= " <option value='default_ringback'".(($selected == "default_ringback") ? ' selected="selected"' : '').">".$text['label-default']." (".$this->default_ringback_label.")</option>\n";
  128. foreach($this->ringbacks as $ringback_value => $ringback_name) {
  129. $select .= " <option value='\${".$ringback_value."}'".(($selected_ringback == $ringback_value) ? ' selected="selected"' : '').">".$ringback_name."</option>\n";
  130. }
  131. $select .= " </optgroup>\n";
  132. unset($selected_ringback);
  133. }
  134. //end the select and return it
  135. $select .= "</select>\n";
  136. return $select;
  137. }
  138. }
  139. }
  140. ?>