--- loncom/interface/lonrequestcourse.pm 2009/10/24 03:56:01 1.36.2.3 +++ 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.36.2.3 2009/10/24 03:56:01 raeburn Exp $ +# $Id: lonrequestcourse.pm,v 1.39 2009/11/04 17:42:17 raeburn Exp $ # # Copyright Michigan State University Board of Trustees # @@ -130,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'}; @@ -234,8 +234,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') { @@ -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"; @@ -611,31 +612,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; @@ -658,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.', @@ -698,24 +677,59 @@ END } return true; } - END - $r->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'})) { + 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('

'. + $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')).' @@ -723,213 +737,49 @@ END '. &Apache::lonhtmlcommon::row_closure(1). - &Apache::lonhtmlcommon::row_title(&mt('Course Type')). - &mt($typename->{'unofficial'})."\n". - '
'."\n". - '
'."\n". + &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, @@ -2235,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')); @@ -2801,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'};