File:  [LON-CAPA] / loncom / interface / lonpreferences.pm
Revision 1.158: download - view: text, annotated - select for diffs
Tue May 5 16:01:50 2009 UTC (15 years ago) by bisitz
Branches: MAIN
CVS tags: HEAD
Optimized and enhanced confirm messages:
(currently only used in lonpreferences.pm)
- Introduce new sub routine "confirmwrapper" and related style "LC_confirm_box"
  Wraps option changes confirmation messages in a box (better separation from rest of screen)
- Moved trailing confirm icons (success/error) to begin of the confirm texts
- Added confirmwrapper to preference settings; consistent output (removed some br, hr, etc.)
- Added HTML new line codes ("\n") to lines in &confirm_success

Localization and Wording:
- Optimized &mt usage und optimized localization file usage:
  Re-use existing phrases and always use same structure of messages ("Set [_1] to [_2]" and "Reset [_1]")
- Optimized wording (eg., Screenname and Nickname)
- Some optimized/corrected German translations and removed now unused phrases
- Optimized confirm text output for author option: "Block access to construction space"

    1: # The LearningOnline Network
    2: # Preferences
    3: #
    4: # $Id: lonpreferences.pm,v 1.158 2009/05/05 16:01:50 bisitz Exp $
    5: #
    6: # Copyright Michigan State University Board of Trustees
    7: #
    8: # This file is part of the LearningOnline Network with CAPA (LON-CAPA).
    9: #
   10: # LON-CAPA is free software; you can redistribute it and/or modify
   11: # it under the terms of the GNU General Public License as published by
   12: # the Free Software Foundation; either version 2 of the License, or
   13: # (at your option) any later version.
   14: #
   15: # LON-CAPA is distributed in the hope that it will be useful,
   16: # but WITHOUT ANY WARRANTY; without even the implied warranty of
   17: # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
   18: # GNU General Public License for more details.
   19: #
   20: # You should have received a copy of the GNU General Public License
   21: # along with LON-CAPA; if not, write to the Free Software
   22: # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
   23: #
   24: # /home/httpd/html/adm/gpl.txt
   25: #
   26: # http://www.lon-capa.org/
   27: #
   28: # This package uses the "londes.js" javascript code. 
   29: #
   30: # TODOs that have to be completed:
   31: #    interface with lonnet to change the password
   32:  
   33: package Apache::lonpreferences;
   34: 
   35: use strict;
   36: use LONCAPA;
   37: use Apache::Constants qw(:common);
   38: use Apache::File;
   39: use Crypt::DES;
   40: use DynaLoader; # for Crypt::DES version
   41: use Apache::loncommon();
   42: use Apache::lonhtmlcommon();
   43: use Apache::lonlocal;
   44: use Apache::lonnet;
   45: use LONCAPA();
   46: 
   47: #
   48: # Write lonnet::passwd to do the call below.
   49: # Use:
   50: #   my $answer=reply("encrypt:passwd:$udom:$uname:$upass",$tryserver);
   51: #
   52: ##################################################
   53: #          password associated functions         #
   54: ##################################################
   55: sub des_keys {
   56:     # Make a new key for DES encryption.
   57:     # Each key has two parts which are returned separately.
   58:     # Please note:  Each key must be passed through the &hex function
   59:     # before it is output to the web browser.  The hex versions cannot
   60:     # be used to decrypt.
   61:     my @hexstr=('0','1','2','3','4','5','6','7',
   62:                 '8','9','a','b','c','d','e','f');
   63:     my $lkey='';
   64:     for (0..7) {
   65:         $lkey.=$hexstr[rand(15)];
   66:     }
   67:     my $ukey='';
   68:     for (0..7) {
   69:         $ukey.=$hexstr[rand(15)];
   70:     }
   71:     return ($lkey,$ukey);
   72: }
   73: 
   74: sub des_decrypt {
   75:     my ($key,$cyphertext) = @_;
   76:     my $keybin=pack("H16",$key);
   77:     my $cypher;
   78:     if ($Crypt::DES::VERSION>=2.03) {
   79:         $cypher=new Crypt::DES $keybin;
   80:     } else {
   81:         $cypher=new DES $keybin;
   82:     }
   83:     my $plaintext=
   84: 	$cypher->decrypt(unpack("a8",pack("H16",substr($cyphertext,0,16))));
   85:     $plaintext.=
   86: 	$cypher->decrypt(unpack("a8",pack("H16",substr($cyphertext,16,16))));
   87:     $plaintext=substr($plaintext,1,ord(substr($plaintext,0,1)) );
   88:     return $plaintext;
   89: }
   90: 
   91: ################################################################
   92: #                       Handler subroutines                    #
   93: ################################################################
   94: 
   95: ################################################################
   96: #         Language Change Subroutines                          #
   97: ################################################################
   98: 
   99: sub wysiwygchanger {
  100:     my $r = shift;
  101:     Apache::lonhtmlcommon::add_breadcrumb(
  102: 	    {	href => '/adm/preferences?action=changewysiwyg',
  103:                 text => 'Change WYSIWYG Preferences'});
  104:     $r->print(Apache::loncommon::start_page('Content Display Settings'));
  105:     $r->print(Apache::lonhtmlcommon::breadcrumbs('Change WYSIWYG Preferences'));
  106: 
  107:     my %userenv = &Apache::lonnet::get
  108:         ('environment',['wysiwygeditor']);
  109:     my $onselect='checked="checked"';
  110:     my $offselect='';
  111:     if ($userenv{'wysiwygeditor'} eq 'on') {
  112: 	$onselect='';
  113: 	$offselect='checked="checked"';
  114:     }
  115:     my $switchoff=&mt('Disable WYSIWYG editor');
  116:     my $switchon=&mt('Enable WYSIWYG editor');
  117:     my $warning='';
  118:     if ($env{'user.adv'}) {
  119:        $warning.="<p>".&mt("The WYSIWYG editor only supports simple HTML and is in many cases unsuited for advanced authoring. In a number of cases, it may destroy advanced authoring involving LaTeX and script function calls.")."</p>";
  120:     }
  121:     $r->print(<<ENDLSCREEN);
  122: <form name="prefs" action="/adm/preferences" method="post">
  123: <input type="hidden" name="action" value="set_wysiwyg" />
  124: $warning
  125: <br />
  126: <label><input type="radio" name="wysiwyg" value="off" $onselect /> $switchoff</label><br />
  127: <label><input type="radio" name="wysiwyg" value="on" $offselect /> $switchon</label>
  128: ENDLSCREEN
  129:     $r->print('<br /><input type="submit" value="'.&mt('Save').'" />');
  130: }
  131: 
  132: 
  133: sub verify_and_change_wysiwyg {
  134:     my $r = shift;
  135:     my $newsetting=$env{'form.wysiwyg'};
  136:     &Apache::lonnet::put('environment',{'wysiwygeditor' => $newsetting});
  137:     &Apache::lonnet::appenv({'environment.wysiwygeditor' => $newsetting});
  138:     my $message=&Apache::lonhtmlcommon::confirm_success(&mt('Set [_1] to [_2]','<i>'.&mt('WYSIWYG Editor').'</i>','<tt>'.&mt($newsetting).'</tt>'));
  139:     $message=&Apache::loncommon::confirmwrapper($message);
  140:     &print_main_menu($r,$message);
  141: }
  142: 
  143: ################################################################
  144: #         Language Change Subroutines                          #
  145: ################################################################
  146: sub languagechanger {
  147:     my $r = shift;
  148:     
  149:     Apache::lonhtmlcommon::add_breadcrumb(
  150: 	    {	href => '/adm/preferences?action=changelanguages',
  151:                 text => 'Change Language'});
  152:     $r->print(Apache::loncommon::start_page('Content Display Settings'));
  153:     $r->print(Apache::lonhtmlcommon::breadcrumbs('Change Language')); 
  154:     my $user       = $env{'user.name'};
  155:     my $domain     = $env{'user.domain'};
  156:     my %userenv = &Apache::lonnet::get
  157:         ('environment',['languages']);
  158:     my $language=$userenv{'languages'};
  159: 
  160:     my $pref=&mt('Preferred language');
  161:     my %langchoices=('' => 'No language preference');
  162:     foreach (&Apache::loncommon::languageids()) {
  163: 	if (&Apache::loncommon::supportedlanguagecode($_)) {
  164: 	    $langchoices{&Apache::loncommon::supportedlanguagecode($_)}
  165: 	               = &Apache::loncommon::plainlanguagedescription($_);
  166: 	}
  167:     }
  168:     my $selectionbox=&Apache::loncommon::select_form($language,'language',
  169: 						     %langchoices);
  170:     $r->print(<<ENDLSCREEN);
  171: <form name="prefs" action="/adm/preferences" method="post">
  172: <input type="hidden" name="action" value="verify_and_change_languages" />
  173: <br />$pref: $selectionbox
  174: ENDLSCREEN
  175:     $r->print('<br /><input type="submit" value="'.&mt('Save').'" />');
  176: }
  177: 
  178: 
  179: sub verify_and_change_languages {
  180:     my $r = shift;
  181:     my $user       = $env{'user.name'};
  182:     my $domain     = $env{'user.domain'};
  183: # Screenname
  184:     my $newlanguage  = $env{'form.language'};
  185:     $newlanguage=~s/[^\-\w]//g;
  186:     my $message='';
  187:     if ($newlanguage) {
  188:         &Apache::lonnet::put('environment',{'languages' => $newlanguage});
  189:         &Apache::lonnet::appenv({'environment.languages' => $newlanguage});
  190:         $message=&Apache::lonhtmlcommon::confirm_success(&mt('Set [_1] to [_2]','<i>'.&mt('Preferred language').'</i>','<tt>"'.$newlanguage.'"</tt>.'));
  191:     } else {
  192:         &Apache::lonnet::del('environment',['languages']);
  193:         &Apache::lonnet::delenv('environment.languages');
  194:         $message=&Apache::lonhtmlcommon::confirm_success(&mt('Reset [_1]','<i>'.&mt('Preferred language').'</i>'));
  195:     }
  196:     $message=&Apache::loncommon::confirmwrapper($message);
  197:     &Apache::loncommon::flush_langs_cache($user,$domain);
  198:     &print_main_menu($r, $message);
  199: }
  200: 
  201: ################################################################
  202: #         Tex Engine Change Subroutines                        #
  203: ################################################################
  204: sub texenginechanger {
  205:     my $r = shift;
  206:     Apache::lonhtmlcommon::add_breadcrumb(
  207: 	    {	href => '/adm/preferences?action=changetexenginepref',
  208:                 text => 'Change How Math Equations Are Displayed'});
  209:     $r->print(Apache::loncommon::start_page('Content Display Settings'));
  210:     $r->print(Apache::lonhtmlcommon::breadcrumbs('Change How Math Equations Are Displayed'));
  211:     my $user       = $env{'user.name'};
  212:     my $domain     = $env{'user.domain'};
  213:     my %userenv = &Apache::lonnet::get('environment',['texengine']);
  214:     my $texengine=$userenv{'texengine'};
  215: 
  216:     my %mathchoices=('' => 'Default',
  217: 		     'tth' => 'tth (TeX to HTML)',
  218: 		     #'ttm' => 'TeX to MathML',
  219: 		     'jsMath' => 'jsMath',
  220: 		     'mimetex' => 'mimetex (Convert to Images)'
  221:                      );
  222:     my $selectionbox=&Apache::loncommon::select_form($texengine,'texengine',
  223: 						     %mathchoices);
  224:     my $jsMath_start=&Apache::lontexconvert::jsMath_header();
  225:     my %lt=&Apache::lonlocal::texthash(
  226:       'headline' => 'Change Math Preferences',
  227:       'preftxt'  => 'Preferred method to display Math',
  228:       'change'   => 'Save',
  229:       'exmpl'    => 'Examples',
  230:       'jsmath'   => 'jsMath:',
  231:       'tth'      => 'tth (TeX to HTML):',
  232:       'mimetex'  => 'mimetex (Convert to Images):',
  233:     );
  234: 
  235:     $r->print(<<ENDLSCREEN);
  236: <h2>$lt{'headline'}</h2>
  237: <form name="prefs" action="/adm/preferences" method="post">
  238: <input type="hidden" name="action" value="verify_and_change_texengine" />
  239: <p>
  240: $lt{'preftxt'}: $selectionbox 
  241: <br />
  242: <input type="submit" value="$lt{'change'}" />
  243: </p>
  244: </form>
  245: <br />
  246: <hr />
  247: $lt{'exmpl'}
  248: 
  249: <h3>$lt{'jsmath'}</h3> 
  250: <p>
  251: $jsMath_start
  252: <script type="text/javascript" language="JavaScript">
  253: if (jsMath.nofonts == 1) {
  254:     document.writeln
  255:         ('<div style="padding: 10; border-style: solid; border-width:3;'
  256: 	 +' border-color: #DD0000; background-color: #FFF8F8; width: 75%; text-align: left">'
  257: 	 +'<small><font color="#AA0000"><b>Warning:</b> '
  258: 	 +'It looks like you don\\\'t have the TeX math fonts installed. '
  259: 	 +'The jsMath example on this page may not look right without them. '
  260: 	 +'The <a href="http://www.math.union.edu/locate/jsMath/" target="_blank"> '
  261: 	 +'jsMath Home Page</a> has information on how to download the '
  262: 	 +'needed fonts.  In the meantime, jsMath will do the best it can '
  263: 	 +'with the fonts you have, but it may not be pretty and some equations '
  264: 	 +'may not be rendered correctly. '
  265: 	 +'</font></small></div>');
  266: }
  267: </script>
  268: <iframe src="/res/adm/pages/math_example.tex?inhibitmenu=yes&texengine=jsMath" width="400" height="120"></iframe>
  269: </p>
  270: 
  271: <h3>$lt{'mimetex'}</h3>
  272: <p>
  273: <iframe src="/res/adm/pages/math_example.tex?inhibitmenu=yes&texengine=mimetex" width="400" height="100"></iframe>
  274: </p>
  275: 
  276: <h3>$lt{'tth'}</h3>
  277: <p>
  278: <iframe src="/res/adm/pages/math_example.tex?inhibitmenu=yes&texengine=tth" width="400" height="200"></iframe>
  279: </p>
  280: ENDLSCREEN
  281:     if ($env{'environment.texengine'} ne 'jsMath') {
  282: 	$r->print('<script type="text/javascript" language="JavaScript">jsMath.Process()</script>');
  283:     }
  284: }
  285: 
  286: 
  287: sub verify_and_change_texengine {
  288:     my $r = shift;
  289:     my $user       = $env{'user.name'};
  290:     my $domain     = $env{'user.domain'};
  291: # Screenname
  292:     my $newtexengine  = $env{'form.texengine'};
  293:     $newtexengine=~s/[^\-\w]//g;
  294:     if ($newtexengine eq 'ttm') {
  295: 	&Apache::lonnet::appenv({'browser.mathml' => 1});
  296:     } else {
  297: 	if ($env{'environment.texengine'} eq 'ttm') {
  298: 	    &Apache::lonnet::appenv({'browser.mathml' => 0});
  299: 	}
  300:     }
  301:     my $message='';
  302:     if ($newtexengine) {
  303:         &Apache::lonnet::put('environment',{'texengine' => $newtexengine});
  304:         &Apache::lonnet::appenv({'environment.texengine' => $newtexengine});
  305:         $message=&Apache::lonhtmlcommon::confirm_success(&mt('Set [_1] to [_2]','<i>'.&mt('Preferred method to display Math').'</i>','<tt>"'.$newtexengine.'"</tt>'));
  306:     } else {
  307:         &Apache::lonnet::del('environment',['texengine']);
  308:         &Apache::lonnet::delenv('environment.texengine');
  309:         $message=&Apache::lonhtmlcommon::confirm_success(&mt('Reset [_1]','<i>'.&mt('Preferred method to display Math').'</i>'));
  310:     }
  311:     $message=&Apache::loncommon::confirmwrapper($message);
  312:     &print_main_menu($r, $message);
  313: }
  314: 
  315: ################################################################
  316: #         Roles Page Preference Change Subroutines         #
  317: ################################################################
  318: sub rolesprefchanger {
  319:     my $r = shift;
  320:     my $role    = ($env{'user.adv'} ? 'Role' : 'Course');
  321:     my $lc_role = ($env{'user.adv'} ? 'role' : 'course');
  322:     my $user       = $env{'user.name'};
  323:     my $domain     = $env{'user.domain'};
  324:     my %userenv = &Apache::lonnet::get
  325:         ('environment',['recentroles','recentrolesn']);
  326:     Apache::lonhtmlcommon::add_breadcrumb(
  327: 	    {	href => '/adm/preferences?action=changerolespref',
  328:                 text => 'Change '.$role.' Page Pref'});
  329:     $r->print(Apache::loncommon::start_page('Content Display Settings'));
  330:     $r->print(Apache::lonhtmlcommon::breadcrumbs('Change '.$role.' Page Pref'));
  331:     my $hotlist_flag=$userenv{'recentroles'};
  332:     my $hotlist_n=$userenv{'recentrolesn'};
  333:     my $checked;
  334:     if ($hotlist_flag) {
  335: 	$checked = 'checked="checked"';
  336:     }
  337:     
  338:     if (!$hotlist_n) { $hotlist_n=3; }
  339:     my $options;
  340:     for (my $i=1; $i<10; $i++) {
  341: 	my $select;
  342: 	if ($hotlist_n == $i) { $select = 'selected="selected"'; }
  343: 	$options .= "<option $select>$i</option>\n";
  344:     }
  345: 
  346: # Get list of recent roles and display with checkbox in front
  347:     my $roles_check_list = '';
  348:     my $role_key='';
  349:     if ($env{'environment.recentroles'}) {
  350:         my %recent_roles =
  351:                &Apache::lonhtmlcommon::get_recent('roles',$env{'environment.recentrolesn'});
  352:         my %frozen_roles =
  353:                &Apache::lonhtmlcommon::get_recent_frozen('roles',$env{'environment.recentrolesn'});
  354:         
  355:         my %role_text = &rolespref_get_role_text([keys(%recent_roles)]);
  356:         my @sorted_roles = sort {$role_text{$a} cmp $role_text{$b}} keys(%role_text);
  357: 
  358:         $roles_check_list .=
  359: 	    &Apache::loncommon::start_data_table().
  360: 	    &Apache::loncommon::start_data_table_header_row().
  361: 	    "<th>".&mt('Freeze '.$role)."</th>".
  362: 	    "<th>".&mt($role)."</td>".
  363: 	    &Apache::loncommon::end_data_table_header_row().
  364: 	    "\n";
  365: 	my $count;
  366:         foreach $role_key (@sorted_roles) {
  367:             my $checked = "";
  368:             my $value = $recent_roles{$role_key};
  369:             if ($frozen_roles{$role_key}) {
  370:                 $checked = "checked=\"checked\"";
  371:             }
  372: 	    $count++;
  373:             $roles_check_list .=
  374: 		&Apache::loncommon::start_data_table_row().
  375: 		'<td class="LC_table_cell_checkbox">'.
  376: 		"<input type=\"checkbox\" $checked name=\"freezeroles\"".
  377: 		" id=\"freezeroles$count\" value=\"$role_key\" /></td>".
  378: 		"<td><label for=\"freezeroles$count\">".
  379: 		"$role_text{$role_key}</label></td>".
  380: 		&Apache::loncommon::end_data_table_row(). "\n";
  381:         }
  382:         $roles_check_list .= "</table>\n";
  383:     }
  384: 
  385:     $r->print('
  386: <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.').'
  387: </p>
  388: <form name="prefs" action="/adm/preferences" method="POST">
  389: <input type="hidden" name="action" value="verify_and_change_rolespref" />
  390: <br /><label>'.&mt('Enable Recent '.$role.'s Hotlist:').'
  391: <input type="checkbox" '.$checked.' name="recentroles" value="true" /></label>
  392: <br />'.&mt('Number of '.$role.'s in Hotlist:').'
  393: <select name="recentrolesn" size="1">
  394: '.$options.'
  395: </select>
  396: <p>'.&mt('This list below can be used to <q>freeze</q> '.$lc_role.'s on your screen. Those marked as frozen will not be removed from the list, even if they have not been used recently.').'
  397: </p>
  398: '.$roles_check_list.'
  399: <br />
  400: <input type="submit" value="'.&mt('Save').'" />
  401: </form>');
  402: }
  403: 
  404: sub rolespref_get_role_text {
  405: # Get a line of text for each role
  406:     my ($roles) = @_;
  407:     my %roletext = ();
  408: 
  409:     foreach my $item (@$roles) {
  410: # get course information
  411:         my ($role,$rest) = split(/\./, $item);
  412:         my $trole = "";
  413:         $trole = &Apache::lonnet::plaintext($role);
  414:         my ($tdomain,$other,$tsection)= split(/\//,Apache::lonnet::declutter($rest));
  415:         my $tother = '-';
  416:         if ($role =~ /^(cc|st|in|ta|ep|cr)/ ) {
  417:             my %newhash=&Apache::lonnet::coursedescription($tdomain."_".$other);
  418:             $tother = " - ".$newhash{'description'};
  419:         } elsif ($role =~ /dc/) {
  420:             $tother = "";
  421:         } else {
  422:             $tother = " - $other";
  423:         }
  424:  
  425:         my $section="";
  426:         if ($tsection) {
  427:             $section = " - Section/Group: $tsection";
  428:         }
  429:         $roletext{$item} = $tdomain." - ".$trole.$tother.$section;
  430:     }
  431:     return %roletext;
  432: }
  433: 
  434: sub verify_and_change_rolespref {
  435:     my $r = shift;
  436:     my $role = ($env{'user.adv'} ? 'Role' : 'Course');
  437:     my $user       = $env{'user.name'};
  438:     my $domain     = $env{'user.domain'};
  439: # Recent Roles Hotlist Flag
  440:     my $hotlist_flag  = $env{'form.recentroles'};
  441:     my $hotlist_n  = $env{'form.recentrolesn'};
  442:     my $message='<hr />';
  443:     if ($hotlist_flag) {
  444:         &Apache::lonnet::put('environment',{'recentroles' => $hotlist_flag});
  445:         &Apache::lonnet::appenv({'environment.recentroles' => $hotlist_flag});
  446:         $message=&mt('Recent '.$role.'s Hotlist is Enabled');
  447:     } else {
  448:         &Apache::lonnet::del('environment',['recentroles']);
  449:         &Apache::lonnet::delenv('environment.recentroles');
  450:         $message=&mt('Recent '.$role.'s Hotlist is Disabled');
  451:     }
  452:     if ($hotlist_n) {
  453:         &Apache::lonnet::put('environment',{'recentrolesn' => $hotlist_n});
  454:         &Apache::lonnet::appenv({'environment.recentrolesn' => $hotlist_n});
  455:         if ($hotlist_flag) {
  456:             $message.="<br />".
  457: 		&mt('Display [_1] Most Recent '.$role.'s',$hotlist_n)."\n";
  458:         }
  459:     }
  460: 
  461: # Get list of froze roles and list of recent roles
  462:     my @freeze_list = &Apache::loncommon::get_env_multiple('form.freezeroles');
  463:     my %freeze = ();
  464:     my %roletext = ();
  465: 
  466:     foreach my $key (@freeze_list) {
  467:         $freeze{$key}='1';
  468:     }
  469: 
  470:     my %recent_roles =
  471:         &Apache::lonhtmlcommon::get_recent('roles',$env{'environment.recentrolesn'});
  472:     my %frozen_roles =
  473:         &Apache::lonhtmlcommon::get_recent_frozen('roles',$env{'environment.recentrolesn'});
  474:     my %role_text = &rolespref_get_role_text([keys(%recent_roles)]);
  475: 
  476: # Unset any roles that were previously frozen but aren't in list
  477:     foreach my $role_key (sort(keys(%recent_roles))) {
  478:         if (($frozen_roles{$role_key}) && (!exists($freeze{$role_key}))) {
  479: 	    $message .= "<br />".&Apache::lonhtmlcommon::confirm_success(&mt('Unfreezing '.$role.': [_1]','<i>'.$role_text{$role_key}.'</i>'));
  480: 	    &Apache::lonhtmlcommon::store_recent('roles',$role_key,' ',0);
  481:         }
  482:     }
  483: 
  484: # Freeze selected roles
  485:     foreach my $role_key (@freeze_list) {
  486:         if (!$frozen_roles{$role_key}) {
  487:              $message .= "<br />".
  488:              &Apache::lonhtmlcommon::confirm_success(&mt('Freezing '.$role.': [_1]','<i>'.$role_text{$role_key}.'</i>'));
  489:              &Apache::lonhtmlcommon::store_recent('roles',
  490:                                           $role_key,' ',1);
  491:         }
  492:     }
  493:     $message=&Apache::loncommon::confirmwrapper($message);
  494:     &print_main_menu($r, $message);
  495: }
  496: 
  497: 
  498: 
  499: ################################################################
  500: #         Anonymous Discussion Name Change Subroutines         #
  501: ################################################################
  502: sub screennamechanger {
  503:     my $r = shift;
  504:     my $user       = $env{'user.name'};
  505:     my $domain     = $env{'user.domain'};
  506:     my %userenv = &Apache::lonnet::get
  507:         ('environment',['screenname','nickname']);
  508:     my $screenname=$userenv{'screenname'};
  509:     my $nickname=$userenv{'nickname'};
  510:     Apache::lonhtmlcommon::add_breadcrumb(
  511: 		{ href => '/adm/preferences?action=changescreenname',
  512:                   text => 'Change Screen Name'});
  513:     $r->print(Apache::loncommon::start_page('Personal Data'));
  514:     $r->print(Apache::lonhtmlcommon::breadcrumbs('Change Screen Name'));
  515:     $r->print('<p>'
  516:              .&mt('Change the name that is displayed in your posts.')
  517:              .'</p>'
  518:     );
  519:     $r->print('<form name="prefs" action="/adm/preferences" method="post">'
  520:              .'<input type="hidden" name="action" value="verify_and_change_screenname" />'
  521:              .&Apache::lonhtmlcommon::start_pick_box()
  522:              .&Apache::lonhtmlcommon::row_title(&mt('Screenname').' '.&mt('(shown if you post anonymously)'))
  523:              .'<input type="text" size="20" value="'.$screenname.'" name="screenname" />'
  524:              .&Apache::lonhtmlcommon::row_closure()
  525:              .&Apache::lonhtmlcommon::row_title(&mt('Nickname').' '.&mt('(shown if you post non-anonymously)'))
  526:              .'<input type="text" size="20" value="'.$nickname.'" name="nickname" />'
  527:              .&Apache::lonhtmlcommon::row_closure()
  528:              .&Apache::lonhtmlcommon::row_title()
  529:              .'<input type="submit" value="'.&mt('Save').'" />'
  530:              .&Apache::lonhtmlcommon::row_closure(1)
  531:              .&Apache::lonhtmlcommon::end_pick_box()
  532:              .'</form>'
  533:     );
  534: }
  535: 
  536: sub verify_and_change_screenname {
  537:     my $r = shift;
  538:     my $user       = $env{'user.name'};
  539:     my $domain     = $env{'user.domain'};
  540: # Screenname
  541:     my $newscreen  = $env{'form.screenname'};
  542:     $newscreen=~s/[^ \w]//g;
  543:     my $message='';
  544:     if ($newscreen) {
  545:         &Apache::lonnet::put('environment',{'screenname' => $newscreen});
  546:         &Apache::lonnet::appenv({'environment.screenname' => $newscreen});
  547:         $message=&Apache::lonhtmlcommon::confirm_success(&mt('Set [_1] to [_2]','<i>'.&mt('Screenname').'</i>','<tt>"'.$newscreen.'."</tt>'));
  548:     } else {
  549:         &Apache::lonnet::del('environment',['screenname']);
  550:         &Apache::lonnet::delenv('environment.screenname');
  551:         $message=&Apache::lonhtmlcommon::confirm_success(&mt('Reset [_1]','<i>'.&mt('Screenname').'</i>'));
  552:     }
  553: # Nickname
  554:     $message.='<br />';
  555:     $newscreen  = $env{'form.nickname'};
  556:     $newscreen=~s/[^ \w]//g;
  557:     if ($newscreen) {
  558:         &Apache::lonnet::put('environment',{'nickname' => $newscreen});
  559:         &Apache::lonnet::appenv({'environment.nickname' => $newscreen});
  560:         $message.=&Apache::lonhtmlcommon::confirm_success(&mt('Set [_1] to [_2]','<i>'.&mt('Nickname').'</i>','<tt>"'.$newscreen.'"</tt>.'));
  561:     } else {
  562:         &Apache::lonnet::del('environment',['nickname']);
  563:         &Apache::lonnet::delenv('environment.nickname');
  564:         $message.=&Apache::lonhtmlcommon::confirm_success(&mt('Reset [_1]','<i>'.&mt('Nickname').'</i>'));
  565:     }
  566:     &Apache::lonnet::devalidate_cache_new('namescache',$user.':'.$domain);
  567:     $message=&Apache::loncommon::confirmwrapper($message);
  568:     &print_main_menu($r, $message);
  569: }
  570: 
  571: ################################################################
  572: #                     Icon Subroutines                         #
  573: ################################################################
  574: sub iconchanger {
  575:     my $r = shift;
  576:     &Apache::lonhtmlcommon::add_breadcrumb(
  577: 	    {	href => '/adm/preferences?action=changeicons',
  578:                 text => 'Change Main Menu'});
  579:     $r->print(Apache::loncommon::start_page('Page Display Settings'));
  580:     $r->print(Apache::lonhtmlcommon::breadcrumbs('Change Main Menu'));
  581: 
  582:     my $user       = $env{'user.name'};
  583:     my $domain     = $env{'user.domain'};
  584:     my %userenv = &Apache::lonnet::get
  585:         ('environment',['icons']);
  586:     my $iconic='checked="checked"';
  587:     my $classic='';
  588:     my $onlyicon='';
  589:     if ($userenv{'icons'} eq 'classic') {
  590:        $classic='checked="checked"';
  591:        $iconic='';
  592:     }
  593:     if ($userenv{'icons'} eq 'iconsonly') {
  594:        $onlyicon='checked="checked"';
  595:        $iconic='';
  596:     }
  597:     my $useicons=&mt('Use icons and text');
  598:     my $usebuttons=&mt('Use buttons and text');
  599:     my $useicononly=&mt('Use icons only');
  600:     my $change=&mt('Save');
  601:     $r->print(<<ENDSCREEN);
  602: <form name="prefs" action="/adm/preferences" method="post">
  603: <input type="hidden" name="action" value="verify_and_change_icons" />
  604: <label><input type="radio" name="menumode" value="iconic" $iconic /> $useicons</label><br />
  605: <label><input type="radio" name="menumode" value="classic" $classic /> $usebuttons</label><br />
  606: <label><input type="radio" name="menumode" value="iconsonly" $onlyicon /> $useicononly</label><br />
  607: <input type="submit" value="$change" />
  608: </form>
  609: ENDSCREEN
  610: }
  611: 
  612: sub verify_and_change_icons {
  613:     my $r = shift;
  614:     my $user       = $env{'user.name'};
  615:     my $domain     = $env{'user.domain'};
  616:     my $newicons   = $env{'form.menumode'};
  617: 
  618:     &Apache::lonnet::put('environment',{'icons' => $newicons});
  619:     &Apache::lonnet::appenv({'environment.icons' => $newicons});
  620:     my $message=&Apache::lonhtmlcommon::confirm_success(&mt('Set [_1] to [_2]','<i>'.&mt('Menu Display').'</i>','<tt>'.$newicons.'</tt>'));
  621:     $message=&Apache::loncommon::confirmwrapper($message);
  622:     &print_main_menu($r, $message);
  623: }
  624: 
  625: ################################################################
  626: #                     Clicker Subroutines                      #
  627: ################################################################
  628: 
  629: sub clickerchanger {
  630:     my $r = shift;
  631:     &Apache::lonhtmlcommon::add_breadcrumb(
  632: 	    {	href => '/adm/preferences?action=changeclicker',
  633:                 text => 'Register Clicker'});
  634:     $r->print(Apache::loncommon::start_page('Other'));
  635:     $r->print(Apache::lonhtmlcommon::breadcrumbs('Register Clicker'));
  636:     my $user       = $env{'user.name'};
  637:     my $domain     = $env{'user.domain'};
  638:     my %userenv = &Apache::lonnet::get
  639:         ('environment',['clickers']);
  640:     my $clickers=$userenv{'clickers'};
  641:     $clickers=~s/\,/\n/gs;
  642:     my $text=&mt('Enter response device ("clicker") numbers');
  643:     my $change=&mt('Save');
  644:     my $helplink=&Apache::loncommon::help_open_topic('Clicker_Registration',&mt('Locating your clicker ID'));
  645:     $r->print(<<ENDSCREEN);
  646: <form name="prefs" action="/adm/preferences" method="post">
  647: <input type="hidden" name="action" value="verify_and_change_clicker" />
  648: <label>$helplink<br /><br />$text<br />
  649: <textarea name="clickers" rows="5" cols="20">$clickers</textarea>
  650: </label>
  651: <br />
  652: <input type="submit" value="$change" />
  653: </form>
  654: ENDSCREEN
  655: }
  656: 
  657: sub verify_and_change_clicker {
  658:     my $r = shift;
  659:     my $user       = $env{'user.name'};
  660:     my $domain     = $env{'user.domain'};
  661:     my $newclickers  = $env{'form.clickers'};
  662:     $newclickers=~s/[^\w\:\-]+/\,/gs;
  663:     $newclickers=~tr/a-z/A-Z/;
  664:     $newclickers=~s/[\:\-]+/\-/g;
  665:     $newclickers=~s/\,+/\,/g;
  666:     $newclickers=~s/^\,//;
  667:     $newclickers=~s/\,$//;
  668:     &Apache::lonnet::put('environment',{'clickers' => $newclickers});
  669:     &Apache::lonnet::appenv({'environment.clickers' => $newclickers});
  670:     my $message=&Apache::lonhtmlcommon::confirm_success(&mt('Registering clickers: [_1]',$newclickers));
  671:     $message=&Apache::loncommon::confirmwrapper($message);
  672:     &print_main_menu($r, $message);
  673: }
  674: 
  675: ################################################################
  676: #               Domcoord Access Subroutines                    #
  677: ################################################################
  678: 
  679: sub domcoordchanger {
  680:     my $r = shift;
  681:     &Apache::lonhtmlcommon::add_breadcrumb(
  682: 	    {	href => '/adm/preferences?action=changedomcoord',
  683:                 text => 'Restrict Domain Coordinator Access'});
  684:     $r->print(Apache::loncommon::start_page('Restrict Domain Coordinator Access'));
  685:     $r->print(Apache::lonhtmlcommon::breadcrumbs('Restrict Domain Coordinator Access'));
  686:     my $user       = $env{'user.name'};
  687:     my $domain     = $env{'user.domain'};
  688:     my %userenv = &Apache::lonnet::get
  689:         ('environment',['domcoord.author']);
  690:     my $constchecked='';
  691:     if ($userenv{'domcoord.author'} eq 'blocked') {
  692:        $constchecked='checked="checked"';
  693:     }
  694:     my $text=&mt('By default, the Domain Coordinator can enter your construction space.');
  695:     my $construction=&mt('Block access to construction space');
  696:     my $change=&mt('Save');
  697:     $r->print(<<ENDSCREEN);
  698: <form name="prefs" action="/adm/preferences" method="post">
  699: <input type="hidden" name="action" value="verify_and_change_domcoord" />
  700: $text<br />
  701: <label><input type="checkbox" name="construction" $constchecked />$construction</label><br />
  702: <input type="submit" value="$change" />
  703: </form>
  704: ENDSCREEN
  705: }
  706: 
  707: sub verify_and_change_domcoord {
  708:     my $r = shift;
  709:     my $user       = $env{'user.name'};
  710:     my $domain     = $env{'user.domain'};
  711:     my %domcoord=('domcoord.author' => '');
  712:     if ($env{'form.construction'}) { $domcoord{'domcoord.author'}='blocked'; }
  713:     &Apache::lonnet::put('environment',\%domcoord);
  714:     &Apache::lonnet::appenv({'environment.domcoord.author' => $domcoord{'domcoord.author'}});
  715:     my $status='';
  716:     if ($domcoord{'domcoord.author'} eq 'blocked') {
  717:         $status=&mt('on');
  718:     } else {
  719:         $status=&mt('off');
  720:     }
  721:     my $message=&Apache::lonhtmlcommon::confirm_success(&mt('Set [_1] to [_2]','<i>'.&mt('Block access to construction space').'</i>','<tt>'.$status.'</tt>'));
  722:     $message=&Apache::loncommon::confirmwrapper($message);
  723:     &print_main_menu($r,$message);
  724: }
  725: 
  726: #################################################################
  727: ##                      Lock Subroutines                        #
  728: #################################################################
  729: 
  730: sub lockwarning {
  731:     my $r = shift;
  732:     my $title=&mt('Action locked');
  733:     my $texttop=&mt('LON-CAPA is currently performing the following actions:');
  734:     my $textbottom=&mt('Changing roles or logging out may result in data corruption.');
  735:     my ($num,%which)=&Apache::lonnet::get_locks();
  736:     my $which='';
  737:     foreach my $id (keys %which) {
  738:        $which.='<li>'.$which{$id}.'</li>';
  739:     }
  740:     my $change=&mt('Override');
  741:     $r->print(<<ENDSCREEN);
  742: <form name="prefs" action="/adm/preferences" method="post">
  743: <input type="hidden" name="action" value="verify_and_change_locks" />
  744: <h1>$title</h1>
  745: $texttop
  746: <ul>
  747: $which
  748: </ul>
  749: $textbottom
  750: <input type="submit" value="$change" />
  751: </form>
  752: ENDSCREEN
  753: }
  754: 
  755: sub verify_and_change_lockwarning {
  756:     my $r = shift;
  757:     &Apache::lonnet::remove_all_locks();
  758:     $r->print(&mt('Cleared locks.'));
  759: }
  760: 
  761: 
  762: ################################################################
  763: #         Message Forward                                      #
  764: ################################################################
  765: 
  766: sub msgforwardchanger {
  767:     my ($r,$message) = @_;
  768:     my $user       = $env{'user.name'};
  769:     my $domain     = $env{'user.domain'};
  770:     my %userenv = &Apache::lonnet::get('environment',['msgforward','notification','critnotification','notifywithhtml']);
  771:     my $msgforward=$userenv{'msgforward'};
  772:     my %lt = &Apache::lonlocal::texthash(
  773:                                           all   => 'All',
  774:                                           crit  => 'Critical only',
  775:                                           reg   => 'Non-critical only',
  776:                                           foad  => 'Forwarding Address(es)',
  777:                                           noti  => 'Notification E-mail Address(es)', 
  778:                                           foad_exmpl => 'e.g. <tt>userA:domain1,userB:domain2,...</tt>',
  779:                                           mnot  => 'E-mail Address(es) which should be notified about new LON-CAPA messages',
  780:  # old: 'Message Notification Email Address(es)',
  781:                                           mnot_exmpl => 'e.g. <tt>joe@doe.com</tt>',
  782:                                           chg   => 'Save',
  783:                                           email => 'The e-mail address entered in row ',
  784:                                           notv => 'is not a valid e-mail address',
  785:                                           toen => "To enter multiple addresses, enter one address at a time, click 'Change' and then add the next one", 
  786:                                           prme => 'Back',
  787:                                         );
  788:     Apache::lonhtmlcommon::add_breadcrumb(
  789: 	    {	href => '/adm/preferences?action=changemsgforward',
  790: 		text => 'Change Message Forwarding/Notification'});
  791:     $r->print(Apache::loncommon::start_page('Message Management'));
  792:     $r->print(Apache::lonhtmlcommon::breadcrumbs('Change Message Forwarding/Notification'));
  793:     my $forwardingHelp = &Apache::loncommon::help_open_topic("Prefs_Forwarding");
  794:     my $notificationHelp = &Apache::loncommon::help_open_topic("Prefs_Notification");
  795:     my $criticalMessageHelp = &Apache::loncommon::help_open_topic("Course_Critical_Message");
  796:     my @allow_html = split(/,/,$userenv{'notifywithhtml'});
  797:     my %allnot = &get_notifications(\%userenv);
  798:     my $validatescript = &Apache::lonhtmlcommon::javascript_valid_email();
  799:     my $jscript = qq|
  800: <script type="text/javascript" language="JavaScript">
  801: function validate() {
  802:     for (var i=0; i<document.prefs.numnotify.value; i++) {
  803:         var checkaddress = 0;
  804:         var addr = document.prefs.elements['address_'+i].value;
  805:         var rownum = i+1;
  806:         if (i < document.prefs.numnotify.value-1) {
  807:             if (document.prefs.elements['modify_notify_'+i].checked) {
  808:                 checkaddress = 1;
  809:             }
  810:         } else {
  811:             if (document.prefs.elements['add_notify_'+i].checked == true) { 
  812:                 checkaddress = 1;
  813:             }
  814:         }
  815:         if (checkaddress == 1)  {
  816:             var addr = document.prefs.elements['address_'+i].value;
  817:             if (validmail(document.prefs.elements['address_'+i]) == false) {
  818:                 var multimsg = '';
  819:                 if (addr.indexOf(",") >= 0) {
  820:                     multimsg = "\\n($lt{'toen'}).";
  821:                 }
  822:                 alert("$lt{'email'} "+rownum+" ('"+addr+"') $lt{'notv'}."+multimsg);
  823:                 return;
  824:             }
  825:         }
  826:     }
  827:     document.prefs.submit();
  828: }
  829: 
  830: function address_changes (adnum) {
  831:      if (!document.prefs.elements['del_notify_'+adnum].checked) { 
  832:          document.prefs.elements['modify_notify_'+adnum].checked = true;
  833:      }   
  834: }
  835: 
  836: function new_address(adnum) {
  837:      document.prefs.elements['add_notify_'+adnum].checked = true;
  838: }
  839: 
  840: function delete_address(adnum) {
  841:      if (document.prefs.elements['del_notify_'+adnum].checked) {
  842:           document.prefs.elements['modify_notify_'+adnum].checked = false;
  843:      }
  844: }
  845: 
  846: function modify_address(adnum) {
  847:     if (document.prefs.elements['modify_notify_'+adnum].checked) {
  848:         document.prefs.elements['del_notify_'+adnum].checked = false;
  849:     }
  850: } 
  851: 
  852: $validatescript
  853: </script>
  854: |;
  855:     $r->print(<<ENDMSG);
  856: $jscript
  857: $message
  858: <h3>$lt{'foad'} $forwardingHelp</h3>
  859: <form name="prefs" action="/adm/preferences" method="post">
  860: <input type="hidden" name="action" value="verify_and_change_msgforward" />
  861: $lt{'foad'} ($lt{'foad_exmpl'}):
  862: <input type="text" size="40" value="$msgforward" name="msgforward" /><br />
  863: <h3>$lt{'noti'} $notificationHelp</h3>
  864: $lt{'mnot'} ($lt{'mnot_exmpl'}):<br />
  865: ENDMSG
  866:     my @sortforwards = sort (keys(%allnot));
  867:     my $output = &Apache::loncommon::start_data_table().
  868:                  &Apache::loncommon::start_data_table_header_row().
  869:                  '<th>&nbsp;</th>'.
  870:                  '<th>'.&mt('Action').'</th>'.
  871:                  '<th>'.&mt('Notification address').'</th><th>'.
  872:                  &mt('Types of message for which notification is sent').
  873:                  $criticalMessageHelp.'</th><th>'.
  874:                  &mt('Excerpt retains HTML tags in message').'</th>'.
  875:                  &Apache::loncommon::end_data_table_header_row();
  876:     my $num = 0;
  877:     my $counter = 1;
  878:     foreach my $item (@sortforwards) {
  879:         $output .= &Apache::loncommon::start_data_table_row().
  880:                    '<td><b>'.$counter.'</b></td>'.
  881:                    '<td><span class="LC_nobreak"><label>'.
  882:                    '<input type="checkbox" name="modify_notify_'.
  883:                    $num.'" onclick="javscript:modify_address('."'$num'".')" />'.
  884:                    &mt('Modify').'</label></span>&nbsp;&nbsp; '.
  885:                    '<span class="LC_nobreak"><label>'.
  886:                    '<input type="checkbox" name="del_notify_'.$num.
  887:                    '" onclick="javscript:delete_address('."'$num'".')" />'.
  888:                    &mt('Delete').'</label></span></td>'.
  889:                    '<td><input type="text" value="'.$item.'" name="address_'.
  890:                    $num.'" onFocus="javascript:address_changes('."'$num'".
  891:                    ')" /></td><td>';
  892:         my %chk;
  893:         if (defined($allnot{$item}{'crit'})) {
  894:             if (defined($allnot{$item}{'reg'})) {
  895:                 $chk{'all'} = 'checked="checked" ';
  896:             } else {
  897:                 $chk{'crit'} = 'checked="checked" ';
  898:             }
  899:         } else {
  900:             $chk{'reg'} = 'checked="checked" ';
  901:         }
  902:         foreach my $type ('all','crit','reg') {
  903:             $output .= '<span class="LC_nobreak"><label>'.
  904:                        '<input type="radio" name="notify_type_'.$num. 
  905:                        '" value="'.$type.'" '.$chk{$type}.
  906:                        ' onchange="javascript:address_changes('."'$num'".')" />'.
  907:                        $lt{$type}.'</label></span>&nbsp;';
  908:         }
  909:         my $htmlon = '';
  910:         my $htmloff = '';
  911:         if (grep/^\Q$item\E/,@allow_html) {
  912:             $htmlon = 'checked="checked" '; 
  913:         } else {
  914:             $htmloff = 'checked="checked" ';
  915:         }
  916:         $output .= '</td><td><label><input type="radio" name="html_'.$num.
  917:                    '" value="1" '.$htmlon.
  918:                    ' onchange="javascript:address_changes('."'$num'".')" />'.
  919:                    &mt('Yes').'</label>&nbsp;'.
  920:                    '<label><input type="radio" name="html_'.$num.'" value="0" '.
  921:                    $htmloff. ' onchange="javascript:address_changes('."'$num'".
  922: ')" />'.
  923:                    &mt('No').'</label></td>'.
  924:                    &Apache::loncommon::end_data_table_row();
  925:         $num ++;
  926:         $counter ++;
  927:     }
  928:     my %defchk = (
  929:                    all => 'checked="checked" ',
  930:                    crit => '',
  931:                    reg => '',
  932:                  );
  933:     $output .= &Apache::loncommon::start_data_table_row().
  934:                '<td><b>'.$counter.'</b></td>'.
  935:                '<td><span class="LC_nobreak"><label>'.
  936:                '<input type="checkbox" name="add_notify_'.$num.
  937:                '" value="1" />'.&mt('Add new address').'</label></span></td>'.
  938:                '<td><input type="text" value="" name="address_'.$num.
  939:                '" onFocus="javascript:new_address('."'$num'".')" /></td><td>';
  940:     foreach my $type ('all','crit','reg') {
  941:         $output .= '<span class="LC_nobreak"><label>'.
  942:                    '<input type="radio" name="notify_type_'.$num.
  943:                    '" value="'.$type.'" '.$defchk{$type}.'/>'.
  944:                    $lt{$type}.'</label></span>&nbsp;';
  945:     }
  946:     $output .= '</td><td><label><input type="radio" name="html_'.$num.
  947:                '" value="1" />'.&mt('Yes').'</label>&nbsp;'.
  948:                '<label><input type="radio" name="html_'.$num.'" value="0" '.
  949:                ' checked="checked" />'.
  950:                &mt('No').'</label></td>'.
  951:                &Apache::loncommon::end_data_table_row().
  952:                &Apache::loncommon::end_data_table();
  953:     $num ++;
  954:     $r->print($output);
  955:     $r->print(qq|
  956: <br /><hr />
  957: <input type="hidden" name="numnotify" value="$num" />
  958: <input type="button" value="$lt{'prme'}" onclick="location.href='/adm/preferences'" />
  959: <input type="button" value="$lt{'chg'}" onclick="javascript:validate()" />
  960: </form>
  961: |);
  962: 
  963: }
  964: 
  965: sub get_notifications {
  966:     my ($userenv) = @_;
  967:     my %allnot;
  968:     my @critnot = split(/,/,$userenv->{'critnotification'});
  969:     my @regnot = split(/,/,$userenv->{'notification'});
  970:     foreach my $item (@critnot) {
  971:         $allnot{$item}{crit} = 1;
  972:     }
  973:     foreach my $item (@regnot) {
  974:         $allnot{$item}{reg} = 1;
  975:     }
  976:     return %allnot;
  977: }
  978: 
  979: sub verify_and_change_msgforward {
  980:     my $r = shift;
  981:     my $user       = $env{'user.name'};
  982:     my $domain     = $env{'user.domain'};
  983:     my $newscreen  = '';
  984:     my $message='';
  985:     foreach (split(/\,/,$env{'form.msgforward'})) {
  986: 	my ($msuser,$msdomain)=split(/[\@\:]/,$_);
  987:         $msuser = &LONCAPA::clean_username($msuser);
  988:         $msdomain = &LONCAPA::clean_domain($msdomain);
  989:         if (($msuser) && ($msdomain)) {
  990: 	    if (&Apache::lonnet::homeserver($msuser,$msdomain) ne 'no_host') {
  991:                $newscreen.=$msuser.':'.$msdomain.',';
  992: 	   } else {
  993:                $message.= &mt('No such user: ').'<tt>'.$msuser.':'.$msdomain.'</tt><br>';
  994:            }
  995:         }
  996:     }
  997:     $newscreen=~s/\,$//;
  998:     if ($newscreen) {
  999:         &Apache::lonnet::put('environment',{'msgforward' => $newscreen});
 1000:         &Apache::lonnet::appenv({'environment.msgforward' => $newscreen});
 1001:         $message .= &mt('Set message forwarding to ').'<tt>"'.$newscreen.'"</tt>.'
 1002:                     .'<br />';
 1003:     } else {
 1004:         &Apache::lonnet::del('environment',['msgforward']);
 1005:         &Apache::lonnet::delenv('environment.msgforward');
 1006:         $message.= &mt("Set message forwarding to 'off'.").'<br />';
 1007:     }
 1008:     my $critnotification;
 1009:     my $notification;
 1010:     my $notify_with_html;
 1011:     my $lastnotify = $env{'form.numnotify'}-1;
 1012:     my $totaladdresses = 0;
 1013:     for (my $i=0; $i<$env{'form.numnotify'}; $i++) {
 1014:         if ((!defined($env{'form.del_notify_'.$i})) &&  
 1015:            ((($i==$lastnotify) && ($env{'form.add_notify_'.$lastnotify} == 1)) ||
 1016:             ($i<$lastnotify))) {
 1017:             if (defined($env{'form.address_'.$i})) {
 1018:                 if ($env{'form.notify_type_'.$i} eq 'all') {
 1019:                     $critnotification .= $env{'form.address_'.$i}.',';
 1020:                     $notification .= $env{'form.address_'.$i}.',';
 1021:                 } elsif ($env{'form.notify_type_'.$i} eq 'crit') {
 1022:                     $critnotification .= $env{'form.address_'.$i}.',';
 1023:                 } elsif ($env{'form.notify_type_'.$i} eq 'reg') {
 1024:                     $notification .= $env{'form.address_'.$i}.','; 
 1025:                 }
 1026:                 if ($env{'form.html_'.$i} eq '1') {
 1027: 		    $notify_with_html .= $env{'form.address_'.$i}.',';       	
 1028:                 }
 1029:                 $totaladdresses ++;
 1030:             }
 1031:         }
 1032:     }
 1033:     $critnotification =~ s/,$//;
 1034:     $critnotification=~s/\s//gs;
 1035:     $notification =~ s/,$//;
 1036:     $notification=~s/\s//gs;
 1037:     $notify_with_html =~ s/,$//;
 1038:     $notify_with_html =~ s/\s//gs;
 1039:     if ($notification) {
 1040:         &Apache::lonnet::put('environment',{'notification' => $notification});
 1041:         &Apache::lonnet::appenv({'environment.notification' => $notification});
 1042:         $message.=&mt('Set non-critical message notification address(es) to ').'<tt>"'.$notification.'"</tt>.<br />';
 1043:     } else {
 1044:         &Apache::lonnet::del('environment',['notification']);
 1045:         &Apache::lonnet::delenv('environment.notification');
 1046:         $message.=&mt("Set non-critical message notification to 'off'.").'<br />';
 1047:     }
 1048:     if ($critnotification) {
 1049:         &Apache::lonnet::put('environment',{'critnotification' => $critnotification});
 1050:         &Apache::lonnet::appenv({'environment.critnotification' => $critnotification});
 1051:         $message.=&mt('Set critical message notification address(es) to ').'<tt>"'.$critnotification.'"</tt>.<br />';
 1052:     } else {
 1053:         &Apache::lonnet::del('environment',['critnotification']);
 1054:         &Apache::lonnet::delenv('environment.critnotification');
 1055:         $message.=&mt("Set critical message notification to 'off'.").'<br />';
 1056:     }
 1057:     if ($critnotification || $notification) {
 1058:         if ($notify_with_html) {
 1059:             &Apache::lonnet::put('environment',{'notifywithhtml' => $notify_with_html});
 1060:             &Apache::lonnet::appenv({'environment.notifywithhtml' => $notify_with_html});
 1061:             $message.=&mt('Set address(es) to receive excerpts with html retained ').'<tt>"'.$notify_with_html.'"</tt>.';
 1062:         } else {
 1063:             &Apache::lonnet::del('environment',['notifywithhtml']);
 1064:             &Apache::lonnet::delenv('environment.notifywithhtml');
 1065:             if ($totaladdresses == 1) {
 1066:                 $message.=&mt("Set notification address to receive excerpts with html stripped.");
 1067:             } else {
 1068:                 $message.=&mt("Set all notification addresses to receive excerpts with html stripped.");
 1069:             }
 1070:         }
 1071:     } else {
 1072:         &Apache::lonnet::del('environment',['notifywithhtml']);
 1073:         &Apache::lonnet::delenv('environment.notifywithhtml');
 1074:     }
 1075:     if ($message) {
 1076:         $message .= '<br /><hr />';
 1077:     }
 1078:     &Apache::loncommon::flush_email_cache($user,$domain);
 1079:     &msgforwardchanger($r,$message);
 1080: }
 1081: 
 1082: ################################################################
 1083: #         Colors                                               #
 1084: ################################################################
 1085: 
 1086: sub colorschanger {
 1087:     my $r = shift;
 1088:     Apache::lonhtmlcommon::add_breadcrumb(
 1089: 	    {	href => '/adm/preferences?action=changecolors',
 1090:                 text => 'Change Colors'});
 1091:     $r->print(Apache::loncommon::start_page('Page Display Settings'));
 1092:     $r->print(Apache::lonhtmlcommon::breadcrumbs('Change Colors'));
 1093: # figure out colors
 1094:     my $function=&Apache::loncommon::get_users_function();
 1095:     my $domain=&Apache::loncommon::determinedomain();
 1096:     my %colortypes=&Apache::lonlocal::texthash(
 1097:         'pgbg'     => 'Page Background Color',
 1098:         'tabbg'    => 'Header Background Color',
 1099:         'sidebg'   => 'Header Border Color',
 1100:         'font'     => 'Font Color',
 1101:         'fontmenu' => 'Font Menu Color',
 1102:         'link'     => 'Un-Visited Link Color',
 1103:         'vlink'    => 'Visited Link Color',
 1104:         'alink'    => 'Active Link Color',
 1105:     );
 1106:     my $start_data_table = &Apache::loncommon::start_data_table();
 1107:     my $chtable='';
 1108:     foreach my $item (sort(keys(%colortypes))) {
 1109:        my $curcol=&Apache::loncommon::designparm($function.'.'.$item,$domain);
 1110:        $chtable.=&Apache::loncommon::start_data_table_row().
 1111: 	   '<td>'.$colortypes{$item}.'</td><td style="background: '.$curcol.
 1112:         '">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</td><td><input name="'.$item.
 1113:         '" size="10" value="'.$curcol.
 1114: '" /></td><td><a href="javascript:pjump('."'color_custom','".$colortypes{$item}.
 1115: "','".$curcol."','"
 1116: 	    .$item."','parmform.pres','psub'".');">'.&mt('Select').'</a></td>'.
 1117: 	    &Apache::loncommon::end_data_table_row()."\n";
 1118:     }
 1119:     my $end_data_table = &Apache::loncommon::end_data_table();
 1120:     my $pjump_def = &Apache::lonhtmlcommon::pjump_javascript_definition();
 1121:     my $savebutton = &mt('Save');
 1122:     my $resetbutton = &mt('Reset All');
 1123:     my $resetbuttondesc = &mt('Reset All Colors to Default');
 1124:     $r->print(<<ENDCOL);
 1125: <script type="text/javascript" language="JavaScript">
 1126: 
 1127:     function pclose() {
 1128:         parmwin=window.open("/adm/rat/empty.html","LONCAPAparms",
 1129:                  "height=350,width=350,scrollbars=no,menubar=no");
 1130:         parmwin.close();
 1131:     }
 1132: 
 1133:     $pjump_def
 1134: 
 1135:     function psub() {
 1136:         pclose();
 1137:         if (document.parmform.pres_marker.value!='') {
 1138:             if (document.parmform.pres_type.value!='') {
 1139:                 eval('document.prefs.'+
 1140:                      document.parmform.pres_marker.value+
 1141: 		     '.value=document.parmform.pres_value.value;');
 1142: 	    }
 1143:         } else {
 1144:             document.parmform.pres_value.value='';
 1145:             document.parmform.pres_marker.value='';
 1146:         }
 1147:     }
 1148: 
 1149: 
 1150: </script>
 1151: <form name="parmform">
 1152: <input type="hidden" name="pres_marker" />
 1153: <input type="hidden" name="pres_type" />
 1154: <input type="hidden" name="pres_value" />
 1155: </form>
 1156: <form name="prefs" action="/adm/preferences" method="post">
 1157: <input type="hidden" name="action" value="verify_and_change_colors" />
 1158: $start_data_table
 1159: $chtable
 1160: $end_data_table
 1161: </table>
 1162: <p>
 1163: <input type="submit" value="$savebutton" />
 1164: <input type="submit" name="resetall" value="$resetbutton" title="$resetbuttondesc" />
 1165: </p>
 1166: </form>
 1167: ENDCOL
 1168: }
 1169: 
 1170: sub verify_and_change_colors {
 1171:     my $r = shift;
 1172: # figure out colors
 1173:     my $function=&Apache::loncommon::get_users_function();
 1174:     my $domain=&Apache::loncommon::determinedomain();
 1175:     my %colortypes=&Apache::lonlocal::texthash(
 1176:         'pgbg'     => 'Page Background Color',
 1177:         'tabbg'    => 'Header Background Color',
 1178:         'sidebg'   => 'Header Border Color',
 1179:         'font'     => 'Font Color',
 1180: 	'fontmenu' => 'Font Menu Color',
 1181:         'link'     => 'Un-Visited Link Color',
 1182:         'vlink'    => 'Visited Link Color',
 1183:         'alink'    => 'Active Link Color',
 1184:     );
 1185: 
 1186:     my $message='';
 1187:     foreach my $item (keys %colortypes) {
 1188:         my $color=$env{'form.'.$item};
 1189:         my $entry='color.'.$function.'.'.$item;
 1190: 	if (($color=~/^\#[0-9A-Fa-f]{6}$/) && (!$env{'form.resetall'})) {
 1191: 	    &Apache::lonnet::put('environment',{$entry => $color});
 1192: 	    &Apache::lonnet::appenv({'environment.'.$entry => $color});
 1193:             $message.=&Apache::lonhtmlcommon::confirm_success(&mt('Set [_1] to [_2]','<i>'.$colortypes{$item}.'</i>','<tt>"'.$color.'"</tt>'))
 1194:                     .'<br />';
 1195: 	} else {
 1196: 	    &Apache::lonnet::del('environment',[$entry]);
 1197: 	    &Apache::lonnet::delenv('environment.'.$entry);
 1198:             $message.=&Apache::lonhtmlcommon::confirm_success(&mt('Reset [_1]','<i>'.$colortypes{$item}.'</i>'))
 1199:                      .'<br />';
 1200: 	}
 1201:     }
 1202:     $message=&Apache::loncommon::confirmwrapper($message);
 1203: 
 1204:     my $now = time;
 1205:     &Apache::lonnet::put('environment',{'color.timestamp' => $now});
 1206:     &Apache::lonnet::appenv({'environment.color.timestamp' => $now});
 1207: 
 1208:     &print_main_menu($r, $message);
 1209: }
 1210: 
 1211: ######################################################
 1212: #            password handler subroutines            #
 1213: ######################################################
 1214: sub passwordchanger {
 1215:     my ($r,$errormessage,$caller,$mailtoken) = @_;
 1216:     # This function is a bit of a mess....
 1217:     # Passwords are encrypted using londes.js (DES encryption)
 1218:     $errormessage = ($errormessage || '');
 1219:     my ($user,$domain,$currentpass,$defdom);
 1220:     &Apache::lonhtmlcommon::add_breadcrumb(
 1221: 		{ href => '/adm/preferences?action=changepass',
 1222:                   text => 'Change Password'});
 1223:     unless ($caller eq 'reset_by_email') {
 1224:         $r->print(Apache::loncommon::start_page('Personal Data'));
 1225:         $r->print(Apache::lonhtmlcommon::breadcrumbs('Change Password'));
 1226:     }
 1227:     if ((!defined($caller)) || ($caller eq 'preferences')) {
 1228:         $user = $env{'user.name'};
 1229:         $domain = $env{'user.domain'};
 1230:         if (!defined($caller)) {
 1231:             $caller = 'preferences';
 1232:         }
 1233:     } elsif ($caller eq 'reset_by_email') {
 1234:             $defdom = $r->dir_config('lonDefDomain');
 1235:             my %data = &Apache::lonnet::tmpget($mailtoken);
 1236:             if (keys(%data) == 0) {
 1237:                 $r->print(&mt('Sorry, the URL you provided to complete the reset of your password was invalid. Either the token included in the URL has been deleted or the URL you provided was invalid. Please submit a [_1]new request[_2] for a password reset, and follow the link to the new URL included in the e-mail that will be sent to you, to allow you to enter a new password.'
 1238:                              ,'<a href="/adm/resetpw">','</a>')
 1239:                 );
 1240:                 return;
 1241:             }
 1242:             if (defined($data{time})) {
 1243:                 if (time - $data{'time'} < 7200) {
 1244:                     $user = $data{'username'};
 1245:                     $domain = $data{'domain'};
 1246:                     $currentpass = $data{'temppasswd'};
 1247:                 } else {
 1248:                     $r->print(&mt('Sorry, the token generated when you requested a password reset has expired.').'<br />');
 1249:                     return;
 1250:                 }
 1251:             } else {
 1252:                 $r->print(&mt('Sorry, the URL generated when you requested reset of your password contained incomplete information.').'<br />');
 1253:                 return;
 1254:             }
 1255:    } else {
 1256:         $r->print(&mt('Page requested in unexpected context').'<br />');
 1257:         return;
 1258:     }
 1259:     my $currentauth=&Apache::lonnet::queryauthenticate($user,$domain);
 1260:     # Check for authentication types that allow changing of the password.
 1261:     return if ($currentauth !~ /^(unix|internal):/);
 1262:     #
 1263:     # Generate keys
 1264:     my ($lkey_cpass ,$ukey_cpass ) = &des_keys();
 1265:     my ($lkey_npass1,$ukey_npass1) = &des_keys();
 1266:     my ($lkey_npass2,$ukey_npass2) = &des_keys();
 1267:     # Store the keys in the log files
 1268:     my $lonhost = $r->dir_config('lonHostID');
 1269:     my $logtoken=Apache::lonnet::reply('tmpput:'
 1270: 				       .$ukey_cpass  . $lkey_cpass .'&'
 1271: 				       .$ukey_npass1 . $lkey_npass1.'&'
 1272: 				       .$ukey_npass2 . $lkey_npass2,
 1273: 				       $lonhost);
 1274:     # Hexify the keys for output as javascript variables
 1275:     my %hexkey;
 1276:     $hexkey{'ukey_cpass'}  = hex($ukey_cpass);
 1277:     $hexkey{'lkey_cpass'}  = hex($lkey_cpass);
 1278:     $hexkey{'ukey_npass1'} = hex($ukey_npass1);
 1279:     $hexkey{'lkey_npass1'} = hex($lkey_npass1);
 1280:     $hexkey{'ukey_npass2'} = hex($ukey_npass2);
 1281:     $hexkey{'lkey_npass2'} = hex($lkey_npass2);
 1282:     # Output javascript to deal with passwords
 1283:     # Output DES javascript
 1284:     {
 1285: 	my $include = $r->dir_config('lonIncludes');
 1286: 	my $jsh=Apache::File->new($include."/londes.js");
 1287: 	$r->print(<$jsh>);
 1288:     }
 1289:     $r->print(&jscript_send($caller));
 1290:     $r->print(<<ENDFORM);
 1291: $errormessage
 1292: 
 1293: <p>
 1294: <!-- We separate the forms into 'server' and 'client' in order to
 1295:      ensure that unencrypted passwords will not be sent out by a
 1296:      crappy browser -->
 1297: ENDFORM
 1298:     $r->print(&server_form($logtoken,$caller,$mailtoken));
 1299:     $r->print(&client_form($caller,\%hexkey,$currentpass,$defdom));
 1300: 
 1301:     #
 1302:     return;
 1303: }
 1304: 
 1305: sub jscript_send {
 1306:     my ($caller) = @_;
 1307:     my $output = qq|
 1308: <script type="text/javascript" language="JavaScript">
 1309: 
 1310:     function send() {
 1311:         uextkey=this.document.client.elements.ukey_cpass.value;
 1312:         lextkey=this.document.client.elements.lkey_cpass.value;
 1313:         initkeys();
 1314: 
 1315:         this.document.pserver.elements.currentpass.value
 1316:             =crypted(this.document.client.elements.currentpass.value);
 1317: 
 1318:         uextkey=this.document.client.elements.ukey_npass1.value;
 1319:         lextkey=this.document.client.elements.lkey_npass1.value;
 1320:         initkeys();
 1321:         this.document.pserver.elements.newpass_1.value
 1322:             =crypted(this.document.client.elements.newpass_1.value);
 1323: 
 1324:         uextkey=this.document.client.elements.ukey_npass2.value;
 1325:         lextkey=this.document.client.elements.lkey_npass2.value;
 1326:         initkeys();
 1327:         this.document.pserver.elements.newpass_2.value
 1328:             =crypted(this.document.client.elements.newpass_2.value);
 1329: |;
 1330:     if ($caller eq 'reset_by_email') {
 1331:         $output .= qq|
 1332:         this.document.pserver.elements.uname.value =
 1333:                    this.document.client.elements.uname.value;
 1334:         this.document.pserver.elements.udom.value =
 1335:                    this.document.client.elements.udom.options[this.document.client.elements.udom.selectedIndex].value;
 1336: |;
 1337:     }
 1338:     $ output .= qq|
 1339:         this.document.pserver.submit();
 1340:     }
 1341: </script>
 1342: |;
 1343: }
 1344: 
 1345: sub client_form {
 1346:     my ($caller,$hexkey,$currentpass,$defdom) = @_;
 1347:     my %lt=&Apache::lonlocal::texthash(
 1348:                 'email' => 'E-mail Address',
 1349:                 'username' => 'Username',
 1350:                 'domain' => 'Domain',
 1351:                 'currentpass' => 'Current Password',
 1352:                 'newpass' => 'New Password',
 1353:                 'confirmpass' => 'Confirm Password',
 1354:                 'changepass' => 'Save');
 1355: 
 1356:     my $output = qq|
 1357: <form name="client" >
 1358: <table>
 1359: |;
 1360:     if ($caller eq 'reset_by_email') {
 1361:         $output .= qq|
 1362: <tr><td class="LC_preferences_labeltext"><label for="email">$lt{'email'}</label>:</td>
 1363:     <td><input type="text" name="email" size="30" /> </td></tr>
 1364: <tr><td class="LC_preferences_labeltext"><label for="uname">$lt{'username'}</label>:</td>
 1365:     <td>
 1366:      <input type="text" name="uname" size="15" />
 1367:      <input type="hidden" name="currentpass" value="$currentpass" />
 1368:     </td></tr>
 1369: <tr><td class="LC_preferences_labeltext"><label for="udom">$lt{'domain'}</label>:</td>
 1370:     <td>
 1371: |;
 1372:         $output .= &Apache::loncommon::select_dom_form($defdom,'udom').'
 1373:    </td>
 1374: </tr>
 1375: ';
 1376:     } else {
 1377:         $output .= qq|
 1378: <tr><td class="LC_preferences_labeltext"><label for="currentpass">$lt{'currentpass'}</label></td>
 1379:     <td><input type="password" name="currentpass" size="10"/> </td></tr>
 1380: |;
 1381:     }
 1382:     $output .= <<"ENDFORM";
 1383: <tr><td class="LC_preferences_labeltext"><label for="newpass_1">$lt{'newpass'}</label></td>
 1384:     <td><input type="password" name="newpass_1" size="10"  /> </td></tr>
 1385: <tr><td class="LC_preferences_labeltext"><label for="newpass_2">$lt{'confirmpass'}</label></td>
 1386:     <td><input type="password" name="newpass_2" size="10"  /> </td></tr>
 1387: <tr><td colspan="2" align="center">
 1388:     <input type="button" value="$lt{'changepass'}" onClick="send();" />
 1389: </table>
 1390: <input type="hidden" name="ukey_cpass"  value="$hexkey->{'ukey_cpass'}" />
 1391: <input type="hidden" name="lkey_cpass"  value="$hexkey->{'lkey_cpass'}" />
 1392: <input type="hidden" name="ukey_npass1" value="$hexkey->{'ukey_npass1'}" />
 1393: <input type="hidden" name="lkey_npass1" value="$hexkey->{'lkey_npass1'}" />
 1394: <input type="hidden" name="ukey_npass2" value="$hexkey->{'ukey_npass2'}" />
 1395: <input type="hidden" name="lkey_npass2" value="$hexkey->{'lkey_npass2'}" />
 1396: </form>
 1397: </p>
 1398: ENDFORM
 1399:     return $output;
 1400: }
 1401: 
 1402: sub server_form {
 1403:     my ($logtoken,$caller,$mailtoken) = @_;
 1404:     my $action = '/adm/preferences';
 1405:     if ($caller eq 'reset_by_email') {
 1406:         $action = '/adm/resetpw';
 1407:     }
 1408:     my $output = qq|
 1409: <form name="pserver" action="$action" method="post">
 1410: <input type="hidden" name="logtoken"    value="$logtoken" />
 1411: <input type="hidden" name="currentpass" value="" />
 1412: <input type="hidden" name="newpass_1"   value="" />
 1413: <input type="hidden" name="newpass_2"   value="" />
 1414:     |;
 1415:     if ($caller eq 'reset_by_email') {
 1416:         $output .=  qq|
 1417: <input type="hidden" name="token"   value="$mailtoken" />
 1418: <input type="hidden" name="uname"   value="" />
 1419: <input type="hidden" name="udom"   value="" />
 1420: 
 1421: |;
 1422:     }
 1423:     $output .= qq|
 1424: <input type="hidden" name="action" value="verify_and_change_pass" />
 1425: </form>
 1426: |;
 1427:     return $output;
 1428: }
 1429: 
 1430: sub verify_and_change_password {
 1431:     my ($r,$caller,$mailtoken) = @_;
 1432:     my ($user,$domain,$homeserver);
 1433:     if ($caller eq 'reset_by_email') {
 1434:         $user       = $env{'form.uname'};
 1435:         $domain     = $env{'form.udom'};
 1436:         if ($user ne '' && $domain ne '') {
 1437:             $homeserver = &Apache::lonnet::homeserver($user,$domain);
 1438:             if ($homeserver eq 'no_host') {
 1439:         &passwordchanger($r,"<p>\n<span class='LC_error'>".
 1440:                          &mt("Invalid username and/or domain")."</span>\n</p>",
 1441:                          $caller,$mailtoken);
 1442:                 return 1;
 1443:             }
 1444:         } else {
 1445:             &passwordchanger($r,"<p>\n<span class='LC_error'>".
 1446:                              &mt("Username and domain were blank")."</span>\n</p>",
 1447:                              $caller,$mailtoken);
 1448:             return 1;
 1449:         }
 1450:     } else {
 1451:         $user       = $env{'user.name'};
 1452:         $domain     = $env{'user.domain'};
 1453:         $homeserver = $env{'user.home'};
 1454:     }
 1455:     my $currentauth=&Apache::lonnet::queryauthenticate($user,$domain);
 1456:     # Check for authentication types that allow changing of the password.
 1457:     if ($currentauth !~ /^(unix|internal):/) {
 1458:         if ($caller eq 'reset_by_email') {
 1459:             &passwordchanger($r,"<p>\n<span class='LC_error'>".
 1460:                              &mt("Authentication type for this user can not be changed by this mechanism").
 1461:                              "</span>\n</p>",
 1462:                               $caller,$mailtoken);
 1463:             return 1;
 1464:         } else {
 1465:             return;
 1466:         }
 1467:     }
 1468:     #
 1469:     my $currentpass = $env{'form.currentpass'}; 
 1470:     my $newpass1    = $env{'form.newpass_1'}; 
 1471:     my $newpass2    = $env{'form.newpass_2'};
 1472:     my $logtoken    = $env{'form.logtoken'};
 1473:     # Check for empty data 
 1474:     unless (defined($currentpass) && 
 1475: 	    defined($newpass1)    && 
 1476: 	    defined($newpass2)    ){
 1477: 	&passwordchanger($r,"<p>\n<span class='LC_error'>".
 1478: 			 &mt("One or more password fields were blank").
 1479:                          "</span>\n</p>",$caller,$mailtoken);
 1480: 	return;
 1481:     }
 1482:     # Get the keys
 1483:     my $lonhost = $r->dir_config('lonHostID');
 1484:     my $tmpinfo = Apache::lonnet::reply('tmpget:'.$logtoken,$lonhost);
 1485:     if (($tmpinfo=~/^error/) || ($tmpinfo eq 'con_lost')) {
 1486:         # I do not a have a better idea about how to handle this
 1487:         my $tryagain_text = &mt('Please log out and try again.');
 1488:         if ($caller eq 'reset_by_email') {
 1489:             $tryagain_text = &mt('Please try again later.');
 1490:         }
 1491:         my $unable=&mt("Unable to retrieve saved token for password decryption");
 1492: 	$r->print(<<ENDERROR);
 1493: <p>
 1494: <span class="LC_error">$unable.  $tryagain_text</span>
 1495: </p>
 1496: ENDERROR
 1497:         # Probably should log an error here
 1498:         return 1;
 1499:     }
 1500:     my ($ckey,$n1key,$n2key)=split(/&/,$tmpinfo);
 1501:     # 
 1502:     $currentpass = &des_decrypt($ckey ,$currentpass);
 1503:     $newpass1    = &des_decrypt($n1key,$newpass1);
 1504:     $newpass2    = &des_decrypt($n2key,$newpass2);
 1505:     #
 1506:     if ($caller eq 'reset_by_email') {
 1507:         my %data = &Apache::lonnet::tmpget($mailtoken);
 1508:         if (keys(%data) == 0) {
 1509:             &passwordchanger($r,
 1510:                          '<span class="LC_error">'.
 1511:                          &mt('Could not verify current authentication.').'  '.
 1512:                          &mt('Please try again.').'</span>',$caller,$mailtoken);
 1513:             return 1;
 1514:         }
 1515:         if ($currentpass ne $data{'temppasswd'}) {
 1516:             &passwordchanger($r,
 1517:                          '<span class="LC_error">'.
 1518:                          &mt('Could not verify current authentication.').'  '.
 1519:                          &mt('Please try again.').'</span>',$caller,$mailtoken);
 1520:             return 1;
 1521:         }
 1522:     } 
 1523:     if ($newpass1 ne $newpass2) {
 1524: 	&passwordchanger($r,
 1525: 			 '<span class="LC_error">'.
 1526: 			 &mt('The new passwords you entered do not match.').'  '.
 1527: 			 &mt('Please try again.').'</span>',$caller,$mailtoken);
 1528: 	return 1;
 1529:     }
 1530:     if (length($newpass1) < 7) {
 1531: 	&passwordchanger($r,
 1532: 			 '<span class="LC_error">'.
 1533: 			 &mt('Passwords must be a minimum of 7 characters long.').'  '.
 1534: 			 &mt('Please try again.').'</span>',$caller,$mailtoken);
 1535: 	return 1;
 1536:     }
 1537:     #
 1538:     # Check for bad characters
 1539:     my $badpassword = 0;
 1540:     foreach (split(//,$newpass1)) {
 1541: 	$badpassword = 1 if ((ord($_)<32)||(ord($_)>126));
 1542:     }
 1543:     if ($badpassword) {
 1544: 	# I can't figure out how to enter bad characters on my browser.
 1545: 	my $errormessage ='<span class="LC_error">'.
 1546:            &mt('The password you entered contained illegal characters.').'<br />'.
 1547:            &mt('Valid characters are').(<<"ENDERROR");
 1548: : space and <br />
 1549: <pre>
 1550: !&quot;\#$%&amp;\'()*+,-./0123456789:;&lt;=&gt;?\@
 1551: ABCDEFGHIJKLMNOPQRSTUVWXYZ[\]^_\`abcdefghijklmnopqrstuvwxyz{|}~
 1552: </pre></span>
 1553: ENDERROR
 1554:         &passwordchanger($r,$errormessage,$caller,$mailtoken);
 1555:         return 1;
 1556:     }
 1557:     # 
 1558:     # Change the password (finally)
 1559:     my $result = &Apache::lonnet::changepass
 1560: 	($user,$domain,$currentpass,$newpass1,$homeserver,$caller);
 1561:     # Inform the user the password has (not?) been changed
 1562:     my $message;
 1563:     if ($result =~ /^ok$/) {
 1564:         $message = &Apache::lonhtmlcommon::confirm_success(&mt('The password for user [_1] was successfully changed.','<i>'.$user.'<i>'));
 1565:         if ($caller eq 'reset_by_email') {
 1566:             $r->print($message.'<br />');
 1567:         } else {
 1568:             &print_main_menu($r, $message);
 1569:         }
 1570:     } else {
 1571: 	# error error: run in circles, scream and shout
 1572:         $message = &Apache::lonhtmlcommon::confirm_success(
 1573:           &mt("The password for user [_1] was not changed.",'<i>'.$user.'</i>').' '.&mt('Please make sure your old password was entered correctly.'),1);
 1574:         unless ($caller eq 'reset_by_email') {
 1575:             $message=&Apache::loncommon::confirmwrapper($message);
 1576:             &print_main_menu($r, $message);
 1577:         }
 1578:         return 1;
 1579:     }
 1580:     return;
 1581: }
 1582: 
 1583: ################################################################
 1584: #            discussion display subroutines 
 1585: ################################################################
 1586: sub discussionchanger {
 1587:     my $r = shift;
 1588:     Apache::lonhtmlcommon::add_breadcrumb(
 1589: 	    {	href => '/adm/preferences?action=changediscussions',
 1590:                 text => 'Change Discussion Preferences'});
 1591:     $r->print(Apache::loncommon::start_page('Message Management'));
 1592:     $r->print(Apache::lonhtmlcommon::breadcrumbs('Change Discussion Preferences'));
 1593:     my $user       = $env{'user.name'};
 1594:     my $domain     = $env{'user.domain'};
 1595:     my %userenv = &Apache::lonnet::get
 1596:         ('environment',['discdisplay','discmarkread']);
 1597:     my $discdisp = 'allposts';
 1598:     my $discmark = 'onmark';
 1599: 
 1600:     if (defined($userenv{'discdisplay'})) {
 1601:         unless ($userenv{'discdisplay'} eq '') { 
 1602:             $discdisp = $userenv{'discdisplay'};
 1603:         }
 1604:     }
 1605:     if (defined($userenv{'discmarkread'})) {
 1606:         unless ($userenv{'discdisplay'} eq '') { 
 1607:             $discmark = $userenv{'discmarkread'};
 1608:         }
 1609:     }
 1610: 
 1611:     my $newdisp = 'unread';
 1612:     my $newmark = 'ondisp';
 1613: 
 1614:     my $function = &Apache::loncommon::get_users_function();
 1615:     my $color = &Apache::loncommon::designparm($function.'.tabbg',
 1616:                                                     $env{'user.domain'});
 1617:     my %lt = &Apache::lonlocal::texthash(
 1618:         'pref' => 'Display Preference',
 1619:         'curr' => 'Current setting ',
 1620:         'actn' => 'Action',
 1621:         'sdpf' => 'Set display preferences for discussion posts for both discussion boards and individual resources in all your courses.',
 1622:         'prca' => 'Preferences can be set that determine',
 1623:         'whpo' => 'Which posts are displayed when you display a discussion board or resource, and',
 1624:         'unwh' => 'Under what circumstances posts are identfied as "New"',
 1625:         'allposts' => 'All posts',
 1626:         'unread' => 'New posts only',
 1627:         'ondisp' => 'Once displayed',
 1628:         'onmark' => 'Once marked as read',
 1629:         'disa' => 'Posts displayed?',
 1630:         'npmr' => 'New posts cease to be identified as "New"?',
 1631:         'thde'  => 'The preferences you set here can be overridden within each individual discussion.',
 1632:         'chgt' => 'Change to '
 1633:     );
 1634:     my $dispchange = $lt{'unread'};
 1635:     my $markchange = $lt{'ondisp'};
 1636:     my $currdisp = $lt{'allposts'};
 1637:     my $currmark = $lt{'onmark'};
 1638: 
 1639:     if ($discdisp eq 'unread') {
 1640:         $dispchange = $lt{'allposts'};
 1641:         $currdisp = $lt{'unread'};
 1642:         $newdisp = 'allposts';
 1643:     }
 1644: 
 1645:     if ($discmark eq 'ondisp') {
 1646:         $markchange = $lt{'onmark'};
 1647:         $currmark = $lt{'ondisp'};
 1648:         $newmark = 'onmark';
 1649:     }
 1650:     
 1651:     $r->print(<<"END");
 1652: <form name="prefs" action="/adm/preferences" method="post">
 1653: <input type="hidden" name="action" value="verify_and_change_discussion" />
 1654: <br />
 1655: $lt{'sdpf'}<br /> $lt{'prca'}  <ol><li>$lt{'whpo'}</li><li>$lt{'unwh'}</li></ol> 
 1656: END
 1657: 
 1658:     $r->print('<p class="LC_info">'.$lt{'thde'}.'</p>');
 1659: 
 1660:     $r->print(&Apache::loncommon::start_data_table());
 1661:     $r->print(<<"END");
 1662:        <tr>
 1663:         <th>$lt{'pref'}</th>
 1664:         <th>$lt{'curr'}</th>
 1665:         <th>$lt{'actn'}?</th>
 1666:        </tr>
 1667: END
 1668:     $r->print(&Apache::loncommon::start_data_table_row());
 1669:     $r->print(<<"END");
 1670:        <td>$lt{'disa'}</td>
 1671:        <td>$lt{$discdisp}</td>
 1672:        <td><label><input type="checkbox" name="discdisp" /><input type="hidden" name="newdisp" value="$newdisp" />&nbsp;$lt{'chgt'} "$dispchange"</label></td>
 1673: END
 1674:     $r->print(&Apache::loncommon::end_data_table_row().
 1675: 	      &Apache::loncommon::start_data_table_row());
 1676:     $r->print(<<"END");
 1677:        <td>$lt{'npmr'}</td>
 1678:        <td>$lt{$discmark}</td>
 1679:        <td><label><input type="checkbox" name="discmark" /><input type="hidden" name="newmark" value="$newmark" />&nbsp;$lt{'chgt'} "$markchange"</label></td>
 1680:       </tr>
 1681: END
 1682:     $r->print(&Apache::loncommon::end_data_table_row().
 1683: 	      &Apache::loncommon::end_data_table());
 1684: 
 1685:     $r->print('<br />'
 1686:              .'<input type="submit" name="sub" value="'.&mt('Save').'" />'
 1687:              .'</form>'
 1688:     );
 1689: }
 1690:                                                                                                                 
 1691: sub verify_and_change_discussion {
 1692:     my $r = shift;
 1693:     my $user     = $env{'user.name'};
 1694:     my $domain   = $env{'user.domain'};
 1695:     my $message='';
 1696:     if (defined($env{'form.discdisp'}) ) {
 1697:         my $newdisp  = $env{'form.newdisp'};
 1698:         if ($newdisp eq 'unread') {
 1699:             $message .=&mt('In discussions: only new posts will be displayed.').'<br />';
 1700:             &Apache::lonnet::put('environment',{'discdisplay' => $newdisp});
 1701:             &Apache::lonnet::appenv({'environment.discdisplay' => $newdisp});
 1702:         } else {
 1703:             $message .= &mt('In discussions: all posts will be displayed.').'<br />';
 1704:             &Apache::lonnet::del('environment',['discdisplay']);
 1705:             &Apache::lonnet::delenv('environment.discdisplay');
 1706:         }
 1707:     }
 1708:     if (defined($env{'form.discmark'}) ) {
 1709:         my $newmark = $env{'form.newmark'};
 1710:         if ($newmark eq 'ondisp') {
 1711:             $message.=&Apache::lonhtmlcommon::confirm_success(&mt('In discussions: new posts will be cease to be identified as "NEW" after display.')).'<br />';
 1712:             &Apache::lonnet::put('environment',{'discmarkread' => $newmark});
 1713:             &Apache::lonnet::appenv({'environment.discmarkread' => $newmark});
 1714:         } else {
 1715:             $message.=&Apache::lonhtmlcommon::confirm_success(&mt('In discussions: posts will be identified as "NEW" until marked as read by the reader.')).'<br />';
 1716:             &Apache::lonnet::del('environment',['discmarkread']);
 1717:             &Apache::lonnet::delenv('environment.discmarkread');
 1718:         }
 1719:     }
 1720:     $message=&Apache::loncommon::confirmwrapper($message);
 1721:     &print_main_menu($r, $message);
 1722: }
 1723: 
 1724: ################################################################
 1725: # Subroutines for page display on course access (Course Coordinators)
 1726: ################################################################
 1727: sub coursedisplaychanger {
 1728:     my $r = shift;
 1729:     &Apache::lonhtmlcommon::add_breadcrumb(
 1730: 	    {	href => '/adm/preferences?action=changecourseinit',
 1731:                 text => 'Change Course Init. Pref.'});
 1732:     $r->print(Apache::loncommon::start_page('Change Course Initialization Preference'));
 1733:     $r->print(Apache::lonhtmlcommon::breadcrumbs('Change Course Init. Pref.'));
 1734:     my $user       = $env{'user.name'};
 1735:     my $domain     = $env{'user.domain'};
 1736:     my %userenv = &Apache::lonnet::get('environment',['course_init_display']);
 1737:     my $currvalue = 'whatsnew';
 1738:     my $firstselect = '';
 1739:     my $whatsnewselect = 'checked="checked"';
 1740:     if (exists($userenv{'course_init_display'})) {
 1741:         if ($userenv{'course_init_display'} eq 'firstres') {
 1742:             $currvalue = 'firstres';
 1743:             $firstselect = 'checked="checked"';
 1744: 	    $whatsnewselect = '';
 1745:         }
 1746:     }
 1747:     my %pagenames = &Apache::lonlocal::texthash(
 1748:                        firstres => 'First resource',
 1749:                        whatsnew => "What's New Page",
 1750:                     );
 1751:     my $whatsnew_off=&mt('Display the [_1]first resource[_2] in the course.','<b>','</b>');
 1752:     my $whatsnew_on=&mt("Display the [_1]What's New Page[_2] - a summary of items in the course which require attention.",'<b>','</b>');
 1753: 
 1754:     $r->print('<br /><b>'
 1755:              .&mt('Set the default page to be displayed when you select a course role')
 1756:              .'</b>&nbsp;'
 1757:              .&mt('(Currently: [_1])',$pagenames{$currvalue})
 1758:              .'<br />'
 1759:              .&mt("The global user preference you set for your courses can be overridden in an individual course by setting a course specific setting via the [_1]What's New Page[_2] in the course.",'<i>','</i>')
 1760:              .'<br /><br />'
 1761:     );
 1762:     $r->print(<<ENDLSCREEN);
 1763: <form name="prefs" action="/adm/preferences" method="post">
 1764: <input type="hidden" name="action" value="verify_and_change_coursepage" />
 1765: <br />
 1766: <label><input type="radio" name="newdisp" value="firstres" $firstselect /> $whatsnew_off</label><br />
 1767: <label><input type="radio" name="newdisp" value="whatsnew" $whatsnewselect /> $whatsnew_on</label><input type="hidden" name="refpage" value="$env{'form.refpage'}" />
 1768: ENDLSCREEN
 1769:     $r->print('<br /><br /><input type="submit" value="'.&mt('Save').'" />
 1770: </form>');
 1771: }
 1772: 
 1773: sub verify_and_change_coursepage {
 1774:     my $r = shift;
 1775:     my $message='';
 1776:     my %lt = &Apache::lonlocal::texthash(
 1777:         'defs' => 'Default now set',
 1778:         'when' => 'when you select a course role from the roles screen',
 1779:         'ywbt' => 'you will be taken to the start of the course.',
 1780:         'apwb' => 'a page will be displayed that lists items in the course that may require action from you.',
 1781:         'gtts' => 'Go to the start of the course',
 1782:         'dasp' => "Display the What's New Page", 
 1783:     );
 1784:     my $newdisp  = $env{'form.newdisp'};
 1785:     $message = '<b>'.$lt{'defs'}.'</b>: '.$lt{'when'}.', ';
 1786:     if ($newdisp eq 'firstres') {
 1787:         $message .= $lt{'ywbt'}.'<br />';
 1788:         &Apache::lonnet::put('environment',{'course_init_display' => $newdisp});
 1789:         &Apache::lonnet::appenv({'environment.course_init_display' => $newdisp});
 1790:     } else {
 1791:         $message .= $lt{'apwb'}.'<br />';
 1792:         &Apache::lonnet::del('environment',['course_init_display']);
 1793:         &Apache::lonnet::delenv('environment.course_init_display');
 1794:     }
 1795:     my $refpage = $env{'form.refpage'};
 1796:     if (($env{'request.course.fn'}) && ($env{'request.course.id'})) {
 1797:         if ($newdisp eq 'firstres') {
 1798:             my $cdom = $env{'course.'.$env{'request.course.id'}.'.domain'};
 1799:             my $cnum = $env{'course.'.$env{'request.course.id'}.'.num'}; 
 1800:             my ($furl,$ferr)=
 1801:                 &Apache::lonuserstate::readmap($cdom.'/'.$cnum);
 1802:             $message .= '<br /><font size="+1"><a href="'.$furl.'">'.$lt{'gtts'}.' <i>'.&mt('now').'</i></a></font>';
 1803:         } else {
 1804:             $message .= '<br /><font size="+1"><a href="/adm/whatsnew?refpage='.
 1805:                         $refpage.'">'.$lt{'dasp'}.'</a></font>';
 1806:         }
 1807:     }
 1808:     &print_main_menu($r, &Apache::lonhtmlcommon::confirm_success($message));
 1809: }
 1810: 
 1811: sub print_main_menu {
 1812:     my ($r, $message) = @_;
 1813:     # Determine current authentication method
 1814:     my $user = $env{'user.name'};
 1815:     my $domain = $env{'user.domain'};
 1816:     my $currentauth=&Apache::lonnet::queryauthenticate($user,$domain);
 1817: 
 1818:     # build the data structure for menu generation
 1819: my $aboutmeurl='/adm/'.$env{'user.domain'}.'/'.$env{'user.name'}.'/aboutme';
 1820: my $role = ($env{'user.adv'} ? 'Roles' : 'Course');
 1821: my %permissions;
 1822: if (&Apache::lonnet::usertools_access($user,$domain,'aboutme')) {
 1823:     $permissions{'aboutme'} = 'F';
 1824: }
 1825: my @menu=
 1826:     ({	categorytitle=>'Personal Data',
 1827: 	items =>[
 1828: 	    {	linktext => 'Personal Information Page',
 1829: 		url => $aboutmeurl,
 1830: 		permission => $permissions{'aboutme'},
 1831: 		#help => 'Prefs_About_Me',
 1832: 		icon => 'system-users.png',
 1833: 		linktitle => 'Edit information about yourself that should be displayed on your public profile.'
 1834: 	    },
 1835: 	    {	linktext => 'Screen Name',
 1836: 		url => '/adm/preferences?action=changescreenname',
 1837: 		permission => 'F',
 1838: 		#help => 'Prefs_Screen_Name_Nickname',
 1839: 		icon => 'preferences-desktop-font.png',
 1840: 		linktitle => 'Change the name that is displayed in your posts.'
 1841: 	    },
 1842: 		]
 1843:     },
 1844:     {	categorytitle=>'Page Display Settings',
 1845: 	items =>[
 1846: 	    {	linktext => 'Color Scheme',
 1847: 		url => '/adm/preferences?action=changecolors',
 1848: 		permission => 'F',
 1849: 		#help => 'Change_Colors',
 1850: 		icon => 'preferences-desktop-theme.png',
 1851: 		linktitle => 'Change LON-CAPA default colors.'
 1852: 	    },
 1853: 	    {	linktext => 'Menu Display',
 1854: 		url => '/adm/preferences?action=changeicons',
 1855: 		permission => 'F',
 1856: 		#help => '',
 1857: 		icon => 'preferences-system-windows.png',
 1858: 		linktitle => 'Change whether the menus are displayed with buttons, icons or icons and text.'
 1859: 	    }
 1860: 
 1861: 		]
 1862:     },
 1863:     {	categorytitle=>'Content Display Settings',
 1864: 	items =>[
 1865: 	    {	linktext => 'Language',
 1866: 		url => '/adm/preferences?action=changelanguages',
 1867: 		permission => 'F',
 1868: 		#help => 'Prefs_Language',
 1869: 		icon => 'preferences-desktop-locale.png',
 1870: 		linktitle => 'Choose the default language for this user.'
 1871: 	    },
 1872: 	    {	linktext => 'WYSIWYG Editor',
 1873: 		url => '/adm/preferences?action=changewysiwyg',
 1874: 		permission => 'F',
 1875: 		#help => '',
 1876: 		icon => 'edit-select-all.png',
 1877: 		linktitle => 'Enable or disable the WYSIWYG-Editor.'
 1878: 	    },
 1879: 	    {	linktext => $role.' Page',
 1880: 		url => '/adm/preferences?action=changerolespref',
 1881: 		permission => 'F',
 1882: 		#help => '',
 1883: 		icon => 'sctr.png',
 1884: 		linktitle => 'Configure the roles hotlist.'
 1885: 	    },
 1886: 	    {	linktext => 'Display of Scientific Equations',
 1887: 		url => '/adm/preferences?action=changetexenginepref',
 1888: 		permission => 'F',
 1889: 		#help => '',
 1890: 		icon => 'stat.png',
 1891: 		linktitle => 'Change how Scientific Equations are displayed.'
 1892: 	    },
 1893: 		]
 1894:     },
 1895:     {	categorytitle=>'Message Management',
 1896: 	items =>[
 1897: 	    {	linktext => 'Messages &amp; Notifications',
 1898: 		url => '/adm/preferences?action=changemsgforward',
 1899: 		permission => 'F',
 1900: 		#help => 'Prefs_Messages',
 1901: 		icon => 'mail-reply-all.png',
 1902: 		linktitle => 'Change messageforwarding or notifications settings.'
 1903: 	    },
 1904: 	    {	linktext => 'Discussion Display',
 1905: 		url => '/adm/preferences?action=changediscussions',
 1906: 		permission => 'F',
 1907: 		#help => 'Change_Discussion_Display',
 1908: 		icon => 'mail-message-new.png',
 1909: 		linktitle => 'Set display preferences for discussion posts for both discussion boards and individual resources in all your courses.'
 1910: 	    },
 1911: 		]
 1912:     },
 1913:     {	categorytitle=>'Other',
 1914: 	items =>[
 1915: 	    {	linktext => 'Register Response Devices (&quot;Clickers&quot;)',
 1916: 		url => '/adm/preferences?action=changeclicker',
 1917: 		permission => 'F',
 1918: 		#help => '',
 1919: 		icon => 'network-workgroup.png',
 1920: 		linktitle => 'Register your clicker.'
 1921: 	    },
 1922: 		]
 1923:     },
 1924:     );
 1925: 
 1926:     if ($currentauth =~ /^(unix|internal):/) {
 1927: push(@{ $menu[0]->{items} }, {
 1928: 	linktext => 'Password',
 1929: 	url => '/adm/preferences?action=changepass',
 1930: 	permission => 'F',
 1931: 	#help => 'Change_Password',
 1932: 	icon => 'emblem-readonly.png',
 1933: 	linktitle => 'Change your password.',
 1934: 	});
 1935:     }
 1936:     if ($env{'environment.remote'} eq 'off') {
 1937: push(@{ $menu[1]->{items} }, {
 1938: 	linktext => 'Launch Remote Control',
 1939: 	url => '/adm/remote?url=/adm/preferences?action=launch',
 1940: 	permission => 'F',
 1941: 	#help => '',
 1942: 	icon => 'network-wireless.png',
 1943: 	linktitle => 'Launch the remote control for LON-CAPA.',
 1944: 	});
 1945:     }else{
 1946: push(@{ $menu[1]->{items} }, {
 1947: 	linktext => 'Collapse Remote Control',
 1948: 	url => '/adm/remote?url=/adm/preferences?action=collapse',
 1949: 	permission => 'F',
 1950: 	#help => '',
 1951: 	icon => 'network-wireless.png',
 1952: 	linktitle => 'Collapse the remote control for LON-CAPA.',
 1953: 	});
 1954:     }
 1955:     my %author_roles = &Apache::lonnet::get_my_roles($user,$domain,'userroles','',['au']);
 1956:     if (keys(%author_roles) > 0) {
 1957: push(@{ $menu[4]->{items} }, {
 1958: 	linktext => 'Restrict Domain Coordinator Access',
 1959: 	url => '/adm/preferences?action=changedomcoord',
 1960: 	permission => 'F',
 1961: 	#help => '',
 1962: 	icon => 'system-lock-screen.png',
 1963: 	linktitle => 'Restrict domain coordinator access.',
 1964: 	});
 1965:     }
 1966: 
 1967:     if (&Apache::lonnet::allowed('whn',$env{'request.course.id'})
 1968: 	|| &Apache::lonnet::allowed('whn',$env{'request.course.id'}.'/'
 1969: 				    .$env{'request.course.sec'})) {
 1970: push(@{ $menu[4]->{items} }, {
 1971: 	linktext => 'Course Initialization',
 1972: 	url => '/adm/preferences?action=changecourseinit',
 1973: 	permission => 'F',
 1974: 	#help => '',
 1975: 	icon => 'edit-copy.png',
 1976: 	linktitle => 'Set the default page to be displayed when you select a course role.',
 1977: 	});
 1978: 
 1979:     }
 1980:     if ($env{'user.name'} =~ /^(albertel|fox|foxr|kortemey|korte|raeburn)$/) {
 1981: push(@{ $menu[4]->{items} }, {
 1982: 	linktext => 'Toggle Debug Messages (Current:'.$env{'user.debug'}.')',
 1983: 	url => '/adm/preferences?action=debugtoggle',
 1984: 	permission => 'F',
 1985: 	#help => '',
 1986: 	icon => 'blog.png',
 1987: 	linktitle => 'Toggle Debug Messages.',
 1988: 	});
 1989:     }   
 1990: 
 1991:     $r->print(&Apache::loncommon::start_page('My Space'));
 1992:     $r->print(Apache::lonhtmlcommon::breadcrumbs('Change Preferences'));
 1993:     $r->print($message);
 1994:     $r->print(Apache::lonhtmlcommon::generate_menu(@menu));
 1995:     $r->print(Apache::loncommon::end_page());
 1996: }
 1997: 
 1998: ######################################################
 1999: #            other handler subroutines               #
 2000: ######################################################
 2001: 
 2002: ################################################################
 2003: #                          Main handler                        #
 2004: ################################################################
 2005: sub handler {    
 2006:     my $r = shift;
 2007:     Apache::loncommon::content_type($r,'text/html');
 2008:     # Some pages contain DES keys and should not be cached.
 2009:     Apache::loncommon::no_cache($r);
 2010:     $r->send_http_header;
 2011:     return OK if $r->header_only;
 2012:     #
 2013:     Apache::loncommon::get_unprocessed_cgi($ENV{'QUERY_STRING'},
 2014:                                    ['action','wysiwyg','returnurl','refpage']);
 2015:     #
 2016:     Apache::lonhtmlcommon::clear_breadcrumbs();
 2017:     Apache::lonhtmlcommon::add_breadcrumb
 2018:         ({href => '/adm/preferences',
 2019:           text => 'Set User Preferences',
 2020:           help =>
 2021:           'Prefs_About_Me,Prefs_Language,Prefs_Screen_Name_Nickname,Change_Colors,Change_Password,Prefs_Messages,Change_Discussion_Display'});
 2022:     if(!exists $env{'form.action'}) {
 2023: 	    &print_main_menu($r);
 2024:     }elsif($env{'form.action'} eq 'changepass'){
 2025:         &passwordchanger($r);
 2026:     }elsif($env{'form.action'} eq 'verify_and_change_pass'){
 2027:         &verify_and_change_password($r);
 2028:     }elsif($env{'form.action'} eq 'changescreenname'){
 2029:         &screennamechanger($r);
 2030:     }elsif($env{'form.action'} eq 'verify_and_change_screenname'){
 2031:         &verify_and_change_screenname($r);
 2032:     }elsif($env{'form.action'} eq 'changemsgforward'){
 2033:         &msgforwardchanger($r);
 2034:     }elsif($env{'form.action'} eq 'verify_and_change_msgforward'){
 2035:         &verify_and_change_msgforward($r);
 2036:     }elsif($env{'form.action'} eq 'changecolors'){
 2037:         &colorschanger($r);
 2038:     }elsif($env{'form.action'} eq 'verify_and_change_colors'){
 2039:         &verify_and_change_colors($r);
 2040:     }elsif($env{'form.action'} eq 'changelanguages'){
 2041:         &languagechanger($r);
 2042:     }elsif($env{'form.action'} eq 'verify_and_change_languages'){
 2043:         &verify_and_change_languages($r);
 2044:     }elsif($env{'form.action'} eq 'changewysiwyg'){
 2045:         &wysiwygchanger($r);
 2046:     }elsif($env{'form.action'} eq 'set_wysiwyg'){
 2047:         &verify_and_change_wysiwyg($r);
 2048:     }elsif($env{'form.action'} eq 'changediscussions'){
 2049:         &discussionchanger($r);
 2050:     }elsif($env{'form.action'} eq 'verify_and_change_discussion'){
 2051:         &verify_and_change_discussion($r);
 2052:     }elsif($env{'form.action'} eq 'changerolespref'){
 2053:         &rolesprefchanger($r);
 2054:     }elsif($env{'form.action'} eq 'verify_and_change_rolespref'){
 2055:         &verify_and_change_rolespref($r);
 2056:     }elsif($env{'form.action'} eq 'changetexenginepref'){
 2057:         &texenginechanger($r);
 2058:     }elsif($env{'form.action'} eq 'verify_and_change_texengine'){
 2059:         &verify_and_change_texengine($r);
 2060:     }elsif($env{'form.action'} eq 'changeicons'){
 2061:         &iconchanger($r);
 2062:     }elsif($env{'form.action'} eq 'verify_and_change_icons'){
 2063:         &verify_and_change_icons($r);
 2064:     }elsif($env{'form.action'} eq 'changeclicker'){
 2065:         &clickerchanger($r);
 2066:     }elsif($env{'form.action'} eq 'verify_and_change_clicker'){
 2067:         &verify_and_change_clicker($r);
 2068:     }elsif($env{'form.action'} eq 'changedomcoord'){
 2069:         &domcoordchanger($r);
 2070:     }elsif($env{'form.action'} eq 'verify_and_change_domcoord'){
 2071:         &verify_and_change_domcoord($r);
 2072:     }elsif($env{'form.action'} eq 'lockwarning'){
 2073:         &lockwarning($r);
 2074:     }elsif($env{'form.action'} eq 'verify_and_change_locks'){
 2075:         &verify_and_change_lockwarning($r);
 2076:     }elsif($env{'form.action'} eq 'changecourseinit'){
 2077:         &coursedisplaychanger($r);
 2078:     }elsif($env{'form.action'} eq 'verify_and_change_coursepage'){
 2079:         &verify_and_change_coursepage($r);
 2080:     }elsif($env{'form.action'} eq 'debugtoggle'){
 2081:         &toggle_debug();
 2082: 	&print_main_menu($r);
 2083:     }
 2084: 
 2085:     return OK;
 2086: 
 2087: 
 2088: }
 2089: #remove when done
 2090: #old handler routine
 2091: sub handler2 {
 2092:     my $r = shift;
 2093:     my $user = $env{'user.name'};
 2094:     my $domain = $env{'user.domain'};
 2095:     &Apache::loncommon::content_type($r,'text/html');
 2096:     # Some pages contain DES keys and should not be cached.
 2097:     &Apache::loncommon::no_cache($r);
 2098:     $r->send_http_header;
 2099:     return OK if $r->header_only;
 2100:     #
 2101:     &Apache::loncommon::get_unprocessed_cgi($ENV{'QUERY_STRING'},
 2102:                                    ['action','wysiwyg','returnurl','refpage']);
 2103:     #
 2104:     &Apache::lonhtmlcommon::clear_breadcrumbs();
 2105:     &Apache::lonhtmlcommon::add_breadcrumb
 2106:         ({href => '/adm/preferences',
 2107:           text => 'Set User Preferences'});
 2108: 
 2109:     my @Options;
 2110:     # Determine current authentication method
 2111:     my $currentauth=&Apache::lonnet::queryauthenticate($user,$domain);
 2112:     if ($currentauth =~ /^(unix|internal):/) {
 2113:         push (@Options,({ action   => 'changepass',
 2114:                           linktext => 'Change Password',
 2115:                           href     => '/adm/preferences',
 2116:                           help     => 'Change_Password',
 2117:                           subroutine => \&passwordchanger,
 2118:                           breadcrumb => 
 2119:                               { href => '/adm/preferences?action=changepass',
 2120:                                 text => 'Change Password'},
 2121:                           },
 2122:                         { action => 'verify_and_change_pass',
 2123:                           subroutine => \&verify_and_change_password,
 2124:                           breadcrumb => 
 2125:                               { href =>'/adm/preferences?action=changepass',
 2126:                                 text => 'Change Password'},
 2127:                           printmenu => 'not_on_error',
 2128:                           }));
 2129:     }
 2130:     push (@Options,({ action   => 'changescreenname',
 2131:                       linktext => 'Change Screen Name',
 2132:                       href     => '/adm/preferences',
 2133:                       help     => 'Prefs_Screen_Name_Nickname',
 2134:                       subroutine => \&screennamechanger,
 2135:                       breadcrumb => 
 2136:                           { href => '/adm/preferences?action=changescreenname',
 2137:                             text => 'Change Screen Name'},
 2138:                       },
 2139:                     { action   => 'verify_and_change_screenname',
 2140:                       subroutine => \&verify_and_change_screenname,
 2141:                       breadcrumb => 
 2142:                           { href => '/adm/preferences?action=changescreenname',
 2143:                             text => 'Change Screen Name'},
 2144:                       printmenu => 'yes',
 2145:                       }));
 2146: 
 2147:     push (@Options,({ action   => 'changemsgforward',
 2148:                       linktext => 'Change Message Forwarding and Notification E-mail Addresses',
 2149:                       href     => '/adm/preferences',
 2150:                       help     => 'Prefs_Messages',
 2151:                       breadcrumb => 
 2152:                           { href => '/adm/preferences?action=changemsgforward',
 2153:                             text => 'Change Message Forwarding/Notification'},
 2154:                       subroutine => \&msgforwardchanger,
 2155:                       },
 2156:                     { action => 'verify_and_change_msgforward',
 2157:                       help   => 'Prefs_Messages',
 2158:                       breadcrumb => 
 2159:                           { href => '/adm/preferences?action=changemsgforward',
 2160:                             text => 'Change Message Forwarding/Notification'},
 2161:                       printmenu => 'yes',
 2162:                       subroutine => \&verify_and_change_msgforward }));
 2163:     my $aboutmeaction=
 2164:         '/adm/'.$env{'user.domain'}.'/'.$env{'user.name'}.'/aboutme';
 2165:     push (@Options,{ action => 'none', 
 2166:                      linktext =>
 2167:                          q{Edit the Personal Information Page},
 2168: 		     help => 'Prefs_About_Me',
 2169:                      href => $aboutmeaction});
 2170:     push (@Options,({ action => 'changecolors',
 2171:                       linktext => 'Change Color Scheme',
 2172:                       href => '/adm/preferences',
 2173:                       help => 'Change_Colors',
 2174:                       breadcrumb => 
 2175:                           { href => '/adm/preferences?action=changecolors',
 2176:                             text => 'Change Colors'},
 2177:                       subroutine => \&colorschanger,
 2178:                   },
 2179:                     { action => 'verify_and_change_colors',
 2180:                       breadcrumb => 
 2181:                           { href => '/adm/preferences?action=changecolors',
 2182:                             text => 'Change Colors'},
 2183:                       printmenu => 'yes',
 2184:                       subroutine => \&verify_and_change_colors,
 2185:                       }));
 2186:     push (@Options,({ action => 'changelanguages',
 2187:                       linktext => 'Change Language Preferences',
 2188:                       href => '/adm/preferences',
 2189: 		      help => 'Prefs_Language',
 2190:                       breadcrumb=>
 2191:                           { href => '/adm/preferences?action=changelanguages',
 2192:                             text => 'Change Language'},
 2193:                       subroutine =>  \&languagechanger,
 2194:                   },
 2195:                     { action => 'verify_and_change_languages',
 2196:                       breadcrumb=>
 2197:                           {href => '/adm/preferences?action=changelanguages',
 2198:                            text => 'Change Language'},
 2199:                       printmenu => 'yes',
 2200:                       subroutine=>\&verify_and_change_languages, }
 2201:                     ));
 2202:     push (@Options,({ action => 'changewysiwyg',
 2203:                       linktext => 'Change WYSIWYG Editor Preferences',
 2204:                       href => '/adm/preferences',
 2205:                       breadcrumb => 
 2206:                             { href => '/adm/preferences?action=changewysiwyg',
 2207:                               text => 'Change WYSIWYG Preferences'},
 2208:                       subroutine => \&wysiwygchanger,
 2209:                   },
 2210:                     { action => 'set_wysiwyg',
 2211:                       breadcrumb =>
 2212:                           { href => '/adm/preferences?action=changewysiwyg',
 2213:                             text => 'Change WYSIWYG Preferences'},
 2214:                       printmenu => 'yes',
 2215:                       subroutine => \&verify_and_change_wysiwyg, }
 2216:                     ));
 2217:     push (@Options,({ action => 'changediscussions',
 2218:                       linktext => 'Change Discussion Display Preferences',
 2219:                       href => '/adm/preferences',
 2220:                       help => 'Change_Discussion_Display',
 2221:                       breadcrumb => 
 2222:                             { href => '/adm/preferences?action=changediscussions',
 2223:                               text => 'Change Discussion Preferences'},
 2224:                       subroutine => \&discussionchanger,
 2225:                   },
 2226:                     { action => 'verify_and_change_discussion',
 2227:                       breadcrumb =>
 2228:                           { href => '/adm/preferences?action=changediscussions',
 2229:                             text => 'Change Discussion Preferences'},
 2230:                       printmenu => 'yes',
 2231:                       subroutine => \&verify_and_change_discussion, }
 2232:                     ));
 2233: 
 2234:     my $role = ($env{'user.adv'} ? 'Roles' : 'Course');
 2235:     push (@Options,({ action   => 'changerolespref',
 2236:                       linktext => 'Change '.$role.' Page Preferences',
 2237:                       href     => '/adm/preferences',
 2238:                       subroutine => \&rolesprefchanger,
 2239:                       breadcrumb =>
 2240:                           { href => '/adm/preferences?action=changerolespref',
 2241:                             text => 'Change '.$role.' Page Pref'},
 2242:                       },
 2243:                     { action   => 'verify_and_change_rolespref',
 2244:                       subroutine => \&verify_and_change_rolespref,
 2245:                       breadcrumb =>
 2246:                           { href => '/adm/preferences?action=changerolespref',
 2247:                             text => 'Change '.$role.' Page Preferences'},
 2248:                       printmenu => 'yes',
 2249:                       }));
 2250: 
 2251:     push (@Options,({ action   => 'changetexenginepref',
 2252:                       linktext => 'Change How Math Equations Are Displayed',
 2253:                       href     => '/adm/preferences',
 2254:                       subroutine => \&texenginechanger,
 2255:                       breadcrumb =>
 2256:                           { href => '/adm/preferences?action=changetexenginepref',
 2257:                             text => 'Change Math Pref'},
 2258:                       },
 2259:                     { action   => 'verify_and_change_texengine',
 2260:                       subroutine => \&verify_and_change_texengine,
 2261:                       breadcrumb =>
 2262:                           { href => '/adm/preferences?action=changetexenginepref',
 2263:                             text => 'Change Math Preferences'},
 2264:                       printmenu => 'yes',
 2265:                       }));
 2266: 
 2267:     if ($env{'environment.remote'} eq 'off') {
 2268: 	push (@Options,({ action => 'launch',
 2269: 			  linktext => 'Launch Remote Control',
 2270: 			  href => '/adm/remote?url=/adm/preferences',
 2271: 		      }));
 2272:     } else {
 2273: 	push (@Options,({ action => 'collapse',
 2274: 			  linktext => 'Collapse Remote Control',
 2275: 			  href => '/adm/remote?url=/adm/preferences',
 2276: 		      }));
 2277:     }
 2278: 
 2279:     push (@Options,({ action   => 'changeicons',
 2280:                       linktext => 'Change How Menus are Displayed',
 2281:                       href     => '/adm/preferences',
 2282:                       subroutine => \&iconchanger,
 2283:                       breadcrumb =>
 2284:                           { href => '/adm/preferences?action=changeicons',
 2285:                             text => 'Change Main Menu'},
 2286:                       },
 2287:                     { action   => 'verify_and_change_icons',
 2288:                       subroutine => \&verify_and_change_icons,
 2289:                       breadcrumb =>
 2290:                           { href => '/adm/preferences?action=changeicons',
 2291:                             text => 'Change Main Menu'},
 2292:                       printmenu => 'yes',
 2293:                       }));
 2294: 
 2295:     push (@Options,({ action   => 'changeclicker',
 2296:                       linktext => 'Register Response Devices ("Clickers")',
 2297:                       href     => '/adm/preferences',
 2298:                       subroutine => \&clickerchanger,
 2299:                       breadcrumb =>
 2300:                           { href => '/adm/preferences?action=changeclicker',
 2301:                             text => 'Register Clicker'},
 2302:                       },
 2303:                     { action   => 'verify_and_change_clicker',
 2304:                       subroutine => \&verify_and_change_clicker,
 2305:                       breadcrumb =>
 2306:                           { href => '/adm/preferences?action=changeclicker',
 2307:                             text => 'Register Clicker'},
 2308:                       printmenu => 'yes',
 2309:                       }));
 2310:     my %author_roles = &Apache::lonnet::get_my_roles($user,$domain,'userroles','',['au']);
 2311:     if (keys(%author_roles) > 0) {
 2312:       push (@Options,({ action   => 'changedomcoord',
 2313:                         linktext => 'Restrict Domain Coordinator Access',
 2314:                         href     => '/adm/preferences',
 2315:                         subroutine => \&domcoordchanger,
 2316:                         breadcrumb =>
 2317:                             { href => '/adm/preferences?action=changedomcoord',
 2318:                               text => 'Restrict Domain Coordinator Access'},
 2319:                       },
 2320:                       { action   => 'verify_and_change_domcoord',
 2321:                         subroutine => \&verify_and_change_domcoord,
 2322:                         breadcrumb =>
 2323:                             { href => '/adm/preferences?action=changedomcoord',
 2324:                               text => 'Restrict Domain Coordinator Access'},
 2325:                         printmenu => 'yes',
 2326:                       }));
 2327:     }
 2328: 
 2329:     push (@Options,({ action   => 'lockwarning',
 2330:                       subroutine => \&lockwarning,
 2331:                       breadcrumb =>
 2332:                           { href => '/adm/preferences?action=lockwarning',
 2333:                             text => 'Lock Warnings'},
 2334:                       },
 2335:                     { action   => 'verify_and_change_locks',
 2336:                       subroutine => \&verify_and_change_lockwarning,
 2337:                       breadcrumb =>
 2338:                           { href => '/adm/preferences?action=lockwarning',
 2339:                             text => 'Lockwarnings'},
 2340:                       printmenu => 'yes',
 2341:                       }));
 2342: 
 2343: 
 2344:     if (&Apache::lonnet::allowed('whn',$env{'request.course.id'})
 2345: 	|| &Apache::lonnet::allowed('whn',$env{'request.course.id'}.'/'
 2346: 				    .$env{'request.course.sec'})) {
 2347:         push (@Options,({ action => 'changecourseinit',
 2348:                           linktext => 'Change Course Initialization Preference',
 2349:                           href => '/adm/preferences',
 2350:                           subroutine => \&coursedisplaychanger,
 2351:                           breadcrumb =>
 2352:                               { href => '/adm/preferences?action=changecourseinit',
 2353:                                 text => 'Change Course Init. Pref.'},
 2354:                           },
 2355:                         { action => 'verify_and_change_coursepage',
 2356:                           breadcrumb =>
 2357:                           { href => '/adm/preferences?action=changecourseinit',                               text => 'Change Course Initialization Preference'},
 2358:                         printmenu => 'yes',
 2359:                         subroutine => \&verify_and_change_coursepage,
 2360:                        }));
 2361:     }
 2362: 
 2363:     if (($env{'user.name'} =~ /^(albertel|fox|foxr|kortemey|korte|raeburn)$/)
 2364:      && ($env{'user.domain'} =~/^(msu|gerd)$/)){
 2365:         push (@Options,({ action => 'debugtoggle',
 2366:                           printmenu => 'yes',
 2367:                           subroutine => \&toggle_debug,
 2368:                           }));
 2369:     }
 2370: 
 2371:     $r->print(&Apache::loncommon::start_page('Change Preferences'));
 2372: 
 2373:     my $call = undef;
 2374:     my $help = undef;
 2375:     my $printmenu = 'yes';
 2376:     foreach my $option (@Options) {
 2377:         if ($option->{'action'} eq $env{'form.action'}) {
 2378:             $call = $option->{'subroutine'};
 2379:             $printmenu = $option->{'printmenu'};
 2380:             if (exists($option->{'breadcrumb'})) {
 2381:                 &Apache::lonhtmlcommon::add_breadcrumb
 2382:                     ($option->{'breadcrumb'});
 2383:             }
 2384: 	    $help=$option->{'help'};
 2385:         }
 2386:     }
 2387:     $r->print(&Apache::lonhtmlcommon::breadcrumbs('Change Preferences',$help));
 2388:     my $error;
 2389:     if (defined($call)) {
 2390:         $error = $call->($r);
 2391:     }
 2392:     if ( ( ($printmenu eq 'yes')
 2393: 	   || ($printmenu eq 'not_on_error' && !$error) )
 2394: 	 && (!$env{'form.returnurl'})) {
 2395:         my $optionlist = '<table cellpadding="5">';
 2396:         if ($env{'user.name'} =~ 
 2397:                          /^(albertel|kortemey|fox|foxr|korte|hallmat3|turtle|raeburn)$/
 2398:             ) {
 2399:             push (@Options,({ action => 'debugtoggle',
 2400:                               linktext => 'Toggle Debug Messages',
 2401:                               text => 'Current Debug status is -'.
 2402:                                   $env{'user.debug'}.'-.',
 2403:                               href => '/adm/preferences',
 2404:                               printmenu => 'yes',
 2405:                               subroutine => \&toggle_debug,
 2406:                               }));
 2407:         }
 2408:         foreach my $option(@Options) {
 2409:             my $optiontext = '';
 2410:             if (exists($option->{'href'})) {
 2411: 		$option->{'href_args'}{'action'}=$option->{'action'};
 2412: 		$optiontext .= 
 2413:                     '<a href="'.&add_get_param($option->{'href'},
 2414: 					       $option->{'href_args'}).'">'.
 2415:                     &mt($option->{'linktext'}).'</a>';
 2416:             }
 2417:             if (exists($option->{'text'})) {
 2418:                 $optiontext .= ' '.&mt($option->{'text'});
 2419:             }
 2420:             if ($optiontext ne '') {
 2421:                 $optiontext = '<font size="+1">'.$optiontext.'</font>'; 
 2422:                 my $helplink = '&nbsp;';
 2423:                 if (exists($option->{'help'})) {
 2424:                     $helplink = &Apache::loncommon::help_open_topic
 2425:                                                     ($option->{'help'});
 2426:                 }
 2427:                 $optionlist .= '<tr>'.
 2428:                     '<td>'.$helplink.'</td>'.
 2429:                     '<td>'.$optiontext.'</td>'.
 2430:                     '</tr>';
 2431:             }
 2432:         }
 2433:         $optionlist .= '</table>';
 2434:         $r->print($optionlist);
 2435:     } elsif ($env{'form.returnurl'}) {
 2436: 	$r->print('<br /><a href="'.$env{'form.returnurl'}.'"><font size="+1">'.
 2437: 		  &mt('Return').'</font></a>');
 2438:     }
 2439:     $r->print(&Apache::loncommon::end_page());
 2440:     return OK;
 2441: }
 2442: 
 2443: sub toggle_debug {
 2444:     if ($env{'user.debug'}) {
 2445:         &Apache::lonnet::delenv('user.debug');
 2446:     } else {
 2447:         &Apache::lonnet::appenv({'user.debug' => 1});
 2448:     }
 2449: }
 2450: 
 2451: 1;
 2452: __END__

FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>