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