--- loncom/interface/spreadsheet/lonspreadsheet.pm 2003/05/19 15:53:07 1.3
+++ loncom/interface/spreadsheet/lonspreadsheet.pm 2003/05/29 13:39:38 1.8
@@ -1,5 +1,5 @@
#
-# $Id: lonspreadsheet.pm,v 1.3 2003/05/19 15:53:07 matthew Exp $
+# $Id: lonspreadsheet.pm,v 1.8 2003/05/29 13:39:38 matthew Exp $
#
# Copyright Michigan State University Board of Trustees
#
@@ -88,6 +88,101 @@ sub selectbox {
return $selout.'';
}
+sub file_dialogs {
+ my ($spreadsheet) = @_;
+ my $bgcolor = "#FFFFFF";
+ my $sheettype = $spreadsheet->{'type'};
+ my $result = '';
+ ##
+ ## Deal with saving the spreadsheet
+ if (exists($ENV{'form.save'}) &&
+ exists($ENV{'form.savefilename'})) {
+ $spreadsheet->filename($ENV{'form.savefilename'});
+ my $save_status = $spreadsheet->save();
+ if ($save_status ne 'ok') {
+ $result .= "An error occurred while saving the spreadsheet".
+ "There error is:".$save_status;
+ return $result;
+ } else {
+ $result .= "Spreadsheet saved as ".$ENV{'form.savefilename'};
+ }
+ } elsif (exists($ENV{'form.newformula'}) &&
+ exists($ENV{'form.cell'}) &&
+ $ENV{'form.cell'} ne '' ) {
+ ##
+ ## Make any requested modifications to the spreadsheet
+ $spreadsheet->modify_cell($ENV{'form.cell'},
+ $ENV{'form.newformula'});
+ $spreadsheet->save_tmp();
+ # output that we are dealing with a temporary file
+ $result .=&hiddenfield('workcopy',$sheettype);
+ $result .='
'.$ENV{'form.cell'}.' = '.
+ $ENV{'form.newformula'}."
\n";
+ }
+ ##
+ ## Editing code
+ $result .=&hiddenfield('cell','').
+ &hiddenfield('newformula','');
+ ##
+ ## Create the save and load dialogs
+ my $filename = $spreadsheet->filename();
+ $filename = 'Default' if ($filename =~ /^default\.$sheettype/i);
+ $filename =~ s/_$sheettype$//;
+ my $save_dialog = ''.
+ ' '.
+ ''.
+ '';
+ my $makedefault_dialog = '';
+ #
+ my $link = 'Browse";
+ my $load_dialog = <
+ |
+
+
+ $link
+ |
+ |
+ | |
\n\n";
+ #
+ $result .=<
+
+
+ $load_dialog |
+
+
+ $save_dialog |
+ $makedefault_dialog |
+
+ |
+
+
+END
+ return $result;
+}
+
sub handler {
my $r=shift;
#
@@ -99,7 +194,7 @@ sub handler {
# Check the course homeserver
$loaderror= &Apache::lonnet::overloaderror($r,
$ENV{'course.'.$ENV{'request.course.id'}.'.home'});
- if ($loaderror) { return $loaderror; }
+# if ($loaderror) { return $loaderror; }
#
# HTML Header
#
@@ -155,6 +250,7 @@ sub handler {
$ENV{'request.course.id'});
my $allowed_to_view = &Apache::lonnet::allowed('vgr',
$ENV{'request.course.id'});
+
#
# Only those able to view others grades will be allowed to continue
# if they are not requesting their own.
@@ -175,10 +271,14 @@ sub handler {
##
## Spit out the javascript required for editing
##
- if (&Apache::lonnet::allowed('mgr',$ENV{'request.course.id'})) {
+ if ($allowed_to_edit) {
+ my $extra_javascript =
+ &Apache::loncommon::browser_and_searcher_javascript();
$r->print(<
+ $extra_javascript
+
var editwin;
function celledit(cellname,cellformula) {
@@ -229,6 +329,7 @@ ENDSCRIPT
#
if (exists($ENV{'form.load'}) && exists($ENV{'form.loadfilename'})) {
$filename = $ENV{'form.loadfilename'};
+ $ENV{'form.workcopy'} = 'no';
}
}
##
@@ -250,84 +351,37 @@ ENDSCRIPT
# error error - run in circles, scream and shout
return;
}
+ $spreadsheet->initialize();
+ #
+ # Output selector
+ $r->print('
');
##
## Editing/loading/saving
if ($allowed_to_edit) {
- ##
- ## Deal with saving the spreadsheet
- if (exists($ENV{'form.save'}) &&
- exists($ENV{'form.savefilename'})) {
- $spreadsheet->filename($ENV{'form.savefilename'});
- my $save_status = $spreadsheet->save();
- if ($save_status ne 'ok') {
- $r->print("An error occurred while saving the spreadsheet".
- "There error is:".$save_status);
- } else {
- $r->print("Spreadsheet saved as ".$ENV{'form.savefilename'});
- }
- } elsif (exists($ENV{'form.newformula'}) &&
- exists($ENV{'form.cell'}) &&
- $ENV{'form.cell'} ne '' ) {
- ##
- ## Make any requested modifications to the spreadsheet
- $spreadsheet->modify_cell($ENV{'form.cell'},
- $ENV{'form.newformula'});
- $spreadsheet->save_tmp();
- # output that we are dealing with a temporary file
- $r->print(&hiddenfield('workcopy',$sheettype));
- $r->print(''.$ENV{'form.cell'}.' = '.
- $ENV{'form.newformula'}.'
'."\n");
- }
- ##
- ## Editing code
- $r->print(&hiddenfield('cell','').
- &hiddenfield('newformula',''));
- ##
- ## Create the save and load dialogs
- $filename = $spreadsheet->filename();
- $filename = '' if ($filename =~ /^default\.$sheettype/i);
- $filename =~ s/_$sheettype$//;
- my $save_dialog =
- ' '.
- '';
- my $makedefault_dialog =
- '';
- #
- my $load_dialog =
- ''.
- '