--- loncom/interface/lonrequestcourse.pm 2009/08/23 03:51:53 1.24
+++ loncom/interface/lonrequestcourse.pm 2009/08/27 00:06:18 1.26
@@ -1,7 +1,7 @@
# The LearningOnline Network
# Request a course
#
-# $Id: lonrequestcourse.pm,v 1.24 2009/08/23 03:51:53 raeburn Exp $
+# $Id: lonrequestcourse.pm,v 1.26 2009/08/27 00:06:18 raeburn Exp $
#
# Copyright Michigan State University Board of Trustees
#
@@ -122,13 +122,42 @@ sub handler {
return OK;
}
+ &Apache::loncommon::get_unprocessed_cgi($ENV{'QUERY_STRING'},['action','showdom','cnum']);
&Apache::lonhtmlcommon::clear_breadcrumbs();
my $dom = &get_course_dom();
my $action = $env{'form.action'};
my $state = $env{'form.state'};
my %stored;
my $jscript;
- if ((defined($state)) && (defined($action))) {
+ my ($uname,$udom,$result,$warning);
+ 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 $namespace = 'courserequestqueue';
+ my $domconfig = &Apache::lonnet::get_domainconfiguser($dom);
+ my %queued =
+ &Apache::lonnet::get($namespace,[$reqkey],$dom,$domconfig);
+ if (ref($queued{$reqkey}) eq 'HASH') {
+ $uname = $queued{$reqkey}{'ownername'};
+ $udom = $queued{$reqkey}{'ownerdom'};
+ if (($udom =~ /^$match_domain$/) && ($uname =~ /^$match_username$/)) {
+ $result = &retrieve_settings($dom,$cnum,$udom,$uname);
+ } else {
+ $warning = &mt('Invalid username or domain for course requestor');
+ }
+ } else {
+ $warning = &mt('No information was found for this course request.');
+ }
+ } else {
+ $warning = &mt('No course request ID provided.');
+ }
+ } else {
+ $warning = &mt('You do not have rights to view course request information.');
+ }
+ } elsif ((defined($state)) && (defined($action))) {
if (($action eq 'view') && ($state eq 'details')) {
if ((defined($env{'form.showdom'})) && (defined($env{'form.cnum'}))) {
my $result = &retrieve_settings($env{'form.showdom'},$env{'form.cnum'});
@@ -154,6 +183,7 @@ sub handler {
my $loaditems = &onload_action($action,$state);
my %states;
+ $states{'display'} = ['details'];
$states{'view'} = ['pick_request','details','cancel','removal'];
$states{'log'} = ['filter','display'];
$states{'new'} = ['courseinfo','enrollment','personnel','review','process'];
@@ -245,10 +275,21 @@ sub handler {
}
} elsif ($action eq 'view') {
if ($state eq 'crstype') {
- &print_main_menu($r,\%can_request,\%states,$dom,$jscript,'',$crumb);
+ &print_main_menu($r,\%can_request,\%states,$dom,$jscript,'',$crumb);
+ } else {
+ &request_administration($r,$action,$state,$page,\%states,$dom,$jscript,
+ $loaditems,$crumb);
+ }
+ } elsif ($action eq 'display') {
+ if ($warning ne '') {
+ my $args = { only_body => 1 };
+ $r->print(&header('Course Requests','','',$args).$crumb.
+ '
'.&mt('Course Request Details').'
'.
+ ''.$warning.'
'.
+ &close_popup_form());
} else {
- &request_administration($r,$action,$state,$page,\%states,$dom,$jscript,
- $loaditems,$crumb);
+ &request_administration($r,$action,$state,$page,\%states,$dom,$jscript,
+ $loaditems,$crumb,$uname,$udom);
}
} elsif ($action eq 'log') {
&print_request_logs($jscript,$loaditems,$crumb);
@@ -259,18 +300,24 @@ sub handler {
}
sub header {
- my ($bodytitle,$jscript,$loaditems,$jsextra) = @_;
+ my ($bodytitle,$jscript,$loaditems,$jsextra,$args) = @_;
if ($jscript) {
$jscript = ''."\n";
}
if ($loaditems) {
- $loaditems = {'add_entries' => $loaditems,};
- return &Apache::loncommon::start_page($bodytitle,$jscript.$jsextra,$loaditems);
- } else {
- return &Apache::loncommon::start_page($bodytitle,$jscript.$jsextra);
+ if (ref($args) eq 'HASH') {
+ my %loadhash = (
+ 'add_entries' => $loaditems,
+ );
+ my %arghash = (%loadhash,%{$args});
+ $args = \%arghash;
+ } else {
+ $args = {'add_entries' => $loaditems,};
+ }
}
+ return &Apache::loncommon::start_page($bodytitle,$jscript.$jsextra,$args);
}
sub form_elements {
@@ -601,7 +648,7 @@ END
}
sub request_administration {
- my ($r,$action,$state,$page,$states,$dom,$jscript,$loaditems,$crumb) = @_;
+ my ($r,$action,$state,$page,$states,$dom,$jscript,$loaditems,$crumb,$uname,$udom) = @_;
my $js;
if (($action eq 'new') || (($action eq 'view') && ($state eq 'pick_request'))) {
$js = <print(''.&mt('Course Request Details').'
'."\n".$form."\n".
- &print_review($formname,$dom,\@codetitles,\%cat_titles,\%cat_order,
+ &print_review($dom,\@codetitles,\%cat_titles,\%cat_order,
\@code_order)."\n".
''."\n");
my @excluded = &get_excluded_elements($dom,$states,'new','review');
@@ -734,6 +781,18 @@ END
}
$r->print('');
}
+ } elsif ($action eq 'display') {
+ my $formname = 'requestcrs';
+ my (@codetitles,%cat_titles,%cat_order,@code_order,$instcode,$code_chk);
+ if ($env{'form.crstype'} eq 'official') {
+ &Apache::lonnet::auto_possible_instcodes($dom,\@codetitles,\%cat_titles,
+ \%cat_order,\@code_order);
+ }
+ $r->print(&header('Course Request','','','',{ 'only_body' => 1}).
+ $crumb."\n".'
'.&mt('Course Request Details').'
'.
+ &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);
}
@@ -741,6 +800,15 @@ END
return;
}
+sub close_popup_form {
+ my $close= &mt('Close Window');
+ return << "END";
+
+END
+}
+
sub print_request_form {
my ($r,$action,$state,$page,$states,$dom) = @_;
my $formname = 'requestcrs';
@@ -841,8 +909,7 @@ sub print_request_form {
&Apache::lonnet::auto_possible_instcodes($dom,\@codetitles,\%cat_titles,
\%cat_order,\@code_order);
$r->print(''.&mt('Review the details of the course request before submission.').'
'.
- &print_review($formname,$dom,\@codetitles,\%cat_titles,\%cat_order,
- \@code_order).
+ &print_review($dom,\@codetitles,\%cat_titles,\%cat_order,\@code_order).
'');
$navtxt{'next'} = &mt('Submit course request');
} elsif ($state eq 'process') {
@@ -1350,13 +1417,16 @@ sub print_request_logs {
}
sub print_review {
- my ($formname,$dom,$codetitles,$cat_titles,$cat_order,$code_order) = @_;
+ my ($dom,$codetitles,$cat_titles,$cat_order,$code_order,$uname,$udom) = @_;
my ($types,$typename) = &course_types();
my ($owner,$ownername,$owneremail);
- $owner = $env{'user.name'}.':'.$env{'user.domain'};
- $ownername = &Apache::loncommon::plainname($env{'user.name'},
- $env{'user.domain'},'first');
- my %emails = &Apache::loncommon::getemails();
+ if ($uname eq '' || $udom eq '') {
+ $uname = $env{'user.name'};
+ $udom = $env{'user.domain'};
+ }
+ $owner = $uname.':'.$udom;
+ $ownername = &Apache::loncommon::plainname($uname,$udom,'first');
+ my %emails = &Apache::loncommon::getemails($uname,$udom);
foreach my $email ('permanentemail','critnotification','notification') {
$owneremail = $emails{$email};
last if ($owneremail ne '');
@@ -1589,7 +1659,7 @@ sub print_review {
''.$personnel_headers.'
'."\n".
$personnel_values.'
'."\n".
&Apache::lonhtmlcommon::row_closure(1).
- &Apache::lonhtmlcommon::end_pick_box();
+ &Apache::lonhtmlcommon::end_pick_box().'';
return $output;
}
@@ -2112,9 +2182,10 @@ sub print_request_outcome {
$env{'user.domain'},$env{'user.name'});
if ($userreqhash{$statuskey} ne '') {
$modified = 1;
- my %queuehash = &Apache::lonnet::get_dom('courserequestqueue',
- [$cnum.'_approval',
- $cnum.'_pending'],$dom);
+ my $uname = &Apache::lonnet::get_domainconfiguser($dom);
+ my %queuehash = &Apache::lonnet::get('courserequestqueue',
+ [$cnum.'_approval',
+ $cnum.'_pending'],$dom,$uname);
if (($queuehash{$cnum.'_approval'} ne '') ||
($queuehash{$cnum.'_pending'} ne '')) {
$queued = 1;
@@ -2326,11 +2397,14 @@ sub check_autolimit {
}
sub retrieve_settings {
- my ($dom,$cnum) = @_;
- my ($result,%reqinfo) = &get_request_settings($dom,$cnum);
+ my ($dom,$cnum,$udom,$uname) = @_;
+ if ($udom eq '' || $uname eq '') {
+ $udom = $env{'user.domain'};
+ $uname = $env{'user.name'};
+ }
+ my ($result,%reqinfo) = &get_request_settings($dom,$cnum,$udom,$uname);
if ($result eq 'ok') {
- if (($env{'user.name'} eq $reqinfo{'owner'}) &&
- ($env{'user.domain'} eq $reqinfo{'domain'})) {
+ if (($udom eq $reqinfo{'domain'}) && ($uname eq $reqinfo{'owner'})) {
$env{'form.chome'} = $reqinfo{'coursehome'};
$env{'form.cdescr'} = $reqinfo{'cdescr'};
$env{'form.crstype'} = $reqinfo{'crstype'};
@@ -2432,12 +2506,11 @@ sub retrieve_settings {
}
sub get_request_settings {
- my ($dom,$cnum) = @_;
+ my ($dom,$cnum,$udom,$uname) = @_;
my $requestkey = $dom.'_'.$cnum;
my ($result,%reqinfo);
if ($requestkey =~ /^($match_domain)_($match_courseid)$/) {
- my %history = &Apache::lonnet::restore($requestkey,'courserequests',
- $env{'user.domain'},$env{'user.name'});
+ my %history = &Apache::lonnet::restore($requestkey,'courserequests',$udom,$uname);
my $disposition = $history{'disposition'};
if (($disposition eq 'approval') || ($disposition eq 'pending')) {
if (ref($history{'details'}) eq 'HASH') {