Annotation of loncom/interface/lonpreferences.pm, revision 1.125.4.2
1.1 www 1: # The LearningOnline Network
2: # Preferences
3: #
1.125.4.2! raeburn 4: # $Id: lonpreferences.pm,v 1.125.4.1 2009/05/20 15:05:19 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.2! raeburn 690: my $status='';
! 691: if ($domcoord{'domcoord.author'} eq 'blocked') {
! 692: $status=&mt('on');
! 693: } else {
! 694: $status=&mt('off');
! 695: }
1.125.4.1 raeburn 696: my $message=&Apache::lonhtmlcommon::confirm_success(&mt('Set [_1] to [_2]','<i>'.&mt('Block access to construction space').'</i>','<tt>'.$status.'</tt>'));
697: $message=&Apache::loncommon::confirmwrapper($message);
698: $r->print(<<ENDVCSCREEN);
699: $message
700: ENDVCSCREEN
1.119 www 701: }
702:
1.118 www 703: #################################################################
704: ## Lock Subroutines #
705: #################################################################
706:
707: sub lockwarning {
708: my $r = shift;
709: my $title=&mt('Action locked');
710: my $texttop=&mt('LON-CAPA is currently performing the following actions:');
711: my $textbottom=&mt('Changing roles or logging out may result in data corruption.');
712: my ($num,%which)=&Apache::lonnet::get_locks();
713: my $which='';
714: foreach my $id (keys %which) {
715: $which.='<li>'.$which{$id}.'</li>';
716: }
717: my $change=&mt('Override');
718: $r->print(<<ENDSCREEN);
719: <form name="prefs" action="/adm/preferences" method="post">
720: <input type="hidden" name="action" value="verify_and_change_locks" />
721: <h1>$title</h1>
722: $texttop
723: <ul>
724: $which
725: </ul>
726: $textbottom
727: <input type="submit" value="$change" />
728: </form>
729: ENDSCREEN
730: }
731:
732: sub verify_and_change_lockwarning {
733: my $r = shift;
734: &Apache::lonnet::remove_all_locks();
735: $r->print(&mt('Cleared locks.'));
736: }
737:
738:
1.105 www 739: ################################################################
1.20 www 740: # Message Forward #
741: ################################################################
742:
743: sub msgforwardchanger {
1.102 raeburn 744: my ($r,$message) = @_;
1.59 albertel 745: my $user = $env{'user.name'};
746: my $domain = $env{'user.domain'};
1.102 raeburn 747: my %userenv = &Apache::lonnet::get('environment',['msgforward','notification','critnotification','notifywithhtml']);
1.20 www 748: my $msgforward=$userenv{'msgforward'};
1.102 raeburn 749: my %lt = &Apache::lonlocal::texthash(
750: all => 'All',
751: crit => 'Critical only',
752: reg => 'Non-critical only',
753: foad => 'Forwarding Address(es)',
1.113 raeburn 754: noti => 'Notification E-mail Address(es)',
1.110 bisitz 755: foad_exmpl => 'e.g. <tt>userA:domain1,userB:domain2,...</tt>',
1.125.4.1 raeburn 756: mnot => 'E-mail Address(es) which should be notified about new LON-CAPA messages',
1.110 bisitz 757: mnot_exmpl => 'e.g. <tt>joe@doe.com</tt>',
1.125.4.1 raeburn 758: chg => 'Save',
1.104 raeburn 759: email => 'The e-mail address entered in row ',
1.102 raeburn 760: notv => 'is not a valid e-mail address',
1.125.4.1 raeburn 761: toen => "To enter multiple addresses, enter one address at a time, click 'Save' and then add the next one",
762: prme => 'Back',
1.102 raeburn 763: );
1.113 raeburn 764: my $forwardingHelp = &Apache::loncommon::help_open_topic("Prefs_Forwarding");
765: my $notificationHelp = &Apache::loncommon::help_open_topic("Prefs_Notification");
766: my $criticalMessageHelp = &Apache::loncommon::help_open_topic("Course_Critical_Message");
1.102 raeburn 767: my @allow_html = split(/,/,$userenv{'notifywithhtml'});
768: my %allnot = &get_notifications(\%userenv);
769: my $validatescript = &Apache::lonhtmlcommon::javascript_valid_email();
770: my $jscript = qq|
771: <script type="text/javascript">
772: function validate() {
773: for (var i=0; i<document.prefs.numnotify.value; i++) {
1.104 raeburn 774: var checkaddress = 0;
1.102 raeburn 775: var addr = document.prefs.elements['address_'+i].value;
1.104 raeburn 776: var rownum = i+1;
1.102 raeburn 777: if (i < document.prefs.numnotify.value-1) {
1.104 raeburn 778: if (document.prefs.elements['modify_notify_'+i].checked) {
1.102 raeburn 779: checkaddress = 1;
1.104 raeburn 780: }
1.102 raeburn 781: } else {
782: if (document.prefs.elements['add_notify_'+i].checked == true) {
783: checkaddress = 1;
784: }
785: }
1.104 raeburn 786: if (checkaddress == 1) {
1.102 raeburn 787: var addr = document.prefs.elements['address_'+i].value;
788: if (validmail(document.prefs.elements['address_'+i]) == false) {
1.104 raeburn 789: var multimsg = '';
790: if (addr.indexOf(",") >= 0) {
791: multimsg = "\\n($lt{'toen'}).";
792: }
1.110 bisitz 793: alert("$lt{'email'} "+rownum+" ('"+addr+"') $lt{'notv'}."+multimsg);
1.102 raeburn 794: return;
795: }
796: }
797: }
798: document.prefs.submit();
799: }
1.104 raeburn 800:
801: function address_changes (adnum) {
802: if (!document.prefs.elements['del_notify_'+adnum].checked) {
803: document.prefs.elements['modify_notify_'+adnum].checked = true;
804: }
805: }
806:
807: function new_address(adnum) {
808: document.prefs.elements['add_notify_'+adnum].checked = true;
809: }
810:
811: function delete_address(adnum) {
812: if (document.prefs.elements['del_notify_'+adnum].checked) {
813: document.prefs.elements['modify_notify_'+adnum].checked = false;
814: }
815: }
816:
817: function modify_address(adnum) {
818: if (document.prefs.elements['modify_notify_'+adnum].checked) {
819: document.prefs.elements['del_notify_'+adnum].checked = false;
820: }
821: }
822:
1.102 raeburn 823: $validatescript
824: </script>
825: |;
1.20 www 826: $r->print(<<ENDMSG);
1.102 raeburn 827: $jscript
828: $message
1.113 raeburn 829: <h3>$lt{'foad'} $forwardingHelp</h3>
1.88 albertel 830: <form name="prefs" action="/adm/preferences" method="post">
1.20 www 831: <input type="hidden" name="action" value="verify_and_change_msgforward" />
1.110 bisitz 832: $lt{'foad'} ($lt{'foad_exmpl'}):
1.113 raeburn 833: <input type="text" size="40" value="$msgforward" name="msgforward" /><br />
834: <h3>$lt{'noti'} $notificationHelp</h3>
1.110 bisitz 835: $lt{'mnot'} ($lt{'mnot_exmpl'}):<br />
1.102 raeburn 836: ENDMSG
837: my @sortforwards = sort (keys(%allnot));
838: my $output = &Apache::loncommon::start_data_table().
839: &Apache::loncommon::start_data_table_header_row().
1.104 raeburn 840: '<th> </th>'.
1.102 raeburn 841: '<th>'.&mt('Action').'</th>'.
842: '<th>'.&mt('Notification address').'</th><th>'.
1.113 raeburn 843: &mt('Types of message for which notification is sent').
844: $criticalMessageHelp.'</th><th>'.
1.104 raeburn 845: &mt('Excerpt retains HTML tags in message').'</th>'.
1.102 raeburn 846: &Apache::loncommon::end_data_table_header_row();
847: my $num = 0;
1.104 raeburn 848: my $counter = 1;
1.102 raeburn 849: foreach my $item (@sortforwards) {
850: $output .= &Apache::loncommon::start_data_table_row().
1.104 raeburn 851: '<td><b>'.$counter.'</b></td>'.
852: '<td><span class="LC_nobreak"><label>'.
853: '<input type="checkbox" name="modify_notify_'.
854: $num.'" onclick="javscript:modify_address('."'$num'".')" />'.
855: &mt('Modify').'</label></span> '.
856: '<span class="LC_nobreak"><label>'.
857: '<input type="checkbox" name="del_notify_'.$num.
858: '" onclick="javscript:delete_address('."'$num'".')" />'.
859: &mt('Delete').'</label></span></td>'.
1.102 raeburn 860: '<td><input type="text" value="'.$item.'" name="address_'.
1.104 raeburn 861: $num.'" onFocus="javascript:address_changes('."'$num'".
862: ')" /></td><td>';
1.102 raeburn 863: my %chk;
864: if (defined($allnot{$item}{'crit'})) {
865: if (defined($allnot{$item}{'reg'})) {
866: $chk{'all'} = 'checked="checked" ';
867: } else {
868: $chk{'crit'} = 'checked="checked" ';
869: }
870: } else {
871: $chk{'reg'} = 'checked="checked" ';
872: }
873: foreach my $type ('all','crit','reg') {
874: $output .= '<span class="LC_nobreak"><label>'.
875: '<input type="radio" name="notify_type_'.$num.
1.104 raeburn 876: '" value="'.$type.'" '.$chk{$type}.
877: ' onchange="javascript:address_changes('."'$num'".')" />'.
878: $lt{$type}.'</label></span> ';
1.102 raeburn 879: }
880: my $htmlon = '';
881: my $htmloff = '';
882: if (grep/^\Q$item\E/,@allow_html) {
883: $htmlon = 'checked="checked" ';
884: } else {
885: $htmloff = 'checked="checked" ';
886: }
887: $output .= '</td><td><label><input type="radio" name="html_'.$num.
1.104 raeburn 888: '" value="1" '.$htmlon.
889: ' onchange="javascript:address_changes('."'$num'".')" />'.
890: &mt('Yes').'</label> '.
1.102 raeburn 891: '<label><input type="radio" name="html_'.$num.'" value="0" '.
1.104 raeburn 892: $htmloff. ' onchange="javascript:address_changes('."'$num'".
893: ')" />'.
894: &mt('No').'</label></td>'.
1.102 raeburn 895: &Apache::loncommon::end_data_table_row();
896: $num ++;
1.104 raeburn 897: $counter ++;
1.102 raeburn 898: }
899: my %defchk = (
900: all => 'checked="checked" ',
901: crit => '',
902: reg => '',
903: );
904: $output .= &Apache::loncommon::start_data_table_row().
1.104 raeburn 905: '<td><b>'.$counter.'</b></td>'.
906: '<td><span class="LC_nobreak"><label>'.
907: '<input type="checkbox" name="add_notify_'.$num.
908: '" value="1" />'.&mt('Add new address').'</label></span></td>'.
1.102 raeburn 909: '<td><input type="text" value="" name="address_'.$num.
1.104 raeburn 910: '" onFocus="javascript:new_address('."'$num'".')" /></td><td>';
1.102 raeburn 911: foreach my $type ('all','crit','reg') {
912: $output .= '<span class="LC_nobreak"><label>'.
913: '<input type="radio" name="notify_type_'.$num.
914: '" value="'.$type.'" '.$defchk{$type}.'/>'.
915: $lt{$type}.'</label></span> ';
916: }
917: $output .= '</td><td><label><input type="radio" name="html_'.$num.
918: '" value="1" />'.&mt('Yes').'</label> '.
919: '<label><input type="radio" name="html_'.$num.'" value="0" '.
920: ' checked="checked" />'.
921: &mt('No').'</label></td>'.
922: &Apache::loncommon::end_data_table_row().
923: &Apache::loncommon::end_data_table();
924: $num ++;
925: $r->print($output);
926: $r->print(qq|
1.113 raeburn 927: <br /><hr />
1.102 raeburn 928: <input type="hidden" name="numnotify" value="$num" />
929: <input type="button" value="$lt{'prme'}" onclick="location.href='/adm/preferences'" />
1.125.4.1 raeburn 930: <input type="button" value="$lt{'chg'}" onclick="javascript:validate()" />
1.20 www 931: </form>
1.102 raeburn 932: |);
933:
934: }
935:
936: sub get_notifications {
937: my ($userenv) = @_;
938: my %allnot;
939: my @critnot = split(/,/,$userenv->{'critnotification'});
940: my @regnot = split(/,/,$userenv->{'notification'});
941: foreach my $item (@critnot) {
942: $allnot{$item}{crit} = 1;
943: }
944: foreach my $item (@regnot) {
945: $allnot{$item}{reg} = 1;
946: }
947: return %allnot;
1.20 www 948: }
949:
950: sub verify_and_change_msgforward {
951: my $r = shift;
1.59 albertel 952: my $user = $env{'user.name'};
953: my $domain = $env{'user.domain'};
1.20 www 954: my $newscreen = '';
955: my $message='';
1.59 albertel 956: foreach (split(/\,/,$env{'form.msgforward'})) {
1.20 www 957: my ($msuser,$msdomain)=split(/[\@\:]/,$_);
1.95 albertel 958: $msuser = &LONCAPA::clean_username($msuser);
959: $msdomain = &LONCAPA::clean_domain($msdomain);
1.20 www 960: if (($msuser) && ($msdomain)) {
961: if (&Apache::lonnet::homeserver($msuser,$msdomain) ne 'no_host') {
962: $newscreen.=$msuser.':'.$msdomain.',';
963: } else {
1.125.4.1 raeburn 964: $message.= &mt('No such user: ').'<tt>'.$msuser.':'.$msdomain.'</tt><br />';
1.20 www 965: }
966: }
967: }
968: $newscreen=~s/\,$//;
969: if ($newscreen) {
970: &Apache::lonnet::put('environment',{'msgforward' => $newscreen});
1.116 raeburn 971: &Apache::lonnet::appenv({'environment.msgforward' => $newscreen});
1.110 bisitz 972: $message .= &mt('Set message forwarding to ').'<tt>"'.$newscreen.'"</tt>.'
973: .'<br />';
1.20 www 974: } else {
975: &Apache::lonnet::del('environment',['msgforward']);
1.125.4.1 raeburn 976: &Apache::lonnet::delenv('environment.msgforward');
1.102 raeburn 977: $message.= &mt("Set message forwarding to 'off'.").'<br />';
1.20 www 978: }
1.102 raeburn 979: my $critnotification;
980: my $notification;
981: my $notify_with_html;
982: my $lastnotify = $env{'form.numnotify'}-1;
1.104 raeburn 983: my $totaladdresses = 0;
1.102 raeburn 984: for (my $i=0; $i<$env{'form.numnotify'}; $i++) {
985: if ((!defined($env{'form.del_notify_'.$i})) &&
1.104 raeburn 986: ((($i==$lastnotify) && ($env{'form.add_notify_'.$lastnotify} == 1)) ||
1.102 raeburn 987: ($i<$lastnotify))) {
988: if (defined($env{'form.address_'.$i})) {
989: if ($env{'form.notify_type_'.$i} eq 'all') {
990: $critnotification .= $env{'form.address_'.$i}.',';
991: $notification .= $env{'form.address_'.$i}.',';
992: } elsif ($env{'form.notify_type_'.$i} eq 'crit') {
993: $critnotification .= $env{'form.address_'.$i}.',';
994: } elsif ($env{'form.notify_type_'.$i} eq 'reg') {
995: $notification .= $env{'form.address_'.$i}.',';
996: }
997: if ($env{'form.html_'.$i} eq '1') {
998: $notify_with_html .= $env{'form.address_'.$i}.',';
999: }
1.104 raeburn 1000: $totaladdresses ++;
1.102 raeburn 1001: }
1002: }
1003: }
1004: $critnotification =~ s/,$//;
1005: $critnotification=~s/\s//gs;
1006: $notification =~ s/,$//;
1.20 www 1007: $notification=~s/\s//gs;
1.102 raeburn 1008: $notify_with_html =~ s/,$//;
1009: $notify_with_html =~ s/\s//gs;
1.20 www 1010: if ($notification) {
1011: &Apache::lonnet::put('environment',{'notification' => $notification});
1.116 raeburn 1012: &Apache::lonnet::appenv({'environment.notification' => $notification});
1.110 bisitz 1013: $message.=&mt('Set non-critical message notification address(es) to ').'<tt>"'.$notification.'"</tt>.<br />';
1.20 www 1014: } else {
1015: &Apache::lonnet::del('environment',['notification']);
1.125.4.1 raeburn 1016: &Apache::lonnet::delenv('environment.notification');
1.110 bisitz 1017: $message.=&mt("Set non-critical message notification to 'off'.").'<br />';
1.20 www 1018: }
1019: if ($critnotification) {
1020: &Apache::lonnet::put('environment',{'critnotification' => $critnotification});
1.116 raeburn 1021: &Apache::lonnet::appenv({'environment.critnotification' => $critnotification});
1.110 bisitz 1022: $message.=&mt('Set critical message notification address(es) to ').'<tt>"'.$critnotification.'"</tt>.<br />';
1.20 www 1023: } else {
1024: &Apache::lonnet::del('environment',['critnotification']);
1.125.4.1 raeburn 1025: &Apache::lonnet::delenv('environment.critnotification');
1.110 bisitz 1026: $message.=&mt("Set critical message notification to 'off'.").'<br />';
1.102 raeburn 1027: }
1028: if ($critnotification || $notification) {
1029: if ($notify_with_html) {
1030: &Apache::lonnet::put('environment',{'notifywithhtml' => $notify_with_html});
1.116 raeburn 1031: &Apache::lonnet::appenv({'environment.notifywithhtml' => $notify_with_html});
1.110 bisitz 1032: $message.=&mt('Set address(es) to receive excerpts with html retained ').'<tt>"'.$notify_with_html.'"</tt>.';
1.102 raeburn 1033: } else {
1034: &Apache::lonnet::del('environment',['notifywithhtml']);
1.125.4.1 raeburn 1035: &Apache::lonnet::delenv('environment.notifywithhtml');
1.104 raeburn 1036: if ($totaladdresses == 1) {
1037: $message.=&mt("Set notification address to receive excerpts with html stripped.");
1038: } else {
1039: $message.=&mt("Set all notification addresses to receive excerpts with html stripped.");
1040: }
1.102 raeburn 1041: }
1042: } else {
1043: &Apache::lonnet::del('environment',['notifywithhtml']);
1.125.4.1 raeburn 1044: &Apache::lonnet::delenv('environment.notifywithhtml');
1.102 raeburn 1045: }
1046: if ($message) {
1047: $message .= '<br /><hr />';
1.20 www 1048: }
1.109 albertel 1049: &Apache::loncommon::flush_email_cache($user,$domain);
1.102 raeburn 1050: &msgforwardchanger($r,$message);
1.6 www 1051: }
1052:
1.12 www 1053: ################################################################
1.19 www 1054: # Colors #
1.12 www 1055: ################################################################
1056:
1.19 www 1057: sub colorschanger {
1.12 www 1058: my $r = shift;
1.19 www 1059: # figure out colors
1.80 albertel 1060: my $function=&Apache::loncommon::get_users_function();
1.19 www 1061: my $domain=&Apache::loncommon::determinedomain();
1.125.4.1 raeburn 1062: my %colortypes=('pgbg' => 'Page Background Color',
1063: 'tabbg' => 'Header Background Color',
1064: 'sidebg'=> 'Header Border Color',
1065: 'font' => 'Font Color',
1066: 'link' => 'Un-Visited Link Color',
1067: 'vlink' => 'Visited Link Color',
1068: 'alink' => 'Active Link Color');
1.82 albertel 1069: my $start_data_table = &Apache::loncommon::start_data_table();
1.19 www 1070: my $chtable='';
1.22 matthew 1071: foreach my $item (sort(keys(%colortypes))) {
1.19 www 1072: my $curcol=&Apache::loncommon::designparm($function.'.'.$item,$domain);
1.82 albertel 1073: $chtable.=&Apache::loncommon::start_data_table_row().
1.83 albertel 1074: '<td>'.$colortypes{$item}.'</td><td style="background: '.$curcol.
1.19 www 1075: '"> </td><td><input name="'.$item.
1.21 www 1076: '" size="10" value="'.$curcol.
1077: '" /></td><td><a href="javascript:pjump('."'color_custom','".$colortypes{$item}.
1.19 www 1078: "','".$curcol."','"
1.125.4.1 raeburn 1079: .$item."','parmform.pres','psub'".');">'.&mt('Select').'</a></td>'.
1.83 albertel 1080: &Apache::loncommon::end_data_table_row()."\n";
1.19 www 1081: }
1.82 albertel 1082: my $end_data_table = &Apache::loncommon::end_data_table();
1.23 matthew 1083: my $pjump_def = &Apache::lonhtmlcommon::pjump_javascript_definition();
1.125.4.1 raeburn 1084: my $savebutton = &mt('Save');
1085: my $resetbutton = &mt('Reset All');
1086: my $resetbuttondesc = &mt('Reset All Colors to Default');
1.19 www 1087: $r->print(<<ENDCOL);
1.82 albertel 1088: <script type="text/javascript">
1.19 www 1089:
1090: function pclose() {
1091: parmwin=window.open("/adm/rat/empty.html","LONCAPAparms",
1092: "height=350,width=350,scrollbars=no,menubar=no");
1093: parmwin.close();
1094: }
1095:
1.23 matthew 1096: $pjump_def
1.19 www 1097:
1098: function psub() {
1099: pclose();
1100: if (document.parmform.pres_marker.value!='') {
1.21 www 1101: if (document.parmform.pres_type.value!='') {
1.77 albertel 1102: eval('document.prefs.'+
1.21 www 1103: document.parmform.pres_marker.value+
1.19 www 1104: '.value=document.parmform.pres_value.value;');
1.21 www 1105: }
1.19 www 1106: } else {
1107: document.parmform.pres_value.value='';
1108: document.parmform.pres_marker.value='';
1109: }
1110: }
1111:
1112:
1113: </script>
1.21 www 1114: <form name="parmform">
1115: <input type="hidden" name="pres_marker" />
1116: <input type="hidden" name="pres_type" />
1117: <input type="hidden" name="pres_value" />
1118: </form>
1.88 albertel 1119: <form name="prefs" action="/adm/preferences" method="post">
1.19 www 1120: <input type="hidden" name="action" value="verify_and_change_colors" />
1.82 albertel 1121: $start_data_table
1.19 www 1122: $chtable
1.82 albertel 1123: $end_data_table
1.19 www 1124: </table>
1.125.4.1 raeburn 1125: <input type="submit" value="$savebutton" />
1126: <input type="submit" name="resetall" value="$resetbutton" title="$resetbuttondesc" />
1.12 www 1127: </form>
1.19 www 1128: ENDCOL
1.12 www 1129: }
1130:
1.19 www 1131: sub verify_and_change_colors {
1.12 www 1132: my $r = shift;
1.19 www 1133: # figure out colors
1.80 albertel 1134: my $function=&Apache::loncommon::get_users_function();
1.19 www 1135: my $domain=&Apache::loncommon::determinedomain();
1.125.4.1 raeburn 1136: my %colortypes=('pgbg' => 'Page Background Color',
1137: 'tabbg' => 'Header Background Color',
1138: 'sidebg'=> 'Header Border Color',
1139: 'font' => 'Font Color',
1140: 'link' => 'Un-Visited Link Color',
1141: 'vlink' => 'Visited Link Color',
1142: 'alink' => 'Active Link Color');
1.19 www 1143:
1.12 www 1144: my $message='';
1.21 www 1145: foreach my $item (keys %colortypes) {
1.59 albertel 1146: my $color=$env{'form.'.$item};
1.21 www 1147: my $entry='color.'.$function.'.'.$item;
1.59 albertel 1148: if (($color=~/^\#[0-9A-Fa-f]{6}$/) && (!$env{'form.resetall'})) {
1.21 www 1149: &Apache::lonnet::put('environment',{$entry => $color});
1.116 raeburn 1150: &Apache::lonnet::appenv({'environment.'.$entry => $color});
1.125.4.1 raeburn 1151: $message.=&Apache::lonhtmlcommon::confirm_success(&mt('Set [_1] to [_2]','<i>'.$colortypes{$item}.'</i>','<tt>"'.$color.'"</tt>'))
1152: .'<br />';
1.21 www 1153: } else {
1154: &Apache::lonnet::del('environment',[$entry]);
1.125.4.1 raeburn 1155: &Apache::lonnet::delenv('environment.'.$entry);
1156: $message.=&Apache::lonhtmlcommon::confirm_success(&mt('Reset [_1]','<i>'.$colortypes{$item}.'</i>'))
1157: .'<br />';
1.21 www 1158: }
1159: }
1.125.4.1 raeburn 1160: $message=&Apache::loncommon::confirmwrapper($message);
1161:
1.84 albertel 1162: my $now = time;
1163: &Apache::lonnet::put('environment',{'color.timestamp' => $now});
1.116 raeburn 1164: &Apache::lonnet::appenv({'environment.color.timestamp' => $now});
1.84 albertel 1165:
1.19 www 1166: $r->print(<<ENDVCCOL);
1.12 www 1167: $message
1.88 albertel 1168: <form name="client" action="/adm/preferences" method="post">
1.21 www 1169: <input type="hidden" name="action" value="changecolors" />
1170: </form>
1.19 www 1171: ENDVCCOL
1.12 www 1172: }
1173:
1.4 matthew 1174: ######################################################
1175: # password handler subroutines #
1176: ######################################################
1.3 matthew 1177: sub passwordchanger {
1.94 raeburn 1178: my ($r,$errormessage,$caller,$mailtoken) = @_;
1.4 matthew 1179: # This function is a bit of a mess....
1.3 matthew 1180: # Passwords are encrypted using londes.js (DES encryption)
1.4 matthew 1181: $errormessage = ($errormessage || '');
1.94 raeburn 1182: my ($user,$domain,$currentpass,$defdom);
1183: if ((!defined($caller)) || ($caller eq 'preferences')) {
1184: $user = $env{'user.name'};
1185: $domain = $env{'user.domain'};
1186: if (!defined($caller)) {
1187: $caller = 'preferences';
1188: }
1189: } elsif ($caller eq 'reset_by_email') {
1190: $defdom = $r->dir_config('lonDefDomain');
1191: my %data = &Apache::lonnet::tmpget($mailtoken);
1192: if (keys(%data) == 0) {
1.125.4.1 raeburn 1193: $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.',
1194: '<a href="/adm/resetpw">','</a>')
1195: );
1.94 raeburn 1196: return;
1197: }
1198: if (defined($data{time})) {
1199: if (time - $data{'time'} < 7200) {
1200: $user = $data{'username'};
1201: $domain = $data{'domain'};
1202: $currentpass = $data{'temppasswd'};
1203: } else {
1204: $r->print(&mt('Sorry, the token generated when you requested a password reset has expired.').'<br />');
1205: return;
1206: }
1207: } else {
1208: $r->print(&mt('Sorry, the URL generated when you requested reset of your password contained incomplete information.').'<br />');
1209: return;
1210: }
1211: } else {
1212: $r->print(&mt('Page requested in unexpected context').'<br />');
1213: return;
1214: }
1.3 matthew 1215: my $currentauth=&Apache::lonnet::queryauthenticate($user,$domain);
1216: # Check for authentication types that allow changing of the password.
1217: return if ($currentauth !~ /^(unix|internal):/);
1218: #
1219: # Generate keys
1220: my ($lkey_cpass ,$ukey_cpass ) = &des_keys();
1221: my ($lkey_npass1,$ukey_npass1) = &des_keys();
1222: my ($lkey_npass2,$ukey_npass2) = &des_keys();
1.4 matthew 1223: # Store the keys in the log files
1.3 matthew 1224: my $lonhost = $r->dir_config('lonHostID');
1225: my $logtoken=Apache::lonnet::reply('tmpput:'
1226: .$ukey_cpass . $lkey_cpass .'&'
1227: .$ukey_npass1 . $lkey_npass1.'&'
1228: .$ukey_npass2 . $lkey_npass2,
1229: $lonhost);
1.4 matthew 1230: # Hexify the keys for output as javascript variables
1.94 raeburn 1231: my %hexkey;
1232: $hexkey{'ukey_cpass'} = hex($ukey_cpass);
1233: $hexkey{'lkey_cpass'} = hex($lkey_cpass);
1234: $hexkey{'ukey_npass1'} = hex($ukey_npass1);
1235: $hexkey{'lkey_npass1'} = hex($lkey_npass1);
1236: $hexkey{'ukey_npass2'} = hex($ukey_npass2);
1237: $hexkey{'lkey_npass2'} = hex($lkey_npass2);
1.3 matthew 1238: # Output javascript to deal with passwords
1.4 matthew 1239: # Output DES javascript
1.3 matthew 1240: {
1241: my $include = $r->dir_config('lonIncludes');
1242: my $jsh=Apache::File->new($include."/londes.js");
1243: $r->print(<$jsh>);
1244: }
1.94 raeburn 1245: $r->print(&jscript_send($caller));
1.3 matthew 1246: $r->print(<<ENDFORM);
1.94 raeburn 1247: $errormessage
1248:
1249: <p>
1250: <!-- We separate the forms into 'server' and 'client' in order to
1251: ensure that unencrypted passwords will not be sent out by a
1252: crappy browser -->
1253: ENDFORM
1254: $r->print(&server_form($logtoken,$caller,$mailtoken));
1255: $r->print(&client_form($caller,\%hexkey,$currentpass,$defdom));
1256:
1257: #
1258: return;
1259: }
1260:
1261: sub jscript_send {
1262: my ($caller) = @_;
1263: my $output = qq|
1.3 matthew 1264: <script language="JavaScript">
1265:
1266: function send() {
1267: uextkey=this.document.client.elements.ukey_cpass.value;
1268: lextkey=this.document.client.elements.lkey_cpass.value;
1269: initkeys();
1270:
1.52 raeburn 1271: this.document.pserver.elements.currentpass.value
1.3 matthew 1272: =crypted(this.document.client.elements.currentpass.value);
1273:
1274: uextkey=this.document.client.elements.ukey_npass1.value;
1275: lextkey=this.document.client.elements.lkey_npass1.value;
1276: initkeys();
1.52 raeburn 1277: this.document.pserver.elements.newpass_1.value
1.3 matthew 1278: =crypted(this.document.client.elements.newpass_1.value);
1279:
1280: uextkey=this.document.client.elements.ukey_npass2.value;
1281: lextkey=this.document.client.elements.lkey_npass2.value;
1282: initkeys();
1.52 raeburn 1283: this.document.pserver.elements.newpass_2.value
1.3 matthew 1284: =crypted(this.document.client.elements.newpass_2.value);
1.94 raeburn 1285: |;
1286: if ($caller eq 'reset_by_email') {
1287: $output .= qq|
1288: this.document.pserver.elements.uname.value =
1289: this.document.client.elements.uname.value;
1290: this.document.pserver.elements.udom.value =
1291: this.document.client.elements.udom.options[this.document.client.elements.udom.selectedIndex].value;
1292: |;
1293: }
1294: $ output .= qq|
1.52 raeburn 1295: this.document.pserver.submit();
1.3 matthew 1296: }
1297: </script>
1.94 raeburn 1298: |;
1299: }
1.3 matthew 1300:
1.94 raeburn 1301: sub client_form {
1302: my ($caller,$hexkey,$currentpass,$defdom) = @_;
1.99 www 1303: my %lt=&Apache::lonlocal::texthash(
1.115 raeburn 1304: 'email' => 'E-mail Address',
1.99 www 1305: 'username' => 'Username',
1306: 'domain' => 'Domain',
1307: 'currentpass' => 'Current Password',
1308: 'newpass' => 'New Password',
1309: 'confirmpass' => 'Confirm Password',
1.125.4.1 raeburn 1310: 'changepass' => 'Save');
1.99 www 1311:
1.94 raeburn 1312: my $output = qq|
1.3 matthew 1313: <form name="client" >
1314: <table>
1.94 raeburn 1315: |;
1316: if ($caller eq 'reset_by_email') {
1317: $output .= qq|
1.99 www 1318: <tr><td class="LC_preferences_labeltext"><label for="email">$lt{'email'}</label>:</td>
1.97 raeburn 1319: <td><input type="text" name="email" size="30" /> </td></tr>
1.99 www 1320: <tr><td class="LC_preferences_labeltext"><label for="uname">$lt{'username'}</label>:</td>
1.94 raeburn 1321: <td>
1.97 raeburn 1322: <input type="text" name="uname" size="15" />
1.94 raeburn 1323: <input type="hidden" name="currentpass" value="$currentpass" />
1324: </td></tr>
1.115 raeburn 1325: <tr><td class="LC_preferences_labeltext"><label for="udom">$lt{'domain'}</label>:</td>
1.94 raeburn 1326: <td>
1327: |;
1328: $output .= &Apache::loncommon::select_dom_form($defdom,'udom').'
1329: </td>
1330: </tr>
1331: ';
1332: } else {
1333: $output .= qq|
1.99 www 1334: <tr><td class="LC_preferences_labeltext"><label for="currentpass">$lt{'currentpass'}</label></td>
1.4 matthew 1335: <td><input type="password" name="currentpass" size="10"/> </td></tr>
1.94 raeburn 1336: |;
1337: }
1338: $output .= <<"ENDFORM";
1.99 www 1339: <tr><td class="LC_preferences_labeltext"><label for="newpass_1">$lt{'newpass'}</label></td>
1.4 matthew 1340: <td><input type="password" name="newpass_1" size="10" /> </td></tr>
1.99 www 1341: <tr><td class="LC_preferences_labeltext"><label for="newpass_2">$lt{'confirmpass'}</label></td>
1.4 matthew 1342: <td><input type="password" name="newpass_2" size="10" /> </td></tr>
1.3 matthew 1343: <tr><td colspan="2" align="center">
1.125.4.1 raeburn 1344: <input type="button" value="$lt{'changepass'}" onClick="send();" />
1.3 matthew 1345: </table>
1.94 raeburn 1346: <input type="hidden" name="ukey_cpass" value="$hexkey->{'ukey_cpass'}" />
1347: <input type="hidden" name="lkey_cpass" value="$hexkey->{'lkey_cpass'}" />
1348: <input type="hidden" name="ukey_npass1" value="$hexkey->{'ukey_npass1'}" />
1349: <input type="hidden" name="lkey_npass1" value="$hexkey->{'lkey_npass1'}" />
1350: <input type="hidden" name="ukey_npass2" value="$hexkey->{'ukey_npass2'}" />
1351: <input type="hidden" name="lkey_npass2" value="$hexkey->{'lkey_npass2'}" />
1.3 matthew 1352: </form>
1353: </p>
1354: ENDFORM
1.94 raeburn 1355: return $output;
1356: }
1357:
1358: sub server_form {
1359: my ($logtoken,$caller,$mailtoken) = @_;
1360: my $action = '/adm/preferences';
1361: if ($caller eq 'reset_by_email') {
1362: $action = '/adm/resetpw';
1363: }
1364: my $output = qq|
1365: <form name="pserver" action="$action" method="post">
1366: <input type="hidden" name="logtoken" value="$logtoken" />
1367: <input type="hidden" name="currentpass" value="" />
1368: <input type="hidden" name="newpass_1" value="" />
1369: <input type="hidden" name="newpass_2" value="" />
1370: |;
1371: if ($caller eq 'reset_by_email') {
1372: $output .= qq|
1373: <input type="hidden" name="token" value="$mailtoken" />
1374: <input type="hidden" name="uname" value="" />
1375: <input type="hidden" name="udom" value="" />
1376:
1377: |;
1378: }
1379: $output .= qq|
1380: <input type="hidden" name="action" value="verify_and_change_pass" />
1381: </form>
1382: |;
1383: return $output;
1.3 matthew 1384: }
1385:
1386: sub verify_and_change_password {
1.94 raeburn 1387: my ($r,$caller,$mailtoken) = @_;
1388: my ($user,$domain,$homeserver);
1389: if ($caller eq 'reset_by_email') {
1390: $user = $env{'form.uname'};
1391: $domain = $env{'form.udom'};
1392: if ($user ne '' && $domain ne '') {
1393: $homeserver = &Apache::lonnet::homeserver($user,$domain);
1394: if ($homeserver eq 'no_host') {
1.99 www 1395: &passwordchanger($r,"<p>\n<span class='LC_error'>".
1396: &mt("Invalid username and/or domain")."</span>\n</p>",
1.94 raeburn 1397: $caller,$mailtoken);
1398: return 1;
1399: }
1400: } else {
1.99 www 1401: &passwordchanger($r,"<p>\n<span class='LC_error'>".
1402: &mt("Username and domain were blank")."</span>\n</p>",
1.94 raeburn 1403: $caller,$mailtoken);
1404: return 1;
1405: }
1406: } else {
1407: $user = $env{'user.name'};
1408: $domain = $env{'user.domain'};
1409: $homeserver = $env{'user.home'};
1410: }
1.3 matthew 1411: my $currentauth=&Apache::lonnet::queryauthenticate($user,$domain);
1.4 matthew 1412: # Check for authentication types that allow changing of the password.
1.94 raeburn 1413: if ($currentauth !~ /^(unix|internal):/) {
1414: if ($caller eq 'reset_by_email') {
1.99 www 1415: &passwordchanger($r,"<p>\n<span class='LC_error'>".
1416: &mt("Authentication type for this user can not be changed by this mechanism").
1417: "</span>\n</p>",
1.94 raeburn 1418: $caller,$mailtoken);
1419: return 1;
1420: } else {
1421: return;
1422: }
1423: }
1.3 matthew 1424: #
1.59 albertel 1425: my $currentpass = $env{'form.currentpass'};
1426: my $newpass1 = $env{'form.newpass_1'};
1427: my $newpass2 = $env{'form.newpass_2'};
1428: my $logtoken = $env{'form.logtoken'};
1.3 matthew 1429: # Check for empty data
1.4 matthew 1430: unless (defined($currentpass) &&
1431: defined($newpass1) &&
1432: defined($newpass2) ){
1.99 www 1433: &passwordchanger($r,"<p>\n<span class='LC_error'>".
1434: &mt("One or more password fields were blank").
1435: "</span>\n</p>",$caller,$mailtoken);
1.3 matthew 1436: return;
1437: }
1.16 albertel 1438: # Get the keys
1439: my $lonhost = $r->dir_config('lonHostID');
1.3 matthew 1440: my $tmpinfo = Apache::lonnet::reply('tmpget:'.$logtoken,$lonhost);
1441: if (($tmpinfo=~/^error/) || ($tmpinfo eq 'con_lost')) {
1.4 matthew 1442: # I do not a have a better idea about how to handle this
1.94 raeburn 1443: my $tryagain_text = &mt('Please log out and try again.');
1444: if ($caller eq 'reset_by_email') {
1445: $tryagain_text = &mt('Please try again later.');
1446: }
1.101 albertel 1447: my $unable=&mt("Unable to retrieve saved token for password decryption");
1.3 matthew 1448: $r->print(<<ENDERROR);
1449: <p>
1.99 www 1450: <span class="LC_error">$unable. $tryagain_text</span>
1.3 matthew 1451: </p>
1452: ENDERROR
1.4 matthew 1453: # Probably should log an error here
1.75 albertel 1454: return 1;
1.3 matthew 1455: }
1456: my ($ckey,$n1key,$n2key)=split(/&/,$tmpinfo);
1.4 matthew 1457: #
1.17 matthew 1458: $currentpass = &des_decrypt($ckey ,$currentpass);
1459: $newpass1 = &des_decrypt($n1key,$newpass1);
1460: $newpass2 = &des_decrypt($n2key,$newpass2);
1.94 raeburn 1461: #
1462: if ($caller eq 'reset_by_email') {
1463: my %data = &Apache::lonnet::tmpget($mailtoken);
1.117 raeburn 1464: if (keys(%data) == 0) {
1465: &passwordchanger($r,
1466: '<span class="LC_error">'.
1467: &mt('Could not verify current authentication.').' '.
1468: &mt('Please try again.').'</span>',$caller,$mailtoken);
1469: return 1;
1470: }
1.94 raeburn 1471: if ($currentpass ne $data{'temppasswd'}) {
1472: &passwordchanger($r,
1.99 www 1473: '<span class="LC_error">'.
1.110 bisitz 1474: &mt('Could not verify current authentication.').' '.
1475: &mt('Please try again.').'</span>',$caller,$mailtoken);
1.94 raeburn 1476: return 1;
1477: }
1478: }
1.3 matthew 1479: if ($newpass1 ne $newpass2) {
1.4 matthew 1480: &passwordchanger($r,
1.99 www 1481: '<span class="LC_error">'.
1.110 bisitz 1482: &mt('The new passwords you entered do not match.').' '.
1483: &mt('Please try again.').'</span>',$caller,$mailtoken);
1.75 albertel 1484: return 1;
1.4 matthew 1485: }
1486: if (length($newpass1) < 7) {
1487: &passwordchanger($r,
1.99 www 1488: '<span class="LC_error">'.
1.110 bisitz 1489: &mt('Passwords must be a minimum of 7 characters long.').' '.
1490: &mt('Please try again.').'</span>',$caller,$mailtoken);
1.75 albertel 1491: return 1;
1.3 matthew 1492: }
1.4 matthew 1493: #
1494: # Check for bad characters
1495: my $badpassword = 0;
1496: foreach (split(//,$newpass1)) {
1497: $badpassword = 1 if ((ord($_)<32)||(ord($_)>126));
1498: }
1499: if ($badpassword) {
1500: # I can't figure out how to enter bad characters on my browser.
1.99 www 1501: my $errormessage ='<span class="LC_error">'.
1.110 bisitz 1502: &mt('The password you entered contained illegal characters.').'<br />'.
1.99 www 1503: &mt('Valid characters are').(<<"ENDERROR");
1504: : space and <br />
1.4 matthew 1505: <pre>
1506: !"\#$%&\'()*+,-./0123456789:;<=>?\@
1507: ABCDEFGHIJKLMNOPQRSTUVWXYZ[\]^_\`abcdefghijklmnopqrstuvwxyz{|}~
1.99 www 1508: </pre></span>
1.4 matthew 1509: ENDERROR
1.94 raeburn 1510: &passwordchanger($r,$errormessage,$caller,$mailtoken);
1511: return 1;
1.4 matthew 1512: }
1513: #
1514: # Change the password (finally)
1515: my $result = &Apache::lonnet::changepass
1.94 raeburn 1516: ($user,$domain,$currentpass,$newpass1,$homeserver,$caller);
1.4 matthew 1517: # Inform the user the password has (not?) been changed
1.125.4.2! raeburn 1518: my $message;
1.4 matthew 1519: if ($result =~ /^ok$/) {
1.125.4.1 raeburn 1520: $message = &Apache::lonhtmlcommon::confirm_success(&mt('The password for user [_1] was successfully changed.','<i>'.$user.'<i>'));
1521: if ($caller eq 'reset_by_email') {
1522: $r->print($message.'<br />');
1523: } else {
1524: $r->print(&Apache::loncommon::confirmwrapper($message));
1525: }
1.4 matthew 1526: } else {
1527: # error error: run in circles, scream and shout
1.125.4.1 raeburn 1528: $message = &Apache::lonhtmlcommon::confirm_success(
1529: &mt("The password for user [_1] was not changed.",'<i>'.$user.'</i>').' '.&mt('Please make sure your old password was entered correctly.'),1);
1530: if ($caller eq 'reset_by_email') {
1531: $r->print($message.'<br />');
1532: } else {
1533: $r->print(&Apache::loncommon::confirmwrapper($message));
1534: }
1.75 albertel 1535: return 1;
1.4 matthew 1536: }
1537: return;
1.3 matthew 1538: }
1539:
1.42 raeburn 1540: ################################################################
1541: # discussion display subroutines
1542: ################################################################
1543: sub discussionchanger {
1544: my $r = shift;
1.59 albertel 1545: my $user = $env{'user.name'};
1546: my $domain = $env{'user.domain'};
1.42 raeburn 1547: my %userenv = &Apache::lonnet::get
1.43 raeburn 1548: ('environment',['discdisplay','discmarkread']);
1549: my $discdisp = 'allposts';
1550: my $discmark = 'onmark';
1551:
1552: if (defined($userenv{'discdisplay'})) {
1553: unless ($userenv{'discdisplay'} eq '') {
1554: $discdisp = $userenv{'discdisplay'};
1555: }
1556: }
1557: if (defined($userenv{'discmarkread'})) {
1558: unless ($userenv{'discdisplay'} eq '') {
1559: $discmark = $userenv{'discmarkread'};
1560: }
1561: }
1562:
1563: my $newdisp = 'unread';
1564: my $newmark = 'ondisp';
1565:
1566: my $function = &Apache::loncommon::get_users_function();
1567: my $color = &Apache::loncommon::designparm($function.'.tabbg',
1.59 albertel 1568: $env{'user.domain'});
1.43 raeburn 1569: my %lt = &Apache::lonlocal::texthash(
1570: 'pref' => 'Display Preference',
1571: 'curr' => 'Current setting ',
1572: 'actn' => 'Action',
1.125.4.1 raeburn 1573: 'sdpf' => 'Set display preferences for discussion posts for both discussion boards and individual resources in all your courses.',
1.43 raeburn 1574: 'prca' => 'Preferences can be set that determine',
1.125.4.1 raeburn 1575: 'whpo' => 'Which posts are displayed when you display a discussion board or resource, and',
1.43 raeburn 1576: 'unwh' => 'Under what circumstances posts are identfied as "New"',
1577: 'allposts' => 'All posts',
1578: 'unread' => 'New posts only',
1579: 'ondisp' => 'Once displayed',
1580: 'onmark' => 'Once marked as read',
1581: 'disa' => 'Posts displayed?',
1582: 'npmr' => 'New posts cease to be identified as "New"?',
1583: 'thde' => 'The preferences you set here can be overridden within each individual discussion.',
1.125.4.1 raeburn 1584: 'chgt' => 'Change to ',
1.43 raeburn 1585: );
1586: my $dispchange = $lt{'unread'};
1587: my $markchange = $lt{'ondisp'};
1588: my $currdisp = $lt{'allposts'};
1589: my $currmark = $lt{'onmark'};
1590:
1591: if ($discdisp eq 'unread') {
1592: $dispchange = $lt{'allposts'};
1593: $currdisp = $lt{'unread'};
1594: $newdisp = 'allposts';
1595: }
1596:
1597: if ($discmark eq 'ondisp') {
1598: $markchange = $lt{'onmark'};
1599: $currmark = $lt{'ondisp'};
1600: $newmark = 'onmark';
1.42 raeburn 1601: }
1.43 raeburn 1602:
1603: $r->print(<<"END");
1.88 albertel 1604: <form name="prefs" action="/adm/preferences" method="post">
1.42 raeburn 1605: <input type="hidden" name="action" value="verify_and_change_discussion" />
1606: <br />
1.87 albertel 1607: $lt{'sdpf'}<br /> $lt{'prca'} <ol><li>$lt{'whpo'}</li><li>$lt{'unwh'}</li></ol>
1.82 albertel 1608: END
1.125.4.1 raeburn 1609: $r->print('<p class="LC_info">'.$lt{'thde'}.'</p>');
1610:
1.82 albertel 1611: $r->print(&Apache::loncommon::start_data_table());
1612: $r->print(<<"END");
1613: <tr>
1614: <th>$lt{'pref'}</th>
1615: <th>$lt{'curr'}</th>
1616: <th>$lt{'actn'}?</th>
1.43 raeburn 1617: </tr>
1.82 albertel 1618: END
1619: $r->print(&Apache::loncommon::start_data_table_row());
1620: $r->print(<<"END");
1.43 raeburn 1621: <td>$lt{'disa'}</td>
1622: <td>$lt{$discdisp}</td>
1.82 albertel 1623: <td><label><input type="checkbox" name="discdisp" /><input type="hidden" name="newdisp" value="$newdisp" /> $lt{'chgt'} "$dispchange"</label></td>
1624: END
1625: $r->print(&Apache::loncommon::end_data_table_row().
1626: &Apache::loncommon::start_data_table_row());
1627: $r->print(<<"END");
1.43 raeburn 1628: <td>$lt{'npmr'}</td>
1629: <td>$lt{$discmark}</td>
1.82 albertel 1630: <td><label><input type="checkbox" name="discmark" /><input type="hidden" name="newmark" value="$newmark" /> $lt{'chgt'} "$markchange"</label></td>
1.43 raeburn 1631: </tr>
1.82 albertel 1632: END
1633: $r->print(&Apache::loncommon::end_data_table_row().
1634: &Apache::loncommon::end_data_table());
1.125.4.1 raeburn 1635: $r->print('<br />'.
1636: '<input type="submit" name="sub" value="'.&mt('Save').'" />'.
1637: '</form>');
1.42 raeburn 1638: }
1639:
1640: sub verify_and_change_discussion {
1641: my $r = shift;
1.59 albertel 1642: my $user = $env{'user.name'};
1643: my $domain = $env{'user.domain'};
1.42 raeburn 1644: my $message='';
1.59 albertel 1645: if (defined($env{'form.discdisp'}) ) {
1646: my $newdisp = $env{'form.newdisp'};
1.43 raeburn 1647: if ($newdisp eq 'unread') {
1.110 bisitz 1648: $message .=&mt('In discussions: only new posts will be displayed.').'<br />';
1.43 raeburn 1649: &Apache::lonnet::put('environment',{'discdisplay' => $newdisp});
1.116 raeburn 1650: &Apache::lonnet::appenv({'environment.discdisplay' => $newdisp});
1.43 raeburn 1651: } else {
1.110 bisitz 1652: $message .= &mt('In discussions: all posts will be displayed.').'<br />';
1.43 raeburn 1653: &Apache::lonnet::del('environment',['discdisplay']);
1.125.4.1 raeburn 1654: &Apache::lonnet::delenv('environment.discdisplay');
1.43 raeburn 1655: }
1656: }
1.59 albertel 1657: if (defined($env{'form.discmark'}) ) {
1658: my $newmark = $env{'form.newmark'};
1.43 raeburn 1659: if ($newmark eq 'ondisp') {
1.125.4.1 raeburn 1660: $message.=&Apache::lonhtmlcommon::confirm_success(&mt('In discussions: new posts will be cease to be identified as "NEW" after display.')).'<br />';
1.43 raeburn 1661: &Apache::lonnet::put('environment',{'discmarkread' => $newmark});
1.116 raeburn 1662: &Apache::lonnet::appenv({'environment.discmarkread' => $newmark});
1.43 raeburn 1663: } else {
1.125.4.1 raeburn 1664: $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 1665: &Apache::lonnet::del('environment',['discmarkread']);
1.125.4.1 raeburn 1666: &Apache::lonnet::delenv('environment.discmarkread');
1.43 raeburn 1667: }
1.42 raeburn 1668: }
1.125.4.1 raeburn 1669: $message=&Apache::loncommon::confirmwrapper($message);
1.42 raeburn 1670: $r->print(<<ENDVCSCREEN);
1671: $message
1672: ENDVCSCREEN
1673: }
1674:
1.63 raeburn 1675: ################################################################
1676: # Subroutines for page display on course access (Course Coordinators)
1677: ################################################################
1678: sub coursedisplaychanger {
1679: my $r = shift;
1680: my $user = $env{'user.name'};
1681: my $domain = $env{'user.domain'};
1.66 albertel 1682: my %userenv = &Apache::lonnet::get('environment',['course_init_display']);
1.71 raeburn 1683: my $currvalue = 'whatsnew';
1.73 albertel 1684: my $firstselect = '';
1685: my $whatsnewselect = 'checked="checked"';
1.71 raeburn 1686: if (exists($userenv{'course_init_display'})) {
1687: if ($userenv{'course_init_display'} eq 'firstres') {
1688: $currvalue = 'firstres';
1.73 albertel 1689: $firstselect = 'checked="checked"';
1690: $whatsnewselect = '';
1.71 raeburn 1691: }
1.63 raeburn 1692: }
1.71 raeburn 1693: my %pagenames = (
1694: firstres => 'First resource',
1.125.4.1 raeburn 1695: whatsnew => "What's New Page",
1.71 raeburn 1696: );
1.125.4.1 raeburn 1697: my $whatsnew_off=&mt('Display the [_1]first resource[_2] in the course.','<b>','</b>');
1698: 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 1699:
1.125.4.1 raeburn 1700: $r->print('<br /><b>'.
1701: &mt('Set the default page to be displayed when you select a course role').
1702: '</b> '.
1703: &mt('(Currently: [_1])',$pagenames{$currvalue}).'<br />'.
1704: &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>').
1705: '<br /><br />');
1.63 raeburn 1706: $r->print(<<ENDLSCREEN);
1.88 albertel 1707: <form name="prefs" action="/adm/preferences" method="post">
1.63 raeburn 1708: <input type="hidden" name="action" value="verify_and_change_coursepage" />
1.72 albertel 1709: <br />
1.65 albertel 1710: <label><input type="radio" name="newdisp" value="firstres" $firstselect /> $whatsnew_off</label><br />
1.70 raeburn 1711: <label><input type="radio" name="newdisp" value="whatsnew" $whatsnewselect /> $whatsnew_on</label><input type="hidden" name="refpage" value="$env{'form.refpage'}" />
1.63 raeburn 1712: ENDLSCREEN
1.125.4.1 raeburn 1713: $r->print('<br /><br /><input type="submit" value="'.&mt('Save').'" />
1.63 raeburn 1714: </form>');
1715: }
1716:
1717: sub verify_and_change_coursepage {
1718: my $r = shift;
1719: my $message='';
1720: my %lt = &Apache::lonlocal::texthash(
1.70 raeburn 1721: 'defs' => 'Default now set',
1.71 raeburn 1722: 'when' => 'when you select a course role from the roles screen',
1.63 raeburn 1723: 'ywbt' => 'you will be taken to the start of the course.',
1724: 'apwb' => 'a page will be displayed that lists items in the course that may require action from you.',
1725: 'gtts' => 'Go to the start of the course',
1.125.4.1 raeburn 1726: 'dasp' => "Display the What's New Page",
1.63 raeburn 1727: );
1728: my $newdisp = $env{'form.newdisp'};
1.70 raeburn 1729: $message = '<b>'.$lt{'defs'}.'</b>: '.$lt{'when'}.', ';
1.63 raeburn 1730: if ($newdisp eq 'firstres') {
1.87 albertel 1731: $message .= $lt{'ywbt'}.'<br />';
1.63 raeburn 1732: &Apache::lonnet::put('environment',{'course_init_display' => $newdisp});
1.116 raeburn 1733: &Apache::lonnet::appenv({'environment.course_init_display' => $newdisp});
1.63 raeburn 1734: } else {
1.87 albertel 1735: $message .= $lt{'apwb'}.'<br />';
1.63 raeburn 1736: &Apache::lonnet::del('environment',['course_init_display']);
1.125.4.1 raeburn 1737: &Apache::lonnet::delenv('environment.course_init_display');
1.63 raeburn 1738: }
1.70 raeburn 1739: my $refpage = $env{'form.refpage'};
1.63 raeburn 1740: if (($env{'request.course.fn'}) && ($env{'request.course.id'})) {
1741: if ($newdisp eq 'firstres') {
1742: my $cdom = $env{'course.'.$env{'request.course.id'}.'.domain'};
1743: my $cnum = $env{'course.'.$env{'request.course.id'}.'.num'};
1744: my ($furl,$ferr)=
1745: &Apache::lonuserstate::readmap($cdom.'/'.$cnum);
1746: $message .= '<br /><font size="+1"><a href="'.$furl.'">'.$lt{'gtts'}.' <i>'.&mt('now').'</i></a></font>';
1747: } else {
1.70 raeburn 1748: $message .= '<br /><font size="+1"><a href="/adm/whatsnew?refpage='.
1749: $refpage.'">'.$lt{'dasp'}.'</a></font>';
1.63 raeburn 1750: }
1751: }
1.125.4.2! raeburn 1752: $message = &Apache::lonhtmlcommon::confirm_success($message);
1.63 raeburn 1753: $r->print(<<ENDVCSCREEN);
1754: $message
1755: ENDVCSCREEN
1756: }
1757:
1758:
1.4 matthew 1759: ######################################################
1760: # other handler subroutines #
1761: ######################################################
1762:
1.3 matthew 1763: ################################################################
1764: # Main handler #
1765: ################################################################
1.1 www 1766: sub handler {
1767: my $r = shift;
1.59 albertel 1768: my $user = $env{'user.name'};
1769: my $domain = $env{'user.domain'};
1.31 www 1770: &Apache::loncommon::content_type($r,'text/html');
1.4 matthew 1771: # Some pages contain DES keys and should not be cached.
1772: &Apache::loncommon::no_cache($r);
1.1 www 1773: $r->send_http_header;
1774: return OK if $r->header_only;
1.9 matthew 1775: #
1.35 matthew 1776: &Apache::loncommon::get_unprocessed_cgi($ENV{'QUERY_STRING'},
1.70 raeburn 1777: ['action','wysiwyg','returnurl','refpage']);
1.35 matthew 1778: #
1779: &Apache::lonhtmlcommon::clear_breadcrumbs();
1780: &Apache::lonhtmlcommon::add_breadcrumb
1781: ({href => '/adm/preferences',
1782: text => 'Set User Preferences'});
1783:
1784: my @Options;
1785: # Determine current authentication method
1786: my $currentauth=&Apache::lonnet::queryauthenticate($user,$domain);
1787: if ($currentauth =~ /^(unix|internal):/) {
1788: push (@Options,({ action => 'changepass',
1.40 www 1789: linktext => 'Change Password',
1.35 matthew 1790: href => '/adm/preferences',
1791: help => 'Change_Password',
1792: subroutine => \&passwordchanger,
1793: breadcrumb =>
1794: { href => '/adm/preferences?action=changepass',
1795: text => 'Change Password'},
1796: },
1797: { action => 'verify_and_change_pass',
1798: subroutine => \&verify_and_change_password,
1799: breadcrumb =>
1800: { href =>'/adm/preferences?action=changepass',
1801: text => 'Change Password'},
1.75 albertel 1802: printmenu => 'not_on_error',
1.35 matthew 1803: }));
1804: }
1805: push (@Options,({ action => 'changescreenname',
1806: linktext => 'Change Screen Name',
1807: href => '/adm/preferences',
1808: help => 'Prefs_Screen_Name_Nickname',
1809: subroutine => \&screennamechanger,
1810: breadcrumb =>
1811: { href => '/adm/preferences?action=changescreenname',
1812: text => 'Change Screen Name'},
1813: },
1814: { action => 'verify_and_change_screenname',
1815: subroutine => \&verify_and_change_screenname,
1816: breadcrumb =>
1817: { href => '/adm/preferences?action=changescreenname',
1818: text => 'Change Screen Name'},
1819: printmenu => 'yes',
1820: }));
1821:
1822: push (@Options,({ action => 'changemsgforward',
1.125.4.1 raeburn 1823: linktext => 'Messages & Notifications',
1.35 matthew 1824: href => '/adm/preferences',
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.35 matthew 1829: subroutine => \&msgforwardchanger,
1830: },
1831: { action => 'verify_and_change_msgforward',
1.113 raeburn 1832: help => 'Prefs_Messages',
1.35 matthew 1833: breadcrumb =>
1834: { href => '/adm/preferences?action=changemsgforward',
1.113 raeburn 1835: text => 'Change Message Forwarding/Notification'},
1.102 raeburn 1836: printmenu => 'no',
1.35 matthew 1837: subroutine => \&verify_and_change_msgforward }));
1.125.4.1 raeburn 1838: if (&Apache::lonnet::usertools_access($user,$domain,'aboutme')) {
1839: my $aboutmeaction = '/adm/'.$domain.'/'.$user.'/aboutme';
1840: push (@Options,{ action => 'none',
1841: linktext =>"Edit the Personal Information Page",
1842: help => 'Prefs_About_Me',
1843: href => $aboutmeaction});
1844: }
1.35 matthew 1845: push (@Options,({ action => 'changecolors',
1846: linktext => 'Change Color Scheme',
1847: href => '/adm/preferences',
1848: help => 'Change_Colors',
1849: breadcrumb =>
1850: { href => '/adm/preferences?action=changecolors',
1851: text => 'Change Colors'},
1852: subroutine => \&colorschanger,
1853: },
1854: { action => 'verify_and_change_colors',
1855: breadcrumb =>
1856: { href => '/adm/preferences?action=changecolors',
1857: text => 'Change Colors'},
1858: printmenu => 'yes',
1859: subroutine => \&verify_and_change_colors,
1860: }));
1861: push (@Options,({ action => 'changelanguages',
1.39 www 1862: linktext => 'Change Language Preferences',
1.35 matthew 1863: href => '/adm/preferences',
1.45 www 1864: help => 'Prefs_Language',
1.35 matthew 1865: breadcrumb=>
1866: { href => '/adm/preferences?action=changelanguages',
1867: text => 'Change Language'},
1868: subroutine => \&languagechanger,
1869: },
1870: { action => 'verify_and_change_languages',
1871: breadcrumb=>
1872: {href => '/adm/preferences?action=changelanguages',
1873: text => 'Change Language'},
1874: printmenu => 'yes',
1875: subroutine=>\&verify_and_change_languages, }
1876: ));
1.44 www 1877: push (@Options,({ action => 'changewysiwyg',
1878: linktext => 'Change WYSIWYG Editor Preferences',
1879: href => '/adm/preferences',
1880: breadcrumb =>
1881: { href => '/adm/preferences?action=changewysiwyg',
1882: text => 'Change WYSIWYG Preferences'},
1883: subroutine => \&wysiwygchanger,
1884: },
1885: { action => 'set_wysiwyg',
1886: breadcrumb =>
1887: { href => '/adm/preferences?action=changewysiwyg',
1888: text => 'Change WYSIWYG Preferences'},
1889: printmenu => 'yes',
1890: subroutine => \&verify_and_change_wysiwyg, }
1891: ));
1.42 raeburn 1892: push (@Options,({ action => 'changediscussions',
1893: linktext => 'Change Discussion Display Preferences',
1894: href => '/adm/preferences',
1.46 raeburn 1895: help => 'Change_Discussion_Display',
1.42 raeburn 1896: breadcrumb =>
1897: { href => '/adm/preferences?action=changediscussions',
1.43 raeburn 1898: text => 'Change Discussion Preferences'},
1.42 raeburn 1899: subroutine => \&discussionchanger,
1900: },
1901: { action => 'verify_and_change_discussion',
1902: breadcrumb =>
1903: { href => '/adm/preferences?action=changediscussions',
1.43 raeburn 1904: text => 'Change Discussion Preferences'},
1.42 raeburn 1905: printmenu => 'yes',
1906: subroutine => \&verify_and_change_discussion, }
1907: ));
1.96 albertel 1908:
1909: my $role = ($env{'user.adv'} ? 'Roles' : 'Course');
1.50 albertel 1910: push (@Options,({ action => 'changerolespref',
1.96 albertel 1911: linktext => 'Change '.$role.' Page Preferences',
1.50 albertel 1912: href => '/adm/preferences',
1913: subroutine => \&rolesprefchanger,
1914: breadcrumb =>
1915: { href => '/adm/preferences?action=changerolespref',
1.96 albertel 1916: text => 'Change '.$role.' Page Pref'},
1.50 albertel 1917: },
1918: { action => 'verify_and_change_rolespref',
1919: subroutine => \&verify_and_change_rolespref,
1920: breadcrumb =>
1921: { href => '/adm/preferences?action=changerolespref',
1.96 albertel 1922: text => 'Change '.$role.' Page Preferences'},
1.50 albertel 1923: printmenu => 'yes',
1924: }));
1925:
1.54 albertel 1926: push (@Options,({ action => 'changetexenginepref',
1927: linktext => 'Change How Math Equations Are Displayed',
1928: href => '/adm/preferences',
1929: subroutine => \&texenginechanger,
1930: breadcrumb =>
1931: { href => '/adm/preferences?action=changetexenginepref',
1932: text => 'Change Math Pref'},
1933: },
1934: { action => 'verify_and_change_texengine',
1935: subroutine => \&verify_and_change_texengine,
1936: breadcrumb =>
1937: { href => '/adm/preferences?action=changetexenginepref',
1938: text => 'Change Math Preferences'},
1939: printmenu => 'yes',
1940: }));
1.85 albertel 1941:
1942: if ($env{'environment.remote'} eq 'off') {
1943: push (@Options,({ action => 'launch',
1944: linktext => 'Launch Remote Control',
1945: href => '/adm/remote?url=/adm/preferences',
1946: }));
1947: } else {
1948: push (@Options,({ action => 'collapse',
1949: linktext => 'Collapse Remote Control',
1950: href => '/adm/remote?url=/adm/preferences',
1951: }));
1952: }
1953:
1.98 www 1954: push (@Options,({ action => 'changeicons',
1.100 www 1955: linktext => 'Change How Menus are Displayed',
1.98 www 1956: href => '/adm/preferences',
1957: subroutine => \&iconchanger,
1958: breadcrumb =>
1959: { href => '/adm/preferences?action=changeicons',
1960: text => 'Change Main Menu'},
1961: },
1962: { action => 'verify_and_change_icons',
1963: subroutine => \&verify_and_change_icons,
1964: breadcrumb =>
1965: { href => '/adm/preferences?action=changeicons',
1966: text => 'Change Main Menu'},
1967: printmenu => 'yes',
1968: }));
1969:
1.106 www 1970: push (@Options,({ action => 'changeclicker',
1.125.4.1 raeburn 1971: linktext => 'Register Response Devices ("Clickers")',
1.106 www 1972: href => '/adm/preferences',
1973: subroutine => \&clickerchanger,
1974: breadcrumb =>
1.118 www 1975: { href => '/adm/preferences?action=changeclicker',
1.106 www 1976: text => 'Register Clicker'},
1977: },
1978: { action => 'verify_and_change_clicker',
1979: subroutine => \&verify_and_change_clicker,
1980: breadcrumb =>
1981: { href => '/adm/preferences?action=changeclicker',
1982: text => 'Register Clicker'},
1983: printmenu => 'yes',
1984: }));
1.125 raeburn 1985: my %author_roles = &Apache::lonnet::get_my_roles($user,$domain,'userroles','',['au']);
1986: if (keys(%author_roles) > 0) {
1.119 www 1987: push (@Options,({ action => 'changedomcoord',
1988: linktext => 'Restrict Domain Coordinator Access',
1989: href => '/adm/preferences',
1990: subroutine => \&domcoordchanger,
1991: breadcrumb =>
1992: { href => '/adm/preferences?action=changedomcoord',
1993: text => 'Restrict Domain Coordinator Access'},
1994: },
1995: { action => 'verify_and_change_domcoord',
1996: subroutine => \&verify_and_change_domcoord,
1997: breadcrumb =>
1998: { href => '/adm/preferences?action=changedomcoord',
1999: text => 'Restrict Domain Coordinator Access'},
2000: printmenu => 'yes',
2001: }));
2002: }
1.105 www 2003:
1.118 www 2004: push (@Options,({ action => 'lockwarning',
2005: subroutine => \&lockwarning,
2006: breadcrumb =>
2007: { href => '/adm/preferences?action=lockwarning',
2008: text => 'Lock Warnings'},
2009: },
2010: { action => 'verify_and_change_locks',
2011: subroutine => \&verify_and_change_lockwarning,
2012: breadcrumb =>
2013: { href => '/adm/preferences?action=lockwarning',
2014: text => 'Lockwarnings'},
2015: printmenu => 'yes',
2016: }));
2017:
1.105 www 2018:
1.74 albertel 2019: if (&Apache::lonnet::allowed('whn',$env{'request.course.id'})
2020: || &Apache::lonnet::allowed('whn',$env{'request.course.id'}.'/'
2021: .$env{'request.course.sec'})) {
1.63 raeburn 2022: push (@Options,({ action => 'changecourseinit',
2023: linktext => 'Change Course Initialization Preference',
2024: href => '/adm/preferences',
2025: subroutine => \&coursedisplaychanger,
2026: breadcrumb =>
2027: { href => '/adm/preferences?action=changecourseinit',
2028: text => 'Change Course Init. Pref.'},
2029: },
2030: { action => 'verify_and_change_coursepage',
2031: breadcrumb =>
2032: { href => '/adm/preferences?action=changecourseinit', text => 'Change Course Initialization Preference'},
2033: printmenu => 'yes',
2034: subroutine => \&verify_and_change_coursepage,
2035: }));
2036: }
1.50 albertel 2037:
1.119 www 2038: if ($env{'user.name'} =~ /^(albertel|fox|foxr|kortemey|korte|raeburn)$/) {
1.35 matthew 2039: push (@Options,({ action => 'debugtoggle',
2040: printmenu => 'yes',
2041: subroutine => \&toggle_debug,
2042: }));
2043: }
1.76 albertel 2044:
2045: $r->print(&Apache::loncommon::start_page('Change Preferences'));
2046:
1.35 matthew 2047: my $call = undef;
1.48 albertel 2048: my $help = undef;
1.35 matthew 2049: my $printmenu = 'yes';
2050: foreach my $option (@Options) {
1.59 albertel 2051: if ($option->{'action'} eq $env{'form.action'}) {
1.35 matthew 2052: $call = $option->{'subroutine'};
2053: $printmenu = $option->{'printmenu'};
2054: if (exists($option->{'breadcrumb'})) {
2055: &Apache::lonhtmlcommon::add_breadcrumb
2056: ($option->{'breadcrumb'});
2057: }
1.48 albertel 2058: $help=$option->{'help'};
1.35 matthew 2059: }
2060: }
1.81 albertel 2061: $r->print(&Apache::lonhtmlcommon::breadcrumbs('Change Preferences',$help));
1.75 albertel 2062: my $error;
1.35 matthew 2063: if (defined($call)) {
1.75 albertel 2064: $error = $call->($r);
1.35 matthew 2065: }
1.75 albertel 2066: if ( ( ($printmenu eq 'yes')
2067: || ($printmenu eq 'not_on_error' && !$error) )
2068: && (!$env{'form.returnurl'})) {
1.35 matthew 2069: my $optionlist = '<table cellpadding="5">';
1.59 albertel 2070: if ($env{'user.name'} =~
1.62 raeburn 2071: /^(albertel|kortemey|fox|foxr|korte|hallmat3|turtle|raeburn)$/
1.35 matthew 2072: ) {
2073: push (@Options,({ action => 'debugtoggle',
2074: linktext => 'Toggle Debug Messages',
2075: text => 'Current Debug status is -'.
1.59 albertel 2076: $env{'user.debug'}.'-.',
1.35 matthew 2077: href => '/adm/preferences',
2078: printmenu => 'yes',
2079: subroutine => \&toggle_debug,
2080: }));
2081: }
2082: foreach my $option(@Options) {
2083: my $optiontext = '';
2084: if (exists($option->{'href'})) {
1.85 albertel 2085: $option->{'href_args'}{'action'}=$option->{'action'};
2086: $optiontext .=
2087: '<a href="'.&add_get_param($option->{'href'},
2088: $option->{'href_args'}).'">'.
1.47 albertel 2089: &mt($option->{'linktext'}).'</a>';
1.35 matthew 2090: }
2091: if (exists($option->{'text'})) {
1.47 albertel 2092: $optiontext .= ' '.&mt($option->{'text'});
1.35 matthew 2093: }
2094: if ($optiontext ne '') {
2095: $optiontext = '<font size="+1">'.$optiontext.'</font>';
2096: my $helplink = ' ';
2097: if (exists($option->{'help'})) {
2098: $helplink = &Apache::loncommon::help_open_topic
2099: ($option->{'help'});
2100: }
2101: $optionlist .= '<tr>'.
2102: '<td>'.$helplink.'</td>'.
2103: '<td>'.$optiontext.'</td>'.
2104: '</tr>';
2105: }
1.13 www 2106: }
1.35 matthew 2107: $optionlist .= '</table>';
2108: $r->print($optionlist);
1.59 albertel 2109: } elsif ($env{'form.returnurl'}) {
2110: $r->print('<br /><a href="'.$env{'form.returnurl'}.'"><font size="+1">'.
1.44 www 2111: &mt('Return').'</font></a>');
1.3 matthew 2112: }
1.76 albertel 2113: $r->print(&Apache::loncommon::end_page());
1.1 www 2114: return OK;
1.35 matthew 2115: }
2116:
2117: sub toggle_debug {
1.59 albertel 2118: if ($env{'user.debug'}) {
1.125.4.1 raeburn 2119: &Apache::lonnet::delenv('user.debug');
1.35 matthew 2120: } else {
1.116 raeburn 2121: &Apache::lonnet::appenv({'user.debug' => 1});
1.35 matthew 2122: }
1.13 www 2123: }
1.1 www 2124:
2125: 1;
2126: __END__
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>