--- loncom/interface/lonrequestcourse.pm 2009/09/08 13:20:27 1.32 +++ 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.32 2009/09/08 13:20:27 raeburn Exp $ +# $Id: lonrequestcourse.pm,v 1.39 2009/11/04 17:42:17 raeburn Exp $ # # Copyright Michigan State University Board of Trustees # @@ -52,10 +52,6 @@ described at http://www.lon-capa.org. =item onload_action() -=item check_can_request() - -=item course_types() - =item print_main_menu() =item request_administration() @@ -134,7 +130,7 @@ sub handler { } &Apache::loncommon::get_unprocessed_cgi($ENV{'QUERY_STRING'}, - ['action','showdom','cnum','state']); + ['action','showdom','cnum','state','crstype']); &Apache::lonhtmlcommon::clear_breadcrumbs(); my $dom = &get_course_dom(); my $action = $env{'form.action'}; @@ -178,7 +174,7 @@ sub handler { $trail{'enrollment'} = 'Enrollment'; } - my ($page,$crumb,$newinstcode,$codechk,$checkedcode) = + my ($page,$crumb,$newinstcode,$codechk,$checkedcode,$description) = &get_breadcrumbs($dom,$action,\$state,\%states,\%trail); if ($action eq 'display') { if (($dom eq $env{'request.role.domain'}) && (&Apache::lonnet::allowed('ccc',$dom))) { @@ -239,7 +235,7 @@ sub handler { $crosslistcode .= $env{'form.crosslist_'.$i.'_'.$item}; } if ($crosslistcode ne '') { - $codechk{$i} = + ($codechk{$i}, my $rest) = &Apache::lonnet::auto_validate_instcode('',$dom,$crosslistcode); } unless ($codechk{$i} eq 'valid') { @@ -276,17 +272,19 @@ sub handler { my $loaditems = &onload_action($action,$state); - my %can_request; - my $canreq = &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, - $codechk,$checkedcode,\@invalidcrosslist); + $codechk,$checkedcode,$description, + \@invalidcrosslist); } } else { $r->print(&header('Course Requests').$crumb. @@ -296,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); @@ -310,12 +308,12 @@ sub handler { &close_popup_form()); } else { &request_administration($r,$action,$state,$page,\%states,$dom,$jscript, - $loaditems,$crumb,'','','','',$uname,$udom); + $loaditems,$crumb,'','','','','',$uname,$udom); } } 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; } @@ -346,7 +344,7 @@ END sub get_breadcrumbs { my ($dom,$action,$state,$states,$trail) = @_; - my ($crumb,$newinstcode,$codechk,$checkedcode,$numtitles); + my ($crumb,$newinstcode,$codechk,$checkedcode,$numtitles,$description); my $page = 0; if ((ref($states) eq 'HASH') && (ref($trail) eq 'HASH') && (ref($state))) { if (defined($action)) { @@ -371,7 +369,7 @@ sub get_breadcrumbs { $$state = 'codepick'; $page --; } else { - $codechk = + ($codechk,$description) = &Apache::lonnet::auto_validate_instcode('', $dom,$newinstcode); if ($codechk ne 'valid') { @@ -416,7 +414,7 @@ sub get_breadcrumbs { {text=>'Pick Action'}); $crumb = &Apache::lonhtmlcommon::breadcrumbs('Course Requests','Course_Requests'); } - return ($page,$crumb,$newinstcode,$codechk,$checkedcode); + return ($page,$crumb,$newinstcode,$codechk,$checkedcode,$description); } sub header { @@ -593,55 +591,12 @@ sub onload_action { return \%loaditems; } -sub check_can_request { - my ($dom,$can_request) = @_; - my $canreq = 0; - my ($types,$typename) = &course_types(); - my @options = ('approval','validate','autolimit'); - my $optregex = join('|',@options); - if ((ref($can_request) eq 'HASH') && (ref($types) eq 'ARRAY')) { - foreach my $type (@{$types}) { - if (&Apache::lonnet::usertools_access($env{'user.name'}, - $env{'user.domain'}, - $type,undef,'requestcourses')) { - $canreq ++; - if ($dom eq $env{'user.domain'}) { - $can_request->{$type} = 1; - } - } - if ($env{'environment.reqcrsotherdom.'.$type} ne '') { - my @curr = split(',',$env{'environment.reqcrsotherdom.'.$type}); - if (@curr > 0) { - $canreq ++; - unless ($dom eq $env{'user.domain'}) { - if (grep(/^\Q$dom\E:($optregex)(=?\d*)$/,@curr)) { - $can_request->{$type} = 1; - } - } - } - } - } - } - return $canreq; -} - -sub course_types { - my @types = ('official','unofficial','community'); - my %typename = ( - official => 'Official course', - unofficial => 'Unofficial course', - community => 'Community', - ); - return (\@types,\%typename); -} - - sub print_main_menu { - my ($r,$can_request,$states,$dom,$jscript,$loaditems,$crumb) = @_; - my ($types,$typename) = &course_types(); + 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"; @@ -681,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.', @@ -721,20 +677,59 @@ END } return true; } - END - - $r->print(&header('Course Requests',$js.$jscript,$loaditems).$crumb.'
'. + 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')).' @@ -745,24 +740,35 @@ 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". &Apache::lonhtmlcommon::row_closure(1)."\n". &Apache::lonhtmlcommon::end_pick_box().'
'."\n". - '
'."\n". + '
'."\n". ''."\n". ''."\n". ''."\n". @@ -776,7 +782,8 @@ END sub request_administration { my ($r,$action,$state,$page,$states,$dom,$jscript,$loaditems,$crumb, - $newinstcode,$codechk,$checkedcode,$invalidcrosslist,$uname,$udom) = @_; + $newinstcode,$codechk,$checkedcode,$description,$invalidcrosslist, + $uname,$udom) = @_; my $js; if (($action eq 'new') || (($action eq 'view') && ($state eq 'pick_request'))) { $js = <print(&header('Request a course',$js.$jscript,$loaditems,$jsextra).$crumb); &print_request_form($r,$action,$state,$page,$states,$dom,$newinstcode, - $codechk,$checkedcode,$invalidcrosslist); + $codechk,$checkedcode,$description,$invalidcrosslist); } elsif ($action eq 'view') { my $jsextra; my $formname = 'requestcrs'; @@ -1124,7 +1131,7 @@ sub get_instcode { sub print_request_form { my ($r,$action,$state,$page,$states,$dom,$newinstcode,$codechk,$checkedcode, - $invalidcrosslist) = @_; + $description,$invalidcrosslist) = @_; my $formname = 'requestcrs'; my ($next,$prev,$message,$output,$codepicker,$crstype); $prev = $states->{$action}[$page-1]; @@ -1134,7 +1141,7 @@ sub print_request_form { next => 'Next', ); $crstype = $env{'form.crstype'}; - $r->print(''); + $r->print('
'); my (@codetitles,%cat_titles,%cat_order,@code_order,$instcode,$code_chk, @disallowed); if ($crstype eq 'official') { @@ -1171,7 +1178,9 @@ sub print_request_form { $codepicker = &coursecode_form($dom,'instcode',\@codetitles, \%cat_titles,\%cat_order); if ($codepicker) { - $r->print('
'.&Apache::lonhtmlcommon::start_pick_box().$codepicker. + $r->print(&mt('Specify the course to be created.'). + '
'.&Apache::lonhtmlcommon::start_pick_box(). + $codepicker. &Apache::lonhtmlcommon::end_pick_box().'
'); } else { $next = $states->{$action}[$page+2]; @@ -1187,7 +1196,7 @@ sub print_request_form { if ($instcode eq '') { $prev = $states->{$action}[$page-2]; } - $r->print(&courseinfo_form($dom,$formname,$crstype,$next)); + $r->print(&courseinfo_form($dom,$formname,$crstype,$next,$description)); } elsif ($state eq 'enrollment') { if ($crstype eq 'official') { &Apache::lonnet::auto_possible_instcodes($dom,\@codetitles,\%cat_titles, @@ -1411,7 +1420,7 @@ sub get_excluded_elements { sub print_enrollment_menu { my ($formname,$instcode,$dom,$codetitles,$cat_titles,$cat_order,$code_order, $invalidcrosslist) =@_; - my ($sections,$autoenroll,$access_dates,$output); + my ($sections,$autoenroll,$access_dates,$output,$hasauto); my $starttime = time; my $endtime = time+(6*30*24*60*60); # 6 months from now, approx @@ -1430,7 +1439,8 @@ sub print_enrollment_menu { $section_form = &inst_section_selector($dom,$instcode); if ($section_form) { $sections = &Apache::lonhtmlcommon::row_headline(). - '

'.&mt('Sections for auto-enrollment').'

'. + '

'.&Apache::loncommon::help_open_topic('Course_Request_Sections'). + ' '.&mt('Sections for auto-enrollment').'

'. &Apache::lonhtmlcommon::row_closure(1). $section_form; } @@ -1457,26 +1467,29 @@ sub print_enrollment_menu { &Apache::lonhtmlcommon::row_closure(1). $crosslist_form; } + $hasauto = 1; $autoenroll = - &Apache::lonhtmlcommon::row_title(&mt('Add registered students automatically')). + &Apache::lonhtmlcommon::row_title(&Apache::loncommon::help_open_topic('Course_Request_Autoadd').' '.&mt('Add registered students automatically')). ''.(' 'x3).''. &Apache::lonhtmlcommon::row_closure(1). - &Apache::lonhtmlcommon::row_title(&mt('Drop unregistered students automatically')). + &Apache::lonhtmlcommon::row_title(&Apache::loncommon::help_open_topic('Course_Request_Autodrop').' '.&mt('Drop unregistered students automatically')). ''.(' 'x3).''. &Apache::lonhtmlcommon::row_closure(1). - &date_setting_table($starttime,$endtime,$formname,'enroll',%enrolltitles); + &date_setting_table($starttime,$endtime,$formname,'enroll', + $hasauto,%enrolltitles); } } my $access_dates = - &date_setting_table($starttime,$endtime,$formname,'access',%accesstitles); + &date_setting_table($starttime,$endtime,$formname,'access',$hasauto, + %accesstitles); $output .= &Apache::lonhtmlcommon::start_pick_box(); if ($sections) { $output .= $sections; @@ -1530,7 +1543,8 @@ sub inst_section_selector { ''.&mt('Include?').''. ''.&mt('Institutional Section').''. - ''.&mt('LON-CAPA section').''. + ''.&Apache::loncommon::help_open_topic('Course_Request_LCSection'). + ' '.&mt('LON-CAPA section').''. &Apache::loncommon::end_data_table_row(); for (my $i=0; $i<@sections; $i++) { my $colflag = $i%2; @@ -1559,7 +1573,7 @@ sub inst_section_selector { } sub date_setting_table { - my ($starttime,$endtime,$formname,$prefix,%datetitles) = @_; + my ($starttime,$endtime,$formname,$prefix,$hasauto,%datetitles) = @_; my ($perpetual,$table); my $startform = &Apache::lonhtmlcommon::date_setter($formname,$prefix.'start', $starttime,'','','',1,'','','',1); @@ -1572,11 +1586,27 @@ sub date_setting_table { &mt('No end date').''; $closure = '1'; } - $table = &Apache::lonhtmlcommon::row_title($datetitles{'start'}). - $startform. + + my %help_item = ( + access => { + start => 'Course_Request_Access_Start', + end => 'Course_Request_Access_End', + }, + enroll => { + start => 'Course_Request_Enroll_Start', + end => 'Course_Request_Enroll_End', + }, + ); + if ($hasauto) { + $help_item{'access'}{'start'} = 'Course_Request_RegAccess_Start'; + $help_item{'access'}{'end'} = 'Course_Request_RegAccess_End'; + } + + $table = &Apache::lonhtmlcommon::row_title(&Apache::loncommon::help_open_topic($help_item{$prefix}{'start'}). + ' '.$datetitles{'start'}).$startform. &Apache::lonhtmlcommon::row_closure(1). - &Apache::lonhtmlcommon::row_title($datetitles{'end'}). - $endform.$perpetual. + &Apache::lonhtmlcommon::row_title(&Apache::loncommon::help_open_topic($help_item{$prefix}{'end'}). + ' '.$datetitles{'end'}).$endform.$perpetual. &Apache::lonhtmlcommon::row_closure($closure); return $table; } @@ -1645,7 +1675,7 @@ sub print_personnel_menu { ); $lt{'unofficial'} = $lt{'official'}; $output .= &Apache::lonhtmlcommon::row_headline(). - '

'.$lt{$crstype}.' '.&mt('Include other personnel?').'

'; + '

'.&Apache::loncommon::help_open_topic('Course_Request_Personnel').' '.$lt{$crstype}.' '.&mt('Include other personnel?').'

'; } for (my $i=0; $i<$persontotal; $i++) { my @linkargs = map { 'person_'.$i.'_'.$_ } (@items); @@ -1687,8 +1717,9 @@ sub print_personnel_menu { ''.&mt('First Name').'
'.$form_elems{'firstname'}.''."\n". ''.&mt('Last Name').'
'.$form_elems{'lastname'}.''."\n". ''.&mt('E-mail').'
'.$form_elems{'emailaddr'}.''."\n". - ''.&mt('Role').'
'.$roleselector.''."\n". - ''.&mt('Section(s)').'
'.$sectionselector.''."\n". + ''.&Apache::loncommon::help_open_topic('Course_Roles').' '.&mt('Role').'
'.$roleselector.''."\n". + ''. + &Apache::loncommon::help_open_topic('Course_Request_Rolesection').' '.&mt('LON-CAPA Section(s)').'
'.$sectionselector.''."\n". ''.&Apache::lonhtmlcommon::row_closure(); } $output .= &Apache::lonhtmlcommon::row_title(&mt('Add another?')). @@ -1696,7 +1727,8 @@ sub print_personnel_menu { ''.&mt('Add?').&Apache::lonhtmlcommon::row_closure(1). - &Apache::lonhtmlcommon::end_pick_box().'
'; + &Apache::lonhtmlcommon::end_pick_box().'
'. + '

'.&mt('You may also add users later, once the course has been created, by using the "Manage course users" link, accessible from the "Main Menu".').'

'; return $output; } @@ -1721,14 +1753,8 @@ sub print_request_status { my ($dom) = @_; my %statusinfo = &Apache::lonnet::dump('courserequests',$env{'user.domain'}, $env{'user.name'},'^status:'.$dom); - my ($output,$formname,%queue_by_date,%typenames); - if ($env{'form.crstype'} eq 'any') { - %typenames = &Apache::lonlocal::texthash ( - official => 'Official course', - unofficial => 'Unofficial course', - community => 'Community', - ); - } + my ($output,$formname,%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); @@ -1799,7 +1825,10 @@ sub print_request_status { ''.&unescape($desc).''. ''.$cdom.''; if ($env{'form.crstype'} eq 'any') { - my $typename = $typenames{$type}; + my $typename; + if (ref($typenames) eq 'HASH') { + $typename = &mt($typenames->{$type}); + } if ($typename eq '') { $typename = &mt('Unknown type'); } @@ -1847,7 +1876,7 @@ sub print_cancel_request { } $output = &mt('No further action will be taken'); } elsif (ref($history{'details'}) eq 'HASH') { - my ($types,$typename) = &course_types(); + my ($types,$typename) = &Apache::loncommon::course_types(); my $showtype = $crstype; if (defined($typename->{$crstype})) { $showtype = $typename->{$crstype}; @@ -1933,7 +1962,7 @@ sub print_request_logs { sub print_review { my ($dom,$codetitles,$cat_titles,$cat_order,$code_order,$uname,$udom, $disallowed,$disallowmsg) = @_; - my ($types,$typename) = &course_types(); + my ($types,$typename) = &Apache::loncommon::course_types(); my ($owner,$ownername,$owneremail); if ($uname eq '' || $udom eq '') { $uname = $env{'user.name'}; @@ -1952,7 +1981,7 @@ sub print_review { $crstypename = $env{'form.crstype'}; if (ref($typename) eq 'HASH') { unless ($typename->{$env{'form.crstype'}} eq '') { - $crstypename = $typename->{$env{'form.crstype'}}; + $crstypename = &mt($typename->{$env{'form.crstype'}}); } } my $category = 'Course'; @@ -2056,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')); @@ -2214,7 +2244,7 @@ sub dates_from_form { } sub courseinfo_form { - my ($dom,$formname,$crstype,$next) = @_; + my ($dom,$formname,$crstype,$next,$description) = @_; my %lt = &Apache::lonlocal::texthash( official => 'You must provide a (brief) course description.', community => 'You must provide a (brief) community description.' @@ -2241,10 +2271,10 @@ ENDJS } my $output .= $js_validate."\n".'
'.&Apache::lonhtmlcommon::start_pick_box(). &Apache::lonhtmlcommon::row_headline(). - '

'.$title.'

'. + '

'.&Apache::loncommon::help_open_topic('Course_Request_Description').' '.$title.'

'. &Apache::lonhtmlcommon::row_closure(1). &Apache::lonhtmlcommon::row_title(&mt('Description')). - ''; + ''; my ($home_server_pick,$numlib) = &Apache::loncommon::home_server_form_item($dom,'chome', 'default','hide'); @@ -2255,7 +2285,7 @@ ENDJS $output .= $home_server_pick. &Apache::lonhtmlcommon::row_closure(). &Apache::lonhtmlcommon::row_headline(). - '

'.&mt('Clone content and settings from an existing course?').'

'. + '

'.&Apache::loncommon::help_open_topic('Course_Request_Clone').' '.&mt('Clone content and settings from an existing course?').'

'. &Apache::lonhtmlcommon::row_closure(1). &clone_form($dom,$formname,$crstype). &Apache::lonhtmlcommon::end_pick_box().'
'."\n"; @@ -2268,14 +2298,14 @@ sub clone_form { if ($crstype eq 'community') { $type = 'Community'; } - my $cloneform = &Apache::loncommon::select_dom_form($dom,'clonedom'). + my $cloneform = &Apache::loncommon::select_dom_form($dom,'clonedom').' '. &Apache::loncommon::selectcourse_link($formname,'clonecrs','clonedom','','','',$type); my %lt = &clone_text(); my $output .= &Apache::lonhtmlcommon::row_title($lt{'cid'}).''.&Apache::lonhtmlcommon::row_closure(1).''. + ''.&Apache::lonhtmlcommon::row_closure(1). + &Apache::lonhtmlcommon::row_title($lt{'dmn'}).''.&Apache::lonhtmlcommon::row_closure(1). &Apache::lonhtmlcommon::row_title($lt{'dsh'}).'