File:  [LON-CAPA] / loncom / interface / lonpreferences.pm
Revision 1.109: download - view: text, annotated - select for diffs
Tue Jul 17 21:11:49 2007 UTC (16 years, 9 months ago) by albertel
Branches: MAIN
CVS tags: version_2_6_0, version_2_5_X, version_2_5_99_1, version_2_5_99_0, version_2_5_2, version_2_5_1, version_2_5_0, version_2_4_99_0, HEAD
-flush the chaced emails addresses if updates occur

    1: # The LearningOnline Network
    2: # Preferences
    3: #
    4: # $Id: lonpreferences.pm,v 1.109 2007/07/17 21:11:49 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: use LONCAPA();
   46: 
   47: #
   48: # Write lonnet::passwd to do the call below.
   49: # Use:
   50: #   my $answer=reply("encrypt:passwd:$udom:$uname:$upass",$tryserver);
   51: #
   52: ##################################################
   53: #          password associated functions         #
   54: ##################################################
   55: sub des_keys {
   56:     # Make a new key for DES encryption.
   57:     # Each key has two parts which are returned separately.
   58:     # Please note:  Each key must be passed through the &hex function
   59:     # before it is output to the web browser.  The hex versions cannot
   60:     # be used to decrypt.
   61:     my @hexstr=('0','1','2','3','4','5','6','7',
   62:                 '8','9','a','b','c','d','e','f');
   63:     my $lkey='';
   64:     for (0..7) {
   65:         $lkey.=$hexstr[rand(15)];
   66:     }
   67:     my $ukey='';
   68:     for (0..7) {
   69:         $ukey.=$hexstr[rand(15)];
   70:     }
   71:     return ($lkey,$ukey);
   72: }
   73: 
   74: sub des_decrypt {
   75:     my ($key,$cyphertext) = @_;
   76:     my $keybin=pack("H16",$key);
   77:     my $cypher;
   78:     if ($Crypt::DES::VERSION>=2.03) {
   79:         $cypher=new Crypt::DES $keybin;
   80:     } else {
   81:         $cypher=new DES $keybin;
   82:     }
   83:     my $plaintext=
   84: 	$cypher->decrypt(unpack("a8",pack("H16",substr($cyphertext,0,16))));
   85:     $plaintext.=
   86: 	$cypher->decrypt(unpack("a8",pack("H16",substr($cyphertext,16,16))));
   87:     $plaintext=substr($plaintext,1,ord(substr($plaintext,0,1)) );
   88:     return $plaintext;
   89: }
   90: 
   91: ################################################################
   92: #                       Handler subroutines                    #
   93: ################################################################
   94: 
   95: ################################################################
   96: #         Language Change Subroutines                          #
   97: ################################################################
   98: 
   99: sub wysiwygchanger {
  100:     my $r = shift;
  101:     my %userenv = &Apache::lonnet::get
  102:         ('environment',['wysiwygeditor']);
  103:     my $onselect='checked="checked"';
  104:     my $offselect='';
  105:     if ($userenv{'wysiwygeditor'} eq 'on') {
  106: 	$onselect='';
  107: 	$offselect='checked="checked"';
  108:     }
  109:     my $switchoff=&mt('Disable WYSIWYG editor');
  110:     my $switchon=&mt('Enable WYSIWYG editor');
  111:     $r->print(<<ENDLSCREEN);
  112: <form name="prefs" action="/adm/preferences" method="post">
  113: <input type="hidden" name="action" value="set_wysiwyg" />
  114: <br />
  115: <label><input type="radio" name="wysiwyg" value="off" $onselect /> $switchoff</label><br />
  116: <label><input type="radio" name="wysiwyg" value="on" $offselect /> $switchon</label>
  117: ENDLSCREEN
  118:     $r->print('<br /><input type="submit" value="'.&mt('Change').'" />');
  119: }
  120: 
  121: 
  122: sub verify_and_change_wysiwyg {
  123:     my $r = shift;
  124:     my $newsetting=$env{'form.wysiwyg'};
  125:     &Apache::lonnet::put('environment',{'wysiwygeditor' => $newsetting});
  126:     &Apache::lonnet::appenv('environment.wysiwygeditor' => $newsetting);
  127:     $r->print('<p>'.&mt('Setting WYSIWYG editor to:').' '.&mt($newsetting).'</p>');
  128: }
  129: 
  130: ################################################################
  131: #         Language Change Subroutines                          #
  132: ################################################################
  133: sub languagechanger {
  134:     my $r = shift;
  135:     my $user       = $env{'user.name'};
  136:     my $domain     = $env{'user.domain'};
  137:     my %userenv = &Apache::lonnet::get
  138:         ('environment',['languages']);
  139:     my $language=$userenv{'languages'};
  140: 
  141:     my $pref=&mt('Preferred language');
  142:     my %langchoices=('' => 'No language preference');
  143:     foreach (&Apache::loncommon::languageids()) {
  144: 	if (&Apache::loncommon::supportedlanguagecode($_)) {
  145: 	    $langchoices{&Apache::loncommon::supportedlanguagecode($_)}
  146: 	               = &Apache::loncommon::plainlanguagedescription($_);
  147: 	}
  148:     }
  149:     my $selectionbox=&Apache::loncommon::select_form($language,'language',
  150: 						     %langchoices);
  151:     $r->print(<<ENDLSCREEN);
  152: <form name="prefs" action="/adm/preferences" method="post">
  153: <input type="hidden" name="action" value="verify_and_change_languages" />
  154: <br />$pref: $selectionbox
  155: ENDLSCREEN
  156:     $r->print('<br /><input type="submit" value="'.&mt('Change').'" />');
  157: }
  158: 
  159: 
  160: sub verify_and_change_languages {
  161:     my $r = shift;
  162:     my $user       = $env{'user.name'};
  163:     my $domain     = $env{'user.domain'};
  164: # Screenname
  165:     my $newlanguage  = $env{'form.language'};
  166:     $newlanguage=~s/[^\-\w]//g;
  167:     my $message='';
  168:     if ($newlanguage) {
  169:         &Apache::lonnet::put('environment',{'languages' => $newlanguage});
  170:         &Apache::lonnet::appenv('environment.languages' => $newlanguage);
  171:         $message='Set new preferred languages to '.$newlanguage;
  172:     } else {
  173:         &Apache::lonnet::del('environment',['languages']);
  174:         &Apache::lonnet::delenv('environment\.languages');
  175:         $message='Reset preferred language';
  176:     }
  177:     $r->print(<<ENDVCSCREEN);
  178: $message
  179: ENDVCSCREEN
  180: }
  181: 
  182: ################################################################
  183: #         Tex Engine Change Subroutines                        #
  184: ################################################################
  185: sub texenginechanger {
  186:     my $r = shift;
  187:     my $user       = $env{'user.name'};
  188:     my $domain     = $env{'user.domain'};
  189:     my %userenv = &Apache::lonnet::get('environment',['texengine']);
  190:     my $texengine=$userenv{'texengine'};
  191: 
  192:     my $pref=&mt('Preferred method to display Math');
  193:     my %mathchoices=('' => 'Default',
  194: 		     'tth' => 'TeX to HTML',
  195: 		     #'ttm' => 'TeX to MathML',
  196: 		     'jsMath' => 'jsMath',
  197: 		     'mimetex' => 'Convert to Images'
  198:                      );
  199:     my $selectionbox=&Apache::loncommon::select_form($texengine,'texengine',
  200: 						     %mathchoices);
  201:     my $jsMath_start=&Apache::lontexconvert::jsMath_header();
  202:     my $change=&mt('Change');
  203:     $r->print(<<ENDLSCREEN);
  204: <br />
  205: 
  206: <form name="prefs" action="/adm/preferences" method="post">
  207: <input type="hidden" name="action" value="verify_and_change_texengine" />
  208: <p>$pref: $selectionbox</p>
  209: <p><input type="submit" value="$change" /></p>
  210: </form>
  211: Examples:
  212: <p> TeX to HTML <br /> 
  213: <iframe src="/res/adm/pages/math_example.tex?inhibitmenu=yes&texengine=tth" width="400" hieght="200"></iframe>
  214: </p>
  215: <p>jsMath <br /> 
  216: $jsMath_start
  217: <script type="text/javascript">
  218: if (jsMath.nofonts == 1) {
  219:     document.writeln
  220:         ('<center><div style="padding: 10; border-style: solid; border-width:3;'
  221: 	 +' border-color: #DD0000; background-color: #FFF8F8; width: 75%; text-align: left">'
  222: 	 +'<small><font color="#AA0000"><b>Warning:</b> '
  223: 	 +'It looks like you don\\\'t have the TeX math fonts installed. '
  224: 	 +'The jsMath example on this page may not look right without them. '
  225: 	 +'The <a href="http://www.math.union.edu/locate/jsMath/" target="_blank"> '
  226: 	 +'jsMath Home Page</a> has information on how to download the '
  227: 	 +'needed fonts.  In the meantime, jsMath will do the best it can '
  228: 	 +'with the fonts you have, but it may not be pretty and some equations '
  229: 	 +'may not be rendered correctly. '
  230: 	 +'</font></small></div></center>');
  231: }
  232: </script>
  233: <iframe src="/res/adm/pages/math_example.tex?inhibitmenu=yes&texengine=jsMath" width="400" hieght="200"></iframe>
  234: 
  235: </p>
  236: <p> Convert to Images <br />
  237: <br />
  238: <iframe src="/res/adm/pages/math_example.tex?inhibitmenu=yes&texengine=mimetex" width="400" hieght="200"></iframe>
  239: </p>
  240: ENDLSCREEN
  241:     if ($env{'environment.texengine'} ne 'jsMath') {
  242: 	$r->print('<script type="text/javascript">jsMath.Process()</script>');
  243:     }
  244: }
  245: 
  246: 
  247: sub verify_and_change_texengine {
  248:     my $r = shift;
  249:     my $user       = $env{'user.name'};
  250:     my $domain     = $env{'user.domain'};
  251: # Screenname
  252:     my $newtexengine  = $env{'form.texengine'};
  253:     $newtexengine=~s/[^\-\w]//g;
  254:     if ($newtexengine eq 'ttm') {
  255: 	&Apache::lonnet::appenv('browser.mathml' => 1);
  256:     } else {
  257: 	if ($env{'environment.texengine'} eq 'ttm') {
  258: 	    &Apache::lonnet::appenv('browser.mathml' => 0);
  259: 	}
  260:     }
  261:     my $message='';
  262:     if ($newtexengine) {
  263:         &Apache::lonnet::put('environment',{'texengine' => $newtexengine});
  264:         &Apache::lonnet::appenv('environment.texengine' => $newtexengine);
  265:         $message='Set new preferred math display to '.$newtexengine;
  266:     } else {
  267:         &Apache::lonnet::del('environment',['texengine']);
  268:         &Apache::lonnet::delenv('environment\.texengine');
  269:         $message='Reset preferred math display.';
  270:     }
  271: 
  272: 
  273:     $r->print(<<ENDVCSCREEN);
  274: $message
  275: ENDVCSCREEN
  276: }
  277: 
  278: ################################################################
  279: #         Roles Page Preference Change Subroutines         #
  280: ################################################################
  281: sub rolesprefchanger {
  282:     my $r = shift;
  283:     my $role    = ($env{'user.adv'} ? 'Role' : 'Course');
  284:     my $lc_role = ($env{'user.adv'} ? 'role' : 'course');
  285:     my $user       = $env{'user.name'};
  286:     my $domain     = $env{'user.domain'};
  287:     my %userenv = &Apache::lonnet::get
  288:         ('environment',['recentroles','recentrolesn']);
  289:     my $hotlist_flag=$userenv{'recentroles'};
  290:     my $hotlist_n=$userenv{'recentrolesn'};
  291:     my $checked;
  292:     if ($hotlist_flag) {
  293: 	$checked = 'checked="checked"';
  294:     }
  295:     
  296:     if (!$hotlist_n) { $hotlist_n=3; }
  297:     my $options;
  298:     for (my $i=1; $i<10; $i++) {
  299: 	my $select;
  300: 	if ($hotlist_n == $i) { $select = 'selected="selected"'; }
  301: 	$options .= "<option $select>$i</option>\n";
  302:     }
  303: 
  304: # Get list of recent roles and display with checkbox in front
  305:     my $roles_check_list = '';
  306:     my $role_key='';
  307:     if ($env{'environment.recentroles'}) {
  308:         my %recent_roles =
  309:                &Apache::lonhtmlcommon::get_recent('roles',$env{'environment.recentrolesn'});
  310:         my %frozen_roles =
  311:                &Apache::lonhtmlcommon::get_recent_frozen('roles',$env{'environment.recentrolesn'});
  312:         
  313:         my %role_text = &rolespref_get_role_text([keys(%recent_roles)]);
  314:         my @sorted_roles = sort {$role_text{$a} cmp $role_text{$b}} keys(%role_text);
  315: 
  316:         $roles_check_list .=
  317: 	    &Apache::loncommon::start_data_table().
  318: 	    &Apache::loncommon::start_data_table_header_row().
  319: 	    "<th>".&mt('Freeze '.$role)."</th>".
  320: 	    "<th>".&mt($role)."</td>".
  321: 	    &Apache::loncommon::end_data_table_header_row().
  322: 	    "\n";
  323: 	my $count;
  324:         foreach $role_key (@sorted_roles) {
  325:             my $checked = "";
  326:             my $value = $recent_roles{$role_key};
  327:             if ($frozen_roles{$role_key}) {
  328:                 $checked = "checked=\"checked\"";
  329:             }
  330: 	    $count++;
  331:             $roles_check_list .=
  332: 		&Apache::loncommon::start_data_table_row().
  333: 		'<td class="LC_table_cell_checkbox">'.
  334: 		"<input type=\"checkbox\" $checked name=\"freezeroles\"".
  335: 		" id=\"freezeroles$count\" value=\"$role_key\" /></td>".
  336: 		"<td><label for=\"freezeroles$count\">".
  337: 		"$role_text{$role_key}</label></td>".
  338: 		&Apache::loncommon::end_data_table_row(). "\n";
  339:         }
  340:         $roles_check_list .= "</table>\n";
  341:     }
  342: 
  343:     $r->print('
  344: <p>'.&mt('Some LON-CAPA users have a long list of '.$lc_role.'s. The Recent '.$role.'s Hotlist feature keeps track of the last N '.$lc_role.'s which have been visited and places a table of these at the top of the '.$lc_role.'s page. People with very few '.$lc_role.'s should leave this feature disabled.').'
  345: </p>
  346: <form name="prefs" action="/adm/preferences" method="POST">
  347: <input type="hidden" name="action" value="verify_and_change_rolespref" />
  348: <br /><label>'.&mt('Enable Recent '.$role.'s Hotlist:').'
  349: <input type="checkbox" '.$checked.' name="recentroles" value="true" /></label>
  350: <br />'.&mt('Number of '.$role.'s in Hotlist:').'
  351: <select name="recentrolesn" size="1">
  352: '.$options.'
  353: </select>
  354: <p>'.&mt('This list below can be used to <q>freeze</q> '.$lc_role.'s on your screen. Those marked as frozen will not be removed from the list, even if they have not been used recently.').'
  355: </p>
  356: '.$roles_check_list.'
  357: <br />
  358: <input type="submit" value="'.&mt('Change').'" />
  359: </form>');
  360: }
  361: 
  362: sub rolespref_get_role_text {
  363: # Get a line of text for each role
  364:     my ($roles) = @_;
  365:     my %roletext = ();
  366: 
  367:     foreach my $item (@$roles) {
  368: # get course information
  369:         my ($role,$rest) = split(/\./, $item);
  370:         my $trole = "";
  371:         $trole = &Apache::lonnet::plaintext($role);
  372:         my ($tdomain,$other,$tsection)= split(/\//,Apache::lonnet::declutter($rest));
  373:         my $tother = '-';
  374:         if ($role =~ /^(cc|st|in|ta|ep|cr)/ ) {
  375:             my %newhash=&Apache::lonnet::coursedescription($tdomain."_".$other);
  376:             $tother = " - ".$newhash{'description'};
  377:         } elsif ($role =~ /dc/) {
  378:             $tother = "";
  379:         } else {
  380:             $tother = " - $other";
  381:         }
  382:  
  383:         my $section="";
  384:         if ($tsection) {
  385:             $section = " - Section/Group: $tsection";
  386:         }
  387:         $roletext{$item} = $tdomain." - ".$trole.$tother.$section;
  388:     }
  389:     return %roletext;
  390: }
  391: 
  392: sub verify_and_change_rolespref {
  393:     my $r = shift;
  394:     my $role = ($env{'user.adv'} ? 'Role' : 'Course');
  395:     my $user       = $env{'user.name'};
  396:     my $domain     = $env{'user.domain'};
  397: # Recent Roles Hotlist Flag
  398:     my $hotlist_flag  = $env{'form.recentroles'};
  399:     my $hotlist_n  = $env{'form.recentrolesn'};
  400:     my $message='<hr />';
  401:     if ($hotlist_flag) {
  402:         &Apache::lonnet::put('environment',{'recentroles' => $hotlist_flag});
  403:         &Apache::lonnet::appenv('environment.recentroles' => $hotlist_flag);
  404:         $message=&mt('Recent '.$role.'s Hotlist is Enabled');
  405:     } else {
  406:         &Apache::lonnet::del('environment',['recentroles']);
  407:         &Apache::lonnet::delenv('environment\.recentroles');
  408:         $message=&mt('Recent '.$role.'s Hotlist is Disabled');
  409:     }
  410:     if ($hotlist_n) {
  411:         &Apache::lonnet::put('environment',{'recentrolesn' => $hotlist_n});
  412:         &Apache::lonnet::appenv('environment.recentrolesn' => $hotlist_n);
  413:         if ($hotlist_flag) {
  414:             $message.="<br />".
  415: 		&mt('Display [_1] Most Recent '.$role.'s',$hotlist_n)."\n";
  416:         }
  417:     }
  418: 
  419: # Get list of froze roles and list of recent roles
  420:     my @freeze_list = &Apache::loncommon::get_env_multiple('form.freezeroles');
  421:     my %freeze = ();
  422:     my %roletext = ();
  423: 
  424:     foreach my $key (@freeze_list) {
  425:         $freeze{$key}='1';
  426:     }
  427: 
  428:     my %recent_roles =
  429:         &Apache::lonhtmlcommon::get_recent('roles',$env{'environment.recentrolesn'});
  430:     my %frozen_roles =
  431:         &Apache::lonhtmlcommon::get_recent_frozen('roles',$env{'environment.recentrolesn'});
  432:     my %role_text = &rolespref_get_role_text([keys(%recent_roles)]);
  433: 
  434: # Unset any roles that were previously frozen but aren't in list
  435:     foreach my $role_key (sort(keys(%recent_roles))) {
  436:         if (($frozen_roles{$role_key}) && (!exists($freeze{$role_key}))) {
  437: 	    $message .= "<br />".&mt('Unfreezing '.$role.': [_1]',$role_text{$role_key})."\n";
  438: 	    &Apache::lonhtmlcommon::store_recent('roles',$role_key,' ',0);
  439:         }
  440:     }
  441: 
  442: # Freeze selected roles
  443:     foreach my $role_key (@freeze_list) {
  444:         if (!$frozen_roles{$role_key}) {
  445:              $message .= "<br />".&mt('Freezing '.$role.': [_1]',$role_text{$role_key})."\n";
  446:              &Apache::lonhtmlcommon::store_recent('roles',
  447:                                           $role_key,' ',1);
  448:         }
  449:     }
  450:     $message .= "<hr /><br />\n";
  451: 
  452:     $r->print(<<ENDRPSCREEN);
  453: $message
  454: ENDRPSCREEN
  455: }
  456: 
  457: 
  458: 
  459: ################################################################
  460: #         Anonymous Discussion Name Change Subroutines         #
  461: ################################################################
  462: sub screennamechanger {
  463:     my $r = shift;
  464:     my $user       = $env{'user.name'};
  465:     my $domain     = $env{'user.domain'};
  466:     my %userenv = &Apache::lonnet::get
  467:         ('environment',['screenname','nickname']);
  468:     my $screenname=$userenv{'screenname'};
  469:     my $nickname=$userenv{'nickname'};
  470:     $r->print(<<ENDSCREEN);
  471: <form name="prefs" action="/adm/preferences" method="post">
  472: <input type="hidden" name="action" value="verify_and_change_screenname" />
  473: <br />New screenname (shown if you post anonymously):
  474: <input type="text" size="20" value="$screenname" name="screenname" />
  475: <br />New nickname (shown if you post non-anonymously):
  476: <input type="text" size="20" value="$nickname" name="nickname" />
  477: <input type="submit" value="Change" />
  478: </form>
  479: ENDSCREEN
  480: }
  481: 
  482: sub verify_and_change_screenname {
  483:     my $r = shift;
  484:     my $user       = $env{'user.name'};
  485:     my $domain     = $env{'user.domain'};
  486: # Screenname
  487:     my $newscreen  = $env{'form.screenname'};
  488:     $newscreen=~s/[^ \w]//g;
  489:     my $message='';
  490:     if ($newscreen) {
  491:         &Apache::lonnet::put('environment',{'screenname' => $newscreen});
  492:         &Apache::lonnet::appenv('environment.screenname' => $newscreen);
  493:         $message='Set new screenname to '.$newscreen;
  494:     } else {
  495:         &Apache::lonnet::del('environment',['screenname']);
  496:         &Apache::lonnet::delenv('environment\.screenname');
  497:         $message='Reset screenname';
  498:     }
  499: # Nickname
  500:     $message.='<br />';
  501:     $newscreen  = $env{'form.nickname'};
  502:     $newscreen=~s/[^ \w]//g;
  503:     if ($newscreen) {
  504:         &Apache::lonnet::put('environment',{'nickname' => $newscreen});
  505:         &Apache::lonnet::appenv('environment.nickname' => $newscreen);
  506:         $message.='Set new nickname to '.$newscreen;
  507:     } else {
  508:         &Apache::lonnet::del('environment',['nickname']);
  509:         &Apache::lonnet::delenv('environment\.nickname');
  510:         $message.='Reset nickname';
  511:     }
  512:     &Apache::lonnet::devalidate_cache_new('namescache',$user.':'.$domain);
  513:     $r->print(<<ENDVCSCREEN);
  514: $message
  515: ENDVCSCREEN
  516: }
  517: 
  518: ################################################################
  519: #                     Icon Subroutines                         #
  520: ################################################################
  521: sub iconchanger {
  522:     my $r = shift;
  523:     my $user       = $env{'user.name'};
  524:     my $domain     = $env{'user.domain'};
  525:     my %userenv = &Apache::lonnet::get
  526:         ('environment',['icons']);
  527:     my $iconic='checked="checked"';
  528:     my $classic='';
  529:     my $onlyicon='';
  530:     if ($userenv{'icons'} eq 'classic') {
  531:        $classic='checked="checked"';
  532:        $iconic='';
  533:     }
  534:     if ($userenv{'icons'} eq 'iconsonly') {
  535:        $onlyicon='checked="checked"';
  536:        $iconic='';
  537:     }
  538:     my $useicons=&mt('Use icons and text');
  539:     my $usebuttons=&mt('Use buttons and text');
  540:     my $useicononly=&mt('Use icons only');
  541:     my $change=&mt('Change');
  542:     $r->print(<<ENDSCREEN);
  543: <form name="prefs" action="/adm/preferences" method="post">
  544: <input type="hidden" name="action" value="verify_and_change_icons" />
  545: <label><input type="radio" name="menumode" value="iconic" $iconic /> $useicons</label><br />
  546: <label><input type="radio" name="menumode" value="classic" $classic /> $usebuttons</label><br />
  547: <label><input type="radio" name="menumode" value="iconsonly" $onlyicon /> $useicononly</label><br />
  548: <input type="submit" value="$change" />
  549: </form>
  550: ENDSCREEN
  551: }
  552: 
  553: sub verify_and_change_icons {
  554:     my $r = shift;
  555:     my $user       = $env{'user.name'};
  556:     my $domain     = $env{'user.domain'};
  557:     my $newicons  = $env{'form.menumode'};
  558: 
  559:     &Apache::lonnet::put('environment',{'icons' => $newicons});
  560:     &Apache::lonnet::appenv('environment.icons' => $newicons);
  561:     $r->print(&mt('Set menu mode to [_1].',$newicons));
  562: }
  563: 
  564: ################################################################
  565: #                     Clicker Subroutines                      #
  566: ################################################################
  567: 
  568: sub clickerchanger {
  569:     my $r = shift;
  570:     my $user       = $env{'user.name'};
  571:     my $domain     = $env{'user.domain'};
  572:     my %userenv = &Apache::lonnet::get
  573:         ('environment',['clickers']);
  574:     my $clickers=$userenv{'clickers'};
  575:     $clickers=~s/\,/\n/gs;
  576:     my $text=&mt('Enter response device ("clicker") numbers');
  577:     my $change=&mt('Register');
  578:     my $helplink=&Apache::loncommon::help_open_topic('Clicker_Registration', 'Locating your clicker ID');
  579:     $r->print(<<ENDSCREEN);
  580: <form name="prefs" action="/adm/preferences" method="post">
  581: <input type="hidden" name="action" value="verify_and_change_clicker" />
  582: <label>$text $helplink<br />
  583: <textarea name="clickers" rows="5" cols="20">$clickers</textarea>
  584: </label>
  585: <input type="submit" value="$change" />
  586: </form>
  587: ENDSCREEN
  588: }
  589: 
  590: sub verify_and_change_clicker {
  591:     my $r = shift;
  592:     my $user       = $env{'user.name'};
  593:     my $domain     = $env{'user.domain'};
  594:     my $newclickers  = $env{'form.clickers'};
  595:     $newclickers=~s/[^\w\:\-]+/\,/gs;
  596:     $newclickers=~tr/a-z/A-Z/;
  597:     $newclickers=~s/[\:\-]+/\-/g;
  598:     $newclickers=~s/\,+/\,/g;
  599:     $newclickers=~s/^\,//;
  600:     $newclickers=~s/\,$//;
  601:     &Apache::lonnet::put('environment',{'clickers' => $newclickers});
  602:     &Apache::lonnet::appenv('environment.clickers' => $newclickers);
  603:     $r->print(&mt('Registering clickers: [_1]',$newclickers));
  604: }
  605: 
  606: ################################################################
  607: #         Message Forward                                      #
  608: ################################################################
  609: 
  610: sub msgforwardchanger {
  611:     my ($r,$message) = @_;
  612:     my $user       = $env{'user.name'};
  613:     my $domain     = $env{'user.domain'};
  614:     my %userenv = &Apache::lonnet::get('environment',['msgforward','notification','critnotification','notifywithhtml']);
  615:     my $msgforward=$userenv{'msgforward'};
  616:     my %lt = &Apache::lonlocal::texthash(
  617:                                           all   => 'All',
  618:                                           crit  => 'Critical only',
  619:                                           reg   => 'Non-critical only',
  620:                                           foad  => 'Forwarding Address(es)',
  621:                                           mnot  => 'Message Notification Email Address(es)',
  622:                                           chg   => 'Change',
  623:                                           email => 'The e-mail address entered in row ',
  624:                                           notv => 'is not a valid e-mail address',
  625:                                           toen => "To enter multiple addresses, enter one address at a time, click 'Change' and then add the next one", 
  626:                                           prme => 'Back to preferences menu',
  627:                                         );
  628:     my $forwardingHelp = Apache::loncommon::help_open_topic("Prefs_Forwarding",
  629: 							    "What are forwarding ".
  630: 							    "and notification ".
  631: 							    "addresses");
  632:     my $criticalMessageHelp = Apache::loncommon::help_open_topic("Course_Critical_Message",
  633: 								 "What are critical messages");
  634:     my @allow_html = split(/,/,$userenv{'notifywithhtml'});
  635:     my %allnot = &get_notifications(\%userenv);
  636:     my $validatescript = &Apache::lonhtmlcommon::javascript_valid_email();
  637:     my $jscript = qq|
  638: <script type="text/javascript">
  639: function validate() {
  640:     for (var i=0; i<document.prefs.numnotify.value; i++) {
  641:         var checkaddress = 0;
  642:         var addr = document.prefs.elements['address_'+i].value;
  643:         var rownum = i+1;
  644:         if (i < document.prefs.numnotify.value-1) {
  645:             if (document.prefs.elements['modify_notify_'+i].checked) {
  646:                 checkaddress = 1;
  647:             }
  648:         } else {
  649:             if (document.prefs.elements['add_notify_'+i].checked == true) { 
  650:                 checkaddress = 1;
  651:             }
  652:         }
  653:         if (checkaddress == 1)  {
  654:             var addr = document.prefs.elements['address_'+i].value;
  655:             if (validmail(document.prefs.elements['address_'+i]) == false) {
  656:                 var multimsg = '';
  657:                 if (addr.indexOf(",") >= 0) {
  658:                     multimsg = "\\n($lt{'toen'}).";
  659:                 }
  660:                 alert("$lt{'email'} "+rownum+": '"+addr+"' $lt{'notv'}."+multimsg);
  661:                 return;
  662:             }
  663:         }
  664:     }
  665:     document.prefs.submit();
  666: }
  667: 
  668: function address_changes (adnum) {
  669:      if (!document.prefs.elements['del_notify_'+adnum].checked) { 
  670:          document.prefs.elements['modify_notify_'+adnum].checked = true;
  671:      }   
  672: }
  673: 
  674: function new_address(adnum) {
  675:      document.prefs.elements['add_notify_'+adnum].checked = true;
  676: }
  677: 
  678: function delete_address(adnum) {
  679:      if (document.prefs.elements['del_notify_'+adnum].checked) {
  680:           document.prefs.elements['modify_notify_'+adnum].checked = false;
  681:      }
  682: }
  683: 
  684: function modify_address(adnum) {
  685:     if (document.prefs.elements['modify_notify_'+adnum].checked) {
  686:         document.prefs.elements['del_notify_'+adnum].checked = false;
  687:     }
  688: } 
  689: 
  690: $validatescript
  691: </script>
  692: |;
  693:     $r->print(<<ENDMSG);
  694: $jscript
  695: $message
  696: $forwardingHelp
  697: <form name="prefs" action="/adm/preferences" method="post">
  698: <input type="hidden" name="action" value="verify_and_change_msgforward" />
  699: $lt{'foad'} (<tt>user:domain,user:domain,...</tt>):
  700: <input type="text" size="40" value="$msgforward" name="msgforward" /><hr />
  701: $criticalMessageHelp
  702: $lt{'mnot'} (<tt>joe\@doe.com</tt>):<br />
  703: ENDMSG
  704:     my @sortforwards = sort (keys(%allnot));
  705:     my $output = &Apache::loncommon::start_data_table().
  706:                  &Apache::loncommon::start_data_table_header_row().
  707:                  '<th>&nbsp;</th>'.
  708:                  '<th>'.&mt('Action').'</th>'.
  709:                  '<th>'.&mt('Notification address').'</th><th>'.
  710:                  &mt('Types of message to forward to this address').'</th><th>'.
  711:                  &mt('Excerpt retains HTML tags in message').'</th>'.
  712:                  &Apache::loncommon::end_data_table_header_row();
  713:     my $num = 0;
  714:     my $counter = 1;
  715:     foreach my $item (@sortforwards) {
  716:         $output .= &Apache::loncommon::start_data_table_row().
  717:                    '<td><b>'.$counter.'</b></td>'.
  718:                    '<td><span class="LC_nobreak"><label>'.
  719:                    '<input type="checkbox" name="modify_notify_'.
  720:                    $num.'" onclick="javscript:modify_address('."'$num'".')" />'.
  721:                    &mt('Modify').'</label></span>&nbsp;&nbsp; '.
  722:                    '<span class="LC_nobreak"><label>'.
  723:                    '<input type="checkbox" name="del_notify_'.$num.
  724:                    '" onclick="javscript:delete_address('."'$num'".')" />'.
  725:                    &mt('Delete').'</label></span></td>'.
  726:                    '<td><input type="text" value="'.$item.'" name="address_'.
  727:                    $num.'" onFocus="javascript:address_changes('."'$num'".
  728:                    ')" /></td><td>';
  729:         my %chk;
  730:         if (defined($allnot{$item}{'crit'})) {
  731:             if (defined($allnot{$item}{'reg'})) {
  732:                 $chk{'all'} = 'checked="checked" ';
  733:             } else {
  734:                 $chk{'crit'} = 'checked="checked" ';
  735:             }
  736:         } else {
  737:             $chk{'reg'} = 'checked="checked" ';
  738:         }
  739:         foreach my $type ('all','crit','reg') {
  740:             $output .= '<span class="LC_nobreak"><label>'.
  741:                        '<input type="radio" name="notify_type_'.$num. 
  742:                        '" value="'.$type.'" '.$chk{$type}.
  743:                        ' onchange="javascript:address_changes('."'$num'".')" />'.
  744:                        $lt{$type}.'</label></span>&nbsp;';
  745:         }
  746:         my $htmlon = '';
  747:         my $htmloff = '';
  748:         if (grep/^\Q$item\E/,@allow_html) {
  749:             $htmlon = 'checked="checked" '; 
  750:         } else {
  751:             $htmloff = 'checked="checked" ';
  752:         }
  753:         $output .= '</td><td><label><input type="radio" name="html_'.$num.
  754:                    '" value="1" '.$htmlon.
  755:                    ' onchange="javascript:address_changes('."'$num'".')" />'.
  756:                    &mt('Yes').'</label>&nbsp;'.
  757:                    '<label><input type="radio" name="html_'.$num.'" value="0" '.
  758:                    $htmloff. ' onchange="javascript:address_changes('."'$num'".
  759: ')" />'.
  760:                    &mt('No').'</label></td>'.
  761:                    &Apache::loncommon::end_data_table_row();
  762:         $num ++;
  763:         $counter ++;
  764:     }
  765:     my %defchk = (
  766:                    all => 'checked="checked" ',
  767:                    crit => '',
  768:                    reg => '',
  769:                  );
  770:     $output .= &Apache::loncommon::start_data_table_row().
  771:                '<td><b>'.$counter.'</b></td>'.
  772:                '<td><span class="LC_nobreak"><label>'.
  773:                '<input type="checkbox" name="add_notify_'.$num.
  774:                '" value="1" />'.&mt('Add new address').'</label></span></td>'.
  775:                '<td><input type="text" value="" name="address_'.$num.
  776:                '" onFocus="javascript:new_address('."'$num'".')" /></td><td>';
  777:     foreach my $type ('all','crit','reg') {
  778:         $output .= '<span class="LC_nobreak"><label>'.
  779:                    '<input type="radio" name="notify_type_'.$num.
  780:                    '" value="'.$type.'" '.$defchk{$type}.'/>'.
  781:                    $lt{$type}.'</label></span>&nbsp;';
  782:     }
  783:     $output .= '</td><td><label><input type="radio" name="html_'.$num.
  784:                '" value="1" />'.&mt('Yes').'</label>&nbsp;'.
  785:                '<label><input type="radio" name="html_'.$num.'" value="0" '.
  786:                ' checked="checked" />'.
  787:                &mt('No').'</label></td>'.
  788:                &Apache::loncommon::end_data_table_row().
  789:                &Apache::loncommon::end_data_table();
  790:     $num ++;
  791:     $r->print($output);
  792:     $r->print(qq|
  793: <hr />
  794: <input type="hidden" name="numnotify" value="$num" />
  795: <input type="button" value="$lt{'chg'}" onclick="javascript:validate()" />
  796: <input type="button" value="$lt{'prme'}" onclick="location.href='/adm/preferences'" />
  797: </form>
  798: |);
  799: 
  800: }
  801: 
  802: sub get_notifications {
  803:     my ($userenv) = @_;
  804:     my %allnot;
  805:     my @critnot = split(/,/,$userenv->{'critnotification'});
  806:     my @regnot = split(/,/,$userenv->{'notification'});
  807:     foreach my $item (@critnot) {
  808:         $allnot{$item}{crit} = 1;
  809:     }
  810:     foreach my $item (@regnot) {
  811:         $allnot{$item}{reg} = 1;
  812:     }
  813:     return %allnot;
  814: }
  815: 
  816: sub verify_and_change_msgforward {
  817:     my $r = shift;
  818:     my $user       = $env{'user.name'};
  819:     my $domain     = $env{'user.domain'};
  820:     my $newscreen  = '';
  821:     my $message='';
  822:     foreach (split(/\,/,$env{'form.msgforward'})) {
  823: 	my ($msuser,$msdomain)=split(/[\@\:]/,$_);
  824:         $msuser = &LONCAPA::clean_username($msuser);
  825:         $msdomain = &LONCAPA::clean_domain($msdomain);
  826:         if (($msuser) && ($msdomain)) {
  827: 	    if (&Apache::lonnet::homeserver($msuser,$msdomain) ne 'no_host') {
  828:                $newscreen.=$msuser.':'.$msdomain.',';
  829: 	   } else {
  830:                $message.= &mt('No such user: ').$msuser.':'.$msdomain.'<br>';
  831:            }
  832:         }
  833:     }
  834:     $newscreen=~s/\,$//;
  835:     if ($newscreen) {
  836:         &Apache::lonnet::put('environment',{'msgforward' => $newscreen});
  837:         &Apache::lonnet::appenv('environment.msgforward' => $newscreen);
  838:         $message .= &mt('Set message forwarding to: ').'<tt>'.$newscreen.
  839:                     '</tt><br />';
  840:     } else {
  841:         &Apache::lonnet::del('environment',['msgforward']);
  842:         &Apache::lonnet::delenv('environment\.msgforward');
  843:         $message.= &mt("Set message forwarding to 'off'.").'<br />';
  844:     }
  845:     my $critnotification;
  846:     my $notification;
  847:     my $notify_with_html;
  848:     my $lastnotify = $env{'form.numnotify'}-1;
  849:     my $totaladdresses = 0;
  850:     for (my $i=0; $i<$env{'form.numnotify'}; $i++) {
  851:         if ((!defined($env{'form.del_notify_'.$i})) &&  
  852:            ((($i==$lastnotify) && ($env{'form.add_notify_'.$lastnotify} == 1)) ||
  853:             ($i<$lastnotify))) {
  854:             if (defined($env{'form.address_'.$i})) {
  855:                 if ($env{'form.notify_type_'.$i} eq 'all') {
  856:                     $critnotification .= $env{'form.address_'.$i}.',';
  857:                     $notification .= $env{'form.address_'.$i}.',';
  858:                 } elsif ($env{'form.notify_type_'.$i} eq 'crit') {
  859:                     $critnotification .= $env{'form.address_'.$i}.',';
  860:                 } elsif ($env{'form.notify_type_'.$i} eq 'reg') {
  861:                     $notification .= $env{'form.address_'.$i}.','; 
  862:                 }
  863:                 if ($env{'form.html_'.$i} eq '1') {
  864: 		    $notify_with_html .= $env{'form.address_'.$i}.',';       	
  865:                 }
  866:                 $totaladdresses ++;
  867:             }
  868:         }
  869:     }
  870:     $critnotification =~ s/,$//;
  871:     $critnotification=~s/\s//gs;
  872:     $notification =~ s/,$//;
  873:     $notification=~s/\s//gs;
  874:     $notify_with_html =~ s/,$//;
  875:     $notify_with_html =~ s/\s//gs;
  876:     if ($notification) {
  877:         &Apache::lonnet::put('environment',{'notification' => $notification});
  878:         &Apache::lonnet::appenv('environment.notification' => $notification);
  879:         $message.=&mt('Set non-critical message notification address(es) to: ').'<tt>'.$notification.'</tt><br />';
  880:     } else {
  881:         &Apache::lonnet::del('environment',['notification']);
  882:         &Apache::lonnet::delenv('environment\.notification');
  883:         $message.=&mt("Non-critical message notification set to 'off'.").'<br />';
  884:     }
  885:     if ($critnotification) {
  886:         &Apache::lonnet::put('environment',{'critnotification' => $critnotification});
  887:         &Apache::lonnet::appenv('environment.critnotification' => $critnotification);
  888:         $message.=&mt('Set critical message notification address(es) to: ').'<tt>'.$critnotification.'</tt><br />';
  889:     } else {
  890:         &Apache::lonnet::del('environment',['critnotification']);
  891:         &Apache::lonnet::delenv('environment\.critnotification');
  892:         $message.=&mt("Critical message notification set to 'off'.").'<br />';
  893:     }
  894:     if ($critnotification || $notification) {
  895:         if ($notify_with_html) {
  896:             &Apache::lonnet::put('environment',{'notifywithhtml' => $notify_with_html});
  897:             &Apache::lonnet::appenv('environment.notifywithhtml' => $notify_with_html);
  898:             $message.=&mt('Set address(es) to receive excerpts with html retained: ').'<tt>'.$notify_with_html.'</tt>';
  899:         } else {
  900:             &Apache::lonnet::del('environment',['notifywithhtml']);
  901:             &Apache::lonnet::delenv('environment\.notifywithhtml');
  902:             if ($totaladdresses == 1) {
  903:                 $message.=&mt("Set notification address to receive excerpts with html stripped.");
  904:             } else {
  905:                 $message.=&mt("Set all notification addresses to receive excerpts with html stripped.");
  906:             }
  907:         }
  908:     } else {
  909:         &Apache::lonnet::del('environment',['notifywithhtml']);
  910:         &Apache::lonnet::delenv('environment\.notifywithhtml');
  911:     }
  912:     if ($message) {
  913:         $message .= '<br /><hr />';
  914:     }
  915:     &Apache::loncommon::flush_email_cache($user,$domain);
  916:     &msgforwardchanger($r,$message);
  917: }
  918: 
  919: ################################################################
  920: #         Colors                                               #
  921: ################################################################
  922: 
  923: sub colorschanger {
  924:     my $r = shift;
  925: # figure out colors
  926:     my $function=&Apache::loncommon::get_users_function();
  927:     my $domain=&Apache::loncommon::determinedomain();
  928:     my %colortypes=('pgbg'  => 'Page Background',
  929:                     'tabbg' => 'Header Background',
  930:                     'sidebg'=> 'Header Border',
  931:                     'font'  => 'Font',
  932:                     'link'  => 'Un-Visited Link',
  933:                     'vlink' => 'Visited Link',
  934:                     'alink' => 'Active Link');
  935:     my $start_data_table = &Apache::loncommon::start_data_table();
  936:     my $chtable='';
  937:     foreach my $item (sort(keys(%colortypes))) {
  938:        my $curcol=&Apache::loncommon::designparm($function.'.'.$item,$domain);
  939:        $chtable.=&Apache::loncommon::start_data_table_row().
  940: 	   '<td>'.$colortypes{$item}.'</td><td style="background: '.$curcol.
  941:         '">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</td><td><input name="'.$item.
  942:         '" size="10" value="'.$curcol.
  943: '" /></td><td><a href="javascript:pjump('."'color_custom','".$colortypes{$item}.
  944: "','".$curcol."','"
  945: 	    .$item."','parmform.pres','psub'".');">Select</a></td>'.
  946: 	    &Apache::loncommon::end_data_table_row()."\n";
  947:     }
  948:     my $end_data_table = &Apache::loncommon::end_data_table();
  949:     my $pjump_def = &Apache::lonhtmlcommon::pjump_javascript_definition();
  950:     $r->print(<<ENDCOL);
  951: <script type="text/javascript">
  952: 
  953:     function pclose() {
  954:         parmwin=window.open("/adm/rat/empty.html","LONCAPAparms",
  955:                  "height=350,width=350,scrollbars=no,menubar=no");
  956:         parmwin.close();
  957:     }
  958: 
  959:     $pjump_def
  960: 
  961:     function psub() {
  962:         pclose();
  963:         if (document.parmform.pres_marker.value!='') {
  964:             if (document.parmform.pres_type.value!='') {
  965:                 eval('document.prefs.'+
  966:                      document.parmform.pres_marker.value+
  967: 		     '.value=document.parmform.pres_value.value;');
  968: 	    }
  969:         } else {
  970:             document.parmform.pres_value.value='';
  971:             document.parmform.pres_marker.value='';
  972:         }
  973:     }
  974: 
  975: 
  976: </script>
  977: <form name="parmform">
  978: <input type="hidden" name="pres_marker" />
  979: <input type="hidden" name="pres_type" />
  980: <input type="hidden" name="pres_value" />
  981: </form>
  982: <form name="prefs" action="/adm/preferences" method="post">
  983: <input type="hidden" name="action" value="verify_and_change_colors" />
  984: $start_data_table
  985: $chtable
  986: $end_data_table
  987: </table>
  988: <input type="submit" value="Change Custom Colors" />
  989: <input type="submit" name="resetall" value="Reset All Colors to Default" />
  990: </form>
  991: ENDCOL
  992: }
  993: 
  994: sub verify_and_change_colors {
  995:     my $r = shift;
  996: # figure out colors
  997:     my $function=&Apache::loncommon::get_users_function();
  998:     my $domain=&Apache::loncommon::determinedomain();
  999:     my %colortypes=('pgbg'  => 'Page Background',
 1000:                     'tabbg' => 'Header Background',
 1001:                     'sidebg'=> 'Header Border',
 1002:                     'font'  => 'Font',
 1003:                     'link'  => 'Un-Visited Link',
 1004:                     'vlink' => 'Visited Link',
 1005:                     'alink' => 'Active Link');
 1006: 
 1007:     my $message='';
 1008:     foreach my $item (keys %colortypes) {
 1009:         my $color=$env{'form.'.$item};
 1010:         my $entry='color.'.$function.'.'.$item;
 1011: 	if (($color=~/^\#[0-9A-Fa-f]{6}$/) && (!$env{'form.resetall'})) {
 1012: 	    &Apache::lonnet::put('environment',{$entry => $color});
 1013: 	    &Apache::lonnet::appenv('environment.'.$entry => $color);
 1014: 	    $message.='Set '.$colortypes{$item}.' to '.$color.'<br />';
 1015: 	} else {
 1016: 	    &Apache::lonnet::del('environment',[$entry]);
 1017: 	    &Apache::lonnet::delenv('environment\.'.$entry);
 1018: 	    $message.='Reset '.$colortypes{$item}.'<br />';
 1019: 	}
 1020:     }
 1021:     my $now = time;
 1022:     &Apache::lonnet::put('environment',{'color.timestamp' => $now});
 1023:     &Apache::lonnet::appenv('environment.color.timestamp' => $now);
 1024: 
 1025:     $r->print(<<ENDVCCOL);
 1026: $message
 1027: <form name="client" action="/adm/preferences" method="post">
 1028: <input type="hidden" name="action" value="changecolors" />
 1029: </form>
 1030: ENDVCCOL
 1031: }
 1032: 
 1033: ######################################################
 1034: #            password handler subroutines            #
 1035: ######################################################
 1036: sub passwordchanger {
 1037:     my ($r,$errormessage,$caller,$mailtoken) = @_;
 1038:     # This function is a bit of a mess....
 1039:     # Passwords are encrypted using londes.js (DES encryption)
 1040:     $errormessage = ($errormessage || '');
 1041:     my ($user,$domain,$currentpass,$defdom);
 1042:     if ((!defined($caller)) || ($caller eq 'preferences')) {
 1043:         $user = $env{'user.name'};
 1044:         $domain = $env{'user.domain'};
 1045:         if (!defined($caller)) {
 1046:             $caller = 'preferences';
 1047:         }
 1048:     } elsif ($caller eq 'reset_by_email') {
 1049:             $defdom = $r->dir_config('lonDefDomain');
 1050:             my %data = &Apache::lonnet::tmpget($mailtoken);
 1051:             if (keys(%data) == 0) {
 1052:                 $r->print(&mt('Sorry, the URL you provided to complete the reset of your password was invalid.  Either the token included in the URL has been deleted or the URL you provided was invalid. Please submit a <a href="/adm/resetpw">new request</a> for a password reset, and follow the link to the new URL included in the e-mail that will be sent to you, to allow you to enter a new password.'));
 1053:                 return;
 1054:             }
 1055:             if (defined($data{time})) {
 1056:                 if (time - $data{'time'} < 7200) {
 1057:                     $user = $data{'username'};
 1058:                     $domain = $data{'domain'};
 1059:                     $currentpass = $data{'temppasswd'};
 1060:                 } else {
 1061:                     $r->print(&mt('Sorry, the token generated when you requested a password reset has expired.').'<br />');
 1062:                     return;
 1063:                 }
 1064:             } else {
 1065:                 $r->print(&mt('Sorry, the URL generated when you requested reset of your password contained incomplete information.').'<br />');
 1066:                 return;
 1067:             }
 1068:    } else {
 1069:         $r->print(&mt('Page requested in unexpected context').'<br />');
 1070:         return;
 1071:     }
 1072:     my $currentauth=&Apache::lonnet::queryauthenticate($user,$domain);
 1073:     # Check for authentication types that allow changing of the password.
 1074:     return if ($currentauth !~ /^(unix|internal):/);
 1075:     #
 1076:     # Generate keys
 1077:     my ($lkey_cpass ,$ukey_cpass ) = &des_keys();
 1078:     my ($lkey_npass1,$ukey_npass1) = &des_keys();
 1079:     my ($lkey_npass2,$ukey_npass2) = &des_keys();
 1080:     # Store the keys in the log files
 1081:     my $lonhost = $r->dir_config('lonHostID');
 1082:     my $logtoken=Apache::lonnet::reply('tmpput:'
 1083: 				       .$ukey_cpass  . $lkey_cpass .'&'
 1084: 				       .$ukey_npass1 . $lkey_npass1.'&'
 1085: 				       .$ukey_npass2 . $lkey_npass2,
 1086: 				       $lonhost);
 1087:     # Hexify the keys for output as javascript variables
 1088:     my %hexkey;
 1089:     $hexkey{'ukey_cpass'}  = hex($ukey_cpass);
 1090:     $hexkey{'lkey_cpass'}  = hex($lkey_cpass);
 1091:     $hexkey{'ukey_npass1'} = hex($ukey_npass1);
 1092:     $hexkey{'lkey_npass1'} = hex($lkey_npass1);
 1093:     $hexkey{'ukey_npass2'} = hex($ukey_npass2);
 1094:     $hexkey{'lkey_npass2'} = hex($lkey_npass2);
 1095:     # Output javascript to deal with passwords
 1096:     # Output DES javascript
 1097:     {
 1098: 	my $include = $r->dir_config('lonIncludes');
 1099: 	my $jsh=Apache::File->new($include."/londes.js");
 1100: 	$r->print(<$jsh>);
 1101:     }
 1102:     $r->print(&jscript_send($caller));
 1103:     $r->print(<<ENDFORM);
 1104: $errormessage
 1105: 
 1106: <p>
 1107: <!-- We separate the forms into 'server' and 'client' in order to
 1108:      ensure that unencrypted passwords will not be sent out by a
 1109:      crappy browser -->
 1110: ENDFORM
 1111:     $r->print(&server_form($logtoken,$caller,$mailtoken));
 1112:     $r->print(&client_form($caller,\%hexkey,$currentpass,$defdom));
 1113: 
 1114:     #
 1115:     return;
 1116: }
 1117: 
 1118: sub jscript_send {
 1119:     my ($caller) = @_;
 1120:     my $output = qq|
 1121: <script language="JavaScript">
 1122: 
 1123:     function send() {
 1124:         uextkey=this.document.client.elements.ukey_cpass.value;
 1125:         lextkey=this.document.client.elements.lkey_cpass.value;
 1126:         initkeys();
 1127: 
 1128:         this.document.pserver.elements.currentpass.value
 1129:             =crypted(this.document.client.elements.currentpass.value);
 1130: 
 1131:         uextkey=this.document.client.elements.ukey_npass1.value;
 1132:         lextkey=this.document.client.elements.lkey_npass1.value;
 1133:         initkeys();
 1134:         this.document.pserver.elements.newpass_1.value
 1135:             =crypted(this.document.client.elements.newpass_1.value);
 1136: 
 1137:         uextkey=this.document.client.elements.ukey_npass2.value;
 1138:         lextkey=this.document.client.elements.lkey_npass2.value;
 1139:         initkeys();
 1140:         this.document.pserver.elements.newpass_2.value
 1141:             =crypted(this.document.client.elements.newpass_2.value);
 1142: |;
 1143:     if ($caller eq 'reset_by_email') {
 1144:         $output .= qq|
 1145:         this.document.pserver.elements.uname.value =
 1146:                    this.document.client.elements.uname.value;
 1147:         this.document.pserver.elements.udom.value =
 1148:                    this.document.client.elements.udom.options[this.document.client.elements.udom.selectedIndex].value;
 1149: |;
 1150:     }
 1151:     $ output .= qq|
 1152:         this.document.pserver.submit();
 1153:     }
 1154: </script>
 1155: |;
 1156: }
 1157: 
 1158: sub client_form {
 1159:     my ($caller,$hexkey,$currentpass,$defdom) = @_;
 1160:     my %lt=&Apache::lonlocal::texthash(
 1161:                 'email' => 'EMail Address',
 1162:                 'username' => 'Username',
 1163:                 'domain' => 'Domain',
 1164:                 'currentpass' => 'Current Password',
 1165:                 'newpass' => 'New Password',
 1166:                 'confirmpass' => 'Confirm Password',
 1167:                 'changepass' => 'Change Password');
 1168: 
 1169:     my $output = qq|
 1170: <form name="client" >
 1171: <table>
 1172: |;
 1173:     if ($caller eq 'reset_by_email') {
 1174:         $output .= qq|
 1175: <tr><td class="LC_preferences_labeltext"><label for="email">$lt{'email'}</label>:</td>
 1176:     <td><input type="text" name="email" size="30" /> </td></tr>
 1177: <tr><td class="LC_preferences_labeltext"><label for="uname">$lt{'username'}</label>:</td>
 1178:     <td>
 1179:      <input type="text" name="uname" size="15" />
 1180:      <input type="hidden" name="currentpass" value="$currentpass" />
 1181:     </td></tr>
 1182: <tr><td class="LC_preferences_labeltext"><label for="udom">$lt{'udom'}</label>:</td>
 1183:     <td>
 1184: |;
 1185:         $output .= &Apache::loncommon::select_dom_form($defdom,'udom').'
 1186:    </td>
 1187: </tr>
 1188: ';
 1189:     } else {
 1190:         $output .= qq|
 1191: <tr><td class="LC_preferences_labeltext"><label for="currentpass">$lt{'currentpass'}</label></td>
 1192:     <td><input type="password" name="currentpass" size="10"/> </td></tr>
 1193: |;
 1194:     }
 1195:     $output .= <<"ENDFORM";
 1196: <tr><td class="LC_preferences_labeltext"><label for="newpass_1">$lt{'newpass'}</label></td>
 1197:     <td><input type="password" name="newpass_1" size="10"  /> </td></tr>
 1198: <tr><td class="LC_preferences_labeltext"><label for="newpass_2">$lt{'confirmpass'}</label></td>
 1199:     <td><input type="password" name="newpass_2" size="10"  /> </td></tr>
 1200: <tr><td colspan="2" align="center">
 1201:     <input type="button" value="$lt{'changepass'}" onClick="send();">
 1202: </table>
 1203: <input type="hidden" name="ukey_cpass"  value="$hexkey->{'ukey_cpass'}" />
 1204: <input type="hidden" name="lkey_cpass"  value="$hexkey->{'lkey_cpass'}" />
 1205: <input type="hidden" name="ukey_npass1" value="$hexkey->{'ukey_npass1'}" />
 1206: <input type="hidden" name="lkey_npass1" value="$hexkey->{'lkey_npass1'}" />
 1207: <input type="hidden" name="ukey_npass2" value="$hexkey->{'ukey_npass2'}" />
 1208: <input type="hidden" name="lkey_npass2" value="$hexkey->{'lkey_npass2'}" />
 1209: </form>
 1210: </p>
 1211: ENDFORM
 1212:     return $output;
 1213: }
 1214: 
 1215: sub server_form {
 1216:     my ($logtoken,$caller,$mailtoken) = @_;
 1217:     my $action = '/adm/preferences';
 1218:     if ($caller eq 'reset_by_email') {
 1219:         $action = '/adm/resetpw';
 1220:     }
 1221:     my $output = qq|
 1222: <form name="pserver" action="$action" method="post">
 1223: <input type="hidden" name="logtoken"    value="$logtoken" />
 1224: <input type="hidden" name="currentpass" value="" />
 1225: <input type="hidden" name="newpass_1"   value="" />
 1226: <input type="hidden" name="newpass_2"   value="" />
 1227:     |;
 1228:     if ($caller eq 'reset_by_email') {
 1229:         $output .=  qq|
 1230: <input type="hidden" name="token"   value="$mailtoken" />
 1231: <input type="hidden" name="uname"   value="" />
 1232: <input type="hidden" name="udom"   value="" />
 1233: 
 1234: |;
 1235:     }
 1236:     $output .= qq|
 1237: <input type="hidden" name="action" value="verify_and_change_pass" />
 1238: </form>
 1239: |;
 1240:     return $output;
 1241: }
 1242: 
 1243: sub verify_and_change_password {
 1244:     my ($r,$caller,$mailtoken) = @_;
 1245:     my ($user,$domain,$homeserver);
 1246:     if ($caller eq 'reset_by_email') {
 1247:         $user       = $env{'form.uname'};
 1248:         $domain     = $env{'form.udom'};
 1249:         if ($user ne '' && $domain ne '') {
 1250:             $homeserver = &Apache::lonnet::homeserver($user,$domain);
 1251:             if ($homeserver eq 'no_host') {
 1252:         &passwordchanger($r,"<p>\n<span class='LC_error'>".
 1253:                          &mt("Invalid username and/or domain")."</span>\n</p>",
 1254:                          $caller,$mailtoken);
 1255:                 return 1;
 1256:             }
 1257:         } else {
 1258:             &passwordchanger($r,"<p>\n<span class='LC_error'>".
 1259:                              &mt("Username and domain were blank")."</span>\n</p>",
 1260:                              $caller,$mailtoken);
 1261:             return 1;
 1262:         }
 1263:     } else {
 1264:         $user       = $env{'user.name'};
 1265:         $domain     = $env{'user.domain'};
 1266:         $homeserver = $env{'user.home'};
 1267:     }
 1268:     my $currentauth=&Apache::lonnet::queryauthenticate($user,$domain);
 1269:     # Check for authentication types that allow changing of the password.
 1270:     if ($currentauth !~ /^(unix|internal):/) {
 1271:         if ($caller eq 'reset_by_email') {
 1272:             &passwordchanger($r,"<p>\n<span class='LC_error'>".
 1273:                              &mt("Authentication type for this user can not be changed by this mechanism").
 1274:                              "</span>\n</p>",
 1275:                               $caller,$mailtoken);
 1276:             return 1;
 1277:         } else {
 1278:             return;
 1279:         }
 1280:     }
 1281:     #
 1282:     my $currentpass = $env{'form.currentpass'}; 
 1283:     my $newpass1    = $env{'form.newpass_1'}; 
 1284:     my $newpass2    = $env{'form.newpass_2'};
 1285:     my $logtoken    = $env{'form.logtoken'};
 1286:     # Check for empty data 
 1287:     unless (defined($currentpass) && 
 1288: 	    defined($newpass1)    && 
 1289: 	    defined($newpass2)    ){
 1290: 	&passwordchanger($r,"<p>\n<span class='LC_error'>".
 1291: 			 &mt("One or more password fields were blank").
 1292:                          "</span>\n</p>",$caller,$mailtoken);
 1293: 	return;
 1294:     }
 1295:     # Get the keys
 1296:     my $lonhost = $r->dir_config('lonHostID');
 1297:     my $tmpinfo = Apache::lonnet::reply('tmpget:'.$logtoken,$lonhost);
 1298:     if (($tmpinfo=~/^error/) || ($tmpinfo eq 'con_lost')) {
 1299:         # I do not a have a better idea about how to handle this
 1300:         my $tryagain_text = &mt('Please log out and try again.');
 1301:         if ($caller eq 'reset_by_email') {
 1302:             $tryagain_text = &mt('Please try again later.');
 1303:         }
 1304:         my $unable=&mt("Unable to retrieve saved token for password decryption");
 1305: 	$r->print(<<ENDERROR);
 1306: <p>
 1307: <span class="LC_error">$unable.  $tryagain_text</span>
 1308: </p>
 1309: ENDERROR
 1310:         # Probably should log an error here
 1311:         return 1;
 1312:     }
 1313:     my ($ckey,$n1key,$n2key)=split(/&/,$tmpinfo);
 1314:     # 
 1315:     $currentpass = &des_decrypt($ckey ,$currentpass);
 1316:     $newpass1    = &des_decrypt($n1key,$newpass1);
 1317:     $newpass2    = &des_decrypt($n2key,$newpass2);
 1318:     #
 1319:     if ($caller eq 'reset_by_email') {
 1320:         my %data = &Apache::lonnet::tmpget($mailtoken);
 1321:         if ($currentpass ne $data{'temppasswd'}) {
 1322:             &passwordchanger($r,
 1323:                          '<span class="LC_error">'.
 1324:                          &mt('Could not verify current authentication').'.  '.
 1325:                          &mt('Please try again').'.</span>',$caller,$mailtoken);
 1326:             return 1;
 1327:         }
 1328:     } 
 1329:     if ($newpass1 ne $newpass2) {
 1330: 	&passwordchanger($r,
 1331: 			 '<span class="LC_error">'.
 1332: 			 &mt('The new passwords you entered do not match').'.  '.
 1333: 			 &mt('Please try again').'.</span>',$caller,$mailtoken);
 1334: 	return 1;
 1335:     }
 1336:     if (length($newpass1) < 7) {
 1337: 	&passwordchanger($r,
 1338: 			 '<span class="LC_error">'.
 1339: 			 &mt('Passwords must be a minimum of 7 characters long').'.  '.
 1340: 			 &mt('Please try again').'</span>.',$caller,$mailtoken);
 1341: 	return 1;
 1342:     }
 1343:     #
 1344:     # Check for bad characters
 1345:     my $badpassword = 0;
 1346:     foreach (split(//,$newpass1)) {
 1347: 	$badpassword = 1 if ((ord($_)<32)||(ord($_)>126));
 1348:     }
 1349:     if ($badpassword) {
 1350: 	# I can't figure out how to enter bad characters on my browser.
 1351: 	my $errormessage ='<span class="LC_error">'.
 1352:            &mt('The password you entered contained illegal characters').'.<br />'.
 1353:            &mt('Valid characters are').(<<"ENDERROR");
 1354: : space and <br />
 1355: <pre>
 1356: !&quot;\#$%&amp;\'()*+,-./0123456789:;&lt;=&gt;?\@
 1357: ABCDEFGHIJKLMNOPQRSTUVWXYZ[\]^_\`abcdefghijklmnopqrstuvwxyz{|}~
 1358: </pre></span>
 1359: ENDERROR
 1360:         &passwordchanger($r,$errormessage,$caller,$mailtoken);
 1361:         return 1;
 1362:     }
 1363:     # 
 1364:     # Change the password (finally)
 1365:     my $result = &Apache::lonnet::changepass
 1366: 	($user,$domain,$currentpass,$newpass1,$homeserver,$caller);
 1367:     # Inform the user the password has (not?) been changed
 1368:     if ($result =~ /^ok$/) {
 1369: 	$r->print("<h3>".&mt('The password for [_1] was successfully changed',$user)."</h3>");
 1370:     } else {
 1371: 	# error error: run in circles, scream and shout
 1372:         $r->print("<h3><span class='LC_error'>".&mt("The password for [_1] was not changed",$user)."</span></h3>".
 1373:                   &mt('Please make sure your old password was entered correctly').'.');
 1374:         return 1;
 1375:     }
 1376:     return;
 1377: }
 1378: 
 1379: ################################################################
 1380: #            discussion display subroutines 
 1381: ################################################################
 1382: sub discussionchanger {
 1383:     my $r = shift;
 1384:     my $user       = $env{'user.name'};
 1385:     my $domain     = $env{'user.domain'};
 1386:     my %userenv = &Apache::lonnet::get
 1387:         ('environment',['discdisplay','discmarkread']);
 1388:     my $discdisp = 'allposts';
 1389:     my $discmark = 'onmark';
 1390: 
 1391:     if (defined($userenv{'discdisplay'})) {
 1392:         unless ($userenv{'discdisplay'} eq '') { 
 1393:             $discdisp = $userenv{'discdisplay'};
 1394:         }
 1395:     }
 1396:     if (defined($userenv{'discmarkread'})) {
 1397:         unless ($userenv{'discdisplay'} eq '') { 
 1398:             $discmark = $userenv{'discmarkread'};
 1399:         }
 1400:     }
 1401: 
 1402:     my $newdisp = 'unread';
 1403:     my $newmark = 'ondisp';
 1404: 
 1405:     my $function = &Apache::loncommon::get_users_function();
 1406:     my $color = &Apache::loncommon::designparm($function.'.tabbg',
 1407:                                                     $env{'user.domain'});
 1408:     my %lt = &Apache::lonlocal::texthash(
 1409:         'pref' => 'Display Preference',
 1410:         'curr' => 'Current setting ',
 1411:         'actn' => 'Action',
 1412:         'sdpf' => 'Set display preferences for discussion posts for both bulletin boards and individual resources in all your courses.',
 1413:         'prca' => 'Preferences can be set that determine',
 1414:         'whpo' => 'Which posts are displayed when you display a bulletin board or resource, and',
 1415:         'unwh' => 'Under what circumstances posts are identfied as "New"',
 1416:         'allposts' => 'All posts',
 1417:         'unread' => 'New posts only',
 1418:         'ondisp' => 'Once displayed',
 1419:         'onmark' => 'Once marked as read',
 1420:         'disa' => 'Posts displayed?',
 1421:         'npmr' => 'New posts cease to be identified as "New"?',
 1422:         'thde'  => 'The preferences you set here can be overridden within each individual discussion.',
 1423:         'chgt' => 'Change to '
 1424:     );
 1425:     my $dispchange = $lt{'unread'};
 1426:     my $markchange = $lt{'ondisp'};
 1427:     my $currdisp = $lt{'allposts'};
 1428:     my $currmark = $lt{'onmark'};
 1429: 
 1430:     if ($discdisp eq 'unread') {
 1431:         $dispchange = $lt{'allposts'};
 1432:         $currdisp = $lt{'unread'};
 1433:         $newdisp = 'allposts';
 1434:     }
 1435: 
 1436:     if ($discmark eq 'ondisp') {
 1437:         $markchange = $lt{'onmark'};
 1438:         $currmark = $lt{'ondisp'};
 1439:         $newmark = 'onmark';
 1440:     }
 1441:     
 1442:     $r->print(<<"END");
 1443: <form name="prefs" action="/adm/preferences" method="post">
 1444: <input type="hidden" name="action" value="verify_and_change_discussion" />
 1445: <br />
 1446: $lt{'sdpf'}<br /> $lt{'prca'}  <ol><li>$lt{'whpo'}</li><li>$lt{'unwh'}</li></ol> 
 1447: <br />
 1448: <br />
 1449: END
 1450:     $r->print(&Apache::loncommon::start_data_table());
 1451:     $r->print(<<"END");
 1452:        <tr>
 1453:         <th>$lt{'pref'}</th>
 1454:         <th>$lt{'curr'}</th>
 1455:         <th>$lt{'actn'}?</th>
 1456:        </tr>
 1457: END
 1458:     $r->print(&Apache::loncommon::start_data_table_row());
 1459:     $r->print(<<"END");
 1460:        <td>$lt{'disa'}</td>
 1461:        <td>$lt{$discdisp}</td>
 1462:        <td><label><input type="checkbox" name="discdisp" /><input type="hidden" name="newdisp" value="$newdisp" />&nbsp;$lt{'chgt'} "$dispchange"</label></td>
 1463: END
 1464:     $r->print(&Apache::loncommon::end_data_table_row().
 1465: 	      &Apache::loncommon::start_data_table_row());
 1466:     $r->print(<<"END");
 1467:        <td>$lt{'npmr'}</td>
 1468:        <td>$lt{$discmark}</td>
 1469:        <td><label><input type="checkbox" name="discmark" /><input type="hidden" name="newmark" value="$newmark" />&nbsp;$lt{'chgt'} "$markchange"</label></td>
 1470:       </tr>
 1471: END
 1472:     $r->print(&Apache::loncommon::end_data_table_row().
 1473: 	      &Apache::loncommon::end_data_table());
 1474:     $r->print(<<"END");
 1475: <br />
 1476: <br />
 1477: <input type="submit" name="sub" value="Save Changes" />
 1478: <br />
 1479: <br />
 1480: Note: $lt{'thde'}
 1481: </form>
 1482: END
 1483: }
 1484:                                                                                                                 
 1485: sub verify_and_change_discussion {
 1486:     my $r = shift;
 1487:     my $user     = $env{'user.name'};
 1488:     my $domain   = $env{'user.domain'};
 1489:     my $message='';
 1490:     if (defined($env{'form.discdisp'}) ) {
 1491:         my $newdisp  = $env{'form.newdisp'};
 1492:         if ($newdisp eq 'unread') {
 1493:             $message .='In discussions: only new posts will be displayed.<br />';
 1494:             &Apache::lonnet::put('environment',{'discdisplay' => $newdisp});
 1495:             &Apache::lonnet::appenv('environment.discdisplay' => $newdisp);
 1496:         } else {
 1497:             $message .= 'In discussions: all posts will be displayed.<br />';
 1498:             &Apache::lonnet::del('environment',['discdisplay']);
 1499:             &Apache::lonnet::delenv('environment\.discdisplay');
 1500:         }
 1501:     }
 1502:     if (defined($env{'form.discmark'}) ) {
 1503:         my $newmark = $env{'form.newmark'};
 1504:         if ($newmark eq 'ondisp') {
 1505:            $message.='In discussions: new posts will be cease to be identified as "new" after display.<br />';
 1506:             &Apache::lonnet::put('environment',{'discmarkread' => $newmark});
 1507:             &Apache::lonnet::appenv('environment.discmarkread' => $newmark);
 1508:         } else {
 1509:             $message.='In discussions: posts will be identified as "new" until marked as read by the reader.<br />';
 1510:             &Apache::lonnet::del('environment',['discmarkread']);
 1511:             &Apache::lonnet::delenv('environment\.discmarkread');
 1512:         }
 1513:     }
 1514:     $r->print(<<ENDVCSCREEN);
 1515: $message
 1516: ENDVCSCREEN
 1517: }
 1518: 
 1519: ################################################################
 1520: # Subroutines for page display on course access (Course Coordinators)
 1521: ################################################################
 1522: sub coursedisplaychanger {
 1523:     my $r = shift;
 1524:     my $user       = $env{'user.name'};
 1525:     my $domain     = $env{'user.domain'};
 1526:     my %userenv = &Apache::lonnet::get('environment',['course_init_display']);
 1527:     my $currvalue = 'whatsnew';
 1528:     my $firstselect = '';
 1529:     my $whatsnewselect = 'checked="checked"';
 1530:     if (exists($userenv{'course_init_display'})) {
 1531:         if ($userenv{'course_init_display'} eq 'firstres') {
 1532:             $currvalue = 'firstres';
 1533:             $firstselect = 'checked="checked"';
 1534: 	    $whatsnewselect = '';
 1535:         }
 1536:     }
 1537:     my %pagenames = (
 1538:                        firstres => 'First resource',
 1539:                        whatsnew => "What's new page",
 1540:                     );
 1541:     my $whatsnew_off=&mt('Display the [_1] in the course.','<b>first resource</b>');
 1542:     my $whatsnew_on=&mt('Display the "[_1]" page - a summary of items in the course which require attention.',"<b>What's New</b>");
 1543: 
 1544:     $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 />');
 1545:     $r->print(<<ENDLSCREEN);
 1546: <form name="prefs" action="/adm/preferences" method="post">
 1547: <input type="hidden" name="action" value="verify_and_change_coursepage" />
 1548: <br />
 1549: <label><input type="radio" name="newdisp" value="firstres" $firstselect /> $whatsnew_off</label><br />
 1550: <label><input type="radio" name="newdisp" value="whatsnew" $whatsnewselect /> $whatsnew_on</label><input type="hidden" name="refpage" value="$env{'form.refpage'}" />
 1551: ENDLSCREEN
 1552:     $r->print('<br /><br /><input type="submit" value="'.&mt('Change').'" />
 1553: </form>');
 1554: }
 1555: 
 1556: sub verify_and_change_coursepage {
 1557:     my $r = shift;
 1558:     my $message='';
 1559:     my %lt = &Apache::lonlocal::texthash(
 1560:         'defs' => 'Default now set',
 1561:         'when' => 'when you select a course role from the roles screen',
 1562:         'ywbt' => 'you will be taken to the start of the course.',
 1563:         'apwb' => 'a page will be displayed that lists items in the course that may require action from you.',
 1564:         'gtts' => 'Go to the start of the course',
 1565:         'dasp' => "Display the What's New page listing course action items", 
 1566:     );
 1567:     my $newdisp  = $env{'form.newdisp'};
 1568:     $message = '<b>'.$lt{'defs'}.'</b>: '.$lt{'when'}.', ';
 1569:     if ($newdisp eq 'firstres') {
 1570:         $message .= $lt{'ywbt'}.'<br />';
 1571:         &Apache::lonnet::put('environment',{'course_init_display' => $newdisp});
 1572:         &Apache::lonnet::appenv('environment.course_init_display' => $newdisp);
 1573:     } else {
 1574:         $message .= $lt{'apwb'}.'<br />';
 1575:         &Apache::lonnet::del('environment',['course_init_display']);
 1576:         &Apache::lonnet::delenv('environment\.course_init_display');
 1577:     }
 1578:     my $refpage = $env{'form.refpage'};
 1579:     if (($env{'request.course.fn'}) && ($env{'request.course.id'})) {
 1580:         if ($newdisp eq 'firstres') {
 1581:             my $cdom = $env{'course.'.$env{'request.course.id'}.'.domain'};
 1582:             my $cnum = $env{'course.'.$env{'request.course.id'}.'.num'}; 
 1583:             my ($furl,$ferr)=
 1584:                 &Apache::lonuserstate::readmap($cdom.'/'.$cnum);
 1585:             $message .= '<br /><font size="+1"><a href="'.$furl.'">'.$lt{'gtts'}.' <i>'.&mt('now').'</i></a></font>';
 1586:         } else {
 1587:             $message .= '<br /><font size="+1"><a href="/adm/whatsnew?refpage='.
 1588:                         $refpage.'">'.$lt{'dasp'}.'</a></font>';
 1589:         }
 1590:     }
 1591:     $r->print(<<ENDVCSCREEN);
 1592: $message
 1593: <br /><br />
 1594: ENDVCSCREEN
 1595: }
 1596: 
 1597: 
 1598: ######################################################
 1599: #            other handler subroutines               #
 1600: ######################################################
 1601: 
 1602: ################################################################
 1603: #                          Main handler                        #
 1604: ################################################################
 1605: sub handler {
 1606:     my $r = shift;
 1607:     my $user = $env{'user.name'};
 1608:     my $domain = $env{'user.domain'};
 1609:     &Apache::loncommon::content_type($r,'text/html');
 1610:     # Some pages contain DES keys and should not be cached.
 1611:     &Apache::loncommon::no_cache($r);
 1612:     $r->send_http_header;
 1613:     return OK if $r->header_only;
 1614:     #
 1615:     &Apache::loncommon::get_unprocessed_cgi($ENV{'QUERY_STRING'},
 1616:                                    ['action','wysiwyg','returnurl','refpage']);
 1617:     #
 1618:     &Apache::lonhtmlcommon::clear_breadcrumbs();
 1619:     &Apache::lonhtmlcommon::add_breadcrumb
 1620:         ({href => '/adm/preferences',
 1621:           text => 'Set User Preferences'});
 1622: 
 1623:     my @Options;
 1624:     # Determine current authentication method
 1625:     my $currentauth=&Apache::lonnet::queryauthenticate($user,$domain);
 1626:     if ($currentauth =~ /^(unix|internal):/) {
 1627:         push (@Options,({ action   => 'changepass',
 1628:                           linktext => 'Change Password',
 1629:                           href     => '/adm/preferences',
 1630:                           help     => 'Change_Password',
 1631:                           subroutine => \&passwordchanger,
 1632:                           breadcrumb => 
 1633:                               { href => '/adm/preferences?action=changepass',
 1634:                                 text => 'Change Password'},
 1635:                           },
 1636:                         { action => 'verify_and_change_pass',
 1637:                           subroutine => \&verify_and_change_password,
 1638:                           breadcrumb => 
 1639:                               { href =>'/adm/preferences?action=changepass',
 1640:                                 text => 'Change Password'},
 1641:                           printmenu => 'not_on_error',
 1642:                           }));
 1643:     }
 1644:     push (@Options,({ action   => 'changescreenname',
 1645:                       linktext => 'Change Screen Name',
 1646:                       href     => '/adm/preferences',
 1647:                       help     => 'Prefs_Screen_Name_Nickname',
 1648:                       subroutine => \&screennamechanger,
 1649:                       breadcrumb => 
 1650:                           { href => '/adm/preferences?action=changescreenname',
 1651:                             text => 'Change Screen Name'},
 1652:                       },
 1653:                     { action   => 'verify_and_change_screenname',
 1654:                       subroutine => \&verify_and_change_screenname,
 1655:                       breadcrumb => 
 1656:                           { href => '/adm/preferences?action=changescreenname',
 1657:                             text => 'Change Screen Name'},
 1658:                       printmenu => 'yes',
 1659:                       }));
 1660: 
 1661:     push (@Options,({ action   => 'changemsgforward',
 1662:                       linktext => 'Change Message Forwarding and Notification Email Addresses',
 1663:                       href     => '/adm/preferences',
 1664:                       help     => 'Prefs_Forwarding',
 1665:                       breadcrumb => 
 1666:                           { href => '/adm/preferences?action=changemsgforward',
 1667:                             text => 'Change Message Forwarding'},
 1668:                       subroutine => \&msgforwardchanger,
 1669:                       },
 1670:                     { action => 'verify_and_change_msgforward',
 1671:                       breadcrumb => 
 1672:                           { href => '/adm/preferences?action=changemsgforward',
 1673:                             text => 'Change Message Forwarding'},
 1674:                       printmenu => 'no',
 1675:                       subroutine => \&verify_and_change_msgforward }));
 1676:     my $aboutmeaction=
 1677:         '/adm/'.$env{'user.domain'}.'/'.$env{'user.name'}.'/aboutme';
 1678:     push (@Options,{ action => 'none', 
 1679:                      linktext =>
 1680:                          q{Edit the 'About Me' Personal Information Screen},
 1681: 		     help => 'Prefs_About_Me',
 1682:                      href => $aboutmeaction});
 1683:     push (@Options,({ action => 'changecolors',
 1684:                       linktext => 'Change Color Scheme',
 1685:                       href => '/adm/preferences',
 1686:                       help => 'Change_Colors',
 1687:                       breadcrumb => 
 1688:                           { href => '/adm/preferences?action=changecolors',
 1689:                             text => 'Change Colors'},
 1690:                       subroutine => \&colorschanger,
 1691:                   },
 1692:                     { action => 'verify_and_change_colors',
 1693:                       breadcrumb => 
 1694:                           { href => '/adm/preferences?action=changecolors',
 1695:                             text => 'Change Colors'},
 1696:                       printmenu => 'yes',
 1697:                       subroutine => \&verify_and_change_colors,
 1698:                       }));
 1699:     push (@Options,({ action => 'changelanguages',
 1700:                       linktext => 'Change Language Preferences',
 1701:                       href => '/adm/preferences',
 1702: 		      help => 'Prefs_Language',
 1703:                       breadcrumb=>
 1704:                           { href => '/adm/preferences?action=changelanguages',
 1705:                             text => 'Change Language'},
 1706:                       subroutine =>  \&languagechanger,
 1707:                   },
 1708:                     { action => 'verify_and_change_languages',
 1709:                       breadcrumb=>
 1710:                           {href => '/adm/preferences?action=changelanguages',
 1711:                            text => 'Change Language'},
 1712:                       printmenu => 'yes',
 1713:                       subroutine=>\&verify_and_change_languages, }
 1714:                     ));
 1715:     push (@Options,({ action => 'changewysiwyg',
 1716:                       linktext => 'Change WYSIWYG Editor Preferences',
 1717:                       href => '/adm/preferences',
 1718:                       breadcrumb => 
 1719:                             { href => '/adm/preferences?action=changewysiwyg',
 1720:                               text => 'Change WYSIWYG Preferences'},
 1721:                       subroutine => \&wysiwygchanger,
 1722:                   },
 1723:                     { action => 'set_wysiwyg',
 1724:                       breadcrumb =>
 1725:                           { href => '/adm/preferences?action=changewysiwyg',
 1726:                             text => 'Change WYSIWYG Preferences'},
 1727:                       printmenu => 'yes',
 1728:                       subroutine => \&verify_and_change_wysiwyg, }
 1729:                     ));
 1730:     push (@Options,({ action => 'changediscussions',
 1731:                       linktext => 'Change Discussion Display Preferences',
 1732:                       href => '/adm/preferences',
 1733:                       help => 'Change_Discussion_Display',
 1734:                       breadcrumb => 
 1735:                             { href => '/adm/preferences?action=changediscussions',
 1736:                               text => 'Change Discussion Preferences'},
 1737:                       subroutine => \&discussionchanger,
 1738:                   },
 1739:                     { action => 'verify_and_change_discussion',
 1740:                       breadcrumb =>
 1741:                           { href => '/adm/preferences?action=changediscussions',
 1742:                             text => 'Change Discussion Preferences'},
 1743:                       printmenu => 'yes',
 1744:                       subroutine => \&verify_and_change_discussion, }
 1745:                     ));
 1746: 
 1747:     my $role = ($env{'user.adv'} ? 'Roles' : 'Course');
 1748:     push (@Options,({ action   => 'changerolespref',
 1749:                       linktext => 'Change '.$role.' Page Preferences',
 1750:                       href     => '/adm/preferences',
 1751:                       subroutine => \&rolesprefchanger,
 1752:                       breadcrumb =>
 1753:                           { href => '/adm/preferences?action=changerolespref',
 1754:                             text => 'Change '.$role.' Page Pref'},
 1755:                       },
 1756:                     { action   => 'verify_and_change_rolespref',
 1757:                       subroutine => \&verify_and_change_rolespref,
 1758:                       breadcrumb =>
 1759:                           { href => '/adm/preferences?action=changerolespref',
 1760:                             text => 'Change '.$role.' Page Preferences'},
 1761:                       printmenu => 'yes',
 1762:                       }));
 1763: 
 1764:     push (@Options,({ action   => 'changetexenginepref',
 1765:                       linktext => 'Change How Math Equations Are Displayed',
 1766:                       href     => '/adm/preferences',
 1767:                       subroutine => \&texenginechanger,
 1768:                       breadcrumb =>
 1769:                           { href => '/adm/preferences?action=changetexenginepref',
 1770:                             text => 'Change Math Pref'},
 1771:                       },
 1772:                     { action   => 'verify_and_change_texengine',
 1773:                       subroutine => \&verify_and_change_texengine,
 1774:                       breadcrumb =>
 1775:                           { href => '/adm/preferences?action=changetexenginepref',
 1776:                             text => 'Change Math Preferences'},
 1777:                       printmenu => 'yes',
 1778:                       }));
 1779: 
 1780:     if ($env{'environment.remote'} eq 'off') {
 1781: 	push (@Options,({ action => 'launch',
 1782: 			  linktext => 'Launch Remote Control',
 1783: 			  href => '/adm/remote?url=/adm/preferences',
 1784: 		      }));
 1785:     } else {
 1786: 	push (@Options,({ action => 'collapse',
 1787: 			  linktext => 'Collapse Remote Control',
 1788: 			  href => '/adm/remote?url=/adm/preferences',
 1789: 		      }));
 1790:     }
 1791: 
 1792:     push (@Options,({ action   => 'changeicons',
 1793:                       linktext => 'Change How Menus are Displayed',
 1794:                       href     => '/adm/preferences',
 1795:                       subroutine => \&iconchanger,
 1796:                       breadcrumb =>
 1797:                           { href => '/adm/preferences?action=changeicons',
 1798:                             text => 'Change Main Menu'},
 1799:                       },
 1800:                     { action   => 'verify_and_change_icons',
 1801:                       subroutine => \&verify_and_change_icons,
 1802:                       breadcrumb =>
 1803:                           { href => '/adm/preferences?action=changeicons',
 1804:                             text => 'Change Main Menu'},
 1805:                       printmenu => 'yes',
 1806:                       }));
 1807: 
 1808:     push (@Options,({ action   => 'changeclicker',
 1809:                       linktext => 'Register Response Devices ("Clickers")',
 1810:                       href     => '/adm/preferences',
 1811:                       subroutine => \&clickerchanger,
 1812:                       breadcrumb =>
 1813:                           { href => '/adm/preferences?action=changeicons',
 1814:                             text => 'Register Clicker'},
 1815:                       },
 1816:                     { action   => 'verify_and_change_clicker',
 1817:                       subroutine => \&verify_and_change_clicker,
 1818:                       breadcrumb =>
 1819:                           { href => '/adm/preferences?action=changeclicker',
 1820:                             text => 'Register Clicker'},
 1821:                       printmenu => 'yes',
 1822:                       }));
 1823: 
 1824: 
 1825:     if (&Apache::lonnet::allowed('whn',$env{'request.course.id'})
 1826: 	|| &Apache::lonnet::allowed('whn',$env{'request.course.id'}.'/'
 1827: 				    .$env{'request.course.sec'})) {
 1828:         push (@Options,({ action => 'changecourseinit',
 1829:                           linktext => 'Change Course Initialization Preference',
 1830:                           href => '/adm/preferences',
 1831:                           subroutine => \&coursedisplaychanger,
 1832:                           breadcrumb =>
 1833:                               { href => '/adm/preferences?action=changecourseinit',
 1834:                                 text => 'Change Course Init. Pref.'},
 1835:                           },
 1836:                         { action => 'verify_and_change_coursepage',
 1837:                           breadcrumb =>
 1838:                           { href => '/adm/preferences?action=changecourseinit',                               text => 'Change Course Initialization Preference'},
 1839:                         printmenu => 'yes',
 1840:                         subroutine => \&verify_and_change_coursepage,
 1841:                        }));
 1842:     }
 1843: 
 1844:     if ($env{'user.name'} =~ /^(albertel|fox|foxr|koretemey|korte|hallmat3|turtle|raeburn)$/) {
 1845:         push (@Options,({ action => 'debugtoggle',
 1846:                           printmenu => 'yes',
 1847:                           subroutine => \&toggle_debug,
 1848:                           }));
 1849:     }
 1850: 
 1851:     $r->print(&Apache::loncommon::start_page('Change Preferences'));
 1852: 
 1853:     my $call = undef;
 1854:     my $help = undef;
 1855:     my $printmenu = 'yes';
 1856:     foreach my $option (@Options) {
 1857:         if ($option->{'action'} eq $env{'form.action'}) {
 1858:             $call = $option->{'subroutine'};
 1859:             $printmenu = $option->{'printmenu'};
 1860:             if (exists($option->{'breadcrumb'})) {
 1861:                 &Apache::lonhtmlcommon::add_breadcrumb
 1862:                     ($option->{'breadcrumb'});
 1863:             }
 1864: 	    $help=$option->{'help'};
 1865:         }
 1866:     }
 1867:     $r->print(&Apache::lonhtmlcommon::breadcrumbs('Change Preferences',$help));
 1868:     my $error;
 1869:     if (defined($call)) {
 1870:         $error = $call->($r);
 1871:     }
 1872:     if ( ( ($printmenu eq 'yes')
 1873: 	   || ($printmenu eq 'not_on_error' && !$error) )
 1874: 	 && (!$env{'form.returnurl'})) {
 1875:         my $optionlist = '<table cellpadding="5">';
 1876:         if ($env{'user.name'} =~ 
 1877:                          /^(albertel|kortemey|fox|foxr|korte|hallmat3|turtle|raeburn)$/
 1878:             ) {
 1879:             push (@Options,({ action => 'debugtoggle',
 1880:                               linktext => 'Toggle Debug Messages',
 1881:                               text => 'Current Debug status is -'.
 1882:                                   $env{'user.debug'}.'-.',
 1883:                               href => '/adm/preferences',
 1884:                               printmenu => 'yes',
 1885:                               subroutine => \&toggle_debug,
 1886:                               }));
 1887:         }
 1888:         foreach my $option(@Options) {
 1889:             my $optiontext = '';
 1890:             if (exists($option->{'href'})) {
 1891: 		$option->{'href_args'}{'action'}=$option->{'action'};
 1892: 		$optiontext .= 
 1893:                     '<a href="'.&add_get_param($option->{'href'},
 1894: 					       $option->{'href_args'}).'">'.
 1895:                     &mt($option->{'linktext'}).'</a>';
 1896:             }
 1897:             if (exists($option->{'text'})) {
 1898:                 $optiontext .= ' '.&mt($option->{'text'});
 1899:             }
 1900:             if ($optiontext ne '') {
 1901:                 $optiontext = '<font size="+1">'.$optiontext.'</font>'; 
 1902:                 my $helplink = '&nbsp;';
 1903:                 if (exists($option->{'help'})) {
 1904:                     $helplink = &Apache::loncommon::help_open_topic
 1905:                                                     ($option->{'help'});
 1906:                 }
 1907:                 $optionlist .= '<tr>'.
 1908:                     '<td>'.$helplink.'</td>'.
 1909:                     '<td>'.$optiontext.'</td>'.
 1910:                     '</tr>';
 1911:             }
 1912:         }
 1913:         $optionlist .= '</table>';
 1914:         $r->print($optionlist);
 1915:     } elsif ($env{'form.returnurl'}) {
 1916: 	$r->print('<br /><a href="'.$env{'form.returnurl'}.'"><font size="+1">'.
 1917: 		  &mt('Return').'</font></a>');
 1918:     }
 1919:     $r->print(&Apache::loncommon::end_page());
 1920:     return OK;
 1921: }
 1922: 
 1923: sub toggle_debug {
 1924:     if ($env{'user.debug'}) {
 1925:         &Apache::lonnet::delenv('user\.debug');
 1926:     } else {
 1927:         &Apache::lonnet::appenv('user.debug' => 1);
 1928:     }
 1929: }
 1930: 
 1931: 1;
 1932: __END__

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