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

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

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