';
+ '';
+ if ($type eq 'email') {
+ $output .= &mt("Formats disallowed for $text{$type}: ");
+ } else {
+ $output .= &mt("Format rules to check for $text{$type}: ");
+ }
+ $output .= ' '.
+ '';
my $rem;
if (ref($ruleorder) eq 'ARRAY') {
for (my $i=0; $i<@{$ruleorder}; $i++) {
@@ -1637,13 +3209,18 @@ sub usercreation_types {
my %lt = &Apache::lonlocal::texthash (
author => 'When adding a co-author',
course => 'When adding a user to a course',
+ requestcrs => 'When requesting a course',
+ selfcreate => 'User creates own account',
any => 'Any',
official => 'Institutional only ',
unofficial => 'Non-institutional only',
+ email => 'E-mail address',
+ login => 'Institutional Login',
+ sso => 'SSO',
none => 'None',
);
return %lt;
-}
+}
sub authtype_names {
my %lt = &Apache::lonlocal::texthash(
@@ -1677,7 +3254,7 @@ sub print_usermodification {
$$rowtotal ++;
$rowcount ++;
}
- } else {
+ } elsif ($position eq 'middle') {
$context = 'course';
$rowcount = 0;
foreach my $role ('st','ep','ta','in','cr') {
@@ -1686,17 +3263,786 @@ sub print_usermodification {
$$rowtotal ++;
$rowcount ++;
}
+ } elsif ($position eq 'bottom') {
+ $context = 'selfcreate';
+ my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
+ $usertypes->{'default'} = $othertitle;
+ if (ref($types) eq 'ARRAY') {
+ push(@{$types},'default');
+ $usertypes->{'default'} = $othertitle;
+ foreach my $status (@{$types}) {
+ $datatable .= &modifiable_userdata_row($context,$status,$settings,
+ $numinrow,$rowcount,$usertypes);
+ $$rowtotal ++;
+ $rowcount ++;
+ }
+ }
+ }
+ return $datatable;
+}
+
+sub print_defaults {
+ my ($dom,$rowtotal) = @_;
+ my @items = ('auth_def','auth_arg_def','lang_def','timezone_def',
+ 'datelocale_def','portal_def');
+ my %domdefaults = &Apache::lonnet::get_domain_defaults($dom);
+ my $titles = &defaults_titles($dom);
+ my $rownum = 0;
+ my ($datatable,$css_class);
+ foreach my $item (@items) {
+ if ($rownum%2) {
+ $css_class = '';
+ } else {
+ $css_class = ' class="LC_odd_row" ';
+ }
+ $datatable .= ''.
+ ''.$titles->{$item}.
+ ' ';
+ if ($item eq 'auth_def') {
+ my @authtypes = ('internal','krb4','krb5','localauth');
+ my %shortauth = (
+ internal => 'int',
+ krb4 => 'krb4',
+ krb5 => 'krb5',
+ localauth => 'loc'
+ );
+ my %authnames = &authtype_names();
+ foreach my $auth (@authtypes) {
+ my $checked = ' ';
+ if ($domdefaults{$item} eq $auth) {
+ $checked = ' checked="checked" ';
+ }
+ $datatable .= ' '.
+ $authnames{$shortauth{$auth}}.' ';
+ }
+ } elsif ($item eq 'timezone_def') {
+ my $includeempty = 1;
+ $datatable .= &Apache::loncommon::select_timezone($item,$domdefaults{$item},undef,$includeempty);
+ } elsif ($item eq 'datelocale_def') {
+ my $includeempty = 1;
+ $datatable .= &Apache::loncommon::select_datelocale($item,$domdefaults{$item},undef,$includeempty);
+ } else {
+ my $size;
+ if ($item eq 'portal_def') {
+ $size = ' size="25"';
+ }
+ $datatable .= ' ';
+ }
+ $datatable .= ' ';
+ $rownum ++;
+ }
+ $$rowtotal += $rownum;
+ return $datatable;
+}
+
+sub defaults_titles {
+ my ($dom) = @_;
+ my %titles = &Apache::lonlocal::texthash (
+ 'auth_def' => 'Default authentication type',
+ 'auth_arg_def' => 'Default authentication argument',
+ 'lang_def' => 'Default language',
+ 'timezone_def' => 'Default timezone',
+ 'datelocale_def' => 'Default locale for dates',
+ 'portal_def' => 'Portal/Default URL',
+ );
+ if ($dom) {
+ my $uprimary_id = &Apache::lonnet::domain($dom,'primary');
+ my $uint_dom = &Apache::lonnet::internet_dom($uprimary_id);
+ my $protocol = $Apache::lonnet::protocol{$uprimary_id};
+ $protocol = 'http' if ($protocol ne 'https');
+ if ($uint_dom) {
+ $titles{'portal_def'} .= ' '.&mt('(for example: [_1])',$protocol.'://loncapa.'.
+ $uint_dom);
+ }
+ }
+ return (\%titles);
+}
+
+sub print_scantronformat {
+ my ($r,$dom,$confname,$settings,$rowtotal) = @_;
+ my $itemcount = 1;
+ my ($datatable,$css_class,$scantronurl,$is_custom,%error,%scantronurls,
+ %confhash);
+ my $switchserver = &check_switchserver($dom,$confname);
+ my %lt = &Apache::lonlocal::texthash (
+ default => 'Default bubblesheet format file error',
+ custom => 'Custom bubblesheet format file error',
+ );
+ my %scantronfiles = (
+ default => 'default.tab',
+ custom => 'custom.tab',
+ );
+ foreach my $key (keys(%scantronfiles)) {
+ $scantronurls{$key} = '/res/'.$dom.'/'.$confname.'/scantron/'
+ .$scantronfiles{$key};
+ }
+ my @defaultinfo = &Apache::lonnet::stat_file($scantronurls{'default'});
+ if ((!@defaultinfo) || ($defaultinfo[0] eq 'no_such_dir')) {
+ if (!$switchserver) {
+ my $servadm = $r->dir_config('lonAdmEMail');
+ my ($configuserok,$author_ok) = &config_check($dom,$confname,$servadm);
+ if ($configuserok eq 'ok') {
+ if ($author_ok eq 'ok') {
+ my %legacyfile = (
+ default => $Apache::lonnet::perlvar{'lonTabDir'}.'/default_scantronformat.tab',
+ custom => $Apache::lonnet::perlvar{'lonTabDir'}.'/scantronformat.tab',
+ );
+ my %md5chk;
+ foreach my $type (keys(%legacyfile)) {
+ ($md5chk{$type}) = split(/ /,`md5sum $legacyfile{$type}`);
+ chomp($md5chk{$type});
+ }
+ if ($md5chk{'default'} ne $md5chk{'custom'}) {
+ foreach my $type (keys(%legacyfile)) {
+ ($scantronurls{$type},my $error) =
+ &legacy_scantronformat($r,$dom,$confname,
+ $type,$legacyfile{$type},
+ $scantronurls{$type},
+ $scantronfiles{$type});
+ if ($error ne '') {
+ $error{$type} = $error;
+ }
+ }
+ if (keys(%error) == 0) {
+ $is_custom = 1;
+ $confhash{'scantron'}{'scantronformat'} =
+ $scantronurls{'custom'};
+ my $putresult =
+ &Apache::lonnet::put_dom('configuration',
+ \%confhash,$dom);
+ if ($putresult ne 'ok') {
+ $error{'custom'} =
+ ''.
+ &mt('An error occurred updating the domain configuration: [_1]',$putresult).' ';
+ }
+ }
+ } else {
+ ($scantronurls{'default'},my $error) =
+ &legacy_scantronformat($r,$dom,$confname,
+ 'default',$legacyfile{'default'},
+ $scantronurls{'default'},
+ $scantronfiles{'default'});
+ if ($error eq '') {
+ $confhash{'scantron'}{'scantronformat'} = '';
+ my $putresult =
+ &Apache::lonnet::put_dom('configuration',
+ \%confhash,$dom);
+ if ($putresult ne 'ok') {
+ $error{'default'} =
+ ''.
+ &mt('An error occurred updating the domain configuration: [_1]',$putresult).' ';
+ }
+ } else {
+ $error{'default'} = $error;
+ }
+ }
+ }
+ }
+ } else {
+ $error{'default'} = &mt("Unable to copy default bubblesheet formatfile to domain's RES space: [_1]",$switchserver);
+ }
+ }
+ if (ref($settings) eq 'HASH') {
+ if ($settings->{'scantronformat'} eq "/res/$dom/$confname/scantron/custom.tab") {
+ my @info = &Apache::lonnet::stat_file($settings->{'scantronformat'});
+ if ((!@info) || ($info[0] eq 'no_such_dir')) {
+ $scantronurl = '';
+ } else {
+ $scantronurl = $settings->{'scantronformat'};
+ }
+ $is_custom = 1;
+ } else {
+ $scantronurl = $scantronurls{'default'};
+ }
+ } else {
+ if ($is_custom) {
+ $scantronurl = $scantronurls{'custom'};
+ } else {
+ $scantronurl = $scantronurls{'default'};
+ }
+ }
+ $css_class = $itemcount%2?' class="LC_odd_row"':'';
+ $datatable .= '';
+ if (!$is_custom) {
+ $datatable .= ''.&mt('Default in use:').' '.
+ '';
+ if ($scantronurl) {
+ $datatable .= ''.
+ &mt('Default bubblesheet format file').' ';
+ } else {
+ $datatable = &mt('File unavailable for display');
+ }
+ $datatable .= ' ';
+ if (keys(%error) == 0) {
+ $datatable .= '';
+ if (!$switchserver) {
+ $datatable .= &mt('Upload:').' ';
+ }
+ } else {
+ my $errorstr;
+ foreach my $key (sort(keys(%error))) {
+ $errorstr .= $lt{$key}.': '.$error{$key}.' ';
+ }
+ $datatable .= ' '.$errorstr;
+ }
+ } else {
+ if (keys(%error) > 0) {
+ my $errorstr;
+ foreach my $key (sort(keys(%error))) {
+ $errorstr .= $lt{$key}.': '.$error{$key}.' ';
+ }
+ $datatable .= ' '.$errorstr.' ';
+ } elsif ($scantronurl) {
+ $datatable .= ' '.
+ ''.
+ &mt('Custom bubblesheet format file').' '.
+ ' '.&mt('Delete?').' '.
+ ' '.
+ &mt('Replace:').' ';
+ }
+ }
+ if (keys(%error) == 0) {
+ if ($switchserver) {
+ $datatable .= &mt('Upload to library server: [_1]',$switchserver);
+ } else {
+ $datatable .=' '.
+ ' ';
+ }
}
+ $datatable .= ' ';
+ $$rowtotal ++;
return $datatable;
}
+sub legacy_scantronformat {
+ my ($r,$dom,$confname,$file,$legacyfile,$newurl,$newfile) = @_;
+ my ($url,$error);
+ my @statinfo = &Apache::lonnet::stat_file($newurl);
+ if ((!@statinfo) || ($statinfo[0] eq 'no_such_dir')) {
+ (my $result,$url) =
+ &publishlogo($r,'copy',$legacyfile,$dom,$confname,'scantron',
+ '','',$newfile);
+ if ($result ne 'ok') {
+ $error = &mt("An error occurred publishing the [_1] bubblesheet format file in RES space. Error was: [_2].",$newfile,$result);
+ }
+ }
+ return ($url,$error);
+}
+
+sub print_coursecategories {
+ my ($position,$dom,$hdritem,$settings,$rowtotal) = @_;
+ my $datatable;
+ if ($position eq 'top') {
+ my $toggle_cats_crs = ' ';
+ my $toggle_cats_dom = ' checked="checked" ';
+ my $can_cat_crs = ' ';
+ my $can_cat_dom = ' checked="checked" ';
+ my $toggle_catscomm_comm = ' ';
+ my $toggle_catscomm_dom = ' checked="checked" ';
+ my $can_catcomm_comm = ' ';
+ my $can_catcomm_dom = ' checked="checked" ';
+
+ if (ref($settings) eq 'HASH') {
+ if ($settings->{'togglecats'} eq 'crs') {
+ $toggle_cats_crs = $toggle_cats_dom;
+ $toggle_cats_dom = ' ';
+ }
+ if ($settings->{'categorize'} eq 'crs') {
+ $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 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 Domain',
+ crs => 'Set in Course',
+ comm => 'Set in Community',
+ );
+ $datatable = ''.
+ ''.$title{'togglecats'}.' '.
+ ''.
+ ' '.$level{'dom'}.' '.
+ ' '.$level{'crs'}.' '.
+ ' '.
+ ''.$title{'categorize'}.' '.
+ ''.
+ ' '.$level{'dom'}.' '.
+ ' '.$level{'crs'}.' '.
+ ' '.
+ ''.$title{'togglecatscomm'}.' '.
+ ''.
+ ' '.$level{'dom'}.' '.
+ ' '.$level{'comm'}.' '.
+ ' '.
+ ''.$title{'categorizecomm'}.' '.
+ ''.
+ ' '.$level{'dom'}.' '.
+ ' '.$level{'comm'}.' '.
+ ' ';
+ $$rowtotal += 4;
+ } else {
+ my $css_class;
+ my $itemcount = 1;
+ my $cathash;
+ if (ref($settings) eq 'HASH') {
+ $cathash = $settings->{'cats'};
+ }
+ if (ref($cathash) eq 'HASH') {
+ my (@cats,@trails,%allitems,%idx,@jsarray);
+ &Apache::loncommon::extract_categories($cathash,\@cats,\@trails,
+ \%allitems,\%idx,\@jsarray);
+ my $maxdepth = scalar(@cats);
+ my $colattrib = '';
+ if ($maxdepth > 2) {
+ $colattrib = ' colspan="2" ';
+ }
+ my @path;
+ if (@cats > 0) {
+ if (ref($cats[0]) eq 'ARRAY') {
+ my $numtop = @{$cats[0]};
+ my $maxnum = $numtop;
+ 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;
+ for (my $i=0; $i<$numtop; $i++) {
+ my $parent = $cats[0][$i];
+ $css_class = $itemcount%2?' class="LC_odd_row"':'';
+ my $item = &escape($parent).'::0';
+ my $chgstr = ' onchange="javascript:reorderCats(this.form,'."'','$item','$idx{$item}'".');"';
+ $lastidx = $idx{$item};
+ $datatable .= ''
+ .'';
+ for (my $k=0; $k<=$maxnum; $k++) {
+ my $vpos = $k+1;
+ my $selstr;
+ if ($k == $i) {
+ $selstr = ' selected="selected" ';
+ }
+ $datatable .= ''.$vpos.' ';
+ }
+ $datatable .= ' ';
+ 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
+ .' '.&mt('Delete').' ';
+ }
+ my $depth = 1;
+ push(@path,$parent);
+ $datatable .= &build_category_rows($itemcount,\@cats,$depth,$parent,\@path,\%idx);
+ pop(@path);
+ $datatable .= ' ';
+ $itemcount ++;
+ }
+ $css_class = $itemcount%2?' class="LC_odd_row"':'';
+ my $chgstr = ' onchange="javascript:reorderCats(this.form,'."'','addcategory_pos','$lastidx'".');"';
+ $datatable .= '';
+ for (my $k=0; $k<=$maxnum; $k++) {
+ my $vpos = $k+1;
+ my $selstr;
+ if ($k == $numtop) {
+ $selstr = ' selected="selected" ';
+ }
+ $datatable .= ''.$vpos.' ';
+ }
+ $datatable .= ' '.&mt('Add category:').' '
+ .' '
+ .' '."\n";
+ $itemcount ++;
+ 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 .= ' '.
+ ''.
+ $default_names{$default}.' ';
+ if ($default eq 'instcode') {
+ $datatable .= '('
+ .&mt('with institutional codes').') ';
+ }
+ $datatable .= ' '
+ .' '
+ .&mt('Display').' '
+ .' '
+ .&mt('Do not display').' ';
+ }
+ }
+ }
+ } else {
+ $datatable .= &initialize_categories($itemcount);
+ }
+ } else {
+ $datatable .= ''.$hdritem->{'header'}->[0]->{'col2'}.' '
+ .&initialize_categories($itemcount);
+ }
+ $$rowtotal += $itemcount;
+ }
+ return $datatable;
+}
+
+sub print_serverstatuses {
+ my ($dom,$settings,$rowtotal) = @_;
+ my $datatable;
+ my @pages = &serverstatus_pages();
+ my (%namedaccess,%machineaccess);
+ foreach my $type (@pages) {
+ $namedaccess{$type} = '';
+ $machineaccess{$type}= '';
+ }
+ if (ref($settings) eq 'HASH') {
+ foreach my $type (@pages) {
+ if (exists($settings->{$type})) {
+ if (ref($settings->{$type}) eq 'HASH') {
+ foreach my $key (keys(%{$settings->{$type}})) {
+ if ($key eq 'namedusers') {
+ $namedaccess{$type} = $settings->{$type}->{$key};
+ } elsif ($key eq 'machines') {
+ $machineaccess{$type} = $settings->{$type}->{$key};
+ }
+ }
+ }
+ }
+ }
+ }
+ my $titles= &LONCAPA::lonauthcgi::serverstatus_titles();
+ my $rownum = 0;
+ my $css_class;
+ foreach my $type (@pages) {
+ $rownum ++;
+ $css_class = $rownum%2?' class="LC_odd_row"':'';
+ $datatable .= ''.
+ ''.
+ $titles->{$type}.' '.
+ ''.
+ ' '.
+ ''.
+ ''.
+ ' '.
+ ' '."\n";
+ }
+ $$rowtotal += $rownum;
+ return $datatable;
+}
+
+sub serverstatus_pages {
+ return ('userstatus','lonstatus','loncron','server-status','codeversions',
+ 'clusterstatus','metadata_keywords','metadata_harvest',
+ 'takeoffline','takeonline','showenv','toggledebug');
+}
+
+sub coursecategories_javascript {
+ my ($settings) = @_;
+ my ($output,$jstext,$cathash);
+ if (ref($settings) eq 'HASH') {
+ $cathash = $settings->{'cats'};
+ }
+ if (ref($cathash) eq 'HASH') {
+ my (@cats,@jsarray,%idx);
+ &Apache::loncommon::gather_categories($cathash,\@cats,\%idx,\@jsarray);
+ if (@jsarray > 0) {
+ $jstext = ' var categories = Array('.scalar(@jsarray).');'."\n";
+ for (my $i=0; $i<@jsarray; $i++) {
+ if (ref($jsarray[$i]) eq 'ARRAY') {
+ my $catstr = join('","',@{$jsarray[$i]});
+ $jstext .= ' categories['.$i.'] = Array("'.$catstr.'");'."\n";
+ }
+ }
+ }
+ } else {
+ $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";
+
+
+ENDSCRIPT
+ return $output;
+}
+
+sub initialize_categories {
+ my ($itemcount) = @_;
+ 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 ++;
+ }
+ $css_class = $itemcount%2?' class="LC_odd_row"':'';
+ $chgstr = ' onchange="javascript:reorderCats(this.form,'."'','addcategory_pos','0'".');"';
+ $datatable .= ''
+ .''
+ .'1 '
+ .'2 '
+ .'3 '
+ .&mt('Add category').' '.&mt('Name:')
+ .' ';
+ return $datatable;
+}
+
+sub build_category_rows {
+ my ($itemcount,$cats,$depth,$parent,$path,$idx) = @_;
+ my ($text,$name,$item,$chgstr);
+ if (ref($cats) eq 'ARRAY') {
+ my $maxdepth = scalar(@{$cats});
+ if (ref($cats->[$depth]) eq 'HASH') {
+ if (ref($cats->[$depth]{$parent}) eq 'ARRAY') {
+ my $numchildren = @{$cats->[$depth]{$parent}};
+ my $css_class = $itemcount%2?' class="LC_odd_row"':'';
+ $text .= '';
+ my ($idxnum,$parent_name,$parent_item);
+ my $higher = $depth - 1;
+ if ($higher == 0) {
+ $parent_name = &escape($parent).'::'.$higher;
+ } else {
+ if (ref($path) eq 'ARRAY') {
+ $parent_name = &escape($parent).':'.&escape($path->[-2]).':'.$higher;
+ }
+ }
+ $parent_item = 'addcategory_pos_'.$parent_name;
+ for (my $j=0; $j<=$numchildren; $j++) {
+ if ($j < $numchildren) {
+ $name = $cats->[$depth]{$parent}[$j];
+ $item = &escape($name).':'.&escape($parent).':'.$depth;
+ $idxnum = $idx->{$item};
+ } else {
+ $name = $parent_name;
+ $item = $parent_item;
+ }
+ $chgstr = ' onchange="javascript:reorderCats(this.form,'."'$parent_name','$item','$idxnum'".');"';
+ $text .= '';
+ for (my $i=0; $i<=$numchildren; $i++) {
+ my $vpos = $i+1;
+ my $selstr;
+ if ($j == $i) {
+ $selstr = ' selected="selected" ';
+ }
+ $text .= ''.$vpos.' ';
+ }
+ $text .= ' ';
+ if ($j < $numchildren) {
+ my $deeper = $depth+1;
+ $text .= $name.' '
+ .' '.&mt('Delete').'';
+ if(ref($path) eq 'ARRAY') {
+ push(@{$path},$name);
+ $text .= &build_category_rows($itemcount,$cats,$deeper,$name,$path,$idx);
+ pop(@{$path});
+ }
+ } else {
+ $text .= &mt('Add subcategory:').' ';
+ }
+ $text .= ' ';
+ }
+ $text .= '
';
+ } else {
+ my $higher = $depth-1;
+ if ($higher == 0) {
+ $name = &escape($parent).'::'.$higher;
+ } else {
+ if (ref($path) eq 'ARRAY') {
+ $name = &escape($parent).':'.&escape($path->[-2]).':'.$higher;
+ }
+ }
+ my $colspan;
+ if ($parent ne 'instcode') {
+ $colspan = $maxdepth - $depth - 1;
+ $text .= ''.&mt('Add subcategory:').' ';
+ }
+ }
+ }
+ }
+ return $text;
+}
+
sub modifiable_userdata_row {
- my ($context,$role,$settings,$numinrow,$rowcount) = @_;
+ my ($context,$role,$settings,$numinrow,$rowcount,$usertypes) = @_;
my $rolename;
- if ($role eq 'cr') {
- $rolename = &mt('Custom role');
+ if ($context eq 'selfcreate') {
+ if (ref($usertypes) eq 'HASH') {
+ $rolename = $usertypes->{$role};
+ } else {
+ $rolename = $role;
+ }
} else {
- $rolename = &Apache::lonnet::plaintext($role);
+ if ($role eq 'cr') {
+ $rolename = &mt('Custom role');
+ } else {
+ $rolename = &Apache::lonnet::plaintext($role);
+ }
}
my @fields = ('lastname','firstname','middlename','generation',
'permanentemail','id');
@@ -1755,10 +4101,19 @@ sub modifiable_userdata_row {
return $output;
}
-sub users_cansearch_row {
- my ($settings,$types,$usertypes,$dom,$numinrow,$othertitle) = @_;
+sub insttypes_row {
+ my ($settings,$types,$usertypes,$dom,$numinrow,$othertitle,$context) = @_;
+ my %lt = &Apache::lonlocal::texthash (
+ cansearch => 'Users allowed to search',
+ statustocreate => 'Institutional affiliation(s) able to create own account (login/SSO)',
+ lockablenames => 'User preference to lock name',
+ );
+ my $showdom;
+ if ($context eq 'cansearch') {
+ $showdom = ' ('.$dom.')';
+ }
my $output = ''.
- ''.&mt('Users allowed to search').' ('.$dom.')'.
+ ' '.$lt{$context}.$showdom.
' ';
return $output;
}
-sub sorted_inst_types {
- my ($dom) = @_;
- my ($usertypes,$order) = &Apache::lonnet::retrieve_inst_usertypes($dom);
- my $othertitle = &mt('All users');
- my @types;
- if (ref($order) eq 'ARRAY') {
- @types = @{$order};
- }
- if (@types == 0) {
- if (ref($usertypes) eq 'HASH') {
- @types = sort(keys(%{$usertypes}));
- }
- }
- if (keys(%{$usertypes}) > 0) {
- $othertitle = &mt('Other users');
- }
- return ($othertitle,$usertypes,\@types);
-}
-
sub sorted_searchtitles {
my %searchtitles = &Apache::lonlocal::texthash(
'uname' => 'username',
@@ -1901,51 +4247,181 @@ sub modify_login {
my ($resulttext,$errors,$colchgtext,%changes,%colchanges);
my %title = ( coursecatalog => 'Display course catalog',
adminmail => 'Display administrator E-mail address',
+ newuser => 'Link for visitors to create a user account',
loginheader => 'Log-in box header');
my @offon = ('off','on');
+ my %curr_loginvia;
+ if (ref($domconfig{login}) eq 'HASH') {
+ if (ref($domconfig{login}{loginvia}) eq 'HASH') {
+ foreach my $lonhost (keys(%{$domconfig{login}{loginvia}})) {
+ $curr_loginvia{$lonhost} = $domconfig{login}{loginvia}{$lonhost};
+ }
+ }
+ }
my %loginhash;
($errors,%colchanges) = &modify_colors($r,$dom,$confname,['login'],
\%domconfig,\%loginhash);
- $loginhash{login}{coursecatalog} = $env{'form.coursecatalog'};
- $loginhash{login}{adminmail} = $env{'form.adminmail'};
+ my @toggles = ('coursecatalog','adminmail','newuser');
+ foreach my $item (@toggles) {
+ $loginhash{login}{$item} = $env{'form.'.$item};
+ }
$loginhash{login}{loginheader} = $env{'form.loginheader'};
if (ref($colchanges{'login'}) eq 'HASH') {
$colchgtext = &display_colorchgs($dom,\%colchanges,['login'],
\%loginhash);
}
+
+ my %servers = &Apache::lonnet::internet_dom_servers($dom);
+ my @loginvia_attribs = ('serverpath','custompath','exempt');
+ if (keys(%servers) > 1) {
+ foreach my $lonhost (keys(%servers)) {
+ next if ($env{'form.'.$lonhost.'_server'} eq $lonhost);
+ if (ref($curr_loginvia{$lonhost}) eq 'HASH') {
+ if ($env{'form.'.$lonhost.'_server'} eq $curr_loginvia{$lonhost}{'server'}) {
+ $loginhash{login}{loginvia}{$lonhost}{'server'} = $curr_loginvia{$lonhost}{'server'};
+ } elsif ($curr_loginvia{$lonhost}{'server'} ne '') {
+ if (defined($servers{$env{'form.'.$lonhost.'_server'}})) {
+ $loginhash{login}{loginvia}{$lonhost}{'server'} = $env{'form.'.$lonhost.'_server'};
+ $changes{'loginvia'}{$lonhost} = 1;
+ } else {
+ $loginhash{login}{loginvia}{$lonhost}{'server'} = '';
+ $changes{'loginvia'}{$lonhost} = 1;
+ }
+ } else {
+ if (defined($servers{$env{'form.'.$lonhost.'_server'}})) {
+ $loginhash{login}{loginvia}{$lonhost}{'server'} = $env{'form.'.$lonhost.'_server'};
+ $changes{'loginvia'}{$lonhost} = 1;
+ }
+ }
+ if ($loginhash{login}{loginvia}{$lonhost}{'server'} eq '') {
+ foreach my $item (@loginvia_attribs) {
+ $loginhash{login}{loginvia}{$lonhost}{$item} = '';
+ }
+ } else {
+ foreach my $item (@loginvia_attribs) {
+ my $new = $env{'form.'.$lonhost.'_'.$item};
+ if (($item eq 'serverpath') && ($new eq 'custom')) {
+ $env{'form.'.$lonhost.'_custompath'} =~ s/\s+//g;
+ if ($env{'form.'.$lonhost.'_custompath'} eq '') {
+ $new = '/';
+ }
+ }
+ if (($item eq 'custompath') &&
+ ($env{'form.'.$lonhost.'_serverpath'} ne 'custom')) {
+ $new = '';
+ }
+ if ($new ne $curr_loginvia{$lonhost}{$item}) {
+ $changes{'loginvia'}{$lonhost} = 1;
+ }
+ if ($item eq 'exempt') {
+ $new =~ s/^\s+//;
+ $new =~ s/\s+$//;
+ my @poss_ips = split(/\s*[,:]\s*/,$new);
+ my @okips;
+ foreach my $ip (@poss_ips) {
+ if ($ip =~ /^\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}$/) {
+ if (($1 <= 255) && ($2 <= 255) && ($3 <= 255) && ($4 <= 255)) {
+ push(@okips,$ip);
+ }
+ }
+ }
+ if (@okips > 0) {
+ $new = join(',',@okips);
+ } else {
+ $new = '';
+ }
+ }
+
+ $loginhash{login}{loginvia}{$lonhost}{$item} = $new;
+ }
+ }
+ } else {
+ if (defined($servers{$env{'form.'.$lonhost.'_server'}})) {
+ $loginhash{login}{loginvia}{$lonhost}{'server'} = $env{'form.'.$lonhost.'_server'};
+ $changes{'loginvia'}{$lonhost} = 1;
+ foreach my $item (@loginvia_attribs) {
+ my $new = $env{'form.'.$lonhost.'_'.$item};
+ if (($item eq 'serverpath') && ($new eq 'custom')) {
+ if ($env{'form.'.$lonhost.'_custompath'} eq '') {
+ $new = '/';
+ }
+ }
+ if (($item eq 'custompath') &&
+ ($env{'form.'.$lonhost.'_serverpath'} ne 'custom')) {
+ $new = '';
+ }
+ $loginhash{login}{loginvia}{$lonhost}{$item} = $new;
+ }
+ }
+ }
+ }
+ }
+
my $putresult = &Apache::lonnet::put_dom('configuration',\%loginhash,
$dom);
if ($putresult eq 'ok') {
- if (($domconfig{'login'}{'coursecatalog'} eq '0') &&
- ($env{'form.coursecatalog'} eq '1')) {
- $changes{'coursecatalog'} = 1;
- } elsif (($domconfig{'login'}{'coursecatalog'} eq '' ||
- $domconfig{'login'}{'coursecatalog'} eq '1') &&
- ($env{'form.coursecatalog'} eq '0')) {
- $changes{'coursecatalog'} = 1;
- }
- if (($domconfig{'login'}{'adminmail'} eq '1') &&
- ($env{'form.adminmail'} eq '0')) {
- $changes{'adminmail'} = 1;
- } elsif (($domconfig{'login'}{'adminmail'} eq '' ||
- $domconfig{'login'}{'adminmail'} eq '0') &&
- ($env{'form.adminmail'} eq '1')) {
- $changes{'adminmail'} = 1;
- }
- if (($domconfig{'login'}{'loginheader'} eq 'text') &&
- ($env{'form.loginheader'} eq 'image')) {
- $changes{'loginheader'} = 1;
- } elsif (($domconfig{'login'}{'loginheader'} eq '' ||
- $domconfig{'login'}{'loginheader'} eq 'image') &&
- ($env{'form.loginheader'} eq 'text')) {
- $changes{'loginheader'} = 1;
+ my @toggles = ('coursecatalog','adminmail','newuser');
+ my %defaultchecked = (
+ 'coursecatalog' => 'on',
+ 'adminmail' => 'off',
+ 'newuser' => 'off',
+ );
+ if (ref($domconfig{'login'}) eq 'HASH') {
+ foreach my $item (@toggles) {
+ if ($defaultchecked{$item} eq 'on') {
+ if (($domconfig{'login'}{$item} eq '0') &&
+ ($env{'form.'.$item} eq '1')) {
+ $changes{$item} = 1;
+ } elsif (($domconfig{'login'}{$item} eq '' ||
+ $domconfig{'login'}{$item} eq '1') &&
+ ($env{'form.'.$item} eq '0')) {
+ $changes{$item} = 1;
+ }
+ } elsif ($defaultchecked{$item} eq 'off') {
+ if (($domconfig{'login'}{$item} eq '1') &&
+ ($env{'form.'.$item} eq '0')) {
+ $changes{$item} = 1;
+ } elsif (($domconfig{'login'}{$item} eq '' ||
+ $domconfig{'login'}{$item} eq '0') &&
+ ($env{'form.'.$item} eq '1')) {
+ $changes{$item} = 1;
+ }
+ }
+ }
}
if (keys(%changes) > 0 || $colchgtext) {
&Apache::loncommon::devalidate_domconfig_cache($dom);
$resulttext = &mt('Changes made:').'';
foreach my $item (sort(keys(%changes))) {
- if ($item eq 'loginheader') {
- $resulttext .= ''.&mt("$title{$item} set to $env{'form.loginheader'}").' ';
+ if ($item eq 'loginvia') {
+ if (ref($changes{$item}) eq 'HASH') {
+ $resulttext .= ''.&mt('Log-in page availability:').'';
+ foreach my $lonhost (sort(keys(%{$changes{$item}}))) {
+ if (defined($servers{$loginhash{login}{loginvia}{$lonhost}{'server'}})) {
+ if (ref($loginhash{login}{loginvia}{$lonhost}) eq 'HASH') {
+ my $protocol = $Apache::lonnet::protocol{$env{'form.'.$lonhost.'_server'}};
+ $protocol = 'http' if ($protocol ne 'https');
+ my $target = $protocol.'://'.$servers{$env{'form.'.$lonhost.'_server'}};
+
+ if ($loginhash{login}{loginvia}{$lonhost}{'serverpath'} eq 'custom') {
+ $target .= $loginhash{login}{loginvia}{$lonhost}{'custompath'};
+ } else {
+ $target .= $loginhash{login}{loginvia}{$lonhost}{'serverpath'};
+ }
+ $resulttext .= ''.&mt('Server: [_1] log-in page redirects to [_2].',$servers{$lonhost},''.$target.' ');
+ if ($loginhash{login}{loginvia}{$lonhost}{'exempt'} ne '') {
+ $resulttext .= ' '.&mt('No redirection for clients from following IPs:').' '.$loginhash{login}{loginvia}{$lonhost}{'exempt'};
+ }
+ $resulttext .= ' ';
+ } else {
+ $resulttext .= ''.&mt('Server: [_1] has standard log-in page.',$lonhost).' ';
+ }
+ } else {
+ $resulttext .= ''.&mt('Server: [_1] has standard log-in page.',$servers{$lonhost}).' ';
+ }
+ }
+ $resulttext .= ' ';
+ }
} else {
$resulttext .= ''.&mt("$title{$item} set to $offon[$env{'form.'.$item}]").' ';
}
@@ -1971,7 +4447,9 @@ sub color_font_choices {
img => "Header",
bgs => "Background colors",
links => "Link colors",
+ images => "Images",
font => "Font color",
+ fontmenu => "Font Menu",
pgbg => "Page",
tabbg => "Header",
sidebg => "Border",
@@ -1986,6 +4464,11 @@ sub modify_rolecolors {
my ($r,$dom,$confname,$roles,%domconfig) = @_;
my ($resulttext,%rolehash);
$rolehash{'rolecolors'} = {};
+ if (ref($domconfig{'rolecolors'}) ne 'HASH') {
+ if ($domconfig{'rolecolors'} eq '') {
+ $domconfig{'rolecolors'} = {};
+ }
+ }
my ($errors,%changes) = &modify_colors($r,$dom,$confname,$roles,
$domconfig{'rolecolors'},$rolehash{'rolecolors'});
my $putresult = &Apache::lonnet::put_dom('configuration',\%rolehash,
@@ -2012,7 +4495,7 @@ sub modify_rolecolors {
sub modify_colors {
my ($r,$dom,$confname,$roles,$domconfig,$confhash) = @_;
my (%changes,%choices);
- my @bgs = ('pgbg','mainbg','sidebg');
+ my @bgs;
my @links = ('link','alink','vlink');
my @logintext;
my @images;
@@ -2024,31 +4507,33 @@ sub modify_colors {
@logintext = ('textcol','bgcol');
} else {
%choices = &color_font_choices();
+ $confhash->{$role}{'fontmenu'} = $env{'form.'.$role.'_fontmenu'};
}
if ($role eq 'login') {
@images = ('img','logo','domlogo','login');
+ @bgs = ('pgbg','mainbg','sidebg');
} else {
@images = ('img');
+ @bgs = ('pgbg','tabbg','sidebg');
}
$confhash->{$role}{'font'} = $env{'form.'.$role.'_font'};
foreach my $item (@bgs,@links,@logintext) {
$confhash->{$role}{$item} = $env{'form.'.$role.'_'.$item};
}
- my ($configuserok,$author_ok,$switchserver,%currroles);
- my $uhome = &Apache::lonnet::homeserver($confname,$dom,1);
- ($configuserok,%currroles) = &check_configuser($uhome,$dom,
- $confname,$servadm);
- if ($configuserok eq 'ok') {
- $switchserver = &check_switchserver($dom,$confname);
- if ($switchserver eq '') {
- $author_ok = &check_authorstatus($dom,$confname,%currroles);
- }
- }
+ my ($configuserok,$author_ok,$switchserver) =
+ &config_check($dom,$confname,$servadm);
my ($width,$height) = &thumb_dimensions();
if (ref($domconfig->{$role}) ne 'HASH') {
$domconfig->{$role} = {};
}
foreach my $img (@images) {
+ if (($role eq 'login') && (($img eq 'img') || ($img eq 'logo'))) {
+ if (defined($env{'form.login_showlogo_'.$img})) {
+ $confhash->{$role}{'showlogo'}{$img} = 1;
+ } else {
+ $confhash->{$role}{'showlogo'}{$img} = 0;
+ }
+ }
if ( ! $env{'form.'.$role.'_'.$img.'.filename'}
&& !defined($domconfig->{$role}{$img})
&& !$env{'form.'.$role.'_del_'.$img}
@@ -2075,11 +4560,11 @@ sub modify_colors {
$error = &mt("Upload of [_1] image for $role page(s) failed because an error occurred publishing the file in RES space. Error was: [_2].",$choices{img},$result);
}
} else {
- $error = &mt("Upload of [_1] image for $role page(s) failed because an author role could not be assigned to a Domain Configuation user ([_2]) in domain: [_3]. Error was: [_4].",$choices{$img},$confname,$dom,$author_ok);
+ $error = &mt("Upload of [_1] image for $role page(s) failed because an author role could not be assigned to a Domain Configuration user ([_2]) in domain: [_3]. Error was: [_4].",$choices{$img},$confname,$dom,$author_ok);
}
}
} else {
- $error = &mt("Upload of [_1] image for $role page(s) failed because a Domain Configuation user ([_2]) could not be created in domain: [_3]. Error was: [_4].",$choices{$img},$confname,$dom,$configuserok);
+ $error = &mt("Upload of [_1] image for $role page(s) failed because a Domain Configuration user ([_2]) could not be created in domain: [_3]. Error was: [_4].",$choices{$img},$confname,$dom,$configuserok);
}
if ($error) {
&Apache::lonnet::logthis($error);
@@ -2123,7 +4608,19 @@ sub modify_colors {
$changes{$role}{'images'}{$img} = 1;
}
}
- }
+ if (($role eq 'login') && (($img eq 'logo') || ($img eq 'img'))) {
+ if (ref($domconfig->{'login'}{'showlogo'}) eq 'HASH') {
+ if ($confhash->{$role}{'showlogo'}{$img} ne
+ $domconfig->{$role}{'showlogo'}{$img}) {
+ $changes{$role}{'showlogo'}{$img} = 1;
+ }
+ } else {
+ if ($confhash->{$role}{'showlogo'}{$img} == 0) {
+ $changes{$role}{'showlogo'}{$img} = 1;
+ }
+ }
+ }
+ }
if ($domconfig->{$role}{'font'} ne '') {
if ($confhash->{$role}{'font'} ne $domconfig->{$role}{'font'}) {
$changes{$role}{'font'} = 1;
@@ -2133,6 +4630,17 @@ sub modify_colors {
$changes{$role}{'font'} = 1;
}
}
+ if ($role ne 'login') {
+ if ($domconfig->{$role}{'fontmenu'} ne '') {
+ if ($confhash->{$role}{'fontmenu'} ne $domconfig->{$role}{'fontmenu'}) {
+ $changes{$role}{'fontmenu'} = 1;
+ }
+ } else {
+ if ($confhash->{$role}{'fontmenu'}) {
+ $changes{$role}{'fontmenu'} = 1;
+ }
+ }
+ }
foreach my $item (@bgs) {
if ($domconfig->{$role}{$item} ne '') {
if ($confhash->{$role}{$item} ne $domconfig->{$role}{$item}) {
@@ -2178,6 +4686,21 @@ sub modify_colors {
return ($errors,%changes);
}
+sub config_check {
+ my ($dom,$confname,$servadm) = @_;
+ my ($configuserok,$author_ok,$switchserver,%currroles);
+ my $uhome = &Apache::lonnet::homeserver($confname,$dom,1);
+ ($configuserok,%currroles) = &check_configuser($uhome,$dom,
+ $confname,$servadm);
+ if ($configuserok eq 'ok') {
+ $switchserver = &check_switchserver($dom,$confname);
+ if ($switchserver eq '') {
+ $author_ok = &check_authorstatus($dom,$confname,%currroles);
+ }
+ }
+ return ($configuserok,$author_ok,$switchserver);
+}
+
sub default_change_checker {
my ($role,$images,$links,$bgs,$logintext,$confhash,$changes) = @_;
foreach my $item (@{$links}) {
@@ -2200,11 +4723,16 @@ sub default_change_checker {
$confhash->{$role}{$img} = '';
$changes->{$role}{'images'}{$img} = 1;
}
+ if ($role eq 'login') {
+ if ($confhash->{$role}{'showlogo'}{$img} == 0) {
+ $changes->{$role}{'showlogo'}{$img} = 1;
+ }
+ }
}
if ($confhash->{$role}{'font'}) {
$changes->{$role}{'font'} = 1;
}
-}
+}
sub display_colorchgs {
my ($dom,$changes,$roles,$confhash) = @_;
@@ -2231,7 +4759,13 @@ sub display_colorchgs {
$resulttext .= ''.&mt($choices{$key}).':';
}
foreach my $item (sort(keys(%{$changes->{$role}{$key}}))) {
- if ($confhash->{$role}{$item} eq '') {
+ if (($role eq 'login') && ($key eq 'showlogo')) {
+ if ($confhash->{$role}{$key}{$item}) {
+ $resulttext .= ''.&mt("$choices{$item} set to be displayed").' ';
+ } else {
+ $resulttext .= ''.&mt("$choices{$item} set to not be displayed").' ';
+ }
+ } elsif ($confhash->{$role}{$item} eq '') {
$resulttext .= ''.&mt("$choices{$item} set to default").' ';
} else {
my $newitem = $confhash->{$role}{$item};
@@ -2309,7 +4843,7 @@ sub check_authorstatus {
my $end = 0;
$author_ok =
&Apache::lonnet::assignrole($dom,$confname,'/'.$dom.'/',
- 'au',$end,$start);
+ 'au',$end,$start,'','','domconfig');
} else {
$author_ok = 'ok';
}
@@ -2317,7 +4851,7 @@ sub check_authorstatus {
}
sub publishlogo {
- my ($r,$action,$formname,$dom,$confname,$subdir,$thumbwidth,$thumbheight) = @_;
+ my ($r,$action,$formname,$dom,$confname,$subdir,$thumbwidth,$thumbheight,$savefileas) = @_;
my ($output,$fname,$logourl);
if ($action eq 'upload') {
$fname=$env{'form.'.$formname.'.filename'};
@@ -2325,6 +4859,9 @@ sub publishlogo {
} else {
($fname) = ($formname =~ /([^\/]+)$/);
}
+ if ($savefileas ne '') {
+ $fname = $savefileas;
+ }
$fname=&Apache::lonnet::clean_filename($fname);
# See if there is anything left
unless ($fname) { return ('error: no uploaded file'); }
@@ -2352,7 +4889,7 @@ sub publishlogo {
!defined(&Apache::loncommon::fileembstyle($1))) {
$output = &mt('Unrecognized file extension ([_1]) - rename the file with a proper extension and re-upload.',$1);
} elsif ($file=~/\.(\d+)\.(\w+)$/) {
- $output = &mt('File name not allowed a rename the file to remove the number immediately before the file extension([_1]) and re-upload.',$2);
+ $output = &mt('File name not allowed - rename the file to remove the number immediately before the file extension([_1]) and re-upload.',$2);
} elsif (-d "$filepath/$file") {
$output = &mt('File name is a directory name - rename the file and re-upload');
} else {
@@ -2533,67 +5070,273 @@ sub check_switchserver {
return $switchserver;
}
-sub javascript_set_colnums {
- return < 1100) {
- document.pickactions.numcols[1].checked = true;
+sub modify_quotas {
+ my ($dom,$action,%domconfig) = @_;
+ my ($context,@usertools,@options,%validations,%titles,%confhash,%toolshash,
+ %limithash,$toolregexp,%conditions,$resulttext,%changes);
+ if ($action eq 'quotas') {
+ $context = 'tools';
+ } else {
+ $context = $action;
+ }
+ if ($context eq 'requestcourses') {
+ @usertools = ('official','unofficial','community');
+ @options =('norequest','approval','validate','autolimit');
+ %validations = &Apache::lonnet::auto_courserequest_checks($dom);
+ %titles = &courserequest_titles();
+ $toolregexp = join('|',@usertools);
+ %conditions = &courserequest_conditions();
} else {
- document.pickactions.numcols[0].checked = true;
+ @usertools = ('aboutme','blog','portfolio');
+ %titles = &tool_titles();
}
-}
-END
-}
-
-sub modify_quotas {
- my ($dom,%domconfig) = @_;
- my ($resulttext,%changes);
- my ($othertitle,$usertypes,$types) = &sorted_inst_types($dom);
- my %formhash;
+ my %domdefaults = &Apache::lonnet::get_domain_defaults($dom);
+ my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
foreach my $key (keys(%env)) {
- if ($key =~ /^form\.quota_(.+)$/) {
- $formhash{$1} = $env{$key};
+ if ($context eq 'requestcourses') {
+ if ($key =~ /^form\.crsreq_($toolregexp)_(.+)$/) {
+ my $item = $1;
+ my $type = $2;
+ if ($type =~ /^limit_(.+)/) {
+ $limithash{$item}{$1} = $env{$key};
+ } else {
+ $confhash{$item}{$type} = $env{$key};
+ }
+ }
+ } else {
+ if ($key =~ /^form\.quota_(.+)$/) {
+ $confhash{'defaultquota'}{$1} = $env{$key};
+ }
+ if ($key =~ /^form\.\Q$context\E_(.+)$/) {
+ @{$toolshash{$1}} = &Apache::loncommon::get_env_multiple($key);
+ }
}
}
- $formhash{'default'} = $env{'form.defaultquota'};
- if (ref($domconfig{'quotas'}) eq 'HASH') {
- foreach my $key (keys(%{$domconfig{'quotas'}})) {
- if (exists($formhash{$key})) {
- if ($formhash{$key} ne $domconfig{'quotas'}{$key}) {
- $changes{$key} = 1;
+ if ($context eq 'requestcourses') {
+ my @approvalnotify = &Apache::loncommon::get_env_multiple('form.reqapprovalnotify');
+ @approvalnotify = sort(@approvalnotify);
+ $confhash{'notify'}{'approval'} = join(',',@approvalnotify);
+ if (ref($domconfig{$action}) eq 'HASH') {
+ if (ref($domconfig{$action}{'notify'}) eq 'HASH') {
+ if ($domconfig{$action}{'notify'}{'approval'} ne $confhash{'notify'}{'approval'}) {
+ $changes{'notify'}{'approval'} = 1;
}
} else {
- $formhash{$key} = $domconfig{'quotas'}{$key};
+ if ($confhash{'notify'}{'approval'}) {
+ $changes{'notify'}{'approval'} = 1;
+ }
+ }
+ } else {
+ if ($confhash{'notify'}{'approval'}) {
+ $changes{'notify'}{'approval'} = 1;
}
}
+ } else {
+ $confhash{'defaultquota'}{'default'} = $env{'form.defaultquota'};
}
- foreach my $key (keys(%formhash)) {
- if ($formhash{$key} ne '') {
- if (!exists($domconfig{'quotas'}{$key})) {
- $changes{$key} = 1;
+ foreach my $item (@usertools) {
+ foreach my $type (@{$types},'default','_LC_adv') {
+ my $unset;
+ if ($context eq 'requestcourses') {
+ $unset = '0';
+ if ($type eq '_LC_adv') {
+ $unset = '';
+ }
+ if ($confhash{$item}{$type} eq 'autolimit') {
+ $confhash{$item}{$type} .= '=';
+ unless ($limithash{$item}{$type} =~ /\D/) {
+ $confhash{$item}{$type} .= $limithash{$item}{$type};
+ }
+ }
+ } else {
+ if (grep(/^\Q$type\E$/,@{$toolshash{$item}})) {
+ $confhash{$item}{$type} = 1;
+ } else {
+ $confhash{$item}{$type} = 0;
+ }
+ }
+ if (ref($domconfig{$action}) eq 'HASH') {
+ if (ref($domconfig{$action}{$item}) eq 'HASH') {
+ if ($domconfig{$action}{$item}{$type} ne $confhash{$item}{$type}) {
+ $changes{$item}{$type} = 1;
+ }
+ } else {
+ if ($context eq 'requestcourses') {
+ if ($confhash{$item}{$type} ne $unset) {
+ $changes{$item}{$type} = 1;
+ }
+ } else {
+ if (!$confhash{$item}{$type}) {
+ $changes{$item}{$type} = 1;
+ }
+ }
+ }
+ } else {
+ if ($context eq 'requestcourses') {
+ if ($confhash{$item}{$type} ne $unset) {
+ $changes{$item}{$type} = 1;
+ }
+ } else {
+ if (!$confhash{$item}{$type}) {
+ $changes{$item}{$type} = 1;
+ }
+ }
}
}
}
+ unless ($context eq 'requestcourses') {
+ if (ref($domconfig{'quotas'}) eq 'HASH') {
+ if (ref($domconfig{'quotas'}{'defaultquota'}) eq 'HASH') {
+ foreach my $key (keys(%{$domconfig{'quotas'}{'defaultquota'}})) {
+ if (exists($confhash{'defaultquota'}{$key})) {
+ if ($confhash{'defaultquota'}{$key} ne $domconfig{'quotas'}{'defaultquota'}{$key}) {
+ $changes{'defaultquota'}{$key} = 1;
+ }
+ } else {
+ $confhash{'defaultquota'}{$key} = $domconfig{'quotas'}{'defaultquota'}{$key};
+ }
+ }
+ } else {
+ foreach my $key (keys(%{$domconfig{'quotas'}})) {
+ if (exists($confhash{'defaultquota'}{$key})) {
+ if ($confhash{'defaultquota'}{$key} ne $domconfig{'quotas'}{$key}) {
+ $changes{'defaultquota'}{$key} = 1;
+ }
+ } else {
+ $confhash{'defaultquota'}{$key} = $domconfig{'quotas'}{$key};
+ }
+ }
+ }
+ }
+ if (ref($confhash{'defaultquota'}) eq 'HASH') {
+ foreach my $key (keys(%{$confhash{'defaultquota'}})) {
+ if (ref($domconfig{'quotas'}) eq 'HASH') {
+ if (ref($domconfig{'quotas'}{'defaultquota'}) eq 'HASH') {
+ if (!exists($domconfig{'quotas'}{'defaultquota'}{$key})) {
+ $changes{'defaultquota'}{$key} = 1;
+ }
+ } else {
+ if (!exists($domconfig{'quotas'}{$key})) {
+ $changes{'defaultquota'}{$key} = 1;
+ }
+ }
+ } else {
+ $changes{'defaultquota'}{$key} = 1;
+ }
+ }
+ }
+ }
+
+ foreach my $key (keys(%confhash)) {
+ $domdefaults{$key} = $confhash{$key};
+ }
+
my %quotahash = (
- quotas => {%formhash},
+ $action => { %confhash }
);
my $putresult = &Apache::lonnet::put_dom('configuration',\%quotahash,
$dom);
if ($putresult eq 'ok') {
if (keys(%changes) > 0) {
+ my $cachetime = 24*60*60;
+ &Apache::lonnet::do_cache_new('domdefaults',$dom,\%domdefaults,$cachetime);
+
$resulttext = &mt('Changes made:').'';
- foreach my $type (@{$types},'default') {
- if (defined($changes{$type})) {
- my $typetitle = $usertypes->{$type};
- if ($type eq 'default') {
- $typetitle = $othertitle;
+ unless ($context eq 'requestcourses') {
+ if (ref($changes{'defaultquota'}) eq 'HASH') {
+ $resulttext .= ''.&mt('Portfolio default quotas').'';
+ foreach my $type (@{$types},'default') {
+ if (defined($changes{'defaultquota'}{$type})) {
+ my $typetitle = $usertypes->{$type};
+ if ($type eq 'default') {
+ $typetitle = $othertitle;
+ }
+ $resulttext .= ''.&mt('[_1] set to [_2] Mb',$typetitle,$confhash{'defaultquota'}{$type}).' ';
+ }
+ }
+ $resulttext .= ' ';
+ }
+ }
+ my %newenv;
+ foreach my $item (@usertools) {
+ if (ref($changes{$item}) eq 'HASH') {
+ my $newacc =
+ &Apache::lonnet::usertools_access($env{'user.name'},
+ $env{'user.domain'},
+ $item,'reload',$context);
+ if ($context eq 'requestcourses') {
+ if ($env{'environment.canrequest.'.$item} ne $newacc) {
+ $newenv{'environment.canrequest.'.$item} = $newacc;
+ }
+ } else {
+ if ($env{'environment.availabletools.'.$item} ne $newacc) {
+ $newenv{'environment.availabletools.'.$item} = $newacc;
+ }
+ }
+ $resulttext .= ''.$titles{$item}.'';
+ foreach my $type (@{$types},'default','_LC_adv') {
+ if ($changes{$item}{$type}) {
+ my $typetitle = $usertypes->{$type};
+ if ($type eq 'default') {
+ $typetitle = $othertitle;
+ } elsif ($type eq '_LC_adv') {
+ $typetitle = 'LON-CAPA Advanced Users';
+ }
+ if ($confhash{$item}{$type}) {
+ if ($context eq 'requestcourses') {
+ my $cond;
+ if ($confhash{$item}{$type} =~ /^autolimit=(\d*)$/) {
+ if ($1 eq '') {
+ $cond = &mt('(Automatic processing of any request).');
+ } else {
+ $cond = &mt('(Automatic processing of requests up to limit of [quant,_1,request] per user).',$1);
+ }
+ } else {
+ $cond = $conditions{$confhash{$item}{$type}};
+ }
+ $resulttext .= ''.&mt('Set to be available to [_1].',$typetitle).' '.$cond.' ';
+ } else {
+ $resulttext .= ''.&mt('Set to be available to [_1]',$typetitle).' ';
+ }
+ } else {
+ if ($type eq '_LC_adv') {
+ if ($confhash{$item}{$type} eq '0') {
+ $resulttext .= ''.&mt('Set to be unavailable to [_1]',$typetitle).' ';
+ } else {
+ $resulttext .= ''.&mt('No override set for [_1]',$typetitle).' ';
+ }
+ } else {
+ $resulttext .= ''.&mt('Set to be unavailable to [_1]',$typetitle).' ';
+ }
+ }
+ }
+ }
+ $resulttext .= ' ';
+ }
+ }
+ if ($action eq 'requestcourses') {
+ if (ref($changes{'notify'}) eq 'HASH') {
+ if ($changes{'notify'}{'approval'}) {
+ if (ref($confhash{'notify'}) eq 'HASH') {
+ if ($confhash{'notify'}{'approval'}) {
+ $resulttext .= ''.&mt('Notification of requests requiring approval will be sent to: ').$confhash{'notify'}{'approval'}.' ';
+ } else {
+ $resulttext .= ''.&mt('No Domain Coordinators will receive notification of course requests requiring approval.').' ';
+ }
+ }
}
- $resulttext .= ''.&mt('[_1] set to [_2] Mb',$typetitle,$formhash{$type}).' ';
}
}
$resulttext .= ' ';
+ if (keys(%newenv)) {
+ &Apache::lonnet::appenv(\%newenv);
+ }
} else {
- $resulttext = &mt('No changes made to default quotas');
+ if ($context eq 'requestcourses') {
+ $resulttext = &mt('No changes made to rights to request creation of courses.');
+ } else {
+ $resulttext = &mt('No changes made to availability of personal information pages, blogs, portfolios or default quotas');
+ }
}
} else {
$resulttext = ''.
@@ -2613,7 +5356,8 @@ sub modify_autoenroll {
}
my $autorun = &Apache::lonnet::auto_run(undef,$dom),
my %title = ( run => 'Auto-enrollment active',
- sender => 'Sender for notification messages');
+ sender => 'Sender for notification messages',
+ coowners => 'Automatic assignment of co-ownership to instructors of record (institutional data)');
my @offon = ('off','on');
my $sender_uname = $env{'form.sender_uname'};
my $sender_domain = $env{'form.sender_domain'};
@@ -2622,11 +5366,12 @@ sub modify_autoenroll {
} elsif ($sender_uname eq '') {
$sender_domain = '';
}
+ my $coowners = $env{'form.autoassign_coowners'};
my %autoenrollhash = (
- autoenroll => { run => $env{'form.autoenroll_run'},
- sender_uname => $sender_uname,
- sender_domain => $sender_domain,
-
+ autoenroll => { 'run' => $env{'form.autoenroll_run'},
+ 'sender_uname' => $sender_uname,
+ 'sender_domain' => $sender_domain,
+ 'co-owners' => $coowners,
}
);
my $putresult = &Apache::lonnet::put_dom('configuration',\%autoenrollhash,
@@ -2647,6 +5392,13 @@ sub modify_autoenroll {
if ($currautoenroll{'sender_domain'} ne $sender_domain) {
$changes{'sender'} = 1;
}
+ if ($currautoenroll{'co-owners'} ne '') {
+ if ($currautoenroll{'co-owners'} ne $coowners) {
+ $changes{'coowners'} = 1;
+ }
+ } elsif ($coowners) {
+ $changes{'coowners'} = 1;
+ }
if (keys(%changes) > 0) {
$resulttext = &mt('Changes made:').'';
if ($changes{'run'}) {
@@ -2659,6 +5411,10 @@ sub modify_autoenroll {
$resulttext .= ''.&mt("$title{'sender'} set to [_1]",$sender_uname.':'.$sender_domain).' ';
}
}
+ if ($changes{'coowners'}) {
+ $resulttext .= ''.&mt("$title{'coowners'} set to $offon[$env{'form.autoassign_coowners'}]").' ';
+ &Apache::loncommon::devalidate_domconfig_cache($dom);
+ }
$resulttext .= ' ';
} else {
$resulttext = &mt('No changes made to auto-enrollment settings');
@@ -2683,28 +5439,50 @@ sub modify_autoupdate {
run => 'Auto-update:',
classlists => 'Updates to user information in classlists?'
);
- my ($othertitle,$usertypes,$types) = &sorted_inst_types($dom);
+ my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
my %fieldtitles = &Apache::lonlocal::texthash (
id => 'Student/Employee ID',
permanentemail => 'E-mail address',
lastname => 'Last Name',
firstname => 'First Name',
middlename => 'Middle Name',
- gen => 'Generation',
+ generation => 'Generation',
);
- my $othertitle = &mt('All users');
+ $othertitle = &mt('All users');
if (keys(%{$usertypes}) > 0) {
$othertitle = &mt('Other users');
}
foreach my $key (keys(%env)) {
if ($key =~ /^form\.updateable_(.+)_([^_]+)$/) {
- push(@{$fields{$1}},$2);
+ my ($usertype,$item) = ($1,$2);
+ if (grep(/^\Q$item\E$/,keys(%fieldtitles))) {
+ if ($usertype eq 'default') {
+ push(@{$fields{$1}},$2);
+ } elsif (ref($types) eq 'ARRAY') {
+ if (grep(/^\Q$usertype\E$/,@{$types})) {
+ push(@{$fields{$1}},$2);
+ }
+ }
+ }
+ }
+ }
+ my @lockablenames = &Apache::loncommon::get_env_multiple('form.lockablenames');
+ @lockablenames = sort(@lockablenames);
+ if (ref($currautoupdate{'lockablenames'}) eq 'ARRAY') {
+ my @changed = &Apache::loncommon::compare_arrays($currautoupdate{'lockablenames'},\@lockablenames);
+ if (@changed) {
+ $changes{'lockablenames'} = 1;
+ }
+ } else {
+ if (@lockablenames) {
+ $changes{'lockablenames'} = 1;
}
}
my %updatehash = (
autoupdate => { run => $env{'form.autoupdate_run'},
classlists => $env{'form.classlists'},
fields => {%fields},
+ lockablenames => \@lockablenames,
}
);
foreach my $key (keys(%currautoupdate)) {
@@ -2722,9 +5500,11 @@ sub modify_autoupdate {
foreach my $type (@{$currautoupdate{$key}{$item}}) {
if (!exists($fields{$item})) {
$change = 1;
+ last;
} elsif (ref($fields{$item}) eq 'ARRAY') {
if (!grep(/^\Q$type\E$/,@{$fields{$item}})) {
$change = 1;
+ last;
}
}
}
@@ -2734,12 +5514,41 @@ sub modify_autoupdate {
}
}
}
+ } elsif ($key eq 'lockablenames') {
+ if (ref($currautoupdate{$key}) eq 'ARRAY') {
+ my @changed = &Apache::loncommon::compare_arrays($currautoupdate{'lockablenames'},\@lockablenames);
+ if (@changed) {
+ $changes{'lockablenames'} = 1;
+ }
+ } else {
+ if (@lockablenames) {
+ $changes{'lockablenames'} = 1;
+ }
+ }
+ }
+ }
+ unless (grep(/^\Qlockablenames\E$/,keys(%currautoupdate))) {
+ if (@lockablenames) {
+ $changes{'lockablenames'} = 1;
}
}
foreach my $item (@{$types},'default') {
if (defined($fields{$item})) {
if (ref($currautoupdate{'fields'}) eq 'HASH') {
- if (!exists($currautoupdate{'fields'}{$item})) {
+ if (ref($currautoupdate{'fields'}{$item}) eq 'ARRAY') {
+ my $change = 0;
+ if (ref($fields{$item}) eq 'ARRAY') {
+ foreach my $type (@{$fields{$item}}) {
+ if (!grep(/^\Q$type\E$/,@{$currautoupdate{'fields'}{$item}})) {
+ $change = 1;
+ last;
+ }
+ }
+ }
+ if ($change) {
+ push(@{$changes{'fields'}},$item);
+ }
+ } else {
push(@{$changes{'fields'}},$item);
}
} else {
@@ -2753,7 +5562,17 @@ sub modify_autoupdate {
if (keys(%changes) > 0) {
$resulttext = &mt('Changes made:').'';
foreach my $key (sort(keys(%changes))) {
- if (ref($changes{$key}) eq 'ARRAY') {
+ if ($key eq 'lockablenames') {
+ $resulttext .= '';
+ if (@lockablenames) {
+ $usertypes->{'default'} = $othertitle;
+ $resulttext .= &mt("User preference to disable replacement of user's name with institutional data (by auto-update), available for the following affiliations:").' '.
+ join(', ', map { $usertypes->{$_}; } @lockablenames).' ';
+ } else {
+ $resulttext .= &mt("User preference to disable replacement of user's name with institutional data (by auto-update) is unavailable.");
+ }
+ $resulttext .= ' ';
+ } elsif (ref($changes{$key}) eq 'ARRAY') {
foreach my $item (@{$changes{$key}}) {
my @newvalues;
foreach my $type (@{$fields{$item}}) {
@@ -2792,6 +5611,78 @@ sub modify_autoupdate {
return $resulttext;
}
+sub modify_autocreate {
+ my ($dom,%domconfig) = @_;
+ my ($resulttext,%changes,%currautocreate,%newvals,%autocreatehash);
+ if (ref($domconfig{'autocreate'}) eq 'HASH') {
+ foreach my $key (keys(%{$domconfig{'autocreate'}})) {
+ $currautocreate{$key} = $domconfig{'autocreate'}{$key};
+ }
+ }
+ my %title= ( xml => 'Auto-creation of courses in XML course description files',
+ req => 'Auto-creation of validated requests for official courses',
+ xmldc => 'Identity of course creator of courses from XML files',
+ );
+ my @types = ('xml','req');
+ foreach my $item (@types) {
+ $newvals{$item} = $env{'form.autocreate_'.$item};
+ $newvals{$item} =~ s/\D//g;
+ $newvals{$item} = 0 if ($newvals{$item} eq '');
+ }
+ $newvals{'xmldc'} = $env{'form.autocreate_xmldc'};
+ my %domcoords = &get_active_dcs($dom);
+ unless (exists($domcoords{$newvals{'xmldc'}})) {
+ $newvals{'xmldc'} = '';
+ }
+ %autocreatehash = (
+ autocreate => { xml => $newvals{'xml'},
+ req => $newvals{'req'},
+ }
+ );
+ if ($newvals{'xmldc'} ne '') {
+ $autocreatehash{'autocreate'}{'xmldc'} = $newvals{'xmldc'};
+ }
+ my $putresult = &Apache::lonnet::put_dom('configuration',\%autocreatehash,
+ $dom);
+ if ($putresult eq 'ok') {
+ my @items = @types;
+ if ($newvals{'xml'}) {
+ push(@items,'xmldc');
+ }
+ foreach my $item (@items) {
+ if (exists($currautocreate{$item})) {
+ if ($currautocreate{$item} ne $newvals{$item}) {
+ $changes{$item} = 1;
+ }
+ } elsif ($newvals{$item}) {
+ $changes{$item} = 1;
+ }
+ }
+ if (keys(%changes) > 0) {
+ my @offon = ('off','on');
+ $resulttext = &mt('Changes made:').'';
+ foreach my $item (@types) {
+ if ($changes{$item}) {
+ my $newtxt = $offon[$newvals{$item}];
+ $resulttext .= ''.&mt("$title{$item} set to [_1]$newtxt [_2]",'',' ').' ';
+ }
+ }
+ if ($changes{'xmldc'}) {
+ my ($dcname,$dcdom) = split(':',$newvals{'xmldc'});
+ my $newtxt = &Apache::loncommon::plainname($dcname,$dcdom);
+ $resulttext .= ''.&mt("$title{'xmldc'} set to [_1]$newtxt [_2]",'',' ').' ';
+ }
+ $resulttext .= ' ';
+ } else {
+ $resulttext = &mt('No changes made to auto-creation settings');
+ }
+ } else {
+ $resulttext = ''.
+ &mt('An error occurred: [_1]',$putresult).' ';
+ }
+ return $resulttext;
+}
+
sub modify_directorysrch {
my ($dom,%domconfig) = @_;
my ($resulttext,%changes);
@@ -2812,7 +5703,7 @@ sub modify_directorysrch {
my @cansearch = &Apache::loncommon::get_env_multiple('form.cansearch');
my @searchby = &Apache::loncommon::get_env_multiple('form.searchby');
- my ($othertitle,$usertypes,$types) = &sorted_inst_types($dom);
+ my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
if (keys(%{$usertypes}) == 0) {
@cansearch = ('default');
} else {
@@ -2974,9 +5865,10 @@ sub modify_contacts {
$currsetting{$key} = $domconfig{'contacts'}{$key};
}
}
- my (%others,%to);
+ my (%others,%to,%bcc);
my @contacts = ('supportemail','adminemail');
- my @mailings = ('errormail','packagesmail','helpdeskmail');
+ my @mailings = ('errormail','packagesmail','helpdeskmail','lonstatusmail',
+ 'requestsmail');
foreach my $type (@mailings) {
@{$newsetting{$type}} =
&Apache::loncommon::get_env_multiple('form.'.$type);
@@ -2989,6 +5881,10 @@ sub modify_contacts {
}
$others{$type} = $env{'form.'.$type.'_others'};
$contacts_hash{contacts}{$type}{'others'} = $others{$type};
+ if ($type eq 'helpdeskmail') {
+ $bcc{$type} = $env{'form.'.$type.'_bcc'};
+ $contacts_hash{contacts}{$type}{'bcc'} = $bcc{$type};
+ }
}
foreach my $item (@contacts) {
$to{$item} = $env{'form.'.$item};
@@ -3013,6 +5909,11 @@ sub modify_contacts {
if ($others{$type} ne $currsetting{$type}{'others'}) {
push(@{$changes{$type}},'others');
}
+ if ($type eq 'helpdeskmail') {
+ if ($bcc{$type} ne $currsetting{$type}{'bcc'}) {
+ push(@{$changes{$type}},'bcc');
+ }
+ }
}
} else {
my %default;
@@ -3021,6 +5922,8 @@ sub modify_contacts {
$default{'errormail'} = 'adminemail';
$default{'packagesmail'} = 'adminemail';
$default{'helpdeskmail'} = 'supportemail';
+ $default{'lonstatusmail'} = 'adminemail';
+ $default{'requestsmail'} = 'adminemail';
foreach my $item (@contacts) {
if ($to{$item} ne $default{$item}) {
$changes{$item} = 1;
@@ -3033,7 +5936,12 @@ sub modify_contacts {
}
if ($others{$type} ne '') {
push(@{$changes{$type}},'others');
- }
+ }
+ if ($type eq 'helpdeskmail') {
+ if ($bcc{$type} ne '') {
+ push(@{$changes{$type}},'bcc');
+ }
+ }
}
}
my $putresult = &Apache::lonnet::put_dom('configuration',\%contacts_hash,
@@ -3061,7 +5969,13 @@ sub modify_contacts {
push(@text,$others{$type});
}
$resulttext .= ''.
- join(', ',@text).' ';
+ join(', ',@text).'';
+ if ($type eq 'helpdeskmail') {
+ if ($bcc{$type} ne '') {
+ $resulttext .= ' '.&mt('with Bcc to').': '.$bcc{$type}.' ';
+ }
+ }
+ $resulttext .= '';
}
}
$resulttext .= ' ';
@@ -3078,30 +5992,109 @@ sub modify_contacts {
sub modify_usercreation {
my ($dom,%domconfig) = @_;
my ($resulttext,%curr_usercreation,%changes,%authallowed,%cancreate);
+ my $warningmsg;
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 @id_rule = &Apache::loncommon::get_env_multiple('form.id_rule');
- my @contexts = ('author','course');
+ my @email_rule = &Apache::loncommon::get_env_multiple('form.email_rule');
+ my @contexts = ('author','course','requestcrs','selfcreate');
foreach my $item(@contexts) {
- $cancreate{$item} = $env{'form.can_createuser_'.$item};
+ if ($item eq 'selfcreate') {
+ @{$cancreate{$item}} = &Apache::loncommon::get_env_multiple('form.can_createuser_'.$item);
+ my %domdefaults = &Apache::lonnet::get_domain_defaults($dom);
+ if (!((($domdefaults{'auth_def'} =~/^krb/) && ($domdefaults{'auth_arg_def'} ne '')) || ($domdefaults{'auth_def'} eq 'localauth'))) {
+ if (ref($cancreate{$item}) eq 'ARRAY') {
+ if (grep(/^login$/,@{$cancreate{$item}})) {
+ $warningmsg = &mt('Although account creation has been set to be available for institutional logins, currently default authentication in this domain has not been set to support this.').' '.&mt('You need to set the default authentication type to Kerberos 4 or 5 (with a Kerberos domain specified), or to Local authentication, if the localauth module has been customized in your domain to authenticate institutional logins.');
+ }
+ }
+ }
+ } else {
+ $cancreate{$item} = $env{'form.can_createuser_'.$item};
+ }
+ }
+ my ($othertitle,$usertypes,$types) =
+ &Apache::loncommon::sorted_inst_types($dom);
+ if (ref($types) eq 'ARRAY') {
+ if (@{$types} > 0) {
+ @{$cancreate{'statustocreate'}} =
+ &Apache::loncommon::get_env_multiple('form.statustocreate');
+ } else {
+ @{$cancreate{'statustocreate'}} = ();
+ }
+ push(@contexts,'statustocreate');
}
if (ref($curr_usercreation{'cancreate'}) eq 'HASH') {
foreach my $item (@contexts) {
- if ($curr_usercreation{'cancreate'}{$item} ne $cancreate{$item}) {
- push(@{$changes{'cancreate'}},$item);
- }
+ if (($item eq 'selfcreate') || ($item eq 'statustocreate')) {
+ if (ref($curr_usercreation{'cancreate'}{$item}) eq 'ARRAY') {
+ foreach my $curr (@{$curr_usercreation{'cancreate'}{$item}}) {
+ if (ref($cancreate{$item}) eq 'ARRAY') {
+ if (!grep(/^$curr$/,@{$cancreate{$item}})) {
+ if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
+ push(@{$changes{'cancreate'}},$item);
+ }
+ }
+ }
+ }
+ } else {
+ if ($curr_usercreation{'cancreate'}{$item} eq '') {
+ if (@{$cancreate{$item}} > 0) {
+ if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
+ push(@{$changes{'cancreate'}},$item);
+ }
+ }
+ } else {
+ if ($curr_usercreation{'cancreate'}{$item} eq 'any') {
+ if (@{$cancreate{$item}} < 3) {
+ if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
+ push(@{$changes{'cancreate'}},$item);
+ }
+ }
+ } elsif ($curr_usercreation{'cancreate'}{$item} eq 'none') {
+ if (@{$cancreate{$item}} > 0) {
+ if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
+ push(@{$changes{'cancreate'}},$item);
+ }
+ }
+ } elsif (!grep(/^$curr_usercreation{'cancreate'}{$item}$/,@{$cancreate{$item}})) {
+ if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
+ push(@{$changes{'cancreate'}},$item);
+ }
+ }
+ }
+ }
+ if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
+ foreach my $type (@{$cancreate{$item}}) {
+ if (ref($curr_usercreation{'cancreate'}{$item}) eq 'ARRAY') {
+ if (!grep(/^$type$/,@{$curr_usercreation{'cancreate'}{$item}})) {
+ if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
+ push(@{$changes{'cancreate'}},$item);
+ }
+ }
+ } elsif (($curr_usercreation{'cancreate'}{$item} ne 'any') &&
+ ($curr_usercreation{'cancreate'}{$item} ne 'none')) {
+ if ($curr_usercreation{'cancreate'}{$item} ne $type) {
+ if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
+ push(@{$changes{'cancreate'}},$item);
+ }
+ }
+ }
+ }
+ }
+ } else {
+ if ($curr_usercreation{'cancreate'}{$item} ne $cancreate{$item}) {
+ push(@{$changes{'cancreate'}},$item);
+ }
+ }
}
} elsif (ref($curr_usercreation{'cancreate'}) eq 'ARRAY') {
foreach my $item (@contexts) {
- if (grep(/^\Q$item\E$/,@{$curr_usercreation{'cancreate'}})) {
+ if (!grep(/^\Q$item\E$/,@{$curr_usercreation{'cancreate'}})) {
if ($cancreate{$item} ne 'any') {
push(@{$changes{'cancreate'}},$item);
}
@@ -3112,7 +6105,7 @@ sub modify_usercreation {
}
}
} else {
- foreach my $item ('author','course') {
+ foreach my $item (@contexts) {
push(@{$changes{'cancreate'}},$item);
}
}
@@ -3147,10 +6140,25 @@ sub modify_usercreation {
push(@{$changes{'id_rule'}},@id_rule);
}
- my @contexts = ('author','course','domain');
+ if (ref($curr_usercreation{'email_rule'}) eq 'ARRAY') {
+ foreach my $type (@{$curr_usercreation{'email_rule'}}) {
+ if (!grep(/^\Q$type\E$/,@email_rule)) {
+ push(@{$changes{'email_rule'}},$type);
+ }
+ }
+ foreach my $type (@email_rule) {
+ if (!grep(/^\Q$type\E$/,@{$curr_usercreation{'email_rule'}})) {
+ push(@{$changes{'email_rule'}},$type);
+ }
+ }
+ } else {
+ push(@{$changes{'email_rule'}},@email_rule);
+ }
+
+ my @authen_contexts = ('author','course','domain');
my @authtypes = ('int','krb4','krb5','loc');
my %authhash;
- foreach my $item (@contexts) {
+ foreach my $item (@authen_contexts) {
my @authallowed = &Apache::loncommon::get_env_multiple('form.'.$item.'_auth');
foreach my $auth (@authtypes) {
if (grep(/^\Q$auth\E$/,@authallowed)) {
@@ -3161,7 +6169,7 @@ sub modify_usercreation {
}
}
if (ref($curr_usercreation{'authtypes'}) eq 'HASH') {
- foreach my $item (@contexts) {
+ foreach my $item (@authen_contexts) {
if (ref($curr_usercreation{'authtypes'}{$item}) eq 'HASH') {
foreach my $auth (@authtypes) {
if ($authhash{$item}{$auth} ne $curr_usercreation{'authtypes'}{$item}{$auth}) {
@@ -3172,7 +6180,7 @@ sub modify_usercreation {
}
}
} else {
- foreach my $item (@contexts) {
+ foreach my $item (@authen_contexts) {
push(@{$changes{'authtypes'}},$item);
}
}
@@ -3182,27 +6190,95 @@ sub modify_usercreation {
cancreate => \%cancreate,
username_rule => \@username_rule,
id_rule => \@id_rule,
+ email_rule => \@email_rule,
authtypes => \%authhash,
}
);
my $putresult = &Apache::lonnet::put_dom('configuration',\%usercreation_hash,
$dom);
+
+ my %selfcreatetypes = (
+ sso => 'users authenticated by institutional single sign on',
+ login => 'users authenticated by institutional log-in',
+ email => 'users who provide a valid e-mail address for use as the username',
+ );
if ($putresult eq 'ok') {
if (keys(%changes) > 0) {
$resulttext = &mt('Changes made:').'';
if (ref($changes{'cancreate'}) eq 'ARRAY') {
my %lt = &usercreation_types();
foreach my $type (@{$changes{'cancreate'}}) {
- my $chgtext;
- if ($cancreate{$type} eq 'none') {
- $chgtext = $lt{$type}.' '.&mt('creation of new users is not permitted, except by a Domain Coordinator.');
- } elsif ($cancreate{$type} eq 'any') {
- $chgtext = $lt{$type}.' '.&mt('creation of new users is permitted for both institutional and non-institutional usernames.');
- } elsif ($cancreate{$type} eq 'official') {
- $chgtext = $lt{$type}.' '.&mt('creation of new users is only permitted for institutional usernames.',$lt{$type});
- } elsif ($cancreate{$type} eq 'unofficial') {
- $chgtext = $lt{$type}.' '.&mt('creation of new users is only permitted for non-institutional usernames.',$lt{$type});
+ my $chgtext;
+ unless ($type eq 'statustocreate') {
+ $chgtext = $lt{$type}.', ';
+ }
+ if ($type eq 'selfcreate') {
+ if (@{$cancreate{$type}} == 0) {
+ $chgtext .= &mt('creation of a new user account is not permitted.');
+ } else {
+ $chgtext .= &mt('creation of a new account is permitted for:').'';
+ foreach my $case (@{$cancreate{$type}}) {
+ $chgtext .= ''.$selfcreatetypes{$case}.' ';
+ }
+ $chgtext .= ' ';
+ if (ref($cancreate{$type}) eq 'ARRAY') {
+ if (grep(/^(login|sso)$/,@{$cancreate{$type}})) {
+ if (ref($cancreate{'statustocreate'}) eq 'ARRAY') {
+ if (@{$cancreate{'statustocreate'}} == 0) {
+ $chgtext .= ''.&mt("However, no institutional affiliations (including 'other') are currently permitted to create accounts.").' ';
+ }
+ }
+ }
+ }
+ }
+ } elsif ($type eq 'statustocreate') {
+ if ((ref($cancreate{'selfcreate'}) eq 'ARRAY') &&
+ (ref($cancreate{'statustocreate'}) eq 'ARRAY')) {
+ if (@{$cancreate{'selfcreate'}} > 0) {
+ if (@{$cancreate{'statustocreate'}} == 0) {
+
+ $chgtext .= &mt("Institutional affiliations permitted to create accounts set to 'None'.");
+ if (!grep(/^email$/,@{$cancreate{'selfcreate'}})) {
+ $chgtext .= ''.&mt("However, no institutional affiliations (including 'other') are currently permitted to create accounts.").' ';
+ }
+ } elsif (ref($usertypes) eq 'HASH') {
+ if (grep(/^(login|sso)$/,@{$cancreate{'selfcreate'}})) {
+ $chgtext .= &mt('Creation of a new account for an institutional user is restricted to the following institutional affiliation(s):');
+ } else {
+ $chgtext .= &mt('Institutional affiliations permitted to create accounts with institutional authentication were set as follows:');
+ }
+ $chgtext .= '';
+ foreach my $case (@{$cancreate{$type}}) {
+ if ($case eq 'default') {
+ $chgtext .= ''.$othertitle.' ';
+ } else {
+ $chgtext .= ''.$usertypes->{$case}.' ';
+ }
+ }
+ $chgtext .= ' ';
+ if (!grep(/^(login|sso)$/,@{$cancreate{'selfcreate'}})) {
+ $chgtext .= ''.&mt('However, users authenticated by institutional login/single sign on are not currently permitted to create accounts.').' ';
+ }
+ }
+ } else {
+ if (@{$cancreate{$type}} == 0) {
+ $chgtext .= &mt("Institutional affiliations permitted to create accounts were set to 'none'.");
+ } else {
+ $chgtext .= &mt('Although institutional affiliations permitted to create accounts were changed, self creation of accounts is not currently permitted for any authentication types.');
+ }
+ }
+ }
+ } else {
+ if ($cancreate{$type} eq 'none') {
+ $chgtext .= &mt('creation of new users is not permitted, except by a Domain Coordinator.');
+ } elsif ($cancreate{$type} eq 'any') {
+ $chgtext .= &mt('creation of new users is permitted for both institutional and non-institutional usernames.');
+ } elsif ($cancreate{$type} eq 'official') {
+ $chgtext .= &mt('creation of new users is only permitted for institutional usernames.');
+ } elsif ($cancreate{$type} eq 'unofficial') {
+ $chgtext .= &mt('creation of new users is only permitted for non-institutional usernames.');
+ }
}
$resulttext .= ''.$chgtext.' ';
}
@@ -3239,6 +6315,23 @@ sub modify_usercreation {
$resulttext .= ''.&mt('There are now no ID formats restricted to verified users in the institutional directory.').' ';
}
}
+ if (ref($changes{'email_rule'}) eq 'ARRAY') {
+ my ($emailrules,$emailruleorder) =
+ &Apache::lonnet::inst_userrules($dom,'email');
+ my $chgtext = '';
+ foreach my $type (@email_rule) {
+ if (ref($emailrules->{$type}) eq 'HASH') {
+ $chgtext .= ''.$emailrules->{$type}{'name'}.' ';
+ }
+ }
+ $chgtext .= ' ';
+ if (@email_rule > 0) {
+ $resulttext .= ''.&mt('Accounts may not be created by users self-enrolling with e-mail addresses of the following types: ').$chgtext.' ';
+ } else {
+ $resulttext .= ''.&mt('There are now no restrictions on e-mail addresses which may be used as a username when self-enrolling.').' ';
+ }
+ }
+
my %authname = &authtype_names();
my %context_title = &context_names();
if (ref($changes{'authtypes'}) eq 'ARRAY') {
@@ -3251,7 +6344,11 @@ sub modify_usercreation {
push(@allowed,$authname{$auth});
}
}
- $chgtext .= join(', ',@allowed).'';
+ if (@allowed > 0) {
+ $chgtext .= join(', ',@allowed).'';
+ } else {
+ $chgtext .= &mt('none').'';
+ }
}
$chgtext .= ' ';
$resulttext .= ''.&mt('Authentication types available for assignment to new users').' '.$chgtext;
@@ -3265,6 +6362,9 @@ sub modify_usercreation {
$resulttext = ''.
&mt('An error occurred: [_1]',$putresult).' ';
}
+ if ($warningmsg ne '') {
+ $resulttext .= ''.$warningmsg.' ';
+ }
return $resulttext;
}
@@ -3276,10 +6376,11 @@ sub modify_usermodification {
$curr_usermodification{$key} = $domconfig{'usermodification'}{$key};
}
}
- my @contexts = ('author','course');
+ my @contexts = ('author','course','selfcreate');
my %context_title = (
author => 'In author context',
course => 'In course context',
+ selfcreate => 'When self creating account',
);
my @fields = ('lastname','firstname','middlename','generation',
'permanentemail','id');
@@ -3287,6 +6388,12 @@ sub modify_usermodification {
author => ['ca','aa'],
course => ['st','ep','ta','in','cr'],
);
+ my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
+ if (ref($types) eq 'ARRAY') {
+ push(@{$types},'default');
+ $usertypes->{'default'} = $othertitle;
+ }
+ $roles{'selfcreate'} = $types;
my %fieldtitles = &Apache::loncommon::personal_data_fieldtitles();
my %modifyhash;
foreach my $context (@contexts) {
@@ -3334,13 +6441,26 @@ sub modify_usermodification {
if (ref($changes{$context}) eq 'ARRAY') {
foreach my $role (@{$changes{$context}}) {
my $rolename;
- if ($role eq 'cr') {
- $rolename = &mt('Custom');
+ if ($context eq 'selfcreate') {
+ $rolename = $role;
+ if (ref($usertypes) eq 'HASH') {
+ if ($usertypes->{$role} ne '') {
+ $rolename = $usertypes->{$role};
+ }
+ }
} else {
- $rolename = &Apache::lonnet::plaintext($role);
+ if ($role eq 'cr') {
+ $rolename = &mt('Custom');
+ } else {
+ $rolename = &Apache::lonnet::plaintext($role);
+ }
}
my @modifiable;
- $resulttext .= ' '.&mt('Target user with [_1] role',$rolename).' - '.&mt('modifiable fields: ');
+ if ($context eq 'selfcreate') {
+ $resulttext .= ''.&mt('Self-creation of account by users with status: [_1]',$rolename).' - '.&mt('modifiable fields (if institutional data blank): ');
+ } else {
+ $resulttext .= ''.&mt('Target user with [_1] role',$rolename).' - '.&mt('modifiable fields: ');
+ }
foreach my $field (@fields) {
if ($modifyhash{$context}{$role}{$field}) {
push(@modifiable,$fieldtitles{$field});
@@ -3368,4 +6488,1526 @@ sub modify_usermodification {
return $resulttext;
}
+sub modify_defaults {
+ my ($dom,$r) = @_;
+ my ($resulttext,$mailmsgtxt,%newvalues,%changes,@errors);
+ my %domdefaults = &Apache::lonnet::get_domain_defaults($dom);
+ my @items = ('auth_def','auth_arg_def','lang_def','timezone_def','datelocale_def','portal_def');
+ my @authtypes = ('internal','krb4','krb5','localauth');
+ foreach my $item (@items) {
+ $newvalues{$item} = $env{'form.'.$item};
+ if ($item eq 'auth_def') {
+ if ($newvalues{$item} ne '') {
+ if (!grep(/^\Q$newvalues{$item}\E$/,@authtypes)) {
+ push(@errors,$item);
+ }
+ }
+ } elsif ($item eq 'lang_def') {
+ if ($newvalues{$item} ne '') {
+ if ($newvalues{$item} =~ /^(\w+)/) {
+ my $langcode = $1;
+ if ($langcode ne 'x_chef') {
+ if (code2language($langcode) eq '') {
+ push(@errors,$item);
+ }
+ }
+ } else {
+ push(@errors,$item);
+ }
+ }
+ } elsif ($item eq 'timezone_def') {
+ if ($newvalues{$item} ne '') {
+ if (!DateTime::TimeZone->is_valid_name($newvalues{$item})) {
+ push(@errors,$item);
+ }
+ }
+ } elsif ($item eq 'datelocale_def') {
+ if ($newvalues{$item} ne '') {
+ my @datelocale_ids = DateTime::Locale->ids();
+ if (!grep(/^\Q$newvalues{$item}\E$/,@datelocale_ids)) {
+ push(@errors,$item);
+ }
+ }
+ } elsif ($item eq 'portal_def') {
+ if ($newvalues{$item} ne '') {
+ unless ($newvalues{$item} =~ /^https?\:\/\/(([a-zA-Z0-9]|[a-zA-Z0-9][a-zA-Z0-9\-]*[a-zA-Z0-9])\.)*([A-Za-z]|[A-Za-z][A-Za-z0-9\-]*[A-Za-z0-9])\/?$/) {
+ push(@errors,$item);
+ }
+ }
+ }
+ if (grep(/^\Q$item\E$/,@errors)) {
+ $newvalues{$item} = $domdefaults{$item};
+ } elsif ($domdefaults{$item} ne $newvalues{$item}) {
+ $changes{$item} = 1;
+ }
+ $domdefaults{$item} = $newvalues{$item};
+ }
+ my %defaults_hash = (
+ defaults => \%newvalues,
+ );
+ my $title = &defaults_titles();
+ my $putresult = &Apache::lonnet::put_dom('configuration',\%defaults_hash,
+ $dom);
+ if ($putresult eq 'ok') {
+ if (keys(%changes) > 0) {
+ $resulttext = &mt('Changes made:').'';
+ my $version = $r->dir_config('lonVersion');
+ my $mailmsgtext = "Changes made to domain settings in a LON-CAPA installation - domain: $dom (running version: $version) - dns_domain.tab needs to be updated with the following changes, to support legacy 2.4, 2.5 and 2.6 versions of LON-CAPA.\n\n";
+ foreach my $item (sort(keys(%changes))) {
+ my $value = $env{'form.'.$item};
+ if ($value eq '') {
+ $value = &mt('none');
+ } elsif ($item eq 'auth_def') {
+ my %authnames = &authtype_names();
+ my %shortauth = (
+ internal => 'int',
+ krb4 => 'krb4',
+ krb5 => 'krb5',
+ localauth => 'loc',
+ );
+ $value = $authnames{$shortauth{$value}};
+ }
+ $resulttext .= ''.&mt('[_1] set to "[_2]"',$title->{$item},$value).' ';
+ $mailmsgtext .= "$title->{$item} set to $value\n";
+ }
+ $resulttext .= ' ';
+ $mailmsgtext .= "\n";
+ my $cachetime = 24*60*60;
+ &Apache::lonnet::do_cache_new('domdefaults',$dom,\%domdefaults,$cachetime);
+ if ($changes{'auth_def'} || $changes{'auth_arg_def'} || $changes{'lang_def'} || $changes{'datelocale_def'}) {
+ my $sysmail = $r->dir_config('lonSysEMail');
+ &Apache::lonmsg::sendemail($sysmail,"LON-CAPA Domain Settings Change - $dom",$mailmsgtext);
+ }
+ } else {
+ $resulttext = &mt('No changes made to default authentication/language/timezone settings');
+ }
+ } else {
+ $resulttext = ''.
+ &mt('An error occurred: [_1]',$putresult).' ';
+ }
+ if (@errors > 0) {
+ $resulttext .= ' '.&mt('The following were left unchanged because the values entered were invalid:');
+ foreach my $item (@errors) {
+ $resulttext .= ' "'.$title->{$item}.'",';
+ }
+ $resulttext =~ s/,$//;
+ }
+ return $resulttext;
+}
+
+sub modify_scantron {
+ my ($r,$dom,$confname,%domconfig) = @_;
+ my ($resulttext,%confhash,%changes,$errors);
+ my $custom = 'custom.tab';
+ my $default = 'default.tab';
+ my $servadm = $r->dir_config('lonAdmEMail');
+ my ($configuserok,$author_ok,$switchserver) =
+ &config_check($dom,$confname,$servadm);
+ if ($env{'form.scantronformat.filename'} ne '') {
+ my $error;
+ if ($configuserok eq 'ok') {
+ if ($switchserver) {
+ $error = &mt("Upload of bubblesheet format file is not permitted to this server: [_1]",$switchserver);
+ } else {
+ if ($author_ok eq 'ok') {
+ my ($result,$scantronurl) =
+ &publishlogo($r,'upload','scantronformat',$dom,
+ $confname,'scantron','','',$custom);
+ if ($result eq 'ok') {
+ $confhash{'scantron'}{'scantronformat'} = $scantronurl;
+ $changes{'scantronformat'} = 1;
+ } else {
+ $error = &mt("Upload of [_1] failed because an error occurred publishing the file in RES space. Error was: [_2].",$custom,$result);
+ }
+ } else {
+ $error = &mt("Upload of [_1] failed because an author role could not be assigned to a Domain Configuration user ([_2]) in domain: [_3]. Error was: [_4].",$custom,$confname,$dom,$author_ok);
+ }
+ }
+ } else {
+ $error = &mt("Upload of [_1] failed because a Domain Configuration user ([_2]) could not be created in domain: [_3]. Error was: [_4].",$custom,$confname,$dom,$configuserok);
+ }
+ if ($error) {
+ &Apache::lonnet::logthis($error);
+ $errors .= ''.$error.' ';
+ }
+ }
+ if (ref($domconfig{'scantron'}) eq 'HASH') {
+ if ($domconfig{'scantron'}{'scantronformat'} ne '') {
+ if ($env{'form.scantronformat_del'}) {
+ $confhash{'scantron'}{'scantronformat'} = '';
+ $changes{'scantronformat'} = 1;
+ }
+ }
+ }
+ if (keys(%confhash) > 0) {
+ my $putresult = &Apache::lonnet::put_dom('configuration',\%confhash,
+ $dom);
+ if ($putresult eq 'ok') {
+ if (keys(%changes) > 0) {
+ if (ref($confhash{'scantron'}) eq 'HASH') {
+ $resulttext = &mt('Changes made:').'';
+ if ($confhash{'scantron'}{'scantronformat'} eq '') {
+ $resulttext .= ''.&mt('[_1] bubblesheet format file removed; [_2] file will be used for courses in this domain.',$custom,$default).' ';
+ } else {
+ $resulttext .= ''.&mt('Custom bubblesheet format file ([_1]) uploaded for use with courses in this domain.',$custom).' ';
+ }
+ $resulttext .= ' ';
+ } else {
+ $resulttext = &mt('Changes made to bubblesheet format file.');
+ }
+ $resulttext .= '';
+ &Apache::loncommon::devalidate_domconfig_cache($dom);
+ } else {
+ $resulttext = &mt('No changes made to bubblesheet format file');
+ }
+ } else {
+ $resulttext = ''.
+ &mt('An error occurred: [_1]',$putresult).' ';
+ }
+ } else {
+ $resulttext = &mt('No changes made to bubblesheet format file');
+ }
+ if ($errors) {
+ $resulttext .= &mt('The following errors occurred: ').'';
+ }
+ return $resulttext;
+}
+
+sub modify_coursecategories {
+ my ($dom,%domconfig) = @_;
+ my ($resulttext,%deletions,%reorderings,%needreordering,%adds,%changes,$errors,
+ $cathash);
+ my @deletecategory = &Apache::loncommon::get_env_multiple('form.deletecategory');
+ if (ref($domconfig{'coursecategories'}) eq 'HASH') {
+ $cathash = $domconfig{'coursecategories'}{'cats'};
+ if ($domconfig{'coursecategories'}{'togglecats'} ne $env{'form.togglecats'}) {
+ $changes{'togglecats'} = 1;
+ $domconfig{'coursecategories'}{'togglecats'} = $env{'form.togglecats'};
+ }
+ if ($domconfig{'coursecategories'}{'categorize'} ne $env{'form.categorize'}) {
+ $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;
+ $changes{'togglecatscomm'} = 1;
+ $changes{'categorizecomm'} = 1;
+ $domconfig{'coursecategories'} = {
+ togglecats => $env{'form.togglecats'},
+ categorize => $env{'form.categorize'},
+ togglecatscomm => $env{'form.togglecatscomm'},
+ categorizecomm => $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') {
+ if (@deletecategory > 0) {
+ #FIXME Need to remove category from all courses using a deleted category
+ &Apache::loncommon::extract_categories($cathash,\@predelcats,\@predeltrails,\%predelallitems);
+ foreach my $item (@deletecategory) {
+ if ($domconfig{'coursecategories'}{'cats'}{$item} ne '') {
+ delete($domconfig{'coursecategories'}{'cats'}{$item});
+ $deletions{$item} = 1;
+ &recurse_cat_deletes($item,$cathash,\%deletions);
+ }
+ }
+ }
+ foreach my $item (keys(%{$cathash})) {
+ my ($cat,$container,$depth) = map { &unescape($_); } split(/:/,$item);
+ if ($cathash->{$item} ne $env{'form.'.$item}) {
+ $reorderings{$item} = 1;
+ $domconfig{'coursecategories'}{'cats'}{$item} = $env{'form.'.$item};
+ }
+ if ($env{'form.addcategory_name_'.$item} ne '') {
+ my $newcat = $env{'form.addcategory_name_'.$item};
+ my $newdepth = $depth+1;
+ my $newitem = &escape($newcat).':'.&escape($cat).':'.$newdepth;
+ $domconfig{'coursecategories'}{'cats'}{$newitem} = $env{'form.addcategory_pos_'.$item};
+ $adds{$newitem} = 1;
+ }
+ if ($env{'form.subcat_'.$item} ne '') {
+ my $newcat = $env{'form.subcat_'.$item};
+ my $newdepth = $depth+1;
+ my $newitem = &escape($newcat).':'.&escape($cat).':'.$newdepth;
+ $domconfig{'coursecategories'}{'cats'}{$newitem} = 0;
+ $adds{$newitem} = 1;
+ }
+ }
+ }
+ if ($env{'form.instcode'} eq '1') {
+ if (ref($cathash) eq 'HASH') {
+ my $newitem = 'instcode::0';
+ if ($cathash->{$newitem} eq '') {
+ $domconfig{'coursecategories'}{'cats'}{$newitem} = $env{'form.instcode_pos'};
+ $adds{$newitem} = 1;
+ }
+ } else {
+ my $newitem = 'instcode::0';
+ $domconfig{'coursecategories'}{'cats'}{$newitem} = $env{'form.instcode_pos'};
+ $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 '') {
+ 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)) {
+ if (keys(%deletions) > 0) {
+ foreach my $key (keys(%deletions)) {
+ if ($predelallitems{$key} ne '') {
+ $sort_by_deltrail{$predelallitems{$key}} = $predeltrails[$predelallitems{$key}];
+ }
+ }
+ }
+ my (@chkcats,@chktrails,%chkallitems);
+ &Apache::loncommon::extract_categories($domconfig{'coursecategories'}{'cats'},\@chkcats,\@chktrails,\%chkallitems);
+ if (ref($chkcats[0]) eq 'ARRAY') {
+ my $depth = 0;
+ my $chg = 0;
+ for (my $i=0; $i<@{$chkcats[0]}; $i++) {
+ my $name = $chkcats[0][$i];
+ my $item;
+ if ($name eq '') {
+ $chg ++;
+ } else {
+ $item = &escape($name).'::0';
+ if ($chg) {
+ $domconfig{'coursecategories'}{'cats'}{$item} -= $chg;
+ }
+ $depth ++;
+ &recurse_check(\@chkcats,$domconfig{'coursecategories'}{'cats'},$depth,$name);
+ $depth --;
+ }
+ }
+ }
+ }
+ if ((keys(%changes) > 0) || (keys(%deletions) > 0) || (keys(%reorderings) > 0) || (keys(%adds) > 0)) {
+ $putresult = &Apache::lonnet::put_dom('configuration',\%domconfig,$dom);
+ if ($putresult eq 'ok') {
+ my %title = (
+ 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 in Domain ("Modify Course/Community")',
+ crs => 'set in Course ("Course Configuration")',
+ comm => 'set in Community ("Community Configuration")',
+ );
+ $resulttext = &mt('Changes made:').'';
+ if ($changes{'togglecats'}) {
+ $resulttext .= ''.&mt("$title{'togglecats'} $level{$env{'form.togglecats'}}").' ';
+ }
+ 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') {
+ $cathash = $domconfig{'coursecategories'}{'cats'};
+ } else {
+ $cathash = {};
+ }
+ my (@cats,@trails,%allitems);
+ &Apache::loncommon::extract_categories($cathash,\@cats,\@trails,\%allitems);
+ if (keys(%deletions) > 0) {
+ $resulttext .= ''.&mt('Deleted categories:').'';
+ foreach my $predeltrail (sort {$a <=> $b } (keys(%sort_by_deltrail))) {
+ $resulttext .= ''.$predeltrails[$predeltrail].' ';
+ }
+ $resulttext .= ' ';
+ }
+ if (keys(%reorderings) > 0) {
+ my %sort_by_trail;
+ $resulttext .= ''.&mt('Reordered categories:').'';
+ foreach my $key (keys(%reorderings)) {
+ if ($allitems{$key} ne '') {
+ $sort_by_trail{$allitems{$key}} = $trails[$allitems{$key}];
+ }
+ }
+ foreach my $trail (sort {$a <=> $b } (keys(%sort_by_trail))) {
+ $resulttext .= ''.$trails[$trail].' ';
+ }
+ $resulttext .= ' ';
+ }
+ if (keys(%adds) > 0) {
+ my %sort_by_trail;
+ $resulttext .= ''.&mt('Added categories:').'';
+ foreach my $key (keys(%adds)) {
+ if ($allitems{$key} ne '') {
+ $sort_by_trail{$allitems{$key}} = $trails[$allitems{$key}];
+ }
+ }
+ foreach my $trail (sort {$a <=> $b } (keys(%sort_by_trail))) {
+ $resulttext .= ''.$trails[$trail].' ';
+ }
+ $resulttext .= ' ';
+ }
+ }
+ $resulttext .= ' ';
+ } else {
+ $resulttext = ''.
+ &mt('An error occurred: [_1]',$putresult).' ';
+ }
+ } else {
+ $resulttext = &mt('No changes made to course and community categories');
+ }
+ return $resulttext;
+}
+
+sub modify_serverstatuses {
+ my ($dom,%domconfig) = @_;
+ my ($resulttext,%changes,%currserverstatus,%newserverstatus);
+ if (ref($domconfig{'serverstatuses'}) eq 'HASH') {
+ %currserverstatus = %{$domconfig{'serverstatuses'}};
+ }
+ my @pages = &serverstatus_pages();
+ foreach my $type (@pages) {
+ $newserverstatus{$type}{'namedusers'} = '';
+ $newserverstatus{$type}{'machines'} = '';
+ if (defined($env{'form.'.$type.'_namedusers'})) {
+ my @users = split(/,/,$env{'form.'.$type.'_namedusers'});
+ my @okusers;
+ foreach my $user (@users) {
+ my ($uname,$udom) = split(/:/,$user);
+ if (($udom =~ /^$match_domain$/) &&
+ (&Apache::lonnet::domain($udom)) &&
+ ($uname =~ /^$match_username$/)) {
+ if (!grep(/^\Q$user\E/,@okusers)) {
+ push(@okusers,$user);
+ }
+ }
+ }
+ if (@okusers > 0) {
+ @okusers = sort(@okusers);
+ $newserverstatus{$type}{'namedusers'} = join(',',@okusers);
+ }
+ }
+ if (defined($env{'form.'.$type.'_machines'})) {
+ my @machines = split(/,/,$env{'form.'.$type.'_machines'});
+ my @okmachines;
+ foreach my $ip (@machines) {
+ my @parts = split(/\./,$ip);
+ next if (@parts < 4);
+ my $badip = 0;
+ for (my $i=0; $i<4; $i++) {
+ if (!(($parts[$i] >= 0) && ($parts[$i] <= 255))) {
+ $badip = 1;
+ last;
+ }
+ }
+ if (!$badip) {
+ push(@okmachines,$ip);
+ }
+ }
+ @okmachines = sort(@okmachines);
+ $newserverstatus{$type}{'machines'} = join(',',@okmachines);
+ }
+ }
+ my %serverstatushash = (
+ serverstatuses => \%newserverstatus,
+ );
+ foreach my $type (@pages) {
+ foreach my $setting ('namedusers','machines') {
+ my (@current,@new);
+ if (ref($currserverstatus{$type}) eq 'HASH') {
+ if ($currserverstatus{$type}{$setting} ne '') {
+ @current = split(/,/,$currserverstatus{$type}{$setting});
+ }
+ }
+ if ($newserverstatus{$type}{$setting} ne '') {
+ @new = split(/,/,$newserverstatus{$type}{$setting});
+ }
+ if (@current > 0) {
+ if (@new > 0) {
+ foreach my $item (@current) {
+ if (!grep(/^\Q$item\E$/,@new)) {
+ $changes{$type}{$setting} = 1;
+ last;
+ }
+ }
+ foreach my $item (@new) {
+ if (!grep(/^\Q$item\E$/,@current)) {
+ $changes{$type}{$setting} = 1;
+ last;
+ }
+ }
+ } else {
+ $changes{$type}{$setting} = 1;
+ }
+ } elsif (@new > 0) {
+ $changes{$type}{$setting} = 1;
+ }
+ }
+ }
+ if (keys(%changes) > 0) {
+ my $titles= &LONCAPA::lonauthcgi::serverstatus_titles();
+ my $putresult = &Apache::lonnet::put_dom('configuration',
+ \%serverstatushash,$dom);
+ if ($putresult eq 'ok') {
+ $resulttext .= &mt('Changes made:').'';
+ foreach my $type (@pages) {
+ if (ref($changes{$type}) eq 'HASH') {
+ $resulttext .= ''.$titles->{$type}.'';
+ if ($changes{$type}{'namedusers'}) {
+ if ($newserverstatus{$type}{'namedusers'} eq '') {
+ $resulttext .= ''.&mt("Access terminated for all specific (named) users").' '."\n";
+ } else {
+ $resulttext .= ''.&mt("Access available for the following specified users: ").$newserverstatus{$type}{'namedusers'}.' '."\n";
+ }
+ }
+ if ($changes{$type}{'machines'}) {
+ if ($newserverstatus{$type}{'machines'} eq '') {
+ $resulttext .= ''.&mt("Access terminated for all specific IP addresses").' '."\n";
+ } else {
+ $resulttext .= ''.&mt("Access available for the following specified IP addresses: ").$newserverstatus{$type}{'machines'}.' '."\n";
+ }
+
+ }
+ $resulttext .= ' ';
+ }
+ }
+ $resulttext .= ' ';
+ } else {
+ $resulttext = ''.
+ &mt('An error occurred saving access settings for server status pages: [_1].',$putresult).' ';
+
+ }
+ } else {
+ $resulttext = &mt('No changes made to access to server status pages');
+ }
+ return $resulttext;
+}
+
+sub modify_helpsettings {
+ my ($r,$dom,$confname,%domconfig) = @_;
+ my ($resulttext,$errors,%changes,%helphash);
+
+ my $customhelpfile = $env{'form.loginhelpurl.filename'};
+ my $defaulthelpfile = 'defaulthelp.html';
+ my $servadm = $r->dir_config('lonAdmEMail');
+ my ($configuserok,$author_ok,$switchserver) =
+ &config_check($dom,$confname,$servadm);
+
+ my %defaultchecked = ('submitbugs' => 'on');
+ my @offon = ('off','on');
+ my %title = ( submitbugs => 'Display link for users to submit a bug',
+ loginhelpurl => 'Unauthenticated login help page set to custom file');
+
+ my @toggles = ('submitbugs');
+
+ $helphash{'helpsettings'} = {};
+
+ if (ref($domconfig{'helpsettings'}) ne 'HASH') {
+ if ($domconfig{'helpsettings'} eq '') {
+ $domconfig{'helpsettings'} = {};
+ }
+ }
+
+ if (ref($domconfig{'helpsettings'}) eq 'HASH') {
+
+ foreach my $item (@toggles) {
+
+ if ($defaultchecked{$item} eq 'on') {
+ if (($domconfig{'helpsettings'}{$item} eq '') &&
+ ($env{'form.'.$item} eq '0')) {
+ $changes{$item} = 1;
+ } elsif ($domconfig{'helpsettings'}{$item} ne $env{'form.'.$item}) {
+ $changes{$item} = 1;
+ }
+ } elsif ($defaultchecked{$item} eq 'off') {
+ if (($domconfig{'helpsettings'}{$item} eq '') &&
+ ($env{'form.'.$item} eq '1')) {
+ $changes{$item} = 1;
+ } elsif ($domconfig{'helpsettings'}{$item} ne $env{'form.'.$item}) {
+ $changes{$item} = 1;
+ }
+ }
+ $helphash{'helpsettings'}{$item} = $env{'form.'.$item};
+ }
+
+ if ($customhelpfile ne '') {
+ my $error;
+ if ($configuserok eq 'ok') {
+ if ($switchserver) {
+ $error = &mt("Upload of custom help file is not permitted to this server: [_1]",$switchserver);
+ } else {
+ if ($author_ok eq 'ok') {
+ my ($result,$loginhelpurl) =
+ &publishlogo($r,'upload','loginhelpurl',$dom,
+ $confname,'help','','',$customhelpfile);
+ if ($result eq 'ok') {
+ $helphash{'helpsettings'}{'loginhelpurl'} = $loginhelpurl;
+ $changes{'loginhelpurl'} = 1;
+ } else {
+ $error = &mt("Upload of [_1] failed because an error occurred publishing the file in RES space. Error was: [_2].",$customhelpfile,$result);
+ }
+ } else {
+ $error = &mt("Upload of [_1] failed because an author role could not be assigned to a Domain Configuration user ([_2]) in domain: [_3]. Error was: [_4].",$customhelpfile,$confname,$dom,$author_ok);
+ }
+ }
+ } else {
+ $error = &mt("Upload of [_1] failed because a Domain Configuration user ([_2]) could not be created in domain: [_3]. Error was: [_4].",$customhelpfile,$confname,$dom,$configuserok);
+ }
+ if ($error) {
+ &Apache::lonnet::logthis($error);
+ $errors .= ''.$error.' ';
+ }
+ }
+
+ if ($domconfig{'helpsettings'}{'loginhelpurl'} ne '') {
+ if ($env{'form.loginhelpurl_del'}) {
+ $helphash{'helpsettings'}{'loginhelpurl'} = '';
+ $changes{'loginhelpurl'} = 1;
+ }
+ }
+ }
+
+
+ my $putresult;
+
+ if (keys(%changes) > 0) {
+ $putresult = &Apache::lonnet::put_dom('configuration',\%helphash,$dom);
+ } else {
+ $putresult = 'ok';
+ }
+
+ if ($putresult eq 'ok') {
+ if (keys(%changes) > 0) {
+ $resulttext = &mt('Changes made:').'';
+ foreach my $item (sort(keys(%changes))) {
+ if ($item eq 'submitbugs') {
+ $resulttext .= ''.&mt("$title{$item} set to $offon[$env{'form.'.$item}]").' ';
+ }
+ if ($item eq 'loginhelpurl') {
+ if ($helphash{'helpsettings'}{'loginhelpurl'} eq '') {
+ $resulttext .= ''.&mt('[_1] help file removed; [_2] file will be used for the unathorized help page in this domain.',$customhelpfile,$defaulthelpfile).' ';
+ } else {
+ $resulttext .= ''.&mt("$title{$item} [_1]",$customhelpfile).' ';
+ }
+ }
+ }
+ $resulttext .= ' ';
+ } else {
+ $resulttext = &mt('No changes made to help settings');
+ }
+ } else {
+ $resulttext = ''.
+ &mt('An error occurred: [_1]',$putresult).' ';
+ }
+ if ($errors) {
+ $resulttext .= &mt('The following errors occurred: ').'';
+ }
+ 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 $currdefresponder = $domconfig{'coursedefaults'}{'anonsurvey_threshold'};
+ my $newdefresponder = $env{'form.anonsurvey_threshold'};
+ $newdefresponder =~ s/\D//g;
+ if ($newdefresponder eq '' || $newdefresponder < 1) {
+ $newdefresponder = 1;
+ }
+ $defaultshash{'coursedefaults'}{'anonsurvey_threshold'} = $newdefresponder;
+ if ($currdefresponder ne $newdefresponder) {
+ unless ($currdefresponder eq '' && $newdefresponder == 10) {
+ $changes{'anonsurvey_threshold'} = 1;
+ }
+ }
+ }
+ 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"').' ';
+ }
+ } elsif ($item eq 'anonsurvey_threshold') {
+ $resulttext .= ''.&mt('Responder count required for display of anonymous survey submissions set to [_1].',$defaultshash{'coursedefaults'}{'anonsurvey_threshold'}).' ';
+ }
+ }
+ $resulttext .= ' ';
+ } else {
+ $resulttext = &mt('No changes made to course defaults');
+ }
+ } else {
+ $resulttext = ''.
+ &mt('An error occurred: [_1]',$putresult).' ';
+ }
+ return $resulttext;
+}
+
+sub modify_usersessions {
+ my ($dom,%domconfig) = @_;
+ my @hostingtypes = ('version','excludedomain','includedomain');
+ my @offloadtypes = ('primary','default');
+ my %types = (
+ remote => \@hostingtypes,
+ hosted => \@hostingtypes,
+ spares => \@offloadtypes,
+ );
+ my @prefixes = ('remote','hosted','spares');
+ my @lcversions = &Apache::lonnet::all_loncaparevs();
+ my (%by_ip,%by_location,@intdoms);
+ &build_location_hashes(\@intdoms,\%by_ip,\%by_location);
+ my @locations = sort(keys(%by_location));
+ my (%defaultshash,%changes);
+ foreach my $prefix (@prefixes) {
+ $defaultshash{'usersessions'}{$prefix} = {};
+ }
+ my %domdefaults = &Apache::lonnet::get_domain_defaults($dom);
+ my $resulttext;
+ my %iphost = &Apache::lonnet::get_iphost();
+ foreach my $prefix (@prefixes) {
+ next if ($prefix eq 'spares');
+ foreach my $type (@{$types{$prefix}}) {
+ my $inuse = $env{'form.'.$prefix.'_'.$type.'_inuse'};
+ if ($type eq 'version') {
+ my $value = $env{'form.'.$prefix.'_'.$type};
+ my $okvalue;
+ if ($value ne '') {
+ if (grep(/^\Q$value\E$/,@lcversions)) {
+ $okvalue = $value;
+ }
+ }
+ if (ref($domconfig{'usersessions'}) eq 'HASH') {
+ if (ref($domconfig{'usersessions'}{$prefix}) eq 'HASH') {
+ if ($domconfig{'usersessions'}{$prefix}{$type} ne '') {
+ if ($inuse == 0) {
+ $changes{$prefix}{$type} = 1;
+ } else {
+ if ($okvalue ne $domconfig{'usersessions'}{$prefix}{$type}) {
+ $changes{$prefix}{$type} = 1;
+ }
+ if ($okvalue ne '') {
+ $defaultshash{'usersessions'}{$prefix}{$type} = $okvalue;
+ }
+ }
+ } else {
+ if (($inuse == 1) && ($okvalue ne '')) {
+ $defaultshash{'usersessions'}{$prefix}{$type} = $okvalue;
+ $changes{$prefix}{$type} = 1;
+ }
+ }
+ } else {
+ if (($inuse == 1) && ($okvalue ne '')) {
+ $defaultshash{'usersessions'}{$prefix}{$type} = $okvalue;
+ $changes{$prefix}{$type} = 1;
+ }
+ }
+ } else {
+ if (($inuse == 1) && ($okvalue ne '')) {
+ $defaultshash{'usersessions'}{$prefix}{$type} = $okvalue;
+ $changes{$prefix}{$type} = 1;
+ }
+ }
+ } else {
+ my @vals = &Apache::loncommon::get_env_multiple('form.'.$prefix.'_'.$type);
+ my @okvals;
+ foreach my $val (@vals) {
+ if ($val =~ /:/) {
+ my @items = split(/:/,$val);
+ foreach my $item (@items) {
+ if (ref($by_location{$item}) eq 'ARRAY') {
+ push(@okvals,$item);
+ }
+ }
+ } else {
+ if (ref($by_location{$val}) eq 'ARRAY') {
+ push(@okvals,$val);
+ }
+ }
+ }
+ @okvals = sort(@okvals);
+ if (ref($domconfig{'usersessions'}) eq 'HASH') {
+ if (ref($domconfig{'usersessions'}{$prefix}) eq 'HASH') {
+ if (ref($domconfig{'usersessions'}{$prefix}{$type}) eq 'ARRAY') {
+ if ($inuse == 0) {
+ $changes{$prefix}{$type} = 1;
+ } else {
+ $defaultshash{'usersessions'}{$prefix}{$type} = \@okvals;
+ my @changed = &Apache::loncommon::compare_arrays($domconfig{'usersessions'}{$prefix}{$type},$defaultshash{'usersessions'}{$prefix}{$type});
+ if (@changed > 0) {
+ $changes{$prefix}{$type} = 1;
+ }
+ }
+ } else {
+ if ($inuse == 1) {
+ $defaultshash{'usersessions'}{$prefix}{$type} = \@okvals;
+ $changes{$prefix}{$type} = 1;
+ }
+ }
+ } else {
+ if ($inuse == 1) {
+ $defaultshash{'usersessions'}{$prefix}{$type} = \@okvals;
+ $changes{$prefix}{$type} = 1;
+ }
+ }
+ } else {
+ if ($inuse == 1) {
+ $defaultshash{'usersessions'}{$prefix}{$type} = \@okvals;
+ $changes{$prefix}{$type} = 1;
+ }
+ }
+ }
+ }
+ }
+
+ my @alldoms = &Apache::lonnet::all_domains();
+ my %uniques = &Apache::lonnet::get_unique_servers(\@alldoms);
+ my %servers = &Apache::lonnet::internet_dom_servers($dom);
+ my %spareid = ¤t_offloads_to($dom,$domconfig{'usersessions'},\%servers);
+ my $savespares;
+
+ foreach my $lonhost (sort(keys(%servers))) {
+ my $serverhomeID =
+ &Apache::lonnet::get_server_homeID($servers{$lonhost});
+ $defaultshash{'usersessions'}{'spares'}{$lonhost} = {};
+ my %spareschg;
+ foreach my $type (@{$types{'spares'}}) {
+ my @okspares;
+ my @checked = &Apache::loncommon::get_env_multiple('form.spare_'.$type.'_'.$lonhost);
+ foreach my $server (@checked) {
+ unless (($server eq $lonhost) || ($server eq $serverhomeID)) {
+ if ($uniques{$server}) {
+ push(@okspares,$server);
+ }
+ }
+ }
+ my $new = $env{'form.newspare_'.$type.'_'.$lonhost};
+ my $newspare;
+ if (($new ne '') && ($uniques{$new})) {
+ unless (($new eq $lonhost) || ($new eq $serverhomeID)) {
+ $newspare = $new;
+ $spareschg{$type} = 1;
+ }
+ }
+ if (ref($spareid{$lonhost}) eq 'HASH') {
+ if (ref($spareid{$lonhost}{$type}) eq 'ARRAY') {
+ my @diffs = &Apache::loncommon::compare_arrays($domconfig{'usersessions'}{'spares'}{$lonhost}{$type},\@okspares);
+ if (@diffs > 0) {
+ $spareschg{$type} = 1;
+ } elsif ($new ne '') {
+ $spareschg{$type} = 1;
+ }
+ }
+ }
+ my @spares;
+ if (($newspare ne '') && (!grep(/^\Q$newspare\E$/,@okspares))) {
+ @spares = sort(@okspares,$newspare);
+ } else {
+ @spares = sort(@okspares);
+ }
+ $defaultshash{'usersessions'}{'spares'}{$lonhost}{$type} = \@spares;
+ }
+ if (keys(%spareschg) > 0) {
+ $changes{'spares'}{$lonhost} = \%spareschg;
+ }
+ }
+
+ if (ref($domconfig{'usersessions'}) eq 'HASH') {
+ if (ref($domconfig{'usersessions'}{'spares'}) eq 'HASH') {
+ if (ref($changes{'spares'}) eq 'HASH') {
+ if (keys(%{$changes{'spares'}}) > 0) {
+ $savespares = 1;
+ }
+ }
+ } else {
+ $savespares = 1;
+ }
+ }
+
+ my $nochgmsg = &mt('No changes made to settings for user session hosting/offloading.');
+ if ((keys(%changes) > 0) || ($savespares)) {
+ my $putresult = &Apache::lonnet::put_dom('configuration',\%defaultshash,
+ $dom);
+ if ($putresult eq 'ok') {
+ if (ref($defaultshash{'usersessions'}) eq 'HASH') {
+ if (ref($defaultshash{'usersessions'}{'remote'}) eq 'HASH') {
+ $domdefaults{'remotesessions'} = $defaultshash{'usersessions'}{'remote'};
+ }
+ if (ref($defaultshash{'usersessions'}{'hosted'}) eq 'HASH') {
+ $domdefaults{'hostedsessions'} = $defaultshash{'usersessions'}{'hosted'};
+ }
+ }
+ my $cachetime = 24*60*60;
+ &Apache::lonnet::do_cache_new('domdefaults',$dom,\%domdefaults,$cachetime);
+ if (keys(%changes) > 0) {
+ my %lt = &usersession_titles();
+ $resulttext = &mt('Changes made:').'';
+ foreach my $prefix (@prefixes) {
+ if (ref($changes{$prefix}) eq 'HASH') {
+ $resulttext .= ''.$lt{$prefix}.'';
+ if ($prefix eq 'spares') {
+ if (ref($changes{$prefix}) eq 'HASH') {
+ foreach my $lonhost (sort(keys(%{$changes{$prefix}}))) {
+ $resulttext .= ''.$lonhost.' ';
+ my $lonhostdom = &Apache::lonnet::host_domain($lonhost);
+ &Apache::lonnet::remote_devalidate_cache($lonhost,'spares',$lonhostdom);
+ if (ref($changes{$prefix}{$lonhost}) eq 'HASH') {
+ foreach my $type (@{$types{$prefix}}) {
+ if ($changes{$prefix}{$lonhost}{$type}) {
+ my $offloadto = &mt('None');
+ if (ref($defaultshash{'usersessions'}{'spares'}{$lonhost}{$type}) eq 'ARRAY') {
+ if (@{$defaultshash{'usersessions'}{'spares'}{$lonhost}{$type}} > 0) {
+ $offloadto = join(', ',@{$defaultshash{'usersessions'}{'spares'}{$lonhost}{$type}});
+ }
+ }
+ $resulttext .= &mt('[_1] set to: [_2].',''.$lt{$type}.' ',$offloadto).(' 'x3);
+ }
+ }
+ }
+ $resulttext .= ' ';
+ }
+ }
+ } else {
+ foreach my $type (@{$types{$prefix}}) {
+ if (defined($changes{$prefix}{$type})) {
+ my $newvalue;
+ if (ref($defaultshash{'usersessions'}) eq 'HASH') {
+ if (ref($defaultshash{'usersessions'}{$prefix})) {
+ if ($type eq 'version') {
+ $newvalue = $defaultshash{'usersessions'}{$prefix}{$type};
+ } elsif (ref($defaultshash{'usersessions'}{$prefix}{$type}) eq 'ARRAY') {
+ if (@{$defaultshash{'usersessions'}{$prefix}{$type}} > 0) {
+ $newvalue = join(', ',@{$defaultshash{'usersessions'}{$prefix}{$type}});
+ }
+ }
+ }
+ }
+ if ($newvalue eq '') {
+ if ($type eq 'version') {
+ $resulttext .= ''.&mt('[_1] set to: off',$lt{$type}).' ';
+ } else {
+ $resulttext .= ''.&mt('[_1] set to: none',$lt{$type}).' ';
+ }
+ } else {
+ if ($type eq 'version') {
+ $newvalue .= ' '.&mt('(or later)');
+ }
+ $resulttext .= ''.&mt('[_1] set to: [_2].',$lt{$type},$newvalue).' ';
+ }
+ }
+ }
+ }
+ $resulttext .= ' ';
+ }
+ }
+ $resulttext .= ' ';
+ } else {
+ $resulttext = $nochgmsg;
+ }
+ } else {
+ $resulttext = ''.
+ &mt('An error occurred: [_1]',$putresult).' ';
+ }
+ } else {
+ $resulttext = $nochgmsg;
+ }
+ return $resulttext;
+}
+
+sub modify_loadbalancing {
+ my ($dom,%domconfig) = @_;
+ my $primary_id = &Apache::lonnet::domain($dom,'primary');
+ my $intdom = &Apache::lonnet::internet_dom($primary_id);
+ my ($othertitle,$usertypes,$types) =
+ &Apache::loncommon::sorted_inst_types($dom);
+ my %servers = &Apache::lonnet::internet_dom_servers($dom);
+ my @sparestypes = ('primary','default');
+ my %typetitles = &sparestype_titles();
+ my $resulttext;
+ if (keys(%servers) > 1) {
+ my ($currbalancer,$currtargets,$currrules);
+ if (ref($domconfig{'loadbalancing'}) eq 'HASH') {
+ $currbalancer = $domconfig{'loadbalancing'}{'lonhost'};
+ $currtargets = $domconfig{'loadbalancing'}{'targets'};
+ $currrules = $domconfig{'loadbalancing'}{'rules'};
+ } else {
+ ($currbalancer,$currtargets) =
+ &Apache::lonnet::get_lonbalancer_config(\%servers);
+ }
+ my ($saveloadbalancing,%defaultshash,%changes);
+ my ($alltypes,$othertypes,$titles) =
+ &loadbalancing_titles($dom,$intdom,$usertypes,$types);
+ my %ruletitles = &offloadtype_text();
+ my $balancer = $env{'form.loadbalancing_lonhost'};
+ if (!$servers{$balancer}) {
+ undef($balancer);
+ }
+ if ($currbalancer ne $balancer) {
+ $changes{'lonhost'} = 1;
+ }
+ $defaultshash{'loadbalancing'}{'lonhost'} = $balancer;
+ if ($balancer ne '') {
+ unless (ref($domconfig{'loadbalancing'}) eq 'HASH') {
+ $saveloadbalancing = 1;
+ }
+ foreach my $sparetype (@sparestypes) {
+ my @targets = &Apache::loncommon::get_env_multiple('form.loadbalancing_target_'.$sparetype);
+ foreach my $target (@targets) {
+ my @offloadto;
+ if (($servers{$target}) && ($target ne $balancer)) {
+ if ($sparetype eq 'default') {
+ if (ref($defaultshash{'loadbalancing'}{'targets'}{'primary'}) eq 'ARRAY') {
+ next if (grep(/^\Q$target\E$/,@{$defaultshash{'loadbalancing'}{'targets'}{'primary'}}));
+ }
+ }
+ unless(grep(/^\Q$target\E$/,@offloadto)) {
+ push(@offloadto,$target);
+ }
+ }
+ $defaultshash{'loadbalancing'}{'targets'}{$sparetype} = \@offloadto;
+ }
+ }
+ } else {
+ foreach my $sparetype (@sparestypes) {
+ $defaultshash{'loadbalancing'}{'targets'}{$sparetype} = [];
+ }
+ }
+ if (ref($currtargets) eq 'HASH') {
+ foreach my $sparetype (@sparestypes) {
+ if (ref($currtargets->{$sparetype}) eq 'ARRAY') {
+ my @targetdiffs = &Apache::loncommon::compare_arrays($currtargets->{$sparetype},$defaultshash{'loadbalancing'}{'targets'}{$sparetype});
+ if (@targetdiffs > 0) {
+ $changes{'targets'} = 1;
+ }
+ } elsif (ref($defaultshash{'loadbalancing'}{'targets'}{$sparetype}) eq 'ARRAY') {
+ if (@{$defaultshash{'loadbalancing'}{'targets'}{$sparetype}} > 0) {
+ $changes{'targets'} = 1;
+ }
+ }
+ }
+ } else {
+ foreach my $sparetype (@sparestypes) {
+ if (ref($defaultshash{'loadbalancing'}{'targets'}{$sparetype}) eq 'ARRAY') {
+ if (@{$defaultshash{'loadbalancing'}{'targets'}{$sparetype}} > 0) {
+ $changes{'targets'} = 1;
+ }
+ }
+ }
+ }
+ my $ishomedom;
+ if ($balancer ne '') {
+ if (&Apache::lonnet::host_domain($balancer) eq $dom) {
+ $ishomedom = 1;
+ }
+ }
+ if (ref($alltypes) eq 'ARRAY') {
+ foreach my $type (@{$alltypes}) {
+ my $rule;
+ if ($balancer ne '') {
+ unless ((($type eq '_LC_external') || ($type eq '_LC_internetdom')) &&
+ (!$ishomedom)) {
+ $rule = $env{'form.loadbalancing_rules_'.$type};
+ }
+ if ($rule eq 'specific') {
+ $rule = $env{'form.loadbalancing_singleserver_'.$type};
+ }
+ }
+ $defaultshash{'loadbalancing'}{'rules'}{$type} = $rule;
+ if (ref($currrules) eq 'HASH') {
+ if ($rule ne $currrules->{$type}) {
+ $changes{'rules'}{$type} = 1;
+ }
+ } elsif ($rule ne '') {
+ $changes{'rules'}{$type} = 1;
+ }
+ }
+ }
+ my $nochgmsg = &mt('No changes made to Load Balancer settings.');
+ if ((keys(%changes) > 0) || ($saveloadbalancing)) {
+ my $putresult = &Apache::lonnet::put_dom('configuration',
+ \%defaultshash,$dom);
+ if ($putresult eq 'ok') {
+ if (keys(%changes) > 0) {
+ if ($changes{'lonhost'}) {
+ if ($currbalancer ne '') {
+ &Apache::lonnet::remote_devalidate_cache($currbalancer,'loadbalancing',$dom);
+ }
+ if ($balancer eq '') {
+ $resulttext .= ''.&mt('Load Balancing with dedicated server discontinued').' ';
+ } else {
+ &Apache::lonnet::remote_devalidate_cache($balancer,'loadbalancing',$dom);
+ $resulttext .= ''.&mt('Dedicated Load Balancer server set to [_1]',$balancer);
+ }
+ } else {
+ &Apache::lonnet::remote_devalidate_cache($balancer,'loadbalancing',$dom);
+ }
+ if (($changes{'targets'}) && ($balancer ne '')) {
+ my %offloadstr;
+ foreach my $sparetype (@sparestypes) {
+ if (ref($defaultshash{'loadbalancing'}{'targets'}{$sparetype}) eq 'ARRAY') {
+ if (@{$defaultshash{'loadbalancing'}{'targets'}{$sparetype}} > 0) {
+ $offloadstr{$sparetype} = join(', ',@{$defaultshash{'loadbalancing'}{'targets'}{$sparetype}});
+ }
+ }
+ }
+ if (keys(%offloadstr) == 0) {
+ $resulttext .= ' '.&mt("Servers to which Load Balance server offloads set to 'None', by default").' ';
+ } else {
+ my $showoffload;
+ foreach my $sparetype (@sparestypes) {
+ $showoffload .= ''.$typetitles{$sparetype}.' : ';
+ if (defined($offloadstr{$sparetype})) {
+ $showoffload .= $offloadstr{$sparetype};
+ } else {
+ $showoffload .= &mt('None');
+ }
+ $showoffload .= (' 'x3);
+ }
+ $resulttext .= ''.&mt('By default, Load Balancer server set to offload to: [_1]',$showoffload).' ';
+ }
+ }
+ if ((ref($changes{'rules'}) eq 'HASH') && ($balancer ne '')) {
+ if ((ref($alltypes) eq 'ARRAY') && (ref($titles) eq 'HASH')) {
+ foreach my $type (@{$alltypes}) {
+ if ($changes{'rules'}{$type}) {
+ my $rule = $defaultshash{'loadbalancing'}{'rules'}{$type};
+ my $balancetext;
+ if ($rule eq '') {
+ $balancetext = $ruletitles{'default'};
+ } elsif (($rule eq 'homeserver') || ($rule eq 'externalbalancer')) {
+ $balancetext = $ruletitles{$rule};
+ } else {
+ $balancetext = &mt('offload to [_1]',$defaultshash{'loadbalancing'}{'rules'}{$type});
+ }
+ $resulttext .= ''.&mt('Load Balancing for [_1] set to: [_2]',$titles->{$type},$balancetext).' ';
+ }
+ }
+ }
+ }
+ if ($resulttext ne '') {
+ $resulttext = &mt('Changes made:').'';
+ } else {
+ $resulttext = $nochgmsg;
+ }
+ } else {
+ $resulttext = $nochgmsg;
+ if ($balancer ne '') {
+ &Apache::lonnet::remote_devalidate_cache($balancer,'loadbalancing',$dom);
+ }
+ }
+ } else {
+ $resulttext = ''.
+ &mt('An error occurred: [_1]',$putresult).' ';
+ }
+ } else {
+ $resulttext = $nochgmsg;
+ }
+ } else {
+ $resulttext = &mt('Load Balancing unavailable as this domain only has one server.');
+ }
+ return $resulttext;
+}
+
+sub recurse_check {
+ my ($chkcats,$categories,$depth,$name) = @_;
+ if (ref($chkcats->[$depth]{$name}) eq 'ARRAY') {
+ my $chg = 0;
+ for (my $j=0; $j<@{$chkcats->[$depth]{$name}}; $j++) {
+ my $category = $chkcats->[$depth]{$name}[$j];
+ my $item;
+ if ($category eq '') {
+ $chg ++;
+ } else {
+ my $deeper = $depth + 1;
+ $item = &escape($category).':'.&escape($name).':'.$depth;
+ if ($chg) {
+ $categories->{$item} -= $chg;
+ }
+ &recurse_check($chkcats,$categories,$deeper,$category);
+ $deeper --;
+ }
+ }
+ }
+ return;
+}
+
+sub recurse_cat_deletes {
+ my ($item,$coursecategories,$deletions) = @_;
+ my ($deleted,$container,$depth) = map { &unescape($_); } split(/:/,$item);
+ my $subdepth = $depth + 1;
+ if (ref($coursecategories) eq 'HASH') {
+ foreach my $subitem (keys(%{$coursecategories})) {
+ my ($child,$parent,$itemdepth) = map { &unescape($_); } split(/:/,$subitem);
+ if (($parent eq $deleted) && ($itemdepth == $subdepth)) {
+ delete($coursecategories->{$subitem});
+ $deletions->{$subitem} = 1;
+ &recurse_cat_deletes($subitem,$coursecategories,$deletions);
+ }
+ }
+ }
+ return;
+}
+
+sub get_active_dcs {
+ my ($dom) = @_;
+ my %dompersonnel = &Apache::lonnet::get_domain_roles($dom,['dc']);
+ my %domcoords;
+ my $numdcs = 0;
+ my $now = time;
+ foreach my $server (keys(%dompersonnel)) {
+ foreach my $user (sort(keys(%{$dompersonnel{$server}}))) {
+ my ($trole,$uname,$udom,$runame,$rudom,$rsec) = split(/:/,$user);
+ my ($end,$start) = split(':',$dompersonnel{$server}{$user});
+ if (($end eq '') || ($end == 0) || ($end > $now)) {
+ if ($start <= $now) {
+ $domcoords{$uname.':'.$udom} = $dompersonnel{$server}{$user};
+ }
+ }
+ }
+ }
+ return %domcoords;
+}
+
+sub active_dc_picker {
+ my ($dom,$curr_dc) = @_;
+ my %domcoords = &get_active_dcs($dom);
+ my @dcs = sort(keys(%domcoords));
+ my $numdcs = scalar(@dcs);
+ my $datatable;
+ my $numinrow = 2;
+ if ($numdcs > 1) {
+ $datatable = '';
+ } elsif (@dcs) {
+ $datatable .= ' ';
+ }
+ return ($numdcs,$datatable);
+}
+
+sub usersession_titles {
+ return &Apache::lonlocal::texthash(
+ hosted => 'Hosting of sessions for users from other domains on servers in this domain',
+
+ remote => 'Hosting of sessions for users in this domain on servers in other domains',
+ spares => 'Servers offloaded to, when busy',
+ version => 'LON-CAPA version requirement',
+ excludedomain => 'Allow all, but exclude specific domains',
+ includedomain => 'Deny all, but include specific domains',
+ primary => 'Primary (checked first)',
+ default => 'Default',
+ );
+}
+
+sub count_servers {
+ my ($currbalancer,%servers) = @_;
+ my (@spares,$numspares);
+ foreach my $lonhost (sort(keys(%servers))) {
+ next if ($currbalancer eq $lonhost);
+ push(@spares,$lonhost);
+ }
+ if ($currbalancer) {
+ $numspares = scalar(@spares);
+ } else {
+ $numspares = scalar(@spares) - 1;
+ }
+ return ($numspares,@spares);
+}
+
+sub lonbalance_targets_js {
+ my ($dom,$types,$servers) = @_;
+ my $select = &mt('Select');
+ my ($alltargets,$allishome,$allinsttypes,@alltypes);
+ if (ref($servers) eq 'HASH') {
+ $alltargets = join("','",sort(keys(%{$servers})));
+ my @homedoms;
+ foreach my $server (sort(keys(%{$servers}))) {
+ if (&Apache::lonnet::host_domain($server) eq $dom) {
+ push(@homedoms,'1');
+ } else {
+ push(@homedoms,'0');
+ }
+ }
+ $allishome = join("','",@homedoms);
+ }
+ if (ref($types) eq 'ARRAY') {
+ if (@{$types} > 0) {
+ @alltypes = @{$types};
+ }
+ }
+ push(@alltypes,'default','_LC_adv','_LC_author','_LC_internetdom','_LC_external');
+ $allinsttypes = join("','",@alltypes);
+ return <<"END";
+
+
+
+END
+}
+
1;