Diff for /loncom/interface/lonviewclasslist.pm between versions 1.9 and 1.21

version 1.9, 2007/09/07 00:09:07 version 1.21, 2023/11/05 19:59:54
Line 34  use strict; Line 34  use strict;
 use Apache::loncoursedata();  use Apache::loncoursedata();
 use Apache::loncommon();  use Apache::loncommon();
 use Apache::lonhtmlcommon();  use Apache::lonhtmlcommon();
   use Apache::courseprefs();
 use Apache::Constants qw(:common :http REDIRECT);  use Apache::Constants qw(:common :http REDIRECT);
 use Apache::lonlocal;  use Apache::lonlocal;
 use Apache::lonnet;  use Apache::lonnet;
Line 60  sub handler { Line 61  sub handler {
         $r->send_http_header;          $r->send_http_header;
         return OK;          return OK;
     }      }
 #    &Apache::loncommon::get_unprocessed_cgi($ENV{'QUERY_STRING'},      &Apache::loncommon::get_unprocessed_cgi($ENV{'QUERY_STRING'},
 #                                            ['action','state']);                                   ['register','forceedit','action',
     &Apache::lonhtmlcommon::clear_breadcrumbs();                                    'symb','todocs','only_body']);
     &Apache::lonhtmlcommon::add_breadcrumb  
         ({href=>"/adm/viewclasslist",  
           text=>"View Classlist",  
           faq=>9,bug=>'Instructor Interface',});  
     #  Needs to be in a course  
     if (! ($env{'request.course.fn'})) {      if (! ($env{'request.course.fn'})) {
         $env{'user.error.msg'}=          $env{'user.error.msg'}=
             "/adm/viewclasslist:not in course role";              "/adm/viewclasslist:not in course role";
Line 76  sub handler { Line 72  sub handler {
     &Apache::loncommon::content_type($r,'text/html');      &Apache::loncommon::content_type($r,'text/html');
     $r->send_http_header;      $r->send_http_header;
     #      #
     my $start_page = &Apache::loncommon::start_page('Classlist');      my $start_page;
     my $breadcrumbs= &Apache::lonhtmlcommon::breadcrumbs(undef,      if ($env{'form.register'}) {
  'Enrollment Manager');          $start_page = &Apache::loncommon::start_page('Classlist',undef,
                                {'force_register' => $env{'form.register'}});
       } else {
           my $args = {};
           if ($env{'form.only_body'}) {
               $args->{'only_body'} = 1;
           } else {
               my $brcrum = [{'href' => 'adm/viewclasslist',
                              'text' => 'View Classlist'},];
               $args->{'bread_crumbs'} = $brcrum;
           }
           $start_page = &Apache::loncommon::start_page('Classlist',undef,
                                                        $args);
       }
     $r->print(<<ENDHEADER);      $r->print(<<ENDHEADER);
 $start_page  $start_page
 $breadcrumbs  
 ENDHEADER  ENDHEADER
   
     # Get classlist view settings      # Get classlist view settings
     my %viewsettings = &retrieve_view_settings();      my %viewsettings = &retrieve_view_settings();
       my $crstype = &Apache::loncommon::course_type();
   
     # Print classlist      if (($env{'form.forceedit'}) || ($env{'form.action'} eq 'setconfig'))  {
     if (keys(%viewsettings) > 0) {          if (&Apache::lonnet::allowed('opa',$env{'request.course.id'})) {
         $r->print(&html_classlist($r,\%viewsettings));              my $cdom = $env{'course.'.$env{'request.course.id'}.'.domain'};
               my $cnum = $env{'course.'.$env{'request.course.id'}.'.num'};
               my $rosterprefs = &roster_prefs($crstype);
               my $allitems = {};
               if ($env{'form.action'} eq 'setconfig') {
                   my %values=&Apache::lonnet::dump('environment',$cdom,$cnum);
                   if (keys(%values) > 0) {
                       my ($numchanged,%changes,%disallowed);
                       my $prefs = {
                                       classlists => $rosterprefs,
                                   };
                       $changes{'classlists'} = {};
                       &Apache::courseprefs::process_changes($cdom,$cnum,'classlists',\%values,
                                                             $rosterprefs,
                                                             $changes{'classlists'},
                                                             $allitems,\%disallowed,$crstype);
                       my $message;
                       if (keys(%{$changes{'classlists'}}) > 0) {
                           my $actions = ['classlists'];
                           $message =
                               &Apache::courseprefs::store_changes($cdom,$cnum,$actions,
                                                                   $actions,$prefs,\%values,
                                                                   \%changes,$crstype);
                       } else {
                           if ($crstype eq 'Community') {
                               $message = &mt('No changes made to community settings.');
                           } else {
                               $message = &mt('No changes made to course settings.');
                           }
                       }
                       $r->print(&Apache::loncommon::confirmwrapper($message));
                  } else {
                       $r->print('<div class="LC_info">'.
                                 &mt('Unable to retrieve current settings.').'<br />'.
                                 &mt('No changes saved.').
                                 '</div>');
                  }
              } else {
                  my $current = {};
                  my @settings = ('student_classlist_view','student_classlist_opt_in',
                                  'student_classlist_portfiles');
                  foreach my $setting (@settings) {
                      $current->{$setting} = $env{"course.$env{'request.course.id'}.$setting"};
                  }
                  my ($output,$rowtotal) =
                      &Apache::courseprefs::print_config_box($r,$cdom,$cnum,'display',
                                                             'viewableroster',
                                                             $rosterprefs,$current,
                                                             $allitems,$crstype);
                  if ($output) {
                      $r->print('<form method="post" name="display" action="/adm/viewclasslist">'."\n".
                                '<input type="hidden" name="action" value="setconfig" />'."\n".
                                '<input type="hidden" name="register" value="'.$env{'form.register'}.'" />'."\n".
                                '<input type="hidden" name="forceedit" value="'.$env{'form.forceedit'}.'" />'."\n");
                      if ($env{'form.symb'}) {
                           $r->print('<input type="hidden" name="symb" value="'.$env{'form.symb'}.'" />'."\n");
                      }
                      if ($env{'form.symb'}) {
                           $r->print('<input type="hidden" name="todocs" value="'.$env{'form.todocs'}.'" />'."\n");
                      }
                      $r->print('<div class="LC_left_float">'.
                                $output.
                                '</div><br clear="all" />'.
                                '<input type="submit" value="'.&mt('Save').'" />'.
                                '</form>');
                  } else {
                      $r->print('<div class="LC_info">');
                      if ($crstype eq 'Community') {
                          $r->print(&mt('No member-viewable community roster settings available.'));
                      } else {
                          $r->print(&mt('No student-viewable course roster settings available.'));
                      }
                      $r->print('</div>');
                  }
              }
           } else {
               $r->print('<div class="LC_info">');
               if ($crstype eq 'Community') {
                   $r->print(&mt('You do not have rights to modify member-viewable community roster settings.'));
               } else {
                   $r->print(&mt('You do not have rights to modify student-viewable course roster settings.'));
               }
               $r->print('</div>');
           }
     } else {      } else {
         $r->print('<h3>'.  
                   &mt("Display of a student-viewable course roster is not currently enabled.").          # Print classlist
                   '</h3>');          if (keys(%viewsettings) > 0) {
               $r->print(&html_classlist($r,$crstype,\%viewsettings));
           } else {
               $r->print('<div class="LC_info">');
               if ($crstype eq 'Community') {
                   $r->print(&mt("Display of a member-viewable community roster is not currently enabled."));
               } else {
                   $r->print(&mt("Display of a student-viewable course roster is not currently enabled."));
               }
               $r->print('</div>');
           }
     }      }
     #      #
     # Finish up      # Finish up
Line 123  sub retrieve_view_settings { Line 225  sub retrieve_view_settings {
     return %viewsettings;      return %viewsettings;
 }  }
   
   sub roster_prefs {
       my ($crstype) = @_;
       my %lt;
       if ($crstype eq 'Community') {
           %lt = &Apache::lonlocal::texthash (
                     svrs => 'Member-viewable roster settings',
                     stuv => 'Member-viewable membership list options',
                     stul => 'Member agreement needed to be listed',
           );
       } else {
           %lt = &Apache::lonlocal::texthash(
                     svrs => 'Student-viewable roster settings',
                     stuv => 'Student-viewable classlist options',
                     stul => 'Student agreement needed to be listed',
           );
       }
       $lt{'incl'} = &mt('Include link to accessible portfolio files');
   
       return 
           { text => $lt{'svrs'},
             header => [ {col1 => 'Setting',
                          col2 => $lt{'stuv'}}],
             ordered => ['student_classlist_view',
                         'student_classlist_opt_in',
                         'student_classlist_portfiles'],
             itemtext => {
                          student_classlist_view        => $lt{'stuv'},
                          student_classlist_opt_in      => $lt{'stul'},
                          student_classlist_portfiles   => $lt{'incl'},
                         },
           };
   }
   
 sub html_classlist {  sub html_classlist {
     my ($r,$viewsettings) = @_;      my ($r,$crstype,$viewsettings) = @_;
     my ($Str,$title,$secdisplay,$cid,$cdom,$cnum,$listtype,%publicroster);      my ($Str,$title,$secdisplay,$cid,$cdom,$cnum,$listtype,%publicroster);
     my $fullroster = &Apache::loncoursedata::get_classlist();      my $fullroster = &Apache::loncoursedata::get_classlist();
     my $classlist;      my $classlist;
   
       my $singular = 'student';
       my $plural = 'students';
       my $titleplural = 'Students';
       my $heading = &mt('Student-viewable course roster');
   
       if ($crstype eq 'Community') {
           $singular = 'member';
           $plural = 'members';
           $titleplural = 'Members';
           $heading = &mt('Member-viewable community roster');
       }
   
     if ($env{'form.action'} eq 'setenv') {      if ($env{'form.action'} eq 'setenv') {
         $Str .= &process_student_prefs();          $Str .= &process_student_prefs($crstype);
     }      }
     $Str .= '<h3>'.&mt('Student-viewable course roster').'</h3>';  
       $Str .= '<h2>'.$heading.'</h2>';
   
     $cid = $env{'request.course.id'};      $cid = $env{'request.course.id'};
     $cdom = $env{'course.'.$cid.'.domain'};      $cdom = $env{'course.'.$cid.'.domain'};
Line 140  sub html_classlist { Line 288  sub html_classlist {
   
     if ($viewsettings->{'limit_to_section'}) {      if ($viewsettings->{'limit_to_section'}) {
         if ($env{'request.course.sec'} eq '') {          if ($env{'request.course.sec'} eq '') {
             $title = '<h4>'.&mt('Students with no section').'</h4>';              $title = &mt($titleplural.' with no section');
             $listtype = 'without a section';              $listtype = 'without a section';
         } else {          } else {
             $title ='<h4>'.&mt('Students in section "[_1]"',              $title = &mt($titleplural.' in section "[_1]"',
                                $env{'request.course.sec'}).'</h4>';                           $env{'request.course.sec'});
             $listtype = 'in the section';              $listtype = 'in the section';
             $secdisplay = " ($env{'request.course.sec'}) ";              $secdisplay = " ($env{'request.course.sec'}) ";
         }          }
     } else {      } else {
         $title .= '<h4>'.&mt('Students in any section').'</h4>';          $title = &mt($titleplural.' in any section');
         $listtype = 'in the course';          $listtype = 'in the course';
           if ($crstype eq 'Community') {
               $listtype = 'in the community';
           }
     }      }
   
     if ($viewsettings->{'student_opt_in'}) {      if ($viewsettings->{'student_opt_in'}) {
         if ($env{'request.role'} =~ /^st/)  {          if ($env{'request.role'} =~ /^st/)  {
             $Str .= &print_roster_form();              $Str .= &print_roster_form($crstype);
         }          }
         %publicroster = &Apache::lonnet::dump('publicroster',$cdom,$cnum);          %publicroster = &Apache::lonnet::dump('publicroster',$cdom,$cnum);
     }      }
   
     $Str .= $title;      $Str .= '<h3>'.$title.'</h3>';
   
     my $fullcount = 0;      my $fullcount = 0;
     my $publiccount = 0;      my $publiccount = 0;
Line 189  sub html_classlist { Line 339  sub html_classlist {
         $displaycount = $publiccount;          $displaycount = $publiccount;
         if ($fullcount > $publiccount) {          if ($fullcount > $publiccount) {
             if ($publiccount) {              if ($publiccount) {
                 $Str .= &mt('Only students who have opted to be listed in the roster ([_1] out of [_2] students) are shown.',$publiccount,$fullcount).'<br />';                  $Str .= &mt('Only '.$plural.' who have opted to be listed in the roster ([_1] out of [_2] '.$plural.') are shown.',$publiccount,$fullcount).'<br />';
             } else {              } else {
                 if ($fullcount == 1) {                  if ($fullcount == 1) {
                     $Str .= &mt('The single student '.$listtype.'[_1] has opted not to be listed in the roster.',$secdisplay);                      $Str .= &mt('The single '.$singular.' '.$listtype.'[_1] has opted not to be listed in the roster.',$secdisplay);
                 } else {                  } else {
                     $Str .= &mt('None of the [_1] students '.$listtype.'[_2] have opted to be listed in the roster.',$fullcount,$secdisplay);                      $Str .= &mt('None of the [_1] '.$plural.' '.$listtype.'[_2] have opted to be listed in the roster.',$fullcount,$secdisplay);
                 }                  }
                 return $Str;                  return $Str;
             }              }
         } else {          } else {
             if ($fullcount > 1) {              if ($fullcount > 1) {
                 $Str .= &mt('All [_1] students '.$listtype.'[_2] have opted to be listed in the roster.',$fullcount,$secdisplay);                  $Str .= &mt('All [_1] '.$plural.' '.$listtype.'[_2] have opted to be listed in the roster.',$fullcount,$secdisplay); 
             } elsif ($fullcount == 1) {              } elsif ($fullcount == 1) {
                 $Str .= &mt('The single student '.$listtype.'[_1] has opted to be listed in the roster.',$secdisplay);                  $Str .= &mt('The single '.$singular.' '.$listtype.'[_1] has opted to be listed in the roster.',$secdisplay);
             }              }
         }          }
     } else {      } else {
         $displaycount = $fullcount;          $displaycount = $fullcount;
         if ($fullcount > 1) {          if ($fullcount > 1) {
             $Str .= &mt('All [_1] students '.$listtype.'[_2] are listed in the roster.',$fullcount,$secdisplay);              $Str .= &mt('All [_1] '.$plural.' '.$listtype.'[_2] are listed in the roster.',$fullcount,$secdisplay);
         } elsif ($fullcount == 1) {          } elsif ($fullcount == 1) {
             $Str .= &mt('There is only a single student '.$listtype.'[_1]',$secdisplay);              $Str .= &mt('There is only a single '.$singular.' '.$listtype.'[_1]',$secdisplay);
         }          }
     }      }
     undef($fullroster);      undef($fullroster);
   
     if (!$displaycount) {      if (!$displaycount) {
         $Str .= &mt('There are currently no students to display.');          $Str .= &mt('There are currently no '.$plural.' to display.');
         return $Str;          return $Str;
     }      }
   
Line 233  sub html_classlist { Line 383  sub html_classlist {
     $Str .= '<br />'.&Apache::loncommon::start_data_table()."\n".      $Str .= '<br />'.&Apache::loncommon::start_data_table()."\n".
             &Apache::loncommon::start_data_table_header_row()."\n".              &Apache::loncommon::start_data_table_header_row()."\n".
         '<th></th>'. # for the count          '<th></th>'. # for the count
         '<th>'.&mt('Student').'</th>'.          '<th>'.&mt('Name').'</th>'.
         '<th>'.&mt('Username').'</th>';          '<th>'.&mt('Username').'</th>';
     if (! $viewsettings->{'limit_to_section'}) {      if (! $viewsettings->{'limit_to_section'}) {
         $Str .= '<th>'.&mt('Section').'</th>';          $Str .= '<th>'.&mt('Section').'</th>';
Line 262  sub html_classlist { Line 412  sub html_classlist {
             '<td>'.('&nbsp;'x2).              '<td>'.('&nbsp;'x2).
             &Apache::loncommon::messagewrapper              &Apache::loncommon::messagewrapper
             ('<img src="/adm/lonIcons/mailto.gif" border="0" />&nbsp;'.              ('<img src="/adm/lonIcons/mailto.gif" border="0" />&nbsp;'.
              $username.'@'.$domain,$username,$domain).'</td>';               $username.':'.$domain,$username,$domain).'</td>';
         if (! $viewsettings->{'limit_to_section'}) {          if (! $viewsettings->{'limit_to_section'}) {
             $Str .= '<td>'.$section.'</td>';              $Str .= '<td>'.$section.'</td>';
         }          }
Line 286  sub html_classlist { Line 436  sub html_classlist {
 }  }
   
 sub print_roster_form {  sub print_roster_form {
       my ($crstype) = @_;
     my $cid = $env{'request.course.id'};      my $cid = $env{'request.course.id'};
     my $showinroster = $env{'environment.internal.'.$cid.'.showinroster'};      my $showinroster = $env{'environment.internal.'.$cid.'.showinroster'};
     my ($showoff,$showon);      my ($showoff,$showon);
Line 296  sub print_roster_form { Line 447  sub print_roster_form {
         $showoff = ' checked="checked" ';          $showoff = ' checked="checked" ';
         $showon = ' ';          $showon = ' ';
     }      }
     my $output = '<hr /><h4>'.&mt('Your roster setting').'</h4>';      my $singular = 'student';
       if ($crstype eq 'Community') {
           $singular = 'member';
       }
       my $output =
           '<div class="LC_left_float">'
          .'<fieldset><legend>'.&mt('Your roster setting').'</legend>';
     if ($showinroster) {      if ($showinroster) {
         $output .= &mt('You are currently listed in the student-viewable roster.');          $output .= &mt("You are currently listed in the $singular-viewable roster.");
     } else {      } else {
         $output .=  &mt('You are currently <b>not</b> listed in the student-viewable roster.');          $output .=  &mt("You are currently [_1]not[_2] listed in the $singular-viewable roster.",'<b>','</b>');
     }      }
     $output .= '<br />'.&mt('Include yourself in the roster?').'&nbsp;&nbsp;'.      $output .= '<br />'.&mt('Include yourself in the roster?').'&nbsp;&nbsp;'.
         '<form name="studentparm" method="post">'.          '<form name="studentparm" method="post" action="">'.
         '<span class="LC_nobreak"><label><input type="radio" name="showinroster" value="1"'.$showon.'/>'.&mt('Yes').'</label>&nbsp;&nbsp;<label>'.          '<span class="LC_nobreak"><label><input type="radio" name="showinroster" value="1"'.$showon.'/>'.&mt('Yes').'</label>&nbsp;&nbsp;<label>'.
         '<input type="radio" name="showinroster" value="0"'.$showoff.'/>'.&mt('No').          '<input type="radio" name="showinroster" value="0"'.$showoff.'/>'.&mt('No').
         '</label></span><br /><br />'.          '</label></span><br /><br />'.
         '<input type="hidden" name="action" value="setenv" />'.          '<input type="hidden" name="action" value="setenv" />'.
         '<input type="submit" name="studentsubmit" value="'.&mt('Save').'" /></form><hr />';          '<input type="submit" name="studentsubmit" value="'.&mt('Save').'" />'.
           '</form></fieldset></div><br clear="all" />';
     return $output;      return $output;
 }  }
   
 sub process_student_prefs {  sub process_student_prefs {
       my ($crstype) = @_;
     my $cid = $env{'request.course.id'};      my $cid = $env{'request.course.id'};
     my $cdom = $env{'course.'.$cid.'.domain'};      my $cdom = $env{'course.'.$cid.'.domain'};
     my $cnum = $env{'course.'.$cid.'.num'};      my $cnum = $env{'course.'.$cid.'.num'};
Line 329  sub process_student_prefs { Line 488  sub process_student_prefs {
     if ($pubroster{$student}) {      if ($pubroster{$student}) {
         $sturoster = 1;          $sturoster = 1;
     }      }
   
       my $singular = 'student';
       if ($crstype eq 'Community') {
           $singular = 'member';
       }
     my $output;      my $output;
     if ($sturoster ne $showinroster) {      if ($sturoster ne $showinroster) {
         my %changeHash = (          my %changeHash = (
Line 337  sub process_student_prefs { Line 501  sub process_student_prefs {
         my $putresult = &Apache::lonnet::put('environment',          my $putresult = &Apache::lonnet::put('environment',
                                              \%changeHash,$udom,$uname);                                               \%changeHash,$udom,$uname);
         if ($putresult eq 'ok') {          if ($putresult eq 'ok') {
             &Apache::lonnet::appenv(%changeHash);              &Apache::lonnet::appenv(\%changeHash);
             my $result = &Apache::lonnet::put('publicroster',{$student => $showinroster,},$cdom,$cnum);              my $result = &Apache::lonnet::put('publicroster',{$student => $showinroster,},$cdom,$cnum);
             if ($result eq 'ok') {              if ($result eq 'ok') {
                 $output .= &mt('Display of your name in the student-viewable roster set to <b>[_1]</b>.',$visibility);                  $output .=
                       &Apache::lonhtmlcommon::confirm_success(
                           &mt("Display of your name in the $singular-viewable roster set to [_1].",'<b>'.$visibility.'</b>'));
             } else {              } else {
                 $output .= '<span class="LC_error">'.&mt('Error occurred saving display setting.').'</span>';                  $output .=
                       &Apache::lonhtmlcommon::confirm_success(
                           &mt('Error occurred saving display setting.'),1);
             }              }
         } else {          } else {
             $output .= '<span class="LC_error">'.&mt('Error occurred saving display setting.').'</span>';              $output .=
                   &Apache::lonhtmlcommon::confirm_success(
                       &mt('Error occurred saving display setting.'),1);
         }          }
     } else {      } else {
         $output .= &mt('Display of your name in the student-viewable roster unchanged (set to <b>[_1]</b>).',$visibility);          $output .=
               &Apache::lonhtmlcommon::confirm_success(
                   &mt("Display of your name in the $singular-viewable roster unchanged (set to [_1]).",'<b>'.$visibility.'</b>'));
     }      }
       $output = &Apache::loncommon::confirmwrapper($output);
     return $output;      return $output;
 }  }
   

Removed from v.1.9  
changed lines
  Added in v.1.21


FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>