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

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

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