voicemail_export.php 9.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314
  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. //get the includes
  32. require "resources/require.php";
  33. require_once "resources/header.php";
  34. echo "<pre>\n";
  35. //prepare the data variable
  36. $data = '';
  37. //delete the voicemail dialplans so that they can be updated
  38. // <extension name="local_extension" app_uuid="71cf1310-b6e3-415b-8745-3cbdc8e15212">
  39. $sql = "select dialplan_uuid from v_dialplans where app_uuid = '71cf1310-b6e3-415b-8745-3cbdc8e15212' ";
  40. // <extension name="send_to_voicemail" app_uuid="001d5dab-e0c6-4352-8f06-e9986ee7b0d8">
  41. $sql .= "or app_uuid = '001d5dab-e0c6-4352-8f06-e9986ee7b0d8' ";
  42. // <extension name="vmain" app_uuid="d085a1e3-c53a-4480-9ca6-6a362899a681">
  43. $sql .= "or app_uuid = 'd085a1e3-c53a-4480-9ca6-6a362899a681' ";
  44. // <extension name="vmain_user" app_uuid="5d47ab13-f25d-4f62-a68e-2a7d945d05b7">
  45. $sql .= "or app_uuid = '5d47ab13-f25d-4f62-a68e-2a7d945d05b7' ";
  46. $prep_statement = $db->prepare(check_sql($sql));
  47. $prep_statement->execute();
  48. $result = $prep_statement->fetchAll(PDO::FETCH_NAMED);
  49. foreach($result as $row) {
  50. $sql = "delete from v_dialplans where dialplan_uuid = '".$row['dialplan_uuid']."'";
  51. echo $sql.";\n";
  52. $db->query($sql);
  53. unset($sql);
  54. $sql = "delete from v_dialplan_details where dialplan_uuid = '".$row['dialplan_uuid']."'";
  55. echo $sql.";\n";
  56. $db->query($sql);
  57. unset($sql);
  58. }
  59. //list the voicemail prefs
  60. $sql = "select * from v_extensions ";
  61. $prep_statement = $db->prepare(check_sql($sql));
  62. $prep_statement->execute();
  63. $result = $prep_statement->fetchAll(PDO::FETCH_NAMED);
  64. $result_count = count($result);
  65. unset ($prep_statement, $sql);
  66. if ($result_count > 0) {
  67. foreach($result as $row) {
  68. $domain_uuid = $row['domain_uuid'];
  69. $voicemail_id = $row['extension'];
  70. $voicemail_password = $row['vm_password'];
  71. $voicemail_enabled = $row['vm_enabled']; //true, false
  72. $voicemail_mail_to = $row['vm_mailto'];
  73. $voicemail_attach_file = $row['vm_attach_file']; //true, false
  74. $voicemail_local_after_email = $row['vm_keep_local_after_email']; //true, false
  75. $voicemail_description = $row['description'];
  76. //print_r($row);
  77. //set default values
  78. if (strlen($voicemail_enabled) == 0) {
  79. $voicemail_enabled = "true";
  80. }
  81. if (strlen($voicemail_attach_file) == 0) {
  82. $voicemail_attach_file = "true";
  83. }
  84. if (strlen($voicemail_local_after_email) == 0) {
  85. $voicemail_local_after_email = "true";
  86. }
  87. //map the voicemail_id to the voicemail_uuid
  88. $voicemail_uuid = uuid();
  89. $mailbox[$voicemail_id]['voicemail_uuid'] = $voicemail_uuid;
  90. if ($row['vm_enabled'] == "true" || $row['vm_enabled'] == "") {
  91. $sql = "insert into v_voicemails ";
  92. $sql .= "(";
  93. $sql .= "domain_uuid, ";
  94. $sql .= "voicemail_uuid, ";
  95. $sql .= "voicemail_id, ";
  96. $sql .= "voicemail_password, ";
  97. //if (strlen($greeting_id) > 0) {
  98. // $sql .= "greeting_id, ";
  99. //}
  100. $sql .= "voicemail_mail_to, ";
  101. $sql .= "voicemail_attach_file, ";
  102. $sql .= "voicemail_local_after_email, ";
  103. $sql .= "voicemail_enabled, ";
  104. $sql .= "voicemail_description ";
  105. $sql .= ") ";
  106. $sql .= "values ";
  107. $sql .= "(";
  108. $sql .= "'$domain_uuid', ";
  109. $sql .= "'$voicemail_uuid', ";
  110. $sql .= "'$voicemail_id', ";
  111. $sql .= "'$voicemail_password', ";
  112. //if (strlen($greeting_id) > 0) {
  113. // $sql .= "'$greeting_id', ";
  114. //}
  115. $sql .= "'$voicemail_mail_to', ";
  116. $sql .= "'$voicemail_attach_file', ";
  117. $sql .= "'$voicemail_local_after_email', ";
  118. $sql .= "'$voicemail_enabled', ";
  119. $sql .= "'$voicemail_description' ";
  120. $sql .= ");\n";
  121. echo $sql.";";
  122. $db->exec(check_sql($sql));
  123. unset($sql);
  124. }
  125. }
  126. }
  127. //list the voicemail messages
  128. /*
  129. $sql = "select * from v_voicemails ";
  130. $prep_statement = $db->prepare(check_sql($sql));
  131. $prep_statement->execute();
  132. $result = $prep_statement->fetchAll(PDO::FETCH_NAMED);
  133. $result_count = count($result);
  134. unset ($prep_statement, $sql);
  135. if ($result_count > 0) {
  136. foreach($result as $row) {
  137. $voicemail_id = $row['voicemail_id'];
  138. $voicemail_uuid = $row['voicemail_uuid'];
  139. $mailbox[$voicemail_id]['voicemail_uuid'] = $voicemail_uuid;
  140. }
  141. }
  142. */
  143. //pdo voicemail database connection
  144. include "resources/pdo_vm.php";
  145. //list the voicemail prefs
  146. $sql = "select * from voicemail_prefs ";
  147. $prep_statement = $db->prepare(check_sql($sql));
  148. $prep_statement->execute();
  149. $result = $prep_statement->fetchAll(PDO::FETCH_NAMED);
  150. $result_count = count($result);
  151. unset ($prep_statement, $sql);
  152. if ($result_count > 0) {
  153. foreach($result as $row) {
  154. $voicemail_id = $row['username'];
  155. $domain_name = $row['domain'];
  156. //$name_path = $row['name_path'];
  157. $greeting_path = $row['greeting_path'];
  158. if (strlen($row['greeting_path']) > 0) {
  159. $greeting_id = substr($greeting_path, -5, 1);
  160. }
  161. else {
  162. $greeting_id = '';
  163. }
  164. $voicemail_password = $row['password'];
  165. //print_r($row);
  166. //get the domain_uuid
  167. foreach($_SESSION['domains'] as $tmp) {
  168. if ($tmp['domain_name'] == $domain_name) {
  169. $domain_uuid = $tmp['domain_uuid'];
  170. }
  171. }
  172. //get the voicemail_uuid
  173. $voicemail_uuid = $mailbox[$voicemail_id]['voicemail_uuid'];
  174. $sql = "update v_voicemails set ";
  175. if (strlen($voicemail_password) > 0) {
  176. $sql .= "voicemail_password = '$voicemail_password', ";
  177. }
  178. if (strlen($greeting_id) > 0) {
  179. $sql .= "greeting_id = '$greeting_id' ";
  180. }
  181. else {
  182. $sql .= "greeting_id = null ";
  183. }
  184. $sql .= "where domain_uuid = '$domain_uuid' ";
  185. $sql .= "and voicemail_uuid = '$voicemail_uuid';";
  186. $data .= $sql;
  187. unset($sql);
  188. }
  189. unset($prep_statement, $sql, $result, $row_count);
  190. }
  191. //list the voicemail messages
  192. $sql = "select * from voicemail_msgs ";
  193. $prep_statement = $db->prepare(check_sql($sql));
  194. $prep_statement->execute();
  195. $result = $prep_statement->fetchAll(PDO::FETCH_NAMED);
  196. $result_count = count($result);
  197. unset ($prep_statement, $sql);
  198. if ($result_count > 0) {
  199. foreach($result as $row) {
  200. $created_epoch = $row['created_epoch'];
  201. $read_epoch = $row['read_epoch'];
  202. $voicemail_id = $row['username'];
  203. $domain_name = $row['domain'];
  204. $voicemail_message_uuid = $row['uuid'];
  205. $caller_id_name = $row['cid_name'];
  206. $caller_id_number = $row['cid_number'];
  207. //$in_folder = $row['in_folder'];
  208. //$file_path = $row['file_path']; // /usr/local/freeswitch/storage/voicemail/default/domain/1234/msg_91a5ca90-2767-11e2-9ebe-5dc9a6afc9fd.wav
  209. $message_length = $row['message_len'];
  210. $voicemail_status = $row['flags'];
  211. $voicemail_priority = $row['read_flags']; // B_NORMAL
  212. //$forwarded_by = $row['forwarded_by'];
  213. $file_path = $row['file_path'];
  214. $array = explode(".", substr($file_path, -40));
  215. $voicemail_message_uuid = $array[0];
  216. //get the domain_uuid
  217. foreach($_SESSION['domains'] as $tmp) {
  218. if ($tmp['domain_name'] == $domain_name) {
  219. $domain_uuid = $tmp['domain_uuid'];
  220. }
  221. }
  222. //get the voicemail_uuid
  223. $voicemail_uuid = $mailbox[$voicemail_id]['voicemail_uuid'];
  224. //update the message status using read_epoch
  225. if ($read_epoch > 0) {
  226. $message_status = 'saved';
  227. }
  228. else {
  229. $message_status = '';
  230. }
  231. //add the voicemail message
  232. $sql = "insert into v_voicemail_messages ";
  233. $sql .= "(";
  234. $sql .= "domain_uuid, ";
  235. $sql .= "voicemail_message_uuid, ";
  236. $sql .= "voicemail_uuid, ";
  237. $sql .= "created_epoch, ";
  238. $sql .= "read_epoch, ";
  239. $sql .= "caller_id_name, ";
  240. $sql .= "caller_id_number, ";
  241. $sql .= "message_length, ";
  242. $sql .= "message_status, ";
  243. $sql .= "message_priority ";
  244. $sql .= ") ";
  245. $sql .= "values ";
  246. $sql .= "(";
  247. $sql .= "'$domain_uuid', ";
  248. $sql .= "'$voicemail_message_uuid', ";
  249. $sql .= "'$voicemail_uuid', ";
  250. $sql .= "'$created_epoch', ";
  251. $sql .= "'$read_epoch', ";
  252. $sql .= "'$caller_id_name', ";
  253. $sql .= "'$caller_id_number', ";
  254. $sql .= "'$message_length', ";
  255. $sql .= "'$message_status', ";
  256. $sql .= "'$message_priority' ";
  257. $sql .= ");";
  258. $data .= $sql;
  259. unset($sql);
  260. }
  261. unset($prep_statement, $sql, $result, $row_count, $domain_uuid);
  262. }
  263. //reset the database connection
  264. unset($db);
  265. require "resources/require.php";
  266. //start the atomic transaction
  267. $db->exec("BEGIN;");
  268. //loop through the sql array
  269. $sql_array = explode(";", $data);
  270. foreach($sql_array as $sql) {
  271. echo $sql."\n";
  272. $db->exec(check_sql($sql));
  273. }
  274. //commit the atomic transaction
  275. $count = $db->exec("COMMIT;"); //returns affected rows
  276. //show the footer
  277. echo "</pre>\n";
  278. require_once "resources/footer.php";
  279. ?>