File:  [LON-CAPA] / loncom / interface / lonpreferences.pm
Revision 1.74: download - view: text, annotated - select for diffs
Fri Jan 6 21:04:34 2006 UTC (18 years, 4 months ago) by albertel
Branches: MAIN
CVS tags: version_2_1_X, version_2_1_3, version_2_1_2, version_2_1_1, HEAD
- check whn for both course and course+section

    1: # The LearningOnline Network
    2: # Preferences
    3: #
    4: # $Id: lonpreferences.pm,v 1.74 2006/01/06 21:04: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 $offselect='';
  102:     my $onselect='checked="1"';
  103:     if ($userenv{'wysiwygeditor'}) {
  104: 	$onselect='';
  105: 	$offselect='checked="1"';
  106:     }
  107:     my $switchoff=&mt('Disable WYSIWYG editor');
  108:     my $switchon=&mt('Enable WYSIWYG editor');
  109:     $r->print(<<ENDLSCREEN);
  110: <form name="server" 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="server" 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="server" 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?buttons=no&mode=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?buttons=no&mode=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?buttons=no&mode=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="server" 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="server" 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="server" 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='student';
  509:     if ($env{'request.role'}=~/^(cc|in|ta|ep)/) {
  510: 	$function='coordinator';
  511:     }
  512:     if ($env{'request.role'}=~/^(su|dc|ad|li)/) {
  513: 	$function='admin';
  514:     }
  515:     if (($env{'request.role'}=~/^(au|ca)/) ||
  516: 	($ENV{'REQUEST_URI'}=~/^(\/priv|\~)/)) {
  517: 	$function='author';
  518:     }
  519:     my $domain=&Apache::loncommon::determinedomain();
  520:     my %colortypes=('pgbg'  => 'Page Background',
  521:                     'tabbg' => 'Header Background',
  522:                     'sidebg'=> 'Header Border',
  523:                     'font'  => 'Font',
  524:                     'link'  => 'Un-Visited Link',
  525:                     'vlink' => 'Visited Link',
  526:                     'alink' => 'Active Link');
  527:     my $chtable='';
  528:     foreach my $item (sort(keys(%colortypes))) {
  529:        my $curcol=&Apache::loncommon::designparm($function.'.'.$item,$domain);
  530:        $chtable.='<tr><td>'.$colortypes{$item}.'</td><td bgcolor="'.$curcol.
  531:         '">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</td><td><input name="'.$item.
  532:         '" size="10" value="'.$curcol.
  533: '" /></td><td><a href="javascript:pjump('."'color_custom','".$colortypes{$item}.
  534: "','".$curcol."','"
  535: 	    .$item."','parmform.pres','psub'".');">Select</a></td></tr>';
  536:     }
  537:     my $pjump_def = &Apache::lonhtmlcommon::pjump_javascript_definition();
  538:     $r->print(<<ENDCOL);
  539: <script>
  540: 
  541:     function pclose() {
  542:         parmwin=window.open("/adm/rat/empty.html","LONCAPAparms",
  543:                  "height=350,width=350,scrollbars=no,menubar=no");
  544:         parmwin.close();
  545:     }
  546: 
  547:     $pjump_def
  548: 
  549:     function psub() {
  550:         pclose();
  551:         if (document.parmform.pres_marker.value!='') {
  552:             if (document.parmform.pres_type.value!='') {
  553:                 eval('document.server.'+
  554:                      document.parmform.pres_marker.value+
  555: 		     '.value=document.parmform.pres_value.value;');
  556: 	    }
  557:         } else {
  558:             document.parmform.pres_value.value='';
  559:             document.parmform.pres_marker.value='';
  560:         }
  561:     }
  562: 
  563: 
  564: </script>
  565: <form name="parmform">
  566: <input type="hidden" name="pres_marker" />
  567: <input type="hidden" name="pres_type" />
  568: <input type="hidden" name="pres_value" />
  569: </form>
  570: <form name="server" action="/adm/preferences" method="post">
  571: <input type="hidden" name="action" value="verify_and_change_colors" />
  572: <table border="2">
  573: $chtable
  574: </table>
  575: <input type="submit" value="Change Custom Colors" />
  576: <input type="submit" name="resetall" value="Reset All Colors to Default" />
  577: </form>
  578: ENDCOL
  579: }
  580: 
  581: sub verify_and_change_colors {
  582:     my $r = shift;
  583: # figure out colors
  584:     my $function='student';
  585:     if ($env{'request.role'}=~/^(cc|in|ta|ep)/) {
  586: 	$function='coordinator';
  587:     }
  588:     if ($env{'request.role'}=~/^(su|dc|ad|li)/) {
  589: 	$function='admin';
  590:     }
  591:     if (($env{'request.role'}=~/^(au|ca)/) ||
  592: 	($ENV{'REQUEST_URI'}=~/^(\/priv|\~)/)) {
  593: 	$function='author';
  594:     }
  595:     my $domain=&Apache::loncommon::determinedomain();
  596:     my %colortypes=('pgbg'  => 'Page Background',
  597:                     'tabbg' => 'Header Background',
  598:                     'sidebg'=> 'Header Border',
  599:                     'font'  => 'Font',
  600:                     'link'  => 'Un-Visited Link',
  601:                     'vlink' => 'Visited Link',
  602:                     'alink' => 'Active Link');
  603: 
  604:     my $message='';
  605:     foreach my $item (keys %colortypes) {
  606:         my $color=$env{'form.'.$item};
  607:         my $entry='color.'.$function.'.'.$item;
  608: 	if (($color=~/^\#[0-9A-Fa-f]{6}$/) && (!$env{'form.resetall'})) {
  609: 	    &Apache::lonnet::put('environment',{$entry => $color});
  610: 	    &Apache::lonnet::appenv('environment.'.$entry => $color);
  611: 	    $message.='Set '.$colortypes{$item}.' to '.$color.'<br />';
  612: 	} else {
  613: 	    &Apache::lonnet::del('environment',[$entry]);
  614: 	    &Apache::lonnet::delenv('environment\.'.$entry);
  615: 	    $message.='Reset '.$colortypes{$item}.'<br />';
  616: 	}
  617:     }
  618:     $r->print(<<ENDVCCOL);
  619: $message
  620: <form name="client" action="/adm/preferences" method="post">
  621: <input type="hidden" name="action" value="changecolors" />
  622: </form>
  623: ENDVCCOL
  624: }
  625: 
  626: ######################################################
  627: #            password handler subroutines            #
  628: ######################################################
  629: sub passwordchanger {
  630:     # This function is a bit of a mess....
  631:     # Passwords are encrypted using londes.js (DES encryption)
  632:     my $r = shift;
  633:     my $errormessage = shift;
  634:     $errormessage = ($errormessage || '');
  635:     my $user       = $env{'user.name'};
  636:     my $domain     = $env{'user.domain'};
  637:     my $homeserver = $env{'user.home'};
  638:     my $currentauth=&Apache::lonnet::queryauthenticate($user,$domain);
  639:     # Check for authentication types that allow changing of the password.
  640:     return if ($currentauth !~ /^(unix|internal):/);
  641:     #
  642:     # Generate keys
  643:     my ($lkey_cpass ,$ukey_cpass ) = &des_keys();
  644:     my ($lkey_npass1,$ukey_npass1) = &des_keys();
  645:     my ($lkey_npass2,$ukey_npass2) = &des_keys();
  646:     # Store the keys in the log files
  647:     my $lonhost = $r->dir_config('lonHostID');
  648:     my $logtoken=Apache::lonnet::reply('tmpput:'
  649: 				       .$ukey_cpass  . $lkey_cpass .'&'
  650: 				       .$ukey_npass1 . $lkey_npass1.'&'
  651: 				       .$ukey_npass2 . $lkey_npass2,
  652: 				       $lonhost);
  653:     # Hexify the keys for output as javascript variables
  654:     $ukey_cpass = hex($ukey_cpass);
  655:     $lkey_cpass = hex($lkey_cpass);
  656:     $ukey_npass1= hex($ukey_npass1);
  657:     $lkey_npass1= hex($lkey_npass1);
  658:     $ukey_npass2= hex($ukey_npass2);
  659:     $lkey_npass2= hex($lkey_npass2);
  660:     # Output javascript to deal with passwords
  661:     # Output DES javascript
  662:     my $html=&Apache::lonxml::xmlbegin();
  663:     $r->print($html."<head>");
  664:     {
  665: 	my $include = $r->dir_config('lonIncludes');
  666: 	my $jsh=Apache::File->new($include."/londes.js");
  667: 	$r->print(<$jsh>);
  668:     }
  669:     $r->print(<<ENDFORM);
  670: <script language="JavaScript">
  671: 
  672:     function send() {
  673:         uextkey=this.document.client.elements.ukey_cpass.value;
  674:         lextkey=this.document.client.elements.lkey_cpass.value;
  675:         initkeys();
  676: 
  677:         this.document.pserver.elements.currentpass.value
  678:             =crypted(this.document.client.elements.currentpass.value);
  679: 
  680:         uextkey=this.document.client.elements.ukey_npass1.value;
  681:         lextkey=this.document.client.elements.lkey_npass1.value;
  682:         initkeys();
  683:         this.document.pserver.elements.newpass_1.value
  684:             =crypted(this.document.client.elements.newpass_1.value);
  685: 
  686:         uextkey=this.document.client.elements.ukey_npass2.value;
  687:         lextkey=this.document.client.elements.lkey_npass2.value;
  688:         initkeys();
  689:         this.document.pserver.elements.newpass_2.value
  690:             =crypted(this.document.client.elements.newpass_2.value);
  691: 
  692:         this.document.pserver.submit();
  693:     }
  694: 
  695: </script>
  696: $errormessage
  697: 
  698: <p>
  699: <!-- We separate the forms into 'server' and 'client' in order to
  700:      ensure that unencrypted passwords will not be sent out by a
  701:      crappy browser -->
  702: 
  703: <form name="pserver" action="/adm/preferences" method="post">
  704: <input type="hidden" name="logtoken"    value="$logtoken" />
  705: <input type="hidden" name="action"      value="verify_and_change_pass" />
  706: <input type="hidden" name="currentpass" value="" />
  707: <input type="hidden" name="newpass_1"   value="" />
  708: <input type="hidden" name="newpass_2"   value="" />
  709: </form>
  710: 
  711: <form name="client" >
  712: <table>
  713: <tr><td align="right"> Current password:                      </td>
  714:     <td><input type="password" name="currentpass" size="10"/> </td></tr>
  715: <tr><td align="right"> New password:                          </td>
  716:     <td><input type="password" name="newpass_1" size="10"  /> </td></tr>
  717: <tr><td align="right"> Confirm password:                      </td>
  718:     <td><input type="password" name="newpass_2" size="10"  /> </td></tr>
  719: <tr><td colspan="2" align="center">
  720:     <input type="button" value="Change Password" onClick="send();">
  721: </table>
  722: <input type="hidden" name="ukey_cpass"  value="$ukey_cpass" />
  723: <input type="hidden" name="lkey_cpass"  value="$lkey_cpass" />
  724: <input type="hidden" name="ukey_npass1" value="$ukey_npass1" />
  725: <input type="hidden" name="lkey_npass1" value="$lkey_npass1" />
  726: <input type="hidden" name="ukey_npass2" value="$ukey_npass2" />
  727: <input type="hidden" name="lkey_npass2" value="$lkey_npass2" />
  728: </form>
  729: </p>
  730: ENDFORM
  731:     #
  732:     return;
  733: }
  734: 
  735: sub verify_and_change_password {
  736:     my $r = shift;
  737:     my $user       = $env{'user.name'};
  738:     my $domain     = $env{'user.domain'};
  739:     my $homeserver = $env{'user.home'};
  740:     my $currentauth=&Apache::lonnet::queryauthenticate($user,$domain);
  741:     # Check for authentication types that allow changing of the password.
  742:     return if ($currentauth !~ /^(unix|internal):/);
  743:     #
  744:     my $html=&Apache::lonxml::xmlbegin();
  745:     $r->print(<<ENDHEADER);
  746: $html
  747: <head>
  748: <title>LON-CAPA Preferences:  Change password for $user</title>
  749: </head>
  750: ENDHEADER
  751:     #
  752:     my $currentpass = $env{'form.currentpass'}; 
  753:     my $newpass1    = $env{'form.newpass_1'}; 
  754:     my $newpass2    = $env{'form.newpass_2'};
  755:     my $logtoken    = $env{'form.logtoken'};
  756:     # Check for empty data 
  757:     unless (defined($currentpass) && 
  758: 	    defined($newpass1)    && 
  759: 	    defined($newpass2)    ){
  760: 	&passwordchanger($r,"<p>\n<font color='#ff0000'>ERROR</font>".
  761: 			 "Password data was blank.\n</p>");
  762: 	return;
  763:     }
  764:     # Get the keys
  765:     my $lonhost = $r->dir_config('lonHostID');
  766:     my $tmpinfo = Apache::lonnet::reply('tmpget:'.$logtoken,$lonhost);
  767:     if (($tmpinfo=~/^error/) || ($tmpinfo eq 'con_lost')) {
  768:         # I do not a have a better idea about how to handle this
  769: 	$r->print(<<ENDERROR);
  770: <p>
  771: <font color="#ff0000">ERROR:</font> Unable to retrieve stored token for
  772: password decryption.  Please log out and try again.
  773: </p>
  774: ENDERROR
  775:         # Probably should log an error here
  776:         return;
  777:     }
  778:     my ($ckey,$n1key,$n2key)=split(/&/,$tmpinfo);
  779:     # 
  780:     $currentpass = &des_decrypt($ckey ,$currentpass);
  781:     $newpass1    = &des_decrypt($n1key,$newpass1);
  782:     $newpass2    = &des_decrypt($n2key,$newpass2);
  783:     # 
  784:     if ($newpass1 ne $newpass2) {
  785: 	&passwordchanger($r,
  786: 			 '<font color="#ff0000">ERROR:</font>'.
  787: 			 'The new passwords you entered do not match.  '.
  788: 			 'Please try again.');
  789: 	return;
  790:     }
  791:     if (length($newpass1) < 7) {
  792: 	&passwordchanger($r,
  793: 			 '<font color="#ff0000">ERROR:</font>'.
  794: 			 'Passwords must be a minimum of 7 characters long.  '.
  795: 			 'Please try again.');
  796: 	return;
  797:     }
  798:     #
  799:     # Check for bad characters
  800:     my $badpassword = 0;
  801:     foreach (split(//,$newpass1)) {
  802: 	$badpassword = 1 if ((ord($_)<32)||(ord($_)>126));
  803:     }
  804:     if ($badpassword) {
  805: 	# I can't figure out how to enter bad characters on my browser.
  806: 	&passwordchanger($r,<<ENDERROR);
  807: <font color="#ff0000">ERROR:</font>
  808: The password you entered contained illegal characters.<br />
  809: Valid characters are: space and <br />
  810: <pre>
  811: !&quot;\#$%&amp;\'()*+,-./0123456789:;&lt;=&gt;?\@
  812: ABCDEFGHIJKLMNOPQRSTUVWXYZ[\]^_\`abcdefghijklmnopqrstuvwxyz{|}~
  813: </pre>
  814: ENDERROR
  815:     }
  816:     # 
  817:     # Change the password (finally)
  818:     my $result = &Apache::lonnet::changepass
  819: 	($user,$domain,$currentpass,$newpass1,$homeserver);
  820:     # Inform the user the password has (not?) been changed
  821:     if ($result =~ /^ok$/) {
  822: 	$r->print(<<"ENDTEXT");
  823: <h2>The password for $user was successfully changed</h2>
  824: ENDTEXT
  825:     } else {
  826: 	# error error: run in circles, scream and shout
  827:         $r->print(<<ENDERROR);
  828: <h2><font color="#ff0000">The password for $user was not changed</font></h2>
  829: Please make sure your old password was entered correctly.
  830: ENDERROR
  831:     }
  832:     return;
  833: }
  834: 
  835: ################################################################
  836: #            discussion display subroutines 
  837: ################################################################
  838: sub discussionchanger {
  839:     my $r = shift;
  840:     my $user       = $env{'user.name'};
  841:     my $domain     = $env{'user.domain'};
  842:     my %userenv = &Apache::lonnet::get
  843:         ('environment',['discdisplay','discmarkread']);
  844:     my $discdisp = 'allposts';
  845:     my $discmark = 'onmark';
  846: 
  847:     if (defined($userenv{'discdisplay'})) {
  848:         unless ($userenv{'discdisplay'} eq '') { 
  849:             $discdisp = $userenv{'discdisplay'};
  850:         }
  851:     }
  852:     if (defined($userenv{'discmarkread'})) {
  853:         unless ($userenv{'discdisplay'} eq '') { 
  854:             $discmark = $userenv{'discmarkread'};
  855:         }
  856:     }
  857: 
  858:     my $newdisp = 'unread';
  859:     my $newmark = 'ondisp';
  860: 
  861:     my $function = &Apache::loncommon::get_users_function();
  862:     my $color = &Apache::loncommon::designparm($function.'.tabbg',
  863:                                                     $env{'user.domain'});
  864:     my %lt = &Apache::lonlocal::texthash(
  865:         'pref' => 'Display Preference',
  866:         'curr' => 'Current setting ',
  867:         'actn' => 'Action',
  868:         'sdpf' => 'Set display preferences for discussion posts for both bulletin boards and individual resources in all your courses.',
  869:         'prca' => 'Preferences can be set that determine',
  870:         'whpo' => 'Which posts are displayed when you display a bulletin board or resource, and',
  871:         'unwh' => 'Under what circumstances posts are identfied as "New"',
  872:         'allposts' => 'All posts',
  873:         'unread' => 'New posts only',
  874:         'ondisp' => 'Once displayed',
  875:         'onmark' => 'Once marked as read',
  876:         'disa' => 'Posts displayed?',
  877:         'npmr' => 'New posts cease to be identified as "New"?',
  878:         'thde'  => 'The preferences you set here can be overridden within each individual discussion.',
  879:         'chgt' => 'Change to '
  880:     );
  881:     my $dispchange = $lt{'unread'};
  882:     my $markchange = $lt{'ondisp'};
  883:     my $currdisp = $lt{'allposts'};
  884:     my $currmark = $lt{'onmark'};
  885: 
  886:     if ($discdisp eq 'unread') {
  887:         $dispchange = $lt{'allposts'};
  888:         $currdisp = $lt{'unread'};
  889:         $newdisp = 'allposts';
  890:     }
  891: 
  892:     if ($discmark eq 'ondisp') {
  893:         $markchange = $lt{'onmark'};
  894:         $currmark = $lt{'ondisp'};
  895:         $newmark = 'onmark';
  896:     }
  897:     
  898:     $r->print(<<"END");
  899: <form name="server" action="/adm/preferences" method="post">
  900: <input type="hidden" name="action" value="verify_and_change_discussion" />
  901: <br />
  902: $lt{'sdpf'}<br/> $lt{'prca'}  <ol><li>$lt{'whpo'}</li><li>$lt{'unwh'}</li></ol> 
  903: <br />
  904: <br />
  905: <table border="0" cellpadding="0" cellspacing="0">
  906:  <tr>
  907:   <td width="100%" bgcolor="#000000">
  908:    <table width="100%" border="0" cellpadding="1" cellspacing="0">
  909:     <tr>
  910:      <td width="100%" bgcolor="#000000">
  911:       <table border="0" cellpadding="3" cellspacing="3" bgcolor="#FFFFFF">
  912:        <tr bgcolor="$color">
  913:         <td><b>$lt{'pref'}</b></td>
  914:         <td><b>$lt{'curr'}</b></td>
  915:         <td><b>$lt{'actn'}?</b></td>
  916:        </tr>
  917:        <tr bgcolor="#dddddd">
  918:        <td>$lt{'disa'}</td>
  919:        <td>$lt{$discdisp}</td>
  920:        <td><input type="checkbox" name="discdisp" /><input type="hidden" name="newdisp" value="$newdisp" />&nbsp;$lt{'chgt'} "$dispchange"</td>
  921:       </tr><tr bgcolor="#eeeeee">
  922:        <td>$lt{'npmr'}</td>
  923:        <td>$lt{$discmark}</td>
  924:        <td><input type="checkbox" name="discmark" /><input type="hidden" name="newmark" value="$newmark" />&nbsp;$lt{'chgt'} "$markchange"</td>
  925:       </tr>
  926:      </table>
  927:     </td>
  928:    </tr>
  929:   </table>
  930:  </td>
  931: </tr>
  932: </table>
  933: <br />
  934: <br />
  935: <input type="submit" name="sub" value="Store Changes" />
  936: <br />
  937: <br />
  938: Note: $lt{'thde'}
  939: </form>
  940: END
  941: }
  942:                                                                                                                 
  943: sub verify_and_change_discussion {
  944:     my $r = shift;
  945:     my $user     = $env{'user.name'};
  946:     my $domain   = $env{'user.domain'};
  947:     my $message='';
  948:     if (defined($env{'form.discdisp'}) ) {
  949:         my $newdisp  = $env{'form.newdisp'};
  950:         if ($newdisp eq 'unread') {
  951:             $message .='In discussions: only new posts will be displayed.<br/>';
  952:             &Apache::lonnet::put('environment',{'discdisplay' => $newdisp});
  953:             &Apache::lonnet::appenv('environment.discdisplay' => $newdisp);
  954:         } else {
  955:             $message .= 'In discussions: all posts will be displayed.<br/>';
  956:             &Apache::lonnet::del('environment',['discdisplay']);
  957:             &Apache::lonnet::delenv('environment\.discdisplay');
  958:         }
  959:     }
  960:     if (defined($env{'form.discmark'}) ) {
  961:         my $newmark = $env{'form.newmark'};
  962:         if ($newmark eq 'ondisp') {
  963:            $message.='In discussions: new posts will be cease to be identified as "new" after display.<br/>';
  964:             &Apache::lonnet::put('environment',{'discmarkread' => $newmark});
  965:             &Apache::lonnet::appenv('environment.discmarkread' => $newmark);
  966:         } else {
  967:             $message.='In discussions: posts will be identified as "new" until marked as read by the reader.<br/>';
  968:             &Apache::lonnet::del('environment',['discmarkread']);
  969:             &Apache::lonnet::delenv('environment\.discmarkread');
  970:         }
  971:     }
  972:     $r->print(<<ENDVCSCREEN);
  973: $message
  974: ENDVCSCREEN
  975: }
  976: 
  977: ################################################################
  978: # Subroutines for page display on course access (Course Coordinators)
  979: ################################################################
  980: sub coursedisplaychanger {
  981:     my $r = shift;
  982:     my $user       = $env{'user.name'};
  983:     my $domain     = $env{'user.domain'};
  984:     my %userenv = &Apache::lonnet::get('environment',['course_init_display']);
  985:     my $currvalue = 'whatsnew';
  986:     my $firstselect = '';
  987:     my $whatsnewselect = 'checked="checked"';
  988:     if (exists($userenv{'course_init_display'})) {
  989:         if ($userenv{'course_init_display'} eq 'firstres') {
  990:             $currvalue = 'firstres';
  991:             $firstselect = 'checked="checked"';
  992: 	    $whatsnewselect = '';
  993:         }
  994:     }
  995:     my %pagenames = (
  996:                        firstres => 'First resource',
  997:                        whatsnew => "What's new page",
  998:                     );
  999:     my $whatsnew_off=&mt('Display the [_1] in the course.','<b>first resource</b>');
 1000:     my $whatsnew_on=&mt('Display the "[_1]" page - a summary of items in the course which require attention.',"<b>What's New</b>");
 1001: 
 1002:     $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 />');
 1003:     $r->print(<<ENDLSCREEN);
 1004: <form name="server" action="/adm/preferences" method="post">
 1005: <input type="hidden" name="action" value="verify_and_change_coursepage" />
 1006: <br />
 1007: <label><input type="radio" name="newdisp" value="firstres" $firstselect /> $whatsnew_off</label><br />
 1008: <label><input type="radio" name="newdisp" value="whatsnew" $whatsnewselect /> $whatsnew_on</label><input type="hidden" name="refpage" value="$env{'form.refpage'}" />
 1009: ENDLSCREEN
 1010:     $r->print('<br /><br /><input type="submit" value="'.&mt('Change').'" />
 1011: </form>');
 1012: }
 1013: 
 1014: sub verify_and_change_coursepage {
 1015:     my $r = shift;
 1016:     my $message='';
 1017:     my %lt = &Apache::lonlocal::texthash(
 1018:         'defs' => 'Default now set',
 1019:         'when' => 'when you select a course role from the roles screen',
 1020:         'ywbt' => 'you will be taken to the start of the course.',
 1021:         'apwb' => 'a page will be displayed that lists items in the course that may require action from you.',
 1022:         'gtts' => 'Go to the start of the course',
 1023:         'dasp' => "Display the What's New page listing course action items", 
 1024:     );
 1025:     my $newdisp  = $env{'form.newdisp'};
 1026:     $message = '<b>'.$lt{'defs'}.'</b>: '.$lt{'when'}.', ';
 1027:     if ($newdisp eq 'firstres') {
 1028:         $message .= $lt{'ywbt'}.'<br/>';
 1029:         &Apache::lonnet::put('environment',{'course_init_display' => $newdisp});
 1030:         &Apache::lonnet::appenv('environment.course_init_display' => $newdisp);
 1031:     } else {
 1032:         $message .= $lt{'apwb'}.'<br/>';
 1033:         &Apache::lonnet::del('environment',['course_init_display']);
 1034:         &Apache::lonnet::delenv('environment\.course_init_display');
 1035:     }
 1036:     my $refpage = $env{'form.refpage'};
 1037:     if (($env{'request.course.fn'}) && ($env{'request.course.id'})) {
 1038:         if ($newdisp eq 'firstres') {
 1039:             my $cdom = $env{'course.'.$env{'request.course.id'}.'.domain'};
 1040:             my $cnum = $env{'course.'.$env{'request.course.id'}.'.num'}; 
 1041:             my ($furl,$ferr)=
 1042:                 &Apache::lonuserstate::readmap($cdom.'/'.$cnum);
 1043:             $message .= '<br /><font size="+1"><a href="'.$furl.'">'.$lt{'gtts'}.' <i>'.&mt('now').'</i></a></font>';
 1044:         } else {
 1045:             $message .= '<br /><font size="+1"><a href="/adm/whatsnew?refpage='.
 1046:                         $refpage.'">'.$lt{'dasp'}.'</a></font>';
 1047:         }
 1048:     }
 1049:     $r->print(<<ENDVCSCREEN);
 1050: $message
 1051: <br /><br />
 1052: ENDVCSCREEN
 1053: }
 1054: 
 1055: 
 1056: ######################################################
 1057: #            other handler subroutines               #
 1058: ######################################################
 1059: 
 1060: ################################################################
 1061: #                          Main handler                        #
 1062: ################################################################
 1063: sub handler {
 1064:     my $r = shift;
 1065:     my $user = $env{'user.name'};
 1066:     my $domain = $env{'user.domain'};
 1067:     &Apache::loncommon::content_type($r,'text/html');
 1068:     # Some pages contain DES keys and should not be cached.
 1069:     &Apache::loncommon::no_cache($r);
 1070:     $r->send_http_header;
 1071:     return OK if $r->header_only;
 1072:     #
 1073:     &Apache::loncommon::get_unprocessed_cgi($ENV{'QUERY_STRING'},
 1074:                                    ['action','wysiwyg','returnurl','refpage']);
 1075:     #
 1076:     &Apache::lonhtmlcommon::clear_breadcrumbs();
 1077:     &Apache::lonhtmlcommon::add_breadcrumb
 1078:         ({href => '/adm/preferences',
 1079:           text => 'Set User Preferences'});
 1080: 
 1081:     my @Options;
 1082:     # Determine current authentication method
 1083:     my $currentauth=&Apache::lonnet::queryauthenticate($user,$domain);
 1084:     if ($currentauth =~ /^(unix|internal):/) {
 1085:         push (@Options,({ action   => 'changepass',
 1086:                           linktext => 'Change Password',
 1087:                           href     => '/adm/preferences',
 1088:                           help     => 'Change_Password',
 1089:                           subroutine => \&passwordchanger,
 1090:                           breadcrumb => 
 1091:                               { href => '/adm/preferences?action=changepass',
 1092:                                 text => 'Change Password'},
 1093:                           },
 1094:                         { action => 'verify_and_change_pass',
 1095:                           subroutine => \&verify_and_change_password,
 1096:                           breadcrumb => 
 1097:                               { href =>'/adm/preferences?action=changepass',
 1098:                                 text => 'Change Password'},
 1099:                           printmenu => 'yes',
 1100:                           }));
 1101:     }
 1102:     push (@Options,({ action   => 'changescreenname',
 1103:                       linktext => 'Change Screen Name',
 1104:                       href     => '/adm/preferences',
 1105:                       help     => 'Prefs_Screen_Name_Nickname',
 1106:                       subroutine => \&screennamechanger,
 1107:                       breadcrumb => 
 1108:                           { href => '/adm/preferences?action=changescreenname',
 1109:                             text => 'Change Screen Name'},
 1110:                       },
 1111:                     { action   => 'verify_and_change_screenname',
 1112:                       subroutine => \&verify_and_change_screenname,
 1113:                       breadcrumb => 
 1114:                           { href => '/adm/preferences?action=changescreenname',
 1115:                             text => 'Change Screen Name'},
 1116:                       printmenu => 'yes',
 1117:                       }));
 1118: 
 1119:     push (@Options,({ action   => 'changemsgforward',
 1120:                       linktext => 'Change Message Forwarding and Notification Addresses',
 1121:                       href     => '/adm/preferences',
 1122:                       help     => 'Prefs_Forwarding',
 1123:                       breadcrumb => 
 1124:                           { href => '/adm/preferences?action=changemsgforward',
 1125:                             text => 'Change Message Forwarding'},
 1126:                       subroutine => \&msgforwardchanger,
 1127:                       },
 1128:                     { action => 'verify_and_change_msgforward',
 1129:                       breadcrumb => 
 1130:                           { href => '/adm/preferences?action=changemsgforward',
 1131:                             text => 'Change Message Forwarding'},
 1132:                       printmenu => 'yes',
 1133:                       subroutine => \&verify_and_change_msgforward }));
 1134:     my $aboutmeaction=
 1135:         '/adm/'.$env{'user.domain'}.'/'.$env{'user.name'}.'/aboutme';
 1136:     push (@Options,{ action => 'none', 
 1137:                      linktext =>
 1138:                          q{Edit the 'About Me' Personal Information Screen},
 1139: 		     help => 'Prefs_About_Me',
 1140:                      href => $aboutmeaction});
 1141:     push (@Options,({ action => 'changecolors',
 1142:                       linktext => 'Change Color Scheme',
 1143:                       href => '/adm/preferences',
 1144:                       help => 'Change_Colors',
 1145:                       breadcrumb => 
 1146:                           { href => '/adm/preferences?action=changecolors',
 1147:                             text => 'Change Colors'},
 1148:                       subroutine => \&colorschanger,
 1149:                   },
 1150:                     { action => 'verify_and_change_colors',
 1151:                       breadcrumb => 
 1152:                           { href => '/adm/preferences?action=changecolors',
 1153:                             text => 'Change Colors'},
 1154:                       printmenu => 'yes',
 1155:                       subroutine => \&verify_and_change_colors,
 1156:                       }));
 1157:     push (@Options,({ action => 'changelanguages',
 1158:                       linktext => 'Change Language Preferences',
 1159:                       href => '/adm/preferences',
 1160: 		      help => 'Prefs_Language',
 1161:                       breadcrumb=>
 1162:                           { href => '/adm/preferences?action=changelanguages',
 1163:                             text => 'Change Language'},
 1164:                       subroutine =>  \&languagechanger,
 1165:                   },
 1166:                     { action => 'verify_and_change_languages',
 1167:                       breadcrumb=>
 1168:                           {href => '/adm/preferences?action=changelanguages',
 1169:                            text => 'Change Language'},
 1170:                       printmenu => 'yes',
 1171:                       subroutine=>\&verify_and_change_languages, }
 1172:                     ));
 1173:     push (@Options,({ action => 'changewysiwyg',
 1174:                       linktext => 'Change WYSIWYG Editor Preferences',
 1175:                       href => '/adm/preferences',
 1176:                       breadcrumb => 
 1177:                             { href => '/adm/preferences?action=changewysiwyg',
 1178:                               text => 'Change WYSIWYG Preferences'},
 1179:                       subroutine => \&wysiwygchanger,
 1180:                   },
 1181:                     { action => 'set_wysiwyg',
 1182:                       breadcrumb =>
 1183:                           { href => '/adm/preferences?action=changewysiwyg',
 1184:                             text => 'Change WYSIWYG Preferences'},
 1185:                       printmenu => 'yes',
 1186:                       subroutine => \&verify_and_change_wysiwyg, }
 1187:                     ));
 1188:     push (@Options,({ action => 'changediscussions',
 1189:                       linktext => 'Change Discussion Display Preferences',
 1190:                       href => '/adm/preferences',
 1191:                       help => 'Change_Discussion_Display',
 1192:                       breadcrumb => 
 1193:                             { href => '/adm/preferences?action=changediscussions',
 1194:                               text => 'Change Discussion Preferences'},
 1195:                       subroutine => \&discussionchanger,
 1196:                   },
 1197:                     { action => 'verify_and_change_discussion',
 1198:                       breadcrumb =>
 1199:                           { href => '/adm/preferences?action=changediscussions',
 1200:                             text => 'Change Discussion Preferences'},
 1201:                       printmenu => 'yes',
 1202:                       subroutine => \&verify_and_change_discussion, }
 1203:                     ));
 1204:                        
 1205:     push (@Options,({ action   => 'changerolespref',
 1206:                       linktext => 'Change Roles Page Preferences',
 1207:                       href     => '/adm/preferences',
 1208:                       subroutine => \&rolesprefchanger,
 1209:                       breadcrumb =>
 1210:                           { href => '/adm/preferences?action=changerolespref',
 1211:                             text => 'Change Roles Pref'},
 1212:                       },
 1213:                     { action   => 'verify_and_change_rolespref',
 1214:                       subroutine => \&verify_and_change_rolespref,
 1215:                       breadcrumb =>
 1216:                           { href => '/adm/preferences?action=changerolespref',
 1217:                             text => 'Change Roles Preferences'},
 1218:                       printmenu => 'yes',
 1219:                       }));
 1220: 
 1221:     push (@Options,({ action   => 'changetexenginepref',
 1222:                       linktext => 'Change How Math Equations Are Displayed',
 1223:                       href     => '/adm/preferences',
 1224:                       subroutine => \&texenginechanger,
 1225:                       breadcrumb =>
 1226:                           { href => '/adm/preferences?action=changetexenginepref',
 1227:                             text => 'Change Math Pref'},
 1228:                       },
 1229:                     { action   => 'verify_and_change_texengine',
 1230:                       subroutine => \&verify_and_change_texengine,
 1231:                       breadcrumb =>
 1232:                           { href => '/adm/preferences?action=changetexenginepref',
 1233:                             text => 'Change Math Preferences'},
 1234:                       printmenu => 'yes',
 1235:                       }));
 1236:     if (&Apache::lonnet::allowed('whn',$env{'request.course.id'})
 1237: 	|| &Apache::lonnet::allowed('whn',$env{'request.course.id'}.'/'
 1238: 				    .$env{'request.course.sec'})) {
 1239:         push (@Options,({ action => 'changecourseinit',
 1240:                           linktext => 'Change Course Initialization Preference',
 1241:                           href => '/adm/preferences',
 1242:                           subroutine => \&coursedisplaychanger,
 1243:                           breadcrumb =>
 1244:                               { href => '/adm/preferences?action=changecourseinit',
 1245:                                 text => 'Change Course Init. Pref.'},
 1246:                           },
 1247:                         { action => 'verify_and_change_coursepage',
 1248:                           breadcrumb =>
 1249:                           { href => '/adm/preferences?action=changecourseinit',                               text => 'Change Course Initialization Preference'},
 1250:                         printmenu => 'yes',
 1251:                         subroutine => \&verify_and_change_coursepage,
 1252:                        }));
 1253:     }
 1254: 
 1255:     if ($env{'user.name'} =~ /^(albertel|fox|foxr|koretemey|korte|hallmat3|turtle|raeburn)$/) {
 1256:         push (@Options,({ action => 'debugtoggle',
 1257:                           printmenu => 'yes',
 1258:                           subroutine => \&toggle_debug,
 1259:                           }));
 1260:     }
 1261:     my $html=&Apache::lonxml::xmlbegin();
 1262:     $r->print(<<ENDHEADER);
 1263: $html
 1264: <head>
 1265: <title>LON-CAPA Preferences</title>
 1266: </head>
 1267: ENDHEADER
 1268:     my $call = undef;
 1269:     my $help = undef;
 1270:     my $printmenu = 'yes';
 1271:     foreach my $option (@Options) {
 1272:         if ($option->{'action'} eq $env{'form.action'}) {
 1273:             $call = $option->{'subroutine'};
 1274:             $printmenu = $option->{'printmenu'};
 1275:             if (exists($option->{'breadcrumb'})) {
 1276:                 &Apache::lonhtmlcommon::add_breadcrumb
 1277:                     ($option->{'breadcrumb'});
 1278:             }
 1279: 	    $help=$option->{'help'};
 1280:         }
 1281:     }
 1282:     $r->print(&Apache::loncommon::bodytag('Change Preferences'));
 1283:     $r->print(&Apache::lonhtmlcommon::breadcrumbs
 1284:               (undef,'Change Preferences',$help));
 1285:     if (defined($call)) {
 1286:         $call->($r);
 1287:     }
 1288:     if (($printmenu eq 'yes') && (!$env{'form.returnurl'})) {
 1289:         my $optionlist = '<table cellpadding="5">';
 1290:         if ($env{'user.name'} =~ 
 1291:                          /^(albertel|kortemey|fox|foxr|korte|hallmat3|turtle|raeburn)$/
 1292:             ) {
 1293:             push (@Options,({ action => 'debugtoggle',
 1294:                               linktext => 'Toggle Debug Messages',
 1295:                               text => 'Current Debug status is -'.
 1296:                                   $env{'user.debug'}.'-.',
 1297:                               href => '/adm/preferences',
 1298:                               printmenu => 'yes',
 1299:                               subroutine => \&toggle_debug,
 1300:                               }));
 1301:         }
 1302:         foreach my $option(@Options) {
 1303:             my $optiontext = '';
 1304:             if (exists($option->{'href'})) {
 1305:                 $optiontext .= 
 1306:                     '<a href="'.$option->{'href'}.
 1307:                     '?action='.$option->{'action'}.'">'.
 1308:                     &mt($option->{'linktext'}).'</a>';
 1309:             }
 1310:             if (exists($option->{'text'})) {
 1311:                 $optiontext .= ' '.&mt($option->{'text'});
 1312:             }
 1313:             if ($optiontext ne '') {
 1314:                 $optiontext = '<font size="+1">'.$optiontext.'</font>'; 
 1315:                 my $helplink = '&nbsp;';
 1316:                 if (exists($option->{'help'})) {
 1317:                     $helplink = &Apache::loncommon::help_open_topic
 1318:                                                     ($option->{'help'});
 1319:                 }
 1320:                 $optionlist .= '<tr>'.
 1321:                     '<td>'.$helplink.'</td>'.
 1322:                     '<td>'.$optiontext.'</td>'.
 1323:                     '</tr>';
 1324:             }
 1325:         }
 1326:         $optionlist .= '</table>';
 1327:         $r->print($optionlist);
 1328:     } elsif ($env{'form.returnurl'}) {
 1329: 	$r->print('<br /><a href="'.$env{'form.returnurl'}.'"><font size="+1">'.
 1330: 		  &mt('Return').'</font></a>');
 1331:     }
 1332:     $r->print(&Apache::loncommon::endbodytag().'</html>');
 1333:     return OK;
 1334: }
 1335: 
 1336: sub toggle_debug {
 1337:     if ($env{'user.debug'}) {
 1338:         &Apache::lonnet::delenv('user\.debug');
 1339:     } else {
 1340:         &Apache::lonnet::appenv('user.debug' => 1);
 1341:     }
 1342: }
 1343: 
 1344: 1;
 1345: __END__

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