[LON-CAPA-cvs] cvs: loncom /interface loncommon.pm lonfeedback.pm

raeburn lon-capa-cvs@mail.lon-capa.org
Sun, 21 Nov 2004 04:24:50 -0000


This is a MIME encoded message

--raeburn1101011090
Content-Type: text/plain

raeburn		Sat Nov 20 23:24:50 2004 EDT

  Modified files:              
    /loncom/interface	lonfeedback.pm loncommon.pm 
  Log:
  Sections in Sort/filter display come from loncommon::get_sections().  Some small display improvements.
  
  
--raeburn1101011090
Content-Type: text/plain
Content-Disposition: attachment; filename="raeburn-20041120232450.txt"

Index: loncom/interface/lonfeedback.pm
diff -u loncom/interface/lonfeedback.pm:1.143 loncom/interface/lonfeedback.pm:1.144
--- loncom/interface/lonfeedback.pm:1.143	Sat Nov 20 15:40:51 2004
+++ loncom/interface/lonfeedback.pm	Sat Nov 20 23:24:49 2004
@@ -1,7 +1,7 @@
 # The LearningOnline Network
 # Feedback
 #
-# $Id: lonfeedback.pm,v 1.143 2004/11/20 20:40:51 raeburn Exp $
+# $Id: lonfeedback.pm,v 1.144 2004/11/21 04:24:49 raeburn Exp $
 #
 # Copyright Michigan State University Board of Trustees
 #
@@ -151,13 +151,18 @@
         %roleshash = &Apache::lonnet::dump('nohist_userroles',$ENV{'course.'.$ENV{'request.course.id'}.'.domain'},$ENV{'course.'.$ENV{'request.course.id'}.'.num'});
         foreach (keys %roleshash) {
             my ($role,$uname,$udom,$sec) = split/:/,$_;
+            if ($role =~ /^cr/) {
+                $role = 'cr';
+            }
             my ($end,$start) = split/:/,$roleshash{$_};
             my $now = time;
             my $status = 'Active';
             if (($now < $start) || ($end > 0 && $now > $end)) {
                 $status = 'Expired';
             }
-            push @{$roleinfo{$uname.':'.$udom}}, $role.':'.$sec.':'.$status;
+            if ($uname && $udom) { 
+                push @{$roleinfo{$uname.':'.$udom}}, $role.':'.$sec.':'.$status;
+            }
         }
         my ($classlist) = &Apache::loncoursedata::get_classlist(
                               $ENV{'request.course.id'},
@@ -446,13 +451,12 @@
                  }
             }
         } else {
-            $sortposts = 'ascdate';
             @showposts =  (sort { $a <=> $b } keys %alldiscussion);
         }
         my $currdepth = 0;
         my $firstidx = $alldiscussion{$showposts[0]};
         foreach (@showposts) {
-            unless (($sortposts eq 'thread') || ($sortposts eq 'ascdate' && $ENV{'environment.threadeddiscussion'}) || ($outputtarget eq 'export')) {
+            unless (($sortposts eq 'thread') || (($sortposts eq '') && ($ENV{'environment.threadeddiscussion'})) || ($outputtarget eq 'export')) {
                 $alldiscussion{$_} = $_;
             }
             unless ( ($notshown{$alldiscussion{$_}} eq '1') || ($shown{$alldiscussion{$_}} == 0) ) {
@@ -550,7 +554,7 @@
             $discussion .= <<END;
                    </font></td>
                    <td>&nbsp;</td>
-                   <td>
+                   <td align="left">
                     <font size="-1"><b><a href="$chglink">$lt{'chgt'}</a>?</font></b>
                    </td>
                   </tr>
@@ -565,13 +569,13 @@
 
                 $discussion .= '<td><font size="-1"><b>'.&mt('Sorted by').'</b>: '.$sort_types{$sortposts}.'<br />';
                 if (defined($ENV{'form.totposters'})) {
-                    $discussion .= &mt('Posts by').': ';
+                    $discussion .= &mt('Posts by').':';
                     if ($totposters > 0) {
                         foreach my $poster (@posters) {
                             $poster =~ s/:/\@/;
-                            $discussion .= $poster.',';
+                            $discussion .= ' '.$poster.',';
                         }
-                        $discussion =~ s/,//;
+                        $discussion =~ s/,$//;
                     } else {
                         $discussion .= &mt('None selected');
                     }
@@ -582,11 +586,12 @@
                         $filterchoice .= '&nbsp;&nbsp;&nbsp; ';
                     }
                     if (@rolefilter > 0) {
-                        $filterchoice .= '<i>'.&mt('roles').'</i>-&nbsp;';
+                        $filterchoice .= '<i>'.&mt('roles').'</i>-';
                         foreach (@rolefilter) {
-                            $filterchoice .= $role_types{$_}.',&nbsp;';
+                            $filterchoice .= '&nbsp;'.$role_types{$_}.',';
                         }
-                        $filterchoice .= '&nbsp;&nbsp;&nbsp; ';
+                        $filterchoice =~ s/,$//;
+                        $filterchoice .= '<br />&nbsp;&nbsp&nbsp;&nbsp;&nbsp;&nbsp;&nbsp&nbsp;';
                     }
                     if ($statusfilter) {
                         $filterchoice .= '<i>'.&mt('status').'</i>-&nbsp;'.$status_types{$statusfilter};
@@ -763,7 +768,7 @@
 	    my $origindex='0.';
             my $numoldver=0;
 	    if ($contrib{$idx.':replyto'}) {
-                if ( (($ENV{'environment.threadeddiscussion'}) && (($sortposts eq '') || ($sortposts eq 'ascdate'))) || ($sortposts eq 'thread') || ($outputtarget eq 'export')) {
+                if ( (($ENV{'environment.threadeddiscussion'}) && ($sortposts eq '')) || ($sortposts eq 'thread') || ($outputtarget eq 'export')) {
 # this is a follow-up message
 		    $original[$idx]=$original[$contrib{$idx.':replyto'}];
 		    $$depth[$idx]=$$depth[$contrib{$idx.':replyto'}]+1;
@@ -958,7 +963,7 @@
                 }
                 if ($outputtarget eq 'export' || $message) {
 		    my $thisindex=$idx;
-		    if ( (($ENV{'environment.threadeddiscussion'}) && (($sortposts eq '') || ($sortposts eq 'ascdate'))) || ($sortposts eq 'thread') || ($outputtarget eq 'export')) {
+		    if ( (($ENV{'environment.threadeddiscussion'}) && ($sortposts eq '')) || ($sortposts eq 'thread') || ($outputtarget eq 'export')) {
 			$thisindex=$origindex.substr('00'.$$replies[$$depth[$idx]],-2,2);
 		    }
 		    $$alldiscussion{$thisindex}=$idx;
@@ -1016,6 +1021,7 @@
                                             my $cc_regexp = $roleregexp.':[^:]*:'.$statusregexp;
                                             if ($role =~ /$cc_regexp/) {
                                                 $$shown{$idx} = 1;
+                                                last;
                                             }
                                         } elsif ($role =~ /^$rolematch$/) {
                                             $$shown{$idx} = 1;
@@ -1776,30 +1782,13 @@
     my $section_sel = '';
     my $numsections = 0;
     my $numvisible = 5;
-    my ($classlist) = &Apache::loncoursedata::get_classlist(
-                              $ENV{'request.course.id'},
-                              $ENV{'course.'.$ENV{'request.course.id'}.'.domain'},
-                              $ENV{'course.'.$ENV{'request.course.id'}.'.num'});
-                                                                                   
-    my $sec_index = &Apache::loncoursedata::CL_SECTION();
-    my $status_index = &Apache::loncoursedata::CL_STATUS();
     my %sectioncount = ();
-    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} ++;
-            }
-        }
-    }
-                                                                                   
-    if ($ENV{'request.course.sec'} !~ /^\s*$/) {
-        @sections = ($ENV{'request.course.sec'});
-        $numvisible = 1;
+
+    $numsections = &Apache::loncommon::get_sections($ENV{'course.'.$ENV{'request.course.id'}.'.domain'},$ENV{'course.'.$ENV{'request.course.id'}.'.num'},\%sectioncount);
+
+    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
@@ -1840,6 +1829,30 @@
 <head>
 <title>$lt{'diso'}</title>
 <meta http-equiv="pragma" content="no-cache" />
+<script type="text/javascript">
+function verifyFilter() {
+    var rolenum = 0
+    for (var i=0; i<document.modifyshown.rolefilter.length; i++) {
+        if (document.modifyshown.rolefilter.options[i].selected == true) {
+            rolenum ++
+        }
+    }
+    if (rolenum == 0) {
+        document.modifyshown.rolefilter.options[0].selected = true
+    }
+
+    var secnum = 0
+    for (var i=0; i<document.modifyshown.sectionpick.length; i++) {
+        if (document.modifyshown.sectionpick.options[i].selected == true) {
+            secnum ++
+        }
+    }
+    if (secnum == 0) {
+        document.modifyshown.sectionpick.options[0].selected = true
+    }
+    document.modifyshown.submit();
+}
+</script>
 </head>
 $bodytag
 <form name="modifyshown" method="post" action="/adm/feedback">
@@ -1860,7 +1873,7 @@
  <tr>
   <td align="center">
    <select name="sortposts">
-    <option value="ascdate" />$sort_types{'ascdate'}
+    <option value="ascdate" selected="selected" />$sort_types{'ascdate'}
     <option value="descdate" />$sort_types{'descdate'}
     <option value="thread" />$sort_types{'thread'}
     <option value="subject" />$sort_types{'subject'}
@@ -1871,7 +1884,7 @@
   <td>&nbsp;</td>
   <td align="center">
    <select name="statusfilter">
-    <option value="all" />$status_types{'all'}
+    <option value="all" selected="selected" />$status_types{'all'}
     <option value="Active" />$status_types{'Active'}
     <option value="Expired" />$status_types{'Expired'}
    </select>
@@ -1903,7 +1916,7 @@
 <br />
 <input type="hidden" name="previous" value="$previous" />
 <input type="hidden" name="applysort" value="$symb" />
-<input type="button" name="sub" value="Store Changes" onClick="javascript:document.modifyshown.submit()" />
+<input type="button" name="sub" value="Store Changes" onClick="verifyFilter()" />
 <br />
 <br />
 </form>
Index: loncom/interface/loncommon.pm
diff -u loncom/interface/loncommon.pm:1.232 loncom/interface/loncommon.pm:1.233
--- loncom/interface/loncommon.pm:1.232	Fri Nov 19 14:31:51 2004
+++ loncom/interface/loncommon.pm	Sat Nov 20 23:24:49 2004
@@ -1,7 +1,7 @@
 # The LearningOnline Network with CAPA
 # a pile of common routines
 #
-# $Id: loncommon.pm,v 1.232 2004/11/19 19:31:51 albertel Exp $
+# $Id: loncommon.pm,v 1.233 2004/11/21 04:24:49 raeburn Exp $
 #
 # Copyright Michigan State University Board of Trustees
 #
@@ -2683,6 +2683,76 @@
 
 ###############################################
 
+=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;
 

--raeburn1101011090--