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