Diff for /loncom/interface/selfenroll.pm between versions 1.8 and 1.9

version 1.8, 2008/07/10 00:19:56 version 1.9, 2008/07/11 13:43:53
Line 61  sub handler { Line 61  sub handler {
       text=>"Self-enroll"});        text=>"Self-enroll"});
     $r->print(&Apache::lonhtmlcommon::breadcrumbs('Self-enroll in course'));      $r->print(&Apache::lonhtmlcommon::breadcrumbs('Self-enroll in course'));
     if ($coursechk ne 'ok') {      if ($coursechk ne 'ok') {
         $r->print(&mt('Invalid domain or course number'));          $r->print('<h3>'.&mt('Self-enrollment error').'</h3>'.
                     '<span class="LC_error">'.&mt('Invalid domain or course number').'</span>');
         $r->print(&Apache::loncommon::end_page());          $r->print(&Apache::loncommon::end_page());
         return OK;          return OK;
     }      }
     my ($cdom,$cnum,$canenroll,$selfenroll_types,$selfenroll_registered,      my ($cdom,$cnum,$canenroll,$selfenroll_types,$selfenroll_registered,
         @cancreate,$knownuser,$selfenroll_access_start,$selfenroll_access_end,          @cancreate,$knownuser,$selfenroll_access_start,$selfenroll_access_end,
         $selfenroll_section,%curr_role,%coursehash);          $selfenroll_section,$selfenroll_future,%curr_role,%coursehash,$cdomdesc);
     my $now = time;      my $now = time;
     %coursehash = &Apache::lonnet::coursedescription($cid);      %coursehash = &Apache::lonnet::coursedescription($cid);
     $cdom = $coursehash{'domain'};      $cdom = $coursehash{'domain'};
Line 80  sub handler { Line 81  sub handler {
     if ($selfenroll_types ne '') {      if ($selfenroll_types ne '') {
         my $start = $coursehash{'internal.selfenroll_start_date'};          my $start = $coursehash{'internal.selfenroll_start_date'};
         my $end = $coursehash{'internal.selfenroll_end_date'};          my $end = $coursehash{'internal.selfenroll_end_date'};
         if (($start > 0 && $start < $now) && ($end > 0 && $end > $now)) {          if (($start > 0 && $start < $now) && (($end == 0) || ($end > 0 && $end > $now))) {
             $canenroll = 1;              $canenroll = 1;
           } elsif (($end == 0) || ($end > 0 && $end > $now)) {
               if ($start > $now) {
                   $selfenroll_future = &Apache::lonlocal::locallocaltime($start);
               }
         }          }
     }      }
       $knownuser = &user_is_known();
     if (!$canenroll) {      if (!$canenroll) {
         $r->print(&mt('Self-enrollment is not currently available for this course.').'<br /><br />');          $r->print('<h3>'.&mt('Self-enrollment unavailable').'</h3><span class="LC_warning">'.
                     &mt('Self-enrollment is not currently available for this course.').
                     '</span><br /><br />');
           if ($selfenroll_types ne '') {
               if ($selfenroll_future ne '') {
                   if ($selfenroll_types eq '*') {
                       $r->print(&mt('Self-enrollment will become available starting [_1], and will be available to all LON-CAPA users.',$selfenroll_future).'<br />');
                   } else {
                       my ($enrolltypes,$longtypes,$alldoms);
                       if ($knownuser) {
                           &get_selfenroll_filters($selfenroll_types,$env{'user.domain'});
                           my $domdesc = &Apache::lonnet::domain($env{'user.domain'},'description');
                           if (ref($enrolltypes) eq 'HASH') {
                               if (ref($enrolltypes->{$env{'user.domain'}}) eq 'ARRAY') {
                                   if (grep(/^any$/,@{$enrolltypes->{$env{'user.domain'}}})) {
                                       $r->print(&mt('Self-enrollment will become available starting [_1], and will be available to all LON-CAPA users at your institution ([_2]).',
                                                 $selfenroll_future,$domdesc).'<br />');
   
                                   } else {
                                       if (&user_can_selfenroll($env{'user.domain'},
                                                           $env{'user.name'},
                                                           $enrolltypes->{$env{'user.domain'}})) {
                                           $r->print(&mt('Self-enrollment will become available starting [_1]; please enroll at that time.',$selfenroll_future)); 
                                       } else {
                                           $r->print(&mt('Although self-enrollment will become available starting [_1], you are ineligible for enrollment.',$selfenroll_future).'<br />');
                                           $r->print(&print_selfenroll_types($longtypes,$env{'user.domain'}));
                                       }
                                   }
                               }
                           } 
                       } else {
                           $r->print(&mt('Self-enrollment will become available starting [_1].',
                                         $selfenroll_future).'<br />');
                           $r->print(&print_selfenroll_types($longtypes));
                       }
                   }
               } 
           }
     }      }
     $knownuser = &user_is_known();  
     if ($knownuser) {      if ($knownuser) {
         foreach my $key (keys(%env)) {          foreach my $key (keys(%env)) {
             if ($key =~ m-^user\.role\.st\./$cdom/$cnum/?(\w*)$-) {              if ($key =~ m-^user\.role\.st\./$cdom/$cnum/?(\w*)$-) {
Line 134  sub handler { Line 176  sub handler {
     my $missing_formitem = &mt('The link to the requested page could not be followed.')."\\n".&mt('The placeholder for the courseID is absent.');      my $missing_formitem = &mt('The link to the requested page could not be followed.')."\\n".&mt('The placeholder for the courseID is absent.');
     if ($knownuser) {      if ($knownuser) {
         if (keys(%curr_role)) {          if (keys(%curr_role)) {
             $r->print(&has_role(%curr_role));              $r->print('<h3>'.&mt('Self-enrollment unavailable').'</h3>'.
                         '<span class="LC_warning">'.&has_role(%curr_role).'</span>');
               $r->print(&Apache::loncommon::end_page());
             return OK;              return OK;
         }          }
         &process_self_enroll($r,$cdom,$cnum,$selfenroll_types,$selfenroll_registered,          &process_self_enroll($r,$cdom,$cnum,$selfenroll_types,$selfenroll_registered,
Line 166  function getIndexByName(item) { Line 210  function getIndexByName(item) {
 }  }
 </script>  </script>
 END  END
         $r->print(&mt('You need to be logged into LON-CAPA to self-enroll in a course.').'<ul><li>'.&mt('If you have an account in LON-CAPA, [_1]log-in[_2].','<a href="javascript:setPath('."'$login_path','firsturl','$firsturl'".')">','</a>').'</li>');          $r->print('<h3>'.&mt('LON-CAPA account required').'</h3>'.
                     &mt('You need to be logged into LON-CAPA to self-enroll in a course.').'<ul><li>'.&mt('If you have an account in LON-CAPA, [_1]log-in[_2].','<a href="javascript:setPath('."'$login_path','firsturl','$firsturl'".')">','</a>').'</li>');
         if (@cancreate > 1) {          if (@cancreate > 1) {
             $r->print('<li>'.&mt('Otherwise:').'<br />');              $r->print('<li>'.&mt('Otherwise:').'<br />');
             my $count = 0;              my $count = 0;
Line 196  END Line 241  END
             }              }
         }          }
         if ($selfenroll_types eq '*') {          if ($selfenroll_types eq '*') {
             $r->print('<br />'.&mt('You will have an opportunity to self enroll in the course once the account has been created.').'</li></ul>');              $r->print('<br />'.&mt('You will be able to self enroll in this course once the account has been created.').'</li></ul>');
         } else {          } else {
             $r->print('</li></ul>');              $r->print('</li></ul>');
             my ($enrolltypes,$longtypes,$alldoms) =               my ($enrolltypes,$longtypes,$alldoms) = 
                 &get_selfenroll_filters($selfenroll_types,$cdom);                  &get_selfenroll_filters($selfenroll_types);
             $r->print(&print_selfenroll_types($longtypes,$cdom));              $r->print(&print_selfenroll_types($longtypes));
         }          }
     } else {      } else {
         $r->print(&mt('You must [_1]log-in[_2] to LON-CAPA with an existing account to be able to enroll in this course, as account creation is not permitted when self-enrolling.','<a href="'.$login_path.'">','</a>'));          my $cdomdesc = &Apache::lonnet::domain($cdom,'description');
           $r->print('<h3>'.&mt('LON-CAPA account required').'</h3>');
           $r->print(&mt('You must [_1]log-in[_2] to LON-CAPA with an existing account to be able to enroll in this course, as account creation at this institution ([_3]) is not permitted when self-enrolling.','<a href="'.$login_path.'">','</a>',$cdomdesc));
         if ($selfenroll_types ne '*') {          if ($selfenroll_types ne '*') {
             my ($enrolltypes,$longtypes,$alldoms) =              my ($enrolltypes,$longtypes,$alldoms) =
                 &get_selfenroll_filters($selfenroll_types);                  &get_selfenroll_filters($selfenroll_types);
             $r->print('<br /><br />'.&print_selfenroll_types($longtypes));              $r->print('<br />'.&print_selfenroll_types($longtypes));
         }          }
           my $displayurl = &escape($firsturl);
           $r->print(&mt('Submit a request to the LON-CAPA [_1]helpdesk[_2] for [_3] if you require assistance.','<a href="/adm/helpdesk?origurl='.$displayurl.'">','</a>',$cdomdesc));
     }      }
     $r->print('<form name ="logmein" method="post" action="">'."\n".      $r->print('<form name ="logmein" method="post" action="">'."\n".
               '<input type="hidden" name="setting" value=""/>'."\n".                '<input type="hidden" name="setting" value=""/>'."\n".
Line 264  sub has_role { Line 313  sub has_role {
     my $output;      my $output;
     if ($curr_role{'status'} eq 'active') {      if ($curr_role{'status'} eq 'active') {
           my $rolelink = &jump_to_role($curr_role{'role'});            my $rolelink = &jump_to_role($curr_role{'role'});
           $output = &mt('You currently have an active role (section: "[_1]") in this course.',$curr_role{'section'}).' '.$rolelink;            $output = &mt('You already have an active student role (section: "[_1]") in this course.',$curr_role{'section'}).'<br>'.$rolelink;
     } elsif ($curr_role{'status'} eq 'future') {      } elsif ($curr_role{'status'} eq 'future') {
         $output = &mt('You have a role (section: "[_1]") in this course which will become active [_2].',$curr_role{'section'},$curr_role{'start'});          $output = &mt('You have a student role (section: "[_1]") in this course which will become active [_2].',$curr_role{'section'},$curr_role{'start'});
     }      }
     return $output;      return $output;
 }  }
Line 276  sub process_self_enroll { Line 325  sub process_self_enroll {
         $selfenroll_access_start,$selfenroll_access_end,$selfenroll_section,$now) = @_;          $selfenroll_access_start,$selfenroll_access_end,$selfenroll_section,$now) = @_;
     my $udom = $env{'user.domain'};      my $udom = $env{'user.domain'};
     my $uname = $env{'user.name'};      my $uname = $env{'user.name'};
     my @info = ['inststatus'];  
     my %userhash = &Apache::lonnet::userenvironment($udom,$uname,@info);  
     my ($enrolltypes,$longtypes,$alldoms) =   
         &get_selfenroll_filters($selfenroll_types,$udom);  
     my @inststatuses;  
     if ($userhash{'inststatus'} eq '') {  
         push(@inststatuses,'other');   
     } else {  
         my @esc_statuses = split(/:/,$userhash{'inststatus'});  
         @inststatuses = map { &unescape($_); } (@esc_statuses);  
     }  
     my $selfenroll = 0;      my $selfenroll = 0;
     if ($alldoms) {      my ($enrolltypes,$longtypes,$alldoms);
       if ($selfenroll_types eq '*') {
         $selfenroll = 1;          $selfenroll = 1;
     } elsif (ref($enrolltypes) eq 'HASH') {      } else {
         if (ref($enrolltypes->{$udom}) eq 'ARRAY') {          ($enrolltypes,$longtypes,$alldoms) =
             if (grep(/^any$/,@{$enrolltypes->{$udom}})) {              &get_selfenroll_filters($selfenroll_types,$udom);
                 $selfenroll = 1;          if ($alldoms) {
             } else {              $selfenroll = 1;
                 foreach my $type (@inststatuses) {          } elsif (ref($enrolltypes) eq 'HASH') {
                     if (grep(/^\Q$type\E$/,@{$enrolltypes->{$udom}})) {              if (ref($enrolltypes->{$udom}) eq 'ARRAY') {
                         $selfenroll = 1;                  if (grep(/^any$/,@{$enrolltypes->{$udom}})) {
                         last;                      $selfenroll = 1;
                     }                  } else {
                       $selfenroll = &user_can_selfenroll($udom,$uname,$enrolltypes->{$udom});
                 }                  }
             }              }
         }          }
Line 313  sub process_self_enroll { Line 353  sub process_self_enroll {
             my ($registered,$instsec,$message) = &check_registered($cdom,$cnum);              my ($registered,$instsec,$message) = &check_registered($cdom,$cnum);
             $usec = $instsec;              $usec = $instsec;
             if (!$registered) {              if (!$registered) {
                 $r->print(&mt('Self-enrollment is restricted to students officially registered for this course.').'<br />');                  $r->print('<h3>'.&mt('Self-enrollment unavailable').'</h3>'.&mt('Self-enrollment is restricted to students officially registered for this course.').'<br />');
                 if ($message) {                  if ($message) {
                     $r->print($message);                      $r->print($message);
                 } else {                  } else {
Line 340  sub process_self_enroll { Line 380  sub process_self_enroll {
             &Apache::lonnet::set_userprivs(\%userroles,\%newrole,%newgroups);              &Apache::lonnet::set_userprivs(\%userroles,\%newrole,%newgroups);
             $userroles{'user.role.'.$spec} = $selfenroll_access_start.'.'.$selfenroll_access_end;              $userroles{'user.role.'.$spec} = $selfenroll_access_start.'.'.$selfenroll_access_end;
             &Apache::lonnet::appenv(\%userroles,[$role,'cm']);              &Apache::lonnet::appenv(\%userroles,[$role,'cm']);
               $r->print('<h3>'.&mt('Enrollment process complete').'</h3>');
             if ($selfenroll_access_end && $selfenroll_access_end <= $now) {              if ($selfenroll_access_end && $selfenroll_access_end <= $now) {
                 $r->print(&mt('The end date for access to this course for users who self-enroll has passed.').'<br />'.&mt('Consequently, although a new role was created for you in the course, it is an inactive role which does not provide access to the course.'));                  $r->print(&mt('The end date for access to this course for users who self-enroll has passed.').'<br />'.&mt('Consequently, although a new role was created for you in the course, it is an inactive role which does not provide access to the course.'));
             } else {              } else {
Line 359  sub process_self_enroll { Line 400  sub process_self_enroll {
                 }                  }
             }              }
         } else {          } else {
             $r->print(&mt('Self-enrollment in this course failed.'));              $r->print('<h3>'.&mt('Enrollment incomplete').'</h3>'.
                         &mt('Self-enrollment in this course failed.'));
             if ($enrollresult ne '') {              if ($enrollresult ne '') {
                 $r->print('<span class="LC_error">'.$enrollresult.'</span>');                  $r->print('<span class="LC_error">'.$enrollresult.'</span>');
             }              }
         }          }
     } else {      } else {
         $r->print(&mt('You are not permitted to enroll yourself in this course.').'<br />');          $r->print('<h3>'.&mt('Self-enrollment unavailable').'</h3>'.
                     &mt('You are not permitted to enroll yourself in this course.').'<br />');
         $r->print(&print_selfenroll_types($longtypes));          $r->print(&print_selfenroll_types($longtypes));
     }      }
     return;      return;
 }  }
   
   sub user_can_selfenroll {
       my ($udom,$uname,$domenrolltypes) = @_;
       my $selfenroll = 0;
       my @info = ['inststatus'];
       my %userhash = &Apache::lonnet::userenvironment($udom,$uname,@info);
       my @inststatuses;
       if ($userhash{'inststatus'} eq '') {
           push(@inststatuses,'other');
       } else {
           my @esc_statuses = split(/:/,$userhash{'inststatus'});
           @inststatuses = map { &unescape($_); } (@esc_statuses);
       }
       foreach my $type (@inststatuses) {
           if (ref($domenrolltypes) eq 'ARRAY') {
               if (grep(/^\Q$type\E$/,@{$domenrolltypes})) {
                   $selfenroll = 1;
                   last;
               }
           }
       }
       return $selfenroll;
   }
   
 sub jump_to_role {  sub jump_to_role {
     my ($role) = @_;      my ($role) = @_;
     my $output = <<"END";      my $output = <<"END";
Line 383  function SelectRole() { Line 449  function SelectRole() {
 END  END
     $output .= '<a href="javascript:SelectRole()">'."\n".       $output .= '<a href="javascript:SelectRole()">'."\n". 
                &mt('Enter course now').'</a>'."\n".                 &mt('Enter course now').'</a>'."\n".
                '<form name="rolechoice" action="/adm/roles">'."\n".                 '<form name="rolechoice" action="/adm/roles" method="post">'."\n".
                '<input type="hidden" name="selectrole" value="" />'."\n".                 '<input type="hidden" name="selectrole" value="" />'."\n".
                '<input type="hidden" name="'.$role.'" value="1" />'."\n".                 '<input type="hidden" name="'.$role.'" value="1" />'."\n".
                '</form>';                 '</form>';
Line 409  sub get_selfenroll_filters { Line 475  sub get_selfenroll_filters {
                 my ($othertitle,$usertypes,$types) =                  my ($othertitle,$usertypes,$types) =
                     &Apache::loncommon::sorted_inst_types($selfdom);                      &Apache::loncommon::sorted_inst_types($selfdom);
                 if (ref($usertypes) eq 'HASH') {                  if (ref($usertypes) eq 'HASH') {
                     $usertypes->{'any'} = &mt('any');                      my $anytype = 1;
                     $usertypes->{'other'} = &mt('other');                      foreach my $key (keys(%{$usertypes})) {
                     @{$enrolltypes{$selfdom}} = @types;                          if (!grep(/^\Q$key\E$/,@types)) {
                     @{$longtypes{$selfdom}} = map {$usertypes->{$_}} @types;                              $anytype = 0;
                               last;
                           }
                       }
                       if ($anytype) {
                           if (!(grep(/^other$/,@types))) {
                               $anytype = 0;
                           }
                       }
                       $usertypes->{'any'} = &mt('Any users');
                       $usertypes->{'other'} = &mt('Others');
                       if ($anytype) {
                           @{$enrolltypes{$selfdom}} = ('any');
                       } else {
                           @{$enrolltypes{$selfdom}} = @types;
                       }
                       @{$longtypes{$selfdom}} = 
                           map {$usertypes->{$_}} @{$enrolltypes{$selfdom}}
                 }                  }
             }              }
         }          }
Line 424  sub print_selfenroll_types { Line 507  sub print_selfenroll_types {
     my ($longtypes,$domain) = @_;      my ($longtypes,$domain) = @_;
     my $output;      my $output;
     if (ref($longtypes) eq 'HASH') {      if (ref($longtypes) eq 'HASH') {
         if (keys(%{$longtypes}) > 0) {          if ($domain ne '') {
             if ($domain ne '') {              my $domdesc = &Apache::lonnet::domain($domain,'description');
                 if (ref($longtypes->{$domain}) eq 'ARRAY') {              if (ref($longtypes->{$domain}) eq 'ARRAY') {
                     if (grep(/^any$/,@{$longtypes->{$domain}})) {                  if (grep(/^any$/,@{$longtypes->{$domain}})) {
                         $output = &mt('Self-enrollment in this course is only available to users in domain "[_1]".',$domain);                      $output = &mt('Self-enrollment in this course is available to any user affiliated with [_1].',$domdesc);
                     } else {                  } else {
                         my $status_str = join(', ',@{$longtypes->{$domain}});                      my $status_str = join(', ',@{$longtypes->{$domain}});
                         $output = &mt('Self-enrollment in this course is only available to users in domain "[_1]" who have the following status: "[_2]".',$domain,$status_str);                      $output = &mt('Self-enrollment in this course is only available to users affiliated with [_1] who have the following status: "[_2]".',$domdesc,$status_str);
                     }  
                 }                  }
             } else {              } else {
                 $output = &mt('Self-enrollment in this course is only available to users in the following domains (with the following status):').' <ul>';                  $output = &mt('Self-enrollment is not currently available for this course for users affiliated with [_1].',$domdesc);
                 foreach my $selfdom (sort(keys(%{$longtypes}))) {              }
                     if (ref($longtypes->{$selfdom}) eq 'ARRAY') {          } elsif (keys(%{$longtypes}) > 0) {
                         $output .= '<li>'.$selfdom.': '.join(', ',@{$longtypes->{$selfdom}}).'</li>';              $output = &mt('Self-enrollment in this course is only available to users affiliated with the following institutions, and who have the required status:').' <ul>';
                     }              foreach my $selfdom (sort(keys(%{$longtypes}))) {
                   my $selfdomdesc = &Apache::lonnet::domain($selfdom,'description');
                   if (ref($longtypes->{$selfdom}) eq 'ARRAY') {
                       $output .= '<li>'.$selfdomdesc.': '.join(', ',@{$longtypes->{$selfdom}}).'</li>';
                 }                  }
                 $output .= '</ul>';  
             }              }
               $output .= '</ul>';
         } else {          } else {
             $output = &mt('Self-enrollment is not currently available for this course.');              $output = &mt('Self-enrollment is not currently available for this course.');
         }          }

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


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