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

1.1       www         1: # The LearningOnline Network
                      2: # Preferences
                      3: #
1.149   ! bisitz      4: # $Id: lonpreferences.pm,v 1.148 2009/03/16 18:20:26 bisitz Exp $
1.2       albertel    5: #
                      6: # Copyright Michigan State University Board of Trustees
                      7: #
                      8: # This file is part of the LearningOnline Network with CAPA (LON-CAPA).
                      9: #
                     10: # LON-CAPA is free software; you can redistribute it and/or modify
                     11: # it under the terms of the GNU General Public License as published by
                     12: # the Free Software Foundation; either version 2 of the License, or
                     13: # (at your option) any later version.
                     14: #
                     15: # LON-CAPA is distributed in the hope that it will be useful,
                     16: # but WITHOUT ANY WARRANTY; without even the implied warranty of
                     17: # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
                     18: # GNU General Public License for more details.
                     19: #
                     20: # You should have received a copy of the GNU General Public License
                     21: # along with LON-CAPA; if not, write to the Free Software
                     22: # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
                     23: #
                     24: # /home/httpd/html/adm/gpl.txt
                     25: #
                     26: # http://www.lon-capa.org/
                     27: #
1.3       matthew    28: # This package uses the "londes.js" javascript code. 
                     29: #
                     30: # TODOs that have to be completed:
                     31: #    interface with lonnet to change the password
                     32:  
1.1       www        33: package Apache::lonpreferences;
                     34: 
                     35: use strict;
1.86      albertel   36: use LONCAPA;
1.1       www        37: use Apache::Constants qw(:common);
1.3       matthew    38: use Apache::File;
                     39: use Crypt::DES;
                     40: use DynaLoader; # for Crypt::DES version
1.4       matthew    41: use Apache::loncommon();
1.23      matthew    42: use Apache::lonhtmlcommon();
1.32      www        43: use Apache::lonlocal;
1.59      albertel   44: use Apache::lonnet;
1.95      albertel   45: use LONCAPA();
1.3       matthew    46: 
                     47: #
                     48: # Write lonnet::passwd to do the call below.
                     49: # Use:
                     50: #   my $answer=reply("encrypt:passwd:$udom:$uname:$upass",$tryserver);
                     51: #
                     52: ##################################################
                     53: #          password associated functions         #
                     54: ##################################################
                     55: sub des_keys {
1.4       matthew    56:     # Make a new key for DES encryption.
1.36      www        57:     # Each key has two parts which are returned separately.
1.4       matthew    58:     # Please note:  Each key must be passed through the &hex function
                     59:     # before it is output to the web browser.  The hex versions cannot
                     60:     # be used to decrypt.
1.3       matthew    61:     my @hexstr=('0','1','2','3','4','5','6','7',
                     62:                 '8','9','a','b','c','d','e','f');
                     63:     my $lkey='';
                     64:     for (0..7) {
                     65:         $lkey.=$hexstr[rand(15)];
                     66:     }
                     67:     my $ukey='';
                     68:     for (0..7) {
                     69:         $ukey.=$hexstr[rand(15)];
                     70:     }
                     71:     return ($lkey,$ukey);
                     72: }
                     73: 
                     74: sub des_decrypt {
                     75:     my ($key,$cyphertext) = @_;
                     76:     my $keybin=pack("H16",$key);
                     77:     my $cypher;
                     78:     if ($Crypt::DES::VERSION>=2.03) {
                     79:         $cypher=new Crypt::DES $keybin;
                     80:     } else {
                     81:         $cypher=new DES $keybin;
                     82:     }
                     83:     my $plaintext=
                     84: 	$cypher->decrypt(unpack("a8",pack("H16",substr($cyphertext,0,16))));
                     85:     $plaintext.=
                     86: 	$cypher->decrypt(unpack("a8",pack("H16",substr($cyphertext,16,16))));
1.4       matthew    87:     $plaintext=substr($plaintext,1,ord(substr($plaintext,0,1)) );
1.3       matthew    88:     return $plaintext;
                     89: }
                     90: 
1.4       matthew    91: ################################################################
                     92: #                       Handler subroutines                    #
                     93: ################################################################
1.9       matthew    94: 
                     95: ################################################################
1.28      www        96: #         Language Change Subroutines                          #
                     97: ################################################################
1.44      www        98: 
                     99: sub wysiwygchanger {
                    100:     my $r = shift;
1.126     droeschl  101:     Apache::lonhtmlcommon::add_breadcrumb(
                    102: 	    {	href => '/adm/preferences?action=changewysiwyg',
                    103:                 text => 'Change WYSIWYG Preferences'});
1.147     schafran  104:     $r->print(Apache::loncommon::start_page('Content Display Settings'));
1.126     droeschl  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.147     schafran  152:     $r->print(Apache::loncommon::start_page('Content Display Settings'));
1.126     droeschl  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']);
1.139     raeburn   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'});
1.147     schafran  211:     $r->print(Apache::loncommon::start_page('Content Display Settings'));
1.126     droeschl  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.148     bisitz    254: <script type="text/javascript" language="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.148     bisitz    284: 	$r->print('<script type="text/javascript" language="JavaScript">jsMath.Process()</script>');
1.55      albertel  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']);
1.139     raeburn   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'});
1.147     schafran  335:     $r->print(Apache::loncommon::start_page('Content Display Settings'));
1.126     droeschl  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']);
1.139     raeburn   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'});
1.147     schafran  522:     $r->print(Apache::loncommon::start_page('Personal Data'));
1.126     droeschl  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.139     raeburn   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']);
1.139     raeburn   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'});
1.147     schafran  590:     $r->print(Apache::loncommon::start_page('Page Display Settings'));
1.126     droeschl  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'});
1.147     schafran  644:     $r->print(Apache::loncommon::start_page('Other'));
1.126     droeschl  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'});
1.147     schafran  792:     $r->print(Apache::loncommon::start_page('Message Management'));
1.126     droeschl  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|
1.148     bisitz    801: <script type="text/javascript" language="JavaScript">
1.102     raeburn   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']);
1.139     raeburn  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']);
1.139     raeburn  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']);
1.139     raeburn  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']);
1.139     raeburn  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']);
1.139     raeburn  1074:         &Apache::lonnet::delenv('environment.notifywithhtml');
1.102     raeburn  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'});
1.147     schafran 1092:     $r->print(Apache::loncommon::start_page('Page Display Settings'));
1.126     droeschl 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.138     schafran 1119:     my $save = &mt('Save');
                   1120:     my $rstall = &mt('Reset All');
                   1121:     my $resetdefault = &mt('Reset All Colors to Default');
1.19      www      1122:     $r->print(<<ENDCOL);
1.148     bisitz   1123: <script type="text/javascript" language="JavaScript">
1.19      www      1124: 
                   1125:     function pclose() {
                   1126:         parmwin=window.open("/adm/rat/empty.html","LONCAPAparms",
                   1127:                  "height=350,width=350,scrollbars=no,menubar=no");
                   1128:         parmwin.close();
                   1129:     }
                   1130: 
1.23      matthew  1131:     $pjump_def
1.19      www      1132: 
                   1133:     function psub() {
                   1134:         pclose();
                   1135:         if (document.parmform.pres_marker.value!='') {
1.21      www      1136:             if (document.parmform.pres_type.value!='') {
1.77      albertel 1137:                 eval('document.prefs.'+
1.21      www      1138:                      document.parmform.pres_marker.value+
1.19      www      1139: 		     '.value=document.parmform.pres_value.value;');
1.21      www      1140: 	    }
1.19      www      1141:         } else {
                   1142:             document.parmform.pres_value.value='';
                   1143:             document.parmform.pres_marker.value='';
                   1144:         }
                   1145:     }
                   1146: 
                   1147: 
                   1148: </script>
1.21      www      1149: <form name="parmform">
                   1150: <input type="hidden" name="pres_marker" />
                   1151: <input type="hidden" name="pres_type" />
                   1152: <input type="hidden" name="pres_value" />
                   1153: </form>
1.88      albertel 1154: <form name="prefs" action="/adm/preferences" method="post">
1.19      www      1155: <input type="hidden" name="action" value="verify_and_change_colors" />
1.82      albertel 1156: $start_data_table
1.19      www      1157: $chtable
1.82      albertel 1158: $end_data_table
1.19      www      1159: </table>
1.138     schafran 1160: <input type="submit" value="$save" />
                   1161: <input type="submit" name="resetall" value="$rstall" title="$resetdefault" />
1.12      www      1162: </form>
1.19      www      1163: ENDCOL
1.12      www      1164: }
                   1165: 
1.19      www      1166: sub verify_and_change_colors {
1.12      www      1167:     my $r = shift;
1.19      www      1168: # figure out colors
1.80      albertel 1169:     my $function=&Apache::loncommon::get_users_function();
1.19      www      1170:     my $domain=&Apache::loncommon::determinedomain();
                   1171:     my %colortypes=('pgbg'  => 'Page Background',
                   1172:                     'tabbg' => 'Header Background',
                   1173:                     'sidebg'=> 'Header Border',
                   1174:                     'font'  => 'Font',
                   1175:                     'link'  => 'Un-Visited Link',
                   1176:                     'vlink' => 'Visited Link',
                   1177:                     'alink' => 'Active Link');
                   1178: 
1.12      www      1179:     my $message='';
1.21      www      1180:     foreach my $item (keys %colortypes) {
1.59      albertel 1181:         my $color=$env{'form.'.$item};
1.21      www      1182:         my $entry='color.'.$function.'.'.$item;
1.59      albertel 1183: 	if (($color=~/^\#[0-9A-Fa-f]{6}$/) && (!$env{'form.resetall'})) {
1.21      www      1184: 	    &Apache::lonnet::put('environment',{$entry => $color});
1.116     raeburn  1185: 	    &Apache::lonnet::appenv({'environment.'.$entry => $color});
1.110     bisitz   1186: 	    $message.=&mt('Set '.$colortypes{$item}.' to ').'<tt>"'.$color.'"</tt>.<br />';
1.21      www      1187: 	} else {
                   1188: 	    &Apache::lonnet::del('environment',[$entry]);
1.138     schafran 1189: 	    &Apache::lonnet::delenv('environment.'.$entry);
1.110     bisitz   1190: 	    $message.=&mt('Reset '.$colortypes{$item}.'.').'<br />';
1.21      www      1191: 	}
                   1192:     }
1.84      albertel 1193:     my $now = time;
                   1194:     &Apache::lonnet::put('environment',{'color.timestamp' => $now});
1.116     raeburn  1195:     &Apache::lonnet::appenv({'environment.color.timestamp' => $now});
1.84      albertel 1196: 
1.126     droeschl 1197:     print_main_menu($r, $message);
                   1198: #    $r->print(<<ENDVCCOL);
                   1199: #$message
                   1200: #<form name="client" action="/adm/preferences" method="post">
                   1201: #<input type="hidden" name="action" value="changecolors" />
                   1202: #</form>
                   1203: #ENDVCCOL
1.12      www      1204: }
                   1205: 
1.4       matthew  1206: ######################################################
                   1207: #            password handler subroutines            #
                   1208: ######################################################
1.3       matthew  1209: sub passwordchanger {
1.94      raeburn  1210:     my ($r,$errormessage,$caller,$mailtoken) = @_;
1.4       matthew  1211:     # This function is a bit of a mess....
1.3       matthew  1212:     # Passwords are encrypted using londes.js (DES encryption)
1.4       matthew  1213:     $errormessage = ($errormessage || '');
1.94      raeburn  1214:     my ($user,$domain,$currentpass,$defdom);
1.126     droeschl 1215:     Apache::lonhtmlcommon::add_breadcrumb(
                   1216: 		{ href => '/adm/preferences?action=changepass',
                   1217:                   text => 'Change Password'});
1.144     raeburn  1218:     unless ($caller eq 'reset_by_email') {
1.147     schafran 1219:         $r->print(Apache::loncommon::start_page('Personal Data'));
1.144     raeburn  1220:         $r->print(Apache::lonhtmlcommon::breadcrumbs('Change Password'));
                   1221:     }
1.94      raeburn  1222:     if ((!defined($caller)) || ($caller eq 'preferences')) {
                   1223:         $user = $env{'user.name'};
                   1224:         $domain = $env{'user.domain'};
                   1225:         if (!defined($caller)) {
                   1226:             $caller = 'preferences';
                   1227:         }
                   1228:     } elsif ($caller eq 'reset_by_email') {
                   1229:             $defdom = $r->dir_config('lonDefDomain');
                   1230:             my %data = &Apache::lonnet::tmpget($mailtoken);
                   1231:             if (keys(%data) == 0) {
1.110     bisitz   1232:                 $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  1233:                 return;
                   1234:             }
                   1235:             if (defined($data{time})) {
                   1236:                 if (time - $data{'time'} < 7200) {
                   1237:                     $user = $data{'username'};
                   1238:                     $domain = $data{'domain'};
                   1239:                     $currentpass = $data{'temppasswd'};
                   1240:                 } else {
                   1241:                     $r->print(&mt('Sorry, the token generated when you requested a password reset has expired.').'<br />');
                   1242:                     return;
                   1243:                 }
                   1244:             } else {
                   1245:                 $r->print(&mt('Sorry, the URL generated when you requested reset of your password contained incomplete information.').'<br />');
                   1246:                 return;
                   1247:             }
                   1248:    } else {
                   1249:         $r->print(&mt('Page requested in unexpected context').'<br />');
                   1250:         return;
                   1251:     }
1.3       matthew  1252:     my $currentauth=&Apache::lonnet::queryauthenticate($user,$domain);
                   1253:     # Check for authentication types that allow changing of the password.
                   1254:     return if ($currentauth !~ /^(unix|internal):/);
                   1255:     #
                   1256:     # Generate keys
                   1257:     my ($lkey_cpass ,$ukey_cpass ) = &des_keys();
                   1258:     my ($lkey_npass1,$ukey_npass1) = &des_keys();
                   1259:     my ($lkey_npass2,$ukey_npass2) = &des_keys();
1.4       matthew  1260:     # Store the keys in the log files
1.3       matthew  1261:     my $lonhost = $r->dir_config('lonHostID');
                   1262:     my $logtoken=Apache::lonnet::reply('tmpput:'
                   1263: 				       .$ukey_cpass  . $lkey_cpass .'&'
                   1264: 				       .$ukey_npass1 . $lkey_npass1.'&'
                   1265: 				       .$ukey_npass2 . $lkey_npass2,
                   1266: 				       $lonhost);
1.4       matthew  1267:     # Hexify the keys for output as javascript variables
1.94      raeburn  1268:     my %hexkey;
                   1269:     $hexkey{'ukey_cpass'}  = hex($ukey_cpass);
                   1270:     $hexkey{'lkey_cpass'}  = hex($lkey_cpass);
                   1271:     $hexkey{'ukey_npass1'} = hex($ukey_npass1);
                   1272:     $hexkey{'lkey_npass1'} = hex($lkey_npass1);
                   1273:     $hexkey{'ukey_npass2'} = hex($ukey_npass2);
                   1274:     $hexkey{'lkey_npass2'} = hex($lkey_npass2);
1.3       matthew  1275:     # Output javascript to deal with passwords
1.4       matthew  1276:     # Output DES javascript
1.3       matthew  1277:     {
                   1278: 	my $include = $r->dir_config('lonIncludes');
                   1279: 	my $jsh=Apache::File->new($include."/londes.js");
                   1280: 	$r->print(<$jsh>);
                   1281:     }
1.94      raeburn  1282:     $r->print(&jscript_send($caller));
1.3       matthew  1283:     $r->print(<<ENDFORM);
1.94      raeburn  1284: $errormessage
                   1285: 
                   1286: <p>
                   1287: <!-- We separate the forms into 'server' and 'client' in order to
                   1288:      ensure that unencrypted passwords will not be sent out by a
                   1289:      crappy browser -->
                   1290: ENDFORM
                   1291:     $r->print(&server_form($logtoken,$caller,$mailtoken));
                   1292:     $r->print(&client_form($caller,\%hexkey,$currentpass,$defdom));
                   1293: 
                   1294:     #
                   1295:     return;
                   1296: }
                   1297: 
                   1298: sub jscript_send {
                   1299:     my ($caller) = @_;
                   1300:     my $output = qq|
1.148     bisitz   1301: <script type="text/javascript" language="JavaScript">
1.3       matthew  1302: 
                   1303:     function send() {
                   1304:         uextkey=this.document.client.elements.ukey_cpass.value;
                   1305:         lextkey=this.document.client.elements.lkey_cpass.value;
                   1306:         initkeys();
                   1307: 
1.52      raeburn  1308:         this.document.pserver.elements.currentpass.value
1.3       matthew  1309:             =crypted(this.document.client.elements.currentpass.value);
                   1310: 
                   1311:         uextkey=this.document.client.elements.ukey_npass1.value;
                   1312:         lextkey=this.document.client.elements.lkey_npass1.value;
                   1313:         initkeys();
1.52      raeburn  1314:         this.document.pserver.elements.newpass_1.value
1.3       matthew  1315:             =crypted(this.document.client.elements.newpass_1.value);
                   1316: 
                   1317:         uextkey=this.document.client.elements.ukey_npass2.value;
                   1318:         lextkey=this.document.client.elements.lkey_npass2.value;
                   1319:         initkeys();
1.52      raeburn  1320:         this.document.pserver.elements.newpass_2.value
1.3       matthew  1321:             =crypted(this.document.client.elements.newpass_2.value);
1.94      raeburn  1322: |;
                   1323:     if ($caller eq 'reset_by_email') {
                   1324:         $output .= qq|
                   1325:         this.document.pserver.elements.uname.value =
                   1326:                    this.document.client.elements.uname.value;
                   1327:         this.document.pserver.elements.udom.value =
                   1328:                    this.document.client.elements.udom.options[this.document.client.elements.udom.selectedIndex].value;
                   1329: |;
                   1330:     }
                   1331:     $ output .= qq|
1.52      raeburn  1332:         this.document.pserver.submit();
1.3       matthew  1333:     }
                   1334: </script>
1.94      raeburn  1335: |;
                   1336: }
1.3       matthew  1337: 
1.94      raeburn  1338: sub client_form {
                   1339:     my ($caller,$hexkey,$currentpass,$defdom) = @_;
1.99      www      1340:     my %lt=&Apache::lonlocal::texthash(
1.115     raeburn  1341:                 'email' => 'E-mail Address',
1.99      www      1342:                 'username' => 'Username',
                   1343:                 'domain' => 'Domain',
                   1344:                 'currentpass' => 'Current Password',
                   1345:                 'newpass' => 'New Password',
                   1346:                 'confirmpass' => 'Confirm Password',
1.136     schafran 1347:                 'changepass' => 'Save');
1.99      www      1348: 
1.94      raeburn  1349:     my $output = qq|
1.3       matthew  1350: <form name="client" >
                   1351: <table>
1.94      raeburn  1352: |;
                   1353:     if ($caller eq 'reset_by_email') {
                   1354:         $output .= qq|
1.99      www      1355: <tr><td class="LC_preferences_labeltext"><label for="email">$lt{'email'}</label>:</td>
1.97      raeburn  1356:     <td><input type="text" name="email" size="30" /> </td></tr>
1.99      www      1357: <tr><td class="LC_preferences_labeltext"><label for="uname">$lt{'username'}</label>:</td>
1.94      raeburn  1358:     <td>
1.97      raeburn  1359:      <input type="text" name="uname" size="15" />
1.94      raeburn  1360:      <input type="hidden" name="currentpass" value="$currentpass" />
                   1361:     </td></tr>
1.115     raeburn  1362: <tr><td class="LC_preferences_labeltext"><label for="udom">$lt{'domain'}</label>:</td>
1.94      raeburn  1363:     <td>
                   1364: |;
                   1365:         $output .= &Apache::loncommon::select_dom_form($defdom,'udom').'
                   1366:    </td>
                   1367: </tr>
                   1368: ';
                   1369:     } else {
                   1370:         $output .= qq|
1.99      www      1371: <tr><td class="LC_preferences_labeltext"><label for="currentpass">$lt{'currentpass'}</label></td>
1.4       matthew  1372:     <td><input type="password" name="currentpass" size="10"/> </td></tr>
1.94      raeburn  1373: |;
                   1374:     }
                   1375:     $output .= <<"ENDFORM";
1.99      www      1376: <tr><td class="LC_preferences_labeltext"><label for="newpass_1">$lt{'newpass'}</label></td>
1.4       matthew  1377:     <td><input type="password" name="newpass_1" size="10"  /> </td></tr>
1.99      www      1378: <tr><td class="LC_preferences_labeltext"><label for="newpass_2">$lt{'confirmpass'}</label></td>
1.4       matthew  1379:     <td><input type="password" name="newpass_2" size="10"  /> </td></tr>
1.3       matthew  1380: <tr><td colspan="2" align="center">
1.149   ! bisitz   1381:     <input type="button" value="$lt{'changepass'}" onClick="send();" />
1.3       matthew  1382: </table>
1.94      raeburn  1383: <input type="hidden" name="ukey_cpass"  value="$hexkey->{'ukey_cpass'}" />
                   1384: <input type="hidden" name="lkey_cpass"  value="$hexkey->{'lkey_cpass'}" />
                   1385: <input type="hidden" name="ukey_npass1" value="$hexkey->{'ukey_npass1'}" />
                   1386: <input type="hidden" name="lkey_npass1" value="$hexkey->{'lkey_npass1'}" />
                   1387: <input type="hidden" name="ukey_npass2" value="$hexkey->{'ukey_npass2'}" />
                   1388: <input type="hidden" name="lkey_npass2" value="$hexkey->{'lkey_npass2'}" />
1.3       matthew  1389: </form>
                   1390: </p>
                   1391: ENDFORM
1.94      raeburn  1392:     return $output;
                   1393: }
                   1394: 
                   1395: sub server_form {
                   1396:     my ($logtoken,$caller,$mailtoken) = @_;
                   1397:     my $action = '/adm/preferences';
                   1398:     if ($caller eq 'reset_by_email') {
                   1399:         $action = '/adm/resetpw';
                   1400:     }
                   1401:     my $output = qq|
                   1402: <form name="pserver" action="$action" method="post">
                   1403: <input type="hidden" name="logtoken"    value="$logtoken" />
                   1404: <input type="hidden" name="currentpass" value="" />
                   1405: <input type="hidden" name="newpass_1"   value="" />
                   1406: <input type="hidden" name="newpass_2"   value="" />
                   1407:     |;
                   1408:     if ($caller eq 'reset_by_email') {
                   1409:         $output .=  qq|
                   1410: <input type="hidden" name="token"   value="$mailtoken" />
                   1411: <input type="hidden" name="uname"   value="" />
                   1412: <input type="hidden" name="udom"   value="" />
                   1413: 
                   1414: |;
                   1415:     }
                   1416:     $output .= qq|
                   1417: <input type="hidden" name="action" value="verify_and_change_pass" />
                   1418: </form>
                   1419: |;
                   1420:     return $output;
1.3       matthew  1421: }
                   1422: 
                   1423: sub verify_and_change_password {
1.94      raeburn  1424:     my ($r,$caller,$mailtoken) = @_;
                   1425:     my ($user,$domain,$homeserver);
                   1426:     if ($caller eq 'reset_by_email') {
                   1427:         $user       = $env{'form.uname'};
                   1428:         $domain     = $env{'form.udom'};
                   1429:         if ($user ne '' && $domain ne '') {
                   1430:             $homeserver = &Apache::lonnet::homeserver($user,$domain);
                   1431:             if ($homeserver eq 'no_host') {
1.99      www      1432:         &passwordchanger($r,"<p>\n<span class='LC_error'>".
                   1433:                          &mt("Invalid username and/or domain")."</span>\n</p>",
1.94      raeburn  1434:                          $caller,$mailtoken);
                   1435:                 return 1;
                   1436:             }
                   1437:         } else {
1.99      www      1438:             &passwordchanger($r,"<p>\n<span class='LC_error'>".
                   1439:                              &mt("Username and domain were blank")."</span>\n</p>",
1.94      raeburn  1440:                              $caller,$mailtoken);
                   1441:             return 1;
                   1442:         }
                   1443:     } else {
                   1444:         $user       = $env{'user.name'};
                   1445:         $domain     = $env{'user.domain'};
                   1446:         $homeserver = $env{'user.home'};
                   1447:     }
1.3       matthew  1448:     my $currentauth=&Apache::lonnet::queryauthenticate($user,$domain);
1.4       matthew  1449:     # Check for authentication types that allow changing of the password.
1.94      raeburn  1450:     if ($currentauth !~ /^(unix|internal):/) {
                   1451:         if ($caller eq 'reset_by_email') {
1.99      www      1452:             &passwordchanger($r,"<p>\n<span class='LC_error'>".
                   1453:                              &mt("Authentication type for this user can not be changed by this mechanism").
                   1454:                              "</span>\n</p>",
1.94      raeburn  1455:                               $caller,$mailtoken);
                   1456:             return 1;
                   1457:         } else {
                   1458:             return;
                   1459:         }
                   1460:     }
1.3       matthew  1461:     #
1.59      albertel 1462:     my $currentpass = $env{'form.currentpass'}; 
                   1463:     my $newpass1    = $env{'form.newpass_1'}; 
                   1464:     my $newpass2    = $env{'form.newpass_2'};
                   1465:     my $logtoken    = $env{'form.logtoken'};
1.3       matthew  1466:     # Check for empty data 
1.4       matthew  1467:     unless (defined($currentpass) && 
                   1468: 	    defined($newpass1)    && 
                   1469: 	    defined($newpass2)    ){
1.99      www      1470: 	&passwordchanger($r,"<p>\n<span class='LC_error'>".
                   1471: 			 &mt("One or more password fields were blank").
                   1472:                          "</span>\n</p>",$caller,$mailtoken);
1.3       matthew  1473: 	return;
                   1474:     }
1.16      albertel 1475:     # Get the keys
                   1476:     my $lonhost = $r->dir_config('lonHostID');
1.3       matthew  1477:     my $tmpinfo = Apache::lonnet::reply('tmpget:'.$logtoken,$lonhost);
                   1478:     if (($tmpinfo=~/^error/) || ($tmpinfo eq 'con_lost')) {
1.4       matthew  1479:         # I do not a have a better idea about how to handle this
1.94      raeburn  1480:         my $tryagain_text = &mt('Please log out and try again.');
                   1481:         if ($caller eq 'reset_by_email') {
                   1482:             $tryagain_text = &mt('Please try again later.');
                   1483:         }
1.101     albertel 1484:         my $unable=&mt("Unable to retrieve saved token for password decryption");
1.3       matthew  1485: 	$r->print(<<ENDERROR);
                   1486: <p>
1.99      www      1487: <span class="LC_error">$unable.  $tryagain_text</span>
1.3       matthew  1488: </p>
                   1489: ENDERROR
1.4       matthew  1490:         # Probably should log an error here
1.75      albertel 1491:         return 1;
1.3       matthew  1492:     }
                   1493:     my ($ckey,$n1key,$n2key)=split(/&/,$tmpinfo);
1.4       matthew  1494:     # 
1.17      matthew  1495:     $currentpass = &des_decrypt($ckey ,$currentpass);
                   1496:     $newpass1    = &des_decrypt($n1key,$newpass1);
                   1497:     $newpass2    = &des_decrypt($n2key,$newpass2);
1.94      raeburn  1498:     #
                   1499:     if ($caller eq 'reset_by_email') {
                   1500:         my %data = &Apache::lonnet::tmpget($mailtoken);
1.117     raeburn  1501:         if (keys(%data) == 0) {
                   1502:             &passwordchanger($r,
                   1503:                          '<span class="LC_error">'.
                   1504:                          &mt('Could not verify current authentication.').'  '.
                   1505:                          &mt('Please try again.').'</span>',$caller,$mailtoken);
                   1506:             return 1;
                   1507:         }
1.94      raeburn  1508:         if ($currentpass ne $data{'temppasswd'}) {
                   1509:             &passwordchanger($r,
1.99      www      1510:                          '<span class="LC_error">'.
1.110     bisitz   1511:                          &mt('Could not verify current authentication.').'  '.
                   1512:                          &mt('Please try again.').'</span>',$caller,$mailtoken);
1.94      raeburn  1513:             return 1;
                   1514:         }
                   1515:     } 
1.3       matthew  1516:     if ($newpass1 ne $newpass2) {
1.4       matthew  1517: 	&passwordchanger($r,
1.99      www      1518: 			 '<span class="LC_error">'.
1.110     bisitz   1519: 			 &mt('The new passwords you entered do not match.').'  '.
                   1520: 			 &mt('Please try again.').'</span>',$caller,$mailtoken);
1.75      albertel 1521: 	return 1;
1.4       matthew  1522:     }
                   1523:     if (length($newpass1) < 7) {
                   1524: 	&passwordchanger($r,
1.99      www      1525: 			 '<span class="LC_error">'.
1.110     bisitz   1526: 			 &mt('Passwords must be a minimum of 7 characters long.').'  '.
                   1527: 			 &mt('Please try again.').'</span>',$caller,$mailtoken);
1.75      albertel 1528: 	return 1;
1.3       matthew  1529:     }
1.4       matthew  1530:     #
                   1531:     # Check for bad characters
                   1532:     my $badpassword = 0;
                   1533:     foreach (split(//,$newpass1)) {
                   1534: 	$badpassword = 1 if ((ord($_)<32)||(ord($_)>126));
                   1535:     }
                   1536:     if ($badpassword) {
                   1537: 	# I can't figure out how to enter bad characters on my browser.
1.99      www      1538: 	my $errormessage ='<span class="LC_error">'.
1.110     bisitz   1539:            &mt('The password you entered contained illegal characters.').'<br />'.
1.99      www      1540:            &mt('Valid characters are').(<<"ENDERROR");
                   1541: : space and <br />
1.4       matthew  1542: <pre>
                   1543: !&quot;\#$%&amp;\'()*+,-./0123456789:;&lt;=&gt;?\@
                   1544: ABCDEFGHIJKLMNOPQRSTUVWXYZ[\]^_\`abcdefghijklmnopqrstuvwxyz{|}~
1.99      www      1545: </pre></span>
1.4       matthew  1546: ENDERROR
1.94      raeburn  1547:         &passwordchanger($r,$errormessage,$caller,$mailtoken);
                   1548:         return 1;
1.4       matthew  1549:     }
                   1550:     # 
                   1551:     # Change the password (finally)
                   1552:     my $result = &Apache::lonnet::changepass
1.94      raeburn  1553: 	($user,$domain,$currentpass,$newpass1,$homeserver,$caller);
1.4       matthew  1554:     # Inform the user the password has (not?) been changed
1.126     droeschl 1555:     my $message;
1.4       matthew  1556:     if ($result =~ /^ok$/) {
1.144     raeburn  1557:         $message = &mt('The password for [_1] was successfully changed.',$user);
                   1558:         if ($caller eq 'reset_by_email') {
                   1559:             $r->print($message.'<br />');
                   1560:         } else {
                   1561:             &print_main_menu($r, $message);
                   1562:         }
1.126     droeschl 1563: #	$r->print("<h3>".&mt('The password for [_1] was successfully changed',$user)."</h3>");
1.4       matthew  1564:     } else {
                   1565: 	# error error: run in circles, scream and shout
1.145     schualex 1566:         $message = &mt("The password for [_1] was not changed.",$user).' '.&mt('Please make sure your old password was entered correctly.');
1.144     raeburn  1567:         unless ($caller eq 'reset_by_email') {
                   1568:             &print_main_menu($r, $message);
                   1569:         }
1.126     droeschl 1570: #        $r->print("<h3><span class='LC_error'>".&mt("The password for [_1] was not changed",$user)."</span></h3>".
                   1571: #                  &mt('Please make sure your old password was entered correctly.'));
1.75      albertel 1572:         return 1;
1.4       matthew  1573:     }
                   1574:     return;
1.3       matthew  1575: }
                   1576: 
1.42      raeburn  1577: ################################################################
                   1578: #            discussion display subroutines 
                   1579: ################################################################
                   1580: sub discussionchanger {
                   1581:     my $r = shift;
1.126     droeschl 1582:     Apache::lonhtmlcommon::add_breadcrumb(
                   1583: 	    {	href => '/adm/preferences?action=changediscussions',
                   1584:                 text => 'Change Discussion Preferences'});
1.147     schafran 1585:     $r->print(Apache::loncommon::start_page('Message Management'));
1.126     droeschl 1586:     $r->print(Apache::lonhtmlcommon::breadcrumbs('Change Discussion Preferences'));
1.59      albertel 1587:     my $user       = $env{'user.name'};
                   1588:     my $domain     = $env{'user.domain'};
1.42      raeburn  1589:     my %userenv = &Apache::lonnet::get
1.43      raeburn  1590:         ('environment',['discdisplay','discmarkread']);
                   1591:     my $discdisp = 'allposts';
                   1592:     my $discmark = 'onmark';
                   1593: 
                   1594:     if (defined($userenv{'discdisplay'})) {
                   1595:         unless ($userenv{'discdisplay'} eq '') { 
                   1596:             $discdisp = $userenv{'discdisplay'};
                   1597:         }
                   1598:     }
                   1599:     if (defined($userenv{'discmarkread'})) {
                   1600:         unless ($userenv{'discdisplay'} eq '') { 
                   1601:             $discmark = $userenv{'discmarkread'};
                   1602:         }
                   1603:     }
                   1604: 
                   1605:     my $newdisp = 'unread';
                   1606:     my $newmark = 'ondisp';
                   1607: 
                   1608:     my $function = &Apache::loncommon::get_users_function();
                   1609:     my $color = &Apache::loncommon::designparm($function.'.tabbg',
1.59      albertel 1610:                                                     $env{'user.domain'});
1.43      raeburn  1611:     my %lt = &Apache::lonlocal::texthash(
                   1612:         'pref' => 'Display Preference',
                   1613:         'curr' => 'Current setting ',
                   1614:         'actn' => 'Action',
1.135     schafran 1615:         'sdpf' => 'Set display preferences for discussion posts for both discussion boards and individual resources in all your courses.',
1.43      raeburn  1616:         'prca' => 'Preferences can be set that determine',
1.135     schafran 1617:         'whpo' => 'Which posts are displayed when you display a discussion board or resource, and',
1.43      raeburn  1618:         'unwh' => 'Under what circumstances posts are identfied as "New"',
                   1619:         'allposts' => 'All posts',
                   1620:         'unread' => 'New posts only',
                   1621:         'ondisp' => 'Once displayed',
                   1622:         'onmark' => 'Once marked as read',
                   1623:         'disa' => 'Posts displayed?',
                   1624:         'npmr' => 'New posts cease to be identified as "New"?',
                   1625:         'thde'  => 'The preferences you set here can be overridden within each individual discussion.',
                   1626:         'chgt' => 'Change to '
                   1627:     );
                   1628:     my $dispchange = $lt{'unread'};
                   1629:     my $markchange = $lt{'ondisp'};
                   1630:     my $currdisp = $lt{'allposts'};
                   1631:     my $currmark = $lt{'onmark'};
                   1632: 
                   1633:     if ($discdisp eq 'unread') {
                   1634:         $dispchange = $lt{'allposts'};
                   1635:         $currdisp = $lt{'unread'};
                   1636:         $newdisp = 'allposts';
                   1637:     }
                   1638: 
                   1639:     if ($discmark eq 'ondisp') {
                   1640:         $markchange = $lt{'onmark'};
                   1641:         $currmark = $lt{'ondisp'};
                   1642:         $newmark = 'onmark';
1.42      raeburn  1643:     }
1.43      raeburn  1644:     
                   1645:     $r->print(<<"END");
1.88      albertel 1646: <form name="prefs" action="/adm/preferences" method="post">
1.42      raeburn  1647: <input type="hidden" name="action" value="verify_and_change_discussion" />
                   1648: <br />
1.87      albertel 1649: $lt{'sdpf'}<br /> $lt{'prca'}  <ol><li>$lt{'whpo'}</li><li>$lt{'unwh'}</li></ol> 
1.43      raeburn  1650: <br />
                   1651: <br />
1.82      albertel 1652: END
                   1653:     $r->print(&Apache::loncommon::start_data_table());
                   1654:     $r->print(<<"END");
                   1655:        <tr>
                   1656:         <th>$lt{'pref'}</th>
                   1657:         <th>$lt{'curr'}</th>
                   1658:         <th>$lt{'actn'}?</th>
1.43      raeburn  1659:        </tr>
1.82      albertel 1660: END
                   1661:     $r->print(&Apache::loncommon::start_data_table_row());
                   1662:     $r->print(<<"END");
1.43      raeburn  1663:        <td>$lt{'disa'}</td>
                   1664:        <td>$lt{$discdisp}</td>
1.82      albertel 1665:        <td><label><input type="checkbox" name="discdisp" /><input type="hidden" name="newdisp" value="$newdisp" />&nbsp;$lt{'chgt'} "$dispchange"</label></td>
                   1666: END
                   1667:     $r->print(&Apache::loncommon::end_data_table_row().
                   1668: 	      &Apache::loncommon::start_data_table_row());
                   1669:     $r->print(<<"END");
1.43      raeburn  1670:        <td>$lt{'npmr'}</td>
                   1671:        <td>$lt{$discmark}</td>
1.82      albertel 1672:        <td><label><input type="checkbox" name="discmark" /><input type="hidden" name="newmark" value="$newmark" />&nbsp;$lt{'chgt'} "$markchange"</label></td>
1.43      raeburn  1673:       </tr>
1.82      albertel 1674: END
                   1675:     $r->print(&Apache::loncommon::end_data_table_row().
                   1676: 	      &Apache::loncommon::end_data_table());
1.142     zhu      1677: 
                   1678:     $r->print('<br /><br /><input type="submit" name="sub" value="'.&mt('Save').'" /><br /><br />'.&mt('Note').': '.$lt{'thde'}.'</form>');
1.42      raeburn  1679: }
                   1680:                                                                                                                 
                   1681: sub verify_and_change_discussion {
                   1682:     my $r = shift;
1.59      albertel 1683:     my $user     = $env{'user.name'};
                   1684:     my $domain   = $env{'user.domain'};
1.42      raeburn  1685:     my $message='';
1.59      albertel 1686:     if (defined($env{'form.discdisp'}) ) {
                   1687:         my $newdisp  = $env{'form.newdisp'};
1.43      raeburn  1688:         if ($newdisp eq 'unread') {
1.110     bisitz   1689:             $message .=&mt('In discussions: only new posts will be displayed.').'<br />';
1.43      raeburn  1690:             &Apache::lonnet::put('environment',{'discdisplay' => $newdisp});
1.116     raeburn  1691:             &Apache::lonnet::appenv({'environment.discdisplay' => $newdisp});
1.43      raeburn  1692:         } else {
1.110     bisitz   1693:             $message .= &mt('In discussions: all posts will be displayed.').'<br />';
1.43      raeburn  1694:             &Apache::lonnet::del('environment',['discdisplay']);
1.139     raeburn  1695:             &Apache::lonnet::delenv('environment.discdisplay');
1.43      raeburn  1696:         }
                   1697:     }
1.59      albertel 1698:     if (defined($env{'form.discmark'}) ) {
                   1699:         my $newmark = $env{'form.newmark'};
1.43      raeburn  1700:         if ($newmark eq 'ondisp') {
1.110     bisitz   1701:            $message.=&mt('In discussions: new posts will be cease to be identified as "NEW" after display.').'<br />';
1.43      raeburn  1702:             &Apache::lonnet::put('environment',{'discmarkread' => $newmark});
1.116     raeburn  1703:             &Apache::lonnet::appenv({'environment.discmarkread' => $newmark});
1.43      raeburn  1704:         } else {
1.110     bisitz   1705:             $message.=&mt('In discussions: posts will be identified as "NEW" until marked as read by the reader.').'<br />';
1.43      raeburn  1706:             &Apache::lonnet::del('environment',['discmarkread']);
1.139     raeburn  1707:             &Apache::lonnet::delenv('environment.discmarkread');
1.43      raeburn  1708:         }
1.42      raeburn  1709:     }
1.126     droeschl 1710: #    $r->print(<<ENDVCSCREEN);
                   1711: #$message
                   1712: #ENDVCSCREEN
                   1713:     print_main_menu($r, $message);
1.42      raeburn  1714: }
                   1715: 
1.63      raeburn  1716: ################################################################
                   1717: # Subroutines for page display on course access (Course Coordinators)
                   1718: ################################################################
                   1719: sub coursedisplaychanger {
                   1720:     my $r = shift;
1.126     droeschl 1721:     Apache::lonhtmlcommon::add_breadcrumb(
                   1722: 	    {	href => '/adm/preferences?action=changecourseinit',
                   1723:                 text => 'Change Course Init. Pref.'});
                   1724:     $r->print(Apache::loncommon::start_page('Change Course Initialization Preference'));
                   1725:     $r->print(Apache::lonhtmlcommon::breadcrumbs('Change Course Init. Pref.'));
1.63      raeburn  1726:     my $user       = $env{'user.name'};
                   1727:     my $domain     = $env{'user.domain'};
1.66      albertel 1728:     my %userenv = &Apache::lonnet::get('environment',['course_init_display']);
1.71      raeburn  1729:     my $currvalue = 'whatsnew';
1.73      albertel 1730:     my $firstselect = '';
                   1731:     my $whatsnewselect = 'checked="checked"';
1.71      raeburn  1732:     if (exists($userenv{'course_init_display'})) {
                   1733:         if ($userenv{'course_init_display'} eq 'firstres') {
                   1734:             $currvalue = 'firstres';
1.73      albertel 1735:             $firstselect = 'checked="checked"';
                   1736: 	    $whatsnewselect = '';
1.71      raeburn  1737:         }
1.63      raeburn  1738:     }
1.134     bisitz   1739:     my %pagenames = &Apache::lonlocal::texthash(
1.71      raeburn  1740:                        firstres => 'First resource',
1.143     hauer    1741:                        whatsnew => "What's New Page",
1.71      raeburn  1742:                     );
1.134     bisitz   1743:     my $whatsnew_off=&mt('Display the [_1]first resource[_2] in the course.','<b>','</b>');
1.143     hauer    1744:     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  1745: 
1.134     bisitz   1746:     $r->print('<br /><b>'
                   1747:              .&mt('Set the default page to be displayed when you select a course role')
                   1748:              .'</b>&nbsp;'
                   1749:              .&mt('(Currently: [_1])',$pagenames{$currvalue})
                   1750:              .'<br />'
1.143     hauer    1751:              .&mt("The global user preference you set for your courses can be overridden in an individual course by setting a course specific setting via the [_1]What's New Page[_2] in the course.",'<i>','</i>')
1.134     bisitz   1752:              .'<br /><br />'
                   1753:     );
1.63      raeburn  1754:     $r->print(<<ENDLSCREEN);
1.88      albertel 1755: <form name="prefs" action="/adm/preferences" method="post">
1.63      raeburn  1756: <input type="hidden" name="action" value="verify_and_change_coursepage" />
1.72      albertel 1757: <br />
1.65      albertel 1758: <label><input type="radio" name="newdisp" value="firstres" $firstselect /> $whatsnew_off</label><br />
1.70      raeburn  1759: <label><input type="radio" name="newdisp" value="whatsnew" $whatsnewselect /> $whatsnew_on</label><input type="hidden" name="refpage" value="$env{'form.refpage'}" />
1.63      raeburn  1760: ENDLSCREEN
1.140     schafran 1761:     $r->print('<br /><br /><input type="submit" value="'.&mt('Save').'" />
1.63      raeburn  1762: </form>');
                   1763: }
                   1764: 
                   1765: sub verify_and_change_coursepage {
                   1766:     my $r = shift;
                   1767:     my $message='';
                   1768:     my %lt = &Apache::lonlocal::texthash(
1.70      raeburn  1769:         'defs' => 'Default now set',
1.71      raeburn  1770:         'when' => 'when you select a course role from the roles screen',
1.63      raeburn  1771:         'ywbt' => 'you will be taken to the start of the course.',
                   1772:         'apwb' => 'a page will be displayed that lists items in the course that may require action from you.',
                   1773:         'gtts' => 'Go to the start of the course',
1.146     hauer    1774:         'dasp' => "Display the What's New Page", 
1.63      raeburn  1775:     );
                   1776:     my $newdisp  = $env{'form.newdisp'};
1.70      raeburn  1777:     $message = '<b>'.$lt{'defs'}.'</b>: '.$lt{'when'}.', ';
1.63      raeburn  1778:     if ($newdisp eq 'firstres') {
1.87      albertel 1779:         $message .= $lt{'ywbt'}.'<br />';
1.63      raeburn  1780:         &Apache::lonnet::put('environment',{'course_init_display' => $newdisp});
1.116     raeburn  1781:         &Apache::lonnet::appenv({'environment.course_init_display' => $newdisp});
1.63      raeburn  1782:     } else {
1.87      albertel 1783:         $message .= $lt{'apwb'}.'<br />';
1.63      raeburn  1784:         &Apache::lonnet::del('environment',['course_init_display']);
1.139     raeburn  1785:         &Apache::lonnet::delenv('environment.course_init_display');
1.63      raeburn  1786:     }
1.70      raeburn  1787:     my $refpage = $env{'form.refpage'};
1.63      raeburn  1788:     if (($env{'request.course.fn'}) && ($env{'request.course.id'})) {
                   1789:         if ($newdisp eq 'firstres') {
                   1790:             my $cdom = $env{'course.'.$env{'request.course.id'}.'.domain'};
                   1791:             my $cnum = $env{'course.'.$env{'request.course.id'}.'.num'}; 
                   1792:             my ($furl,$ferr)=
                   1793:                 &Apache::lonuserstate::readmap($cdom.'/'.$cnum);
                   1794:             $message .= '<br /><font size="+1"><a href="'.$furl.'">'.$lt{'gtts'}.' <i>'.&mt('now').'</i></a></font>';
                   1795:         } else {
1.70      raeburn  1796:             $message .= '<br /><font size="+1"><a href="/adm/whatsnew?refpage='.
                   1797:                         $refpage.'">'.$lt{'dasp'}.'</a></font>';
1.63      raeburn  1798:         }
                   1799:     }
1.126     droeschl 1800: #    $r->print(<<ENDVCSCREEN);
                   1801: #$message
                   1802: #<br /><br />
                   1803: #ENDVCSCREEN
                   1804:     print_main_menu($r, $message);
1.63      raeburn  1805: }
                   1806: 
1.126     droeschl 1807: sub print_main_menu {
                   1808:     my ($r, $message) = @_;
                   1809:     # Determine current authentication method
                   1810:     my $user = $env{'user.name'};
                   1811:     my $domain = $env{'user.domain'};
                   1812:     my $currentauth=&Apache::lonnet::queryauthenticate($user,$domain);
                   1813: 
                   1814:     # build the data structure for menu generation
                   1815: my $aboutmeurl='/adm/'.$env{'user.domain'}.'/'.$env{'user.name'}.'/aboutme';
                   1816: my $role = ($env{'user.adv'} ? 'Roles' : 'Course');
1.131     raeburn  1817: my %permissions;
                   1818: if (&Apache::lonnet::usertools_access($user,$domain,'aboutme')) {
                   1819:     $permissions{'aboutme'} = 'F';
                   1820: }
1.126     droeschl 1821: my @menu=
                   1822:     ({	categorytitle=>'Personal Data',
                   1823: 	items =>[
1.141     weissno  1824: 	    {	linktext => 'Personal Information Page',
1.126     droeschl 1825: 		url => $aboutmeurl,
1.131     raeburn  1826: 		permission => $permissions{'aboutme'},
1.126     droeschl 1827: 		#help => 'Prefs_About_Me',
                   1828: 		icon => 'system-users.png',
                   1829: 		linktitle => 'Edit information about yourself that should be displayed on your public profile.'
                   1830: 	    },
                   1831: 	    {	linktext => 'Screen Name',
                   1832: 		url => '/adm/preferences?action=changescreenname',
                   1833: 		permission => 'F',
                   1834: 		#help => 'Prefs_Screen_Name_Nickname',
                   1835: 		icon => 'preferences-desktop-font.png',
                   1836: 		linktitle => 'Change the name that is displayed in your posts.'
                   1837: 	    },
                   1838: 		]
                   1839:     },
                   1840:     {	categorytitle=>'Page Display Settings',
                   1841: 	items =>[
                   1842: 	    {	linktext => 'Color Scheme',
                   1843: 		url => '/adm/preferences?action=changecolors',
                   1844: 		permission => 'F',
                   1845: 		#help => 'Change_Colors',
                   1846: 		icon => 'preferences-desktop-theme.png',
                   1847: 		linktitle => 'Change LON-CAPA default colors.'
                   1848: 	    },
                   1849: 	    {	linktext => 'Menu Display',
                   1850: 		url => '/adm/preferences?action=changeicons',
                   1851: 		permission => 'F',
                   1852: 		#help => '',
                   1853: 		icon => 'preferences-system-windows.png',
                   1854: 		linktitle => 'Change whether the menus are displayed with buttons, icons or icons and text.'
                   1855: 	    }
                   1856: 
                   1857: 		]
                   1858:     },
                   1859:     {	categorytitle=>'Content Display Settings',
                   1860: 	items =>[
                   1861: 	    {	linktext => 'Language',
                   1862: 		url => '/adm/preferences?action=changelanguages',
                   1863: 		permission => 'F',
                   1864: 		#help => 'Prefs_Language',
                   1865: 		icon => 'preferences-desktop-locale.png',
1.127     droeschl 1866: 		linktitle => 'Choose the default language for this user.'
1.126     droeschl 1867: 	    },
1.128     droeschl 1868: 	    {	linktext => 'WYSIWYG Editor',
1.126     droeschl 1869: 		url => '/adm/preferences?action=changewysiwyg',
                   1870: 		permission => 'F',
                   1871: 		#help => '',
                   1872: 		icon => 'edit-select-all.png',
                   1873: 		linktitle => 'Enable or disable the WYSIWYG-Editor.'
                   1874: 	    },
1.128     droeschl 1875: 	    {	linktext => $role.' Page',
1.126     droeschl 1876: 		url => '/adm/preferences?action=changerolespref',
                   1877: 		permission => 'F',
                   1878: 		#help => '',
                   1879: 		icon => 'sctr.png',
                   1880: 		linktitle => 'Configure the roles hotlist.'
                   1881: 	    },
1.127     droeschl 1882: 	    {	linktext => 'Display of Scientific Equations',
1.126     droeschl 1883: 		url => '/adm/preferences?action=changetexenginepref',
                   1884: 		permission => 'F',
                   1885: 		#help => '',
                   1886: 		icon => 'stat.png',
1.127     droeschl 1887: 		linktitle => 'Change how Scientific Equations are displayed.'
1.126     droeschl 1888: 	    },
                   1889: 		]
                   1890:     },
1.128     droeschl 1891:     {	categorytitle=>'Message Management',
                   1892: 	items =>[
                   1893: 	    {	linktext => 'Messages & Notifications',
                   1894: 		url => '/adm/preferences?action=changemsgforward',
                   1895: 		permission => 'F',
                   1896: 		#help => 'Prefs_Messages',
                   1897: 		icon => 'mail-reply-all.png',
                   1898: 		linktitle => 'Change messageforwarding or notifications settings.'
                   1899: 	    },
                   1900: 	    {	linktext => 'Discussion Display',
                   1901: 		url => '/adm/preferences?action=changediscussions',
                   1902: 		permission => 'F',
                   1903: 		#help => 'Change_Discussion_Display',
                   1904: 		icon => 'mail-message-new.png',
1.135     schafran 1905: 		linktitle => 'Set display preferences for discussion posts for both discussion boards and individual resources in all your courses.'
1.128     droeschl 1906: 	    },
                   1907: 		]
                   1908:     },
1.126     droeschl 1909:     {	categorytitle=>'Other',
                   1910: 	items =>[
                   1911: 	    {	linktext => 'Register Response Devices ("Clickers")',
                   1912: 		url => '/adm/preferences?action=changeclicker',
                   1913: 		permission => 'F',
                   1914: 		#help => '',
                   1915: 		icon => 'network-workgroup.png',
                   1916: 		linktitle => 'Register your clicker.'
                   1917: 	    },
                   1918: 		]
                   1919:     },
                   1920:     );
                   1921: 
                   1922:     if ($currentauth =~ /^(unix|internal):/) {
                   1923: push(@{ $menu[0]->{items} }, {
                   1924: 	linktext => 'Password',
                   1925: 	url => '/adm/preferences?action=changepass',
                   1926: 	permission => 'F',
                   1927: 	#help => 'Change_Password',
                   1928: 	icon => 'emblem-readonly.png',
                   1929: 	linktitle => 'Change your password.',
                   1930: 	});
                   1931:     }
                   1932:     if ($env{'environment.remote'} eq 'off') {
                   1933: push(@{ $menu[1]->{items} }, {
                   1934: 	linktext => 'Launch Remote Control',
                   1935: 	url => '/adm/remote?url=/adm/preferences?action=launch',
                   1936: 	permission => 'F',
                   1937: 	#help => '',
                   1938: 	icon => 'network-wireless.png',
                   1939: 	linktitle => 'Launch the remote control for LON-CAPA.',
                   1940: 	});
                   1941:     }else{
                   1942: push(@{ $menu[1]->{items} }, {
                   1943: 	linktext => 'Collapse Remote Control',
                   1944: 	url => '/adm/remote?url=/adm/preferences?action=collapse',
                   1945: 	permission => 'F',
                   1946: 	#help => '',
                   1947: 	icon => 'network-wireless.png',
                   1948: 	linktitle => 'Collapse the remote control for LON-CAPA.',
                   1949: 	});
                   1950:     }
                   1951:     my %author_roles = &Apache::lonnet::get_my_roles($user,$domain,'userroles','',['au']);
                   1952:     if (keys(%author_roles) > 0) {
                   1953: push(@{ $menu[4]->{items} }, {
                   1954: 	linktext => 'Restrict Domain Coordinator Access',
                   1955: 	url => '/adm/preferences?action=changedomcoord',
                   1956: 	permission => 'F',
                   1957: 	#help => '',
                   1958: 	icon => 'system-lock-screen.png',
                   1959: 	linktitle => 'Restrict domain coordinator access.',
                   1960: 	});
                   1961:     }
                   1962: 
                   1963:     if (&Apache::lonnet::allowed('whn',$env{'request.course.id'})
                   1964: 	|| &Apache::lonnet::allowed('whn',$env{'request.course.id'}.'/'
                   1965: 				    .$env{'request.course.sec'})) {
                   1966: push(@{ $menu[4]->{items} }, {
1.128     droeschl 1967: 	linktext => 'Course Initialization',
1.126     droeschl 1968: 	url => '/adm/preferences?action=changecourseinit',
                   1969: 	permission => 'F',
                   1970: 	#help => '',
                   1971: 	icon => 'edit-copy.png',
                   1972: 	linktitle => 'Set the default page to be displayed when you select a course role.',
                   1973: 	});
                   1974: 
                   1975:     }
                   1976:     if ($env{'user.name'} =~ /^(albertel|fox|foxr|kortemey|korte|raeburn)$/) {
                   1977: push(@{ $menu[4]->{items} }, {
                   1978: 	linktext => 'Toggle Debug Messages (Current:'.$env{'user.debug'}.')',
                   1979: 	url => '/adm/preferences?action=debugtoggle',
                   1980: 	permission => 'F',
                   1981: 	#help => '',
                   1982: 	icon => 'blog.png',
                   1983: 	linktitle => 'Toggle Debug Messages.',
                   1984: 	});
                   1985:     }   
                   1986: 
1.147     schafran 1987:     $r->print(&Apache::loncommon::start_page('My Space'));
1.126     droeschl 1988:     $r->print(Apache::lonhtmlcommon::breadcrumbs('Change Preferences'));
                   1989:     $r->print($message);
                   1990:     $r->print(Apache::lonhtmlcommon::generate_menu(@menu));
                   1991:     $r->print(Apache::loncommon::end_page());
                   1992: }
1.63      raeburn  1993: 
1.4       matthew  1994: ######################################################
                   1995: #            other handler subroutines               #
                   1996: ######################################################
                   1997: 
1.3       matthew  1998: ################################################################
                   1999: #                          Main handler                        #
                   2000: ################################################################
1.126     droeschl 2001: sub handler {    
                   2002:     my $r = shift;
                   2003:     Apache::loncommon::content_type($r,'text/html');
                   2004:     # Some pages contain DES keys and should not be cached.
                   2005:     Apache::loncommon::no_cache($r);
                   2006:     $r->send_http_header;
                   2007:     return OK if $r->header_only;
                   2008:     #
                   2009:     Apache::loncommon::get_unprocessed_cgi($ENV{'QUERY_STRING'},
                   2010:                                    ['action','wysiwyg','returnurl','refpage']);
                   2011:     #
                   2012:     Apache::lonhtmlcommon::clear_breadcrumbs();
                   2013:     Apache::lonhtmlcommon::add_breadcrumb
                   2014:         ({href => '/adm/preferences',
                   2015:           text => 'Set User Preferences'});
                   2016:     if(!exists $env{'form.action'}) {
                   2017: 	&print_main_menu($r);
                   2018:     }elsif($env{'form.action'} eq 'changepass'){
                   2019:         &passwordchanger($r);
                   2020:     }elsif($env{'form.action'} eq 'verify_and_change_pass'){
                   2021:         &verify_and_change_password($r);
                   2022:     }elsif($env{'form.action'} eq 'changescreenname'){
                   2023:         &screennamechanger($r);
                   2024:     }elsif($env{'form.action'} eq 'verify_and_change_screenname'){
                   2025:         &verify_and_change_screenname($r);
                   2026:     }elsif($env{'form.action'} eq 'changemsgforward'){
                   2027:         &msgforwardchanger($r);
                   2028:     }elsif($env{'form.action'} eq 'verify_and_change_msgforward'){
                   2029:         &verify_and_change_msgforward($r);
                   2030:     }elsif($env{'form.action'} eq 'changecolors'){
                   2031:         &colorschanger($r);
                   2032:     }elsif($env{'form.action'} eq 'verify_and_change_colors'){
                   2033:         &verify_and_change_colors($r);
                   2034:     }elsif($env{'form.action'} eq 'changelanguages'){
                   2035:         &languagechanger($r);
                   2036:     }elsif($env{'form.action'} eq 'verify_and_change_languages'){
                   2037:         &verify_and_change_languages($r);
                   2038:     }elsif($env{'form.action'} eq 'changewysiwyg'){
                   2039:         &wysiwygchanger($r);
                   2040:     }elsif($env{'form.action'} eq 'set_wysiwyg'){
                   2041:         &verify_and_change_wysiwyg($r);
                   2042:     }elsif($env{'form.action'} eq 'changediscussions'){
                   2043:         &discussionchanger($r);
                   2044:     }elsif($env{'form.action'} eq 'verify_and_change_discussion'){
                   2045:         &verify_and_change_discussion($r);
                   2046:     }elsif($env{'form.action'} eq 'changerolespref'){
                   2047:         &rolesprefchanger($r);
                   2048:     }elsif($env{'form.action'} eq 'verify_and_change_rolespref'){
                   2049:         &verify_and_change_rolespref($r);
                   2050:     }elsif($env{'form.action'} eq 'changetexenginepref'){
                   2051:         &texenginechanger($r);
                   2052:     }elsif($env{'form.action'} eq 'verify_and_change_texengine'){
                   2053:         &verify_and_change_texengine($r);
                   2054:     }elsif($env{'form.action'} eq 'changeicons'){
                   2055:         &iconchanger($r);
                   2056:     }elsif($env{'form.action'} eq 'verify_and_change_icons'){
                   2057:         &verify_and_change_icons($r);
                   2058:     }elsif($env{'form.action'} eq 'changeclicker'){
                   2059:         &clickerchanger($r);
                   2060:     }elsif($env{'form.action'} eq 'verify_and_change_clicker'){
                   2061:         &verify_and_change_clicker($r);
                   2062:     }elsif($env{'form.action'} eq 'changedomcoord'){
                   2063:         &domcoordchanger($r);
                   2064:     }elsif($env{'form.action'} eq 'verify_and_change_domcoord'){
                   2065:         &verify_and_change_domcoord($r);
                   2066:     }elsif($env{'form.action'} eq 'lockwarning'){
                   2067:         &lockwarning($r);
                   2068:     }elsif($env{'form.action'} eq 'verify_and_change_locks'){
                   2069:         &verify_and_change_lockwarning($r);
                   2070:     }elsif($env{'form.action'} eq 'changecourseinit'){
                   2071:         &coursedisplaychanger($r);
                   2072:     }elsif($env{'form.action'} eq 'verify_and_change_coursepage'){
                   2073:         &verify_and_change_coursepage($r);
                   2074:     }elsif($env{'form.action'} eq 'debugtoggle'){
                   2075:         toggle_debug();
                   2076: 	print_main_menu($r);
                   2077:     }
                   2078: 
                   2079:     return OK;
                   2080: 
                   2081: 
                   2082: }
                   2083: #remove when done
                   2084: #old handler routine
                   2085: sub handler2 {
1.1       www      2086:     my $r = shift;
1.59      albertel 2087:     my $user = $env{'user.name'};
                   2088:     my $domain = $env{'user.domain'};
1.31      www      2089:     &Apache::loncommon::content_type($r,'text/html');
1.4       matthew  2090:     # Some pages contain DES keys and should not be cached.
                   2091:     &Apache::loncommon::no_cache($r);
1.1       www      2092:     $r->send_http_header;
                   2093:     return OK if $r->header_only;
1.9       matthew  2094:     #
1.35      matthew  2095:     &Apache::loncommon::get_unprocessed_cgi($ENV{'QUERY_STRING'},
1.70      raeburn  2096:                                    ['action','wysiwyg','returnurl','refpage']);
1.35      matthew  2097:     #
                   2098:     &Apache::lonhtmlcommon::clear_breadcrumbs();
                   2099:     &Apache::lonhtmlcommon::add_breadcrumb
                   2100:         ({href => '/adm/preferences',
                   2101:           text => 'Set User Preferences'});
                   2102: 
                   2103:     my @Options;
                   2104:     # Determine current authentication method
                   2105:     my $currentauth=&Apache::lonnet::queryauthenticate($user,$domain);
                   2106:     if ($currentauth =~ /^(unix|internal):/) {
                   2107:         push (@Options,({ action   => 'changepass',
1.40      www      2108:                           linktext => 'Change Password',
1.35      matthew  2109:                           href     => '/adm/preferences',
                   2110:                           help     => 'Change_Password',
                   2111:                           subroutine => \&passwordchanger,
                   2112:                           breadcrumb => 
                   2113:                               { href => '/adm/preferences?action=changepass',
                   2114:                                 text => 'Change Password'},
                   2115:                           },
                   2116:                         { action => 'verify_and_change_pass',
                   2117:                           subroutine => \&verify_and_change_password,
                   2118:                           breadcrumb => 
                   2119:                               { href =>'/adm/preferences?action=changepass',
                   2120:                                 text => 'Change Password'},
1.75      albertel 2121:                           printmenu => 'not_on_error',
1.35      matthew  2122:                           }));
                   2123:     }
                   2124:     push (@Options,({ action   => 'changescreenname',
                   2125:                       linktext => 'Change Screen Name',
                   2126:                       href     => '/adm/preferences',
                   2127:                       help     => 'Prefs_Screen_Name_Nickname',
                   2128:                       subroutine => \&screennamechanger,
                   2129:                       breadcrumb => 
                   2130:                           { href => '/adm/preferences?action=changescreenname',
                   2131:                             text => 'Change Screen Name'},
                   2132:                       },
                   2133:                     { action   => 'verify_and_change_screenname',
                   2134:                       subroutine => \&verify_and_change_screenname,
                   2135:                       breadcrumb => 
                   2136:                           { href => '/adm/preferences?action=changescreenname',
                   2137:                             text => 'Change Screen Name'},
                   2138:                       printmenu => 'yes',
                   2139:                       }));
                   2140: 
                   2141:     push (@Options,({ action   => 'changemsgforward',
1.129     schafran 2142:                       linktext => 'Change Message Forwarding and Notification E-mail Addresses',
1.35      matthew  2143:                       href     => '/adm/preferences',
1.113     raeburn  2144:                       help     => 'Prefs_Messages',
1.35      matthew  2145:                       breadcrumb => 
                   2146:                           { href => '/adm/preferences?action=changemsgforward',
1.113     raeburn  2147:                             text => 'Change Message Forwarding/Notification'},
1.35      matthew  2148:                       subroutine => \&msgforwardchanger,
                   2149:                       },
                   2150:                     { action => 'verify_and_change_msgforward',
1.113     raeburn  2151:                       help   => 'Prefs_Messages',
1.35      matthew  2152:                       breadcrumb => 
                   2153:                           { href => '/adm/preferences?action=changemsgforward',
1.113     raeburn  2154:                             text => 'Change Message Forwarding/Notification'},
1.126     droeschl 2155:                       printmenu => 'yes',
1.35      matthew  2156:                       subroutine => \&verify_and_change_msgforward }));
                   2157:     my $aboutmeaction=
1.59      albertel 2158:         '/adm/'.$env{'user.domain'}.'/'.$env{'user.name'}.'/aboutme';
1.35      matthew  2159:     push (@Options,{ action => 'none', 
                   2160:                      linktext =>
1.141     weissno  2161:                          q{Edit the Personal Information Page},
1.45      www      2162: 		     help => 'Prefs_About_Me',
1.35      matthew  2163:                      href => $aboutmeaction});
                   2164:     push (@Options,({ action => 'changecolors',
                   2165:                       linktext => 'Change Color Scheme',
                   2166:                       href => '/adm/preferences',
                   2167:                       help => 'Change_Colors',
                   2168:                       breadcrumb => 
                   2169:                           { href => '/adm/preferences?action=changecolors',
                   2170:                             text => 'Change Colors'},
                   2171:                       subroutine => \&colorschanger,
                   2172:                   },
                   2173:                     { action => 'verify_and_change_colors',
                   2174:                       breadcrumb => 
                   2175:                           { href => '/adm/preferences?action=changecolors',
                   2176:                             text => 'Change Colors'},
                   2177:                       printmenu => 'yes',
                   2178:                       subroutine => \&verify_and_change_colors,
                   2179:                       }));
                   2180:     push (@Options,({ action => 'changelanguages',
1.39      www      2181:                       linktext => 'Change Language Preferences',
1.35      matthew  2182:                       href => '/adm/preferences',
1.45      www      2183: 		      help => 'Prefs_Language',
1.35      matthew  2184:                       breadcrumb=>
                   2185:                           { href => '/adm/preferences?action=changelanguages',
                   2186:                             text => 'Change Language'},
                   2187:                       subroutine =>  \&languagechanger,
                   2188:                   },
                   2189:                     { action => 'verify_and_change_languages',
                   2190:                       breadcrumb=>
                   2191:                           {href => '/adm/preferences?action=changelanguages',
                   2192:                            text => 'Change Language'},
                   2193:                       printmenu => 'yes',
                   2194:                       subroutine=>\&verify_and_change_languages, }
                   2195:                     ));
1.44      www      2196:     push (@Options,({ action => 'changewysiwyg',
                   2197:                       linktext => 'Change WYSIWYG Editor Preferences',
                   2198:                       href => '/adm/preferences',
                   2199:                       breadcrumb => 
                   2200:                             { href => '/adm/preferences?action=changewysiwyg',
                   2201:                               text => 'Change WYSIWYG Preferences'},
                   2202:                       subroutine => \&wysiwygchanger,
                   2203:                   },
                   2204:                     { action => 'set_wysiwyg',
                   2205:                       breadcrumb =>
                   2206:                           { href => '/adm/preferences?action=changewysiwyg',
                   2207:                             text => 'Change WYSIWYG Preferences'},
                   2208:                       printmenu => 'yes',
                   2209:                       subroutine => \&verify_and_change_wysiwyg, }
                   2210:                     ));
1.42      raeburn  2211:     push (@Options,({ action => 'changediscussions',
                   2212:                       linktext => 'Change Discussion Display Preferences',
                   2213:                       href => '/adm/preferences',
1.46      raeburn  2214:                       help => 'Change_Discussion_Display',
1.42      raeburn  2215:                       breadcrumb => 
                   2216:                             { href => '/adm/preferences?action=changediscussions',
1.43      raeburn  2217:                               text => 'Change Discussion Preferences'},
1.42      raeburn  2218:                       subroutine => \&discussionchanger,
                   2219:                   },
                   2220:                     { action => 'verify_and_change_discussion',
                   2221:                       breadcrumb =>
                   2222:                           { href => '/adm/preferences?action=changediscussions',
1.43      raeburn  2223:                             text => 'Change Discussion Preferences'},
1.42      raeburn  2224:                       printmenu => 'yes',
                   2225:                       subroutine => \&verify_and_change_discussion, }
                   2226:                     ));
1.96      albertel 2227: 
                   2228:     my $role = ($env{'user.adv'} ? 'Roles' : 'Course');
1.50      albertel 2229:     push (@Options,({ action   => 'changerolespref',
1.96      albertel 2230:                       linktext => 'Change '.$role.' Page Preferences',
1.50      albertel 2231:                       href     => '/adm/preferences',
                   2232:                       subroutine => \&rolesprefchanger,
                   2233:                       breadcrumb =>
                   2234:                           { href => '/adm/preferences?action=changerolespref',
1.96      albertel 2235:                             text => 'Change '.$role.' Page Pref'},
1.50      albertel 2236:                       },
                   2237:                     { action   => 'verify_and_change_rolespref',
                   2238:                       subroutine => \&verify_and_change_rolespref,
                   2239:                       breadcrumb =>
                   2240:                           { href => '/adm/preferences?action=changerolespref',
1.96      albertel 2241:                             text => 'Change '.$role.' Page Preferences'},
1.50      albertel 2242:                       printmenu => 'yes',
                   2243:                       }));
                   2244: 
1.54      albertel 2245:     push (@Options,({ action   => 'changetexenginepref',
                   2246:                       linktext => 'Change How Math Equations Are Displayed',
                   2247:                       href     => '/adm/preferences',
                   2248:                       subroutine => \&texenginechanger,
                   2249:                       breadcrumb =>
                   2250:                           { href => '/adm/preferences?action=changetexenginepref',
                   2251:                             text => 'Change Math Pref'},
                   2252:                       },
                   2253:                     { action   => 'verify_and_change_texengine',
                   2254:                       subroutine => \&verify_and_change_texengine,
                   2255:                       breadcrumb =>
                   2256:                           { href => '/adm/preferences?action=changetexenginepref',
                   2257:                             text => 'Change Math Preferences'},
                   2258:                       printmenu => 'yes',
                   2259:                       }));
1.85      albertel 2260: 
                   2261:     if ($env{'environment.remote'} eq 'off') {
                   2262: 	push (@Options,({ action => 'launch',
                   2263: 			  linktext => 'Launch Remote Control',
                   2264: 			  href => '/adm/remote?url=/adm/preferences',
                   2265: 		      }));
                   2266:     } else {
                   2267: 	push (@Options,({ action => 'collapse',
                   2268: 			  linktext => 'Collapse Remote Control',
                   2269: 			  href => '/adm/remote?url=/adm/preferences',
                   2270: 		      }));
                   2271:     }
                   2272: 
1.98      www      2273:     push (@Options,({ action   => 'changeicons',
1.100     www      2274:                       linktext => 'Change How Menus are Displayed',
1.98      www      2275:                       href     => '/adm/preferences',
                   2276:                       subroutine => \&iconchanger,
                   2277:                       breadcrumb =>
                   2278:                           { href => '/adm/preferences?action=changeicons',
                   2279:                             text => 'Change Main Menu'},
                   2280:                       },
                   2281:                     { action   => 'verify_and_change_icons',
                   2282:                       subroutine => \&verify_and_change_icons,
                   2283:                       breadcrumb =>
                   2284:                           { href => '/adm/preferences?action=changeicons',
                   2285:                             text => 'Change Main Menu'},
                   2286:                       printmenu => 'yes',
                   2287:                       }));
                   2288: 
1.106     www      2289:     push (@Options,({ action   => 'changeclicker',
                   2290:                       linktext => 'Register Response Devices ("Clickers")',
                   2291:                       href     => '/adm/preferences',
                   2292:                       subroutine => \&clickerchanger,
                   2293:                       breadcrumb =>
1.118     www      2294:                           { href => '/adm/preferences?action=changeclicker',
1.106     www      2295:                             text => 'Register Clicker'},
                   2296:                       },
                   2297:                     { action   => 'verify_and_change_clicker',
                   2298:                       subroutine => \&verify_and_change_clicker,
                   2299:                       breadcrumb =>
                   2300:                           { href => '/adm/preferences?action=changeclicker',
                   2301:                             text => 'Register Clicker'},
                   2302:                       printmenu => 'yes',
                   2303:                       }));
1.125     raeburn  2304:     my %author_roles = &Apache::lonnet::get_my_roles($user,$domain,'userroles','',['au']);
                   2305:     if (keys(%author_roles) > 0) {
1.119     www      2306:       push (@Options,({ action   => 'changedomcoord',
                   2307:                         linktext => 'Restrict Domain Coordinator Access',
                   2308:                         href     => '/adm/preferences',
                   2309:                         subroutine => \&domcoordchanger,
                   2310:                         breadcrumb =>
                   2311:                             { href => '/adm/preferences?action=changedomcoord',
                   2312:                               text => 'Restrict Domain Coordinator Access'},
                   2313:                       },
                   2314:                       { action   => 'verify_and_change_domcoord',
                   2315:                         subroutine => \&verify_and_change_domcoord,
                   2316:                         breadcrumb =>
                   2317:                             { href => '/adm/preferences?action=changedomcoord',
                   2318:                               text => 'Restrict Domain Coordinator Access'},
                   2319:                         printmenu => 'yes',
                   2320:                       }));
                   2321:     }
1.105     www      2322: 
1.118     www      2323:     push (@Options,({ action   => 'lockwarning',
                   2324:                       subroutine => \&lockwarning,
                   2325:                       breadcrumb =>
                   2326:                           { href => '/adm/preferences?action=lockwarning',
                   2327:                             text => 'Lock Warnings'},
                   2328:                       },
                   2329:                     { action   => 'verify_and_change_locks',
                   2330:                       subroutine => \&verify_and_change_lockwarning,
                   2331:                       breadcrumb =>
                   2332:                           { href => '/adm/preferences?action=lockwarning',
                   2333:                             text => 'Lockwarnings'},
                   2334:                       printmenu => 'yes',
                   2335:                       }));
                   2336: 
1.105     www      2337: 
1.74      albertel 2338:     if (&Apache::lonnet::allowed('whn',$env{'request.course.id'})
                   2339: 	|| &Apache::lonnet::allowed('whn',$env{'request.course.id'}.'/'
                   2340: 				    .$env{'request.course.sec'})) {
1.63      raeburn  2341:         push (@Options,({ action => 'changecourseinit',
                   2342:                           linktext => 'Change Course Initialization Preference',
                   2343:                           href => '/adm/preferences',
                   2344:                           subroutine => \&coursedisplaychanger,
                   2345:                           breadcrumb =>
                   2346:                               { href => '/adm/preferences?action=changecourseinit',
                   2347:                                 text => 'Change Course Init. Pref.'},
                   2348:                           },
                   2349:                         { action => 'verify_and_change_coursepage',
                   2350:                           breadcrumb =>
                   2351:                           { href => '/adm/preferences?action=changecourseinit',                               text => 'Change Course Initialization Preference'},
                   2352:                         printmenu => 'yes',
                   2353:                         subroutine => \&verify_and_change_coursepage,
                   2354:                        }));
                   2355:     }
1.50      albertel 2356: 
1.119     www      2357:     if ($env{'user.name'} =~ /^(albertel|fox|foxr|kortemey|korte|raeburn)$/) {
1.35      matthew  2358:         push (@Options,({ action => 'debugtoggle',
                   2359:                           printmenu => 'yes',
                   2360:                           subroutine => \&toggle_debug,
                   2361:                           }));
                   2362:     }
1.76      albertel 2363: 
                   2364:     $r->print(&Apache::loncommon::start_page('Change Preferences'));
                   2365: 
1.35      matthew  2366:     my $call = undef;
1.48      albertel 2367:     my $help = undef;
1.35      matthew  2368:     my $printmenu = 'yes';
                   2369:     foreach my $option (@Options) {
1.59      albertel 2370:         if ($option->{'action'} eq $env{'form.action'}) {
1.35      matthew  2371:             $call = $option->{'subroutine'};
                   2372:             $printmenu = $option->{'printmenu'};
                   2373:             if (exists($option->{'breadcrumb'})) {
                   2374:                 &Apache::lonhtmlcommon::add_breadcrumb
                   2375:                     ($option->{'breadcrumb'});
                   2376:             }
1.48      albertel 2377: 	    $help=$option->{'help'};
1.35      matthew  2378:         }
                   2379:     }
1.81      albertel 2380:     $r->print(&Apache::lonhtmlcommon::breadcrumbs('Change Preferences',$help));
1.75      albertel 2381:     my $error;
1.35      matthew  2382:     if (defined($call)) {
1.75      albertel 2383:         $error = $call->($r);
1.35      matthew  2384:     }
1.75      albertel 2385:     if ( ( ($printmenu eq 'yes')
                   2386: 	   || ($printmenu eq 'not_on_error' && !$error) )
                   2387: 	 && (!$env{'form.returnurl'})) {
1.35      matthew  2388:         my $optionlist = '<table cellpadding="5">';
1.59      albertel 2389:         if ($env{'user.name'} =~ 
1.62      raeburn  2390:                          /^(albertel|kortemey|fox|foxr|korte|hallmat3|turtle|raeburn)$/
1.35      matthew  2391:             ) {
                   2392:             push (@Options,({ action => 'debugtoggle',
                   2393:                               linktext => 'Toggle Debug Messages',
                   2394:                               text => 'Current Debug status is -'.
1.59      albertel 2395:                                   $env{'user.debug'}.'-.',
1.35      matthew  2396:                               href => '/adm/preferences',
                   2397:                               printmenu => 'yes',
                   2398:                               subroutine => \&toggle_debug,
                   2399:                               }));
                   2400:         }
                   2401:         foreach my $option(@Options) {
                   2402:             my $optiontext = '';
                   2403:             if (exists($option->{'href'})) {
1.85      albertel 2404: 		$option->{'href_args'}{'action'}=$option->{'action'};
                   2405: 		$optiontext .= 
                   2406:                     '<a href="'.&add_get_param($option->{'href'},
                   2407: 					       $option->{'href_args'}).'">'.
1.47      albertel 2408:                     &mt($option->{'linktext'}).'</a>';
1.35      matthew  2409:             }
                   2410:             if (exists($option->{'text'})) {
1.47      albertel 2411:                 $optiontext .= ' '.&mt($option->{'text'});
1.35      matthew  2412:             }
                   2413:             if ($optiontext ne '') {
                   2414:                 $optiontext = '<font size="+1">'.$optiontext.'</font>'; 
                   2415:                 my $helplink = '&nbsp;';
                   2416:                 if (exists($option->{'help'})) {
                   2417:                     $helplink = &Apache::loncommon::help_open_topic
                   2418:                                                     ($option->{'help'});
                   2419:                 }
                   2420:                 $optionlist .= '<tr>'.
                   2421:                     '<td>'.$helplink.'</td>'.
                   2422:                     '<td>'.$optiontext.'</td>'.
                   2423:                     '</tr>';
                   2424:             }
1.13      www      2425:         }
1.35      matthew  2426:         $optionlist .= '</table>';
                   2427:         $r->print($optionlist);
1.59      albertel 2428:     } elsif ($env{'form.returnurl'}) {
                   2429: 	$r->print('<br /><a href="'.$env{'form.returnurl'}.'"><font size="+1">'.
1.44      www      2430: 		  &mt('Return').'</font></a>');
1.3       matthew  2431:     }
1.76      albertel 2432:     $r->print(&Apache::loncommon::end_page());
1.1       www      2433:     return OK;
1.35      matthew  2434: }
                   2435: 
                   2436: sub toggle_debug {
1.59      albertel 2437:     if ($env{'user.debug'}) {
1.139     raeburn  2438:         &Apache::lonnet::delenv('user.debug');
1.35      matthew  2439:     } else {
1.116     raeburn  2440:         &Apache::lonnet::appenv({'user.debug' => 1});
1.35      matthew  2441:     }
1.13      www      2442: }
1.1       www      2443: 
                   2444: 1;
                   2445: __END__

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