From fda420c673f94c0520545c6028b2d506d387304b Mon Sep 17 00:00:00 2001 From: mattf Date: Fri, 24 Oct 2008 05:41:14 +0000 Subject: [PATCH] several small changes to the ALL_inbound AGI script altered the AST_CLOSERstats.php to allow for selection of multiple in-groups in report git-svn-id: svn://192.168.202.10@988 3d104415-ff17-0410-8863-d5cf3c621b8a --- agi/agi-VDAD_ALL_inbound.agi | 202 ++++++++++++++++++------------- www/vicidial/AST_CLOSERstats.php | 172 +++++++++++++++++++++----- 2 files changed, 258 insertions(+), 116 deletions(-) diff --git a/agi/agi-VDAD_ALL_inbound.agi b/agi/agi-VDAD_ALL_inbound.agi index 81191fd0..305e3a34 100644 --- a/agi/agi-VDAD_ALL_inbound.agi +++ b/agi/agi-VDAD_ALL_inbound.agi @@ -86,6 +86,7 @@ # 81011-1019 - Added option for press 1 to leave voicemail if wait time > hold-time-option-seconds # 81020-0237 - Added term_reason logging for all possible exits of the script # 81021-2315 - Changed and add queue_log logging +# 81024-0006 - Changed LOOKUP to insert new lead if phone_number < 3 digits, changed queue_sec calculation # $script = 'agi-VDAD_ALL_inbound.agi'; @@ -109,6 +110,7 @@ $hm = "$hour$min"; $hm = ($hm + 0); $now_date_epoch = time(); +$start_epoch = $now_date_epoch; $now_date = "$year-$mon-$mday $hour:$min:$sec"; $CLInow_date = "$year-$mon-$mday\\ $hour:$min:$sec"; $start_time=$now_date; @@ -509,55 +511,8 @@ if ($call_handle_method =~ /DIGITID$/) if ($call_handle_method =~ /LOOKUP/) { - $listSQL = ''; - if ($call_handle_method =~ /LOOKUPRL$/) - {$listSQL = "and list_id='$list_id'";} - else + if (length($phone_number) < 3) { - if ($call_handle_method =~ /LOOKUPRC$/) - { - ### Grab all lists associated with Scampaign_id - $cbc=0; - $SlistsSQL=''; - $stmtA = "SELECT list_id FROM vicidial_lists where campaign_id='$Scampaign_id' limit 100;"; - $sthA = $dbhA->prepare($stmtA) or die "preparing: ",$dbhA->errstr; - $sthA->execute or die "executing: $stmtA ", $dbhA->errstr; - $sthArows=$sthA->rows; - while ($sthArows > $cbc) - { - @aryA = $sthA->fetchrow_array; - $SlistsSQL .= "'$aryA[0]',"; - $cbc++; - } - $sthA->finish(); - chop($SlistsSQL); - - if (length($SlistsSQL)>3) - {$listSQL = "and list_id IN($SlistsSQL)";} - } - } - - $cbc=0; - $stmtA= "SELECT lead_id from vicidial_list where phone_number='$phone_number' $listSQL order by last_local_call_time desc limit 1;"; - if ($AGILOG) {$agi_string = "VDAD vicidial_list search |$phone_number|$stmtA|"; &agi_output;} - $sthA = $dbhA->prepare($stmtA) or die "preparing: ",$dbhA->errstr; - $sthA->execute or die "executing: $stmtA ", $dbhA->errstr; - $sthArows=$sthA->rows; - if ($sthArows > 0) - { - $rec_countCUSTDATA=0; - while ($sthArows > $cbc) - { - @aryA = $sthA->fetchrow_array; - $insert_lead_id = "$aryA[0]"; - $cbc++; - } - $sthA->finish(); - - if ($AGILOG) {$agi_string = "VDAD vicidial_list found |$insert_lead_id|$stmtA|"; &agi_output;} - } - else - { ### insert a record into the vicidial_list table $stmtA = "INSERT INTO vicidial_list (entry_date,modify_date,status,user,vendor_lead_code,source_id,list_id,called_since_last_reset,phone_code,phone_number,security_phrase,called_count,gmt_offset_now,comments) values('$SQLdate','$tsSQLdate','INBND','$fronter','$inbound_number','VDCL','$list_id','Y','$phone_code','$phone_number','$channel_group','1','$local_gmt','$VLcomments');"; $affected_rows = $dbhA->do($stmtA); @@ -575,7 +530,77 @@ if ($call_handle_method =~ /LOOKUP/) $sthA->finish(); if ($AGILOG) {$agi_string = "VDAD vicidial_list insert |$insert_lead_id|$stmtA|"; &agi_output;} - } + } + else + { + $listSQL = ''; + if ($call_handle_method =~ /LOOKUPRL$/) + {$listSQL = "and list_id='$list_id'";} + else + { + if ($call_handle_method =~ /LOOKUPRC$/) + { + ### Grab all lists associated with Scampaign_id + $cbc=0; + $SlistsSQL=''; + $stmtA = "SELECT list_id FROM vicidial_lists where campaign_id='$Scampaign_id' limit 100;"; + $sthA = $dbhA->prepare($stmtA) or die "preparing: ",$dbhA->errstr; + $sthA->execute or die "executing: $stmtA ", $dbhA->errstr; + $sthArows=$sthA->rows; + while ($sthArows > $cbc) + { + @aryA = $sthA->fetchrow_array; + $SlistsSQL .= "'$aryA[0]',"; + $cbc++; + } + $sthA->finish(); + chop($SlistsSQL); + + if (length($SlistsSQL)>3) + {$listSQL = "and list_id IN($SlistsSQL)";} + } + } + + $cbc=0; + $stmtA= "SELECT lead_id from vicidial_list where phone_number='$phone_number' $listSQL order by last_local_call_time desc limit 1;"; + if ($AGILOG) {$agi_string = "VDAD vicidial_list search |$phone_number|$stmtA|"; &agi_output;} + $sthA = $dbhA->prepare($stmtA) or die "preparing: ",$dbhA->errstr; + $sthA->execute or die "executing: $stmtA ", $dbhA->errstr; + $sthArows=$sthA->rows; + if ($sthArows > 0) + { + $rec_countCUSTDATA=0; + while ($sthArows > $cbc) + { + @aryA = $sthA->fetchrow_array; + $insert_lead_id = "$aryA[0]"; + $cbc++; + } + $sthA->finish(); + + if ($AGILOG) {$agi_string = "VDAD vicidial_list found |$insert_lead_id|$stmtA|"; &agi_output;} + } + else + { + ### insert a record into the vicidial_list table + $stmtA = "INSERT INTO vicidial_list (entry_date,modify_date,status,user,vendor_lead_code,source_id,list_id,called_since_last_reset,phone_code,phone_number,security_phrase,called_count,gmt_offset_now,comments) values('$SQLdate','$tsSQLdate','INBND','$fronter','$inbound_number','VDCL','$list_id','Y','$phone_code','$phone_number','$channel_group','1','$local_gmt','$VLcomments');"; + $affected_rows = $dbhA->do($stmtA); + $cbc=0; + $stmtB = "select LAST_INSERT_ID() LIMIT 1;"; + $sthA = $dbhA->prepare($stmtB) or die "preparing: ",$dbhA->errstr; + $sthA->execute or die "executing: $stmtA ", $dbhA->errstr; + $sthArows=$sthA->rows; + while ($sthArows > $cbc) + { + @aryA = $sthA->fetchrow_array; + $insert_lead_id = "$aryA[0]"; + $cbc++; + } + $sthA->finish(); + + if ($AGILOG) {$agi_string = "VDAD vicidial_list insert |$insert_lead_id|$stmtA|"; &agi_output;} + } + } } else @@ -628,6 +653,29 @@ if ( ($hm < $ct_default_start) || ($hm > $ct_default_stop) ) { $VHqueryCID = "VA$CIDdate$hour$min$sec$sec"; + $stmtA = "INSERT INTO vicidial_closer_log set status='DROP',start_epoch='$now_date_epoch',end_epoch='$now_date_epoch',length_in_sec='1',queue_seconds='0',lead_id = '$insert_lead_id',campaign_id='$channel_group',user='VDCL',list_id='$list_id',call_date='$now_date',phone_code='$phone_code',phone_number='$phone_number',comments='AFTER HOURS DROP',term_reason='AFTERHOURS';"; + $affected_rows = $dbhA->do($stmtA); + $stmtB = "select LAST_INSERT_ID() LIMIT 1;"; + $sthA = $dbhA->prepare($stmtB) or die "preparing: ",$dbhA->errstr; + $sthA->execute or die "executing: $stmtB ", $dbhA->errstr; + $sthArows=$sthA->rows; + if ($sthArows > 0) + { + @aryA = $sthA->fetchrow_array; + $insert_close_id = "$aryA[0]"; + $cbc++; + } + $sthA->finish(); + if ($AGILOG) {$agi_string = "-- VDCL vcl insert: |$affected_rows|$insert_lead_id|$insert_close_id|\n|$stmtA|"; &agi_output;} + + $stmtA = "UPDATE vicidial_list set status='DROP' where lead_id = '$insert_lead_id';"; + $affected_rows = $dbhA->do($stmtA); + if ($AGILOG) {$agi_string = "-- VDCL vl update: |$affected_rows|$insert_lead_id|\n|$stmtA|"; &agi_output;} + + $stmtA = "DELETE FROM vicidial_auto_calls where callerid='$callerid' and server_ip='$VARserver_ip' order by call_time desc limit 1;"; + $affected_rows = $dbhA->do($stmtA); + if ($AGILOG) {$agi_string = "-- VDCL vac record deleted: |$affected_rows| $VDADcampaign|"; &agi_output;} + if ($after_hours_action =~ /EXTENSION|VOICEMAIL|IN_GROUP/) { if ($after_hours_action =~ /EXTENSION/) @@ -661,28 +709,6 @@ if ( ($hm < $ct_default_start) || ($hm > $ct_default_stop) ) checkresult($result); } } - $stmtA = "DELETE FROM vicidial_auto_calls where callerid='$callerid' and server_ip='$VARserver_ip' order by call_time desc limit 1;"; - $affected_rows = $dbhA->do($stmtA); - if ($AGILOG) {$agi_string = "-- VDCL vac record deleted: |$affected_rows| $VDADcampaign|"; &agi_output;} - - $stmtA = "INSERT INTO vicidial_closer_log set status='DROP',start_epoch='$now_date_epoch',end_epoch='$now_date_epoch',length_in_sec='1',queue_seconds='0',lead_id = '$insert_lead_id',campaign_id='$channel_group',user='VDCL',list_id='$list_id',call_date='$now_date',phone_code='$phone_code',phone_number='$phone_number',comments='AFTER HOURS DROP',term_reason='AFTERHOURS';"; - $affected_rows = $dbhA->do($stmtA); - $stmtB = "select LAST_INSERT_ID() LIMIT 1;"; - $sthA = $dbhA->prepare($stmtB) or die "preparing: ",$dbhA->errstr; - $sthA->execute or die "executing: $stmtB ", $dbhA->errstr; - $sthArows=$sthA->rows; - if ($sthArows > 0) - { - @aryA = $sthA->fetchrow_array; - $insert_close_id = "$aryA[0]"; - $cbc++; - } - $sthA->finish(); - if ($AGILOG) {$agi_string = "-- VDCL vcl insert: |$affected_rows|$insert_lead_id|$insert_close_id|\n|$stmtA|"; &agi_output;} - - $stmtA = "UPDATE vicidial_list set status='DROP' where lead_id = '$insert_lead_id';"; - $affected_rows = $dbhA->do($stmtA); - if ($AGILOG) {$agi_string = "-- VDCL vl update: |$affected_rows|$insert_lead_id|\n|$stmtA|"; &agi_output;} if ($after_hours_action =~ /HANGUP/) { @@ -2010,7 +2036,9 @@ if ($wait_in_queue > 0) ### sleep for 99 hundredths of a second usleep(1*990*1000); - $drop_timer++; + # $drop_timer++; + $NOWsec = time(); + $drop_timer = ($NOWsec - $start_epoch); } } @@ -2022,8 +2050,10 @@ if ($affected_rows < 1) $affected_rows = $dbhA->do($stmtA); if ($AGILOG) {$agi_string = "$affected_rows|VDAC-reinsert|$stmtA|"; &agi_output;} } -#if ($AGILOG) {$agi_string = "-- VDAD : |$affected_rows|update of vac table: $callerid\n|$stmtA|"; &agi_output;} - +else + { +# if ($AGILOG) {$agi_string = "-- VDAD : |$affected_rows|update vac table: $callerid\n|$stmtA|$drop_timer ($NOWsec - $start_epoch)|"; &agi_output;} + } } ############################################ @@ -2093,6 +2123,18 @@ if ($drop_action =~ /IN_GROUP/) if ($AGILOG) {$agi_string = "-- VDCL DROP: |$drop_action|$DROPexten|"; &agi_output;} + $stmtA = "DELETE FROM vicidial_auto_calls where callerid='$callerid' and server_ip='$VARserver_ip' order by call_time desc limit 1;"; + $affected_rows = $dbhA->do($stmtA); + if ($AGILOG) {$agi_string = "-- VDCL vac record deleted: |$affected_rows| $VDADcampaign|"; &agi_output;} + + $stmtA = "UPDATE vicidial_closer_log set status='DROP',end_epoch='$now_date_epoch',length_in_sec='$drop_seconds',queue_seconds='$drop_seconds',term_reason='QUEUETIMEOUT' where lead_id = '$insert_lead_id' order by start_epoch desc limit 1;"; + $affected_rows = $dbhA->do($stmtA); + if ($AGILOG) {$agi_string = "-- VDCL vcl update: |$affected_rows|$insert_lead_id|\n|$stmtA|"; &agi_output;} + + $stmtA = "UPDATE vicidial_list set status='XDROP' where lead_id = '$insert_lead_id';"; + $affected_rows = $dbhA->do($stmtA); + if ($AGILOG) {$agi_string = "-- VDCL vl update: |$affected_rows|$insert_lead_id|\n|$stmtA|"; &agi_output;} + ### use STDOUT to send call to proper DROP location $VHqueryCID = "VH$CIDdate$VDADconf_exten"; @@ -2120,18 +2162,6 @@ if ($AGILOG) {$agi_string = "-- VDCL DROP: |$drop_action|$DROPexten|"; &agi $affected_rows = $dbhA->do($stmtA); if ($AGILOG) {$agi_string = "-- VDCL call_hungup timeout: |$VHqueryCID|$VDADconf_exten|$channel|insert to vicidial_manager"; &agi_output;} } - - $stmtA = "DELETE FROM vicidial_auto_calls where callerid='$callerid' and server_ip='$VARserver_ip' order by call_time desc limit 1;"; - $affected_rows = $dbhA->do($stmtA); - if ($AGILOG) {$agi_string = "-- VDCL vac record deleted: |$affected_rows| $VDADcampaign|"; &agi_output;} - - $stmtA = "UPDATE vicidial_closer_log set status='DROP',end_epoch='$now_date_epoch',length_in_sec='$drop_seconds',queue_seconds='$drop_seconds',term_reason='QUEUETIMEOUT' where lead_id = '$insert_lead_id' order by start_epoch desc limit 1;"; - $affected_rows = $dbhA->do($stmtA); - if ($AGILOG) {$agi_string = "-- VDCL vcl update: |$affected_rows|$insert_lead_id|\n|$stmtA|"; &agi_output;} - - $stmtA = "UPDATE vicidial_list set status='XDROP' where lead_id = '$insert_lead_id';"; - $affected_rows = $dbhA->do($stmtA); - if ($AGILOG) {$agi_string = "-- VDCL vl update: |$affected_rows|$insert_lead_id|\n|$stmtA|"; &agi_output;} } $dbhA->disconnect(); diff --git a/www/vicidial/AST_CLOSERstats.php b/www/vicidial/AST_CLOSERstats.php index 03765e4f..dc6d98db 100644 --- a/www/vicidial/AST_CLOSERstats.php +++ b/www/vicidial/AST_CLOSERstats.php @@ -15,6 +15,7 @@ # 80709-0331 - Added time stats to call statuses # 80722-2149 - Added Status Category stats # 81015-0705 - Added IVR calls count +# 81024-0037 - Added multi-select inbound-groups # require("dbconnect.php"); @@ -26,14 +27,16 @@ if (isset($_GET["group"])) {$group=$_GET["group"];} elseif (isset($_POST["group"])) {$group=$_POST["group"];} if (isset($_GET["query_date"])) {$query_date=$_GET["query_date"];} elseif (isset($_POST["query_date"])) {$query_date=$_POST["query_date"];} -if (isset($_GET["end_date"])) {$end_date=$_GET["end_date"];} - elseif (isset($_POST["end_date"])) {$end_date=$_POST["end_date"];} +if (isset($_GET["end_date"])) {$end_date=$_GET["end_date"];} + elseif (isset($_POST["end_date"])) {$end_date=$_POST["end_date"];} if (isset($_GET["shift"])) {$shift=$_GET["shift"];} elseif (isset($_POST["shift"])) {$shift=$_POST["shift"];} if (isset($_GET["submit"])) {$submit=$_GET["submit"];} - elseif (isset($_POST["submit"])) {$submit=$_POST["submit"];} + elseif (isset($_POST["submit"])) {$submit=$_POST["submit"];} if (isset($_GET["SUBMIT"])) {$SUBMIT=$_GET["SUBMIT"];} - elseif (isset($_POST["SUBMIT"])) {$SUBMIT=$_POST["SUBMIT"];} + elseif (isset($_POST["SUBMIT"])) {$SUBMIT=$_POST["SUBMIT"];} +if (isset($_GET["DB"])) {$DB=$_GET["DB"];} + elseif (isset($_POST["DB"])) {$DB=$_POST["DB"];} $PHP_AUTH_USER = ereg_replace("[^0-9a-zA-Z]","",$PHP_AUTH_USER); $PHP_AUTH_PW = ereg_replace("[^0-9a-zA-Z]","",$PHP_AUTH_PW); @@ -84,13 +87,37 @@ $rslt=mysql_query($stmt, $link); if ($DB) {echo "$stmt\n";} $groups_to_print = mysql_num_rows($rslt); $i=0; + $LISTgroups[$i]='---NONE---'; + $i++; + $groups_to_print++; while ($i < $groups_to_print) { $row=mysql_fetch_row($rslt); - $groups[$i] =$row[0]; + $LISTgroups[$i] =$row[0]; $i++; } +$i=0; +$group_string='|'; +$group_ct = count($group); +while($i < $group_ct) + { + $group_string .= "$group[$i]|"; + $group_SQL .= "'$group[$i]',"; + $i++; + } +if ( (ereg("--NONE--",$group_string) ) or ($group_ct < 1) ) + { + $group_SQL = "''"; +# $group_SQL = "group_id IN('')"; + } +else + { + $group_SQL = eregi_replace(",$",'',$group_SQL); +# $group_SQL = "group_id IN($group_SQL)"; + } + + $stmt="select vsc_id,vsc_name from vicidial_status_categories;"; $rslt=mysql_query($stmt, $link); if ($DB) {echo "$stmt\n";} @@ -120,33 +147,65 @@ while ($i < $statcats_to_print) \n"; echo "VICIDIAL: VDAD Closer Stats\n"; +if ($DB > 0) + { + echo "
\n"; + echo "$group_ct|$group_string|$group_SQL\n"; + echo "
\n"; + echo "$shift|$query_date|$end_date\n"; + echo "
\n"; + } + echo "
\n"; +echo "\n"; +echo "
\n"; +echo "\n"; +echo "Date Range:
\n"; echo "\n"; echo " to \n"; -echo "
\n"; +echo "Inbound Groups: \n"; +echo "\n"; +echo "\n"; -echo "\n"; +echo "           MODIFY | REPORTS \n"; + +echo "
\n"; + +#echo "\n"; +echo "Shift: \n"; -echo "\n"; -echo "           MODIFY | REPORTS \n"; +echo "   \n"; +echo "
\n"; echo "
\n\n"; echo "
\n\n";
 
 
-if (!$group)
+if ($groups_to_print < 1)
 {
 echo "\n\n";
 echo "PLEASE SELECT AN IN-GROUP AND DATE RANGE ABOVE AND CLICK SUBMIT\n";
@@ -178,18 +237,71 @@ $query_date_END = "$end_date $time_END";
 
 
 
-echo "VICIDIAL: Auto-dial Closer Stats                      $NOW_TIME\n";
+echo "VICIDIAL: Auto-dial Closer Stats: $group_string          $NOW_TIME\n";
+
+
+
+
+
+
+if ($group_ct > 1)
+	{
+	echo "\n";
+	echo "---------- MULTI-GROUP BREAKDOWN:\n";
+	echo "+----------------------+---------+---------+---------+---------+\n";
+	echo "| IN-GROUP             | CALLS   | DROPS   | DROP %  | IVR     |\n";
+	echo "+----------------------+---------+---------+---------+---------+\n";
+
+	$i=0;
+	while($i < $group_ct)
+		{
+		$stmt="select count(*),sum(length_in_sec) from vicidial_closer_log where call_date >= '$query_date_BEGIN' and call_date <= '$query_date_END' and campaign_id='$group[$i]';";
+		$rslt=mysql_query($stmt, $link);
+		if ($DB) {echo "$stmt\n";}
+		$row=mysql_fetch_row($rslt);
+
+		$stmt="select count(*) from live_inbound_log where start_time >= '$query_date_BEGIN' and start_time <= '$query_date_END' and comment_a='$group[$i]' and comment_b='START';";
+		$rslt=mysql_query($stmt, $link);
+		if ($DB) {echo "$stmt\n";}
+		$rowx=mysql_fetch_row($rslt);
+
+		$stmt="select count(*),sum(length_in_sec) from vicidial_closer_log where call_date >= '$query_date_BEGIN' and call_date <= '$query_date_END' and campaign_id='$group[$i]' and status IN('DROP','XDROP') and (length_in_sec <= 9999 or length_in_sec is null);";
+		$rslt=mysql_query($stmt, $link);
+		if ($DB) {echo "$stmt\n";}
+		$rowy=mysql_fetch_row($rslt);
+
+		$groupDISPLAY =	sprintf("%20s", $group[$i]);
+		$gTOTALcalls =	sprintf("%7s", $row[0]);
+		$gIVRcalls =	sprintf("%7s", $rowx[0]);
+		$gDROPcalls =	sprintf("%7s", $rowy[0]);
+		if ( ($gDROPcalls < 1) or ($gTOTALcalls < 1) )
+			{$gDROPpercent = '0';}
+		else
+			{
+			$gDROPpercent = (($gDROPcalls / $gTOTALcalls) * 100);
+			$gDROPpercent = round($gDROPpercent, 2);
+			}
+		$gDROPpercent =	sprintf("%6s", $gDROPpercent);
+
+		echo "| $groupDISPLAY | $gTOTALcalls | $gDROPcalls | $gDROPpercent% | $gIVRcalls |\n";
+		$i++;
+		}
+
+	echo "+----------------------+---------+---------+---------+---------+\n";
+
+	}
+
 
 echo "\n";
 echo "Time range: $query_date_BEGIN to $query_date_END\n\n";
 echo "---------- TOTALS\n";
 
-$stmt="select count(*),sum(length_in_sec) from vicidial_closer_log where call_date >= '$query_date_BEGIN' and call_date <= '$query_date_END' and campaign_id='" . mysql_real_escape_string($group) . "';";
+$stmt="select count(*),sum(length_in_sec) from vicidial_closer_log where call_date >= '$query_date_BEGIN' and call_date <= '$query_date_END' and campaign_id IN($group_SQL);";
 $rslt=mysql_query($stmt, $link);
 if ($DB) {echo "$stmt\n";}
 $row=mysql_fetch_row($rslt);
 
-$stmt="select count(*) from live_inbound_log where start_time >= '$query_date_BEGIN' and start_time <= '$query_date_END' and comment_a='" . mysql_real_escape_string($group) . "' and comment_b='START';";
+$stmt="select count(*) from live_inbound_log where start_time >= '$query_date_BEGIN' and start_time <= '$query_date_END' and comment_a IN($group_SQL) and comment_b='START';";
 $rslt=mysql_query($stmt, $link);
 if ($DB) {echo "$stmt\n";}
 $rowx=mysql_fetch_row($rslt);
@@ -213,7 +325,7 @@ echo "Calls taken into the IVR for this In-Group:   $IVRcalls\n";
 echo "\n";
 echo "---------- DROPS\n";
 
-$stmt="select count(*),sum(length_in_sec) from vicidial_closer_log where call_date >= '$query_date_BEGIN' and call_date <= '$query_date_END' and campaign_id='" . mysql_real_escape_string($group) . "' and status='DROP' and (length_in_sec <= 999 or length_in_sec is null);";
+$stmt="select count(*),sum(length_in_sec) from vicidial_closer_log where call_date >= '$query_date_BEGIN' and call_date <= '$query_date_END' and campaign_id IN($group_SQL) and status IN('DROP','XDROP') and (length_in_sec <= 9999 or length_in_sec is null);";
 $rslt=mysql_query($stmt, $link);
 if ($DB) {echo "$stmt\n";}
 $row=mysql_fetch_row($rslt);
@@ -284,7 +396,7 @@ while ($p < $statuses_to_print)
 echo "\n";
 echo "---------- QUEUE STATS\n";
 
-$stmt="select count(*),sum(queue_seconds) from vicidial_closer_log where call_date >= '$query_date_BEGIN' and call_date <= '$query_date_END' and campaign_id='" . mysql_real_escape_string($group) . "' and (queue_seconds > 0);";
+$stmt="select count(*),sum(queue_seconds) from vicidial_closer_log where call_date >= '$query_date_BEGIN' and call_date <= '$query_date_END' and campaign_id IN($group_SQL) and (queue_seconds > 0);";
 $rslt=mysql_query($stmt, $link);
 if ($DB) {echo "$stmt\n";}
 $row=mysql_fetch_row($rslt);
@@ -333,7 +445,7 @@ echo "+-------------------------------------------------------------------------
 echo "|     0     5    10    15    20    25    30    35    40    45    50    55    60    90   +90 | TOTAL      |\n";
 echo "+-------------------------------------------------------------------------------------------+------------+\n";
 
-$stmt="select count(*),queue_seconds from vicidial_closer_log where call_date >= '$query_date_BEGIN' and call_date <= '$query_date_END' and  campaign_id='" . mysql_real_escape_string($group) . "' group by queue_seconds;";
+$stmt="select count(*),queue_seconds from vicidial_closer_log where call_date >= '$query_date_BEGIN' and call_date <= '$query_date_END' and  campaign_id IN($group_SQL) group by queue_seconds;";
 $rslt=mysql_query($stmt, $link);
 if ($DB) {echo "$stmt\n";}
 $reasons_to_print = mysql_num_rows($rslt);
@@ -396,7 +508,7 @@ echo "+----------------------+------------+\n";
 echo "| HANGUP REASON        | CALLS      |\n";
 echo "+----------------------+------------+\n";
 
-$stmt="select count(*),term_reason from vicidial_closer_log where call_date >= '$query_date_BEGIN' and call_date <= '$query_date_END' and  campaign_id='" . mysql_real_escape_string($group) . "' group by term_reason;";
+$stmt="select count(*),term_reason from vicidial_closer_log where call_date >= '$query_date_BEGIN' and call_date <= '$query_date_END' and  campaign_id IN($group_SQL) group by term_reason;";
 $rslt=mysql_query($stmt, $link);
 if ($DB) {echo "$stmt\n";}
 $reasons_to_print = mysql_num_rows($rslt);
@@ -438,7 +550,7 @@ echo "+--------+----------------------+----------------------+------------+-----
 
 
 ## get counts and time totals for all statuses in this campaign
-$stmt="select count(*),status,sum(length_in_sec) from vicidial_closer_log where call_date >= '$query_date_BEGIN' and call_date <= '$query_date_END' and  campaign_id='" . mysql_real_escape_string($group) . "' group by status;";
+$stmt="select count(*),status,sum(length_in_sec) from vicidial_closer_log where call_date >= '$query_date_BEGIN' and call_date <= '$query_date_END' and  campaign_id IN($group_SQL) group by status;";
 $rslt=mysql_query($stmt, $link);
 if ($DB) {echo "$stmt\n";}
 $statuses_to_print = mysql_num_rows($rslt);
@@ -620,7 +732,7 @@ echo "+--------------------------+------------+----------+--------+\n";
 echo "| AGENT                    | CALLS      | TIME M   | AVRG M |\n";
 echo "+--------------------------+------------+----------+--------+\n";
 
-$stmt="select vicidial_closer_log.user,full_name,count(*),sum(length_in_sec),avg(length_in_sec) from vicidial_closer_log,vicidial_users where call_date >= '$query_date_BEGIN' and call_date <= '$query_date_END' and  campaign_id='" . mysql_real_escape_string($group) . "' and vicidial_closer_log.user is not null and length_in_sec is not null and length_in_sec > 0 and vicidial_closer_log.user=vicidial_users.user group by vicidial_closer_log.user;";
+$stmt="select vicidial_closer_log.user,full_name,count(*),sum(length_in_sec),avg(length_in_sec) from vicidial_closer_log,vicidial_users where call_date >= '$query_date_BEGIN' and call_date <= '$query_date_END' and  campaign_id IN($group_SQL) and vicidial_closer_log.user is not null and length_in_sec is not null and length_in_sec > 0 and vicidial_closer_log.user=vicidial_users.user group by vicidial_closer_log.user;";
 $rslt=mysql_query($stmt, $link);
 if ($DB) {echo "$stmt\n";}
 $users_to_print = mysql_num_rows($rslt);
@@ -710,14 +822,14 @@ $i=0;
 $h=0;
 while ($i <= 96)
 	{
-	$stmt="select count(*) from vicidial_closer_log where call_date >= '$query_date $h:00:00' and call_date <= '$query_date $h:14:59' and campaign_id='" . mysql_real_escape_string($group) . "';";
+	$stmt="select count(*) from vicidial_closer_log where call_date >= '$query_date $h:00:00' and call_date <= '$query_date $h:14:59' and campaign_id IN($group_SQL);";
 	$rslt=mysql_query($stmt, $link);
 	if ($DB) {echo "$stmt\n";}
 	$row=mysql_fetch_row($rslt);
 	$hour_count[$i] = $row[0];
 	if ($hour_count[$i] > $hi_hour_count) {$hi_hour_count = $hour_count[$i];}
 	if ($hour_count[$i] > 0) {$last_full_record = $i;}
-	$stmt="select count(*) from vicidial_closer_log where call_date >= '$query_date $h:00:00' and call_date <= '$query_date $h:14:59' and campaign_id='" . mysql_real_escape_string($group) . "' and status='DROP';";
+	$stmt="select count(*) from vicidial_closer_log where call_date >= '$query_date $h:00:00' and call_date <= '$query_date $h:14:59' and campaign_id IN($group_SQL) and status IN('DROP','XDROP');";
 	$rslt=mysql_query($stmt, $link);
 	if ($DB) {echo "$stmt\n";}
 	$row=mysql_fetch_row($rslt);
@@ -725,42 +837,42 @@ while ($i <= 96)
 	$i++;
 
 
-	$stmt="select count(*) from vicidial_closer_log where call_date >= '$query_date $h:15:00' and call_date <= '$query_date $h:29:59' and campaign_id='$group';";
+	$stmt="select count(*) from vicidial_closer_log where call_date >= '$query_date $h:15:00' and call_date <= '$query_date $h:29:59' and campaign_id IN($group_SQL);";
 	$rslt=mysql_query($stmt, $link);
 	if ($DB) {echo "$stmt\n";}
 	$row=mysql_fetch_row($rslt);
 	$hour_count[$i] = $row[0];
 	if ($hour_count[$i] > $hi_hour_count) {$hi_hour_count = $hour_count[$i];}
 	if ($hour_count[$i] > 0) {$last_full_record = $i;}
-	$stmt="select count(*) from vicidial_closer_log where call_date >= '$query_date $h:15:00' and call_date <= '$query_date $h:29:59' and campaign_id='" . mysql_real_escape_string($group) . "' and status='DROP';";
+	$stmt="select count(*) from vicidial_closer_log where call_date >= '$query_date $h:15:00' and call_date <= '$query_date $h:29:59' and campaign_id IN($group_SQL) and status IN('DROP','XDROP');";
 	$rslt=mysql_query($stmt, $link);
 	if ($DB) {echo "$stmt\n";}
 	$row=mysql_fetch_row($rslt);
 	$drop_count[$i] = $row[0];
 	$i++;
 
-	$stmt="select count(*) from vicidial_closer_log where call_date >= '$query_date $h:30:00' and call_date <= '$query_date $h:44:59' and campaign_id='" . mysql_real_escape_string($group) . "';";
+	$stmt="select count(*) from vicidial_closer_log where call_date >= '$query_date $h:30:00' and call_date <= '$query_date $h:44:59' and campaign_id IN($group_SQL);";
 	$rslt=mysql_query($stmt, $link);
 	if ($DB) {echo "$stmt\n";}
 	$row=mysql_fetch_row($rslt);
 	$hour_count[$i] = $row[0];
 	if ($hour_count[$i] > $hi_hour_count) {$hi_hour_count = $hour_count[$i];}
 	if ($hour_count[$i] > 0) {$last_full_record = $i;}
-	$stmt="select count(*) from vicidial_closer_log where call_date >= '$query_date $h:30:00' and call_date <= '$query_date $h:44:59' and campaign_id='" . mysql_real_escape_string($group) . "' and status='DROP';";
+	$stmt="select count(*) from vicidial_closer_log where call_date >= '$query_date $h:30:00' and call_date <= '$query_date $h:44:59' and campaign_id IN($group_SQL) and status IN('DROP','XDROP');";
 	$rslt=mysql_query($stmt, $link);
 	if ($DB) {echo "$stmt\n";}
 	$row=mysql_fetch_row($rslt);
 	$drop_count[$i] = $row[0];
 	$i++;
 
-	$stmt="select count(*) from vicidial_closer_log where call_date >= '$query_date $h:45:00' and call_date <= '$query_date $h:59:59' and campaign_id='" . mysql_real_escape_string($group) . "';";
+	$stmt="select count(*) from vicidial_closer_log where call_date >= '$query_date $h:45:00' and call_date <= '$query_date $h:59:59' and campaign_id IN($group_SQL);";
 	$rslt=mysql_query($stmt, $link);
 	if ($DB) {echo "$stmt\n";}
 	$row=mysql_fetch_row($rslt);
 	$hour_count[$i] = $row[0];
 	if ($hour_count[$i] > $hi_hour_count) {$hi_hour_count = $hour_count[$i];}
 	if ($hour_count[$i] > 0) {$last_full_record = $i;}
-	$stmt="select count(*) from vicidial_closer_log where call_date >= '$query_date $h:45:00' and call_date <= '$query_date $h:59:59' and campaign_id='" . mysql_real_escape_string($group) . "' and status='DROP';";
+	$stmt="select count(*) from vicidial_closer_log where call_date >= '$query_date $h:45:00' and call_date <= '$query_date $h:59:59' and campaign_id IN($group_SQL) and status IN('DROP','XDROP')';";
 	$rslt=mysql_query($stmt, $link);
 	if ($DB) {echo "$stmt\n";}
 	$row=mysql_fetch_row($rslt);
@@ -910,4 +1022,4 @@ echo "\nRun Time: $RUNtime seconds\n";
 ?>
 
- \ No newline at end of file +