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

1.1       www         1: # The LearningOnline Network
                      2: # Preferences
                      3: #
1.108   ! www         4: # $Id: lonpreferences.pm,v 1.107 2007/07/05 21:37:38 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='';
1.100     www       529:     my $onlyicon='';
1.98      www       530:     if ($userenv{'icons'} eq 'classic') {
                    531:        $classic='checked="checked"';
                    532:        $iconic='';
                    533:     }
1.100     www       534:     if ($userenv{'icons'} eq 'iconsonly') {
                    535:        $onlyicon='checked="checked"';
                    536:        $iconic='';
                    537:     }
                    538:     my $useicons=&mt('Use icons and text');
                    539:     my $usebuttons=&mt('Use buttons and text');
                    540:     my $useicononly=&mt('Use icons only');
1.98      www       541:     my $change=&mt('Change');
                    542:     $r->print(<<ENDSCREEN);
                    543: <form name="prefs" action="/adm/preferences" method="post">
                    544: <input type="hidden" name="action" value="verify_and_change_icons" />
                    545: <label><input type="radio" name="menumode" value="iconic" $iconic /> $useicons</label><br />
                    546: <label><input type="radio" name="menumode" value="classic" $classic /> $usebuttons</label><br />
1.100     www       547: <label><input type="radio" name="menumode" value="iconsonly" $onlyicon /> $useicononly</label><br />
1.98      www       548: <input type="submit" value="$change" />
                    549: </form>
                    550: ENDSCREEN
                    551: }
                    552: 
                    553: sub verify_and_change_icons {
                    554:     my $r = shift;
                    555:     my $user       = $env{'user.name'};
                    556:     my $domain     = $env{'user.domain'};
                    557:     my $newicons  = $env{'form.menumode'};
                    558: 
                    559:     &Apache::lonnet::put('environment',{'icons' => $newicons});
                    560:     &Apache::lonnet::appenv('environment.icons' => $newicons);
                    561:     $r->print(&mt('Set menu mode to [_1].',$newicons));
                    562: }
                    563: 
                    564: ################################################################
1.105     www       565: #                     Clicker Subroutines                      #
                    566: ################################################################
                    567: 
                    568: sub clickerchanger {
                    569:     my $r = shift;
                    570:     my $user       = $env{'user.name'};
                    571:     my $domain     = $env{'user.domain'};
                    572:     my %userenv = &Apache::lonnet::get
                    573:         ('environment',['clickers']);
                    574:     my $clickers=$userenv{'clickers'};
                    575:     $clickers=~s/\,/\n/gs;
                    576:     my $text=&mt('Enter response device ("clicker") numbers');
                    577:     my $change=&mt('Register');
1.107     www       578:     my $helplink=&Apache::loncommon::help_open_topic('Clicker_Registration', 'Locating your clicker ID');
1.105     www       579:     $r->print(<<ENDSCREEN);
                    580: <form name="prefs" action="/adm/preferences" method="post">
                    581: <input type="hidden" name="action" value="verify_and_change_clicker" />
1.107     www       582: <label>$text $helplink<br />
1.108   ! www       583: <textarea name="clickers" rows="5" cols="20">$clickers</textarea>
1.105     www       584: </label>
                    585: <input type="submit" value="$change" />
                    586: </form>
                    587: ENDSCREEN
                    588: }
                    589: 
                    590: sub verify_and_change_clicker {
                    591:     my $r = shift;
                    592:     my $user       = $env{'user.name'};
                    593:     my $domain     = $env{'user.domain'};
                    594:     my $newclickers  = $env{'form.clickers'};
1.108   ! www       595:     $newclickers=~s/[^\w\:\-]+/\,/gs;
1.105     www       596:     $newclickers=~tr/a-z/A-Z/;
1.108   ! www       597:     $newclickers=~s/[\:\-]+/\-/g;
        !           598:     $newclickers=~s/\,+/\,/g;
1.105     www       599:     $newclickers=~s/^\,//;
                    600:     $newclickers=~s/\,$//;
                    601:     &Apache::lonnet::put('environment',{'clickers' => $newclickers});
                    602:     &Apache::lonnet::appenv('environment.clickers' => $newclickers);
                    603:     $r->print(&mt('Registering clickers: [_1]',$newclickers));
                    604: }
                    605: 
                    606: ################################################################
1.20      www       607: #         Message Forward                                      #
                    608: ################################################################
                    609: 
                    610: sub msgforwardchanger {
1.102     raeburn   611:     my ($r,$message) = @_;
1.59      albertel  612:     my $user       = $env{'user.name'};
                    613:     my $domain     = $env{'user.domain'};
1.102     raeburn   614:     my %userenv = &Apache::lonnet::get('environment',['msgforward','notification','critnotification','notifywithhtml']);
1.20      www       615:     my $msgforward=$userenv{'msgforward'};
1.102     raeburn   616:     my %lt = &Apache::lonlocal::texthash(
                    617:                                           all   => 'All',
                    618:                                           crit  => 'Critical only',
                    619:                                           reg   => 'Non-critical only',
                    620:                                           foad  => 'Forwarding Address(es)',
                    621:                                           mnot  => 'Message Notification Email Address(es)',
                    622:                                           chg   => 'Change',
1.104     raeburn   623:                                           email => 'The e-mail address entered in row ',
1.102     raeburn   624:                                           notv => 'is not a valid e-mail address',
1.103     raeburn   625:                                           toen => "To enter multiple addresses, enter one address at a time, click 'Change' and then add the next one", 
1.102     raeburn   626:                                           prme => 'Back to preferences menu',
                    627:                                         );
1.25      bowersj2  628:     my $forwardingHelp = Apache::loncommon::help_open_topic("Prefs_Forwarding",
                    629: 							    "What are forwarding ".
                    630: 							    "and notification ".
                    631: 							    "addresses");
1.27      bowersj2  632:     my $criticalMessageHelp = Apache::loncommon::help_open_topic("Course_Critical_Message",
                    633: 								 "What are critical messages");
1.102     raeburn   634:     my @allow_html = split(/,/,$userenv{'notifywithhtml'});
                    635:     my %allnot = &get_notifications(\%userenv);
                    636:     my $validatescript = &Apache::lonhtmlcommon::javascript_valid_email();
                    637:     my $jscript = qq|
                    638: <script type="text/javascript">
                    639: function validate() {
                    640:     for (var i=0; i<document.prefs.numnotify.value; i++) {
1.104     raeburn   641:         var checkaddress = 0;
1.102     raeburn   642:         var addr = document.prefs.elements['address_'+i].value;
1.104     raeburn   643:         var rownum = i+1;
1.102     raeburn   644:         if (i < document.prefs.numnotify.value-1) {
1.104     raeburn   645:             if (document.prefs.elements['modify_notify_'+i].checked) {
1.102     raeburn   646:                 checkaddress = 1;
1.104     raeburn   647:             }
1.102     raeburn   648:         } else {
                    649:             if (document.prefs.elements['add_notify_'+i].checked == true) { 
                    650:                 checkaddress = 1;
                    651:             }
                    652:         }
1.104     raeburn   653:         if (checkaddress == 1)  {
1.102     raeburn   654:             var addr = document.prefs.elements['address_'+i].value;
                    655:             if (validmail(document.prefs.elements['address_'+i]) == false) {
1.104     raeburn   656:                 var multimsg = '';
                    657:                 if (addr.indexOf(",") >= 0) {
                    658:                     multimsg = "\\n($lt{'toen'}).";
                    659:                 }
                    660:                 alert("$lt{'email'} "+rownum+": '"+addr+"' $lt{'notv'}."+multimsg);
1.102     raeburn   661:                 return;
                    662:             }
                    663:         }
                    664:     }
                    665:     document.prefs.submit();
                    666: }
1.104     raeburn   667: 
                    668: function address_changes (adnum) {
                    669:      if (!document.prefs.elements['del_notify_'+adnum].checked) { 
                    670:          document.prefs.elements['modify_notify_'+adnum].checked = true;
                    671:      }   
                    672: }
                    673: 
                    674: function new_address(adnum) {
                    675:      document.prefs.elements['add_notify_'+adnum].checked = true;
                    676: }
                    677: 
                    678: function delete_address(adnum) {
                    679:      if (document.prefs.elements['del_notify_'+adnum].checked) {
                    680:           document.prefs.elements['modify_notify_'+adnum].checked = false;
                    681:      }
                    682: }
                    683: 
                    684: function modify_address(adnum) {
                    685:     if (document.prefs.elements['modify_notify_'+adnum].checked) {
                    686:         document.prefs.elements['del_notify_'+adnum].checked = false;
                    687:     }
                    688: } 
                    689: 
1.102     raeburn   690: $validatescript
                    691: </script>
                    692: |;
1.20      www       693:     $r->print(<<ENDMSG);
1.102     raeburn   694: $jscript
                    695: $message
                    696: $forwardingHelp
1.88      albertel  697: <form name="prefs" action="/adm/preferences" method="post">
1.20      www       698: <input type="hidden" name="action" value="verify_and_change_msgforward" />
1.102     raeburn   699: $lt{'foad'} (<tt>user:domain,user:domain,...</tt>):
1.20      www       700: <input type="text" size="40" value="$msgforward" name="msgforward" /><hr />
1.102     raeburn   701: $criticalMessageHelp
                    702: $lt{'mnot'} (<tt>joe\@doe.com</tt>):<br />
                    703: ENDMSG
                    704:     my @sortforwards = sort (keys(%allnot));
                    705:     my $output = &Apache::loncommon::start_data_table().
                    706:                  &Apache::loncommon::start_data_table_header_row().
1.104     raeburn   707:                  '<th>&nbsp;</th>'.
1.102     raeburn   708:                  '<th>'.&mt('Action').'</th>'.
                    709:                  '<th>'.&mt('Notification address').'</th><th>'.
1.104     raeburn   710:                  &mt('Types of message to forward to this address').'</th><th>'.
                    711:                  &mt('Excerpt retains HTML tags in message').'</th>'.
1.102     raeburn   712:                  &Apache::loncommon::end_data_table_header_row();
                    713:     my $num = 0;
1.104     raeburn   714:     my $counter = 1;
1.102     raeburn   715:     foreach my $item (@sortforwards) {
                    716:         $output .= &Apache::loncommon::start_data_table_row().
1.104     raeburn   717:                    '<td><b>'.$counter.'</b></td>'.
                    718:                    '<td><span class="LC_nobreak"><label>'.
                    719:                    '<input type="checkbox" name="modify_notify_'.
                    720:                    $num.'" onclick="javscript:modify_address('."'$num'".')" />'.
                    721:                    &mt('Modify').'</label></span>&nbsp;&nbsp; '.
                    722:                    '<span class="LC_nobreak"><label>'.
                    723:                    '<input type="checkbox" name="del_notify_'.$num.
                    724:                    '" onclick="javscript:delete_address('."'$num'".')" />'.
                    725:                    &mt('Delete').'</label></span></td>'.
1.102     raeburn   726:                    '<td><input type="text" value="'.$item.'" name="address_'.
1.104     raeburn   727:                    $num.'" onFocus="javascript:address_changes('."'$num'".
                    728:                    ')" /></td><td>';
1.102     raeburn   729:         my %chk;
                    730:         if (defined($allnot{$item}{'crit'})) {
                    731:             if (defined($allnot{$item}{'reg'})) {
                    732:                 $chk{'all'} = 'checked="checked" ';
                    733:             } else {
                    734:                 $chk{'crit'} = 'checked="checked" ';
                    735:             }
                    736:         } else {
                    737:             $chk{'reg'} = 'checked="checked" ';
                    738:         }
                    739:         foreach my $type ('all','crit','reg') {
                    740:             $output .= '<span class="LC_nobreak"><label>'.
                    741:                        '<input type="radio" name="notify_type_'.$num. 
1.104     raeburn   742:                        '" value="'.$type.'" '.$chk{$type}.
                    743:                        ' onchange="javascript:address_changes('."'$num'".')" />'.
                    744:                        $lt{$type}.'</label></span>&nbsp;';
1.102     raeburn   745:         }
                    746:         my $htmlon = '';
                    747:         my $htmloff = '';
                    748:         if (grep/^\Q$item\E/,@allow_html) {
                    749:             $htmlon = 'checked="checked" '; 
                    750:         } else {
                    751:             $htmloff = 'checked="checked" ';
                    752:         }
                    753:         $output .= '</td><td><label><input type="radio" name="html_'.$num.
1.104     raeburn   754:                    '" value="1" '.$htmlon.
                    755:                    ' onchange="javascript:address_changes('."'$num'".')" />'.
                    756:                    &mt('Yes').'</label>&nbsp;'.
1.102     raeburn   757:                    '<label><input type="radio" name="html_'.$num.'" value="0" '.
1.104     raeburn   758:                    $htmloff. ' onchange="javascript:address_changes('."'$num'".
                    759: ')" />'.
                    760:                    &mt('No').'</label></td>'.
1.102     raeburn   761:                    &Apache::loncommon::end_data_table_row();
                    762:         $num ++;
1.104     raeburn   763:         $counter ++;
1.102     raeburn   764:     }
                    765:     my %defchk = (
                    766:                    all => 'checked="checked" ',
                    767:                    crit => '',
                    768:                    reg => '',
                    769:                  );
                    770:     $output .= &Apache::loncommon::start_data_table_row().
1.104     raeburn   771:                '<td><b>'.$counter.'</b></td>'.
                    772:                '<td><span class="LC_nobreak"><label>'.
                    773:                '<input type="checkbox" name="add_notify_'.$num.
                    774:                '" value="1" />'.&mt('Add new address').'</label></span></td>'.
1.102     raeburn   775:                '<td><input type="text" value="" name="address_'.$num.
1.104     raeburn   776:                '" onFocus="javascript:new_address('."'$num'".')" /></td><td>';
1.102     raeburn   777:     foreach my $type ('all','crit','reg') {
                    778:         $output .= '<span class="LC_nobreak"><label>'.
                    779:                    '<input type="radio" name="notify_type_'.$num.
                    780:                    '" value="'.$type.'" '.$defchk{$type}.'/>'.
                    781:                    $lt{$type}.'</label></span>&nbsp;';
                    782:     }
                    783:     $output .= '</td><td><label><input type="radio" name="html_'.$num.
                    784:                '" value="1" />'.&mt('Yes').'</label>&nbsp;'.
                    785:                '<label><input type="radio" name="html_'.$num.'" value="0" '.
                    786:                ' checked="checked" />'.
                    787:                &mt('No').'</label></td>'.
                    788:                &Apache::loncommon::end_data_table_row().
                    789:                &Apache::loncommon::end_data_table();
                    790:     $num ++;
                    791:     $r->print($output);
                    792:     $r->print(qq|
                    793: <hr />
                    794: <input type="hidden" name="numnotify" value="$num" />
                    795: <input type="button" value="$lt{'chg'}" onclick="javascript:validate()" />
                    796: <input type="button" value="$lt{'prme'}" onclick="location.href='/adm/preferences'" />
1.20      www       797: </form>
1.102     raeburn   798: |);
                    799: 
                    800: }
                    801: 
                    802: sub get_notifications {
                    803:     my ($userenv) = @_;
                    804:     my %allnot;
                    805:     my @critnot = split(/,/,$userenv->{'critnotification'});
                    806:     my @regnot = split(/,/,$userenv->{'notification'});
                    807:     foreach my $item (@critnot) {
                    808:         $allnot{$item}{crit} = 1;
                    809:     }
                    810:     foreach my $item (@regnot) {
                    811:         $allnot{$item}{reg} = 1;
                    812:     }
                    813:     return %allnot;
1.20      www       814: }
                    815: 
                    816: sub verify_and_change_msgforward {
                    817:     my $r = shift;
1.59      albertel  818:     my $user       = $env{'user.name'};
                    819:     my $domain     = $env{'user.domain'};
1.20      www       820:     my $newscreen  = '';
                    821:     my $message='';
1.59      albertel  822:     foreach (split(/\,/,$env{'form.msgforward'})) {
1.20      www       823: 	my ($msuser,$msdomain)=split(/[\@\:]/,$_);
1.95      albertel  824:         $msuser = &LONCAPA::clean_username($msuser);
                    825:         $msdomain = &LONCAPA::clean_domain($msdomain);
1.20      www       826:         if (($msuser) && ($msdomain)) {
                    827: 	    if (&Apache::lonnet::homeserver($msuser,$msdomain) ne 'no_host') {
                    828:                $newscreen.=$msuser.':'.$msdomain.',';
                    829: 	   } else {
1.102     raeburn   830:                $message.= &mt('No such user: ').$msuser.':'.$msdomain.'<br>';
1.20      www       831:            }
                    832:         }
                    833:     }
                    834:     $newscreen=~s/\,$//;
                    835:     if ($newscreen) {
                    836:         &Apache::lonnet::put('environment',{'msgforward' => $newscreen});
                    837:         &Apache::lonnet::appenv('environment.msgforward' => $newscreen);
1.102     raeburn   838:         $message .= &mt('Set message forwarding to: ').'<tt>'.$newscreen.
                    839:                     '</tt><br />';
1.20      www       840:     } else {
                    841:         &Apache::lonnet::del('environment',['msgforward']);
                    842:         &Apache::lonnet::delenv('environment\.msgforward');
1.102     raeburn   843:         $message.= &mt("Set message forwarding to 'off'.").'<br />';
1.20      www       844:     }
1.102     raeburn   845:     my $critnotification;
                    846:     my $notification;
                    847:     my $notify_with_html;
                    848:     my $lastnotify = $env{'form.numnotify'}-1;
1.104     raeburn   849:     my $totaladdresses = 0;
1.102     raeburn   850:     for (my $i=0; $i<$env{'form.numnotify'}; $i++) {
                    851:         if ((!defined($env{'form.del_notify_'.$i})) &&  
1.104     raeburn   852:            ((($i==$lastnotify) && ($env{'form.add_notify_'.$lastnotify} == 1)) ||
1.102     raeburn   853:             ($i<$lastnotify))) {
                    854:             if (defined($env{'form.address_'.$i})) {
                    855:                 if ($env{'form.notify_type_'.$i} eq 'all') {
                    856:                     $critnotification .= $env{'form.address_'.$i}.',';
                    857:                     $notification .= $env{'form.address_'.$i}.',';
                    858:                 } elsif ($env{'form.notify_type_'.$i} eq 'crit') {
                    859:                     $critnotification .= $env{'form.address_'.$i}.',';
                    860:                 } elsif ($env{'form.notify_type_'.$i} eq 'reg') {
                    861:                     $notification .= $env{'form.address_'.$i}.','; 
                    862:                 }
                    863:                 if ($env{'form.html_'.$i} eq '1') {
                    864: 		    $notify_with_html .= $env{'form.address_'.$i}.',';       	
                    865:                 }
1.104     raeburn   866:                 $totaladdresses ++;
1.102     raeburn   867:             }
                    868:         }
                    869:     }
                    870:     $critnotification =~ s/,$//;
                    871:     $critnotification=~s/\s//gs;
                    872:     $notification =~ s/,$//;
1.20      www       873:     $notification=~s/\s//gs;
1.102     raeburn   874:     $notify_with_html =~ s/,$//;
                    875:     $notify_with_html =~ s/\s//gs;
1.20      www       876:     if ($notification) {
                    877:         &Apache::lonnet::put('environment',{'notification' => $notification});
                    878:         &Apache::lonnet::appenv('environment.notification' => $notification);
1.102     raeburn   879:         $message.=&mt('Set non-critical message notification address(es) to: ').'<tt>'.$notification.'</tt><br />';
1.20      www       880:     } else {
                    881:         &Apache::lonnet::del('environment',['notification']);
                    882:         &Apache::lonnet::delenv('environment\.notification');
1.102     raeburn   883:         $message.=&mt("Non-critical message notification set to 'off'.").'<br />';
1.20      www       884:     }
                    885:     if ($critnotification) {
                    886:         &Apache::lonnet::put('environment',{'critnotification' => $critnotification});
                    887:         &Apache::lonnet::appenv('environment.critnotification' => $critnotification);
1.102     raeburn   888:         $message.=&mt('Set critical message notification address(es) to: ').'<tt>'.$critnotification.'</tt><br />';
1.20      www       889:     } else {
                    890:         &Apache::lonnet::del('environment',['critnotification']);
                    891:         &Apache::lonnet::delenv('environment\.critnotification');
1.104     raeburn   892:         $message.=&mt("Critical message notification set to 'off'.").'<br />';
1.102     raeburn   893:     }
                    894:     if ($critnotification || $notification) {
                    895:         if ($notify_with_html) {
                    896:             &Apache::lonnet::put('environment',{'notifywithhtml' => $notify_with_html});
                    897:             &Apache::lonnet::appenv('environment.notifywithhtml' => $notify_with_html);
                    898:             $message.=&mt('Set address(es) to receive excerpts with html retained: ').'<tt>'.$notify_with_html.'</tt>';
                    899:         } else {
                    900:             &Apache::lonnet::del('environment',['notifywithhtml']);
                    901:             &Apache::lonnet::delenv('environment\.notifywithhtml');
1.104     raeburn   902:             if ($totaladdresses == 1) {
                    903:                 $message.=&mt("Set notification address to receive excerpts with html stripped.");
                    904:             } else {
                    905:                 $message.=&mt("Set all notification addresses to receive excerpts with html stripped.");
                    906:             }
1.102     raeburn   907:         }
                    908:     } else {
                    909:         &Apache::lonnet::del('environment',['notifywithhtml']);
                    910:         &Apache::lonnet::delenv('environment\.notifywithhtml');
                    911:     }
                    912:     if ($message) {
                    913:         $message .= '<br /><hr />';
1.20      www       914:     }
1.102     raeburn   915:     &msgforwardchanger($r,$message);
1.6       www       916: }
                    917: 
1.12      www       918: ################################################################
1.19      www       919: #         Colors                                               #
1.12      www       920: ################################################################
                    921: 
1.19      www       922: sub colorschanger {
1.12      www       923:     my $r = shift;
1.19      www       924: # figure out colors
1.80      albertel  925:     my $function=&Apache::loncommon::get_users_function();
1.19      www       926:     my $domain=&Apache::loncommon::determinedomain();
                    927:     my %colortypes=('pgbg'  => 'Page Background',
                    928:                     'tabbg' => 'Header Background',
                    929:                     'sidebg'=> 'Header Border',
                    930:                     'font'  => 'Font',
                    931:                     'link'  => 'Un-Visited Link',
                    932:                     'vlink' => 'Visited Link',
                    933:                     'alink' => 'Active Link');
1.82      albertel  934:     my $start_data_table = &Apache::loncommon::start_data_table();
1.19      www       935:     my $chtable='';
1.22      matthew   936:     foreach my $item (sort(keys(%colortypes))) {
1.19      www       937:        my $curcol=&Apache::loncommon::designparm($function.'.'.$item,$domain);
1.82      albertel  938:        $chtable.=&Apache::loncommon::start_data_table_row().
1.83      albertel  939: 	   '<td>'.$colortypes{$item}.'</td><td style="background: '.$curcol.
1.19      www       940:         '">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</td><td><input name="'.$item.
1.21      www       941:         '" size="10" value="'.$curcol.
                    942: '" /></td><td><a href="javascript:pjump('."'color_custom','".$colortypes{$item}.
1.19      www       943: "','".$curcol."','"
1.82      albertel  944: 	    .$item."','parmform.pres','psub'".');">Select</a></td>'.
1.83      albertel  945: 	    &Apache::loncommon::end_data_table_row()."\n";
1.19      www       946:     }
1.82      albertel  947:     my $end_data_table = &Apache::loncommon::end_data_table();
1.23      matthew   948:     my $pjump_def = &Apache::lonhtmlcommon::pjump_javascript_definition();
1.19      www       949:     $r->print(<<ENDCOL);
1.82      albertel  950: <script type="text/javascript">
1.19      www       951: 
                    952:     function pclose() {
                    953:         parmwin=window.open("/adm/rat/empty.html","LONCAPAparms",
                    954:                  "height=350,width=350,scrollbars=no,menubar=no");
                    955:         parmwin.close();
                    956:     }
                    957: 
1.23      matthew   958:     $pjump_def
1.19      www       959: 
                    960:     function psub() {
                    961:         pclose();
                    962:         if (document.parmform.pres_marker.value!='') {
1.21      www       963:             if (document.parmform.pres_type.value!='') {
1.77      albertel  964:                 eval('document.prefs.'+
1.21      www       965:                      document.parmform.pres_marker.value+
1.19      www       966: 		     '.value=document.parmform.pres_value.value;');
1.21      www       967: 	    }
1.19      www       968:         } else {
                    969:             document.parmform.pres_value.value='';
                    970:             document.parmform.pres_marker.value='';
                    971:         }
                    972:     }
                    973: 
                    974: 
                    975: </script>
1.21      www       976: <form name="parmform">
                    977: <input type="hidden" name="pres_marker" />
                    978: <input type="hidden" name="pres_type" />
                    979: <input type="hidden" name="pres_value" />
                    980: </form>
1.88      albertel  981: <form name="prefs" action="/adm/preferences" method="post">
1.19      www       982: <input type="hidden" name="action" value="verify_and_change_colors" />
1.82      albertel  983: $start_data_table
1.19      www       984: $chtable
1.82      albertel  985: $end_data_table
1.19      www       986: </table>
1.21      www       987: <input type="submit" value="Change Custom Colors" />
                    988: <input type="submit" name="resetall" value="Reset All Colors to Default" />
1.12      www       989: </form>
1.19      www       990: ENDCOL
1.12      www       991: }
                    992: 
1.19      www       993: sub verify_and_change_colors {
1.12      www       994:     my $r = shift;
1.19      www       995: # figure out colors
1.80      albertel  996:     my $function=&Apache::loncommon::get_users_function();
1.19      www       997:     my $domain=&Apache::loncommon::determinedomain();
                    998:     my %colortypes=('pgbg'  => 'Page Background',
                    999:                     'tabbg' => 'Header Background',
                   1000:                     'sidebg'=> 'Header Border',
                   1001:                     'font'  => 'Font',
                   1002:                     'link'  => 'Un-Visited Link',
                   1003:                     'vlink' => 'Visited Link',
                   1004:                     'alink' => 'Active Link');
                   1005: 
1.12      www      1006:     my $message='';
1.21      www      1007:     foreach my $item (keys %colortypes) {
1.59      albertel 1008:         my $color=$env{'form.'.$item};
1.21      www      1009:         my $entry='color.'.$function.'.'.$item;
1.59      albertel 1010: 	if (($color=~/^\#[0-9A-Fa-f]{6}$/) && (!$env{'form.resetall'})) {
1.21      www      1011: 	    &Apache::lonnet::put('environment',{$entry => $color});
                   1012: 	    &Apache::lonnet::appenv('environment.'.$entry => $color);
                   1013: 	    $message.='Set '.$colortypes{$item}.' to '.$color.'<br />';
                   1014: 	} else {
                   1015: 	    &Apache::lonnet::del('environment',[$entry]);
                   1016: 	    &Apache::lonnet::delenv('environment\.'.$entry);
                   1017: 	    $message.='Reset '.$colortypes{$item}.'<br />';
                   1018: 	}
                   1019:     }
1.84      albertel 1020:     my $now = time;
                   1021:     &Apache::lonnet::put('environment',{'color.timestamp' => $now});
                   1022:     &Apache::lonnet::appenv('environment.color.timestamp' => $now);
                   1023: 
1.19      www      1024:     $r->print(<<ENDVCCOL);
1.12      www      1025: $message
1.88      albertel 1026: <form name="client" action="/adm/preferences" method="post">
1.21      www      1027: <input type="hidden" name="action" value="changecolors" />
                   1028: </form>
1.19      www      1029: ENDVCCOL
1.12      www      1030: }
                   1031: 
1.4       matthew  1032: ######################################################
                   1033: #            password handler subroutines            #
                   1034: ######################################################
1.3       matthew  1035: sub passwordchanger {
1.94      raeburn  1036:     my ($r,$errormessage,$caller,$mailtoken) = @_;
1.4       matthew  1037:     # This function is a bit of a mess....
1.3       matthew  1038:     # Passwords are encrypted using londes.js (DES encryption)
1.4       matthew  1039:     $errormessage = ($errormessage || '');
1.94      raeburn  1040:     my ($user,$domain,$currentpass,$defdom);
                   1041:     if ((!defined($caller)) || ($caller eq 'preferences')) {
                   1042:         $user = $env{'user.name'};
                   1043:         $domain = $env{'user.domain'};
                   1044:         if (!defined($caller)) {
                   1045:             $caller = 'preferences';
                   1046:         }
                   1047:     } elsif ($caller eq 'reset_by_email') {
                   1048:             $defdom = $r->dir_config('lonDefDomain');
                   1049:             my %data = &Apache::lonnet::tmpget($mailtoken);
                   1050:             if (keys(%data) == 0) {
                   1051:                 $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.'));
                   1052:                 return;
                   1053:             }
                   1054:             if (defined($data{time})) {
                   1055:                 if (time - $data{'time'} < 7200) {
                   1056:                     $user = $data{'username'};
                   1057:                     $domain = $data{'domain'};
                   1058:                     $currentpass = $data{'temppasswd'};
                   1059:                 } else {
                   1060:                     $r->print(&mt('Sorry, the token generated when you requested a password reset has expired.').'<br />');
                   1061:                     return;
                   1062:                 }
                   1063:             } else {
                   1064:                 $r->print(&mt('Sorry, the URL generated when you requested reset of your password contained incomplete information.').'<br />');
                   1065:                 return;
                   1066:             }
                   1067:    } else {
                   1068:         $r->print(&mt('Page requested in unexpected context').'<br />');
                   1069:         return;
                   1070:     }
1.3       matthew  1071:     my $currentauth=&Apache::lonnet::queryauthenticate($user,$domain);
                   1072:     # Check for authentication types that allow changing of the password.
                   1073:     return if ($currentauth !~ /^(unix|internal):/);
                   1074:     #
                   1075:     # Generate keys
                   1076:     my ($lkey_cpass ,$ukey_cpass ) = &des_keys();
                   1077:     my ($lkey_npass1,$ukey_npass1) = &des_keys();
                   1078:     my ($lkey_npass2,$ukey_npass2) = &des_keys();
1.4       matthew  1079:     # Store the keys in the log files
1.3       matthew  1080:     my $lonhost = $r->dir_config('lonHostID');
                   1081:     my $logtoken=Apache::lonnet::reply('tmpput:'
                   1082: 				       .$ukey_cpass  . $lkey_cpass .'&'
                   1083: 				       .$ukey_npass1 . $lkey_npass1.'&'
                   1084: 				       .$ukey_npass2 . $lkey_npass2,
                   1085: 				       $lonhost);
1.4       matthew  1086:     # Hexify the keys for output as javascript variables
1.94      raeburn  1087:     my %hexkey;
                   1088:     $hexkey{'ukey_cpass'}  = hex($ukey_cpass);
                   1089:     $hexkey{'lkey_cpass'}  = hex($lkey_cpass);
                   1090:     $hexkey{'ukey_npass1'} = hex($ukey_npass1);
                   1091:     $hexkey{'lkey_npass1'} = hex($lkey_npass1);
                   1092:     $hexkey{'ukey_npass2'} = hex($ukey_npass2);
                   1093:     $hexkey{'lkey_npass2'} = hex($lkey_npass2);
1.3       matthew  1094:     # Output javascript to deal with passwords
1.4       matthew  1095:     # Output DES javascript
1.3       matthew  1096:     {
                   1097: 	my $include = $r->dir_config('lonIncludes');
                   1098: 	my $jsh=Apache::File->new($include."/londes.js");
                   1099: 	$r->print(<$jsh>);
                   1100:     }
1.94      raeburn  1101:     $r->print(&jscript_send($caller));
1.3       matthew  1102:     $r->print(<<ENDFORM);
1.94      raeburn  1103: $errormessage
                   1104: 
                   1105: <p>
                   1106: <!-- We separate the forms into 'server' and 'client' in order to
                   1107:      ensure that unencrypted passwords will not be sent out by a
                   1108:      crappy browser -->
                   1109: ENDFORM
                   1110:     $r->print(&server_form($logtoken,$caller,$mailtoken));
                   1111:     $r->print(&client_form($caller,\%hexkey,$currentpass,$defdom));
                   1112: 
                   1113:     #
                   1114:     return;
                   1115: }
                   1116: 
                   1117: sub jscript_send {
                   1118:     my ($caller) = @_;
                   1119:     my $output = qq|
1.3       matthew  1120: <script language="JavaScript">
                   1121: 
                   1122:     function send() {
                   1123:         uextkey=this.document.client.elements.ukey_cpass.value;
                   1124:         lextkey=this.document.client.elements.lkey_cpass.value;
                   1125:         initkeys();
                   1126: 
1.52      raeburn  1127:         this.document.pserver.elements.currentpass.value
1.3       matthew  1128:             =crypted(this.document.client.elements.currentpass.value);
                   1129: 
                   1130:         uextkey=this.document.client.elements.ukey_npass1.value;
                   1131:         lextkey=this.document.client.elements.lkey_npass1.value;
                   1132:         initkeys();
1.52      raeburn  1133:         this.document.pserver.elements.newpass_1.value
1.3       matthew  1134:             =crypted(this.document.client.elements.newpass_1.value);
                   1135: 
                   1136:         uextkey=this.document.client.elements.ukey_npass2.value;
                   1137:         lextkey=this.document.client.elements.lkey_npass2.value;
                   1138:         initkeys();
1.52      raeburn  1139:         this.document.pserver.elements.newpass_2.value
1.3       matthew  1140:             =crypted(this.document.client.elements.newpass_2.value);
1.94      raeburn  1141: |;
                   1142:     if ($caller eq 'reset_by_email') {
                   1143:         $output .= qq|
                   1144:         this.document.pserver.elements.uname.value =
                   1145:                    this.document.client.elements.uname.value;
                   1146:         this.document.pserver.elements.udom.value =
                   1147:                    this.document.client.elements.udom.options[this.document.client.elements.udom.selectedIndex].value;
                   1148: |;
                   1149:     }
                   1150:     $ output .= qq|
1.52      raeburn  1151:         this.document.pserver.submit();
1.3       matthew  1152:     }
                   1153: </script>
1.94      raeburn  1154: |;
                   1155: }
1.3       matthew  1156: 
1.94      raeburn  1157: sub client_form {
                   1158:     my ($caller,$hexkey,$currentpass,$defdom) = @_;
1.99      www      1159:     my %lt=&Apache::lonlocal::texthash(
                   1160:                 'email' => 'EMail Address',
                   1161:                 'username' => 'Username',
                   1162:                 'domain' => 'Domain',
                   1163:                 'currentpass' => 'Current Password',
                   1164:                 'newpass' => 'New Password',
                   1165:                 'confirmpass' => 'Confirm Password',
                   1166:                 'changepass' => 'Change Password');
                   1167: 
1.94      raeburn  1168:     my $output = qq|
1.3       matthew  1169: <form name="client" >
                   1170: <table>
1.94      raeburn  1171: |;
                   1172:     if ($caller eq 'reset_by_email') {
                   1173:         $output .= qq|
1.99      www      1174: <tr><td class="LC_preferences_labeltext"><label for="email">$lt{'email'}</label>:</td>
1.97      raeburn  1175:     <td><input type="text" name="email" size="30" /> </td></tr>
1.99      www      1176: <tr><td class="LC_preferences_labeltext"><label for="uname">$lt{'username'}</label>:</td>
1.94      raeburn  1177:     <td>
1.97      raeburn  1178:      <input type="text" name="uname" size="15" />
1.94      raeburn  1179:      <input type="hidden" name="currentpass" value="$currentpass" />
                   1180:     </td></tr>
1.99      www      1181: <tr><td class="LC_preferences_labeltext"><label for="udom">$lt{'udom'}</label>:</td>
1.94      raeburn  1182:     <td>
                   1183: |;
                   1184:         $output .= &Apache::loncommon::select_dom_form($defdom,'udom').'
                   1185:    </td>
                   1186: </tr>
                   1187: ';
                   1188:     } else {
                   1189:         $output .= qq|
1.99      www      1190: <tr><td class="LC_preferences_labeltext"><label for="currentpass">$lt{'currentpass'}</label></td>
1.4       matthew  1191:     <td><input type="password" name="currentpass" size="10"/> </td></tr>
1.94      raeburn  1192: |;
                   1193:     }
                   1194:     $output .= <<"ENDFORM";
1.99      www      1195: <tr><td class="LC_preferences_labeltext"><label for="newpass_1">$lt{'newpass'}</label></td>
1.4       matthew  1196:     <td><input type="password" name="newpass_1" size="10"  /> </td></tr>
1.99      www      1197: <tr><td class="LC_preferences_labeltext"><label for="newpass_2">$lt{'confirmpass'}</label></td>
1.4       matthew  1198:     <td><input type="password" name="newpass_2" size="10"  /> </td></tr>
1.3       matthew  1199: <tr><td colspan="2" align="center">
1.99      www      1200:     <input type="button" value="$lt{'changepass'}" onClick="send();">
1.3       matthew  1201: </table>
1.94      raeburn  1202: <input type="hidden" name="ukey_cpass"  value="$hexkey->{'ukey_cpass'}" />
                   1203: <input type="hidden" name="lkey_cpass"  value="$hexkey->{'lkey_cpass'}" />
                   1204: <input type="hidden" name="ukey_npass1" value="$hexkey->{'ukey_npass1'}" />
                   1205: <input type="hidden" name="lkey_npass1" value="$hexkey->{'lkey_npass1'}" />
                   1206: <input type="hidden" name="ukey_npass2" value="$hexkey->{'ukey_npass2'}" />
                   1207: <input type="hidden" name="lkey_npass2" value="$hexkey->{'lkey_npass2'}" />
1.3       matthew  1208: </form>
                   1209: </p>
                   1210: ENDFORM
1.94      raeburn  1211:     return $output;
                   1212: }
                   1213: 
                   1214: sub server_form {
                   1215:     my ($logtoken,$caller,$mailtoken) = @_;
                   1216:     my $action = '/adm/preferences';
                   1217:     if ($caller eq 'reset_by_email') {
                   1218:         $action = '/adm/resetpw';
                   1219:     }
                   1220:     my $output = qq|
                   1221: <form name="pserver" action="$action" method="post">
                   1222: <input type="hidden" name="logtoken"    value="$logtoken" />
                   1223: <input type="hidden" name="currentpass" value="" />
                   1224: <input type="hidden" name="newpass_1"   value="" />
                   1225: <input type="hidden" name="newpass_2"   value="" />
                   1226:     |;
                   1227:     if ($caller eq 'reset_by_email') {
                   1228:         $output .=  qq|
                   1229: <input type="hidden" name="token"   value="$mailtoken" />
                   1230: <input type="hidden" name="uname"   value="" />
                   1231: <input type="hidden" name="udom"   value="" />
                   1232: 
                   1233: |;
                   1234:     }
                   1235:     $output .= qq|
                   1236: <input type="hidden" name="action" value="verify_and_change_pass" />
                   1237: </form>
                   1238: |;
                   1239:     return $output;
1.3       matthew  1240: }
                   1241: 
                   1242: sub verify_and_change_password {
1.94      raeburn  1243:     my ($r,$caller,$mailtoken) = @_;
                   1244:     my ($user,$domain,$homeserver);
                   1245:     if ($caller eq 'reset_by_email') {
                   1246:         $user       = $env{'form.uname'};
                   1247:         $domain     = $env{'form.udom'};
                   1248:         if ($user ne '' && $domain ne '') {
                   1249:             $homeserver = &Apache::lonnet::homeserver($user,$domain);
                   1250:             if ($homeserver eq 'no_host') {
1.99      www      1251:         &passwordchanger($r,"<p>\n<span class='LC_error'>".
                   1252:                          &mt("Invalid username and/or domain")."</span>\n</p>",
1.94      raeburn  1253:                          $caller,$mailtoken);
                   1254:                 return 1;
                   1255:             }
                   1256:         } else {
1.99      www      1257:             &passwordchanger($r,"<p>\n<span class='LC_error'>".
                   1258:                              &mt("Username and domain were blank")."</span>\n</p>",
1.94      raeburn  1259:                              $caller,$mailtoken);
                   1260:             return 1;
                   1261:         }
                   1262:     } else {
                   1263:         $user       = $env{'user.name'};
                   1264:         $domain     = $env{'user.domain'};
                   1265:         $homeserver = $env{'user.home'};
                   1266:     }
1.3       matthew  1267:     my $currentauth=&Apache::lonnet::queryauthenticate($user,$domain);
1.4       matthew  1268:     # Check for authentication types that allow changing of the password.
1.94      raeburn  1269:     if ($currentauth !~ /^(unix|internal):/) {
                   1270:         if ($caller eq 'reset_by_email') {
1.99      www      1271:             &passwordchanger($r,"<p>\n<span class='LC_error'>".
                   1272:                              &mt("Authentication type for this user can not be changed by this mechanism").
                   1273:                              "</span>\n</p>",
1.94      raeburn  1274:                               $caller,$mailtoken);
                   1275:             return 1;
                   1276:         } else {
                   1277:             return;
                   1278:         }
                   1279:     }
1.3       matthew  1280:     #
1.59      albertel 1281:     my $currentpass = $env{'form.currentpass'}; 
                   1282:     my $newpass1    = $env{'form.newpass_1'}; 
                   1283:     my $newpass2    = $env{'form.newpass_2'};
                   1284:     my $logtoken    = $env{'form.logtoken'};
1.3       matthew  1285:     # Check for empty data 
1.4       matthew  1286:     unless (defined($currentpass) && 
                   1287: 	    defined($newpass1)    && 
                   1288: 	    defined($newpass2)    ){
1.99      www      1289: 	&passwordchanger($r,"<p>\n<span class='LC_error'>".
                   1290: 			 &mt("One or more password fields were blank").
                   1291:                          "</span>\n</p>",$caller,$mailtoken);
1.3       matthew  1292: 	return;
                   1293:     }
1.16      albertel 1294:     # Get the keys
                   1295:     my $lonhost = $r->dir_config('lonHostID');
1.3       matthew  1296:     my $tmpinfo = Apache::lonnet::reply('tmpget:'.$logtoken,$lonhost);
                   1297:     if (($tmpinfo=~/^error/) || ($tmpinfo eq 'con_lost')) {
1.4       matthew  1298:         # I do not a have a better idea about how to handle this
1.94      raeburn  1299:         my $tryagain_text = &mt('Please log out and try again.');
                   1300:         if ($caller eq 'reset_by_email') {
                   1301:             $tryagain_text = &mt('Please try again later.');
                   1302:         }
1.101     albertel 1303:         my $unable=&mt("Unable to retrieve saved token for password decryption");
1.3       matthew  1304: 	$r->print(<<ENDERROR);
                   1305: <p>
1.99      www      1306: <span class="LC_error">$unable.  $tryagain_text</span>
1.3       matthew  1307: </p>
                   1308: ENDERROR
1.4       matthew  1309:         # Probably should log an error here
1.75      albertel 1310:         return 1;
1.3       matthew  1311:     }
                   1312:     my ($ckey,$n1key,$n2key)=split(/&/,$tmpinfo);
1.4       matthew  1313:     # 
1.17      matthew  1314:     $currentpass = &des_decrypt($ckey ,$currentpass);
                   1315:     $newpass1    = &des_decrypt($n1key,$newpass1);
                   1316:     $newpass2    = &des_decrypt($n2key,$newpass2);
1.94      raeburn  1317:     #
                   1318:     if ($caller eq 'reset_by_email') {
                   1319:         my %data = &Apache::lonnet::tmpget($mailtoken);
                   1320:         if ($currentpass ne $data{'temppasswd'}) {
                   1321:             &passwordchanger($r,
1.99      www      1322:                          '<span class="LC_error">'.
                   1323:                          &mt('Could not verify current authentication').'.  '.
                   1324:                          &mt('Please try again').'.</span>',$caller,$mailtoken);
1.94      raeburn  1325:             return 1;
                   1326:         }
                   1327:     } 
1.3       matthew  1328:     if ($newpass1 ne $newpass2) {
1.4       matthew  1329: 	&passwordchanger($r,
1.99      www      1330: 			 '<span class="LC_error">'.
                   1331: 			 &mt('The new passwords you entered do not match').'.  '.
                   1332: 			 &mt('Please try again').'.</span>',$caller,$mailtoken);
1.75      albertel 1333: 	return 1;
1.4       matthew  1334:     }
                   1335:     if (length($newpass1) < 7) {
                   1336: 	&passwordchanger($r,
1.99      www      1337: 			 '<span class="LC_error">'.
                   1338: 			 &mt('Passwords must be a minimum of 7 characters long').'.  '.
                   1339: 			 &mt('Please try again').'</span>.',$caller,$mailtoken);
1.75      albertel 1340: 	return 1;
1.3       matthew  1341:     }
1.4       matthew  1342:     #
                   1343:     # Check for bad characters
                   1344:     my $badpassword = 0;
                   1345:     foreach (split(//,$newpass1)) {
                   1346: 	$badpassword = 1 if ((ord($_)<32)||(ord($_)>126));
                   1347:     }
                   1348:     if ($badpassword) {
                   1349: 	# I can't figure out how to enter bad characters on my browser.
1.99      www      1350: 	my $errormessage ='<span class="LC_error">'.
                   1351:            &mt('The password you entered contained illegal characters').'.<br />'.
                   1352:            &mt('Valid characters are').(<<"ENDERROR");
                   1353: : space and <br />
1.4       matthew  1354: <pre>
                   1355: !&quot;\#$%&amp;\'()*+,-./0123456789:;&lt;=&gt;?\@
                   1356: ABCDEFGHIJKLMNOPQRSTUVWXYZ[\]^_\`abcdefghijklmnopqrstuvwxyz{|}~
1.99      www      1357: </pre></span>
1.4       matthew  1358: ENDERROR
1.94      raeburn  1359:         &passwordchanger($r,$errormessage,$caller,$mailtoken);
                   1360:         return 1;
1.4       matthew  1361:     }
                   1362:     # 
                   1363:     # Change the password (finally)
                   1364:     my $result = &Apache::lonnet::changepass
1.94      raeburn  1365: 	($user,$domain,$currentpass,$newpass1,$homeserver,$caller);
1.4       matthew  1366:     # Inform the user the password has (not?) been changed
                   1367:     if ($result =~ /^ok$/) {
1.99      www      1368: 	$r->print("<h3>".&mt('The password for [_1] was successfully changed',$user)."</h3>");
1.4       matthew  1369:     } else {
                   1370: 	# error error: run in circles, scream and shout
1.99      www      1371:         $r->print("<h3><span class='LC_error'>".&mt("The password for [_1] was not changed",$user)."</span></h3>".
                   1372:                   &mt('Please make sure your old password was entered correctly').'.');
1.75      albertel 1373:         return 1;
1.4       matthew  1374:     }
                   1375:     return;
1.3       matthew  1376: }
                   1377: 
1.42      raeburn  1378: ################################################################
                   1379: #            discussion display subroutines 
                   1380: ################################################################
                   1381: sub discussionchanger {
                   1382:     my $r = shift;
1.59      albertel 1383:     my $user       = $env{'user.name'};
                   1384:     my $domain     = $env{'user.domain'};
1.42      raeburn  1385:     my %userenv = &Apache::lonnet::get
1.43      raeburn  1386:         ('environment',['discdisplay','discmarkread']);
                   1387:     my $discdisp = 'allposts';
                   1388:     my $discmark = 'onmark';
                   1389: 
                   1390:     if (defined($userenv{'discdisplay'})) {
                   1391:         unless ($userenv{'discdisplay'} eq '') { 
                   1392:             $discdisp = $userenv{'discdisplay'};
                   1393:         }
                   1394:     }
                   1395:     if (defined($userenv{'discmarkread'})) {
                   1396:         unless ($userenv{'discdisplay'} eq '') { 
                   1397:             $discmark = $userenv{'discmarkread'};
                   1398:         }
                   1399:     }
                   1400: 
                   1401:     my $newdisp = 'unread';
                   1402:     my $newmark = 'ondisp';
                   1403: 
                   1404:     my $function = &Apache::loncommon::get_users_function();
                   1405:     my $color = &Apache::loncommon::designparm($function.'.tabbg',
1.59      albertel 1406:                                                     $env{'user.domain'});
1.43      raeburn  1407:     my %lt = &Apache::lonlocal::texthash(
                   1408:         'pref' => 'Display Preference',
                   1409:         'curr' => 'Current setting ',
                   1410:         'actn' => 'Action',
                   1411:         'sdpf' => 'Set display preferences for discussion posts for both bulletin boards and individual resources in all your courses.',
                   1412:         'prca' => 'Preferences can be set that determine',
                   1413:         'whpo' => 'Which posts are displayed when you display a bulletin board or resource, and',
                   1414:         'unwh' => 'Under what circumstances posts are identfied as "New"',
                   1415:         'allposts' => 'All posts',
                   1416:         'unread' => 'New posts only',
                   1417:         'ondisp' => 'Once displayed',
                   1418:         'onmark' => 'Once marked as read',
                   1419:         'disa' => 'Posts displayed?',
                   1420:         'npmr' => 'New posts cease to be identified as "New"?',
                   1421:         'thde'  => 'The preferences you set here can be overridden within each individual discussion.',
                   1422:         'chgt' => 'Change to '
                   1423:     );
                   1424:     my $dispchange = $lt{'unread'};
                   1425:     my $markchange = $lt{'ondisp'};
                   1426:     my $currdisp = $lt{'allposts'};
                   1427:     my $currmark = $lt{'onmark'};
                   1428: 
                   1429:     if ($discdisp eq 'unread') {
                   1430:         $dispchange = $lt{'allposts'};
                   1431:         $currdisp = $lt{'unread'};
                   1432:         $newdisp = 'allposts';
                   1433:     }
                   1434: 
                   1435:     if ($discmark eq 'ondisp') {
                   1436:         $markchange = $lt{'onmark'};
                   1437:         $currmark = $lt{'ondisp'};
                   1438:         $newmark = 'onmark';
1.42      raeburn  1439:     }
1.43      raeburn  1440:     
                   1441:     $r->print(<<"END");
1.88      albertel 1442: <form name="prefs" action="/adm/preferences" method="post">
1.42      raeburn  1443: <input type="hidden" name="action" value="verify_and_change_discussion" />
                   1444: <br />
1.87      albertel 1445: $lt{'sdpf'}<br /> $lt{'prca'}  <ol><li>$lt{'whpo'}</li><li>$lt{'unwh'}</li></ol> 
1.43      raeburn  1446: <br />
                   1447: <br />
1.82      albertel 1448: END
                   1449:     $r->print(&Apache::loncommon::start_data_table());
                   1450:     $r->print(<<"END");
                   1451:        <tr>
                   1452:         <th>$lt{'pref'}</th>
                   1453:         <th>$lt{'curr'}</th>
                   1454:         <th>$lt{'actn'}?</th>
1.43      raeburn  1455:        </tr>
1.82      albertel 1456: END
                   1457:     $r->print(&Apache::loncommon::start_data_table_row());
                   1458:     $r->print(<<"END");
1.43      raeburn  1459:        <td>$lt{'disa'}</td>
                   1460:        <td>$lt{$discdisp}</td>
1.82      albertel 1461:        <td><label><input type="checkbox" name="discdisp" /><input type="hidden" name="newdisp" value="$newdisp" />&nbsp;$lt{'chgt'} "$dispchange"</label></td>
                   1462: END
                   1463:     $r->print(&Apache::loncommon::end_data_table_row().
                   1464: 	      &Apache::loncommon::start_data_table_row());
                   1465:     $r->print(<<"END");
1.43      raeburn  1466:        <td>$lt{'npmr'}</td>
                   1467:        <td>$lt{$discmark}</td>
1.82      albertel 1468:        <td><label><input type="checkbox" name="discmark" /><input type="hidden" name="newmark" value="$newmark" />&nbsp;$lt{'chgt'} "$markchange"</label></td>
1.43      raeburn  1469:       </tr>
1.82      albertel 1470: END
                   1471:     $r->print(&Apache::loncommon::end_data_table_row().
                   1472: 	      &Apache::loncommon::end_data_table());
                   1473:     $r->print(<<"END");
1.43      raeburn  1474: <br />
                   1475: <br />
1.101     albertel 1476: <input type="submit" name="sub" value="Save Changes" />
1.43      raeburn  1477: <br />
                   1478: <br />
                   1479: Note: $lt{'thde'}
                   1480: </form>
                   1481: END
1.42      raeburn  1482: }
                   1483:                                                                                                                 
                   1484: sub verify_and_change_discussion {
                   1485:     my $r = shift;
1.59      albertel 1486:     my $user     = $env{'user.name'};
                   1487:     my $domain   = $env{'user.domain'};
1.42      raeburn  1488:     my $message='';
1.59      albertel 1489:     if (defined($env{'form.discdisp'}) ) {
                   1490:         my $newdisp  = $env{'form.newdisp'};
1.43      raeburn  1491:         if ($newdisp eq 'unread') {
1.87      albertel 1492:             $message .='In discussions: only new posts will be displayed.<br />';
1.43      raeburn  1493:             &Apache::lonnet::put('environment',{'discdisplay' => $newdisp});
                   1494:             &Apache::lonnet::appenv('environment.discdisplay' => $newdisp);
                   1495:         } else {
1.87      albertel 1496:             $message .= 'In discussions: all posts will be displayed.<br />';
1.43      raeburn  1497:             &Apache::lonnet::del('environment',['discdisplay']);
                   1498:             &Apache::lonnet::delenv('environment\.discdisplay');
                   1499:         }
                   1500:     }
1.59      albertel 1501:     if (defined($env{'form.discmark'}) ) {
                   1502:         my $newmark = $env{'form.newmark'};
1.43      raeburn  1503:         if ($newmark eq 'ondisp') {
1.87      albertel 1504:            $message.='In discussions: new posts will be cease to be identified as "new" after display.<br />';
1.43      raeburn  1505:             &Apache::lonnet::put('environment',{'discmarkread' => $newmark});
                   1506:             &Apache::lonnet::appenv('environment.discmarkread' => $newmark);
                   1507:         } else {
1.87      albertel 1508:             $message.='In discussions: posts will be identified as "new" until marked as read by the reader.<br />';
1.43      raeburn  1509:             &Apache::lonnet::del('environment',['discmarkread']);
                   1510:             &Apache::lonnet::delenv('environment\.discmarkread');
                   1511:         }
1.42      raeburn  1512:     }
                   1513:     $r->print(<<ENDVCSCREEN);
                   1514: $message
                   1515: ENDVCSCREEN
                   1516: }
                   1517: 
1.63      raeburn  1518: ################################################################
                   1519: # Subroutines for page display on course access (Course Coordinators)
                   1520: ################################################################
                   1521: sub coursedisplaychanger {
                   1522:     my $r = shift;
                   1523:     my $user       = $env{'user.name'};
                   1524:     my $domain     = $env{'user.domain'};
1.66      albertel 1525:     my %userenv = &Apache::lonnet::get('environment',['course_init_display']);
1.71      raeburn  1526:     my $currvalue = 'whatsnew';
1.73      albertel 1527:     my $firstselect = '';
                   1528:     my $whatsnewselect = 'checked="checked"';
1.71      raeburn  1529:     if (exists($userenv{'course_init_display'})) {
                   1530:         if ($userenv{'course_init_display'} eq 'firstres') {
                   1531:             $currvalue = 'firstres';
1.73      albertel 1532:             $firstselect = 'checked="checked"';
                   1533: 	    $whatsnewselect = '';
1.71      raeburn  1534:         }
1.63      raeburn  1535:     }
1.71      raeburn  1536:     my %pagenames = (
                   1537:                        firstres => 'First resource',
                   1538:                        whatsnew => "What's new page",
                   1539:                     );
1.70      raeburn  1540:     my $whatsnew_off=&mt('Display the [_1] in the course.','<b>first resource</b>');
                   1541:     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  1542: 
1.71      raeburn  1543:     $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  1544:     $r->print(<<ENDLSCREEN);
1.88      albertel 1545: <form name="prefs" action="/adm/preferences" method="post">
1.63      raeburn  1546: <input type="hidden" name="action" value="verify_and_change_coursepage" />
1.72      albertel 1547: <br />
1.65      albertel 1548: <label><input type="radio" name="newdisp" value="firstres" $firstselect /> $whatsnew_off</label><br />
1.70      raeburn  1549: <label><input type="radio" name="newdisp" value="whatsnew" $whatsnewselect /> $whatsnew_on</label><input type="hidden" name="refpage" value="$env{'form.refpage'}" />
1.63      raeburn  1550: ENDLSCREEN
1.70      raeburn  1551:     $r->print('<br /><br /><input type="submit" value="'.&mt('Change').'" />
1.63      raeburn  1552: </form>');
                   1553: }
                   1554: 
                   1555: sub verify_and_change_coursepage {
                   1556:     my $r = shift;
                   1557:     my $message='';
                   1558:     my %lt = &Apache::lonlocal::texthash(
1.70      raeburn  1559:         'defs' => 'Default now set',
1.71      raeburn  1560:         'when' => 'when you select a course role from the roles screen',
1.63      raeburn  1561:         'ywbt' => 'you will be taken to the start of the course.',
                   1562:         'apwb' => 'a page will be displayed that lists items in the course that may require action from you.',
                   1563:         'gtts' => 'Go to the start of the course',
1.70      raeburn  1564:         'dasp' => "Display the What's New page listing course action items", 
1.63      raeburn  1565:     );
                   1566:     my $newdisp  = $env{'form.newdisp'};
1.70      raeburn  1567:     $message = '<b>'.$lt{'defs'}.'</b>: '.$lt{'when'}.', ';
1.63      raeburn  1568:     if ($newdisp eq 'firstres') {
1.87      albertel 1569:         $message .= $lt{'ywbt'}.'<br />';
1.63      raeburn  1570:         &Apache::lonnet::put('environment',{'course_init_display' => $newdisp});
                   1571:         &Apache::lonnet::appenv('environment.course_init_display' => $newdisp);
                   1572:     } else {
1.87      albertel 1573:         $message .= $lt{'apwb'}.'<br />';
1.63      raeburn  1574:         &Apache::lonnet::del('environment',['course_init_display']);
                   1575:         &Apache::lonnet::delenv('environment\.course_init_display');
                   1576:     }
1.70      raeburn  1577:     my $refpage = $env{'form.refpage'};
1.63      raeburn  1578:     if (($env{'request.course.fn'}) && ($env{'request.course.id'})) {
                   1579:         if ($newdisp eq 'firstres') {
                   1580:             my $cdom = $env{'course.'.$env{'request.course.id'}.'.domain'};
                   1581:             my $cnum = $env{'course.'.$env{'request.course.id'}.'.num'}; 
                   1582:             my ($furl,$ferr)=
                   1583:                 &Apache::lonuserstate::readmap($cdom.'/'.$cnum);
                   1584:             $message .= '<br /><font size="+1"><a href="'.$furl.'">'.$lt{'gtts'}.' <i>'.&mt('now').'</i></a></font>';
                   1585:         } else {
1.70      raeburn  1586:             $message .= '<br /><font size="+1"><a href="/adm/whatsnew?refpage='.
                   1587:                         $refpage.'">'.$lt{'dasp'}.'</a></font>';
1.63      raeburn  1588:         }
                   1589:     }
                   1590:     $r->print(<<ENDVCSCREEN);
                   1591: $message
                   1592: <br /><br />
                   1593: ENDVCSCREEN
                   1594: }
                   1595: 
                   1596: 
1.4       matthew  1597: ######################################################
                   1598: #            other handler subroutines               #
                   1599: ######################################################
                   1600: 
1.3       matthew  1601: ################################################################
                   1602: #                          Main handler                        #
                   1603: ################################################################
1.1       www      1604: sub handler {
                   1605:     my $r = shift;
1.59      albertel 1606:     my $user = $env{'user.name'};
                   1607:     my $domain = $env{'user.domain'};
1.31      www      1608:     &Apache::loncommon::content_type($r,'text/html');
1.4       matthew  1609:     # Some pages contain DES keys and should not be cached.
                   1610:     &Apache::loncommon::no_cache($r);
1.1       www      1611:     $r->send_http_header;
                   1612:     return OK if $r->header_only;
1.9       matthew  1613:     #
1.35      matthew  1614:     &Apache::loncommon::get_unprocessed_cgi($ENV{'QUERY_STRING'},
1.70      raeburn  1615:                                    ['action','wysiwyg','returnurl','refpage']);
1.35      matthew  1616:     #
                   1617:     &Apache::lonhtmlcommon::clear_breadcrumbs();
                   1618:     &Apache::lonhtmlcommon::add_breadcrumb
                   1619:         ({href => '/adm/preferences',
                   1620:           text => 'Set User Preferences'});
                   1621: 
                   1622:     my @Options;
                   1623:     # Determine current authentication method
                   1624:     my $currentauth=&Apache::lonnet::queryauthenticate($user,$domain);
                   1625:     if ($currentauth =~ /^(unix|internal):/) {
                   1626:         push (@Options,({ action   => 'changepass',
1.40      www      1627:                           linktext => 'Change Password',
1.35      matthew  1628:                           href     => '/adm/preferences',
                   1629:                           help     => 'Change_Password',
                   1630:                           subroutine => \&passwordchanger,
                   1631:                           breadcrumb => 
                   1632:                               { href => '/adm/preferences?action=changepass',
                   1633:                                 text => 'Change Password'},
                   1634:                           },
                   1635:                         { action => 'verify_and_change_pass',
                   1636:                           subroutine => \&verify_and_change_password,
                   1637:                           breadcrumb => 
                   1638:                               { href =>'/adm/preferences?action=changepass',
                   1639:                                 text => 'Change Password'},
1.75      albertel 1640:                           printmenu => 'not_on_error',
1.35      matthew  1641:                           }));
                   1642:     }
                   1643:     push (@Options,({ action   => 'changescreenname',
                   1644:                       linktext => 'Change Screen Name',
                   1645:                       href     => '/adm/preferences',
                   1646:                       help     => 'Prefs_Screen_Name_Nickname',
                   1647:                       subroutine => \&screennamechanger,
                   1648:                       breadcrumb => 
                   1649:                           { href => '/adm/preferences?action=changescreenname',
                   1650:                             text => 'Change Screen Name'},
                   1651:                       },
                   1652:                     { action   => 'verify_and_change_screenname',
                   1653:                       subroutine => \&verify_and_change_screenname,
                   1654:                       breadcrumb => 
                   1655:                           { href => '/adm/preferences?action=changescreenname',
                   1656:                             text => 'Change Screen Name'},
                   1657:                       printmenu => 'yes',
                   1658:                       }));
                   1659: 
                   1660:     push (@Options,({ action   => 'changemsgforward',
1.97      raeburn  1661:                       linktext => 'Change Message Forwarding and Notification Email Addresses',
1.35      matthew  1662:                       href     => '/adm/preferences',
                   1663:                       help     => 'Prefs_Forwarding',
                   1664:                       breadcrumb => 
                   1665:                           { href => '/adm/preferences?action=changemsgforward',
                   1666:                             text => 'Change Message Forwarding'},
                   1667:                       subroutine => \&msgforwardchanger,
                   1668:                       },
                   1669:                     { action => 'verify_and_change_msgforward',
                   1670:                       breadcrumb => 
                   1671:                           { href => '/adm/preferences?action=changemsgforward',
                   1672:                             text => 'Change Message Forwarding'},
1.102     raeburn  1673:                       printmenu => 'no',
1.35      matthew  1674:                       subroutine => \&verify_and_change_msgforward }));
                   1675:     my $aboutmeaction=
1.59      albertel 1676:         '/adm/'.$env{'user.domain'}.'/'.$env{'user.name'}.'/aboutme';
1.35      matthew  1677:     push (@Options,{ action => 'none', 
                   1678:                      linktext =>
1.41      www      1679:                          q{Edit the 'About Me' Personal Information Screen},
1.45      www      1680: 		     help => 'Prefs_About_Me',
1.35      matthew  1681:                      href => $aboutmeaction});
                   1682:     push (@Options,({ action => 'changecolors',
                   1683:                       linktext => 'Change Color Scheme',
                   1684:                       href => '/adm/preferences',
                   1685:                       help => 'Change_Colors',
                   1686:                       breadcrumb => 
                   1687:                           { href => '/adm/preferences?action=changecolors',
                   1688:                             text => 'Change Colors'},
                   1689:                       subroutine => \&colorschanger,
                   1690:                   },
                   1691:                     { action => 'verify_and_change_colors',
                   1692:                       breadcrumb => 
                   1693:                           { href => '/adm/preferences?action=changecolors',
                   1694:                             text => 'Change Colors'},
                   1695:                       printmenu => 'yes',
                   1696:                       subroutine => \&verify_and_change_colors,
                   1697:                       }));
                   1698:     push (@Options,({ action => 'changelanguages',
1.39      www      1699:                       linktext => 'Change Language Preferences',
1.35      matthew  1700:                       href => '/adm/preferences',
1.45      www      1701: 		      help => 'Prefs_Language',
1.35      matthew  1702:                       breadcrumb=>
                   1703:                           { href => '/adm/preferences?action=changelanguages',
                   1704:                             text => 'Change Language'},
                   1705:                       subroutine =>  \&languagechanger,
                   1706:                   },
                   1707:                     { action => 'verify_and_change_languages',
                   1708:                       breadcrumb=>
                   1709:                           {href => '/adm/preferences?action=changelanguages',
                   1710:                            text => 'Change Language'},
                   1711:                       printmenu => 'yes',
                   1712:                       subroutine=>\&verify_and_change_languages, }
                   1713:                     ));
1.44      www      1714:     push (@Options,({ action => 'changewysiwyg',
                   1715:                       linktext => 'Change WYSIWYG Editor Preferences',
                   1716:                       href => '/adm/preferences',
                   1717:                       breadcrumb => 
                   1718:                             { href => '/adm/preferences?action=changewysiwyg',
                   1719:                               text => 'Change WYSIWYG Preferences'},
                   1720:                       subroutine => \&wysiwygchanger,
                   1721:                   },
                   1722:                     { action => 'set_wysiwyg',
                   1723:                       breadcrumb =>
                   1724:                           { href => '/adm/preferences?action=changewysiwyg',
                   1725:                             text => 'Change WYSIWYG Preferences'},
                   1726:                       printmenu => 'yes',
                   1727:                       subroutine => \&verify_and_change_wysiwyg, }
                   1728:                     ));
1.42      raeburn  1729:     push (@Options,({ action => 'changediscussions',
                   1730:                       linktext => 'Change Discussion Display Preferences',
                   1731:                       href => '/adm/preferences',
1.46      raeburn  1732:                       help => 'Change_Discussion_Display',
1.42      raeburn  1733:                       breadcrumb => 
                   1734:                             { href => '/adm/preferences?action=changediscussions',
1.43      raeburn  1735:                               text => 'Change Discussion Preferences'},
1.42      raeburn  1736:                       subroutine => \&discussionchanger,
                   1737:                   },
                   1738:                     { action => 'verify_and_change_discussion',
                   1739:                       breadcrumb =>
                   1740:                           { href => '/adm/preferences?action=changediscussions',
1.43      raeburn  1741:                             text => 'Change Discussion Preferences'},
1.42      raeburn  1742:                       printmenu => 'yes',
                   1743:                       subroutine => \&verify_and_change_discussion, }
                   1744:                     ));
1.96      albertel 1745: 
                   1746:     my $role = ($env{'user.adv'} ? 'Roles' : 'Course');
1.50      albertel 1747:     push (@Options,({ action   => 'changerolespref',
1.96      albertel 1748:                       linktext => 'Change '.$role.' Page Preferences',
1.50      albertel 1749:                       href     => '/adm/preferences',
                   1750:                       subroutine => \&rolesprefchanger,
                   1751:                       breadcrumb =>
                   1752:                           { href => '/adm/preferences?action=changerolespref',
1.96      albertel 1753:                             text => 'Change '.$role.' Page Pref'},
1.50      albertel 1754:                       },
                   1755:                     { action   => 'verify_and_change_rolespref',
                   1756:                       subroutine => \&verify_and_change_rolespref,
                   1757:                       breadcrumb =>
                   1758:                           { href => '/adm/preferences?action=changerolespref',
1.96      albertel 1759:                             text => 'Change '.$role.' Page Preferences'},
1.50      albertel 1760:                       printmenu => 'yes',
                   1761:                       }));
                   1762: 
1.54      albertel 1763:     push (@Options,({ action   => 'changetexenginepref',
                   1764:                       linktext => 'Change How Math Equations Are Displayed',
                   1765:                       href     => '/adm/preferences',
                   1766:                       subroutine => \&texenginechanger,
                   1767:                       breadcrumb =>
                   1768:                           { href => '/adm/preferences?action=changetexenginepref',
                   1769:                             text => 'Change Math Pref'},
                   1770:                       },
                   1771:                     { action   => 'verify_and_change_texengine',
                   1772:                       subroutine => \&verify_and_change_texengine,
                   1773:                       breadcrumb =>
                   1774:                           { href => '/adm/preferences?action=changetexenginepref',
                   1775:                             text => 'Change Math Preferences'},
                   1776:                       printmenu => 'yes',
                   1777:                       }));
1.85      albertel 1778: 
                   1779:     if ($env{'environment.remote'} eq 'off') {
                   1780: 	push (@Options,({ action => 'launch',
                   1781: 			  linktext => 'Launch Remote Control',
                   1782: 			  href => '/adm/remote?url=/adm/preferences',
                   1783: 		      }));
                   1784:     } else {
                   1785: 	push (@Options,({ action => 'collapse',
                   1786: 			  linktext => 'Collapse Remote Control',
                   1787: 			  href => '/adm/remote?url=/adm/preferences',
                   1788: 		      }));
                   1789:     }
                   1790: 
1.98      www      1791:     push (@Options,({ action   => 'changeicons',
1.100     www      1792:                       linktext => 'Change How Menus are Displayed',
1.98      www      1793:                       href     => '/adm/preferences',
                   1794:                       subroutine => \&iconchanger,
                   1795:                       breadcrumb =>
                   1796:                           { href => '/adm/preferences?action=changeicons',
                   1797:                             text => 'Change Main Menu'},
                   1798:                       },
                   1799:                     { action   => 'verify_and_change_icons',
                   1800:                       subroutine => \&verify_and_change_icons,
                   1801:                       breadcrumb =>
                   1802:                           { href => '/adm/preferences?action=changeicons',
                   1803:                             text => 'Change Main Menu'},
                   1804:                       printmenu => 'yes',
                   1805:                       }));
                   1806: 
1.106     www      1807:     push (@Options,({ action   => 'changeclicker',
                   1808:                       linktext => 'Register Response Devices ("Clickers")',
                   1809:                       href     => '/adm/preferences',
                   1810:                       subroutine => \&clickerchanger,
                   1811:                       breadcrumb =>
                   1812:                           { href => '/adm/preferences?action=changeicons',
                   1813:                             text => 'Register Clicker'},
                   1814:                       },
                   1815:                     { action   => 'verify_and_change_clicker',
                   1816:                       subroutine => \&verify_and_change_clicker,
                   1817:                       breadcrumb =>
                   1818:                           { href => '/adm/preferences?action=changeclicker',
                   1819:                             text => 'Register Clicker'},
                   1820:                       printmenu => 'yes',
                   1821:                       }));
1.105     www      1822: 
                   1823: 
1.74      albertel 1824:     if (&Apache::lonnet::allowed('whn',$env{'request.course.id'})
                   1825: 	|| &Apache::lonnet::allowed('whn',$env{'request.course.id'}.'/'
                   1826: 				    .$env{'request.course.sec'})) {
1.63      raeburn  1827:         push (@Options,({ action => 'changecourseinit',
                   1828:                           linktext => 'Change Course Initialization Preference',
                   1829:                           href => '/adm/preferences',
                   1830:                           subroutine => \&coursedisplaychanger,
                   1831:                           breadcrumb =>
                   1832:                               { href => '/adm/preferences?action=changecourseinit',
                   1833:                                 text => 'Change Course Init. Pref.'},
                   1834:                           },
                   1835:                         { action => 'verify_and_change_coursepage',
                   1836:                           breadcrumb =>
                   1837:                           { href => '/adm/preferences?action=changecourseinit',                               text => 'Change Course Initialization Preference'},
                   1838:                         printmenu => 'yes',
                   1839:                         subroutine => \&verify_and_change_coursepage,
                   1840:                        }));
                   1841:     }
1.50      albertel 1842: 
1.62      raeburn  1843:     if ($env{'user.name'} =~ /^(albertel|fox|foxr|koretemey|korte|hallmat3|turtle|raeburn)$/) {
1.35      matthew  1844:         push (@Options,({ action => 'debugtoggle',
                   1845:                           printmenu => 'yes',
                   1846:                           subroutine => \&toggle_debug,
                   1847:                           }));
                   1848:     }
1.76      albertel 1849: 
                   1850:     $r->print(&Apache::loncommon::start_page('Change Preferences'));
                   1851: 
1.35      matthew  1852:     my $call = undef;
1.48      albertel 1853:     my $help = undef;
1.35      matthew  1854:     my $printmenu = 'yes';
                   1855:     foreach my $option (@Options) {
1.59      albertel 1856:         if ($option->{'action'} eq $env{'form.action'}) {
1.35      matthew  1857:             $call = $option->{'subroutine'};
                   1858:             $printmenu = $option->{'printmenu'};
                   1859:             if (exists($option->{'breadcrumb'})) {
                   1860:                 &Apache::lonhtmlcommon::add_breadcrumb
                   1861:                     ($option->{'breadcrumb'});
                   1862:             }
1.48      albertel 1863: 	    $help=$option->{'help'};
1.35      matthew  1864:         }
                   1865:     }
1.81      albertel 1866:     $r->print(&Apache::lonhtmlcommon::breadcrumbs('Change Preferences',$help));
1.75      albertel 1867:     my $error;
1.35      matthew  1868:     if (defined($call)) {
1.75      albertel 1869:         $error = $call->($r);
1.35      matthew  1870:     }
1.75      albertel 1871:     if ( ( ($printmenu eq 'yes')
                   1872: 	   || ($printmenu eq 'not_on_error' && !$error) )
                   1873: 	 && (!$env{'form.returnurl'})) {
1.35      matthew  1874:         my $optionlist = '<table cellpadding="5">';
1.59      albertel 1875:         if ($env{'user.name'} =~ 
1.62      raeburn  1876:                          /^(albertel|kortemey|fox|foxr|korte|hallmat3|turtle|raeburn)$/
1.35      matthew  1877:             ) {
                   1878:             push (@Options,({ action => 'debugtoggle',
                   1879:                               linktext => 'Toggle Debug Messages',
                   1880:                               text => 'Current Debug status is -'.
1.59      albertel 1881:                                   $env{'user.debug'}.'-.',
1.35      matthew  1882:                               href => '/adm/preferences',
                   1883:                               printmenu => 'yes',
                   1884:                               subroutine => \&toggle_debug,
                   1885:                               }));
                   1886:         }
                   1887:         foreach my $option(@Options) {
                   1888:             my $optiontext = '';
                   1889:             if (exists($option->{'href'})) {
1.85      albertel 1890: 		$option->{'href_args'}{'action'}=$option->{'action'};
                   1891: 		$optiontext .= 
                   1892:                     '<a href="'.&add_get_param($option->{'href'},
                   1893: 					       $option->{'href_args'}).'">'.
1.47      albertel 1894:                     &mt($option->{'linktext'}).'</a>';
1.35      matthew  1895:             }
                   1896:             if (exists($option->{'text'})) {
1.47      albertel 1897:                 $optiontext .= ' '.&mt($option->{'text'});
1.35      matthew  1898:             }
                   1899:             if ($optiontext ne '') {
                   1900:                 $optiontext = '<font size="+1">'.$optiontext.'</font>'; 
                   1901:                 my $helplink = '&nbsp;';
                   1902:                 if (exists($option->{'help'})) {
                   1903:                     $helplink = &Apache::loncommon::help_open_topic
                   1904:                                                     ($option->{'help'});
                   1905:                 }
                   1906:                 $optionlist .= '<tr>'.
                   1907:                     '<td>'.$helplink.'</td>'.
                   1908:                     '<td>'.$optiontext.'</td>'.
                   1909:                     '</tr>';
                   1910:             }
1.13      www      1911:         }
1.35      matthew  1912:         $optionlist .= '</table>';
                   1913:         $r->print($optionlist);
1.59      albertel 1914:     } elsif ($env{'form.returnurl'}) {
                   1915: 	$r->print('<br /><a href="'.$env{'form.returnurl'}.'"><font size="+1">'.
1.44      www      1916: 		  &mt('Return').'</font></a>');
1.3       matthew  1917:     }
1.76      albertel 1918:     $r->print(&Apache::loncommon::end_page());
1.1       www      1919:     return OK;
1.35      matthew  1920: }
                   1921: 
                   1922: sub toggle_debug {
1.59      albertel 1923:     if ($env{'user.debug'}) {
1.35      matthew  1924:         &Apache::lonnet::delenv('user\.debug');
                   1925:     } else {
                   1926:         &Apache::lonnet::appenv('user.debug' => 1);
                   1927:     }
1.13      www      1928: }
1.1       www      1929: 
                   1930: 1;
                   1931: __END__

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