File:  [LON-CAPA] / loncom / interface / lonpreferences.pm
Revision 1.90: download - view: text, annotated - select for diffs
Wed Jun 14 19:13:11 2006 UTC (18 years ago) by albertel
Branches: MAIN
CVS tags: HEAD
- typo

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

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