--- loncom/interface/loncommon.pm 2005/12/01 23:04:08 1.300 +++ loncom/interface/loncommon.pm 2006/03/21 16:32:50 1.315 @@ -1,7 +1,7 @@ # The LearningOnline Network with CAPA # a pile of common routines # -# $Id: loncommon.pm,v 1.300 2005/12/01 23:04:08 albertel Exp $ +# $Id: loncommon.pm,v 1.315 2006/03/21 16:32:50 albertel Exp $ # # Copyright Michigan State University Board of Trustees # @@ -331,7 +331,10 @@ sub storeresurl { sub studentbrowser_javascript { unless ( (($env{'request.course.id'}) && - (&Apache::lonnet::allowed('srm',$env{'request.course.id'}))) + (&Apache::lonnet::allowed('srm',$env{'request.course.id'}) + || &Apache::lonnet::allowed('srm',$env{'request.course.id'}. + '/'.$env{'request.course.sec'}) + )) || ($env{'request.role'}=~/^(au|dc|su)/) ) { return ''; } return (<<'ENDSTDBRW'); @@ -362,7 +365,9 @@ ENDSTDBRW sub selectstudent_link { my ($form,$unameele,$udomele)=@_; if ($env{'request.course.id'}) { - unless (&Apache::lonnet::allowed('srm',$env{'request.course.id'})) { + if (!&Apache::lonnet::allowed('srm',$env{'request.course.id'}) + && !&Apache::lonnet::allowed('srm',$env{'request.course.id'}. + '/'.$env{'request.course.sec'})) { return ''; } return " @@ -2887,6 +2898,8 @@ ENDROLE $dc_info.= $cid.' '.$env{'course.'.$cid.'.internal.coursecode'}; $dc_info = '('.$dc_info.')'; } + # Explicit link to get inline menu + my $menu='
 
'.&mt('Switch to Inline Menu Mode').''; # return(< -$titleinfo $dc_info +$titleinfo $dc_info $menu $env{'environment.firstname'} @@ -2923,7 +2936,7 @@ ENDBODY =back -=head1 HTTP Helpers +=head1 HTML Helpers =over 4 @@ -2931,26 +2944,204 @@ ENDBODY Returns a uniform footer for LON-CAPA web pages. -Inputs: - -=over 4 +Inputs: none =back -Returns: A uniform footer for LON-CAPA web pages. - =cut sub endbodytag { my $endbodytag=''; $endbodytag=&Apache::lontexconvert::jsMath_process()."\n".$endbodytag; + if ( exists( $env{'internal.head.redirect'} ) ) { + $endbodytag= + "
". + &mt('Continue').''. + $endbodytag; + } return $endbodytag; } +=pod + +=over 4 + +=item * &headtag() + +Returns a uniform footer for LON-CAPA web pages. + +Inputs: $title - optional title for the head + $head_extra - optional extra HTML to put inside the + $args - optional arguments + redirect - array ref of seconds before redirect occurs + url to redirect to + (side effect of setting + $env{'internal.head.redirect'} to the url + redirected too) +=back + +=cut + +sub headtag { + my ($title,$head_extra,$args) = @_; + + my $result = + ''. + &Apache::lonxml::fontsettings(). + &Apache::lonhtmlcommon::htmlareaheaders(); + + if (ref($args->{'redirect'})) { + my ($time,$url) = @{$args->{'redirect'}}; + $url = &Apache::lonenc::check_encrypt($url); + $env{'internal.head.redirect'} = $url; + $result.=< + +ADDMETA + } + if (!defined($title)) { + $title = 'The LearningOnline Network with CAPA'; + } + + $result .= ' LON-CAPA '.&mt($title).''.$head_extra; + + return $result; +} + +=pod + +=over 4 + +=item * &endheadtag() + +Returns a uniform for LON-CAPA web pages. + +Inputs: none + +=back + +=cut + +sub endheadtag { + return ''; +} + +=pod + +=over 4 + +=item * &head() + +Returns a uniform complete .. section for LON-CAPA web pages. + +Inputs: $title - optional title for the page + $head_extra - optional extra HTML to put inside the +=back + +=cut + +sub head { + my ($title,$head_extra) = @_; + return &headtag($title,$head_extra).&endheadtag(); +} + +=pod + +=over 4 + +=item * &start_page() + +Returns a complete .. section for LON-CAPA web pages. + +Inputs: $title - optional title for the page + $head_extra - optional extra HTML to incude inside the + $args - additional optional args supported are: + only_body -> is true will set &bodytag() onlybodytag arg on + no_nav_bar -> is true will set &bodytag() notopbar arg on + add_entries -> additional attributes to add to the + domain -> force to color decorate a page for a + specific domain + function -> force usage of a specific rolish color scheme + redirect -> see &headtag() + bgcolor -> override the default page bg color + js_ready -> return a string ready for being used in + a javascript writeln + +=back + +=cut + +sub start_page { + my ($title,$head_extra,$args) = @_; + my %head_args; + if (defined($args->{'redirect'})) { + $head_args{'redirect'} = $args->{'redirect'}; + } + $env{'internal.start_page'}++; + my $result = + &Apache::lonxml::xmlbegin(). + &headtag($title,$head_extra,\%head_args).&endheadtag(). + &bodytag($title, $args->{'function'}, $args->{'add_entries'}, + $args->{'only_body'}, + undef,undef,undef,$args->{'no_nav_bar'},$args->{'bgcolor'}); + if ($args->{'js_ready'}) { + $result =~ s/[\n\r]/ /g; + $result =~ s/'/\\'/g; + } + return $result; +} + +=pod + +=over 4 + +=item * &head() + +Returns a complete section for LON-CAPA web pages. + +Inputs: $args - additional optional args supported are: + js_ready -> return a string ready for being used in + a javascript writeln +=back + +=cut + +sub end_page { + my ($args) = @_; + $env{'internal.end_page'}++; + my $result = &endbodytag()."\n"; + if ($args->{'js_ready'}) { + $result =~ s/[\n\r]/ /g; + $result =~ s/'/\\'/g; + } + return $result; +} + +sub validate_page { + if ( exists($env{'internal.start_page'}) + && $env{'internal.start_page'} > 1) { + &Apache::lonnet::logthis('start_page called multiple times'); + } + if ( exists($env{'internal.end_page'}) + && $env{'internal.end_page'} > 1) { + &Apache::lonnet::logthis('end_page called multiple times'); + } + if ( exists($env{'internal.start_page'}) + && ! exists($env{'internal.end_page'})) { + &Apache::lonnet::logthis('start_page called without end_page'); + } + if ( ! exists($env{'internal.start_page'}) + && exists($env{'internal.end_page'})) { + &Apache::lonnet::logthis('end_page called without start_page'); + } +} + ############################################### =pod +=over 4 + =item get_users_function Used by &bodytag to determine the current users primary role. @@ -3165,7 +3356,7 @@ times for group members. Outer hash key is functions. Inner hash keys are chat,discussion,email,files,homepage,roster. Corresponding values are either on or off, depending on -whther this type of functionality is available for the group. +whether this type of functionality is available for the group. =cut @@ -3176,13 +3367,18 @@ sub get_group_settings { my $parser=HTML::TokeParser->new(\$groupinfo); my $token; my $tool = ''; + my $role = ''; my %content=(); while ($token=$parser->get_token) { if ($token->[0] eq 'S') { my $entry=$token->[1]; - if ($entry eq 'functions') { + if ($entry eq 'functions' || $entry eq 'autosec') { %{$content{$entry}} = (); $tool = $entry; + } elsif ($entry eq 'role') { + if ($tool eq 'autosec') { + $role = $token->[2]{id}; + } } else { my $value=$parser->get_text('/'.$entry); if ($entry eq 'name') { @@ -3192,14 +3388,24 @@ sub get_group_settings { } } elsif ($entry eq 'groupname') { $content{$entry}=&Apache::lonnet::unescape($value); + } elsif (($entry eq 'roles') || ($entry eq 'types') || + ($entry eq 'sectionpick') || ($entry eq 'defpriv')) { + push(@{$content{$entry}},$value); + } elsif ($entry eq 'section') { + if ($tool eq 'autosec' && $role ne '') { + push(@{$content{$tool}{$role}},$value); + } } else { $content{$entry}=$value; } } } elsif ($token->[0] eq 'E') { - if ($token->[1] eq 'functions') { + if ($token->[1] eq 'functions' || $token->[1] eq 'autosec') { $tool = ''; + } elsif ($token->[1] eq 'role') { + $role = ''; } + } } return %content; @@ -3724,6 +3930,22 @@ sub upfile_select_html { return $Str; } +sub get_samples { + my ($records,$toget) = @_; + my @samples=({}); + my $got=0; + foreach my $rec (@$records) { + my %temp = &record_sep($rec); + if (! grep(/\S/, values(%temp))) { next; } + if (%temp) { + $samples[$got]=\%temp; + $got++; + if ($got == $toget) { last; } + } + } + return \@samples; +} + ###################################################### ###################################################### @@ -3741,18 +3963,15 @@ Apache Request ref, $records is an array ###################################################### sub csv_print_samples { my ($r,$records) = @_; - my (%sone,%stwo,%sthree); - %sone=&record_sep($$records[0]); - if (defined($$records[1])) {%stwo=&record_sep($$records[1]);} - if (defined($$records[2])) {%sthree=&record_sep($$records[2]);} - # + my $samples = &get_samples($records,3); + $r->print(&mt('Samples').'
'); - foreach (sort({$a <=> $b} keys(%sone))) { + foreach (sort({$a <=> $b} keys(%{ $samples->[0] }))) { $r->print(''); } $r->print(''); - foreach my $hash (\%sone,\%stwo,\%sthree) { + foreach my $hash (@$samples) { $r->print(''); - foreach (sort({$a <=> $b} keys(%sone))) { + foreach (sort({$a <=> $b} keys(%{ $samples->[0] }))) { $r->print(''); @@ -3781,8 +4000,8 @@ $d is an array of 2 element arrays (inte ###################################################### sub csv_print_select_table { my ($r,$records,$d) = @_; - my $i=0;my %sone; - %sone=&record_sep($$records[0]); + my $i=0; + my $samples = &get_samples($records,1); $r->print(&mt('Associate columns with student attributes.')."\n". '
'.&mt('Column [_1]',($_+1)).'
'); if (defined($$hash{$_})) { $r->print($$hash{$_}); } $r->print('
'. ''. @@ -3794,7 +4013,7 @@ sub csv_print_select_table { $r->print('
'.&mt('Attribute').''); - %sone=&record_sep($$records[0]); - if (defined($$records[1])) {%stwo=&record_sep($$records[1]);} - if (defined($$records[2])) {%sthree=&record_sep($$records[2]);} - # - foreach (sort keys %sone) { + + foreach my $key (sort(keys(%{ $samples->[0] }))) { $r->print(''); $i++; }
'. &mt('Field').''.&mt('Samples').'
'); - if (defined($sone{$_})) { $r->print($sone{$_}."
\n"); } - if (defined($stwo{$_})) { $r->print($stwo{$_}."
\n"); } - if (defined($sthree{$_})) { $r->print($sthree{$_}."
\n"); } + foreach my $line (0..2) { + if (defined($samples->[$line]{$key})) { + $r->print($samples->[$line]{$key}."
\n"); + } + } $r->print('