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

raeburn raeburn@source.lon-capa.org
Tue, 11 Jan 2011 04:28:52 -0000


raeburn		Tue Jan 11 04:28:52 2011 EDT

  Modified files:              
    /loncom/interface	lonrequestcourse.pm 
  Log:
  - For official courses, where institutional code defined and auto-enroll enabled:
      - include textboxes for input of institutional section if no official sections known. 
  - A single help icon for multiple crosslisting rows.
  
  
Index: loncom/interface/lonrequestcourse.pm
diff -u loncom/interface/lonrequestcourse.pm:1.60 loncom/interface/lonrequestcourse.pm:1.61
--- loncom/interface/lonrequestcourse.pm:1.60	Wed Jan  5 18:47:46 2011
+++ loncom/interface/lonrequestcourse.pm	Tue Jan 11 04:28:52 2011
@@ -1,7 +1,7 @@
 # The LearningOnline Network
 # Request a course
 #
-# $Id: lonrequestcourse.pm,v 1.60 2011/01/05 18:47:46 raeburn Exp $
+# $Id: lonrequestcourse.pm,v 1.61 2011/01/11 04:28:52 raeburn Exp $
 #
 # Copyright Michigan State University Board of Trustees
 #
@@ -556,7 +556,6 @@
     }
     if (&Apache::lonnet::auto_run('',$dom)) {
         my %extras = (
-                       sectotal           => 'hidden',
                        enrollstart_month  => 'selectbox',
                        enrollstart_hour   => 'selectbox',
                        enrollend_month    => 'selectbox',
@@ -572,12 +571,30 @@
                        addcrosslist       => 'checkbox',
                        autoadds           => 'radio',
                        autodrops          => 'radio',
-                     );
-        if ($env{'form.sectotal'} > 0) {
-            for (my $i=0; $i<$env{'form.sectotal'}; $i++) {
-                $extras{'sec_'.$i} = 'radio';
-                $extras{'secnum_'.$i} = 'text';
-                $extras{'loncapasec_'.$i} = 'text';
+        );
+        my ($instcode,$titlescount) = &get_instcode($dom);
+        if ($instcode) {
+            my @sections = &Apache::lonnet::auto_get_sections(undef,$dom,$instcode);
+            if (@sections) {
+                $extras{'sectotal'} = 'hidden';
+                if ($env{'form.sectotal'} > 0) {
+                    for (my $i=0; $i<$env{'form.sectotal'}; $i++) {
+                        $extras{'sec_'.$i} = 'radio';
+                        $extras{'secnum_'.$i} = 'text';
+                        $extras{'loncapasec_'.$i} = 'text';
+                    }
+                }
+            } else {
+                $extras{'addsection'} = 'checkbox';
+                my $sectotal = $env{'form.sectotal'};
+                if ($env{'form.addsection'}) {
+                    $sectotal ++;
+                }
+                for (my $i=0; $i<$sectotal; $i++) {
+                    $extras{'sec_'.$i} = 'checkbox';
+                    $extras{'secnum_'.$i} = 'text',
+                    $extras{'loncapasec_'.$i} = 'text',
+                }
             }
         }
         my $crosslisttotal = $env{'form.crosslisttotal'};
@@ -587,7 +604,6 @@
         if (!$crosslisttotal) {
             $crosslisttotal = 1;
         }
-
         for (my $i=0; $i<$env{'form.crosslisttotal'}; $i++) {
             if ($numtitles) {
                 $extras{'crosslist_'.$i.'_'.$lastitem} = 'text';
@@ -1468,7 +1484,7 @@
         }
     }
     if ($state eq 'enrollment') {
-        push(@excluded,'crosslisttotal');
+        push(@excluded,('sectotal','crosslisttotal'));
     }
     $r->print(&Apache::lonhtmlcommon::echo_form_input(\@excluded).'</form>');
     &display_navbuttons($r,$dom,$formname,$prev,$navtxt{'prev'},$next,
@@ -1577,7 +1593,29 @@
         if (&Apache::lonnet::auto_run('',$dom)) {
             $output = &show_invalid_crosslists($invalidcrosslist);
             my ($section_form,$crosslist_form);
-            $section_form = &inst_section_selector($dom,$instcode);
+            if ($instcode ne '') {
+                $section_form = &inst_section_selector($dom,$instcode);
+                if ($section_form eq '') {
+                    my $sectotal = $env{'form.sectotal'};
+                    if (!$sectotal) {
+                        $sectotal = 1;
+                    }
+                    if ($env{'form.addsection'}) {
+                        $sectotal ++;
+                    }
+                    for (my $i=0; $i<$sectotal; $i++) {
+                        $section_form .= &sections_form($dom,$instcode,$i);
+                    }
+                    if ($section_form) {
+                        $section_form .=
+                    &Apache::lonhtmlcommon::row_title(&mt('Add another')).
+                    '<input name="sectotal" type="hidden" value="'.$sectotal.'" />'.
+                    '<input name="addsection" type="checkbox" value="'.$sectotal.'"'.
+                    ' onclick="javascript:nextPage(document.'.$formname.",'".$env{'form.state'}.
+                   "'".');" />'.&mt('Add?').&Apache::lonhtmlcommon::row_closure();
+                    }
+                }
+            }
             if ($section_form) {
                 $sections = &Apache::lonhtmlcommon::row_headline().
                             '<h3>'.&Apache::loncommon::help_open_topic('Course_Request_Sections').
@@ -1604,7 +1642,7 @@
                     ' onclick="javascript:nextPage(document.'.$formname.",'".$env{'form.state'}.
                    "'".');" />'.&mt('Add?').&Apache::lonhtmlcommon::row_closure();
                 $sections .=  &Apache::lonhtmlcommon::row_headline.
-                              '<h3>'.&mt('Crosslisted courses for auto-enrollment').'</h3>'.
+                              '<h3>'.&Apache::loncommon::help_open_topic('Course_Request_Crosslist').'&nbsp;'.&mt('Crosslisted courses for auto-enrollment').'</h3>'.
                               &Apache::lonhtmlcommon::row_closure(1).
                               $crosslist_form;
             }
@@ -2862,7 +2900,6 @@
                    );
     my %helpitem = ( 
                      instcode => 'Course_Request_Category',
-                     crosslist => 'Course_Request_Crosslist',
                    );
     if ((ref($codetitles) eq 'ARRAY') && (ref($cat_titles) eq 'HASH') && 
         (ref($cat_order))) {
@@ -2879,7 +2916,11 @@
             my $lastitem = pop(@{$codetitles});
             my $lastinput = '<input type="text" size="5" name="'.$sel.'_'.                                            $lastitem.'" />';
             if (@{$codetitles} > 0) {
-                $output = &Apache::lonhtmlcommon::row_title(&Apache::loncommon::help_open_topic($helpitem{$context}).'&nbsp;'.$rowtitle{$context}).
+                my $helplink;
+                if (defined($helpitem{$context})) {
+                    $helplink = &Apache::loncommon::help_open_topic($helpitem{$context}).'&nbsp;';
+                }
+                $output = &Apache::lonhtmlcommon::row_title($helplink.$rowtitle{$context}).
                           '<table><tr>';
                 if ($context eq 'crosslist') {
                     $output .= '<td>'.&mt('Include?').'<br />'.
@@ -2944,6 +2985,26 @@
     return $output;
 }
 
+sub sections_form {
+    my ($dom,$instcode,$num) = @_;
+    my $rowtitle;
+    if ($instcode eq '') {
+        $rowtitle = &mt('Sections');
+    } else {
+        $rowtitle = &mt('Sections of [_1]',$instcode);
+    }
+    return &Apache::lonhtmlcommon::row_title($rowtitle).
+           '<table><tr><td align="center">'.
+           '<span class="LC_nobreak">'.&mt('Include?').
+           '<input type="checkbox" name="sec_'.$num.'" value="1" /></span>'.
+           '</td><td align="center">'.&mt('Institutional section').'<br />'.
+           '<input type="text" size="10" name="secnum_'.$num.'" />'.
+           '</td><td align="center">'.&mt('LON-CAPA section').'<br />'.
+           '<input type="text" size="10" name="loncapasec_'.$num.'" />'.
+           '</td></tr></table>'.
+           &Apache::lonhtmlcommon::row_closure(1);
+}
+
 sub get_course_dom {
     my $codedom = &Apache::lonnet::default_login_domain();
     if ($env{'form.showdom'} ne '') {