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