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

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

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