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