File:  [LON-CAPA] / loncom / interface / lonpreferences.pm
Revision 1.81: download - view: text, annotated - select for diffs
Mon May 1 19:37:34 2006 UTC (18 years, 1 month ago) by albertel
Branches: MAIN
CVS tags: HEAD
- upadte breadcrumbs calls

    1: # The LearningOnline Network
    2: # Preferences
    3: #
    4: # $Id: lonpreferences.pm,v 1.81 2006/05/01 19:37:34 albertel 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 Apache::Constants qw(:common);
   37: use Apache::File;
   38: use Crypt::DES;
   39: use DynaLoader; # for Crypt::DES version
   40: use Apache::loncommon();
   41: use Apache::lonhtmlcommon();
   42: use Apache::lonlocal;
   43: use Apache::lonnet;
   44: 
   45: #
   46: # Write lonnet::passwd to do the call below.
   47: # Use:
   48: #   my $answer=reply("encrypt:passwd:$udom:$uname:$upass",$tryserver);
   49: #
   50: ##################################################
   51: #          password associated functions         #
   52: ##################################################
   53: sub des_keys {
   54:     # Make a new key for DES encryption.
   55:     # Each key has two parts which are returned separately.
   56:     # Please note:  Each key must be passed through the &hex function
   57:     # before it is output to the web browser.  The hex versions cannot
   58:     # be used to decrypt.
   59:     my @hexstr=('0','1','2','3','4','5','6','7',
   60:                 '8','9','a','b','c','d','e','f');
   61:     my $lkey='';
   62:     for (0..7) {
   63:         $lkey.=$hexstr[rand(15)];
   64:     }
   65:     my $ukey='';
   66:     for (0..7) {
   67:         $ukey.=$hexstr[rand(15)];
   68:     }
   69:     return ($lkey,$ukey);
   70: }
   71: 
   72: sub des_decrypt {
   73:     my ($key,$cyphertext) = @_;
   74:     my $keybin=pack("H16",$key);
   75:     my $cypher;
   76:     if ($Crypt::DES::VERSION>=2.03) {
   77:         $cypher=new Crypt::DES $keybin;
   78:     } else {
   79:         $cypher=new DES $keybin;
   80:     }
   81:     my $plaintext=
   82: 	$cypher->decrypt(unpack("a8",pack("H16",substr($cyphertext,0,16))));
   83:     $plaintext.=
   84: 	$cypher->decrypt(unpack("a8",pack("H16",substr($cyphertext,16,16))));
   85:     $plaintext=substr($plaintext,1,ord(substr($plaintext,0,1)) );
   86:     return $plaintext;
   87: }
   88: 
   89: ################################################################
   90: #                       Handler subroutines                    #
   91: ################################################################
   92: 
   93: ################################################################
   94: #         Language Change Subroutines                          #
   95: ################################################################
   96: 
   97: sub wysiwygchanger {
   98:     my $r = shift;
   99:     my %userenv = &Apache::lonnet::get
  100:         ('environment',['wysiwygeditor']);
  101:     my $onselect='checked="checked"';
  102:     my $offselect='';
  103:     if ($userenv{'wysiwygeditor'} eq 'on') {
  104: 	$onselect='';
  105: 	$offselect='checked="checked"';
  106:     }
  107:     my $switchoff=&mt('Disable WYSIWYG editor');
  108:     my $switchon=&mt('Enable WYSIWYG editor');
  109:     $r->print(<<ENDLSCREEN);
  110: <form name="prefs" action="/adm/preferences" method="POST">
  111: <input type="hidden" name="action" value="set_wysiwyg" />
  112: <br />
  113: <label><input type="radio" name="wysiwyg" value="off" $onselect /> $switchoff</label><br />
  114: <label><input type="radio" name="wysiwyg" value="on" $offselect /> $switchon</label>
  115: ENDLSCREEN
  116:     $r->print('<br /><input type="submit" value="'.&mt('Change').'" />');
  117: }
  118: 
  119: 
  120: sub verify_and_change_wysiwyg {
  121:     my $r = shift;
  122:     my $newsetting=$env{'form.wysiwyg'};
  123:     &Apache::lonnet::put('environment',{'wysiwygeditor' => $newsetting});
  124:     &Apache::lonnet::appenv('environment.wysiwygeditor' => $newsetting);
  125:     $r->print('<p>'.&mt('Setting WYSIWYG editor to:').' '.&mt($newsetting).'</p>');
  126: }
  127: 
  128: ################################################################
  129: #         Language Change Subroutines                          #
  130: ################################################################
  131: sub languagechanger {
  132:     my $r = shift;
  133:     my $user       = $env{'user.name'};
  134:     my $domain     = $env{'user.domain'};
  135:     my %userenv = &Apache::lonnet::get
  136:         ('environment',['languages']);
  137:     my $language=$userenv{'languages'};
  138: 
  139:     my $pref=&mt('Preferred language');
  140:     my %langchoices=('' => 'No language preference');
  141:     foreach (&Apache::loncommon::languageids()) {
  142: 	if (&Apache::loncommon::supportedlanguagecode($_)) {
  143: 	    $langchoices{&Apache::loncommon::supportedlanguagecode($_)}
  144: 	               = &Apache::loncommon::plainlanguagedescription($_);
  145: 	}
  146:     }
  147:     my $selectionbox=&Apache::loncommon::select_form($language,'language',
  148: 						     %langchoices);
  149:     $r->print(<<ENDLSCREEN);
  150: <form name="prefs" action="/adm/preferences" method="POST">
  151: <input type="hidden" name="action" value="verify_and_change_languages" />
  152: <br />$pref: $selectionbox
  153: ENDLSCREEN
  154:     $r->print('<br /><input type="submit" value="'.&mt('Change').'" />');
  155: }
  156: 
  157: 
  158: sub verify_and_change_languages {
  159:     my $r = shift;
  160:     my $user       = $env{'user.name'};
  161:     my $domain     = $env{'user.domain'};
  162: # Screenname
  163:     my $newlanguage  = $env{'form.language'};
  164:     $newlanguage=~s/[^\-\w]//g;
  165:     my $message='';
  166:     if ($newlanguage) {
  167:         &Apache::lonnet::put('environment',{'languages' => $newlanguage});
  168:         &Apache::lonnet::appenv('environment.languages' => $newlanguage);
  169:         $message='Set new preferred languages to '.$newlanguage;
  170:     } else {
  171:         &Apache::lonnet::del('environment',['languages']);
  172:         &Apache::lonnet::delenv('environment\.languages');
  173:         $message='Reset preferred language';
  174:     }
  175:     $r->print(<<ENDVCSCREEN);
  176: $message
  177: ENDVCSCREEN
  178: }
  179: 
  180: ################################################################
  181: #         Tex Engine Change Subroutines                        #
  182: ################################################################
  183: sub texenginechanger {
  184:     my $r = shift;
  185:     my $user       = $env{'user.name'};
  186:     my $domain     = $env{'user.domain'};
  187:     my %userenv = &Apache::lonnet::get('environment',['texengine']);
  188:     my $texengine=$userenv{'texengine'};
  189: 
  190:     my $pref=&mt('Preferred method to display Math');
  191:     my %mathchoices=('' => 'Default',
  192: 		     'tth' => 'TeX to HTML',
  193: 		     #'ttm' => 'TeX to MathML',
  194: 		     'jsMath' => 'jsMath',
  195: 		     'mimetex' => 'Convert to Images'
  196:                      );
  197:     my $selectionbox=&Apache::loncommon::select_form($texengine,'texengine',
  198: 						     %mathchoices);
  199:     my $jsMath_start=&Apache::lontexconvert::jsMath_header();
  200:     my $change=&mt('Change');
  201:     $r->print(<<ENDLSCREEN);
  202: <br />
  203: 
  204: <form name="prefs" action="/adm/preferences" method="POST">
  205: <input type="hidden" name="action" value="verify_and_change_texengine" />
  206: <p>$pref: $selectionbox</p>
  207: <p><input type="submit" value="$change" /></p>
  208: </form>
  209: Examples:
  210: <p> TeX to HTML <br /> 
  211: <iframe src="/res/adm/pages/math_example.tex?inhibitmenu=yes&texengine=tth" width="400" hieght="200"></iframe>
  212: </p>
  213: <p>jsMath <br /> 
  214: $jsMath_start
  215: <script type="text/javascript">
  216: if (jsMath.nofonts == 1) {
  217:     document.writeln
  218:         ('<center><div style="padding: 10; border-style: solid; border-width:3;'
  219: 	 +' border-color: #DD0000; background-color: #FFF8F8; width: 75%; text-align: left">'
  220: 	 +'<small><font color="#AA0000"><b>Warning:</b> '
  221: 	 +'It looks like you don\\\'t have the TeX math fonts installed. '
  222: 	 +'The jsMath example on this page may not look right without them. '
  223: 	 +'The <a href="http://www.math.union.edu/locate/jsMath/" target="_blank"> '
  224: 	 +'jsMath Home Page</a> has information on how to download the '
  225: 	 +'needed fonts.  In the meantime, jsMath will do the best it can '
  226: 	 +'with the fonts you have, but it may not be pretty and some equations '
  227: 	 +'may not be rendered correctly. '
  228: 	 +'</font></small></div></center>');
  229: }
  230: </script>
  231: <iframe src="/res/adm/pages/math_example.tex?inhibitmenu=yes&texengine=jsMath" width="400" hieght="200"></iframe>
  232: 
  233: </p>
  234: <p> Convert to Images <br />
  235: <br />
  236: <iframe src="/res/adm/pages/math_example.tex?inhibitmenu=yes&texengine=mimetex" width="400" hieght="200"></iframe>
  237: </p>
  238: ENDLSCREEN
  239:     if ($env{'environment.texengine'} ne 'jsMath') {
  240: 	$r->print('<script type="text/javascript">jsMath.Process()</script>');
  241:     }
  242: }
  243: 
  244: 
  245: sub verify_and_change_texengine {
  246:     my $r = shift;
  247:     my $user       = $env{'user.name'};
  248:     my $domain     = $env{'user.domain'};
  249: # Screenname
  250:     my $newtexengine  = $env{'form.texengine'};
  251:     $newtexengine=~s/[^\-\w]//g;
  252:     if ($newtexengine eq 'ttm') {
  253: 	&Apache::lonnet::appenv('browser.mathml' => 1);
  254:     } else {
  255: 	if ($env{'environment.texengine'} eq 'ttm') {
  256: 	    &Apache::lonnet::appenv('browser.mathml' => 0);
  257: 	}
  258:     }
  259:     my $message='';
  260:     if ($newtexengine) {
  261:         &Apache::lonnet::put('environment',{'texengine' => $newtexengine});
  262:         &Apache::lonnet::appenv('environment.texengine' => $newtexengine);
  263:         $message='Set new preferred math display to '.$newtexengine;
  264:     } else {
  265:         &Apache::lonnet::del('environment',['texengine']);
  266:         &Apache::lonnet::delenv('environment\.texengine');
  267:         $message='Reset preferred math display.';
  268:     }
  269: 
  270: 
  271:     $r->print(<<ENDVCSCREEN);
  272: $message
  273: ENDVCSCREEN
  274: }
  275: 
  276: ################################################################
  277: #         Roles Page Preference Change Subroutines         #
  278: ################################################################
  279: sub rolesprefchanger {
  280:     my $r = shift;
  281:     my $user       = $env{'user.name'};
  282:     my $domain     = $env{'user.domain'};
  283:     my %userenv = &Apache::lonnet::get
  284:         ('environment',['recentroles','recentrolesn']);
  285:     my $hotlist_flag=$userenv{'recentroles'};
  286:     my $hotlist_n=$userenv{'recentrolesn'};
  287:     my $checked;
  288:     if ($hotlist_flag) {
  289: 	$checked = 'checked="checked"';
  290:     }
  291:     
  292:     if (!$hotlist_n) { $hotlist_n=3; }
  293:     my $options;
  294:     for (my $i=1; $i<10; $i++) {
  295: 	my $select;
  296: 	if ($hotlist_n == $i) { $select = 'selected="selected"'; }
  297: 	$options .= "<option $select>$i</option>\n";
  298:     }
  299: 
  300:     $r->print(<<ENDSCREEN);
  301: <p>Some LON-CAPA users have a long list of roles. The Recent Roles Hotlist
  302: feature keeps track of the last N roles which have been
  303: visited and places a table of these at the top of the roles page.
  304: People with very few roles should leave this feature disabled.
  305: </p>
  306: 
  307: <form name="prefs" action="/adm/preferences" method="POST">
  308: <input type="hidden" name="action" value="verify_and_change_rolespref" />
  309: <br />Enable Recent Roles Hotlist:
  310: <input type="checkbox" $checked name="recentroles" value="true" />
  311: <br />Number of roles in Hotlist:
  312: <select name="recentrolesn" size="1">
  313: $options
  314: </select>
  315: <br />
  316: <input type="submit" value="Change" />
  317: </form>
  318: ENDSCREEN
  319: }
  320: 
  321: sub verify_and_change_rolespref {
  322:     my $r = shift;
  323:     my $user       = $env{'user.name'};
  324:     my $domain     = $env{'user.domain'};
  325: # Recent Roles Hotlist Flag
  326:     my $hotlist_flag  = $env{'form.recentroles'};
  327:     my $hotlist_n  = $env{'form.recentrolesn'};
  328:     my $message='';
  329:     if ($hotlist_flag) {
  330:         &Apache::lonnet::put('environment',{'recentroles' => $hotlist_flag});
  331:         &Apache::lonnet::appenv('environment.recentroles' => $hotlist_flag);
  332:         $message='Recent Roles Hotlist is Enabled';
  333:     } else {
  334:         &Apache::lonnet::del('environment',['recentroles']);
  335:         &Apache::lonnet::delenv('environment\.recentroles');
  336:         $message='Recent Roles Hotlist is Disabled';
  337:     }
  338:     if ($hotlist_n) {
  339:         &Apache::lonnet::put('environment',{'recentrolesn' => $hotlist_n});
  340:         &Apache::lonnet::appenv('environment.recentrolesn' => $hotlist_n);
  341:         if ($hotlist_flag) {
  342:             $message.="<br />Display $hotlist_n Most Recent Roles\n";
  343:         }
  344:     }
  345: 
  346:     $r->print(<<ENDRPSCREEN);
  347: $message
  348: ENDRPSCREEN
  349: }
  350: 
  351: 
  352: 
  353: ################################################################
  354: #         Anonymous Discussion Name Change Subroutines         #
  355: ################################################################
  356: sub screennamechanger {
  357:     my $r = shift;
  358:     my $user       = $env{'user.name'};
  359:     my $domain     = $env{'user.domain'};
  360:     my %userenv = &Apache::lonnet::get
  361:         ('environment',['screenname','nickname']);
  362:     my $screenname=$userenv{'screenname'};
  363:     my $nickname=$userenv{'nickname'};
  364:     $r->print(<<ENDSCREEN);
  365: <form name="prefs" action="/adm/preferences" method="POST">
  366: <input type="hidden" name="action" value="verify_and_change_screenname" />
  367: <br />New screenname (shown if you post anonymously):
  368: <input type="text" size="20" value="$screenname" name="screenname" />
  369: <br />New nickname (shown if you post non-anonymously):
  370: <input type="text" size="20" value="$nickname" name="nickname" />
  371: <input type="submit" value="Change" />
  372: </form>
  373: ENDSCREEN
  374: }
  375: 
  376: sub verify_and_change_screenname {
  377:     my $r = shift;
  378:     my $user       = $env{'user.name'};
  379:     my $domain     = $env{'user.domain'};
  380: # Screenname
  381:     my $newscreen  = $env{'form.screenname'};
  382:     $newscreen=~s/[^ \w]//g;
  383:     my $message='';
  384:     if ($newscreen) {
  385:         &Apache::lonnet::put('environment',{'screenname' => $newscreen});
  386:         &Apache::lonnet::appenv('environment.screenname' => $newscreen);
  387:         $message='Set new screenname to '.$newscreen;
  388:     } else {
  389:         &Apache::lonnet::del('environment',['screenname']);
  390:         &Apache::lonnet::delenv('environment\.screenname');
  391:         $message='Reset screenname';
  392:     }
  393: # Nickname
  394:     $message.='<br />';
  395:     $newscreen  = $env{'form.nickname'};
  396:     $newscreen=~s/[^ \w]//g;
  397:     if ($newscreen) {
  398:         &Apache::lonnet::put('environment',{'nickname' => $newscreen});
  399:         &Apache::lonnet::appenv('environment.nickname' => $newscreen);
  400:         $message.='Set new nickname to '.$newscreen;
  401:     } else {
  402:         &Apache::lonnet::del('environment',['nickname']);
  403:         &Apache::lonnet::delenv('environment\.nickname');
  404:         $message.='Reset nickname';
  405:     }
  406:     &Apache::lonnet::devalidate_cache_new('namescache',$user.':'.$domain);
  407:     $r->print(<<ENDVCSCREEN);
  408: $message
  409: ENDVCSCREEN
  410: }
  411: 
  412: ################################################################
  413: #         Message Forward                                      #
  414: ################################################################
  415: 
  416: sub msgforwardchanger {
  417:     my $r = shift;
  418:     my $user       = $env{'user.name'};
  419:     my $domain     = $env{'user.domain'};
  420:     my %userenv = &Apache::lonnet::get('environment',['msgforward','notification','critnotification']);
  421:     my $msgforward=$userenv{'msgforward'};
  422:     my $notification=$userenv{'notification'};
  423:     my $critnotification=$userenv{'critnotification'};
  424:     my $forwardingHelp = Apache::loncommon::help_open_topic("Prefs_Forwarding",
  425: 							    "What are forwarding ".
  426: 							    "and notification ".
  427: 							    "addresses");
  428:     my $criticalMessageHelp = Apache::loncommon::help_open_topic("Course_Critical_Message",
  429: 								 "What are critical messages");
  430: 
  431:     $r->print(<<ENDMSG);
  432: $forwardingHelp <br />
  433: <form name="prefs" action="/adm/preferences" method="POST">
  434: <input type="hidden" name="action" value="verify_and_change_msgforward" />
  435: New Forwarding Address(es) (<tt>user:domain,user:domain,...</tt>):
  436: <input type="text" size="40" value="$msgforward" name="msgforward" /><hr />
  437: New Message Notification Email Address(es) (<tt>joe\@doe.com,jane\@doe.edu,...</tt>):
  438: <input type="text" size="40" value="$notification" name="notification" /><hr />
  439: New Critical Message Notification Email Address(es) (<tt>joe\@doe.com,jane\@doe.edu,...</tt>):
  440: <input type="text" size="40" value="$critnotification" name="critnotification" />$criticalMessageHelp<hr />
  441: <input type="submit" value="Change" />
  442: </form>
  443: ENDMSG
  444: }
  445: 
  446: sub verify_and_change_msgforward {
  447:     my $r = shift;
  448:     my $user       = $env{'user.name'};
  449:     my $domain     = $env{'user.domain'};
  450:     my $newscreen  = '';
  451:     my $message='';
  452:     foreach (split(/\,/,$env{'form.msgforward'})) {
  453: 	my ($msuser,$msdomain)=split(/[\@\:]/,$_);
  454:         $msuser=~s/\W//g;
  455:         $msdomain=~s/\W//g;
  456:         if (($msuser) && ($msdomain)) {
  457: 	    if (&Apache::lonnet::homeserver($msuser,$msdomain) ne 'no_host') {
  458:                $newscreen.=$msuser.':'.$msdomain.',';
  459: 	   } else {
  460:                $message.='No such user: '.$msuser.':'.$msdomain.'<br>';
  461:            }
  462:         }
  463:     }
  464:     $newscreen=~s/\,$//;
  465:     if ($newscreen) {
  466:         &Apache::lonnet::put('environment',{'msgforward' => $newscreen});
  467:         &Apache::lonnet::appenv('environment.msgforward' => $newscreen);
  468:         $message.='Set new message forwarding to '.$newscreen.'<br />';
  469:     } else {
  470:         &Apache::lonnet::del('environment',['msgforward']);
  471:         &Apache::lonnet::delenv('environment\.msgforward');
  472:         $message.='Reset message forwarding<br />';
  473:     }
  474:     my $notification=$env{'form.notification'};
  475:     $notification=~s/\s//gs;
  476:     if ($notification) {
  477:         &Apache::lonnet::put('environment',{'notification' => $notification});
  478:         &Apache::lonnet::appenv('environment.notification' => $notification);
  479:         $message.='Set message notification address to '.$notification.'<br />';
  480:     } else {
  481:         &Apache::lonnet::del('environment',['notification']);
  482:         &Apache::lonnet::delenv('environment\.notification');
  483:         $message.='Reset message notification<br />';
  484:     }
  485:     my $critnotification=$env{'form.critnotification'};
  486:     $critnotification=~s/\s//gs;
  487:     if ($critnotification) {
  488:         &Apache::lonnet::put('environment',{'critnotification' => $critnotification});
  489:         &Apache::lonnet::appenv('environment.critnotification' => $critnotification);
  490:         $message.='Set critical message notification address to '.$critnotification;
  491:     } else {
  492:         &Apache::lonnet::del('environment',['critnotification']);
  493:         &Apache::lonnet::delenv('environment\.critnotification');
  494:         $message.='Reset critical message notification<br />';
  495:     }
  496:     $r->print(<<ENDVCMSG);
  497: $message
  498: ENDVCMSG
  499: }
  500: 
  501: ################################################################
  502: #         Colors                                               #
  503: ################################################################
  504: 
  505: sub colorschanger {
  506:     my $r = shift;
  507: # figure out colors
  508:     my $function=&Apache::loncommon::get_users_function();
  509:     my $domain=&Apache::loncommon::determinedomain();
  510:     my %colortypes=('pgbg'  => 'Page Background',
  511:                     'tabbg' => 'Header Background',
  512:                     'sidebg'=> 'Header Border',
  513:                     'font'  => 'Font',
  514:                     'link'  => 'Un-Visited Link',
  515:                     'vlink' => 'Visited Link',
  516:                     'alink' => 'Active Link');
  517:     my $chtable='';
  518:     foreach my $item (sort(keys(%colortypes))) {
  519:        my $curcol=&Apache::loncommon::designparm($function.'.'.$item,$domain);
  520:        $chtable.='<tr><td>'.$colortypes{$item}.'</td><td bgcolor="'.$curcol.
  521:         '">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</td><td><input name="'.$item.
  522:         '" size="10" value="'.$curcol.
  523: '" /></td><td><a href="javascript:pjump('."'color_custom','".$colortypes{$item}.
  524: "','".$curcol."','"
  525: 	    .$item."','parmform.pres','psub'".');">Select</a></td></tr>';
  526:     }
  527:     my $pjump_def = &Apache::lonhtmlcommon::pjump_javascript_definition();
  528:     $r->print(<<ENDCOL);
  529: <script>
  530: 
  531:     function pclose() {
  532:         parmwin=window.open("/adm/rat/empty.html","LONCAPAparms",
  533:                  "height=350,width=350,scrollbars=no,menubar=no");
  534:         parmwin.close();
  535:     }
  536: 
  537:     $pjump_def
  538: 
  539:     function psub() {
  540:         pclose();
  541:         if (document.parmform.pres_marker.value!='') {
  542:             if (document.parmform.pres_type.value!='') {
  543:                 eval('document.prefs.'+
  544:                      document.parmform.pres_marker.value+
  545: 		     '.value=document.parmform.pres_value.value;');
  546: 	    }
  547:         } else {
  548:             document.parmform.pres_value.value='';
  549:             document.parmform.pres_marker.value='';
  550:         }
  551:     }
  552: 
  553: 
  554: </script>
  555: <form name="parmform">
  556: <input type="hidden" name="pres_marker" />
  557: <input type="hidden" name="pres_type" />
  558: <input type="hidden" name="pres_value" />
  559: </form>
  560: <form name="prefs" action="/adm/preferences" method="POST">
  561: <input type="hidden" name="action" value="verify_and_change_colors" />
  562: <table border="2">
  563: $chtable
  564: </table>
  565: <input type="submit" value="Change Custom Colors" />
  566: <input type="submit" name="resetall" value="Reset All Colors to Default" />
  567: </form>
  568: ENDCOL
  569: }
  570: 
  571: sub verify_and_change_colors {
  572:     my $r = shift;
  573: # figure out colors
  574:     my $function=&Apache::loncommon::get_users_function();
  575:     my $domain=&Apache::loncommon::determinedomain();
  576:     my %colortypes=('pgbg'  => 'Page Background',
  577:                     'tabbg' => 'Header Background',
  578:                     'sidebg'=> 'Header Border',
  579:                     'font'  => 'Font',
  580:                     'link'  => 'Un-Visited Link',
  581:                     'vlink' => 'Visited Link',
  582:                     'alink' => 'Active Link');
  583: 
  584:     my $message='';
  585:     foreach my $item (keys %colortypes) {
  586:         my $color=$env{'form.'.$item};
  587:         my $entry='color.'.$function.'.'.$item;
  588: 	if (($color=~/^\#[0-9A-Fa-f]{6}$/) && (!$env{'form.resetall'})) {
  589: 	    &Apache::lonnet::put('environment',{$entry => $color});
  590: 	    &Apache::lonnet::appenv('environment.'.$entry => $color);
  591: 	    $message.='Set '.$colortypes{$item}.' to '.$color.'<br />';
  592: 	} else {
  593: 	    &Apache::lonnet::del('environment',[$entry]);
  594: 	    &Apache::lonnet::delenv('environment\.'.$entry);
  595: 	    $message.='Reset '.$colortypes{$item}.'<br />';
  596: 	}
  597:     }
  598:     $r->print(<<ENDVCCOL);
  599: $message
  600: <form name="client" action="/adm/preferences" method="POST">
  601: <input type="hidden" name="action" value="changecolors" />
  602: </form>
  603: ENDVCCOL
  604: }
  605: 
  606: ######################################################
  607: #            password handler subroutines            #
  608: ######################################################
  609: sub passwordchanger {
  610:     # This function is a bit of a mess....
  611:     # Passwords are encrypted using londes.js (DES encryption)
  612:     my $r = shift;
  613:     my $errormessage = shift;
  614:     $errormessage = ($errormessage || '');
  615:     my $user       = $env{'user.name'};
  616:     my $domain     = $env{'user.domain'};
  617:     my $homeserver = $env{'user.home'};
  618:     my $currentauth=&Apache::lonnet::queryauthenticate($user,$domain);
  619:     # Check for authentication types that allow changing of the password.
  620:     return if ($currentauth !~ /^(unix|internal):/);
  621:     #
  622:     # Generate keys
  623:     my ($lkey_cpass ,$ukey_cpass ) = &des_keys();
  624:     my ($lkey_npass1,$ukey_npass1) = &des_keys();
  625:     my ($lkey_npass2,$ukey_npass2) = &des_keys();
  626:     # Store the keys in the log files
  627:     my $lonhost = $r->dir_config('lonHostID');
  628:     my $logtoken=Apache::lonnet::reply('tmpput:'
  629: 				       .$ukey_cpass  . $lkey_cpass .'&'
  630: 				       .$ukey_npass1 . $lkey_npass1.'&'
  631: 				       .$ukey_npass2 . $lkey_npass2,
  632: 				       $lonhost);
  633:     # Hexify the keys for output as javascript variables
  634:     $ukey_cpass = hex($ukey_cpass);
  635:     $lkey_cpass = hex($lkey_cpass);
  636:     $ukey_npass1= hex($ukey_npass1);
  637:     $lkey_npass1= hex($lkey_npass1);
  638:     $ukey_npass2= hex($ukey_npass2);
  639:     $lkey_npass2= hex($lkey_npass2);
  640:     # Output javascript to deal with passwords
  641:     # Output DES javascript
  642:     {
  643: 	my $include = $r->dir_config('lonIncludes');
  644: 	my $jsh=Apache::File->new($include."/londes.js");
  645: 	$r->print(<$jsh>);
  646:     }
  647:     $r->print(<<ENDFORM);
  648: <script language="JavaScript">
  649: 
  650:     function send() {
  651:         uextkey=this.document.client.elements.ukey_cpass.value;
  652:         lextkey=this.document.client.elements.lkey_cpass.value;
  653:         initkeys();
  654: 
  655:         this.document.pserver.elements.currentpass.value
  656:             =crypted(this.document.client.elements.currentpass.value);
  657: 
  658:         uextkey=this.document.client.elements.ukey_npass1.value;
  659:         lextkey=this.document.client.elements.lkey_npass1.value;
  660:         initkeys();
  661:         this.document.pserver.elements.newpass_1.value
  662:             =crypted(this.document.client.elements.newpass_1.value);
  663: 
  664:         uextkey=this.document.client.elements.ukey_npass2.value;
  665:         lextkey=this.document.client.elements.lkey_npass2.value;
  666:         initkeys();
  667:         this.document.pserver.elements.newpass_2.value
  668:             =crypted(this.document.client.elements.newpass_2.value);
  669: 
  670:         this.document.pserver.submit();
  671:     }
  672: 
  673: </script>
  674: $errormessage
  675: 
  676: <p>
  677: <!-- We separate the forms into 'server' and 'client' in order to
  678:      ensure that unencrypted passwords will not be sent out by a
  679:      crappy browser -->
  680: 
  681: <form name="pserver" action="/adm/preferences" method="POST">
  682: <input type="hidden" name="logtoken"    value="$logtoken" />
  683: <input type="hidden" name="action"      value="verify_and_change_pass" />
  684: <input type="hidden" name="currentpass" value="" />
  685: <input type="hidden" name="newpass_1"   value="" />
  686: <input type="hidden" name="newpass_2"   value="" />
  687: </form>
  688: 
  689: <form name="client" >
  690: <table>
  691: <tr><td align="right"> Current password:                      </td>
  692:     <td><input type="password" name="currentpass" size="10"/> </td></tr>
  693: <tr><td align="right"> New password:                          </td>
  694:     <td><input type="password" name="newpass_1" size="10"  /> </td></tr>
  695: <tr><td align="right"> Confirm password:                      </td>
  696:     <td><input type="password" name="newpass_2" size="10"  /> </td></tr>
  697: <tr><td colspan="2" align="center">
  698:     <input type="button" value="Change Password" onClick="send();">
  699: </table>
  700: <input type="hidden" name="ukey_cpass"  value="$ukey_cpass" />
  701: <input type="hidden" name="lkey_cpass"  value="$lkey_cpass" />
  702: <input type="hidden" name="ukey_npass1" value="$ukey_npass1" />
  703: <input type="hidden" name="lkey_npass1" value="$lkey_npass1" />
  704: <input type="hidden" name="ukey_npass2" value="$ukey_npass2" />
  705: <input type="hidden" name="lkey_npass2" value="$lkey_npass2" />
  706: </form>
  707: </p>
  708: ENDFORM
  709:     #
  710:     return;
  711: }
  712: 
  713: sub verify_and_change_password {
  714:     my $r = shift;
  715:     my $user       = $env{'user.name'};
  716:     my $domain     = $env{'user.domain'};
  717:     my $homeserver = $env{'user.home'};
  718:     my $currentauth=&Apache::lonnet::queryauthenticate($user,$domain);
  719:     # Check for authentication types that allow changing of the password.
  720:     return if ($currentauth !~ /^(unix|internal):/);
  721:     #
  722:     my $currentpass = $env{'form.currentpass'}; 
  723:     my $newpass1    = $env{'form.newpass_1'}; 
  724:     my $newpass2    = $env{'form.newpass_2'};
  725:     my $logtoken    = $env{'form.logtoken'};
  726:     # Check for empty data 
  727:     unless (defined($currentpass) && 
  728: 	    defined($newpass1)    && 
  729: 	    defined($newpass2)    ){
  730: 	&passwordchanger($r,"<p>\n<font color='#ff0000'>ERROR</font>".
  731: 			 "Password data was blank.\n</p>");
  732: 	return;
  733:     }
  734:     # Get the keys
  735:     my $lonhost = $r->dir_config('lonHostID');
  736:     my $tmpinfo = Apache::lonnet::reply('tmpget:'.$logtoken,$lonhost);
  737:     if (($tmpinfo=~/^error/) || ($tmpinfo eq 'con_lost')) {
  738:         # I do not a have a better idea about how to handle this
  739: 	$r->print(<<ENDERROR);
  740: <p>
  741: <font color="#ff0000">ERROR:</font> Unable to retrieve stored token for
  742: password decryption.  Please log out and try again.
  743: </p>
  744: ENDERROR
  745:         # Probably should log an error here
  746:         return 1;
  747:     }
  748:     my ($ckey,$n1key,$n2key)=split(/&/,$tmpinfo);
  749:     # 
  750:     $currentpass = &des_decrypt($ckey ,$currentpass);
  751:     $newpass1    = &des_decrypt($n1key,$newpass1);
  752:     $newpass2    = &des_decrypt($n2key,$newpass2);
  753:     # 
  754:     if ($newpass1 ne $newpass2) {
  755: 	&passwordchanger($r,
  756: 			 '<font color="#ff0000">ERROR:</font>'.
  757: 			 'The new passwords you entered do not match.  '.
  758: 			 'Please try again.');
  759: 	return 1;
  760:     }
  761:     if (length($newpass1) < 7) {
  762: 	&passwordchanger($r,
  763: 			 '<font color="#ff0000">ERROR:</font>'.
  764: 			 'Passwords must be a minimum of 7 characters long.  '.
  765: 			 'Please try again.');
  766: 	return 1;
  767:     }
  768:     #
  769:     # Check for bad characters
  770:     my $badpassword = 0;
  771:     foreach (split(//,$newpass1)) {
  772: 	$badpassword = 1 if ((ord($_)<32)||(ord($_)>126));
  773:     }
  774:     if ($badpassword) {
  775: 	# I can't figure out how to enter bad characters on my browser.
  776: 	&passwordchanger($r,<<ENDERROR);
  777: <font color="#ff0000">ERROR:</font>
  778: The password you entered contained illegal characters.<br />
  779: Valid characters are: space and <br />
  780: <pre>
  781: !&quot;\#$%&amp;\'()*+,-./0123456789:;&lt;=&gt;?\@
  782: ABCDEFGHIJKLMNOPQRSTUVWXYZ[\]^_\`abcdefghijklmnopqrstuvwxyz{|}~
  783: </pre>
  784: ENDERROR
  785:     }
  786:     # 
  787:     # Change the password (finally)
  788:     my $result = &Apache::lonnet::changepass
  789: 	($user,$domain,$currentpass,$newpass1,$homeserver);
  790:     # Inform the user the password has (not?) been changed
  791:     if ($result =~ /^ok$/) {
  792: 	$r->print(<<"ENDTEXT");
  793: <h2>The password for $user was successfully changed</h2>
  794: ENDTEXT
  795:     } else {
  796: 	# error error: run in circles, scream and shout
  797:         $r->print(<<ENDERROR);
  798: <h2><font color="#ff0000">The password for $user was not changed</font></h2>
  799: Please make sure your old password was entered correctly.
  800: ENDERROR
  801:         return 1;
  802:     }
  803:     return;
  804: }
  805: 
  806: ################################################################
  807: #            discussion display subroutines 
  808: ################################################################
  809: sub discussionchanger {
  810:     my $r = shift;
  811:     my $user       = $env{'user.name'};
  812:     my $domain     = $env{'user.domain'};
  813:     my %userenv = &Apache::lonnet::get
  814:         ('environment',['discdisplay','discmarkread']);
  815:     my $discdisp = 'allposts';
  816:     my $discmark = 'onmark';
  817: 
  818:     if (defined($userenv{'discdisplay'})) {
  819:         unless ($userenv{'discdisplay'} eq '') { 
  820:             $discdisp = $userenv{'discdisplay'};
  821:         }
  822:     }
  823:     if (defined($userenv{'discmarkread'})) {
  824:         unless ($userenv{'discdisplay'} eq '') { 
  825:             $discmark = $userenv{'discmarkread'};
  826:         }
  827:     }
  828: 
  829:     my $newdisp = 'unread';
  830:     my $newmark = 'ondisp';
  831: 
  832:     my $function = &Apache::loncommon::get_users_function();
  833:     my $color = &Apache::loncommon::designparm($function.'.tabbg',
  834:                                                     $env{'user.domain'});
  835:     my %lt = &Apache::lonlocal::texthash(
  836:         'pref' => 'Display Preference',
  837:         'curr' => 'Current setting ',
  838:         'actn' => 'Action',
  839:         'sdpf' => 'Set display preferences for discussion posts for both bulletin boards and individual resources in all your courses.',
  840:         'prca' => 'Preferences can be set that determine',
  841:         'whpo' => 'Which posts are displayed when you display a bulletin board or resource, and',
  842:         'unwh' => 'Under what circumstances posts are identfied as "New"',
  843:         'allposts' => 'All posts',
  844:         'unread' => 'New posts only',
  845:         'ondisp' => 'Once displayed',
  846:         'onmark' => 'Once marked as read',
  847:         'disa' => 'Posts displayed?',
  848:         'npmr' => 'New posts cease to be identified as "New"?',
  849:         'thde'  => 'The preferences you set here can be overridden within each individual discussion.',
  850:         'chgt' => 'Change to '
  851:     );
  852:     my $dispchange = $lt{'unread'};
  853:     my $markchange = $lt{'ondisp'};
  854:     my $currdisp = $lt{'allposts'};
  855:     my $currmark = $lt{'onmark'};
  856: 
  857:     if ($discdisp eq 'unread') {
  858:         $dispchange = $lt{'allposts'};
  859:         $currdisp = $lt{'unread'};
  860:         $newdisp = 'allposts';
  861:     }
  862: 
  863:     if ($discmark eq 'ondisp') {
  864:         $markchange = $lt{'onmark'};
  865:         $currmark = $lt{'ondisp'};
  866:         $newmark = 'onmark';
  867:     }
  868:     
  869:     $r->print(<<"END");
  870: <form name="prefs" action="/adm/preferences" method="POST">
  871: <input type="hidden" name="action" value="verify_and_change_discussion" />
  872: <br />
  873: $lt{'sdpf'}<br/> $lt{'prca'}  <ol><li>$lt{'whpo'}</li><li>$lt{'unwh'}</li></ol> 
  874: <br />
  875: <br />
  876: <table border="0" cellpadding="0" cellspacing="0">
  877:  <tr>
  878:   <td width="100%" bgcolor="#000000">
  879:    <table width="100%" border="0" cellpadding="1" cellspacing="0">
  880:     <tr>
  881:      <td width="100%" bgcolor="#000000">
  882:       <table border="0" cellpadding="3" cellspacing="3" bgcolor="#FFFFFF">
  883:        <tr bgcolor="$color">
  884:         <td><b>$lt{'pref'}</b></td>
  885:         <td><b>$lt{'curr'}</b></td>
  886:         <td><b>$lt{'actn'}?</b></td>
  887:        </tr>
  888:        <tr bgcolor="#dddddd">
  889:        <td>$lt{'disa'}</td>
  890:        <td>$lt{$discdisp}</td>
  891:        <td><input type="checkbox" name="discdisp" /><input type="hidden" name="newdisp" value="$newdisp" />&nbsp;$lt{'chgt'} "$dispchange"</td>
  892:       </tr><tr bgcolor="#eeeeee">
  893:        <td>$lt{'npmr'}</td>
  894:        <td>$lt{$discmark}</td>
  895:        <td><input type="checkbox" name="discmark" /><input type="hidden" name="newmark" value="$newmark" />&nbsp;$lt{'chgt'} "$markchange"</td>
  896:       </tr>
  897:      </table>
  898:     </td>
  899:    </tr>
  900:   </table>
  901:  </td>
  902: </tr>
  903: </table>
  904: <br />
  905: <br />
  906: <input type="submit" name="sub" value="Store Changes" />
  907: <br />
  908: <br />
  909: Note: $lt{'thde'}
  910: </form>
  911: END
  912: }
  913:                                                                                                                 
  914: sub verify_and_change_discussion {
  915:     my $r = shift;
  916:     my $user     = $env{'user.name'};
  917:     my $domain   = $env{'user.domain'};
  918:     my $message='';
  919:     if (defined($env{'form.discdisp'}) ) {
  920:         my $newdisp  = $env{'form.newdisp'};
  921:         if ($newdisp eq 'unread') {
  922:             $message .='In discussions: only new posts will be displayed.<br/>';
  923:             &Apache::lonnet::put('environment',{'discdisplay' => $newdisp});
  924:             &Apache::lonnet::appenv('environment.discdisplay' => $newdisp);
  925:         } else {
  926:             $message .= 'In discussions: all posts will be displayed.<br/>';
  927:             &Apache::lonnet::del('environment',['discdisplay']);
  928:             &Apache::lonnet::delenv('environment\.discdisplay');
  929:         }
  930:     }
  931:     if (defined($env{'form.discmark'}) ) {
  932:         my $newmark = $env{'form.newmark'};
  933:         if ($newmark eq 'ondisp') {
  934:            $message.='In discussions: new posts will be cease to be identified as "new" after display.<br/>';
  935:             &Apache::lonnet::put('environment',{'discmarkread' => $newmark});
  936:             &Apache::lonnet::appenv('environment.discmarkread' => $newmark);
  937:         } else {
  938:             $message.='In discussions: posts will be identified as "new" until marked as read by the reader.<br/>';
  939:             &Apache::lonnet::del('environment',['discmarkread']);
  940:             &Apache::lonnet::delenv('environment\.discmarkread');
  941:         }
  942:     }
  943:     $r->print(<<ENDVCSCREEN);
  944: $message
  945: ENDVCSCREEN
  946: }
  947: 
  948: ################################################################
  949: # Subroutines for page display on course access (Course Coordinators)
  950: ################################################################
  951: sub coursedisplaychanger {
  952:     my $r = shift;
  953:     my $user       = $env{'user.name'};
  954:     my $domain     = $env{'user.domain'};
  955:     my %userenv = &Apache::lonnet::get('environment',['course_init_display']);
  956:     my $currvalue = 'whatsnew';
  957:     my $firstselect = '';
  958:     my $whatsnewselect = 'checked="checked"';
  959:     if (exists($userenv{'course_init_display'})) {
  960:         if ($userenv{'course_init_display'} eq 'firstres') {
  961:             $currvalue = 'firstres';
  962:             $firstselect = 'checked="checked"';
  963: 	    $whatsnewselect = '';
  964:         }
  965:     }
  966:     my %pagenames = (
  967:                        firstres => 'First resource',
  968:                        whatsnew => "What's new page",
  969:                     );
  970:     my $whatsnew_off=&mt('Display the [_1] in the course.','<b>first resource</b>');
  971:     my $whatsnew_on=&mt('Display the "[_1]" page - a summary of items in the course which require attention.',"<b>What's New</b>");
  972: 
  973:     $r->print('<br /><b>'.&mt('Set the default page to be displayed when you select a course role').'</b>&nbsp;'.&mt('(Currently: [_1])',$pagenames{$currvalue}).'<br />'.&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]" page in the course',"<i>What's New</i>").'<br /><br />');
  974:     $r->print(<<ENDLSCREEN);
  975: <form name="prefs" action="/adm/preferences" method="POST">
  976: <input type="hidden" name="action" value="verify_and_change_coursepage" />
  977: <br />
  978: <label><input type="radio" name="newdisp" value="firstres" $firstselect /> $whatsnew_off</label><br />
  979: <label><input type="radio" name="newdisp" value="whatsnew" $whatsnewselect /> $whatsnew_on</label><input type="hidden" name="refpage" value="$env{'form.refpage'}" />
  980: ENDLSCREEN
  981:     $r->print('<br /><br /><input type="submit" value="'.&mt('Change').'" />
  982: </form>');
  983: }
  984: 
  985: sub verify_and_change_coursepage {
  986:     my $r = shift;
  987:     my $message='';
  988:     my %lt = &Apache::lonlocal::texthash(
  989:         'defs' => 'Default now set',
  990:         'when' => 'when you select a course role from the roles screen',
  991:         'ywbt' => 'you will be taken to the start of the course.',
  992:         'apwb' => 'a page will be displayed that lists items in the course that may require action from you.',
  993:         'gtts' => 'Go to the start of the course',
  994:         'dasp' => "Display the What's New page listing course action items", 
  995:     );
  996:     my $newdisp  = $env{'form.newdisp'};
  997:     $message = '<b>'.$lt{'defs'}.'</b>: '.$lt{'when'}.', ';
  998:     if ($newdisp eq 'firstres') {
  999:         $message .= $lt{'ywbt'}.'<br/>';
 1000:         &Apache::lonnet::put('environment',{'course_init_display' => $newdisp});
 1001:         &Apache::lonnet::appenv('environment.course_init_display' => $newdisp);
 1002:     } else {
 1003:         $message .= $lt{'apwb'}.'<br/>';
 1004:         &Apache::lonnet::del('environment',['course_init_display']);
 1005:         &Apache::lonnet::delenv('environment\.course_init_display');
 1006:     }
 1007:     my $refpage = $env{'form.refpage'};
 1008:     if (($env{'request.course.fn'}) && ($env{'request.course.id'})) {
 1009:         if ($newdisp eq 'firstres') {
 1010:             my $cdom = $env{'course.'.$env{'request.course.id'}.'.domain'};
 1011:             my $cnum = $env{'course.'.$env{'request.course.id'}.'.num'}; 
 1012:             my ($furl,$ferr)=
 1013:                 &Apache::lonuserstate::readmap($cdom.'/'.$cnum);
 1014:             $message .= '<br /><font size="+1"><a href="'.$furl.'">'.$lt{'gtts'}.' <i>'.&mt('now').'</i></a></font>';
 1015:         } else {
 1016:             $message .= '<br /><font size="+1"><a href="/adm/whatsnew?refpage='.
 1017:                         $refpage.'">'.$lt{'dasp'}.'</a></font>';
 1018:         }
 1019:     }
 1020:     $r->print(<<ENDVCSCREEN);
 1021: $message
 1022: <br /><br />
 1023: ENDVCSCREEN
 1024: }
 1025: 
 1026: 
 1027: ######################################################
 1028: #            other handler subroutines               #
 1029: ######################################################
 1030: 
 1031: ################################################################
 1032: #                          Main handler                        #
 1033: ################################################################
 1034: sub handler {
 1035:     my $r = shift;
 1036:     my $user = $env{'user.name'};
 1037:     my $domain = $env{'user.domain'};
 1038:     &Apache::loncommon::content_type($r,'text/html');
 1039:     # Some pages contain DES keys and should not be cached.
 1040:     &Apache::loncommon::no_cache($r);
 1041:     $r->send_http_header;
 1042:     return OK if $r->header_only;
 1043:     #
 1044:     &Apache::loncommon::get_unprocessed_cgi($ENV{'QUERY_STRING'},
 1045:                                    ['action','wysiwyg','returnurl','refpage']);
 1046:     #
 1047:     &Apache::lonhtmlcommon::clear_breadcrumbs();
 1048:     &Apache::lonhtmlcommon::add_breadcrumb
 1049:         ({href => '/adm/preferences',
 1050:           text => 'Set User Preferences'});
 1051: 
 1052:     my @Options;
 1053:     # Determine current authentication method
 1054:     my $currentauth=&Apache::lonnet::queryauthenticate($user,$domain);
 1055:     if ($currentauth =~ /^(unix|internal):/) {
 1056:         push (@Options,({ action   => 'changepass',
 1057:                           linktext => 'Change Password',
 1058:                           href     => '/adm/preferences',
 1059:                           help     => 'Change_Password',
 1060:                           subroutine => \&passwordchanger,
 1061:                           breadcrumb => 
 1062:                               { href => '/adm/preferences?action=changepass',
 1063:                                 text => 'Change Password'},
 1064:                           },
 1065:                         { action => 'verify_and_change_pass',
 1066:                           subroutine => \&verify_and_change_password,
 1067:                           breadcrumb => 
 1068:                               { href =>'/adm/preferences?action=changepass',
 1069:                                 text => 'Change Password'},
 1070:                           printmenu => 'not_on_error',
 1071:                           }));
 1072:     }
 1073:     push (@Options,({ action   => 'changescreenname',
 1074:                       linktext => 'Change Screen Name',
 1075:                       href     => '/adm/preferences',
 1076:                       help     => 'Prefs_Screen_Name_Nickname',
 1077:                       subroutine => \&screennamechanger,
 1078:                       breadcrumb => 
 1079:                           { href => '/adm/preferences?action=changescreenname',
 1080:                             text => 'Change Screen Name'},
 1081:                       },
 1082:                     { action   => 'verify_and_change_screenname',
 1083:                       subroutine => \&verify_and_change_screenname,
 1084:                       breadcrumb => 
 1085:                           { href => '/adm/preferences?action=changescreenname',
 1086:                             text => 'Change Screen Name'},
 1087:                       printmenu => 'yes',
 1088:                       }));
 1089: 
 1090:     push (@Options,({ action   => 'changemsgforward',
 1091:                       linktext => 'Change Message Forwarding and Notification Addresses',
 1092:                       href     => '/adm/preferences',
 1093:                       help     => 'Prefs_Forwarding',
 1094:                       breadcrumb => 
 1095:                           { href => '/adm/preferences?action=changemsgforward',
 1096:                             text => 'Change Message Forwarding'},
 1097:                       subroutine => \&msgforwardchanger,
 1098:                       },
 1099:                     { action => 'verify_and_change_msgforward',
 1100:                       breadcrumb => 
 1101:                           { href => '/adm/preferences?action=changemsgforward',
 1102:                             text => 'Change Message Forwarding'},
 1103:                       printmenu => 'yes',
 1104:                       subroutine => \&verify_and_change_msgforward }));
 1105:     my $aboutmeaction=
 1106:         '/adm/'.$env{'user.domain'}.'/'.$env{'user.name'}.'/aboutme';
 1107:     push (@Options,{ action => 'none', 
 1108:                      linktext =>
 1109:                          q{Edit the 'About Me' Personal Information Screen},
 1110: 		     help => 'Prefs_About_Me',
 1111:                      href => $aboutmeaction});
 1112:     push (@Options,({ action => 'changecolors',
 1113:                       linktext => 'Change Color Scheme',
 1114:                       href => '/adm/preferences',
 1115:                       help => 'Change_Colors',
 1116:                       breadcrumb => 
 1117:                           { href => '/adm/preferences?action=changecolors',
 1118:                             text => 'Change Colors'},
 1119:                       subroutine => \&colorschanger,
 1120:                   },
 1121:                     { action => 'verify_and_change_colors',
 1122:                       breadcrumb => 
 1123:                           { href => '/adm/preferences?action=changecolors',
 1124:                             text => 'Change Colors'},
 1125:                       printmenu => 'yes',
 1126:                       subroutine => \&verify_and_change_colors,
 1127:                       }));
 1128:     push (@Options,({ action => 'changelanguages',
 1129:                       linktext => 'Change Language Preferences',
 1130:                       href => '/adm/preferences',
 1131: 		      help => 'Prefs_Language',
 1132:                       breadcrumb=>
 1133:                           { href => '/adm/preferences?action=changelanguages',
 1134:                             text => 'Change Language'},
 1135:                       subroutine =>  \&languagechanger,
 1136:                   },
 1137:                     { action => 'verify_and_change_languages',
 1138:                       breadcrumb=>
 1139:                           {href => '/adm/preferences?action=changelanguages',
 1140:                            text => 'Change Language'},
 1141:                       printmenu => 'yes',
 1142:                       subroutine=>\&verify_and_change_languages, }
 1143:                     ));
 1144:     push (@Options,({ action => 'changewysiwyg',
 1145:                       linktext => 'Change WYSIWYG Editor Preferences',
 1146:                       href => '/adm/preferences',
 1147:                       breadcrumb => 
 1148:                             { href => '/adm/preferences?action=changewysiwyg',
 1149:                               text => 'Change WYSIWYG Preferences'},
 1150:                       subroutine => \&wysiwygchanger,
 1151:                   },
 1152:                     { action => 'set_wysiwyg',
 1153:                       breadcrumb =>
 1154:                           { href => '/adm/preferences?action=changewysiwyg',
 1155:                             text => 'Change WYSIWYG Preferences'},
 1156:                       printmenu => 'yes',
 1157:                       subroutine => \&verify_and_change_wysiwyg, }
 1158:                     ));
 1159:     push (@Options,({ action => 'changediscussions',
 1160:                       linktext => 'Change Discussion Display Preferences',
 1161:                       href => '/adm/preferences',
 1162:                       help => 'Change_Discussion_Display',
 1163:                       breadcrumb => 
 1164:                             { href => '/adm/preferences?action=changediscussions',
 1165:                               text => 'Change Discussion Preferences'},
 1166:                       subroutine => \&discussionchanger,
 1167:                   },
 1168:                     { action => 'verify_and_change_discussion',
 1169:                       breadcrumb =>
 1170:                           { href => '/adm/preferences?action=changediscussions',
 1171:                             text => 'Change Discussion Preferences'},
 1172:                       printmenu => 'yes',
 1173:                       subroutine => \&verify_and_change_discussion, }
 1174:                     ));
 1175:                        
 1176:     push (@Options,({ action   => 'changerolespref',
 1177:                       linktext => 'Change Roles Page Preferences',
 1178:                       href     => '/adm/preferences',
 1179:                       subroutine => \&rolesprefchanger,
 1180:                       breadcrumb =>
 1181:                           { href => '/adm/preferences?action=changerolespref',
 1182:                             text => 'Change Roles Pref'},
 1183:                       },
 1184:                     { action   => 'verify_and_change_rolespref',
 1185:                       subroutine => \&verify_and_change_rolespref,
 1186:                       breadcrumb =>
 1187:                           { href => '/adm/preferences?action=changerolespref',
 1188:                             text => 'Change Roles Preferences'},
 1189:                       printmenu => 'yes',
 1190:                       }));
 1191: 
 1192:     push (@Options,({ action   => 'changetexenginepref',
 1193:                       linktext => 'Change How Math Equations Are Displayed',
 1194:                       href     => '/adm/preferences',
 1195:                       subroutine => \&texenginechanger,
 1196:                       breadcrumb =>
 1197:                           { href => '/adm/preferences?action=changetexenginepref',
 1198:                             text => 'Change Math Pref'},
 1199:                       },
 1200:                     { action   => 'verify_and_change_texengine',
 1201:                       subroutine => \&verify_and_change_texengine,
 1202:                       breadcrumb =>
 1203:                           { href => '/adm/preferences?action=changetexenginepref',
 1204:                             text => 'Change Math Preferences'},
 1205:                       printmenu => 'yes',
 1206:                       }));
 1207:     if (&Apache::lonnet::allowed('whn',$env{'request.course.id'})
 1208: 	|| &Apache::lonnet::allowed('whn',$env{'request.course.id'}.'/'
 1209: 				    .$env{'request.course.sec'})) {
 1210:         push (@Options,({ action => 'changecourseinit',
 1211:                           linktext => 'Change Course Initialization Preference',
 1212:                           href => '/adm/preferences',
 1213:                           subroutine => \&coursedisplaychanger,
 1214:                           breadcrumb =>
 1215:                               { href => '/adm/preferences?action=changecourseinit',
 1216:                                 text => 'Change Course Init. Pref.'},
 1217:                           },
 1218:                         { action => 'verify_and_change_coursepage',
 1219:                           breadcrumb =>
 1220:                           { href => '/adm/preferences?action=changecourseinit',                               text => 'Change Course Initialization Preference'},
 1221:                         printmenu => 'yes',
 1222:                         subroutine => \&verify_and_change_coursepage,
 1223:                        }));
 1224:     }
 1225: 
 1226:     if ($env{'user.name'} =~ /^(albertel|fox|foxr|koretemey|korte|hallmat3|turtle|raeburn)$/) {
 1227:         push (@Options,({ action => 'debugtoggle',
 1228:                           printmenu => 'yes',
 1229:                           subroutine => \&toggle_debug,
 1230:                           }));
 1231:     }
 1232: 
 1233:     $r->print(&Apache::loncommon::start_page('Change Preferences'));
 1234: 
 1235:     my $call = undef;
 1236:     my $help = undef;
 1237:     my $printmenu = 'yes';
 1238:     foreach my $option (@Options) {
 1239:         if ($option->{'action'} eq $env{'form.action'}) {
 1240:             $call = $option->{'subroutine'};
 1241:             $printmenu = $option->{'printmenu'};
 1242:             if (exists($option->{'breadcrumb'})) {
 1243:                 &Apache::lonhtmlcommon::add_breadcrumb
 1244:                     ($option->{'breadcrumb'});
 1245:             }
 1246: 	    $help=$option->{'help'};
 1247:         }
 1248:     }
 1249:     $r->print(&Apache::lonhtmlcommon::breadcrumbs('Change Preferences',$help));
 1250:     my $error;
 1251:     if (defined($call)) {
 1252:         $error = $call->($r);
 1253:     }
 1254:     if ( ( ($printmenu eq 'yes')
 1255: 	   || ($printmenu eq 'not_on_error' && !$error) )
 1256: 	 && (!$env{'form.returnurl'})) {
 1257:         my $optionlist = '<table cellpadding="5">';
 1258:         if ($env{'user.name'} =~ 
 1259:                          /^(albertel|kortemey|fox|foxr|korte|hallmat3|turtle|raeburn)$/
 1260:             ) {
 1261:             push (@Options,({ action => 'debugtoggle',
 1262:                               linktext => 'Toggle Debug Messages',
 1263:                               text => 'Current Debug status is -'.
 1264:                                   $env{'user.debug'}.'-.',
 1265:                               href => '/adm/preferences',
 1266:                               printmenu => 'yes',
 1267:                               subroutine => \&toggle_debug,
 1268:                               }));
 1269:         }
 1270:         foreach my $option(@Options) {
 1271:             my $optiontext = '';
 1272:             if (exists($option->{'href'})) {
 1273:                 $optiontext .= 
 1274:                     '<a href="'.$option->{'href'}.
 1275:                     '?action='.$option->{'action'}.'">'.
 1276:                     &mt($option->{'linktext'}).'</a>';
 1277:             }
 1278:             if (exists($option->{'text'})) {
 1279:                 $optiontext .= ' '.&mt($option->{'text'});
 1280:             }
 1281:             if ($optiontext ne '') {
 1282:                 $optiontext = '<font size="+1">'.$optiontext.'</font>'; 
 1283:                 my $helplink = '&nbsp;';
 1284:                 if (exists($option->{'help'})) {
 1285:                     $helplink = &Apache::loncommon::help_open_topic
 1286:                                                     ($option->{'help'});
 1287:                 }
 1288:                 $optionlist .= '<tr>'.
 1289:                     '<td>'.$helplink.'</td>'.
 1290:                     '<td>'.$optiontext.'</td>'.
 1291:                     '</tr>';
 1292:             }
 1293:         }
 1294:         $optionlist .= '</table>';
 1295:         $r->print($optionlist);
 1296:     } elsif ($env{'form.returnurl'}) {
 1297: 	$r->print('<br /><a href="'.$env{'form.returnurl'}.'"><font size="+1">'.
 1298: 		  &mt('Return').'</font></a>');
 1299:     }
 1300:     $r->print(&Apache::loncommon::end_page());
 1301:     return OK;
 1302: }
 1303: 
 1304: sub toggle_debug {
 1305:     if ($env{'user.debug'}) {
 1306:         &Apache::lonnet::delenv('user\.debug');
 1307:     } else {
 1308:         &Apache::lonnet::appenv('user.debug' => 1);
 1309:     }
 1310: }
 1311: 
 1312: 1;
 1313: __END__

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