--- loncom/interface/Attic/lonspreadsheet.pm 2002/04/10 15:30:13 1.83 +++ loncom/interface/Attic/lonspreadsheet.pm 2002/04/12 21:41:13 1.86 @@ -1,5 +1,5 @@ # -# $Id: lonspreadsheet.pm,v 1.83 2002/04/10 15:30:13 matthew Exp $ +# $Id: lonspreadsheet.pm,v 1.86 2002/04/12 21:41:13 matthew Exp $ # # Copyright Michigan State University Board of Trustees # @@ -111,6 +111,23 @@ my %parmhash; my $includedir; my $tmpdir; +# ------------------------------------------------ Send critical message +sub send_crit_msg { + my ($uname,$udom,$subject,$message,$sendback) = @_; + my $result = &Apache::lonmsg::user_crit_msg($uname,$udom,$subject, + $message,$sendback); + return ($result eq 'ok' ? 1 : 0); +} + +# ------------------------------------------------ Send noncritical message +sub send_msg { + my ($uname,$udom,$subject,$message) = @_; + my $result = &Apache::lonmsg::user_normal_msg($uname,$udom, + $subject,$message); + return ($result eq 'ok' ? 1 : 0); +} + + # ============================================================================= # ===================================== Implements an instance of a spreadsheet @@ -122,6 +139,8 @@ sub initsheet { $safeeval->permit("sort"); $safeeval->deny(":base_io"); $safehole->wrap(\&Apache::lonnet::EXT,$safeeval,'&EXT'); + $safehole->wrap(\&send_msg, $safeeval,"&send_msg"); + $safehole->wrap(\&send_crit_msg,$safeeval,"&send_crit_msg"); my $code=<<'ENDDEFS'; # ---------------------------------------------------- Inside of the safe space @@ -508,6 +527,15 @@ sub HASH { return $Values[-1]; } +#------------------------------------------------------- + +=item NUM(range) + +returns the number of items in the range. + +=cut + +#------------------------------------------------------- sub NUM { my $mask=mask(@_); my $num= $#{@{grep(/$mask/,keys(%v))}}+1; @@ -527,6 +555,15 @@ sub BIN { } +#------------------------------------------------------- + +=item SUM(range) + +returns the sum of items in the range. + +=cut + +#------------------------------------------------------- sub SUM { my $mask=mask(@_); my $sum=0; @@ -536,6 +573,15 @@ sub SUM { return $sum; } +#------------------------------------------------------- + +=item MEAN(range) + +compute the average of the items in the range. + +=cut + +#------------------------------------------------------- sub MEAN { my $mask=mask(@_); my $sum=0; my $num=0; @@ -550,6 +596,15 @@ sub MEAN { } } +#------------------------------------------------------- + +=item STDDEV(range) + +compute the standard deviation of the items in the range. + +=cut + +#------------------------------------------------------- sub STDDEV { my $mask=mask(@_); my $sum=0; my $num=0; @@ -566,6 +621,15 @@ sub STDDEV { return sqrt($sum/($num-1)); } +#------------------------------------------------------- + +=item PROD(range) + +compute the product of the items in the range. + +=cut + +#------------------------------------------------------- sub PROD { my $mask=mask(@_); my $prod=1; @@ -575,6 +639,15 @@ sub PROD { return $prod; } +#------------------------------------------------------- + +=item MAX(range) + +compute the maximum of the items in the range. + +=cut + +#------------------------------------------------------- sub MAX { my $mask=mask(@_); my $max='-'; @@ -585,6 +658,15 @@ sub MAX { return $max; } +#------------------------------------------------------- + +=item MIN(range) + +compute the minimum of the items in the range. + +=cut + +#------------------------------------------------------- sub MIN { my $mask=mask(@_); my $min='-'; @@ -595,12 +677,22 @@ sub MIN { return $min; } +#------------------------------------------------------- + +=item SUMMAX(num,lower,upper) + +compute the sum of the largest 'num' items in the range from +'lower' to 'upper' + +=cut + +#------------------------------------------------------- sub SUMMAX { my ($num,$lower,$upper)=@_; my $mask=mask($lower,$upper); my @inside=(); foreach (grep /$mask/,keys(%v)) { - $inside[$#inside+1]=$v{$_}; + push (@inside,$v{$_}); } @inside=sort(@inside); my $sum=0; my $i; @@ -610,6 +702,16 @@ sub SUMMAX { return $sum; } +#------------------------------------------------------- + +=item SUMMIN(num,lower,upper) + +compute the sum of the smallest 'num' items in the range from +'lower' to 'upper' + +=cut + +#------------------------------------------------------- sub SUMMIN { my ($num,$lower,$upper)=@_; my $mask=mask($lower,$upper); @@ -625,6 +727,40 @@ sub SUMMIN { return $sum; } +#------------------------------------------------------- + +=item SEND_CRIT_MSG(subject,message) + +Send a critical message to a student. + +=cut + +#------------------------------------------------------- +sub SEND_CRIT_MSG { + my ($subject,$message) = @_; + my $name = $uname; + my $dom = $udom; + return (&send_crit_msg($name,$dom,$subject,$message) ? 'Message Sent.' + : 'Error sending message'); +} + +#------------------------------------------------------- + +=item SEND_MSG(subject,message) + +Send a message to a student. + +=cut + +#------------------------------------------------------- +sub SEND_MSG { + my ($subject,$message) = @_; + my $name = $uname; + my $dom = $udom; + return (&send_msg($name,$dom,$subject,$message) ? 'Message Sent.' + : 'Error sending message'); +} + sub expandnamed { my $expression=shift; if ($expression=~/^\&/) { @@ -1233,17 +1369,11 @@ sub readsheet { } elsif($fn=~/\/*\.spreadsheet$/) { my $sheetxml=&Apache::lonnet::getfile (&Apache::lonnet::filelocation('',$fn)); - print "
$sheetxml
"; if ($sheetxml == -1) { $sheetxml='"Error loading spreadsheet ' .$fn.'"'; } %f=%{&parse_sheet(\$sheetxml)}; - print "
";
-         foreach (sort( keys(%f))) {
-             print "$_ = $f{$_}\n";
-         }
-         print "
"; } else { my $sheet=''; my %tmphash = &Apache::lonnet::dump($fn,$cdom,$cnum); @@ -2342,8 +2472,8 @@ $tmpdir=$r->dir_config('lonDaemons').'/t function celledit(cn,cf) { var cnf=prompt(cn,cf); - if (cnf!=null) { - document.sheet.unewfield.value=cn; + if (cnf!=null) { + document.sheet.unewfield.value=cn; document.sheet.unewformula.value=cnf; document.sheet.submit(); }