[LON-CAPA-cvs] cvs: loncom /interface lonpickcourse.pm
raeburn
raeburn@source.lon-capa.org
Sun, 21 Feb 2010 15:09:36 -0000
raeburn Sun Feb 21 15:09:36 2010 EDT
Modified files:
/loncom/interface lonpickcourse.pm
Log:
- Move generation of list of cloneable courses based on active CC role for
a user to subroutine: &get_coordinator_cloneable() to facilitate reuse.
Index: loncom/interface/lonpickcourse.pm
diff -u loncom/interface/lonpickcourse.pm:1.91 loncom/interface/lonpickcourse.pm:1.92
--- loncom/interface/lonpickcourse.pm:1.91 Wed Dec 2 18:33:27 2009
+++ loncom/interface/lonpickcourse.pm Sun Feb 21 15:09:36 2010
@@ -1,7 +1,7 @@
# The LearningOnline Network
# Pick a course
#
-# $Id: lonpickcourse.pm,v 1.91 2009/12/02 18:33:27 bisitz Exp $
+# $Id: lonpickcourse.pm,v 1.92 2010/02/21 15:09:36 raeburn Exp $
#
# Copyright Michigan State University Board of Trustees
#
@@ -79,7 +79,7 @@
$typeelement = '<input type="hidden" name="typeelement" value="'.$env{'form.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)$/);
}
@@ -309,8 +309,8 @@
my $ccrolechk = ' checked="checked" ';
my $menuchk = ' ';
if ($env{'form.prevphase'} ne '') {
- $ccrolechk = ' ';
- $menuchk = ' checked="checked" ';
+ $ccrolechk = ' ';
+ $menuchk = ' checked="checked" ';
}
$r->print(
'<fieldset>'
@@ -380,6 +380,14 @@
}
$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());
@@ -392,17 +400,22 @@
$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$env{'form.clonerudom'}\E$/,@cloneable)) {
+ $canclone = 1;
+ }
+ if (grep(/^\Q$cloneruname\E:\Q$clonerudom\E$/,@cloneable)) {
+ $canclone = 1;
+ }
}
}
}
@@ -762,33 +775,15 @@
.&Apache::lonhtmlcommon::row_closure(1);
}
$output .= &Apache::lonhtmlcommon::end_pick_box().'<p>';
- 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 = '<div class="LC_error">'.&mt('Intended course owner does not exist').
- '</div>';
- } else {
- my $ccrole;
- if ($type eq 'Community') {
- $ccrole = 'co';
- } elsif ($type eq 'Course') {
- $ccrole = 'cc';
- }
- if ($env{'form.form'} eq 'ccrs') {
- $output .= '<input type="hidden" name="cloner" value="'.$env{'form.cloner'}.'" />'."\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 .= '<input type="hidden" name="cloner" value="'.$env{'form.cloner'}.'" />'."\n";
}
- if ($cc_clone ne '') {
- $output .= '<input type="hidden" name="cc_clone" value="'.$cc_clone.'" />';
+ if ($coord_cloneable) {
+ $output .= '<input type="hidden" name="cc_clone" value="'.$coord_cloneable.'" />';
}
}
$output .= '<input type="hidden" name="updater" value="">'."\n".
@@ -797,6 +792,30 @@
return $jscript.$warning.$output;
}
+sub get_coordinator_cloneable {
+ my ($cloneruname,$clonerudom,$type) = @_;
+ if (&Apache::lonnet::homeserver($cloneruname,$clonerudom) eq 'no_host') {
+ my $warning = '<div class="LC_error">'.&mt('Intended course owner does not exist').
+ '</div>';
+ 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);