--- loncom/interface/lonrequestcourse.pm 2009/10/02 16:15:49 1.36.2.2 +++ loncom/interface/lonrequestcourse.pm 2013/12/25 20:43:46 1.71 @@ -1,7 +1,7 @@ # The LearningOnline Network # Request a course # -# $Id: lonrequestcourse.pm,v 1.36.2.2 2009/10/02 16:15:49 raeburn Exp $ +# $Id: lonrequestcourse.pm,v 1.71 2013/12/25 20:43:46 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() @@ -98,8 +94,6 @@ described at http://www.lon-capa.org. =item print_request_outcome() -=item get_processtype() - =item check_autolimit() =item retrieve_settings() @@ -134,17 +128,21 @@ sub handler { } &Apache::loncommon::get_unprocessed_cgi($ENV{'QUERY_STRING'}, - ['action','showdom','cnum','state']); + ['action','showdom','cnum','state','crstype','queue']); &Apache::lonhtmlcommon::clear_breadcrumbs(); my $dom = &get_course_dom(); my $action = $env{'form.action'}; my $state = $env{'form.state'}; my (%states,%stored); - my ($jscript,$uname,$udom,$result,$warning); + my ($jscript,$uname,$udom,$result,$warning,$showcredits,$instcredits); + my %domdefs = &Apache::lonnet::get_domain_defaults($dom); + if ($domdefs{'officialcredits'} || $domdefs{'unofficialcredits'} || $domdefs{'textbookcredits'}) { + $showcredits = 1; + } $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')) { @@ -153,6 +151,12 @@ sub handler { } } + if (($action eq 'new') && (&Apache::loncoursequeueadmin::author_prompt())) { + if (ref($states{$action}) eq 'ARRAY') { + push(@{$states{$action}},'reqauthor'); + } + } + foreach my $key (keys(%states)) { if (ref($states{$key}) eq 'ARRAY') { unshift (@{$states{$key}},'crstype'); @@ -161,31 +165,33 @@ sub handler { my @invalidcrosslist; my %trail = ( - crstype => 'Course Request Action', + crstype => 'Request Action', codepick => 'Category', courseinfo => 'Description', enrollment => 'Access Dates', personnel => 'Personnel', review => 'Review', process => 'Result', + reqauthor => 'Authoring Space Result', pick_request => 'Display Summary', details => 'Request Details', cancel => 'Cancel Request', removal => 'Outcome', + display => 'Request Logs', ); if (($env{'form.crstype'} eq 'official') && (&Apache::lonnet::auto_run('',$dom))) { $trail{'enrollment'} = 'Enrollment'; } - my ($page,$crumb,$newinstcode,$codechk,$checkedcode,$description) = + 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))) { - 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 = @@ -196,16 +202,30 @@ sub handler { if (($udom =~ /^$match_domain$/) && ($uname =~ /^$match_username$/)) { $result = &retrieve_settings($dom,$cnum,$udom,$uname); } else { - $warning = &mt('Invalid username or domain for course requestor'); + if ($env{'form.crstype'} eq 'community') { + $warning = &mt('Invalid username or domain for community requestor'); + } else { + $warning = &mt('Invalid username or domain for course requestor'); + } } } else { - $warning = &mt('No information was found for this course request.'); + if ($env{'form.crstype'} eq 'community') { + $warning = &mt('No information was found for this community request.'); + } 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.'); + if ($env{'form.crstype'} eq 'any') { + $warning = &mt('You do not have rights to view course or community request information.'); + } elsif ($env{'form.crstype'} eq 'community') { + $warning = &mt('You do not have rights to view community request information.'); + } 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')) { @@ -238,8 +258,8 @@ sub handler { foreach my $item (@code_order) { $crosslistcode .= $env{'form.crosslist_'.$i.'_'.$item}; } - if ($crosslistcode ne '') { - ($codechk{$i}, my $rest) = + if ($crosslistcode ne '') { + ($codechk{$i}, my $rest) = &Apache::lonnet::auto_validate_instcode('',$dom,$crosslistcode); } unless ($codechk{$i} eq 'valid') { @@ -253,11 +273,11 @@ sub handler { } } } - my %elements = &form_elements($dom); + (my $elements,$instcredits) = &form_elements($dom,$showcredits); my $elementsref = {}; - if (ref($elements{$action}) eq 'HASH') { - if (ref($elements{$action}{$state}) eq 'HASH') { - $elementsref = $elements{$action}{$state}; + if ((ref($elements) eq 'HASH') && (ref($elements->{$action}) eq 'HASH')) { + if (ref($elements->{$action}{$state}) eq 'HASH') { + $elementsref = $elements->{$action}{$state}; } } if (($state eq 'courseinfo') && ($env{'form.clonedom'} eq '')) { @@ -267,6 +287,9 @@ sub handler { $jscript = &mainmenu_javascript(); } else { $jscript = &Apache::lonhtmlcommon::set_form_elements($elementsref,\%stored); + if ($state eq 'courseinfo') { + $jscript .= &cloning_javascript(); + } } } @@ -276,47 +299,66 @@ 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,$description, - \@invalidcrosslist); + $showcredits,$instcredits,\@invalidcrosslist); } } else { - $r->print(&header('Course Requests').$crumb. + $r->print(&header('Course/Community Requests').$crumb. '
'. - &mt('You do not have privileges to request creation of courses.'). + &mt('You do not have privileges to request creation of courses or communities.'). '
'.&Apache::loncommon::end_page()); } } 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); + $loaditems,$crumb,'','','','',$showcredits); } } elsif ($action eq 'display') { if ($warning ne '') { my $args = { only_body => 1 }; - $r->print(&header('Course Requests','','',$args).$crumb. - '

'.&mt('Course Request Details').'

'. + $r->print(&header('Course/Community Requests','','' ,'',$args).$crumb. + '

'.&mt('Course/Community Request Details').'

'. '
'.$warning.'
'. &close_popup_form()); } else { &request_administration($r,$action,$state,$page,\%states,$dom,$jscript, - $loaditems,$crumb,'','','','','',$uname,$udom); + $loaditems,$crumb,'','','','',$showcredits,'','', + $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{$action}[$i]) { &Apache::lonhtmlcommon::add_breadcrumb( {text=>"$trail->{$$state}"}); - $crumb = &Apache::lonhtmlcommon::breadcrumbs('Course Requests','Course_Requests'); + $crumb = &Apache::lonhtmlcommon::breadcrumbs('Course/Community Requests','Course_Requests'); last; } else { - if (($$state eq 'process') || ($$state eq 'removal')) { + if (($$state eq 'process') || ($$state eq 'removal') || ($$state eq 'reqauthor')) { &Apache::lonhtmlcommon::add_breadcrumb( { href => '/adm/requestcourse', text => "$trail->{$states->{$action}[$i]}", @@ -410,12 +468,12 @@ sub get_breadcrumbs { } else { &Apache::lonhtmlcommon::add_breadcrumb( {text=>'Pick Action'}); - $crumb = &Apache::lonhtmlcommon::breadcrumbs('Course Requests','Course_Requests'); + $crumb = &Apache::lonhtmlcommon::breadcrumbs('Course/Community Requests','Course_Requests'); } } else { &Apache::lonhtmlcommon::add_breadcrumb( {text=>'Pick Action'}); - $crumb = &Apache::lonhtmlcommon::breadcrumbs('Course Requests','Course_Requests'); + $crumb = &Apache::lonhtmlcommon::breadcrumbs('Course/Community Requests','Course_Requests'); } return ($page,$crumb,$newinstcode,$codechk,$checkedcode,$description); } @@ -442,7 +500,8 @@ sub header { } sub form_elements { - my ($dom) = @_; + my ($dom,$showcredits) = @_; + my $instcredits; my %elements = ( new => { @@ -453,6 +512,7 @@ sub form_elements { }, courseinfo => { cdescr => 'text', + cloning => 'radio', clonecrs => 'text', clonedom => 'selectbox', datemode => 'radio', @@ -509,7 +569,6 @@ sub form_elements { } if (&Apache::lonnet::auto_run('',$dom)) { my %extras = ( - sectotal => 'hidden', enrollstart_month => 'selectbox', enrollstart_hour => 'selectbox', enrollend_month => 'selectbox', @@ -525,12 +584,39 @@ sub form_elements { addcrosslist => 'checkbox', autoadds => 'radio', autodrops => 'radio', - ); - if ($env{'form.sectotal'} > 0) { - for (my $i=0; $i<$env{'form.sectotal'}; $i++) { - $extras{'sec_'.$i} = 'radio'; - $extras{'secnum_'.$i} = 'text'; - $extras{'loncapasec_'.$i} = 'text'; + ); + my ($instcode,$titlescount) = &get_instcode($dom); + if ($instcode) { + my @sections = &Apache::lonnet::auto_get_sections(undef,$dom,$instcode); + if (@sections) { + $extras{'sectotal'} = 'hidden'; + if ($env{'form.sectotal'} > 0) { + for (my $i=0; $i<$env{'form.sectotal'}; $i++) { + $extras{'sec_'.$i} = 'radio'; + $extras{'secnum_'.$i} = 'text'; + $extras{'loncapasec_'.$i} = 'text'; + } + } + } else { + $extras{'addsection'} = 'checkbox'; + my $sectotal = $env{'form.sectotal'}; + if ($env{'form.addsection'}) { + $sectotal ++; + } + for (my $i=0; $i<$sectotal; $i++) { + $extras{'sec_'.$i} = 'checkbox'; + $extras{'secnum_'.$i} = 'text', + $extras{'loncapasec_'.$i} = 'text', + } + } + (my $outcome,my $desc,$instcredits) = + &Apache::lonnet::auto_validate_instcode(undef,$dom,$instcode); + if ($showcredits && $instcredits eq '') { + $extras{'coursecredits'} = 'text'; + } + } elsif (($env{'form.crstype'} eq 'unofficial') || ($env{'form.crstype'} eq 'textbook')) { + if ($showcredits) { + $extras{'coursecredits'} = 'text'; } } my $crosslisttotal = $env{'form.crosslisttotal'}; @@ -540,7 +626,6 @@ sub form_elements { if (!$crosslisttotal) { $crosslisttotal = 1; } - for (my $i=0; $i<$env{'form.crosslisttotal'}; $i++) { if ($numtitles) { $extras{'crosslist_'.$i.'_'.$lastitem} = 'text'; @@ -578,7 +663,7 @@ sub form_elements { } my %personnelhash = (%{$elements{'new'}{'personnel'}},%people); %{$elements{'new'}{'personnel'}} = %personnelhash; - return %elements; + return (\%elements,$instcredits);; } sub onload_action { @@ -588,63 +673,19 @@ 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);'; } - } - 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; - } - } - } - } + if ($state eq 'courseinfo') { + $loaditems{'onload'} .= 'javascript:setCloneDisplay(document.requestcrs);'; } } - return $canreq; -} - -sub course_types { - my @types = ('unofficial'); - my %typename = ( - official => 'Official course', - unofficial => 'Unofficial course', - community => 'Community', - ); - return (\@types,\%typename); + return \%loaditems; } - sub print_main_menu { - my ($r,$can_request,$states,$dom,$jscript,$loaditems,$crumb) = @_; - my ($types,$typename) = &course_types(); - my $onchange; - unless ($env{'form.interface'} eq 'textual') { - $onchange = 1; - } - + my ($r,$can_request,$states,$dom,$jscript,$loaditems,$crumb,$request_domains) = @_; + my ($types,$typename) = &Apache::loncommon::course_types(); + my $onchange = 'this.form.submit()'; my $nextstate_setter = "\n"; if (ref($states) eq 'HASH') { foreach my $key (keys(%{$states})) { @@ -658,31 +699,8 @@ sub print_main_menu { } } - my $standby=&mt('Course selected. Please stand by.'); my $js = <<"END"; -function enterrole (thisform,rolecode,buttonname) { - document.title='$standby'; - window.status='$standby'; - thisform.newrole.value=rolecode; - thisform.selectrole.value='1'; - thisform.submit(); -} - -function ToSyllabus(cdom,cnum) { - if (cdom == '' || cdom == null) { - return; - } - if (cnum == '' || cnum == null) { - return; - } - var options = 'height=600,width=800,resizable=yes,scrollbars=yes,location=no,menubar=no,toolbar=no'; - var url = "/public/"+cdom+"/"+cnum+"/syllabus"; - syllwin = window.open(url,'',options,1); - syllwin.focus(); - return; -} - function nextPage(formname) { var crschoice = document.mainmenu_coursetype.crstype.value; var actionchoice = document.mainmenu_action.action.value; @@ -703,19 +721,23 @@ $nextstate_setter function check_can_request(crschoice,actionchoice) { var official = ''; var unofficial = ''; - var community = ''; + var community = ''; + var textbook = ''; 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.', 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.', + community => 'You are not permitted to request creation of a community in this domain.', + textbook => 'You are not permitted to request creation of a textbook course in this domain', + all => 'You must choose a specific course type when making a new course request.', + allt => '"All types" is not allowed.', ); $js .= <print(&header('Concept Test Courses',$js.$jscript,$loaditems).$crumb); - my $existing = &existing_courses(); - if ($existing) { - $r->print('
'. - '

'.&mt('Request creation of a new course').'

'); - } else { - $r->print('

'.&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'}) || $can_request->{'textbook'}) { + 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 = 'Community Requests'; + $pageinfo = &mt('Request creation of a new course, 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('

'. + $r->print(&header($pagetitle,$js.$jscript,$loaditems).$crumb. + '

'.$pageinfo.'

'. + '
'. &Apache::lonhtmlcommon::start_pick_box(). - &Apache::lonhtmlcommon::row_title(&mt('Course Domain')). - '
'); - $r->print('GCI Web Center Concept Test Delivery (gcitest)'."\n". - ''); + &Apache::lonhtmlcommon::row_title($domaintitle). + ''. + &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')).' @@ -770,217 +834,53 @@ END '. - &Apache::lonhtmlcommon::row_closure(1). - &Apache::lonhtmlcommon::row_title(&mt('Course Type')). - &mt($typename->{'unofficial'})."\n". - '
'."\n". - '
'."\n". + &Apache::lonhtmlcommon::row_closure(). + &Apache::lonhtmlcommon::row_title(&mt('Type')).' +
+
'."\n". &Apache::lonhtmlcommon::row_closure(1)."\n". - &Apache::lonhtmlcommon::end_pick_box().'

'."\n". - '

'."\n". + &Apache::lonhtmlcommon::end_pick_box().'
'."\n". + '
'."\n". ''."\n". ''."\n". ''."\n". ''."\n". ''."\n". - '

'); - if ($existing) { - $r->print('

'.&mt('Enter an existing Concept Test course').'

'.$existing.'
'); - } else { - $r->print('
'); - } + ''); $r->print(&Apache::loncommon::end_page()); return; } -sub existing_courses { - my $output; - my %roleshash = &Apache::lonnet::get_my_roles(undef,undef,'userroles',undef, - ['cc'],['gcitest']); - my %courses; - if (keys(%roleshash) > 0) { - foreach my $key (keys(%roleshash)) { - my ($cnum,$cdom,$role) = split(':',$key); - my ($tstart,$tend) = split(':',$roleshash{$key}); - my %coursehash = &Apache::lonnet::coursedescription($cdom.'/'.$cnum); - $courses{$cdom.'_'.$cnum}{'description'} = $coursehash{'description'}; - $courses{$cdom.'_'.$cnum}{'owner'} = $coursehash{'internal.courseowner'}; - if (defined($coursehash{'default_enrollment_start_date'}) ) { - $courses{$cdom.'_'.$cnum}{'startaccess'} = - &Apache::lonlocal::locallocaltime($coursehash{'default_enrollment_start_date'}); - } - if (defined($coursehash{'default_enrollment_end_date'}) ) { - $courses{$cdom.'_'.$cnum}{'endaccess'} = - &Apache::lonlocal::locallocaltime($coursehash{'default_enrollment_end_date'}); - if ($coursehash{'default_enrollment_end_date'} == 0) { - $courses{$cdom.'_'.$cnum}{'endaccess'} = &mt('No ending date'); - } - } - } - $output = '
'. - &Apache::loncommon::start_data_table(). - &Apache::loncommon::start_data_table_header_row(); - my @coltitles = ('Select','Title','Owner(s)', - 'Default Access Dates for Students','Student Counts'); - foreach my $item (@coltitles) { - $output .= ''; - if ($item eq 'Select') { - $output .= '  '; - } else { - $output .= &mt($item); - } - $output .= ''; - } - $output .= &Apache::loncommon::end_data_table_header_row(); - my %courseinfo = &build_courseinfo_hash(\%courses); - my %Sortby; - foreach my $course (sort(keys(%courses))) { - my $clean_title = $courseinfo{$course}{'title'}; - $clean_title =~ s/\W+//g; - if ($clean_title eq '') { - $clean_title = $courseinfo{$course}{'title'}; - } - push(@{$Sortby{$clean_title}},$course); - } - my @sorted_courses; - my @sorted_courses = sort { lc($a) cmp lc($b) } (keys(%Sortby)); - foreach my $item (@sorted_courses) { - foreach my $course (@{$Sortby{$item}}) { - my ($cdom,$cnum) = split('_',$course); - $output.= &Apache::loncommon::start_data_table_row(). - &courseinfo_row($courseinfo{$course},$cnum,$cdom). - &Apache::loncommon::end_data_table_row(); - } - } - $output .= &Apache::loncommon::end_data_table(). - ''. - '
'; - } - return $output; -} - -sub build_courseinfo_hash { - my ($courses) = @_; - my %courseinfo; - foreach my $course (keys(%{$courses})) { - my ($cdom,$cnum) = split('_',$course); - my $descr; - if (ref($courses->{$course}) eq 'HASH') { - $descr = $courses->{$course}{'description'}; - } - my $cleandesc=&HTML::Entities::encode($descr,'<>&"'); - $cleandesc=~s/'/\\'/g; - $cleandesc =~ s/^\s+//; - my ($cdom,$cnum)=split(/\_/,$course); - my ($singleowner,@owners,%ownernames); - if (ref($courses->{$course}) eq 'HASH') { - $singleowner = $courses->{$course}{'owner'}; - push(@owners,$singleowner); - if (ref($courses->{$course}{'co-owners'}) eq 'ARRAY') { - foreach my $item (@{$courses->{$course}{'co-owners'}}) { - push(@owners,$item); - } - } - } - foreach my $owner (@owners) { - my ($ownername,$ownerdom); - if ($owner =~ /:/) { - ($ownername,$ownerdom) = split(/:/,$owner); - } else { - $ownername = $owner; - if ($owner ne '') { - $ownerdom = $cdom; - } - } - if ($ownername ne '' && $ownerdom ne '') { - my %namehash=&Apache::loncommon::getnames($ownername,$ownerdom); - $ownernames{$ownername.':'.$ownerdom} = \%namehash; - } - } - $courseinfo{$course}{'cdom'} = $cdom; - $courseinfo{$course}{'cnum'} = $cnum; - my @lastnames; - foreach my $owner (keys(%ownernames)) { - if (ref($ownernames{$owner}) eq 'HASH') { - push(@lastnames,$ownernames{$owner}{'lastname'}); - } - } - $courseinfo{$course}{'ownerlastnames'} = join(', ',sort(@lastnames)); - $courseinfo{$course}{'title'} = $cleandesc; - $courseinfo{$course}{'owner'} = $singleowner; - my @classids; - $courseinfo{$course}{'counts'} = &count_students($cdom,$cnum,0); - my $startaccess = $courses->{$course}{'startaccess'}; - my $endaccess = $courses->{$course}{'endaccess'}; - my $accessdates; - if ($startaccess) { - $accessdates .= ''.&mt('From:[_1]',' '.$startaccess).'
'; - } - if ($endaccess) { - $accessdates .= ''.&mt('To:[_1]',' '.$endaccess).'
'; - } - $courseinfo{$course}{'access'} = $accessdates; - } - return %courseinfo; -} - -sub courseinfo_row { - my ($info,$cnum,$cdom) = @_; - my $output; - if (ref($info) eq 'HASH') { - my $rolecode = 'cc./'.$cdom.'/'.$cnum; - my $buttonname = $rolecode; - $buttonname=~s/\W//g; - $output .= ''. - ''.$info->{'title'}.' '. - ''. - &mt('Syllabus').''. - ''.$info->{'ownerlastnames'}.''. - ''.$info->{'access'}.''. - ''.$info->{'counts'}.''; - } else { - $output = ''.&mt('No information available for [_1].', - $cdom.'_'.$cnum).''; - return $output; - } - return $output; -} - -sub count_students { - my ($cdom,$cnum,$numsec) = @_; - my $classlist = &Apache::loncoursedata::get_classlist($cdom,$cnum); - my %student_count = ( - Active => 0, - Future => 0, - Expired => 0, - ); - my %idx; - $idx{'status'} = &Apache::loncoursedata::CL_STATUS(); - my %status_title = &Apache::lonlocal::texthash( - Expired => 'Previous access', - Active => 'Current access', - Future => 'Future access', - ); - - while (my ($student,$data) = each(%$classlist)) { - $student_count{$data->[$idx{'status'}]} ++; - } - - my $countslist = &mt('[quant,_1,section:,sections:,No sections]',$numsec).'
'; - foreach my $status ('Active','Future') { - $countslist .= ''.$status_title{$status}.': '. - $student_count{$status}.'
'; - } - return $countslist; -} - - sub request_administration { my ($r,$action,$state,$page,$states,$dom,$jscript,$loaditems,$crumb, - $newinstcode,$codechk,$checkedcode,$description,$invalidcrosslist, - $uname,$udom) = @_; + $newinstcode,$codechk,$checkedcode,$description,$showcredits, + $instcredits,$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); + my $title; + if ($env{'form.crstype'} eq 'community') { + $title = 'Request a community'; + } else { + $title = 'Request a course'; + } + $r->print(&header($title,$js.$jscript,$loaditems,$jsextra).$crumb); &print_request_form($r,$action,$state,$page,$states,$dom,$newinstcode, - $codechk,$checkedcode,$description,$invalidcrosslist); + $codechk,$checkedcode,$description,$showcredits, + $instcredits,$invalidcrosslist); } elsif ($action eq 'view') { my $jsextra; my $formname = 'requestcrs'; @@ -1031,12 +938,29 @@ END } elsif ($state eq 'cancel') { $jsextra = &viewcancel_javascript($formname); } - $r->print(&header('Manage course requests',$js.$jscript.$jsextra,$loaditems). - $crumb); + my $title; + if ($env{'form.crstype'} eq 'community') { + $title = 'Manage community requests'; + } else { + $title = 'Manage course requests'; + } + $r->print(&header($title,$js.$jscript.$jsextra,$loaditems).$crumb); my $form = '
'; if ($state eq 'pick_request') { - $r->print('

'.&mt('Pending course requests').'

'."\n".$form."\n". - &print_request_status($dom).'
'); + my $title; + if ($env{'form.crstype'} eq 'community') { + $title = &mt('Pending community requests'); + } elsif ($env{'form.crstype'} eq 'official') { + $title = &mt('Pending requests for official courses'); + } elsif ($env{'form.crstype'} eq 'unofficial') { + $title = &mt('Pending requests for unofficial courses'); + } elsif ($env{'form.crstype'} eq 'textbook') { + $title = &mt('Pending requests for textbook courses'); + } else { + $title = &mt('Pending course/community requests'); + } + $r->print('

'.$title.'

'."\n".$form."\n". + &print_request_status($dom,$action).'
'); } elsif ($state eq 'details') { my (@codetitles,%cat_titles,%cat_order,@code_order,$instcode,$code_chk); my $origcnum = $env{'form.cnum'}; @@ -1047,11 +971,18 @@ END &Apache::lonnet::auto_possible_instcodes($dom,\@codetitles,\%cat_titles, \%cat_order,\@code_order); } - $r->print('

'.&mt('Course Request Details').'

'."\n".$form."\n". + my $title; + if ($env{'form.crstype'} eq 'community') { + $title = &mt('Community Request Details'); + } else { + $title = &mt('Course Request Details'); + } + $r->print('

'.$title.'

'."\n".$form."\n". &print_review($dom,\@codetitles,\%cat_titles,\%cat_order, - \@code_order)."\n". + \@code_order,'','','','',$instcredits)."\n". ''."\n"); - my @excluded = &get_excluded_elements($dom,$states,'new','review'); + my @excluded = &get_excluded_elements($dom,$states,'new','review', + $showcredits); push(@excluded,'origcnum'); $r->print(&Apache::lonhtmlcommon::echo_form_input(\@excluded).'
'); my $other = 'modify'; @@ -1064,10 +995,17 @@ END $navtxt{'next'},$state,$other,$navtxt{'other'}); $r->print(''); } elsif ($state eq 'cancel') { + my $title; + if ($env{'form.crstype'} eq 'community') { + $title = &mt('Cancel community request'); + } else { + $title = &mt('Cancel course request'); + } my ($result,$output) = &print_cancel_request($dom,$env{'form.origcnum'}); - $r->print('

'.&mt('Cancel course request').'

'."\n".$form."\n". + $r->print('

'.$title.'

'."\n".$form."\n". $output); - my @excluded = &get_excluded_elements($dom,$states,'view','cancel'); + my @excluded = &get_excluded_elements($dom,$states,'view','cancel', + $showcredits); $r->print(&Apache::lonhtmlcommon::echo_form_input(\@excluded).'
'); my %navtxt = &Apache::lonlocal::texthash ( prev => 'Back', @@ -1114,7 +1052,11 @@ END ''."\n". ''."\n"); if ($result eq 'ok') { - $r->print(&mt('Your course request has been cancelled.')); + if ($env{'form.crstype'} eq 'community') { + $r->print(&mt('Your community request has been cancelled.')); + } else { + $r->print(&mt('Your course request has been cancelled.')); + } } else { $r->print('
'. &mt('The request cancellation process was not complete.'). @@ -1129,13 +1071,20 @@ END &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').'

'. + my ($title,$header); + if ($env{'form.crstype'} eq 'community') { + $title = 'Community Request'; + $header = &mt('Community Request'); + } else { + $title = 'Course Request'; + $header = &mt('Course Request'); + } + $r->print(&header($title,'','','',{ 'only_body' => 1}). + $crumb."\n".'

'.$header.'

'. &print_review($dom,\@codetitles,\%cat_titles,\%cat_order, - \@code_order,$uname,$udom)."\n".'
'. + \@code_order,$uname,$udom,'','',$instcredits)."\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; @@ -1328,7 +1277,7 @@ sub get_instcode { sub print_request_form { my ($r,$action,$state,$page,$states,$dom,$newinstcode,$codechk,$checkedcode, - $description,$invalidcrosslist) = @_; + $description,$showcredits,$instcredits,$invalidcrosslist) = @_; my $formname = 'requestcrs'; my ($next,$prev,$message,$output,$codepicker,$crstype); $prev = $states->{$action}[$page-1]; @@ -1401,7 +1350,7 @@ sub print_request_form { } $r->print(&print_enrollment_menu($formname,$instcode,$dom,\@codetitles, \%cat_titles,\%cat_order,\@code_order, - $invalidcrosslist)); + $showcredits,$instcredits,$invalidcrosslist)); } elsif ($state eq 'personnel') { $r->print(&print_personnel_menu($dom,$formname,$crstype,$invalidcrosslist)); } elsif ($state eq 'review') { @@ -1427,16 +1376,38 @@ sub print_request_form { } if ($skipuser) { push(@disallowed,$i); - $disallowmsg{$i} = &mt('[_1] was excluded because new users need be from the course domain',''.$personname.':'.$persondom.''); + $disallowmsg{$i} = &mt('[_1] was excluded because new users need to be from the course domain',''.$personname.':'.$persondom.''); next; } } - if (&get_cancreate_status($persondom,$personname,$dom)) { - my ($allowed,$msg) = + my $usertype = &get_usertype($persondom,$personname,\%curr_rules,\%got_rules); + if (&Apache::lonuserutils::can_create_user($dom,'requestcrs',$usertype)) { + my ($allowed,$msg,$authtype,$authparam) = &check_newuser_rules($persondom,$personname, \%alerts,\%rulematch,\%inst_results, \%curr_rules,\%got_rules); if ($allowed) { + my %domdefaults = &Apache::lonnet::get_domain_defaults($persondom); + if ($usertype eq 'official') { + if ($authtype eq '') { + $authtype = $domdefaults{'auth_def'}; + $authparam = $domdefaults{'auth_arg_def'}; + } + } elsif ($usertype eq 'unofficial') { + if ($authtype eq '') { + $authtype = 'internal'; + $authparam = ''; + } + } else { + $authtype = $domdefaults{'auth_def'}; + $authparam = $domdefaults{'auth_arg_def'}; + } + if (($authtype eq '') || + (($authtype =~/^krb/) && ($authparam eq ''))) { + push(@disallowed,$i); + $disallowmsg{$i} = &mt('[_1] was excluded because institutional information is incomplete for this new user.',''.$personname.':'.$persondom.''); + next; + } if (ref($inst_results{$personname.':'.$persondom}) eq 'HASH') { if ($inst_results{$personname.':'.$persondom}{'lastname'} ne '') { $env{'form.person_'.$i.'_lastname'} = $inst_results{$personname.':'.$persondom}{'lastname'}; @@ -1482,33 +1453,103 @@ 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); - $r->print('

'.&mt('Review course request details before submission').'

'. - &print_review($dom,\@codetitles,\%cat_titles,\%cat_order,\@code_order,'','',\@disallowed,\%disallowmsg). + if ($crstype eq 'community') { + $r->print('

'.&mt('Review community request details before submission').'

'); + } else { + $r->print('

'.&mt('Review course request details before submission').'

'); + } + $r->print(&print_review($dom,\@codetitles,\%cat_titles,\%cat_order,\@code_order,'','',\@disallowed,\%disallowmsg,$instcredits). ''); - $navtxt{'next'} = &mt('Submit course request'); + if ($crstype eq 'community') { + $navtxt{'next'} = &mt('Submit community request'); + } else { + $navtxt{'next'} = &mt('Submit course request'); + } } elsif ($state eq 'process') { if ($crstype eq 'official') { &Apache::lonnet::auto_possible_instcodes($dom,\@codetitles,\%cat_titles, \%cat_order,\@code_order); } my ($storeresult,$result) = &print_request_outcome($dom,\@codetitles, - \@code_order); + \@code_order,$instcredits); $r->print($result); if (($storeresult eq 'ok') || ($storeresult eq 'created')) { - $r->print('

'); if ($storeresult eq 'ok') { - $r->print(''. - &mt('Modify this request').''.(' 'x4)); + $r->print('

'. + &mt('Modify this request').''.(' 'x4). + ''.&mt('Make another request').'

'); + } + if (&Apache::loncoursequeueadmin::author_prompt()) { + $r->print('

'.&mt('Access to authoring space').'

'. + '

'. + &mt('Although assessment items can be created directly inside a course, such items only use part of the assessment capabilities of LON-CAPA.'). + '
'. + &mt('By contrast, items created in authoring space, then imported into a course, can use all of the features of the assessment engine.').'

'. + '

'.&mt('Request authoring space access now?'). + ' '. + ''. + (' 'x2). + ''. + '

'. + ''. + ''. + ''. + ''. + ''. + ''. + ''. + '
'); + } elsif ($storeresult eq 'created') { + $r->print('

'.&mt('Make another request').'

'); + } + } + } elsif ($state eq 'reqauthor') { + my ($result,@links); + if ($env{'form.requestauthor'}) { + $r->print(&Apache::loncoursequeueadmin::process_reqauthor(\$result)); + if ($result eq 'created') { + my $role = 'au'; + my $spec = "$role./$env{'form.showdom'}/"; + push(@links,&mt('Enter your authoring space with role: [_1]', + ''. + &Apache::lonnet::plaintext($role).'')); } - $r->print(''.&mt('Make another request').'

'); - return; + } + if (($env{'form.disposition'} eq 'created') && + ($env{'form.cnum'} =~ /^$match_courseid$/) && + ($env{'form.showdom'} =~ /^$match_domain$/)) { + my ($spec,$area,$role,$type); + my $role = 'cc'; + my $spec = "$role./$env{'form.showdom'}/$env{'form.cnum'}"; + my $type = 'Course'; + if ($env{'form.crstype'} eq 'community') { + $type = 'Community'; + } + my $showrole = &Apache::lonnet::plaintext($role,$type); + unshift(@links,&mt('Enter new course with role: [_1]', + ''.$showrole.'')); + } + if (@links > 1) { + $r->print(&mt('New roles will be listed on your [_1]Roles[_2] page.', + '','').' '.&mt('Choose a role:'). + '
    '); + foreach my $link (@links) { + $r->print('
  • '.$link.'
  • '); + } + $r->print('
'); + } elsif (@links == 1) { + $r->print('

'.$links[0].'

'); } } - my @excluded = &get_excluded_elements($dom,$states,$action,$state); + my @excluded = &get_excluded_elements($dom,$states,$action,$state,$showcredits); if ($state eq 'personnel') { push(@excluded,'persontotal'); } @@ -1535,25 +1576,28 @@ sub print_request_form { $count ++; } $env{'form.persontotal'} = $count; - } } if ($state eq 'enrollment') { - push(@excluded,'crosslisttotal'); + push(@excluded,('sectotal','crosslisttotal')); + } + if (($state eq 'process') || ($state eq 'reqauthor')) { + $r->print(''); + } else { + $r->print(&Apache::lonhtmlcommon::echo_form_input(\@excluded).''); + &display_navbuttons($r,$dom,$formname,$prev,$navtxt{'prev'},$next, + $navtxt{'next'},$state); } - $r->print(&Apache::lonhtmlcommon::echo_form_input(\@excluded).''); - &display_navbuttons($r,$dom,$formname,$prev,$navtxt{'prev'},$next, - $navtxt{'next'},$state); return; } -sub get_cancreate_status { - my ($persondom,$personname,$dom) = @_; +sub get_usertype { + my ($persondom,$personname,$curr_rules,$got_rules) = @_; my ($rules,$ruleorder) = &Apache::lonnet::inst_userrules($persondom,'username'); my $usertype = &Apache::lonuserutils::check_usertype($persondom,$personname, - $rules); - return &Apache::lonuserutils::can_create_user($dom,'requestcrs',$usertype); + $rules,$curr_rules,$got_rules); + return $usertype; } sub check_newuser_rules { @@ -1561,7 +1605,7 @@ sub check_newuser_rules { $got_rules) = @_; my $allowed = 1; my $newuser = 1; - my ($checkhash,$userchkmsg); + my ($checkhash,$userchkmsg,$authtype,$authparam); my $checks = { 'username' => 1 }; $checkhash->{$personname.':'.$persondom} = { 'newuser' => $newuser }; &Apache::loncommon::user_rule_check($checkhash,$checks,$alerts,$rulematch, @@ -1583,22 +1627,38 @@ sub check_newuser_rules { } } } - return ($allowed,$userchkmsg); + if ($allowed) { + if (ref($rulematch) eq 'HASH') { + if (ref($rulematch->{$personname.':'.$persondom}) eq 'HASH') { + my $matchedrule = $rulematch->{$personname.':'.$persondom}{'username'}; + my ($rules,$ruleorder) = + &Apache::lonnet::inst_userrules($persondom,'username'); + if (ref($rules) eq 'HASH') { + if (ref($rules->{$matchedrule}) eq 'HASH') { + $authtype = $rules->{$matchedrule}{'authtype'}; + $authparam = $rules->{$matchedrule}{'authparm'}; + } + } + } + } + } + return ($allowed,$userchkmsg,$authtype,$authparam); } sub get_excluded_elements { - my ($dom,$states,$action,$state) = @_; + my ($dom,$states,$action,$state,$showcredits) = @_; my @excluded = ('counter'); - my %elements = &form_elements($dom); + my ($elements,$instcredits) = &form_elements($dom,$showcredits); if (ref($states) eq 'HASH') { if (ref($states->{$action}) eq 'ARRAY') { my @items = @{$states->{$action}}; my $numitems = scalar(@items); if ($numitems) { for (my $i=$numitems-1; $i>=0; $i--) { - if (ref($elements{$action}) eq 'HASH') { - if (ref($elements{$action}{$items[$i]}) eq 'HASH') { - foreach my $key (keys(%{$elements{$action}{$items[$i]}})) { + if ((ref($elements) eq 'HASH') && + (ref($elements->{$action}) eq 'HASH')) { + if (ref($elements->{$action}{$items[$i]}) eq 'HASH') { + foreach my $key (keys(%{$elements->{$action}{$items[$i]}})) { push(@excluded,$key); } } @@ -1616,8 +1676,9 @@ 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,$hasauto); + $showcredits,$instcredits,$invalidcrosslist) =@_; + my ($sections,$autoenroll,$access_dates,$output,$hasauto,$hascredits, + $creditsrow,$domdefcredits); my $starttime = time; my $endtime = time+(6*30*24*60*60); # 6 months from now, approx @@ -1629,11 +1690,39 @@ sub print_enrollment_menu { 'start' => 'Start auto-enrollment', 'end' => 'End auto-enrollment', ); + if ($showcredits) { + unless ($env{'form.crstype'} eq 'community') { + my %domdefs = &Apache::lonnet::get_domain_defaults($dom); + $domdefcredits = $domdefs{$env{'form.crstype'}.'credits'}; + } + } if ($env{'form.crstype'} eq 'official') { if (&Apache::lonnet::auto_run('',$dom)) { $output = &show_invalid_crosslists($invalidcrosslist); my ($section_form,$crosslist_form); - $section_form = &inst_section_selector($dom,$instcode); + if ($instcode ne '') { + $section_form = &inst_section_selector($dom,$instcode); + if ($section_form eq '') { + my $sectotal = $env{'form.sectotal'}; + if (!$sectotal) { + $sectotal = 1; + } + if ($env{'form.addsection'}) { + $sectotal ++; + } + for (my $i=0; $i<$sectotal; $i++) { + $section_form .= §ions_form($dom,$instcode,$i); + } + if ($section_form) { + $section_form .= + &Apache::lonhtmlcommon::row_title(&mt('Add another')). + ''. + ''.&mt('Add?').&Apache::lonhtmlcommon::row_closure(); + } + } + } if ($section_form) { $sections = &Apache::lonhtmlcommon::row_headline(). '

'.&Apache::loncommon::help_open_topic('Course_Request_Sections'). @@ -1654,13 +1743,13 @@ sub print_enrollment_menu { } if ($crosslist_form) { $crosslist_form .= - &Apache::lonhtmlcommon::row_title(&mt('Add another?')). + &Apache::lonhtmlcommon::row_title(&mt('Add another')). ''. ''.&mt('Add?').&Apache::lonhtmlcommon::row_closure(); $sections .= &Apache::lonhtmlcommon::row_headline. - '

'.&mt('Crosslisted courses for auto-enrollment').'

'. + '

'.&Apache::loncommon::help_open_topic('Course_Request_Crosslist').' '.&mt('Crosslisted courses for auto-enrollment').'

'. &Apache::lonhtmlcommon::row_closure(1). $crosslist_form; } @@ -1681,12 +1770,29 @@ sub print_enrollment_menu { &mt('No').''. &Apache::lonhtmlcommon::row_closure(1). &date_setting_table($starttime,$endtime,$formname,'enroll', - $hasauto,%enrolltitles); + $hasauto,undef,%enrolltitles); + if ($showcredits) { + if ($instcredits) { + $creditsrow = &mt('[quant,_1,credit]',$instcredits); + } else { + $creditsrow = ''. + ''; + } + $hascredits = 1; + } + } + } elsif (($env{'form.crstype'} eq 'unofficial') || ($env{'form.crstype'} eq 'textbook')) { + if ($showcredits) { + $creditsrow = ''. + ''; + $hascredits = 1; } } my $access_dates = &date_setting_table($starttime,$endtime,$formname,'access',$hasauto, - %accesstitles); + $hascredits,%accesstitles); $output .= &Apache::lonhtmlcommon::start_pick_box(); if ($sections) { $output .= $sections; @@ -1705,7 +1811,15 @@ sub print_enrollment_menu { $output .= &Apache::lonhtmlcommon::row_headline('Access'). '

'.$header.'

'. &Apache::lonhtmlcommon::row_closure(1). - $access_dates + $access_dates; + } + if ($creditsrow) { + $output .= &Apache::lonhtmlcommon::row_headline('Credits'). + '

'.&mt('Credits earned by students').'

'. + &Apache::lonhtmlcommon::row_closure(1). + &Apache::lonhtmlcommon::row_title(&mt('Default credits')). + $creditsrow. + &Apache::lonhtmlcommon::row_closure(1); } return '
'.&Apache::lonhtmlcommon::start_pick_box().$output. &Apache::lonhtmlcommon::end_pick_box().'
'; @@ -1770,7 +1884,7 @@ sub inst_section_selector { } sub date_setting_table { - my ($starttime,$endtime,$formname,$prefix,$hasauto,%datetitles) = @_; + my ($starttime,$endtime,$formname,$prefix,$hasauto,$hascredits,%datetitles)=@_; my ($perpetual,$table); my $startform = &Apache::lonhtmlcommon::date_setter($formname,$prefix.'start', $starttime,'','','',1,'','','',1); @@ -1781,7 +1895,9 @@ sub date_setting_table { $perpetual = ' '; - $closure = '1'; + unless ($hascredits) { + $closure = '1'; + } } my %help_item = ( @@ -1800,10 +1916,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; } @@ -1826,12 +1942,12 @@ sub print_personnel_menu { } my @items = ('uname','dom','lastname','firstname','emailaddr','hidedom'); - my $roleoptions; - my @roles = &Apache::lonuserutils::roles_by_context('course'); my $type = 'Course'; if ($crstype eq 'community') { $type = 'Community'; } + my $roleoptions; + my @roles = &Apache::lonuserutils::roles_by_context('course','',$type); foreach my $role (@roles) { my $plrole = &Apache::lonnet::plaintext($role,$type); $roleoptions .= ' '."\n"; @@ -1871,6 +1987,7 @@ sub print_personnel_menu { official => 'Requestor is automatically assigned Course Coordinator role.', ); $lt{'unofficial'} = $lt{'official'}; + $lt{'textbook'} = $lt{'textbook'}; $output .= &Apache::lonhtmlcommon::row_headline(). '

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

'; } @@ -1919,13 +2036,17 @@ sub print_personnel_menu { &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?')). + $output .= &Apache::lonhtmlcommon::row_title(&mt('Add another')). ''. ''.&mt('Add?').&Apache::lonhtmlcommon::row_closure(1). - &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".').'

'; + &Apache::lonhtmlcommon::end_pick_box().''; + if ($crstype eq 'community') { + $output .= '

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

'; + } else { + $output .= '

'.&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; } @@ -1946,61 +2067,111 @@ 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 ($types,$typenames) = &course_types(); + 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". ''."\n". ''."\n"; if (@sortedtimes > 0) { + my $desctitle; + if ($env{'form.crstype'} eq 'any') { + $desctitle = &mt('Course/Community Description') + } elsif ($env{'form.crstype'} eq 'community') { + $desctitle = &mt('Community Description') + } else { + $desctitle = &mt('Course Description'); + } $output .= &Apache::loncommon::start_data_table(). &Apache::loncommon::start_data_table_header_row(). ''.&mt('Action').''. - ''.&mt('Course Description').''. + ''.$desctitle.''. ''.&mt('Domain').''; if ($env{'form.crstype'} eq 'any') { $output .= ''.&mt('Type').''; @@ -2048,7 +2219,13 @@ sub print_request_status { } $output .= &Apache::loncommon::end_data_table(); } else { - $output .= '
'.&mt('You have no matching course requests awaiting approval by a Domain Coordinator or held in a queue pending administrative action at your institution.').'
'; + if ($env{'form.crstype'} eq 'any') { +$output .= '
'.&mt('You have no matching course or community requests awaiting approval by a Domain Coordinator or held in a queue pending administrative action at your institution.').'
'; + } elsif ($env{'form.crstype'} eq 'community') { + $output .= '
'.&mt('You have no matching community requests awaiting approval by a Domain Coordinator or held in a queue pending administrative action at your institution.').'
'; + } else { + $output .= '
'.&mt('You have no matching course requests awaiting approval by a Domain Coordinator or held in a queue pending administrative action at your institution.').'
'; + } } $output .= '
'; @@ -2073,7 +2250,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}; @@ -2089,8 +2266,12 @@ sub print_cancel_request { ''.$showtype.''. &Apache::loncommon::end_data_table_row(). &Apache::loncommon::end_data_table(). - '
'. - &mt('Cancelling the request will remove it from the queue of pending course requests').'
'; + '
'; + if ($crstype eq 'community') { + $output .= &mt('Cancelling the request will remove it from the queue of pending community requests').'
'; + } else { + $output .= &mt('Cancelling the request will remove it from the queue of pending course requests').''; + } $result = 'ok'; } else { $output = '
'.&mt('No record exists for the course ID').'
'; @@ -2137,8 +2318,8 @@ ENDJS } sub viewcancel_javascript { - my $alert = &mt('Are you sure you want to cancel this request?\\n'. - 'Your request will be removed.'); + my $alert = &mt('Are you sure you want to cancel this request?').'\\n'. + &mt('Your request will be removed.'); return << "ENDJS"; function nextPage(formname,nextstate) { if (confirm('$alert')) { @@ -2152,14 +2333,295 @@ 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('
'."\n". + ''."\n". + ''."\n"); + # set defaults + my $now = time(); + my $defstart = $now - (7*24*3600); #7 days ago + my %defaults = ( + page => '1', + show => '10', + crstype => 'any', + status => 'any', + requested_before_date => $now, + requested_after_date => $defstart, + ); + my ($types,$typenames) = &Apache::loncommon::course_types(); + my $more_records = 0; + my %curr; + foreach my $item ('show','page','crstype','status') { + $curr{$item} = $env{'form.'.$item}; + } + $curr{'requested_after_date'} = &Apache::lonhtmlcommon::get_date_from_form('requested_after_date'); + $curr{'requested_before_date'} = &Apache::lonhtmlcommon::get_date_from_form('requested_before_date'); + foreach my $key (keys(%defaults)) { + if ($curr{$key} eq '') { + $curr{$key} = $defaults{$key}; + } + } + my ($statuses,$statusnames) = &reqstatus_names($curr{'crstype'}); + $r->print(''. + &requestlog_display_filter($formname,\%curr)); + my %queue_by_date = &sorted_request_history($dom,$env{'form.action'},\%curr); + my @sortedtimes = sort {$a <=> $b} (keys(%queue_by_date)); + my $showntablehdr = 0; + my $tablehdr = &Apache::loncommon::start_data_table(). + &Apache::loncommon::start_data_table_header_row(). + ' '.&mt('Request Date').''. + ''.&mt('Description').''; + if ($curr{'crstype'} eq 'any') { + $tablehdr .= ''.&mt('Course Type').''; + } + if (($curr{'crstype'} eq 'official') || ($curr{'crstype'} eq 'any')) { + $tablehdr .= ''.&mt('Institutional Code').''; + } + if ($curr{'status'} eq 'any') { + $tablehdr .= ''.&mt('Status').''; + } elsif ($curr{'status'} eq 'created') { + $tablehdr .= ''.&mt('Creation Date').''; + } elsif ($curr{'status'} eq 'cancelled') { + $tablehdr .= ''.&mt('Cancellation Date').''; + } elsif ($curr{'status'} eq 'rejected') { + $tablehdr .= ''.&mt('Rejection Date').''; + } + $tablehdr .= &Apache::loncommon::end_data_table_header_row(); + my ($minshown,$maxshown); + $minshown = 1; + my $count = 0; + if ($curr{'show'} ne &mt('all')) { + $maxshown = $curr{'page'} * $curr{'show'}; + if ($curr{'page'} > 1) { + $minshown = 1 + ($curr{'page'} - 1) * $curr{'show'}; + } + } + my $norecords; + if (@sortedtimes > 0) { + foreach my $item (@sortedtimes) { + if ($curr{'show'} ne &mt('all')) { + if ($count >= $curr{'page'} * $curr{'show'}) { + $more_records = 1; + last; + } + } + $count ++; + next if ($count < $minshown); + if (!$showntablehdr) { + $r->print($tablehdr); + $showntablehdr = 1; + } + my $showtime = &Apache::lonlocal::locallocaltime($item); + if (ref($queue_by_date{$item}) eq 'ARRAY') { + foreach my $request (sort(@{$queue_by_date{$item}})) { + my ($key,$crstype,$desc,$timestamp,$status,$instcode) = split(':',$request); + my ($cdom,$cnum) = split('_',$key); + my $output = &Apache::loncommon::start_data_table_row(). + ''.$count.''. + ''.$showtime.''. + ''.&unescape($desc).''; + if ($curr{'crstype'} eq 'any') { + my $typename; + if (ref($typenames) eq 'HASH') { + $typename = &mt($typenames->{$crstype}); + } + if ($typename eq '') { + $typename = &mt('Unknown type'); + } + $output .= ''.$typename.''; + } + if (($curr{'crstype'} eq 'any') || + ($curr{'crstype'} eq 'official')) { + my $showinstcode; + if ($crstype eq 'official') { + $showinstcode = &unescape($instcode); + } else { + $showinstcode = &mt('Not applicable'); + } + $output .= ''.$showinstcode.''; + } + if ($curr{'status'} eq 'any') { + my $statusname = &mt('Unknown status'); + if (ref($statusnames) eq 'HASH') { + if ($statusnames->{$status} ne '') { + $statusname = $statusnames->{$status}; + } + } + if (($status eq 'created') || ($status eq 'cancelled') || + ($status eq 'rejected')) { + $statusname .= ' '.&Apache::lonlocal::locallocaltime($timestamp); + } + $output .= ''.$statusname.''; + } elsif (($status eq 'created') || ($status eq 'cancelled') || + ($status eq 'rejected')) { + $output .= ''.&Apache::lonlocal::locallocaltime($timestamp).''; + } + $output .= &Apache::loncommon::end_data_table_row(); + $r->print($output); + } + } + } + if ($showntablehdr) { + $r->print(&Apache::loncommon::end_data_table()); + if (($curr{'page'} > 1) || ($more_records)) { + $r->print(''); + if ($curr{'page'} > 1) { + $r->print(''); + } + if ($more_records) { + $r->print(''); + } + $r->print('
'.&mt('Previous [_1] changes',$curr{'show'}).''.&mt('Next [_1] changes',$curr{'show'}).'
'); + $r->print(<<"ENDSCRIPT"); + +ENDSCRIPT + } + } else { + $norecords = 1; + } + } else { + $norecords = 1; + } + if ($norecords) { + $r->print('

'. + &mt('There are no records to display'). + '

'); + } + $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') || ($crstype eq 'textbook')) { + $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 = ''; + 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 .= ''. + ''; + my ($types,$typenames) = &Apache::loncommon::course_types(); + if (ref($types) eq 'ARRAY') { + if (@{$types} > 1) { + $output .= ''; + } + } + my ($statuses,$statusnames) = &reqstatus_names($curr->{'crstype'}); + if (ref($statuses) eq 'ARRAY') { + if (@{$statuses} > 1) { + $output .= ''; + } + } + $output .= '
'. + ''.&mt('Records/page:').'
'. + &Apache::lonmeta::selectbox('show',$curr->{'show'},undef, + (&mt('all'),5,10,20,50,100,1000,10000)). + '
  '.&mt('Window during which course/community was requested:').'
'. + ''. + ''. + '
'.&mt('After:'). + ''.$startform.'
'.&mt('Before:').''.$endform.'
'. + '
  '. + &mt('Course Type:').'
'. + &mt('Request Status:').'
'; + + # Update Display button + $output .= '

'. + ''. + '


'; + return $output; +} + sub print_review { my ($dom,$codetitles,$cat_titles,$cat_order,$code_order,$uname,$udom, - $disallowed,$disallowmsg) = @_; - my ($types,$typename) = &course_types(); + $disallowed,$disallowmsg,$instcredits) = @_; + my ($types,$typename) = &Apache::loncommon::course_types(); my ($owner,$ownername,$owneremail); if ($uname eq '' || $udom eq '') { $uname = $env{'user.name'}; @@ -2206,6 +2668,12 @@ sub print_review { } } } + $inst_headers .= ''.&mt('Credits').''; + if ($instcredits) { + $inst_values .= ''.$instcredits.''; + } else { + $inst_values .= ''.$env{'form.coursecredits'}.''; + } if (&Apache::lonnet::auto_run('',$dom)) { $enrollrow_title = &mt('Enrollment'); $enroll_headers = ''.&mt('Automatic Adds').''. @@ -2275,14 +2743,19 @@ sub print_review { $section_values .= $xlistinfo; } $section_values .= ''; + } elsif (($env{'form.crstype'} eq 'unofficial') || ($env{'form.crstype'} eq 'textbook')) { + $inst_headers .= ''.&mt('Credits').''; + $inst_values .= ''.$env{'form.coursecredits'}.''; } 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'}); + my $canclone = &Apache::loncoursequeueadmin::can_clone_course($uname, + $udom,$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')); @@ -2324,15 +2797,18 @@ sub print_review { } my $container = 'Course'; + my $ccrole = 'cc'; if ($env{'form.crstype'} eq 'community') { $container = 'Community'; + $ccrole = 'co'; } $personnel_headers = ''.&mt('Name').''.&mt('Username:Domain'). ''.&mt('Role').''.&mt('LON-CAPA Sections'). ''; + $personnel_values .= ''.$ownername.''.$owner.''. - ''.&Apache::lonnet::plaintext('cc',$container).''. + ''.&Apache::lonnet::plaintext($ccrole,$container).''. ''.&mt('None').''; for (my $i=0; $i<$env{'form.persontotal'}; $i++) { if ($env{'form.person_'.$i.'_uname'} ne '') { @@ -2368,7 +2844,7 @@ sub print_review { if ($showsec eq '') { $showsec = &mt('None'); } - if ($env{'form.person_'.$i.'_role'} eq 'cc') { + if ($env{'form.person_'.$i.'_role'} eq $ccrole) { $showsec = &mt('None'); } my $role = $env{'form.person_'.$i.'_role'}; @@ -2446,6 +2922,7 @@ sub courseinfo_form { community => 'You must provide a (brief) community description.' ); $lt{'unofficial'} = $lt{'official'}; + $lt{'textbook'} = $lt{'official'}; my $js_validate = <<"ENDJS"; ENDJS my $title = &mt('Brief Course Description'); + my $clonetitle = &mt('Clone content and settings from an existing course?'); if ($crstype eq 'community') { $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). @@ -2481,10 +2978,22 @@ ENDJS $output .= $home_server_pick. &Apache::lonhtmlcommon::row_closure(). &Apache::lonhtmlcommon::row_headline(). - '

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

'. + '

'.&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(). + ''."\n"; + &Apache::lonhtmlcommon::end_pick_box().'
'. + &Apache::lonhtmlcommon::end_pick_box()."\n"; return $output; } @@ -2494,15 +3003,16 @@ sub clone_form { if ($crstype eq 'community') { $type = 'Community'; } - 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_title($lt{'dmn'}).''.&Apache::lonhtmlcommon::row_closure(1). + &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). &Apache::lonhtmlcommon::row_title($lt{'dsh'}).'