[LON-CAPA-cvs] cvs: loncom /homework bridgetask.pm /interface loncommon.pm loncoursegroups.pm loncreateuser.pm lonfeedback.pm lonparmset.pm lonpickcourse.pm

albertel lon-capa-cvs@mail.lon-capa.org
Tue, 09 May 2006 15:09:28 -0000


This is a MIME encoded message

--albertel1147187368
Content-Type: text/plain

albertel		Tue May  9 11:09:28 2006 EDT

  Modified files:              
    /loncom/homework	bridgetask.pm 
    /loncom/interface	loncommon.pm loncoursegroups.pm loncreateuser.pm 
                     	lonfeedback.pm lonparmset.pm lonpickcourse.pm 
  Log:
  - morphing get_sections so it's easier to use
  
  
--albertel1147187368
Content-Type: text/plain
Content-Disposition: attachment; filename="albertel-20060509110928.txt"

Index: loncom/homework/bridgetask.pm
diff -u loncom/homework/bridgetask.pm:1.143 loncom/homework/bridgetask.pm:1.144
--- loncom/homework/bridgetask.pm:1.143	Thu Apr 20 03:00:20 2006
+++ loncom/homework/bridgetask.pm	Tue May  9 11:09:21 2006
@@ -1,7 +1,7 @@
 # The LearningOnline Network with CAPA 
 # definition of tags that give a structure to a document
 #
-# $Id: bridgetask.pm,v 1.143 2006/04/20 07:00:20 albertel Exp $
+# $Id: bridgetask.pm,v 1.144 2006/05/09 15:09:21 albertel Exp $
 #
 # Copyright Michigan State University Board of Trustees
 #
@@ -170,8 +170,8 @@
     my (undef,$cid)=&Apache::lonxml::whichuser();
     my $cnum=$env{'course.'.$cid.'.num'};
     my $cdom=$env{'course.'.$cid.'.domain'};
-    my %sections;
-    my $numsections=&Apache::loncommon::get_sections($cdom,$cnum,\%sections);
+    my %sections = &Apache::loncommon::get_sections($cdom,$cnum);
+
     my $size=5;
     if (scalar(keys(%sections)) < 3) {
 	$size=scalar(keys(%sections))+2;
@@ -214,7 +214,7 @@
 						   'gradingdomain');
 	$result.=&Apache::loncommon::studentbrowser_javascript();
 	$result.= '</p>';
-  }
+    }
     return $result;
 }
 
Index: loncom/interface/loncommon.pm
diff -u loncom/interface/loncommon.pm:1.365 loncom/interface/loncommon.pm:1.366
--- loncom/interface/loncommon.pm:1.365	Tue May  9 10:38:09 2006
+++ loncom/interface/loncommon.pm	Tue May  9 11:09:27 2006
@@ -1,7 +1,7 @@
 # The LearningOnline Network with CAPA
 # a pile of common routines
 #
-# $Id: loncommon.pm,v 1.365 2006/05/09 14:38:09 albertel Exp $
+# $Id: loncommon.pm,v 1.366 2006/05/09 15:09:27 albertel Exp $
 #
 # Copyright Michigan State University Board of Trustees
 #
@@ -3751,20 +3751,27 @@
 
 ###############################################
 sub get_sections {
-    my ($cdom,$cnum,$sectioncount,$possible_roles) = @_;
-    if (!($cdom && $cnum)) { return 0; }
-    my $numsections = 0;
+    my ($cdom,$cnum,$possible_roles) = @_;
+    if (!defined($cdom) || !defined($cnum)) {
+        my $cid =  $env{'request.course.id'};
+
+	return if (!defined($cid));
+
+        $cdom = $env{'course.'.$cid.'.domain'};
+        $cnum = $env{'course.'.$cid.'.num'};
+    }
+
+    my %sectioncount;
 
-    if (!defined($possible_roles) || (grep/^st$/,@$possible_roles)) {
+    if (!defined($possible_roles) || (grep(/^st$/,@$possible_roles))) {
 	my ($classlist) = &Apache::loncoursedata::get_classlist($cdom,$cnum);
 	my $sec_index = &Apache::loncoursedata::CL_SECTION();
 	my $status_index = &Apache::loncoursedata::CL_STATUS();
-	while (my ($student,$data) = each %$classlist) {
+	while (my ($student,$data) = each(%$classlist)) {
 	    my ($section,$status) = ($data->[$sec_index],
 				     $data->[$status_index]);
 	    unless ($section eq '-1' || $section =~ /^\s*$/) {
-		if (!defined($$sectioncount{$section})) { $numsections++; }
-		$$sectioncount{$section}++;
+		$sectioncount{$section}++;
 	    }
 	}
     }
@@ -3780,10 +3787,9 @@
 	}
 	if ($user =~ /^$role:[^:]*:[^:]*:(\w+)/) { $section=$1; }
 	if (!defined($section) || $section eq '-1') { next; }
-	if (!defined($$sectioncount{$section})) { $numsections++; } 
-	$$sectioncount{$section}++;
+	$sectioncount{$section}++;
     }
-    return $numsections;
+    return %sectioncount;
 }
 
 ###############################################
Index: loncom/interface/loncoursegroups.pm
diff -u loncom/interface/loncoursegroups.pm:1.15 loncom/interface/loncoursegroups.pm:1.16
--- loncom/interface/loncoursegroups.pm:1.15	Tue May  9 10:38:09 2006
+++ loncom/interface/loncoursegroups.pm	Tue May  9 11:09:27 2006
@@ -454,9 +454,8 @@
         (($state eq 'pick_name') || ($state eq 'pick_privs'))) ||
        (($action eq 'modify') && (($state eq 'change_settings') ||
                                   ($state eq 'add_members')))) {
-        my $numsections = &Apache::loncommon::get_sections($cdom,$cnum,
-                                                           \%sectioncount);
-        if ($numsections > 0) {
+        %sectioncount = &Apache::loncommon::get_sections($cdom,$cnum);
+        if (%sectioncount) {
             $elements{'create'}{'pick_name'}{'sectionpick'} = 'selectbox';
             $elements{'modify'}{'change_mapping'}{'sectionpick'} = 'selectbox';
             $elements{'modify'}{'add_members'}{'sectionpick'} = 'selectbox';
@@ -3410,8 +3409,7 @@
 
 sub validate_groupname {
     my ($groupname,$action,$cdom,$cnum) = @_;
-    my %sectioncount;
-    my $numsec=&Apache::loncommon::get_sections($cdom,$cnum,\%sectioncount);
+    my %sectioncount = &Apache::loncommon::get_sections($cdom,$cnum);
     my %curr_groups = &Apache::loncommon::coursegroups($cdom,$cnum);
 
     my %lt = &Apache::lonlocal::texthash (
@@ -3436,12 +3434,9 @@
         $earlyout = $exitmsg.$lt{'isno'}.'<br />'.$lt{'gnmo'};
         return $earlyout;
     }
-    if ($numsec) {
-        if (exists($sectioncount{$groupname})) {
-            $earlyout = $exitmsg.$lt{'cnnb'}.&mt('a section').$lt{'inth'}.
-                        '<br />'.$lt{'grna'};
-            return $earlyout;
-        }
+    if (exists($sectioncount{$groupname})) {
+	return $exitmsg.$lt{'cnnb'}.&mt('a section').$lt{'inth'}.
+	    '<br />'.$lt{'grna'};
     }
     if ($action eq 'create' 
 	&& exists($curr_groups{$groupname})) {
Index: loncom/interface/loncreateuser.pm
diff -u loncom/interface/loncreateuser.pm:1.114 loncom/interface/loncreateuser.pm:1.115
--- loncom/interface/loncreateuser.pm:1.114	Tue May  9 10:38:10 2006
+++ loncom/interface/loncreateuser.pm	Tue May  9 11:09:27 2006
@@ -1,7 +1,7 @@
 # The LearningOnline Network with CAPA
 # Create a user
 #
-# $Id: loncreateuser.pm,v 1.114 2006/05/09 14:38:10 albertel Exp $
+# $Id: loncreateuser.pm,v 1.115 2006/05/09 15:09:27 albertel Exp $
 #
 # Copyright Michigan State University Board of Trustees
 #
@@ -974,7 +974,6 @@
 #
 # Course level
 #
-    my $num_sections;
 
     if ($env{'request.role'} =~ m-^dc\./(\w+)/$-) {
         $r->print(&course_level_dc($1));
@@ -1761,11 +1760,11 @@
 	$bgcol=~s/[^7-9a-e]//g;
 	$bgcol=substr($bgcol.$bgcol.$bgcol.'ffffff',2,6);
 	my ($domain,$cnum)=split(/\//,$thiscourse);
-        my %sections_count = ();
-        my $num_sections = 0;
+        my %sections_count;
         if (defined($env{'request.course.id'})) {
             if ($env{'request.course.id'} eq $domain.'_'.$cnum) {
-                $num_sections = &Apache::loncommon::get_sections($domain,$cnum,\%sections_count);
+                %sections_count = 
+		    &Apache::loncommon::get_sections($domain,$cnum);
             }
         }
 	foreach  ('st','ta','ep','ad','in','cc') {
@@ -1778,8 +1777,8 @@
 <td>$area<br />Domain: $domain</td>
 ENDEXTENT
 	        if ($_ ne 'cc') {
-                    if ($num_sections > 0) {
-                        my $currsec = &course_sections($num_sections,\%sections_count,$protectedcourse.'_'.$_);
+                    if (%sections_count) {
+                        my $currsec = &course_sections(\%sections_count,$protectedcourse.'_'.$_);
                         $table .= 
                     '<td><table border="0" cellspacing="0" cellpadding="0">'.
                      '<tr><td valign="top">'.$lt{'exs'}.'<br />'.
@@ -1819,8 +1818,8 @@
 <td>$plrole</td>
 <td>$area</td>
 END
-                if ($num_sections > 0) {
-                    my $currsec = &course_sections($num_sections,\%sections_count,$customrole);
+                if (%sections_count) {
+                    my $currsec = &course_sections(\%sections_count,$customrole);
                     $table.=
                    '<td><table border="0" cellspacing="0" cellpadding="0">'.
                    '<tr><td valign="top">'.$lt{'exs'}.'<br />'.
@@ -1859,10 +1858,10 @@
 }
 
 sub course_sections {
-    my ($num_sections,$sections_count,$role) = @_;
+    my ($sections_count,$role) = @_;
     my $output = '';
     my @sections = (sort {$a <=> $b} keys %{$sections_count});
-    if ($num_sections == 1) {
+    if (scalar(@sections) == 1) {
         $output = '<select name="currsec_'.$role.'" >'."\n".
                   '  <option value="">Select</option>'."\n".
                   '  <option value="">No section</option>'."\n".
@@ -1870,7 +1869,7 @@
     } else {
         $output = '<select name="currsec_'.$role.'" ';
         my $multiple = 4;
-        if ($num_sections <4) { $multiple = $num_sections; }
+        if (scalar(@sections) < 4) { $multiple = scalar(@sections); }
         $output .= '"multiple" size="'.$multiple.'">'."\n";
         foreach (@sections) {
             $output .= '<option value="'.$_.'">'.$_."</option>\n";
Index: loncom/interface/lonfeedback.pm
diff -u loncom/interface/lonfeedback.pm:1.196 loncom/interface/lonfeedback.pm:1.197
--- loncom/interface/lonfeedback.pm:1.196	Mon May  8 18:12:29 2006
+++ loncom/interface/lonfeedback.pm	Tue May  9 11:09:27 2006
@@ -1,7 +1,7 @@
 # The LearningOnline Network
 # Feedback
 #
-# $Id: lonfeedback.pm,v 1.196 2006/05/08 22:12:29 albertel Exp $
+# $Id: lonfeedback.pm,v 1.197 2006/05/09 15:09:27 albertel Exp $
 #
 # Copyright Michigan State University Board of Trustees
 #
@@ -1817,23 +1817,21 @@
     $r->send_http_header;
 
     &Apache::lonenc::check_encrypt(\$symb);
-    my @sections = ();
+    my @sections;
     my $section_sel = '';
-    my $numsections = 0;
     my $numvisible = 5;
-    my %sectioncount = ();
-
-    $numsections = &Apache::loncommon::get_sections($env{'course.'.$env{'request.course.id'}.'.domain'},$env{'course.'.$env{'request.course.id'}.'.num'},\%sectioncount);
+    my %sectioncount = &Apache::loncommon::get_sections();
 
     if ($env{'request.course.sec'} !~ /^\s*$/) {  #Restrict section choice to current section 
         @sections = ('all',$env{'request.course.sec'});
         $numvisible = 2;
     } else {
         @sections = sort {$a cmp $b} keys(%sectioncount);
-        unshift(@sections,'all'); # Put 'all' at the front of the list
-        if ($numsections < 4) {
-            $numvisible = $numsections + 1;
+        if (scalar(@sections) < 4) {
+            $numvisible = scalar(@sections) + 1;
         }
+        unshift(@sections,'all'); # Put 'all' at the front of the list
+
     }
     foreach (@sections) {
         $section_sel .= "  <option value=\"$_\" />$_\n";
Index: loncom/interface/lonparmset.pm
diff -u loncom/interface/lonparmset.pm:1.299 loncom/interface/lonparmset.pm:1.300
--- loncom/interface/lonparmset.pm:1.299	Tue May  9 10:38:10 2006
+++ loncom/interface/lonparmset.pm	Tue May  9 11:09:27 2006
@@ -1,7 +1,7 @@
 # The LearningOnline Network with CAPA
 # Handler to set parameters for assessments
 #
-# $Id: lonparmset.pm,v 1.299 2006/05/09 14:38:10 albertel Exp $
+# $Id: lonparmset.pm,v 1.300 2006/05/09 15:09:27 albertel Exp $
 #
 # Copyright Michigan State University Board of Trustees
 #
@@ -1117,16 +1117,13 @@
 		    'oi'    => "or ID",
 		    'ad'    => "at Domain"
 				       );
-    my %sectionhash=();
     my $sections='';
-    my $numsec = &Apache::loncommon::get_sections(
-                 $env{'course.'.$env{'request.course.id'}.'.domain'},
-                 $env{'course.'.$env{'request.course.id'}.'.num'},
-					 \%sectionhash);
+    my %sectionhash = &Apache::loncommon::get_sections();
+
     my $groups;
     my %grouphash = &Apache::loncommon::coursegroups();
 
-    if ($numsec > 0) {
+    if (%sectionhash) {
         $sections=$lt{'se'}.': <select name="csec"';
         if (%grouphash && $parmlev ne 'full') {
             $sections .= qq| onchange="group_or_section('csec')" |;
@@ -1139,7 +1136,7 @@
         }
         $sections.='</select>';
     }
-    if ($numsec && %grouphash && $parmlev ne 'full') {
+    if (%sectionhash && %grouphash && $parmlev ne 'full') {
         $sections .= '&nbsp;or&nbsp;';
         $sections .= qq|
 <script type="text/javascript">
@@ -1168,7 +1165,7 @@
 
     if (%grouphash) {
         $groups=$lt{'gr'}.': <select name="cgroup"';
-        if ($numsec && $env{'form.action'} eq 'settable') {
+        if (%sectionhash && $env{'form.action'} eq 'settable') {
             $groups .= qq| onchange="group_or_section('cgroup')" |;
         }
         $groups .= '>';
@@ -1245,26 +1242,21 @@
 
 sub sectionmenu {
     my ($r,$selectedsections)=@_;
-    my %sectionhash=();
-    my $sections='';
-    my $numsec = &Apache::loncommon::get_sections(
-                 $env{'course.'.$env{'request.course.id'}.'.domain'},
-                 $env{'course.'.$env{'request.course.id'}.'.num'},
-					 \%sectionhash);
-    if ($numsec) {
-	$r->print('<select name="Section" multiple="true" size="8" >');
-	foreach my $s ('all',sort keys %sectionhash) {
-	    $r->print('    <option value="'.$s.'"');
-	    foreach (@{$selectedsections}) {
-		if ($s eq $_) {
-		    $r->print(' selected');
-		    last;
-		}
+    my %sectionhash = &Apache::loncommon::get_sections();
+    return if (!%sectionhash);
+
+    $r->print('<select name="Section" multiple="true" size="8" >');
+    foreach my $s ('all',sort keys %sectionhash) {
+	$r->print('    <option value="'.$s.'"');
+	foreach (@{$selectedsections}) {
+	    if ($s eq $_) {
+		$r->print(' selected');
+		last;
 	    }
-	    $r->print('>'.$s."</option>\n");
 	}
-        $r->print("</select>\n");
-   }
+	$r->print('>'.$s."</option>\n");
+    }
+    $r->print("</select>\n");
 }
 
 sub groupmenu {
Index: loncom/interface/lonpickcourse.pm
diff -u loncom/interface/lonpickcourse.pm:1.44 loncom/interface/lonpickcourse.pm:1.45
--- loncom/interface/lonpickcourse.pm:1.44	Tue May  9 10:38:10 2006
+++ loncom/interface/lonpickcourse.pm	Tue May  9 11:09:27 2006
@@ -1,7 +1,7 @@
 # The LearningOnline Network
 # Pick a course
 #
-# $Id: lonpickcourse.pm,v 1.44 2006/05/09 14:38:10 albertel Exp $
+# $Id: lonpickcourse.pm,v 1.45 2006/05/09 15:09:27 albertel Exp $
 #
 # Copyright Michigan State University Board of Trustees
 #
@@ -101,13 +101,11 @@
     if ($env{'form.form'} eq 'cu' && $env{'form.pickedcourse'}) {
         $loaditem{'onload'} ="setSections()";
         my ($cdom,$cnum) = split/_/,$env{'form.pickedcourse'};
-        my %sections_count = ();
-        $num_sections = &Apache::loncommon::get_sections($cdom,$cnum,\%sections_count);
-        my @sections = ();
-        if ($num_sections > 0) {
-            @sections = (sort {$a <=> $b} keys(%sections_count));
-            $seclist = join('","',@sections);
-        }
+
+        my %sections_count = &Apache::loncommon::get_sections($cdom,$cnum);
+        my @sections =  (sort {$a <=> $b} keys(%sections_count));
+	$seclist = join('","',@sections);
+
         my %curr_groups = &Apache::loncommon::coursegroups($cdom,$cnum);
 	$groupslist = join(',',sort(keys(%curr_groups)));
     }

--albertel1147187368--