/LANG_www/vicidial_el/AST_timeoncall.php

https://github.com/inktel/Vicidial · PHP · 180 lines · 149 code · 26 blank · 5 comment · 24 complexity · f4dafa08a8d40f981dce3abf65eceda9 MD5 · raw file

  1. <?
  2. ### AST_timeoncall.php
  3. ###
  4. ### Copyright (C) 2006 Matt Florell <vicidial@gmail.com> LICENSE: GPLv2
  5. ###
  6. require("dbconnect.php");
  7. $PHP_AUTH_USER=$_SERVER['PHP_AUTH_USER'];
  8. $PHP_AUTH_PW=$_SERVER['PHP_AUTH_PW'];
  9. $PHP_SELF=$_SERVER['PHP_SELF'];
  10. if (isset($_GET["server_ip"])) {$server_ip=$_GET["server_ip"];}
  11. elseif (isset($_POST["server_ip"])) {$server_ip=$_POST["server_ip"];}
  12. if (isset($_GET["reset_counter"])) {$reset_counter=$_GET["reset_counter"];}
  13. elseif (isset($_POST["reset_counter"])) {$reset_counter=$_POST["reset_counter"];}
  14. if (isset($_GET["submit"])) {$submit=$_GET["submit"];}
  15. elseif (isset($_POST["submit"])) {$submit=$_POST["submit"];}
  16. if (isset($_GET["ΕΠΙΒΕΒΑΙΩΣΗ"])) {$ΕΠΙΒΕΒΑΙΩΣΗ=$_GET["ΕΠΙΒΕΒΑΙΩΣΗ"];}
  17. elseif (isset($_POST["ΕΠΙΒΕΒΑΙΩΣΗ"])) {$ΕΠΙΒΕΒΑΙΩΣΗ=$_POST["ΕΠΙΒΕΒΑΙΩΣΗ"];}
  18. $NOW_TIME = date("Y-m-d H:i:s");
  19. $STARTtime = date("U");
  20. ?>
  21. <HTML>
  22. <HEAD>
  23. <STYLE type="text/css">
  24. <!--
  25. .green {color: white; background-color: green}
  26. .red {color: white; background-color: red}
  27. -->
  28. </STYLE>
  29. <?
  30. echo "<META HTTP-EQUIV=\"Content-Type\" CONTENT=\"text/html; charset=utf-8\">\n";
  31. echo"<META HTTP-EQUIV=Refresh CONTENT=\"15; URL=$PHP_SELF?server_ip=$server_ip&DB=$DB\">\n";
  32. echo "<TITLE>VICIDIAL: Time On Call</TITLE></HEAD><BODY BGCOLOR=WHITE>\n";
  33. echo "<PRE>\n\n";
  34. echo "VICIDIAL: Time On Call $NOW_TIME\n\n";
  35. echo "+------------+-----------+-----------+------------------+---------------------+---------+\n";
  36. echo "| STATION | SESSIONID | CHANNEL | NUMBER DIALED | START TIME | MINUTES |\n";
  37. echo "+------------+-----------+-----------+------------------+---------------------+---------+\n";
  38. $stmt="SELECT count(*) from live_sip_channels where server_ip='$server_ip';";
  39. $rslt=mysql_query($stmt, $link);
  40. if ($DB) {echo "$stmt\n";}
  41. $row=mysql_fetch_row($rslt);
  42. $parked_count = $row[0];
  43. if ($parked_count > 0)
  44. {
  45. $stmt="select extension from live_channels where server_ip='$server_ip';";
  46. $rslt=mysql_query($stmt, $link);
  47. if ($DB) {echo "$stmt\n";}
  48. $ext_to_print = mysql_num_rows($rslt);
  49. $i=0;
  50. $live_zap_counter=0;
  51. $sessions = '';
  52. while ($i < $ext_to_print)
  53. {
  54. $row=mysql_fetch_row($rslt);
  55. if (preg_match("/^8600/i",$row[0]))
  56. {
  57. $sessions .= "$row[0]|";
  58. }
  59. $i++;
  60. }
  61. $sessions = preg_replace("/\|$/",'',$sessions);
  62. if ($DB) {echo "SESSIONS: -$sessions-\n";}
  63. $stmt="select * from live_sip_channels where server_ip='$server_ip' order by channel;";
  64. $rslt=mysql_query($stmt, $link);
  65. if ($DB) {echo "$stmt\n";}
  66. $parked_to_print = mysql_num_rows($rslt);
  67. $i=0;
  68. $live_calls_counter=0;
  69. while ($i < $parked_to_print)
  70. {
  71. $row=mysql_fetch_row($rslt);
  72. if ( (preg_match("/Zap\/|internal|ring/i",$row[3])) or (preg_match("/Local\//i",$row[0])) )
  73. {
  74. if ($DB) {echo "NOT STATION |$row[0]|$row[3]|\n";}
  75. $session_id = '';
  76. }
  77. else
  78. {
  79. if (preg_match("/$row[3]/i",$sessions))
  80. {
  81. if ($DB) {echo "LIVE STATION|$row[0]|$row[3]|\n";}
  82. $session_id = $row[3];
  83. $station = preg_replace("/SIP\//",'',$row[0]);
  84. $station = preg_replace("/-.*/",'',$station);
  85. $LIVE_sessions[$live_calls_counter] = "$session_id";
  86. $LIVE_sessions_FORMAT[$live_calls_counter] = sprintf("%-9s", $session_id);
  87. $LIVE_stations[$live_calls_counter] = "$station";
  88. $LIVE_stations_FORMAT[$live_calls_counter] = sprintf("%-10s", $station);
  89. # echo "| $station | $session_id | \n";
  90. $live_calls_counter++;
  91. }
  92. else
  93. {
  94. if ($DB) {echo "NOT STATIONZ|$row[0]|$row[3]|\n";}
  95. $session_id = '';
  96. }
  97. }
  98. $i++;
  99. }
  100. if ($live_calls_counter > 0)
  101. {
  102. $i=0;
  103. $LC_counter = $live_calls_counter;
  104. while ($i < $live_calls_counter)
  105. {
  106. $stmt="select channel,extension,number_dialed,start_time,start_epoch from call_log where extension='$LIVE_stations[$i]' and server_ip='$server_ip' order by uniqueid desc LIMIT 1;";
  107. $rslt=mysql_query($stmt, $link);
  108. if ($DB) {echo "$stmt\n";}
  109. $parked_to_print = mysql_num_rows($rslt);
  110. $row=mysql_fetch_row($rslt);
  111. $channel = sprintf("%-9s", $row[0]);
  112. $number_dialed = sprintf("%-16s", $row[2]);
  113. $start_time = sprintf("%-19s", $row[3]);
  114. $call_time_S = ($STARTtime - $row[4]);
  115. $call_time_M = ($call_time_S / 60);
  116. $call_time_M = round($call_time_M, 2);
  117. $call_time_M_int = intval("$call_time_M");
  118. $call_time_SEC = ($call_time_M - $call_time_M_int);
  119. $call_time_SEC = ($call_time_SEC * 60);
  120. $call_time_SEC = round($call_time_SEC, 0);
  121. if ($call_time_SEC < 10) {$call_time_SEC = "0$call_time_SEC";}
  122. $call_time_MS = "$call_time_M_int:$call_time_SEC";
  123. $call_time_MS = sprintf("%7s", $call_time_MS);
  124. $G = ''; $EG = '';
  125. if ($call_time_M_int >= 12) {$G='<SPAN class="green"><B>'; $EG='</B></SPAN>';}
  126. if ($call_time_M_int >= 31) {$G='<SPAN class="red"><B>'; $EG='</B></SPAN>';}
  127. echo "| $G$LIVE_stations_FORMAT[$i]$EG | $G$LIVE_sessions_FORMAT[$i]$EG | $G$channel$EG | $G$number_dialed$EG | $G$start_time$EG | $G$call_time_MS$EG |\n";
  128. $i++;
  129. }
  130. echo "+------------+-----------+-----------+------------------+---------------------+---------+\n";
  131. echo " $i stations on live calls on server $server_ip\n\n";
  132. echo " <SPAN class=\"green\"><B> </SPAN> - 12 minutes or more on live call\n";
  133. echo " <SPAN class=\"red\"><B> </SPAN> - Over 30 minutes on live call\n";
  134. }
  135. else
  136. {
  137. echo "*****************************************************************************************\n";
  138. echo "*****************************************************************************************\n";
  139. echo "*************************************** NO LIVE STATIONS ********************************\n";
  140. echo "*****************************************************************************************\n";
  141. echo "*****************************************************************************************\n";
  142. }
  143. }
  144. else
  145. {
  146. echo "*****************************************************************************************\n";
  147. echo "*****************************************************************************************\n";
  148. echo "*************************************** NO LIVE STATIONS ********************************\n";
  149. echo "*****************************************************************************************\n";
  150. echo "*****************************************************************************************\n";
  151. }
  152. ?>
  153. </PRE>
  154. </BODY></HTML>