[LON-CAPA-cvs] cvs: loncom / lond /enrollment localenroll.pm /interface loncoursequeueadmin.pm lonrequestcourse.pm /lonnet/perl lonnet.pm

raeburn raeburn at source.lon-capa.org
Fri Jan 3 13:39:56 EST 2014


raeburn		Fri Jan  3 18:39:56 2014 EDT

  Modified files:              
    /loncom	lond 
    /loncom/lonnet/perl	lonnet.pm 
    /loncom/interface	lonrequestcourse.pm loncoursequeueadmin.pm 
    /loncom/enrollment	localenroll.pm 
  Log:
  - New routine in localenroll.pm -- &crsreq_updates() -- to support 
    domain-specific operations during course request process.
  - Tabbed interface used for textbook-type course requests, one tab
    for course creation, one for request logs.
  - Column for unique codes included in user's request log display, if
    domain has enabled use of unique codes.
  - Correction to LON-CAPA messaging of unique code -- recipient should
    be requestor.
  
  
-------------- next part --------------
Index: loncom/lond
diff -u loncom/lond:1.505 loncom/lond:1.506
--- loncom/lond:1.505	Wed Jan  1 17:41:37 2014
+++ loncom/lond	Fri Jan  3 18:39:43 2014
@@ -2,7 +2,7 @@
 # The LearningOnline Network
 # lond "LON Daemon" Server (port "LOND" 5663)
 #
-# $Id: lond,v 1.505 2014/01/01 17:41:37 raeburn Exp $
+# $Id: lond,v 1.506 2014/01/03 18:39:43 raeburn Exp $
 #
 # Copyright Michigan State University Board of Trustees
 #
@@ -61,7 +61,7 @@
 my $status='';
 my $lastlog='';
 
-my $VERSION='$Revision: 1.505 $'; #' stupid emacs
+my $VERSION='$Revision: 1.506 $'; #' stupid emacs
 my $remoteVERSION;
 my $currenthostid="default";
 my $currentdomainid;
@@ -5313,6 +5313,49 @@
 }
 &register_handler("autocrsreqvalidation", \&validate_crsreq_handler, 0, 1, 0);
 
+sub crsreq_update_handler {
+    my ($cmd, $tail, $client) = @_;
+    my $userinput = "$cmd:$tail";
+    my ($cdom,$cnum,$crstype,$action,$ownername,$ownerdomain,$fullname,$title,$code,$infohashref) =
+        split(/:/, $tail);
+    $crstype = &unescape($crstype);
+    $action = &unescape($action);
+    $ownername = &unescape($ownername);
+    $ownerdomain = &unescape($ownerdomain);
+    $fullname = &unescape($fullname);
+    $title = &unescape($title);
+    $code = &unescape($code);
+    my $incoming = &Apache::lonnet::thaw_unescape($infohashref);
+    my ($result,$outcome);
+    eval {
+        local($SIG{__DIE__})='DEFAULT';
+        my %rtnhash;
+        $outcome = &localenroll::crsreq_updates($cdom,$cnum,$crstype,$action,
+                                                $ownername,$ownerdomain,$fullname,
+                                                $title,$code,$incoming,\%rtnhash);
+        if ($outcome eq 'ok') {
+            my @posskeys = qw(createdweb createdmsg queuedweb queuedmsg formitems reviewweb);
+            foreach my $key (keys(%rtnhash)) {
+                if (grep(/^\Q$key\E/, at posskeys)) {
+                    $result .= &escape($key).'='.&Apache::lonnet::freeze_escape($rtnhash{$key}).'&';
+                }
+            }
+            $result =~ s/\&$//;
+        }
+    };
+    if (!$@) {
+        if ($outcome eq 'ok') {
+            &Reply($client, \$result, $userinput);
+        } else {
+            &Reply($client, "format_error\n", $userinput);
+        }
+    } else {
+        &Failure($client,"unknown_cmd\n",$userinput);
+    }
+    return 1;
+}
+&register_handler("autocrsrequpdate", \&crsreq_update_handler, 0, 1, 0);
+
 #
 #   Read and retrieve institutional code format (for support form).
 # Formal Parameters:
Index: loncom/lonnet/perl/lonnet.pm
diff -u loncom/lonnet/perl/lonnet.pm:1.1247 loncom/lonnet/perl/lonnet.pm:1.1248
--- loncom/lonnet/perl/lonnet.pm:1.1247	Wed Jan  1 17:41:42 2014
+++ loncom/lonnet/perl/lonnet.pm	Fri Jan  3 18:39:48 2014
@@ -1,7 +1,7 @@
 # The LearningOnline Network
 # TCP networking package
 #
-# $Id: lonnet.pm,v 1.1247 2014/01/01 17:41:42 raeburn Exp $
+# $Id: lonnet.pm,v 1.1248 2014/01/03 18:39:48 raeburn Exp $
 #
 # Copyright Michigan State University Board of Trustees
 #
@@ -7851,6 +7851,33 @@
     return $response;
 }
 
+sub auto_crsreq_update {
+    my ($cdom,$cnum,$crstype,$action,$ownername,$ownerdomain,$fullname,$title,
+        $code,$inbound) = @_;
+    my ($homeserver,%crsreqresponse);
+    if ($cdom =~ /^$match_domain$/) {
+        $homeserver = &domain($cdom,'primary');
+    }
+    unless (($homeserver eq 'no_host') || ($homeserver eq '')) {
+        my $info;
+        if (ref($inbound) eq 'HASH') {
+            $info = &freeze_escape($inbound);
+        }
+        my $response=&reply('autocrsrequpdate:'.$cdom.':'.$cnum.':'.&escape($crstype).
+                            ':'.&escape($action).':'.&escape($ownername).':'.
+                            &escape($ownerdomain).':'.&escape($fullname).':'.
+                            &escape($title).':'.&escape($code).':'.$info,$homeserver);
+        unless ($response =~ /(con_lost|error|no_such_host|refused)/) {
+            my @items = split(/&/,$response);
+            foreach my $item (@items) {
+                my ($key,$value) = split('=',$item);
+                $crsreqresponse{&unescape($key)} = &thaw_unescape($value);
+            }
+        }
+    }
+    return \%crsreqresponse;
+}
+
 # ------------------------------------------------------- Course Group routines
 
 sub get_coursegroups {
Index: loncom/interface/lonrequestcourse.pm
diff -u loncom/interface/lonrequestcourse.pm:1.72 loncom/interface/lonrequestcourse.pm:1.73
--- loncom/interface/lonrequestcourse.pm:1.72	Fri Dec 27 14:34:52 2013
+++ loncom/interface/lonrequestcourse.pm	Fri Jan  3 18:39:51 2014
@@ -1,7 +1,7 @@
 # The LearningOnline Network
 # Request a course
 #
-# $Id: lonrequestcourse.pm,v 1.72 2013/12/27 14:34:52 raeburn Exp $
+# $Id: lonrequestcourse.pm,v 1.73 2014/01/03 18:39:51 raeburn Exp $
 #
 # Copyright Michigan State University Board of Trustees
 #
@@ -128,7 +128,7 @@
     }
 
     &Apache::loncommon::get_unprocessed_cgi($ENV{'QUERY_STRING'},
-        ['action','showdom','cnum','state','crstype','queue']);
+        ['action','showdom','cnum','state','crstype','queue','tabs']);
     &Apache::lonhtmlcommon::clear_breadcrumbs();
     my $dom = &get_course_dom();
     my $action = $env{'form.action'};
@@ -155,16 +155,31 @@
     }
 
     if ($canreq) {
-        if ((scalar(keys(%can_request)) == 1) && ($can_request{'textbook'})) {
+        if (($env{'form.crstype'} eq 'textbook') || 
+            (scalar(keys(%can_request)) == 1) && ($can_request{'textbook'})) {
             my %domconfig = &Apache::lonnet::get_dom('configuration',['requestcourses'],$dom);
             if ($action eq 'log') {
+                my $usetabs;
+                if ((scalar(keys(%can_request)) == 1) && ($can_request{'textbook'})) {
+                    $usetabs = 1;
+                } elsif ($env{'form.tabs'} eq 'on') {
+                    $usetabs = 1;
+                }
                 &Apache::lonhtmlcommon::add_breadcrumb({text=>'Course Request'});
                 my $crumb = &Apache::lonhtmlcommon::breadcrumbs('Course Requests','Course_Requests');
-                &print_request_logs($r,$dom,undef,undef,$crumb);
+                &print_request_logs($r,$dom,undef,undef,$crumb,$usetabs);
             } elsif ($action eq 'process') {
-                &process_textbook_request($r,$dom,$action,\%domdefs,\%domconfig);
+                if ($can_request{'textbook'}) {
+                    &process_textbook_request($r,$dom,$action,\%domdefs,\%domconfig,\%can_request);
+                } else {
+                    &textbook_request_disabled($r,$dom,\%can_request);
+                }
             } else {
-                &print_textbook_form($r,$dom,\@incdoms,\%domdefs,$domconfig{'requestcourses'});
+                if ($can_request{'textbook'}) {
+                    &print_textbook_form($r,$dom,\@incdoms,\%domdefs,$domconfig{'requestcourses'},\%can_request);
+                } else {
+                    &textbook_request_disabled($r,$dom,\%can_request);
+                }
             }
             return OK;
         }
@@ -195,7 +210,7 @@
 
     my @invalidcrosslist;
     my %trail = (
-                 crstype       => 'Request Action',
+                 crstype       => 'Pick Action',
                  codepick      => 'Category',
                  courseinfo    => 'Description',
                  enrollment    => 'Access Dates',
@@ -382,7 +397,7 @@
 }
 
 ENDJS
-            &print_request_logs($r,$dom,$jscript,$loaditems,$crumb);
+            &print_request_logs($r,$dom,$jscript,$loaditems,$crumb,\%can_request);
         }
     } else {
         &print_main_menu($r,\%can_request,\%states,$dom,$jscript,'',$crumb,\@incdoms);
@@ -1483,6 +1498,15 @@
         }
         $r->print(&print_review($dom,\@codetitles,\%cat_titles,\%cat_order,\@code_order,'','',\@disallowed,\%disallowmsg,$instcredits).
                   '<input type="hidden" name="cnum" value="'.$cnum.'" />');
+        my $fullname = &Apache::loncommon::plainname($env{'user.name'},
+                                                     $env{'user.domain'});
+        my $postprocess = &Apache::lonnet::auto_crsreq_update($dom,$cnum,$crstype,'review',$env{'user.name'},
+                                                              $env{'user.domain'},$fullname,$env{'form.cdescr'});
+        if (ref($postprocess) eq 'HASH') {
+            if ($postprocess->{'reviewweb'}) {
+                $r->print($postprocess->{'reviewweb'});
+            }
+        }
         if ($crstype eq 'community') {
             $navtxt{'next'} = &mt('Submit community request');
         } else {
@@ -2126,6 +2150,7 @@
             my $crstype = $history{'crstype'};
             my $disposition = $history{'disposition'};
             my $status = $history{'status'};
+            my $uniquecode = $history{'code'}; 
             if ($action eq 'view') {
                 next if ((exists($history{'status'})) && ($history{'status'} eq 'created'));
             } else {
@@ -2141,7 +2166,7 @@
                 $entry = $requestkey.':'.$crstype.':'.
                          &escape($history{'details'}{'cdescr'});
                 if ($action eq 'log') {
-                    $entry .= ':'.$lastupdate.':';
+                    $entry .= ':'.$uniquecode.':'.$lastupdate.':';
                     if ($statusinfo{$key} ne '') {
                         $entry .= $statusinfo{$key};
                     } elsif ($status ne '') {
@@ -2354,7 +2379,7 @@
 }
 
 sub print_request_logs {
-    my ($r,$dom,$jscript,$loaditems,$crumb) = @_;
+    my ($r,$dom,$jscript,$loaditems,$crumb,$usetabs) = @_;
     my $title;
     if ($env{'form.crstype'} eq 'community') {
         $title = 'Community Request Logs';
@@ -2364,6 +2389,9 @@
         $title = 'Course Request Logs';
     }
     $r->print(&header($title,$jscript,$loaditems).$crumb);
+    if ($usetabs) {
+        &startContentScreen($r,'textbooklogs');
+    }
     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".
@@ -2408,6 +2436,28 @@
     if (($curr{'crstype'} eq 'official') || ($curr{'crstype'} eq 'any')) {
         $tablehdr .= '<th>'.&mt('Institutional Code').'</th>';
     }
+    my $showuniquecode;
+    my %domconfig = &Apache::lonnet::get_dom('configuration',['requestcourses'],$dom);
+    if (($curr{'status'} eq 'any') || ($curr{'status'} eq 'created')) {
+        if (ref($domconfig{'requestcourses'}) eq 'HASH') {
+            if (ref($domconfig{'requestcourses'}{'uniquecode'}) eq 'HASH') {
+                if ($curr{'crstype'} eq 'any') {
+                    my @types = qw(official unofficial community textbook);
+                    foreach my $type (@types) {
+                        if ($domconfig{'requestcourses'}{'uniquecode'}{$type}) {
+                            $showuniquecode = 1;
+                            last;
+                        }
+                    }
+                } elsif ($domconfig{'requestcourses'}{'uniquecode'}{$curr{'crstype'}}) {
+                    $showuniquecode = 1;
+                }
+            }
+        }
+    }
+    if ($showuniquecode) {
+        $tablehdr .= '<th>'.&mt('Unique Code').'</th>';    
+    }
     if ($curr{'status'} eq 'any') {
         $tablehdr .= '<th>'.&mt('Status').'</th>';
     } elsif ($curr{'status'} eq 'created') {
@@ -2445,7 +2495,7 @@
             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 ($key,$crstype,$desc,$uniquecode,$timestamp,$status,$instcode) = split(':',$request);
                     my ($cdom,$cnum) = split('_',$key);
                     my $output = &Apache::loncommon::start_data_table_row().
      '<td>'.$count.'</td>'.
@@ -2471,6 +2521,13 @@
                         }
                         $output .= '<td>'.$showinstcode.'</td>';
                     }
+                    if ($showuniquecode) {
+                        if ($status eq 'created') {
+                            $output .= '<td>'.$uniquecode.'</td>';
+                        } else {
+                            $output .= '<td>'.&mt('Not applicable').'</td>';
+                        }    
+                    }
                     if ($curr{'status'} eq 'any') {
                         my $statusname = &mt('Unknown status');
                         if (ref($statusnames) eq 'HASH') {
@@ -2531,8 +2588,14 @@
                   &mt('There are no records to display').
                   '</p>');
     }
-    $r->print('</form>'.
-              &Apache::loncommon::end_page());
+    if ($usetabs) {
+        $r->print('<input type="hidden" name="tabs" value="on" />');
+    }
+    $r->print('</form>');
+    if ($usetabs) {
+        &endContentScreen($r);
+    }
+    $r->print(&Apache::loncommon::end_page());
     return;
 }
 
@@ -3274,16 +3337,17 @@
         $output = &mt('Invalid LON-CAPA course number for the new course')."\n"; 
         return $output;
     }
-
-    %domconfig = &Apache::lonnet::get_dom('configuration',['requestcourses'],$dom);
+    $crstype = $env{'form.crstype'};
+    my %domconfig = &Apache::lonnet::get_dom('configuration',['requestcourses'],$dom);
     if (ref($domconfig{'requestcourses'}) eq 'HASH') {
         if (ref($domconfig{'requestcourses'}{'notify'}) eq 'HASH') {
             $req_notifylist = $domconfig{'requestcourses'}{'notify'}{'approval'};
         }
-        $uniquecode = $domconfig{'requestcourses'}{'uniquecode'};
+        if (ref($domconfig{'requestcourses'}{'uniquecode'}) eq 'HASH') {
+            $uniquecode = $domconfig{'requestcourses'}{'uniquecode'}{$crstype};
+        }
     }
     $now = time;
-    $crstype = $env{'form.crstype'};
     my $ccrole = 'cc';
     if ($crstype eq 'community') {
         $ccrole = 'co';
@@ -3578,7 +3642,32 @@
         }
         $reqhash{'disposition'} = $disposition;
         $reqstatus = $disposition;
-        my ($modified,$queued);
+        my ($modified,$queued,$coursedesc,%customitems);
+        unless ($disposition eq 'rejected') {
+            if (ref($details) eq 'HASH') {
+                $coursedesc = $details->{'cdescr'};
+            }
+            my $fullname = &Apache::loncommon::plainname($env{'user.name'},
+                                                         $env{'user.domain'});
+            my $inprocess = &Apache::lonnet::auto_crsreq_update($dom,$cnum,$crstype,'process',$env{'user.name'},
+                                                                $env{'user.domain'},$fullname,$coursedesc);
+            if (ref($inprocess) eq 'HASH') {
+                if (ref($inprocess->{'formitems'}) eq 'HASH') {
+                    foreach my $key (keys(%{$inprocess->{'formitems'}})) {
+                        if ($inprocess->{'formitems'}->{$key} eq 'multiple') {
+                            if (exists($env{'form.'.$key})) {
+                                @{$customitems{$key}} = &Apache::loncommon::get_env_multiple($env{'form.'.$key});
+                            }
+                        } else {
+                            if (exists($env{'form.'.$key})) {
+                                $customitems{$key} = $env{'form.'.$key};
+                                $reqhash{'custom'}{$key} = $customitems{$key};
+                            }
+                        }
+                    }
+                }
+            }
+        }
         if ($disposition eq 'rejected') {
             if ($crstype eq 'community') {
                 $output = &mt('Your community request was rejected.');
@@ -3600,9 +3689,10 @@
             foreach my $role (@roles) {
                 $longroles{$role}=&Apache::lonnet::plaintext($role,$type);
             }
-            my $result = &Apache::loncoursequeueadmin::course_creation($dom,$cnum,
-                                   'autocreate',$details,\$logmsg,\$newusermsg,\$addresult,
-                                   \$enrollcount,\$response,\$keysmsg,\%domdefs,\%longroles,\$code);
+            my ($result,$postprocess) = &Apache::loncoursequeueadmin::course_creation($dom,$cnum,
+                                          'autocreate',$details,\$logmsg,\$newusermsg,\$addresult,
+                                          \$enrollcount,\$response,\$keysmsg,\%domdefs,\%longroles,
+                                          \$code,\%customitems);
             if ($result eq 'created') {
                 $disposition = 'created';
                 $reqstatus = 'created';
@@ -3613,9 +3703,13 @@
                 } else {
                     $output = '<p>'.&mt('Your course request has been processed and the course has been created.');
                 }
-                if ($code) {
+                if (($code) || ((ref($postprocess) eq 'HASH') && 
+                                (($postprocess->{'createdweb'}) || ($postprocess->{'createdmsg'})))) {
                     $output .= &notification_information($disposition,$env{'user.name'}.':'.$env{'user.domain'},
-                                                         $cnum,$now,$code);
+                                                         $cnum,$now,$code,$postprocess);
+                }
+                if ($code) {
+                    $reqhash{'code'} = $code;
                 }
                 $output .= '<br />'.$role_result.'</p>';
                 $creationresult = 'created';
@@ -3633,7 +3727,7 @@
             }
         } else {
             my $requestid = $cnum.'_'.$disposition;
-            my $request = { 
+            my $request = {
                             $requestid => {
                                             timestamp   => $now,
                                             crstype     => $crstype,
@@ -3689,6 +3783,18 @@
                 $output .= '<p>'.&mt('Your course request has been updated').'</p>';
             }
             $output .= &notification_information($disposition,$req_notifylist,$cnum,$now);
+            if ($disposition eq 'approval') {
+                my $fullname = &Apache::loncommon::plainname($env{'user.name'},
+                                                             $env{'user.domain'});
+                my $postprocess = 
+                    &Apache::lonnet::auto_crsreq_update($dom,$cnum,$crstype,'queued',$env{'user.name'},
+                                                        $env{'user.domain'},$fullname,$env{'form.cdescr'});
+                if ((ref($postprocess) eq 'HASH') && 
+                    ((ref($postprocess->{'queuedmsg'}) eq 'HASH') || ($postprocess->{'queuedweb'}))) { 
+                    my $recipient = $env{'user.name'}.':'.$env{'user.domain'};
+                    $output .= &notification_information($disposition,$recipient,$cnum,$now,undef,$postprocess);
+                }
+            }
         }
         if ($validationerror ne '') {
             $output .= '<p class="LC_warning">'.&mt('An error occurred validating your request with institutional data sources: [_1].',$validationerror).'</p>';
@@ -3840,7 +3946,7 @@
 }
 
 sub notification_information {
-    my ($disposition,$req_notifylist,$cnum,$now,$code) = @_;
+    my ($disposition,$req_notifylist,$cnum,$now,$code,$postprocess) = @_;
     my %emails = &Apache::loncommon::getemails();
     my $address;
     if (($emails{'permanentemail'} ne '') || ($emails{'notification'} ne '')) {
@@ -3858,33 +3964,82 @@
         }
         if ($req_notifylist) {
             my $fullname = &Apache::loncommon::plainname($env{'user.name'},
-                                                                     $env{'user.domain'});
+                                                         $env{'user.domain'});
             my $sender = $env{'user.name'}.':'.$env{'user.domain'};
             &Apache::loncoursequeueadmin::send_selfserve_notification($req_notifylist,"$fullname ($env{'user.name'}:$env{'user.domain'})",$cnum,$env{'form.cdescr'},$now,'coursereq',$sender);
         }
+        if (ref($postprocess) eq 'HASH') {
+            if (ref($postprocess->{'queuedmsg'}) eq 'ARRAY') {
+                if (scalar(@{$postprocess->{'queuedmsg'}}) > 0) {
+                    my $recipient = $env{'user.name'}.':'.$env{'user.domain'};
+                    my $sender = $recipient;
+                    my $addmsg = [];
+                    foreach my $item (@{$postprocess->{'queuedmsg'}}) {
+                        if (ref($item) eq 'HASH') {
+                            if ($item->{'mt'} ne '') {
+                                push(@{$addmsg},$item);
+                            }
+                        }
+                    }
+                    if (scalar(@{$addmsg}) > 0) {
+                        &Apache::loncoursequeueadmin::send_selfserve_notification($recipient,$addmsg,$cnum,
+                                                                                  $env{'form.cdescr'},$now,
+                                                                                  'queuedreq',$sender);
+                    }
+                }
+            }
+            if ($postprocess->{'queuedweb'}) {
+                $output .= $postprocess->{'queuedweb'};
+            }
+        }
     } elsif ($disposition eq 'pending') {
         $output .= '<div class="LC_info">'.
 &mt('Your request has been placed in a queue pending administrative action.').'<br />'.
 &mt("Usually this means that your institution's information systems do not list you among the instructional personnel for this course.").'<br />'.
 &mt('The list of instructional personnel for the course will be automatically checked daily, and once you are listed the request will be processed.').
                    '</div>';
-    } elsif (($disposition eq 'created') && ($code)) {
-        my $codemsg = [{
-                         mt   => 'Students can automatically select your course by entering this code: [_1]',
-                         args => [$code],
-                     }];
-        $output .= '<p>'.
-                   &mt('Students can automatically select your course by entering this code: [_1].','<b>'.$code.'</b>').
-                   '<br />'.
-                   &mt('A message has been sent to your LON-CAPA account with this information.');
-        if ($address ne '') {
-            $output.= '<br />'.&mt('And an e-mail has also been sent to: [_1] with this code.',$address);
-        }
-        $output .= '</p>';
-        my $sender = $env{'user.name'}.':'.$env{'user.domain'};
-        if ($code) {
-            &Apache::loncoursequeueadmin::send_selfserve_notification($req_notifylist,$codemsg,$cnum,$env{'form.cdescr'},
-                                                                      $now,'uniquecode',$sender);
+    } elsif ($disposition eq 'created') {
+        if (($code) || ((ref($postprocess) eq 'HASH') && 
+            ((ref($postprocess->{'createdmsg'}) eq 'ARRAY') || ($postprocess->{'createdweb'})))) {
+            my $addmsg = [];
+            my $recipient = $env{'user.name'}.':'.$env{'user.domain'};
+            my $sender = $recipient;
+            if ($code) {
+                push(@{$addmsg},{
+                                  mt   => 'Students can automatically select your course by entering this code: [_1]',
+                                  args => [$code],
+                                });
+                $output .= '<p>'.
+                           &mt('Students can automatically select your course by entering this code: [_1].','<b>'.$code.'</b>').
+                           '<br />'.
+                           &mt('A message has been sent to your LON-CAPA account with this information.');
+                if ($address ne '') {
+                    $output.= '<br />'.&mt('An e-mail has also been sent to: [_1] with this code.',$address);
+                }
+                $output .= '</p>';
+            }
+            if (ref($postprocess) eq 'HASH') {
+                if (ref($postprocess->{'createdmsg'}) eq 'ARRAY') {
+                    foreach my $item (@{$postprocess->{'createdmsg'}}) {
+                        if (ref($item) eq 'HASH') {
+                            if ($item->{'mt'} ne '') {  
+                                push(@{$addmsg},$item);
+                            }
+                        }
+                    }
+                }
+                if ($postprocess->{'createdweb'}) {
+                    $output .= $postprocess->{'createdweb'}
+                }
+            }
+            if (scalar(@{$addmsg}) > 0) {
+                my $type = 'createdreq';
+                if ($code) {
+                    $type = 'uniquecode';
+                }
+                &Apache::loncoursequeueadmin::send_selfserve_notification($recipient,$addmsg,$cnum,$env{'form.cdescr'},
+                                                                          $now,$type,$sender);
+            }
         }
     } else {
         $output .= '<div class="LC_warning">'.
@@ -4110,7 +4265,7 @@
 }
 
 sub print_textbook_form {
-    my ($r,$dom,$incdoms,$domdefs,$settings) = @_;
+    my ($r,$dom,$incdoms,$domdefs,$settings,$can_request) = @_;
     my ($bookshash,%ordered);
     my $crstype = 'textbook';
 #
@@ -4170,9 +4325,18 @@
     $loaditems{'onload'} = 'javascript:uncheckAllRadio();';
     $r->print(&header('Course Request',$jscript,\%loaditems));
 
+    if (ref($can_request) eq 'HASH') {
+        unless ((scalar(keys(%{$can_request})) == 1) && ($can_request->{'textbook'})) {
+            &Apache::lonhtmlcommon::add_breadcrumb(
+                { href => '/adm/requestcourse',
+                  text => 'Pick action',
+                });
+        }
+    }
     &Apache::lonhtmlcommon::add_breadcrumb({text=>'Course Request'});
     $r->print(&Apache::lonhtmlcommon::breadcrumbs('Course Requests','Course_Requests'));
 
+    &startContentScreen($r,'textbookrequests');
 #
 # Show domain selector form, if required.
 #
@@ -4369,21 +4533,37 @@
               ' '.&mt($accesstitles{'end'}).$endform.'<br /></div>');
 
 #
+# Display any custom fields for this course type
+#
+    my $fullname = &Apache::loncommon::plainname($env{'user.name'},
+                                                 $env{'user.domain'});
+    my $postprocess = &Apache::lonnet::auto_crsreq_update($dom,undef,$crstype,'review',
+                                                          $env{'user.name'},
+                                                          $env{'user.domain'},$fullname);
+    if (ref($postprocess) eq 'HASH') {
+        if ($postprocess->{'reviewweb'}) {
+            $r->print($postprocess->{'reviewweb'});
+        }
+    }
+
+#
 # Submit button
 #
-    $r->print('<input type="hidden" name="action" value="process" />'.
+    $r->print('<input type="hidden" name="crstype" value="textbook" />'.
+              '<input type="hidden" name="action" value="process" />'.
               '<input type="submit" value="'.&mt('Create course').'" />');
 
 #
 # End request form
 #
-    $r->print('</form>'.
-              &Apache::loncommon::end_page());
+    $r->print('</form>');
+    &endContentScreen($r).
+    $r->print(&Apache::loncommon::end_page());
     return;
 }
 
 sub process_textbook_request {
-    my ($r,$dom,$action,$domdefs,$domconfig) = @_;
+    my ($r,$dom,$action,$domdefs,$domconfig,$can_request) = @_;
     my ($uniquecode,$req_notifylist);
     my $crstype = 'textbook';
     if (ref($domconfig) eq 'HASH') {
@@ -4425,6 +4605,14 @@
     }
     $r->print(&header('Course Creation'));
 
+    if (ref($can_request) eq 'HASH') {
+        unless ((scalar(keys(%{$can_request})) == 1) && ($can_request->{'textbook'})) {
+            &Apache::lonhtmlcommon::add_breadcrumb(
+                { href => '/adm/requestcourse',
+                  text => 'Pick action',
+                });
+        }
+    }
     &Apache::lonhtmlcommon::add_breadcrumb(
                                            { href => '/adm/requestcourse',
                                              text => "Create Course",
@@ -4432,6 +4620,7 @@
                                           );
     &Apache::lonhtmlcommon::add_breadcrumb({text=>'Request Processed'});
     $r->print(&Apache::lonhtmlcommon::breadcrumbs('Course Requests','Course_Requests'));
+    &startContentScreen($r,'textbookrequests');
 
     my $details = {
                     owner          => $env{'user.name'},
@@ -4459,6 +4648,7 @@
     } elsif ($result eq 'created') {
         $r->print('<p><a href="/adm/requestcourse">'.&mt('Create another course').'</a></p>');
     }
+    &endContentScreen($r);
     $r->print(&Apache::loncommon::end_page());
 }
 
@@ -4600,6 +4790,20 @@
 ENDSCRIPT
 
 }
+
+sub startContentScreen {
+    my ($r,$mode)=@_;
+    $r->print("\n".'<ul class="LC_TabContentBigger" id="textbookreq">'."\n");
+    $r->print('<li'.(($mode eq 'textbookrequests')?' class="active"':'').'><a href="/adm/requestcourse"><b>       '.&mt('Request a Course').'       </b></a></li>'."\n");
+    $r->print('<li'.(($mode eq 'textbooklogs')?' class="active"':'').'><a href="/adm/requestcourse?action=log&crstype=textbook&tabs=on"><b>     '.&mt('Course Request History').'     </b></a></li>'."\n");
+    $r->print("\n".'</ul>'."\n");
+    $r->print('<div class="LC_Box" style="clear:both;margin:0;"><div id="mainbox" style="margin:0 0;padding:0 0;"><div class="LC_ContentBox" id="maincontentbox" style="display: block;">');
+}
+
+sub endContentScreen {
+   my ($r)=@_;
+   $r->print('</div></div></div>');
+}
    
 1;
 
Index: loncom/interface/loncoursequeueadmin.pm
diff -u loncom/interface/loncoursequeueadmin.pm:1.40 loncom/interface/loncoursequeueadmin.pm:1.41
--- loncom/interface/loncoursequeueadmin.pm:1.40	Wed Dec 25 20:43:46 2013
+++ loncom/interface/loncoursequeueadmin.pm	Fri Jan  3 18:39:51 2014
@@ -1,7 +1,7 @@
 # The LearningOnline Network
 # Utilities to administer domain course requests and course self-enroll requests
 #
-# $Id: loncoursequeueadmin.pm,v 1.40 2013/12/25 20:43:46 raeburn Exp $
+# $Id: loncoursequeueadmin.pm,v 1.41 2014/01/03 18:39:51 raeburn Exp $
 #
 # Copyright Michigan State University Board of Trustees
 #
@@ -213,7 +213,6 @@
                       mt =>'[_1]As Domain Coordinator, use: [_2]Main Menu -> Create users or modify the roles and privileges of users -> Authoring space reqests[_3]to display a list of pending requests, which you can either approve or reject.',
                       args => ["\n","\n\n  ","\n\n"],
                      });
-
     } elsif ($context eq 'requestauthor') {
         $rawsubj = 'Authoring space request';
         $msgtxt = 'Your request for an authoring space requested on [_1]has been reviewed by a Domain Coordinator.';
@@ -229,6 +228,16 @@
         if (ref($textstr) eq 'ARRAY') {
             push(@rawmsg,@{$textstr});
         }
+    } elsif ($context eq 'queuedcrsreq') {
+        $rawsubj = 'Course Request Queued';
+        if (ref($textstr) eq 'ARRAY') {
+            push(@rawmsg,@{$textstr});
+        }
+    } elsif ($context eq 'createdcrsreq') {
+        $rawsubj = 'Course Creation Information';
+        if (ref($textstr) eq 'ARRAY') {
+            push(@rawmsg,@{$textstr});
+        }
     }
     my @to_notify = split(/,/,$notifylist);
     my $numsent = 0;
@@ -789,10 +798,20 @@
                                                      $ownerdom,$ownername);
                         if ((ref($history{'details'}) eq 'HASH') && 
                             ($history{'disposition'} eq $queue)) {
-                            my ($logmsg,$newusermsg,$addresult,$enrollcount,$response,$keysmsg,$code);
-                            my $result = &course_creation($cdom,$cnum,$context,$history{'details'},\$logmsg,
-                                                      \$newusermsg,\$addresult,\$enrollcount,
-                                                      \$response,\$keysmsg,\%domdefs,$longroles,\$code);
+                            my ($logmsg,$newusermsg,$addresult,$enrollcount,$response,$keysmsg,$code,%customitems);
+                            my $fullname = '';
+                            my $inprocess = &Apache::lonnet::auto_crsreq_update($cdom,$cnum,$crstype,'process',$ownername,
+                                                                                $ownerdom,$fullname,$coursedesc);
+                            if (ref($inprocess) eq 'HASH') {
+                                foreach my $key (keys(%{$inprocess})) {
+                                    if (exists($history{'details'}{$key})) { 
+                                        $customitems{$key} = $history{'details'}{$key};
+                                    }
+                                }
+                            }
+                            my ($result,$postprocess) = &course_creation($cdom,$cnum,$context,$history{'details'},\$logmsg,
+                                                        \$newusermsg,\$addresult,\$enrollcount,
+                                                        \$response,\$keysmsg,\%domdefs,$longroles,\$code,\%customitems);
                             if ($result eq 'created') {
                                 if ($crstype eq 'community') {
                                     $approvedmsg = $approvalmsg{'community'};
@@ -812,6 +831,17 @@
                                             });
                                         $codes{$cnum} = $code;
                                     }
+                                    if (ref($postprocess) eq 'HASH') {
+                                        if (ref($postprocess->{'createdmsg'}) eq 'ARRAY') {
+                                            foreach my $item (@{$postprocess->{'createdmsg'}}) {
+                                                if (ref($item) eq 'HASH') {
+                                                    if ($item->{'mt'} ne '') {
+                                                        push(@{$approvedmsg},$item);
+                                                    }
+                                                }
+                                            }
+                                        }
+                                    }
                                 }
                                 push(@completed,$cnum);
                                 
@@ -1325,13 +1355,14 @@
 
 sub course_creation {
     my ($dom,$cnum,$context,$details,$logmsg,$newusermsg,$addresult,$enrollcount,$output,
-        $keysmsg,$domdefs,$longroles,$coderef) =  @_;
+        $keysmsg,$domdefs,$longroles,$coderef,$customhash) =  @_;
     unless ((ref($details) eq 'HASH') && (ref($domdefs) eq 'HASH') && 
             (ref($longroles) eq 'HASH')) {
         return 'error: Invalid request';
     }
     my ($result,$ownername,$ownerdom);
     my $crstype = $details->{'crstype'};
+    my $coursedesc = $details->{'cdescr'};
     my %domconfig = &Apache::lonnet::get_dom('configuration',['requestauthor'],$dom);
     if (ref($domconfig{'requestcourses'}) eq 'HASH') {
         if (ref($domconfig{'requestcourses'}{'uniquecode'}) eq 'HASH') {
@@ -1347,6 +1378,7 @@
         $ownername = $env{'user.name'};
         $ownerdom  = $env{'user.domain'};
     }
+    my $fullname = &Apache::loncommon::plainname($ownername,$ownerdom);
     my $owneremail;
     my %emails = &Apache::loncommon::getemails($ownername,$ownerdom);
     foreach my $email ('permanentemail','critnotification','notification') {
@@ -1357,12 +1389,19 @@
     my $cid = &LONCAPA::batchcreatecourse::build_course($dom,$cnum,'requestcourses',
                   \%reqdetails,$longroles,$logmsg,$newusermsg,$addresult,
                   $enrollcount,$output,$keysmsg,$ownerdom,$ownername,$cnum,$crstype,$coderef);
+    my $postprocess;
     if ($cid eq "/$dom/$cnum") {
         $result = 'created';
+        my $code;
+        if (ref($coderef)) {
+            $code = $$coderef;
+        }
+        $postprocess = &Apache::lonnet::auto_crsreq_update($dom,$cnum,$crstype,$result,$ownername,
+                                                           $ownerdom,$fullname,$coursedesc,$code,$customhash);
     } else {
         $result = 'error: '.$cid;
     }
-    return $result;
+    return ($result,$postprocess);
 }
 
 sub build_batchcreatehash {
@@ -1388,6 +1427,12 @@
         if ($details->{'crstype'} eq 'community') {
             $batchhash{'crstype'} = 'Community';
         } else {
+            if ($details->{'crstype'} eq 'textbook') {
+                if ($details->{'clonecrs'} && $details->{'clonedom'}) {
+                    my %clonedfrom = &Apache::lonnet::coursedescription($details->{'clonedom'}.'_'.$details->{'clonecrs'});
+                    $batchhash{'textbook'} = $clonedfrom{'description'};
+                }
+            }
             $batchhash{'crstype'} = 'Course';
         }
         my ($owner_firstname,$owner_lastname);
@@ -1725,7 +1770,20 @@
                 $reqstatus = $disposition;
                 if ($disposition eq 'process') {
                     my ($logmsg,$newusermsg,$addresult,$enrollcount,$response,$keysmsg,$code);
-                    my $result = &course_creation($dom,$cnum,'domain',$history{'details'},\$logmsg,\$newusermsg,\$addresult,\$enrollcount,\$response,\$keysmsg,\%domdefs,\%longroles,\$code);
+                    my %customitems;
+                    my $fullname = &Apache::loncommon::plainname($ownername,$ownerdom);
+                    my $inprocess = &Apache::lonnet::auto_crsreq_update($dom,$cnum,$crstype,'process',$ownername,
+                                                                        $ownerdom,$fullname,$cdescr);
+                    if (ref($inprocess) eq 'HASH') {
+                        foreach my $key (keys(%{$inprocess})) {
+                            if (exists($history{'details'}{$key})) {
+                                $customitems{$key} = $history{'details'}{$key};
+                            }
+                        }
+                    }
+                    my ($result,$postprocess) = 
+                        &course_creation($dom,$cnum,'domain',$history{'details'},\$logmsg,\$newusermsg,\$addresult,
+                                         \$enrollcount,\$response,\$keysmsg,\%domdefs,\%longroles,\$code,\%customitems);
                     if ($result eq 'created') {
                         $disposition = 'created';
                         $reqstatus = 'created';
@@ -1749,6 +1807,17 @@
                                     mt => 'If currently logged-in to LON-CAPA, log-out and log-in again to select your new course role.'
                                  }];
                             my $sender = $dcname.':'.$dcdom;
+                            if (ref($postprocess) eq 'HASH') {
+                                if (ref($postprocess->{'createdmsg'}) eq 'ARRAY') {
+                                    foreach my $item (@{$postprocess->{'createdmsg'}}) {
+                                        if (ref($item) eq 'HASH') {
+                                             if ($item->{'mt'} ne '') {
+                                                 push(@{$approvedmsg},$item);
+                                             }
+                                        }
+                                    }
+                                }
+                            }
                             &send_selfserve_notification($owner,$approvedmsg,
                                                          $cid,$cdescr,$now,
                                                          $beneficiary,$sender,
Index: loncom/enrollment/localenroll.pm
diff -u loncom/enrollment/localenroll.pm:1.44 loncom/enrollment/localenroll.pm:1.45
--- loncom/enrollment/localenroll.pm:1.44	Fri Mar  1 04:49:04 2013
+++ loncom/enrollment/localenroll.pm	Fri Jan  3 18:39:55 2014
@@ -1,6 +1,6 @@
 # functions to glue school database system into Lon-CAPA for 
 # automated enrollment
-# $Id: localenroll.pm,v 1.44 2013/03/01 04:49:04 raeburn Exp $
+# $Id: localenroll.pm,v 1.45 2014/01/03 18:39:55 raeburn Exp $
 #
 # Copyright Michigan State University Board of Trustees
 #
@@ -437,6 +437,39 @@
     return 'ok';
 }
 
+sub crsreq_updates {
+    my ($cdom,$cnum,$crstype,$action,$ownername,$ownerdomain,$fullname,$title,
+        $code,$incoming,$outgoing) = @_;
+    unless (ref($outgoing) eq 'HASH') {
+        return 'fail';
+    }
+    my %extrainfo;
+    if (ref($incoming) eq 'HASH') {
+        %extrainfo = %{$incoming};
+    }
+    if ($action eq 'review') {
+        $outgoing->{'reviewweb'} = '';
+    } elsif ($action eq 'process') {
+        $outgoing->{'formitems'} = {}; # key=>value, where key is form element name
+                                       #             and value is multiple, if there
+                                       #             are multiple form elements with
+                                       #             the same name.  
+    } elsif ($action eq 'created') {
+        $outgoing->{'createdweb'} = '';
+        $outgoing->{'createdmsg'} = [{
+                                     mt => '',
+                                     args => [],
+                                    }];
+    } elsif ($action eq 'queued') {
+        $outgoing->{'queuedmsg'} = [{ 
+                                     mt   => '', 
+                                     args => [],
+                                    }];
+        $outgoing->{'queuedweb'} = '';
+    }
+    return 'ok'
+}
+
 =pod
 
 =item create_password()


More information about the LON-CAPA-cvs mailing list