#!/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 ; # our $debug = 1 ; #------------------------------------------------------------------------------------------ &today ; #-------- page opts -------------------------------------------------------------------------------------------------------------------------------------------------- our $table = 'organisations' ; #--------------------------------------------------------------------------------------------------------------------------------------------------------------------- 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} = 'name' ; $sort_field{2} = 'region_id' ; $select{region_id} = 1 ; $allow_deselect{region_id} = 1 ; # local $region_id_where = qq~~ ; local @abcd = () ; # if ($usertype eq 'schools_manager') { # &db_min_ro('users','1,region_ids',"`id`='$userid'",'','') ; # foreach (split(",",$db{users}{1}{region_ids})) { # push @abcd , "`id` = '$_'" ; # } # } # $region_id_where = join (" OR ",@abcd) ; 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','id,name,code',$region_id_where,'','') ; foreach (sort {$db{regions}{$a}{name} cmp $db{regions}{$b}{name}} keys %{$db{regions}}) { $opts{region_id} .= qq~~ ; } } #------------------------------------------------------------------------------------------ sub validate { # $i{name} = uc $i{name} ; my $exists = '' ; $i{name} = &common_fix_str($i{name}) ; &db_min_ro($table,'*',"name = '$i{name}'",'name','') ; foreach my $id (keys %{$db{$table}}) { if (lc $db{$table}{$id}{name} eq lc $i{name}) { $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 ; &db_min_ro('regions','id,code',"id = '$i{region_id}'",'','') ; $i{region_code} = $db{regions}{$i{region_id}}{code} ; # $ignore{region_id} = 1 ; $ignore{sel_field} = 1 ; $i{id} = &db_min_get_max($table,'id') ; &db_min_insert('organisations') ; } #------------------------------------------------------------------------------------------ sub add_db_fields { &hidden_fields ; # $ignore{id} = 1 ; } #------------------------------------------------------------------------------------------ sub hidden_fields { $ignore{iaction} = 1 ; $required{name} = 1 ; $required{region_id} = 1 ; $hidden{sel_field} = 2 ; $db{$table}{''}{sel_field} = $selbox if $selbox ; } #------------------------------------------------------------------------------------------ sub add_screen { # called from common_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 { $trigger_jquery_raw .= qq~ parent.\$("#$i{sel_field}").append(""); // 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 today ; use common ; use common_min ; use dialog ; 1;