Diff for /loncom/auth/lonroles.pm between versions 1.273 and 1.274

version 1.273, 2012/08/15 16:56:52 version 1.274, 2012/08/16 17:02:46
Line 211  sub handler { Line 211  sub handler {
         $update = $then;          $update = $then;
     }      }
   
       &Apache::loncommon::get_unprocessed_cgi($ENV{'QUERY_STRING'});
   
   # -------------------------------------------------- Check if setting hot list 
       my $hotlist;
       if ($env{'form.action'} eq 'verify_and_change_rolespref') {
           $hotlist = &Apache::lonpreferences::verify_and_change_rolespref($r);
       }
   
 # -------------------------------------------------------- Check for new roles  # -------------------------------------------------------- Check for new roles
     my $updateresult;      my $updateresult;
     if ($env{'form.doupdate'}) {      if ($env{'form.state'} eq 'doupdate') {
         my $show_course=&Apache::loncommon::show_course();          my $show_course=&Apache::loncommon::show_course();
         my $checkingtxt;          my $checkingtxt;
         if ($show_course) {          if ($show_course) {
Line 221  sub handler { Line 229  sub handler {
         } else {          } else {
             $checkingtxt = &mt('Checking for new roles ...');              $checkingtxt = &mt('Checking for new roles ...');
         }          }
         $updateresult = '<span class="LC_info">'.$checkingtxt.'</span>';          $updateresult = $checkingtxt;
         $updateresult .= &update_session_roles();          $updateresult .= &update_session_roles();
         &Apache::lonnet::appenv({'user.update.time'  => $now});          &Apache::lonnet::appenv({'user.update.time'  => $now});
         $update = $now;          $update = $now;
Line 230  sub handler { Line 238  sub handler {
   
 # -------------------------------------------------- Check for author requests  # -------------------------------------------------- Check for author requests
     my $reqauthor;      my $reqauthor;
     if ($env{'form.requestauthor'}) {      if ($env{'form.state'} eq 'requestauthor') {
        $reqauthor = &Apache::loncoursequeueadmin::process_reqauthor(\$update);         $reqauthor = &Apache::loncoursequeueadmin::process_reqauthor(\$update);
     }      }
   
     my $envkey;      my $envkey;
     my %dcroles = ();      my %dcroles = ();
     my $numdc = &check_fordc(\%dcroles,$update,$then);      my $numdc = &check_fordc(\%dcroles,$update,$then);
     &Apache::loncommon::get_unprocessed_cgi($ENV{'QUERY_STRING'});  
     my $loncaparev = $Apache::lonnet::perlvar{'lonVersion'};      my $loncaparev = $Apache::lonnet::perlvar{'lonVersion'};
   
 # ================================================================== Roles Init  # ================================================================== Roles Init
Line 654  ENDENTERKEY Line 661  ENDENTERKEY
         $recent = &mt('Recent Courses');          $recent = &mt('Recent Courses');
     }      }
     my $brcrum =[{href=>"/adm/roles",text=>$crumbtext}];      my $brcrum =[{href=>"/adm/roles",text=>$crumbtext}];
   
       my %roles_in_env;
       my $showcount = &roles_from_env(\%roles_in_env,$update); 
   
     my $swinfo=&Apache::lonmenu::rawconfig();      my $swinfo=&Apache::lonmenu::rawconfig();
     my $start_page=&Apache::loncommon::start_page($pagetitle,undef,{bread_crumbs=>$brcrum});      my $start_page=&Apache::loncommon::start_page($pagetitle,undef,{bread_crumbs=>$brcrum});
       my $funcs = &get_roles_functions($showcount);
     my $standby=&mt('Role selected. Please stand by.');      my $standby=&mt('Role selected. Please stand by.');
     $standby=~s/\n/\\n/g;      $standby=~s/\n/\\n/g;
     my $noscript='<span class="LC_error">'.&mt('Use of LON-CAPA requires Javascript to be enabled in your web browser.').'<br />'.&mt('As this is not the case, most functionality in the system will be unavailable.').'</span><br />';      my $noscript='<br /><span class="LC_error">'.&mt('Use of LON-CAPA requires Javascript to be enabled in your web browser.').'<br />'.&mt('As this is not the case, most functionality in the system will be unavailable.').'</span><br />';
   
     $r->print(<<ENDHEADER);      $r->print(<<ENDHEADER);
 $start_page  $start_page
 <br />  $funcs
 <noscript>  <noscript>
 $noscript  $noscript
 </noscript>  </noscript>
Line 685  function enterrole (thisform,rolecode,bu Line 697  function enterrole (thisform,rolecode,bu
     }      }
 }  }
   
 function setToUpdate(thisform) {  function rolesView (caller) {
     thisform.doupdate.value='1';      if ((caller == 'showall') || (caller == 'noshowall')) {
     thisform.selectrole.value='';          document.rolechoice.display.value = caller;
     thisform.submit();      } else {
 }          if ((caller == 'doupdate') || (caller == 'requestauthor') ||
               (caller == 'queued')) { 
 function setToRequestAuthor(thisform) {              document.rolechoice.state.value = caller;
     thisform.requestauthor.value='1';          }
     thisform.selectrole.value='';      }
     thisform.submit();       document.rolechoice.selectrole.value='';
       document.rolechoice.submit();
 }  }
   
 // ]]>  // ]]>
Line 763  ENDHEADER Line 776  ENDHEADER
   &Apache::loncommon::end_page());    &Apache::loncommon::end_page());
  return OK;   return OK;
     } else {      } else {
         if ($updateresult || $reqauthor) {          if ($updateresult || $reqauthor || $hotlist) {
             $r->print('<div>'.              my $showresult = '<div>';
                       $updateresult.              if ($updateresult) {
                       $reqauthor.                  $showresult .= &Apache::lonhtmlcommon::confirm_success($updateresult);
                       '</div>');              }
               if ($reqauthor) {
                   $showresult .= &Apache::lonhtmlcommon::confirm_success($reqauthor);
               }
               if ($hotlist) {
                   $showresult .= $hotlist;
               } 
               $showresult .= '</div>';
               $r->print($showresult);
           } elsif ($env{'form.state'} eq 'queued') {
               $r->print(&get_queued());
         }          }
         if (($ENV{'REDIRECT_QUERY_STRING'}) && ($fn)) {          if (($ENV{'REDIRECT_QUERY_STRING'}) && ($fn)) {
        $fn.='?'.$ENV{'REDIRECT_QUERY_STRING'};         $fn.='?'.$ENV{'REDIRECT_QUERY_STRING'};
         }          }
           my $display = ($env{'form.display'} =~ /^(showall)$/);
         $r->print('<form method="post" name="rolechoice" action="'.(($fn)?$fn:$r->uri).'">');          $r->print('<form method="post" name="rolechoice" action="'.(($fn)?$fn:$r->uri).'">');
         $r->print('<input type="hidden" name="orgurl" value="'.$fn.'" />');          $r->print('<input type="hidden" name="orgurl" value="'.$fn.'" />');
         $r->print('<input type="hidden" name="selectrole" value="1" />');          $r->print('<input type="hidden" name="selectrole" value="1" />');
         $r->print('<input type="hidden" name="newrole" value="" />');          $r->print('<input type="hidden" name="newrole" value="" />');
           $r->print('<input type="hidden" name="display" value="'.$display.'" />');
           $r->print('<input type="hidden" name="state" value="" />');
     }      }
     $r->rflush();      $r->rflush();
   
     my (%roletext,%sortrole,%roleclass,%futureroles,%timezones);      my (%roletext,%sortrole,%roleclass,%futureroles,%timezones);
     my ($countactive,$countfuture,$inrole,$possiblerole) =       my ($countactive,$countfuture,$inrole,$possiblerole) = 
         &gather_roles($update,$refresh,$now,$reinit,$nochoose,\%roletext,\%sortrole,\%roleclass,          &gather_roles($update,$refresh,$now,$reinit,$nochoose,\%roles_in_env,\%roletext,
                       \%futureroles,\%timezones,$loncaparev);                        \%sortrole,\%roleclass,\%futureroles,\%timezones,$loncaparev);
     $refresh = $now;      $refresh = $now;
     &Apache::lonnet::appenv({'user.refresh.time'  => $refresh});      &Apache::lonnet::appenv({'user.refresh.time'  => $refresh});
     my $updatebutton = &mt('Check for role changes');      unless ($env{'user.adv'}) { 
     my $show_course=&Apache::loncommon::show_course();  
     if ($show_course) {  
         $updatebutton = &mt('Check for new courses');  
     }  
     my $do_update;  
     unless (($env{'form.source'} eq 'login') || ($env{'form.doupdate'})) {  
         $do_update = '<input type="hidden" name="doupdate" value="" />'.  
                      '<input type="button" name="update" value="'.  
                      $updatebutton.'" onclick="javascript:setToUpdate(this.form)" />';  
     }  
     my ($requestauthor,$requestcrs);  
     unless ($reqauthor) {  
         if ($env{'environment.canrequest.author'}) {  
             unless (&Apache::loncoursequeueadmin::is_active_author()) {  
                 my ($status,$timestamp) = split(/:/,$env{'environment.requestauthorqueued'});  
                 if ($status eq 'approval') {  
                     $requestauthor = &mt('A request for authoring space submitted on [_1] is awaiting approval',&Apache::lonlocal::locallocaltime($timestamp));   
                 } elsif (($status eq 'approved') && ($do_update)) {  
                     my %roleshash = &Apache::lonnet::get_my_roles($env{'user.name'},$env{'user.domain'},'userroles',  
                                                                   ['active'],['au'],[$env{'user.domain'}]);  
                     if (keys(%roleshash)) {  
                         $requestauthor = &mt('Your request for an author role has been approved.').'<br />';  
                         if ($show_course) {  
                             $requestauthor .= &mt('Use the "Check for new courses" button to update your list of roles.');  
                         } else {  
                             $requestauthor .= &mt('Use the "Check for new roles" button to update your list of roles.');   
                         }  
                         $requestauthor = '<span class="LC_info">'.$requestauthor.'</span>';  
                     }  
                 }  
                 unless ($requestauthor) {  
                     $requestauthor =   
                         '<input type="hidden" name="requestauthor" value="" />'.  
                         '<input type="button" name="reqauthor" value="'.  
                         &mt('Request author space').'" '.   
                         'onclick="javascript:setToRequestAuthor(this.form)" />';  
                 }  
             }  
         }  
     }  
     my $do_update;  
     unless (($env{'form.source'} eq 'login') || ($env{'form.doupdate'})) {  
         $do_update = '<input type="hidden" name="doupdate" value="" />'.  
                      '<input type="button" name="update" value="'.  
                      $updatebutton.'" onclick="javascript:setToUpdate(this.form)" />';  
     }  
     if ($env{'user.adv'}) {  
         my $showall = '<label><input type="checkbox" name="showall"';  
         if ($env{'form.showall'}) {   
             $showall .= ' checked="checked" ';  
         }  
         $showall .= ' />'.&mt('Show all roles').'</label>&nbsp;'.  
                     '<input type="submit" value="'.&mt('Update display').'" />';  
         if ($do_update || $requestauthor) {  
             $r->print('<div class="LC_left_float"><fieldset>'.  
                       '<legend>'. &mt('Display').'</legend>'.  
                       $showall.'</fieldset></div>');  
             if ($do_update) {  
                 $r->print('<div class="LC_left_float">'.  
                           '<fieldset><legend>'.&mt('Changes?').'</legend>'.  
                           $do_update.'</fieldset></div>');  
             }  
             if ($requestauthor) {  
                 $r->print('<div class="LC_left_float">'.  
                           '<fieldset><legend>'.&mt('Add author role').'</legend>'.  
                           $requestauthor.'</fieldset>');  
             }  
             $r->print('</div><br clear="all" />');  
         } else {  
             $r->print($showall);  
         }  
     } else {  
         if ($do_update && $requestauthor) {  
             $r->print('<div class="LC_left_float">'.  
                       '<fieldset><legend>'.&mt('Changes?').'</legend>'.  
                       $do_update.'</fieldset></div>'.  
                       '<div class="LC_left_float">'.  
                       '<fieldset><legend>'.&mt('Add author role').'</legend>'.  
                       $requestauthor.'</fieldset></div><br clear="all" />');  
         } elsif ($do_update) {  
             $r->print('<p>'.$do_update.'</p>');  
         } elsif ($requestauthor) {  
             $r->print('<p>'.$requestauthor.'</p>');  
         }  
         if ($countactive > 0) {          if ($countactive > 0) {
             $r->print(&Apache::loncoursequeueadmin::queued_selfenrollment());  
             my $domdesc = &Apache::lonnet::domain($env{'user.domain'},'description');              my $domdesc = &Apache::lonnet::domain($env{'user.domain'},'description');
             my $esc_dom = &HTML::Entities::encode($env{'user.domain'},'"<>&');               my $esc_dom = &HTML::Entities::encode($env{'user.domain'},'"<>&'); 
             $r->print(              $r->print(
Line 1049  ENDHEADER Line 990  ENDHEADER
     return OK;      return OK;
 }  }
   
   sub roles_from_env {
       my ($roleshash,$update) = @_;
       my $count = 0;
       if (ref($roleshash) eq 'HASH') {
           foreach my $envkey (keys(%env)) {
               if ($envkey =~ m{^user\.role\.(\w+)[./]}) {
                   next if ($1 eq 'gr');
                   $roleshash->{$envkey} = $env{$envkey};
                   my ($start,$end) = split(/\./,$env{$envkey});
                   unless ($end && $end<$update) {
                       $count ++;
                   }
               }
           }
       }
       return $count;
   }
   
 sub gather_roles {  sub gather_roles {
     my ($update,$refresh,$now,$reinit,$nochoose,$roletext,$sortrole,$roleclass,$futureroles,$timezones,$loncaparev) = @_;      my ($update,$refresh,$now,$reinit,$nochoose,$roles_in_env,$roletext,$sortrole,$roleclass,$futureroles,
           $timezones,$loncaparev) = @_;
     my ($countactive,$countfuture,$inrole,$possiblerole) = (0,0,0,'');      my ($countactive,$countfuture,$inrole,$possiblerole) = (0,0,0,'');
     my $advanced = $env{'user.adv'};      my $advanced = $env{'user.adv'};
     my $tryagain = $env{'form.tryagain'};      my $tryagain = $env{'form.tryagain'};
     my @ids = &Apache::lonnet::current_machine_ids();      my @ids = &Apache::lonnet::current_machine_ids();
     foreach my $envkey (sort(keys(%env))) {      if (ref($roles_in_env) eq 'HASH') {
         my $button = 1;          foreach my $envkey (sort(keys(%{$roles_in_env}))) {
         my $switchserver='';              my $button = 1;
         my $switchwarning;              my $switchserver='';
         my ($role_text,$role_text_end,$sortkey);              my $switchwarning;
         if ($envkey=~/^user\.role\./) {              my ($role_text,$role_text_end,$sortkey,$role,$where,$trolecode,$tstart,
             my ($role,$where,$trolecode,$tstart,$tend,$tremark,$tstatus,$tpstart,$tpend);                  $tend,$tremark,$tstatus,$tpstart,$tpend);
             &Apache::lonnet::role_status($envkey,$update,$refresh,$now,\$role,\$where,              &Apache::lonnet::role_status($envkey,$update,$refresh,$now,\$role,\$where,
                                          \$trolecode,\$tstatus,\$tstart,\$tend);                                           \$trolecode,\$tstatus,\$tstart,\$tend);
             next if (!defined($role) || $role eq '' || $role =~ /^gr/);              next if (!defined($role) || $role eq '' || $role =~ /^gr/);
Line 1075  sub gather_roles { Line 1035  sub gather_roles {
             if (($tstatus eq 'is')              if (($tstatus eq 'is')
                 || ($tstatus eq 'selected')                  || ($tstatus eq 'selected')
                 || ($tstatus eq 'future')                  || ($tstatus eq 'future')
                 || ($env{'form.showall'})) {                  || ($env{'form.display'} eq 'showall')) {
                 my $timezone = &role_timezone($where,$timezones);                  my $timezone = &role_timezone($where,$timezones);
                 if ($tstart) {                  if ($tstart) {
                     $tpstart=&Apache::lonlocal::locallocaltime($tstart,$timezone);                      $tpstart=&Apache::lonlocal::locallocaltime($tstart,$timezone);
Line 2208  sub update_session_roles { Line 2168  sub update_session_roles {
     }      }
     if (($oldsec) && (@newsec > 0)) {      if (($oldsec) && (@newsec > 0)) {
         if (@newsec > 1) {          if (@newsec > 1) {
             $msg = '<div class="LC_warning">'.&mt('The section has changed for your current role. Log-out and log-in again to select a role for the new section.').'</div>';              $msg = '<p class="LC_warning">'.&mt('The section has changed for your current role. Log-out and log-in again to select a role for the new section.').'</p>';
         } else {          } else {
             my $newrole = $env{'request.role'};              my $newrole = $env{'request.role'};
             if ($newsec[0] eq 'none') {              if ($newsec[0] eq 'none') {
Line 2246  sub update_session_roles { Line 2206  sub update_session_roles {
             $msg .= '</form></p>';              $msg .= '</form></p>';
         }          }
     } elsif ($currrole_expired) {      } elsif ($currrole_expired) {
         $msg .= '<div class="LC_warning">';          $msg .= '<p class="LC_warning">';
         if (&Apache::loncommon::show_course()) {          if (&Apache::loncommon::show_course()) {
             $msg .= &mt('Your role in the current course has expired.');              $msg .= &mt('Your role in the current course has expired.');
         } else {          } else {
             $msg .= &mt('Your current role has expired.');              $msg .= &mt('Your current role has expired.');
         }          }
         $msg .= '<br />'.&mt('However you can continue to use this role until you logout, click the "Re-Select" button, or your session has been idle for more than 24 hours.').'</div>';          $msg .= '<br />'.&mt('However you can continue to use this role until you logout, click the "Re-Select" button, or your session has been idle for more than 24 hours.').'</p>';
     }      }
     if (!@changed_roles || !(keys(%changed_groups))) {      if (!@changed_roles || !(keys(%changed_groups))) {
         my ($rolesmsg,$groupsmsg);          my ($rolesmsg,$groupsmsg);
Line 2534  sub is_active_course { Line 2494  sub is_active_course {
     return $is_active;      return $is_active;
 }  }
   
   sub get_roles_functions {
       my ($rolescount) = @_;
       my @links;
       if ($env{'user.adv'}) {
           if ($env{'form.display'} eq 'showall') {
               push(@links,["javascript:rolesView('noshowall');",'edit-redo-22x22',&mt('Exclude expired roles')]);
           } else {
               push(@links,["javascript:rolesView('showall');",'edit-undo-22x22',&mt('Include expired roles')]);
           }
       }
       push(@links,["javascript:rolesView('doupdate');",'start-here-22x22',&mt('Check for changes')]);
       if ($env{'environment.canrequest.author'}) {
           unless (&Apache::loncoursequeueadmin::is_active_author()) {
               push(@links,["javascript:rolesView('requestauthor');",'list-add-22x22',&mt('Request author role')]);
           }
       }
       if (&Apache::lonmenu::check_for_rcrs()) {
           push(@links,['/adm/requestcourse','rcrs-22x22',&mt('Request course')]);
       }
       if ($env{'form.state'} eq 'queued') {
           push(@links,["javascript:rolesView('noqueued');",'selfenrl-queue-22x22',&mt('Hide queued')]);
       } else {
           push(@links,["javascript:rolesView('queued');",'selfenrl-queue-22x22',&mt('Show queued')]);
       }
       if (($rolescount > 3) || ($env{'environment.recentroles'})) {
           push(@links,['/adm/preferences?action=changerolespref&amp;returnurl=/adm/roles','role_hotlist-22x22',&mt('Hotlist')]);
       }
       
       my $funcs = &Apache::lonhtmlcommon::start_funclist();
       foreach my $link (@links) {
           $funcs .= &Apache::lonhtmlcommon::add_item_funclist(
                         '<a href="'.$link->[0].'" class="LC_menubuttons_link">'.
                         '<img src="/res/adm/pages/'.$link->[1].'.png" class="LC_icon" alt="'.$link->[2].'" />'.
                         $link->[2].'</a>');
       }
       $funcs .= &Apache::lonhtmlcommon::end_funclist();
       return &Apache::loncommon::head_subbox($funcs);
   }
   
   sub get_queued {
       my ($output,%reqcrs);
       my ($types,$typenames) = &Apache::loncommon::course_types();
       my %statusinfo = &Apache::lonnet::dump('courserequests',$env{'user.domain'},
                                              $env{'user.name'},'^status:');
       foreach my $key (keys(%statusinfo)) {
           next unless (($statusinfo{$key} eq 'approval') || ($statusinfo{$key} eq 'pending'));
           (undef,my($cdom,$cnum)) = split(':',$key);
           my $requestkey = $cdom.'_'.$cnum;
           if ($requestkey =~ /^($match_domain)_($match_courseid)$/) {
               my %history = &Apache::lonnet::restore($requestkey,'courserequests',
                                                      $env{'user.domain'},$env{'user.name'});
               next if ((exists($history{'status'})) && ($history{'status'} eq 'created'));
               my $reqtime = $history{'reqtime'};
               my $lastupdate = $history{'timestamp'};
               my $showtype = $history{'crstype'};
               if (defined($typenames->{$history{'crstype'}})) {
                   $showtype = $typenames->{$history{'crstype'}};
               }
               my $description;
               if (ref($history{'details'}) eq 'HASH') {
                   $description = $history{details}{'cdescr'};
               }
               @{$reqcrs{$reqtime}} = ($description,$showtype); 
           }
       }
       my @sortedtimes = sort {$a <=> $b} (keys(%reqcrs));
       if (@sortedtimes > 0) {
           $output .= '<p><b>'.&mt('Course/Community requests').'</b><br />'.
                      &Apache::loncommon::start_data_table().
                      &Apache::loncommon::start_data_table_header_row().
                      '<th>'.&mt('Date requested').'</th>'.
                      '<th>'.&mt('Course title').'</th>'.
                      '<th>'.&mt('Course type').'</th>';
                      &Apache::loncommon::end_data_table_header_row();
           foreach my $reqtime (@sortedtimes) {
               next unless (ref($reqcrs{$reqtime}) eq 'ARRAY');
               $output .= &Apache::loncommon::start_data_table_row().
                          '<td>'.&Apache::lonlocal::locallocaltime($reqtime).'</td>'.
                          '<td>'.join('</td><td>',@{$reqcrs{$reqtime}}).'</td>'.
                          &Apache::loncommon::end_data_table_row();
           }
           $output .= &Apache::loncommon::end_data_table().
                      '<br /></p>';
       }
       my $queuedselfenroll = &Apache::loncoursequeueadmin::queued_selfenrollment(1);
       if ($queuedselfenroll) {
           $output .= '<p><b>'.&mt('Enrollment requests').'</b><br />'.
                      $queuedselfenroll.'<br /></p>';
       }
       if ($env{'environment.canrequest.author'}) {
           unless (&Apache::loncoursequeueadmin::is_active_author()) {
               my $requestauthor;
               my ($status,$timestamp) = split(/:/,$env{'environment.requestauthorqueued'});
               if (($status eq 'approval') || ($status eq 'approved')) {
                   $output .= '<p><b>'.&mt('Author role request').'</b><br />';
                   if ($status eq 'approval') {
                       $output .= &mt('A request for authoring space submitted on [_1] is awaiting approval',
                                     &Apache::lonlocal::locallocaltime($timestamp));
                   } elsif ($status eq 'approved') {
                       my %roleshash =
                           &Apache::lonnet::get_my_roles($env{'user.name'},$env{'user.domain'},'userroles',
                                                         ['active'],['au'],[$env{'user.domain'}]);
                       if (keys(%roleshash)) {
                           $output .= '<span class="LC_info">'.
                                      &mt('Your request for an author role has been approved.').'<br />'.
                                      &mt('Use the "Check for changes" link to update your list of roles.').
                                      '</span>';
                       }
                   }
                   $output .= '</p>';
               }
           }
       }
       unless ($output) {
           if ($env{'environment.canrequest.author'} || $env{'environment.canrequest.official'} ||
               $env{'environment.canrequest.unofficial'} || $env{'environment.canrequest.community'}) {
               $output = &mt('No requests for courses, communities or authoring currently queued');
           } else {
               $output = &mt('No enrollment requests currently queued awaiting approval');
           }
       }
       return '<div class="LC_left_float"><fieldset><legend>'.&mt('Queued requests').'</legend>'.
              $output.'</fieldset></div><br clear="all" />';
   }
   
 1;  1;
 __END__  __END__
   

Removed from v.1.273  
changed lines
  Added in v.1.274


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