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

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

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