/web-interface/tpl/www/bloc/service/ipbx/asterisk/call_management/cdr/exportcsv.php

https://github.com/Eyepea/xivo-gallifrey · PHP · 174 lines · 129 code · 28 blank · 17 comment · 18 complexity · 1aeceb9f80a4f26b170f92420f3823d0 MD5 · raw file

  1. <?php
  2. #
  3. # XiVO Web-Interface
  4. # Copyright (C) 2006-2010 Proformatique <technique@proformatique.com>
  5. #
  6. # This program is free software: you can redistribute it and/or modify
  7. # it under the terms of the GNU General Public License as published by
  8. # the Free Software Foundation, either version 3 of the License, or
  9. # (at your option) any later version.
  10. #
  11. # This program is distributed in the hope that it will be useful,
  12. # but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  14. # GNU General Public License for more details.
  15. #
  16. # You should have received a copy of the GNU General Public License
  17. # along with this program. If not, see <http://www.gnu.org/licenses/>.
  18. #
  19. $url = &$this->get_module('url');
  20. $result = $this->get_var('result');
  21. $info = $this->get_var('info');
  22. if($result === false)
  23. die();
  24. header('Pragma: no-cache');
  25. header('Cache-Control: private, must-revalidate');
  26. header('Last-Modified: '.
  27. date('D, d M Y H:i:s',mktime()).' '.
  28. dwho_i18n::strftime_l('%Z',null));
  29. header('Content-Disposition: attachment; filename=xivo_cdr-'.
  30. dwho_i18n::strftime_l('%Y-%m-%d-%H:%M:%S',null).'.csv');
  31. header('Content-Type: text/csv; charset=UTF-8');
  32. ob_start();
  33. echo '"',str_replace('"','""',$this->bbf('fm_dbeg')),'";',
  34. '"',str_replace('"','""',$info['dbeg']),'"',"\n";
  35. if($info['dend'] !== '')
  36. {
  37. echo '"',str_replace('"','""',$this->bbf('fm_dend')),'";',
  38. '"',str_replace('"','""',$info['dend']),'"',"\n";
  39. }
  40. if($info['channel'] !== '')
  41. {
  42. if($info['channel'] === XIVO_SRE_IPBX_AST_CHAN_UNKNOWN)
  43. $info['channel'] = $this->bbf('fm_channel-opt','unknown');
  44. echo '"',str_replace('"','""',$this->bbf('fm_channel')),'";',
  45. '"',str_replace('"','""',$info['channel']),'"',"\n";
  46. }
  47. if($info['disposition'] !== '')
  48. {
  49. echo '"',str_replace('"','""',$this->bbf('fm_disposition')),'";',
  50. '"',str_replace('"','""',$this->bbf('fm_disposition-opt',$info['disposition'])),'"',"\n";
  51. }
  52. if($info['amaflags'] !== '')
  53. {
  54. echo '"',str_replace('"','""',$this->bbf('fm_amaflags')),'";',
  55. '"',str_replace('"','""',$this->bbf('ast_amaflag_name_info',$info['amaflagsmeta'])),'"',"\n";
  56. }
  57. if($info['dcontext'] !== '')
  58. {
  59. echo '"',str_replace('"','""',$this->bbf('fm_dcontext')),'";',
  60. '"',str_replace('"','""',$info['dcontext']),'"',"\n";
  61. }
  62. if($info['src'] !== '')
  63. {
  64. echo '"',str_replace('"','""',$this->bbf('fm_src')),'";',
  65. '"',str_replace('"','""',$info['src']),'"',"\n";
  66. }
  67. if($info['dst'] !== '')
  68. {
  69. echo '"',str_replace('"','""',$this->bbf('fm_dst')),'";',
  70. '"',str_replace('"','""',$info['dst']),'"',"\n";
  71. }
  72. if($info['clid'] !== '')
  73. {
  74. echo '"',str_replace('"','""',$this->bbf('fm_clid')),'";',
  75. '"',str_replace('"','""',$info['clid']),'"',"\n";
  76. }
  77. if($info['accountcode'] !== '')
  78. {
  79. echo '"',str_replace('"','""',$this->bbf('fm_accountcode')),'";',
  80. '"',str_replace('"','""',$info['accountcode']),'"',"\n";
  81. }
  82. if($info['userfield'] !== '')
  83. {
  84. echo '"',str_replace('"','""',$this->bbf('fm_userfield')),'";',
  85. '"',str_replace('"','""',$info['userfield']),'"',"\n";
  86. }
  87. if($info['dubeg'] !== '')
  88. {
  89. echo '"',str_replace('"','""',$this->bbf('fm_dubeg')),'";',
  90. '"',str_replace('"','""',$this->bbf('fm_dubeg-'.$info['dubegunit'],$info['dubeg'])),'"',"\n";
  91. }
  92. if($info['duend'] !== '')
  93. {
  94. echo '"',str_replace('"','""',$this->bbf('fm_duend')),'";',
  95. '"',str_replace('"','""',$this->bbf('fm_duend-'.$info['duendunit'],$info['duend'])),'"',"\n";
  96. }
  97. echo "\n";
  98. if($result === null || ($nb = count($result)) === 0)
  99. {
  100. echo $this->bbf('no_cdr-result');
  101. header('Content-Length: '.ob_get_length());
  102. ob_end_flush();
  103. die();
  104. }
  105. echo '"',str_replace('"','""',$this->bbf('col_calldate')),'";',
  106. '"',str_replace('"','""',$this->bbf('col_src')),'";',
  107. '"',str_replace('"','""',$this->bbf('col_dst')),'";',
  108. '"',str_replace('"','""',$this->bbf('col_duration')),'";',
  109. '"',str_replace('"','""',$this->bbf('col_channel')),'";',
  110. '"',str_replace('"','""',$this->bbf('col_disposition')),'";',
  111. '"',str_replace('"','""',$this->bbf('col_amaflags')),'";',
  112. '"',str_replace('"','""',$this->bbf('col_clid')),'";',
  113. '"',str_replace('"','""',$this->bbf('col_accountcode')),'";',
  114. '"',str_replace('"','""',$this->bbf('col_userfield')),'";',
  115. '"',str_replace('"','""',$this->bbf('col_dcontext')),'";',
  116. '"',str_replace('"','""',$this->bbf('col_dstchannel')),'";',
  117. '"',str_replace('"','""',$this->bbf('col_billsec')),'";',
  118. '"',str_replace('"','""',$this->bbf('col_lastapp')),'";',
  119. '"',str_replace('"','""',$this->bbf('col_lastdata')),'";',
  120. '"',str_replace('"','""',$this->bbf('col_uniqueid')),'"',"\n";
  121. for($i = 0;$i < $nb;$i++)
  122. {
  123. $ref = &$result[$i];
  124. if($ref['channel'] === XIVO_SRE_IPBX_AST_CHAN_UNKNOWN)
  125. $ref['channel'] = $this->bbf('entry_channel','unknown');
  126. echo '"',str_replace('"','""',strftime($this->bbf('date_format_yymmddhhiiss'),strtotime($ref['calldate']))),'";',
  127. '"',str_replace('"','""',$ref['src']),'";',
  128. '"',str_replace('"','""',$ref['dst']),'";',
  129. '"',str_replace('"','""',$ref['duration']),'";',
  130. '"',str_replace('"','""',$ref['channel']),'";',
  131. '"',str_replace('"','""',$this->bbf('entry_disposition',$ref['disposition'])),'";',
  132. '"',str_replace('"','""',$this->bbf('ast_amaflag_name_info',$ref['amaflagsmeta'])),'";',
  133. '"',str_replace('"','""',$ref['clid']),'";',
  134. '"',str_replace('"','""',$ref['accountcode']),'";',
  135. '"',str_replace('"','""',$ref['userfield']),'";',
  136. '"',str_replace('"','""',$ref['dcontext']),'";',
  137. '"',str_replace('"','""',$ref['dstchannel']),'";',
  138. '"',str_replace('"','""',$ref['billsec']),'";',
  139. '"',str_replace('"','""',$ref['lastapp']),'";',
  140. '"',str_replace('"','""',$ref['lastdata']),'";',
  141. '"',str_replace('"','""',$ref['uniqueid']),'"',"\n";
  142. }
  143. header('Content-Length: '.ob_get_length());
  144. ob_end_flush();
  145. die();
  146. ?>