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

1.1       www         1: # The LearningOnline Network
                      2: # Preferences
                      3: #
1.227   ! raeburn     4: # $Id: lonpreferences.pm,v 1.226 2018/04/27 21:39:42 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.226     raeburn  1514:     my ($r,$caller,$mailtoken,$ended) = @_;
1.94      raeburn  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);
1.226     raeburn  1659:             if (ref($ended)) {
                   1660:                 $$ended = 1;
                   1661:             }
1.144     raeburn  1662:         }
1.4       matthew  1663:     } else {
                   1664: 	# error error: run in circles, scream and shout
1.173     raeburn  1665:         if ($caller eq 'reset_by_email') {
                   1666:             if (!$result) {
                   1667:                 return 1;
                   1668:             } else {
                   1669:                 return $result;
                   1670:             }
                   1671:         } else {
                   1672:             $message = &Apache::lonhtmlcommon::confirm_success(
                   1673:                 &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   1674:             $message=&Apache::loncommon::confirmwrapper($message);
1.144     raeburn  1675:             &print_main_menu($r, $message);
1.226     raeburn  1676:             if (ref($ended)) {
                   1677:                 $$ended = 1;
                   1678:             }
1.144     raeburn  1679:         }
1.4       matthew  1680:     }
                   1681:     return;
1.3       matthew  1682: }
                   1683: 
1.42      raeburn  1684: ################################################################
                   1685: #            discussion display subroutines 
                   1686: ################################################################
                   1687: sub discussionchanger {
                   1688:     my $r = shift;
1.126     droeschl 1689:     Apache::lonhtmlcommon::add_breadcrumb(
                   1690: 	    {	href => '/adm/preferences?action=changediscussions',
                   1691:                 text => 'Change Discussion Preferences'});
1.178     bisitz   1692:     $r->print(Apache::loncommon::start_page('Change Discussion Preferences'));
1.126     droeschl 1693:     $r->print(Apache::lonhtmlcommon::breadcrumbs('Change Discussion Preferences'));
1.59      albertel 1694:     my $user       = $env{'user.name'};
                   1695:     my $domain     = $env{'user.domain'};
1.42      raeburn  1696:     my %userenv = &Apache::lonnet::get
1.43      raeburn  1697:         ('environment',['discdisplay','discmarkread']);
                   1698:     my $discdisp = 'allposts';
                   1699:     my $discmark = 'onmark';
                   1700: 
                   1701:     if (defined($userenv{'discdisplay'})) {
                   1702:         unless ($userenv{'discdisplay'} eq '') { 
                   1703:             $discdisp = $userenv{'discdisplay'};
                   1704:         }
                   1705:     }
                   1706:     if (defined($userenv{'discmarkread'})) {
1.171     raeburn  1707:         unless ($userenv{'discmarkread'} eq '') { 
1.43      raeburn  1708:             $discmark = $userenv{'discmarkread'};
                   1709:         }
                   1710:     }
                   1711: 
                   1712:     my $newdisp = 'unread';
                   1713:     my $newmark = 'ondisp';
                   1714: 
                   1715:     my $function = &Apache::loncommon::get_users_function();
                   1716:     my $color = &Apache::loncommon::designparm($function.'.tabbg',
1.59      albertel 1717:                                                     $env{'user.domain'});
1.43      raeburn  1718:     my %lt = &Apache::lonlocal::texthash(
                   1719:         'pref' => 'Display Preference',
                   1720:         'curr' => 'Current setting ',
                   1721:         'actn' => 'Action',
1.135     schafran 1722:         'sdpf' => 'Set display preferences for discussion posts for both discussion boards and individual resources in all your courses.',
1.43      raeburn  1723:         'prca' => 'Preferences can be set that determine',
1.135     schafran 1724:         'whpo' => 'Which posts are displayed when you display a discussion board or resource, and',
1.194     raeburn  1725:         'unwh' => 'Under what circumstances posts are identified as "NEW"',
1.43      raeburn  1726:         'allposts' => 'All posts',
                   1727:         'unread' => 'New posts only',
                   1728:         'ondisp' => 'Once displayed',
1.194     raeburn  1729:         'onmark' => 'Once marked not NEW',
1.43      raeburn  1730:         'disa' => 'Posts displayed?',
1.194     raeburn  1731:         'npmr' => 'New posts cease to be identified as "NEW"?',
1.43      raeburn  1732:         'thde'  => 'The preferences you set here can be overridden within each individual discussion.',
                   1733:         'chgt' => 'Change to '
                   1734:     );
                   1735:     my $dispchange = $lt{'unread'};
                   1736:     my $markchange = $lt{'ondisp'};
                   1737:     my $currdisp = $lt{'allposts'};
                   1738:     my $currmark = $lt{'onmark'};
                   1739: 
                   1740:     if ($discdisp eq 'unread') {
                   1741:         $dispchange = $lt{'allposts'};
                   1742:         $currdisp = $lt{'unread'};
                   1743:         $newdisp = 'allposts';
                   1744:     }
                   1745: 
                   1746:     if ($discmark eq 'ondisp') {
                   1747:         $markchange = $lt{'onmark'};
                   1748:         $currmark = $lt{'ondisp'};
                   1749:         $newmark = 'onmark';
1.42      raeburn  1750:     }
1.171     raeburn  1751: 
1.43      raeburn  1752:     $r->print(<<"END");
1.88      albertel 1753: <form name="prefs" action="/adm/preferences" method="post">
1.42      raeburn  1754: <input type="hidden" name="action" value="verify_and_change_discussion" />
                   1755: <br />
1.87      albertel 1756: $lt{'sdpf'}<br /> $lt{'prca'}  <ol><li>$lt{'whpo'}</li><li>$lt{'unwh'}</li></ol> 
1.82      albertel 1757: END
1.158     bisitz   1758: 
                   1759:     $r->print('<p class="LC_info">'.$lt{'thde'}.'</p>');
                   1760: 
1.82      albertel 1761:     $r->print(&Apache::loncommon::start_data_table());
                   1762:     $r->print(<<"END");
                   1763:        <tr>
                   1764:         <th>$lt{'pref'}</th>
                   1765:         <th>$lt{'curr'}</th>
                   1766:         <th>$lt{'actn'}?</th>
1.43      raeburn  1767:        </tr>
1.82      albertel 1768: END
                   1769:     $r->print(&Apache::loncommon::start_data_table_row());
                   1770:     $r->print(<<"END");
1.43      raeburn  1771:        <td>$lt{'disa'}</td>
                   1772:        <td>$lt{$discdisp}</td>
1.82      albertel 1773:        <td><label><input type="checkbox" name="discdisp" /><input type="hidden" name="newdisp" value="$newdisp" />&nbsp;$lt{'chgt'} "$dispchange"</label></td>
                   1774: END
                   1775:     $r->print(&Apache::loncommon::end_data_table_row().
                   1776: 	      &Apache::loncommon::start_data_table_row());
                   1777:     $r->print(<<"END");
1.43      raeburn  1778:        <td>$lt{'npmr'}</td>
                   1779:        <td>$lt{$discmark}</td>
1.82      albertel 1780:        <td><label><input type="checkbox" name="discmark" /><input type="hidden" name="newmark" value="$newmark" />&nbsp;$lt{'chgt'} "$markchange"</label></td>
1.43      raeburn  1781:       </tr>
1.82      albertel 1782: END
                   1783:     $r->print(&Apache::loncommon::end_data_table_row().
                   1784: 	      &Apache::loncommon::end_data_table());
1.142     zhu      1785: 
1.158     bisitz   1786:     $r->print('<br />'
                   1787:              .'<input type="submit" name="sub" value="'.&mt('Save').'" />'
                   1788:              .'</form>'
                   1789:     );
1.42      raeburn  1790: }
                   1791:                                                                                                                 
                   1792: sub verify_and_change_discussion {
                   1793:     my $r = shift;
1.59      albertel 1794:     my $user     = $env{'user.name'};
                   1795:     my $domain   = $env{'user.domain'};
1.42      raeburn  1796:     my $message='';
1.59      albertel 1797:     if (defined($env{'form.discdisp'}) ) {
                   1798:         my $newdisp  = $env{'form.newdisp'};
1.43      raeburn  1799:         if ($newdisp eq 'unread') {
1.171     raeburn  1800:             $message .=&Apache::lonhtmlcommon::confirm_success(&mt('In discussions: only new posts will be displayed.')).'<br />';
1.43      raeburn  1801:             &Apache::lonnet::put('environment',{'discdisplay' => $newdisp});
1.116     raeburn  1802:             &Apache::lonnet::appenv({'environment.discdisplay' => $newdisp});
1.43      raeburn  1803:         } else {
1.171     raeburn  1804:             $message .= &Apache::lonhtmlcommon::confirm_success(&mt('In discussions: all posts will be displayed.')).'<br />';
1.43      raeburn  1805:             &Apache::lonnet::del('environment',['discdisplay']);
1.139     raeburn  1806:             &Apache::lonnet::delenv('environment.discdisplay');
1.43      raeburn  1807:         }
                   1808:     }
1.59      albertel 1809:     if (defined($env{'form.discmark'}) ) {
                   1810:         my $newmark = $env{'form.newmark'};
1.43      raeburn  1811:         if ($newmark eq 'ondisp') {
1.209     bisitz   1812:             $message.=&Apache::lonhtmlcommon::confirm_success(&mt('In discussions: new posts will cease to be identified as "NEW" after display.')).'<br />';
1.43      raeburn  1813:             &Apache::lonnet::put('environment',{'discmarkread' => $newmark});
1.116     raeburn  1814:             &Apache::lonnet::appenv({'environment.discmarkread' => $newmark});
1.43      raeburn  1815:         } else {
1.194     raeburn  1816:             $message.=&Apache::lonhtmlcommon::confirm_success(&mt('In discussions: posts will be identified as "NEW" until marked as not "NEW".')).'<br />';
1.43      raeburn  1817:             &Apache::lonnet::del('environment',['discmarkread']);
1.139     raeburn  1818:             &Apache::lonnet::delenv('environment.discmarkread');
1.43      raeburn  1819:         }
1.42      raeburn  1820:     }
1.158     bisitz   1821:     $message=&Apache::loncommon::confirmwrapper($message);
1.152     www      1822:     &print_main_menu($r, $message);
1.42      raeburn  1823: }
                   1824: 
1.63      raeburn  1825: ################################################################
                   1826: # Subroutines for page display on course access (Course Coordinators)
                   1827: ################################################################
                   1828: sub coursedisplaychanger {
                   1829:     my $r = shift;
1.152     www      1830:     &Apache::lonhtmlcommon::add_breadcrumb(
1.126     droeschl 1831: 	    {	href => '/adm/preferences?action=changecourseinit',
                   1832:                 text => 'Change Course Init. Pref.'});
                   1833:     $r->print(Apache::loncommon::start_page('Change Course Initialization Preference'));
                   1834:     $r->print(Apache::lonhtmlcommon::breadcrumbs('Change Course Init. Pref.'));
1.63      raeburn  1835:     my $user       = $env{'user.name'};
                   1836:     my $domain     = $env{'user.domain'};
1.66      albertel 1837:     my %userenv = &Apache::lonnet::get('environment',['course_init_display']);
1.71      raeburn  1838:     my $currvalue = 'whatsnew';
1.73      albertel 1839:     my $firstselect = '';
                   1840:     my $whatsnewselect = 'checked="checked"';
1.71      raeburn  1841:     if (exists($userenv{'course_init_display'})) {
                   1842:         if ($userenv{'course_init_display'} eq 'firstres') {
                   1843:             $currvalue = 'firstres';
1.73      albertel 1844:             $firstselect = 'checked="checked"';
                   1845: 	    $whatsnewselect = '';
1.71      raeburn  1846:         }
1.63      raeburn  1847:     }
1.134     bisitz   1848:     my %pagenames = &Apache::lonlocal::texthash(
1.71      raeburn  1849:                        firstres => 'First resource',
1.143     hauer    1850:                        whatsnew => "What's New Page",
1.71      raeburn  1851:                     );
1.134     bisitz   1852:     my $whatsnew_off=&mt('Display the [_1]first resource[_2] in the course.','<b>','</b>');
1.143     hauer    1853:     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  1854: 
1.134     bisitz   1855:     $r->print('<br /><b>'
                   1856:              .&mt('Set the default page to be displayed when you select a course role')
                   1857:              .'</b>&nbsp;'
                   1858:              .&mt('(Currently: [_1])',$pagenames{$currvalue})
                   1859:              .'<br />'
1.143     hauer    1860:              .&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   1861:              .'<br /><br />'
                   1862:     );
1.63      raeburn  1863:     $r->print(<<ENDLSCREEN);
1.88      albertel 1864: <form name="prefs" action="/adm/preferences" method="post">
1.63      raeburn  1865: <input type="hidden" name="action" value="verify_and_change_coursepage" />
1.72      albertel 1866: <br />
1.65      albertel 1867: <label><input type="radio" name="newdisp" value="firstres" $firstselect /> $whatsnew_off</label><br />
1.70      raeburn  1868: <label><input type="radio" name="newdisp" value="whatsnew" $whatsnewselect /> $whatsnew_on</label><input type="hidden" name="refpage" value="$env{'form.refpage'}" />
1.63      raeburn  1869: ENDLSCREEN
1.140     schafran 1870:     $r->print('<br /><br /><input type="submit" value="'.&mt('Save').'" />
1.63      raeburn  1871: </form>');
                   1872: }
                   1873: 
                   1874: sub verify_and_change_coursepage {
                   1875:     my $r = shift;
                   1876:     my $message='';
                   1877:     my %lt = &Apache::lonlocal::texthash(
1.70      raeburn  1878:         'defs' => 'Default now set',
1.71      raeburn  1879:         'when' => 'when you select a course role from the roles screen',
1.63      raeburn  1880:         'ywbt' => 'you will be taken to the start of the course.',
                   1881:         'apwb' => 'a page will be displayed that lists items in the course that may require action from you.',
                   1882:         'gtts' => 'Go to the start of the course',
1.146     hauer    1883:         'dasp' => "Display the What's New Page", 
1.63      raeburn  1884:     );
                   1885:     my $newdisp  = $env{'form.newdisp'};
1.70      raeburn  1886:     $message = '<b>'.$lt{'defs'}.'</b>: '.$lt{'when'}.', ';
1.63      raeburn  1887:     if ($newdisp eq 'firstres') {
1.87      albertel 1888:         $message .= $lt{'ywbt'}.'<br />';
1.63      raeburn  1889:         &Apache::lonnet::put('environment',{'course_init_display' => $newdisp});
1.116     raeburn  1890:         &Apache::lonnet::appenv({'environment.course_init_display' => $newdisp});
1.63      raeburn  1891:     } else {
1.87      albertel 1892:         $message .= $lt{'apwb'}.'<br />';
1.63      raeburn  1893:         &Apache::lonnet::del('environment',['course_init_display']);
1.139     raeburn  1894:         &Apache::lonnet::delenv('environment.course_init_display');
1.63      raeburn  1895:     }
1.70      raeburn  1896:     my $refpage = $env{'form.refpage'};
1.63      raeburn  1897:     if (($env{'request.course.fn'}) && ($env{'request.course.id'})) {
                   1898:         if ($newdisp eq 'firstres') {
                   1899:             my $cdom = $env{'course.'.$env{'request.course.id'}.'.domain'};
                   1900:             my $cnum = $env{'course.'.$env{'request.course.id'}.'.num'}; 
                   1901:             my ($furl,$ferr)=
                   1902:                 &Apache::lonuserstate::readmap($cdom.'/'.$cnum);
1.180     wenzelju 1903:             $message .= '<br /><a href="'.$furl.'">'.$lt{'gtts'}.' <i>'.&mt('now').'</i></a>';
1.63      raeburn  1904:         } else {
1.180     wenzelju 1905:             $message .= '<br /><a href="/adm/whatsnew?refpage='.
                   1906:                         $refpage.'">'.$lt{'dasp'}.'</a>';
1.63      raeburn  1907:         }
                   1908:     }
1.180     wenzelju 1909:     $message = &Apache::lonhtmlcommon::confirm_success($message);
                   1910:     $message = &Apache::loncommon::confirmwrapper($message);
                   1911:     &print_main_menu($r,$message);
1.63      raeburn  1912: }
                   1913: 
1.215     golterma 1914: sub author_space_settings {
                   1915:     my $r = shift;
                   1916:     &Apache::lonhtmlcommon::add_breadcrumb(
                   1917:             {   href => '/adm/preferences?action=authorsettings',
                   1918:                 text => 'Authoring Space Settings'});
                   1919:     my $user       = $env{'user.name'};
                   1920:     my $domain     = $env{'user.domain'};
                   1921:     my %author_roles = &Apache::lonnet::get_my_roles($user,$domain,'userroles','',['au','ca','aa']);
                   1922:     if (keys(%author_roles) > 0) {
                   1923:             $r->print(Apache::loncommon::start_page('Authoring Space Settings'));
                   1924:             $r->print(Apache::lonhtmlcommon::breadcrumbs('Authoring Space Settings'));
                   1925:             my %userenv = &Apache::lonnet::get('environment',['nocodemirror']);
                   1926:             my $constchecked='';
                   1927:             if ($env{'environment.nocodemirror'}) {
                   1928:                $constchecked=' checked="checked"';
                   1929:             }
1.216     droeschl 1930:             my $text=&mt('By default, CodeMirror an editor with advanced functionality for editing code is activated for authors.');
                   1931:             my $cmoff=&mt('Deactivate CodeMirror. This can improve performance on slow computers and accessibility.');
1.215     golterma 1932:             my $change=&mt('Save');
1.225     raeburn  1933:             my $returnurl = &HTML::Entities::encode($env{'form.returnurl'},'"<>&\'');
1.215     golterma 1934:             $r->print(<<ENDSCREEN);
                   1935:         <form name="prefs" action="/adm/preferences" method="post">
1.225     raeburn  1936:         <input type="hidden" name="returnurl" value="$returnurl" />
1.215     golterma 1937:         <input type="hidden" name="action" value="change_authoring_settings" />
                   1938:         $text<br />
                   1939:         <label><input type="checkbox" name="cmoff"$constchecked />$cmoff</label><br />
                   1940:         <input type="submit" value="$change" />
                   1941:         </form>
                   1942: ENDSCREEN
                   1943:     }
                   1944: }
                   1945: 
                   1946: sub change_authoring_settings {
                   1947:     my $r = shift;
                   1948:     my $user       = $env{'user.name'};
                   1949:     my $domain     = $env{'user.domain'};
                   1950:     my %author_roles = &Apache::lonnet::get_my_roles($user,$domain,'userroles','',['au','ca','aa']);
                   1951:     if (keys(%author_roles) > 0) {
                   1952:             my %ausettings=('environment.nocodemirror' => '');
                   1953:             if ($env{'form.cmoff'}) { $ausettings{'environment.nocodemirror'}='yes'; }
                   1954:             &Apache::lonnet::put('environment',\%ausettings);
                   1955:             &Apache::lonnet::appenv({'environment.nocodemirror' => $ausettings{'environment.nocodemirror'}});
                   1956:             my $status='';
                   1957:             if ($ausettings{'environment.nocodemirror'} eq 'yes') {
                   1958:                 $status=&mt('on');
                   1959:             } else {
                   1960:                 $status=&mt('off');
                   1961:             }
1.216     droeschl 1962:             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 1963:             $message=&Apache::loncommon::confirmwrapper($message);
1.225     raeburn  1964:             if ($env{'form.returnurl'}) {
                   1965:                 &do_redirect($r,$env{'form.returnurl'},$message);
                   1966:             } else {
                   1967:                 &print_main_menu($r,$message);
                   1968:             }
1.215     golterma 1969:     }
                   1970: }
                   1971: 
1.186     raeburn  1972: sub lockednameschanger {
                   1973:     my $r = shift;
                   1974:     &Apache::lonhtmlcommon::add_breadcrumb(
                   1975:             {   href => '/adm/preferences?action=changelockednames',
                   1976:                 text => 'Automatic name changes'});
                   1977:     $r->print(Apache::loncommon::start_page('Automatic name changes'));
                   1978:     $r->print(Apache::lonhtmlcommon::breadcrumbs('Allow/disallow name updates'));
                   1979:     my %userenv = &Apache::lonnet::get('environment',['lockedname']);
                   1980:     my $lockedname='';
                   1981:     if (&can_toggle_namelocking()) {
                   1982:         if ($userenv{'lockedname'}) {
                   1983:             $lockedname = ' checked="checked"';
                   1984:         }
                   1985:         my %updateable;
                   1986:         my %domconfig =
                   1987:             &Apache::lonnet::get_dom('configuration',['autoupdate'],$env{'user.domain'});
                   1988:         if (ref($domconfig{'autoupdate'}) eq 'HASH') {
                   1989:             if ($domconfig{'autoupdate'}{'run'}) {
                   1990:                 my @inststatuses = split(':',$env{'environment.inststatus'});
                   1991:                 unless (@inststatuses) {
                   1992:                     @inststatuses = ('default');
                   1993:                 }
                   1994:                 %updateable = &updateable_userinfo($domconfig{'autoupdate'},\@inststatuses);
                   1995:             }
                   1996:         }
                   1997:         if (keys(%updateable)) {
                   1998:             my %longnames = &Apache::lonlocal::texthash (
                   1999:                                 firstname  => 'First Name',
                   2000:                                 middlename => 'Middle Name',
                   2001:                                 lastname   => 'Last Name',
                   2002:                             );
                   2003:             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:').
                   2004:                      '<ul>';
                   2005:            foreach my $item ('firstname','middlename','lastname') {
                   2006:                if ($updateable{$item}) {
                   2007:                    $text .= '<li>'.$longnames{$item}.'</li>';
                   2008:                }
                   2009:            }
                   2010:            $text .= '</ul>'; 
                   2011:            my $locking=&mt('Disallow automatic updates to name information for your LON-CAPA account');
                   2012:            my $change=&mt('Save');
                   2013:            $r->print(<<ENDSCREEN);
                   2014: <form name="prefs" action="/adm/preferences" method="post">
                   2015: <input type="hidden" name="action" value="verify_and_change_lockednames" />
                   2016: $text<br />
                   2017: <label><input type="checkbox" value="1" name="lockednames"$lockedname />$locking</label><br />
                   2018: <input type="submit" value="$change" />
                   2019: </form>
                   2020: ENDSCREEN
                   2021:         } else {
                   2022:             my $message = &mt('Based on your institutional affiliation no name information is automatically updated for your LON-CAPA account.');
                   2023:             &print_main_menu($r,$message);
                   2024:         }
                   2025:     } else {
                   2026:         my $message = &mt('You are not permitted to set a user preference for automatic name updates for your LON-CAPA account.');
                   2027:         &print_main_menu($r,$message);
                   2028:     }
                   2029: }
                   2030: 
                   2031: sub verify_and_change_lockednames {
                   2032:     my $r = shift;
                   2033:     my $message;
                   2034:     if (&can_toggle_namelocking()) {
                   2035:         my $newlockedname = $env{'form.lockednames'};
                   2036:         $newlockedname =~ s/\D//g;
                   2037:         my $currlockedname = $env{'environment.lockedname'};
                   2038:         if ($newlockedname ne $currlockedname) {
                   2039:             if ($newlockedname) {
                   2040:                 if (&Apache::lonnet::put('environment',{lockedname => $newlockedname}) eq 'ok') {
                   2041:                     &Apache::lonnet::appenv({'environment.lockedname' => $newlockedname});
                   2042:                 }
                   2043:             } elsif (&Apache::lonnet::del('environment',['lockedname']) eq 'ok') {
                   2044:                 &Apache::lonnet::delenv('environment.lockedname');
                   2045:             }
                   2046:         }
                   2047:         my $status='';
                   2048:         if ($newlockedname) {
                   2049:             $status=&mt('disallowed');
                   2050:         } else {
                   2051:             $status=&mt('allowed');
                   2052:         }
                   2053:         $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>'));
                   2054:         $message=&Apache::loncommon::confirmwrapper($message);
                   2055:     }
                   2056:     &print_main_menu($r,$message);
                   2057: }
                   2058: 
1.126     droeschl 2059: sub print_main_menu {
                   2060:     my ($r, $message) = @_;
                   2061:     # Determine current authentication method
                   2062:     my $user = $env{'user.name'};
                   2063:     my $domain = $env{'user.domain'};
                   2064:     my $currentauth=&Apache::lonnet::queryauthenticate($user,$domain);
                   2065: 
                   2066:     # build the data structure for menu generation
                   2067: my $aboutmeurl='/adm/'.$env{'user.domain'}.'/'.$env{'user.name'}.'/aboutme';
                   2068: my $role = ($env{'user.adv'} ? 'Roles' : 'Course');
1.131     raeburn  2069: my %permissions;
                   2070: if (&Apache::lonnet::usertools_access($user,$domain,'aboutme')) {
                   2071:     $permissions{'aboutme'} = 'F';
                   2072: }
1.126     droeschl 2073: my @menu=
                   2074:     ({	categorytitle=>'Personal Data',
                   2075: 	items =>[
1.141     weissno  2076: 	    {	linktext => 'Personal Information Page',
1.126     droeschl 2077: 		url => $aboutmeurl,
1.131     raeburn  2078: 		permission => $permissions{'aboutme'},
1.126     droeschl 2079: 		#help => 'Prefs_About_Me',
                   2080: 		icon => 'system-users.png',
                   2081: 		linktitle => 'Edit information about yourself that should be displayed on your public profile.'
                   2082: 	    },
                   2083: 	    {	linktext => 'Screen Name',
                   2084: 		url => '/adm/preferences?action=changescreenname',
                   2085: 		permission => 'F',
                   2086: 		#help => 'Prefs_Screen_Name_Nickname',
                   2087: 		icon => 'preferences-desktop-font.png',
                   2088: 		linktitle => 'Change the name that is displayed in your posts.'
                   2089: 	    },
                   2090: 		]
                   2091:     },
                   2092:     {	categorytitle=>'Content Display Settings',
                   2093: 	items =>[
                   2094: 	    {	linktext => 'Language',
                   2095: 		url => '/adm/preferences?action=changelanguages',
                   2096: 		permission => 'F',
                   2097: 		#help => 'Prefs_Language',
                   2098: 		icon => 'preferences-desktop-locale.png',
1.127     droeschl 2099: 		linktitle => 'Choose the default language for this user.'
1.126     droeschl 2100: 	    },
1.128     droeschl 2101: 	    {	linktext => $role.' Page',
1.126     droeschl 2102: 		url => '/adm/preferences?action=changerolespref',
                   2103: 		permission => 'F',
                   2104: 		#help => '',
1.189     wenzelju 2105: 		icon => 'role_hotlist.png',
1.126     droeschl 2106: 		linktitle => 'Configure the roles hotlist.'
                   2107: 	    },
1.177     raeburn  2108: 	    {	linktext => 'Math display settings',
1.126     droeschl 2109: 		url => '/adm/preferences?action=changetexenginepref',
                   2110: 		permission => 'F',
                   2111: 		#help => '',
1.188     wenzelju 2112: 		icon => 'dismath.png',
1.177     raeburn  2113: 		linktitle => 'Change how math is displayed.'
1.126     droeschl 2114: 	    },
                   2115: 		]
                   2116:     },
1.185     droeschl 2117:     {	categorytitle=>'Page Display Settings',
                   2118: 	items =>[
                   2119: 	    {	linktext => 'Color Scheme',
                   2120: 		url => '/adm/preferences?action=changecolors',
                   2121: 		permission => 'F',
                   2122: 		#help => 'Change_Colors',
                   2123: 		icon => 'preferences-desktop-theme.png',
                   2124: 		linktitle => 'Change LON-CAPA default colors.'
                   2125: 	    },
1.192     raeburn  2126:             {   linktext => 'Menu Display',
                   2127:                 url => '/adm/preferences?action=changeicons',
                   2128:                 permission => 'F',
                   2129:                 #help => '',
                   2130:                 icon => 'preferences-system-windows.png',
                   2131:                 linktitle => 'Change whether the menus are displayed with icons or icons and text.'
                   2132:             }
1.185     droeschl 2133: 		]
                   2134:     },
1.178     bisitz   2135:     {	categorytitle=>'Messages &amp; Notifications',
1.128     droeschl 2136: 	items =>[
1.153     www      2137: 	    {	linktext => 'Messages &amp; Notifications',
1.128     droeschl 2138: 		url => '/adm/preferences?action=changemsgforward',
                   2139: 		permission => 'F',
                   2140: 		#help => 'Prefs_Messages',
                   2141: 		icon => 'mail-reply-all.png',
                   2142: 		linktitle => 'Change messageforwarding or notifications settings.'
                   2143: 	    },
                   2144: 	    {	linktext => 'Discussion Display',
                   2145: 		url => '/adm/preferences?action=changediscussions',
                   2146: 		permission => 'F',
                   2147: 		#help => 'Change_Discussion_Display',
1.191     riegler  2148: 		icon => 'chat.png',
1.135     schafran 2149: 		linktitle => 'Set display preferences for discussion posts for both discussion boards and individual resources in all your courses.'
1.128     droeschl 2150: 	    },
                   2151: 		]
                   2152:     },
1.126     droeschl 2153:     {	categorytitle=>'Other',
                   2154: 	items =>[
1.153     www      2155: 	    {	linktext => 'Register Response Devices (&quot;Clickers&quot;)',
1.126     droeschl 2156: 		url => '/adm/preferences?action=changeclicker',
                   2157: 		permission => 'F',
                   2158: 		#help => '',
                   2159: 		icon => 'network-workgroup.png',
                   2160: 		linktitle => 'Register your clicker.'
                   2161: 	    },
                   2162: 		]
                   2163:     },
                   2164:     );
                   2165: 
                   2166:     if ($currentauth =~ /^(unix|internal):/) {
                   2167: push(@{ $menu[0]->{items} }, {
                   2168: 	linktext => 'Password',
                   2169: 	url => '/adm/preferences?action=changepass',
                   2170: 	permission => 'F',
                   2171: 	#help => 'Change_Password',
                   2172: 	icon => 'emblem-readonly.png',
                   2173: 	linktitle => 'Change your password.',
                   2174: 	});
                   2175:     }
1.186     raeburn  2176: 
                   2177:     if (&can_toggle_namelocking()) {
                   2178:         push(@{ $menu[0]->{items} }, {
                   2179:         linktext => 'Automatic name changes',
                   2180:         url => '/adm/preferences?action=changelockednames',
                   2181:         permission => 'F',
                   2182:         #help => '',
                   2183:         icon => 'system-lock-screen.png',
                   2184:         linktitle => 'Allow/disallow propagation of name changes from institutional directory service',
                   2185:         });
                   2186:     }
                   2187: 
1.126     droeschl 2188:     my %author_roles = &Apache::lonnet::get_my_roles($user,$domain,'userroles','',['au']);
                   2189:     if (keys(%author_roles) > 0) {
                   2190: push(@{ $menu[4]->{items} }, {
                   2191: 	linktext => 'Restrict Domain Coordinator Access',
                   2192: 	url => '/adm/preferences?action=changedomcoord',
                   2193: 	permission => 'F',
                   2194: 	#help => '',
                   2195: 	icon => 'system-lock-screen.png',
                   2196: 	linktitle => 'Restrict domain coordinator access.',
                   2197: 	});
                   2198:     }
                   2199: 
                   2200:     if (&Apache::lonnet::allowed('whn',$env{'request.course.id'})
                   2201: 	|| &Apache::lonnet::allowed('whn',$env{'request.course.id'}.'/'
                   2202: 				    .$env{'request.course.sec'})) {
                   2203: push(@{ $menu[4]->{items} }, {
1.128     droeschl 2204: 	linktext => 'Course Initialization',
1.126     droeschl 2205: 	url => '/adm/preferences?action=changecourseinit',
                   2206: 	permission => 'F',
                   2207: 	#help => '',
1.189     wenzelju 2208: 	icon => 'course_ini.png',
1.126     droeschl 2209: 	linktitle => 'Set the default page to be displayed when you select a course role.',
                   2210: 	});
                   2211: 
                   2212:     }
1.215     golterma 2213: 
1.222     raeburn  2214:     my %author_coauthor_roles = &Apache::lonnet::get_my_roles($user,$domain,'userroles','',['au','ca','aa']);
                   2215:     if (keys(%author_coauthor_roles) > 0) {
1.215     golterma 2216:         push(@{ $menu[4]->{items} }, {
                   2217:             linktext => 'Authoring Space Configuration',
                   2218:             url => '/adm/preferences?action=authorsettings',
                   2219:             permission => 'F',
1.224     raeburn  2220:             icon => 'codemirror.png',
1.215     golterma 2221:             linktitle => 'Settings for your authoring space.',
                   2222:         });
                   2223:     }
                   2224: 
1.174     raeburn  2225:     if (&can_toggle_debug()) {
1.126     droeschl 2226: push(@{ $menu[4]->{items} }, {
1.174     raeburn  2227: 	linktext => 'Toggle Debug Messages (Currently '.($env{'user.debug'} ? 'on)' : 'off)'),
1.126     droeschl 2228: 	url => '/adm/preferences?action=debugtoggle',
                   2229: 	permission => 'F',
                   2230: 	#help => '',
                   2231: 	icon => 'blog.png',
                   2232: 	linktitle => 'Toggle Debug Messages.',
                   2233: 	});
1.186     raeburn  2234:     }
1.126     droeschl 2235: 
1.147     schafran 2236:     $r->print(&Apache::loncommon::start_page('My Space'));
1.126     droeschl 2237:     $r->print(Apache::lonhtmlcommon::breadcrumbs('Change Preferences'));
                   2238:     $r->print($message);
                   2239:     $r->print(Apache::lonhtmlcommon::generate_menu(@menu));
                   2240:     $r->print(Apache::loncommon::end_page());
                   2241: }
1.63      raeburn  2242: 
1.4       matthew  2243: ######################################################
                   2244: #            other handler subroutines               #
                   2245: ######################################################
                   2246: 
1.3       matthew  2247: ################################################################
                   2248: #                          Main handler                        #
                   2249: ################################################################
1.126     droeschl 2250: sub handler {    
                   2251:     my $r = shift;
                   2252:     Apache::loncommon::content_type($r,'text/html');
                   2253:     # Some pages contain DES keys and should not be cached.
                   2254:     Apache::loncommon::no_cache($r);
                   2255:     $r->send_http_header;
                   2256:     return OK if $r->header_only;
                   2257:     #
                   2258:     Apache::loncommon::get_unprocessed_cgi($ENV{'QUERY_STRING'},
                   2259:                                    ['action','wysiwyg','returnurl','refpage']);
                   2260:     #
                   2261:     Apache::lonhtmlcommon::clear_breadcrumbs();
1.226     raeburn  2262:     my ($brlink,$brtxt,$brhelp,$ended);
1.198     raeburn  2263:     if (($env{'form.action'} eq 'changerolespref') && ($env{'form.returnurl'} eq '/adm/roles')) {
                   2264:         $brlink ='/adm/roles';
                   2265:         $brtxt = 'User Roles';
1.225     raeburn  2266:     } elsif ((($env{'form.action'} eq 'changedomcoord') ||
                   2267:               ($env{'form.action'} eq 'authorsettings')) &&
                   2268:              (($env{'form.returnurl'} =~ m{^/(priv/|res($|/))}) ||
                   2269:               ($env{'form.returnurl'} eq '/adm/createuser'))) {
                   2270:         $brlink = $env{'form.returnurl'};
                   2271:         if ($env{'form.returnurl'} eq '/adm/createuser') {
                   2272:             $brtxt = 'User Management';
                   2273:         } elsif ($env{'form.returnurl'} =~ m{^/res($\/)}) {
                   2274:             $brtxt = 'Browse published resources';
                   2275:         } else {
                   2276:             $brtxt = 'Authoring Space';
                   2277:         }
1.198     raeburn  2278:     } else {
                   2279:         $brlink ='/adm/preferences';
                   2280:         $brtxt = 'Set User Preferences';
                   2281:         $brhelp = 'Prefs_About_Me,Prefs_Language,Prefs_Screen_Name_Nickname,Change_Colors,Change_Password,Prefs_Messages,Change_Discussion_Display';   
                   2282:     }
1.126     droeschl 2283:     Apache::lonhtmlcommon::add_breadcrumb
1.198     raeburn  2284:         ({href => $brlink,
                   2285:           text => $brtxt,
                   2286:           help => $brhelp,});
1.126     droeschl 2287:     if(!exists $env{'form.action'}) {
1.225     raeburn  2288: 	&print_main_menu($r);
1.226     raeburn  2289:         $ended = 1;
1.126     droeschl 2290:     }elsif($env{'form.action'} eq 'changepass'){
                   2291:         &passwordchanger($r);
                   2292:     }elsif($env{'form.action'} eq 'verify_and_change_pass'){
1.227   ! raeburn  2293:         &verify_and_change_password($r,'preferences','',\$ended);
1.126     droeschl 2294:     }elsif($env{'form.action'} eq 'changescreenname'){
                   2295:         &screennamechanger($r);
                   2296:     }elsif($env{'form.action'} eq 'verify_and_change_screenname'){
                   2297:         &verify_and_change_screenname($r);
1.226     raeburn  2298:         $ended = 1;
1.126     droeschl 2299:     }elsif($env{'form.action'} eq 'changemsgforward'){
                   2300:         &msgforwardchanger($r);
                   2301:     }elsif($env{'form.action'} eq 'verify_and_change_msgforward'){
                   2302:         &verify_and_change_msgforward($r);
                   2303:     }elsif($env{'form.action'} eq 'changecolors'){
                   2304:         &colorschanger($r);
                   2305:     }elsif($env{'form.action'} eq 'verify_and_change_colors'){
                   2306:         &verify_and_change_colors($r);
1.226     raeburn  2307:         $ended = 1;
1.126     droeschl 2308:     }elsif($env{'form.action'} eq 'changelanguages'){
                   2309:         &languagechanger($r);
                   2310:     }elsif($env{'form.action'} eq 'verify_and_change_languages'){
                   2311:         &verify_and_change_languages($r);
1.226     raeburn  2312:         $ended = 1;
1.126     droeschl 2313:     }elsif($env{'form.action'} eq 'changewysiwyg'){
                   2314:         &wysiwygchanger($r);
                   2315:     }elsif($env{'form.action'} eq 'set_wysiwyg'){
                   2316:         &verify_and_change_wysiwyg($r);
1.227   ! raeburn  2317:         $ended = 1;
1.126     droeschl 2318:     }elsif($env{'form.action'} eq 'changediscussions'){
                   2319:         &discussionchanger($r);
                   2320:     }elsif($env{'form.action'} eq 'verify_and_change_discussion'){
                   2321:         &verify_and_change_discussion($r);
1.226     raeburn  2322:         $ended = 1;
1.126     droeschl 2323:     }elsif($env{'form.action'} eq 'changerolespref'){
                   2324:         &rolesprefchanger($r);
                   2325:     }elsif($env{'form.action'} eq 'verify_and_change_rolespref'){
                   2326:         &verify_and_change_rolespref($r);
1.226     raeburn  2327:         $ended = 1;
1.126     droeschl 2328:     }elsif($env{'form.action'} eq 'changetexenginepref'){
                   2329:         &texenginechanger($r);
                   2330:     }elsif($env{'form.action'} eq 'verify_and_change_texengine'){
                   2331:         &verify_and_change_texengine($r);
1.227   ! raeburn  2332:         $ended = 1;
1.192     raeburn  2333:     }elsif($env{'form.action'} eq 'changeicons'){
                   2334:         &iconchanger($r);
                   2335:     }elsif($env{'form.action'} eq 'verify_and_change_icons'){
                   2336:         &verify_and_change_icons($r);
1.226     raeburn  2337:         $ended = 1;
1.126     droeschl 2338:     }elsif($env{'form.action'} eq 'changeclicker'){
                   2339:         &clickerchanger($r);
                   2340:     }elsif($env{'form.action'} eq 'verify_and_change_clicker'){
                   2341:         &verify_and_change_clicker($r);
1.227   ! raeburn  2342:         $ended = 1;
1.126     droeschl 2343:     }elsif($env{'form.action'} eq 'changedomcoord'){
                   2344:         &domcoordchanger($r);
                   2345:     }elsif($env{'form.action'} eq 'verify_and_change_domcoord'){
                   2346:         &verify_and_change_domcoord($r);
1.226     raeburn  2347:         $ended = 1;
1.126     droeschl 2348:     }elsif($env{'form.action'} eq 'lockwarning'){
                   2349:         &lockwarning($r);
                   2350:     }elsif($env{'form.action'} eq 'verify_and_change_locks'){
                   2351:         &verify_and_change_lockwarning($r);
                   2352:     }elsif($env{'form.action'} eq 'changecourseinit'){
                   2353:         &coursedisplaychanger($r);
                   2354:     }elsif($env{'form.action'} eq 'verify_and_change_coursepage'){
                   2355:         &verify_and_change_coursepage($r);
1.226     raeburn  2356:         $ended = 1;
1.215     golterma 2357:     }elsif($env{'form.action'} eq 'authorsettings'){
                   2358:         &author_space_settings($r);
                   2359:     }elsif($env{'form.action'} eq 'change_authoring_settings'){
                   2360:         &change_authoring_settings($r);
1.227   ! raeburn  2361:         $ended = 1;
1.126     droeschl 2362:     }elsif($env{'form.action'} eq 'debugtoggle'){
1.174     raeburn  2363:         if (&can_toggle_debug()) {
                   2364:             &toggle_debug();
                   2365:         }
1.154     www      2366: 	&print_main_menu($r);
1.226     raeburn  2367:         $ended = 1;
1.186     raeburn  2368:     } elsif ($env{'form.action'} eq 'changelockednames') {
                   2369:         &lockednameschanger($r);
                   2370:     } elsif ($env{'form.action'} eq 'verify_and_change_lockednames') {
                   2371:         &verify_and_change_lockednames($r);
1.226     raeburn  2372:         $ended = 1;
1.126     droeschl 2373:     }
                   2374: 
1.165     bisitz   2375:     # Properly end the HTML page of all preference pages
                   2376:     # started in each sub routine
                   2377:     # Exception: print_main_menu has its own end_page call
1.226     raeburn  2378:     unless ($ended) {
1.165     bisitz   2379:         $r->print(&Apache::loncommon::end_page());
                   2380:     }
                   2381: 
1.126     droeschl 2382:     return OK;
1.35      matthew  2383: }
                   2384: 
                   2385: sub toggle_debug {
1.59      albertel 2386:     if ($env{'user.debug'}) {
1.139     raeburn  2387:         &Apache::lonnet::delenv('user.debug');
1.35      matthew  2388:     } else {
1.116     raeburn  2389:         &Apache::lonnet::appenv({'user.debug' => 1});
1.35      matthew  2390:     }
1.13      www      2391: }
1.1       www      2392: 
1.174     raeburn  2393: sub can_toggle_debug {
                   2394:     my $can_toggle = 0;
                   2395:     my $page = 'toggledebug';
                   2396:     if (&LONCAPA::lonauthcgi::can_view($page)) {
                   2397:         $can_toggle = 1;
                   2398:     } elsif (&LONCAPA::lonauthcgi::check_ipbased_access($page)) {
                   2399:         $can_toggle = 1;
                   2400:     }
                   2401:     return $can_toggle;
                   2402: }
                   2403: 
1.186     raeburn  2404: sub can_toggle_namelocking {
                   2405:     my $lockablenames;
                   2406:     my %domconfig =
                   2407:         &Apache::lonnet::get_dom('configuration',['autoupdate'],$env{'user.domain'});
                   2408:     if (ref($domconfig{'autoupdate'}) eq 'HASH') {
                   2409:         if ($domconfig{'autoupdate'}{'run'}) {
                   2410:             my @inststatuses = split(':',$env{'environment.inststatus'});
                   2411:             unless (@inststatuses) {
                   2412:                 @inststatuses = ('default');
                   2413:             }
                   2414:             my %updateable = &updateable_userinfo($domconfig{'autoupdate'},\@inststatuses);
                   2415:             if ($updateable{'lastname'} || $updateable{'firstname'} ||
                   2416:                 $updateable{'middlename'}) { 
                   2417:                 if (ref($domconfig{'autoupdate'}{'lockablenames'}) eq 'ARRAY') {
                   2418:                     unless (@inststatuses) {
                   2419:                         @inststatuses = ('default');
                   2420:                     }
                   2421:                     foreach my $status (@inststatuses) {
                   2422:                         if (grep(/^\Q$status\E$/,@{$domconfig{'autoupdate'}{'lockablenames'}})) {
                   2423:                             $lockablenames = 1;
                   2424:                             last;
                   2425:                         }
                   2426:                     }
                   2427:                 }
                   2428:             }
                   2429:         }
                   2430:     }
                   2431:     return $lockablenames;
                   2432: }
                   2433: 
                   2434: sub updateable_userinfo {
                   2435:     my ($autoupdate,$inststatuses) = @_;
                   2436:     my %updateable;
                   2437:     return %updateable unless ((ref($autoupdate) eq 'HASH') && 
                   2438:                                (ref($inststatuses) eq 'ARRAY'));
                   2439:     if (ref($autoupdate->{'fields'}) eq 'HASH') {
                   2440:         foreach my $status (@{$inststatuses}) {
                   2441:             if (ref($autoupdate->{'fields'}{$status}) eq 'ARRAY') {
                   2442:                 foreach my $field (@{$autoupdate->{'fields'}{$status}}) {
                   2443:                     $updateable{$field} = 1;
                   2444:                 }
                   2445:             }
                   2446:         }
                   2447:     }
                   2448:     return %updateable;
                   2449: }
                   2450: 
1.225     raeburn  2451: sub do_redirect {
                   2452:     my ($r,$url,$msg) = @_;
                   2453:     $r->print(
                   2454:         &Apache::loncommon::start_page('Switching Server ...',undef,
                   2455:                                        {'redirect'       => [0.5,$url]}).
                   2456:         '<div style="padding:0;clear:both;margin:0;border:0"></div>'."\n".
                   2457:         "$msg\n".
                   2458:         &Apache::loncommon::end_page());
                   2459:     return;
                   2460: }
                   2461: 
1.1       www      2462: 1;
                   2463: __END__

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