--- loncom/interface/loncoursequeueadmin.pm 2013/12/25 20:43:46 1.40
+++ loncom/interface/loncoursequeueadmin.pm 2014/03/03 17:11:41 1.44
@@ -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.44 2014/03/03 17:11:41 raeburn Exp $
#
# Copyright Michigan State University Board of Trustees
#
@@ -116,7 +116,7 @@ sub send_selfserve_notification {
push(@rawmsg,@{$textstr});
}
} elsif ($context eq 'authormanagers') {
- $rawsubj = 'Authoring space requests reviewed';
+ $rawsubj = 'Authoring Space requests reviewed';
push(@rawmsg,{
mt => 'Authoring requests in the following domain: "[_1]" have been reviewed.',
args => ["\n$contextdesc"],
@@ -124,6 +124,15 @@ sub send_selfserve_notification {
if (ref($textstr) eq 'ARRAY') {
push(@rawmsg,@{$textstr});
}
+ } elsif ($context eq 'usernamemanagers') {
+ $rawsubj = 'LON-CAPA account requests reviewed';
+ push(@rawmsg,{
+ mt => 'Account requests in the following domain: "[_1]" have been reviewed.',
+ args => ["\n$contextdesc"],
+ });
+ if (ref($textstr) eq 'ARRAY') {
+ push(@rawmsg,@{$textstr});
+ }
} elsif ($context eq 'enroller') {
$rawsubj = 'Enrollment request';
if ($crstype eq 'community') {
@@ -203,20 +212,41 @@ sub send_selfserve_notification {
args => [" \n\n","\n"],
});
} elsif ($context eq 'authorreq') {
- $rawsubj = 'Authoring space request to review';
+ $rawsubj = 'Authoring Space request to review';
$msgtxt = 'Assignment of an author role in the [_1] domain[_2]was requested by [_3] on [_4].';
push(@rawmsg,{
mt => $msgtxt,
args => [$contextdesc,"\n",$textstr,$timestamp],
},
{
- 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.',
+ mt =>'[_1]As Domain Coordinator, use: [_2]Main Menu -> Create users or modify the roles and privileges of users -> Authoring Space requests[_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.';
+ $rawsubj = 'Authoring Space request';
+ $msgtxt = 'Your request for an Authoring Space requested on [_1]has been reviewed by a Domain Coordinator.';
+ push(@rawmsg,{
+ mt => $msgtxt,
+ args => [$timestamp."\n"],
+ });
+ if (ref($textstr) eq 'ARRAY') {
+ push(@rawmsg,@{$textstr});
+ }
+ } elsif ($context eq 'usernamereq') {
+ $rawsubj = 'LON-CAPA account request';
+ $msgtxt = 'Creation of a LON-CAPA account in the [_1] domain[_2]was requested by [_3] on [_4].';
+ push(@rawmsg,{
+ mt => $msgtxt,
+ args => [$contextdesc,"\n",$textstr,$timestamp],
+ },
+ {
+ mt =>'[_1]As Domain Coordinator, use: [_2]Main Menu -> Create users or modify the roles and privileges of users
+ -> LON-CAPA account requests[_3]to display a list of pending requests, which you can either approve or reject.',
+ args => ["\n","\n\n ","\n\n"],
+ });
+ } elsif ($context eq 'requestusername') {
+ $rawsubj = 'LON-CAPA account request';
+ $msgtxt = 'Your request for a LON-CAPA account requested on [_1]has been reviewed by a Domain Coordinator.';
push(@rawmsg,{
mt => $msgtxt,
args => [$timestamp."\n"],
@@ -229,6 +259,16 @@ sub send_selfserve_notification {
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;
@@ -246,9 +286,14 @@ sub send_selfserve_notification {
my %reciphash = (
cc => $msgcc,
);
- my ($uname,$udom);
+ my ($uname,$udom,$need_temp_env);
if ($sender =~ /:/) {
($uname,$udom) = split(/:/,$sender);
+ if ($context eq 'usernamereq') {
+ unless ($env{'user.name'} && $env{'user.domain'}) {
+ $need_temp_env = 1;
+ }
+ }
} elsif ($context eq 'course') {
$uname = $sender;
my %courseinfo = &Apache::lonnet::coursedescription($cid);
@@ -265,9 +310,14 @@ sub send_selfserve_notification {
$message .= &Apache::lonlocal::mt_user($sender_lh,$item->{mt},@{$item->{args}})."\n";
}
}
- &Apache::lonmsg::process_sent_mail($subject,'',$numsent,$stamp,$uname,$udom,$msgcount,$cid,$$,$message,\@recusers,\@recudoms,undef,undef,undef,undef,$senderuname,$senderudom);
+ &Apache::lonmsg::process_sent_mail($subject,'',$numsent,$stamp,$uname,$udom,$msgcount,$cid,$$,$message,
+ \@recusers,\@recudoms,undef,undef,undef,undef,$senderuname,$senderudom);
my ($recipid,$recipstatus) = &Apache::lonmsg::store_recipients($subject,$uname,$udom,\%reciphash);
my $status;
+ if ($need_temp_env) {
+ $env{'user.name'} = $uname;
+ $env{'user.domain'} = $udom;
+ }
foreach my $recip (sort(keys(%{$msgcc}))) {
my ($ccname,$ccdom) = split(/:/,$recip);
my $recip_lh = &Apache::loncommon::user_lang($ccname,$ccdom,$cid);
@@ -300,10 +350,22 @@ sub send_selfserve_notification {
if ($rejectedlist) {
$message .= "\n\n".&Apache::lonlocal::mt_user($sender_lh,'Rejected author role requests:')."\n".$rejectedlist;
}
+ } elsif ($context eq 'usernamemanagers') {
+ if ($approvedlist) {
+ $message .= "\n\n".&Apache::lonlocal::mt_user($sender_lh,'Approved LON-CAPA account requests:')."\n".$approvedlist;
+ }
+ if ($rejectedlist) {
+ $message .= "\n\n".&Apache::lonlocal::mt_user($sender_lh,'Rejected LON-CAPA account requests:')."\n".$rejectedlist;
+ }
}
- $status .= &Apache::lonmsg::user_normal_msg($ccname,$ccdom,$subject,$message,undef,undef,undef,1,\%sentmessage,undef,undef,undef,1,$recipid).',';
+ $status .= &Apache::lonmsg::user_normal_msg($ccname,$ccdom,$subject,$message,undef,undef,undef,1,
+ \%sentmessage,undef,undef,undef,1,$recipid).',';
}
$status =~ s/,$//;
+ if ($need_temp_env) {
+ undef($env{'user.name'});
+ undef($env{'user.domain'});
+ }
return ($recipstatus,$status);
}
@@ -320,6 +382,11 @@ sub display_queued_requests {
$namespace = 'requestauthorqueue';
%requesthash = &Apache::lonnet::dump_dom($namespace,$dom);
$nextelement = '';
+ } elsif ($context eq 'requestusername') {
+ $formaction = '/adm/createuser';
+ $namespace = 'usernamequeue';
+ %requesthash = &Apache::lonnet::dump_dom($namespace,$dom);
+ $nextelement = '';
} else {
$formaction = '/adm/createcourse';
$namespace = 'courserequestqueue';
@@ -345,6 +412,9 @@ sub display_queued_requests {
} elsif ($context eq 'requestauthor') {
$timestamp = $requesthash{$item};
($entry) = ($item =~ /^($match_username)_approval$/);
+ } elsif ($context eq 'requestusername') {
+ $timestamp = $requesthash{$item};
+ ($entry) = (&unescape($item) =~ /^($match_username)_approval$/);
} else {
$timestamp = $requesthash{$item}{'timestamp'};
if (ref($requesthash{$item}) eq 'HASH') {
@@ -375,7 +445,9 @@ sub display_queued_requests {
'
'.&mt('Requests are validated against institutional data to confirm that the requestor is an instructor of record.').' '.
&mt('Validation is attempted when the request is submitted.').' '.&mt('If unvalidated, the request will be held in a queue.').' '.&mt('Validation of pending requests is automatically repeated daily.').'
'.&mt('Requests for LON-CAPA accounts queued pending approval by a Domain Coordinator').'
';
} else {
$output .= '
'.&mt('Course/Community requests queued pending approval by a Domain Coordinator').'
';
}
@@ -388,7 +460,9 @@ sub display_queued_requests {
} elsif ($context eq 'pending') {
$output .= &mt('There are currently no requests for official courses awaiting validation.');
} elsif ($context eq 'requestauthor') {
- $output .= &mt('There are currently no requests for authoring space awaiting approval.');
+ $output .= &mt('There are currently no requests for Authoring Space awaiting approval.');
+ } elsif ($context eq 'requestusername') {
+ $output .= &mt('There are currently no requests for LON-CAPA accounts awaiting approval.');
} elsif ($context eq 'domain') {
$output .= &mt('There are currently no course or community requests awaiting approval.');
}
@@ -408,6 +482,10 @@ sub display_queued_requests {
$output .= &mt('There are currently no enrollment requests awaiting approval.');
} elsif ($context eq 'pending') {
$output .= &mt('There are currently no requests for official courses awaiting validation.');
+ } elsif ($context eq 'requestauthor') {
+ $output .= &mt('There are currently no requests for Authoring Space awaiting approval.');
+ } elsif ($context eq 'requestusername') {
+ $output .= &mt('There are currently no requests for LON-CAPA accounts awaiting approval.');
} else {
$output .= &mt('There are currently no course or community requests awaiting approval.');
}
@@ -431,6 +509,9 @@ sub build_queue_display {
'
'.&mt("For the following requests an error occurred when removing the request from the queue:").'
';
+ foreach my $item (@warn_dels) {
+ my ($escuname) = split(/_/,$item);
+ $output .= '
'.&unescape($escuname).'
';
+ }
+ $output .= '
';
} else {
$output .= '
'.&mt("For the following course/community requests an error occurred when removing requests from the pending queue:").'
';
foreach my $cnum (@warn_dels) {
@@ -1325,13 +1596,14 @@ sub get_student_counts {
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 +1619,7 @@ sub course_creation {
$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 +1630,19 @@ sub course_creation {
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 +1668,12 @@ sub build_batchcreatehash {
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 +2011,20 @@ sub process_official_reqs {
$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 +2048,17 @@ sub process_official_reqs {
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,
@@ -1861,13 +2171,13 @@ sub process_reqauthor {
my ($dispositionref,$updateref) = @_;
if (&is_active_author()) {
return ''.
- &mt('An authoring space has already been assigned to you.').' '.
+ &mt('An Authoring Space has already been assigned to you.').' '.
&mt('Please select the Author role from your [_1]roles page[_2].','',
'').'';
}
unless ($env{'environment.canrequest.author'}) {
return ''.
- &mt('You do not currently have rights to request an authoring space.').' '.
+ &mt('You do not currently have rights to request an Authoring Space.').' '.
&mt('Please contact the [_1]helpdesk[_2] for assistance.','',
'').'';
}
@@ -1875,7 +2185,7 @@ sub process_reqauthor {
if ($queued =~ /^approval:(\d+)$/) {
my $timestamp = $1;
return ''.
- &mt('A request for authoring space submitted on [_1] is awaiting approval',
+ &mt('A request for Authoring Space submitted on [_1] is awaiting approval',
&Apache::lonlocal::locallocaltime($timestamp)).
'';
} elsif ($queued =~ /^approved:(\d+)$/) {
@@ -1884,7 +2194,7 @@ sub process_reqauthor {
['active'],['au'],[$env{'user.domain'}]);
if (keys(%roleshash) > 0) {
return ''.
- &mt('A request for authoring space submitted on [_1] has been approved.',
+ &mt('A request for Authoring Space submitted on [_1] has been approved.',
&Apache::lonlocal::locallocaltime($timestamp)).
'';
}
@@ -1901,7 +2211,7 @@ sub process_reqauthor {
if (&Apache::lonnet::assignrole($env{'user.domain'},$env{'user.name'},'/'.$env{'user.domain'}.'/',
'au',undef,$start,undef,undef,'requestauthor') eq 'ok') {
$output = ''.
- &mt('Access to authoring space has been activated').' ';
+ &mt('Access to Authoring Space has been activated').' ';
&Apache::lonroles::update_session_roles();
&Apache::lonnet::appenv({'user.update.time' => $now});
if (ref($updateref)) {
@@ -1912,7 +2222,7 @@ sub process_reqauthor {
}
} else {
$output = ''.
- &mt('An error occurred while activating your access to authoring space');
+ &mt('An error occurred while activating your access to Authoring Space');
}
} elsif ($val eq 'approval') {
my $domconfiguser = &Apache::lonnet::get_domainconfiguser($env{'user.domain'});
@@ -1943,12 +2253,12 @@ sub process_reqauthor {
my $userresult =
&Apache::lonnet::put('requestauthor',\%userrequest,$env{'user.domain'},$env{'user.name'});
$output = ''.
- &mt('Your request for authoring space has been submitted for approval.').
+ &mt('Your request for Authoring Space has been submitted for approval.').
'';
&Apache::lonnet::appenv({'environment.requestauthorqueued' => $val.':'.$now});
} else {
$output = ''.
- &mt('An error occurred saving your request for authoring space.').
+ &mt('An error occurred saving your request for Authoring Space.').
'';
}
}