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