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

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

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