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