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

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

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