#!/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 ; use LWP::UserAgent; use XML::LibXML; use LWP::Simple; use XML::Simple ; use JSON ; &today; #--------------------------------------------------------------------------------------------------------------------------------------------------------------------- @ARGV = split(/\\*\&/, $ENV{'QUERY_STRING'}); $action = $ARGV[0] ; our ($q) = CGI -> new() ; our $iaction = $q -> param('iaction') || $action ; our $isaved = $q -> param('isaved') || '' ; $iaction = 'report' unless $iaction ; our $debug = 1 ; # our $testing = 1 ; # our $testing = 1 ; # our $testdcd = 1 ; # if ($username ne 'handre') { # print "<< MAINTENANCE IN PROGRESS >>" ; exit ; # } # -------- page opts -------------------------------------------------------------------------------------------------------------------------------------------------- &page_opts ; #--------------------------------------------------------------------------------------------------------------------------------------------------------------------- our $srchscr = 1 ; ##DO NOT CHANGE THE ORDER OF THERE COLUMNS IT IS THE ORDER IN WHICH THEY ARE STORED IN THE DATABASE our @sql_col_display = ("system","region","head_operator","system_test_date","status","equipment_checked","venue","comments","dates","special_arrangements") ; ##DO NOT CHANGE THE ORDER OF THERE COLUMNS IT IS THE ORDER IN WHICH THEY ARE STORED IN THE DATABASE &db_open_upd ; our $db_ignore_open_close = 1 ; # do one open and one close instead of repeating it if ($iaction eq 'report') { &report_screen } elsif ($iaction eq 'save') { &common_min_load_params ; &update ; &report_ifields; $iaction = 'report' ; &list_screen ; exit if ($username eq 'handre' || $username eq 'rory') && $testing ; $s{no} = 1 ; &screen3 ; } elsif ($iaction eq 'list') { &common_min_load_params ; &report_ifields; &list_screen ; &screen3 ; } $db_ignore_open_close = 0 ; # do one open and one close instead of repeating it &db_close_conn ; &common_min_action; exit; #------------------------------------------------------------------------------------------ sub update { &db_min_ro('mobile_tracking_system','event_system_id,id,mobile_tracking_system_data','','','') ; my %system_exists = () ; foreach (keys %{$db{mobile_tracking_system}}) { $system_exists{$_} = 1 ; } my %ii = %i ; my %seen_event_system_id = () ; foreach my $field (keys %ii) { next if ($field =~ /^update_/ && !$ii{$field}) || $field !~ /^update_/ ; local @a = split(/\_/,$field) ; my $event_system_id = $a[-1] ; $event_system_id = int($event_system_id) ; next if $seen_event_system_id{$event_system_id} ; $seen_event_system_id{$event_system_id} = 1 ; %i = () ; foreach my $field_2 (@sql_col_display) { next if $field_2 eq 'system' ; my $field_name = qq~$field_2\_$event_system_id~ ; $i{mobile_tracking_system_data} .= qq~$ii{$field_name}:;:~ ; } $i{mobile_tracking_system_data} =~ s/(?:\:;\:)+$// if $i{mobile_tracking_system_data} ; $i{mobile_tracking_system_data} = qq~~ if $i{mobile_tracking_system_data} !~ /[a-zA-Z0-9]/ ; $ignore{mobile_tracking_system_data} = ((!$i{mobile_tracking_system_data} && !$db{mobile_tracking_system}{$event_system_id}{mobile_tracking_system_data}) || ($i{mobile_tracking_system_data} eq $db{mobile_tracking_system}{$event_system_id}{mobile_tracking_system_data})) ? 1 : 0 ; # if ($db{mobile_tracking_system}{$event_system_id}{id}) { if ($system_exists{$event_system_id}) { &db_min_upd('mobile_tracking_system',"`event_system_id`='$event_system_id'") unless $ignore{mobile_tracking_system_data} ; } elsif (!$ignore{mobile_tracking_system_data}) { $i{event_system_id} = $event_system_id ; $i{id} = &db_min_get_max('mobile_tracking_system','id') ; &db_min_insert('mobile_tracking_system') ; } } %i = %ii ; } #------------------------------------------------------------------------------------------ sub report_screen { our $lcol = 3 ; our $fcol = 5 ; $print_box_content_rows .= &common_min_forms_start('report') ; # &common_min_select_opts('system_id',$table,'name',$i{client_id},'') ; my $def_val = ($i{system_type}) ? $i{system_type} : "all" ; my %def_selected = () ; $def_selected{$def_val} = "SELECTED" ; $opts{system_type} = qq~ ~ ; $print_box_content_rows .= &common_min_form_select('system_type',$i{system_type}) ; $i{region} = ($i{region}) ? $i{region} : "all" ; my %select_hashes = () ; $select_hashes{region} = {1 => 'JHB',2 => 'PTA',3 => 'CPT',4 => 'KZN',5 => 'BLOEM',6 => 'EL',7 => 'PE',8 => 'GARDEN ROUTE',9 => 'LP',10 => 'MP',11 => 'NC',12 => 'NW',13 => 'INTERNATIONAL','all' => 'All'} ; $opts{region} = "" ; $opts{region} =~ s/value='\Q$i{region}\E'/value='$i{region}' SELECTED/g if $i{region} ; $print_box_content_rows .= &common_min_form_select('region',$i{region}) ; $print_box_content_rows .= &common_min_forms_end('','','list') ; &common_min_search_screen ; } #------------------------------------------------------------------------------- sub report_ifields { if ($i{system_type} && $i{system_type} ne 'all') { push @report_sql, "(es.system_type = '$i{system_type}')" ; my $system_type = ucfirst $i{system_type} ; push @report_results, "SYSTEM TYPE = '$system_type'" ; } elsif ($i{system_type} eq 'all') { push @report_sql, "(es.system_type = 'mobile' OR es.system_type = 'solo')" ; push @report_results, "SYSTEM TYPE = ('Mobile' OR 'Solo')" ; } my %select_hashes = () ; $select_hashes{region} = {1 => 'JHB',2 => 'PTA',3 => 'CPT',4 => 'KZN',5 => 'BLOEM',6 => 'EL',7 => 'PE',8 => 'GARDEN ROUTE',9 => 'LP',10 => 'MP',11 => 'NC',12 => 'NW',13 => 'INTERNATIONAL','all' => 'All'} ; if ($i{region} && $i{region} ne 'all') { push @report_sql, "(mts.mobile_tracking_system_data REGEXP '^$i{region}(:;:|\$)')" ; push @report_results, "REGION = '$select_hashes{region}{$i{region}}'" ; } $report_results_msg = uc join(', ', @report_results) ; if (not $report_results_msg) { $error = qq~ENTER AT LEAST ONE SEARCH PARAMETER~ ; &report_screen; } elsif ($iaction eq 'save') { $isaved = qq~SUCCESSFULLY SAVED!~ ; } else { $isaved = qq~SELECT WHERE $report_results_msg~ ; } our $srch_where_sql = join(' AND ',@report_sql) ; # $srch_where_sql = qq~es.id=1~ ; } #------------------------------------------------------------------------------------------ sub load_list_vars { my ($where) = @_ ; &common_min_select_opts('head_operator','users','name','','','',"`user_type` = 'casual_c'") ; # &db_min_ro($table,"*","$where",'','') ; $where = "WHERE $where" if $where ; &db_min_raw(" SELECT es.*, mts.mobile_tracking_system_data FROM $table es LEFT JOIN mobile_tracking_system mts ON es.id = mts.event_system_id $where; "); foreach $row (@$rows_array_ref) { for (0 .. $col_cnt){ next if $col_name{$_} eq 'lastupdate' ; $db{$table}{@$row[0]}{$col_name{$_}} = @$row[$_] ; } } } #------------------------------------------------------------------------------------------ sub list_screen { $print_box_content_rows .= &common_min_forms_start("$lcpage") ; &load_list_vars($srch_where_sql) ; $fcol = 12 ; our $xlsx_title_heading = "Mobile System Tracking Report" ; our $xlsxdir = "mobile_system_tracking" ; our $xlsxreportname = "Mobile_System_Tracking_Report" ; &report_xlsx_export_header("$xlsxreportname",$xlsxdir,'',$xlsx_title_heading) ; push @sql_col_display,"update" ; # push @sql_col_display,"" ; my @rev_sql_col_display = reverse @sql_col_display ; foreach (@rev_sql_col_display) { $lastchild++ ; $last_child{$_} = $lastchild ; } # &common_debug("last-child : $_ [$last_child{$_}]"); $xlsxrow-- ; our $current_date = int("$now_year$now_mm$now_dd") ; our $found_editable = 0 ; our %seen_field_id = () ; our %all_location_ids_per_system = () ; our $all_ids = qq~~ ; local @month_names = ("","Jan","Feb","Mar","Apr","May","Jun","Jul","Aug","Sep","Oct","Nov","Dec") ; our $quote_and_ops_ids = qq~~ ; our @selects_with_default_ids = () ; our @table_with_default_ids = () ; our @dropdown_chosen_ids = () ; our @update_ids = () ; my $table_row = 0 ; my $placeholder_row_cnt = 0 ; our @date_value_ids = () ; our @default_javascript_by_id = () ; our @all_update_field_ids = () ; my %select_hashes = () ; # our @sql_col_display = ("system","region","head_operator","system_test_date","status","equipment_checked","venue","comments","dates","special_arrangements") ; $select_hashes{region} = {1 => 'JHB',2 => 'PTA',3 => 'CPT',4 => 'KZN',5 => 'BLOEM',6 => 'EL',7 => 'PE',8 => 'GARDEN ROUTE',9 => 'LP',10 => 'MP',11 => 'NC',12 => 'NW',13 => 'INTERNATIONAL'} ; $select_hashes{status} = {1 => 'All Clear',2 => 'Support Needed',3 => 'Part Pending'} ; $select_hashes{equipment_checked} = {1 => 'Yes',2 => 'No'} ; $select_hashes{venue} = {1 => 'JHB HUB',2 => 'BLOEM HUB',3 => 'KZN HUB',4 => 'CPT HUB',5 => 'RMA HUB',6 => 'SCHOOL',7 => 'OPERATOR'} ; foreach (keys %{$db{users}}) { $select_hashes{head_operator}{$_} = $db{users}{$_}{name} ; } $opts{region} = "" ; $opts{status} = "" ; $opts{equipment_checked} = "" ; $opts{venue} = "" ; # $opts{region} = qq~~ ; # $opts{status} = qq~~ ; # $opts{equipment_checked} = qq~~ ; # $opts{venue} = qq~RMA HUBSCHOOLOPERATOR~ ; # rgb(255,165,0) ## orange # rgb(255,255,0) ## yellow # rgb(81,203,242) ## Blue # rgb(50,50,50) ## Black/Grey # rgb(249,13,13) ## Red # rgb(128,64,0) ## Brown # Bloem + NC - Orange # JHB + PTA - Yellow # CPT + Garden Route - Blue # KZN - Black/Grey # EL + PE - Red # LP + MP + NW - Brown my %region_background_color = () ; $region_background_color{1} = "rgb(255,255,0)" ; $region_background_color{2} = $region_background_color{1} ; $region_background_color{3} = "rgb(81,203,242)" ; $region_background_color{4} = "rgb(115,117,117)" ; $region_background_color{5} = "rgb(255,153,0)" ; $region_background_color{6} = "rgb(249,13,13)" ; $region_background_color{7} = $region_background_color{6} ; $region_background_color{8} = "rgb(81,203,242)" ; $region_background_color{9} = "rgb(172,115,57)" ; $region_background_color{10} = $region_background_color{9} ; $region_background_color{11} = $region_background_color{5} ; $region_background_color{12} = $region_background_color{9} ; # 153, 102, 51 foreach my $id (sort {$a <=> $b} keys %{$db{$table}}) { $table_row++ ; $print_tbody .= qq~