Diff for /loncom/interface/selfenroll.pm between versions 1.11 and 1.12

version 1.11, 2008/07/14 10:25:25 version 1.12, 2008/07/17 12:22:28
Line 51  sub handler { Line 51  sub handler {
     }      }
     &Apache::lonacc::get_posted_cgi($r);      &Apache::lonacc::get_posted_cgi($r);
     &Apache::lonlocal::get_language_handle($r);      &Apache::lonlocal::get_language_handle($r);
     &Apache::loncommon::get_unprocessed_cgi($ENV{'QUERY_STRING'},['cid']);      &Apache::loncommon::get_unprocessed_cgi($ENV{'QUERY_STRING'},['courseid']);
     my ($coursechk,$cid) = &validate_course_id($env{'form.cid'});      my $js = &Apache::createaccount::catreturn_js();
       my $desc;
       my ($coursechk,$courseid) = &validate_course_id($env{'form.courseid'});
     if ($coursechk ne 'ok') {      if ($coursechk ne 'ok') {
         &page_header($r,$cid);          &page_header($r,$courseid,$js);
         $r->print('<h3>'.&mt('Self-enrollment error').'</h3>'.          $r->print('<h3>'.&mt('Self-enrollment error').'</h3>'.
                   '<span class="LC_error">'.                    '<span class="LC_error">'.
                   &mt('Invalid domain or course number').'</span>');                    &mt('Invalid domain or course number').'</span>');
         $r->print(&Apache::loncommon::end_page());          &page_footer($r);
         return OK;          return OK;
     }      }
     my $now = time;      my $now = time;
     my $js;  
     if ($env{'form.phase'} eq 'login') {      if ($env{'form.phase'} eq 'login') {
         $js = &Apache::createaccount::javascript_setforms($now);          $js .= "\n".&Apache::createaccount::javascript_setforms($now);
     }      }
     &page_header($r,$cid,$js);      my %coursehash = &Apache::lonnet::coursedescription($courseid);
       my $cdom = $coursehash{'domain'};
       my $cnum = $coursehash{'num'};
       my $desc = $coursehash{'description'};
       &page_header($r,$courseid,$js,$desc);
     my $include = $r->dir_config('lonIncludes');      my $include = $r->dir_config('lonIncludes');
     if ($env{'form.phase'} eq 'login') {      if ($env{'form.phase'} eq 'login') {
         my $jsh=Apache::File->new($include."/londes.js");          my $jsh=Apache::File->new($include."/londes.js");
         $r->print(<$jsh>);          $r->print(<$jsh>);
     }      }
     my ($cdom,$cnum,$desc,$canenroll,$selfenroll_types,$selfenroll_registered,      my ($canenroll,$selfenroll_types,$selfenroll_registered,@cancreate,
         @cancreate,$knownuser,$selfenroll_access_start,$selfenroll_access_end,          $knownuser,$selfenroll_access_start,$selfenroll_access_end,
         $selfenroll_section,$selfenroll_future,%curr_role,%coursehash,$cdomdesc);          $selfenroll_section,$selfenroll_future,%curr_role,$cdomdesc);
     %coursehash = &Apache::lonnet::coursedescription($cid);  
     $cdom = $coursehash{'domain'};  
     $cnum = $coursehash{'num'};  
     $desc = $coursehash{'description'};  
     $selfenroll_types = $coursehash{'internal.selfenroll_types'};      $selfenroll_types = $coursehash{'internal.selfenroll_types'};
     $selfenroll_registered =  $coursehash{'internal.selfenroll_registered'};      $selfenroll_registered =  $coursehash{'internal.selfenroll_registered'};
     $selfenroll_section = $coursehash{'internal.selfenroll_section'};      $selfenroll_section = $coursehash{'internal.selfenroll_section'};
Line 167  sub handler { Line 168  sub handler {
         if (keys(%curr_role)) {          if (keys(%curr_role)) {
             $r->print(&has_role(%curr_role));              $r->print(&has_role(%curr_role));
         }          }
         $r->print(&Apache::loncommon::end_page());          &page_footer($r);
         return OK;          return OK;
     }      }
     @cancreate = &can_create($cdom);      @cancreate = &can_create($cdom);
     my ($login_path,$firsturl,$create_path,$sso_url,$missing_formitem);      my ($form,$login_path,$firsturl,$create_path,$sso_url,$missing_formitem);
       $form = 'logmein';
     $login_path = '/adm/login';      $login_path = '/adm/login';
     $firsturl= '/adm/selfenroll?cid='.$cid;      $firsturl= '/adm/selfenroll?courseid='.$courseid;
     $create_path = '/adm/createaccount';      $create_path = '/adm/createaccount';
     $sso_url = $r->dir_config('lonSSOReloginServer');      $sso_url = $r->dir_config('lonSSOReloginServer');
     if ($sso_url eq '') {      if ($sso_url eq '') {
Line 184  sub handler { Line 186  sub handler {
         if (keys(%curr_role)) {          if (keys(%curr_role)) {
             $r->print('<h3>'.&mt('Self-enrollment unavailable').'</h3>'.              $r->print('<h3>'.&mt('Self-enrollment unavailable').'</h3>'.
                       '<span class="LC_warning">'.&has_role(%curr_role).'</span>');                        '<span class="LC_warning">'.&has_role(%curr_role).'</span>');
             $r->print(&Apache::loncommon::end_page());              &page_footer($r);
             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 194  sub handler { Line 196  sub handler {
         my $submit_text = &mt('Log in');          my $submit_text = &mt('Log in');
         $r->print('<h3>'.&mt('Log-in to LON-CAPA').'</h3>');          $r->print('<h3>'.&mt('Log-in to LON-CAPA').'</h3>');
         my $udom = &Apache::lonnet::default_login_domain();          my $udom = &Apache::lonnet::default_login_domain();
         $r->print(&Apache::createaccount::login_box($now,$lonhost,$cid,          $r->print(&Apache::createaccount::login_box($now,$lonhost,$courseid,
                                            $submit_text,$udom,'selfenroll'));                                             $submit_text,$udom,'selfenroll'));
         $r->print(&mt('You will be able to self-enroll in the course you selected ([_1]) after you have successfully logged in.','<b>'.$desc.'</b>').          $r->print(&mt('You will be able to self-enroll in the course you selected ([_1]) after you have successfully logged in.','<b>'.$desc.'</b>'));
                   &Apache::loncommon::end_page());          &page_footer($r);
         return OK;          return OK;
     } elsif (@cancreate > 0) {      } elsif (@cancreate > 0) {
         $r->print(<<END);          $r->print(<<END);
 <script type="text/javascript">  <script type="text/javascript">
 function setPath(formaction,item,arg) {  function setPath(formname,formaction,item,arg) {
     if (formaction != '') {      var formidx = getFormByName(formname);
         document.forms.logmein.action = formaction;      if (formidx > -1) {
     }          if (formaction != '') {
     var itemid = getIndexByName("setting");              document.forms[formidx].action = formaction;
     if (itemid > -1) {          }
         document.logmein.elements[itemid].name = item;          var itemid = getIndexByName(formidx,'setting');
         document.logmein.elements[itemid].value = arg;          if (itemid > -1) {
         document.logmein.submit();              document.forms[formidx].elements[itemid].name = item;
     } else {              document.forms[formidx].elements[itemid].value = arg;
         alert("$missing_formitem");              document.forms[formidx].submit();
           } else {
               alert("$missing_formitem");
           }
     }      }
     return;      return;
 }  }
   
 function getIndexByName(item) {  
     for (var i=0;i<document.logmein.elements.length;i++) {  
         if (document.logmein.elements[i].name == item) {  
             return i;  
         }  
     }  
     return -1;  
 }  
 </script>  </script>
 END  END
         $r->print('<h3>'.&mt('LON-CAPA account required').'</h3>'.          $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('."'','phase','login'".')">','</a>').'</li>');                    &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('."'$form','','phase','login'".')">','</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 238  END Line 235  END
                 }                  }
                 if (grep(/^$type$/,@cancreate)) {                  if (grep(/^$type$/,@cancreate)) {
                     if ($type eq 'sso') {                      if ($type eq 'sso') {
                         $r->print('&nbsp;&nbsp;'.&mt("if you have an institutional log-in, use your institution's [_1]single sign on page[_2] to log-in, then create an account",'<a href="javascript:setPath('."'$sso_url','firsturl','$firsturl'".')">','</a>'));                          $r->print('&nbsp;&nbsp;'.&mt("if you have an institutional log-in, use your institution's [_1]single sign on page[_2] to log-in, then create an account",'<a href="javascript:setPath('."'$form','$sso_url','firsturl','$firsturl'".')">','</a>'));
                     } elsif ($type eq 'login') {                      } elsif ($type eq 'login') {
                         $r->print('&nbsp;&nbsp;'.&mt('if you have an institutional login, [_1]create an account[_2]','<a href="javascript:setPath('."'$create_path','courseid','$cid'".')">','</a>'));                          $r->print('&nbsp;&nbsp;'.&mt('if you have an institutional login, [_1]create an account[_2]','<a href="javascript:setPath('."'$form','$create_path','context','selfenroll_create'".')">','</a>'));
                     } elsif ($type eq 'email') {                      } elsif ($type eq 'email') {
                         $r->print('&nbsp;&nbsp;'.&mt('you can use an e-mail address to [_1]create an account[_2]','<a href="javascript:setPath('."'$create_path','courseid','$cid'".')">','</a>'));                          $r->print('&nbsp;&nbsp;'.&mt('you can use an e-mail address to [_1]create an account[_2]','<a href="javascript:setPath('."'$form','$create_path','context','selfenroll_create'".')">','</a>'));
                     }                      }
                     $count ++;                      $count ++;
                 }                  }
Line 250  END Line 247  END
             $r->print('.<br />');              $r->print('.<br />');
         } else {          } else {
             if ($cancreate[0] eq 'login') {              if ($cancreate[0] eq 'login') {
                 $r->print('<li>'.&mt('Otherwise, if you have an institutional login, [_1]create an account[_2].','<a href="javascript:setPath('."'$create_path','courseid','$cid'".')">','</a>'));                  $r->print('<li>'.&mt('Otherwise, if you have an institutional login, [_1]create an account[_2].','<a href="javascript:setPath('."'$form','$create_path','context','selfenroll_create'".')">','</a>'));
             } elsif ($cancreate[0] eq 'email') {              } elsif ($cancreate[0] eq 'email') {
                 $r->print('<li>'.&mt('Otherwise, you will use an e-mail address to [_1]create an account[_2].','<a href="javascript:setPath('."'$create_path','courseid','$cid'".')">','</a>'));                  $r->print('<li>'.&mt('Otherwise, you will use an e-mail address to [_1]create an account[_2].','<a href="javascript:setPath('."'$form','$create_path','context','selfenroll_create'".')">','</a>'));
             } elsif ($cancreate[0] eq 'sso') {              } elsif ($cancreate[0] eq 'sso') {
                 $r->print('<li>'.&mt("Otherwise, use your institution's [_1]single sign on page[_2] to log-in, then create an account.",'<a href="javascript:setPath('."'$sso_url','firsturl','$firsturl'".')">','</a>'));                  $r->print('<li>'.&mt("Otherwise, use your institution's [_1]single sign on page[_2] to log-in, then create an account.",'<a href="javascript:setPath('."'$form','$sso_url','firsturl','$firsturl'".')">','</a>'));
             }              }
         }          }
         if ($selfenroll_types eq '*') {          if ($selfenroll_types eq '*') {
Line 277  END Line 274  END
         my $displayurl = &escape($firsturl);          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(&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("\n".'<form name="'.$form.'" method="post" action="">'."\n".
               '<input type="hidden" name=cid" value="'.$cid.'" />'."\n".                '<input type="hidden" name="courseid" value="'.$courseid.'" />'."\n".
               '<input type="hidden" name="setting" value=""/>'."\n".                '<input type="hidden" name="setting" value=""/>'."\n".
               '</form>'."\n".                &Apache::lonhtmlcommon::echo_form_input(['backto','courseid','context','phase'])."\n".
               &Apache::loncommon::end_page());                '</form>'."\n");
                 &page_footer($r);
     return OK;      return OK;
 }  }
   
 sub page_header {  sub page_header {
     my ($r,$cid,$js) = @_;      my ($r,$courseid,$js,$desc) = @_;
     my $start_page =      my $start_page =
         &Apache::loncommon::start_page('Self-enroll in a LON-CAPA course',$js,          &Apache::loncommon::start_page('Self-enroll in a LON-CAPA course',$js,
                                        {'no_inline_link'   => 1,});                                         {'no_inline_link'   => 1,});
     $r->print($start_page);      $r->print($start_page);
     &Apache::lonhtmlcommon::clear_breadcrumbs();      &Apache::lonhtmlcommon::clear_breadcrumbs();
     &Apache::lonhtmlcommon::add_breadcrumb      &Apache::createaccount::selfenroll_crumbs($r,$courseid,$desc);
                        ({href=>"/adm/selfenroll?cid=$cid",  
                          text=>"Self-enroll"});  
     $r->print(&Apache::lonhtmlcommon::breadcrumbs('Self-enroll in course'));      $r->print(&Apache::lonhtmlcommon::breadcrumbs('Self-enroll in course'));
     return;      return;
 }  }
   
   sub page_footer {
       my ($r) = @_;
       $r->print('<form name="backupcrumbs" method="post" action="/adm/coursecatalog">'."\n".
                 &Apache::lonhtmlcommon::echo_form_input(['backto','courseid','phase','context']).
                 '</form>'.&Apache::loncommon::end_page());
       return;
   }
   
 sub validate_course_id {  sub validate_course_id {
     my ($cid) = @_;      my ($courseid) = @_;
     my ($cdom,$cnum) = ($env{'form.cid'} =~ /^($match_domain)_($match_courseid)$/);      my ($cdom,$cnum) = ($env{'form.courseid'} =~ /^($match_domain)_($match_courseid)$/);
     if ($cdom ne '' && $cnum ne '') {      if ($cdom ne '' && $cnum ne '') {
         if (&Apache::lonnet::is_course($cdom,$cnum)) {          if (&Apache::lonnet::is_course($cdom,$cnum)) {
             return ('ok',$cid);              return ('ok',$courseid);
         }          }
     }       } 
     return;      return;
Line 552  sub print_selfenroll_types { Line 556  sub print_selfenroll_types {
                 $output = &mt('Self-enrollment is not currently available for this course for users affiliated with [_1].',$domdesc);                  $output = &mt('Self-enrollment is not currently available for this course for users affiliated with [_1].',$domdesc);
             }              }
         } elsif (keys(%{$longtypes}) > 0) {          } elsif (keys(%{$longtypes}) > 0) {
             $output = &mt('Self-enrollment in this course is only available to users affiliated with the following institutions, and who have the required status:').' <ul>';              $output = &mt('Self-enrollment in this course is only available to users affiliated with the following institutions, and who have the required status:').' <ul>'."\n";
             foreach my $selfdom (sort(keys(%{$longtypes}))) {              foreach my $selfdom (sort(keys(%{$longtypes}))) {
                 my $selfdomdesc = &Apache::lonnet::domain($selfdom,'description');                  my $selfdomdesc = &Apache::lonnet::domain($selfdom,'description');
                 if (ref($longtypes->{$selfdom}) eq 'ARRAY') {                  if (ref($longtypes->{$selfdom}) eq 'ARRAY') {
                     $output .= '<li>'.$selfdomdesc.': '.join(', ',@{$longtypes->{$selfdom}}).'</li>';                      $output .= '<li>'.$selfdomdesc.': '.join(', ',@{$longtypes->{$selfdom}}).'</li>'."\n";
                 }                  }
             }              }
             $output .= '</ul>';              $output .= '</ul>'."\n";
         } 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.11  
changed lines
  Added in v.1.12


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