File:  [LON-CAPA] / loncom / interface / lonpreferences.pm
Revision 1.54: download - view: text, annotated - select for diffs
Fri Feb 25 05:54:01 2005 UTC (19 years, 4 months ago) by albertel
Branches: MAIN
CVS tags: HEAD
- adding jsMath as a TeX -> HTML option
- adding the ability for a user to choose between jsMath and tth
- setting tth as the default, but I think the default should be based off browser detection, on anything at all modern jsMath is much sexier

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

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