File:  [LON-CAPA] / loncom / interface / lonpreferences.pm
Revision 1.194: download - view: text, annotated - select for diffs
Sun Jul 31 01:21:04 2011 UTC (12 years, 9 months ago) by raeburn
Branches: MAIN
CVS tags: language_hyphenation_merge, language_hyphenation, HEAD
- Bug 6291.
  - Consistent wording.
  - Fix typo.

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

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