Annotation of loncom/interface/lonpreferences.pm, revision 1.109
1.1 www 1: # The LearningOnline Network
2: # Preferences
3: #
1.109 ! albertel 4: # $Id: lonpreferences.pm,v 1.108 2007/07/06 23:17:30 www 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='';
1.100 www 529: my $onlyicon='';
1.98 www 530: if ($userenv{'icons'} eq 'classic') {
531: $classic='checked="checked"';
532: $iconic='';
533: }
1.100 www 534: if ($userenv{'icons'} eq 'iconsonly') {
535: $onlyicon='checked="checked"';
536: $iconic='';
537: }
538: my $useicons=&mt('Use icons and text');
539: my $usebuttons=&mt('Use buttons and text');
540: my $useicononly=&mt('Use icons only');
1.98 www 541: my $change=&mt('Change');
542: $r->print(<<ENDSCREEN);
543: <form name="prefs" action="/adm/preferences" method="post">
544: <input type="hidden" name="action" value="verify_and_change_icons" />
545: <label><input type="radio" name="menumode" value="iconic" $iconic /> $useicons</label><br />
546: <label><input type="radio" name="menumode" value="classic" $classic /> $usebuttons</label><br />
1.100 www 547: <label><input type="radio" name="menumode" value="iconsonly" $onlyicon /> $useicononly</label><br />
1.98 www 548: <input type="submit" value="$change" />
549: </form>
550: ENDSCREEN
551: }
552:
553: sub verify_and_change_icons {
554: my $r = shift;
555: my $user = $env{'user.name'};
556: my $domain = $env{'user.domain'};
557: my $newicons = $env{'form.menumode'};
558:
559: &Apache::lonnet::put('environment',{'icons' => $newicons});
560: &Apache::lonnet::appenv('environment.icons' => $newicons);
561: $r->print(&mt('Set menu mode to [_1].',$newicons));
562: }
563:
564: ################################################################
1.105 www 565: # Clicker Subroutines #
566: ################################################################
567:
568: sub clickerchanger {
569: my $r = shift;
570: my $user = $env{'user.name'};
571: my $domain = $env{'user.domain'};
572: my %userenv = &Apache::lonnet::get
573: ('environment',['clickers']);
574: my $clickers=$userenv{'clickers'};
575: $clickers=~s/\,/\n/gs;
576: my $text=&mt('Enter response device ("clicker") numbers');
577: my $change=&mt('Register');
1.107 www 578: my $helplink=&Apache::loncommon::help_open_topic('Clicker_Registration', 'Locating your clicker ID');
1.105 www 579: $r->print(<<ENDSCREEN);
580: <form name="prefs" action="/adm/preferences" method="post">
581: <input type="hidden" name="action" value="verify_and_change_clicker" />
1.107 www 582: <label>$text $helplink<br />
1.108 www 583: <textarea name="clickers" rows="5" cols="20">$clickers</textarea>
1.105 www 584: </label>
585: <input type="submit" value="$change" />
586: </form>
587: ENDSCREEN
588: }
589:
590: sub verify_and_change_clicker {
591: my $r = shift;
592: my $user = $env{'user.name'};
593: my $domain = $env{'user.domain'};
594: my $newclickers = $env{'form.clickers'};
1.108 www 595: $newclickers=~s/[^\w\:\-]+/\,/gs;
1.105 www 596: $newclickers=~tr/a-z/A-Z/;
1.108 www 597: $newclickers=~s/[\:\-]+/\-/g;
598: $newclickers=~s/\,+/\,/g;
1.105 www 599: $newclickers=~s/^\,//;
600: $newclickers=~s/\,$//;
601: &Apache::lonnet::put('environment',{'clickers' => $newclickers});
602: &Apache::lonnet::appenv('environment.clickers' => $newclickers);
603: $r->print(&mt('Registering clickers: [_1]',$newclickers));
604: }
605:
606: ################################################################
1.20 www 607: # Message Forward #
608: ################################################################
609:
610: sub msgforwardchanger {
1.102 raeburn 611: my ($r,$message) = @_;
1.59 albertel 612: my $user = $env{'user.name'};
613: my $domain = $env{'user.domain'};
1.102 raeburn 614: my %userenv = &Apache::lonnet::get('environment',['msgforward','notification','critnotification','notifywithhtml']);
1.20 www 615: my $msgforward=$userenv{'msgforward'};
1.102 raeburn 616: my %lt = &Apache::lonlocal::texthash(
617: all => 'All',
618: crit => 'Critical only',
619: reg => 'Non-critical only',
620: foad => 'Forwarding Address(es)',
621: mnot => 'Message Notification Email Address(es)',
622: chg => 'Change',
1.104 raeburn 623: email => 'The e-mail address entered in row ',
1.102 raeburn 624: notv => 'is not a valid e-mail address',
1.103 raeburn 625: toen => "To enter multiple addresses, enter one address at a time, click 'Change' and then add the next one",
1.102 raeburn 626: prme => 'Back to preferences menu',
627: );
1.25 bowersj2 628: my $forwardingHelp = Apache::loncommon::help_open_topic("Prefs_Forwarding",
629: "What are forwarding ".
630: "and notification ".
631: "addresses");
1.27 bowersj2 632: my $criticalMessageHelp = Apache::loncommon::help_open_topic("Course_Critical_Message",
633: "What are critical messages");
1.102 raeburn 634: my @allow_html = split(/,/,$userenv{'notifywithhtml'});
635: my %allnot = &get_notifications(\%userenv);
636: my $validatescript = &Apache::lonhtmlcommon::javascript_valid_email();
637: my $jscript = qq|
638: <script type="text/javascript">
639: function validate() {
640: for (var i=0; i<document.prefs.numnotify.value; i++) {
1.104 raeburn 641: var checkaddress = 0;
1.102 raeburn 642: var addr = document.prefs.elements['address_'+i].value;
1.104 raeburn 643: var rownum = i+1;
1.102 raeburn 644: if (i < document.prefs.numnotify.value-1) {
1.104 raeburn 645: if (document.prefs.elements['modify_notify_'+i].checked) {
1.102 raeburn 646: checkaddress = 1;
1.104 raeburn 647: }
1.102 raeburn 648: } else {
649: if (document.prefs.elements['add_notify_'+i].checked == true) {
650: checkaddress = 1;
651: }
652: }
1.104 raeburn 653: if (checkaddress == 1) {
1.102 raeburn 654: var addr = document.prefs.elements['address_'+i].value;
655: if (validmail(document.prefs.elements['address_'+i]) == false) {
1.104 raeburn 656: var multimsg = '';
657: if (addr.indexOf(",") >= 0) {
658: multimsg = "\\n($lt{'toen'}).";
659: }
660: alert("$lt{'email'} "+rownum+": '"+addr+"' $lt{'notv'}."+multimsg);
1.102 raeburn 661: return;
662: }
663: }
664: }
665: document.prefs.submit();
666: }
1.104 raeburn 667:
668: function address_changes (adnum) {
669: if (!document.prefs.elements['del_notify_'+adnum].checked) {
670: document.prefs.elements['modify_notify_'+adnum].checked = true;
671: }
672: }
673:
674: function new_address(adnum) {
675: document.prefs.elements['add_notify_'+adnum].checked = true;
676: }
677:
678: function delete_address(adnum) {
679: if (document.prefs.elements['del_notify_'+adnum].checked) {
680: document.prefs.elements['modify_notify_'+adnum].checked = false;
681: }
682: }
683:
684: function modify_address(adnum) {
685: if (document.prefs.elements['modify_notify_'+adnum].checked) {
686: document.prefs.elements['del_notify_'+adnum].checked = false;
687: }
688: }
689:
1.102 raeburn 690: $validatescript
691: </script>
692: |;
1.20 www 693: $r->print(<<ENDMSG);
1.102 raeburn 694: $jscript
695: $message
696: $forwardingHelp
1.88 albertel 697: <form name="prefs" action="/adm/preferences" method="post">
1.20 www 698: <input type="hidden" name="action" value="verify_and_change_msgforward" />
1.102 raeburn 699: $lt{'foad'} (<tt>user:domain,user:domain,...</tt>):
1.20 www 700: <input type="text" size="40" value="$msgforward" name="msgforward" /><hr />
1.102 raeburn 701: $criticalMessageHelp
702: $lt{'mnot'} (<tt>joe\@doe.com</tt>):<br />
703: ENDMSG
704: my @sortforwards = sort (keys(%allnot));
705: my $output = &Apache::loncommon::start_data_table().
706: &Apache::loncommon::start_data_table_header_row().
1.104 raeburn 707: '<th> </th>'.
1.102 raeburn 708: '<th>'.&mt('Action').'</th>'.
709: '<th>'.&mt('Notification address').'</th><th>'.
1.104 raeburn 710: &mt('Types of message to forward to this address').'</th><th>'.
711: &mt('Excerpt retains HTML tags in message').'</th>'.
1.102 raeburn 712: &Apache::loncommon::end_data_table_header_row();
713: my $num = 0;
1.104 raeburn 714: my $counter = 1;
1.102 raeburn 715: foreach my $item (@sortforwards) {
716: $output .= &Apache::loncommon::start_data_table_row().
1.104 raeburn 717: '<td><b>'.$counter.'</b></td>'.
718: '<td><span class="LC_nobreak"><label>'.
719: '<input type="checkbox" name="modify_notify_'.
720: $num.'" onclick="javscript:modify_address('."'$num'".')" />'.
721: &mt('Modify').'</label></span> '.
722: '<span class="LC_nobreak"><label>'.
723: '<input type="checkbox" name="del_notify_'.$num.
724: '" onclick="javscript:delete_address('."'$num'".')" />'.
725: &mt('Delete').'</label></span></td>'.
1.102 raeburn 726: '<td><input type="text" value="'.$item.'" name="address_'.
1.104 raeburn 727: $num.'" onFocus="javascript:address_changes('."'$num'".
728: ')" /></td><td>';
1.102 raeburn 729: my %chk;
730: if (defined($allnot{$item}{'crit'})) {
731: if (defined($allnot{$item}{'reg'})) {
732: $chk{'all'} = 'checked="checked" ';
733: } else {
734: $chk{'crit'} = 'checked="checked" ';
735: }
736: } else {
737: $chk{'reg'} = 'checked="checked" ';
738: }
739: foreach my $type ('all','crit','reg') {
740: $output .= '<span class="LC_nobreak"><label>'.
741: '<input type="radio" name="notify_type_'.$num.
1.104 raeburn 742: '" value="'.$type.'" '.$chk{$type}.
743: ' onchange="javascript:address_changes('."'$num'".')" />'.
744: $lt{$type}.'</label></span> ';
1.102 raeburn 745: }
746: my $htmlon = '';
747: my $htmloff = '';
748: if (grep/^\Q$item\E/,@allow_html) {
749: $htmlon = 'checked="checked" ';
750: } else {
751: $htmloff = 'checked="checked" ';
752: }
753: $output .= '</td><td><label><input type="radio" name="html_'.$num.
1.104 raeburn 754: '" value="1" '.$htmlon.
755: ' onchange="javascript:address_changes('."'$num'".')" />'.
756: &mt('Yes').'</label> '.
1.102 raeburn 757: '<label><input type="radio" name="html_'.$num.'" value="0" '.
1.104 raeburn 758: $htmloff. ' onchange="javascript:address_changes('."'$num'".
759: ')" />'.
760: &mt('No').'</label></td>'.
1.102 raeburn 761: &Apache::loncommon::end_data_table_row();
762: $num ++;
1.104 raeburn 763: $counter ++;
1.102 raeburn 764: }
765: my %defchk = (
766: all => 'checked="checked" ',
767: crit => '',
768: reg => '',
769: );
770: $output .= &Apache::loncommon::start_data_table_row().
1.104 raeburn 771: '<td><b>'.$counter.'</b></td>'.
772: '<td><span class="LC_nobreak"><label>'.
773: '<input type="checkbox" name="add_notify_'.$num.
774: '" value="1" />'.&mt('Add new address').'</label></span></td>'.
1.102 raeburn 775: '<td><input type="text" value="" name="address_'.$num.
1.104 raeburn 776: '" onFocus="javascript:new_address('."'$num'".')" /></td><td>';
1.102 raeburn 777: foreach my $type ('all','crit','reg') {
778: $output .= '<span class="LC_nobreak"><label>'.
779: '<input type="radio" name="notify_type_'.$num.
780: '" value="'.$type.'" '.$defchk{$type}.'/>'.
781: $lt{$type}.'</label></span> ';
782: }
783: $output .= '</td><td><label><input type="radio" name="html_'.$num.
784: '" value="1" />'.&mt('Yes').'</label> '.
785: '<label><input type="radio" name="html_'.$num.'" value="0" '.
786: ' checked="checked" />'.
787: &mt('No').'</label></td>'.
788: &Apache::loncommon::end_data_table_row().
789: &Apache::loncommon::end_data_table();
790: $num ++;
791: $r->print($output);
792: $r->print(qq|
793: <hr />
794: <input type="hidden" name="numnotify" value="$num" />
795: <input type="button" value="$lt{'chg'}" onclick="javascript:validate()" />
796: <input type="button" value="$lt{'prme'}" onclick="location.href='/adm/preferences'" />
1.20 www 797: </form>
1.102 raeburn 798: |);
799:
800: }
801:
802: sub get_notifications {
803: my ($userenv) = @_;
804: my %allnot;
805: my @critnot = split(/,/,$userenv->{'critnotification'});
806: my @regnot = split(/,/,$userenv->{'notification'});
807: foreach my $item (@critnot) {
808: $allnot{$item}{crit} = 1;
809: }
810: foreach my $item (@regnot) {
811: $allnot{$item}{reg} = 1;
812: }
813: return %allnot;
1.20 www 814: }
815:
816: sub verify_and_change_msgforward {
817: my $r = shift;
1.59 albertel 818: my $user = $env{'user.name'};
819: my $domain = $env{'user.domain'};
1.20 www 820: my $newscreen = '';
821: my $message='';
1.59 albertel 822: foreach (split(/\,/,$env{'form.msgforward'})) {
1.20 www 823: my ($msuser,$msdomain)=split(/[\@\:]/,$_);
1.95 albertel 824: $msuser = &LONCAPA::clean_username($msuser);
825: $msdomain = &LONCAPA::clean_domain($msdomain);
1.20 www 826: if (($msuser) && ($msdomain)) {
827: if (&Apache::lonnet::homeserver($msuser,$msdomain) ne 'no_host') {
828: $newscreen.=$msuser.':'.$msdomain.',';
829: } else {
1.102 raeburn 830: $message.= &mt('No such user: ').$msuser.':'.$msdomain.'<br>';
1.20 www 831: }
832: }
833: }
834: $newscreen=~s/\,$//;
835: if ($newscreen) {
836: &Apache::lonnet::put('environment',{'msgforward' => $newscreen});
837: &Apache::lonnet::appenv('environment.msgforward' => $newscreen);
1.102 raeburn 838: $message .= &mt('Set message forwarding to: ').'<tt>'.$newscreen.
839: '</tt><br />';
1.20 www 840: } else {
841: &Apache::lonnet::del('environment',['msgforward']);
842: &Apache::lonnet::delenv('environment\.msgforward');
1.102 raeburn 843: $message.= &mt("Set message forwarding to 'off'.").'<br />';
1.20 www 844: }
1.102 raeburn 845: my $critnotification;
846: my $notification;
847: my $notify_with_html;
848: my $lastnotify = $env{'form.numnotify'}-1;
1.104 raeburn 849: my $totaladdresses = 0;
1.102 raeburn 850: for (my $i=0; $i<$env{'form.numnotify'}; $i++) {
851: if ((!defined($env{'form.del_notify_'.$i})) &&
1.104 raeburn 852: ((($i==$lastnotify) && ($env{'form.add_notify_'.$lastnotify} == 1)) ||
1.102 raeburn 853: ($i<$lastnotify))) {
854: if (defined($env{'form.address_'.$i})) {
855: if ($env{'form.notify_type_'.$i} eq 'all') {
856: $critnotification .= $env{'form.address_'.$i}.',';
857: $notification .= $env{'form.address_'.$i}.',';
858: } elsif ($env{'form.notify_type_'.$i} eq 'crit') {
859: $critnotification .= $env{'form.address_'.$i}.',';
860: } elsif ($env{'form.notify_type_'.$i} eq 'reg') {
861: $notification .= $env{'form.address_'.$i}.',';
862: }
863: if ($env{'form.html_'.$i} eq '1') {
864: $notify_with_html .= $env{'form.address_'.$i}.',';
865: }
1.104 raeburn 866: $totaladdresses ++;
1.102 raeburn 867: }
868: }
869: }
870: $critnotification =~ s/,$//;
871: $critnotification=~s/\s//gs;
872: $notification =~ s/,$//;
1.20 www 873: $notification=~s/\s//gs;
1.102 raeburn 874: $notify_with_html =~ s/,$//;
875: $notify_with_html =~ s/\s//gs;
1.20 www 876: if ($notification) {
877: &Apache::lonnet::put('environment',{'notification' => $notification});
878: &Apache::lonnet::appenv('environment.notification' => $notification);
1.102 raeburn 879: $message.=&mt('Set non-critical message notification address(es) to: ').'<tt>'.$notification.'</tt><br />';
1.20 www 880: } else {
881: &Apache::lonnet::del('environment',['notification']);
882: &Apache::lonnet::delenv('environment\.notification');
1.102 raeburn 883: $message.=&mt("Non-critical message notification set to 'off'.").'<br />';
1.20 www 884: }
885: if ($critnotification) {
886: &Apache::lonnet::put('environment',{'critnotification' => $critnotification});
887: &Apache::lonnet::appenv('environment.critnotification' => $critnotification);
1.102 raeburn 888: $message.=&mt('Set critical message notification address(es) to: ').'<tt>'.$critnotification.'</tt><br />';
1.20 www 889: } else {
890: &Apache::lonnet::del('environment',['critnotification']);
891: &Apache::lonnet::delenv('environment\.critnotification');
1.104 raeburn 892: $message.=&mt("Critical message notification set to 'off'.").'<br />';
1.102 raeburn 893: }
894: if ($critnotification || $notification) {
895: if ($notify_with_html) {
896: &Apache::lonnet::put('environment',{'notifywithhtml' => $notify_with_html});
897: &Apache::lonnet::appenv('environment.notifywithhtml' => $notify_with_html);
898: $message.=&mt('Set address(es) to receive excerpts with html retained: ').'<tt>'.$notify_with_html.'</tt>';
899: } else {
900: &Apache::lonnet::del('environment',['notifywithhtml']);
901: &Apache::lonnet::delenv('environment\.notifywithhtml');
1.104 raeburn 902: if ($totaladdresses == 1) {
903: $message.=&mt("Set notification address to receive excerpts with html stripped.");
904: } else {
905: $message.=&mt("Set all notification addresses to receive excerpts with html stripped.");
906: }
1.102 raeburn 907: }
908: } else {
909: &Apache::lonnet::del('environment',['notifywithhtml']);
910: &Apache::lonnet::delenv('environment\.notifywithhtml');
911: }
912: if ($message) {
913: $message .= '<br /><hr />';
1.20 www 914: }
1.109 ! albertel 915: &Apache::loncommon::flush_email_cache($user,$domain);
1.102 raeburn 916: &msgforwardchanger($r,$message);
1.6 www 917: }
918:
1.12 www 919: ################################################################
1.19 www 920: # Colors #
1.12 www 921: ################################################################
922:
1.19 www 923: sub colorschanger {
1.12 www 924: my $r = shift;
1.19 www 925: # figure out colors
1.80 albertel 926: my $function=&Apache::loncommon::get_users_function();
1.19 www 927: my $domain=&Apache::loncommon::determinedomain();
928: my %colortypes=('pgbg' => 'Page Background',
929: 'tabbg' => 'Header Background',
930: 'sidebg'=> 'Header Border',
931: 'font' => 'Font',
932: 'link' => 'Un-Visited Link',
933: 'vlink' => 'Visited Link',
934: 'alink' => 'Active Link');
1.82 albertel 935: my $start_data_table = &Apache::loncommon::start_data_table();
1.19 www 936: my $chtable='';
1.22 matthew 937: foreach my $item (sort(keys(%colortypes))) {
1.19 www 938: my $curcol=&Apache::loncommon::designparm($function.'.'.$item,$domain);
1.82 albertel 939: $chtable.=&Apache::loncommon::start_data_table_row().
1.83 albertel 940: '<td>'.$colortypes{$item}.'</td><td style="background: '.$curcol.
1.19 www 941: '"> </td><td><input name="'.$item.
1.21 www 942: '" size="10" value="'.$curcol.
943: '" /></td><td><a href="javascript:pjump('."'color_custom','".$colortypes{$item}.
1.19 www 944: "','".$curcol."','"
1.82 albertel 945: .$item."','parmform.pres','psub'".');">Select</a></td>'.
1.83 albertel 946: &Apache::loncommon::end_data_table_row()."\n";
1.19 www 947: }
1.82 albertel 948: my $end_data_table = &Apache::loncommon::end_data_table();
1.23 matthew 949: my $pjump_def = &Apache::lonhtmlcommon::pjump_javascript_definition();
1.19 www 950: $r->print(<<ENDCOL);
1.82 albertel 951: <script type="text/javascript">
1.19 www 952:
953: function pclose() {
954: parmwin=window.open("/adm/rat/empty.html","LONCAPAparms",
955: "height=350,width=350,scrollbars=no,menubar=no");
956: parmwin.close();
957: }
958:
1.23 matthew 959: $pjump_def
1.19 www 960:
961: function psub() {
962: pclose();
963: if (document.parmform.pres_marker.value!='') {
1.21 www 964: if (document.parmform.pres_type.value!='') {
1.77 albertel 965: eval('document.prefs.'+
1.21 www 966: document.parmform.pres_marker.value+
1.19 www 967: '.value=document.parmform.pres_value.value;');
1.21 www 968: }
1.19 www 969: } else {
970: document.parmform.pres_value.value='';
971: document.parmform.pres_marker.value='';
972: }
973: }
974:
975:
976: </script>
1.21 www 977: <form name="parmform">
978: <input type="hidden" name="pres_marker" />
979: <input type="hidden" name="pres_type" />
980: <input type="hidden" name="pres_value" />
981: </form>
1.88 albertel 982: <form name="prefs" action="/adm/preferences" method="post">
1.19 www 983: <input type="hidden" name="action" value="verify_and_change_colors" />
1.82 albertel 984: $start_data_table
1.19 www 985: $chtable
1.82 albertel 986: $end_data_table
1.19 www 987: </table>
1.21 www 988: <input type="submit" value="Change Custom Colors" />
989: <input type="submit" name="resetall" value="Reset All Colors to Default" />
1.12 www 990: </form>
1.19 www 991: ENDCOL
1.12 www 992: }
993:
1.19 www 994: sub verify_and_change_colors {
1.12 www 995: my $r = shift;
1.19 www 996: # figure out colors
1.80 albertel 997: my $function=&Apache::loncommon::get_users_function();
1.19 www 998: my $domain=&Apache::loncommon::determinedomain();
999: my %colortypes=('pgbg' => 'Page Background',
1000: 'tabbg' => 'Header Background',
1001: 'sidebg'=> 'Header Border',
1002: 'font' => 'Font',
1003: 'link' => 'Un-Visited Link',
1004: 'vlink' => 'Visited Link',
1005: 'alink' => 'Active Link');
1006:
1.12 www 1007: my $message='';
1.21 www 1008: foreach my $item (keys %colortypes) {
1.59 albertel 1009: my $color=$env{'form.'.$item};
1.21 www 1010: my $entry='color.'.$function.'.'.$item;
1.59 albertel 1011: if (($color=~/^\#[0-9A-Fa-f]{6}$/) && (!$env{'form.resetall'})) {
1.21 www 1012: &Apache::lonnet::put('environment',{$entry => $color});
1013: &Apache::lonnet::appenv('environment.'.$entry => $color);
1014: $message.='Set '.$colortypes{$item}.' to '.$color.'<br />';
1015: } else {
1016: &Apache::lonnet::del('environment',[$entry]);
1017: &Apache::lonnet::delenv('environment\.'.$entry);
1018: $message.='Reset '.$colortypes{$item}.'<br />';
1019: }
1020: }
1.84 albertel 1021: my $now = time;
1022: &Apache::lonnet::put('environment',{'color.timestamp' => $now});
1023: &Apache::lonnet::appenv('environment.color.timestamp' => $now);
1024:
1.19 www 1025: $r->print(<<ENDVCCOL);
1.12 www 1026: $message
1.88 albertel 1027: <form name="client" action="/adm/preferences" method="post">
1.21 www 1028: <input type="hidden" name="action" value="changecolors" />
1029: </form>
1.19 www 1030: ENDVCCOL
1.12 www 1031: }
1032:
1.4 matthew 1033: ######################################################
1034: # password handler subroutines #
1035: ######################################################
1.3 matthew 1036: sub passwordchanger {
1.94 raeburn 1037: my ($r,$errormessage,$caller,$mailtoken) = @_;
1.4 matthew 1038: # This function is a bit of a mess....
1.3 matthew 1039: # Passwords are encrypted using londes.js (DES encryption)
1.4 matthew 1040: $errormessage = ($errormessage || '');
1.94 raeburn 1041: my ($user,$domain,$currentpass,$defdom);
1042: if ((!defined($caller)) || ($caller eq 'preferences')) {
1043: $user = $env{'user.name'};
1044: $domain = $env{'user.domain'};
1045: if (!defined($caller)) {
1046: $caller = 'preferences';
1047: }
1048: } elsif ($caller eq 'reset_by_email') {
1049: $defdom = $r->dir_config('lonDefDomain');
1050: my %data = &Apache::lonnet::tmpget($mailtoken);
1051: if (keys(%data) == 0) {
1052: $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.'));
1053: return;
1054: }
1055: if (defined($data{time})) {
1056: if (time - $data{'time'} < 7200) {
1057: $user = $data{'username'};
1058: $domain = $data{'domain'};
1059: $currentpass = $data{'temppasswd'};
1060: } else {
1061: $r->print(&mt('Sorry, the token generated when you requested a password reset has expired.').'<br />');
1062: return;
1063: }
1064: } else {
1065: $r->print(&mt('Sorry, the URL generated when you requested reset of your password contained incomplete information.').'<br />');
1066: return;
1067: }
1068: } else {
1069: $r->print(&mt('Page requested in unexpected context').'<br />');
1070: return;
1071: }
1.3 matthew 1072: my $currentauth=&Apache::lonnet::queryauthenticate($user,$domain);
1073: # Check for authentication types that allow changing of the password.
1074: return if ($currentauth !~ /^(unix|internal):/);
1075: #
1076: # Generate keys
1077: my ($lkey_cpass ,$ukey_cpass ) = &des_keys();
1078: my ($lkey_npass1,$ukey_npass1) = &des_keys();
1079: my ($lkey_npass2,$ukey_npass2) = &des_keys();
1.4 matthew 1080: # Store the keys in the log files
1.3 matthew 1081: my $lonhost = $r->dir_config('lonHostID');
1082: my $logtoken=Apache::lonnet::reply('tmpput:'
1083: .$ukey_cpass . $lkey_cpass .'&'
1084: .$ukey_npass1 . $lkey_npass1.'&'
1085: .$ukey_npass2 . $lkey_npass2,
1086: $lonhost);
1.4 matthew 1087: # Hexify the keys for output as javascript variables
1.94 raeburn 1088: my %hexkey;
1089: $hexkey{'ukey_cpass'} = hex($ukey_cpass);
1090: $hexkey{'lkey_cpass'} = hex($lkey_cpass);
1091: $hexkey{'ukey_npass1'} = hex($ukey_npass1);
1092: $hexkey{'lkey_npass1'} = hex($lkey_npass1);
1093: $hexkey{'ukey_npass2'} = hex($ukey_npass2);
1094: $hexkey{'lkey_npass2'} = hex($lkey_npass2);
1.3 matthew 1095: # Output javascript to deal with passwords
1.4 matthew 1096: # Output DES javascript
1.3 matthew 1097: {
1098: my $include = $r->dir_config('lonIncludes');
1099: my $jsh=Apache::File->new($include."/londes.js");
1100: $r->print(<$jsh>);
1101: }
1.94 raeburn 1102: $r->print(&jscript_send($caller));
1.3 matthew 1103: $r->print(<<ENDFORM);
1.94 raeburn 1104: $errormessage
1105:
1106: <p>
1107: <!-- We separate the forms into 'server' and 'client' in order to
1108: ensure that unencrypted passwords will not be sent out by a
1109: crappy browser -->
1110: ENDFORM
1111: $r->print(&server_form($logtoken,$caller,$mailtoken));
1112: $r->print(&client_form($caller,\%hexkey,$currentpass,$defdom));
1113:
1114: #
1115: return;
1116: }
1117:
1118: sub jscript_send {
1119: my ($caller) = @_;
1120: my $output = qq|
1.3 matthew 1121: <script language="JavaScript">
1122:
1123: function send() {
1124: uextkey=this.document.client.elements.ukey_cpass.value;
1125: lextkey=this.document.client.elements.lkey_cpass.value;
1126: initkeys();
1127:
1.52 raeburn 1128: this.document.pserver.elements.currentpass.value
1.3 matthew 1129: =crypted(this.document.client.elements.currentpass.value);
1130:
1131: uextkey=this.document.client.elements.ukey_npass1.value;
1132: lextkey=this.document.client.elements.lkey_npass1.value;
1133: initkeys();
1.52 raeburn 1134: this.document.pserver.elements.newpass_1.value
1.3 matthew 1135: =crypted(this.document.client.elements.newpass_1.value);
1136:
1137: uextkey=this.document.client.elements.ukey_npass2.value;
1138: lextkey=this.document.client.elements.lkey_npass2.value;
1139: initkeys();
1.52 raeburn 1140: this.document.pserver.elements.newpass_2.value
1.3 matthew 1141: =crypted(this.document.client.elements.newpass_2.value);
1.94 raeburn 1142: |;
1143: if ($caller eq 'reset_by_email') {
1144: $output .= qq|
1145: this.document.pserver.elements.uname.value =
1146: this.document.client.elements.uname.value;
1147: this.document.pserver.elements.udom.value =
1148: this.document.client.elements.udom.options[this.document.client.elements.udom.selectedIndex].value;
1149: |;
1150: }
1151: $ output .= qq|
1.52 raeburn 1152: this.document.pserver.submit();
1.3 matthew 1153: }
1154: </script>
1.94 raeburn 1155: |;
1156: }
1.3 matthew 1157:
1.94 raeburn 1158: sub client_form {
1159: my ($caller,$hexkey,$currentpass,$defdom) = @_;
1.99 www 1160: my %lt=&Apache::lonlocal::texthash(
1161: 'email' => 'EMail Address',
1162: 'username' => 'Username',
1163: 'domain' => 'Domain',
1164: 'currentpass' => 'Current Password',
1165: 'newpass' => 'New Password',
1166: 'confirmpass' => 'Confirm Password',
1167: 'changepass' => 'Change Password');
1168:
1.94 raeburn 1169: my $output = qq|
1.3 matthew 1170: <form name="client" >
1171: <table>
1.94 raeburn 1172: |;
1173: if ($caller eq 'reset_by_email') {
1174: $output .= qq|
1.99 www 1175: <tr><td class="LC_preferences_labeltext"><label for="email">$lt{'email'}</label>:</td>
1.97 raeburn 1176: <td><input type="text" name="email" size="30" /> </td></tr>
1.99 www 1177: <tr><td class="LC_preferences_labeltext"><label for="uname">$lt{'username'}</label>:</td>
1.94 raeburn 1178: <td>
1.97 raeburn 1179: <input type="text" name="uname" size="15" />
1.94 raeburn 1180: <input type="hidden" name="currentpass" value="$currentpass" />
1181: </td></tr>
1.99 www 1182: <tr><td class="LC_preferences_labeltext"><label for="udom">$lt{'udom'}</label>:</td>
1.94 raeburn 1183: <td>
1184: |;
1185: $output .= &Apache::loncommon::select_dom_form($defdom,'udom').'
1186: </td>
1187: </tr>
1188: ';
1189: } else {
1190: $output .= qq|
1.99 www 1191: <tr><td class="LC_preferences_labeltext"><label for="currentpass">$lt{'currentpass'}</label></td>
1.4 matthew 1192: <td><input type="password" name="currentpass" size="10"/> </td></tr>
1.94 raeburn 1193: |;
1194: }
1195: $output .= <<"ENDFORM";
1.99 www 1196: <tr><td class="LC_preferences_labeltext"><label for="newpass_1">$lt{'newpass'}</label></td>
1.4 matthew 1197: <td><input type="password" name="newpass_1" size="10" /> </td></tr>
1.99 www 1198: <tr><td class="LC_preferences_labeltext"><label for="newpass_2">$lt{'confirmpass'}</label></td>
1.4 matthew 1199: <td><input type="password" name="newpass_2" size="10" /> </td></tr>
1.3 matthew 1200: <tr><td colspan="2" align="center">
1.99 www 1201: <input type="button" value="$lt{'changepass'}" onClick="send();">
1.3 matthew 1202: </table>
1.94 raeburn 1203: <input type="hidden" name="ukey_cpass" value="$hexkey->{'ukey_cpass'}" />
1204: <input type="hidden" name="lkey_cpass" value="$hexkey->{'lkey_cpass'}" />
1205: <input type="hidden" name="ukey_npass1" value="$hexkey->{'ukey_npass1'}" />
1206: <input type="hidden" name="lkey_npass1" value="$hexkey->{'lkey_npass1'}" />
1207: <input type="hidden" name="ukey_npass2" value="$hexkey->{'ukey_npass2'}" />
1208: <input type="hidden" name="lkey_npass2" value="$hexkey->{'lkey_npass2'}" />
1.3 matthew 1209: </form>
1210: </p>
1211: ENDFORM
1.94 raeburn 1212: return $output;
1213: }
1214:
1215: sub server_form {
1216: my ($logtoken,$caller,$mailtoken) = @_;
1217: my $action = '/adm/preferences';
1218: if ($caller eq 'reset_by_email') {
1219: $action = '/adm/resetpw';
1220: }
1221: my $output = qq|
1222: <form name="pserver" action="$action" method="post">
1223: <input type="hidden" name="logtoken" value="$logtoken" />
1224: <input type="hidden" name="currentpass" value="" />
1225: <input type="hidden" name="newpass_1" value="" />
1226: <input type="hidden" name="newpass_2" value="" />
1227: |;
1228: if ($caller eq 'reset_by_email') {
1229: $output .= qq|
1230: <input type="hidden" name="token" value="$mailtoken" />
1231: <input type="hidden" name="uname" value="" />
1232: <input type="hidden" name="udom" value="" />
1233:
1234: |;
1235: }
1236: $output .= qq|
1237: <input type="hidden" name="action" value="verify_and_change_pass" />
1238: </form>
1239: |;
1240: return $output;
1.3 matthew 1241: }
1242:
1243: sub verify_and_change_password {
1.94 raeburn 1244: my ($r,$caller,$mailtoken) = @_;
1245: my ($user,$domain,$homeserver);
1246: if ($caller eq 'reset_by_email') {
1247: $user = $env{'form.uname'};
1248: $domain = $env{'form.udom'};
1249: if ($user ne '' && $domain ne '') {
1250: $homeserver = &Apache::lonnet::homeserver($user,$domain);
1251: if ($homeserver eq 'no_host') {
1.99 www 1252: &passwordchanger($r,"<p>\n<span class='LC_error'>".
1253: &mt("Invalid username and/or domain")."</span>\n</p>",
1.94 raeburn 1254: $caller,$mailtoken);
1255: return 1;
1256: }
1257: } else {
1.99 www 1258: &passwordchanger($r,"<p>\n<span class='LC_error'>".
1259: &mt("Username and domain were blank")."</span>\n</p>",
1.94 raeburn 1260: $caller,$mailtoken);
1261: return 1;
1262: }
1263: } else {
1264: $user = $env{'user.name'};
1265: $domain = $env{'user.domain'};
1266: $homeserver = $env{'user.home'};
1267: }
1.3 matthew 1268: my $currentauth=&Apache::lonnet::queryauthenticate($user,$domain);
1.4 matthew 1269: # Check for authentication types that allow changing of the password.
1.94 raeburn 1270: if ($currentauth !~ /^(unix|internal):/) {
1271: if ($caller eq 'reset_by_email') {
1.99 www 1272: &passwordchanger($r,"<p>\n<span class='LC_error'>".
1273: &mt("Authentication type for this user can not be changed by this mechanism").
1274: "</span>\n</p>",
1.94 raeburn 1275: $caller,$mailtoken);
1276: return 1;
1277: } else {
1278: return;
1279: }
1280: }
1.3 matthew 1281: #
1.59 albertel 1282: my $currentpass = $env{'form.currentpass'};
1283: my $newpass1 = $env{'form.newpass_1'};
1284: my $newpass2 = $env{'form.newpass_2'};
1285: my $logtoken = $env{'form.logtoken'};
1.3 matthew 1286: # Check for empty data
1.4 matthew 1287: unless (defined($currentpass) &&
1288: defined($newpass1) &&
1289: defined($newpass2) ){
1.99 www 1290: &passwordchanger($r,"<p>\n<span class='LC_error'>".
1291: &mt("One or more password fields were blank").
1292: "</span>\n</p>",$caller,$mailtoken);
1.3 matthew 1293: return;
1294: }
1.16 albertel 1295: # Get the keys
1296: my $lonhost = $r->dir_config('lonHostID');
1.3 matthew 1297: my $tmpinfo = Apache::lonnet::reply('tmpget:'.$logtoken,$lonhost);
1298: if (($tmpinfo=~/^error/) || ($tmpinfo eq 'con_lost')) {
1.4 matthew 1299: # I do not a have a better idea about how to handle this
1.94 raeburn 1300: my $tryagain_text = &mt('Please log out and try again.');
1301: if ($caller eq 'reset_by_email') {
1302: $tryagain_text = &mt('Please try again later.');
1303: }
1.101 albertel 1304: my $unable=&mt("Unable to retrieve saved token for password decryption");
1.3 matthew 1305: $r->print(<<ENDERROR);
1306: <p>
1.99 www 1307: <span class="LC_error">$unable. $tryagain_text</span>
1.3 matthew 1308: </p>
1309: ENDERROR
1.4 matthew 1310: # Probably should log an error here
1.75 albertel 1311: return 1;
1.3 matthew 1312: }
1313: my ($ckey,$n1key,$n2key)=split(/&/,$tmpinfo);
1.4 matthew 1314: #
1.17 matthew 1315: $currentpass = &des_decrypt($ckey ,$currentpass);
1316: $newpass1 = &des_decrypt($n1key,$newpass1);
1317: $newpass2 = &des_decrypt($n2key,$newpass2);
1.94 raeburn 1318: #
1319: if ($caller eq 'reset_by_email') {
1320: my %data = &Apache::lonnet::tmpget($mailtoken);
1321: if ($currentpass ne $data{'temppasswd'}) {
1322: &passwordchanger($r,
1.99 www 1323: '<span class="LC_error">'.
1324: &mt('Could not verify current authentication').'. '.
1325: &mt('Please try again').'.</span>',$caller,$mailtoken);
1.94 raeburn 1326: return 1;
1327: }
1328: }
1.3 matthew 1329: if ($newpass1 ne $newpass2) {
1.4 matthew 1330: &passwordchanger($r,
1.99 www 1331: '<span class="LC_error">'.
1332: &mt('The new passwords you entered do not match').'. '.
1333: &mt('Please try again').'.</span>',$caller,$mailtoken);
1.75 albertel 1334: return 1;
1.4 matthew 1335: }
1336: if (length($newpass1) < 7) {
1337: &passwordchanger($r,
1.99 www 1338: '<span class="LC_error">'.
1339: &mt('Passwords must be a minimum of 7 characters long').'. '.
1340: &mt('Please try again').'</span>.',$caller,$mailtoken);
1.75 albertel 1341: return 1;
1.3 matthew 1342: }
1.4 matthew 1343: #
1344: # Check for bad characters
1345: my $badpassword = 0;
1346: foreach (split(//,$newpass1)) {
1347: $badpassword = 1 if ((ord($_)<32)||(ord($_)>126));
1348: }
1349: if ($badpassword) {
1350: # I can't figure out how to enter bad characters on my browser.
1.99 www 1351: my $errormessage ='<span class="LC_error">'.
1352: &mt('The password you entered contained illegal characters').'.<br />'.
1353: &mt('Valid characters are').(<<"ENDERROR");
1354: : space and <br />
1.4 matthew 1355: <pre>
1356: !"\#$%&\'()*+,-./0123456789:;<=>?\@
1357: ABCDEFGHIJKLMNOPQRSTUVWXYZ[\]^_\`abcdefghijklmnopqrstuvwxyz{|}~
1.99 www 1358: </pre></span>
1.4 matthew 1359: ENDERROR
1.94 raeburn 1360: &passwordchanger($r,$errormessage,$caller,$mailtoken);
1361: return 1;
1.4 matthew 1362: }
1363: #
1364: # Change the password (finally)
1365: my $result = &Apache::lonnet::changepass
1.94 raeburn 1366: ($user,$domain,$currentpass,$newpass1,$homeserver,$caller);
1.4 matthew 1367: # Inform the user the password has (not?) been changed
1368: if ($result =~ /^ok$/) {
1.99 www 1369: $r->print("<h3>".&mt('The password for [_1] was successfully changed',$user)."</h3>");
1.4 matthew 1370: } else {
1371: # error error: run in circles, scream and shout
1.99 www 1372: $r->print("<h3><span class='LC_error'>".&mt("The password for [_1] was not changed",$user)."</span></h3>".
1373: &mt('Please make sure your old password was entered correctly').'.');
1.75 albertel 1374: return 1;
1.4 matthew 1375: }
1376: return;
1.3 matthew 1377: }
1378:
1.42 raeburn 1379: ################################################################
1380: # discussion display subroutines
1381: ################################################################
1382: sub discussionchanger {
1383: my $r = shift;
1.59 albertel 1384: my $user = $env{'user.name'};
1385: my $domain = $env{'user.domain'};
1.42 raeburn 1386: my %userenv = &Apache::lonnet::get
1.43 raeburn 1387: ('environment',['discdisplay','discmarkread']);
1388: my $discdisp = 'allposts';
1389: my $discmark = 'onmark';
1390:
1391: if (defined($userenv{'discdisplay'})) {
1392: unless ($userenv{'discdisplay'} eq '') {
1393: $discdisp = $userenv{'discdisplay'};
1394: }
1395: }
1396: if (defined($userenv{'discmarkread'})) {
1397: unless ($userenv{'discdisplay'} eq '') {
1398: $discmark = $userenv{'discmarkread'};
1399: }
1400: }
1401:
1402: my $newdisp = 'unread';
1403: my $newmark = 'ondisp';
1404:
1405: my $function = &Apache::loncommon::get_users_function();
1406: my $color = &Apache::loncommon::designparm($function.'.tabbg',
1.59 albertel 1407: $env{'user.domain'});
1.43 raeburn 1408: my %lt = &Apache::lonlocal::texthash(
1409: 'pref' => 'Display Preference',
1410: 'curr' => 'Current setting ',
1411: 'actn' => 'Action',
1412: 'sdpf' => 'Set display preferences for discussion posts for both bulletin boards and individual resources in all your courses.',
1413: 'prca' => 'Preferences can be set that determine',
1414: 'whpo' => 'Which posts are displayed when you display a bulletin board or resource, and',
1415: 'unwh' => 'Under what circumstances posts are identfied as "New"',
1416: 'allposts' => 'All posts',
1417: 'unread' => 'New posts only',
1418: 'ondisp' => 'Once displayed',
1419: 'onmark' => 'Once marked as read',
1420: 'disa' => 'Posts displayed?',
1421: 'npmr' => 'New posts cease to be identified as "New"?',
1422: 'thde' => 'The preferences you set here can be overridden within each individual discussion.',
1423: 'chgt' => 'Change to '
1424: );
1425: my $dispchange = $lt{'unread'};
1426: my $markchange = $lt{'ondisp'};
1427: my $currdisp = $lt{'allposts'};
1428: my $currmark = $lt{'onmark'};
1429:
1430: if ($discdisp eq 'unread') {
1431: $dispchange = $lt{'allposts'};
1432: $currdisp = $lt{'unread'};
1433: $newdisp = 'allposts';
1434: }
1435:
1436: if ($discmark eq 'ondisp') {
1437: $markchange = $lt{'onmark'};
1438: $currmark = $lt{'ondisp'};
1439: $newmark = 'onmark';
1.42 raeburn 1440: }
1.43 raeburn 1441:
1442: $r->print(<<"END");
1.88 albertel 1443: <form name="prefs" action="/adm/preferences" method="post">
1.42 raeburn 1444: <input type="hidden" name="action" value="verify_and_change_discussion" />
1445: <br />
1.87 albertel 1446: $lt{'sdpf'}<br /> $lt{'prca'} <ol><li>$lt{'whpo'}</li><li>$lt{'unwh'}</li></ol>
1.43 raeburn 1447: <br />
1448: <br />
1.82 albertel 1449: END
1450: $r->print(&Apache::loncommon::start_data_table());
1451: $r->print(<<"END");
1452: <tr>
1453: <th>$lt{'pref'}</th>
1454: <th>$lt{'curr'}</th>
1455: <th>$lt{'actn'}?</th>
1.43 raeburn 1456: </tr>
1.82 albertel 1457: END
1458: $r->print(&Apache::loncommon::start_data_table_row());
1459: $r->print(<<"END");
1.43 raeburn 1460: <td>$lt{'disa'}</td>
1461: <td>$lt{$discdisp}</td>
1.82 albertel 1462: <td><label><input type="checkbox" name="discdisp" /><input type="hidden" name="newdisp" value="$newdisp" /> $lt{'chgt'} "$dispchange"</label></td>
1463: END
1464: $r->print(&Apache::loncommon::end_data_table_row().
1465: &Apache::loncommon::start_data_table_row());
1466: $r->print(<<"END");
1.43 raeburn 1467: <td>$lt{'npmr'}</td>
1468: <td>$lt{$discmark}</td>
1.82 albertel 1469: <td><label><input type="checkbox" name="discmark" /><input type="hidden" name="newmark" value="$newmark" /> $lt{'chgt'} "$markchange"</label></td>
1.43 raeburn 1470: </tr>
1.82 albertel 1471: END
1472: $r->print(&Apache::loncommon::end_data_table_row().
1473: &Apache::loncommon::end_data_table());
1474: $r->print(<<"END");
1.43 raeburn 1475: <br />
1476: <br />
1.101 albertel 1477: <input type="submit" name="sub" value="Save Changes" />
1.43 raeburn 1478: <br />
1479: <br />
1480: Note: $lt{'thde'}
1481: </form>
1482: END
1.42 raeburn 1483: }
1484:
1485: sub verify_and_change_discussion {
1486: my $r = shift;
1.59 albertel 1487: my $user = $env{'user.name'};
1488: my $domain = $env{'user.domain'};
1.42 raeburn 1489: my $message='';
1.59 albertel 1490: if (defined($env{'form.discdisp'}) ) {
1491: my $newdisp = $env{'form.newdisp'};
1.43 raeburn 1492: if ($newdisp eq 'unread') {
1.87 albertel 1493: $message .='In discussions: only new posts will be displayed.<br />';
1.43 raeburn 1494: &Apache::lonnet::put('environment',{'discdisplay' => $newdisp});
1495: &Apache::lonnet::appenv('environment.discdisplay' => $newdisp);
1496: } else {
1.87 albertel 1497: $message .= 'In discussions: all posts will be displayed.<br />';
1.43 raeburn 1498: &Apache::lonnet::del('environment',['discdisplay']);
1499: &Apache::lonnet::delenv('environment\.discdisplay');
1500: }
1501: }
1.59 albertel 1502: if (defined($env{'form.discmark'}) ) {
1503: my $newmark = $env{'form.newmark'};
1.43 raeburn 1504: if ($newmark eq 'ondisp') {
1.87 albertel 1505: $message.='In discussions: new posts will be cease to be identified as "new" after display.<br />';
1.43 raeburn 1506: &Apache::lonnet::put('environment',{'discmarkread' => $newmark});
1507: &Apache::lonnet::appenv('environment.discmarkread' => $newmark);
1508: } else {
1.87 albertel 1509: $message.='In discussions: posts will be identified as "new" until marked as read by the reader.<br />';
1.43 raeburn 1510: &Apache::lonnet::del('environment',['discmarkread']);
1511: &Apache::lonnet::delenv('environment\.discmarkread');
1512: }
1.42 raeburn 1513: }
1514: $r->print(<<ENDVCSCREEN);
1515: $message
1516: ENDVCSCREEN
1517: }
1518:
1.63 raeburn 1519: ################################################################
1520: # Subroutines for page display on course access (Course Coordinators)
1521: ################################################################
1522: sub coursedisplaychanger {
1523: my $r = shift;
1524: my $user = $env{'user.name'};
1525: my $domain = $env{'user.domain'};
1.66 albertel 1526: my %userenv = &Apache::lonnet::get('environment',['course_init_display']);
1.71 raeburn 1527: my $currvalue = 'whatsnew';
1.73 albertel 1528: my $firstselect = '';
1529: my $whatsnewselect = 'checked="checked"';
1.71 raeburn 1530: if (exists($userenv{'course_init_display'})) {
1531: if ($userenv{'course_init_display'} eq 'firstres') {
1532: $currvalue = 'firstres';
1.73 albertel 1533: $firstselect = 'checked="checked"';
1534: $whatsnewselect = '';
1.71 raeburn 1535: }
1.63 raeburn 1536: }
1.71 raeburn 1537: my %pagenames = (
1538: firstres => 'First resource',
1539: whatsnew => "What's new page",
1540: );
1.70 raeburn 1541: my $whatsnew_off=&mt('Display the [_1] in the course.','<b>first resource</b>');
1542: 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 1543:
1.71 raeburn 1544: $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 1545: $r->print(<<ENDLSCREEN);
1.88 albertel 1546: <form name="prefs" action="/adm/preferences" method="post">
1.63 raeburn 1547: <input type="hidden" name="action" value="verify_and_change_coursepage" />
1.72 albertel 1548: <br />
1.65 albertel 1549: <label><input type="radio" name="newdisp" value="firstres" $firstselect /> $whatsnew_off</label><br />
1.70 raeburn 1550: <label><input type="radio" name="newdisp" value="whatsnew" $whatsnewselect /> $whatsnew_on</label><input type="hidden" name="refpage" value="$env{'form.refpage'}" />
1.63 raeburn 1551: ENDLSCREEN
1.70 raeburn 1552: $r->print('<br /><br /><input type="submit" value="'.&mt('Change').'" />
1.63 raeburn 1553: </form>');
1554: }
1555:
1556: sub verify_and_change_coursepage {
1557: my $r = shift;
1558: my $message='';
1559: my %lt = &Apache::lonlocal::texthash(
1.70 raeburn 1560: 'defs' => 'Default now set',
1.71 raeburn 1561: 'when' => 'when you select a course role from the roles screen',
1.63 raeburn 1562: 'ywbt' => 'you will be taken to the start of the course.',
1563: 'apwb' => 'a page will be displayed that lists items in the course that may require action from you.',
1564: 'gtts' => 'Go to the start of the course',
1.70 raeburn 1565: 'dasp' => "Display the What's New page listing course action items",
1.63 raeburn 1566: );
1567: my $newdisp = $env{'form.newdisp'};
1.70 raeburn 1568: $message = '<b>'.$lt{'defs'}.'</b>: '.$lt{'when'}.', ';
1.63 raeburn 1569: if ($newdisp eq 'firstres') {
1.87 albertel 1570: $message .= $lt{'ywbt'}.'<br />';
1.63 raeburn 1571: &Apache::lonnet::put('environment',{'course_init_display' => $newdisp});
1572: &Apache::lonnet::appenv('environment.course_init_display' => $newdisp);
1573: } else {
1.87 albertel 1574: $message .= $lt{'apwb'}.'<br />';
1.63 raeburn 1575: &Apache::lonnet::del('environment',['course_init_display']);
1576: &Apache::lonnet::delenv('environment\.course_init_display');
1577: }
1.70 raeburn 1578: my $refpage = $env{'form.refpage'};
1.63 raeburn 1579: if (($env{'request.course.fn'}) && ($env{'request.course.id'})) {
1580: if ($newdisp eq 'firstres') {
1581: my $cdom = $env{'course.'.$env{'request.course.id'}.'.domain'};
1582: my $cnum = $env{'course.'.$env{'request.course.id'}.'.num'};
1583: my ($furl,$ferr)=
1584: &Apache::lonuserstate::readmap($cdom.'/'.$cnum);
1585: $message .= '<br /><font size="+1"><a href="'.$furl.'">'.$lt{'gtts'}.' <i>'.&mt('now').'</i></a></font>';
1586: } else {
1.70 raeburn 1587: $message .= '<br /><font size="+1"><a href="/adm/whatsnew?refpage='.
1588: $refpage.'">'.$lt{'dasp'}.'</a></font>';
1.63 raeburn 1589: }
1590: }
1591: $r->print(<<ENDVCSCREEN);
1592: $message
1593: <br /><br />
1594: ENDVCSCREEN
1595: }
1596:
1597:
1.4 matthew 1598: ######################################################
1599: # other handler subroutines #
1600: ######################################################
1601:
1.3 matthew 1602: ################################################################
1603: # Main handler #
1604: ################################################################
1.1 www 1605: sub handler {
1606: my $r = shift;
1.59 albertel 1607: my $user = $env{'user.name'};
1608: my $domain = $env{'user.domain'};
1.31 www 1609: &Apache::loncommon::content_type($r,'text/html');
1.4 matthew 1610: # Some pages contain DES keys and should not be cached.
1611: &Apache::loncommon::no_cache($r);
1.1 www 1612: $r->send_http_header;
1613: return OK if $r->header_only;
1.9 matthew 1614: #
1.35 matthew 1615: &Apache::loncommon::get_unprocessed_cgi($ENV{'QUERY_STRING'},
1.70 raeburn 1616: ['action','wysiwyg','returnurl','refpage']);
1.35 matthew 1617: #
1618: &Apache::lonhtmlcommon::clear_breadcrumbs();
1619: &Apache::lonhtmlcommon::add_breadcrumb
1620: ({href => '/adm/preferences',
1621: text => 'Set User Preferences'});
1622:
1623: my @Options;
1624: # Determine current authentication method
1625: my $currentauth=&Apache::lonnet::queryauthenticate($user,$domain);
1626: if ($currentauth =~ /^(unix|internal):/) {
1627: push (@Options,({ action => 'changepass',
1.40 www 1628: linktext => 'Change Password',
1.35 matthew 1629: href => '/adm/preferences',
1630: help => 'Change_Password',
1631: subroutine => \&passwordchanger,
1632: breadcrumb =>
1633: { href => '/adm/preferences?action=changepass',
1634: text => 'Change Password'},
1635: },
1636: { action => 'verify_and_change_pass',
1637: subroutine => \&verify_and_change_password,
1638: breadcrumb =>
1639: { href =>'/adm/preferences?action=changepass',
1640: text => 'Change Password'},
1.75 albertel 1641: printmenu => 'not_on_error',
1.35 matthew 1642: }));
1643: }
1644: push (@Options,({ action => 'changescreenname',
1645: linktext => 'Change Screen Name',
1646: href => '/adm/preferences',
1647: help => 'Prefs_Screen_Name_Nickname',
1648: subroutine => \&screennamechanger,
1649: breadcrumb =>
1650: { href => '/adm/preferences?action=changescreenname',
1651: text => 'Change Screen Name'},
1652: },
1653: { action => 'verify_and_change_screenname',
1654: subroutine => \&verify_and_change_screenname,
1655: breadcrumb =>
1656: { href => '/adm/preferences?action=changescreenname',
1657: text => 'Change Screen Name'},
1658: printmenu => 'yes',
1659: }));
1660:
1661: push (@Options,({ action => 'changemsgforward',
1.97 raeburn 1662: linktext => 'Change Message Forwarding and Notification Email Addresses',
1.35 matthew 1663: href => '/adm/preferences',
1664: help => 'Prefs_Forwarding',
1665: breadcrumb =>
1666: { href => '/adm/preferences?action=changemsgforward',
1667: text => 'Change Message Forwarding'},
1668: subroutine => \&msgforwardchanger,
1669: },
1670: { action => 'verify_and_change_msgforward',
1671: breadcrumb =>
1672: { href => '/adm/preferences?action=changemsgforward',
1673: text => 'Change Message Forwarding'},
1.102 raeburn 1674: printmenu => 'no',
1.35 matthew 1675: subroutine => \&verify_and_change_msgforward }));
1676: my $aboutmeaction=
1.59 albertel 1677: '/adm/'.$env{'user.domain'}.'/'.$env{'user.name'}.'/aboutme';
1.35 matthew 1678: push (@Options,{ action => 'none',
1679: linktext =>
1.41 www 1680: q{Edit the 'About Me' Personal Information Screen},
1.45 www 1681: help => 'Prefs_About_Me',
1.35 matthew 1682: href => $aboutmeaction});
1683: push (@Options,({ action => 'changecolors',
1684: linktext => 'Change Color Scheme',
1685: href => '/adm/preferences',
1686: help => 'Change_Colors',
1687: breadcrumb =>
1688: { href => '/adm/preferences?action=changecolors',
1689: text => 'Change Colors'},
1690: subroutine => \&colorschanger,
1691: },
1692: { action => 'verify_and_change_colors',
1693: breadcrumb =>
1694: { href => '/adm/preferences?action=changecolors',
1695: text => 'Change Colors'},
1696: printmenu => 'yes',
1697: subroutine => \&verify_and_change_colors,
1698: }));
1699: push (@Options,({ action => 'changelanguages',
1.39 www 1700: linktext => 'Change Language Preferences',
1.35 matthew 1701: href => '/adm/preferences',
1.45 www 1702: help => 'Prefs_Language',
1.35 matthew 1703: breadcrumb=>
1704: { href => '/adm/preferences?action=changelanguages',
1705: text => 'Change Language'},
1706: subroutine => \&languagechanger,
1707: },
1708: { action => 'verify_and_change_languages',
1709: breadcrumb=>
1710: {href => '/adm/preferences?action=changelanguages',
1711: text => 'Change Language'},
1712: printmenu => 'yes',
1713: subroutine=>\&verify_and_change_languages, }
1714: ));
1.44 www 1715: push (@Options,({ action => 'changewysiwyg',
1716: linktext => 'Change WYSIWYG Editor Preferences',
1717: href => '/adm/preferences',
1718: breadcrumb =>
1719: { href => '/adm/preferences?action=changewysiwyg',
1720: text => 'Change WYSIWYG Preferences'},
1721: subroutine => \&wysiwygchanger,
1722: },
1723: { action => 'set_wysiwyg',
1724: breadcrumb =>
1725: { href => '/adm/preferences?action=changewysiwyg',
1726: text => 'Change WYSIWYG Preferences'},
1727: printmenu => 'yes',
1728: subroutine => \&verify_and_change_wysiwyg, }
1729: ));
1.42 raeburn 1730: push (@Options,({ action => 'changediscussions',
1731: linktext => 'Change Discussion Display Preferences',
1732: href => '/adm/preferences',
1.46 raeburn 1733: help => 'Change_Discussion_Display',
1.42 raeburn 1734: breadcrumb =>
1735: { href => '/adm/preferences?action=changediscussions',
1.43 raeburn 1736: text => 'Change Discussion Preferences'},
1.42 raeburn 1737: subroutine => \&discussionchanger,
1738: },
1739: { action => 'verify_and_change_discussion',
1740: breadcrumb =>
1741: { href => '/adm/preferences?action=changediscussions',
1.43 raeburn 1742: text => 'Change Discussion Preferences'},
1.42 raeburn 1743: printmenu => 'yes',
1744: subroutine => \&verify_and_change_discussion, }
1745: ));
1.96 albertel 1746:
1747: my $role = ($env{'user.adv'} ? 'Roles' : 'Course');
1.50 albertel 1748: push (@Options,({ action => 'changerolespref',
1.96 albertel 1749: linktext => 'Change '.$role.' Page Preferences',
1.50 albertel 1750: href => '/adm/preferences',
1751: subroutine => \&rolesprefchanger,
1752: breadcrumb =>
1753: { href => '/adm/preferences?action=changerolespref',
1.96 albertel 1754: text => 'Change '.$role.' Page Pref'},
1.50 albertel 1755: },
1756: { action => 'verify_and_change_rolespref',
1757: subroutine => \&verify_and_change_rolespref,
1758: breadcrumb =>
1759: { href => '/adm/preferences?action=changerolespref',
1.96 albertel 1760: text => 'Change '.$role.' Page Preferences'},
1.50 albertel 1761: printmenu => 'yes',
1762: }));
1763:
1.54 albertel 1764: push (@Options,({ action => 'changetexenginepref',
1765: linktext => 'Change How Math Equations Are Displayed',
1766: href => '/adm/preferences',
1767: subroutine => \&texenginechanger,
1768: breadcrumb =>
1769: { href => '/adm/preferences?action=changetexenginepref',
1770: text => 'Change Math Pref'},
1771: },
1772: { action => 'verify_and_change_texengine',
1773: subroutine => \&verify_and_change_texengine,
1774: breadcrumb =>
1775: { href => '/adm/preferences?action=changetexenginepref',
1776: text => 'Change Math Preferences'},
1777: printmenu => 'yes',
1778: }));
1.85 albertel 1779:
1780: if ($env{'environment.remote'} eq 'off') {
1781: push (@Options,({ action => 'launch',
1782: linktext => 'Launch Remote Control',
1783: href => '/adm/remote?url=/adm/preferences',
1784: }));
1785: } else {
1786: push (@Options,({ action => 'collapse',
1787: linktext => 'Collapse Remote Control',
1788: href => '/adm/remote?url=/adm/preferences',
1789: }));
1790: }
1791:
1.98 www 1792: push (@Options,({ action => 'changeicons',
1.100 www 1793: linktext => 'Change How Menus are Displayed',
1.98 www 1794: href => '/adm/preferences',
1795: subroutine => \&iconchanger,
1796: breadcrumb =>
1797: { href => '/adm/preferences?action=changeicons',
1798: text => 'Change Main Menu'},
1799: },
1800: { action => 'verify_and_change_icons',
1801: subroutine => \&verify_and_change_icons,
1802: breadcrumb =>
1803: { href => '/adm/preferences?action=changeicons',
1804: text => 'Change Main Menu'},
1805: printmenu => 'yes',
1806: }));
1807:
1.106 www 1808: push (@Options,({ action => 'changeclicker',
1809: linktext => 'Register Response Devices ("Clickers")',
1810: href => '/adm/preferences',
1811: subroutine => \&clickerchanger,
1812: breadcrumb =>
1813: { href => '/adm/preferences?action=changeicons',
1814: text => 'Register Clicker'},
1815: },
1816: { action => 'verify_and_change_clicker',
1817: subroutine => \&verify_and_change_clicker,
1818: breadcrumb =>
1819: { href => '/adm/preferences?action=changeclicker',
1820: text => 'Register Clicker'},
1821: printmenu => 'yes',
1822: }));
1.105 www 1823:
1824:
1.74 albertel 1825: if (&Apache::lonnet::allowed('whn',$env{'request.course.id'})
1826: || &Apache::lonnet::allowed('whn',$env{'request.course.id'}.'/'
1827: .$env{'request.course.sec'})) {
1.63 raeburn 1828: push (@Options,({ action => 'changecourseinit',
1829: linktext => 'Change Course Initialization Preference',
1830: href => '/adm/preferences',
1831: subroutine => \&coursedisplaychanger,
1832: breadcrumb =>
1833: { href => '/adm/preferences?action=changecourseinit',
1834: text => 'Change Course Init. Pref.'},
1835: },
1836: { action => 'verify_and_change_coursepage',
1837: breadcrumb =>
1838: { href => '/adm/preferences?action=changecourseinit', text => 'Change Course Initialization Preference'},
1839: printmenu => 'yes',
1840: subroutine => \&verify_and_change_coursepage,
1841: }));
1842: }
1.50 albertel 1843:
1.62 raeburn 1844: if ($env{'user.name'} =~ /^(albertel|fox|foxr|koretemey|korte|hallmat3|turtle|raeburn)$/) {
1.35 matthew 1845: push (@Options,({ action => 'debugtoggle',
1846: printmenu => 'yes',
1847: subroutine => \&toggle_debug,
1848: }));
1849: }
1.76 albertel 1850:
1851: $r->print(&Apache::loncommon::start_page('Change Preferences'));
1852:
1.35 matthew 1853: my $call = undef;
1.48 albertel 1854: my $help = undef;
1.35 matthew 1855: my $printmenu = 'yes';
1856: foreach my $option (@Options) {
1.59 albertel 1857: if ($option->{'action'} eq $env{'form.action'}) {
1.35 matthew 1858: $call = $option->{'subroutine'};
1859: $printmenu = $option->{'printmenu'};
1860: if (exists($option->{'breadcrumb'})) {
1861: &Apache::lonhtmlcommon::add_breadcrumb
1862: ($option->{'breadcrumb'});
1863: }
1.48 albertel 1864: $help=$option->{'help'};
1.35 matthew 1865: }
1866: }
1.81 albertel 1867: $r->print(&Apache::lonhtmlcommon::breadcrumbs('Change Preferences',$help));
1.75 albertel 1868: my $error;
1.35 matthew 1869: if (defined($call)) {
1.75 albertel 1870: $error = $call->($r);
1.35 matthew 1871: }
1.75 albertel 1872: if ( ( ($printmenu eq 'yes')
1873: || ($printmenu eq 'not_on_error' && !$error) )
1874: && (!$env{'form.returnurl'})) {
1.35 matthew 1875: my $optionlist = '<table cellpadding="5">';
1.59 albertel 1876: if ($env{'user.name'} =~
1.62 raeburn 1877: /^(albertel|kortemey|fox|foxr|korte|hallmat3|turtle|raeburn)$/
1.35 matthew 1878: ) {
1879: push (@Options,({ action => 'debugtoggle',
1880: linktext => 'Toggle Debug Messages',
1881: text => 'Current Debug status is -'.
1.59 albertel 1882: $env{'user.debug'}.'-.',
1.35 matthew 1883: href => '/adm/preferences',
1884: printmenu => 'yes',
1885: subroutine => \&toggle_debug,
1886: }));
1887: }
1888: foreach my $option(@Options) {
1889: my $optiontext = '';
1890: if (exists($option->{'href'})) {
1.85 albertel 1891: $option->{'href_args'}{'action'}=$option->{'action'};
1892: $optiontext .=
1893: '<a href="'.&add_get_param($option->{'href'},
1894: $option->{'href_args'}).'">'.
1.47 albertel 1895: &mt($option->{'linktext'}).'</a>';
1.35 matthew 1896: }
1897: if (exists($option->{'text'})) {
1.47 albertel 1898: $optiontext .= ' '.&mt($option->{'text'});
1.35 matthew 1899: }
1900: if ($optiontext ne '') {
1901: $optiontext = '<font size="+1">'.$optiontext.'</font>';
1902: my $helplink = ' ';
1903: if (exists($option->{'help'})) {
1904: $helplink = &Apache::loncommon::help_open_topic
1905: ($option->{'help'});
1906: }
1907: $optionlist .= '<tr>'.
1908: '<td>'.$helplink.'</td>'.
1909: '<td>'.$optiontext.'</td>'.
1910: '</tr>';
1911: }
1.13 www 1912: }
1.35 matthew 1913: $optionlist .= '</table>';
1914: $r->print($optionlist);
1.59 albertel 1915: } elsif ($env{'form.returnurl'}) {
1916: $r->print('<br /><a href="'.$env{'form.returnurl'}.'"><font size="+1">'.
1.44 www 1917: &mt('Return').'</font></a>');
1.3 matthew 1918: }
1.76 albertel 1919: $r->print(&Apache::loncommon::end_page());
1.1 www 1920: return OK;
1.35 matthew 1921: }
1922:
1923: sub toggle_debug {
1.59 albertel 1924: if ($env{'user.debug'}) {
1.35 matthew 1925: &Apache::lonnet::delenv('user\.debug');
1926: } else {
1927: &Apache::lonnet::appenv('user.debug' => 1);
1928: }
1.13 www 1929: }
1.1 www 1930:
1931: 1;
1932: __END__
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>