Annotation of loncom/interface/lonpreferences.pm, revision 1.59

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

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