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

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

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