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