[LON-CAPA-cvs] cvs: loncom /auth lonauth.pm lonlogin.pm /interface domainprefs.pm

raeburn raeburn at source.lon-capa.org
Sun Aug 26 20:53:22 EDT 2012


raeburn		Mon Aug 27 00:53:22 2012 EDT

  Modified files:              
    /loncom/auth	lonauth.pm lonlogin.pm 
    /loncom/interface	domainprefs.pm 
  Log:
  - Move &loginhelpdisplay() from lonlogin.pm to lonauth.pm to facilitate reuse.
  - Log-in help page configuration moved from helpsettings to login section in 
    Domain configuration interface.
  - Add ability to upload different help files for the different supported languages.
  - Link to log-in help page depends on user's browser language preferences.
  
  
-------------- next part --------------
Index: loncom/auth/lonauth.pm
diff -u loncom/auth/lonauth.pm:1.121 loncom/auth/lonauth.pm:1.122
--- loncom/auth/lonauth.pm:1.121	Wed Apr 11 11:40:07 2012
+++ loncom/auth/lonauth.pm	Mon Aug 27 00:52:45 2012
@@ -1,7 +1,7 @@
 # The LearningOnline Network
 # User Authentication Module
 #
-# $Id: lonauth.pm,v 1.121 2012/04/11 11:40:07 goltermann Exp $
+# $Id: lonauth.pm,v 1.122 2012/08/27 00:52:45 raeburn Exp $
 #
 # Copyright Michigan State University Board of Trustees
 #
@@ -139,15 +139,19 @@
     my %lt=&Apache::lonlocal::texthash(
 				       'wel' => 'Welcome',
 				       'pro' => 'Login problems?',
-				       'log' => 'loginproblems.html',
 				       );
+    my $loginhelp = &loginhelpdisplay($domain);
+    if ($loginhelp) {
+        $loginhelp = '<p><a href="'.$loginhelp.'">'.$lt{'pro'}.'</a></p>';
+    }
+
     my $welcome = &mt('Welcome to the Learning[_1]Online[_2] Network with CAPA. Please wait while your session is being set up.','<i>','</i>'); 
     $r->print(<<ENDSUCCESS);
 $start_page
 $windowinfo
 <h1>$lt{'wel'}</h1>
-$welcome<p>
-<a href="/adm/$lt{'log'}">$lt{'pro'}</a></p>
+$welcome
+$loginhelp
 $continuelink
 $end_page
 ENDSUCCESS
@@ -543,6 +547,33 @@
     return $result;
 }
 
+sub loginhelpdisplay {
+    my ($authdomain) = @_;
+    my $login_help = 1;
+    my $lang = &Apache::lonlocal::current_language();
+    if ($login_help) {
+        my $dom = $authdomain;
+        if ($dom eq '') {
+            $dom = &Apache::lonnet::default_login_domain();
+        }
+        my %domconfhash = &Apache::loncommon::get_domainconf($dom);
+        my $loginhelp_url;
+        if ($lang) {
+            $loginhelp_url = $domconfhash{$dom.'.login.helpurl_'.$lang};
+            if ($loginhelp_url ne '') {
+                return $loginhelp_url;
+            }
+        }
+        $loginhelp_url = $domconfhash{$dom.'.login.helpurl_nolang'};
+        if ($loginhelp_url ne '') {
+            return $loginhelp_url;
+        } else {
+            return '/adm/loginproblems.html';
+        }
+    }
+    return;
+}
+
 1;
 __END__
 
Index: loncom/auth/lonlogin.pm
diff -u loncom/auth/lonlogin.pm:1.151 loncom/auth/lonlogin.pm:1.152
--- loncom/auth/lonlogin.pm:1.151	Wed Apr 18 18:57:34 2012
+++ loncom/auth/lonlogin.pm	Mon Aug 27 00:52:45 2012
@@ -1,7 +1,7 @@
 # The LearningOnline Network
 # Login Screen
 #
-# $Id: lonlogin.pm,v 1.151 2012/04/18 18:57:34 raeburn Exp $
+# $Id: lonlogin.pm,v 1.152 2012/08/27 00:52:45 raeburn Exp $
 #
 # Copyright Michigan State University Board of Trustees
 #
@@ -374,8 +374,10 @@
 
     my $forgotpw = &forgotpwdisplay(%lt);
     $forgotpw .= '<br />' if $forgotpw;
-    my $loginhelp = &loginhelpdisplay($authdomain,%lt);
-    $loginhelp .= '<br />' if $loginhelp;
+    my $loginhelp = &Apache::lonauth::loginhelpdisplay($authdomain);
+    if ($loginhelp) {
+        $loginhelp = '<a href="'.$loginhelp.'">'.$lt{'help'}.'</a><br />';
+    }
 
 # ---------------------------------------------------- Serve out DES JavaScript
     {
@@ -657,25 +659,6 @@
     return;
 }
 
-sub loginhelpdisplay {
-    my ($authdomain,%lt) = @_;
-    my $login_help = 1;
-    if ($login_help) {
-        my $dom = $authdomain;
-        if ($dom eq '') {
-            $dom = &Apache::lonnet::default_login_domain();
-        }
-        my %helpconfig = &Apache::lonnet::get_dom('configuration',['helpsettings'],$dom);
-        my $loginhelp_url = $helpconfig{'helpsettings'}{'loginhelpurl'};
-        if ($loginhelp_url ne '') {
-            return '<a href="'.$loginhelp_url.'">'.$lt{'help'}.'</a>';
-        } else {
-            return '<a href="/adm/loginproblems.html">'.$lt{'help'}.'</a>';
-        }
-    }
-    return;
-}
-
 sub coursecatalog_link {
     my ($linkname) = @_;
     return <<"END";
Index: loncom/interface/domainprefs.pm
diff -u loncom/interface/domainprefs.pm:1.167 loncom/interface/domainprefs.pm:1.168
--- loncom/interface/domainprefs.pm:1.167	Sat Aug 25 22:55:00 2012
+++ loncom/interface/domainprefs.pm	Mon Aug 27 00:53:22 2012
@@ -1,7 +1,7 @@
 # The LearningOnline Network with CAPA
 # Handler to set domain-wide configuration settings
 #
-# $Id: domainprefs.pm,v 1.167 2012/08/25 22:55:00 raeburn Exp $
+# $Id: domainprefs.pm,v 1.168 2012/08/27 00:53:22 raeburn Exp $
 #
 # Copyright Michigan State University Board of Trustees
 #
@@ -238,10 +238,11 @@
         'login' =>
                     { text => 'Log-in page options',
                       help => 'Domain_Configuration_Login_Page',
-                      header => [{col1 => 'Item',
-                                  col2 => '',}],
+                      header => [{col1 => 'Log-in Page Items',
+                                  col2 => '',},
+                                 {col1 => 'Log-in Help',
+                                  col2 => 'Value'}],
                     },
-
         'defaults' => 
                     { text => 'Default authentication/language/timezone/portal',
                       help => 'Domain_Configuration_LangTZAuth',
@@ -354,8 +355,6 @@
                  {text   => 'Help page settings',
                   help   => 'Domain_Configuration_Help_Settings',
                   header => [{col1 => 'Help Settings (logged-in users)',
-                              col2 => 'Value'},
-                             {col1 => 'Help Settings (before log-in)',
                               col2 => 'Value'}],
                  },
         'coursedefaults' => 
@@ -398,7 +397,9 @@
                             header => [{col1 => 'Log-in Service',
                                         col2 => 'Server Setting',},
                                        {col1 => 'Log-in Page Items',
-                                        col2 => ''}],
+                                        col2 => ''},
+                                       {col1 => 'Log-in Help',
+                                        col2 => 'Value'}],
                            };
     }
     my @roles = ('student','coordinator','author','admin');
@@ -533,7 +534,8 @@
     if ($numheaders > 1) {
         my $colspan = '';
         my $rightcolspan = '';
-        if (($action eq 'rolecolors') || ($action eq 'coursecategories')) {
+        if (($action eq 'rolecolors') || ($action eq 'coursecategories') || 
+            (($action eq 'login') && ($numheaders < 3))) {
             $colspan = ' colspan="2"';
         }
         if ($action eq 'usersessions') {
@@ -557,14 +559,16 @@
         } elsif ($action eq 'coursecategories') {
             $output .= &print_coursecategories('top',$dom,$item,$settings,\$rowtotal);
         } elsif ($action eq 'login') {
-            $output .= &print_login('top',$dom,$confname,$phase,$settings,\$rowtotal);
-            $colspan = ' colspan="2"';
+            if ($numheaders == 3) {
+                $colspan = ' colspan="2"';
+                $output .= &print_login('service',$dom,$confname,$phase,$settings,\$rowtotal);
+            } else {
+                $output .= &print_login('page',$dom,$confname,$phase,$settings,\$rowtotal);
+            }
         } elsif ($action eq 'requestcourses') {
             $output .= &print_quotas($dom,$settings,\$rowtotal,$action);
         } elsif ($action eq 'requestauthor') {
             $output .= &print_quotas($dom,$settings,\$rowtotal,$action);
-        } elsif ($action eq 'helpsettings') {
-            $output .= &print_helpsettings('top',$dom,$confname,$settings,\$rowtotal);
         } elsif ($action eq 'usersessions') {
             $output .= &print_usersessions('top',$dom,$settings,\$rowtotal); 
         } elsif ($action eq 'rolecolors') {
@@ -627,13 +631,26 @@
         } elsif ($action eq 'coursecategories') {
             $output .= &print_coursecategories('bottom',$dom,$item,$settings,\$rowtotal);
         } elsif ($action eq 'login') {
-            $output .= &print_login('bottom',$dom,$confname,$phase,$settings,\$rowtotal);
+            if ($numheaders == 3) {
+                $output .= &print_login('page',$dom,$confname,$phase,$settings,\$rowtotal).'
+           </table>
+          </td>
+         </tr>
+         <tr>
+           <td>
+            <table class="LC_nested">
+             <tr class="LC_info_row">
+              <td class="LC_left_item"'.$colspan.'>'.&mt($item->{'header'}->[2]->{'col1'}).'</td>
+              <td class="LC_right_item"'.$colspan.'>'.&mt($item->{'header'}->[2]->{'col2'}).'</td>      </tr>'.
+                       &print_login('help',$dom,$confname,$phase,$settings,\$rowtotal);
+                $rowtotal ++;
+            } else {
+                $output .= &print_login('help',$dom,$confname,$phase,$settings,\$rowtotal);
+            }
         } elsif ($action eq 'requestcourses') {
             $output .= &print_requestmail($dom,$action,$settings,\$rowtotal);
         } elsif ($action eq 'requestauthor') {
             $output .= &print_requestmail($dom,$action,$settings,\$rowtotal);
-        } elsif ($action eq 'helpsettings') {
-            $output .= &print_helpsettings('bottom',$dom,$confname,$settings,\$rowtotal);
         } elsif ($action eq 'usersessions') {
             $output .= &print_usersessions('middle',$dom,$settings,\$rowtotal).'
            </table>
@@ -725,10 +742,7 @@
         }
         $output .= '</tr>';
         $rowtotal ++;
-        if ($action eq 'login') {
-            $output .= &print_login('bottom',$dom,$confname,$phase,$settings,
-                                    \$rowtotal);
-        } elsif ($action eq 'quotas') {
+        if ($action eq 'quotas') {
             $output .= &print_quotas($dom,$settings,\$rowtotal,$action);
         } elsif ($action eq 'autoenroll') {
             $output .= &print_autoenroll($dom,$settings,\$rowtotal);
@@ -745,7 +759,7 @@
         } elsif ($action eq 'serverstatuses') {
             $output .= &print_serverstatuses($dom,$settings,\$rowtotal);
         } elsif ($action eq 'helpsettings') {
-            $output .= &print_helpsettings('top',$dom,$confname,$settings,\$rowtotal);
+            $output .= &print_helpsettings($dom,$confname,$settings,\$rowtotal);
         } elsif ($action eq 'loadbalancing') {
             $output .= &print_loadbalancing($dom,$settings,\$rowtotal);
         }
@@ -759,11 +773,11 @@
 }
 
 sub print_login {
-    my ($position,$dom,$confname,$phase,$settings,$rowtotal) = @_;
+    my ($caller,$dom,$confname,$phase,$settings,$rowtotal) = @_;
     my ($css_class,$datatable);
     my %choices = &login_choices();
 
-    if ($position eq 'top') {
+    if ($caller eq 'service') {
         my %servers = &Apache::lonnet::internet_dom_servers($dom);
         my $choice = $choices{'disallowlogin'};
         $css_class = ' class="LC_odd_row"';
@@ -830,131 +844,218 @@
         }
         $datatable .= '</table></td></tr>';
         return $datatable;
-    }
-
-    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 @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);
-    my %defaultdesign = %Apache::loncommon::defaultdesign;
-    my (%is_custom,%designs);
-    my %defaults = (
-                   font => $defaultdesign{'login.font'},
-                   );
-    foreach my $item (@images) {
-        $defaults{$item} = $defaultdesign{'login.'.$item};
-        $defaults{'showlogo'}{$item} = 1;
-    }
-    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') {
+    } elsif ($caller eq 'page') {
+        my %defaultchecked = ( 
+                               'coursecatalog' => 'on',
+                               'adminmail'     => 'off',
+                               'newuser'       => 'off',
+                             );
+        my @toggles = ('coursecatalog','adminmail','newuser');
+        my (%checkedon,%checkedoff);
         foreach my $item (@toggles) {
-            if ($settings->{$item} eq '1') {
-                $checkedon{$item} =  ' checked="checked" ';
+            if ($defaultchecked{$item} eq 'on') { 
+                $checkedon{$item} = ' checked="checked" ';
                 $checkedoff{$item} = ' ';
-            } elsif ($settings->{$item} eq '0') {
-                $checkedoff{$item} =  ' checked="checked" ';
+            } elsif ($defaultchecked{$item} eq 'off') {
+                $checkedoff{$item} = ' checked="checked" ';
                 $checkedon{$item} = ' ';
             }
         }
+        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);
+        my %defaultdesign = %Apache::loncommon::defaultdesign;
+        my (%is_custom,%designs);
+        my %defaults = (
+                       font => $defaultdesign{'login.font'},
+                       );
         foreach my $item (@images) {
-            if (defined($settings->{$item})) {
-                $designs{$item} = $settings->{$item};
-                $is_custom{$item} = 1;
-            }
-            if (defined($settings->{'showlogo'}{$item})) {
-                $designs{'showlogo'}{$item} = $settings->{'showlogo'}{$item};
-            }
+            $defaults{$item} = $defaultdesign{'login.'.$item};
+            $defaults{'showlogo'}{$item} = 1;
+        }
+        foreach my $item (@bgs) {
+            $defaults{'bgs'}{$item} = $defaultdesign{'login.'.$item};
         }
         foreach my $item (@logintext) {
-            if ($settings->{$item} ne '') {
-                $designs{'logintext'}{$item} = $settings->{$item};
-                $is_custom{$item} = 1;
-            }
+            $defaults{'logintext'}{$item} = $defaultdesign{'login.'.$item};
         }
-        if ($settings->{'font'} ne '') {
-            $designs{'font'} = $settings->{'font'};
-            $is_custom{'font'} = 1;
+        foreach my $item (@links) {
+            $defaults{'links'}{$item} = $defaultdesign{'login.'.$item};
         }
-        foreach my $item (@bgs) {
-            if ($settings->{$item} ne '') {
-                $designs{'bgs'}{$item} = $settings->{$item};
-                $is_custom{$item} = 1;
+        if (ref($settings) eq 'HASH') {
+            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 (@links) {
-            if ($settings->{$item} ne '') {
-                $designs{'links'}{$item} = $settings->{$item};
-                $is_custom{$item} = 1;
+            foreach my $item (@images) {
+                if (defined($settings->{$item})) {
+                    $designs{$item} = $settings->{$item};
+                    $is_custom{$item} = 1;
+                }
+                if (defined($settings->{'showlogo'}{$item})) {
+                    $designs{'showlogo'}{$item} = $settings->{'showlogo'}{$item};
+                }
+            }
+            foreach my $item (@logintext) {
+                if ($settings->{$item} ne '') {
+                    $designs{'logintext'}{$item} = $settings->{$item};
+                    $is_custom{$item} = 1;
+                }
+            }
+            if ($settings->{'font'} ne '') {
+                $designs{'font'} = $settings->{'font'};
+                $is_custom{'font'} = 1;
+            }
+            foreach my $item (@bgs) {
+                if ($settings->{$item} ne '') {
+                    $designs{'bgs'}{$item} = $settings->{$item};
+                    $is_custom{$item} = 1;
+                }
+            }
+            foreach my $item (@links) {
+                if ($settings->{$item} ne '') {
+                    $designs{'links'}{$item} = $settings->{$item};
+                    $is_custom{$item} = 1;
+                }
+            }
+        } else {
+            if ($designhash{$dom.'.login.font'} ne '') {
+                $designs{'font'} = $designhash{$dom.'.login.font'};
+                $is_custom{'font'} = 1;
+            }
+            foreach my $item (@images) {
+                if ($designhash{$dom.'.login.'.$item} ne '') {
+                    $designs{$item} = $designhash{$dom.'.login.'.$item};
+                    $is_custom{$item} = 1;
+                }
+            }
+            foreach my $item (@bgs) {
+                if ($designhash{$dom.'.login.'.$item} ne '') {
+                    $designs{'bgs'}{$item} = $designhash{$dom.'.login.'.$item};
+                    $is_custom{$item} = 1;
+                }
+            }
+            foreach my $item (@links) {
+                if ($designhash{$dom.'.login.'.$item} ne '') {
+                    $designs{'links'}{$item} = $designhash{$dom.'.login.'.$item};
+                    $is_custom{$item} = 1;
+                }
             }
         }
-    } else {
-        if ($designhash{$dom.'.login.font'} ne '') {
-            $designs{'font'} = $designhash{$dom.'.login.font'};
-            $is_custom{'font'} = 1;
+        my %alt_text = &Apache::lonlocal::texthash  ( img => 'Log-in banner',
+                                                      logo => 'Institution Logo',
+                                                      domlogo => 'Domain Logo',
+                                                      login => 'Login box');
+        my $itemcount = 1;
+        foreach my $item (@toggles) {
+            $css_class = $itemcount%2?' class="LC_odd_row"':'';
+            $datatable .=  
+                '<tr'.$css_class.'><td colspan="2">'.$choices{$item}.
+                '</td><td>'.
+                '<span class="LC_nobreak"><label><input type="radio" name="'.
+                $item.'"'.$checkedon{$item}.' value="1" />'.&mt('Yes').
+                '</label> <label><input type="radio" name="'.$item.'"'.
+                $checkedoff{$item}.' value="0" />'.&mt('No').'</label></span></td>'.
+                '</tr>';
+            $itemcount ++;
         }
-        foreach my $item (@images) {
-            if ($designhash{$dom.'.login.'.$item} ne '') {
-                $designs{$item} = $designhash{$dom.'.login.'.$item};
-                $is_custom{$item} = 1;
+        $datatable .= &display_color_options($dom,$confname,$phase,'login',$itemcount,\%choices,\%is_custom,\%defaults,\%designs,\@images,\@bgs,\@links,\%alt_text,$rowtotal,\@logintext);
+        $datatable .= '</tr></table></td></tr>';
+    } elsif ($caller eq 'help') {
+        my ($defaulturl,$defaulttype,%url,%type,%lt,%langchoices);
+        my $switchserver = &check_switchserver($dom,$confname);
+        my $itemcount = 1;
+        $defaulturl = '/adm/loginproblems.html';
+        $defaulttype = 'default';
+        %lt = &Apache::lonlocal::texthash (
+                     del     => 'Delete?',
+                     rep     => 'Replace:',
+                     upl     => 'Upload:',
+                     default => 'Default',
+                     custom  => 'Custom',
+                                             );
+        %langchoices = &Apache::lonlocal::texthash(&get_languages_hash());
+        my @currlangs;
+        if (ref($settings) eq 'HASH') {
+            if (ref($settings->{'helpurl'}) eq 'HASH') {
+                foreach my $key (sort(keys(%{$settings->{'helpurl'}}))) {
+                    next if ($settings->{'helpurl'}{$key} eq '');
+                    $url{$key} = $settings->{'helpurl'}{$key}.'?inhibitmenu=yes';
+                    $type{$key} = 'custom';
+                    unless ($key eq 'nolang') {
+                        push(@currlangs,$key);
+                    }
+                }
+            } elsif ($settings->{'helpurl'} ne '') {
+                $type{'nolang'} = 'custom';
+                $url{'nolang'} = $settings->{'helpurl'}.'?inhibitmenu=yes';
             }
         }
-        foreach my $item (@bgs) {
-            if ($designhash{$dom.'.login.'.$item} ne '') {
-                $designs{'bgs'}{$item} = $designhash{$dom.'.login.'.$item};
-                $is_custom{$item} = 1;
+        foreach my $lang ('nolang',sort(@currlangs)) {
+            $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
+            $datatable .= '<tr'.$css_class.'>';
+            if ($url{$lang} eq '') {
+                $url{$lang} = $defaulturl;
+            }
+            if ($type{$lang} eq '') {
+                $type{$lang} = $defaulttype;
+            }
+            $datatable .= '<td colspan="2"><span class="LC_nobreak">';
+            if ($lang eq 'nolang') {
+                $datatable .= &mt('Log-in help page if no specific language file: [_1]',
+                                  &Apache::loncommon::modal_link($url{$lang},$lt{$type{$lang}},600,500));
+            } else {
+                $datatable .= &mt('Log-in help page for language: [_1] is [_2]',
+                                  $langchoices{$lang},
+                                  &Apache::loncommon::modal_link($url{$lang},$lt{$type{$lang}},600,500));
+            }
+            $datatable .= '</span></td>'."\n".
+                          '<td class="LC_left_item">';
+            if ($type{$lang} eq 'custom') {
+                $datatable .= '<span class="LC_nobreak"><label>'.
+                              '<input type="checkbox" name="loginhelpurl_del" value="'.$lang.'" />'.
+                              $lt{'del'}.'</label> '.$lt{'rep'}.'</span>';
+            } else {
+                $datatable .= $lt{'upl'};
             }
+            $datatable .='<br />';
+            if ($switchserver) {
+                $datatable .= &mt('Upload to library server: [_1]',$switchserver);
+            } else {
+                $datatable .= '<input type="file" name="loginhelpurl_'.$lang.'" />';
+            }
+            $datatable .= '</td></tr>';
+            $itemcount ++;
         }
-        foreach my $item (@links) {
-            if ($designhash{$dom.'.login.'.$item} ne '') {
-                $designs{'links'}{$item} = $designhash{$dom.'.login.'.$item};
-                $is_custom{$item} = 1;
+        my @addlangs;
+        foreach my $lang (sort(keys(%langchoices))) {
+            next if ((grep(/^\Q$lang\E$/, at currlangs)) || ($lang eq 'x_chef'));
+            push(@addlangs,$lang);
+        }
+        if (@addlangs > 0) {
+            my %toadd;
+            map { $toadd{$_} = $langchoices{$_} ; } @addlangs;
+            $toadd{''} = &mt('Select');
+            $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
+            $datatable .= '<tr'.$css_class.'><td class="LC_left_item" colspan="2">'.
+                          &mt('Add log-in help page for a specific language:').' '.
+                          &Apache::loncommon::select_form('','loginhelpurl_add_lang',\%toadd).
+                          '</td><td class="LC_left_item">'.$lt{'upl'}.'<br />';
+            if ($switchserver) {
+                $datatable .= &mt('Upload to library server: [_1]',$switchserver);
+            } else {
+                $datatable .= '<input type="file" name="loginhelpurl_add_file" />';
             }
+            $datatable .= '</td></tr>';
         }
     }
-    my %alt_text = &Apache::lonlocal::texthash  ( img => 'Log-in banner',
-                                                  logo => 'Institution Logo',
-                                                  domlogo => 'Domain Logo',
-                                                  login => 'Login box');
-    my $itemcount = 1;
-    foreach my $item (@toggles) {
-        $css_class = $itemcount%2?' class="LC_odd_row"':'';
-        $datatable .=  
-            '<tr'.$css_class.'><td colspan="2">'.$choices{$item}.
-            '</td><td>'.
-            '<span class="LC_nobreak"><label><input type="radio" name="'.
-            $item.'"'.$checkedon{$item}.' value="1" />'.&mt('Yes').
-            '</label> <label><input type="radio" name="'.$item.'"'.
-            $checkedoff{$item}.' value="0" />'.&mt('No').'</label></span></td>'.
-            '</tr>';
-        $itemcount ++;
-    }
-    $datatable .= &display_color_options($dom,$confname,$phase,'login',$itemcount,\%choices,\%is_custom,\%defaults,\%designs,\@images,\@bgs,\@links,\%alt_text,$rowtotal,\@logintext);
-    $datatable .= '</tr></table></td></tr>';
     return $datatable;
 }
 
@@ -2263,61 +2364,18 @@
 }
 
 sub print_helpsettings {
-    my ($position,$dom,$confname,$settings,$rowtotal) = @_;
-    my ($css_class,$datatable,$itemcount);
-    my $switchserver = &check_switchserver($dom,$confname);
+    my ($dom,$confname,$settings,$rowtotal) = @_;
+    my ($datatable,$itemcount);
     $itemcount = 1;
-    if ($position eq 'top') {
-        my (%checkedon,%checkedoff,%choices,%defaultchecked, at toggles,$align);
-        $choices{'submitbugs'} = &mt('Display link to: [_1]?',
-                                     &Apache::loncommon::modal_link('http://bugs.loncapa.org',
-                                     &mt('LON-CAPA bug tracker'),600,500));
-        %defaultchecked = ('submitbugs' => 'on');
-        @toggles = ('submitbugs',);
-        $align = 'LC_left_item';
+    my (%choices,%defaultchecked, at toggles);
+    $choices{'submitbugs'} = &mt('Display link to: [_1]?',
+                                 &Apache::loncommon::modal_link('http://bugs.loncapa.org',
+                                 &mt('LON-CAPA bug tracker'),600,500));
+    %defaultchecked = ('submitbugs' => 'on');
+    @toggles = ('submitbugs',);
 
-        ($datatable,$itemcount) = &radiobutton_prefs($settings,\@toggles,\%defaultchecked,
-                                                     \%choices,$itemcount);
-    } else {
-        $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
-        $datatable .= '<tr'.$css_class.'>';
-        my $url = '/adm/loginproblems.html'; 
-        my $type = 'default';
-        my %lt = &Apache::lonlocal::texthash (
-                     del     => 'Delete?',
-                     rep     => 'Replace:',
-                     upl     => 'Upload:',
-                     default => 'Default',
-                     custom  => 'Custom', 
-                                             ); 
-        if (ref($settings) eq 'HASH') {
-            if (ref($settings->{'loginhelpurl'}) eq 'HASH') {
-
-            } elsif ($settings->{'loginhelpurl'} ne '') {
-                $type = 'custom';
-                $url = $settings->{'loginhelpurl'}.'?inhibitmenu=yes';
-            }
-        }
-        $datatable .= '<td class="LC_left_item"><span class="LC_nobreak">'.
-                      &mt('Log-in help page currently in use: [_1]',
-                          &Apache::loncommon::modal_link($url,$lt{$type},600,500)).
-                      '</span></td>'."\n".
-                      '<td class="LC_left_item">';
-        if ($type eq 'custom') {
-            $datatable .= '<span class="LC_nobreak"><label>'.
-                          '<input type="checkbox" name="loginhelpurl_del" value="1" />'.$lt{'del'}. 
-                          '</label> '.$lt{'rep'}.'</span>';
-        } else {
-            $datatable .= $lt{'upl'};
-        }
-        $datatable .='<br />';
-        if ($switchserver) {
-            $datatable .= &mt('Upload to library server: [_1]',$switchserver);
-        } else {
-            $datatable .= '<input type="file" name="loginhelpurl" />';
-        } 
-        $datatable .= '</td></tr>';
-    }
+    ($datatable,$itemcount) = &radiobutton_prefs($settings,\@toggles,\%defaultchecked,
+                                                 \%choices,$itemcount);
     return $datatable;
 }
 
@@ -3527,13 +3585,8 @@
             my $includeempty = 1;
             $datatable .= &Apache::loncommon::select_datelocale($item,$domdefaults{$item},undef,$includeempty);
         } elsif ($item eq 'lang_def') {
-            my %langchoices=('' => 'No language preference');
-            foreach my $id (&Apache::loncommon::languageids()) {
-                my $code = &Apache::loncommon::supportedlanguagecode($id);
-                if ($code ne '') {
-                   $langchoices{$code} =  &Apache::loncommon::plainlanguagedescription($id);
-                }
-            }
+            my %langchoices = &get_languages_hash();
+            $langchoices{''} = 'No language preference';
             %langchoices = &Apache::lonlocal::texthash(%langchoices);
             $datatable .= &Apache::loncommon::select_form($domdefaults{$item},$item,
                                                           \%langchoices);
@@ -3552,6 +3605,17 @@
     return $datatable;
 }
 
+sub get_languages_hash {
+    my %langchoices;
+    foreach my $id (&Apache::loncommon::languageids()) {
+        my $code = &Apache::loncommon::supportedlanguagecode($id);
+        if ($code ne '') {
+            $langchoices{$code} =  &Apache::loncommon::plainlanguagedescription($id);
+        }
+    }
+    return %langchoices;
+}
+
 sub defaults_titles {
     my ($dom) = @_;
     my %titles = &Apache::lonlocal::texthash (
@@ -4463,13 +4527,13 @@
 
 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',
-                  newuser => 'Link for visitors to create a user account',
-                  loginheader => 'Log-in box header');
-    my @offon = ('off','on');
-    my %curr_loginvia;
+    my ($resulttext,$errors,$colchgtext,%changes,%colchanges,%newfile,%newurl,
+        %curr_loginvia,%loginhash, at currlangs, at newlangs,$addedfile,%title, at offon);
+    %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');
+    @offon = ('off','on');
     if (ref($domconfig{login}) eq 'HASH') {
         if (ref($domconfig{login}{loginvia}) eq 'HASH') {
             foreach my $lonhost (keys(%{$domconfig{login}{loginvia}})) {
@@ -4477,7 +4541,6 @@
             }
         }
     }
-    my %loginhash;
     ($errors,%colchanges) = &modify_colors($r,$dom,$confname,['login'],
                                            \%domconfig,\%loginhash);
     my @toggles = ('coursecatalog','adminmail','newuser');
@@ -4576,6 +4639,95 @@
         }
     }
 
+    my $servadm = $r->dir_config('lonAdmEMail');
+    my %langchoices = &Apache::lonlocal::texthash(&get_languages_hash());
+    if (ref($domconfig{'login'}) eq 'HASH') {
+        if (ref($domconfig{'login'}{'helpurl'}) eq 'HASH') {
+            foreach my $lang (sort(keys(%{$domconfig{'login'}{'helpurl'}}))) {
+                if ($lang eq 'nolang') {
+                    push(@currlangs,$lang);
+                } elsif (defined($langchoices{$lang})) {
+                    push(@currlangs,$lang);
+                } else {
+                    next;
+                }
+            }
+        }
+    }
+    my @delurls = &Apache::loncommon::get_env_multiple('form.loginhelpurl_del');
+    if (@currlangs > 0) {
+        foreach my $lang (@currlangs) {
+            if (grep(/^\Q$lang\E$/, at delurls)) {
+                $changes{'helpurl'}{$lang} = 1;
+            } elsif ($env{'form.loginhelpurl_'.$lang.'.filename'}) {
+                $changes{'helpurl'}{$lang} = 1;
+                $newfile{$lang} = $env{'form.loginhelpurl_'.$lang.'.filename'};
+                push(@newlangs,$lang);
+            } else {
+                $loginhash{'login'}{'helpurl'}{$lang} = $domconfig{'login'}{'helpurl'}{$lang};
+            }
+        }
+    }
+    unless (grep(/^nolang$/, at currlangs)) {
+        if ($env{'form.loginhelpurl_nolang.filename'}) {
+            $changes{'helpurl'}{'nolang'} = 1;
+            $newfile{'nolang'} = $env{'form.loginhelpurl_nolang.filename'};
+            push(@newlangs,'nolang');
+        }
+    }
+    if ($env{'form.loginhelpurl_add_lang'}) {
+        if ((defined($langchoices{$env{'form.loginhelpurl_add_lang'}})) &&
+            ($env{'form.loginhelpurl_add_file.filename'})) {
+            $newfile{$env{'form.loginhelpurl_add_lang'}} = $env{'form.loginhelpurl_add_file.filename'};
+            $addedfile = $env{'form.loginhelpurl_add_lang'};
+        }
+    }
+    if ((@newlangs > 0) || ($addedfile)) {
+        my $error;
+        my ($configuserok,$author_ok,$switchserver) = &config_check($dom,$confname,$servadm);
+        if ($configuserok eq 'ok') {
+            if ($switchserver) {
+                $error = &mt("Upload of custom help file is not permitted to this server: [_1]",$switchserver);
+            } elsif ($author_ok eq 'ok') {
+                my @allnew = @newlangs;
+                if ($addedfile ne '') {
+                    push(@allnew,$addedfile);
+                }
+                foreach my $lang (@allnew) {
+                    my $formelem = 'loginhelpurl_'.$lang;
+                    if ($lang eq $env{'form.loginhelpurl_add_lang'}) {
+                        $formelem = 'loginhelpurl_add_file';
+                    }
+                    (my $result,$newurl{$lang}) = &publishlogo($r,'upload',$formelem,$dom,$confname,
+                                                               "help/$lang",'','',$newfile{$lang});
+                    if ($result eq 'ok') {
+                        $loginhash{'login'}{'helpurl'}{$lang} = $newurl{$lang};
+                        $changes{'helpurl'}{$lang} = 1;
+                    } else {
+                        my $puberror = &mt("Upload of [_1] failed because an error occurred publishing the file in RES space. Error was: [_2].",$newfile{$lang},$result);
+                        $errors .= '<li><span class="LC_error">'.$puberror.'</span></li>';
+                        if ((grep(/^\Q$lang\E$/, at currlangs)) && 
+                            (!grep(/^\Q$lang\E$/, at delurls))) {
+
+                            $loginhash{'login'}{'helpurl'}{$lang} = $domconfig{'login'}{'helpurl'}{$lang};
+                        }
+                    }
+                }
+            } else {
+                $error = &mt("Upload of custom log-in help file(s) failed because an author role could not be assigned to a Domain Configuration user ([_1]) in domain: [_2].  Error was: [_3].",$confname,$dom,$author_ok);
+            }
+        } else {
+            $error = &mt("Upload of custom log-in help file(s) failed because a Domain Configuration user ([_1]) could not be created in domain: [_2].  Error was: [_3].",$confname,$dom,$configuserok);
+        }
+        if ($error) {
+            &Apache::lonnet::logthis($error);
+            $errors .= '<li><span class="LC_error">'.$error.'</span></li>';
+        }
+    }
+
+    my $defaulthelpfile = '/adm/loginproblems.html';
+    my $defaulttext = &mt('Default in use');
+
     my $putresult = &Apache::lonnet::put_dom('configuration',\%loginhash,
                                              $dom);
     if ($putresult eq 'ok') {
@@ -4641,6 +4793,32 @@
                         }
                         $resulttext .= '</ul></li>';
                     }
+                } elsif ($item eq 'helpurl') {
+                    if (ref($changes{$item}) eq 'HASH') {
+                        foreach my $lang (sort(keys(%{$changes{$item}}))) {
+                            if (grep(/^\Q$lang\E$/, at delurls)) {
+                                my ($chg,$link);
+                                $link = &Apache::loncommon::modal_link($defaulthelpfile,$defaulttext,600,500);
+                                if ($lang eq 'nolang') {
+                                    $chg = &mt('custom log-in help file removed for no preferred language; [_1]',$link);
+                                } else {
+                                    $chg = &mt('custom log-in help file removed for specific language: [_1]; [_2]',$langchoices{$lang},$link);
+                                }
+                                $resulttext .= '<li>'.$chg.'</li>';
+                            } else {
+                                my $chg;
+                                if ($lang eq 'nolang') {
+                                    $chg = &mt('custom log-in help file for no preferred language');
+                                } else {
+                                    $chg = &mt('custom log-in help file for specific language: [_1]',$langchoices{$lang});
+                                }
+                                $resulttext .= '<li>'.&Apache::loncommon::modal_link(
+                                                      $loginhash{'login'}{'helpurl'}{$lang}.
+                                                      '?inhibitmenu=yes',$chg,600,500).
+                                               '</li>';
+                            }
+                        }
+                    }
                 } else {
                     $resulttext .= '<li>'.&mt("$title{$item} set to $offon[$env{'form.'.$item}]").'</li>';
                 }
@@ -7419,24 +7597,9 @@
 sub modify_helpsettings {
     my ($r,$dom,$confname,%domconfig) = @_;
     my ($resulttext,$errors,%changes,%helphash);
-    my $customhelpfile = $env{'form.loginhelpurl.filename'};
-    my $defaulthelpfile = '/adm/loginproblems.html';
-    my $defaulttext = &mt('Default in use');
-    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') { 
@@ -7460,48 +7623,11 @@
                 $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 .= '<li><span class="LC_error">'.$error.'</span></li>';
-            }
-        }
-        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) {
+        if ($putresult eq 'ok') {
             $resulttext = &mt('Changes made:').'<ul>';
             foreach my $item (sort(keys(%changes))) {
                 if ($item eq 'submitbugs') {
@@ -7509,30 +7635,17 @@
                                               &Apache::loncommon::modal_link('http://bugs.loncapa.org',
                                               &mt('LON-CAPA bug tracker'),600,500)).'</li>';
                 }
-                if ($item eq 'loginhelpurl') {
-                    if ($helphash{'helpsettings'}{'loginhelpurl'} eq '') {
-                        $resulttext .= '<li>'.&mt('custom log-in help file removed.').' '.
-                                              &Apache::loncommon::modal_link($defaulthelpfile,
-                                              $defaulttext,600,500).'</li>';
-                    } else {
-                        $resulttext .= '<li>'.&Apache::loncommon::modal_link(
-                                                  $helphash{'helpsettings'}{'loginhelpurl'}.
-                                                  '?inhibitmenu=yes',
-                                                  &mt('custom log-in help file'),600,500).
-                                       '</li>';
-                    }
-                }
             }
             $resulttext .= '</ul>';
         } else {
             $resulttext = &mt('No changes made to help settings');
+            $errors .= '<li><span class="LC_error">'.
+                       &mt('An error occurred storing the settings: [_1]',
+                           $putresult).'</span></li>';
         }
-    } else {
-        $errors .= '<li><span class="LC_error">'.&mt('An error occurred storing the settings: [_1]',
-                                                     $putresult).'</span></li>';
     }
     if ($errors) {
-        $resulttext .= &mt('The following errors occurred: ').'<ul>'.
+        $resulttext .= '<br />'.&mt('The following errors occurred: ').'<ul>'.
                        $errors.'</ul>';
     }
     return $resulttext;
@@ -8115,7 +8228,7 @@
                 delete($coursecategories->{$subitem});
                 $deletions->{$subitem} = 1;
                 &recurse_cat_deletes($subitem,$coursecategories,$deletions);
-            }  
+            }
         }
     }
     return;


More information about the LON-CAPA-cvs mailing list