From cc068698568f370b8ee013cd70add49fb55d2fe3 Mon Sep 17 00:00:00 2001 From: mattf Date: Sat, 11 Sep 2021 23:43:01 +0000 Subject: [PATCH] Fix for --ALL-- selection user-group permission issues in 3 export reports git-svn-id: svn://192.168.202.10@3517 3d104415-ff17-0410-8863-d5cf3c621b8a --- www/vicidial/call_report_export.php | 115 ++++++++++++++++-- www/vicidial/call_report_export_carrier.php | 125 ++++++++++++++++++-- www/vicidial/lead_report_export.php | 121 +++++++++++++++++-- 3 files changed, 339 insertions(+), 22 deletions(-) diff --git a/www/vicidial/call_report_export.php b/www/vicidial/call_report_export.php index c8147ddf..59dd6093 100644 --- a/www/vicidial/call_report_export.php +++ b/www/vicidial/call_report_export.php @@ -5,7 +5,7 @@ # and/or vicidial_closer_log information by status, list_id and date range. # downloads to a flat text file that is tab delimited # -# Copyright (C) 2020 Matt Florell LICENSE: AGPLv2 +# Copyright (C) 2021 Matt Florell LICENSE: AGPLv2 # # CHANGES # @@ -60,6 +60,7 @@ # 191119-1731 - Fix for alternate server url for recordings, issue #1175 # 200115-1151 - Added ALTERNATE_2 export option with alternate header option in options.php # 200709-2106 - Added EXTENDED_4 export option with logged list_id from time of call +# 210911-1907 - Fix for --ALL-- selection user-group permission issue # $startMS = microtime(); @@ -423,6 +424,20 @@ if ($run_export > 0) } } + # Get campaigns for "ALL" + $stmt="select campaign_id from vicidial_campaigns $whereLOGallowed_campaignsSQL order by campaign_id;"; + $rslt=mysql_to_mysqli($stmt, $link); + if ($DB) {echo "$stmt\n";} + $ALL_available_campaigns = mysqli_num_rows($rslt); + $h=0; + $ALL_campaign_SQL=""; + while ($h < $ALL_available_campaigns) + { + $row=mysqli_fetch_row($rslt); + $ALL_campaign_SQL .= "'$row[0]',"; + $h++; + } + $i=0; while($i < $campaign_ct) { @@ -431,6 +446,11 @@ if ($run_export > 0) $campaign_string .= "$campaign[$i]|"; $campaign_SQL .= "'$campaign[$i]',"; } + # Need this for next few lines + if (preg_match("/\-\-ALL\-\-/",$campaign[$i]) && !preg_match("/\-\-ALL\-\-/",$campaign_string)) + { + $campaign_string .= "$campaign[$i]|"; + } $i++; } if ( (preg_match('/\s\-\-NONE\-\-\s/',$campaign_string) ) or ($campaign_ct < 1) ) @@ -442,7 +462,8 @@ if ($run_export > 0) { if (preg_match("/\-\-ALL\-\-/",$campaign_string) ) { - $campaign_SQL = ""; + $campaign_SQL = preg_replace('/,$/i', '',$ALL_campaign_SQL); + $campaign_SQL = "and vl.campaign_id IN($campaign_SQL)"; $RUNcampaign++; } else @@ -452,7 +473,23 @@ if ($run_export > 0) $RUNcampaign++; } } + if ($DB) {echo "** $regexLOGallowed_campaigns --- $LOGallowed_campaigns --- $campaign_string **\n";} + + # Get inbound groups for "ALL" + $stmt="select group_id from vicidial_inbound_groups $whereLOGadmin_viewable_groupsSQL order by group_id;"; + $rslt=mysql_to_mysqli($stmt, $link); + if ($DB) {echo "$stmt\n";} + $ALL_available_groups = mysqli_num_rows($rslt); + $h=0; + $ALL_group_SQL=""; + while($h < $ALL_available_groups) + { + $row=mysqli_fetch_row($rslt); + $ALL_group_SQL .= "'$row[0]',"; + $h++; + } + $i=0; while($i < $group_ct) { @@ -470,7 +507,8 @@ if ($run_export > 0) { if ( (preg_match("/\-\-ALL\-\-/",$group_string) ) or ($group_ct < 1) ) { - $group_SQL = ""; + $group_SQL = preg_replace('/,$/i', '',$ALL_group_SQL); + $group_SQL = "and vl.campaign_id IN($group_SQL)"; $RUNgroup++; } else @@ -480,6 +518,20 @@ if ($run_export > 0) $RUNgroup++; } } + + # Get user groups for "ALL" + $stmt="select user_group from vicidial_user_groups $whereLOGadmin_viewable_groupsSQL order by user_group;"; + $rslt=mysql_to_mysqli($stmt, $link); + if ($DB) {echo "$stmt\n";} + $ALL_available_user_groups = mysqli_num_rows($rslt); + $h=0; + $ALL_user_group_SQL=""; + while ($h < $ALL_available_user_groups) + { + $row=mysqli_fetch_row($rslt); + $ALL_user_group_SQL .= "'$row[0]',"; + $h++; + } $i=0; while($i < $user_group_ct) @@ -490,7 +542,8 @@ if ($run_export > 0) } if ( (preg_match('/\-\-ALL\-\-/',$user_group_string) ) or ($user_group_ct < 1) ) { - $user_group_SQL = ""; + $user_group_SQL = preg_replace('/,$/i', '',$ALL_user_group_SQL); + $user_group_SQL = "and (vl.user_group IN($user_group_SQL) or vl.user_group is null)"; } else { @@ -498,6 +551,22 @@ if ($run_export > 0) $user_group_SQL = "and vl.user_group IN($user_group_SQL)"; } + + + # Get lists for "ALL" + $stmt="select list_id from vicidial_lists $whereLOGallowed_campaignsSQL order by list_id;"; + $rslt=mysql_to_mysqli($stmt, $link); + if ($DB) {echo "$stmt\n";} + $ALL_available_lists = mysqli_num_rows($rslt); + $h=0; + $ALL_list_SQL=""; + while ($h < $ALL_available_lists) + { + $row=mysqli_fetch_row($rslt); + $ALL_list_SQL .= "'$row[0]',"; + $h++; + } + $i=0; while($i < $list_ct) { @@ -507,7 +576,8 @@ if ($run_export > 0) } if ( (preg_match('/\-\-ALL\-\-/',$list_string) ) or ($list_ct < 1) ) { - $list_SQL = ""; + $list_SQL = preg_replace('/,$/i', '',$ALL_list_SQL); + $list_SQL = "and vl.list_id IN($list_SQL)"; } else { @@ -515,6 +585,34 @@ if ($run_export > 0) $list_SQL = "and vi.list_id IN($list_SQL)"; } + + + $stmt="select status from vicidial_statuses order by status;"; + $rslt=mysql_to_mysqli($stmt, $link); + if ($DB) {echo "$stmt\n";} + $ALL_available_statuses = mysqli_num_rows($rslt); + $h=0; + $ALL_status_SQL=""; + while ($h < $ALL_available_statuses) + { + $row=mysqli_fetch_row($rslt); + $ALL_status_SQL .= "'$row[0]',"; + $h++; + } + + $stmt="select distinct status from vicidial_campaign_statuses $whereLOGallowed_campaignsSQL order by status;"; + $rslt=mysql_to_mysqli($stmt, $link); + if ($DB) {echo "$stmt\n";} + $ALL_available_Cstatuses = mysqli_num_rows($rslt); + $j=0; + while ($j < $ALL_available_Cstatuses) + { + $row=mysqli_fetch_row($rslt); + $ALL_status_SQL .= "'$row[0]',"; + $j++; + } + + $i=0; while($i < $status_ct) { @@ -524,7 +622,8 @@ if ($run_export > 0) } if ( (preg_match('/\-\-ALL\-\-/',$status_string) ) or ($status_ct < 1) ) { - $status_SQL = ""; + $status_SQL = preg_replace('/,$/i', '',$ALL_status_SQL); + $status_SQL = "and vl.status IN($status_SQL)"; } else { @@ -742,12 +841,12 @@ if ($run_export > 0) $stmtA = "SELECT vl.call_date,vl.phone_number,vl.status,vl.user,vu.full_name,vl.campaign_id,vi.vendor_lead_code,vi.source_id,vi.list_id,vi.gmt_offset_now,vi.phone_code,vi.phone_number,vi.title,vi.first_name,vi.middle_initial,vi.last_name,vi.address1,vi.address2,vi.address3,vi.city,vi.state,vi.province,vi.postal_code,vi.country_code,vi.gender,vi.date_of_birth,vi.alt_phone,vi.email,vi.security_phrase,vi.comments,vl.length_in_sec,vl.user_group,vl.queue_seconds,vi.rank,vi.owner,vi.lead_id,vl.closecallid,vi.entry_list_id,vl.uniqueid$export_fields_SQL from vicidial_users vu,".$vicidial_closer_log_table." vl,vicidial_list vi where ".$date_field." >= '$query_date 00:00:00' and ".$date_field." <= '$end_date 23:59:59' and vu.user=vl.user and vi.lead_id=vl.lead_id $list_SQL $group_SQL $user_group_SQL $status_SQL order by ".$date_field." limit 1000000;"; } $rslt=mysql_to_mysqli($stmtA, $link); - if ($DB) {$DBout .= "$stmt\n";} + if ($DB) {$DBout .= "$stmtA\n";} $inbound_to_print = mysqli_num_rows($rslt); if ( ($inbound_to_print < 1) and ($outbound_calls < 1) ) { echo _QXZ("There are no inbound calls during this time period for these parameters")."\n"; - if ($DB) {echo "$stmt\n";} + if ($DB) {echo "$stmtA\n";} exit; } else diff --git a/www/vicidial/call_report_export_carrier.php b/www/vicidial/call_report_export_carrier.php index 517a8f98..e1edbf0a 100644 --- a/www/vicidial/call_report_export_carrier.php +++ b/www/vicidial/call_report_export_carrier.php @@ -6,7 +6,7 @@ # downloads to a flat text file that is tab delimited. This version also # attempts to link carrier and dial log entries to those calls. # -# Copyright (C) 2019 Matt Florell LICENSE: AGPLv2 +# Copyright (C) 2021 Matt Florell LICENSE: AGPLv2 # # CHANGES # @@ -20,6 +20,7 @@ # 170409-1542 - Added IP List validation code # 190610-2037 - Fixed admin hide phone issue # 190926-0927 - Fixes for PHP7 +# 210911-1908 - Fix for --ALL-- selection user-group permission issue # $startMS = microtime(); @@ -325,6 +326,20 @@ if ($run_export > 0) $user_groupQS=""; $listQS=""; $statusQS=""; + + # Get campaigns for "ALL" + $stmt="select campaign_id from vicidial_campaigns $whereLOGallowed_campaignsSQL order by campaign_id;"; + $rslt=mysql_to_mysqli($stmt, $link); + if ($DB) {echo "$stmt\n";} + $ALL_available_campaigns = mysqli_num_rows($rslt); + $h=0; + $ALL_campaign_SQL=""; + while ($h < $ALL_available_campaigns) + { + $row=mysqli_fetch_row($rslt); + $ALL_campaign_SQL .= "'$row[0]',"; + $h++; + } $i=0; while($i < $campaign_ct) @@ -335,6 +350,11 @@ if ($run_export > 0) $campaign_SQL .= "'$campaign[$i]',"; $campaignQS .= "&campaign[]=$campaign[$i]"; } + # Need this for next few lines + if (preg_match("/\-\-ALL\-\-/",$campaign[$i]) && !preg_match("/\-\-ALL\-\-/",$campaign_string)) + { + $campaign_string .= "$campaign[$i]|"; + } $i++; } if ( (preg_match('/\s\-\-NONE\-\-\s/',$campaign_string) ) or ($campaign_ct < 1) ) @@ -342,6 +362,12 @@ if ($run_export > 0) $campaign_SQL = "campaign_id IN('')"; $RUNcampaign=0; } + else if ( preg_match('/\-\-ALL\-\-/',$campaign_string) ) + { + $campaign_SQL = preg_replace('/,$/i', '',$ALL_campaign_SQL); + $campaign_SQL = "and vl.campaign_id IN($campaign_SQL)"; + $RUNcampaign=$campaign_ct; + } else { $campaign_SQL = preg_replace('/,$/i', '',$campaign_SQL); @@ -349,6 +375,21 @@ if ($run_export > 0) $RUNcampaign++; } + + # Get inbound groups for "ALL" + $stmt="select group_id from vicidial_inbound_groups $whereLOGadmin_viewable_groupsSQL order by group_id;"; + $rslt=mysql_to_mysqli($stmt, $link); + if ($DB) {echo "$stmt\n";} + $ALL_available_groups = mysqli_num_rows($rslt); + $h=0; + $ALL_group_SQL=""; + while($h < $ALL_available_groups) + { + $row=mysqli_fetch_row($rslt); + $ALL_group_SQL .= "'$row[0]',"; + $h++; + } + $i=0; while($i < $group_ct) { @@ -365,9 +406,32 @@ if ($run_export > 0) } else { - $group_SQL = preg_replace('/,$/i', '',$group_SQL); - $group_SQL = "and vl.campaign_id IN($group_SQL)"; - $RUNgroup++; + if ( (preg_match("/\-\-ALL\-\-/",$group_string) ) or ($group_ct < 1) ) + { + $group_SQL = preg_replace('/,$/i', '',$ALL_group_SQL); + $group_SQL = "and vl.campaign_id IN($group_SQL)"; + $RUNgroup++; + } + else + { + $group_SQL = preg_replace('/,$/i', '',$group_SQL); + $group_SQL = "and vl.campaign_id IN($group_SQL)"; + $RUNgroup++; + } + } + + # Get user groups for "ALL" + $stmt="select user_group from vicidial_user_groups $whereLOGadmin_viewable_groupsSQL order by user_group;"; + $rslt=mysql_to_mysqli($stmt, $link); + if ($DB) {echo "$stmt\n";} + $ALL_available_user_groups = mysqli_num_rows($rslt); + $h=0; + $ALL_user_group_SQL=""; + while ($h < $ALL_available_user_groups) + { + $row=mysqli_fetch_row($rslt); + $ALL_user_group_SQL .= "'$row[0]',"; + $h++; } $i=0; @@ -380,7 +444,8 @@ if ($run_export > 0) } if ( (preg_match('/\-\-ALL\-\-/',$user_group_string) ) or ($user_group_ct < 1) ) { - $user_group_SQL = ""; + $user_group_SQL = preg_replace('/,$/i', '',$ALL_user_group_SQL); + $user_group_SQL = "and (vl.user_group IN($user_group_SQL) or vl.user_group is null)"; } else { @@ -388,6 +453,22 @@ if ($run_export > 0) $user_group_SQL = "and vl.user_group IN($user_group_SQL)"; } + + + # Get lists for "ALL" + $stmt="select list_id from vicidial_lists $whereLOGallowed_campaignsSQL order by list_id;"; + $rslt=mysql_to_mysqli($stmt, $link); + if ($DB) {echo "$stmt\n";} + $ALL_available_lists = mysqli_num_rows($rslt); + $h=0; + $ALL_list_SQL=""; + while ($h < $ALL_available_lists) + { + $row=mysqli_fetch_row($rslt); + $ALL_list_SQL .= "'$row[0]',"; + $h++; + } + $i=0; while($i < $list_ct) { @@ -398,7 +479,8 @@ if ($run_export > 0) } if ( (preg_match('/\-\-ALL\-\-/',$list_string) ) or ($list_ct < 1) ) { - $list_SQL = ""; + $list_SQL = preg_replace('/,$/i', '',$ALL_list_SQL); + $list_SQL = "and vl.list_id IN($list_SQL)"; } else { @@ -406,6 +488,34 @@ if ($run_export > 0) $list_SQL = "and vi.list_id IN($list_SQL)"; } + + + $stmt="select status from vicidial_statuses order by status;"; + $rslt=mysql_to_mysqli($stmt, $link); + if ($DB) {echo "$stmt\n";} + $ALL_available_statuses = mysqli_num_rows($rslt); + $h=0; + $ALL_status_SQL=""; + while ($h < $ALL_available_statuses) + { + $row=mysqli_fetch_row($rslt); + $ALL_status_SQL .= "'$row[0]',"; + $h++; + } + + $stmt="select distinct status from vicidial_campaign_statuses $whereLOGallowed_campaignsSQL order by status;"; + $rslt=mysql_to_mysqli($stmt, $link); + if ($DB) {echo "$stmt\n";} + $ALL_available_Cstatuses = mysqli_num_rows($rslt); + $j=0; + while ($j < $ALL_available_Cstatuses) + { + $row=mysqli_fetch_row($rslt); + $ALL_status_SQL .= "'$row[0]',"; + $j++; + } + + $i=0; while($i < $status_ct) { @@ -416,7 +526,8 @@ if ($run_export > 0) } if ( (preg_match('/\-\-ALL\-\-/',$status_string) ) or ($status_ct < 1) ) { - $status_SQL = ""; + $status_SQL = preg_replace('/,$/i', '',$ALL_status_SQL); + $status_SQL = "and vl.status IN($status_SQL)"; } else { diff --git a/www/vicidial/lead_report_export.php b/www/vicidial/lead_report_export.php index f1b9595d..240ace78 100644 --- a/www/vicidial/lead_report_export.php +++ b/www/vicidial/lead_report_export.php @@ -35,10 +35,13 @@ # 190610-2036 - Fixed admin hide phone issue # 190926-0926 - Fixes for PHP7 # 210302-0839 - Added exclude_call_log_data option +# 210911-1906 - Fix for --ALL-- selection user-group permission issue # $startMS = microtime(); +$vlcs[0]=''; + require("dbconnect_mysqli.php"); require("functions.php"); @@ -399,6 +402,19 @@ if ($run_export > 0) $list_string='|'; $status_string='|'; $did_string='|'; + # Get campaigns for "ALL" + $stmt="select campaign_id from vicidial_campaigns $whereLOGallowed_campaignsSQL order by campaign_id;"; + $rslt=mysql_to_mysqli($stmt, $link); + if ($DB) {echo "$stmt\n";} + $ALL_available_campaigns = mysqli_num_rows($rslt); + $h=0; + $ALL_campaign_SQL=""; + while ($h < $ALL_available_campaigns) + { + $row=mysqli_fetch_row($rslt); + $ALL_campaign_SQL .= "'$row[0]',"; + $h++; + } $i=0; while($i < $campaign_ct) @@ -408,6 +424,11 @@ if ($run_export > 0) $campaign_string .= "$campaign[$i]|"; $campaign_SQL .= "'$campaign[$i]',"; } + # Need this for next few lines + if (preg_match("/\-\-ALL\-\-/",$campaign[$i]) && !preg_match("/\-\-ALL\-\-/",$campaign_string)) + { + $campaign_string .= "$campaign[$i]|"; + } $i++; } if ( (preg_match('/\-\-NONE\-\-/',$campaign_string) ) or ($campaign_ct < 1) ) @@ -417,7 +438,8 @@ if ($run_export > 0) } else if ( preg_match('/\-\-ALL\-\-/',$campaign_string) ) { - $campaign_SQL = ""; + $campaign_SQL = preg_replace('/,$/i', '',$ALL_campaign_SQL); + $campaign_SQL = "and vl.campaign_id IN($campaign_SQL)"; $RUNcampaign=$campaign_ct; } else @@ -427,6 +449,21 @@ if ($run_export > 0) $RUNcampaign++; } + + # Get inbound groups for "ALL" + $stmt="select group_id from vicidial_inbound_groups $whereLOGadmin_viewable_groupsSQL order by group_id;"; + $rslt=mysql_to_mysqli($stmt, $link); + if ($DB) {echo "$stmt\n";} + $ALL_available_groups = mysqli_num_rows($rslt); + $h=0; + $ALL_group_SQL=""; + while($h < $ALL_available_groups) + { + $row=mysqli_fetch_row($rslt); + $ALL_group_SQL .= "'$row[0]',"; + $h++; + } + $i=0; while($i < $group_ct) { @@ -442,9 +479,18 @@ if ($run_export > 0) } else { - $group_SQL = preg_replace('/,$/i', '',$group_SQL); - $group_SQL = "and vl.campaign_id IN($group_SQL)"; - $RUNgroup++; + if ( (preg_match("/\-\-ALL\-\-/",$group_string) ) or ($group_ct < 1) ) + { + $group_SQL = preg_replace('/,$/i', '',$ALL_group_SQL); + $group_SQL = "and vl.campaign_id IN($group_SQL)"; + $RUNgroup++; + } + else + { + $group_SQL = preg_replace('/,$/i', '',$group_SQL); + $group_SQL = "and vl.campaign_id IN($group_SQL)"; + $RUNgroup++; + } } $i=0; @@ -488,6 +534,20 @@ if ($run_export > 0) $RUNvlc++; } if ( ($vlc_filter=="NO") or ($VLC_enabled != 'Y') ) {$vlc_SQL=""; $RUNvlc=0;} + + # Get user groups for "ALL" + $stmt="select user_group from vicidial_user_groups $whereLOGadmin_viewable_groupsSQL order by user_group;"; + $rslt=mysql_to_mysqli($stmt, $link); + if ($DB) {echo "$stmt\n";} + $ALL_available_user_groups = mysqli_num_rows($rslt); + $h=0; + $ALL_user_group_SQL=""; + while ($h < $ALL_available_user_groups) + { + $row=mysqli_fetch_row($rslt); + $ALL_user_group_SQL .= "'$row[0]',"; + $h++; + } $i=0; while($i < $user_group_ct) @@ -498,7 +558,8 @@ if ($run_export > 0) } if ( (preg_match('/\-\-ALL\-\-/',$user_group_string) ) or ($user_group_ct < 1) ) { - $user_group_SQL = ""; + $user_group_SQL = preg_replace('/,$/i', '',$ALL_user_group_SQL); + $user_group_SQL = "and (vl.user_group IN($user_group_SQL) or vl.user_group is null)"; } else { @@ -506,6 +567,22 @@ if ($run_export > 0) $user_group_SQL = "and vl.user_group IN($user_group_SQL)"; } + + + # Get lists for "ALL" + $stmt="select list_id from vicidial_lists $whereLOGallowed_campaignsSQL order by list_id;"; + $rslt=mysql_to_mysqli($stmt, $link); + if ($DB) {echo "$stmt\n";} + $ALL_available_lists = mysqli_num_rows($rslt); + $h=0; + $ALL_list_SQL=""; + while ($h < $ALL_available_lists) + { + $row=mysqli_fetch_row($rslt); + $ALL_list_SQL .= "'$row[0]',"; + $h++; + } + $i=0; while($i < $list_ct) { @@ -515,7 +592,8 @@ if ($run_export > 0) } if ( (preg_match('/\-\-ALL\-\-/',$list_string) ) or ($list_ct < 1) ) { - $list_SQL = ""; + $list_SQL = preg_replace('/,$/i', '',$ALL_list_SQL); + $list_SQL = "and vl.list_id IN($list_SQL)"; } else { @@ -523,6 +601,34 @@ if ($run_export > 0) $list_SQL = "and vi.list_id IN($list_SQL)"; } + + + $stmt="select status from vicidial_statuses order by status;"; + $rslt=mysql_to_mysqli($stmt, $link); + if ($DB) {echo "$stmt\n";} + $ALL_available_statuses = mysqli_num_rows($rslt); + $h=0; + $ALL_status_SQL=""; + while ($h < $ALL_available_statuses) + { + $row=mysqli_fetch_row($rslt); + $ALL_status_SQL .= "'$row[0]',"; + $h++; + } + + $stmt="select distinct status from vicidial_campaign_statuses $whereLOGallowed_campaignsSQL order by status;"; + $rslt=mysql_to_mysqli($stmt, $link); + if ($DB) {echo "$stmt\n";} + $ALL_available_Cstatuses = mysqli_num_rows($rslt); + $j=0; + while ($j < $ALL_available_Cstatuses) + { + $row=mysqli_fetch_row($rslt); + $ALL_status_SQL .= "'$row[0]',"; + $j++; + } + + $i=0; while($i < $status_ct) { @@ -532,7 +638,8 @@ if ($run_export > 0) } if ( (preg_match('/\-\-ALL\-\-/',$status_string) ) or ($status_ct < 1) ) { - $status_SQL = ""; + $status_SQL = preg_replace('/,$/i', '',$ALL_status_SQL); + $status_SQL = "and vi.status IN($status_SQL)"; } else {