204 lines
6.2 KiB
Perl
204 lines
6.2 KiB
Perl
#!/usr/bin/perl
|
|
|
|
BEGIN { use lib '/usr/home/cfg' ; require push_inc ; }
|
|
|
|
require cfg ;
|
|
|
|
#---------------------------------------------------------------------------------------------------------------------------------------------------------------------
|
|
|
|
use CGI::Carp qw(fatalsToBrowser);
|
|
use CGI;
|
|
|
|
&today;
|
|
|
|
#---------------------------------------------------------------------------------------------------------------------------------------------------------------------
|
|
|
|
@ARGV = split(/\\*\&/, $ENV{'QUERY_STRING'});
|
|
$action = $ARGV[0] ;
|
|
|
|
our ($q) = CGI -> new() ;
|
|
our $iaction = $q -> param('iaction') || $action ;
|
|
our $isaved = $q -> param('isaved') || '' ;
|
|
|
|
# our $debug = 1 ;
|
|
|
|
#-------- page opts --------------------------------------------------------------------------------------------------------------------------------------------------
|
|
|
|
&page_opts ;
|
|
|
|
#---------------------------------------------------------------------------------------------------------------------------------------------------------------------
|
|
|
|
print "Content-type: text/html\n\n";
|
|
|
|
&common_min_action;
|
|
|
|
exit;
|
|
|
|
#------------------------------------------------------------------------------------------
|
|
|
|
sub validate {
|
|
|
|
my $exists = '' ;
|
|
|
|
$i{name} = lc $i{name} ;
|
|
$i{name} =~ s/ //gi ;
|
|
|
|
&db_min_ro($table,'*',"name = '$i{name}'",'name','') ;
|
|
|
|
foreach my $id (keys %{$db{$table}}) { if ($db{$table}{$id}{name} eq $i{name}) { $exists = 1 ; } }
|
|
|
|
if ($exists) {
|
|
$alert = &common_min_alert('warning',"NAME ALREADY EXISTS!",'ok') ;
|
|
%col_name = ();
|
|
&common_min_add_screen;
|
|
&common_min_screen1;
|
|
}
|
|
|
|
} #------------------------------------------------------------------------------------------
|
|
|
|
sub insert {
|
|
|
|
&add_db_fields ;
|
|
|
|
# $i{lastupdate} = "$now_ccyy_mm_dd $now_hour:$now_min:$now_sec" ;
|
|
|
|
&db_min_insert($table) ;
|
|
|
|
} #------------------------------------------------------------------------------------------
|
|
|
|
sub update {
|
|
|
|
unless ($i{id}) { $error = qq(NO ID) ; return ; }
|
|
|
|
&edit_db_fields ;
|
|
|
|
# unless ($i{block}) { $i{block} = '0' ; }
|
|
# $i{lastupdate} = "$now_ccyy_mm_dd $now_hour:$now_min:$now_sec" ;
|
|
|
|
&db_min_upd($table,"id='$i{id}'") ;
|
|
|
|
} #------------------------------------------------------------------------------------------
|
|
|
|
sub list_screen {
|
|
|
|
my %seen_camera = () ;
|
|
my $delete_button = "" ;
|
|
|
|
&db_min_ro('event_quotes','id, camera_system_id','','','') ;
|
|
|
|
foreach my $id (keys %{$db{'event_quotes'}}) {
|
|
next if $seen_camera{$db{'event_quotes'}{$id}{camera_system_id}} ;
|
|
$seen_camera{$db{'event_quotes'}{$id}{camera_system_id}} = 1 ;
|
|
}
|
|
|
|
&db_min_ro('quotes','id, camera_system_id','','','') ;
|
|
|
|
foreach my $id (keys %{$db{'quotes'}}) {
|
|
next if $seen_camera{$db{'quotes'}{$id}{camera_system_id}} ;
|
|
$seen_camera{$db{'quotes'}{$id}{camera_system_id}} = 1 ;
|
|
}
|
|
|
|
&db_min_ro($table,'*','','name','') ;
|
|
|
|
foreach my $id (keys %{$db{$table}}) {
|
|
my $disp_blocked = qq(<span class="label label-success" title="Active!" data-toggle="tooltip"><i class="glyphicon glyphicon-ok"></i></span>); if ($db{$table}{$id}{block}) { $disp_blocked = qq(<span class="label label-danger" title="Blocked!" data-toggle="tooltip"><i class="glyphicon glyphicon-ok"></i></span>); }
|
|
|
|
# $opts{$lcpage} .= qq~<option value="$db{$table}{$id}{username}">$db{$table}{$id}{name}</option>~ ;
|
|
|
|
my $edit_butt = '' ; my $del_butt = '' ;
|
|
|
|
if ($useropts{super}{$username}) {
|
|
$edit_butt = qq~ <a class="btn btn-info btn-xs" href="javascript:editMinItem('$db{$table}{$id}{id}');"><i class="glyphicon glyphicon-edit icon-white"></i></a>~ ;
|
|
}
|
|
if ($useropts{boss}{$username} or $useropts{super}{$username}) {
|
|
$del_butt = qq~ <a class="btn btn-danger btn-xs" href="javascript:deleteMinItem('$db{$table}{$id}{name}','$db{$table}{$id}{id}')"><i class="glyphicon glyphicon-trash icon-white"></i></a>~ if not $seen_camera{$id} ;
|
|
$del_butt = qq~ <a class="btn btn-default btn-xs" href="#" title data-toggle="tooltip" data-original-title="In system use!"><i class="glyphicon glyphicon-trash icon-white"></i></a>~ if $seen_camera{$id} ;
|
|
}
|
|
|
|
$print_tbody .= qq~<tr id="$id">
|
|
<td>$id</td>
|
|
<td>$db{$table}{$id}{name}</td>
|
|
<td>$db{$table}{$id}{description}</td>
|
|
<td nowrap>
|
|
$edit_butt
|
|
$del_butt
|
|
</td>
|
|
</tr>~ ;
|
|
}
|
|
|
|
} #------------------------------------------------------------------------------------------
|
|
|
|
sub add_db_fields {
|
|
|
|
&hidden_db_fields;
|
|
|
|
$ignore{id} = 1 ;
|
|
|
|
} #------------------------------------------------------------------------------------------
|
|
|
|
sub edit_db_fields {
|
|
|
|
&hidden_db_fields;
|
|
|
|
$hidden{id} = 1 ; # 1 = bypass for db update
|
|
|
|
} #------------------------------------------------------------------------------------------
|
|
|
|
sub hidden_db_fields {
|
|
|
|
$ignore{iaction} = 1 ;
|
|
|
|
# $readonly{name} = 'READONLY' ;
|
|
$required{name} = 1 ;
|
|
$required{description} = 1 ;
|
|
|
|
} #------------------------------------------------------------------------------------------
|
|
|
|
sub add_screen {
|
|
|
|
# called from common_add_screen
|
|
|
|
&select_opts ;
|
|
|
|
} #------------------------------------------------------------------------------------------
|
|
|
|
sub edit_screen {
|
|
|
|
# our ($lcol,$fcol) = &common_min_columns($label_col,$field_col) ;
|
|
|
|
# $selected{based_in}{$db{$table}{$i{id}}{based_in}} = "SELECTED" ;
|
|
|
|
# $extra_form_fields .= &common_min_form_input('new_password','','password') ;
|
|
|
|
&select_opts ;
|
|
|
|
} #------------------------------------------------------------------------------------------
|
|
|
|
sub select_opts {
|
|
|
|
# $required{based_in} = 1 ;
|
|
# $select{based_in} = 1 ;
|
|
# $opts{based_in} = qq(<option value="JNB" $selected{based_in}{'JNB'}>Johannesburg</option><option value="CPT" $selected{based_in}{'CPT'}>Cape Town</option>) ;
|
|
|
|
} #------------------------------------------------------------------------------------------
|
|
|
|
sub thead {
|
|
|
|
$print_thead = qq(<THEAD><TR><TH>ID</TH><TH>NAME</TH><TH>DESCRIPTION</TH><TH> </TH></TR></THEAD>) ;
|
|
|
|
} #-------------------------------------------------------------------------------
|
|
|
|
sub page_opts {
|
|
|
|
our $glyphicon = 'facetime-video' ;
|
|
our $lcpage = 'camera-system' ; $ucpage = uc $lcpage ; $ucfirstpage = ucfirst $lcpage ;
|
|
our $table = 'camera_systems' ;
|
|
|
|
&common_min_add_extras ;
|
|
|
|
} #-------------------------------------------------------------------------------
|
|
|
|
use common ;
|
|
use today ;
|
|
|
|
1; |