#!/usr/bin/perl BEGIN { use lib '/usr/home/cfg' ; require push_inc ; } require cfg ; print "Content-type: text/html\n\n"; &today ; #--------------------------------------------------------------------------------------------------------------------------------------------------------------------- use DBI; use CGI::Carp qw(fatalsToBrowser); use CGI; @ARGV = split(/\\*\&/, $ENV{'QUERY_STRING'}); our $action = $ARGV[0] ; our $selectfield = $ARGV[1] ; our $analytics_id = $ARGV[2] ; our $row_cnt = $ARGV[3] ; our $default_reason = $ARGV[4] ; $is_from_analytics_event = "" unless $is_from_analytics_event ; # our $debug = 1 ; our $table = 'analytics_event_bookings' ; our ($q) = CGI -> new() ; $iaction = $q -> param('iaction') || $action ; our $dialog = 1 ; #--------------------------------------------------------------------------------------------------------------------------------------------------------------------- if ($iaction eq 'add'){ &common_min_add_screen ; &screen1 ; } if ($iaction eq 'save'){ &common_min_load_params ; &update ; &screen2 ; } &common_min_action; exit ; #------------------------------------------------------------------------------------------ sub update { &add_db_fields ; # $i{last_edited_by} = $userid ; $i{last_updated} = "$now_ccyy_mm_dd $now_hour:$now_min:$now_sec" ; $ignore{sel_field} = 1 ; my %ii = %i ; %i = () ; # &db_min_ro($table,'1,cant_charge_client_reasons',"id='$analytics_id'",'','') if $analytics_id ; # my @reasons = ($db{$table}{1}{cant_charge_client_reasons}) ? split(/\:|;/,$db{$table}{1}{cant_charge_client_reasons}) : (undef) ; $i{reason} = $ii{reason} ; $i{reason} =~ s/\:\|;//g ; $i{reason} =~ s/ +$//g ; $i{reason} =~ s/^ //g ; # $#reasons = $row_cnt-1 if $#reasons < $row_cnt-1 ; # Pads with undef automatically # @reasons = map { defined($_) ? $_ : "" } @reasons ; # $reasons[$row_cnt-1] = $i{reason} ; # $i{cant_charge_client_reasons} = join(":|;",@reasons) ; # $i{cant_charge_client_reasons} =~ s/\:\|;+$//g ; # &db_min_upd($table,"id='$analytics_id'") if $analytics_id ; } #------------------------------------------------------------------------------------------ sub add_screen { $box_header_title = 'Add Reason' ; $hidden_action = 'save' ; $head_col_width = 2 ; } #------------------------------------------------------------------------------------------ sub add_db_fields { $ignore{iaction} = 1 ; $hidden{id} = 2 ; $hidden{sel_field} = 2 ; $required{reason} = 1 ; $textarea{reason} = 1 ; $db{$table}{''}{sel_field} = $selectfield if $selectfield ; $default_reason =~ s/\_new_line_character_/\n/g ; $default_reason =~ s/\\ / /g ; $default_reason =~ s/\%A0/ /g ; $db{$table}{''}{reason} = "$default_reason" ; $sort_field{1} = "reason" ; } #------------------------------------------------------------------------------------------ sub thead { &common_min_thead ; } #------------------------------------------------------------------------------- sub screen1 { $trigger_jquery_raw .= qq~ \$('#btn-close-customer').click(function (e) { parent.BootstrapDialog.closeAll() ; }); ~ ; &common_min_dialog_load_screen ; } #------------------------------------------------------------------------------------------ sub screen2 { my $reason_tooltip = "$i{reason}" ; $reason_tooltip =~ s/\R/
/g; $reason_tooltip =~ s/ /\ /g; my $reason_default = "$i{reason}" ; $reason_default =~ s/\R/_new_line_character_/g; $reason_default =~ s/ /\ /g ; # my $data_base_value = "$i{cant_charge_client_reasons}" ; # $data_base_value =~ s/\R/
/g; $trigger_jquery_raw .= qq~ let reasons = parent.\$("input[name='cant_charge_client_reasons']").val() ; let reasons_arr = reasons ? reasons.split(":|;") : [undefined] ; let row_cnt = $row_cnt ; if (reasons_arr.length < row_cnt) { reasons_arr.length = row_cnt; reasons_arr = reasons_arr.map(v => v !== undefined ? v : ""); } reasons_arr[row_cnt - 1] = "$reason_default" ; let joined_reasons = reasons_arr.join(":|;"); ~ ; $trigger_jquery_raw .= qq~ let analytics_id = $analytics_id ; let update_url = "$useropts{scripts}/get/get_analytics_charge_client.pl?analytics_id="+analytics_id+"&row_cnt="+row_cnt+"&reason=$reason_default" ; \$.get(update_url) ; ~ if $analytics_id ; $trigger_jquery_raw .= qq~ parent.\$("input[name='cant_charge_client_reasons']").val(joined_reasons) ; if (parent.\$("#reason_icon_$row_cnt").html()) { parent.\$("#reason_icon_$row_cnt").remove() } let html_cant_charge = "  " ; console.log('$useropts{scripts}/get/update_analytics_cant_charge_client_fixtures.pl?analytics_id=1011&row_cnt=$row_cnt&reason=$reason_default') ; let checkbox_html = "" ; parent.\$("#c_cant_charge_client_fixtures_$row_cnt").html(checkbox_html+""+html_cant_charge).trigger("chosen:updated") ; parent.\$("#checkboxCant_charge_client_fixtures_$row_cnt").prop("checked",true) ; parent.\$('[data-toggle="tooltip"]').tooltip({html:true}); parent.BootstrapDialog.closeAll() ; ~; &common_min_dialog_save_screen ; } #------------------------------------------------------------------------------------------ use today ; use dialog ; use common ; 1;