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

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

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