"Fossies" - the Fresh Open Source Software Archive

Member "absence-v2.1/cgi-bin/absence-control.pl" (20 Oct 2013, 3967 Bytes) of package /linux/www/web-absence-2.1.tar.gz:


As a special service "Fossies" has tried to format the requested source page into HTML format using (guessed) Perl source code syntax highlighting (style: standard) with prefixed line numbers and code folding option. Alternatively you can here view or download the uninterpreted source code file. For more information about "absence-control.pl" see the Fossies "Dox" file reference documentation.

    1 #!/usr/bin/perl
    2 
    3 #======================================================================
    4 #    This file is part of Absence.
    5 #
    6 #    Absence is free software: you can redistribute it and/or modify
    7 #    it under the terms of the GNU General Public License as published by
    8 #    the Free Software Foundation, either version 3 of the License, or
    9 #    (at your option) any later version.
   10 #
   11 #    Absence is distributed in the hope that it will be useful,
   12 #    but WITHOUT ANY WARRANTY; without even the implied warranty of
   13 #    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
   14 #    GNU General Public License for more details.
   15 #
   16 #    You should have received a copy of the GNU General Public License
   17 #    along with Absence.  If not, see <http://www.gnu.org/licenses/>.
   18 #======================================================================
   19 
   20 # $Id: absence-control.pl 111 2013-10-20 17:57:24Z urban $
   21 
   22 use CGI;
   23 
   24 $CGI::POST_MAX = 100;
   25 $CGI::DISABLE_UPLOADS = 1;
   26 
   27 my $INSTANCE;
   28 
   29 BEGIN {
   30     if ($ENV{QUERY_STRING} =~ /^instance=(\S+)$/) {
   31         $ENV{INSTANCE_NAME} = $1;
   32         $INSTANCE = $1;
   33     }
   34 }
   35 
   36 use AbsenceConfig;
   37 use AbsenceDB;
   38 use AbsenceAuthentication;
   39 use AbsenceAuthorization;
   40 
   41 my $DEF_CHUNKSIZE   = 6;
   42 my $MAIN_SCRIPT     = AbsenceConfig::fetch('main_script');
   43 my $MANAGE_SCRIPT   = AbsenceConfig::fetch('manage_script');
   44 #my $CONTROL_SCRIPT = AbsenceConfig::fetch('control_script');
   45 my $TOP             = AbsenceConfig::fetch('data_dir_rel');
   46 my $COLOR_CONTROL   = AbsenceConfig::fetch('wp_control');
   47 my $VERSION         = '2.0.1';
   48 my $COOKIE_NAME     = 'absence';
   49 
   50 if (exists($ENV{INSTANCE_NAME})){
   51     $MAIN_SCRIPT .= "?instance=$ENV{INSTANCE_NAME}";
   52     $COOKIE_NAME = "absence-$ENV{INSTANCE_NAME}";
   53 }
   54 
   55 my ($month, $year) = (localtime(time))[4,5];
   56 $month++;
   57 $year += 1900;
   58 my $chunksize = $DEF_CHUNKSIZE;
   59 
   60 my $q = new CGI;
   61 $q->import_names;
   62 $q->charset('utf-8');
   63 
   64 #-----------------------------------------------------------------
   65 # first, authenticate if necessary
   66 #-----------------------------------------------------------------
   67 my $AUTH_UID = AbsenceAuthentication::checkAuthentication($q);
   68 
   69 my %cook = $q->cookie($COOKIE_NAME);
   70 
   71 if (exists($cook{chunksize})) {
   72     $chunksize = $cook{chunksize};
   73 }
   74 
   75 my $def_group_id = '';
   76 if (exists($cook{group_id})) {
   77     $def_group_id = $cook{group_id};
   78 }
   79 
   80 if (exists($cook{month})) {
   81     $month = $cook{month};
   82     $year = $cook{year};
   83 }
   84 
   85 print $q->header(),
   86     $q->start_html(
   87         -title      => 'Absence',
   88         -target     => 'display',
   89         -BGCOLOR    => $COLOR_CONTROL,
   90     );
   91 
   92 if ((AbsenceConfig::fetch('authentication') eq 'yes') &&
   93     !defined($ENV{REMOTE_USER}))
   94 {
   95     print "<H3>NOT AUTHENTICATED</H3>\n", $q->end_html;
   96     exit;
   97 }
   98 
   99 print $q->startform(
  100     -name   => 'AbsenceControl',
  101     -action => $MAIN_SCRIPT,
  102     -method => 'POST',
  103 );
  104 
  105 #print "AU:$AUTH_USER ";
  106 
  107 print "Show";
  108 print $q->popup_menu(
  109     -name   => 'chunksize',
  110     -values => [1..15],
  111     -default=> $chunksize,
  112 );
  113 print "Months. Start with ";
  114 print $q->popup_menu(
  115     -name   => 'start_month',
  116     -values => [1..12],
  117     -default=> $month,
  118 );
  119 print $q->popup_menu(
  120     -name   => 'start_year',
  121     -values => [2005..2025],
  122     -default=> $year,
  123 );
  124 print $q->submit(-value => 'SHOW ME!');
  125 print $q->submit(-name => 'jump',   -value => 'Previous');
  126 print $q->submit(-name => 'jump',   -value => 'Next');
  127 print "Group";
  128 my @groups = AbsenceAuthorization::getReadGroups($AUTH_UID);
  129 my $labref;
  130 my $def;
  131 foreach my $group_id (@groups) {
  132     $name = AbsenceDB::getGroup($group_id, 'name');
  133     $labref->{$group_id} = $name;
  134 }
  135 my $js_submit = q[JavaScript:document.AbsenceControl.submit();];
  136 
  137 my @sorted = sort {lc($labref->{$a}) cmp lc($labref->{$b})} @groups;
  138 print $q->popup_menu(
  139     -name       => 'group_id',
  140     -values     => \@sorted,
  141     -default    => $def_group_id,
  142     -labels     => $labref,
  143     -onChange   => $js_submit,
  144 );
  145 
  146 my $inst_str;
  147 if (exists($ENV{INSTANCE_NAME})) {
  148     $inst_str = qq[?instance=$ENV{INSTANCE_NAME}];
  149 }
  150 print qq[&nbsp;&nbsp;<A HREF="$MANAGE_SCRIPT$inst_str">Manage</A><BR>\n];
  151 print $q->endform;
  152 #print "<BR>cookie_name = [$COOKIE_NAME]\n";
  153 
  154 
  155 print $q->end_html;