--- loncom/interface/lonrequestcourse.pm 2009/10/25 14:48:55 1.38 +++ loncom/interface/lonrequestcourse.pm 2009/11/04 17:42:17 1.39 @@ -1,7 +1,7 @@ # The LearningOnline Network # Request a course # -# $Id: lonrequestcourse.pm,v 1.38 2009/10/25 14:48:55 raeburn Exp $ +# $Id: lonrequestcourse.pm,v 1.39 2009/11/04 17:42:17 raeburn Exp $ # # Copyright Michigan State University Board of Trustees # @@ -272,13 +272,14 @@ sub handler { my $loaditems = &onload_action($action,$state); - my %can_request; - my $canreq = &Apache::lonnet::check_can_request($dom,\%can_request); + my (%can_request,%request_domains); + my $canreq = + &Apache::lonnet::check_can_request($dom,\%can_request,\%request_domains); if ($action eq 'new') { if ($canreq) { if ($state eq 'crstype') { &print_main_menu($r,\%can_request,\%states,$dom,$jscript,$loaditems, - $crumb); + $crumb,\%request_domains); } else { &request_administration($r,$action,$state,$page,\%states,$dom, $jscript,$loaditems,$crumb,$newinstcode, @@ -293,7 +294,7 @@ sub handler { } } elsif ($action eq 'view') { if ($state eq 'crstype') { - &print_main_menu($r,\%can_request,\%states,$dom,$jscript,$loaditems,$crumb); + &print_main_menu($r,\%can_request,\%states,$dom,$jscript,$loaditems,$crumb,\%request_domains); } else { &request_administration($r,$action,$state,$page,\%states,$dom,$jscript, $loaditems,$crumb); @@ -312,7 +313,7 @@ sub handler { } elsif ($action eq 'log') { &print_request_logs($jscript,$loaditems,$crumb); } else { - &print_main_menu($r,\%can_request,\%states,$dom,$jscript,'',$crumb); + &print_main_menu($r,\%can_request,\%states,$dom,$jscript,'',$crumb,\%request_domains); } return OK; } @@ -591,11 +592,11 @@ sub onload_action { } sub print_main_menu { - my ($r,$can_request,$states,$dom,$jscript,$loaditems,$crumb) = @_; + 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 = 1; + $onchange = 'this.form.submit()'; } my $nextstate_setter = "\n"; @@ -635,11 +636,12 @@ function check_can_request(crschoice,act var unofficial = ''; var community = ''; END - - foreach my $item (keys(%{$can_request})) { - $js .= " + if (ref($can_request) eq 'HASH') { + foreach my $item (keys(%{$can_request})) { + $js .= " $item = 1; "; + } } my %lt = &Apache::lonlocal::texthash( official => 'You are not permitted to request creation of an official course in this domain.', @@ -675,22 +677,59 @@ END } return true; } - END - - $r->print(&header('Course Requests',$js.$jscript,$loaditems).$crumb. - '

'.&mt('Request creation of a new course, or review your pending course requests.').'

'. + my ($pagetitle,$pageinfo,$domaintitle); + if (ref($can_request) eq 'HASH') { + if (($can_request->{'official'}) || ($can_request->{'unofficial'})) { + if ($can_request->{'community'}) { + $pagetitle = 'Course/Community Requests'; + $pageinfo = &mt('Request creation of a new course or community, or review your pending requests.'); + $domaintitle = &mt('Course/Community Domain'); + } else { + $pagetitle = 'Course Requests'; + $pageinfo = &mt('Request creation of a new course, or review your pending course requests.'); + $domaintitle = &mt('Course Domain'); + } + } elsif ($can_request->{'community'}) { + $pagetitle = 'Course/Community Requests'; + $pageinfo = &mt('Request creation of a new course or community, or review your pending requests.'); + $domaintitle = &mt('Community Domain'); + } else { + $pagetitle = 'Course/Community Requests'; + $pageinfo = &mt('You do not have rights to request creation of courses in this domain; please choose a different domain.'); + $domaintitle = &mt('Course/Community Domain'); + } + } + my @incdoms; + if (ref($request_domains) eq 'HASH') { + foreach my $item (keys(%{$request_domains})) { + if (ref($request_domains->{$item}) eq 'ARRAY') { + foreach my $possdom (@{$request_domains->{$item}}) { + unless(grep(/^\Q$possdom\E$/,@incdoms)) { + push(@incdoms,$possdom); + } + } + } + } + } + $r->print(&header($pagetitle,$js.$jscript,$loaditems).$crumb. + '

'.$pageinfo.'

'. '
'. &Apache::lonhtmlcommon::start_pick_box(). - &Apache::lonhtmlcommon::row_title(&mt('Course Domain')). + &Apache::lonhtmlcommon::row_title($domaintitle). '
'. - &Apache::loncommon::select_dom_form($dom,'showdom','',1,$onchange)); + &Apache::loncommon::select_dom_form($dom,'showdom','',1,$onchange,\@incdoms)); if (!$onchange) { $r->print(' '); } + unless ((ref($can_request) eq 'HASH') && (keys(%{$can_request}) > 0)) { + $r->print(&Apache::lonhtmlcommon::row_closure(1)."\n". + &Apache::lonhtmlcommon::end_pick_box().'
'."\n". + &Apache::loncommon::end_page()); + return; + } $r->print(''.&Apache::lonhtmlcommon::row_closure()); - my $formname = 'requestcrs'; my $nexttext = &mt('Next'); $r->print(&Apache::lonhtmlcommon::row_title(&mt('Action')).' @@ -701,18 +740,29 @@ END '. &Apache::lonhtmlcommon::row_closure(1). - &Apache::lonhtmlcommon::row_title(&mt('Course Type')).' + &Apache::lonhtmlcommon::row_title(&mt('Type')).'
-'); + if (ref($can_request) eq 'HASH') { + if (keys(%{$can_request}) > 1) { + $r->print(' '); + } + if ((ref($types) eq 'ARRAY') && (ref($typename) eq 'HASH')) { + foreach my $type (@{$types}) { + next unless($can_request->{$type}); + my $selected = ''; + if ($env{'form.crstype'} eq '') { + if ($type eq 'official') { + $selected = ' selected="selected"'; + } + } else { + if ($type eq $env{'form.crstype'}) { + $selected = ' selected="selected"'; + } + } + $r->print(''."\n"); } - $r->print(''."\n"); } } $r->print('
'."\n". @@ -2035,7 +2085,8 @@ sub print_review { if (($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'}); + $env{'user.domain'},$env{'form.clonecrs'},$env{'form.clonedom'}, + $env{'form.crstype'}); if ($canclone) { my %courseenv = &Apache::lonnet::userenvironment($env{'form.clonedom'}, $env{'form.clonecrs'},('description','internal.coursecode')); @@ -2601,7 +2652,8 @@ sub print_request_outcome { if ($clonehome ne 'no_host') { my $canclone = &Apache::loncoursequeueadmin::can_clone_course($env{'user.name'}, - $env{'user.domain'},$env{'form.clonecrs'}, $env{'form.clonedom'}); + $env{'user.domain'},$env{'form.clonecrs'},$env{'form.clonedom'}, + $crstype); if ($canclone) { $clonecrs = $env{'form.clonecrs'}; $clonedom = $env{'form.clonedom'};