--- loncom/interface/domainprefs.pm 2007/12/11 00:44:23 1.33 +++ loncom/interface/domainprefs.pm 2008/05/01 00:01:16 1.47 @@ -1,7 +1,7 @@ # The LearningOnline Network with CAPA # Handler to set domain-wide configuration settings # -# $Id: domainprefs.pm,v 1.33 2007/12/11 00:44:23 raeburn Exp $ +# $Id: domainprefs.pm,v 1.47 2008/05/01 00:01:16 raeburn Exp $ # # Copyright Michigan State University Board of Trustees # @@ -36,9 +36,11 @@ use Apache::lonnet; use Apache::loncommon(); use Apache::lonhtmlcommon(); use Apache::lonlocal; +use Apache::lonmsg(); use LONCAPA(); use LONCAPA::Enrollment; use File::Copy; +use Locale::Language; sub handler { my $r=shift; @@ -68,10 +70,11 @@ sub handler { my %domconfig = &Apache::lonnet::get_dom('configuration',['login','rolecolors', 'quotas','autoenroll','autoupdate','directorysrch', - 'usercreation','usermodification','contacts'],$dom); - my @prefs_order = ('rolecolors','login','quotas','autoenroll', + 'usercreation','usermodification','contacts','defaults','scantron'], + $dom); + my @prefs_order = ('rolecolors','login','defaults','quotas','autoenroll', 'autoupdate','directorysrch','contacts', - 'usercreation','usermodification'); + 'usercreation','usermodification','scantron'); my %prefs = ( 'rolecolors' => { text => 'Default color schemes', @@ -91,6 +94,12 @@ sub handler { header => [{col1 => 'Item', col2 => '',}], }, + 'defaults' => + { text => 'Default authentication/language', + help => '', + header => [{col1 => 'Setting', + col2 => 'Value'}], + }, 'quotas' => { text => 'Default quotas for user portfolios', help => 'Default_User_Quota', @@ -108,7 +117,7 @@ sub handler { help => 'Domain_Auto_Update', header => [{col1 => 'Setting', col2 => 'Value',}, - {col1 => 'User Population', + {col1 => 'User population', col2 => 'Updataeable user data'}], }, 'directorysrch' => @@ -127,10 +136,12 @@ sub handler { 'usercreation' => { text => 'User creation', help => 'Domain_User_Creation', - header => [{col1 => 'Setting', - col2 => 'Value',}, + header => [{col1 => 'Format rule type', + col2 => 'Format rules in force'}, + {col1 => 'User account creation', + col2 => 'Usernames which may be created',}, {col1 => 'Context', - col2 => 'Assignable Authentication Types'}], + col2 => 'Assignable authentication types'}], }, 'usermodification' => { text => 'User modification', @@ -140,6 +151,13 @@ sub handler { {col1 => 'Target user has role', col2 => 'User information updateable in course context'}], }, + 'scantron' => + { text => 'Scantron format file', + help => 'Domain_Scantron_Formats', + header => [ {col1 => 'Item', + col2 => '', + }], + }, ); my @roles = ('student','coordinator','author','admin'); my @actions = &Apache::loncommon::get_env_multiple('form.actions'); @@ -245,7 +263,7 @@ sub handler { my @ids=&Apache::lonnet::current_machine_ids(); if (!grep(/^\Q$primarylibserv\E$/,@ids)) { my %designhash = &Apache::loncommon::get_domainconf($dom); - my @loginimages = ('img','logo','domlogo'); + my @loginimages = ('img','logo','domlogo','login'); my $custom_img_count = 0; foreach my $img (@loginimages) { if ($designhash{$dom.'.login.'.$img} ne '') { @@ -279,11 +297,24 @@ sub handler { ' />  '. '

'); + ' />

'); + my ($numitems,$midpoint,$seconddiv,$count); + $numitems = @prefs_order; + $midpoint = int($numitems/2); + if ($numitems%2) { + $midpoint ++; + } + $count = 0; foreach my $item (@prefs_order) { - $r->print('

'); + $r->print('

'); + $count ++; + if ((!$seconddiv) && ($count >= $midpoint)) { + $r->print('
'."\n".'
'."\n"); + $seconddiv = 1; + } } - $r->print('

'.&mt('Display options').'

'."\n". + $r->print('

'. + &mt('Display options').'

'."\n". '

'.&mt('Display using: ')."\n". '  '. @@ -318,6 +349,10 @@ sub process_changes { $output = &modify_usermodification($dom,%domconfig); } elsif ($action eq 'contacts') { $output = &modify_contacts($dom,%domconfig); + } elsif ($action eq 'defaults') { + $output = &modify_defaults($dom,$r); + } elsif ($action eq 'scantron') { + $output = &modify_scantron($r,$dom,$confname,\%domconfig); } return $output; } @@ -372,7 +407,18 @@ sub print_config_box { if ($action eq 'autoupdate') { $output .= &print_autoupdate('bottom',$dom,$settings,\$rowtotal); } elsif ($action eq 'usercreation') { - $output .= &print_usercreation('bottom',$dom,$settings,\$rowtotal); + $output .= &print_usercreation('middle',$dom,$settings,\$rowtotal).' + + + + + + + + + '. + &print_usercreation('bottom',$dom,$settings,\$rowtotal); + $rowtotal ++; } elsif ($action eq 'usermodification') { $output .= &print_usermodification('bottom',$dom,$settings,\$rowtotal); } else { @@ -428,6 +474,10 @@ sub print_config_box { $output .= &print_directorysrch($dom,$settings,\$rowtotal); } elsif ($action eq 'contacts') { $output .= &print_contacts($dom,$settings,\$rowtotal); + } elsif ($action eq 'defaults') { + $output .= &print_defaults($dom,\$rowtotal); + } elsif ($action eq 'scantron') { + $output .= &print_scantronformat($r,$dom,$confname,$settings,\$rowtotal); } } $output .= ' @@ -542,10 +592,25 @@ sub print_footer { sub print_login { my ($dom,$confname,$phase,$settings,$rowtotal) = @_; my %choices = &login_choices(); - my ($catalogon,$catalogoff,$adminmailon,$adminmailoff); - $catalogon = ' checked="checked" '; - $adminmailoff = ' checked="checked" '; - my @images = ('img','logo','domlogo'); + my %defaultchecked = ( + 'coursecatalog' => 'on', + 'adminmail' => 'off', + 'newuser' => 'off', + ); + my @toggles = ('coursecatalog','adminmail','newuser'); + my (%checkedon,%checkedoff); + foreach my $item (@toggles) { + if ($defaultchecked{$item} eq 'on') { + $checkedon{$item} = ' checked="checked" '; + $checkedoff{$item} = ' '; + } elsif ($defaultchecked{$item} eq 'off') { + $checkedoff{$item} = ' checked="checked" '; + $checkedon{$item} = ' '; + } + } + my $loginheader = 'image'; + my @images = ('img','logo','domlogo','login'); + my @logintext = ('textcol','bgcol'); my @bgs = ('pgbg','mainbg','sidebg'); my @links = ('link','alink','vlink'); my %designhash = &Apache::loncommon::get_domainconf($dom); @@ -560,17 +625,21 @@ sub print_login { foreach my $item (@bgs) { $defaults{'bgs'}{$item} = $defaultdesign{'login.'.$item}; } + foreach my $item (@logintext) { + $defaults{'logintext'}{$item} = $defaultdesign{'login.'.$item}; + } foreach my $item (@links) { $defaults{'links'}{$item} = $defaultdesign{'login.'.$item}; } if (ref($settings) eq 'HASH') { - if ($settings->{'coursecatalog'} eq '0') { - $catalogoff = $catalogon; - $catalogon = ' '; - } - if ($settings->{'adminmail'} eq '1') { - $adminmailon = $adminmailoff; - $adminmailoff = ' '; + foreach my $item (@toggles) { + if ($settings->{$item} eq '1') { + $checkedon{$item} = ' checked="checked" '; + $checkedoff{$item} = ' '; + } elsif ($settings->{$item} eq '0') { + $checkedoff{$item} = ' checked="checked" '; + $checkedon{$item} = ' '; + } } foreach my $item (@images) { if ($settings->{$item} ne '') { @@ -578,6 +647,15 @@ sub print_login { $is_custom{$item} = 1; } } + foreach my $item (@logintext) { + if ($settings->{$item} ne '') { + $designs{'logintext'}{$item} = $settings->{$item}; + $is_custom{$item} = 1; + } + } + if ($settings->{'loginheader'} ne '') { + $loginheader = $settings->{'loginheader'}; + } if ($settings->{'font'} ne '') { $designs{'font'} = $settings->{'font'}; $is_custom{'font'} = 1; @@ -620,28 +698,23 @@ sub print_login { } my %alt_text = &Apache::lonlocal::texthash ( img => 'Log-in banner', logo => 'Institution Logo', - domlogo => 'Domain Logo'); + domlogo => 'Domain Logo', + login => 'Login box'); my $itemcount = 1; - my $css_class = $itemcount%2?' class="LC_odd_row"':''; - my $datatable = - ''. - ''; - $itemcount ++; - $css_class = $itemcount%2?' class="LC_odd_row"':''; - $datatable .= ''. - ''. - ''; - $itemcount ++; - $datatable .= &display_color_options($dom,$confname,$phase,'login',$itemcount,\%choices,\%is_custom,\%defaults,\%designs,\@images,\@bgs,\@links,\%alt_text,$rowtotal); + my ($css_class,$datatable); + foreach my $item (@toggles) { + $css_class = $itemcount%2?' class="LC_odd_row"':''; + $datatable .= + ''. + ''; + $itemcount ++; + } + $datatable .= &display_color_options($dom,$confname,$phase,'login',$itemcount,\%choices,\%is_custom,\%defaults,\%designs,\@images,\@bgs,\@links,\%alt_text,$rowtotal,\@logintext,$loginheader); $datatable .= '
'.$item->{'header'}->[2]->{'col1'}.''.$item->{'header'}->[2]->{'col2'}.'
'.$choices{'coursecatalog'}. - ''. - ' '. - '
'.$choices{'adminmail'}.''. - ' '. - '
'.$choices{$item}. + ''. + ' 
'; return $datatable; } @@ -651,9 +724,13 @@ sub login_choices { &Apache::lonlocal::texthash ( coursecatalog => 'Display Course Catalog link?', adminmail => "Display Administrator's E-mail Address?", + newuser => "Link to create a user account", img => "Header", logo => "Main Logo", domlogo => "Domain Logo", + login => "Log-in Header", + textcol => "Text color", + bgcol => "Box color", bgs => "Background colors", links => "Link colors", font => "Font color", @@ -741,7 +818,7 @@ sub print_rolecolors { sub display_color_options { my ($dom,$confname,$phase,$role,$itemcount,$choices,$is_custom,$defaults,$designs, - $images,$bgs,$links,$alt_text,$rowtotal) = @_; + $images,$bgs,$links,$alt_text,$rowtotal,$logintext,$loginheader) = @_; my $css_class = $itemcount%2?' class="LC_odd_row"':''; my $datatable = ''. ''.$choices->{'font'}.''; @@ -763,13 +840,19 @@ sub display_color_options { $css_class = $itemcount%2?' class="LC_odd_row"':''; $datatable .= ''. ''.$choices->{$img}.''; - my ($imgfile, $img_import); + my ($imgfile,$img_import,$login_hdr_pick,$logincolors); if ($designs->{$img} ne '') { $imgfile = $designs->{$img}; $img_import = ($imgfile =~ m{^/adm/}); } else { $imgfile = $defaults->{$img}; } + if ($img eq 'login') { + $login_hdr_pick = &login_header_options($img,$role,$defaults,$is_custom,$choices, + $loginheader); + $logincolors = + &login_text_colors($img,$role,$logintext,$phase,$choices,$designs); + } if ($imgfile) { my ($showfile,$fullsize); if ($imgfile =~ m-^(/res/\Q$dom\E/\Q$confname\E/\Q$img\E)/([^/]+)$-) { @@ -810,25 +893,32 @@ sub display_color_options { } } if ($showfile) { - $showfile = &Apache::loncommon::lonhttpdurl($showfile); - $fullsize = &Apache::loncommon::lonhttpdurl($imgfile); - $datatable.= ''; - if (!$is_custom->{$img}) { - $datatable .= &mt('Default in use:').'
'; - } - if ($img_import) { - $datatable.= ''; - } - $datatable.= ''.$alt_text->{$img}.
-                             ''; - if ($is_custom->{$img}) { - $datatable.=' '.&mt('Replace:').'
'; - } else { - $datatable.=''.&mt('Upload:').'
'; + if ($showfile =~ m{^/(adm|res)/}) { + if ($showfile =~ m{^/res/}) { + my $local_showfile = + &Apache::lonnet::filelocation('',$showfile); + &Apache::lonnet::repcopy($local_showfile); + } + $showfile = &Apache::loncommon::lonhttpdurl($showfile); + } + if ($imgfile) { + if ($imgfile =~ m{^/(adm|res)/}) { + if ($imgfile =~ m{^/res/}) { + my $local_imgfile = + &Apache::lonnet::filelocation('',$imgfile); + &Apache::lonnet::repcopy($local_imgfile); + } + $fullsize = &Apache::loncommon::lonhttpdurl($imgfile); + } else { + $fullsize = $imgfile; + } } + $datatable .= ''; + if ($img eq 'login') { + $datatable .= $login_hdr_pick; + } + $datatable .= &image_changes($is_custom->{$img},$alt_text->{$img},$img_import, + $showfile,$fullsize,$role,$img,$imgfile,$logincolors); } else { $datatable .= '
'. &mt('Upload:'); @@ -868,7 +958,7 @@ sub display_color_options { $datatable .= '    '; } $datatable .= '
'; + '" onblur = "javascript:colchg_span('."'css_".$role.'_'.$item."'".',this);" />'; } $datatable .= ''; $itemcount ++; @@ -902,6 +992,79 @@ sub display_color_options { return $datatable; } +sub login_header_options { + my ($img,$role,$defaults,$is_custom,$choices,$loginheader) = @_; + my $image_checked = ' checked="checked" '; + my $text_checked = ' '; + if ($loginheader eq 'text') { + $image_checked = ' '; + $text_checked = ' checked="checked" '; + } + my $output = '   '. + '
'."\n"; + if ((!$is_custom->{'textcol'}) || (!$is_custom->{'bgcol'})) { + $output .= &mt('Text default(s)').':
'; + if (!$is_custom->{'textcol'}) { + $output .= $choices->{'textcol'}.': '.$defaults->{'logintext'}{'textcol'}. + '   '; + } + if (!$is_custom->{'bgcol'}) { + $output .= $choices->{'bgcol'}.': '. + '   '; + } + $output .= '
'; + } + $output .='
'; + return $output; +} + +sub login_text_colors { + my ($img,$role,$logintext,$phase,$choices,$designs) = @_; + my $color_menu = ''; + foreach my $item (@{$logintext}) { + my $link = &color_pick($phase,$role,$item,$choices->{$item},$designs->{'logintext'}{$item}); + $color_menu .= ''. + ''; + } + $color_menu .= '
'.$link; + if ($designs->{'logintext'}{$item}) { + $color_menu .= '    '; + } + $color_menu .= '
 

'; + return $color_menu; +} + +sub image_changes { + my ($is_custom,$alt_text,$img_import,$showfile,$fullsize,$role,$img,$imgfile,$logincolors) = @_; + my $output; + if (!$is_custom) { + if ($img eq 'login') { + $output .= &mt('Default image:').'
'; + } else { + $output .= &mt('Default in use:').'
'; + } + } + if ($img_import) { + $output .= ''; + } + $output .= ''.$alt_text.''; + if ($is_custom) { + $output .= ''.$logincolors.' '.&mt('Replace:').'
'; + } else { + $output .= ''.$logincolors.&mt('Upload:').'
'; + } + return $output; +} + sub color_pick { my ($phase,$role,$item,$desc,$curcol) = @_; my $link = '{'sender_uname'}; + } my $datatable=''. ''.&mt('Auto-enrollment active?').''. ''. + &mt('Default scantron format file').''; + } else { + $datatable = &mt('File unavailable for display'); + } + $datatable .= ''.&mt('Upload:').'
'; + } 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 scantron format file').'' + .'' + .''.&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] scantron format file in RES space. Error was: [_2].",$newfile,$result); + } + } + return ($url,$error); +} + sub modifiable_userdata_row { my ($context,$role,$settings,$numinrow,$rowcount) = @_; my $rolename; @@ -1599,25 +2039,6 @@ sub users_cansearch_row { 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', @@ -1657,10 +2078,12 @@ sub usertype_update_row { $datatable .= ''; } my $check = ' '; - if (ref($settings->{'fields'}) eq 'HASH') { - if (ref($settings->{'fields'}{$type}) eq 'ARRAY') { - if (grep(/^\Q$fields->[$i]\E$/,@{$settings->{'fields'}{$type}})) { - $check = ' checked="checked" '; + if (ref($settings) eq 'HASH') { + if (ref($settings->{'fields'}) eq 'HASH') { + if (ref($settings->{'fields'}{$type}) eq 'ARRAY') { + if (grep(/^\Q$fields->[$i]\E$/,@{$settings->{'fields'}{$type}})) { + $check = ' checked="checked" '; + } } } } @@ -1690,13 +2113,18 @@ sub modify_login { my ($r,$dom,$confname,%domconfig) = @_; my ($resulttext,$errors,$colchgtext,%changes,%colchanges); my %title = ( coursecatalog => 'Display course catalog', - adminmail => 'Display administrator E-mail address'); + 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 %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); @@ -1704,26 +2132,50 @@ sub modify_login { 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; + my @toggles = ('coursecatalog','adminmail','newuser'); + my %defaultchecked = ( + 'coursecatalog' => 'on', + 'adminmail' => 'off', + 'newuser' => 'off', + ); + 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 (($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; } if (keys(%changes) > 0 || $colchgtext) { + &Apache::loncommon::devalidate_domconfig_cache($dom); $resulttext = &mt('Changes made:').'

'; } else { @@ -1767,6 +2219,7 @@ sub modify_rolecolors { $dom); if ($putresult eq 'ok') { if (keys(%changes) > 0) { + &Apache::loncommon::devalidate_domconfig_cache($dom); $resulttext = &display_colorchgs($dom,\%changes,$roles, $rolehash{'rolecolors'}); } else { @@ -1788,35 +2241,32 @@ sub modify_colors { my (%changes,%choices); my @bgs = ('pgbg','mainbg','sidebg'); my @links = ('link','alink','vlink'); + my @logintext; my @images; my $servadm = $r->dir_config('lonAdmEMail'); my $errors; foreach my $role (@{$roles}) { if ($role eq 'login') { %choices = &login_choices(); + @logintext = ('textcol','bgcol'); } else { %choices = &color_font_choices(); } if ($role eq 'login') { - @images = ('img','logo','domlogo'); + @images = ('img','logo','domlogo','login'); } else { @images = ('img'); } $confhash->{$role}{'font'} = $env{'form.'.$role.'_font'}; - foreach my $item (@bgs,@links) { + 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 ( ! $env{'form.'.$role.'_'.$img.'.filename'} && !defined($domconfig->{$role}{$img}) @@ -1844,11 +2294,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); @@ -1924,20 +2374,46 @@ sub modify_colors { } } } + foreach my $item (@logintext) { + if ($domconfig->{$role}{$item} ne '') { + if ($confhash->{$role}{$item} ne $domconfig->{$role}{$item}) { + $changes{$role}{'logintext'}{$item} = 1; + } + } else { + if ($confhash->{$role}{$item}) { + $changes{$role}{'logintext'}{$item} = 1; + } + } + } } else { &default_change_checker($role,\@images,\@links,\@bgs, - $confhash,\%changes); + \@logintext,$confhash,\%changes); } } else { &default_change_checker($role,\@images,\@links,\@bgs, - $confhash,\%changes); + \@logintext,$confhash,\%changes); } } 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,$confhash,$changes) = @_; + my ($role,$images,$links,$bgs,$logintext,$confhash,$changes) = @_; foreach my $item (@{$links}) { if ($confhash->{$role}{$item}) { $changes->{$role}{'links'}{$item} = 1; @@ -1948,6 +2424,11 @@ sub default_change_checker { $changes->{$role}{'bgs'}{$item} = 1; } } + foreach my $item (@{$logintext}) { + if ($confhash->{$role}{$item}) { + $changes->{$role}{'logintext'}{$item} = 1; + } + } foreach my $img (@{$images}) { if ($env{'form.'.$role.'_del_'.$img}) { $confhash->{$role}{$img} = ''; @@ -1962,7 +2443,6 @@ sub default_change_checker { sub display_colorchgs { my ($dom,$changes,$roles,$confhash) = @_; my (%choices,$resulttext); - &Apache::loncommon::devalidate_domconfig_cache($dom); if (!grep(/^login$/,@{$roles})) { $resulttext = &mt('Changes made:').'
'; } @@ -2063,7 +2543,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'; } @@ -2071,7 +2551,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'}; @@ -2079,6 +2559,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'); } @@ -2106,7 +2589,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 { @@ -2302,7 +2785,7 @@ END sub modify_quotas { my ($dom,%domconfig) = @_; my ($resulttext,%changes); - my ($othertitle,$usertypes,$types) = &sorted_inst_types($dom); + my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom); my %formhash; foreach my $key (keys(%env)) { if ($key =~ /^form\.quota_(.+)$/) { @@ -2437,7 +2920,7 @@ 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', @@ -2566,7 +3049,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 { @@ -2820,7 +3303,7 @@ sub modify_contacts { } $resulttext .= ''; } else { - $resulttext = &mt('No changes made to contact information.'); + $resulttext = &mt('No changes made to contact information'); } } else { $resulttext = ''. @@ -2831,33 +3314,52 @@ sub modify_contacts { sub modify_usercreation { my ($dom,%domconfig) = @_; - my ($resulttext,%curr_usercreation,%changes,%authallowed); + 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 @cancreate = &Apache::loncommon::get_env_multiple('form.can_createuser'); - if (ref($curr_usercreation{'cancreate'}) eq 'ARRAY') { - foreach my $type (@{$curr_usercreation{'cancreate'}}) { - if (!grep(/^\Q$type\E$/,@cancreate)) { - push(@{$changes{'cancreate'}},$type); + my @email_rule = &Apache::loncommon::get_env_multiple('form.email_rule'); + my @contexts = ('author','course','selfcreate'); + foreach my $item(@contexts) { + $cancreate{$item} = $env{'form.can_createuser_'.$item}; + if ($item eq 'selfcreate') { + my %domdefaults = &Apache::lonnet::get_domain_defaults($dom); + if (!((($domdefaults{'auth_def'} =~/^krb/) && ($domdefaults{'auth_arg_def'} ne '')) || ($domdefaults{'auth_def'} eq 'localauth'))) { + if (($cancreate{$item} eq 'any') || ($cancreate{$item} eq 'login')) { + $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.'); + } } } - foreach my $type (@cancreate) { - if (!grep(/^\Q$type\E$/,@{$curr_usercreation{'cancreate'}})) { - push(@{$changes{'cancreate'}},$type); + } + if (ref($curr_usercreation{'cancreate'}) eq 'HASH') { + foreach my $item (@contexts) { + 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 ($cancreate{$item} ne 'any') { + push(@{$changes{'cancreate'}},$item); + } + } else { + if ($cancreate{$item} ne 'none') { + push(@{$changes{'cancreate'}},$item); + } } } } else { - push(@{$changes{'cancreate'}},@cancreate); + foreach my $item (@contexts) { + push(@{$changes{'cancreate'}},$item); + } } + if (ref($curr_usercreation{'username_rule'}) eq 'ARRAY') { foreach my $type (@{$curr_usercreation{'username_rule'}}) { if (!grep(/^\Q$type\E$/,@username_rule)) { @@ -2888,10 +3390,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)) { @@ -2902,7 +3419,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}) { @@ -2913,16 +3430,17 @@ sub modify_usercreation { } } } else { - foreach my $item (@contexts) { + foreach my $item (@authen_contexts) { push(@{$changes{'authtypes'}},$item); } } my %usercreation_hash = ( usercreation => { - cancreate => \@cancreate, + cancreate => \%cancreate, username_rule => \@username_rule, id_rule => \@id_rule, + email_rule => \@email_rule, authtypes => \%authhash, } ); @@ -2933,15 +3451,33 @@ sub modify_usercreation { if (keys(%changes) > 0) { $resulttext = &mt('Changes made:').''; $resulttext .= '
  • '.&mt('Authentication types available for assignment to new users').'
    '.$chgtext; @@ -3002,6 +3559,9 @@ sub modify_usercreation { $resulttext = ''. &mt('An error occurred: [_1]',$putresult).''; } + if ($warningmsg ne '') { + $resulttext .= '
    '.$warningmsg.'
    '; + } return $resulttext; } @@ -3104,5 +3664,172 @@ 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'); + 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 (code2language($langcode) eq '') { + push(@errors,$item); + } + } else { + push(@errors,$item); + } + } + } + if (grep(/^\Q$item\E$/,@errors)) { + $newvalues{$item} = $domdefaults{$item}; + } elsif ($domdefaults{$item} ne $newvalues{$item}) { + $changes{$item} = 1; + } + } + my %defaults_hash = ( + defaults => { auth_def => $newvalues{'auth_def'}, + auth_arg_def => $newvalues{'auth_arg_def'}, + lang_def => $newvalues{'lang_def'}, + } + ); + 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:').''; + $mailmsgtext .= "\n"; + my $cachetime = 24*60*60; + &Apache::lonnet::do_cache_new('domdefaults',$dom, + $defaults_hash{'defaults'},$cachetime); + 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 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 scantron 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{'scantron'}{'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) eq 'HASH') { + if (ref($domconfig->{'scantron'}) eq 'HASH') { + if ($domconfig->{'scantron'}{'scantronformat'} ne '') { + if ($env{'form.scantronformat_del'}) { + $confhash{'scantron'}{'scantronformat'} = ''; + $changes{'scantron'}{'scantronformat'} = 1; + } + } + } + } + if (keys(%confhash) > 0) { + my $putresult = &Apache::lonnet::put_dom('configuration',\%confhash, + $dom); + if ($putresult eq 'ok') { + if (keys(%changes) > 0) { + $resulttext = &mt('Changes made:').''; + &Apache::loncommon::devalidate_domconfig_cache($dom); + } else { + $resulttext = &mt('No changes made to scantron format file'); + } + } else { + $resulttext = ''. + &mt('An error occurred: [_1]',$putresult).''; + } + } else { + $resulttext = &mt('No changes made to scantron format file'); + } + if ($errors) { + $resulttext .= &mt('The following errors occurred: ').''; + } + return $resulttext; +} 1;