[LON-CAPA-cvs] cvs: loncom /interface domainprefs.pm
raeburn
lon-capa-cvs-allow@mail.lon-capa.org
Wed, 12 Sep 2007 12:01:06 -0000
This is a MIME encoded message
--raeburn1189598466
Content-Type: text/plain
raeburn Wed Sep 12 08:01:06 2007 EDT
Modified files:
/loncom/interface domainprefs.pm
Log:
Ability to set user creation options
- when user creation is allowed by non-DCs
(a) to create co-authors; (b) to enroll users in a course)
- which namespacing rules to enforce
--raeburn1189598466
Content-Type: text/plain
Content-Disposition: attachment; filename="raeburn-20070912080106.txt"
Index: loncom/interface/domainprefs.pm
diff -u loncom/interface/domainprefs.pm:1.26 loncom/interface/domainprefs.pm:1.27
--- loncom/interface/domainprefs.pm:1.26 Sat Sep 1 17:20:14 2007
+++ loncom/interface/domainprefs.pm Wed Sep 12 08:01:04 2007
@@ -1,7 +1,7 @@
# The LearningOnline Network with CAPA
# Handler to set domain-wide configuration settings
#
-# $Id: domainprefs.pm,v 1.26 2007/09/01 21:20:14 raeburn Exp $
+# $Id: domainprefs.pm,v 1.27 2007/09/12 12:01:04 raeburn Exp $
#
# Copyright Michigan State University Board of Trustees
#
@@ -67,7 +67,8 @@
}
my %domconfig =
&Apache::lonnet::get_dom('configuration',['login','rolecolors',
- 'quotas','autoenroll','autoupdate','directorysrch'],$dom);
+ 'quotas','autoenroll','autoupdate','directorysrch',
+ 'usercreation'],$dom);
my @prefs = (
{ text => 'Default color schemes',
help => 'Default_Color_Schemes',
@@ -113,6 +114,12 @@
header => [{col1 => 'Setting',
col2 => 'Value',}],
},
+ { text => 'User creation',
+ help => 'Domain_User_Creation',
+ action => 'usercreation',
+ header => [{col1 => 'Setting',
+ col2 => 'Value',}],
+ },
);
my @roles = ('student','coordinator','author','admin');
&Apache::lonhtmlcommon::add_breadcrumb
@@ -197,6 +204,8 @@
$output = &modify_autoupdate($dom,%domconfig);
} elsif ($action eq 'directorysrch') {
$output = &modify_directorysrch($dom,%domconfig);
+ } elsif ($action eq 'usercreation') {
+ $output = &modify_user_creation($dom,%domconfig);
}
return $output;
}
@@ -289,7 +298,9 @@
$r->print(&print_autoenroll($dom,$settings));
} elsif ($action eq 'directorysrch') {
$r->print(&print_directorysrch($dom,$settings));
- }
+ } elsif ($action eq 'usercreation') {
+ $r->print(&print_usercreation($dom,$settings));
+ }
}
$r->print('
</table>
@@ -1000,6 +1011,82 @@
return $datatable;
}
+sub print_usercreation {
+ my ($dom,$settings) = @_;
+ my $numinrow = 4;
+ my ($rules,$ruleorder) = &Apache::lonnet::inst_userrules($dom);
+ my %checked;
+ if (ref($settings) eq 'HASH') {
+ if (ref($settings->{'cancreate'}) eq 'ARRAY') {
+ foreach my $item (@{$settings->{'cancreate'}}) {
+ $checked{$item} = ' checked="checked" ';
+ }
+ }
+ }
+ my $datatable = '<td>'.&mt('User creation other than by DC: ').'</td>'.
+ '<td class="LC_left_item"><table><tr><td>'.
+ '<span class="LC_nobreak"><label>'.
+ '<input type="checkbox" name="can_createuser" '.
+ $checked{'author'}.' value="author" />'.
+ &mt('When adding a co-author/assistant author').
+ '</label><span></td></tr>'.
+ '<tr><td>'.
+ '<span class="LC_nobreak"><label>'.
+ '<input type="checkbox" name="can_createuser" '.
+ $checked{'course'}.' value="course" />'.
+ &mt('When adding users to a course').
+ '</label><span></td></tr></table></td></tr>';
+ if (ref($rules) eq 'HASH') {
+ if (keys(%{$rules}) > 0) {
+ $datatable .= &username_formats_row($settings,$rules,$ruleorder,
+ $numinrow);
+ }
+ }
+ return $datatable;
+}
+
+sub username_formats_row {
+ my ($settings,$rules,$ruleorder,$numinrow) = @_;
+ my $output = '<tr class="LC_odd_row">'.
+ '<td>'.&mt('Format rules to check for new usernames').
+ '</td><td class="LC_left_item" colspan="2"><table>';
+ my $rem;
+ if (ref($ruleorder) eq 'ARRAY') {
+ for (my $i=0; $i<@{$ruleorder}; $i++) {
+ if (ref($rules->{$ruleorder->[$i]}) eq 'HASH') {
+ my $rem = $i%($numinrow);
+ if ($rem == 0) {
+ if ($i > 0) {
+ $output .= '</tr>';
+ }
+ $output .= '<tr>';
+ }
+ my $check = ' ';
+ if (ref($settings->{'username_rule'}) eq 'ARRAY') {
+ if (grep(/^\Q$ruleorder->[$i]\E$/,@{$settings->{'username_rule'}})) {
+ $check = ' checked="checked" ';
+ }
+ }
+ $output .= '<td class="LC_left_item">'.
+ '<span class="LC_nobreak"><label>'.
+ '<input type="checkbox" name="username_rule" '.
+ 'value="'.$ruleorder->[$i].'"'.$check.'/>'.
+ $rules->{$ruleorder->[$i]}{'name'}.'</label></span></td>';
+ }
+ }
+ $rem = @{$ruleorder}%($numinrow);
+ }
+ my $colsleft = $numinrow - $rem;
+ if ($colsleft > 1 ) {
+ $output .= '<td colspan="'.$colsleft.'" class="LC_left_item">'.
+ ' </td>';
+ } elsif ($colsleft == 1) {
+ $output .= '<td class="LC_left_item"> </td>';
+ }
+ $output .= '</tr></table></td></tr>';
+ return $output;
+}
+
sub users_cansearch_row {
my ($settings,$types,$usertypes,$dom,$numinrow,$othertitle) = @_;
my $output = '<tr class="LC_odd_row">'.
@@ -2156,6 +2243,100 @@
}
} else {
$resulttext = '<span class="LC_error">'.
+ &mt('An error occurred: [_1]',$putresult).'</span>';
+ }
+ return $resulttext;
+}
+
+sub modify_user_creation {
+ my ($dom,%domconfig) = @_;
+ my ($resulttext,%curr_usercreation,%changes);
+ if (ref($domconfig{'usercreation'}) eq 'HASH') {
+ foreach my $key (keys(%{$domconfig{'usercreation'}})) {
+ $curr_usercreation{$key} = $domconfig{'usercreation'}{$key};
+ }
+ }
+ my %title = &Apache::lonlocal::texthash (
+ author => 'adding co-authors/assistant authors',
+ course => 'adding users to a course',
+ );
+ my @username_rule = &Apache::loncommon::get_env_multiple('form.username_rule');
+ my @cancreate = &Apache::loncommon::get_env_multiple('form.can_createuser');
+ if (ref($curr_usercreation{'cancreate'}) eq 'ARRAY') {
+ foreach my $type (@{$curr_usercreation{'cancreate'}}) {
+ if (!grep(/^\Q$type\E$/,@cancreate)) {
+ push(@{$changes{'cancreate'}},$type);
+ }
+ }
+ foreach my $type (@cancreate) {
+ if (!grep(/^\Q$type\E$/,@{$curr_usercreation{'cancreate'}})) {
+ push(@{$changes{'cancreate'}},$type);
+ }
+ }
+ } else {
+ push(@{$changes{'cancreate'}},@cancreate);
+ }
+ if (ref($curr_usercreation{'username_rule'}) eq 'ARRAY') {
+ foreach my $type (@{$curr_usercreation{'username_rule'}}) {
+ if (!grep(/^\Q$type\E$/,@username_rule)) {
+ push(@{$changes{'username_rule'}},$type);
+ }
+ }
+ foreach my $type (@username_rule) {
+ if (!grep(/^\Q$type\E$/,@{$curr_usercreation{'username_rule'}})) {
+ push(@{$changes{'username_rule'}},$type);
+ }
+ }
+ } else {
+ push(@{$changes{'username_rule'}},@username_rule);
+ }
+
+ my %usercreation_hash = (
+ usercreation => {
+ cancreate => \@cancreate,
+ username_rule => \@username_rule,
+ }
+ );
+
+ my $putresult = &Apache::lonnet::put_dom('configuration',\%usercreation_hash,
+ $dom);
+ if ($putresult eq 'ok') {
+ if (keys(%changes) > 0) {
+ $resulttext = &mt('Changes made:').'<ul>';
+ my $chgtext;
+ if (ref($changes{'cancreate'}) eq 'ARRAY') {
+ my $chgtext = '<ul>';
+ foreach my $type (@cancreate) {
+ $chgtext .= '<li>'.$title{$type}.'</li>';
+ }
+ $chgtext .= '</ul>';
+ if (@cancreate > 0) {
+ $resulttext .= '<li>'.&mt('Creation of new users is permitted by a Domain Coordinator, and also by other users when: ').$chgtext.'</li>';
+ } else {
+ $resulttext .= '<li>'.&mt("Creation of new users is now only allowed when the user's role is Domain Coordinator.").'</li>';
+ }
+ }
+ if (ref($changes{'username_rule'}) eq 'ARRAY') {
+ my ($rules,$ruleorder) = &Apache::lonnet::inst_userrules($dom);
+ my $chgtext = '<ul>';
+ foreach my $type (@username_rule) {
+ if (ref($rules->{$type}) eq 'HASH') {
+ $chgtext .= '<li>'.$rules->{$type}{'name'}.'</li>';
+ }
+ }
+ $chgtext .= '</ul>';
+ if (@username_rule > 0) {
+ $resulttext .= '<li>'.&mt('Usernames with the following formats are restricted to verified users in the institutional directory: ').$chgtext.'</li>';
+ } else {
+ $resulttext .= '<li>'.&mt('There are now no username formats currenty restricted to verified users in the institutional directory.').'</li>';
+ }
+ }
+ $resulttext .= '</ul>';
+ } else {
+ $resulttext = &mt('No changes made to log-in page settings');
+ }
+ } else {
+ $resulttext = '<span class="LC_error">'.
&mt('An error occurred: [_1]',$putresult).'</span>';
}
return $resulttext;
--raeburn1189598466--