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