File:  [LON-CAPA] / loncom / interface / lonmanagekeys.pm
Revision 1.1: download - view: text, annotated - select for diffs
Sat Apr 12 15:57:30 2003 UTC (21 years ago) by www
Branches: MAIN
CVS tags: HEAD
"Return Location" link in inline remote

# The LearningOnline Network with CAPA
# Handler to manage course access keys 
#
# $Id: lonmanagekeys.pm,v 1.1 2003/04/12 15:57:30 www Exp $
#
# Copyright Michigan State University Board of Trustees
#
# This file is part of the LearningOnline Network with CAPA (LON-CAPA).
#
# LON-CAPA is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
#
# LON-CAPA is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with LON-CAPA; if not, write to the Free Software
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
#
# /home/httpd/html/adm/gpl.txt
#
# http://www.lon-capa.org/
#
###############################################################
###############################################################

package Apache::lonmanagekeys;

use strict;
use Apache::lonnet();
use Apache::loncommon();
use Apache::lonhtmlcommon();
use Apache::Constants qw(:common :http REDIRECT);
use Spreadsheet::WriteExcel;

###############################################################
###############################################################
sub header {
    my $bodytag=&Apache::loncommon::bodytag('Access Key Management');
    return(<<ENDHEAD);
<html>
<head>
<title>LON-CAPA Access Key Management</title>
</head>
$bodytag
<form method="post" enctype="multipart/form-data"  
      action="/adm/keymanage" name="keyform">
ENDHEAD
}

# =================================================== Show student list to drop
sub show_key_list {
    my ($r,$mode,$linkto,$action,$statusmode,$classlist,$keylist)=@_;
#
# Just junk so that this compiles
#
    my ($username,$domain,$id,$name,$section,$status,@Sorted_Students);
#
# 
# 
    my $cid=$ENV{'request.course.id'};
    #
    # Variables for excel output
    my ($excel_workbook, $excel_sheet, $excel_filename,$row);
    #

    # Print out header 
    if ($mode eq 'view') {
    } elsif ($mode eq 'excel') {
        # Create the excel spreadsheet
        $excel_filename = '/prtspool/'.
            $ENV{'user.name'}.'_'.$ENV{'user.domain'}.'_'.
                time.'_'.rand(1000000000).'.xls';
        $excel_workbook = Spreadsheet::WriteExcel->new('/home/httpd'.
                                                       $excel_filename);
        $excel_workbook->set_tempdir('/home/httpd/perl/tmp');
        $excel_sheet = $excel_workbook->addworksheet('classlist');
        #
        my $description = 'Classlist for '.
            $ENV{'course.'.$ENV{'request.course.id'}.'.description'};
        $excel_sheet->write($row++,0,$description);
        #
        $excel_sheet->write($row++,0,["username","domain","ID",
                                      "student name","section","status"]);
    }
    foreach my $student (@Sorted_Students) {
        if ($mode eq 'view') {
        } elsif ($mode eq 'csv') {
            # no need to bother with $linkto
            my @line = ();
            foreach ($username,$domain,$id,$name,$section) {
                push @line,&Apache::loncommon::csv_translate($_);
            }
            if ($statusmode eq 'Any') {
                push @line,&Apache::loncommon::csv_translate($status);
            }
            my $tmp = $";
            $" = '","';
            $r->print("\"@line\"\n");
            $" = $tmp;
        } elsif ($mode eq 'excel') {
            $excel_sheet->write($row++,0,[$username,$domain,$id,
                                          $name,$section,$status]);
        }
    }
    if ($mode eq 'view') {
    } elsif ($mode eq 'excel') {
        $excel_workbook->close();
        $r->print('<p><a href="'.$excel_filename.'">'.
                  'Your Excel spreadsheet</a> is ready for download.</p>'."\n");
    }
}

###################################################################
###################################################################
sub handler {
    my $r=shift;
    if ($r->header_only) {
        $r->content_type('text/html');
        $r->send_http_header;
        return OK;
    }
    &Apache::loncommon::get_unprocessed_cgi($ENV{'QUERY_STRING'},['state']);

    unless (&Apache::lonnet::allowed('mky',$ENV{'request.role.domain'})) {
        $ENV{'user.error.msg'}=
            "/adm/managekeys:mky:0:0:Cannot manage access keys";
        return HTTP_NOT_ACCEPTABLE; 
    }
    #
    # Only output the header information if they did not request csv format
    #
    if (exists($ENV{'form.state'}) && ($ENV{'form.state'} eq 'csv')) {
        $r->content_type('text/csv');
    } else {
        # Start page
        $r->content_type('text/html');
        $r->send_http_header;
        $r->print(&header());
    }
#
# do stuff here.
#

    if (exists($ENV{'form.state'}) && ($ENV{'form.state'} eq 'csv')) {
        $r->print("\n");
    } else {
        $r->print('</form></body></html>');
    }
    return OK;
}

###################################################################
###################################################################

1;
__END__



FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>