Annotation of loncom/interface/lonpreferences.pm, revision 1.196.4.28.2.4
1.1 www 1: # The LearningOnline Network
2: # Preferences
3: #
1.196.4.28.2. (raeburn 4:): # $Id: lonpreferences.pm,v 1.196.4.28.2.3 2024/03/01 14:23:23 raeburn Exp $
1.2 albertel 5: #
6: # Copyright Michigan State University Board of Trustees
7: #
8: # This file is part of the LearningOnline Network with CAPA (LON-CAPA).
9: #
10: # LON-CAPA is free software; you can redistribute it and/or modify
11: # it under the terms of the GNU General Public License as published by
12: # the Free Software Foundation; either version 2 of the License, or
13: # (at your option) any later version.
14: #
15: # LON-CAPA is distributed in the hope that it will be useful,
16: # but WITHOUT ANY WARRANTY; without even the implied warranty of
17: # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18: # GNU General Public License for more details.
19: #
20: # You should have received a copy of the GNU General Public License
21: # along with LON-CAPA; if not, write to the Free Software
22: # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
23: #
24: # /home/httpd/html/adm/gpl.txt
25: #
26: # http://www.lon-capa.org/
27: #
1.3 matthew 28: # This package uses the "londes.js" javascript code.
29: #
30:
1.1 www 31: package Apache::lonpreferences;
32:
33: use strict;
34: use Apache::Constants qw(:common);
1.3 matthew 35: use Apache::File;
1.4 matthew 36: use Apache::loncommon();
1.23 matthew 37: use Apache::lonhtmlcommon();
1.32 www 38: use Apache::lonlocal;
1.59 albertel 39: use Apache::lonnet;
1.174 raeburn 40: use LONCAPA::lonauthcgi();
1.95 albertel 41: use LONCAPA();
1.196.4.28.2. (raeburn 42:): use DateTime::TimeZone();
1.3 matthew 43:
1.4 matthew 44: ################################################################
45: # Handler subroutines #
46: ################################################################
1.9 matthew 47:
48: ################################################################
1.28 www 49: # Language Change Subroutines #
50: ################################################################
1.44 www 51:
52: sub wysiwygchanger {
53: my $r = shift;
1.126 droeschl 54: Apache::lonhtmlcommon::add_breadcrumb(
55: { href => '/adm/preferences?action=changewysiwyg',
56: text => 'Change WYSIWYG Preferences'});
1.147 schafran 57: $r->print(Apache::loncommon::start_page('Content Display Settings'));
1.126 droeschl 58: $r->print(Apache::lonhtmlcommon::breadcrumbs('Change WYSIWYG Preferences'));
59:
1.44 www 60: my %userenv = &Apache::lonnet::get
61: ('environment',['wysiwygeditor']);
1.78 albertel 62: my $onselect='checked="checked"';
1.44 www 63: my $offselect='';
1.77 albertel 64: if ($userenv{'wysiwygeditor'} eq 'on') {
1.44 www 65: $onselect='';
1.78 albertel 66: $offselect='checked="checked"';
1.44 www 67: }
68: my $switchoff=&mt('Disable WYSIWYG editor');
69: my $switchon=&mt('Enable WYSIWYG editor');
1.124 www 70: my $warning='';
71: if ($env{'user.adv'}) {
1.185 droeschl 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>";
1.124 www 73: }
1.44 www 74: $r->print(<<ENDLSCREEN);
1.88 albertel 75: <form name="prefs" action="/adm/preferences" method="post">
1.44 www 76: <input type="hidden" name="action" value="set_wysiwyg" />
1.124 www 77: $warning
1.44 www 78: <br />
1.65 albertel 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>
1.44 www 81: ENDLSCREEN
1.136 schafran 82: $r->print('<br /><input type="submit" value="'.&mt('Save').'" />');
1.44 www 83: }
84:
85:
86: sub verify_and_change_wysiwyg {
87: my $r = shift;
1.59 albertel 88: my $newsetting=$env{'form.wysiwyg'};
1.44 www 89: &Apache::lonnet::put('environment',{'wysiwygeditor' => $newsetting});
1.116 raeburn 90: &Apache::lonnet::appenv({'environment.wysiwygeditor' => $newsetting});
1.158 bisitz 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);
1.44 www 94: }
95:
96: ################################################################
97: # Language Change Subroutines #
98: ################################################################
1.28 www 99: sub languagechanger {
100: my $r = shift;
1.126 droeschl 101:
102: Apache::lonhtmlcommon::add_breadcrumb(
103: { href => '/adm/preferences?action=changelanguages',
1.127 droeschl 104: text => 'Change Language'});
1.147 schafran 105: $r->print(Apache::loncommon::start_page('Content Display Settings'));
1.126 droeschl 106: $r->print(Apache::lonhtmlcommon::breadcrumbs('Change Language'));
1.196.4.10 raeburn 107: my %userenv = &Apache::lonnet::get('environment',['languages']);
1.29 www 108: my $language=$userenv{'languages'};
1.32 www 109:
1.196.4.10 raeburn 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: );
1.28 www 117: }
118:
119:
120: sub verify_and_change_languages {
121: my $r = shift;
1.59 albertel 122: my $user = $env{'user.name'};
123: my $domain = $env{'user.domain'};
1.28 www 124: # Screenname
1.59 albertel 125: my $newlanguage = $env{'form.language'};
1.28 www 126: $newlanguage=~s/[^\-\w]//g;
127: my $message='';
128: if ($newlanguage) {
1.29 www 129: &Apache::lonnet::put('environment',{'languages' => $newlanguage});
1.116 raeburn 130: &Apache::lonnet::appenv({'environment.languages' => $newlanguage});
1.183 bisitz 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.');
1.28 www 137: } else {
1.29 www 138: &Apache::lonnet::del('environment',['languages']);
1.139 raeburn 139: &Apache::lonnet::delenv('environment.languages');
1.158 bisitz 140: $message=&Apache::lonhtmlcommon::confirm_success(&mt('Reset [_1]','<i>'.&mt('Preferred language').'</i>'));
1.28 www 141: }
1.158 bisitz 142: $message=&Apache::loncommon::confirmwrapper($message);
1.132 raeburn 143: &Apache::loncommon::flush_langs_cache($user,$domain);
1.152 www 144: &print_main_menu($r, $message);
1.28 www 145: }
146:
1.50 albertel 147: ################################################################
1.54 albertel 148: # Tex Engine Change Subroutines #
149: ################################################################
150: sub texenginechanger {
151: my $r = shift;
1.126 droeschl 152: Apache::lonhtmlcommon::add_breadcrumb(
153: { href => '/adm/preferences?action=changetexenginepref',
1.177 raeburn 154: text => 'Math display settings'});
1.147 schafran 155: $r->print(Apache::loncommon::start_page('Content Display Settings'));
1.177 raeburn 156: $r->print(Apache::lonhtmlcommon::breadcrumbs('Math display settings'));
1.59 albertel 157: my $user = $env{'user.name'};
158: my $domain = $env{'user.domain'};
1.54 albertel 159: my %userenv = &Apache::lonnet::get('environment',['texengine']);
160: my $texengine=$userenv{'texengine'};
1.196.4.18 raeburn 161: if (lc($texengine) eq 'jsmath') {
162: $texengine = 'MathJax';
163: }
1.54 albertel 164:
1.69 albertel 165: my %mathchoices=('' => 'Default',
1.123 bisitz 166: 'tth' => 'tth (TeX to HTML)',
1.64 albertel 167: #'ttm' => 'TeX to MathML',
1.196.4.3 raeburn 168: 'MathJax' => 'MathJax',
1.168 www 169: 'mimetex' => 'mimetex (Convert to Images)',
170: 'raw' => 'Raw (Screen Reader)'
1.54 albertel 171: );
1.190 raeburn 172: %mathchoices = &Apache::lonlocal::texthash(%mathchoices);
1.179 bisitz 173: my $selectionbox=
174: &Apache::loncommon::select_form(
175: $texengine,
176: 'texengine',
1.190 raeburn 177: \%mathchoices);
1.196.4.3 raeburn 178: my $MathJax_start=&Apache::lontexconvert::MathJax_header();
1.123 bisitz 179: my %lt=&Apache::lonlocal::texthash(
1.177 raeburn 180: 'headline' => 'Change how math is displayed',
181: 'preftxt' => 'Preferred method to display math',
1.136 schafran 182: 'change' => 'Save',
1.123 bisitz 183: 'exmpl' => 'Examples',
1.196.4.3 raeburn 184: 'mathjax' => 'MathJax:',
1.196.4.15 raeburn 185: 'mathjaxinfo' => 'MathJax provides rendered equations whose source code can be extracted in TeX and MathML formats by right clicking the equation.',
1.123 bisitz 186: 'tth' => 'tth (TeX to HTML):',
187: 'mimetex' => 'mimetex (Convert to Images):',
188: );
189:
1.54 albertel 190: $r->print(<<ENDLSCREEN);
1.123 bisitz 191: <h2>$lt{'headline'}</h2>
1.88 albertel 192: <form name="prefs" action="/adm/preferences" method="post">
1.54 albertel 193: <input type="hidden" name="action" value="verify_and_change_texengine" />
1.123 bisitz 194: <p>
1.136 schafran 195: $lt{'preftxt'}: $selectionbox
196: <br />
197: <input type="submit" value="$lt{'change'}" />
1.123 bisitz 198: </p>
1.54 albertel 199: </form>
1.123 bisitz 200: <br />
201: <hr />
202: $lt{'exmpl'}
203:
1.196.4.3 raeburn 204: <h3>$lt{'mathjax'}</h3>
205: </script>
1.196.4.15 raeburn 206: <iframe src="/res/adm/pages/math_example.tex?inhibitmenu=yes&texengine=MathJax" width="400" height="150"></iframe>
1.196.4.3 raeburn 207: </p>
208: <p>
1.196.4.15 raeburn 209: $lt{'mathjaxinfo'}
1.196.4.3 raeburn 210: </p>
211:
1.123 bisitz 212: <h3>$lt{'mimetex'}</h3>
213: <p>
1.196.4.15 raeburn 214: <iframe src="/res/adm/pages/math_example.tex?inhibitmenu=yes&texengine=mimetex" width="400" height="150"></iframe>
1.67 albertel 215: </p>
1.123 bisitz 216:
217: <h3>$lt{'tth'}</h3>
218: <p>
1.196.4.15 raeburn 219: <iframe src="/res/adm/pages/math_example.tex?inhibitmenu=yes&texengine=tth" width="400" height="150"></iframe>
1.67 albertel 220: </p>
1.54 albertel 221: ENDLSCREEN
222: }
223:
224:
225: sub verify_and_change_texengine {
226: my $r = shift;
1.59 albertel 227: my $user = $env{'user.name'};
228: my $domain = $env{'user.domain'};
1.54 albertel 229: # Screenname
1.59 albertel 230: my $newtexengine = $env{'form.texengine'};
1.54 albertel 231: $newtexengine=~s/[^\-\w]//g;
1.196.4.18 raeburn 232: if (lc($newtexengine) eq 'jsmath') {
233: $newtexengine = 'MathJax';
234: }
1.56 albertel 235: if ($newtexengine eq 'ttm') {
1.116 raeburn 236: &Apache::lonnet::appenv({'browser.mathml' => 1});
1.56 albertel 237: } else {
1.59 albertel 238: if ($env{'environment.texengine'} eq 'ttm') {
1.116 raeburn 239: &Apache::lonnet::appenv({'browser.mathml' => 0});
1.56 albertel 240: }
241: }
1.54 albertel 242: my $message='';
243: if ($newtexengine) {
244: &Apache::lonnet::put('environment',{'texengine' => $newtexengine});
1.116 raeburn 245: &Apache::lonnet::appenv({'environment.texengine' => $newtexengine});
1.158 bisitz 246: $message=&Apache::lonhtmlcommon::confirm_success(&mt('Set [_1] to [_2]','<i>'.&mt('Preferred method to display Math').'</i>','<tt>"'.$newtexengine.'"</tt>'));
1.54 albertel 247: } else {
248: &Apache::lonnet::del('environment',['texengine']);
1.139 raeburn 249: &Apache::lonnet::delenv('environment.texengine');
1.158 bisitz 250: $message=&Apache::lonhtmlcommon::confirm_success(&mt('Reset [_1]','<i>'.&mt('Preferred method to display Math').'</i>'));
1.54 albertel 251: }
1.158 bisitz 252: $message=&Apache::loncommon::confirmwrapper($message);
1.152 www 253: &print_main_menu($r, $message);
1.54 albertel 254: }
255:
256: ################################################################
1.50 albertel 257: # Roles Page Preference Change Subroutines #
258: ################################################################
259: sub rolesprefchanger {
260: my $r = shift;
1.96 albertel 261: my $role = ($env{'user.adv'} ? 'Role' : 'Course');
262: my $lc_role = ($env{'user.adv'} ? 'role' : 'course');
1.59 albertel 263: my $user = $env{'user.name'};
264: my $domain = $env{'user.domain'};
1.50 albertel 265: my %userenv = &Apache::lonnet::get
266: ('environment',['recentroles','recentrolesn']);
1.196.4.5 raeburn 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: }
1.126 droeschl 274: Apache::lonhtmlcommon::add_breadcrumb(
275: { href => '/adm/preferences?action=changerolespref',
1.196.4.5 raeburn 276: text => $brtext});
1.147 schafran 277: $r->print(Apache::loncommon::start_page('Content Display Settings'));
1.196.4.5 raeburn 278: $r->print(Apache::lonhtmlcommon::breadcrumbs($brtitle));
1.50 albertel 279: my $hotlist_flag=$userenv{'recentroles'};
280: my $hotlist_n=$userenv{'recentrolesn'};
1.196.4.5 raeburn 281: my ($checkedon,$checkedoff);
1.50 albertel 282: if ($hotlist_flag) {
1.196.4.5 raeburn 283: $checkedon = 'checked="checked"';
284: } else {
285: $checkedoff = 'checked="checked"';
1.50 albertel 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:
1.89 albertel 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'});
1.91 albertel 302: my %frozen_roles =
303: &Apache::lonhtmlcommon::get_recent_frozen('roles',$env{'environment.recentrolesn'});
1.89 albertel 304:
1.93 albertel 305: my %role_text = &rolespref_get_role_text([keys(%recent_roles)]);
1.92 albertel 306: my @sorted_roles = sort {$role_text{$a} cmp $role_text{$b}} keys(%role_text);
307:
1.89 albertel 308: $roles_check_list .=
309: &Apache::loncommon::start_data_table().
310: &Apache::loncommon::start_data_table_header_row().
1.96 albertel 311: "<th>".&mt('Freeze '.$role)."</th>".
1.196.4.5 raeburn 312: "<th>".&mt($role)."</th>".
1.89 albertel 313: &Apache::loncommon::end_data_table_header_row().
314: "\n";
315: my $count;
1.92 albertel 316: foreach $role_key (@sorted_roles) {
1.89 albertel 317: my $checked = "";
318: my $value = $recent_roles{$role_key};
1.91 albertel 319: if ($frozen_roles{$role_key}) {
1.159 bisitz 320: $checked = ' checked="checked"';
1.89 albertel 321: }
322: $count++;
323: $roles_check_list .=
324: &Apache::loncommon::start_data_table_row().
325: '<td class="LC_table_cell_checkbox">'.
1.159 bisitz 326: "<input type=\"checkbox\"$checked name=\"freezeroles\"".
1.89 albertel 327: " id=\"freezeroles$count\" value=\"$role_key\" /></td>".
328: "<td><label for=\"freezeroles$count\">".
1.92 albertel 329: "$role_text{$role_key}</label></td>".
1.89 albertel 330: &Apache::loncommon::end_data_table_row(). "\n";
331: }
332: $roles_check_list .= "</table>\n";
333: }
334:
1.196.4.5 raeburn 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: }
1.89 albertel 343: $r->print('
1.196.4.5 raeburn 344: <form name="prefs" action="'.$actionurl.'" method="post">
1.50 albertel 345: <input type="hidden" name="action" value="verify_and_change_rolespref" />
1.196.4.5 raeburn 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>'.
1.181 wenzelju 351: &Apache::lonhtmlcommon::start_pick_box().
1.196.4.5 raeburn 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>'.
1.181 wenzelju 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">'.
1.196.4.5 raeburn 361: $options.'
362: </select>'.
1.181 wenzelju 363: &Apache::lonhtmlcommon::row_closure(1).
1.196.4.5 raeburn 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 />'.
1.196.4.8 raeburn 370: &mt('Those '.$lc_role.'s marked frozen will not be removed from the list, even if not recently used.').'
1.89 albertel 371: </p>
372: '.$roles_check_list.'
1.196.4.5 raeburn 373: </div>');
374: } else {
375: $r->print('<br clear="all" />'.
1.196.4.13 raeburn 376: &mt('Once the Hotlist contains recently visited '.$lc_role.'s you can return to this page to also set frozen roles.'));
1.196.4.5 raeburn 377: }
378: $r->print('
379: <br clear="all" />
1.136 schafran 380: <input type="submit" value="'.&mt('Save').'" />
1.89 albertel 381: </form>');
1.50 albertel 382: }
383:
1.92 albertel 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);
1.93 albertel 392: my $trole = "";
393: $trole = &Apache::lonnet::plaintext($role);
1.92 albertel 394: my ($tdomain,$other,$tsection)= split(/\//,Apache::lonnet::declutter($rest));
395: my $tother = '-';
1.93 albertel 396: if ($role =~ /^(cc|st|in|ta|ep|cr)/ ) {
1.92 albertel 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:
1.50 albertel 414: sub verify_and_change_rolespref {
415: my $r = shift;
1.96 albertel 416: my $role = ($env{'user.adv'} ? 'Role' : 'Course');
1.59 albertel 417: my $user = $env{'user.name'};
418: my $domain = $env{'user.domain'};
1.50 albertel 419: # Recent Roles Hotlist Flag
1.59 albertel 420: my $hotlist_flag = $env{'form.recentroles'};
421: my $hotlist_n = $env{'form.recentrolesn'};
1.89 albertel 422: my $message='<hr />';
1.50 albertel 423: if ($hotlist_flag) {
424: &Apache::lonnet::put('environment',{'recentroles' => $hotlist_flag});
1.116 raeburn 425: &Apache::lonnet::appenv({'environment.recentroles' => $hotlist_flag});
1.180 wenzelju 426: $message=&Apache::lonhtmlcommon::confirm_success(&mt('Recent '.$role.'s Hotlist is Enabled.')." ".&mt('Display [_1] Most Recent '.$role.'s.',$hotlist_n));
1.50 albertel 427: } else {
428: &Apache::lonnet::del('environment',['recentroles']);
1.139 raeburn 429: &Apache::lonnet::delenv('environment.recentroles');
1.180 wenzelju 430: $message=&Apache::lonhtmlcommon::confirm_success(&mt('Recent '.$role.'s Hotlist is Disabled'));
1.50 albertel 431: }
432: if ($hotlist_n) {
433: &Apache::lonnet::put('environment',{'recentrolesn' => $hotlist_n});
1.116 raeburn 434: &Apache::lonnet::appenv({'environment.recentrolesn' => $hotlist_n});
1.89 albertel 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 = ();
1.92 albertel 440: my %roletext = ();
441:
1.89 albertel 442: foreach my $key (@freeze_list) {
1.91 albertel 443: $freeze{$key}='1';
1.89 albertel 444: }
1.92 albertel 445:
1.89 albertel 446: my %recent_roles =
447: &Apache::lonhtmlcommon::get_recent('roles',$env{'environment.recentrolesn'});
1.91 albertel 448: my %frozen_roles =
449: &Apache::lonhtmlcommon::get_recent_frozen('roles',$env{'environment.recentrolesn'});
1.92 albertel 450: my %role_text = &rolespref_get_role_text([keys(%recent_roles)]);
1.89 albertel 451:
452: # Unset any roles that were previously frozen but aren't in list
453: foreach my $role_key (sort(keys(%recent_roles))) {
1.91 albertel 454: if (($frozen_roles{$role_key}) && (!exists($freeze{$role_key}))) {
1.158 bisitz 455: $message .= "<br />".&Apache::lonhtmlcommon::confirm_success(&mt('Unfreezing '.$role.': [_1]','<i>'.$role_text{$role_key}.'</i>'));
1.91 albertel 456: &Apache::lonhtmlcommon::store_recent('roles',$role_key,' ',0);
1.89 albertel 457: }
458: }
459:
460: # Freeze selected roles
461: foreach my $role_key (@freeze_list) {
1.91 albertel 462: if (!$frozen_roles{$role_key}) {
1.154 www 463: $message .= "<br />".
1.158 bisitz 464: &Apache::lonhtmlcommon::confirm_success(&mt('Freezing '.$role.': [_1]','<i>'.$role_text{$role_key}.'</i>'));
1.89 albertel 465: &Apache::lonhtmlcommon::store_recent('roles',
1.91 albertel 466: $role_key,' ',1);
1.50 albertel 467: }
468: }
1.158 bisitz 469: $message=&Apache::loncommon::confirmwrapper($message);
1.196.4.5 raeburn 470: if ($env{'form.returnurl'} eq '/adm/roles') {
471: return $message;
472: } else {
473: &print_main_menu($r, $message);
474: }
1.50 albertel 475: }
476:
477:
1.28 www 478: ################################################################
1.9 matthew 479: # Anonymous Discussion Name Change Subroutines #
480: ################################################################
1.5 www 481: sub screennamechanger {
482: my $r = shift;
1.59 albertel 483: my $user = $env{'user.name'};
484: my $domain = $env{'user.domain'};
1.14 www 485: my %userenv = &Apache::lonnet::get
486: ('environment',['screenname','nickname']);
1.6 www 487: my $screenname=$userenv{'screenname'};
1.14 www 488: my $nickname=$userenv{'nickname'};
1.126 droeschl 489: Apache::lonhtmlcommon::add_breadcrumb(
490: { href => '/adm/preferences?action=changescreenname',
491: text => 'Change Screen Name'});
1.147 schafran 492: $r->print(Apache::loncommon::start_page('Personal Data'));
1.126 droeschl 493: $r->print(Apache::lonhtmlcommon::breadcrumbs('Change Screen Name'));
1.133 bisitz 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()
1.158 bisitz 501: .&Apache::lonhtmlcommon::row_title(&mt('Screenname').' '.&mt('(shown if you post anonymously)'))
1.133 bisitz 502: .'<input type="text" size="20" value="'.$screenname.'" name="screenname" />'
503: .&Apache::lonhtmlcommon::row_closure()
1.158 bisitz 504: .&Apache::lonhtmlcommon::row_title(&mt('Nickname').' '.&mt('(shown if you post non-anonymously)'))
1.133 bisitz 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: );
1.5 www 513: }
1.6 www 514:
515: sub verify_and_change_screenname {
516: my $r = shift;
1.59 albertel 517: my $user = $env{'user.name'};
518: my $domain = $env{'user.domain'};
1.14 www 519: # Screenname
1.59 albertel 520: my $newscreen = $env{'form.screenname'};
1.14 www 521: $newscreen=~s/[^ \w]//g;
1.6 www 522: my $message='';
523: if ($newscreen) {
1.7 www 524: &Apache::lonnet::put('environment',{'screenname' => $newscreen});
1.116 raeburn 525: &Apache::lonnet::appenv({'environment.screenname' => $newscreen});
1.161 bisitz 526: $message=&Apache::lonhtmlcommon::confirm_success(&mt('Set [_1] to [_2]','<i>'.&mt('Screenname').'</i>','<tt>"'.$newscreen.'"</tt>'));
1.6 www 527: } else {
528: &Apache::lonnet::del('environment',['screenname']);
1.139 raeburn 529: &Apache::lonnet::delenv('environment.screenname');
1.158 bisitz 530: $message=&Apache::lonhtmlcommon::confirm_success(&mt('Reset [_1]','<i>'.&mt('Screenname').'</i>'));
1.6 www 531: }
1.14 www 532: # Nickname
533: $message.='<br />';
1.59 albertel 534: $newscreen = $env{'form.nickname'};
1.14 www 535: $newscreen=~s/[^ \w]//g;
536: if ($newscreen) {
537: &Apache::lonnet::put('environment',{'nickname' => $newscreen});
1.116 raeburn 538: &Apache::lonnet::appenv({'environment.nickname' => $newscreen});
1.161 bisitz 539: $message.=&Apache::lonhtmlcommon::confirm_success(&mt('Set [_1] to [_2]','<i>'.&mt('Nickname').'</i>','<tt>"'.$newscreen.'"</tt>'));
1.14 www 540: } else {
541: &Apache::lonnet::del('environment',['nickname']);
1.139 raeburn 542: &Apache::lonnet::delenv('environment.nickname');
1.158 bisitz 543: $message.=&Apache::lonhtmlcommon::confirm_success(&mt('Reset [_1]','<i>'.&mt('Nickname').'</i>'));
1.14 www 544: }
1.68 www 545: &Apache::lonnet::devalidate_cache_new('namescache',$user.':'.$domain);
1.158 bisitz 546: $message=&Apache::loncommon::confirmwrapper($message);
1.152 www 547: &print_main_menu($r, $message);
1.20 www 548: }
549:
550: ################################################################
1.192 raeburn 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 {
1.196.4.27 raeburn 630: my %icon_text = &Apache::lonlocal::texthash (
1.192 raeburn 631: annotate => 'Notes',
1.196.4.4 raeburn 632: wishlist => 'Stored Links',
1.192 raeburn 633: catalog => 'Info',
634: evaluate => 'Evaluate',
635: feedback => 'Communicate',
636: printout => 'Print',
637: );
638: my %inlinetools = (
1.196.4.27 raeburn 639: printout => "s&8&3&prt.png&$icon_text{'printout'}&printout[_1]&gopost('/adm/printout',currentURL)&".&mt('Prepare a printable document'),
640: wishlist => "s&9&1&wishlist-link.png&$icon_text{'wishlist'}&wishlistlink[_2]&set_wishlistlink()&".&mt('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)&".&mt('Provide my evaluation of this resource'),
642: feedback => "s&8&2&fdbk.png&$icon_text{'feedback'}&discuss[_1]&gopost('/adm/feedback',currentURL,1)&".&mt('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()&".&mt('Make notes and annotations about this resource'),
644: catalog => "s&6&3&catalog.png&$icon_text{'catalog'}&info[_1]&catalog_info()&".&mt('Show Metadata'),
1.192 raeburn 645: );
646: my @toolsorder = qw(annotate wishlist evaluate feedback printout catalog);
647: return (\%inlinetools,\@toolsorder);
648: }
649:
650: ################################################################
1.105 www 651: # Clicker Subroutines #
652: ################################################################
653:
654: sub clickerchanger {
655: my $r = shift;
1.152 www 656: &Apache::lonhtmlcommon::add_breadcrumb(
1.126 droeschl 657: { href => '/adm/preferences?action=changeclicker',
658: text => 'Register Clicker'});
1.147 schafran 659: $r->print(Apache::loncommon::start_page('Other'));
1.126 droeschl 660: $r->print(Apache::lonhtmlcommon::breadcrumbs('Register Clicker'));
1.105 www 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');
1.151 bisitz 668: my $change=&mt('Save');
1.114 bisitz 669: my $helplink=&Apache::loncommon::help_open_topic('Clicker_Registration',&mt('Locating your clicker ID'));
1.105 www 670: $r->print(<<ENDSCREEN);
671: <form name="prefs" action="/adm/preferences" method="post">
672: <input type="hidden" name="action" value="verify_and_change_clicker" />
1.151 bisitz 673: <label>$helplink<br /><br />$text<br />
1.108 www 674: <textarea name="clickers" rows="5" cols="20">$clickers</textarea>
1.105 www 675: </label>
1.151 bisitz 676: <br />
1.105 www 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 $newclickers = $env{'form.clickers'};
1.108 www 687: $newclickers=~s/[^\w\:\-]+/\,/gs;
1.105 www 688: $newclickers=~tr/a-z/A-Z/;
1.108 www 689: $newclickers=~s/[\:\-]+/\-/g;
690: $newclickers=~s/\,+/\,/g;
1.105 www 691: $newclickers=~s/^\,//;
692: $newclickers=~s/\,$//;
693: &Apache::lonnet::put('environment',{'clickers' => $newclickers});
1.116 raeburn 694: &Apache::lonnet::appenv({'environment.clickers' => $newclickers});
1.158 bisitz 695: my $message=&Apache::lonhtmlcommon::confirm_success(&mt('Registering clickers: [_1]',$newclickers));
696: $message=&Apache::loncommon::confirmwrapper($message);
697: &print_main_menu($r, $message);
1.105 www 698: }
699:
1.119 www 700: ################################################################
701: # Domcoord Access Subroutines #
702: ################################################################
703:
704: sub domcoordchanger {
705: my $r = shift;
1.154 www 706: &Apache::lonhtmlcommon::add_breadcrumb(
1.126 droeschl 707: { href => '/adm/preferences?action=changedomcoord',
708: text => 'Restrict Domain Coordinator Access'});
709: $r->print(Apache::loncommon::start_page('Restrict Domain Coordinator Access'));
710: $r->print(Apache::lonhtmlcommon::breadcrumbs('Restrict Domain Coordinator Access'));
1.119 www 711: my $user = $env{'user.name'};
712: my $domain = $env{'user.domain'};
713: my %userenv = &Apache::lonnet::get
1.120 www 714: ('environment',['domcoord.author']);
1.119 www 715: my $constchecked='';
716: if ($userenv{'domcoord.author'} eq 'blocked') {
1.159 bisitz 717: $constchecked=' checked="checked"';
1.119 www 718: }
1.196.4.11 raeburn 719: my $text=&mt('By default, the Domain Coordinator can enter your Authoring Space.');
720: my $construction=&mt('Block access to Authoring Space');
1.136 schafran 721: my $change=&mt('Save');
1.196.4.24 raeburn 722: my $returnurl = &HTML::Entities::encode($env{'form.returnurl'},'"<>&\'');
1.119 www 723: $r->print(<<ENDSCREEN);
724: <form name="prefs" action="/adm/preferences" method="post">
1.196.4.24 raeburn 725: <input type="hidden" name="returnurl" value="$returnurl" />
1.119 www 726: <input type="hidden" name="action" value="verify_and_change_domcoord" />
727: $text<br />
1.159 bisitz 728: <label><input type="checkbox" name="construction"$constchecked />$construction</label><br />
1.119 www 729: <input type="submit" value="$change" />
730: </form>
731: ENDSCREEN
732: }
733:
734: sub verify_and_change_domcoord {
735: my $r = shift;
736: my $user = $env{'user.name'};
737: my $domain = $env{'user.domain'};
1.120 www 738: my %domcoord=('domcoord.author' => '');
1.119 www 739: if ($env{'form.construction'}) { $domcoord{'domcoord.author'}='blocked'; }
740: &Apache::lonnet::put('environment',\%domcoord);
1.120 www 741: &Apache::lonnet::appenv({'environment.domcoord.author' => $domcoord{'domcoord.author'}});
1.158 bisitz 742: my $status='';
743: if ($domcoord{'domcoord.author'} eq 'blocked') {
744: $status=&mt('on');
745: } else {
746: $status=&mt('off');
747: }
1.196.4.11 raeburn 748: my $message=&Apache::lonhtmlcommon::confirm_success(&mt('Set [_1] to [_2]','<i>'.&mt('Block access to Authoring Space').'</i>','<tt>'.$status.'</tt>'));
1.158 bisitz 749: $message=&Apache::loncommon::confirmwrapper($message);
1.196.4.24 raeburn 750: if ($env{'form.returnurl'}) {
751: &do_redirect($r,$env{'form.returnurl'},$message);
752: } else {
753: &print_main_menu($r,$message);
754: }
1.119 www 755: }
756:
1.118 www 757: #################################################################
758: ## Lock Subroutines #
759: #################################################################
760:
761: sub lockwarning {
762: my $r = shift;
763: my $title=&mt('Action locked');
764: my $texttop=&mt('LON-CAPA is currently performing the following actions:');
765: my $textbottom=&mt('Changing roles or logging out may result in data corruption.');
766: my ($num,%which)=&Apache::lonnet::get_locks();
767: my $which='';
1.196.4.16 raeburn 768: foreach my $id (keys(%which)) {
1.118 www 769: $which.='<li>'.$which{$id}.'</li>';
770: }
771: my $change=&mt('Override');
772: $r->print(<<ENDSCREEN);
773: <form name="prefs" action="/adm/preferences" method="post">
774: <input type="hidden" name="action" value="verify_and_change_locks" />
775: <h1>$title</h1>
776: $texttop
777: <ul>
778: $which
779: </ul>
780: $textbottom
781: <input type="submit" value="$change" />
782: </form>
783: ENDSCREEN
784: }
785:
786: sub verify_and_change_lockwarning {
787: my $r = shift;
788: &Apache::lonnet::remove_all_locks();
789: $r->print(&mt('Cleared locks.'));
790: }
791:
792:
1.105 www 793: ################################################################
1.20 www 794: # Message Forward #
795: ################################################################
796:
797: sub msgforwardchanger {
1.102 raeburn 798: my ($r,$message) = @_;
1.59 albertel 799: my $user = $env{'user.name'};
800: my $domain = $env{'user.domain'};
1.102 raeburn 801: my %userenv = &Apache::lonnet::get('environment',['msgforward','notification','critnotification','notifywithhtml']);
1.20 www 802: my $msgforward=$userenv{'msgforward'};
1.102 raeburn 803: my %lt = &Apache::lonlocal::texthash(
804: all => 'All',
805: crit => 'Critical only',
806: reg => 'Non-critical only',
1.175 raeburn 807: foad => 'Forward to account(s)',
808: fwdm => 'Forward messages to other account(s) in LON-CAPA',
809: noti => 'E-mail notification of LON-CAPA messages',
810: mnot => 'E-mail address(es) which should be notified about new LON-CAPA messages',
1.136 schafran 811: chg => 'Save',
1.104 raeburn 812: email => 'The e-mail address entered in row ',
1.102 raeburn 813: notv => 'is not a valid e-mail address',
1.103 raeburn 814: toen => "To enter multiple addresses, enter one address at a time, click 'Change' and then add the next one",
1.136 schafran 815: prme => 'Back',
1.102 raeburn 816: );
1.196.4.12 raeburn 817: $lt{'foad_exmpl'} = &mt('e.g. [_1]userA:domain1,userB:domain2,...[_2]','<tt>','</tt>');
818: $lt{'mnot_exmpl'} = &mt('e.g. [_1]joe@doe.com[_2]','<tt>','</tt>');
1.126 droeschl 819: Apache::lonhtmlcommon::add_breadcrumb(
820: { href => '/adm/preferences?action=changemsgforward',
1.176 raeburn 821: text => 'Messages & Notifications'});
1.178 bisitz 822: $r->print(Apache::loncommon::start_page('Messages & Notifications'));
823: $r->print(Apache::lonhtmlcommon::breadcrumbs('Messages & Notifications'));
1.113 raeburn 824: my $forwardingHelp = &Apache::loncommon::help_open_topic("Prefs_Forwarding");
825: my $notificationHelp = &Apache::loncommon::help_open_topic("Prefs_Notification");
826: my $criticalMessageHelp = &Apache::loncommon::help_open_topic("Course_Critical_Message");
1.102 raeburn 827: my @allow_html = split(/,/,$userenv{'notifywithhtml'});
828: my %allnot = &get_notifications(\%userenv);
829: my $validatescript = &Apache::lonhtmlcommon::javascript_valid_email();
830: my $jscript = qq|
1.148 bisitz 831: <script type="text/javascript" language="JavaScript">
1.102 raeburn 832: function validate() {
833: for (var i=0; i<document.prefs.numnotify.value; i++) {
1.104 raeburn 834: var checkaddress = 0;
1.102 raeburn 835: var addr = document.prefs.elements['address_'+i].value;
1.104 raeburn 836: var rownum = i+1;
1.102 raeburn 837: if (i < document.prefs.numnotify.value-1) {
1.104 raeburn 838: if (document.prefs.elements['modify_notify_'+i].checked) {
1.102 raeburn 839: checkaddress = 1;
1.104 raeburn 840: }
1.102 raeburn 841: } else {
842: if (document.prefs.elements['add_notify_'+i].checked == true) {
843: checkaddress = 1;
844: }
845: }
1.104 raeburn 846: if (checkaddress == 1) {
1.102 raeburn 847: var addr = document.prefs.elements['address_'+i].value;
848: if (validmail(document.prefs.elements['address_'+i]) == false) {
1.104 raeburn 849: var multimsg = '';
850: if (addr.indexOf(",") >= 0) {
851: multimsg = "\\n($lt{'toen'}).";
852: }
1.110 bisitz 853: alert("$lt{'email'} "+rownum+" ('"+addr+"') $lt{'notv'}."+multimsg);
1.102 raeburn 854: return;
855: }
856: }
857: }
858: document.prefs.submit();
859: }
1.104 raeburn 860:
861: function address_changes (adnum) {
862: if (!document.prefs.elements['del_notify_'+adnum].checked) {
863: document.prefs.elements['modify_notify_'+adnum].checked = true;
864: }
865: }
866:
867: function new_address(adnum) {
868: document.prefs.elements['add_notify_'+adnum].checked = true;
869: }
870:
871: function delete_address(adnum) {
872: if (document.prefs.elements['del_notify_'+adnum].checked) {
873: document.prefs.elements['modify_notify_'+adnum].checked = false;
874: }
875: }
876:
877: function modify_address(adnum) {
878: if (document.prefs.elements['modify_notify_'+adnum].checked) {
879: document.prefs.elements['del_notify_'+adnum].checked = false;
880: }
881: }
882:
1.102 raeburn 883: $validatescript
884: </script>
885: |;
1.20 www 886: $r->print(<<ENDMSG);
1.102 raeburn 887: $jscript
888: $message
1.175 raeburn 889: <h3>$lt{'fwdm'} $forwardingHelp</h3>
1.88 albertel 890: <form name="prefs" action="/adm/preferences" method="post">
1.20 www 891: <input type="hidden" name="action" value="verify_and_change_msgforward" />
1.110 bisitz 892: $lt{'foad'} ($lt{'foad_exmpl'}):
1.175 raeburn 893: <input type="text" size="40" value="$msgforward" name="msgforward" />
894: <br /><br />
1.113 raeburn 895: <h3>$lt{'noti'} $notificationHelp</h3>
1.110 bisitz 896: $lt{'mnot'} ($lt{'mnot_exmpl'}):<br />
1.102 raeburn 897: ENDMSG
898: my @sortforwards = sort (keys(%allnot));
899: my $output = &Apache::loncommon::start_data_table().
900: &Apache::loncommon::start_data_table_header_row().
1.104 raeburn 901: '<th> </th>'.
1.102 raeburn 902: '<th>'.&mt('Action').'</th>'.
903: '<th>'.&mt('Notification address').'</th><th>'.
1.113 raeburn 904: &mt('Types of message for which notification is sent').
905: $criticalMessageHelp.'</th><th>'.
1.104 raeburn 906: &mt('Excerpt retains HTML tags in message').'</th>'.
1.102 raeburn 907: &Apache::loncommon::end_data_table_header_row();
908: my $num = 0;
1.104 raeburn 909: my $counter = 1;
1.102 raeburn 910: foreach my $item (@sortforwards) {
911: $output .= &Apache::loncommon::start_data_table_row().
1.104 raeburn 912: '<td><b>'.$counter.'</b></td>'.
913: '<td><span class="LC_nobreak"><label>'.
914: '<input type="checkbox" name="modify_notify_'.
915: $num.'" onclick="javscript:modify_address('."'$num'".')" />'.
916: &mt('Modify').'</label></span> '.
917: '<span class="LC_nobreak"><label>'.
918: '<input type="checkbox" name="del_notify_'.$num.
919: '" onclick="javscript:delete_address('."'$num'".')" />'.
920: &mt('Delete').'</label></span></td>'.
1.102 raeburn 921: '<td><input type="text" value="'.$item.'" name="address_'.
1.196.4.12 raeburn 922: $num.'" onfocus="javascript:address_changes('."'$num'".
1.104 raeburn 923: ')" /></td><td>';
1.102 raeburn 924: my %chk;
925: if (defined($allnot{$item}{'crit'})) {
926: if (defined($allnot{$item}{'reg'})) {
927: $chk{'all'} = 'checked="checked" ';
928: } else {
929: $chk{'crit'} = 'checked="checked" ';
930: }
931: } else {
932: $chk{'reg'} = 'checked="checked" ';
933: }
934: foreach my $type ('all','crit','reg') {
935: $output .= '<span class="LC_nobreak"><label>'.
936: '<input type="radio" name="notify_type_'.$num.
1.104 raeburn 937: '" value="'.$type.'" '.$chk{$type}.
938: ' onchange="javascript:address_changes('."'$num'".')" />'.
1.175 raeburn 939: $lt{$type}.'</label></span>'.(' ' x4);
1.102 raeburn 940: }
941: my $htmlon = '';
942: my $htmloff = '';
943: if (grep/^\Q$item\E/,@allow_html) {
944: $htmlon = 'checked="checked" ';
945: } else {
946: $htmloff = 'checked="checked" ';
947: }
948: $output .= '</td><td><label><input type="radio" name="html_'.$num.
1.104 raeburn 949: '" value="1" '.$htmlon.
950: ' onchange="javascript:address_changes('."'$num'".')" />'.
1.175 raeburn 951: &mt('Yes').'</label>'.(' ' x3).
1.102 raeburn 952: '<label><input type="radio" name="html_'.$num.'" value="0" '.
1.104 raeburn 953: $htmloff. ' onchange="javascript:address_changes('."'$num'".
954: ')" />'.
955: &mt('No').'</label></td>'.
1.102 raeburn 956: &Apache::loncommon::end_data_table_row();
957: $num ++;
1.104 raeburn 958: $counter ++;
1.102 raeburn 959: }
960: my %defchk = (
961: all => 'checked="checked" ',
962: crit => '',
963: reg => '',
964: );
965: $output .= &Apache::loncommon::start_data_table_row().
1.104 raeburn 966: '<td><b>'.$counter.'</b></td>'.
967: '<td><span class="LC_nobreak"><label>'.
968: '<input type="checkbox" name="add_notify_'.$num.
969: '" value="1" />'.&mt('Add new address').'</label></span></td>'.
1.102 raeburn 970: '<td><input type="text" value="" name="address_'.$num.
1.196.4.12 raeburn 971: '" onfocus="javascript:new_address('."'$num'".')" /></td><td>';
1.102 raeburn 972: foreach my $type ('all','crit','reg') {
973: $output .= '<span class="LC_nobreak"><label>'.
974: '<input type="radio" name="notify_type_'.$num.
975: '" value="'.$type.'" '.$defchk{$type}.'/>'.
1.175 raeburn 976: $lt{$type}.'</label></span>'.(' ' x4);
1.102 raeburn 977: }
978: $output .= '</td><td><label><input type="radio" name="html_'.$num.
1.175 raeburn 979: '" value="1" />'.&mt('Yes').'</label>'.(' ' x3).
1.102 raeburn 980: '<label><input type="radio" name="html_'.$num.'" value="0" '.
981: ' checked="checked" />'.
982: &mt('No').'</label></td>'.
983: &Apache::loncommon::end_data_table_row().
984: &Apache::loncommon::end_data_table();
985: $num ++;
986: $r->print($output);
987: $r->print(qq|
1.113 raeburn 988: <br /><hr />
1.102 raeburn 989: <input type="hidden" name="numnotify" value="$num" />
1.136 schafran 990: <input type="button" value="$lt{'prme'}" onclick="location.href='/adm/preferences'" />
1.102 raeburn 991: <input type="button" value="$lt{'chg'}" onclick="javascript:validate()" />
1.20 www 992: </form>
1.102 raeburn 993: |);
994:
995: }
996:
997: sub get_notifications {
998: my ($userenv) = @_;
999: my %allnot;
1000: my @critnot = split(/,/,$userenv->{'critnotification'});
1001: my @regnot = split(/,/,$userenv->{'notification'});
1002: foreach my $item (@critnot) {
1003: $allnot{$item}{crit} = 1;
1004: }
1005: foreach my $item (@regnot) {
1006: $allnot{$item}{reg} = 1;
1007: }
1008: return %allnot;
1.20 www 1009: }
1010:
1011: sub verify_and_change_msgforward {
1012: my $r = shift;
1.59 albertel 1013: my $user = $env{'user.name'};
1014: my $domain = $env{'user.domain'};
1.20 www 1015: my $newscreen = '';
1016: my $message='';
1.182 raeburn 1017: foreach my $recip (split(/\,/,$env{'form.msgforward'})) {
1018: my ($msuser,$msdomain);
1019: if ($recip =~ /:/) {
1020: ($msuser,$msdomain)=split(':',$recip);
1021: } else {
1022: ($msuser,$msdomain)=split(/\@/,$recip);
1023: }
1.95 albertel 1024: $msuser = &LONCAPA::clean_username($msuser);
1025: $msdomain = &LONCAPA::clean_domain($msdomain);
1.20 www 1026: if (($msuser) && ($msdomain)) {
1027: if (&Apache::lonnet::homeserver($msuser,$msdomain) ne 'no_host') {
1.182 raeburn 1028: $newscreen.=$msuser.':'.$msdomain.',';
1029: } else {
1030: $message.= &mt('No such user: ').'<tt>'.$msuser.':'.$msdomain.'</tt><br />';
1031: }
1.20 www 1032: }
1033: }
1034: $newscreen=~s/\,$//;
1035: if ($newscreen) {
1036: &Apache::lonnet::put('environment',{'msgforward' => $newscreen});
1.116 raeburn 1037: &Apache::lonnet::appenv({'environment.msgforward' => $newscreen});
1.180 wenzelju 1038: $message .= &Apache::lonhtmlcommon::confirm_success(&mt('Set message forwarding to ').'<tt>"'.$newscreen.'"</tt>.<br />');
1.20 www 1039: } else {
1040: &Apache::lonnet::del('environment',['msgforward']);
1.139 raeburn 1041: &Apache::lonnet::delenv('environment.msgforward');
1.180 wenzelju 1042: $message.= &Apache::lonhtmlcommon::confirm_success(&mt("Set message forwarding to 'off'.").'<br />');
1.20 www 1043: }
1.102 raeburn 1044: my $critnotification;
1045: my $notification;
1046: my $notify_with_html;
1047: my $lastnotify = $env{'form.numnotify'}-1;
1.104 raeburn 1048: my $totaladdresses = 0;
1.102 raeburn 1049: for (my $i=0; $i<$env{'form.numnotify'}; $i++) {
1050: if ((!defined($env{'form.del_notify_'.$i})) &&
1.104 raeburn 1051: ((($i==$lastnotify) && ($env{'form.add_notify_'.$lastnotify} == 1)) ||
1.102 raeburn 1052: ($i<$lastnotify))) {
1053: if (defined($env{'form.address_'.$i})) {
1054: if ($env{'form.notify_type_'.$i} eq 'all') {
1055: $critnotification .= $env{'form.address_'.$i}.',';
1056: $notification .= $env{'form.address_'.$i}.',';
1057: } elsif ($env{'form.notify_type_'.$i} eq 'crit') {
1058: $critnotification .= $env{'form.address_'.$i}.',';
1059: } elsif ($env{'form.notify_type_'.$i} eq 'reg') {
1060: $notification .= $env{'form.address_'.$i}.',';
1061: }
1062: if ($env{'form.html_'.$i} eq '1') {
1063: $notify_with_html .= $env{'form.address_'.$i}.',';
1064: }
1.104 raeburn 1065: $totaladdresses ++;
1.102 raeburn 1066: }
1067: }
1068: }
1069: $critnotification =~ s/,$//;
1070: $critnotification=~s/\s//gs;
1071: $notification =~ s/,$//;
1.20 www 1072: $notification=~s/\s//gs;
1.102 raeburn 1073: $notify_with_html =~ s/,$//;
1074: $notify_with_html =~ s/\s//gs;
1.20 www 1075: if ($notification) {
1076: &Apache::lonnet::put('environment',{'notification' => $notification});
1.116 raeburn 1077: &Apache::lonnet::appenv({'environment.notification' => $notification});
1.180 wenzelju 1078: $message.=&Apache::lonhtmlcommon::confirm_success(&mt('Set non-critical message notification address(es) to ').'<tt>"'.$notification.'"</tt>.<br />');
1.20 www 1079: } else {
1080: &Apache::lonnet::del('environment',['notification']);
1.139 raeburn 1081: &Apache::lonnet::delenv('environment.notification');
1.180 wenzelju 1082: $message.=&Apache::lonhtmlcommon::confirm_success(&mt("Set non-critical message notification to 'off'.").'<br />');
1.20 www 1083: }
1084: if ($critnotification) {
1085: &Apache::lonnet::put('environment',{'critnotification' => $critnotification});
1.116 raeburn 1086: &Apache::lonnet::appenv({'environment.critnotification' => $critnotification});
1.180 wenzelju 1087: $message.=&Apache::lonhtmlcommon::confirm_success(&mt('Set critical message notification address(es) to ').'<tt>"'.$critnotification.'"</tt>.<br />');
1.20 www 1088: } else {
1089: &Apache::lonnet::del('environment',['critnotification']);
1.139 raeburn 1090: &Apache::lonnet::delenv('environment.critnotification');
1.180 wenzelju 1091: $message.=&Apache::lonhtmlcommon::confirm_success(&mt("Set critical message notification to 'off'.").'<br />');
1.102 raeburn 1092: }
1093: if ($critnotification || $notification) {
1094: if ($notify_with_html) {
1095: &Apache::lonnet::put('environment',{'notifywithhtml' => $notify_with_html});
1.116 raeburn 1096: &Apache::lonnet::appenv({'environment.notifywithhtml' => $notify_with_html});
1.180 wenzelju 1097: $message.=&Apache::lonhtmlcommon::confirm_success(&mt('Set address(es) to receive excerpts with html retained ').'<tt>"'.$notify_with_html.'"</tt>.');
1.102 raeburn 1098: } else {
1099: &Apache::lonnet::del('environment',['notifywithhtml']);
1.139 raeburn 1100: &Apache::lonnet::delenv('environment.notifywithhtml');
1.104 raeburn 1101: if ($totaladdresses == 1) {
1.180 wenzelju 1102: $message.=&Apache::lonhtmlcommon::confirm_success(&mt("Set notification address to receive excerpts with html stripped."));
1.104 raeburn 1103: } else {
1.180 wenzelju 1104: $message.=&Apache::lonhtmlcommon::confirm_success(&mt("Set all notification addresses to receive excerpts with html stripped."));
1.104 raeburn 1105: }
1.102 raeburn 1106: }
1107: } else {
1108: &Apache::lonnet::del('environment',['notifywithhtml']);
1.139 raeburn 1109: &Apache::lonnet::delenv('environment.notifywithhtml');
1.102 raeburn 1110: }
1.109 albertel 1111: &Apache::loncommon::flush_email_cache($user,$domain);
1.180 wenzelju 1112: $message=&Apache::loncommon::confirmwrapper($message);
1.102 raeburn 1113: &msgforwardchanger($r,$message);
1.6 www 1114: }
1115:
1.12 www 1116: ################################################################
1.19 www 1117: # Colors #
1.12 www 1118: ################################################################
1119:
1.19 www 1120: sub colorschanger {
1.12 www 1121: my $r = shift;
1.126 droeschl 1122: Apache::lonhtmlcommon::add_breadcrumb(
1123: { href => '/adm/preferences?action=changecolors',
1124: text => 'Change Colors'});
1.147 schafran 1125: $r->print(Apache::loncommon::start_page('Page Display Settings'));
1.126 droeschl 1126: $r->print(Apache::lonhtmlcommon::breadcrumbs('Change Colors'));
1.19 www 1127: # figure out colors
1.80 albertel 1128: my $function=&Apache::loncommon::get_users_function();
1.19 www 1129: my $domain=&Apache::loncommon::determinedomain();
1.157 bisitz 1130: my %colortypes=&Apache::lonlocal::texthash(
1131: 'pgbg' => 'Page Background Color',
1132: 'tabbg' => 'Header Background Color',
1133: 'sidebg' => 'Header Border Color',
1134: 'font' => 'Font Color',
1135: 'fontmenu' => 'Font Menu Color',
1136: 'link' => 'Un-Visited Link Color',
1137: 'vlink' => 'Visited Link Color',
1138: 'alink' => 'Active Link Color',
1139: );
1.82 albertel 1140: my $start_data_table = &Apache::loncommon::start_data_table();
1.19 www 1141: my $chtable='';
1.22 matthew 1142: foreach my $item (sort(keys(%colortypes))) {
1.19 www 1143: my $curcol=&Apache::loncommon::designparm($function.'.'.$item,$domain);
1.82 albertel 1144: $chtable.=&Apache::loncommon::start_data_table_row().
1.196.4.7 raeburn 1145: '<td>'.$colortypes{$item}.'<td><input name="'.$item.
1146: '" class="colorchooser" size="10" value="'.$curcol.
1147: '" /></td>'.
1148: &Apache::loncommon::end_data_table_row()."\n";
1.19 www 1149: }
1.82 albertel 1150: my $end_data_table = &Apache::loncommon::end_data_table();
1.23 matthew 1151: my $pjump_def = &Apache::lonhtmlcommon::pjump_javascript_definition();
1.157 bisitz 1152: my $savebutton = &mt('Save');
1153: my $resetbutton = &mt('Reset All');
1154: my $resetbuttondesc = &mt('Reset All Colors to Default');
1.196.4.7 raeburn 1155: my $colorchooser=&Apache::lonhtmlcommon::color_picker();
1.196.4.9 raeburn 1156: $r->print('<script type="text/javascript" language="JavaScript">
1.196.4.7 raeburn 1157: ' . $colorchooser . '
1158: </script>
1159: ');
1160: $r->print(<<ENDCOL);
1.19 www 1161:
1.196.4.12 raeburn 1162: <form name="parmform" action="">
1.21 www 1163: <input type="hidden" name="pres_marker" />
1164: <input type="hidden" name="pres_type" />
1165: <input type="hidden" name="pres_value" />
1166: </form>
1.88 albertel 1167: <form name="prefs" action="/adm/preferences" method="post">
1.19 www 1168: <input type="hidden" name="action" value="verify_and_change_colors" />
1.82 albertel 1169: $start_data_table
1.19 www 1170: $chtable
1.82 albertel 1171: $end_data_table
1.19 www 1172: </table>
1.157 bisitz 1173: <p>
1174: <input type="submit" value="$savebutton" />
1175: <input type="submit" name="resetall" value="$resetbutton" title="$resetbuttondesc" />
1176: </p>
1.12 www 1177: </form>
1.19 www 1178: ENDCOL
1.12 www 1179: }
1180:
1.19 www 1181: sub verify_and_change_colors {
1.12 www 1182: my $r = shift;
1.19 www 1183: # figure out colors
1.80 albertel 1184: my $function=&Apache::loncommon::get_users_function();
1.19 www 1185: my $domain=&Apache::loncommon::determinedomain();
1.157 bisitz 1186: my %colortypes=&Apache::lonlocal::texthash(
1187: 'pgbg' => 'Page Background Color',
1188: 'tabbg' => 'Header Background Color',
1189: 'sidebg' => 'Header Border Color',
1190: 'font' => 'Font Color',
1191: 'fontmenu' => 'Font Menu Color',
1192: 'link' => 'Un-Visited Link Color',
1193: 'vlink' => 'Visited Link Color',
1194: 'alink' => 'Active Link Color',
1195: );
1.19 www 1196:
1.12 www 1197: my $message='';
1.196.4.16 raeburn 1198: foreach my $item (keys(%colortypes)) {
1.59 albertel 1199: my $color=$env{'form.'.$item};
1.196.4.7 raeburn 1200: if (!($color =~ /^#/)) {
1201: $color = '#' . $color;
1202: }
1.21 www 1203: my $entry='color.'.$function.'.'.$item;
1.59 albertel 1204: if (($color=~/^\#[0-9A-Fa-f]{6}$/) && (!$env{'form.resetall'})) {
1.21 www 1205: &Apache::lonnet::put('environment',{$entry => $color});
1.116 raeburn 1206: &Apache::lonnet::appenv({'environment.'.$entry => $color});
1.157 bisitz 1207: $message.=&Apache::lonhtmlcommon::confirm_success(&mt('Set [_1] to [_2]','<i>'.$colortypes{$item}.'</i>','<tt>"'.$color.'"</tt>'))
1208: .'<br />';
1.21 www 1209: } else {
1210: &Apache::lonnet::del('environment',[$entry]);
1.138 schafran 1211: &Apache::lonnet::delenv('environment.'.$entry);
1.157 bisitz 1212: $message.=&Apache::lonhtmlcommon::confirm_success(&mt('Reset [_1]','<i>'.$colortypes{$item}.'</i>'))
1213: .'<br />';
1.21 www 1214: }
1215: }
1.158 bisitz 1216: $message=&Apache::loncommon::confirmwrapper($message);
1.157 bisitz 1217:
1.84 albertel 1218: my $now = time;
1219: &Apache::lonnet::put('environment',{'color.timestamp' => $now});
1.116 raeburn 1220: &Apache::lonnet::appenv({'environment.color.timestamp' => $now});
1.84 albertel 1221:
1.152 www 1222: &print_main_menu($r, $message);
1.12 www 1223: }
1224:
1.4 matthew 1225: ######################################################
1226: # password handler subroutines #
1227: ######################################################
1.3 matthew 1228: sub passwordchanger {
1.196.4.25 raeburn 1229: my ($r,$errormessage,$caller,$mailtoken,$timelimit,$extrafields) = @_;
1.4 matthew 1230: # This function is a bit of a mess....
1.3 matthew 1231: # Passwords are encrypted using londes.js (DES encryption)
1.4 matthew 1232: $errormessage = ($errormessage || '');
1.196.4.28 raeburn 1233: my ($user,$domain,$currentpass,$clientip);
1234: $clientip = &Apache::lonnet::get_requestor_ip($r);
1.152 www 1235: &Apache::lonhtmlcommon::add_breadcrumb(
1.126 droeschl 1236: { href => '/adm/preferences?action=changepass',
1237: text => 'Change Password'});
1.144 raeburn 1238: unless ($caller eq 'reset_by_email') {
1.147 schafran 1239: $r->print(Apache::loncommon::start_page('Personal Data'));
1.144 raeburn 1240: $r->print(Apache::lonhtmlcommon::breadcrumbs('Change Password'));
1241: }
1.94 raeburn 1242: if ((!defined($caller)) || ($caller eq 'preferences')) {
1243: $user = $env{'user.name'};
1244: $domain = $env{'user.domain'};
1245: if (!defined($caller)) {
1246: $caller = 'preferences';
1247: }
1.196.4.26 raeburn 1248: my ($blocked,$blocktext) =
1.196.4.28 raeburn 1249: &Apache::loncommon::blocking_status('passwd',$clientip);
1.196.4.26 raeburn 1250: if ($blocked) {
1251: $r->print('<p class="LC_warning">'.$blocktext.'</p>');
1252: return;
1253: }
1.94 raeburn 1254: } elsif ($caller eq 'reset_by_email') {
1.196.4.25 raeburn 1255: my %data = &Apache::lonnet::tmpget($mailtoken);
1256: if (keys(%data) == 0) {
1257: $r->print(
1258: '<p class="LC_warning">'
1259: .&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.'
1260: ,'<a href="/adm/resetpw">','</a>')
1261: .'</p>'
1262: );
1263: return;
1264: }
1265: if (defined($data{time})) {
1266: if (time - $data{'time'} < $timelimit) {
1267: $user = $data{'username'};
1268: $domain = $data{'domain'};
1269: $currentpass = $data{'temppasswd'};
1.196.4.26 raeburn 1270: my ($blocked,$blocktext) =
1.196.4.28 raeburn 1271: &Apache::loncommon::blocking_status('passwd',$clientip,$user,$domain);
1.196.4.26 raeburn 1272: if ($blocked) {
1273: $r->print('<p class="LC_warning">'.$blocktext.'</p>');
1274: return;
1275: }
1.94 raeburn 1276: } else {
1.196.4.6 raeburn 1277: $r->print(
1.196.4.25 raeburn 1278: '<p class="LC_warning">'
1279: .&mt('Sorry, the token generated when you requested'
1280: .' a password reset has expired.')
1.196.4.6 raeburn 1281: .'</p>'
1282: );
1.94 raeburn 1283: return;
1284: }
1.196.4.25 raeburn 1285: } else {
1286: $r->print(
1287: '<p class="LC_warning">'
1288: .&mt('Sorry, the URL generated when you requested reset of'
1289: .' your password contained incomplete information.')
1290: .'</p>'
1291: );
1292: return;
1293: }
1294: if (&Apache::lonnet::domain($domain) eq '') {
1295: $domain = $r->dir_config('lonDefDomain');
1296: }
1.193 raeburn 1297: } else {
1.196.4.6 raeburn 1298: $r->print(
1299: '<p class="LC_error">'
1300: .&mt('Page requested in unexpected context')
1301: .'</p>'
1302: );
1.94 raeburn 1303: return;
1304: }
1.3 matthew 1305: my $currentauth=&Apache::lonnet::queryauthenticate($user,$domain);
1306: # Check for authentication types that allow changing of the password.
1307: return if ($currentauth !~ /^(unix|internal):/);
1308: #
1309: # Generate keys
1.196.4.14 raeburn 1310: my ($lkey_cpass ,$ukey_cpass ) = &Apache::loncommon::des_keys();
1311: my ($lkey_npass1,$ukey_npass1) = &Apache::loncommon::des_keys();
1312: my ($lkey_npass2,$ukey_npass2) = &Apache::loncommon::des_keys();
1.4 matthew 1313: # Store the keys in the log files
1.3 matthew 1314: my $lonhost = $r->dir_config('lonHostID');
1315: my $logtoken=Apache::lonnet::reply('tmpput:'
1316: .$ukey_cpass . $lkey_cpass .'&'
1317: .$ukey_npass1 . $lkey_npass1.'&'
1318: .$ukey_npass2 . $lkey_npass2,
1319: $lonhost);
1.4 matthew 1320: # Hexify the keys for output as javascript variables
1.94 raeburn 1321: my %hexkey;
1322: $hexkey{'ukey_cpass'} = hex($ukey_cpass);
1323: $hexkey{'lkey_cpass'} = hex($lkey_cpass);
1324: $hexkey{'ukey_npass1'} = hex($ukey_npass1);
1325: $hexkey{'lkey_npass1'} = hex($lkey_npass1);
1326: $hexkey{'ukey_npass2'} = hex($ukey_npass2);
1327: $hexkey{'lkey_npass2'} = hex($lkey_npass2);
1.3 matthew 1328: # Output javascript to deal with passwords
1.4 matthew 1329: # Output DES javascript
1.3 matthew 1330: {
1331: my $include = $r->dir_config('lonIncludes');
1332: my $jsh=Apache::File->new($include."/londes.js");
1333: $r->print(<$jsh>);
1334: }
1.196.4.26 raeburn 1335: $r->print(&jscript_send($caller,$domain,$currentauth,$extrafields));
1.3 matthew 1336: $r->print(<<ENDFORM);
1.94 raeburn 1337: $errormessage
1338:
1339: <p>
1340: <!-- We separate the forms into 'server' and 'client' in order to
1341: ensure that unencrypted passwords will not be sent out by a
1342: crappy browser -->
1343: ENDFORM
1.196.4.25 raeburn 1344: $r->print(&server_form($logtoken,$caller,$mailtoken,$extrafields));
1345: $r->print(&client_form($caller,\%hexkey,$currentpass,$domain,$extrafields));
1.94 raeburn 1346:
1347: #
1348: return;
1349: }
1350:
1351: sub jscript_send {
1.196.4.26 raeburn 1352: my ($caller,$domain,$currentauth,$extrafields) = @_;
1353: my ($min,$max,$rulestr,$numrules);
1354: $min = $Apache::lonnet::passwdmin;
1355: my %js_lt = &Apache::lonlocal::texthash(
1356: uc => 'New password needs at least one upper case letter',
1357: lc => 'New password needs at least one lower case letter',
1358: num => 'New password needs at least one number',
1359: spec => 'New password needs at least one non-alphanumeric',
1360: blank1 => 'Empty Password field',
1361: blank2 => 'Empty Confirm Password field',
1362: mismatch => 'Contents of Password and Confirm Password fields must match',
1363: fail => 'Please fix the following:',
1364: );
1365: &js_escape(\%js_lt);
1366: if ($currentauth eq 'internal:') {
1367: if ($domain ne '') {
1368: my %passwdconf = &Apache::lonnet::get_passwdconf($domain);
1369: if (keys(%passwdconf)) {
1370: if ($passwdconf{min}) {
1371: $min = $passwdconf{min};
1372: }
1373: if ($passwdconf{max}) {
1374: $max = $passwdconf{max};
1375: $js_lt{'long'} = &js_escape(&mt('Maximum password length: [_1]',$max));
1376: }
1377: if (ref($passwdconf{chars}) eq 'ARRAY') {
1378: if (@{$passwdconf{chars}}) {
1379: $rulestr = join('","',@{$passwdconf{chars}});
1380: $numrules = scalar(@{$passwdconf{chars}});
1381: }
1382: }
1383: }
1384: }
1385: }
1386: $js_lt{'short'} = &js_escape(&mt('Minimum password length: [_1]',$min));
1387:
1388: my $passwdcheck = <<"ENDJS";
1389: var errors = new Array();
1390: var min = parseInt("$min") || 0;
1391: var currauth = "$currentauth";
1392: if (this.document.client.elements.newpass_1.value == '') {
1393: errors.push("$js_lt{'blank1'}");
1394: }
1395: if (this.document.client.elements.newpass_2.value == '') {
1396: errors.push("$js_lt{'blank2'}");
1397: }
1398: if (errors.length == 0) {
1399: if (this.document.client.elements.newpass_1.value != this.document.client.elements.newpass_2.value) {
1400: errors.push("$js_lt{'mismatch'}");
1401: }
1402: var posspass = this.document.client.elements.newpass_1.value;
1403: if (min > 0) {
1404: if (posspass.length < min) {
1405: errors.push("$js_lt{'short'}");
1406: }
1407: }
1408: if (currauth == 'internal:') {
1409: var max = parseInt("$max") || 0;
1410: if (max > 0) {
1411: if (posspass.length > max) {
1412: errors.push("$js_lt{'long'}");
1413: }
1414: }
1415: var numrules = parseInt("$numrules") || 0;
1416: if (numrules > 0) {
1417: var rules = new Array("$rulestr");
1418: for (var i=0; i<rules.length; i++) {
1419: if (rules[i] == 'uc') {
1420: if (!posspass.match(/[A-Z]/)) {
1421: errors.push("$js_lt{'uc'}");
1422: }
1423: } else if (rules[i] == 'lc') {
1424: if (!posspass.match(/[a-z]/)) {
1425: errors.push("$js_lt{'lc'}");
1426: }
1427: } else if (rules[i] == 'num') {
1428: if (!posspass.match(/\\d/)) {
1429: errors.push("$js_lt{'num'}");
1430: }
1431: } else if (rules[i] == 'spec') {
1432: var pattern = /^[!@#$%^&*()_+\\-=\\[\\]{};':"\\\|,.<a>\\/?]/;
1433: if (!posspass.match(pattern)) {
1434: errors.push("$js_lt{'spec'}");
1435: }
1436: }
1437: }
1438: }
1439: }
1440: }
1441: if (errors.length > 0) {
1442: alert("$js_lt{'fail'}"+"\\n\\n"+errors.join("\\n"));
1443: return;
1444: }
1445: ENDJS
1.94 raeburn 1446: my $output = qq|
1.148 bisitz 1447: <script type="text/javascript" language="JavaScript">
1.3 matthew 1448:
1449: function send() {
1.196.4.26 raeburn 1450: $passwdcheck
1.3 matthew 1451: uextkey=this.document.client.elements.ukey_cpass.value;
1452: lextkey=this.document.client.elements.lkey_cpass.value;
1453: initkeys();
1.196.4.19 raeburn 1454: this.document.pserver.elements.currentpass.value =
1455: getCrypted(this.document.client.elements.currentpass.value);
1.3 matthew 1456: uextkey=this.document.client.elements.ukey_npass1.value;
1457: lextkey=this.document.client.elements.lkey_npass1.value;
1458: initkeys();
1.52 raeburn 1459: this.document.pserver.elements.newpass_1.value
1.196.4.19 raeburn 1460: =getCrypted(this.document.client.elements.newpass_1.value);
1.3 matthew 1461: uextkey=this.document.client.elements.ukey_npass2.value;
1462: lextkey=this.document.client.elements.lkey_npass2.value;
1463: initkeys();
1.52 raeburn 1464: this.document.pserver.elements.newpass_2.value
1.196.4.19 raeburn 1465: =getCrypted(this.document.client.elements.newpass_2.value);
1.94 raeburn 1466: |;
1467: if ($caller eq 'reset_by_email') {
1.196.4.25 raeburn 1468: if ((ref($extrafields) eq 'HASH') && ($extrafields->{'username'})) {
1469: $output .= qq|
1.94 raeburn 1470: this.document.pserver.elements.uname.value =
1471: this.document.client.elements.uname.value;
1472: this.document.pserver.elements.udom.value =
1473: this.document.client.elements.udom.options[this.document.client.elements.udom.selectedIndex].value;
1.196.4.25 raeburn 1474: |;
1475: }
1476: if ((ref($extrafields) eq 'HASH') && ($extrafields->{'email'})) {
1477: $output .= qq|
1.173 raeburn 1478: this.document.pserver.elements.email.value =
1479: this.document.client.elements.email.value;
1.94 raeburn 1480: |;
1.196.4.25 raeburn 1481: }
1.94 raeburn 1482: }
1483: $ output .= qq|
1.52 raeburn 1484: this.document.pserver.submit();
1.3 matthew 1485: }
1.196.4.19 raeburn 1486:
1.3 matthew 1487: </script>
1.94 raeburn 1488: |;
1489: }
1.3 matthew 1490:
1.94 raeburn 1491: sub client_form {
1.196.4.25 raeburn 1492: my ($caller,$hexkey,$currentpass,$defdom,$extrafields) = @_;
1.99 www 1493: my %lt=&Apache::lonlocal::texthash(
1.115 raeburn 1494: 'email' => 'E-mail Address',
1.99 www 1495: 'username' => 'Username',
1496: 'domain' => 'Domain',
1497: 'currentpass' => 'Current Password',
1498: 'newpass' => 'New Password',
1499: 'confirmpass' => 'Confirm Password',
1.169 raeburn 1500: 'changepass' => 'Save',
1501: );
1.99 www 1502:
1.196.4.12 raeburn 1503: my $output = '<form name="client" action="">'
1.164 bisitz 1504: .&Apache::lonhtmlcommon::start_pick_box();
1.94 raeburn 1505: if ($caller eq 'reset_by_email') {
1.196.4.25 raeburn 1506: if ((ref($extrafields) eq 'HASH') && ($extrafields->{'email'})) {
1507: $output .= &Apache::lonhtmlcommon::row_title(
1.164 bisitz 1508: '<label for="email">'.$lt{'email'}.'</label>')
1.196.4.25 raeburn 1509: .'<input type="text" name="email" size="30" autocapitalize="off" autocorrect="off" />'
1510: .&Apache::lonhtmlcommon::row_closure();
1511: }
1512: if ((ref($extrafields) eq 'HASH') && ($extrafields->{'username'})) {
1513: $output .= &Apache::lonhtmlcommon::row_title(
1.164 bisitz 1514: '<label for="uname">'.$lt{'username'}.'</label>')
1.196.4.25 raeburn 1515: .'<input type="text" name="uname" size="20" autocapitalize="off" autocorrect="off" />'
1516: .&Apache::lonhtmlcommon::row_closure()
1517: .&Apache::lonhtmlcommon::row_title(
1.164 bisitz 1518: '<label for="udom">'.$lt{'domain'}.'</label>')
1.196.4.25 raeburn 1519: .&Apache::loncommon::select_dom_form($defdom,'udom')
1520: .&Apache::lonhtmlcommon::row_closure();
1521: }
1.94 raeburn 1522: } else {
1.164 bisitz 1523: $output .= &Apache::lonhtmlcommon::row_title(
1524: '<label for="currentpass">'.$lt{'currentpass'}.'</label>')
1.196.4.19 raeburn 1525: .'<input type="password" name="currentpass" size="20"/>'
1.164 bisitz 1526: .&Apache::lonhtmlcommon::row_closure();
1527: }
1528: $output .= &Apache::lonhtmlcommon::row_title(
1529: '<label for="newpass_1">'.$lt{'newpass'}.'</label>')
1.196.4.19 raeburn 1530: .'<input type="password" name="newpass_1" size="20" />'
1.164 bisitz 1531: .&Apache::lonhtmlcommon::row_closure()
1532: .&Apache::lonhtmlcommon::row_title(
1533: '<label for="newpass_2">'.$lt{'confirmpass'}.'</label>')
1.196.4.19 raeburn 1534: .'<input type="password" name="newpass_2" size="20" />'
1.164 bisitz 1535: .&Apache::lonhtmlcommon::row_closure(1)
1536: .&Apache::lonhtmlcommon::end_pick_box();
1.196.4.25 raeburn 1537: if ($caller eq 'reset_by_email') {
1538: $output .= '<input type="hidden" name="currentpass" value="'.$currentpass.'" />';
1539: }
1.196.4.12 raeburn 1540: $output .= '<p><input type="button" value="'.$lt{'changepass'}.'" onclick="send();" /></p>'
1.164 bisitz 1541: .qq|
1.94 raeburn 1542: <input type="hidden" name="ukey_cpass" value="$hexkey->{'ukey_cpass'}" />
1543: <input type="hidden" name="lkey_cpass" value="$hexkey->{'lkey_cpass'}" />
1544: <input type="hidden" name="ukey_npass1" value="$hexkey->{'ukey_npass1'}" />
1545: <input type="hidden" name="lkey_npass1" value="$hexkey->{'lkey_npass1'}" />
1546: <input type="hidden" name="ukey_npass2" value="$hexkey->{'ukey_npass2'}" />
1547: <input type="hidden" name="lkey_npass2" value="$hexkey->{'lkey_npass2'}" />
1.3 matthew 1548: </form>
1549: </p>
1.164 bisitz 1550: |;
1.94 raeburn 1551: return $output;
1552: }
1553:
1554: sub server_form {
1.196.4.25 raeburn 1555: my ($logtoken,$caller,$mailtoken,$extrafields) = @_;
1.94 raeburn 1556: my $action = '/adm/preferences';
1557: if ($caller eq 'reset_by_email') {
1558: $action = '/adm/resetpw';
1559: }
1560: my $output = qq|
1561: <form name="pserver" action="$action" method="post">
1562: <input type="hidden" name="logtoken" value="$logtoken" />
1563: <input type="hidden" name="currentpass" value="" />
1564: <input type="hidden" name="newpass_1" value="" />
1565: <input type="hidden" name="newpass_2" value="" />
1.196.4.25 raeburn 1566: |;
1.94 raeburn 1567: if ($caller eq 'reset_by_email') {
1568: $output .= qq|
1569: <input type="hidden" name="token" value="$mailtoken" />
1.196.4.25 raeburn 1570: |;
1571: if ((ref($extrafields) eq 'HASH') && ($extrafields->{'username'})) {
1572: $output .= qq|
1.94 raeburn 1573: <input type="hidden" name="uname" value="" />
1574: <input type="hidden" name="udom" value="" />
1.196.4.25 raeburn 1575: |;
1576: }
1577: if ((ref($extrafields) eq 'HASH') && ($extrafields->{'email'})) {
1578: $output .= qq|
1.173 raeburn 1579: <input type="hidden" name="email" value="" />
1.94 raeburn 1580: |;
1.196.4.25 raeburn 1581: }
1.94 raeburn 1582: }
1583: $output .= qq|
1584: <input type="hidden" name="action" value="verify_and_change_pass" />
1585: </form>
1586: |;
1587: return $output;
1.3 matthew 1588: }
1589:
1590: sub verify_and_change_password {
1.196.4.26 raeburn 1591: my ($r,$caller,$mailtoken,$timelimit,$extrafields,$ended) = @_;
1.196.4.28 raeburn 1592: my ($user,$domain,$homeserver,$clientip);
1.94 raeburn 1593: if ($caller eq 'reset_by_email') {
1594: $user = $env{'form.uname'};
1595: $domain = $env{'form.udom'};
1596: if ($user ne '' && $domain ne '') {
1597: $homeserver = &Apache::lonnet::homeserver($user,$domain);
1598: if ($homeserver eq 'no_host') {
1.99 www 1599: &passwordchanger($r,"<p>\n<span class='LC_error'>".
1600: &mt("Invalid username and/or domain")."</span>\n</p>",
1.196.4.26 raeburn 1601: $caller,$mailtoken,$timelimit,$extrafields);
1602: return 'no_host';
1.94 raeburn 1603: }
1604: } else {
1.99 www 1605: &passwordchanger($r,"<p>\n<span class='LC_error'>".
1606: &mt("Username and domain were blank")."</span>\n</p>",
1.196.4.26 raeburn 1607: $caller,$mailtoken,$timelimit,$extrafields);
1608: return 'missingdata';
1.94 raeburn 1609: }
1610: } else {
1611: $user = $env{'user.name'};
1612: $domain = $env{'user.domain'};
1613: $homeserver = $env{'user.home'};
1614: }
1.196.4.28 raeburn 1615: $clientip = &Apache::lonnet::get_requestor_ip($r);
1.196.4.26 raeburn 1616: my ($blocked,$blocktext) =
1.196.4.28 raeburn 1617: &Apache::loncommon::blocking_status('passwd',$clientip,$user,$domain);
1.196.4.26 raeburn 1618: if ($blocked) {
1619: $r->print('<p class="LC_warning">'.$blocktext.'</p>');
1620: if ($caller eq 'reset_by_email') {
1621: return 'blocked';
1622: } else {
1623: return;
1624: }
1625: }
1.3 matthew 1626: my $currentauth=&Apache::lonnet::queryauthenticate($user,$domain);
1.4 matthew 1627: # Check for authentication types that allow changing of the password.
1.94 raeburn 1628: if ($currentauth !~ /^(unix|internal):/) {
1629: if ($caller eq 'reset_by_email') {
1.99 www 1630: &passwordchanger($r,"<p>\n<span class='LC_error'>".
1631: &mt("Authentication type for this user can not be changed by this mechanism").
1632: "</span>\n</p>",
1.196.4.26 raeburn 1633: $caller,$mailtoken,$timelimit,$extrafields);
1634: return 'otherauth';
1.94 raeburn 1635: } else {
1636: return;
1637: }
1638: }
1.3 matthew 1639: #
1.59 albertel 1640: my $currentpass = $env{'form.currentpass'};
1641: my $newpass1 = $env{'form.newpass_1'};
1642: my $newpass2 = $env{'form.newpass_2'};
1643: my $logtoken = $env{'form.logtoken'};
1.3 matthew 1644: # Check for empty data
1.4 matthew 1645: unless (defined($currentpass) &&
1646: defined($newpass1) &&
1647: defined($newpass2) ){
1.99 www 1648: &passwordchanger($r,"<p>\n<span class='LC_error'>".
1649: &mt("One or more password fields were blank").
1.196.4.26 raeburn 1650: "</span>\n</p>",$caller,$mailtoken,$timelimit,$extrafields);
1651: if ($caller eq 'reset_by_email') {
1652: return 'missingdata';
1653: } else {
1654: return;
1655: }
1.3 matthew 1656: }
1.16 albertel 1657: # Get the keys
1658: my $lonhost = $r->dir_config('lonHostID');
1.3 matthew 1659: my $tmpinfo = Apache::lonnet::reply('tmpget:'.$logtoken,$lonhost);
1660: if (($tmpinfo=~/^error/) || ($tmpinfo eq 'con_lost')) {
1.4 matthew 1661: # I do not a have a better idea about how to handle this
1.94 raeburn 1662: my $tryagain_text = &mt('Please log out and try again.');
1663: if ($caller eq 'reset_by_email') {
1664: $tryagain_text = &mt('Please try again later.');
1665: }
1.101 albertel 1666: my $unable=&mt("Unable to retrieve saved token for password decryption");
1.3 matthew 1667: $r->print(<<ENDERROR);
1668: <p>
1.99 www 1669: <span class="LC_error">$unable. $tryagain_text</span>
1.3 matthew 1670: </p>
1671: ENDERROR
1.4 matthew 1672: # Probably should log an error here
1.196.4.26 raeburn 1673: if ($caller eq 'reset_by_email') {
1674: return 'internalerror';
1675: } else {
1676: return;
1677: }
1.3 matthew 1678: }
1679: my ($ckey,$n1key,$n2key)=split(/&/,$tmpinfo);
1.196.4.25 raeburn 1680: #
1.196.4.14 raeburn 1681: $currentpass = &Apache::loncommon::des_decrypt($ckey ,$currentpass);
1682: $newpass1 = &Apache::loncommon::des_decrypt($n1key,$newpass1);
1683: $newpass2 = &Apache::loncommon::des_decrypt($n2key,$newpass2);
1.94 raeburn 1684: #
1685: if ($caller eq 'reset_by_email') {
1686: my %data = &Apache::lonnet::tmpget($mailtoken);
1.117 raeburn 1687: if (keys(%data) == 0) {
1688: &passwordchanger($r,
1689: '<span class="LC_error">'.
1690: &mt('Could not verify current authentication.').' '.
1.196.4.26 raeburn 1691: &mt('Please try again.').'</span>',$caller,$mailtoken,$timelimit,$extrafields);
1692: return 'emptydata';
1.117 raeburn 1693: }
1.94 raeburn 1694: if ($currentpass ne $data{'temppasswd'}) {
1695: &passwordchanger($r,
1.99 www 1696: '<span class="LC_error">'.
1.110 bisitz 1697: &mt('Could not verify current authentication.').' '.
1.196.4.26 raeburn 1698: &mt('Please try again.').'</span>',$caller,$mailtoken,$timelimit,$extrafields);
1699: return 'missingtemp';
1.94 raeburn 1700: }
1.196.4.25 raeburn 1701: }
1.3 matthew 1702: if ($newpass1 ne $newpass2) {
1.4 matthew 1703: &passwordchanger($r,
1.196.4.6 raeburn 1704: '<span class="LC_warning">'.
1.110 bisitz 1705: &mt('The new passwords you entered do not match.').' '.
1.196.4.26 raeburn 1706: &mt('Please try again.').'</span>',$caller,$mailtoken,$timelimit,$extrafields);
1707: if ($caller eq 'reset_by_email') {
1708: return 'mismatch';
1709: } else {
1710: return;
1711: }
1.4 matthew 1712: }
1.196.4.25 raeburn 1713: if ($currentauth eq 'unix:') {
1714: if (length($newpass1) < 7) {
1715: &passwordchanger($r,
1716: '<span class="LC_warning">'.
1717: &mt('Passwords must be a minimum of 7 characters long.').' '.
1.196.4.26 raeburn 1718: &mt('Please try again.').'</span>',$caller,$mailtoken,$timelimit,$extrafields);
1719: if ($caller eq 'reset_by_email') {
1720: return 'length';
1721: } else {
1722: return;
1723: }
1.196.4.25 raeburn 1724: }
1725: } else {
1726: my $warning = &Apache::loncommon::check_passwd_rules($domain,$newpass1);
1727: if ($warning) {
1728: &passwordchanger($r,'<span class="LC_warning">'.
1729: $warning.
1730: &mt('Please try again.').'</span>',
1.196.4.26 raeburn 1731: $caller,$mailtoken,$timelimit,$extrafields);
1732: if ($caller eq 'reset_by_email') {
1733: return 'rules';
1734: } else {
1735: return;
1736: }
1.196.4.25 raeburn 1737: }
1.3 matthew 1738: }
1.4 matthew 1739: #
1740: # Check for bad characters
1741: my $badpassword = 0;
1742: foreach (split(//,$newpass1)) {
1743: $badpassword = 1 if ((ord($_)<32)||(ord($_)>126));
1744: }
1745: if ($badpassword) {
1746: # I can't figure out how to enter bad characters on my browser.
1.196.4.6 raeburn 1747: my $errormessage ='<span class="LC_warning">'.
1.110 bisitz 1748: &mt('The password you entered contained illegal characters.').'<br />'.
1.99 www 1749: &mt('Valid characters are').(<<"ENDERROR");
1750: : space and <br />
1.4 matthew 1751: <pre>
1752: !"\#$%&\'()*+,-./0123456789:;<=>?\@
1753: ABCDEFGHIJKLMNOPQRSTUVWXYZ[\]^_\`abcdefghijklmnopqrstuvwxyz{|}~
1.99 www 1754: </pre></span>
1.4 matthew 1755: ENDERROR
1.196.4.26 raeburn 1756: &passwordchanger($r,$errormessage,$caller,$mailtoken,$timelimit,$extrafields);
1757: if ($caller eq 'reset_by_email') {
1758: return 'badchars';
1759: } else {
1760: return;
1761: }
1.4 matthew 1762: }
1763: #
1764: # Change the password (finally)
1765: my $result = &Apache::lonnet::changepass
1.94 raeburn 1766: ($user,$domain,$currentpass,$newpass1,$homeserver,$caller);
1.4 matthew 1767: # Inform the user the password has (not?) been changed
1.126 droeschl 1768: my $message;
1.4 matthew 1769: if ($result =~ /^ok$/) {
1.170 bisitz 1770: $message = &Apache::lonhtmlcommon::confirm_success(&mt('The password for user [_1] was successfully changed.','<i>'.$user.'</i>'));
1.180 wenzelju 1771: $message = &Apache::loncommon::confirmwrapper($message);
1.144 raeburn 1772: if ($caller eq 'reset_by_email') {
1773: $r->print($message.'<br />');
1774: } else {
1775: &print_main_menu($r, $message);
1.196.4.24 raeburn 1776: if (ref($ended)) {
1777: $$ended = 1;
1778: }
1.144 raeburn 1779: }
1.4 matthew 1780: } else {
1781: # error error: run in circles, scream and shout
1.173 raeburn 1782: if ($caller eq 'reset_by_email') {
1783: if (!$result) {
1.196.4.26 raeburn 1784: return 'error';
1.173 raeburn 1785: } else {
1786: return $result;
1787: }
1788: } else {
1.196.4.25 raeburn 1789: my $feedback;
1790: if ($result eq 'prioruse') {
1791: $feedback = &mt('Please enter a password that you have not used recently.');
1792: } else {
1793: $feedback = &mt('Please make sure your old password was entered correctly.');
1794: }
1.173 raeburn 1795: $message = &Apache::lonhtmlcommon::confirm_success(
1.196.4.25 raeburn 1796: &mt("The password for user [_1] was not changed.",'<i>'.$user.'</i>').' '.$feedback,1);
1.158 bisitz 1797: $message=&Apache::loncommon::confirmwrapper($message);
1.144 raeburn 1798: &print_main_menu($r, $message);
1.196.4.24 raeburn 1799: if (ref($ended)) {
1800: $$ended = 1;
1801: }
1.144 raeburn 1802: }
1.4 matthew 1803: }
1804: return;
1.3 matthew 1805: }
1806:
1.42 raeburn 1807: ################################################################
1808: # discussion display subroutines
1809: ################################################################
1810: sub discussionchanger {
1811: my $r = shift;
1.126 droeschl 1812: Apache::lonhtmlcommon::add_breadcrumb(
1813: { href => '/adm/preferences?action=changediscussions',
1814: text => 'Change Discussion Preferences'});
1.178 bisitz 1815: $r->print(Apache::loncommon::start_page('Change Discussion Preferences'));
1.126 droeschl 1816: $r->print(Apache::lonhtmlcommon::breadcrumbs('Change Discussion Preferences'));
1.59 albertel 1817: my $user = $env{'user.name'};
1818: my $domain = $env{'user.domain'};
1.42 raeburn 1819: my %userenv = &Apache::lonnet::get
1.43 raeburn 1820: ('environment',['discdisplay','discmarkread']);
1821: my $discdisp = 'allposts';
1822: my $discmark = 'onmark';
1823:
1824: if (defined($userenv{'discdisplay'})) {
1825: unless ($userenv{'discdisplay'} eq '') {
1826: $discdisp = $userenv{'discdisplay'};
1827: }
1828: }
1829: if (defined($userenv{'discmarkread'})) {
1.171 raeburn 1830: unless ($userenv{'discmarkread'} eq '') {
1.43 raeburn 1831: $discmark = $userenv{'discmarkread'};
1832: }
1833: }
1834:
1835: my $newdisp = 'unread';
1836: my $newmark = 'ondisp';
1837:
1838: my $function = &Apache::loncommon::get_users_function();
1839: my $color = &Apache::loncommon::designparm($function.'.tabbg',
1.59 albertel 1840: $env{'user.domain'});
1.43 raeburn 1841: my %lt = &Apache::lonlocal::texthash(
1842: 'pref' => 'Display Preference',
1843: 'curr' => 'Current setting ',
1844: 'actn' => 'Action',
1.135 schafran 1845: 'sdpf' => 'Set display preferences for discussion posts for both discussion boards and individual resources in all your courses.',
1.43 raeburn 1846: 'prca' => 'Preferences can be set that determine',
1.135 schafran 1847: 'whpo' => 'Which posts are displayed when you display a discussion board or resource, and',
1.194 raeburn 1848: 'unwh' => 'Under what circumstances posts are identified as "NEW"',
1.43 raeburn 1849: 'allposts' => 'All posts',
1850: 'unread' => 'New posts only',
1851: 'ondisp' => 'Once displayed',
1.194 raeburn 1852: 'onmark' => 'Once marked not NEW',
1.43 raeburn 1853: 'disa' => 'Posts displayed?',
1.194 raeburn 1854: 'npmr' => 'New posts cease to be identified as "NEW"?',
1.43 raeburn 1855: 'thde' => 'The preferences you set here can be overridden within each individual discussion.',
1856: 'chgt' => 'Change to '
1857: );
1858: my $dispchange = $lt{'unread'};
1859: my $markchange = $lt{'ondisp'};
1860: my $currdisp = $lt{'allposts'};
1861: my $currmark = $lt{'onmark'};
1862:
1863: if ($discdisp eq 'unread') {
1864: $dispchange = $lt{'allposts'};
1865: $currdisp = $lt{'unread'};
1866: $newdisp = 'allposts';
1867: }
1868:
1869: if ($discmark eq 'ondisp') {
1870: $markchange = $lt{'onmark'};
1871: $currmark = $lt{'ondisp'};
1872: $newmark = 'onmark';
1.42 raeburn 1873: }
1.171 raeburn 1874:
1.43 raeburn 1875: $r->print(<<"END");
1.88 albertel 1876: <form name="prefs" action="/adm/preferences" method="post">
1.42 raeburn 1877: <input type="hidden" name="action" value="verify_and_change_discussion" />
1878: <br />
1.87 albertel 1879: $lt{'sdpf'}<br /> $lt{'prca'} <ol><li>$lt{'whpo'}</li><li>$lt{'unwh'}</li></ol>
1.82 albertel 1880: END
1.158 bisitz 1881:
1882: $r->print('<p class="LC_info">'.$lt{'thde'}.'</p>');
1883:
1.82 albertel 1884: $r->print(&Apache::loncommon::start_data_table());
1885: $r->print(<<"END");
1886: <tr>
1887: <th>$lt{'pref'}</th>
1888: <th>$lt{'curr'}</th>
1889: <th>$lt{'actn'}?</th>
1.43 raeburn 1890: </tr>
1.82 albertel 1891: END
1892: $r->print(&Apache::loncommon::start_data_table_row());
1893: $r->print(<<"END");
1.43 raeburn 1894: <td>$lt{'disa'}</td>
1895: <td>$lt{$discdisp}</td>
1.82 albertel 1896: <td><label><input type="checkbox" name="discdisp" /><input type="hidden" name="newdisp" value="$newdisp" /> $lt{'chgt'} "$dispchange"</label></td>
1897: END
1898: $r->print(&Apache::loncommon::end_data_table_row().
1899: &Apache::loncommon::start_data_table_row());
1900: $r->print(<<"END");
1.43 raeburn 1901: <td>$lt{'npmr'}</td>
1902: <td>$lt{$discmark}</td>
1.82 albertel 1903: <td><label><input type="checkbox" name="discmark" /><input type="hidden" name="newmark" value="$newmark" /> $lt{'chgt'} "$markchange"</label></td>
1.43 raeburn 1904: </tr>
1.82 albertel 1905: END
1906: $r->print(&Apache::loncommon::end_data_table_row().
1907: &Apache::loncommon::end_data_table());
1.142 zhu 1908:
1.158 bisitz 1909: $r->print('<br />'
1910: .'<input type="submit" name="sub" value="'.&mt('Save').'" />'
1911: .'</form>'
1912: );
1.42 raeburn 1913: }
1914:
1915: sub verify_and_change_discussion {
1916: my $r = shift;
1.59 albertel 1917: my $user = $env{'user.name'};
1918: my $domain = $env{'user.domain'};
1.42 raeburn 1919: my $message='';
1.59 albertel 1920: if (defined($env{'form.discdisp'}) ) {
1921: my $newdisp = $env{'form.newdisp'};
1.43 raeburn 1922: if ($newdisp eq 'unread') {
1.171 raeburn 1923: $message .=&Apache::lonhtmlcommon::confirm_success(&mt('In discussions: only new posts will be displayed.')).'<br />';
1.43 raeburn 1924: &Apache::lonnet::put('environment',{'discdisplay' => $newdisp});
1.116 raeburn 1925: &Apache::lonnet::appenv({'environment.discdisplay' => $newdisp});
1.43 raeburn 1926: } else {
1.171 raeburn 1927: $message .= &Apache::lonhtmlcommon::confirm_success(&mt('In discussions: all posts will be displayed.')).'<br />';
1.43 raeburn 1928: &Apache::lonnet::del('environment',['discdisplay']);
1.139 raeburn 1929: &Apache::lonnet::delenv('environment.discdisplay');
1.43 raeburn 1930: }
1931: }
1.59 albertel 1932: if (defined($env{'form.discmark'}) ) {
1933: my $newmark = $env{'form.newmark'};
1.43 raeburn 1934: if ($newmark eq 'ondisp') {
1.196.4.12 raeburn 1935: $message.=&Apache::lonhtmlcommon::confirm_success(&mt('In discussions: new posts will cease to be identified as "NEW" after display.')).'<br />';
1.43 raeburn 1936: &Apache::lonnet::put('environment',{'discmarkread' => $newmark});
1.116 raeburn 1937: &Apache::lonnet::appenv({'environment.discmarkread' => $newmark});
1.43 raeburn 1938: } else {
1.194 raeburn 1939: $message.=&Apache::lonhtmlcommon::confirm_success(&mt('In discussions: posts will be identified as "NEW" until marked as not "NEW".')).'<br />';
1.43 raeburn 1940: &Apache::lonnet::del('environment',['discmarkread']);
1.139 raeburn 1941: &Apache::lonnet::delenv('environment.discmarkread');
1.43 raeburn 1942: }
1.42 raeburn 1943: }
1.158 bisitz 1944: $message=&Apache::loncommon::confirmwrapper($message);
1.152 www 1945: &print_main_menu($r, $message);
1.42 raeburn 1946: }
1947:
1.63 raeburn 1948: ################################################################
1949: # Subroutines for page display on course access (Course Coordinators)
1950: ################################################################
1951: sub coursedisplaychanger {
1952: my $r = shift;
1.152 www 1953: &Apache::lonhtmlcommon::add_breadcrumb(
1.126 droeschl 1954: { href => '/adm/preferences?action=changecourseinit',
1955: text => 'Change Course Init. Pref.'});
1956: $r->print(Apache::loncommon::start_page('Change Course Initialization Preference'));
1957: $r->print(Apache::lonhtmlcommon::breadcrumbs('Change Course Init. Pref.'));
1.63 raeburn 1958: my $user = $env{'user.name'};
1959: my $domain = $env{'user.domain'};
1.66 albertel 1960: my %userenv = &Apache::lonnet::get('environment',['course_init_display']);
1.71 raeburn 1961: my $currvalue = 'whatsnew';
1.73 albertel 1962: my $firstselect = '';
1963: my $whatsnewselect = 'checked="checked"';
1.71 raeburn 1964: if (exists($userenv{'course_init_display'})) {
1965: if ($userenv{'course_init_display'} eq 'firstres') {
1966: $currvalue = 'firstres';
1.73 albertel 1967: $firstselect = 'checked="checked"';
1968: $whatsnewselect = '';
1.71 raeburn 1969: }
1.63 raeburn 1970: }
1.134 bisitz 1971: my %pagenames = &Apache::lonlocal::texthash(
1.71 raeburn 1972: firstres => 'First resource',
1.143 hauer 1973: whatsnew => "What's New Page",
1.71 raeburn 1974: );
1.134 bisitz 1975: my $whatsnew_off=&mt('Display the [_1]first resource[_2] in the course.','<b>','</b>');
1.143 hauer 1976: my $whatsnew_on=&mt("Display the [_1]What's New Page[_2] - a summary of items in the course which require attention.",'<b>','</b>');
1.63 raeburn 1977:
1.134 bisitz 1978: $r->print('<br /><b>'
1979: .&mt('Set the default page to be displayed when you select a course role')
1980: .'</b> '
1981: .&mt('(Currently: [_1])',$pagenames{$currvalue})
1982: .'<br />'
1.143 hauer 1983: .&mt("The global user preference you set for your courses can be overridden in an individual course by setting a course specific setting via the [_1]What's New Page[_2] in the course.",'<i>','</i>')
1.134 bisitz 1984: .'<br /><br />'
1985: );
1.63 raeburn 1986: $r->print(<<ENDLSCREEN);
1.88 albertel 1987: <form name="prefs" action="/adm/preferences" method="post">
1.63 raeburn 1988: <input type="hidden" name="action" value="verify_and_change_coursepage" />
1.72 albertel 1989: <br />
1.65 albertel 1990: <label><input type="radio" name="newdisp" value="firstres" $firstselect /> $whatsnew_off</label><br />
1.70 raeburn 1991: <label><input type="radio" name="newdisp" value="whatsnew" $whatsnewselect /> $whatsnew_on</label><input type="hidden" name="refpage" value="$env{'form.refpage'}" />
1.63 raeburn 1992: ENDLSCREEN
1.140 schafran 1993: $r->print('<br /><br /><input type="submit" value="'.&mt('Save').'" />
1.63 raeburn 1994: </form>');
1995: }
1996:
1997: sub verify_and_change_coursepage {
1998: my $r = shift;
1999: my $message='';
2000: my %lt = &Apache::lonlocal::texthash(
1.70 raeburn 2001: 'defs' => 'Default now set',
1.71 raeburn 2002: 'when' => 'when you select a course role from the roles screen',
1.63 raeburn 2003: 'ywbt' => 'you will be taken to the start of the course.',
2004: 'apwb' => 'a page will be displayed that lists items in the course that may require action from you.',
2005: 'gtts' => 'Go to the start of the course',
1.146 hauer 2006: 'dasp' => "Display the What's New Page",
1.63 raeburn 2007: );
2008: my $newdisp = $env{'form.newdisp'};
1.70 raeburn 2009: $message = '<b>'.$lt{'defs'}.'</b>: '.$lt{'when'}.', ';
1.63 raeburn 2010: if ($newdisp eq 'firstres') {
1.87 albertel 2011: $message .= $lt{'ywbt'}.'<br />';
1.63 raeburn 2012: &Apache::lonnet::put('environment',{'course_init_display' => $newdisp});
1.116 raeburn 2013: &Apache::lonnet::appenv({'environment.course_init_display' => $newdisp});
1.63 raeburn 2014: } else {
1.87 albertel 2015: $message .= $lt{'apwb'}.'<br />';
1.63 raeburn 2016: &Apache::lonnet::del('environment',['course_init_display']);
1.139 raeburn 2017: &Apache::lonnet::delenv('environment.course_init_display');
1.63 raeburn 2018: }
1.70 raeburn 2019: my $refpage = $env{'form.refpage'};
1.63 raeburn 2020: if (($env{'request.course.fn'}) && ($env{'request.course.id'})) {
2021: if ($newdisp eq 'firstres') {
2022: my $cdom = $env{'course.'.$env{'request.course.id'}.'.domain'};
2023: my $cnum = $env{'course.'.$env{'request.course.id'}.'.num'};
2024: my ($furl,$ferr)=
2025: &Apache::lonuserstate::readmap($cdom.'/'.$cnum);
1.180 wenzelju 2026: $message .= '<br /><a href="'.$furl.'">'.$lt{'gtts'}.' <i>'.&mt('now').'</i></a>';
1.63 raeburn 2027: } else {
1.180 wenzelju 2028: $message .= '<br /><a href="/adm/whatsnew?refpage='.
2029: $refpage.'">'.$lt{'dasp'}.'</a>';
1.63 raeburn 2030: }
2031: }
1.180 wenzelju 2032: $message = &Apache::lonhtmlcommon::confirm_success($message);
2033: $message = &Apache::loncommon::confirmwrapper($message);
2034: &print_main_menu($r,$message);
1.63 raeburn 2035: }
2036:
1.196.4.20 raeburn 2037: sub author_space_settings {
2038: my $r = shift;
2039: &Apache::lonhtmlcommon::add_breadcrumb(
2040: { href => '/adm/preferences?action=authorsettings',
2041: text => 'Authoring Space Settings'});
2042: my $user = $env{'user.name'};
2043: my $domain = $env{'user.domain'};
2044: my %author_roles = &Apache::lonnet::get_my_roles($user,$domain,'userroles','',['au','ca','aa']);
2045: if (keys(%author_roles) > 0) {
1.196.4.28.2. (raeburn 2046:): my ($showdomdefs,$js,$args,@items);
2047:): my $returnurl = &HTML::Entities::encode($env{'form.returnurl'},'"<>&\'');
2048:): my $reqdmajor = 2;
2049:): my $reqdminor = 11;
2050:): my $reqddotnum = 4;
2051:): my $reqddotlett= 'B';
2052:): my $reqdreldate = '2024030109';
2053:): my $reqletterfail;
2054:): my $loncaparev = &Apache::lonnet::get_server_loncaparev($env{'user.domain'},$env{'user.home'});
2055:): my ($major,$minor,$dotrel,$reldate) = ($loncaparev =~ /^\'?(\d+)\.(\d+)\.([\w.]+)\-(\d+)\'?$/);
2056:): my ($dotnum,$dotlett) = split(/\./,$dotrel);
2057:): my %lettdig = &Apache::lonnet::letter_to_digits();
2058:): if ((exists($lettdig{$dotlett})) && (exists($lettdig{$reqddotlett}))) {
2059:): if ($lettdig{$reqddotlett} > $lettdig{$dotlett}) {
2060:): $reqletterfail = 1;
2061:): }
2062:): }
2063:): unless (($major eq '' && $minor eq '') ||
2064:): ($reqdmajor > $major) || (($reqdmajor == $major) && ($reqdminor > $minor)) ||
2065:): (($reqdmajor == $major) && ($reqdminor == $minor) && ($reqddotnum > $dotnum)) ||
2066:): (($reqdmajor == $major) && ($reqdminor == $minor) && ($reqddotnum == $dotnum) && $reqletterfail) ||
2067:): (($reqdmajor == $major) && ($reqdminor == $minor) && ($reqddotnum == $dotnum) && ($reqdreldate > $reldate))) {
2068:): @items = ('nocodemirror','copyright','sourceavail');
2069:): $showdomdefs = 1;
2070:): $js = &toggle_options_js();
2071:): my $onload;
2072:): foreach my $item (@items) {
2073:): $onload .= "javascript:toggleOptions(document.prefs,'$item','user_$item');"
2074:): }
2075:): $args = { 'add_entries' => { 'onload' => $onload } };
2076:): }
2077:): $r->print(Apache::loncommon::start_page('Authoring Space Settings',$js,$args));
2078:): $r->print(Apache::lonhtmlcommon::breadcrumbs('Authoring Space Settings'));
2079:): if ($showdomdefs) {
2080:): my %userenv = &Apache::lonnet::get('environment',\@items);
2081:): my %domdefs = &Apache::lonnet::get_domain_defaults($domain);
2082:): my %staticdefaults = (
2083:): 'nocodemirror' => '0',
2084:): 'copyright' => 'default',
2085:): 'sourceavail' => 'closed',
2086:): );
2087:): my %lt = &authoring_settings_text();
2088:): my %titles = &authoring_settings_titles();
2089:): $r->print("<h3>$lt{'auss'}</h3><br /><hr />\n".
2090:): '<form name="prefs" action="/adm/preferences" method="post">'."\n".
2091:): '<input type="hidden" name="returnurl" value="'.$returnurl.'" />'."\n".
2092:): '<input type="hidden" name="action" value="change_authoring_settings" />'."\n");
2093:): foreach my $item (@items) {
2094:): my ($domdef,$checkeddom,$checkeduser,$domdefdisplay,$divsty,$userelem);
2095:): $checkeddom = ' checked="checked"';
2096:): $divsty = 'display:none';
2097:): if (exists($domdefs{$item})) {
2098:): $domdef = $domdefs{$item};
2099:): } else {
2100:): $domdef = $staticdefaults{$item};
2101:): }
2102:): if ($item eq 'copyright') {
2103:): $domdefdisplay = &Apache::loncommon::copyrightdescription($domdef);
2104:): $userelem = &selectbox('userchoice_'.$item,$userenv{$item},'',
2105:): \&Apache::loncommon::copyrightdescription,
2106:): (grep !/^priv|custom$/,(&Apache::loncommon::copyrightids)));
2107:): } elsif ($item eq 'sourceavail') {
2108:): $domdefdisplay = &Apache::loncommon::source_copyrightdescription($domdef);
2109:): $userelem = &selectbox('userchoice_'.$item,$userenv{$item},'',
2110:): \&Apache::loncommon::source_copyrightdescription,
2111:): (&Apache::loncommon::source_copyrightids));
2112:): } elsif ($item eq 'nocodemirror') {
2113:): if ($domdef) {
2114:): $domdefdisplay = $lt{'yes'};
2115:): } else {
2116:): $domdefdisplay = $lt{'no'};
2117:): }
2118:): my %checked;
2119:): $checked{'no'} = ' checked="checked"';
2120:): if ($userenv{$item} eq 'yes') {
2121:): $checked{'yes'} = $checked{'no'};
2122:): $checked{'no'} = '';
2123:): }
2124:): $userelem = '<span class="LC_nobreak">';
2125:): foreach my $choice ('yes','no') {
2126:): $userelem .= '<label><input type="radio" name="userchoice_'.$item.'" value="'.$choice.'"'.
2127:): $checked{$choice}.' />'.$lt{$choice}.'</label> ';
2128:): }
2129:): $userelem .= '</span>';
2130:): }
2131:): if ($userenv{$item} ne '') {
2132:): $checkeduser = $checkeddom;
2133:): $checkeddom = '';
2134:): $divsty = 'display:inline-block';
2135:): }
2136:): $r->print(<<"END");
2137:): <h4><span class="LC_nobreak">$titles{$item}</span></h4>
2138:): <p class="LC_nobreak">$lt{'curd'}: <span style="font-style:italic">$domdefdisplay</span></p>
2139:): <p class="LC_nobreak">
2140:): <label><input type="radio" name="$item" value="dom" onclick="toggleOptions(this.form,'$item','user_$item');"$checkeddom />$lt{'used'}</label>
2141:): <label><input type="radio" name="$item" value="user" onclick="toggleOptions(this.form,'$item','user_$item');"$checkeduser />$lt{'usyo'}</label></p>
2142:): <fieldset id="user_$item" style="$divsty">
2143:): <legend style="font-weight:normal;font-style:italic;">$lt{'ousv'}</legend>
2144:): $userelem
2145:): </fieldset><br /><hr />
2146:): END
2147:): }
2148:): $r->print('<br />'.
2149:): '<input type="submit" value="'.$lt{'save'}.'" />'.
2150:): '</form>'."\n");
2151:): } else {
1.196.4.20 raeburn 2152: my $constchecked='';
2153: if ($env{'environment.nocodemirror'}) {
2154: $constchecked=' checked="checked"';
2155: }
2156: my $text=&mt('By default, CodeMirror an editor with advanced functionality for editing code is activated for authors.');
2157: my $cmoff=&mt('Deactivate CodeMirror. This can improve performance on slow computers and accessibility.');
2158: my $change=&mt('Save');
2159: $r->print(<<ENDSCREEN);
2160: <form name="prefs" action="/adm/preferences" method="post">
1.196.4.24 raeburn 2161: <input type="hidden" name="returnurl" value="$returnurl" />
1.196.4.20 raeburn 2162: <input type="hidden" name="action" value="change_authoring_settings" />
2163: $text<br />
2164: <label><input type="checkbox" name="cmoff"$constchecked />$cmoff</label><br />
2165: <input type="submit" value="$change" />
2166: </form>
2167: ENDSCREEN
1.196.4.28.2. (raeburn 2168:): }
1.196.4.20 raeburn 2169: }
2170: }
2171:
2172: sub change_authoring_settings {
2173: my $r = shift;
2174: my $user = $env{'user.name'};
2175: my $domain = $env{'user.domain'};
2176: my %author_roles = &Apache::lonnet::get_my_roles($user,$domain,'userroles','',['au','ca','aa']);
2177: if (keys(%author_roles) > 0) {
1.196.4.28.2. (raeburn 2178:): my $message;
2179:): if (0) {
1.196.4.20 raeburn 2180: my %ausettings=('environment.nocodemirror' => '');
2181: if ($env{'form.cmoff'}) { $ausettings{'environment.nocodemirror'}='yes'; }
2182: &Apache::lonnet::put('environment',\%ausettings);
2183: &Apache::lonnet::appenv({'environment.nocodemirror' => $ausettings{'environment.nocodemirror'}});
2184: my $status='';
2185: if ($ausettings{'environment.nocodemirror'} eq 'yes') {
2186: $status=&mt('on');
2187: } else {
2188: $status=&mt('off');
2189: }
1.196.4.28.2. (raeburn 2190:): $message=&Apache::lonhtmlcommon::confirm_success(&mt('Set [_1] to [_2]','<i>'.&mt('Deactivate CodeMirror in Authoring Space').'</i>','<tt>'.$status.'</tt>'));
1.196.4.20 raeburn 2191: $message=&Apache::loncommon::confirmwrapper($message);
1.196.4.28.2. (raeburn 2192:): } else {
2193:): my @items = ('nocodemirror','copyright','sourceavail');
2194:): my %oldsettings = &Apache::lonnet::get('environment',\@items);
2195:): my %domdefs = &Apache::lonnet::get_domain_defaults($domain);
2196:): my %lt = &authoring_settings_text();
2197:): my %titles = &authoring_settings_titles();
2198:): my ($result,%newsettings,%changes,@delete,@unchanged,@delerrors,@adderrors);
2199:): foreach my $item (@items) {
2200:): if ($env{'form.'.$item} eq 'dom') {
2201:): if ($oldsettings{$item} eq '') {
2202:): push(@unchanged,$item);
2203:): } else {
2204:): push(@delete,$item);
2205:): }
2206:): } elsif ($env{'form.'.$item} eq 'user') {
2207:): my $newval = $env{'form.userchoice_'.$item};
2208:): my @possibles;
2209:): if ($item eq 'nocodemirror') {
2210:): if ($newval =~ /^yes|no$/) {
2211:): $newsettings{$item} = $newval;
2212:): }
2213:): } elsif ($item eq 'copyright') {
2214:): @possibles = (grep !/^priv|custom$/,(&Apache::loncommon::copyrightids));
2215:): if (grep(/^\Q$newval\E$/,@possibles)) {
2216:): $newsettings{$item} = $newval;
2217:): }
2218:): } elsif ($item eq 'sourceavail') {
2219:): @possibles = (&Apache::loncommon::source_copyrightids);
2220:): if (grep(/^\Q$newval\E$/,@possibles)) {
2221:): $newsettings{$item} = $newval;
2222:): }
2223:): }
2224:): if ($oldsettings{$item} eq $newsettings{$item}) {
2225:): push(@unchanged,$item);
2226:): } else {
2227:): $changes{$item} = $newsettings{$item};
2228:): }
2229:): }
2230:): }
2231:): if (@delete) {
2232:): if (&Apache::lonnet::del('environment',\@delete) eq 'ok') {
2233:): foreach my $key (@delete) {
2234:): &Apache::lonnet::delenv('environment.'.$key);
2235:): }
2236:): } else {
2237:): @delerrors = @delete;
2238:): }
2239:): }
2240:): if (keys(%changes)) {
2241:): if (&Apache::lonnet::put('environment',\%changes) eq 'ok') {
2242:): my %newenvhash;
2243:): map {$newenvhash{'environment.'.$_} = $changes{$_}; } (keys(%changes));
2244:): &Apache::lonnet::appenv(\%newenvhash);
2245:): } else {
2246:): foreach my $item (@items) {
2247:): if (exists($changes{$item})) {
2248:): push(@adderrors,$item);
2249:): }
2250:): }
2251:): }
2252:): }
2253:): if (@adderrors) {
2254:): $result = &mt('An error occurred when saving user-specific settings for').': '.
2255:): join(', ', map { $titles{$_} } @adderrors);
2256:): $message = &Apache::loncommon::confirmwrapper(&Apache::lonhtmlcommon::confirm_success($result,1));
2257:): } elsif (keys(%changes)) {
2258:): $result = &mt('User-specific settings saved:').'<ul>';
2259:): foreach my $item (@items) {
2260:): next unless (exists($changes{$item}));
2261:): my $value = $changes{$item};
2262:): if ($item eq 'nocodemirror') {
2263:): $value = $lt{$changes{$item}};
2264:): } elsif ($item eq 'copyright') {
2265:): $value = &Apache::loncommon::copyrightdescription($changes{$item});
2266:): } elsif ($item eq 'sourceavail') {
2267:): $value = &Apache::loncommon::source_copyrightdescription($changes{$item});
2268:): }
2269:): $result .= '<li>'.
2270:): &mt('[_1] set to [_2]',
2271:): $titles{$item},
2272:): '<span style="font-style:italic">'.$value.'</span>').
2273:): '</li>';
2274:): }
2275:): $result .= '</ul>';
2276:): $message = &Apache::loncommon::confirmwrapper(&Apache::lonhtmlcommon::confirm_success($result));
2277:): }
2278:): if (@delerrors) {
2279:): $result = &mt('An error occurred when deleting user-specific settings for').':<ul><li>'.
2280:): join('</li><li>', map { $titles{$_} } @delerrors).'</li></ul>';
2281:): $message .= &Apache::loncommon::confirmwrapper(&Apache::lonhtmlcommon::confirm_success($result,1));
2282:): } elsif (@delete) {
2283:): $result = &mt('Set use of domain default for').':<ul><li>'.
2284:): join('</li><li>', map { $titles{$_} } @delete).'</li></ul>';
2285:): $message .= &Apache::loncommon::confirmwrapper(&Apache::lonhtmlcommon::confirm_success($result));
2286:): }
2287:): if (@unchanged) {
2288:): $result = &mt('No changes made for').':<ul><li>'.
2289:): join('</li><li>', map { $titles{$_} } @unchanged).'</li></ul>';
2290:): $message .= &Apache::loncommon::confirmwrapper(&Apache::lonhtmlcommon::confirm_success($result));
1.196.4.24 raeburn 2291: }
1.196.4.28.2. (raeburn 2292:): }
2293:): if ($env{'form.returnurl'}) {
2294:): &do_redirect($r,$env{'form.returnurl'},$message);
2295:): } else {
2296:): &print_main_menu($r,$message);
2297:): }
1.196.4.20 raeburn 2298: }
2299: }
2300:
1.196.4.28.2. (raeburn 2301:): sub authoring_settings_text {
2302:): return &Apache::lonlocal::texthash(
2303:): 'auss' => 'Authoring Space Settings',
2304:): 'used' => 'Use domain default',
2305:): 'usyo' => 'Use your own user-specific setting',
2306:): 'curd' => 'Current domain default is',
2307:): 'ousv' => 'Own user-specific value',
2308:): 'save' => 'Save',
2309:): 'yes' => 'Deactivated',
2310:): 'no' => 'Activated',
2311:): );
2312:): }
2313:):
2314:): sub authoring_settings_titles {
2315:): return &Apache::lonlocal::texthash(
2316:): 'nocodemirror' => 'CodeMirror for EditXML editor',
2317:): 'copyright' => 'Default Copyright/Distribution in new metadata file',
2318:): 'sourceavail' => 'Default Source Available in new metadata file',
2319:): );
2320:): }
2321:):
1.186 raeburn 2322: sub lockednameschanger {
2323: my $r = shift;
2324: my %userenv = &Apache::lonnet::get('environment',['lockedname']);
2325: my $lockedname='';
1.196.4.28.2. (raeburn 2326:): my $ended;
1.186 raeburn 2327: if (&can_toggle_namelocking()) {
2328: if ($userenv{'lockedname'}) {
2329: $lockedname = ' checked="checked"';
2330: }
2331: my %updateable;
2332: my %domconfig =
2333: &Apache::lonnet::get_dom('configuration',['autoupdate'],$env{'user.domain'});
2334: if (ref($domconfig{'autoupdate'}) eq 'HASH') {
2335: if ($domconfig{'autoupdate'}{'run'}) {
2336: my @inststatuses = split(':',$env{'environment.inststatus'});
2337: unless (@inststatuses) {
2338: @inststatuses = ('default');
2339: }
2340: %updateable = &updateable_userinfo($domconfig{'autoupdate'},\@inststatuses);
2341: }
2342: }
2343: if (keys(%updateable)) {
1.196.4.28.2. (raeburn 2344:): &Apache::lonhtmlcommon::add_breadcrumb(
2345:): { href => '/adm/preferences?action=changelockednames',
2346:): text => 'Automatic name changes'});
2347:): $r->print(Apache::loncommon::start_page('Automatic name changes'));
2348:): $r->print(Apache::lonhtmlcommon::breadcrumbs('Allow/disallow name updates'));
1.186 raeburn 2349: my %longnames = &Apache::lonlocal::texthash (
2350: firstname => 'First Name',
2351: middlename => 'Middle Name',
2352: lastname => 'Last Name',
2353: );
2354: 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:').
2355: '<ul>';
2356: foreach my $item ('firstname','middlename','lastname') {
2357: if ($updateable{$item}) {
2358: $text .= '<li>'.$longnames{$item}.'</li>';
2359: }
2360: }
2361: $text .= '</ul>';
2362: my $locking=&mt('Disallow automatic updates to name information for your LON-CAPA account');
2363: my $change=&mt('Save');
2364: $r->print(<<ENDSCREEN);
2365: <form name="prefs" action="/adm/preferences" method="post">
2366: <input type="hidden" name="action" value="verify_and_change_lockednames" />
2367: $text<br />
2368: <label><input type="checkbox" value="1" name="lockednames"$lockedname />$locking</label><br />
2369: <input type="submit" value="$change" />
2370: </form>
2371: ENDSCREEN
2372: } else {
2373: my $message = &mt('Based on your institutional affiliation no name information is automatically updated for your LON-CAPA account.');
2374: &print_main_menu($r,$message);
1.196.4.28.2. (raeburn 2375:): $ended = 1;
1.186 raeburn 2376: }
2377: } else {
2378: my $message = &mt('You are not permitted to set a user preference for automatic name updates for your LON-CAPA account.');
2379: &print_main_menu($r,$message);
1.196.4.28.2. (raeburn 2380:): $ended = 1;
1.186 raeburn 2381: }
1.196.4.28.2. (raeburn 2382:): return $ended;
1.186 raeburn 2383: }
2384:
2385: sub verify_and_change_lockednames {
2386: my $r = shift;
2387: my $message;
2388: if (&can_toggle_namelocking()) {
2389: my $newlockedname = $env{'form.lockednames'};
2390: $newlockedname =~ s/\D//g;
2391: my $currlockedname = $env{'environment.lockedname'};
2392: if ($newlockedname ne $currlockedname) {
2393: if ($newlockedname) {
2394: if (&Apache::lonnet::put('environment',{lockedname => $newlockedname}) eq 'ok') {
2395: &Apache::lonnet::appenv({'environment.lockedname' => $newlockedname});
2396: }
2397: } elsif (&Apache::lonnet::del('environment',['lockedname']) eq 'ok') {
2398: &Apache::lonnet::delenv('environment.lockedname');
2399: }
2400: }
2401: my $status='';
2402: if ($newlockedname) {
2403: $status=&mt('disallowed');
2404: } else {
2405: $status=&mt('allowed');
2406: }
2407: $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>'));
2408: $message=&Apache::loncommon::confirmwrapper($message);
2409: }
2410: &print_main_menu($r,$message);
2411: }
2412:
1.196.4.28.2. (raeburn 2413:): sub timezonechanger {
2414:): my $r = shift;
2415:): my $uname = $env{'user.name'};
2416:): my $udom = $env{'user.domain'};
2417:): if (&Apache::lonnet::usertools_access($uname,$udom,'timezone')) {
2418:): my $js = &toggle_options_js();
2419:): my %loaditems = (
2420:): onload => "javascript:toggleOptions(document.prefs,'settimezone','LC_timezone_selector');",
2421:): );
2422:): my $args = { 'add_entries' => \%loaditems };
2423:): &Apache::lonhtmlcommon::add_breadcrumb(
2424:): { href => '/adm/preferences?action=',
2425:): text => 'Set Your Time Zone'});
2426:): $r->print(Apache::loncommon::start_page('Set Your Time Zone',$js,$args));
2427:): $r->print(Apache::lonhtmlcommon::breadcrumbs('Set Your Time Zone'));
2428:): my %userenv = &Apache::lonnet::get('environment',['timezone']);
2429:): my $timezone = $userenv{'timezone'};
2430:): my %lt = &Apache::lonlocal::texthash(
2431:): lctz => 'Use Time Zone set by LON-CAPA',
2432:): owntz => 'Use Time Zone set by you',
2433:): save => 'Save',
2434:): );
2435:): my (%checked,$tzsty);
2436:): if ($userenv{'timezone'} ne '') {
2437:): $checked{'owntz'} = ' checked="checked"';
2438:): $tzsty = 'inline-block';
2439:): } else {
2440:): $checked{'lctz'} = ' checked="checked"';
2441:): $tzsty = 'none';
2442:): }
2443:): my $onclick = ' onclick="javascript:toggleOptions(this.form,'."'settimezone','LC_timezone_selector'".');"';
2444:): my $selector = &Apache::loncommon::select_timezone('timezone',$timezone,undef,1);
2445:): $r->print(<<"END");
2446:): <form name="prefs" action="/adm/preferences" method="post">
2447:): <input type="hidden" name="action" value="verify_and_change_timezone" />
2448:): <span class="LC_nobreak">
2449:): <label><input type="radio" name="settimezone" value="0"$checked{'lctz'}$onclick />
2450:): $lt{'lctz'}</label>
2451:): <label><input type="radio" name="settimezone" value="1"$checked{'owntz'}$onclick />
2452:): $lt{'owntz'}</label><div style="display:$tzsty" id="LC_timezone_selector">
2453:): $selector
2454:): </div></span><br /><br />
2455:): <input type="submit" value="$lt{'save'}" />
2456:): </form>
2457:): END
2458:): }
2459:): return;
2460:): }
2461:):
2462:): sub verify_and_change_timezone {
2463:): my $r = shift;
2464:): my $currtimezone = $env{'environment.timezone'};
2465:): my $newtimezone;
2466:): if ($env{'form.settimezone'}) {
2467:): $newtimezone = $env{'form.timezone'};
2468:): if (DateTime::TimeZone->is_valid_name($env{'form.timezone'})) {
2469:): $newtimezone = $env{'form.timezone'};
2470:): }
2471:): }
2472:): my $message='';
2473:): if ($newtimezone) {
2474:): if ($newtimezone eq $currtimezone) {
2475:): $message = &mt('Time Zone settings unchanged');
2476:): } else {
2477:): &Apache::lonnet::put('environment',{'timezone' => $newtimezone});
2478:): &Apache::lonnet::appenv({'environment.timezone' => $newtimezone});
2479:): $message=&Apache::lonhtmlcommon::confirm_success(
2480:): &mt('Set [_1] to [_2]',
2481:): '<i>'.&mt('Your Time Zone').'</i>',
2482:): '<tt>"'.$newtimezone.'"</tt>.')).
2483:): '<br />';
2484:): }
2485:): } elsif ($currtimezone) {
2486:): &Apache::lonnet::del('environment',['timezone']);
2487:): &Apache::lonnet::delenv('environment.timezone');
2488:): $message=&Apache::lonhtmlcommon::confirm_success(&mt('Time Zone now set by LON-CAPA'));
2489:): } else {
2490:): $message = &mt('Time Zone settings unchanged');
2491:): }
2492:): $message=&Apache::loncommon::confirmwrapper($message);
2493:): &print_main_menu($r,$message);
2494:): return;
2495:): }
2496:):
1.126 droeschl 2497: sub print_main_menu {
2498: my ($r, $message) = @_;
2499: # Determine current authentication method
2500: my $user = $env{'user.name'};
2501: my $domain = $env{'user.domain'};
2502: my $currentauth=&Apache::lonnet::queryauthenticate($user,$domain);
2503:
2504: # build the data structure for menu generation
2505: my $aboutmeurl='/adm/'.$env{'user.domain'}.'/'.$env{'user.name'}.'/aboutme';
2506: my $role = ($env{'user.adv'} ? 'Roles' : 'Course');
1.131 raeburn 2507: my %permissions;
2508: if (&Apache::lonnet::usertools_access($user,$domain,'aboutme')) {
2509: $permissions{'aboutme'} = 'F';
2510: }
1.196.4.28.2. (raeburn 2511:): if (&Apache::lonnet::usertools_access($user,$domain,'timezone')) {
2512:): $permissions{'timezone'} = 'F';
2513:): }
2514:): my %author_roles = &Apache::lonnet::get_my_roles($user,$domain,'userroles','',['au']);
2515:): my %author_coauthor_roles = &Apache::lonnet::get_my_roles($user,$domain,'userroles','',['au','ca','aa']);
1.126 droeschl 2516: my @menu=
2517: ({ categorytitle=>'Personal Data',
2518: items =>[
1.141 weissno 2519: { linktext => 'Personal Information Page',
1.126 droeschl 2520: url => $aboutmeurl,
1.131 raeburn 2521: permission => $permissions{'aboutme'},
1.126 droeschl 2522: #help => 'Prefs_About_Me',
2523: icon => 'system-users.png',
2524: linktitle => 'Edit information about yourself that should be displayed on your public profile.'
2525: },
2526: { linktext => 'Screen Name',
2527: url => '/adm/preferences?action=changescreenname',
2528: permission => 'F',
2529: #help => 'Prefs_Screen_Name_Nickname',
2530: icon => 'preferences-desktop-font.png',
2531: linktitle => 'Change the name that is displayed in your posts.'
2532: },
2533: ]
2534: },
2535: { categorytitle=>'Content Display Settings',
2536: items =>[
2537: { linktext => 'Language',
2538: url => '/adm/preferences?action=changelanguages',
2539: permission => 'F',
2540: #help => 'Prefs_Language',
2541: icon => 'preferences-desktop-locale.png',
1.127 droeschl 2542: linktitle => 'Choose the default language for this user.'
1.126 droeschl 2543: },
1.128 droeschl 2544: { linktext => $role.' Page',
1.126 droeschl 2545: url => '/adm/preferences?action=changerolespref',
2546: permission => 'F',
2547: #help => '',
1.189 wenzelju 2548: icon => 'role_hotlist.png',
1.126 droeschl 2549: linktitle => 'Configure the roles hotlist.'
2550: },
1.177 raeburn 2551: { linktext => 'Math display settings',
1.126 droeschl 2552: url => '/adm/preferences?action=changetexenginepref',
2553: permission => 'F',
2554: #help => '',
1.188 wenzelju 2555: icon => 'dismath.png',
1.177 raeburn 2556: linktitle => 'Change how math is displayed.'
1.126 droeschl 2557: },
1.196.4.28.2. (raeburn 2558:): {
2559:): linktext => 'Time Zone',
2560:): url => '/adm/preferences?action=changetimezone',
2561:): permission => $permissions{'timezone'},
2562:): #help => '',
2563:): icon => 'timezone.png',
2564:): linktitle => 'Set your time zone.',
2565:): }
1.126 droeschl 2566: ]
2567: },
1.185 droeschl 2568: { categorytitle=>'Page Display Settings',
2569: items =>[
2570: { linktext => 'Color Scheme',
2571: url => '/adm/preferences?action=changecolors',
2572: permission => 'F',
2573: #help => 'Change_Colors',
2574: icon => 'preferences-desktop-theme.png',
2575: linktitle => 'Change LON-CAPA default colors.'
2576: },
1.192 raeburn 2577: { linktext => 'Menu Display',
2578: url => '/adm/preferences?action=changeicons',
2579: permission => 'F',
2580: #help => '',
2581: icon => 'preferences-system-windows.png',
2582: linktitle => 'Change whether the menus are displayed with icons or icons and text.'
2583: }
1.185 droeschl 2584: ]
2585: },
1.178 bisitz 2586: { categorytitle=>'Messages & Notifications',
1.128 droeschl 2587: items =>[
1.153 www 2588: { linktext => 'Messages & Notifications',
1.128 droeschl 2589: url => '/adm/preferences?action=changemsgforward',
2590: permission => 'F',
2591: #help => 'Prefs_Messages',
2592: icon => 'mail-reply-all.png',
2593: linktitle => 'Change messageforwarding or notifications settings.'
2594: },
2595: { linktext => 'Discussion Display',
2596: url => '/adm/preferences?action=changediscussions',
2597: permission => 'F',
2598: #help => 'Change_Discussion_Display',
1.191 riegler 2599: icon => 'chat.png',
1.135 schafran 2600: linktitle => 'Set display preferences for discussion posts for both discussion boards and individual resources in all your courses.'
1.128 droeschl 2601: },
2602: ]
2603: },
1.196.4.28.2. (raeburn 2604:): );
2605:): if (keys(%author_coauthor_roles) > 0) {
2606:): push(@menu,
2607:): { categorytitle=>'Authoring Settings',
2608:): items => [
2609:): {
2610:): linktext => 'Authoring Space Configuration',
2611:): url => '/adm/preferences?action=authorsettings',
2612:): permission => 'F',
2613:): icon => 'codemirror.png',
2614:): linktitle => 'Settings for your authoring space.',
2615:): },
2616:): ]
2617:): },
2618:): );
2619:): if (keys(%author_roles) > 0) {
2620:): push(@{ $menu[4]->{items} }, {
2621:): linktext => 'Restrict Domain Coordinator Access',
2622:): url => '/adm/preferences?action=changedomcoord',
2623:): permission => 'F',
2624:): #help => '',
2625:): icon => 'system-lock-screen.png',
2626:): linktitle => 'Restrict domain coordinator access.',
2627:): });
2628:): }
2629:): }
2630:): push(@menu,
1.126 droeschl 2631: { categorytitle=>'Other',
2632: items =>[
1.153 www 2633: { linktext => 'Register Response Devices ("Clickers")',
1.126 droeschl 2634: url => '/adm/preferences?action=changeclicker',
2635: permission => 'F',
2636: #help => '',
2637: icon => 'network-workgroup.png',
2638: linktitle => 'Register your clicker.'
2639: },
2640: ]
2641: },
2642: );
2643:
2644: if ($currentauth =~ /^(unix|internal):/) {
1.196.4.28.2. (raeburn 2645:): push(@{ $menu[0]->{items} }, {
1.126 droeschl 2646: linktext => 'Password',
2647: url => '/adm/preferences?action=changepass',
2648: permission => 'F',
2649: #help => 'Change_Password',
2650: icon => 'emblem-readonly.png',
2651: linktitle => 'Change your password.',
2652: });
2653: }
1.196.4.2 raeburn 2654: if ($env{'environment.remote'} eq 'off') {
1.196.4.28.2. (raeburn 2655:): push(@{ $menu[1]->{items} }, {
1.196.4.2 raeburn 2656: linktext => 'Launch Remote Control',
2657: url => '/adm/remote?url=/adm/preferences&action=launch',
2658: permission => 'F',
2659: #help => '',
2660: icon => 'remotecontrol.png',
2661: linktitle => 'Launch the remote control for LON-CAPA.',
2662: });
2663: }else{
2664: push(@{ $menu[1]->{items} }, {
2665: linktext => 'Collapse Remote Control',
2666: url => '/adm/remote?url=/adm/preferences&action=collapse',
2667: permission => 'F',
2668: #help => '',
2669: icon => 'remotecontrol.png',
2670: linktitle => 'Collapse the remote control for LON-CAPA.',
2671: });
2672: }
1.186 raeburn 2673:
2674: if (&can_toggle_namelocking()) {
2675: push(@{ $menu[0]->{items} }, {
2676: linktext => 'Automatic name changes',
2677: url => '/adm/preferences?action=changelockednames',
2678: permission => 'F',
2679: #help => '',
2680: icon => 'system-lock-screen.png',
2681: linktitle => 'Allow/disallow propagation of name changes from institutional directory service',
2682: });
2683: }
2684:
1.126 droeschl 2685: if (&Apache::lonnet::allowed('whn',$env{'request.course.id'})
2686: || &Apache::lonnet::allowed('whn',$env{'request.course.id'}.'/'
2687: .$env{'request.course.sec'})) {
1.196.4.28.2. (raeburn 2688:): push(@{ $menu[-1]->{items} }, {
1.128 droeschl 2689: linktext => 'Course Initialization',
1.126 droeschl 2690: url => '/adm/preferences?action=changecourseinit',
2691: permission => 'F',
2692: #help => '',
1.189 wenzelju 2693: icon => 'course_ini.png',
1.126 droeschl 2694: linktitle => 'Set the default page to be displayed when you select a course role.',
2695: });
2696:
2697: }
1.196.4.21 raeburn 2698:
1.174 raeburn 2699: if (&can_toggle_debug()) {
1.196.4.28.2. (raeburn 2700:): push(@{ $menu[-1]->{items} }, {
1.174 raeburn 2701: linktext => 'Toggle Debug Messages (Currently '.($env{'user.debug'} ? 'on)' : 'off)'),
1.126 droeschl 2702: url => '/adm/preferences?action=debugtoggle',
2703: permission => 'F',
2704: #help => '',
2705: icon => 'blog.png',
2706: linktitle => 'Toggle Debug Messages.',
2707: });
1.186 raeburn 2708: }
1.126 droeschl 2709:
1.147 schafran 2710: $r->print(&Apache::loncommon::start_page('My Space'));
1.126 droeschl 2711: $r->print(Apache::lonhtmlcommon::breadcrumbs('Change Preferences'));
2712: $r->print($message);
2713: $r->print(Apache::lonhtmlcommon::generate_menu(@menu));
2714: $r->print(Apache::loncommon::end_page());
2715: }
1.63 raeburn 2716:
1.4 matthew 2717: ######################################################
2718: # other handler subroutines #
2719: ######################################################
2720:
1.3 matthew 2721: ################################################################
2722: # Main handler #
2723: ################################################################
1.126 droeschl 2724: sub handler {
2725: my $r = shift;
2726: Apache::loncommon::content_type($r,'text/html');
2727: # Some pages contain DES keys and should not be cached.
2728: Apache::loncommon::no_cache($r);
2729: $r->send_http_header;
2730: return OK if $r->header_only;
2731: #
2732: Apache::loncommon::get_unprocessed_cgi($ENV{'QUERY_STRING'},
2733: ['action','wysiwyg','returnurl','refpage']);
2734: #
2735: Apache::lonhtmlcommon::clear_breadcrumbs();
1.196.4.24 raeburn 2736: my ($brlink,$brtxt,$brhelp,$ended);
1.196.4.5 raeburn 2737: if (($env{'form.action'} eq 'changerolespref') && ($env{'form.returnurl'} eq '/adm/roles')) {
2738: $brlink ='/adm/roles';
2739: $brtxt = 'User Roles';
1.196.4.24 raeburn 2740: } elsif ((($env{'form.action'} eq 'changedomcoord') ||
2741: ($env{'form.action'} eq 'authorsettings')) &&
2742: (($env{'form.returnurl'} =~ m{^/(priv/|res($|/))}) ||
2743: ($env{'form.returnurl'} eq '/adm/createuser'))) {
2744: $brlink = $env{'form.returnurl'};
2745: if ($env{'form.returnurl'} eq '/adm/createuser') {
2746: $brtxt = 'User Management';
2747: } elsif ($env{'form.returnurl'} =~ m{^/res($\/)}) {
2748: $brtxt = 'Browse published resources';
2749: } else {
2750: $brtxt = 'Authoring Space';
2751: }
1.196.4.5 raeburn 2752: } else {
2753: $brlink ='/adm/preferences';
2754: $brtxt = 'Set User Preferences';
2755: $brhelp = 'Prefs_About_Me,Prefs_Language,Prefs_Screen_Name_Nickname,Change_Colors,Change_Password,Prefs_Messages,Change_Discussion_Display';
2756: }
1.126 droeschl 2757: Apache::lonhtmlcommon::add_breadcrumb
1.196.4.5 raeburn 2758: ({href => $brlink,
2759: text => $brtxt,
2760: help => $brhelp,});
1.126 droeschl 2761: if(!exists $env{'form.action'}) {
1.150 droeschl 2762: &print_main_menu($r);
1.196.4.24 raeburn 2763: $ended = 1;
1.126 droeschl 2764: }elsif($env{'form.action'} eq 'changepass'){
2765: &passwordchanger($r);
2766: }elsif($env{'form.action'} eq 'verify_and_change_pass'){
1.196.4.26 raeburn 2767: &verify_and_change_password($r,'preferences','','','',\$ended);
1.126 droeschl 2768: }elsif($env{'form.action'} eq 'changescreenname'){
2769: &screennamechanger($r);
2770: }elsif($env{'form.action'} eq 'verify_and_change_screenname'){
2771: &verify_and_change_screenname($r);
1.196.4.24 raeburn 2772: $ended = 1;
1.126 droeschl 2773: }elsif($env{'form.action'} eq 'changemsgforward'){
2774: &msgforwardchanger($r);
2775: }elsif($env{'form.action'} eq 'verify_and_change_msgforward'){
2776: &verify_and_change_msgforward($r);
2777: }elsif($env{'form.action'} eq 'changecolors'){
2778: &colorschanger($r);
2779: }elsif($env{'form.action'} eq 'verify_and_change_colors'){
2780: &verify_and_change_colors($r);
1.196.4.24 raeburn 2781: $ended = 1;
1.126 droeschl 2782: }elsif($env{'form.action'} eq 'changelanguages'){
2783: &languagechanger($r);
2784: }elsif($env{'form.action'} eq 'verify_and_change_languages'){
2785: &verify_and_change_languages($r);
1.196.4.24 raeburn 2786: $ended = 1;
1.126 droeschl 2787: }elsif($env{'form.action'} eq 'changewysiwyg'){
2788: &wysiwygchanger($r);
2789: }elsif($env{'form.action'} eq 'set_wysiwyg'){
2790: &verify_and_change_wysiwyg($r);
1.196.4.24 raeburn 2791: $ended = 1;
1.126 droeschl 2792: }elsif($env{'form.action'} eq 'changediscussions'){
2793: &discussionchanger($r);
2794: }elsif($env{'form.action'} eq 'verify_and_change_discussion'){
2795: &verify_and_change_discussion($r);
1.196.4.24 raeburn 2796: $ended = 1;
1.126 droeschl 2797: }elsif($env{'form.action'} eq 'changerolespref'){
2798: &rolesprefchanger($r);
2799: }elsif($env{'form.action'} eq 'verify_and_change_rolespref'){
2800: &verify_and_change_rolespref($r);
1.196.4.24 raeburn 2801: $ended = 1;
1.126 droeschl 2802: }elsif($env{'form.action'} eq 'changetexenginepref'){
2803: &texenginechanger($r);
2804: }elsif($env{'form.action'} eq 'verify_and_change_texengine'){
2805: &verify_and_change_texengine($r);
1.196.4.24 raeburn 2806: $ended = 1;
1.192 raeburn 2807: }elsif($env{'form.action'} eq 'changeicons'){
2808: &iconchanger($r);
2809: }elsif($env{'form.action'} eq 'verify_and_change_icons'){
2810: &verify_and_change_icons($r);
1.196.4.24 raeburn 2811: $ended = 1;
1.126 droeschl 2812: }elsif($env{'form.action'} eq 'changeclicker'){
2813: &clickerchanger($r);
2814: }elsif($env{'form.action'} eq 'verify_and_change_clicker'){
2815: &verify_and_change_clicker($r);
1.196.4.24 raeburn 2816: $ended = 1;
1.126 droeschl 2817: }elsif($env{'form.action'} eq 'changedomcoord'){
2818: &domcoordchanger($r);
2819: }elsif($env{'form.action'} eq 'verify_and_change_domcoord'){
2820: &verify_and_change_domcoord($r);
1.196.4.24 raeburn 2821: $ended = 1;
1.126 droeschl 2822: }elsif($env{'form.action'} eq 'lockwarning'){
2823: &lockwarning($r);
2824: }elsif($env{'form.action'} eq 'verify_and_change_locks'){
2825: &verify_and_change_lockwarning($r);
2826: }elsif($env{'form.action'} eq 'changecourseinit'){
2827: &coursedisplaychanger($r);
2828: }elsif($env{'form.action'} eq 'verify_and_change_coursepage'){
2829: &verify_and_change_coursepage($r);
1.196.4.24 raeburn 2830: $ended = 1;
1.196.4.20 raeburn 2831: }elsif($env{'form.action'} eq 'authorsettings'){
2832: &author_space_settings($r);
2833: }elsif($env{'form.action'} eq 'change_authoring_settings'){
2834: &change_authoring_settings($r);
1.196.4.24 raeburn 2835: $ended = 1;
1.126 droeschl 2836: }elsif($env{'form.action'} eq 'debugtoggle'){
1.174 raeburn 2837: if (&can_toggle_debug()) {
2838: &toggle_debug();
2839: }
1.154 www 2840: &print_main_menu($r);
1.196.4.24 raeburn 2841: $ended = 1;
1.186 raeburn 2842: } elsif ($env{'form.action'} eq 'changelockednames') {
1.196.4.28.2. (raeburn 2843:): $ended = &lockednameschanger($r);
1.186 raeburn 2844: } elsif ($env{'form.action'} eq 'verify_and_change_lockednames') {
2845: &verify_and_change_lockednames($r);
1.196.4.24 raeburn 2846: $ended = 1;
1.196.4.28.2. (raeburn 2847:): } elsif ($env{'form.action'} eq 'changetimezone') {
2848:): &timezonechanger($r);
2849:): } elsif ($env{'form.action'} eq 'verify_and_change_timezone') {
2850:): &verify_and_change_timezone($r);
1.126 droeschl 2851: }
2852:
1.165 bisitz 2853: # Properly end the HTML page of all preference pages
2854: # started in each sub routine
2855: # Exception: print_main_menu has its own end_page call
1.196.4.24 raeburn 2856: unless ($ended) {
1.165 bisitz 2857: $r->print(&Apache::loncommon::end_page());
2858: }
2859:
1.126 droeschl 2860: return OK;
1.35 matthew 2861: }
2862:
2863: sub toggle_debug {
1.59 albertel 2864: if ($env{'user.debug'}) {
1.139 raeburn 2865: &Apache::lonnet::delenv('user.debug');
1.35 matthew 2866: } else {
1.116 raeburn 2867: &Apache::lonnet::appenv({'user.debug' => 1});
1.35 matthew 2868: }
1.13 www 2869: }
1.1 www 2870:
1.174 raeburn 2871: sub can_toggle_debug {
2872: my $can_toggle = 0;
2873: my $page = 'toggledebug';
2874: if (&LONCAPA::lonauthcgi::can_view($page)) {
2875: $can_toggle = 1;
2876: } elsif (&LONCAPA::lonauthcgi::check_ipbased_access($page)) {
2877: $can_toggle = 1;
2878: }
2879: return $can_toggle;
2880: }
2881:
1.186 raeburn 2882: sub can_toggle_namelocking {
2883: my $lockablenames;
2884: my %domconfig =
2885: &Apache::lonnet::get_dom('configuration',['autoupdate'],$env{'user.domain'});
2886: if (ref($domconfig{'autoupdate'}) eq 'HASH') {
2887: if ($domconfig{'autoupdate'}{'run'}) {
2888: my @inststatuses = split(':',$env{'environment.inststatus'});
2889: unless (@inststatuses) {
2890: @inststatuses = ('default');
2891: }
2892: my %updateable = &updateable_userinfo($domconfig{'autoupdate'},\@inststatuses);
2893: if ($updateable{'lastname'} || $updateable{'firstname'} ||
2894: $updateable{'middlename'}) {
2895: if (ref($domconfig{'autoupdate'}{'lockablenames'}) eq 'ARRAY') {
2896: unless (@inststatuses) {
2897: @inststatuses = ('default');
2898: }
2899: foreach my $status (@inststatuses) {
2900: if (grep(/^\Q$status\E$/,@{$domconfig{'autoupdate'}{'lockablenames'}})) {
2901: $lockablenames = 1;
2902: last;
2903: }
2904: }
2905: }
2906: }
2907: }
2908: }
2909: return $lockablenames;
2910: }
2911:
2912: sub updateable_userinfo {
2913: my ($autoupdate,$inststatuses) = @_;
2914: my %updateable;
2915: return %updateable unless ((ref($autoupdate) eq 'HASH') &&
2916: (ref($inststatuses) eq 'ARRAY'));
2917: if (ref($autoupdate->{'fields'}) eq 'HASH') {
2918: foreach my $status (@{$inststatuses}) {
2919: if (ref($autoupdate->{'fields'}{$status}) eq 'ARRAY') {
2920: foreach my $field (@{$autoupdate->{'fields'}{$status}}) {
2921: $updateable{$field} = 1;
2922: }
2923: }
2924: }
2925: }
2926: return %updateable;
2927: }
2928:
1.196.4.24 raeburn 2929: sub do_redirect {
2930: my ($r,$url,$msg) = @_;
2931: $r->print(
1.196.4.28.2. (raeburn 2932:): &Apache::loncommon::start_page('Loading ...',undef,
2933:): {'redirect' => [2,$url]}).
1.196.4.24 raeburn 2934: '<div style="padding:0;clear:both;margin:0;border:0"></div>'."\n".
2935: "$msg\n".
2936: &Apache::loncommon::end_page());
2937: return;
2938: }
2939:
1.196.4.28.2. (raeburn 2940:): sub toggle_options_js {
2941:): return <<"ENDSCRIPT";
2942:): <script type="text/javascript">
2943:): // <![CDATA[
2944:): function toggleOptions(form,radioname,divid) {
2945:): var num = form.elements[radioname].length;
2946:): if (num) {
2947:): var setvis = '';
2948:): var onvalue = 'user';
2949:): if (radioname == 'settimezone') {
2950:): onvalue = '1';
2951:): }
2952:): for (var i=0; i<num; i++) {
2953:): if (form.elements[radioname][i].checked) {
2954:): if (form.elements[radioname][i].value == onvalue) {
2955:): if (document.getElementById(divid)) {
2956:): document.getElementById(divid).style.display = 'inline-block';
2957:): }
2958:): setvis = 1;
2959:): }
2960:): break;
2961:): }
2962:): }
2963:): if (!setvis) {
2964:): if (document.getElementById(divid)) {
2965:): document.getElementById(divid).style.display = 'none';
2966:): }
2967:): }
2968:): }
2969:): return;
2970:): }
2971:): // ]]>
2972:): </script>
2973:): ENDSCRIPT
2974:): }
2975:):
2976:): sub selectbox {
2977:): my ($name,$value,$readonly,$functionref,@idlist)=@_;
2978:): my $selout = '<select name="'.$name.'">';
2979:): foreach my $id (@idlist) {
2980:): $selout.='<option value="'.$id.'"';
2981:): if ($id eq $value) {
2982:): $selout.=' selected="selected"';
2983:): }
2984:): if ($readonly) {
2985:): $selout .= ' disabled="disabled"';
2986:): }
2987:): $selout.='>'.&{$functionref}($id).'</option>';
2988:): }
2989:): $selout.='</select>';
2990:): return $selout;
2991:): }
2992:):
1.1 www 2993: 1;
2994: __END__
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>