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

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

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