File:  [LON-CAPA] / loncom / interface / lonpreferences.pm
Revision 1.93: download - view: text, annotated - select for diffs
Mon Jun 26 18:56:50 2006 UTC (17 years, 10 months ago) by albertel
Branches: MAIN
CVS tags: version_2_2_X, version_2_2_2, version_2_2_1, version_2_2_0, version_2_1_99_3, version_2_1_99_2, version_2_1_99_1, version_2_1_99_0, HEAD
- extend plaintext to handle cr roles
- lonroles makes use of the improved plaintext
- from mlucas

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

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