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

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

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