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