--- loncom/interface/lonquickgrades.pm 2011/06/03 00:04:47 1.99 +++ loncom/interface/lonquickgrades.pm 2015/03/13 22:34:00 1.106 @@ -1,7 +1,7 @@ # The LearningOnline Network with CAPA # Quick Student Grades Display # -# $Id: lonquickgrades.pm,v 1.99 2011/06/03 00:04:47 www Exp $ +# $Id: lonquickgrades.pm,v 1.106 2015/03/13 22:34:00 raeburn Exp $ # # Copyright Michigan State University Board of Trustees # @@ -29,12 +29,30 @@ package Apache::lonquickgrades; use strict; -use Apache::Constants qw(:common :http); +use Apache::Constants qw(:common :http REDIRECT); use POSIX; use Apache::loncommon; use Apache::lonlocal; use Apache::lonnet; use Apache::grades; +use Apache::loncoursedata; +use Apache::lonstudentassessment; + +use Time::HiRes; +use Spreadsheet::WriteExcel; +use Spreadsheet::WriteExcel::Utility(); +# +# Excel data +# +my $excel_sheet; +my $excel_workbook; +my $filename; +my $format; +my $request_aborted; +my $header_row; +my $cols_output; +my %prog_state; + sub handler { my $r = shift; @@ -57,6 +75,39 @@ sub real_handler { return OK; } + my $cangrade=&Apache::lonnet::allowed('mgr'); + + unless ($cangrade) { + # Check for critical messages and redirect if present. + my ($redirect,$url) = &Apache::loncommon::critical_redirect(300); + if ($redirect) { + &Apache::loncommon::content_type($r,'text/html'); + $r->header_out(Location => $url); + return REDIRECT; + } + + # Check if course needs to be re-initialized + my $loncaparev = $r->dir_config('lonVersion'); + my ($result,@reinit) = &Apache::loncommon::needs_coursereinit($loncaparev); + + if ($result eq 'switch') { + &Apache::loncommon::content_type($r,'text/html'); + $r->send_http_header; + $r->print(&Apache::loncommon::check_release_result(@reinit)); + return OK; + } elsif ($result eq 'update') { + my $cnum = $env{'course.'.$env{'request.course.id'}.'.num'}; + my $cdom = $env{'course.'.$env{'request.course.id'}.'.domain'}; + my ($furl,$ferr) = &Apache::lonuserstate::readmap("$cdom/$cnum"); + if ($ferr) { + my $requrl = $r->uri; + $env{'user.error.msg'}="$requrl:bre:0:0:Course not initialized"; + $env{'user.reinit'} = 1; + return HTTP_NOT_ACCEPTABLE; + } + } + } + # Send header, don't cache this page &Apache::loncommon::no_cache($r); $r->send_http_header; @@ -81,7 +132,6 @@ sub real_handler { &startGradeScreen($r,'quick'); - my $cangrade=&Apache::lonnet::allowed('mgr'); # # Pick student # @@ -89,6 +139,39 @@ sub real_handler { my $udom; my $stdid; if ($cangrade) { + $r->print("

".&mt("Download Multiple")."

". + ''."\n". + ''. + ''. + ''. + ''. + ''. + ''."\n". + ''."\n". + '
'.&mt('Sections').''. + &Apache::loncommon::help_open_topic("Chart_Sections"). + ''.&mt('Groups').''. + ''.&mt('Student Data').''. + &Apache::loncommon::help_open_topic("Chart_Student_Data"). + ''.&mt('Access Status').''. + &Apache::loncommon::help_open_topic("Chart_Enrollment_Status"). + ''.&mt('Output Format').''. + &Apache::loncommon::help_open_topic("Chart_Output_Formats"). + ' 
'."\n". + &Apache::lonstatistics::SectionSelect('Section','multiple',5). + ''. + &Apache::lonstatistics::GroupSelect('Group','multiple',5). + ''. + &Apache::lonstatistics::StudentDataSelect('StudentData','multiple',5,undef). + ''."\n". + &Apache::lonhtmlcommon::StatusOptions(undef,undef,5). + ''."\n". + &Apache::lonstudentassessment::CreateAndParseOutputSelector(). + ''. + ''. + '
'."\n" + ); + $r->print("

".&mt("Display Individual")."

"); if ($env{'form.uname'}) { $uname=$env{'form.uname'}; } if ($env{'form.udom'}) { $udom=$env{'form.udom'}; } if ($env{'form.id'}) { $stdid=$env{'form.id'}; } @@ -106,8 +189,8 @@ sub real_handler { $r->print(&mt('For User [_1] or Student/Employee ID [_2] at Domain [_3]' ,'' ,' ' - ,$chooseopt).'
'. - '

'); + ,$chooseopt). + '  

'); if (($uname) && ($udom)) { $r->print('

'.&mt('Full Name: [_1]',&Apache::loncommon::plainname($uname,$udom)).'

'); } @@ -125,7 +208,6 @@ sub real_handler { $navmap,$totalParts,$totalPossible,$totalRight,$totalAttempted,$topLevelParts,$topLevelRight,$topLevelAttempted); } if ($cangrade) { $r->print("\n\n"); } - &endGradeScreen($r); return OK; @@ -141,9 +223,22 @@ sub getStudentCatGrade { sub getAllStudentData { my $cdom = $env{'course.'.$env{'request.course.id'}.'.domain'}; my $cnum = $env{'course.'.$env{'request.course.id'}.'.num'}; + my %categories=&Apache::lonnet::dump('grading_categories',$cdom,$cnum); -#FIXME: debugging output - return &getStudentCatGrade('korte','gerd',%categories); + + my $classlist = &Apache::loncoursedata::get_classlist(); + + my $statusidx = &Apache::loncoursedata::CL_STATUS(); + my $usernameidx = &Apache::loncoursedata::CL_SNAME(); + my $domainidx = &Apache::loncoursedata::CL_SDOM(); + my $fullnameidx = &Apache::loncoursedata::CL_FULLNAME(); + + foreach my $key (keys(%{$classlist})) { + my $student = $classlist->{$key}; + my $perc=&getStudentCatGrade($classlist->{$student}->[$usernameidx], + $classlist->{$student}->[$domainidx], + %categories); + } } @@ -198,7 +293,7 @@ sub startGradeScreen { if ($env{'form.symb'}) { $r->print("\n".'    '. + '&command=gradingmenu">    '. &mt('Problem Grading').'    '); } @@ -212,6 +307,68 @@ sub endGradeScreen { $r->print(''.&Apache::loncommon::end_page()); } +# ----------- + + +sub excel_cleanup { + undef ($excel_sheet); + undef ($excel_workbook); + undef ($filename); + undef ($format); +} + + +sub excel_initialize { + my ($r) = @_; + + &excel_cleanup(); + + # Create sheet + ($excel_workbook,$filename,$format)= + &Apache::loncommon::create_workbook($r); + return if (! defined($excel_workbook)); + # + # Add a worksheet + my $sheetname = $env{'course.'.$env{'request.course.id'}.'.description'}; + $sheetname = &Apache::loncommon::clean_excel_name($sheetname); + $excel_sheet = $excel_workbook->addworksheet($sheetname); + # + # Put the course description in the header + $excel_sheet->write($header_row,$cols_output++, + $env{'course.'.$env{'request.course.id'}.'.description'}, + $format->{'h1'}); +} + +sub excel_finish { + my ($r) = @_; + if ($request_aborted || ! defined($excel_sheet)) { + &excel_cleanup(); + return; + } + # + # Write the excel file + $excel_workbook->close(); + # + # Close the progress window + &Apache::lonhtmlcommon::Close_PrgWin($r,\%prog_state); + # + # Tell the user where to get their excel file + $r->print('
'. + ''.&mt('Your Excel spreadsheet').''."\n"); + $r->rflush(); + &excel_cleanup(); + return; +} + + +# +# CSV data +# +# ----------- + +# +# Go through the complete course and collect data +# sub getData {