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

1.1       www         1: # The LearningOnline Network
                      2: # Preferences
                      3: #
1.225   ! raeburn     4: # $Id: lonpreferences.pm,v 1.224 2016/09/19 03:19:12 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.94      raeburn  1266:     my ($r,$errormessage,$caller,$mailtoken) = @_;
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})) {
                   1302:                 if (time - $data{'time'} < 7200) {
                   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.94      raeburn  1365:     $r->print(&jscript_send($caller));
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
                   1374:     $r->print(&server_form($logtoken,$caller,$mailtoken));
1.193     raeburn  1375:     $r->print(&client_form($caller,\%hexkey,$currentpass,$domain));
1.94      raeburn  1376: 
                   1377:     #
                   1378:     return;
                   1379: }
                   1380: 
                   1381: sub jscript_send {
                   1382:     my ($caller) = @_;
                   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') {
                   1404:         $output .= qq|
                   1405:         this.document.pserver.elements.uname.value =
                   1406:                    this.document.client.elements.uname.value;
                   1407:         this.document.pserver.elements.udom.value =
                   1408:                    this.document.client.elements.udom.options[this.document.client.elements.udom.selectedIndex].value;
1.173     raeburn  1409:         this.document.pserver.elements.email.value =
                   1410:                    this.document.client.elements.email.value;
1.94      raeburn  1411: |;
                   1412:     }
                   1413:     $ output .= qq|
1.52      raeburn  1414:         this.document.pserver.submit();
1.3       matthew  1415:     }
1.219     raeburn  1416: 
1.3       matthew  1417: </script>
1.94      raeburn  1418: |;
                   1419: }
1.3       matthew  1420: 
1.94      raeburn  1421: sub client_form {
                   1422:     my ($caller,$hexkey,$currentpass,$defdom) = @_;
1.99      www      1423:     my %lt=&Apache::lonlocal::texthash(
1.115     raeburn  1424:                 'email' => 'E-mail Address',
1.99      www      1425:                 'username' => 'Username',
                   1426:                 'domain' => 'Domain',
                   1427:                 'currentpass' => 'Current Password',
                   1428:                 'newpass' => 'New Password',
                   1429:                 'confirmpass' => 'Confirm Password',
1.169     raeburn  1430:                 'changepass' => 'Save',
                   1431:     );
1.99      www      1432: 
1.207     bisitz   1433:     my $output = '<form name="client" action="">'
1.164     bisitz   1434:                 .&Apache::lonhtmlcommon::start_pick_box();
1.94      raeburn  1435:     if ($caller eq 'reset_by_email') {
1.221     raeburn  1436:         my $mobileargs;
                   1437:         (undef,undef,undef,undef,undef,undef,my $clientmobile) =
                   1438:             &Apache::loncommon::decode_user_agent();
                   1439:         if ($clientmobile) {
                   1440:             $mobileargs = 'autocapitalize="off" autocorrect="off" ';
                   1441:         }
1.164     bisitz   1442:         $output .= &Apache::lonhtmlcommon::row_title(
                   1443:                        '<label for="email">'.$lt{'email'}.'</label>')
1.221     raeburn  1444:                   .'<input type="text" name="email" size="30" '.$mobileargs.'/>'
1.164     bisitz   1445:                   .&Apache::lonhtmlcommon::row_closure()
                   1446:                   .&Apache::lonhtmlcommon::row_title(
                   1447:                        '<label for="uname">'.$lt{'username'}.'</label>')
1.221     raeburn  1448:                   .'<input type="text" name="uname" size="20" '.$mobileargs.'/>'
1.164     bisitz   1449:                   .'<input type="hidden" name="currentpass" value="'.$currentpass.'" />'
                   1450:                   .&Apache::lonhtmlcommon::row_closure()
                   1451:                   .&Apache::lonhtmlcommon::row_title(
                   1452:                        '<label for="udom">'.$lt{'domain'}.'</label>')
                   1453:                   .&Apache::loncommon::select_dom_form($defdom,'udom')
                   1454:                   .&Apache::lonhtmlcommon::row_closure();
1.94      raeburn  1455:     } else {
1.164     bisitz   1456:         $output .= &Apache::lonhtmlcommon::row_title(
                   1457:                        '<label for="currentpass">'.$lt{'currentpass'}.'</label>')
1.219     raeburn  1458:                   .'<input type="password" name="currentpass" size="20"/>'
1.164     bisitz   1459:                   .&Apache::lonhtmlcommon::row_closure();
                   1460:     }
                   1461:     $output .= &Apache::lonhtmlcommon::row_title(
                   1462:                    '<label for="newpass_1">'.$lt{'newpass'}.'</label>')
1.219     raeburn  1463:               .'<input type="password" name="newpass_1" size="20" />'
1.164     bisitz   1464:               .&Apache::lonhtmlcommon::row_closure()
                   1465:               .&Apache::lonhtmlcommon::row_title(
                   1466:                    '<label for="newpass_2">'.$lt{'confirmpass'}.'</label>')
1.219     raeburn  1467:               .'<input type="password" name="newpass_2" size="20" />'
1.164     bisitz   1468:               .&Apache::lonhtmlcommon::row_closure(1)
                   1469:               .&Apache::lonhtmlcommon::end_pick_box();
1.206     bisitz   1470:     $output .= '<p><input type="button" value="'.$lt{'changepass'}.'" onclick="send();" /></p>'
1.164     bisitz   1471:               .qq|
1.94      raeburn  1472: <input type="hidden" name="ukey_cpass"  value="$hexkey->{'ukey_cpass'}" />
                   1473: <input type="hidden" name="lkey_cpass"  value="$hexkey->{'lkey_cpass'}" />
                   1474: <input type="hidden" name="ukey_npass1" value="$hexkey->{'ukey_npass1'}" />
                   1475: <input type="hidden" name="lkey_npass1" value="$hexkey->{'lkey_npass1'}" />
                   1476: <input type="hidden" name="ukey_npass2" value="$hexkey->{'ukey_npass2'}" />
                   1477: <input type="hidden" name="lkey_npass2" value="$hexkey->{'lkey_npass2'}" />
1.3       matthew  1478: </form>
                   1479: </p>
1.164     bisitz   1480: |;
1.94      raeburn  1481:     return $output;
                   1482: }
                   1483: 
                   1484: sub server_form {
                   1485:     my ($logtoken,$caller,$mailtoken) = @_;
                   1486:     my $action = '/adm/preferences';
                   1487:     if ($caller eq 'reset_by_email') {
                   1488:         $action = '/adm/resetpw';
                   1489:     }
                   1490:     my $output = qq|
                   1491: <form name="pserver" action="$action" method="post">
                   1492: <input type="hidden" name="logtoken"    value="$logtoken" />
                   1493: <input type="hidden" name="currentpass" value="" />
                   1494: <input type="hidden" name="newpass_1"   value="" />
                   1495: <input type="hidden" name="newpass_2"   value="" />
                   1496:     |;
                   1497:     if ($caller eq 'reset_by_email') {
                   1498:         $output .=  qq|
                   1499: <input type="hidden" name="token"   value="$mailtoken" />
                   1500: <input type="hidden" name="uname"   value="" />
                   1501: <input type="hidden" name="udom"   value="" />
1.173     raeburn  1502: <input type="hidden" name="email"   value="" />
1.94      raeburn  1503: 
                   1504: |;
                   1505:     }
                   1506:     $output .= qq|
                   1507: <input type="hidden" name="action" value="verify_and_change_pass" />
                   1508: </form>
                   1509: |;
                   1510:     return $output;
1.3       matthew  1511: }
                   1512: 
                   1513: sub verify_and_change_password {
1.94      raeburn  1514:     my ($r,$caller,$mailtoken) = @_;
                   1515:     my ($user,$domain,$homeserver);
1.217     raeburn  1516:     my ($blocked,$blocktext) =
                   1517:         &Apache::loncommon::blocking_status('passwd');
                   1518:     if ($blocked) {
                   1519:         $r->print('<p class="LC_warning">'.$blocktext.'</p>');
                   1520:         return;
                   1521:     }
1.94      raeburn  1522:     if ($caller eq 'reset_by_email') {
                   1523:         $user       = $env{'form.uname'};
                   1524:         $domain     = $env{'form.udom'};
                   1525:         if ($user ne '' && $domain ne '') {
                   1526:             $homeserver = &Apache::lonnet::homeserver($user,$domain);
                   1527:             if ($homeserver eq 'no_host') {
1.99      www      1528:         &passwordchanger($r,"<p>\n<span class='LC_error'>".
                   1529:                          &mt("Invalid username and/or domain")."</span>\n</p>",
1.94      raeburn  1530:                          $caller,$mailtoken);
                   1531:                 return 1;
                   1532:             }
                   1533:         } else {
1.99      www      1534:             &passwordchanger($r,"<p>\n<span class='LC_error'>".
                   1535:                              &mt("Username and domain were blank")."</span>\n</p>",
1.94      raeburn  1536:                              $caller,$mailtoken);
                   1537:             return 1;
                   1538:         }
                   1539:     } else {
                   1540:         $user       = $env{'user.name'};
                   1541:         $domain     = $env{'user.domain'};
                   1542:         $homeserver = $env{'user.home'};
                   1543:     }
1.3       matthew  1544:     my $currentauth=&Apache::lonnet::queryauthenticate($user,$domain);
1.4       matthew  1545:     # Check for authentication types that allow changing of the password.
1.94      raeburn  1546:     if ($currentauth !~ /^(unix|internal):/) {
                   1547:         if ($caller eq 'reset_by_email') {
1.99      www      1548:             &passwordchanger($r,"<p>\n<span class='LC_error'>".
                   1549:                              &mt("Authentication type for this user can not be changed by this mechanism").
                   1550:                              "</span>\n</p>",
1.94      raeburn  1551:                               $caller,$mailtoken);
                   1552:             return 1;
                   1553:         } else {
                   1554:             return;
                   1555:         }
                   1556:     }
1.3       matthew  1557:     #
1.59      albertel 1558:     my $currentpass = $env{'form.currentpass'}; 
                   1559:     my $newpass1    = $env{'form.newpass_1'}; 
                   1560:     my $newpass2    = $env{'form.newpass_2'};
                   1561:     my $logtoken    = $env{'form.logtoken'};
1.3       matthew  1562:     # Check for empty data 
1.4       matthew  1563:     unless (defined($currentpass) && 
                   1564: 	    defined($newpass1)    && 
                   1565: 	    defined($newpass2)    ){
1.99      www      1566: 	&passwordchanger($r,"<p>\n<span class='LC_error'>".
                   1567: 			 &mt("One or more password fields were blank").
                   1568:                          "</span>\n</p>",$caller,$mailtoken);
1.3       matthew  1569: 	return;
                   1570:     }
1.16      albertel 1571:     # Get the keys
                   1572:     my $lonhost = $r->dir_config('lonHostID');
1.3       matthew  1573:     my $tmpinfo = Apache::lonnet::reply('tmpget:'.$logtoken,$lonhost);
                   1574:     if (($tmpinfo=~/^error/) || ($tmpinfo eq 'con_lost')) {
1.4       matthew  1575:         # I do not a have a better idea about how to handle this
1.94      raeburn  1576:         my $tryagain_text = &mt('Please log out and try again.');
                   1577:         if ($caller eq 'reset_by_email') {
                   1578:             $tryagain_text = &mt('Please try again later.');
                   1579:         }
1.101     albertel 1580:         my $unable=&mt("Unable to retrieve saved token for password decryption");
1.3       matthew  1581: 	$r->print(<<ENDERROR);
                   1582: <p>
1.99      www      1583: <span class="LC_error">$unable.  $tryagain_text</span>
1.3       matthew  1584: </p>
                   1585: ENDERROR
1.4       matthew  1586:         # Probably should log an error here
1.75      albertel 1587:         return 1;
1.3       matthew  1588:     }
                   1589:     my ($ckey,$n1key,$n2key)=split(/&/,$tmpinfo);
1.219     raeburn  1590:     #
1.211     raeburn  1591:     $currentpass = &Apache::loncommon::des_decrypt($ckey ,$currentpass);
                   1592:     $newpass1    = &Apache::loncommon::des_decrypt($n1key,$newpass1);
                   1593:     $newpass2    = &Apache::loncommon::des_decrypt($n2key,$newpass2);
1.94      raeburn  1594:     #
                   1595:     if ($caller eq 'reset_by_email') {
                   1596:         my %data = &Apache::lonnet::tmpget($mailtoken);
1.117     raeburn  1597:         if (keys(%data) == 0) {
                   1598:             &passwordchanger($r,
                   1599:                          '<span class="LC_error">'.
                   1600:                          &mt('Could not verify current authentication.').'  '.
                   1601:                          &mt('Please try again.').'</span>',$caller,$mailtoken);
                   1602:             return 1;
                   1603:         }
1.94      raeburn  1604:         if ($currentpass ne $data{'temppasswd'}) {
                   1605:             &passwordchanger($r,
1.99      www      1606:                          '<span class="LC_error">'.
1.110     bisitz   1607:                          &mt('Could not verify current authentication.').'  '.
                   1608:                          &mt('Please try again.').'</span>',$caller,$mailtoken);
1.94      raeburn  1609:             return 1;
                   1610:         }
                   1611:     } 
1.3       matthew  1612:     if ($newpass1 ne $newpass2) {
1.4       matthew  1613: 	&passwordchanger($r,
1.199     bisitz   1614: 			 '<span class="LC_warning">'.
1.110     bisitz   1615: 			 &mt('The new passwords you entered do not match.').'  '.
                   1616: 			 &mt('Please try again.').'</span>',$caller,$mailtoken);
1.75      albertel 1617: 	return 1;
1.4       matthew  1618:     }
                   1619:     if (length($newpass1) < 7) {
                   1620: 	&passwordchanger($r,
1.199     bisitz   1621: 			 '<span class="LC_warning">'.
1.110     bisitz   1622: 			 &mt('Passwords must be a minimum of 7 characters long.').'  '.
                   1623: 			 &mt('Please try again.').'</span>',$caller,$mailtoken);
1.75      albertel 1624: 	return 1;
1.3       matthew  1625:     }
1.4       matthew  1626:     #
                   1627:     # Check for bad characters
                   1628:     my $badpassword = 0;
                   1629:     foreach (split(//,$newpass1)) {
                   1630: 	$badpassword = 1 if ((ord($_)<32)||(ord($_)>126));
                   1631:     }
                   1632:     if ($badpassword) {
                   1633: 	# I can't figure out how to enter bad characters on my browser.
1.199     bisitz   1634: 	my $errormessage ='<span class="LC_warning">'.
1.110     bisitz   1635:            &mt('The password you entered contained illegal characters.').'<br />'.
1.99      www      1636:            &mt('Valid characters are').(<<"ENDERROR");
                   1637: : space and <br />
1.4       matthew  1638: <pre>
                   1639: !&quot;\#$%&amp;\'()*+,-./0123456789:;&lt;=&gt;?\@
                   1640: ABCDEFGHIJKLMNOPQRSTUVWXYZ[\]^_\`abcdefghijklmnopqrstuvwxyz{|}~
1.99      www      1641: </pre></span>
1.4       matthew  1642: ENDERROR
1.94      raeburn  1643:         &passwordchanger($r,$errormessage,$caller,$mailtoken);
                   1644:         return 1;
1.4       matthew  1645:     }
                   1646:     # 
                   1647:     # Change the password (finally)
                   1648:     my $result = &Apache::lonnet::changepass
1.94      raeburn  1649: 	($user,$domain,$currentpass,$newpass1,$homeserver,$caller);
1.4       matthew  1650:     # Inform the user the password has (not?) been changed
1.126     droeschl 1651:     my $message;
1.4       matthew  1652:     if ($result =~ /^ok$/) {
1.170     bisitz   1653:         $message = &Apache::lonhtmlcommon::confirm_success(&mt('The password for user [_1] was successfully changed.','<i>'.$user.'</i>'));
1.180     wenzelju 1654:         $message = &Apache::loncommon::confirmwrapper($message);
1.144     raeburn  1655:         if ($caller eq 'reset_by_email') {
                   1656:             $r->print($message.'<br />');
                   1657:         } else {
                   1658:             &print_main_menu($r, $message);
                   1659:         }
1.4       matthew  1660:     } else {
                   1661: 	# error error: run in circles, scream and shout
1.173     raeburn  1662:         if ($caller eq 'reset_by_email') {
                   1663:             if (!$result) {
                   1664:                 return 1;
                   1665:             } else {
                   1666:                 return $result;
                   1667:             }
                   1668:         } else {
                   1669:             $message = &Apache::lonhtmlcommon::confirm_success(
                   1670:                 &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   1671:             $message=&Apache::loncommon::confirmwrapper($message);
1.144     raeburn  1672:             &print_main_menu($r, $message);
                   1673:         }
1.4       matthew  1674:     }
                   1675:     return;
1.3       matthew  1676: }
                   1677: 
1.42      raeburn  1678: ################################################################
                   1679: #            discussion display subroutines 
                   1680: ################################################################
                   1681: sub discussionchanger {
                   1682:     my $r = shift;
1.126     droeschl 1683:     Apache::lonhtmlcommon::add_breadcrumb(
                   1684: 	    {	href => '/adm/preferences?action=changediscussions',
                   1685:                 text => 'Change Discussion Preferences'});
1.178     bisitz   1686:     $r->print(Apache::loncommon::start_page('Change Discussion Preferences'));
1.126     droeschl 1687:     $r->print(Apache::lonhtmlcommon::breadcrumbs('Change Discussion Preferences'));
1.59      albertel 1688:     my $user       = $env{'user.name'};
                   1689:     my $domain     = $env{'user.domain'};
1.42      raeburn  1690:     my %userenv = &Apache::lonnet::get
1.43      raeburn  1691:         ('environment',['discdisplay','discmarkread']);
                   1692:     my $discdisp = 'allposts';
                   1693:     my $discmark = 'onmark';
                   1694: 
                   1695:     if (defined($userenv{'discdisplay'})) {
                   1696:         unless ($userenv{'discdisplay'} eq '') { 
                   1697:             $discdisp = $userenv{'discdisplay'};
                   1698:         }
                   1699:     }
                   1700:     if (defined($userenv{'discmarkread'})) {
1.171     raeburn  1701:         unless ($userenv{'discmarkread'} eq '') { 
1.43      raeburn  1702:             $discmark = $userenv{'discmarkread'};
                   1703:         }
                   1704:     }
                   1705: 
                   1706:     my $newdisp = 'unread';
                   1707:     my $newmark = 'ondisp';
                   1708: 
                   1709:     my $function = &Apache::loncommon::get_users_function();
                   1710:     my $color = &Apache::loncommon::designparm($function.'.tabbg',
1.59      albertel 1711:                                                     $env{'user.domain'});
1.43      raeburn  1712:     my %lt = &Apache::lonlocal::texthash(
                   1713:         'pref' => 'Display Preference',
                   1714:         'curr' => 'Current setting ',
                   1715:         'actn' => 'Action',
1.135     schafran 1716:         'sdpf' => 'Set display preferences for discussion posts for both discussion boards and individual resources in all your courses.',
1.43      raeburn  1717:         'prca' => 'Preferences can be set that determine',
1.135     schafran 1718:         'whpo' => 'Which posts are displayed when you display a discussion board or resource, and',
1.194     raeburn  1719:         'unwh' => 'Under what circumstances posts are identified as "NEW"',
1.43      raeburn  1720:         'allposts' => 'All posts',
                   1721:         'unread' => 'New posts only',
                   1722:         'ondisp' => 'Once displayed',
1.194     raeburn  1723:         'onmark' => 'Once marked not NEW',
1.43      raeburn  1724:         'disa' => 'Posts displayed?',
1.194     raeburn  1725:         'npmr' => 'New posts cease to be identified as "NEW"?',
1.43      raeburn  1726:         'thde'  => 'The preferences you set here can be overridden within each individual discussion.',
                   1727:         'chgt' => 'Change to '
                   1728:     );
                   1729:     my $dispchange = $lt{'unread'};
                   1730:     my $markchange = $lt{'ondisp'};
                   1731:     my $currdisp = $lt{'allposts'};
                   1732:     my $currmark = $lt{'onmark'};
                   1733: 
                   1734:     if ($discdisp eq 'unread') {
                   1735:         $dispchange = $lt{'allposts'};
                   1736:         $currdisp = $lt{'unread'};
                   1737:         $newdisp = 'allposts';
                   1738:     }
                   1739: 
                   1740:     if ($discmark eq 'ondisp') {
                   1741:         $markchange = $lt{'onmark'};
                   1742:         $currmark = $lt{'ondisp'};
                   1743:         $newmark = 'onmark';
1.42      raeburn  1744:     }
1.171     raeburn  1745: 
1.43      raeburn  1746:     $r->print(<<"END");
1.88      albertel 1747: <form name="prefs" action="/adm/preferences" method="post">
1.42      raeburn  1748: <input type="hidden" name="action" value="verify_and_change_discussion" />
                   1749: <br />
1.87      albertel 1750: $lt{'sdpf'}<br /> $lt{'prca'}  <ol><li>$lt{'whpo'}</li><li>$lt{'unwh'}</li></ol> 
1.82      albertel 1751: END
1.158     bisitz   1752: 
                   1753:     $r->print('<p class="LC_info">'.$lt{'thde'}.'</p>');
                   1754: 
1.82      albertel 1755:     $r->print(&Apache::loncommon::start_data_table());
                   1756:     $r->print(<<"END");
                   1757:        <tr>
                   1758:         <th>$lt{'pref'}</th>
                   1759:         <th>$lt{'curr'}</th>
                   1760:         <th>$lt{'actn'}?</th>
1.43      raeburn  1761:        </tr>
1.82      albertel 1762: END
                   1763:     $r->print(&Apache::loncommon::start_data_table_row());
                   1764:     $r->print(<<"END");
1.43      raeburn  1765:        <td>$lt{'disa'}</td>
                   1766:        <td>$lt{$discdisp}</td>
1.82      albertel 1767:        <td><label><input type="checkbox" name="discdisp" /><input type="hidden" name="newdisp" value="$newdisp" />&nbsp;$lt{'chgt'} "$dispchange"</label></td>
                   1768: END
                   1769:     $r->print(&Apache::loncommon::end_data_table_row().
                   1770: 	      &Apache::loncommon::start_data_table_row());
                   1771:     $r->print(<<"END");
1.43      raeburn  1772:        <td>$lt{'npmr'}</td>
                   1773:        <td>$lt{$discmark}</td>
1.82      albertel 1774:        <td><label><input type="checkbox" name="discmark" /><input type="hidden" name="newmark" value="$newmark" />&nbsp;$lt{'chgt'} "$markchange"</label></td>
1.43      raeburn  1775:       </tr>
1.82      albertel 1776: END
                   1777:     $r->print(&Apache::loncommon::end_data_table_row().
                   1778: 	      &Apache::loncommon::end_data_table());
1.142     zhu      1779: 
1.158     bisitz   1780:     $r->print('<br />'
                   1781:              .'<input type="submit" name="sub" value="'.&mt('Save').'" />'
                   1782:              .'</form>'
                   1783:     );
1.42      raeburn  1784: }
                   1785:                                                                                                                 
                   1786: sub verify_and_change_discussion {
                   1787:     my $r = shift;
1.59      albertel 1788:     my $user     = $env{'user.name'};
                   1789:     my $domain   = $env{'user.domain'};
1.42      raeburn  1790:     my $message='';
1.59      albertel 1791:     if (defined($env{'form.discdisp'}) ) {
                   1792:         my $newdisp  = $env{'form.newdisp'};
1.43      raeburn  1793:         if ($newdisp eq 'unread') {
1.171     raeburn  1794:             $message .=&Apache::lonhtmlcommon::confirm_success(&mt('In discussions: only new posts will be displayed.')).'<br />';
1.43      raeburn  1795:             &Apache::lonnet::put('environment',{'discdisplay' => $newdisp});
1.116     raeburn  1796:             &Apache::lonnet::appenv({'environment.discdisplay' => $newdisp});
1.43      raeburn  1797:         } else {
1.171     raeburn  1798:             $message .= &Apache::lonhtmlcommon::confirm_success(&mt('In discussions: all posts will be displayed.')).'<br />';
1.43      raeburn  1799:             &Apache::lonnet::del('environment',['discdisplay']);
1.139     raeburn  1800:             &Apache::lonnet::delenv('environment.discdisplay');
1.43      raeburn  1801:         }
                   1802:     }
1.59      albertel 1803:     if (defined($env{'form.discmark'}) ) {
                   1804:         my $newmark = $env{'form.newmark'};
1.43      raeburn  1805:         if ($newmark eq 'ondisp') {
1.209     bisitz   1806:             $message.=&Apache::lonhtmlcommon::confirm_success(&mt('In discussions: new posts will cease to be identified as "NEW" after display.')).'<br />';
1.43      raeburn  1807:             &Apache::lonnet::put('environment',{'discmarkread' => $newmark});
1.116     raeburn  1808:             &Apache::lonnet::appenv({'environment.discmarkread' => $newmark});
1.43      raeburn  1809:         } else {
1.194     raeburn  1810:             $message.=&Apache::lonhtmlcommon::confirm_success(&mt('In discussions: posts will be identified as "NEW" until marked as not "NEW".')).'<br />';
1.43      raeburn  1811:             &Apache::lonnet::del('environment',['discmarkread']);
1.139     raeburn  1812:             &Apache::lonnet::delenv('environment.discmarkread');
1.43      raeburn  1813:         }
1.42      raeburn  1814:     }
1.158     bisitz   1815:     $message=&Apache::loncommon::confirmwrapper($message);
1.152     www      1816:     &print_main_menu($r, $message);
1.42      raeburn  1817: }
                   1818: 
1.63      raeburn  1819: ################################################################
                   1820: # Subroutines for page display on course access (Course Coordinators)
                   1821: ################################################################
                   1822: sub coursedisplaychanger {
                   1823:     my $r = shift;
1.152     www      1824:     &Apache::lonhtmlcommon::add_breadcrumb(
1.126     droeschl 1825: 	    {	href => '/adm/preferences?action=changecourseinit',
                   1826:                 text => 'Change Course Init. Pref.'});
                   1827:     $r->print(Apache::loncommon::start_page('Change Course Initialization Preference'));
                   1828:     $r->print(Apache::lonhtmlcommon::breadcrumbs('Change Course Init. Pref.'));
1.63      raeburn  1829:     my $user       = $env{'user.name'};
                   1830:     my $domain     = $env{'user.domain'};
1.66      albertel 1831:     my %userenv = &Apache::lonnet::get('environment',['course_init_display']);
1.71      raeburn  1832:     my $currvalue = 'whatsnew';
1.73      albertel 1833:     my $firstselect = '';
                   1834:     my $whatsnewselect = 'checked="checked"';
1.71      raeburn  1835:     if (exists($userenv{'course_init_display'})) {
                   1836:         if ($userenv{'course_init_display'} eq 'firstres') {
                   1837:             $currvalue = 'firstres';
1.73      albertel 1838:             $firstselect = 'checked="checked"';
                   1839: 	    $whatsnewselect = '';
1.71      raeburn  1840:         }
1.63      raeburn  1841:     }
1.134     bisitz   1842:     my %pagenames = &Apache::lonlocal::texthash(
1.71      raeburn  1843:                        firstres => 'First resource',
1.143     hauer    1844:                        whatsnew => "What's New Page",
1.71      raeburn  1845:                     );
1.134     bisitz   1846:     my $whatsnew_off=&mt('Display the [_1]first resource[_2] in the course.','<b>','</b>');
1.143     hauer    1847:     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  1848: 
1.134     bisitz   1849:     $r->print('<br /><b>'
                   1850:              .&mt('Set the default page to be displayed when you select a course role')
                   1851:              .'</b>&nbsp;'
                   1852:              .&mt('(Currently: [_1])',$pagenames{$currvalue})
                   1853:              .'<br />'
1.143     hauer    1854:              .&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   1855:              .'<br /><br />'
                   1856:     );
1.63      raeburn  1857:     $r->print(<<ENDLSCREEN);
1.88      albertel 1858: <form name="prefs" action="/adm/preferences" method="post">
1.63      raeburn  1859: <input type="hidden" name="action" value="verify_and_change_coursepage" />
1.72      albertel 1860: <br />
1.65      albertel 1861: <label><input type="radio" name="newdisp" value="firstres" $firstselect /> $whatsnew_off</label><br />
1.70      raeburn  1862: <label><input type="radio" name="newdisp" value="whatsnew" $whatsnewselect /> $whatsnew_on</label><input type="hidden" name="refpage" value="$env{'form.refpage'}" />
1.63      raeburn  1863: ENDLSCREEN
1.140     schafran 1864:     $r->print('<br /><br /><input type="submit" value="'.&mt('Save').'" />
1.63      raeburn  1865: </form>');
                   1866: }
                   1867: 
                   1868: sub verify_and_change_coursepage {
                   1869:     my $r = shift;
                   1870:     my $message='';
                   1871:     my %lt = &Apache::lonlocal::texthash(
1.70      raeburn  1872:         'defs' => 'Default now set',
1.71      raeburn  1873:         'when' => 'when you select a course role from the roles screen',
1.63      raeburn  1874:         'ywbt' => 'you will be taken to the start of the course.',
                   1875:         'apwb' => 'a page will be displayed that lists items in the course that may require action from you.',
                   1876:         'gtts' => 'Go to the start of the course',
1.146     hauer    1877:         'dasp' => "Display the What's New Page", 
1.63      raeburn  1878:     );
                   1879:     my $newdisp  = $env{'form.newdisp'};
1.70      raeburn  1880:     $message = '<b>'.$lt{'defs'}.'</b>: '.$lt{'when'}.', ';
1.63      raeburn  1881:     if ($newdisp eq 'firstres') {
1.87      albertel 1882:         $message .= $lt{'ywbt'}.'<br />';
1.63      raeburn  1883:         &Apache::lonnet::put('environment',{'course_init_display' => $newdisp});
1.116     raeburn  1884:         &Apache::lonnet::appenv({'environment.course_init_display' => $newdisp});
1.63      raeburn  1885:     } else {
1.87      albertel 1886:         $message .= $lt{'apwb'}.'<br />';
1.63      raeburn  1887:         &Apache::lonnet::del('environment',['course_init_display']);
1.139     raeburn  1888:         &Apache::lonnet::delenv('environment.course_init_display');
1.63      raeburn  1889:     }
1.70      raeburn  1890:     my $refpage = $env{'form.refpage'};
1.63      raeburn  1891:     if (($env{'request.course.fn'}) && ($env{'request.course.id'})) {
                   1892:         if ($newdisp eq 'firstres') {
                   1893:             my $cdom = $env{'course.'.$env{'request.course.id'}.'.domain'};
                   1894:             my $cnum = $env{'course.'.$env{'request.course.id'}.'.num'}; 
                   1895:             my ($furl,$ferr)=
                   1896:                 &Apache::lonuserstate::readmap($cdom.'/'.$cnum);
1.180     wenzelju 1897:             $message .= '<br /><a href="'.$furl.'">'.$lt{'gtts'}.' <i>'.&mt('now').'</i></a>';
1.63      raeburn  1898:         } else {
1.180     wenzelju 1899:             $message .= '<br /><a href="/adm/whatsnew?refpage='.
                   1900:                         $refpage.'">'.$lt{'dasp'}.'</a>';
1.63      raeburn  1901:         }
                   1902:     }
1.180     wenzelju 1903:     $message = &Apache::lonhtmlcommon::confirm_success($message);
                   1904:     $message = &Apache::loncommon::confirmwrapper($message);
                   1905:     &print_main_menu($r,$message);
1.63      raeburn  1906: }
                   1907: 
1.215     golterma 1908: sub author_space_settings {
                   1909:     my $r = shift;
                   1910:     &Apache::lonhtmlcommon::add_breadcrumb(
                   1911:             {   href => '/adm/preferences?action=authorsettings',
                   1912:                 text => 'Authoring Space Settings'});
                   1913:     my $user       = $env{'user.name'};
                   1914:     my $domain     = $env{'user.domain'};
                   1915:     my %author_roles = &Apache::lonnet::get_my_roles($user,$domain,'userroles','',['au','ca','aa']);
                   1916:     if (keys(%author_roles) > 0) {
                   1917:             $r->print(Apache::loncommon::start_page('Authoring Space Settings'));
                   1918:             $r->print(Apache::lonhtmlcommon::breadcrumbs('Authoring Space Settings'));
                   1919:             my %userenv = &Apache::lonnet::get('environment',['nocodemirror']);
                   1920:             my $constchecked='';
                   1921:             if ($env{'environment.nocodemirror'}) {
                   1922:                $constchecked=' checked="checked"';
                   1923:             }
1.216     droeschl 1924:             my $text=&mt('By default, CodeMirror an editor with advanced functionality for editing code is activated for authors.');
                   1925:             my $cmoff=&mt('Deactivate CodeMirror. This can improve performance on slow computers and accessibility.');
1.215     golterma 1926:             my $change=&mt('Save');
1.225   ! raeburn  1927:             my $returnurl = &HTML::Entities::encode($env{'form.returnurl'},'"<>&\'');
1.215     golterma 1928:             $r->print(<<ENDSCREEN);
                   1929:         <form name="prefs" action="/adm/preferences" method="post">
1.225   ! raeburn  1930:         <input type="hidden" name="returnurl" value="$returnurl" />
1.215     golterma 1931:         <input type="hidden" name="action" value="change_authoring_settings" />
                   1932:         $text<br />
                   1933:         <label><input type="checkbox" name="cmoff"$constchecked />$cmoff</label><br />
                   1934:         <input type="submit" value="$change" />
                   1935:         </form>
                   1936: ENDSCREEN
                   1937:     }
                   1938: }
                   1939: 
                   1940: sub change_authoring_settings {
                   1941:     my $r = shift;
                   1942:     my $user       = $env{'user.name'};
                   1943:     my $domain     = $env{'user.domain'};
                   1944:     my %author_roles = &Apache::lonnet::get_my_roles($user,$domain,'userroles','',['au','ca','aa']);
                   1945:     if (keys(%author_roles) > 0) {
                   1946:             my %ausettings=('environment.nocodemirror' => '');
                   1947:             if ($env{'form.cmoff'}) { $ausettings{'environment.nocodemirror'}='yes'; }
                   1948:             &Apache::lonnet::put('environment',\%ausettings);
                   1949:             &Apache::lonnet::appenv({'environment.nocodemirror' => $ausettings{'environment.nocodemirror'}});
                   1950:             my $status='';
                   1951:             if ($ausettings{'environment.nocodemirror'} eq 'yes') {
                   1952:                 $status=&mt('on');
                   1953:             } else {
                   1954:                 $status=&mt('off');
                   1955:             }
1.216     droeschl 1956:             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 1957:             $message=&Apache::loncommon::confirmwrapper($message);
1.225   ! raeburn  1958:             if ($env{'form.returnurl'}) {
        !          1959:                 &do_redirect($r,$env{'form.returnurl'},$message);
        !          1960:             } else {
        !          1961:                 &print_main_menu($r,$message);
        !          1962:             }
1.215     golterma 1963:     }
                   1964: }
                   1965: 
1.186     raeburn  1966: sub lockednameschanger {
                   1967:     my $r = shift;
                   1968:     &Apache::lonhtmlcommon::add_breadcrumb(
                   1969:             {   href => '/adm/preferences?action=changelockednames',
                   1970:                 text => 'Automatic name changes'});
                   1971:     $r->print(Apache::loncommon::start_page('Automatic name changes'));
                   1972:     $r->print(Apache::lonhtmlcommon::breadcrumbs('Allow/disallow name updates'));
                   1973:     my %userenv = &Apache::lonnet::get('environment',['lockedname']);
                   1974:     my $lockedname='';
                   1975:     if (&can_toggle_namelocking()) {
                   1976:         if ($userenv{'lockedname'}) {
                   1977:             $lockedname = ' checked="checked"';
                   1978:         }
                   1979:         my %updateable;
                   1980:         my %domconfig =
                   1981:             &Apache::lonnet::get_dom('configuration',['autoupdate'],$env{'user.domain'});
                   1982:         if (ref($domconfig{'autoupdate'}) eq 'HASH') {
                   1983:             if ($domconfig{'autoupdate'}{'run'}) {
                   1984:                 my @inststatuses = split(':',$env{'environment.inststatus'});
                   1985:                 unless (@inststatuses) {
                   1986:                     @inststatuses = ('default');
                   1987:                 }
                   1988:                 %updateable = &updateable_userinfo($domconfig{'autoupdate'},\@inststatuses);
                   1989:             }
                   1990:         }
                   1991:         if (keys(%updateable)) {
                   1992:             my %longnames = &Apache::lonlocal::texthash (
                   1993:                                 firstname  => 'First Name',
                   1994:                                 middlename => 'Middle Name',
                   1995:                                 lastname   => 'Last Name',
                   1996:                             );
                   1997:             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:').
                   1998:                      '<ul>';
                   1999:            foreach my $item ('firstname','middlename','lastname') {
                   2000:                if ($updateable{$item}) {
                   2001:                    $text .= '<li>'.$longnames{$item}.'</li>';
                   2002:                }
                   2003:            }
                   2004:            $text .= '</ul>'; 
                   2005:            my $locking=&mt('Disallow automatic updates to name information for your LON-CAPA account');
                   2006:            my $change=&mt('Save');
                   2007:            $r->print(<<ENDSCREEN);
                   2008: <form name="prefs" action="/adm/preferences" method="post">
                   2009: <input type="hidden" name="action" value="verify_and_change_lockednames" />
                   2010: $text<br />
                   2011: <label><input type="checkbox" value="1" name="lockednames"$lockedname />$locking</label><br />
                   2012: <input type="submit" value="$change" />
                   2013: </form>
                   2014: ENDSCREEN
                   2015:         } else {
                   2016:             my $message = &mt('Based on your institutional affiliation no name information is automatically updated for your LON-CAPA account.');
                   2017:             &print_main_menu($r,$message);
                   2018:         }
                   2019:     } else {
                   2020:         my $message = &mt('You are not permitted to set a user preference for automatic name updates for your LON-CAPA account.');
                   2021:         &print_main_menu($r,$message);
                   2022:     }
                   2023: }
                   2024: 
                   2025: sub verify_and_change_lockednames {
                   2026:     my $r = shift;
                   2027:     my $message;
                   2028:     if (&can_toggle_namelocking()) {
                   2029:         my $newlockedname = $env{'form.lockednames'};
                   2030:         $newlockedname =~ s/\D//g;
                   2031:         my $currlockedname = $env{'environment.lockedname'};
                   2032:         if ($newlockedname ne $currlockedname) {
                   2033:             if ($newlockedname) {
                   2034:                 if (&Apache::lonnet::put('environment',{lockedname => $newlockedname}) eq 'ok') {
                   2035:                     &Apache::lonnet::appenv({'environment.lockedname' => $newlockedname});
                   2036:                 }
                   2037:             } elsif (&Apache::lonnet::del('environment',['lockedname']) eq 'ok') {
                   2038:                 &Apache::lonnet::delenv('environment.lockedname');
                   2039:             }
                   2040:         }
                   2041:         my $status='';
                   2042:         if ($newlockedname) {
                   2043:             $status=&mt('disallowed');
                   2044:         } else {
                   2045:             $status=&mt('allowed');
                   2046:         }
                   2047:         $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>'));
                   2048:         $message=&Apache::loncommon::confirmwrapper($message);
                   2049:     }
                   2050:     &print_main_menu($r,$message);
                   2051: }
                   2052: 
1.126     droeschl 2053: sub print_main_menu {
                   2054:     my ($r, $message) = @_;
                   2055:     # Determine current authentication method
                   2056:     my $user = $env{'user.name'};
                   2057:     my $domain = $env{'user.domain'};
                   2058:     my $currentauth=&Apache::lonnet::queryauthenticate($user,$domain);
                   2059: 
                   2060:     # build the data structure for menu generation
                   2061: my $aboutmeurl='/adm/'.$env{'user.domain'}.'/'.$env{'user.name'}.'/aboutme';
                   2062: my $role = ($env{'user.adv'} ? 'Roles' : 'Course');
1.131     raeburn  2063: my %permissions;
                   2064: if (&Apache::lonnet::usertools_access($user,$domain,'aboutme')) {
                   2065:     $permissions{'aboutme'} = 'F';
                   2066: }
1.126     droeschl 2067: my @menu=
                   2068:     ({	categorytitle=>'Personal Data',
                   2069: 	items =>[
1.141     weissno  2070: 	    {	linktext => 'Personal Information Page',
1.126     droeschl 2071: 		url => $aboutmeurl,
1.131     raeburn  2072: 		permission => $permissions{'aboutme'},
1.126     droeschl 2073: 		#help => 'Prefs_About_Me',
                   2074: 		icon => 'system-users.png',
                   2075: 		linktitle => 'Edit information about yourself that should be displayed on your public profile.'
                   2076: 	    },
                   2077: 	    {	linktext => 'Screen Name',
                   2078: 		url => '/adm/preferences?action=changescreenname',
                   2079: 		permission => 'F',
                   2080: 		#help => 'Prefs_Screen_Name_Nickname',
                   2081: 		icon => 'preferences-desktop-font.png',
                   2082: 		linktitle => 'Change the name that is displayed in your posts.'
                   2083: 	    },
                   2084: 		]
                   2085:     },
                   2086:     {	categorytitle=>'Content Display Settings',
                   2087: 	items =>[
                   2088: 	    {	linktext => 'Language',
                   2089: 		url => '/adm/preferences?action=changelanguages',
                   2090: 		permission => 'F',
                   2091: 		#help => 'Prefs_Language',
                   2092: 		icon => 'preferences-desktop-locale.png',
1.127     droeschl 2093: 		linktitle => 'Choose the default language for this user.'
1.126     droeschl 2094: 	    },
1.128     droeschl 2095: 	    {	linktext => $role.' Page',
1.126     droeschl 2096: 		url => '/adm/preferences?action=changerolespref',
                   2097: 		permission => 'F',
                   2098: 		#help => '',
1.189     wenzelju 2099: 		icon => 'role_hotlist.png',
1.126     droeschl 2100: 		linktitle => 'Configure the roles hotlist.'
                   2101: 	    },
1.177     raeburn  2102: 	    {	linktext => 'Math display settings',
1.126     droeschl 2103: 		url => '/adm/preferences?action=changetexenginepref',
                   2104: 		permission => 'F',
                   2105: 		#help => '',
1.188     wenzelju 2106: 		icon => 'dismath.png',
1.177     raeburn  2107: 		linktitle => 'Change how math is displayed.'
1.126     droeschl 2108: 	    },
                   2109: 		]
                   2110:     },
1.185     droeschl 2111:     {	categorytitle=>'Page Display Settings',
                   2112: 	items =>[
                   2113: 	    {	linktext => 'Color Scheme',
                   2114: 		url => '/adm/preferences?action=changecolors',
                   2115: 		permission => 'F',
                   2116: 		#help => 'Change_Colors',
                   2117: 		icon => 'preferences-desktop-theme.png',
                   2118: 		linktitle => 'Change LON-CAPA default colors.'
                   2119: 	    },
1.192     raeburn  2120:             {   linktext => 'Menu Display',
                   2121:                 url => '/adm/preferences?action=changeicons',
                   2122:                 permission => 'F',
                   2123:                 #help => '',
                   2124:                 icon => 'preferences-system-windows.png',
                   2125:                 linktitle => 'Change whether the menus are displayed with icons or icons and text.'
                   2126:             }
1.185     droeschl 2127: 		]
                   2128:     },
1.178     bisitz   2129:     {	categorytitle=>'Messages &amp; Notifications',
1.128     droeschl 2130: 	items =>[
1.153     www      2131: 	    {	linktext => 'Messages &amp; Notifications',
1.128     droeschl 2132: 		url => '/adm/preferences?action=changemsgforward',
                   2133: 		permission => 'F',
                   2134: 		#help => 'Prefs_Messages',
                   2135: 		icon => 'mail-reply-all.png',
                   2136: 		linktitle => 'Change messageforwarding or notifications settings.'
                   2137: 	    },
                   2138: 	    {	linktext => 'Discussion Display',
                   2139: 		url => '/adm/preferences?action=changediscussions',
                   2140: 		permission => 'F',
                   2141: 		#help => 'Change_Discussion_Display',
1.191     riegler  2142: 		icon => 'chat.png',
1.135     schafran 2143: 		linktitle => 'Set display preferences for discussion posts for both discussion boards and individual resources in all your courses.'
1.128     droeschl 2144: 	    },
                   2145: 		]
                   2146:     },
1.126     droeschl 2147:     {	categorytitle=>'Other',
                   2148: 	items =>[
1.153     www      2149: 	    {	linktext => 'Register Response Devices (&quot;Clickers&quot;)',
1.126     droeschl 2150: 		url => '/adm/preferences?action=changeclicker',
                   2151: 		permission => 'F',
                   2152: 		#help => '',
                   2153: 		icon => 'network-workgroup.png',
                   2154: 		linktitle => 'Register your clicker.'
                   2155: 	    },
                   2156: 		]
                   2157:     },
                   2158:     );
                   2159: 
                   2160:     if ($currentauth =~ /^(unix|internal):/) {
                   2161: push(@{ $menu[0]->{items} }, {
                   2162: 	linktext => 'Password',
                   2163: 	url => '/adm/preferences?action=changepass',
                   2164: 	permission => 'F',
                   2165: 	#help => 'Change_Password',
                   2166: 	icon => 'emblem-readonly.png',
                   2167: 	linktitle => 'Change your password.',
                   2168: 	});
                   2169:     }
1.186     raeburn  2170: 
                   2171:     if (&can_toggle_namelocking()) {
                   2172:         push(@{ $menu[0]->{items} }, {
                   2173:         linktext => 'Automatic name changes',
                   2174:         url => '/adm/preferences?action=changelockednames',
                   2175:         permission => 'F',
                   2176:         #help => '',
                   2177:         icon => 'system-lock-screen.png',
                   2178:         linktitle => 'Allow/disallow propagation of name changes from institutional directory service',
                   2179:         });
                   2180:     }
                   2181: 
1.126     droeschl 2182:     my %author_roles = &Apache::lonnet::get_my_roles($user,$domain,'userroles','',['au']);
                   2183:     if (keys(%author_roles) > 0) {
                   2184: push(@{ $menu[4]->{items} }, {
                   2185: 	linktext => 'Restrict Domain Coordinator Access',
                   2186: 	url => '/adm/preferences?action=changedomcoord',
                   2187: 	permission => 'F',
                   2188: 	#help => '',
                   2189: 	icon => 'system-lock-screen.png',
                   2190: 	linktitle => 'Restrict domain coordinator access.',
                   2191: 	});
                   2192:     }
                   2193: 
                   2194:     if (&Apache::lonnet::allowed('whn',$env{'request.course.id'})
                   2195: 	|| &Apache::lonnet::allowed('whn',$env{'request.course.id'}.'/'
                   2196: 				    .$env{'request.course.sec'})) {
                   2197: push(@{ $menu[4]->{items} }, {
1.128     droeschl 2198: 	linktext => 'Course Initialization',
1.126     droeschl 2199: 	url => '/adm/preferences?action=changecourseinit',
                   2200: 	permission => 'F',
                   2201: 	#help => '',
1.189     wenzelju 2202: 	icon => 'course_ini.png',
1.126     droeschl 2203: 	linktitle => 'Set the default page to be displayed when you select a course role.',
                   2204: 	});
                   2205: 
                   2206:     }
1.215     golterma 2207: 
1.222     raeburn  2208:     my %author_coauthor_roles = &Apache::lonnet::get_my_roles($user,$domain,'userroles','',['au','ca','aa']);
                   2209:     if (keys(%author_coauthor_roles) > 0) {
1.215     golterma 2210:         push(@{ $menu[4]->{items} }, {
                   2211:             linktext => 'Authoring Space Configuration',
                   2212:             url => '/adm/preferences?action=authorsettings',
                   2213:             permission => 'F',
1.224     raeburn  2214:             icon => 'codemirror.png',
1.215     golterma 2215:             linktitle => 'Settings for your authoring space.',
                   2216:         });
                   2217:     }
                   2218: 
1.174     raeburn  2219:     if (&can_toggle_debug()) {
1.126     droeschl 2220: push(@{ $menu[4]->{items} }, {
1.174     raeburn  2221: 	linktext => 'Toggle Debug Messages (Currently '.($env{'user.debug'} ? 'on)' : 'off)'),
1.126     droeschl 2222: 	url => '/adm/preferences?action=debugtoggle',
                   2223: 	permission => 'F',
                   2224: 	#help => '',
                   2225: 	icon => 'blog.png',
                   2226: 	linktitle => 'Toggle Debug Messages.',
                   2227: 	});
1.186     raeburn  2228:     }
1.126     droeschl 2229: 
1.147     schafran 2230:     $r->print(&Apache::loncommon::start_page('My Space'));
1.126     droeschl 2231:     $r->print(Apache::lonhtmlcommon::breadcrumbs('Change Preferences'));
                   2232:     $r->print($message);
                   2233:     $r->print(Apache::lonhtmlcommon::generate_menu(@menu));
                   2234:     $r->print(Apache::loncommon::end_page());
                   2235: }
1.63      raeburn  2236: 
1.4       matthew  2237: ######################################################
                   2238: #            other handler subroutines               #
                   2239: ######################################################
                   2240: 
1.3       matthew  2241: ################################################################
                   2242: #                          Main handler                        #
                   2243: ################################################################
1.126     droeschl 2244: sub handler {    
                   2245:     my $r = shift;
                   2246:     Apache::loncommon::content_type($r,'text/html');
                   2247:     # Some pages contain DES keys and should not be cached.
                   2248:     Apache::loncommon::no_cache($r);
                   2249:     $r->send_http_header;
                   2250:     return OK if $r->header_only;
                   2251:     #
                   2252:     Apache::loncommon::get_unprocessed_cgi($ENV{'QUERY_STRING'},
                   2253:                                    ['action','wysiwyg','returnurl','refpage']);
                   2254:     #
                   2255:     Apache::lonhtmlcommon::clear_breadcrumbs();
1.198     raeburn  2256:     my ($brlink,$brtxt,$brhelp);
                   2257:     if (($env{'form.action'} eq 'changerolespref') && ($env{'form.returnurl'} eq '/adm/roles')) {
                   2258:         $brlink ='/adm/roles';
                   2259:         $brtxt = 'User Roles';
1.225   ! raeburn  2260:     } elsif ((($env{'form.action'} eq 'changedomcoord') ||
        !          2261:               ($env{'form.action'} eq 'authorsettings')) &&
        !          2262:              (($env{'form.returnurl'} =~ m{^/(priv/|res($|/))}) ||
        !          2263:               ($env{'form.returnurl'} eq '/adm/createuser'))) {
        !          2264:         $brlink = $env{'form.returnurl'};
        !          2265:         if ($env{'form.returnurl'} eq '/adm/createuser') {
        !          2266:             $brtxt = 'User Management';
        !          2267:         } elsif ($env{'form.returnurl'} =~ m{^/res($\/)}) {
        !          2268:             $brtxt = 'Browse published resources';
        !          2269:         } else {
        !          2270:             $brtxt = 'Authoring Space';
        !          2271:         }
1.198     raeburn  2272:     } else {
                   2273:         $brlink ='/adm/preferences';
                   2274:         $brtxt = 'Set User Preferences';
                   2275:         $brhelp = 'Prefs_About_Me,Prefs_Language,Prefs_Screen_Name_Nickname,Change_Colors,Change_Password,Prefs_Messages,Change_Discussion_Display';   
                   2276:     }
1.126     droeschl 2277:     Apache::lonhtmlcommon::add_breadcrumb
1.198     raeburn  2278:         ({href => $brlink,
                   2279:           text => $brtxt,
                   2280:           help => $brhelp,});
1.126     droeschl 2281:     if(!exists $env{'form.action'}) {
1.225   ! raeburn  2282: 	&print_main_menu($r);
1.126     droeschl 2283:     }elsif($env{'form.action'} eq 'changepass'){
                   2284:         &passwordchanger($r);
                   2285:     }elsif($env{'form.action'} eq 'verify_and_change_pass'){
1.219     raeburn  2286:         &verify_and_change_password($r,'preferences');
1.126     droeschl 2287:     }elsif($env{'form.action'} eq 'changescreenname'){
                   2288:         &screennamechanger($r);
                   2289:     }elsif($env{'form.action'} eq 'verify_and_change_screenname'){
                   2290:         &verify_and_change_screenname($r);
                   2291:     }elsif($env{'form.action'} eq 'changemsgforward'){
                   2292:         &msgforwardchanger($r);
                   2293:     }elsif($env{'form.action'} eq 'verify_and_change_msgforward'){
                   2294:         &verify_and_change_msgforward($r);
                   2295:     }elsif($env{'form.action'} eq 'changecolors'){
                   2296:         &colorschanger($r);
                   2297:     }elsif($env{'form.action'} eq 'verify_and_change_colors'){
                   2298:         &verify_and_change_colors($r);
                   2299:     }elsif($env{'form.action'} eq 'changelanguages'){
                   2300:         &languagechanger($r);
                   2301:     }elsif($env{'form.action'} eq 'verify_and_change_languages'){
                   2302:         &verify_and_change_languages($r);
                   2303:     }elsif($env{'form.action'} eq 'changewysiwyg'){
                   2304:         &wysiwygchanger($r);
                   2305:     }elsif($env{'form.action'} eq 'set_wysiwyg'){
                   2306:         &verify_and_change_wysiwyg($r);
                   2307:     }elsif($env{'form.action'} eq 'changediscussions'){
                   2308:         &discussionchanger($r);
                   2309:     }elsif($env{'form.action'} eq 'verify_and_change_discussion'){
                   2310:         &verify_and_change_discussion($r);
                   2311:     }elsif($env{'form.action'} eq 'changerolespref'){
                   2312:         &rolesprefchanger($r);
                   2313:     }elsif($env{'form.action'} eq 'verify_and_change_rolespref'){
                   2314:         &verify_and_change_rolespref($r);
                   2315:     }elsif($env{'form.action'} eq 'changetexenginepref'){
                   2316:         &texenginechanger($r);
                   2317:     }elsif($env{'form.action'} eq 'verify_and_change_texengine'){
                   2318:         &verify_and_change_texengine($r);
1.192     raeburn  2319:     }elsif($env{'form.action'} eq 'changeicons'){
                   2320:         &iconchanger($r);
                   2321:     }elsif($env{'form.action'} eq 'verify_and_change_icons'){
                   2322:         &verify_and_change_icons($r);
1.126     droeschl 2323:     }elsif($env{'form.action'} eq 'changeclicker'){
                   2324:         &clickerchanger($r);
                   2325:     }elsif($env{'form.action'} eq 'verify_and_change_clicker'){
                   2326:         &verify_and_change_clicker($r);
                   2327:     }elsif($env{'form.action'} eq 'changedomcoord'){
                   2328:         &domcoordchanger($r);
                   2329:     }elsif($env{'form.action'} eq 'verify_and_change_domcoord'){
                   2330:         &verify_and_change_domcoord($r);
                   2331:     }elsif($env{'form.action'} eq 'lockwarning'){
                   2332:         &lockwarning($r);
                   2333:     }elsif($env{'form.action'} eq 'verify_and_change_locks'){
                   2334:         &verify_and_change_lockwarning($r);
                   2335:     }elsif($env{'form.action'} eq 'changecourseinit'){
                   2336:         &coursedisplaychanger($r);
                   2337:     }elsif($env{'form.action'} eq 'verify_and_change_coursepage'){
                   2338:         &verify_and_change_coursepage($r);
1.215     golterma 2339:     }elsif($env{'form.action'} eq 'authorsettings'){
                   2340:         &author_space_settings($r);
                   2341:     }elsif($env{'form.action'} eq 'change_authoring_settings'){
                   2342:         &change_authoring_settings($r);
1.126     droeschl 2343:     }elsif($env{'form.action'} eq 'debugtoggle'){
1.174     raeburn  2344:         if (&can_toggle_debug()) {
                   2345:             &toggle_debug();
                   2346:         }
1.154     www      2347: 	&print_main_menu($r);
1.186     raeburn  2348:     } elsif ($env{'form.action'} eq 'changelockednames') {
                   2349:         &lockednameschanger($r);
                   2350:     } elsif ($env{'form.action'} eq 'verify_and_change_lockednames') {
                   2351:         &verify_and_change_lockednames($r);
1.126     droeschl 2352:     }
                   2353: 
1.165     bisitz   2354:     # Properly end the HTML page of all preference pages
                   2355:     # started in each sub routine
                   2356:     # Exception: print_main_menu has its own end_page call
                   2357:     unless (!exists $env{'form.action'} ||
                   2358:             $env{'form.action'} eq 'debugtoggle') {
                   2359:         $r->print(&Apache::loncommon::end_page());
                   2360:     }
                   2361: 
1.126     droeschl 2362:     return OK;
1.35      matthew  2363: }
                   2364: 
                   2365: sub toggle_debug {
1.59      albertel 2366:     if ($env{'user.debug'}) {
1.139     raeburn  2367:         &Apache::lonnet::delenv('user.debug');
1.35      matthew  2368:     } else {
1.116     raeburn  2369:         &Apache::lonnet::appenv({'user.debug' => 1});
1.35      matthew  2370:     }
1.13      www      2371: }
1.1       www      2372: 
1.174     raeburn  2373: sub can_toggle_debug {
                   2374:     my $can_toggle = 0;
                   2375:     my $page = 'toggledebug';
                   2376:     if (&LONCAPA::lonauthcgi::can_view($page)) {
                   2377:         $can_toggle = 1;
                   2378:     } elsif (&LONCAPA::lonauthcgi::check_ipbased_access($page)) {
                   2379:         $can_toggle = 1;
                   2380:     }
                   2381:     return $can_toggle;
                   2382: }
                   2383: 
1.186     raeburn  2384: sub can_toggle_namelocking {
                   2385:     my $lockablenames;
                   2386:     my %domconfig =
                   2387:         &Apache::lonnet::get_dom('configuration',['autoupdate'],$env{'user.domain'});
                   2388:     if (ref($domconfig{'autoupdate'}) eq 'HASH') {
                   2389:         if ($domconfig{'autoupdate'}{'run'}) {
                   2390:             my @inststatuses = split(':',$env{'environment.inststatus'});
                   2391:             unless (@inststatuses) {
                   2392:                 @inststatuses = ('default');
                   2393:             }
                   2394:             my %updateable = &updateable_userinfo($domconfig{'autoupdate'},\@inststatuses);
                   2395:             if ($updateable{'lastname'} || $updateable{'firstname'} ||
                   2396:                 $updateable{'middlename'}) { 
                   2397:                 if (ref($domconfig{'autoupdate'}{'lockablenames'}) eq 'ARRAY') {
                   2398:                     unless (@inststatuses) {
                   2399:                         @inststatuses = ('default');
                   2400:                     }
                   2401:                     foreach my $status (@inststatuses) {
                   2402:                         if (grep(/^\Q$status\E$/,@{$domconfig{'autoupdate'}{'lockablenames'}})) {
                   2403:                             $lockablenames = 1;
                   2404:                             last;
                   2405:                         }
                   2406:                     }
                   2407:                 }
                   2408:             }
                   2409:         }
                   2410:     }
                   2411:     return $lockablenames;
                   2412: }
                   2413: 
                   2414: sub updateable_userinfo {
                   2415:     my ($autoupdate,$inststatuses) = @_;
                   2416:     my %updateable;
                   2417:     return %updateable unless ((ref($autoupdate) eq 'HASH') && 
                   2418:                                (ref($inststatuses) eq 'ARRAY'));
                   2419:     if (ref($autoupdate->{'fields'}) eq 'HASH') {
                   2420:         foreach my $status (@{$inststatuses}) {
                   2421:             if (ref($autoupdate->{'fields'}{$status}) eq 'ARRAY') {
                   2422:                 foreach my $field (@{$autoupdate->{'fields'}{$status}}) {
                   2423:                     $updateable{$field} = 1;
                   2424:                 }
                   2425:             }
                   2426:         }
                   2427:     }
                   2428:     return %updateable;
                   2429: }
                   2430: 
1.225   ! raeburn  2431: sub do_redirect {
        !          2432:     my ($r,$url,$msg) = @_;
        !          2433:     $r->print(
        !          2434:         &Apache::loncommon::start_page('Switching Server ...',undef,
        !          2435:                                        {'redirect'       => [0.5,$url]}).
        !          2436:         '<div style="padding:0;clear:both;margin:0;border:0"></div>'."\n".
        !          2437:         "$msg\n".
        !          2438:         &Apache::loncommon::end_page());
        !          2439:     return;
        !          2440: }
        !          2441: 
1.1       www      2442: 1;
                   2443: __END__

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