--- loncom/interface/loncommon.pm 2004/11/13 21:06:27 1.231
+++ loncom/interface/loncommon.pm 2004/11/21 04:24:49 1.233
@@ -1,7 +1,7 @@
# The LearningOnline Network with CAPA
# a pile of common routines
#
-# $Id: loncommon.pm,v 1.231 2004/11/13 21:06:27 albertel Exp $
+# $Id: loncommon.pm,v 1.233 2004/11/21 04:24:49 raeburn Exp $
#
# Copyright Michigan State University Board of Trustees
#
@@ -2614,7 +2614,6 @@ ENDROLE
if ($thisdisfn!~m|/$|) { $forcereg=1; }
}
- &Apache::lonnet::logthis("hrrm");
return $bodytag.&Apache::lonmenu::menubuttons($forcereg,'web',
$forcereg).
'
'.$titleinfo.' | '.$roleinfo.'
';
@@ -2684,6 +2683,76 @@ sub get_users_function {
###############################################
+=pod
+
+=item get_sections
+
+Determines all the sections for a course including
+sections with students and sections containing other roles.
+Incoming parameters: domain, course number, reference to
+section hash (keys to be section/group IDs), reference to
+array containing roles for which sections should be gathered
+(optional). If the fourth argument is undefined, sections
+are gathered for any role.
+
+Returns number of sections.
+
+=cut
+
+###############################################
+sub get_sections {
+ my ($cdom,$cnum,$sectioncount,$possible_roles) = @_;
+ my $cid = $cdom.'_'.$cnum;
+ my $numsections = 0;
+ if ($cdom && $cnum) {
+ if (!defined($possible_roles) || (grep/^st$/,@$possible_roles)) {
+ my ($classlist) = &Apache::loncoursedata::get_classlist($cid,$cdom,$cnum);
+ my $sec_index = &Apache::loncoursedata::CL_SECTION();
+ my $status_index = &Apache::loncoursedata::CL_STATUS();
+ while (my ($student,$data) = each %$classlist) {
+ my ($section,$status) = ($data->[$sec_index],
+ $data->[$status_index]);
+ unless ($section eq '' || $section =~ /^\s*$/) {
+ if (!defined($$sectioncount{$section})) {
+ $$sectioncount{$section} = 1;
+ $numsections ++;
+ } else {
+ $$sectioncount{$section} ++;
+ }
+ }
+ }
+ }
+ my %courseroles = &Apache::lonnet::dump('nohist_userroles',$cdom,$cnum);
+ foreach my $user (sort keys %courseroles) {
+ if ($user =~ /^(\w{2})/) {
+ my $role = $1;
+ if (!defined($possible_roles) || (grep/^$role$/,@$possible_roles)) {
+ if ($role eq 'cr') {
+ if ($user =~ m-^$role/[^/]*/[^/]*/[^/]*:[^:]*:[^:]*:(\w+)-) {
+ if (!defined($$sectioncount{$1})) {
+ $$sectioncount{$1} = 1;
+ $numsections ++;
+ } else {
+ $$sectioncount{$1} ++;
+ }
+ }
+ }
+ if ($user =~ /^$role:[^:]*:[^:]*:(\w+)/) {
+ if (!defined($$sectioncount{$1})) {
+ $$sectioncount{$1} = 1;
+ $numsections ++;
+ } else {
+ $$sectioncount{$1} ++;
+ }
+ }
+ }
+ }
+ }
+ }
+ return $numsections;
+}
+
+
sub get_posted_cgi {
my $r=shift;