--- loncom/interface/lonrequestcourse.pm	2010/03/16 22:40:12	1.47
+++ loncom/interface/lonrequestcourse.pm	2013/12/24 19:15:11	1.69
@@ -1,7 +1,7 @@
 # The LearningOnline Network
 # Request a course
 #
-# $Id: lonrequestcourse.pm,v 1.47 2010/03/16 22:40:12 raeburn Exp $
+# $Id: lonrequestcourse.pm,v 1.69 2013/12/24 19:15:11 raeburn Exp $
 #
 # Copyright Michigan State University Board of Trustees
 #
@@ -128,17 +128,21 @@ sub handler {
     }
 
     &Apache::loncommon::get_unprocessed_cgi($ENV{'QUERY_STRING'},
-        ['action','showdom','cnum','state','crstype']);
+        ['action','showdom','cnum','state','crstype','queue']);
     &Apache::lonhtmlcommon::clear_breadcrumbs();
     my $dom = &get_course_dom();
     my $action = $env{'form.action'};
     my $state = $env{'form.state'};
     my (%states,%stored);
-    my ($jscript,$uname,$udom,$result,$warning);
+    my ($jscript,$uname,$udom,$result,$warning,$showcredits,$instcredits);
+    my %domdefs = &Apache::lonnet::get_domain_defaults($dom);
+    if ($domdefs{'officialcredits'} || $domdefs{'unofficialcredits'} || $domdefs{'textbookcredits'}) {
+        $showcredits = 1;
+    }
 
     $states{'display'} = ['details'];
     $states{'view'} = ['pick_request','details','cancel','removal'];
-    $states{'log'} = ['filter','display'];
+    $states{'log'} = ['display'];
     $states{'new'} = ['courseinfo','enrollment','personnel','review','process'];
 
     if (($action eq 'new') && ($env{'form.crstype'} eq 'official')) {
@@ -147,6 +151,12 @@ sub handler {
         }
     }
 
+    if (($action eq 'new') && (&Apache::loncoursequeueadmin::author_prompt())) {
+        if (ref($states{$action}) eq 'ARRAY') {
+            push(@{$states{$action}},'reqauthor');
+        }
+    }
+
     foreach my $key (keys(%states)) {
         if (ref($states{$key}) eq 'ARRAY') {
             unshift (@{$states{$key}},'crstype');
@@ -162,23 +172,26 @@ sub handler {
                  personnel     => 'Personnel',
                  review        => 'Review',
                  process       => 'Result',
+                 reqauthor     => 'Authoring Space Result',
                  pick_request  => 'Display Summary',
                  details       => 'Request Details',
                  cancel        => 'Cancel Request',
                  removal       => 'Outcome',
+                 display       => 'Request Logs',
                 );
 
     if (($env{'form.crstype'} eq 'official') && (&Apache::lonnet::auto_run('',$dom))) {
         $trail{'enrollment'} = 'Enrollment';
     }
 
-    my ($page,$crumb,$newinstcode,$codechk,$checkedcode,$description) = 
+    my ($page,$crumb,$newinstcode,$codechk,$checkedcode,$description) =
         &get_breadcrumbs($dom,$action,\$state,\%states,\%trail);
     if ($action eq 'display') {
         if (($dom eq $env{'request.role.domain'}) && (&Apache::lonnet::allowed('ccc',$dom))) {
             if ($env{'form.cnum'} ne '') {
                 my $cnum = $env{'form.cnum'};
-                my $reqkey = $cnum.'_approval';
+                my $queue = $env{'form.queue'};
+                my $reqkey = $cnum.'_'.$queue;
                 my $namespace = 'courserequestqueue';
                 my $domconfig = &Apache::lonnet::get_domainconfiguser($dom);
                 my %queued =
@@ -260,11 +273,11 @@ sub handler {
                 }
             }
         }
-        my %elements =  &form_elements($dom);
+        (my $elements,$instcredits) = &form_elements($dom,$showcredits);
         my $elementsref = {};
-        if (ref($elements{$action}) eq 'HASH') {
-            if (ref($elements{$action}{$state}) eq 'HASH') {
-                $elementsref = $elements{$action}{$state};
+        if ((ref($elements) eq 'HASH') && (ref($elements->{$action}) eq 'HASH')) {
+            if (ref($elements->{$action}{$state}) eq 'HASH') {
+                $elementsref = $elements->{$action}{$state};
             }
         }
         if (($state eq 'courseinfo') && ($env{'form.clonedom'} eq '')) {
@@ -298,7 +311,7 @@ sub handler {
                 &request_administration($r,$action,$state,$page,\%states,$dom,
                                         $jscript,$loaditems,$crumb,$newinstcode,
                                         $codechk,$checkedcode,$description,
-                                        \@invalidcrosslist);
+                                        $showcredits,$instcredits,\@invalidcrosslist);
             }
         } else {
             $r->print(&header('Course/Community Requests').$crumb.
@@ -311,21 +324,39 @@ sub handler {
             &print_main_menu($r,\%can_request,\%states,$dom,$jscript,$loaditems,$crumb,\%request_domains);
         } else {
             &request_administration($r,$action,$state,$page,\%states,$dom,$jscript,
-                                    $loaditems,$crumb);
+                                    $loaditems,$crumb,'','','','',$showcredits);
         }
     } elsif ($action eq 'display') {
         if ($warning ne '') {
             my $args = { only_body => 1 };
-            $r->print(&header('Course/Community Requests','','',$args).$crumb.
+            $r->print(&header('Course/Community Requests','','' ,'',$args).$crumb.
                       '<h3>'.&mt('Course/Community Request Details').'</h3>'.
                       '<div class="LC_warning">'.$warning.'</div>'.
                       &close_popup_form());
         } else {
             &request_administration($r,$action,$state,$page,\%states,$dom,$jscript,
-                                    $loaditems,$crumb,'','','','','',$uname,$udom);
+                                    $loaditems,$crumb,'','','','',$showcredits,'','',
+                                    $uname,$udom);
         }
     } elsif ($action eq 'log') {
-        &print_request_logs($jscript,$loaditems,$crumb);
+        if ($state eq 'crstype') {
+            &print_main_menu($r,\%can_request,\%states,$dom,$jscript,'',$crumb,\%request_domains);
+        } else {
+            $jscript .= <<ENDJS;
+
+function backPage(formname,prevstate) {
+    formname.state.value = prevstate;
+    formname.submit();
+}
+
+function setPage(formname) {
+    formname.page.value = '1';
+    return;
+}
+
+ENDJS
+            &print_request_logs($r,$dom,$jscript,$loaditems,$crumb);
+        }
     } else {
         &print_main_menu($r,\%can_request,\%states,$dom,$jscript,'',$crumb,\%request_domains);
     }
@@ -420,7 +451,7 @@ sub get_breadcrumbs {
                     $crumb = &Apache::lonhtmlcommon::breadcrumbs('Course/Community Requests','Course_Requests');
                     last;
                 } else {
-                    if (($$state eq 'process') || ($$state eq 'removal')) {
+                    if (($$state eq 'process') || ($$state eq 'removal') || ($$state eq 'reqauthor')) {
                         &Apache::lonhtmlcommon::add_breadcrumb(
                             { href => '/adm/requestcourse',
                               text => "$trail->{$states->{$action}[$i]}",
@@ -469,7 +500,8 @@ sub header {
 }
 
 sub form_elements {
-    my ($dom) = @_;
+    my ($dom,$showcredits) = @_;
+    my $instcredits;
     my %elements =
     (
         new => {
@@ -537,7 +569,6 @@ sub form_elements {
     }
     if (&Apache::lonnet::auto_run('',$dom)) {
         my %extras = (
-                       sectotal           => 'hidden',
                        enrollstart_month  => 'selectbox',
                        enrollstart_hour   => 'selectbox',
                        enrollend_month    => 'selectbox',
@@ -553,12 +584,39 @@ sub form_elements {
                        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 $outcome,my $desc,$instcredits) = 
+                &Apache::lonnet::auto_validate_instcode(undef,$dom,$instcode);
+            if ($showcredits && $instcredits eq '') {
+                $extras{'coursecredits'} = 'text';
+            }
+        } elsif (($env{'form.crstype'} eq 'unofficial') || ($env{'form.crstype'} eq 'textbook')) {
+            if ($showcredits) {
+                $extras{'coursecredits'} = 'text';
             }
         }
         my $crosslisttotal = $env{'form.crosslisttotal'};
@@ -568,7 +626,6 @@ sub form_elements {
         if (!$crosslisttotal) {
             $crosslisttotal = 1;
         }
-
         for (my $i=0; $i<$env{'form.crosslisttotal'}; $i++) {
             if ($numtitles) {
                 $extras{'crosslist_'.$i.'_'.$lastitem} = 'text';
@@ -606,7 +663,7 @@ sub form_elements {
     }
     my %personnelhash = (%{$elements{'new'}{'personnel'}},%people);
     %{$elements{'new'}{'personnel'}} = %personnelhash;
-    return %elements;
+    return (\%elements,$instcredits);;
 }
 
 sub onload_action {
@@ -628,11 +685,7 @@ sub onload_action {
 sub print_main_menu {
     my ($r,$can_request,$states,$dom,$jscript,$loaditems,$crumb,$request_domains) = @_;
     my ($types,$typename) = &Apache::loncommon::course_types();
-    my $onchange;
-    unless ($env{'form.interface'} eq 'textual') {
-        $onchange = 'this.form.submit()';
-    }
-
+    my $onchange = 'this.form.submit()';
     my $nextstate_setter = "\n";
     if (ref($states) eq 'HASH') {
         foreach my $key (keys(%{$states})) {
@@ -668,7 +721,8 @@ $nextstate_setter
 function check_can_request(crschoice,actionchoice) {
     var official = '';
     var unofficial = '';
-    var community = '';    
+    var community = '';
+    var textbook = '';
 END
     if (ref($can_request) eq 'HASH') {
         foreach my $item (keys(%{$can_request})) {
@@ -680,8 +734,10 @@ END
     my %lt = &Apache::lonlocal::texthash(
         official => 'You are not permitted to request creation of an official course in this domain.',
         unofficial => 'You are not permitted to request creation of an unofficial course in this domain.',
-        community => 'You are not permitted to request creation of a community this domain.',
-        all => 'You must choose a specific course type when making a new course request.\\nAll types is not allowed.',
+        community => 'You are not permitted to request creation of a community in this domain.',
+        textbook => 'You are not permitted to request creation of a textbook course in this domain',
+        all => 'You must choose a specific course type when making a new course request.',
+        allt => '"All types" is not allowed.',
     ); 
     $js .= <<END;
     if (crschoice == 'official') {
@@ -702,10 +758,17 @@ END
                     return false;
                 }
             } else {
-                if (actionchoice == 'new') {
-                    alert("$lt{'all'}");
-                    return false;
-                }               
+                if (crschoice == 'textbook') {
+                    if (textbook != 1) {
+                        alert("$lt{'community'}");
+                        return false;
+                    }
+                } else {
+                    if (actionchoice == 'new') {
+                        alert('$lt{'all'}'+'\\n'+'$lt{'allt'}');
+                        return false;
+                    }
+                }
             }
         }
     }
@@ -714,7 +777,7 @@ END
 END
     my ($pagetitle,$pageinfo,$domaintitle);
     if (ref($can_request) eq 'HASH') {
-        if (($can_request->{'official'}) || ($can_request->{'unofficial'})) {
+        if (($can_request->{'official'}) || ($can_request->{'unofficial'}) || $can_request->{'textbook'}) {
             if ($can_request->{'community'}) {
                 $pagetitle = 'Course/Community Requests';
                 $pageinfo = &mt('Request creation of a new course or community, or review your pending requests.');
@@ -816,8 +879,8 @@ END
 
 sub request_administration {
     my ($r,$action,$state,$page,$states,$dom,$jscript,$loaditems,$crumb,
-        $newinstcode,$codechk,$checkedcode,$description,$invalidcrosslist,
-        $uname,$udom) = @_;
+        $newinstcode,$codechk,$checkedcode,$description,$showcredits,
+        $instcredits,$invalidcrosslist,$uname,$udom) = @_;
     my $js;
     if (($action eq 'new') || (($action eq 'view') && ($state eq 'pick_request'))) {
         $js =  <<END;
@@ -841,7 +904,7 @@ END
     }
     if ($action eq 'new') {
         my $jsextra;
-        if ($state eq 'courseinfo') {
+        if (($state eq 'courseinfo') || ($state eq 'codepick')) {
             $jsextra = "\n".&Apache::loncommon::coursebrowser_javascript($dom);
         } elsif ($state eq 'enrollment') {
             if (($env{'form.crstype'} eq 'official') && 
@@ -859,7 +922,8 @@ END
         }
         $r->print(&header($title,$js.$jscript,$loaditems,$jsextra).$crumb);
         &print_request_form($r,$action,$state,$page,$states,$dom,$newinstcode,
-                            $codechk,$checkedcode,$description,$invalidcrosslist);
+                            $codechk,$checkedcode,$description,$showcredits,
+                            $instcredits,$invalidcrosslist);
     } elsif ($action eq 'view') {
         my $jsextra;
         my $formname = 'requestcrs';
@@ -890,11 +954,13 @@ END
                 $title = &mt('Pending requests for official courses');
             } elsif ($env{'form.crstype'} eq 'unofficial') {
                 $title = &mt('Pending requests for unofficial courses');
+            } elsif ($env{'form.crstype'} eq 'textbook') {
+                $title = &mt('Pending requests for textbook courses');
             } else {
                 $title = &mt('Pending course/community requests'); 
             }
             $r->print('<h3>'.$title.'</h3><div>'."\n".$form."\n".
-                      &print_request_status($dom).'</form></div>');
+                      &print_request_status($dom,$action).'</form></div>');
         } elsif ($state eq 'details') {
             my (@codetitles,%cat_titles,%cat_order,@code_order,$instcode,$code_chk);
             my $origcnum = $env{'form.cnum'};
@@ -913,9 +979,10 @@ END
             }
             $r->print('<h3>'.$title.'</h3><div>'."\n".$form."\n".
                       &print_review($dom,\@codetitles,\%cat_titles,\%cat_order,
-                                    \@code_order)."\n".
+                                    \@code_order,'','','','',$instcredits)."\n".
                       '<input name="origcnum" value="'.$origcnum.'" type="hidden" />'."\n");
-            my @excluded = &get_excluded_elements($dom,$states,'new','review');
+            my @excluded = &get_excluded_elements($dom,$states,'new','review',
+                                                  $showcredits);
             push(@excluded,'origcnum');
             $r->print(&Apache::lonhtmlcommon::echo_form_input(\@excluded).'</div>');
             my $other = 'modify';
@@ -937,7 +1004,8 @@ END
             my ($result,$output) = &print_cancel_request($dom,$env{'form.origcnum'});
             $r->print('<h3>'.$title.'</h3><div>'."\n".$form."\n".
                       $output);
-            my @excluded = &get_excluded_elements($dom,$states,'view','cancel');
+            my @excluded = &get_excluded_elements($dom,$states,'view','cancel',
+                                                  $showcredits);
             $r->print(&Apache::lonhtmlcommon::echo_form_input(\@excluded).'</div>');
             my %navtxt = &Apache::lonlocal::texthash (
                                                       prev => 'Back',
@@ -1014,10 +1082,9 @@ END
         $r->print(&header($title,'','','',{ 'only_body' => 1}).
                   $crumb."\n".'<h3>'.$header.'</h3>'.
                   &print_review($dom,\@codetitles,\%cat_titles,\%cat_order,
-                                \@code_order,$uname,$udom)."\n".'</div>'.
+                                \@code_order,$uname,$udom,'','',$instcredits)."\n".
+                  '</div>'.
                   &close_popup_form());
-    } elsif ($action eq 'log') {
-        $r->print(&coursereq_log('View request log',$jscript,$loaditems).$crumb);
     }
     $r->print(&Apache::loncommon::end_page());
     return;
@@ -1210,7 +1277,7 @@ sub get_instcode {
 
 sub print_request_form {
     my ($r,$action,$state,$page,$states,$dom,$newinstcode,$codechk,$checkedcode,
-        $description,$invalidcrosslist) = @_;
+        $description,$showcredits,$instcredits,$invalidcrosslist) = @_;
     my $formname = 'requestcrs';
     my ($next,$prev,$message,$output,$codepicker,$crstype);
     $prev = $states->{$action}[$page-1];
@@ -1283,7 +1350,7 @@ sub print_request_form {
         }
         $r->print(&print_enrollment_menu($formname,$instcode,$dom,\@codetitles,
                                          \%cat_titles,\%cat_order,\@code_order,
-                                         $invalidcrosslist));
+                                         $showcredits,$instcredits,$invalidcrosslist));
     } elsif ($state eq 'personnel') {
         $r->print(&print_personnel_menu($dom,$formname,$crstype,$invalidcrosslist));
     } elsif ($state eq 'review') {
@@ -1309,16 +1376,38 @@ sub print_request_form {
                             }
                             if ($skipuser) {
                                 push(@disallowed,$i);
-                                $disallowmsg{$i} = &mt('[_1] was excluded because new users need be from the course domain','<tt>'.$personname.':'.$persondom.'</tt>');
+                                $disallowmsg{$i} = &mt('[_1] was excluded because new users need to be from the course domain','<tt>'.$personname.':'.$persondom.'</tt>');
                                 next;
                             }
                         }
-                        if (&get_cancreate_status($persondom,$personname,$dom)) {
-                            my ($allowed,$msg) = 
+                        my $usertype = &get_usertype($persondom,$personname,\%curr_rules,\%got_rules);
+                        if (&Apache::lonuserutils::can_create_user($dom,'requestcrs',$usertype)) {
+                            my ($allowed,$msg,$authtype,$authparam) = 
                                 &check_newuser_rules($persondom,$personname,
                                     \%alerts,\%rulematch,\%inst_results,
                                     \%curr_rules,\%got_rules);
                             if ($allowed) {
+                                my %domdefaults = &Apache::lonnet::get_domain_defaults($persondom);
+                                if ($usertype eq 'official') {
+                                    if ($authtype eq '') {
+                                        $authtype = $domdefaults{'auth_def'};
+                                        $authparam = $domdefaults{'auth_arg_def'};
+                                    }
+                                } elsif ($usertype eq 'unofficial') {
+                                    if ($authtype eq '') {
+                                        $authtype = 'internal';
+                                        $authparam = '';
+                                    }
+                                } else {
+                                    $authtype = $domdefaults{'auth_def'};
+                                    $authparam = $domdefaults{'auth_arg_def'};
+                                }
+                                if (($authtype eq '') ||
+                                    (($authtype =~/^krb/) && ($authparam eq ''))) {
+                                    push(@disallowed,$i);
+                                    $disallowmsg{$i} = &mt('[_1] was excluded because institutional information is incomplete for this new user.','<tt>'.$personname.':'.$persondom.'</tt>');
+                                    next;
+                                }
                                 if (ref($inst_results{$personname.':'.$persondom}) eq 'HASH') {
                                     if ($inst_results{$personname.':'.$persondom}{'lastname'} ne '') {
                                         $env{'form.person_'.$i.'_lastname'} = $inst_results{$personname.':'.$persondom}{'lastname'};
@@ -1377,7 +1466,7 @@ sub print_request_form {
         } else {
             $r->print('<h3>'.&mt('Review course request details before submission').'</h3>');
         }
-        $r->print(&print_review($dom,\@codetitles,\%cat_titles,\%cat_order,\@code_order,'','',\@disallowed,\%disallowmsg).
+        $r->print(&print_review($dom,\@codetitles,\%cat_titles,\%cat_order,\@code_order,'','',\@disallowed,\%disallowmsg,$instcredits).
                   '<input type="hidden" name="cnum" value="'.$cnum.'" />');
         if ($crstype eq 'community') {
             $navtxt{'next'} = &mt('Submit community request');
@@ -1390,19 +1479,77 @@ sub print_request_form {
                                                      \%cat_order,\@code_order);
         }
         my ($storeresult,$result) = &print_request_outcome($dom,\@codetitles,
-                                                           \@code_order);
+                                                           \@code_order,$instcredits);
         $r->print($result);
         if (($storeresult eq 'ok') || ($storeresult eq 'created')) {
-            $r->print('<p>');
             if ($storeresult eq 'ok') {
-                $r->print('<a href="/adm/requestcourse?action=view&state=details&showdom='.$dom.'&cnum='. $env{'form.cnum'}.'">'.
-                          &mt('Modify this request').'</a>'.('&nbsp;'x4));
+                $r->print('<p><a href="/adm/requestcourse?action=view&state=details&showdom='.$dom.'&cnum='. $env{'form.cnum'}.'">'.
+                          &mt('Modify this request').'</a>'.('&nbsp;'x4).
+                          '<a href="/adm/requestcourse">'.&mt('Make another request').'</a></p>');
+            }
+            if (&Apache::loncoursequeueadmin::author_prompt()) {
+                $r->print('<h3>'.&mt('Access to authoring space').'</h3>'.
+                          '<p>'.
+                          &mt('Although assessment items can be created directly inside a course, such items only use part of the assessment capabilities of LON-CAPA.').
+                          '<br />'.
+                          &mt('By contrast, items created in authoring space, then imported into a course, can use all of the features of the assessment engine.').'</p>'.
+                          '<p>'.&mt('Request authoring space access now?').
+                          '<span class="LC_nobreak">&nbsp;'.
+                          '<label><input type="radio" name="requestauthor" value="1" />'.&mt('Yes').'</label>'.
+                          ('&nbsp;'x2).
+                          '<label><input type="radio" name="requestauthor" value="0" checked="checked"/>'.&mt('No').'</label>'.
+                          '</span></p>'.
+                          '<input type="submit" name="newauthor" value="'.&mt('Submit authoring request').'" />'.
+                          '<input type="hidden" name="state" value="reqauthor" />'.
+                          '<input type="hidden" name="action" value="'.$env{'form.action'}.'" />'.
+                          '<input type="hidden" name="cnum" value="'.$env{'form.cnum'}.'" />'.
+                          '<input type="hidden" name="showdom" value="'.$env{'form.showdom'}.'" />'.
+                          '<input type="hidden" name="crstype" value="'.$env{'form.crstype'}.'" />'.
+                          '<input type="hidden" name="disposition" value="'.$storeresult.'" />'.
+                          '<br />');
+            } elsif ($storeresult eq 'created') {
+                $r->print('<p><a href="/adm/requestcourse">'.&mt('Make another request').'</a></p>');
+            }
+        }
+    } elsif ($state eq 'reqauthor') {
+        my ($result,@links); 
+        if ($env{'form.requestauthor'}) {
+            $r->print(&Apache::loncoursequeueadmin::process_reqauthor(\$result));
+            if ($result eq 'created') {
+                my $role = 'au';
+                my $spec = "$role./$env{'form.showdom'}/";
+                push(@links,&mt('Enter your authoring space with role: [_1]',
+                                '<a href="/adm/roles?selectrole=1&amp;'.$spec.'=1">'.
+                                &Apache::lonnet::plaintext($role).'</a>'));
+            }
+        }
+        if (($env{'form.disposition'} eq 'created') &&
+            ($env{'form.cnum'} =~ /^$match_courseid$/) &&
+            ($env{'form.showdom'} =~ /^$match_domain$/)) {
+            my ($spec,$area,$role,$type);
+            my $role = 'cc';
+            my $spec = "$role./$env{'form.showdom'}/$env{'form.cnum'}";
+            my $type = 'Course';
+            if ($env{'form.crstype'} eq 'community') {
+                $type = 'Community';
             }
-            $r->print('<a href="/adm/requestcourse">'.&mt('Make another request').'</a></p>');
-            return;
+            my $showrole = &Apache::lonnet::plaintext($role,$type);
+            unshift(@links,&mt('Enter new course with role: [_1]',
+                               '<a href="/adm/roles?selectrole=1&amp;'.$spec.'=1">'.$showrole.'</a>'));
+        }
+        if (@links > 1) {
+            $r->print(&mt('New roles will be listed on your [_1]Roles[_2] page.',
+                          '<a href="/adm/roles">','</a>').'&nbsp'.&mt('Choose a role:').
+                       '<ul>');
+            foreach my $link (@links) {
+                $r->print('<li>'.$link.'</li>');
+            }
+            $r->print('</ul>');
+        } elsif (@links == 1) {
+            $r->print('<p>'.$links[0].'</p>');
         }
     }
-    my @excluded = &get_excluded_elements($dom,$states,$action,$state);
+    my @excluded = &get_excluded_elements($dom,$states,$action,$state,$showcredits);
     if ($state eq 'personnel') {
         push(@excluded,'persontotal');
     }
@@ -1429,25 +1576,28 @@ sub print_request_form {
                 $count ++;
             }
             $env{'form.persontotal'} = $count;
-             
         }
     }
     if ($state eq 'enrollment') {
-        push(@excluded,'crosslisttotal');
+        push(@excluded,('sectotal','crosslisttotal'));
+    }
+    if (($state eq 'process') || ($state eq 'reqauthor')) {
+        $r->print('</form>');
+    } else {
+        $r->print(&Apache::lonhtmlcommon::echo_form_input(\@excluded).'</form>');
+        &display_navbuttons($r,$dom,$formname,$prev,$navtxt{'prev'},$next,
+                            $navtxt{'next'},$state);
     }
-    $r->print(&Apache::lonhtmlcommon::echo_form_input(\@excluded).'</form>');
-    &display_navbuttons($r,$dom,$formname,$prev,$navtxt{'prev'},$next,
-                        $navtxt{'next'},$state);
     return;
 }
 
-sub get_cancreate_status {
-    my ($persondom,$personname,$dom) = @_;
+sub get_usertype {
+    my ($persondom,$personname,$curr_rules,$got_rules) = @_;
     my ($rules,$ruleorder) =
         &Apache::lonnet::inst_userrules($persondom,'username');
     my $usertype = &Apache::lonuserutils::check_usertype($persondom,$personname,
-                                                         $rules);
-    return &Apache::lonuserutils::can_create_user($dom,'requestcrs',$usertype);
+                                                         $rules,$curr_rules,$got_rules);
+    return $usertype;
 }
 
 sub check_newuser_rules {
@@ -1455,7 +1605,7 @@ sub check_newuser_rules {
         $got_rules) = @_;
     my $allowed = 1;
     my $newuser = 1;
-    my ($checkhash,$userchkmsg);
+    my ($checkhash,$userchkmsg,$authtype,$authparam);
     my $checks = { 'username' => 1 };
     $checkhash->{$personname.':'.$persondom} = { 'newuser' => $newuser };
     &Apache::loncommon::user_rule_check($checkhash,$checks,$alerts,$rulematch,
@@ -1477,22 +1627,38 @@ sub check_newuser_rules {
             }
         }
     }
-    return ($allowed,$userchkmsg);
+    if ($allowed) {
+        if (ref($rulematch) eq 'HASH') {
+            if (ref($rulematch->{$personname.':'.$persondom}) eq 'HASH') {
+                my $matchedrule = $rulematch->{$personname.':'.$persondom}{'username'};
+                my ($rules,$ruleorder) =
+                    &Apache::lonnet::inst_userrules($persondom,'username');
+                if (ref($rules) eq 'HASH') {
+                    if (ref($rules->{$matchedrule}) eq 'HASH') {
+                        $authtype = $rules->{$matchedrule}{'authtype'};
+                        $authparam = $rules->{$matchedrule}{'authparm'};
+                    }
+                }
+            }
+        }
+    }
+    return ($allowed,$userchkmsg,$authtype,$authparam);
 }
 
 sub get_excluded_elements {
-    my ($dom,$states,$action,$state) = @_;
+    my ($dom,$states,$action,$state,$showcredits) = @_;
     my @excluded = ('counter');
-    my %elements = &form_elements($dom);
+    my ($elements,$instcredits) = &form_elements($dom,$showcredits);
     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]}})) {
+                    if ((ref($elements) eq 'HASH') && 
+                        (ref($elements->{$action}) eq 'HASH')) {
+                        if (ref($elements->{$action}{$items[$i]}) eq 'HASH') {
+                            foreach my $key (keys(%{$elements->{$action}{$items[$i]}})) {
                                 push(@excluded,$key);
                             }
                         }
@@ -1510,8 +1676,9 @@ sub get_excluded_elements {
 
 sub print_enrollment_menu {
     my ($formname,$instcode,$dom,$codetitles,$cat_titles,$cat_order,$code_order,
-        $invalidcrosslist) =@_;
-    my ($sections,$autoenroll,$access_dates,$output,$hasauto);
+        $showcredits,$instcredits,$invalidcrosslist) =@_;
+    my ($sections,$autoenroll,$access_dates,$output,$hasauto,$hascredits,
+        $creditsrow,$domdefcredits);
     my $starttime = time;
     my $endtime = time+(6*30*24*60*60); # 6 months from now, approx
 
@@ -1523,11 +1690,39 @@ sub print_enrollment_menu {
                            'start' => 'Start auto-enrollment',
                            'end'   => 'End auto-enrollment',
                        );
+    if ($showcredits) {
+        unless ($env{'form.crstype'} eq 'community') {
+            my %domdefs = &Apache::lonnet::get_domain_defaults($dom);
+            $domdefcredits = $domdefs{$env{'form.crstype'}.'credits'};
+        }
+    }
     if ($env{'form.crstype'} eq 'official') {
         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').
@@ -1554,7 +1749,7 @@ sub print_enrollment_menu {
                     ' 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;
             }
@@ -1575,12 +1770,29 @@ sub print_enrollment_menu {
                 &mt('No').'</label></span>'. 
                 &Apache::lonhtmlcommon::row_closure(1).
                 &date_setting_table($starttime,$endtime,$formname,'enroll',
-                                    $hasauto,%enrolltitles);
+                                    $hasauto,undef,%enrolltitles);
+            if ($showcredits) {
+                if ($instcredits) {
+                    $creditsrow = &mt('[quant,_1,credit]',$instcredits);
+                } else {
+                    $creditsrow = '<span class="LC_nobreak">'.
+                                  '<input type="text" size="3" name="coursecredits"'.
+                                  ' value="'.$domdefcredits.'" />';
+                }
+                $hascredits = 1;
+            }
+        }
+    } elsif (($env{'form.crstype'} eq 'unofficial') || ($env{'form.crstype'} eq 'textbook')) {
+        if ($showcredits) {
+            $creditsrow = '<span class="LC_nobreak">'.
+                          '<input type="text" size="3" name="coursecredits"'.
+                          ' value="'.$domdefcredits.'"/>';
+            $hascredits = 1;
         }
     }
     my $access_dates = 
         &date_setting_table($starttime,$endtime,$formname,'access',$hasauto,
-                            %accesstitles);
+                            $hascredits,%accesstitles);
     $output .= &Apache::lonhtmlcommon::start_pick_box();
     if ($sections) {
         $output .=  $sections;
@@ -1599,7 +1811,15 @@ sub print_enrollment_menu {
         $output .= &Apache::lonhtmlcommon::row_headline('Access').
                    '<h3>'.$header.'</h3>'.
                    &Apache::lonhtmlcommon::row_closure(1).
-                   $access_dates
+                   $access_dates;
+    }
+    if ($creditsrow) {
+        $output .= &Apache::lonhtmlcommon::row_headline('Credits').
+                   '<h3>'.&mt('Credits earned by students').'</h3>'.
+                   &Apache::lonhtmlcommon::row_closure(1).
+                   &Apache::lonhtmlcommon::row_title(&mt('Default credits')).
+                   $creditsrow.
+                   &Apache::lonhtmlcommon::row_closure(1);
     }
     return '<div>'.&Apache::lonhtmlcommon::start_pick_box().$output.
            &Apache::lonhtmlcommon::end_pick_box().'</div>';
@@ -1664,7 +1884,7 @@ sub inst_section_selector {
 }
 
 sub date_setting_table {
-    my ($starttime,$endtime,$formname,$prefix,$hasauto,%datetitles) = @_;
+    my ($starttime,$endtime,$formname,$prefix,$hasauto,$hascredits,%datetitles)=@_;
     my ($perpetual,$table);
     my $startform = &Apache::lonhtmlcommon::date_setter($formname,$prefix.'start',
                                                         $starttime,'','','',1,'','','',1);
@@ -1675,7 +1895,9 @@ sub date_setting_table {
         $perpetual = ' <span class="LC_nobreak"><label>'.
                      '<input type="checkbox" name="no_end_date" />'.
                      &mt('No end date').'</label></span>';
-        $closure = '1';
+        unless ($hascredits) {
+            $closure = '1';
+        }
     }
 
     my %help_item = (
@@ -1765,6 +1987,7 @@ sub print_personnel_menu {
             official => 'Requestor is automatically assigned Course Coordinator role.',
         );
         $lt{'unofficial'} = $lt{'official'};
+        $lt{'textbook'} = $lt{'textbook'};
         $output .= &Apache::lonhtmlcommon::row_headline().
                   '<h3>'.&Apache::loncommon::help_open_topic('Course_Request_Personnel').'&nbsp;'.$lt{$crstype}.' '.&mt('Include other personnel?').'</h3>';
     }
@@ -1844,51 +2067,93 @@ sub current_lc_sections {
     return @currsecs;
 }
 
-sub print_request_status {
-    my ($dom) = @_;
+sub sorted_request_history {
+    my ($dom,$action,$curr_req) = @_;
+    my ($after,$before,$statusfilter,$crstypefilter);
+    if ($env{'form.status'} ne '') {
+        $statusfilter = $env{'form.status'};
+    }
+    if ($env{'form.crstype'} ne '') {
+        $crstypefilter = $env{'form.crstype'};
+    }
+    if (ref($curr_req) eq 'HASH') {
+        $after = $curr_req->{'requested_after_date'},
+        $before = $curr_req->{'requested_before_date'};
+        $statusfilter = $curr_req->{'status'};
+        $crstypefilter = $curr_req->{'crstype'};
+    }
     my %statusinfo = &Apache::lonnet::dump('courserequests',$env{'user.domain'},
                                            $env{'user.name'},'^status:'.$dom);
-    my ($output,$formname,%queue_by_date);
+    my %queue_by_date;
     my ($types,$typenames) = &Apache::loncommon::course_types();
     foreach my $key (keys(%statusinfo)) {
-        if (($statusinfo{$key} eq 'approval') || ($statusinfo{$key} eq 'pending')) { 
-            (undef,my($cdom,$cnum)) = split(':',$key);
-            next if ($cdom ne $dom);   
-            my $requestkey = $cdom.'_'.$cnum;
-            if ($requestkey =~ /^($match_domain)_($match_courseid)$/) {
-                my %history = &Apache::lonnet::restore($requestkey,'courserequests',
-                                                       $env{'user.domain'},$env{'user.name'});
-                my $entry;
-                my $timestamp = $history{'reqtime'};
-                my $crstype = $history{'crstype'};
-                my $disposition = $history{'disposition'};
+        if ($action eq 'view') {
+            next unless (($statusinfo{$key} eq 'approval') || ($statusinfo{$key} eq 'pending'));
+        } else {
+            next unless (($statusfilter eq 'any') ||
+                          ($statusfilter eq $statusinfo{$key}));
+        }
+        (undef,my($cdom,$cnum)) = split(':',$key);
+        next if ($cdom ne $dom);   
+        my $requestkey = $cdom.'_'.$cnum;
+        if ($requestkey =~ /^($match_domain)_($match_courseid)$/) {
+            my %history = &Apache::lonnet::restore($requestkey,'courserequests',
+                                                   $env{'user.domain'},$env{'user.name'});
+            my $entry;
+            my $reqtime = $history{'reqtime'};
+            my $lastupdate = $history{'timestamp'};
+            my $crstype = $history{'crstype'};
+            my $disposition = $history{'disposition'};
+            my $status = $history{'status'};
+            if ($action eq 'view') {
                 next if ((exists($history{'status'})) && ($history{'status'} eq 'created'));
-                next unless (($env{'form.crstype'} eq 'any') || 
-                            ($env{'form.crstype'} eq $crstype));
+            } else {
+                next if (($reqtime < $after) || ($reqtime > $before));
+            }
+            next unless (($crstypefilter eq 'any') || 
+                         ($crstypefilter eq $crstype));
+            if ($action eq 'view') {
                 next unless (($disposition eq 'approval') || 
                              ($disposition eq 'pending'));
-                if (ref($history{'details'}) eq 'HASH') {
-                    $entry = $requestkey.':'.$crstype.':'.
-                             &escape($history{'details'}{'cdescr'});
-                    if ($crstype eq 'official') {
-                        $entry .= ':'.&escape($history{'details'}{'instcode'}); 
+            }
+            if (ref($history{'details'}) eq 'HASH') {
+                $entry = $requestkey.':'.$crstype.':'.
+                         &escape($history{'details'}{'cdescr'});
+                if ($action eq 'log') {
+                    $entry .= ':'.$lastupdate.':';
+                    if ($statusinfo{$key} ne '') {
+                        $entry .= $statusinfo{$key};
+                    } elsif ($status ne '') {
+                        $entry .= $status;
+                    } else {
+                        $entry .= $disposition;
                     }
                 }
-                if ($entry ne '') {
-                    if (exists($queue_by_date{$timestamp})) {
-                        if (ref($queue_by_date{$timestamp}) eq 'ARRAY') {
-                            push(@{$queue_by_date{$timestamp}},$entry);
-                        }
-                    } else {
-                        @{$queue_by_date{$timestamp}} = ($entry);
+                if ($crstype eq 'official') {
+                    $entry .= ':'.&escape($history{'details'}{'instcode'}); 
+                }
+            }
+            if ($entry ne '') {
+                if (exists($queue_by_date{$reqtime})) {
+                    if (ref($queue_by_date{$reqtime}) eq 'ARRAY') {
+                        push(@{$queue_by_date{$reqtime}},$entry);
                     }
+                } else {
+                    @{$queue_by_date{$reqtime}} = ($entry);
                 }
             }
         }
     }
-    $formname = 'requestcrs';
+    return %queue_by_date;
+}
+
+sub print_request_status {
+    my ($dom,$action) = @_;
+    my %queue_by_date = &sorted_request_history($dom,$action);
     my @sortedtimes = sort {$a <=> $b} (keys(%queue_by_date));
-    $output = '<input type="hidden" name="action" value="'.$env{'form.action'}.'" />'."\n".
+    my $formname = 'requestcrs';
+    my ($types,$typenames) = &Apache::loncommon::course_types();
+    my $output = '<input type="hidden" name="action" value="'.$env{'form.action'}.'" />'."\n".
 
               '<input type="hidden" name="state" value="'.$env{'form.state'}.'" />'."\n".
               '<input type="hidden" name="crstype" value="'.$env{'form.crstype'}.'" />'."\n".
@@ -2053,8 +2318,8 @@ ENDJS
 }
 
 sub viewcancel_javascript {
-    my $alert = &mt('Are you sure you want to cancel this request?\\n'.
-                    'Your request will be removed.');
+    my $alert = &mt('Are you sure you want to cancel this request?').'\\n'.
+                &mt('Your request will be removed.');
     return << "ENDJS";
 function nextPage(formname,nextstate) {
     if (confirm('$alert')) {
@@ -2068,13 +2333,294 @@ ENDJS
 }
 
 sub print_request_logs {
-    my ($jscript,$loaditems,$crumb) = @_;
+    my ($r,$dom,$jscript,$loaditems,$crumb) = @_;
+    my $title;
+    if ($env{'form.crstype'} eq 'community') {
+        $title = 'Community Request Logs';
+    } elsif ($env{'form.crstype'} eq 'any') {
+        $title = 'Course/Community Request Logs';
+    } else {
+        $title = 'Course Request Logs';
+    }
+    $r->print(&header($title,$jscript,$loaditems).$crumb);
+    my $formname = 'requestcrs';
+    $r->print('<form action="/adm/requestcourse" method="post" name="'.$formname.'" onsubmit="javascript:setPage(this);">'."\n".
+              '<input type="hidden" name="action" value="log" />'."\n".
+              '<input type="hidden" name="state" value="display" />'."\n");
+    # set defaults
+    my $now = time();
+    my $defstart = $now - (7*24*3600); #7 days ago
+    my %defaults = (
+                     page                => '1',
+                     show                => '10',
+                     crstype             => 'any',
+                     status              => 'any',
+                     requested_before_date => $now,
+                     requested_after_date  => $defstart,
+                   );
+    my ($types,$typenames) = &Apache::loncommon::course_types();
+    my $more_records = 0;
+    my %curr;
+    foreach my $item ('show','page','crstype','status') {
+        $curr{$item} = $env{'form.'.$item};
+    }
+    $curr{'requested_after_date'} = &Apache::lonhtmlcommon::get_date_from_form('requested_after_date');
+    $curr{'requested_before_date'} = &Apache::lonhtmlcommon::get_date_from_form('requested_before_date');
+    foreach my $key (keys(%defaults)) {
+        if ($curr{$key} eq '') {
+            $curr{$key} = $defaults{$key};
+        }
+    }
+    my ($statuses,$statusnames) = &reqstatus_names($curr{'crstype'});
+    $r->print('<input type="hidden" name="page" value="'.$curr{'page'}.'" />'.
+              &requestlog_display_filter($formname,\%curr));
+    my %queue_by_date = &sorted_request_history($dom,$env{'form.action'},\%curr);
+    my @sortedtimes = sort {$a <=> $b} (keys(%queue_by_date));
+    my $showntablehdr = 0;
+    my $tablehdr = &Apache::loncommon::start_data_table().
+                   &Apache::loncommon::start_data_table_header_row().
+                   '<th>&nbsp;</th><th>'.&mt('Request Date').'</th>'.
+                   '<th>'.&mt('Description').'</th>';
+    if ($curr{'crstype'} eq 'any') {
+        $tablehdr .= '<th>'.&mt('Course Type').'</th>';
+    }
+    if (($curr{'crstype'} eq 'official') || ($curr{'crstype'} eq 'any')) {
+        $tablehdr .= '<th>'.&mt('Institutional Code').'</th>';
+    }
+    if ($curr{'status'} eq 'any') {
+        $tablehdr .= '<th>'.&mt('Status').'</th>';
+    } elsif ($curr{'status'} eq 'created') {
+        $tablehdr .= '<th>'.&mt('Creation Date').'</th>';
+    } elsif ($curr{'status'} eq 'cancelled') {
+        $tablehdr .= '<th>'.&mt('Cancellation Date').'</th>';
+    } elsif ($curr{'status'} eq 'rejected') {
+        $tablehdr .= '<th>'.&mt('Rejection Date').'</th>';
+    }
+    $tablehdr .= &Apache::loncommon::end_data_table_header_row();
+    my ($minshown,$maxshown);
+    $minshown = 1;
+    my $count = 0;
+    if ($curr{'show'} ne &mt('all')) {
+        $maxshown = $curr{'page'} * $curr{'show'};
+        if ($curr{'page'} > 1) {
+            $minshown = 1 + ($curr{'page'} - 1) * $curr{'show'};
+        }
+    }
+    my $norecords;
+    if (@sortedtimes > 0) {
+        foreach my $item (@sortedtimes) {
+            if ($curr{'show'} ne &mt('all')) {
+                if ($count >= $curr{'page'} * $curr{'show'}) {
+                    $more_records = 1;
+                    last;
+                }
+            }
+            $count ++;
+            next if ($count < $minshown);
+            if (!$showntablehdr) {
+                $r->print($tablehdr);
+                $showntablehdr = 1;
+            }
+            my $showtime = &Apache::lonlocal::locallocaltime($item);
+            if (ref($queue_by_date{$item}) eq 'ARRAY') {
+                foreach my $request (sort(@{$queue_by_date{$item}})) {
+                    my ($key,$crstype,$desc,$timestamp,$status,$instcode) = split(':',$request);
+                    my ($cdom,$cnum) = split('_',$key);
+                    my $output = &Apache::loncommon::start_data_table_row().
+     '<td>'.$count.'</td>'.
+     '<td>'.$showtime.'</td>'.
+     '<td>'.&unescape($desc).'</td>';
+                    if ($curr{'crstype'} eq 'any') {
+                        my $typename;
+                        if (ref($typenames) eq 'HASH') {
+                            $typename = &mt($typenames->{$crstype});
+                        }
+                        if ($typename eq '') {
+                            $typename = &mt('Unknown type');
+                        }
+                        $output .= '<td>'.$typename.'</td>';
+                    }
+                    if (($curr{'crstype'} eq 'any') ||
+                        ($curr{'crstype'} eq 'official')) {
+                        my $showinstcode;
+                        if ($crstype eq 'official') {
+                            $showinstcode = &unescape($instcode);
+                        } else {
+                            $showinstcode = &mt('Not applicable');
+                        }
+                        $output .= '<td>'.$showinstcode.'</td>';
+                    }
+                    if ($curr{'status'} eq 'any') {
+                        my $statusname = &mt('Unknown status');
+                        if (ref($statusnames) eq 'HASH') {
+                            if ($statusnames->{$status} ne '') {
+                                $statusname = $statusnames->{$status};
+                            }
+                        }
+                        if (($status eq 'created') || ($status eq 'cancelled') ||
+                            ($status eq 'rejected')) {
+                            $statusname .= ' '.&Apache::lonlocal::locallocaltime($timestamp);
+                        }
+                        $output .= '<td>'.$statusname.'</td>';
+                    } elsif (($status eq 'created') || ($status eq 'cancelled') ||
+                             ($status eq 'rejected')) {
+                         $output .= '<td>'.&Apache::lonlocal::locallocaltime($timestamp).'</td>';
+                    }
+                    $output .= &Apache::loncommon::end_data_table_row();
+                    $r->print($output);
+                }
+            }
+        }
+        if ($showntablehdr) {  
+            $r->print(&Apache::loncommon::end_data_table());
+            if (($curr{'page'} > 1) || ($more_records)) {
+                $r->print('<table><tr>');
+                if ($curr{'page'} > 1) {
+                    $r->print('<td><a href="javascript:chgPage('."'previous'".');">'.&mt('Previous [_1] changes',$curr{'show'}).'</a></td>');
+                }
+                if ($more_records) {
+                    $r->print('<td><a href="javascript:chgPage('."'next'".');">'.&mt('Next [_1] changes',$curr{'show'}).'</a></td>');
+                }
+                $r->print('</tr></table>');
+                $r->print(<<"ENDSCRIPT");
+<script type="text/javascript">
+// <![CDATA[
+function chgPage(caller) {
+    if (caller == 'previous') {
+        document.$formname.page.value --;
+    }
+    if (caller == 'next') {
+        document.$formname.page.value ++;
+    }
+    document.$formname.submit();
+    return;
+}
+// ]]>
+</script>
+ENDSCRIPT
+            }
+        } else {
+            $norecords = 1;
+        }
+    } else {
+        $norecords = 1;
+    }
+    if ($norecords) {
+        $r->print('<p class="LC_info">'.
+                  &mt('There are no records to display').
+                  '</p>');
+    }
+    $r->print('</form>'.
+              &Apache::loncommon::end_page());
     return;
 }
 
+sub reqstatus_names {
+    my ($crstype) = @_;
+    my @statuses = qw(created approval pending rejected cancelled);
+    my %statusnames =
+            &Apache::lonlocal::texthash (
+                        created   => 'Created',
+                        approval  => 'Queued pending approval',
+                        pending   => 'Queued pending validation',
+                        rejected  => 'Request rejected',
+                        cancelled => 'Request cancelled',
+            );
+    if (($crstype eq 'official') || ($crstype eq 'unofficial') || ($crstype eq 'textbook')) {
+        $statusnames{'created'} = &mt('Course created');
+    } elsif ($crstype eq 'community') {
+        $statusnames{'created'} = &mt('Community created');
+    }
+    return (\@statuses,\%statusnames);
+}
+
+sub requestlog_display_filter {
+    my ($formname,$curr) = @_;
+    my $nolink = 1;
+    my $output = '<table><tr><td valign="top">'.
+                 '<span class="LC_nobreak"><b>'.&mt('Records/page:').'</b></span><br />'.
+                 &Apache::lonmeta::selectbox('show',$curr->{'show'},undef,
+                                              (&mt('all'),5,10,20,50,100,1000,10000)).
+                 '</td><td>&nbsp;&nbsp;</td>';
+    my $startform =
+        &Apache::lonhtmlcommon::date_setter($formname,'requested_after_date',
+                                            $curr->{'requested_after_date'},undef,
+                                            undef,undef,undef,undef,undef,undef,$nolink);
+    my $endform =
+        &Apache::lonhtmlcommon::date_setter($formname,'requested_before_date',
+                                            $curr->{'requested_before_date'},undef,
+                                            undef,undef,undef,undef,undef,undef,$nolink);
+    $output .= '<td valign="top"><b>'.&mt('Window during which course/community was requested:').'</b><br />'.
+               '<table><tr><td>'.&mt('After:').
+               '</td><td>'.$startform.'</td></tr>'.
+               '<tr><td>'.&mt('Before:').'</td>'.
+               '<td>'.$endform.'</td></tr></table>'.
+               '</td>'.
+               '<td>&nbsp;&nbsp;</td>';
+    my ($types,$typenames) = &Apache::loncommon::course_types();
+    if (ref($types) eq 'ARRAY') {
+        if (@{$types} > 1) {
+            $output .= '<td valign="top"><b>'.
+                       &mt('Course Type:').'</b><br /><select name="crstype">';
+            my $selstr = '';
+            if ($curr->{'crstype'} eq 'any') {
+                $selstr = ' selected="selected"';
+            }
+            $output .= '<option value="any"'.$selstr.'>'.&mt('All types').'</option>'."\n";
+            foreach my $crstype (@{$types}) {
+                my $selstr = '';
+                if ($curr->{'crstype'} eq $crstype) {
+                    $selstr = ' selected="selected"';
+                }
+                my $typename = $crstype;
+                if (ref($typenames) eq 'HASH') {
+                    if ($typenames->{$crstype} ne '') {
+                        $typename = $typenames->{$crstype};
+                    }
+                }
+                $output .= '<option value="'.$crstype.'"'.$selstr.'>'.$typename.'</option>'."\n";
+            }
+            $output .= '</select></td>';
+        }
+    }
+    my ($statuses,$statusnames) = &reqstatus_names($curr->{'crstype'});
+    if (ref($statuses) eq 'ARRAY') {
+        if (@{$statuses} > 1) {
+            $output .= '<td valign="top"><b>'.
+                       &mt('Request Status:').'</b><br /><select name="status">';
+            my $selstr = '';
+            if ($curr->{'status'} eq 'any') {
+                $selstr = ' selected="selected"';
+            }
+            $output .= '<option value="any"'.$selstr.'>'.&mt('Any status').'</option>'."\n";
+            foreach my $status (@{$statuses}) {
+                my $selstr = '';
+                if ($curr->{'status'} eq $status) {
+                    $selstr = ' selected="selected"';
+                }
+                my $statusname = $status;
+                if (ref($statusnames) eq 'HASH') {
+                    if ($statusnames->{$status} ne '') {
+                        $statusname = $statusnames->{$status};
+                    }
+                }
+                $output .= '<option value="'.$status.'"'.$selstr.'>'.$statusname.'</option>'."\n";
+            }
+            $output .= '</select></td>';
+        }
+    }
+    $output .= '</tr></table>';
+
+    # Update Display button
+    $output .= '<p>'.
+               '<input type="submit" value="'.&mt('Update Display').'" />'.
+               '</p><hr />';
+    return $output;
+}
+
 sub print_review {
     my ($dom,$codetitles,$cat_titles,$cat_order,$code_order,$uname,$udom,
-        $disallowed,$disallowmsg) = @_;
+        $disallowed,$disallowmsg,$instcredits) = @_;
     my ($types,$typename) = &Apache::loncommon::course_types();
     my ($owner,$ownername,$owneremail);
     if ($uname eq '' || $udom eq '') {
@@ -2122,6 +2668,12 @@ sub print_review {
                 }
             }
         }
+        $inst_headers .= '<th>'.&mt('Credits').'</th>';
+        if ($instcredits) {
+            $inst_values .= '<td>'.$instcredits.'</td>';
+        } else {
+            $inst_values .= '<td>'.$env{'form.coursecredits'}.'</td>';
+        }
         if (&Apache::lonnet::auto_run('',$dom)) {
             $enrollrow_title = &mt('Enrollment');
             $enroll_headers = '<th>'.&mt('Automatic Adds').'</th>'.
@@ -2191,6 +2743,9 @@ sub print_review {
             $section_values .= $xlistinfo;
         }
         $section_values .= '</table></td>';
+    } elsif (($env{'form.crstype'} eq 'unofficial') || ($env{'form.crstype'} eq 'textbook')) {
+        $inst_headers .= '<th>'.&mt('Credits').'</th>';
+        $inst_values .= '<td>'.$env{'form.coursecredits'}.'</td>';
     }
 
     my %ctxt = &clone_text();
@@ -2198,8 +2753,8 @@ sub print_review {
     if (($env{'form.cloning'}) &&
         ($env{'form.clonecrs'} =~ /^$match_name$/) && 
         ($env{'form.clonedom'} =~ /^$match_domain$/)) {
-        my $canclone = &Apache::loncoursequeueadmin::can_clone_course($env{'user.name'},
-                           $env{'user.domain'},$env{'form.clonecrs'},$env{'form.clonedom'},
+        my $canclone = &Apache::loncoursequeueadmin::can_clone_course($uname,
+                           $udom,$env{'form.clonecrs'},$env{'form.clonedom'},
                            $env{'form.crstype'});
         if ($canclone) {
             my %courseenv = &Apache::lonnet::userenvironment($env{'form.clonedom'},
@@ -2367,6 +2922,7 @@ sub courseinfo_form {
                 community => 'You must provide a (brief) community description.'
              );
     $lt{'unofficial'} = $lt{'official'};
+    $lt{'textbook'} = $lt{'official'};
     my $js_validate = <<"ENDJS";
 <script type="text/javascript">
 // <![CDATA['
@@ -2428,7 +2984,7 @@ ENDJS
                '<label><input type="radio" name="cloning" value="1" '.
                'onclick="javascript:toggleCloning()" />'.
                &mt('Yes').('&nbsp;'x2).'</label><label>'.
-               '<input type="radio" name="cloning" value="0" '.
+               '<input type="radio" name="cloning" value="0" checked="checked" '.
                'onclick="javascript:toggleCloning()" />'.&mt('No').'</label>'.
                '</h3>'.
                &Apache::lonhtmlcommon::row_closure(1).
@@ -2447,15 +3003,16 @@ sub clone_form {
     if ($crstype eq 'community') {
         $type = 'Community';
     }
-    my $cloneform = &Apache::loncommon::select_dom_form($dom,'clonedom').'&nbsp;'.
-                    &Apache::loncommon::selectcourse_link($formname,'clonecrs','clonedom','','','',$type);
     my %lt = &clone_text();
     my $output .= 
-        &Apache::lonhtmlcommon::row_title($lt{'cid'}).'<label>'.
-        '<input type="text" size="25" name="clonecrs" value=""  />'.
-        '</label>'.&Apache::lonhtmlcommon::row_closure(1).
         &Apache::lonhtmlcommon::row_title($lt{'dmn'}).'<label>'.
-        $cloneform.'</label>'.&Apache::lonhtmlcommon::row_closure(1).
+        &Apache::loncommon::select_dom_form($dom,'clonedom').'</label>'.
+        &Apache::lonhtmlcommon::row_closure(1).
+        &Apache::lonhtmlcommon::row_title($lt{'cid'}).'<label>'.
+        '<input type="text" size="25" name="clonecrs" value="" onfocus="this.blur();opencrsbrowser('."'$formname','clonecrs','clonedom','','','','','$type'".')" />'.
+        '</label>&nbsp;'.
+        &Apache::loncommon::selectcourse_link($formname,'clonecrs','clonedom','','','',$type).
+        &Apache::lonhtmlcommon::row_closure(1).
         &Apache::lonhtmlcommon::row_title($lt{'dsh'}).'<label>'.
         '<input type="radio" name="datemode" value="delete" /> '.$lt{'ncd'}.
         '</label><br /><label>'.
@@ -2488,7 +3045,6 @@ sub coursecode_form {
                    );
     my %helpitem = ( 
                      instcode => 'Course_Request_Category',
-                     crosslist => 'Course_Request_Crosslist',
                    );
     if ((ref($codetitles) eq 'ARRAY') && (ref($cat_titles) eq 'HASH') && 
         (ref($cat_order))) {
@@ -2505,7 +3061,11 @@ sub coursecode_form {
             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 />'.
@@ -2570,6 +3130,26 @@ sub coursecode_form {
     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 '') {
@@ -2662,9 +3242,9 @@ sub display_navbuttons {
 }
 
 sub print_request_outcome {
-    my ($dom,$codetitles,$code_order) = @_;
+    my ($dom,$codetitles,$code_order,$instcredits) = @_;
     my ($output,$cnum,$now,$req_notifylist,$crstype,$enrollstart,$enrollend,
-        %sections,%crosslistings,%personnel,@baduname,@missingdom,%domconfig,);
+        %sections,%crosslistings,%personnel,@baduname,@missingdom,%domconfig);
     my $sectotal = $env{'form.sectotal'};
     my $crosslisttotal = 0;
     $cnum = $env{'form.cnum'};
@@ -2699,6 +3279,10 @@ sub print_request_outcome {
                         push(@instsections,$sec);
                     }
                     $sections{$i}{'loncapa'} = $env{'form.loncapasec_'.$i};
+                    $sections{$i}{'loncapa'} =~ s/\W//g;
+                    if ($sections{$i}{'loncapa'} eq 'none') {
+                        $sections{$i}{'loncapa'} = '';
+                    }
                 }
             }
         }
@@ -2724,6 +3308,7 @@ sub print_request_outcome {
         $enrollstart = '';
         $enrollend = '';
     }
+    my (%alerts,%rulematch,%inst_results,%curr_rules,%got_rules,%disallowmsg,%skipped);
     for (my $i=0; $i<$env{'form.persontotal'}; $i++) {
         my $uname = $env{'form.person_'.$i.'_uname'};
         my $udom = $env{'form.person_'.$i.'_dom'};
@@ -2735,6 +3320,56 @@ sub print_request_outcome {
                              lastname     => $env{'form.person_'.$i.'_lastname'},
                              emailaddr    => $env{'form.person_'.$i.'_emailaddr'},
                                                    };
+                    if (&Apache::lonnet::homeserver($uname,$udom) eq 'no_host') {
+                        my $usertype = &get_usertype($udom,$uname,\%curr_rules,\%got_rules);
+                        if (&Apache::lonuserutils::can_create_user($udom,'requestcrs',$usertype)) {
+                            my ($allowed,$msg,$authtype,$authparam) =
+                                &check_newuser_rules($udom,$uname,\%alerts,\%rulematch,
+                                                     \%inst_results,\%curr_rules,\%got_rules);
+                            if ($allowed) {
+                                my %domdefaults = &Apache::lonnet::get_domain_defaults($udom);
+                                if ($usertype eq 'official') {
+                                    if ($authtype eq '') {
+                                        $authtype = $domdefaults{'auth_def'};
+                                        $authparam = $domdefaults{'auth_arg_def'};
+                                    } else {
+                                        if ($authtype eq 'loc') {
+                                            $authtype = 'localauth';
+                                        } elsif ($authtype eq 'int') {
+                                            $authtype = 'internal';
+                                        }
+                                        if ($authtype !~ /^(krb4|krb5|internal|localauth)$/) {
+                                            $authtype = $domdefaults{'auth_def'};
+                                            $authparam = $domdefaults{'auth_arg_def'};
+                                        }
+                                    }
+                                } elsif ($usertype eq 'unofficial') {
+                                    if ($authtype eq '') {
+                                        $authtype = 'internal';
+                                        $authparam = '';
+                                    }
+                                } else {
+                                    $authtype = $domdefaults{'auth_def'};
+                                    $authparam = $domdefaults{'auth_arg_def'};
+                                }
+                                if (($authtype eq '') ||
+                                    (($authtype =~/^krb(4|5)$/) && ($authparam eq '')) ||
+                                    ($authtype !~ /^(krb4|krb5|internal|localauth)$/)) {
+                                    $skipped{$uname.':'.$udom} = 1;
+                                    next;
+                                } else {
+                                    $personnel{$uname.':'.$udom}{'authtype'} = $authtype;
+                                    $personnel{$uname.':'.$udom}{'autharg'} = $authparam;
+                                }
+                            } else {
+                                $skipped{$uname.':'.$udom} = 1;
+                                next;
+                            }
+                        } else {
+                            $skipped{$uname.':'.$udom} = 1;
+                            next;
+                        }
+                    }
                 }
                 my $role = $env{'form.person_'.$i.'_role'};
                 unless ($role eq '') {
@@ -2780,6 +3415,11 @@ sub print_request_outcome {
             push(@baduname,$uname.':'.$udom);
         }
     }
+    if (keys(%skipped)) {
+        foreach my $key (keys(%skipped)) {
+            delete($personnel{$key}); 
+        }
+    }
     my ($accessstart,$accessend) = &dates_from_form('accessstart','accessend');
     my $autodrops = 0;
     if ($env{'form.autodrops'}) {
@@ -2787,15 +3427,18 @@ sub print_request_outcome {
     }
     my $autoadds = 0;
     if ($env{'form.autoadds'}) {
-        $autodrops = $env{'form.autoadds'};
-    }
-    if ($env{'form.autoadds'}) {
-        $autodrops = $env{'form.autoadds'};
+        $autoadds = $env{'form.autoadds'};
     }
     my $instcode = '';
     if (exists($env{'form.instcode'})) {
         $instcode = $env{'form.instcode'};
     }
+    my $credits;
+    if ($instcredits) {
+        $credits = $instcredits;
+    } elsif (exists($env{'form.coursecredits'})) {
+        $credits = $env{'form.coursecredits'};
+    }
     my $clonecrs = '';
     my $clonedom = '';
     if (($env{'form.cloning'}) &&
@@ -2823,6 +3466,7 @@ sub print_request_outcome {
                     cdescr         => $env{'form.cdescr'},
                     crstype        => $env{'form.crstype'},
                     instcode       => $instcode,
+                    defaultcredits => $credits, 
                     clonedom       => $clonedom,
                     clonecrs       => $clonecrs,
                     datemode       => $env{'form.datemode'},
@@ -2841,8 +3485,9 @@ sub print_request_outcome {
                   };
     my (@inststatuses,$storeresult,$creationresult);
     my $val = 
-        &Apache::loncoursequeueadmin::get_processtype($env{'user.name'},$env{'user.domain'},
-            $env{'user.adv'},$dom,$crstype,\@inststatuses,\%domconfig);
+        &Apache::loncoursequeueadmin::get_processtype('course',$env{'user.name'},
+                                                      $env{'user.domain'},$env{'user.adv'},
+                                                      $dom,$crstype,\@inststatuses,\%domconfig);
     if ($val eq '') {
         if ($crstype eq 'official') {
             $output = &mt('You are not permitted to request creation of official courses.');
@@ -2850,6 +3495,8 @@ sub print_request_outcome {
             $output = &mt('You are not permitted to request creation of unofficial courses.');
         } elsif ($crstype eq 'community') {
             $output = &mt('You are not permitted to request creation of communities');
+        } elsif ($crstype eq 'textbook') {
+            $output = &mt('You are not permitted to request creation of textbook courses');
         } else {
             $output = &mt('Unrecognized course type: [_1]',$crstype);
         }
@@ -2958,6 +3605,9 @@ sub print_request_outcome {
                                             description => $env{'form.cdescr'}, 
                                           },
                           };
+            if ($crstype eq 'official') {
+                $request->{$requestid}->{'instcode'} = $instcode;
+            }
             my $statuskey = 'status:'.$dom.':'.$cnum;
             my %userreqhash = &Apache::lonnet::get('courserequests',[$statuskey],
                                                    $env{'user.domain'},$env{'user.name'});
@@ -2994,7 +3644,7 @@ sub print_request_outcome {
         }
         ($storeresult,my $updateresult) = 
             &Apache::loncoursequeueadmin::update_coursereq_status(\%reqhash,$dom,
-                $cnum,$reqstatus,'request');
+                $cnum,$reqstatus,'request',$env{'user.domain'},$env{'user.name'});
         if ($modified && $queued && $storeresult eq 'ok') {
             if ($crstype eq 'community') {
                 $output .= '<p>'.&mt('Your community request has been updated').'</p>';
@@ -3203,7 +3853,7 @@ sub check_autolimit {
             if (($crstype eq 'community') && 
                 (exists($crsroles{$cnum.':'.$cdom.':co'}))) {
                 $count ++;
-            } elsif ((($crstype eq 'official') || ($crstype eq 'unofficial')) &&
+            } elsif ((($crstype eq 'official') || ($crstype eq 'unofficial') || ($crstype eq 'textbook')) &&
                      (exists($crsroles{$cnum.':'.$cdom.':cc'}))) {
                 $count ++;
             }
@@ -3249,18 +3899,31 @@ sub retrieve_settings {
             }
             $env{'form.clonecrs'} = $reqinfo{'clonecrs'};
             $env{'form.clonedom'} = $reqinfo{'clonedom'};
+            if (($reqinfo{'clonecrs'} ne '') && ($reqinfo{'clonedom'} ne '')) {
+                $env{'form.cloning'} = 1;
+            }
             $env{'form.datemode'} = $reqinfo{'datemode'};
             $env{'form.dateshift'} = $reqinfo{'dateshift'};
-            if (($reqinfo{'crstype'} eq 'official') && ($reqinfo{'instcode'} ne '')) { 
-                 $env{'form.sectotal'} = $reqinfo{'sectotal'};
-                 $env{'form.crosslisttotal'} = $reqinfo{'crosslisttotal'};
-                 $env{'form.autoadds'} = $reqinfo{'autoadds'};
-                 $env{'form.autdrops'} = $reqinfo{'autodrops'};
-                 $env{'form.instcode'} = $reqinfo{'instcode'};
-                 my $crscode = { 
-                                 $cnum => $reqinfo{'instcode'},
-                               };
-                 &extract_instcode($dom,'instcode',$crscode,$cnum);
+            if ($reqinfo{'crstype'} eq 'official') {
+                $env{'form.autoadds'} = $reqinfo{'autoadds'};
+                $env{'form.autodrops'} = $reqinfo{'autodrops'};
+                if ($reqinfo{'instcode'} ne '') { 
+                    $env{'form.sectotal'} = $reqinfo{'sectotal'};
+                    $env{'form.crosslisttotal'} = $reqinfo{'crosslisttotal'};
+                    $env{'form.instcode'} = $reqinfo{'instcode'};
+                    my $crscode = { 
+                                    $cnum => $reqinfo{'instcode'},
+                                  };
+                    &extract_instcode($dom,'instcode',$crscode,$cnum);
+                    (undef,undef,my $instcredits) =
+                        &Apache::lonnet::auto_validate_instcode(undef,$dom,
+                                                                $reqinfo{'instcode'});
+                    if ($instcredits ne $reqinfo{'defaultcredits'}) {
+                        $env{'form.coursecredits'} = $reqinfo{'defaultcredits'};
+                    }
+                }
+            } elsif (($reqinfo{'crstype'} eq 'unofficial') || ($reqinfo{'crstype'} eq 'textbook')) {
+                $env{'form.coursecredits'} = $reqinfo{'defaultcredits'};
             }
             my @currsec;
             if (ref($reqinfo{'sections'}) eq 'HASH') {