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

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

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