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

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

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