aisa/scripts/dialog/add_operator.pl

157 lines
4.1 KiB
Perl
Raw Permalink Normal View History

2025-11-26 09:31:54 +00:00
#!/usr/bin/perl
BEGIN { use lib '/usr/home/cfg' ; require push_inc ; }
use CGI qw( :standard );
use CGI::Carp qw(fatalsToBrowser);
use Crypt::PasswdMD5;
require cfg ;
# print "Content-type: text/html\n\n";
print header; # CGI.pm method
use POSIX;
#------------------------------------------------------------------------------------------
@ARGV = split(/\\*\&/, $ENV{'QUERY_STRING'});
my $qaction = $ARGV[0] ;
my $selbox = $ARGV[1] ;
our ($q) = CGI -> new() ;
$iaction = $q -> param('iaction') || $qaction ;
our $dialog = 1 ;
# our $debug = 1 ;
#------------------------------------------------------------------------------------------
# our $savjqy = 1 ; # save via jquery
# our $addbkb = 1 ; # add back button
# our $testing = 1 ;
#------------------------------------------------------------------------------------------
&today ;
#-------- page opts --------------------------------------------------------------------------------------------------------------------------------------------------
our $table = 'users' ;
our $user_type = 'casual' ;
our $lcpage = 'operator' ; $ucpage = uc $lcpage ; $ucfirstpage = ucfirst $lcpage ;
#---------------------------------------------------------------------------------------------------------------------------------------------------------------------
if ($iaction eq 'add') {
&common_min_add_screen;
&screen1 ;
}
if ($iaction eq 'save'){
&common_min_load_params ;
&validate ;
&insert ;
&screen2 ;
}
exit ;
#------------------------------------------------------------------------------------------
sub sort_fields {
&users_sort_fields ;
} #-------------------------------------------------------------------------------
sub validate {
# &common_debug("1. sel_field=$i{sel_field}");
&users_validate;
} #------------------------------------------------------------------------------------------
sub insert {
$ignore{sel_field} = 1 ;
# &common_debug("2. sel_field=$i{sel_field}");
&users_insert ;
} #------------------------------------------------------------------------------------------
sub add_db_fields {
$hidden{sel_field} = 2 ;
$db{$table}{''}{sel_field} = $selbox if $selbox ;
$allow_deselect{based_in} = 1 ;
$allow_deselect{user_type} = 1 ;
$allow_deselect{region_ids} = 1 ;
&users_add_db_fields ;
} #------------------------------------------------------------------------------------------
sub process_multi_select {
&users_process_multi_select ;
} #------------------------------------------------------------------------------------------
sub add_screen {
# called from common_add_screen
$boxtitle = 'Add' ;
&users_add_screen ;
} #------------------------------------------------------------------------------------------
sub screen1 {
$trigger_jquery_raw .= qq~
\$('#btn-close-customer').click(function (e) {
parent.BootstrapDialog.closeAll() ;
});~ ;
&common_min_dialog_load_screen ;
} #------------------------------------------------------------------------------------------
sub screen2 {
# &common_debug("3. sel_field=$i{sel_field}");
if ($selbox eq 'selectEvents_operator_allocated') {
$trigger_jquery_raw .= qq~
let hidden_input = parent.\$("input[name='eventsoperatorallocated']").val() ;
if (hidden_input) {
parent.\$("input[name='eventsoperatorallocated']").val(hidden_input+",$i{id}") ;
} else {
parent.\$("input[name='eventsoperatorallocated']").val("$i{id}") ;
}
~ ;
}
$trigger_jquery_raw .= qq~
parent.\$("#$i{sel_field}").append("<option SELECTED value='$i{id}'>$i{name}</option>");
// parent.\$("#$i{sel_field}").val('$new_row_id').trigger('change'); // this must stay commented out for multi-selects, otherwise it removes existing selected options
parent.\$("#$i{sel_field}").trigger("chosen:updated");
parent.BootstrapDialog.closeAll() ;
~;
&common_min_dialog_save_screen ;
} #------------------------------------------------------------------------------------------
use db ;
use users ;
use today ;
use common ;
use dialog ;
1;