--- loncom/interface/Attic/lonspreadsheet.pm 2001/04/09 17:59:04 1.54
+++ loncom/interface/Attic/lonspreadsheet.pm 2001/07/21 22:45:46 1.56
@@ -5,7 +5,8 @@
# 12/08,12/09,12/11,12/12,12/15,12/16,12/18,12/19,12/30,
# 01/01/01,02/01,03/01,19/01,20/01,22/01,
# 03/05,03/08,03/10,03/12,03/13,03/15,03/17,
-# 03/19,03/20,03/21,03/27,04/05,04/09 Gerd Kortemeyer
+# 03/19,03/20,03/21,03/27,04/05,04/09,
+# 07/09,07/14,07/21 Gerd Kortemeyer
package Apache::lonspreadsheet;
@@ -77,12 +78,17 @@ sub initsheet {
# v: output values
# c: preloaded constants (A-column)
# rl: row label
+# os: other spreadsheets (for student spreadsheet only)
undef %v;
undef %t;
undef %f;
undef %c;
undef %rl;
+undef @os;
+
+ undef $nfield;
+ undef $nsheet;
$maxrow=0;
$sheettype='';
@@ -397,7 +403,18 @@ sub outrowassess {
my $n=shift;
my @cols=();
if ($n) {
- $cols[0]=$rl{$f{'A'.$n}};
+ my ($usy,$ufn)=split(/\_\_\&\&\&\_\_/,$f{'A'.$n});
+ $cols[0]=$rl{$f{'A'.$n}}.'
'.
+ '';
} else {
$cols[0]='Export';
}
@@ -460,6 +477,13 @@ sub setconstants {
%{$safeeval->varglob('c')}=%c;
}
+# --------------------------------------------- Set names of other spreadsheets
+
+sub setothersheets {
+ my ($safeeval,@os)=@_;
+ @{$safeeval->varglob('os')}=@os;
+}
+
# ------------------------------------------------ Add or change formula values
sub setrowlabels {
@@ -508,6 +532,12 @@ sub getmaxrow {
my $safeeval=shift;
return $safeeval->reval('$maxrow');
}
+# -------------------------------------------- Store which sheet needs changing
+
+sub changesheet {
+ my ($safeeval,$nfield,$nsheet)=@_;
+ $safeeval->reval('$nfield='.$nfield.'; $nsheet='.$nsheet.';');
+}
# ---------------------------------------------------------------- Set filename
@@ -600,6 +630,7 @@ sub exportdata {
return $safeeval->reval('&exportrowa()');
}
+
# ========================================================== End of Spreadsheet
# =============================================================================
@@ -638,11 +669,15 @@ sub rown {
my $showf=0;
my $proc;
my $maxred;
- if (&gettype($safeeval) eq 'assesscalc') {
+ if (&gettype($safeeval) eq 'studentcalc') {
$proc='&outrowassess';
- $maxred=1;
+ $maxred=26;
} else {
$proc='&outrow';
+ }
+ if (&gettype($safeeval) eq 'assesscalc') {
+ $maxred=1;
+ } else {
$maxred=26;
}
if ($n eq '-') { $proc='&templaterow'; $n=-1; }
@@ -716,6 +751,29 @@ sub outsheet {
}
#
+# ----------------------------------------------- Read list of available sheets
+#
+
+sub othersheets {
+ my ($safeeval,$stype)=@_;
+
+ my $cnum=&getcnum($safeeval);
+ my $cdom=&getcdom($safeeval);
+ my $chome=&getchome($safeeval);
+
+ my @alternatives=();
+ my $result=&Apache::lonnet::reply('dump:'.$cdom.':'.$cnum.':'.
+ $stype.'_spreadsheets',$chome);
+ if ($result!~/^error\:/) {
+ map {
+ $alternatives[$#alternatives+1]=
+ &Apache::lonnet::unescape((split(/\=/,$_))[0]);
+ } split(/\&/,$result);
+ }
+ return @alternatives;
+}
+
+#
# -------------------------------------- Read spreadsheet formulas for a course
#
@@ -835,8 +893,10 @@ sub writesheet {
# ----------------------------------------------------------------- Write sheet
my $sheetdata='';
map {
+ unless ($f{$_} eq 'import') {
$sheetdata.=&Apache::lonnet::escape($_).'='.
&Apache::lonnet::escape($f{$_}).'&';
+ }
} keys %f;
$sheetdata=~s/\&$//;
my $reply=&Apache::lonnet::reply('put:'.$cdom.':'.$cnum.':'.$fn.':'.
@@ -844,7 +904,8 @@ sub writesheet {
if ($reply eq 'ok') {
$reply=&Apache::lonnet::reply('put:'.$cdom.':'.$cnum.':'.
$stype.'_spreadsheets:'.
- &Apache::lonnet::escape($fn).'='.$ENV{'user.name'},
+ &Apache::lonnet::escape($fn).'='.$ENV{'user.name'}.'@'.
+ $ENV{'user.domain'},
$chome);
if ($reply eq 'ok') {
if ($makedef) {
@@ -902,7 +963,13 @@ sub tmpread {
$fo{$name}=$value;
}
}
- if ($nfield) { $fo{$nfield}=$nform; }
+ if ($nform eq 'changesheet') {
+ unless ($ENV{'form.sel_'.$nfield} eq 'Default') {
+ &changesheet($safeeval,$nfield,$ENV{'form.sel_'.$nfield});
+ }
+ } else {
+ if ($nfield) { $fo{$nfield}=$nform; }
+ }
&setformulas($safeeval,%fo);
}
@@ -1223,9 +1290,10 @@ sub loadstudent {
if ($_=~/^A(\d+)/) {
my $row=$1;
unless (($f{$_}=~/^\!/) || ($row==0)) {
+ my ($usy,$ufn)=split(/\_\_\&\&\&\_\_/,$f{$_});
@assessdata=&exportsheet(&getuname($safeeval),
&getudom($safeeval),
- 'assesscalc',$f{$_});
+ 'assesscalc',$usy,$ufn);
my $index=0;
map {
if ($assessdata[$index]) {
@@ -1760,6 +1828,10 @@ $tmpdir=$r->dir_config('lonDaemons').'/t
}
} (split(/&/,$ENV{'QUERY_STRING'}));
+# -------------------------------------- Interactive loading of specific sheet?
+ if (($ENV{'form.load'}) && ($ENV{'form.loadthissheet'} ne 'Default')) {
+ $ENV{'form.ufn'}=$ENV{'form.loadthissheet'};
+ }
# ------------------------------------------- Nothing there? Must be login user
my $aname;
@@ -1795,6 +1867,12 @@ $tmpdir=$r->dir_config('lonDaemons').'/t
}
}
+ function changesheet(cn) {
+ document.sheet.unewfield.value=cn;
+ document.sheet.unewformula.value='changesheet';
+ document.sheet.submit();
+ }
+
ENDSCRIPT
$r->print('
Saving spreadsheet: '. - &writesheet($asheet,$ENV{'form.makedefufn'}).'
'); - } - } - -# ------------------------------------------------ Write the modified worksheet - - $r->print('Current sheet: '.&getfilename($asheet).'
'); - - &tmpwrite($asheet); - # ---------------------------------------------------------- Additional options $r->print( @@ -1932,6 +1989,24 @@ ENDSCRIPT $r->print(&hiddenfield('ufn',&getfilename($asheet))); +# ----------------------------------------------------------------- Load dialog + if (&Apache::lonnet::allowed('opa',$ENV{'request.course.id'})) { + $r->print('
'. + '
'); + if (&gettype($asheet) eq 'studentcalc') { + &setothersheets($asheet,&othersheets($asheet,'assesscalc')); + } + } + # --------------------------------------------------------------- Cached sheets &expirationdates(); @@ -1968,6 +2043,29 @@ ENDSCRIPT my $calcoutput=&calcsheet($asheet); $r->print('
Saving spreadsheet: '. + &writesheet($asheet,$ENV{'form.makedefufn'}).'
'); + } + } + +# ------------------------------------------------ Write the modified worksheet + + $r->print('Current sheet: '.&getfilename($asheet).'
'); + + &tmpwrite($asheet); + +# ------------------------------------------------------------- Print out sheet + &outsheet($r,$asheet); $r->print('