--- loncom/interface/lonpickcourse.pm 2009/11/03 14:32:44 1.89 +++ loncom/interface/lonpickcourse.pm 2010/06/19 01:38:03 1.93.2.1 @@ -1,7 +1,7 @@ # The LearningOnline Network # Pick a course # -# $Id: lonpickcourse.pm,v 1.89 2009/11/03 14:32:44 raeburn Exp $ +# $Id: lonpickcourse.pm,v 1.93.2.1 2010/06/19 01:38:03 raeburn Exp $ # # Copyright Michigan State University Board of Trustees # @@ -51,7 +51,7 @@ sub handler { ($ENV{'QUERY_STRING'},['domainfilter','form','cnumelement', 'cdomelement','cnameelement','roleelement', 'multiple','type','setroles','fixeddom','cloner']); - my ($type,$title,$jscript,$multelement,$multiple,$roleelement, + my ($type,$title,$jscript,$multelement,$multiple,$roleelement,$typeelement, $lastaction,$autosubmit,$submitopener,$cloneruname,$clonerudom); # Get course type - Course or Community. @@ -75,8 +75,11 @@ sub handler { $submitopener = &processpick(); $autosubmit = 'process_pick("'.$roledom.'")'; } + if ($env{'form.typeelement'} ne '') { + $typeelement = ''; + } - # if called when a DC is creating a course + # if called when a DC is creating a course for another user. if ($env{'form.form'} eq 'ccrs') { ($cloneruname,$clonerudom) = ($env{'form.cloner'} =~ /^($match_username):($match_domain)$/); } @@ -165,7 +168,7 @@ sub handler { $r->print(&build_filters($filterlist,$type,$roleelement,$multelement, $filter,$action,\$numtitles,undef,$cloneruname, - $clonerudom)); + $clonerudom,$typeelement)); } # ---------------------------------------------------------------- Get the data @@ -303,12 +306,8 @@ sub display_matched_courses { } my $cctitle = &Apache::lonnet::plaintext($ccrole,$type); my $dctitle = &Apache::lonnet::plaintext('dc'); - my $ccrolechk = ' checked="checked" '; - my $menuchk = ' '; - if ($env{'form.prevphase'} ne '') { - $ccrolechk = ' '; - $menuchk = ' checked="checked" '; - } + my $ccrolechk = ' '; + my $menuchk = ' checked="checked" '; $r->print( '
' .''.&mt('Action').'' @@ -377,6 +376,14 @@ sub display_matched_courses { } $r->print(&Apache::loncommon::end_data_table_header_row()); } + my %cc_cloneable; + if (($env{'form.form'} eq 'ccrs') || ($env{'form.form'} eq 'requestcrs')) { + my ($coord_cloneable,$warning) = + &get_coordinator_cloneable($cloneruname,$clonerudom,$type); + if ($coord_cloneable) { + map {$cc_cloneable{$_} = 1;} split('&',$coord_cloneable); + } + } foreach my $description (sort { lc($a) cmp lc($b) } (keys(%by_descrip))) { foreach my $course (@{$by_descrip{$description}}) { $r->print(&Apache::loncommon::start_data_table_row()); @@ -389,17 +396,22 @@ sub display_matched_courses { $instcode = $courses{$course}{'inst_code'}; $ttype = $courses{$course}{'type'}; if (($env{'form.form'} eq 'ccrs') || ($env{'form.form'} eq 'requestcrs')) { - my $cloners = $courses{$course}{'cloners'}; - if ($cloners ne '') { - my @cloneable = split(',',$cloners); - if (grep(/^\*$/,@cloneable)) { - $canclone = 1; - } - if (grep(/^\*:\Q$env{'form.clonerudom'}\E$/,@cloneable)) { - $canclone = 1; - } - if (grep(/^\Q$cloneruname\E:\Q$clonerudom\E$/,@cloneable)) { - $canclone = 1; + if ($cc_cloneable{$courses{$course}{'cnum'}.':'.$courses{$course}{'domain'}}) { + $canclone = 1; + } + unless ($canclone) { + my $cloners = $courses{$course}{'cloners'}; + if ($cloners ne '') { + my @cloneable = split(',',$cloners); + if (grep(/^\*$/,@cloneable)) { + $canclone = 1; + } + if (grep(/^\*:\Q$clonerudom\E$/,@cloneable)) { + $canclone = 1; + } + if (grep(/^\Q$cloneruname\E:\Q$clonerudom\E$/,@cloneable)) { + $canclone = 1; + } } } } @@ -414,7 +426,7 @@ sub display_matched_courses { ($descr,$instcode,$singleowner,$ttype)=split(/:/,$courses{$course}); push(@owners,&unescape($singleowner)); } - my $ownerstr = join(', ',@owners); + my $ownerstr = join(', ',map { &Apache::loncommon::plainname(split(':',$_)); } @owners); $r->print(''.&course_chooser($multiple,$cdom,$cnum,$cleandesc,$canclone).''); $r->print(''.$description.''); $r->print(''); @@ -481,6 +493,11 @@ sub display_matched_courses { $env{'form.cnumelement'}.'" />'."\n". ''."\n"); + if ($env{'form.typeelement'} ne '') { + $r->print(''."\n"); + + } } if ((exists($env{'form.fixeddom'})) && ($env{'form.form'} eq 'rules')) { $r->print(' &mt("$type Title"), - 'cdo' => &mt("$type Domain"), - 'ins' => &mt('Institutional Code'), - 'inc' => &mt('Institutional Categorization'), - 'cow' => &mt("$type Owner/Co-owner"), - 'cop' => &mt("$type Personnel Includes"), - 'cog' => &mt('Type') + $sincefilterform=&Apache::loncommon::select_form( + $filter->{'sincefilter'}, + 'sincefilter', + ( '-1' => '', + '86400' => &mt('today'), + '604800' => &mt('last week'), + '2592000' => &mt('last month'), + '7776000' => &mt('last three months'), + '15552000' => &mt('last six months'), + '31104000' => &mt('last year'), + 'select_form_order' => + ['-1','86400','604800','2592000','7776000', + '15552000','31104000'])); + + my %lt = &Apache::lonlocal::texthash( + 'cac' => "$type Activity", + 'cde' => "$type Title", + 'cdo' => "$type Domain", + 'ins' => 'Institutional Code', + 'inc' => 'Institutional Categorization', + 'cow' => "$type Owner/Co-owner", + 'cop' => "$type Personnel Includes", + 'cog' => 'Type', ); if (($env{'form.form'} eq 'ccrs') || ($env{'form.form'} eq 'requestcrs')) { @@ -685,6 +704,7 @@ sub build_filters { $name_input $roleelement $multelement +$typeelement |; if ($formname eq 'portform') { $output .= ''."\n"; @@ -751,33 +771,15 @@ $multelement .&Apache::lonhtmlcommon::row_closure(1); } $output .= &Apache::lonhtmlcommon::end_pick_box().'

'; - my $warning; + my ($coord_cloneable,$warning); if (($env{'form.form'} eq 'ccrs') || ($env{'form.form'} eq 'requestcrs')) { - my $cloneruhome=&Apache::lonnet::homeserver($cloneruname,$clonerudom); - my $cc_clone; - if ($cloneruhome eq 'no_host') { - $warning = '

'.&mt('Intended course owner does not exist'). - '
'; - } else { - my $ccrole; - if ($type eq 'Community') { - $ccrole = 'co'; - } elsif ($type eq 'Course') { - $ccrole = 'cc'; - } - if ($env{'form.form'} eq 'ccrs') { - $output .= ''."\n"; - } - my %ccroles = &Apache::lonnet::get_my_roles($cloneruname,$clonerudom, - 'userroles',['active'], [$ccrole]); - foreach my $key (sort(keys(%ccroles))) { - my ($cnum,$cdom,$role) = split(':',$key); - $cc_clone .= $cdom.':'.$cnum.'&'; - } - $cc_clone =~ s/\&$//; + ($coord_cloneable,$warning) = + &get_coordinator_cloneable($cloneruname,$clonerudom,$type); + if ($env{'form.form'} eq 'ccrs') { + $output .= ''."\n"; } - if ($cc_clone ne '') { - $output .= ''; + if ($coord_cloneable) { + $output .= ''; } } $output .= ''."\n". @@ -786,6 +788,30 @@ $multelement return $jscript.$warning.$output; } +sub get_coordinator_cloneable { + my ($cloneruname,$clonerudom,$type) = @_; + if (&Apache::lonnet::homeserver($cloneruname,$clonerudom) eq 'no_host') { + my $warning = '
'.&mt('Intended course owner does not exist'). + '
'; + return ('',$warning); + } else { + my ($cc_clone,$ccrole); + if ($type eq 'Community') { + $ccrole = 'co'; + } elsif ($type eq 'Course') { + $ccrole = 'cc'; + } + my %ccroles = &Apache::lonnet::get_my_roles($cloneruname,$clonerudom, + 'userroles',['active'], [$ccrole]); + foreach my $key (sort(keys(%ccroles))) { + my ($cnum,$cdom,$role) = split(':',$key); + $cc_clone .= $cdom.':'.$cnum.'&'; + } + $cc_clone =~ s/\&$//; + return ($cc_clone); + } +} + sub instcode_selectors { my ($codedom,$formname,$officialjs) = @_; my ($output,@codetitles,%cat_titles,%cat_order,%cat_items); @@ -981,13 +1007,19 @@ function gochoose(cname,cdom,cdesc) { } ENDSCRIPT } else { - my $name_code; + my ($name_code,$type_code); if ($env{'form.cnameelement'} ne '') { $name_code = 'opener.document.'.$env{'form.form'}.'.'. $env{'form.cnameelement'}.'.value=cdesc;'; } + if ($env{'form.typeelement'} ne '') { + $type_code = 'opener.document.'.$env{'form.form'}.'.'. + $env{'form.typeelement'}.'.value=document.courselist.type;'; + } + $output .= qq| $name_code + $type_code opener.document.$env{'form.form'}.$env{'form.cnumelement'}.value=cname; var slct=opener.document.$env{'form.form'}.$env{'form.cdomelement'}; if (slct.options == undefined) { @@ -1129,10 +1161,10 @@ Side Effects: None =item * X -B: +B: -Input: 7 - anonymous array of search criteria; course type; $roleelement ; $multelement ; anonymous hash of criteria and their values; form action; ref to scalar (count of number of elements in institutional codes -- e.g., 4 for year, semester, department, and number); caller context (e.g., set to 'modifycourse' when routine is called from lonmodifycourse.pm). +Input: 11 - anonymous array of search criteria; course type; $roleelement ; $multelement ; anonymous hash of criteria and their values; form action; ref to scalar (count of number of elements in institutional codes -- e.g., 4 for year, semester, department, and number); caller context (e.g., set to 'modifycourse' when routine is called from lonmodifycourse.pm), username and domain of new course owner who wants to clone, $tyepelem Output: 1 - $output - HTML for display of search criteria, and hidden form elements.