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

1.1       www         1: # The LearningOnline Network
                      2: # Preferences
                      3: #
1.99    ! www         4: # $Id: lonpreferences.pm,v 1.98 2007/04/13 13:39:32 www Exp $
1.2       albertel    5: #
                      6: # Copyright Michigan State University Board of Trustees
                      7: #
                      8: # This file is part of the LearningOnline Network with CAPA (LON-CAPA).
                      9: #
                     10: # LON-CAPA is free software; you can redistribute it and/or modify
                     11: # it under the terms of the GNU General Public License as published by
                     12: # the Free Software Foundation; either version 2 of the License, or
                     13: # (at your option) any later version.
                     14: #
                     15: # LON-CAPA is distributed in the hope that it will be useful,
                     16: # but WITHOUT ANY WARRANTY; without even the implied warranty of
                     17: # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
                     18: # GNU General Public License for more details.
                     19: #
                     20: # You should have received a copy of the GNU General Public License
                     21: # along with LON-CAPA; if not, write to the Free Software
                     22: # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
                     23: #
                     24: # /home/httpd/html/adm/gpl.txt
                     25: #
                     26: # http://www.lon-capa.org/
                     27: #
1.3       matthew    28: # This package uses the "londes.js" javascript code. 
                     29: #
                     30: # TODOs that have to be completed:
                     31: #    interface with lonnet to change the password
                     32:  
1.1       www        33: package Apache::lonpreferences;
                     34: 
                     35: use strict;
1.86      albertel   36: use LONCAPA;
1.1       www        37: use Apache::Constants qw(:common);
1.3       matthew    38: use Apache::File;
                     39: use Crypt::DES;
                     40: use DynaLoader; # for Crypt::DES version
1.4       matthew    41: use Apache::loncommon();
1.23      matthew    42: use Apache::lonhtmlcommon();
1.32      www        43: use Apache::lonlocal;
1.59      albertel   44: use Apache::lonnet;
1.95      albertel   45: use LONCAPA();
1.3       matthew    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 {
1.4       matthew    56:     # Make a new key for DES encryption.
1.36      www        57:     # Each key has two parts which are returned separately.
1.4       matthew    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.
1.3       matthew    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))));
1.4       matthew    87:     $plaintext=substr($plaintext,1,ord(substr($plaintext,0,1)) );
1.3       matthew    88:     return $plaintext;
                     89: }
                     90: 
1.4       matthew    91: ################################################################
                     92: #                       Handler subroutines                    #
                     93: ################################################################
1.9       matthew    94: 
                     95: ################################################################
1.28      www        96: #         Language Change Subroutines                          #
                     97: ################################################################
1.44      www        98: 
                     99: sub wysiwygchanger {
                    100:     my $r = shift;
                    101:     my %userenv = &Apache::lonnet::get
                    102:         ('environment',['wysiwygeditor']);
1.78      albertel  103:     my $onselect='checked="checked"';
1.44      www       104:     my $offselect='';
1.77      albertel  105:     if ($userenv{'wysiwygeditor'} eq 'on') {
1.44      www       106: 	$onselect='';
1.78      albertel  107: 	$offselect='checked="checked"';
1.44      www       108:     }
                    109:     my $switchoff=&mt('Disable WYSIWYG editor');
                    110:     my $switchon=&mt('Enable WYSIWYG editor');
                    111:     $r->print(<<ENDLSCREEN);
1.88      albertel  112: <form name="prefs" action="/adm/preferences" method="post">
1.44      www       113: <input type="hidden" name="action" value="set_wysiwyg" />
                    114: <br />
1.65      albertel  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>
1.44      www       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;
1.59      albertel  124:     my $newsetting=$env{'form.wysiwyg'};
1.44      www       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: ################################################################
1.28      www       133: sub languagechanger {
                    134:     my $r = shift;
1.59      albertel  135:     my $user       = $env{'user.name'};
                    136:     my $domain     = $env{'user.domain'};
1.28      www       137:     my %userenv = &Apache::lonnet::get
1.32      www       138:         ('environment',['languages']);
1.29      www       139:     my $language=$userenv{'languages'};
1.32      www       140: 
1.33      www       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);
1.28      www       151:     $r->print(<<ENDLSCREEN);
1.88      albertel  152: <form name="prefs" action="/adm/preferences" method="post">
1.28      www       153: <input type="hidden" name="action" value="verify_and_change_languages" />
1.33      www       154: <br />$pref: $selectionbox
1.28      www       155: ENDLSCREEN
1.35      matthew   156:     $r->print('<br /><input type="submit" value="'.&mt('Change').'" />');
1.28      www       157: }
                    158: 
                    159: 
                    160: sub verify_and_change_languages {
                    161:     my $r = shift;
1.59      albertel  162:     my $user       = $env{'user.name'};
                    163:     my $domain     = $env{'user.domain'};
1.28      www       164: # Screenname
1.59      albertel  165:     my $newlanguage  = $env{'form.language'};
1.28      www       166:     $newlanguage=~s/[^\-\w]//g;
                    167:     my $message='';
                    168:     if ($newlanguage) {
1.29      www       169:         &Apache::lonnet::put('environment',{'languages' => $newlanguage});
                    170:         &Apache::lonnet::appenv('environment.languages' => $newlanguage);
                    171:         $message='Set new preferred languages to '.$newlanguage;
1.28      www       172:     } else {
1.29      www       173:         &Apache::lonnet::del('environment',['languages']);
                    174:         &Apache::lonnet::delenv('environment\.languages');
1.28      www       175:         $message='Reset preferred language';
                    176:     }
                    177:     $r->print(<<ENDVCSCREEN);
                    178: $message
                    179: ENDVCSCREEN
                    180: }
                    181: 
1.50      albertel  182: ################################################################
1.54      albertel  183: #         Tex Engine Change Subroutines                        #
                    184: ################################################################
                    185: sub texenginechanger {
                    186:     my $r = shift;
1.59      albertel  187:     my $user       = $env{'user.name'};
                    188:     my $domain     = $env{'user.domain'};
1.54      albertel  189:     my %userenv = &Apache::lonnet::get('environment',['texengine']);
                    190:     my $texengine=$userenv{'texengine'};
                    191: 
                    192:     my $pref=&mt('Preferred method to display Math');
1.69      albertel  193:     my %mathchoices=('' => 'Default',
1.54      albertel  194: 		     'tth' => 'TeX to HTML',
1.64      albertel  195: 		     #'ttm' => 'TeX to MathML',
1.54      albertel  196: 		     'jsMath' => 'jsMath',
1.57      albertel  197: 		     'mimetex' => 'Convert to Images'
1.54      albertel  198:                      );
                    199:     my $selectionbox=&Apache::loncommon::select_form($texengine,'texengine',
                    200: 						     %mathchoices);
1.67      albertel  201:     my $jsMath_start=&Apache::lontexconvert::jsMath_header();
1.54      albertel  202:     my $change=&mt('Change');
                    203:     $r->print(<<ENDLSCREEN);
1.67      albertel  204: <br />
                    205: 
1.88      albertel  206: <form name="prefs" action="/adm/preferences" method="post">
1.54      albertel  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:
1.67      albertel  212: <p> TeX to HTML <br /> 
1.79      albertel  213: <iframe src="/res/adm/pages/math_example.tex?inhibitmenu=yes&texengine=tth" width="400" hieght="200"></iframe>
1.67      albertel  214: </p>
1.54      albertel  215: <p>jsMath <br /> 
1.67      albertel  216: $jsMath_start
1.57      albertel  217: <script type="text/javascript">
1.54      albertel  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>
1.79      albertel  233: <iframe src="/res/adm/pages/math_example.tex?inhibitmenu=yes&texengine=jsMath" width="400" hieght="200"></iframe>
1.54      albertel  234: 
1.67      albertel  235: </p>
                    236: <p> Convert to Images <br />
                    237: <br />
1.79      albertel  238: <iframe src="/res/adm/pages/math_example.tex?inhibitmenu=yes&texengine=mimetex" width="400" hieght="200"></iframe>
1.67      albertel  239: </p>
1.54      albertel  240: ENDLSCREEN
1.59      albertel  241:     if ($env{'environment.texengine'} ne 'jsMath') {
1.55      albertel  242: 	$r->print('<script type="text/javascript">jsMath.Process()</script>');
                    243:     }
1.54      albertel  244: }
                    245: 
                    246: 
                    247: sub verify_and_change_texengine {
                    248:     my $r = shift;
1.59      albertel  249:     my $user       = $env{'user.name'};
                    250:     my $domain     = $env{'user.domain'};
1.54      albertel  251: # Screenname
1.59      albertel  252:     my $newtexengine  = $env{'form.texengine'};
1.54      albertel  253:     $newtexengine=~s/[^\-\w]//g;
1.56      albertel  254:     if ($newtexengine eq 'ttm') {
                    255: 	&Apache::lonnet::appenv('browser.mathml' => 1);
                    256:     } else {
1.59      albertel  257: 	if ($env{'environment.texengine'} eq 'ttm') {
1.56      albertel  258: 	    &Apache::lonnet::appenv('browser.mathml' => 0);
                    259: 	}
                    260:     }
1.54      albertel  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:     }
1.56      albertel  271: 
                    272: 
1.54      albertel  273:     $r->print(<<ENDVCSCREEN);
                    274: $message
                    275: ENDVCSCREEN
                    276: }
                    277: 
                    278: ################################################################
1.50      albertel  279: #         Roles Page Preference Change Subroutines         #
                    280: ################################################################
                    281: sub rolesprefchanger {
                    282:     my $r = shift;
1.96      albertel  283:     my $role    = ($env{'user.adv'} ? 'Role' : 'Course');
                    284:     my $lc_role = ($env{'user.adv'} ? 'role' : 'course');
1.59      albertel  285:     my $user       = $env{'user.name'};
                    286:     my $domain     = $env{'user.domain'};
1.50      albertel  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: 
1.89      albertel  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'});
1.91      albertel  310:         my %frozen_roles =
                    311:                &Apache::lonhtmlcommon::get_recent_frozen('roles',$env{'environment.recentrolesn'});
1.89      albertel  312:         
1.93      albertel  313:         my %role_text = &rolespref_get_role_text([keys(%recent_roles)]);
1.92      albertel  314:         my @sorted_roles = sort {$role_text{$a} cmp $role_text{$b}} keys(%role_text);
                    315: 
1.89      albertel  316:         $roles_check_list .=
                    317: 	    &Apache::loncommon::start_data_table().
                    318: 	    &Apache::loncommon::start_data_table_header_row().
1.96      albertel  319: 	    "<th>".&mt('Freeze '.$role)."</th>".
                    320: 	    "<th>".&mt($role)."</td>".
1.89      albertel  321: 	    &Apache::loncommon::end_data_table_header_row().
                    322: 	    "\n";
                    323: 	my $count;
1.92      albertel  324:         foreach $role_key (@sorted_roles) {
1.89      albertel  325:             my $checked = "";
                    326:             my $value = $recent_roles{$role_key};
1.91      albertel  327:             if ($frozen_roles{$role_key}) {
1.89      albertel  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\">".
1.92      albertel  337: 		"$role_text{$role_key}</label></td>".
1.89      albertel  338: 		&Apache::loncommon::end_data_table_row(). "\n";
                    339:         }
                    340:         $roles_check_list .= "</table>\n";
                    341:     }
                    342: 
                    343:     $r->print('
1.96      albertel  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.').'
1.50      albertel  345: </p>
1.89      albertel  346: <form name="prefs" action="/adm/preferences" method="POST">
1.50      albertel  347: <input type="hidden" name="action" value="verify_and_change_rolespref" />
1.96      albertel  348: <br /><label>'.&mt('Enable Recent '.$role.'s Hotlist:').'
1.89      albertel  349: <input type="checkbox" '.$checked.' name="recentroles" value="true" /></label>
1.96      albertel  350: <br />'.&mt('Number of '.$role.'s in Hotlist:').'
1.50      albertel  351: <select name="recentrolesn" size="1">
1.89      albertel  352: '.$options.'
1.50      albertel  353: </select>
1.96      albertel  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.').'
1.89      albertel  355: </p>
                    356: '.$roles_check_list.'
1.50      albertel  357: <br />
1.89      albertel  358: <input type="submit" value="'.&mt('Change').'" />
                    359: </form>');
1.50      albertel  360: }
                    361: 
1.92      albertel  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);
1.93      albertel  370:         my $trole = "";
                    371:         $trole = &Apache::lonnet::plaintext($role);
1.92      albertel  372:         my ($tdomain,$other,$tsection)= split(/\//,Apache::lonnet::declutter($rest));
                    373:         my $tother = '-';
1.93      albertel  374:         if ($role =~ /^(cc|st|in|ta|ep|cr)/ ) {
1.92      albertel  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: 
1.50      albertel  392: sub verify_and_change_rolespref {
                    393:     my $r = shift;
1.96      albertel  394:     my $role = ($env{'user.adv'} ? 'Role' : 'Course');
1.59      albertel  395:     my $user       = $env{'user.name'};
                    396:     my $domain     = $env{'user.domain'};
1.50      albertel  397: # Recent Roles Hotlist Flag
1.59      albertel  398:     my $hotlist_flag  = $env{'form.recentroles'};
                    399:     my $hotlist_n  = $env{'form.recentrolesn'};
1.89      albertel  400:     my $message='<hr />';
1.50      albertel  401:     if ($hotlist_flag) {
                    402:         &Apache::lonnet::put('environment',{'recentroles' => $hotlist_flag});
                    403:         &Apache::lonnet::appenv('environment.recentroles' => $hotlist_flag);
1.96      albertel  404:         $message=&mt('Recent '.$role.'s Hotlist is Enabled');
1.50      albertel  405:     } else {
                    406:         &Apache::lonnet::del('environment',['recentroles']);
                    407:         &Apache::lonnet::delenv('environment\.recentroles');
1.96      albertel  408:         $message=&mt('Recent '.$role.'s Hotlist is Disabled');
1.50      albertel  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) {
1.90      albertel  414:             $message.="<br />".
1.96      albertel  415: 		&mt('Display [_1] Most Recent '.$role.'s',$hotlist_n)."\n";
1.89      albertel  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 = ();
1.92      albertel  422:     my %roletext = ();
                    423: 
1.89      albertel  424:     foreach my $key (@freeze_list) {
1.91      albertel  425:         $freeze{$key}='1';
1.89      albertel  426:     }
1.92      albertel  427: 
1.89      albertel  428:     my %recent_roles =
                    429:         &Apache::lonhtmlcommon::get_recent('roles',$env{'environment.recentrolesn'});
1.91      albertel  430:     my %frozen_roles =
                    431:         &Apache::lonhtmlcommon::get_recent_frozen('roles',$env{'environment.recentrolesn'});
1.92      albertel  432:     my %role_text = &rolespref_get_role_text([keys(%recent_roles)]);
1.89      albertel  433: 
                    434: # Unset any roles that were previously frozen but aren't in list
                    435:     foreach my $role_key (sort(keys(%recent_roles))) {
1.91      albertel  436:         if (($frozen_roles{$role_key}) && (!exists($freeze{$role_key}))) {
1.96      albertel  437: 	    $message .= "<br />".&mt('Unfreezing '.$role.': [_1]',$role_text{$role_key})."\n";
1.91      albertel  438: 	    &Apache::lonhtmlcommon::store_recent('roles',$role_key,' ',0);
1.89      albertel  439:         }
                    440:     }
                    441: 
                    442: # Freeze selected roles
                    443:     foreach my $role_key (@freeze_list) {
1.91      albertel  444:         if (!$frozen_roles{$role_key}) {
1.96      albertel  445:              $message .= "<br />".&mt('Freezing '.$role.': [_1]',$role_text{$role_key})."\n";
1.89      albertel  446:              &Apache::lonhtmlcommon::store_recent('roles',
1.91      albertel  447:                                           $role_key,' ',1);
1.50      albertel  448:         }
                    449:     }
1.89      albertel  450:     $message .= "<hr /><br />\n";
1.50      albertel  451: 
                    452:     $r->print(<<ENDRPSCREEN);
                    453: $message
                    454: ENDRPSCREEN
                    455: }
                    456: 
                    457: 
1.28      www       458: 
                    459: ################################################################
1.9       matthew   460: #         Anonymous Discussion Name Change Subroutines         #
                    461: ################################################################
1.5       www       462: sub screennamechanger {
                    463:     my $r = shift;
1.59      albertel  464:     my $user       = $env{'user.name'};
                    465:     my $domain     = $env{'user.domain'};
1.14      www       466:     my %userenv = &Apache::lonnet::get
                    467:         ('environment',['screenname','nickname']);
1.6       www       468:     my $screenname=$userenv{'screenname'};
1.14      www       469:     my $nickname=$userenv{'nickname'};
1.5       www       470:     $r->print(<<ENDSCREEN);
1.88      albertel  471: <form name="prefs" action="/adm/preferences" method="post">
1.6       www       472: <input type="hidden" name="action" value="verify_and_change_screenname" />
1.14      www       473: <br />New screenname (shown if you post anonymously):
1.6       www       474: <input type="text" size="20" value="$screenname" name="screenname" />
1.14      www       475: <br />New nickname (shown if you post non-anonymously):
                    476: <input type="text" size="20" value="$nickname" name="nickname" />
1.6       www       477: <input type="submit" value="Change" />
                    478: </form>
1.5       www       479: ENDSCREEN
                    480: }
1.6       www       481: 
                    482: sub verify_and_change_screenname {
                    483:     my $r = shift;
1.59      albertel  484:     my $user       = $env{'user.name'};
                    485:     my $domain     = $env{'user.domain'};
1.14      www       486: # Screenname
1.59      albertel  487:     my $newscreen  = $env{'form.screenname'};
1.14      www       488:     $newscreen=~s/[^ \w]//g;
1.6       www       489:     my $message='';
                    490:     if ($newscreen) {
1.7       www       491:         &Apache::lonnet::put('environment',{'screenname' => $newscreen});
                    492:         &Apache::lonnet::appenv('environment.screenname' => $newscreen);
1.6       www       493:         $message='Set new screenname to '.$newscreen;
                    494:     } else {
                    495:         &Apache::lonnet::del('environment',['screenname']);
1.7       www       496:         &Apache::lonnet::delenv('environment\.screenname');
1.6       www       497:         $message='Reset screenname';
                    498:     }
1.14      www       499: # Nickname
                    500:     $message.='<br />';
1.59      albertel  501:     $newscreen  = $env{'form.nickname'};
1.14      www       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:     }
1.68      www       512:     &Apache::lonnet::devalidate_cache_new('namescache',$user.':'.$domain);
1.6       www       513:     $r->print(<<ENDVCSCREEN);
                    514: $message
                    515: ENDVCSCREEN
1.20      www       516: }
                    517: 
                    518: ################################################################
1.98      www       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:     if ($userenv{'icons'} eq 'classic') {
                    530:        $classic='checked="checked"';
                    531:        $iconic='';
                    532:     }
                    533:     my $useicons=&mt('Use icons');
                    534:     my $usebuttons=&mt('Use classic buttons');
                    535:     my $change=&mt('Change');
                    536:     $r->print(<<ENDSCREEN);
                    537: <form name="prefs" action="/adm/preferences" method="post">
                    538: <input type="hidden" name="action" value="verify_and_change_icons" />
                    539: <label><input type="radio" name="menumode" value="iconic" $iconic /> $useicons</label><br />
                    540: <label><input type="radio" name="menumode" value="classic" $classic /> $usebuttons</label><br />
                    541: <input type="submit" value="$change" />
                    542: </form>
                    543: ENDSCREEN
                    544: }
                    545: 
                    546: sub verify_and_change_icons {
                    547:     my $r = shift;
                    548:     my $user       = $env{'user.name'};
                    549:     my $domain     = $env{'user.domain'};
                    550:     my $newicons  = $env{'form.menumode'};
                    551: 
                    552:     &Apache::lonnet::put('environment',{'icons' => $newicons});
                    553:     &Apache::lonnet::appenv('environment.icons' => $newicons);
                    554:     $r->print(&mt('Set menu mode to [_1].',$newicons));
                    555: }
                    556: 
                    557: ################################################################
1.20      www       558: #         Message Forward                                      #
                    559: ################################################################
                    560: 
                    561: sub msgforwardchanger {
                    562:     my $r = shift;
1.59      albertel  563:     my $user       = $env{'user.name'};
                    564:     my $domain     = $env{'user.domain'};
1.26      www       565:     my %userenv = &Apache::lonnet::get('environment',['msgforward','notification','critnotification']);
1.20      www       566:     my $msgforward=$userenv{'msgforward'};
                    567:     my $notification=$userenv{'notification'};
                    568:     my $critnotification=$userenv{'critnotification'};
1.25      bowersj2  569:     my $forwardingHelp = Apache::loncommon::help_open_topic("Prefs_Forwarding",
                    570: 							    "What are forwarding ".
                    571: 							    "and notification ".
                    572: 							    "addresses");
1.27      bowersj2  573:     my $criticalMessageHelp = Apache::loncommon::help_open_topic("Course_Critical_Message",
                    574: 								 "What are critical messages");
                    575: 
1.20      www       576:     $r->print(<<ENDMSG);
1.25      bowersj2  577: $forwardingHelp <br />
1.88      albertel  578: <form name="prefs" action="/adm/preferences" method="post">
1.20      www       579: <input type="hidden" name="action" value="verify_and_change_msgforward" />
                    580: New Forwarding Address(es) (<tt>user:domain,user:domain,...</tt>):
                    581: <input type="text" size="40" value="$msgforward" name="msgforward" /><hr />
                    582: New Message Notification Email Address(es) (<tt>joe\@doe.com,jane\@doe.edu,...</tt>):
                    583: <input type="text" size="40" value="$notification" name="notification" /><hr />
                    584: New Critical Message Notification Email Address(es) (<tt>joe\@doe.com,jane\@doe.edu,...</tt>):
1.27      bowersj2  585: <input type="text" size="40" value="$critnotification" name="critnotification" />$criticalMessageHelp<hr />
1.20      www       586: <input type="submit" value="Change" />
                    587: </form>
                    588: ENDMSG
                    589: }
                    590: 
                    591: sub verify_and_change_msgforward {
                    592:     my $r = shift;
1.59      albertel  593:     my $user       = $env{'user.name'};
                    594:     my $domain     = $env{'user.domain'};
1.20      www       595:     my $newscreen  = '';
                    596:     my $message='';
1.59      albertel  597:     foreach (split(/\,/,$env{'form.msgforward'})) {
1.20      www       598: 	my ($msuser,$msdomain)=split(/[\@\:]/,$_);
1.95      albertel  599:         $msuser = &LONCAPA::clean_username($msuser);
                    600:         $msdomain = &LONCAPA::clean_domain($msdomain);
1.20      www       601:         if (($msuser) && ($msdomain)) {
                    602: 	    if (&Apache::lonnet::homeserver($msuser,$msdomain) ne 'no_host') {
                    603:                $newscreen.=$msuser.':'.$msdomain.',';
                    604: 	   } else {
                    605:                $message.='No such user: '.$msuser.':'.$msdomain.'<br>';
                    606:            }
                    607:         }
                    608:     }
                    609:     $newscreen=~s/\,$//;
                    610:     if ($newscreen) {
                    611:         &Apache::lonnet::put('environment',{'msgforward' => $newscreen});
                    612:         &Apache::lonnet::appenv('environment.msgforward' => $newscreen);
                    613:         $message.='Set new message forwarding to '.$newscreen.'<br />';
                    614:     } else {
                    615:         &Apache::lonnet::del('environment',['msgforward']);
                    616:         &Apache::lonnet::delenv('environment\.msgforward');
                    617:         $message.='Reset message forwarding<br />';
                    618:     }
1.59      albertel  619:     my $notification=$env{'form.notification'};
1.20      www       620:     $notification=~s/\s//gs;
                    621:     if ($notification) {
                    622:         &Apache::lonnet::put('environment',{'notification' => $notification});
                    623:         &Apache::lonnet::appenv('environment.notification' => $notification);
                    624:         $message.='Set message notification address to '.$notification.'<br />';
                    625:     } else {
                    626:         &Apache::lonnet::del('environment',['notification']);
                    627:         &Apache::lonnet::delenv('environment\.notification');
                    628:         $message.='Reset message notification<br />';
                    629:     }
1.59      albertel  630:     my $critnotification=$env{'form.critnotification'};
1.20      www       631:     $critnotification=~s/\s//gs;
                    632:     if ($critnotification) {
                    633:         &Apache::lonnet::put('environment',{'critnotification' => $critnotification});
                    634:         &Apache::lonnet::appenv('environment.critnotification' => $critnotification);
                    635:         $message.='Set critical message notification address to '.$critnotification;
                    636:     } else {
                    637:         &Apache::lonnet::del('environment',['critnotification']);
                    638:         &Apache::lonnet::delenv('environment\.critnotification');
                    639:         $message.='Reset critical message notification<br />';
                    640:     }
                    641:     $r->print(<<ENDVCMSG);
                    642: $message
                    643: ENDVCMSG
1.6       www       644: }
                    645: 
1.12      www       646: ################################################################
1.19      www       647: #         Colors                                               #
1.12      www       648: ################################################################
                    649: 
1.19      www       650: sub colorschanger {
1.12      www       651:     my $r = shift;
1.19      www       652: # figure out colors
1.80      albertel  653:     my $function=&Apache::loncommon::get_users_function();
1.19      www       654:     my $domain=&Apache::loncommon::determinedomain();
                    655:     my %colortypes=('pgbg'  => 'Page Background',
                    656:                     'tabbg' => 'Header Background',
                    657:                     'sidebg'=> 'Header Border',
                    658:                     'font'  => 'Font',
                    659:                     'link'  => 'Un-Visited Link',
                    660:                     'vlink' => 'Visited Link',
                    661:                     'alink' => 'Active Link');
1.82      albertel  662:     my $start_data_table = &Apache::loncommon::start_data_table();
1.19      www       663:     my $chtable='';
1.22      matthew   664:     foreach my $item (sort(keys(%colortypes))) {
1.19      www       665:        my $curcol=&Apache::loncommon::designparm($function.'.'.$item,$domain);
1.82      albertel  666:        $chtable.=&Apache::loncommon::start_data_table_row().
1.83      albertel  667: 	   '<td>'.$colortypes{$item}.'</td><td style="background: '.$curcol.
1.19      www       668:         '">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</td><td><input name="'.$item.
1.21      www       669:         '" size="10" value="'.$curcol.
                    670: '" /></td><td><a href="javascript:pjump('."'color_custom','".$colortypes{$item}.
1.19      www       671: "','".$curcol."','"
1.82      albertel  672: 	    .$item."','parmform.pres','psub'".');">Select</a></td>'.
1.83      albertel  673: 	    &Apache::loncommon::end_data_table_row()."\n";
1.19      www       674:     }
1.82      albertel  675:     my $end_data_table = &Apache::loncommon::end_data_table();
1.23      matthew   676:     my $pjump_def = &Apache::lonhtmlcommon::pjump_javascript_definition();
1.19      www       677:     $r->print(<<ENDCOL);
1.82      albertel  678: <script type="text/javascript">
1.19      www       679: 
                    680:     function pclose() {
                    681:         parmwin=window.open("/adm/rat/empty.html","LONCAPAparms",
                    682:                  "height=350,width=350,scrollbars=no,menubar=no");
                    683:         parmwin.close();
                    684:     }
                    685: 
1.23      matthew   686:     $pjump_def
1.19      www       687: 
                    688:     function psub() {
                    689:         pclose();
                    690:         if (document.parmform.pres_marker.value!='') {
1.21      www       691:             if (document.parmform.pres_type.value!='') {
1.77      albertel  692:                 eval('document.prefs.'+
1.21      www       693:                      document.parmform.pres_marker.value+
1.19      www       694: 		     '.value=document.parmform.pres_value.value;');
1.21      www       695: 	    }
1.19      www       696:         } else {
                    697:             document.parmform.pres_value.value='';
                    698:             document.parmform.pres_marker.value='';
                    699:         }
                    700:     }
                    701: 
                    702: 
                    703: </script>
1.21      www       704: <form name="parmform">
                    705: <input type="hidden" name="pres_marker" />
                    706: <input type="hidden" name="pres_type" />
                    707: <input type="hidden" name="pres_value" />
                    708: </form>
1.88      albertel  709: <form name="prefs" action="/adm/preferences" method="post">
1.19      www       710: <input type="hidden" name="action" value="verify_and_change_colors" />
1.82      albertel  711: $start_data_table
1.19      www       712: $chtable
1.82      albertel  713: $end_data_table
1.19      www       714: </table>
1.21      www       715: <input type="submit" value="Change Custom Colors" />
                    716: <input type="submit" name="resetall" value="Reset All Colors to Default" />
1.12      www       717: </form>
1.19      www       718: ENDCOL
1.12      www       719: }
                    720: 
1.19      www       721: sub verify_and_change_colors {
1.12      www       722:     my $r = shift;
1.19      www       723: # figure out colors
1.80      albertel  724:     my $function=&Apache::loncommon::get_users_function();
1.19      www       725:     my $domain=&Apache::loncommon::determinedomain();
                    726:     my %colortypes=('pgbg'  => 'Page Background',
                    727:                     'tabbg' => 'Header Background',
                    728:                     'sidebg'=> 'Header Border',
                    729:                     'font'  => 'Font',
                    730:                     'link'  => 'Un-Visited Link',
                    731:                     'vlink' => 'Visited Link',
                    732:                     'alink' => 'Active Link');
                    733: 
1.12      www       734:     my $message='';
1.21      www       735:     foreach my $item (keys %colortypes) {
1.59      albertel  736:         my $color=$env{'form.'.$item};
1.21      www       737:         my $entry='color.'.$function.'.'.$item;
1.59      albertel  738: 	if (($color=~/^\#[0-9A-Fa-f]{6}$/) && (!$env{'form.resetall'})) {
1.21      www       739: 	    &Apache::lonnet::put('environment',{$entry => $color});
                    740: 	    &Apache::lonnet::appenv('environment.'.$entry => $color);
                    741: 	    $message.='Set '.$colortypes{$item}.' to '.$color.'<br />';
                    742: 	} else {
                    743: 	    &Apache::lonnet::del('environment',[$entry]);
                    744: 	    &Apache::lonnet::delenv('environment\.'.$entry);
                    745: 	    $message.='Reset '.$colortypes{$item}.'<br />';
                    746: 	}
                    747:     }
1.84      albertel  748:     my $now = time;
                    749:     &Apache::lonnet::put('environment',{'color.timestamp' => $now});
                    750:     &Apache::lonnet::appenv('environment.color.timestamp' => $now);
                    751: 
1.19      www       752:     $r->print(<<ENDVCCOL);
1.12      www       753: $message
1.88      albertel  754: <form name="client" action="/adm/preferences" method="post">
1.21      www       755: <input type="hidden" name="action" value="changecolors" />
                    756: </form>
1.19      www       757: ENDVCCOL
1.12      www       758: }
                    759: 
1.4       matthew   760: ######################################################
                    761: #            password handler subroutines            #
                    762: ######################################################
1.3       matthew   763: sub passwordchanger {
1.94      raeburn   764:     my ($r,$errormessage,$caller,$mailtoken) = @_;
1.4       matthew   765:     # This function is a bit of a mess....
1.3       matthew   766:     # Passwords are encrypted using londes.js (DES encryption)
1.4       matthew   767:     $errormessage = ($errormessage || '');
1.94      raeburn   768:     my ($user,$domain,$currentpass,$defdom);
                    769:     if ((!defined($caller)) || ($caller eq 'preferences')) {
                    770:         $user = $env{'user.name'};
                    771:         $domain = $env{'user.domain'};
                    772:         if (!defined($caller)) {
                    773:             $caller = 'preferences';
                    774:         }
                    775:     } elsif ($caller eq 'reset_by_email') {
                    776:             $defdom = $r->dir_config('lonDefDomain');
                    777:             my %data = &Apache::lonnet::tmpget($mailtoken);
                    778:             if (keys(%data) == 0) {
                    779:                 $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.'));
                    780:                 return;
                    781:             }
                    782:             if (defined($data{time})) {
                    783:                 if (time - $data{'time'} < 7200) {
                    784:                     $user = $data{'username'};
                    785:                     $domain = $data{'domain'};
                    786:                     $currentpass = $data{'temppasswd'};
                    787:                 } else {
                    788:                     $r->print(&mt('Sorry, the token generated when you requested a password reset has expired.').'<br />');
                    789:                     return;
                    790:                 }
                    791:             } else {
                    792:                 $r->print(&mt('Sorry, the URL generated when you requested reset of your password contained incomplete information.').'<br />');
                    793:                 return;
                    794:             }
                    795:    } else {
                    796:         $r->print(&mt('Page requested in unexpected context').'<br />');
                    797:         return;
                    798:     }
1.3       matthew   799:     my $currentauth=&Apache::lonnet::queryauthenticate($user,$domain);
                    800:     # Check for authentication types that allow changing of the password.
                    801:     return if ($currentauth !~ /^(unix|internal):/);
                    802:     #
                    803:     # Generate keys
                    804:     my ($lkey_cpass ,$ukey_cpass ) = &des_keys();
                    805:     my ($lkey_npass1,$ukey_npass1) = &des_keys();
                    806:     my ($lkey_npass2,$ukey_npass2) = &des_keys();
1.4       matthew   807:     # Store the keys in the log files
1.3       matthew   808:     my $lonhost = $r->dir_config('lonHostID');
                    809:     my $logtoken=Apache::lonnet::reply('tmpput:'
                    810: 				       .$ukey_cpass  . $lkey_cpass .'&'
                    811: 				       .$ukey_npass1 . $lkey_npass1.'&'
                    812: 				       .$ukey_npass2 . $lkey_npass2,
                    813: 				       $lonhost);
1.4       matthew   814:     # Hexify the keys for output as javascript variables
1.94      raeburn   815:     my %hexkey;
                    816:     $hexkey{'ukey_cpass'}  = hex($ukey_cpass);
                    817:     $hexkey{'lkey_cpass'}  = hex($lkey_cpass);
                    818:     $hexkey{'ukey_npass1'} = hex($ukey_npass1);
                    819:     $hexkey{'lkey_npass1'} = hex($lkey_npass1);
                    820:     $hexkey{'ukey_npass2'} = hex($ukey_npass2);
                    821:     $hexkey{'lkey_npass2'} = hex($lkey_npass2);
1.3       matthew   822:     # Output javascript to deal with passwords
1.4       matthew   823:     # Output DES javascript
1.3       matthew   824:     {
                    825: 	my $include = $r->dir_config('lonIncludes');
                    826: 	my $jsh=Apache::File->new($include."/londes.js");
                    827: 	$r->print(<$jsh>);
                    828:     }
1.94      raeburn   829:     $r->print(&jscript_send($caller));
1.3       matthew   830:     $r->print(<<ENDFORM);
1.94      raeburn   831: $errormessage
                    832: 
                    833: <p>
                    834: <!-- We separate the forms into 'server' and 'client' in order to
                    835:      ensure that unencrypted passwords will not be sent out by a
                    836:      crappy browser -->
                    837: ENDFORM
                    838:     $r->print(&server_form($logtoken,$caller,$mailtoken));
                    839:     $r->print(&client_form($caller,\%hexkey,$currentpass,$defdom));
                    840: 
                    841:     #
                    842:     return;
                    843: }
                    844: 
                    845: sub jscript_send {
                    846:     my ($caller) = @_;
                    847:     my $output = qq|
1.3       matthew   848: <script language="JavaScript">
                    849: 
                    850:     function send() {
                    851:         uextkey=this.document.client.elements.ukey_cpass.value;
                    852:         lextkey=this.document.client.elements.lkey_cpass.value;
                    853:         initkeys();
                    854: 
1.52      raeburn   855:         this.document.pserver.elements.currentpass.value
1.3       matthew   856:             =crypted(this.document.client.elements.currentpass.value);
                    857: 
                    858:         uextkey=this.document.client.elements.ukey_npass1.value;
                    859:         lextkey=this.document.client.elements.lkey_npass1.value;
                    860:         initkeys();
1.52      raeburn   861:         this.document.pserver.elements.newpass_1.value
1.3       matthew   862:             =crypted(this.document.client.elements.newpass_1.value);
                    863: 
                    864:         uextkey=this.document.client.elements.ukey_npass2.value;
                    865:         lextkey=this.document.client.elements.lkey_npass2.value;
                    866:         initkeys();
1.52      raeburn   867:         this.document.pserver.elements.newpass_2.value
1.3       matthew   868:             =crypted(this.document.client.elements.newpass_2.value);
1.94      raeburn   869: |;
                    870:     if ($caller eq 'reset_by_email') {
                    871:         $output .= qq|
                    872:         this.document.pserver.elements.uname.value =
                    873:                    this.document.client.elements.uname.value;
                    874:         this.document.pserver.elements.udom.value =
                    875:                    this.document.client.elements.udom.options[this.document.client.elements.udom.selectedIndex].value;
                    876: |;
                    877:     }
                    878:     $ output .= qq|
1.52      raeburn   879:         this.document.pserver.submit();
1.3       matthew   880:     }
                    881: </script>
1.94      raeburn   882: |;
                    883: }
1.3       matthew   884: 
1.94      raeburn   885: sub client_form {
                    886:     my ($caller,$hexkey,$currentpass,$defdom) = @_;
1.99    ! www       887:     my %lt=&Apache::lonlocal::texthash(
        !           888:                 'email' => 'EMail Address',
        !           889:                 'username' => 'Username',
        !           890:                 'domain' => 'Domain',
        !           891:                 'currentpass' => 'Current Password',
        !           892:                 'newpass' => 'New Password',
        !           893:                 'confirmpass' => 'Confirm Password',
        !           894:                 'changepass' => 'Change Password');
        !           895: 
1.94      raeburn   896:     my $output = qq|
1.3       matthew   897: <form name="client" >
                    898: <table>
1.94      raeburn   899: |;
                    900:     if ($caller eq 'reset_by_email') {
                    901:         $output .= qq|
1.99    ! www       902: <tr><td class="LC_preferences_labeltext"><label for="email">$lt{'email'}</label>:</td>
1.97      raeburn   903:     <td><input type="text" name="email" size="30" /> </td></tr>
1.99    ! www       904: <tr><td class="LC_preferences_labeltext"><label for="uname">$lt{'username'}</label>:</td>
1.94      raeburn   905:     <td>
1.97      raeburn   906:      <input type="text" name="uname" size="15" />
1.94      raeburn   907:      <input type="hidden" name="currentpass" value="$currentpass" />
                    908:     </td></tr>
1.99    ! www       909: <tr><td class="LC_preferences_labeltext"><label for="udom">$lt{'udom'}</label>:</td>
1.94      raeburn   910:     <td>
                    911: |;
                    912:         $output .= &Apache::loncommon::select_dom_form($defdom,'udom').'
                    913:    </td>
                    914: </tr>
                    915: ';
                    916:     } else {
                    917:         $output .= qq|
1.99    ! www       918: <tr><td class="LC_preferences_labeltext"><label for="currentpass">$lt{'currentpass'}</label></td>
1.4       matthew   919:     <td><input type="password" name="currentpass" size="10"/> </td></tr>
1.94      raeburn   920: |;
                    921:     }
                    922:     $output .= <<"ENDFORM";
1.99    ! www       923: <tr><td class="LC_preferences_labeltext"><label for="newpass_1">$lt{'newpass'}</label></td>
1.4       matthew   924:     <td><input type="password" name="newpass_1" size="10"  /> </td></tr>
1.99    ! www       925: <tr><td class="LC_preferences_labeltext"><label for="newpass_2">$lt{'confirmpass'}</label></td>
1.4       matthew   926:     <td><input type="password" name="newpass_2" size="10"  /> </td></tr>
1.3       matthew   927: <tr><td colspan="2" align="center">
1.99    ! www       928:     <input type="button" value="$lt{'changepass'}" onClick="send();">
1.3       matthew   929: </table>
1.94      raeburn   930: <input type="hidden" name="ukey_cpass"  value="$hexkey->{'ukey_cpass'}" />
                    931: <input type="hidden" name="lkey_cpass"  value="$hexkey->{'lkey_cpass'}" />
                    932: <input type="hidden" name="ukey_npass1" value="$hexkey->{'ukey_npass1'}" />
                    933: <input type="hidden" name="lkey_npass1" value="$hexkey->{'lkey_npass1'}" />
                    934: <input type="hidden" name="ukey_npass2" value="$hexkey->{'ukey_npass2'}" />
                    935: <input type="hidden" name="lkey_npass2" value="$hexkey->{'lkey_npass2'}" />
1.3       matthew   936: </form>
                    937: </p>
                    938: ENDFORM
1.94      raeburn   939:     return $output;
                    940: }
                    941: 
                    942: sub server_form {
                    943:     my ($logtoken,$caller,$mailtoken) = @_;
                    944:     my $action = '/adm/preferences';
                    945:     if ($caller eq 'reset_by_email') {
                    946:         $action = '/adm/resetpw';
                    947:     }
                    948:     my $output = qq|
                    949: <form name="pserver" action="$action" method="post">
                    950: <input type="hidden" name="logtoken"    value="$logtoken" />
                    951: <input type="hidden" name="currentpass" value="" />
                    952: <input type="hidden" name="newpass_1"   value="" />
                    953: <input type="hidden" name="newpass_2"   value="" />
                    954:     |;
                    955:     if ($caller eq 'reset_by_email') {
                    956:         $output .=  qq|
                    957: <input type="hidden" name="token"   value="$mailtoken" />
                    958: <input type="hidden" name="uname"   value="" />
                    959: <input type="hidden" name="udom"   value="" />
                    960: 
                    961: |;
                    962:     }
                    963:     $output .= qq|
                    964: <input type="hidden" name="action" value="verify_and_change_pass" />
                    965: </form>
                    966: |;
                    967:     return $output;
1.3       matthew   968: }
                    969: 
                    970: sub verify_and_change_password {
1.94      raeburn   971:     my ($r,$caller,$mailtoken) = @_;
                    972:     my ($user,$domain,$homeserver);
                    973:     if ($caller eq 'reset_by_email') {
                    974:         $user       = $env{'form.uname'};
                    975:         $domain     = $env{'form.udom'};
                    976:         if ($user ne '' && $domain ne '') {
                    977:             $homeserver = &Apache::lonnet::homeserver($user,$domain);
                    978:             if ($homeserver eq 'no_host') {
1.99    ! www       979:         &passwordchanger($r,"<p>\n<span class='LC_error'>".
        !           980:                          &mt("Invalid username and/or domain")."</span>\n</p>",
1.94      raeburn   981:                          $caller,$mailtoken);
                    982:                 return 1;
                    983:             }
                    984:         } else {
1.99    ! www       985:             &passwordchanger($r,"<p>\n<span class='LC_error'>".
        !           986:                              &mt("Username and domain were blank")."</span>\n</p>",
1.94      raeburn   987:                              $caller,$mailtoken);
                    988:             return 1;
                    989:         }
                    990:     } else {
                    991:         $user       = $env{'user.name'};
                    992:         $domain     = $env{'user.domain'};
                    993:         $homeserver = $env{'user.home'};
                    994:     }
1.3       matthew   995:     my $currentauth=&Apache::lonnet::queryauthenticate($user,$domain);
1.4       matthew   996:     # Check for authentication types that allow changing of the password.
1.94      raeburn   997:     if ($currentauth !~ /^(unix|internal):/) {
                    998:         if ($caller eq 'reset_by_email') {
1.99    ! www       999:             &passwordchanger($r,"<p>\n<span class='LC_error'>".
        !          1000:                              &mt("Authentication type for this user can not be changed by this mechanism").
        !          1001:                              "</span>\n</p>",
1.94      raeburn  1002:                               $caller,$mailtoken);
                   1003:             return 1;
                   1004:         } else {
                   1005:             return;
                   1006:         }
                   1007:     }
1.3       matthew  1008:     #
1.59      albertel 1009:     my $currentpass = $env{'form.currentpass'}; 
                   1010:     my $newpass1    = $env{'form.newpass_1'}; 
                   1011:     my $newpass2    = $env{'form.newpass_2'};
                   1012:     my $logtoken    = $env{'form.logtoken'};
1.3       matthew  1013:     # Check for empty data 
1.4       matthew  1014:     unless (defined($currentpass) && 
                   1015: 	    defined($newpass1)    && 
                   1016: 	    defined($newpass2)    ){
1.99    ! www      1017: 	&passwordchanger($r,"<p>\n<span class='LC_error'>".
        !          1018: 			 &mt("One or more password fields were blank").
        !          1019:                          "</span>\n</p>",$caller,$mailtoken);
1.3       matthew  1020: 	return;
                   1021:     }
1.16      albertel 1022:     # Get the keys
                   1023:     my $lonhost = $r->dir_config('lonHostID');
1.3       matthew  1024:     my $tmpinfo = Apache::lonnet::reply('tmpget:'.$logtoken,$lonhost);
                   1025:     if (($tmpinfo=~/^error/) || ($tmpinfo eq 'con_lost')) {
1.4       matthew  1026:         # I do not a have a better idea about how to handle this
1.94      raeburn  1027:         my $tryagain_text = &mt('Please log out and try again.');
                   1028:         if ($caller eq 'reset_by_email') {
                   1029:             $tryagain_text = &mt('Please try again later.');
                   1030:         }
1.99    ! www      1031:         my $unable=&mt("Unable to retrieve stored token for password decryption");
1.3       matthew  1032: 	$r->print(<<ENDERROR);
                   1033: <p>
1.99    ! www      1034: <span class="LC_error">$unable.  $tryagain_text</span>
1.3       matthew  1035: </p>
                   1036: ENDERROR
1.4       matthew  1037:         # Probably should log an error here
1.75      albertel 1038:         return 1;
1.3       matthew  1039:     }
                   1040:     my ($ckey,$n1key,$n2key)=split(/&/,$tmpinfo);
1.4       matthew  1041:     # 
1.17      matthew  1042:     $currentpass = &des_decrypt($ckey ,$currentpass);
                   1043:     $newpass1    = &des_decrypt($n1key,$newpass1);
                   1044:     $newpass2    = &des_decrypt($n2key,$newpass2);
1.94      raeburn  1045:     #
                   1046:     if ($caller eq 'reset_by_email') {
                   1047:         my %data = &Apache::lonnet::tmpget($mailtoken);
                   1048:         if ($currentpass ne $data{'temppasswd'}) {
                   1049:             &passwordchanger($r,
1.99    ! www      1050:                          '<span class="LC_error">'.
        !          1051:                          &mt('Could not verify current authentication').'.  '.
        !          1052:                          &mt('Please try again').'.</span>',$caller,$mailtoken);
1.94      raeburn  1053:             return 1;
                   1054:         }
                   1055:     } 
1.3       matthew  1056:     if ($newpass1 ne $newpass2) {
1.4       matthew  1057: 	&passwordchanger($r,
1.99    ! www      1058: 			 '<span class="LC_error">'.
        !          1059: 			 &mt('The new passwords you entered do not match').'.  '.
        !          1060: 			 &mt('Please try again').'.</span>',$caller,$mailtoken);
1.75      albertel 1061: 	return 1;
1.4       matthew  1062:     }
                   1063:     if (length($newpass1) < 7) {
                   1064: 	&passwordchanger($r,
1.99    ! www      1065: 			 '<span class="LC_error">'.
        !          1066: 			 &mt('Passwords must be a minimum of 7 characters long').'.  '.
        !          1067: 			 &mt('Please try again').'</span>.',$caller,$mailtoken);
1.75      albertel 1068: 	return 1;
1.3       matthew  1069:     }
1.4       matthew  1070:     #
                   1071:     # Check for bad characters
                   1072:     my $badpassword = 0;
                   1073:     foreach (split(//,$newpass1)) {
                   1074: 	$badpassword = 1 if ((ord($_)<32)||(ord($_)>126));
                   1075:     }
                   1076:     if ($badpassword) {
                   1077: 	# I can't figure out how to enter bad characters on my browser.
1.99    ! www      1078: 	my $errormessage ='<span class="LC_error">'.
        !          1079:            &mt('The password you entered contained illegal characters').'.<br />'.
        !          1080:            &mt('Valid characters are').(<<"ENDERROR");
        !          1081: : space and <br />
1.4       matthew  1082: <pre>
                   1083: !&quot;\#$%&amp;\'()*+,-./0123456789:;&lt;=&gt;?\@
                   1084: ABCDEFGHIJKLMNOPQRSTUVWXYZ[\]^_\`abcdefghijklmnopqrstuvwxyz{|}~
1.99    ! www      1085: </pre></span>
1.4       matthew  1086: ENDERROR
1.94      raeburn  1087:         &passwordchanger($r,$errormessage,$caller,$mailtoken);
                   1088:         return 1;
1.4       matthew  1089:     }
                   1090:     # 
                   1091:     # Change the password (finally)
                   1092:     my $result = &Apache::lonnet::changepass
1.94      raeburn  1093: 	($user,$domain,$currentpass,$newpass1,$homeserver,$caller);
1.4       matthew  1094:     # Inform the user the password has (not?) been changed
                   1095:     if ($result =~ /^ok$/) {
1.99    ! www      1096: 	$r->print("<h3>".&mt('The password for [_1] was successfully changed',$user)."</h3>");
1.4       matthew  1097:     } else {
                   1098: 	# error error: run in circles, scream and shout
1.99    ! www      1099:         $r->print("<h3><span class='LC_error'>".&mt("The password for [_1] was not changed",$user)."</span></h3>".
        !          1100:                   &mt('Please make sure your old password was entered correctly').'.');
1.75      albertel 1101:         return 1;
1.4       matthew  1102:     }
                   1103:     return;
1.3       matthew  1104: }
                   1105: 
1.42      raeburn  1106: ################################################################
                   1107: #            discussion display subroutines 
                   1108: ################################################################
                   1109: sub discussionchanger {
                   1110:     my $r = shift;
1.59      albertel 1111:     my $user       = $env{'user.name'};
                   1112:     my $domain     = $env{'user.domain'};
1.42      raeburn  1113:     my %userenv = &Apache::lonnet::get
1.43      raeburn  1114:         ('environment',['discdisplay','discmarkread']);
                   1115:     my $discdisp = 'allposts';
                   1116:     my $discmark = 'onmark';
                   1117: 
                   1118:     if (defined($userenv{'discdisplay'})) {
                   1119:         unless ($userenv{'discdisplay'} eq '') { 
                   1120:             $discdisp = $userenv{'discdisplay'};
                   1121:         }
                   1122:     }
                   1123:     if (defined($userenv{'discmarkread'})) {
                   1124:         unless ($userenv{'discdisplay'} eq '') { 
                   1125:             $discmark = $userenv{'discmarkread'};
                   1126:         }
                   1127:     }
                   1128: 
                   1129:     my $newdisp = 'unread';
                   1130:     my $newmark = 'ondisp';
                   1131: 
                   1132:     my $function = &Apache::loncommon::get_users_function();
                   1133:     my $color = &Apache::loncommon::designparm($function.'.tabbg',
1.59      albertel 1134:                                                     $env{'user.domain'});
1.43      raeburn  1135:     my %lt = &Apache::lonlocal::texthash(
                   1136:         'pref' => 'Display Preference',
                   1137:         'curr' => 'Current setting ',
                   1138:         'actn' => 'Action',
                   1139:         'sdpf' => 'Set display preferences for discussion posts for both bulletin boards and individual resources in all your courses.',
                   1140:         'prca' => 'Preferences can be set that determine',
                   1141:         'whpo' => 'Which posts are displayed when you display a bulletin board or resource, and',
                   1142:         'unwh' => 'Under what circumstances posts are identfied as "New"',
                   1143:         'allposts' => 'All posts',
                   1144:         'unread' => 'New posts only',
                   1145:         'ondisp' => 'Once displayed',
                   1146:         'onmark' => 'Once marked as read',
                   1147:         'disa' => 'Posts displayed?',
                   1148:         'npmr' => 'New posts cease to be identified as "New"?',
                   1149:         'thde'  => 'The preferences you set here can be overridden within each individual discussion.',
                   1150:         'chgt' => 'Change to '
                   1151:     );
                   1152:     my $dispchange = $lt{'unread'};
                   1153:     my $markchange = $lt{'ondisp'};
                   1154:     my $currdisp = $lt{'allposts'};
                   1155:     my $currmark = $lt{'onmark'};
                   1156: 
                   1157:     if ($discdisp eq 'unread') {
                   1158:         $dispchange = $lt{'allposts'};
                   1159:         $currdisp = $lt{'unread'};
                   1160:         $newdisp = 'allposts';
                   1161:     }
                   1162: 
                   1163:     if ($discmark eq 'ondisp') {
                   1164:         $markchange = $lt{'onmark'};
                   1165:         $currmark = $lt{'ondisp'};
                   1166:         $newmark = 'onmark';
1.42      raeburn  1167:     }
1.43      raeburn  1168:     
                   1169:     $r->print(<<"END");
1.88      albertel 1170: <form name="prefs" action="/adm/preferences" method="post">
1.42      raeburn  1171: <input type="hidden" name="action" value="verify_and_change_discussion" />
                   1172: <br />
1.87      albertel 1173: $lt{'sdpf'}<br /> $lt{'prca'}  <ol><li>$lt{'whpo'}</li><li>$lt{'unwh'}</li></ol> 
1.43      raeburn  1174: <br />
                   1175: <br />
1.82      albertel 1176: END
                   1177:     $r->print(&Apache::loncommon::start_data_table());
                   1178:     $r->print(<<"END");
                   1179:        <tr>
                   1180:         <th>$lt{'pref'}</th>
                   1181:         <th>$lt{'curr'}</th>
                   1182:         <th>$lt{'actn'}?</th>
1.43      raeburn  1183:        </tr>
1.82      albertel 1184: END
                   1185:     $r->print(&Apache::loncommon::start_data_table_row());
                   1186:     $r->print(<<"END");
1.43      raeburn  1187:        <td>$lt{'disa'}</td>
                   1188:        <td>$lt{$discdisp}</td>
1.82      albertel 1189:        <td><label><input type="checkbox" name="discdisp" /><input type="hidden" name="newdisp" value="$newdisp" />&nbsp;$lt{'chgt'} "$dispchange"</label></td>
                   1190: END
                   1191:     $r->print(&Apache::loncommon::end_data_table_row().
                   1192: 	      &Apache::loncommon::start_data_table_row());
                   1193:     $r->print(<<"END");
1.43      raeburn  1194:        <td>$lt{'npmr'}</td>
                   1195:        <td>$lt{$discmark}</td>
1.82      albertel 1196:        <td><label><input type="checkbox" name="discmark" /><input type="hidden" name="newmark" value="$newmark" />&nbsp;$lt{'chgt'} "$markchange"</label></td>
1.43      raeburn  1197:       </tr>
1.82      albertel 1198: END
                   1199:     $r->print(&Apache::loncommon::end_data_table_row().
                   1200: 	      &Apache::loncommon::end_data_table());
                   1201:     $r->print(<<"END");
1.43      raeburn  1202: <br />
                   1203: <br />
                   1204: <input type="submit" name="sub" value="Store Changes" />
                   1205: <br />
                   1206: <br />
                   1207: Note: $lt{'thde'}
                   1208: </form>
                   1209: END
1.42      raeburn  1210: }
                   1211:                                                                                                                 
                   1212: sub verify_and_change_discussion {
                   1213:     my $r = shift;
1.59      albertel 1214:     my $user     = $env{'user.name'};
                   1215:     my $domain   = $env{'user.domain'};
1.42      raeburn  1216:     my $message='';
1.59      albertel 1217:     if (defined($env{'form.discdisp'}) ) {
                   1218:         my $newdisp  = $env{'form.newdisp'};
1.43      raeburn  1219:         if ($newdisp eq 'unread') {
1.87      albertel 1220:             $message .='In discussions: only new posts will be displayed.<br />';
1.43      raeburn  1221:             &Apache::lonnet::put('environment',{'discdisplay' => $newdisp});
                   1222:             &Apache::lonnet::appenv('environment.discdisplay' => $newdisp);
                   1223:         } else {
1.87      albertel 1224:             $message .= 'In discussions: all posts will be displayed.<br />';
1.43      raeburn  1225:             &Apache::lonnet::del('environment',['discdisplay']);
                   1226:             &Apache::lonnet::delenv('environment\.discdisplay');
                   1227:         }
                   1228:     }
1.59      albertel 1229:     if (defined($env{'form.discmark'}) ) {
                   1230:         my $newmark = $env{'form.newmark'};
1.43      raeburn  1231:         if ($newmark eq 'ondisp') {
1.87      albertel 1232:            $message.='In discussions: new posts will be cease to be identified as "new" after display.<br />';
1.43      raeburn  1233:             &Apache::lonnet::put('environment',{'discmarkread' => $newmark});
                   1234:             &Apache::lonnet::appenv('environment.discmarkread' => $newmark);
                   1235:         } else {
1.87      albertel 1236:             $message.='In discussions: posts will be identified as "new" until marked as read by the reader.<br />';
1.43      raeburn  1237:             &Apache::lonnet::del('environment',['discmarkread']);
                   1238:             &Apache::lonnet::delenv('environment\.discmarkread');
                   1239:         }
1.42      raeburn  1240:     }
                   1241:     $r->print(<<ENDVCSCREEN);
                   1242: $message
                   1243: ENDVCSCREEN
                   1244: }
                   1245: 
1.63      raeburn  1246: ################################################################
                   1247: # Subroutines for page display on course access (Course Coordinators)
                   1248: ################################################################
                   1249: sub coursedisplaychanger {
                   1250:     my $r = shift;
                   1251:     my $user       = $env{'user.name'};
                   1252:     my $domain     = $env{'user.domain'};
1.66      albertel 1253:     my %userenv = &Apache::lonnet::get('environment',['course_init_display']);
1.71      raeburn  1254:     my $currvalue = 'whatsnew';
1.73      albertel 1255:     my $firstselect = '';
                   1256:     my $whatsnewselect = 'checked="checked"';
1.71      raeburn  1257:     if (exists($userenv{'course_init_display'})) {
                   1258:         if ($userenv{'course_init_display'} eq 'firstres') {
                   1259:             $currvalue = 'firstres';
1.73      albertel 1260:             $firstselect = 'checked="checked"';
                   1261: 	    $whatsnewselect = '';
1.71      raeburn  1262:         }
1.63      raeburn  1263:     }
1.71      raeburn  1264:     my %pagenames = (
                   1265:                        firstres => 'First resource',
                   1266:                        whatsnew => "What's new page",
                   1267:                     );
1.70      raeburn  1268:     my $whatsnew_off=&mt('Display the [_1] in the course.','<b>first resource</b>');
                   1269:     my $whatsnew_on=&mt('Display the "[_1]" page - a summary of items in the course which require attention.',"<b>What's New</b>");
1.63      raeburn  1270: 
1.71      raeburn  1271:     $r->print('<br /><b>'.&mt('Set the default page to be displayed when you select a course role').'</b>&nbsp;'.&mt('(Currently: [_1])',$pagenames{$currvalue}).'<br />'.&mt('The global user preference you set for your courses can be overridden in an individual course by setting a course specific setting via the "[_1]" page in the course',"<i>What's New</i>").'<br /><br />');
1.63      raeburn  1272:     $r->print(<<ENDLSCREEN);
1.88      albertel 1273: <form name="prefs" action="/adm/preferences" method="post">
1.63      raeburn  1274: <input type="hidden" name="action" value="verify_and_change_coursepage" />
1.72      albertel 1275: <br />
1.65      albertel 1276: <label><input type="radio" name="newdisp" value="firstres" $firstselect /> $whatsnew_off</label><br />
1.70      raeburn  1277: <label><input type="radio" name="newdisp" value="whatsnew" $whatsnewselect /> $whatsnew_on</label><input type="hidden" name="refpage" value="$env{'form.refpage'}" />
1.63      raeburn  1278: ENDLSCREEN
1.70      raeburn  1279:     $r->print('<br /><br /><input type="submit" value="'.&mt('Change').'" />
1.63      raeburn  1280: </form>');
                   1281: }
                   1282: 
                   1283: sub verify_and_change_coursepage {
                   1284:     my $r = shift;
                   1285:     my $message='';
                   1286:     my %lt = &Apache::lonlocal::texthash(
1.70      raeburn  1287:         'defs' => 'Default now set',
1.71      raeburn  1288:         'when' => 'when you select a course role from the roles screen',
1.63      raeburn  1289:         'ywbt' => 'you will be taken to the start of the course.',
                   1290:         'apwb' => 'a page will be displayed that lists items in the course that may require action from you.',
                   1291:         'gtts' => 'Go to the start of the course',
1.70      raeburn  1292:         'dasp' => "Display the What's New page listing course action items", 
1.63      raeburn  1293:     );
                   1294:     my $newdisp  = $env{'form.newdisp'};
1.70      raeburn  1295:     $message = '<b>'.$lt{'defs'}.'</b>: '.$lt{'when'}.', ';
1.63      raeburn  1296:     if ($newdisp eq 'firstres') {
1.87      albertel 1297:         $message .= $lt{'ywbt'}.'<br />';
1.63      raeburn  1298:         &Apache::lonnet::put('environment',{'course_init_display' => $newdisp});
                   1299:         &Apache::lonnet::appenv('environment.course_init_display' => $newdisp);
                   1300:     } else {
1.87      albertel 1301:         $message .= $lt{'apwb'}.'<br />';
1.63      raeburn  1302:         &Apache::lonnet::del('environment',['course_init_display']);
                   1303:         &Apache::lonnet::delenv('environment\.course_init_display');
                   1304:     }
1.70      raeburn  1305:     my $refpage = $env{'form.refpage'};
1.63      raeburn  1306:     if (($env{'request.course.fn'}) && ($env{'request.course.id'})) {
                   1307:         if ($newdisp eq 'firstres') {
                   1308:             my $cdom = $env{'course.'.$env{'request.course.id'}.'.domain'};
                   1309:             my $cnum = $env{'course.'.$env{'request.course.id'}.'.num'}; 
                   1310:             my ($furl,$ferr)=
                   1311:                 &Apache::lonuserstate::readmap($cdom.'/'.$cnum);
                   1312:             $message .= '<br /><font size="+1"><a href="'.$furl.'">'.$lt{'gtts'}.' <i>'.&mt('now').'</i></a></font>';
                   1313:         } else {
1.70      raeburn  1314:             $message .= '<br /><font size="+1"><a href="/adm/whatsnew?refpage='.
                   1315:                         $refpage.'">'.$lt{'dasp'}.'</a></font>';
1.63      raeburn  1316:         }
                   1317:     }
                   1318:     $r->print(<<ENDVCSCREEN);
                   1319: $message
                   1320: <br /><br />
                   1321: ENDVCSCREEN
                   1322: }
                   1323: 
                   1324: 
1.4       matthew  1325: ######################################################
                   1326: #            other handler subroutines               #
                   1327: ######################################################
                   1328: 
1.3       matthew  1329: ################################################################
                   1330: #                          Main handler                        #
                   1331: ################################################################
1.1       www      1332: sub handler {
                   1333:     my $r = shift;
1.59      albertel 1334:     my $user = $env{'user.name'};
                   1335:     my $domain = $env{'user.domain'};
1.31      www      1336:     &Apache::loncommon::content_type($r,'text/html');
1.4       matthew  1337:     # Some pages contain DES keys and should not be cached.
                   1338:     &Apache::loncommon::no_cache($r);
1.1       www      1339:     $r->send_http_header;
                   1340:     return OK if $r->header_only;
1.9       matthew  1341:     #
1.35      matthew  1342:     &Apache::loncommon::get_unprocessed_cgi($ENV{'QUERY_STRING'},
1.70      raeburn  1343:                                    ['action','wysiwyg','returnurl','refpage']);
1.35      matthew  1344:     #
                   1345:     &Apache::lonhtmlcommon::clear_breadcrumbs();
                   1346:     &Apache::lonhtmlcommon::add_breadcrumb
                   1347:         ({href => '/adm/preferences',
                   1348:           text => 'Set User Preferences'});
                   1349: 
                   1350:     my @Options;
                   1351:     # Determine current authentication method
                   1352:     my $currentauth=&Apache::lonnet::queryauthenticate($user,$domain);
                   1353:     if ($currentauth =~ /^(unix|internal):/) {
                   1354:         push (@Options,({ action   => 'changepass',
1.40      www      1355:                           linktext => 'Change Password',
1.35      matthew  1356:                           href     => '/adm/preferences',
                   1357:                           help     => 'Change_Password',
                   1358:                           subroutine => \&passwordchanger,
                   1359:                           breadcrumb => 
                   1360:                               { href => '/adm/preferences?action=changepass',
                   1361:                                 text => 'Change Password'},
                   1362:                           },
                   1363:                         { action => 'verify_and_change_pass',
                   1364:                           subroutine => \&verify_and_change_password,
                   1365:                           breadcrumb => 
                   1366:                               { href =>'/adm/preferences?action=changepass',
                   1367:                                 text => 'Change Password'},
1.75      albertel 1368:                           printmenu => 'not_on_error',
1.35      matthew  1369:                           }));
                   1370:     }
                   1371:     push (@Options,({ action   => 'changescreenname',
                   1372:                       linktext => 'Change Screen Name',
                   1373:                       href     => '/adm/preferences',
                   1374:                       help     => 'Prefs_Screen_Name_Nickname',
                   1375:                       subroutine => \&screennamechanger,
                   1376:                       breadcrumb => 
                   1377:                           { href => '/adm/preferences?action=changescreenname',
                   1378:                             text => 'Change Screen Name'},
                   1379:                       },
                   1380:                     { action   => 'verify_and_change_screenname',
                   1381:                       subroutine => \&verify_and_change_screenname,
                   1382:                       breadcrumb => 
                   1383:                           { href => '/adm/preferences?action=changescreenname',
                   1384:                             text => 'Change Screen Name'},
                   1385:                       printmenu => 'yes',
                   1386:                       }));
                   1387: 
                   1388:     push (@Options,({ action   => 'changemsgforward',
1.97      raeburn  1389:                       linktext => 'Change Message Forwarding and Notification Email Addresses',
1.35      matthew  1390:                       href     => '/adm/preferences',
                   1391:                       help     => 'Prefs_Forwarding',
                   1392:                       breadcrumb => 
                   1393:                           { href => '/adm/preferences?action=changemsgforward',
                   1394:                             text => 'Change Message Forwarding'},
                   1395:                       subroutine => \&msgforwardchanger,
                   1396:                       },
                   1397:                     { action => 'verify_and_change_msgforward',
                   1398:                       breadcrumb => 
                   1399:                           { href => '/adm/preferences?action=changemsgforward',
                   1400:                             text => 'Change Message Forwarding'},
                   1401:                       printmenu => 'yes',
                   1402:                       subroutine => \&verify_and_change_msgforward }));
                   1403:     my $aboutmeaction=
1.59      albertel 1404:         '/adm/'.$env{'user.domain'}.'/'.$env{'user.name'}.'/aboutme';
1.35      matthew  1405:     push (@Options,{ action => 'none', 
                   1406:                      linktext =>
1.41      www      1407:                          q{Edit the 'About Me' Personal Information Screen},
1.45      www      1408: 		     help => 'Prefs_About_Me',
1.35      matthew  1409:                      href => $aboutmeaction});
                   1410:     push (@Options,({ action => 'changecolors',
                   1411:                       linktext => 'Change Color Scheme',
                   1412:                       href => '/adm/preferences',
                   1413:                       help => 'Change_Colors',
                   1414:                       breadcrumb => 
                   1415:                           { href => '/adm/preferences?action=changecolors',
                   1416:                             text => 'Change Colors'},
                   1417:                       subroutine => \&colorschanger,
                   1418:                   },
                   1419:                     { action => 'verify_and_change_colors',
                   1420:                       breadcrumb => 
                   1421:                           { href => '/adm/preferences?action=changecolors',
                   1422:                             text => 'Change Colors'},
                   1423:                       printmenu => 'yes',
                   1424:                       subroutine => \&verify_and_change_colors,
                   1425:                       }));
                   1426:     push (@Options,({ action => 'changelanguages',
1.39      www      1427:                       linktext => 'Change Language Preferences',
1.35      matthew  1428:                       href => '/adm/preferences',
1.45      www      1429: 		      help => 'Prefs_Language',
1.35      matthew  1430:                       breadcrumb=>
                   1431:                           { href => '/adm/preferences?action=changelanguages',
                   1432:                             text => 'Change Language'},
                   1433:                       subroutine =>  \&languagechanger,
                   1434:                   },
                   1435:                     { action => 'verify_and_change_languages',
                   1436:                       breadcrumb=>
                   1437:                           {href => '/adm/preferences?action=changelanguages',
                   1438:                            text => 'Change Language'},
                   1439:                       printmenu => 'yes',
                   1440:                       subroutine=>\&verify_and_change_languages, }
                   1441:                     ));
1.44      www      1442:     push (@Options,({ action => 'changewysiwyg',
                   1443:                       linktext => 'Change WYSIWYG Editor Preferences',
                   1444:                       href => '/adm/preferences',
                   1445:                       breadcrumb => 
                   1446:                             { href => '/adm/preferences?action=changewysiwyg',
                   1447:                               text => 'Change WYSIWYG Preferences'},
                   1448:                       subroutine => \&wysiwygchanger,
                   1449:                   },
                   1450:                     { action => 'set_wysiwyg',
                   1451:                       breadcrumb =>
                   1452:                           { href => '/adm/preferences?action=changewysiwyg',
                   1453:                             text => 'Change WYSIWYG Preferences'},
                   1454:                       printmenu => 'yes',
                   1455:                       subroutine => \&verify_and_change_wysiwyg, }
                   1456:                     ));
1.42      raeburn  1457:     push (@Options,({ action => 'changediscussions',
                   1458:                       linktext => 'Change Discussion Display Preferences',
                   1459:                       href => '/adm/preferences',
1.46      raeburn  1460:                       help => 'Change_Discussion_Display',
1.42      raeburn  1461:                       breadcrumb => 
                   1462:                             { href => '/adm/preferences?action=changediscussions',
1.43      raeburn  1463:                               text => 'Change Discussion Preferences'},
1.42      raeburn  1464:                       subroutine => \&discussionchanger,
                   1465:                   },
                   1466:                     { action => 'verify_and_change_discussion',
                   1467:                       breadcrumb =>
                   1468:                           { href => '/adm/preferences?action=changediscussions',
1.43      raeburn  1469:                             text => 'Change Discussion Preferences'},
1.42      raeburn  1470:                       printmenu => 'yes',
                   1471:                       subroutine => \&verify_and_change_discussion, }
                   1472:                     ));
1.96      albertel 1473: 
                   1474:     my $role = ($env{'user.adv'} ? 'Roles' : 'Course');
1.50      albertel 1475:     push (@Options,({ action   => 'changerolespref',
1.96      albertel 1476:                       linktext => 'Change '.$role.' Page Preferences',
1.50      albertel 1477:                       href     => '/adm/preferences',
                   1478:                       subroutine => \&rolesprefchanger,
                   1479:                       breadcrumb =>
                   1480:                           { href => '/adm/preferences?action=changerolespref',
1.96      albertel 1481:                             text => 'Change '.$role.' Page Pref'},
1.50      albertel 1482:                       },
                   1483:                     { action   => 'verify_and_change_rolespref',
                   1484:                       subroutine => \&verify_and_change_rolespref,
                   1485:                       breadcrumb =>
                   1486:                           { href => '/adm/preferences?action=changerolespref',
1.96      albertel 1487:                             text => 'Change '.$role.' Page Preferences'},
1.50      albertel 1488:                       printmenu => 'yes',
                   1489:                       }));
                   1490: 
1.54      albertel 1491:     push (@Options,({ action   => 'changetexenginepref',
                   1492:                       linktext => 'Change How Math Equations Are Displayed',
                   1493:                       href     => '/adm/preferences',
                   1494:                       subroutine => \&texenginechanger,
                   1495:                       breadcrumb =>
                   1496:                           { href => '/adm/preferences?action=changetexenginepref',
                   1497:                             text => 'Change Math Pref'},
                   1498:                       },
                   1499:                     { action   => 'verify_and_change_texengine',
                   1500:                       subroutine => \&verify_and_change_texengine,
                   1501:                       breadcrumb =>
                   1502:                           { href => '/adm/preferences?action=changetexenginepref',
                   1503:                             text => 'Change Math Preferences'},
                   1504:                       printmenu => 'yes',
                   1505:                       }));
1.85      albertel 1506: 
                   1507:     if ($env{'environment.remote'} eq 'off') {
                   1508: 	push (@Options,({ action => 'launch',
                   1509: 			  linktext => 'Launch Remote Control',
                   1510: 			  href => '/adm/remote?url=/adm/preferences',
                   1511: 		      }));
                   1512:     } else {
                   1513: 	push (@Options,({ action => 'collapse',
                   1514: 			  linktext => 'Collapse Remote Control',
                   1515: 			  href => '/adm/remote?url=/adm/preferences',
                   1516: 		      }));
                   1517:     }
                   1518: 
1.98      www      1519:     push (@Options,({ action   => 'changeicons',
                   1520:                       linktext => 'Change How Main Menu is Displayed',
                   1521:                       href     => '/adm/preferences',
                   1522:                       subroutine => \&iconchanger,
                   1523:                       breadcrumb =>
                   1524:                           { href => '/adm/preferences?action=changeicons',
                   1525:                             text => 'Change Main Menu'},
                   1526:                       },
                   1527:                     { action   => 'verify_and_change_icons',
                   1528:                       subroutine => \&verify_and_change_icons,
                   1529:                       breadcrumb =>
                   1530:                           { href => '/adm/preferences?action=changeicons',
                   1531:                             text => 'Change Main Menu'},
                   1532:                       printmenu => 'yes',
                   1533:                       }));
                   1534: 
1.74      albertel 1535:     if (&Apache::lonnet::allowed('whn',$env{'request.course.id'})
                   1536: 	|| &Apache::lonnet::allowed('whn',$env{'request.course.id'}.'/'
                   1537: 				    .$env{'request.course.sec'})) {
1.63      raeburn  1538:         push (@Options,({ action => 'changecourseinit',
                   1539:                           linktext => 'Change Course Initialization Preference',
                   1540:                           href => '/adm/preferences',
                   1541:                           subroutine => \&coursedisplaychanger,
                   1542:                           breadcrumb =>
                   1543:                               { href => '/adm/preferences?action=changecourseinit',
                   1544:                                 text => 'Change Course Init. Pref.'},
                   1545:                           },
                   1546:                         { action => 'verify_and_change_coursepage',
                   1547:                           breadcrumb =>
                   1548:                           { href => '/adm/preferences?action=changecourseinit',                               text => 'Change Course Initialization Preference'},
                   1549:                         printmenu => 'yes',
                   1550:                         subroutine => \&verify_and_change_coursepage,
                   1551:                        }));
                   1552:     }
1.50      albertel 1553: 
1.62      raeburn  1554:     if ($env{'user.name'} =~ /^(albertel|fox|foxr|koretemey|korte|hallmat3|turtle|raeburn)$/) {
1.35      matthew  1555:         push (@Options,({ action => 'debugtoggle',
                   1556:                           printmenu => 'yes',
                   1557:                           subroutine => \&toggle_debug,
                   1558:                           }));
                   1559:     }
1.76      albertel 1560: 
                   1561:     $r->print(&Apache::loncommon::start_page('Change Preferences'));
                   1562: 
1.35      matthew  1563:     my $call = undef;
1.48      albertel 1564:     my $help = undef;
1.35      matthew  1565:     my $printmenu = 'yes';
                   1566:     foreach my $option (@Options) {
1.59      albertel 1567:         if ($option->{'action'} eq $env{'form.action'}) {
1.35      matthew  1568:             $call = $option->{'subroutine'};
                   1569:             $printmenu = $option->{'printmenu'};
                   1570:             if (exists($option->{'breadcrumb'})) {
                   1571:                 &Apache::lonhtmlcommon::add_breadcrumb
                   1572:                     ($option->{'breadcrumb'});
                   1573:             }
1.48      albertel 1574: 	    $help=$option->{'help'};
1.35      matthew  1575:         }
                   1576:     }
1.81      albertel 1577:     $r->print(&Apache::lonhtmlcommon::breadcrumbs('Change Preferences',$help));
1.75      albertel 1578:     my $error;
1.35      matthew  1579:     if (defined($call)) {
1.75      albertel 1580:         $error = $call->($r);
1.35      matthew  1581:     }
1.75      albertel 1582:     if ( ( ($printmenu eq 'yes')
                   1583: 	   || ($printmenu eq 'not_on_error' && !$error) )
                   1584: 	 && (!$env{'form.returnurl'})) {
1.35      matthew  1585:         my $optionlist = '<table cellpadding="5">';
1.59      albertel 1586:         if ($env{'user.name'} =~ 
1.62      raeburn  1587:                          /^(albertel|kortemey|fox|foxr|korte|hallmat3|turtle|raeburn)$/
1.35      matthew  1588:             ) {
                   1589:             push (@Options,({ action => 'debugtoggle',
                   1590:                               linktext => 'Toggle Debug Messages',
                   1591:                               text => 'Current Debug status is -'.
1.59      albertel 1592:                                   $env{'user.debug'}.'-.',
1.35      matthew  1593:                               href => '/adm/preferences',
                   1594:                               printmenu => 'yes',
                   1595:                               subroutine => \&toggle_debug,
                   1596:                               }));
                   1597:         }
                   1598:         foreach my $option(@Options) {
                   1599:             my $optiontext = '';
                   1600:             if (exists($option->{'href'})) {
1.85      albertel 1601: 		$option->{'href_args'}{'action'}=$option->{'action'};
                   1602: 		$optiontext .= 
                   1603:                     '<a href="'.&add_get_param($option->{'href'},
                   1604: 					       $option->{'href_args'}).'">'.
1.47      albertel 1605:                     &mt($option->{'linktext'}).'</a>';
1.35      matthew  1606:             }
                   1607:             if (exists($option->{'text'})) {
1.47      albertel 1608:                 $optiontext .= ' '.&mt($option->{'text'});
1.35      matthew  1609:             }
                   1610:             if ($optiontext ne '') {
                   1611:                 $optiontext = '<font size="+1">'.$optiontext.'</font>'; 
                   1612:                 my $helplink = '&nbsp;';
                   1613:                 if (exists($option->{'help'})) {
                   1614:                     $helplink = &Apache::loncommon::help_open_topic
                   1615:                                                     ($option->{'help'});
                   1616:                 }
                   1617:                 $optionlist .= '<tr>'.
                   1618:                     '<td>'.$helplink.'</td>'.
                   1619:                     '<td>'.$optiontext.'</td>'.
                   1620:                     '</tr>';
                   1621:             }
1.13      www      1622:         }
1.35      matthew  1623:         $optionlist .= '</table>';
                   1624:         $r->print($optionlist);
1.59      albertel 1625:     } elsif ($env{'form.returnurl'}) {
                   1626: 	$r->print('<br /><a href="'.$env{'form.returnurl'}.'"><font size="+1">'.
1.44      www      1627: 		  &mt('Return').'</font></a>');
1.3       matthew  1628:     }
1.76      albertel 1629:     $r->print(&Apache::loncommon::end_page());
1.1       www      1630:     return OK;
1.35      matthew  1631: }
                   1632: 
                   1633: sub toggle_debug {
1.59      albertel 1634:     if ($env{'user.debug'}) {
1.35      matthew  1635:         &Apache::lonnet::delenv('user\.debug');
                   1636:     } else {
                   1637:         &Apache::lonnet::appenv('user.debug' => 1);
                   1638:     }
1.13      www      1639: }
1.1       www      1640: 
                   1641: 1;
                   1642: __END__

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