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