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

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

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