#!/usr/bin/perl BEGIN { use lib '/usr/home/cfg' ; require push_inc ; } require cfg ; print "Content-type: text/html\n\n"; # unless ($useropts{it}{$username}) { print "<<<<<<<<<<<< MAINTENANCE IN PROGRESS >>>>>>>>>" ; exit ; } #--------------------------------------------------------------------------------------------------------------------------------------------------------------------- use CGI::Carp qw(fatalsToBrowser); use CGI; use Mail::Sendmail; use Fcntl qw(:flock); use File::Copy; use File::Basename; use Date::Calc qw(:all); use Excel::Writer::XLSX; use Time::Piece ; &today; #--------------------------------------------------------------------------------------------------------------------------------------------------------------------- @ARGV = split(/\\*\&/, $ENV{'QUERY_STRING'}); $action = $ARGV[0] ; our ($q) = CGI -> new() ; our $iaction = $q -> param('iaction') || $action ; our $isaved = $q -> param('isaved') || '' ; our $no_dates_in_table = 1 ; # our $debug = 1 ; # our $testing = 1 ; # if ($username ne 'handre') { # print "<< MAINTENANCE IN PROGRESS >>" ; exit ; # } #-------- page opts -------------------------------------------------------------------------------------------------------------------------------------------------- &page_opts ; #--------------------------------------------------------------------------------------------------------------------------------------------------------------------- our $srchscr = 1 ; if ($iaction eq 'save') { &db_open_upd ; our $db_ignore_open_close = 1 ; # do one open and one close instead of repeating it &common_min_load_params ; &report_ifields ; &update ; &list_screen ; $db_ignore_open_close = 0 ; # do one open and one close instead of repeating it &db_close_conn ; # exit if $username eq 'handre' && $testing ; &screen3 ; # &redirect_screen; } &db_open_ro ; our $db_ignore_open_close = 1 ; # do one open and one close instead of repeating it &report_screen if $iaction eq '' ; if ($iaction eq 'report') { &common_min_load_params ; &report_ifields ; &list_screen ; &screen3 ; } &common_min_action ; $db_ignore_open_close = 0 ; # do one open and one close instead of repeating it &db_close_conn ; exit ; #------------------------------------------------------------------------------------------ sub hidden_fields { # $ignore{id} = 1 ; $ignore{iaction} = 1 ; $ignore{date} = 1 ; $ignore{troubleshoot_monitor_id} = 1 ; for my $d_cnt (1 .. $date_counter) { for my $shift_cnt (1 .. 4) { $ignore{"shifttroubleshootmonitorid_$shift_cnt\_$d_cnt"} = 1 ; $ignore{"shift_troubleshoot_monitor_$shift_cnt\_$d_cnt"} = 1 ; } } # $ignore{monitor_ids} = 1 ; $ignore{update_table_1} = 1 ; $ignore{update} = 1 ; $ignore{"itv-table_length"} = 1 ; } #------------------------------------------------------------------------------------------ sub update { &schedule_update("shift_operator_ids","troubleshoot_monitor_ids","shifttroubleshootmonitorid","troubleshoot_monitor_notes") ; # 12=f:;s:|s:1;t:1|f:2;s:2-13=|f:3;s:3|f:4;s:4 &schedule_update_monitor_reports ; # my @table_sql_where = () ; # if ($i{client_id}) { # push @table_sql_where, "`quote_to`='$i{client_id}'" ; # } # if ($i{date_from} && $i{date_to}) { # check dates # push @table_sql_where, "(('$i{date_from} 00:00:00' <= `date_from` AND `date_from` <= '$i{date_to} 23:59:59') OR ('$i{date_from} 00:00:00' <= `date_to` AND `date_to` <= '$i{date_to} 23:59:59') OR (`date_from` <= '$i{date_from} 00:00:00' AND '$i{date_to} 23:59:59' <= `date_to`))" ; ############################################### > OR >= # } # # if ($i{monitor_id} and $i{monitor_id} ne 'all') { # # push @table_sql_where,"`TROUBLESHOOT MONITOR` = '$db{users}{1}{name}'" ; # # } # my $table_sql_where_str = join(" AND ",@table_sql_where) ; # &db_min_ro($table,"id,monitor_report_saved_data","$table_sql_where_str",'','') ; # my %saved_field_hash = () ; # foreach my $id (keys %{$db{$table}}) { # my @saved_data_split_1 = split(/\-/,$db{$table}{$id}{monitor_report_saved_data}) ; # foreach my $a (@saved_data_split_1) { # my @saved_data_split_2 = split(/\=/,$a) ; # my $event_sys_id = $saved_data_split_2[0] ; # my @saved_data_split_3 = split(/\|/,$saved_data_split_2[1]) ; # my $day_cnt = 0 ; # foreach my $b (@saved_data_split_3) { # $day_cnt++ ; # next unless $b =~ /(\d+)/g ; # $saved_field_hash{$id}{$event_sys_id}{$day_cnt} = $b ; # } # } # } # foreach my $field_name (keys %i) { # next if ($field_name =~ /update_event/ && !$i{$field_name}) || $field_name !~ /update_event/ ; # my @fields = split(/\_/,$field_name) ; # my $system_id = substr($fields[-3],5) ; # my $day_cnt = $fields[-2] ; # my $event_id = $fields[-1] ; # my $fixture_field = "fixture_check_event$system_id\_$day_cnt\_$event_id" ; # my $status_field = "status_event$system_id\_$day_cnt\_$event_id" ; # $saved_field_hash{$event_id}{$system_id}{$day_cnt} = qq~~ ; # $saved_field_hash{$event_id}{$system_id}{$day_cnt} = qq~f:$i{$fixture_field};~ if $i{$fixture_field} ; # $saved_field_hash{$event_id}{$system_id}{$day_cnt} .= qq~s:$i{$status_field}~ if $i{$status_field} ; # } # %ii = %i ; # %i = () ; # foreach my $event_id (keys %saved_field_hash) { # $i{monitor_report_saved_data} = qq~~ ; # foreach my $system_id (sort { $a <=> $b } keys %{$saved_field_hash{$event_id}}) { # # $i{monitor_report_saved_data} .= qq~$system_id\=~ ; # my $saved_by_system = qq~~ ; # foreach my $day_max (sort { $b <=> $a } keys %{$saved_field_hash{$event_id}{$system_id}}) { # for my $day_cnt (1 .. $day_max) { # $saved_by_system .= qq~$saved_field_hash{$event_id}{$system_id}{$day_cnt}|~ ; # } # chop $saved_by_system if $day_max ; # last ; # } # $i{monitor_report_saved_data} .= qq~$system_id\=$saved_by_system\-~ if $saved_by_system =~ /(\d+)/g ; # } # chop $i{monitor_report_saved_data} if $i{monitor_report_saved_data} ; # next if ($i{monitor_report_saved_data} eq $db{$table}{$event_id}{monitor_report_saved_data}) || (!$i{monitor_report_saved_data} && !$db{$table}{$event_id}{monitor_report_saved_data}) ; # &db_min_upd($table,"id='$event_id'") ; # } # %i = %ii ; } #------------------------------------------------------------------------------------------ sub report_ifields { &load_search_vars ; # if ($i{date}) { # check dates # push @report_sql, " `date_from` <= '$i{date} 23:59:59' AND '$i{date} 00:00:00' <= `date_to` " ; # push @report_results, "DATE IS '$i{date}'" ; # } else { # $error = qq~PLEASE ENTER A DATE!~ ; # &report_screen; # } if ($i{client_id}) { push @report_sql, "`quote_to`='$i{client_id}'" ; &db_min_ro('customers','id,name',"`id`='$i{client_id}'") ; push @report_results,"`CLIENT` = '$db{customers}{$i{client_id}}{name}'" ; } my $date_from_val = $i{date_from} ; my $date_to_val = $i{date_to} ; $date_from_val =~ s/\-//g ; $date_to_val =~ s/\-//g ; if ($i{date_from} && $i{date_to} && $date_from_val > $date_to_val) { $error = qq~THE START MUST BE BEFORE THE END DATE!!!~ ; &report_screen ; } elsif ($i{date_from} && $i{date_to}) { # check dates push @report_sql, "(('$i{date_from} 00:00:00' <= `date_from` AND `date_from` <= '$i{date_to} 23:59:59') OR ('$i{date_from} 00:00:00' <= `date_to` AND `date_to` <= '$i{date_to} 23:59:59') OR (`date_from` <= '$i{date_from} 00:00:00' AND '$i{date_to} 23:59:59' <= `date_to`))" ; ############################################### > OR >= push @report_results, "(EVENT BETWEEN '$i{date_from}' AND '$i{date_to}')" ; } else { $error = qq~PLEASE ENTER A START AND END DATE!!!~ ; &report_screen; } if ($i{monitor_id} and $i{monitor_id} ne 'all') { push @report_results,"`TROUBLESHOOT MONITOR` = '$db{users}{1}{name}'" ; push @report_sql, " `troubleshoot_monitor_ids` LIKE '%$i{troubleshoot_monitor_id}%' " ; } elsif ($i{monitor_id} and $i{monitor_id} eq 'all') { push @report_results,"`TROUBLESHOOT MONITORS` = 'ALL'" ; } else { # push @report_sql, "(`user_id` = '')" ; } $report_results_msg = uc join(', ', @report_results) ; if ($iaction eq 'save') { $isaved = qq(SUCCESSFULLY SAVED!) ; } elsif (not $report_results_msg) { $error = qq(ENTER AT LEAST ONE SEARCH PARAMETER) ; &report_screen; } else { $isaved = qq(SELECT WHERE $report_results_msg) ; } our $srch_where_sql = join(' AND ',@report_sql) ; my @date = split(/ /,$i{date}) ; my ($year_inp,$month_inp,$day_inp) = split(/\-/,$date[0]) ; our $date_inp_val = int("$year_inp$month_inp$day_inp") ; our $today_val = int("$now_year$now_mm$now_dd") ; } #------------------------------------------------------------------------------------------ sub load_search_vars { if ($i{monitor_id} and $i{monitor_id} ne 'all') { &db_min_ro('users','1,name',"`id` = '$i{troubleshoot_monitor_id}'",'','') ; } } #------------------------------------------------------------------------------------------ sub list_screen { $print_box_content_rows .= &common_min_forms_start("$lcpage") ; # our $monitoring_report = 1 ; our $troubleshoot_monitoring_report = 1 ; our $extra_column = ",monitor_report_saved_data" ; &schedule_load_list_vars("$srch_where_sql") ; $fcol = 12 ; my $report = 1 ; our $xlsxdir = "troubleshoot_report" ; our $xlsxreportname = "Troubleshoot_Report" ; my $date = &common_write_date_interval($i{date_from},$i{date_to}) ; our $xlsx_title_heading = "Troubleshoot Allocations $date" ; my $field_name = "troubleshoot_shift_monitor" ; my $uc_field_name = ucfirst $field_name ; our $print_tbody_extra = qq~~ ; # our @sql_col_display_extra = ("date","shift_1_(07:00-10:00)","shift_2_(10:00-13:00)","shift_3_(13:00-16:00)","shift_4_(16:00-19:00)") ; our @sql_col_display_extra = ("date","shift_1_(08:00-11:00)","shift_2_(11:00-14:00)","shift_3_(14:00-17:00)","shift_4_(17:00-21:00)","notes") ; push @sql_col_display_extra,"update" ; # if $date_inp_val >= $today_val ; our @sql_col_display = ("count","event","date","day","start_date","start_time","end_time","region","sport","system","club_name","operator","fixture_check","status","comments") ; # push @sql_col_display,"update" if ($monitoring_report || $temp_calibrator_report) && $date_inp_val >= $today_val ; &report_xlsx_export_header("$xlsxreportname",$xlsxdir,'',$xlsx_title_heading) ; # troubleshoot_monitoring_report &schedule_build_extra_table("shift_troubleshoot_monitor","shift_operator_ids","troubleshoot_monitor_ids","troubleshoot_monitor_notes","select_troubleshoot_monitors") ; # &common_min_table_update_checkbox_col("3") ; push @sql_col_display,"update" ; my $table_col_name = "troubleshoot_monitor_ids" ; $xlsxrow-- ; my @rev_sql_col_display = reverse @sql_col_display ; foreach (@rev_sql_col_display) { $lastchild++ ; $last_child{$_} = $lastchild ; } &schedule_get_monitor_reports_default_values ; # our %default_values = () ; # # 12=f:;s:|s:1;t:1|f:2;s:2-13=|f:3;s:3|f:4;s:4 # foreach my $id (keys %{$db{$table}}) { # my @saved_data_split_1 = split(/\-/,$db{$table}{$id}{monitor_report_saved_data}) ; # # $sql_col_display[-2] # # $default_vals{}{$event_sys_id}{$sys_day_cnt}{$id} # foreach my $a (@saved_data_split_1) { # my @saved_data_split_2 = split(/\=/,$a) ; # my $event_sys_id = $saved_data_split_2[0] ; # my @saved_data_split_3 = split(/\|/,$saved_data_split_2[1]) ; # my $day_cnt = 0 ; # foreach my $b (@saved_data_split_3) { # $day_cnt++ ; # next unless $b =~ /(\d+)/g ; # my @saved_data_split_3 = split(/\;/,$b) ; # my @saved_data_split_4 = split(/\:/,$saved_data_split_3[0]) ; # my @saved_data_split_5 = split(/\:/,$saved_data_split_3[1]) ; # if ($saved_data_split_4[0] =~ /f/) { # $default_values{$sql_col_display[-3]}{$event_sys_id}{$day_cnt}{$id} = $saved_data_split_4[1] ; # } # if ($saved_data_split_5[0] =~ /s/) { # $default_values{$sql_col_display[-2]}{$event_sys_id}{$day_cnt}{$id} = $saved_data_split_5[1] ; # } elsif ($saved_data_split_4[0] =~ /s/) { # $default_values{$sql_col_display[-2]}{$event_sys_id}{$day_cnt}{$id} = $saved_data_split_4[1] ; # } # } # } # } &common_min_select_opts("status","monitor_status","status") ; our @default_javascript_by_id_2 = () ; &schedule_build_table("troubleshoot_monitor_ids") ; # if ($date_inp_val >= $today_val) { # $trigger_jquery_raw .= qq~ # \$("#itv-table tr th:nth-last-child(5)").css("width","10%") ; # \$("#itv-table tr th:nth-last-child(4)").css("width","10%") ; # \$("#itv-table tr th:nth-last-child(3)").css("width","10%") ; # \$("#itv-table tr th:nth-last-child(2)").css("width","10%") ; # ~ ; # } else { # $trigger_jquery_raw .= qq~ # \$("#select_monitors tr th:nth-last-child(1)").css("width","23%") ; # \$("#select_monitors tr th:nth-last-child(4)").css("width","23%") ; # \$("#select_monitors tr th:nth-last-child(3)").css("width","23%") ; # \$("#select_monitors tr th:nth-last-child(2)").css("width","23%") ; # ~ ; # } # &calibration_build_table_and_or_excel(1) ; # if ($found_after_date) { # } else { # $trigger_jquery_raw .= qq~ # \$("#itv-table tr th:nth-last-child(2)").css("width", "7.5%") ; # \$("#itv-table tr th:nth-last-child(3)").css("width", "7.5%") ; # \$("#itv-table tr th:nth-last-child(4)").css("width", "7.5%") ; # \$("#itv-table tr th:nth-last-child(5)").css("width", "7.5%") ; # ~ ; # } # my $first_table_multi_select_table_cells_str = join(",",@first_table_multi_select_table_cells) ; # &common_min_table_select_fixed_width_jquery($first_table_multi_select_table_cells_str ) ; # &common_min_table_select_default_values_jquery ; # &common_min_table_update_checkbox_col("3") ; my $first_table_multi_select_table_cells_str = join(",",@first_table_multi_select_table_cells) ; # $useropts{table_id} &common_min_table_select_fixed_width_jquery($first_table_multi_select_table_cells_str) ; &common_min_table_select_prevent_dropdown_overlap_jquery ; &common_min_table_select_default_values_jquery ; &common_min_table_update_checkbox_col("3","content","[id^='textareaComments_'],[id^='selectFixture_check_'],[id^='selectStatus_'],[id^='selectShift_troubleshoot_monitor_1_'],[id^='selectShift_troubleshoot_monitor_2_'],[id^='selectShift_troubleshoot_monitor_3_'],[id^='selectShift_troubleshoot_monitor_4_'],[id^='textareaShift_troubleshoot_monitor_notes_1_'],[id^='textareaShift_troubleshoot_monitor_notes_2_'],[id^='textareaShift_troubleshoot_monitor_notes_3_'],[id^='textareaShift_troubleshoot_monitor_notes_4_']") ; # my $default_javascript_by_id_str = join (",",@default_javascript_by_id) ; # print "\n default_javascript_by_id_str : $default_javascript_by_id_str" ; # $trigger_jquery_raw .= qq~ # all_def_vals = {$default_javascript_by_id_str} ; # \$("#$useropts{table_id}").on("change","[id^='selectFixture_check_'],[id^='selectStatus_']", function (event) { # event.preventDefault(); # console.log("2 update : "+this.id) ; # check_whether_to_update(this.id); # }); # ~ ; # &common_min_table_update_checkbox_col("3") ; $fnsortorder = 'asc' ; &common_min_extra_crumb("$lcpage","Search Screen") ; } #------------------------------------------------------------------------------------------ sub thead { # &common_min_thead ; } #------------------------------------------------------------------------------- sub page_opts { our $glyphicon = 'list' ; # our $lcpage = 'monitor-allocations' ; our $lcpage = 'troubleshoot-report' ; &common_page_name ; our $table = 'event_quotes' ; $page_title = 'Troubleshoot Allocations' ; } #------------------------------------------------------------------------------- sub report_screen { our $lcol = 3 ; our $fcol = 5 ; $print_box_content_rows .= &common_min_forms_start('report') ; &common_min_select_opts('client_id','customers','name','','','',"events='1'") ; $allow_deselect{client_id} = 1 ; $opts{client_id} =~ s/value="$i{client_id}"/value="$i{client_id}" SELECTED/g if $i{client_id} ; $print_box_content_rows .= &common_min_form_select('client_id','') ; my ($sql_next_day) = &common_add_delta_days(1) ; my ($next_year,$next_month,$next_day) = split(/\-/,$sql_next_day) ; $print_box_content_rows .= &common_min_form_datepicker('date_from',"$now_year-$now_mm-$now_dd") ; #unless $i{date_from} ; $print_box_content_rows .= &common_min_form_datepicker('date_to',"$next_year-$next_month-$next_day") ; #unless $i{date_from} ; push @date_value_ids,"input[name='date_from']" ; push @date_value_ids,"input[name='date_to']" ; &common_min_table_validate_date_inputs_jquery ; $preferred_title{troubleshoot_monitor_id} = "Troubleshoot Monitor" ; # &db_min_ro('users',"id,name","`user_type` = 'support' OR `user_type` = 'casual_calibrator'",'','') ; # &db_min_ro('users',"id,name,username","`name` NOT LIKE 'Rory%'",'','') ; $selected{troubleshoot_monitor_id}{all} = 'SELECTED' ; # if ($i{monitor_id}) { # $selected{monitor_id}{$i{monitor_id}} = 'SELECTED' ; # $selected{monitor_id}{all} = '' ; # } # foreach (sort {$db{users}{$a}{name} cmp $db{users}{$b}{name}} keys %{$db{users}}) { # next if $useropts{it}{$db{users}{$_}{username}} ; # $opts{monitor_id} .= qq~~ ; # } $opts{troubleshoot_monitor_id} .= qq~~ ; $print_box_content_rows .= &common_min_form_select('troubleshoot_monitor_id','') ; $print_box_content_rows .= &common_min_forms_end('','','report') ; &common_min_search_screen ; } #------------------------------------------------------------------------------- sub screen3 { &thead; if ($isaved) { $alert = &common_min_alert('success',"$ucpage $isaved!",'ok') ; } else { &common_min_alert_type ; } # my $page = "$lcpage\s" ; my $page = "event-quotes" ; if ($s{no}) { $page = $lcpage ; } # &db_min_ro('daily_monitor_ids','date,monitor_ids') ; my @sql_col_display_2 = @sql_col_display ; @sql_col_display = @sql_col_display_extra ; our %custom_column_styles = () ; $custom_column_styles{fixture_check} = qq~style="width:7%;min-width:150px;"~ ; $custom_column_styles{status} = qq~style="width:7%;min-width:150px;"~ ; &common_min_thead ; $print_box_content_rows .= qq~