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

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

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