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

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

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