';
+ $prevattempts='';
$prevattempts.='History | ';
foreach (sort(keys %lasthash)) {
my ($ign,@parts) = split(/\./,$_);
- if (@parts) {
+ if ($#parts > 0) {
my $data=$parts[-1];
pop(@parts);
$prevattempts.='Part '.join('.',@parts).' '.$data.' | ';
} else {
- $prevattempts.=''.$ign.' | ';
+ if ($#parts == 0) {
+ $prevattempts.=''.$parts[0].' | ';
+ } else {
+ $prevattempts.=''.$ign.' | ';
+ }
}
}
if ($getattempt eq '') {
@@ -826,6 +1323,7 @@ sub get_previous_attempt {
} else {
$value=$lasthash{$_};
}
+ if ($_ =~/$regexp$/ && (defined &$gradesub)) {$value = &$gradesub($value)}
$prevattempts.=''.$value.' | ';
}
$prevattempts.='
---|
| ';
@@ -838,7 +1336,7 @@ sub get_previous_attempt {
}
sub get_student_view {
- my ($symb,$username,$domain,$courseid) = @_;
+ my ($symb,$username,$domain,$courseid,$target) = @_;
my ($map,$id,$feedurl) = split(/___/,$symb);
my (%old,%moreenv);
my @elements=('symb','courseid','domain','username');
@@ -846,6 +1344,7 @@ sub get_student_view {
$old{$element}=$ENV{'form.grade_'.$element};
$moreenv{'form.grade_'.$element}=eval '$'.$element #'
}
+ if ($target eq 'tex') {$moreenv{'form.grade_target'} = 'tex';}
&Apache::lonnet::appenv(%moreenv);
my $userview=&Apache::lonnet::ssi('/res/'.$feedurl);
&Apache::lonnet::delenv('form.grade_');
@@ -878,32 +1377,243 @@ sub get_student_answers {
foreach my $element (@elements) {
$ENV{'form.grade_'.$element}=$old{$element};
}
- $userview=~s/\]*\>//gi;
- $userview=~s/\<\/body\>//gi;
- $userview=~s/\//gi;
- $userview=~s/\<\/html\>//gi;
- $userview=~s/\//gi;
- $userview=~s/\<\/head\>//gi;
- $userview=~s/action\s*\=/would_be_action\=/gi;
return $userview;
}
###############################################
-=item get_unprocessed_cgi($query,$possible_names)
-Modify the %ENV hash to contain unprocessed CGI form parameters held in
-$query. The parameters listed in $possible_names (an array reference),
-will be set in $ENV{'form.name'} if they do not already exist.
+sub timehash {
+ my @ltime=localtime(shift);
+ return ( 'seconds' => $ltime[0],
+ 'minutes' => $ltime[1],
+ 'hours' => $ltime[2],
+ 'day' => $ltime[3],
+ 'month' => $ltime[4]+1,
+ 'year' => $ltime[5]+1900,
+ 'weekday' => $ltime[6],
+ 'dayyear' => $ltime[7]+1,
+ 'dlsav' => $ltime[8] );
+}
+
+sub maketime {
+ my %th=@_;
+ return POSIX::mktime(
+ ($th{'seconds'},$th{'minutes'},$th{'hours'},
+ $th{'day'},$th{'month'}-1,$th{'year'}-1900,0,0,$th{'dlsav'}));
+}
-Typically called with $ENV{'QUERY_STRING'} as the first parameter.
-$possible_names is an ref to an array of form element names. As an example:
-get_unprocessed_cgi($ENV{'QUERY_STRING'},['uname','udom']);
-will result in $ENV{'form.uname'} and $ENV{'form.udom'} being set.
+
+#########################################
+#
+# Retro-fixing of un-backward-compatible time format
+
+sub unsqltime {
+ my $timestamp=shift;
+ if ($timestamp=~/^(\d+)\-(\d+)\-(\d+)\s+(\d+)\:(\d+)\:(\d+)$/) {
+ $timestamp=&maketime(
+ 'year'=>$1,'month'=>$2,'day'=>$3,
+ 'hours'=>$4,'minutes'=>$5,'seconds'=>$6);
+ }
+ return $timestamp;
+}
+
+#########################################
+
+sub findallcourses {
+ my %courses=();
+ my $now=time;
+ foreach (keys %ENV) {
+ if ($_=~/^user\.role\.\w+\.\/(\w+)\/(\w+)/) {
+ my ($starttime,$endtime)=$ENV{$_};
+ my $active=1;
+ if ($starttime) {
+ if ($now<$starttime) { $active=0; }
+ }
+ if ($endtime) {
+ if ($now>$endtime) { $active=0; }
+ }
+ if ($active) { $courses{$1.'_'.$2}=1; }
+ }
+ }
+ return keys %courses;
+}
+
+###############################################
+###############################################
+
+=pod
+
+=item &determinedomain()
+
+Inputs: $domain (usually will be undef)
+
+Returns: Determines which domain should be used for designs
=cut
###############################################
+sub determinedomain {
+ my $domain=shift;
+ if (! $domain) {
+ # Determine domain if we have not been given one
+ $domain = $Apache::lonnet::perlvar{'lonDefDomain'};
+ if ($ENV{'user.domain'}) { $domain=$ENV{'user.domain'}; }
+ if ($ENV{'request.role.domain'}) {
+ $domain=$ENV{'request.role.domain'};
+ }
+ }
+ return $domain;
+}
+###############################################
+=pod
+
+=item &domainlogo()
+
+Inputs: $domain (usually will be undef)
+
+Returns: A link to a domain logo, if the domain logo exists.
+If the domain logo does not exist, a description of the domain.
+
+=cut
+###############################################
+sub domainlogo {
+ my $domain = &determinedomain(shift);
+ # See if there is a logo
+ if (-e '/home/httpd/html/adm/lonDomLogos/'.$domain.'.gif') {
+ return '';
+ } elsif(exists($Apache::lonnet::domaindescription{$domain})) {
+ return $Apache::lonnet::domaindescription{$domain};
+ } else {
+ return '';
+ }
+}
+##############################################
+
+=pod
+
+=item &designparm()
+
+Inputs: $which parameter; $domain (usually will be undef)
+
+Returns: value of designparamter $which
+
+=cut
+##############################################
+sub designparm {
+ my ($which,$domain)=@_;
+ $domain=&determinedomain($domain);
+ if ($designhash{$domain.'.'.$which}) {
+ return $designhash{$domain.'.'.$which};
+ } else {
+ return $designhash{'default.'.$which};
+ }
+}
+
+###############################################
+###############################################
+
+=pod
+
+=item &bodytag()
+
+Returns a uniform header for LON-CAPA web pages.
+
+Inputs:
+
+ $title, A title to be displayed on the page.
+ $function, the current role (can be undef).
+ $addentries, extra parameters for the tag.
+ $bodyonly, if defined, only return the tag.
+ $domain, if defined, force a given domain.
+
+Returns: A uniform header for LON-CAPA web pages.
+If $bodyonly is nonzero, a string containing a tag will be returned.
+If $bodyonly is undef or zero, an html string containing a tag and
+other decorations will be returned.
+
+=cut
+
+###############################################
+
+
+###############################################
+sub bodytag {
+ my ($title,$function,$addentries,$bodyonly,$domain)=@_;
+ unless ($function) {
+ $function='student';
+ if ($ENV{'request.role'}=~/^(cc|in|ta|ep)/) {
+ $function='coordinator';
+ }
+ if ($ENV{'request.role'}=~/^(su|dc|ad|li)/) {
+ $function='admin';
+ }
+ if (($ENV{'request.role'}=~/^(au|ca)/) ||
+ ($ENV{'REQUEST_URI'}=~/^(\/priv|\~)/)) {
+ $function='author';
+ }
+ }
+ my $img=&designparm($function.'.img',$domain);
+ my $pgbg=&designparm($function.'.pgbg',$domain);
+ my $tabbg=&designparm($function.'.tabbg',$domain);
+ my $font=&designparm($function.'.font',$domain);
+ my $link=&designparm($function.'.link',$domain);
+ my $alink=&designparm($function.'.alink',$domain);
+ my $vlink=&designparm($function.'.vlink',$domain);
+ my $sidebg=&designparm($function.'.sidebg',$domain);
+
+ # role and realm
+ my ($role,$realm)
+ =&Apache::lonnet::plaintext((split(/\./,$ENV{'request.role'}))[0]);
+# realm
+ if ($ENV{'request.course.id'}) {
+ $realm=
+ $ENV{'course.'.$ENV{'request.course.id'}.'.description'};
+ }
+ unless ($realm) { $realm=' '; }
+# Set messages
+ my $messages=&domainlogo($domain);
+# Output
+ my $bodytag = <
+END
+ if ($bodyonly) {
+ return $bodytag;
+ } elsif ($ENV{'browser.interface'} eq 'textual') {
+ return $bodytag.'LON-CAPA: '.$title.
+ 'Main Menu ';
+ } else {
+ return(<
+
+ |
+$messages |
+
+
+
+ $title
+ |
+
+ $ENV{'environment.firstname'}
+ $ENV{'environment.middlename'}
+ $ENV{'environment.lastname'}
+ $ENV{'environment.generation'}
+
+ |
+
+
+$role
+ |
+
+$realm |
+ |