--- loncom/interface/lonrequestcourse.pm 2010/01/14 20:08:13 1.43
+++ loncom/interface/lonrequestcourse.pm 2010/06/08 16:37:20 1.52
@@ -1,7 +1,7 @@
# The LearningOnline Network
# Request a course
#
-# $Id: lonrequestcourse.pm,v 1.43 2010/01/14 20:08:13 raeburn Exp $
+# $Id: lonrequestcourse.pm,v 1.52 2010/06/08 16:37:20 bisitz Exp $
#
# Copyright Michigan State University Board of Trustees
#
@@ -128,7 +128,7 @@ 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'};
@@ -138,7 +138,7 @@ sub handler {
$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')) {
@@ -166,6 +166,7 @@ sub handler {
details => 'Request Details',
cancel => 'Cancel Request',
removal => 'Outcome',
+ display => 'Request Logs',
);
if (($env{'form.crstype'} eq 'official') && (&Apache::lonnet::auto_run('',$dom))) {
@@ -176,10 +177,10 @@ sub handler {
&get_breadcrumbs($dom,$action,\$state,\%states,\%trail);
if ($action eq 'display') {
if (($dom eq $env{'request.role.domain'}) && (&Apache::lonnet::allowed('ccc',$dom))) {
- my $namespace = 'courserequestqueue';
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 =
@@ -275,6 +276,9 @@ sub handler {
$jscript = &mainmenu_javascript();
} else {
$jscript = &Apache::lonhtmlcommon::set_form_elements($elementsref,\%stored);
+ if ($state eq 'courseinfo') {
+ $jscript .= &cloning_javascript();
+ }
}
}
@@ -314,7 +318,7 @@ sub handler {
} 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.
'
'.&mt('Course/Community Request Details').'
'.
''.$warning.'
'.
&close_popup_form());
@@ -323,7 +327,24 @@ sub handler {
$loaditems,$crumb,'','','','','',$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 .= < 1) {
+ for (var i=0; i {
cdescr => 'text',
+ cloning => 'radio',
clonecrs => 'text',
clonedom => 'selectbox',
datemode => 'radio',
@@ -597,7 +635,10 @@ sub onload_action {
if ($state eq 'crstype') {
$loaditems{'onload'} = 'javascript:setAction(document.mainmenu_action);javascript:setType(document.mainmenu_coursetype)';
} else {
- $loaditems{'onload'} = 'javascript:setFormElements(document.requestcrs)';
+ $loaditems{'onload'} = 'javascript:setFormElements(document.requestcrs);';
+ }
+ if ($state eq 'courseinfo') {
+ $loaditems{'onload'} .= 'javascript:setCloneDisplay(document.requestcrs);';
}
}
return \%loaditems;
@@ -606,11 +647,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})) {
@@ -659,7 +696,7 @@ END
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.',
+ all => 'You must choose a specific course type when making a new course request.\\n\"All types\" is not allowed.',
);
$js .= <'.&mt('View/Modify/Cancel pending requests').'
'.
- &Apache::lonhtmlcommon::row_closure(1).
+ &Apache::lonhtmlcommon::row_closure().
&Apache::lonhtmlcommon::row_title(&mt('Type')).'
');
} elsif ($state eq 'details') {
my (@codetitles,%cat_titles,%cat_order,@code_order,$instcode,$code_chk);
my $origcnum = $env{'form.cnum'};
@@ -994,8 +1031,6 @@ END
&print_review($dom,\@codetitles,\%cat_titles,\%cat_order,
\@code_order,$uname,$udom)."\n".''.
&close_popup_form());
- } elsif ($action eq 'log') {
- $r->print(&coursereq_log('View request log',$jscript,$loaditems).$crumb);
}
$r->print(&Apache::loncommon::end_page());
return;
@@ -1342,7 +1377,11 @@ sub print_request_form {
if ($env{'form.origcnum'} =~ /^($match_courseid)$/) {
$cnum = $env{'form.origcnum'};
} else {
- $cnum = &Apache::lonnet::generate_coursenum($dom);
+ my $gentype = 'Course';
+ if ($crstype eq 'community') {
+ $gentype = 'Community';
+ }
+ $cnum = &Apache::lonnet::generate_coursenum($dom,$gentype);
}
&Apache::lonnet::auto_possible_instcodes($dom,\@codetitles,\%cat_titles,
\%cat_order,\@code_order);
@@ -1668,10 +1707,10 @@ sub date_setting_table {
}
$table = &Apache::lonhtmlcommon::row_title(&Apache::loncommon::help_open_topic($help_item{$prefix}{'start'}).
- ' '.$datetitles{'start'}).$startform.
+ ' '.&mt($datetitles{'start'})).$startform.
&Apache::lonhtmlcommon::row_closure(1).
&Apache::lonhtmlcommon::row_title(&Apache::loncommon::help_open_topic($help_item{$prefix}{'end'}).
- ' '.$datetitles{'end'}).$endform.$perpetual.
+ ' '.&mt($datetitles{'end'})).$endform.$perpetual.
&Apache::lonhtmlcommon::row_closure($closure);
return $table;
}
@@ -1818,51 +1857,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 = ''."\n".
+ my $formname = 'requestcrs';
+ my ($types,$typenames) = &Apache::loncommon::course_types();
+ my $output = ''."\n".
''."\n".
''."\n".
@@ -2042,10 +2123,291 @@ 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(''.
+ &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')) {
+ $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 = ''.
+ ''.&mt('Records/page:').' '.
+ &Apache::lonmeta::selectbox('show',$curr->{'show'},undef,
+ (&mt('all'),5,10,20,50,100,1000,10000)).
+ ' | | ';
+ 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 .= ''.&mt('Window during which course/community was requested:').' '.
+ ''.&mt('After:').
+ ' | '.$startform.' | '.
+ ''.&mt('Before:').' | '.
+ ''.$endform.' | '.
+ ' | '.
+ ' | ';
+ my ($types,$typenames) = &Apache::loncommon::course_types();
+ if (ref($types) eq 'ARRAY') {
+ if (@{$types} > 1) {
+ $output .= ''.
+ &mt('Course Type:').'
| ';
+ }
+ }
+ my ($statuses,$statusnames) = &reqstatus_names($curr->{'crstype'});
+ if (ref($statuses) eq 'ARRAY') {
+ if (@{$statuses} > 1) {
+ $output .= ''.
+ &mt('Request Status:').'
| ';
+ }
+ }
+ $output .= '
';
+
+ # Update Display button
+ $output .= ''.
+ ''.
+ '
';
+ return $output;
+}
+
sub print_review {
my ($dom,$codetitles,$cat_titles,$cat_order,$code_order,$uname,$udom,
$disallowed,$disallowmsg) = @_;
@@ -2169,7 +2531,8 @@ sub print_review {
my %ctxt = &clone_text();
$inst_headers .= ''.&mt('Clone From').' | ';
- if (($env{'form.clonecrs'} =~ /^$match_name$/) &&
+ 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'},
@@ -2351,6 +2714,24 @@ function validateForm() {
}
nextPage(document.$formname,'$next');
}
+
+function toggleCloning() {
+ var willclone;
+ if (document.$formname.cloning.length > 1) {
+ for (var i=0; i
@@ -2361,7 +2742,7 @@ ENDJS
$title = &mt('Brief Community Description');
$clonetitle = &mt('Clone content and settings from an existing community?');
}
- my $output .= $js_validate."\n".''.&Apache::lonhtmlcommon::start_pick_box().
+ my $output .= $js_validate."\n".&Apache::lonhtmlcommon::start_pick_box().
&Apache::lonhtmlcommon::row_headline().
'
'.&Apache::loncommon::help_open_topic('Course_Request_Description').' '.$title.'
'.
&Apache::lonhtmlcommon::row_closure(1).
@@ -2377,10 +2758,22 @@ ENDJS
$output .= $home_server_pick.
&Apache::lonhtmlcommon::row_closure().
&Apache::lonhtmlcommon::row_headline().
- '
'.&Apache::loncommon::help_open_topic('Course_Request_Clone').' '.$clonetitle.'
'.
+ '
'.&Apache::loncommon::help_open_topic('Course_Request_Clone').' '.$clonetitle.
+ &Apache::lonhtmlcommon::row_closure(1).
+ &Apache::lonhtmlcommon::row_title(&mt('Clone?')).
+ ''.
+ '
'.
&Apache::lonhtmlcommon::row_closure(1).
+ &Apache::lonhtmlcommon::row_headline().
+ '
'.
+ &Apache::lonhtmlcommon::start_pick_box().
&clone_form($dom,$formname,$crstype).
- &Apache::lonhtmlcommon::end_pick_box().'
'."\n";
+ &Apache::lonhtmlcommon::end_pick_box().'
'.
+ &Apache::lonhtmlcommon::end_pick_box()."\n";
return $output;
}
@@ -2425,7 +2818,7 @@ sub clone_text {
sub coursecode_form {
my ($dom,$context,$codetitles,$cat_titles,$cat_order,$num) = @_;
my $output;
- my %rowtitle = (
+ my %rowtitle = &Apache::lonlocal::texthash (
instcode => 'Course Category',
crosslist => 'Cross Listed Course',
);
@@ -2741,7 +3134,8 @@ sub print_request_outcome {
}
my $clonecrs = '';
my $clonedom = '';
- if (($env{'form.clonecrs'} =~ /^($match_courseid)$/) &&
+ if (($env{'form.cloning'}) &&
+ ($env{'form.clonecrs'} =~ /^($match_courseid)$/) &&
($env{'form.clonedom'} =~ /^($match_domain)$/)) {
my $clonehome = &Apache::lonnet::homeserver($env{'form.clonecrs'},
$env{'form.clonedom'});
@@ -2900,6 +3294,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'});
@@ -2934,26 +3331,9 @@ sub print_request_outcome {
}
}
}
- my ($statusresult);
- if ($requestkey =~ /^($match_domain)_($match_courseid)$/) {
- $storeresult = &Apache::lonnet::store_userdata(\%reqhash,$requestkey,
- 'courserequests');
- if ($storeresult eq 'ok') {
- my %status = (
- 'status:'.$dom.':'.$cnum => $reqstatus,
- );
- $statusresult = &Apache::lonnet::put('courserequests',\%status);
- }
- } else {
- $storeresult = 'error: invalid requestkey format';
- }
- if ($storeresult ne 'ok') {
- $output .= ''.&mt('An error occurred saving a record of the details of your request: [_1].',$storeresult).'
';
- &Apache::lonnet::logthis("Error saving course request - $requestkey for $env{'user.name'}:$env{'user.domain'} - $storeresult");
- } elsif ($statusresult ne 'ok') {
- $output .= ''.&mt('An error occurred saving a record of the status of your request: [_1].',$statusresult).'
';
- &Apache::lonnet::logthis("Error saving course request status for $requestkey (for $env{'user.name'}:$env{'user.domain'}) - $statusresult");
- }
+ ($storeresult,my $updateresult) =
+ &Apache::loncoursequeueadmin::update_coursereq_status(\%reqhash,$dom,
+ $cnum,$reqstatus,'request');
if ($modified && $queued && $storeresult eq 'ok') {
if ($crstype eq 'community') {
$output .= ''.&mt('Your community request has been updated').'
';
@@ -2963,7 +3343,10 @@ sub print_request_outcome {
$output .= ¬ification_information($disposition,$req_notifylist,$cnum,$now);
}
if ($validationerror ne '') {
- $output .= ''.&mt('An error occurred validating your request with institutional data sources: [_1].',$validationerror).'';
+ $output .= ''.&mt('An error occurred validating your request with institutional data sources: [_1].',$validationerror).'
';
+ }
+ if ($updateresult) {
+ $output .= $updateresult;
}
}
if ($creationresult ne '') {
@@ -3139,8 +3522,8 @@ sub notification_information {
'';
} else {
$output .= ''.
- &mt('Your request status is: [_1].',$disposition).
- '
'
+ &mt('Your request status is: [_1].',$disposition).
+ '';
}
return $output;
}