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

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

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