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

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

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