File:  [LON-CAPA] / loncom / interface / spreadsheet / lonspreadsheet.pm
Revision 1.67: download - view: text, annotated - select for diffs
Tue Nov 30 15:55:39 2021 UTC (2 years, 5 months ago) by raeburn
Branches: MAIN
CVS tags: version_2_12_X, HEAD
- Bug 6955 IP-based blocking. Pass user'sIP address as third arg to
  loncommon::blockcheck() and second to loncommon::blocking_status().

    1: #
    2: # $Id: lonspreadsheet.pm,v 1.67 2021/11/30 15:55:39 raeburn Exp $
    3: #
    4: # Copyright Michigan State University Board of Trustees
    5: #
    6: # This file is part of the LearningOnline Network with CAPA (LON-CAPA).
    7: #
    8: # LON-CAPA is free software; you can redistribute it and/or modify
    9: # it under the terms of the GNU General Public License as published by
   10: # the Free Software Foundation; either version 2 of the License, or
   11: # (at your option) any later version.
   12: #
   13: # LON-CAPA is distributed in the hope that it will be useful,
   14: # but WITHOUT ANY WARRANTY; without even the implied warranty of
   15: # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
   16: # GNU General Public License for more details.
   17: #
   18: # You should have received a copy of the GNU General Public License
   19: # along with LON-CAPA; if not, write to the Free Software
   20: # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
   21: #
   22: # /home/httpd/html/adm/gpl.txt
   23: #
   24: # http://www.lon-capa.org/
   25: #
   26: # The LearningOnline Network with CAPA
   27: # Spreadsheet/Grades Display Handler
   28: #
   29: # POD required stuff:
   30: 
   31: =head1 NAME
   32: 
   33: lonspreadsheet
   34: 
   35: =head1 SYNOPSIS
   36: 
   37: Spreadsheet interface to internal LON-CAPA data
   38: 
   39: =head1 DESCRIPTION
   40: 
   41: Lonspreadsheet provides course coordinators the ability to manage their
   42: students grades online.  The students are able to view their own grades, but
   43: not the grades of their peers.  The spreadsheet is highly customizable,
   44: offering the ability to use Perl code to manipulate data, as well as many
   45: built-in functions.
   46: 
   47: =head2 Functions available to user of lonspreadsheet
   48: 
   49: =over 4
   50: 
   51: =cut
   52: 
   53: 
   54: package Apache::lonspreadsheet;
   55:             
   56: use strict;
   57: use warnings FATAL=>'all';
   58: no warnings 'uninitialized';
   59: use Apache::classcalc();
   60: use Apache::studentcalc();
   61: use Apache::assesscalc();
   62: use Apache::Constants qw(:common :http);
   63: use Apache::lonnet;
   64: use Apache::lonhtmlcommon;
   65: use Apache::lonlocal;
   66: use Apache::loncoursedata();
   67: use Apache::lonquickgrades();
   68: use HTML::Entities();
   69: 
   70: ##
   71: ## HTML utility subroutines really should go in lonhtmlcommon
   72: ##
   73: 
   74: sub textfield {
   75:     my ($title,$name,$value)=@_;
   76:     return "\n<p><b>$title:</b><br />".
   77:         '<input type="text" name="'.$name.'" size="80" value="'.$value.'" />';
   78: }
   79: 
   80: sub hiddenfield {
   81:     my ($name,$value)=@_;
   82:     return '<input type="hidden" name="'.$name.'" value="'.$value.'" />'."\n";
   83: }
   84: 
   85: sub selectbox {
   86:     my ($title,$name,$value,%options)=@_;
   87:     my $selout="\n<p><b>$title:</b><br />".'<select name="'.$name.'">';
   88:     foreach (sort keys(%options)) {
   89:         $selout.='<option value="'.$_.'"';
   90:         if ($_ eq $value) { $selout.=' selected="selected"'; }
   91:         $selout.='>'.&mt($options{$_}).'</option>';
   92:     }
   93:     return $selout.'</select>';
   94: }
   95: 
   96: sub file_dialogs {
   97:     my ($spreadsheet) = @_;
   98:     my $bgcolor = "#FFFFFF";
   99:     my $sheettype = $spreadsheet->{'type'};
  100:     my $result = '';
  101:     my $message = '';
  102:     ##
  103:     ## Deal with saving the spreadsheet
  104:     $spreadsheet->check_formulas_loaded();
  105:     if ((exists($env{'form.save'}) || exists($env{'form.makedefault'})) && 
  106:         exists($env{'form.savefilename'})) {
  107:         $spreadsheet->filename($env{'form.savefilename'});
  108:         my $save_status = $spreadsheet->save();
  109:         if ($save_status ne 'ok') {
  110:             $message .= '<span class="LC_error">'.
  111:                 &mt('An error occurred while saving the spreadsheet. The error is: [_1].',
  112:                     $save_status).'</span>';
  113:         } else {
  114:             $message .= '<span class="LC_info">'.&mt('Spreadsheet saved as: [_1] .',
  115:                         '<span class="LC_filename">'.$spreadsheet->filename().'</span>').
  116:                         '</span>';
  117:         }
  118:     } elsif (exists($env{'form.newformula'}) && 
  119:              exists($env{'form.cell'})       && 
  120:              $env{'form.cell'} ne '' ) {
  121:         ##
  122:         ## Make any requested modifications to the spreadsheet
  123:         $spreadsheet->modify_cell($env{'form.cell'},
  124:                                   $env{'form.newformula'});
  125:         $spreadsheet->save_tmp();
  126:         # output that we are dealing with a temporary file
  127:         $result .=&hiddenfield('workcopy',$sheettype);
  128:         if ($env{'form.newformula'} !~ /^\s*$/) {
  129:             $message .='<table><tr>'.
  130:               '<td valign="top"><pre>'.&mt('Cell').' '.$env{'form.cell'}.' = </pre></td>'.
  131:               '<td><pre>'.$env{'form.newformula'}."</pre></td></tr></table>\n";
  132:         } else {
  133:             $message .= &mt('Deleted contents of cell').' '.$env{'form.cell'}.'.';
  134:         }
  135:     }
  136:     ##
  137:     ## Editing code
  138:     $result .=&hiddenfield('cell','').
  139:               &hiddenfield('newformula','');
  140:     ##
  141:     ## Create the save and load dialogs
  142:     my $filename = $spreadsheet->filename();
  143:     my $truefilename = $filename;
  144:     if ($spreadsheet->is_default()) {
  145:         $filename = 'Default';
  146:     }
  147:     my $save_dialog = '<span class="LC_nobreak">'.
  148:         '<input type="submit" name="save" value="'.&mt('Save as').'" /> '.
  149:         '<input type="text" name="savefilename" size="30" value="'.
  150:         $truefilename.'" />'.
  151:         '</span>';
  152:     my $makedefault_dialog = '<input type="submit" name="makedefault" '.
  153:         'value="'.&mt('Save as &amp; Make This Sheet the Default').'"/>';
  154:     #
  155:     my $link = '<a href="javascript:openbrowser'.
  156:         "('sheet','loadfilename','spreadsheet')\">".&mt('Select Spreadsheet File')."</a>";
  157:     my $load=&mt('Load:');
  158:     my $load_dialog = <<END;
  159: <table bgcolor="$bgcolor">
  160: <tr><td><input type="submit" name="load" value="$load" /></td>
  161:     <td><span class="LC_nobreak">
  162:         <input type="text" name="loadfilename" size="20" value="$filename" />
  163:         $link</span>
  164:     </td></tr>
  165: <tr><td>&nbsp;</td><td>
  166:     <select name="fileselect" onchange="document.sheet.loadfilename.value=document.sheet.fileselect.value" >
  167: END
  168:     my $default_filename_set = 0;
  169:     foreach my $sheetfilename ($spreadsheet->othersheets()) {
  170:         $load_dialog .= '    <option value="'.$sheetfilename.'"';
  171:         if ($filename eq $sheetfilename) {
  172:             $load_dialog .= ' selected="selected"';
  173:             $default_filename_set = 1;
  174:         }
  175:         $load_dialog .= '>'.$sheetfilename."</option>\n";
  176:     }
  177:     $load_dialog .= "</select>\n</td><td>&nbsp;</td></tr>\n</table>\n";
  178:         #
  179:     my $headline = &mt('File Dialogs');
  180:     $result .=<<END;
  181: <!-- 
  182:     <fieldset title="File Dialogs" >
  183:     <legend>$headline</legend>
  184:   -->
  185: <!-- load / save dialogs -->
  186: <table cellspacing="2">
  187: <tr>
  188:     <td>$load_dialog</td>
  189:     <td>
  190:         <table bgcolor="$bgcolor">
  191:         <tr><td>$save_dialog</td></tr>
  192:         <tr><td align="center">$makedefault_dialog</td></tr>
  193:         </table>
  194:     </td>
  195: </tr>
  196: </table>
  197: <!--
  198:     </fieldset>
  199:   -->
  200: END
  201:     return ($result,$message);
  202: }
  203: 
  204: sub handler {
  205:     my $r=shift;
  206:     #
  207:     # HTML Header
  208:     #
  209:     if ($r->header_only) {
  210:         &Apache::loncommon::content_type($r,'text/html');
  211:         $r->send_http_header;
  212:         return OK;
  213:     }
  214:     #
  215:     # Roles Checking
  216:     #
  217:     # Needs to be in a course
  218:     if (! $env{'request.course.fn'}) { 
  219:         # Not in a course, or not allowed to modify parms
  220:         $env{'user.error.msg'}=
  221:             $r->uri.":opa:0:0:Cannot modify spreadsheet";
  222:         return HTTP_NOT_ACCEPTABLE; 
  223:     }
  224:     my ($sheettype) = ($r->uri=~/\/(\w+)$/);
  225:     my $courseid = $env{'request.course.id'};
  226: 
  227:     ##
  228:     ## Check permissions
  229:     my $allowed_to_edit = &Apache::lonnet::allowed('mgr',
  230:                                                 $env{'request.course.id'});
  231:     # Only those instructors/tas/whatevers with complete access
  232:     # (not section restricted) are able to modify spreadsheets.
  233:     my $allowed_to_view =  &Apache::lonnet::allowed('vgr',
  234:                                                 $env{'request.course.id'});
  235:     if (! $allowed_to_view) {
  236:         $allowed_to_view = &Apache::lonnet::allowed('vgr',
  237:                     $env{'request.course.id'}.'/'.$env{'request.course.sec'});
  238:         # Those who are restricted by section are allowed to view.
  239:         # The routines in lonstatistics which decide which students'
  240:         # will be shown take care of the restriction by section.
  241:     }
  242: 
  243:     #
  244:     # Check if display of course gradebook is blocked
  245:     #
  246: 
  247:     if ($env{'request.course.id'}) {
  248:         my $cdom = $env{'course.'.$env{'request.course.id'}.'.domain'};
  249:         my $cnum = $env{'course.'.$env{'request.course.id'}.'.num'};
  250:         my $clientip = &Apache::lonnet::get_requestor_ip($r);
  251:         my ($blocked,$blocktext) =
  252:             &Apache::loncommon::blocking_status('grades',$clientip,$cnum,$cdom);
  253:         if ($blocked) {
  254:             my $checkrole = "cm./$cdom/$cnum";
  255:             if ($env{'request.course.sec'} ne '') {
  256:                 $checkrole .= "/$env{'request.course.sec'}";
  257:             }
  258:             unless ((&Apache::lonnet::allowed('evb',undef,undef,$checkrole)) &&
  259:                     ($env{'request.role'} !~ m{^st\./$cdom/$cnum})) {
  260:                 &Apache::lonquickgrades::grades_blocked($r,$blocktext,'spreadsheet');
  261:                 return OK;
  262:             }
  263:         }
  264:     }
  265: 
  266:     #
  267:     # Do not allow users without vgr or mgr priv to continue unless 
  268:     # grading type is set to spreadsheet. 
  269:     #
  270: 
  271:     if ((!$allowed_to_view) && (!$allowed_to_edit)) {
  272:         if ($env{'course.'.$courseid.'.grading'} eq 'spreadsheet') {
  273:             if ($sheettype ne 'studentcalc') {
  274:                 $r->internal_redirect('/adm/studentcalc');
  275:                 return OK;
  276:             }
  277:         } else {
  278:             $r->internal_redirect('/adm/quickgrades');
  279:             return OK;
  280:         }
  281:     }
  282:     #
  283:     # Get query string for limited number of parameters
  284:     #
  285:     &Apache::loncommon::get_unprocessed_cgi
  286:         ($ENV{'QUERY_STRING'},['sname','sdomain','usymb','filename','recalc',
  287:                                'output_format','not_first_run']);
  288:     #
  289:     # Deal with restricted student permissions 
  290:     #
  291:     if ($env{'request.role'} =~ /^st\./) {
  292:         delete $env{'form.cell'}       if (exists($env{'form.cell'}));
  293:         delete $env{'form.newformula'} if (exists($env{'form.newformula'}));
  294:     }
  295:     #
  296:     # Determine basic information about the spreadsheet
  297:     #
  298:     my $symb   = undef;
  299:     $symb = $env{'form.usymb'} if (exists($env{'form.usymb'}));
  300:     my $name   = $env{'user.name'};
  301:     my $domain = $env{'user.domain'};
  302:     my $warning;
  303:     if (exists($env{'form.sname'}) && $env{'form.sname'} ne '') {
  304:         if (($env{'form.sname'} ne $env{'user.name'}) ||
  305:             ($env{'form.sdomain'} ne $env{'user.domain'})) {
  306:             if (($allowed_to_view) || ($allowed_to_edit)) {
  307:                 if (&Apache::lonnet::homeserver($env{'form.sname'},$env{'form.sdomain'}) ne 'no_host') {
  308:                     $name   = $env{'form.sname'};
  309:                     $domain = $env{'form.sdomain'};
  310:                 } else {
  311:                     $warning = &mt('Requested user: "[_1]" does not exist; your own sheet is displayed instead.',$env{'form.sname'}.':'.$env{'form.sdomain'});
  312:                 }
  313:             } else {
  314:                 $warning = &mt('Your current role is not permitted to display this sheet for the requested user: "[_1]"; your own sheet is displayed instead.',$env{'form.sname'}.':'.$env{'form.sdomain'});
  315:             }
  316:         }
  317:     }
  318:     $env{'form.sname'} = $name;
  319:     $env{'form.sdomain'} = $domain;
  320:     my $section = &Apache::lonnet::getsection($domain,$name,
  321: 					      $env{'request.course.id'});
  322:     my @groups;
  323:     if (($env{'user.name'} eq $name) && ($env{'user.domain'} eq $domain)) {
  324:         @groups = &Apache::lonnet::sort_course_groups($env{'request.course.id'},
  325:                                     split(':',$env{'request.course.groups'}));
  326:     } else {
  327:         @groups = &Apache::lonnet::get_users_groups($domain,$name,
  328:                                                     $env{'request.course.id'});
  329:     }
  330: 
  331:     #
  332:     # Only those able to view others grades will be allowed to continue 
  333:     # if they are not requesting their own.
  334:     if ($sheettype eq 'classcalc') {
  335:         if (!$allowed_to_view) {
  336:             $r->internal_redirect('/adm/studentcalc');
  337:             return OK;
  338: 	}
  339:     }
  340:     if ((($name   ne $env{'user.name'} ) ||
  341:          ($domain ne $env{'user.domain'})) && $sheettype ne 'classcalc') {
  342:         # Check that the student is in their section?
  343:         if (exists($env{'request.course.sec'}) && 
  344:             $env{'request.course.sec'} ne '' ) {
  345:             my $stu_sec = &Apache::lonnet::getsection($domain,$name,
  346: 						    $env{'request.course.id'});
  347:             if ($stu_sec ne $env{'request.course.sec'}) {
  348: 		$env{'user.error.msg'}=
  349: 		    $r->uri.":vgr:0:0:Requested student not in your section.";
  350: 		return HTTP_NOT_ACCEPTABLE; 
  351:             }
  352:         }
  353:     }
  354: 
  355:     #
  356:     # Open page, try to prevent browser cache.
  357:     #
  358:     &Apache::loncommon::content_type($r,'text/html');
  359:     &Apache::loncommon::no_cache($r);
  360:     $r->send_http_header;
  361: 
  362:     #
  363:     # Header....
  364:     #
  365:     my $nothing = &Apache::lonhtmlcommon::javascript_nothing();
  366:     ##
  367:     ## Spit out the javascript required for editing
  368:     ##
  369:     my $js;
  370:     if ($allowed_to_edit) {
  371: 	my %lt=&Apache::lonlocal::texthash(
  372: 		'ce' => 'Cell',
  373: 		'ac' => 'Save',
  374: 		'dc' => 'Cancel'
  375: 	);
  376:         my $extra_javascript = 
  377:             &Apache::loncommon::browser_and_searcher_javascript();
  378: 	
  379: 	my $cell_extra_js   = &Apache::loncommon::resize_textarea_js();
  380: 	my $cell_edit_start = 
  381: 	    &Apache::loncommon::start_page('Cell Edit Window',$cell_extra_js,
  382: 					   {'only_body' => 1,
  383: 					    'js_ready'  => 1,
  384: 					    'add_entries'  => {
  385: 						'onresize' => "resize_textarea('LC_newformula','LC_aftertextarea')",
  386: 						'onload'   => "resize_textarea('LC_newformula','LC_aftertextarea')",
  387: 					    }});
  388: 	my $cell_edit_end = 
  389: 	    &Apache::loncommon::end_page({'js_ready'  => 1,});
  390: 
  391:         $js = <<ENDSCRIPT;
  392: <script type="text/javascript">
  393: //<!--
  394:     $extra_javascript
  395: 
  396:     var editwin;
  397: 
  398:     function celledit(cellname,cellformula) {
  399:         var edit_text = '';
  400:         // cellformula may contain less-than and greater-than symbols, so
  401:         // we need to escape them?  
  402:         edit_text +='$cell_edit_start';
  403:         edit_text += '<form name="editwinform" action="">';
  404:         edit_text += '<center><h3>$lt{'ce'} '+cellname+'</h3>';
  405:         edit_text += '<textarea id="LC_newformula" name="newformula" ';
  406:         edit_text += ' cols="60" rows="12"; wrap="off" style="width:100%">';
  407: 	edit_text += cellformula+'</textarea>';
  408:         edit_text += '<div id="LC_aftertextarea"><br />';
  409:         edit_text += '<input type="button" name="accept" value="$lt{'ac'}"';
  410:         edit_text += ' onclick=\\\'javascript:';
  411:         edit_text += 'opener.document.sheet.cell.value=';
  412:         edit_text +=     '"'+cellname+'";';
  413:         edit_text += 'opener.document.sheet.newformula.value=';
  414:         edit_text +=     'document.editwinform.newformula.value;';
  415:         edit_text += 'opener.document.sheet.submit();';
  416:         edit_text += 'self.close()\\\' />';
  417:         edit_text += '&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;';
  418:         edit_text += '<input type="button" name="abort" ';
  419:         edit_text +=     'value="$lt{'dc'}"';
  420:         edit_text += ' onclick="javascript:self.close()" />';
  421:         edit_text += '</center></div></form>$cell_edit_end';
  422: 
  423:         if (editwin != null && !(editwin.closed) ) {
  424:             editwin.close();
  425:         }
  426: 
  427:         editwin = window.open($nothing,'CellEditWin','height=280,width=480,scrollbars=no,resizable=yes,alwaysRaised=yes,dependent=yes',true);
  428:         editwin.document.write(edit_text);
  429:         editwin.document.close();
  430:     }
  431: //-->
  432: </script>
  433: ENDSCRIPT
  434:     }
  435:     &Apache::lonhtmlcommon::clear_breadcrumbs();
  436:     &Apache::lonhtmlcommon::add_breadcrumb
  437:         ({href  => $r->uri,
  438:           title => 'Spreadsheet',
  439:           text  => 'Spreadsheet',
  440:           faq   => 134,
  441:           bug   => 'Spreadsheet'});
  442:     $r->print(&Apache::loncommon::start_page('Grades Spreadsheet',$js).
  443:               &Apache::lonhtmlcommon::breadcrumbs('Spreadsheet',
  444: 						  'Spreadsheet_About'));
  445: 
  446:     #
  447:     # Tabs
  448:     # 
  449:     &Apache::lonquickgrades::startGradeScreen($r,'spreadsheet');
  450: 
  451:     #
  452:     # Open the form
  453:     # 
  454:     if ($warning) {
  455:         $r->print('<p class="LC_info">'.$warning.'</p>');
  456:     }
  457:     $r->print('<form action="'.$r->uri.'" name="sheet" method="post">');
  458:     $r->print(&hiddenfield('sname'  ,$env{'form.sname'}).
  459:               &hiddenfield('sdomain',$env{'form.sdomain'}).
  460:               &hiddenfield('usymb'  ,$env{'form.usymb'}));
  461:     $r->rflush();
  462:     ##
  463:     ## Determine the filename to use
  464:     my $filename = undef;
  465:     if ($allowed_to_edit) {
  466:         $filename = $env{'form.filename'} if (exists($env{'form.filename'}));
  467:         #
  468:         if (exists($env{'form.load'}) && exists($env{'form.loadfilename'})) {
  469:             $filename = $env{'form.loadfilename'};
  470:             $env{'form.workcopy'} = 'no';
  471:         }
  472:     }
  473:     ##
  474:     ## Take care of "backdoor" spreadsheet expiration / recalc stuff
  475:     if ($allowed_to_edit && exists($env{'form.recalc'})) {
  476:         if (exists($env{'form.recalc'})) {
  477:             &Apache::loncoursedata::delete_caches($env{'requres.course.id'});
  478:         }
  479:         if ($env{'form.recalc'} eq 'expireallsheets') {
  480:             &Apache::lonnet::logthis('spreadsheet expired: entire course');
  481:             # expire ALL spreadsheets
  482:             &Apache::lonnet::expirespread('','','studentcalc');
  483:             &Apache::lonnet::expirespread('','','assesscalc');
  484:             $r->print('<h3>'.
  485:                       &mt('Expired spreadsheet caches for all students').
  486:                       '</h3>');
  487:         } elsif ($env{'form.recalc'} =~ /^symb:/) {
  488:             # expire for all students on this symb
  489:             my ($symb) = ($env{'form.recalc'} =~ /^symb:(.*)$/);
  490:             &Apache::lonnet::logthis('spreadsheet expired: symb = '.$symb);
  491:             &Apache::lonnet::expirespread('','','assesscalc',$symb);
  492:             &Apache::lonnet::expirespread('','','studentcalc');
  493:             $r->print('<h3>'.
  494:               &mt('Expired spreadsheet caches for all students for symb  [_1]',
  495:                   $symb).
  496:                       '</h3>');
  497:         } elsif ($env{'form.recalc'} =~ /^student:/) {
  498:             # expire all assessment spreadsheets for this user
  499:             my ($sname,$sdom) = ($env{'form.recalc'}=~/^student:(.*):(.*)$/);
  500:             &Apache::lonnet::logthis('spreadsheet expired: student = '.
  501:                                      $sname.'@'.$sdom);
  502:             if (defined($sname) && defined($sdom)) {
  503:                 &Apache::lonnet::expirespread($sname,$sdom,'assesscalc');
  504:                 &Apache::lonnet::expirespread($sname,$sdom,'studentcalc');
  505:                 $r->print('<h3>'.
  506:                           &mt('Expired spreadsheet caches for student [_1]',
  507:                               $sname.'@'.$sdom).
  508:                           '</h3>');
  509:             }
  510:         }
  511:     }
  512:     ##
  513:     ## Make the spreadsheet
  514:     &Apache::Spreadsheet::initialize_spreadsheet_package();
  515:     my $spreadsheet = undef;
  516:     if ($sheettype eq 'classcalc') {
  517:         $spreadsheet = Apache::classcalc->new($name,$domain,$filename,undef,
  518: 					      $section,\@groups);
  519:     } elsif ($sheettype eq 'studentcalc') {
  520:         $spreadsheet = Apache::studentcalc->new($name,$domain,$filename,undef,
  521: 						$section,\@groups);
  522:     } elsif ($sheettype eq 'assesscalc' && 
  523:              defined($symb) && 
  524:              $allowed_to_edit) {
  525:         $spreadsheet = Apache::assesscalc->new($name,$domain,$filename,$symb,
  526: 					       $section,\@groups);
  527:     } else {
  528:         return HTTP_NOT_ACCEPTABLE;
  529:     }
  530:     if (! defined($spreadsheet)) {
  531:         # error error - run in circles, scream and shout
  532:         return;
  533:     }
  534:     $spreadsheet->initialize();
  535:     #
  536:     # Output selector
  537:     ##
  538:     ## Editing/loading/saving
  539:     if ($allowed_to_edit) {
  540:         my ($html,$action_message) = &file_dialogs($spreadsheet);
  541:         if ($env{'form.makedefault'}) {
  542:             $spreadsheet->make_default();
  543:             if ($action_message) {
  544:                 $action_message .= '<br />';
  545:             }
  546:             $action_message .= &mt('Made this spreadsheet the default');
  547:             if ($sheettype eq 'classcalc') {
  548:                 $action_message .= ' '.&mt('for the course');
  549:             } elsif ($sheettype eq 'studentcalc') {
  550:                 $action_message .= ' '.&mt('for all students');
  551:             } elsif ($sheettype eq 'assesscalc') {
  552:                 $action_message .= ' '.&mt('for all assessments');
  553:             }
  554:             $action_message .= '.';
  555:         }
  556:         $r->print('<table><tr><td valign="top">'.
  557:                   $spreadsheet->html_header().
  558:                   '</td>'.
  559:                   '<td valign="center">'.$html."</td></tr></table>\n");
  560:         if ($action_message ne '') {
  561:             $r->print(
  562:                 &Apache::loncommon::confirmwrapper(
  563:                     &mt('Last Action:')
  564:                    .$action_message)
  565:             );
  566:         }
  567:         $r->rflush();
  568:     } else {
  569:         $r->print('<table><tr><td>'.$spreadsheet->html_header().
  570:                   "</td></tr></table>\n");
  571:     }
  572:     $r->rflush();
  573:     #
  574:     $r->print("<table><tr>");
  575:     $r->print('<td><input type="submit" value="'.
  576:               &mt('Generate Spreadsheet').'" />'.
  577:               '</td>');
  578:     if ($allowed_to_view) {
  579:         $r->print('<td>'.
  580:                   &Apache::loncommon::help_open_topic("Spreadsheet_About",
  581:                                                       &mt('Spreadsheet Help')).
  582:                   '</td>');
  583:     }
  584:     if ($allowed_to_edit) {
  585:         $r->print('<td>'.
  586:                   &Apache::loncommon::help_open_topic("Spreadsheet_Editing",
  587:                                                       &mt('Editing Help')).
  588:                   '</td>');
  589:     }
  590:     $r->print('</tr></table>');
  591:     #
  592:     # Keep track of the filename
  593:     $r->print(&hiddenfield('filename',$filename));
  594:     #
  595:     # Keep track of the number of times we have been called, sort of.
  596:     $r->print(&hiddenfield('not_first_run','1'));
  597:     #
  598:     if (exists($env{'form.not_first_run'}) || $sheettype ne 'classcalc') {
  599:         $r->print($spreadsheet->get_html_title());
  600:         if ($allowed_to_view || $allowed_to_edit) {
  601:             $r->print($spreadsheet->parent_link());
  602:         }
  603:         $r->rflush();
  604:         $spreadsheet->display($r);
  605:     }
  606:     $r->print('</form>');
  607:     &Apache::lonquickgrades::endGradeScreen($r);
  608:     $r->print(&Apache::loncommon::end_page());
  609:     $spreadsheet->clear_package();
  610:     return OK;
  611: }
  612: 
  613: 1;
  614: 
  615: __END__
  616: 

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