Annotation of loncom/interface/lonpreferences.pm, revision 1.132
1.1 www 1: # The LearningOnline Network
2: # Preferences
3: #
1.132 ! raeburn 4: # $Id: lonpreferences.pm,v 1.131 2008/12/08 23:09:26 raeburn 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.95 albertel 45: use LONCAPA();
1.3 matthew 46:
47: #
48: # Write lonnet::passwd to do the call below.
49: # Use:
50: # my $answer=reply("encrypt:passwd:$udom:$uname:$upass",$tryserver);
51: #
52: ##################################################
53: # password associated functions #
54: ##################################################
55: sub des_keys {
1.4 matthew 56: # Make a new key for DES encryption.
1.36 www 57: # Each key has two parts which are returned separately.
1.4 matthew 58: # Please note: Each key must be passed through the &hex function
59: # before it is output to the web browser. The hex versions cannot
60: # be used to decrypt.
1.3 matthew 61: my @hexstr=('0','1','2','3','4','5','6','7',
62: '8','9','a','b','c','d','e','f');
63: my $lkey='';
64: for (0..7) {
65: $lkey.=$hexstr[rand(15)];
66: }
67: my $ukey='';
68: for (0..7) {
69: $ukey.=$hexstr[rand(15)];
70: }
71: return ($lkey,$ukey);
72: }
73:
74: sub des_decrypt {
75: my ($key,$cyphertext) = @_;
76: my $keybin=pack("H16",$key);
77: my $cypher;
78: if ($Crypt::DES::VERSION>=2.03) {
79: $cypher=new Crypt::DES $keybin;
80: } else {
81: $cypher=new DES $keybin;
82: }
83: my $plaintext=
84: $cypher->decrypt(unpack("a8",pack("H16",substr($cyphertext,0,16))));
85: $plaintext.=
86: $cypher->decrypt(unpack("a8",pack("H16",substr($cyphertext,16,16))));
1.4 matthew 87: $plaintext=substr($plaintext,1,ord(substr($plaintext,0,1)) );
1.3 matthew 88: return $plaintext;
89: }
90:
1.4 matthew 91: ################################################################
92: # Handler subroutines #
93: ################################################################
1.9 matthew 94:
95: ################################################################
1.28 www 96: # Language Change Subroutines #
97: ################################################################
1.44 www 98:
99: sub wysiwygchanger {
100: my $r = shift;
1.126 droeschl 101: Apache::lonhtmlcommon::add_breadcrumb(
102: { href => '/adm/preferences?action=changewysiwyg',
103: text => 'Change WYSIWYG Preferences'});
104: $r->print(Apache::loncommon::start_page('Change WYSIWYG Preferences'));
105: $r->print(Apache::lonhtmlcommon::breadcrumbs('Change WYSIWYG Preferences'));
106:
1.44 www 107: my %userenv = &Apache::lonnet::get
108: ('environment',['wysiwygeditor']);
1.78 albertel 109: my $onselect='checked="checked"';
1.44 www 110: my $offselect='';
1.77 albertel 111: if ($userenv{'wysiwygeditor'} eq 'on') {
1.44 www 112: $onselect='';
1.78 albertel 113: $offselect='checked="checked"';
1.44 www 114: }
115: my $switchoff=&mt('Disable WYSIWYG editor');
116: my $switchon=&mt('Enable WYSIWYG editor');
1.124 www 117: my $warning='';
118: if ($env{'user.adv'}) {
119: $warning.="<p>".&mt("The WYSIWYG editor only supports simple HTML and is in many cases unsuited for advanced authoring. In a number of cases, it may destroy advanced authoring involving LaTeX and script function calls.")."</p>";
120: }
1.44 www 121: $r->print(<<ENDLSCREEN);
1.88 albertel 122: <form name="prefs" action="/adm/preferences" method="post">
1.44 www 123: <input type="hidden" name="action" value="set_wysiwyg" />
1.124 www 124: $warning
1.44 www 125: <br />
1.65 albertel 126: <label><input type="radio" name="wysiwyg" value="off" $onselect /> $switchoff</label><br />
127: <label><input type="radio" name="wysiwyg" value="on" $offselect /> $switchon</label>
1.44 www 128: ENDLSCREEN
129: $r->print('<br /><input type="submit" value="'.&mt('Change').'" />');
130: }
131:
132:
133: sub verify_and_change_wysiwyg {
134: my $r = shift;
1.59 albertel 135: my $newsetting=$env{'form.wysiwyg'};
1.44 www 136: &Apache::lonnet::put('environment',{'wysiwygeditor' => $newsetting});
1.116 raeburn 137: &Apache::lonnet::appenv({'environment.wysiwygeditor' => $newsetting});
1.126 droeschl 138: # $r->print('<p>'.&mt('Setting WYSIWYG editor to:').' '.&mt($newsetting).'</p>');
139: print_main_menu($r,'<p>'.&mt('Setting WYSIWYG editor to:').' '
140: .&mt($newsetting).'</p>');
1.44 www 141: }
142:
143: ################################################################
144: # Language Change Subroutines #
145: ################################################################
1.28 www 146: sub languagechanger {
147: my $r = shift;
1.126 droeschl 148:
149: Apache::lonhtmlcommon::add_breadcrumb(
150: { href => '/adm/preferences?action=changelanguages',
1.127 droeschl 151: text => 'Change Language'});
1.126 droeschl 152: $r->print(Apache::loncommon::start_page('Change Language'));
153: $r->print(Apache::lonhtmlcommon::breadcrumbs('Change Language'));
1.59 albertel 154: my $user = $env{'user.name'};
155: my $domain = $env{'user.domain'};
1.28 www 156: my %userenv = &Apache::lonnet::get
1.32 www 157: ('environment',['languages']);
1.29 www 158: my $language=$userenv{'languages'};
1.32 www 159:
1.33 www 160: my $pref=&mt('Preferred language');
161: my %langchoices=('' => 'No language preference');
162: foreach (&Apache::loncommon::languageids()) {
163: if (&Apache::loncommon::supportedlanguagecode($_)) {
164: $langchoices{&Apache::loncommon::supportedlanguagecode($_)}
165: = &Apache::loncommon::plainlanguagedescription($_);
166: }
167: }
168: my $selectionbox=&Apache::loncommon::select_form($language,'language',
169: %langchoices);
1.28 www 170: $r->print(<<ENDLSCREEN);
1.88 albertel 171: <form name="prefs" action="/adm/preferences" method="post">
1.28 www 172: <input type="hidden" name="action" value="verify_and_change_languages" />
1.33 www 173: <br />$pref: $selectionbox
1.28 www 174: ENDLSCREEN
1.35 matthew 175: $r->print('<br /><input type="submit" value="'.&mt('Change').'" />');
1.28 www 176: }
177:
178:
179: sub verify_and_change_languages {
180: my $r = shift;
1.59 albertel 181: my $user = $env{'user.name'};
182: my $domain = $env{'user.domain'};
1.28 www 183: # Screenname
1.59 albertel 184: my $newlanguage = $env{'form.language'};
1.28 www 185: $newlanguage=~s/[^\-\w]//g;
186: my $message='';
187: if ($newlanguage) {
1.29 www 188: &Apache::lonnet::put('environment',{'languages' => $newlanguage});
1.116 raeburn 189: &Apache::lonnet::appenv({'environment.languages' => $newlanguage});
1.110 bisitz 190: $message=&mt('Set new preferred languages to ').'<tt>"'.$newlanguage.'"</tt>.';
1.28 www 191: } else {
1.29 www 192: &Apache::lonnet::del('environment',['languages']);
193: &Apache::lonnet::delenv('environment\.languages');
1.110 bisitz 194: $message=&mt('Reset preferred language.');
1.28 www 195: }
1.132 ! raeburn 196: &Apache::loncommon::flush_langs_cache($user,$domain);
1.126 droeschl 197: print_main_menu($r, $message);
198: # $r->print(<<ENDVCSCREEN);
199: #$message
200: #ENDVCSCREEN
1.28 www 201: }
202:
1.50 albertel 203: ################################################################
1.54 albertel 204: # Tex Engine Change Subroutines #
205: ################################################################
206: sub texenginechanger {
207: my $r = shift;
1.126 droeschl 208: Apache::lonhtmlcommon::add_breadcrumb(
209: { href => '/adm/preferences?action=changetexenginepref',
210: text => 'Change How Math Equations Are Displayed'});
211: $r->print(Apache::loncommon::start_page('Change How Math Equations Are Displayed'));
212: $r->print(Apache::lonhtmlcommon::breadcrumbs('Change How Math Equations Are Displayed'));
1.59 albertel 213: my $user = $env{'user.name'};
214: my $domain = $env{'user.domain'};
1.54 albertel 215: my %userenv = &Apache::lonnet::get('environment',['texengine']);
216: my $texengine=$userenv{'texengine'};
217:
1.69 albertel 218: my %mathchoices=('' => 'Default',
1.123 bisitz 219: 'tth' => 'tth (TeX to HTML)',
1.64 albertel 220: #'ttm' => 'TeX to MathML',
1.54 albertel 221: 'jsMath' => 'jsMath',
1.123 bisitz 222: 'mimetex' => 'mimetex (Convert to Images)'
1.54 albertel 223: );
224: my $selectionbox=&Apache::loncommon::select_form($texengine,'texengine',
225: %mathchoices);
1.67 albertel 226: my $jsMath_start=&Apache::lontexconvert::jsMath_header();
1.123 bisitz 227: my %lt=&Apache::lonlocal::texthash(
228: 'headline' => 'Change Math Preferences',
229: 'preftxt' => 'Preferred method to display Math',
230: 'change' => 'Change',
231: 'exmpl' => 'Examples',
232: 'jsmath' => 'jsMath:',
233: 'tth' => 'tth (TeX to HTML):',
234: 'mimetex' => 'mimetex (Convert to Images):',
235: );
236:
1.54 albertel 237: $r->print(<<ENDLSCREEN);
1.123 bisitz 238: <h2>$lt{'headline'}</h2>
1.88 albertel 239: <form name="prefs" action="/adm/preferences" method="post">
1.54 albertel 240: <input type="hidden" name="action" value="verify_and_change_texengine" />
1.123 bisitz 241: <p>
242: $lt{'preftxt'}:<br />
243: $selectionbox <input type="submit" value="$lt{'change'}" />
244: </p>
1.54 albertel 245: </form>
1.123 bisitz 246: <br />
247: <hr />
248: $lt{'exmpl'}
249:
250: <h3>$lt{'jsmath'}</h3>
251: <p>
1.67 albertel 252: $jsMath_start
1.57 albertel 253: <script type="text/javascript">
1.54 albertel 254: if (jsMath.nofonts == 1) {
255: document.writeln
1.123 bisitz 256: ('<div style="padding: 10; border-style: solid; border-width:3;'
1.54 albertel 257: +' border-color: #DD0000; background-color: #FFF8F8; width: 75%; text-align: left">'
258: +'<small><font color="#AA0000"><b>Warning:</b> '
259: +'It looks like you don\\\'t have the TeX math fonts installed. '
260: +'The jsMath example on this page may not look right without them. '
261: +'The <a href="http://www.math.union.edu/locate/jsMath/" target="_blank"> '
262: +'jsMath Home Page</a> has information on how to download the '
263: +'needed fonts. In the meantime, jsMath will do the best it can '
264: +'with the fonts you have, but it may not be pretty and some equations '
265: +'may not be rendered correctly. '
1.123 bisitz 266: +'</font></small></div>');
1.54 albertel 267: }
268: </script>
1.122 www 269: <iframe src="/res/adm/pages/math_example.tex?inhibitmenu=yes&texengine=jsMath" width="400" height="120"></iframe>
1.123 bisitz 270: </p>
1.54 albertel 271:
1.123 bisitz 272: <h3>$lt{'mimetex'}</h3>
273: <p>
274: <iframe src="/res/adm/pages/math_example.tex?inhibitmenu=yes&texengine=mimetex" width="400" height="100"></iframe>
1.67 albertel 275: </p>
1.123 bisitz 276:
277: <h3>$lt{'tth'}</h3>
278: <p>
279: <iframe src="/res/adm/pages/math_example.tex?inhibitmenu=yes&texengine=tth" width="400" height="200"></iframe>
1.67 albertel 280: </p>
1.54 albertel 281: ENDLSCREEN
1.59 albertel 282: if ($env{'environment.texengine'} ne 'jsMath') {
1.55 albertel 283: $r->print('<script type="text/javascript">jsMath.Process()</script>');
284: }
1.54 albertel 285: }
286:
287:
288: sub verify_and_change_texengine {
289: my $r = shift;
1.59 albertel 290: my $user = $env{'user.name'};
291: my $domain = $env{'user.domain'};
1.54 albertel 292: # Screenname
1.59 albertel 293: my $newtexengine = $env{'form.texengine'};
1.54 albertel 294: $newtexengine=~s/[^\-\w]//g;
1.56 albertel 295: if ($newtexengine eq 'ttm') {
1.116 raeburn 296: &Apache::lonnet::appenv({'browser.mathml' => 1});
1.56 albertel 297: } else {
1.59 albertel 298: if ($env{'environment.texengine'} eq 'ttm') {
1.116 raeburn 299: &Apache::lonnet::appenv({'browser.mathml' => 0});
1.56 albertel 300: }
301: }
1.54 albertel 302: my $message='';
303: if ($newtexengine) {
304: &Apache::lonnet::put('environment',{'texengine' => $newtexengine});
1.116 raeburn 305: &Apache::lonnet::appenv({'environment.texengine' => $newtexengine});
1.110 bisitz 306: $message=&mt('Set new preferred math display to ').'<tt>"'.$newtexengine.'"</tt>.';
1.54 albertel 307: } else {
308: &Apache::lonnet::del('environment',['texengine']);
309: &Apache::lonnet::delenv('environment\.texengine');
1.110 bisitz 310: $message=&mt('Reset preferred math display.');
1.54 albertel 311: }
1.56 albertel 312:
313:
1.126 droeschl 314: # $r->print(<<ENDVCSCREEN);
315: #$message
316: #ENDVCSCREEN
317: print_main_menu($r, $message);
1.54 albertel 318: }
319:
320: ################################################################
1.50 albertel 321: # Roles Page Preference Change Subroutines #
322: ################################################################
323: sub rolesprefchanger {
324: my $r = shift;
1.96 albertel 325: my $role = ($env{'user.adv'} ? 'Role' : 'Course');
326: my $lc_role = ($env{'user.adv'} ? 'role' : 'course');
1.59 albertel 327: my $user = $env{'user.name'};
328: my $domain = $env{'user.domain'};
1.50 albertel 329: my %userenv = &Apache::lonnet::get
330: ('environment',['recentroles','recentrolesn']);
1.126 droeschl 331: Apache::lonhtmlcommon::add_breadcrumb(
332: { href => '/adm/preferences?action=changerolespref',
333: text => 'Change '.$role.' Page Pref'});
334: $r->print(Apache::loncommon::start_page('Change '.$role.' Page Pref'));
335: $r->print(Apache::lonhtmlcommon::breadcrumbs('Change '.$role.' Page Pref'));
1.50 albertel 336: my $hotlist_flag=$userenv{'recentroles'};
337: my $hotlist_n=$userenv{'recentrolesn'};
338: my $checked;
339: if ($hotlist_flag) {
340: $checked = 'checked="checked"';
341: }
342:
343: if (!$hotlist_n) { $hotlist_n=3; }
344: my $options;
345: for (my $i=1; $i<10; $i++) {
346: my $select;
347: if ($hotlist_n == $i) { $select = 'selected="selected"'; }
348: $options .= "<option $select>$i</option>\n";
349: }
350:
1.89 albertel 351: # Get list of recent roles and display with checkbox in front
352: my $roles_check_list = '';
353: my $role_key='';
354: if ($env{'environment.recentroles'}) {
355: my %recent_roles =
356: &Apache::lonhtmlcommon::get_recent('roles',$env{'environment.recentrolesn'});
1.91 albertel 357: my %frozen_roles =
358: &Apache::lonhtmlcommon::get_recent_frozen('roles',$env{'environment.recentrolesn'});
1.89 albertel 359:
1.93 albertel 360: my %role_text = &rolespref_get_role_text([keys(%recent_roles)]);
1.92 albertel 361: my @sorted_roles = sort {$role_text{$a} cmp $role_text{$b}} keys(%role_text);
362:
1.89 albertel 363: $roles_check_list .=
364: &Apache::loncommon::start_data_table().
365: &Apache::loncommon::start_data_table_header_row().
1.96 albertel 366: "<th>".&mt('Freeze '.$role)."</th>".
367: "<th>".&mt($role)."</td>".
1.89 albertel 368: &Apache::loncommon::end_data_table_header_row().
369: "\n";
370: my $count;
1.92 albertel 371: foreach $role_key (@sorted_roles) {
1.89 albertel 372: my $checked = "";
373: my $value = $recent_roles{$role_key};
1.91 albertel 374: if ($frozen_roles{$role_key}) {
1.89 albertel 375: $checked = "checked=\"checked\"";
376: }
377: $count++;
378: $roles_check_list .=
379: &Apache::loncommon::start_data_table_row().
380: '<td class="LC_table_cell_checkbox">'.
381: "<input type=\"checkbox\" $checked name=\"freezeroles\"".
382: " id=\"freezeroles$count\" value=\"$role_key\" /></td>".
383: "<td><label for=\"freezeroles$count\">".
1.92 albertel 384: "$role_text{$role_key}</label></td>".
1.89 albertel 385: &Apache::loncommon::end_data_table_row(). "\n";
386: }
387: $roles_check_list .= "</table>\n";
388: }
389:
390: $r->print('
1.96 albertel 391: <p>'.&mt('Some LON-CAPA users have a long list of '.$lc_role.'s. The Recent '.$role.'s Hotlist feature keeps track of the last N '.$lc_role.'s which have been visited and places a table of these at the top of the '.$lc_role.'s page. People with very few '.$lc_role.'s should leave this feature disabled.').'
1.50 albertel 392: </p>
1.89 albertel 393: <form name="prefs" action="/adm/preferences" method="POST">
1.50 albertel 394: <input type="hidden" name="action" value="verify_and_change_rolespref" />
1.96 albertel 395: <br /><label>'.&mt('Enable Recent '.$role.'s Hotlist:').'
1.89 albertel 396: <input type="checkbox" '.$checked.' name="recentroles" value="true" /></label>
1.96 albertel 397: <br />'.&mt('Number of '.$role.'s in Hotlist:').'
1.50 albertel 398: <select name="recentrolesn" size="1">
1.89 albertel 399: '.$options.'
1.50 albertel 400: </select>
1.96 albertel 401: <p>'.&mt('This list below can be used to <q>freeze</q> '.$lc_role.'s on your screen. Those marked as frozen will not be removed from the list, even if they have not been used recently.').'
1.89 albertel 402: </p>
403: '.$roles_check_list.'
1.50 albertel 404: <br />
1.89 albertel 405: <input type="submit" value="'.&mt('Change').'" />
406: </form>');
1.50 albertel 407: }
408:
1.92 albertel 409: sub rolespref_get_role_text {
410: # Get a line of text for each role
411: my ($roles) = @_;
412: my %roletext = ();
413:
414: foreach my $item (@$roles) {
415: # get course information
416: my ($role,$rest) = split(/\./, $item);
1.93 albertel 417: my $trole = "";
418: $trole = &Apache::lonnet::plaintext($role);
1.92 albertel 419: my ($tdomain,$other,$tsection)= split(/\//,Apache::lonnet::declutter($rest));
420: my $tother = '-';
1.93 albertel 421: if ($role =~ /^(cc|st|in|ta|ep|cr)/ ) {
1.92 albertel 422: my %newhash=&Apache::lonnet::coursedescription($tdomain."_".$other);
423: $tother = " - ".$newhash{'description'};
424: } elsif ($role =~ /dc/) {
425: $tother = "";
426: } else {
427: $tother = " - $other";
428: }
429:
430: my $section="";
431: if ($tsection) {
432: $section = " - Section/Group: $tsection";
433: }
434: $roletext{$item} = $tdomain." - ".$trole.$tother.$section;
435: }
436: return %roletext;
437: }
438:
1.50 albertel 439: sub verify_and_change_rolespref {
440: my $r = shift;
1.96 albertel 441: my $role = ($env{'user.adv'} ? 'Role' : 'Course');
1.59 albertel 442: my $user = $env{'user.name'};
443: my $domain = $env{'user.domain'};
1.50 albertel 444: # Recent Roles Hotlist Flag
1.59 albertel 445: my $hotlist_flag = $env{'form.recentroles'};
446: my $hotlist_n = $env{'form.recentrolesn'};
1.89 albertel 447: my $message='<hr />';
1.50 albertel 448: if ($hotlist_flag) {
449: &Apache::lonnet::put('environment',{'recentroles' => $hotlist_flag});
1.116 raeburn 450: &Apache::lonnet::appenv({'environment.recentroles' => $hotlist_flag});
1.96 albertel 451: $message=&mt('Recent '.$role.'s Hotlist is Enabled');
1.50 albertel 452: } else {
453: &Apache::lonnet::del('environment',['recentroles']);
454: &Apache::lonnet::delenv('environment\.recentroles');
1.96 albertel 455: $message=&mt('Recent '.$role.'s Hotlist is Disabled');
1.50 albertel 456: }
457: if ($hotlist_n) {
458: &Apache::lonnet::put('environment',{'recentrolesn' => $hotlist_n});
1.116 raeburn 459: &Apache::lonnet::appenv({'environment.recentrolesn' => $hotlist_n});
1.50 albertel 460: if ($hotlist_flag) {
1.90 albertel 461: $message.="<br />".
1.96 albertel 462: &mt('Display [_1] Most Recent '.$role.'s',$hotlist_n)."\n";
1.89 albertel 463: }
464: }
465:
466: # Get list of froze roles and list of recent roles
467: my @freeze_list = &Apache::loncommon::get_env_multiple('form.freezeroles');
468: my %freeze = ();
1.92 albertel 469: my %roletext = ();
470:
1.89 albertel 471: foreach my $key (@freeze_list) {
1.91 albertel 472: $freeze{$key}='1';
1.89 albertel 473: }
1.92 albertel 474:
1.89 albertel 475: my %recent_roles =
476: &Apache::lonhtmlcommon::get_recent('roles',$env{'environment.recentrolesn'});
1.91 albertel 477: my %frozen_roles =
478: &Apache::lonhtmlcommon::get_recent_frozen('roles',$env{'environment.recentrolesn'});
1.92 albertel 479: my %role_text = &rolespref_get_role_text([keys(%recent_roles)]);
1.89 albertel 480:
481: # Unset any roles that were previously frozen but aren't in list
482: foreach my $role_key (sort(keys(%recent_roles))) {
1.91 albertel 483: if (($frozen_roles{$role_key}) && (!exists($freeze{$role_key}))) {
1.96 albertel 484: $message .= "<br />".&mt('Unfreezing '.$role.': [_1]',$role_text{$role_key})."\n";
1.91 albertel 485: &Apache::lonhtmlcommon::store_recent('roles',$role_key,' ',0);
1.89 albertel 486: }
487: }
488:
489: # Freeze selected roles
490: foreach my $role_key (@freeze_list) {
1.91 albertel 491: if (!$frozen_roles{$role_key}) {
1.96 albertel 492: $message .= "<br />".&mt('Freezing '.$role.': [_1]',$role_text{$role_key})."\n";
1.89 albertel 493: &Apache::lonhtmlcommon::store_recent('roles',
1.91 albertel 494: $role_key,' ',1);
1.50 albertel 495: }
496: }
1.89 albertel 497: $message .= "<hr /><br />\n";
1.50 albertel 498:
1.126 droeschl 499: # $r->print(<<ENDRPSCREEN);
500: #$message
501: #ENDRPSCREEN
502: print_main_menu($r, $message);
1.50 albertel 503: }
504:
505:
1.28 www 506:
507: ################################################################
1.9 matthew 508: # Anonymous Discussion Name Change Subroutines #
509: ################################################################
1.5 www 510: sub screennamechanger {
511: my $r = shift;
1.59 albertel 512: my $user = $env{'user.name'};
513: my $domain = $env{'user.domain'};
1.14 www 514: my %userenv = &Apache::lonnet::get
515: ('environment',['screenname','nickname']);
1.6 www 516: my $screenname=$userenv{'screenname'};
1.14 www 517: my $nickname=$userenv{'nickname'};
1.110 bisitz 518: my %lt = &Apache::lonlocal::texthash(
519: text_screenname => 'New screenname (shown if you post anonymously):',
520: text_nickname => 'New nickname (shown if you post non-anonymously):',
521: text_submit => 'Change',
522: );
1.126 droeschl 523: Apache::lonhtmlcommon::add_breadcrumb(
524: { href => '/adm/preferences?action=changescreenname',
525: text => 'Change Screen Name'});
526: $r->print(Apache::loncommon::start_page('Change Screen Name'));
527: $r->print(Apache::lonhtmlcommon::breadcrumbs('Change Screen Name'));
1.5 www 528: $r->print(<<ENDSCREEN);
1.88 albertel 529: <form name="prefs" action="/adm/preferences" method="post">
1.6 www 530: <input type="hidden" name="action" value="verify_and_change_screenname" />
1.110 bisitz 531: <br />$lt{'text_screenname'}
1.6 www 532: <input type="text" size="20" value="$screenname" name="screenname" />
1.110 bisitz 533: <br />$lt{'text_nickname'}
1.14 www 534: <input type="text" size="20" value="$nickname" name="nickname" />
1.110 bisitz 535: <br />
536: <input type="submit" value="$lt{'text_submit'}" />
1.6 www 537: </form>
1.5 www 538: ENDSCREEN
539: }
1.6 www 540:
541: sub verify_and_change_screenname {
542: my $r = shift;
1.59 albertel 543: my $user = $env{'user.name'};
544: my $domain = $env{'user.domain'};
1.14 www 545: # Screenname
1.59 albertel 546: my $newscreen = $env{'form.screenname'};
1.14 www 547: $newscreen=~s/[^ \w]//g;
1.6 www 548: my $message='';
549: if ($newscreen) {
1.7 www 550: &Apache::lonnet::put('environment',{'screenname' => $newscreen});
1.116 raeburn 551: &Apache::lonnet::appenv({'environment.screenname' => $newscreen});
1.110 bisitz 552: $message=&mt('Set new screenname to ').'<tt>"'.$newscreen.'."</tt>.';
1.6 www 553: } else {
554: &Apache::lonnet::del('environment',['screenname']);
1.7 www 555: &Apache::lonnet::delenv('environment\.screenname');
1.110 bisitz 556: $message=&mt('Reset screenname.');
1.6 www 557: }
1.14 www 558: # Nickname
559: $message.='<br />';
1.59 albertel 560: $newscreen = $env{'form.nickname'};
1.14 www 561: $newscreen=~s/[^ \w]//g;
562: if ($newscreen) {
563: &Apache::lonnet::put('environment',{'nickname' => $newscreen});
1.116 raeburn 564: &Apache::lonnet::appenv({'environment.nickname' => $newscreen});
1.110 bisitz 565: $message.=&mt('Set new nickname to ').'<tt>"'.$newscreen.'"</tt>.';
1.14 www 566: } else {
567: &Apache::lonnet::del('environment',['nickname']);
568: &Apache::lonnet::delenv('environment\.nickname');
1.110 bisitz 569: $message.=&mt('Reset nickname.');
1.14 www 570: }
1.68 www 571: &Apache::lonnet::devalidate_cache_new('namescache',$user.':'.$domain);
1.126 droeschl 572: # $r->print(<<ENDVCSCREEN);
573: #$message
574: #ENDVCSCREEN
575: print_main_menu($r, $message);
1.20 www 576: }
577:
578: ################################################################
1.98 www 579: # Icon Subroutines #
580: ################################################################
581: sub iconchanger {
582: my $r = shift;
1.126 droeschl 583: Apache::lonhtmlcommon::add_breadcrumb(
584: { href => '/adm/preferences?action=changeicons',
585: text => 'Change Main Menu'});
586: $r->print(Apache::loncommon::start_page('Change Main Menu'));
587: $r->print(Apache::lonhtmlcommon::breadcrumbs('Change Main Menu'));
588:
1.98 www 589: my $user = $env{'user.name'};
590: my $domain = $env{'user.domain'};
591: my %userenv = &Apache::lonnet::get
592: ('environment',['icons']);
593: my $iconic='checked="checked"';
594: my $classic='';
1.100 www 595: my $onlyicon='';
1.98 www 596: if ($userenv{'icons'} eq 'classic') {
597: $classic='checked="checked"';
598: $iconic='';
599: }
1.100 www 600: if ($userenv{'icons'} eq 'iconsonly') {
601: $onlyicon='checked="checked"';
602: $iconic='';
603: }
604: my $useicons=&mt('Use icons and text');
605: my $usebuttons=&mt('Use buttons and text');
606: my $useicononly=&mt('Use icons only');
1.98 www 607: my $change=&mt('Change');
608: $r->print(<<ENDSCREEN);
609: <form name="prefs" action="/adm/preferences" method="post">
610: <input type="hidden" name="action" value="verify_and_change_icons" />
611: <label><input type="radio" name="menumode" value="iconic" $iconic /> $useicons</label><br />
612: <label><input type="radio" name="menumode" value="classic" $classic /> $usebuttons</label><br />
1.100 www 613: <label><input type="radio" name="menumode" value="iconsonly" $onlyicon /> $useicononly</label><br />
1.98 www 614: <input type="submit" value="$change" />
615: </form>
616: ENDSCREEN
617: }
618:
619: sub verify_and_change_icons {
620: my $r = shift;
621: my $user = $env{'user.name'};
622: my $domain = $env{'user.domain'};
623: my $newicons = $env{'form.menumode'};
624:
625: &Apache::lonnet::put('environment',{'icons' => $newicons});
1.116 raeburn 626: &Apache::lonnet::appenv({'environment.icons' => $newicons});
1.126 droeschl 627: # $r->print(&mt('Set menu mode to [_1].',$newicons));
628: print_main_menu($r, &mt('Set menu mode to [_1].',$newicons));
1.98 www 629: }
630:
631: ################################################################
1.105 www 632: # Clicker Subroutines #
633: ################################################################
634:
635: sub clickerchanger {
636: my $r = shift;
1.126 droeschl 637: Apache::lonhtmlcommon::add_breadcrumb(
638: { href => '/adm/preferences?action=changeclicker',
639: text => 'Register Clicker'});
640: $r->print(Apache::loncommon::start_page('Register Clicker'));
641: $r->print(Apache::lonhtmlcommon::breadcrumbs('Register Clicker'));
1.105 www 642: my $user = $env{'user.name'};
643: my $domain = $env{'user.domain'};
644: my %userenv = &Apache::lonnet::get
645: ('environment',['clickers']);
646: my $clickers=$userenv{'clickers'};
647: $clickers=~s/\,/\n/gs;
648: my $text=&mt('Enter response device ("clicker") numbers');
649: my $change=&mt('Register');
1.114 bisitz 650: my $helplink=&Apache::loncommon::help_open_topic('Clicker_Registration',&mt('Locating your clicker ID'));
1.105 www 651: $r->print(<<ENDSCREEN);
652: <form name="prefs" action="/adm/preferences" method="post">
653: <input type="hidden" name="action" value="verify_and_change_clicker" />
1.107 www 654: <label>$text $helplink<br />
1.108 www 655: <textarea name="clickers" rows="5" cols="20">$clickers</textarea>
1.105 www 656: </label>
657: <input type="submit" value="$change" />
658: </form>
659: ENDSCREEN
660: }
661:
662: sub verify_and_change_clicker {
663: my $r = shift;
664: my $user = $env{'user.name'};
665: my $domain = $env{'user.domain'};
666: my $newclickers = $env{'form.clickers'};
1.108 www 667: $newclickers=~s/[^\w\:\-]+/\,/gs;
1.105 www 668: $newclickers=~tr/a-z/A-Z/;
1.108 www 669: $newclickers=~s/[\:\-]+/\-/g;
670: $newclickers=~s/\,+/\,/g;
1.105 www 671: $newclickers=~s/^\,//;
672: $newclickers=~s/\,$//;
673: &Apache::lonnet::put('environment',{'clickers' => $newclickers});
1.116 raeburn 674: &Apache::lonnet::appenv({'environment.clickers' => $newclickers});
1.126 droeschl 675: # $r->print(&mt('Registering clickers: [_1]',$newclickers));
676: print_main_menu($r, &mt('Registering clickers: [_1]',$newclickers));
1.105 www 677: }
678:
1.119 www 679: ################################################################
680: # Domcoord Access Subroutines #
681: ################################################################
682:
683: sub domcoordchanger {
684: my $r = shift;
1.126 droeschl 685: Apache::lonhtmlcommon::add_breadcrumb(
686: { href => '/adm/preferences?action=changedomcoord',
687: text => 'Restrict Domain Coordinator Access'});
688: $r->print(Apache::loncommon::start_page('Restrict Domain Coordinator Access'));
689: $r->print(Apache::lonhtmlcommon::breadcrumbs('Restrict Domain Coordinator Access'));
1.119 www 690: my $user = $env{'user.name'};
691: my $domain = $env{'user.domain'};
692: my %userenv = &Apache::lonnet::get
1.120 www 693: ('environment',['domcoord.author']);
1.119 www 694: my $constchecked='';
695: if ($userenv{'domcoord.author'} eq 'blocked') {
696: $constchecked='checked="checked"';
697: }
1.120 www 698: my $text=&mt('By default, the Domain Coordinator can enter your construction space.');
1.119 www 699: my $construction=&mt('Block access to construction space');
700: my $change=&mt('Change');
701: $r->print(<<ENDSCREEN);
702: <form name="prefs" action="/adm/preferences" method="post">
703: <input type="hidden" name="action" value="verify_and_change_domcoord" />
704: $text<br />
705: <label><input type="checkbox" name="construction" $constchecked />$construction</label><br />
706: <input type="submit" value="$change" />
707: </form>
708: ENDSCREEN
709: }
710:
711: sub verify_and_change_domcoord {
712: my $r = shift;
713: my $user = $env{'user.name'};
714: my $domain = $env{'user.domain'};
1.120 www 715: my %domcoord=('domcoord.author' => '');
1.119 www 716: if ($env{'form.construction'}) { $domcoord{'domcoord.author'}='blocked'; }
717: &Apache::lonnet::put('environment',\%domcoord);
1.120 www 718: &Apache::lonnet::appenv({'environment.domcoord.author' => $domcoord{'domcoord.author'}});
1.126 droeschl 719: # $r->print(&mt('Registering Domain Coordinator access restrictions.'));
720: print_main_menu($r, &mt('Registering Domain Coordinator access restrictions.'));
1.119 www 721: }
722:
1.118 www 723: #################################################################
724: ## Lock Subroutines #
725: #################################################################
726:
727: sub lockwarning {
728: my $r = shift;
729: my $title=&mt('Action locked');
730: my $texttop=&mt('LON-CAPA is currently performing the following actions:');
731: my $textbottom=&mt('Changing roles or logging out may result in data corruption.');
732: my ($num,%which)=&Apache::lonnet::get_locks();
733: my $which='';
734: foreach my $id (keys %which) {
735: $which.='<li>'.$which{$id}.'</li>';
736: }
737: my $change=&mt('Override');
738: $r->print(<<ENDSCREEN);
739: <form name="prefs" action="/adm/preferences" method="post">
740: <input type="hidden" name="action" value="verify_and_change_locks" />
741: <h1>$title</h1>
742: $texttop
743: <ul>
744: $which
745: </ul>
746: $textbottom
747: <input type="submit" value="$change" />
748: </form>
749: ENDSCREEN
750: }
751:
752: sub verify_and_change_lockwarning {
753: my $r = shift;
754: &Apache::lonnet::remove_all_locks();
755: $r->print(&mt('Cleared locks.'));
756: }
757:
758:
1.105 www 759: ################################################################
1.20 www 760: # Message Forward #
761: ################################################################
762:
763: sub msgforwardchanger {
1.102 raeburn 764: my ($r,$message) = @_;
1.59 albertel 765: my $user = $env{'user.name'};
766: my $domain = $env{'user.domain'};
1.102 raeburn 767: my %userenv = &Apache::lonnet::get('environment',['msgforward','notification','critnotification','notifywithhtml']);
1.20 www 768: my $msgforward=$userenv{'msgforward'};
1.102 raeburn 769: my %lt = &Apache::lonlocal::texthash(
770: all => 'All',
771: crit => 'Critical only',
772: reg => 'Non-critical only',
773: foad => 'Forwarding Address(es)',
1.113 raeburn 774: noti => 'Notification E-mail Address(es)',
1.110 bisitz 775: foad_exmpl => 'e.g. <tt>userA:domain1,userB:domain2,...</tt>',
1.130 schafran 776: mnot => 'E-mail Address(es) which should be notified about new LON-CAPA messages',
777: # old: 'Message Notification Email Address(es)',
1.110 bisitz 778: mnot_exmpl => 'e.g. <tt>joe@doe.com</tt>',
1.102 raeburn 779: chg => 'Change',
1.104 raeburn 780: email => 'The e-mail address entered in row ',
1.102 raeburn 781: notv => 'is not a valid e-mail address',
1.103 raeburn 782: toen => "To enter multiple addresses, enter one address at a time, click 'Change' and then add the next one",
1.102 raeburn 783: prme => 'Back to preferences menu',
784: );
1.126 droeschl 785: Apache::lonhtmlcommon::add_breadcrumb(
786: { href => '/adm/preferences?action=changemsgforward',
787: text => 'Change Message Forwarding/Notification'});
788: $r->print(Apache::loncommon::start_page('Change Message Forwarding/Notification'));
789: $r->print(Apache::lonhtmlcommon::breadcrumbs('Change Message Forwarding/Notification'));
1.113 raeburn 790: my $forwardingHelp = &Apache::loncommon::help_open_topic("Prefs_Forwarding");
791: my $notificationHelp = &Apache::loncommon::help_open_topic("Prefs_Notification");
792: my $criticalMessageHelp = &Apache::loncommon::help_open_topic("Course_Critical_Message");
1.102 raeburn 793: my @allow_html = split(/,/,$userenv{'notifywithhtml'});
794: my %allnot = &get_notifications(\%userenv);
795: my $validatescript = &Apache::lonhtmlcommon::javascript_valid_email();
796: my $jscript = qq|
797: <script type="text/javascript">
798: function validate() {
799: for (var i=0; i<document.prefs.numnotify.value; i++) {
1.104 raeburn 800: var checkaddress = 0;
1.102 raeburn 801: var addr = document.prefs.elements['address_'+i].value;
1.104 raeburn 802: var rownum = i+1;
1.102 raeburn 803: if (i < document.prefs.numnotify.value-1) {
1.104 raeburn 804: if (document.prefs.elements['modify_notify_'+i].checked) {
1.102 raeburn 805: checkaddress = 1;
1.104 raeburn 806: }
1.102 raeburn 807: } else {
808: if (document.prefs.elements['add_notify_'+i].checked == true) {
809: checkaddress = 1;
810: }
811: }
1.104 raeburn 812: if (checkaddress == 1) {
1.102 raeburn 813: var addr = document.prefs.elements['address_'+i].value;
814: if (validmail(document.prefs.elements['address_'+i]) == false) {
1.104 raeburn 815: var multimsg = '';
816: if (addr.indexOf(",") >= 0) {
817: multimsg = "\\n($lt{'toen'}).";
818: }
1.110 bisitz 819: alert("$lt{'email'} "+rownum+" ('"+addr+"') $lt{'notv'}."+multimsg);
1.102 raeburn 820: return;
821: }
822: }
823: }
824: document.prefs.submit();
825: }
1.104 raeburn 826:
827: function address_changes (adnum) {
828: if (!document.prefs.elements['del_notify_'+adnum].checked) {
829: document.prefs.elements['modify_notify_'+adnum].checked = true;
830: }
831: }
832:
833: function new_address(adnum) {
834: document.prefs.elements['add_notify_'+adnum].checked = true;
835: }
836:
837: function delete_address(adnum) {
838: if (document.prefs.elements['del_notify_'+adnum].checked) {
839: document.prefs.elements['modify_notify_'+adnum].checked = false;
840: }
841: }
842:
843: function modify_address(adnum) {
844: if (document.prefs.elements['modify_notify_'+adnum].checked) {
845: document.prefs.elements['del_notify_'+adnum].checked = false;
846: }
847: }
848:
1.102 raeburn 849: $validatescript
850: </script>
851: |;
1.20 www 852: $r->print(<<ENDMSG);
1.102 raeburn 853: $jscript
854: $message
1.113 raeburn 855: <h3>$lt{'foad'} $forwardingHelp</h3>
1.88 albertel 856: <form name="prefs" action="/adm/preferences" method="post">
1.20 www 857: <input type="hidden" name="action" value="verify_and_change_msgforward" />
1.110 bisitz 858: $lt{'foad'} ($lt{'foad_exmpl'}):
1.113 raeburn 859: <input type="text" size="40" value="$msgforward" name="msgforward" /><br />
860: <h3>$lt{'noti'} $notificationHelp</h3>
1.110 bisitz 861: $lt{'mnot'} ($lt{'mnot_exmpl'}):<br />
1.102 raeburn 862: ENDMSG
863: my @sortforwards = sort (keys(%allnot));
864: my $output = &Apache::loncommon::start_data_table().
865: &Apache::loncommon::start_data_table_header_row().
1.104 raeburn 866: '<th> </th>'.
1.102 raeburn 867: '<th>'.&mt('Action').'</th>'.
868: '<th>'.&mt('Notification address').'</th><th>'.
1.113 raeburn 869: &mt('Types of message for which notification is sent').
870: $criticalMessageHelp.'</th><th>'.
1.104 raeburn 871: &mt('Excerpt retains HTML tags in message').'</th>'.
1.102 raeburn 872: &Apache::loncommon::end_data_table_header_row();
873: my $num = 0;
1.104 raeburn 874: my $counter = 1;
1.102 raeburn 875: foreach my $item (@sortforwards) {
876: $output .= &Apache::loncommon::start_data_table_row().
1.104 raeburn 877: '<td><b>'.$counter.'</b></td>'.
878: '<td><span class="LC_nobreak"><label>'.
879: '<input type="checkbox" name="modify_notify_'.
880: $num.'" onclick="javscript:modify_address('."'$num'".')" />'.
881: &mt('Modify').'</label></span> '.
882: '<span class="LC_nobreak"><label>'.
883: '<input type="checkbox" name="del_notify_'.$num.
884: '" onclick="javscript:delete_address('."'$num'".')" />'.
885: &mt('Delete').'</label></span></td>'.
1.102 raeburn 886: '<td><input type="text" value="'.$item.'" name="address_'.
1.104 raeburn 887: $num.'" onFocus="javascript:address_changes('."'$num'".
888: ')" /></td><td>';
1.102 raeburn 889: my %chk;
890: if (defined($allnot{$item}{'crit'})) {
891: if (defined($allnot{$item}{'reg'})) {
892: $chk{'all'} = 'checked="checked" ';
893: } else {
894: $chk{'crit'} = 'checked="checked" ';
895: }
896: } else {
897: $chk{'reg'} = 'checked="checked" ';
898: }
899: foreach my $type ('all','crit','reg') {
900: $output .= '<span class="LC_nobreak"><label>'.
901: '<input type="radio" name="notify_type_'.$num.
1.104 raeburn 902: '" value="'.$type.'" '.$chk{$type}.
903: ' onchange="javascript:address_changes('."'$num'".')" />'.
904: $lt{$type}.'</label></span> ';
1.102 raeburn 905: }
906: my $htmlon = '';
907: my $htmloff = '';
908: if (grep/^\Q$item\E/,@allow_html) {
909: $htmlon = 'checked="checked" ';
910: } else {
911: $htmloff = 'checked="checked" ';
912: }
913: $output .= '</td><td><label><input type="radio" name="html_'.$num.
1.104 raeburn 914: '" value="1" '.$htmlon.
915: ' onchange="javascript:address_changes('."'$num'".')" />'.
916: &mt('Yes').'</label> '.
1.102 raeburn 917: '<label><input type="radio" name="html_'.$num.'" value="0" '.
1.104 raeburn 918: $htmloff. ' onchange="javascript:address_changes('."'$num'".
919: ')" />'.
920: &mt('No').'</label></td>'.
1.102 raeburn 921: &Apache::loncommon::end_data_table_row();
922: $num ++;
1.104 raeburn 923: $counter ++;
1.102 raeburn 924: }
925: my %defchk = (
926: all => 'checked="checked" ',
927: crit => '',
928: reg => '',
929: );
930: $output .= &Apache::loncommon::start_data_table_row().
1.104 raeburn 931: '<td><b>'.$counter.'</b></td>'.
932: '<td><span class="LC_nobreak"><label>'.
933: '<input type="checkbox" name="add_notify_'.$num.
934: '" value="1" />'.&mt('Add new address').'</label></span></td>'.
1.102 raeburn 935: '<td><input type="text" value="" name="address_'.$num.
1.104 raeburn 936: '" onFocus="javascript:new_address('."'$num'".')" /></td><td>';
1.102 raeburn 937: foreach my $type ('all','crit','reg') {
938: $output .= '<span class="LC_nobreak"><label>'.
939: '<input type="radio" name="notify_type_'.$num.
940: '" value="'.$type.'" '.$defchk{$type}.'/>'.
941: $lt{$type}.'</label></span> ';
942: }
943: $output .= '</td><td><label><input type="radio" name="html_'.$num.
944: '" value="1" />'.&mt('Yes').'</label> '.
945: '<label><input type="radio" name="html_'.$num.'" value="0" '.
946: ' checked="checked" />'.
947: &mt('No').'</label></td>'.
948: &Apache::loncommon::end_data_table_row().
949: &Apache::loncommon::end_data_table();
950: $num ++;
951: $r->print($output);
952: $r->print(qq|
1.113 raeburn 953: <br /><hr />
1.102 raeburn 954: <input type="hidden" name="numnotify" value="$num" />
955: <input type="button" value="$lt{'chg'}" onclick="javascript:validate()" />
956: <input type="button" value="$lt{'prme'}" onclick="location.href='/adm/preferences'" />
1.20 www 957: </form>
1.102 raeburn 958: |);
959:
960: }
961:
962: sub get_notifications {
963: my ($userenv) = @_;
964: my %allnot;
965: my @critnot = split(/,/,$userenv->{'critnotification'});
966: my @regnot = split(/,/,$userenv->{'notification'});
967: foreach my $item (@critnot) {
968: $allnot{$item}{crit} = 1;
969: }
970: foreach my $item (@regnot) {
971: $allnot{$item}{reg} = 1;
972: }
973: return %allnot;
1.20 www 974: }
975:
976: sub verify_and_change_msgforward {
977: my $r = shift;
1.59 albertel 978: my $user = $env{'user.name'};
979: my $domain = $env{'user.domain'};
1.20 www 980: my $newscreen = '';
981: my $message='';
1.59 albertel 982: foreach (split(/\,/,$env{'form.msgforward'})) {
1.20 www 983: my ($msuser,$msdomain)=split(/[\@\:]/,$_);
1.95 albertel 984: $msuser = &LONCAPA::clean_username($msuser);
985: $msdomain = &LONCAPA::clean_domain($msdomain);
1.20 www 986: if (($msuser) && ($msdomain)) {
987: if (&Apache::lonnet::homeserver($msuser,$msdomain) ne 'no_host') {
988: $newscreen.=$msuser.':'.$msdomain.',';
989: } else {
1.110 bisitz 990: $message.= &mt('No such user: ').'<tt>'.$msuser.':'.$msdomain.'</tt><br>';
1.20 www 991: }
992: }
993: }
994: $newscreen=~s/\,$//;
995: if ($newscreen) {
996: &Apache::lonnet::put('environment',{'msgforward' => $newscreen});
1.116 raeburn 997: &Apache::lonnet::appenv({'environment.msgforward' => $newscreen});
1.110 bisitz 998: $message .= &mt('Set message forwarding to ').'<tt>"'.$newscreen.'"</tt>.'
999: .'<br />';
1.20 www 1000: } else {
1001: &Apache::lonnet::del('environment',['msgforward']);
1002: &Apache::lonnet::delenv('environment\.msgforward');
1.102 raeburn 1003: $message.= &mt("Set message forwarding to 'off'.").'<br />';
1.20 www 1004: }
1.102 raeburn 1005: my $critnotification;
1006: my $notification;
1007: my $notify_with_html;
1008: my $lastnotify = $env{'form.numnotify'}-1;
1.104 raeburn 1009: my $totaladdresses = 0;
1.102 raeburn 1010: for (my $i=0; $i<$env{'form.numnotify'}; $i++) {
1011: if ((!defined($env{'form.del_notify_'.$i})) &&
1.104 raeburn 1012: ((($i==$lastnotify) && ($env{'form.add_notify_'.$lastnotify} == 1)) ||
1.102 raeburn 1013: ($i<$lastnotify))) {
1014: if (defined($env{'form.address_'.$i})) {
1015: if ($env{'form.notify_type_'.$i} eq 'all') {
1016: $critnotification .= $env{'form.address_'.$i}.',';
1017: $notification .= $env{'form.address_'.$i}.',';
1018: } elsif ($env{'form.notify_type_'.$i} eq 'crit') {
1019: $critnotification .= $env{'form.address_'.$i}.',';
1020: } elsif ($env{'form.notify_type_'.$i} eq 'reg') {
1021: $notification .= $env{'form.address_'.$i}.',';
1022: }
1023: if ($env{'form.html_'.$i} eq '1') {
1024: $notify_with_html .= $env{'form.address_'.$i}.',';
1025: }
1.104 raeburn 1026: $totaladdresses ++;
1.102 raeburn 1027: }
1028: }
1029: }
1030: $critnotification =~ s/,$//;
1031: $critnotification=~s/\s//gs;
1032: $notification =~ s/,$//;
1.20 www 1033: $notification=~s/\s//gs;
1.102 raeburn 1034: $notify_with_html =~ s/,$//;
1035: $notify_with_html =~ s/\s//gs;
1.20 www 1036: if ($notification) {
1037: &Apache::lonnet::put('environment',{'notification' => $notification});
1.116 raeburn 1038: &Apache::lonnet::appenv({'environment.notification' => $notification});
1.110 bisitz 1039: $message.=&mt('Set non-critical message notification address(es) to ').'<tt>"'.$notification.'"</tt>.<br />';
1.20 www 1040: } else {
1041: &Apache::lonnet::del('environment',['notification']);
1042: &Apache::lonnet::delenv('environment\.notification');
1.110 bisitz 1043: $message.=&mt("Set non-critical message notification to 'off'.").'<br />';
1.20 www 1044: }
1045: if ($critnotification) {
1046: &Apache::lonnet::put('environment',{'critnotification' => $critnotification});
1.116 raeburn 1047: &Apache::lonnet::appenv({'environment.critnotification' => $critnotification});
1.110 bisitz 1048: $message.=&mt('Set critical message notification address(es) to ').'<tt>"'.$critnotification.'"</tt>.<br />';
1.20 www 1049: } else {
1050: &Apache::lonnet::del('environment',['critnotification']);
1051: &Apache::lonnet::delenv('environment\.critnotification');
1.110 bisitz 1052: $message.=&mt("Set critical message notification to 'off'.").'<br />';
1.102 raeburn 1053: }
1054: if ($critnotification || $notification) {
1055: if ($notify_with_html) {
1056: &Apache::lonnet::put('environment',{'notifywithhtml' => $notify_with_html});
1.116 raeburn 1057: &Apache::lonnet::appenv({'environment.notifywithhtml' => $notify_with_html});
1.110 bisitz 1058: $message.=&mt('Set address(es) to receive excerpts with html retained ').'<tt>"'.$notify_with_html.'"</tt>.';
1.102 raeburn 1059: } else {
1060: &Apache::lonnet::del('environment',['notifywithhtml']);
1061: &Apache::lonnet::delenv('environment\.notifywithhtml');
1.104 raeburn 1062: if ($totaladdresses == 1) {
1063: $message.=&mt("Set notification address to receive excerpts with html stripped.");
1064: } else {
1065: $message.=&mt("Set all notification addresses to receive excerpts with html stripped.");
1066: }
1.102 raeburn 1067: }
1068: } else {
1069: &Apache::lonnet::del('environment',['notifywithhtml']);
1070: &Apache::lonnet::delenv('environment\.notifywithhtml');
1071: }
1072: if ($message) {
1073: $message .= '<br /><hr />';
1.20 www 1074: }
1.109 albertel 1075: &Apache::loncommon::flush_email_cache($user,$domain);
1.102 raeburn 1076: &msgforwardchanger($r,$message);
1.6 www 1077: }
1078:
1.12 www 1079: ################################################################
1.19 www 1080: # Colors #
1.12 www 1081: ################################################################
1082:
1.19 www 1083: sub colorschanger {
1.12 www 1084: my $r = shift;
1.126 droeschl 1085: Apache::lonhtmlcommon::add_breadcrumb(
1086: { href => '/adm/preferences?action=changecolors',
1087: text => 'Change Colors'});
1088: $r->print(Apache::loncommon::start_page('Change Colors'));
1089: $r->print(Apache::lonhtmlcommon::breadcrumbs('Change Colors'));
1.19 www 1090: # figure out colors
1.80 albertel 1091: my $function=&Apache::loncommon::get_users_function();
1.19 www 1092: my $domain=&Apache::loncommon::determinedomain();
1093: my %colortypes=('pgbg' => 'Page Background',
1094: 'tabbg' => 'Header Background',
1095: 'sidebg'=> 'Header Border',
1096: 'font' => 'Font',
1097: 'link' => 'Un-Visited Link',
1098: 'vlink' => 'Visited Link',
1099: 'alink' => 'Active Link');
1.82 albertel 1100: my $start_data_table = &Apache::loncommon::start_data_table();
1.19 www 1101: my $chtable='';
1.22 matthew 1102: foreach my $item (sort(keys(%colortypes))) {
1.19 www 1103: my $curcol=&Apache::loncommon::designparm($function.'.'.$item,$domain);
1.82 albertel 1104: $chtable.=&Apache::loncommon::start_data_table_row().
1.83 albertel 1105: '<td>'.$colortypes{$item}.'</td><td style="background: '.$curcol.
1.19 www 1106: '"> </td><td><input name="'.$item.
1.21 www 1107: '" size="10" value="'.$curcol.
1108: '" /></td><td><a href="javascript:pjump('."'color_custom','".$colortypes{$item}.
1.19 www 1109: "','".$curcol."','"
1.82 albertel 1110: .$item."','parmform.pres','psub'".');">Select</a></td>'.
1.83 albertel 1111: &Apache::loncommon::end_data_table_row()."\n";
1.19 www 1112: }
1.82 albertel 1113: my $end_data_table = &Apache::loncommon::end_data_table();
1.23 matthew 1114: my $pjump_def = &Apache::lonhtmlcommon::pjump_javascript_definition();
1.19 www 1115: $r->print(<<ENDCOL);
1.82 albertel 1116: <script type="text/javascript">
1.19 www 1117:
1118: function pclose() {
1119: parmwin=window.open("/adm/rat/empty.html","LONCAPAparms",
1120: "height=350,width=350,scrollbars=no,menubar=no");
1121: parmwin.close();
1122: }
1123:
1.23 matthew 1124: $pjump_def
1.19 www 1125:
1126: function psub() {
1127: pclose();
1128: if (document.parmform.pres_marker.value!='') {
1.21 www 1129: if (document.parmform.pres_type.value!='') {
1.77 albertel 1130: eval('document.prefs.'+
1.21 www 1131: document.parmform.pres_marker.value+
1.19 www 1132: '.value=document.parmform.pres_value.value;');
1.21 www 1133: }
1.19 www 1134: } else {
1135: document.parmform.pres_value.value='';
1136: document.parmform.pres_marker.value='';
1137: }
1138: }
1139:
1140:
1141: </script>
1.21 www 1142: <form name="parmform">
1143: <input type="hidden" name="pres_marker" />
1144: <input type="hidden" name="pres_type" />
1145: <input type="hidden" name="pres_value" />
1146: </form>
1.88 albertel 1147: <form name="prefs" action="/adm/preferences" method="post">
1.19 www 1148: <input type="hidden" name="action" value="verify_and_change_colors" />
1.82 albertel 1149: $start_data_table
1.19 www 1150: $chtable
1.82 albertel 1151: $end_data_table
1.19 www 1152: </table>
1.21 www 1153: <input type="submit" value="Change Custom Colors" />
1154: <input type="submit" name="resetall" value="Reset All Colors to Default" />
1.12 www 1155: </form>
1.19 www 1156: ENDCOL
1.12 www 1157: }
1158:
1.19 www 1159: sub verify_and_change_colors {
1.12 www 1160: my $r = shift;
1.19 www 1161: # figure out colors
1.80 albertel 1162: my $function=&Apache::loncommon::get_users_function();
1.19 www 1163: my $domain=&Apache::loncommon::determinedomain();
1164: my %colortypes=('pgbg' => 'Page Background',
1165: 'tabbg' => 'Header Background',
1166: 'sidebg'=> 'Header Border',
1167: 'font' => 'Font',
1168: 'link' => 'Un-Visited Link',
1169: 'vlink' => 'Visited Link',
1170: 'alink' => 'Active Link');
1171:
1.12 www 1172: my $message='';
1.21 www 1173: foreach my $item (keys %colortypes) {
1.59 albertel 1174: my $color=$env{'form.'.$item};
1.21 www 1175: my $entry='color.'.$function.'.'.$item;
1.59 albertel 1176: if (($color=~/^\#[0-9A-Fa-f]{6}$/) && (!$env{'form.resetall'})) {
1.21 www 1177: &Apache::lonnet::put('environment',{$entry => $color});
1.116 raeburn 1178: &Apache::lonnet::appenv({'environment.'.$entry => $color});
1.110 bisitz 1179: $message.=&mt('Set '.$colortypes{$item}.' to ').'<tt>"'.$color.'"</tt>.<br />';
1.21 www 1180: } else {
1181: &Apache::lonnet::del('environment',[$entry]);
1182: &Apache::lonnet::delenv('environment\.'.$entry);
1.110 bisitz 1183: $message.=&mt('Reset '.$colortypes{$item}.'.').'<br />';
1.21 www 1184: }
1185: }
1.84 albertel 1186: my $now = time;
1187: &Apache::lonnet::put('environment',{'color.timestamp' => $now});
1.116 raeburn 1188: &Apache::lonnet::appenv({'environment.color.timestamp' => $now});
1.84 albertel 1189:
1.126 droeschl 1190: print_main_menu($r, $message);
1191: # $r->print(<<ENDVCCOL);
1192: #$message
1193: #<form name="client" action="/adm/preferences" method="post">
1194: #<input type="hidden" name="action" value="changecolors" />
1195: #</form>
1196: #ENDVCCOL
1.12 www 1197: }
1198:
1.4 matthew 1199: ######################################################
1200: # password handler subroutines #
1201: ######################################################
1.3 matthew 1202: sub passwordchanger {
1.94 raeburn 1203: my ($r,$errormessage,$caller,$mailtoken) = @_;
1.4 matthew 1204: # This function is a bit of a mess....
1.3 matthew 1205: # Passwords are encrypted using londes.js (DES encryption)
1.4 matthew 1206: $errormessage = ($errormessage || '');
1.94 raeburn 1207: my ($user,$domain,$currentpass,$defdom);
1.126 droeschl 1208: Apache::lonhtmlcommon::add_breadcrumb(
1209: { href => '/adm/preferences?action=changepass',
1210: text => 'Change Password'});
1211: $r->print(Apache::loncommon::start_page('Change Password'));
1212: $r->print(Apache::lonhtmlcommon::breadcrumbs('Change Password'));
1.94 raeburn 1213: if ((!defined($caller)) || ($caller eq 'preferences')) {
1214: $user = $env{'user.name'};
1215: $domain = $env{'user.domain'};
1216: if (!defined($caller)) {
1217: $caller = 'preferences';
1218: }
1219: } elsif ($caller eq 'reset_by_email') {
1220: $defdom = $r->dir_config('lonDefDomain');
1221: my %data = &Apache::lonnet::tmpget($mailtoken);
1222: if (keys(%data) == 0) {
1.110 bisitz 1223: $r->print(&mt('Sorry, the URL you provided to complete the reset of your password was invalid. Either the token included in the URL has been deleted or the URL you provided was invalid. Please submit a <a href="/adm/resetpw">new request</a> for a password reset, and follow the link to the new URL included in the e-mail that will be sent to you, to allow you to enter a new password.'));
1.94 raeburn 1224: return;
1225: }
1226: if (defined($data{time})) {
1227: if (time - $data{'time'} < 7200) {
1228: $user = $data{'username'};
1229: $domain = $data{'domain'};
1230: $currentpass = $data{'temppasswd'};
1231: } else {
1232: $r->print(&mt('Sorry, the token generated when you requested a password reset has expired.').'<br />');
1233: return;
1234: }
1235: } else {
1236: $r->print(&mt('Sorry, the URL generated when you requested reset of your password contained incomplete information.').'<br />');
1237: return;
1238: }
1239: } else {
1240: $r->print(&mt('Page requested in unexpected context').'<br />');
1241: return;
1242: }
1.3 matthew 1243: my $currentauth=&Apache::lonnet::queryauthenticate($user,$domain);
1244: # Check for authentication types that allow changing of the password.
1245: return if ($currentauth !~ /^(unix|internal):/);
1246: #
1247: # Generate keys
1248: my ($lkey_cpass ,$ukey_cpass ) = &des_keys();
1249: my ($lkey_npass1,$ukey_npass1) = &des_keys();
1250: my ($lkey_npass2,$ukey_npass2) = &des_keys();
1.4 matthew 1251: # Store the keys in the log files
1.3 matthew 1252: my $lonhost = $r->dir_config('lonHostID');
1253: my $logtoken=Apache::lonnet::reply('tmpput:'
1254: .$ukey_cpass . $lkey_cpass .'&'
1255: .$ukey_npass1 . $lkey_npass1.'&'
1256: .$ukey_npass2 . $lkey_npass2,
1257: $lonhost);
1.4 matthew 1258: # Hexify the keys for output as javascript variables
1.94 raeburn 1259: my %hexkey;
1260: $hexkey{'ukey_cpass'} = hex($ukey_cpass);
1261: $hexkey{'lkey_cpass'} = hex($lkey_cpass);
1262: $hexkey{'ukey_npass1'} = hex($ukey_npass1);
1263: $hexkey{'lkey_npass1'} = hex($lkey_npass1);
1264: $hexkey{'ukey_npass2'} = hex($ukey_npass2);
1265: $hexkey{'lkey_npass2'} = hex($lkey_npass2);
1.3 matthew 1266: # Output javascript to deal with passwords
1.4 matthew 1267: # Output DES javascript
1.3 matthew 1268: {
1269: my $include = $r->dir_config('lonIncludes');
1270: my $jsh=Apache::File->new($include."/londes.js");
1271: $r->print(<$jsh>);
1272: }
1.94 raeburn 1273: $r->print(&jscript_send($caller));
1.3 matthew 1274: $r->print(<<ENDFORM);
1.94 raeburn 1275: $errormessage
1276:
1277: <p>
1278: <!-- We separate the forms into 'server' and 'client' in order to
1279: ensure that unencrypted passwords will not be sent out by a
1280: crappy browser -->
1281: ENDFORM
1282: $r->print(&server_form($logtoken,$caller,$mailtoken));
1283: $r->print(&client_form($caller,\%hexkey,$currentpass,$defdom));
1284:
1285: #
1286: return;
1287: }
1288:
1289: sub jscript_send {
1290: my ($caller) = @_;
1291: my $output = qq|
1.3 matthew 1292: <script language="JavaScript">
1293:
1294: function send() {
1295: uextkey=this.document.client.elements.ukey_cpass.value;
1296: lextkey=this.document.client.elements.lkey_cpass.value;
1297: initkeys();
1298:
1.52 raeburn 1299: this.document.pserver.elements.currentpass.value
1.3 matthew 1300: =crypted(this.document.client.elements.currentpass.value);
1301:
1302: uextkey=this.document.client.elements.ukey_npass1.value;
1303: lextkey=this.document.client.elements.lkey_npass1.value;
1304: initkeys();
1.52 raeburn 1305: this.document.pserver.elements.newpass_1.value
1.3 matthew 1306: =crypted(this.document.client.elements.newpass_1.value);
1307:
1308: uextkey=this.document.client.elements.ukey_npass2.value;
1309: lextkey=this.document.client.elements.lkey_npass2.value;
1310: initkeys();
1.52 raeburn 1311: this.document.pserver.elements.newpass_2.value
1.3 matthew 1312: =crypted(this.document.client.elements.newpass_2.value);
1.94 raeburn 1313: |;
1314: if ($caller eq 'reset_by_email') {
1315: $output .= qq|
1316: this.document.pserver.elements.uname.value =
1317: this.document.client.elements.uname.value;
1318: this.document.pserver.elements.udom.value =
1319: this.document.client.elements.udom.options[this.document.client.elements.udom.selectedIndex].value;
1320: |;
1321: }
1322: $ output .= qq|
1.52 raeburn 1323: this.document.pserver.submit();
1.3 matthew 1324: }
1325: </script>
1.94 raeburn 1326: |;
1327: }
1.3 matthew 1328:
1.94 raeburn 1329: sub client_form {
1330: my ($caller,$hexkey,$currentpass,$defdom) = @_;
1.99 www 1331: my %lt=&Apache::lonlocal::texthash(
1.115 raeburn 1332: 'email' => 'E-mail Address',
1.99 www 1333: 'username' => 'Username',
1334: 'domain' => 'Domain',
1335: 'currentpass' => 'Current Password',
1336: 'newpass' => 'New Password',
1337: 'confirmpass' => 'Confirm Password',
1338: 'changepass' => 'Change Password');
1339:
1.94 raeburn 1340: my $output = qq|
1.3 matthew 1341: <form name="client" >
1342: <table>
1.94 raeburn 1343: |;
1344: if ($caller eq 'reset_by_email') {
1345: $output .= qq|
1.99 www 1346: <tr><td class="LC_preferences_labeltext"><label for="email">$lt{'email'}</label>:</td>
1.97 raeburn 1347: <td><input type="text" name="email" size="30" /> </td></tr>
1.99 www 1348: <tr><td class="LC_preferences_labeltext"><label for="uname">$lt{'username'}</label>:</td>
1.94 raeburn 1349: <td>
1.97 raeburn 1350: <input type="text" name="uname" size="15" />
1.94 raeburn 1351: <input type="hidden" name="currentpass" value="$currentpass" />
1352: </td></tr>
1.115 raeburn 1353: <tr><td class="LC_preferences_labeltext"><label for="udom">$lt{'domain'}</label>:</td>
1.94 raeburn 1354: <td>
1355: |;
1356: $output .= &Apache::loncommon::select_dom_form($defdom,'udom').'
1357: </td>
1358: </tr>
1359: ';
1360: } else {
1361: $output .= qq|
1.99 www 1362: <tr><td class="LC_preferences_labeltext"><label for="currentpass">$lt{'currentpass'}</label></td>
1.4 matthew 1363: <td><input type="password" name="currentpass" size="10"/> </td></tr>
1.94 raeburn 1364: |;
1365: }
1366: $output .= <<"ENDFORM";
1.99 www 1367: <tr><td class="LC_preferences_labeltext"><label for="newpass_1">$lt{'newpass'}</label></td>
1.4 matthew 1368: <td><input type="password" name="newpass_1" size="10" /> </td></tr>
1.99 www 1369: <tr><td class="LC_preferences_labeltext"><label for="newpass_2">$lt{'confirmpass'}</label></td>
1.4 matthew 1370: <td><input type="password" name="newpass_2" size="10" /> </td></tr>
1.3 matthew 1371: <tr><td colspan="2" align="center">
1.99 www 1372: <input type="button" value="$lt{'changepass'}" onClick="send();">
1.3 matthew 1373: </table>
1.94 raeburn 1374: <input type="hidden" name="ukey_cpass" value="$hexkey->{'ukey_cpass'}" />
1375: <input type="hidden" name="lkey_cpass" value="$hexkey->{'lkey_cpass'}" />
1376: <input type="hidden" name="ukey_npass1" value="$hexkey->{'ukey_npass1'}" />
1377: <input type="hidden" name="lkey_npass1" value="$hexkey->{'lkey_npass1'}" />
1378: <input type="hidden" name="ukey_npass2" value="$hexkey->{'ukey_npass2'}" />
1379: <input type="hidden" name="lkey_npass2" value="$hexkey->{'lkey_npass2'}" />
1.3 matthew 1380: </form>
1381: </p>
1382: ENDFORM
1.94 raeburn 1383: return $output;
1384: }
1385:
1386: sub server_form {
1387: my ($logtoken,$caller,$mailtoken) = @_;
1388: my $action = '/adm/preferences';
1389: if ($caller eq 'reset_by_email') {
1390: $action = '/adm/resetpw';
1391: }
1392: my $output = qq|
1393: <form name="pserver" action="$action" method="post">
1394: <input type="hidden" name="logtoken" value="$logtoken" />
1395: <input type="hidden" name="currentpass" value="" />
1396: <input type="hidden" name="newpass_1" value="" />
1397: <input type="hidden" name="newpass_2" value="" />
1398: |;
1399: if ($caller eq 'reset_by_email') {
1400: $output .= qq|
1401: <input type="hidden" name="token" value="$mailtoken" />
1402: <input type="hidden" name="uname" value="" />
1403: <input type="hidden" name="udom" value="" />
1404:
1405: |;
1406: }
1407: $output .= qq|
1408: <input type="hidden" name="action" value="verify_and_change_pass" />
1409: </form>
1410: |;
1411: return $output;
1.3 matthew 1412: }
1413:
1414: sub verify_and_change_password {
1.94 raeburn 1415: my ($r,$caller,$mailtoken) = @_;
1416: my ($user,$domain,$homeserver);
1417: if ($caller eq 'reset_by_email') {
1418: $user = $env{'form.uname'};
1419: $domain = $env{'form.udom'};
1420: if ($user ne '' && $domain ne '') {
1421: $homeserver = &Apache::lonnet::homeserver($user,$domain);
1422: if ($homeserver eq 'no_host') {
1.99 www 1423: &passwordchanger($r,"<p>\n<span class='LC_error'>".
1424: &mt("Invalid username and/or domain")."</span>\n</p>",
1.94 raeburn 1425: $caller,$mailtoken);
1426: return 1;
1427: }
1428: } else {
1.99 www 1429: &passwordchanger($r,"<p>\n<span class='LC_error'>".
1430: &mt("Username and domain were blank")."</span>\n</p>",
1.94 raeburn 1431: $caller,$mailtoken);
1432: return 1;
1433: }
1434: } else {
1435: $user = $env{'user.name'};
1436: $domain = $env{'user.domain'};
1437: $homeserver = $env{'user.home'};
1438: }
1.3 matthew 1439: my $currentauth=&Apache::lonnet::queryauthenticate($user,$domain);
1.4 matthew 1440: # Check for authentication types that allow changing of the password.
1.94 raeburn 1441: if ($currentauth !~ /^(unix|internal):/) {
1442: if ($caller eq 'reset_by_email') {
1.99 www 1443: &passwordchanger($r,"<p>\n<span class='LC_error'>".
1444: &mt("Authentication type for this user can not be changed by this mechanism").
1445: "</span>\n</p>",
1.94 raeburn 1446: $caller,$mailtoken);
1447: return 1;
1448: } else {
1449: return;
1450: }
1451: }
1.3 matthew 1452: #
1.59 albertel 1453: my $currentpass = $env{'form.currentpass'};
1454: my $newpass1 = $env{'form.newpass_1'};
1455: my $newpass2 = $env{'form.newpass_2'};
1456: my $logtoken = $env{'form.logtoken'};
1.3 matthew 1457: # Check for empty data
1.4 matthew 1458: unless (defined($currentpass) &&
1459: defined($newpass1) &&
1460: defined($newpass2) ){
1.99 www 1461: &passwordchanger($r,"<p>\n<span class='LC_error'>".
1462: &mt("One or more password fields were blank").
1463: "</span>\n</p>",$caller,$mailtoken);
1.3 matthew 1464: return;
1465: }
1.16 albertel 1466: # Get the keys
1467: my $lonhost = $r->dir_config('lonHostID');
1.3 matthew 1468: my $tmpinfo = Apache::lonnet::reply('tmpget:'.$logtoken,$lonhost);
1469: if (($tmpinfo=~/^error/) || ($tmpinfo eq 'con_lost')) {
1.4 matthew 1470: # I do not a have a better idea about how to handle this
1.94 raeburn 1471: my $tryagain_text = &mt('Please log out and try again.');
1472: if ($caller eq 'reset_by_email') {
1473: $tryagain_text = &mt('Please try again later.');
1474: }
1.101 albertel 1475: my $unable=&mt("Unable to retrieve saved token for password decryption");
1.3 matthew 1476: $r->print(<<ENDERROR);
1477: <p>
1.99 www 1478: <span class="LC_error">$unable. $tryagain_text</span>
1.3 matthew 1479: </p>
1480: ENDERROR
1.4 matthew 1481: # Probably should log an error here
1.75 albertel 1482: return 1;
1.3 matthew 1483: }
1484: my ($ckey,$n1key,$n2key)=split(/&/,$tmpinfo);
1.4 matthew 1485: #
1.17 matthew 1486: $currentpass = &des_decrypt($ckey ,$currentpass);
1487: $newpass1 = &des_decrypt($n1key,$newpass1);
1488: $newpass2 = &des_decrypt($n2key,$newpass2);
1.94 raeburn 1489: #
1490: if ($caller eq 'reset_by_email') {
1491: my %data = &Apache::lonnet::tmpget($mailtoken);
1.117 raeburn 1492: if (keys(%data) == 0) {
1493: &passwordchanger($r,
1494: '<span class="LC_error">'.
1495: &mt('Could not verify current authentication.').' '.
1496: &mt('Please try again.').'</span>',$caller,$mailtoken);
1497: return 1;
1498: }
1.94 raeburn 1499: if ($currentpass ne $data{'temppasswd'}) {
1500: &passwordchanger($r,
1.99 www 1501: '<span class="LC_error">'.
1.110 bisitz 1502: &mt('Could not verify current authentication.').' '.
1503: &mt('Please try again.').'</span>',$caller,$mailtoken);
1.94 raeburn 1504: return 1;
1505: }
1506: }
1.3 matthew 1507: if ($newpass1 ne $newpass2) {
1.4 matthew 1508: &passwordchanger($r,
1.99 www 1509: '<span class="LC_error">'.
1.110 bisitz 1510: &mt('The new passwords you entered do not match.').' '.
1511: &mt('Please try again.').'</span>',$caller,$mailtoken);
1.75 albertel 1512: return 1;
1.4 matthew 1513: }
1514: if (length($newpass1) < 7) {
1515: &passwordchanger($r,
1.99 www 1516: '<span class="LC_error">'.
1.110 bisitz 1517: &mt('Passwords must be a minimum of 7 characters long.').' '.
1518: &mt('Please try again.').'</span>',$caller,$mailtoken);
1.75 albertel 1519: return 1;
1.3 matthew 1520: }
1.4 matthew 1521: #
1522: # Check for bad characters
1523: my $badpassword = 0;
1524: foreach (split(//,$newpass1)) {
1525: $badpassword = 1 if ((ord($_)<32)||(ord($_)>126));
1526: }
1527: if ($badpassword) {
1528: # I can't figure out how to enter bad characters on my browser.
1.99 www 1529: my $errormessage ='<span class="LC_error">'.
1.110 bisitz 1530: &mt('The password you entered contained illegal characters.').'<br />'.
1.99 www 1531: &mt('Valid characters are').(<<"ENDERROR");
1532: : space and <br />
1.4 matthew 1533: <pre>
1534: !"\#$%&\'()*+,-./0123456789:;<=>?\@
1535: ABCDEFGHIJKLMNOPQRSTUVWXYZ[\]^_\`abcdefghijklmnopqrstuvwxyz{|}~
1.99 www 1536: </pre></span>
1.4 matthew 1537: ENDERROR
1.94 raeburn 1538: &passwordchanger($r,$errormessage,$caller,$mailtoken);
1539: return 1;
1.4 matthew 1540: }
1541: #
1542: # Change the password (finally)
1543: my $result = &Apache::lonnet::changepass
1.94 raeburn 1544: ($user,$domain,$currentpass,$newpass1,$homeserver,$caller);
1.4 matthew 1545: # Inform the user the password has (not?) been changed
1.126 droeschl 1546: my $message;
1.4 matthew 1547: if ($result =~ /^ok$/) {
1.126 droeschl 1548: $message = &mt('The password for [_1] was successfully changed',$user);
1549: print_main_menu($r, $message);
1550: # $r->print("<h3>".&mt('The password for [_1] was successfully changed',$user)."</h3>");
1.4 matthew 1551: } else {
1552: # error error: run in circles, scream and shout
1.126 droeschl 1553: $message = &mt("The password for [_1] was not changed",$user)
1554: .&mt('Please make sure your old password was entered correctly.');
1555: print_main_menu($r, $message);
1556: # $r->print("<h3><span class='LC_error'>".&mt("The password for [_1] was not changed",$user)."</span></h3>".
1557: # &mt('Please make sure your old password was entered correctly.'));
1.75 albertel 1558: return 1;
1.4 matthew 1559: }
1560: return;
1.3 matthew 1561: }
1562:
1.42 raeburn 1563: ################################################################
1564: # discussion display subroutines
1565: ################################################################
1566: sub discussionchanger {
1567: my $r = shift;
1.126 droeschl 1568: Apache::lonhtmlcommon::add_breadcrumb(
1569: { href => '/adm/preferences?action=changediscussions',
1570: text => 'Change Discussion Preferences'});
1571: $r->print(Apache::loncommon::start_page('Change Discussion Preferences'));
1572: $r->print(Apache::lonhtmlcommon::breadcrumbs('Change Discussion Preferences'));
1.59 albertel 1573: my $user = $env{'user.name'};
1574: my $domain = $env{'user.domain'};
1.42 raeburn 1575: my %userenv = &Apache::lonnet::get
1.43 raeburn 1576: ('environment',['discdisplay','discmarkread']);
1577: my $discdisp = 'allposts';
1578: my $discmark = 'onmark';
1579:
1580: if (defined($userenv{'discdisplay'})) {
1581: unless ($userenv{'discdisplay'} eq '') {
1582: $discdisp = $userenv{'discdisplay'};
1583: }
1584: }
1585: if (defined($userenv{'discmarkread'})) {
1586: unless ($userenv{'discdisplay'} eq '') {
1587: $discmark = $userenv{'discmarkread'};
1588: }
1589: }
1590:
1591: my $newdisp = 'unread';
1592: my $newmark = 'ondisp';
1593:
1594: my $function = &Apache::loncommon::get_users_function();
1595: my $color = &Apache::loncommon::designparm($function.'.tabbg',
1.59 albertel 1596: $env{'user.domain'});
1.43 raeburn 1597: my %lt = &Apache::lonlocal::texthash(
1598: 'pref' => 'Display Preference',
1599: 'curr' => 'Current setting ',
1600: 'actn' => 'Action',
1601: 'sdpf' => 'Set display preferences for discussion posts for both bulletin boards and individual resources in all your courses.',
1602: 'prca' => 'Preferences can be set that determine',
1603: 'whpo' => 'Which posts are displayed when you display a bulletin board or resource, and',
1604: 'unwh' => 'Under what circumstances posts are identfied as "New"',
1605: 'allposts' => 'All posts',
1606: 'unread' => 'New posts only',
1607: 'ondisp' => 'Once displayed',
1608: 'onmark' => 'Once marked as read',
1609: 'disa' => 'Posts displayed?',
1610: 'npmr' => 'New posts cease to be identified as "New"?',
1611: 'thde' => 'The preferences you set here can be overridden within each individual discussion.',
1612: 'chgt' => 'Change to '
1613: );
1614: my $dispchange = $lt{'unread'};
1615: my $markchange = $lt{'ondisp'};
1616: my $currdisp = $lt{'allposts'};
1617: my $currmark = $lt{'onmark'};
1618:
1619: if ($discdisp eq 'unread') {
1620: $dispchange = $lt{'allposts'};
1621: $currdisp = $lt{'unread'};
1622: $newdisp = 'allposts';
1623: }
1624:
1625: if ($discmark eq 'ondisp') {
1626: $markchange = $lt{'onmark'};
1627: $currmark = $lt{'ondisp'};
1628: $newmark = 'onmark';
1.42 raeburn 1629: }
1.43 raeburn 1630:
1631: $r->print(<<"END");
1.88 albertel 1632: <form name="prefs" action="/adm/preferences" method="post">
1.42 raeburn 1633: <input type="hidden" name="action" value="verify_and_change_discussion" />
1634: <br />
1.87 albertel 1635: $lt{'sdpf'}<br /> $lt{'prca'} <ol><li>$lt{'whpo'}</li><li>$lt{'unwh'}</li></ol>
1.43 raeburn 1636: <br />
1637: <br />
1.82 albertel 1638: END
1639: $r->print(&Apache::loncommon::start_data_table());
1640: $r->print(<<"END");
1641: <tr>
1642: <th>$lt{'pref'}</th>
1643: <th>$lt{'curr'}</th>
1644: <th>$lt{'actn'}?</th>
1.43 raeburn 1645: </tr>
1.82 albertel 1646: END
1647: $r->print(&Apache::loncommon::start_data_table_row());
1648: $r->print(<<"END");
1.43 raeburn 1649: <td>$lt{'disa'}</td>
1650: <td>$lt{$discdisp}</td>
1.82 albertel 1651: <td><label><input type="checkbox" name="discdisp" /><input type="hidden" name="newdisp" value="$newdisp" /> $lt{'chgt'} "$dispchange"</label></td>
1652: END
1653: $r->print(&Apache::loncommon::end_data_table_row().
1654: &Apache::loncommon::start_data_table_row());
1655: $r->print(<<"END");
1.43 raeburn 1656: <td>$lt{'npmr'}</td>
1657: <td>$lt{$discmark}</td>
1.82 albertel 1658: <td><label><input type="checkbox" name="discmark" /><input type="hidden" name="newmark" value="$newmark" /> $lt{'chgt'} "$markchange"</label></td>
1.43 raeburn 1659: </tr>
1.82 albertel 1660: END
1661: $r->print(&Apache::loncommon::end_data_table_row().
1662: &Apache::loncommon::end_data_table());
1663: $r->print(<<"END");
1.43 raeburn 1664: <br />
1665: <br />
1.101 albertel 1666: <input type="submit" name="sub" value="Save Changes" />
1.43 raeburn 1667: <br />
1668: <br />
1669: Note: $lt{'thde'}
1670: </form>
1671: END
1.42 raeburn 1672: }
1673:
1674: sub verify_and_change_discussion {
1675: my $r = shift;
1.59 albertel 1676: my $user = $env{'user.name'};
1677: my $domain = $env{'user.domain'};
1.42 raeburn 1678: my $message='';
1.59 albertel 1679: if (defined($env{'form.discdisp'}) ) {
1680: my $newdisp = $env{'form.newdisp'};
1.43 raeburn 1681: if ($newdisp eq 'unread') {
1.110 bisitz 1682: $message .=&mt('In discussions: only new posts will be displayed.').'<br />';
1.43 raeburn 1683: &Apache::lonnet::put('environment',{'discdisplay' => $newdisp});
1.116 raeburn 1684: &Apache::lonnet::appenv({'environment.discdisplay' => $newdisp});
1.43 raeburn 1685: } else {
1.110 bisitz 1686: $message .= &mt('In discussions: all posts will be displayed.').'<br />';
1.43 raeburn 1687: &Apache::lonnet::del('environment',['discdisplay']);
1688: &Apache::lonnet::delenv('environment\.discdisplay');
1689: }
1690: }
1.59 albertel 1691: if (defined($env{'form.discmark'}) ) {
1692: my $newmark = $env{'form.newmark'};
1.43 raeburn 1693: if ($newmark eq 'ondisp') {
1.110 bisitz 1694: $message.=&mt('In discussions: new posts will be cease to be identified as "NEW" after display.').'<br />';
1.43 raeburn 1695: &Apache::lonnet::put('environment',{'discmarkread' => $newmark});
1.116 raeburn 1696: &Apache::lonnet::appenv({'environment.discmarkread' => $newmark});
1.43 raeburn 1697: } else {
1.110 bisitz 1698: $message.=&mt('In discussions: posts will be identified as "NEW" until marked as read by the reader.').'<br />';
1.43 raeburn 1699: &Apache::lonnet::del('environment',['discmarkread']);
1700: &Apache::lonnet::delenv('environment\.discmarkread');
1701: }
1.42 raeburn 1702: }
1.126 droeschl 1703: # $r->print(<<ENDVCSCREEN);
1704: #$message
1705: #ENDVCSCREEN
1706: print_main_menu($r, $message);
1.42 raeburn 1707: }
1708:
1.63 raeburn 1709: ################################################################
1710: # Subroutines for page display on course access (Course Coordinators)
1711: ################################################################
1712: sub coursedisplaychanger {
1713: my $r = shift;
1.126 droeschl 1714: Apache::lonhtmlcommon::add_breadcrumb(
1715: { href => '/adm/preferences?action=changecourseinit',
1716: text => 'Change Course Init. Pref.'});
1717: $r->print(Apache::loncommon::start_page('Change Course Initialization Preference'));
1718: $r->print(Apache::lonhtmlcommon::breadcrumbs('Change Course Init. Pref.'));
1.63 raeburn 1719: my $user = $env{'user.name'};
1720: my $domain = $env{'user.domain'};
1.66 albertel 1721: my %userenv = &Apache::lonnet::get('environment',['course_init_display']);
1.71 raeburn 1722: my $currvalue = 'whatsnew';
1.73 albertel 1723: my $firstselect = '';
1724: my $whatsnewselect = 'checked="checked"';
1.71 raeburn 1725: if (exists($userenv{'course_init_display'})) {
1726: if ($userenv{'course_init_display'} eq 'firstres') {
1727: $currvalue = 'firstres';
1.73 albertel 1728: $firstselect = 'checked="checked"';
1729: $whatsnewselect = '';
1.71 raeburn 1730: }
1.63 raeburn 1731: }
1.71 raeburn 1732: my %pagenames = (
1733: firstres => 'First resource',
1734: whatsnew => "What's new page",
1735: );
1.70 raeburn 1736: my $whatsnew_off=&mt('Display the [_1] in the course.','<b>first resource</b>');
1737: 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 1738:
1.71 raeburn 1739: $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 1740: $r->print(<<ENDLSCREEN);
1.88 albertel 1741: <form name="prefs" action="/adm/preferences" method="post">
1.63 raeburn 1742: <input type="hidden" name="action" value="verify_and_change_coursepage" />
1.72 albertel 1743: <br />
1.65 albertel 1744: <label><input type="radio" name="newdisp" value="firstres" $firstselect /> $whatsnew_off</label><br />
1.70 raeburn 1745: <label><input type="radio" name="newdisp" value="whatsnew" $whatsnewselect /> $whatsnew_on</label><input type="hidden" name="refpage" value="$env{'form.refpage'}" />
1.63 raeburn 1746: ENDLSCREEN
1.70 raeburn 1747: $r->print('<br /><br /><input type="submit" value="'.&mt('Change').'" />
1.63 raeburn 1748: </form>');
1749: }
1750:
1751: sub verify_and_change_coursepage {
1752: my $r = shift;
1753: my $message='';
1754: my %lt = &Apache::lonlocal::texthash(
1.70 raeburn 1755: 'defs' => 'Default now set',
1.71 raeburn 1756: 'when' => 'when you select a course role from the roles screen',
1.63 raeburn 1757: 'ywbt' => 'you will be taken to the start of the course.',
1758: 'apwb' => 'a page will be displayed that lists items in the course that may require action from you.',
1759: 'gtts' => 'Go to the start of the course',
1.70 raeburn 1760: 'dasp' => "Display the What's New page listing course action items",
1.63 raeburn 1761: );
1762: my $newdisp = $env{'form.newdisp'};
1.70 raeburn 1763: $message = '<b>'.$lt{'defs'}.'</b>: '.$lt{'when'}.', ';
1.63 raeburn 1764: if ($newdisp eq 'firstres') {
1.87 albertel 1765: $message .= $lt{'ywbt'}.'<br />';
1.63 raeburn 1766: &Apache::lonnet::put('environment',{'course_init_display' => $newdisp});
1.116 raeburn 1767: &Apache::lonnet::appenv({'environment.course_init_display' => $newdisp});
1.63 raeburn 1768: } else {
1.87 albertel 1769: $message .= $lt{'apwb'}.'<br />';
1.63 raeburn 1770: &Apache::lonnet::del('environment',['course_init_display']);
1771: &Apache::lonnet::delenv('environment\.course_init_display');
1772: }
1.70 raeburn 1773: my $refpage = $env{'form.refpage'};
1.63 raeburn 1774: if (($env{'request.course.fn'}) && ($env{'request.course.id'})) {
1775: if ($newdisp eq 'firstres') {
1776: my $cdom = $env{'course.'.$env{'request.course.id'}.'.domain'};
1777: my $cnum = $env{'course.'.$env{'request.course.id'}.'.num'};
1778: my ($furl,$ferr)=
1779: &Apache::lonuserstate::readmap($cdom.'/'.$cnum);
1780: $message .= '<br /><font size="+1"><a href="'.$furl.'">'.$lt{'gtts'}.' <i>'.&mt('now').'</i></a></font>';
1781: } else {
1.70 raeburn 1782: $message .= '<br /><font size="+1"><a href="/adm/whatsnew?refpage='.
1783: $refpage.'">'.$lt{'dasp'}.'</a></font>';
1.63 raeburn 1784: }
1785: }
1.126 droeschl 1786: # $r->print(<<ENDVCSCREEN);
1787: #$message
1788: #<br /><br />
1789: #ENDVCSCREEN
1790: print_main_menu($r, $message);
1.63 raeburn 1791: }
1792:
1.126 droeschl 1793: sub print_main_menu {
1794: my ($r, $message) = @_;
1795: # Determine current authentication method
1796: my $user = $env{'user.name'};
1797: my $domain = $env{'user.domain'};
1798: my $currentauth=&Apache::lonnet::queryauthenticate($user,$domain);
1799:
1800: # build the data structure for menu generation
1801: my $aboutmeurl='/adm/'.$env{'user.domain'}.'/'.$env{'user.name'}.'/aboutme';
1802: my $role = ($env{'user.adv'} ? 'Roles' : 'Course');
1.131 raeburn 1803: my %permissions;
1804: if (&Apache::lonnet::usertools_access($user,$domain,'aboutme')) {
1805: $permissions{'aboutme'} = 'F';
1806: }
1.126 droeschl 1807: my @menu=
1808: ({ categorytitle=>'Personal Data',
1809: items =>[
1810: { linktext => 'About Me',
1811: url => $aboutmeurl,
1.131 raeburn 1812: permission => $permissions{'aboutme'},
1.126 droeschl 1813: #help => 'Prefs_About_Me',
1814: icon => 'system-users.png',
1815: linktitle => 'Edit information about yourself that should be displayed on your public profile.'
1816: },
1817: { linktext => 'Screen Name',
1818: url => '/adm/preferences?action=changescreenname',
1819: permission => 'F',
1820: #help => 'Prefs_Screen_Name_Nickname',
1821: icon => 'preferences-desktop-font.png',
1822: linktitle => 'Change the name that is displayed in your posts.'
1823: },
1824: ]
1825: },
1826: { categorytitle=>'Page Display Settings',
1827: items =>[
1828: { linktext => 'Color Scheme',
1829: url => '/adm/preferences?action=changecolors',
1830: permission => 'F',
1831: #help => 'Change_Colors',
1832: icon => 'preferences-desktop-theme.png',
1833: linktitle => 'Change LON-CAPA default colors.'
1834: },
1835: { linktext => 'Menu Display',
1836: url => '/adm/preferences?action=changeicons',
1837: permission => 'F',
1838: #help => '',
1839: icon => 'preferences-system-windows.png',
1840: linktitle => 'Change whether the menus are displayed with buttons, icons or icons and text.'
1841: }
1842:
1843: ]
1844: },
1845: { categorytitle=>'Content Display Settings',
1846: items =>[
1847: { linktext => 'Language',
1848: url => '/adm/preferences?action=changelanguages',
1849: permission => 'F',
1850: #help => 'Prefs_Language',
1851: icon => 'preferences-desktop-locale.png',
1.127 droeschl 1852: linktitle => 'Choose the default language for this user.'
1.126 droeschl 1853: },
1.128 droeschl 1854: { linktext => 'WYSIWYG Editor',
1.126 droeschl 1855: url => '/adm/preferences?action=changewysiwyg',
1856: permission => 'F',
1857: #help => '',
1858: icon => 'edit-select-all.png',
1859: linktitle => 'Enable or disable the WYSIWYG-Editor.'
1860: },
1.128 droeschl 1861: { linktext => $role.' Page',
1.126 droeschl 1862: url => '/adm/preferences?action=changerolespref',
1863: permission => 'F',
1864: #help => '',
1865: icon => 'sctr.png',
1866: linktitle => 'Configure the roles hotlist.'
1867: },
1.127 droeschl 1868: { linktext => 'Display of Scientific Equations',
1.126 droeschl 1869: url => '/adm/preferences?action=changetexenginepref',
1870: permission => 'F',
1871: #help => '',
1872: icon => 'stat.png',
1.127 droeschl 1873: linktitle => 'Change how Scientific Equations are displayed.'
1.126 droeschl 1874: },
1875: ]
1876: },
1.128 droeschl 1877: { categorytitle=>'Message Management',
1878: items =>[
1879: { linktext => 'Messages & Notifications',
1880: url => '/adm/preferences?action=changemsgforward',
1881: permission => 'F',
1882: #help => 'Prefs_Messages',
1883: icon => 'mail-reply-all.png',
1884: linktitle => 'Change messageforwarding or notifications settings.'
1885: },
1886: { linktext => 'Discussion Display',
1887: url => '/adm/preferences?action=changediscussions',
1888: permission => 'F',
1889: #help => 'Change_Discussion_Display',
1890: icon => 'mail-message-new.png',
1891: linktitle => 'Set display preferences for discussion posts for both bulletin boards and individual resources in all your courses.'
1892: },
1893: ]
1894: },
1.126 droeschl 1895: { categorytitle=>'Other',
1896: items =>[
1897: { linktext => 'Register Response Devices ("Clickers")',
1898: url => '/adm/preferences?action=changeclicker',
1899: permission => 'F',
1900: #help => '',
1901: icon => 'network-workgroup.png',
1902: linktitle => 'Register your clicker.'
1903: },
1904: ]
1905: },
1906: );
1907:
1908: if ($currentauth =~ /^(unix|internal):/) {
1909: push(@{ $menu[0]->{items} }, {
1910: linktext => 'Password',
1911: url => '/adm/preferences?action=changepass',
1912: permission => 'F',
1913: #help => 'Change_Password',
1914: icon => 'emblem-readonly.png',
1915: linktitle => 'Change your password.',
1916: });
1917: }
1918: if ($env{'environment.remote'} eq 'off') {
1919: push(@{ $menu[1]->{items} }, {
1920: linktext => 'Launch Remote Control',
1921: url => '/adm/remote?url=/adm/preferences?action=launch',
1922: permission => 'F',
1923: #help => '',
1924: icon => 'network-wireless.png',
1925: linktitle => 'Launch the remote control for LON-CAPA.',
1926: });
1927: }else{
1928: push(@{ $menu[1]->{items} }, {
1929: linktext => 'Collapse Remote Control',
1930: url => '/adm/remote?url=/adm/preferences?action=collapse',
1931: permission => 'F',
1932: #help => '',
1933: icon => 'network-wireless.png',
1934: linktitle => 'Collapse the remote control for LON-CAPA.',
1935: });
1936: }
1937: my %author_roles = &Apache::lonnet::get_my_roles($user,$domain,'userroles','',['au']);
1938: if (keys(%author_roles) > 0) {
1939: push(@{ $menu[4]->{items} }, {
1940: linktext => 'Restrict Domain Coordinator Access',
1941: url => '/adm/preferences?action=changedomcoord',
1942: permission => 'F',
1943: #help => '',
1944: icon => 'system-lock-screen.png',
1945: linktitle => 'Restrict domain coordinator access.',
1946: });
1947: }
1948:
1949: if (&Apache::lonnet::allowed('whn',$env{'request.course.id'})
1950: || &Apache::lonnet::allowed('whn',$env{'request.course.id'}.'/'
1951: .$env{'request.course.sec'})) {
1952: push(@{ $menu[4]->{items} }, {
1.128 droeschl 1953: linktext => 'Course Initialization',
1.126 droeschl 1954: url => '/adm/preferences?action=changecourseinit',
1955: permission => 'F',
1956: #help => '',
1957: icon => 'edit-copy.png',
1958: linktitle => 'Set the default page to be displayed when you select a course role.',
1959: });
1960:
1961: }
1962: if ($env{'user.name'} =~ /^(albertel|fox|foxr|kortemey|korte|raeburn)$/) {
1963: push(@{ $menu[4]->{items} }, {
1964: linktext => 'Toggle Debug Messages (Current:'.$env{'user.debug'}.')',
1965: url => '/adm/preferences?action=debugtoggle',
1966: permission => 'F',
1967: #help => '',
1968: icon => 'blog.png',
1969: linktitle => 'Toggle Debug Messages.',
1970: });
1971: }
1972:
1973: $r->print(&Apache::loncommon::start_page('Change Preferences'));
1974: $r->print(Apache::lonhtmlcommon::breadcrumbs('Change Preferences'));
1975: $r->print($message);
1976: $r->print(Apache::lonhtmlcommon::generate_menu(@menu));
1977: $r->print(Apache::loncommon::end_page());
1978: }
1.63 raeburn 1979:
1.4 matthew 1980: ######################################################
1981: # other handler subroutines #
1982: ######################################################
1983:
1.3 matthew 1984: ################################################################
1985: # Main handler #
1986: ################################################################
1.126 droeschl 1987: sub handler {
1988: my $r = shift;
1989: Apache::loncommon::content_type($r,'text/html');
1990: # Some pages contain DES keys and should not be cached.
1991: Apache::loncommon::no_cache($r);
1992: $r->send_http_header;
1993: return OK if $r->header_only;
1994: #
1995: Apache::loncommon::get_unprocessed_cgi($ENV{'QUERY_STRING'},
1996: ['action','wysiwyg','returnurl','refpage']);
1997: #
1998: Apache::lonhtmlcommon::clear_breadcrumbs();
1999: Apache::lonhtmlcommon::add_breadcrumb
2000: ({href => '/adm/preferences',
2001: text => 'Set User Preferences'});
2002: if(!exists $env{'form.action'}) {
2003: &print_main_menu($r);
2004: }elsif($env{'form.action'} eq 'changepass'){
2005: &passwordchanger($r);
2006: }elsif($env{'form.action'} eq 'verify_and_change_pass'){
2007: &verify_and_change_password($r);
2008: }elsif($env{'form.action'} eq 'changescreenname'){
2009: &screennamechanger($r);
2010: }elsif($env{'form.action'} eq 'verify_and_change_screenname'){
2011: &verify_and_change_screenname($r);
2012: }elsif($env{'form.action'} eq 'changemsgforward'){
2013: &msgforwardchanger($r);
2014: }elsif($env{'form.action'} eq 'verify_and_change_msgforward'){
2015: &verify_and_change_msgforward($r);
2016: }elsif($env{'form.action'} eq 'changecolors'){
2017: &colorschanger($r);
2018: }elsif($env{'form.action'} eq 'verify_and_change_colors'){
2019: &verify_and_change_colors($r);
2020: }elsif($env{'form.action'} eq 'changelanguages'){
2021: &languagechanger($r);
2022: }elsif($env{'form.action'} eq 'verify_and_change_languages'){
2023: &verify_and_change_languages($r);
2024: }elsif($env{'form.action'} eq 'changewysiwyg'){
2025: &wysiwygchanger($r);
2026: }elsif($env{'form.action'} eq 'set_wysiwyg'){
2027: &verify_and_change_wysiwyg($r);
2028: }elsif($env{'form.action'} eq 'changediscussions'){
2029: &discussionchanger($r);
2030: }elsif($env{'form.action'} eq 'verify_and_change_discussion'){
2031: &verify_and_change_discussion($r);
2032: }elsif($env{'form.action'} eq 'changerolespref'){
2033: &rolesprefchanger($r);
2034: }elsif($env{'form.action'} eq 'verify_and_change_rolespref'){
2035: &verify_and_change_rolespref($r);
2036: }elsif($env{'form.action'} eq 'changetexenginepref'){
2037: &texenginechanger($r);
2038: }elsif($env{'form.action'} eq 'verify_and_change_texengine'){
2039: &verify_and_change_texengine($r);
2040: }elsif($env{'form.action'} eq 'changeicons'){
2041: &iconchanger($r);
2042: }elsif($env{'form.action'} eq 'verify_and_change_icons'){
2043: &verify_and_change_icons($r);
2044: }elsif($env{'form.action'} eq 'changeclicker'){
2045: &clickerchanger($r);
2046: }elsif($env{'form.action'} eq 'verify_and_change_clicker'){
2047: &verify_and_change_clicker($r);
2048: }elsif($env{'form.action'} eq 'changedomcoord'){
2049: &domcoordchanger($r);
2050: }elsif($env{'form.action'} eq 'verify_and_change_domcoord'){
2051: &verify_and_change_domcoord($r);
2052: }elsif($env{'form.action'} eq 'lockwarning'){
2053: &lockwarning($r);
2054: }elsif($env{'form.action'} eq 'verify_and_change_locks'){
2055: &verify_and_change_lockwarning($r);
2056: }elsif($env{'form.action'} eq 'changecourseinit'){
2057: &coursedisplaychanger($r);
2058: }elsif($env{'form.action'} eq 'verify_and_change_coursepage'){
2059: &verify_and_change_coursepage($r);
2060: }elsif($env{'form.action'} eq 'debugtoggle'){
2061: toggle_debug();
2062: print_main_menu($r);
2063: }
2064:
2065: return OK;
2066:
2067:
2068: }
2069: #remove when done
2070: #old handler routine
2071: sub handler2 {
1.1 www 2072: my $r = shift;
1.59 albertel 2073: my $user = $env{'user.name'};
2074: my $domain = $env{'user.domain'};
1.31 www 2075: &Apache::loncommon::content_type($r,'text/html');
1.4 matthew 2076: # Some pages contain DES keys and should not be cached.
2077: &Apache::loncommon::no_cache($r);
1.1 www 2078: $r->send_http_header;
2079: return OK if $r->header_only;
1.9 matthew 2080: #
1.35 matthew 2081: &Apache::loncommon::get_unprocessed_cgi($ENV{'QUERY_STRING'},
1.70 raeburn 2082: ['action','wysiwyg','returnurl','refpage']);
1.35 matthew 2083: #
2084: &Apache::lonhtmlcommon::clear_breadcrumbs();
2085: &Apache::lonhtmlcommon::add_breadcrumb
2086: ({href => '/adm/preferences',
2087: text => 'Set User Preferences'});
2088:
2089: my @Options;
2090: # Determine current authentication method
2091: my $currentauth=&Apache::lonnet::queryauthenticate($user,$domain);
2092: if ($currentauth =~ /^(unix|internal):/) {
2093: push (@Options,({ action => 'changepass',
1.40 www 2094: linktext => 'Change Password',
1.35 matthew 2095: href => '/adm/preferences',
2096: help => 'Change_Password',
2097: subroutine => \&passwordchanger,
2098: breadcrumb =>
2099: { href => '/adm/preferences?action=changepass',
2100: text => 'Change Password'},
2101: },
2102: { action => 'verify_and_change_pass',
2103: subroutine => \&verify_and_change_password,
2104: breadcrumb =>
2105: { href =>'/adm/preferences?action=changepass',
2106: text => 'Change Password'},
1.75 albertel 2107: printmenu => 'not_on_error',
1.35 matthew 2108: }));
2109: }
2110: push (@Options,({ action => 'changescreenname',
2111: linktext => 'Change Screen Name',
2112: href => '/adm/preferences',
2113: help => 'Prefs_Screen_Name_Nickname',
2114: subroutine => \&screennamechanger,
2115: breadcrumb =>
2116: { href => '/adm/preferences?action=changescreenname',
2117: text => 'Change Screen Name'},
2118: },
2119: { action => 'verify_and_change_screenname',
2120: subroutine => \&verify_and_change_screenname,
2121: breadcrumb =>
2122: { href => '/adm/preferences?action=changescreenname',
2123: text => 'Change Screen Name'},
2124: printmenu => 'yes',
2125: }));
2126:
2127: push (@Options,({ action => 'changemsgforward',
1.129 schafran 2128: linktext => 'Change Message Forwarding and Notification E-mail Addresses',
1.35 matthew 2129: href => '/adm/preferences',
1.113 raeburn 2130: help => 'Prefs_Messages',
1.35 matthew 2131: breadcrumb =>
2132: { href => '/adm/preferences?action=changemsgforward',
1.113 raeburn 2133: text => 'Change Message Forwarding/Notification'},
1.35 matthew 2134: subroutine => \&msgforwardchanger,
2135: },
2136: { action => 'verify_and_change_msgforward',
1.113 raeburn 2137: help => 'Prefs_Messages',
1.35 matthew 2138: breadcrumb =>
2139: { href => '/adm/preferences?action=changemsgforward',
1.113 raeburn 2140: text => 'Change Message Forwarding/Notification'},
1.126 droeschl 2141: printmenu => 'yes',
1.35 matthew 2142: subroutine => \&verify_and_change_msgforward }));
2143: my $aboutmeaction=
1.59 albertel 2144: '/adm/'.$env{'user.domain'}.'/'.$env{'user.name'}.'/aboutme';
1.35 matthew 2145: push (@Options,{ action => 'none',
2146: linktext =>
1.41 www 2147: q{Edit the 'About Me' Personal Information Screen},
1.45 www 2148: help => 'Prefs_About_Me',
1.35 matthew 2149: href => $aboutmeaction});
2150: push (@Options,({ action => 'changecolors',
2151: linktext => 'Change Color Scheme',
2152: href => '/adm/preferences',
2153: help => 'Change_Colors',
2154: breadcrumb =>
2155: { href => '/adm/preferences?action=changecolors',
2156: text => 'Change Colors'},
2157: subroutine => \&colorschanger,
2158: },
2159: { action => 'verify_and_change_colors',
2160: breadcrumb =>
2161: { href => '/adm/preferences?action=changecolors',
2162: text => 'Change Colors'},
2163: printmenu => 'yes',
2164: subroutine => \&verify_and_change_colors,
2165: }));
2166: push (@Options,({ action => 'changelanguages',
1.39 www 2167: linktext => 'Change Language Preferences',
1.35 matthew 2168: href => '/adm/preferences',
1.45 www 2169: help => 'Prefs_Language',
1.35 matthew 2170: breadcrumb=>
2171: { href => '/adm/preferences?action=changelanguages',
2172: text => 'Change Language'},
2173: subroutine => \&languagechanger,
2174: },
2175: { action => 'verify_and_change_languages',
2176: breadcrumb=>
2177: {href => '/adm/preferences?action=changelanguages',
2178: text => 'Change Language'},
2179: printmenu => 'yes',
2180: subroutine=>\&verify_and_change_languages, }
2181: ));
1.44 www 2182: push (@Options,({ action => 'changewysiwyg',
2183: linktext => 'Change WYSIWYG Editor Preferences',
2184: href => '/adm/preferences',
2185: breadcrumb =>
2186: { href => '/adm/preferences?action=changewysiwyg',
2187: text => 'Change WYSIWYG Preferences'},
2188: subroutine => \&wysiwygchanger,
2189: },
2190: { action => 'set_wysiwyg',
2191: breadcrumb =>
2192: { href => '/adm/preferences?action=changewysiwyg',
2193: text => 'Change WYSIWYG Preferences'},
2194: printmenu => 'yes',
2195: subroutine => \&verify_and_change_wysiwyg, }
2196: ));
1.42 raeburn 2197: push (@Options,({ action => 'changediscussions',
2198: linktext => 'Change Discussion Display Preferences',
2199: href => '/adm/preferences',
1.46 raeburn 2200: help => 'Change_Discussion_Display',
1.42 raeburn 2201: breadcrumb =>
2202: { href => '/adm/preferences?action=changediscussions',
1.43 raeburn 2203: text => 'Change Discussion Preferences'},
1.42 raeburn 2204: subroutine => \&discussionchanger,
2205: },
2206: { action => 'verify_and_change_discussion',
2207: breadcrumb =>
2208: { href => '/adm/preferences?action=changediscussions',
1.43 raeburn 2209: text => 'Change Discussion Preferences'},
1.42 raeburn 2210: printmenu => 'yes',
2211: subroutine => \&verify_and_change_discussion, }
2212: ));
1.96 albertel 2213:
2214: my $role = ($env{'user.adv'} ? 'Roles' : 'Course');
1.50 albertel 2215: push (@Options,({ action => 'changerolespref',
1.96 albertel 2216: linktext => 'Change '.$role.' Page Preferences',
1.50 albertel 2217: href => '/adm/preferences',
2218: subroutine => \&rolesprefchanger,
2219: breadcrumb =>
2220: { href => '/adm/preferences?action=changerolespref',
1.96 albertel 2221: text => 'Change '.$role.' Page Pref'},
1.50 albertel 2222: },
2223: { action => 'verify_and_change_rolespref',
2224: subroutine => \&verify_and_change_rolespref,
2225: breadcrumb =>
2226: { href => '/adm/preferences?action=changerolespref',
1.96 albertel 2227: text => 'Change '.$role.' Page Preferences'},
1.50 albertel 2228: printmenu => 'yes',
2229: }));
2230:
1.54 albertel 2231: push (@Options,({ action => 'changetexenginepref',
2232: linktext => 'Change How Math Equations Are Displayed',
2233: href => '/adm/preferences',
2234: subroutine => \&texenginechanger,
2235: breadcrumb =>
2236: { href => '/adm/preferences?action=changetexenginepref',
2237: text => 'Change Math Pref'},
2238: },
2239: { action => 'verify_and_change_texengine',
2240: subroutine => \&verify_and_change_texengine,
2241: breadcrumb =>
2242: { href => '/adm/preferences?action=changetexenginepref',
2243: text => 'Change Math Preferences'},
2244: printmenu => 'yes',
2245: }));
1.85 albertel 2246:
2247: if ($env{'environment.remote'} eq 'off') {
2248: push (@Options,({ action => 'launch',
2249: linktext => 'Launch Remote Control',
2250: href => '/adm/remote?url=/adm/preferences',
2251: }));
2252: } else {
2253: push (@Options,({ action => 'collapse',
2254: linktext => 'Collapse Remote Control',
2255: href => '/adm/remote?url=/adm/preferences',
2256: }));
2257: }
2258:
1.98 www 2259: push (@Options,({ action => 'changeicons',
1.100 www 2260: linktext => 'Change How Menus are Displayed',
1.98 www 2261: href => '/adm/preferences',
2262: subroutine => \&iconchanger,
2263: breadcrumb =>
2264: { href => '/adm/preferences?action=changeicons',
2265: text => 'Change Main Menu'},
2266: },
2267: { action => 'verify_and_change_icons',
2268: subroutine => \&verify_and_change_icons,
2269: breadcrumb =>
2270: { href => '/adm/preferences?action=changeicons',
2271: text => 'Change Main Menu'},
2272: printmenu => 'yes',
2273: }));
2274:
1.106 www 2275: push (@Options,({ action => 'changeclicker',
2276: linktext => 'Register Response Devices ("Clickers")',
2277: href => '/adm/preferences',
2278: subroutine => \&clickerchanger,
2279: breadcrumb =>
1.118 www 2280: { href => '/adm/preferences?action=changeclicker',
1.106 www 2281: text => 'Register Clicker'},
2282: },
2283: { action => 'verify_and_change_clicker',
2284: subroutine => \&verify_and_change_clicker,
2285: breadcrumb =>
2286: { href => '/adm/preferences?action=changeclicker',
2287: text => 'Register Clicker'},
2288: printmenu => 'yes',
2289: }));
1.125 raeburn 2290: my %author_roles = &Apache::lonnet::get_my_roles($user,$domain,'userroles','',['au']);
2291: if (keys(%author_roles) > 0) {
1.119 www 2292: push (@Options,({ action => 'changedomcoord',
2293: linktext => 'Restrict Domain Coordinator Access',
2294: href => '/adm/preferences',
2295: subroutine => \&domcoordchanger,
2296: breadcrumb =>
2297: { href => '/adm/preferences?action=changedomcoord',
2298: text => 'Restrict Domain Coordinator Access'},
2299: },
2300: { action => 'verify_and_change_domcoord',
2301: subroutine => \&verify_and_change_domcoord,
2302: breadcrumb =>
2303: { href => '/adm/preferences?action=changedomcoord',
2304: text => 'Restrict Domain Coordinator Access'},
2305: printmenu => 'yes',
2306: }));
2307: }
1.105 www 2308:
1.118 www 2309: push (@Options,({ action => 'lockwarning',
2310: subroutine => \&lockwarning,
2311: breadcrumb =>
2312: { href => '/adm/preferences?action=lockwarning',
2313: text => 'Lock Warnings'},
2314: },
2315: { action => 'verify_and_change_locks',
2316: subroutine => \&verify_and_change_lockwarning,
2317: breadcrumb =>
2318: { href => '/adm/preferences?action=lockwarning',
2319: text => 'Lockwarnings'},
2320: printmenu => 'yes',
2321: }));
2322:
1.105 www 2323:
1.74 albertel 2324: if (&Apache::lonnet::allowed('whn',$env{'request.course.id'})
2325: || &Apache::lonnet::allowed('whn',$env{'request.course.id'}.'/'
2326: .$env{'request.course.sec'})) {
1.63 raeburn 2327: push (@Options,({ action => 'changecourseinit',
2328: linktext => 'Change Course Initialization Preference',
2329: href => '/adm/preferences',
2330: subroutine => \&coursedisplaychanger,
2331: breadcrumb =>
2332: { href => '/adm/preferences?action=changecourseinit',
2333: text => 'Change Course Init. Pref.'},
2334: },
2335: { action => 'verify_and_change_coursepage',
2336: breadcrumb =>
2337: { href => '/adm/preferences?action=changecourseinit', text => 'Change Course Initialization Preference'},
2338: printmenu => 'yes',
2339: subroutine => \&verify_and_change_coursepage,
2340: }));
2341: }
1.50 albertel 2342:
1.119 www 2343: if ($env{'user.name'} =~ /^(albertel|fox|foxr|kortemey|korte|raeburn)$/) {
1.35 matthew 2344: push (@Options,({ action => 'debugtoggle',
2345: printmenu => 'yes',
2346: subroutine => \&toggle_debug,
2347: }));
2348: }
1.76 albertel 2349:
2350: $r->print(&Apache::loncommon::start_page('Change Preferences'));
2351:
1.35 matthew 2352: my $call = undef;
1.48 albertel 2353: my $help = undef;
1.35 matthew 2354: my $printmenu = 'yes';
2355: foreach my $option (@Options) {
1.59 albertel 2356: if ($option->{'action'} eq $env{'form.action'}) {
1.35 matthew 2357: $call = $option->{'subroutine'};
2358: $printmenu = $option->{'printmenu'};
2359: if (exists($option->{'breadcrumb'})) {
2360: &Apache::lonhtmlcommon::add_breadcrumb
2361: ($option->{'breadcrumb'});
2362: }
1.48 albertel 2363: $help=$option->{'help'};
1.35 matthew 2364: }
2365: }
1.81 albertel 2366: $r->print(&Apache::lonhtmlcommon::breadcrumbs('Change Preferences',$help));
1.75 albertel 2367: my $error;
1.35 matthew 2368: if (defined($call)) {
1.75 albertel 2369: $error = $call->($r);
1.35 matthew 2370: }
1.75 albertel 2371: if ( ( ($printmenu eq 'yes')
2372: || ($printmenu eq 'not_on_error' && !$error) )
2373: && (!$env{'form.returnurl'})) {
1.35 matthew 2374: my $optionlist = '<table cellpadding="5">';
1.59 albertel 2375: if ($env{'user.name'} =~
1.62 raeburn 2376: /^(albertel|kortemey|fox|foxr|korte|hallmat3|turtle|raeburn)$/
1.35 matthew 2377: ) {
2378: push (@Options,({ action => 'debugtoggle',
2379: linktext => 'Toggle Debug Messages',
2380: text => 'Current Debug status is -'.
1.59 albertel 2381: $env{'user.debug'}.'-.',
1.35 matthew 2382: href => '/adm/preferences',
2383: printmenu => 'yes',
2384: subroutine => \&toggle_debug,
2385: }));
2386: }
2387: foreach my $option(@Options) {
2388: my $optiontext = '';
2389: if (exists($option->{'href'})) {
1.85 albertel 2390: $option->{'href_args'}{'action'}=$option->{'action'};
2391: $optiontext .=
2392: '<a href="'.&add_get_param($option->{'href'},
2393: $option->{'href_args'}).'">'.
1.47 albertel 2394: &mt($option->{'linktext'}).'</a>';
1.35 matthew 2395: }
2396: if (exists($option->{'text'})) {
1.47 albertel 2397: $optiontext .= ' '.&mt($option->{'text'});
1.35 matthew 2398: }
2399: if ($optiontext ne '') {
2400: $optiontext = '<font size="+1">'.$optiontext.'</font>';
2401: my $helplink = ' ';
2402: if (exists($option->{'help'})) {
2403: $helplink = &Apache::loncommon::help_open_topic
2404: ($option->{'help'});
2405: }
2406: $optionlist .= '<tr>'.
2407: '<td>'.$helplink.'</td>'.
2408: '<td>'.$optiontext.'</td>'.
2409: '</tr>';
2410: }
1.13 www 2411: }
1.35 matthew 2412: $optionlist .= '</table>';
2413: $r->print($optionlist);
1.59 albertel 2414: } elsif ($env{'form.returnurl'}) {
2415: $r->print('<br /><a href="'.$env{'form.returnurl'}.'"><font size="+1">'.
1.44 www 2416: &mt('Return').'</font></a>');
1.3 matthew 2417: }
1.76 albertel 2418: $r->print(&Apache::loncommon::end_page());
1.1 www 2419: return OK;
1.35 matthew 2420: }
2421:
2422: sub toggle_debug {
1.59 albertel 2423: if ($env{'user.debug'}) {
1.35 matthew 2424: &Apache::lonnet::delenv('user\.debug');
2425: } else {
1.116 raeburn 2426: &Apache::lonnet::appenv({'user.debug' => 1});
1.35 matthew 2427: }
1.13 www 2428: }
1.1 www 2429:
2430: 1;
2431: __END__
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>