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

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

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