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

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

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