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

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

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