Annotation of loncom/interface/lonpreferences.pm, revision 1.117
1.1 www 1: # The LearningOnline Network
2: # Preferences
3: #
1.117 ! raeburn 4: # $Id: lonpreferences.pm,v 1.116 2008/03/12 02:45:07 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});
1.116 raeburn 126: &Apache::lonnet::appenv({'environment.wysiwygeditor' => $newsetting});
1.44 www 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});
1.116 raeburn 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') {
1.116 raeburn 255: &Apache::lonnet::appenv({'browser.mathml' => 1});
1.56 albertel 256: } else {
1.59 albertel 257: if ($env{'environment.texengine'} eq 'ttm') {
1.116 raeburn 258: &Apache::lonnet::appenv({'browser.mathml' => 0});
1.56 albertel 259: }
260: }
1.54 albertel 261: my $message='';
262: if ($newtexengine) {
263: &Apache::lonnet::put('environment',{'texengine' => $newtexengine});
1.116 raeburn 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});
1.116 raeburn 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});
1.116 raeburn 412: &Apache::lonnet::appenv({'environment.recentrolesn' => $hotlist_n});
1.50 albertel 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});
1.116 raeburn 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});
1.116 raeburn 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});
1.116 raeburn 566: &Apache::lonnet::appenv({'environment.icons' => $newicons});
1.98 www 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.114 bisitz 584: my $helplink=&Apache::loncommon::help_open_topic('Clicker_Registration',&mt('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});
1.116 raeburn 608: &Apache::lonnet::appenv({'environment.clickers' => $newclickers});
1.105 www 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});
1.116 raeburn 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});
1.116 raeburn 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});
1.116 raeburn 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});
1.116 raeburn 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});
1.116 raeburn 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});
1.116 raeburn 1030: &Apache::lonnet::appenv({'environment.color.timestamp' => $now});
1.84 albertel 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(
1.115 raeburn 1168: 'email' => 'E-mail Address',
1.99 www 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.115 raeburn 1189: <tr><td class="LC_preferences_labeltext"><label for="udom">$lt{'domain'}</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);
1.117 ! raeburn 1328: if (keys(%data) == 0) {
! 1329: &passwordchanger($r,
! 1330: '<span class="LC_error">'.
! 1331: &mt('Could not verify current authentication.').' '.
! 1332: &mt('Please try again.').'</span>',$caller,$mailtoken);
! 1333: return 1;
! 1334: }
1.94 raeburn 1335: if ($currentpass ne $data{'temppasswd'}) {
1336: &passwordchanger($r,
1.99 www 1337: '<span class="LC_error">'.
1.110 bisitz 1338: &mt('Could not verify current authentication.').' '.
1339: &mt('Please try again.').'</span>',$caller,$mailtoken);
1.94 raeburn 1340: return 1;
1341: }
1342: }
1.3 matthew 1343: if ($newpass1 ne $newpass2) {
1.4 matthew 1344: &passwordchanger($r,
1.99 www 1345: '<span class="LC_error">'.
1.110 bisitz 1346: &mt('The new passwords you entered do not match.').' '.
1347: &mt('Please try again.').'</span>',$caller,$mailtoken);
1.75 albertel 1348: return 1;
1.4 matthew 1349: }
1350: if (length($newpass1) < 7) {
1351: &passwordchanger($r,
1.99 www 1352: '<span class="LC_error">'.
1.110 bisitz 1353: &mt('Passwords must be a minimum of 7 characters long.').' '.
1354: &mt('Please try again.').'</span>',$caller,$mailtoken);
1.75 albertel 1355: return 1;
1.3 matthew 1356: }
1.4 matthew 1357: #
1358: # Check for bad characters
1359: my $badpassword = 0;
1360: foreach (split(//,$newpass1)) {
1361: $badpassword = 1 if ((ord($_)<32)||(ord($_)>126));
1362: }
1363: if ($badpassword) {
1364: # I can't figure out how to enter bad characters on my browser.
1.99 www 1365: my $errormessage ='<span class="LC_error">'.
1.110 bisitz 1366: &mt('The password you entered contained illegal characters.').'<br />'.
1.99 www 1367: &mt('Valid characters are').(<<"ENDERROR");
1368: : space and <br />
1.4 matthew 1369: <pre>
1370: !"\#$%&\'()*+,-./0123456789:;<=>?\@
1371: ABCDEFGHIJKLMNOPQRSTUVWXYZ[\]^_\`abcdefghijklmnopqrstuvwxyz{|}~
1.99 www 1372: </pre></span>
1.4 matthew 1373: ENDERROR
1.94 raeburn 1374: &passwordchanger($r,$errormessage,$caller,$mailtoken);
1375: return 1;
1.4 matthew 1376: }
1377: #
1378: # Change the password (finally)
1379: my $result = &Apache::lonnet::changepass
1.94 raeburn 1380: ($user,$domain,$currentpass,$newpass1,$homeserver,$caller);
1.4 matthew 1381: # Inform the user the password has (not?) been changed
1382: if ($result =~ /^ok$/) {
1.99 www 1383: $r->print("<h3>".&mt('The password for [_1] was successfully changed',$user)."</h3>");
1.4 matthew 1384: } else {
1385: # error error: run in circles, scream and shout
1.99 www 1386: $r->print("<h3><span class='LC_error'>".&mt("The password for [_1] was not changed",$user)."</span></h3>".
1.110 bisitz 1387: &mt('Please make sure your old password was entered correctly.'));
1.75 albertel 1388: return 1;
1.4 matthew 1389: }
1390: return;
1.3 matthew 1391: }
1392:
1.42 raeburn 1393: ################################################################
1394: # discussion display subroutines
1395: ################################################################
1396: sub discussionchanger {
1397: my $r = shift;
1.59 albertel 1398: my $user = $env{'user.name'};
1399: my $domain = $env{'user.domain'};
1.42 raeburn 1400: my %userenv = &Apache::lonnet::get
1.43 raeburn 1401: ('environment',['discdisplay','discmarkread']);
1402: my $discdisp = 'allposts';
1403: my $discmark = 'onmark';
1404:
1405: if (defined($userenv{'discdisplay'})) {
1406: unless ($userenv{'discdisplay'} eq '') {
1407: $discdisp = $userenv{'discdisplay'};
1408: }
1409: }
1410: if (defined($userenv{'discmarkread'})) {
1411: unless ($userenv{'discdisplay'} eq '') {
1412: $discmark = $userenv{'discmarkread'};
1413: }
1414: }
1415:
1416: my $newdisp = 'unread';
1417: my $newmark = 'ondisp';
1418:
1419: my $function = &Apache::loncommon::get_users_function();
1420: my $color = &Apache::loncommon::designparm($function.'.tabbg',
1.59 albertel 1421: $env{'user.domain'});
1.43 raeburn 1422: my %lt = &Apache::lonlocal::texthash(
1423: 'pref' => 'Display Preference',
1424: 'curr' => 'Current setting ',
1425: 'actn' => 'Action',
1426: 'sdpf' => 'Set display preferences for discussion posts for both bulletin boards and individual resources in all your courses.',
1427: 'prca' => 'Preferences can be set that determine',
1428: 'whpo' => 'Which posts are displayed when you display a bulletin board or resource, and',
1429: 'unwh' => 'Under what circumstances posts are identfied as "New"',
1430: 'allposts' => 'All posts',
1431: 'unread' => 'New posts only',
1432: 'ondisp' => 'Once displayed',
1433: 'onmark' => 'Once marked as read',
1434: 'disa' => 'Posts displayed?',
1435: 'npmr' => 'New posts cease to be identified as "New"?',
1436: 'thde' => 'The preferences you set here can be overridden within each individual discussion.',
1437: 'chgt' => 'Change to '
1438: );
1439: my $dispchange = $lt{'unread'};
1440: my $markchange = $lt{'ondisp'};
1441: my $currdisp = $lt{'allposts'};
1442: my $currmark = $lt{'onmark'};
1443:
1444: if ($discdisp eq 'unread') {
1445: $dispchange = $lt{'allposts'};
1446: $currdisp = $lt{'unread'};
1447: $newdisp = 'allposts';
1448: }
1449:
1450: if ($discmark eq 'ondisp') {
1451: $markchange = $lt{'onmark'};
1452: $currmark = $lt{'ondisp'};
1453: $newmark = 'onmark';
1.42 raeburn 1454: }
1.43 raeburn 1455:
1456: $r->print(<<"END");
1.88 albertel 1457: <form name="prefs" action="/adm/preferences" method="post">
1.42 raeburn 1458: <input type="hidden" name="action" value="verify_and_change_discussion" />
1459: <br />
1.87 albertel 1460: $lt{'sdpf'}<br /> $lt{'prca'} <ol><li>$lt{'whpo'}</li><li>$lt{'unwh'}</li></ol>
1.43 raeburn 1461: <br />
1462: <br />
1.82 albertel 1463: END
1464: $r->print(&Apache::loncommon::start_data_table());
1465: $r->print(<<"END");
1466: <tr>
1467: <th>$lt{'pref'}</th>
1468: <th>$lt{'curr'}</th>
1469: <th>$lt{'actn'}?</th>
1.43 raeburn 1470: </tr>
1.82 albertel 1471: END
1472: $r->print(&Apache::loncommon::start_data_table_row());
1473: $r->print(<<"END");
1.43 raeburn 1474: <td>$lt{'disa'}</td>
1475: <td>$lt{$discdisp}</td>
1.82 albertel 1476: <td><label><input type="checkbox" name="discdisp" /><input type="hidden" name="newdisp" value="$newdisp" /> $lt{'chgt'} "$dispchange"</label></td>
1477: END
1478: $r->print(&Apache::loncommon::end_data_table_row().
1479: &Apache::loncommon::start_data_table_row());
1480: $r->print(<<"END");
1.43 raeburn 1481: <td>$lt{'npmr'}</td>
1482: <td>$lt{$discmark}</td>
1.82 albertel 1483: <td><label><input type="checkbox" name="discmark" /><input type="hidden" name="newmark" value="$newmark" /> $lt{'chgt'} "$markchange"</label></td>
1.43 raeburn 1484: </tr>
1.82 albertel 1485: END
1486: $r->print(&Apache::loncommon::end_data_table_row().
1487: &Apache::loncommon::end_data_table());
1488: $r->print(<<"END");
1.43 raeburn 1489: <br />
1490: <br />
1.101 albertel 1491: <input type="submit" name="sub" value="Save Changes" />
1.43 raeburn 1492: <br />
1493: <br />
1494: Note: $lt{'thde'}
1495: </form>
1496: END
1.42 raeburn 1497: }
1498:
1499: sub verify_and_change_discussion {
1500: my $r = shift;
1.59 albertel 1501: my $user = $env{'user.name'};
1502: my $domain = $env{'user.domain'};
1.42 raeburn 1503: my $message='';
1.59 albertel 1504: if (defined($env{'form.discdisp'}) ) {
1505: my $newdisp = $env{'form.newdisp'};
1.43 raeburn 1506: if ($newdisp eq 'unread') {
1.110 bisitz 1507: $message .=&mt('In discussions: only new posts will be displayed.').'<br />';
1.43 raeburn 1508: &Apache::lonnet::put('environment',{'discdisplay' => $newdisp});
1.116 raeburn 1509: &Apache::lonnet::appenv({'environment.discdisplay' => $newdisp});
1.43 raeburn 1510: } else {
1.110 bisitz 1511: $message .= &mt('In discussions: all posts will be displayed.').'<br />';
1.43 raeburn 1512: &Apache::lonnet::del('environment',['discdisplay']);
1513: &Apache::lonnet::delenv('environment\.discdisplay');
1514: }
1515: }
1.59 albertel 1516: if (defined($env{'form.discmark'}) ) {
1517: my $newmark = $env{'form.newmark'};
1.43 raeburn 1518: if ($newmark eq 'ondisp') {
1.110 bisitz 1519: $message.=&mt('In discussions: new posts will be cease to be identified as "NEW" after display.').'<br />';
1.43 raeburn 1520: &Apache::lonnet::put('environment',{'discmarkread' => $newmark});
1.116 raeburn 1521: &Apache::lonnet::appenv({'environment.discmarkread' => $newmark});
1.43 raeburn 1522: } else {
1.110 bisitz 1523: $message.=&mt('In discussions: posts will be identified as "NEW" until marked as read by the reader.').'<br />';
1.43 raeburn 1524: &Apache::lonnet::del('environment',['discmarkread']);
1525: &Apache::lonnet::delenv('environment\.discmarkread');
1526: }
1.42 raeburn 1527: }
1528: $r->print(<<ENDVCSCREEN);
1529: $message
1530: ENDVCSCREEN
1531: }
1532:
1.63 raeburn 1533: ################################################################
1534: # Subroutines for page display on course access (Course Coordinators)
1535: ################################################################
1536: sub coursedisplaychanger {
1537: my $r = shift;
1538: my $user = $env{'user.name'};
1539: my $domain = $env{'user.domain'};
1.66 albertel 1540: my %userenv = &Apache::lonnet::get('environment',['course_init_display']);
1.71 raeburn 1541: my $currvalue = 'whatsnew';
1.73 albertel 1542: my $firstselect = '';
1543: my $whatsnewselect = 'checked="checked"';
1.71 raeburn 1544: if (exists($userenv{'course_init_display'})) {
1545: if ($userenv{'course_init_display'} eq 'firstres') {
1546: $currvalue = 'firstres';
1.73 albertel 1547: $firstselect = 'checked="checked"';
1548: $whatsnewselect = '';
1.71 raeburn 1549: }
1.63 raeburn 1550: }
1.71 raeburn 1551: my %pagenames = (
1552: firstres => 'First resource',
1553: whatsnew => "What's new page",
1554: );
1.70 raeburn 1555: my $whatsnew_off=&mt('Display the [_1] in the course.','<b>first resource</b>');
1556: 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 1557:
1.71 raeburn 1558: $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 1559: $r->print(<<ENDLSCREEN);
1.88 albertel 1560: <form name="prefs" action="/adm/preferences" method="post">
1.63 raeburn 1561: <input type="hidden" name="action" value="verify_and_change_coursepage" />
1.72 albertel 1562: <br />
1.65 albertel 1563: <label><input type="radio" name="newdisp" value="firstres" $firstselect /> $whatsnew_off</label><br />
1.70 raeburn 1564: <label><input type="radio" name="newdisp" value="whatsnew" $whatsnewselect /> $whatsnew_on</label><input type="hidden" name="refpage" value="$env{'form.refpage'}" />
1.63 raeburn 1565: ENDLSCREEN
1.70 raeburn 1566: $r->print('<br /><br /><input type="submit" value="'.&mt('Change').'" />
1.63 raeburn 1567: </form>');
1568: }
1569:
1570: sub verify_and_change_coursepage {
1571: my $r = shift;
1572: my $message='';
1573: my %lt = &Apache::lonlocal::texthash(
1.70 raeburn 1574: 'defs' => 'Default now set',
1.71 raeburn 1575: 'when' => 'when you select a course role from the roles screen',
1.63 raeburn 1576: 'ywbt' => 'you will be taken to the start of the course.',
1577: 'apwb' => 'a page will be displayed that lists items in the course that may require action from you.',
1578: 'gtts' => 'Go to the start of the course',
1.70 raeburn 1579: 'dasp' => "Display the What's New page listing course action items",
1.63 raeburn 1580: );
1581: my $newdisp = $env{'form.newdisp'};
1.70 raeburn 1582: $message = '<b>'.$lt{'defs'}.'</b>: '.$lt{'when'}.', ';
1.63 raeburn 1583: if ($newdisp eq 'firstres') {
1.87 albertel 1584: $message .= $lt{'ywbt'}.'<br />';
1.63 raeburn 1585: &Apache::lonnet::put('environment',{'course_init_display' => $newdisp});
1.116 raeburn 1586: &Apache::lonnet::appenv({'environment.course_init_display' => $newdisp});
1.63 raeburn 1587: } else {
1.87 albertel 1588: $message .= $lt{'apwb'}.'<br />';
1.63 raeburn 1589: &Apache::lonnet::del('environment',['course_init_display']);
1590: &Apache::lonnet::delenv('environment\.course_init_display');
1591: }
1.70 raeburn 1592: my $refpage = $env{'form.refpage'};
1.63 raeburn 1593: if (($env{'request.course.fn'}) && ($env{'request.course.id'})) {
1594: if ($newdisp eq 'firstres') {
1595: my $cdom = $env{'course.'.$env{'request.course.id'}.'.domain'};
1596: my $cnum = $env{'course.'.$env{'request.course.id'}.'.num'};
1597: my ($furl,$ferr)=
1598: &Apache::lonuserstate::readmap($cdom.'/'.$cnum);
1599: $message .= '<br /><font size="+1"><a href="'.$furl.'">'.$lt{'gtts'}.' <i>'.&mt('now').'</i></a></font>';
1600: } else {
1.70 raeburn 1601: $message .= '<br /><font size="+1"><a href="/adm/whatsnew?refpage='.
1602: $refpage.'">'.$lt{'dasp'}.'</a></font>';
1.63 raeburn 1603: }
1604: }
1605: $r->print(<<ENDVCSCREEN);
1606: $message
1607: <br /><br />
1608: ENDVCSCREEN
1609: }
1610:
1611:
1.4 matthew 1612: ######################################################
1613: # other handler subroutines #
1614: ######################################################
1615:
1.3 matthew 1616: ################################################################
1617: # Main handler #
1618: ################################################################
1.1 www 1619: sub handler {
1620: my $r = shift;
1.59 albertel 1621: my $user = $env{'user.name'};
1622: my $domain = $env{'user.domain'};
1.31 www 1623: &Apache::loncommon::content_type($r,'text/html');
1.4 matthew 1624: # Some pages contain DES keys and should not be cached.
1625: &Apache::loncommon::no_cache($r);
1.1 www 1626: $r->send_http_header;
1627: return OK if $r->header_only;
1.9 matthew 1628: #
1.35 matthew 1629: &Apache::loncommon::get_unprocessed_cgi($ENV{'QUERY_STRING'},
1.70 raeburn 1630: ['action','wysiwyg','returnurl','refpage']);
1.35 matthew 1631: #
1632: &Apache::lonhtmlcommon::clear_breadcrumbs();
1633: &Apache::lonhtmlcommon::add_breadcrumb
1634: ({href => '/adm/preferences',
1635: text => 'Set User Preferences'});
1636:
1637: my @Options;
1638: # Determine current authentication method
1639: my $currentauth=&Apache::lonnet::queryauthenticate($user,$domain);
1640: if ($currentauth =~ /^(unix|internal):/) {
1641: push (@Options,({ action => 'changepass',
1.40 www 1642: linktext => 'Change Password',
1.35 matthew 1643: href => '/adm/preferences',
1644: help => 'Change_Password',
1645: subroutine => \&passwordchanger,
1646: breadcrumb =>
1647: { href => '/adm/preferences?action=changepass',
1648: text => 'Change Password'},
1649: },
1650: { action => 'verify_and_change_pass',
1651: subroutine => \&verify_and_change_password,
1652: breadcrumb =>
1653: { href =>'/adm/preferences?action=changepass',
1654: text => 'Change Password'},
1.75 albertel 1655: printmenu => 'not_on_error',
1.35 matthew 1656: }));
1657: }
1658: push (@Options,({ action => 'changescreenname',
1659: linktext => 'Change Screen Name',
1660: href => '/adm/preferences',
1661: help => 'Prefs_Screen_Name_Nickname',
1662: subroutine => \&screennamechanger,
1663: breadcrumb =>
1664: { href => '/adm/preferences?action=changescreenname',
1665: text => 'Change Screen Name'},
1666: },
1667: { action => 'verify_and_change_screenname',
1668: subroutine => \&verify_and_change_screenname,
1669: breadcrumb =>
1670: { href => '/adm/preferences?action=changescreenname',
1671: text => 'Change Screen Name'},
1672: printmenu => 'yes',
1673: }));
1674:
1675: push (@Options,({ action => 'changemsgforward',
1.97 raeburn 1676: linktext => 'Change Message Forwarding and Notification Email Addresses',
1.35 matthew 1677: href => '/adm/preferences',
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.35 matthew 1682: subroutine => \&msgforwardchanger,
1683: },
1684: { action => 'verify_and_change_msgforward',
1.113 raeburn 1685: help => 'Prefs_Messages',
1.35 matthew 1686: breadcrumb =>
1687: { href => '/adm/preferences?action=changemsgforward',
1.113 raeburn 1688: text => 'Change Message Forwarding/Notification'},
1.102 raeburn 1689: printmenu => 'no',
1.35 matthew 1690: subroutine => \&verify_and_change_msgforward }));
1691: my $aboutmeaction=
1.59 albertel 1692: '/adm/'.$env{'user.domain'}.'/'.$env{'user.name'}.'/aboutme';
1.35 matthew 1693: push (@Options,{ action => 'none',
1694: linktext =>
1.41 www 1695: q{Edit the 'About Me' Personal Information Screen},
1.45 www 1696: help => 'Prefs_About_Me',
1.35 matthew 1697: href => $aboutmeaction});
1698: push (@Options,({ action => 'changecolors',
1699: linktext => 'Change Color Scheme',
1700: href => '/adm/preferences',
1701: help => 'Change_Colors',
1702: breadcrumb =>
1703: { href => '/adm/preferences?action=changecolors',
1704: text => 'Change Colors'},
1705: subroutine => \&colorschanger,
1706: },
1707: { action => 'verify_and_change_colors',
1708: breadcrumb =>
1709: { href => '/adm/preferences?action=changecolors',
1710: text => 'Change Colors'},
1711: printmenu => 'yes',
1712: subroutine => \&verify_and_change_colors,
1713: }));
1714: push (@Options,({ action => 'changelanguages',
1.39 www 1715: linktext => 'Change Language Preferences',
1.35 matthew 1716: href => '/adm/preferences',
1.45 www 1717: help => 'Prefs_Language',
1.35 matthew 1718: breadcrumb=>
1719: { href => '/adm/preferences?action=changelanguages',
1720: text => 'Change Language'},
1721: subroutine => \&languagechanger,
1722: },
1723: { action => 'verify_and_change_languages',
1724: breadcrumb=>
1725: {href => '/adm/preferences?action=changelanguages',
1726: text => 'Change Language'},
1727: printmenu => 'yes',
1728: subroutine=>\&verify_and_change_languages, }
1729: ));
1.44 www 1730: push (@Options,({ action => 'changewysiwyg',
1731: linktext => 'Change WYSIWYG Editor Preferences',
1732: href => '/adm/preferences',
1733: breadcrumb =>
1734: { href => '/adm/preferences?action=changewysiwyg',
1735: text => 'Change WYSIWYG Preferences'},
1736: subroutine => \&wysiwygchanger,
1737: },
1738: { action => 'set_wysiwyg',
1739: breadcrumb =>
1740: { href => '/adm/preferences?action=changewysiwyg',
1741: text => 'Change WYSIWYG Preferences'},
1742: printmenu => 'yes',
1743: subroutine => \&verify_and_change_wysiwyg, }
1744: ));
1.42 raeburn 1745: push (@Options,({ action => 'changediscussions',
1746: linktext => 'Change Discussion Display Preferences',
1747: href => '/adm/preferences',
1.46 raeburn 1748: help => 'Change_Discussion_Display',
1.42 raeburn 1749: breadcrumb =>
1750: { href => '/adm/preferences?action=changediscussions',
1.43 raeburn 1751: text => 'Change Discussion Preferences'},
1.42 raeburn 1752: subroutine => \&discussionchanger,
1753: },
1754: { action => 'verify_and_change_discussion',
1755: breadcrumb =>
1756: { href => '/adm/preferences?action=changediscussions',
1.43 raeburn 1757: text => 'Change Discussion Preferences'},
1.42 raeburn 1758: printmenu => 'yes',
1759: subroutine => \&verify_and_change_discussion, }
1760: ));
1.96 albertel 1761:
1762: my $role = ($env{'user.adv'} ? 'Roles' : 'Course');
1.50 albertel 1763: push (@Options,({ action => 'changerolespref',
1.96 albertel 1764: linktext => 'Change '.$role.' Page Preferences',
1.50 albertel 1765: href => '/adm/preferences',
1766: subroutine => \&rolesprefchanger,
1767: breadcrumb =>
1768: { href => '/adm/preferences?action=changerolespref',
1.96 albertel 1769: text => 'Change '.$role.' Page Pref'},
1.50 albertel 1770: },
1771: { action => 'verify_and_change_rolespref',
1772: subroutine => \&verify_and_change_rolespref,
1773: breadcrumb =>
1774: { href => '/adm/preferences?action=changerolespref',
1.96 albertel 1775: text => 'Change '.$role.' Page Preferences'},
1.50 albertel 1776: printmenu => 'yes',
1777: }));
1778:
1.54 albertel 1779: push (@Options,({ action => 'changetexenginepref',
1780: linktext => 'Change How Math Equations Are Displayed',
1781: href => '/adm/preferences',
1782: subroutine => \&texenginechanger,
1783: breadcrumb =>
1784: { href => '/adm/preferences?action=changetexenginepref',
1785: text => 'Change Math Pref'},
1786: },
1787: { action => 'verify_and_change_texengine',
1788: subroutine => \&verify_and_change_texengine,
1789: breadcrumb =>
1790: { href => '/adm/preferences?action=changetexenginepref',
1791: text => 'Change Math Preferences'},
1792: printmenu => 'yes',
1793: }));
1.85 albertel 1794:
1795: if ($env{'environment.remote'} eq 'off') {
1796: push (@Options,({ action => 'launch',
1797: linktext => 'Launch Remote Control',
1798: href => '/adm/remote?url=/adm/preferences',
1799: }));
1800: } else {
1801: push (@Options,({ action => 'collapse',
1802: linktext => 'Collapse Remote Control',
1803: href => '/adm/remote?url=/adm/preferences',
1804: }));
1805: }
1806:
1.98 www 1807: push (@Options,({ action => 'changeicons',
1.100 www 1808: linktext => 'Change How Menus are Displayed',
1.98 www 1809: href => '/adm/preferences',
1810: subroutine => \&iconchanger,
1811: breadcrumb =>
1812: { href => '/adm/preferences?action=changeicons',
1813: text => 'Change Main Menu'},
1814: },
1815: { action => 'verify_and_change_icons',
1816: subroutine => \&verify_and_change_icons,
1817: breadcrumb =>
1818: { href => '/adm/preferences?action=changeicons',
1819: text => 'Change Main Menu'},
1820: printmenu => 'yes',
1821: }));
1822:
1.106 www 1823: push (@Options,({ action => 'changeclicker',
1824: linktext => 'Register Response Devices ("Clickers")',
1825: href => '/adm/preferences',
1826: subroutine => \&clickerchanger,
1827: breadcrumb =>
1828: { href => '/adm/preferences?action=changeicons',
1829: text => 'Register Clicker'},
1830: },
1831: { action => 'verify_and_change_clicker',
1832: subroutine => \&verify_and_change_clicker,
1833: breadcrumb =>
1834: { href => '/adm/preferences?action=changeclicker',
1835: text => 'Register Clicker'},
1836: printmenu => 'yes',
1837: }));
1.105 www 1838:
1839:
1.74 albertel 1840: if (&Apache::lonnet::allowed('whn',$env{'request.course.id'})
1841: || &Apache::lonnet::allowed('whn',$env{'request.course.id'}.'/'
1842: .$env{'request.course.sec'})) {
1.63 raeburn 1843: push (@Options,({ action => 'changecourseinit',
1844: linktext => 'Change Course Initialization Preference',
1845: href => '/adm/preferences',
1846: subroutine => \&coursedisplaychanger,
1847: breadcrumb =>
1848: { href => '/adm/preferences?action=changecourseinit',
1849: text => 'Change Course Init. Pref.'},
1850: },
1851: { action => 'verify_and_change_coursepage',
1852: breadcrumb =>
1853: { href => '/adm/preferences?action=changecourseinit', text => 'Change Course Initialization Preference'},
1854: printmenu => 'yes',
1855: subroutine => \&verify_and_change_coursepage,
1856: }));
1857: }
1.50 albertel 1858:
1.62 raeburn 1859: if ($env{'user.name'} =~ /^(albertel|fox|foxr|koretemey|korte|hallmat3|turtle|raeburn)$/) {
1.35 matthew 1860: push (@Options,({ action => 'debugtoggle',
1861: printmenu => 'yes',
1862: subroutine => \&toggle_debug,
1863: }));
1864: }
1.76 albertel 1865:
1866: $r->print(&Apache::loncommon::start_page('Change Preferences'));
1867:
1.35 matthew 1868: my $call = undef;
1.48 albertel 1869: my $help = undef;
1.35 matthew 1870: my $printmenu = 'yes';
1871: foreach my $option (@Options) {
1.59 albertel 1872: if ($option->{'action'} eq $env{'form.action'}) {
1.35 matthew 1873: $call = $option->{'subroutine'};
1874: $printmenu = $option->{'printmenu'};
1875: if (exists($option->{'breadcrumb'})) {
1876: &Apache::lonhtmlcommon::add_breadcrumb
1877: ($option->{'breadcrumb'});
1878: }
1.48 albertel 1879: $help=$option->{'help'};
1.35 matthew 1880: }
1881: }
1.81 albertel 1882: $r->print(&Apache::lonhtmlcommon::breadcrumbs('Change Preferences',$help));
1.75 albertel 1883: my $error;
1.35 matthew 1884: if (defined($call)) {
1.75 albertel 1885: $error = $call->($r);
1.35 matthew 1886: }
1.75 albertel 1887: if ( ( ($printmenu eq 'yes')
1888: || ($printmenu eq 'not_on_error' && !$error) )
1889: && (!$env{'form.returnurl'})) {
1.35 matthew 1890: my $optionlist = '<table cellpadding="5">';
1.59 albertel 1891: if ($env{'user.name'} =~
1.62 raeburn 1892: /^(albertel|kortemey|fox|foxr|korte|hallmat3|turtle|raeburn)$/
1.35 matthew 1893: ) {
1894: push (@Options,({ action => 'debugtoggle',
1895: linktext => 'Toggle Debug Messages',
1896: text => 'Current Debug status is -'.
1.59 albertel 1897: $env{'user.debug'}.'-.',
1.35 matthew 1898: href => '/adm/preferences',
1899: printmenu => 'yes',
1900: subroutine => \&toggle_debug,
1901: }));
1902: }
1903: foreach my $option(@Options) {
1904: my $optiontext = '';
1905: if (exists($option->{'href'})) {
1.85 albertel 1906: $option->{'href_args'}{'action'}=$option->{'action'};
1907: $optiontext .=
1908: '<a href="'.&add_get_param($option->{'href'},
1909: $option->{'href_args'}).'">'.
1.47 albertel 1910: &mt($option->{'linktext'}).'</a>';
1.35 matthew 1911: }
1912: if (exists($option->{'text'})) {
1.47 albertel 1913: $optiontext .= ' '.&mt($option->{'text'});
1.35 matthew 1914: }
1915: if ($optiontext ne '') {
1916: $optiontext = '<font size="+1">'.$optiontext.'</font>';
1917: my $helplink = ' ';
1918: if (exists($option->{'help'})) {
1919: $helplink = &Apache::loncommon::help_open_topic
1920: ($option->{'help'});
1921: }
1922: $optionlist .= '<tr>'.
1923: '<td>'.$helplink.'</td>'.
1924: '<td>'.$optiontext.'</td>'.
1925: '</tr>';
1926: }
1.13 www 1927: }
1.35 matthew 1928: $optionlist .= '</table>';
1929: $r->print($optionlist);
1.59 albertel 1930: } elsif ($env{'form.returnurl'}) {
1931: $r->print('<br /><a href="'.$env{'form.returnurl'}.'"><font size="+1">'.
1.44 www 1932: &mt('Return').'</font></a>');
1.3 matthew 1933: }
1.76 albertel 1934: $r->print(&Apache::loncommon::end_page());
1.1 www 1935: return OK;
1.35 matthew 1936: }
1937:
1938: sub toggle_debug {
1.59 albertel 1939: if ($env{'user.debug'}) {
1.35 matthew 1940: &Apache::lonnet::delenv('user\.debug');
1941: } else {
1.116 raeburn 1942: &Apache::lonnet::appenv({'user.debug' => 1});
1.35 matthew 1943: }
1.13 www 1944: }
1.1 www 1945:
1946: 1;
1947: __END__
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>