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