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

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

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