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

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

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