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