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 "