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

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

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