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

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

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