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

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

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