File:  [LON-CAPA] / loncom / interface / lonpreferences.pm
Revision 1.196.4.23: download - view: text, annotated - select for diffs
Mon Sep 19 03:21:20 2016 UTC (7 years, 7 months ago) by raeburn
Branches: version_2_11_X
CVS tags: version_2_11_2_uiuc, version_2_11_2_msu, version_2_11_2_educog, version_2_11_2
Diff to branchpoint 1.196: preferred, unified
- For 2.11
  - Backport 1.224

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

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