--- loncom/interface/lonrequestcourse.pm 2015/07/14 00:11:48 1.92
+++ loncom/interface/lonrequestcourse.pm 2024/07/03 22:34:22 1.95.2.8
@@ -1,7 +1,7 @@
# The LearningOnline Network
# Request a course
#
-# $Id: lonrequestcourse.pm,v 1.92 2015/07/14 00:11:48 raeburn Exp $
+# $Id: lonrequestcourse.pm,v 1.95.2.8 2024/07/03 22:34:22 raeburn Exp $
#
# Copyright Michigan State University Board of Trustees
#
@@ -119,6 +119,10 @@ use Apache::loncoursequeueadmin;
use Apache::lonuserutils;
use LONCAPA qw(:DEFAULT :match);
+my $registered_flush;
+my $registered_instcats;
+my $modified_dom;
+
sub handler {
my ($r) = @_;
&Apache::loncommon::content_type($r,'text/html');
@@ -127,6 +131,10 @@ sub handler {
return OK;
}
+ $registered_flush = 0;
+ $registered_instcats = 0;
+ $modified_dom = '';
+
&Apache::loncommon::get_unprocessed_cgi($ENV{'QUERY_STRING'},
['action','showdom','cnum','state','crstype','queue','tabs']);
&Apache::lonhtmlcommon::clear_breadcrumbs();
@@ -311,8 +319,6 @@ sub handler {
$jscript = &Apache::lonhtmlcommon::set_form_elements($elementsref,\%stored);
if ($state eq 'courseinfo') {
$jscript .= &cloning_javascript();
- } elsif ($state eq 'process') {
- $jscript .= &processing_javascript();
}
}
}
@@ -424,17 +430,6 @@ function setCloneDisplay(courseForm) {
END
}
-sub processing_javascript {
- return <<"END";
-function hideProcessing() {
- if (document.getElementById('processing')) {
- document.getElementById('processing').style.display="none";
- }
-}
-
-END
-}
-
sub get_breadcrumbs {
my ($dom,$action,$state,$states,$trail) = @_;
my ($crumb,$newinstcode,$codechk,$checkedcode,$numtitles,$description);
@@ -712,9 +707,6 @@ sub onload_action {
if ($state eq 'courseinfo') {
$loaditems{'onload'} .= 'javascript:setCloneDisplay(document.requestcrs);';
}
- if ($state eq 'process') {
- $loaditems{'onload'} .= 'javascript:hideProcessing();';
- }
}
return \%loaditems;
}
@@ -2097,6 +2089,18 @@ sub print_personnel_menu {
$output .= &Apache::lonhtmlcommon::row_headline().
'
'.&Apache::loncommon::help_open_topic('Course_Request_Personnel').' '.$lt{$crstype}.' '.&mt('Include other personnel?').'
';
}
+ my $cansearch = 1;
+ my @alldoms = &Apache::lonnet::all_domains();
+ if (@alldoms == 1) {
+ my %domsrch = &Apache::lonnet::get_dom('configuration',
+ ['directorysrch'],$alldoms[0]);
+ if (ref($domsrch{'directorysrch'}) eq 'HASH') {
+ if ((!$domsrch{'directorysrch'}{'available'}) &&
+ ($domsrch{'directorysrch'}{'lcavailable'} eq '0')) {
+ $cansearch = 0;
+ }
+ }
+ }
for (my $i=0; $i<$persontotal; $i++) {
my @linkargs = map { 'person_'.$i.'_'.$_ } (@items);
my $linkargstr = join("','",@linkargs);
@@ -2121,9 +2125,14 @@ sub print_personnel_menu {
}
$sectionselector .= $newtitle.
''."\n";
- my $usersrchlinktxt = &mt('Search for user');
- my $usersrchlink = &Apache::loncommon::selectuser_link($formname,@linkargs,$dom,
- $usersrchlinktxt);
+ my $usersrchlink;
+ if ($cansearch) {
+ my $usersrchlinktxt = &mt('Search for user');
+ $usersrchlink = &Apache::loncommon::selectuser_link($formname,@linkargs,$dom,
+ $usersrchlinktxt);
+ } else {
+ $usersrchlink = ' ';
+ }
my $userchklinktxt = &mt('Check username');
my $userchklink = &Apache::loncommon::selectuser_link($formname,@linkargs,$dom,
$userchklinktxt,'checkusername');
@@ -2370,7 +2379,7 @@ sub print_cancel_request {
&Apache::loncommon::start_data_table_row().
''.$history{details}{'cdescr'}.' | '.
&Apache::lonlocal::locallocaltime($timestamp).' | '.
- ''.$showtype.' | '.
+ ''.&mt($showtype).' | '.
&Apache::loncommon::end_data_table_row().
&Apache::loncommon::end_data_table().
'
';
@@ -2724,7 +2733,7 @@ sub requestlog_display_filter {
$typename = $typenames->{$crstype};
}
}
- $output .= '
'."\n";
+ $output .= '
'."\n";
}
$output .= '';
}
@@ -3162,7 +3171,7 @@ sub clone_form {
&Apache::loncommon::select_dom_form($dom,'clonedom').''.
&Apache::lonhtmlcommon::row_closure(1).
&Apache::lonhtmlcommon::row_title($lt{'cid'}).'
'.
&Apache::loncommon::selectcourse_link($formname,'clonecrs','clonedom','','','',$type).
&Apache::lonhtmlcommon::row_closure(1).
@@ -3173,7 +3182,7 @@ sub clone_form {
'
'.
- '
'.
+ '
'.
&Apache::lonhtmlcommon::row_closure(1);
return $output;
}
@@ -3212,7 +3221,7 @@ sub coursecode_form {
}
if (@{$codetitles} > 0) {
my $lastitem = pop(@{$codetitles});
- my $lastinput = '
';
+ my $lastinput = '
';
if (@{$codetitles} > 0) {
my $helplink;
if (defined($helpitem{$context})) {
@@ -3613,6 +3622,19 @@ sub print_request_outcome {
}
}
}
+ if ($env{'form.chome'} eq 'default') {
+ my %servers = &Apache::lonnet::get_servers($dom,'library');
+ my $numlib = keys(%servers);
+ if ($numlib) {
+ my $loadm=10000000;
+ my $chome;
+ foreach my $tryserver (keys(%servers)) {
+ ($chome,$loadm) =
+ &Apache::lonnet::compare_server_load($tryserver,$chome,$loadm);
+ }
+ $env{'form.chome'} = $chome;
+ }
+ }
my $details = {
owner => $env{'user.name'},
domain => $env{'user.domain'},
@@ -3667,7 +3689,7 @@ sub process_request {
}
$storeresult = 'notpermitted';
} else {
- my ($disposition,$message,$reqstatus,$coursedesc,%customvalidation);
+ my ($disposition,$message,$reqstatus,$coursedesc,$accessstart,$accessend,%customvalidation);
my %reqhash = (
reqtime => $now,
crstype => $crstype,
@@ -3679,6 +3701,8 @@ sub process_request {
$env{'user.domain'});
if (ref($details) eq 'HASH') {
$coursedesc = $details->{'cdescr'};
+ $accessstart = $details->{'accessstart'};
+ $accessend = $details->{'accessend'};
}
if ($val eq 'autolimit=') {
$disposition = 'process';
@@ -3766,9 +3790,20 @@ sub process_request {
foreach my $role (@roles) {
$longroles{$role}=&Apache::lonnet::plaintext($role,$type);
}
- $r->print('
'."\n".
- &mt('Your request is being processed; this page will update when processing is complete.').
- '
');
+ my $preamble = '
'.
+ '
'.
+ &mt("Please be patient while your request is processed").
+ '
'.
+ '
';
+ my $closure = <
+//
+
+ENDCLOSE
+ my %prog_state = &Apache::lonhtmlcommon::Create_PrgWin($r,undef,$preamble);
+ &Apache::lonhtmlcommon::Update_PrgWin($r,\%prog_state,&mt('Processing ...'));
$r->rflush();
if (ref($details) eq 'HASH') {
if ($details->{'clonecrs'}) {
@@ -3786,10 +3821,15 @@ sub process_request {
$customitems{'_LC_owneremail'} = $owneremail;
}
$customitems{'_LC_coursedomainname'} = &Apache::lonnet::domain($dom,'description');
+ $customitems{'_LC_coursedescription'} = $coursedesc;
+ $customitems{'_LC_coursestartdate'} = $accessstart;
+ $customitems{'_LC_courseenddate'} = $accessend;
my ($result,$postprocess) = &Apache::loncoursequeueadmin::course_creation($dom,$cnum,
'autocreate',$details,\$logmsg,\$newusermsg,\$addresult,
\$enrollcount,\$response,\$keysmsg,\%domdefs,\%longroles,
\$code,\%customitems);
+ &Apache::lonhtmlcommon::Update_PrgWin($r,\%prog_state,&mt('Finished!'));
+ &Apache::lonhtmlcommon::Close_PrgWin($r,\%prog_state);
if (ref($postprocess) eq 'HASH') {
$customized = $postprocess->{'createdcustomized'};
}
@@ -3824,6 +3864,24 @@ sub process_request {
}
$output .= '';
$creationresult = 'created';
+ # Flush the course logs so reverse user roles immediately updated
+ unless ($registered_flush) {
+ my $handlers = $r->get_handlers('PerlCleanupHandler');
+ $r->set_handlers('PerlCleanupHandler' => [\&Apache::lonnet::flushcourselogs,@{$handlers}]);
+ $registered_flush=1;
+ }
+ if ($instcode ne '') {
+ &Apache::lonnet::devalidate_cache_new('instcats',$dom);
+ # Update cache of self-cataloging courses on institution's server(s).
+ if (&Apache::lonnet::shared_institution($dom)) {
+ unless ($registered_instcats) {
+ my $handlers = $r->get_handlers('PerlCleanupHandler');
+ $r->set_handlers('PerlCleanupHandler' => [\&devalidate_remote_instcats,@{$handlers}]);
+ $registered_instcats=1;
+ $modified_dom = $dom;
+ }
+ }
+ }
} else {
$output = '';
if ($crstype eq 'community') {
@@ -3932,7 +3990,7 @@ sub process_request {
} elsif ($disposition eq 'pending') {
my $pendingform;
if ($crstype ne 'official') {
- $pendingform = &pending_validation_form($dom,$cnum,$crstype,$now,$token,
+ $pendingform = &pending_validation_form($r,$dom,$cnum,$crstype,$now,$token,
$lonhost,$env{'form.cdescr'});
}
if ($pendingform) {
@@ -3959,6 +4017,22 @@ sub process_request {
}
}
+sub devalidate_remote_instcats {
+ if ($modified_dom ne '') {
+ my %servers = &Apache::lonnet::internet_dom_servers($modified_dom);
+ my %thismachine;
+ map { $thismachine{$_} = 1; } &Apache::lonnet::current_machine_ids();
+ if (keys(%servers)) {
+ foreach my $server (keys(%servers)) {
+ next if ($thismachine{$server});
+ &Apache::lonnet::remote_devalidate_cache($server,['instcats:'.$modified_dom]);
+ }
+ }
+ $modified_dom = '';
+ }
+ return;
+}
+
sub custom_formitems {
my ($preprocess,$customhash) = @_;
return unless ((ref($preprocess) eq 'HASH') && (ref($customhash) eq 'HASH'));
@@ -4234,7 +4308,7 @@ sub notification_information {
}
sub pending_validation_form {
- my ($cdom,$cnum,$crstype,$now,$token,$lonhost,$cdesc) = @_;
+ my ($r,$cdom,$cnum,$crstype,$now,$token,$lonhost,$cdesc) = @_;
my $output;
my %postvalues = (
'owner' => $env{'user.name'}.':'.$env{'user.domain'},
@@ -4267,9 +4341,12 @@ sub pending_validation_form {
$buttontext = &mt('Create course');
}
}
+ my $hostname = &Apache::lonnet::hostname($lonhost);
my $protocol = $Apache::lonnet::protocol{$lonhost};
$protocol = 'http' if ($protocol ne 'https');
- my $crscreator = $protocol.'://'.&Apache::lonnet::hostname($lonhost).'/cgi-bin/createpending.pl';
+ my $alias = &Apache::lonnet::use_proxy_alias($r,$lonhost);
+ $hostname = $alias if ($alias ne '');
+ my $crscreator = $protocol.'://'.$hostname.'/cgi-bin/createpending.pl';
$output .= ''."\n".
''."\n".
''."\n".
@@ -4549,7 +4626,16 @@ sub print_textbook_form {
$cc_clone .= $cdom.':'.$cnum.'&';
unless (exists($cloneable{$cdom.'_'.$cnum})) {
my %courseinfo = &Apache::lonnet::coursedescription($cdom.'_'.$cnum,{'one_time' => 1});
- $cloneable{$cdom.'_'.$cnum} = \%courseinfo;
+ $cloneable{$cdom.'_'.$cnum} = {
+ context => $courseinfo{'internal.creationcontext'},
+ created => $courseinfo{'internal.created'},
+ creator => $courseinfo{'internal.creator'},
+ description => $courseinfo{'description'},
+ inst_code => $courseinfo{'coursecode'},
+ owner => $courseinfo{'internal.courseowner'},
+ releaserequired => $courseinfo{'internal.releaserequired'},
+ type => $courseinfo{'type'},
+ };
}
}
@@ -4742,13 +4828,13 @@ sub print_textbook_form {
if (keys(%cloneable)) {
$r->print('');
}
#
@@ -4757,13 +4843,13 @@ sub print_textbook_form {
if (keys(%domcloneable)) {
$r->print('');
}
@@ -4845,11 +4931,14 @@ sub clone_selection_table {
$cleantitle=~s/'/\\'/g;
$cleantitle =~ s/^\s+//;
my ($namestr,@owners,%ownernames);
- my $singleowner = $cloneableref->{$cid}{'internal.courseowner'};
- push(@owners,$singleowner);
+ if ($cloneableref->{$cid}{'owner'} ne '') {
+ push(@owners,$cloneableref->{$cid}{'owner'});
+ }
if ($cloneableref->{$cid}{'co-owners'} ne '') {
- foreach my $item (split(/,/,$cloneableref->{$cid}{'internal.co-owners'})) {
- push(@owners,$item);
+ foreach my $item (split(/,/,$cloneableref->{$cid}{'co-owners'})) {
+ if (($item ne '') && (!grep(/^\Q$item\E$/,@owners))) {
+ push(@owners,$item);
+ }
}
}
foreach my $owner (@owners) {
@@ -4945,11 +5034,7 @@ sub process_textbook_request {
undef($clonedom);
}
}
- my $js = &processing_javascript();
- my $loaditems = {
- onload => 'javascript:hideProcessing();',
- };
- $r->print(&header('Course Creation',$js,$loaditems));
+ $r->print(&header('Course Creation'));
if (ref($can_request) eq 'HASH') {
unless ((scalar(keys(%{$can_request})) == 1) && ($can_request->{'textbook'})) {
@@ -4983,9 +5068,31 @@ sub process_textbook_request {
accessend => $accessend,
personnel => {},
};
- if ($reqtype eq 'existing') {
- $details->{datemode} = $env{'form.datemode'};
- $details->{dateshift} = $env{'form.dateshift'};
+ if (($clonecrs ne '') && ($clonedom ne '')) {
+ if ($reqtype eq 'existing') {
+ $details->{datemode} = $env{'form.owndatemode'};
+ if ($details->{datemode} eq 'shift') {
+ $details->{dateshift} = $env{'form.owndateshift'};
+ } else {
+ $details->{dateshift} = '';
+ }
+ } elsif ($reqtype eq 'colleague') {
+ $details->{datemode} = $env{'form.colldatemode'};
+ if ($details->{datemode} eq 'shift') {
+ $details->{dateshift} = $env{'form.colldateshift'};
+ } else {
+ $details->{dateshift} = '';
+ }
+ } elsif (($reqtype eq 'textbook') || ($reqtype eq 'template')) {
+ $details->{datemode} = 'delete';
+ $details->{dateshift} = '';
+ }
+ if ($details->{dateshift} ne '') {
+ $details->{dateshift} =~ s/[^\d\.]+//g;
+ }
+ } else {
+ $details->{datemode} = '';
+ $details->{dateshift} = '';
}
my $lonhost = $r->dir_config('lonHostID');
$r->rflush();