Annotation of loncom/interface/lonpreferences.pm, revision 1.55
1.1 www 1: # The LearningOnline Network
2: # Preferences
3: #
1.55 ! albertel 4: # $Id: lonpreferences.pm,v 1.54 2005/02/25 05:54:01 albertel Exp $
1.2 albertel 5: #
6: # Copyright Michigan State University Board of Trustees
7: #
8: # This file is part of the LearningOnline Network with CAPA (LON-CAPA).
9: #
10: # LON-CAPA is free software; you can redistribute it and/or modify
11: # it under the terms of the GNU General Public License as published by
12: # the Free Software Foundation; either version 2 of the License, or
13: # (at your option) any later version.
14: #
15: # LON-CAPA is distributed in the hope that it will be useful,
16: # but WITHOUT ANY WARRANTY; without even the implied warranty of
17: # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18: # GNU General Public License for more details.
19: #
20: # You should have received a copy of the GNU General Public License
21: # along with LON-CAPA; if not, write to the Free Software
22: # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
23: #
24: # /home/httpd/html/adm/gpl.txt
25: #
26: # http://www.lon-capa.org/
27: #
1.3 matthew 28: # This package uses the "londes.js" javascript code.
29: #
30: # TODOs that have to be completed:
31: # interface with lonnet to change the password
32:
1.1 www 33: package Apache::lonpreferences;
34:
35: use strict;
36: use Apache::Constants qw(:common);
1.3 matthew 37: use Apache::File;
38: use Crypt::DES;
39: use DynaLoader; # for Crypt::DES version
1.4 matthew 40: use Apache::loncommon();
1.23 matthew 41: use Apache::lonhtmlcommon();
1.32 www 42: use Apache::lonlocal;
1.3 matthew 43:
44: #
45: # Write lonnet::passwd to do the call below.
46: # Use:
47: # my $answer=reply("encrypt:passwd:$udom:$uname:$upass",$tryserver);
48: #
49: ##################################################
50: # password associated functions #
51: ##################################################
52: sub des_keys {
1.4 matthew 53: # Make a new key for DES encryption.
1.36 www 54: # Each key has two parts which are returned separately.
1.4 matthew 55: # Please note: Each key must be passed through the &hex function
56: # before it is output to the web browser. The hex versions cannot
57: # be used to decrypt.
1.3 matthew 58: my @hexstr=('0','1','2','3','4','5','6','7',
59: '8','9','a','b','c','d','e','f');
60: my $lkey='';
61: for (0..7) {
62: $lkey.=$hexstr[rand(15)];
63: }
64: my $ukey='';
65: for (0..7) {
66: $ukey.=$hexstr[rand(15)];
67: }
68: return ($lkey,$ukey);
69: }
70:
71: sub des_decrypt {
72: my ($key,$cyphertext) = @_;
73: my $keybin=pack("H16",$key);
74: my $cypher;
75: if ($Crypt::DES::VERSION>=2.03) {
76: $cypher=new Crypt::DES $keybin;
77: } else {
78: $cypher=new DES $keybin;
79: }
80: my $plaintext=
81: $cypher->decrypt(unpack("a8",pack("H16",substr($cyphertext,0,16))));
82: $plaintext.=
83: $cypher->decrypt(unpack("a8",pack("H16",substr($cyphertext,16,16))));
1.4 matthew 84: $plaintext=substr($plaintext,1,ord(substr($plaintext,0,1)) );
1.3 matthew 85: return $plaintext;
86: }
87:
1.4 matthew 88: ################################################################
89: # Handler subroutines #
90: ################################################################
1.9 matthew 91:
92: ################################################################
1.28 www 93: # Language Change Subroutines #
94: ################################################################
1.44 www 95:
96: sub wysiwygchanger {
97: my $r = shift;
98: my %userenv = &Apache::lonnet::get
99: ('environment',['wysiwygeditor']);
100: my $offselect='';
101: my $onselect='checked="1"';
102: if ($userenv{'wysiwygeditor'}) {
103: $onselect='';
104: $offselect='checked="1"';
105: }
106: my $switchoff=&mt('Disable WYSIWYG editor');
107: my $switchon=&mt('Enable WYSIWYG editor');
108: $r->print(<<ENDLSCREEN);
109: <form name="server" action="/adm/preferences" method="post">
110: <input type="hidden" name="action" value="set_wysiwyg" />
111: <br />
112: <input type="radio" name="wysiwyg" value="off" $onselect /> $switchoff<br />
113: <input type="radio" name="wysiwyg" value="on" $offselect /> $switchon
114: ENDLSCREEN
115: $r->print('<br /><input type="submit" value="'.&mt('Change').'" />');
116: }
117:
118:
119: sub verify_and_change_wysiwyg {
120: my $r = shift;
121: my $newsetting=$ENV{'form.wysiwyg'};
122: &Apache::lonnet::put('environment',{'wysiwygeditor' => $newsetting});
123: &Apache::lonnet::appenv('environment.wysiwygeditor' => $newsetting);
124: $r->print('<p>'.&mt('Setting WYSIWYG editor to:').' '.&mt($newsetting).'</p>');
125: }
126:
127: ################################################################
128: # Language Change Subroutines #
129: ################################################################
1.28 www 130: sub languagechanger {
131: my $r = shift;
132: my $user = $ENV{'user.name'};
133: my $domain = $ENV{'user.domain'};
134: my %userenv = &Apache::lonnet::get
1.32 www 135: ('environment',['languages']);
1.29 www 136: my $language=$userenv{'languages'};
1.32 www 137:
1.33 www 138: my $pref=&mt('Preferred language');
139: my %langchoices=('' => 'No language preference');
140: foreach (&Apache::loncommon::languageids()) {
141: if (&Apache::loncommon::supportedlanguagecode($_)) {
142: $langchoices{&Apache::loncommon::supportedlanguagecode($_)}
143: = &Apache::loncommon::plainlanguagedescription($_);
144: }
145: }
146: my $selectionbox=&Apache::loncommon::select_form($language,'language',
147: %langchoices);
1.28 www 148: $r->print(<<ENDLSCREEN);
149: <form name="server" action="/adm/preferences" method="post">
150: <input type="hidden" name="action" value="verify_and_change_languages" />
1.33 www 151: <br />$pref: $selectionbox
1.28 www 152: ENDLSCREEN
1.35 matthew 153: $r->print('<br /><input type="submit" value="'.&mt('Change').'" />');
1.28 www 154: }
155:
156:
157: sub verify_and_change_languages {
158: my $r = shift;
159: my $user = $ENV{'user.name'};
160: my $domain = $ENV{'user.domain'};
161: # Screenname
162: my $newlanguage = $ENV{'form.language'};
163: $newlanguage=~s/[^\-\w]//g;
164: my $message='';
165: if ($newlanguage) {
1.29 www 166: &Apache::lonnet::put('environment',{'languages' => $newlanguage});
167: &Apache::lonnet::appenv('environment.languages' => $newlanguage);
168: $message='Set new preferred languages to '.$newlanguage;
1.28 www 169: } else {
1.29 www 170: &Apache::lonnet::del('environment',['languages']);
171: &Apache::lonnet::delenv('environment\.languages');
1.28 www 172: $message='Reset preferred language';
173: }
174: $r->print(<<ENDVCSCREEN);
175: </p>
176: $message
177: ENDVCSCREEN
178: }
179:
1.50 albertel 180: ################################################################
1.54 albertel 181: # Tex Engine Change Subroutines #
182: ################################################################
183: sub texenginechanger {
184: my $r = shift;
185: my $user = $ENV{'user.name'};
186: my $domain = $ENV{'user.domain'};
187: my %userenv = &Apache::lonnet::get('environment',['texengine']);
188: my $texengine=$userenv{'texengine'};
189:
190: my $pref=&mt('Preferred method to display Math');
191: my %mathchoices=('' => 'No Preference',
192: 'tth' => 'TeX to HTML',
193: #'ttm' => 'TeX to MathML',
194: 'jsMath' => 'jsMath',
195: #'mimetex' => 'Convert to Images'
196: );
197: my $selectionbox=&Apache::loncommon::select_form($texengine,'texengine',
198: %mathchoices);
199: my $mathexample='$$\int\left(\frac{a+b}{c^6*d}\right)$$';
200: my $jsMath_example=&Apache::lontexconvert::jsMath_converted(\$mathexample);
201: $mathexample='$$\int\left(\frac{a+b}{c^6*d}\right)$$';
202: my $tth_example=&Apache::lontexconvert::tth_converted(\$mathexample);
203: my $change=&mt('Change');
204: $r->print(<<ENDLSCREEN);
205: <form name="server" 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 /> $tth_example</p>
212: <script type"text/javascript">function NoFontMessage () { }</script>
213: <script src="/adm/jsMath/jsMath.js"></script>
214: <p>jsMath <br />
215:
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:
233: $jsMath_example</p>
234: ENDLSCREEN
1.55 ! albertel 235: if ($ENV{'environment.texengine'} ne 'jsMath') {
! 236: $r->print('<script type="text/javascript">jsMath.Process()</script>');
! 237: }
1.54 albertel 238: }
239:
240:
241: sub verify_and_change_texengine {
242: my $r = shift;
243: my $user = $ENV{'user.name'};
244: my $domain = $ENV{'user.domain'};
245: # Screenname
246: my $newtexengine = $ENV{'form.texengine'};
247: $newtexengine=~s/[^\-\w]//g;
248: my $message='';
249: if ($newtexengine) {
250: &Apache::lonnet::put('environment',{'texengine' => $newtexengine});
251: &Apache::lonnet::appenv('environment.texengine' => $newtexengine);
252: $message='Set new preferred math display to '.$newtexengine;
253: } else {
254: &Apache::lonnet::del('environment',['texengine']);
255: &Apache::lonnet::delenv('environment\.texengine');
256: $message='Reset preferred math display.';
257: }
258: $r->print(<<ENDVCSCREEN);
259: </p>
260: $message
261: ENDVCSCREEN
262: }
263:
264: ################################################################
1.50 albertel 265: # Roles Page Preference Change Subroutines #
266: ################################################################
267: sub rolesprefchanger {
268: my $r = shift;
269: my $user = $ENV{'user.name'};
270: my $domain = $ENV{'user.domain'};
271: my %userenv = &Apache::lonnet::get
272: ('environment',['recentroles','recentrolesn']);
273: my $hotlist_flag=$userenv{'recentroles'};
274: my $hotlist_n=$userenv{'recentrolesn'};
275: my $checked;
276: if ($hotlist_flag) {
277: $checked = 'checked="checked"';
278: }
279:
280: if (!$hotlist_n) { $hotlist_n=3; }
281: my $options;
282: for (my $i=1; $i<10; $i++) {
283: my $select;
284: if ($hotlist_n == $i) { $select = 'selected="selected"'; }
285: $options .= "<option $select>$i</option>\n";
286: }
287:
288: $r->print(<<ENDSCREEN);
289: <p>Some LON-CAPA users have a long list of roles. The Recent Roles Hotlist
290: feature keeps track of the last N roles which have been
291: visited and places a table of these at the top of the roles page.
292: People with very few roles should leave this feature disabled.
293: </p>
294:
295: <form name="server" action="/adm/preferences" method="post">
296: <input type="hidden" name="action" value="verify_and_change_rolespref" />
297: <br />Enable Recent Roles Hotlist:
298: <input type="checkbox" $checked name="recentroles" value="true" />
299: <br />Number of roles in Hotlist:
300: <select name="recentrolesn" size="1">
301: $options
302: </select>
303: <br />
304: <input type="submit" value="Change" />
305: </form>
306: ENDSCREEN
307: }
308:
309: sub verify_and_change_rolespref {
310: my $r = shift;
311: my $user = $ENV{'user.name'};
312: my $domain = $ENV{'user.domain'};
313: # Recent Roles Hotlist Flag
314: my $hotlist_flag = $ENV{'form.recentroles'};
315: my $hotlist_n = $ENV{'form.recentrolesn'};
316: my $message='';
317: if ($hotlist_flag) {
318: &Apache::lonnet::put('environment',{'recentroles' => $hotlist_flag});
319: &Apache::lonnet::appenv('environment.recentroles' => $hotlist_flag);
320: $message='Recent Roles Hotlist is Enabled';
321: } else {
322: &Apache::lonnet::del('environment',['recentroles']);
323: &Apache::lonnet::delenv('environment\.recentroles');
324: $message='Recent Roles Hotlist is Disabled';
325: }
326: if ($hotlist_n) {
327: &Apache::lonnet::put('environment',{'recentrolesn' => $hotlist_n});
328: &Apache::lonnet::appenv('environment.recentrolesn' => $hotlist_n);
329: if ($hotlist_flag) {
330: $message.="<br />Display $hotlist_n Most Recent Roles\n";
331: }
332: }
333:
334: $r->print(<<ENDRPSCREEN);
335: </p>
336: $message
337: ENDRPSCREEN
338: }
339:
340:
1.28 www 341:
342: ################################################################
1.9 matthew 343: # Anonymous Discussion Name Change Subroutines #
344: ################################################################
1.5 www 345: sub screennamechanger {
346: my $r = shift;
347: my $user = $ENV{'user.name'};
348: my $domain = $ENV{'user.domain'};
1.14 www 349: my %userenv = &Apache::lonnet::get
350: ('environment',['screenname','nickname']);
1.6 www 351: my $screenname=$userenv{'screenname'};
1.14 www 352: my $nickname=$userenv{'nickname'};
1.5 www 353: $r->print(<<ENDSCREEN);
1.6 www 354: <form name="server" action="/adm/preferences" method="post">
355: <input type="hidden" name="action" value="verify_and_change_screenname" />
1.14 www 356: <br />New screenname (shown if you post anonymously):
1.6 www 357: <input type="text" size="20" value="$screenname" name="screenname" />
1.14 www 358: <br />New nickname (shown if you post non-anonymously):
359: <input type="text" size="20" value="$nickname" name="nickname" />
1.6 www 360: <input type="submit" value="Change" />
361: </form>
1.5 www 362: ENDSCREEN
363: }
1.6 www 364:
365: sub verify_and_change_screenname {
366: my $r = shift;
367: my $user = $ENV{'user.name'};
368: my $domain = $ENV{'user.domain'};
1.14 www 369: # Screenname
1.6 www 370: my $newscreen = $ENV{'form.screenname'};
1.14 www 371: $newscreen=~s/[^ \w]//g;
1.6 www 372: my $message='';
373: if ($newscreen) {
1.7 www 374: &Apache::lonnet::put('environment',{'screenname' => $newscreen});
375: &Apache::lonnet::appenv('environment.screenname' => $newscreen);
1.6 www 376: $message='Set new screenname to '.$newscreen;
377: } else {
378: &Apache::lonnet::del('environment',['screenname']);
1.7 www 379: &Apache::lonnet::delenv('environment\.screenname');
1.6 www 380: $message='Reset screenname';
381: }
1.14 www 382: # Nickname
383: $message.='<br />';
1.17 matthew 384: $newscreen = $ENV{'form.nickname'};
1.14 www 385: $newscreen=~s/[^ \w]//g;
386: if ($newscreen) {
387: &Apache::lonnet::put('environment',{'nickname' => $newscreen});
388: &Apache::lonnet::appenv('environment.nickname' => $newscreen);
389: $message.='Set new nickname to '.$newscreen;
390: } else {
391: &Apache::lonnet::del('environment',['nickname']);
392: &Apache::lonnet::delenv('environment\.nickname');
393: $message.='Reset nickname';
394: }
395:
1.6 www 396: $r->print(<<ENDVCSCREEN);
397: </p>
398: $message
399: ENDVCSCREEN
1.20 www 400: }
401:
402: ################################################################
403: # Message Forward #
404: ################################################################
405:
406: sub msgforwardchanger {
407: my $r = shift;
408: my $user = $ENV{'user.name'};
409: my $domain = $ENV{'user.domain'};
1.26 www 410: my %userenv = &Apache::lonnet::get('environment',['msgforward','notification','critnotification']);
1.20 www 411: my $msgforward=$userenv{'msgforward'};
412: my $notification=$userenv{'notification'};
413: my $critnotification=$userenv{'critnotification'};
1.25 bowersj2 414: my $forwardingHelp = Apache::loncommon::help_open_topic("Prefs_Forwarding",
415: "What are forwarding ".
416: "and notification ".
417: "addresses");
1.27 bowersj2 418: my $criticalMessageHelp = Apache::loncommon::help_open_topic("Course_Critical_Message",
419: "What are critical messages");
420:
1.20 www 421: $r->print(<<ENDMSG);
1.25 bowersj2 422: $forwardingHelp <br />
1.20 www 423: <form name="server" action="/adm/preferences" method="post">
424: <input type="hidden" name="action" value="verify_and_change_msgforward" />
425: New Forwarding Address(es) (<tt>user:domain,user:domain,...</tt>):
426: <input type="text" size="40" value="$msgforward" name="msgforward" /><hr />
427: New Message Notification Email Address(es) (<tt>joe\@doe.com,jane\@doe.edu,...</tt>):
428: <input type="text" size="40" value="$notification" name="notification" /><hr />
429: New Critical Message Notification Email Address(es) (<tt>joe\@doe.com,jane\@doe.edu,...</tt>):
1.27 bowersj2 430: <input type="text" size="40" value="$critnotification" name="critnotification" />$criticalMessageHelp<hr />
1.20 www 431: <input type="submit" value="Change" />
432: </form>
433: ENDMSG
434: }
435:
436: sub verify_and_change_msgforward {
437: my $r = shift;
438: my $user = $ENV{'user.name'};
439: my $domain = $ENV{'user.domain'};
440: my $newscreen = '';
441: my $message='';
442: foreach (split(/\,/,$ENV{'form.msgforward'})) {
443: my ($msuser,$msdomain)=split(/[\@\:]/,$_);
444: $msuser=~s/\W//g;
445: $msdomain=~s/\W//g;
446: if (($msuser) && ($msdomain)) {
447: if (&Apache::lonnet::homeserver($msuser,$msdomain) ne 'no_host') {
448: $newscreen.=$msuser.':'.$msdomain.',';
449: } else {
450: $message.='No such user: '.$msuser.':'.$msdomain.'<br>';
451: }
452: }
453: }
454: $newscreen=~s/\,$//;
455: if ($newscreen) {
456: &Apache::lonnet::put('environment',{'msgforward' => $newscreen});
457: &Apache::lonnet::appenv('environment.msgforward' => $newscreen);
458: $message.='Set new message forwarding to '.$newscreen.'<br />';
459: } else {
460: &Apache::lonnet::del('environment',['msgforward']);
461: &Apache::lonnet::delenv('environment\.msgforward');
462: $message.='Reset message forwarding<br />';
463: }
464: my $notification=$ENV{'form.notification'};
465: $notification=~s/\s//gs;
466: if ($notification) {
467: &Apache::lonnet::put('environment',{'notification' => $notification});
468: &Apache::lonnet::appenv('environment.notification' => $notification);
469: $message.='Set message notification address to '.$notification.'<br />';
470: } else {
471: &Apache::lonnet::del('environment',['notification']);
472: &Apache::lonnet::delenv('environment\.notification');
473: $message.='Reset message notification<br />';
474: }
475: my $critnotification=$ENV{'form.critnotification'};
476: $critnotification=~s/\s//gs;
477: if ($critnotification) {
478: &Apache::lonnet::put('environment',{'critnotification' => $critnotification});
479: &Apache::lonnet::appenv('environment.critnotification' => $critnotification);
480: $message.='Set critical message notification address to '.$critnotification;
481: } else {
482: &Apache::lonnet::del('environment',['critnotification']);
483: &Apache::lonnet::delenv('environment\.critnotification');
484: $message.='Reset critical message notification<br />';
485: }
486: $r->print(<<ENDVCMSG);
487: </p>
488: $message
489: ENDVCMSG
1.6 www 490: }
491:
1.12 www 492: ################################################################
1.19 www 493: # Colors #
1.12 www 494: ################################################################
495:
1.19 www 496: sub colorschanger {
1.12 www 497: my $r = shift;
1.19 www 498: # figure out colors
499: my $function='student';
500: if ($ENV{'request.role'}=~/^(cc|in|ta|ep)/) {
501: $function='coordinator';
502: }
503: if ($ENV{'request.role'}=~/^(su|dc|ad|li)/) {
504: $function='admin';
505: }
506: if (($ENV{'request.role'}=~/^(au|ca)/) ||
507: ($ENV{'REQUEST_URI'}=~/^(\/priv|\~)/)) {
508: $function='author';
509: }
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 $chtable='';
1.22 matthew 519: foreach my $item (sort(keys(%colortypes))) {
1.19 www 520: my $curcol=&Apache::loncommon::designparm($function.'.'.$item,$domain);
521: $chtable.='<tr><td>'.$colortypes{$item}.'</td><td bgcolor="'.$curcol.
522: '"> </td><td><input name="'.$item.
1.21 www 523: '" size="10" value="'.$curcol.
524: '" /></td><td><a href="javascript:pjump('."'color_custom','".$colortypes{$item}.
1.19 www 525: "','".$curcol."','"
1.21 www 526: .$item."','parmform.pres','psub'".');">Select</a></td></tr>';
1.19 www 527: }
1.23 matthew 528: my $pjump_def = &Apache::lonhtmlcommon::pjump_javascript_definition();
1.19 www 529: $r->print(<<ENDCOL);
530: <script>
531:
532: function pclose() {
533: parmwin=window.open("/adm/rat/empty.html","LONCAPAparms",
534: "height=350,width=350,scrollbars=no,menubar=no");
535: parmwin.close();
536: }
537:
1.23 matthew 538: $pjump_def
1.19 www 539:
540: function psub() {
541: pclose();
542: if (document.parmform.pres_marker.value!='') {
1.21 www 543: if (document.parmform.pres_type.value!='') {
544: eval('document.server.'+
545: document.parmform.pres_marker.value+
1.19 www 546: '.value=document.parmform.pres_value.value;');
1.21 www 547: }
1.19 www 548: } else {
549: document.parmform.pres_value.value='';
550: document.parmform.pres_marker.value='';
551: }
552: }
553:
554:
555: </script>
1.21 www 556: <form name="parmform">
557: <input type="hidden" name="pres_marker" />
558: <input type="hidden" name="pres_type" />
559: <input type="hidden" name="pres_value" />
560: </form>
1.12 www 561: <form name="server" action="/adm/preferences" method="post">
1.19 www 562: <input type="hidden" name="action" value="verify_and_change_colors" />
563: <table border="2">
564: $chtable
565: </table>
1.21 www 566: <input type="submit" value="Change Custom Colors" />
567: <input type="submit" name="resetall" value="Reset All Colors to Default" />
1.12 www 568: </form>
1.19 www 569: ENDCOL
1.12 www 570: }
571:
1.19 www 572: sub verify_and_change_colors {
1.12 www 573: my $r = shift;
1.19 www 574: # figure out colors
575: my $function='student';
576: if ($ENV{'request.role'}=~/^(cc|in|ta|ep)/) {
577: $function='coordinator';
578: }
579: if ($ENV{'request.role'}=~/^(su|dc|ad|li)/) {
580: $function='admin';
581: }
582: if (($ENV{'request.role'}=~/^(au|ca)/) ||
583: ($ENV{'REQUEST_URI'}=~/^(\/priv|\~)/)) {
584: $function='author';
585: }
586: my $domain=&Apache::loncommon::determinedomain();
587: my %colortypes=('pgbg' => 'Page Background',
588: 'tabbg' => 'Header Background',
589: 'sidebg'=> 'Header Border',
590: 'font' => 'Font',
591: 'link' => 'Un-Visited Link',
592: 'vlink' => 'Visited Link',
593: 'alink' => 'Active Link');
594:
1.12 www 595: my $message='';
1.21 www 596: foreach my $item (keys %colortypes) {
597: my $color=$ENV{'form.'.$item};
598: my $entry='color.'.$function.'.'.$item;
599: if (($color=~/^\#[0-9A-Fa-f]{6}$/) && (!$ENV{'form.resetall'})) {
600: &Apache::lonnet::put('environment',{$entry => $color});
601: &Apache::lonnet::appenv('environment.'.$entry => $color);
602: $message.='Set '.$colortypes{$item}.' to '.$color.'<br />';
603: } else {
604: &Apache::lonnet::del('environment',[$entry]);
605: &Apache::lonnet::delenv('environment\.'.$entry);
606: $message.='Reset '.$colortypes{$item}.'<br />';
607: }
608: }
1.19 www 609: $r->print(<<ENDVCCOL);
1.12 www 610: </p>
611: $message
1.21 www 612: <form name="client" action="/adm/preferences" method="post">
613: <input type="hidden" name="action" value="changecolors" />
614: </form>
1.19 www 615: ENDVCCOL
1.12 www 616: }
617:
1.4 matthew 618: ######################################################
619: # password handler subroutines #
620: ######################################################
1.3 matthew 621: sub passwordchanger {
1.4 matthew 622: # This function is a bit of a mess....
1.3 matthew 623: # Passwords are encrypted using londes.js (DES encryption)
624: my $r = shift;
1.4 matthew 625: my $errormessage = shift;
626: $errormessage = ($errormessage || '');
1.3 matthew 627: my $user = $ENV{'user.name'};
628: my $domain = $ENV{'user.domain'};
629: my $homeserver = $ENV{'user.home'};
630: my $currentauth=&Apache::lonnet::queryauthenticate($user,$domain);
631: # Check for authentication types that allow changing of the password.
632: return if ($currentauth !~ /^(unix|internal):/);
633: #
634: # Generate keys
635: my ($lkey_cpass ,$ukey_cpass ) = &des_keys();
636: my ($lkey_npass1,$ukey_npass1) = &des_keys();
637: my ($lkey_npass2,$ukey_npass2) = &des_keys();
1.4 matthew 638: # Store the keys in the log files
1.3 matthew 639: my $lonhost = $r->dir_config('lonHostID');
640: my $logtoken=Apache::lonnet::reply('tmpput:'
641: .$ukey_cpass . $lkey_cpass .'&'
642: .$ukey_npass1 . $lkey_npass1.'&'
643: .$ukey_npass2 . $lkey_npass2,
644: $lonhost);
1.4 matthew 645: # Hexify the keys for output as javascript variables
1.3 matthew 646: $ukey_cpass = hex($ukey_cpass);
647: $lkey_cpass = hex($lkey_cpass);
648: $ukey_npass1= hex($ukey_npass1);
649: $lkey_npass1= hex($lkey_npass1);
650: $ukey_npass2= hex($ukey_npass2);
651: $lkey_npass2= hex($lkey_npass2);
652: # Output javascript to deal with passwords
1.4 matthew 653: # Output DES javascript
1.53 albertel 654: my $html=&Apache::lonxml::xmlbegin();
655: $r->print($html."<head>");
1.3 matthew 656: {
657: my $include = $r->dir_config('lonIncludes');
658: my $jsh=Apache::File->new($include."/londes.js");
659: $r->print(<$jsh>);
660: }
661: $r->print(<<ENDFORM);
662: <script language="JavaScript">
663:
664: function send() {
665: uextkey=this.document.client.elements.ukey_cpass.value;
666: lextkey=this.document.client.elements.lkey_cpass.value;
667: initkeys();
668:
1.52 raeburn 669: this.document.pserver.elements.currentpass.value
1.3 matthew 670: =crypted(this.document.client.elements.currentpass.value);
671:
672: uextkey=this.document.client.elements.ukey_npass1.value;
673: lextkey=this.document.client.elements.lkey_npass1.value;
674: initkeys();
1.52 raeburn 675: this.document.pserver.elements.newpass_1.value
1.3 matthew 676: =crypted(this.document.client.elements.newpass_1.value);
677:
678: uextkey=this.document.client.elements.ukey_npass2.value;
679: lextkey=this.document.client.elements.lkey_npass2.value;
680: initkeys();
1.52 raeburn 681: this.document.pserver.elements.newpass_2.value
1.3 matthew 682: =crypted(this.document.client.elements.newpass_2.value);
683:
1.52 raeburn 684: this.document.pserver.submit();
1.3 matthew 685: }
686:
687: </script>
1.4 matthew 688: $errormessage
1.10 www 689:
1.3 matthew 690: <p>
1.36 www 691: <!-- We separate the forms into 'server' and 'client' in order to
1.3 matthew 692: ensure that unencrypted passwords will not be sent out by a
693: crappy browser -->
694:
1.52 raeburn 695: <form name="pserver" action="/adm/preferences" method="post">
1.3 matthew 696: <input type="hidden" name="logtoken" value="$logtoken" />
697: <input type="hidden" name="action" value="verify_and_change_pass" />
698: <input type="hidden" name="currentpass" value="" />
1.4 matthew 699: <input type="hidden" name="newpass_1" value="" />
700: <input type="hidden" name="newpass_2" value="" />
1.3 matthew 701: </form>
702:
703: <form name="client" >
704: <table>
1.4 matthew 705: <tr><td align="right"> Current password: </td>
706: <td><input type="password" name="currentpass" size="10"/> </td></tr>
707: <tr><td align="right"> New password: </td>
708: <td><input type="password" name="newpass_1" size="10" /> </td></tr>
709: <tr><td align="right"> Confirm password: </td>
710: <td><input type="password" name="newpass_2" size="10" /> </td></tr>
1.3 matthew 711: <tr><td colspan="2" align="center">
712: <input type="button" value="Change Password" onClick="send();">
713: </table>
1.4 matthew 714: <input type="hidden" name="ukey_cpass" value="$ukey_cpass" />
715: <input type="hidden" name="lkey_cpass" value="$lkey_cpass" />
1.3 matthew 716: <input type="hidden" name="ukey_npass1" value="$ukey_npass1" />
717: <input type="hidden" name="lkey_npass1" value="$lkey_npass1" />
718: <input type="hidden" name="ukey_npass2" value="$ukey_npass2" />
719: <input type="hidden" name="lkey_npass2" value="$lkey_npass2" />
720: </form>
721: </p>
722: ENDFORM
723: #
724: return;
725: }
726:
727: sub verify_and_change_password {
728: my $r = shift;
729: my $user = $ENV{'user.name'};
730: my $domain = $ENV{'user.domain'};
731: my $homeserver = $ENV{'user.home'};
732: my $currentauth=&Apache::lonnet::queryauthenticate($user,$domain);
1.4 matthew 733: # Check for authentication types that allow changing of the password.
734: return if ($currentauth !~ /^(unix|internal):/);
1.3 matthew 735: #
1.53 albertel 736: my $html=&Apache::lonxml::xmlbegin();
1.4 matthew 737: $r->print(<<ENDHEADER);
1.53 albertel 738: $html
1.4 matthew 739: <head>
740: <title>LON-CAPA Preferences: Change password for $user</title>
741: </head>
742: ENDHEADER
1.3 matthew 743: #
744: my $currentpass = $ENV{'form.currentpass'};
745: my $newpass1 = $ENV{'form.newpass_1'};
746: my $newpass2 = $ENV{'form.newpass_2'};
747: my $logtoken = $ENV{'form.logtoken'};
748: # Check for empty data
1.4 matthew 749: unless (defined($currentpass) &&
750: defined($newpass1) &&
751: defined($newpass2) ){
752: &passwordchanger($r,"<p>\n<font color='#ff0000'>ERROR</font>".
753: "Password data was blank.\n</p>");
1.3 matthew 754: return;
755: }
1.16 albertel 756: # Get the keys
757: my $lonhost = $r->dir_config('lonHostID');
1.3 matthew 758: my $tmpinfo = Apache::lonnet::reply('tmpget:'.$logtoken,$lonhost);
759: if (($tmpinfo=~/^error/) || ($tmpinfo eq 'con_lost')) {
1.4 matthew 760: # I do not a have a better idea about how to handle this
1.3 matthew 761: $r->print(<<ENDERROR);
762: <p>
763: <font color="#ff0000">ERROR:</font> Unable to retrieve stored token for
1.4 matthew 764: password decryption. Please log out and try again.
1.3 matthew 765: </p>
766: ENDERROR
1.4 matthew 767: # Probably should log an error here
1.3 matthew 768: return;
769: }
770: my ($ckey,$n1key,$n2key)=split(/&/,$tmpinfo);
1.4 matthew 771: #
1.17 matthew 772: $currentpass = &des_decrypt($ckey ,$currentpass);
773: $newpass1 = &des_decrypt($n1key,$newpass1);
774: $newpass2 = &des_decrypt($n2key,$newpass2);
1.4 matthew 775: #
1.3 matthew 776: if ($newpass1 ne $newpass2) {
1.4 matthew 777: &passwordchanger($r,
778: '<font color="#ff0000">ERROR:</font>'.
779: 'The new passwords you entered do not match. '.
780: 'Please try again.');
781: return;
782: }
783: if (length($newpass1) < 7) {
784: &passwordchanger($r,
785: '<font color="#ff0000">ERROR:</font>'.
786: 'Passwords must be a minimum of 7 characters long. '.
787: 'Please try again.');
1.3 matthew 788: return;
789: }
1.4 matthew 790: #
791: # Check for bad characters
792: my $badpassword = 0;
793: foreach (split(//,$newpass1)) {
794: $badpassword = 1 if ((ord($_)<32)||(ord($_)>126));
795: }
796: if ($badpassword) {
797: # I can't figure out how to enter bad characters on my browser.
798: &passwordchanger($r,<<ENDERROR);
799: <font color="#ff0000">ERROR:</font>
800: The password you entered contained illegal characters.<br />
801: Valid characters are: space and <br />
802: <pre>
803: !"\#$%&\'()*+,-./0123456789:;<=>?\@
804: ABCDEFGHIJKLMNOPQRSTUVWXYZ[\]^_\`abcdefghijklmnopqrstuvwxyz{|}~
805: </pre>
806: ENDERROR
807: }
808: #
809: # Change the password (finally)
810: my $result = &Apache::lonnet::changepass
811: ($user,$domain,$currentpass,$newpass1,$homeserver);
812: # Inform the user the password has (not?) been changed
813: if ($result =~ /^ok$/) {
814: $r->print(<<"ENDTEXT");
1.9 matthew 815: <h2>The password for $user was successfully changed</h2>
1.4 matthew 816: ENDTEXT
817: } else {
818: # error error: run in circles, scream and shout
819: $r->print(<<ENDERROR);
1.9 matthew 820: <h2><font color="#ff0000">The password for $user was not changed</font></h2>
1.8 matthew 821: Please make sure your old password was entered correctly.
1.4 matthew 822: ENDERROR
823: }
824: return;
1.3 matthew 825: }
826:
1.42 raeburn 827: ################################################################
828: # discussion display subroutines
829: ################################################################
830: sub discussionchanger {
831: my $r = shift;
832: my $user = $ENV{'user.name'};
833: my $domain = $ENV{'user.domain'};
834: my %userenv = &Apache::lonnet::get
1.43 raeburn 835: ('environment',['discdisplay','discmarkread']);
836: my $discdisp = 'allposts';
837: my $discmark = 'onmark';
838:
839: if (defined($userenv{'discdisplay'})) {
840: unless ($userenv{'discdisplay'} eq '') {
841: $discdisp = $userenv{'discdisplay'};
842: }
843: }
844: if (defined($userenv{'discmarkread'})) {
845: unless ($userenv{'discdisplay'} eq '') {
846: $discmark = $userenv{'discmarkread'};
847: }
848: }
849:
850: my $newdisp = 'unread';
851: my $newmark = 'ondisp';
852:
853: my $function = &Apache::loncommon::get_users_function();
854: my $color = &Apache::loncommon::designparm($function.'.tabbg',
855: $ENV{'user.domain'});
856: my %lt = &Apache::lonlocal::texthash(
857: 'pref' => 'Display Preference',
858: 'curr' => 'Current setting ',
859: 'actn' => 'Action',
860: 'sdpf' => 'Set display preferences for discussion posts for both bulletin boards and individual resources in all your courses.',
861: 'prca' => 'Preferences can be set that determine',
862: 'whpo' => 'Which posts are displayed when you display a bulletin board or resource, and',
863: 'unwh' => 'Under what circumstances posts are identfied as "New"',
864: 'allposts' => 'All posts',
865: 'unread' => 'New posts only',
866: 'ondisp' => 'Once displayed',
867: 'onmark' => 'Once marked as read',
868: 'disa' => 'Posts displayed?',
869: 'npmr' => 'New posts cease to be identified as "New"?',
870: 'thde' => 'The preferences you set here can be overridden within each individual discussion.',
871: 'chgt' => 'Change to '
872: );
873: my $dispchange = $lt{'unread'};
874: my $markchange = $lt{'ondisp'};
875: my $currdisp = $lt{'allposts'};
876: my $currmark = $lt{'onmark'};
877:
878: if ($discdisp eq 'unread') {
879: $dispchange = $lt{'allposts'};
880: $currdisp = $lt{'unread'};
881: $newdisp = 'allposts';
882: }
883:
884: if ($discmark eq 'ondisp') {
885: $markchange = $lt{'onmark'};
886: $currmark = $lt{'ondisp'};
887: $newmark = 'onmark';
1.42 raeburn 888: }
1.43 raeburn 889:
890: $r->print(<<"END");
1.42 raeburn 891: <form name="server" action="/adm/preferences" method="post">
892: <input type="hidden" name="action" value="verify_and_change_discussion" />
893: <br />
1.43 raeburn 894: $lt{'sdpf'}<br/> $lt{'prca'} <ol><li>$lt{'whpo'}</li><li>$lt{'unwh'}</li></ol>
895: <br />
896: <br />
897: <table border="0" cellpadding="0" cellspacing="0">
898: <tr>
899: <td width="100%" bgcolor="#000000">
900: <table width="100%" border="0" cellpadding="1" cellspacing="0">
901: <tr>
902: <td width="100%" bgcolor="#000000">
903: <table border="0" cellpadding="3" cellspacing="3" bgcolor="#FFFFFF">
904: <tr bgcolor="$color">
905: <td><b>$lt{'pref'}</b></td>
906: <td><b>$lt{'curr'}</b></td>
907: <td><b>$lt{'actn'}?</b></td>
908: </tr>
909: <tr bgcolor="#dddddd">
910: <td>$lt{'disa'}</td>
911: <td>$lt{$discdisp}</td>
912: <td><input type="checkbox" name="discdisp" /><input type="hidden" name="newdisp" value="$newdisp" /> $lt{'chgt'} "$dispchange"</td>
913: </tr><tr bgcolor="#eeeeee">
914: <td>$lt{'npmr'}</td>
915: <td>$lt{$discmark}</td>
916: <td><input type="checkbox" name="discmark" /><input type="hidden" name="newmark" value="$newmark" /> $lt{'chgt'} "$markchange"</td>
917: </tr>
918: </table>
919: </td>
920: </tr>
921: </table>
922: </td>
923: </tr>
924: </table>
925: <br />
926: <br />
927: <input type="submit" name="sub" value="Store Changes" />
928: <br />
929: <br />
930: Note: $lt{'thde'}
931: </form>
932: END
1.42 raeburn 933: }
934:
935: sub verify_and_change_discussion {
936: my $r = shift;
1.43 raeburn 937: my $user = $ENV{'user.name'};
938: my $domain = $ENV{'user.domain'};
1.42 raeburn 939: my $message='';
1.43 raeburn 940: if (defined($ENV{'form.discdisp'}) ) {
941: my $newdisp = $ENV{'form.newdisp'};
942: if ($newdisp eq 'unread') {
943: $message .='In discussions: only new posts will be displayed.<br/>';
944: &Apache::lonnet::put('environment',{'discdisplay' => $newdisp});
945: &Apache::lonnet::appenv('environment.discdisplay' => $newdisp);
946: } else {
947: $message .= 'In discussions: all posts will be displayed.<br/>';
948: &Apache::lonnet::del('environment',['discdisplay']);
949: &Apache::lonnet::delenv('environment\.discdisplay');
950: }
951: }
952: if (defined($ENV{'form.discmark'}) ) {
953: my $newmark = $ENV{'form.newmark'};
954: if ($newmark eq 'ondisp') {
955: $message.='In discussions: new posts will be cease to be identified as "new" after display.<br/>';
956: &Apache::lonnet::put('environment',{'discmarkread' => $newmark});
957: &Apache::lonnet::appenv('environment.discmarkread' => $newmark);
958: } else {
959: $message.='In discussions: posts will be identified as "new" until marked as read by the reader.<br/>';
960: &Apache::lonnet::del('environment',['discmarkread']);
961: &Apache::lonnet::delenv('environment\.discmarkread');
962: }
1.42 raeburn 963: }
964: $r->print(<<ENDVCSCREEN);
965: </p>
966: $message
967: ENDVCSCREEN
968: }
969:
1.4 matthew 970: ######################################################
971: # other handler subroutines #
972: ######################################################
973:
1.3 matthew 974: ################################################################
975: # Main handler #
976: ################################################################
1.1 www 977: sub handler {
978: my $r = shift;
1.3 matthew 979: my $user = $ENV{'user.name'};
980: my $domain = $ENV{'user.domain'};
1.31 www 981: &Apache::loncommon::content_type($r,'text/html');
1.4 matthew 982: # Some pages contain DES keys and should not be cached.
983: &Apache::loncommon::no_cache($r);
1.1 www 984: $r->send_http_header;
985: return OK if $r->header_only;
1.9 matthew 986: #
1.35 matthew 987: &Apache::loncommon::get_unprocessed_cgi($ENV{'QUERY_STRING'},
1.44 www 988: ['action','wysiwyg','returnurl']);
1.35 matthew 989: #
990: &Apache::lonhtmlcommon::clear_breadcrumbs();
991: &Apache::lonhtmlcommon::add_breadcrumb
992: ({href => '/adm/preferences',
993: text => 'Set User Preferences'});
994:
995: my @Options;
996: # Determine current authentication method
997: my $currentauth=&Apache::lonnet::queryauthenticate($user,$domain);
998: if ($currentauth =~ /^(unix|internal):/) {
999: push (@Options,({ action => 'changepass',
1.40 www 1000: linktext => 'Change Password',
1.35 matthew 1001: href => '/adm/preferences',
1002: help => 'Change_Password',
1003: subroutine => \&passwordchanger,
1004: breadcrumb =>
1005: { href => '/adm/preferences?action=changepass',
1006: text => 'Change Password'},
1007: },
1008: { action => 'verify_and_change_pass',
1009: subroutine => \&verify_and_change_password,
1010: breadcrumb =>
1011: { href =>'/adm/preferences?action=changepass',
1012: text => 'Change Password'},
1013: printmenu => 'yes',
1014: }));
1015: }
1016: push (@Options,({ action => 'changescreenname',
1017: linktext => 'Change Screen Name',
1018: href => '/adm/preferences',
1019: help => 'Prefs_Screen_Name_Nickname',
1020: subroutine => \&screennamechanger,
1021: breadcrumb =>
1022: { href => '/adm/preferences?action=changescreenname',
1023: text => 'Change Screen Name'},
1024: },
1025: { action => 'verify_and_change_screenname',
1026: subroutine => \&verify_and_change_screenname,
1027: breadcrumb =>
1028: { href => '/adm/preferences?action=changescreenname',
1029: text => 'Change Screen Name'},
1030: printmenu => 'yes',
1031: }));
1032:
1033: push (@Options,({ action => 'changemsgforward',
1.49 albertel 1034: linktext => 'Change Message Forwarding and Notification Addresses',
1.35 matthew 1035: href => '/adm/preferences',
1036: help => 'Prefs_Forwarding',
1037: breadcrumb =>
1038: { href => '/adm/preferences?action=changemsgforward',
1039: text => 'Change Message Forwarding'},
1040: subroutine => \&msgforwardchanger,
1041: },
1042: { action => 'verify_and_change_msgforward',
1043: breadcrumb =>
1044: { href => '/adm/preferences?action=changemsgforward',
1045: text => 'Change Message Forwarding'},
1046: printmenu => 'yes',
1047: subroutine => \&verify_and_change_msgforward }));
1048: my $aboutmeaction=
1049: '/adm/'.$ENV{'user.domain'}.'/'.$ENV{'user.name'}.'/aboutme';
1050: push (@Options,{ action => 'none',
1051: linktext =>
1.41 www 1052: q{Edit the 'About Me' Personal Information Screen},
1.45 www 1053: help => 'Prefs_About_Me',
1.35 matthew 1054: href => $aboutmeaction});
1055: push (@Options,({ action => 'changecolors',
1056: linktext => 'Change Color Scheme',
1057: href => '/adm/preferences',
1058: help => 'Change_Colors',
1059: breadcrumb =>
1060: { href => '/adm/preferences?action=changecolors',
1061: text => 'Change Colors'},
1062: subroutine => \&colorschanger,
1063: },
1064: { action => 'verify_and_change_colors',
1065: breadcrumb =>
1066: { href => '/adm/preferences?action=changecolors',
1067: text => 'Change Colors'},
1068: printmenu => 'yes',
1069: subroutine => \&verify_and_change_colors,
1070: }));
1071: push (@Options,({ action => 'changelanguages',
1.39 www 1072: linktext => 'Change Language Preferences',
1.35 matthew 1073: href => '/adm/preferences',
1.45 www 1074: help => 'Prefs_Language',
1.35 matthew 1075: breadcrumb=>
1076: { href => '/adm/preferences?action=changelanguages',
1077: text => 'Change Language'},
1078: subroutine => \&languagechanger,
1079: },
1080: { action => 'verify_and_change_languages',
1081: breadcrumb=>
1082: {href => '/adm/preferences?action=changelanguages',
1083: text => 'Change Language'},
1084: printmenu => 'yes',
1085: subroutine=>\&verify_and_change_languages, }
1086: ));
1.44 www 1087: push (@Options,({ action => 'changewysiwyg',
1088: linktext => 'Change WYSIWYG Editor Preferences',
1089: href => '/adm/preferences',
1090: breadcrumb =>
1091: { href => '/adm/preferences?action=changewysiwyg',
1092: text => 'Change WYSIWYG Preferences'},
1093: subroutine => \&wysiwygchanger,
1094: },
1095: { action => 'set_wysiwyg',
1096: breadcrumb =>
1097: { href => '/adm/preferences?action=changewysiwyg',
1098: text => 'Change WYSIWYG Preferences'},
1099: printmenu => 'yes',
1100: subroutine => \&verify_and_change_wysiwyg, }
1101: ));
1.42 raeburn 1102: push (@Options,({ action => 'changediscussions',
1103: linktext => 'Change Discussion Display Preferences',
1104: href => '/adm/preferences',
1.46 raeburn 1105: help => 'Change_Discussion_Display',
1.42 raeburn 1106: breadcrumb =>
1107: { href => '/adm/preferences?action=changediscussions',
1.43 raeburn 1108: text => 'Change Discussion Preferences'},
1.42 raeburn 1109: subroutine => \&discussionchanger,
1110: },
1111: { action => 'verify_and_change_discussion',
1112: breadcrumb =>
1113: { href => '/adm/preferences?action=changediscussions',
1.43 raeburn 1114: text => 'Change Discussion Preferences'},
1.42 raeburn 1115: printmenu => 'yes',
1116: subroutine => \&verify_and_change_discussion, }
1117: ));
1118:
1.50 albertel 1119: push (@Options,({ action => 'changerolespref',
1120: linktext => 'Change Roles Page Preferences',
1121: href => '/adm/preferences',
1122: subroutine => \&rolesprefchanger,
1123: breadcrumb =>
1124: { href => '/adm/preferences?action=changerolespref',
1125: text => 'Change Roles Pref'},
1126: },
1127: { action => 'verify_and_change_rolespref',
1128: subroutine => \&verify_and_change_rolespref,
1129: breadcrumb =>
1130: { href => '/adm/preferences?action=changerolespref',
1131: text => 'Change Roles Preferences'},
1132: printmenu => 'yes',
1133: }));
1134:
1.54 albertel 1135: push (@Options,({ action => 'changetexenginepref',
1136: linktext => 'Change How Math Equations Are Displayed',
1137: href => '/adm/preferences',
1138: subroutine => \&texenginechanger,
1139: breadcrumb =>
1140: { href => '/adm/preferences?action=changetexenginepref',
1141: text => 'Change Math Pref'},
1142: },
1143: { action => 'verify_and_change_texengine',
1144: subroutine => \&verify_and_change_texengine,
1145: breadcrumb =>
1146: { href => '/adm/preferences?action=changetexenginepref',
1147: text => 'Change Math Preferences'},
1148: printmenu => 'yes',
1149: }));
1150:
1.50 albertel 1151:
1.51 foxr 1152: if ($ENV{'user.name'} =~ /^(albertel|fox|foxr|koretemey|korte|hallmat3|turtle)$/) {
1.35 matthew 1153: push (@Options,({ action => 'debugtoggle',
1154: printmenu => 'yes',
1155: subroutine => \&toggle_debug,
1156: }));
1157: }
1.53 albertel 1158: my $html=&Apache::lonxml::xmlbegin();
1.35 matthew 1159: $r->print(<<ENDHEADER);
1.53 albertel 1160: $html
1.1 www 1161: <head>
1.4 matthew 1162: <title>LON-CAPA Preferences</title>
1.1 www 1163: </head>
1.3 matthew 1164: ENDHEADER
1.35 matthew 1165: my $call = undef;
1.48 albertel 1166: my $help = undef;
1.35 matthew 1167: my $printmenu = 'yes';
1168: foreach my $option (@Options) {
1169: if ($option->{'action'} eq $ENV{'form.action'}) {
1170: $call = $option->{'subroutine'};
1171: $printmenu = $option->{'printmenu'};
1172: if (exists($option->{'breadcrumb'})) {
1173: &Apache::lonhtmlcommon::add_breadcrumb
1174: ($option->{'breadcrumb'});
1175: }
1.48 albertel 1176: $help=$option->{'help'};
1.35 matthew 1177: }
1178: }
1179: $r->print(&Apache::loncommon::bodytag('Change Preferences'));
1180: $r->print(&Apache::lonhtmlcommon::breadcrumbs
1.48 albertel 1181: (undef,'Change Preferences',$help));
1.35 matthew 1182: if (defined($call)) {
1183: $call->($r);
1184: }
1.44 www 1185: if (($printmenu eq 'yes') && (!$ENV{'form.returnurl'})) {
1.35 matthew 1186: my $optionlist = '<table cellpadding="5">';
1187: if ($ENV{'user.name'} =~
1.51 foxr 1188: /^(albertel|kortemey|fox|foxr|korte|hallmat3|turtle)$/
1.35 matthew 1189: ) {
1190: push (@Options,({ action => 'debugtoggle',
1191: linktext => 'Toggle Debug Messages',
1192: text => 'Current Debug status is -'.
1193: $ENV{'user.debug'}.'-.',
1194: href => '/adm/preferences',
1195: printmenu => 'yes',
1196: subroutine => \&toggle_debug,
1197: }));
1198: }
1199: foreach my $option(@Options) {
1200: my $optiontext = '';
1201: if (exists($option->{'href'})) {
1202: $optiontext .=
1203: '<a href="'.$option->{'href'}.
1204: '?action='.$option->{'action'}.'">'.
1.47 albertel 1205: &mt($option->{'linktext'}).'</a>';
1.35 matthew 1206: }
1207: if (exists($option->{'text'})) {
1.47 albertel 1208: $optiontext .= ' '.&mt($option->{'text'});
1.35 matthew 1209: }
1210: if ($optiontext ne '') {
1211: $optiontext = '<font size="+1">'.$optiontext.'</font>';
1212: my $helplink = ' ';
1213: if (exists($option->{'help'})) {
1214: $helplink = &Apache::loncommon::help_open_topic
1215: ($option->{'help'});
1216: }
1217: $optionlist .= '<tr>'.
1218: '<td>'.$helplink.'</td>'.
1219: '<td>'.$optiontext.'</td>'.
1220: '</tr>';
1221: }
1.13 www 1222: }
1.35 matthew 1223: $optionlist .= '</table>';
1224: $r->print($optionlist);
1.44 www 1225: } elsif ($ENV{'form.returnurl'}) {
1226: $r->print('<br /><a href="'.$ENV{'form.returnurl'}.'"><font size="+1">'.
1227: &mt('Return').'</font></a>');
1.3 matthew 1228: }
1.54 albertel 1229: $r->print(&Apache::loncommon::endbodytag().'</html>');
1.1 www 1230: return OK;
1.35 matthew 1231: }
1232:
1233: sub toggle_debug {
1234: if ($ENV{'user.debug'}) {
1235: &Apache::lonnet::delenv('user\.debug');
1236: } else {
1237: &Apache::lonnet::appenv('user.debug' => 1);
1238: }
1.13 www 1239: }
1.1 www 1240:
1241: 1;
1242: __END__
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>