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