Annotation of loncom/interface/spreadsheet/lonspreadsheet.pm, revision 1.40

1.1       matthew     1: #
1.40    ! albertel    2: # $Id: lonspreadsheet.pm,v 1.39 2004/10/12 20:51:54 albertel Exp $
1.1       matthew     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;
1.23      matthew    57: use warnings FATAL=>'all';
                     58: no warnings 'uninitialized';
1.1       matthew    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;
1.25      www        65: use Apache::lonlocal;
1.26      matthew    66: use Apache::loncoursedata();
1.1       matthew    67: use HTML::Entities();
                     68: 
                     69: ##
                     70: ## HTML utility subroutines really should go in lonhtmlcommon
                     71: ##
                     72: 
                     73: sub textfield {
                     74:     my ($title,$name,$value)=@_;
1.28      matthew    75:     return "\n<p><b>$title:</b><br />".
                     76:         '<input type=text name="'.$name.'" size=80 value="'.$value.'" />';
1.1       matthew    77: }
                     78: 
                     79: sub hiddenfield {
                     80:     my ($name,$value)=@_;
                     81:     return '<input type=hidden name="'.$name.'" value="'.$value.'" />'."\n";
                     82: }
                     83: 
                     84: sub selectbox {
                     85:     my ($title,$name,$value,%options)=@_;
1.28      matthew    86:     my $selout="\n<p><b>$title:</b><br />".'<select name="'.$name.'">';
1.1       matthew    87:     foreach (sort keys(%options)) {
                     88:         $selout.='<option value="'.$_.'"';
                     89:         if ($_ eq $value) { $selout.=' selected'; }
1.27      www        90:         $selout.='>'.&mt($options{$_}).'</option>';
1.1       matthew    91:     }
                     92:     return $selout.'</select>';
                     93: }
                     94: 
1.5       matthew    95: sub file_dialogs {
                     96:     my ($spreadsheet) = @_;
                     97:     my $bgcolor = "#FFFFFF";
                     98:     my $sheettype = $spreadsheet->{'type'};
                     99:     my $result = '';
1.11      matthew   100:     my $message = '';
1.5       matthew   101:     ##
                    102:     ## Deal with saving the spreadsheet
1.40    ! albertel  103:     if ((exists($env{'form.save'}) || exists($env{'form.makedefault'})) && 
        !           104:         exists($env{'form.savefilename'})) {
        !           105:         $spreadsheet->filename($env{'form.savefilename'});
1.5       matthew   106:         my $save_status = $spreadsheet->save();
                    107:         if ($save_status ne 'ok') {
1.11      matthew   108:             $message .= "An error occurred while saving the spreadsheet".
1.5       matthew   109:                 "There error is:".$save_status;
                    110:         } else {
1.24      matthew   111:             $message .= "Spreadsheet saved as ".$spreadsheet->filename();
1.5       matthew   112:         }
1.40    ! albertel  113:     } elsif (exists($env{'form.newformula'}) && 
        !           114:              exists($env{'form.cell'})       && 
        !           115:              $env{'form.cell'} ne '' ) {
1.5       matthew   116:         ##
                    117:         ## Make any requested modifications to the spreadsheet
1.40    ! albertel  118:         $spreadsheet->modify_cell($env{'form.cell'},
        !           119:                                   $env{'form.newformula'});
1.5       matthew   120:         $spreadsheet->save_tmp();
                    121:         # output that we are dealing with a temporary file
                    122:         $result .=&hiddenfield('workcopy',$sheettype);
1.40    ! albertel  123:         if ($env{'form.newformula'} !~ /^\s*$/) {
1.11      matthew   124:             $message .='<table><tr>'.
1.40    ! albertel  125:               '<td valign="top"><pre>'.&mt('Cell').' '.$env{'form.cell'}.' = </pre></td>'.
        !           126:               '<td><pre>'.$env{'form.newformula'}."</pre></td></tr></table>\n";
1.11      matthew   127:         } else {
1.40    ! albertel  128:             $message .= &mt('Deleted contents of cell').' '.$env{'form.cell'}.'.';
1.11      matthew   129:         }
1.5       matthew   130:     }
                    131:     ##
                    132:     ## Editing code
                    133:     $result .=&hiddenfield('cell','').
                    134:               &hiddenfield('newformula','');
                    135:     ##
                    136:     ## Create the save and load dialogs
                    137:     my $filename = $spreadsheet->filename();
1.10      matthew   138:     my $truefilename = $filename;
                    139:     if ($spreadsheet->is_default()) {
                    140:         $filename = 'Default';
                    141:     }
1.5       matthew   142:     my $save_dialog = '<nobr>'.
1.27      www       143:         '<input type="submit" name="save" value="'.&mt('Save as').'" /> '.
1.5       matthew   144:         '<input type="text" name="savefilename" size="30" value="'.
1.10      matthew   145:         $truefilename.'" />'.
1.5       matthew   146:         '</nobr>';
                    147:     my $makedefault_dialog = '<input type="submit" name="makedefault" '.
1.27      www       148:         'value="'.&mt('Save as & Make This Sheet the Default').'"/>';
1.5       matthew   149:     #
                    150:     my $link = '<a href="javascript:openbrowser'.
1.27      www       151:         "('sheet','loadfilename','spreadsheet')\">".&mt('Select Spreadsheet File')."</a>";
                    152:     my $load=&mt('Load:');
1.5       matthew   153:     my $load_dialog = <<END;
                    154: <table bgcolor="$bgcolor">
1.27      www       155: <tr><td><input type="submit" name="load" value="$load" /></td>
1.5       matthew   156:     <td><nobr>
1.10      matthew   157:         <input type="text" name="loadfilename" size="20" value="$filename" />
1.5       matthew   158:         $link</nobr>
                    159:     </td></tr>
                    160: <tr><td>&nbsp;</td><td>
                    161:     <select name="fileselect" onchange="document.sheet.loadfilename.value=document.sheet.fileselect.value" >
                    162: END
1.7       matthew   163:     my $default_filename_set = 0;
1.5       matthew   164:     foreach my $sheetfilename ($spreadsheet->othersheets()) {
1.28      matthew   165:         $load_dialog .= '    <option value="'.$sheetfilename.'"';
1.5       matthew   166:         if ($filename eq $sheetfilename) {
                    167:             $load_dialog .= ' selected';
1.7       matthew   168:             $default_filename_set = 1;
1.5       matthew   169:         }
                    170:         $load_dialog .= '>'.$sheetfilename."</option>\n";
                    171:     }
1.22      matthew   172:     $load_dialog .= "</select>\n</td><td>&nbsp;</td></tr>\n</table>\n";
1.5       matthew   173:         #
                    174:     $result .=<<END;
1.23      matthew   175: <!-- 
                    176:     <fieldset title="File Dialogs" >
                    177:     <legend>File Dialogs</legend>
                    178:   -->
1.5       matthew   179: <!-- load / save dialogs -->
                    180: <table cellspacing="2">
                    181: <tr>
                    182:     <td>$load_dialog</td>
                    183:     <td>
                    184:         <table bgcolor="$bgcolor">
                    185:         <tr><td>$save_dialog</td></tr>
                    186:         <tr><td align="center">$makedefault_dialog</td></tr>
                    187:         </table>
                    188:     </td>
                    189: </tr>
                    190: </table>
1.23      matthew   191: <!--
                    192:     </fieldset>
                    193:   -->
1.5       matthew   194: END
1.11      matthew   195:     return ($result,$message);
1.5       matthew   196: }
                    197: 
1.1       matthew   198: sub handler {
                    199:     my $r=shift;
                    200:     #
                    201:     # Overload checking
                    202:     #
                    203:     # Check this server
                    204:     my $loaderror=&Apache::lonnet::overloaderror($r);
                    205:     if ($loaderror) { return $loaderror; }
                    206:     # Check the course homeserver
                    207:     $loaderror= &Apache::lonnet::overloaderror($r,
1.40    ! albertel  208:                       $env{'course.'.$env{'request.course.id'}.'.home'});
1.4       matthew   209: #    if ($loaderror) { return $loaderror; } 
1.1       matthew   210:     #
                    211:     # HTML Header
                    212:     #
                    213:     if ($r->header_only) {
1.25      www       214:         &Apache::loncommon::content_type($r,'text/html');
1.1       matthew   215:         $r->send_http_header;
                    216:         return OK;
                    217:     }
                    218:     #
                    219:     # Roles Checking
                    220:     #
                    221:     # Needs to be in a course
1.40    ! albertel  222:     if (! $env{'request.course.fn'}) { 
1.1       matthew   223:         # Not in a course, or not allowed to modify parms
1.40    ! albertel  224:         $env{'user.error.msg'}=
1.1       matthew   225:             $r->uri.":opa:0:0:Cannot modify spreadsheet";
                    226:         return HTTP_NOT_ACCEPTABLE; 
1.17      matthew   227:     }
1.40    ! albertel  228:     my $courseid = $env{'request.course.id'};
1.17      matthew   229:     #
1.30      albertel  230:     # Do not allow students to continue if standard or external grading is in
                    231:     # effect.
                    232:     #
1.40    ! albertel  233:     if ($env{'request.role'} =~ /^st\./) {
        !           234:         if ($env{'course.'.$courseid.'.grading'} eq 'standard' ||
        !           235: 	    $env{'course.'.$courseid.'.grading'} eq 'external' ) {
1.17      matthew   236:             return HTTP_NOT_ACCEPTABLE;
                    237:         }
1.1       matthew   238:     }
                    239:     #
                    240:     # Get query string for limited number of parameters
                    241:     #
                    242:     &Apache::loncommon::get_unprocessed_cgi
1.37      matthew   243:         ($ENV{'QUERY_STRING'},['sname','sdomain','usymb','filename','recalc',
                    244:                                'output_format','not_first_run']);
1.1       matthew   245:     #
                    246:     # Deal with restricted student permissions 
                    247:     #
1.40    ! albertel  248:     if ($env{'request.role'} =~ /^st\./) {
        !           249:         delete $env{'form.cell'}       if (exists($env{'form.cell'}));
        !           250:         delete $env{'form.newformula'} if (exists($env{'form.newformula'}));
1.1       matthew   251:     }
                    252:     #
                    253:     # Determine basic information about the spreadsheet
                    254:     my ($sheettype) = ($r->uri=~/\/(\w+)$/);
                    255:     #
                    256:     my $symb   = undef;
1.40    ! albertel  257:     $symb = $env{'form.usymb'} if (exists($env{'form.usymb'}));
        !           258:     my $name   = $env{'user.name'};
        !           259:     my $domain = $env{'user.domain'};
        !           260:     if (exists($env{'form.sname'}) && $env{'form.sname'} ne '') {
        !           261:         $name   = $env{'form.sname'};
        !           262:         $domain = $env{'form.sdomain'};
1.1       matthew   263:     }
1.40    ! albertel  264:     $env{'form.sname'} = $name;
        !           265:     $env{'form.sdomain'} = $domain;
1.3       matthew   266:     ##
                    267:     ## Check permissions
                    268:     my $allowed_to_edit = &Apache::lonnet::allowed('mgr',
1.40    ! albertel  269:                                                 $env{'request.course.id'});
1.12      matthew   270:     # Only those instructors/tas/whatevers with complete access
                    271:     # (not section restricted) are able to modify spreadsheets.
1.3       matthew   272:     my $allowed_to_view =  &Apache::lonnet::allowed('vgr',
1.40    ! albertel  273:                                                 $env{'request.course.id'});
1.12      matthew   274:     if (! $allowed_to_view) {
                    275:         $allowed_to_view = &Apache::lonnet::allowed('vgr',
1.40    ! albertel  276:                     $env{'request.course.id'}.'/'.$env{'request.course.sec'});
1.12      matthew   277:         # Those who are restricted by section are allowed to view.
                    278:         # The routines in lonstatistics which decide which students' 
                    279:         # will be shown take care of the restriction by section.
                    280:     }
1.1       matthew   281:     #
1.3       matthew   282:     # Only those able to view others grades will be allowed to continue 
                    283:     # if they are not requesting their own.
1.12      matthew   284:     if ($sheettype eq 'classcalc') {
1.3       matthew   285:         if (! $allowed_to_view) {
1.40    ! albertel  286: 	    $env{'user.error.msg'}=
1.14      www       287: 		$r->uri.":vgr:0:0:Access Permission Denied";
                    288: 	    return HTTP_NOT_ACCEPTABLE; 
                    289: 	}
1.1       matthew   290:     }
1.40    ! albertel  291:     if ((($name   ne $env{'user.name'} ) ||
        !           292:          ($domain ne $env{'user.domain'})) && $sheettype ne 'classcalc') {
1.12      matthew   293:         # Check that the student is in their section?
1.40    ! albertel  294:         if (exists($env{'request.course.sec'}) && 
        !           295:             $env{'request.course.sec'} ne '' ) {
1.39      albertel  296:             my $stu_sec = &Apache::lonnet::getsection($domain,$name,
1.40    ! albertel  297: 						    $env{'request.course.id'});
        !           298:             if ($stu_sec ne $env{'request.course.sec'}) {
        !           299: 		$env{'user.error.msg'}=
1.14      www       300: 		    $r->uri.":vgr:0:0:Requested student not in your section.";
                    301: 		return HTTP_NOT_ACCEPTABLE; 
1.12      matthew   302:             }
                    303:         }
                    304:     }
1.14      www       305: 
                    306:     #
                    307:     # Open page, try to prevent browser cache.
                    308:     #
1.25      www       309:     &Apache::loncommon::content_type($r,'text/html');
1.15      matthew   310:     &Apache::loncommon::no_cache($r);
1.14      www       311:     $r->send_http_header;
1.12      matthew   312: 
1.1       matthew   313:     #
                    314:     # Header....
                    315:     #
                    316:     $r->print('<html><head><title>LON-CAPA Spreadsheet</title>');
                    317:     my $nothing = &Apache::lonhtmlcommon::javascript_nothing();
                    318:     ##
                    319:     ## Spit out the javascript required for editing
                    320:     ##
1.5       matthew   321:     if ($allowed_to_edit) {
1.27      www       322: 	my %lt=(
                    323: 		'ce' => 'Cell',
                    324: 		'ac' => 'Accept',
                    325: 		'dc' => 'Discard Changes'
                    326: 	);
1.5       matthew   327:         my $extra_javascript = 
                    328:             &Apache::loncommon::browser_and_searcher_javascript();
1.1       matthew   329:         $r->print(<<ENDSCRIPT);
1.28      matthew   330: <script type="text/javascript">
                    331: //<!--
1.5       matthew   332:     $extra_javascript
                    333: 
1.1       matthew   334:     var editwin;
                    335: 
                    336:     function celledit(cellname,cellformula) {
                    337:         var edit_text = '';
                    338:         // cellformula may contain less-than and greater-than symbols, so
                    339:         // we need to escape them?  
                    340:         edit_text +='<html><head><title>Cell Edit Window</title></head><body>';
                    341:         edit_text += '<form name="editwinform">';
1.27      www       342:         edit_text += '<center><h3>$lt{'ce'} '+cellname+'</h3>';
1.18      matthew   343:         edit_text += '<textarea name="newformula" cols="60" rows="12"';
1.1       matthew   344:         edit_text += ' wrap="off" >'+cellformula+'</textarea>';
                    345:         edit_text += '</br>';
1.27      www       346:         edit_text += '<input type="button" name="accept" value="$lt{'ac'}"';
1.1       matthew   347:         edit_text += ' onClick=\\\'javascript:';
                    348:         edit_text += 'opener.document.sheet.cell.value=';
                    349:         edit_text +=     '"'+cellname+'";';
                    350:         edit_text += 'opener.document.sheet.newformula.value=';
                    351:         edit_text +=     'document.editwinform.newformula.value;';
                    352:         edit_text += 'opener.document.sheet.submit();';
                    353:         edit_text += 'self.close()\\\' />';
                    354:         edit_text += '&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;';
                    355:         edit_text += '<input type="button" name="abort" ';
1.27      www       356:         edit_text +=     'value="$lt{'dc'}"';
1.1       matthew   357:         edit_text += ' onClick="javascript:self.close()" />';
                    358:         edit_text += '</center></body></html>';
                    359: 
                    360:         if (editwin != null && !(editwin.closed) ) {
                    361:             editwin.close();
                    362:         }
                    363: 
1.29      albertel  364:         editwin = window.open($nothing,'CellEditWin','height=280,width=480,scrollbars=no,resizable=yes,alwaysRaised=yes,dependent=yes',true);
1.1       matthew   365:         editwin.document.write(edit_text);
                    366:     }
1.28      matthew   367: //-->
1.1       matthew   368: </script>
                    369: ENDSCRIPT
                    370:     }
1.33      matthew   371:     &Apache::lonhtmlcommon::clear_breadcrumbs();
                    372:     &Apache::lonhtmlcommon::add_breadcrumb
                    373:         ({href  => $r->uri,
1.36      matthew   374:           title => 'Spreadsheet',
                    375:           text  => 'Spreadsheet',
1.33      matthew   376:           faq   => 134,
                    377:           bug   => 'Spreadsheet'});
1.1       matthew   378:     $r->print('</head>'.&Apache::loncommon::bodytag('Grades Spreadsheet').
1.36      matthew   379:               &Apache::lonhtmlcommon::breadcrumbs(undef,'Spreadsheet').
1.1       matthew   380:               '<form action="'.$r->uri.'" name="sheet" method="post">');
1.40    ! albertel  381:     $r->print(&hiddenfield('sname'  ,$env{'form.sname'}).
        !           382:               &hiddenfield('sdomain',$env{'form.sdomain'}).
        !           383:               &hiddenfield('usymb'  ,$env{'form.usymb'}));
1.1       matthew   384:     $r->rflush();
                    385:     ##
                    386:     ## Determine the filename to use
                    387:     my $filename = undef;
1.3       matthew   388:     if ($allowed_to_edit) {
1.40    ! albertel  389:         $filename = $env{'form.filename'} if (exists($env{'form.filename'}));
1.1       matthew   390:         #
1.40    ! albertel  391:         if (exists($env{'form.load'}) && exists($env{'form.loadfilename'})) {
        !           392:             $filename = $env{'form.loadfilename'};
        !           393:             $env{'form.workcopy'} = 'no';
1.1       matthew   394:         }
                    395:     }
                    396:     ##
1.19      matthew   397:     ## Take care of "backdoor" spreadsheet expiration / recalc stuff
1.40    ! albertel  398:     if ($allowed_to_edit && exists($env{'form.recalc'})) {
        !           399:         if (exists($env{'form.recalc'})) {
        !           400:             &Apache::loncoursedata::delete_caches($env{'requres.course.id'});
1.26      matthew   401:         }
1.40    ! albertel  402:         if ($env{'form.recalc'} eq 'ilovewastingtime') {
1.37      matthew   403:             &Apache::lonnet::logthis('spreadsheet expired: entire course');
1.19      matthew   404:             # expire ALL spreadsheets
                    405:             &Apache::lonnet::expirespread('','','studentcalc');
                    406:             &Apache::lonnet::expirespread('','','assesscalc');
1.37      matthew   407:             $r->print('<h3>'.
                    408:                       &mt('Expired spreadsheet caches for all students').
                    409:                       '</h3>');
1.40    ! albertel  410:         } elsif ($env{'form.recalc'} =~ /^symb:/) {
1.19      matthew   411:             # expire for all students on this symb
1.40    ! albertel  412:             my ($symb) = ($env{'form.recalc'} =~ /^symb:(.*)$/);
1.37      matthew   413:             &Apache::lonnet::logthis('spreadsheet expired: symb = '.$symb);
1.19      matthew   414:             &Apache::lonnet::expirespread('','','assesscalc',$symb);
                    415:             &Apache::lonnet::expirespread('','','studentcalc');
1.37      matthew   416:             $r->print('<h3>'.
                    417:               &mt('Expired spreadsheet caches for all students for symb  [_1]',
                    418:                   $symb).
                    419:                       '</h3>');
1.40    ! albertel  420:         } elsif ($env{'form.recalc'} =~ /^student:/) {
1.19      matthew   421:             # expire all assessment spreadsheets for this user
1.40    ! albertel  422:             my ($sname,$sdom) = ($env{'form.recalc'}=~/^student:(.*):(.*)$/);
1.37      matthew   423:             &Apache::lonnet::logthis('spreadsheet expired: student = '.
                    424:                                      $sname.'@'.$sdom);
1.19      matthew   425:             if (defined($sname) && defined($sdom)) {
                    426:                 &Apache::lonnet::expirespread($sname,$sdom,'assesscalc');
                    427:                 &Apache::lonnet::expirespread($sname,$sdom,'studentcalc');
1.37      matthew   428:                 $r->print('<h3>'.
                    429:                           &mt('Expired spreadsheet caches for student [_1]',
                    430:                               $sname.'@'.$sdom).
                    431:                           '</h3>');
1.19      matthew   432:             }
                    433:         }
                    434:     }
                    435:     ##
1.1       matthew   436:     ## Make the spreadsheet
                    437:     &Apache::Spreadsheet::initialize_spreadsheet_package();
                    438:     my $spreadsheet = undef;
                    439:     if ($sheettype eq 'classcalc') {
                    440:         $spreadsheet = Apache::classcalc->new($name,$domain,$filename,undef);
                    441:     } elsif ($sheettype eq 'studentcalc') {
                    442:         $spreadsheet = Apache::studentcalc->new($name,$domain,$filename,undef);
1.2       matthew   443:     } elsif ($sheettype eq 'assesscalc' && 
                    444:              defined($symb) && 
1.3       matthew   445:              $allowed_to_edit) {
1.1       matthew   446:         $spreadsheet = Apache::assesscalc->new($name,$domain,$filename,$symb);
                    447:     } else {
1.2       matthew   448:         return HTTP_NOT_ACCEPTABLE;
                    449:     }
                    450:     if (! defined($spreadsheet)) {
                    451:         # error error - run in circles, scream and shout
1.1       matthew   452:         return;
                    453:     }
1.8       matthew   454:     $spreadsheet->initialize();
1.5       matthew   455:     #
                    456:     # Output selector
1.1       matthew   457:     ##
                    458:     ## Editing/loading/saving
1.3       matthew   459:     if ($allowed_to_edit) {
1.11      matthew   460:         my ($html,$action_message) = &file_dialogs($spreadsheet);
1.40    ! albertel  461:         if ($env{'form.makedefault'}) {
1.10      matthew   462:             $spreadsheet->make_default();
1.11      matthew   463:             if ($action_message) {
                    464:                 $action_message .= '<br />';
                    465:             }
1.27      www       466:             $action_message .= &mt('Made this spreadsheet the default');
1.11      matthew   467:             if ($sheettype eq 'classcalc') {
1.27      www       468:                 $action_message .= ' '.&mt('for the course');
1.11      matthew   469:             } elsif ($sheettype eq 'studentcalc') {
1.27      www       470:                 $action_message .= ' '.&mt('for all students');
1.11      matthew   471:             } elsif ($sheettype eq 'assesscalc') {
1.27      www       472:                 $action_message .= ' '.&mt('for all assessments');
1.11      matthew   473:             }
                    474:             $action_message .= '.';
1.10      matthew   475:         }
1.38      matthew   476:         $r->print('<table><tr><td valign="top">'.
                    477:                   $spreadsheet->html_header().
                    478:                   '</td>'.
                    479:                   '<td valign="center">'.$html."</td></tr></table>\n");
1.12      matthew   480:         if ($action_message ne '') {
                    481:             $r->print(<<END);
1.11      matthew   482: <table>
                    483: <tr><td valign="top"><b>Last Action:</b></td>
                    484:     <td>&nbsp;</td>
                    485:     <td>$action_message</td>
                    486: </tr>
                    487: </table>
                    488: END
1.12      matthew   489:         }
1.1       matthew   490:         $r->rflush();
1.5       matthew   491:     } else {
                    492:         $r->print('<table><tr><td>'.$spreadsheet->html_header().
                    493:                   "</td></tr></table>\n");
1.1       matthew   494:     }
1.11      matthew   495:     $r->rflush();
1.1       matthew   496:     #
1.19      matthew   497:     $r->print("<table><tr>");
1.31      matthew   498:     $r->print('<td><input type="submit" value="'.
                    499:               &mt('Generate Spreadsheet').'" />'.
                    500:               '</td>');
1.21      matthew   501:     if ($allowed_to_view) {
                    502:         $r->print('<td>'.
                    503:                   &Apache::loncommon::help_open_topic("Spreadsheet_About",
                    504:                                                       'Spreadsheet Help').
                    505:                   '</td>');
                    506:     }
                    507:     if ($allowed_to_edit) {
                    508:         $r->print('<td>'.
                    509:                   &Apache::loncommon::help_open_topic("Spreadsheet_Editing",
                    510:                                                       'Editing Help').
                    511:                   '</td>');
                    512:     }
1.19      matthew   513:     $r->print('</tr></table>');
1.10      matthew   514:     #
1.1       matthew   515:     # Keep track of the filename
                    516:     $r->print(&hiddenfield('filename',$filename));
                    517:     #
1.5       matthew   518:     # Keep track of the number of times we have been called, sort of.
                    519:     $r->print(&hiddenfield('not_first_run','whatever'));
                    520:     #
1.40    ! albertel  521:     if (exists($env{'form.not_first_run'}) || $sheettype ne 'classcalc') {
1.5       matthew   522:         $r->print($spreadsheet->get_html_title());
                    523:         if ($allowed_to_view || $allowed_to_edit) {
                    524:             $r->print($spreadsheet->parent_link());
                    525:         }
1.16      matthew   526:         $r->rflush();
1.5       matthew   527:         $spreadsheet->display($r);
1.1       matthew   528:     }
                    529:     $r->print('</form></body></html>');
                    530:     return OK;
                    531: }
                    532: 
                    533: 1;
                    534: 
                    535: __END__
                    536: 

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