📜 ⬆️ ⬇️

Report on missed calls per day

It took a script for one of the clients to notify the mail of calls missed during the day. Perhaps he is not very tricky, but I think others can come in handy. The query selects data on unanswered incoming calls for yesterday. Such information is quite relevant to many organizations, because if customers do not get through to them, they can get through to others. Asterisk 1.6 , MySQL DBMS is installed on the server.

Here is the script itself:
<?php /*       */ $hostname = "localhost"; $username = "dbuser"; $password = "dbpass"; $dbName = "dbname"; /*  MySQL,     */ $cdrtable = "cdr"; /*      */ $time = mktime(date('H'), date('i'), date('s'), date('m'), date('d')-1, date('Y')); $ydate = date("dmY", $time); /*   */ mysql_connect($hostname,$username,$password) OR DIE("    "); /*   .    -   */ mysql_select_db($dbName) or die(mysql_error()); /*   .    ,  LENGTH( `src` ) >3,    */ $query = "SELECT `dst` , `src` , `duration` , `dstchannel` , `calldate` FROM `cdr` WHERE DATE_SUB( CURDATE( ) , INTERVAL 1 DAY ) <= `calldate` AND CURDATE( ) > `calldate` AND `disposition` = 'NO ANSWER' AND LENGTH( `src` ) >3"; /*  .    -  . */ $res=mysql_query($query) or die(mysql_error()); /*     */ $number = mysql_num_rows($res); /*   */ $mes="     $ydate.\r\n\r\n"; /*   */ if ($number == 0) { $mes .= "   "; } else { /*         $row,     */ while ($row=mysql_fetch_array($res)) { $mes .= " ".$row['calldate'].".  ".$row['src']; $mes .= "  ".mb_substr($row['dstchannel'],4,3); $mes .= ".  ".$row['duration']." .\r\n"; } } /*   */ mail('admin@mail.domain', $ydate.' report', $mes); ?> 


I tried to comment in sufficient detail, if something does not work, ask.

Sample letter:
')
Report on missed calls for 10/29/2012.

2012-10-29 11:46:38. From 4959819231 Subscriber 109. Waiting 45 seconds.
2012-10-29 13:18:45. From 4956103380 Subscriber 104. Waiting 47 seconds.
2012-10-29 14:33:13. From 4959819331 Subscriber 104. Waiting 53 seconds.
2012-10-29 16:58:40. From 9030293453 Subscriber 101. Wait 12 sec.

Source: https://habr.com/ru/post/156751/


All Articles