File:  [LON-CAPA] / loncom / interface / lonpreferences.pm
Revision 1.125.4.3: download - view: text, annotated - select for diffs
Thu Aug 13 17:55:44 2009 UTC (14 years, 9 months ago) by raeburn
Branches: version_2_9_X
Diff to branchpoint 1.125: preferred, unified
- Backport 1.164, 1.168.

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

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