Advertisement
Guest User

Untitled

a guest
Jun 22nd, 2017
106
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 4.36 KB | None | 0 0
  1. <?php
  2.  
  3. include('../config2.php');
  4.  
  5.     $query = "SELECT start, finished FROM billingdates ORDER BY start ASC";
  6.     $result = mysql_query($query);
  7.  
  8.  
  9.     while ($row2=mysql_fetch_array($result))
  10.     {
  11.         $startdate[] = $row2['start'];
  12.         $enddate[] = $row2['finished'];
  13.     }
  14.  
  15.  
  16. $query = "SELECT account, did, calls, msgs, deliveryhistory, frequency FROM reports";
  17. $results = mysql_query($query);
  18.  
  19. function callsReport()
  20. {
  21. $db = pg_connect('host=10.0.11.64 dbname=call_linx_trans_db_backup user=call_linx password=');
  22.  
  23.         $query = sprintf("select * from (SELECT to_char(time_start, 'mm-dd-yyyy hh12:mm:ss') AS time_start, dura_caller :: numeric, dura_wrapup ::numeric, callerid, round(round(((round((((COALESCE(dura_caller,.00000000001) :: numeric)/6)+0.49),0)*6)/60),1)+((round((((COALESCE(dura_vmsoutb,.0000000000000001) :: numeric)/6)+0.49),0)*6)/60)+(((round((((COALESCE(dura_wrapup,0) :: numeric)/6)+.49),0)*6)/60)*.5),1) AS agent_time FROM call_stats WHERE mainbox = '" . $row['did'] . "' AND time_start BETWEEN '$startdate[2]' AND '$enddate[2]') as x where x.agent_time > 0 ORDER BY time_start");
  24.  
  25.         $result = pg_query($query);
  26.         if (!$result) {
  27.             echo "Problem with query " . $query . "<br/>";
  28.             echo pg_last_error();
  29.             exit();
  30.         }
  31.  
  32.         $num_rows = pg_num_rows($result);
  33.        
  34.         echo "<div class=\"scrollTableContainer\"><table class=\"dataTable\" cellspacing=\"0\"><thead id='mythead'><tr><th>Start Time</th><th>Agent Time</th><th>Caller ID (When Provided)</th></tr></thead><hr>";
  35.  
  36.         while($row = pg_fetch_assoc($result)) {
  37.            echo "<tr>";
  38.            echo "<td>" . $row['time_start'] . " </td>";
  39.            echo "<td>";
  40.            echo " " . $row['agent_time'] . " </td>";
  41.            if ( $row['dura_caller'] == 0 ) echo "<td>-</td>";
  42.            else echo "<td>" . $row['callerid'] . " <br /></td></tr>";
  43.         }
  44.         echo "</table></div>";
  45.            
  46.            
  47.             $db = pg_connect('host=10.0.11.64 dbname=call_linx_trans_db_backup user=call_linx password=');
  48.            
  49.     $query2 = "SELECT COUNT(inbound) AS inboundcount FROM call_stats WHERE inbound = 1 AND dura_released = null AND mainbox= '$did' AND time_start between '$startdate[2]' AND '$enddate[2]'";
  50.  
  51.     $result2 = pg_query($query2);
  52.         if (!$result2) {
  53.             echo "Problem with query " . $query2 . "<br/>";
  54.             echo pg_last_error();
  55.             exit();
  56.         }
  57.        
  58. $row = pg_fetch_array($result2);
  59.  
  60. $Inbound = $row['inboundcount'];
  61.  
  62.  
  63. $avgcount = "SELECT round((SUM((dura_wait :: numeric))/(SUM(inbound))),1) as avghold FROM call_stats WHERE inbound = 1 AND dura_released = null AND mainbox= '$did' AND time_start between '$startdate[2]' AND '$enddate[2]'";
  64.  
  65. $avgcountresult = pg_query($avgcount);
  66.         if (!$avgcountresult) {
  67.             echo "Problem with query " . $avgcount . "<br/>";
  68.             echo pg_last_error();
  69.             exit();
  70.         }
  71.        
  72. $row = pg_fetch_array($avgcountresult);
  73.        
  74. $AvgHold = $row['avghold'];
  75.  
  76. $query3 = sprintf("SELECT round(SUM(round(((round((((COALESCE(dura_caller,.00000000001) :: numeric)/6)+0.49),0)*6)/60),1)+((round((((COALESCE(dura_vmsoutb,.0000000000000001) :: numeric)/6)+0.49),0)*6)/60)
  77. +(((round((((COALESCE(dura_wrapup,0) :: numeric)/6)+.49),0)*6)/60)*.5)),1) AS agenttime FROM call_stats WHERE mainbox= '$did' AND time_start between '$startdate[2]' AND '$enddate[2]'");
  78.  
  79. $result3 = pg_query($query3);
  80.         if (!$result3) {
  81.             echo "Problem with query " . $query3 . "<br/>";
  82.             echo pg_last_error();
  83.             exit();
  84.         }
  85.        
  86. $row1 = pg_fetch_array($result3);
  87.  
  88. $TotalMinutes = $row1['agenttime'];
  89.  
  90. echo "<font size=\"3\"><br /><br />Total Calls: <strong>" . $Inbound . "</strong><br /> Total Minutes Used: <strong>" . $TotalMinutes .  "</strong><br />";
  91. echo " Average Hold (seconds): <strong>"
  92.  . $AvgHold .  "</strong><br /><br /><br />";
  93. echo "</font><br /><br />";
  94. }
  95.  
  96. while ($row=mysql_fetch_array($results))
  97.     {
  98.         $did=$row['did'];
  99.         $dow = date(l);
  100.        
  101.         echo $dow;
  102.        
  103.         // Checks to make sure it can run the report for calls
  104.         if ($row['calls']=="1")
  105.             {
  106.                 // Checks the frequency of the run - If it is 1 - it runs daily - If it is 7 it runs weekly - 30 is monthly
  107.                 if ($row['frequency']=="1")
  108.                 {
  109.        
  110.                 callsReport();
  111.    
  112.                 }
  113.             }
  114.    
  115.     // This checks the frequency if it is not 1 day a week
  116.     if ($row['frequency']=="7")
  117.                 {
  118.                     // Checks to make sure its Monday. If it is not, the report wont run
  119.                     if ($dow=="Monday")
  120.                     {
  121.                         callsReport();
  122.    
  123.    
  124.                     }
  125.                 }
  126.    
  127. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement