1: # The LearningOnline Network
2: # Preferences
3: #
4: # $Id: lonpreferences.pm,v 1.87 2006/06/14 18:54:23 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: $r->print(<<ENDSCREEN);
302: <p>Some LON-CAPA users have a long list of roles. The Recent Roles Hotlist
303: feature keeps track of the last N roles which have been
304: visited and places a table of these at the top of the roles page.
305: People with very few roles should leave this feature disabled.
306: </p>
307:
308: <form name="prefs" action="/adm/preferences" method="POST">
309: <input type="hidden" name="action" value="verify_and_change_rolespref" />
310: <br /><label>Enable Recent Roles Hotlist:
311: <input type="checkbox" $checked name="recentroles" value="true" /></label>
312: <br />Number of roles in Hotlist:
313: <select name="recentrolesn" size="1">
314: $options
315: </select>
316: <br />
317: <input type="submit" value="Change" />
318: </form>
319: ENDSCREEN
320: }
321:
322: sub verify_and_change_rolespref {
323: my $r = shift;
324: my $user = $env{'user.name'};
325: my $domain = $env{'user.domain'};
326: # Recent Roles Hotlist Flag
327: my $hotlist_flag = $env{'form.recentroles'};
328: my $hotlist_n = $env{'form.recentrolesn'};
329: my $message='';
330: if ($hotlist_flag) {
331: &Apache::lonnet::put('environment',{'recentroles' => $hotlist_flag});
332: &Apache::lonnet::appenv('environment.recentroles' => $hotlist_flag);
333: $message='Recent Roles Hotlist is Enabled';
334: } else {
335: &Apache::lonnet::del('environment',['recentroles']);
336: &Apache::lonnet::delenv('environment\.recentroles');
337: $message='Recent Roles Hotlist is Disabled';
338: }
339: if ($hotlist_n) {
340: &Apache::lonnet::put('environment',{'recentrolesn' => $hotlist_n});
341: &Apache::lonnet::appenv('environment.recentrolesn' => $hotlist_n);
342: if ($hotlist_flag) {
343: $message.="<br />Display $hotlist_n Most Recent Roles\n";
344: }
345: }
346:
347: $r->print(<<ENDRPSCREEN);
348: $message
349: ENDRPSCREEN
350: }
351:
352:
353:
354: ################################################################
355: # Anonymous Discussion Name Change Subroutines #
356: ################################################################
357: sub screennamechanger {
358: my $r = shift;
359: my $user = $env{'user.name'};
360: my $domain = $env{'user.domain'};
361: my %userenv = &Apache::lonnet::get
362: ('environment',['screenname','nickname']);
363: my $screenname=$userenv{'screenname'};
364: my $nickname=$userenv{'nickname'};
365: $r->print(<<ENDSCREEN);
366: <form name="prefs" action="/adm/preferences" method="POST">
367: <input type="hidden" name="action" value="verify_and_change_screenname" />
368: <br />New screenname (shown if you post anonymously):
369: <input type="text" size="20" value="$screenname" name="screenname" />
370: <br />New nickname (shown if you post non-anonymously):
371: <input type="text" size="20" value="$nickname" name="nickname" />
372: <input type="submit" value="Change" />
373: </form>
374: ENDSCREEN
375: }
376:
377: sub verify_and_change_screenname {
378: my $r = shift;
379: my $user = $env{'user.name'};
380: my $domain = $env{'user.domain'};
381: # Screenname
382: my $newscreen = $env{'form.screenname'};
383: $newscreen=~s/[^ \w]//g;
384: my $message='';
385: if ($newscreen) {
386: &Apache::lonnet::put('environment',{'screenname' => $newscreen});
387: &Apache::lonnet::appenv('environment.screenname' => $newscreen);
388: $message='Set new screenname to '.$newscreen;
389: } else {
390: &Apache::lonnet::del('environment',['screenname']);
391: &Apache::lonnet::delenv('environment\.screenname');
392: $message='Reset screenname';
393: }
394: # Nickname
395: $message.='<br />';
396: $newscreen = $env{'form.nickname'};
397: $newscreen=~s/[^ \w]//g;
398: if ($newscreen) {
399: &Apache::lonnet::put('environment',{'nickname' => $newscreen});
400: &Apache::lonnet::appenv('environment.nickname' => $newscreen);
401: $message.='Set new nickname to '.$newscreen;
402: } else {
403: &Apache::lonnet::del('environment',['nickname']);
404: &Apache::lonnet::delenv('environment\.nickname');
405: $message.='Reset nickname';
406: }
407: &Apache::lonnet::devalidate_cache_new('namescache',$user.':'.$domain);
408: $r->print(<<ENDVCSCREEN);
409: $message
410: ENDVCSCREEN
411: }
412:
413: ################################################################
414: # Message Forward #
415: ################################################################
416:
417: sub msgforwardchanger {
418: my $r = shift;
419: my $user = $env{'user.name'};
420: my $domain = $env{'user.domain'};
421: my %userenv = &Apache::lonnet::get('environment',['msgforward','notification','critnotification']);
422: my $msgforward=$userenv{'msgforward'};
423: my $notification=$userenv{'notification'};
424: my $critnotification=$userenv{'critnotification'};
425: my $forwardingHelp = Apache::loncommon::help_open_topic("Prefs_Forwarding",
426: "What are forwarding ".
427: "and notification ".
428: "addresses");
429: my $criticalMessageHelp = Apache::loncommon::help_open_topic("Course_Critical_Message",
430: "What are critical messages");
431:
432: $r->print(<<ENDMSG);
433: $forwardingHelp <br />
434: <form name="prefs" action="/adm/preferences" method="POST">
435: <input type="hidden" name="action" value="verify_and_change_msgforward" />
436: New Forwarding Address(es) (<tt>user:domain,user:domain,...</tt>):
437: <input type="text" size="40" value="$msgforward" name="msgforward" /><hr />
438: New Message Notification Email Address(es) (<tt>joe\@doe.com,jane\@doe.edu,...</tt>):
439: <input type="text" size="40" value="$notification" name="notification" /><hr />
440: New Critical Message Notification Email Address(es) (<tt>joe\@doe.com,jane\@doe.edu,...</tt>):
441: <input type="text" size="40" value="$critnotification" name="critnotification" />$criticalMessageHelp<hr />
442: <input type="submit" value="Change" />
443: </form>
444: ENDMSG
445: }
446:
447: sub verify_and_change_msgforward {
448: my $r = shift;
449: my $user = $env{'user.name'};
450: my $domain = $env{'user.domain'};
451: my $newscreen = '';
452: my $message='';
453: foreach (split(/\,/,$env{'form.msgforward'})) {
454: my ($msuser,$msdomain)=split(/[\@\:]/,$_);
455: $msuser=~s/\W//g;
456: $msdomain=~s/\W//g;
457: if (($msuser) && ($msdomain)) {
458: if (&Apache::lonnet::homeserver($msuser,$msdomain) ne 'no_host') {
459: $newscreen.=$msuser.':'.$msdomain.',';
460: } else {
461: $message.='No such user: '.$msuser.':'.$msdomain.'<br>';
462: }
463: }
464: }
465: $newscreen=~s/\,$//;
466: if ($newscreen) {
467: &Apache::lonnet::put('environment',{'msgforward' => $newscreen});
468: &Apache::lonnet::appenv('environment.msgforward' => $newscreen);
469: $message.='Set new message forwarding to '.$newscreen.'<br />';
470: } else {
471: &Apache::lonnet::del('environment',['msgforward']);
472: &Apache::lonnet::delenv('environment\.msgforward');
473: $message.='Reset message forwarding<br />';
474: }
475: my $notification=$env{'form.notification'};
476: $notification=~s/\s//gs;
477: if ($notification) {
478: &Apache::lonnet::put('environment',{'notification' => $notification});
479: &Apache::lonnet::appenv('environment.notification' => $notification);
480: $message.='Set message notification address to '.$notification.'<br />';
481: } else {
482: &Apache::lonnet::del('environment',['notification']);
483: &Apache::lonnet::delenv('environment\.notification');
484: $message.='Reset message notification<br />';
485: }
486: my $critnotification=$env{'form.critnotification'};
487: $critnotification=~s/\s//gs;
488: if ($critnotification) {
489: &Apache::lonnet::put('environment',{'critnotification' => $critnotification});
490: &Apache::lonnet::appenv('environment.critnotification' => $critnotification);
491: $message.='Set critical message notification address to '.$critnotification;
492: } else {
493: &Apache::lonnet::del('environment',['critnotification']);
494: &Apache::lonnet::delenv('environment\.critnotification');
495: $message.='Reset critical message notification<br />';
496: }
497: $r->print(<<ENDVCMSG);
498: $message
499: ENDVCMSG
500: }
501:
502: ################################################################
503: # Colors #
504: ################################################################
505:
506: sub colorschanger {
507: my $r = shift;
508: # figure out colors
509: my $function=&Apache::loncommon::get_users_function();
510: my $domain=&Apache::loncommon::determinedomain();
511: my %colortypes=('pgbg' => 'Page Background',
512: 'tabbg' => 'Header Background',
513: 'sidebg'=> 'Header Border',
514: 'font' => 'Font',
515: 'link' => 'Un-Visited Link',
516: 'vlink' => 'Visited Link',
517: 'alink' => 'Active Link');
518: my $start_data_table = &Apache::loncommon::start_data_table();
519: my $chtable='';
520: foreach my $item (sort(keys(%colortypes))) {
521: my $curcol=&Apache::loncommon::designparm($function.'.'.$item,$domain);
522: $chtable.=&Apache::loncommon::start_data_table_row().
523: '<td>'.$colortypes{$item}.'</td><td style="background: '.$curcol.
524: '"> </td><td><input name="'.$item.
525: '" size="10" value="'.$curcol.
526: '" /></td><td><a href="javascript:pjump('."'color_custom','".$colortypes{$item}.
527: "','".$curcol."','"
528: .$item."','parmform.pres','psub'".');">Select</a></td>'.
529: &Apache::loncommon::end_data_table_row()."\n";
530: }
531: my $end_data_table = &Apache::loncommon::end_data_table();
532: my $pjump_def = &Apache::lonhtmlcommon::pjump_javascript_definition();
533: $r->print(<<ENDCOL);
534: <script type="text/javascript">
535:
536: function pclose() {
537: parmwin=window.open("/adm/rat/empty.html","LONCAPAparms",
538: "height=350,width=350,scrollbars=no,menubar=no");
539: parmwin.close();
540: }
541:
542: $pjump_def
543:
544: function psub() {
545: pclose();
546: if (document.parmform.pres_marker.value!='') {
547: if (document.parmform.pres_type.value!='') {
548: eval('document.prefs.'+
549: document.parmform.pres_marker.value+
550: '.value=document.parmform.pres_value.value;');
551: }
552: } else {
553: document.parmform.pres_value.value='';
554: document.parmform.pres_marker.value='';
555: }
556: }
557:
558:
559: </script>
560: <form name="parmform">
561: <input type="hidden" name="pres_marker" />
562: <input type="hidden" name="pres_type" />
563: <input type="hidden" name="pres_value" />
564: </form>
565: <form name="prefs" action="/adm/preferences" method="POST">
566: <input type="hidden" name="action" value="verify_and_change_colors" />
567: $start_data_table
568: $chtable
569: $end_data_table
570: </table>
571: <input type="submit" value="Change Custom Colors" />
572: <input type="submit" name="resetall" value="Reset All Colors to Default" />
573: </form>
574: ENDCOL
575: }
576:
577: sub verify_and_change_colors {
578: my $r = shift;
579: # figure out colors
580: my $function=&Apache::loncommon::get_users_function();
581: my $domain=&Apache::loncommon::determinedomain();
582: my %colortypes=('pgbg' => 'Page Background',
583: 'tabbg' => 'Header Background',
584: 'sidebg'=> 'Header Border',
585: 'font' => 'Font',
586: 'link' => 'Un-Visited Link',
587: 'vlink' => 'Visited Link',
588: 'alink' => 'Active Link');
589:
590: my $message='';
591: foreach my $item (keys %colortypes) {
592: my $color=$env{'form.'.$item};
593: my $entry='color.'.$function.'.'.$item;
594: if (($color=~/^\#[0-9A-Fa-f]{6}$/) && (!$env{'form.resetall'})) {
595: &Apache::lonnet::put('environment',{$entry => $color});
596: &Apache::lonnet::appenv('environment.'.$entry => $color);
597: $message.='Set '.$colortypes{$item}.' to '.$color.'<br />';
598: } else {
599: &Apache::lonnet::del('environment',[$entry]);
600: &Apache::lonnet::delenv('environment\.'.$entry);
601: $message.='Reset '.$colortypes{$item}.'<br />';
602: }
603: }
604: my $now = time;
605: &Apache::lonnet::put('environment',{'color.timestamp' => $now});
606: &Apache::lonnet::appenv('environment.color.timestamp' => $now);
607:
608: $r->print(<<ENDVCCOL);
609: $message
610: <form name="client" action="/adm/preferences" method="POST">
611: <input type="hidden" name="action" value="changecolors" />
612: </form>
613: ENDVCCOL
614: }
615:
616: ######################################################
617: # password handler subroutines #
618: ######################################################
619: sub passwordchanger {
620: # This function is a bit of a mess....
621: # Passwords are encrypted using londes.js (DES encryption)
622: my $r = shift;
623: my $errormessage = shift;
624: $errormessage = ($errormessage || '');
625: my $user = $env{'user.name'};
626: my $domain = $env{'user.domain'};
627: my $homeserver = $env{'user.home'};
628: my $currentauth=&Apache::lonnet::queryauthenticate($user,$domain);
629: # Check for authentication types that allow changing of the password.
630: return if ($currentauth !~ /^(unix|internal):/);
631: #
632: # Generate keys
633: my ($lkey_cpass ,$ukey_cpass ) = &des_keys();
634: my ($lkey_npass1,$ukey_npass1) = &des_keys();
635: my ($lkey_npass2,$ukey_npass2) = &des_keys();
636: # Store the keys in the log files
637: my $lonhost = $r->dir_config('lonHostID');
638: my $logtoken=Apache::lonnet::reply('tmpput:'
639: .$ukey_cpass . $lkey_cpass .'&'
640: .$ukey_npass1 . $lkey_npass1.'&'
641: .$ukey_npass2 . $lkey_npass2,
642: $lonhost);
643: # Hexify the keys for output as javascript variables
644: $ukey_cpass = hex($ukey_cpass);
645: $lkey_cpass = hex($lkey_cpass);
646: $ukey_npass1= hex($ukey_npass1);
647: $lkey_npass1= hex($lkey_npass1);
648: $ukey_npass2= hex($ukey_npass2);
649: $lkey_npass2= hex($lkey_npass2);
650: # Output javascript to deal with passwords
651: # Output DES javascript
652: {
653: my $include = $r->dir_config('lonIncludes');
654: my $jsh=Apache::File->new($include."/londes.js");
655: $r->print(<$jsh>);
656: }
657: $r->print(<<ENDFORM);
658: <script language="JavaScript">
659:
660: function send() {
661: uextkey=this.document.client.elements.ukey_cpass.value;
662: lextkey=this.document.client.elements.lkey_cpass.value;
663: initkeys();
664:
665: this.document.pserver.elements.currentpass.value
666: =crypted(this.document.client.elements.currentpass.value);
667:
668: uextkey=this.document.client.elements.ukey_npass1.value;
669: lextkey=this.document.client.elements.lkey_npass1.value;
670: initkeys();
671: this.document.pserver.elements.newpass_1.value
672: =crypted(this.document.client.elements.newpass_1.value);
673:
674: uextkey=this.document.client.elements.ukey_npass2.value;
675: lextkey=this.document.client.elements.lkey_npass2.value;
676: initkeys();
677: this.document.pserver.elements.newpass_2.value
678: =crypted(this.document.client.elements.newpass_2.value);
679:
680: this.document.pserver.submit();
681: }
682:
683: </script>
684: $errormessage
685:
686: <p>
687: <!-- We separate the forms into 'server' and 'client' in order to
688: ensure that unencrypted passwords will not be sent out by a
689: crappy browser -->
690:
691: <form name="pserver" action="/adm/preferences" method="POST">
692: <input type="hidden" name="logtoken" value="$logtoken" />
693: <input type="hidden" name="action" value="verify_and_change_pass" />
694: <input type="hidden" name="currentpass" value="" />
695: <input type="hidden" name="newpass_1" value="" />
696: <input type="hidden" name="newpass_2" value="" />
697: </form>
698:
699: <form name="client" >
700: <table>
701: <tr><td align="right"> Current password: </td>
702: <td><input type="password" name="currentpass" size="10"/> </td></tr>
703: <tr><td align="right"> New password: </td>
704: <td><input type="password" name="newpass_1" size="10" /> </td></tr>
705: <tr><td align="right"> Confirm password: </td>
706: <td><input type="password" name="newpass_2" size="10" /> </td></tr>
707: <tr><td colspan="2" align="center">
708: <input type="button" value="Change Password" onClick="send();">
709: </table>
710: <input type="hidden" name="ukey_cpass" value="$ukey_cpass" />
711: <input type="hidden" name="lkey_cpass" value="$lkey_cpass" />
712: <input type="hidden" name="ukey_npass1" value="$ukey_npass1" />
713: <input type="hidden" name="lkey_npass1" value="$lkey_npass1" />
714: <input type="hidden" name="ukey_npass2" value="$ukey_npass2" />
715: <input type="hidden" name="lkey_npass2" value="$lkey_npass2" />
716: </form>
717: </p>
718: ENDFORM
719: #
720: return;
721: }
722:
723: sub verify_and_change_password {
724: my $r = shift;
725: my $user = $env{'user.name'};
726: my $domain = $env{'user.domain'};
727: my $homeserver = $env{'user.home'};
728: my $currentauth=&Apache::lonnet::queryauthenticate($user,$domain);
729: # Check for authentication types that allow changing of the password.
730: return if ($currentauth !~ /^(unix|internal):/);
731: #
732: my $currentpass = $env{'form.currentpass'};
733: my $newpass1 = $env{'form.newpass_1'};
734: my $newpass2 = $env{'form.newpass_2'};
735: my $logtoken = $env{'form.logtoken'};
736: # Check for empty data
737: unless (defined($currentpass) &&
738: defined($newpass1) &&
739: defined($newpass2) ){
740: &passwordchanger($r,"<p>\n<font color='#ff0000'>ERROR</font>".
741: "Password data was blank.\n</p>");
742: return;
743: }
744: # Get the keys
745: my $lonhost = $r->dir_config('lonHostID');
746: my $tmpinfo = Apache::lonnet::reply('tmpget:'.$logtoken,$lonhost);
747: if (($tmpinfo=~/^error/) || ($tmpinfo eq 'con_lost')) {
748: # I do not a have a better idea about how to handle this
749: $r->print(<<ENDERROR);
750: <p>
751: <font color="#ff0000">ERROR:</font> Unable to retrieve stored token for
752: password decryption. Please log out and try again.
753: </p>
754: ENDERROR
755: # Probably should log an error here
756: return 1;
757: }
758: my ($ckey,$n1key,$n2key)=split(/&/,$tmpinfo);
759: #
760: $currentpass = &des_decrypt($ckey ,$currentpass);
761: $newpass1 = &des_decrypt($n1key,$newpass1);
762: $newpass2 = &des_decrypt($n2key,$newpass2);
763: #
764: if ($newpass1 ne $newpass2) {
765: &passwordchanger($r,
766: '<font color="#ff0000">ERROR:</font>'.
767: 'The new passwords you entered do not match. '.
768: 'Please try again.');
769: return 1;
770: }
771: if (length($newpass1) < 7) {
772: &passwordchanger($r,
773: '<font color="#ff0000">ERROR:</font>'.
774: 'Passwords must be a minimum of 7 characters long. '.
775: 'Please try again.');
776: return 1;
777: }
778: #
779: # Check for bad characters
780: my $badpassword = 0;
781: foreach (split(//,$newpass1)) {
782: $badpassword = 1 if ((ord($_)<32)||(ord($_)>126));
783: }
784: if ($badpassword) {
785: # I can't figure out how to enter bad characters on my browser.
786: &passwordchanger($r,<<ENDERROR);
787: <font color="#ff0000">ERROR:</font>
788: The password you entered contained illegal characters.<br />
789: Valid characters are: space and <br />
790: <pre>
791: !"\#$%&\'()*+,-./0123456789:;<=>?\@
792: ABCDEFGHIJKLMNOPQRSTUVWXYZ[\]^_\`abcdefghijklmnopqrstuvwxyz{|}~
793: </pre>
794: ENDERROR
795: }
796: #
797: # Change the password (finally)
798: my $result = &Apache::lonnet::changepass
799: ($user,$domain,$currentpass,$newpass1,$homeserver);
800: # Inform the user the password has (not?) been changed
801: if ($result =~ /^ok$/) {
802: $r->print(<<"ENDTEXT");
803: <h2>The password for $user was successfully changed</h2>
804: ENDTEXT
805: } else {
806: # error error: run in circles, scream and shout
807: $r->print(<<ENDERROR);
808: <h2><font color="#ff0000">The password for $user was not changed</font></h2>
809: Please make sure your old password was entered correctly.
810: ENDERROR
811: return 1;
812: }
813: return;
814: }
815:
816: ################################################################
817: # discussion display subroutines
818: ################################################################
819: sub discussionchanger {
820: my $r = shift;
821: my $user = $env{'user.name'};
822: my $domain = $env{'user.domain'};
823: my %userenv = &Apache::lonnet::get
824: ('environment',['discdisplay','discmarkread']);
825: my $discdisp = 'allposts';
826: my $discmark = 'onmark';
827:
828: if (defined($userenv{'discdisplay'})) {
829: unless ($userenv{'discdisplay'} eq '') {
830: $discdisp = $userenv{'discdisplay'};
831: }
832: }
833: if (defined($userenv{'discmarkread'})) {
834: unless ($userenv{'discdisplay'} eq '') {
835: $discmark = $userenv{'discmarkread'};
836: }
837: }
838:
839: my $newdisp = 'unread';
840: my $newmark = 'ondisp';
841:
842: my $function = &Apache::loncommon::get_users_function();
843: my $color = &Apache::loncommon::designparm($function.'.tabbg',
844: $env{'user.domain'});
845: my %lt = &Apache::lonlocal::texthash(
846: 'pref' => 'Display Preference',
847: 'curr' => 'Current setting ',
848: 'actn' => 'Action',
849: 'sdpf' => 'Set display preferences for discussion posts for both bulletin boards and individual resources in all your courses.',
850: 'prca' => 'Preferences can be set that determine',
851: 'whpo' => 'Which posts are displayed when you display a bulletin board or resource, and',
852: 'unwh' => 'Under what circumstances posts are identfied as "New"',
853: 'allposts' => 'All posts',
854: 'unread' => 'New posts only',
855: 'ondisp' => 'Once displayed',
856: 'onmark' => 'Once marked as read',
857: 'disa' => 'Posts displayed?',
858: 'npmr' => 'New posts cease to be identified as "New"?',
859: 'thde' => 'The preferences you set here can be overridden within each individual discussion.',
860: 'chgt' => 'Change to '
861: );
862: my $dispchange = $lt{'unread'};
863: my $markchange = $lt{'ondisp'};
864: my $currdisp = $lt{'allposts'};
865: my $currmark = $lt{'onmark'};
866:
867: if ($discdisp eq 'unread') {
868: $dispchange = $lt{'allposts'};
869: $currdisp = $lt{'unread'};
870: $newdisp = 'allposts';
871: }
872:
873: if ($discmark eq 'ondisp') {
874: $markchange = $lt{'onmark'};
875: $currmark = $lt{'ondisp'};
876: $newmark = 'onmark';
877: }
878:
879: $r->print(<<"END");
880: <form name="prefs" action="/adm/preferences" method="POST">
881: <input type="hidden" name="action" value="verify_and_change_discussion" />
882: <br />
883: $lt{'sdpf'}<br /> $lt{'prca'} <ol><li>$lt{'whpo'}</li><li>$lt{'unwh'}</li></ol>
884: <br />
885: <br />
886: END
887: $r->print(&Apache::loncommon::start_data_table());
888: $r->print(<<"END");
889: <tr>
890: <th>$lt{'pref'}</th>
891: <th>$lt{'curr'}</th>
892: <th>$lt{'actn'}?</th>
893: </tr>
894: END
895: $r->print(&Apache::loncommon::start_data_table_row());
896: $r->print(<<"END");
897: <td>$lt{'disa'}</td>
898: <td>$lt{$discdisp}</td>
899: <td><label><input type="checkbox" name="discdisp" /><input type="hidden" name="newdisp" value="$newdisp" /> $lt{'chgt'} "$dispchange"</label></td>
900: END
901: $r->print(&Apache::loncommon::end_data_table_row().
902: &Apache::loncommon::start_data_table_row());
903: $r->print(<<"END");
904: <td>$lt{'npmr'}</td>
905: <td>$lt{$discmark}</td>
906: <td><label><input type="checkbox" name="discmark" /><input type="hidden" name="newmark" value="$newmark" /> $lt{'chgt'} "$markchange"</label></td>
907: </tr>
908: END
909: $r->print(&Apache::loncommon::end_data_table_row().
910: &Apache::loncommon::end_data_table());
911: $r->print(<<"END");
912: <br />
913: <br />
914: <input type="submit" name="sub" value="Store Changes" />
915: <br />
916: <br />
917: Note: $lt{'thde'}
918: </form>
919: END
920: }
921:
922: sub verify_and_change_discussion {
923: my $r = shift;
924: my $user = $env{'user.name'};
925: my $domain = $env{'user.domain'};
926: my $message='';
927: if (defined($env{'form.discdisp'}) ) {
928: my $newdisp = $env{'form.newdisp'};
929: if ($newdisp eq 'unread') {
930: $message .='In discussions: only new posts will be displayed.<br />';
931: &Apache::lonnet::put('environment',{'discdisplay' => $newdisp});
932: &Apache::lonnet::appenv('environment.discdisplay' => $newdisp);
933: } else {
934: $message .= 'In discussions: all posts will be displayed.<br />';
935: &Apache::lonnet::del('environment',['discdisplay']);
936: &Apache::lonnet::delenv('environment\.discdisplay');
937: }
938: }
939: if (defined($env{'form.discmark'}) ) {
940: my $newmark = $env{'form.newmark'};
941: if ($newmark eq 'ondisp') {
942: $message.='In discussions: new posts will be cease to be identified as "new" after display.<br />';
943: &Apache::lonnet::put('environment',{'discmarkread' => $newmark});
944: &Apache::lonnet::appenv('environment.discmarkread' => $newmark);
945: } else {
946: $message.='In discussions: posts will be identified as "new" until marked as read by the reader.<br />';
947: &Apache::lonnet::del('environment',['discmarkread']);
948: &Apache::lonnet::delenv('environment\.discmarkread');
949: }
950: }
951: $r->print(<<ENDVCSCREEN);
952: $message
953: ENDVCSCREEN
954: }
955:
956: ################################################################
957: # Subroutines for page display on course access (Course Coordinators)
958: ################################################################
959: sub coursedisplaychanger {
960: my $r = shift;
961: my $user = $env{'user.name'};
962: my $domain = $env{'user.domain'};
963: my %userenv = &Apache::lonnet::get('environment',['course_init_display']);
964: my $currvalue = 'whatsnew';
965: my $firstselect = '';
966: my $whatsnewselect = 'checked="checked"';
967: if (exists($userenv{'course_init_display'})) {
968: if ($userenv{'course_init_display'} eq 'firstres') {
969: $currvalue = 'firstres';
970: $firstselect = 'checked="checked"';
971: $whatsnewselect = '';
972: }
973: }
974: my %pagenames = (
975: firstres => 'First resource',
976: whatsnew => "What's new page",
977: );
978: my $whatsnew_off=&mt('Display the [_1] in the course.','<b>first resource</b>');
979: my $whatsnew_on=&mt('Display the "[_1]" page - a summary of items in the course which require attention.',"<b>What's New</b>");
980:
981: $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 />');
982: $r->print(<<ENDLSCREEN);
983: <form name="prefs" action="/adm/preferences" method="POST">
984: <input type="hidden" name="action" value="verify_and_change_coursepage" />
985: <br />
986: <label><input type="radio" name="newdisp" value="firstres" $firstselect /> $whatsnew_off</label><br />
987: <label><input type="radio" name="newdisp" value="whatsnew" $whatsnewselect /> $whatsnew_on</label><input type="hidden" name="refpage" value="$env{'form.refpage'}" />
988: ENDLSCREEN
989: $r->print('<br /><br /><input type="submit" value="'.&mt('Change').'" />
990: </form>');
991: }
992:
993: sub verify_and_change_coursepage {
994: my $r = shift;
995: my $message='';
996: my %lt = &Apache::lonlocal::texthash(
997: 'defs' => 'Default now set',
998: 'when' => 'when you select a course role from the roles screen',
999: 'ywbt' => 'you will be taken to the start of the course.',
1000: 'apwb' => 'a page will be displayed that lists items in the course that may require action from you.',
1001: 'gtts' => 'Go to the start of the course',
1002: 'dasp' => "Display the What's New page listing course action items",
1003: );
1004: my $newdisp = $env{'form.newdisp'};
1005: $message = '<b>'.$lt{'defs'}.'</b>: '.$lt{'when'}.', ';
1006: if ($newdisp eq 'firstres') {
1007: $message .= $lt{'ywbt'}.'<br />';
1008: &Apache::lonnet::put('environment',{'course_init_display' => $newdisp});
1009: &Apache::lonnet::appenv('environment.course_init_display' => $newdisp);
1010: } else {
1011: $message .= $lt{'apwb'}.'<br />';
1012: &Apache::lonnet::del('environment',['course_init_display']);
1013: &Apache::lonnet::delenv('environment\.course_init_display');
1014: }
1015: my $refpage = $env{'form.refpage'};
1016: if (($env{'request.course.fn'}) && ($env{'request.course.id'})) {
1017: if ($newdisp eq 'firstres') {
1018: my $cdom = $env{'course.'.$env{'request.course.id'}.'.domain'};
1019: my $cnum = $env{'course.'.$env{'request.course.id'}.'.num'};
1020: my ($furl,$ferr)=
1021: &Apache::lonuserstate::readmap($cdom.'/'.$cnum);
1022: $message .= '<br /><font size="+1"><a href="'.$furl.'">'.$lt{'gtts'}.' <i>'.&mt('now').'</i></a></font>';
1023: } else {
1024: $message .= '<br /><font size="+1"><a href="/adm/whatsnew?refpage='.
1025: $refpage.'">'.$lt{'dasp'}.'</a></font>';
1026: }
1027: }
1028: $r->print(<<ENDVCSCREEN);
1029: $message
1030: <br /><br />
1031: ENDVCSCREEN
1032: }
1033:
1034:
1035: ######################################################
1036: # other handler subroutines #
1037: ######################################################
1038:
1039: ################################################################
1040: # Main handler #
1041: ################################################################
1042: sub handler {
1043: my $r = shift;
1044: my $user = $env{'user.name'};
1045: my $domain = $env{'user.domain'};
1046: &Apache::loncommon::content_type($r,'text/html');
1047: # Some pages contain DES keys and should not be cached.
1048: &Apache::loncommon::no_cache($r);
1049: $r->send_http_header;
1050: return OK if $r->header_only;
1051: #
1052: &Apache::loncommon::get_unprocessed_cgi($ENV{'QUERY_STRING'},
1053: ['action','wysiwyg','returnurl','refpage']);
1054: #
1055: &Apache::lonhtmlcommon::clear_breadcrumbs();
1056: &Apache::lonhtmlcommon::add_breadcrumb
1057: ({href => '/adm/preferences',
1058: text => 'Set User Preferences'});
1059:
1060: my @Options;
1061: # Determine current authentication method
1062: my $currentauth=&Apache::lonnet::queryauthenticate($user,$domain);
1063: if ($currentauth =~ /^(unix|internal):/) {
1064: push (@Options,({ action => 'changepass',
1065: linktext => 'Change Password',
1066: href => '/adm/preferences',
1067: help => 'Change_Password',
1068: subroutine => \&passwordchanger,
1069: breadcrumb =>
1070: { href => '/adm/preferences?action=changepass',
1071: text => 'Change Password'},
1072: },
1073: { action => 'verify_and_change_pass',
1074: subroutine => \&verify_and_change_password,
1075: breadcrumb =>
1076: { href =>'/adm/preferences?action=changepass',
1077: text => 'Change Password'},
1078: printmenu => 'not_on_error',
1079: }));
1080: }
1081: push (@Options,({ action => 'changescreenname',
1082: linktext => 'Change Screen Name',
1083: href => '/adm/preferences',
1084: help => 'Prefs_Screen_Name_Nickname',
1085: subroutine => \&screennamechanger,
1086: breadcrumb =>
1087: { href => '/adm/preferences?action=changescreenname',
1088: text => 'Change Screen Name'},
1089: },
1090: { action => 'verify_and_change_screenname',
1091: subroutine => \&verify_and_change_screenname,
1092: breadcrumb =>
1093: { href => '/adm/preferences?action=changescreenname',
1094: text => 'Change Screen Name'},
1095: printmenu => 'yes',
1096: }));
1097:
1098: push (@Options,({ action => 'changemsgforward',
1099: linktext => 'Change Message Forwarding and Notification Addresses',
1100: href => '/adm/preferences',
1101: help => 'Prefs_Forwarding',
1102: breadcrumb =>
1103: { href => '/adm/preferences?action=changemsgforward',
1104: text => 'Change Message Forwarding'},
1105: subroutine => \&msgforwardchanger,
1106: },
1107: { action => 'verify_and_change_msgforward',
1108: breadcrumb =>
1109: { href => '/adm/preferences?action=changemsgforward',
1110: text => 'Change Message Forwarding'},
1111: printmenu => 'yes',
1112: subroutine => \&verify_and_change_msgforward }));
1113: my $aboutmeaction=
1114: '/adm/'.$env{'user.domain'}.'/'.$env{'user.name'}.'/aboutme';
1115: push (@Options,{ action => 'none',
1116: linktext =>
1117: q{Edit the 'About Me' Personal Information Screen},
1118: help => 'Prefs_About_Me',
1119: href => $aboutmeaction});
1120: push (@Options,({ action => 'changecolors',
1121: linktext => 'Change Color Scheme',
1122: href => '/adm/preferences',
1123: help => 'Change_Colors',
1124: breadcrumb =>
1125: { href => '/adm/preferences?action=changecolors',
1126: text => 'Change Colors'},
1127: subroutine => \&colorschanger,
1128: },
1129: { action => 'verify_and_change_colors',
1130: breadcrumb =>
1131: { href => '/adm/preferences?action=changecolors',
1132: text => 'Change Colors'},
1133: printmenu => 'yes',
1134: subroutine => \&verify_and_change_colors,
1135: }));
1136: push (@Options,({ action => 'changelanguages',
1137: linktext => 'Change Language Preferences',
1138: href => '/adm/preferences',
1139: help => 'Prefs_Language',
1140: breadcrumb=>
1141: { href => '/adm/preferences?action=changelanguages',
1142: text => 'Change Language'},
1143: subroutine => \&languagechanger,
1144: },
1145: { action => 'verify_and_change_languages',
1146: breadcrumb=>
1147: {href => '/adm/preferences?action=changelanguages',
1148: text => 'Change Language'},
1149: printmenu => 'yes',
1150: subroutine=>\&verify_and_change_languages, }
1151: ));
1152: push (@Options,({ action => 'changewysiwyg',
1153: linktext => 'Change WYSIWYG Editor Preferences',
1154: href => '/adm/preferences',
1155: breadcrumb =>
1156: { href => '/adm/preferences?action=changewysiwyg',
1157: text => 'Change WYSIWYG Preferences'},
1158: subroutine => \&wysiwygchanger,
1159: },
1160: { action => 'set_wysiwyg',
1161: breadcrumb =>
1162: { href => '/adm/preferences?action=changewysiwyg',
1163: text => 'Change WYSIWYG Preferences'},
1164: printmenu => 'yes',
1165: subroutine => \&verify_and_change_wysiwyg, }
1166: ));
1167: push (@Options,({ action => 'changediscussions',
1168: linktext => 'Change Discussion Display Preferences',
1169: href => '/adm/preferences',
1170: help => 'Change_Discussion_Display',
1171: breadcrumb =>
1172: { href => '/adm/preferences?action=changediscussions',
1173: text => 'Change Discussion Preferences'},
1174: subroutine => \&discussionchanger,
1175: },
1176: { action => 'verify_and_change_discussion',
1177: breadcrumb =>
1178: { href => '/adm/preferences?action=changediscussions',
1179: text => 'Change Discussion Preferences'},
1180: printmenu => 'yes',
1181: subroutine => \&verify_and_change_discussion, }
1182: ));
1183:
1184: push (@Options,({ action => 'changerolespref',
1185: linktext => 'Change Roles Page Preferences',
1186: href => '/adm/preferences',
1187: subroutine => \&rolesprefchanger,
1188: breadcrumb =>
1189: { href => '/adm/preferences?action=changerolespref',
1190: text => 'Change Roles Pref'},
1191: },
1192: { action => 'verify_and_change_rolespref',
1193: subroutine => \&verify_and_change_rolespref,
1194: breadcrumb =>
1195: { href => '/adm/preferences?action=changerolespref',
1196: text => 'Change Roles Preferences'},
1197: printmenu => 'yes',
1198: }));
1199:
1200: push (@Options,({ action => 'changetexenginepref',
1201: linktext => 'Change How Math Equations Are Displayed',
1202: href => '/adm/preferences',
1203: subroutine => \&texenginechanger,
1204: breadcrumb =>
1205: { href => '/adm/preferences?action=changetexenginepref',
1206: text => 'Change Math Pref'},
1207: },
1208: { action => 'verify_and_change_texengine',
1209: subroutine => \&verify_and_change_texengine,
1210: breadcrumb =>
1211: { href => '/adm/preferences?action=changetexenginepref',
1212: text => 'Change Math Preferences'},
1213: printmenu => 'yes',
1214: }));
1215:
1216: if ($env{'environment.remote'} eq 'off') {
1217: push (@Options,({ action => 'launch',
1218: linktext => 'Launch Remote Control',
1219: href => '/adm/remote?url=/adm/preferences',
1220: }));
1221: } else {
1222: push (@Options,({ action => 'collapse',
1223: linktext => 'Collapse Remote Control',
1224: href => '/adm/remote?url=/adm/preferences',
1225: }));
1226: }
1227:
1228: if (&Apache::lonnet::allowed('whn',$env{'request.course.id'})
1229: || &Apache::lonnet::allowed('whn',$env{'request.course.id'}.'/'
1230: .$env{'request.course.sec'})) {
1231: push (@Options,({ action => 'changecourseinit',
1232: linktext => 'Change Course Initialization Preference',
1233: href => '/adm/preferences',
1234: subroutine => \&coursedisplaychanger,
1235: breadcrumb =>
1236: { href => '/adm/preferences?action=changecourseinit',
1237: text => 'Change Course Init. Pref.'},
1238: },
1239: { action => 'verify_and_change_coursepage',
1240: breadcrumb =>
1241: { href => '/adm/preferences?action=changecourseinit', text => 'Change Course Initialization Preference'},
1242: printmenu => 'yes',
1243: subroutine => \&verify_and_change_coursepage,
1244: }));
1245: }
1246:
1247: if ($env{'user.name'} =~ /^(albertel|fox|foxr|koretemey|korte|hallmat3|turtle|raeburn)$/) {
1248: push (@Options,({ action => 'debugtoggle',
1249: printmenu => 'yes',
1250: subroutine => \&toggle_debug,
1251: }));
1252: }
1253:
1254: $r->print(&Apache::loncommon::start_page('Change Preferences'));
1255:
1256: my $call = undef;
1257: my $help = undef;
1258: my $printmenu = 'yes';
1259: foreach my $option (@Options) {
1260: if ($option->{'action'} eq $env{'form.action'}) {
1261: $call = $option->{'subroutine'};
1262: $printmenu = $option->{'printmenu'};
1263: if (exists($option->{'breadcrumb'})) {
1264: &Apache::lonhtmlcommon::add_breadcrumb
1265: ($option->{'breadcrumb'});
1266: }
1267: $help=$option->{'help'};
1268: }
1269: }
1270: $r->print(&Apache::lonhtmlcommon::breadcrumbs('Change Preferences',$help));
1271: my $error;
1272: if (defined($call)) {
1273: $error = $call->($r);
1274: }
1275: if ( ( ($printmenu eq 'yes')
1276: || ($printmenu eq 'not_on_error' && !$error) )
1277: && (!$env{'form.returnurl'})) {
1278: my $optionlist = '<table cellpadding="5">';
1279: if ($env{'user.name'} =~
1280: /^(albertel|kortemey|fox|foxr|korte|hallmat3|turtle|raeburn)$/
1281: ) {
1282: push (@Options,({ action => 'debugtoggle',
1283: linktext => 'Toggle Debug Messages',
1284: text => 'Current Debug status is -'.
1285: $env{'user.debug'}.'-.',
1286: href => '/adm/preferences',
1287: printmenu => 'yes',
1288: subroutine => \&toggle_debug,
1289: }));
1290: }
1291: foreach my $option(@Options) {
1292: my $optiontext = '';
1293: if (exists($option->{'href'})) {
1294: $option->{'href_args'}{'action'}=$option->{'action'};
1295: $optiontext .=
1296: '<a href="'.&add_get_param($option->{'href'},
1297: $option->{'href_args'}).'">'.
1298: &mt($option->{'linktext'}).'</a>';
1299: }
1300: if (exists($option->{'text'})) {
1301: $optiontext .= ' '.&mt($option->{'text'});
1302: }
1303: if ($optiontext ne '') {
1304: $optiontext = '<font size="+1">'.$optiontext.'</font>';
1305: my $helplink = ' ';
1306: if (exists($option->{'help'})) {
1307: $helplink = &Apache::loncommon::help_open_topic
1308: ($option->{'help'});
1309: }
1310: $optionlist .= '<tr>'.
1311: '<td>'.$helplink.'</td>'.
1312: '<td>'.$optiontext.'</td>'.
1313: '</tr>';
1314: }
1315: }
1316: $optionlist .= '</table>';
1317: $r->print($optionlist);
1318: } elsif ($env{'form.returnurl'}) {
1319: $r->print('<br /><a href="'.$env{'form.returnurl'}.'"><font size="+1">'.
1320: &mt('Return').'</font></a>');
1321: }
1322: $r->print(&Apache::loncommon::end_page());
1323: return OK;
1324: }
1325:
1326: sub toggle_debug {
1327: if ($env{'user.debug'}) {
1328: &Apache::lonnet::delenv('user\.debug');
1329: } else {
1330: &Apache::lonnet::appenv('user.debug' => 1);
1331: }
1332: }
1333:
1334: 1;
1335: __END__
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>