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

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

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