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

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

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