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

1.1       www         1: # The LearningOnline Network
                      2: # Preferences
                      3: #
1.133   ! bisitz      4: # $Id: lonpreferences.pm,v 1.132 2008/12/23 19:22:13 raeburn Exp $
1.2       albertel    5: #
                      6: # Copyright Michigan State University Board of Trustees
                      7: #
                      8: # This file is part of the LearningOnline Network with CAPA (LON-CAPA).
                      9: #
                     10: # LON-CAPA is free software; you can redistribute it and/or modify
                     11: # it under the terms of the GNU General Public License as published by
                     12: # the Free Software Foundation; either version 2 of the License, or
                     13: # (at your option) any later version.
                     14: #
                     15: # LON-CAPA is distributed in the hope that it will be useful,
                     16: # but WITHOUT ANY WARRANTY; without even the implied warranty of
                     17: # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
                     18: # GNU General Public License for more details.
                     19: #
                     20: # You should have received a copy of the GNU General Public License
                     21: # along with LON-CAPA; if not, write to the Free Software
                     22: # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
                     23: #
                     24: # /home/httpd/html/adm/gpl.txt
                     25: #
                     26: # http://www.lon-capa.org/
                     27: #
1.3       matthew    28: # This package uses the "londes.js" javascript code. 
                     29: #
                     30: # TODOs that have to be completed:
                     31: #    interface with lonnet to change the password
                     32:  
1.1       www        33: package Apache::lonpreferences;
                     34: 
                     35: use strict;
1.86      albertel   36: use LONCAPA;
1.1       www        37: use Apache::Constants qw(:common);
1.3       matthew    38: use Apache::File;
                     39: use Crypt::DES;
                     40: use DynaLoader; # for Crypt::DES version
1.4       matthew    41: use Apache::loncommon();
1.23      matthew    42: use Apache::lonhtmlcommon();
1.32      www        43: use Apache::lonlocal;
1.59      albertel   44: use Apache::lonnet;
1.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.71      raeburn  1735:     my %pagenames = (
                   1736:                        firstres => 'First resource',
                   1737:                        whatsnew => "What's new page",
                   1738:                     );
1.70      raeburn  1739:     my $whatsnew_off=&mt('Display the [_1] in the course.','<b>first resource</b>');
                   1740:     my $whatsnew_on=&mt('Display the "[_1]" page - a summary of items in the course which require attention.',"<b>What's New</b>");
1.63      raeburn  1741: 
1.71      raeburn  1742:     $r->print('<br /><b>'.&mt('Set the default page to be displayed when you select a course role').'</b>&nbsp;'.&mt('(Currently: [_1])',$pagenames{$currvalue}).'<br />'.&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]" page in the course',"<i>What's New</i>").'<br /><br />');
1.63      raeburn  1743:     $r->print(<<ENDLSCREEN);
1.88      albertel 1744: <form name="prefs" action="/adm/preferences" method="post">
1.63      raeburn  1745: <input type="hidden" name="action" value="verify_and_change_coursepage" />
1.72      albertel 1746: <br />
1.65      albertel 1747: <label><input type="radio" name="newdisp" value="firstres" $firstselect /> $whatsnew_off</label><br />
1.70      raeburn  1748: <label><input type="radio" name="newdisp" value="whatsnew" $whatsnewselect /> $whatsnew_on</label><input type="hidden" name="refpage" value="$env{'form.refpage'}" />
1.63      raeburn  1749: ENDLSCREEN
1.70      raeburn  1750:     $r->print('<br /><br /><input type="submit" value="'.&mt('Change').'" />
1.63      raeburn  1751: </form>');
                   1752: }
                   1753: 
                   1754: sub verify_and_change_coursepage {
                   1755:     my $r = shift;
                   1756:     my $message='';
                   1757:     my %lt = &Apache::lonlocal::texthash(
1.70      raeburn  1758:         'defs' => 'Default now set',
1.71      raeburn  1759:         'when' => 'when you select a course role from the roles screen',
1.63      raeburn  1760:         'ywbt' => 'you will be taken to the start of the course.',
                   1761:         'apwb' => 'a page will be displayed that lists items in the course that may require action from you.',
                   1762:         'gtts' => 'Go to the start of the course',
1.70      raeburn  1763:         'dasp' => "Display the What's New page listing course action items", 
1.63      raeburn  1764:     );
                   1765:     my $newdisp  = $env{'form.newdisp'};
1.70      raeburn  1766:     $message = '<b>'.$lt{'defs'}.'</b>: '.$lt{'when'}.', ';
1.63      raeburn  1767:     if ($newdisp eq 'firstres') {
1.87      albertel 1768:         $message .= $lt{'ywbt'}.'<br />';
1.63      raeburn  1769:         &Apache::lonnet::put('environment',{'course_init_display' => $newdisp});
1.116     raeburn  1770:         &Apache::lonnet::appenv({'environment.course_init_display' => $newdisp});
1.63      raeburn  1771:     } else {
1.87      albertel 1772:         $message .= $lt{'apwb'}.'<br />';
1.63      raeburn  1773:         &Apache::lonnet::del('environment',['course_init_display']);
                   1774:         &Apache::lonnet::delenv('environment\.course_init_display');
                   1775:     }
1.70      raeburn  1776:     my $refpage = $env{'form.refpage'};
1.63      raeburn  1777:     if (($env{'request.course.fn'}) && ($env{'request.course.id'})) {
                   1778:         if ($newdisp eq 'firstres') {
                   1779:             my $cdom = $env{'course.'.$env{'request.course.id'}.'.domain'};
                   1780:             my $cnum = $env{'course.'.$env{'request.course.id'}.'.num'}; 
                   1781:             my ($furl,$ferr)=
                   1782:                 &Apache::lonuserstate::readmap($cdom.'/'.$cnum);
                   1783:             $message .= '<br /><font size="+1"><a href="'.$furl.'">'.$lt{'gtts'}.' <i>'.&mt('now').'</i></a></font>';
                   1784:         } else {
1.70      raeburn  1785:             $message .= '<br /><font size="+1"><a href="/adm/whatsnew?refpage='.
                   1786:                         $refpage.'">'.$lt{'dasp'}.'</a></font>';
1.63      raeburn  1787:         }
                   1788:     }
1.126     droeschl 1789: #    $r->print(<<ENDVCSCREEN);
                   1790: #$message
                   1791: #<br /><br />
                   1792: #ENDVCSCREEN
                   1793:     print_main_menu($r, $message);
1.63      raeburn  1794: }
                   1795: 
1.126     droeschl 1796: sub print_main_menu {
                   1797:     my ($r, $message) = @_;
                   1798:     # Determine current authentication method
                   1799:     my $user = $env{'user.name'};
                   1800:     my $domain = $env{'user.domain'};
                   1801:     my $currentauth=&Apache::lonnet::queryauthenticate($user,$domain);
                   1802: 
                   1803:     # build the data structure for menu generation
                   1804: my $aboutmeurl='/adm/'.$env{'user.domain'}.'/'.$env{'user.name'}.'/aboutme';
                   1805: my $role = ($env{'user.adv'} ? 'Roles' : 'Course');
1.131     raeburn  1806: my %permissions;
                   1807: if (&Apache::lonnet::usertools_access($user,$domain,'aboutme')) {
                   1808:     $permissions{'aboutme'} = 'F';
                   1809: }
1.126     droeschl 1810: my @menu=
                   1811:     ({	categorytitle=>'Personal Data',
                   1812: 	items =>[
                   1813: 	    {	linktext => 'About Me',
                   1814: 		url => $aboutmeurl,
1.131     raeburn  1815: 		permission => $permissions{'aboutme'},
1.126     droeschl 1816: 		#help => 'Prefs_About_Me',
                   1817: 		icon => 'system-users.png',
                   1818: 		linktitle => 'Edit information about yourself that should be displayed on your public profile.'
                   1819: 	    },
                   1820: 	    {	linktext => 'Screen Name',
                   1821: 		url => '/adm/preferences?action=changescreenname',
                   1822: 		permission => 'F',
                   1823: 		#help => 'Prefs_Screen_Name_Nickname',
                   1824: 		icon => 'preferences-desktop-font.png',
                   1825: 		linktitle => 'Change the name that is displayed in your posts.'
                   1826: 	    },
                   1827: 		]
                   1828:     },
                   1829:     {	categorytitle=>'Page Display Settings',
                   1830: 	items =>[
                   1831: 	    {	linktext => 'Color Scheme',
                   1832: 		url => '/adm/preferences?action=changecolors',
                   1833: 		permission => 'F',
                   1834: 		#help => 'Change_Colors',
                   1835: 		icon => 'preferences-desktop-theme.png',
                   1836: 		linktitle => 'Change LON-CAPA default colors.'
                   1837: 	    },
                   1838: 	    {	linktext => 'Menu Display',
                   1839: 		url => '/adm/preferences?action=changeicons',
                   1840: 		permission => 'F',
                   1841: 		#help => '',
                   1842: 		icon => 'preferences-system-windows.png',
                   1843: 		linktitle => 'Change whether the menus are displayed with buttons, icons or icons and text.'
                   1844: 	    }
                   1845: 
                   1846: 		]
                   1847:     },
                   1848:     {	categorytitle=>'Content Display Settings',
                   1849: 	items =>[
                   1850: 	    {	linktext => 'Language',
                   1851: 		url => '/adm/preferences?action=changelanguages',
                   1852: 		permission => 'F',
                   1853: 		#help => 'Prefs_Language',
                   1854: 		icon => 'preferences-desktop-locale.png',
1.127     droeschl 1855: 		linktitle => 'Choose the default language for this user.'
1.126     droeschl 1856: 	    },
1.128     droeschl 1857: 	    {	linktext => 'WYSIWYG Editor',
1.126     droeschl 1858: 		url => '/adm/preferences?action=changewysiwyg',
                   1859: 		permission => 'F',
                   1860: 		#help => '',
                   1861: 		icon => 'edit-select-all.png',
                   1862: 		linktitle => 'Enable or disable the WYSIWYG-Editor.'
                   1863: 	    },
1.128     droeschl 1864: 	    {	linktext => $role.' Page',
1.126     droeschl 1865: 		url => '/adm/preferences?action=changerolespref',
                   1866: 		permission => 'F',
                   1867: 		#help => '',
                   1868: 		icon => 'sctr.png',
                   1869: 		linktitle => 'Configure the roles hotlist.'
                   1870: 	    },
1.127     droeschl 1871: 	    {	linktext => 'Display of Scientific Equations',
1.126     droeschl 1872: 		url => '/adm/preferences?action=changetexenginepref',
                   1873: 		permission => 'F',
                   1874: 		#help => '',
                   1875: 		icon => 'stat.png',
1.127     droeschl 1876: 		linktitle => 'Change how Scientific Equations are displayed.'
1.126     droeschl 1877: 	    },
                   1878: 		]
                   1879:     },
1.128     droeschl 1880:     {	categorytitle=>'Message Management',
                   1881: 	items =>[
                   1882: 	    {	linktext => 'Messages & Notifications',
                   1883: 		url => '/adm/preferences?action=changemsgforward',
                   1884: 		permission => 'F',
                   1885: 		#help => 'Prefs_Messages',
                   1886: 		icon => 'mail-reply-all.png',
                   1887: 		linktitle => 'Change messageforwarding or notifications settings.'
                   1888: 	    },
                   1889: 	    {	linktext => 'Discussion Display',
                   1890: 		url => '/adm/preferences?action=changediscussions',
                   1891: 		permission => 'F',
                   1892: 		#help => 'Change_Discussion_Display',
                   1893: 		icon => 'mail-message-new.png',
                   1894: 		linktitle => 'Set display preferences for discussion posts for both bulletin boards and individual resources in all your courses.'
                   1895: 	    },
                   1896: 		]
                   1897:     },
1.126     droeschl 1898:     {	categorytitle=>'Other',
                   1899: 	items =>[
                   1900: 	    {	linktext => 'Register Response Devices ("Clickers")',
                   1901: 		url => '/adm/preferences?action=changeclicker',
                   1902: 		permission => 'F',
                   1903: 		#help => '',
                   1904: 		icon => 'network-workgroup.png',
                   1905: 		linktitle => 'Register your clicker.'
                   1906: 	    },
                   1907: 		]
                   1908:     },
                   1909:     );
                   1910: 
                   1911:     if ($currentauth =~ /^(unix|internal):/) {
                   1912: push(@{ $menu[0]->{items} }, {
                   1913: 	linktext => 'Password',
                   1914: 	url => '/adm/preferences?action=changepass',
                   1915: 	permission => 'F',
                   1916: 	#help => 'Change_Password',
                   1917: 	icon => 'emblem-readonly.png',
                   1918: 	linktitle => 'Change your password.',
                   1919: 	});
                   1920:     }
                   1921:     if ($env{'environment.remote'} eq 'off') {
                   1922: push(@{ $menu[1]->{items} }, {
                   1923: 	linktext => 'Launch Remote Control',
                   1924: 	url => '/adm/remote?url=/adm/preferences?action=launch',
                   1925: 	permission => 'F',
                   1926: 	#help => '',
                   1927: 	icon => 'network-wireless.png',
                   1928: 	linktitle => 'Launch the remote control for LON-CAPA.',
                   1929: 	});
                   1930:     }else{
                   1931: push(@{ $menu[1]->{items} }, {
                   1932: 	linktext => 'Collapse Remote Control',
                   1933: 	url => '/adm/remote?url=/adm/preferences?action=collapse',
                   1934: 	permission => 'F',
                   1935: 	#help => '',
                   1936: 	icon => 'network-wireless.png',
                   1937: 	linktitle => 'Collapse the remote control for LON-CAPA.',
                   1938: 	});
                   1939:     }
                   1940:     my %author_roles = &Apache::lonnet::get_my_roles($user,$domain,'userroles','',['au']);
                   1941:     if (keys(%author_roles) > 0) {
                   1942: push(@{ $menu[4]->{items} }, {
                   1943: 	linktext => 'Restrict Domain Coordinator Access',
                   1944: 	url => '/adm/preferences?action=changedomcoord',
                   1945: 	permission => 'F',
                   1946: 	#help => '',
                   1947: 	icon => 'system-lock-screen.png',
                   1948: 	linktitle => 'Restrict domain coordinator access.',
                   1949: 	});
                   1950:     }
                   1951: 
                   1952:     if (&Apache::lonnet::allowed('whn',$env{'request.course.id'})
                   1953: 	|| &Apache::lonnet::allowed('whn',$env{'request.course.id'}.'/'
                   1954: 				    .$env{'request.course.sec'})) {
                   1955: push(@{ $menu[4]->{items} }, {
1.128     droeschl 1956: 	linktext => 'Course Initialization',
1.126     droeschl 1957: 	url => '/adm/preferences?action=changecourseinit',
                   1958: 	permission => 'F',
                   1959: 	#help => '',
                   1960: 	icon => 'edit-copy.png',
                   1961: 	linktitle => 'Set the default page to be displayed when you select a course role.',
                   1962: 	});
                   1963: 
                   1964:     }
                   1965:     if ($env{'user.name'} =~ /^(albertel|fox|foxr|kortemey|korte|raeburn)$/) {
                   1966: push(@{ $menu[4]->{items} }, {
                   1967: 	linktext => 'Toggle Debug Messages (Current:'.$env{'user.debug'}.')',
                   1968: 	url => '/adm/preferences?action=debugtoggle',
                   1969: 	permission => 'F',
                   1970: 	#help => '',
                   1971: 	icon => 'blog.png',
                   1972: 	linktitle => 'Toggle Debug Messages.',
                   1973: 	});
                   1974:     }   
                   1975: 
                   1976:     $r->print(&Apache::loncommon::start_page('Change Preferences'));
                   1977:     $r->print(Apache::lonhtmlcommon::breadcrumbs('Change Preferences'));
                   1978:     $r->print($message);
                   1979:     $r->print(Apache::lonhtmlcommon::generate_menu(@menu));
                   1980:     $r->print(Apache::loncommon::end_page());
                   1981: }
1.63      raeburn  1982: 
1.4       matthew  1983: ######################################################
                   1984: #            other handler subroutines               #
                   1985: ######################################################
                   1986: 
1.3       matthew  1987: ################################################################
                   1988: #                          Main handler                        #
                   1989: ################################################################
1.126     droeschl 1990: sub handler {    
                   1991:     my $r = shift;
                   1992:     Apache::loncommon::content_type($r,'text/html');
                   1993:     # Some pages contain DES keys and should not be cached.
                   1994:     Apache::loncommon::no_cache($r);
                   1995:     $r->send_http_header;
                   1996:     return OK if $r->header_only;
                   1997:     #
                   1998:     Apache::loncommon::get_unprocessed_cgi($ENV{'QUERY_STRING'},
                   1999:                                    ['action','wysiwyg','returnurl','refpage']);
                   2000:     #
                   2001:     Apache::lonhtmlcommon::clear_breadcrumbs();
                   2002:     Apache::lonhtmlcommon::add_breadcrumb
                   2003:         ({href => '/adm/preferences',
                   2004:           text => 'Set User Preferences'});
                   2005:     if(!exists $env{'form.action'}) {
                   2006: 	&print_main_menu($r);
                   2007:     }elsif($env{'form.action'} eq 'changepass'){
                   2008:         &passwordchanger($r);
                   2009:     }elsif($env{'form.action'} eq 'verify_and_change_pass'){
                   2010:         &verify_and_change_password($r);
                   2011:     }elsif($env{'form.action'} eq 'changescreenname'){
                   2012:         &screennamechanger($r);
                   2013:     }elsif($env{'form.action'} eq 'verify_and_change_screenname'){
                   2014:         &verify_and_change_screenname($r);
                   2015:     }elsif($env{'form.action'} eq 'changemsgforward'){
                   2016:         &msgforwardchanger($r);
                   2017:     }elsif($env{'form.action'} eq 'verify_and_change_msgforward'){
                   2018:         &verify_and_change_msgforward($r);
                   2019:     }elsif($env{'form.action'} eq 'changecolors'){
                   2020:         &colorschanger($r);
                   2021:     }elsif($env{'form.action'} eq 'verify_and_change_colors'){
                   2022:         &verify_and_change_colors($r);
                   2023:     }elsif($env{'form.action'} eq 'changelanguages'){
                   2024:         &languagechanger($r);
                   2025:     }elsif($env{'form.action'} eq 'verify_and_change_languages'){
                   2026:         &verify_and_change_languages($r);
                   2027:     }elsif($env{'form.action'} eq 'changewysiwyg'){
                   2028:         &wysiwygchanger($r);
                   2029:     }elsif($env{'form.action'} eq 'set_wysiwyg'){
                   2030:         &verify_and_change_wysiwyg($r);
                   2031:     }elsif($env{'form.action'} eq 'changediscussions'){
                   2032:         &discussionchanger($r);
                   2033:     }elsif($env{'form.action'} eq 'verify_and_change_discussion'){
                   2034:         &verify_and_change_discussion($r);
                   2035:     }elsif($env{'form.action'} eq 'changerolespref'){
                   2036:         &rolesprefchanger($r);
                   2037:     }elsif($env{'form.action'} eq 'verify_and_change_rolespref'){
                   2038:         &verify_and_change_rolespref($r);
                   2039:     }elsif($env{'form.action'} eq 'changetexenginepref'){
                   2040:         &texenginechanger($r);
                   2041:     }elsif($env{'form.action'} eq 'verify_and_change_texengine'){
                   2042:         &verify_and_change_texengine($r);
                   2043:     }elsif($env{'form.action'} eq 'changeicons'){
                   2044:         &iconchanger($r);
                   2045:     }elsif($env{'form.action'} eq 'verify_and_change_icons'){
                   2046:         &verify_and_change_icons($r);
                   2047:     }elsif($env{'form.action'} eq 'changeclicker'){
                   2048:         &clickerchanger($r);
                   2049:     }elsif($env{'form.action'} eq 'verify_and_change_clicker'){
                   2050:         &verify_and_change_clicker($r);
                   2051:     }elsif($env{'form.action'} eq 'changedomcoord'){
                   2052:         &domcoordchanger($r);
                   2053:     }elsif($env{'form.action'} eq 'verify_and_change_domcoord'){
                   2054:         &verify_and_change_domcoord($r);
                   2055:     }elsif($env{'form.action'} eq 'lockwarning'){
                   2056:         &lockwarning($r);
                   2057:     }elsif($env{'form.action'} eq 'verify_and_change_locks'){
                   2058:         &verify_and_change_lockwarning($r);
                   2059:     }elsif($env{'form.action'} eq 'changecourseinit'){
                   2060:         &coursedisplaychanger($r);
                   2061:     }elsif($env{'form.action'} eq 'verify_and_change_coursepage'){
                   2062:         &verify_and_change_coursepage($r);
                   2063:     }elsif($env{'form.action'} eq 'debugtoggle'){
                   2064:         toggle_debug();
                   2065: 	print_main_menu($r);
                   2066:     }
                   2067: 
                   2068:     return OK;
                   2069: 
                   2070: 
                   2071: }
                   2072: #remove when done
                   2073: #old handler routine
                   2074: sub handler2 {
1.1       www      2075:     my $r = shift;
1.59      albertel 2076:     my $user = $env{'user.name'};
                   2077:     my $domain = $env{'user.domain'};
1.31      www      2078:     &Apache::loncommon::content_type($r,'text/html');
1.4       matthew  2079:     # Some pages contain DES keys and should not be cached.
                   2080:     &Apache::loncommon::no_cache($r);
1.1       www      2081:     $r->send_http_header;
                   2082:     return OK if $r->header_only;
1.9       matthew  2083:     #
1.35      matthew  2084:     &Apache::loncommon::get_unprocessed_cgi($ENV{'QUERY_STRING'},
1.70      raeburn  2085:                                    ['action','wysiwyg','returnurl','refpage']);
1.35      matthew  2086:     #
                   2087:     &Apache::lonhtmlcommon::clear_breadcrumbs();
                   2088:     &Apache::lonhtmlcommon::add_breadcrumb
                   2089:         ({href => '/adm/preferences',
                   2090:           text => 'Set User Preferences'});
                   2091: 
                   2092:     my @Options;
                   2093:     # Determine current authentication method
                   2094:     my $currentauth=&Apache::lonnet::queryauthenticate($user,$domain);
                   2095:     if ($currentauth =~ /^(unix|internal):/) {
                   2096:         push (@Options,({ action   => 'changepass',
1.40      www      2097:                           linktext => 'Change Password',
1.35      matthew  2098:                           href     => '/adm/preferences',
                   2099:                           help     => 'Change_Password',
                   2100:                           subroutine => \&passwordchanger,
                   2101:                           breadcrumb => 
                   2102:                               { href => '/adm/preferences?action=changepass',
                   2103:                                 text => 'Change Password'},
                   2104:                           },
                   2105:                         { action => 'verify_and_change_pass',
                   2106:                           subroutine => \&verify_and_change_password,
                   2107:                           breadcrumb => 
                   2108:                               { href =>'/adm/preferences?action=changepass',
                   2109:                                 text => 'Change Password'},
1.75      albertel 2110:                           printmenu => 'not_on_error',
1.35      matthew  2111:                           }));
                   2112:     }
                   2113:     push (@Options,({ action   => 'changescreenname',
                   2114:                       linktext => 'Change Screen Name',
                   2115:                       href     => '/adm/preferences',
                   2116:                       help     => 'Prefs_Screen_Name_Nickname',
                   2117:                       subroutine => \&screennamechanger,
                   2118:                       breadcrumb => 
                   2119:                           { href => '/adm/preferences?action=changescreenname',
                   2120:                             text => 'Change Screen Name'},
                   2121:                       },
                   2122:                     { action   => 'verify_and_change_screenname',
                   2123:                       subroutine => \&verify_and_change_screenname,
                   2124:                       breadcrumb => 
                   2125:                           { href => '/adm/preferences?action=changescreenname',
                   2126:                             text => 'Change Screen Name'},
                   2127:                       printmenu => 'yes',
                   2128:                       }));
                   2129: 
                   2130:     push (@Options,({ action   => 'changemsgforward',
1.129     schafran 2131:                       linktext => 'Change Message Forwarding and Notification E-mail Addresses',
1.35      matthew  2132:                       href     => '/adm/preferences',
1.113     raeburn  2133:                       help     => 'Prefs_Messages',
1.35      matthew  2134:                       breadcrumb => 
                   2135:                           { href => '/adm/preferences?action=changemsgforward',
1.113     raeburn  2136:                             text => 'Change Message Forwarding/Notification'},
1.35      matthew  2137:                       subroutine => \&msgforwardchanger,
                   2138:                       },
                   2139:                     { action => 'verify_and_change_msgforward',
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.126     droeschl 2144:                       printmenu => 'yes',
1.35      matthew  2145:                       subroutine => \&verify_and_change_msgforward }));
                   2146:     my $aboutmeaction=
1.59      albertel 2147:         '/adm/'.$env{'user.domain'}.'/'.$env{'user.name'}.'/aboutme';
1.35      matthew  2148:     push (@Options,{ action => 'none', 
                   2149:                      linktext =>
1.41      www      2150:                          q{Edit the 'About Me' Personal Information Screen},
1.45      www      2151: 		     help => 'Prefs_About_Me',
1.35      matthew  2152:                      href => $aboutmeaction});
                   2153:     push (@Options,({ action => 'changecolors',
                   2154:                       linktext => 'Change Color Scheme',
                   2155:                       href => '/adm/preferences',
                   2156:                       help => 'Change_Colors',
                   2157:                       breadcrumb => 
                   2158:                           { href => '/adm/preferences?action=changecolors',
                   2159:                             text => 'Change Colors'},
                   2160:                       subroutine => \&colorschanger,
                   2161:                   },
                   2162:                     { action => 'verify_and_change_colors',
                   2163:                       breadcrumb => 
                   2164:                           { href => '/adm/preferences?action=changecolors',
                   2165:                             text => 'Change Colors'},
                   2166:                       printmenu => 'yes',
                   2167:                       subroutine => \&verify_and_change_colors,
                   2168:                       }));
                   2169:     push (@Options,({ action => 'changelanguages',
1.39      www      2170:                       linktext => 'Change Language Preferences',
1.35      matthew  2171:                       href => '/adm/preferences',
1.45      www      2172: 		      help => 'Prefs_Language',
1.35      matthew  2173:                       breadcrumb=>
                   2174:                           { href => '/adm/preferences?action=changelanguages',
                   2175:                             text => 'Change Language'},
                   2176:                       subroutine =>  \&languagechanger,
                   2177:                   },
                   2178:                     { action => 'verify_and_change_languages',
                   2179:                       breadcrumb=>
                   2180:                           {href => '/adm/preferences?action=changelanguages',
                   2181:                            text => 'Change Language'},
                   2182:                       printmenu => 'yes',
                   2183:                       subroutine=>\&verify_and_change_languages, }
                   2184:                     ));
1.44      www      2185:     push (@Options,({ action => 'changewysiwyg',
                   2186:                       linktext => 'Change WYSIWYG Editor Preferences',
                   2187:                       href => '/adm/preferences',
                   2188:                       breadcrumb => 
                   2189:                             { href => '/adm/preferences?action=changewysiwyg',
                   2190:                               text => 'Change WYSIWYG Preferences'},
                   2191:                       subroutine => \&wysiwygchanger,
                   2192:                   },
                   2193:                     { action => 'set_wysiwyg',
                   2194:                       breadcrumb =>
                   2195:                           { href => '/adm/preferences?action=changewysiwyg',
                   2196:                             text => 'Change WYSIWYG Preferences'},
                   2197:                       printmenu => 'yes',
                   2198:                       subroutine => \&verify_and_change_wysiwyg, }
                   2199:                     ));
1.42      raeburn  2200:     push (@Options,({ action => 'changediscussions',
                   2201:                       linktext => 'Change Discussion Display Preferences',
                   2202:                       href => '/adm/preferences',
1.46      raeburn  2203:                       help => 'Change_Discussion_Display',
1.42      raeburn  2204:                       breadcrumb => 
                   2205:                             { href => '/adm/preferences?action=changediscussions',
1.43      raeburn  2206:                               text => 'Change Discussion Preferences'},
1.42      raeburn  2207:                       subroutine => \&discussionchanger,
                   2208:                   },
                   2209:                     { action => 'verify_and_change_discussion',
                   2210:                       breadcrumb =>
                   2211:                           { href => '/adm/preferences?action=changediscussions',
1.43      raeburn  2212:                             text => 'Change Discussion Preferences'},
1.42      raeburn  2213:                       printmenu => 'yes',
                   2214:                       subroutine => \&verify_and_change_discussion, }
                   2215:                     ));
1.96      albertel 2216: 
                   2217:     my $role = ($env{'user.adv'} ? 'Roles' : 'Course');
1.50      albertel 2218:     push (@Options,({ action   => 'changerolespref',
1.96      albertel 2219:                       linktext => 'Change '.$role.' Page Preferences',
1.50      albertel 2220:                       href     => '/adm/preferences',
                   2221:                       subroutine => \&rolesprefchanger,
                   2222:                       breadcrumb =>
                   2223:                           { href => '/adm/preferences?action=changerolespref',
1.96      albertel 2224:                             text => 'Change '.$role.' Page Pref'},
1.50      albertel 2225:                       },
                   2226:                     { action   => 'verify_and_change_rolespref',
                   2227:                       subroutine => \&verify_and_change_rolespref,
                   2228:                       breadcrumb =>
                   2229:                           { href => '/adm/preferences?action=changerolespref',
1.96      albertel 2230:                             text => 'Change '.$role.' Page Preferences'},
1.50      albertel 2231:                       printmenu => 'yes',
                   2232:                       }));
                   2233: 
1.54      albertel 2234:     push (@Options,({ action   => 'changetexenginepref',
                   2235:                       linktext => 'Change How Math Equations Are Displayed',
                   2236:                       href     => '/adm/preferences',
                   2237:                       subroutine => \&texenginechanger,
                   2238:                       breadcrumb =>
                   2239:                           { href => '/adm/preferences?action=changetexenginepref',
                   2240:                             text => 'Change Math Pref'},
                   2241:                       },
                   2242:                     { action   => 'verify_and_change_texengine',
                   2243:                       subroutine => \&verify_and_change_texengine,
                   2244:                       breadcrumb =>
                   2245:                           { href => '/adm/preferences?action=changetexenginepref',
                   2246:                             text => 'Change Math Preferences'},
                   2247:                       printmenu => 'yes',
                   2248:                       }));
1.85      albertel 2249: 
                   2250:     if ($env{'environment.remote'} eq 'off') {
                   2251: 	push (@Options,({ action => 'launch',
                   2252: 			  linktext => 'Launch Remote Control',
                   2253: 			  href => '/adm/remote?url=/adm/preferences',
                   2254: 		      }));
                   2255:     } else {
                   2256: 	push (@Options,({ action => 'collapse',
                   2257: 			  linktext => 'Collapse Remote Control',
                   2258: 			  href => '/adm/remote?url=/adm/preferences',
                   2259: 		      }));
                   2260:     }
                   2261: 
1.98      www      2262:     push (@Options,({ action   => 'changeicons',
1.100     www      2263:                       linktext => 'Change How Menus are Displayed',
1.98      www      2264:                       href     => '/adm/preferences',
                   2265:                       subroutine => \&iconchanger,
                   2266:                       breadcrumb =>
                   2267:                           { href => '/adm/preferences?action=changeicons',
                   2268:                             text => 'Change Main Menu'},
                   2269:                       },
                   2270:                     { action   => 'verify_and_change_icons',
                   2271:                       subroutine => \&verify_and_change_icons,
                   2272:                       breadcrumb =>
                   2273:                           { href => '/adm/preferences?action=changeicons',
                   2274:                             text => 'Change Main Menu'},
                   2275:                       printmenu => 'yes',
                   2276:                       }));
                   2277: 
1.106     www      2278:     push (@Options,({ action   => 'changeclicker',
                   2279:                       linktext => 'Register Response Devices ("Clickers")',
                   2280:                       href     => '/adm/preferences',
                   2281:                       subroutine => \&clickerchanger,
                   2282:                       breadcrumb =>
1.118     www      2283:                           { href => '/adm/preferences?action=changeclicker',
1.106     www      2284:                             text => 'Register Clicker'},
                   2285:                       },
                   2286:                     { action   => 'verify_and_change_clicker',
                   2287:                       subroutine => \&verify_and_change_clicker,
                   2288:                       breadcrumb =>
                   2289:                           { href => '/adm/preferences?action=changeclicker',
                   2290:                             text => 'Register Clicker'},
                   2291:                       printmenu => 'yes',
                   2292:                       }));
1.125     raeburn  2293:     my %author_roles = &Apache::lonnet::get_my_roles($user,$domain,'userroles','',['au']);
                   2294:     if (keys(%author_roles) > 0) {
1.119     www      2295:       push (@Options,({ action   => 'changedomcoord',
                   2296:                         linktext => 'Restrict Domain Coordinator Access',
                   2297:                         href     => '/adm/preferences',
                   2298:                         subroutine => \&domcoordchanger,
                   2299:                         breadcrumb =>
                   2300:                             { href => '/adm/preferences?action=changedomcoord',
                   2301:                               text => 'Restrict Domain Coordinator Access'},
                   2302:                       },
                   2303:                       { action   => 'verify_and_change_domcoord',
                   2304:                         subroutine => \&verify_and_change_domcoord,
                   2305:                         breadcrumb =>
                   2306:                             { href => '/adm/preferences?action=changedomcoord',
                   2307:                               text => 'Restrict Domain Coordinator Access'},
                   2308:                         printmenu => 'yes',
                   2309:                       }));
                   2310:     }
1.105     www      2311: 
1.118     www      2312:     push (@Options,({ action   => 'lockwarning',
                   2313:                       subroutine => \&lockwarning,
                   2314:                       breadcrumb =>
                   2315:                           { href => '/adm/preferences?action=lockwarning',
                   2316:                             text => 'Lock Warnings'},
                   2317:                       },
                   2318:                     { action   => 'verify_and_change_locks',
                   2319:                       subroutine => \&verify_and_change_lockwarning,
                   2320:                       breadcrumb =>
                   2321:                           { href => '/adm/preferences?action=lockwarning',
                   2322:                             text => 'Lockwarnings'},
                   2323:                       printmenu => 'yes',
                   2324:                       }));
                   2325: 
1.105     www      2326: 
1.74      albertel 2327:     if (&Apache::lonnet::allowed('whn',$env{'request.course.id'})
                   2328: 	|| &Apache::lonnet::allowed('whn',$env{'request.course.id'}.'/'
                   2329: 				    .$env{'request.course.sec'})) {
1.63      raeburn  2330:         push (@Options,({ action => 'changecourseinit',
                   2331:                           linktext => 'Change Course Initialization Preference',
                   2332:                           href => '/adm/preferences',
                   2333:                           subroutine => \&coursedisplaychanger,
                   2334:                           breadcrumb =>
                   2335:                               { href => '/adm/preferences?action=changecourseinit',
                   2336:                                 text => 'Change Course Init. Pref.'},
                   2337:                           },
                   2338:                         { action => 'verify_and_change_coursepage',
                   2339:                           breadcrumb =>
                   2340:                           { href => '/adm/preferences?action=changecourseinit',                               text => 'Change Course Initialization Preference'},
                   2341:                         printmenu => 'yes',
                   2342:                         subroutine => \&verify_and_change_coursepage,
                   2343:                        }));
                   2344:     }
1.50      albertel 2345: 
1.119     www      2346:     if ($env{'user.name'} =~ /^(albertel|fox|foxr|kortemey|korte|raeburn)$/) {
1.35      matthew  2347:         push (@Options,({ action => 'debugtoggle',
                   2348:                           printmenu => 'yes',
                   2349:                           subroutine => \&toggle_debug,
                   2350:                           }));
                   2351:     }
1.76      albertel 2352: 
                   2353:     $r->print(&Apache::loncommon::start_page('Change Preferences'));
                   2354: 
1.35      matthew  2355:     my $call = undef;
1.48      albertel 2356:     my $help = undef;
1.35      matthew  2357:     my $printmenu = 'yes';
                   2358:     foreach my $option (@Options) {
1.59      albertel 2359:         if ($option->{'action'} eq $env{'form.action'}) {
1.35      matthew  2360:             $call = $option->{'subroutine'};
                   2361:             $printmenu = $option->{'printmenu'};
                   2362:             if (exists($option->{'breadcrumb'})) {
                   2363:                 &Apache::lonhtmlcommon::add_breadcrumb
                   2364:                     ($option->{'breadcrumb'});
                   2365:             }
1.48      albertel 2366: 	    $help=$option->{'help'};
1.35      matthew  2367:         }
                   2368:     }
1.81      albertel 2369:     $r->print(&Apache::lonhtmlcommon::breadcrumbs('Change Preferences',$help));
1.75      albertel 2370:     my $error;
1.35      matthew  2371:     if (defined($call)) {
1.75      albertel 2372:         $error = $call->($r);
1.35      matthew  2373:     }
1.75      albertel 2374:     if ( ( ($printmenu eq 'yes')
                   2375: 	   || ($printmenu eq 'not_on_error' && !$error) )
                   2376: 	 && (!$env{'form.returnurl'})) {
1.35      matthew  2377:         my $optionlist = '<table cellpadding="5">';
1.59      albertel 2378:         if ($env{'user.name'} =~ 
1.62      raeburn  2379:                          /^(albertel|kortemey|fox|foxr|korte|hallmat3|turtle|raeburn)$/
1.35      matthew  2380:             ) {
                   2381:             push (@Options,({ action => 'debugtoggle',
                   2382:                               linktext => 'Toggle Debug Messages',
                   2383:                               text => 'Current Debug status is -'.
1.59      albertel 2384:                                   $env{'user.debug'}.'-.',
1.35      matthew  2385:                               href => '/adm/preferences',
                   2386:                               printmenu => 'yes',
                   2387:                               subroutine => \&toggle_debug,
                   2388:                               }));
                   2389:         }
                   2390:         foreach my $option(@Options) {
                   2391:             my $optiontext = '';
                   2392:             if (exists($option->{'href'})) {
1.85      albertel 2393: 		$option->{'href_args'}{'action'}=$option->{'action'};
                   2394: 		$optiontext .= 
                   2395:                     '<a href="'.&add_get_param($option->{'href'},
                   2396: 					       $option->{'href_args'}).'">'.
1.47      albertel 2397:                     &mt($option->{'linktext'}).'</a>';
1.35      matthew  2398:             }
                   2399:             if (exists($option->{'text'})) {
1.47      albertel 2400:                 $optiontext .= ' '.&mt($option->{'text'});
1.35      matthew  2401:             }
                   2402:             if ($optiontext ne '') {
                   2403:                 $optiontext = '<font size="+1">'.$optiontext.'</font>'; 
                   2404:                 my $helplink = '&nbsp;';
                   2405:                 if (exists($option->{'help'})) {
                   2406:                     $helplink = &Apache::loncommon::help_open_topic
                   2407:                                                     ($option->{'help'});
                   2408:                 }
                   2409:                 $optionlist .= '<tr>'.
                   2410:                     '<td>'.$helplink.'</td>'.
                   2411:                     '<td>'.$optiontext.'</td>'.
                   2412:                     '</tr>';
                   2413:             }
1.13      www      2414:         }
1.35      matthew  2415:         $optionlist .= '</table>';
                   2416:         $r->print($optionlist);
1.59      albertel 2417:     } elsif ($env{'form.returnurl'}) {
                   2418: 	$r->print('<br /><a href="'.$env{'form.returnurl'}.'"><font size="+1">'.
1.44      www      2419: 		  &mt('Return').'</font></a>');
1.3       matthew  2420:     }
1.76      albertel 2421:     $r->print(&Apache::loncommon::end_page());
1.1       www      2422:     return OK;
1.35      matthew  2423: }
                   2424: 
                   2425: sub toggle_debug {
1.59      albertel 2426:     if ($env{'user.debug'}) {
1.35      matthew  2427:         &Apache::lonnet::delenv('user\.debug');
                   2428:     } else {
1.116     raeburn  2429:         &Apache::lonnet::appenv({'user.debug' => 1});
1.35      matthew  2430:     }
1.13      www      2431: }
1.1       www      2432: 
                   2433: 1;
                   2434: __END__

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