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

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

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