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