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