File:  [LON-CAPA] / loncom / interface / lonpreferences.pm
Revision 1.82: download - view: text, annotated - select for diffs
Mon May 1 22:15:17 2006 UTC (18 years ago) by albertel
Branches: MAIN
CVS tags: HEAD
- some data table conversion
- <label>

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

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