File:  [LON-CAPA] / loncom / interface / lonpreferences.pm
Revision 1.125.4.2: download - view: text, annotated - select for diffs
Thu May 21 16:00:49 2009 UTC (15 years ago) by raeburn
Branches: version_2_9_X
Diff to branchpoint 1.125: preferred, unified
- Some items missed in backports to create 1.125.4.1.

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

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