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

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

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