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