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

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

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