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

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

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