, Matt Florell LICENSE: AGPLv2 # # This is a report designed for showing custom statistics based on client # requirements. This is not a standard VICIdial report. # # CHANGES # 160411-1917 - First build based upon called_counts_multilist_report.php # 160412-2022 - Callback bug fixed, modified Total count to use modify_date instead of entry_date # 160427-1655 - Added called count categories # 170409-1540 - Added IP List validation code # 180508-2315 - Added new help display # $startMS = microtime(); header ("Content-type: text/html; charset=utf-8"); require("dbconnect_mysqli.php"); require("functions.php"); require("screen_colors.php"); $PHP_AUTH_USER=$_SERVER['PHP_AUTH_USER']; $PHP_AUTH_PW=$_SERVER['PHP_AUTH_PW']; $QUERY_STRING=$_SERVER['QUERY_STRING']; $PHP_SELF=$_SERVER['PHP_SELF']; $PHP_SELF = preg_replace('/\.php.*/i','.php',$PHP_SELF); if (isset($_GET["list_ids"])) {$list_ids=$_GET["list_ids"];} elseif (isset($_POST["list_ids"])) {$list_ids=$_POST["list_ids"];} if (isset($_GET["override_date"])) {$override_date=$_GET["override_date"];} elseif (isset($_POST["override_date"])) {$override_date=$_POST["override_date"];} 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["shift"])) {$shift=$_GET["shift"];} elseif (isset($_POST["shift"])) {$shift=$_POST["shift"];} if (isset($_GET["DB"])) {$DB=$_GET["DB"];} elseif (isset($_POST["DB"])) {$DB=$_POST["DB"];} if (isset($_GET["submit"])) {$submit=$_GET["submit"];} elseif (isset($_POST["submit"])) {$submit=$_POST["submit"];} if (isset($_GET["file_download"])) {$file_download=$_GET["file_download"];} elseif (isset($_POST["file_download"])) {$file_download=$_POST["file_download"];} if (isset($_GET["SUBMIT"])) {$SUBMIT=$_GET["SUBMIT"];} elseif (isset($_POST["SUBMIT"])) {$SUBMIT=$_POST["SUBMIT"];} if (isset($_GET["report_display_type"])) {$report_display_type=$_GET["report_display_type"];} elseif (isset($_POST["report_display_type"])) {$report_display_type=$_POST["report_display_type"];} if (isset($_GET["search_archived_data"])) {$search_archived_data=$_GET["search_archived_data"];} elseif (isset($_POST["search_archived_data"])) {$search_archived_data=$_POST["search_archived_data"];} if (strlen($shift)<2) {$shift='ALL';} if (strlen($bottom_graph)<2) {$bottom_graph='NO';} if (strlen($carrier_stats)<2) {$carrier_stats='NO';} if (strlen($include_rollover)<2) {$include_rollover='NO';} $DB=preg_replace("/[^0-9a-zA-Z]/","",$DB); $today=date("Y-m-d"); $report_name = 'Medialog Inventory Report'; $db_source = 'M'; $JS_text="\n"; $HEADER.=""; $HEADER.="\n"; $HEADER.="\n"; $HEADER.="\n"; $HEADER.="$JS_text"; #$HEADER.="\n"; $HEADER.="\n"; $HEADER.=""._QXZ("$report_name")."\n"; $short_header=1; $draw_graph=1; #require("admin_header.php"); $NWB#medialog_inventory_report$NWE $MAIN.=""._QXZ("$report_name")." \n"; $MAIN.="
"; $MAIN.="
\n"; $MAIN.="
"._QXZ("Dates").":
"; $MAIN.="\n"; $MAIN.="\n"; $MAIN.=""; $MAIN.="\n"; $MAIN.="
"._QXZ("to")."
"; $MAIN.="\n"; if (preg_match('/MSIE/i', $_SERVER['HTTP_USER_AGENT'])) { $JS_events="onBlur='LoadLists(this.form.group)' onKeyUp='LoadLists(this.form.group)'"; } else { $JS_events="onMouseUp='LoadLists(this.form.group)' onBlur='LoadLists(this.form.group)' onKeyUp='LoadLists(this.form.group)'"; } $MAIN.="
"._QXZ("Campaigns").":
"; $MAIN.="\n"; $MAIN.="
"; $MAIN.=_QXZ("Lists").": ("._QXZ("optional, possibly slow").")
\n"; $MAIN.=$list_options; $MAIN.="
"; if ($archives_available=="Y") { $MAIN.="
"._QXZ("Search archived data")."\n"; } $MAIN.="

\n"; $MAIN.="

"._QXZ("reset").""; $MAIN.="
"; $MAIN.="
\n\n"; if (count($list_ids) > 0 && count($group) > 0) { $CSV_text= "\"Status-Report\"\n\n"; $CSV_text.="\"Zeitraum\",\"\",\"Kampagnen\",\"\",\"Listen\"\n"; $rpt_title_row[0]="Datum von"; $rpt_title_row[1]=date("d.m.Y", strtotime($query_date)); $rpt_title_row[2]="Datum bis"; $rpt_title_row[3]=date("d.m.Y", strtotime($end_date)); $MAIN.="
\n";
	$MAIN.=" Status-Report          ["._QXZ("DOWNLOAD")."]\n";
	$MAIN.="------------------\n";
	$MAIN.=" Zeitraum:  Datum von $rpt_title_row[1]  --  Datum bis $rpt_title_row[3]\n";
	$MAIN.=" Kampagnen: ".implode(", ", $group)."\n";
	$MAIN.=" Listen: ".implode(", ", $list_ids)."\n";

	if ($group_ct>$list_id_ct) {$max_ct=$group_ct;} else {$max_ct=$list_id_ct;}
	if ($max_ct<4) {$max_ct=4;}

	for ($i=0; $i<$max_ct; $i++) {
		$CSV_text.="\"$rpt_title_row[$i]\",\"\",\"$group[$i]\",\"\",\"$list_ids[$i]\"\n";
	}
	$CSV_text.="\n";
	$CSV_text.="\"\",\"Count\",\"%\",\"\",\"\",\"Kontaktstatus\"\n";


	$no_stmt="select distinct status from vicidial_statuses where human_answered='Y' and not_interested='Y' and completed='Y' and dnc='N' UNION select distinct status from vicidial_campaign_statuses where human_answered='Y' and not_interested='Y' and completed='Y' and dnc='N' $group_SQLand";
	$no_rslt=mysql_to_mysqli($no_stmt, $link);
	$no_statuses=array();
	while($no_row=mysqli_fetch_row($no_rslt)) {
		array_push($no_statuses, $no_row[0]);
	}

	$nixi_stmt="select distinct status from vicidial_statuses where human_answered='Y' and not_interested='Y' and completed='Y' and dnc='Y' UNION select distinct status from vicidial_campaign_statuses where  human_answered='Y' and not_interested='Y' and completed='Y' and dnc='Y' $group_SQLand";
	$nixi_rslt=mysql_to_mysqli($nixi_stmt, $link);
	$nixi_statuses=array();
	while($nixi_row=mysqli_fetch_row($nixi_rslt)) {
		array_push($nixi_statuses, $nixi_row[0]);
	}
	
	$afc_statuses=array("DC", "AFAX", "DCF", "ADC", "CPDINV");

	$sale_stmt="select distinct status from vicidial_statuses where sale='Y' UNION select distinct status from vicidial_campaign_statuses where sale='Y' $group_SQLand";
	$sale_rslt=mysql_to_mysqli($sale_stmt, $link);
	$sale_statuses=array();
	while($sale_row=mysqli_fetch_row($sale_rslt)) {
		array_push($sale_statuses, $sale_row[0]);
	}

	$MAIN.=" Falsche Tel: ".implode(", ", $afc_statuses)."\n";
	$MAIN.=" Nixi: ".implode(", ", $nixi_statuses)."\n";
	$MAIN.=" No: ".implode(", ", $no_statuses)."\n";
	$MAIN.=" Sales: ".implode(", ", $sale_statuses)."\n\n";

	$all_statuses=array_merge($no_statuses, $nixi_statuses, $afc_statuses, $sale_statuses);
#	print_r($all_statuses);
#	print_r($sale_statuses);

	$afc_counts=array();
	$nixi_counts=array();
	$no_counts=array();
	$sales_counts=array();

	$total=0;
	$workoff_total=0;

	# SNAPSHOT FOR TOP AND BOTTOM VALUES?
	# $stmt="select status, called_count, count(*) from vicidial_list where entry_date>='$query_date 00:00:00' and entry_date<='$end_date 23:59:59' $list_id_SQLand group by status, called_count order by status, called_count";
	#$stmt="select count(*) from vicidial_list where entry_date>='$query_date 00:00:00' and entry_date<='$end_date 23:59:59' $list_id_SQLand";
	$stmt="select count(*) from vicidial_list $list_id_SQLwhere";
	if ($DB) {echo $stmt."
\n";} $rslt=mysql_to_mysqli($stmt, $link); while ($row=mysqli_fetch_row($rslt)) { $total=$row[0]; $workoff_total=$total; } # CALL ACTIVITY $stmt="select ".$vicidial_list_table.".lead_id from ".$vicidial_list_table.", ".$vicidial_log_table." where ".$vicidial_log_table.".call_date>='$query_date 00:00:00' and ".$vicidial_log_table.".call_date<='$end_date 23:59:59' $list_id_SQLandVLJOIN UNION select distinct ".$vicidial_list_table.".lead_id from ".$vicidial_list_table.", ".$vicidial_closer_log_table." where ".$vicidial_closer_log_table.".call_date>='$query_date 00:00:00' and ".$vicidial_closer_log_table.".call_date<='$end_date 23:59:59' $list_id_SQLandVCLJOIN;"; $call_count_stmt="select ".$vicidial_log_table.".lead_id,".$vicidial_list_table.".called_count,".$vicidial_log_table.".status,".$vicidial_log_table.".call_date from ".$vicidial_list_table.", ".$vicidial_log_table." where ".$vicidial_log_table.".call_date>='$query_date 00:00:00' and ".$vicidial_log_table.".call_date<='$end_date 23:59:59' and ".$vicidial_log_table.".status in ('".implode("', '", $all_statuses)."') $group_SQLand $list_id_SQLandVLJOIN UNION select ".$vicidial_closer_log_table.".lead_id,".$vicidial_list_table.".called_count,".$vicidial_closer_log_table.".status,".$vicidial_closer_log_table.".call_date from ".$vicidial_list_table.", ".$vicidial_closer_log_table." where ".$vicidial_closer_log_table.".call_date>='$query_date 00:00:00' and ".$vicidial_closer_log_table.".call_date<='$end_date 23:59:59' and ".$vicidial_closer_log_table.".status in ('".implode("', '", $all_statuses)."') $list_id_SQLandVCLJOIN"; $stmt="select list_id, called_count, status from vicidial_list $list_id_SQLwhere"; # QUERY 1 $zb_counts=array(); $cc_stmt="select if(called_count>15, '4', if(called_count>10, '3', if(called_count>5, '2', if(called_count>0, '1', '0')))) as ary_index, count(*) from vicidial_list $list_id_SQLwhere group by ary_index"; $cc_rslt=mysql_to_mysqli($cc_stmt, $link); while ($ccrow=mysqli_fetch_row($cc_rslt)) { $zb_counts[$ccrow[0]]=$ccrow[1]; } # $call_count_stmt="select ".$vicidial_log_table.".lead_id,".$vicidial_list_table.".called_count,".$vicidial_log_table.".status,".$vicidial_log_table.".call_date from ".$vicidial_list_table.", ".$vicidial_log_table." where ".$vicidial_log_table.".call_date>='$query_date 00:00:00' and ".$vicidial_log_table.".call_date<='$end_date 23:59:59' and ".$vicidial_log_table.".status in ('".implode("', '", $all_statuses)."') $group_SQLand $list_id_SQLandVLJOIN UNION select ".$vicidial_closer_log_table.".lead_id,".$vicidial_list_table.".called_count,".$vicidial_closer_log_table.".status,".$vicidial_closer_log_table.".call_date from ".$vicidial_list_table.", ".$vicidial_closer_log_table." where ".$vicidial_closer_log_table.".call_date>='$query_date 00:00:00' and ".$vicidial_closer_log_table.".call_date<='$end_date 23:59:59' and ".$vicidial_closer_log_table.".status in ('".implode("', '", $all_statuses)."') $list_id_SQLandVCLJOIN"; # QUERY 2 $call_count_stmt="select ".$vicidial_log_table.".lead_id,".$vicidial_list_table.".called_count,".$vicidial_log_table.".status,".$vicidial_log_table.".call_date from ".$vicidial_list_table.", ".$vicidial_log_table." where ".$vicidial_log_table.".call_date<='$end_date 23:59:59' and ".$vicidial_log_table.".status in ('".implode("', '", $all_statuses)."') $group_SQLand $list_id_SQLandVLJOIN UNION select ".$vicidial_closer_log_table.".lead_id,".$vicidial_list_table.".called_count,".$vicidial_closer_log_table.".status,".$vicidial_closer_log_table.".call_date from ".$vicidial_list_table.", ".$vicidial_closer_log_table." where ".$vicidial_closer_log_table.".call_date<='$end_date 23:59:59' and ".$vicidial_closer_log_table.".status in ('".implode("', '", $all_statuses)."') $list_id_SQLandVCLJOIN"; # QUERY 3 $stmt="select lead_id, called_count, status, max(call_date) from ($call_count_stmt) as dt group by lead_id, called_count, status"; # USED WITH QUERY 2 and 3 if ($DB) {echo $stmt."
\n";} $rslt=mysql_to_mysqli($stmt, $link); # print_r($afc_statuses); # print_r($nixi_statuses); # print_r($no_statuses); # print_r($sale_statuses); while ($row=mysqli_fetch_row($rslt)) { $status=$row[2]; $called_count=$row[1]; $workoff_total--; if ($called_count>0) { if ($called_count>=1 && $called_count<=5) { $ary_index=1; } else if ($called_count<=10) { $ary_index=2; } else if ($called_count<=15) { $ary_index=3; } else if ($called_count>15) { $ary_index=4; } if(in_array($status, $no_statuses)) { $no_counts[0]++; $no_counts[$ary_index]++; $zb_counts[$ary_index]--; } else if (in_array($status, $nixi_statuses)) { $nixi_counts[0]++; $nixi_counts[$ary_index]++; $zb_counts[$ary_index]--; } else if (in_array($status, $afc_statuses)) { $afc_counts[0]++; $afc_counts[$ary_index]++; $zb_counts[$ary_index]--; } else if (in_array($status, $sale_statuses)) { $sales_counts[0]++; $sales_counts[$ary_index]++; $zb_counts[$ary_index]--; } else { $workoff_total++; } } else { $workoff_total++; } # $total+=$count; } $workoff_total+=0; for($i=0; $i<=4; $i++) { $afc_counts[$i]+=0; $nixi_counts[$i]+=0; $no_counts[$i]+=0; $sales_counts[$i]+=0; $zb_counts[$i]+=0; } $CSV_text.="\"Total\",\"$total\",\"\",\"\",\"1 - 5\",\"6 - 10\",\"10 - 15\",\"> 15\"\n"; $CSV_text.="\"Falsche Tel.\",\"$afc_counts[0]\",\"".sprintf("%.2f", (100*($afc_counts[0]/$total)))." %\",\"\",\"$afc_counts[1]\",\"$afc_counts[2]\",\"$afc_counts[3]\",\"$afc_counts[4]\"\n"; $CSV_text.="\"Nixi\",\"$nixi_counts[0]\",\"".sprintf("%.2f", (100*($nixi_counts[0]/($nixi_counts[0]+$no_counts[0]+$sales_counts[0]))))." %\",\"\",\"$nixi_counts[1]\",\"$nixi_counts[2]\",\"$nixi_counts[3]\",\"$nixi_counts[4]\"\n"; $CSV_text.="\"No\",\"$no_counts[0]\",\"\",\"\",\"$no_counts[1]\",\"$no_counts[2]\",\"$no_counts[3]\",\"$no_counts[4]\"\n"; $CSV_text.="\"Sales\",\"$sales_counts[0]\",\"".sprintf("%.2f", (100*($sales_counts[0]/($nixi_counts[0]+$no_counts[0]+$sales_counts[0]))))." %\",\"\",\"$sales_counts[1]\",\"$sales_counts[2]\",\"$sales_counts[3]\",\"$sales_counts[4]\"\n"; $head ="+------------------+---------+---------+---+---------+---------+---------+---------+\n"; $MAIN.=$head; $MAIN.="| | Count | % | | Kontaktstatus |\n"; $MAIN.=$head; $MAIN.="| Total | ".sprintf("%7s", $total)." | | | 1 - 5 | 6 - 10 | 10 - 15 | > 15 |\n"; $MAIN.="| Falsche Tel. | ".sprintf("%7s", $afc_counts[0])." | ".sprintf("%6s", sprintf("%.2f", (100*($afc_counts[0]/$total))))."% | | ".sprintf("%7s", $afc_counts[1])." | ".sprintf("%7s", $afc_counts[2])." | ".sprintf("%7s", $afc_counts[3])." | ".sprintf("%7s", $afc_counts[4])." |\n"; $MAIN.="| Nixi | ".sprintf("%7s", $nixi_counts[0])." | ".sprintf("%6s", sprintf("%.2f", (100*($nixi_counts[0]/($nixi_counts[0]+$no_counts[0]+$sales_counts[0])))))."% | | ".sprintf("%7s", $nixi_counts[1])." | ".sprintf("%7s", $nixi_counts[2])." | ".sprintf("%7s", $nixi_counts[3])." | ".sprintf("%7s", $nixi_counts[4])." |\n"; $MAIN.="| No | ".sprintf("%7s", $no_counts[0])." | ".sprintf("%7s", " ")." | | ".sprintf("%7s", $no_counts[1])." | ".sprintf("%7s", $no_counts[2])." | ".sprintf("%7s", $no_counts[3])." | ".sprintf("%7s", $no_counts[4])." |\n"; # Check percentage output here $MAIN.="| Sales | ".sprintf("%7s", $sales_counts[0])." | ".sprintf("%6s", sprintf("%.2f", (100*($sales_counts[0]/($nixi_counts[0]+$no_counts[0]+$sales_counts[0])))))."% | | ".sprintf("%7s", $sales_counts[1])." | ".sprintf("%7s", $sales_counts[2])." | ".sprintf("%7s", $sales_counts[3])." | ".sprintf("%7s", $sales_counts[4])." |\n"; $MAIN.=$head; # CALLBACKS $anyone_counts=array(); $useronly_counts=array(); $calledback_counts=array(); $callbacks_group_SQLand = "and vicidial_callbacks.campaign_id in ($group_SQL)"; $callbacks_group_SQL = "where vicidial_callbacks.campaign_id in ($group_SQL)"; $callback_listid_SQLand=" and vicidial_callbacks.list_id in ($list_id_SQL)"; $callback_listid_SQL=" where vicidial_callbacks.list_id in ($list_id_SQL)"; $callbk_stmt="select recipient, called_count, if(callback_time<'".date("Y-m-d H:i:s")."', 'CALLED', 'NOT CALLED') from vicidial_callbacks, vicidial_list where vicidial_list.lead_id=vicidial_callbacks.lead_id $callbacks_group_SQLand $callback_listid_SQLand"; if ($DB) {echo "$callbk_stmt
";} $callbk_rslt=mysql_to_mysqli($callbk_stmt, $link); while ($callbk_row=mysqli_fetch_row($callbk_rslt)) { $recipient=$callbk_row[0]; $called_count=$callbk_row[1]; $callbk_status=$callbk_row[2]; if ($called_count>=1 && $called_count<=5) { $ary_index=1; } else if ($called_count<=10) { $ary_index=2; } else if ($called_count<=15) { $ary_index=3; } else if ($called_count>15) { $ary_index=4; } if ($callbk_status=="NOT CALLED") { if($recipient=="ANYONE") { $anyone_counts[0]++; $anyone_counts[$ary_index]++; } else { $useronly_counts[0]++; $useronly_counts[$ary_index]++; } } else { $calledback_counts[0]++; $calledback_counts[$ary_index]++; } } for($i=0; $i<=4; $i++) { $anyone_counts[$i]+=0; $useronly_counts[$i]+=0; $calledback_counts[$i]+=0; } $CSV_text.="\"WV Team\",\"$anyone_counts[0]\",\"\",\"\",\"$anyone_counts[1]\",\"$anyone_counts[2]\",\"$anyone_counts[3]\",\"$anyone_counts[4]\"\n"; $CSV_text.="\"WV persönlich\",\"$useronly_counts[0]\",\"\",\"\",\"$useronly_counts[1]\",\"$useronly_counts[2]\",\"$useronly_counts[3]\",\"$useronly_counts[4]\"\n"; $CSV_text.="\"WV Vergangenheit \",\"$calledback_counts[0]\",\"\",\"\",\"$calledback_counts[1]\",\"$calledback_counts[2]\",\"$calledback_counts[3]\",\"$calledback_counts[4]\"\n\n"; $CSV_text.="\"Zu bearbeiten\",\"$workoff_total\",\"\",\"\",\"$zb_counts[1]\",\"$zb_counts[2]\",\"$zb_counts[3]\",\"$zb_counts[4]\",\"$zb_counts[0] (undialed)\"\n\n\n\n"; $MAIN.="| WV Team | ".sprintf("%7s", $anyone_counts[0])." | ".sprintf("%7s", " ")." | | ".sprintf("%7s", $anyone_counts[1])." | ".sprintf("%7s", $anyone_counts[2])." | ".sprintf("%7s", $anyone_counts[3])." | ".sprintf("%7s", $anyone_counts[4])." |\n"; $MAIN.="| WV persönlich | ".sprintf("%7s", $useronly_counts[0])." | ".sprintf("%7s", " ")." | | ".sprintf("%7s", $useronly_counts[1])." | ".sprintf("%7s", $useronly_counts[2])." | ".sprintf("%7s", $useronly_counts[3])." | ".sprintf("%7s", $useronly_counts[4])." |\n"; $MAIN.="| WV Vergangenheit | ".sprintf("%7s", $calledback_counts[0])." | ".sprintf("%7s", " ")." | | ".sprintf("%7s", $calledback_counts[1])." | ".sprintf("%7s", $calledback_counts[2])." | ".sprintf("%7s", $calledback_counts[3])." | ".sprintf("%7s", $calledback_counts[4])." |\n"; $MAIN.=$head; $MAIN.="| Zu bearbeiten | ".sprintf("%7s", $workoff_total)." | ".sprintf("%7s", " ")." | | ".sprintf("%7s", $zb_counts[1])." | ".sprintf("%7s", $zb_counts[2])." | ".sprintf("%7s", $zb_counts[3])." | ".sprintf("%7s", $zb_counts[4])." | ".sprintf("%7s", $zb_counts[0])." (undialed)\n"; $MAIN.=$head; ## Lower section $CSV_text.="\"Tagesstatus\"\n"; $CSV_text.="\"\",\"Falsche Tel. (AFC)\",\"%\",\"Nixi\",\"No\",\"Sales\",\"%\",\"Summe (sum)\"\n"; $MAIN.=" Tagesstatus \n"; $foot= "+------------+--------------+---------+---------+---------+---------+---------+---------+\n"; $MAIN.=$foot; $MAIN.="| | Falsche Tel. | % | Nixi | No | Sales | % | Summe |\n"; $MAIN.=$foot; $date_stmt="select distinct substr(call_date, 1, 10) as cdate from vicidial_log where call_date>='$query_date 00:00:00' and call_date<='$end_date 23:59:59' $group_SQLand $list_id_SQLand and status in ('".implode("', '", $all_statuses)."') order by cdate asc"; $date_rslt=mysql_to_mysqli($date_stmt, $link); $date_ary=array(); while($date_row=mysqli_fetch_row($date_rslt)) { array_push($date_ary, $date_row[0]); } $total_date_daily_count=0; $total_contact_daily_count=0; $total_no_daily_counts=0; $total_nixi_daily_counts=0; $total_afc_daily_counts=0; $total_sales_daily_counts=0; for ($i=0; $i='$date_ary[$i] 00:00:00' and ".$vicidial_log_table.".call_date<='$date_ary[$i] 23:59:59' and ".$vicidial_log_table.".status in ('".implode("', '", $all_statuses)."') $group_SQLand $list_id_SQLandVLJOIN UNION select ".$vicidial_closer_log_table.".lead_id,".$vicidial_list_table.".called_count,".$vicidial_closer_log_table.".status,".$vicidial_closer_log_table.".call_date from ".$vicidial_list_table.", ".$vicidial_closer_log_table." where ".$vicidial_closer_log_table.".call_date>='$date_ary[$i] 00:00:00' and ".$vicidial_closer_log_table.".call_date<='$date_ary[$i] 23:59:59' and ".$vicidial_closer_log_table.".status in ('".implode("', '", $all_statuses)."') $list_id_SQLandVCLJOIN"; # Need counts not limited by status? Otherwise use above statement $stmt="select ".$vicidial_log_table.".lead_id,".$vicidial_list_table.".called_count,".$vicidial_log_table.".status,".$vicidial_log_table.".call_date from ".$vicidial_list_table.", ".$vicidial_log_table." where ".$vicidial_log_table.".call_date>='$date_ary[$i] 00:00:00' and ".$vicidial_log_table.".call_date<='$date_ary[$i] 23:59:59' $group_SQLand $list_id_SQLandVLJOIN UNION select ".$vicidial_closer_log_table.".lead_id,".$vicidial_list_table.".called_count,".$vicidial_closer_log_table.".status,".$vicidial_closer_log_table.".call_date from ".$vicidial_list_table.", ".$vicidial_closer_log_table." where ".$vicidial_closer_log_table.".call_date>='$date_ary[$i] 00:00:00' and ".$vicidial_closer_log_table.".call_date<='$date_ary[$i] 23:59:59' $list_id_SQLandVCLJOIN"; # $stmt="select lead_id, called_count, status, max(call_date) from ($call_count_stmt) as dt group by lead_id, called_count, status"; $rslt=mysql_to_mysqli($stmt, $link); $date_daily_count=0; $contact_daily_count=0; $no_daily_counts=0; $nixi_daily_counts=0; $afc_daily_counts=0; $sales_daily_counts=0; while($row=mysqli_fetch_row($rslt)) { $status=$row[2]; # $count=$row[1]; $date_daily_count++; if(in_array($status, $no_statuses)) { $no_daily_counts++; $contact_daily_count++; } else if (in_array($status, $nixi_statuses)) { $nixi_daily_counts++; $contact_daily_count++; } else if (in_array($status, $afc_statuses)) { $afc_daily_counts++; $contact_daily_count++; } else if (in_array($status, $sale_statuses)) { $sales_daily_counts++; $contact_daily_count++; } } $CSV_text.="\"$DEU_date\",\"$afc_daily_counts\",\"".sprintf("%.2f", (100*($afc_daily_counts/$total)))." %\",\"$nixi_daily_counts\",\"$no_daily_counts\",\"$sales_daily_counts\",\"".sprintf("%.2f", (100*($sales_daily_counts/($nixi_daily_counts+$no_daily_counts+$sales_daily_counts))))." %\",\"$contact_daily_count\"\n"; $MAIN.="| $DEU_date | ".sprintf("%12s", $afc_daily_counts)." | ".sprintf("%6s", sprintf("%.2f", (100*($afc_daily_counts/$total))))."% | ".sprintf("%7s", $nixi_daily_counts)." | ".sprintf("%7s", $no_daily_counts)." | ".sprintf("%7s", $sales_daily_counts)." | ".sprintf("%6s", sprintf("%.2f", (100*($sales_daily_counts/($nixi_daily_counts+$no_daily_counts+$sales_daily_counts)))))."% | ".sprintf("%7s", $contact_daily_count)." |\n"; $MAIN.=$foot; $total_date_daily_count+=$date_daily_count; $total_contact_daily_count+=$contact_daily_count; $total_no_daily_counts+=$no_daily_counts; $total_nixi_daily_counts+=$nixi_daily_counts; $total_afc_daily_counts+=$afc_daily_counts; $total_sales_daily_counts+=$sales_daily_counts; } /* # CALLED ATTEMPTS COUNT WITHIN RANGE select lead_id, sum(ct) as total_count from (select vicidial_list.lead_id, count(*) as ct from vicidial_list, vicidial_log where vicidial_log.call_date>='2015-01-30 00:00:00' and vicidial_log.call_date<='2016-03-30 23:59:59' and vicidial_log.lead_id=vicidial_list.lead_id and vicidial_list.list_id IN('101','5555','102314','7777') group by lead_id UNION select vicidial_list.lead_id, count(*) as ct from vicidial_list, vicidial_closer_log where vicidial_closer_log.call_date>='2014-01-30 00:00:00' and vicidial_closer_log.call_date<='2016-03-30 23:59:59' and vicidial_closer_log.lead_id=vicidial_list.lead_id and vicidial_list.list_id IN('101','5555','102314','7777') group by lead_id) as temp_count group by lead_id order by lead_id; # CURRENT CALLED COUNT WITHIN RANGE select lead_id, max(max_count) as total_count from (select vicidial_log.lead_id, max(vicidial_log.called_count) as max_count from vicidial_list, vicidial_log where vicidial_log.call_date>='2015-01-30 00:00:00' and vicidial_log.call_date<='2016-03-30 23:59:59' and vicidial_log.lead_id=vicidial_list.lead_id and vicidial_list.list_id IN('101','5555','102314','7777') group by lead_id UNION select vicidial_closer_log.lead_id, max(vicidial_closer_log.called_count) as max_count from vicidial_list, vicidial_closer_log where vicidial_closer_log.call_date>='2014-01-30 00:00:00' and vicidial_closer_log.call_date<='2016-03-30 23:59:59' and vicidial_closer_log.lead_id=vicidial_list.lead_id and vicidial_list.list_id IN('101','5555','102314','7777') group by lead_id) as temp_count group by lead_id order by lead_id; */ $MAIN.="

\n"; $MAIN.="\n"; if ($file_download>0) { $FILE_TIME = date("Ymd-His"); $CSVfilename = "MEDIALOG_INVENTORY_report_$US$FILE_TIME.csv"; $CSV_text=preg_replace('/\n +,/', ',', $CSV_text); $CSV_text=preg_replace('/ +\"/', '"', $CSV_text); $CSV_text=preg_replace('/\" +/', '"', $CSV_text); // We'll be outputting a TXT file header('Content-type: application/octet-stream'); // It will be called LIST_101_20090209-121212.txt header("Content-Disposition: attachment; filename=\"$CSVfilename\""); header('Expires: 0'); header('Cache-Control: must-revalidate, post-check=0, pre-check=0'); header('Pragma: public'); ob_clean(); flush(); echo "$CSV_text"; } else { echo $HEADER; require("admin_header.php"); echo $MAIN; } } else { echo $HEADER; require("admin_header.php"); echo $MAIN; } if ($db_source == 'S') { mysqli_close($link); $use_slave_server=0; $db_source = 'M'; require("dbconnect_mysqli.php"); } $endMS = microtime(); $startMSary = explode(" ",$startMS); $endMSary = explode(" ",$endMS); $runS = ($endMSary[0] - $startMSary[0]); $runM = ($endMSary[1] - $startMSary[1]); $TOTALrun = ($runS + $runM); $stmt="UPDATE vicidial_report_log set run_time='$TOTALrun' where report_log_id='$report_log_id';"; if ($DB) {echo "|$stmt|\n";} $rslt=mysql_to_mysqli($stmt, $link); exit; ?>