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

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

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