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