aisa/scripts/dialog/add_club.pl

190 lines
5.1 KiB
Perl
Raw 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);
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 $savjqy = 1 ; # save via jquery
# our $addbkb = 1 ; # add back button
# our $testing = 1 ;
#------------------------------------------------------------------------------------------
&today ;
#-------- page opts --------------------------------------------------------------------------------------------------------------------------------------------------
our $table = 'clubs' ;
#---------------------------------------------------------------------------------------------------------------------------------------------------------------------
if ($iaction eq 'add') {
&load_vars ;
&common_min_add_screen;
&screen1 ;
}
if ($iaction eq 'save') {
&common_min_load_params ;
&validate ;
&insert_clubs ;
&screen2 ;
}
exit ;
#------------------------------------------------------------------------------------------
sub load_vars {
$preferred_title{name} = "Club Name" ;
$sort_field{1} = 'name' ;
$sort_field{2} = 'status' ;
$select{status} = 1 ;
$allow_deselect{status} = 1 ;
$textarea{club_name} = 1 ;
# $trigger_jquery_raw .= qq~\$("#selectStatus").chosen({ allow_single_deselect:false });~ ;
} #------------------------------------------------------------------------------------------
sub validate {
# $i{city} = uc $i{city} ;
my $exists = '' ;
$i{name} = &common_fix_str($i{name}) ;
if (length($i{name}) > 75) { $alert = &common_min_alert('warning',"YOUR CLUB NAME CONTAINS TOO MANY CHARACTERS!",'warning-sign') ; %col_name = () ; &load_vars ; &common_min_add_screen ; &screen1 ; exit ; }
&db_min_ro($table,'*',"name = '$i{name}'",'name','') ;
foreach my $id (keys %{$db{$table}}) { if (lc $db{$table}{$id}{city} eq lc $i{city}) { $exists = 1 ; } }
if ($exists) { $alert = &common_min_alert('warning',"$ucpage ALREADY EXISTS!",'warning-sign') ; %col_name = (); &load_vars ; &common_min_add_screen; &screen1; exit ; }
} #------------------------------------------------------------------------------------------
sub insert_clubs {
&add_db_fields ;
# &db_min_ro($table,"1,MAX(id)+1 as 'max_id'",'','','') ;
# $i{id} = $db{$table}{1}{max_id} ;
# $i{name} = $i{name} ;
# $ignore{club_name} = 1 ;
$i{id} = &db_min_get_max($table,'id') ;
$i{users_count} = 0 unless $i{users_count} ;
&db_min_insert($table) ;
} #------------------------------------------------------------------------------------------
sub add_db_fields {
&hidden_fields ;
# $ignore{id} = 1 ;
} #------------------------------------------------------------------------------------------
sub hidden_fields {
$ignore{iaction} = 1 ;
# $required{city} = 1 ;
# $required{province} = 1 ;
# $required{lat} = 1 ;
# $required{lng} = 1 ;
} #------------------------------------------------------------------------------------------
sub add_screen {
# called from common_add_screen
$boxtitle = 'Add' ;
&select_opts ;
} #------------------------------------------------------------------------------------------
sub select_opts {
$opts{status} .= qq~<option value = "active" SELECTED >Active</option>~ ;
$opts{status} .= qq~<option value = "inactive">Inactive</option>~ ;
} #------------------------------------------------------------------------------------------
sub screen1 {
$trigger_jquery_raw .= qq~
\$('#btn-close-customer').click(function (e) {
parent.BootstrapDialog.closeAll() ;
});~ ;
&common_min_dialog_load_screen ;
} #------------------------------------------------------------------------------------------
sub screen2 {
$trigger_jquery_raw .= qq~
// parent.\$("#$i{sel_field}").append("<option SELECTED value='$i{id}'>$i{name}</option>");
// parent.\$("#$i{sel_field}").val('$i{id}').trigger('change');
// parent.\$("#$i{sel_field}").trigger("chosen:updated");
for (let system_row_cnt=1;system_row_cnt<=15;system_row_cnt++) {
let club_drop_down_exists = parent.\$("#system_name_row_"+system_row_cnt).find("#selectClub_name_"+system_row_cnt).length ;
if (club_drop_down_exists) {
let club_name_field = "#selectClub_name_"+system_row_cnt ;
parent.\$(club_name_field).append("<option value='$i{id}'>$i{name}</option>");
if (!parent.\$(club_name_field).val()) {
parent.\$(club_name_field).val("$i{id}") ;
parent.\$(club_name_field).trigger("chosen:updated");
}
}
}
parent.BootstrapDialog.closeAll() ;
~;
&common_min_dialog_save_screen ;
} #------------------------------------------------------------------------------------------
use db ;
use today ;
use common ;
use common_min ;
use dialog ;
1;