File:  [LON-CAPA] / loncom / interface / lonpreferences.pm
Revision 1.92: download - view: text, annotated - select for diffs
Thu Jun 22 23:30:33 2006 UTC (18 years ago) by albertel
Branches: MAIN
CVS tags: HEAD
- from Mark Lucas (BUG#3763) fixes yup the role display order.

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

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