# # $Id: lonspreadsheet.pm,v 1.2 2003/05/19 14:06:18 matthew 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/ # # The LearningOnline Network with CAPA # Spreadsheet/Grades Display Handler # # POD required stuff: =head1 NAME lonspreadsheet =head1 SYNOPSIS Spreadsheet interface to internal LON-CAPA data =head1 DESCRIPTION Lonspreadsheet provides course coordinators the ability to manage their students grades online. The students are able to view their own grades, but not the grades of their peers. The spreadsheet is highly customizable, offering the ability to use Perl code to manipulate data, as well as many built-in functions. =head2 Functions available to user of lonspreadsheet =over 4 =cut package Apache::lonspreadsheet; use strict; use Apache::classcalc(); use Apache::studentcalc(); use Apache::assesscalc(); use Apache::Constants qw(:common :http); use Apache::lonnet; use Apache::lonhtmlcommon; use HTML::Entities(); ## ## HTML utility subroutines really should go in lonhtmlcommon ## sub textfield { my ($title,$name,$value)=@_; return "\n

$title:
". ''; } sub hiddenfield { my ($name,$value)=@_; return ''."\n"; } sub selectbox { my ($title,$name,$value,%options)=@_; my $selout="\n

$title:
".''; } sub handler { my $r=shift; # # Overload checking # # Check this server my $loaderror=&Apache::lonnet::overloaderror($r); if ($loaderror) { return $loaderror; } # Check the course homeserver $loaderror= &Apache::lonnet::overloaderror($r, $ENV{'course.'.$ENV{'request.course.id'}.'.home'}); if ($loaderror) { return $loaderror; } # # HTML Header # if ($r->header_only) { $r->content_type('text/html'); $r->send_http_header; return OK; } # # Roles Checking # # Needs to be in a course if (! $ENV{'request.course.fn'}) { # Not in a course, or not allowed to modify parms $ENV{'user.error.msg'}= $r->uri.":opa:0:0:Cannot modify spreadsheet"; return HTTP_NOT_ACCEPTABLE; } # # Get query string for limited number of parameters # &Apache::loncommon::get_unprocessed_cgi ($ENV{'QUERY_STRING'},['sname','sdomain','usymb','filename']); # # Deal with restricted student permissions # if ($ENV{'request.role'} =~ /^st\./) { delete $ENV{'form.cell'} if (exists($ENV{'form.cell'})); delete $ENV{'form.newformula'} if (exists($ENV{'form.newformula'})); } # # Determine basic information about the spreadsheet my ($sheettype) = ($r->uri=~/\/(\w+)$/); # my $symb = undef; $symb = $ENV{'form.usymb'} if (exists($ENV{'form.usymb'})); my $name = $ENV{'user.name'}; my $domain = $ENV{'user.domain'}; if (exists($ENV{'form.sname'})) { $name = $ENV{'form.sname'}; $domain = $ENV{'form.sdomain'}; } # # Open page, try to prevent browser cache. # $r->content_type('text/html'); $r->header_out('Cache-control','no-cache'); $r->header_out('Pragma','no-cache'); $r->send_http_header; # # Check user permissions - only those able to view others grades # will be allowed to continue if they are not requesting their own. if (($sheettype eq 'classcalc') || ($name ne $ENV{'user.name'} ) || ($domain ne $ENV{'user.domain'})) { if (! &Apache::lonnet::allowed('vgr',$ENV{'request.course.id'})) { $r->print('

Access Permission Denied

'. ''); return OK; } } # # Header.... # $r->print('LON-CAPA Spreadsheet'); my $nothing = &Apache::lonhtmlcommon::javascript_nothing(); ## ## Spit out the javascript required for editing ## if (&Apache::lonnet::allowed('mgr',$ENV{'request.course.id'})) { $r->print(< var editwin; function celledit(cellname,cellformula) { var edit_text = ''; // cellformula may contain less-than and greater-than symbols, so // we need to escape them? edit_text +='Cell Edit Window'; edit_text += '
'; edit_text += '

Cell '+cellname+'

'; edit_text += '