Annotation of loncom/interface/lonpreferences.pm, revision 1.98
1.1 www 1: # The LearningOnline Network
2: # Preferences
3: #
1.98 ! www 4: # $Id: lonpreferences.pm,v 1.97 2007/03/07 16:24:08 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;
101: my %userenv = &Apache::lonnet::get
102: ('environment',['wysiwygeditor']);
1.78 albertel 103: my $onselect='checked="checked"';
1.44 www 104: my $offselect='';
1.77 albertel 105: if ($userenv{'wysiwygeditor'} eq 'on') {
1.44 www 106: $onselect='';
1.78 albertel 107: $offselect='checked="checked"';
1.44 www 108: }
109: my $switchoff=&mt('Disable WYSIWYG editor');
110: my $switchon=&mt('Enable WYSIWYG editor');
111: $r->print(<<ENDLSCREEN);
1.88 albertel 112: <form name="prefs" action="/adm/preferences" method="post">
1.44 www 113: <input type="hidden" name="action" value="set_wysiwyg" />
114: <br />
1.65 albertel 115: <label><input type="radio" name="wysiwyg" value="off" $onselect /> $switchoff</label><br />
116: <label><input type="radio" name="wysiwyg" value="on" $offselect /> $switchon</label>
1.44 www 117: ENDLSCREEN
118: $r->print('<br /><input type="submit" value="'.&mt('Change').'" />');
119: }
120:
121:
122: sub verify_and_change_wysiwyg {
123: my $r = shift;
1.59 albertel 124: my $newsetting=$env{'form.wysiwyg'};
1.44 www 125: &Apache::lonnet::put('environment',{'wysiwygeditor' => $newsetting});
126: &Apache::lonnet::appenv('environment.wysiwygeditor' => $newsetting);
127: $r->print('<p>'.&mt('Setting WYSIWYG editor to:').' '.&mt($newsetting).'</p>');
128: }
129:
130: ################################################################
131: # Language Change Subroutines #
132: ################################################################
1.28 www 133: sub languagechanger {
134: my $r = shift;
1.59 albertel 135: my $user = $env{'user.name'};
136: my $domain = $env{'user.domain'};
1.28 www 137: my %userenv = &Apache::lonnet::get
1.32 www 138: ('environment',['languages']);
1.29 www 139: my $language=$userenv{'languages'};
1.32 www 140:
1.33 www 141: my $pref=&mt('Preferred language');
142: my %langchoices=('' => 'No language preference');
143: foreach (&Apache::loncommon::languageids()) {
144: if (&Apache::loncommon::supportedlanguagecode($_)) {
145: $langchoices{&Apache::loncommon::supportedlanguagecode($_)}
146: = &Apache::loncommon::plainlanguagedescription($_);
147: }
148: }
149: my $selectionbox=&Apache::loncommon::select_form($language,'language',
150: %langchoices);
1.28 www 151: $r->print(<<ENDLSCREEN);
1.88 albertel 152: <form name="prefs" action="/adm/preferences" method="post">
1.28 www 153: <input type="hidden" name="action" value="verify_and_change_languages" />
1.33 www 154: <br />$pref: $selectionbox
1.28 www 155: ENDLSCREEN
1.35 matthew 156: $r->print('<br /><input type="submit" value="'.&mt('Change').'" />');
1.28 www 157: }
158:
159:
160: sub verify_and_change_languages {
161: my $r = shift;
1.59 albertel 162: my $user = $env{'user.name'};
163: my $domain = $env{'user.domain'};
1.28 www 164: # Screenname
1.59 albertel 165: my $newlanguage = $env{'form.language'};
1.28 www 166: $newlanguage=~s/[^\-\w]//g;
167: my $message='';
168: if ($newlanguage) {
1.29 www 169: &Apache::lonnet::put('environment',{'languages' => $newlanguage});
170: &Apache::lonnet::appenv('environment.languages' => $newlanguage);
171: $message='Set new preferred languages to '.$newlanguage;
1.28 www 172: } else {
1.29 www 173: &Apache::lonnet::del('environment',['languages']);
174: &Apache::lonnet::delenv('environment\.languages');
1.28 www 175: $message='Reset preferred language';
176: }
177: $r->print(<<ENDVCSCREEN);
178: $message
179: ENDVCSCREEN
180: }
181:
1.50 albertel 182: ################################################################
1.54 albertel 183: # Tex Engine Change Subroutines #
184: ################################################################
185: sub texenginechanger {
186: my $r = shift;
1.59 albertel 187: my $user = $env{'user.name'};
188: my $domain = $env{'user.domain'};
1.54 albertel 189: my %userenv = &Apache::lonnet::get('environment',['texengine']);
190: my $texengine=$userenv{'texengine'};
191:
192: my $pref=&mt('Preferred method to display Math');
1.69 albertel 193: my %mathchoices=('' => 'Default',
1.54 albertel 194: 'tth' => 'TeX to HTML',
1.64 albertel 195: #'ttm' => 'TeX to MathML',
1.54 albertel 196: 'jsMath' => 'jsMath',
1.57 albertel 197: 'mimetex' => 'Convert to Images'
1.54 albertel 198: );
199: my $selectionbox=&Apache::loncommon::select_form($texengine,'texengine',
200: %mathchoices);
1.67 albertel 201: my $jsMath_start=&Apache::lontexconvert::jsMath_header();
1.54 albertel 202: my $change=&mt('Change');
203: $r->print(<<ENDLSCREEN);
1.67 albertel 204: <br />
205:
1.88 albertel 206: <form name="prefs" action="/adm/preferences" method="post">
1.54 albertel 207: <input type="hidden" name="action" value="verify_and_change_texengine" />
208: <p>$pref: $selectionbox</p>
209: <p><input type="submit" value="$change" /></p>
210: </form>
211: Examples:
1.67 albertel 212: <p> TeX to HTML <br />
1.79 albertel 213: <iframe src="/res/adm/pages/math_example.tex?inhibitmenu=yes&texengine=tth" width="400" hieght="200"></iframe>
1.67 albertel 214: </p>
1.54 albertel 215: <p>jsMath <br />
1.67 albertel 216: $jsMath_start
1.57 albertel 217: <script type="text/javascript">
1.54 albertel 218: if (jsMath.nofonts == 1) {
219: document.writeln
220: ('<center><div style="padding: 10; border-style: solid; border-width:3;'
221: +' border-color: #DD0000; background-color: #FFF8F8; width: 75%; text-align: left">'
222: +'<small><font color="#AA0000"><b>Warning:</b> '
223: +'It looks like you don\\\'t have the TeX math fonts installed. '
224: +'The jsMath example on this page may not look right without them. '
225: +'The <a href="http://www.math.union.edu/locate/jsMath/" target="_blank"> '
226: +'jsMath Home Page</a> has information on how to download the '
227: +'needed fonts. In the meantime, jsMath will do the best it can '
228: +'with the fonts you have, but it may not be pretty and some equations '
229: +'may not be rendered correctly. '
230: +'</font></small></div></center>');
231: }
232: </script>
1.79 albertel 233: <iframe src="/res/adm/pages/math_example.tex?inhibitmenu=yes&texengine=jsMath" width="400" hieght="200"></iframe>
1.54 albertel 234:
1.67 albertel 235: </p>
236: <p> Convert to Images <br />
237: <br />
1.79 albertel 238: <iframe src="/res/adm/pages/math_example.tex?inhibitmenu=yes&texengine=mimetex" width="400" hieght="200"></iframe>
1.67 albertel 239: </p>
1.54 albertel 240: ENDLSCREEN
1.59 albertel 241: if ($env{'environment.texengine'} ne 'jsMath') {
1.55 albertel 242: $r->print('<script type="text/javascript">jsMath.Process()</script>');
243: }
1.54 albertel 244: }
245:
246:
247: sub verify_and_change_texengine {
248: my $r = shift;
1.59 albertel 249: my $user = $env{'user.name'};
250: my $domain = $env{'user.domain'};
1.54 albertel 251: # Screenname
1.59 albertel 252: my $newtexengine = $env{'form.texengine'};
1.54 albertel 253: $newtexengine=~s/[^\-\w]//g;
1.56 albertel 254: if ($newtexengine eq 'ttm') {
255: &Apache::lonnet::appenv('browser.mathml' => 1);
256: } else {
1.59 albertel 257: if ($env{'environment.texengine'} eq 'ttm') {
1.56 albertel 258: &Apache::lonnet::appenv('browser.mathml' => 0);
259: }
260: }
1.54 albertel 261: my $message='';
262: if ($newtexengine) {
263: &Apache::lonnet::put('environment',{'texengine' => $newtexengine});
264: &Apache::lonnet::appenv('environment.texengine' => $newtexengine);
265: $message='Set new preferred math display to '.$newtexengine;
266: } else {
267: &Apache::lonnet::del('environment',['texengine']);
268: &Apache::lonnet::delenv('environment\.texengine');
269: $message='Reset preferred math display.';
270: }
1.56 albertel 271:
272:
1.54 albertel 273: $r->print(<<ENDVCSCREEN);
274: $message
275: ENDVCSCREEN
276: }
277:
278: ################################################################
1.50 albertel 279: # Roles Page Preference Change Subroutines #
280: ################################################################
281: sub rolesprefchanger {
282: my $r = shift;
1.96 albertel 283: my $role = ($env{'user.adv'} ? 'Role' : 'Course');
284: my $lc_role = ($env{'user.adv'} ? 'role' : 'course');
1.59 albertel 285: my $user = $env{'user.name'};
286: my $domain = $env{'user.domain'};
1.50 albertel 287: my %userenv = &Apache::lonnet::get
288: ('environment',['recentroles','recentrolesn']);
289: my $hotlist_flag=$userenv{'recentroles'};
290: my $hotlist_n=$userenv{'recentrolesn'};
291: my $checked;
292: if ($hotlist_flag) {
293: $checked = 'checked="checked"';
294: }
295:
296: if (!$hotlist_n) { $hotlist_n=3; }
297: my $options;
298: for (my $i=1; $i<10; $i++) {
299: my $select;
300: if ($hotlist_n == $i) { $select = 'selected="selected"'; }
301: $options .= "<option $select>$i</option>\n";
302: }
303:
1.89 albertel 304: # Get list of recent roles and display with checkbox in front
305: my $roles_check_list = '';
306: my $role_key='';
307: if ($env{'environment.recentroles'}) {
308: my %recent_roles =
309: &Apache::lonhtmlcommon::get_recent('roles',$env{'environment.recentrolesn'});
1.91 albertel 310: my %frozen_roles =
311: &Apache::lonhtmlcommon::get_recent_frozen('roles',$env{'environment.recentrolesn'});
1.89 albertel 312:
1.93 albertel 313: my %role_text = &rolespref_get_role_text([keys(%recent_roles)]);
1.92 albertel 314: my @sorted_roles = sort {$role_text{$a} cmp $role_text{$b}} keys(%role_text);
315:
1.89 albertel 316: $roles_check_list .=
317: &Apache::loncommon::start_data_table().
318: &Apache::loncommon::start_data_table_header_row().
1.96 albertel 319: "<th>".&mt('Freeze '.$role)."</th>".
320: "<th>".&mt($role)."</td>".
1.89 albertel 321: &Apache::loncommon::end_data_table_header_row().
322: "\n";
323: my $count;
1.92 albertel 324: foreach $role_key (@sorted_roles) {
1.89 albertel 325: my $checked = "";
326: my $value = $recent_roles{$role_key};
1.91 albertel 327: if ($frozen_roles{$role_key}) {
1.89 albertel 328: $checked = "checked=\"checked\"";
329: }
330: $count++;
331: $roles_check_list .=
332: &Apache::loncommon::start_data_table_row().
333: '<td class="LC_table_cell_checkbox">'.
334: "<input type=\"checkbox\" $checked name=\"freezeroles\"".
335: " id=\"freezeroles$count\" value=\"$role_key\" /></td>".
336: "<td><label for=\"freezeroles$count\">".
1.92 albertel 337: "$role_text{$role_key}</label></td>".
1.89 albertel 338: &Apache::loncommon::end_data_table_row(). "\n";
339: }
340: $roles_check_list .= "</table>\n";
341: }
342:
343: $r->print('
1.96 albertel 344: <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 345: </p>
1.89 albertel 346: <form name="prefs" action="/adm/preferences" method="POST">
1.50 albertel 347: <input type="hidden" name="action" value="verify_and_change_rolespref" />
1.96 albertel 348: <br /><label>'.&mt('Enable Recent '.$role.'s Hotlist:').'
1.89 albertel 349: <input type="checkbox" '.$checked.' name="recentroles" value="true" /></label>
1.96 albertel 350: <br />'.&mt('Number of '.$role.'s in Hotlist:').'
1.50 albertel 351: <select name="recentrolesn" size="1">
1.89 albertel 352: '.$options.'
1.50 albertel 353: </select>
1.96 albertel 354: <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 355: </p>
356: '.$roles_check_list.'
1.50 albertel 357: <br />
1.89 albertel 358: <input type="submit" value="'.&mt('Change').'" />
359: </form>');
1.50 albertel 360: }
361:
1.92 albertel 362: sub rolespref_get_role_text {
363: # Get a line of text for each role
364: my ($roles) = @_;
365: my %roletext = ();
366:
367: foreach my $item (@$roles) {
368: # get course information
369: my ($role,$rest) = split(/\./, $item);
1.93 albertel 370: my $trole = "";
371: $trole = &Apache::lonnet::plaintext($role);
1.92 albertel 372: my ($tdomain,$other,$tsection)= split(/\//,Apache::lonnet::declutter($rest));
373: my $tother = '-';
1.93 albertel 374: if ($role =~ /^(cc|st|in|ta|ep|cr)/ ) {
1.92 albertel 375: my %newhash=&Apache::lonnet::coursedescription($tdomain."_".$other);
376: $tother = " - ".$newhash{'description'};
377: } elsif ($role =~ /dc/) {
378: $tother = "";
379: } else {
380: $tother = " - $other";
381: }
382:
383: my $section="";
384: if ($tsection) {
385: $section = " - Section/Group: $tsection";
386: }
387: $roletext{$item} = $tdomain." - ".$trole.$tother.$section;
388: }
389: return %roletext;
390: }
391:
1.50 albertel 392: sub verify_and_change_rolespref {
393: my $r = shift;
1.96 albertel 394: my $role = ($env{'user.adv'} ? 'Role' : 'Course');
1.59 albertel 395: my $user = $env{'user.name'};
396: my $domain = $env{'user.domain'};
1.50 albertel 397: # Recent Roles Hotlist Flag
1.59 albertel 398: my $hotlist_flag = $env{'form.recentroles'};
399: my $hotlist_n = $env{'form.recentrolesn'};
1.89 albertel 400: my $message='<hr />';
1.50 albertel 401: if ($hotlist_flag) {
402: &Apache::lonnet::put('environment',{'recentroles' => $hotlist_flag});
403: &Apache::lonnet::appenv('environment.recentroles' => $hotlist_flag);
1.96 albertel 404: $message=&mt('Recent '.$role.'s Hotlist is Enabled');
1.50 albertel 405: } else {
406: &Apache::lonnet::del('environment',['recentroles']);
407: &Apache::lonnet::delenv('environment\.recentroles');
1.96 albertel 408: $message=&mt('Recent '.$role.'s Hotlist is Disabled');
1.50 albertel 409: }
410: if ($hotlist_n) {
411: &Apache::lonnet::put('environment',{'recentrolesn' => $hotlist_n});
412: &Apache::lonnet::appenv('environment.recentrolesn' => $hotlist_n);
413: if ($hotlist_flag) {
1.90 albertel 414: $message.="<br />".
1.96 albertel 415: &mt('Display [_1] Most Recent '.$role.'s',$hotlist_n)."\n";
1.89 albertel 416: }
417: }
418:
419: # Get list of froze roles and list of recent roles
420: my @freeze_list = &Apache::loncommon::get_env_multiple('form.freezeroles');
421: my %freeze = ();
1.92 albertel 422: my %roletext = ();
423:
1.89 albertel 424: foreach my $key (@freeze_list) {
1.91 albertel 425: $freeze{$key}='1';
1.89 albertel 426: }
1.92 albertel 427:
1.89 albertel 428: my %recent_roles =
429: &Apache::lonhtmlcommon::get_recent('roles',$env{'environment.recentrolesn'});
1.91 albertel 430: my %frozen_roles =
431: &Apache::lonhtmlcommon::get_recent_frozen('roles',$env{'environment.recentrolesn'});
1.92 albertel 432: my %role_text = &rolespref_get_role_text([keys(%recent_roles)]);
1.89 albertel 433:
434: # Unset any roles that were previously frozen but aren't in list
435: foreach my $role_key (sort(keys(%recent_roles))) {
1.91 albertel 436: if (($frozen_roles{$role_key}) && (!exists($freeze{$role_key}))) {
1.96 albertel 437: $message .= "<br />".&mt('Unfreezing '.$role.': [_1]',$role_text{$role_key})."\n";
1.91 albertel 438: &Apache::lonhtmlcommon::store_recent('roles',$role_key,' ',0);
1.89 albertel 439: }
440: }
441:
442: # Freeze selected roles
443: foreach my $role_key (@freeze_list) {
1.91 albertel 444: if (!$frozen_roles{$role_key}) {
1.96 albertel 445: $message .= "<br />".&mt('Freezing '.$role.': [_1]',$role_text{$role_key})."\n";
1.89 albertel 446: &Apache::lonhtmlcommon::store_recent('roles',
1.91 albertel 447: $role_key,' ',1);
1.50 albertel 448: }
449: }
1.89 albertel 450: $message .= "<hr /><br />\n";
1.50 albertel 451:
452: $r->print(<<ENDRPSCREEN);
453: $message
454: ENDRPSCREEN
455: }
456:
457:
1.28 www 458:
459: ################################################################
1.9 matthew 460: # Anonymous Discussion Name Change Subroutines #
461: ################################################################
1.5 www 462: sub screennamechanger {
463: my $r = shift;
1.59 albertel 464: my $user = $env{'user.name'};
465: my $domain = $env{'user.domain'};
1.14 www 466: my %userenv = &Apache::lonnet::get
467: ('environment',['screenname','nickname']);
1.6 www 468: my $screenname=$userenv{'screenname'};
1.14 www 469: my $nickname=$userenv{'nickname'};
1.5 www 470: $r->print(<<ENDSCREEN);
1.88 albertel 471: <form name="prefs" action="/adm/preferences" method="post">
1.6 www 472: <input type="hidden" name="action" value="verify_and_change_screenname" />
1.14 www 473: <br />New screenname (shown if you post anonymously):
1.6 www 474: <input type="text" size="20" value="$screenname" name="screenname" />
1.14 www 475: <br />New nickname (shown if you post non-anonymously):
476: <input type="text" size="20" value="$nickname" name="nickname" />
1.6 www 477: <input type="submit" value="Change" />
478: </form>
1.5 www 479: ENDSCREEN
480: }
1.6 www 481:
482: sub verify_and_change_screenname {
483: my $r = shift;
1.59 albertel 484: my $user = $env{'user.name'};
485: my $domain = $env{'user.domain'};
1.14 www 486: # Screenname
1.59 albertel 487: my $newscreen = $env{'form.screenname'};
1.14 www 488: $newscreen=~s/[^ \w]//g;
1.6 www 489: my $message='';
490: if ($newscreen) {
1.7 www 491: &Apache::lonnet::put('environment',{'screenname' => $newscreen});
492: &Apache::lonnet::appenv('environment.screenname' => $newscreen);
1.6 www 493: $message='Set new screenname to '.$newscreen;
494: } else {
495: &Apache::lonnet::del('environment',['screenname']);
1.7 www 496: &Apache::lonnet::delenv('environment\.screenname');
1.6 www 497: $message='Reset screenname';
498: }
1.14 www 499: # Nickname
500: $message.='<br />';
1.59 albertel 501: $newscreen = $env{'form.nickname'};
1.14 www 502: $newscreen=~s/[^ \w]//g;
503: if ($newscreen) {
504: &Apache::lonnet::put('environment',{'nickname' => $newscreen});
505: &Apache::lonnet::appenv('environment.nickname' => $newscreen);
506: $message.='Set new nickname to '.$newscreen;
507: } else {
508: &Apache::lonnet::del('environment',['nickname']);
509: &Apache::lonnet::delenv('environment\.nickname');
510: $message.='Reset nickname';
511: }
1.68 www 512: &Apache::lonnet::devalidate_cache_new('namescache',$user.':'.$domain);
1.6 www 513: $r->print(<<ENDVCSCREEN);
514: $message
515: ENDVCSCREEN
1.20 www 516: }
517:
518: ################################################################
1.98 ! www 519: # Icon Subroutines #
! 520: ################################################################
! 521: sub iconchanger {
! 522: my $r = shift;
! 523: my $user = $env{'user.name'};
! 524: my $domain = $env{'user.domain'};
! 525: my %userenv = &Apache::lonnet::get
! 526: ('environment',['icons']);
! 527: my $iconic='checked="checked"';
! 528: my $classic='';
! 529: if ($userenv{'icons'} eq 'classic') {
! 530: $classic='checked="checked"';
! 531: $iconic='';
! 532: }
! 533: my $useicons=&mt('Use icons');
! 534: my $usebuttons=&mt('Use classic buttons');
! 535: my $change=&mt('Change');
! 536: $r->print(<<ENDSCREEN);
! 537: <form name="prefs" action="/adm/preferences" method="post">
! 538: <input type="hidden" name="action" value="verify_and_change_icons" />
! 539: <label><input type="radio" name="menumode" value="iconic" $iconic /> $useicons</label><br />
! 540: <label><input type="radio" name="menumode" value="classic" $classic /> $usebuttons</label><br />
! 541: <input type="submit" value="$change" />
! 542: </form>
! 543: ENDSCREEN
! 544: }
! 545:
! 546: sub verify_and_change_icons {
! 547: my $r = shift;
! 548: my $user = $env{'user.name'};
! 549: my $domain = $env{'user.domain'};
! 550: my $newicons = $env{'form.menumode'};
! 551:
! 552: &Apache::lonnet::put('environment',{'icons' => $newicons});
! 553: &Apache::lonnet::appenv('environment.icons' => $newicons);
! 554: $r->print(&mt('Set menu mode to [_1].',$newicons));
! 555: }
! 556:
! 557: ################################################################
1.20 www 558: # Message Forward #
559: ################################################################
560:
561: sub msgforwardchanger {
562: my $r = shift;
1.59 albertel 563: my $user = $env{'user.name'};
564: my $domain = $env{'user.domain'};
1.26 www 565: my %userenv = &Apache::lonnet::get('environment',['msgforward','notification','critnotification']);
1.20 www 566: my $msgforward=$userenv{'msgforward'};
567: my $notification=$userenv{'notification'};
568: my $critnotification=$userenv{'critnotification'};
1.25 bowersj2 569: my $forwardingHelp = Apache::loncommon::help_open_topic("Prefs_Forwarding",
570: "What are forwarding ".
571: "and notification ".
572: "addresses");
1.27 bowersj2 573: my $criticalMessageHelp = Apache::loncommon::help_open_topic("Course_Critical_Message",
574: "What are critical messages");
575:
1.20 www 576: $r->print(<<ENDMSG);
1.25 bowersj2 577: $forwardingHelp <br />
1.88 albertel 578: <form name="prefs" action="/adm/preferences" method="post">
1.20 www 579: <input type="hidden" name="action" value="verify_and_change_msgforward" />
580: New Forwarding Address(es) (<tt>user:domain,user:domain,...</tt>):
581: <input type="text" size="40" value="$msgforward" name="msgforward" /><hr />
582: New Message Notification Email Address(es) (<tt>joe\@doe.com,jane\@doe.edu,...</tt>):
583: <input type="text" size="40" value="$notification" name="notification" /><hr />
584: New Critical Message Notification Email Address(es) (<tt>joe\@doe.com,jane\@doe.edu,...</tt>):
1.27 bowersj2 585: <input type="text" size="40" value="$critnotification" name="critnotification" />$criticalMessageHelp<hr />
1.20 www 586: <input type="submit" value="Change" />
587: </form>
588: ENDMSG
589: }
590:
591: sub verify_and_change_msgforward {
592: my $r = shift;
1.59 albertel 593: my $user = $env{'user.name'};
594: my $domain = $env{'user.domain'};
1.20 www 595: my $newscreen = '';
596: my $message='';
1.59 albertel 597: foreach (split(/\,/,$env{'form.msgforward'})) {
1.20 www 598: my ($msuser,$msdomain)=split(/[\@\:]/,$_);
1.95 albertel 599: $msuser = &LONCAPA::clean_username($msuser);
600: $msdomain = &LONCAPA::clean_domain($msdomain);
1.20 www 601: if (($msuser) && ($msdomain)) {
602: if (&Apache::lonnet::homeserver($msuser,$msdomain) ne 'no_host') {
603: $newscreen.=$msuser.':'.$msdomain.',';
604: } else {
605: $message.='No such user: '.$msuser.':'.$msdomain.'<br>';
606: }
607: }
608: }
609: $newscreen=~s/\,$//;
610: if ($newscreen) {
611: &Apache::lonnet::put('environment',{'msgforward' => $newscreen});
612: &Apache::lonnet::appenv('environment.msgforward' => $newscreen);
613: $message.='Set new message forwarding to '.$newscreen.'<br />';
614: } else {
615: &Apache::lonnet::del('environment',['msgforward']);
616: &Apache::lonnet::delenv('environment\.msgforward');
617: $message.='Reset message forwarding<br />';
618: }
1.59 albertel 619: my $notification=$env{'form.notification'};
1.20 www 620: $notification=~s/\s//gs;
621: if ($notification) {
622: &Apache::lonnet::put('environment',{'notification' => $notification});
623: &Apache::lonnet::appenv('environment.notification' => $notification);
624: $message.='Set message notification address to '.$notification.'<br />';
625: } else {
626: &Apache::lonnet::del('environment',['notification']);
627: &Apache::lonnet::delenv('environment\.notification');
628: $message.='Reset message notification<br />';
629: }
1.59 albertel 630: my $critnotification=$env{'form.critnotification'};
1.20 www 631: $critnotification=~s/\s//gs;
632: if ($critnotification) {
633: &Apache::lonnet::put('environment',{'critnotification' => $critnotification});
634: &Apache::lonnet::appenv('environment.critnotification' => $critnotification);
635: $message.='Set critical message notification address to '.$critnotification;
636: } else {
637: &Apache::lonnet::del('environment',['critnotification']);
638: &Apache::lonnet::delenv('environment\.critnotification');
639: $message.='Reset critical message notification<br />';
640: }
641: $r->print(<<ENDVCMSG);
642: $message
643: ENDVCMSG
1.6 www 644: }
645:
1.12 www 646: ################################################################
1.19 www 647: # Colors #
1.12 www 648: ################################################################
649:
1.19 www 650: sub colorschanger {
1.12 www 651: my $r = shift;
1.19 www 652: # figure out colors
1.80 albertel 653: my $function=&Apache::loncommon::get_users_function();
1.19 www 654: my $domain=&Apache::loncommon::determinedomain();
655: my %colortypes=('pgbg' => 'Page Background',
656: 'tabbg' => 'Header Background',
657: 'sidebg'=> 'Header Border',
658: 'font' => 'Font',
659: 'link' => 'Un-Visited Link',
660: 'vlink' => 'Visited Link',
661: 'alink' => 'Active Link');
1.82 albertel 662: my $start_data_table = &Apache::loncommon::start_data_table();
1.19 www 663: my $chtable='';
1.22 matthew 664: foreach my $item (sort(keys(%colortypes))) {
1.19 www 665: my $curcol=&Apache::loncommon::designparm($function.'.'.$item,$domain);
1.82 albertel 666: $chtable.=&Apache::loncommon::start_data_table_row().
1.83 albertel 667: '<td>'.$colortypes{$item}.'</td><td style="background: '.$curcol.
1.19 www 668: '"> </td><td><input name="'.$item.
1.21 www 669: '" size="10" value="'.$curcol.
670: '" /></td><td><a href="javascript:pjump('."'color_custom','".$colortypes{$item}.
1.19 www 671: "','".$curcol."','"
1.82 albertel 672: .$item."','parmform.pres','psub'".');">Select</a></td>'.
1.83 albertel 673: &Apache::loncommon::end_data_table_row()."\n";
1.19 www 674: }
1.82 albertel 675: my $end_data_table = &Apache::loncommon::end_data_table();
1.23 matthew 676: my $pjump_def = &Apache::lonhtmlcommon::pjump_javascript_definition();
1.19 www 677: $r->print(<<ENDCOL);
1.82 albertel 678: <script type="text/javascript">
1.19 www 679:
680: function pclose() {
681: parmwin=window.open("/adm/rat/empty.html","LONCAPAparms",
682: "height=350,width=350,scrollbars=no,menubar=no");
683: parmwin.close();
684: }
685:
1.23 matthew 686: $pjump_def
1.19 www 687:
688: function psub() {
689: pclose();
690: if (document.parmform.pres_marker.value!='') {
1.21 www 691: if (document.parmform.pres_type.value!='') {
1.77 albertel 692: eval('document.prefs.'+
1.21 www 693: document.parmform.pres_marker.value+
1.19 www 694: '.value=document.parmform.pres_value.value;');
1.21 www 695: }
1.19 www 696: } else {
697: document.parmform.pres_value.value='';
698: document.parmform.pres_marker.value='';
699: }
700: }
701:
702:
703: </script>
1.21 www 704: <form name="parmform">
705: <input type="hidden" name="pres_marker" />
706: <input type="hidden" name="pres_type" />
707: <input type="hidden" name="pres_value" />
708: </form>
1.88 albertel 709: <form name="prefs" action="/adm/preferences" method="post">
1.19 www 710: <input type="hidden" name="action" value="verify_and_change_colors" />
1.82 albertel 711: $start_data_table
1.19 www 712: $chtable
1.82 albertel 713: $end_data_table
1.19 www 714: </table>
1.21 www 715: <input type="submit" value="Change Custom Colors" />
716: <input type="submit" name="resetall" value="Reset All Colors to Default" />
1.12 www 717: </form>
1.19 www 718: ENDCOL
1.12 www 719: }
720:
1.19 www 721: sub verify_and_change_colors {
1.12 www 722: my $r = shift;
1.19 www 723: # figure out colors
1.80 albertel 724: my $function=&Apache::loncommon::get_users_function();
1.19 www 725: my $domain=&Apache::loncommon::determinedomain();
726: my %colortypes=('pgbg' => 'Page Background',
727: 'tabbg' => 'Header Background',
728: 'sidebg'=> 'Header Border',
729: 'font' => 'Font',
730: 'link' => 'Un-Visited Link',
731: 'vlink' => 'Visited Link',
732: 'alink' => 'Active Link');
733:
1.12 www 734: my $message='';
1.21 www 735: foreach my $item (keys %colortypes) {
1.59 albertel 736: my $color=$env{'form.'.$item};
1.21 www 737: my $entry='color.'.$function.'.'.$item;
1.59 albertel 738: if (($color=~/^\#[0-9A-Fa-f]{6}$/) && (!$env{'form.resetall'})) {
1.21 www 739: &Apache::lonnet::put('environment',{$entry => $color});
740: &Apache::lonnet::appenv('environment.'.$entry => $color);
741: $message.='Set '.$colortypes{$item}.' to '.$color.'<br />';
742: } else {
743: &Apache::lonnet::del('environment',[$entry]);
744: &Apache::lonnet::delenv('environment\.'.$entry);
745: $message.='Reset '.$colortypes{$item}.'<br />';
746: }
747: }
1.84 albertel 748: my $now = time;
749: &Apache::lonnet::put('environment',{'color.timestamp' => $now});
750: &Apache::lonnet::appenv('environment.color.timestamp' => $now);
751:
1.19 www 752: $r->print(<<ENDVCCOL);
1.12 www 753: $message
1.88 albertel 754: <form name="client" action="/adm/preferences" method="post">
1.21 www 755: <input type="hidden" name="action" value="changecolors" />
756: </form>
1.19 www 757: ENDVCCOL
1.12 www 758: }
759:
1.4 matthew 760: ######################################################
761: # password handler subroutines #
762: ######################################################
1.3 matthew 763: sub passwordchanger {
1.94 raeburn 764: my ($r,$errormessage,$caller,$mailtoken) = @_;
1.4 matthew 765: # This function is a bit of a mess....
1.3 matthew 766: # Passwords are encrypted using londes.js (DES encryption)
1.4 matthew 767: $errormessage = ($errormessage || '');
1.94 raeburn 768: my ($user,$domain,$currentpass,$defdom);
769: if ((!defined($caller)) || ($caller eq 'preferences')) {
770: $user = $env{'user.name'};
771: $domain = $env{'user.domain'};
772: if (!defined($caller)) {
773: $caller = 'preferences';
774: }
775: } elsif ($caller eq 'reset_by_email') {
776: $defdom = $r->dir_config('lonDefDomain');
777: my %data = &Apache::lonnet::tmpget($mailtoken);
778: if (keys(%data) == 0) {
779: $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.'));
780: return;
781: }
782: if (defined($data{time})) {
783: if (time - $data{'time'} < 7200) {
784: $user = $data{'username'};
785: $domain = $data{'domain'};
786: $currentpass = $data{'temppasswd'};
787: } else {
788: $r->print(&mt('Sorry, the token generated when you requested a password reset has expired.').'<br />');
789: return;
790: }
791: } else {
792: $r->print(&mt('Sorry, the URL generated when you requested reset of your password contained incomplete information.').'<br />');
793: return;
794: }
795: } else {
796: $r->print(&mt('Page requested in unexpected context').'<br />');
797: return;
798: }
1.3 matthew 799: my $currentauth=&Apache::lonnet::queryauthenticate($user,$domain);
800: # Check for authentication types that allow changing of the password.
801: return if ($currentauth !~ /^(unix|internal):/);
802: #
803: # Generate keys
804: my ($lkey_cpass ,$ukey_cpass ) = &des_keys();
805: my ($lkey_npass1,$ukey_npass1) = &des_keys();
806: my ($lkey_npass2,$ukey_npass2) = &des_keys();
1.4 matthew 807: # Store the keys in the log files
1.3 matthew 808: my $lonhost = $r->dir_config('lonHostID');
809: my $logtoken=Apache::lonnet::reply('tmpput:'
810: .$ukey_cpass . $lkey_cpass .'&'
811: .$ukey_npass1 . $lkey_npass1.'&'
812: .$ukey_npass2 . $lkey_npass2,
813: $lonhost);
1.4 matthew 814: # Hexify the keys for output as javascript variables
1.94 raeburn 815: my %hexkey;
816: $hexkey{'ukey_cpass'} = hex($ukey_cpass);
817: $hexkey{'lkey_cpass'} = hex($lkey_cpass);
818: $hexkey{'ukey_npass1'} = hex($ukey_npass1);
819: $hexkey{'lkey_npass1'} = hex($lkey_npass1);
820: $hexkey{'ukey_npass2'} = hex($ukey_npass2);
821: $hexkey{'lkey_npass2'} = hex($lkey_npass2);
1.3 matthew 822: # Output javascript to deal with passwords
1.4 matthew 823: # Output DES javascript
1.3 matthew 824: {
825: my $include = $r->dir_config('lonIncludes');
826: my $jsh=Apache::File->new($include."/londes.js");
827: $r->print(<$jsh>);
828: }
1.94 raeburn 829: $r->print(&jscript_send($caller));
1.3 matthew 830: $r->print(<<ENDFORM);
1.94 raeburn 831: $errormessage
832:
833: <p>
834: <!-- We separate the forms into 'server' and 'client' in order to
835: ensure that unencrypted passwords will not be sent out by a
836: crappy browser -->
837: ENDFORM
838: $r->print(&server_form($logtoken,$caller,$mailtoken));
839: $r->print(&client_form($caller,\%hexkey,$currentpass,$defdom));
840:
841: #
842: return;
843: }
844:
845: sub jscript_send {
846: my ($caller) = @_;
847: my $output = qq|
1.3 matthew 848: <script language="JavaScript">
849:
850: function send() {
851: uextkey=this.document.client.elements.ukey_cpass.value;
852: lextkey=this.document.client.elements.lkey_cpass.value;
853: initkeys();
854:
1.52 raeburn 855: this.document.pserver.elements.currentpass.value
1.3 matthew 856: =crypted(this.document.client.elements.currentpass.value);
857:
858: uextkey=this.document.client.elements.ukey_npass1.value;
859: lextkey=this.document.client.elements.lkey_npass1.value;
860: initkeys();
1.52 raeburn 861: this.document.pserver.elements.newpass_1.value
1.3 matthew 862: =crypted(this.document.client.elements.newpass_1.value);
863:
864: uextkey=this.document.client.elements.ukey_npass2.value;
865: lextkey=this.document.client.elements.lkey_npass2.value;
866: initkeys();
1.52 raeburn 867: this.document.pserver.elements.newpass_2.value
1.3 matthew 868: =crypted(this.document.client.elements.newpass_2.value);
1.94 raeburn 869: |;
870: if ($caller eq 'reset_by_email') {
871: $output .= qq|
872: this.document.pserver.elements.uname.value =
873: this.document.client.elements.uname.value;
874: this.document.pserver.elements.udom.value =
875: this.document.client.elements.udom.options[this.document.client.elements.udom.selectedIndex].value;
876: |;
877: }
878: $ output .= qq|
1.52 raeburn 879: this.document.pserver.submit();
1.3 matthew 880: }
881: </script>
1.94 raeburn 882: |;
883: }
1.3 matthew 884:
1.94 raeburn 885: sub client_form {
886: my ($caller,$hexkey,$currentpass,$defdom) = @_;
887: my $output = qq|
1.3 matthew 888: <form name="client" >
889: <table>
1.94 raeburn 890: |;
891: if ($caller eq 'reset_by_email') {
892: $output .= qq|
893: <tr><td align="right"> E-mail address: </td>
1.97 raeburn 894: <td><input type="text" name="email" size="30" /> </td></tr>
1.94 raeburn 895: <tr><td align="right"> Username: </td>
896: <td>
1.97 raeburn 897: <input type="text" name="uname" size="15" />
1.94 raeburn 898: <input type="hidden" name="currentpass" value="$currentpass" />
899: </td></tr>
900: <tr><td align="right"> Domain: </td>
901: <td>
902: |;
903: $output .= &Apache::loncommon::select_dom_form($defdom,'udom').'
904: </td>
905: </tr>
906: ';
907: } else {
908: $output .= qq|
1.4 matthew 909: <tr><td align="right"> Current password: </td>
910: <td><input type="password" name="currentpass" size="10"/> </td></tr>
1.94 raeburn 911: |;
912: }
913: $output .= <<"ENDFORM";
1.4 matthew 914: <tr><td align="right"> New password: </td>
915: <td><input type="password" name="newpass_1" size="10" /> </td></tr>
916: <tr><td align="right"> Confirm password: </td>
917: <td><input type="password" name="newpass_2" size="10" /> </td></tr>
1.3 matthew 918: <tr><td colspan="2" align="center">
919: <input type="button" value="Change Password" onClick="send();">
920: </table>
1.94 raeburn 921: <input type="hidden" name="ukey_cpass" value="$hexkey->{'ukey_cpass'}" />
922: <input type="hidden" name="lkey_cpass" value="$hexkey->{'lkey_cpass'}" />
923: <input type="hidden" name="ukey_npass1" value="$hexkey->{'ukey_npass1'}" />
924: <input type="hidden" name="lkey_npass1" value="$hexkey->{'lkey_npass1'}" />
925: <input type="hidden" name="ukey_npass2" value="$hexkey->{'ukey_npass2'}" />
926: <input type="hidden" name="lkey_npass2" value="$hexkey->{'lkey_npass2'}" />
1.3 matthew 927: </form>
928: </p>
929: ENDFORM
1.94 raeburn 930: return $output;
931: }
932:
933: sub server_form {
934: my ($logtoken,$caller,$mailtoken) = @_;
935: my $action = '/adm/preferences';
936: if ($caller eq 'reset_by_email') {
937: $action = '/adm/resetpw';
938: }
939: my $output = qq|
940: <form name="pserver" action="$action" method="post">
941: <input type="hidden" name="logtoken" value="$logtoken" />
942: <input type="hidden" name="currentpass" value="" />
943: <input type="hidden" name="newpass_1" value="" />
944: <input type="hidden" name="newpass_2" value="" />
945: |;
946: if ($caller eq 'reset_by_email') {
947: $output .= qq|
948: <input type="hidden" name="token" value="$mailtoken" />
949: <input type="hidden" name="uname" value="" />
950: <input type="hidden" name="udom" value="" />
951:
952: |;
953: }
954: $output .= qq|
955: <input type="hidden" name="action" value="verify_and_change_pass" />
956: </form>
957: |;
958: return $output;
1.3 matthew 959: }
960:
961: sub verify_and_change_password {
1.94 raeburn 962: my ($r,$caller,$mailtoken) = @_;
963: my ($user,$domain,$homeserver);
964: if ($caller eq 'reset_by_email') {
965: $user = $env{'form.uname'};
966: $domain = $env{'form.udom'};
967: if ($user ne '' && $domain ne '') {
968: $homeserver = &Apache::lonnet::homeserver($user,$domain);
969: if ($homeserver eq 'no_host') {
970: &passwordchanger($r,"<p>\n<font color='#ff0000'>ERROR</font>".
971: "Invalid username and/or domain .\n</p>",
972: $caller,$mailtoken);
973: return 1;
974: }
975: } else {
976: &passwordchanger($r,"<p>\n<font color='#ff0000'>ERROR</font>".
977: "Username and Domain were blank.\n</p>",
978: $caller,$mailtoken);
979: return 1;
980: }
981: } else {
982: $user = $env{'user.name'};
983: $domain = $env{'user.domain'};
984: $homeserver = $env{'user.home'};
985: }
1.3 matthew 986: my $currentauth=&Apache::lonnet::queryauthenticate($user,$domain);
1.4 matthew 987: # Check for authentication types that allow changing of the password.
1.94 raeburn 988: if ($currentauth !~ /^(unix|internal):/) {
989: if ($caller eq 'reset_by_email') {
990: &passwordchanger($r,"<p>\n<font color='#ff0000'>ERROR</font>".
991: "Authentication type for this user can not be changed by this mechanism..\n</p>",
992: $caller,$mailtoken);
993: return 1;
994: } else {
995: return;
996: }
997: }
1.3 matthew 998: #
1.59 albertel 999: my $currentpass = $env{'form.currentpass'};
1000: my $newpass1 = $env{'form.newpass_1'};
1001: my $newpass2 = $env{'form.newpass_2'};
1002: my $logtoken = $env{'form.logtoken'};
1.3 matthew 1003: # Check for empty data
1.4 matthew 1004: unless (defined($currentpass) &&
1005: defined($newpass1) &&
1006: defined($newpass2) ){
1007: &passwordchanger($r,"<p>\n<font color='#ff0000'>ERROR</font>".
1.94 raeburn 1008: "One or more password fields were blank.\n</p>",$caller,$mailtoken);
1.3 matthew 1009: return;
1010: }
1.16 albertel 1011: # Get the keys
1012: my $lonhost = $r->dir_config('lonHostID');
1.3 matthew 1013: my $tmpinfo = Apache::lonnet::reply('tmpget:'.$logtoken,$lonhost);
1014: if (($tmpinfo=~/^error/) || ($tmpinfo eq 'con_lost')) {
1.4 matthew 1015: # I do not a have a better idea about how to handle this
1.94 raeburn 1016: my $tryagain_text = &mt('Please log out and try again.');
1017: if ($caller eq 'reset_by_email') {
1018: $tryagain_text = &mt('Please try again later.');
1019: }
1.3 matthew 1020: $r->print(<<ENDERROR);
1021: <p>
1022: <font color="#ff0000">ERROR:</font> Unable to retrieve stored token for
1.94 raeburn 1023: password decryption. $tryagain_text
1.3 matthew 1024: </p>
1025: ENDERROR
1.4 matthew 1026: # Probably should log an error here
1.75 albertel 1027: return 1;
1.3 matthew 1028: }
1029: my ($ckey,$n1key,$n2key)=split(/&/,$tmpinfo);
1.4 matthew 1030: #
1.17 matthew 1031: $currentpass = &des_decrypt($ckey ,$currentpass);
1032: $newpass1 = &des_decrypt($n1key,$newpass1);
1033: $newpass2 = &des_decrypt($n2key,$newpass2);
1.94 raeburn 1034: #
1035: if ($caller eq 'reset_by_email') {
1036: my %data = &Apache::lonnet::tmpget($mailtoken);
1037: if ($currentpass ne $data{'temppasswd'}) {
1038: &passwordchanger($r,
1039: '<font color="#ff0000">ERROR:</font>'.
1040: 'Could not verify current authentication. '.
1041: 'Please try again.',$caller,$mailtoken);
1042: return 1;
1043: }
1044: }
1.3 matthew 1045: if ($newpass1 ne $newpass2) {
1.4 matthew 1046: &passwordchanger($r,
1047: '<font color="#ff0000">ERROR:</font>'.
1048: 'The new passwords you entered do not match. '.
1.94 raeburn 1049: 'Please try again.',$caller,$mailtoken);
1.75 albertel 1050: return 1;
1.4 matthew 1051: }
1052: if (length($newpass1) < 7) {
1053: &passwordchanger($r,
1054: '<font color="#ff0000">ERROR:</font>'.
1055: 'Passwords must be a minimum of 7 characters long. '.
1.94 raeburn 1056: 'Please try again.',$caller,$mailtoken);
1.75 albertel 1057: return 1;
1.3 matthew 1058: }
1.4 matthew 1059: #
1060: # Check for bad characters
1061: my $badpassword = 0;
1062: foreach (split(//,$newpass1)) {
1063: $badpassword = 1 if ((ord($_)<32)||(ord($_)>126));
1064: }
1065: if ($badpassword) {
1066: # I can't figure out how to enter bad characters on my browser.
1.94 raeburn 1067: my $errormessage = <<"ENDERROR";
1.4 matthew 1068: <font color="#ff0000">ERROR:</font>
1069: The password you entered contained illegal characters.<br />
1070: Valid characters are: space and <br />
1071: <pre>
1072: !"\#$%&\'()*+,-./0123456789:;<=>?\@
1073: ABCDEFGHIJKLMNOPQRSTUVWXYZ[\]^_\`abcdefghijklmnopqrstuvwxyz{|}~
1074: </pre>
1075: ENDERROR
1.94 raeburn 1076: &passwordchanger($r,$errormessage,$caller,$mailtoken);
1077: return 1;
1.4 matthew 1078: }
1079: #
1080: # Change the password (finally)
1081: my $result = &Apache::lonnet::changepass
1.94 raeburn 1082: ($user,$domain,$currentpass,$newpass1,$homeserver,$caller);
1.4 matthew 1083: # Inform the user the password has (not?) been changed
1084: if ($result =~ /^ok$/) {
1085: $r->print(<<"ENDTEXT");
1.94 raeburn 1086: <h3>The password for $user was successfully changed</h3>
1.4 matthew 1087: ENDTEXT
1088: } else {
1089: # error error: run in circles, scream and shout
1090: $r->print(<<ENDERROR);
1.94 raeburn 1091: <h3><font color="#ff0000">The password for $user was not changed</font></h3>
1.8 matthew 1092: Please make sure your old password was entered correctly.
1.4 matthew 1093: ENDERROR
1.75 albertel 1094: return 1;
1.4 matthew 1095: }
1096: return;
1.3 matthew 1097: }
1098:
1.42 raeburn 1099: ################################################################
1100: # discussion display subroutines
1101: ################################################################
1102: sub discussionchanger {
1103: my $r = shift;
1.59 albertel 1104: my $user = $env{'user.name'};
1105: my $domain = $env{'user.domain'};
1.42 raeburn 1106: my %userenv = &Apache::lonnet::get
1.43 raeburn 1107: ('environment',['discdisplay','discmarkread']);
1108: my $discdisp = 'allposts';
1109: my $discmark = 'onmark';
1110:
1111: if (defined($userenv{'discdisplay'})) {
1112: unless ($userenv{'discdisplay'} eq '') {
1113: $discdisp = $userenv{'discdisplay'};
1114: }
1115: }
1116: if (defined($userenv{'discmarkread'})) {
1117: unless ($userenv{'discdisplay'} eq '') {
1118: $discmark = $userenv{'discmarkread'};
1119: }
1120: }
1121:
1122: my $newdisp = 'unread';
1123: my $newmark = 'ondisp';
1124:
1125: my $function = &Apache::loncommon::get_users_function();
1126: my $color = &Apache::loncommon::designparm($function.'.tabbg',
1.59 albertel 1127: $env{'user.domain'});
1.43 raeburn 1128: my %lt = &Apache::lonlocal::texthash(
1129: 'pref' => 'Display Preference',
1130: 'curr' => 'Current setting ',
1131: 'actn' => 'Action',
1132: 'sdpf' => 'Set display preferences for discussion posts for both bulletin boards and individual resources in all your courses.',
1133: 'prca' => 'Preferences can be set that determine',
1134: 'whpo' => 'Which posts are displayed when you display a bulletin board or resource, and',
1135: 'unwh' => 'Under what circumstances posts are identfied as "New"',
1136: 'allposts' => 'All posts',
1137: 'unread' => 'New posts only',
1138: 'ondisp' => 'Once displayed',
1139: 'onmark' => 'Once marked as read',
1140: 'disa' => 'Posts displayed?',
1141: 'npmr' => 'New posts cease to be identified as "New"?',
1142: 'thde' => 'The preferences you set here can be overridden within each individual discussion.',
1143: 'chgt' => 'Change to '
1144: );
1145: my $dispchange = $lt{'unread'};
1146: my $markchange = $lt{'ondisp'};
1147: my $currdisp = $lt{'allposts'};
1148: my $currmark = $lt{'onmark'};
1149:
1150: if ($discdisp eq 'unread') {
1151: $dispchange = $lt{'allposts'};
1152: $currdisp = $lt{'unread'};
1153: $newdisp = 'allposts';
1154: }
1155:
1156: if ($discmark eq 'ondisp') {
1157: $markchange = $lt{'onmark'};
1158: $currmark = $lt{'ondisp'};
1159: $newmark = 'onmark';
1.42 raeburn 1160: }
1.43 raeburn 1161:
1162: $r->print(<<"END");
1.88 albertel 1163: <form name="prefs" action="/adm/preferences" method="post">
1.42 raeburn 1164: <input type="hidden" name="action" value="verify_and_change_discussion" />
1165: <br />
1.87 albertel 1166: $lt{'sdpf'}<br /> $lt{'prca'} <ol><li>$lt{'whpo'}</li><li>$lt{'unwh'}</li></ol>
1.43 raeburn 1167: <br />
1168: <br />
1.82 albertel 1169: END
1170: $r->print(&Apache::loncommon::start_data_table());
1171: $r->print(<<"END");
1172: <tr>
1173: <th>$lt{'pref'}</th>
1174: <th>$lt{'curr'}</th>
1175: <th>$lt{'actn'}?</th>
1.43 raeburn 1176: </tr>
1.82 albertel 1177: END
1178: $r->print(&Apache::loncommon::start_data_table_row());
1179: $r->print(<<"END");
1.43 raeburn 1180: <td>$lt{'disa'}</td>
1181: <td>$lt{$discdisp}</td>
1.82 albertel 1182: <td><label><input type="checkbox" name="discdisp" /><input type="hidden" name="newdisp" value="$newdisp" /> $lt{'chgt'} "$dispchange"</label></td>
1183: END
1184: $r->print(&Apache::loncommon::end_data_table_row().
1185: &Apache::loncommon::start_data_table_row());
1186: $r->print(<<"END");
1.43 raeburn 1187: <td>$lt{'npmr'}</td>
1188: <td>$lt{$discmark}</td>
1.82 albertel 1189: <td><label><input type="checkbox" name="discmark" /><input type="hidden" name="newmark" value="$newmark" /> $lt{'chgt'} "$markchange"</label></td>
1.43 raeburn 1190: </tr>
1.82 albertel 1191: END
1192: $r->print(&Apache::loncommon::end_data_table_row().
1193: &Apache::loncommon::end_data_table());
1194: $r->print(<<"END");
1.43 raeburn 1195: <br />
1196: <br />
1197: <input type="submit" name="sub" value="Store Changes" />
1198: <br />
1199: <br />
1200: Note: $lt{'thde'}
1201: </form>
1202: END
1.42 raeburn 1203: }
1204:
1205: sub verify_and_change_discussion {
1206: my $r = shift;
1.59 albertel 1207: my $user = $env{'user.name'};
1208: my $domain = $env{'user.domain'};
1.42 raeburn 1209: my $message='';
1.59 albertel 1210: if (defined($env{'form.discdisp'}) ) {
1211: my $newdisp = $env{'form.newdisp'};
1.43 raeburn 1212: if ($newdisp eq 'unread') {
1.87 albertel 1213: $message .='In discussions: only new posts will be displayed.<br />';
1.43 raeburn 1214: &Apache::lonnet::put('environment',{'discdisplay' => $newdisp});
1215: &Apache::lonnet::appenv('environment.discdisplay' => $newdisp);
1216: } else {
1.87 albertel 1217: $message .= 'In discussions: all posts will be displayed.<br />';
1.43 raeburn 1218: &Apache::lonnet::del('environment',['discdisplay']);
1219: &Apache::lonnet::delenv('environment\.discdisplay');
1220: }
1221: }
1.59 albertel 1222: if (defined($env{'form.discmark'}) ) {
1223: my $newmark = $env{'form.newmark'};
1.43 raeburn 1224: if ($newmark eq 'ondisp') {
1.87 albertel 1225: $message.='In discussions: new posts will be cease to be identified as "new" after display.<br />';
1.43 raeburn 1226: &Apache::lonnet::put('environment',{'discmarkread' => $newmark});
1227: &Apache::lonnet::appenv('environment.discmarkread' => $newmark);
1228: } else {
1.87 albertel 1229: $message.='In discussions: posts will be identified as "new" until marked as read by the reader.<br />';
1.43 raeburn 1230: &Apache::lonnet::del('environment',['discmarkread']);
1231: &Apache::lonnet::delenv('environment\.discmarkread');
1232: }
1.42 raeburn 1233: }
1234: $r->print(<<ENDVCSCREEN);
1235: $message
1236: ENDVCSCREEN
1237: }
1238:
1.63 raeburn 1239: ################################################################
1240: # Subroutines for page display on course access (Course Coordinators)
1241: ################################################################
1242: sub coursedisplaychanger {
1243: my $r = shift;
1244: my $user = $env{'user.name'};
1245: my $domain = $env{'user.domain'};
1.66 albertel 1246: my %userenv = &Apache::lonnet::get('environment',['course_init_display']);
1.71 raeburn 1247: my $currvalue = 'whatsnew';
1.73 albertel 1248: my $firstselect = '';
1249: my $whatsnewselect = 'checked="checked"';
1.71 raeburn 1250: if (exists($userenv{'course_init_display'})) {
1251: if ($userenv{'course_init_display'} eq 'firstres') {
1252: $currvalue = 'firstres';
1.73 albertel 1253: $firstselect = 'checked="checked"';
1254: $whatsnewselect = '';
1.71 raeburn 1255: }
1.63 raeburn 1256: }
1.71 raeburn 1257: my %pagenames = (
1258: firstres => 'First resource',
1259: whatsnew => "What's new page",
1260: );
1.70 raeburn 1261: my $whatsnew_off=&mt('Display the [_1] in the course.','<b>first resource</b>');
1262: 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 1263:
1.71 raeburn 1264: $r->print('<br /><b>'.&mt('Set the default page to be displayed when you select a course role').'</b> '.&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 1265: $r->print(<<ENDLSCREEN);
1.88 albertel 1266: <form name="prefs" action="/adm/preferences" method="post">
1.63 raeburn 1267: <input type="hidden" name="action" value="verify_and_change_coursepage" />
1.72 albertel 1268: <br />
1.65 albertel 1269: <label><input type="radio" name="newdisp" value="firstres" $firstselect /> $whatsnew_off</label><br />
1.70 raeburn 1270: <label><input type="radio" name="newdisp" value="whatsnew" $whatsnewselect /> $whatsnew_on</label><input type="hidden" name="refpage" value="$env{'form.refpage'}" />
1.63 raeburn 1271: ENDLSCREEN
1.70 raeburn 1272: $r->print('<br /><br /><input type="submit" value="'.&mt('Change').'" />
1.63 raeburn 1273: </form>');
1274: }
1275:
1276: sub verify_and_change_coursepage {
1277: my $r = shift;
1278: my $message='';
1279: my %lt = &Apache::lonlocal::texthash(
1.70 raeburn 1280: 'defs' => 'Default now set',
1.71 raeburn 1281: 'when' => 'when you select a course role from the roles screen',
1.63 raeburn 1282: 'ywbt' => 'you will be taken to the start of the course.',
1283: 'apwb' => 'a page will be displayed that lists items in the course that may require action from you.',
1284: 'gtts' => 'Go to the start of the course',
1.70 raeburn 1285: 'dasp' => "Display the What's New page listing course action items",
1.63 raeburn 1286: );
1287: my $newdisp = $env{'form.newdisp'};
1.70 raeburn 1288: $message = '<b>'.$lt{'defs'}.'</b>: '.$lt{'when'}.', ';
1.63 raeburn 1289: if ($newdisp eq 'firstres') {
1.87 albertel 1290: $message .= $lt{'ywbt'}.'<br />';
1.63 raeburn 1291: &Apache::lonnet::put('environment',{'course_init_display' => $newdisp});
1292: &Apache::lonnet::appenv('environment.course_init_display' => $newdisp);
1293: } else {
1.87 albertel 1294: $message .= $lt{'apwb'}.'<br />';
1.63 raeburn 1295: &Apache::lonnet::del('environment',['course_init_display']);
1296: &Apache::lonnet::delenv('environment\.course_init_display');
1297: }
1.70 raeburn 1298: my $refpage = $env{'form.refpage'};
1.63 raeburn 1299: if (($env{'request.course.fn'}) && ($env{'request.course.id'})) {
1300: if ($newdisp eq 'firstres') {
1301: my $cdom = $env{'course.'.$env{'request.course.id'}.'.domain'};
1302: my $cnum = $env{'course.'.$env{'request.course.id'}.'.num'};
1303: my ($furl,$ferr)=
1304: &Apache::lonuserstate::readmap($cdom.'/'.$cnum);
1305: $message .= '<br /><font size="+1"><a href="'.$furl.'">'.$lt{'gtts'}.' <i>'.&mt('now').'</i></a></font>';
1306: } else {
1.70 raeburn 1307: $message .= '<br /><font size="+1"><a href="/adm/whatsnew?refpage='.
1308: $refpage.'">'.$lt{'dasp'}.'</a></font>';
1.63 raeburn 1309: }
1310: }
1311: $r->print(<<ENDVCSCREEN);
1312: $message
1313: <br /><br />
1314: ENDVCSCREEN
1315: }
1316:
1317:
1.4 matthew 1318: ######################################################
1319: # other handler subroutines #
1320: ######################################################
1321:
1.3 matthew 1322: ################################################################
1323: # Main handler #
1324: ################################################################
1.1 www 1325: sub handler {
1326: my $r = shift;
1.59 albertel 1327: my $user = $env{'user.name'};
1328: my $domain = $env{'user.domain'};
1.31 www 1329: &Apache::loncommon::content_type($r,'text/html');
1.4 matthew 1330: # Some pages contain DES keys and should not be cached.
1331: &Apache::loncommon::no_cache($r);
1.1 www 1332: $r->send_http_header;
1333: return OK if $r->header_only;
1.9 matthew 1334: #
1.35 matthew 1335: &Apache::loncommon::get_unprocessed_cgi($ENV{'QUERY_STRING'},
1.70 raeburn 1336: ['action','wysiwyg','returnurl','refpage']);
1.35 matthew 1337: #
1338: &Apache::lonhtmlcommon::clear_breadcrumbs();
1339: &Apache::lonhtmlcommon::add_breadcrumb
1340: ({href => '/adm/preferences',
1341: text => 'Set User Preferences'});
1342:
1343: my @Options;
1344: # Determine current authentication method
1345: my $currentauth=&Apache::lonnet::queryauthenticate($user,$domain);
1346: if ($currentauth =~ /^(unix|internal):/) {
1347: push (@Options,({ action => 'changepass',
1.40 www 1348: linktext => 'Change Password',
1.35 matthew 1349: href => '/adm/preferences',
1350: help => 'Change_Password',
1351: subroutine => \&passwordchanger,
1352: breadcrumb =>
1353: { href => '/adm/preferences?action=changepass',
1354: text => 'Change Password'},
1355: },
1356: { action => 'verify_and_change_pass',
1357: subroutine => \&verify_and_change_password,
1358: breadcrumb =>
1359: { href =>'/adm/preferences?action=changepass',
1360: text => 'Change Password'},
1.75 albertel 1361: printmenu => 'not_on_error',
1.35 matthew 1362: }));
1363: }
1364: push (@Options,({ action => 'changescreenname',
1365: linktext => 'Change Screen Name',
1366: href => '/adm/preferences',
1367: help => 'Prefs_Screen_Name_Nickname',
1368: subroutine => \&screennamechanger,
1369: breadcrumb =>
1370: { href => '/adm/preferences?action=changescreenname',
1371: text => 'Change Screen Name'},
1372: },
1373: { action => 'verify_and_change_screenname',
1374: subroutine => \&verify_and_change_screenname,
1375: breadcrumb =>
1376: { href => '/adm/preferences?action=changescreenname',
1377: text => 'Change Screen Name'},
1378: printmenu => 'yes',
1379: }));
1380:
1381: push (@Options,({ action => 'changemsgforward',
1.97 raeburn 1382: linktext => 'Change Message Forwarding and Notification Email Addresses',
1.35 matthew 1383: href => '/adm/preferences',
1384: help => 'Prefs_Forwarding',
1385: breadcrumb =>
1386: { href => '/adm/preferences?action=changemsgforward',
1387: text => 'Change Message Forwarding'},
1388: subroutine => \&msgforwardchanger,
1389: },
1390: { action => 'verify_and_change_msgforward',
1391: breadcrumb =>
1392: { href => '/adm/preferences?action=changemsgforward',
1393: text => 'Change Message Forwarding'},
1394: printmenu => 'yes',
1395: subroutine => \&verify_and_change_msgforward }));
1396: my $aboutmeaction=
1.59 albertel 1397: '/adm/'.$env{'user.domain'}.'/'.$env{'user.name'}.'/aboutme';
1.35 matthew 1398: push (@Options,{ action => 'none',
1399: linktext =>
1.41 www 1400: q{Edit the 'About Me' Personal Information Screen},
1.45 www 1401: help => 'Prefs_About_Me',
1.35 matthew 1402: href => $aboutmeaction});
1403: push (@Options,({ action => 'changecolors',
1404: linktext => 'Change Color Scheme',
1405: href => '/adm/preferences',
1406: help => 'Change_Colors',
1407: breadcrumb =>
1408: { href => '/adm/preferences?action=changecolors',
1409: text => 'Change Colors'},
1410: subroutine => \&colorschanger,
1411: },
1412: { action => 'verify_and_change_colors',
1413: breadcrumb =>
1414: { href => '/adm/preferences?action=changecolors',
1415: text => 'Change Colors'},
1416: printmenu => 'yes',
1417: subroutine => \&verify_and_change_colors,
1418: }));
1419: push (@Options,({ action => 'changelanguages',
1.39 www 1420: linktext => 'Change Language Preferences',
1.35 matthew 1421: href => '/adm/preferences',
1.45 www 1422: help => 'Prefs_Language',
1.35 matthew 1423: breadcrumb=>
1424: { href => '/adm/preferences?action=changelanguages',
1425: text => 'Change Language'},
1426: subroutine => \&languagechanger,
1427: },
1428: { action => 'verify_and_change_languages',
1429: breadcrumb=>
1430: {href => '/adm/preferences?action=changelanguages',
1431: text => 'Change Language'},
1432: printmenu => 'yes',
1433: subroutine=>\&verify_and_change_languages, }
1434: ));
1.44 www 1435: push (@Options,({ action => 'changewysiwyg',
1436: linktext => 'Change WYSIWYG Editor Preferences',
1437: href => '/adm/preferences',
1438: breadcrumb =>
1439: { href => '/adm/preferences?action=changewysiwyg',
1440: text => 'Change WYSIWYG Preferences'},
1441: subroutine => \&wysiwygchanger,
1442: },
1443: { action => 'set_wysiwyg',
1444: breadcrumb =>
1445: { href => '/adm/preferences?action=changewysiwyg',
1446: text => 'Change WYSIWYG Preferences'},
1447: printmenu => 'yes',
1448: subroutine => \&verify_and_change_wysiwyg, }
1449: ));
1.42 raeburn 1450: push (@Options,({ action => 'changediscussions',
1451: linktext => 'Change Discussion Display Preferences',
1452: href => '/adm/preferences',
1.46 raeburn 1453: help => 'Change_Discussion_Display',
1.42 raeburn 1454: breadcrumb =>
1455: { href => '/adm/preferences?action=changediscussions',
1.43 raeburn 1456: text => 'Change Discussion Preferences'},
1.42 raeburn 1457: subroutine => \&discussionchanger,
1458: },
1459: { action => 'verify_and_change_discussion',
1460: breadcrumb =>
1461: { href => '/adm/preferences?action=changediscussions',
1.43 raeburn 1462: text => 'Change Discussion Preferences'},
1.42 raeburn 1463: printmenu => 'yes',
1464: subroutine => \&verify_and_change_discussion, }
1465: ));
1.96 albertel 1466:
1467: my $role = ($env{'user.adv'} ? 'Roles' : 'Course');
1.50 albertel 1468: push (@Options,({ action => 'changerolespref',
1.96 albertel 1469: linktext => 'Change '.$role.' Page Preferences',
1.50 albertel 1470: href => '/adm/preferences',
1471: subroutine => \&rolesprefchanger,
1472: breadcrumb =>
1473: { href => '/adm/preferences?action=changerolespref',
1.96 albertel 1474: text => 'Change '.$role.' Page Pref'},
1.50 albertel 1475: },
1476: { action => 'verify_and_change_rolespref',
1477: subroutine => \&verify_and_change_rolespref,
1478: breadcrumb =>
1479: { href => '/adm/preferences?action=changerolespref',
1.96 albertel 1480: text => 'Change '.$role.' Page Preferences'},
1.50 albertel 1481: printmenu => 'yes',
1482: }));
1483:
1.54 albertel 1484: push (@Options,({ action => 'changetexenginepref',
1485: linktext => 'Change How Math Equations Are Displayed',
1486: href => '/adm/preferences',
1487: subroutine => \&texenginechanger,
1488: breadcrumb =>
1489: { href => '/adm/preferences?action=changetexenginepref',
1490: text => 'Change Math Pref'},
1491: },
1492: { action => 'verify_and_change_texengine',
1493: subroutine => \&verify_and_change_texengine,
1494: breadcrumb =>
1495: { href => '/adm/preferences?action=changetexenginepref',
1496: text => 'Change Math Preferences'},
1497: printmenu => 'yes',
1498: }));
1.85 albertel 1499:
1500: if ($env{'environment.remote'} eq 'off') {
1501: push (@Options,({ action => 'launch',
1502: linktext => 'Launch Remote Control',
1503: href => '/adm/remote?url=/adm/preferences',
1504: }));
1505: } else {
1506: push (@Options,({ action => 'collapse',
1507: linktext => 'Collapse Remote Control',
1508: href => '/adm/remote?url=/adm/preferences',
1509: }));
1510: }
1511:
1.98 ! www 1512: push (@Options,({ action => 'changeicons',
! 1513: linktext => 'Change How Main Menu is Displayed',
! 1514: href => '/adm/preferences',
! 1515: subroutine => \&iconchanger,
! 1516: breadcrumb =>
! 1517: { href => '/adm/preferences?action=changeicons',
! 1518: text => 'Change Main Menu'},
! 1519: },
! 1520: { action => 'verify_and_change_icons',
! 1521: subroutine => \&verify_and_change_icons,
! 1522: breadcrumb =>
! 1523: { href => '/adm/preferences?action=changeicons',
! 1524: text => 'Change Main Menu'},
! 1525: printmenu => 'yes',
! 1526: }));
! 1527:
1.74 albertel 1528: if (&Apache::lonnet::allowed('whn',$env{'request.course.id'})
1529: || &Apache::lonnet::allowed('whn',$env{'request.course.id'}.'/'
1530: .$env{'request.course.sec'})) {
1.63 raeburn 1531: push (@Options,({ action => 'changecourseinit',
1532: linktext => 'Change Course Initialization Preference',
1533: href => '/adm/preferences',
1534: subroutine => \&coursedisplaychanger,
1535: breadcrumb =>
1536: { href => '/adm/preferences?action=changecourseinit',
1537: text => 'Change Course Init. Pref.'},
1538: },
1539: { action => 'verify_and_change_coursepage',
1540: breadcrumb =>
1541: { href => '/adm/preferences?action=changecourseinit', text => 'Change Course Initialization Preference'},
1542: printmenu => 'yes',
1543: subroutine => \&verify_and_change_coursepage,
1544: }));
1545: }
1.50 albertel 1546:
1.62 raeburn 1547: if ($env{'user.name'} =~ /^(albertel|fox|foxr|koretemey|korte|hallmat3|turtle|raeburn)$/) {
1.35 matthew 1548: push (@Options,({ action => 'debugtoggle',
1549: printmenu => 'yes',
1550: subroutine => \&toggle_debug,
1551: }));
1552: }
1.76 albertel 1553:
1554: $r->print(&Apache::loncommon::start_page('Change Preferences'));
1555:
1.35 matthew 1556: my $call = undef;
1.48 albertel 1557: my $help = undef;
1.35 matthew 1558: my $printmenu = 'yes';
1559: foreach my $option (@Options) {
1.59 albertel 1560: if ($option->{'action'} eq $env{'form.action'}) {
1.35 matthew 1561: $call = $option->{'subroutine'};
1562: $printmenu = $option->{'printmenu'};
1563: if (exists($option->{'breadcrumb'})) {
1564: &Apache::lonhtmlcommon::add_breadcrumb
1565: ($option->{'breadcrumb'});
1566: }
1.48 albertel 1567: $help=$option->{'help'};
1.35 matthew 1568: }
1569: }
1.81 albertel 1570: $r->print(&Apache::lonhtmlcommon::breadcrumbs('Change Preferences',$help));
1.75 albertel 1571: my $error;
1.35 matthew 1572: if (defined($call)) {
1.75 albertel 1573: $error = $call->($r);
1.35 matthew 1574: }
1.75 albertel 1575: if ( ( ($printmenu eq 'yes')
1576: || ($printmenu eq 'not_on_error' && !$error) )
1577: && (!$env{'form.returnurl'})) {
1.35 matthew 1578: my $optionlist = '<table cellpadding="5">';
1.59 albertel 1579: if ($env{'user.name'} =~
1.62 raeburn 1580: /^(albertel|kortemey|fox|foxr|korte|hallmat3|turtle|raeburn)$/
1.35 matthew 1581: ) {
1582: push (@Options,({ action => 'debugtoggle',
1583: linktext => 'Toggle Debug Messages',
1584: text => 'Current Debug status is -'.
1.59 albertel 1585: $env{'user.debug'}.'-.',
1.35 matthew 1586: href => '/adm/preferences',
1587: printmenu => 'yes',
1588: subroutine => \&toggle_debug,
1589: }));
1590: }
1591: foreach my $option(@Options) {
1592: my $optiontext = '';
1593: if (exists($option->{'href'})) {
1.85 albertel 1594: $option->{'href_args'}{'action'}=$option->{'action'};
1595: $optiontext .=
1596: '<a href="'.&add_get_param($option->{'href'},
1597: $option->{'href_args'}).'">'.
1.47 albertel 1598: &mt($option->{'linktext'}).'</a>';
1.35 matthew 1599: }
1600: if (exists($option->{'text'})) {
1.47 albertel 1601: $optiontext .= ' '.&mt($option->{'text'});
1.35 matthew 1602: }
1603: if ($optiontext ne '') {
1604: $optiontext = '<font size="+1">'.$optiontext.'</font>';
1605: my $helplink = ' ';
1606: if (exists($option->{'help'})) {
1607: $helplink = &Apache::loncommon::help_open_topic
1608: ($option->{'help'});
1609: }
1610: $optionlist .= '<tr>'.
1611: '<td>'.$helplink.'</td>'.
1612: '<td>'.$optiontext.'</td>'.
1613: '</tr>';
1614: }
1.13 www 1615: }
1.35 matthew 1616: $optionlist .= '</table>';
1617: $r->print($optionlist);
1.59 albertel 1618: } elsif ($env{'form.returnurl'}) {
1619: $r->print('<br /><a href="'.$env{'form.returnurl'}.'"><font size="+1">'.
1.44 www 1620: &mt('Return').'</font></a>');
1.3 matthew 1621: }
1.76 albertel 1622: $r->print(&Apache::loncommon::end_page());
1.1 www 1623: return OK;
1.35 matthew 1624: }
1625:
1626: sub toggle_debug {
1.59 albertel 1627: if ($env{'user.debug'}) {
1.35 matthew 1628: &Apache::lonnet::delenv('user\.debug');
1629: } else {
1630: &Apache::lonnet::appenv('user.debug' => 1);
1631: }
1.13 www 1632: }
1.1 www 1633:
1634: 1;
1635: __END__
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>