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