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

raeburn raeburn at source.lon-capa.org
Thu May 16 16:03:51 EDT 2013


raeburn		Thu May 16 20:03:51 2013 EDT

  Modified files:              
    /loncom/interface	lonsyllabus.pm 
  Log:
  - Bug 6185.
  - Implement ability to control whih course personnel are displayed on 
    Syllabus page (standard template).
  
  
-------------- next part --------------
Index: loncom/interface/lonsyllabus.pm
diff -u loncom/interface/lonsyllabus.pm:1.126 loncom/interface/lonsyllabus.pm:1.127
--- loncom/interface/lonsyllabus.pm:1.126	Wed May 15 18:45:29 2013
+++ loncom/interface/lonsyllabus.pm	Thu May 16 20:03:51 2013
@@ -1,7 +1,7 @@
 # The LearningOnline Network
 # Syllabus
 #
-# $Id: lonsyllabus.pm,v 1.126 2013/05/15 18:45:29 raeburn Exp $
+# $Id: lonsyllabus.pm,v 1.127 2013/05/16 20:03:51 raeburn Exp $
 #
 # Copyright Michigan State University Board of Trustees
 #
@@ -332,18 +332,18 @@
             }
             &Apache::lontemplate::print_start_template($r,&mt('Personnel'),'LC_Box',
                                                        'box_000_showpeople',$display);
-            $r->print(&get_personnel($r,$target,$cdom,$cnum,$allowed));
+            $r->print(&get_personnel($r,$target,$cdom,$cnum,$allowed,$crstype,\%syllabus));
             &Apache::lontemplate::print_end_template($r);
         } else {
             unless ($hidepersonnel) {
                 &Apache::lontemplate::print_start_template($r,&mt('Personnel'),'LC_Box');
-                $r->print(&get_personnel($r,$target,$cdom,$cnum,$allowed));  
+                $r->print(&get_personnel($r,$target,$cdom,$cnum,$allowed,$crstype,\%syllabus));  
                 &Apache::lontemplate::print_end_template($r);
             }
         }
     } else {
         unless ($hidepersonnel) {
-            $r->print(&get_personnel($r,$target,$cdom,$cnum,$allowed));
+            $r->print(&get_personnel($r,$target,$cdom,$cnum,$allowed,$crstype,%syllabus));
         }
     }
 # -------------------------------------------------------------- Announcements?
@@ -940,49 +940,121 @@
 }
 
 sub get_personnel {
-    my ($r,$target,$cdom,$cnum,$allowed) = @_;
+    my ($r,$target,$cdom,$cnum,$allowed,$crstype,$syllabus) = @_;
+    my (%hiddenroles,%hiddenusers);
+    if (ref($syllabus) eq 'HASH') {
+        if (ref($syllabus->{'personnel'}) eq 'HASH') {
+            if ($syllabus->{'personnel'}{'hiderole'}) {
+                map { $hiddenroles{$_} = 1; } split(/,/,$syllabus->{'personnel'}{'hiderole'});
+            }
+            if ($syllabus->{'personnel'}{'hideuser'}) {
+                map { $hiddenusers{$_} = 1; } split(/,/,$syllabus->{'personnel'}{'hideuser'});
+            }
+        }
+    }
     my $output;
-    my %coursepersonnel=&Apache::lonnet::get_course_adv_roles($cdom.'/'.$cnum);
+    my %coursepersonnel=&Apache::lonnet::get_course_adv_roles($cdom.'/'.$cnum,1);
     if ($target ne 'tex') {
-        $r->print(&Apache::lonhtmlcommon::start_pick_box());
+        if ($allowed) {
+            $r->print(&Apache::loncommon::start_data_table().
+                      &Apache::loncommon::start_data_table_header_row().
+                      '<th>'.&mt('Role hidden?').'</th><th>'.&mt('Role').'</th>'.
+                      '<th>'.&mt('Personnel (hidden if checked)').'</th>'.
+                      &Apache::loncommon::end_data_table_header_row());
+        } else {
+            $r->print(&Apache::lonhtmlcommon::start_pick_box());
+        }
     } else {
         $r->print('\begin{tabular}{|p{0.45\textwidth}|p{0.45\textwidth}|}\hline');
     }
     my @personnel=sort(keys(%coursepersonnel));
     my $lastpers=$personnel[$#personnel];
     foreach my $element (@personnel) {
+        unless ($allowed) {
+            next if ($hiddenroles{$element}) 
+        }
+        my ($role,$sec);
+        if ($element =~ /:/) {
+            ($role,$sec) = split(/:/,$element);
+        } else {
+            $role = $element;
+        }
+        my $roletext = &Apache::lonnet::plaintext($role,$crstype);
+        if ($sec) {
+            $roletext .=' ('.&Apache::lonlocal::mt('Section [_1]',$sec).')';
+        }
         if ($target ne 'tex') {
-            $r->print(&Apache::lonhtmlcommon::row_title($element));
+            if ($allowed) {
+                my $checked;
+                if ($hiddenroles{$element}) {
+                    $checked = ' checked="checked"';
+                }
+                $r->print(&Apache::loncommon::start_data_table_row().
+                          '<td>'.
+                          '<input type="checkbox" name="hiderole" value="'.$element.'" '.
+                          $checked.' />'.
+                          '</td><td>'.$roletext.'</td><td>');
+            } else {
+                $r->print(&Apache::lonhtmlcommon::row_title($roletext));
+            }
         } else {
-            $r->print(' '.&Apache::lonxml::xmlparse($r,'tex',$element).' & ');
+            $r->print(' '.&Apache::lonxml::xmlparse($r,'tex',$roletext).' & ');
         }
         my @coursepersonlist;
         foreach my $user (split(/\,/,$coursepersonnel{$element})) {
             my ($puname,$pudom)=split(/\:/,$user);
             if ($target ne 'tex') {
                 my $courseperson = &Apache::loncommon::plainname($puname,$pudom);
-                if (($env{'user.name'} eq '') || ($env{'user.name'} eq 'public') ||
-                    ($env{'user.domain'} eq '') || ($env{'user.domain'} eq 'public')) {
-                    push(@coursepersonlist,$courseperson);
+                my $checked;
+                if ($hiddenusers{$element.'&'.$puname.':'.$pudom}) {
+                    $checked = ' checked="checked"';
+                }
+                if ($allowed) {
+                    my $item = '<span class="LC_nobreak"><label>'.
+                               '<input type="checkbox" name="hideuser" value="'.$element.'&'.$puname.':'.$pudom.'"'.$checked.' />'.
+                               &Apache::loncommon::aboutmewrapper($courseperson
+,
+                                               $puname,$pudom).
+                               '</label>'.(' 'x2).'</span> ';
+                    push(@coursepersonlist,$item);
+
                 } else {
-                    push(@coursepersonlist,&Apache::loncommon::aboutmewrapper($courseperson,
-                              $puname,$pudom));
+                    next if ($hiddenusers{$element.'&'.$puname.':'.$pudom});
+                    if (($env{'user.name'} eq '') || ($env{'user.name'} eq 'public') ||
+                        ($env{'user.domain'} eq '') || ($env{'user.domain'} eq 'public')) {
+                        push(@coursepersonlist,$courseperson);
+                    } else {
+                        push(@coursepersonlist,&Apache::loncommon::aboutmewrapper($courseperson,
+                                               $puname,$pudom));
+                    }
                 }
             } else {
                 push(@coursepersonlist,&Apache::loncommon::plainname($puname,
                               $pudom).' ');
             }
         }
-        $r->print(join(", ", at coursepersonlist));
+        if ($allowed) {
+            $r->print(join('', at coursepersonlist));
+        } else {
+            $r->print(join(', ', at coursepersonlist));
+        }
         if ($target ne 'tex') {
-            my $lastclose=$element eq $lastpers?1:0;
-            $r->print(&Apache::lonhtmlcommon::row_closure($lastclose));
+            if ($allowed) {
+                $r->print(&Apache::loncommon::end_data_table_row());
+            } else {
+                my $lastclose=$element eq $lastpers?1:0;
+                $r->print(&Apache::lonhtmlcommon::row_closure($lastclose));
+            }
         } else {
             $r->print('\\\\ \hline');
         }
     }
     if ($target ne 'tex') {
-        $r->print(&Apache::lonhtmlcommon::end_pick_box());
+        if ($allowed) {
+            $r->print(&Apache::loncommon::end_data_table());
+        } else {
+            $r->print(&Apache::lonhtmlcommon::end_pick_box());
+        }
     } else {
         $r->print('\end{tabular}\\\\');
     }
@@ -1030,6 +1102,33 @@
                     my ($prefix) = split(/_/,$field);
                     $syllabus->{'uploaded.fields'} .= $prefix.',';
                 }
+                if ($field eq '000_showpeople') {
+                    my @hideusers = &Apache::loncommon::get_env_multiple('form.hideuser');
+                    my @hideroles = &Apache::loncommon::get_env_multiple('form.hiderole');
+                    my %coursepersonnel=&Apache::lonnet::get_course_adv_roles($cdom.'/'.$cnum,1);
+                    my %personnel;
+                    foreach my $key (keys(%coursepersonnel)) {
+                        map { $personnel{$key}{$_} = 1; } split(/,/,$coursepersonnel{$key});
+                    }
+                    %{$syllabus->{'personnel'}} = ();
+                    $syllabus->{'personnel'}{'hideuser'} = '';
+                    $syllabus->{'personnel'}{'hiderole'} = '';
+                    foreach my $role (@hideroles) {
+                        if (exists($personnel{$role})) {
+                            $syllabus->{'personnel'}{'hiderole'} .= $role.',';
+                        }
+                    }
+                    foreach my $item (@hideusers) {
+                        my ($role,$user) = split(/\&/,$item);
+                        if (ref($personnel{$role}) eq 'HASH') {
+                            if ($personnel{$role}{$user}) {
+                                $syllabus->{'personnel'}{'hideuser'} .= $item.',';
+                            }
+                        }
+                    }
+                    $syllabus->{'personnel'}{'hideuser'} =~ s/,$//;
+                    $syllabus->{'personnel'}{'hiderole'} =~ s/,$//;
+                }
             }
             $syllabus->{'uploaded.fields'} =~ s/,$//;
         }


More information about the LON-CAPA-cvs mailing list