aisa/scripts/leave.pl
2025-11-26 11:31:54 +02:00

253 lines
7.5 KiB
Perl

#!/usr/bin/perl
BEGIN { use lib '/usr/home/cfg' ; require push_inc ; }
use CGI qw( :standard );
use CGI::Carp qw(fatalsToBrowser);
use Fcntl qw(:flock);
use File::Copy;
use File::Basename;
require cfg ;
print header; # CGI.pm method
#---------------------------------------------------------------------------------------------------------------------------------------------------------------------
&today;
#---------------------------------------------------------------------------------------------------------------------------------------------------------------------
# unless ($username eq 'rory') { print ">>>>>> APOLOGIES, DOING MAINTENANCE <<<<<<"; exit; }
@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 ;
&common_min_restriction_super ;
#-------- page opts --------------------------------------------------------------------------------------------------------------------------------------------------
&page_opts ;
#---------------------------------------------------------------------------------------------------------------------------------------------------------------------
&common_min_action;
exit;
#------------------------------------------------------------------------------------------
sub validate {
# my $exists = '' ;
# &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',"$ucpage ALREADY EXISTS!",'ok') ; %col_name = (); &common_min_add_screen; &common_min_screen1; }
} #------------------------------------------------------------------------------------------
sub insert {
&add_db_fields ;
$i{id} = &db_min_get_max($table,'id') ;
&common_min_upload_files("leave/$i{id}") ;
$i{date_time} = "$now_ccyy_mm_dd $now_hour:$now_min:$now_sec" ;
$i{category} = 'leave' ;
&db_min_insert($table) ;
} #------------------------------------------------------------------------------------------
sub update {
unless ($i{id}) { $error = qq(NO ID) ; return ; }
&edit_db_fields ;
&common_min_upload_files("leave/$i{id}") ;
# 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 {
&db_min_ro('users','*','','','') ;
foreach my $id (keys %{$db{users}}) { $user_name{$id} = $db{users}{$id}{name} ; }
my $extra_sql = '' ; unless ($useropts{super}{lc $username}) { $extra_sql = " AND `user_id`='$userid'" ; }
&db_min_ro($table,'*',"`category`='leave'$extra_sql",'','') ;
foreach my $id (keys %{$db{$table}}) {
my $leave_type = ucfirst $db{$table}{$id}{type} ;
my $attach_butt = '' ; $attach_options = &common_min_get_uploads("leave/$id",'all') ; if ($attach_options) { $attach_butt = qq(&nbsp;<a href="#" data-toggle="popover" data-placement="left" data-content="$attach_options" title="Uploaded Documents" data-html="true" data-trigger="focus" class="btn btn-default btn-xs"><i class="glyphicon glyphicon-paperclip" style="top:4px;"></i></a>) ; }
my $edit_butt = '' ;
my $del_butt = '' ;
if ($useropts{boss}{lc $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>&nbsp;) ;
$del_butt = qq(<a class="btn btn-danger btn-xs" href="javascript:deleteMinItem('$user_name{$db{$table}{$id}{user_id}} $leave_type Leave','$db{$table}{$id}{id}')"><i class="glyphicon glyphicon-trash icon-white"></i></a>) ;
}
$print_tbody .= qq(<tr id="$id">
<td>$id</td>
<td>$db{$table}{$id}{date_time}</td>
<td><span class="label-primary label">$user_name{$db{$table}{$id}{user_id}}</span></td>
<td>$db{$table}{$id}{startdate}</td>
<td>$db{$table}{$id}{enddate}</td>
<td>$db{$table}{$id}{days}</td>
<td><span class="label-default label">$leave_type</span></td>
<td>$db{$table}{$id}{notes}</td>
<td nowrap>&nbsp;
$edit_butt
$del_butt
$attach_butt
</td>
</tr>) ;
}
} #------------------------------------------------------------------------------------------
sub thead {
$print_thead = qq(<THEAD><TR><TH>ID</TH><TH>DATE ADDED</TH><TH>STAFF NAME</TH><TH>START DATE</TH><TH>END DATE</TH><TH>DAYS</TH><TH>TYPE</TH><TH>NOTES</TH><TH>&nbsp;</TH></TR></THEAD>) ;
} #-------------------------------------------------------------------------------
sub add_db_fields {
&hidden_db_fields ;
# $ignore{id} = 1 ;
$hidden{id} = 2 ;
} #------------------------------------------------------------------------------------------
sub sort_leave_fields {
$sort_field{1} = 'startdate' ;
$sort_field{2} = 'enddate' ;
$sort_field{3} = 'days' ;
$sort_field{4} = 'type' ;
$sort_field{5} = 'user_id' ;
$sort_field{6} = 'notes' ;
} #-------------------------------------------------------------------------------
sub hidden_db_fields {
$ignore{iaction} = 1 ;
$textarea{notes} = 1 ;
# $required{title} = 1 ;
$required{category} = 1 ;
$required{days} = 9 ;
$datetimepicker{startdate} = 1 ;
$datetimepicker{enddate} = 1 ;
$ignore{completed} = 1 ;
$ignore{iattachleave} = 1 ;
$ignore{title} = 1 ;
# $hidden{user_id} = 2 ;
$hidden{date_time} = 2 ;
$hidden{category} = 2 ;
&sort_leave_fields ;
} #------------------------------------------------------------------------------------------
sub edit_db_fields {
&hidden_db_fields ;
$hidden{id} = 1 ;
} #------------------------------------------------------------------------------------------
sub add_screen {
&select_opts('') ;
} #------------------------------------------------------------------------------------------
sub edit_screen {
$selected{'type'}{$db{$table}{$i{id}}{type}} = 'SELECTED' ;
$leave_uploads = &common_min_get_uploads("leave/$i{id}",'leave') ;
&select_opts($i{id}) ;
} #------------------------------------------------------------------------------------------
sub select_opts {
my ($id) = @_ ;
@user_excl_sql = () ;
foreach (keys %{$useropts{it}}) {
push @user_excl_sql, "username <> '$_'" ;
}
my $user_excl_sql = join(" AND ", @user_excl_sql) ;
&common_min_select_opts('user_id','users','name',$db{$table}{$id}{user_id},1,'',$user_excl_sql) ;
&common_min_opts('leave_type','type',1) ;
$extra_form_fields .= qq(<div class='row'><div class="col-md-12">&nbsp;</div></div>
<div class='row'>
<div class="col-md-12">
<div class="form-group">
<label for="docConfFile">Attach Documents</label>
<input type="file" id="docLeaveFile" name='iattachleave' data-validation="required" tabindex='$tindex'>
<p class="help-block">Upload file from PC.</p>
</div>
</div>
</div>
<div class='row'>
<div class="col-md-12">
$leave_uploads
</div>
</div>
) ;
} #-------------------------------------------------------------------------------
sub page_opts {
our $glyphicon = 'calendar' ;
our $lcpage = 'leave' ; $ucpage = uc $lcpage ; $ucfirstpage = ucfirst $lcpage ;
our $table = 'events' ;
$s{no} = 1 ;
&common_min_add_extras ;
&common_min_add_box_icon ;
unless ($useropts{boss}{lc $username}) { $box_icon = '' ; }
} #-------------------------------------------------------------------------------
use common ;
use today ;
1;