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