File:  [LON-CAPA] / loncom / interface / lonpreferences.pm
Revision 1.125.4.1: download - view: text, annotated - select for diffs
Wed May 20 15:05:19 2009 UTC (15 years ago) by raeburn
Branches: version_2_9_X
Diff to branchpoint 1.125: preferred, unified
- Backport 1.129, 1.130, 1.131, 1.132, 1.134, 1.135, 1.136, 1.137, 1.139, 1.140, 1.141, 1.142, 1.143, 1.146, 1.149, 1.151, 1.152, 1.153, 1.154, 1.155, 1.157, 1.158 1.159, 1.160, 1.162, 1.163.

    1: # The LearningOnline Network
    2: # Preferences
    3: #
    4: # $Id: lonpreferences.pm,v 1.125.4.1 2009/05/20 15:05:19 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 $message=&Apache::lonhtmlcommon::confirm_success(&mt('Set [_1] to [_2]','<i>'.&mt('Block access to construction space').'</i>','<tt>'.$status.'</tt>'));
  691:     $message=&Apache::loncommon::confirmwrapper($message);
  692:     $r->print(<<ENDVCSCREEN);
  693: $message
  694: ENDVCSCREEN
  695: }
  696: 
  697: #################################################################
  698: ##                      Lock Subroutines                        #
  699: #################################################################
  700: 
  701: sub lockwarning {
  702:     my $r = shift;
  703:     my $title=&mt('Action locked');
  704:     my $texttop=&mt('LON-CAPA is currently performing the following actions:');
  705:     my $textbottom=&mt('Changing roles or logging out may result in data corruption.');
  706:     my ($num,%which)=&Apache::lonnet::get_locks();
  707:     my $which='';
  708:     foreach my $id (keys %which) {
  709:        $which.='<li>'.$which{$id}.'</li>';
  710:     }
  711:     my $change=&mt('Override');
  712:     $r->print(<<ENDSCREEN);
  713: <form name="prefs" action="/adm/preferences" method="post">
  714: <input type="hidden" name="action" value="verify_and_change_locks" />
  715: <h1>$title</h1>
  716: $texttop
  717: <ul>
  718: $which
  719: </ul>
  720: $textbottom
  721: <input type="submit" value="$change" />
  722: </form>
  723: ENDSCREEN
  724: }
  725: 
  726: sub verify_and_change_lockwarning {
  727:     my $r = shift;
  728:     &Apache::lonnet::remove_all_locks();
  729:     $r->print(&mt('Cleared locks.'));
  730: }
  731: 
  732: 
  733: ################################################################
  734: #         Message Forward                                      #
  735: ################################################################
  736: 
  737: sub msgforwardchanger {
  738:     my ($r,$message) = @_;
  739:     my $user       = $env{'user.name'};
  740:     my $domain     = $env{'user.domain'};
  741:     my %userenv = &Apache::lonnet::get('environment',['msgforward','notification','critnotification','notifywithhtml']);
  742:     my $msgforward=$userenv{'msgforward'};
  743:     my %lt = &Apache::lonlocal::texthash(
  744:                                           all   => 'All',
  745:                                           crit  => 'Critical only',
  746:                                           reg   => 'Non-critical only',
  747:                                           foad  => 'Forwarding Address(es)',
  748:                                           noti  => 'Notification E-mail Address(es)', 
  749:                                           foad_exmpl => 'e.g. <tt>userA:domain1,userB:domain2,...</tt>',
  750:                                           mnot  => 'E-mail Address(es) which should be notified about new LON-CAPA messages',
  751:                                           mnot_exmpl => 'e.g. <tt>joe@doe.com</tt>',
  752:                                           chg   => 'Save',
  753:                                           email => 'The e-mail address entered in row ',
  754:                                           notv => 'is not a valid e-mail address',
  755:                                           toen => "To enter multiple addresses, enter one address at a time, click 'Save' and then add the next one", 
  756:                                           prme => 'Back',
  757:                                         );
  758:     my $forwardingHelp = &Apache::loncommon::help_open_topic("Prefs_Forwarding");
  759:     my $notificationHelp = &Apache::loncommon::help_open_topic("Prefs_Notification");
  760:     my $criticalMessageHelp = &Apache::loncommon::help_open_topic("Course_Critical_Message");
  761:     my @allow_html = split(/,/,$userenv{'notifywithhtml'});
  762:     my %allnot = &get_notifications(\%userenv);
  763:     my $validatescript = &Apache::lonhtmlcommon::javascript_valid_email();
  764:     my $jscript = qq|
  765: <script type="text/javascript">
  766: function validate() {
  767:     for (var i=0; i<document.prefs.numnotify.value; i++) {
  768:         var checkaddress = 0;
  769:         var addr = document.prefs.elements['address_'+i].value;
  770:         var rownum = i+1;
  771:         if (i < document.prefs.numnotify.value-1) {
  772:             if (document.prefs.elements['modify_notify_'+i].checked) {
  773:                 checkaddress = 1;
  774:             }
  775:         } else {
  776:             if (document.prefs.elements['add_notify_'+i].checked == true) { 
  777:                 checkaddress = 1;
  778:             }
  779:         }
  780:         if (checkaddress == 1)  {
  781:             var addr = document.prefs.elements['address_'+i].value;
  782:             if (validmail(document.prefs.elements['address_'+i]) == false) {
  783:                 var multimsg = '';
  784:                 if (addr.indexOf(",") >= 0) {
  785:                     multimsg = "\\n($lt{'toen'}).";
  786:                 }
  787:                 alert("$lt{'email'} "+rownum+" ('"+addr+"') $lt{'notv'}."+multimsg);
  788:                 return;
  789:             }
  790:         }
  791:     }
  792:     document.prefs.submit();
  793: }
  794: 
  795: function address_changes (adnum) {
  796:      if (!document.prefs.elements['del_notify_'+adnum].checked) { 
  797:          document.prefs.elements['modify_notify_'+adnum].checked = true;
  798:      }   
  799: }
  800: 
  801: function new_address(adnum) {
  802:      document.prefs.elements['add_notify_'+adnum].checked = true;
  803: }
  804: 
  805: function delete_address(adnum) {
  806:      if (document.prefs.elements['del_notify_'+adnum].checked) {
  807:           document.prefs.elements['modify_notify_'+adnum].checked = false;
  808:      }
  809: }
  810: 
  811: function modify_address(adnum) {
  812:     if (document.prefs.elements['modify_notify_'+adnum].checked) {
  813:         document.prefs.elements['del_notify_'+adnum].checked = false;
  814:     }
  815: } 
  816: 
  817: $validatescript
  818: </script>
  819: |;
  820:     $r->print(<<ENDMSG);
  821: $jscript
  822: $message
  823: <h3>$lt{'foad'} $forwardingHelp</h3>
  824: <form name="prefs" action="/adm/preferences" method="post">
  825: <input type="hidden" name="action" value="verify_and_change_msgforward" />
  826: $lt{'foad'} ($lt{'foad_exmpl'}):
  827: <input type="text" size="40" value="$msgforward" name="msgforward" /><br />
  828: <h3>$lt{'noti'} $notificationHelp</h3>
  829: $lt{'mnot'} ($lt{'mnot_exmpl'}):<br />
  830: ENDMSG
  831:     my @sortforwards = sort (keys(%allnot));
  832:     my $output = &Apache::loncommon::start_data_table().
  833:                  &Apache::loncommon::start_data_table_header_row().
  834:                  '<th>&nbsp;</th>'.
  835:                  '<th>'.&mt('Action').'</th>'.
  836:                  '<th>'.&mt('Notification address').'</th><th>'.
  837:                  &mt('Types of message for which notification is sent').
  838:                  $criticalMessageHelp.'</th><th>'.
  839:                  &mt('Excerpt retains HTML tags in message').'</th>'.
  840:                  &Apache::loncommon::end_data_table_header_row();
  841:     my $num = 0;
  842:     my $counter = 1;
  843:     foreach my $item (@sortforwards) {
  844:         $output .= &Apache::loncommon::start_data_table_row().
  845:                    '<td><b>'.$counter.'</b></td>'.
  846:                    '<td><span class="LC_nobreak"><label>'.
  847:                    '<input type="checkbox" name="modify_notify_'.
  848:                    $num.'" onclick="javscript:modify_address('."'$num'".')" />'.
  849:                    &mt('Modify').'</label></span>&nbsp;&nbsp; '.
  850:                    '<span class="LC_nobreak"><label>'.
  851:                    '<input type="checkbox" name="del_notify_'.$num.
  852:                    '" onclick="javscript:delete_address('."'$num'".')" />'.
  853:                    &mt('Delete').'</label></span></td>'.
  854:                    '<td><input type="text" value="'.$item.'" name="address_'.
  855:                    $num.'" onFocus="javascript:address_changes('."'$num'".
  856:                    ')" /></td><td>';
  857:         my %chk;
  858:         if (defined($allnot{$item}{'crit'})) {
  859:             if (defined($allnot{$item}{'reg'})) {
  860:                 $chk{'all'} = 'checked="checked" ';
  861:             } else {
  862:                 $chk{'crit'} = 'checked="checked" ';
  863:             }
  864:         } else {
  865:             $chk{'reg'} = 'checked="checked" ';
  866:         }
  867:         foreach my $type ('all','crit','reg') {
  868:             $output .= '<span class="LC_nobreak"><label>'.
  869:                        '<input type="radio" name="notify_type_'.$num. 
  870:                        '" value="'.$type.'" '.$chk{$type}.
  871:                        ' onchange="javascript:address_changes('."'$num'".')" />'.
  872:                        $lt{$type}.'</label></span>&nbsp;';
  873:         }
  874:         my $htmlon = '';
  875:         my $htmloff = '';
  876:         if (grep/^\Q$item\E/,@allow_html) {
  877:             $htmlon = 'checked="checked" '; 
  878:         } else {
  879:             $htmloff = 'checked="checked" ';
  880:         }
  881:         $output .= '</td><td><label><input type="radio" name="html_'.$num.
  882:                    '" value="1" '.$htmlon.
  883:                    ' onchange="javascript:address_changes('."'$num'".')" />'.
  884:                    &mt('Yes').'</label>&nbsp;'.
  885:                    '<label><input type="radio" name="html_'.$num.'" value="0" '.
  886:                    $htmloff. ' onchange="javascript:address_changes('."'$num'".
  887: ')" />'.
  888:                    &mt('No').'</label></td>'.
  889:                    &Apache::loncommon::end_data_table_row();
  890:         $num ++;
  891:         $counter ++;
  892:     }
  893:     my %defchk = (
  894:                    all => 'checked="checked" ',
  895:                    crit => '',
  896:                    reg => '',
  897:                  );
  898:     $output .= &Apache::loncommon::start_data_table_row().
  899:                '<td><b>'.$counter.'</b></td>'.
  900:                '<td><span class="LC_nobreak"><label>'.
  901:                '<input type="checkbox" name="add_notify_'.$num.
  902:                '" value="1" />'.&mt('Add new address').'</label></span></td>'.
  903:                '<td><input type="text" value="" name="address_'.$num.
  904:                '" onFocus="javascript:new_address('."'$num'".')" /></td><td>';
  905:     foreach my $type ('all','crit','reg') {
  906:         $output .= '<span class="LC_nobreak"><label>'.
  907:                    '<input type="radio" name="notify_type_'.$num.
  908:                    '" value="'.$type.'" '.$defchk{$type}.'/>'.
  909:                    $lt{$type}.'</label></span>&nbsp;';
  910:     }
  911:     $output .= '</td><td><label><input type="radio" name="html_'.$num.
  912:                '" value="1" />'.&mt('Yes').'</label>&nbsp;'.
  913:                '<label><input type="radio" name="html_'.$num.'" value="0" '.
  914:                ' checked="checked" />'.
  915:                &mt('No').'</label></td>'.
  916:                &Apache::loncommon::end_data_table_row().
  917:                &Apache::loncommon::end_data_table();
  918:     $num ++;
  919:     $r->print($output);
  920:     $r->print(qq|
  921: <br /><hr />
  922: <input type="hidden" name="numnotify" value="$num" />
  923: <input type="button" value="$lt{'prme'}" onclick="location.href='/adm/preferences'" />
  924: <input type="button" value="$lt{'chg'}" onclick="javascript:validate()" />
  925: </form>
  926: |);
  927: 
  928: }
  929: 
  930: sub get_notifications {
  931:     my ($userenv) = @_;
  932:     my %allnot;
  933:     my @critnot = split(/,/,$userenv->{'critnotification'});
  934:     my @regnot = split(/,/,$userenv->{'notification'});
  935:     foreach my $item (@critnot) {
  936:         $allnot{$item}{crit} = 1;
  937:     }
  938:     foreach my $item (@regnot) {
  939:         $allnot{$item}{reg} = 1;
  940:     }
  941:     return %allnot;
  942: }
  943: 
  944: sub verify_and_change_msgforward {
  945:     my $r = shift;
  946:     my $user       = $env{'user.name'};
  947:     my $domain     = $env{'user.domain'};
  948:     my $newscreen  = '';
  949:     my $message='';
  950:     foreach (split(/\,/,$env{'form.msgforward'})) {
  951: 	my ($msuser,$msdomain)=split(/[\@\:]/,$_);
  952:         $msuser = &LONCAPA::clean_username($msuser);
  953:         $msdomain = &LONCAPA::clean_domain($msdomain);
  954:         if (($msuser) && ($msdomain)) {
  955: 	    if (&Apache::lonnet::homeserver($msuser,$msdomain) ne 'no_host') {
  956:                $newscreen.=$msuser.':'.$msdomain.',';
  957: 	   } else {
  958:                $message.= &mt('No such user: ').'<tt>'.$msuser.':'.$msdomain.'</tt><br />';
  959:            }
  960:         }
  961:     }
  962:     $newscreen=~s/\,$//;
  963:     if ($newscreen) {
  964:         &Apache::lonnet::put('environment',{'msgforward' => $newscreen});
  965:         &Apache::lonnet::appenv({'environment.msgforward' => $newscreen});
  966:         $message .= &mt('Set message forwarding to ').'<tt>"'.$newscreen.'"</tt>.'
  967:                     .'<br />';
  968:     } else {
  969:         &Apache::lonnet::del('environment',['msgforward']);
  970:         &Apache::lonnet::delenv('environment.msgforward');
  971:         $message.= &mt("Set message forwarding to 'off'.").'<br />';
  972:     }
  973:     my $critnotification;
  974:     my $notification;
  975:     my $notify_with_html;
  976:     my $lastnotify = $env{'form.numnotify'}-1;
  977:     my $totaladdresses = 0;
  978:     for (my $i=0; $i<$env{'form.numnotify'}; $i++) {
  979:         if ((!defined($env{'form.del_notify_'.$i})) &&  
  980:            ((($i==$lastnotify) && ($env{'form.add_notify_'.$lastnotify} == 1)) ||
  981:             ($i<$lastnotify))) {
  982:             if (defined($env{'form.address_'.$i})) {
  983:                 if ($env{'form.notify_type_'.$i} eq 'all') {
  984:                     $critnotification .= $env{'form.address_'.$i}.',';
  985:                     $notification .= $env{'form.address_'.$i}.',';
  986:                 } elsif ($env{'form.notify_type_'.$i} eq 'crit') {
  987:                     $critnotification .= $env{'form.address_'.$i}.',';
  988:                 } elsif ($env{'form.notify_type_'.$i} eq 'reg') {
  989:                     $notification .= $env{'form.address_'.$i}.','; 
  990:                 }
  991:                 if ($env{'form.html_'.$i} eq '1') {
  992: 		    $notify_with_html .= $env{'form.address_'.$i}.',';       	
  993:                 }
  994:                 $totaladdresses ++;
  995:             }
  996:         }
  997:     }
  998:     $critnotification =~ s/,$//;
  999:     $critnotification=~s/\s//gs;
 1000:     $notification =~ s/,$//;
 1001:     $notification=~s/\s//gs;
 1002:     $notify_with_html =~ s/,$//;
 1003:     $notify_with_html =~ s/\s//gs;
 1004:     if ($notification) {
 1005:         &Apache::lonnet::put('environment',{'notification' => $notification});
 1006:         &Apache::lonnet::appenv({'environment.notification' => $notification});
 1007:         $message.=&mt('Set non-critical message notification address(es) to ').'<tt>"'.$notification.'"</tt>.<br />';
 1008:     } else {
 1009:         &Apache::lonnet::del('environment',['notification']);
 1010:         &Apache::lonnet::delenv('environment.notification');
 1011:         $message.=&mt("Set non-critical message notification to 'off'.").'<br />';
 1012:     }
 1013:     if ($critnotification) {
 1014:         &Apache::lonnet::put('environment',{'critnotification' => $critnotification});
 1015:         &Apache::lonnet::appenv({'environment.critnotification' => $critnotification});
 1016:         $message.=&mt('Set critical message notification address(es) to ').'<tt>"'.$critnotification.'"</tt>.<br />';
 1017:     } else {
 1018:         &Apache::lonnet::del('environment',['critnotification']);
 1019:         &Apache::lonnet::delenv('environment.critnotification');
 1020:         $message.=&mt("Set critical message notification to 'off'.").'<br />';
 1021:     }
 1022:     if ($critnotification || $notification) {
 1023:         if ($notify_with_html) {
 1024:             &Apache::lonnet::put('environment',{'notifywithhtml' => $notify_with_html});
 1025:             &Apache::lonnet::appenv({'environment.notifywithhtml' => $notify_with_html});
 1026:             $message.=&mt('Set address(es) to receive excerpts with html retained ').'<tt>"'.$notify_with_html.'"</tt>.';
 1027:         } else {
 1028:             &Apache::lonnet::del('environment',['notifywithhtml']);
 1029:             &Apache::lonnet::delenv('environment.notifywithhtml');
 1030:             if ($totaladdresses == 1) {
 1031:                 $message.=&mt("Set notification address to receive excerpts with html stripped.");
 1032:             } else {
 1033:                 $message.=&mt("Set all notification addresses to receive excerpts with html stripped.");
 1034:             }
 1035:         }
 1036:     } else {
 1037:         &Apache::lonnet::del('environment',['notifywithhtml']);
 1038:         &Apache::lonnet::delenv('environment.notifywithhtml');
 1039:     }
 1040:     if ($message) {
 1041:         $message .= '<br /><hr />';
 1042:     }
 1043:     &Apache::loncommon::flush_email_cache($user,$domain);
 1044:     &msgforwardchanger($r,$message);
 1045: }
 1046: 
 1047: ################################################################
 1048: #         Colors                                               #
 1049: ################################################################
 1050: 
 1051: sub colorschanger {
 1052:     my $r = shift;
 1053: # figure out colors
 1054:     my $function=&Apache::loncommon::get_users_function();
 1055:     my $domain=&Apache::loncommon::determinedomain();
 1056:     my %colortypes=('pgbg'  => 'Page Background Color',
 1057:                     'tabbg' => 'Header Background Color',
 1058:                     'sidebg'=> 'Header Border Color',
 1059:                     'font'  => 'Font Color',
 1060:                     'link'  => 'Un-Visited Link Color',
 1061:                     'vlink' => 'Visited Link Color',
 1062:                     'alink' => 'Active Link Color');
 1063:     my $start_data_table = &Apache::loncommon::start_data_table();
 1064:     my $chtable='';
 1065:     foreach my $item (sort(keys(%colortypes))) {
 1066:        my $curcol=&Apache::loncommon::designparm($function.'.'.$item,$domain);
 1067:        $chtable.=&Apache::loncommon::start_data_table_row().
 1068: 	   '<td>'.$colortypes{$item}.'</td><td style="background: '.$curcol.
 1069:         '">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</td><td><input name="'.$item.
 1070:         '" size="10" value="'.$curcol.
 1071: '" /></td><td><a href="javascript:pjump('."'color_custom','".$colortypes{$item}.
 1072: "','".$curcol."','"
 1073: 	    .$item."','parmform.pres','psub'".');">'.&mt('Select').'</a></td>'.
 1074: 	    &Apache::loncommon::end_data_table_row()."\n";
 1075:     }
 1076:     my $end_data_table = &Apache::loncommon::end_data_table();
 1077:     my $pjump_def = &Apache::lonhtmlcommon::pjump_javascript_definition();
 1078:     my $savebutton = &mt('Save');
 1079:     my $resetbutton = &mt('Reset All');
 1080:     my $resetbuttondesc = &mt('Reset All Colors to Default');
 1081:     $r->print(<<ENDCOL);
 1082: <script type="text/javascript">
 1083: 
 1084:     function pclose() {
 1085:         parmwin=window.open("/adm/rat/empty.html","LONCAPAparms",
 1086:                  "height=350,width=350,scrollbars=no,menubar=no");
 1087:         parmwin.close();
 1088:     }
 1089: 
 1090:     $pjump_def
 1091: 
 1092:     function psub() {
 1093:         pclose();
 1094:         if (document.parmform.pres_marker.value!='') {
 1095:             if (document.parmform.pres_type.value!='') {
 1096:                 eval('document.prefs.'+
 1097:                      document.parmform.pres_marker.value+
 1098: 		     '.value=document.parmform.pres_value.value;');
 1099: 	    }
 1100:         } else {
 1101:             document.parmform.pres_value.value='';
 1102:             document.parmform.pres_marker.value='';
 1103:         }
 1104:     }
 1105: 
 1106: 
 1107: </script>
 1108: <form name="parmform">
 1109: <input type="hidden" name="pres_marker" />
 1110: <input type="hidden" name="pres_type" />
 1111: <input type="hidden" name="pres_value" />
 1112: </form>
 1113: <form name="prefs" action="/adm/preferences" method="post">
 1114: <input type="hidden" name="action" value="verify_and_change_colors" />
 1115: $start_data_table
 1116: $chtable
 1117: $end_data_table
 1118: </table>
 1119: <input type="submit" value="$savebutton" />
 1120: <input type="submit" name="resetall" value="$resetbutton" title="$resetbuttondesc" />
 1121: </form>
 1122: ENDCOL
 1123: }
 1124: 
 1125: sub verify_and_change_colors {
 1126:     my $r = shift;
 1127: # figure out colors
 1128:     my $function=&Apache::loncommon::get_users_function();
 1129:     my $domain=&Apache::loncommon::determinedomain();
 1130:     my %colortypes=('pgbg'  => 'Page Background Color',
 1131:                     'tabbg' => 'Header Background Color',
 1132:                     'sidebg'=> 'Header Border Color',
 1133:                     'font'  => 'Font Color',
 1134:                     'link'  => 'Un-Visited Link Color',
 1135:                     'vlink' => 'Visited Link Color',
 1136:                     'alink' => 'Active Link Color');
 1137: 
 1138:     my $message='';
 1139:     foreach my $item (keys %colortypes) {
 1140:         my $color=$env{'form.'.$item};
 1141:         my $entry='color.'.$function.'.'.$item;
 1142: 	if (($color=~/^\#[0-9A-Fa-f]{6}$/) && (!$env{'form.resetall'})) {
 1143: 	    &Apache::lonnet::put('environment',{$entry => $color});
 1144: 	    &Apache::lonnet::appenv({'environment.'.$entry => $color});
 1145:             $message.=&Apache::lonhtmlcommon::confirm_success(&mt('Set [_1] to [_2]','<i>'.$colortypes{$item}.'</i>','<tt>"'.$color.'"</tt>'))
 1146:                     .'<br />';
 1147: 	} else {
 1148: 	    &Apache::lonnet::del('environment',[$entry]);
 1149: 	    &Apache::lonnet::delenv('environment.'.$entry);
 1150:             $message.=&Apache::lonhtmlcommon::confirm_success(&mt('Reset [_1]','<i>'.$colortypes{$item}.'</i>'))
 1151:                      .'<br />';
 1152: 	}
 1153:     }
 1154:     $message=&Apache::loncommon::confirmwrapper($message);
 1155: 
 1156:     my $now = time;
 1157:     &Apache::lonnet::put('environment',{'color.timestamp' => $now});
 1158:     &Apache::lonnet::appenv({'environment.color.timestamp' => $now});
 1159: 
 1160:     $r->print(<<ENDVCCOL);
 1161: $message
 1162: <form name="client" action="/adm/preferences" method="post">
 1163: <input type="hidden" name="action" value="changecolors" />
 1164: </form>
 1165: ENDVCCOL
 1166: }
 1167: 
 1168: ######################################################
 1169: #            password handler subroutines            #
 1170: ######################################################
 1171: sub passwordchanger {
 1172:     my ($r,$errormessage,$caller,$mailtoken) = @_;
 1173:     # This function is a bit of a mess....
 1174:     # Passwords are encrypted using londes.js (DES encryption)
 1175:     $errormessage = ($errormessage || '');
 1176:     my ($user,$domain,$currentpass,$defdom);
 1177:     if ((!defined($caller)) || ($caller eq 'preferences')) {
 1178:         $user = $env{'user.name'};
 1179:         $domain = $env{'user.domain'};
 1180:         if (!defined($caller)) {
 1181:             $caller = 'preferences';
 1182:         }
 1183:     } elsif ($caller eq 'reset_by_email') {
 1184:             $defdom = $r->dir_config('lonDefDomain');
 1185:             my %data = &Apache::lonnet::tmpget($mailtoken);
 1186:             if (keys(%data) == 0) {
 1187:                 $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.',
 1188:                           '<a href="/adm/resetpw">','</a>')
 1189:                 );
 1190:                 return;
 1191:             }
 1192:             if (defined($data{time})) {
 1193:                 if (time - $data{'time'} < 7200) {
 1194:                     $user = $data{'username'};
 1195:                     $domain = $data{'domain'};
 1196:                     $currentpass = $data{'temppasswd'};
 1197:                 } else {
 1198:                     $r->print(&mt('Sorry, the token generated when you requested a password reset has expired.').'<br />');
 1199:                     return;
 1200:                 }
 1201:             } else {
 1202:                 $r->print(&mt('Sorry, the URL generated when you requested reset of your password contained incomplete information.').'<br />');
 1203:                 return;
 1204:             }
 1205:    } else {
 1206:         $r->print(&mt('Page requested in unexpected context').'<br />');
 1207:         return;
 1208:     }
 1209:     my $currentauth=&Apache::lonnet::queryauthenticate($user,$domain);
 1210:     # Check for authentication types that allow changing of the password.
 1211:     return if ($currentauth !~ /^(unix|internal):/);
 1212:     #
 1213:     # Generate keys
 1214:     my ($lkey_cpass ,$ukey_cpass ) = &des_keys();
 1215:     my ($lkey_npass1,$ukey_npass1) = &des_keys();
 1216:     my ($lkey_npass2,$ukey_npass2) = &des_keys();
 1217:     # Store the keys in the log files
 1218:     my $lonhost = $r->dir_config('lonHostID');
 1219:     my $logtoken=Apache::lonnet::reply('tmpput:'
 1220: 				       .$ukey_cpass  . $lkey_cpass .'&'
 1221: 				       .$ukey_npass1 . $lkey_npass1.'&'
 1222: 				       .$ukey_npass2 . $lkey_npass2,
 1223: 				       $lonhost);
 1224:     # Hexify the keys for output as javascript variables
 1225:     my %hexkey;
 1226:     $hexkey{'ukey_cpass'}  = hex($ukey_cpass);
 1227:     $hexkey{'lkey_cpass'}  = hex($lkey_cpass);
 1228:     $hexkey{'ukey_npass1'} = hex($ukey_npass1);
 1229:     $hexkey{'lkey_npass1'} = hex($lkey_npass1);
 1230:     $hexkey{'ukey_npass2'} = hex($ukey_npass2);
 1231:     $hexkey{'lkey_npass2'} = hex($lkey_npass2);
 1232:     # Output javascript to deal with passwords
 1233:     # Output DES javascript
 1234:     {
 1235: 	my $include = $r->dir_config('lonIncludes');
 1236: 	my $jsh=Apache::File->new($include."/londes.js");
 1237: 	$r->print(<$jsh>);
 1238:     }
 1239:     $r->print(&jscript_send($caller));
 1240:     $r->print(<<ENDFORM);
 1241: $errormessage
 1242: 
 1243: <p>
 1244: <!-- We separate the forms into 'server' and 'client' in order to
 1245:      ensure that unencrypted passwords will not be sent out by a
 1246:      crappy browser -->
 1247: ENDFORM
 1248:     $r->print(&server_form($logtoken,$caller,$mailtoken));
 1249:     $r->print(&client_form($caller,\%hexkey,$currentpass,$defdom));
 1250: 
 1251:     #
 1252:     return;
 1253: }
 1254: 
 1255: sub jscript_send {
 1256:     my ($caller) = @_;
 1257:     my $output = qq|
 1258: <script language="JavaScript">
 1259: 
 1260:     function send() {
 1261:         uextkey=this.document.client.elements.ukey_cpass.value;
 1262:         lextkey=this.document.client.elements.lkey_cpass.value;
 1263:         initkeys();
 1264: 
 1265:         this.document.pserver.elements.currentpass.value
 1266:             =crypted(this.document.client.elements.currentpass.value);
 1267: 
 1268:         uextkey=this.document.client.elements.ukey_npass1.value;
 1269:         lextkey=this.document.client.elements.lkey_npass1.value;
 1270:         initkeys();
 1271:         this.document.pserver.elements.newpass_1.value
 1272:             =crypted(this.document.client.elements.newpass_1.value);
 1273: 
 1274:         uextkey=this.document.client.elements.ukey_npass2.value;
 1275:         lextkey=this.document.client.elements.lkey_npass2.value;
 1276:         initkeys();
 1277:         this.document.pserver.elements.newpass_2.value
 1278:             =crypted(this.document.client.elements.newpass_2.value);
 1279: |;
 1280:     if ($caller eq 'reset_by_email') {
 1281:         $output .= qq|
 1282:         this.document.pserver.elements.uname.value =
 1283:                    this.document.client.elements.uname.value;
 1284:         this.document.pserver.elements.udom.value =
 1285:                    this.document.client.elements.udom.options[this.document.client.elements.udom.selectedIndex].value;
 1286: |;
 1287:     }
 1288:     $ output .= qq|
 1289:         this.document.pserver.submit();
 1290:     }
 1291: </script>
 1292: |;
 1293: }
 1294: 
 1295: sub client_form {
 1296:     my ($caller,$hexkey,$currentpass,$defdom) = @_;
 1297:     my %lt=&Apache::lonlocal::texthash(
 1298:                 'email' => 'E-mail Address',
 1299:                 'username' => 'Username',
 1300:                 'domain' => 'Domain',
 1301:                 'currentpass' => 'Current Password',
 1302:                 'newpass' => 'New Password',
 1303:                 'confirmpass' => 'Confirm Password',
 1304:                 'changepass' => 'Save');
 1305: 
 1306:     my $output = qq|
 1307: <form name="client" >
 1308: <table>
 1309: |;
 1310:     if ($caller eq 'reset_by_email') {
 1311:         $output .= qq|
 1312: <tr><td class="LC_preferences_labeltext"><label for="email">$lt{'email'}</label>:</td>
 1313:     <td><input type="text" name="email" size="30" /> </td></tr>
 1314: <tr><td class="LC_preferences_labeltext"><label for="uname">$lt{'username'}</label>:</td>
 1315:     <td>
 1316:      <input type="text" name="uname" size="15" />
 1317:      <input type="hidden" name="currentpass" value="$currentpass" />
 1318:     </td></tr>
 1319: <tr><td class="LC_preferences_labeltext"><label for="udom">$lt{'domain'}</label>:</td>
 1320:     <td>
 1321: |;
 1322:         $output .= &Apache::loncommon::select_dom_form($defdom,'udom').'
 1323:    </td>
 1324: </tr>
 1325: ';
 1326:     } else {
 1327:         $output .= qq|
 1328: <tr><td class="LC_preferences_labeltext"><label for="currentpass">$lt{'currentpass'}</label></td>
 1329:     <td><input type="password" name="currentpass" size="10"/> </td></tr>
 1330: |;
 1331:     }
 1332:     $output .= <<"ENDFORM";
 1333: <tr><td class="LC_preferences_labeltext"><label for="newpass_1">$lt{'newpass'}</label></td>
 1334:     <td><input type="password" name="newpass_1" size="10"  /> </td></tr>
 1335: <tr><td class="LC_preferences_labeltext"><label for="newpass_2">$lt{'confirmpass'}</label></td>
 1336:     <td><input type="password" name="newpass_2" size="10"  /> </td></tr>
 1337: <tr><td colspan="2" align="center">
 1338:     <input type="button" value="$lt{'changepass'}" onClick="send();" />
 1339: </table>
 1340: <input type="hidden" name="ukey_cpass"  value="$hexkey->{'ukey_cpass'}" />
 1341: <input type="hidden" name="lkey_cpass"  value="$hexkey->{'lkey_cpass'}" />
 1342: <input type="hidden" name="ukey_npass1" value="$hexkey->{'ukey_npass1'}" />
 1343: <input type="hidden" name="lkey_npass1" value="$hexkey->{'lkey_npass1'}" />
 1344: <input type="hidden" name="ukey_npass2" value="$hexkey->{'ukey_npass2'}" />
 1345: <input type="hidden" name="lkey_npass2" value="$hexkey->{'lkey_npass2'}" />
 1346: </form>
 1347: </p>
 1348: ENDFORM
 1349:     return $output;
 1350: }
 1351: 
 1352: sub server_form {
 1353:     my ($logtoken,$caller,$mailtoken) = @_;
 1354:     my $action = '/adm/preferences';
 1355:     if ($caller eq 'reset_by_email') {
 1356:         $action = '/adm/resetpw';
 1357:     }
 1358:     my $output = qq|
 1359: <form name="pserver" action="$action" method="post">
 1360: <input type="hidden" name="logtoken"    value="$logtoken" />
 1361: <input type="hidden" name="currentpass" value="" />
 1362: <input type="hidden" name="newpass_1"   value="" />
 1363: <input type="hidden" name="newpass_2"   value="" />
 1364:     |;
 1365:     if ($caller eq 'reset_by_email') {
 1366:         $output .=  qq|
 1367: <input type="hidden" name="token"   value="$mailtoken" />
 1368: <input type="hidden" name="uname"   value="" />
 1369: <input type="hidden" name="udom"   value="" />
 1370: 
 1371: |;
 1372:     }
 1373:     $output .= qq|
 1374: <input type="hidden" name="action" value="verify_and_change_pass" />
 1375: </form>
 1376: |;
 1377:     return $output;
 1378: }
 1379: 
 1380: sub verify_and_change_password {
 1381:     my ($r,$caller,$mailtoken) = @_;
 1382:     my ($user,$domain,$homeserver);
 1383:     if ($caller eq 'reset_by_email') {
 1384:         $user       = $env{'form.uname'};
 1385:         $domain     = $env{'form.udom'};
 1386:         if ($user ne '' && $domain ne '') {
 1387:             $homeserver = &Apache::lonnet::homeserver($user,$domain);
 1388:             if ($homeserver eq 'no_host') {
 1389:         &passwordchanger($r,"<p>\n<span class='LC_error'>".
 1390:                          &mt("Invalid username and/or domain")."</span>\n</p>",
 1391:                          $caller,$mailtoken);
 1392:                 return 1;
 1393:             }
 1394:         } else {
 1395:             &passwordchanger($r,"<p>\n<span class='LC_error'>".
 1396:                              &mt("Username and domain were blank")."</span>\n</p>",
 1397:                              $caller,$mailtoken);
 1398:             return 1;
 1399:         }
 1400:     } else {
 1401:         $user       = $env{'user.name'};
 1402:         $domain     = $env{'user.domain'};
 1403:         $homeserver = $env{'user.home'};
 1404:     }
 1405:     my $currentauth=&Apache::lonnet::queryauthenticate($user,$domain);
 1406:     # Check for authentication types that allow changing of the password.
 1407:     if ($currentauth !~ /^(unix|internal):/) {
 1408:         if ($caller eq 'reset_by_email') {
 1409:             &passwordchanger($r,"<p>\n<span class='LC_error'>".
 1410:                              &mt("Authentication type for this user can not be changed by this mechanism").
 1411:                              "</span>\n</p>",
 1412:                               $caller,$mailtoken);
 1413:             return 1;
 1414:         } else {
 1415:             return;
 1416:         }
 1417:     }
 1418:     #
 1419:     my $currentpass = $env{'form.currentpass'}; 
 1420:     my $newpass1    = $env{'form.newpass_1'}; 
 1421:     my $newpass2    = $env{'form.newpass_2'};
 1422:     my $logtoken    = $env{'form.logtoken'};
 1423:     # Check for empty data 
 1424:     unless (defined($currentpass) && 
 1425: 	    defined($newpass1)    && 
 1426: 	    defined($newpass2)    ){
 1427: 	&passwordchanger($r,"<p>\n<span class='LC_error'>".
 1428: 			 &mt("One or more password fields were blank").
 1429:                          "</span>\n</p>",$caller,$mailtoken);
 1430: 	return;
 1431:     }
 1432:     # Get the keys
 1433:     my $lonhost = $r->dir_config('lonHostID');
 1434:     my $tmpinfo = Apache::lonnet::reply('tmpget:'.$logtoken,$lonhost);
 1435:     if (($tmpinfo=~/^error/) || ($tmpinfo eq 'con_lost')) {
 1436:         # I do not a have a better idea about how to handle this
 1437:         my $tryagain_text = &mt('Please log out and try again.');
 1438:         if ($caller eq 'reset_by_email') {
 1439:             $tryagain_text = &mt('Please try again later.');
 1440:         }
 1441:         my $unable=&mt("Unable to retrieve saved token for password decryption");
 1442: 	$r->print(<<ENDERROR);
 1443: <p>
 1444: <span class="LC_error">$unable.  $tryagain_text</span>
 1445: </p>
 1446: ENDERROR
 1447:         # Probably should log an error here
 1448:         return 1;
 1449:     }
 1450:     my ($ckey,$n1key,$n2key)=split(/&/,$tmpinfo);
 1451:     # 
 1452:     $currentpass = &des_decrypt($ckey ,$currentpass);
 1453:     $newpass1    = &des_decrypt($n1key,$newpass1);
 1454:     $newpass2    = &des_decrypt($n2key,$newpass2);
 1455:     #
 1456:     if ($caller eq 'reset_by_email') {
 1457:         my %data = &Apache::lonnet::tmpget($mailtoken);
 1458:         if (keys(%data) == 0) {
 1459:             &passwordchanger($r,
 1460:                          '<span class="LC_error">'.
 1461:                          &mt('Could not verify current authentication.').'  '.
 1462:                          &mt('Please try again.').'</span>',$caller,$mailtoken);
 1463:             return 1;
 1464:         }
 1465:         if ($currentpass ne $data{'temppasswd'}) {
 1466:             &passwordchanger($r,
 1467:                          '<span class="LC_error">'.
 1468:                          &mt('Could not verify current authentication.').'  '.
 1469:                          &mt('Please try again.').'</span>',$caller,$mailtoken);
 1470:             return 1;
 1471:         }
 1472:     } 
 1473:     if ($newpass1 ne $newpass2) {
 1474: 	&passwordchanger($r,
 1475: 			 '<span class="LC_error">'.
 1476: 			 &mt('The new passwords you entered do not match.').'  '.
 1477: 			 &mt('Please try again.').'</span>',$caller,$mailtoken);
 1478: 	return 1;
 1479:     }
 1480:     if (length($newpass1) < 7) {
 1481: 	&passwordchanger($r,
 1482: 			 '<span class="LC_error">'.
 1483: 			 &mt('Passwords must be a minimum of 7 characters long.').'  '.
 1484: 			 &mt('Please try again.').'</span>',$caller,$mailtoken);
 1485: 	return 1;
 1486:     }
 1487:     #
 1488:     # Check for bad characters
 1489:     my $badpassword = 0;
 1490:     foreach (split(//,$newpass1)) {
 1491: 	$badpassword = 1 if ((ord($_)<32)||(ord($_)>126));
 1492:     }
 1493:     if ($badpassword) {
 1494: 	# I can't figure out how to enter bad characters on my browser.
 1495: 	my $errormessage ='<span class="LC_error">'.
 1496:            &mt('The password you entered contained illegal characters.').'<br />'.
 1497:            &mt('Valid characters are').(<<"ENDERROR");
 1498: : space and <br />
 1499: <pre>
 1500: !&quot;\#$%&amp;\'()*+,-./0123456789:;&lt;=&gt;?\@
 1501: ABCDEFGHIJKLMNOPQRSTUVWXYZ[\]^_\`abcdefghijklmnopqrstuvwxyz{|}~
 1502: </pre></span>
 1503: ENDERROR
 1504:         &passwordchanger($r,$errormessage,$caller,$mailtoken);
 1505:         return 1;
 1506:     }
 1507:     # 
 1508:     # Change the password (finally)
 1509:     my $result = &Apache::lonnet::changepass
 1510: 	($user,$domain,$currentpass,$newpass1,$homeserver,$caller);
 1511:     # Inform the user the password has (not?) been changed
 1512:     if ($result =~ /^ok$/) {
 1513:         $message = &Apache::lonhtmlcommon::confirm_success(&mt('The password for user [_1] was successfully changed.','<i>'.$user.'<i>'));
 1514:         if ($caller eq 'reset_by_email') {
 1515:             $r->print($message.'<br />');
 1516:         } else {
 1517:             $r->print(&Apache::loncommon::confirmwrapper($message));
 1518:         }
 1519:     } else {
 1520: 	# error error: run in circles, scream and shout
 1521:         $message = &Apache::lonhtmlcommon::confirm_success(
 1522:                    &mt("The password for user [_1] was not changed.",'<i>'.$user.'</i>').' '.&mt('Please make sure your old password was entered correctly.'),1);
 1523:         if ($caller eq 'reset_by_email') {
 1524:             $r->print($message.'<br />');
 1525:         } else {
 1526:             $r->print(&Apache::loncommon::confirmwrapper($message));
 1527:         }
 1528:         return 1;
 1529:     }
 1530:     return;
 1531: }
 1532: 
 1533: ################################################################
 1534: #            discussion display subroutines 
 1535: ################################################################
 1536: sub discussionchanger {
 1537:     my $r = shift;
 1538:     my $user       = $env{'user.name'};
 1539:     my $domain     = $env{'user.domain'};
 1540:     my %userenv = &Apache::lonnet::get
 1541:         ('environment',['discdisplay','discmarkread']);
 1542:     my $discdisp = 'allposts';
 1543:     my $discmark = 'onmark';
 1544: 
 1545:     if (defined($userenv{'discdisplay'})) {
 1546:         unless ($userenv{'discdisplay'} eq '') { 
 1547:             $discdisp = $userenv{'discdisplay'};
 1548:         }
 1549:     }
 1550:     if (defined($userenv{'discmarkread'})) {
 1551:         unless ($userenv{'discdisplay'} eq '') { 
 1552:             $discmark = $userenv{'discmarkread'};
 1553:         }
 1554:     }
 1555: 
 1556:     my $newdisp = 'unread';
 1557:     my $newmark = 'ondisp';
 1558: 
 1559:     my $function = &Apache::loncommon::get_users_function();
 1560:     my $color = &Apache::loncommon::designparm($function.'.tabbg',
 1561:                                                     $env{'user.domain'});
 1562:     my %lt = &Apache::lonlocal::texthash(
 1563:         'pref' => 'Display Preference',
 1564:         'curr' => 'Current setting ',
 1565:         'actn' => 'Action',
 1566:         'sdpf' => 'Set display preferences for discussion posts for both discussion boards and individual resources in all your courses.',
 1567:         'prca' => 'Preferences can be set that determine',
 1568:         'whpo' => 'Which posts are displayed when you display a discussion board or resource, and',
 1569:         'unwh' => 'Under what circumstances posts are identfied as "New"',
 1570:         'allposts' => 'All posts',
 1571:         'unread' => 'New posts only',
 1572:         'ondisp' => 'Once displayed',
 1573:         'onmark' => 'Once marked as read',
 1574:         'disa' => 'Posts displayed?',
 1575:         'npmr' => 'New posts cease to be identified as "New"?',
 1576:         'thde'  => 'The preferences you set here can be overridden within each individual discussion.',
 1577:         'chgt' => 'Change to ',
 1578:     );
 1579:     my $dispchange = $lt{'unread'};
 1580:     my $markchange = $lt{'ondisp'};
 1581:     my $currdisp = $lt{'allposts'};
 1582:     my $currmark = $lt{'onmark'};
 1583: 
 1584:     if ($discdisp eq 'unread') {
 1585:         $dispchange = $lt{'allposts'};
 1586:         $currdisp = $lt{'unread'};
 1587:         $newdisp = 'allposts';
 1588:     }
 1589: 
 1590:     if ($discmark eq 'ondisp') {
 1591:         $markchange = $lt{'onmark'};
 1592:         $currmark = $lt{'ondisp'};
 1593:         $newmark = 'onmark';
 1594:     }
 1595:     
 1596:     $r->print(<<"END");
 1597: <form name="prefs" action="/adm/preferences" method="post">
 1598: <input type="hidden" name="action" value="verify_and_change_discussion" />
 1599: <br />
 1600: $lt{'sdpf'}<br /> $lt{'prca'}  <ol><li>$lt{'whpo'}</li><li>$lt{'unwh'}</li></ol> 
 1601: END
 1602:     $r->print('<p class="LC_info">'.$lt{'thde'}.'</p>');
 1603: 
 1604:     $r->print(&Apache::loncommon::start_data_table());
 1605:     $r->print(<<"END");
 1606:        <tr>
 1607:         <th>$lt{'pref'}</th>
 1608:         <th>$lt{'curr'}</th>
 1609:         <th>$lt{'actn'}?</th>
 1610:        </tr>
 1611: END
 1612:     $r->print(&Apache::loncommon::start_data_table_row());
 1613:     $r->print(<<"END");
 1614:        <td>$lt{'disa'}</td>
 1615:        <td>$lt{$discdisp}</td>
 1616:        <td><label><input type="checkbox" name="discdisp" /><input type="hidden" name="newdisp" value="$newdisp" />&nbsp;$lt{'chgt'} "$dispchange"</label></td>
 1617: END
 1618:     $r->print(&Apache::loncommon::end_data_table_row().
 1619: 	      &Apache::loncommon::start_data_table_row());
 1620:     $r->print(<<"END");
 1621:        <td>$lt{'npmr'}</td>
 1622:        <td>$lt{$discmark}</td>
 1623:        <td><label><input type="checkbox" name="discmark" /><input type="hidden" name="newmark" value="$newmark" />&nbsp;$lt{'chgt'} "$markchange"</label></td>
 1624:       </tr>
 1625: END
 1626:     $r->print(&Apache::loncommon::end_data_table_row().
 1627: 	      &Apache::loncommon::end_data_table());
 1628:     $r->print('<br />'.
 1629:               '<input type="submit" name="sub" value="'.&mt('Save').'" />'.
 1630:               '</form>');
 1631: }
 1632:                                                                                                                 
 1633: sub verify_and_change_discussion {
 1634:     my $r = shift;
 1635:     my $user     = $env{'user.name'};
 1636:     my $domain   = $env{'user.domain'};
 1637:     my $message='';
 1638:     if (defined($env{'form.discdisp'}) ) {
 1639:         my $newdisp  = $env{'form.newdisp'};
 1640:         if ($newdisp eq 'unread') {
 1641:             $message .=&mt('In discussions: only new posts will be displayed.').'<br />';
 1642:             &Apache::lonnet::put('environment',{'discdisplay' => $newdisp});
 1643:             &Apache::lonnet::appenv({'environment.discdisplay' => $newdisp});
 1644:         } else {
 1645:             $message .= &mt('In discussions: all posts will be displayed.').'<br />';
 1646:             &Apache::lonnet::del('environment',['discdisplay']);
 1647:             &Apache::lonnet::delenv('environment.discdisplay');
 1648:         }
 1649:     }
 1650:     if (defined($env{'form.discmark'}) ) {
 1651:         my $newmark = $env{'form.newmark'};
 1652:         if ($newmark eq 'ondisp') {
 1653:             $message.=&Apache::lonhtmlcommon::confirm_success(&mt('In discussions: new posts will be cease to be identified as "NEW" after display.')).'<br />';
 1654:             &Apache::lonnet::put('environment',{'discmarkread' => $newmark});
 1655:             &Apache::lonnet::appenv({'environment.discmarkread' => $newmark});
 1656:         } else {
 1657:             $message.=&Apache::lonhtmlcommon::confirm_success(&mt('In discussions: posts will be identified as "NEW" until marked as read by the reader.')).'<br />';
 1658:             &Apache::lonnet::del('environment',['discmarkread']);
 1659:             &Apache::lonnet::delenv('environment.discmarkread');
 1660:         }
 1661:     }
 1662:     $message=&Apache::loncommon::confirmwrapper($message);
 1663:     $r->print(<<ENDVCSCREEN);
 1664: $message
 1665: ENDVCSCREEN
 1666: }
 1667: 
 1668: ################################################################
 1669: # Subroutines for page display on course access (Course Coordinators)
 1670: ################################################################
 1671: sub coursedisplaychanger {
 1672:     my $r = shift;
 1673:     my $user       = $env{'user.name'};
 1674:     my $domain     = $env{'user.domain'};
 1675:     my %userenv = &Apache::lonnet::get('environment',['course_init_display']);
 1676:     my $currvalue = 'whatsnew';
 1677:     my $firstselect = '';
 1678:     my $whatsnewselect = 'checked="checked"';
 1679:     if (exists($userenv{'course_init_display'})) {
 1680:         if ($userenv{'course_init_display'} eq 'firstres') {
 1681:             $currvalue = 'firstres';
 1682:             $firstselect = 'checked="checked"';
 1683: 	    $whatsnewselect = '';
 1684:         }
 1685:     }
 1686:     my %pagenames = (
 1687:                        firstres => 'First resource',
 1688:                        whatsnew => "What's New Page",
 1689:                     );
 1690:     my $whatsnew_off=&mt('Display the [_1]first resource[_2] in the course.','<b>','</b>');
 1691:     my $whatsnew_on=&mt("Display the [_1]What's New Page[_2] - a summary of items in the course which require attention.",'<b>','</b>');
 1692: 
 1693:     $r->print('<br /><b>'.
 1694:               &mt('Set the default page to be displayed when you select a course role').
 1695:               '</b>&nbsp;'.
 1696:               &mt('(Currently: [_1])',$pagenames{$currvalue}).'<br />'.
 1697:               &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>').
 1698:               '<br /><br />');
 1699:     $r->print(<<ENDLSCREEN);
 1700: <form name="prefs" action="/adm/preferences" method="post">
 1701: <input type="hidden" name="action" value="verify_and_change_coursepage" />
 1702: <br />
 1703: <label><input type="radio" name="newdisp" value="firstres" $firstselect /> $whatsnew_off</label><br />
 1704: <label><input type="radio" name="newdisp" value="whatsnew" $whatsnewselect /> $whatsnew_on</label><input type="hidden" name="refpage" value="$env{'form.refpage'}" />
 1705: ENDLSCREEN
 1706:     $r->print('<br /><br /><input type="submit" value="'.&mt('Save').'" />
 1707: </form>');
 1708: }
 1709: 
 1710: sub verify_and_change_coursepage {
 1711:     my $r = shift;
 1712:     my $message='';
 1713:     my %lt = &Apache::lonlocal::texthash(
 1714:         'defs' => 'Default now set',
 1715:         'when' => 'when you select a course role from the roles screen',
 1716:         'ywbt' => 'you will be taken to the start of the course.',
 1717:         'apwb' => 'a page will be displayed that lists items in the course that may require action from you.',
 1718:         'gtts' => 'Go to the start of the course',
 1719:         'dasp' => "Display the What's New Page", 
 1720:     );
 1721:     my $newdisp  = $env{'form.newdisp'};
 1722:     $message = '<b>'.$lt{'defs'}.'</b>: '.$lt{'when'}.', ';
 1723:     if ($newdisp eq 'firstres') {
 1724:         $message .= $lt{'ywbt'}.'<br />';
 1725:         &Apache::lonnet::put('environment',{'course_init_display' => $newdisp});
 1726:         &Apache::lonnet::appenv({'environment.course_init_display' => $newdisp});
 1727:     } else {
 1728:         $message .= $lt{'apwb'}.'<br />';
 1729:         &Apache::lonnet::del('environment',['course_init_display']);
 1730:         &Apache::lonnet::delenv('environment.course_init_display');
 1731:     }
 1732:     my $refpage = $env{'form.refpage'};
 1733:     if (($env{'request.course.fn'}) && ($env{'request.course.id'})) {
 1734:         if ($newdisp eq 'firstres') {
 1735:             my $cdom = $env{'course.'.$env{'request.course.id'}.'.domain'};
 1736:             my $cnum = $env{'course.'.$env{'request.course.id'}.'.num'}; 
 1737:             my ($furl,$ferr)=
 1738:                 &Apache::lonuserstate::readmap($cdom.'/'.$cnum);
 1739:             $message .= '<br /><font size="+1"><a href="'.$furl.'">'.$lt{'gtts'}.' <i>'.&mt('now').'</i></a></font>';
 1740:         } else {
 1741:             $message .= '<br /><font size="+1"><a href="/adm/whatsnew?refpage='.
 1742:                         $refpage.'">'.$lt{'dasp'}.'</a></font>';
 1743:         }
 1744:     }
 1745:     $message = &Apache::lonhtmlcommon::confirm_success($message)
 1746:     $r->print(<<ENDVCSCREEN);
 1747: $message
 1748: ENDVCSCREEN
 1749: }
 1750: 
 1751: 
 1752: ######################################################
 1753: #            other handler subroutines               #
 1754: ######################################################
 1755: 
 1756: ################################################################
 1757: #                          Main handler                        #
 1758: ################################################################
 1759: sub handler {
 1760:     my $r = shift;
 1761:     my $user = $env{'user.name'};
 1762:     my $domain = $env{'user.domain'};
 1763:     &Apache::loncommon::content_type($r,'text/html');
 1764:     # Some pages contain DES keys and should not be cached.
 1765:     &Apache::loncommon::no_cache($r);
 1766:     $r->send_http_header;
 1767:     return OK if $r->header_only;
 1768:     #
 1769:     &Apache::loncommon::get_unprocessed_cgi($ENV{'QUERY_STRING'},
 1770:                                    ['action','wysiwyg','returnurl','refpage']);
 1771:     #
 1772:     &Apache::lonhtmlcommon::clear_breadcrumbs();
 1773:     &Apache::lonhtmlcommon::add_breadcrumb
 1774:         ({href => '/adm/preferences',
 1775:           text => 'Set User Preferences'});
 1776: 
 1777:     my @Options;
 1778:     # Determine current authentication method
 1779:     my $currentauth=&Apache::lonnet::queryauthenticate($user,$domain);
 1780:     if ($currentauth =~ /^(unix|internal):/) {
 1781:         push (@Options,({ action   => 'changepass',
 1782:                           linktext => 'Change Password',
 1783:                           href     => '/adm/preferences',
 1784:                           help     => 'Change_Password',
 1785:                           subroutine => \&passwordchanger,
 1786:                           breadcrumb => 
 1787:                               { href => '/adm/preferences?action=changepass',
 1788:                                 text => 'Change Password'},
 1789:                           },
 1790:                         { action => 'verify_and_change_pass',
 1791:                           subroutine => \&verify_and_change_password,
 1792:                           breadcrumb => 
 1793:                               { href =>'/adm/preferences?action=changepass',
 1794:                                 text => 'Change Password'},
 1795:                           printmenu => 'not_on_error',
 1796:                           }));
 1797:     }
 1798:     push (@Options,({ action   => 'changescreenname',
 1799:                       linktext => 'Change Screen Name',
 1800:                       href     => '/adm/preferences',
 1801:                       help     => 'Prefs_Screen_Name_Nickname',
 1802:                       subroutine => \&screennamechanger,
 1803:                       breadcrumb => 
 1804:                           { href => '/adm/preferences?action=changescreenname',
 1805:                             text => 'Change Screen Name'},
 1806:                       },
 1807:                     { action   => 'verify_and_change_screenname',
 1808:                       subroutine => \&verify_and_change_screenname,
 1809:                       breadcrumb => 
 1810:                           { href => '/adm/preferences?action=changescreenname',
 1811:                             text => 'Change Screen Name'},
 1812:                       printmenu => 'yes',
 1813:                       }));
 1814: 
 1815:     push (@Options,({ action   => 'changemsgforward',
 1816:                       linktext => 'Messages &amp; Notifications',
 1817:                       href     => '/adm/preferences',
 1818:                       help     => 'Prefs_Messages',
 1819:                       breadcrumb => 
 1820:                           { href => '/adm/preferences?action=changemsgforward',
 1821:                             text => 'Change Message Forwarding/Notification'},
 1822:                       subroutine => \&msgforwardchanger,
 1823:                       },
 1824:                     { action => 'verify_and_change_msgforward',
 1825:                       help   => 'Prefs_Messages',
 1826:                       breadcrumb => 
 1827:                           { href => '/adm/preferences?action=changemsgforward',
 1828:                             text => 'Change Message Forwarding/Notification'},
 1829:                       printmenu => 'no',
 1830:                       subroutine => \&verify_and_change_msgforward }));
 1831:     if (&Apache::lonnet::usertools_access($user,$domain,'aboutme')) {
 1832:         my $aboutmeaction = '/adm/'.$domain.'/'.$user.'/aboutme';
 1833:         push (@Options,{ action   => 'none', 
 1834:                          linktext =>"Edit the Personal Information Page",
 1835:                          help     => 'Prefs_About_Me',
 1836:                          href => $aboutmeaction});
 1837:     }
 1838:     push (@Options,({ action => 'changecolors',
 1839:                       linktext => 'Change Color Scheme',
 1840:                       href => '/adm/preferences',
 1841:                       help => 'Change_Colors',
 1842:                       breadcrumb => 
 1843:                           { href => '/adm/preferences?action=changecolors',
 1844:                             text => 'Change Colors'},
 1845:                       subroutine => \&colorschanger,
 1846:                   },
 1847:                     { action => 'verify_and_change_colors',
 1848:                       breadcrumb => 
 1849:                           { href => '/adm/preferences?action=changecolors',
 1850:                             text => 'Change Colors'},
 1851:                       printmenu => 'yes',
 1852:                       subroutine => \&verify_and_change_colors,
 1853:                       }));
 1854:     push (@Options,({ action => 'changelanguages',
 1855:                       linktext => 'Change Language Preferences',
 1856:                       href => '/adm/preferences',
 1857: 		      help => 'Prefs_Language',
 1858:                       breadcrumb=>
 1859:                           { href => '/adm/preferences?action=changelanguages',
 1860:                             text => 'Change Language'},
 1861:                       subroutine =>  \&languagechanger,
 1862:                   },
 1863:                     { action => 'verify_and_change_languages',
 1864:                       breadcrumb=>
 1865:                           {href => '/adm/preferences?action=changelanguages',
 1866:                            text => 'Change Language'},
 1867:                       printmenu => 'yes',
 1868:                       subroutine=>\&verify_and_change_languages, }
 1869:                     ));
 1870:     push (@Options,({ action => 'changewysiwyg',
 1871:                       linktext => 'Change WYSIWYG Editor Preferences',
 1872:                       href => '/adm/preferences',
 1873:                       breadcrumb => 
 1874:                             { href => '/adm/preferences?action=changewysiwyg',
 1875:                               text => 'Change WYSIWYG Preferences'},
 1876:                       subroutine => \&wysiwygchanger,
 1877:                   },
 1878:                     { action => 'set_wysiwyg',
 1879:                       breadcrumb =>
 1880:                           { href => '/adm/preferences?action=changewysiwyg',
 1881:                             text => 'Change WYSIWYG Preferences'},
 1882:                       printmenu => 'yes',
 1883:                       subroutine => \&verify_and_change_wysiwyg, }
 1884:                     ));
 1885:     push (@Options,({ action => 'changediscussions',
 1886:                       linktext => 'Change Discussion Display Preferences',
 1887:                       href => '/adm/preferences',
 1888:                       help => 'Change_Discussion_Display',
 1889:                       breadcrumb => 
 1890:                             { href => '/adm/preferences?action=changediscussions',
 1891:                               text => 'Change Discussion Preferences'},
 1892:                       subroutine => \&discussionchanger,
 1893:                   },
 1894:                     { action => 'verify_and_change_discussion',
 1895:                       breadcrumb =>
 1896:                           { href => '/adm/preferences?action=changediscussions',
 1897:                             text => 'Change Discussion Preferences'},
 1898:                       printmenu => 'yes',
 1899:                       subroutine => \&verify_and_change_discussion, }
 1900:                     ));
 1901: 
 1902:     my $role = ($env{'user.adv'} ? 'Roles' : 'Course');
 1903:     push (@Options,({ action   => 'changerolespref',
 1904:                       linktext => 'Change '.$role.' Page Preferences',
 1905:                       href     => '/adm/preferences',
 1906:                       subroutine => \&rolesprefchanger,
 1907:                       breadcrumb =>
 1908:                           { href => '/adm/preferences?action=changerolespref',
 1909:                             text => 'Change '.$role.' Page Pref'},
 1910:                       },
 1911:                     { action   => 'verify_and_change_rolespref',
 1912:                       subroutine => \&verify_and_change_rolespref,
 1913:                       breadcrumb =>
 1914:                           { href => '/adm/preferences?action=changerolespref',
 1915:                             text => 'Change '.$role.' Page Preferences'},
 1916:                       printmenu => 'yes',
 1917:                       }));
 1918: 
 1919:     push (@Options,({ action   => 'changetexenginepref',
 1920:                       linktext => 'Change How Math Equations Are Displayed',
 1921:                       href     => '/adm/preferences',
 1922:                       subroutine => \&texenginechanger,
 1923:                       breadcrumb =>
 1924:                           { href => '/adm/preferences?action=changetexenginepref',
 1925:                             text => 'Change Math Pref'},
 1926:                       },
 1927:                     { action   => 'verify_and_change_texengine',
 1928:                       subroutine => \&verify_and_change_texengine,
 1929:                       breadcrumb =>
 1930:                           { href => '/adm/preferences?action=changetexenginepref',
 1931:                             text => 'Change Math Preferences'},
 1932:                       printmenu => 'yes',
 1933:                       }));
 1934: 
 1935:     if ($env{'environment.remote'} eq 'off') {
 1936: 	push (@Options,({ action => 'launch',
 1937: 			  linktext => 'Launch Remote Control',
 1938: 			  href => '/adm/remote?url=/adm/preferences',
 1939: 		      }));
 1940:     } else {
 1941: 	push (@Options,({ action => 'collapse',
 1942: 			  linktext => 'Collapse Remote Control',
 1943: 			  href => '/adm/remote?url=/adm/preferences',
 1944: 		      }));
 1945:     }
 1946: 
 1947:     push (@Options,({ action   => 'changeicons',
 1948:                       linktext => 'Change How Menus are Displayed',
 1949:                       href     => '/adm/preferences',
 1950:                       subroutine => \&iconchanger,
 1951:                       breadcrumb =>
 1952:                           { href => '/adm/preferences?action=changeicons',
 1953:                             text => 'Change Main Menu'},
 1954:                       },
 1955:                     { action   => 'verify_and_change_icons',
 1956:                       subroutine => \&verify_and_change_icons,
 1957:                       breadcrumb =>
 1958:                           { href => '/adm/preferences?action=changeicons',
 1959:                             text => 'Change Main Menu'},
 1960:                       printmenu => 'yes',
 1961:                       }));
 1962: 
 1963:     push (@Options,({ action   => 'changeclicker',
 1964:                       linktext => 'Register Response Devices (&quot;Clickers&quot;)',
 1965:                       href     => '/adm/preferences',
 1966:                       subroutine => \&clickerchanger,
 1967:                       breadcrumb =>
 1968:                           { href => '/adm/preferences?action=changeclicker',
 1969:                             text => 'Register Clicker'},
 1970:                       },
 1971:                     { action   => 'verify_and_change_clicker',
 1972:                       subroutine => \&verify_and_change_clicker,
 1973:                       breadcrumb =>
 1974:                           { href => '/adm/preferences?action=changeclicker',
 1975:                             text => 'Register Clicker'},
 1976:                       printmenu => 'yes',
 1977:                       }));
 1978:     my %author_roles = &Apache::lonnet::get_my_roles($user,$domain,'userroles','',['au']);
 1979:     if (keys(%author_roles) > 0) {
 1980:       push (@Options,({ action   => 'changedomcoord',
 1981:                         linktext => 'Restrict Domain Coordinator Access',
 1982:                         href     => '/adm/preferences',
 1983:                         subroutine => \&domcoordchanger,
 1984:                         breadcrumb =>
 1985:                             { href => '/adm/preferences?action=changedomcoord',
 1986:                               text => 'Restrict Domain Coordinator Access'},
 1987:                       },
 1988:                       { action   => 'verify_and_change_domcoord',
 1989:                         subroutine => \&verify_and_change_domcoord,
 1990:                         breadcrumb =>
 1991:                             { href => '/adm/preferences?action=changedomcoord',
 1992:                               text => 'Restrict Domain Coordinator Access'},
 1993:                         printmenu => 'yes',
 1994:                       }));
 1995:     }
 1996: 
 1997:     push (@Options,({ action   => 'lockwarning',
 1998:                       subroutine => \&lockwarning,
 1999:                       breadcrumb =>
 2000:                           { href => '/adm/preferences?action=lockwarning',
 2001:                             text => 'Lock Warnings'},
 2002:                       },
 2003:                     { action   => 'verify_and_change_locks',
 2004:                       subroutine => \&verify_and_change_lockwarning,
 2005:                       breadcrumb =>
 2006:                           { href => '/adm/preferences?action=lockwarning',
 2007:                             text => 'Lockwarnings'},
 2008:                       printmenu => 'yes',
 2009:                       }));
 2010: 
 2011: 
 2012:     if (&Apache::lonnet::allowed('whn',$env{'request.course.id'})
 2013: 	|| &Apache::lonnet::allowed('whn',$env{'request.course.id'}.'/'
 2014: 				    .$env{'request.course.sec'})) {
 2015:         push (@Options,({ action => 'changecourseinit',
 2016:                           linktext => 'Change Course Initialization Preference',
 2017:                           href => '/adm/preferences',
 2018:                           subroutine => \&coursedisplaychanger,
 2019:                           breadcrumb =>
 2020:                               { href => '/adm/preferences?action=changecourseinit',
 2021:                                 text => 'Change Course Init. Pref.'},
 2022:                           },
 2023:                         { action => 'verify_and_change_coursepage',
 2024:                           breadcrumb =>
 2025:                           { href => '/adm/preferences?action=changecourseinit',                               text => 'Change Course Initialization Preference'},
 2026:                         printmenu => 'yes',
 2027:                         subroutine => \&verify_and_change_coursepage,
 2028:                        }));
 2029:     }
 2030: 
 2031:     if ($env{'user.name'} =~ /^(albertel|fox|foxr|kortemey|korte|raeburn)$/) {
 2032:         push (@Options,({ action => 'debugtoggle',
 2033:                           printmenu => 'yes',
 2034:                           subroutine => \&toggle_debug,
 2035:                           }));
 2036:     }
 2037: 
 2038:     $r->print(&Apache::loncommon::start_page('Change Preferences'));
 2039: 
 2040:     my $call = undef;
 2041:     my $help = undef;
 2042:     my $printmenu = 'yes';
 2043:     foreach my $option (@Options) {
 2044:         if ($option->{'action'} eq $env{'form.action'}) {
 2045:             $call = $option->{'subroutine'};
 2046:             $printmenu = $option->{'printmenu'};
 2047:             if (exists($option->{'breadcrumb'})) {
 2048:                 &Apache::lonhtmlcommon::add_breadcrumb
 2049:                     ($option->{'breadcrumb'});
 2050:             }
 2051: 	    $help=$option->{'help'};
 2052:         }
 2053:     }
 2054:     $r->print(&Apache::lonhtmlcommon::breadcrumbs('Change Preferences',$help));
 2055:     my $error;
 2056:     if (defined($call)) {
 2057:         $error = $call->($r);
 2058:     }
 2059:     if ( ( ($printmenu eq 'yes')
 2060: 	   || ($printmenu eq 'not_on_error' && !$error) )
 2061: 	 && (!$env{'form.returnurl'})) {
 2062:         my $optionlist = '<table cellpadding="5">';
 2063:         if ($env{'user.name'} =~ 
 2064:                          /^(albertel|kortemey|fox|foxr|korte|hallmat3|turtle|raeburn)$/
 2065:             ) {
 2066:             push (@Options,({ action => 'debugtoggle',
 2067:                               linktext => 'Toggle Debug Messages',
 2068:                               text => 'Current Debug status is -'.
 2069:                                   $env{'user.debug'}.'-.',
 2070:                               href => '/adm/preferences',
 2071:                               printmenu => 'yes',
 2072:                               subroutine => \&toggle_debug,
 2073:                               }));
 2074:         }
 2075:         foreach my $option(@Options) {
 2076:             my $optiontext = '';
 2077:             if (exists($option->{'href'})) {
 2078: 		$option->{'href_args'}{'action'}=$option->{'action'};
 2079: 		$optiontext .= 
 2080:                     '<a href="'.&add_get_param($option->{'href'},
 2081: 					       $option->{'href_args'}).'">'.
 2082:                     &mt($option->{'linktext'}).'</a>';
 2083:             }
 2084:             if (exists($option->{'text'})) {
 2085:                 $optiontext .= ' '.&mt($option->{'text'});
 2086:             }
 2087:             if ($optiontext ne '') {
 2088:                 $optiontext = '<font size="+1">'.$optiontext.'</font>'; 
 2089:                 my $helplink = '&nbsp;';
 2090:                 if (exists($option->{'help'})) {
 2091:                     $helplink = &Apache::loncommon::help_open_topic
 2092:                                                     ($option->{'help'});
 2093:                 }
 2094:                 $optionlist .= '<tr>'.
 2095:                     '<td>'.$helplink.'</td>'.
 2096:                     '<td>'.$optiontext.'</td>'.
 2097:                     '</tr>';
 2098:             }
 2099:         }
 2100:         $optionlist .= '</table>';
 2101:         $r->print($optionlist);
 2102:     } elsif ($env{'form.returnurl'}) {
 2103: 	$r->print('<br /><a href="'.$env{'form.returnurl'}.'"><font size="+1">'.
 2104: 		  &mt('Return').'</font></a>');
 2105:     }
 2106:     $r->print(&Apache::loncommon::end_page());
 2107:     return OK;
 2108: }
 2109: 
 2110: sub toggle_debug {
 2111:     if ($env{'user.debug'}) {
 2112:         &Apache::lonnet::delenv('user.debug');
 2113:     } else {
 2114:         &Apache::lonnet::appenv({'user.debug' => 1});
 2115:     }
 2116: }
 2117: 
 2118: 1;
 2119: __END__

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