From 3d798b6049f1e2021668748edf307de3ada66385 Mon Sep 17 00:00:00 2001 From: mattf Date: Mon, 27 Feb 2012 20:43:00 +0000 Subject: [PATCH] Added SCRIPT_multirecording.php script that allows triggering of starting and stopping of recordings on demand within a script in a IFRAME git-svn-id: svn://192.168.202.10@1791 3d104415-ff17-0410-8863-d5cf3c621b8a --- agc_2-X/trunk/UPGRADE | 3 + .../trunk/www/agc/SCRIPT_multirecording.php | 135 +++++++++++++ .../www/agc/SCRIPT_multirecording_AJAX.php | 178 ++++++++++++++++++ 3 files changed, 316 insertions(+) create mode 100644 agc_2-X/trunk/www/agc/SCRIPT_multirecording.php create mode 100644 agc_2-X/trunk/www/agc/SCRIPT_multirecording_AJAX.php diff --git a/agc_2-X/trunk/UPGRADE b/agc_2-X/trunk/UPGRADE index 3b05d912..0383e945 100644 --- a/agc_2-X/trunk/UPGRADE +++ b/agc_2-X/trunk/UPGRADE @@ -822,6 +822,9 @@ OTHER CHANGES: 187. Added HTML bar chart display options to most of the reports. +188. Added SCRIPT_multirecording.php script that allows triggering of starting + and stopping of recordings on demand within a script in a IFRAME + diff --git a/agc_2-X/trunk/www/agc/SCRIPT_multirecording.php b/agc_2-X/trunk/www/agc/SCRIPT_multirecording.php new file mode 100644 index 00000000..ea327d32 --- /dev/null +++ b/agc_2-X/trunk/www/agc/SCRIPT_multirecording.php @@ -0,0 +1,135 @@ + LICENSE: AGPLv2 +# - works in conjunction with SCRIPT_multirecording_AJAX.php to allow reps the ability to make their own recordings over the course of a call while the entire call is being recorded into its own file, as in ALLFORCE recording. +# +# Implementation is done by creating a script in the Scripts section that calls this page within an +# +# All style parameters may be adjusted to suit your needs, but all variables listed in the above example MUST be passed to the VICI_multirecording.php page if this is implemented. +# Variables are: campaign, lead_id, phone_number, session_id, server_ip, user, vendor_lead_code, uniqueid +# +# CHANGELOG +# 120227-1512 - First Build +# + +require("dbconnect.php"); +if (isset($_GET["campaign"])) {$campaign=$_GET["campaign"];} + elseif (isset($_POST["campaign"])) {$campaign=$_POST["campaign"];} +if (isset($_GET["lead_id"])) {$lead_id=$_GET["lead_id"];} + elseif (isset($_POST["lead_id"])) {$lead_id=$_POST["lead_id"];} +if (isset($_GET["phone_number"])) {$phone_number=$_GET["phone_number"];} + elseif (isset($_POST["phone_number"])) {$phone_number=$_POST["phone_number"];} +if (isset($_GET["user"])) {$user=$_GET["user"];} + elseif (isset($_POST["user"])) {$user=$_POST["user"];} +if (isset($_GET["session_id"])) {$session_id=$_GET["session_id"];} + elseif (isset($_POST["session_id"])) {$session_id=$_POST["session_id"];} +if (isset($_GET["server_ip"])) {$server_ip=$_GET["server_ip"];} + elseif (isset($_POST["server_ip"])) {$server_ip=$_POST["server_ip"];} +if (isset($_GET["uniqueid"])) {$uniqueid=$_GET["uniqueid"];} + elseif (isset($_POST["uniqueid"])) {$uniqueid=$_POST["uniqueid"];} +if (isset($_GET["vendor_lead_code"])) {$vendor_lead_code=$_GET["vendor_lead_code"];} + elseif (isset($_POST["vendor_lead_code"])) {$vendor_lead_code=$_POST["vendor_lead_code"];} +?> + + + + +
+
+ + +, 'START')" value="START RECORDING"> + + +
+
+ + + diff --git a/agc_2-X/trunk/www/agc/SCRIPT_multirecording_AJAX.php b/agc_2-X/trunk/www/agc/SCRIPT_multirecording_AJAX.php new file mode 100644 index 00000000..522721d8 --- /dev/null +++ b/agc_2-X/trunk/www/agc/SCRIPT_multirecording_AJAX.php @@ -0,0 +1,178 @@ + LICENSE: AGPLv2 +# +# Other scripts that this application depends on: +# - SCRIPT_multirecording.php: Gives agents ability to stop and start recordings over a forced-recording (ALLFORCE) call +# +# CHANGELOG +# 120224-2240 - First Build +# + +require("dbconnect.php"); +if (isset($_GET["campaign"])) {$campaign=$_GET["campaign"];} + elseif (isset($_POST["campaign"])) {$campaign=$_POST["campaign"];} +if (isset($_GET["lead_id"])) {$lead_id=$_GET["lead_id"];} + elseif (isset($_POST["lead_id"])) {$lead_id=$_POST["lead_id"];} +if (isset($_GET["phone_number"])) {$phone_number=$_GET["phone_number"];} + elseif (isset($_POST["phone_number"])) {$phone_number=$_POST["phone_number"];} +if (isset($_GET["user"])) {$user=$_GET["user"];} + elseif (isset($_POST["user"])) {$user=$_POST["user"];} +if (isset($_GET["session_id"])) {$session_id=$_GET["session_id"];} + elseif (isset($_POST["session_id"])) {$session_id=$_POST["session_id"];} +if (isset($_GET["server_ip"])) {$server_ip=$_GET["server_ip"];} + elseif (isset($_POST["server_ip"])) {$server_ip=$_POST["server_ip"];} +if (isset($_GET["uniqueid"])) {$uniqueid=$_GET["uniqueid"];} + elseif (isset($_POST["uniqueid"])) {$uniqueid=$_POST["uniqueid"];} +if (isset($_GET["vendor_lead_code"])) {$vendor_lead_code=$_GET["vendor_lead_code"];} + elseif (isset($_POST["vendor_lead_code"])) {$vendor_lead_code=$_POST["vendor_lead_code"];} +if (isset($_GET["rec_action"])) {$rec_action=$_GET["rec_action"];} + elseif (isset($_POST["rec_action"])) {$rec_action=$_POST["rec_action"];} +if (isset($_GET["recording_channel"])) {$recording_channel=$_GET["recording_channel"];} + elseif (isset($_POST["recording_channel"])) {$recording_channel=$_POST["recording_channel"];} + +$StarTtime = date("U"); +$NOW_DATE = date("Y-m-d"); +$NOW_TIME = date("Y-m-d H:i:s"); +$NOWnum = date("YmdHis"); +$exten="8309"; +$ext_context="default"; +#if (eregi("^10.10.", $server_ip)) {$ext_context="demo";} else {$ext_content="default";} + +$stmt="select campaign_rec_filename from vicidial_campaigns where campaign_id='$campaign'"; +$rslt=mysql_query($stmt, $link); +$row=mysql_fetch_array($rslt); +$filename=$row["campaign_rec_filename"]; +$filename=eregi_replace("CAMPAIGN", $campaign, $filename); +$filename=eregi_replace("CUSTPHONE", $phone_number, $filename); +$filename=eregi_replace("FULLDATE", date("Ymd-His"), $filename); +$filename=eregi_replace("TINYDATE", (date("Y")-2000).date("mdHis"), $filename); +$filename=eregi_replace("AGENT", $user, $filename); +$filename=eregi_replace("EPOCH", $StarTtime, $filename); +$filename=eregi_replace("VENDORLEADCODE", $vendor_lead_code, $filename); +$filename=eregi_replace("LEADID", $lead_id, $filename); + +$channel="Local/5".$session_id."@".$ext_context; +$ext_priority=1; +$one_mysql_log=0; +$row=''; $rowx=''; +$channel_live=1; + +if ($rec_action=="START") + { + + if ( (strlen($exten)<3) or (strlen($channel)<4) or (strlen($filename)<15)) { + $channel_live=0; + echo "ERROR 1"; + } else { + ######################## START RECORDING ########################## + + $stmt="SELECT channel FROM live_sip_channels where server_ip = '$server_ip' and channel LIKE \"$channel%\" and channel LIKE \"%,1\";"; + $rslt=mysql_query($stmt, $link); + $channel_SQL=" and channel not in ("; + while($row=mysql_fetch_array($rslt)) + { + $channel_SQL.="'$row[channel]',"; + } + $channel_SQL=substr($channel_SQL,0,-1); + $channel_SQL.=")"; + + + + $VDvicidial_id=''; + $stmt="INSERT INTO vicidial_manager values('','','$NOW_TIME','NEW','N','$server_ip','','Originate','$filename','Channel: $channel','Context: $ext_context','Exten: $exten','Priority: $ext_priority','Callerid: $filename','','','','','');"; + $rslt=mysql_query($stmt, $link); + + $stmt = "INSERT INTO recording_log (channel,server_ip,extension,start_time,start_epoch,filename,lead_id,user) values('$channel','$server_ip','$exten','$NOW_TIME','$StarTtime','$filename','$lead_id','$user')"; + $rslt=mysql_query($stmt, $link); + $RLaffected_rows = mysql_affected_rows($link); + if ($RLaffected_rows > 0) { + usleep(2000000); + $recording_id = mysql_insert_id($link); + $current_rec_filename=$filename; + $channel_stmt="SELECT channel FROM live_sip_channels where server_ip = '$server_ip' and channel LIKE \"$channel%\" and channel LIKE \"%,1\" $channel_SQL;"; + $channel_rslt=mysql_query($channel_stmt, $link); + if (mysql_num_rows($channel_rslt)==1) + { + $channel_row=mysql_fetch_row($channel_rslt); + echo "$recording_id|$channel_row[0]"; + } + else + { + echo "Error 2\n$channel_stmt\n".mysql_num_rows($channel_rslt); + } + } else { + echo "Error 3"; + } + + ##### get call type from vicidial_live_agents table + $VLA_inOUT='NONE'; + $stmt="SELECT comments FROM vicidial_live_agents where user='$user' order by last_update_time desc limit 1;"; + $rslt=mysql_query($stmt, $link); + $VLA_inOUT_ct = mysql_num_rows($rslt); + if ($VLA_inOUT_ct > 0) { + $row=mysql_fetch_row($rslt); + $VLA_inOUT = $row[0]; + } + if ($VLA_inOUT == 'INBOUND') { + $four_hours_ago = date("Y-m-d H:i:s", mktime(date("H")-4,date("i"),date("s"),date("m"),date("d"),date("Y"))); + + ##### look for the vicidial ID in the vicidial_closer_log table + $stmt="SELECT closecallid FROM vicidial_closer_log where lead_id='$lead_id' and user='$user' and call_date > \"$four_hours_ago\" order by closecallid desc limit 1;"; + } else { + ##### look for the vicidial ID in the vicidial_log table + $stmt="SELECT uniqueid FROM vicidial_log where uniqueid='$uniqueid' and lead_id='$lead_id';"; + } +/* + $rslt=mysql_query($stmt, $link); + $VM_mancall_ct = mysql_num_rows($rslt); + if ($VM_mancall_ct > 0) { + $row=mysql_fetch_row($rslt); + $VDvicidial_id = $row[0]; + $stmt = "UPDATE recording_log SET vicidial_id='$VDvicidial_id' where recording_id='$recording_id';"; + $rslt=mysql_query($stmt, $link); + } +*/ + } + + } +else + { +############### STOP RECORDING ######## + $stmt="SELECT recording_id,start_epoch FROM recording_log where recording_id='$rec_action' and end_epoch is null"; + $rslt=mysql_query($stmt, $link); + $rec_count = mysql_num_rows($rslt); + if ($rec_count>0) { + $row=mysql_fetch_row($rslt); + $recording_id = $row[0]; + $start_time = $row[1]; + $length_in_sec = ($StarTtime - $start_time); + $length_in_min = ($length_in_sec / 60); + $length_in_min = sprintf("%8.2f", $length_in_min); + + $stmt = "UPDATE recording_log set end_time='$NOW_TIME',end_epoch='$StarTtime',length_in_sec=$length_in_sec,length_in_min='$length_in_min' where recording_id='$rec_action'"; + $rslt=mysql_query($stmt, $link); + } + + # find and hang up the recording + $stmt="SELECT channel FROM live_sip_channels where server_ip = '$server_ip' and channel LIKE \"$recording_channel%\" and channel LIKE \"%,1\";"; + $rslt=mysql_query($stmt, $link); + $rec_count = mysql_num_rows($rslt); + $h=0; + while ($rec_count>$h) { + $rowx=mysql_fetch_row($rslt); + $HUchannel[$h] = $rowx[0]; + $h++; + } + $i=0; + while ($h>$i) { + $stmt="INSERT INTO vicidial_manager values('','','$NOW_TIME','NEW','N','$server_ip','','Hangup','RH12345$StarTtime$i','Channel: $HUchannel[$i]','','','','','','','','','');"; + $rslt=mysql_query($stmt, $link); + $i++; + echo "HANGUP SUCCESSFUL"; + } + + } +###################################### +?>