--- loncom/interface/lonrequestcourse.pm 2015/06/09 21:22:57 1.89
+++ loncom/interface/lonrequestcourse.pm 2015/06/14 00:02:43 1.90
@@ -1,7 +1,7 @@
# The LearningOnline Network
# Request a course
#
-# $Id: lonrequestcourse.pm,v 1.89 2015/06/09 21:22:57 damieng Exp $
+# $Id: lonrequestcourse.pm,v 1.90 2015/06/14 00:02:43 raeburn Exp $
#
# Copyright Michigan State University Board of Trustees
#
@@ -1574,8 +1574,8 @@ sub print_request_form {
\%cat_order,\@code_order);
}
my $lonhost = $r->dir_config('lonHostID');
- my ($storeresult,$result) = &print_request_outcome($r,$lonhost,$dom,\@codetitles,
- \@code_order,$instcredits);
+ my ($storeresult,$result,$customized) = &print_request_outcome($r,$lonhost,$dom,\@codetitles,
+ \@code_order,$instcredits);
$r->print($result);
if (($storeresult eq 'ok') || ($storeresult eq 'created')) {
if ($storeresult eq 'ok') {
@@ -1584,10 +1584,14 @@ sub print_request_form {
''.&mt('Make another request').'
');
}
if (&Apache::loncoursequeueadmin::author_prompt()) {
- &print_author_prompt($r,$env{'form.action'},$env{'form.cnum'},$env{'form.showdom'},
- $env{'form.crstype'},$storeresult);
+ unless ($customized) {
+ &print_author_prompt($r,$env{'form.action'},$env{'form.cnum'},$env{'form.showdom'},
+ $env{'form.crstype'},$storeresult);
+ }
} elsif ($storeresult eq 'created') {
- $r->print(''.&mt('Make another request').'
');
+ unless ($customized) {
+ $r->print(''.&mt('Make another request').'
');
+ }
}
}
} elsif ($state eq 'reqauthor') {
@@ -3636,15 +3640,15 @@ sub print_request_outcome {
accessend => $accessend,
personnel => \%personnel,
};
- my ($result,$output) = &process_request($r,$lonhost,$dom,$cnum,$crstype,$now,$details,$instcode,
- $req_notifylist,\@instsections,\%domconfig);
- return ($result,$output);
+ my ($result,$output,$customized) = &process_request($r,$lonhost,$dom,$cnum,$crstype,$now,$details,
+ $instcode,$req_notifylist,\@instsections,\%domconfig);
+ return ($result,$output,$customized);
}
sub process_request {
my ($r,$lonhost,$dom,$cnum,$crstype,$now,$details,$instcode,$req_notifylist,$instsections,
$domconfig) = @_;
- my (@inststatuses,$storeresult,$creationresult,$output);
+ my (@inststatuses,$storeresult,$creationresult,$output,$customized);
my $val =
&Apache::loncoursequeueadmin::get_processtype('course',$env{'user.name'},
$env{'user.domain'},$env{'user.adv'},
@@ -3663,7 +3667,7 @@ sub process_request {
}
$storeresult = 'notpermitted';
} else {
- my ($disposition,$message,$reqstatus,$coursedesc);
+ my ($disposition,$message,$reqstatus,$coursedesc,%customvalidation);
my %reqhash = (
reqtime => $now,
crstype => $crstype,
@@ -3683,10 +3687,10 @@ sub process_request {
$disposition = &check_autolimit($env{'user.name'},$env{'user.domain'},
$dom,$crstype,$limit,\$message);
} elsif ($val eq 'validate') {
- my ($inststatuslist,$validationchk,$validation,%custominfo);
+ my ($inststatuslist,$validationchk,$validation);
if (ref($details) eq 'HASH') {
if ($details->{'clonecrs'}) {
- $custominfo{'_LC_clonefrom'} = $details->{'clonedom'}.'_'.$details->{'clonecrs'};
+ $customvalidation{'_LC_clonefrom'} = $details->{'clonedom'}.'_'.$details->{'clonecrs'};
}
}
if (@inststatuses > 0) {
@@ -3698,27 +3702,18 @@ sub process_request {
$instseclist = join(',',@{$instsections});
}
}
+#
+# Retrieve any custom form information used for validation
+#
my $preprocess = &Apache::lonnet::auto_crsreq_update($dom,$cnum,$crstype,'prevalidate',$env{'user.name'},
$env{'user.domain'},$fullname,$coursedesc);
if (ref($preprocess) eq 'HASH') {
- if (ref($preprocess->{'formitems'}) eq 'HASH') {
- foreach my $key (keys(%{$preprocess->{'formitems'}})) {
- if ($preprocess->{'formitems'}->{$key} eq 'multiple') {
- if (exists($env{'form.'.$key})) {
- @{$custominfo{$key}} = &Apache::loncommon::get_env_multiple($env{'form.'.$key});
- }
- } else {
- if (exists($env{'form.'.$key})) {
- $custominfo{$key} = $env{'form.'.$key};
- }
- }
- }
- }
+ &custom_formitems($preprocess,\%customvalidation);
}
$validationchk =
&Apache::lonnet::auto_courserequest_validation($dom,
$env{'user.name'}.':'.$env{'user.domain'},$crstype,
- $inststatuslist,$instcode,$instseclist,\%custominfo);
+ $inststatuslist,$instcode,$instseclist,\%customvalidation);
if ($validationchk =~ /:/) {
($validation,$message) = split(':',$validationchk);
} else {
@@ -3738,21 +3733,15 @@ sub process_request {
my ($modified,$queued,$coursedesc,$token,%customitems);
unless ($disposition eq 'rejected') {
my $inprocess = &Apache::lonnet::auto_crsreq_update($dom,$cnum,$crstype,'process',$env{'user.name'},
- $env{'user.domain'},$fullname,$coursedesc);
+ $env{'user.domain'},$fullname,$coursedesc,undef,
+ undef,undef,\%customvalidation);
+#
+# Retrieve any custom form information submitted with review page and include in request details.
+#
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};
- }
- }
- }
+ &custom_formitems($inprocess,\%customitems);
+ foreach my $key (keys(%customitems)) {
+ $reqhash{'custom'}{$key} = $customitems{$key};
}
}
}
@@ -3786,10 +3775,24 @@ sub process_request {
$customitems{'_LC_clonefrom'} = $details->{'clonedom'}.'_'.$details->{'clonecrs'};
}
}
+ $customitems{'_LC_ownerfullname'} = &Apache::loncommon::plainname($env{'user.name'},$env{'user.domain'},'first');
+ my $owneremail;
+ my %emails = &Apache::loncommon::getemails();
+ foreach my $email ('permanentemail','critnotification','notification') {
+ $owneremail = $emails{$email};
+ last if ($owneremail ne '');
+ }
+ if ($owneremail ne '') {
+ $customitems{'_LC_owneremail'} = $owneremail;
+ }
+ $customitems{'_LC_coursedomainname'} = &Apache::lonnet::domain($dom,'description');
my ($result,$postprocess) = &Apache::loncoursequeueadmin::course_creation($dom,$cnum,
'autocreate',$details,\$logmsg,\$newusermsg,\$addresult,
\$enrollcount,\$response,\$keysmsg,\%domdefs,\%longroles,
\$code,\%customitems);
+ if (ref($postprocess) eq 'HASH') {
+ $customized = $postprocess->{'createdcustomized'};
+ }
if ($result eq 'created') {
$disposition = 'created';
$reqstatus = 'created';
@@ -3816,7 +3819,10 @@ sub process_request {
}
}
}
- $output .= '
'.$role_result.'';
+ unless ($customized) {
+ $output .= '
'.$role_result;
+ }
+ $output .= '';
$creationresult = 'created';
} else {
$output = '';
@@ -3921,6 +3927,7 @@ sub process_request {
if ((ref($postprocess) eq 'HASH') &&
((ref($postprocess->{'queuedmsg'}) eq 'HASH') || ($postprocess->{'queuedweb'}))) {
¬ification_information($disposition,undef,$dom,$cnum,$now,undef,$postprocess);
+ $customized = $postprocess->{'createdcustomized'};
}
} elsif ($disposition eq 'pending') {
my $pendingform;
@@ -3933,6 +3940,9 @@ sub process_request {
} else {
$output .= ¬ification_information($disposition,undef,$dom,$cnum,$now,undef,$postprocess);
}
+ if (ref($postprocess) eq 'HASH') {
+ $customized = $postprocess->{'createdcustomized'};
+ }
}
}
if ($validationerror ne '') {
@@ -3943,9 +3953,34 @@ sub process_request {
}
}
if ($creationresult ne '') {
- return ($creationresult,$output);
+ return ($creationresult,$output,$customized);
} else {
- return ($storeresult,$output);
+ return ($storeresult,$output,$customized);
+ }
+}
+
+sub custom_formitems {
+ my ($preprocess,$customhash) = @_;
+ return unless ((ref($preprocess) eq 'HASH') && (ref($customhash) eq 'HASH'));
+ if (ref($preprocess->{'formitems'}) eq 'HASH') {
+ foreach my $key (keys(%{$preprocess->{'formitems'}})) {
+ if ($preprocess->{'formitems'}->{$key} eq 'multiple') {
+ if (exists($env{'form.'.$key})) {
+ my @items = &Apache::loncommon::get_env_multiple($env{'form.'.$key});
+ foreach my $item (@items) {
+ $item =~ s/(`)/'/g;
+ $item =~ s/\$/\(\$\)/g;
+ push(@{$customhash->{$key}},$item);
+ }
+ }
+ } else {
+ if (exists($env{'form.'.$key})) {
+ $customhash->{$key} = $env{'form.'.$key};
+ $customhash->{$key} =~ s/(`)/'/g;
+ $customhash->{$key} =~ s/\$/\(\$\)/g;
+ }
+ }
+ }
}
}
@@ -4499,16 +4534,19 @@ sub print_textbook_form {
}
#
-# Retrieve information about courses owned by user, or in which user has an active or future
-# Course Coordinator role
+# Retrieve information about courses owned by user, or in which user has an active
+# Course Coordinator role
#
my $numcurrent;
my %cloneable = &Apache::lonnet::courseiddump($dom,'.',1,'.',$env{'user.name'}.':'.$env{'user.domain'},
- undef,undef,undef,'Course');
+ '.',undef,undef,'Course');
my %ccroles = &Apache::lonnet::get_my_roles($env{'user.name'},$env{'user.domain'},'userroles',
- ['active','future'],['cc']);
+ ['active'],['cc']);
+
+ my $cc_clone = '';
foreach my $role (keys(%ccroles)) {
my ($cnum,$cdom,$rest) = split(/:/,$role,3);
+ $cc_clone .= $cdom.':'.$cnum.'&';
unless (exists($cloneable{$cdom.'_'.$cnum})) {
my %courseinfo = &Apache::lonnet::coursedescription($cdom.'_'.$cnum,{'one_time' => 1});
$cloneable{$cdom.'_'.$cnum} = \%courseinfo;
@@ -4517,9 +4555,59 @@ sub print_textbook_form {
my $numcurrent = scalar(keys(%cloneable));
- my $jscript = &textbook_request_javascript(\%numprefab,$numcurrent);
+#
+# Retrieve information about courses from user's domain which user can clone, but which not owned
+# or cloneable based on Course Coordinator role.
+#
+ my ($numdomcourses,%domcloneable);
+ my %allcloneable = &Apache::lonnet::courseiddump($dom,'.',1,'.','.','.',undef,undef,'Course',
+ undef,undef,undef,undef,undef,
+ $env{'user.name'}.':'.$env{'user.domain'},
+ $cc_clone,1);
+ foreach my $cid (keys(%allcloneable)) {
+ unless (exists($cloneable{$cid})) {
+ $domcloneable{$cid} = $allcloneable{$cid};
+ }
+ }
+ $numdomcourses = scalar(keys(%domcloneable));
+
+ my $fullname = &Apache::loncommon::plainname($env{'user.name'},
+ $env{'user.domain'});
+
+#
+# Retrieve any custom form information prior to rendering page
+#
+
+ my $initprocess = &Apache::lonnet::auto_crsreq_update($dom,undef,$crstype,'initializereview',$env{'user.name'},
+ $env{'user.domain'},$fullname);
+ my %custominit;
+ if (ref($initprocess) eq 'HASH') {
+ &custom_formitems($initprocess,\%custominit);
+ }
+
+#
+# Retrieve any custom onload actions or javascript used for page before rendering
+#
+
+ my ($customonload,$customjs,$customvalidationjs);
+ my $inprocess = &Apache::lonnet::auto_crsreq_update($dom,undef,$crstype,'prereview',$env{'user.name'},
+ $env{'user.domain'},$fullname,undef,undef,
+ undef,undef,\%custominit);
+ if (ref($inprocess) eq 'HASH') {
+ $customonload = $inprocess->{'onload'};
+ $customjs = $inprocess->{'javascript'};
+ $customvalidationjs = $inprocess->{'validationjs'};
+ }
+
+ my $postprocess = &Apache::lonnet::auto_crsreq_update($dom,undef,$crstype,'review',
+ $env{'user.name'},
+ $env{'user.domain'},$fullname,undef,undef,
+ undef,undef,\%custominit);
+
+ my $jscript = &textbook_request_javascript(\%numprefab,$numcurrent,$numdomcourses,$customvalidationjs);
+ $jscript .= $customjs;
my %loaditems;
- $loaditems{'onload'} = 'javascript:uncheckAllRadio();';
+ $loaditems{'onload'} = 'javascript:uncheckAllRadio();'.$customonload;
$r->print(&header('Course Request',$jscript,\%loaditems));
if (ref($can_request) eq 'HASH') {
@@ -4564,7 +4652,7 @@ sub print_textbook_form {
#
# Content source selection, if more than one available
#
- if (keys(%cloneable) || keys(%ordered)) {
+ if (keys(%cloneable) || keys(%ordered) || keys(%domcloneable)) {
$r->print(''.
'
');
}
#
+# Table of other cloneable courses from user's domain (exclude own courses)
+#
+ if (keys(%domcloneable)) {
+ $r->print('');
+ }
+
+#
# End of content selector
#
- if (keys(%cloneable) || keys(%ordered)) {
+ if (keys(%cloneable) || keys(%domcloneable) || keys(%ordered)) {
$r->print('');
}
@@ -4759,11 +4801,6 @@ sub print_textbook_form {
#
# 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'});
@@ -4786,6 +4823,84 @@ sub print_textbook_form {
return;
}
+sub clone_selection_table {
+ my ($dom,$name,$cloneableref) = @_;
+ return unless ((ref($cloneableref) eq 'HASH') && (($name eq 'owned') || ($name eq 'colleague')));
+ my %allownernames;
+ my %sortbytitle;
+ my $output;
+ foreach my $cid (sort(keys(%{$cloneableref}))) {
+ if (ref($cloneableref->{$cid}) eq 'HASH') {
+ my $cdesc = $cloneableref->{$cid}{'description'};
+ $cdesc =~ s/`/'/g;
+ if ($cdesc ne '') {
+ push(@{$sortbytitle{$cdesc}},$cid);
+ }
+ }
+ }
+ foreach my $title (sort(keys(%sortbytitle))) {
+ if (ref($sortbytitle{$title}) eq 'ARRAY') {
+ foreach my $cid (sort(@{$sortbytitle{$title}})) {
+ my $cleantitle=&HTML::Entities::encode($title,'<>&"');
+ $cleantitle=~s/'/\\'/g;
+ $cleantitle =~ s/^\s+//;
+ my ($namestr,@owners,%ownernames);
+ my $singleowner = $cloneableref->{$cid}{'internal.courseowner'};
+ push(@owners,$singleowner);
+ if ($cloneableref->{$cid}{'co-owners'} ne '') {
+ foreach my $item (split(/,/,$cloneableref->{$cid}{'internal.co-owners'})) {
+ push(@owners,$item);
+ }
+ }
+ foreach my $owner (@owners) {
+ my ($ownername,$ownerdom);
+ if ($owner =~ /:/) {
+ ($ownername,$ownerdom) = split(/:/,$owner);
+ } else {
+ $ownername = $owner;
+ if ($owner ne '') {
+ $ownerdom = $dom;
+ }
+ }
+ if ($ownername ne '' && $ownerdom ne '') {
+ if (exists($allownernames{$ownername.':'.$ownerdom})) {
+ $ownernames{$ownername.':'.$ownerdom} = $allownernames{$ownername.':'.$ownerdom};
+ } else {
+ my %namehash=&Apache::loncommon::getnames($ownername,$ownerdom);
+ $ownernames{$ownername.':'.$ownerdom} = \%namehash;
+ $allownernames{$ownername.':'.$ownerdom} = $ownernames{$ownername.':'.$ownerdom};
+ }
+ }
+ }
+ my @lastnames;
+ foreach my $owner (keys(%ownernames)) {
+ if (ref($ownernames{$owner}) eq 'HASH') {
+ push(@lastnames,$ownernames{$owner}{'lastname'});
+ }
+ }
+ if (@lastnames) {
+ $namestr = join(', ',sort(@lastnames));
+ }
+ $output .= &Apache::loncommon::start_data_table_row().
+ ' | '.
+ ''.$namestr.' | '.
+ &Apache::loncommon::end_data_table_row();
+ }
+ }
+ }
+ if ($output) {
+ return &Apache::loncommon::start_data_table().
+ &Apache::loncommon::start_data_table_header_row().
+ ''.&mt('Title').' | '.
+ ''.&mt('Owner/co-owner(s)').' | '.
+ &Apache::loncommon::end_data_table_header_row().
+ $output.
+ &Apache::loncommon::end_data_table();
+ }
+ return;
+}
+
sub process_textbook_request {
my ($r,$dom,$action,$domdefs,$domconfig,$can_request) = @_;
my ($uniquecode,$req_notifylist);
@@ -4811,6 +4926,8 @@ sub process_textbook_request {
$clonefrom = $env{'form.template'};
} elsif ($reqtype eq 'existing') {
$clonefrom = $env{'form.owned'};
+ } elsif ($reqtype eq 'colleague') {
+ $clonefrom = $env{'form.colleague'};
}
my ($accessstart,$accessend) = &dates_from_form('accessstart','accessend');
if ($clonefrom) {
@@ -4872,28 +4989,33 @@ sub process_textbook_request {
}
my $lonhost = $r->dir_config('lonHostID');
$r->rflush();
- my ($result,$output) = &process_request($r,$lonhost,$dom,$cnum,$crstype,$now,$details,'',
- $req_notifylist,[],$domconfig);
+ my ($result,$output,$customized) = &process_request($r,$lonhost,$dom,$cnum,$crstype,$now,$details,
+ '',$req_notifylist,[],$domconfig);
$r->print($output);
if (&Apache::loncoursequeueadmin::author_prompt()) {
- &print_author_prompt($r,$action,$cnum,$dom,$crstype,$result);
+ unless ($customized) {
+ &print_author_prompt($r,$action,$cnum,$dom,$crstype,$result);
+ }
} elsif ($result eq 'created') {
- $r->print(''.&mt('Create another course').'
');
+ unless ($customized) {
+ $r->print(''.&mt('Create another course').'
');
+ }
}
&endContentScreen($r);
$r->print(&Apache::loncommon::end_page());
}
sub textbook_request_javascript {
- my ($numprefab,$numcurrent) = @_;
+ my ($numprefab,$numcurrent,$numcolleague,$customvalidationjs) = @_;
return unless (ref($numprefab) eq 'HASH');
- return if (!$numprefab->{'textbooks'} && !$numprefab->{'templates'} && !$numcurrent);
+ return if (!$numprefab->{'textbooks'} && !$numprefab->{'templates'} && !$numcurrent && !$numcolleague);
my %js_lt = &Apache::lonlocal::texthash(
- choose => 'Please select a content option.',
- textbook => 'Please select a textbook, or choose a different option.',
- template => 'Please select a template, or choose a different option.',
- existing => 'Please select one of your existing courses to copy, or choose a different option.',
- title => 'Please enter a course title.',
+ choose => 'Please select a content option.',
+ textbook => 'Please select a textbook, or choose a different option.',
+ template => 'Please select a template, or choose a different option.',
+ existing => 'Please select one of your existing courses to copy, or choose a different option.',
+ colleague => "Please select a colleague's course to copy, or choose a different option.",
+ title => 'Please enter a course title.',
);
&js_escape(\%js_lt);
return <<"ENDSCRIPT";
@@ -4902,7 +5024,7 @@ function cloneChoice() {
var radioLength = document.requestcourse.cloning.length;
if (radioLength == undefined) {
var val = document.requestcourse.cloning.value;
- if ((val == 'textbook') || (val == 'template') || (val == 'existing')) {
+ if ((val == 'textbook') || (val == 'template') || (val == 'existing') || (val == 'colleague')) {
var elem = document.getElementById('show'+val);
if (document.requestcourse.cloning.checked) {
elem.style.display = 'block';
@@ -4914,7 +5036,7 @@ function cloneChoice() {
} else {
for (var i=0; i{'textbooks'};
var numtemplate = $numprefab->{'templates'};
var numcurrent = $numcurrent;
+ var numcolleague = $numcolleague;
if (numbook > 0) {
uncheckRadio('textbook');
}
@@ -4964,6 +5090,9 @@ function uncheckAllRadio() {
if (numcurrent > 0) {
uncheckRadio('existing');
}
+ if (numcolleague > 0) {
+ uncheckRadio('colleague');
+ }
return;
}
@@ -4991,7 +5120,7 @@ function validTextbookReq() {
}
}
var group;
- if ((cloneChoice == 'textbook') || (cloneChoice == 'template') || (cloneChoice == 'existing')) {
+ if ((cloneChoice == 'textbook') || (cloneChoice == 'template') || (cloneChoice == 'existing') || (cloneChoice == 'colleague')) {
var group;
if (cloneChoice == 'textbook') {
group = document.getElementsByName('book');
@@ -4999,7 +5128,11 @@ function validTextbookReq() {
if (cloneChoice == 'template') {
group = document.getElementsByName('template');
} else {
- group = document.getElementsByName('owned');
+ if (cloneChoice == 'existing') {
+ group = document.getElementsByName('owned');
+ } else {
+ group = document.getElementsByName('colleague');
+ }
}
}
var groupLength = group.length;
@@ -5023,7 +5156,11 @@ function validTextbookReq() {
if (cloneChoice == 'template') {
alert("$js_lt{'template'}");
} else {
- alert("$js_lt{'existing'}");
+ if (cloneChoice == 'existing') {
+ alert("$js_lt{'existing'}");
+ } else {
+ alert("js_$lt{'colleague'}");
+ }
}
}
return false;
@@ -5034,6 +5171,7 @@ function validTextbookReq() {
alert("$js_lt{'title'}");
return false;
}
+ $customvalidationjs
return true;
}