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