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