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

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

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