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

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

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