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

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

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