@@ -1262,110 +1806,159 @@ ENDSCRIPT
&hiddenfield('usymb',$ENV{'form.usymb'}).
&hiddenfield('unewfield','').
&hiddenfield('unewformula',''));
- }
+
+# ---------------------- Make sure that this gets out, even if user hits "stop"
+
$r->rflush();
+
# ---------------------------------------- Read new sheet or modified worksheet
- my $sheetone=initsheet();
$r->uri=~/\/(\w+)$/;
- &settype($sheetone,$1);
+
+ my $asheet=&makenewsheet($aname,$adom,$1,$ENV{'form.usymb'});
+
+# ------------------------ If a new formula had been entered, go from work copy
+
if ($ENV{'form.unewfield'}) {
$r->print('Modified Workcopy ');
$ENV{'form.unewformula'}=~s/\'/\"/g;
$r->print('New formula: '.$ENV{'form.unewfield'}.'='.
$ENV{'form.unewformula'}.'
');
- &setfilename($sheetone,$ENV{'form.ufn'});
- &tmpread($sheetone,$r->dir_config('lonDaemons').'/tmp/',
- $ENV{'form.usymb'},
+ &setfilename($asheet,$ENV{'form.ufn'});
+ &tmpread($asheet,
$ENV{'form.unewfield'},$ENV{'form.unewformula'});
- } elsif ($ENV{'form.saveas'}) {
- &setfilename($sheetone,$ENV{'form.ufn'});
- &tmpread($sheetone,$r->dir_config('lonDaemons').'/tmp/',
- $ENV{'form.usymb'});
+
+ } elsif ($ENV{'form.saveas'}) {
+ &setfilename($asheet,$ENV{'form.ufn'});
+ &tmpread($asheet);
} else {
- &readsheet($sheetone,$ENV{'form.ufn'},$r);
- $ENV{'form.ufn'}=&getfilename($sheetone);
+ &readsheet($asheet,$ENV{'form.ufn'});
}
- if (&gettype($sheetone) eq 'classcalc') {
-# ---------------------------------- For course view: get courselist and update
- &updatestudentrows($sheetone);
- } else {
-# ----------------- For assessment and student: See if all import rows uptodate
+# -------------------------------------------------- Print out user information
+
+ unless (&gettype($asheet) eq 'classcalc') {
+ $r->print('
User: '.&getuname($asheet).
+ 'Domain: '.&getudom($asheet));
+ if (&getcsec($asheet) eq '-1') {
+ $r->print('
'.
+ 'Not a student in this course ');
+ } else {
+ $r->print('Section/Group: '.&getcsec($asheet));
+ }
+ }
+
+# ---------------------------------------------------------------- Course title
+
+ $r->print(''.
+ $ENV{'course.'.$ENV{'request.course.id'}.'.description'}.' ');
+
+# ---------------------------------------------------- See if user can see this
+
+ if ((&gettype($asheet) eq 'classcalc') ||
+ (&getuname($asheet) ne $ENV{'user.name'}) ||
+ (&getudom($asheet) ne $ENV{'user.domain'})) {
+ unless (&Apache::lonnet::allowed('vgr',&getcid($asheet))) {
+ $r->print(
+ 'Access Permission Denied ');
+ return OK;
+ }
+ }
- if (tie(%parmhash,'GDBM_File',
- $ENV{'request.course.fn'}.'_parms.db',&GDBM_READER,0640)) {
- $csec=&Apache::lonnet::usection($udom,$uname,$ENV{'request.course.id'});
- if ($csec eq '-1') {
- $r->print(''.
- "User '$uname' at domain '$udom' not a student in this course ");
- }
- &updaterows($sheetone);
- untie(%parmhash);
- } else {
- $r->print(''.
- 'Could not initialize import fields (not in a course) ');
- }
- }
# ---------------------------------------------------- See if something to save
+
if (&Apache::lonnet::allowed('opa',$ENV{'request.course.id'})) {
my $fname='';
if ($ENV{'form.saveas'} && ($fname=$ENV{'form.newfn'})) {
$fname=~s/\W/\_/g;
if ($fname eq 'default') { $fname='course_default'; }
- $fname.='_'.&gettype($sheetone);
- &setfilename($sheetone,$fname);
+ $fname.='_'.&gettype($asheet);
+ &setfilename($asheet,$fname);
$ENV{'form.ufn'}=$fname;
- my $reply=&writesheet($sheetone);
- unless ($reroute) {
- $r->print('Saving spreadsheet: '.$reply.'
');
- }
- }
+ $r->print('
Saving spreadsheet: '.
+ &writesheet($asheet,$ENV{'form.makedefufn'}).'
');
+ }
}
+
# ------------------------------------------------ Write the modified worksheet
- &tmpwrite($sheetone,$r->dir_config('lonDaemons').'/tmp/',
- $ENV{'form.usymb'});
+ $r->print('Current sheet: '.&getfilename($asheet).'
');
+
+ &tmpwrite($asheet);
+
+# ---------------------------------------------------------- Additional options
+
+ $r->print(
+ '
'
+ );
+ if (&gettype($asheet) eq 'assesscalc') {
+ $r->print ('
Level up: Student Sheet
');
+ }
+
+ if ((&gettype($asheet) eq 'studentcalc') &&
+ (&Apache::lonnet::allowed('vgr',&getcid($asheet)))) {
+ $r->print (
+ '
'.
+ 'Level up: Course Sheet
');
+ }
+
+
+# ----------------------------------------------------------------- Save dialog
+
-# ----------------------------------------------------- Print user, course, etc
- unless ($reroute) {
if (&Apache::lonnet::allowed('opa',$ENV{'request.course.id'})) {
my $fname=$ENV{'form.ufn'};
$fname=~s/\_[^\_]+$//;
if ($fname eq 'default') { $fname='course_default'; }
$r->print(' '.
- '
');
+ ' (make default: )
');
}
- $r->print(&hiddenfield('ufn',$ENV{'form.ufn'}));
- unless (&gettype($sheetone) eq 'classcalc') {
- $r->print('User: '.$uname.'Domain: '.$udom);
- }
- $r->print('
'.
- $ENV{'course.'.$ENV{'request.course.id'}.'.description'}.' ');
- if ($csec) {
- $r->print('Group/Section: '.$csec.' ');
- }
- }
-# -------------------------------------------------------- Import and calculate
- if (&gettype($sheetone) eq 'assesscalc') {
- &rowaassess($sheetone,$ENV{'form.usymb'});
- } elsif (&gettype($sheetone) eq 'studentcalc') {
- &rowazstudent($sheetone);
- }
- my $calcoutput=&calcsheet($sheetone);
- unless ($reroute) {
- $r->print(''.$calcoutput.' ');
+ $r->print(&hiddenfield('ufn',&getfilename($asheet)));
+
+# --------------------------------------------------------------- Cached sheets
+
+ &expirationdates();
+
+ undef %oldsheets;
+ undef %loadedcaches;
+
+ if (&gettype($asheet) eq 'classcalc') {
+ $r->print("Loading previously calculated student sheets ... \n");
+ $r->rflush();
+ &cachedcsheets();
+ } elsif (&gettype($asheet) eq 'studentcalc') {
+ $r->print("Loading previously calculated assessment sheets ... \n");
+ $r->rflush();
+ &cachedssheets(&getuname($asheet),&getudom($asheet),
+ &getuhome($asheet));
}
-# ------------------------------------------------------- Print or export sheet
- unless ($reroute) {
- &outsheet($r,$sheetone);
+# ----------------------------------------------------- Update sheet, load rows
+
+ $r->print("Loaded sheet(s), updating rows ... \n");
+ $r->rflush();
+
+ &updatesheet($asheet);
+
+ $r->print("Updated rows, loading row data ... \n");
+ $r->rflush();
+
+ &loadrows($asheet,$r);
+
+ $r->print("Loaded row data, calculating sheet ... \n");
+ $r->rflush();
+
+ my $calcoutput=&calcsheet($asheet);
+ $r->print(''.$calcoutput.' ');
+ &outsheet($r,$asheet);
$r->print('