--- loncom/interface/domainprefs.pm 2009/11/16 04:03:05 1.119
+++ loncom/interface/domainprefs.pm 2009/11/30 06:23:32 1.121
@@ -1,7 +1,7 @@
# The LearningOnline Network with CAPA
# Handler to set domain-wide configuration settings
#
-# $Id: domainprefs.pm,v 1.119 2009/11/16 04:03:05 raeburn Exp $
+# $Id: domainprefs.pm,v 1.121 2009/11/30 06:23:32 raeburn Exp $
#
# Copyright Michigan State University Board of Trustees
#
@@ -202,11 +202,12 @@ sub handler {
'quotas','autoenroll','autoupdate','directorysrch',
'usercreation','usermodification','contacts','defaults',
'scantron','coursecategories','serverstatuses',
- 'requestcourses','helpsettings'],$dom);
+ 'requestcourses','helpsettings','coursedefaults'],$dom);
my @prefs_order = ('rolecolors','login','defaults','quotas','autoenroll',
'autoupdate','directorysrch','contacts',
'usercreation','usermodification','scantron',
- 'requestcourses','coursecategories','serverstatuses','helpsettings');
+ 'requestcourses','coursecategories','serverstatuses','helpsettings',
+ 'coursedefaults');
my %prefs = (
'rolecolors' =>
{ text => 'Default color schemes',
@@ -303,7 +304,7 @@ sub handler {
col2 => 'Value'}],
},
'coursecategories' =>
- { text => 'Cataloging of courses',
+ { text => 'Cataloging of courses/communities',
help => 'Domain_Configuration_Cataloging_Courses',
header => [{col1 => 'Category settings',
col2 => '',},
@@ -325,6 +326,18 @@ sub handler {
header => [{col1 => 'Setting',
col2 => 'Value',}],
},
+ 'coursedefaults' =>
+ {text => 'Course/Community defaults',
+ help => 'Domain_Configuration_Course_Defaults',
+ header => [{col1 => 'Setting',
+ col2 => 'Value',}],
+ },
+ 'privacy' =>
+ {text => 'User Privacy',
+ help => 'Domain_Configuration_User_Privacy',
+ header => [{col1 => 'Setting',
+ col2 => 'Value',}],
+ },
);
my %servers = &dom_servers($dom);
if (keys(%servers) > 1) {
@@ -423,6 +436,8 @@ sub process_changes {
$output = &modify_quotas($dom,$action,%domconfig);
} elsif ($action eq 'helpsettings') {
$output = &modify_helpsettings($dom,%domconfig);
+ } elsif ($action eq 'coursedefaults') {
+ $output = &modify_coursedefaults($dom,%domconfig);
}
return $output;
}
@@ -611,8 +626,10 @@ sub print_config_box {
} elsif ($action eq 'serverstatuses') {
$output .= &print_serverstatuses($dom,$settings,\$rowtotal);
} elsif ($action eq 'helpsettings') {
- $output .= &print_helpsettings($dom,$settings,\$rowtotal);
- }
+ $output .= &print_helpsettings($dom,$settings,\$rowtotal);
+ } elsif ($action eq 'coursedefaults') {
+ $output .= &print_coursedefaults($dom,$settings,\$rowtotal);
+ }
}
$output .= '
@@ -1929,33 +1946,40 @@ sub print_contacts {
}
sub print_helpsettings {
-
- my ($dom,$settings,$rowtotal) = @_;
- my ($css_class,$datatable);
- my $itemcount = 1;
- my (%checkedon,%checkedoff,%choices,%defaultchecked,@toggles);
-
- %choices =
+ my ($dom,$settings,$rowtotal) = @_;
+ my ($css_class,$datatable);
+ my $itemcount = 1;
+ my (%checkedon,%checkedoff,%choices,%defaultchecked,@toggles);
+ %choices =
&Apache::lonlocal::texthash (
submitbugs => 'Display "Submit a bug" link?',
);
-
- %defaultchecked = ('submitbugs' => 'on');
-
- @toggles = ('submitbugs',);
-
- foreach my $item (@toggles) {
- if ($defaultchecked{$item} eq 'on') {
+ %defaultchecked = ('submitbugs' => 'on');
+ @toggles = ('submitbugs',);
+ ($datatable,$itemcount) = &radiobutton_prefs($settings,\@toggles,\%defaultchecked,
+ \%choices,$itemcount);
+ $$rowtotal += $itemcount;
+ return $datatable;
+}
+
+sub radiobutton_prefs {
+ my ($settings,$toggles,$defaultchecked,$choices,$itemcount) = @_;
+ return unless ((ref($toggles) eq 'ARRAY') && (ref($defaultchecked) eq 'HASH') &&
+ (ref($choices) eq 'HASH'));
+
+ my (%checkedon,%checkedoff,$datatable,$css_class);
+
+ foreach my $item (@{$toggles}) {
+ if ($defaultchecked->{$item} eq 'on') {
$checkedon{$item} = ' checked="checked" ';
$checkedoff{$item} = ' ';
- } elsif ($defaultchecked{$item} eq 'off') {
+ } elsif ($defaultchecked->{$item} eq 'off') {
$checkedoff{$item} = ' checked="checked" ';
$checkedon{$item} = ' ';
}
}
-
if (ref($settings) eq 'HASH') {
- foreach my $item (@toggles) {
+ foreach my $item (@{$toggles}) {
if ($settings->{$item} eq '1') {
$checkedon{$item} = ' checked="checked" ';
$checkedoff{$item} = ' ';
@@ -1964,12 +1988,11 @@ sub print_helpsettings {
$checkedon{$item} = ' ';
}
}
- }
-
- foreach my $item (@toggles) {
+ }
+ foreach my $item (@{$toggles}) {
$css_class = $itemcount%2?' class="LC_odd_row"':'';
- $datatable .=
- '
'.$choices{$item}.
+ $datatable .=
+ ''.$choices->{$item}.
' '.
''.
' {'togglecats'} eq 'crs') {
$toggle_cats_crs = $toggle_cats_dom;
@@ -2604,14 +2648,25 @@ sub print_coursecategories {
$can_cat_crs = $can_cat_dom;
$can_cat_dom = ' ';
}
+ if ($settings->{'togglecatscomm'} eq 'comm') {
+ $toggle_catscomm_comm = $toggle_catscomm_dom;
+ $toggle_catscomm_dom = ' ';
+ }
+ if ($settings->{'categorizecomm'} eq 'comm') {
+ $can_catcomm_comm = $can_catcomm_dom;
+ $can_catcomm_dom = ' ';
+ }
}
my %title = &Apache::lonlocal::texthash (
- togglecats => 'Show/Hide a course in the catalog',
- categorize => 'Assign a category to a course',
+ togglecats => 'Show/Hide a course in catalog',
+ togglecatscomm => 'Show/Hide a community in catalog',
+ categorize => 'Assign a category to a course',
+ categorizecomm => 'Assign a category to a community',
);
my %level = &Apache::lonlocal::texthash (
- dom => 'Set in "Modify Course" (Domain)',
- crs => 'Set in "Modify Parameters" (Course)',
+ dom => 'Set in Domain',
+ crs => 'Set in Course',
+ comm => 'Set in Community',
);
$datatable = ''.
''.$title{'togglecats'}.' '.
@@ -2627,8 +2682,22 @@ sub print_coursecategories {
$can_cat_dom.' value="dom" />'.$level{'dom'}.' '.
' '.$level{'crs'}.' '.
+ ' '.
+ ''.$title{'togglecatscomm'}.' '.
+ ''.
+ ' '.$level{'dom'}.' '.
+ ' '.$level{'comm'}.' '.
+ ' '.
+ ''.$title{'categorizecomm'}.' '.
+ ''.
+ ' '.$level{'dom'}.' '.
+ ' '.$level{'comm'}.' '.
' ';
- $$rowtotal += 2;
+ $$rowtotal += 4;
} else {
my $css_class;
my $itemcount = 1;
@@ -2650,7 +2719,15 @@ sub print_coursecategories {
if (ref($cats[0]) eq 'ARRAY') {
my $numtop = @{$cats[0]};
my $maxnum = $numtop;
- if ((!grep(/^instcode$/,@{$cats[0]})) || ($cathash->{'instcode::0'} eq '')) {
+ my %default_names = (
+ instcode => &mt('Official courses'),
+ communities => &mt('Communities'),
+ );
+
+ if ((!grep(/^instcode$/,@{$cats[0]})) ||
+ ($cathash->{'instcode::0'} eq '') ||
+ (!grep(/^communities$/,@{$cats[0]})) ||
+ ($cathash->{'communities::0'} eq '')) {
$maxnum ++;
}
my $lastidx;
@@ -2671,14 +2748,33 @@ sub print_coursecategories {
$datatable .= ''.$vpos.' ';
}
$datatable .= ' ';
- if ($parent eq 'instcode') {
- $datatable .= ''.&mt('Official courses')
- .' ('
- .&mt('with institutional codes').') '
- .' '
- .&mt('Display').' '
- .' '
- .&mt('Do not display').' ';
+ if ($parent eq 'instcode' || $parent eq 'communities') {
+ $datatable .= ''
+ .$default_names{$parent}.' ';
+ if ($parent eq 'instcode') {
+ $datatable .= '('
+ .&mt('with institutional codes')
+ .') ';
+ } else {
+ $datatable .= '';
+ }
+ $datatable .= ' ';
} else {
$datatable .= $parent
.' '
.' '."\n";
$itemcount ++;
- if ((!grep(/^instcode$/,@{$cats[0]})) || ($cathash->{'instcode::0'} eq '')) {
- $css_class = $itemcount%2?' class="LC_odd_row"':'';
- my $chgstr = ' onchange="javascript:reorderCats(this.form,'."'','instcode_pos','$lastidx'".');"';
- $datatable .= ''.
- '';
- for (my $k=0; $k<=$maxnum; $k++) {
- my $vpos = $k+1;
- my $selstr;
- if ($k == $maxnum) {
- $selstr = ' selected="selected" ';
+ foreach my $default ('instcode','communities') {
+ if ((!grep(/^\Q$default\E$/,@{$cats[0]})) || ($cathash->{$default.'::0'} eq '')) {
+ $css_class = $itemcount%2?' class="LC_odd_row"':'';
+ my $chgstr = ' onchange="javascript:reorderCats(this.form,'."'','$default"."_pos','$lastidx'".');"';
+ $datatable .= ''.
+ '';
+ for (my $k=0; $k<=$maxnum; $k++) {
+ my $vpos = $k+1;
+ my $selstr;
+ if ($k == $maxnum) {
+ $selstr = ' selected="selected" ';
+ }
+ $datatable .= ''.$vpos.' ';
}
- $datatable .= ''.$vpos.' ';
+ $datatable .= ' '.
+ ''.
+ $default_names{$default}.' ';
+ if ($default eq 'instcode') {
+ $datatable .= '('
+ .&mt('with institutional codes').') ';
+ }
+ $datatable .= ' '
+ .' '
+ .&mt('Display').' '
+ .' '
+ .&mt('Do not display').' ';
}
- $datatable .= ' '
- .&mt('Official courses').' '.'('
- .&mt('with institutional codes').') '
- .' '
- .&mt('Display').' '
- .' '
- .&mt('Do not display').' ';
}
}
} else {
@@ -2814,6 +2917,9 @@ sub coursecategories_javascript {
$jstext = ' var categories = Array(1);'."\n".
' categories[0] = Array("instcode_pos");'."\n";
}
+ my $instcode_reserved = &mt('The name: "instcode" is a reserved category');
+ my $communities_reserved = &mt('The name: "communities" is a reserved category');
+ my $choose_again = '\\n'.&mt('Please use a different name for the new top level category');
$output = <<"ENDSCRIPT";
@@ -2882,25 +3001,40 @@ ENDSCRIPT
sub initialize_categories {
my ($itemcount) = @_;
- my $datatable;
- my $css_class = $itemcount%2?' class="LC_odd_row"':'';
- my $chgstr = ' onchange="javascript:reorderCats(this.form,'."'','instcode_pos','0'".');"';
-
- $datatable = ''
- .'1 '
- .'2 '
- .&mt('Official courses (with institutional codes)')
- .' '
- .' '
- .&mt('Display').' '
- .' '.&mt('Do not display')
+ my ($datatable,$css_class,$chgstr);
+ my %default_names = (
+ instcode => 'Official courses (with institutional codes)',
+ communities => 'Communities',
+ );
+ my $select0 = ' selected="selected"';
+ my $select1 = '';
+ foreach my $default ('instcode','communities') {
+ $css_class = $itemcount%2?' class="LC_odd_row"':'';
+ $chgstr = ' onchange="javascript:reorderCats(this.form,'."'',$default"."_pos','0'".');"';
+ if ($default eq 'communities') {
+ $select1 = $select0;
+ $select0 = '';
+ }
+ $datatable .= ''
+ .''
+ .'1 '
+ .'2 '
+ .'3 '
+ .$default_names{$default}
+ .' '
+ .' '
+ .&mt('Display').' '
+ .' '.&mt('Do not display')
.' ';
- $itemcount ++;
+ $itemcount ++;
+ }
$css_class = $itemcount%2?' class="LC_odd_row"':'';
$chgstr = ' onchange="javascript:reorderCats(this.form,'."'','addcategory_pos','0'".');"';
$datatable .= ''
- .'1 '
- .'2 '
+ .''
+ .'1 '
+ .'2 '
+ .'3 '
.&mt('Add category').' '.&mt('Name:')
.' ';
return $datatable;
@@ -5398,6 +5532,14 @@ sub modify_coursecategories {
$changes{'categorize'} = 1;
$domconfig{'coursecategories'}{'categorize'} = $env{'form.categorize'};
}
+ if ($domconfig{'coursecategories'}{'togglecatscomm'} ne $env{'form.togglecatscomm'}) {
+ $changes{'togglecatscomm'} = 1;
+ $domconfig{'coursecategories'}{'togglecatscomm'} = $env{'form.togglecatscomm'};
+ }
+ if ($domconfig{'coursecategories'}{'categorizecomm'} ne $env{'form.categorizecomm'}) {
+ $changes{'categorizecomm'} = 1;
+ $domconfig{'coursecategories'}{'categorizecomm'} = $env{'form.categorizecomm'};
+ }
} else {
$changes{'togglecats'} = 1;
$changes{'categorize'} = 1;
@@ -5405,11 +5547,20 @@ sub modify_coursecategories {
togglecats => $env{'form.togglecats'},
categorize => $env{'form.categorize'},
};
+ $changes{'togglecatscomm'} = 1;
+ $changes{'categorizecomm'} = 1;
+ $domconfig{'coursecategories'} = {
+ togglecats => $env{'form.togglecatscomm'},
+ categorize => $env{'form.categorizecomm'},
+ };
}
if (ref($cathash) eq 'HASH') {
if (($domconfig{'coursecategories'}{'cats'}{'instcode::0'} ne '') && ($env{'form.instcode'} == 0)) {
push (@deletecategory,'instcode::0');
}
+ if (($domconfig{'coursecategories'}{'cats'}{'communities::0'} ne '') && ($env{'form.communities'} == 0)) {
+ push(@deletecategory,'communities::0');
+ }
}
my (@predelcats,@predeltrails,%predelallitems,%sort_by_deltrail);
if (ref($cathash) eq 'HASH') {
@@ -5459,10 +5610,26 @@ sub modify_coursecategories {
$adds{$newitem} = 1;
}
}
+ if ($env{'form.communities'} eq '1') {
+ if (ref($cathash) eq 'HASH') {
+ my $newitem = 'communities::0';
+ if ($cathash->{$newitem} eq '') {
+ $domconfig{'coursecategories'}{'cats'}{$newitem} = $env{'form.communities_pos'};
+ $adds{$newitem} = 1;
+ }
+ } else {
+ my $newitem = 'communities::0';
+ $domconfig{'coursecategories'}{'cats'}{$newitem} = $env{'form.communities_pos'};
+ $adds{$newitem} = 1;
+ }
+ }
if ($env{'form.addcategory_name'} ne '') {
- my $newitem = &escape($env{'form.addcategory_name'}).'::0';
- $domconfig{'coursecategories'}{'cats'}{$newitem} = $env{'form.addcategory_pos'};
- $adds{$newitem} = 1;
+ if (($env{'form.addcategory_name'} ne 'instcode') &&
+ ($env{'form.addcategory_name'} ne 'communities')) {
+ my $newitem = &escape($env{'form.addcategory_name'}).'::0';
+ $domconfig{'coursecategories'}{'cats'}{$newitem} = $env{'form.addcategory_pos'};
+ $adds{$newitem} = 1;
+ }
}
my $putresult;
if ((keys(%deletions) > 0) || (keys(%reorderings) > 0) || (keys(%adds) > 0)) {
@@ -5499,12 +5666,15 @@ sub modify_coursecategories {
$putresult = &Apache::lonnet::put_dom('configuration',\%domconfig,$dom);
if ($putresult eq 'ok') {
my %title = (
- togglecats => 'Show/Hide a course in the catalog',
- categorize => 'Category assigned to course',
+ togglecats => 'Show/Hide a course in catalog',
+ categorize => 'Assign a category to a course',
+ togglecatscomm => 'Show/Hide a community in catalog',
+ categorizecomm => 'Assign a category to a community',
);
my %level = (
- dom => 'set from "Modify Course" (Domain)',
- crs => 'set from "Parameters" (Course)',
+ dom => 'set in Domain ("Modify Course/Community")',
+ crs => 'set in Course ("Course Configuration")',
+ comm => 'set in Community ("Community Configuration")',
);
$resulttext = &mt('Changes made:').'';
if ($changes{'togglecats'}) {
@@ -5513,6 +5683,12 @@ sub modify_coursecategories {
if ($changes{'categorize'}) {
$resulttext .= ''.&mt("$title{'categorize'} $level{$env{'form.categorize'}}").' ';
}
+ if ($changes{'togglecatscomm'}) {
+ $resulttext .= ''.&mt("$title{'togglecatscomm'} $level{$env{'form.togglecatscomm'}}").' ';
+ }
+ if ($changes{'categorizecomm'}) {
+ $resulttext .= ''.&mt("$title{'categorizecomm'} $level{$env{'form.categorizecomm'}}").' ';
+ }
if ((keys(%deletions) > 0) || (keys(%reorderings) > 0) || (keys(%adds) > 0)) {
my $cathash;
if (ref($domconfig{'coursecategories'}) eq 'HASH') {
@@ -5562,7 +5738,7 @@ sub modify_coursecategories {
&mt('An error occurred: [_1]',$putresult).' ';
}
} else {
- $resulttext = &mt('No changes made to course categories');
+ $resulttext = &mt('No changes made to course and community categories');
}
return $resulttext;
}
@@ -5757,6 +5933,72 @@ sub modify_helpsettings {
}
return $resulttext;
}
+
+sub modify_coursedefaults {
+ my ($dom,%domconfig) = @_;
+ my ($resulttext,$errors,%changes,%defaultshash);
+ my %defaultchecked = ('canuse_pdfforms' => 'off');
+ my @offon = ('off','on');
+ my @toggles = ('canuse_pdfforms');
+
+ $defaultshash{'coursedefaults'} = {};
+
+ if (ref($domconfig{'coursedefaults'}) ne 'HASH') {
+ if ($domconfig{'coursedefaults'} eq '') {
+ $domconfig{'coursedefaults'} = {};
+ }
+ }
+
+ if (ref($domconfig{'coursedefaults'}) eq 'HASH') {
+ foreach my $item (@toggles) {
+ if ($defaultchecked{$item} eq 'on') {
+ if (($domconfig{'coursedefaults'}{$item} eq '') &&
+ ($env{'form.'.$item} eq '0')) {
+ $changes{$item} = 1;
+ } elsif ($domconfig{'coursdefaults'}{$item} ne $env{'form.'.$item}) {
+ $changes{$item} = 1;
+ }
+ } elsif ($defaultchecked{$item} eq 'off') {
+ if (($domconfig{'coursedefaults'}{$item} eq '') &&
+ ($env{'form.'.$item} eq '1')) {
+ $changes{$item} = 1;
+ } elsif ($domconfig{'coursedefaults'}{$item} ne $env{'form.'.$item}) {
+ $changes{$item} = 1;
+ }
+ }
+ $defaultshash{'coursedefaults'}{$item} = $env{'form.'.$item};
+ }
+ }
+ my $putresult = &Apache::lonnet::put_dom('configuration',\%defaultshash,
+ $dom);
+ if ($putresult eq 'ok') {
+ if (keys(%changes) > 0) {
+ if ($changes{'canuse_pdfforms'}) {
+ my %domdefaults = &Apache::lonnet::get_domain_defaults($dom);
+ $domdefaults{'canuse_pdfforms'}=$defaultshash{'coursedefaults'}{'canuse_pdfforms'};
+ my $cachetime = 24*60*60;
+ &Apache::lonnet::do_cache_new('domdefaults',$dom,\%domdefaults,$cachetime);
+ }
+ $resulttext = &mt('Changes made:').'';
+ foreach my $item (sort(keys(%changes))) {
+ if ($item eq 'canuse_pdfforms') {
+ if ($env{'form.'.$item} eq '1') {
+ $resulttext .= ''.&mt("Course/Community users can create/upload PDF forms set to 'on'").' ';
+ } else {
+ $resulttext .= ''.&mt('Course/Community users can create/upload PDF forms set to "off"').' ';
+ }
+ }
+ }
+ $resulttext .= ' ';
+ } else {
+ $resulttext = &mt('No changes made to course defaults');
+ }
+ } else {
+ $resulttext = ''.
+ &mt('An error occurred: [_1]',$putresult).' ';
+ }
+ return $resulttext;
+}
sub recurse_check {
my ($chkcats,$categories,$depth,$name) = @_;