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

raeburn lon-capa-cvs-allow@mail.lon-capa.org
Thu, 17 Jul 2008 12:22:28 -0000


This is a MIME encoded message

--raeburn1216297348
Content-Type: text/plain

raeburn		Thu Jul 17 08:22:28 2008 EDT

  Modified files:              
    /loncom/interface	selfenroll.pm 
  Log:
  - Breadcrumbs added to facilitate retreat to course catalog or initial self-enrollment page.
  - &page_footer() added to provide backupcrumba form used to store catalog filters used originally.
  - &Apache::createaccount::catreturn_js() used to generate getFormByName() and getIndexByName() javascript.
  - &Apache::createaccount::selfenroll_crumbs() used to generate breadcrumbs.
  - setPath() javascript function takes new first argument - formname - now page can have multiple forms.
  - logmein form now includes echo of catalog search form elements so subsequent screens generated by createaccount.pm can include irteurn to course catalog in breadcrumbs.    
  - form element cid renamed courseid (and $cid renamed $courseid) to avoid confusing this with the cid form element used for entering a studentID in loncreateuser:personal_data_display().
  
  
--raeburn1216297348
Content-Type: text/plain
Content-Disposition: attachment; filename="raeburn-20080717082228.txt"

Index: loncom/interface/selfenroll.pm
diff -u loncom/interface/selfenroll.pm:1.11 loncom/interface/selfenroll.pm:1.12
--- loncom/interface/selfenroll.pm:1.11	Mon Jul 14 06:25:25 2008
+++ loncom/interface/selfenroll.pm	Thu Jul 17 08:22:28 2008
@@ -1,7 +1,7 @@
 # The LearningOnline Network
 # Allow users to self-enroll in a course
 #
-# $Id: selfenroll.pm,v 1.11 2008/07/14 10:25:25 raeburn Exp $
+# $Id: selfenroll.pm,v 1.12 2008/07/17 12:22:28 raeburn Exp $
 #
 # Copyright Michigan State University Board of Trustees
 #
@@ -51,34 +51,35 @@
     }
     &Apache::lonacc::get_posted_cgi($r);
     &Apache::lonlocal::get_language_handle($r);
-    &Apache::loncommon::get_unprocessed_cgi($ENV{'QUERY_STRING'},['cid']);
-    my ($coursechk,$cid) = &validate_course_id($env{'form.cid'});
+    &Apache::loncommon::get_unprocessed_cgi($ENV{'QUERY_STRING'},['courseid']);
+    my $js = &Apache::createaccount::catreturn_js();
+    my $desc;
+    my ($coursechk,$courseid) = &validate_course_id($env{'form.courseid'});
     if ($coursechk ne 'ok') {
-        &page_header($r,$cid);
+        &page_header($r,$courseid,$js);
         $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());
+        &page_footer($r);
         return OK;
     }
     my $now = time;
-    my $js;
     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');
     if ($env{'form.phase'} eq 'login') {
         my $jsh=Apache::File->new($include."/londes.js");
         $r->print(<$jsh>);
     }
-    my ($cdom,$cnum,$desc,$canenroll,$selfenroll_types,$selfenroll_registered,
-        @cancreate,$knownuser,$selfenroll_access_start,$selfenroll_access_end,
-        $selfenroll_section,$selfenroll_future,%curr_role,%coursehash,$cdomdesc);
-    %coursehash = &Apache::lonnet::coursedescription($cid);
-    $cdom = $coursehash{'domain'};
-    $cnum = $coursehash{'num'};
-    $desc = $coursehash{'description'};
+    my ($canenroll,$selfenroll_types,$selfenroll_registered,@cancreate,
+        $knownuser,$selfenroll_access_start,$selfenroll_access_end,
+        $selfenroll_section,$selfenroll_future,%curr_role,$cdomdesc);
     $selfenroll_types = $coursehash{'internal.selfenroll_types'};
     $selfenroll_registered =  $coursehash{'internal.selfenroll_registered'};
     $selfenroll_section = $coursehash{'internal.selfenroll_section'};
@@ -167,13 +168,14 @@
         if (keys(%curr_role)) {
             $r->print(&has_role(%curr_role));
         }
-        $r->print(&Apache::loncommon::end_page());
+        &page_footer($r);
         return OK;
     }
     @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';
-    $firsturl= '/adm/selfenroll?cid='.$cid;
+    $firsturl= '/adm/selfenroll?courseid='.$courseid;
     $create_path = '/adm/createaccount';
     $sso_url = $r->dir_config('lonSSOReloginServer');
     if ($sso_url eq '') {
@@ -184,7 +186,7 @@
         if (keys(%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());
+            &page_footer($r);
             return OK;
         }
         &process_self_enroll($r,$cdom,$cnum,$selfenroll_types,$selfenroll_registered,
@@ -194,41 +196,36 @@
         my $submit_text = &mt('Log in');
         $r->print('<h3>'.&mt('Log-in to LON-CAPA').'</h3>');
         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'));
-        $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());
+        $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>'));
+        &page_footer($r);
         return OK;
     } elsif (@cancreate > 0) {
         $r->print(<<END);
 <script type="text/javascript">
-function setPath(formaction,item,arg) {
-    if (formaction != '') {
-        document.forms.logmein.action = formaction;
-    }
-    var itemid = getIndexByName("setting");
-    if (itemid > -1) {
-        document.logmein.elements[itemid].name = item;
-        document.logmein.elements[itemid].value = arg;
-        document.logmein.submit();
-    } else {
-        alert("$missing_formitem");
+function setPath(formname,formaction,item,arg) {
+    var formidx = getFormByName(formname);
+    if (formidx > -1) {
+        if (formaction != '') {
+            document.forms[formidx].action = formaction;
+        }
+        var itemid = getIndexByName(formidx,'setting');
+        if (itemid > -1) {
+            document.forms[formidx].elements[itemid].name = item;
+            document.forms[formidx].elements[itemid].value = arg;
+            document.forms[formidx].submit();
+        } else {
+            alert("$missing_formitem");
+        }
     }
     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>
 END
         $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) {
             $r->print('<li>'.&mt('Otherwise:').'<br />');
             my $count = 0;
@@ -238,11 +235,11 @@
                 }
                 if (grep(/^$type$/,@cancreate)) {
                     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') {
-                        $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') {
-                        $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 ++;
                 }
@@ -250,11 +247,11 @@
             $r->print('.<br />');
         } else {
             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') {
-                $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') {
-                $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 '*') {
@@ -277,34 +274,41 @@
         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".
-              '<input type="hidden" name=cid" value="'.$cid.'" />'."\n".
+    $r->print("\n".'<form name="'.$form.'" method="post" action="">'."\n".
+              '<input type="hidden" name="courseid" value="'.$courseid.'" />'."\n".
               '<input type="hidden" name="setting" value=""/>'."\n".
-              '</form>'."\n".
-              &Apache::loncommon::end_page());
+              &Apache::lonhtmlcommon::echo_form_input(['backto','courseid','context','phase'])."\n".
+              '</form>'."\n");
+              &page_footer($r);
     return OK;
 }
 
 sub page_header {
-    my ($r,$cid,$js) = @_;
+    my ($r,$courseid,$js,$desc) = @_;
     my $start_page =
         &Apache::loncommon::start_page('Self-enroll in a LON-CAPA course',$js,
                                        {'no_inline_link'   => 1,});
     $r->print($start_page);
     &Apache::lonhtmlcommon::clear_breadcrumbs();
-    &Apache::lonhtmlcommon::add_breadcrumb
-                       ({href=>"/adm/selfenroll?cid=$cid",
-                         text=>"Self-enroll"});
+    &Apache::createaccount::selfenroll_crumbs($r,$courseid,$desc);
     $r->print(&Apache::lonhtmlcommon::breadcrumbs('Self-enroll in course'));
     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 {
-    my ($cid) = @_;
-    my ($cdom,$cnum) = ($env{'form.cid'} =~ /^($match_domain)_($match_courseid)$/);
+    my ($courseid) = @_;
+    my ($cdom,$cnum) = ($env{'form.courseid'} =~ /^($match_domain)_($match_courseid)$/);
     if ($cdom ne '' && $cnum ne '') {
         if (&Apache::lonnet::is_course($cdom,$cnum)) {
-            return ('ok',$cid);
+            return ('ok',$courseid);
         }
     } 
     return;
@@ -552,14 +556,14 @@
                 $output = &mt('Self-enrollment is not currently available for this course for users affiliated with [_1].',$domdesc);
             }
         } 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}))) {
                 my $selfdomdesc = &Apache::lonnet::domain($selfdom,'description');
                 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 {
             $output = &mt('Self-enrollment is not currently available for this course.');
         }

--raeburn1216297348--