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

raeburn raeburn@source.lon-capa.org
Tue, 04 Aug 2009 20:15:50 -0000


This is a MIME encoded message

--raeburn1249416950
Content-Type: text/plain

raeburn		Tue Aug  4 20:15:50 2009 EDT

  Modified files:              
    /loncom/interface	lonrequestcourse.pm 
  Log:
  - Add infrastructure to support stepping backwards or forwards across multiple pages in the course request form.
  - For official courses, if auto-enrollment available in course's domain:
     - Cross-listing of multiple course sections added to enrollment page 
     - Auto-adds and Auto-drops can be enabled.
  - Course personnel page uses pop-up window containing lonpickuser.pm to search for users.
  
  Saving my work.
  
  
--raeburn1249416950
Content-Type: text/plain
Content-Disposition: attachment; filename="raeburn-20090804201550.txt"

Index: loncom/interface/lonrequestcourse.pm
diff -u loncom/interface/lonrequestcourse.pm:1.1 loncom/interface/lonrequestcourse.pm:1.2
--- loncom/interface/lonrequestcourse.pm:1.1	Mon Jul 27 22:58:24 2009
+++ loncom/interface/lonrequestcourse.pm	Tue Aug  4 20:15:50 2009
@@ -1,7 +1,7 @@
 # The LearningOnline Network
 # Request a course
 #
-# $Id: lonrequestcourse.pm,v 1.1 2009/07/27 22:58:24 raeburn Exp $
+# $Id: lonrequestcourse.pm,v 1.2 2009/08/04 20:15:50 raeburn Exp $
 #
 # Copyright Michigan State University Board of Trustees
 #
@@ -67,35 +67,240 @@
     &Apache::loncommon::content_type($r,'text/html');
     $r->send_http_header;
 
+    &Apache::lonhtmlcommon::clear_breadcrumbs();
+    my $dom = &get_course_dom();
     my $action = $env{'form.action'};
     my $state = $env{'form.state'};
-    my $dom = &get_course_dom();
+
+    my %stored;
+    my $jscript;
+    if ((defined($state)) && (defined($action))) {
+        my %elements =  &form_elements($dom);
+        if (($action eq 'view') && ($state ne 'crstype')) {
+            if (defined($env{'form.request_id'})) {
+                %stored = &retrieve_settings($dom,$env{'form.request_id'});
+            }
+        }
+        my $elementsref = {};
+        if (ref($elements{$action}) eq 'HASH') {
+            if (ref($elements{$action}{$state}) eq 'HASH') {
+                $elementsref = $elements{$action}{$state};
+            }
+        }
+        $jscript = &Apache::lonhtmlcommon::set_form_elements($elementsref,\%stored);
+    }
+
+    if ($state eq 'personnel') {
+        $jscript .= "\n".&Apache::loncommon::userbrowser_javascript();
+    }
+
+    my $loaditems = &onload_action($action,$state);
+
+    my %states;
+    $states{'view'} = ['pick_request','details','review','process'];
+    $states{'log'} = ['filter','display'];
+    $states{'new'} = ['courseinfo','enrollment','personnel','review','process'];
+    if (($action eq 'new') && ($env{'form.crstype'} eq 'official')) {
+        unless ($env{'form.state'} eq 'crstype') {
+            unshift (@{$states{'new'}},'codepick');
+        }
+    }
+
+    foreach my $key (keys(%states)) {
+        if (ref($states{$key}) eq 'ARRAY') {
+            unshift (@{$states{$key}},'crstype');
+        }
+    }
+
+    my $page = 0;
+    if (defined($action)) {
+        my $done = 0;
+        my $i=0;
+        if (ref($states{$action}) eq 'ARRAY') {
+            while ($i<@{$states{$action}} && !$done) {
+                if ($states{$action}[$i] eq $state) {
+                    $page = $i;
+                    $done = 1;
+                }
+                $i++;
+            }
+        }
+    }
+
     my %can_request;
     my $canreq = &check_can_request($dom,\%can_request);
     if ($action eq 'new') {
         if ($canreq) {
             if ($state eq 'crstype') {
-                &print_main_menu($r,\%can_request,$dom);
+                &print_main_menu($r,\%can_request,\%states,$dom,$jscript,$loaditems);
             } else {
-                &request_administration($r,$action,$state,$dom);
+                &request_administration($r,$action,$state,$page,\%states,$dom,$jscript,
+                                        $loaditems);
             }
         } else {
-            $r->print(&Apache::loncommon::start_page('Course Requests').
+            $r->print(&header('Course Requests').
                       '<div class="LC_warning">'.
                       &mt('You do not have privileges to request creation of courses.').
-                      '</div>'.
-                      &Apache::loncommon::end_page());
+                      '</div>'.&Apache::loncommon::end_page());
         }
     } elsif ($action eq 'view') {
-        &print_request_status();
+        &print_request_status($jscript,$loaditems);
     } elsif ($action eq 'log') {
-        &print_request_logs();
+        &print_request_logs($jscript,$loaditems);
     } else {
-        &print_main_menu($r,\%can_request,$dom);
+        &print_main_menu($r,\%can_request,\%states,$dom,$jscript);
     }
     return OK;
 }
 
+sub header {
+    my ($bodytitle,$jscript,$loaditems,$jsextra) = @_;
+    if ($jscript) {
+        $jscript = '<script type="text/javascript">'.
+                   $jscript.'</script>'."\n";
+    }
+    if ($loaditems) {
+        $loaditems = {'add_entries' => $loaditems,}; 
+    } 
+    return &Apache::loncommon::start_page($bodytitle,$jscript.$jsextra,$loaditems);
+}
+
+sub form_elements {
+    my ($dom) = @_;
+    my %elements =
+    (
+        new => {
+            crstype => {
+                crstype => 'selectbox',
+                action  => 'selectbox',
+            },
+            courseinfo => {
+                cdescr           => 'text',
+                clonecourse      => 'text',
+                clonedomain      => 'selectbox',
+                datemode         => 'radio',
+                dateshift        => 'text',
+            },
+            enrollment  => {
+                startaccess_month  => 'selectbox',
+                startaccess_hour   => 'selectbox',
+                endaccess_month    => 'selectbox',
+                endaccess_hour     => 'selectbox',
+                startaccess_day    => 'text',
+                startaccess_year   => 'text',
+                startaccess_minute => 'text',
+                startaccess_second => 'text',
+                endaccess_day      => 'text',
+                endaccess_year     => 'text',
+                endaccess_minute   => 'text',
+                endaccess_second   => 'text',
+                no_end_date      => 'checkbox',
+            },
+            personnel => {
+                persontotal => 'hidden',
+                addperson   => 'checkbox', 
+            },
+         },
+         view => {
+            crstype => {
+                crstype => 'selectbox',
+                action  => 'selectbox',
+            },
+         },
+    );
+    my (@codetitles,%cat_titles,%cat_order,@code_order,$lastitem);
+    &Apache::lonnet::auto_possible_instcodes($dom,\@codetitles,\%cat_titles,
+                                             \%cat_order,\@code_order);
+    my $numtitles = scalar(@codetitles);
+    if ($numtitles) {
+        my %extras;
+        $lastitem = pop(@codetitles);
+        $extras{'instcode_'.$lastitem} = 'text'; 
+        foreach my $item (@codetitles) {
+            $extras{'instcode_'.$item} = 'selectbox';   
+        }
+        $elements{'new'}{'codepick'} = \%extras;
+    }
+    if (&Apache::lonnet::auto_run('',$dom)) {
+        my %extras = (
+                       sectotal           => 'hidden',
+                       startenroll_month  => 'selectbox',
+                       startenroll_hour   => 'selectbox',
+                       endenroll_month    => 'selectbox',
+                       endenroll_hour     => 'selectbox',
+                       startenroll_day    => 'text',
+                       startenroll_year   => 'text',
+                       startenroll_minute => 'text',
+                       startenroll_second => 'text',
+                       endenroll_day      => 'text',
+                       endenroll_year     => 'text',
+                       endenroll_minute   => 'text',
+                       endenroll_second   => 'text',
+                       crosslisttotal     => 'hidden',
+                       addcrosslist       => 'checkbox',
+                       autoadds           => 'radio',
+                       autodrops          => 'radio',
+                     );
+        if ($env{'form.sectotal'} > 0) {
+            for (my $i=0; $i<$env{'form.sectotal'}; $i++) {
+                $extras{'sec_'.$i} = 'checkbox',
+                $extras{'secnum_'.$i} = 'text',
+                $extras{'loncapasec_'.$i} = 'checkbox',
+            }
+        }
+        my $crosslisttotal = $env{'form.crosslisttotal'};
+        if (!defined($crosslisttotal)) {
+            $crosslisttotal = 1;
+        }
+        if ($crosslisttotal > 0) {
+            for (my $i=0; $i<$env{'form.crosslisttotal'}; $i++) {
+                if ($numtitles) {
+                    $extras{'crosslist_'.$i.'_'.$lastitem} = 'text';
+                }
+                if (@codetitles > 0) {
+                    foreach my $item (@codetitles) {
+                        $extras{'crosslist_'.$i.'_'.$item} = 'selectbox';
+                    }
+                }
+                $extras{'crosslist_'.$i} = 'checkbox';
+                $extras{'crosslist_'.$i.'_instsec'} = 'text',
+                $extras{'crosslist_'.$i.'_lcsec'} = 'text',
+            }
+        }
+        my %mergedhash = (%{$elements{'new'}{'enrollment'}},%extras);
+        %{$elements{'new'}{'enrollment'}} = %mergedhash;
+    }
+    my %people;
+    my $persontotal = $env{'form.persontotal'};
+    if (!defined($persontotal)) {
+        $persontotal = 1;
+    }
+    for (my $i=0; $i<$persontotal; $i++) {
+        $people{'person_'.$i.'_uname'}    = 'text',
+        $people{'person_'.$i.'_dom'}      = 'selectbox',
+        $people{'person_'.$i.'_hidedom'}  = 'hidden',
+        $people{'person_'.$i.'_first'}    = 'text',
+        $people{'person_'.$i.'_last'}     = 'text',
+        $people{'person_'.$i.'_email'}    = 'text',
+        $people{'person_'.$i.'_role'}     = 'selectbox',
+        $people{'person_'.$i.'_sec'}      = 'selectbox',
+        $people{'person_'.$i.'_newsec'}   = 'text',
+        $people{'person_'.$i.'_sections'} = 'hidden',
+    }
+    my %personnelhash = (%{$elements{'new'}{'personnel'}},%people);
+    %{$elements{'new'}{'personnel'}} = %personnelhash;
+    return %elements;
+}
+
+sub onload_action {
+    my ($action,$state) = @_;
+    my %loaditems;
+    if (($action eq 'new') || ($action eq 'view')) {
+        $loaditems{'onload'} = 'javascript:setFormElements(document.requestcrs)';
+    }
+    return \%loaditems;
+}
+
 sub check_can_request {
     my ($dom,$can_request) = @_;
     my $canreq = 0;
@@ -126,31 +331,43 @@
 }
 
 sub print_main_menu {
-    my ($r,$can_request,$dom) = @_;
+    my ($r,$can_request,$states,$dom,$jscript,$loaditems) = @_;
     my $onchange;
     unless ($env{'form.interface'} eq 'textual') {
         $onchange = 1;
     }
 
-    &Apache::lonhtmlcommon::clear_breadcrumbs();
+    my $nextstate_setter = "\n";
+    if (ref($states) eq 'HASH') {
+        foreach my $key (keys(%{$states})) {
+            if (ref($states->{$key}) eq 'ARRAY') {
+                $nextstate_setter .= 
+"             if (actionchoice == '$key') {
+                  nextstate = '".$states->{$key}[1]."';
+             }
+";
+            }
+        }
+    }
 
-    my $js = <<END;
-<script type="text/javascript">
+    my $js = <<"END";
 
-function nextPage(formname,nextstate) {
-    if (check_can_request() == true) {
+function nextPage(formname) {
+    var crschoice = document.requestcrs.crstype.value;
+    var actionchoice = document.requestcrs.action.value;
+    if (check_can_request(crschoice,actionchoice) == true) {
+        if ((actionchoice == 'new') && (crschoice == 'official')) {
+            nextstate = 'codepick';
+        } else {
+$nextstate_setter 
+        } 
         formname.state.value= nextstate;
         formname.submit();
     }
     return;
 }
 
-function backPage(formname,prevstate) {
-    formname.state.value = prevstate;
-    formname.submit();
-}
-
-function check_can_request() {
+function check_can_request(crschoice,actionchoice) {
     var official = '';
     var unofficial = '';
     var community = '';    
@@ -168,7 +385,6 @@
         all => 'You must choose a specific course type when making a new course request.\\nAll types is not allowed.',
     ); 
     $js .= <<END;
-    var crschoice = document.requestform.crstype.value;
     if (crschoice == 'official') {
         if (official != 1) {
             alert("$lt{'official'}");
@@ -187,7 +403,6 @@
                     return false;
                 }
             } else {
-                var actionchoice = document.requestform.action.value;     
                 if (actionchoice == 'new') {
                     alert("$lt{'all'}");
                     return false;
@@ -197,12 +412,10 @@
     }
     return true;
 }
-</script>
 
 END
 
-    my $formname = 'requestform';
-    $r->print(&Apache::loncommon::start_page('Course Requests',$js).
+    $r->print(&header('Course Requests',$js.$jscript,$loaditems).
               '<p><div>'.
               '<form name="domforcourse" method="post" action="/adm/requestcourse">'.
               &Apache::lonhtmlcommon::start_pick_box().
@@ -215,15 +428,14 @@
     $r->print(&Apache::lonhtmlcommon::row_closure(1).
               &Apache::lonhtmlcommon::end_pick_box().'</form></div>');
 
-    my $formname = 'requestform';
-    my $next = 'codepick';
+    my $formname = 'requestcrs';
     my $nexttext = &mt('Next');
     $r->print('<div><form name="'.$formname.'" method="post" action="/adm/requestcourse">'.
               &Apache::lonhtmlcommon::start_pick_box().
               &Apache::lonhtmlcommon::row_title('Action').'
 <input type="hidden" name="showdom" value="'.$dom.'" />
 <select size="1" name="action" >
- <option value="new">'.&mt('New course request').'</option>
+ <option value="new">'.&mt('New request').'</option>
  <option value="view">'.&mt('View/Modify/Cancel pending requests').'</option>
  <option value="log">'.&mt('View request history').'</option>
 </select>'.
@@ -231,24 +443,24 @@
               &Apache::lonhtmlcommon::row_title('Course Type').'
 <select size="1" name="crstype">
  <option value="any">'.&mt('All types').'</option>
- <option value="official">'.&mt('Official course').'</option>
+ <option value="official" selected="selected">'.&mt('Official course').'</option>
  <option value="unofficial">'.&mt('Unofficial course').'</option>
  <option value="community">'.&mt('Community').'</option>
 </select>
 <input type="hidden" name="state" value="crstype" />'.
               &Apache::lonhtmlcommon::row_closure(1).
               &Apache::lonhtmlcommon::end_pick_box().'<br />
-<input type="button" name="next" value="'.$nexttext.'" onclick="javascript:nextPage(document.'.$formname.','."'".$next."'".')" />
+<input type="button" name="next" value="'.$nexttext.'" onclick="javascript:nextPage(document.'.$formname.')" />
 </form></div>');
     $r->print(&Apache::loncommon::end_page());
     return;
 }
 
 sub request_administration {
-    my ($r,$action,$state,$dom) = @_;
-    if ($action eq 'new') {
-        my $js =  <<END;
-<script type="text/javascript">
+    my ($r,$action,$state,$page,$states,$dom,$jscript,$loaditems) = @_;
+    my $js;
+    if (($action eq 'new') || ($action eq 'view')) {
+        $js =  <<END;
 
 function nextPage(formname,nextstate) {
     formname.state.value= nextstate;
@@ -259,63 +471,61 @@
     formname.submit();
 }
 
-</script>
-
 END
-
+    }
+    if ($action eq 'new') {
+        my $jsextra;
         unless (($state eq 'review') || ($state eq 'process')) {
-            $js .= "\n".&Apache::loncommon::coursebrowser_javascript($dom);
+            $jsextra = "\n".&Apache::loncommon::coursebrowser_javascript($dom);
         }
-        my $start_page =
-            &Apache::loncommon::start_page('Request a course',$js);
-        $r->print($start_page);
+        $r->print(&header('Request a course',$js.$jscript,$loaditems,$jsextra));
         if ($state eq 'review') {
             &print_review($r,$state,$dom);
         } elsif ($state eq 'process') {
             &print_request_outcome($r,$state,$dom);
         } else {
-            &print_request_form($r,$state,$dom);
+            &print_request_form($r,$action,$state,$page,$states,$dom);
         }
-        $r->print(&Apache::loncommon::end_page());
+    } elsif ($action eq 'view') {
+        $r->print(&header('Manage course requests',$js.$jscript,$loaditems));
     } elsif ($action eq 'log') {
-        $r->print(&coursereq_log());       
+        $r->print(&coursereq_log('View request log',$jscript,$loaditems));       
     }
+    $r->print(&Apache::loncommon::end_page());
     return;
 }
 
 sub print_request_form {
-    my ($r,$state,$dom) = @_;
+    my ($r,$action,$state,$page,$states,$dom) = @_;
     my $formname = 'requestcrs';
-    my ($next,$prev,$message,$output,$codepicker);
-    my $prev = 'crstype';
+    my ($next,$prev,$message,$output,$codepicker,$crstype);
+    $prev = $states->{$action}[$page-1];
+    $next = $states->{$action}[$page+1];
+    $crstype = $env{'form.crstype'};
     $r->print('<form name="'.$formname.'" method="post" action="/adm/requestcourse">');
-    my $crstype = $env{'form.crstype'};
-    my $xlist = 0;
+    my (@codetitles,%cat_titles,%cat_order,@code_order,$instcode,$code_chk);
     if ($crstype eq 'official') {
-        my (@codetitles,%cat_titles,%cat_order,@code_order);
         &Apache::lonnet::auto_possible_instcodes($dom,\@codetitles,\%cat_titles,
                                                  \%cat_order,\@code_order);
-        if ($state eq 'courseinfo') {
-            my $instcode;
-            if (@code_order > 0) {
+        if ($env{'form.instcode'} ne '') {
+            $instcode = $env{'form.instcode'};
+        }
+    }
+    if ($prev eq 'codepick') {
+        if (@code_order > 0) {
+            my $message;
+            if ($instcode eq '') {
                 foreach my $item (@code_order) {
-                    $instcode .= $env{'form.instcode_'.$item};  
+                    $instcode .= $env{'form.instcode_'.$item};
                 }
+                $r->print('<input type="hidden" name="instcode" value="'.$instcode.'" />'."\n");
             }
             if ($instcode ne '') {
-                my $code_chk = &Apache::lonnet::auto_validate_instcode('',$dom,$instcode);
+                $code_chk = &Apache::lonnet::auto_validate_instcode('',$dom,$instcode);
                 if ($code_chk eq 'ok') {
                     $message = '<div class="LC_info">'.
                                &mt('The chosen course category [_1] is valid.','<b>'.
-                               $instcode.'</b>').'</div>';  
-                    my @sections = &Apache::lonnet::auto_get_sections(undef,$dom,
-                                                                      $instcode);
-                    if (@sections) {
-                        $output .= &inst_section_selector(\@sections);
-                    }
-                    $output .= &coursecode_form($dom,'crosslist',\@codetitles,
-                                                \%cat_titles,\%cat_order,$xlist);
-                    $prev = 'codepick';
+                               $instcode.'</b>').'</div>';
                 } else {
                     $message = '<div class="LC_warning">'.
                                &mt('No course was found matching your choice of institutional course category.');
@@ -324,64 +534,304 @@
                     }
                     $message .= '</div>';
                 }
+            } else {
+                $message = '<div class="LC_warning">'.
+                           &mt('No course was found matching your choice of institutional course category.');
             }
+            unless ($code_chk eq 'ok') {
+                $prev = 'crstype';
+            }
+            $r->print($message);
         }
-        unless ($prev eq 'codepick') {
+    }
+    if ($prev eq 'crstype') {
+        if (@code_order > 0) {
             $codepicker = &coursecode_form($dom,'instcode',\@codetitles,
                                            \%cat_titles,\%cat_order);
+            if ($codepicker) {
+                $r->print('<div>'.&Apache::lonhtmlcommon::start_pick_box().$codepicker.
+                          &Apache::lonhtmlcommon::end_pick_box().'</div>');
+            } else {
+                $r->print(&courseinfo_form($dom,$formname,$crstype));
+            }
+        } else {
+            $r->print(&courseinfo_form($dom,$formname,$crstype));
         }
+    } elsif ($prev eq 'codepick') {
+        $r->print(&courseinfo_form($dom,$formname,$crstype));
+    } elsif ($state eq 'enrollment') {
+        $r->print(&print_enrollment_menu($formname,$instcode,$dom,\@codetitles,
+                                         \%cat_titles,\%cat_order,\@code_order));
+    } elsif ($state eq 'personnel') {
+        $r->print(&print_personnel_menu($dom,$formname));
     }
-    $r->print($message.'<div>'.&Apache::lonhtmlcommon::start_pick_box());
-    if ($output ne '') {
-        $r->print($output);
-    }
-    if ($codepicker) {
-        $r->print($codepicker);
-        $state = 'codepick';
-        $next = 'courseinfo';
-    } else {
-        $r->print(&courseinfo_form());
-        $state = 'courseinfo';
-        $next = 'review';
-    }
-    $r->print(&Apache::lonhtmlcommon::end_pick_box().'</div>'."\n");
-    unless ($codepicker) {
-        $r->print('<div>'.&clone_form($dom,$formname,$crstype).'</div>'."\n");
+    my @excluded = ('counter');
+    my %elements = &form_elements($dom);
+    if (ref($states) eq 'HASH') {
+        if (ref($states->{$action}) eq 'ARRAY') {
+            my @items = @{$states->{$action}};
+            my $numitems = scalar(@items);
+            if ($numitems) {
+                for (my $i=$numitems-1; $i>=0; $i--) {
+                    if (ref($elements{$action}) eq 'HASH') {
+                        if (ref($elements{$action}{$items[$i]}) eq 'HASH') {
+                            foreach my $key (keys(%{$elements{$action}{$items[$i]}})) { 
+                                push(@excluded,$key);
+                            }
+                        }
+                    }
+                    last if ($items[$i] eq $state);
+                }
+            }
+        }
     }
-    $r->print('<input type="hidden" name="state" value="'.$state.'" />'.
-              &Apache::lonhtmlcommon::echo_form_input(['state']).'</form>');
+    if (grep(/^instcode_/,@excluded)) {
+        push(@excluded,'instcode');
+    }
+    $r->print(&Apache::lonhtmlcommon::echo_form_input(\@excluded).'</form>');
     &display_navbuttons($r,$formname,$prev,'Previous',$next,'Next');
     return;
 }
 
+sub print_enrollment_menu {
+    my ($formname,$instcode,$dom,$codetitles,$cat_titles,$cat_order,$code_order) =@_;
+    my ($sections,$autoenroll,$access_dates);
+    my $starttime = time;
+    my $endtime = time+(6*30*24*60*60); # 6 months from now, approx
+
+    my %accesstitles = (
+                          'start' => 'Default start access',
+                           'end'   => 'Default end accss',
+                       );
+    my %enrolltitles = (
+                           'start' => 'Start auto-enrollment',
+                           'end'   => 'End auto-enrollment',
+                       );
+    if ($env{'form.crstype'} eq 'official') {
+        if (&Apache::lonnet::auto_run('',$dom)) {
+            my ($section_form,$crosslist_form,$autoenroll_form);
+            $section_form = &inst_section_selector($dom,$instcode);
+            my $crosslisttotal = $env{'form.crosslisttotal'};
+            if (!defined($crosslisttotal)) {
+                $crosslisttotal = 1;
+            }
+            if ($env{'form.addcrosslist'}) {
+                $crosslisttotal ++;
+            }
+            for (my $i=0; $i<$crosslisttotal; $i++) {
+                $crosslist_form .= &coursecode_form($dom,'crosslist',$codetitles, 
+                                                  $cat_titles,$cat_order,$i);
+            }
+            if ($crosslist_form) { 
+                $crosslist_form .= 
+                    &Apache::lonhtmlcommon::row_title(&mt('Add another?')).
+                    '<input name="crosslisttotal" type="hidden" value="'.$crosslisttotal.'" />'.
+                    '<input name="addcrosslist" type="checkbox" value="'.$crosslisttotal.'"'.
+                    ' onclick="javascript:nextPage(document.'.$formname.",'".$env{'form.state'}.
+                   "'".');" />'.&mt('Add?').&Apache::lonhtmlcommon::row_closure(1);
+            }
+            if ($section_form || $crosslist_form) {
+                $sections = '<div>'.&Apache::lonhtmlcommon::start_pick_box().
+                            $section_form.$crosslist_form.
+                            &Apache::lonhtmlcommon::end_pick_box().'</div>'."\n";
+            }
+            $autoenroll_form = 
+                &Apache::lonhtmlcommon::row_title(&mt('Add registered students automatically')).
+                '<span class="LC_nobreak"><label>'.
+                '<input type="radio" name="autoadds" value="1">'.
+                &mt('Yes').'</label>'.('&nbsp;'x3).'<label>'.
+                '<input type="radio" name="autoadds" value="0" checked="checked">'.
+                &mt('No').'</label></span>'.
+                &Apache::lonhtmlcommon::row_closure().
+                &Apache::lonhtmlcommon::row_title(&mt('Drop unregistered students automatically')).
+                '<span class="LC_nobreak"><label>'.
+                '<input type="radio" name="autodrops" value="1">'.
+                &mt('Yes').'</label>'.('&nbsp;'x3).'<label>'.
+                '<input type="radio" name="autodrops" value="0" checked="checked">'.
+                &mt('No').'</label></span>'. 
+                &Apache::lonhtmlcommon::row_closure().
+                &date_setting_table($starttime,$endtime,$formname,'enroll',%enrolltitles);
+            if ($autoenroll_form) {
+                $autoenroll = '<div>'.&Apache::lonhtmlcommon::start_pick_box().
+                              $autoenroll_form.
+                              &Apache::lonhtmlcommon::end_pick_box().'</div>'."\n";
+            }
+        }
+    }
+    my $access_dates_form = 
+        &date_setting_table($starttime,$endtime,$formname,'access',%accesstitles);
+    if ($access_dates_form) {
+        $access_dates = '<div>'.&Apache::lonhtmlcommon::start_pick_box().
+                        $access_dates_form.
+                        &Apache::lonhtmlcommon::end_pick_box().'</div>'."\n";
+    }
+    return $sections.$autoenroll.$access_dates;
+}
+
 sub inst_section_selector {
-    my ($sections,$selected) = @_;
+    my ($dom,$instcode) = @_;
+    my @sections = &Apache::lonnet::auto_get_sections(undef,$dom,$instcode);
+    my $sectotal = scalar(@sections);
     my $output;
-    if (ref($sections) eq 'ARRAY') {
-        $output = &Apache::lonhtmlcommon::row_title('Sections').
-                  &Apache::loncommon::start_data_table().
-                  &Apache::loncommon::start_data_table_row().
-                  '<th>'.&mt('Institutional Section').'</th>'.
-                  '<th>'.&mt('LON-CAPA section ID').'</th>'.
-                  '<th>'.&mt('Include in course?').'</th>'.
-                  &Apache::loncommon::end_data_table_row();
-        for (my $i=0; $i<@{$sections}; $i++) {
+    if ($sectotal) {
+        $output .=  &Apache::lonhtmlcommon::row_title('Sections').
+                    &Apache::loncommon::start_data_table().
+                    &Apache::loncommon::start_data_table_row().
+                    '<th>'.&mt('Include?').'<input type="hidden" name="sectotal" '.
+                    'value="'.$sectotal.'"</th>'.
+                    '<th>'.&mt('Institutional Section').'</th>'.
+                    '<th>'.&mt('LON-CAPA section').'</th>'.
+                    &Apache::loncommon::end_data_table_row();
+        for (my $i=0; $i<@sections; $i++) {
             my $colflag = $i%2;
             $output .= &Apache::loncommon::start_data_table_row().
-                       '<td>'.$sections->[$i].
+                       '<td><input type="checkbox" name="sec_'.$i.
+                       '" checked="checked" /></td>'.
+                       '<td>'.$sections[$i].
                        '<input type="hidden" name="secnum_'.$i.'" value="'.
-                       $sections->[$i].'" /></td>'.
+                       $sections[$i].'" /></td>'.
                        '<td><input type="text" size="10" name="loncapasec_'.$i.
-                       '" value="'.$sections->[$i].'" /></td>'.
-                       '<td><input type="checkbox" name="sec_'.$i. 
-                       '" checked="checked" /></td>'.
+                       '" value="'.$sections[$i].'" /></td>'.
                        &Apache::loncommon::end_data_table_row();
         }
-        $output .= &Apache::loncommon::end_data_table();
+        $output .= &Apache::loncommon::end_data_table().
+                   &Apache::lonhtmlcommon::row_closure();
     }
     return $output;
 }
 
+sub date_setting_table {
+    my ($starttime,$endtime,$formname,$suffix,%datetitles) = @_;
+    my ($perpetual,$table);
+    my $startform = &Apache::lonhtmlcommon::date_setter($formname,'start'.$suffix,
+                                                        $starttime,'','','',1,'','','',1);
+    my $endform = &Apache::lonhtmlcommon::date_setter($formname,'end'.$suffix,
+                                                      $endtime,'','','',1,'','','',1);
+    if ($suffix eq 'access') {
+        $perpetual = ' <span class="LC_nobreak"><label>'.
+                     '<input type="checkbox" name="no_end_date" />'.
+                     &mt('No end date').'</label></span>';
+    }
+    $table = &Apache::lonhtmlcommon::row_title($datetitles{'start'}).
+             $startform.
+             &Apache::lonhtmlcommon::row_closure().
+             &Apache::lonhtmlcommon::row_title($datetitles{'end'}).
+             $endform.$perpetual.
+             &Apache::lonhtmlcommon::row_closure(1);
+    return $table;
+}
+
+sub print_personnel_menu {
+    my ($dom,$formname) = @_;
+    my $output = '<div>'.&Apache::lonhtmlcommon::start_pick_box();
+    my $persontotal = $env{'form.persontotal'};
+    if (!defined($persontotal)) {
+        $persontotal = 1;
+    }
+    if ($env{'form.addperson'}) {
+        $persontotal ++;
+    }
+    my $userlinktxt = &mt('Set User');
+    my @items = ('uname','dom','last','first','email','hidedom');
+
+    my $roleoptions;
+    my @roles = &Apache::lonuserutils::roles_by_context('course');
+    foreach my $role (@roles) {
+        my $plrole=&Apache::lonnet::plaintext($role);
+        $roleoptions .= '  <option value="'.$role.'">'.$plrole.'</option>'."\n";
+    }
+    my %customroles=&Apache::lonuserutils::my_custom_roles();
+    if (keys(%customroles) > 0) {
+        foreach my $cust (sort(keys(%customroles))) {
+            my $custrole='cr_cr_'.$env{'user.domain'}.
+                    '_'.$env{'user.name'}.'_'.$cust;
+            $roleoptions .= '  <option value="'.$custrole.'">'.$cust.'</option>'."\n";
+        }
+    }
+
+    my @currsecs;
+    if ($env{'form.sectotal'}) {
+        for (my $i=0; $i<$env{'form.sectotal'}; $i++) {
+            if (defined($env{'form.loncapasec_'.$i})) {
+                my $lcsec = $env{'form.loncapasec_'.$i};
+                unless (grep(/^\Q$lcsec\E$/,@currsecs)) {
+                    push(@currsecs,$lcsec);
+                }
+            }
+        }
+    }
+
+    my ($existtitle,$existops,$existmult,$newtitle,$seccolspan);
+    if (@currsecs) {
+        my $existsize = scalar(@currsecs);
+        if ($existsize > 3) {
+            $existsize = 3;
+        }
+        if ($existsize > 1) {
+            $existmult = ' multiple="multiple" size="'.$existsize.'" ';
+        }
+        @currsecs = sort { $a <=> $b } (@currsecs);
+        $existtitle = &mt('Official').':&nbsp;';
+        $existops = '<option value="">'.&mt('None').'</option>';
+        foreach my $sec (@currsecs) {
+            $existops .= '<option value="'.$sec.'">'.$sec.'</option>'."\n";
+        }
+        $seccolspan = ' colspan="2"';
+        $newtitle = &mt('Other').':&nbsp;';
+    }
+
+    for (my $i=0; $i<$persontotal; $i++) { 
+        my @linkargs = map { 'person_'.$i.'_'.$_ } (@items);
+        my $linkargstr = join("','",@linkargs);
+        my $userlink = &Apache::loncommon::selectuser_link($formname,@linkargs,$userlinktxt);
+        my $uname_form = '<input type="text" name="person_'.$i.'_uname" value=""'.
+                         ' onFocus="this.blur();'.
+                         'openuserbrowser('."'$formname','$linkargstr'".');" />';
+        my $onchange = 'javascript:fix_domain('."'$formname','person_".$i."_dom',".
+                       "'person_".$i."_hidedom'".');'.
+                       'openuserbrowser('."'$formname','$linkargstr'".');';
+        my $udom_form = &Apache::loncommon::select_dom_form($dom,'person_'.$i.'_dom','',
+                                                            1,$onchange).
+                        '<input type="hidden" name="person_'.$i.'_hidedom" value="'.$dom.'" />';
+        my %form_elems;
+        foreach my $item (@items) {
+            next if (($item eq 'dom') || ($item eq 'uname') || ($item eq 'hidedom'));
+            $form_elems{$item} = '<input type="text" name="person_'.$i.'_'.$item.'" '.
+                                 'value="" readonly="readonly" />';
+        }
+        my $roleselector = '<select name="person_'.$i.'_role">'."\n".
+                           $roleoptions.'</select>';
+        my $sectionselector;
+        if (@currsecs) {
+            $sectionselector = $existtitle.'<select name="person_'.$i.'_sec"'.
+                               $existmult.'>'."\n".$existops.'</select>'.('&nbsp;' x3);
+        }
+        $sectionselector .= $newtitle.
+            '<input type="text" name="person_'.$i.'_newsec" size="15" value="" />'.
+            '<input type="hidden" name="person_'.$i.'_sections" value="" />'."\n";
+         
+        $output .= 
+            &Apache::lonhtmlcommon::row_title(&mt('Additional Personnel').'<br />'.
+                                              '<span class="LC_nobreak">'.$userlink.
+                                              '</span>').
+            '<table><tr><td align="center" valign="top">'.&mt('Username').'<br />'.$uname_form.'</td>'."\n".
+            '<td align="center" valign="top" colspan="2">'.&mt('Domain').'<br />'.$udom_form.'</td></tr><tr>'."\n".
+            '<td align="center" valign="top">'.&mt('First Name').'<br />'.$form_elems{'first'}.'</td>'."\n".
+            '<td align="center" valign="top">'.&mt('Last Name').'<br />'.$form_elems{'last'}.'</td>'."\n".
+            '<td align="center" valign="top">'.&mt('E-mail').'<br />'.$form_elems{email}.'</td></tr>'."\n".
+            '<tr><td align="center" valign="top">'.&mt('Role').'<br />'.$roleselector.'</td>'."\n".
+            '<td'.$seccolspan.' align="center" valign="top">'.&mt('Section(s)').'<br />'.$sectionselector.'</td>'."\n".
+            '</tr></table>'.&Apache::lonhtmlcommon::row_closure();
+    }
+    $output .= &Apache::lonhtmlcommon::row_title(&mt('Add another?')).
+               '<input name="persontotal" type="hidden" value="'.$persontotal.'" />'.
+               '<input name="addperson" type="checkbox" value="'.$persontotal.'"'.
+               ' onclick="javascript:nextPage(document.'.$formname.",'".$env{'form.state'}.
+               "'".');" />'.&mt('Add?').&Apache::lonhtmlcommon::row_closure(1).
+               &Apache::lonhtmlcommon::end_pick_box().'</div>';
+    return $output;
+}
+
 sub print_request_status {
     return;
 }
@@ -396,8 +846,13 @@
 }
 
 sub courseinfo_form {
-    my $output = &Apache::lonhtmlcommon::row_title('Course Description').
-                 '<input type="text" size="40" name="description" />';
+    my ($dom,$formname,$crstype) = @_;
+    my $output = '<div>'.&Apache::lonhtmlcommon::start_pick_box().
+                 &Apache::lonhtmlcommon::row_title('Course Description').
+                 '<input type="text" size="40" name="cdescr" />'.
+                 &Apache::lonhtmlcommon::row_closure(1).
+                 &Apache::lonhtmlcommon::end_pick_box().'</div>'.
+                 '<div>'.&clone_form($dom,$formname,$crstype).'</div>'."\n";
     return $output;
 }
 
@@ -408,8 +863,7 @@
         $type = 'Community';
     }
     my $cloneform = &Apache::loncommon::select_dom_form($dom,'clonedomain').
-                    &Apache::loncommon::selectcourse_link($formname,'clonecourse',
-                                                         'clonedomain','','','',$type);
+                    &Apache::loncommon::selectcourse_link($formname,'clonecourse','clonedomain','','','',$type);
     my %lt = &Apache::lonlocal::texthash(
                     'cid'  => 'Course ID',
                     'dmn'  => 'Domain',
@@ -418,48 +872,55 @@
                     'prd'  => 'Clone date parameters as-is',
                     'shd'  => 'Shift date parameters by number of days',
     );
-    my $output .= &Apache::lonhtmlcommon::start_pick_box(). 
-                  &Apache::lonhtmlcommon::row_title($lt{'cid'}).
-                  '<label><input type="text" size="25" name="clonecourse" value="" />'.
-                  '</label>'.&Apache::lonhtmlcommon::row_closure(1).'<label>'.
-                  &Apache::lonhtmlcommon::row_title($lt{'dmn'}).'</label>'.
-                  $cloneform.'</label>'.&Apache::lonhtmlcommon::row_closure().
-                  &Apache::lonhtmlcommon::row_title($lt{'dsh'}).'<label>'.
-                  '<input type="radio" name="datemode" value="delete" /> '.$lt{'ncd'}.
-                  '</label><br /><label>'.
-                  '<input type="radio" name="datemode" value="preserve" /> '.$lt{'prd'}.
-                  '</label><br /><label>'.
-                  '<input type="radio" name="datemode" value="shift" checked="checked" /> '.
-                  $lt{'shd'}.'</label>'.
-                  '<input type="text" size="5" name="dateshift" value="365" />'.
-                  &Apache::lonhtmlcommon::row_closure(1).
-                  &Apache::lonhtmlcommon::end_pick_box();
+    my $output .= 
+        &Apache::lonhtmlcommon::start_pick_box(). 
+        &Apache::lonhtmlcommon::row_title($lt{'cid'}).'<label>'.
+        '<input type="text" size="25" name="clonecourse" value="" onfocus="this.blur();'.
+        'opencrsbrowser('."'$formname','clonecourse','clonedomain','','','','$type'".');" />'.
+        '</label>'.&Apache::lonhtmlcommon::row_closure(1).'<label>'.
+        &Apache::lonhtmlcommon::row_title($lt{'dmn'}).'</label>'.
+        $cloneform.'</label>'.&Apache::lonhtmlcommon::row_closure().
+        &Apache::lonhtmlcommon::row_title($lt{'dsh'}).'<label>'.
+        '<input type="radio" name="datemode" value="delete" /> '.$lt{'ncd'}.
+        '</label><br /><label>'.
+        '<input type="radio" name="datemode" value="preserve" /> '.$lt{'prd'}.
+        '</label><br /><label>'.
+        '<input type="radio" name="datemode" value="shift" checked="checked" /> '.
+        $lt{'shd'}.'</label>'.
+        '<input type="text" size="5" name="dateshift" value="365" />'.
+        &Apache::lonhtmlcommon::row_closure(1).
+        &Apache::lonhtmlcommon::end_pick_box();
     return $output;
 }
 
 sub coursecode_form {
-    my ($dom,$context,$codetitles,$cat_titles,$cat_order,$count) = @_;
+    my ($dom,$context,$codetitles,$cat_titles,$cat_order,$num) = @_;
     my $output;
+    my %rowtitle = (
+                    instcode  => 'Course Category',
+                    crosslist => 'Cross Listed Course',
+                   );
     if ((ref($codetitles) eq 'ARRAY') && (ref($cat_titles) eq 'HASH') && 
         (ref($cat_order))) {
+        my ($sel,$instsec,$lcsec);
+        $sel = $context;
+        if ($context eq 'crosslist') {
+            $sel .= '_'.$num;
+            $instsec = &mt('Institutional section').'<br />'.
+                       '<input type="text" size="10" name="'.$sel.'_instsec" />';
+            $lcsec = &mt('LON-CAPA section').'<br />'.
+                     '<input type="text" size="10" name="'.$sel.'_lcsec" />';
+        }
         if (@{$codetitles} > 0) {
             my $lastitem = pop(@{$codetitles});
-            my $sel = $context;
-            if ($context eq 'crosslist') {
-                $sel .= '_'.$count;
-            }
-            my $lastinput = '<input type="text" size="5" name="'.$sel.'_'.                                    $lastitem.'" />';
-            my %rowtitle = (
-                             instcode  => 'Course Category',
-                             crosslist => 'Cross Listed Course',
-                           );
+            my $lastinput = '<input type="text" size="5" name="'.$sel.'_'.                                            $lastitem.'" />';
             if (@{$codetitles} > 0) {
-                my $sel = $context;
-                if ($context eq 'crosslist') {
-                    $sel .= '_'.$count;
-                }
                 $output = &Apache::lonhtmlcommon::row_title($rowtitle{$context}).
                           '<table><tr>';
+                if ($context eq 'crosslist') {
+                    $output .= '<td>'.&mt('Include?').'<br />'.
+                               '<input type="checkbox" name="'.$sel.'" value="1" /></td>';
+                }
                 foreach my $title (@{$codetitles}) {
                     if (ref($cat_order->{$title}) eq 'ARRAY') {
                         if (@{$cat_order->{$title}} > 0) {
@@ -483,7 +944,8 @@
                 }
                 if ($context eq 'crosslist') {
                     $output .= '<td align="center">'.$lastitem.'<br />'."\n".
-                               $lastinput.'</td></tr></table>';
+                               $lastinput.'</td><td align="center">'.$instsec.'</td>'.
+                               '<td align="center">'.$lcsec.'</td></tr></table>';
                 } else {
                     $output .= '</tr></table>'.
                                &Apache::lonhtmlcommon::row_closure().
@@ -493,13 +955,26 @@
             } else {
                 if ($context eq 'crosslist') {
                     $output .= &Apache::lonhtmlcommon::row_title($rowtitle{$context}).
-                               $lastitem.'<br />';
+                               '<table><tr>'.
+                               '<td align="center">'.$lastitem.'<br />'.$lastinput.'</td>'.
+                               '<td align="center">'.$instsec.'</td><td>'.$lcsec.'</td>'.
+                               '</tr></table>';
                 } else { 
                     $output .= &Apache::lonhtmlcommon::row_title('Course '.$lastitem).
                                $lastinput;
                 }
-                $output .=  $lastinput.&Apache::lonhtmlcommon::row_closure(1);
             }
+            $output .=  &Apache::lonhtmlcommon::row_closure(1);
+            push(@$codetitles,$lastitem);    
+        } elsif ($context eq 'crosslist') {
+            $output .= &Apache::lonhtmlcommon::row_title($rowtitle{$context}).
+                       '<table><tr><td align="center">'.
+                       '<span class="LC_nobreak">'.&mt('Include?').
+                       '<input type="checkbox" name="'.$sel.'" value="1" /></span>'.
+                       '</td><td align="center">'.&mt('Institutional ID').'<br />'.
+                       '<input type="text" size="10" name="'.$sel.'_instsec" />'.
+                       '</td><td align="center">'.$lcsec.'</td></tr></table>'.
+                       &Apache::lonhtmlcommon::row_closure(1);
         }
     }
     return $output;
@@ -547,5 +1022,30 @@
     return;
 }
 
+sub retrieve_settings {
+    my ($dom,$request_id) = @_;
+    my %reqinfo = &get_request_settings($request_id,$dom);
+    my %stored;
+    $stored{'cdescr'} = &unescape($reqinfo{'description'});
+    $stored{'startaccess'} = $reqinfo{'startaccess'};
+    $stored{'endaccess'} = $reqinfo{'endaccess'};
+    if ($stored{'endaccess'} == 0) {
+        $stored{'no_end_date'} = 1;
+    }
+    $stored{'startenroll'} = $reqinfo{'startenroll'};
+    $stored{'endenroll'} = $reqinfo{'endenroll'};
+    $stored{'crosslist'} = $reqinfo{'crosslist'};
+    $stored{'clonecourse'} = $reqinfo{'clonecourse'};
+    $stored{'clonedomain'} = $reqinfo{'clonedomain'};
+    $stored{'sections'} = $reqinfo{'sections'};
+    $stored{'personnel'} = $reqinfo{'personnel'};
+
+    return %stored;
+}
+
+sub get_request_settings {
+    my ($request_id,$dom);
+}
+
 1;
 

--raeburn1249416950--