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

1.1       www         1: # The LearningOnline Network
                      2: # Preferences
                      3: #
1.200   ! foxr        4: # $Id: lonpreferences.pm,v 1.199 2012/10/04 13:41:10 bisitz Exp $
1.2       albertel    5: #
                      6: # Copyright Michigan State University Board of Trustees
                      7: #
                      8: # This file is part of the LearningOnline Network with CAPA (LON-CAPA).
                      9: #
                     10: # LON-CAPA is free software; you can redistribute it and/or modify
                     11: # it under the terms of the GNU General Public License as published by
                     12: # the Free Software Foundation; either version 2 of the License, or
                     13: # (at your option) any later version.
                     14: #
                     15: # LON-CAPA is distributed in the hope that it will be useful,
                     16: # but WITHOUT ANY WARRANTY; without even the implied warranty of
                     17: # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
                     18: # GNU General Public License for more details.
                     19: #
                     20: # You should have received a copy of the GNU General Public License
                     21: # along with LON-CAPA; if not, write to the Free Software
                     22: # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
                     23: #
                     24: # /home/httpd/html/adm/gpl.txt
                     25: #
                     26: # http://www.lon-capa.org/
                     27: #
1.3       matthew    28: # This package uses the "londes.js" javascript code. 
                     29: #
                     30: # TODOs that have to be completed:
                     31: #    interface with lonnet to change the password
                     32:  
1.1       www        33: package Apache::lonpreferences;
                     34: 
                     35: use strict;
1.86      albertel   36: use LONCAPA;
1.1       www        37: use Apache::Constants qw(:common);
1.3       matthew    38: use Apache::File;
                     39: use Crypt::DES;
                     40: use DynaLoader; # for Crypt::DES version
1.4       matthew    41: use Apache::loncommon();
1.23      matthew    42: use Apache::lonhtmlcommon();
1.32      www        43: use Apache::lonlocal;
1.59      albertel   44: use Apache::lonnet;
1.174     raeburn    45: use LONCAPA::lonauthcgi();
1.95      albertel   46: use LONCAPA();
1.3       matthew    47: 
                     48: #
                     49: # Write lonnet::passwd to do the call below.
                     50: # Use:
                     51: #   my $answer=reply("encrypt:passwd:$udom:$uname:$upass",$tryserver);
                     52: #
                     53: ##################################################
                     54: #          password associated functions         #
                     55: ##################################################
                     56: sub des_keys {
1.4       matthew    57:     # Make a new key for DES encryption.
1.36      www        58:     # Each key has two parts which are returned separately.
1.4       matthew    59:     # Please note:  Each key must be passed through the &hex function
                     60:     # before it is output to the web browser.  The hex versions cannot
                     61:     # be used to decrypt.
1.3       matthew    62:     my @hexstr=('0','1','2','3','4','5','6','7',
                     63:                 '8','9','a','b','c','d','e','f');
                     64:     my $lkey='';
                     65:     for (0..7) {
                     66:         $lkey.=$hexstr[rand(15)];
                     67:     }
                     68:     my $ukey='';
                     69:     for (0..7) {
                     70:         $ukey.=$hexstr[rand(15)];
                     71:     }
                     72:     return ($lkey,$ukey);
                     73: }
                     74: 
                     75: sub des_decrypt {
                     76:     my ($key,$cyphertext) = @_;
                     77:     my $keybin=pack("H16",$key);
                     78:     my $cypher;
                     79:     if ($Crypt::DES::VERSION>=2.03) {
                     80:         $cypher=new Crypt::DES $keybin;
                     81:     } else {
                     82:         $cypher=new DES $keybin;
                     83:     }
                     84:     my $plaintext=
                     85: 	$cypher->decrypt(unpack("a8",pack("H16",substr($cyphertext,0,16))));
                     86:     $plaintext.=
                     87: 	$cypher->decrypt(unpack("a8",pack("H16",substr($cyphertext,16,16))));
1.4       matthew    88:     $plaintext=substr($plaintext,1,ord(substr($plaintext,0,1)) );
1.3       matthew    89:     return $plaintext;
                     90: }
                     91: 
1.4       matthew    92: ################################################################
                     93: #                       Handler subroutines                    #
                     94: ################################################################
1.9       matthew    95: 
                     96: ################################################################
1.28      www        97: #         Language Change Subroutines                          #
                     98: ################################################################
1.44      www        99: 
                    100: sub wysiwygchanger {
                    101:     my $r = shift;
1.126     droeschl  102:     Apache::lonhtmlcommon::add_breadcrumb(
                    103: 	    {	href => '/adm/preferences?action=changewysiwyg',
                    104:                 text => 'Change WYSIWYG Preferences'});
1.147     schafran  105:     $r->print(Apache::loncommon::start_page('Content Display Settings'));
1.126     droeschl  106:     $r->print(Apache::lonhtmlcommon::breadcrumbs('Change WYSIWYG Preferences'));
                    107: 
1.44      www       108:     my %userenv = &Apache::lonnet::get
                    109:         ('environment',['wysiwygeditor']);
1.78      albertel  110:     my $onselect='checked="checked"';
1.44      www       111:     my $offselect='';
1.77      albertel  112:     if ($userenv{'wysiwygeditor'} eq 'on') {
1.44      www       113: 	$onselect='';
1.78      albertel  114: 	$offselect='checked="checked"';
1.44      www       115:     }
                    116:     my $switchoff=&mt('Disable WYSIWYG editor');
                    117:     my $switchon=&mt('Enable WYSIWYG editor');
1.124     www       118:     my $warning='';
                    119:     if ($env{'user.adv'}) {
1.185     droeschl  120:        $warning.='<p class="LC_warning">'.&mt("The WYSIWYG editor only supports simple HTML and is in many cases unsuited for advanced authoring. In a number of cases, it may destroy advanced authoring involving LaTeX and script function calls.")."</p>";
1.124     www       121:     }
1.44      www       122:     $r->print(<<ENDLSCREEN);
1.88      albertel  123: <form name="prefs" action="/adm/preferences" method="post">
1.44      www       124: <input type="hidden" name="action" value="set_wysiwyg" />
1.124     www       125: $warning
1.44      www       126: <br />
1.65      albertel  127: <label><input type="radio" name="wysiwyg" value="off" $onselect /> $switchoff</label><br />
                    128: <label><input type="radio" name="wysiwyg" value="on" $offselect /> $switchon</label>
1.44      www       129: ENDLSCREEN
1.136     schafran  130:     $r->print('<br /><input type="submit" value="'.&mt('Save').'" />');
1.44      www       131: }
                    132: 
                    133: 
                    134: sub verify_and_change_wysiwyg {
                    135:     my $r = shift;
1.59      albertel  136:     my $newsetting=$env{'form.wysiwyg'};
1.44      www       137:     &Apache::lonnet::put('environment',{'wysiwygeditor' => $newsetting});
1.116     raeburn   138:     &Apache::lonnet::appenv({'environment.wysiwygeditor' => $newsetting});
1.158     bisitz    139:     my $message=&Apache::lonhtmlcommon::confirm_success(&mt('Set [_1] to [_2]','<i>'.&mt('WYSIWYG Editor').'</i>','<tt>'.&mt($newsetting).'</tt>'));
                    140:     $message=&Apache::loncommon::confirmwrapper($message);
                    141:     &print_main_menu($r,$message);
1.44      www       142: }
                    143: 
                    144: ################################################################
                    145: #         Language Change Subroutines                          #
                    146: ################################################################
1.28      www       147: sub languagechanger {
                    148:     my $r = shift;
1.126     droeschl  149:     
                    150:     Apache::lonhtmlcommon::add_breadcrumb(
                    151: 	    {	href => '/adm/preferences?action=changelanguages',
1.127     droeschl  152:                 text => 'Change Language'});
1.147     schafran  153:     $r->print(Apache::loncommon::start_page('Content Display Settings'));
1.126     droeschl  154:     $r->print(Apache::lonhtmlcommon::breadcrumbs('Change Language')); 
1.59      albertel  155:     my $user       = $env{'user.name'};
                    156:     my $domain     = $env{'user.domain'};
1.28      www       157:     my %userenv = &Apache::lonnet::get
1.32      www       158:         ('environment',['languages']);
1.29      www       159:     my $language=$userenv{'languages'};
1.32      www       160: 
1.33      www       161:     my $pref=&mt('Preferred language');
                    162:     my %langchoices=('' => 'No language preference');
                    163:     foreach (&Apache::loncommon::languageids()) {
                    164: 	if (&Apache::loncommon::supportedlanguagecode($_)) {
                    165: 	    $langchoices{&Apache::loncommon::supportedlanguagecode($_)}
                    166: 	               = &Apache::loncommon::plainlanguagedescription($_);
                    167: 	}
                    168:     }
1.190     raeburn   169:     %langchoices = &Apache::lonlocal::texthash(%langchoices);
1.179     bisitz    170:     my $selectionbox=
                    171:            &Apache::loncommon::select_form(
                    172:                $language,
                    173:                'language',
1.190     raeburn   174:                \%langchoices);
1.28      www       175:     $r->print(<<ENDLSCREEN);
1.88      albertel  176: <form name="prefs" action="/adm/preferences" method="post">
1.28      www       177: <input type="hidden" name="action" value="verify_and_change_languages" />
1.33      www       178: <br />$pref: $selectionbox
1.28      www       179: ENDLSCREEN
1.136     schafran  180:     $r->print('<br /><input type="submit" value="'.&mt('Save').'" />');
1.28      www       181: }
                    182: 
                    183: 
                    184: sub verify_and_change_languages {
                    185:     my $r = shift;
1.59      albertel  186:     my $user       = $env{'user.name'};
                    187:     my $domain     = $env{'user.domain'};
1.28      www       188: # Screenname
1.59      albertel  189:     my $newlanguage  = $env{'form.language'};
1.28      www       190:     $newlanguage=~s/[^\-\w]//g;
                    191:     my $message='';
                    192:     if ($newlanguage) {
1.29      www       193:         &Apache::lonnet::put('environment',{'languages' => $newlanguage});
1.116     raeburn   194:         &Apache::lonnet::appenv({'environment.languages' => $newlanguage});
1.183     bisitz    195:         $message=&Apache::lonhtmlcommon::confirm_success(
                    196:             &mt('Set [_1] to [_2]',
                    197:                 '<i>'.&mt('Preferred language').'</i>',
                    198:                 '<tt>"'.$newlanguage.'"</tt>.'))
                    199:            .'<br />'
                    200:            .&mt('The change will become active on the next page.');
1.28      www       201:     } else {
1.29      www       202:         &Apache::lonnet::del('environment',['languages']);
1.139     raeburn   203:         &Apache::lonnet::delenv('environment.languages');
1.158     bisitz    204:         $message=&Apache::lonhtmlcommon::confirm_success(&mt('Reset [_1]','<i>'.&mt('Preferred language').'</i>'));
1.28      www       205:     }
1.158     bisitz    206:     $message=&Apache::loncommon::confirmwrapper($message);
1.132     raeburn   207:     &Apache::loncommon::flush_langs_cache($user,$domain);
1.152     www       208:     &print_main_menu($r, $message);
1.28      www       209: }
                    210: 
1.50      albertel  211: ################################################################
1.54      albertel  212: #         Tex Engine Change Subroutines                        #
                    213: ################################################################
                    214: sub texenginechanger {
                    215:     my $r = shift;
1.126     droeschl  216:     Apache::lonhtmlcommon::add_breadcrumb(
                    217: 	    {	href => '/adm/preferences?action=changetexenginepref',
1.177     raeburn   218:                 text => 'Math display settings'});
1.147     schafran  219:     $r->print(Apache::loncommon::start_page('Content Display Settings'));
1.177     raeburn   220:     $r->print(Apache::lonhtmlcommon::breadcrumbs('Math display settings'));
1.59      albertel  221:     my $user       = $env{'user.name'};
                    222:     my $domain     = $env{'user.domain'};
1.54      albertel  223:     my %userenv = &Apache::lonnet::get('environment',['texengine']);
                    224:     my $texengine=$userenv{'texengine'};
                    225: 
1.69      albertel  226:     my %mathchoices=('' => 'Default',
1.123     bisitz    227: 		     'tth' => 'tth (TeX to HTML)',
1.64      albertel  228: 		     #'ttm' => 'TeX to MathML',
1.54      albertel  229: 		     'jsMath' => 'jsMath',
1.195     dseaton   230: 		     'MathJax' => 'MathJax',
1.168     www       231: 		     'mimetex' => 'mimetex (Convert to Images)',
                    232:                      'raw' => 'Raw (Screen Reader)'
1.54      albertel  233:                      );
1.190     raeburn   234:     %mathchoices = &Apache::lonlocal::texthash(%mathchoices);
1.179     bisitz    235:     my $selectionbox=
                    236:            &Apache::loncommon::select_form(
                    237:                $texengine,
                    238:                'texengine',
1.190     raeburn   239:                \%mathchoices);
1.195     dseaton   240:     my $MathJax_start=&Apache::lontexconvert::MathJax_header();
1.67      albertel  241:     my $jsMath_start=&Apache::lontexconvert::jsMath_header();
1.123     bisitz    242:     my %lt=&Apache::lonlocal::texthash(
1.177     raeburn   243:       'headline' => 'Change how math is displayed',
                    244:       'preftxt'  => 'Preferred method to display math',
1.136     schafran  245:       'change'   => 'Save',
1.123     bisitz    246:       'exmpl'    => 'Examples',
1.195     dseaton   247:       'mathjax'  => 'MathJax:',
1.123     bisitz    248:       'jsmath'   => 'jsMath:',
                    249:       'tth'      => 'tth (TeX to HTML):',
                    250:       'mimetex'  => 'mimetex (Convert to Images):',
                    251:     );
                    252: 
1.162     bisitz    253:     my $jsMathWarning='<p>'
                    254:                      .'<div class="LC_warning">'
                    255:                      .&mt("It looks like you don't have the TeX math fonts installed.")
                    256:                      .'</div>'
                    257:                      .'<div>'
                    258:                      .&mt('The jsMath example on this page may not look right without them. '
                    259:                          .'The [_1]jsMath Home Page[_2] has information on how to download the '
                    260:                          .'needed fonts. In the meantime, jsMath will do the best it can '
                    261:                          .'with the fonts you have, but it may not be pretty and some equations '
                    262:                          .'may not be rendered correctly.'
                    263:                          ,'<a href="http://www.math.union.edu/locate/jsMath/" target="_blank">'
                    264:                          ,'</a>')
                    265:                      .'</div>'
                    266:                      .'</p>';
                    267: 
1.54      albertel  268:     $r->print(<<ENDLSCREEN);
1.123     bisitz    269: <h2>$lt{'headline'}</h2>
1.88      albertel  270: <form name="prefs" action="/adm/preferences" method="post">
1.54      albertel  271: <input type="hidden" name="action" value="verify_and_change_texengine" />
1.123     bisitz    272: <p>
1.136     schafran  273: $lt{'preftxt'}: $selectionbox 
                    274: <br />
                    275: <input type="submit" value="$lt{'change'}" />
1.123     bisitz    276: </p>
1.54      albertel  277: </form>
1.123     bisitz    278: <br />
                    279: <hr />
                    280: $lt{'exmpl'}
                    281: 
1.195     dseaton   282: <h3>$lt{'mathjax'}</h3>
                    283: </script>
                    284: <iframe src="/res/adm/pages/math_example.tex?inhibitmenu=yes&texengine=MathJax" width="400" height="120"></iframe>
                    285: </p>
                    286: <p>
                    287: MathJax provides rendered equations whose source code can be extracted in TeX and MathML formats by right clicking the equation.
                    288: </p>
                    289: 
1.123     bisitz    290: <h3>$lt{'jsmath'}</h3> 
                    291: <p>
1.67      albertel  292: $jsMath_start
1.148     bisitz    293: <script type="text/javascript" language="JavaScript">
1.54      albertel  294: if (jsMath.nofonts == 1) {
1.162     bisitz    295:     document.writeln($jsMathWarning);
1.54      albertel  296: }
1.195     dseaton   297: 
1.54      albertel  298: </script>
1.122     www       299: <iframe src="/res/adm/pages/math_example.tex?inhibitmenu=yes&texengine=jsMath" width="400" height="120"></iframe>
1.123     bisitz    300: </p>
1.54      albertel  301: 
1.123     bisitz    302: <h3>$lt{'mimetex'}</h3>
                    303: <p>
                    304: <iframe src="/res/adm/pages/math_example.tex?inhibitmenu=yes&texengine=mimetex" width="400" height="100"></iframe>
1.67      albertel  305: </p>
1.123     bisitz    306: 
                    307: <h3>$lt{'tth'}</h3>
                    308: <p>
1.177     raeburn   309: <iframe src="/res/adm/pages/math_example.tex?inhibitmenu=yes&texengine=tth" width="400" height="220"></iframe>
1.67      albertel  310: </p>
1.54      albertel  311: ENDLSCREEN
1.59      albertel  312:     if ($env{'environment.texengine'} ne 'jsMath') {
1.148     bisitz    313: 	$r->print('<script type="text/javascript" language="JavaScript">jsMath.Process()</script>');
1.55      albertel  314:     }
1.54      albertel  315: }
                    316: 
                    317: 
                    318: sub verify_and_change_texengine {
                    319:     my $r = shift;
1.59      albertel  320:     my $user       = $env{'user.name'};
                    321:     my $domain     = $env{'user.domain'};
1.54      albertel  322: # Screenname
1.59      albertel  323:     my $newtexengine  = $env{'form.texengine'};
1.54      albertel  324:     $newtexengine=~s/[^\-\w]//g;
1.56      albertel  325:     if ($newtexengine eq 'ttm') {
1.116     raeburn   326: 	&Apache::lonnet::appenv({'browser.mathml' => 1});
1.56      albertel  327:     } else {
1.59      albertel  328: 	if ($env{'environment.texengine'} eq 'ttm') {
1.116     raeburn   329: 	    &Apache::lonnet::appenv({'browser.mathml' => 0});
1.56      albertel  330: 	}
                    331:     }
1.54      albertel  332:     my $message='';
                    333:     if ($newtexengine) {
                    334:         &Apache::lonnet::put('environment',{'texengine' => $newtexengine});
1.116     raeburn   335:         &Apache::lonnet::appenv({'environment.texengine' => $newtexengine});
1.158     bisitz    336:         $message=&Apache::lonhtmlcommon::confirm_success(&mt('Set [_1] to [_2]','<i>'.&mt('Preferred method to display Math').'</i>','<tt>"'.$newtexengine.'"</tt>'));
1.54      albertel  337:     } else {
                    338:         &Apache::lonnet::del('environment',['texengine']);
1.139     raeburn   339:         &Apache::lonnet::delenv('environment.texengine');
1.158     bisitz    340:         $message=&Apache::lonhtmlcommon::confirm_success(&mt('Reset [_1]','<i>'.&mt('Preferred method to display Math').'</i>'));
1.54      albertel  341:     }
1.158     bisitz    342:     $message=&Apache::loncommon::confirmwrapper($message);
1.152     www       343:     &print_main_menu($r, $message);
1.54      albertel  344: }
                    345: 
                    346: ################################################################
1.50      albertel  347: #         Roles Page Preference Change Subroutines         #
                    348: ################################################################
                    349: sub rolesprefchanger {
                    350:     my $r = shift;
1.96      albertel  351:     my $role    = ($env{'user.adv'} ? 'Role' : 'Course');
                    352:     my $lc_role = ($env{'user.adv'} ? 'role' : 'course');
1.59      albertel  353:     my $user       = $env{'user.name'};
                    354:     my $domain     = $env{'user.domain'};
1.50      albertel  355:     my %userenv = &Apache::lonnet::get
                    356:         ('environment',['recentroles','recentrolesn']);
1.198     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.198     raeburn   366:                 text => $brtext});
1.147     schafran  367:     $r->print(Apache::loncommon::start_page('Content Display Settings'));
1.198     raeburn   368:     $r->print(Apache::lonhtmlcommon::breadcrumbs($brtitle));
1.50      albertel  369:     my $hotlist_flag=$userenv{'recentroles'};
                    370:     my $hotlist_n=$userenv{'recentrolesn'};
1.198     raeburn   371:     my ($checkedon,$checkedoff);
1.50      albertel  372:     if ($hotlist_flag) {
1.198     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.198     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.198     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.198     raeburn   434: <form name="prefs" action="'.$actionurl.'" method="post">
1.50      albertel  435: <input type="hidden" name="action" value="verify_and_change_rolespref" />
1.198     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.198     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.198     raeburn   451: $options.'
                    452: </select>'.
1.181     wenzelju  453: &Apache::lonhtmlcommon::row_closure(1).
1.198     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.198     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.198     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.197     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.197     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.200   ! foxr     1230: 	   '<td>'.$colortypes{$item}.'<td><input name="'.$item.
        !          1231:         '" class="colorchooser"  size="10" value="'.$curcol.
        !          1232: '" /></td>'.
1.83      albertel 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.200   ! foxr     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:     $r->print(<<ENDCOL);
                   1246: 
1.21      www      1247: <form name="parmform">
                   1248: <input type="hidden" name="pres_marker" />
                   1249: <input type="hidden" name="pres_type" />
                   1250: <input type="hidden" name="pres_value" />
                   1251: </form>
1.88      albertel 1252: <form name="prefs" action="/adm/preferences" method="post">
1.19      www      1253: <input type="hidden" name="action" value="verify_and_change_colors" />
1.82      albertel 1254: $start_data_table
1.19      www      1255: $chtable
1.82      albertel 1256: $end_data_table
1.19      www      1257: </table>
1.157     bisitz   1258: <p>
                   1259: <input type="submit" value="$savebutton" />
                   1260: <input type="submit" name="resetall" value="$resetbutton" title="$resetbuttondesc" />
                   1261: </p>
1.12      www      1262: </form>
1.19      www      1263: ENDCOL
1.12      www      1264: }
                   1265: 
1.19      www      1266: sub verify_and_change_colors {
1.12      www      1267:     my $r = shift;
1.19      www      1268: # figure out colors
1.80      albertel 1269:     my $function=&Apache::loncommon::get_users_function();
1.19      www      1270:     my $domain=&Apache::loncommon::determinedomain();
1.157     bisitz   1271:     my %colortypes=&Apache::lonlocal::texthash(
                   1272:         'pgbg'     => 'Page Background Color',
                   1273:         'tabbg'    => 'Header Background Color',
                   1274:         'sidebg'   => 'Header Border Color',
                   1275:         'font'     => 'Font Color',
                   1276: 	'fontmenu' => 'Font Menu Color',
                   1277:         'link'     => 'Un-Visited Link Color',
                   1278:         'vlink'    => 'Visited Link Color',
                   1279:         'alink'    => 'Active Link Color',
                   1280:     );
1.19      www      1281: 
1.12      www      1282:     my $message='';
1.21      www      1283:     foreach my $item (keys %colortypes) {
1.59      albertel 1284:         my $color=$env{'form.'.$item};
1.200   ! foxr     1285: 	if (!($color =~ /^#/)) {
        !          1286: 	    $color = '#' . $color;
        !          1287: 	}
1.21      www      1288:         my $entry='color.'.$function.'.'.$item;
1.59      albertel 1289: 	if (($color=~/^\#[0-9A-Fa-f]{6}$/) && (!$env{'form.resetall'})) {
1.21      www      1290: 	    &Apache::lonnet::put('environment',{$entry => $color});
1.116     raeburn  1291: 	    &Apache::lonnet::appenv({'environment.'.$entry => $color});
1.157     bisitz   1292:             $message.=&Apache::lonhtmlcommon::confirm_success(&mt('Set [_1] to [_2]','<i>'.$colortypes{$item}.'</i>','<tt>"'.$color.'"</tt>'))
                   1293:                     .'<br />';
1.21      www      1294: 	} else {
                   1295: 	    &Apache::lonnet::del('environment',[$entry]);
1.138     schafran 1296: 	    &Apache::lonnet::delenv('environment.'.$entry);
1.157     bisitz   1297:             $message.=&Apache::lonhtmlcommon::confirm_success(&mt('Reset [_1]','<i>'.$colortypes{$item}.'</i>'))
                   1298:                      .'<br />';
1.21      www      1299: 	}
                   1300:     }
1.158     bisitz   1301:     $message=&Apache::loncommon::confirmwrapper($message);
1.157     bisitz   1302: 
1.84      albertel 1303:     my $now = time;
                   1304:     &Apache::lonnet::put('environment',{'color.timestamp' => $now});
1.116     raeburn  1305:     &Apache::lonnet::appenv({'environment.color.timestamp' => $now});
1.84      albertel 1306: 
1.152     www      1307:     &print_main_menu($r, $message);
1.12      www      1308: }
                   1309: 
1.4       matthew  1310: ######################################################
                   1311: #            password handler subroutines            #
                   1312: ######################################################
1.3       matthew  1313: sub passwordchanger {
1.94      raeburn  1314:     my ($r,$errormessage,$caller,$mailtoken) = @_;
1.4       matthew  1315:     # This function is a bit of a mess....
1.3       matthew  1316:     # Passwords are encrypted using londes.js (DES encryption)
1.4       matthew  1317:     $errormessage = ($errormessage || '');
1.193     raeburn  1318:     my ($user,$domain,$currentpass);
1.152     www      1319:     &Apache::lonhtmlcommon::add_breadcrumb(
1.126     droeschl 1320: 		{ href => '/adm/preferences?action=changepass',
                   1321:                   text => 'Change Password'});
1.144     raeburn  1322:     unless ($caller eq 'reset_by_email') {
1.147     schafran 1323:         $r->print(Apache::loncommon::start_page('Personal Data'));
1.144     raeburn  1324:         $r->print(Apache::lonhtmlcommon::breadcrumbs('Change Password'));
                   1325:     }
1.94      raeburn  1326:     if ((!defined($caller)) || ($caller eq 'preferences')) {
                   1327:         $user = $env{'user.name'};
                   1328:         $domain = $env{'user.domain'};
                   1329:         if (!defined($caller)) {
                   1330:             $caller = 'preferences';
                   1331:         }
                   1332:     } elsif ($caller eq 'reset_by_email') {
                   1333:             my %data = &Apache::lonnet::tmpget($mailtoken);
                   1334:             if (keys(%data) == 0) {
1.199     bisitz   1335:                 $r->print(
                   1336:                     '<p class="LC_warning">'
                   1337:                    .&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.'
                   1338:                        ,'<a href="/adm/resetpw">','</a>')
                   1339:                    .'</p>'
1.155     bisitz   1340:                 );
1.94      raeburn  1341:                 return;
                   1342:             }
                   1343:             if (defined($data{time})) {
                   1344:                 if (time - $data{'time'} < 7200) {
                   1345:                     $user = $data{'username'};
                   1346:                     $domain = $data{'domain'};
                   1347:                     $currentpass = $data{'temppasswd'};
                   1348:                 } else {
1.199     bisitz   1349:                     $r->print(
                   1350:                         '<p class="LC_warning">'
                   1351:                        .&mt('Sorry, the token generated when you requested'
                   1352:                            .' a password reset has expired.')
                   1353:                        .'</p>'
                   1354:                     );
1.94      raeburn  1355:                     return;
                   1356:                 }
                   1357:             } else {
1.199     bisitz   1358:                 $r->print(
                   1359:                     '<p class="LC_warning">'
                   1360:                    .&mt('Sorry, the URL generated when you requested reset of'
                   1361:                        .' your password contained incomplete information.')
                   1362:                    .'</p>'
                   1363:                 );
1.94      raeburn  1364:                 return;
                   1365:             }
1.193     raeburn  1366:             if (&Apache::lonnet::domain($domain) eq '') {
                   1367:                 $domain = $r->dir_config('lonDefDomain');
                   1368:             }
                   1369:     } else {
1.199     bisitz   1370:         $r->print(
                   1371:             '<p class="LC_error">'
                   1372:            .&mt('Page requested in unexpected context')
                   1373:            .'</p>'
                   1374:         );
1.94      raeburn  1375:         return;
                   1376:     }
1.3       matthew  1377:     my $currentauth=&Apache::lonnet::queryauthenticate($user,$domain);
                   1378:     # Check for authentication types that allow changing of the password.
                   1379:     return if ($currentauth !~ /^(unix|internal):/);
                   1380:     #
                   1381:     # Generate keys
                   1382:     my ($lkey_cpass ,$ukey_cpass ) = &des_keys();
                   1383:     my ($lkey_npass1,$ukey_npass1) = &des_keys();
                   1384:     my ($lkey_npass2,$ukey_npass2) = &des_keys();
1.4       matthew  1385:     # Store the keys in the log files
1.3       matthew  1386:     my $lonhost = $r->dir_config('lonHostID');
                   1387:     my $logtoken=Apache::lonnet::reply('tmpput:'
                   1388: 				       .$ukey_cpass  . $lkey_cpass .'&'
                   1389: 				       .$ukey_npass1 . $lkey_npass1.'&'
                   1390: 				       .$ukey_npass2 . $lkey_npass2,
                   1391: 				       $lonhost);
1.4       matthew  1392:     # Hexify the keys for output as javascript variables
1.94      raeburn  1393:     my %hexkey;
                   1394:     $hexkey{'ukey_cpass'}  = hex($ukey_cpass);
                   1395:     $hexkey{'lkey_cpass'}  = hex($lkey_cpass);
                   1396:     $hexkey{'ukey_npass1'} = hex($ukey_npass1);
                   1397:     $hexkey{'lkey_npass1'} = hex($lkey_npass1);
                   1398:     $hexkey{'ukey_npass2'} = hex($ukey_npass2);
                   1399:     $hexkey{'lkey_npass2'} = hex($lkey_npass2);
1.3       matthew  1400:     # Output javascript to deal with passwords
1.4       matthew  1401:     # Output DES javascript
1.3       matthew  1402:     {
                   1403: 	my $include = $r->dir_config('lonIncludes');
                   1404: 	my $jsh=Apache::File->new($include."/londes.js");
                   1405: 	$r->print(<$jsh>);
                   1406:     }
1.94      raeburn  1407:     $r->print(&jscript_send($caller));
1.3       matthew  1408:     $r->print(<<ENDFORM);
1.94      raeburn  1409: $errormessage
                   1410: 
                   1411: <p>
                   1412: <!-- We separate the forms into 'server' and 'client' in order to
                   1413:      ensure that unencrypted passwords will not be sent out by a
                   1414:      crappy browser -->
                   1415: ENDFORM
                   1416:     $r->print(&server_form($logtoken,$caller,$mailtoken));
1.193     raeburn  1417:     $r->print(&client_form($caller,\%hexkey,$currentpass,$domain));
1.94      raeburn  1418: 
                   1419:     #
                   1420:     return;
                   1421: }
                   1422: 
                   1423: sub jscript_send {
                   1424:     my ($caller) = @_;
                   1425:     my $output = qq|
1.148     bisitz   1426: <script type="text/javascript" language="JavaScript">
1.3       matthew  1427: 
                   1428:     function send() {
                   1429:         uextkey=this.document.client.elements.ukey_cpass.value;
                   1430:         lextkey=this.document.client.elements.lkey_cpass.value;
                   1431:         initkeys();
                   1432: 
1.52      raeburn  1433:         this.document.pserver.elements.currentpass.value
1.3       matthew  1434:             =crypted(this.document.client.elements.currentpass.value);
                   1435: 
                   1436:         uextkey=this.document.client.elements.ukey_npass1.value;
                   1437:         lextkey=this.document.client.elements.lkey_npass1.value;
                   1438:         initkeys();
1.52      raeburn  1439:         this.document.pserver.elements.newpass_1.value
1.3       matthew  1440:             =crypted(this.document.client.elements.newpass_1.value);
                   1441: 
                   1442:         uextkey=this.document.client.elements.ukey_npass2.value;
                   1443:         lextkey=this.document.client.elements.lkey_npass2.value;
                   1444:         initkeys();
1.52      raeburn  1445:         this.document.pserver.elements.newpass_2.value
1.3       matthew  1446:             =crypted(this.document.client.elements.newpass_2.value);
1.94      raeburn  1447: |;
                   1448:     if ($caller eq 'reset_by_email') {
                   1449:         $output .= qq|
                   1450:         this.document.pserver.elements.uname.value =
                   1451:                    this.document.client.elements.uname.value;
                   1452:         this.document.pserver.elements.udom.value =
                   1453:                    this.document.client.elements.udom.options[this.document.client.elements.udom.selectedIndex].value;
1.173     raeburn  1454:         this.document.pserver.elements.email.value =
                   1455:                    this.document.client.elements.email.value;
1.94      raeburn  1456: |;
                   1457:     }
                   1458:     $ output .= qq|
1.52      raeburn  1459:         this.document.pserver.submit();
1.3       matthew  1460:     }
                   1461: </script>
1.94      raeburn  1462: |;
                   1463: }
1.3       matthew  1464: 
1.94      raeburn  1465: sub client_form {
                   1466:     my ($caller,$hexkey,$currentpass,$defdom) = @_;
1.99      www      1467:     my %lt=&Apache::lonlocal::texthash(
1.115     raeburn  1468:                 'email' => 'E-mail Address',
1.99      www      1469:                 'username' => 'Username',
                   1470:                 'domain' => 'Domain',
                   1471:                 'currentpass' => 'Current Password',
                   1472:                 'newpass' => 'New Password',
                   1473:                 'confirmpass' => 'Confirm Password',
1.169     raeburn  1474:                 'changepass' => 'Save',
                   1475:     );
1.99      www      1476: 
1.164     bisitz   1477:     my $output = '<form name="client">'
                   1478:                 .&Apache::lonhtmlcommon::start_pick_box();
1.94      raeburn  1479:     if ($caller eq 'reset_by_email') {
1.164     bisitz   1480:         $output .= &Apache::lonhtmlcommon::row_title(
                   1481:                        '<label for="email">'.$lt{'email'}.'</label>')
                   1482:                   .'<input type="text" name="email" size="30" />'
                   1483:                   .&Apache::lonhtmlcommon::row_closure()
                   1484:                   .&Apache::lonhtmlcommon::row_title(
                   1485:                        '<label for="uname">'.$lt{'username'}.'</label>')
                   1486:                   .'<input type="text" name="uname" size="15" />'
                   1487:                   .'<input type="hidden" name="currentpass" value="'.$currentpass.'" />'
                   1488:                   .&Apache::lonhtmlcommon::row_closure()
                   1489:                   .&Apache::lonhtmlcommon::row_title(
                   1490:                        '<label for="udom">'.$lt{'domain'}.'</label>')
                   1491:                   .&Apache::loncommon::select_dom_form($defdom,'udom')
                   1492:                   .&Apache::lonhtmlcommon::row_closure();
1.94      raeburn  1493:     } else {
1.164     bisitz   1494:         $output .= &Apache::lonhtmlcommon::row_title(
                   1495:                        '<label for="currentpass">'.$lt{'currentpass'}.'</label>')
                   1496:                   .'<input type="password" name="currentpass" size="10"/>'
                   1497:                   .&Apache::lonhtmlcommon::row_closure();
                   1498:     }
                   1499:     $output .= &Apache::lonhtmlcommon::row_title(
                   1500:                    '<label for="newpass_1">'.$lt{'newpass'}.'</label>')
                   1501:               .'<input type="password" name="newpass_1" size="10" />'
                   1502:               .&Apache::lonhtmlcommon::row_closure()
                   1503:               .&Apache::lonhtmlcommon::row_title(
                   1504:                    '<label for="newpass_2">'.$lt{'confirmpass'}.'</label>')
                   1505:               .'<input type="password" name="newpass_2" size="10" />'
                   1506:               .&Apache::lonhtmlcommon::row_closure(1)
                   1507:               .&Apache::lonhtmlcommon::end_pick_box();
                   1508:     $output .= '<p><input type="button" value="'.$lt{'changepass'}.'" onClick="send();" /></p>'
                   1509:               .qq|
1.94      raeburn  1510: <input type="hidden" name="ukey_cpass"  value="$hexkey->{'ukey_cpass'}" />
                   1511: <input type="hidden" name="lkey_cpass"  value="$hexkey->{'lkey_cpass'}" />
                   1512: <input type="hidden" name="ukey_npass1" value="$hexkey->{'ukey_npass1'}" />
                   1513: <input type="hidden" name="lkey_npass1" value="$hexkey->{'lkey_npass1'}" />
                   1514: <input type="hidden" name="ukey_npass2" value="$hexkey->{'ukey_npass2'}" />
                   1515: <input type="hidden" name="lkey_npass2" value="$hexkey->{'lkey_npass2'}" />
1.3       matthew  1516: </form>
                   1517: </p>
1.164     bisitz   1518: |;
1.94      raeburn  1519:     return $output;
                   1520: }
                   1521: 
                   1522: sub server_form {
                   1523:     my ($logtoken,$caller,$mailtoken) = @_;
                   1524:     my $action = '/adm/preferences';
                   1525:     if ($caller eq 'reset_by_email') {
                   1526:         $action = '/adm/resetpw';
                   1527:     }
                   1528:     my $output = qq|
                   1529: <form name="pserver" action="$action" method="post">
                   1530: <input type="hidden" name="logtoken"    value="$logtoken" />
                   1531: <input type="hidden" name="currentpass" value="" />
                   1532: <input type="hidden" name="newpass_1"   value="" />
                   1533: <input type="hidden" name="newpass_2"   value="" />
                   1534:     |;
                   1535:     if ($caller eq 'reset_by_email') {
                   1536:         $output .=  qq|
                   1537: <input type="hidden" name="token"   value="$mailtoken" />
                   1538: <input type="hidden" name="uname"   value="" />
                   1539: <input type="hidden" name="udom"   value="" />
1.173     raeburn  1540: <input type="hidden" name="email"   value="" />
1.94      raeburn  1541: 
                   1542: |;
                   1543:     }
                   1544:     $output .= qq|
                   1545: <input type="hidden" name="action" value="verify_and_change_pass" />
                   1546: </form>
                   1547: |;
                   1548:     return $output;
1.3       matthew  1549: }
                   1550: 
                   1551: sub verify_and_change_password {
1.94      raeburn  1552:     my ($r,$caller,$mailtoken) = @_;
                   1553:     my ($user,$domain,$homeserver);
                   1554:     if ($caller eq 'reset_by_email') {
                   1555:         $user       = $env{'form.uname'};
                   1556:         $domain     = $env{'form.udom'};
                   1557:         if ($user ne '' && $domain ne '') {
                   1558:             $homeserver = &Apache::lonnet::homeserver($user,$domain);
                   1559:             if ($homeserver eq 'no_host') {
1.99      www      1560:         &passwordchanger($r,"<p>\n<span class='LC_error'>".
                   1561:                          &mt("Invalid username and/or domain")."</span>\n</p>",
1.94      raeburn  1562:                          $caller,$mailtoken);
                   1563:                 return 1;
                   1564:             }
                   1565:         } else {
1.99      www      1566:             &passwordchanger($r,"<p>\n<span class='LC_error'>".
                   1567:                              &mt("Username and domain were blank")."</span>\n</p>",
1.94      raeburn  1568:                              $caller,$mailtoken);
                   1569:             return 1;
                   1570:         }
                   1571:     } else {
                   1572:         $user       = $env{'user.name'};
                   1573:         $domain     = $env{'user.domain'};
                   1574:         $homeserver = $env{'user.home'};
                   1575:     }
1.3       matthew  1576:     my $currentauth=&Apache::lonnet::queryauthenticate($user,$domain);
1.4       matthew  1577:     # Check for authentication types that allow changing of the password.
1.94      raeburn  1578:     if ($currentauth !~ /^(unix|internal):/) {
                   1579:         if ($caller eq 'reset_by_email') {
1.99      www      1580:             &passwordchanger($r,"<p>\n<span class='LC_error'>".
                   1581:                              &mt("Authentication type for this user can not be changed by this mechanism").
                   1582:                              "</span>\n</p>",
1.94      raeburn  1583:                               $caller,$mailtoken);
                   1584:             return 1;
                   1585:         } else {
                   1586:             return;
                   1587:         }
                   1588:     }
1.3       matthew  1589:     #
1.59      albertel 1590:     my $currentpass = $env{'form.currentpass'}; 
                   1591:     my $newpass1    = $env{'form.newpass_1'}; 
                   1592:     my $newpass2    = $env{'form.newpass_2'};
                   1593:     my $logtoken    = $env{'form.logtoken'};
1.3       matthew  1594:     # Check for empty data 
1.4       matthew  1595:     unless (defined($currentpass) && 
                   1596: 	    defined($newpass1)    && 
                   1597: 	    defined($newpass2)    ){
1.99      www      1598: 	&passwordchanger($r,"<p>\n<span class='LC_error'>".
                   1599: 			 &mt("One or more password fields were blank").
                   1600:                          "</span>\n</p>",$caller,$mailtoken);
1.3       matthew  1601: 	return;
                   1602:     }
1.16      albertel 1603:     # Get the keys
                   1604:     my $lonhost = $r->dir_config('lonHostID');
1.3       matthew  1605:     my $tmpinfo = Apache::lonnet::reply('tmpget:'.$logtoken,$lonhost);
                   1606:     if (($tmpinfo=~/^error/) || ($tmpinfo eq 'con_lost')) {
1.4       matthew  1607:         # I do not a have a better idea about how to handle this
1.94      raeburn  1608:         my $tryagain_text = &mt('Please log out and try again.');
                   1609:         if ($caller eq 'reset_by_email') {
                   1610:             $tryagain_text = &mt('Please try again later.');
                   1611:         }
1.101     albertel 1612:         my $unable=&mt("Unable to retrieve saved token for password decryption");
1.3       matthew  1613: 	$r->print(<<ENDERROR);
                   1614: <p>
1.99      www      1615: <span class="LC_error">$unable.  $tryagain_text</span>
1.3       matthew  1616: </p>
                   1617: ENDERROR
1.4       matthew  1618:         # Probably should log an error here
1.75      albertel 1619:         return 1;
1.3       matthew  1620:     }
                   1621:     my ($ckey,$n1key,$n2key)=split(/&/,$tmpinfo);
1.4       matthew  1622:     # 
1.17      matthew  1623:     $currentpass = &des_decrypt($ckey ,$currentpass);
                   1624:     $newpass1    = &des_decrypt($n1key,$newpass1);
                   1625:     $newpass2    = &des_decrypt($n2key,$newpass2);
1.94      raeburn  1626:     #
                   1627:     if ($caller eq 'reset_by_email') {
                   1628:         my %data = &Apache::lonnet::tmpget($mailtoken);
1.117     raeburn  1629:         if (keys(%data) == 0) {
                   1630:             &passwordchanger($r,
                   1631:                          '<span class="LC_error">'.
                   1632:                          &mt('Could not verify current authentication.').'  '.
                   1633:                          &mt('Please try again.').'</span>',$caller,$mailtoken);
                   1634:             return 1;
                   1635:         }
1.94      raeburn  1636:         if ($currentpass ne $data{'temppasswd'}) {
                   1637:             &passwordchanger($r,
1.99      www      1638:                          '<span class="LC_error">'.
1.110     bisitz   1639:                          &mt('Could not verify current authentication.').'  '.
                   1640:                          &mt('Please try again.').'</span>',$caller,$mailtoken);
1.94      raeburn  1641:             return 1;
                   1642:         }
                   1643:     } 
1.3       matthew  1644:     if ($newpass1 ne $newpass2) {
1.4       matthew  1645: 	&passwordchanger($r,
1.199     bisitz   1646: 			 '<span class="LC_warning">'.
1.110     bisitz   1647: 			 &mt('The new passwords you entered do not match.').'  '.
                   1648: 			 &mt('Please try again.').'</span>',$caller,$mailtoken);
1.75      albertel 1649: 	return 1;
1.4       matthew  1650:     }
                   1651:     if (length($newpass1) < 7) {
                   1652: 	&passwordchanger($r,
1.199     bisitz   1653: 			 '<span class="LC_warning">'.
1.110     bisitz   1654: 			 &mt('Passwords must be a minimum of 7 characters long.').'  '.
                   1655: 			 &mt('Please try again.').'</span>',$caller,$mailtoken);
1.75      albertel 1656: 	return 1;
1.3       matthew  1657:     }
1.4       matthew  1658:     #
                   1659:     # Check for bad characters
                   1660:     my $badpassword = 0;
                   1661:     foreach (split(//,$newpass1)) {
                   1662: 	$badpassword = 1 if ((ord($_)<32)||(ord($_)>126));
                   1663:     }
                   1664:     if ($badpassword) {
                   1665: 	# I can't figure out how to enter bad characters on my browser.
1.199     bisitz   1666: 	my $errormessage ='<span class="LC_warning">'.
1.110     bisitz   1667:            &mt('The password you entered contained illegal characters.').'<br />'.
1.99      www      1668:            &mt('Valid characters are').(<<"ENDERROR");
                   1669: : space and <br />
1.4       matthew  1670: <pre>
                   1671: !&quot;\#$%&amp;\'()*+,-./0123456789:;&lt;=&gt;?\@
                   1672: ABCDEFGHIJKLMNOPQRSTUVWXYZ[\]^_\`abcdefghijklmnopqrstuvwxyz{|}~
1.99      www      1673: </pre></span>
1.4       matthew  1674: ENDERROR
1.94      raeburn  1675:         &passwordchanger($r,$errormessage,$caller,$mailtoken);
                   1676:         return 1;
1.4       matthew  1677:     }
                   1678:     # 
                   1679:     # Change the password (finally)
                   1680:     my $result = &Apache::lonnet::changepass
1.94      raeburn  1681: 	($user,$domain,$currentpass,$newpass1,$homeserver,$caller);
1.4       matthew  1682:     # Inform the user the password has (not?) been changed
1.126     droeschl 1683:     my $message;
1.4       matthew  1684:     if ($result =~ /^ok$/) {
1.170     bisitz   1685:         $message = &Apache::lonhtmlcommon::confirm_success(&mt('The password for user [_1] was successfully changed.','<i>'.$user.'</i>'));
1.180     wenzelju 1686:         $message = &Apache::loncommon::confirmwrapper($message);
1.144     raeburn  1687:         if ($caller eq 'reset_by_email') {
                   1688:             $r->print($message.'<br />');
                   1689:         } else {
                   1690:             &print_main_menu($r, $message);
                   1691:         }
1.4       matthew  1692:     } else {
                   1693: 	# error error: run in circles, scream and shout
1.173     raeburn  1694:         if ($caller eq 'reset_by_email') {
                   1695:             if (!$result) {
                   1696:                 return 1;
                   1697:             } else {
                   1698:                 return $result;
                   1699:             }
                   1700:         } else {
                   1701:             $message = &Apache::lonhtmlcommon::confirm_success(
                   1702:                 &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   1703:             $message=&Apache::loncommon::confirmwrapper($message);
1.144     raeburn  1704:             &print_main_menu($r, $message);
                   1705:         }
1.4       matthew  1706:     }
                   1707:     return;
1.3       matthew  1708: }
                   1709: 
1.42      raeburn  1710: ################################################################
                   1711: #            discussion display subroutines 
                   1712: ################################################################
                   1713: sub discussionchanger {
                   1714:     my $r = shift;
1.126     droeschl 1715:     Apache::lonhtmlcommon::add_breadcrumb(
                   1716: 	    {	href => '/adm/preferences?action=changediscussions',
                   1717:                 text => 'Change Discussion Preferences'});
1.178     bisitz   1718:     $r->print(Apache::loncommon::start_page('Change Discussion Preferences'));
1.126     droeschl 1719:     $r->print(Apache::lonhtmlcommon::breadcrumbs('Change Discussion Preferences'));
1.59      albertel 1720:     my $user       = $env{'user.name'};
                   1721:     my $domain     = $env{'user.domain'};
1.42      raeburn  1722:     my %userenv = &Apache::lonnet::get
1.43      raeburn  1723:         ('environment',['discdisplay','discmarkread']);
                   1724:     my $discdisp = 'allposts';
                   1725:     my $discmark = 'onmark';
                   1726: 
                   1727:     if (defined($userenv{'discdisplay'})) {
                   1728:         unless ($userenv{'discdisplay'} eq '') { 
                   1729:             $discdisp = $userenv{'discdisplay'};
                   1730:         }
                   1731:     }
                   1732:     if (defined($userenv{'discmarkread'})) {
1.171     raeburn  1733:         unless ($userenv{'discmarkread'} eq '') { 
1.43      raeburn  1734:             $discmark = $userenv{'discmarkread'};
                   1735:         }
                   1736:     }
                   1737: 
                   1738:     my $newdisp = 'unread';
                   1739:     my $newmark = 'ondisp';
                   1740: 
                   1741:     my $function = &Apache::loncommon::get_users_function();
                   1742:     my $color = &Apache::loncommon::designparm($function.'.tabbg',
1.59      albertel 1743:                                                     $env{'user.domain'});
1.43      raeburn  1744:     my %lt = &Apache::lonlocal::texthash(
                   1745:         'pref' => 'Display Preference',
                   1746:         'curr' => 'Current setting ',
                   1747:         'actn' => 'Action',
1.135     schafran 1748:         'sdpf' => 'Set display preferences for discussion posts for both discussion boards and individual resources in all your courses.',
1.43      raeburn  1749:         'prca' => 'Preferences can be set that determine',
1.135     schafran 1750:         'whpo' => 'Which posts are displayed when you display a discussion board or resource, and',
1.194     raeburn  1751:         'unwh' => 'Under what circumstances posts are identified as "NEW"',
1.43      raeburn  1752:         'allposts' => 'All posts',
                   1753:         'unread' => 'New posts only',
                   1754:         'ondisp' => 'Once displayed',
1.194     raeburn  1755:         'onmark' => 'Once marked not NEW',
1.43      raeburn  1756:         'disa' => 'Posts displayed?',
1.194     raeburn  1757:         'npmr' => 'New posts cease to be identified as "NEW"?',
1.43      raeburn  1758:         'thde'  => 'The preferences you set here can be overridden within each individual discussion.',
                   1759:         'chgt' => 'Change to '
                   1760:     );
                   1761:     my $dispchange = $lt{'unread'};
                   1762:     my $markchange = $lt{'ondisp'};
                   1763:     my $currdisp = $lt{'allposts'};
                   1764:     my $currmark = $lt{'onmark'};
                   1765: 
                   1766:     if ($discdisp eq 'unread') {
                   1767:         $dispchange = $lt{'allposts'};
                   1768:         $currdisp = $lt{'unread'};
                   1769:         $newdisp = 'allposts';
                   1770:     }
                   1771: 
                   1772:     if ($discmark eq 'ondisp') {
                   1773:         $markchange = $lt{'onmark'};
                   1774:         $currmark = $lt{'ondisp'};
                   1775:         $newmark = 'onmark';
1.42      raeburn  1776:     }
1.171     raeburn  1777: 
1.43      raeburn  1778:     $r->print(<<"END");
1.88      albertel 1779: <form name="prefs" action="/adm/preferences" method="post">
1.42      raeburn  1780: <input type="hidden" name="action" value="verify_and_change_discussion" />
                   1781: <br />
1.87      albertel 1782: $lt{'sdpf'}<br /> $lt{'prca'}  <ol><li>$lt{'whpo'}</li><li>$lt{'unwh'}</li></ol> 
1.82      albertel 1783: END
1.158     bisitz   1784: 
                   1785:     $r->print('<p class="LC_info">'.$lt{'thde'}.'</p>');
                   1786: 
1.82      albertel 1787:     $r->print(&Apache::loncommon::start_data_table());
                   1788:     $r->print(<<"END");
                   1789:        <tr>
                   1790:         <th>$lt{'pref'}</th>
                   1791:         <th>$lt{'curr'}</th>
                   1792:         <th>$lt{'actn'}?</th>
1.43      raeburn  1793:        </tr>
1.82      albertel 1794: END
                   1795:     $r->print(&Apache::loncommon::start_data_table_row());
                   1796:     $r->print(<<"END");
1.43      raeburn  1797:        <td>$lt{'disa'}</td>
                   1798:        <td>$lt{$discdisp}</td>
1.82      albertel 1799:        <td><label><input type="checkbox" name="discdisp" /><input type="hidden" name="newdisp" value="$newdisp" />&nbsp;$lt{'chgt'} "$dispchange"</label></td>
                   1800: END
                   1801:     $r->print(&Apache::loncommon::end_data_table_row().
                   1802: 	      &Apache::loncommon::start_data_table_row());
                   1803:     $r->print(<<"END");
1.43      raeburn  1804:        <td>$lt{'npmr'}</td>
                   1805:        <td>$lt{$discmark}</td>
1.82      albertel 1806:        <td><label><input type="checkbox" name="discmark" /><input type="hidden" name="newmark" value="$newmark" />&nbsp;$lt{'chgt'} "$markchange"</label></td>
1.43      raeburn  1807:       </tr>
1.82      albertel 1808: END
                   1809:     $r->print(&Apache::loncommon::end_data_table_row().
                   1810: 	      &Apache::loncommon::end_data_table());
1.142     zhu      1811: 
1.158     bisitz   1812:     $r->print('<br />'
                   1813:              .'<input type="submit" name="sub" value="'.&mt('Save').'" />'
                   1814:              .'</form>'
                   1815:     );
1.42      raeburn  1816: }
                   1817:                                                                                                                 
                   1818: sub verify_and_change_discussion {
                   1819:     my $r = shift;
1.59      albertel 1820:     my $user     = $env{'user.name'};
                   1821:     my $domain   = $env{'user.domain'};
1.42      raeburn  1822:     my $message='';
1.59      albertel 1823:     if (defined($env{'form.discdisp'}) ) {
                   1824:         my $newdisp  = $env{'form.newdisp'};
1.43      raeburn  1825:         if ($newdisp eq 'unread') {
1.171     raeburn  1826:             $message .=&Apache::lonhtmlcommon::confirm_success(&mt('In discussions: only new posts will be displayed.')).'<br />';
1.43      raeburn  1827:             &Apache::lonnet::put('environment',{'discdisplay' => $newdisp});
1.116     raeburn  1828:             &Apache::lonnet::appenv({'environment.discdisplay' => $newdisp});
1.43      raeburn  1829:         } else {
1.171     raeburn  1830:             $message .= &Apache::lonhtmlcommon::confirm_success(&mt('In discussions: all posts will be displayed.')).'<br />';
1.43      raeburn  1831:             &Apache::lonnet::del('environment',['discdisplay']);
1.139     raeburn  1832:             &Apache::lonnet::delenv('environment.discdisplay');
1.43      raeburn  1833:         }
                   1834:     }
1.59      albertel 1835:     if (defined($env{'form.discmark'}) ) {
                   1836:         my $newmark = $env{'form.newmark'};
1.43      raeburn  1837:         if ($newmark eq 'ondisp') {
1.152     www      1838:             $message.=&Apache::lonhtmlcommon::confirm_success(&mt('In discussions: new posts will be cease to be identified as "NEW" after display.')).'<br />';
1.43      raeburn  1839:             &Apache::lonnet::put('environment',{'discmarkread' => $newmark});
1.116     raeburn  1840:             &Apache::lonnet::appenv({'environment.discmarkread' => $newmark});
1.43      raeburn  1841:         } else {
1.194     raeburn  1842:             $message.=&Apache::lonhtmlcommon::confirm_success(&mt('In discussions: posts will be identified as "NEW" until marked as not "NEW".')).'<br />';
1.43      raeburn  1843:             &Apache::lonnet::del('environment',['discmarkread']);
1.139     raeburn  1844:             &Apache::lonnet::delenv('environment.discmarkread');
1.43      raeburn  1845:         }
1.42      raeburn  1846:     }
1.158     bisitz   1847:     $message=&Apache::loncommon::confirmwrapper($message);
1.152     www      1848:     &print_main_menu($r, $message);
1.42      raeburn  1849: }
                   1850: 
1.63      raeburn  1851: ################################################################
                   1852: # Subroutines for page display on course access (Course Coordinators)
                   1853: ################################################################
                   1854: sub coursedisplaychanger {
                   1855:     my $r = shift;
1.152     www      1856:     &Apache::lonhtmlcommon::add_breadcrumb(
1.126     droeschl 1857: 	    {	href => '/adm/preferences?action=changecourseinit',
                   1858:                 text => 'Change Course Init. Pref.'});
                   1859:     $r->print(Apache::loncommon::start_page('Change Course Initialization Preference'));
                   1860:     $r->print(Apache::lonhtmlcommon::breadcrumbs('Change Course Init. Pref.'));
1.63      raeburn  1861:     my $user       = $env{'user.name'};
                   1862:     my $domain     = $env{'user.domain'};
1.66      albertel 1863:     my %userenv = &Apache::lonnet::get('environment',['course_init_display']);
1.71      raeburn  1864:     my $currvalue = 'whatsnew';
1.73      albertel 1865:     my $firstselect = '';
                   1866:     my $whatsnewselect = 'checked="checked"';
1.71      raeburn  1867:     if (exists($userenv{'course_init_display'})) {
                   1868:         if ($userenv{'course_init_display'} eq 'firstres') {
                   1869:             $currvalue = 'firstres';
1.73      albertel 1870:             $firstselect = 'checked="checked"';
                   1871: 	    $whatsnewselect = '';
1.71      raeburn  1872:         }
1.63      raeburn  1873:     }
1.134     bisitz   1874:     my %pagenames = &Apache::lonlocal::texthash(
1.71      raeburn  1875:                        firstres => 'First resource',
1.143     hauer    1876:                        whatsnew => "What's New Page",
1.71      raeburn  1877:                     );
1.134     bisitz   1878:     my $whatsnew_off=&mt('Display the [_1]first resource[_2] in the course.','<b>','</b>');
1.143     hauer    1879:     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  1880: 
1.134     bisitz   1881:     $r->print('<br /><b>'
                   1882:              .&mt('Set the default page to be displayed when you select a course role')
                   1883:              .'</b>&nbsp;'
                   1884:              .&mt('(Currently: [_1])',$pagenames{$currvalue})
                   1885:              .'<br />'
1.143     hauer    1886:              .&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   1887:              .'<br /><br />'
                   1888:     );
1.63      raeburn  1889:     $r->print(<<ENDLSCREEN);
1.88      albertel 1890: <form name="prefs" action="/adm/preferences" method="post">
1.63      raeburn  1891: <input type="hidden" name="action" value="verify_and_change_coursepage" />
1.72      albertel 1892: <br />
1.65      albertel 1893: <label><input type="radio" name="newdisp" value="firstres" $firstselect /> $whatsnew_off</label><br />
1.70      raeburn  1894: <label><input type="radio" name="newdisp" value="whatsnew" $whatsnewselect /> $whatsnew_on</label><input type="hidden" name="refpage" value="$env{'form.refpage'}" />
1.63      raeburn  1895: ENDLSCREEN
1.140     schafran 1896:     $r->print('<br /><br /><input type="submit" value="'.&mt('Save').'" />
1.63      raeburn  1897: </form>');
                   1898: }
                   1899: 
                   1900: sub verify_and_change_coursepage {
                   1901:     my $r = shift;
                   1902:     my $message='';
                   1903:     my %lt = &Apache::lonlocal::texthash(
1.70      raeburn  1904:         'defs' => 'Default now set',
1.71      raeburn  1905:         'when' => 'when you select a course role from the roles screen',
1.63      raeburn  1906:         'ywbt' => 'you will be taken to the start of the course.',
                   1907:         'apwb' => 'a page will be displayed that lists items in the course that may require action from you.',
                   1908:         'gtts' => 'Go to the start of the course',
1.146     hauer    1909:         'dasp' => "Display the What's New Page", 
1.63      raeburn  1910:     );
                   1911:     my $newdisp  = $env{'form.newdisp'};
1.70      raeburn  1912:     $message = '<b>'.$lt{'defs'}.'</b>: '.$lt{'when'}.', ';
1.63      raeburn  1913:     if ($newdisp eq 'firstres') {
1.87      albertel 1914:         $message .= $lt{'ywbt'}.'<br />';
1.63      raeburn  1915:         &Apache::lonnet::put('environment',{'course_init_display' => $newdisp});
1.116     raeburn  1916:         &Apache::lonnet::appenv({'environment.course_init_display' => $newdisp});
1.63      raeburn  1917:     } else {
1.87      albertel 1918:         $message .= $lt{'apwb'}.'<br />';
1.63      raeburn  1919:         &Apache::lonnet::del('environment',['course_init_display']);
1.139     raeburn  1920:         &Apache::lonnet::delenv('environment.course_init_display');
1.63      raeburn  1921:     }
1.70      raeburn  1922:     my $refpage = $env{'form.refpage'};
1.63      raeburn  1923:     if (($env{'request.course.fn'}) && ($env{'request.course.id'})) {
                   1924:         if ($newdisp eq 'firstres') {
                   1925:             my $cdom = $env{'course.'.$env{'request.course.id'}.'.domain'};
                   1926:             my $cnum = $env{'course.'.$env{'request.course.id'}.'.num'}; 
                   1927:             my ($furl,$ferr)=
                   1928:                 &Apache::lonuserstate::readmap($cdom.'/'.$cnum);
1.180     wenzelju 1929:             $message .= '<br /><a href="'.$furl.'">'.$lt{'gtts'}.' <i>'.&mt('now').'</i></a>';
1.63      raeburn  1930:         } else {
1.180     wenzelju 1931:             $message .= '<br /><a href="/adm/whatsnew?refpage='.
                   1932:                         $refpage.'">'.$lt{'dasp'}.'</a>';
1.63      raeburn  1933:         }
                   1934:     }
1.180     wenzelju 1935:     $message = &Apache::lonhtmlcommon::confirm_success($message);
                   1936:     $message = &Apache::loncommon::confirmwrapper($message);
                   1937:     &print_main_menu($r,$message);
1.63      raeburn  1938: }
                   1939: 
1.186     raeburn  1940: sub lockednameschanger {
                   1941:     my $r = shift;
                   1942:     &Apache::lonhtmlcommon::add_breadcrumb(
                   1943:             {   href => '/adm/preferences?action=changelockednames',
                   1944:                 text => 'Automatic name changes'});
                   1945:     $r->print(Apache::loncommon::start_page('Automatic name changes'));
                   1946:     $r->print(Apache::lonhtmlcommon::breadcrumbs('Allow/disallow name updates'));
                   1947:     my %userenv = &Apache::lonnet::get('environment',['lockedname']);
                   1948:     my $lockedname='';
                   1949:     if (&can_toggle_namelocking()) {
                   1950:         if ($userenv{'lockedname'}) {
                   1951:             $lockedname = ' checked="checked"';
                   1952:         }
                   1953:         my %updateable;
                   1954:         my %domconfig =
                   1955:             &Apache::lonnet::get_dom('configuration',['autoupdate'],$env{'user.domain'});
                   1956:         if (ref($domconfig{'autoupdate'}) eq 'HASH') {
                   1957:             if ($domconfig{'autoupdate'}{'run'}) {
                   1958:                 my @inststatuses = split(':',$env{'environment.inststatus'});
                   1959:                 unless (@inststatuses) {
                   1960:                     @inststatuses = ('default');
                   1961:                 }
                   1962:                 %updateable = &updateable_userinfo($domconfig{'autoupdate'},\@inststatuses);
                   1963:             }
                   1964:         }
                   1965:         if (keys(%updateable)) {
                   1966:             my %longnames = &Apache::lonlocal::texthash (
                   1967:                                 firstname  => 'First Name',
                   1968:                                 middlename => 'Middle Name',
                   1969:                                 lastname   => 'Last Name',
                   1970:                             );
                   1971:             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:').
                   1972:                      '<ul>';
                   1973:            foreach my $item ('firstname','middlename','lastname') {
                   1974:                if ($updateable{$item}) {
                   1975:                    $text .= '<li>'.$longnames{$item}.'</li>';
                   1976:                }
                   1977:            }
                   1978:            $text .= '</ul>'; 
                   1979:            my $locking=&mt('Disallow automatic updates to name information for your LON-CAPA account');
                   1980:            my $change=&mt('Save');
                   1981:            $r->print(<<ENDSCREEN);
                   1982: <form name="prefs" action="/adm/preferences" method="post">
                   1983: <input type="hidden" name="action" value="verify_and_change_lockednames" />
                   1984: $text<br />
                   1985: <label><input type="checkbox" value="1" name="lockednames"$lockedname />$locking</label><br />
                   1986: <input type="submit" value="$change" />
                   1987: </form>
                   1988: ENDSCREEN
                   1989:         } else {
                   1990:             my $message = &mt('Based on your institutional affiliation no name information is automatically updated for your LON-CAPA account.');
                   1991:             &print_main_menu($r,$message);
                   1992:         }
                   1993:     } else {
                   1994:         my $message = &mt('You are not permitted to set a user preference for automatic name updates for your LON-CAPA account.');
                   1995:         &print_main_menu($r,$message);
                   1996:     }
                   1997: }
                   1998: 
                   1999: sub verify_and_change_lockednames {
                   2000:     my $r = shift;
                   2001:     my $message;
                   2002:     if (&can_toggle_namelocking()) {
                   2003:         my $newlockedname = $env{'form.lockednames'};
                   2004:         $newlockedname =~ s/\D//g;
                   2005:         my $currlockedname = $env{'environment.lockedname'};
                   2006:         if ($newlockedname ne $currlockedname) {
                   2007:             if ($newlockedname) {
                   2008:                 if (&Apache::lonnet::put('environment',{lockedname => $newlockedname}) eq 'ok') {
                   2009:                     &Apache::lonnet::appenv({'environment.lockedname' => $newlockedname});
                   2010:                 }
                   2011:             } elsif (&Apache::lonnet::del('environment',['lockedname']) eq 'ok') {
                   2012:                 &Apache::lonnet::delenv('environment.lockedname');
                   2013:             }
                   2014:         }
                   2015:         my $status='';
                   2016:         if ($newlockedname) {
                   2017:             $status=&mt('disallowed');
                   2018:         } else {
                   2019:             $status=&mt('allowed');
                   2020:         }
                   2021:         $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>'));
                   2022:         $message=&Apache::loncommon::confirmwrapper($message);
                   2023:     }
                   2024:     &print_main_menu($r,$message);
                   2025: }
                   2026: 
1.126     droeschl 2027: sub print_main_menu {
                   2028:     my ($r, $message) = @_;
                   2029:     # Determine current authentication method
                   2030:     my $user = $env{'user.name'};
                   2031:     my $domain = $env{'user.domain'};
                   2032:     my $currentauth=&Apache::lonnet::queryauthenticate($user,$domain);
                   2033: 
                   2034:     # build the data structure for menu generation
                   2035: my $aboutmeurl='/adm/'.$env{'user.domain'}.'/'.$env{'user.name'}.'/aboutme';
                   2036: my $role = ($env{'user.adv'} ? 'Roles' : 'Course');
1.131     raeburn  2037: my %permissions;
                   2038: if (&Apache::lonnet::usertools_access($user,$domain,'aboutme')) {
                   2039:     $permissions{'aboutme'} = 'F';
                   2040: }
1.126     droeschl 2041: my @menu=
                   2042:     ({	categorytitle=>'Personal Data',
                   2043: 	items =>[
1.141     weissno  2044: 	    {	linktext => 'Personal Information Page',
1.126     droeschl 2045: 		url => $aboutmeurl,
1.131     raeburn  2046: 		permission => $permissions{'aboutme'},
1.126     droeschl 2047: 		#help => 'Prefs_About_Me',
                   2048: 		icon => 'system-users.png',
                   2049: 		linktitle => 'Edit information about yourself that should be displayed on your public profile.'
                   2050: 	    },
                   2051: 	    {	linktext => 'Screen Name',
                   2052: 		url => '/adm/preferences?action=changescreenname',
                   2053: 		permission => 'F',
                   2054: 		#help => 'Prefs_Screen_Name_Nickname',
                   2055: 		icon => 'preferences-desktop-font.png',
                   2056: 		linktitle => 'Change the name that is displayed in your posts.'
                   2057: 	    },
                   2058: 		]
                   2059:     },
                   2060:     {	categorytitle=>'Content Display Settings',
                   2061: 	items =>[
                   2062: 	    {	linktext => 'Language',
                   2063: 		url => '/adm/preferences?action=changelanguages',
                   2064: 		permission => 'F',
                   2065: 		#help => 'Prefs_Language',
                   2066: 		icon => 'preferences-desktop-locale.png',
1.127     droeschl 2067: 		linktitle => 'Choose the default language for this user.'
1.126     droeschl 2068: 	    },
1.128     droeschl 2069: 	    {	linktext => $role.' Page',
1.126     droeschl 2070: 		url => '/adm/preferences?action=changerolespref',
                   2071: 		permission => 'F',
                   2072: 		#help => '',
1.189     wenzelju 2073: 		icon => 'role_hotlist.png',
1.126     droeschl 2074: 		linktitle => 'Configure the roles hotlist.'
                   2075: 	    },
1.177     raeburn  2076: 	    {	linktext => 'Math display settings',
1.126     droeschl 2077: 		url => '/adm/preferences?action=changetexenginepref',
                   2078: 		permission => 'F',
                   2079: 		#help => '',
1.188     wenzelju 2080: 		icon => 'dismath.png',
1.177     raeburn  2081: 		linktitle => 'Change how math is displayed.'
1.126     droeschl 2082: 	    },
                   2083: 		]
                   2084:     },
1.185     droeschl 2085:     {	categorytitle=>'Page Display Settings',
                   2086: 	items =>[
                   2087: 	    {	linktext => 'Color Scheme',
                   2088: 		url => '/adm/preferences?action=changecolors',
                   2089: 		permission => 'F',
                   2090: 		#help => 'Change_Colors',
                   2091: 		icon => 'preferences-desktop-theme.png',
                   2092: 		linktitle => 'Change LON-CAPA default colors.'
                   2093: 	    },
1.192     raeburn  2094:             {   linktext => 'Menu Display',
                   2095:                 url => '/adm/preferences?action=changeicons',
                   2096:                 permission => 'F',
                   2097:                 #help => '',
                   2098:                 icon => 'preferences-system-windows.png',
                   2099:                 linktitle => 'Change whether the menus are displayed with icons or icons and text.'
                   2100:             }
1.185     droeschl 2101: 		]
                   2102:     },
1.178     bisitz   2103:     {	categorytitle=>'Messages &amp; Notifications',
1.128     droeschl 2104: 	items =>[
1.153     www      2105: 	    {	linktext => 'Messages &amp; Notifications',
1.128     droeschl 2106: 		url => '/adm/preferences?action=changemsgforward',
                   2107: 		permission => 'F',
                   2108: 		#help => 'Prefs_Messages',
                   2109: 		icon => 'mail-reply-all.png',
                   2110: 		linktitle => 'Change messageforwarding or notifications settings.'
                   2111: 	    },
                   2112: 	    {	linktext => 'Discussion Display',
                   2113: 		url => '/adm/preferences?action=changediscussions',
                   2114: 		permission => 'F',
                   2115: 		#help => 'Change_Discussion_Display',
1.191     riegler  2116: 		icon => 'chat.png',
1.135     schafran 2117: 		linktitle => 'Set display preferences for discussion posts for both discussion boards and individual resources in all your courses.'
1.128     droeschl 2118: 	    },
                   2119: 		]
                   2120:     },
1.126     droeschl 2121:     {	categorytitle=>'Other',
                   2122: 	items =>[
1.153     www      2123: 	    {	linktext => 'Register Response Devices (&quot;Clickers&quot;)',
1.126     droeschl 2124: 		url => '/adm/preferences?action=changeclicker',
                   2125: 		permission => 'F',
                   2126: 		#help => '',
                   2127: 		icon => 'network-workgroup.png',
                   2128: 		linktitle => 'Register your clicker.'
                   2129: 	    },
                   2130: 		]
                   2131:     },
                   2132:     );
                   2133: 
                   2134:     if ($currentauth =~ /^(unix|internal):/) {
                   2135: push(@{ $menu[0]->{items} }, {
                   2136: 	linktext => 'Password',
                   2137: 	url => '/adm/preferences?action=changepass',
                   2138: 	permission => 'F',
                   2139: 	#help => 'Change_Password',
                   2140: 	icon => 'emblem-readonly.png',
                   2141: 	linktitle => 'Change your password.',
                   2142: 	});
                   2143:     }
1.186     raeburn  2144: 
                   2145:     if (&can_toggle_namelocking()) {
                   2146:         push(@{ $menu[0]->{items} }, {
                   2147:         linktext => 'Automatic name changes',
                   2148:         url => '/adm/preferences?action=changelockednames',
                   2149:         permission => 'F',
                   2150:         #help => '',
                   2151:         icon => 'system-lock-screen.png',
                   2152:         linktitle => 'Allow/disallow propagation of name changes from institutional directory service',
                   2153:         });
                   2154:     }
                   2155: 
1.126     droeschl 2156:     my %author_roles = &Apache::lonnet::get_my_roles($user,$domain,'userroles','',['au']);
                   2157:     if (keys(%author_roles) > 0) {
                   2158: push(@{ $menu[4]->{items} }, {
                   2159: 	linktext => 'Restrict Domain Coordinator Access',
                   2160: 	url => '/adm/preferences?action=changedomcoord',
                   2161: 	permission => 'F',
                   2162: 	#help => '',
                   2163: 	icon => 'system-lock-screen.png',
                   2164: 	linktitle => 'Restrict domain coordinator access.',
                   2165: 	});
                   2166:     }
                   2167: 
                   2168:     if (&Apache::lonnet::allowed('whn',$env{'request.course.id'})
                   2169: 	|| &Apache::lonnet::allowed('whn',$env{'request.course.id'}.'/'
                   2170: 				    .$env{'request.course.sec'})) {
                   2171: push(@{ $menu[4]->{items} }, {
1.128     droeschl 2172: 	linktext => 'Course Initialization',
1.126     droeschl 2173: 	url => '/adm/preferences?action=changecourseinit',
                   2174: 	permission => 'F',
                   2175: 	#help => '',
1.189     wenzelju 2176: 	icon => 'course_ini.png',
1.126     droeschl 2177: 	linktitle => 'Set the default page to be displayed when you select a course role.',
                   2178: 	});
                   2179: 
                   2180:     }
1.174     raeburn  2181:     if (&can_toggle_debug()) {
1.126     droeschl 2182: push(@{ $menu[4]->{items} }, {
1.174     raeburn  2183: 	linktext => 'Toggle Debug Messages (Currently '.($env{'user.debug'} ? 'on)' : 'off)'),
1.126     droeschl 2184: 	url => '/adm/preferences?action=debugtoggle',
                   2185: 	permission => 'F',
                   2186: 	#help => '',
                   2187: 	icon => 'blog.png',
                   2188: 	linktitle => 'Toggle Debug Messages.',
                   2189: 	});
1.186     raeburn  2190:     }
1.126     droeschl 2191: 
1.147     schafran 2192:     $r->print(&Apache::loncommon::start_page('My Space'));
1.126     droeschl 2193:     $r->print(Apache::lonhtmlcommon::breadcrumbs('Change Preferences'));
                   2194:     $r->print($message);
                   2195:     $r->print(Apache::lonhtmlcommon::generate_menu(@menu));
                   2196:     $r->print(Apache::loncommon::end_page());
                   2197: }
1.63      raeburn  2198: 
1.4       matthew  2199: ######################################################
                   2200: #            other handler subroutines               #
                   2201: ######################################################
                   2202: 
1.3       matthew  2203: ################################################################
                   2204: #                          Main handler                        #
                   2205: ################################################################
1.126     droeschl 2206: sub handler {    
                   2207:     my $r = shift;
                   2208:     Apache::loncommon::content_type($r,'text/html');
                   2209:     # Some pages contain DES keys and should not be cached.
                   2210:     Apache::loncommon::no_cache($r);
                   2211:     $r->send_http_header;
                   2212:     return OK if $r->header_only;
                   2213:     #
                   2214:     Apache::loncommon::get_unprocessed_cgi($ENV{'QUERY_STRING'},
                   2215:                                    ['action','wysiwyg','returnurl','refpage']);
                   2216:     #
                   2217:     Apache::lonhtmlcommon::clear_breadcrumbs();
1.198     raeburn  2218:     my ($brlink,$brtxt,$brhelp);
                   2219:     if (($env{'form.action'} eq 'changerolespref') && ($env{'form.returnurl'} eq '/adm/roles')) {
                   2220:         $brlink ='/adm/roles';
                   2221:         $brtxt = 'User Roles';
                   2222:     } else {
                   2223:         $brlink ='/adm/preferences';
                   2224:         $brtxt = 'Set User Preferences';
                   2225:         $brhelp = 'Prefs_About_Me,Prefs_Language,Prefs_Screen_Name_Nickname,Change_Colors,Change_Password,Prefs_Messages,Change_Discussion_Display';   
                   2226:     }
1.126     droeschl 2227:     Apache::lonhtmlcommon::add_breadcrumb
1.198     raeburn  2228:         ({href => $brlink,
                   2229:           text => $brtxt,
                   2230:           help => $brhelp,});
1.126     droeschl 2231:     if(!exists $env{'form.action'}) {
1.150     droeschl 2232: 	    &print_main_menu($r);
1.126     droeschl 2233:     }elsif($env{'form.action'} eq 'changepass'){
                   2234:         &passwordchanger($r);
                   2235:     }elsif($env{'form.action'} eq 'verify_and_change_pass'){
                   2236:         &verify_and_change_password($r);
                   2237:     }elsif($env{'form.action'} eq 'changescreenname'){
                   2238:         &screennamechanger($r);
                   2239:     }elsif($env{'form.action'} eq 'verify_and_change_screenname'){
                   2240:         &verify_and_change_screenname($r);
                   2241:     }elsif($env{'form.action'} eq 'changemsgforward'){
                   2242:         &msgforwardchanger($r);
                   2243:     }elsif($env{'form.action'} eq 'verify_and_change_msgforward'){
                   2244:         &verify_and_change_msgforward($r);
                   2245:     }elsif($env{'form.action'} eq 'changecolors'){
                   2246:         &colorschanger($r);
                   2247:     }elsif($env{'form.action'} eq 'verify_and_change_colors'){
                   2248:         &verify_and_change_colors($r);
                   2249:     }elsif($env{'form.action'} eq 'changelanguages'){
                   2250:         &languagechanger($r);
                   2251:     }elsif($env{'form.action'} eq 'verify_and_change_languages'){
                   2252:         &verify_and_change_languages($r);
                   2253:     }elsif($env{'form.action'} eq 'changewysiwyg'){
                   2254:         &wysiwygchanger($r);
                   2255:     }elsif($env{'form.action'} eq 'set_wysiwyg'){
                   2256:         &verify_and_change_wysiwyg($r);
                   2257:     }elsif($env{'form.action'} eq 'changediscussions'){
                   2258:         &discussionchanger($r);
                   2259:     }elsif($env{'form.action'} eq 'verify_and_change_discussion'){
                   2260:         &verify_and_change_discussion($r);
                   2261:     }elsif($env{'form.action'} eq 'changerolespref'){
                   2262:         &rolesprefchanger($r);
                   2263:     }elsif($env{'form.action'} eq 'verify_and_change_rolespref'){
                   2264:         &verify_and_change_rolespref($r);
                   2265:     }elsif($env{'form.action'} eq 'changetexenginepref'){
                   2266:         &texenginechanger($r);
                   2267:     }elsif($env{'form.action'} eq 'verify_and_change_texengine'){
                   2268:         &verify_and_change_texengine($r);
1.192     raeburn  2269:     }elsif($env{'form.action'} eq 'changeicons'){
                   2270:         &iconchanger($r);
                   2271:     }elsif($env{'form.action'} eq 'verify_and_change_icons'){
                   2272:         &verify_and_change_icons($r);
1.126     droeschl 2273:     }elsif($env{'form.action'} eq 'changeclicker'){
                   2274:         &clickerchanger($r);
                   2275:     }elsif($env{'form.action'} eq 'verify_and_change_clicker'){
                   2276:         &verify_and_change_clicker($r);
                   2277:     }elsif($env{'form.action'} eq 'changedomcoord'){
                   2278:         &domcoordchanger($r);
                   2279:     }elsif($env{'form.action'} eq 'verify_and_change_domcoord'){
                   2280:         &verify_and_change_domcoord($r);
                   2281:     }elsif($env{'form.action'} eq 'lockwarning'){
                   2282:         &lockwarning($r);
                   2283:     }elsif($env{'form.action'} eq 'verify_and_change_locks'){
                   2284:         &verify_and_change_lockwarning($r);
                   2285:     }elsif($env{'form.action'} eq 'changecourseinit'){
                   2286:         &coursedisplaychanger($r);
                   2287:     }elsif($env{'form.action'} eq 'verify_and_change_coursepage'){
                   2288:         &verify_and_change_coursepage($r);
                   2289:     }elsif($env{'form.action'} eq 'debugtoggle'){
1.174     raeburn  2290:         if (&can_toggle_debug()) {
                   2291:             &toggle_debug();
                   2292:         }
1.154     www      2293: 	&print_main_menu($r);
1.186     raeburn  2294:     } elsif ($env{'form.action'} eq 'changelockednames') {
                   2295:         &lockednameschanger($r);
                   2296:     } elsif ($env{'form.action'} eq 'verify_and_change_lockednames') {
                   2297:         &verify_and_change_lockednames($r);
1.126     droeschl 2298:     }
                   2299: 
1.165     bisitz   2300:     # Properly end the HTML page of all preference pages
                   2301:     # started in each sub routine
                   2302:     # Exception: print_main_menu has its own end_page call
                   2303:     unless (!exists $env{'form.action'} ||
                   2304:             $env{'form.action'} eq 'debugtoggle') {
                   2305:         $r->print(&Apache::loncommon::end_page());
                   2306:     }
                   2307: 
1.126     droeschl 2308:     return OK;
1.35      matthew  2309: }
                   2310: 
                   2311: sub toggle_debug {
1.59      albertel 2312:     if ($env{'user.debug'}) {
1.139     raeburn  2313:         &Apache::lonnet::delenv('user.debug');
1.35      matthew  2314:     } else {
1.116     raeburn  2315:         &Apache::lonnet::appenv({'user.debug' => 1});
1.35      matthew  2316:     }
1.13      www      2317: }
1.1       www      2318: 
1.174     raeburn  2319: sub can_toggle_debug {
                   2320:     my $can_toggle = 0;
                   2321:     my $page = 'toggledebug';
                   2322:     if (&LONCAPA::lonauthcgi::can_view($page)) {
                   2323:         $can_toggle = 1;
                   2324:     } elsif (&LONCAPA::lonauthcgi::check_ipbased_access($page)) {
                   2325:         $can_toggle = 1;
                   2326:     }
                   2327:     return $can_toggle;
                   2328: }
                   2329: 
1.186     raeburn  2330: sub can_toggle_namelocking {
                   2331:     my $lockablenames;
                   2332:     my %domconfig =
                   2333:         &Apache::lonnet::get_dom('configuration',['autoupdate'],$env{'user.domain'});
                   2334:     if (ref($domconfig{'autoupdate'}) eq 'HASH') {
                   2335:         if ($domconfig{'autoupdate'}{'run'}) {
                   2336:             my @inststatuses = split(':',$env{'environment.inststatus'});
                   2337:             unless (@inststatuses) {
                   2338:                 @inststatuses = ('default');
                   2339:             }
                   2340:             my %updateable = &updateable_userinfo($domconfig{'autoupdate'},\@inststatuses);
                   2341:             if ($updateable{'lastname'} || $updateable{'firstname'} ||
                   2342:                 $updateable{'middlename'}) { 
                   2343:                 if (ref($domconfig{'autoupdate'}{'lockablenames'}) eq 'ARRAY') {
                   2344:                     unless (@inststatuses) {
                   2345:                         @inststatuses = ('default');
                   2346:                     }
                   2347:                     foreach my $status (@inststatuses) {
                   2348:                         if (grep(/^\Q$status\E$/,@{$domconfig{'autoupdate'}{'lockablenames'}})) {
                   2349:                             $lockablenames = 1;
                   2350:                             last;
                   2351:                         }
                   2352:                     }
                   2353:                 }
                   2354:             }
                   2355:         }
                   2356:     }
                   2357:     return $lockablenames;
                   2358: }
                   2359: 
                   2360: sub updateable_userinfo {
                   2361:     my ($autoupdate,$inststatuses) = @_;
                   2362:     my %updateable;
                   2363:     return %updateable unless ((ref($autoupdate) eq 'HASH') && 
                   2364:                                (ref($inststatuses) eq 'ARRAY'));
                   2365:     if (ref($autoupdate->{'fields'}) eq 'HASH') {
                   2366:         foreach my $status (@{$inststatuses}) {
                   2367:             if (ref($autoupdate->{'fields'}{$status}) eq 'ARRAY') {
                   2368:                 foreach my $field (@{$autoupdate->{'fields'}{$status}}) {
                   2369:                     $updateable{$field} = 1;
                   2370:                 }
                   2371:             }
                   2372:         }
                   2373:     }
                   2374:     return %updateable;
                   2375: }
                   2376: 
1.1       www      2377: 1;
                   2378: __END__

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