Annotation of loncom/interface/loncommon.pm, revision 1.10

1.10    ! albertel    1: # The LearningOnline Network with CAPA
1.1       albertel    2: # a pile of common routines
1.10    ! albertel    3: #
        !             4: # $Id: gplheader.pl,v 1.1 2001/11/29 18:19:27 www Exp $
        !             5: #
        !             6: # Copyright Michigan State University Board of Trustees
        !             7: #
        !             8: # This file is part of the LearningOnline Network with CAPA (LON-CAPA).
        !             9: #
        !            10: # LON-CAPA is free software; you can redistribute it and/or modify
        !            11: # it under the terms of the GNU General Public License as published by
        !            12: # the Free Software Foundation; either version 2 of the License, or
        !            13: # (at your option) any later version.
        !            14: #
        !            15: # LON-CAPA is distributed in the hope that it will be useful,
        !            16: # but WITHOUT ANY WARRANTY; without even the implied warranty of
        !            17: # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
        !            18: # GNU General Public License for more details.
        !            19: #
        !            20: # You should have received a copy of the GNU General Public License
        !            21: # along with LON-CAPA; if not, write to the Free Software
        !            22: # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
        !            23: #
        !            24: # /home/httpd/html/adm/gpl.txt
        !            25: #
        !            26: # http://www.lon-capa.org/
        !            27: #
1.1       albertel   28: # 2/13 Guy Albertelli
                     29: 
                     30: # Makes a table out of the previous attempts
1.2       albertel   31: # Inputs result_from_symbread, user, domain, course_id
1.1       albertel   32: 
                     33: package Apache::loncommon;
                     34: 
                     35: use strict;
1.8       albertel   36: use POSIX qw(strftime);
1.1       albertel   37: use Apache::Constants qw(:common);
                     38: use Apache::lonmsg();
                     39: 
                     40: sub get_previous_attempt {
1.2       albertel   41:   my ($symb,$username,$domain,$course)=@_;
1.1       albertel   42:   my $prevattempts='';
                     43:   if ($symb) {
1.3       albertel   44:     my (%returnhash)=
                     45:       &Apache::lonnet::restore($symb,$course,$domain,$username);
1.1       albertel   46:     if ($returnhash{'version'}) {
                     47:       my %lasthash=();
                     48:       my $version;
                     49:       for ($version=1;$version<=$returnhash{'version'};$version++) {
                     50:         map {
                     51: 	  $lasthash{$_}=$returnhash{$version.':'.$_};
1.4       albertel   52:         } sort(split(/\:/,$returnhash{$version.':keys'}));
1.1       albertel   53:       }
                     54:       $prevattempts='<table border=2></tr><th>History</th>';
                     55:       map {
                     56:         $prevattempts.='<th>'.$_.'</th>';
1.4       albertel   57:       } sort(keys %lasthash);
1.1       albertel   58:       for ($version=1;$version<=$returnhash{'version'};$version++) {
                     59:         $prevattempts.='</tr><tr><th>Attempt '.$version.'</th>';
                     60:         map {
1.5       albertel   61: 	  my $value;
                     62: 	  if ($_ =~ /timestamp/) {
                     63: 	    $value=scalar(localtime($returnhash{$version.':'.$_}));
                     64: 	  } else {
                     65: 	    $value=$returnhash{$version.':'.$_};
                     66: 	  }
                     67: 	  $prevattempts.='<td>'.$value.'</td>';   
1.4       albertel   68:         } sort(keys %lasthash);
1.1       albertel   69:       }
                     70:       $prevattempts.='</tr><tr><th>Current</th>';
                     71:       map {
1.5       albertel   72: 	my $value;
                     73: 	if ($_ =~ /timestamp/) {
                     74: 	  $value=scalar(localtime($lasthash{$_}));
                     75: 	} else {
                     76: 	  $value=$lasthash{$_};
                     77: 	}
                     78: 	$prevattempts.='<td>'.$value.'</td>';
1.4       albertel   79:       } sort(keys %lasthash);
1.1       albertel   80:       $prevattempts.='</tr></table>';
                     81:     } else {
                     82:       $prevattempts='Nothing submitted - no attempts.';
                     83:     }
                     84:   } else {
                     85:     $prevattempts='No data.';
                     86:   }
1.10    ! albertel   87: }
        !            88: 
        !            89: sub get_student_view {
        !            90:   my ($symb,$username,$domain,$courseid) = @_;
        !            91:   my ($map,$id,$feedurl) = split(/___/,$symb);
        !            92:   my (%old,%moreenv);
        !            93:   my @elements=('symb','courseid','domain','username');
        !            94:   foreach my $element (@elements) {
        !            95:     $old{$element}=$ENV{'form.grade_'.$element};
        !            96:     $moreenv{'form.grade_'.$element}=eval '$'.$element #'
        !            97:   }
        !            98:   &Apache::lonnet::appenv(%moreenv);
        !            99:   my $userview=&Apache::lonnet::ssi('/res/'.$feedurl);
        !           100:   &Apache::lonnet::delenv('form.grade_');
        !           101:   foreach my $element (@elements) {
        !           102:     $ENV{'form.grade_'.$element}=$old{$element};
        !           103:   }
        !           104:   $userview=~s/\<body[^\>]*\>//gi;
        !           105:   $userview=~s/\<\/body\>//gi;
        !           106:   $userview=~s/\<html\>//gi;
        !           107:   $userview=~s/\<\/html\>//gi;
        !           108:   $userview=~s/\<head\>//gi;
        !           109:   $userview=~s/\<\/head\>//gi;
        !           110:   $userview=~s/action\s*\=/would_be_action\=/gi;
        !           111:   return $userview;
1.1       albertel  112: }
                    113: 
1.6       albertel  114: sub get_unprocessed_cgi {
                    115:   my ($query)= @_;
                    116:   map {
                    117:     my ($name, $value) = split(/=/,$_);
                    118:     $value =~ tr/+/ /;
                    119:     $value =~ s/%([a-fA-F0-9][a-fA-F0-9])/pack("C",hex($1))/eg;
                    120:     if (!defined($ENV{'form.'.$name})) { $ENV{'form.'.$name}=$value; }
                    121:   } (split(/&/,$query));
                    122: }
                    123: 
1.7       albertel  124: sub cacheheader {
1.8       albertel  125:   my $date=strftime("%a, %d %b %Y %H:%M:%S GMT",gmtime);
1.7       albertel  126:   my $output .='<meta HTTP-EQUIV="Expires" CONTENT="'.$date.'" />
                    127:                 <meta HTTP-EQUIV="Cache-control" CONTENT="no-cache" />
                    128:                 <meta HTTP-EQUIV="Pragma" CONTENT="no-cache" />';
                    129:   return $output;
                    130: }
                    131: 
1.9       albertel  132: sub no_cache {
                    133:   my ($r) = @_;
                    134:   my $date=strftime("%a, %d %b %Y %H:%M:%S GMT",gmtime);
                    135:   $r->no_cache(1);
                    136:   $r->header_out("Pragma" => "no-cache");
                    137:   $r->header_out("Expires" => $date);
                    138: }
1.1       albertel  139: 1;
                    140: __END__;

FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>