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

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

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