Advertisement
Guest User

Untitled

a guest
Jun 22nd, 2017
94
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 12.19 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, email FROM reports";
  17. $results = mysql_query($query);
  18.  
  19. while ($row=mysql_fetch_array($results))
  20.     {
  21.         $did = $row['did'];
  22.         $dow = date(l);
  23.         $dom = date(d);
  24.         $today = date("D, F j, Y");
  25.        
  26.         // Checks to make sure it can run the report for calls
  27.         if ($row['calls']=="1")
  28.             {
  29.                 // Checks the frequency of the run - If it is 1 - it runs daily - If it is 7 it runs weekly - 30 is monthly
  30.                 if ($row['frequency']=="1")
  31.                 {
  32.                    
  33.                             // Email Recipient/Sender
  34.     $recip = $row['email'];
  35.     $sender = "service@maximumcallcenter.com";
  36.                            
  37.                             // Starts message
  38.                             $strMessage = "Call Report: \n\n\n";
  39.                             $strMessage .= '<html><head></head><body><table><tr><th>Call Time</th><th>Talk Time</th><th>Caller ID (If Available)</th></tr>';
  40.            
  41.         $db = pg_connect('host=10.0.11.64 dbname=call_linx_trans_db_backup user=call_linx password=');
  42.  
  43.         $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");
  44.  
  45.         $result = pg_query($query);
  46.         if (!$result) {
  47.             echo "Problem with query " . $query . "<br/>";
  48.             echo pg_last_error();
  49.             exit();
  50.         }
  51.  
  52.         $num_rows = pg_num_rows($result);
  53.  
  54.         while($row = pg_fetch_array($result))
  55.         {
  56.         $strMessage .= '<tr><td><center>' . $row['time_start'] . '</center></td><td><center>' . $row['agent_time'] . '</center></td><td><center>' . $row['callerid'] . '</center></td></tr>';  
  57.         }
  58.  
  59.             }
  60.            
  61.             $db = pg_connect('host=10.0.11.64 dbname=call_linx_trans_db_backup user=call_linx password=');
  62.            
  63.     $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]'";
  64.  
  65.     $result2 = pg_query($query2);
  66.         if (!$result2) {
  67.             echo "Problem with query " . $query2 . "<br/>";
  68.             echo pg_last_error();
  69.             exit();
  70.         }
  71.        
  72. $row = pg_fetch_array($result2);
  73.  
  74. $Inbound = $row['inboundcount'];
  75.  
  76.  
  77. $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]'";
  78.  
  79. $avgcountresult = pg_query($avgcount);
  80.         if (!$avgcountresult) {
  81.             echo "Problem with query " . $avgcount . "<br/>";
  82.             echo pg_last_error();
  83.             exit();
  84.         }
  85.        
  86. $row = pg_fetch_array($avgcountresult);
  87.        
  88. $AvgHold = $row['avghold'];
  89.  
  90. $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)
  91. +(((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]'");
  92.  
  93. $result3 = pg_query($query3);
  94.         if (!$result3) {
  95.             echo "Problem with query " . $query3 . "<br/>";
  96.             echo pg_last_error();
  97.             exit();
  98.         }
  99.        
  100. $row1 = pg_fetch_array($result3);
  101.  
  102. $TotalMinutes = $row1['agenttime'];
  103.  
  104. $strMessage .= "<font size=\"3\"><br /><br />Total Calls: <strong>" . $Inbound . "</strong><br /> Total Minutes Used: <strong>" . $TotalMinutes .  "</strong><br /> Average Hold (seconds): <strong>" . $AvgHold .  "</strong><br /><br /><br /></font><br /><br />";  
  105.    
  106.    
  107.     $headers = 'MIME-Version: 1.0' . "\r\n";
  108.     $headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n";
  109.     $headers .= 'From: MAXIMUM Call Center <service@maximumcallcenter.com>' . "\r\n";
  110.     $subject = 'MAXIMUM Call Center - Call Report';
  111.    
  112.     // Sends email
  113.     mail( $recip, $subject, $strMessage, $headers );
  114.    
  115.     var_dump($strMessage);
  116.    
  117.     }
  118.    
  119.     }
  120.     // This checks the frequency if it is not 1 day a week
  121.     if ($row['frequency']=="7")
  122.                 {
  123.                     // Checks to make sure its Monday. If it is not, the report wont run
  124.                     if ($dow=="Monday")
  125.                     {
  126.        
  127.     // Email Recipient/Sender
  128.     $recip = $row['email'];
  129.     $sender = "service@maximumcallcenter.com";
  130.                            
  131.                             // Starts message
  132.                             $strMessage = "Call Report: \n\n\n";
  133.                             $strMessage .= '<html><head></head><body><table><tr><th>Call Time</th><th>Talk Time</th><th>Caller ID (If Available)</th></tr>';
  134.            
  135.         $db = pg_connect('host=10.0.11.64 dbname=call_linx_trans_db_backup user=call_linx password=');
  136.  
  137.         $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");
  138.  
  139.         $result = pg_query($query);
  140.         if (!$result) {
  141.             echo "Problem with query " . $query . "<br/>";
  142.             echo pg_last_error();
  143.             exit();
  144.         }
  145.  
  146.         $num_rows = pg_num_rows($result);
  147.  
  148.         while($row = pg_fetch_array($result))
  149.         {
  150.         $strMessage .= '<tr><td><center>' . $row['time_start'] . '</center></td><td><center>' . $row['agent_time'] . '</center></td><td><center>' . $row['callerid'] . '</center></td></tr>';  
  151.         }
  152.  
  153.             }
  154.            
  155.             $db = pg_connect('host=10.0.11.64 dbname=call_linx_trans_db_backup user=call_linx password=');
  156.            
  157.     $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]'";
  158.  
  159.     $result2 = pg_query($query2);
  160.         if (!$result2) {
  161.             echo "Problem with query " . $query2 . "<br/>";
  162.             echo pg_last_error();
  163.             exit();
  164.         }
  165.        
  166. $row = pg_fetch_array($result2);
  167.  
  168. $Inbound = $row['inboundcount'];
  169.  
  170.  
  171. $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]'";
  172.  
  173. $avgcountresult = pg_query($avgcount);
  174.         if (!$avgcountresult) {
  175.             echo "Problem with query " . $avgcount . "<br/>";
  176.             echo pg_last_error();
  177.             exit();
  178.         }
  179.        
  180. $row = pg_fetch_array($avgcountresult);
  181.        
  182. $AvgHold = $row['avghold'];
  183.  
  184. $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)
  185. +(((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]'");
  186.  
  187. $result3 = pg_query($query3);
  188.         if (!$result3) {
  189.             echo "Problem with query " . $query3 . "<br/>";
  190.             echo pg_last_error();
  191.             exit();
  192.         }
  193.        
  194. $row1 = pg_fetch_array($result3);
  195.  
  196. $TotalMinutes = $row1['agenttime'];
  197.  
  198. $strMessage .= "<font size=\"3\"><br /><br />Total Calls: <strong>" . $Inbound . "</strong><br /> Total Minutes Used: <strong>" . $TotalMinutes .  "</strong><br /> Average Hold (seconds): <strong>" . $AvgHold .  "</strong><br /><br /><br /></font><br /><br />";  
  199.    
  200.    
  201.     $headers = 'MIME-Version: 1.0' . "\r\n";
  202.     $headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n";
  203.     $headers .= 'From: MAXIMUM Call Center <service@maximumcallcenter.com>' . "\r\n";
  204.     $subject = 'MAXIMUM Call Center - Call Report';
  205.    
  206.     // Sends email
  207.     mail( $recip, $subject, $strMessage, $headers );
  208.    
  209.                     }
  210.                
  211.             if ($row['frequency']=="30")
  212.                         {
  213.                             // Checks to make sure its Monday. If it is not, the report wont run
  214.                             if ($dom=="31")
  215.                                 {
  216.                                     // Email Recipient/Sender
  217.     $recip = $row['email'];
  218.     $sender = "service@maximumcallcenter.com";
  219.                            
  220.                             // Starts message
  221.                             $strMessage = "Call Report: \n\n\n";
  222.                             $strMessage .= '<html><head></head><body><table><tr><th>Call Time</th><th>Talk Time</th><th>Caller ID (If Available)</th></tr>';
  223.            
  224.         $db = pg_connect('host=10.0.11.64 dbname=call_linx_trans_db_backup user=call_linx password=');
  225.  
  226.         $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");
  227.  
  228.         $result = pg_query($query);
  229.         if (!$result) {
  230.             echo "Problem with query " . $query . "<br/>";
  231.             echo pg_last_error();
  232.             exit();
  233.         }
  234.  
  235.         $num_rows = pg_num_rows($result);
  236.  
  237.         while($row = pg_fetch_array($result))
  238.         {
  239.         $strMessage .= '<tr><td><center>' . $row['time_start'] . '</center></td><td><center>' . $row['agent_time'] . '</center></td><td><center>' . $row['callerid'] . '</center></td></tr>';  
  240.         }
  241.  
  242.             }
  243.            
  244.             $db = pg_connect('host=10.0.11.64 dbname=call_linx_trans_db_backup user=call_linx password=');
  245.            
  246.     $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]'";
  247.  
  248.     $result2 = pg_query($query2);
  249.         if (!$result2) {
  250.             echo "Problem with query " . $query2 . "<br/>";
  251.             echo pg_last_error();
  252.             exit();
  253.         }
  254.        
  255. $row = pg_fetch_array($result2);
  256.  
  257. $Inbound = $row['inboundcount'];
  258.  
  259.  
  260. $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]'";
  261.  
  262. $avgcountresult = pg_query($avgcount);
  263.         if (!$avgcountresult) {
  264.             echo "Problem with query " . $avgcount . "<br/>";
  265.             echo pg_last_error();
  266.             exit();
  267.         }
  268.        
  269. $row = pg_fetch_array($avgcountresult);
  270.        
  271. $AvgHold = $row['avghold'];
  272.  
  273. $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)
  274. +(((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]'");
  275.  
  276. $result3 = pg_query($query3);
  277.         if (!$result3) {
  278.             echo "Problem with query " . $query3 . "<br/>";
  279.             echo pg_last_error();
  280.             exit();
  281.         }
  282.        
  283. $row1 = pg_fetch_array($result3);
  284.  
  285. $TotalMinutes = $row1['agenttime'];
  286.  
  287. $strMessage .= "<font size=\"3\"><br /><br />Total Calls: <strong>" . $Inbound . "</strong><br /> Total Minutes Used: <strong>" . $TotalMinutes .  "</strong><br /> Average Hold (seconds): <strong>" . $AvgHold .  "</strong><br /><br /><br /></font><br /><br />";  
  288.    
  289.    
  290.     $headers = 'MIME-Version: 1.0' . "\r\n";
  291.     $headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n";
  292.     $headers .= 'From: MAXIMUM Call Center <service@maximumcallcenter.com>' . "\r\n";
  293.     $subject = 'MAXIMUM Call Center - Call Report';
  294.    
  295.     // Sends email
  296.     mail( $recip, $subject, $strMessage, $headers );
  297.                                 }
  298.                                
  299.  
  300.                                 $date = date(D, d, l, yy)
  301.                        
  302.        
  303. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement