--- loncom/interface/lonmanagekeys.pm 2003/05/02 16:58:56 1.10 +++ loncom/interface/lonmanagekeys.pm 2004/05/08 02:07:16 1.14 @@ -1,7 +1,7 @@ # The LearningOnline Network with CAPA # Handler to manage course access keys # -# $Id: lonmanagekeys.pm,v 1.10 2003/05/02 16:58:56 www Exp $ +# $Id: lonmanagekeys.pm,v 1.14 2004/05/08 02:07:16 www Exp $ # # Copyright Michigan State University Board of Trustees # @@ -36,6 +36,7 @@ use Apache::loncommon(); use Apache::lonhtmlcommon(); use Apache::Constants qw(:common :http REDIRECT); use Spreadsheet::WriteExcel; +use Apache::lonlocal; ############################################################### ############################################################### @@ -54,11 +55,12 @@ ENDHEAD # =================================================== Show student list to drop sub show_key_list { - my ($r,$comment,$newonly,$checkonly,%cenv)=@_; + my ($r,$csvlist,$comment,$newonly,$checkonly,%cenv)=@_; $comment=~s/\W/\./g; my %accesskeys=&Apache::lonnet::dump ('accesskeys',$cenv{'domain'},$cenv{'num'}); - $r->print(<print(< function copyallcom(tf) { for (i=0; i ENDTABLEHEADER + } foreach (keys %accesskeys) { if ($_=~/^error\:/) { $r->print('No keys have been generated yet.'); @@ -87,78 +90,31 @@ ENDTABLEHEADER } else { if ($newonly) { next; } } - $r->print("\n".$_.''.($checkout? + unless ($csvlist) { + $r->print("\n".$_.''.($checkout? $checkout:'-').''. join('
',split(/\s*\;\s*/,$com)). ''); + } else { + my @line = (); + push @line,&Apache::loncommon::csv_translate($_); + push @line,&Apache::loncommon::csv_translate($checkout); + foreach (split(/\s*\;\s*/,$com)) { + push @line,&Apache::loncommon::csv_translate($_); + } + my $tmp = $"; + $" = '","'; + $r->print("\"@line\"\n"); + $" = $tmp; + } } } - $r->print(''); - $r->print('
'); - return ''; -# -# Junk below -# - my ($mode,$linkto,$action,$statusmode,$classlist,$keylist); -# -# Just junk so that this compiles -# - my ($username,$domain,$id,$name,$section,$status,@Sorted_Students); -# -# -# - my $cid=$ENV{'form.cid'}; - # - # 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('

'. - 'Your Excel spreadsheet is ready for download.

'."\n"); + unless ($csvlist) { + $r->print(''); + $r->print('
'); } + return ''; } @@ -219,7 +175,7 @@ sub addcom { sub handler { my $r=shift; if ($r->header_only) { - $r->content_type('text/html'); + &Apache::loncommon::content_type($r,'text/html'); $r->send_http_header; return OK; } @@ -235,20 +191,34 @@ sub handler { return HTTP_NOT_ACCEPTABLE; } if ($ENV{'form.cid'}) { - my %cenv=&Apache::lonnet::coursedescription($ENV{'form.cid'}); - if (exists($ENV{'form.state'}) && ($ENV{'form.state'} eq 'csv')) { + my %cenv=&Apache::lonnet::coursedescription($ENV{'form.cid'}); + my $keytype=''; + if ($cenv{'url'} eq '/res/') { + ($cenv{'num'},$cenv{'domain'})=split(/\_/,$ENV{'form.cid'}); + $keytype='auth'; + } elsif ($cenv{'keyauth'}) { + ($cenv{'num'},$cenv{'domain'})=split(/\W/,$cenv{'keyauth'}); + $keytype='auth'; + } else { + $keytype='course'; + } + if ($ENV{'form.listkeyscsv'}) { # # CSV Output # $r->content_type('text/csv'); + $r->send_http_header; # # Do CSV # + &show_key_list($r,1,$ENV{'form.listcom'}, + $ENV{'form.newonly'},$ENV{'form.checkonly'},%cenv); + } else { # # Normal web stuff # - $r->content_type('text/html'); + &Apache::loncommon::content_type($r,'text/html'); $r->send_http_header; $r->print(&header()); @@ -266,18 +236,24 @@ sub handler { $r->print($msg.'
'); } if ($ENV{'form.listkeys'}) { - &show_key_list($r,$ENV{'form.listcom'}, + &show_key_list($r,0,$ENV{'form.listcom'}, $ENV{'form.newonly'},$ENV{'form.checkonly'},%cenv); } if ($ENV{'form.addcom'}) { &addcom(%cenv); } # --- Menu - $r->print('

Key Access

'); - if ($cenv{'keyaccess'} eq 'yes') { - $r->print('Access to this course is key controlled.
') + if ($keytype eq 'course') { + $r->print('

'.&mt('Key Access').'

'); + if ($cenv{'keyaccess'} eq 'yes') { + $r->print(&mt('Access to this course is key controlled.'). +'
') } else { - $r->print('Access to this course is open, no access keys.
'); + $r->print(&mt('Access to this course is open, no access keys').'
'); + } + } else { + $r->print('

'.&mt('Key Authority'). + ' '.$cenv{'num'}.'@'.$cenv{'domain'}.'

'); } $r->print(<

Generate New Keys

@@ -285,26 +261,27 @@ Number of keys to be generated:

List Keys

-Comments/Remarks/Notes/User/Batch Number: +Comments/Remarks/Notes/User/Batch Number Filter:
Unused keys only
Used keys only
- + + ENDKEYMENU $r->print(''); } } else { # Start page no course id - $r->content_type('text/html'); + &Apache::loncommon::content_type($r,'text/html'); $r->send_http_header; $r->print(&header().&Apache::loncommon::coursebrowser_javascript()); $r->print( - 'Course ID: '); - $r->print('Domain: '.&Apache::loncommon::select_dom_form( + &mt('Course ID of Key Authority').': '); + $r->print(&mt('Domain').': '.&Apache::loncommon::select_dom_form( $ENV{'request.role.domain'},'domain')); $r->print(&Apache::loncommon::selectcourse_link( 'keyform','course','domain')); - $r->print('
'); + $r->print('
'); $r->print(''); } return OK;