diff --git a/bin/ADMIN_keepalive_ALL.pl b/bin/ADMIN_keepalive_ALL.pl index 09d0c0a5..53d05f99 100644 --- a/bin/ADMIN_keepalive_ALL.pl +++ b/bin/ADMIN_keepalive_ALL.pl @@ -15,7 +15,7 @@ # - Auto reset lists at defined times # - Auto restarts Asterisk process if enabled in servers settings # -# Copyright (C) 2023 Matt Florell LICENSE: AGPLv2 +# Copyright (C) 2024 Matt Florell LICENSE: AGPLv2 # # CHANGES # 61011-1348 - First build @@ -170,9 +170,10 @@ # 230925-1454 - Added -recmon settings # 231136-2158 - Added hopper_hold_inserts HCI lead reservations clearing for old reservations # 231129-0849 - Added reset of vicidial_phone_number_call_daily_counts table +# 240401-1810 - Added purging of vicidial_pending_ar records older than 7 days # -$build = '231129-0849'; +$build = '240401-1810'; $DB=0; # Debug flag $teodDB=0; # flag to log Timeclock End of Day processes to log file @@ -2202,6 +2203,24 @@ if ($timeclock_end_of_day_NOW > 0) ##### END vicidial_khomp_log end of day process removing records older than 7 days ##### + ##### BEGIN vicidial_pending_ar end of day process removing records older than 7 days ##### + $stmtA = "DELETE from vicidial_pending_ar where start_datetime < \"$SDSQLdate\";"; + if($DBX){print STDERR "\n|$stmtA|\n";} + $affected_rows = $dbhA->do($stmtA); + if($DB){print STDERR "\n|$affected_rows vicidial_pending_ar records older than 7 days purged|\n";} + if ($teodDB) {$event_string = "vicidial_pending_ar records older than 7 days purged: |$stmtA|$affected_rows|"; &teod_logger;} + + $stmtA = "optimize table vicidial_pending_ar;"; + if($DBX){print STDERR "\n|$stmtA|\n";} + $sthA = $dbhA->prepare($stmtA) or die "preparing: ",$dbhA->errstr; + $sthA->execute or die "executing: $stmtA ", $dbhA->errstr; + $sthArows=$sthA->rows; + @aryA = $sthA->fetchrow_array; + if ($DB) {print "|",$aryA[0],"|",$aryA[1],"|",$aryA[2],"|",$aryA[3],"|","\n";} + $sthA->finish(); + ##### END vicidial_pending_ar end of day process removing records older than 7 days ##### + + ##### BEGIN vicidial_two_factor_auth end of day process removing expired and older records ##### $stmtA = "DELETE from vicidial_two_factor_auth where (auth_exp_date < NOW()) or ( (auth_code_exp_date < NOW()) and (auth_stage != '1') );"; if($DBX){print STDERR "\n|$stmtA|\n";} @@ -5962,8 +5981,9 @@ if ($SSenable_auto_reports > 0) $r++; } - if ($DB) {print "Automated Reports DONE: $r\n";} + if ($DB) {print "Automated Reports launched: $r\n";} } + if ($DB) {print "Automated Reports DONE\n";} } ################################################################################ ##### END automated reports diff --git a/bin/AST_dialer_inventory_snapshot.pl b/bin/AST_dialer_inventory_snapshot.pl index f6acd8c1..5497c759 100644 --- a/bin/AST_dialer_inventory_snapshot.pl +++ b/bin/AST_dialer_inventory_snapshot.pl @@ -228,6 +228,7 @@ while (@group=$campaign_rslt->fetchrow_array) $inventory_ptnstr="|"; while (@row=$rslt->fetchrow_array) { + $row[0] =~ s/[^-_0-9\p{L}]//ugi; $dial_statuses.="$row[0] "; $inventory_statuses.="'$row[0]',"; $inventory_ptnstr.="$row[0]|"; @@ -383,6 +384,7 @@ sub GetListCount $new_count=0; $total_calls=0; while (@ct_row=$ct_rslt->fetchrow_array) { + $ct_row[0] =~ s/[^-_0-9\p{L}]//ugi; $list_start_inv+=$ct_row[2]; $total_calls+=($ct_row[1]*$ct_row[2]); if ($inventory_ptnstr=~/\|$ct_row[0]\|/ && $ct_row[1]=="0") {$new_count+=$ct_row[2];} diff --git a/bin/AST_email_web_report.pl b/bin/AST_email_web_report.pl index 37fb2083..a412489a 100644 --- a/bin/AST_email_web_report.pl +++ b/bin/AST_email_web_report.pl @@ -9,7 +9,7 @@ # # /usr/share/astguiclient/AST_email_web_report.pl --email-list=test@gmail.com --email-sender=test@test.com # -# Copyright (C) 2020 Matt Florell LICENSE: AGPLv2 +# Copyright (C) 2024 Matt Florell LICENSE: AGPLv2 # # CHANGES # 90225-1247 - First version @@ -22,6 +22,7 @@ # 170719-1242 - Added more debug and '8days' date option # 170825-1114 - Added report filename_override option # 200601-0941 - Added support to launch an SFTP process using settings containers, added settings container CLI option for Email/FTP settings +# 240401-1341 - Added vicidial_pending_ar table entries # $txt = '.txt'; @@ -521,6 +522,8 @@ if (length($report_id) > 1) $email_subject =~ s/--A--date--B--|--A--today--B--/$year-$mon-$mday/gi; $email_subject =~ s/--A--yesterday--B--/$Tyear-$Tmon-$Tmday/gi; $email_subject =~ s/--A--datetime--B--/$year-$mon-$mday $hour:$min:$sec/gi; + @php_script_url = $location =~ /([\w-]+\.php)/g; + $php_script = $php_script_url[0]; $location =~ s/\&/\\&/gi; $location =~ s/--A--today--B--/$year-$mon-$mday/gi; $location =~ s/--A--yesterday--B--/$Tyear-$Tmon-$Tmday/gi; @@ -543,6 +546,7 @@ if (length($report_id) > 1) $filename_override =~ s/--A--30days--B--/$Hyear-$Hmon-$Hmday/gi; $filename_override =~ s/--A--filedatetime--B--/$filedatetime/gi; if ($DB) {print "FINAL LOCATION: |$location|\n";} + if ($DB) {print "REPORT SCRIPT: |$php_script|\n";} if ($DB) {print "FILENAME OVERRIDE: |$filename_override|\n";} } else @@ -669,6 +673,11 @@ else } ### GRAB THE REPORT + +$stmtB="INSERT INTO vicidial_pending_ar SET start_datetime='$timestamp', user='$http_user', report_id='$report_id', php_script='$php_script', status='TRIGGERED', notes='';"; +$Iaffected_rows = $dbhA->do($stmtB); +if ($DB) {print "Pending AR entry inserted: $Iaffected_rows|$stmtB\n";} + if (!$Q) {print "Running Report $ship_date\n$location\n";} `/usr/bin/wget --auth-no-challenge --http-user=$http_user --http-password=$http_pass --output-document=/tmp/X$HTMLfile --output-file=/tmp/Y$HTMLfileLOG $location `; diff --git a/bin/AST_email_web_reportFTPSSL.pl b/bin/AST_email_web_reportFTPSSL.pl index 3573d2a6..37613173 100644 --- a/bin/AST_email_web_reportFTPSSL.pl +++ b/bin/AST_email_web_reportFTPSSL.pl @@ -20,11 +20,12 @@ # # MAKE SURE YOU TEST THAT THIS IS WORKING MANUALLY!!! # -# Copyright (C) 2022 Matt Florell LICENSE: AGPLv2 +# Copyright (C) 2024 Matt Florell LICENSE: AGPLv2 # # CHANGES # 200601-1047 - First version, based upon AST_email_web_report.pl # 221002-1603 - Added comments for optional additional FTPSSL variable: "OverridePASV" +# 240401-1343 - Added vicidial_pending_ar table entries # $txt = '.txt'; @@ -550,6 +551,8 @@ if (length($report_id) > 1) $email_subject =~ s/--A--date--B--|--A--today--B--/$year-$mon-$mday/gi; $email_subject =~ s/--A--yesterday--B--/$Tyear-$Tmon-$Tmday/gi; $email_subject =~ s/--A--datetime--B--/$year-$mon-$mday $hour:$min:$sec/gi; + @php_script_url = $location =~ /([\w-]+\.php)/g; + $php_script = $php_script_url[0]; $location =~ s/\&/\\&/gi; $location =~ s/--A--today--B--/$year-$mon-$mday/gi; $location =~ s/--A--yesterday--B--/$Tyear-$Tmon-$Tmday/gi; @@ -572,6 +575,7 @@ if (length($report_id) > 1) $filename_override =~ s/--A--30days--B--/$Hyear-$Hmon-$Hmday/gi; $filename_override =~ s/--A--filedatetime--B--/$filedatetime/gi; if ($DB) {print "FINAL LOCATION: |$location|\n";} + if ($DB) {print "REPORT SCRIPT: |$php_script|\n";} if ($DB) {print "FILENAME OVERRIDE: |$filename_override|\n";} } else @@ -656,6 +660,11 @@ else } ### GRAB THE REPORT + +$stmtB="INSERT INTO vicidial_pending_ar SET start_datetime='$timestamp', user='$http_user', report_id='$report_id', php_script='$php_script', status='TRIGGERED', notes='';"; +$Iaffected_rows = $dbhA->do($stmtB); +if ($DB) {print "Pending AR entry inserted: $Iaffected_rows|$stmtB\n";} + if (!$Q) {print "Running Report $ship_date\n$location\n";} `/usr/bin/wget --auth-no-challenge --http-user=$http_user --http-password=$http_pass --output-document=/tmp/X$HTMLfile --output-file=/tmp/Y$HTMLfileLOG $location `; diff --git a/bin/AST_email_web_reportSFTP.pl b/bin/AST_email_web_reportSFTP.pl index 8d1540f2..981a15e2 100644 --- a/bin/AST_email_web_reportSFTP.pl +++ b/bin/AST_email_web_reportSFTP.pl @@ -17,10 +17,11 @@ # # MAKE SURE YOU TEST THAT THIS IS WORKING MANUALLY!!! # -# Copyright (C) 2020 Matt Florell LICENSE: AGPLv2 +# Copyright (C) 2024 Matt Florell LICENSE: AGPLv2 # # CHANGES # 200601-1047 - First version, based upon AST_email_web_report.pl +# 240401-1342 - Added vicidial_pending_ar table entries # $txt = '.txt'; @@ -532,6 +533,8 @@ if (length($report_id) > 1) $email_subject =~ s/--A--date--B--|--A--today--B--/$year-$mon-$mday/gi; $email_subject =~ s/--A--yesterday--B--/$Tyear-$Tmon-$Tmday/gi; $email_subject =~ s/--A--datetime--B--/$year-$mon-$mday $hour:$min:$sec/gi; + @php_script_url = $location =~ /([\w-]+\.php)/g; + $php_script = $php_script_url[0]; $location =~ s/\&/\\&/gi; $location =~ s/--A--today--B--/$year-$mon-$mday/gi; $location =~ s/--A--yesterday--B--/$Tyear-$Tmon-$Tmday/gi; @@ -554,6 +557,7 @@ if (length($report_id) > 1) $filename_override =~ s/--A--30days--B--/$Hyear-$Hmon-$Hmday/gi; $filename_override =~ s/--A--filedatetime--B--/$filedatetime/gi; if ($DB) {print "FINAL LOCATION: |$location|\n";} + if ($DB) {print "REPORT SCRIPT: |$php_script|\n";} if ($DB) {print "FILENAME OVERRIDE: |$filename_override|\n";} } else @@ -638,6 +642,11 @@ else } ### GRAB THE REPORT + +$stmtB="INSERT INTO vicidial_pending_ar SET start_datetime='$timestamp', user='$http_user', report_id='$report_id', php_script='$php_script', status='TRIGGERED', notes='';"; +$Iaffected_rows = $dbhA->do($stmtB); +if ($DB) {print "Pending AR entry inserted: $Iaffected_rows|$stmtB\n";} + if (!$Q) {print "Running Report $ship_date\n$location\n";} `/usr/bin/wget --auth-no-challenge --http-user=$http_user --http-password=$http_pass --output-document=/tmp/X$HTMLfile --output-file=/tmp/Y$HTMLfileLOG $location `; diff --git a/bin/AST_flush_DBqueue.pl b/bin/AST_flush_DBqueue.pl index 25e0b060..81e42a24 100644 --- a/bin/AST_flush_DBqueue.pl +++ b/bin/AST_flush_DBqueue.pl @@ -298,14 +298,15 @@ if ($sthArows > 0) $sthA->finish(); ### Grab system_settings values from the database -$stmtA = "SELECT sip_event_logging FROM system_settings limit 1;"; +$stmtA = "SELECT sip_event_logging,enable_auto_reports FROM system_settings limit 1;"; $sthA = $dbhA->prepare($stmtA) or die "preparing: ",$dbhA->errstr; $sthA->execute or die "executing: $stmtA ", $dbhA->errstr; $sthArows=$sthA->rows; if ($sthArows > 0) { @aryA = $sthA->fetchrow_array; - $SSsip_event_logging = $aryA[0]; + $SSsip_event_logging = $aryA[0]; + $SSenable_auto_reports = $aryA[1]; } $sthA->finish(); @@ -637,6 +638,26 @@ if (!$T) } if (!$Q) {print " - OPTIMIZE vicidial_3way_press_multi \n";} +if ($SSenable_auto_reports > 0) + { + $stmtA = "UPDATE vicidial_pending_ar SET status='ERROR' where status='TRIGGERED' and start_datetime < '$SQLdate_NEG_tenminute';"; + if($DB){print STDERR "\n|$stmtA|\n";} + if (!$T) { $affected_rows = $dbhA->do($stmtA);} + if (!$Q) {print " - vicidial_pending_ar flush: $affected_rows rows\n";} + + $stmtA = "OPTIMIZE table vicidial_pending_ar;"; + if($DB){print STDERR "\n|$stmtA|\n";} + if (!$T) + { + $sthA = $dbhA->prepare($stmtA) or die "preparing: ",$dbhA->errstr; + $sthA->execute or die "executing: $stmtA ", $dbhA->errstr; + $sthArows=$sthA->rows; + @aryA = $sthA->fetchrow_array; + if (!$Q) {print "|",$aryA[0],"|",$aryA[1],"|",$aryA[2],"|",$aryA[3],"|","\n";} + $sthA->finish(); + } + if (!$Q) {print " - OPTIMIZE vicidial_pending_ar \n";} + } $stmtA = "DELETE from server_live_stats where update_time < '$DQLdate_NEG_twelvehour';"; if($DB){print STDERR "\n|$stmtA|\n";} diff --git a/docs/Inbound_line_controls.pdf b/docs/Inbound_line_controls.pdf new file mode 100644 index 00000000..295d8ccf Binary files /dev/null and b/docs/Inbound_line_controls.pdf differ diff --git a/docs/VICIDIAL_statuses.txt b/docs/VICIDIAL_statuses.txt index 3ab04810..485291ec 100644 --- a/docs/VICIDIAL_statuses.txt +++ b/docs/VICIDIAL_statuses.txt @@ -83,3 +83,5 @@ SRDROP - SHARED outbound campaign drop to in-group, not included in most DROP st HUCXXX - Enhanced Disconnect Logging level 3 failed calls, where 'XXX' is the disconnect code. For example: "HUC18" for Cause 18 (SIP 408 Request timeout) ADAIR - Dead Air Auto, for AMD NOAUDIODATA calls ACFLTR - Inbound call areacode filter check +LTMGAD - Campaign HotKey option, will transfer customer to voicemail message and disposition the call +XAMMAD - Campaign HotKey option, will transfer customer to voicemail message and disposition the call diff --git a/extras/MySQL_AST_CREATE_tables.sql b/extras/MySQL_AST_CREATE_tables.sql index 5dc693b0..e060733d 100644 --- a/extras/MySQL_AST_CREATE_tables.sql +++ b/extras/MySQL_AST_CREATE_tables.sql @@ -5233,6 +5233,32 @@ mb_available BIGINT(14) default '0', unique index livepartitions (server_ip, partition_path) ) ENGINE=MyISAM; +CREATE TABLE inbound_disabled_entries ( +interval_id INT(10) UNSIGNED NOT NULL AUTO_INCREMENT PRIMARY KEY, +start_datetime DATETIME, +end_datetime datetime, +location VARCHAR(50), +message VARCHAR(100), +message_type ENUM('MEETING','CLOSED','WEATHER','CUSTOM'), +status ENUM('ACTIVE','LIVE','COMPLETED','CANCELLED') DEFAULT 'ACTIVE', +user VARCHAR(20), +modify_date TIMESTAMP NOT NULL DEFAULT current_timestamp() ON UPDATE current_timestamp(), +modified_by VARCHAR(20), +holiday_id VARCHAR(30), +KEY inbound_disabled_entries_key (start_datetime,end_datetime,location) +) ENGINE=MyISAM; + +CREATE TABLE vicidial_pending_ar ( +ar_id INT(10) UNSIGNED NOT NULL AUTO_INCREMENT PRIMARY KEY, +report_id VARCHAR(30) default '', +start_datetime DATETIME, +php_script VARCHAR(50) default '', +user VARCHAR(20), +status ENUM('TRIGGERED','AUTHORIZED','COMPLETED','ERROR') DEFAULT 'TRIGGERED', +notes TEXT, +KEY pending_ar_key (user,start_datetime) +) ENGINE=MyISAM; + ALTER TABLE vicidial_email_list MODIFY message text character set utf8; @@ -5632,4 +5658,4 @@ INSERT INTO `wallboard_reports` VALUES ('AGENTS_AND_QUEUES','Agents and Queues', UPDATE system_settings set vdc_agent_api_active='1'; -UPDATE system_settings SET db_schema_version='1710',db_schema_update_date=NOW(),reload_timestamp=NOW(); +UPDATE system_settings SET db_schema_version='1711',db_schema_update_date=NOW(),reload_timestamp=NOW(); diff --git a/extras/inbound_line_controls.php b/extras/inbound_line_controls.php new file mode 100644 index 00000000..356228ad --- /dev/null +++ b/extras/inbound_line_controls.php @@ -0,0 +1,2040 @@ + 0) + { + $row=mysqli_fetch_row($rslt); + $non_latin = $row[0]; + $SSoutbound_autodial_active = $row[1]; + $slave_db_server = $row[2]; + $reports_use_slave_db = $row[3]; + $user_territories_active = $row[4]; + $webroot_writable = $row[5]; + $allow_emails = $row[6]; + $SSlevel_8_disable_add = $row[7]; + $SSenable_languages = $row[8]; + $SSlanguage_method = $row[9]; + $log_recording_access = $row[10]; + $SSadmin_screen_colors = $row[11]; + $SSmute_recordings = $row[12]; + $sounds_web_server = $row[13]; + $sounds_web_directory = $row[14]; + $admin_web_dir = $row[15]; + $SSallow_web_debug = $row[16]; + } + +if (!preg_match('/^http/', $sounds_web_server)) {$http_prefix="http://";} else {$http_prefix="";} +if ($SSallow_web_debug < 1) {$DB=0;} +##### END SETTINGS LOOKUP ##### +########################################### + +$DB=preg_replace("/[^0-9a-zA-Z]/","",$DB); +$from_date = preg_replace('/[^\-0-9]/', '', $from_date); +$from_hour = preg_replace('/[^0-9]/', '', $from_hour); +$from_min = preg_replace('/[^0-9]/', '', $from_min); +$to_date = preg_replace('/[^\-0-9]/', '', $to_date); +$to_hour = preg_replace('/[^0-9]/', '', $to_hour); +$to_min = preg_replace('/[^0-9]/', '', $to_min); +$insert_flag = preg_replace('/[^0-9]/', '', $insert_flag); +$interval_id = preg_replace('/[^0-9]/', '', $interval_id); + +if ($non_latin < 1) + { + $PHP_AUTH_USER = preg_replace('/[^-_0-9a-zA-Z]/', '', $PHP_AUTH_USER); + $PHP_AUTH_PW = preg_replace('/[^-_0-9a-zA-Z]/', '', $PHP_AUTH_PW); + $default_submit = preg_replace('/[^-_\s0-9a-zA-Z]/', '', $default_submit); + $location = preg_replace('/[^-_0-9a-zA-Z]/', '', $location); + $message_type = preg_replace('/[^a-zA-Z]/', '', $message_type); + $audio_file = preg_replace('/[^-_0-9a-zA-Z]/', '', $audio_file); + $meeting_field = preg_replace('/[^-_0-9a-zA-Z]/', '', $meeting_field); + $closed_field = preg_replace('/[^-_0-9a-zA-Z]/', '', $closed_field); + $weather_field = preg_replace('/[^-_0-9a-zA-Z]/', '', $weather_field); + $holiday_field = preg_replace('/[^-_0-9a-zA-Z]/', '', $holiday_field); + $custom_field = preg_replace('/[^-_0-9a-zA-Z]/', '', $custom_field); + $holiday_id = preg_replace('/[^-_0-9a-zA-Z]/','',$holiday_id); + $action = preg_replace('/[^-_0-9a-zA-Z]/', '', $action); + $message = preg_replace('/[^-_0-9a-zA-Z]/', '', $message); + } +else + { + $PHP_AUTH_USER = preg_replace('/[^\-_0-9\p{L}]/u', '', $PHP_AUTH_USER); + $PHP_AUTH_PW = preg_replace('/[^\-_0-9\p{L}]/u', '', $PHP_AUTH_PW); + $default_submit = preg_replace('/[^\-_\s0-9\p{L}]/u', '', $default_submit); + $location = preg_replace('/[^\-_0-9\p{L}]/u', '', $location); + $message_type = preg_replace('/[^\p{L}]/u', '', $message_type); + $audio_file = preg_replace('/[^\-_0-9\p{L}]/u', '', $audio_file); + $meeting_field = preg_replace('/[^\-_0-9\p{L}]/u', '', $meeting_field); + $closed_field = preg_replace('/[^\-_0-9\p{L}]/u', '', $closed_field); + $weather_field = preg_replace('/[^\-_0-9\p{L}]/u', '', $weather_field); + $holiday_field = preg_replace('/[^-_0-9\p{L}]/', '', $holiday_field); + $custom_field = preg_replace('/[^\-_\.0-9\p{L}]/u', '', $custom_field); + $holiday_id = preg_replace('/[^\-_0-9\p{L}]/u','',$holiday_id); + $action = preg_replace('/[^\-_0-9\p{L}]/u', '', $action); + $message = preg_replace('/[^\-_0-9\p{L}]/u', '', $message); + } + + + +$user_auth=0; +$auth=0; +$reports_auth=0; +$qc_auth=0; +$auth_message = user_authorization($PHP_AUTH_USER,$PHP_AUTH_PW,'QC',1,0); +if ($auth_message == 'GOOD') + {$user_auth=1;} + +if ($auth_message == 'GOOD') + {$user_auth=1;} + +if ($user_auth > 0) + { + $stmt="SELECT count(*) from vicidial_users where user='$PHP_AUTH_USER' and user_level > 7 and api_only_user != '1';"; + if ($DB) {echo "|$stmt|\n";} + $rslt=mysql_to_mysqli($stmt, $link); + $row=mysqli_fetch_row($rslt); + $auth=$row[0]; + + $stmt="SELECT count(*) from vicidial_users where user='$PHP_AUTH_USER' and user_level > 6 and view_reports='1' and api_only_user != '1';"; + if ($DB) {echo "|$stmt|\n";} + $rslt=mysql_to_mysqli($stmt, $link); + $row=mysqli_fetch_row($rslt); + $reports_auth=$row[0]; + + $stmt="select user_level, user_group from vicidial_users where user='$PHP_AUTH_USER'"; + $rslt=mysql_to_mysqli($stmt, $link); + $row=mysqli_fetch_row($rslt); + $user_level=$row[0]; + + $reports_only_user=0; + $qc_only_user=0; + if ( ($reports_auth > 0) and ($auth < 1) ) + { + $ADD=999999; + $reports_only_user=1; + } + if ( ($reports_auth < 1) and ($auth < 1) ) + { + if ( ($ADD != '881') and ($ADD != '100000000000000') ) + { + $ADD=100000000000000; + } + $qc_only_user=1; + } + if ( ($reports_auth < 1) and ($auth < 1) ) + { + $VDdisplayMESSAGE = _QXZ("You do not have permission to be here"); + Header ("Content-type: text/html; charset=utf-8"); + echo "$VDdisplayMESSAGE: |$PHP_AUTH_USER|$auth_message|\n"; + exit; + } + if ( (strlen($VUuser_admin_redirect_url) > 5) and ($SSuser_admin_redirect > 0) ) + { + Header('Location: '.$VUuser_admin_redirect_url); + echo""._QXZ("Admin Redirect")."\n"; + echo"\n"; + echo"\n"; + echo"\n"; + echo"\n"; + echo""._QXZ("click here to continue").". . .\n"; + exit; + } + } +else + { + $VDdisplayMESSAGE = _QXZ("Login incorrect, please try again"); + if ($auth_message == 'LOCK') + { + $VDdisplayMESSAGE = _QXZ("Too many login attempts, try again in 15 minutes"); + Header ("Content-type: text/html; charset=utf-8"); + echo "$VDdisplayMESSAGE: |$PHP_AUTH_USER|$auth_message|\n"; + exit; + } + if ($auth_message == 'IPBLOCK') + { + $VDdisplayMESSAGE = _QXZ("Your IP Address is not allowed") . ": $ip"; + Header ("Content-type: text/html; charset=utf-8"); + echo "$VDdisplayMESSAGE: |$PHP_AUTH_USER|$auth_message|\n"; + exit; + } + Header("WWW-Authenticate: Basic realm=\"CONTACT-CENTER-ADMIN\""); + Header("HTTP/1.0 401 Unauthorized"); + echo "$VDdisplayMESSAGE: |$PHP_AUTH_USER|$PHP_AUTH_PW|$auth_message|\n"; + exit; + } + +$expected_files=array("meeting", "closed", "weather", "holiday", "custom"); +$container_default_str="^".implode("\s|^", $expected_files)."\s"; +$audio_file_str=implode("|", $expected_files); + +if ($default_submit=="Set as defaults") + { + $upd_container_text=""; + $found_files=array(); + + $container_stmt="select container_entry from vicidial_settings_containers where container_id='INBOUND_LINE_CONTROLS'"; + $container_rslt=mysql_to_mysqli($container_stmt, $link); + $container_row=mysqli_fetch_row($container_rslt); + # echo "\n"; + + $upd_stmt="UPDATE vicidial_settings_containers set container_entry='".mysqli_escape_string($link, $upd_container_text)."' where container_id='INBOUND_LINE_CONTROLS'"; + $upd_rslt=mysql_to_mysqli($upd_stmt, $link); + } + +$container_stmt="select container_entry from vicidial_settings_containers where container_id='INBOUND_LINE_CONTROLS'"; +$container_rslt=mysql_to_mysqli($container_stmt, $link); +$location_array=array(); +$audio_array=array(); +$locations_calltimes_array=array(); +$completed_days=1; + +if (mysqli_num_rows($container_rslt)==0) + { + echo "ERROR: This feature requires a settings container named 'INBOUND_LINE_CONTROLS'"; + echo ($user_level==9 ? "

Create a new settings container here" : ""); + echo "

Go back to admin"; + exit; + } + +$location_restrictions=array(); +$event_restrictions=array(); +while ($container_row=mysqli_fetch_row($container_rslt)) + { + $inbound_instructions=explode("\n", $container_row[0]); + for ($i=0; $i/', $inbound_instructions[$i])) + { + $instructions=explode("=>", $inbound_instructions[$i]); + if (preg_match('/^minimum_required_level_locations/', $instructions[0])) + { + $instructions[1]=preg_replace("/\s/", "", $instructions[1]); + $location_sets=explode("|", $instructions[1]); + for ($j=0; $j $required_user_level) + { + if($user_level<$required_user_level) + { + if (($index = array_search($current_location, $location_array)) !== false) + { + unset($location_array[$index]); + } + } + } +$location_array=array_values($location_array); + +foreach ($locations_calltimes_array as $active_location => $array) + { + $locations_calltimes_array["$active_location"]=array_unique($array); + } + +if ($action=="get_local_time") + { + echo date("Y-m-d-H-i"); + exit; + } + +if ($audio_file && $action=="move_audio_file") + { + $temp_filename = "../agc/polly/generated/".$audio_file; + passthru("cp $temp_filename ../$sounds_web_directory/"); + $success_msg="SUCCESS"."\n***"; + echo trim($success_msg); + + $stmt="UPDATE servers SET sounds_update='Y';"; + $rslt=mysql_to_mysqli($stmt, $link); + + ### LOG INSERTION Admin Log Table ### + $SQL_log = "$stmt|"; + $SQL_log = preg_replace('/;/', '', $SQL_log); + $SQL_log = addslashes($SQL_log); + $stmt="INSERT INTO vicidial_admin_log set event_date=NOW(), user='$PHP_AUTH_USER', ip_address='$ip', event_section='AUDIOSTORE', event_type='COPY', record_id='manualupload', event_code='$audio_file', event_sql=\"$SQL_log\", event_notes='NEW: $audio_file POLLY GENERATED';"; + if ($DB) {echo "|$stmt|\n";} + $rslt=mysql_to_mysqli($stmt, $link); + + exit; + } + +if ($action=="insert_interval" && $location && $message && $message_type && $from_date && $from_hour && $from_min && $to_date && $to_hour && $to_min) + { + $error_msg=""; + + $dup_stmt="select count(*) from inbound_disabled_entries where start_datetime='".$from_date." ".$from_hour.":".$from_min.":00' and end_datetime='".$to_date." ".$to_hour.":".$to_min.":00' and location in ('$location'".(preg_match('/\|/', $location) ? ", '".preg_replace('/\|/', "', '", $location)."'" : "").") and status in ('LIVE', 'ACTIVE')"; + $dup_rslt=mysql_to_mysqli($dup_stmt, $link); + $dup_row=mysqli_fetch_row($dup_rslt); + if ($dup_row[0]>0) + { + $error_msg.="ERROR: This interval (".$from_date." ".$from_hour.":".$from_min.":00 to ".$to_date." ".$to_hour.":".$to_min.":00 for ".preg_replace('/\|/', ", ", $location).") is already scheduled for a live/upcoming downtime"; + # $error_msg.="
$dup_stmt"; + } + + $msg_array=CheckHolidayConflicts($location, $locations_calltimes_array, $from_date, $from_hour, $from_min, $to_date, $to_hour, $to_min, "", 1); + + $error_msg.=$msg_array[0]; + $ok_msg=$msg_array[1]; + $interval_time_array=$msg_array[2]; + # echo "ERR: $error_msg

OK: $ok_msg"; + + # exit; + + if (strlen($error_msg)==0) + { + $holiday_id="AG_".date("YmdHis")."_".$message_type; + $ins_stmt="INSERT INTO inbound_disabled_entries(start_datetime, end_datetime, location, message, message_type, user, holiday_id) VALUES('".$from_date." ".$from_hour.":".$from_min.":00', '".$to_date." ".$to_hour.":".$to_min.":00', '$location', '$message', '$message_type', '$PHP_AUTH_USER', '$holiday_id')"; + $ins_rslt=mysql_to_mysqli($ins_stmt, $link); + if (mysqli_affected_rows($link)>0) + { + + $h=1; + foreach ($interval_time_array as $date => $times) + { + $VD_holiday_id=$holiday_id."_".$h; + $holiday_stmt="insert into vicidial_call_time_holidays VALUES('$VD_holiday_id', 'Play $message_type $message message', 'Created by $PHP_AUTH_USER on ".date("Y-m-d H:i:s")." to be played $date', '$date', 'ACTIVE', '".$times["start"]."', '".$times["end"]."', '$message', 'LOCKED_HOLIDAY', 'ADDITION_REVERSE')"; + # echo $holiday_stmt."
"; + $holiday_rslt=mysql_to_mysqli($holiday_stmt, $link); + + $selected_locations=explode("|", $location); + for ($n=0; $n0) + { + $row=mysqli_fetch_row($rslt); + $ct_holidays = $row[0]; + + if (preg_match('/\|$/i',$ct_holidays)) + {$ct_holidays = "$ct_holidays$VD_holiday_id\|";} + else + {$ct_holidays = "$ct_holidays\|$VD_holiday_id\|";} + $stmt="UPDATE vicidial_call_times set ct_holidays='$ct_holidays' where call_time_id='".$call_time."';"; + $rslt=mysql_to_mysqli($stmt, $link); + + ### LOG INSERTION Admin Log Table ### + $SQL_log = "$stmt|"; + $SQL_log = preg_replace('/;/', '', $SQL_log); + $SQL_log = addslashes($SQL_log); + $stmt="INSERT INTO vicidial_admin_log set event_date=now(), user='$PHP_AUTH_USER', ip_address='$ip', event_section='CALLTIMES', event_type='MODIFY', record_id='".$call_time."', event_code='ADMIN MODIFY CALL TIME ADD HOLIDAY RULE', event_sql=\"$SQL_log\", event_notes='Holiday Rule Added: $VD_holiday_id';"; + if ($DB) {echo "|$stmt|\n";} + $rslt=mysql_to_mysqli($stmt, $link); + } + } + } + } + $h++; + } + } + header("Location: $PHP_SELF"); + } + else + { + # echo "ERROR: $error_msg"; + } + } + +if ($action=="update_interval" && $interval_id && $holiday_id && $from_date && $from_hour && $from_min && $to_date && $to_hour && $to_min) + { + $msg_array=CheckHolidayConflicts($location, $locations_calltimes_array, $from_date, $from_hour, $from_min, $to_date, $to_hour, $to_min, $holiday_id, 0); + + $error_msg=$msg_array[0]; + $ok_msg=$msg_array[1]; + $interval_time_array=$msg_array[2]; + # echo "ERR: $error_msg

OK: $ok_msg"; + + + if (strlen($error_msg)==0) + { + $upd_stmt="UPDATE inbound_disabled_entries set start_datetime='".$from_date." ".$from_hour.":".$from_min.":00', end_datetime='".$to_date." ".$to_hour.":".$to_min.":00', modified_by='$PHP_AUTH_USER' where interval_id='$interval_id' "; + $upd_rslt=mysql_to_mysqli($upd_stmt, $link); + if (mysqli_affected_rows($link)>0) + { + echo "SUCCESS\n"; + + # Get interval info in case more inserts need to be done + $int_stmt="select * from inbound_disabled_entries where interval_id='$interval_id'"; + $int_rslt=mysql_to_mysqli($int_stmt, $link); + while($int_row=mysqli_fetch_array($int_rslt)) + { + $message=$int_row["message"]; + $message_type=$int_row["message_type"]; + $upd_location=$int_row["location"]; + } + + $ct_stmt=""; + + # Update holidays table anything that is now not in the date range + # $holiday_stmt="UPDATE vicidial_call_time_holidays set holiday_status='INACTIVE' where holiday_id like '$holiday_id%' and holiday_date not in ('".implode("', '", array_keys($interval_time_array))."')"; + $holiday_stmt="DELETE from vicidial_call_time_holidays where holiday_id like '$holiday_id%'"; + $holiday_rslt=mysql_to_mysqli($holiday_stmt, $link); + $ct_stmt.="$holiday_stmt|"; + + # Remove old holidays + $selected_locations=explode("|", $upd_location); + for ($n=0; $n0) + { + $row=mysqli_fetch_row($rslt); + $ct_holidays = $row[0]; + + $holiday_pattern=$holiday_id."\_[0-9]+"; + $ct_holidays = preg_replace("/$holiday_pattern/i", '', $ct_holidays); + $ct_holidays = preg_replace("/\|+/", '|', $ct_holidays); + $stmt="UPDATE vicidial_call_times set ct_holidays='$ct_holidays' where call_time_id='".$call_time."';"; + $rslt=mysql_to_mysqli($stmt, $link); + } + } + } + } + + /* Unnecessary with above switching to 'DELETE + # Get latest ID in case update adds a new day to the range necessitating a new holiday + $latest_stmt="select holiday_id from vicidial_call_time_holidays where holiday_id like '$holiday_id%' order by holiday_id desc limit 1"; + $latest_rslt=mysql_to_mysqli($latest_stmt, $link); + while($latest_row=mysqli_fetch_row($latest_rslt)) + { + $h=$latest_row[0]; + $h=preg_replace("/$holiday_id/", "", $h); + $h=preg_replace("/[^0-9]/", "", $h); + } + */ + + $h=1; + foreach ($interval_time_array as $date => $times) + { + /* Unnecessary with above switching to 'DELETE + #$holiday_stmt="select count(*) From vicidial_call_time_holidays where holiday_id like '$holiday_id%' and holiday_date='$date'"; + #$holiday_rslt=mysql_to_mysqli($holiday_stmt, $link); + #$holiday_ct=mysqli_fetch_row($holiday_rslt); + + #if ($holiday_ct[0]==0) + # { + */ + + $VD_holiday_id=$holiday_id."_".$h; + $holiday_stmt_ins="INSERT into vicidial_call_time_holidays VALUES('$VD_holiday_id', 'Play $message_type $message message', 'Added by $PHP_AUTH_USER on ".date("Y-m-d H:i:s")." to be played $date', '$date', 'ACTIVE', '".$times["start"]."', '".$times["end"]."', '$message', 'LOCKED_HOLIDAY', 'ADDITION_REVERSE')"; + $holiday_rslt_ins=mysql_to_mysqli($holiday_stmt_ins, $link); + $ct_stmt.="$holiday_stmt_ins|"; + + $selected_locations=explode("|", $upd_location); + for ($n=0; $n0) + { + $row=mysqli_fetch_row($rslt); + $ct_holidays = $row[0]; + + if (preg_match('/\|$/i',$ct_holidays)) + {$ct_holidays = "$ct_holidays$VD_holiday_id\|";} + else + {$ct_holidays = "$ct_holidays\|$VD_holiday_id\|";} + $stmt="UPDATE vicidial_call_times set ct_holidays='$ct_holidays' where call_time_id='".$call_time."';"; + $rslt=mysql_to_mysqli($stmt, $link); + + ### LOG INSERTION Admin Log Table ### + $SQL_log = "$stmt|"; + $SQL_log = preg_replace('/;/', '', $SQL_log); + $SQL_log = addslashes($SQL_log); + $stmt="INSERT INTO vicidial_admin_log set event_date=now(), user='$PHP_AUTH_USER', ip_address='$ip', event_section='CALLTIMES', event_type='MODIFY', record_id='".$call_time."', event_code='ADMIN MODIFY CALL TIME MODIFY HOLIDAY RULE', event_sql=\"$SQL_log\", event_notes='Holiday Rule Added: $VD_holiday_id';"; + if ($DB) {echo "|$stmt|\n";} + $rslt=mysql_to_mysqli($stmt, $link); + } + } + } + } + $h++; + + /* Unnecessary with above switching to 'DELETE + } + else + { + $holiday_stmt_upd="UPDATE vicidial_call_time_holidays set holiday_status='ACTIVE', ct_default_start='".$times["start"]."', ct_default_stop='".$times["end"]."' where holiday_id like '$holiday_id%' and holiday_date='$date'"; + $holiday_rslt_upd=mysql_to_mysqli($holiday_stmt_upd, $link); + $ct_stmt.="$holiday_stmt_upd|"; + } + */ + + $upd_stmt="update inbound_disabled_entries set status='LIVE' where status='ACTIVE' and start_datetime<=now() and end_datetime>=now()"; + $upd_rslt=mysql_to_mysqli($upd_stmt, $link); + } + + $inb_stmt="select * from inbound_disabled_entries where interval_id='$interval_id'"; + $inb_rslt=mysql_to_mysqli($inb_stmt, $link); + if (mysqli_num_rows($inb_rslt)>0) + { + $row=mysqli_fetch_array($inb_rslt); + $location=preg_replace('/\|/', ', ', $row["location"]); + + $full_name=""; + $fn_stmt="select full_name from vicidial_users where user='$row[user]'"; + $fn_rslt=mysql_to_mysqli($fn_stmt, $link); + if(mysqli_num_rows($fn_rslt)>0) + { + $fn_row=mysqli_fetch_row($fn_rslt); + $full_name=", $fn_row[0]"; + } + + ### LOG INSERTION Admin Log Table ### + $SQL_log = "$ct_stmt"; + $SQL_log = preg_replace('/;/', '', $SQL_log); + $SQL_log = addslashes($SQL_log); + $stmt="INSERT INTO vicidial_admin_log set event_date=now(), user='$PHP_AUTH_USER', ip_address='$ip', event_section='CALLTIMES', event_type='MODIFY', record_id='$holiday_id', event_code='ADMIN MODIFY CALL TIME CHANGE HOLIDAY RULE', event_sql=\"$SQL_log\", event_notes='".$call_time."';"; + if ($DB) {echo "|$stmt|\n";} + $rslt=mysql_to_mysqli($stmt, $link); + + + echo "UPDATED: Inbound $location lines are currently down from $row[start_datetime] to $row[end_datetime], requested by $row[user]$full_name\n"; + echo "$row[start_datetime]|$row[end_datetime]|".date("Y-m-d H:i:s")."|$row[user]$full_name\n"; + } + $current_time=date("YmdHi"); + $upd_from_time=preg_replace('/[^0-9]/', '', $from_date.$from_hour.$from_min); + + if ($current_time>=$upd_from_time) {echo "RELOAD_IMMEDIATELY";} + exit; + } + else + { + echo "FAILED"; + exit; + } + } + else + { + echo "FAILED\n$error_msg"; + exit; + } + } + +if ($action=="delete_interval" && $interval_id && $holiday_id) + { + $del_stmt="UPDATE inbound_disabled_entries set status='CANCELLED', modified_by='$PHP_AUTH_USER' where status in ('ACTIVE', 'LIVE') and interval_id='$interval_id'"; + $del_rslt=mysql_to_mysqli($del_stmt, $link); + if (mysqli_affected_rows($link)>0) + { + $data_stmt="select * from inbound_disabled_entries where interval_id='$interval_id'"; + $data_rslt=mysql_to_mysqli($data_stmt, $link); + $data_row=mysqli_fetch_array($data_rslt); + $location=$data_row["location"]; + + $location_array_delete=explode("|", $location); + for ($n=0; $n"; + $rslt=mysql_to_mysqli($stmt, $link); + + ### LOG INSERTION Admin Log Table ### + $SQL_log = "$stmt|"; + $SQL_log = preg_replace('/;/', '', $SQL_log); + $SQL_log = addslashes($SQL_log); + $stmt="INSERT INTO vicidial_admin_log set event_date=now(), user='$PHP_AUTH_USER', ip_address='$ip', event_section='CALLTIMES', event_type='MODIFY', record_id='$call_time_id', event_code='ADMIN MODIFY CALL TIME REMOVE HOLIDAY RULE', event_sql=\"$SQL_log\", event_notes='".$call_time."';"; + if ($DB) {echo "|$stmt|\n";} + $rslt=mysql_to_mysqli($stmt, $link); + } + } + } + +# echo _QXZ("Holiday Rule Removed").": $holiday_rule
\n"; + + $ct_stmt="UPDATE vicidial_call_time_holidays set holiday_status='INACTIVE' where holiday_id like '$holiday_id%'"; + $ct_rslt=mysql_to_mysqli($ct_stmt, $link); + + header("Location: $PHP_SELF"); + } + } + + + +function CheckHolidayConflicts($locale, $locale_calltimes_array, $fdate, $fhour, $fmin, $tdate, $thour, $tmin, $holiday_id, $DB) + { + global $link; + + $error_msg=""; + $ok_msg=""; + $start_period=strtotime($fdate); + $end_period=strtotime($tdate); + + $interval_time_array=array(); + for ($period=$start_period; $period<=$end_period; $period+=86400) { + $key=date('Y-m-d', $period); + $start_time="0000"; + $end_time="2359"; + if ($key==$fdate) {$start_time=$fhour.$fmin;} + if ($key==$tdate) {$end_time=$thour.$tmin;} + $interval_time_array["$key"]["start"]=$start_time; + $interval_time_array["$key"]["end"]=$end_time; + } + + + /* Skip ALL this, as duplicate entries are fine + + if ($DB) {print_r($interval_time_array);} + if ($DB) {"

".print_r($interval_holiday_array);} + + $location_array=explode("|", $locale); + for ($n=0; $nLocation: ".$locale."
";} + + $all_ct_holidays=array(); + $dup_check_stmt="select ct_holidays From vicidial_call_times where call_time_id in ('".implode("', '", $call_times_array)."') and ct_holidays is not null and length(ct_holidays)>=2"; + $dup_check_rslt=mysql_to_mysqli($dup_check_stmt, $link); + + if ($DB) {echo $dup_check_stmt."
";} + + while($dc_row=mysqli_fetch_row($dup_check_rslt)) + { + $ct_array=explode("|", $dc_row[0]); + $ct_array=array_filter($ct_array); + $all_ct_holidays=array_merge($all_ct_holidays, $ct_array); + } + $all_ct_holidays=array_unique($all_ct_holidays); + print_r($all_ct_holidays); + + $active_holidays=array(); + $holiday_stmt="select holiday_id, holiday_date, ct_default_start, ct_default_stop from vicidial_call_time_holidays where holiday_id in ('".implode("', '", $all_ct_holidays)."') and holiday_date in ('".implode("', '", array_keys($interval_time_array))."') and holiday_status='ACTIVE'"; + if ($holiday_id) {$holiday_stmt.=" and holiday_id not like '".$holiday_id."%'";} + $holiday_rslt=mysql_to_mysqli($holiday_stmt, $link); + # if ($DB) {echo $holiday_stmt."
"; print_r($holiday_rslt); exit;} + while ($holiday_row=mysqli_fetch_array($holiday_rslt)) + { + $holiday_id=$holiday_row["holiday_id"]; + $holiday_date=$holiday_row["holiday_date"]; + $ct_default_start=$holiday_row["ct_default_start"]; + $ct_default_stop=$holiday_row["ct_default_stop"]; + + foreach ($interval_time_array as $date => $times) + { + $date=preg_replace('/X/', '', $date); + if ($holiday_date==$date) + { + if (($times["start"]<$ct_default_start && $ct_default_start<$times["end"]) || ($times["start"]<$ct_default_stop && $ct_default_stop<$times["end"])) + { + $error_msg.="ERROR: New interval conflicts with holiday $holiday_id on $holiday_date. Interval covers $times[start] to $times[end] - Holiday covers $ct_default_start to $ct_default_stop
"; + } + else + { + $ok_msg.="OK - Interval shares date with holiday $holiday_id on $holiday_date. Interval covers $times[start] to $times[end] - Holiday covers $ct_default_start to $ct_default_stop
"; + } + } + } + } + } + */ + return array($error_msg, $ok_msg, $interval_time_array); + } + + + +### UPDATE INTERVAL STATUSES +$upd_stmt="update inbound_disabled_entries set status='LIVE' where status='ACTIVE' and start_datetime<=now() and end_datetime>=now()"; +$upd_rslt=mysql_to_mysqli($upd_stmt, $link); + +$upd_stmt="update inbound_disabled_entries set status='COMPLETED' where status in ('LIVE', 'ACTIVE') and end_datetime<=now()"; +$upd_rslt=mysql_to_mysqli($upd_stmt, $link); + +$HEADER.="\n"; +$HEADER.="\n"; +$HEADER.="\n"; +$HEADER.="\n"; + +$HEADER.="\n"; + +$HEADER.="\n"; +$HEADER.="\n"; + +$HEADER.="\n"; + +$HEADER.="\n"; +$HEADER.="VOX inbound line controls\n"; + +header ("Content-type: text/html; charset=utf-8"); +echo $HEADER; +require("admin_header.php"); + +echo "
"; +echo "\n"; +?> + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +0) + { + echo ""; + echo ""; + echo ""; + } +?> + +=now(), 0, 1) as live, if(status='LIVE', 0, if(status='ACTIVE', 1, 2)) as dispo_rank from inbound_disabled_entries where status in ('ACTIVE', 'LIVE') order by dispo_rank asc, location desc, live asc, start_datetime asc"; +$rslt=mysql_to_mysqli($stmt, $link); +if (mysqli_num_rows($rslt)>0) + { + echo "\n"; + echo "\t
\n"; +# echo $holiday_stmt."
"; +echo "Inbound line controls:"; +echo "
 
These settings will disable the inbound lines for the selected locations:
1) Please select the locations that you wish to disable Inbound calling:
+ ".trim($location_array[$l])."
\n"; + } + $k++; + echo "All locations"; + + ?> +
2) + + + + + +  \n"; + + $event_cols=5; + foreach ($event_restrictions as $current_event => $required_user_level) + { + if(in_array($current_event, $expected_files) && $user_level<$required_user_level) + { + $event_cols--; + } + } + + for ($i=0; $i=$event_restrictions["$event"]) + { + echo "\t\t\t\n"; + } + } + ?> + + + + + ".($user_level==9 ? "==>>" : "")."\n"; + + for ($i=0; $i=$event_restrictions["$event"]) + { + echo ""; + } + } +/* + echo ""; + + echo ""; + + echo " + + + + +
While the inbound lines are down, please play the following turn-away message:   (edit default messages)" : ""); ?>
\n"; + echo "\t\t\t\t".ucfirst($event)." "; + echo ($user_level>=$mand_lvl ? "change" : ""); + echo "\n\t\t\t
"; + echo ""; + echo ""; + echo ($audio_array["$event"] ? "".$audio_array["$event"]."" : "(none set)"); + echo ""; + echo ""; + echo ""; + echo ""; + echo ($audio_array["closed"] ? "".$audio_array["closed"]."" : "(none set)"); + echo ""; + echo ""; + echo ""; + echo ""; + echo ($audio_array["weather"] ? "".$audio_array["weather"]."" : "(none set)"); + echo ""; + echo ""; + echo ""; + echo ""; + echo ($audio_array["holiday"] ? "".$audio_array["holiday"]."" : "(none set)"); + echo ""; + + echo ""; + echo ""; + echo ""; + echo ($audio_array["custom"] ? "".$audio_array["custom"]."" : "(none set)"); + echo ""; +*/ + ?> +
  + + "; + echo ""; + } + else + { + echo " "; + } + ?> + + +
+
3) Select the dates and times that the inbound lines should be down:
  + + + + + + +
+ " size=10 maxsize=10> +

+ + + + + + + + + + + + + + + + + + + + + + + + + + + + : + + + + + + + + + + + + + + +
to + " size=10 maxsize=10> +

+ + + + + + + + + + + + + + + + + + + + + + + + + + + + : + + + + + + + + + + + + + + +
+ ** All times for inbound disable are in time, using 24-hour military time **
  +
4) Hit Submit to Execute :   + $insert_flag|$action|$location|$message|$message_type|$from_date|$from_hour|$from_min|$to_date|$to_hour|$to_min"; ?> +
"; + echo "$error_msg"; + echo "
\n"; + + $starttime_str=""; + $endtime_str=""; + $array_str=""; + + echo "\n"; + +# echo "\t\n"; +# echo "\n"; + + $i=0; + while ($row=mysqli_fetch_array($rslt)) + { + + if($row["dispo_rank"]==0 && !$live_header) + { + $live_header="\n\t\n\n"; + echo $live_header; + echo "\n"; + echo ""; + echo ""; + echo ""; + echo ""; + echo ""; + echo ""; + echo ""; + echo ""; + echo ""; + echo "\n"; + } + else if($row["dispo_rank"]==1 && !$active_header) + { + $active_header="\n\t\n\n"; + echo $active_header; + # echo "

"; +# echo "\n"; +# echo "\t\n\n"; + } + +$stmt="select * from inbound_disabled_entries where status in ('COMPLETED', 'CANCELLED') and end_datetime>=now()-INTERVAL $completed_days DAY order by status asc, end_datetime desc, start_datetime desc"; +$rslt=mysql_to_mysqli($stmt, $link); +if (mysqli_num_rows($rslt)>0) + { + echo "\n\t\n\n"; + echo "\n"; + } +?> + +



Currently Active Inbound Disable Status:

CURRENTLY LIVE DOWNTIMES:

 Created ByInterval Start Date/TimeInterval End Date/TimeLocationMessageStatusLast ModifiedLast Modified By

UPCOMING SCHEDULED DOWNTIMES:

\n"; + echo "\n"; + echo "\n"; + echo ""; + echo ""; + echo ""; + echo ""; + echo ""; + echo ""; + echo ""; + echo ""; + echo ""; + echo "\n"; + $i=0; + } + + + if ($i%2==0) + {$bgcolor="FFFFFF";} else {$bgcolor="E6E6E6";} + + $full_name=""; + $fn_stmt="select full_name from vicidial_users where user='$row[user]'"; + $fn_rslt=mysql_to_mysqli($fn_stmt, $link); + if(mysqli_num_rows($fn_rslt)>0) + { + $fn_row=mysqli_fetch_row($fn_rslt); + $full_name="
$fn_row[0]"; + } + + $modify_name=""; + $fn_stmt="select full_name from vicidial_users where user='$row[modified_by]'"; + $fn_rslt=mysql_to_mysqli($fn_stmt, $link); + if(mysqli_num_rows($fn_rslt)>0) + { + $fn_row=mysqli_fetch_row($fn_rslt); + $modify_name="
$fn_row[0]"; + } + + $font_class=($row["status"]=="LIVE" ? "blink" : "small_standard"); + + $location=preg_replace('/\|/', ', ', $row["location"]); + +# echo ""; +# echo ""; +# echo ""; + + echo "\n"; + echo "\n"; + echo ""; + echo ""; + echo ""; + echo ""; + echo ""; + echo ""; + echo ""; + echo ""; + echo "\n"; + + echo "\n"; + echo "\t"; + echo "\n"; +# echo "\n"; +# echo ""; +# echo "\n"; + $i++; + } + $starttime_str=preg_replace('/, $/', '', $starttime_str); + $endtime_str=preg_replace('/, $/', '', $endtime_str); + $array_str=preg_replace('/,$/', '', $array_str); + + echo "\t
 Created ByInterval Start Date/TimeInterval End Date/TimeLocationMessageStatusLast ModifiedLast Modified By

$row[status]

Inbound $location lines are scheduled to be down from ".substr($row["start_datetime"], 0, -3)." to ".substr($row["end_datetime"], 0, -3).", requested by $row[user]$full_name
Message being played: ".$row["message"]."

\n"; + echo " "; + if ($row["status"]!="LIVE") + { + $starttime_str.="'".preg_replace('/[^0-9]/', '', $row["start_datetime"])."', "; + $button_value="CANCEL"; + } + else + { + $endtime_str.="'".preg_replace('/[^0-9]/', '', $row["end_datetime"])."', "; + $button_value="RESUME"; + } + $array_str.="\n['$row[interval_id]', '".preg_replace('/[^0-9]/', '', $row["start_datetime"])."', '".preg_replace('/[^0-9]/', '', $row["end_datetime"])."', '".$row["status"]."'],"; + echo ""; + echo "$row[user]$full_name".substr($row["start_datetime"], 0, -3)."".substr($row["end_datetime"], 0, -3)."$location$row[message_type]
Play message
".($row["status"]!="LIVE" ? "SCHEDULED" : "LIVE")."$row[modify_date]$row[modified_by]$modify_name
\n"; + echo ""; + + echo "
 "; +# echo "
\n\t



Recent Completed/Cancelled Disabled Inbound - past $completed_days days:
"; + echo "\n"; + echo "\n"; + echo "\t\n"; + echo "\t\n"; + echo "\t\n"; + echo "\t\n"; + echo "\t\n"; + echo "\t\n"; + echo "\t\n"; + echo "\t\n"; + echo "\n"; + + $i=0; + while($row=mysqli_fetch_array($rslt)) + { + if ($i%2==0) + {$bgcolor="FFFFFF";} else {$bgcolor="E6E6E6";} + + $location=preg_replace('/\|/', ', ', $row["location"]); + + $full_name=""; + $fn_stmt="select full_name from vicidial_users where user='$row[user]'"; + $fn_rslt=mysql_to_mysqli($fn_stmt, $link); + if(mysqli_num_rows($fn_rslt)>0) + { + $fn_row=mysqli_fetch_row($fn_rslt); + $full_name=", $fn_row[0]"; + } + + + echo "\n"; + echo "\t\n"; + echo "\t\n"; + echo "\t\n"; + echo "\t\n"; + echo "\t\n"; + echo "\t\n"; + echo "\t\n"; + echo "\t\n"; + echo "\n"; + $i++; + } + + echo "
Created byInterval start date/timeInterval end date/timeLocationMessageStatusLast ModifiedModified By
".$row["user"].$full_name."".substr($row["start_datetime"], 0, -3)."".substr($row["end_datetime"], 0, -3)."".$location."".$row["message_type"]." - ".$row["message"]."".$row["status"]."".$row["modify_date"]."".$row["modified_by"]."
\n"; + echo "
+ + + + +

\n\n"; + + +echo "\n\n\n


\n"._QXZ("script runtime").": $RUNtime "._QXZ("seconds")."|$db_source
"; + +# print_r($location_array); + +echo "
"; +echo ""; +echo ""; + +# header ("Content-type: text/html; charset=utf-8"); +# echo $HEADER; +# require("admin_header.php"); +# echo $MAIN; + +?> diff --git a/extras/upgrade_2.14.sql b/extras/upgrade_2.14.sql index fdd096df..e48443f6 100644 --- a/extras/upgrade_2.14.sql +++ b/extras/upgrade_2.14.sql @@ -2669,3 +2669,31 @@ UPDATE system_settings SET db_schema_version='1709',db_schema_update_date=NOW() ALTER TABLE vicidial_call_time_holidays ADD holiday_method VARCHAR(40) default 'REPLACE'; UPDATE system_settings SET db_schema_version='1710',db_schema_update_date=NOW() where db_schema_version < 1710; + +CREATE TABLE inbound_disabled_entries ( +interval_id INT(10) UNSIGNED NOT NULL AUTO_INCREMENT PRIMARY KEY, +start_datetime DATETIME, +end_datetime datetime, +location VARCHAR(50), +message VARCHAR(100), +message_type ENUM('MEETING','CLOSED','WEATHER','CUSTOM'), +status ENUM('ACTIVE','LIVE','COMPLETED','CANCELLED') DEFAULT 'ACTIVE', +user VARCHAR(20), +modify_date TIMESTAMP NOT NULL DEFAULT current_timestamp() ON UPDATE current_timestamp(), +modified_by VARCHAR(20), +holiday_id VARCHAR(30), +KEY inbound_disabled_entries_key (start_datetime,end_datetime,location) +) ENGINE=MyISAM; + +CREATE TABLE vicidial_pending_ar ( +ar_id INT(10) UNSIGNED NOT NULL AUTO_INCREMENT PRIMARY KEY, +report_id VARCHAR(30) default '', +start_datetime DATETIME, +php_script VARCHAR(50) default '', +user VARCHAR(20), +status ENUM('TRIGGERED','AUTHORIZED','COMPLETED','ERROR') DEFAULT 'TRIGGERED', +notes TEXT, +KEY pending_ar_key (user,start_datetime) +) ENGINE=MyISAM; + +UPDATE system_settings SET db_schema_version='1711',db_schema_update_date=NOW() where db_schema_version < 1711; diff --git a/www/vicidial/functions.php b/www/vicidial/functions.php index e1106a38..868a89f9 100644 --- a/www/vicidial/functions.php +++ b/www/vicidial/functions.php @@ -4,7 +4,7 @@ # # functions for administrative scripts and reports # -# Copyright (C) 2023 Matt Florell LICENSE: AGPLv2 +# Copyright (C) 2024 Matt Florell LICENSE: AGPLv2 # # # CHANGES: @@ -41,6 +41,7 @@ # 210615-0952 - Default security fix, CVE-2021-28854 # 220921-1209 - Added more failed login logging in user_authorization function # 231119-1445 - Added user_authorization for HCI page users +# 240401-1459 - Added check for vicidial_pending_ar entries in user_authorization # ##### BEGIN validate user login credentials, check for failed lock out ##### @@ -51,7 +52,7 @@ function user_authorization($user,$pass,$user_option,$user_update,$api_call) ############################################# ##### START SYSTEM_SETTINGS LOOKUP ##### - $stmt = "SELECT use_non_latin,webroot_writable,pass_hash_enabled,pass_key,pass_cost,allow_ip_lists,system_ip_blacklist,two_factor_auth_hours,two_factor_container FROM system_settings;"; + $stmt = "SELECT use_non_latin,webroot_writable,pass_hash_enabled,pass_key,pass_cost,allow_ip_lists,system_ip_blacklist,two_factor_auth_hours,two_factor_container,enable_auto_reports FROM system_settings;"; $rslt=mysql_to_mysqli($stmt, $link); if ($DB) {echo "$stmt\n";} $qm_conf_ct = mysqli_num_rows($rslt); @@ -67,6 +68,7 @@ function user_authorization($user,$pass,$user_option,$user_update,$api_call) $SSsystem_ip_blacklist = $row[6]; $SStwo_factor_auth_hours = $row[7]; $SStwo_factor_container = $row[8]; + $SSenable_auto_reports = $row[9]; } ##### END SETTINGS LOOKUP ##### ########################################### @@ -260,6 +262,26 @@ function user_authorization($user,$pass,$user_option,$user_update,$api_call) if ($VALID_2FA < 1) { $auth_key='2FA'; + + if ( ($user_option == 'REPORTS') and ($SSenable_auto_reports > 0) ) + { + # If this is a REPORT, check for a triggered automated report, and if so, allow it to proceed + $stmt="SELECT count(*) from vicidial_pending_ar where user='$user' and status='TRIGGERED' and start_datetime > date_add(now(), interval 5 minute);"; + $rslt=mysql_to_mysqli($stmt, $link); + if ($DB) {echo "$stmt\n";} + $auth_check_to_print = mysqli_num_rows($rslt); + if ($auth_check_to_print > 0) + { + $row=mysqli_fetch_row($rslt); + if ($row[0] > 0); + { + $stmt="UPDATE vicidial_pending_ar SET status='AUTHORIZED',notes='$NOW_TIME $ip' WHERE user='$user' and status='TRIGGERED' and start_datetime > date_add(now(), interval 5 minute) order by start_datetime limit 1;"; + $rslt=mysql_to_mysqli($stmt, $link); + + $auth_key='GOOD'; + } + } + } } } }