182 lines
5.0 KiB
Perl
182 lines
5.0 KiB
Perl
|
|
#!/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] ;
|
||
|
|
my $organisation_ids = $ARGV[2] ;
|
||
|
|
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 = 'addresses' ;
|
||
|
|
|
||
|
|
#---------------------------------------------------------------------------------------------------------------------------------------------------------------------
|
||
|
|
|
||
|
|
if ($iaction eq 'add') {
|
||
|
|
&load_vars ;
|
||
|
|
&common_min_add_screen;
|
||
|
|
&screen1 ;
|
||
|
|
}
|
||
|
|
|
||
|
|
if ($iaction eq 'save') {
|
||
|
|
&common_min_load_params ;
|
||
|
|
&validate ;
|
||
|
|
&insert ;
|
||
|
|
&screen2 ;
|
||
|
|
}
|
||
|
|
|
||
|
|
exit ;
|
||
|
|
|
||
|
|
#------------------------------------------------------------------------------------------
|
||
|
|
|
||
|
|
sub load_vars {
|
||
|
|
|
||
|
|
$sort_field{1} = 'address' ;
|
||
|
|
$sort_field{2} = 'organisation_id' ;
|
||
|
|
|
||
|
|
$preferred_title{organisation_id} = "Venue" ;
|
||
|
|
$select{organisation_id} = 1 ;
|
||
|
|
$textarea{address} = 1;
|
||
|
|
|
||
|
|
foreach (split(/,/,$organisation_ids)) {
|
||
|
|
$include_organisation_ids{$_} = 1 ;
|
||
|
|
}
|
||
|
|
|
||
|
|
my $sql_or = '' ;
|
||
|
|
|
||
|
|
if ($is_schools_manager || $is_operator) {
|
||
|
|
@report_sql_or = () ;
|
||
|
|
foreach $_reg_id (keys %{$glob_regids{$userid}}) {
|
||
|
|
push @report_sql_or, "id = '$_reg_id'"
|
||
|
|
}
|
||
|
|
$sql_or = join(' OR ',@report_sql_or) ;
|
||
|
|
}
|
||
|
|
|
||
|
|
&db_min_ro('regions','code,1',"$sql_or",'','') ;
|
||
|
|
|
||
|
|
my %regions_code = () ;
|
||
|
|
|
||
|
|
foreach (keys %{$db{regions}}) {
|
||
|
|
$regions_code{$_} = 1 ;
|
||
|
|
}
|
||
|
|
|
||
|
|
&db_min_ro('organisations','*',"$sql_or",'','') ;
|
||
|
|
|
||
|
|
foreach (sort {$db{organisations}{$a}{name} cmp $db{organisations}{$b}{name}} keys %{$db{organisations}}) {
|
||
|
|
next unless $regions_code{$db{organisations}{$_}{region_code}} ;
|
||
|
|
next unless $include_organisation_ids{$_} ;
|
||
|
|
$opts{organisation_id} .= qq~<option value="$_">$db{organisations}{$_}{name} [$db{organisations}{$_}{region_code}]</option>~ ;
|
||
|
|
}
|
||
|
|
|
||
|
|
} #------------------------------------------------------------------------------------------
|
||
|
|
|
||
|
|
sub validate {
|
||
|
|
|
||
|
|
my $exists = '' ;
|
||
|
|
|
||
|
|
$i{address} = &common_fix_str($i{address}) ;
|
||
|
|
|
||
|
|
&db_min_ro($table,'*',"`address` = '$i{address}'",'address','') ;
|
||
|
|
|
||
|
|
foreach my $id (keys %{$db{$table}}) { if ($db{$table}{$id}{address} eq $i{address}) { $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 {
|
||
|
|
|
||
|
|
&add_db_fields ;
|
||
|
|
|
||
|
|
$ignore{sel_field} = 1 ;
|
||
|
|
$ignore{id} = 1 ;
|
||
|
|
|
||
|
|
&db_min_insert($table) ;
|
||
|
|
|
||
|
|
} #------------------------------------------------------------------------------------------
|
||
|
|
|
||
|
|
sub add_db_fields {
|
||
|
|
|
||
|
|
&hidden_fields ;
|
||
|
|
|
||
|
|
$hidden{sel_field} = 2 ;
|
||
|
|
$db{$table}{''}{sel_field} = $selbox if $selbox ;
|
||
|
|
$ignore{id} = 1 ;
|
||
|
|
|
||
|
|
} #------------------------------------------------------------------------------------------
|
||
|
|
|
||
|
|
sub hidden_fields {
|
||
|
|
|
||
|
|
$ignore{iaction} = 1 ;
|
||
|
|
$required{address} = 1 ;
|
||
|
|
$required{organisation_id} = 1 ;
|
||
|
|
|
||
|
|
} #------------------------------------------------------------------------------------------
|
||
|
|
|
||
|
|
sub add_screen {
|
||
|
|
|
||
|
|
$boxtitle = 'Add' ;
|
||
|
|
|
||
|
|
} #------------------------------------------------------------------------------------------
|
||
|
|
|
||
|
|
sub screen1 {
|
||
|
|
|
||
|
|
$trigger_jquery_raw .= qq~
|
||
|
|
\$('#btn-close-customer').click(function (e) {
|
||
|
|
parent.BootstrapDialog.closeAll() ;
|
||
|
|
});~ ;
|
||
|
|
|
||
|
|
&common_min_dialog_load_screen ;
|
||
|
|
|
||
|
|
} #------------------------------------------------------------------------------------------
|
||
|
|
|
||
|
|
sub screen2 {
|
||
|
|
|
||
|
|
my @for_update_fields = split(/_/,$selbox) ;
|
||
|
|
|
||
|
|
$trigger_jquery_raw .= qq~
|
||
|
|
parent.\$("#$i{sel_field}").append("<option SELECTED value='$new_row_id'>$i{address}</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.\$("#checkboxUpdate_to_$for_update_fields[-2]\_$for_update_fields[-1]").prop("checked",true) ;
|
||
|
|
parent.\$("#checkboxUpdate_from_$for_update_fields[-2]\_$for_update_fields[-1]").prop("checked",true) ;
|
||
|
|
parent.BootstrapDialog.closeAll() ;
|
||
|
|
~;
|
||
|
|
|
||
|
|
&common_min_dialog_save_screen ;
|
||
|
|
|
||
|
|
} #------------------------------------------------------------------------------------------
|
||
|
|
|
||
|
|
use db ;
|
||
|
|
use today ;
|
||
|
|
use common ;
|
||
|
|
use common_min ;
|
||
|
|
use dialog ;
|
||
|
|
|
||
|
|
1;
|