--- loncom/interface/lonpreferences.pm	2009/05/06 16:19:34	1.159
+++ loncom/interface/lonpreferences.pm	2009/10/08 19:54:37	1.173
@@ -1,7 +1,7 @@
 # The LearningOnline Network
 # Preferences
 #
-# $Id: lonpreferences.pm,v 1.159 2009/05/06 16:19:34 bisitz Exp $
+# $Id: lonpreferences.pm,v 1.173 2009/10/08 19:54:37 raeburn Exp $
 #
 # Copyright Michigan State University Board of Trustees
 #
@@ -217,7 +217,8 @@ sub texenginechanger {
 		     'tth' => 'tth (TeX to HTML)',
 		     #'ttm' => 'TeX to MathML',
 		     'jsMath' => 'jsMath',
-		     'mimetex' => 'mimetex (Convert to Images)'
+		     'mimetex' => 'mimetex (Convert to Images)',
+                     'raw' => 'Raw (Screen Reader)'
                      );
     my $selectionbox=&Apache::loncommon::select_form($texengine,'texengine',
 						     %mathchoices);
@@ -232,6 +233,21 @@ sub texenginechanger {
       'mimetex'  => 'mimetex (Convert to Images):',
     );
 
+    my $jsMathWarning='<p>'
+                     .'<div class="LC_warning">'
+                     .&mt("It looks like you don't have the TeX math fonts installed.")
+                     .'</div>'
+                     .'<div>'
+                     .&mt('The jsMath example on this page may not look right without them. '
+                         .'The [_1]jsMath Home Page[_2] has information on how to download the '
+                         .'needed fonts. In the meantime, jsMath will do the best it can '
+                         .'with the fonts you have, but it may not be pretty and some equations '
+                         .'may not be rendered correctly.'
+                         ,'<a href="http://www.math.union.edu/locate/jsMath/" target="_blank">'
+                         ,'</a>')
+                     .'</div>'
+                     .'</p>';
+
     $r->print(<<ENDLSCREEN);
 <h2>$lt{'headline'}</h2>
 <form name="prefs" action="/adm/preferences" method="post">
@@ -251,18 +267,7 @@ $lt{'exmpl'}
 $jsMath_start
 <script type="text/javascript" language="JavaScript">
 if (jsMath.nofonts == 1) {
-    document.writeln
-        ('<div style="padding: 10; border-style: solid; border-width:3;'
-	 +' border-color: #DD0000; background-color: #FFF8F8; width: 75%; text-align: left">'
-	 +'<small><font color="#AA0000"><b>Warning:</b> '
-	 +'It looks like you don\\\'t have the TeX math fonts installed. '
-	 +'The jsMath example on this page may not look right without them. '
-	 +'The <a href="http://www.math.union.edu/locate/jsMath/" target="_blank"> '
-	 +'jsMath Home Page</a> has information on how to download the '
-	 +'needed fonts.  In the meantime, jsMath will do the best it can '
-	 +'with the fonts you have, but it may not be pretty and some equations '
-	 +'may not be rendered correctly. '
-	 +'</font></small></div>');
+    document.writeln($jsMathWarning);
 }
 </script>
 <iframe src="/res/adm/pages/math_example.tex?inhibitmenu=yes&texengine=jsMath" width="400" height="120"></iframe>
@@ -385,7 +390,7 @@ sub rolesprefchanger {
     $r->print('
 <p>'.&mt('Some LON-CAPA users have a long list of '.$lc_role.'s. The Recent '.$role.'s Hotlist feature keeps track of the last N '.$lc_role.'s which have been visited and places a table of these at the top of the '.$lc_role.'s page. People with very few '.$lc_role.'s should leave this feature disabled.').'
 </p>
-<form name="prefs" action="/adm/preferences" method="POST">
+<form name="prefs" action="/adm/preferences" method="post">
 <input type="hidden" name="action" value="verify_and_change_rolespref" />
 <br /><label>'.&mt('Enable Recent '.$role.'s Hotlist:').'
 <input type="checkbox"'.$checked.' name="recentroles" value="true" /></label>
@@ -544,7 +549,7 @@ sub verify_and_change_screenname {
     if ($newscreen) {
         &Apache::lonnet::put('environment',{'screenname' => $newscreen});
         &Apache::lonnet::appenv({'environment.screenname' => $newscreen});
-        $message=&Apache::lonhtmlcommon::confirm_success(&mt('Set [_1] to [_2]','<i>'.&mt('Screenname').'</i>','<tt>"'.$newscreen.'."</tt>'));
+        $message=&Apache::lonhtmlcommon::confirm_success(&mt('Set [_1] to [_2]','<i>'.&mt('Screenname').'</i>','<tt>"'.$newscreen.'"</tt>'));
     } else {
         &Apache::lonnet::del('environment',['screenname']);
         &Apache::lonnet::delenv('environment.screenname');
@@ -557,7 +562,7 @@ sub verify_and_change_screenname {
     if ($newscreen) {
         &Apache::lonnet::put('environment',{'nickname' => $newscreen});
         &Apache::lonnet::appenv({'environment.nickname' => $newscreen});
-        $message.=&Apache::lonhtmlcommon::confirm_success(&mt('Set [_1] to [_2]','<i>'.&mt('Nickname').'</i>','<tt>"'.$newscreen.'"</tt>.'));
+        $message.=&Apache::lonhtmlcommon::confirm_success(&mt('Set [_1] to [_2]','<i>'.&mt('Nickname').'</i>','<tt>"'.$newscreen.'"</tt>'));
     } else {
         &Apache::lonnet::del('environment',['nickname']);
         &Apache::lonnet::delenv('environment.nickname');
@@ -990,7 +995,7 @@ sub verify_and_change_msgforward {
 	    if (&Apache::lonnet::homeserver($msuser,$msdomain) ne 'no_host') {
                $newscreen.=$msuser.':'.$msdomain.',';
 	   } else {
-               $message.= &mt('No such user: ').'<tt>'.$msuser.':'.$msdomain.'</tt><br>';
+               $message.= &mt('No such user: ').'<tt>'.$msuser.':'.$msdomain.'</tt><br />';
            }
         }
     }
@@ -1333,6 +1338,8 @@ sub jscript_send {
                    this.document.client.elements.uname.value;
         this.document.pserver.elements.udom.value =
                    this.document.client.elements.udom.options[this.document.client.elements.udom.selectedIndex].value;
+        this.document.pserver.elements.email.value =
+                   this.document.client.elements.email.value;
 |;
     }
     $ output .= qq|
@@ -1351,42 +1358,42 @@ sub client_form {
                 'currentpass' => 'Current Password',
                 'newpass' => 'New Password',
                 'confirmpass' => 'Confirm Password',
-                'changepass' => 'Save');
+                'changepass' => 'Save',
+    );
 
-    my $output = qq|
-<form name="client" >
-<table>
-|;
+    my $output = '<form name="client">'
+                .&Apache::lonhtmlcommon::start_pick_box();
     if ($caller eq 'reset_by_email') {
-        $output .= qq|
-<tr><td class="LC_preferences_labeltext"><label for="email">$lt{'email'}</label>:</td>
-    <td><input type="text" name="email" size="30" /> </td></tr>
-<tr><td class="LC_preferences_labeltext"><label for="uname">$lt{'username'}</label>:</td>
-    <td>
-     <input type="text" name="uname" size="15" />
-     <input type="hidden" name="currentpass" value="$currentpass" />
-    </td></tr>
-<tr><td class="LC_preferences_labeltext"><label for="udom">$lt{'domain'}</label>:</td>
-    <td>
-|;
-        $output .= &Apache::loncommon::select_dom_form($defdom,'udom').'
-   </td>
-</tr>
-';
+        $output .= &Apache::lonhtmlcommon::row_title(
+                       '<label for="email">'.$lt{'email'}.'</label>')
+                  .'<input type="text" name="email" size="30" />'
+                  .&Apache::lonhtmlcommon::row_closure()
+                  .&Apache::lonhtmlcommon::row_title(
+                       '<label for="uname">'.$lt{'username'}.'</label>')
+                  .'<input type="text" name="uname" size="15" />'
+                  .'<input type="hidden" name="currentpass" value="'.$currentpass.'" />'
+                  .&Apache::lonhtmlcommon::row_closure()
+                  .&Apache::lonhtmlcommon::row_title(
+                       '<label for="udom">'.$lt{'domain'}.'</label>')
+                  .&Apache::loncommon::select_dom_form($defdom,'udom')
+                  .&Apache::lonhtmlcommon::row_closure();
     } else {
-        $output .= qq|
-<tr><td class="LC_preferences_labeltext"><label for="currentpass">$lt{'currentpass'}</label></td>
-    <td><input type="password" name="currentpass" size="10"/> </td></tr>
-|;
-    }
-    $output .= <<"ENDFORM";
-<tr><td class="LC_preferences_labeltext"><label for="newpass_1">$lt{'newpass'}</label></td>
-    <td><input type="password" name="newpass_1" size="10"  /> </td></tr>
-<tr><td class="LC_preferences_labeltext"><label for="newpass_2">$lt{'confirmpass'}</label></td>
-    <td><input type="password" name="newpass_2" size="10"  /> </td></tr>
-<tr><td colspan="2" align="center">
-    <input type="button" value="$lt{'changepass'}" onClick="send();" />
-</table>
+        $output .= &Apache::lonhtmlcommon::row_title(
+                       '<label for="currentpass">'.$lt{'currentpass'}.'</label>')
+                  .'<input type="password" name="currentpass" size="10"/>'
+                  .&Apache::lonhtmlcommon::row_closure();
+    }
+    $output .= &Apache::lonhtmlcommon::row_title(
+                   '<label for="newpass_1">'.$lt{'newpass'}.'</label>')
+              .'<input type="password" name="newpass_1" size="10" />'
+              .&Apache::lonhtmlcommon::row_closure()
+              .&Apache::lonhtmlcommon::row_title(
+                   '<label for="newpass_2">'.$lt{'confirmpass'}.'</label>')
+              .'<input type="password" name="newpass_2" size="10" />'
+              .&Apache::lonhtmlcommon::row_closure(1)
+              .&Apache::lonhtmlcommon::end_pick_box();
+    $output .= '<p><input type="button" value="'.$lt{'changepass'}.'" onClick="send();" /></p>'
+              .qq|
 <input type="hidden" name="ukey_cpass"  value="$hexkey->{'ukey_cpass'}" />
 <input type="hidden" name="lkey_cpass"  value="$hexkey->{'lkey_cpass'}" />
 <input type="hidden" name="ukey_npass1" value="$hexkey->{'ukey_npass1'}" />
@@ -1395,7 +1402,7 @@ sub client_form {
 <input type="hidden" name="lkey_npass2" value="$hexkey->{'lkey_npass2'}" />
 </form>
 </p>
-ENDFORM
+|;
     return $output;
 }
 
@@ -1417,6 +1424,7 @@ sub server_form {
 <input type="hidden" name="token"   value="$mailtoken" />
 <input type="hidden" name="uname"   value="" />
 <input type="hidden" name="udom"   value="" />
+<input type="hidden" name="email"   value="" />
 
 |;
     }
@@ -1561,7 +1569,7 @@ ENDERROR
     # Inform the user the password has (not?) been changed
     my $message;
     if ($result =~ /^ok$/) {
-        $message = &Apache::lonhtmlcommon::confirm_success(&mt('The password for user [_1] was successfully changed.','<i>'.$user.'<i>'));
+        $message = &Apache::lonhtmlcommon::confirm_success(&mt('The password for user [_1] was successfully changed.','<i>'.$user.'</i>'));
         if ($caller eq 'reset_by_email') {
             $r->print($message.'<br />');
         } else {
@@ -1569,13 +1577,18 @@ ENDERROR
         }
     } else {
 	# error error: run in circles, scream and shout
-        $message = &Apache::lonhtmlcommon::confirm_success(
-          &mt("The password for user [_1] was not changed.",'<i>'.$user.'</i>').' '.&mt('Please make sure your old password was entered correctly.'),1);
-        unless ($caller eq 'reset_by_email') {
+        if ($caller eq 'reset_by_email') {
+            if (!$result) {
+                return 1;
+            } else {
+                return $result;
+            }
+        } else {
+            $message = &Apache::lonhtmlcommon::confirm_success(
+                &mt("The password for user [_1] was not changed.",'<i>'.$user.'</i>').' '.&mt('Please make sure your old password was entered correctly.'),1);
             $message=&Apache::loncommon::confirmwrapper($message);
             &print_main_menu($r, $message);
         }
-        return 1;
     }
     return;
 }
@@ -1603,7 +1616,7 @@ sub discussionchanger {
         }
     }
     if (defined($userenv{'discmarkread'})) {
-        unless ($userenv{'discdisplay'} eq '') { 
+        unless ($userenv{'discmarkread'} eq '') { 
             $discmark = $userenv{'discmarkread'};
         }
     }
@@ -1647,7 +1660,7 @@ sub discussionchanger {
         $currmark = $lt{'ondisp'};
         $newmark = 'onmark';
     }
-    
+
     $r->print(<<"END");
 <form name="prefs" action="/adm/preferences" method="post">
 <input type="hidden" name="action" value="verify_and_change_discussion" />
@@ -1696,11 +1709,11 @@ sub verify_and_change_discussion {
     if (defined($env{'form.discdisp'}) ) {
         my $newdisp  = $env{'form.newdisp'};
         if ($newdisp eq 'unread') {
-            $message .=&mt('In discussions: only new posts will be displayed.').'<br />';
+            $message .=&Apache::lonhtmlcommon::confirm_success(&mt('In discussions: only new posts will be displayed.')).'<br />';
             &Apache::lonnet::put('environment',{'discdisplay' => $newdisp});
             &Apache::lonnet::appenv({'environment.discdisplay' => $newdisp});
         } else {
-            $message .= &mt('In discussions: all posts will be displayed.').'<br />';
+            $message .= &Apache::lonhtmlcommon::confirm_success(&mt('In discussions: all posts will be displayed.')).'<br />';
             &Apache::lonnet::del('environment',['discdisplay']);
             &Apache::lonnet::delenv('environment.discdisplay');
         }
@@ -1936,19 +1949,19 @@ push(@{ $menu[0]->{items} }, {
     if ($env{'environment.remote'} eq 'off') {
 push(@{ $menu[1]->{items} }, {
 	linktext => 'Launch Remote Control',
-	url => '/adm/remote?url=/adm/preferences?action=launch',
+	url => '/adm/remote?url=/adm/preferences&amp;action=launch',
 	permission => 'F',
 	#help => '',
-	icon => 'network-wireless.png',
+	icon => 'remotecontrol.png',
 	linktitle => 'Launch the remote control for LON-CAPA.',
 	});
     }else{
 push(@{ $menu[1]->{items} }, {
 	linktext => 'Collapse Remote Control',
-	url => '/adm/remote?url=/adm/preferences?action=collapse',
+	url => '/adm/remote?url=/adm/preferences&amp;action=collapse',
 	permission => 'F',
 	#help => '',
-	icon => 'network-wireless.png',
+	icon => 'remotecontrol.png',
 	linktitle => 'Collapse the remote control for LON-CAPA.',
 	});
     }
@@ -2082,361 +2095,14 @@ sub handler {
 	&print_main_menu($r);
     }
 
-    return OK;
-
-
-}
-#remove when done
-#old handler routine
-sub handler2 {
-    my $r = shift;
-    my $user = $env{'user.name'};
-    my $domain = $env{'user.domain'};
-    &Apache::loncommon::content_type($r,'text/html');
-    # Some pages contain DES keys and should not be cached.
-    &Apache::loncommon::no_cache($r);
-    $r->send_http_header;
-    return OK if $r->header_only;
-    #
-    &Apache::loncommon::get_unprocessed_cgi($ENV{'QUERY_STRING'},
-                                   ['action','wysiwyg','returnurl','refpage']);
-    #
-    &Apache::lonhtmlcommon::clear_breadcrumbs();
-    &Apache::lonhtmlcommon::add_breadcrumb
-        ({href => '/adm/preferences',
-          text => 'Set User Preferences'});
-
-    my @Options;
-    # Determine current authentication method
-    my $currentauth=&Apache::lonnet::queryauthenticate($user,$domain);
-    if ($currentauth =~ /^(unix|internal):/) {
-        push (@Options,({ action   => 'changepass',
-                          linktext => 'Change Password',
-                          href     => '/adm/preferences',
-                          help     => 'Change_Password',
-                          subroutine => \&passwordchanger,
-                          breadcrumb => 
-                              { href => '/adm/preferences?action=changepass',
-                                text => 'Change Password'},
-                          },
-                        { action => 'verify_and_change_pass',
-                          subroutine => \&verify_and_change_password,
-                          breadcrumb => 
-                              { href =>'/adm/preferences?action=changepass',
-                                text => 'Change Password'},
-                          printmenu => 'not_on_error',
-                          }));
-    }
-    push (@Options,({ action   => 'changescreenname',
-                      linktext => 'Change Screen Name',
-                      href     => '/adm/preferences',
-                      help     => 'Prefs_Screen_Name_Nickname',
-                      subroutine => \&screennamechanger,
-                      breadcrumb => 
-                          { href => '/adm/preferences?action=changescreenname',
-                            text => 'Change Screen Name'},
-                      },
-                    { action   => 'verify_and_change_screenname',
-                      subroutine => \&verify_and_change_screenname,
-                      breadcrumb => 
-                          { href => '/adm/preferences?action=changescreenname',
-                            text => 'Change Screen Name'},
-                      printmenu => 'yes',
-                      }));
-
-    push (@Options,({ action   => 'changemsgforward',
-                      linktext => 'Change Message Forwarding and Notification E-mail Addresses',
-                      href     => '/adm/preferences',
-                      help     => 'Prefs_Messages',
-                      breadcrumb => 
-                          { href => '/adm/preferences?action=changemsgforward',
-                            text => 'Change Message Forwarding/Notification'},
-                      subroutine => \&msgforwardchanger,
-                      },
-                    { action => 'verify_and_change_msgforward',
-                      help   => 'Prefs_Messages',
-                      breadcrumb => 
-                          { href => '/adm/preferences?action=changemsgforward',
-                            text => 'Change Message Forwarding/Notification'},
-                      printmenu => 'yes',
-                      subroutine => \&verify_and_change_msgforward }));
-    my $aboutmeaction=
-        '/adm/'.$env{'user.domain'}.'/'.$env{'user.name'}.'/aboutme';
-    push (@Options,{ action => 'none', 
-                     linktext =>
-                         q{Edit the Personal Information Page},
-		     help => 'Prefs_About_Me',
-                     href => $aboutmeaction});
-    push (@Options,({ action => 'changecolors',
-                      linktext => 'Change Color Scheme',
-                      href => '/adm/preferences',
-                      help => 'Change_Colors',
-                      breadcrumb => 
-                          { href => '/adm/preferences?action=changecolors',
-                            text => 'Change Colors'},
-                      subroutine => \&colorschanger,
-                  },
-                    { action => 'verify_and_change_colors',
-                      breadcrumb => 
-                          { href => '/adm/preferences?action=changecolors',
-                            text => 'Change Colors'},
-                      printmenu => 'yes',
-                      subroutine => \&verify_and_change_colors,
-                      }));
-    push (@Options,({ action => 'changelanguages',
-                      linktext => 'Change Language Preferences',
-                      href => '/adm/preferences',
-		      help => 'Prefs_Language',
-                      breadcrumb=>
-                          { href => '/adm/preferences?action=changelanguages',
-                            text => 'Change Language'},
-                      subroutine =>  \&languagechanger,
-                  },
-                    { action => 'verify_and_change_languages',
-                      breadcrumb=>
-                          {href => '/adm/preferences?action=changelanguages',
-                           text => 'Change Language'},
-                      printmenu => 'yes',
-                      subroutine=>\&verify_and_change_languages, }
-                    ));
-    push (@Options,({ action => 'changewysiwyg',
-                      linktext => 'Change WYSIWYG Editor Preferences',
-                      href => '/adm/preferences',
-                      breadcrumb => 
-                            { href => '/adm/preferences?action=changewysiwyg',
-                              text => 'Change WYSIWYG Preferences'},
-                      subroutine => \&wysiwygchanger,
-                  },
-                    { action => 'set_wysiwyg',
-                      breadcrumb =>
-                          { href => '/adm/preferences?action=changewysiwyg',
-                            text => 'Change WYSIWYG Preferences'},
-                      printmenu => 'yes',
-                      subroutine => \&verify_and_change_wysiwyg, }
-                    ));
-    push (@Options,({ action => 'changediscussions',
-                      linktext => 'Change Discussion Display Preferences',
-                      href => '/adm/preferences',
-                      help => 'Change_Discussion_Display',
-                      breadcrumb => 
-                            { href => '/adm/preferences?action=changediscussions',
-                              text => 'Change Discussion Preferences'},
-                      subroutine => \&discussionchanger,
-                  },
-                    { action => 'verify_and_change_discussion',
-                      breadcrumb =>
-                          { href => '/adm/preferences?action=changediscussions',
-                            text => 'Change Discussion Preferences'},
-                      printmenu => 'yes',
-                      subroutine => \&verify_and_change_discussion, }
-                    ));
-
-    my $role = ($env{'user.adv'} ? 'Roles' : 'Course');
-    push (@Options,({ action   => 'changerolespref',
-                      linktext => 'Change '.$role.' Page Preferences',
-                      href     => '/adm/preferences',
-                      subroutine => \&rolesprefchanger,
-                      breadcrumb =>
-                          { href => '/adm/preferences?action=changerolespref',
-                            text => 'Change '.$role.' Page Pref'},
-                      },
-                    { action   => 'verify_and_change_rolespref',
-                      subroutine => \&verify_and_change_rolespref,
-                      breadcrumb =>
-                          { href => '/adm/preferences?action=changerolespref',
-                            text => 'Change '.$role.' Page Preferences'},
-                      printmenu => 'yes',
-                      }));
-
-    push (@Options,({ action   => 'changetexenginepref',
-                      linktext => 'Change How Math Equations Are Displayed',
-                      href     => '/adm/preferences',
-                      subroutine => \&texenginechanger,
-                      breadcrumb =>
-                          { href => '/adm/preferences?action=changetexenginepref',
-                            text => 'Change Math Pref'},
-                      },
-                    { action   => 'verify_and_change_texengine',
-                      subroutine => \&verify_and_change_texengine,
-                      breadcrumb =>
-                          { href => '/adm/preferences?action=changetexenginepref',
-                            text => 'Change Math Preferences'},
-                      printmenu => 'yes',
-                      }));
-
-    if ($env{'environment.remote'} eq 'off') {
-	push (@Options,({ action => 'launch',
-			  linktext => 'Launch Remote Control',
-			  href => '/adm/remote?url=/adm/preferences',
-		      }));
-    } else {
-	push (@Options,({ action => 'collapse',
-			  linktext => 'Collapse Remote Control',
-			  href => '/adm/remote?url=/adm/preferences',
-		      }));
-    }
-
-    push (@Options,({ action   => 'changeicons',
-                      linktext => 'Change How Menus are Displayed',
-                      href     => '/adm/preferences',
-                      subroutine => \&iconchanger,
-                      breadcrumb =>
-                          { href => '/adm/preferences?action=changeicons',
-                            text => 'Change Main Menu'},
-                      },
-                    { action   => 'verify_and_change_icons',
-                      subroutine => \&verify_and_change_icons,
-                      breadcrumb =>
-                          { href => '/adm/preferences?action=changeicons',
-                            text => 'Change Main Menu'},
-                      printmenu => 'yes',
-                      }));
-
-    push (@Options,({ action   => 'changeclicker',
-                      linktext => 'Register Response Devices ("Clickers")',
-                      href     => '/adm/preferences',
-                      subroutine => \&clickerchanger,
-                      breadcrumb =>
-                          { href => '/adm/preferences?action=changeclicker',
-                            text => 'Register Clicker'},
-                      },
-                    { action   => 'verify_and_change_clicker',
-                      subroutine => \&verify_and_change_clicker,
-                      breadcrumb =>
-                          { href => '/adm/preferences?action=changeclicker',
-                            text => 'Register Clicker'},
-                      printmenu => 'yes',
-                      }));
-    my %author_roles = &Apache::lonnet::get_my_roles($user,$domain,'userroles','',['au']);
-    if (keys(%author_roles) > 0) {
-      push (@Options,({ action   => 'changedomcoord',
-                        linktext => 'Restrict Domain Coordinator Access',
-                        href     => '/adm/preferences',
-                        subroutine => \&domcoordchanger,
-                        breadcrumb =>
-                            { href => '/adm/preferences?action=changedomcoord',
-                              text => 'Restrict Domain Coordinator Access'},
-                      },
-                      { action   => 'verify_and_change_domcoord',
-                        subroutine => \&verify_and_change_domcoord,
-                        breadcrumb =>
-                            { href => '/adm/preferences?action=changedomcoord',
-                              text => 'Restrict Domain Coordinator Access'},
-                        printmenu => 'yes',
-                      }));
-    }
-
-    push (@Options,({ action   => 'lockwarning',
-                      subroutine => \&lockwarning,
-                      breadcrumb =>
-                          { href => '/adm/preferences?action=lockwarning',
-                            text => 'Lock Warnings'},
-                      },
-                    { action   => 'verify_and_change_locks',
-                      subroutine => \&verify_and_change_lockwarning,
-                      breadcrumb =>
-                          { href => '/adm/preferences?action=lockwarning',
-                            text => 'Lockwarnings'},
-                      printmenu => 'yes',
-                      }));
-
-
-    if (&Apache::lonnet::allowed('whn',$env{'request.course.id'})
-	|| &Apache::lonnet::allowed('whn',$env{'request.course.id'}.'/'
-				    .$env{'request.course.sec'})) {
-        push (@Options,({ action => 'changecourseinit',
-                          linktext => 'Change Course Initialization Preference',
-                          href => '/adm/preferences',
-                          subroutine => \&coursedisplaychanger,
-                          breadcrumb =>
-                              { href => '/adm/preferences?action=changecourseinit',
-                                text => 'Change Course Init. Pref.'},
-                          },
-                        { action => 'verify_and_change_coursepage',
-                          breadcrumb =>
-                          { href => '/adm/preferences?action=changecourseinit',                               text => 'Change Course Initialization Preference'},
-                        printmenu => 'yes',
-                        subroutine => \&verify_and_change_coursepage,
-                       }));
-    }
-
-    if (($env{'user.name'} =~ /^(albertel|fox|foxr|kortemey|korte|raeburn)$/)
-     && ($env{'user.domain'} =~/^(msu|gerd)$/)){
-        push (@Options,({ action => 'debugtoggle',
-                          printmenu => 'yes',
-                          subroutine => \&toggle_debug,
-                          }));
-    }
-
-    $r->print(&Apache::loncommon::start_page('Change Preferences'));
-
-    my $call = undef;
-    my $help = undef;
-    my $printmenu = 'yes';
-    foreach my $option (@Options) {
-        if ($option->{'action'} eq $env{'form.action'}) {
-            $call = $option->{'subroutine'};
-            $printmenu = $option->{'printmenu'};
-            if (exists($option->{'breadcrumb'})) {
-                &Apache::lonhtmlcommon::add_breadcrumb
-                    ($option->{'breadcrumb'});
-            }
-	    $help=$option->{'help'};
-        }
+    # Properly end the HTML page of all preference pages
+    # started in each sub routine
+    # Exception: print_main_menu has its own end_page call
+    unless (!exists $env{'form.action'} ||
+            $env{'form.action'} eq 'debugtoggle') {
+        $r->print(&Apache::loncommon::end_page());
     }
-    $r->print(&Apache::lonhtmlcommon::breadcrumbs('Change Preferences',$help));
-    my $error;
-    if (defined($call)) {
-        $error = $call->($r);
-    }
-    if ( ( ($printmenu eq 'yes')
-	   || ($printmenu eq 'not_on_error' && !$error) )
-	 && (!$env{'form.returnurl'})) {
-        my $optionlist = '<table cellpadding="5">';
-        if ($env{'user.name'} =~ 
-                         /^(albertel|kortemey|fox|foxr|korte|hallmat3|turtle|raeburn)$/
-            ) {
-            push (@Options,({ action => 'debugtoggle',
-                              linktext => 'Toggle Debug Messages',
-                              text => 'Current Debug status is -'.
-                                  $env{'user.debug'}.'-.',
-                              href => '/adm/preferences',
-                              printmenu => 'yes',
-                              subroutine => \&toggle_debug,
-                              }));
-        }
-        foreach my $option(@Options) {
-            my $optiontext = '';
-            if (exists($option->{'href'})) {
-		$option->{'href_args'}{'action'}=$option->{'action'};
-		$optiontext .= 
-                    '<a href="'.&add_get_param($option->{'href'},
-					       $option->{'href_args'}).'">'.
-                    &mt($option->{'linktext'}).'</a>';
-            }
-            if (exists($option->{'text'})) {
-                $optiontext .= ' '.&mt($option->{'text'});
-            }
-            if ($optiontext ne '') {
-                $optiontext = '<font size="+1">'.$optiontext.'</font>'; 
-                my $helplink = '&nbsp;';
-                if (exists($option->{'help'})) {
-                    $helplink = &Apache::loncommon::help_open_topic
-                                                    ($option->{'help'});
-                }
-                $optionlist .= '<tr>'.
-                    '<td>'.$helplink.'</td>'.
-                    '<td>'.$optiontext.'</td>'.
-                    '</tr>';
-            }
-        }
-        $optionlist .= '</table>';
-        $r->print($optionlist);
-    } elsif ($env{'form.returnurl'}) {
-	$r->print('<br /><a href="'.$env{'form.returnurl'}.'"><font size="+1">'.
-		  &mt('Return').'</font></a>');
-    }
-    $r->print(&Apache::loncommon::end_page());
+
     return OK;
 }