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