PageRenderTime 57ms CodeModel.GetById 24ms RepoModel.GetById 1ms app.codeStats 0ms

/cdr/cdrinfo.php

https://github.com/gujun/ssweb
PHP | 139 lines | 116 code | 9 blank | 14 comment | 24 complexity | 0c3167618325fab92728878e75bb0b0c MD5 | raw file
  1. <?php
  2. //set_include_path(get_include_path().PATH_SEPARATOR.'../libs/'.PATH_SEPARATOR.'../include/');
  3. require_once "../include/switchroot.php";
  4. $dir = $switchroot."log/cdr-csv/";
  5. $trim = '"';
  6. $doc = array();
  7. $rowIdx = 1;
  8. //$doc;// array('用户','号码','被叫','开始','时长');
  9. $time_start = date('Y-m-d H:i:s');//,mktime(13,0,0,11,1,2009));
  10. if(isset($_POST['start'])){
  11. $time_start = $_POST['start'];
  12. }
  13. $time_end = date('Y-m-d H:i:s');//,mktime(14,0,0,12,31,2009));
  14. if(isset($_POST['end'])){
  15. $time_end = $_POST['end'];
  16. }
  17. //echo "$time_start--$time_end <br>";
  18. if(is_dir($dir)){
  19. // echo "is dir\n";
  20. if($dh = opendir($dir)){
  21. //echo "open".$dir."\n";
  22. while(($file = readdir($dh)) !== false){
  23. //echo $dir.$file."\n";
  24. if(is_file($dir.$file) && is_readable($dir.$file)){
  25. //echo $dir.$file."readable\n";
  26. $fh = fopen($dir.$file,"r");
  27. if($fh){
  28. //echo $dir.$file."open\n";
  29. while(!feof($fh)){
  30. $buffer = stream_get_line($fh,1024,"\n");
  31. //echo $buffer."\n";
  32. /*<template name="example">"${caller_id_name}","${caller_id_number}","${destination_number}","${context}","${start_stamp}","${answ
  33. er_stamp}","${end_stamp}","${duration}","${billsec}","${hangup_cause}","${uuid}","${bleg_uuid}","${accountcode}","${read_codec}","${
  34. write_codec}"</template>*/
  35. list($name,$caller_id,$callee_id,$context,$start,$answer,$end,$dura,$billsec,$cause,$uuid,$bleg_uuid,$account,$read_codec,$write_codec) = explode(",",$buffer,15);
  36. $name = trim($name,$trim);
  37. if(is_null($caller_id) || strlen($caller_id) == 0 || strstr($caller_id,'00000000') !== false){
  38. continue;
  39. }
  40. $start = trim($start,$trim);
  41. if(strcmp($start,$time_start) < 0 ||
  42. strcmp($start,$time_end) > 0){
  43. continue;
  44. }
  45. $caller_id = trim($caller_id,$trim);
  46. $callee_id = trim($callee_id,$trim);
  47. $answer = trim($answer,$trim);
  48. $billsec = trim($billsec,$trim);
  49. $billhour = (int)($billsec/3600);
  50. $billsec = (int)($billsec - ($billhour*3600));
  51. $billmin = (int)($billsec/60);
  52. $billsec = (int)($billsec - ($billmin*60));
  53. $bill = "";
  54. if($billhour > 0){
  55. $bill .= $billhour."时".$billmin."分".$billsec."秒";
  56. }
  57. else if($billmin > 0){
  58. $bill .= $billmin."分".$billsec."秒";
  59. }
  60. else if($billsec > 0){
  61. $bill .= $billsec."秒";
  62. }
  63. else{
  64. $bill .="0";
  65. }
  66. if(($apos = strpos($callee_id,'@')) !== false){
  67. $callee_id = substr($callee_id,0,$apos);
  68. $callee_id = substr(strrchr($callee_id,': '),1);
  69. }
  70. $doc[] = array($name,$caller_id,$callee_id,$start,$bill);
  71. }
  72. fclose($fh);
  73. }
  74. }
  75. }
  76. closedir($dh);
  77. }
  78. }
  79. function cmp($a,$b){
  80. $r = 0;
  81. $r = strcmp($a[0],$b[0]);
  82. if($r == 0){
  83. $r = strcmp($a[3],$b[3]);
  84. }
  85. return $r;
  86. }
  87. usort($doc,"cmp");
  88. array_unshift($doc,array('用户','号码','被叫','开始','时长'));
  89. session_start();
  90. if(isset($_SESSION['cdr'])){
  91. unset($_SESSION['cdr']);
  92. //session_distory();
  93. }
  94. $_SESSION['cdr']=$doc;
  95. session_write_close();
  96. echo "<div align='center'>\n";
  97. echo "<table bordercolor='#000000' border=0 width=600 align='center'>\n";
  98. //echo "<tr><td>用户</td><td>号码</td><td>被叫</td><td>开始</td><td>时长</td></tr>\n";
  99. foreach($doc as $row=>$cols){
  100. if(($rowIdx%2) == 0){
  101. echo "<tr bgcolor='#FFFFFF' align='right'>\n";
  102. }
  103. else{
  104. echo "<tr bgcolor='#EDF3F4' align='right'>\n";
  105. }
  106. $colIdx = 'A';
  107. echo "<td>\n";
  108. echo "$cols[0]";
  109. echo "</td>\n";
  110. echo "<td>\n";
  111. echo "$cols[1]";
  112. echo "</td>\n";
  113. echo "<td>\n";
  114. echo "$cols[2]";
  115. echo "</td>\n";
  116. echo "<td>\n";
  117. echo "$cols[3]";
  118. echo "</td>\n";
  119. echo "<td>\n";
  120. echo "$cols[4]";
  121. echo "</td>\n";
  122. $rowIdx++;
  123. echo "</tr>\n";
  124. }
  125. echo "</table>\n";
  126. echo "</div>\n";
  127. echo "<div align='right'>";
  128. echo "<a href=\"xls.php\">xls导出</a>";
  129. echo "</div>";
  130. ?>