Annotation of loncom/interface/loncreateuser.pm, revision 1.442
1.20 harris41 1: # The LearningOnline Network with CAPA
1.1 www 2: # Create a user
3: #
1.442 ! raeburn 4: # $Id: loncreateuser.pm,v 1.441 2017/07/26 19:42:22 raeburn Exp $
1.22 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.20 harris41 28: ###
29:
1.1 www 30: package Apache::loncreateuser;
1.66 bowersj2 31:
32: =pod
33:
34: =head1 NAME
35:
1.263 jms 36: Apache::loncreateuser.pm
1.66 bowersj2 37:
38: =head1 SYNOPSIS
39:
1.263 jms 40: Handler to create users and custom roles
41:
42: Provides an Apache handler for creating users,
1.66 bowersj2 43: editing their login parameters, roles, and removing roles, and
44: also creating and assigning custom roles.
45:
46: =head1 OVERVIEW
47:
48: =head2 Custom Roles
49:
50: In LON-CAPA, roles are actually collections of privileges. "Teaching
51: Assistant", "Course Coordinator", and other such roles are really just
52: collection of privileges that are useful in many circumstances.
53:
1.324 raeburn 54: Custom roles can be defined by a Domain Coordinator, Course Coordinator
55: or Community Coordinator via the Manage User functionality.
56: The custom role editor screen will show all privileges which can be
57: assigned to users. For a complete list of privileges, please see
58: C</home/httpd/lonTabs/rolesplain.tab>.
1.66 bowersj2 59:
1.324 raeburn 60: Custom role definitions are stored in the C<roles.db> file of the creator
61: of the role.
1.66 bowersj2 62:
63: =cut
1.1 www 64:
65: use strict;
66: use Apache::Constants qw(:common :http);
67: use Apache::lonnet;
1.54 bowersj2 68: use Apache::loncommon;
1.68 www 69: use Apache::lonlocal;
1.117 raeburn 70: use Apache::longroup;
1.190 raeburn 71: use Apache::lonuserutils;
1.307 raeburn 72: use Apache::loncoursequeueadmin;
1.139 albertel 73: use LONCAPA qw(:DEFAULT :match);
1.1 www 74:
1.20 harris41 75: my $loginscript; # piece of javascript used in two separate instances
76: my $authformnop;
77: my $authformkrb;
78: my $authformint;
79: my $authformfsys;
80: my $authformloc;
81:
1.94 matthew 82: sub initialize_authen_forms {
1.227 raeburn 83: my ($dom,$formname,$curr_authtype,$mode) = @_;
84: my ($krbdef,$krbdefdom) = &Apache::loncommon::get_kerberos_defaults($dom);
85: my %param = ( formname => $formname,
1.187 raeburn 86: kerb_def_dom => $krbdefdom,
1.227 raeburn 87: kerb_def_auth => $krbdef,
1.187 raeburn 88: domain => $dom,
89: );
1.188 raeburn 90: my %abv_auth = &auth_abbrev();
1.227 raeburn 91: if ($curr_authtype =~ /^(krb4|krb5|internal|localauth|unix):(.*)$/) {
1.188 raeburn 92: my $long_auth = $1;
1.227 raeburn 93: my $curr_autharg = $2;
1.188 raeburn 94: my %abv_auth = &auth_abbrev();
95: $param{'curr_authtype'} = $abv_auth{$long_auth};
96: if ($long_auth =~ /^krb(4|5)$/) {
97: $param{'curr_kerb_ver'} = $1;
1.227 raeburn 98: $param{'curr_autharg'} = $curr_autharg;
1.188 raeburn 99: }
1.205 raeburn 100: if ($mode eq 'modifyuser') {
101: $param{'mode'} = $mode;
102: }
1.187 raeburn 103: }
1.227 raeburn 104: $loginscript = &Apache::loncommon::authform_header(%param);
105: $authformkrb = &Apache::loncommon::authform_kerberos(%param);
1.31 matthew 106: $authformnop = &Apache::loncommon::authform_nochange(%param);
107: $authformint = &Apache::loncommon::authform_internal(%param);
108: $authformfsys = &Apache::loncommon::authform_filesystem(%param);
109: $authformloc = &Apache::loncommon::authform_local(%param);
1.20 harris41 110: }
111:
1.188 raeburn 112: sub auth_abbrev {
113: my %abv_auth = (
1.368 raeburn 114: krb5 => 'krb',
115: krb4 => 'krb',
116: internal => 'int',
117: localauth => 'loc',
118: unix => 'fsys',
1.188 raeburn 119: );
120: return %abv_auth;
121: }
1.43 www 122:
1.134 raeburn 123: # ====================================================
124:
1.378 raeburn 125: sub user_quotas {
1.134 raeburn 126: my ($ccuname,$ccdomain) = @_;
127: my %lt = &Apache::lonlocal::texthash(
1.267 raeburn 128: 'usrt' => "User Tools",
129: 'cust' => "Custom quota",
130: 'chqu' => "Change quota",
1.134 raeburn 131: );
1.378 raeburn 132:
1.149 raeburn 133: my $quota_javascript = <<"END_SCRIPT";
134: <script type="text/javascript">
1.301 bisitz 135: // <![CDATA[
1.378 raeburn 136: function quota_changes(caller,context) {
137: var customoff = document.getElementById('custom_'+context+'quota_off');
138: var customon = document.getElementById('custom_'+context+'quota_on');
139: var number = document.getElementById(context+'quota');
1.149 raeburn 140: if (caller == "custom") {
1.378 raeburn 141: if (customoff) {
142: if (customoff.checked) {
143: number.value = "";
144: }
1.149 raeburn 145: }
146: }
147: if (caller == "quota") {
1.378 raeburn 148: if (customon) {
149: customon.checked = true;
150: }
1.149 raeburn 151: }
1.378 raeburn 152: return;
1.149 raeburn 153: }
1.301 bisitz 154: // ]]>
1.149 raeburn 155: </script>
156: END_SCRIPT
1.378 raeburn 157: my $longinsttype;
158: my ($usertypes,$order) = &Apache::lonnet::retrieve_inst_usertypes($ccdomain);
1.267 raeburn 159: my $output = $quota_javascript."\n".
160: '<h3>'.$lt{'usrt'}.'</h3>'."\n".
161: &Apache::loncommon::start_data_table();
162:
1.418 raeburn 163: if ((&Apache::lonnet::allowed('mut',$ccdomain)) ||
164: (&Apache::lonnet::allowed('udp',$ccdomain))) {
1.275 raeburn 165: $output .= &build_tools_display($ccuname,$ccdomain,'tools');
1.267 raeburn 166: }
1.378 raeburn 167:
168: my %titles = &Apache::lonlocal::texthash (
169: portfolio => "Disk space allocated to user's portfolio files",
1.385 bisitz 170: author => "Disk space allocated to user's Authoring Space (if role assigned)",
1.378 raeburn 171: );
172: foreach my $name ('portfolio','author') {
173: my ($currquota,$quotatype,$inststatus,$defquota) =
174: &Apache::loncommon::get_user_quota($ccuname,$ccdomain,$name);
175: if ($longinsttype eq '') {
176: if ($inststatus ne '') {
177: if ($usertypes->{$inststatus} ne '') {
178: $longinsttype = $usertypes->{$inststatus};
179: }
180: }
181: }
182: my ($showquota,$custom_on,$custom_off,$defaultinfo);
183: $custom_on = ' ';
184: $custom_off = ' checked="checked" ';
185: if ($quotatype eq 'custom') {
186: $custom_on = $custom_off;
187: $custom_off = ' ';
188: $showquota = $currquota;
189: if ($longinsttype eq '') {
190: $defaultinfo = &mt('For this user, the default quota would be [_1]'
1.383 raeburn 191: .' MB.',$defquota);
1.378 raeburn 192: } else {
193: $defaultinfo = &mt("For this user, the default quota would be [_1]".
1.383 raeburn 194: " MB, as determined by the user's institutional".
1.378 raeburn 195: " affiliation ([_2]).",$defquota,$longinsttype);
196: }
197: } else {
198: if ($longinsttype eq '') {
199: $defaultinfo = &mt('For this user, the default quota is [_1]'
1.383 raeburn 200: .' MB.',$defquota);
1.378 raeburn 201: } else {
202: $defaultinfo = &mt("For this user, the default quota of [_1]".
1.383 raeburn 203: " MB, is determined by the user's institutional".
1.378 raeburn 204: " affiliation ([_2]).",$defquota,$longinsttype);
205: }
206: }
207:
208: if (&Apache::lonnet::allowed('mpq',$ccdomain)) {
209: $output .= '<tr class="LC_info_row">'."\n".
210: ' <td>'.$titles{$name}.'</td>'."\n".
211: ' </tr>'."\n".
212: &Apache::loncommon::start_data_table_row()."\n".
1.390 bisitz 213: ' <td><span class="LC_nobreak">'.
214: &mt('Current quota: [_1] MB',$currquota).'</span> '.
1.378 raeburn 215: $defaultinfo.'</td>'."\n".
216: &Apache::loncommon::end_data_table_row()."\n".
217: &Apache::loncommon::start_data_table_row()."\n".
218: ' <td><span class="LC_nobreak">'.$lt{'chqu'}.
219: ': <label>'.
220: '<input type="radio" name="custom_'.$name.'quota" id="custom_'.$name.'quota_off" '.
1.379 raeburn 221: 'value="0" '.$custom_off.' onchange="javascript:quota_changes('."'custom','$name'".');"'.
1.390 bisitz 222: ' /><span class="LC_nobreak">'.
223: &mt('Default ([_1] MB)',$defquota).'</span></label> '.
1.378 raeburn 224: ' <label><input type="radio" name="custom_'.$name.'quota" id="custom_'.$name.'quota_on" '.
1.379 raeburn 225: 'value="1" '.$custom_on.' onchange="javascript:quota_changes('."'custom','$name'".');"'.
1.378 raeburn 226: ' />'.$lt{'cust'}.':</label> '.
1.379 raeburn 227: '<input type="text" name="'.$name.'quota" id="'.$name.'quota" size ="5" '.
228: 'value="'.$showquota.'" onfocus="javascript:quota_changes('."'quota','$name'".');"'.
1.390 bisitz 229: ' /> '.&mt('MB').'</span></td>'."\n".
1.378 raeburn 230: &Apache::loncommon::end_data_table_row()."\n";
231: }
232: }
1.267 raeburn 233: $output .= &Apache::loncommon::end_data_table();
1.134 raeburn 234: return $output;
235: }
236:
1.275 raeburn 237: sub build_tools_display {
238: my ($ccuname,$ccdomain,$context) = @_;
1.306 raeburn 239: my (@usertools,%userenv,$output,@options,%validations,%reqtitles,%reqdisplay,
1.332 raeburn 240: $colspan,$isadv,%domconfig);
1.275 raeburn 241: my %lt = &Apache::lonlocal::texthash (
242: 'blog' => "Personal User Blog",
243: 'aboutme' => "Personal Information Page",
1.385 bisitz 244: 'webdav' => "WebDAV access to Authoring Spaces (if SSL and author/co-author)",
1.275 raeburn 245: 'portfolio' => "Personal User Portfolio",
246: 'avai' => "Available",
247: 'cusa' => "availability",
248: 'chse' => "Change setting",
249: 'usde' => "Use default",
250: 'uscu' => "Use custom",
251: 'official' => 'Can request creation of official courses',
1.299 raeburn 252: 'unofficial' => 'Can request creation of unofficial courses',
253: 'community' => 'Can request creation of communities',
1.384 raeburn 254: 'textbook' => 'Can request creation of textbook courses',
1.411 raeburn 255: 'placement' => 'Can request creation of placement tests',
1.362 raeburn 256: 'requestauthor' => 'Can request author space',
1.275 raeburn 257: );
1.279 raeburn 258: if ($context eq 'requestcourses') {
1.275 raeburn 259: %userenv = &Apache::lonnet::userenvironment($ccdomain,$ccuname,
1.299 raeburn 260: 'requestcourses.official','requestcourses.unofficial',
1.411 raeburn 261: 'requestcourses.community','requestcourses.textbook',
262: 'requestcourses.placement');
263: @usertools = ('official','unofficial','community','textbook','placement');
1.309 raeburn 264: @options =('norequest','approval','autolimit','validate');
1.306 raeburn 265: %validations = &Apache::lonnet::auto_courserequest_checks($ccdomain);
266: %reqtitles = &courserequest_titles();
267: %reqdisplay = &courserequest_display();
268: $colspan = ' colspan="2"';
1.332 raeburn 269: %domconfig =
270: &Apache::lonnet::get_dom('configuration',['requestcourses'],$ccdomain);
1.418 raeburn 271: $isadv = &Apache::lonnet::is_advanced_user($ccdomain,$ccuname);
1.362 raeburn 272: } elsif ($context eq 'requestauthor') {
273: %userenv = &Apache::lonnet::userenvironment($ccdomain,$ccuname,
274: 'requestauthor');
275: @usertools = ('requestauthor');
276: @options =('norequest','approval','automatic');
277: %reqtitles = &requestauthor_titles();
278: %reqdisplay = &requestauthor_display();
279: $colspan = ' colspan="2"';
280: %domconfig =
281: &Apache::lonnet::get_dom('configuration',['requestauthor'],$ccdomain);
1.275 raeburn 282: } else {
283: %userenv = &Apache::lonnet::userenvironment($ccdomain,$ccuname,
1.361 raeburn 284: 'tools.aboutme','tools.portfolio','tools.blog',
285: 'tools.webdav');
286: @usertools = ('aboutme','blog','webdav','portfolio');
1.275 raeburn 287: }
288: foreach my $item (@usertools) {
1.306 raeburn 289: my ($custom_access,$curr_access,$cust_on,$cust_off,$tool_on,$tool_off,
290: $currdisp,$custdisp,$custradio);
1.275 raeburn 291: $cust_off = 'checked="checked" ';
292: $tool_on = 'checked="checked" ';
293: $curr_access =
294: &Apache::lonnet::usertools_access($ccuname,$ccdomain,$item,undef,
295: $context);
1.362 raeburn 296: if ($context eq 'requestauthor') {
297: if ($userenv{$context} ne '') {
298: $cust_on = ' checked="checked" ';
299: $cust_off = '';
300: }
301: } elsif ($userenv{$context.'.'.$item} ne '') {
1.306 raeburn 302: $cust_on = ' checked="checked" ';
303: $cust_off = '';
304: }
305: if ($context eq 'requestcourses') {
306: if ($userenv{$context.'.'.$item} eq '') {
1.314 raeburn 307: $custom_access = &mt('Currently from default setting.');
1.306 raeburn 308: } else {
309: $custom_access = &mt('Currently from custom setting.');
1.275 raeburn 310: }
1.362 raeburn 311: } elsif ($context eq 'requestauthor') {
312: if ($userenv{$context} eq '') {
313: $custom_access = &mt('Currently from default setting.');
314: } else {
315: $custom_access = &mt('Currently from custom setting.');
316: }
1.275 raeburn 317: } else {
1.306 raeburn 318: if ($userenv{$context.'.'.$item} eq '') {
1.314 raeburn 319: $custom_access =
1.306 raeburn 320: &mt('Availability determined currently from default setting.');
321: if (!$curr_access) {
322: $tool_off = 'checked="checked" ';
323: $tool_on = '';
324: }
325: } else {
1.314 raeburn 326: $custom_access =
1.306 raeburn 327: &mt('Availability determined currently from custom setting.');
328: if ($userenv{$context.'.'.$item} == 0) {
329: $tool_off = 'checked="checked" ';
330: $tool_on = '';
331: }
1.275 raeburn 332: }
333: }
334: $output .= ' <tr class="LC_info_row">'."\n".
1.306 raeburn 335: ' <td'.$colspan.'>'.$lt{$item}.'</td>'."\n".
1.275 raeburn 336: ' </tr>'."\n".
1.306 raeburn 337: &Apache::loncommon::start_data_table_row()."\n";
1.418 raeburn 338:
1.362 raeburn 339: if (($context eq 'requestcourses') || ($context eq 'requestauthor')) {
1.306 raeburn 340: my ($curroption,$currlimit);
1.362 raeburn 341: my $envkey = $context.'.'.$item;
342: if ($context eq 'requestauthor') {
343: $envkey = $context;
344: }
345: if ($userenv{$envkey} ne '') {
346: $curroption = $userenv{$envkey};
1.332 raeburn 347: } else {
348: my (@inststatuses);
1.362 raeburn 349: if ($context eq 'requestcourses') {
350: $curroption =
351: &Apache::loncoursequeueadmin::get_processtype('course',$ccuname,$ccdomain,
352: $isadv,$ccdomain,$item,
353: \@inststatuses,\%domconfig);
354: } else {
355: $curroption =
356: &Apache::loncoursequeueadmin::get_processtype('requestauthor',$ccuname,$ccdomain,
357: $isadv,$ccdomain,undef,
358: \@inststatuses,\%domconfig);
359: }
1.332 raeburn 360: }
1.306 raeburn 361: if (!$curroption) {
362: $curroption = 'norequest';
363: }
364: if ($curroption =~ /^autolimit=(\d*)$/) {
365: $currlimit = $1;
1.314 raeburn 366: if ($currlimit eq '') {
367: $currdisp = &mt('Yes, automatic creation');
368: } else {
369: $currdisp = &mt('Yes, up to [quant,_1,request]/user',$currlimit);
370: }
1.306 raeburn 371: } else {
372: $currdisp = $reqdisplay{$curroption};
373: }
374: $custdisp = '<table>';
375: foreach my $option (@options) {
376: my $val = $option;
377: if ($option eq 'norequest') {
378: $val = 0;
379: }
380: if ($option eq 'validate') {
381: my $canvalidate = 0;
382: if (ref($validations{$item}) eq 'HASH') {
383: if ($validations{$item}{'_custom_'}) {
384: $canvalidate = 1;
385: }
386: }
387: next if (!$canvalidate);
388: }
389: my $checked = '';
390: if ($option eq $curroption) {
391: $checked = ' checked="checked"';
392: } elsif ($option eq 'autolimit') {
393: if ($curroption =~ /^autolimit/) {
394: $checked = ' checked="checked"';
395: }
396: }
1.362 raeburn 397: my $name = 'crsreq_'.$item;
398: if ($context eq 'requestauthor') {
399: $name = $item;
400: }
1.306 raeburn 401: $custdisp .= '<tr><td><span class="LC_nobreak"><label>'.
1.362 raeburn 402: '<input type="radio" name="'.$name.'" '.
403: 'value="'.$val.'"'.$checked.' />'.
1.306 raeburn 404: $reqtitles{$option}.'</label> ';
405: if ($option eq 'autolimit') {
1.362 raeburn 406: $custdisp .= '<input type="text" name="'.$name.
407: '_limit" size="1" '.
1.314 raeburn 408: 'value="'.$currlimit.'" /></span><br />'.
409: $reqtitles{'unlimited'};
1.362 raeburn 410: } else {
411: $custdisp .= '</span>';
412: }
413: $custdisp .= '</td></tr>';
1.306 raeburn 414: }
415: $custdisp .= '</table>';
416: $custradio = '</span></td><td>'.&mt('Custom setting').'<br />'.$custdisp;
417: } else {
418: $currdisp = ($curr_access?&mt('Yes'):&mt('No'));
1.362 raeburn 419: my $name = $context.'_'.$item;
420: if ($context eq 'requestauthor') {
421: $name = $context;
422: }
1.306 raeburn 423: $custdisp = '<span class="LC_nobreak"><label>'.
1.362 raeburn 424: '<input type="radio" name="'.$name.'"'.
1.361 raeburn 425: ' value="1" '.$tool_on.'/>'.&mt('On').'</label> <label>'.
1.362 raeburn 426: '<input type="radio" name="'.$name.'" value="0" '.
1.306 raeburn 427: $tool_off.'/>'.&mt('Off').'</label></span>';
428: $custradio = (' 'x2).'--'.$lt{'cusa'}.': '.$custdisp.
429: '</span>';
430: }
431: $output .= ' <td'.$colspan.'>'.$custom_access.(' 'x4).
1.419 raeburn 432: $lt{'avai'}.': '.$currdisp.'</td>'."\n".
1.418 raeburn 433: &Apache::loncommon::end_data_table_row()."\n";
434: unless (&Apache::lonnet::allowed('udp',$ccdomain)) {
435: $output .=
1.275 raeburn 436: &Apache::loncommon::start_data_table_row()."\n".
1.306 raeburn 437: ' <td style="vertical-align:top;"><span class="LC_nobreak">'.
438: $lt{'chse'}.': <label>'.
1.275 raeburn 439: '<input type="radio" name="custom'.$item.'" value="0" '.
1.306 raeburn 440: $cust_off.'/>'.$lt{'usde'}.'</label>'.(' ' x3).
441: '<label><input type="radio" name="custom'.$item.'" value="1" '.
442: $cust_on.'/>'.$lt{'uscu'}.'</label>'.$custradio.'</td>'.
1.275 raeburn 443: &Apache::loncommon::end_data_table_row()."\n";
1.418 raeburn 444: }
1.275 raeburn 445: }
446: return $output;
447: }
448:
1.300 raeburn 449: sub coursereq_externaluser {
450: my ($ccuname,$ccdomain,$cdom) = @_;
1.306 raeburn 451: my (@usertools,@options,%validations,%userenv,$output);
1.300 raeburn 452: my %lt = &Apache::lonlocal::texthash (
453: 'official' => 'Can request creation of official courses',
454: 'unofficial' => 'Can request creation of unofficial courses',
455: 'community' => 'Can request creation of communities',
1.384 raeburn 456: 'textbook' => 'Can request creation of textbook courses',
1.411 raeburn 457: 'placement' => 'Can request creation of placement tests',
1.300 raeburn 458: );
459:
460: %userenv = &Apache::lonnet::userenvironment($ccdomain,$ccuname,
461: 'reqcrsotherdom.official','reqcrsotherdom.unofficial',
1.411 raeburn 462: 'reqcrsotherdom.community','reqcrsotherdom.textbook',
463: 'reqcrsotherdom.placement');
464: @usertools = ('official','unofficial','community','textbook','placement');
1.309 raeburn 465: @options = ('approval','validate','autolimit');
1.306 raeburn 466: %validations = &Apache::lonnet::auto_courserequest_checks($cdom);
467: my $optregex = join('|',@options);
468: my %reqtitles = &courserequest_titles();
1.300 raeburn 469: foreach my $item (@usertools) {
1.306 raeburn 470: my ($curroption,$currlimit,$tooloff);
1.300 raeburn 471: if ($userenv{'reqcrsotherdom.'.$item} ne '') {
472: my @curr = split(',',$userenv{'reqcrsotherdom.'.$item});
1.314 raeburn 473: foreach my $req (@curr) {
474: if ($req =~ /^\Q$cdom\E\:($optregex)=?(\d*)$/) {
475: $curroption = $1;
476: $currlimit = $2;
477: last;
1.306 raeburn 478: }
479: }
1.314 raeburn 480: if (!$curroption) {
481: $curroption = 'norequest';
482: $tooloff = ' checked="checked"';
483: }
1.306 raeburn 484: } else {
485: $curroption = 'norequest';
486: $tooloff = ' checked="checked"';
487: }
488: $output.= &Apache::loncommon::start_data_table_row()."\n".
1.314 raeburn 489: ' <td><span class="LC_nobreak">'.$lt{$item}.': </span></td><td>'.
490: '<table><tr><td valign="top">'."\n".
1.306 raeburn 491: '<label><input type="radio" name="reqcrsotherdom_'.$item.
1.314 raeburn 492: '" value=""'.$tooloff.' />'.$reqtitles{'norequest'}.
493: '</label></td>';
1.306 raeburn 494: foreach my $option (@options) {
495: if ($option eq 'validate') {
496: my $canvalidate = 0;
497: if (ref($validations{$item}) eq 'HASH') {
498: if ($validations{$item}{'_external_'}) {
499: $canvalidate = 1;
500: }
501: }
502: next if (!$canvalidate);
503: }
504: my $checked = '';
505: if ($option eq $curroption) {
506: $checked = ' checked="checked"';
507: }
1.314 raeburn 508: $output .= '<td valign="top"><span class="LC_nobreak"><label>'.
1.306 raeburn 509: '<input type="radio" name="reqcrsotherdom_'.$item.
510: '" value="'.$option.'"'.$checked.' />'.
1.314 raeburn 511: $reqtitles{$option}.'</label>';
1.306 raeburn 512: if ($option eq 'autolimit') {
1.314 raeburn 513: $output .= ' <input type="text" name="reqcrsotherdom_'.
1.306 raeburn 514: $item.'_limit" size="1" '.
1.314 raeburn 515: 'value="'.$currlimit.'" /></span>'.
516: '<br />'.$reqtitles{'unlimited'};
517: } else {
518: $output .= '</span>';
1.300 raeburn 519: }
1.314 raeburn 520: $output .= '</td>';
1.300 raeburn 521: }
1.314 raeburn 522: $output .= '</td></tr></table></td>'."\n".
1.300 raeburn 523: &Apache::loncommon::end_data_table_row()."\n";
524: }
525: return $output;
526: }
527:
1.362 raeburn 528: sub domainrole_req {
529: my ($ccuname,$ccdomain) = @_;
530: return '<br /><h3>'.
531: &mt('User Can Request Assignment of Domain Roles?').
532: '</h3>'."\n".
533: &Apache::loncommon::start_data_table().
534: &build_tools_display($ccuname,$ccdomain,
535: 'requestauthor').
536: &Apache::loncommon::end_data_table();
537: }
538:
1.306 raeburn 539: sub courserequest_titles {
540: my %titles = &Apache::lonlocal::texthash (
541: official => 'Official',
542: unofficial => 'Unofficial',
543: community => 'Communities',
1.384 raeburn 544: textbook => 'Textbook',
1.411 raeburn 545: placement => 'Placement Tests',
1.306 raeburn 546: norequest => 'Not allowed',
1.309 raeburn 547: approval => 'Approval by Dom. Coord.',
1.306 raeburn 548: validate => 'With validation',
549: autolimit => 'Numerical limit',
1.314 raeburn 550: unlimited => '(blank for unlimited)',
1.306 raeburn 551: );
552: return %titles;
553: }
554:
555: sub courserequest_display {
556: my %titles = &Apache::lonlocal::texthash (
1.309 raeburn 557: approval => 'Yes, need approval',
1.306 raeburn 558: validate => 'Yes, with validation',
559: norequest => 'No',
560: );
561: return %titles;
562: }
563:
1.362 raeburn 564: sub requestauthor_titles {
565: my %titles = &Apache::lonlocal::texthash (
566: norequest => 'Not allowed',
567: approval => 'Approval by Dom. Coord.',
568: automatic => 'Automatic approval',
569: );
570: return %titles;
571:
572: }
573:
574: sub requestauthor_display {
575: my %titles = &Apache::lonlocal::texthash (
576: approval => 'Yes, need approval',
577: automatic => 'Yes, automatic approval',
578: norequest => 'No',
579: );
580: return %titles;
581: }
582:
1.383 raeburn 583: sub requestchange_display {
584: my %titles = &Apache::lonlocal::texthash (
585: approval => "availability set to 'on' (approval required)",
586: automatic => "availability set to 'on' (automatic approval)",
587: norequest => "availability set to 'off'",
588: );
589: return %titles;
590: }
591:
1.362 raeburn 592: sub curr_requestauthor {
593: my ($uname,$udom,$isadv,$inststatuses,$domconfig) = @_;
594: return unless ((ref($inststatuses) eq 'ARRAY') && (ref($domconfig) eq 'HASH'));
595: if ($uname eq '' || $udom eq '') {
596: $uname = $env{'user.name'};
597: $udom = $env{'user.domain'};
598: $isadv = $env{'user.adv'};
599: }
600: my (%userenv,%settings,$val);
601: my @options = ('automatic','approval');
602: %userenv =
603: &Apache::lonnet::userenvironment($udom,$uname,'requestauthor','inststatus');
604: if ($userenv{'requestauthor'}) {
605: $val = $userenv{'requestauthor'};
606: @{$inststatuses} = ('_custom_');
607: } else {
608: my %alltasks;
609: if (ref($domconfig->{'requestauthor'}) eq 'HASH') {
610: %settings = %{$domconfig->{'requestauthor'}};
611: if (($isadv) && ($settings{'_LC_adv'} ne '')) {
612: $val = $settings{'_LC_adv'};
613: @{$inststatuses} = ('_LC_adv_');
614: } else {
615: if ($userenv{'inststatus'} ne '') {
616: @{$inststatuses} = split(',',$userenv{'inststatus'});
617: } else {
618: @{$inststatuses} = ('default');
619: }
620: foreach my $status (@{$inststatuses}) {
621: if (exists($settings{$status})) {
622: my $value = $settings{$status};
623: next unless ($value);
624: unless (exists($alltasks{$value})) {
625: if (ref($alltasks{$value}) eq 'ARRAY') {
626: unless(grep(/^\Q$status\E$/,@{$alltasks{$value}})) {
627: push(@{$alltasks{$value}},$status);
628: }
629: } else {
630: @{$alltasks{$value}} = ($status);
631: }
632: }
633: }
634: }
635: foreach my $option (@options) {
636: if ($alltasks{$option}) {
637: $val = $option;
638: last;
639: }
640: }
641: }
642: }
643: }
644: return $val;
645: }
646:
1.2 www 647: # =================================================================== Phase one
1.1 www 648:
1.42 matthew 649: sub print_username_entry_form {
1.439 raeburn 650: my ($r,$context,$response,$srch,$forcenewuser,$crstype,$brcrum,
651: $permission) = @_;
1.101 albertel 652: my $defdom=$env{'request.role.domain'};
1.160 raeburn 653: my $formtoset = 'crtuser';
654: if (exists($env{'form.startrolename'})) {
655: $formtoset = 'docustom';
656: $env{'form.rolename'} = $env{'form.startrolename'};
1.207 raeburn 657: } elsif ($env{'form.origform'} eq 'crtusername') {
658: $formtoset = $env{'form.origform'};
1.160 raeburn 659: }
660:
661: my ($jsback,$elements) = &crumb_utilities();
662:
663: my $jscript = &Apache::loncommon::studentbrowser_javascript()."\n".
1.165 albertel 664: '<script type="text/javascript">'."\n".
1.301 bisitz 665: '// <![CDATA['."\n".
666: &Apache::lonhtmlcommon::set_form_elements($elements->{$formtoset})."\n".
667: '// ]]>'."\n".
1.162 raeburn 668: '</script>'."\n";
1.160 raeburn 669:
1.324 raeburn 670: my %existingroles=&Apache::lonuserutils::my_custom_roles($crstype);
671: if (($env{'form.action'} eq 'custom') && (keys(%existingroles) > 0)
672: && (&Apache::lonnet::allowed('mcr','/'))) {
673: $jscript .= &customrole_javascript();
674: }
1.224 raeburn 675: my $helpitem = 'Course_Change_Privileges';
676: if ($env{'form.action'} eq 'custom') {
1.439 raeburn 677: if ($context eq 'course') {
678: $helpitem = 'Course_Editing_Custom_Roles';
679: } elsif ($context eq 'domain') {
680: $helpitem = 'Domain_Editing_Custom_Roles';
681: }
1.224 raeburn 682: } elsif ($env{'form.action'} eq 'singlestudent') {
683: $helpitem = 'Course_Add_Student';
1.416 raeburn 684: } elsif ($env{'form.action'} eq 'accesslogs') {
685: $helpitem = 'Domain_User_Access_Logs';
1.439 raeburn 686: } elsif ($context eq 'author') {
687: $helpitem = 'Author_Change_Privileges';
688: } elsif ($context eq 'domain') {
689: if ($permission->{'cusr'}) {
690: $helpitem = 'Domain_Change_Privileges';
691: } elsif ($permission->{'view'}) {
692: $helpitem = 'Domain_View_Privileges';
693: } else {
694: undef($helpitem);
695: }
1.224 raeburn 696: }
1.422 raeburn 697: my %breadcrumb_text = &singleuser_breadcrumb($crstype,$context,$defdom);
1.351 raeburn 698: if ($env{'form.action'} eq 'custom') {
699: push(@{$brcrum},
700: {href=>"javascript:backPage(document.crtuser)",
701: text=>"Pick custom role",
702: help => $helpitem,}
703: );
704: } else {
705: push (@{$brcrum},
706: {href => "javascript:backPage(document.crtuser)",
707: text => $breadcrumb_text{'search'},
708: help => $helpitem,
709: faq => 282,
710: bug => 'Instructor Interface',}
711: );
712: }
713: my %loaditems = (
714: 'onload' => "javascript:setFormElements(document.$formtoset)",
715: );
716: my $args = {bread_crumbs => $brcrum,
717: bread_crumbs_component => 'User Management',
718: add_entries => \%loaditems,};
719: $r->print(&Apache::loncommon::start_page('User Management',$jscript,$args));
720:
1.71 sakharuk 721: my %lt=&Apache::lonlocal::texthash(
1.229 raeburn 722: 'srst' => 'Search for a user and enroll as a student',
1.318 raeburn 723: 'srme' => 'Search for a user and enroll as a member',
1.229 raeburn 724: 'srad' => 'Search for a user and modify/add user information or roles',
1.422 raeburn 725: 'srvu' => 'Search for a user and view user information and roles',
1.416 raeburn 726: 'srva' => 'Search for a user and view access log information',
1.71 sakharuk 727: 'usr' => "Username",
728: 'dom' => "Domain",
1.324 raeburn 729: 'ecrp' => "Define or Edit Custom Role",
730: 'nr' => "role name",
1.282 schafran 731: 'cre' => "Next",
1.71 sakharuk 732: );
1.351 raeburn 733:
1.214 raeburn 734: if ($env{'form.action'} eq 'custom') {
1.190 raeburn 735: if (&Apache::lonnet::allowed('mcr','/')) {
1.324 raeburn 736: my $newroletext = &mt('Define new custom role:');
737: $r->print('<form action="/adm/createuser" method="post" name="docustom">'.
738: '<input type="hidden" name="action" value="'.$env{'form.action'}.'" />'.
739: '<input type="hidden" name="phase" value="selected_custom_edit" />'.
740: '<h3>'.$lt{'ecrp'}.'</h3>'.
741: &Apache::loncommon::start_data_table().
742: &Apache::loncommon::start_data_table_row().
743: '<td>');
744: if (keys(%existingroles) > 0) {
745: $r->print('<br /><label><input type="radio" name="customroleaction" value="new" checked="checked" onclick="setCustomFields();" /><b>'.$newroletext.'</b></label>');
746: } else {
747: $r->print('<br /><input type="hidden" name="customroleaction" value="new" /><b>'.$newroletext.'</b>');
748: }
749: $r->print('</td><td align="center">'.$lt{'nr'}.'<br /><input type="text" size="15" name="newrolename" onfocus="setCustomAction('."'new'".');" /></td>'.
750: &Apache::loncommon::end_data_table_row());
751: if (keys(%existingroles) > 0) {
752: $r->print(&Apache::loncommon::start_data_table_row().'<td><br />'.
753: '<label><input type="radio" name="customroleaction" value="edit" onclick="setCustomFields();"/><b>'.
754: &mt('View/Modify existing role:').'</b></label></td>'.
755: '<td align="center"><br />'.
756: '<select name="rolename" onchange="setCustomAction('."'edit'".');">'.
1.326 raeburn 757: '<option value="" selected="selected">'.
1.324 raeburn 758: &mt('Select'));
759: foreach my $role (sort(keys(%existingroles))) {
1.326 raeburn 760: $r->print('<option value="'.$role.'">'.$role.'</option>');
1.324 raeburn 761: }
762: $r->print('</select>'.
763: '</td>'.
764: &Apache::loncommon::end_data_table_row());
765: }
766: $r->print(&Apache::loncommon::end_data_table().'<p>'.
767: '<input name="customeditor" type="submit" value="'.
768: $lt{'cre'}.'" /></p>'.
769: '</form>');
1.190 raeburn 770: }
1.213 raeburn 771: } else {
1.229 raeburn 772: my $actiontext = $lt{'srad'};
1.436 raeburn 773: my $fixeddom;
1.213 raeburn 774: if ($env{'form.action'} eq 'singlestudent') {
1.318 raeburn 775: if ($crstype eq 'Community') {
776: $actiontext = $lt{'srme'};
777: } else {
778: $actiontext = $lt{'srst'};
779: }
1.416 raeburn 780: } elsif ($env{'form.action'} eq 'accesslogs') {
1.417 raeburn 781: $actiontext = $lt{'srva'};
1.436 raeburn 782: $fixeddom = 1;
1.422 raeburn 783: } elsif (($env{'form.action'} eq 'singleuser') &&
784: ($context eq 'domain') && (!&Apache::lonnet::allowed('mau',$defdom))) {
785: $actiontext = $lt{'srvu'};
1.439 raeburn 786: $fixeddom = 1;
1.213 raeburn 787: }
1.324 raeburn 788: $r->print("<h3>$actiontext</h3>");
1.213 raeburn 789: if ($env{'form.origform'} ne 'crtusername') {
1.415 raeburn 790: if ($response) {
791: $r->print("\n<div>$response</div>".
792: '<br clear="all" />');
793: }
1.213 raeburn 794: }
1.436 raeburn 795: $r->print(&entry_form($defdom,$srch,$forcenewuser,$context,$response,$crstype,$fixeddom));
1.107 www 796: }
1.110 albertel 797: }
798:
1.324 raeburn 799: sub customrole_javascript {
800: my $js = <<"END";
801: <script type="text/javascript">
802: // <![CDATA[
803:
804: function setCustomFields() {
805: if (document.docustom.customroleaction.length > 0) {
806: for (var i=0; i<document.docustom.customroleaction.length; i++) {
807: if (document.docustom.customroleaction[i].checked) {
808: if (document.docustom.customroleaction[i].value == 'new') {
809: document.docustom.rolename.selectedIndex = 0;
810: } else {
811: document.docustom.newrolename.value = '';
812: }
813: }
814: }
815: }
816: return;
817: }
818:
819: function setCustomAction(caller) {
820: if (document.docustom.customroleaction.length > 0) {
821: for (var i=0; i<document.docustom.customroleaction.length; i++) {
822: if (document.docustom.customroleaction[i].value == caller) {
823: document.docustom.customroleaction[i].checked = true;
824: }
825: }
826: }
827: setCustomFields();
828: return;
829: }
830:
831: // ]]>
832: </script>
833: END
834: return $js;
835: }
836:
1.160 raeburn 837: sub entry_form {
1.416 raeburn 838: my ($dom,$srch,$forcenewuser,$context,$responsemsg,$crstype,$fixeddom) = @_;
1.229 raeburn 839: my ($usertype,$inexact);
1.214 raeburn 840: if (ref($srch) eq 'HASH') {
841: if (($srch->{'srchin'} eq 'dom') &&
842: ($srch->{'srchby'} eq 'uname') &&
843: ($srch->{'srchtype'} eq 'exact') &&
844: ($srch->{'srchdomain'} ne '') &&
845: ($srch->{'srchterm'} ne '')) {
1.353 raeburn 846: my (%curr_rules,%got_rules);
1.214 raeburn 847: my ($rules,$ruleorder) =
848: &Apache::lonnet::inst_userrules($srch->{'srchdomain'},'username');
1.353 raeburn 849: $usertype = &Apache::lonuserutils::check_usertype($srch->{'srchdomain'},$srch->{'srchterm'},$rules,\%curr_rules,\%got_rules);
1.229 raeburn 850: } else {
851: $inexact = 1;
1.214 raeburn 852: }
1.207 raeburn 853: }
1.438 raeburn 854: my ($cancreate,$noinstd);
855: if ($env{'form.action'} eq 'accesslogs') {
856: $noinstd = 1;
857: } else {
858: $cancreate =
859: &Apache::lonuserutils::can_create_user($dom,$context,$usertype);
860: }
1.412 raeburn 861: my ($userpicker,$cansearch) =
1.179 raeburn 862: &Apache::loncommon::user_picker($dom,$srch,$forcenewuser,
1.438 raeburn 863: 'document.crtuser',$cancreate,$usertype,$context,$fixeddom,$noinstd);
1.160 raeburn 864: my $srchbutton = &mt('Search');
1.229 raeburn 865: if ($env{'form.action'} eq 'singlestudent') {
866: $srchbutton = &mt('Search and Enroll');
1.416 raeburn 867: } elsif ($env{'form.action'} eq 'accesslogs') {
868: $srchbutton = &mt('Search');
1.229 raeburn 869: } elsif ($cancreate && $responsemsg ne '' && $inexact) {
870: $srchbutton = &mt('Search or Add New User');
871: }
1.412 raeburn 872: my $output;
873: if ($cansearch) {
874: $output = <<"ENDBLOCK";
1.160 raeburn 875: <form action="/adm/createuser" method="post" name="crtuser">
1.190 raeburn 876: <input type="hidden" name="action" value="$env{'form.action'}" />
1.160 raeburn 877: <input type="hidden" name="phase" value="get_user_info" />
878: $userpicker
1.179 raeburn 879: <input name="userrole" type="button" value="$srchbutton" onclick="javascript:validateEntry(document.crtuser)" />
1.160 raeburn 880: </form>
1.207 raeburn 881: ENDBLOCK
1.412 raeburn 882: } else {
883: $output = '<p>'.$userpicker.'</p>';
884: }
1.422 raeburn 885: if (($env{'form.phase'} eq '') && ($env{'form.action'} ne 'accesslogs') &&
1.430 raeburn 886: (!(($env{'form.action'} eq 'singleuser') && ($context eq 'domain') &&
1.422 raeburn 887: (!&Apache::lonnet::allowed('mau',$env{'request.role.domain'}))))) {
1.207 raeburn 888: my $defdom=$env{'request.role.domain'};
889: my $domform = &Apache::loncommon::select_dom_form($defdom,'srchdomain');
890: my %lt=&Apache::lonlocal::texthash(
1.229 raeburn 891: 'enro' => 'Enroll one student',
1.318 raeburn 892: 'enrm' => 'Enroll one member',
1.229 raeburn 893: 'admo' => 'Add/modify a single user',
894: 'crea' => 'create new user if required',
895: 'uskn' => "username is known",
1.207 raeburn 896: 'crnu' => 'Create a new user',
897: 'usr' => 'Username',
898: 'dom' => 'in domain',
1.229 raeburn 899: 'enrl' => 'Enroll',
900: 'cram' => 'Create/Modify user',
1.207 raeburn 901: );
1.229 raeburn 902: my $sellink=&Apache::loncommon::selectstudent_link('crtusername','srchterm','srchdomain');
903: my ($title,$buttontext,$showresponse);
1.318 raeburn 904: if ($env{'form.action'} eq 'singlestudent') {
905: if ($crstype eq 'Community') {
906: $title = $lt{'enrm'};
907: } else {
908: $title = $lt{'enro'};
909: }
1.229 raeburn 910: $buttontext = $lt{'enrl'};
911: } else {
912: $title = $lt{'admo'};
913: $buttontext = $lt{'cram'};
914: }
915: if ($cancreate) {
916: $title .= ' <span class="LC_cusr_subheading">('.$lt{'crea'}.')</span>';
917: } else {
918: $title .= ' <span class="LC_cusr_subheading">('.$lt{'uskn'}.')</span>';
919: }
920: if ($env{'form.origform'} eq 'crtusername') {
921: $showresponse = $responsemsg;
922: }
1.207 raeburn 923: $output .= <<"ENDDOCUMENT";
1.229 raeburn 924: <br />
1.207 raeburn 925: <form action="/adm/createuser" method="post" name="crtusername">
926: <input type="hidden" name="action" value="$env{'form.action'}" />
927: <input type="hidden" name="phase" value="createnewuser" />
928: <input type="hidden" name="srchtype" value="exact" />
1.233 raeburn 929: <input type="hidden" name="srchby" value="uname" />
1.207 raeburn 930: <input type="hidden" name="srchin" value="dom" />
931: <input type="hidden" name="forcenewuser" value="1" />
932: <input type="hidden" name="origform" value="crtusername" />
1.229 raeburn 933: <h3>$title</h3>
934: $showresponse
1.207 raeburn 935: <table>
936: <tr>
937: <td>$lt{'usr'}:</td>
938: <td><input type="text" size="15" name="srchterm" /></td>
939: <td> $lt{'dom'}:</td><td>$domform</td>
1.229 raeburn 940: <td> $sellink </td>
941: <td> <input name="userrole" type="submit" value="$buttontext" /></td>
1.207 raeburn 942: </tr>
943: </table>
944: </form>
1.160 raeburn 945: ENDDOCUMENT
1.207 raeburn 946: }
1.160 raeburn 947: return $output;
948: }
1.110 albertel 949:
950: sub user_modification_js {
1.113 raeburn 951: my ($pjump_def,$dc_setcourse_code,$nondc_setsection_code,$groupslist)=@_;
952:
1.110 albertel 953: return <<END;
954: <script type="text/javascript" language="Javascript">
1.301 bisitz 955: // <![CDATA[
1.314 raeburn 956:
1.110 albertel 957: $pjump_def
958: $dc_setcourse_code
959:
960: function dateset() {
961: eval("document.cu."+document.cu.pres_marker.value+
962: ".value=document.cu.pres_value.value");
1.359 www 963: modalWindow.close();
1.110 albertel 964: }
965:
1.113 raeburn 966: $nondc_setsection_code
1.301 bisitz 967: // ]]>
1.110 albertel 968: </script>
969: END
1.2 www 970: }
971:
972: # =================================================================== Phase two
1.160 raeburn 973: sub print_user_selection_page {
1.351 raeburn 974: my ($r,$response,$srch,$srch_results,$srcharray,$context,$opener_elements,$crstype,$brcrum) = @_;
1.160 raeburn 975: my @fields = ('username','domain','lastname','firstname','permanentemail');
976: my $sortby = $env{'form.sortby'};
977:
978: if (!grep(/^\Q$sortby\E$/,@fields)) {
979: $sortby = 'lastname';
980: }
981:
982: my ($jsback,$elements) = &crumb_utilities();
983:
984: my $jscript = (<<ENDSCRIPT);
985: <script type="text/javascript">
1.301 bisitz 986: // <![CDATA[
1.160 raeburn 987: function pickuser(uname,udom) {
988: document.usersrchform.seluname.value=uname;
989: document.usersrchform.seludom.value=udom;
990: document.usersrchform.phase.value="userpicked";
991: document.usersrchform.submit();
992: }
993:
994: $jsback
1.301 bisitz 995: // ]]>
1.160 raeburn 996: </script>
997: ENDSCRIPT
998:
999: my %lt=&Apache::lonlocal::texthash(
1.179 raeburn 1000: 'usrch' => "User Search to add/modify roles",
1001: 'stusrch' => "User Search to enroll student",
1.318 raeburn 1002: 'memsrch' => "User Search to enroll member",
1.416 raeburn 1003: 'srcva' => "Search for a user and view access log information",
1.422 raeburn 1004: 'usrvu' => "User Search to view user roles",
1.179 raeburn 1005: 'usel' => "Select a user to add/modify roles",
1.422 raeburn 1006: 'suvr' => "Select a user to view roles",
1.318 raeburn 1007: 'stusel' => "Select a user to enroll as a student",
1008: 'memsel' => "Select a user to enroll as a member",
1.416 raeburn 1009: 'vacsel' => "Select a user to view access log",
1.160 raeburn 1010: 'username' => "username",
1011: 'domain' => "domain",
1012: 'lastname' => "last name",
1013: 'firstname' => "first name",
1014: 'permanentemail' => "permanent e-mail",
1015: );
1.302 raeburn 1016: if ($context eq 'requestcrs') {
1017: $r->print('<div>');
1018: } else {
1.422 raeburn 1019: my %breadcrumb_text = &singleuser_breadcrumb($crstype,$context,$srch->{'srchdomain'});
1.351 raeburn 1020: my $helpitem;
1021: if ($env{'form.action'} eq 'singleuser') {
1022: $helpitem = 'Course_Change_Privileges';
1023: } elsif ($env{'form.action'} eq 'singlestudent') {
1024: $helpitem = 'Course_Add_Student';
1.439 raeburn 1025: } elsif ($context eq 'author') {
1026: $helpitem = 'Author_Change_Privileges';
1027: } elsif ($context eq 'domain') {
1028: $helpitem = 'Domain_Change_Privileges';
1.351 raeburn 1029: }
1030: push (@{$brcrum},
1031: {href => "javascript:backPage(document.usersrchform,'','')",
1032: text => $breadcrumb_text{'search'},
1033: faq => 282,
1034: bug => 'Instructor Interface',},
1035: {href => "javascript:backPage(document.usersrchform,'get_user_info','select')",
1036: text => $breadcrumb_text{'userpicked'},
1037: faq => 282,
1038: bug => 'Instructor Interface',
1039: help => $helpitem}
1040: );
1041: $r->print(&Apache::loncommon::start_page('User Management',$jscript,{bread_crumbs => $brcrum}));
1.302 raeburn 1042: if ($env{'form.action'} eq 'singleuser') {
1.422 raeburn 1043: my $readonly;
1044: if (($context eq 'domain') && (!&Apache::lonnet::allowed('mau',$srch->{'srchdomain'}))) {
1045: $readonly = 1;
1046: $r->print("<b>$lt{'usrvu'}</b><br />");
1047: } else {
1048: $r->print("<b>$lt{'usrch'}</b><br />");
1049: }
1.318 raeburn 1050: $r->print(&entry_form($srch->{'srchdomain'},$srch,undef,$context,undef,$crstype));
1.422 raeburn 1051: if ($readonly) {
1052: $r->print('<h3>'.$lt{'suvr'}.'</h3>');
1053: } else {
1054: $r->print('<h3>'.$lt{'usel'}.'</h3>');
1055: }
1.302 raeburn 1056: } elsif ($env{'form.action'} eq 'singlestudent') {
1.318 raeburn 1057: $r->print($jscript."<b>");
1058: if ($crstype eq 'Community') {
1059: $r->print($lt{'memsrch'});
1060: } else {
1061: $r->print($lt{'stusrch'});
1062: }
1063: $r->print("</b><br />");
1064: $r->print(&entry_form($srch->{'srchdomain'},$srch,undef,$context,undef,$crstype));
1065: $r->print('</form><h3>');
1066: if ($crstype eq 'Community') {
1067: $r->print($lt{'memsel'});
1068: } else {
1069: $r->print($lt{'stusel'});
1070: }
1071: $r->print('</h3>');
1.416 raeburn 1072: } elsif ($env{'form.action'} eq 'accesslogs') {
1073: $r->print("<b>$lt{'srcva'}</b><br />");
1.438 raeburn 1074: $r->print(&entry_form($srch->{'srchdomain'},$srch,undef,$context,undef,undef,1));
1.416 raeburn 1075: $r->print('<h3>'.$lt{'vacsel'}.'</h3>');
1.302 raeburn 1076: }
1.179 raeburn 1077: }
1.380 bisitz 1078: $r->print('<form name="usersrchform" method="post" action="">'.
1.160 raeburn 1079: &Apache::loncommon::start_data_table()."\n".
1080: &Apache::loncommon::start_data_table_header_row()."\n".
1081: ' <th> </th>'."\n");
1082: foreach my $field (@fields) {
1083: $r->print(' <th><a href="javascript:document.usersrchform.sortby.value='.
1084: "'".$field."'".';document.usersrchform.submit();">'.
1085: $lt{$field}.'</a></th>'."\n");
1086: }
1087: $r->print(&Apache::loncommon::end_data_table_header_row());
1088:
1089: my @sorted_users = sort {
1.167 albertel 1090: lc($srch_results->{$a}->{$sortby}) cmp lc($srch_results->{$b}->{$sortby})
1.160 raeburn 1091: ||
1.167 albertel 1092: lc($srch_results->{$a}->{lastname}) cmp lc($srch_results->{$b}->{lastname})
1.160 raeburn 1093: ||
1094: lc($srch_results->{$a}->{firstname}) cmp lc($srch_results->{$b}->{firstname})
1.167 albertel 1095: ||
1096: lc($a) cmp lc($b)
1.160 raeburn 1097: } (keys(%$srch_results));
1098:
1099: foreach my $user (@sorted_users) {
1100: my ($uname,$udom) = split(/:/,$user);
1.302 raeburn 1101: my $onclick;
1102: if ($context eq 'requestcrs') {
1.314 raeburn 1103: $onclick =
1.302 raeburn 1104: 'onclick="javascript:gochoose('."'$uname','$udom',".
1105: "'$srch_results->{$user}->{firstname}',".
1106: "'$srch_results->{$user}->{lastname}',".
1107: "'$srch_results->{$user}->{permanentemail}'".');"';
1108: } else {
1.314 raeburn 1109: $onclick =
1.302 raeburn 1110: ' onclick="javascript:pickuser('."'".$uname."'".','."'".$udom."'".');"';
1111: }
1.160 raeburn 1112: $r->print(&Apache::loncommon::start_data_table_row().
1.302 raeburn 1113: '<td><input type="button" name="seluser" value="'.&mt('Select').'" '.
1114: $onclick.' /></td>'.
1.160 raeburn 1115: '<td><tt>'.$uname.'</tt></td>'.
1116: '<td><tt>'.$udom.'</tt></td>');
1117: foreach my $field ('lastname','firstname','permanentemail') {
1118: $r->print('<td>'.$srch_results->{$user}->{$field}.'</td>');
1119: }
1120: $r->print(&Apache::loncommon::end_data_table_row());
1121: }
1122: $r->print(&Apache::loncommon::end_data_table().'<br /><br />');
1.179 raeburn 1123: if (ref($srcharray) eq 'ARRAY') {
1124: foreach my $item (@{$srcharray}) {
1125: $r->print('<input type="hidden" name="'.$item.'" value="'.$env{'form.'.$item}.'" />'."\n");
1126: }
1127: }
1.160 raeburn 1128: $r->print(' <input type="hidden" name="sortby" value="'.$sortby.'" />'."\n".
1129: ' <input type="hidden" name="seluname" value="" />'."\n".
1130: ' <input type="hidden" name="seludom" value="" />'."\n".
1.179 raeburn 1131: ' <input type="hidden" name="currstate" value="select" />'."\n".
1.190 raeburn 1132: ' <input type="hidden" name="phase" value="get_user_info" />'."\n".
1.214 raeburn 1133: ' <input type="hidden" name="action" value="'.$env{'form.action'}.'" />'."\n");
1.302 raeburn 1134: if ($context eq 'requestcrs') {
1135: $r->print($opener_elements.'</form></div>');
1136: } else {
1.351 raeburn 1137: $r->print($response.'</form>');
1.302 raeburn 1138: }
1.160 raeburn 1139: }
1140:
1141: sub print_user_query_page {
1.351 raeburn 1142: my ($r,$caller,$brcrum) = @_;
1.160 raeburn 1143: # FIXME - this is for a network-wide name search (similar to catalog search)
1144: # To use frames with similar behavior to catalog/portfolio search.
1145: # To be implemented.
1146: return;
1147: }
1148:
1.42 matthew 1149: sub print_user_modification_page {
1.375 raeburn 1150: my ($r,$ccuname,$ccdomain,$srch,$response,$context,$permission,$crstype,
1151: $brcrum,$showcredits) = @_;
1.185 raeburn 1152: if (($ccuname eq '') || ($ccdomain eq '')) {
1.215 raeburn 1153: my $usermsg = &mt('No username and/or domain provided.');
1154: $env{'form.phase'} = '';
1.439 raeburn 1155: &print_username_entry_form($r,$context,$usermsg,'','',$crstype,$brcrum,
1156: $permission);
1.58 www 1157: return;
1158: }
1.213 raeburn 1159: my ($form,$formname);
1160: if ($env{'form.action'} eq 'singlestudent') {
1161: $form = 'document.enrollstudent';
1162: $formname = 'enrollstudent';
1163: } else {
1164: $form = 'document.cu';
1165: $formname = 'cu';
1166: }
1.188 raeburn 1167: my %abv_auth = &auth_abbrev();
1.227 raeburn 1168: my (%rulematch,%inst_results,$newuser,%alerts,%curr_rules,%got_rules);
1.185 raeburn 1169: my $uhome=&Apache::lonnet::homeserver($ccuname,$ccdomain);
1170: if ($uhome eq 'no_host') {
1.215 raeburn 1171: my $usertype;
1172: my ($rules,$ruleorder) =
1173: &Apache::lonnet::inst_userrules($ccdomain,'username');
1174: $usertype =
1.353 raeburn 1175: &Apache::lonuserutils::check_usertype($ccdomain,$ccuname,$rules,
1.362 raeburn 1176: \%curr_rules,\%got_rules);
1.215 raeburn 1177: my $cancreate =
1178: &Apache::lonuserutils::can_create_user($ccdomain,$context,
1179: $usertype);
1180: if (!$cancreate) {
1.292 bisitz 1181: my $helplink = 'javascript:helpMenu('."'display'".')';
1.215 raeburn 1182: my %usertypetext = (
1183: official => 'institutional',
1184: unofficial => 'non-institutional',
1185: );
1186: my $response;
1187: if ($env{'form.origform'} eq 'crtusername') {
1.362 raeburn 1188: $response = '<span class="LC_warning">'.
1189: &mt('No match found for the username [_1] in LON-CAPA domain: [_2]',
1190: '<b>'.$ccuname.'</b>',$ccdomain).
1.215 raeburn 1191: '</span><br />';
1192: }
1.292 bisitz 1193: $response .= '<p class="LC_warning">'
1194: .&mt("You are not authorized to create new $usertypetext{$usertype} users in this domain.")
1.418 raeburn 1195: .' ';
1196: if ($context eq 'domain') {
1197: $response .= &mt('Please contact a [_1] for assistance.',
1198: &Apache::lonnet::plaintext('dc'));
1199: } else {
1200: $response .= &mt('Please contact the [_1]helpdesk[_2] for assistance.'
1201: ,'<a href="'.$helplink.'">','</a>');
1202: }
1203: $response .= '</p><br />';
1.215 raeburn 1204: $env{'form.phase'} = '';
1.439 raeburn 1205: &print_username_entry_form($r,$context,$response,undef,undef,$crstype,$brcrum,
1206: $permission);
1.215 raeburn 1207: return;
1208: }
1.188 raeburn 1209: $newuser = 1;
1.193 raeburn 1210: my $checkhash;
1211: my $checks = { 'username' => 1 };
1.196 raeburn 1212: $checkhash->{$ccuname.':'.$ccdomain} = { 'newuser' => $newuser };
1.193 raeburn 1213: &Apache::loncommon::user_rule_check($checkhash,$checks,
1.196 raeburn 1214: \%alerts,\%rulematch,\%inst_results,\%curr_rules,\%got_rules);
1215: if (ref($alerts{'username'}) eq 'HASH') {
1216: if (ref($alerts{'username'}{$ccdomain}) eq 'HASH') {
1217: my $domdesc =
1.193 raeburn 1218: &Apache::lonnet::domain($ccdomain,'description');
1.196 raeburn 1219: if ($alerts{'username'}{$ccdomain}{$ccuname}) {
1220: my $userchkmsg;
1221: if (ref($curr_rules{$ccdomain}) eq 'HASH') {
1222: $userchkmsg =
1223: &Apache::loncommon::instrule_disallow_msg('username',
1.193 raeburn 1224: $domdesc,1).
1225: &Apache::loncommon::user_rule_formats($ccdomain,
1226: $domdesc,$curr_rules{$ccdomain}{'username'},
1227: 'username');
1.196 raeburn 1228: }
1.215 raeburn 1229: $env{'form.phase'} = '';
1.439 raeburn 1230: &print_username_entry_form($r,$context,$userchkmsg,undef,undef,$crstype,$brcrum,
1231: $permission);
1.196 raeburn 1232: return;
1.215 raeburn 1233: }
1.193 raeburn 1234: }
1.185 raeburn 1235: }
1.187 raeburn 1236: } else {
1.188 raeburn 1237: $newuser = 0;
1.185 raeburn 1238: }
1.160 raeburn 1239: if ($response) {
1.215 raeburn 1240: $response = '<br />'.$response;
1.160 raeburn 1241: }
1.149 raeburn 1242:
1.52 matthew 1243: my $pjump_def = &Apache::lonhtmlcommon::pjump_javascript_definition();
1.88 raeburn 1244: my $dc_setcourse_code = '';
1.119 raeburn 1245: my $nondc_setsection_code = '';
1.112 albertel 1246: my %loaditem;
1.114 albertel 1247:
1.216 raeburn 1248: my $groupslist = &Apache::lonuserutils::get_groupslist();
1.88 raeburn 1249:
1.375 raeburn 1250: my $js = &validation_javascript($context,$ccdomain,$pjump_def,$crstype,
1.216 raeburn 1251: $groupslist,$newuser,$formname,\%loaditem);
1.422 raeburn 1252: my %breadcrumb_text = &singleuser_breadcrumb($crstype,$context,$ccdomain);
1.224 raeburn 1253: my $helpitem = 'Course_Change_Privileges';
1254: if ($env{'form.action'} eq 'singlestudent') {
1255: $helpitem = 'Course_Add_Student';
1.439 raeburn 1256: } elsif ($context eq 'author') {
1257: $helpitem = 'Author_Change_Privileges';
1258: } elsif ($context eq 'domain') {
1259: $helpitem = 'Domain_Change_Privileges';
1.224 raeburn 1260: }
1.351 raeburn 1261: push (@{$brcrum},
1262: {href => "javascript:backPage($form)",
1263: text => $breadcrumb_text{'search'},
1264: faq => 282,
1265: bug => 'Instructor Interface',});
1266: if ($env{'form.phase'} eq 'userpicked') {
1267: push(@{$brcrum},
1268: {href => "javascript:backPage($form,'get_user_info','select')",
1269: text => $breadcrumb_text{'userpicked'},
1270: faq => 282,
1271: bug => 'Instructor Interface',});
1272: }
1273: push(@{$brcrum},
1274: {href => "javascript:backPage($form,'$env{'form.phase'}','modify')",
1275: text => $breadcrumb_text{'modify'},
1276: faq => 282,
1277: bug => 'Instructor Interface',
1278: help => $helpitem});
1279: my $args = {'add_entries' => \%loaditem,
1280: 'bread_crumbs' => $brcrum,
1281: 'bread_crumbs_component' => 'User Management'};
1282: if ($env{'form.popup'}) {
1283: $args->{'no_nav_bar'} = 1;
1284: }
1285: my $start_page =
1286: &Apache::loncommon::start_page('User Management',$js,$args);
1.3 www 1287:
1.25 matthew 1288: my $forminfo =<<"ENDFORMINFO";
1.216 raeburn 1289: <form action="/adm/createuser" method="post" name="$formname">
1.190 raeburn 1290: <input type="hidden" name="phase" value="update_user_data" />
1.188 raeburn 1291: <input type="hidden" name="ccuname" value="$ccuname" />
1292: <input type="hidden" name="ccdomain" value="$ccdomain" />
1.157 albertel 1293: <input type="hidden" name="pres_value" value="" />
1294: <input type="hidden" name="pres_type" value="" />
1295: <input type="hidden" name="pres_marker" value="" />
1.25 matthew 1296: ENDFORMINFO
1.375 raeburn 1297: my (%inccourses,$roledom,$defaultcredits);
1.329 raeburn 1298: if ($context eq 'course') {
1299: $inccourses{$env{'request.course.id'}}=1;
1300: $roledom = $env{'course.'.$env{'request.course.id'}.'.domain'};
1.375 raeburn 1301: if ($showcredits) {
1302: $defaultcredits = &Apache::lonuserutils::get_defaultcredits();
1303: }
1.329 raeburn 1304: } elsif ($context eq 'author') {
1305: $roledom = $env{'request.role.domain'};
1306: } elsif ($context eq 'domain') {
1307: foreach my $key (keys(%env)) {
1308: $roledom = $env{'request.role.domain'};
1309: if ($key=~/^user\.priv\.cm\.\/($roledom)\/($match_username)/) {
1310: $inccourses{$1.'_'.$2}=1;
1311: }
1312: }
1313: } else {
1314: foreach my $key (keys(%env)) {
1315: if ($key=~/^user\.priv\.cm\.\/($match_domain)\/($match_username)/) {
1316: $inccourses{$1.'_'.$2}=1;
1317: }
1.2 www 1318: }
1.24 matthew 1319: }
1.389 bisitz 1320: my $title = '';
1.216 raeburn 1321: if ($newuser) {
1.427 raeburn 1322: my ($portfolioform,$domroleform);
1.267 raeburn 1323: if ((&Apache::lonnet::allowed('mpq',$env{'request.role.domain'})) ||
1324: (&Apache::lonnet::allowed('mut',$env{'request.role.domain'}))) {
1325: # Current user has quota or user tools modification privileges
1.378 raeburn 1326: $portfolioform = '<br />'.&user_quotas($ccuname,$ccdomain);
1.134 raeburn 1327: }
1.383 raeburn 1328: if ((&Apache::lonnet::allowed('cau',$env{'request.role.domain'})) &&
1329: ($ccdomain eq $env{'request.role.domain'})) {
1.362 raeburn 1330: $domroleform = '<br />'.&domainrole_req($ccuname,$ccdomain);
1331: }
1.227 raeburn 1332: &initialize_authen_forms($ccdomain,$formname);
1.188 raeburn 1333: my %lt=&Apache::lonlocal::texthash(
1334: 'lg' => 'Login Data',
1.190 raeburn 1335: 'hs' => "Home Server",
1.188 raeburn 1336: );
1.185 raeburn 1337: $r->print(<<ENDTITLE);
1.110 albertel 1338: $start_page
1.160 raeburn 1339: $response
1.25 matthew 1340: $forminfo
1.31 matthew 1341: <script type="text/javascript" language="Javascript">
1.301 bisitz 1342: // <![CDATA[
1.20 harris41 1343: $loginscript
1.301 bisitz 1344: // ]]>
1.31 matthew 1345: </script>
1.20 harris41 1346: <input type='hidden' name='makeuser' value='1' />
1.185 raeburn 1347: ENDTITLE
1.213 raeburn 1348: if ($env{'form.action'} eq 'singlestudent') {
1.318 raeburn 1349: if ($crstype eq 'Community') {
1.389 bisitz 1350: $title = &mt('Create New User [_1] in domain [_2] as a member',
1351: '"'.$ccuname.'"','"'.$ccdomain.'"');
1.318 raeburn 1352: } else {
1.389 bisitz 1353: $title = &mt('Create New User [_1] in domain [_2] as a student',
1354: '"'.$ccuname.'"','"'.$ccdomain.'"');
1.318 raeburn 1355: }
1.389 bisitz 1356: } else {
1357: $title = &mt('Create New User [_1] in domain [_2]',
1358: '"'.$ccuname.'"','"'.$ccdomain.'"');
1.213 raeburn 1359: }
1.389 bisitz 1360: $r->print('<h2>'.$title.'</h2>'."\n");
1361: $r->print('<div class="LC_left_float">');
1.393 raeburn 1362: $r->print(&personal_data_display($ccuname,$ccdomain,$newuser,$context,
1363: $inst_results{$ccuname.':'.$ccdomain}));
1364: # Option to disable student/employee ID conflict checking not offerred for new users.
1.187 raeburn 1365: my ($home_server_pick,$numlib) =
1366: &Apache::loncommon::home_server_form_item($ccdomain,'hserver',
1367: 'default','hide');
1368: if ($numlib > 1) {
1369: $r->print("
1.185 raeburn 1370: <br />
1.187 raeburn 1371: $lt{'hs'}: $home_server_pick
1372: <br />");
1373: } else {
1374: $r->print($home_server_pick);
1375: }
1.304 raeburn 1376: if (&Apache::lonnet::allowed('ccc',$env{'request.role.domain'})) {
1.362 raeburn 1377: $r->print('<br /><h3>'.
1378: &mt('User Can Request Creation of Courses/Communities in this Domain?').'</h3>'.
1.304 raeburn 1379: &Apache::loncommon::start_data_table().
1380: &build_tools_display($ccuname,$ccdomain,
1381: 'requestcourses').
1382: &Apache::loncommon::end_data_table());
1383: }
1.188 raeburn 1384: $r->print('</div>'."\n".'<div class="LC_left_float"><h3>'.
1385: $lt{'lg'}.'</h3>');
1.185 raeburn 1386: my ($fixedauth,$varauth,$authmsg);
1.193 raeburn 1387: if (ref($rulematch{$ccuname.':'.$ccdomain}) eq 'HASH') {
1388: my $matchedrule = $rulematch{$ccuname.':'.$ccdomain}{'username'};
1389: my ($rules,$ruleorder) =
1390: &Apache::lonnet::inst_userrules($ccdomain,'username');
1.185 raeburn 1391: if (ref($rules) eq 'HASH') {
1.193 raeburn 1392: if (ref($rules->{$matchedrule}) eq 'HASH') {
1393: my $authtype = $rules->{$matchedrule}{'authtype'};
1.185 raeburn 1394: if ($authtype !~ /^(krb4|krb5|int|fsys|loc)$/) {
1.190 raeburn 1395: $r->print(&Apache::lonuserutils::set_login($ccdomain,$authformkrb,$authformint,$authformloc));
1.275 raeburn 1396: } else {
1.193 raeburn 1397: my $authparm = $rules->{$matchedrule}{'authparm'};
1.273 raeburn 1398: $authmsg = $rules->{$matchedrule}{'authmsg'};
1.185 raeburn 1399: if ($authtype =~ /^krb(4|5)$/) {
1400: my $ver = $1;
1401: if ($authparm ne '') {
1402: $fixedauth = <<"KERB";
1403: <input type="hidden" name="login" value="krb" />
1404: <input type="hidden" name="krbver" value="$ver" />
1405: <input type="hidden" name="krbarg" value="$authparm" />
1406: KERB
1407: }
1408: } else {
1409: $fixedauth =
1410: '<input type="hidden" name="login" value="'.$authtype.'" />'."\n";
1.193 raeburn 1411: if ($rules->{$matchedrule}{'authparmfixed'}) {
1.185 raeburn 1412: $fixedauth .=
1413: '<input type="hidden" name="'.$authtype.'arg" value="'.$authparm.'" />'."\n";
1414: } else {
1.273 raeburn 1415: if ($authtype eq 'int') {
1416: $varauth = '<br />'.
1.301 bisitz 1417: &mt('[_1] Internally authenticated (with initial password [_2])','','<input type="password" size="10" name="intarg" value="" />')."<label><input type=\"checkbox\" name=\"visible\" onclick='if (this.checked) { this.form.intarg.type=\"text\" } else { this.form.intarg.type=\"password\" }' />".&mt('Visible input').'</label>';
1.273 raeburn 1418: } elsif ($authtype eq 'loc') {
1419: $varauth = '<br />'.
1420: &mt('[_1] Local Authentication with argument [_2]','','<input type="text" name="'.$authtype.'arg" value="" />')."\n";
1421: } else {
1422: $varauth =
1.185 raeburn 1423: '<input type="text" name="'.$authtype.'arg" value="" />'."\n";
1.273 raeburn 1424: }
1.185 raeburn 1425: }
1426: }
1427: }
1428: } else {
1.190 raeburn 1429: $r->print(&Apache::lonuserutils::set_login($ccdomain,$authformkrb,$authformint,$authformloc));
1.185 raeburn 1430: }
1431: }
1432: if ($authmsg) {
1433: $r->print(<<ENDAUTH);
1434: $fixedauth
1435: $authmsg
1436: $varauth
1437: ENDAUTH
1438: }
1439: } else {
1.190 raeburn 1440: $r->print(&Apache::lonuserutils::set_login($ccdomain,$authformkrb,$authformint,$authformloc));
1.187 raeburn 1441: }
1.427 raeburn 1442: $r->print($portfolioform.$domroleform);
1.215 raeburn 1443: if ($env{'form.action'} eq 'singlestudent') {
1444: $r->print(&date_sections_select($context,$newuser,$formname,
1.375 raeburn 1445: $permission,$crstype,$ccuname,
1446: $ccdomain,$showcredits));
1.215 raeburn 1447: }
1448: $r->print('</div><div class="LC_clear_float_footer"></div>');
1.216 raeburn 1449: } else { # user already exists
1.389 bisitz 1450: $r->print($start_page.$forminfo);
1.213 raeburn 1451: if ($env{'form.action'} eq 'singlestudent') {
1.318 raeburn 1452: if ($crstype eq 'Community') {
1.389 bisitz 1453: $title = &mt('Enroll one member: [_1] in domain [_2]',
1454: '"'.$ccuname.'"','"'.$ccdomain.'"');
1.318 raeburn 1455: } else {
1.389 bisitz 1456: $title = &mt('Enroll one student: [_1] in domain [_2]',
1457: '"'.$ccuname.'"','"'.$ccdomain.'"');
1.318 raeburn 1458: }
1.213 raeburn 1459: } else {
1.418 raeburn 1460: if ($permission->{'cusr'}) {
1461: $title = &mt('Modify existing user: [_1] in domain [_2]',
1462: '"'.$ccuname.'"','"'.$ccdomain.'"');
1463: } else {
1464: $title = &mt('Existing user: [_1] in domain [_2]',
1.389 bisitz 1465: '"'.$ccuname.'"','"'.$ccdomain.'"');
1.418 raeburn 1466: }
1.213 raeburn 1467: }
1.389 bisitz 1468: $r->print('<h2>'.$title.'</h2>'."\n");
1469: $r->print('<div class="LC_left_float">');
1.393 raeburn 1470: $r->print(&personal_data_display($ccuname,$ccdomain,$newuser,$context,
1471: $inst_results{$ccuname.':'.$ccdomain}));
1.430 raeburn 1472: if ((&Apache::lonnet::allowed('ccc',$env{'request.role.domain'})) ||
1.418 raeburn 1473: (&Apache::lonnet::allowed('udp',$env{'request.role.domain'}))) {
1.362 raeburn 1474: $r->print('<br /><h3>'.&mt('User Can Request Creation of Courses/Communities in this Domain?').'</h3>'.
1.300 raeburn 1475: &Apache::loncommon::start_data_table());
1.314 raeburn 1476: if ($env{'request.role.domain'} eq $ccdomain) {
1.300 raeburn 1477: $r->print(&build_tools_display($ccuname,$ccdomain,'requestcourses'));
1478: } else {
1479: $r->print(&coursereq_externaluser($ccuname,$ccdomain,
1480: $env{'request.role.domain'}));
1481: }
1482: $r->print(&Apache::loncommon::end_data_table());
1.275 raeburn 1483: }
1.199 raeburn 1484: $r->print('</div>');
1.427 raeburn 1485: my @order = ('auth','quota','tools','requestauthor');
1.362 raeburn 1486: my %user_text;
1487: my ($isadv,$isauthor) =
1.418 raeburn 1488: &Apache::lonnet::is_advanced_user($ccdomain,$ccuname);
1.362 raeburn 1489: if ((!$isauthor) &&
1.418 raeburn 1490: ((&Apache::lonnet::allowed('cau',$env{'request.role.domain'})) ||
1491: (&Apache::lonnet::allowed('udp',$env{'request.role.domain'}))) &&
1.430 raeburn 1492: ($env{'request.role.domain'} eq $ccdomain)) {
1.362 raeburn 1493: $user_text{'requestauthor'} = &domainrole_req($ccuname,$ccdomain);
1494: }
1495: $user_text{'auth'} = &user_authentication($ccuname,$ccdomain,$formname);
1.267 raeburn 1496: if ((&Apache::lonnet::allowed('mpq',$ccdomain)) ||
1.418 raeburn 1497: (&Apache::lonnet::allowed('mut',$ccdomain)) ||
1498: (&Apache::lonnet::allowed('udp',$ccdomain))) {
1.188 raeburn 1499: # Current user has quota modification privileges
1.378 raeburn 1500: $user_text{'quota'} = &user_quotas($ccuname,$ccdomain);
1.267 raeburn 1501: }
1502: if (!&Apache::lonnet::allowed('mpq',$ccdomain)) {
1503: if (&Apache::lonnet::allowed('mpq',$env{'request.role.domain'})) {
1504: my %lt=&Apache::lonlocal::texthash(
1.385 bisitz 1505: 'dska' => "Disk quotas for user's portfolio and Authoring Space",
1506: 'youd' => "You do not have privileges to modify the portfolio and/or Authoring Space quotas for this user.",
1.267 raeburn 1507: 'ichr' => "If a change is required, contact a domain coordinator for the domain",
1508: );
1.362 raeburn 1509: $user_text{'quota'} = <<ENDNOPORTPRIV;
1.188 raeburn 1510: <h3>$lt{'dska'}</h3>
1511: $lt{'youd'} $lt{'ichr'}: $ccdomain
1512: ENDNOPORTPRIV
1.267 raeburn 1513: }
1514: }
1515: if (!&Apache::lonnet::allowed('mut',$ccdomain)) {
1516: if (&Apache::lonnet::allowed('mut',$env{'request.role.domain'})) {
1517: my %lt=&Apache::lonlocal::texthash(
1518: 'utav' => "User Tools Availability",
1.361 raeburn 1519: 'yodo' => "You do not have privileges to modify Portfolio, Blog, WebDAV, or Personal Information Page settings for this user.",
1.267 raeburn 1520: 'ifch' => "If a change is required, contact a domain coordinator for the domain",
1521: );
1.362 raeburn 1522: $user_text{'tools'} = <<ENDNOTOOLSPRIV;
1.267 raeburn 1523: <h3>$lt{'utav'}</h3>
1524: $lt{'yodo'} $lt{'ifch'}: $ccdomain
1525: ENDNOTOOLSPRIV
1526: }
1.188 raeburn 1527: }
1.362 raeburn 1528: my $gotdiv = 0;
1529: foreach my $item (@order) {
1530: if ($user_text{$item} ne '') {
1531: unless ($gotdiv) {
1532: $r->print('<div class="LC_left_float">');
1533: $gotdiv = 1;
1534: }
1535: $r->print('<br />'.$user_text{$item});
1536: }
1537: }
1538: if ($env{'form.action'} eq 'singlestudent') {
1539: unless ($gotdiv) {
1540: $r->print('<div class="LC_left_float">');
1.213 raeburn 1541: }
1.375 raeburn 1542: my $credits;
1543: if ($showcredits) {
1544: $credits = &get_user_credits($ccuname,$ccdomain,$defaultcredits);
1545: if ($credits eq '') {
1546: $credits = $defaultcredits;
1547: }
1548: }
1.374 raeburn 1549: $r->print(&date_sections_select($context,$newuser,$formname,
1.375 raeburn 1550: $permission,$crstype,$ccuname,
1551: $ccdomain,$showcredits));
1.374 raeburn 1552: }
1.362 raeburn 1553: if ($gotdiv) {
1554: $r->print('</div><div class="LC_clear_float_footer"></div>');
1.188 raeburn 1555: }
1.418 raeburn 1556: my $statuses;
1557: if (($context eq 'domain') && (&Apache::lonnet::allowed('udp',$ccdomain)) &&
1558: (!&Apache::lonnet::allowed('mau',$ccdomain))) {
1559: $statuses = ['active'];
1560: } elsif (($context eq 'course') && ((&Apache::lonnet::allowed('vcl',$env{'request.course.id'})) ||
1561: ($env{'request.course.sec'} &&
1562: &Apache::lonnet::allowed('vcl',$env{'request.course.id'}.'/'.$env{'request.course.sec'})))) {
1.430 raeburn 1563: $statuses = ['active'];
1.418 raeburn 1564: }
1.217 raeburn 1565: if ($env{'form.action'} ne 'singlestudent') {
1.329 raeburn 1566: &display_existing_roles($r,$ccuname,$ccdomain,\%inccourses,$context,
1.418 raeburn 1567: $roledom,$crstype,$showcredits,$statuses);
1.217 raeburn 1568: }
1.25 matthew 1569: } ## End of new user/old user logic
1.218 raeburn 1570: if ($env{'form.action'} eq 'singlestudent') {
1.318 raeburn 1571: my $btntxt;
1572: if ($crstype eq 'Community') {
1573: $btntxt = &mt('Enroll Member');
1574: } else {
1575: $btntxt = &mt('Enroll Student');
1576: }
1577: $r->print('<br /><input type="button" value="'.$btntxt.'" onclick="setSections(this.form)" />'."\n");
1.418 raeburn 1578: } elsif ($permission->{'cusr'}) {
1.393 raeburn 1579: $r->print('<div class="LC_left_float">'.
1580: '<fieldset><legend>'.&mt('Add Roles').'</legend>');
1.218 raeburn 1581: my $addrolesdisplay = 0;
1582: if ($context eq 'domain' || $context eq 'author') {
1583: $addrolesdisplay = &new_coauthor_roles($r,$ccuname,$ccdomain);
1584: }
1585: if ($context eq 'domain') {
1.357 raeburn 1586: my $add_domainroles = &new_domain_roles($r,$ccdomain);
1.218 raeburn 1587: if (!$addrolesdisplay) {
1588: $addrolesdisplay = $add_domainroles;
1.2 www 1589: }
1.375 raeburn 1590: $r->print(&course_level_dc($env{'request.role.domain'},$showcredits));
1.393 raeburn 1591: $r->print('</fieldset></div><div class="LC_clear_float_footer"></div>'.
1592: '<br /><input type="button" value="'.&mt('Save').'" onclick="setCourse()" />'."\n");
1.218 raeburn 1593: } elsif ($context eq 'author') {
1594: if ($addrolesdisplay) {
1.393 raeburn 1595: $r->print('</fieldset></div><div class="LC_clear_float_footer"></div>'.
1596: '<br /><input type="button" value="'.&mt('Save').'"');
1.218 raeburn 1597: if ($newuser) {
1.301 bisitz 1598: $r->print(' onclick="auth_check()" \>'."\n");
1.218 raeburn 1599: } else {
1.301 bisitz 1600: $r->print('onclick="this.form.submit()" \>'."\n");
1.218 raeburn 1601: }
1.188 raeburn 1602: } else {
1.393 raeburn 1603: $r->print('</fieldset></div>'.
1604: '<div class="LC_clear_float_footer"></div>'.
1605: '<br /><a href="javascript:backPage(document.cu)">'.
1.218 raeburn 1606: &mt('Back to previous page').'</a>');
1.188 raeburn 1607: }
1608: } else {
1.375 raeburn 1609: $r->print(&course_level_table(\%inccourses,$showcredits,$defaultcredits));
1.393 raeburn 1610: $r->print('</fieldset></div><div class="LC_clear_float_footer"></div>'.
1611: '<br /><input type="button" value="'.&mt('Save').'" onclick="setSections(this.form)" />'."\n");
1.188 raeburn 1612: }
1.88 raeburn 1613: }
1.188 raeburn 1614: $r->print(&Apache::lonhtmlcommon::echo_form_input(['phase','userrole','ccdomain','prevphase','currstate','ccuname','ccdomain']));
1.179 raeburn 1615: $r->print('<input type="hidden" name="currstate" value="" />');
1.393 raeburn 1616: $r->print('<input type="hidden" name="prevphase" value="'.$env{'form.phase'}.'" /></form><br /><br />');
1.218 raeburn 1617: return;
1.2 www 1618: }
1.1 www 1619:
1.213 raeburn 1620: sub singleuser_breadcrumb {
1.422 raeburn 1621: my ($crstype,$context,$domain) = @_;
1.213 raeburn 1622: my %breadcrumb_text;
1623: if ($env{'form.action'} eq 'singlestudent') {
1.318 raeburn 1624: if ($crstype eq 'Community') {
1625: $breadcrumb_text{'search'} = 'Enroll a member';
1626: } else {
1627: $breadcrumb_text{'search'} = 'Enroll a student';
1628: }
1.422 raeburn 1629: $breadcrumb_text{'userpicked'} = 'Select a user';
1630: $breadcrumb_text{'modify'} = 'Set section/dates';
1.416 raeburn 1631: } elsif ($env{'form.action'} eq 'accesslogs') {
1632: $breadcrumb_text{'search'} = 'View access logs for a user';
1.422 raeburn 1633: $breadcrumb_text{'userpicked'} = 'Select a user';
1634: $breadcrumb_text{'activity'} = 'Activity';
1635: } elsif (($env{'form.action'} eq 'singleuser') && ($context eq 'domain') &&
1636: (!&Apache::lonnet::allowed('mau',$domain))) {
1637: $breadcrumb_text{'search'} = "View user's roles";
1638: $breadcrumb_text{'userpicked'} = 'Select a user';
1639: $breadcrumb_text{'modify'} = 'User roles';
1.213 raeburn 1640: } else {
1.229 raeburn 1641: $breadcrumb_text{'search'} = 'Create/modify a user';
1.422 raeburn 1642: $breadcrumb_text{'userpicked'} = 'Select a user';
1643: $breadcrumb_text{'modify'} = 'Set user role';
1.213 raeburn 1644: }
1645: return %breadcrumb_text;
1646: }
1647:
1648: sub date_sections_select {
1.375 raeburn 1649: my ($context,$newuser,$formname,$permission,$crstype,$ccuname,$ccdomain,
1650: $showcredits) = @_;
1651: my $credits;
1652: if ($showcredits) {
1653: my $defaultcredits = &Apache::lonuserutils::get_defaultcredits();
1654: $credits = &get_user_credits($ccuname,$ccdomain,$defaultcredits);
1655: if ($credits eq '') {
1656: $credits = $defaultcredits;
1657: }
1658: }
1.213 raeburn 1659: my $cid = $env{'request.course.id'};
1660: my ($cnum,$cdom) = &Apache::lonuserutils::get_course_identity($cid);
1661: my $date_table = '<h3>'.&mt('Starting and Ending Dates').'</h3>'."\n".
1662: &Apache::lonuserutils::date_setting_table(undef,undef,$context,
1663: undef,$formname,$permission);
1664: my $rowtitle = 'Section';
1.375 raeburn 1665: my $secbox = '<h3>'.&mt('Section and Credits').'</h3>'."\n".
1.213 raeburn 1666: &Apache::lonuserutils::section_picker($cdom,$cnum,'st',$rowtitle,
1.375 raeburn 1667: $permission,$context,'',$crstype,
1668: $showcredits,$credits);
1.213 raeburn 1669: my $output = $date_table.$secbox;
1670: return $output;
1671: }
1672:
1.216 raeburn 1673: sub validation_javascript {
1.375 raeburn 1674: my ($context,$ccdomain,$pjump_def,$crstype,$groupslist,$newuser,$formname,
1.216 raeburn 1675: $loaditem) = @_;
1676: my $dc_setcourse_code = '';
1677: my $nondc_setsection_code = '';
1678: if ($context eq 'domain') {
1679: my $dcdom = $env{'request.role.domain'};
1680: $loaditem->{'onload'} = "document.cu.coursedesc.value='';";
1.227 raeburn 1681: $dc_setcourse_code =
1682: &Apache::lonuserutils::dc_setcourse_js('cu','singleuser',$context);
1.216 raeburn 1683: } else {
1.227 raeburn 1684: my $checkauth;
1685: if (($newuser) || (&Apache::lonnet::allowed('mau',$ccdomain))) {
1686: $checkauth = 1;
1687: }
1688: if ($context eq 'course') {
1689: $nondc_setsection_code =
1690: &Apache::lonuserutils::setsections_javascript($formname,$groupslist,
1.375 raeburn 1691: undef,$checkauth,
1692: $crstype);
1.227 raeburn 1693: }
1694: if ($checkauth) {
1695: $nondc_setsection_code .=
1696: &Apache::lonuserutils::verify_authen($formname,$context);
1697: }
1.216 raeburn 1698: }
1699: my $js = &user_modification_js($pjump_def,$dc_setcourse_code,
1700: $nondc_setsection_code,$groupslist);
1701: my ($jsback,$elements) = &crumb_utilities();
1702: $js .= "\n".
1.301 bisitz 1703: '<script type="text/javascript">'."\n".
1704: '// <![CDATA['."\n".
1705: $jsback."\n".
1706: '// ]]>'."\n".
1707: '</script>'."\n";
1.216 raeburn 1708: return $js;
1709: }
1710:
1.217 raeburn 1711: sub display_existing_roles {
1.375 raeburn 1712: my ($r,$ccuname,$ccdomain,$inccourses,$context,$roledom,$crstype,
1.418 raeburn 1713: $showcredits,$statuses) = @_;
1.329 raeburn 1714: my $now=time;
1.418 raeburn 1715: my $showall = 1;
1716: my ($showexpired,$showactive);
1717: if ((ref($statuses) eq 'ARRAY') && (@{$statuses} > 0)) {
1718: $showall = 0;
1719: if (grep(/^expired$/,@{$statuses})) {
1720: $showexpired = 1;
1721: }
1722: if (grep(/^active$/,@{$statuses})) {
1723: $showactive = 1;
1724: }
1725: if ($showexpired && $showactive) {
1726: $showall = 1;
1727: }
1728: }
1.329 raeburn 1729: my %lt=&Apache::lonlocal::texthash(
1.217 raeburn 1730: 'rer' => "Existing Roles",
1731: 'rev' => "Revoke",
1732: 'del' => "Delete",
1733: 'ren' => "Re-Enable",
1734: 'rol' => "Role",
1735: 'ext' => "Extent",
1.375 raeburn 1736: 'crd' => "Credits",
1.217 raeburn 1737: 'sta' => "Start",
1738: 'end' => "End",
1739: );
1.329 raeburn 1740: my (%rolesdump,%roletext,%sortrole,%roleclass,%rolepriv);
1741: if ($context eq 'course' || $context eq 'author') {
1742: my @roles = &Apache::lonuserutils::roles_by_context($context,1,$crstype);
1743: my %roleshash =
1744: &Apache::lonnet::get_my_roles($ccuname,$ccdomain,'userroles',
1745: ['active','previous','future'],\@roles,$roledom,1);
1746: foreach my $key (keys(%roleshash)) {
1747: my ($start,$end) = split(':',$roleshash{$key});
1748: next if ($start eq '-1' || $end eq '-1');
1749: my ($rnum,$rdom,$role,$sec) = split(':',$key);
1750: if ($context eq 'course') {
1751: next unless (($rnum eq $env{'course.'.$env{'request.course.id'}.'.num'})
1752: && ($rdom eq $env{'course.'.$env{'request.course.id'}.'.domain'}));
1753: } elsif ($context eq 'author') {
1754: next unless (($rnum eq $env{'user.name'}) && ($rdom eq $env{'request.role.domain'}));
1755: }
1756: my ($newkey,$newvalue,$newrole);
1757: $newkey = '/'.$rdom.'/'.$rnum;
1758: if ($sec ne '') {
1759: $newkey .= '/'.$sec;
1760: }
1761: $newvalue = $role;
1762: if ($role =~ /^cr/) {
1763: $newrole = 'cr';
1764: } else {
1765: $newrole = $role;
1766: }
1767: $newkey .= '_'.$newrole;
1768: if ($start ne '' && $end ne '') {
1769: $newvalue .= '_'.$end.'_'.$start;
1.335 raeburn 1770: } elsif ($end ne '') {
1771: $newvalue .= '_'.$end;
1.329 raeburn 1772: }
1773: $rolesdump{$newkey} = $newvalue;
1774: }
1775: } else {
1.360 raeburn 1776: %rolesdump=&Apache::lonnet::dump('roles',$ccdomain,$ccuname);
1.329 raeburn 1777: }
1778: # Build up table of user roles to allow revocation and re-enabling of roles.
1779: my ($tmp) = keys(%rolesdump);
1780: return if ($tmp =~ /^(con_lost|error)/i);
1781: foreach my $area (sort { my $a1=join('_',(split('_',$a))[1,0]);
1782: my $b1=join('_',(split('_',$b))[1,0]);
1783: return $a1 cmp $b1;
1784: } keys(%rolesdump)) {
1785: next if ($area =~ /^rolesdef/);
1786: my $envkey=$area;
1787: my $role = $rolesdump{$area};
1788: my $thisrole=$area;
1789: $area =~ s/\_\w\w$//;
1790: my ($role_code,$role_end_time,$role_start_time) =
1791: split(/_/,$role);
1.418 raeburn 1792: my $active=1;
1793: $active=0 if (($role_end_time) && ($now>$role_end_time));
1794: if ($active) {
1795: next unless($showall || $showactive);
1796: } else {
1.430 raeburn 1797: next unless($showall || $showexpired);
1.418 raeburn 1798: }
1.217 raeburn 1799: # Is this a custom role? Get role owner and title.
1.329 raeburn 1800: my ($croleudom,$croleuname,$croletitle)=
1801: ($role_code=~m{^cr/($match_domain)/($match_username)/(\w+)$});
1802: my $allowed=0;
1803: my $delallowed=0;
1804: my $sortkey=$role_code;
1805: my $class='Unknown';
1.375 raeburn 1806: my $credits='';
1.418 raeburn 1807: my $csec;
1.421 raeburn 1808: if ($area =~ m{^/($match_domain)/($match_courseid)}) {
1.329 raeburn 1809: $class='Course';
1810: my ($coursedom,$coursedir) = ($1,$2);
1811: my $cid = $1.'_'.$2;
1812: # $1.'_'.$2 is the course id (eg. 103_12345abcef103l3).
1.421 raeburn 1813: next if ($envkey =~ m{^/$match_domain/$match_courseid/[A-Za-z0-9]+_gr$});
1.329 raeburn 1814: my %coursedata=
1815: &Apache::lonnet::coursedescription($cid);
1816: if ($coursedir =~ /^$match_community$/) {
1817: $class='Community';
1818: }
1819: $sortkey.="\0$coursedom";
1820: my $carea;
1821: if (defined($coursedata{'description'})) {
1822: $carea=$coursedata{'description'}.
1823: '<br />'.&mt('Domain').': '.$coursedom.(' 'x8).
1824: &Apache::loncommon::syllabuswrapper(&mt('Syllabus'),$coursedir,$coursedom);
1825: $sortkey.="\0".$coursedata{'description'};
1826: } else {
1827: if ($class eq 'Community') {
1828: $carea=&mt('Unavailable community').': '.$area;
1829: $sortkey.="\0".&mt('Unavailable community').': '.$area;
1.217 raeburn 1830: } else {
1831: $carea=&mt('Unavailable course').': '.$area;
1832: $sortkey.="\0".&mt('Unavailable course').': '.$area;
1833: }
1.329 raeburn 1834: }
1835: $sortkey.="\0$coursedir";
1836: $inccourses->{$cid}=1;
1.375 raeburn 1837: if (($showcredits) && ($class eq 'Course') && ($role_code eq 'st')) {
1838: my $defaultcredits = $coursedata{'internal.defaultcredits'};
1839: $credits =
1840: &get_user_credits($ccuname,$ccdomain,$defaultcredits,
1841: $coursedom,$coursedir);
1842: if ($credits eq '') {
1843: $credits = $defaultcredits;
1844: }
1845: }
1.329 raeburn 1846: if ((&Apache::lonnet::allowed('c'.$role_code,$coursedom.'/'.$coursedir)) ||
1847: (&Apache::lonnet::allowed('c'.$role_code,$ccdomain))) {
1848: $allowed=1;
1849: }
1850: unless ($allowed) {
1.365 raeburn 1851: my $isowner = &Apache::lonuserutils::is_courseowner($cid,$coursedata{'internal.courseowner'});
1.329 raeburn 1852: if ($isowner) {
1853: if (($role_code eq 'co') && ($class eq 'Community')) {
1854: $allowed = 1;
1855: } elsif (($role_code eq 'cc') && ($class eq 'Course')) {
1856: $allowed = 1;
1857: }
1.217 raeburn 1858: }
1.329 raeburn 1859: }
1860: if ((&Apache::lonnet::allowed('dro',$coursedom)) ||
1861: (&Apache::lonnet::allowed('dro',$ccdomain))) {
1862: $delallowed=1;
1863: }
1.217 raeburn 1864: # - custom role. Needs more info, too
1.329 raeburn 1865: if ($croletitle) {
1866: if (&Apache::lonnet::allowed('ccr',$coursedom.'/'.$coursedir)) {
1867: $allowed=1;
1868: $thisrole.='.'.$role_code;
1.217 raeburn 1869: }
1.329 raeburn 1870: }
1.418 raeburn 1871: if ($area=~m{^/($match_domain/$match_courseid/(\w+))}) {
1872: $csec = $2;
1873: $carea.='<br />'.&mt('Section: [_1]',$csec);
1874: $sortkey.="\0$csec";
1.329 raeburn 1875: if (!$allowed) {
1.418 raeburn 1876: if ($env{'request.course.sec'} eq $csec) {
1877: if (&Apache::lonnet::allowed('c'.$role_code,$1)) {
1.329 raeburn 1878: $allowed = 1;
1.217 raeburn 1879: }
1880: }
1881: }
1.329 raeburn 1882: }
1883: $area=$carea;
1884: } else {
1885: $sortkey.="\0".$area;
1886: # Determine if current user is able to revoke privileges
1887: if ($area=~m{^/($match_domain)/}) {
1888: if ((&Apache::lonnet::allowed('c'.$role_code,$1)) ||
1889: (&Apache::lonnet::allowed('c'.$role_code,$ccdomain))) {
1890: $allowed=1;
1.217 raeburn 1891: }
1.329 raeburn 1892: if (((&Apache::lonnet::allowed('dro',$1)) ||
1893: (&Apache::lonnet::allowed('dro',$ccdomain))) &&
1894: ($role_code ne 'dc')) {
1895: $delallowed=1;
1.217 raeburn 1896: }
1.329 raeburn 1897: } else {
1898: if (&Apache::lonnet::allowed('c'.$role_code,'/')) {
1.217 raeburn 1899: $allowed=1;
1900: }
1901: }
1.363 raeburn 1902: if ($role_code eq 'ca' || $role_code eq 'au' || $role_code eq 'aa') {
1.377 raeburn 1903: $class='Authoring Space';
1.329 raeburn 1904: } elsif ($role_code eq 'su') {
1905: $class='System';
1.217 raeburn 1906: } else {
1.329 raeburn 1907: $class='Domain';
1.217 raeburn 1908: }
1.329 raeburn 1909: }
1910: if (($role_code eq 'ca') || ($role_code eq 'aa')) {
1911: $area=~m{/($match_domain)/($match_username)};
1912: if (&Apache::lonuserutils::authorpriv($2,$1)) {
1913: $allowed=1;
1.217 raeburn 1914: } else {
1.329 raeburn 1915: $allowed=0;
1.217 raeburn 1916: }
1.329 raeburn 1917: }
1918: my $row = '';
1.418 raeburn 1919: if ($showall) {
1920: $row.= '<td>';
1921: if (($active) && ($allowed)) {
1922: $row.= '<input type="checkbox" name="rev:'.$thisrole.'" />';
1923: } else {
1924: if ($active) {
1925: $row.=' ';
1926: } else {
1927: $row.=&mt('expired or revoked');
1928: }
1929: }
1930: $row.='</td><td>';
1931: if ($allowed && !$active) {
1932: $row.= '<input type="checkbox" name="ren:'.$thisrole.'" />';
1933: } else {
1934: $row.=' ';
1935: }
1936: $row.='</td><td>';
1937: if ($delallowed) {
1938: $row.= '<input type="checkbox" name="del:'.$thisrole.'" />';
1.217 raeburn 1939: } else {
1.418 raeburn 1940: $row.=' ';
1.217 raeburn 1941: }
1.430 raeburn 1942: $row.= '</td>';
1.329 raeburn 1943: }
1944: my $plaintext='';
1945: if (!$croletitle) {
1.375 raeburn 1946: $plaintext=&Apache::lonnet::plaintext($role_code,$class);
1947: if (($showcredits) && ($credits ne '')) {
1948: $plaintext .= '<br/ ><span class="LC_nobreak">'.
1949: '<span class="LC_fontsize_small">'.
1950: &mt('Credits: [_1]',$credits).
1951: '</span></span>';
1952: }
1.329 raeburn 1953: } else {
1954: $plaintext=
1.395 bisitz 1955: &mt('Custom role [_1][_2]defined by [_3]',
1.346 bisitz 1956: '"'.$croletitle.'"',
1957: '<br />',
1958: $croleuname.':'.$croleudom);
1.329 raeburn 1959: }
1.418 raeburn 1960: $row.= '<td>'.$plaintext.'</td>'.
1961: '<td>'.$area.'</td>'.
1962: '<td>'.($role_start_time?&Apache::lonlocal::locallocaltime($role_start_time)
1963: : ' ' ).'</td>'.
1964: '<td>'.($role_end_time ?&Apache::lonlocal::locallocaltime($role_end_time)
1965: : ' ' ).'</td>';
1.329 raeburn 1966: $sortrole{$sortkey}=$envkey;
1967: $roletext{$envkey}=$row;
1968: $roleclass{$envkey}=$class;
1.418 raeburn 1969: if ($allowed) {
1970: $rolepriv{$envkey}='edit';
1971: } else {
1972: if ($context eq 'domain') {
1.420 raeburn 1973: if ((&Apache::lonnet::allowed('vur',$ccdomain)) &&
1.421 raeburn 1974: ($envkey=~m{^/$ccdomain/})) {
1.418 raeburn 1975: $rolepriv{$envkey}='view';
1976: }
1977: } elsif ($context eq 'course') {
1978: if ((&Apache::lonnet::allowed('vcl',$env{'request.course.id'})) ||
1979: ($env{'request.course.sec'} && ($env{'request.course.sec'} eq $csec) &&
1980: &Apache::lonnet::allowed('vcl',$env{'request.course.id'}.'/'.$env{'request.course.sec'}))) {
1981: $rolepriv{$envkey}='view';
1982: }
1983: }
1984: }
1.329 raeburn 1985: } # end of foreach (table building loop)
1986:
1987: my $rolesdisplay = 0;
1988: my %output = ();
1.377 raeburn 1989: foreach my $type ('Authoring Space','Course','Community','Domain','System','Unknown') {
1.329 raeburn 1990: $output{$type} = '';
1991: foreach my $which (sort {uc($a) cmp uc($b)} (keys(%sortrole))) {
1992: if ( ($roleclass{$sortrole{$which}} =~ /^\Q$type\E/ ) && ($rolepriv{$sortrole{$which}}) ) {
1993: $output{$type}.=
1994: &Apache::loncommon::start_data_table_row().
1995: $roletext{$sortrole{$which}}.
1996: &Apache::loncommon::end_data_table_row();
1.217 raeburn 1997: }
1.329 raeburn 1998: }
1999: unless($output{$type} eq '') {
2000: $output{$type} = '<tr class="LC_info_row">'.
2001: "<td align='center' colspan='7'>".&mt($type)."</td></tr>".
2002: $output{$type};
2003: $rolesdisplay = 1;
2004: }
2005: }
2006: if ($rolesdisplay == 1) {
2007: my $contextrole='';
2008: if ($env{'request.course.id'}) {
2009: if (&Apache::loncommon::course_type() eq 'Community') {
2010: $contextrole = &mt('Existing Roles in this Community');
1.290 bisitz 2011: } else {
1.329 raeburn 2012: $contextrole = &mt('Existing Roles in this Course');
1.290 bisitz 2013: }
1.329 raeburn 2014: } elsif ($env{'request.role'} =~ /^au\./) {
1.377 raeburn 2015: $contextrole = &mt('Existing Co-Author Roles in your Authoring Space');
1.329 raeburn 2016: } else {
1.418 raeburn 2017: if ($showall) {
2018: $contextrole = &mt('Existing Roles in this Domain');
2019: } elsif ($showactive) {
2020: $contextrole = &mt('Unexpired Roles in this Domain');
2021: } elsif ($showexpired) {
2022: $contextrole = &mt('Expired or Revoked Roles in this Domain');
2023: }
1.329 raeburn 2024: }
1.393 raeburn 2025: $r->print('<div class="LC_left_float">'.
1.375 raeburn 2026: '<fieldset><legend>'.$contextrole.'</legend>'.
1.217 raeburn 2027: &Apache::loncommon::start_data_table("LC_createuser").
1.418 raeburn 2028: &Apache::loncommon::start_data_table_header_row());
2029: if ($showall) {
2030: $r->print(
1.419 raeburn 2031: '<th>'.$lt{'rev'}.'</th><th>'.$lt{'ren'}.'</th><th>'.$lt{'del'}.'</th>'
1.418 raeburn 2032: );
2033: } elsif ($showexpired) {
2034: $r->print('<th>'.$lt{'rev'}.'</th>');
2035: }
2036: $r->print(
1.419 raeburn 2037: '<th>'.$lt{'rol'}.'</th><th>'.$lt{'ext'}.'</th>'.
2038: '<th>'.$lt{'sta'}.'</th><th>'.$lt{'end'}.'</th>'.
1.217 raeburn 2039: &Apache::loncommon::end_data_table_header_row());
1.377 raeburn 2040: foreach my $type ('Authoring Space','Course','Community','Domain','System','Unknown') {
1.329 raeburn 2041: if ($output{$type}) {
2042: $r->print($output{$type}."\n");
1.217 raeburn 2043: }
2044: }
1.375 raeburn 2045: $r->print(&Apache::loncommon::end_data_table().
2046: '</fieldset></div>');
1.329 raeburn 2047: }
1.217 raeburn 2048: return;
2049: }
2050:
1.218 raeburn 2051: sub new_coauthor_roles {
2052: my ($r,$ccuname,$ccdomain) = @_;
2053: my $addrolesdisplay = 0;
2054: #
2055: # Co-Author
2056: #
2057: if (&Apache::lonuserutils::authorpriv($env{'user.name'},
2058: $env{'request.role.domain'}) &&
2059: ($env{'user.name'} ne $ccuname || $env{'user.domain'} ne $ccdomain)) {
2060: # No sense in assigning co-author role to yourself
2061: $addrolesdisplay = 1;
2062: my $cuname=$env{'user.name'};
2063: my $cudom=$env{'request.role.domain'};
2064: my %lt=&Apache::lonlocal::texthash(
1.377 raeburn 2065: 'cs' => "Authoring Space",
1.218 raeburn 2066: 'act' => "Activate",
2067: 'rol' => "Role",
2068: 'ext' => "Extent",
2069: 'sta' => "Start",
2070: 'end' => "End",
2071: 'cau' => "Co-Author",
2072: 'caa' => "Assistant Co-Author",
2073: 'ssd' => "Set Start Date",
2074: 'sed' => "Set End Date"
2075: );
2076: $r->print('<h4>'.$lt{'cs'}.'</h4>'."\n".
2077: &Apache::loncommon::start_data_table()."\n".
2078: &Apache::loncommon::start_data_table_header_row()."\n".
2079: '<th>'.$lt{'act'}.'</th><th>'.$lt{'rol'}.'</th>'.
2080: '<th>'.$lt{'ext'}.'</th><th>'.$lt{'sta'}.'</th>'.
2081: '<th>'.$lt{'end'}.'</th>'."\n".
2082: &Apache::loncommon::end_data_table_header_row()."\n".
2083: &Apache::loncommon::start_data_table_row().'
2084: <td>
1.291 bisitz 2085: <input type="checkbox" name="act_'.$cudom.'_'.$cuname.'_ca" />
1.218 raeburn 2086: </td>
2087: <td>'.$lt{'cau'}.'</td>
2088: <td>'.$cudom.'_'.$cuname.'</td>
2089: <td><input type="hidden" name="start_'.$cudom.'_'.$cuname.'_ca" value="" />
2090: <a href=
2091: "javascript:pjump('."'date_start','Start Date Co-Author',document.cu.start_$cudom\_$cuname\_ca.value,'start_$cudom\_$cuname\_ca','cu.pres','dateset'".')">'.$lt{'ssd'}.'</a></td>
2092: <td><input type="hidden" name="end_'.$cudom.'_'.$cuname.'_ca" value="" />
2093: <a href=
2094: "javascript:pjump('."'date_end','End Date Co-Author',document.cu.end_$cudom\_$cuname\_ca.value,'end_$cudom\_$cuname\_ca','cu.pres','dateset'".')">'.$lt{'sed'}.'</a></td>'."\n".
2095: &Apache::loncommon::end_data_table_row()."\n".
2096: &Apache::loncommon::start_data_table_row()."\n".
1.291 bisitz 2097: '<td><input type="checkbox" name="act_'.$cudom.'_'.$cuname.'_aa" /></td>
1.218 raeburn 2098: <td>'.$lt{'caa'}.'</td>
2099: <td>'.$cudom.'_'.$cuname.'</td>
2100: <td><input type="hidden" name="start_'.$cudom.'_'.$cuname.'_aa" value="" />
2101: <a href=
2102: "javascript:pjump('."'date_start','Start Date Assistant Co-Author',document.cu.start_$cudom\_$cuname\_aa.value,'start_$cudom\_$cuname\_aa','cu.pres','dateset'".')">'.$lt{'ssd'}.'</a></td>
2103: <td><input type="hidden" name="end_'.$cudom.'_'.$cuname.'_aa" value="" />
2104: <a href=
2105: "javascript:pjump('."'date_end','End Date Assistant Co-Author',document.cu.end_$cudom\_$cuname\_aa.value,'end_$cudom\_$cuname\_aa','cu.pres','dateset'".')">'.$lt{'sed'}.'</a></td>'."\n".
2106: &Apache::loncommon::end_data_table_row()."\n".
2107: &Apache::loncommon::end_data_table());
2108: } elsif ($env{'request.role'} =~ /^au\./) {
2109: if (!(&Apache::lonuserutils::authorpriv($env{'user.name'},
2110: $env{'request.role.domain'}))) {
2111: $r->print('<span class="LC_error">'.
2112: &mt('You do not have privileges to assign co-author roles.').
2113: '</span>');
2114: } elsif (($env{'user.name'} eq $ccuname) &&
2115: ($env{'user.domain'} eq $ccdomain)) {
1.377 raeburn 2116: $r->print(&mt('Assigning yourself a co-author or assistant co-author role in your own author area in Authoring Space is not permitted'));
1.218 raeburn 2117: }
2118: }
2119: return $addrolesdisplay;;
2120: }
2121:
2122: sub new_domain_roles {
1.357 raeburn 2123: my ($r,$ccdomain) = @_;
1.218 raeburn 2124: my $addrolesdisplay = 0;
2125: #
2126: # Domain level
2127: #
2128: my $num_domain_level = 0;
2129: my $domaintext =
2130: '<h4>'.&mt('Domain Level').'</h4>'.
2131: &Apache::loncommon::start_data_table().
2132: &Apache::loncommon::start_data_table_header_row().
2133: '<th>'.&mt('Activate').'</th><th>'.&mt('Role').'</th><th>'.
2134: &mt('Extent').'</th>'.
2135: '<th>'.&mt('Start').'</th><th>'.&mt('End').'</th>'.
2136: &Apache::loncommon::end_data_table_header_row();
1.312 raeburn 2137: my @allroles = &Apache::lonuserutils::roles_by_context('domain');
1.218 raeburn 2138: foreach my $thisdomain (sort(&Apache::lonnet::all_domains())) {
1.312 raeburn 2139: foreach my $role (@allroles) {
2140: next if ($role eq 'ad');
1.357 raeburn 2141: next if (($role eq 'au') && ($ccdomain ne $thisdomain));
1.218 raeburn 2142: if (&Apache::lonnet::allowed('c'.$role,$thisdomain)) {
2143: my $plrole=&Apache::lonnet::plaintext($role);
2144: my %lt=&Apache::lonlocal::texthash(
2145: 'ssd' => "Set Start Date",
2146: 'sed' => "Set End Date"
2147: );
2148: $num_domain_level ++;
2149: $domaintext .=
2150: &Apache::loncommon::start_data_table_row().
1.291 bisitz 2151: '<td><input type="checkbox" name="act_'.$thisdomain.'_'.$role.'" /></td>
1.218 raeburn 2152: <td>'.$plrole.'</td>
2153: <td>'.$thisdomain.'</td>
2154: <td><input type="hidden" name="start_'.$thisdomain.'_'.$role.'" value="" />
2155: <a href=
2156: "javascript:pjump('."'date_start','Start Date $plrole',document.cu.start_$thisdomain\_$role.value,'start_$thisdomain\_$role','cu.pres','dateset'".')">'.$lt{'ssd'}.'</a></td>
2157: <td><input type="hidden" name="end_'.$thisdomain.'_'.$role.'" value="" />
2158: <a href=
2159: "javascript:pjump('."'date_end','End Date $plrole',document.cu.end_$thisdomain\_$role.value,'end_$thisdomain\_$role','cu.pres','dateset'".')">'.$lt{'sed'}.'</a></td>'.
2160: &Apache::loncommon::end_data_table_row();
2161: }
2162: }
2163: }
2164: $domaintext.= &Apache::loncommon::end_data_table();
2165: if ($num_domain_level > 0) {
2166: $r->print($domaintext);
2167: $addrolesdisplay = 1;
2168: }
2169: return $addrolesdisplay;
2170: }
2171:
1.188 raeburn 2172: sub user_authentication {
1.227 raeburn 2173: my ($ccuname,$ccdomain,$formname) = @_;
1.188 raeburn 2174: my $currentauth=&Apache::lonnet::queryauthenticate($ccuname,$ccdomain);
1.227 raeburn 2175: my $outcome;
1.418 raeburn 2176: my %lt=&Apache::lonlocal::texthash(
2177: 'err' => "ERROR",
2178: 'uuas' => "This user has an unrecognized authentication scheme",
2179: 'adcs' => "Please alert a domain coordinator of this situation",
2180: 'sldb' => "Please specify login data below",
2181: 'ld' => "Login Data"
2182: );
1.188 raeburn 2183: # Check for a bad authentication type
2184: if ($currentauth !~ /^(krb4|krb5|unix|internal|localauth):/) {
2185: # bad authentication scheme
2186: if (&Apache::lonnet::allowed('mau',$ccdomain)) {
1.227 raeburn 2187: &initialize_authen_forms($ccdomain,$formname);
2188:
1.190 raeburn 2189: my $choices = &Apache::lonuserutils::set_login($ccdomain,$authformkrb,$authformint,$authformloc);
1.188 raeburn 2190: $outcome = <<ENDBADAUTH;
2191: <script type="text/javascript" language="Javascript">
1.301 bisitz 2192: // <![CDATA[
1.188 raeburn 2193: $loginscript
1.301 bisitz 2194: // ]]>
1.188 raeburn 2195: </script>
2196: <span class="LC_error">$lt{'err'}:
2197: $lt{'uuas'} ($currentauth). $lt{'sldb'}.</span>
2198: <h3>$lt{'ld'}</h3>
2199: $choices
2200: ENDBADAUTH
2201: } else {
2202: # This user is not allowed to modify the user's
2203: # authentication scheme, so just notify them of the problem
2204: $outcome = <<ENDBADAUTH;
2205: <span class="LC_error"> $lt{'err'}:
2206: $lt{'uuas'} ($currentauth). $lt{'adcs'}.
2207: </span>
2208: ENDBADAUTH
2209: }
2210: } else { # Authentication type is valid
1.418 raeburn 2211:
1.227 raeburn 2212: &initialize_authen_forms($ccdomain,$formname,$currentauth,'modifyuser');
1.205 raeburn 2213: my ($authformcurrent,$can_modify,@authform_others) =
1.188 raeburn 2214: &modify_login_block($ccdomain,$currentauth);
2215: if (&Apache::lonnet::allowed('mau',$ccdomain)) {
2216: # Current user has login modification privileges
2217: $outcome =
2218: '<script type="text/javascript" language="Javascript">'."\n".
1.301 bisitz 2219: '// <![CDATA['."\n".
1.188 raeburn 2220: $loginscript."\n".
1.301 bisitz 2221: '// ]]>'."\n".
1.188 raeburn 2222: '</script>'."\n".
2223: '<h3>'.$lt{'ld'}.'</h3>'.
2224: &Apache::loncommon::start_data_table().
1.205 raeburn 2225: &Apache::loncommon::start_data_table_row().
1.188 raeburn 2226: '<td>'.$authformnop;
1.418 raeburn 2227: if (($can_modify) && (&Apache::lonnet::allowed('mau',$ccdomain))) {
1.188 raeburn 2228: $outcome .= '</td>'."\n".
2229: &Apache::loncommon::end_data_table_row().
2230: &Apache::loncommon::start_data_table_row().
2231: '<td>'.$authformcurrent.'</td>'.
2232: &Apache::loncommon::end_data_table_row()."\n";
2233: } else {
1.200 raeburn 2234: $outcome .= ' ('.$authformcurrent.')</td>'.
2235: &Apache::loncommon::end_data_table_row()."\n";
1.188 raeburn 2236: }
1.418 raeburn 2237: if (&Apache::lonnet::allowed('mau',$ccdomain)) {
2238: foreach my $item (@authform_others) {
2239: $outcome .= &Apache::loncommon::start_data_table_row().
2240: '<td>'.$item.'</td>'.
2241: &Apache::loncommon::end_data_table_row()."\n";
2242: }
1.188 raeburn 2243: }
1.205 raeburn 2244: $outcome .= &Apache::loncommon::end_data_table();
1.188 raeburn 2245: } else {
1.418 raeburn 2246: if (&Apache::lonnet::allowed('udp',$ccdomain)) {
2247: # Current user has rights to view domain preferences for user's domain
2248: my $result;
2249: if ($currentauth =~ /^krb(4|5):([^:]*)$/) {
2250: my ($krbver,$krbrealm) = ($1,$2);
2251: if ($krbrealm eq '') {
2252: $result = &mt('Currently Kerberos authenticated, Version [_1].',$krbver);
2253: } else {
2254: $result = &mt('Currently Kerberos authenticated with domain [_1] Version [_2].',
1.426 raeburn 2255: $krbrealm,$krbver);
1.418 raeburn 2256: }
2257: } elsif ($currentauth =~ /^internal:/) {
2258: $result = &mt('Currently internally authenticated.');
2259: } elsif ($currentauth =~ /^localauth:/) {
2260: $result = &mt('Currently using local (institutional) authentication.');
2261: } elsif ($currentauth =~ /^unix:/) {
2262: $result = &mt('Currently Filesystem Authenticated.');
2263: }
2264: $outcome = '<h3>'.$lt{'ld'}.'</h3>'.
2265: &Apache::loncommon::start_data_table().
2266: &Apache::loncommon::start_data_table_row().
2267: '<td>'.$result.'</td>'.
2268: &Apache::loncommon::end_data_table_row()."\n".
2269: &Apache::loncommon::end_data_table();
2270: } elsif (&Apache::lonnet::allowed('mau',$env{'request.role.domain'})) {
1.188 raeburn 2271: my %lt=&Apache::lonlocal::texthash(
2272: 'ccld' => "Change Current Login Data",
2273: 'yodo' => "You do not have privileges to modify the authentication configuration for this user.",
2274: 'ifch' => "If a change is required, contact a domain coordinator for the domain",
2275: );
2276: $outcome .= <<ENDNOPRIV;
2277: <h3>$lt{'ccld'}</h3>
2278: $lt{'yodo'} $lt{'ifch'}: $ccdomain
1.235 raeburn 2279: <input type="hidden" name="login" value="nochange" />
1.188 raeburn 2280: ENDNOPRIV
2281: }
2282: }
2283: } ## End of "check for bad authentication type" logic
2284: return $outcome;
2285: }
2286:
1.187 raeburn 2287: sub modify_login_block {
2288: my ($dom,$currentauth) = @_;
2289: my %domconfig = &Apache::lonnet::get_dom('configuration',['usercreation'],$dom);
2290: my ($authnum,%can_assign) =
2291: &Apache::loncommon::get_assignable_auth($dom);
1.205 raeburn 2292: my ($authformcurrent,@authform_others,$show_override_msg);
1.187 raeburn 2293: if ($currentauth=~/^krb(4|5):/) {
2294: $authformcurrent=$authformkrb;
2295: if ($can_assign{'int'}) {
1.205 raeburn 2296: push(@authform_others,$authformint);
1.187 raeburn 2297: }
2298: if ($can_assign{'loc'}) {
1.205 raeburn 2299: push(@authform_others,$authformloc);
1.187 raeburn 2300: }
2301: if (($can_assign{'krb4'}) || ($can_assign{'krb5'})) {
2302: $show_override_msg = 1;
2303: }
2304: } elsif ($currentauth=~/^internal:/) {
2305: $authformcurrent=$authformint;
2306: if (($can_assign{'krb4'}) || ($can_assign{'krb5'})) {
1.205 raeburn 2307: push(@authform_others,$authformkrb);
1.187 raeburn 2308: }
2309: if ($can_assign{'loc'}) {
1.205 raeburn 2310: push(@authform_others,$authformloc);
1.187 raeburn 2311: }
2312: if ($can_assign{'int'}) {
2313: $show_override_msg = 1;
2314: }
2315: } elsif ($currentauth=~/^unix:/) {
2316: $authformcurrent=$authformfsys;
2317: if (($can_assign{'krb4'}) || ($can_assign{'krb5'})) {
1.205 raeburn 2318: push(@authform_others,$authformkrb);
1.187 raeburn 2319: }
2320: if ($can_assign{'int'}) {
1.205 raeburn 2321: push(@authform_others,$authformint);
1.187 raeburn 2322: }
2323: if ($can_assign{'loc'}) {
1.205 raeburn 2324: push(@authform_others,$authformloc);
1.187 raeburn 2325: }
2326: if ($can_assign{'fsys'}) {
2327: $show_override_msg = 1;
2328: }
2329: } elsif ($currentauth=~/^localauth:/) {
2330: $authformcurrent=$authformloc;
2331: if (($can_assign{'krb4'}) || ($can_assign{'krb5'})) {
1.205 raeburn 2332: push(@authform_others,$authformkrb);
1.187 raeburn 2333: }
2334: if ($can_assign{'int'}) {
1.205 raeburn 2335: push(@authform_others,$authformint);
1.187 raeburn 2336: }
2337: if ($can_assign{'loc'}) {
2338: $show_override_msg = 1;
2339: }
2340: }
2341: if ($show_override_msg) {
1.205 raeburn 2342: $authformcurrent = '<table><tr><td colspan="3">'.$authformcurrent.
2343: '</td></tr>'."\n".
2344: '<tr><td> </td>'.
2345: '<td><b>'.&mt('Currently in use').'</b></td>'.
2346: '<td align="right"><span class="LC_cusr_emph">'.
1.187 raeburn 2347: &mt('will override current values').
1.205 raeburn 2348: '</span></td></tr></table>';
1.187 raeburn 2349: }
1.205 raeburn 2350: return ($authformcurrent,$show_override_msg,@authform_others);
1.187 raeburn 2351: }
2352:
1.188 raeburn 2353: sub personal_data_display {
1.391 raeburn 2354: my ($ccuname,$ccdomain,$newuser,$context,$inst_results,$rolesarray,
1.442 ! raeburn 2355: $now,$captchaform,$emailusername,$usertype,$usernameset,$condition) = @_;
1.388 bisitz 2356: my ($output,%userenv,%canmodify,%canmodify_status);
1.219 raeburn 2357: my @userinfo = ('firstname','middlename','lastname','generation',
2358: 'permanentemail','id');
1.252 raeburn 2359: my $rowcount = 0;
2360: my $editable = 0;
1.391 raeburn 2361: my %textboxsize = (
2362: firstname => '15',
2363: middlename => '15',
2364: lastname => '15',
2365: generation => '5',
2366: permanentemail => '25',
2367: id => '15',
2368: );
2369:
2370: my %lt=&Apache::lonlocal::texthash(
2371: 'pd' => "Personal Data",
2372: 'firstname' => "First Name",
2373: 'middlename' => "Middle Name",
2374: 'lastname' => "Last Name",
2375: 'generation' => "Generation",
2376: 'permanentemail' => "Permanent e-mail address",
2377: 'id' => "Student/Employee ID",
2378: 'lg' => "Login Data",
2379: 'inststatus' => "Affiliation",
2380: 'email' => 'E-mail address',
2381: 'valid' => 'Validation',
1.442 ! raeburn 2382: 'username' => 'Username',
1.391 raeburn 2383: );
2384:
2385: %canmodify_status =
1.286 raeburn 2386: &Apache::lonuserutils::can_modify_userinfo($context,$ccdomain,
2387: ['inststatus'],$rolesarray);
1.253 raeburn 2388: if (!$newuser) {
1.188 raeburn 2389: # Get the users information
2390: %userenv = &Apache::lonnet::get('environment',
2391: ['firstname','middlename','lastname','generation',
1.286 raeburn 2392: 'permanentemail','id','inststatus'],$ccdomain,$ccuname);
1.219 raeburn 2393: %canmodify =
2394: &Apache::lonuserutils::can_modify_userinfo($context,$ccdomain,
1.252 raeburn 2395: \@userinfo,$rolesarray);
1.257 raeburn 2396: } elsif ($context eq 'selfcreate') {
1.391 raeburn 2397: if ($newuser eq 'email') {
1.396 raeburn 2398: if (ref($emailusername) eq 'HASH') {
2399: if (ref($emailusername->{$usertype}) eq 'HASH') {
2400: my ($infofields,$infotitles) = &Apache::loncommon::emailusername_info();
1.442 ! raeburn 2401: @userinfo = ();
1.396 raeburn 2402: if ((ref($infofields) eq 'ARRAY') && (ref($infotitles) eq 'HASH')) {
2403: foreach my $field (@{$infofields}) {
2404: if ($emailusername->{$usertype}->{$field}) {
2405: push(@userinfo,$field);
2406: $canmodify{$field} = 1;
2407: unless ($textboxsize{$field}) {
2408: $textboxsize{$field} = 25;
2409: }
2410: unless ($lt{$field}) {
2411: $lt{$field} = $infotitles->{$field};
2412: }
2413: if ($emailusername->{$usertype}->{$field} eq 'required') {
2414: $lt{$field} .= '<b>*</b>';
2415: }
1.391 raeburn 2416: }
2417: }
2418: }
2419: }
2420: }
2421: } else {
2422: %canmodify = &selfcreate_canmodify($context,$ccdomain,\@userinfo,
2423: $inst_results,$rolesarray);
2424: }
1.188 raeburn 2425: }
1.391 raeburn 2426:
1.188 raeburn 2427: my $genhelp=&Apache::loncommon::help_open_topic('Generation');
2428: $output = '<h3>'.$lt{'pd'}.'</h3>'.
2429: &Apache::lonhtmlcommon::start_pick_box();
1.391 raeburn 2430: if (($context eq 'selfcreate') && ($newuser eq 'email')) {
1.442 ! raeburn 2431: if ($condition) {
! 2432: if ($condition =~ /[-\w]+\.[-\w]+$/) {
! 2433: $condition = '@'.$condition;
! 2434: } else {
! 2435: undef($condition);
! 2436: }
! 2437: }
1.396 raeburn 2438: $output .= &Apache::lonhtmlcommon::row_title($lt{'email'}.'<b>*</b>',undef,
1.391 raeburn 2439: 'LC_oddrow_value')."\n".
1.442 ! raeburn 2440: '<input type="text" name="uname" size="25" value="'.$condition.'" autocomplete="off" />';
1.391 raeburn 2441: $rowcount ++;
2442: $output .= &Apache::lonhtmlcommon::row_closure(1);
1.408 raeburn 2443: my $upassone = '<input type="password" name="upass'.$now.'" size="20" autocomplete="off" />';
2444: my $upasstwo = '<input type="password" name="upasscheck'.$now.'" size="20" autocomplete="off" />';
1.396 raeburn 2445: $output .= &Apache::lonhtmlcommon::row_title(&mt('Password').'<b>*</b>',
1.391 raeburn 2446: 'LC_pick_box_title',
2447: 'LC_oddrow_value')."\n".
2448: $upassone."\n".
2449: &Apache::lonhtmlcommon::row_closure(1)."\n".
1.396 raeburn 2450: &Apache::lonhtmlcommon::row_title(&mt('Confirm password').'<b>*</b>',
1.391 raeburn 2451: 'LC_pick_box_title',
2452: 'LC_oddrow_value')."\n".
2453: $upasstwo.
2454: &Apache::lonhtmlcommon::row_closure()."\n";
1.442 ! raeburn 2455: if ($usernameset) {
! 2456: my $onclick = "toggleDisplay(this,'selfcreateusername');";
! 2457: $output .= &Apache::lonhtmlcommon::row_title($lt{'username'},undef,'LC_oddrow_value')."\n".
! 2458: &mt('Use e-mail address: ').
! 2459: '<label><input type="radio" name="emailused" value="1" checked="checked" onclick="'.$onclick.'" />'.&mt('Yes').'</label>'."\n".
! 2460: (' 'x2).
! 2461: '<label><input type="radio" name="emailused" value="0" onclick="'.$onclick.'" />'.&mt('No').'</label>'."\n".
! 2462: '<div id="selfcreateusername" style="display: none; font-size: smaller">'.
! 2463: '<br /><span class="LC_nobreak">'.&mt('Preferred username').
! 2464: ' <input type="text" name="username" value="" size="20" autocomplete="off"/>'.
! 2465: '</span></div>'."\n".&Apache::lonhtmlcommon::row_closure(1);
! 2466: $rowcount ++;
! 2467: }
1.391 raeburn 2468: }
1.188 raeburn 2469: foreach my $item (@userinfo) {
2470: my $rowtitle = $lt{$item};
1.252 raeburn 2471: my $hiderow = 0;
1.188 raeburn 2472: if ($item eq 'generation') {
2473: $rowtitle = $genhelp.$rowtitle;
2474: }
1.252 raeburn 2475: my $row = &Apache::lonhtmlcommon::row_title($rowtitle,undef,'LC_oddrow_value')."\n";
1.188 raeburn 2476: if ($newuser) {
1.210 raeburn 2477: if (ref($inst_results) eq 'HASH') {
2478: if ($inst_results->{$item} ne '') {
1.252 raeburn 2479: $row .= '<input type="hidden" name="c'.$item.'" value="'.$inst_results->{$item}.'" />'.$inst_results->{$item};
1.210 raeburn 2480: } else {
1.252 raeburn 2481: if ($context eq 'selfcreate') {
1.391 raeburn 2482: if ($canmodify{$item}) {
1.394 raeburn 2483: $row .= '<input type="text" name="c'.$item.'" size="'.$textboxsize{$item}.'" value="" autocomplete="off" />';
1.252 raeburn 2484: $editable ++;
2485: } else {
2486: $hiderow = 1;
2487: }
1.253 raeburn 2488: } else {
2489: $row .= '<input type="text" name="c'.$item.'" size="'.$textboxsize{$item}.'" value="" />';
1.252 raeburn 2490: }
1.210 raeburn 2491: }
1.188 raeburn 2492: } else {
1.252 raeburn 2493: if ($context eq 'selfcreate') {
1.401 raeburn 2494: if ($canmodify{$item}) {
2495: if ($newuser eq 'email') {
2496: $row .= '<input type="text" name="'.$item.'" size="'.$textboxsize{$item}.'" value="" autocomplete="off" />';
1.287 raeburn 2497: } else {
1.401 raeburn 2498: $row .= '<input type="text" name="c'.$item.'" size="'.$textboxsize{$item}.'" value="" autocomplete="off" />';
1.287 raeburn 2499: }
1.401 raeburn 2500: $editable ++;
2501: } else {
2502: $hiderow = 1;
1.252 raeburn 2503: }
1.253 raeburn 2504: } else {
2505: $row .= '<input type="text" name="c'.$item.'" size="'.$textboxsize{$item}.'" value="" />';
1.252 raeburn 2506: }
1.188 raeburn 2507: }
2508: } else {
1.219 raeburn 2509: if ($canmodify{$item}) {
1.252 raeburn 2510: $row .= '<input type="text" name="c'.$item.'" size="'.$textboxsize{$item}.'" value="'.$userenv{$item}.'" />';
1.393 raeburn 2511: if (($item eq 'id') && (!$newuser)) {
2512: $row .= '<br />'.&Apache::lonuserutils::forceid_change($context);
2513: }
1.188 raeburn 2514: } else {
1.252 raeburn 2515: $row .= $userenv{$item};
1.188 raeburn 2516: }
2517: }
1.252 raeburn 2518: $row .= &Apache::lonhtmlcommon::row_closure(1);
2519: if (!$hiderow) {
2520: $output .= $row;
2521: $rowcount ++;
2522: }
1.188 raeburn 2523: }
1.286 raeburn 2524: if (($canmodify_status{'inststatus'}) || ($context ne 'selfcreate')) {
2525: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($ccdomain);
2526: if (ref($types) eq 'ARRAY') {
2527: if (@{$types} > 0) {
2528: my ($hiderow,$shown);
2529: if ($canmodify_status{'inststatus'}) {
2530: $shown = &pick_inst_statuses($userenv{'inststatus'},$usertypes,$types);
2531: } else {
2532: if ($userenv{'inststatus'} eq '') {
2533: $hiderow = 1;
1.334 raeburn 2534: } else {
2535: my @showitems;
2536: foreach my $item ( map { &unescape($_); } split(':',$userenv{'inststatus'})) {
2537: if (exists($usertypes->{$item})) {
2538: push(@showitems,$usertypes->{$item});
2539: } else {
2540: push(@showitems,$item);
2541: }
2542: }
2543: if (@showitems) {
2544: $shown = join(', ',@showitems);
2545: } else {
2546: $hiderow = 1;
2547: }
1.286 raeburn 2548: }
2549: }
2550: if (!$hiderow) {
1.389 bisitz 2551: my $row = &Apache::lonhtmlcommon::row_title(&mt('Affiliations'),undef,'LC_oddrow_value')."\n".
1.286 raeburn 2552: $shown.&Apache::lonhtmlcommon::row_closure(1);
2553: if ($context eq 'selfcreate') {
2554: $rowcount ++;
2555: }
2556: $output .= $row;
2557: }
2558: }
2559: }
2560: }
1.391 raeburn 2561: if (($context eq 'selfcreate') && ($newuser eq 'email')) {
2562: if ($captchaform) {
1.410 raeburn 2563: $output .= &Apache::lonhtmlcommon::row_title($lt{'valid'}.'*',
2564: 'LC_pick_box_title')."\n".
2565: $captchaform."\n".'<br /><br />'.
1.391 raeburn 2566: &Apache::lonhtmlcommon::row_closure(1);
2567: $rowcount ++;
2568: }
2569: my $submit_text = &mt('Create account');
2570: $output .= &Apache::lonhtmlcommon::row_title()."\n".
2571: '<br /><input type="submit" name="createaccount" value="'.
2572: $submit_text.'" />'.
1.396 raeburn 2573: '<input type="hidden" name="type" value="'.$usertype.'" />'.
1.391 raeburn 2574: &Apache::lonhtmlcommon::row_closure(1);
2575: }
1.188 raeburn 2576: $output .= &Apache::lonhtmlcommon::end_pick_box();
1.206 raeburn 2577: if (wantarray) {
1.252 raeburn 2578: if ($context eq 'selfcreate') {
2579: return($output,$rowcount,$editable);
2580: } else {
1.388 bisitz 2581: return $output;
1.252 raeburn 2582: }
1.206 raeburn 2583: } else {
2584: return $output;
2585: }
1.188 raeburn 2586: }
2587:
1.286 raeburn 2588: sub pick_inst_statuses {
2589: my ($curr,$usertypes,$types) = @_;
2590: my ($output,$rem,@currtypes);
2591: if ($curr ne '') {
2592: @currtypes = map { &unescape($_); } split(/:/,$curr);
2593: }
2594: my $numinrow = 2;
2595: if (ref($types) eq 'ARRAY') {
2596: $output = '<table>';
2597: my $lastcolspan;
2598: for (my $i=0; $i<@{$types}; $i++) {
2599: if (defined($usertypes->{$types->[$i]})) {
2600: my $rem = $i%($numinrow);
2601: if ($rem == 0) {
2602: if ($i<@{$types}-1) {
2603: if ($i > 0) {
2604: $output .= '</tr>';
2605: }
2606: $output .= '<tr>';
2607: }
2608: } elsif ($i==@{$types}-1) {
2609: my $colsleft = $numinrow - $rem;
2610: if ($colsleft > 1) {
2611: $lastcolspan = ' colspan="'.$colsleft.'"';
2612: }
2613: }
2614: my $check = ' ';
2615: if (grep(/^\Q$types->[$i]\E$/,@currtypes)) {
2616: $check = ' checked="checked" ';
2617: }
2618: $output .= '<td class="LC_left_item"'.$lastcolspan.'>'.
2619: '<span class="LC_nobreak"><label>'.
2620: '<input type="checkbox" name="inststatus" '.
2621: 'value="'.$types->[$i].'"'.$check.'/>'.
2622: $usertypes->{$types->[$i]}.'</label></span></td>';
2623: }
2624: }
2625: $output .= '</tr></table>';
2626: }
2627: return $output;
2628: }
2629:
1.257 raeburn 2630: sub selfcreate_canmodify {
2631: my ($context,$dom,$userinfo,$inst_results,$rolesarray) = @_;
2632: if (ref($inst_results) eq 'HASH') {
2633: my @inststatuses = &get_inststatuses($inst_results);
2634: if (@inststatuses == 0) {
2635: @inststatuses = ('default');
2636: }
2637: $rolesarray = \@inststatuses;
2638: }
2639: my %canmodify =
2640: &Apache::lonuserutils::can_modify_userinfo($context,$dom,$userinfo,
2641: $rolesarray);
2642: return %canmodify;
2643: }
2644:
1.252 raeburn 2645: sub get_inststatuses {
2646: my ($insthashref) = @_;
2647: my @inststatuses = ();
2648: if (ref($insthashref) eq 'HASH') {
2649: if (ref($insthashref->{'inststatus'}) eq 'ARRAY') {
2650: @inststatuses = @{$insthashref->{'inststatus'}};
2651: }
2652: }
2653: return @inststatuses;
2654: }
2655:
1.4 www 2656: # ================================================================= Phase Three
1.42 matthew 2657: sub update_user_data {
1.375 raeburn 2658: my ($r,$context,$crstype,$brcrum,$showcredits) = @_;
1.101 albertel 2659: my $uhome=&Apache::lonnet::homeserver($env{'form.ccuname'},
2660: $env{'form.ccdomain'});
1.27 matthew 2661: # Error messages
1.188 raeburn 2662: my $error = '<span class="LC_error">'.&mt('Error').': ';
1.193 raeburn 2663: my $end = '</span><br /><br />';
2664: my $rtnlink = '<a href="javascript:backPage(document.userupdate,'.
1.188 raeburn 2665: "'$env{'form.prevphase'}','modify')".'" />'.
1.219 raeburn 2666: &mt('Return to previous page').'</a>'.
2667: &Apache::loncommon::end_page();
2668: my $now = time;
1.40 www 2669: my $title;
1.101 albertel 2670: if (exists($env{'form.makeuser'})) {
1.40 www 2671: $title='Set Privileges for New User';
2672: } else {
2673: $title='Modify User Privileges';
2674: }
1.213 raeburn 2675: my $newuser = 0;
1.160 raeburn 2676: my ($jsback,$elements) = &crumb_utilities();
2677: my $jscript = '<script type="text/javascript">'."\n".
1.301 bisitz 2678: '// <![CDATA['."\n".
2679: $jsback."\n".
2680: '// ]]>'."\n".
2681: '</script>'."\n";
1.422 raeburn 2682: my %breadcrumb_text = &singleuser_breadcrumb($crstype,$context,$env{'form.ccdomain'});
1.351 raeburn 2683: push (@{$brcrum},
2684: {href => "javascript:backPage(document.userupdate)",
2685: text => $breadcrumb_text{'search'},
2686: faq => 282,
2687: bug => 'Instructor Interface',}
2688: );
2689: if ($env{'form.prevphase'} eq 'userpicked') {
2690: push(@{$brcrum},
2691: {href => "javascript:backPage(document.userupdate,'get_user_info','select')",
2692: text => $breadcrumb_text{'userpicked'},
2693: faq => 282,
2694: bug => 'Instructor Interface',});
1.233 raeburn 2695: }
1.224 raeburn 2696: my $helpitem = 'Course_Change_Privileges';
2697: if ($env{'form.action'} eq 'singlestudent') {
2698: $helpitem = 'Course_Add_Student';
1.439 raeburn 2699: } elsif ($context eq 'author') {
2700: $helpitem = 'Author_Change_Privileges';
2701: } elsif ($context eq 'domain') {
2702: $helpitem = 'Domain_Change_Privileges';
1.224 raeburn 2703: }
1.351 raeburn 2704: push(@{$brcrum},
2705: {href => "javascript:backPage(document.userupdate,'$env{'form.prevphase'}','modify')",
2706: text => $breadcrumb_text{'modify'},
2707: faq => 282,
2708: bug => 'Instructor Interface',},
2709: {href => "/adm/createuser",
2710: text => "Result",
2711: faq => 282,
2712: bug => 'Instructor Interface',
2713: help => $helpitem});
2714: my $args = {bread_crumbs => $brcrum,
2715: bread_crumbs_component => 'User Management'};
2716: if ($env{'form.popup'}) {
2717: $args->{'no_nav_bar'} = 1;
2718: }
2719: $r->print(&Apache::loncommon::start_page($title,$jscript,$args));
1.188 raeburn 2720: $r->print(&update_result_form($uhome));
1.27 matthew 2721: # Check Inputs
1.101 albertel 2722: if (! $env{'form.ccuname'} ) {
1.193 raeburn 2723: $r->print($error.&mt('No login name specified').'.'.$end.$rtnlink);
1.27 matthew 2724: return;
2725: }
1.138 albertel 2726: if ( $env{'form.ccuname'} ne
2727: &LONCAPA::clean_username($env{'form.ccuname'}) ) {
1.281 bisitz 2728: $r->print($error.&mt('Invalid login name.').' '.
2729: &mt('Only letters, numbers, periods, dashes, @, and underscores are valid.').
1.193 raeburn 2730: $end.$rtnlink);
1.27 matthew 2731: return;
2732: }
1.101 albertel 2733: if (! $env{'form.ccdomain'} ) {
1.193 raeburn 2734: $r->print($error.&mt('No domain specified').'.'.$end.$rtnlink);
1.27 matthew 2735: return;
2736: }
1.138 albertel 2737: if ( $env{'form.ccdomain'} ne
2738: &LONCAPA::clean_domain($env{'form.ccdomain'}) ) {
1.281 bisitz 2739: $r->print($error.&mt('Invalid domain name.').' '.
2740: &mt('Only letters, numbers, periods, dashes, and underscores are valid.').
1.193 raeburn 2741: $end.$rtnlink);
1.27 matthew 2742: return;
2743: }
1.219 raeburn 2744: if ($uhome eq 'no_host') {
2745: $newuser = 1;
2746: }
1.101 albertel 2747: if (! exists($env{'form.makeuser'})) {
1.29 matthew 2748: # Modifying an existing user, so check the validity of the name
2749: if ($uhome eq 'no_host') {
1.389 bisitz 2750: $r->print(
2751: $error
2752: .'<p class="LC_error">'
2753: .&mt('Unable to determine home server for [_1] in domain [_2].',
2754: '"'.$env{'form.ccuname'}.'"','"'.$env{'form.ccdomain'}.'"')
2755: .'</p>');
1.29 matthew 2756: return;
2757: }
2758: }
1.27 matthew 2759: # Determine authentication method and password for the user being modified
2760: my $amode='';
2761: my $genpwd='';
1.101 albertel 2762: if ($env{'form.login'} eq 'krb') {
1.41 albertel 2763: $amode='krb';
1.101 albertel 2764: $amode.=$env{'form.krbver'};
2765: $genpwd=$env{'form.krbarg'};
2766: } elsif ($env{'form.login'} eq 'int') {
1.27 matthew 2767: $amode='internal';
1.101 albertel 2768: $genpwd=$env{'form.intarg'};
2769: } elsif ($env{'form.login'} eq 'fsys') {
1.27 matthew 2770: $amode='unix';
1.101 albertel 2771: $genpwd=$env{'form.fsysarg'};
2772: } elsif ($env{'form.login'} eq 'loc') {
1.27 matthew 2773: $amode='localauth';
1.101 albertel 2774: $genpwd=$env{'form.locarg'};
1.27 matthew 2775: $genpwd=" " if (!$genpwd);
1.101 albertel 2776: } elsif (($env{'form.login'} eq 'nochange') ||
2777: ($env{'form.login'} eq '' )) {
1.34 matthew 2778: # There is no need to tell the user we did not change what they
2779: # did not ask us to change.
1.35 matthew 2780: # If they are creating a new user but have not specified login
2781: # information this will be caught below.
1.30 matthew 2782: } else {
1.367 golterma 2783: $r->print($error.&mt('Invalid login mode or password').$end.$rtnlink);
2784: return;
1.27 matthew 2785: }
1.164 albertel 2786:
1.188 raeburn 2787: $r->print('<h3>'.&mt('User [_1] in domain [_2]',
1.367 golterma 2788: $env{'form.ccuname'}.' ('.&Apache::loncommon::plainname($env{'form.ccuname'},
2789: $env{'form.ccdomain'}).')', $env{'form.ccdomain'}).'</h3>');
2790: my %prog_state = &Apache::lonhtmlcommon::Create_PrgWin($r,2);
1.344 bisitz 2791:
1.193 raeburn 2792: my (%alerts,%rulematch,%inst_results,%curr_rules);
1.334 raeburn 2793: my @userinfo = ('firstname','middlename','lastname','generation','permanentemail','id');
1.361 raeburn 2794: my @usertools = ('aboutme','blog','webdav','portfolio');
1.411 raeburn 2795: my @requestcourses = ('official','unofficial','community','textbook','placement');
1.362 raeburn 2796: my @requestauthor = ('requestauthor');
1.286 raeburn 2797: my ($othertitle,$usertypes,$types) =
2798: &Apache::loncommon::sorted_inst_types($env{'form.ccdomain'});
1.334 raeburn 2799: my %canmodify_status =
2800: &Apache::lonuserutils::can_modify_userinfo($context,$env{'form.ccdomain'},
2801: ['inststatus']);
1.101 albertel 2802: if ($env{'form.makeuser'}) {
1.164 albertel 2803: $r->print('<h3>'.&mt('Creating new account.').'</h3>');
1.27 matthew 2804: # Check for the authentication mode and password
2805: if (! $amode || ! $genpwd) {
1.193 raeburn 2806: $r->print($error.&mt('Invalid login mode or password').$end.$rtnlink);
1.27 matthew 2807: return;
1.18 albertel 2808: }
1.29 matthew 2809: # Determine desired host
1.101 albertel 2810: my $desiredhost = $env{'form.hserver'};
1.29 matthew 2811: if (lc($desiredhost) eq 'default') {
2812: $desiredhost = undef;
2813: } else {
1.147 albertel 2814: my %home_servers =
2815: &Apache::lonnet::get_servers($env{'form.ccdomain'},'library');
1.29 matthew 2816: if (! exists($home_servers{$desiredhost})) {
1.193 raeburn 2817: $r->print($error.&mt('Invalid home server specified').$end.$rtnlink);
2818: return;
2819: }
2820: }
2821: # Check ID format
2822: my %checkhash;
2823: my %checks = ('id' => 1);
2824: %{$checkhash{$env{'form.ccuname'}.':'.$env{'form.ccdomain'}}} = (
1.219 raeburn 2825: 'newuser' => $newuser,
1.196 raeburn 2826: 'id' => $env{'form.cid'},
1.193 raeburn 2827: );
1.196 raeburn 2828: if ($env{'form.cid'} ne '') {
2829: &Apache::loncommon::user_rule_check(\%checkhash,\%checks,\%alerts,
2830: \%rulematch,\%inst_results,\%curr_rules);
2831: if (ref($alerts{'id'}) eq 'HASH') {
2832: if (ref($alerts{'id'}{$env{'form.ccdomain'}}) eq 'HASH') {
2833: my $domdesc =
2834: &Apache::lonnet::domain($env{'form.ccdomain'},'description');
2835: if ($alerts{'id'}{$env{'form.ccdomain'}}{$env{'form.cid'}}) {
2836: my $userchkmsg;
2837: if (ref($curr_rules{$env{'form.ccdomain'}}) eq 'HASH') {
2838: $userchkmsg =
2839: &Apache::loncommon::instrule_disallow_msg('id',
2840: $domdesc,1).
2841: &Apache::loncommon::user_rule_formats($env{'form.ccdomain'},
2842: $domdesc,$curr_rules{$env{'form.ccdomain'}}{'id'},'id');
2843: }
2844: $r->print($error.&mt('Invalid ID format').$end.
2845: $userchkmsg.$rtnlink);
2846: return;
2847: }
2848: }
1.29 matthew 2849: }
2850: }
1.367 golterma 2851: &Apache::lonhtmlcommon::Increment_PrgWin($r, \%prog_state);
1.27 matthew 2852: # Call modifyuser
2853: my $result = &Apache::lonnet::modifyuser
1.193 raeburn 2854: ($env{'form.ccdomain'},$env{'form.ccuname'},$env{'form.cid'},
1.188 raeburn 2855: $amode,$genpwd,$env{'form.cfirstname'},
2856: $env{'form.cmiddlename'},$env{'form.clastname'},
2857: $env{'form.cgeneration'},undef,$desiredhost,
2858: $env{'form.cpermanentemail'});
1.77 www 2859: $r->print(&mt('Generating user').': '.$result);
1.219 raeburn 2860: $uhome = &Apache::lonnet::homeserver($env{'form.ccuname'},
1.101 albertel 2861: $env{'form.ccdomain'});
1.334 raeburn 2862: my (%changeHash,%newcustom,%changed,%changedinfo);
1.267 raeburn 2863: if ($uhome ne 'no_host') {
1.334 raeburn 2864: if ($context eq 'domain') {
1.378 raeburn 2865: foreach my $name ('portfolio','author') {
2866: if ($env{'form.custom_'.$name.'quota'} == 1) {
2867: if ($env{'form.'.$name.'quota'} eq '') {
2868: $newcustom{$name.'quota'} = 0;
2869: } else {
2870: $newcustom{$name.'quota'} = $env{'form.'.$name.'quota'};
2871: $newcustom{$name.'quota'} =~ s/[^\d\.]//g;
2872: }
2873: if ("a_admin($newcustom{$name.'quota'},\%changeHash,$name)) {
2874: $changed{$name.'quota'} = 1;
2875: }
1.334 raeburn 2876: }
2877: }
2878: foreach my $item (@usertools) {
2879: if ($env{'form.custom'.$item} == 1) {
2880: $newcustom{$item} = $env{'form.tools_'.$item};
2881: $changed{$item} = &tool_admin($item,$newcustom{$item},
2882: \%changeHash,'tools');
2883: }
1.267 raeburn 2884: }
1.334 raeburn 2885: foreach my $item (@requestcourses) {
1.341 raeburn 2886: if ($env{'form.custom'.$item} == 1) {
2887: $newcustom{$item} = $env{'form.crsreq_'.$item};
2888: if ($env{'form.crsreq_'.$item} eq 'autolimit') {
2889: $newcustom{$item} .= '=';
1.383 raeburn 2890: $env{'form.crsreq_'.$item.'_limit'} =~ s/\D+//g;
2891: if ($env{'form.crsreq_'.$item.'_limit'}) {
1.341 raeburn 2892: $newcustom{$item} .= $env{'form.crsreq_'.$item.'_limit'};
2893: }
1.334 raeburn 2894: }
1.341 raeburn 2895: $changed{$item} = &tool_admin($item,$newcustom{$item},
2896: \%changeHash,'requestcourses');
1.334 raeburn 2897: }
1.275 raeburn 2898: }
1.362 raeburn 2899: if ($env{'form.customrequestauthor'} == 1) {
2900: $newcustom{'requestauthor'} = $env{'form.requestauthor'};
2901: $changed{'requestauthor'} = &tool_admin('requestauthor',
2902: $newcustom{'requestauthor'},
2903: \%changeHash,'requestauthor');
2904: }
1.275 raeburn 2905: }
1.334 raeburn 2906: if ($canmodify_status{'inststatus'}) {
2907: if (exists($env{'form.inststatus'})) {
2908: my @inststatuses = &Apache::loncommon::get_env_multiple('form.inststatus');
2909: if (@inststatuses > 0) {
2910: $changeHash{'inststatus'} = join(',',@inststatuses);
2911: $changed{'inststatus'} = $changeHash{'inststatus'};
1.306 raeburn 2912: }
2913: }
1.232 raeburn 2914: }
1.334 raeburn 2915: if (keys(%changed)) {
2916: foreach my $item (@userinfo) {
2917: $changeHash{$item} = $env{'form.c'.$item};
1.286 raeburn 2918: }
1.267 raeburn 2919: my $chgresult =
2920: &Apache::lonnet::put('environment',\%changeHash,
2921: $env{'form.ccdomain'},$env{'form.ccuname'});
2922: }
1.232 raeburn 2923: }
1.219 raeburn 2924: $r->print('<br />'.&mt('Home server').': '.$uhome.' '.
2925: &Apache::lonnet::hostname($uhome));
1.101 albertel 2926: } elsif (($env{'form.login'} ne 'nochange') &&
2927: ($env{'form.login'} ne '' )) {
1.27 matthew 2928: # Modify user privileges
2929: if (! $amode || ! $genpwd) {
1.193 raeburn 2930: $r->print($error.'Invalid login mode or password'.$end.$rtnlink);
1.27 matthew 2931: return;
1.20 harris41 2932: }
1.395 bisitz 2933: # Only allow authentication modification if the person has authority
1.101 albertel 2934: if (&Apache::lonnet::allowed('mau',$env{'form.ccdomain'})) {
1.20 harris41 2935: $r->print('Modifying authentication: '.
1.31 matthew 2936: &Apache::lonnet::modifyuserauth(
1.101 albertel 2937: $env{'form.ccdomain'},$env{'form.ccuname'},
1.21 harris41 2938: $amode,$genpwd));
1.102 albertel 2939: $r->print('<br />'.&mt('Home server').': '.&Apache::lonnet::homeserver
1.101 albertel 2940: ($env{'form.ccuname'},$env{'form.ccdomain'}));
1.4 www 2941: } else {
1.27 matthew 2942: # Okay, this is a non-fatal error.
1.395 bisitz 2943: $r->print($error.&mt('You do not have the authority to modify this users authentication information.').$end);
1.27 matthew 2944: }
1.28 matthew 2945: }
1.344 bisitz 2946: $r->rflush(); # Finish display of header before time consuming actions start
1.367 golterma 2947: &Apache::lonhtmlcommon::Increment_PrgWin($r,\%prog_state);
1.28 matthew 2948: ##
1.375 raeburn 2949: my (@userroles,%userupdate,$cnum,$cdom,$defaultcredits,%namechanged);
1.213 raeburn 2950: if ($context eq 'course') {
1.375 raeburn 2951: ($cnum,$cdom) =
2952: &Apache::lonuserutils::get_course_identity();
1.318 raeburn 2953: $crstype = &Apache::loncommon::course_type($cdom.'_'.$cnum);
1.375 raeburn 2954: if ($showcredits) {
2955: $defaultcredits = &Apache::lonuserutils::get_defaultcredits($cdom,$cnum);
2956: }
1.213 raeburn 2957: }
1.101 albertel 2958: if (! $env{'form.makeuser'} ) {
1.28 matthew 2959: # Check for need to change
2960: my %userenv = &Apache::lonnet::get
1.134 raeburn 2961: ('environment',['firstname','middlename','lastname','generation',
1.378 raeburn 2962: 'id','permanentemail','portfolioquota','authorquota','inststatus',
2963: 'tools.aboutme','tools.blog','tools.webdav','tools.portfolio',
1.361 raeburn 2964: 'requestcourses.official','requestcourses.unofficial',
1.384 raeburn 2965: 'requestcourses.community','requestcourses.textbook',
2966: 'reqcrsotherdom.official','reqcrsotherdom.unofficial',
2967: 'reqcrsotherdom.community','reqcrsotherdom.textbook',
1.427 raeburn 2968: 'reqcrsotherdom.placement','requestauthor'],
1.160 raeburn 2969: $env{'form.ccdomain'},$env{'form.ccuname'});
1.28 matthew 2970: my ($tmp) = keys(%userenv);
2971: if ($tmp =~ /^(con_lost|error)/i) {
2972: %userenv = ();
2973: }
1.206 raeburn 2974: my $no_forceid_alert;
2975: # Check to see if user information can be changed
2976: my %domconfig =
2977: &Apache::lonnet::get_dom('configuration',['usermodification'],
2978: $env{'form.ccdomain'});
1.213 raeburn 2979: my @statuses = ('active','future');
2980: my %roles = &Apache::lonnet::get_my_roles($env{'form.ccuname'},$env{'form.ccdomain'},'userroles',\@statuses,undef,$env{'request.role.domain'});
2981: my ($auname,$audom);
1.220 raeburn 2982: if ($context eq 'author') {
1.206 raeburn 2983: $auname = $env{'user.name'};
2984: $audom = $env{'user.domain'};
2985: }
2986: foreach my $item (keys(%roles)) {
1.220 raeburn 2987: my ($rolenum,$roledom,$role) = split(/:/,$item,-1);
1.206 raeburn 2988: if ($context eq 'course') {
2989: if ($cnum ne '' && $cdom ne '') {
2990: if ($rolenum eq $cnum && $roledom eq $cdom) {
2991: if (!grep(/^\Q$role\E$/,@userroles)) {
2992: push(@userroles,$role);
2993: }
2994: }
2995: }
2996: } elsif ($context eq 'author') {
2997: if ($rolenum eq $auname && $roledom eq $audom) {
2998: if (!grep(/^\Q$role\E$/,@userroles)) {
2999: push(@userroles,$role);
3000: }
3001: }
3002: }
3003: }
1.220 raeburn 3004: if ($env{'form.action'} eq 'singlestudent') {
3005: if (!grep(/^st$/,@userroles)) {
3006: push(@userroles,'st');
3007: }
3008: } else {
3009: # Check for course or co-author roles being activated or re-enabled
3010: if ($context eq 'author' || $context eq 'course') {
3011: foreach my $key (keys(%env)) {
3012: if ($context eq 'author') {
3013: if ($key=~/^form\.act_\Q$audom\E_\Q$auname\E_([^_]+)/) {
3014: if (!grep(/^\Q$1\E$/,@userroles)) {
3015: push(@userroles,$1);
3016: }
3017: } elsif ($key =~/^form\.ren\:\Q$audom\E\/\Q$auname\E_([^_]+)/) {
3018: if (!grep(/^\Q$1\E$/,@userroles)) {
3019: push(@userroles,$1);
3020: }
1.206 raeburn 3021: }
1.220 raeburn 3022: } elsif ($context eq 'course') {
3023: if ($key=~/^form\.act_\Q$cdom\E_\Q$cnum\E_([^_]+)/) {
3024: if (!grep(/^\Q$1\E$/,@userroles)) {
3025: push(@userroles,$1);
3026: }
3027: } elsif ($key =~/^form\.ren\:\Q$cdom\E\/\Q$cnum\E(\/?\w*)_([^_]+)/) {
3028: if (!grep(/^\Q$1\E$/,@userroles)) {
3029: push(@userroles,$1);
3030: }
1.206 raeburn 3031: }
3032: }
3033: }
3034: }
3035: }
3036: #Check to see if we can change personal data for the user
3037: my (@mod_disallowed,@longroles);
3038: foreach my $role (@userroles) {
3039: if ($role eq 'cr') {
3040: push(@longroles,'Custom');
3041: } else {
1.318 raeburn 3042: push(@longroles,&Apache::lonnet::plaintext($role,$crstype));
1.206 raeburn 3043: }
3044: }
1.219 raeburn 3045: my %canmodify = &Apache::lonuserutils::can_modify_userinfo($context,$env{'form.ccdomain'},\@userinfo,\@userroles);
3046: foreach my $item (@userinfo) {
1.28 matthew 3047: # Strip leading and trailing whitespace
1.203 raeburn 3048: $env{'form.c'.$item} =~ s/(\s+$|^\s+)//g;
1.219 raeburn 3049: if (!$canmodify{$item}) {
1.207 raeburn 3050: if (defined($env{'form.c'.$item})) {
3051: if ($env{'form.c'.$item} ne $userenv{$item}) {
3052: push(@mod_disallowed,$item);
3053: }
1.206 raeburn 3054: }
3055: $env{'form.c'.$item} = $userenv{$item};
3056: }
1.28 matthew 3057: }
1.259 bisitz 3058: # Check to see if we can change the Student/Employee ID
1.196 raeburn 3059: my $forceid = $env{'form.forceid'};
3060: my $recurseid = $env{'form.recurseid'};
3061: my (%alerts,%rulematch,%idinst_results,%curr_rules,%got_rules);
1.203 raeburn 3062: my %uidhash = &Apache::lonnet::idrget($env{'form.ccdomain'},
3063: $env{'form.ccuname'});
3064: if (($uidhash{$env{'form.ccuname'}}) &&
3065: ($uidhash{$env{'form.ccuname'}}!~/error\:/) &&
3066: (!$forceid)) {
3067: if ($env{'form.cid'} ne $uidhash{$env{'form.ccuname'}}) {
3068: $env{'form.cid'} = $userenv{'id'};
1.293 bisitz 3069: $no_forceid_alert = &mt('New student/employee ID does not match existing ID for this user.')
1.259 bisitz 3070: .'<br />'
3071: .&mt("Change is not permitted without checking the 'Force ID change' checkbox on the previous page.")
3072: .'<br />'."\n";
1.203 raeburn 3073: }
3074: }
3075: if ($env{'form.cid'} ne $userenv{'id'}) {
1.196 raeburn 3076: my $checkhash;
3077: my $checks = { 'id' => 1 };
3078: $checkhash->{$env{'form.ccuname'}.':'.$env{'form.ccdomain'}} =
3079: { 'newuser' => $newuser,
3080: 'id' => $env{'form.cid'},
3081: };
3082: &Apache::loncommon::user_rule_check($checkhash,$checks,
3083: \%alerts,\%rulematch,\%idinst_results,\%curr_rules,\%got_rules);
3084: if (ref($alerts{'id'}) eq 'HASH') {
3085: if (ref($alerts{'id'}{$env{'form.ccdomain'}}) eq 'HASH') {
1.203 raeburn 3086: $env{'form.cid'} = $userenv{'id'};
1.196 raeburn 3087: }
3088: }
3089: }
1.378 raeburn 3090: my (%quotachanged,%oldquota,%newquota,%olddefquota,%newdefquota,
3091: $oldinststatus,$newinststatus,%oldisdefault,%newisdefault,%oldsettings,
1.339 raeburn 3092: %oldsettingstext,%newsettings,%newsettingstext,@disporder,
1.378 raeburn 3093: %oldsettingstatus,%newsettingstatus);
1.334 raeburn 3094: @disporder = ('inststatus');
3095: if ($env{'request.role.domain'} eq $env{'form.ccdomain'}) {
1.362 raeburn 3096: push(@disporder,'requestcourses','requestauthor');
1.334 raeburn 3097: } else {
3098: push(@disporder,'reqcrsotherdom');
3099: }
3100: push(@disporder,('quota','tools'));
1.338 raeburn 3101: $oldinststatus = $userenv{'inststatus'};
1.378 raeburn 3102: foreach my $name ('portfolio','author') {
3103: ($olddefquota{$name},$oldsettingstatus{$name}) =
3104: &Apache::loncommon::default_quota($env{'form.ccdomain'},$oldinststatus,$name);
3105: ($newdefquota{$name},$newsettingstatus{$name}) = ($olddefquota{$name},$oldsettingstatus{$name});
3106: }
1.334 raeburn 3107: my %canshow;
1.220 raeburn 3108: if (&Apache::lonnet::allowed('mpq',$env{'form.ccdomain'})) {
1.334 raeburn 3109: $canshow{'quota'} = 1;
1.220 raeburn 3110: }
1.267 raeburn 3111: if (&Apache::lonnet::allowed('mut',$env{'form.ccdomain'})) {
1.334 raeburn 3112: $canshow{'tools'} = 1;
1.267 raeburn 3113: }
1.275 raeburn 3114: if (&Apache::lonnet::allowed('ccc',$env{'form.ccdomain'})) {
1.334 raeburn 3115: $canshow{'requestcourses'} = 1;
1.300 raeburn 3116: } elsif (&Apache::lonnet::allowed('ccc',$env{'request.role.domain'})) {
1.334 raeburn 3117: $canshow{'reqcrsotherdom'} = 1;
1.275 raeburn 3118: }
1.286 raeburn 3119: if (&Apache::lonnet::allowed('mau',$env{'form.ccdomain'})) {
1.334 raeburn 3120: $canshow{'inststatus'} = 1;
1.286 raeburn 3121: }
1.362 raeburn 3122: if (&Apache::lonnet::allowed('cau',$env{'form.ccdomain'})) {
3123: $canshow{'requestauthor'} = 1;
3124: }
1.267 raeburn 3125: my (%changeHash,%changed);
1.286 raeburn 3126: if ($oldinststatus eq '') {
1.334 raeburn 3127: $oldsettings{'inststatus'} = $othertitle;
1.286 raeburn 3128: } else {
3129: if (ref($usertypes) eq 'HASH') {
1.334 raeburn 3130: $oldsettings{'inststatus'} = join(', ',map{ $usertypes->{ &unescape($_) }; } (split(/:/,$userenv{'inststatus'})));
1.286 raeburn 3131: } else {
1.334 raeburn 3132: $oldsettings{'inststatus'} = join(', ',map{ &unescape($_); } (split(/:/,$userenv{'inststatus'})));
1.286 raeburn 3133: }
3134: }
3135: $changeHash{'inststatus'} = $userenv{'inststatus'};
1.334 raeburn 3136: if ($canmodify_status{'inststatus'}) {
3137: $canshow{'inststatus'} = 1;
1.286 raeburn 3138: if (exists($env{'form.inststatus'})) {
3139: my @inststatuses = &Apache::loncommon::get_env_multiple('form.inststatus');
3140: if (@inststatuses > 0) {
3141: $newinststatus = join(':',map { &escape($_); } @inststatuses);
3142: $changeHash{'inststatus'} = $newinststatus;
3143: if ($newinststatus ne $oldinststatus) {
3144: $changed{'inststatus'} = $newinststatus;
1.378 raeburn 3145: foreach my $name ('portfolio','author') {
3146: ($newdefquota{$name},$newsettingstatus{$name}) =
3147: &Apache::loncommon::default_quota($env{'form.ccdomain'},$newinststatus,$name);
3148: }
1.286 raeburn 3149: }
3150: if (ref($usertypes) eq 'HASH') {
1.334 raeburn 3151: $newsettings{'inststatus'} = join(', ',map{ $usertypes->{$_}; } (@inststatuses));
1.286 raeburn 3152: } else {
1.337 raeburn 3153: $newsettings{'inststatus'} = join(', ',@inststatuses);
1.286 raeburn 3154: }
1.334 raeburn 3155: }
3156: } else {
3157: $newinststatus = '';
3158: $changeHash{'inststatus'} = $newinststatus;
3159: $newsettings{'inststatus'} = $othertitle;
3160: if ($newinststatus ne $oldinststatus) {
3161: $changed{'inststatus'} = $changeHash{'inststatus'};
1.378 raeburn 3162: foreach my $name ('portfolio','author') {
3163: ($newdefquota{$name},$newsettingstatus{$name}) =
3164: &Apache::loncommon::default_quota($env{'form.ccdomain'},$newinststatus,$name);
3165: }
1.286 raeburn 3166: }
3167: }
1.334 raeburn 3168: } elsif ($context ne 'selfcreate') {
3169: $canshow{'inststatus'} = 1;
1.337 raeburn 3170: $newsettings{'inststatus'} = $oldsettings{'inststatus'};
1.286 raeburn 3171: }
1.378 raeburn 3172: foreach my $name ('portfolio','author') {
3173: $changeHash{$name.'quota'} = $userenv{$name.'quota'};
3174: }
1.334 raeburn 3175: if ($context eq 'domain') {
1.378 raeburn 3176: foreach my $name ('portfolio','author') {
3177: if ($userenv{$name.'quota'} ne '') {
3178: $oldquota{$name} = $userenv{$name.'quota'};
3179: if ($env{'form.custom_'.$name.'quota'} == 1) {
3180: if ($env{'form.'.$name.'quota'} eq '') {
3181: $newquota{$name} = 0;
3182: } else {
3183: $newquota{$name} = $env{'form.'.$name.'quota'};
3184: $newquota{$name} =~ s/[^\d\.]//g;
3185: }
3186: if ($newquota{$name} != $oldquota{$name}) {
3187: if ("a_admin($newquota{$name},\%changeHash,$name)) {
3188: $changed{$name.'quota'} = 1;
3189: }
3190: }
1.334 raeburn 3191: } else {
1.378 raeburn 3192: if ("a_admin('',\%changeHash,$name)) {
3193: $changed{$name.'quota'} = 1;
3194: $newquota{$name} = $newdefquota{$name};
3195: $newisdefault{$name} = 1;
3196: }
1.334 raeburn 3197: }
1.149 raeburn 3198: } else {
1.378 raeburn 3199: $oldisdefault{$name} = 1;
3200: $oldquota{$name} = $olddefquota{$name};
3201: if ($env{'form.custom_'.$name.'quota'} == 1) {
3202: if ($env{'form.'.$name.'quota'} eq '') {
3203: $newquota{$name} = 0;
3204: } else {
3205: $newquota{$name} = $env{'form.'.$name.'quota'};
3206: $newquota{$name} =~ s/[^\d\.]//g;
3207: }
3208: if ("a_admin($newquota{$name},\%changeHash,$name)) {
3209: $changed{$name.'quota'} = 1;
3210: }
1.334 raeburn 3211: } else {
1.378 raeburn 3212: $newquota{$name} = $newdefquota{$name};
3213: $newisdefault{$name} = 1;
1.334 raeburn 3214: }
1.378 raeburn 3215: }
3216: if ($oldisdefault{$name}) {
3217: $oldsettingstext{'quota'}{$name} = &get_defaultquota_text($oldsettingstatus{$name});
1.383 raeburn 3218: } else {
3219: $oldsettingstext{'quota'}{$name} = &mt('custom quota: [_1] MB',$oldquota{$name});
1.378 raeburn 3220: }
3221: if ($newisdefault{$name}) {
3222: $newsettingstext{'quota'}{$name} = &get_defaultquota_text($newsettingstatus{$name});
1.383 raeburn 3223: } else {
3224: $newsettingstext{'quota'}{$name} = &mt('custom quota: [_1] MB',$newquota{$name});
1.134 raeburn 3225: }
3226: }
1.334 raeburn 3227: &tool_changes('tools',\@usertools,\%oldsettings,\%oldsettingstext,\%userenv,
3228: \%changeHash,\%changed,\%newsettings,\%newsettingstext);
3229: if ($env{'form.ccdomain'} eq $env{'request.role.domain'}) {
3230: &tool_changes('requestcourses',\@requestcourses,\%oldsettings,\%oldsettingstext,
3231: \%userenv,\%changeHash,\%changed,\%newsettings,\%newsettingstext);
1.384 raeburn 3232: &tool_changes('requestauthor',\@requestauthor,\%oldsettings,\%oldsettingstext,
3233: \%userenv,\%changeHash,\%changed,\%newsettings,\%newsettingstext);
1.149 raeburn 3234: } else {
1.334 raeburn 3235: &tool_changes('reqcrsotherdom',\@requestcourses,\%oldsettings,\%oldsettingstext,
3236: \%userenv,\%changeHash,\%changed,\%newsettings,\%newsettingstext);
1.149 raeburn 3237: }
3238: }
1.334 raeburn 3239: foreach my $item (@userinfo) {
3240: if ($env{'form.c'.$item} ne $userenv{$item}) {
3241: $namechanged{$item} = 1;
3242: }
1.204 raeburn 3243: }
1.378 raeburn 3244: foreach my $name ('portfolio','author') {
1.390 bisitz 3245: $oldsettings{'quota'}{$name} = &mt('[_1] MB',$oldquota{$name});
3246: $newsettings{'quota'}{$name} = &mt('[_1] MB',$newquota{$name});
1.378 raeburn 3247: }
1.334 raeburn 3248: if ((keys(%namechanged) > 0) || (keys(%changed) > 0)) {
1.267 raeburn 3249: my ($chgresult,$namechgresult);
3250: if (keys(%changed) > 0) {
3251: $chgresult =
1.204 raeburn 3252: &Apache::lonnet::put('environment',\%changeHash,
3253: $env{'form.ccdomain'},$env{'form.ccuname'});
1.267 raeburn 3254: if ($chgresult eq 'ok') {
3255: if (($env{'user.name'} eq $env{'form.ccuname'}) &&
3256: ($env{'user.domain'} eq $env{'form.ccdomain'})) {
1.270 raeburn 3257: my %newenvhash;
3258: foreach my $key (keys(%changed)) {
1.411 raeburn 3259: if (($key eq 'official') || ($key eq 'unofficial') ||
3260: ($key eq 'community') || ($key eq 'textbook') ||
3261: ($key eq 'placement')) {
1.279 raeburn 3262: $newenvhash{'environment.requestcourses.'.$key} =
3263: $changeHash{'requestcourses.'.$key};
1.362 raeburn 3264: if ($changeHash{'requestcourses.'.$key}) {
1.332 raeburn 3265: $newenvhash{'environment.canrequest.'.$key} = 1;
1.279 raeburn 3266: } else {
3267: $newenvhash{'environment.canrequest.'.$key} =
3268: &Apache::lonnet::usertools_access($env{'user.name'},$env{'user.domain'},
3269: $key,'reload','requestcourses');
3270: }
1.362 raeburn 3271: } elsif ($key eq 'requestauthor') {
3272: $newenvhash{'environment.'.$key} = $changeHash{$key};
3273: if ($changeHash{$key}) {
3274: $newenvhash{'environment.canrequest.author'} = 1;
3275: } else {
3276: $newenvhash{'environment.canrequest.author'} =
3277: &Apache::lonnet::usertools_access($env{'user.name'},$env{'user.domain'},
3278: $key,'reload','requestauthor');
3279: }
1.275 raeburn 3280: } elsif ($key ne 'quota') {
1.270 raeburn 3281: $newenvhash{'environment.tools.'.$key} =
3282: $changeHash{'tools.'.$key};
1.279 raeburn 3283: if ($changeHash{'tools.'.$key} ne '') {
3284: $newenvhash{'environment.availabletools.'.$key} =
3285: $changeHash{'tools.'.$key};
3286: } else {
3287: $newenvhash{'environment.availabletools.'.$key} =
1.367 golterma 3288: &Apache::lonnet::usertools_access($env{'user.name'},$env{'user.domain'},
3289: $key,'reload','tools');
1.279 raeburn 3290: }
1.270 raeburn 3291: }
3292: }
1.271 raeburn 3293: if (keys(%newenvhash)) {
3294: &Apache::lonnet::appenv(\%newenvhash);
3295: }
1.267 raeburn 3296: }
3297: }
1.204 raeburn 3298: }
1.334 raeburn 3299: if (keys(%namechanged) > 0) {
1.337 raeburn 3300: foreach my $field (@userinfo) {
3301: $changeHash{$field} = $env{'form.c'.$field};
3302: }
3303: # Make the change
1.204 raeburn 3304: $namechgresult =
3305: &Apache::lonnet::modifyuser($env{'form.ccdomain'},
3306: $env{'form.ccuname'},$changeHash{'id'},undef,undef,
3307: $changeHash{'firstname'},$changeHash{'middlename'},
3308: $changeHash{'lastname'},$changeHash{'generation'},
1.337 raeburn 3309: $changeHash{'id'},undef,$changeHash{'permanentemail'},undef,\@userinfo);
1.220 raeburn 3310: %userupdate = (
3311: lastname => $env{'form.clastname'},
3312: middlename => $env{'form.cmiddlename'},
3313: firstname => $env{'form.cfirstname'},
3314: generation => $env{'form.cgeneration'},
3315: id => $env{'form.cid'},
3316: );
1.204 raeburn 3317: }
1.334 raeburn 3318: if (((keys(%namechanged) > 0) && $namechgresult eq 'ok') ||
1.267 raeburn 3319: ((keys(%changed) > 0) && $chgresult eq 'ok')) {
1.28 matthew 3320: # Tell the user we changed the name
1.334 raeburn 3321: &display_userinfo($r,1,\@disporder,\%canshow,\@requestcourses,
1.362 raeburn 3322: \@usertools,\@requestauthor,\%userenv,\%changed,\%namechanged,
1.334 raeburn 3323: \%oldsettings, \%oldsettingstext,\%newsettings,
3324: \%newsettingstext);
1.203 raeburn 3325: if ($env{'form.cid'} ne $userenv{'id'}) {
3326: &Apache::lonnet::idput($env{'form.ccdomain'},
1.407 raeburn 3327: {$env{'form.ccuname'} => $env{'form.cid'}},$uhome,'ids');
1.203 raeburn 3328: if (($recurseid) &&
3329: (&Apache::lonnet::allowed('mau',$env{'form.ccdomain'}))) {
3330: my $idresult =
3331: &Apache::lonuserutils::propagate_id_change(
3332: $env{'form.ccuname'},$env{'form.ccdomain'},
3333: \%userupdate);
3334: $r->print('<br />'.$idresult.'<br />');
3335: }
1.196 raeburn 3336: }
1.149 raeburn 3337: if (($env{'form.ccdomain'} eq $env{'user.domain'}) &&
3338: ($env{'form.ccuname'} eq $env{'user.name'})) {
3339: my %newenvhash;
3340: foreach my $key (keys(%changeHash)) {
3341: $newenvhash{'environment.'.$key} = $changeHash{$key};
3342: }
1.238 raeburn 3343: &Apache::lonnet::appenv(\%newenvhash);
1.149 raeburn 3344: }
1.28 matthew 3345: } else { # error occurred
1.389 bisitz 3346: $r->print(
3347: '<p class="LC_error">'
3348: .&mt('Unable to successfully change environment for [_1] in domain [_2].',
3349: '"'.$env{'form.ccuname'}.'"',
3350: '"'.$env{'form.ccdomain'}.'"')
3351: .'</p>');
1.28 matthew 3352: }
1.334 raeburn 3353: } else { # End of if ($env ... ) logic
1.275 raeburn 3354: # They did not want to change the users name, quota, tool availability,
3355: # or ability to request creation of courses,
1.267 raeburn 3356: # but we can still tell them what the name and quota and availabilities are
1.334 raeburn 3357: &display_userinfo($r,undef,\@disporder,\%canshow,\@requestcourses,
1.362 raeburn 3358: \@usertools,\@requestauthor,\%userenv,\%changed,\%namechanged,\%oldsettings,
1.334 raeburn 3359: \%oldsettingstext,\%newsettings,\%newsettingstext);
1.28 matthew 3360: }
1.206 raeburn 3361: if (@mod_disallowed) {
3362: my ($rolestr,$contextname);
3363: if (@longroles > 0) {
3364: $rolestr = join(', ',@longroles);
3365: } else {
3366: $rolestr = &mt('No roles');
3367: }
3368: if ($context eq 'course') {
1.399 bisitz 3369: $contextname = 'course';
1.206 raeburn 3370: } elsif ($context eq 'author') {
1.399 bisitz 3371: $contextname = 'co-author';
1.206 raeburn 3372: }
3373: $r->print(&mt('The following fields were not updated: ').'<ul>');
3374: my %fieldtitles = &Apache::loncommon::personal_data_fieldtitles();
3375: foreach my $field (@mod_disallowed) {
3376: $r->print('<li>'.$fieldtitles{$field}.'</li>'."\n");
3377: }
1.207 raeburn 3378: $r->print('</ul>');
3379: if (@mod_disallowed == 1) {
1.399 bisitz 3380: $r->print(&mt("You do not have the authority to change this field given the user's current set of active/future $contextname roles:"));
1.207 raeburn 3381: } else {
1.399 bisitz 3382: $r->print(&mt("You do not have the authority to change these fields given the user's current set of active/future $contextname roles:"));
1.207 raeburn 3383: }
1.292 bisitz 3384: my $helplink = 'javascript:helpMenu('."'display'".')';
3385: $r->print('<span class="LC_cusr_emph">'.$rolestr.'</span><br />'
3386: .&mt('Please contact your [_1]helpdesk[_2] for more information.'
3387: ,'<a href="'.$helplink.'">','</a>')
3388: .'<br />');
1.206 raeburn 3389: }
1.259 bisitz 3390: $r->print('<span class="LC_warning">'
3391: .$no_forceid_alert
3392: .&Apache::lonuserutils::print_namespacing_alerts($env{'form.ccdomain'},\%alerts,\%curr_rules)
3393: .'</span>');
1.4 www 3394: }
1.367 golterma 3395: &Apache::lonhtmlcommon::Close_PrgWin($r,\%prog_state);
1.220 raeburn 3396: if ($env{'form.action'} eq 'singlestudent') {
1.375 raeburn 3397: &enroll_single_student($r,$uhome,$amode,$genpwd,$now,$newuser,$context,
3398: $crstype,$showcredits,$defaultcredits);
1.386 bisitz 3399: my $linktext = ($crstype eq 'Community' ?
3400: &mt('Enroll Another Member') : &mt('Enroll Another Student'));
3401: $r->print(
3402: &Apache::lonhtmlcommon::actionbox([
3403: '<a href="javascript:backPage(document.userupdate)">'
3404: .($crstype eq 'Community' ?
3405: &mt('Enroll Another Member') : &mt('Enroll Another Student'))
3406: .'</a>']));
1.220 raeburn 3407: } else {
1.375 raeburn 3408: my @rolechanges = &update_roles($r,$context,$showcredits);
1.334 raeburn 3409: if (keys(%namechanged) > 0) {
1.220 raeburn 3410: if ($context eq 'course') {
3411: if (@userroles > 0) {
1.225 raeburn 3412: if ((@rolechanges == 0) ||
3413: (!(grep(/^st$/,@rolechanges)))) {
3414: if (grep(/^st$/,@userroles)) {
3415: my $classlistupdated =
3416: &Apache::lonuserutils::update_classlist($cdom,
1.220 raeburn 3417: $cnum,$env{'form.ccdomain'},
3418: $env{'form.ccuname'},\%userupdate);
1.225 raeburn 3419: }
1.220 raeburn 3420: }
3421: }
3422: }
3423: }
1.226 raeburn 3424: my $userinfo = &Apache::loncommon::plainname($env{'form.ccuname'},
1.233 raeburn 3425: $env{'form.ccdomain'});
3426: if ($env{'form.popup'}) {
3427: $r->print('<p><a href="javascript:window.close()">'.&mt('Close window').'</a></p>');
3428: } else {
1.367 golterma 3429: $r->print('<br />'.&Apache::lonhtmlcommon::actionbox(['<a href="javascript:backPage(document.userupdate,'."'$env{'form.prevphase'}','modify'".')">'
3430: .&mt('Modify this user: [_1]','<span class="LC_cusr_emph">'.$env{'form.ccuname'}.':'.$env{'form.ccdomain'}.' ('.$userinfo.')</span>').'</a>',
3431: '<a href="javascript:backPage(document.userupdate)">'.&mt('Create/Modify Another User').'</a>']));
1.233 raeburn 3432: }
1.220 raeburn 3433: }
3434: }
3435:
1.334 raeburn 3436: sub display_userinfo {
1.362 raeburn 3437: my ($r,$changed,$order,$canshow,$requestcourses,$usertools,$requestauthor,
3438: $userenv,$changedhash,$namechangedhash,$oldsetting,$oldsettingtext,
1.334 raeburn 3439: $newsetting,$newsettingtext) = @_;
3440: return unless (ref($order) eq 'ARRAY' &&
3441: ref($canshow) eq 'HASH' &&
3442: ref($requestcourses) eq 'ARRAY' &&
1.362 raeburn 3443: ref($requestauthor) eq 'ARRAY' &&
1.334 raeburn 3444: ref($usertools) eq 'ARRAY' &&
3445: ref($userenv) eq 'HASH' &&
3446: ref($changedhash) eq 'HASH' &&
3447: ref($oldsetting) eq 'HASH' &&
3448: ref($oldsettingtext) eq 'HASH' &&
3449: ref($newsetting) eq 'HASH' &&
3450: ref($newsettingtext) eq 'HASH');
3451: my %lt=&Apache::lonlocal::texthash(
1.372 raeburn 3452: 'ui' => 'User Information',
1.334 raeburn 3453: 'uic' => 'User Information Changed',
3454: 'firstname' => 'First Name',
3455: 'middlename' => 'Middle Name',
3456: 'lastname' => 'Last Name',
3457: 'generation' => 'Generation',
3458: 'id' => 'Student/Employee ID',
3459: 'permanentemail' => 'Permanent e-mail address',
1.378 raeburn 3460: 'portfolioquota' => 'Disk space allocated to portfolio files',
1.385 bisitz 3461: 'authorquota' => 'Disk space allocated to Authoring Space',
1.334 raeburn 3462: 'blog' => 'Blog Availability',
1.361 raeburn 3463: 'webdav' => 'WebDAV Availability',
1.334 raeburn 3464: 'aboutme' => 'Personal Information Page Availability',
3465: 'portfolio' => 'Portfolio Availability',
3466: 'official' => 'Can Request Official Courses',
3467: 'unofficial' => 'Can Request Unofficial Courses',
3468: 'community' => 'Can Request Communities',
1.384 raeburn 3469: 'textbook' => 'Can Request Textbook Courses',
1.411 raeburn 3470: 'placement' => 'Can Request Placement Tests',
1.362 raeburn 3471: 'requestauthor' => 'Can Request Author Role',
1.334 raeburn 3472: 'inststatus' => "Affiliation",
3473: 'prvs' => 'Previous Value:',
3474: 'chto' => 'Changed To:'
3475: );
3476: if ($changed) {
1.372 raeburn 3477: $r->print('<h3>'.$lt{'uic'}.'</h3>'.
1.367 golterma 3478: &Apache::loncommon::start_data_table().
3479: &Apache::loncommon::start_data_table_header_row());
1.334 raeburn 3480: $r->print("<th> </th>\n");
1.367 golterma 3481: $r->print('<th><b>'.$lt{'prvs'}.'</b></th>');
3482: $r->print('<th><span class="LC_nobreak"><b>'.$lt{'chto'}.'</b></span></th>');
3483: $r->print(&Apache::loncommon::end_data_table_header_row());
3484: my @userinfo = ('firstname','middlename','lastname','generation','permanentemail','id');
3485:
1.334 raeburn 3486: foreach my $item (@userinfo) {
3487: my $value = $env{'form.c'.$item};
1.367 golterma 3488: #show changes only:
1.383 raeburn 3489: unless ($value eq $userenv->{$item}){
1.367 golterma 3490: $r->print(&Apache::loncommon::start_data_table_row());
3491: $r->print("<td>$lt{$item}</td>\n");
1.383 raeburn 3492: $r->print("<td>".$userenv->{$item}."</td>\n");
1.367 golterma 3493: $r->print("<td>$value </td>\n");
3494: $r->print(&Apache::loncommon::end_data_table_row());
1.334 raeburn 3495: }
3496: }
3497: foreach my $entry (@{$order}) {
1.383 raeburn 3498: if ($canshow->{$entry}) {
3499: if (($entry eq 'requestcourses') || ($entry eq 'reqcrsotherdom') || ($entry eq 'requestauthor')) {
3500: my @items;
3501: if ($entry eq 'requestauthor') {
3502: @items = ($entry);
3503: } else {
3504: @items = @{$requestcourses};
1.384 raeburn 3505: }
1.383 raeburn 3506: foreach my $item (@items) {
3507: if (($newsetting->{$item} ne $oldsetting->{$item}) ||
3508: ($newsettingtext->{$item} ne $oldsettingtext->{$item})) {
3509: $r->print(&Apache::loncommon::start_data_table_row()."\n");
3510: $r->print("<td>$lt{$item}</td>\n");
3511: $r->print("<td>".$oldsetting->{$item});
3512: if ($oldsettingtext->{$item}) {
3513: if ($oldsetting->{$item}) {
3514: $r->print(' -- ');
3515: }
3516: $r->print($oldsettingtext->{$item});
3517: }
3518: $r->print("</td>\n");
3519: $r->print("<td>".$newsetting->{$item});
3520: if ($newsettingtext->{$item}) {
3521: if ($newsetting->{$item}) {
3522: $r->print(' -- ');
3523: }
3524: $r->print($newsettingtext->{$item});
3525: }
3526: $r->print("</td>\n");
3527: $r->print(&Apache::loncommon::end_data_table_row()."\n");
1.334 raeburn 3528: }
3529: }
3530: } elsif ($entry eq 'tools') {
3531: foreach my $item (@{$usertools}) {
1.383 raeburn 3532: if ($newsetting->{$item} ne $oldsetting->{$item}) {
3533: $r->print(&Apache::loncommon::start_data_table_row()."\n");
3534: $r->print("<td>$lt{$item}</td>\n");
3535: $r->print("<td>".$oldsetting->{$item}.' '.$oldsettingtext->{$item}."</td>\n");
3536: $r->print("<td>".$newsetting->{$item}.' '.$newsettingtext->{$item}."</td>\n");
3537: $r->print(&Apache::loncommon::end_data_table_row()."\n");
1.334 raeburn 3538: }
3539: }
1.378 raeburn 3540: } elsif ($entry eq 'quota') {
3541: if ((ref($oldsetting->{$entry}) eq 'HASH') && (ref($oldsettingtext->{$entry}) eq 'HASH') &&
3542: (ref($newsetting->{$entry}) eq 'HASH') && (ref($newsettingtext->{$entry}) eq 'HASH')) {
3543: foreach my $name ('portfolio','author') {
1.383 raeburn 3544: if ($newsetting->{$entry}->{$name} ne $oldsetting->{$entry}->{$name}) {
3545: $r->print(&Apache::loncommon::start_data_table_row()."\n");
3546: $r->print("<td>$lt{$name.$entry}</td>\n");
3547: $r->print("<td>".$oldsettingtext->{$entry}->{$name}."</td>\n");
3548: $r->print("<td>".$newsettingtext->{$entry}->{$name}."</td>\n");
3549: $r->print(&Apache::loncommon::end_data_table_row()."\n");
1.378 raeburn 3550: }
3551: }
3552: }
1.334 raeburn 3553: } else {
1.383 raeburn 3554: if ($newsetting->{$entry} ne $oldsetting->{$entry}) {
3555: $r->print(&Apache::loncommon::start_data_table_row()."\n");
3556: $r->print("<td>$lt{$entry}</td>\n");
3557: $r->print("<td>".$oldsetting->{$entry}.' '.$oldsettingtext->{$entry}."</td>\n");
3558: $r->print("<td>".$newsetting->{$entry}.' '.$newsettingtext->{$entry}."</td>\n");
3559: $r->print(&Apache::loncommon::end_data_table_row()."\n");
1.334 raeburn 3560: }
3561: }
3562: }
3563: }
1.367 golterma 3564: $r->print(&Apache::loncommon::end_data_table().'<br />');
1.372 raeburn 3565: } else {
3566: $r->print('<h3>'.$lt{'ui'}.'</h3>'.
3567: '<p>'.&mt('No changes made to user information').'</p>');
1.334 raeburn 3568: }
3569: return;
3570: }
3571:
1.275 raeburn 3572: sub tool_changes {
3573: my ($context,$usertools,$oldaccess,$oldaccesstext,$userenv,$changeHash,
3574: $changed,$newaccess,$newaccesstext) = @_;
3575: if (!((ref($usertools) eq 'ARRAY') && (ref($oldaccess) eq 'HASH') &&
3576: (ref($oldaccesstext) eq 'HASH') && (ref($userenv) eq 'HASH') &&
3577: (ref($changeHash) eq 'HASH') && (ref($changed) eq 'HASH') &&
3578: (ref($newaccess) eq 'HASH') && (ref($newaccesstext) eq 'HASH'))) {
3579: return;
3580: }
1.383 raeburn 3581: my %reqdisplay = &requestchange_display();
1.300 raeburn 3582: if ($context eq 'reqcrsotherdom') {
1.309 raeburn 3583: my @options = ('approval','validate','autolimit');
1.306 raeburn 3584: my $optregex = join('|',@options);
1.300 raeburn 3585: my $cdom = $env{'request.role.domain'};
3586: foreach my $tool (@{$usertools}) {
1.383 raeburn 3587: $oldaccesstext->{$tool} = &mt("availability set to 'off'");
1.314 raeburn 3588: $newaccesstext->{$tool} = $oldaccesstext->{$tool};
1.300 raeburn 3589: $changeHash->{$context.'.'.$tool} = $userenv->{$context.'.'.$tool};
1.383 raeburn 3590: my ($newop,$limit);
1.314 raeburn 3591: if ($env{'form.'.$context.'_'.$tool}) {
3592: $newop = $env{'form.'.$context.'_'.$tool};
3593: if ($newop eq 'autolimit') {
1.383 raeburn 3594: $limit = $env{'form.'.$context.'_'.$tool.'_limit'};
1.314 raeburn 3595: $limit =~ s/\D+//g;
3596: $newop .= '='.$limit;
3597: }
3598: }
1.300 raeburn 3599: if ($userenv->{$context.'.'.$tool} eq '') {
1.314 raeburn 3600: if ($newop) {
3601: $changed->{$tool}=&tool_admin($tool,$cdom.':'.$newop,
1.300 raeburn 3602: $changeHash,$context);
3603: if ($changed->{$tool}) {
1.383 raeburn 3604: if ($newop =~ /^autolimit/) {
3605: if ($limit) {
3606: $newaccesstext->{$tool} = &mt('available with automatic approval, up to limit of [quant,_1,request] per user',$limit);
3607: } else {
3608: $newaccesstext->{$tool} = &mt('available with automatic approval (unlimited)');
3609: }
3610: } else {
3611: $newaccesstext->{$tool} = $reqdisplay{$newop};
3612: }
1.300 raeburn 3613: } else {
3614: $newaccesstext->{$tool} = $oldaccesstext->{$tool};
3615: }
3616: }
3617: } else {
3618: my @curr = split(',',$userenv->{$context.'.'.$tool});
3619: my @new;
3620: my $changedoms;
1.314 raeburn 3621: foreach my $req (@curr) {
3622: if ($req =~ /^\Q$cdom\E\:($optregex\=?\d*)$/) {
3623: my $oldop = $1;
1.383 raeburn 3624: if ($oldop =~ /^autolimit=(\d*)/) {
3625: my $limit = $1;
3626: if ($limit) {
3627: $oldaccesstext->{$tool} = &mt('available with automatic approval, up to limit of [quant,_1,request] per user',$limit);
3628: } else {
3629: $oldaccesstext->{$tool} = &mt('available with automatic approval (unlimited)');
3630: }
3631: } else {
3632: $oldaccesstext->{$tool} = $reqdisplay{$oldop};
3633: }
1.314 raeburn 3634: if ($oldop ne $newop) {
3635: $changedoms = 1;
3636: foreach my $item (@curr) {
3637: my ($reqdom,$option) = split(':',$item);
3638: unless ($reqdom eq $cdom) {
3639: push(@new,$item);
3640: }
3641: }
3642: if ($newop) {
3643: push(@new,$cdom.':'.$newop);
1.300 raeburn 3644: }
1.314 raeburn 3645: @new = sort(@new);
1.300 raeburn 3646: }
1.314 raeburn 3647: last;
1.300 raeburn 3648: }
1.314 raeburn 3649: }
3650: if ((!$changedoms) && ($newop)) {
1.300 raeburn 3651: $changedoms = 1;
1.306 raeburn 3652: @new = sort(@curr,$cdom.':'.$newop);
1.300 raeburn 3653: }
3654: if ($changedoms) {
1.314 raeburn 3655: my $newdomstr;
1.300 raeburn 3656: if (@new) {
3657: $newdomstr = join(',',@new);
3658: }
3659: $changed->{$tool}=&tool_admin($tool,$newdomstr,$changeHash,
3660: $context);
3661: if ($changed->{$tool}) {
3662: if ($env{'form.'.$context.'_'.$tool}) {
1.306 raeburn 3663: if ($env{'form.'.$context.'_'.$tool} eq 'autolimit') {
1.314 raeburn 3664: my $limit = $env{'form.'.$context.'_'.$tool.'_limit'};
3665: $limit =~ s/\D+//g;
3666: if ($limit) {
1.383 raeburn 3667: $newaccesstext->{$tool} = &mt('available with automatic approval, up to limit of [quant,_1,request] per user',$limit);
1.314 raeburn 3668: } else {
1.383 raeburn 3669: $newaccesstext->{$tool} = &mt('available with automatic approval (unlimited)');
1.306 raeburn 3670: }
1.314 raeburn 3671: } else {
1.306 raeburn 3672: $newaccesstext->{$tool} = $reqdisplay{$env{'form.'.$context.'_'.$tool}};
3673: }
1.300 raeburn 3674: } else {
1.383 raeburn 3675: $newaccesstext->{$tool} = &mt("availability set to 'off'");
1.300 raeburn 3676: }
3677: }
3678: }
3679: }
3680: }
3681: return;
3682: }
1.275 raeburn 3683: foreach my $tool (@{$usertools}) {
1.383 raeburn 3684: my ($newval,$limit,$envkey);
1.362 raeburn 3685: $envkey = $context.'.'.$tool;
1.306 raeburn 3686: if ($context eq 'requestcourses') {
3687: $newval = $env{'form.crsreq_'.$tool};
3688: if ($newval eq 'autolimit') {
1.383 raeburn 3689: $limit = $env{'form.crsreq_'.$tool.'_limit'};
3690: $limit =~ s/\D+//g;
3691: $newval .= '='.$limit;
1.306 raeburn 3692: }
1.362 raeburn 3693: } elsif ($context eq 'requestauthor') {
3694: $newval = $env{'form.'.$context};
3695: $envkey = $context;
1.314 raeburn 3696: } else {
1.306 raeburn 3697: $newval = $env{'form.'.$context.'_'.$tool};
3698: }
1.362 raeburn 3699: if ($userenv->{$envkey} ne '') {
1.275 raeburn 3700: $oldaccess->{$tool} = &mt('custom');
1.383 raeburn 3701: if (($context eq 'requestcourses') || ($context eq 'requestauthor')) {
3702: if ($userenv->{$envkey} =~ /^autolimit=(\d*)$/) {
3703: my $currlimit = $1;
3704: if ($currlimit eq '') {
3705: $oldaccesstext->{$tool} = &mt('available with automatic approval (unlimited)');
3706: } else {
3707: $oldaccesstext->{$tool} = &mt('available with automatic approval, up to limit of [quant,_1,request] per user',$currlimit);
3708: }
3709: } elsif ($userenv->{$envkey}) {
3710: $oldaccesstext->{$tool} = $reqdisplay{$userenv->{$envkey}};
3711: } else {
3712: $oldaccesstext->{$tool} = &mt("availability set to 'off'");
3713: }
1.275 raeburn 3714: } else {
1.383 raeburn 3715: if ($userenv->{$envkey}) {
3716: $oldaccesstext->{$tool} = &mt("availability set to 'on'");
3717: } else {
3718: $oldaccesstext->{$tool} = &mt("availability set to 'off'");
3719: }
1.275 raeburn 3720: }
1.362 raeburn 3721: $changeHash->{$envkey} = $userenv->{$envkey};
1.275 raeburn 3722: if ($env{'form.custom'.$tool} == 1) {
1.362 raeburn 3723: if ($newval ne $userenv->{$envkey}) {
1.306 raeburn 3724: $changed->{$tool} = &tool_admin($tool,$newval,$changeHash,
3725: $context);
1.275 raeburn 3726: if ($changed->{$tool}) {
3727: $newaccess->{$tool} = &mt('custom');
1.383 raeburn 3728: if (($context eq 'requestcourses') || ($context eq 'requestauthor')) {
3729: if ($newval =~ /^autolimit/) {
3730: if ($limit) {
3731: $newaccesstext->{$tool} = &mt('available with automatic approval, up to limit of [quant,_1,request] per user',$limit);
3732: } else {
3733: $newaccesstext->{$tool} = &mt('available with automatic approval (unlimited)');
3734: }
3735: } elsif ($newval) {
3736: $newaccesstext->{$tool} = $reqdisplay{$newval};
3737: } else {
3738: $newaccesstext->{$tool} = &mt("availability set to 'off'");
3739: }
1.275 raeburn 3740: } else {
1.383 raeburn 3741: if ($newval) {
3742: $newaccesstext->{$tool} = &mt("availability set to 'on'");
3743: } else {
3744: $newaccesstext->{$tool} = &mt("availability set to 'off'");
3745: }
1.275 raeburn 3746: }
3747: } else {
3748: $newaccess->{$tool} = $oldaccess->{$tool};
1.383 raeburn 3749: if (($context eq 'requestcourses') || ($context eq 'requestauthor')) {
3750: if ($newval =~ /^autolimit/) {
3751: if ($limit) {
3752: $newaccesstext->{$tool} = &mt('available with automatic approval, up to limit of [quant,_1,request] per user',$limit);
3753: } else {
3754: $newaccesstext->{$tool} = &mt('available with automatic approval (unlimited)');
3755: }
3756: } elsif ($newval) {
3757: $newaccesstext->{$tool} = $reqdisplay{$newval};
3758: } else {
3759: $newaccesstext->{$tool} = &mt("availability set to 'off'");
3760: }
1.275 raeburn 3761: } else {
1.383 raeburn 3762: if ($userenv->{$context.'.'.$tool}) {
3763: $newaccesstext->{$tool} = &mt("availability set to 'on'");
3764: } else {
3765: $newaccesstext->{$tool} = &mt("availability set to 'off'");
3766: }
1.275 raeburn 3767: }
3768: }
3769: } else {
3770: $newaccess->{$tool} = $oldaccess->{$tool};
3771: $newaccesstext->{$tool} = $oldaccesstext->{$tool};
3772: }
3773: } else {
3774: $changed->{$tool} = &tool_admin($tool,'',$changeHash,$context);
3775: if ($changed->{$tool}) {
3776: $newaccess->{$tool} = &mt('default');
3777: } else {
3778: $newaccess->{$tool} = $oldaccess->{$tool};
1.383 raeburn 3779: if (($context eq 'requestcourses') || ($context eq 'requestauthor')) {
3780: if ($newval =~ /^autolimit/) {
3781: if ($limit) {
3782: $newaccesstext->{$tool} = &mt('available with automatic approval, up to limit of [quant,_1,request] per user',$limit);
3783: } else {
3784: $newaccesstext->{$tool} = &mt('available with automatic approval (unlimited)');
3785: }
3786: } elsif ($newval) {
3787: $newaccesstext->{$tool} = $reqdisplay{$newval};
3788: } else {
3789: $newaccesstext->{$tool} = &mt("availability set to 'off'");
3790: }
1.275 raeburn 3791: } else {
1.383 raeburn 3792: if ($userenv->{$context.'.'.$tool}) {
3793: $newaccesstext->{$tool} = &mt("availability set to 'on'");
3794: } else {
3795: $newaccesstext->{$tool} = &mt("availability set to 'off'");
3796: }
1.275 raeburn 3797: }
3798: }
3799: }
3800: } else {
3801: $oldaccess->{$tool} = &mt('default');
3802: if ($env{'form.custom'.$tool} == 1) {
1.306 raeburn 3803: $changed->{$tool} = &tool_admin($tool,$newval,$changeHash,
3804: $context);
1.275 raeburn 3805: if ($changed->{$tool}) {
3806: $newaccess->{$tool} = &mt('custom');
1.383 raeburn 3807: if (($context eq 'requestcourses') || ($context eq 'requestauthor')) {
3808: if ($newval =~ /^autolimit/) {
3809: if ($limit) {
3810: $newaccesstext->{$tool} = &mt('available with automatic approval, up to limit of [quant,_1,request] per user',$limit);
3811: } else {
3812: $newaccesstext->{$tool} = &mt('available with automatic approval (unlimited)');
3813: }
3814: } elsif ($newval) {
3815: $newaccesstext->{$tool} = $reqdisplay{$newval};
3816: } else {
3817: $newaccesstext->{$tool} = &mt("availability set to 'off'");
3818: }
1.275 raeburn 3819: } else {
1.383 raeburn 3820: if ($newval) {
3821: $newaccesstext->{$tool} = &mt("availability set to 'on'");
3822: } else {
3823: $newaccesstext->{$tool} = &mt("availability set to 'off'");
3824: }
1.275 raeburn 3825: }
3826: } else {
3827: $newaccess->{$tool} = $oldaccess->{$tool};
3828: }
3829: } else {
3830: $newaccess->{$tool} = $oldaccess->{$tool};
3831: }
3832: }
3833: }
3834: return;
3835: }
3836:
1.220 raeburn 3837: sub update_roles {
1.375 raeburn 3838: my ($r,$context,$showcredits) = @_;
1.4 www 3839: my $now=time;
1.225 raeburn 3840: my @rolechanges;
1.220 raeburn 3841: my %disallowed;
1.73 sakharuk 3842: $r->print('<h3>'.&mt('Modifying Roles').'</h3>');
1.404 raeburn 3843: foreach my $key (keys(%env)) {
1.135 raeburn 3844: next if (! $env{$key});
1.190 raeburn 3845: next if ($key eq 'form.action');
1.27 matthew 3846: # Revoke roles
1.135 raeburn 3847: if ($key=~/^form\.rev/) {
3848: if ($key=~/^form\.rev\:([^\_]+)\_([^\_\.]+)$/) {
1.64 www 3849: # Revoke standard role
1.170 albertel 3850: my ($scope,$role) = ($1,$2);
3851: my $result =
3852: &Apache::lonnet::revokerole($env{'form.ccdomain'},
3853: $env{'form.ccuname'},
1.239 raeburn 3854: $scope,$role,'','',$context);
1.367 golterma 3855: $r->print(&Apache::lonhtmlcommon::confirm_success(
1.369 bisitz 3856: &mt('Revoking [_1] in [_2]',
3857: &Apache::lonnet::plaintext($role),
1.372 raeburn 3858: &Apache::loncommon::show_role_extent($scope,$context,$role)),
1.369 bisitz 3859: $result ne "ok").'<br />');
3860: if ($result ne "ok") {
3861: $r->print(&mt('Error: [_1]',$result).'<br />');
3862: }
1.170 albertel 3863: if ($role eq 'st') {
1.202 raeburn 3864: my $result =
1.198 raeburn 3865: &Apache::lonuserutils::classlist_drop($scope,
3866: $env{'form.ccuname'},$env{'form.ccdomain'},
1.202 raeburn 3867: $now);
1.367 golterma 3868: $r->print(&Apache::lonhtmlcommon::confirm_success($result));
1.53 www 3869: }
1.225 raeburn 3870: if (!grep(/^\Q$role\E$/,@rolechanges)) {
3871: push(@rolechanges,$role);
3872: }
1.196 raeburn 3873: }
1.195 raeburn 3874: if ($key=~m{^form\.rev\:([^_]+)_cr\.cr/($match_domain)/($match_username)/(\w+)$}s) {
1.64 www 3875: # Revoke custom role
1.369 bisitz 3876: my $result = &Apache::lonnet::revokecustomrole(
3877: $env{'form.ccdomain'},$env{'form.ccuname'},$1,$2,$3,$4,'','',$context);
1.367 golterma 3878: $r->print(&Apache::lonhtmlcommon::confirm_success(
1.369 bisitz 3879: &mt('Revoking custom role [_1] by [_2] in [_3]',
1.372 raeburn 3880: $4,$3.':'.$2,&Apache::loncommon::show_role_extent($1,$context,'cr')),
1.369 bisitz 3881: $result ne 'ok').'<br />');
3882: if ($result ne "ok") {
3883: $r->print(&mt('Error: [_1]',$result).'<br />');
3884: }
1.225 raeburn 3885: if (!grep(/^cr$/,@rolechanges)) {
3886: push(@rolechanges,'cr');
3887: }
1.64 www 3888: }
1.135 raeburn 3889: } elsif ($key=~/^form\.del/) {
3890: if ($key=~/^form\.del\:([^\_]+)\_([^\_\.]+)$/) {
1.116 raeburn 3891: # Delete standard role
1.170 albertel 3892: my ($scope,$role) = ($1,$2);
3893: my $result =
3894: &Apache::lonnet::assignrole($env{'form.ccdomain'},
3895: $env{'form.ccuname'},
1.239 raeburn 3896: $scope,$role,$now,0,1,'',
3897: $context);
1.367 golterma 3898: $r->print(&Apache::lonhtmlcommon::confirm_success(
3899: &mt('Deleting [_1] in [_2]',
1.369 bisitz 3900: &Apache::lonnet::plaintext($role),
1.372 raeburn 3901: &Apache::loncommon::show_role_extent($scope,$context,$role)),
1.369 bisitz 3902: $result ne 'ok').'<br />');
3903: if ($result ne "ok") {
3904: $r->print(&mt('Error: [_1]',$result).'<br />');
3905: }
1.367 golterma 3906:
1.170 albertel 3907: if ($role eq 'st') {
1.202 raeburn 3908: my $result =
1.198 raeburn 3909: &Apache::lonuserutils::classlist_drop($scope,
3910: $env{'form.ccuname'},$env{'form.ccdomain'},
1.202 raeburn 3911: $now);
1.369 bisitz 3912: $r->print(&Apache::lonhtmlcommon::confirm_success($result));
1.81 albertel 3913: }
1.225 raeburn 3914: if (!grep(/^\Q$role\E$/,@rolechanges)) {
3915: push(@rolechanges,$role);
3916: }
1.116 raeburn 3917: }
1.139 albertel 3918: if ($key=~m{^form\.del\:([^_]+)_cr\.cr/($match_domain)/($match_username)/(\w+)$}) {
1.116 raeburn 3919: my ($url,$rdom,$rnam,$rolename) = ($1,$2,$3,$4);
3920: # Delete custom role
1.369 bisitz 3921: my $result =
3922: &Apache::lonnet::assigncustomrole($env{'form.ccdomain'},
3923: $env{'form.ccuname'},$url,$rdom,$rnam,$rolename,$now,
3924: 0,1,$context);
3925: $r->print(&Apache::lonhtmlcommon::confirm_success(&mt('Deleting custom role [_1] by [_2] in [_3]',
1.372 raeburn 3926: $rolename,$rnam.':'.$rdom,&Apache::loncommon::show_role_extent($1,$context,'cr')),
1.369 bisitz 3927: $result ne "ok").'<br />');
3928: if ($result ne "ok") {
3929: $r->print(&mt('Error: [_1]',$result).'<br />');
3930: }
1.367 golterma 3931:
1.225 raeburn 3932: if (!grep(/^cr$/,@rolechanges)) {
3933: push(@rolechanges,'cr');
3934: }
1.116 raeburn 3935: }
1.135 raeburn 3936: } elsif ($key=~/^form\.ren/) {
1.101 albertel 3937: my $udom = $env{'form.ccdomain'};
3938: my $uname = $env{'form.ccuname'};
1.116 raeburn 3939: # Re-enable standard role
1.135 raeburn 3940: if ($key=~/^form\.ren\:([^\_]+)\_([^\_\.]+)$/) {
1.89 raeburn 3941: my $url = $1;
3942: my $role = $2;
3943: my $logmsg;
3944: my $output;
3945: if ($role eq 'st') {
1.141 albertel 3946: if ($url =~ m-^/($match_domain)/($match_courseid)/?(\w*)$-) {
1.374 raeburn 3947: my ($cdom,$cnum,$csec) = ($1,$2,$3);
1.375 raeburn 3948: my $credits;
3949: if ($showcredits) {
3950: my $defaultcredits =
3951: &Apache::lonuserutils::get_defaultcredits($cdom,$cnum);
3952: $credits = &get_user_credits($defaultcredits,$cdom,$cnum);
3953: }
3954: my $result = &Apache::loncommon::commit_studentrole(\$logmsg,$udom,$uname,$url,$role,$now,0,$cdom,$cnum,$csec,$context,$credits);
1.220 raeburn 3955: if (($result =~ /^error/) || ($result eq 'not_in_class') || ($result eq 'unknown_course') || ($result eq 'refused')) {
1.223 raeburn 3956: if ($result eq 'refused' && $logmsg) {
3957: $output = $logmsg;
3958: } else {
1.369 bisitz 3959: $output = &mt('Error: [_1]',$result)."\n";
1.223 raeburn 3960: }
1.89 raeburn 3961: } else {
1.372 raeburn 3962: $output = &Apache::lonhtmlcommon::confirm_success(&mt('Assigning [_1] in [_2] starting [_3]',
3963: &Apache::lonnet::plaintext($role),
3964: &Apache::loncommon::show_role_extent($url,$context,'st'),
3965: &Apache::lonlocal::locallocaltime($now))).'<br />'.$logmsg.'<br />';
1.89 raeburn 3966: }
3967: }
3968: } else {
1.101 albertel 3969: my $result=&Apache::lonnet::assignrole($env{'form.ccdomain'},
1.239 raeburn 3970: $env{'form.ccuname'},$url,$role,0,$now,'','',
3971: $context);
1.367 golterma 3972: $output = &Apache::lonhtmlcommon::confirm_success(&mt('Re-enabling [_1] in [_2]',
1.372 raeburn 3973: &Apache::lonnet::plaintext($role),
3974: &Apache::loncommon::show_role_extent($url,$context,$role)),$result ne "ok").'<br />';
1.369 bisitz 3975: if ($result ne "ok") {
3976: $output .= &mt('Error: [_1]',$result).'<br />';
3977: }
3978: }
1.89 raeburn 3979: $r->print($output);
1.225 raeburn 3980: if (!grep(/^\Q$role\E$/,@rolechanges)) {
3981: push(@rolechanges,$role);
3982: }
1.113 raeburn 3983: }
1.116 raeburn 3984: # Re-enable custom role
1.139 albertel 3985: if ($key=~m{^form\.ren\:([^_]+)_cr\.cr/($match_domain)/($match_username)/(\w+)$}) {
1.116 raeburn 3986: my ($url,$rdom,$rnam,$rolename) = ($1,$2,$3,$4);
3987: my $result = &Apache::lonnet::assigncustomrole(
3988: $env{'form.ccdomain'}, $env{'form.ccuname'},
1.240 raeburn 3989: $url,$rdom,$rnam,$rolename,0,$now,undef,$context);
1.369 bisitz 3990: $r->print(&Apache::lonhtmlcommon::confirm_success(
3991: &mt('Re-enabling custom role [_1] by [_2] in [_3]',
1.372 raeburn 3992: $rolename,$rnam.':'.$rdom,&Apache::loncommon::show_role_extent($1,$context,'cr')),
1.369 bisitz 3993: $result ne "ok").'<br />');
3994: if ($result ne "ok") {
3995: $r->print(&mt('Error: [_1]',$result).'<br />');
3996: }
1.225 raeburn 3997: if (!grep(/^cr$/,@rolechanges)) {
3998: push(@rolechanges,'cr');
3999: }
1.116 raeburn 4000: }
1.135 raeburn 4001: } elsif ($key=~/^form\.act/) {
1.101 albertel 4002: my $udom = $env{'form.ccdomain'};
4003: my $uname = $env{'form.ccuname'};
1.141 albertel 4004: if ($key=~/^form\.act\_($match_domain)\_($match_courseid)\_cr_cr_($match_domain)_($match_username)_([^\_]+)$/) {
1.65 www 4005: # Activate a custom role
1.83 albertel 4006: my ($one,$two,$three,$four,$five)=($1,$2,$3,$4,$5);
4007: my $url='/'.$one.'/'.$two;
4008: my $full=$one.'_'.$two.'_cr_cr_'.$three.'_'.$four.'_'.$five;
1.65 www 4009:
1.101 albertel 4010: my $start = ( $env{'form.start_'.$full} ?
4011: $env{'form.start_'.$full} :
1.88 raeburn 4012: $now );
1.101 albertel 4013: my $end = ( $env{'form.end_'.$full} ?
4014: $env{'form.end_'.$full} :
1.88 raeburn 4015: 0 );
4016:
4017: # split multiple sections
4018: my %sections = ();
1.101 albertel 4019: my $num_sections = &build_roles($env{'form.sec_'.$full},\%sections,$5);
1.88 raeburn 4020: if ($num_sections == 0) {
1.240 raeburn 4021: $r->print(&Apache::loncommon::commit_customrole($udom,$uname,$url,$three,$four,$five,$start,$end,$context));
1.88 raeburn 4022: } else {
1.114 albertel 4023: my %curr_groups =
1.117 raeburn 4024: &Apache::longroup::coursegroups($one,$two);
1.404 raeburn 4025: foreach my $sec (sort {$a cmp $b} keys(%sections)) {
1.113 raeburn 4026: if (($sec eq 'none') || ($sec eq 'all') ||
4027: exists($curr_groups{$sec})) {
4028: $disallowed{$sec} = $url;
4029: next;
4030: }
4031: my $securl = $url.'/'.$sec;
1.240 raeburn 4032: $r->print(&Apache::loncommon::commit_customrole($udom,$uname,$securl,$three,$four,$five,$start,$end,$context));
1.88 raeburn 4033: }
4034: }
1.225 raeburn 4035: if (!grep(/^cr$/,@rolechanges)) {
4036: push(@rolechanges,'cr');
4037: }
1.142 raeburn 4038: } elsif ($key=~/^form\.act\_($match_domain)\_($match_name)\_([^\_]+)$/) {
1.27 matthew 4039: # Activate roles for sections with 3 id numbers
4040: # set start, end times, and the url for the class
1.83 albertel 4041: my ($one,$two,$three)=($1,$2,$3);
1.101 albertel 4042: my $start = ( $env{'form.start_'.$one.'_'.$two.'_'.$three} ?
4043: $env{'form.start_'.$one.'_'.$two.'_'.$three} :
1.27 matthew 4044: $now );
1.101 albertel 4045: my $end = ( $env{'form.end_'.$one.'_'.$two.'_'.$three} ?
4046: $env{'form.end_'.$one.'_'.$two.'_'.$three} :
1.27 matthew 4047: 0 );
1.83 albertel 4048: my $url='/'.$one.'/'.$two;
1.88 raeburn 4049: my $type = 'three';
4050: # split multiple sections
4051: my %sections = ();
1.101 albertel 4052: my $num_sections = &build_roles($env{'form.sec_'.$one.'_'.$two.'_'.$three},\%sections,$three);
1.375 raeburn 4053: my $credits;
4054: if ($three eq 'st') {
4055: if ($showcredits) {
4056: my $defaultcredits =
4057: &Apache::lonuserutils::get_defaultcredits($one,$two);
4058: $credits = $env{'form.credits_'.$one.'_'.$two.'_'.$three};
4059: $credits =~ s/[^\d\.]//g;
4060: if ($credits eq $defaultcredits) {
4061: undef($credits);
4062: }
4063: }
4064: }
1.88 raeburn 4065: if ($num_sections == 0) {
1.375 raeburn 4066: $r->print(&Apache::loncommon::commit_standardrole($udom,$uname,$url,$three,$start,$end,$one,$two,'',$context,$credits));
1.88 raeburn 4067: } else {
1.114 albertel 4068: my %curr_groups =
1.117 raeburn 4069: &Apache::longroup::coursegroups($one,$two);
1.88 raeburn 4070: my $emptysec = 0;
1.404 raeburn 4071: foreach my $sec (sort {$a cmp $b} keys(%sections)) {
1.88 raeburn 4072: $sec =~ s/\W//g;
1.113 raeburn 4073: if ($sec ne '') {
4074: if (($sec eq 'none') || ($sec eq 'all') ||
4075: exists($curr_groups{$sec})) {
4076: $disallowed{$sec} = $url;
4077: next;
4078: }
1.88 raeburn 4079: my $securl = $url.'/'.$sec;
1.375 raeburn 4080: $r->print(&Apache::loncommon::commit_standardrole($udom,$uname,$securl,$three,$start,$end,$one,$two,$sec,$context,$credits));
1.88 raeburn 4081: } else {
4082: $emptysec = 1;
4083: }
4084: }
4085: if ($emptysec) {
1.375 raeburn 4086: $r->print(&Apache::loncommon::commit_standardrole($udom,$uname,$url,$three,$start,$end,$one,$two,'',$context,$credits));
1.88 raeburn 4087: }
1.225 raeburn 4088: }
4089: if (!grep(/^\Q$three\E$/,@rolechanges)) {
4090: push(@rolechanges,$three);
4091: }
1.135 raeburn 4092: } elsif ($key=~/^form\.act\_([^\_]+)\_([^\_]+)$/) {
1.27 matthew 4093: # Activate roles for sections with two id numbers
4094: # set start, end times, and the url for the class
1.101 albertel 4095: my $start = ( $env{'form.start_'.$1.'_'.$2} ?
4096: $env{'form.start_'.$1.'_'.$2} :
1.27 matthew 4097: $now );
1.101 albertel 4098: my $end = ( $env{'form.end_'.$1.'_'.$2} ?
4099: $env{'form.end_'.$1.'_'.$2} :
1.27 matthew 4100: 0 );
1.225 raeburn 4101: my $one = $1;
4102: my $two = $2;
4103: my $url='/'.$one.'/';
1.88 raeburn 4104: # split multiple sections
4105: my %sections = ();
1.225 raeburn 4106: my $num_sections = &build_roles($env{'form.sec_'.$one.'_'.$two},\%sections,$two);
1.88 raeburn 4107: if ($num_sections == 0) {
1.240 raeburn 4108: $r->print(&Apache::loncommon::commit_standardrole($udom,$uname,$url,$two,$start,$end,$one,undef,'',$context));
1.88 raeburn 4109: } else {
4110: my $emptysec = 0;
1.404 raeburn 4111: foreach my $sec (sort {$a cmp $b} keys(%sections)) {
1.88 raeburn 4112: if ($sec ne '') {
4113: my $securl = $url.'/'.$sec;
1.240 raeburn 4114: $r->print(&Apache::loncommon::commit_standardrole($udom,$uname,$securl,$two,$start,$end,$one,undef,$sec,$context));
1.88 raeburn 4115: } else {
4116: $emptysec = 1;
4117: }
4118: }
4119: if ($emptysec) {
1.240 raeburn 4120: $r->print(&Apache::loncommon::commit_standardrole($udom,$uname,$url,$two,$start,$end,$one,undef,'',$context));
1.88 raeburn 4121: }
4122: }
1.225 raeburn 4123: if (!grep(/^\Q$two\E$/,@rolechanges)) {
4124: push(@rolechanges,$two);
4125: }
1.64 www 4126: } else {
1.190 raeburn 4127: $r->print('<p><span class="LC_error">'.&mt('ERROR').': '.&mt('Unknown command').' <tt>'.$key.'</tt></span></p><br />');
1.64 www 4128: }
1.113 raeburn 4129: foreach my $key (sort(keys(%disallowed))) {
1.274 bisitz 4130: $r->print('<p class="LC_warning">');
1.113 raeburn 4131: if (($key eq 'none') || ($key eq 'all')) {
1.274 bisitz 4132: $r->print(&mt('[_1] may not be used as the name for a section, as it is a reserved word.','<tt>'.$key.'</tt>'));
1.113 raeburn 4133: } else {
1.274 bisitz 4134: $r->print(&mt('[_1] may not be used as the name for a section, as it is the name of a course group.','<tt>'.$key.'</tt>'));
1.113 raeburn 4135: }
1.274 bisitz 4136: $r->print('</p><p>'
4137: .&mt('Please [_1]go back[_2] and choose a different section name.'
4138: ,'<a href="javascript:history.go(-1)'
4139: ,'</a>')
4140: .'</p><br />'
4141: );
1.113 raeburn 4142: }
4143: }
1.101 albertel 4144: } # End of foreach (keys(%env))
1.75 www 4145: # Flush the course logs so reverse user roles immediately updated
1.349 raeburn 4146: $r->register_cleanup(\&Apache::lonnet::flushcourselogs);
1.225 raeburn 4147: if (@rolechanges == 0) {
1.372 raeburn 4148: $r->print('<p>'.&mt('No roles to modify').'</p>');
1.193 raeburn 4149: }
1.225 raeburn 4150: return @rolechanges;
1.220 raeburn 4151: }
4152:
1.375 raeburn 4153: sub get_user_credits {
4154: my ($uname,$udom,$defaultcredits,$cdom,$cnum) = @_;
4155: if ($cdom eq '' || $cnum eq '') {
4156: return unless ($env{'request.course.id'});
4157: $cdom = $env{'course.'.$env{'request.course.id'}.'.domain'};
4158: $cnum = $env{'course.'.$env{'request.course.id'}.'.num'};
4159: }
4160: my $credits;
4161: my %currhash =
4162: &Apache::lonnet::get('classlist',[$uname.':'.$udom],$cdom,$cnum);
4163: if (keys(%currhash) > 0) {
4164: my @items = split(/:/,$currhash{$uname.':'.$udom});
4165: my $crdidx = &Apache::loncoursedata::CL_CREDITS() - 3;
4166: $credits = $items[$crdidx];
4167: $credits =~ s/[^\d\.]//g;
4168: }
4169: if ($credits eq $defaultcredits) {
4170: undef($credits);
4171: }
4172: return $credits;
4173: }
4174:
1.220 raeburn 4175: sub enroll_single_student {
1.375 raeburn 4176: my ($r,$uhome,$amode,$genpwd,$now,$newuser,$context,$crstype,
4177: $showcredits,$defaultcredits) = @_;
1.318 raeburn 4178: $r->print('<h3>');
4179: if ($crstype eq 'Community') {
4180: $r->print(&mt('Enrolling Member'));
4181: } else {
4182: $r->print(&mt('Enrolling Student'));
4183: }
4184: $r->print('</h3>');
1.220 raeburn 4185:
4186: # Remove non alphanumeric values from section
4187: $env{'form.sections'}=~s/\W//g;
4188:
1.375 raeburn 4189: my $credits;
4190: if (($showcredits) && ($env{'form.credits'} ne '')) {
4191: $credits = $env{'form.credits'};
4192: $credits =~ s/[^\d\.]//g;
4193: if ($credits ne '') {
4194: if ($credits eq $defaultcredits) {
4195: undef($credits);
4196: }
4197: }
4198: }
4199:
1.220 raeburn 4200: # Clean out any old student roles the user has in this class.
4201: &Apache::lonuserutils::modifystudent($env{'form.ccdomain'},
4202: $env{'form.ccuname'},$env{'request.course.id'},undef,$uhome);
4203: my ($startdate,$enddate) = &Apache::lonuserutils::get_dates_from_form();
4204: my $enroll_result =
4205: &Apache::lonnet::modify_student_enrollment($env{'form.ccdomain'},
4206: $env{'form.ccuname'},$env{'form.cid'},$env{'form.cfirstname'},
4207: $env{'form.cmiddlename'},$env{'form.clastname'},
4208: $env{'form.generation'},$env{'form.sections'},$enddate,
1.375 raeburn 4209: $startdate,'manual',undef,$env{'request.course.id'},'',$context,
4210: $credits);
1.220 raeburn 4211: if ($enroll_result =~ /^ok/) {
1.381 bisitz 4212: $r->print(&mt('[_1] enrolled','<b>'.$env{'form.ccuname'}.':'.$env{'form.ccdomain'}.'</b>'));
1.220 raeburn 4213: if ($env{'form.sections'} ne '') {
4214: $r->print(' '.&mt('in section [_1]',$env{'form.sections'}));
4215: }
4216: my ($showstart,$showend);
4217: if ($startdate <= $now) {
4218: $showstart = &mt('Access starts immediately');
4219: } else {
4220: $showstart = &mt('Access starts: ').&Apache::lonlocal::locallocaltime($startdate);
4221: }
4222: if ($enddate == 0) {
4223: $showend = &mt('ends: no ending date');
4224: } else {
4225: $showend = &mt('ends: ').&Apache::lonlocal::locallocaltime($enddate);
4226: }
4227: $r->print('.<br />'.$showstart.'; '.$showend);
4228: if ($startdate <= $now && !$newuser) {
1.386 bisitz 4229: $r->print('<p class="LC_info">');
1.318 raeburn 4230: if ($crstype eq 'Community') {
1.392 raeburn 4231: $r->print(&mt('If the member is currently logged-in to LON-CAPA, the new role can be displayed by using the "Check for changes" link on the Roles/Courses page.'));
1.318 raeburn 4232: } else {
1.392 raeburn 4233: $r->print(&mt('If the student is currently logged-in to LON-CAPA, the new role can be displayed by using the "Check for changes" link on the Roles/Courses page.'));
1.318 raeburn 4234: }
4235: $r->print('</p>');
1.220 raeburn 4236: }
4237: } else {
4238: $r->print(&mt('unable to enroll').": ".$enroll_result);
4239: }
4240: return;
1.188 raeburn 4241: }
4242:
1.204 raeburn 4243: sub get_defaultquota_text {
4244: my ($settingstatus) = @_;
4245: my $defquotatext;
4246: if ($settingstatus eq '') {
1.383 raeburn 4247: $defquotatext = &mt('default');
1.204 raeburn 4248: } else {
4249: my ($usertypes,$order) =
4250: &Apache::lonnet::retrieve_inst_usertypes($env{'form.ccdomain'});
4251: if ($usertypes->{$settingstatus} eq '') {
1.383 raeburn 4252: $defquotatext = &mt('default');
1.204 raeburn 4253: } else {
1.383 raeburn 4254: $defquotatext = &mt('default for [_1]',$usertypes->{$settingstatus});
1.204 raeburn 4255: }
4256: }
4257: return $defquotatext;
4258: }
4259:
1.188 raeburn 4260: sub update_result_form {
4261: my ($uhome) = @_;
4262: my $outcome =
1.367 golterma 4263: '<form name="userupdate" method="post" action="">'."\n";
1.160 raeburn 4264: foreach my $item ('srchby','srchin','srchtype','srchterm','srchdomain','ccuname','ccdomain') {
1.188 raeburn 4265: $outcome .= '<input type="hidden" name="'.$item.'" value="'.$env{'form.'.$item}.'" />'."\n";
1.160 raeburn 4266: }
1.207 raeburn 4267: if ($env{'form.origname'} ne '') {
4268: $outcome .= '<input type="hidden" name="origname" value="'.$env{'form.origname'}.'" />'."\n";
4269: }
1.160 raeburn 4270: foreach my $item ('sortby','seluname','seludom') {
4271: if (exists($env{'form.'.$item})) {
1.188 raeburn 4272: $outcome .= '<input type="hidden" name="'.$item.'" value="'.$env{'form.'.$item}.'" />'."\n";
1.160 raeburn 4273: }
4274: }
1.188 raeburn 4275: if ($uhome eq 'no_host') {
4276: $outcome .= '<input type="hidden" name="forcenewuser" value="1" />'."\n";
4277: }
4278: $outcome .= '<input type="hidden" name="phase" value="" />'."\n".
1.383 raeburn 4279: '<input type="hidden" name="currstate" value="" />'."\n".
4280: '<input type="hidden" name="action" value="'.$env{'form.action'}.'" />'."\n".
1.188 raeburn 4281: '</form>';
4282: return $outcome;
1.4 www 4283: }
4284:
1.149 raeburn 4285: sub quota_admin {
1.378 raeburn 4286: my ($setquota,$changeHash,$name) = @_;
1.149 raeburn 4287: my $quotachanged;
4288: if (&Apache::lonnet::allowed('mpq',$env{'form.ccdomain'})) {
4289: # Current user has quota modification privileges
1.267 raeburn 4290: if (ref($changeHash) eq 'HASH') {
4291: $quotachanged = 1;
1.378 raeburn 4292: $changeHash->{$name.'quota'} = $setquota;
1.267 raeburn 4293: }
1.149 raeburn 4294: }
4295: return $quotachanged;
4296: }
4297:
1.267 raeburn 4298: sub tool_admin {
1.275 raeburn 4299: my ($tool,$settool,$changeHash,$context) = @_;
4300: my $canchange = 0;
1.279 raeburn 4301: if ($context eq 'requestcourses') {
1.275 raeburn 4302: if (&Apache::lonnet::allowed('ccc',$env{'form.ccdomain'})) {
4303: $canchange = 1;
4304: }
1.300 raeburn 4305: } elsif ($context eq 'reqcrsotherdom') {
4306: if (&Apache::lonnet::allowed('ccc',$env{'request.role.domain'})) {
4307: $canchange = 1;
4308: }
1.362 raeburn 4309: } elsif ($context eq 'requestauthor') {
4310: if (&Apache::lonnet::allowed('cau',$env{'request.role.domain'})) {
4311: $canchange = 1;
4312: }
1.275 raeburn 4313: } elsif (&Apache::lonnet::allowed('mut',$env{'form.ccdomain'})) {
4314: # Current user has quota modification privileges
4315: $canchange = 1;
4316: }
1.267 raeburn 4317: my $toolchanged;
1.275 raeburn 4318: if ($canchange) {
1.267 raeburn 4319: if (ref($changeHash) eq 'HASH') {
4320: $toolchanged = 1;
1.362 raeburn 4321: if ($tool eq 'requestauthor') {
4322: $changeHash->{$context} = $settool;
4323: } else {
4324: $changeHash->{$context.'.'.$tool} = $settool;
4325: }
1.267 raeburn 4326: }
4327: }
4328: return $toolchanged;
4329: }
4330:
1.88 raeburn 4331: sub build_roles {
1.89 raeburn 4332: my ($sectionstr,$sections,$role) = @_;
1.88 raeburn 4333: my $num_sections = 0;
4334: if ($sectionstr=~ /,/) {
4335: my @secnums = split/,/,$sectionstr;
1.89 raeburn 4336: if ($role eq 'st') {
4337: $secnums[0] =~ s/\W//g;
4338: $$sections{$secnums[0]} = 1;
4339: $num_sections = 1;
4340: } else {
4341: foreach my $sec (@secnums) {
4342: $sec =~ ~s/\W//g;
1.150 banghart 4343: if (!($sec eq "")) {
1.89 raeburn 4344: if (exists($$sections{$sec})) {
4345: $$sections{$sec} ++;
4346: } else {
4347: $$sections{$sec} = 1;
4348: $num_sections ++;
4349: }
1.88 raeburn 4350: }
4351: }
4352: }
4353: } else {
4354: $sectionstr=~s/\W//g;
4355: unless ($sectionstr eq '') {
4356: $$sections{$sectionstr} = 1;
4357: $num_sections ++;
4358: }
4359: }
1.129 albertel 4360:
1.88 raeburn 4361: return $num_sections;
4362: }
4363:
1.58 www 4364: # ========================================================== Custom Role Editor
4365:
4366: sub custom_role_editor {
1.439 raeburn 4367: my ($r,$context,$brcrum,$prefix,$permission) = @_;
1.324 raeburn 4368: my $action = $env{'form.customroleaction'};
1.439 raeburn 4369: my ($rolename,$helpitem);
1.324 raeburn 4370: if ($action eq 'new') {
4371: $rolename=$env{'form.newrolename'};
4372: } else {
4373: $rolename=$env{'form.rolename'};
1.59 www 4374: }
4375:
1.324 raeburn 4376: my ($crstype,$context);
4377: if ($env{'request.course.id'}) {
4378: $crstype = &Apache::loncommon::course_type();
4379: $context = 'course';
1.439 raeburn 4380: $helpitem = 'Course_Editing_Custom_Roles';
1.324 raeburn 4381: } else {
4382: $context = 'domain';
1.414 raeburn 4383: $crstype = 'course';
1.439 raeburn 4384: $helpitem = 'Domain_Editing_Custom_Roles';
1.324 raeburn 4385: }
1.351 raeburn 4386:
4387: $rolename=~s/[^A-Za-z0-9]//gs;
4388: if (!$rolename || $env{'form.phase'} eq 'pickrole') {
1.439 raeburn 4389: &print_username_entry_form($r,$context,undef,undef,undef,$crstype,$brcrum,
4390: $permission);
1.351 raeburn 4391: return;
4392: }
4393:
1.414 raeburn 4394: my $formname = 'form1';
4395: my %privs=();
4396: my $body_top = '<h2>';
4397: # ------------------------------------------------------- Does this role exist?
1.59 www 4398: my ($rdummy,$roledef)=
4399: &Apache::lonnet::get('roles',["rolesdef_$rolename"]);
4400: if (($rdummy ne 'con_lost') && ($roledef ne '')) {
1.414 raeburn 4401: $body_top .= &mt('Existing Role').' "';
1.61 www 4402: # ------------------------------------------------- Get current role privileges
1.414 raeburn 4403: ($privs{'system'},$privs{'domain'},$privs{'course'})=split(/\_/,$roledef);
4404: if ($privs{'system'} =~ /bre\&S/) {
4405: if ($context eq 'domain') {
1.417 raeburn 4406: $crstype = 'Course';
1.414 raeburn 4407: } elsif ($crstype eq 'Community') {
4408: $privs{'system'} =~ s/bre\&S//;
4409: }
4410: } elsif ($context eq 'domain') {
4411: $crstype = 'Course';
1.324 raeburn 4412: }
1.59 www 4413: } else {
1.414 raeburn 4414: $body_top .= &mt('New Role').' "';
4415: $roledef='';
1.59 www 4416: }
1.153 banghart 4417: $body_top .= $rolename.'"</h2>';
1.414 raeburn 4418:
4419: # ------------------------------------------------------- What can be assigned?
4420: my %full=();
1.417 raeburn 4421: my %levels=(
1.414 raeburn 4422: course => {},
4423: domain => {},
4424: system => {},
4425: );
4426: my %levelscurrent=(
4427: course => {},
4428: domain => {},
4429: system => {},
4430: );
4431: &Apache::lonuserutils::custom_role_privs(\%privs,\%full,\%levels,\%levelscurrent);
1.160 raeburn 4432: my ($jsback,$elements) = &crumb_utilities();
1.414 raeburn 4433: my @templateroles = &Apache::lonuserutils::custom_template_roles($context,$crstype);
1.417 raeburn 4434: my $head_script =
1.414 raeburn 4435: &Apache::lonuserutils::custom_roledefs_js($context,$crstype,$formname,
4436: \%full,\@templateroles,$jsback);
1.351 raeburn 4437: push (@{$brcrum},
1.414 raeburn 4438: {href => "javascript:backPage(document.$formname,'pickrole','')",
1.351 raeburn 4439: text => "Pick custom role",
4440: faq => 282,bug=>'Instructor Interface',},
1.414 raeburn 4441: {href => "javascript:backPage(document.$formname,'','')",
1.351 raeburn 4442: text => "Edit custom role",
4443: faq => 282,
4444: bug => 'Instructor Interface',
1.439 raeburn 4445: help => $helpitem}
1.351 raeburn 4446: );
4447: my $args = { bread_crumbs => $brcrum,
4448: bread_crumbs_component => 'User Management'};
4449: $r->print(&Apache::loncommon::start_page('Custom Role Editor',
4450: $head_script,$args).
4451: $body_top);
1.414 raeburn 4452: $r->print('<form name="'.$formname.'" method="post" action="">'."\n".
4453: &Apache::lonuserutils::custom_role_header($context,$crstype,
4454: \@templateroles,$prefix));
1.264 bisitz 4455:
1.61 www 4456: $r->print(<<ENDCCF);
4457: <input type="hidden" name="phase" value="set_custom_roles" />
4458: <input type="hidden" name="rolename" value="$rolename" />
4459: ENDCCF
1.414 raeburn 4460: $r->print(&Apache::lonuserutils::custom_role_table($crstype,\%full,\%levels,
4461: \%levelscurrent,$prefix));
1.135 raeburn 4462: $r->print(&Apache::loncommon::end_data_table().
1.190 raeburn 4463: '<input type="hidden" name="action" value="'.$env{'form.action'}.'" />'.
1.160 raeburn 4464: '<input type="hidden" name="startrolename" value="'.$env{'form.rolename'}.
1.417 raeburn 4465: '" />'."\n".'<input type="hidden" name="currstate" value="" />'."\n".
1.160 raeburn 4466: '<input type="reset" value="'.&mt("Reset").'" />'."\n".
1.351 raeburn 4467: '<input type="submit" value="'.&mt('Save').'" /></form>');
1.61 www 4468: }
1.414 raeburn 4469:
1.61 www 4470: # ---------------------------------------------------------- Call to definerole
4471: sub set_custom_role {
1.439 raeburn 4472: my ($r,$context,$brcrum,$prefix,$permission) = @_;
1.101 albertel 4473: my $rolename=$env{'form.rolename'};
1.63 www 4474: $rolename=~s/[^A-Za-z0-9]//gs;
1.150 banghart 4475: if (!$rolename) {
1.439 raeburn 4476: &custom_role_editor($r,$context,$brcrum,$prefix,$permission);
1.61 www 4477: return;
4478: }
1.160 raeburn 4479: my ($jsback,$elements) = &crumb_utilities();
1.301 bisitz 4480: my $jscript = '<script type="text/javascript">'
4481: .'// <![CDATA['."\n"
4482: .$jsback."\n"
4483: .'// ]]>'."\n"
4484: .'</script>'."\n";
1.439 raeburn 4485: my $helpitem = 'Course_Editing_Custom_Roles';
4486: if ($context eq 'domain') {
4487: $helpitem = 'Domain_Editing_Custom_Roles';
4488: }
1.352 raeburn 4489: push(@{$brcrum},
4490: {href => "javascript:backPage(document.customresult,'pickrole','')",
4491: text => "Pick custom role",
4492: faq => 282,
4493: bug => 'Instructor Interface',},
4494: {href => "javascript:backPage(document.customresult,'selected_custom_edit','')",
4495: text => "Edit custom role",
4496: faq => 282,
4497: bug => 'Instructor Interface',},
4498: {href => "javascript:backPage(document.customresult,'set_custom_roles','')",
4499: text => "Result",
4500: faq => 282,
4501: bug => 'Instructor Interface',
1.439 raeburn 4502: help => $helpitem,}
1.352 raeburn 4503: );
4504: my $args = { bread_crumbs => $brcrum,
1.414 raeburn 4505: bread_crumbs_component => 'User Management'};
1.351 raeburn 4506: $r->print(&Apache::loncommon::start_page('Save Custom Role',$jscript,$args));
1.160 raeburn 4507:
1.393 raeburn 4508: my $newrole;
1.61 www 4509: my ($rdummy,$roledef)=
1.110 albertel 4510: &Apache::lonnet::get('roles',["rolesdef_$rolename"]);
4511:
1.61 www 4512: # ------------------------------------------------------- Does this role exist?
1.188 raeburn 4513: $r->print('<h3>');
1.61 www 4514: if (($rdummy ne 'con_lost') && ($roledef ne '')) {
1.73 sakharuk 4515: $r->print(&mt('Existing Role').' "');
1.61 www 4516: } else {
1.73 sakharuk 4517: $r->print(&mt('New Role').' "');
1.61 www 4518: $roledef='';
1.393 raeburn 4519: $newrole = 1;
1.61 www 4520: }
1.188 raeburn 4521: $r->print($rolename.'"</h3>');
1.414 raeburn 4522: # ------------------------------------------------- Assign role and show result
1.61 www 4523:
1.387 bisitz 4524: my $errmsg;
1.414 raeburn 4525: my %newprivs = &Apache::lonuserutils::custom_role_update($rolename,$prefix);
4526: # Assign role and return result
4527: my $result = &Apache::lonnet::definerole($rolename,$newprivs{'s'},$newprivs{'d'},
4528: $newprivs{'c'});
1.387 bisitz 4529: if ($result ne 'ok') {
4530: $errmsg = ': '.$result;
4531: }
4532: my $message =
4533: &Apache::lonhtmlcommon::confirm_success(
4534: &mt('Defining Role').$errmsg, ($result eq 'ok' ? 0 : 1));
1.101 albertel 4535: if ($env{'request.course.id'}) {
4536: my $url='/'.$env{'request.course.id'};
1.63 www 4537: $url=~s/\_/\//g;
1.387 bisitz 4538: $result =
4539: &Apache::lonnet::assigncustomrole(
4540: $env{'user.domain'},$env{'user.name'},
4541: $url,
4542: $env{'user.domain'},$env{'user.name'},
4543: $rolename,undef,undef,undef,$context);
4544: if ($result ne 'ok') {
4545: $errmsg = ': '.$result;
4546: }
4547: $message .=
4548: '<br />'
4549: .&Apache::lonhtmlcommon::confirm_success(
4550: &mt('Assigning Role to Self').$errmsg, ($result eq 'ok' ? 0 : 1));
1.63 www 4551: }
1.380 bisitz 4552: $r->print(
1.387 bisitz 4553: &Apache::loncommon::confirmwrapper($message)
4554: .'<br />'
4555: .&Apache::lonhtmlcommon::actionbox([
4556: '<a href="javascript:backPage(document.customresult,'."'pickrole'".')">'
4557: .&mt('Create or edit another custom role')
4558: .'</a>'])
1.380 bisitz 4559: .'<form name="customresult" method="post" action="">'
1.387 bisitz 4560: .&Apache::lonhtmlcommon::echo_form_input([])
4561: .'</form>'
1.380 bisitz 4562: );
1.58 www 4563: }
4564:
1.2 www 4565: # ================================================================ Main Handler
4566: sub handler {
4567: my $r = shift;
4568: if ($r->header_only) {
1.68 www 4569: &Apache::loncommon::content_type($r,'text/html');
1.2 www 4570: $r->send_http_header;
4571: return OK;
4572: }
1.439 raeburn 4573: my ($context,$crstype,$cid,$cnum,$cdom,$allhelpitems);
4574:
1.190 raeburn 4575: if ($env{'request.course.id'}) {
4576: $context = 'course';
1.318 raeburn 4577: $crstype = &Apache::loncommon::course_type();
1.190 raeburn 4578: } elsif ($env{'request.role'} =~ /^au\./) {
1.206 raeburn 4579: $context = 'author';
1.190 raeburn 4580: } else {
4581: $context = 'domain';
4582: }
1.375 raeburn 4583:
1.439 raeburn 4584: my ($permission,$allowed) =
4585: &Apache::lonuserutils::get_permission($context,$crstype);
4586:
4587: if ($allowed) {
4588: my @allhelp;
4589: if ($context eq 'course') {
4590: $cid = $env{'request.course.id'};
4591: $cdom = $env{'course.'.$cid.'.domain'};
4592: $cnum = $env{'course.'.$cid.'.num'};
4593:
4594: if ($permission->{'cusr'}) {
4595: push(@allhelp,'Course_Create_Class_List');
4596: }
4597: if ($permission->{'view'} || $permission->{'cusr'}) {
4598: push(@allhelp,('Course_Change_Privileges','Course_View_Class_List'));
4599: }
4600: if ($permission->{'custom'}) {
4601: push(@allhelp,'Course_Editing_Custom_Roles');
4602: }
4603: if ($permission->{'cusr'}) {
4604: push(@allhelp,('Course_Add_Student','Course_Drop_Student'));
4605: }
4606: unless ($permission->{'cusr_section'}) {
4607: if (&Apache::lonnet::auto_run($cnum,$cdom) && (($permission->{'cusr'}) || ($permission->{'view'}))) {
4608: push(@allhelp,'Course_Automated_Enrollment');
4609: }
4610: if ($permission->{'selfenrolladmin'}) {
4611: push(@allhelp,'Course_Approve_Selfenroll');
4612: }
4613: }
4614: if ($permission->{'grp_manage'}) {
4615: push(@allhelp,'Course_Manage_Group');
4616: }
4617: if ($permission->{'view'} || $permission->{'cusr'}) {
4618: push(@allhelp,'Course_User_Logs');
4619: }
4620: } elsif ($context eq 'author') {
4621: push(@allhelp,('Author_Change_Privileges','Author_Create_Coauthor_List',
4622: 'Author_View_Coauthor_List','Author_User_Logs'));
4623: } else {
4624: if ($permission->{'cusr'}) {
4625: push(@allhelp,'Domain_Change_Privileges');
4626: if ($permission->{'activity'}) {
4627: push(@allhelp,'Domain_User_Access_Logs');
4628: }
4629: push(@allhelp,('Domain_Create_Users','Domain_View_Users_List'));
4630: if ($permission->{'custom'}) {
4631: push(@allhelp,'Domain_Editing_Custom_Roles');
4632: }
4633: push(@allhelp,('Domain_Role_Approvals','Domain_Username_Approvals','Domain_Change_Logs'));
4634: } elsif ($permission->{'view'}) {
4635: push(@allhelp,'Domain_View_Privileges');
4636: if ($permission->{'activity'}) {
4637: push(@allhelp,'Domain_User_Access_Logs');
4638: }
4639: push(@allhelp,('Domain_View_Users_List','Domain_Change_Logs'));
4640: }
4641: }
4642: if (@allhelp) {
4643: $allhelpitems = join(',',@allhelp);
4644: }
4645: }
4646:
1.190 raeburn 4647: &Apache::loncommon::get_unprocessed_cgi($ENV{'QUERY_STRING'},
1.233 raeburn 4648: ['action','state','callingform','roletype','showrole','bulkaction','popup','phase',
1.391 raeburn 4649: 'username','domain','srchterm','srchdomain','srchin','srchby','srchtype','queue']);
1.190 raeburn 4650: &Apache::lonhtmlcommon::clear_breadcrumbs();
1.351 raeburn 4651: my $args;
4652: my $brcrum = [];
4653: my $bread_crumbs_component = 'User Management';
1.391 raeburn 4654: if (($env{'form.action'} ne 'dateselect') && ($env{'form.action'} ne 'displayuserreq')) {
1.351 raeburn 4655: $brcrum = [{href=>"/adm/createuser",
4656: text=>"User Management",
1.439 raeburn 4657: help=>$allhelpitems}
1.351 raeburn 4658: ];
1.202 raeburn 4659: }
1.190 raeburn 4660: if (!$allowed) {
1.358 raeburn 4661: if ($context eq 'course') {
4662: $r->internal_redirect('/adm/viewclasslist');
4663: return OK;
4664: }
1.190 raeburn 4665: $env{'user.error.msg'}=
4666: "/adm/createuser:cst:0:0:Cannot create/modify user data ".
4667: "or view user status.";
4668: return HTTP_NOT_ACCEPTABLE;
4669: }
4670:
4671: &Apache::loncommon::content_type($r,'text/html');
4672: $r->send_http_header;
4673:
1.375 raeburn 4674: my $showcredits;
4675: if ((($context eq 'course') && ($crstype eq 'Course')) ||
4676: ($context eq 'domain')) {
4677: my %domdefaults =
4678: &Apache::lonnet::get_domain_defaults($env{'request.role.domain'});
4679: if ($domdefaults{'officialcredits'} || $domdefaults{'unofficialcredits'}) {
4680: $showcredits = 1;
4681: }
4682: }
4683:
1.190 raeburn 4684: # Main switch on form.action and form.state, as appropriate
4685: if (! exists($env{'form.action'})) {
1.351 raeburn 4686: $args = {bread_crumbs => $brcrum,
4687: bread_crumbs_component => $bread_crumbs_component};
4688: $r->print(&header(undef,$args));
1.318 raeburn 4689: $r->print(&print_main_menu($permission,$context,$crstype));
1.190 raeburn 4690: } elsif ($env{'form.action'} eq 'upload' && $permission->{'cusr'}) {
1.439 raeburn 4691: my $helpitem = 'Course_Create_Class_List';
4692: if ($context eq 'author') {
4693: $helpitem = 'Author_Create_Coauthor_List';
4694: } elsif ($context eq 'domain') {
4695: $helpitem = 'Domain_Create_Users';
4696: }
1.351 raeburn 4697: push(@{$brcrum},
4698: { href => '/adm/createuser?action=upload&state=',
4699: text => 'Upload Users List',
1.439 raeburn 4700: help => $helpitem,
1.351 raeburn 4701: });
4702: $bread_crumbs_component = 'Upload Users List';
4703: $args = {bread_crumbs => $brcrum,
4704: bread_crumbs_component => $bread_crumbs_component};
4705: $r->print(&header(undef,$args));
1.190 raeburn 4706: $r->print('<form name="studentform" method="post" '.
4707: 'enctype="multipart/form-data" '.
4708: ' action="/adm/createuser">'."\n");
4709: if (! exists($env{'form.state'})) {
4710: &Apache::lonuserutils::print_first_users_upload_form($r,$context);
4711: } elsif ($env{'form.state'} eq 'got_file') {
1.375 raeburn 4712: &Apache::lonuserutils::print_upload_manager_form($r,$context,$permission,
4713: $crstype,$showcredits);
1.190 raeburn 4714: } elsif ($env{'form.state'} eq 'enrolling') {
4715: if ($env{'form.datatoken'}) {
1.375 raeburn 4716: &Apache::lonuserutils::upfile_drop_add($r,$context,$permission,
4717: $showcredits);
1.190 raeburn 4718: }
4719: } else {
4720: &Apache::lonuserutils::print_first_users_upload_form($r,$context);
4721: }
1.416 raeburn 4722: } elsif (((($env{'form.action'} eq 'singleuser') || ($env{'form.action'}
4723: eq 'singlestudent')) && ($permission->{'cusr'})) ||
1.418 raeburn 4724: (($env{'form.action'} eq 'singleuser') && ($permission->{'view'})) ||
1.416 raeburn 4725: (($env{'form.action'} eq 'accesslogs') && ($permission->{'activity'}))) {
1.190 raeburn 4726: my $phase = $env{'form.phase'};
4727: my @search = ('srchterm','srchby','srchin','srchtype','srchdomain');
1.192 albertel 4728: &Apache::loncreateuser::restore_prev_selections();
4729: my $srch;
4730: foreach my $item (@search) {
4731: $srch->{$item} = $env{'form.'.$item};
4732: }
1.207 raeburn 4733: if (($phase eq 'get_user_info') || ($phase eq 'userpicked') ||
1.416 raeburn 4734: ($phase eq 'createnewuser') || ($phase eq 'activity')) {
1.207 raeburn 4735: if ($env{'form.phase'} eq 'createnewuser') {
4736: my $response;
4737: if ($env{'form.srchterm'} !~ /^$match_username$/) {
1.366 bisitz 4738: my $response =
4739: '<span class="LC_warning">'
4740: .&mt('You must specify a valid username. Only the following are allowed:'
4741: .' letters numbers - . @')
4742: .'</span>';
1.221 raeburn 4743: $env{'form.phase'} = '';
1.375 raeburn 4744: &print_username_entry_form($r,$context,$response,$srch,undef,
1.439 raeburn 4745: $crstype,$brcrum,$permission);
1.207 raeburn 4746: } else {
4747: my $ccuname =&LONCAPA::clean_username($srch->{'srchterm'});
4748: my $ccdomain=&LONCAPA::clean_domain($srch->{'srchdomain'});
4749: &print_user_modification_page($r,$ccuname,$ccdomain,
1.221 raeburn 4750: $srch,$response,$context,
1.375 raeburn 4751: $permission,$crstype,$brcrum,
4752: $showcredits);
1.207 raeburn 4753: }
4754: } elsif ($env{'form.phase'} eq 'get_user_info') {
1.190 raeburn 4755: my ($currstate,$response,$forcenewuser,$results) =
1.221 raeburn 4756: &user_search_result($context,$srch);
1.190 raeburn 4757: if ($env{'form.currstate'} eq 'modify') {
4758: $currstate = $env{'form.currstate'};
4759: }
4760: if ($currstate eq 'select') {
4761: &print_user_selection_page($r,$response,$srch,$results,
1.351 raeburn 4762: \@search,$context,undef,$crstype,
4763: $brcrum);
1.416 raeburn 4764: } elsif (($currstate eq 'modify') || ($env{'form.action'} eq 'accesslogs')) {
4765: my ($ccuname,$ccdomain,$uhome);
1.190 raeburn 4766: if (($srch->{'srchby'} eq 'uname') &&
4767: ($srch->{'srchtype'} eq 'exact')) {
4768: $ccuname = $srch->{'srchterm'};
4769: $ccdomain= $srch->{'srchdomain'};
4770: } else {
4771: my @matchedunames = keys(%{$results});
4772: ($ccuname,$ccdomain) = split(/:/,$matchedunames[0]);
4773: }
4774: $ccuname =&LONCAPA::clean_username($ccuname);
4775: $ccdomain=&LONCAPA::clean_domain($ccdomain);
1.416 raeburn 4776: if ($env{'form.action'} eq 'accesslogs') {
4777: my $uhome;
4778: if (($ccuname ne '') && ($ccdomain ne '')) {
4779: $uhome = &Apache::lonnet::homeserver($ccuname,$ccdomain);
4780: }
4781: if (($uhome eq '') || ($uhome eq 'no_host')) {
4782: $env{'form.phase'} = '';
4783: undef($forcenewuser);
4784: #if ($response) {
4785: # unless ($response =~ m{\Q<br /><br />\E$}) {
4786: # $response .= '<br /><br />';
4787: # }
4788: #}
4789: &print_username_entry_form($r,$context,$response,$srch,
1.439 raeburn 4790: $forcenewuser,$crstype,$brcrum,
4791: $permission);
1.416 raeburn 4792: } else {
4793: &print_useraccesslogs_display($r,$ccuname,$ccdomain,$permission,$brcrum);
4794: }
4795: } else {
4796: if ($env{'form.forcenewuser'}) {
4797: $response = '';
4798: }
4799: &print_user_modification_page($r,$ccuname,$ccdomain,
4800: $srch,$response,$context,
4801: $permission,$crstype,$brcrum);
1.190 raeburn 4802: }
4803: } elsif ($currstate eq 'query') {
1.351 raeburn 4804: &print_user_query_page($r,'createuser',$brcrum);
1.190 raeburn 4805: } else {
1.229 raeburn 4806: $env{'form.phase'} = '';
1.207 raeburn 4807: &print_username_entry_form($r,$context,$response,$srch,
1.439 raeburn 4808: $forcenewuser,$crstype,$brcrum,
4809: $permission);
1.190 raeburn 4810: }
4811: } elsif ($env{'form.phase'} eq 'userpicked') {
4812: my $ccuname = &LONCAPA::clean_username($env{'form.seluname'});
4813: my $ccdomain = &LONCAPA::clean_domain($env{'form.seludom'});
1.416 raeburn 4814: if ($env{'form.action'} eq 'accesslogs') {
4815: &print_useraccesslogs_display($r,$ccuname,$ccdomain,$permission,$brcrum);
4816: } else {
4817: &print_user_modification_page($r,$ccuname,$ccdomain,$srch,'',
4818: $context,$permission,$crstype,
4819: $brcrum);
4820: }
4821: } elsif ($env{'form.action'} eq 'accesslogs') {
4822: my $ccuname = &LONCAPA::clean_username($env{'form.accessuname'});
4823: my $ccdomain = &LONCAPA::clean_domain($env{'form.accessudom'});
4824: &print_useraccesslogs_display($r,$ccuname,$ccdomain,$permission,$brcrum);
1.190 raeburn 4825: }
4826: } elsif ($env{'form.phase'} eq 'update_user_data') {
1.375 raeburn 4827: &update_user_data($r,$context,$crstype,$brcrum,$showcredits);
1.190 raeburn 4828: } else {
1.351 raeburn 4829: &print_username_entry_form($r,$context,undef,$srch,undef,$crstype,
1.439 raeburn 4830: $brcrum,$permission);
1.190 raeburn 4831: }
4832: } elsif ($env{'form.action'} eq 'custom' && $permission->{'custom'}) {
1.414 raeburn 4833: my $prefix;
1.190 raeburn 4834: if ($env{'form.phase'} eq 'set_custom_roles') {
1.439 raeburn 4835: &set_custom_role($r,$context,$brcrum,$prefix,$permission);
1.190 raeburn 4836: } else {
1.439 raeburn 4837: &custom_role_editor($r,$context,$brcrum,$prefix,$permission);
1.190 raeburn 4838: }
1.362 raeburn 4839: } elsif (($env{'form.action'} eq 'processauthorreq') &&
4840: ($permission->{'cusr'}) &&
4841: (&Apache::lonnet::allowed('cau',$env{'request.role.domain'}))) {
4842: push(@{$brcrum},
4843: {href => '/adm/createuser?action=processauthorreq',
1.385 bisitz 4844: text => 'Authoring Space requests',
1.362 raeburn 4845: help => 'Domain_Role_Approvals'});
4846: $bread_crumbs_component = 'Authoring requests';
4847: if ($env{'form.state'} eq 'done') {
4848: push(@{$brcrum},
4849: {href => '/adm/createuser?action=authorreqqueue',
4850: text => 'Result',
4851: help => 'Domain_Role_Approvals'});
4852: $bread_crumbs_component = 'Authoring request result';
4853: }
4854: $args = { bread_crumbs => $brcrum,
4855: bread_crumbs_component => $bread_crumbs_component};
1.391 raeburn 4856: my $js = &usernamerequest_javascript();
4857: $r->print(&header(&add_script($js),$args));
1.362 raeburn 4858: if (!exists($env{'form.state'})) {
4859: $r->print(&Apache::loncoursequeueadmin::display_queued_requests('requestauthor',
4860: $env{'request.role.domain'}));
4861: } elsif ($env{'form.state'} eq 'done') {
4862: $r->print('<h3>'.&mt('Authoring request processing').'</h3>'."\n");
4863: $r->print(&Apache::loncoursequeueadmin::update_request_queue('requestauthor',
4864: $env{'request.role.domain'}));
4865: }
1.391 raeburn 4866: } elsif (($env{'form.action'} eq 'processusernamereq') &&
4867: ($permission->{'cusr'}) &&
4868: (&Apache::lonnet::allowed('cau',$env{'request.role.domain'}))) {
4869: push(@{$brcrum},
4870: {href => '/adm/createuser?action=processusernamereq',
4871: text => 'LON-CAPA account requests',
4872: help => 'Domain_Username_Approvals'});
4873: $bread_crumbs_component = 'Account requests';
4874: if ($env{'form.state'} eq 'done') {
4875: push(@{$brcrum},
4876: {href => '/adm/createuser?action=usernamereqqueue',
4877: text => 'Result',
4878: help => 'Domain_Username_Approvals'});
4879: $bread_crumbs_component = 'LON-CAPA account request result';
4880: }
4881: $args = { bread_crumbs => $brcrum,
4882: bread_crumbs_component => $bread_crumbs_component};
4883: my $js = &usernamerequest_javascript();
4884: $r->print(&header(&add_script($js),$args));
4885: if (!exists($env{'form.state'})) {
4886: $r->print(&Apache::loncoursequeueadmin::display_queued_requests('requestusername',
4887: $env{'request.role.domain'}));
4888: } elsif ($env{'form.state'} eq 'done') {
4889: $r->print('<h3>'.&mt('LON-CAPA account request processing').'</h3>'."\n");
4890: $r->print(&Apache::loncoursequeueadmin::update_request_queue('requestusername',
4891: $env{'request.role.domain'}));
4892: }
4893: } elsif (($env{'form.action'} eq 'displayuserreq') &&
4894: ($permission->{'cusr'})) {
4895: my $dom = $env{'form.domain'};
4896: my $uname = $env{'form.username'};
4897: my $warning;
4898: if (($dom =~ /^$match_domain$/) && (&Apache::lonnet::domain($dom) ne '')) {
4899: if (($dom eq $env{'request.role.domain'}) && (&Apache::lonnet::allowed('ccc',$dom))) {
4900: if (($uname =~ /^$match_username$/) && ($env{'form.queue'} eq 'approval')) {
4901: my $uhome = &Apache::lonnet::homeserver($uname,$dom);
4902: if ($uhome eq 'no_host') {
4903: my $queue = $env{'form.queue'};
4904: my $reqkey = &escape($uname).'_'.$queue;
4905: my $namespace = 'usernamequeue';
4906: my $domconfig = &Apache::lonnet::get_domainconfiguser($dom);
4907: my %queued =
4908: &Apache::lonnet::get($namespace,[$reqkey],$dom,$domconfig);
4909: unless ($queued{$reqkey}) {
4910: $warning = &mt('No information was found for this LON-CAPA account request.');
4911: }
4912: } else {
4913: $warning = &mt('A LON-CAPA account already exists for the requested username and domain.');
4914: }
4915: } else {
4916: $warning = &mt('LON-CAPA account request status check is for an invalid username.');
4917: }
4918: } else {
4919: $warning = &mt('You do not have rights to view LON-CAPA account requests in the domain specified.');
4920: }
4921: } else {
4922: $warning = &mt('LON-CAPA account request status check is for an invalid domain.');
4923: }
4924: my $args = { only_body => 1 };
4925: $r->print(&header(undef,$args).
4926: '<h3>'.&mt('LON-CAPA Account Request Details').'</h3>');
4927: if ($warning ne '') {
4928: $r->print('<div class="LC_warning">'.$warning.'</div>');
4929: } else {
4930: my ($infofields,$infotitles) = &Apache::loncommon::emailusername_info();
4931: my $domconfiguser = &Apache::lonnet::get_domainconfiguser($dom);
4932: my %domconfig = &Apache::lonnet::get_dom('configuration',['usercreation'],$dom);
4933: if (ref($domconfig{'usercreation'}) eq 'HASH') {
4934: if (ref($domconfig{'usercreation'}{'cancreate'}) eq 'HASH') {
4935: if (ref($domconfig{'usercreation'}{'cancreate'}{'emailusername'}) eq 'HASH') {
4936: my %info =
4937: &Apache::lonnet::get('nohist_requestedusernames',[$uname],$dom,$domconfiguser);
4938: if (ref($info{$uname}) eq 'HASH') {
1.396 raeburn 4939: my $usertype = $info{$uname}{'inststatus'};
4940: unless ($usertype) {
4941: $usertype = 'default';
4942: }
1.442 ! raeburn 4943: my ($showstatus,$showemail,$pickstart);
! 4944: my $numextras = 0;
! 4945: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
! 4946: if (ref($usertypes) eq 'HASH') {
! 4947: if ($usertypes->{$usertype}) {
! 4948: $showstatus = $usertypes->{$usertype};
! 4949: } else {
! 4950: $showstatus = $othertitle;
! 4951: }
! 4952: $numextras ++;
! 4953: }
! 4954: if (($info{$uname}{'email'} ne '') && ($info{$uname}{'email'} ne $uname)) {
! 4955: $showemail = $info{$uname}{'email'};
! 4956: $numextras ++;
! 4957: }
1.396 raeburn 4958: if (ref($domconfig{'usercreation'}{'cancreate'}{'emailusername'}{$usertype}) eq 'HASH') {
4959: if ((ref($infofields) eq 'ARRAY') && (ref($infotitles) eq 'HASH')) {
1.442 ! raeburn 4960: $pickstart = 1;
1.396 raeburn 4961: $r->print('<div>'.&Apache::lonhtmlcommon::start_pick_box());
1.442 ! raeburn 4962: my ($num,$count);
1.396 raeburn 4963: $count = scalar(keys(%{$domconfig{'usercreation'}{'cancreate'}{'emailusername'}{$usertype}}));
1.442 ! raeburn 4964: $count += $numextras;
1.396 raeburn 4965: foreach my $field (@{$infofields}) {
4966: next unless ($domconfig{'usercreation'}{'cancreate'}{'emailusername'}{$usertype}{$field});
4967: next unless ($infotitles->{$field});
4968: $r->print(&Apache::lonhtmlcommon::row_title($infotitles->{$field}).
4969: $info{$uname}{$field});
4970: $num ++;
1.442 ! raeburn 4971: unless ($count == $num) {
1.396 raeburn 4972: $r->print(&Apache::lonhtmlcommon::row_closure());
4973: }
4974: }
1.442 ! raeburn 4975: }
! 4976: }
! 4977: if ($numextras) {
! 4978: unless ($pickstart) {
! 4979: $r->print('<div>'.&Apache::lonhtmlcommon::start_pick_box());
! 4980: $pickstart = 1;
! 4981: }
! 4982: if ($showemail) {
! 4983: my $closure = '';
! 4984: unless ($showstatus) {
! 4985: $closure = 1;
1.391 raeburn 4986: }
1.442 ! raeburn 4987: $r->print(&Apache::lonhtmlcommon::row_title(&mt('E-mail address')).
! 4988: $showemail.
! 4989: &Apache::lonhtmlcommon::row_closure($closure));
1.391 raeburn 4990: }
1.442 ! raeburn 4991: if ($showstatus) {
! 4992: $r->print(&Apache::lonhtmlcommon::row_title(&mt('Status type[_1](self-reported)','<br />')).
! 4993: $showstatus.
! 4994: &Apache::lonhtmlcommon::row_closure(1));
! 4995: }
! 4996: }
! 4997: if ($pickstart) {
! 4998: $r->print(&Apache::lonhtmlcommon::end_pick_box().'</div>');
! 4999: } else {
! 5000: $r->print('<div>'.&mt('No information to display for this account request.').'</div>');
1.391 raeburn 5001: }
1.442 ! raeburn 5002: } else {
! 5003: $r->print('<div>'.&mt('No information available for this account request.').'</div>');
1.391 raeburn 5004: }
5005: }
5006: }
5007: }
5008: }
1.442 ! raeburn 5009: $r->print(&close_popup_form());
1.207 raeburn 5010: } elsif (($env{'form.action'} eq 'listusers') &&
5011: ($permission->{'view'} || $permission->{'cusr'})) {
1.439 raeburn 5012: my $helpitem = 'Course_View_Class_List';
5013: if ($context eq 'author') {
5014: $helpitem = 'Author_View_Coauthor_List';
5015: } elsif ($context eq 'domain') {
5016: $helpitem = 'Domain_View_Users_List';
5017: }
1.202 raeburn 5018: if ($env{'form.phase'} eq 'bulkchange') {
1.351 raeburn 5019: push(@{$brcrum},
5020: {href => '/adm/createuser?action=listusers',
5021: text => "List Users"},
5022: {href => "/adm/createuser",
5023: text => "Result",
1.439 raeburn 5024: help => $helpitem});
1.351 raeburn 5025: $bread_crumbs_component = 'Update Users';
5026: $args = {bread_crumbs => $brcrum,
5027: bread_crumbs_component => $bread_crumbs_component};
5028: $r->print(&header(undef,$args));
1.202 raeburn 5029: my $setting = $env{'form.roletype'};
5030: my $choice = $env{'form.bulkaction'};
5031: if ($permission->{'cusr'}) {
1.336 raeburn 5032: &Apache::lonuserutils::update_user_list($r,$context,$setting,$choice,$crstype);
1.221 raeburn 5033: } else {
5034: $r->print(&mt('You are not authorized to make bulk changes to user roles'));
1.223 raeburn 5035: $r->print('<p><a href="/adm/createuser?action=listusers">'.&mt('Display User Lists').'</a>');
1.202 raeburn 5036: }
5037: } else {
1.351 raeburn 5038: push(@{$brcrum},
5039: {href => '/adm/createuser?action=listusers',
5040: text => "List Users",
1.439 raeburn 5041: help => $helpitem});
1.351 raeburn 5042: $bread_crumbs_component = 'List Users';
5043: $args = {bread_crumbs => $brcrum,
5044: bread_crumbs_component => $bread_crumbs_component};
1.202 raeburn 5045: my ($cb_jscript,$jscript,$totcodes,$codetitles,$idlist,$idlist_titles);
5046: my $formname = 'studentform';
1.364 raeburn 5047: my $hidecall = "hide_searching();";
1.321 raeburn 5048: if (($context eq 'domain') && (($env{'form.roletype'} eq 'course') ||
5049: ($env{'form.roletype'} eq 'community'))) {
5050: if ($env{'form.roletype'} eq 'course') {
5051: ($cb_jscript,$jscript,$totcodes,$codetitles,$idlist,$idlist_titles) =
5052: &Apache::lonuserutils::courses_selector($env{'request.role.domain'},
5053: $formname);
5054: } elsif ($env{'form.roletype'} eq 'community') {
5055: $cb_jscript =
5056: &Apache::loncommon::coursebrowser_javascript($env{'request.role.domain'});
5057: my %elements = (
5058: coursepick => 'radio',
5059: coursetotal => 'text',
5060: courselist => 'text',
5061: );
5062: $jscript = &Apache::lonhtmlcommon::set_form_elements(\%elements);
5063: }
1.364 raeburn 5064: $jscript .= &verify_user_display($context)."\n".
5065: &Apache::loncommon::check_uncheck_jscript();
1.202 raeburn 5066: my $js = &add_script($jscript).$cb_jscript;
5067: my $loadcode =
5068: &Apache::lonuserutils::course_selector_loadcode($formname);
5069: if ($loadcode ne '') {
1.364 raeburn 5070: $args->{add_entries} = {onload => "$loadcode;$hidecall"};
5071: } else {
5072: $args->{add_entries} = {onload => $hidecall};
1.202 raeburn 5073: }
1.351 raeburn 5074: $r->print(&header($js,$args));
1.191 raeburn 5075: } else {
1.364 raeburn 5076: $args->{add_entries} = {onload => $hidecall};
5077: $jscript = &verify_user_display($context).
5078: &Apache::loncommon::check_uncheck_jscript();
5079: $r->print(&header(&add_script($jscript),$args));
1.191 raeburn 5080: }
1.202 raeburn 5081: &Apache::lonuserutils::print_userlist($r,undef,$permission,$context,
1.375 raeburn 5082: $formname,$totcodes,$codetitles,$idlist,$idlist_titles,
5083: $showcredits);
1.191 raeburn 5084: }
1.213 raeburn 5085: } elsif ($env{'form.action'} eq 'drop' && $permission->{'cusr'}) {
1.318 raeburn 5086: my $brtext;
5087: if ($crstype eq 'Community') {
5088: $brtext = 'Drop Members';
5089: } else {
5090: $brtext = 'Drop Students';
5091: }
1.351 raeburn 5092: push(@{$brcrum},
5093: {href => '/adm/createuser?action=drop',
5094: text => $brtext,
5095: help => 'Course_Drop_Student'});
5096: if ($env{'form.state'} eq 'done') {
5097: push(@{$brcrum},
5098: {href=>'/adm/createuser?action=drop',
5099: text=>"Result"});
5100: }
5101: $bread_crumbs_component = $brtext;
5102: $args = {bread_crumbs => $brcrum,
5103: bread_crumbs_component => $bread_crumbs_component};
5104: $r->print(&header(undef,$args));
1.213 raeburn 5105: if (!exists($env{'form.state'})) {
1.318 raeburn 5106: &Apache::lonuserutils::print_drop_menu($r,$context,$permission,$crstype);
1.213 raeburn 5107: } elsif ($env{'form.state'} eq 'done') {
5108: &Apache::lonuserutils::update_user_list($r,$context,undef,
5109: $env{'form.action'});
5110: }
1.202 raeburn 5111: } elsif ($env{'form.action'} eq 'dateselect') {
5112: if ($permission->{'cusr'}) {
1.351 raeburn 5113: $r->print(&header(undef,{'no_nav_bar' => 1}).
1.375 raeburn 5114: &Apache::lonuserutils::date_section_selector($context,$permission,
5115: $crstype,$showcredits));
1.202 raeburn 5116: } else {
1.351 raeburn 5117: $r->print(&header(undef,{'no_nav_bar' => 1}).
5118: '<span class="LC_error">'.&mt('You do not have permission to modify dates or sections for users').'</span>');
1.202 raeburn 5119: }
1.237 raeburn 5120: } elsif ($env{'form.action'} eq 'selfenroll') {
1.398 raeburn 5121: if ($permission->{selfenrolladmin}) {
5122: my %currsettings = (
5123: selfenroll_types => $env{'course.'.$cid.'.internal.selfenroll_types'},
5124: selfenroll_registered => $env{'course.'.$cid.'.internal.selfenroll_registered'},
5125: selfenroll_section => $env{'course.'.$cid.'.internal.selfenroll_section'},
5126: selfenroll_notifylist => $env{'course.'.$cid.'.internal.selfenroll_notifylist'},
5127: selfenroll_approval => $env{'course.'.$cid.'.internal.selfenroll_approval'},
5128: selfenroll_limit => $env{'course.'.$cid.'.internal.selfenroll_limit'},
5129: selfenroll_cap => $env{'course.'.$cid.'.internal.selfenroll_cap'},
5130: selfenroll_start_date => $env{'course.'.$cid.'.internal.selfenroll_start_date'},
5131: selfenroll_end_date => $env{'course.'.$cid.'.internal.selfenroll_end_date'},
5132: selfenroll_start_access => $env{'course.'.$cid.'.internal.selfenroll_start_access'},
5133: selfenroll_end_access => $env{'course.'.$cid.'.internal.selfenroll_end_access'},
5134: default_enrollment_start_date => $env{'course.'.$cid.'.default_enrollment_start_date'},
5135: default_enrollment_end_date => $env{'course.'.$cid.'.default_enrollment_end_date'},
1.400 raeburn 5136: uniquecode => $env{'course.'.$cid.'.internal.uniquecode'},
1.398 raeburn 5137: );
5138: push(@{$brcrum},
5139: {href => '/adm/createuser?action=selfenroll',
5140: text => "Configure Self-enrollment",
5141: help => 'Course_Self_Enrollment'});
5142: if (!exists($env{'form.state'})) {
5143: $args = { bread_crumbs => $brcrum,
5144: bread_crumbs_component => 'Configure Self-enrollment'};
5145: $r->print(&header(undef,$args));
5146: $r->print('<h3>'.&mt('Self-enrollment with a student role').'</h3>'."\n");
5147: &print_selfenroll_menu($r,'course',$cid,$cdom,$cnum,\%currsettings);
5148: } elsif ($env{'form.state'} eq 'done') {
5149: push (@{$brcrum},
5150: {href=>'/adm/createuser?action=selfenroll',
5151: text=>"Result"});
5152: $args = { bread_crumbs => $brcrum,
5153: bread_crumbs_component => 'Self-enrollment result'};
5154: $r->print(&header(undef,$args));
5155: $r->print('<h3>'.&mt('Self-enrollment with a student role').'</h3>'."\n");
1.400 raeburn 5156: &update_selfenroll_config($r,$cid,$cdom,$cnum,$context,$crstype,\%currsettings);
1.398 raeburn 5157: }
5158: } else {
5159: $r->print(&header(undef,{'no_nav_bar' => 1}).
5160: '<span class="LC_error">'.&mt('You do not have permission to configure self-enrollment').'</span>');
1.237 raeburn 5161: }
1.277 raeburn 5162: } elsif ($env{'form.action'} eq 'selfenrollqueue') {
1.418 raeburn 5163: if ($permission->{selfenrolladmin}) {
1.351 raeburn 5164: push(@{$brcrum},
5165: {href => '/adm/createuser?action=selfenrollqueue',
1.418 raeburn 5166: text => 'Enrollment requests',
1.439 raeburn 5167: help => 'Course_Approve_Selfenroll'});
1.418 raeburn 5168: $bread_crumbs_component = 'Enrollment requests';
5169: if ($env{'form.state'} eq 'done') {
5170: push(@{$brcrum},
5171: {href => '/adm/createuser?action=selfenrollqueue',
5172: text => 'Result',
1.439 raeburn 5173: help => 'Course_Approve_Selfenroll'});
1.418 raeburn 5174: $bread_crumbs_component = 'Enrollment result';
5175: }
5176: $args = { bread_crumbs => $brcrum,
5177: bread_crumbs_component => $bread_crumbs_component};
5178: $r->print(&header(undef,$args));
5179: my $coursedesc = $env{'course.'.$cid.'.description'};
5180: if (!exists($env{'form.state'})) {
5181: $r->print('<h3>'.&mt('Pending enrollment requests').'</h3>'."\n");
5182: $r->print(&Apache::loncoursequeueadmin::display_queued_requests($context,
5183: $cdom,$cnum));
5184: } elsif ($env{'form.state'} eq 'done') {
5185: $r->print('<h3>'.&mt('Enrollment request processing').'</h3>'."\n");
5186: $r->print(&Apache::loncoursequeueadmin::update_request_queue($context,
1.430 raeburn 5187: $cdom,$cnum,$coursedesc));
1.418 raeburn 5188: }
5189: } else {
5190: $r->print(&header(undef,{'no_nav_bar' => 1}).
5191: '<span class="LC_error">'.&mt('You do not have permission to manage self-enrollment').'</span>');
1.351 raeburn 5192: }
1.418 raeburn 5193: } elsif ($env{'form.action'} eq 'changelogs') {
5194: if ($permission->{cusr} || $permission->{view}) {
5195: &print_userchangelogs_display($r,$context,$permission,$brcrum);
5196: } else {
5197: $r->print(&header(undef,{'no_nav_bar' => 1}).
5198: '<span class="LC_error">'.&mt('You do not have permission to view change logs').'</span>');
1.277 raeburn 5199: }
1.428 raeburn 5200: } elsif ($env{'form.action'} eq 'helpdesk') {
5201: if (($permission->{'owner'}) || ($permission->{'co-owner'})) {
5202: if ($env{'form.state'} eq 'process') {
5203: if ($permission->{'owner'}) {
5204: &update_helpdeskaccess($r,$permission,$brcrum);
5205: } else {
5206: &print_helpdeskaccess_display($r,$permission,$brcrum);
1.430 raeburn 5207: }
1.428 raeburn 5208: } else {
5209: &print_helpdeskaccess_display($r,$permission,$brcrum);
5210: }
5211: } else {
5212: $r->print(&header(undef,{'no_nav_bar' => 1}).
5213: '<span class="LC_error">'.&mt('You do not have permission to view helpdesk access').'</span>');
5214: }
1.190 raeburn 5215: } else {
1.351 raeburn 5216: $bread_crumbs_component = 'User Management';
5217: $args = { bread_crumbs => $brcrum,
5218: bread_crumbs_component => $bread_crumbs_component};
5219: $r->print(&header(undef,$args));
1.318 raeburn 5220: $r->print(&print_main_menu($permission,$context,$crstype));
1.190 raeburn 5221: }
1.351 raeburn 5222: $r->print(&Apache::loncommon::end_page());
1.190 raeburn 5223: return OK;
5224: }
5225:
5226: sub header {
1.351 raeburn 5227: my ($jscript,$args) = @_;
1.190 raeburn 5228: my $start_page;
1.351 raeburn 5229: if (ref($args) eq 'HASH') {
5230: $start_page=&Apache::loncommon::start_page('User Management',$jscript,$args);
1.190 raeburn 5231: } else {
1.351 raeburn 5232: $start_page=&Apache::loncommon::start_page('User Management',$jscript);
1.190 raeburn 5233: }
5234: return $start_page;
5235: }
1.2 www 5236:
1.191 raeburn 5237: sub add_script {
5238: my ($js) = @_;
1.301 bisitz 5239: return '<script type="text/javascript">'."\n"
5240: .'// <![CDATA['."\n"
5241: .$js."\n"
5242: .'// ]]>'."\n"
5243: .'</script>'."\n";
1.191 raeburn 5244: }
5245:
1.391 raeburn 5246: sub usernamerequest_javascript {
5247: my $js = <<ENDJS;
5248:
5249: function openusernamereqdisplay(dom,uname,queue) {
5250: var url = '/adm/createuser?action=displayuserreq';
5251: url += '&domain='+dom+'&username='+uname+'&queue='+queue;
5252: var title = 'Account_Request_Browser';
5253: var options = 'scrollbars=1,resizable=1,menubar=0';
5254: options += ',width=700,height=600';
5255: var stdeditbrowser = open(url,title,options,'1');
5256: stdeditbrowser.focus();
5257: return;
5258: }
5259:
5260: ENDJS
5261: }
5262:
5263: sub close_popup_form {
5264: my $close= &mt('Close Window');
5265: return << "END";
5266: <p><form name="displayreq" action="" method="post">
5267: <input type="button" name="closeme" value="$close" onclick="javascript:self.close();" />
5268: </form></p>
5269: END
5270: }
5271:
1.202 raeburn 5272: sub verify_user_display {
1.364 raeburn 5273: my ($context) = @_;
1.374 raeburn 5274: my %lt = &Apache::lonlocal::texthash (
5275: course => 'course(s): description, section(s), status',
5276: community => 'community(s): description, section(s), status',
5277: author => 'author',
5278: );
1.364 raeburn 5279: my $photos;
5280: if (($context eq 'course') && $env{'request.course.id'}) {
5281: $photos = $env{'course.'.$env{'request.course.id'}.'.internal.showphoto'};
5282: }
1.202 raeburn 5283: my $output = <<"END";
5284:
1.364 raeburn 5285: function hide_searching() {
5286: if (document.getElementById('searching')) {
5287: document.getElementById('searching').style.display = 'none';
5288: }
5289: return;
5290: }
5291:
1.202 raeburn 5292: function display_update() {
5293: document.studentform.action.value = 'listusers';
5294: document.studentform.phase.value = 'display';
5295: document.studentform.submit();
5296: }
5297:
1.364 raeburn 5298: function updateCols(caller) {
5299: var context = '$context';
5300: var photos = '$photos';
5301: if (caller == 'Status') {
1.374 raeburn 5302: if ((context == 'domain') &&
5303: ((document.studentform.roletype.options[document.studentform.roletype.selectedIndex].value == 'course') ||
5304: (document.studentform.roletype.options[document.studentform.roletype.selectedIndex].value == 'community'))) {
1.364 raeburn 5305: document.getElementById('showcolstatus').checked = false;
5306: document.getElementById('showcolstatus').disabled = 'disabled';
5307: document.getElementById('showcolstart').checked = false;
5308: document.getElementById('showcolend').checked = false;
1.374 raeburn 5309: } else {
5310: if (document.studentform.Status.options[document.studentform.Status.selectedIndex].value == 'Any') {
5311: document.getElementById('showcolstatus').checked = true;
5312: document.getElementById('showcolstatus').disabled = '';
5313: document.getElementById('showcolstart').checked = true;
5314: document.getElementById('showcolend').checked = true;
5315: } else {
5316: document.getElementById('showcolstatus').checked = false;
5317: document.getElementById('showcolstatus').disabled = 'disabled';
5318: document.getElementById('showcolstart').checked = false;
5319: document.getElementById('showcolend').checked = false;
5320: }
1.364 raeburn 5321: }
5322: }
5323: if (caller == 'output') {
5324: if (photos == 1) {
5325: if (document.getElementById('showcolphoto')) {
5326: var photoitem = document.getElementById('showcolphoto');
5327: if (document.studentform.output.options[document.studentform.output.selectedIndex].value == 'html') {
5328: photoitem.checked = true;
5329: photoitem.disabled = '';
5330: } else {
5331: photoitem.checked = false;
5332: photoitem.disabled = 'disabled';
5333: }
5334: }
5335: }
5336: }
5337: if (caller == 'showrole') {
1.371 raeburn 5338: if ((document.studentform.showrole.options[document.studentform.showrole.selectedIndex].value == 'Any') ||
5339: (document.studentform.showrole.options[document.studentform.showrole.selectedIndex].value == 'cr')) {
1.364 raeburn 5340: document.getElementById('showcolrole').checked = true;
5341: document.getElementById('showcolrole').disabled = '';
5342: } else {
5343: document.getElementById('showcolrole').checked = false;
5344: document.getElementById('showcolrole').disabled = 'disabled';
5345: }
1.374 raeburn 5346: if (context == 'domain') {
1.382 raeburn 5347: var quotausageshow = 0;
1.374 raeburn 5348: if ((document.studentform.roletype.options[document.studentform.roletype.selectedIndex].value == 'course') ||
5349: (document.studentform.roletype.options[document.studentform.roletype.selectedIndex].value == 'community')) {
5350: document.getElementById('showcolstatus').checked = false;
5351: document.getElementById('showcolstatus').disabled = 'disabled';
5352: document.getElementById('showcolstart').checked = false;
5353: document.getElementById('showcolend').checked = false;
5354: } else {
5355: if (document.studentform.Status.options[document.studentform.Status.selectedIndex].value == 'Any') {
5356: document.getElementById('showcolstatus').checked = true;
5357: document.getElementById('showcolstatus').disabled = '';
5358: document.getElementById('showcolstart').checked = true;
5359: document.getElementById('showcolend').checked = true;
5360: }
5361: }
5362: if (document.studentform.roletype.options[document.studentform.roletype.selectedIndex].value == 'domain') {
5363: document.getElementById('showcolextent').disabled = 'disabled';
5364: document.getElementById('showcolextent').checked = 'false';
5365: document.getElementById('showextent').style.display='none';
5366: document.getElementById('showcoltextextent').innerHTML = '';
1.382 raeburn 5367: if ((document.studentform.showrole.options[document.studentform.showrole.selectedIndex].value == 'au') ||
5368: (document.studentform.showrole.options[document.studentform.showrole.selectedIndex].value == 'Any')) {
5369: if (document.getElementById('showcolauthorusage')) {
5370: document.getElementById('showcolauthorusage').disabled = '';
5371: }
5372: if (document.getElementById('showcolauthorquota')) {
5373: document.getElementById('showcolauthorquota').disabled = '';
5374: }
5375: quotausageshow = 1;
5376: }
1.374 raeburn 5377: } else {
5378: document.getElementById('showextent').style.display='block';
5379: document.getElementById('showextent').style.textAlign='left';
5380: document.getElementById('showextent').style.textFace='normal';
5381: if (document.studentform.roletype.options[document.studentform.roletype.selectedIndex].value == 'author') {
5382: document.getElementById('showcolextent').disabled = '';
5383: document.getElementById('showcolextent').checked = 'true';
5384: document.getElementById('showcoltextextent').innerHTML="$lt{'author'}";
5385: } else {
5386: document.getElementById('showcolextent').disabled = '';
5387: document.getElementById('showcolextent').checked = 'true';
5388: if (document.studentform.roletype.options[document.studentform.roletype.selectedIndex].value == 'community') {
5389: document.getElementById('showcoltextextent').innerHTML="$lt{'community'}";
5390: } else {
5391: document.getElementById('showcoltextextent').innerHTML="$lt{'course'}";
5392: }
5393: }
5394: }
1.382 raeburn 5395: if (quotausageshow == 0) {
5396: if (document.getElementById('showcolauthorusage')) {
5397: document.getElementById('showcolauthorusage').checked = false;
5398: document.getElementById('showcolauthorusage').disabled = 'disabled';
5399: }
5400: if (document.getElementById('showcolauthorquota')) {
5401: document.getElementById('showcolauthorquota').checked = false;
5402: document.getElementById('showcolauthorquota').disabled = 'disabled';
5403: }
5404: }
1.374 raeburn 5405: }
1.364 raeburn 5406: }
5407: return;
5408: }
5409:
1.202 raeburn 5410: END
5411: return $output;
5412:
5413: }
5414:
1.190 raeburn 5415: ###############################################################
5416: ###############################################################
5417: # Menu Phase One
5418: sub print_main_menu {
1.318 raeburn 5419: my ($permission,$context,$crstype) = @_;
5420: my $linkcontext = $context;
5421: my $stuterm = lc(&Apache::lonnet::plaintext('st',$crstype));
5422: if (($context eq 'course') && ($crstype eq 'Community')) {
5423: $linkcontext = lc($crstype);
5424: $stuterm = 'Members';
5425: }
1.208 raeburn 5426: my %links = (
1.298 droeschl 5427: domain => {
5428: upload => 'Upload a File of Users',
5429: singleuser => 'Add/Modify a User',
5430: listusers => 'Manage Users',
5431: },
5432: author => {
5433: upload => 'Upload a File of Co-authors',
5434: singleuser => 'Add/Modify a Co-author',
5435: listusers => 'Manage Co-authors',
5436: },
5437: course => {
5438: upload => 'Upload a File of Course Users',
5439: singleuser => 'Add/Modify a Course User',
1.354 www 5440: listusers => 'List and Modify Multiple Course Users',
1.298 droeschl 5441: },
1.318 raeburn 5442: community => {
5443: upload => 'Upload a File of Community Users',
5444: singleuser => 'Add/Modify a Community User',
1.354 www 5445: listusers => 'List and Modify Multiple Community Users',
1.318 raeburn 5446: },
5447: );
5448: my %linktitles = (
5449: domain => {
5450: singleuser => 'Add a user to the domain, and/or a course or community in the domain.',
5451: listusers => 'Show and manage users in this domain.',
5452: },
5453: author => {
5454: singleuser => 'Add a user with a co- or assistant author role.',
5455: listusers => 'Show and manage co- or assistant authors.',
5456: },
5457: course => {
5458: singleuser => 'Add a user with a certain role to this course.',
5459: listusers => 'Show and manage users in this course.',
5460: },
5461: community => {
5462: singleuser => 'Add a user with a certain role to this community.',
5463: listusers => 'Show and manage users in this community.',
5464: },
1.298 droeschl 5465: );
1.418 raeburn 5466: if ($linkcontext eq 'domain') {
5467: unless ($permission->{'cusr'}) {
1.430 raeburn 5468: $links{'domain'}{'singleuser'} = 'View a User';
1.418 raeburn 5469: $linktitles{'domain'}{'singleuser'} = 'View information about a user in the domain';
5470: }
5471: } elsif ($linkcontext eq 'course') {
5472: unless ($permission->{'cusr'}) {
5473: $links{'course'}{'singleuser'} = 'View a Course User';
5474: $linktitles{'course'}{'singleuser'} = 'View information about a user in this course';
5475: $links{'course'}{'listusers'} = 'List Course Users';
5476: $linktitles{'course'}{'listusers'} = 'Show information about users in this course';
5477: }
5478: } elsif ($linkcontext eq 'community') {
5479: unless ($permission->{'cusr'}) {
5480: $links{'community'}{'singleuser'} = 'View a Community User';
5481: $linktitles{'community'}{'singleuser'} = 'View information about a user in this community';
5482: $links{'community'}{'listusers'} = 'List Community Users';
5483: $linktitles{'community'}{'listusers'} = 'Show information about users in this community';
5484: }
5485: }
1.298 droeschl 5486: my @menu = ( {categorytitle => 'Single Users',
5487: items =>
5488: [
5489: {
1.318 raeburn 5490: linktext => $links{$linkcontext}{'singleuser'},
1.298 droeschl 5491: icon => 'edit-redo.png',
5492: #help => 'Course_Change_Privileges',
5493: url => '/adm/createuser?action=singleuser',
1.418 raeburn 5494: permission => ($permission->{'view'} || $permission->{'cusr'}),
1.318 raeburn 5495: linktitle => $linktitles{$linkcontext}{'singleuser'},
1.298 droeschl 5496: },
5497: ]},
5498:
5499: {categorytitle => 'Multiple Users',
5500: items =>
5501: [
5502: {
1.318 raeburn 5503: linktext => $links{$linkcontext}{'upload'},
1.340 wenzelju 5504: icon => 'uplusr.png',
1.298 droeschl 5505: #help => 'Course_Create_Class_List',
5506: url => '/adm/createuser?action=upload',
5507: permission => $permission->{'cusr'},
5508: linktitle => 'Upload a CSV or a text file containing users.',
5509: },
5510: {
1.318 raeburn 5511: linktext => $links{$linkcontext}{'listusers'},
1.340 wenzelju 5512: icon => 'mngcu.png',
1.298 droeschl 5513: #help => 'Course_View_Class_List',
5514: url => '/adm/createuser?action=listusers',
5515: permission => ($permission->{'view'} || $permission->{'cusr'}),
1.318 raeburn 5516: linktitle => $linktitles{$linkcontext}{'listusers'},
1.298 droeschl 5517: },
5518:
5519: ]},
5520:
5521: {categorytitle => 'Administration',
5522: items => [ ]},
5523: );
1.415 raeburn 5524:
1.265 mielkec 5525: if ($context eq 'domain'){
1.416 raeburn 5526: push(@{ $menu[0]->{items} }, # Single Users
5527: {
5528: linktext => 'User Access Log',
1.417 raeburn 5529: icon => 'document-properties.png',
1.425 raeburn 5530: #help => 'Domain_User_Access_Logs',
1.416 raeburn 5531: url => '/adm/createuser?action=accesslogs',
5532: permission => $permission->{'activity'},
5533: linktitle => 'View user access log.',
5534: }
5535: );
1.298 droeschl 5536:
5537: push(@{ $menu[2]->{items} }, #Category: Administration
5538: {
5539: linktext => 'Custom Roles',
5540: icon => 'emblem-photos.png',
5541: #help => 'Course_Editing_Custom_Roles',
5542: url => '/adm/createuser?action=custom',
5543: permission => $permission->{'custom'},
5544: linktitle => 'Configure a custom role.',
5545: },
1.362 raeburn 5546: {
5547: linktext => 'Authoring Space Requests',
5548: icon => 'selfenrl-queue.png',
5549: #help => 'Domain_Role_Approvals',
5550: url => '/adm/createuser?action=processauthorreq',
5551: permission => $permission->{'cusr'},
5552: linktitle => 'Approve or reject author role requests',
5553: },
1.363 raeburn 5554: {
1.391 raeburn 5555: linktext => 'LON-CAPA Account Requests',
5556: icon => 'list-add.png',
5557: #help => 'Domain_Username_Approvals',
5558: url => '/adm/createuser?action=processusernamereq',
5559: permission => $permission->{'cusr'},
5560: linktitle => 'Approve or reject LON-CAPA account requests',
5561: },
5562: {
1.363 raeburn 5563: linktext => 'Change Log',
5564: icon => 'document-properties.png',
5565: #help => 'Course_User_Logs',
5566: url => '/adm/createuser?action=changelogs',
1.418 raeburn 5567: permission => ($permission->{'cusr'} || $permission->{'view'}),
1.363 raeburn 5568: linktitle => 'View change log.',
5569: },
1.298 droeschl 5570: );
5571:
1.265 mielkec 5572: }elsif ($context eq 'course'){
1.298 droeschl 5573: my ($cnum,$cdom) = &Apache::lonuserutils::get_course_identity();
1.318 raeburn 5574:
5575: my %linktext = (
5576: 'Course' => {
5577: single => 'Add/Modify a Student',
5578: drop => 'Drop Students',
5579: groups => 'Course Groups',
5580: },
5581: 'Community' => {
5582: single => 'Add/Modify a Member',
5583: drop => 'Drop Members',
5584: groups => 'Community Groups',
5585: },
5586: );
1.411 raeburn 5587: $linktext{'Placement'} = $linktext{'Course'};
1.318 raeburn 5588:
5589: my %linktitle = (
5590: 'Course' => {
5591: single => 'Add a user with the role of student to this course',
5592: drop => 'Remove a student from this course.',
5593: groups => 'Manage course groups',
5594: },
5595: 'Community' => {
5596: single => 'Add a user with the role of member to this community',
5597: drop => 'Remove a member from this community.',
5598: groups => 'Manage community groups',
5599: },
5600: );
5601:
1.411 raeburn 5602: $linktitle{'Placement'} = $linktitle{'Course'};
5603:
1.298 droeschl 5604: push(@{ $menu[0]->{items} }, #Category: Single Users
5605: {
1.318 raeburn 5606: linktext => $linktext{$crstype}{'single'},
1.298 droeschl 5607: #help => 'Course_Add_Student',
5608: icon => 'list-add.png',
5609: url => '/adm/createuser?action=singlestudent',
5610: permission => $permission->{'cusr'},
1.318 raeburn 5611: linktitle => $linktitle{$crstype}{'single'},
1.298 droeschl 5612: },
5613: );
5614:
5615: push(@{ $menu[1]->{items} }, #Category: Multiple Users
5616: {
1.318 raeburn 5617: linktext => $linktext{$crstype}{'drop'},
1.298 droeschl 5618: icon => 'edit-undo.png',
5619: #help => 'Course_Drop_Student',
5620: url => '/adm/createuser?action=drop',
5621: permission => $permission->{'cusr'},
1.318 raeburn 5622: linktitle => $linktitle{$crstype}{'drop'},
1.298 droeschl 5623: },
5624: );
5625: push(@{ $menu[2]->{items} }, #Category: Administration
1.428 raeburn 5626: {
5627: linktext => 'Helpdesk Access',
5628: icon => 'helpdesk-access.png',
5629: #help => 'Course_Helpdesk_Access',
5630: url => '/adm/createuser?action=helpdesk',
5631: permission => ($permission->{'owner'} || $permission->{'co-owner'}),
5632: linktitle => 'Helpdesk access options',
5633: },
5634: {
1.298 droeschl 5635: linktext => 'Custom Roles',
5636: icon => 'emblem-photos.png',
5637: #help => 'Course_Editing_Custom_Roles',
5638: url => '/adm/createuser?action=custom',
5639: permission => $permission->{'custom'},
5640: linktitle => 'Configure a custom role.',
5641: },
5642: {
1.318 raeburn 5643: linktext => $linktext{$crstype}{'groups'},
1.333 wenzelju 5644: icon => 'grps.png',
1.298 droeschl 5645: #help => 'Course_Manage_Group',
5646: url => '/adm/coursegroups?refpage=cusr',
5647: permission => $permission->{'grp_manage'},
1.318 raeburn 5648: linktitle => $linktitle{$crstype}{'groups'},
1.298 droeschl 5649: },
5650: {
1.328 wenzelju 5651: linktext => 'Change Log',
1.298 droeschl 5652: icon => 'document-properties.png',
5653: #help => 'Course_User_Logs',
5654: url => '/adm/createuser?action=changelogs',
1.418 raeburn 5655: permission => ($permission->{'view'} || $permission->{'cusr'}),
1.298 droeschl 5656: linktitle => 'View change log.',
5657: },
5658: );
1.277 raeburn 5659: if ($env{'course.'.$env{'request.course.id'}.'.internal.selfenroll_approval'}) {
1.298 droeschl 5660: push(@{ $menu[2]->{items} },
1.398 raeburn 5661: {
1.298 droeschl 5662: linktext => 'Enrollment Requests',
5663: icon => 'selfenrl-queue.png',
5664: #help => 'Course_Approve_Selfenroll',
5665: url => '/adm/createuser?action=selfenrollqueue',
1.398 raeburn 5666: permission => $permission->{'selfenrolladmin'},
1.298 droeschl 5667: linktitle =>'Approve or reject enrollment requests.',
5668: },
5669: );
1.277 raeburn 5670: }
1.298 droeschl 5671:
1.265 mielkec 5672: if (!exists($permission->{'cusr_section'})){
1.320 raeburn 5673: if ($crstype ne 'Community') {
5674: push(@{ $menu[2]->{items} },
5675: {
5676: linktext => 'Automated Enrollment',
5677: icon => 'roles.png',
5678: #help => 'Course_Automated_Enrollment',
5679: permission => (&Apache::lonnet::auto_run($cnum,$cdom)
1.418 raeburn 5680: && (($permission->{'cusr'}) ||
5681: ($permission->{'view'}))),
1.320 raeburn 5682: url => '/adm/populate',
5683: linktitle => 'Automated enrollment manager.',
5684: }
5685: );
5686: }
5687: push(@{ $menu[2]->{items} },
1.298 droeschl 5688: {
5689: linktext => 'User Self-Enrollment',
1.342 wenzelju 5690: icon => 'self_enroll.png',
1.298 droeschl 5691: #help => 'Course_Self_Enrollment',
5692: url => '/adm/createuser?action=selfenroll',
1.398 raeburn 5693: permission => $permission->{'selfenrolladmin'},
1.317 bisitz 5694: linktitle => 'Configure user self-enrollment.',
1.298 droeschl 5695: },
5696: );
5697: }
1.363 raeburn 5698: } elsif ($context eq 'author') {
1.370 raeburn 5699: push(@{ $menu[2]->{items} }, #Category: Administration
1.363 raeburn 5700: {
5701: linktext => 'Change Log',
5702: icon => 'document-properties.png',
5703: #help => 'Course_User_Logs',
5704: url => '/adm/createuser?action=changelogs',
5705: permission => $permission->{'cusr'},
5706: linktitle => 'View change log.',
5707: },
1.370 raeburn 5708: );
1.363 raeburn 5709: }
5710: return Apache::lonhtmlcommon::generate_menu(@menu);
1.250 raeburn 5711: # { text => 'View Log-in History',
5712: # help => 'Course_User_Logins',
5713: # action => 'logins',
5714: # permission => $permission->{'cusr'},
5715: # });
1.190 raeburn 5716: }
5717:
1.189 albertel 5718: sub restore_prev_selections {
5719: my %saveable_parameters = ('srchby' => 'scalar',
5720: 'srchin' => 'scalar',
5721: 'srchtype' => 'scalar',
5722: );
5723: &Apache::loncommon::store_settings('user','user_picker',
5724: \%saveable_parameters);
5725: &Apache::loncommon::restore_settings('user','user_picker',
5726: \%saveable_parameters);
5727: }
5728:
1.237 raeburn 5729: sub print_selfenroll_menu {
1.418 raeburn 5730: my ($r,$context,$cid,$cdom,$cnum,$currsettings,$additional,$readonly) = @_;
1.322 raeburn 5731: my $crstype = &Apache::loncommon::course_type();
1.398 raeburn 5732: my $formname = 'selfenroll';
1.237 raeburn 5733: my $nolink = 1;
1.398 raeburn 5734: my ($row,$lt) = &Apache::lonuserutils::get_selfenroll_titles();
1.237 raeburn 5735: my $groupslist = &Apache::lonuserutils::get_groupslist();
5736: my $setsec_js =
5737: &Apache::lonuserutils::setsections_javascript($formname,$groupslist);
1.249 raeburn 5738: my %alerts = &Apache::lonlocal::texthash(
5739: acto => 'Activation of self-enrollment was selected for the following domain(s)',
5740: butn => 'but no user types have been checked.',
5741: wilf => "Please uncheck 'activate' or check at least one type.",
5742: );
1.418 raeburn 5743: my $disabled;
5744: if ($readonly) {
5745: $disabled = ' disabled="disabled"';
5746: }
1.405 damieng 5747: &js_escape(\%alerts);
1.249 raeburn 5748: my $selfenroll_js = <<"ENDSCRIPT";
5749: function update_types(caller,num) {
5750: var delidx = getIndexByName('selfenroll_delete');
5751: var actidx = getIndexByName('selfenroll_activate');
5752: if (caller == 'selfenroll_all') {
5753: var selall;
5754: for (var i=0; i<document.$formname.selfenroll_all.length; i++) {
5755: if (document.$formname.selfenroll_all[i].checked) {
5756: selall = document.$formname.selfenroll_all[i].value;
5757: }
5758: }
5759: if (selall == 1) {
5760: if (delidx != -1) {
5761: if (document.$formname.selfenroll_delete.length) {
5762: for (var j=0; j<document.$formname.selfenroll_delete.length; j++) {
5763: document.$formname.selfenroll_delete[j].checked = true;
5764: }
5765: } else {
5766: document.$formname.elements[delidx].checked = true;
5767: }
5768: }
5769: if (actidx != -1) {
5770: if (document.$formname.selfenroll_activate.length) {
5771: for (var j=0; j<document.$formname.selfenroll_activate.length; j++) {
5772: document.$formname.selfenroll_activate[j].checked = false;
5773: }
5774: } else {
5775: document.$formname.elements[actidx].checked = false;
5776: }
5777: }
5778: document.$formname.selfenroll_newdom.selectedIndex = 0;
5779: }
5780: }
5781: if (caller == 'selfenroll_activate') {
5782: if (document.$formname.selfenroll_activate.length) {
5783: for (var j=0; j<document.$formname.selfenroll_activate.length; j++) {
5784: if (document.$formname.selfenroll_activate[j].value == num) {
5785: if (document.$formname.selfenroll_activate[j].checked) {
5786: for (var i=0; i<document.$formname.selfenroll_all.length; i++) {
5787: if (document.$formname.selfenroll_all[i].value == '1') {
5788: document.$formname.selfenroll_all[i].checked = false;
5789: }
5790: if (document.$formname.selfenroll_all[i].value == '0') {
5791: document.$formname.selfenroll_all[i].checked = true;
5792: }
5793: }
5794: }
5795: }
5796: }
5797: } else {
5798: for (var i=0; i<document.$formname.selfenroll_all.length; i++) {
5799: if (document.$formname.selfenroll_all[i].value == '1') {
5800: document.$formname.selfenroll_all[i].checked = false;
5801: }
5802: if (document.$formname.selfenroll_all[i].value == '0') {
5803: document.$formname.selfenroll_all[i].checked = true;
5804: }
5805: }
5806: }
5807: }
5808: if (caller == 'selfenroll_delete') {
5809: if (document.$formname.selfenroll_delete.length) {
5810: for (var j=0; j<document.$formname.selfenroll_delete.length; j++) {
5811: if (document.$formname.selfenroll_delete[j].value == num) {
5812: if (document.$formname.selfenroll_delete[j].checked) {
5813: var delindex = getIndexByName('selfenroll_types_'+num);
5814: if (delindex != -1) {
5815: if (document.$formname.elements[delindex].length) {
5816: for (var k=0; k<document.$formname.elements[delindex].length; k++) {
5817: document.$formname.elements[delindex][k].checked = false;
5818: }
5819: } else {
5820: document.$formname.elements[delindex].checked = false;
5821: }
5822: }
5823: }
5824: }
5825: }
5826: } else {
5827: if (document.$formname.selfenroll_delete.checked) {
5828: var delindex = getIndexByName('selfenroll_types_'+num);
5829: if (delindex != -1) {
5830: if (document.$formname.elements[delindex].length) {
5831: for (var k=0; k<document.$formname.elements[delindex].length; k++) {
5832: document.$formname.elements[delindex][k].checked = false;
5833: }
5834: } else {
5835: document.$formname.elements[delindex].checked = false;
5836: }
5837: }
5838: }
5839: }
5840: }
5841: return;
5842: }
5843:
5844: function validate_types(form) {
5845: var needaction = new Array();
5846: var countfail = 0;
5847: var actidx = getIndexByName('selfenroll_activate');
5848: if (actidx != -1) {
5849: if (document.$formname.selfenroll_activate.length) {
5850: for (var j=0; j<document.$formname.selfenroll_activate.length; j++) {
5851: var num = document.$formname.selfenroll_activate[j].value;
5852: if (document.$formname.selfenroll_activate[j].checked) {
5853: countfail = check_types(num,countfail,needaction)
5854: }
5855: }
5856: } else {
5857: if (document.$formname.selfenroll_activate.checked) {
1.398 raeburn 5858: var num = document.$formname.selfenroll_activate.value;
1.249 raeburn 5859: countfail = check_types(num,countfail,needaction)
5860: }
5861: }
5862: }
5863: if (countfail > 0) {
5864: var msg = "$alerts{'acto'}\\n";
5865: var loopend = needaction.length -1;
5866: if (loopend > 0) {
5867: for (var m=0; m<loopend; m++) {
5868: msg += needaction[m]+", ";
5869: }
5870: }
5871: msg += needaction[loopend]+"\\n$alerts{'butn'}\\n$alerts{'wilf'}";
5872: alert(msg);
5873: return;
5874: }
5875: setSections(form);
5876: }
5877:
5878: function check_types(num,countfail,needaction) {
1.441 raeburn 5879: var boxname = 'selfenroll_types_'+num;
5880: var typeidx = getIndexByName(boxname);
1.249 raeburn 5881: var count = 0;
5882: if (typeidx != -1) {
1.441 raeburn 5883: if (document.$formname.elements[boxname].length) {
5884: for (var k=0; k<document.$formname.elements[boxname].length; k++) {
5885: if (document.$formname.elements[boxname][k].checked) {
1.249 raeburn 5886: count ++;
5887: }
5888: }
5889: } else {
5890: if (document.$formname.elements[typeidx].checked) {
5891: count ++;
5892: }
5893: }
5894: if (count == 0) {
5895: var domidx = getIndexByName('selfenroll_dom_'+num);
5896: if (domidx != -1) {
5897: var domname = document.$formname.elements[domidx].value;
5898: needaction[countfail] = domname;
5899: countfail ++;
5900: }
5901: }
5902: }
5903: return countfail;
5904: }
5905:
1.398 raeburn 5906: function toggleNotify() {
5907: var selfenrollApproval = 0;
5908: if (document.$formname.selfenroll_approval.length) {
5909: for (var i=0; i<document.$formname.selfenroll_approval.length; i++) {
5910: if (document.$formname.selfenroll_approval[i].checked) {
5911: selfenrollApproval = document.$formname.selfenroll_approval[i].value;
5912: break;
5913: }
5914: }
5915: }
5916: if (document.getElementById('notified')) {
5917: if (selfenrollApproval == 0) {
5918: document.getElementById('notified').style.display='none';
5919: } else {
5920: document.getElementById('notified').style.display='block';
5921: }
5922: }
5923: return;
5924: }
5925:
1.249 raeburn 5926: function getIndexByName(item) {
5927: for (var i=0;i<document.$formname.elements.length;i++) {
5928: if (document.$formname.elements[i].name == item) {
5929: return i;
5930: }
5931: }
5932: return -1;
5933: }
5934: ENDSCRIPT
1.256 raeburn 5935:
1.237 raeburn 5936: my $output = '<script type="text/javascript">'."\n".
1.301 bisitz 5937: '// <![CDATA['."\n".
1.249 raeburn 5938: $setsec_js."\n".$selfenroll_js."\n".
1.301 bisitz 5939: '// ]]>'."\n".
1.237 raeburn 5940: '</script>'."\n".
1.256 raeburn 5941: '<h3>'.$lt->{'selfenroll'}.'</h3>'."\n";
1.400 raeburn 5942:
5943: my $visactions = &cat_visibility();
5944: my ($cathash,%cattype);
5945: my %domconfig = &Apache::lonnet::get_dom('configuration',['coursecategories'],$cdom);
5946: if (ref($domconfig{'coursecategories'}) eq 'HASH') {
5947: $cathash = $domconfig{'coursecategories'}{'cats'};
5948: $cattype{'auth'} = $domconfig{'coursecategories'}{'auth'};
5949: $cattype{'unauth'} = $domconfig{'coursecategories'}{'unauth'};
1.406 raeburn 5950: if ($cattype{'auth'} eq '') {
5951: $cattype{'auth'} = 'std';
5952: }
5953: if ($cattype{'unauth'} eq '') {
5954: $cattype{'unauth'} = 'std';
5955: }
1.400 raeburn 5956: } else {
5957: $cathash = {};
5958: $cattype{'auth'} = 'std';
5959: $cattype{'unauth'} = 'std';
5960: }
5961: if (($cattype{'auth'} eq 'none') && ($cattype{'unauth'} eq 'none')) {
5962: $r->print('<br /><span class="LC_warning">'.$visactions->{'miss'}.'</span><br />'.$visactions->{'yous'}.
5963: '<br />'.
5964: '<br />'.$visactions->{'take'}.'<ul>'.
5965: '<li>'.$visactions->{'dc_chgconf'}.'</li>'.
5966: '</ul>');
5967: } elsif (($cattype{'auth'} !~ /^(std|domonly)$/) && ($cattype{'unauth'} !~ /^(std|domonly)$/)) {
5968: if ($currsettings->{'uniquecode'}) {
5969: $r->print('<span class="LC_info">'.$visactions->{'vis'}.'</span>');
5970: } else {
5971: $r->print('<br /><span class="LC_warning">'.$visactions->{'miss'}.'</span><br />'.$visactions->{'yous'}.
5972: '<br />'.
5973: '<br />'.$visactions->{'take'}.'<ul>'.
5974: '<li>'.$visactions->{'dc_setcode'}.'</li>'.
5975: '</ul><br />');
5976: }
5977: } else {
5978: my ($visible,$cansetvis,$vismsgs) = &visible_in_stdcat($cdom,$cnum,\%domconfig);
5979: if (ref($visactions) eq 'HASH') {
5980: if ($visible) {
5981: $output .= '<p class="LC_info">'.$visactions->{'vis'}.'</p>';
5982: } else {
5983: $output .= '<p class="LC_warning">'.$visactions->{'miss'}.'</p>'
5984: .$visactions->{'yous'}.
5985: '<p>'.$visactions->{'gen'}.'<br />'.$visactions->{'coca'};
5986: if (ref($vismsgs) eq 'ARRAY') {
5987: $output .= '<br />'.$visactions->{'make'}.'<ul>';
5988: foreach my $item (@{$vismsgs}) {
5989: $output .= '<li>'.$visactions->{$item}.'</li>';
5990: }
5991: $output .= '</ul>';
1.256 raeburn 5992: }
1.400 raeburn 5993: $output .= '</p>';
1.256 raeburn 5994: }
5995: }
5996: }
1.398 raeburn 5997: my $actionhref = '/adm/createuser';
5998: if ($context eq 'domain') {
5999: $actionhref = '/adm/modifycourse';
6000: }
1.400 raeburn 6001:
6002: my %noedit;
6003: unless ($context eq 'domain') {
6004: %noedit = &get_noedit_fields($cdom,$cnum,$crstype,$row);
6005: }
1.398 raeburn 6006: $output .= '<form name="'.$formname.'" method="post" action="'.$actionhref.'">'."\n".
1.256 raeburn 6007: &Apache::lonhtmlcommon::start_pick_box();
1.237 raeburn 6008: if (ref($row) eq 'ARRAY') {
6009: foreach my $item (@{$row}) {
6010: my $title = $item;
6011: if (ref($lt) eq 'HASH') {
6012: $title = $lt->{$item};
6013: }
1.297 bisitz 6014: $output .= &Apache::lonhtmlcommon::row_title($title);
1.237 raeburn 6015: if ($item eq 'types') {
1.398 raeburn 6016: my $curr_types;
6017: if (ref($currsettings) eq 'HASH') {
6018: $curr_types = $currsettings->{'selfenroll_types'};
6019: }
1.400 raeburn 6020: if ($noedit{$item}) {
6021: if ($curr_types eq '*') {
6022: $output .= &mt('Any user in any domain');
6023: } else {
6024: my @entries = split(/;/,$curr_types);
6025: if (@entries > 0) {
6026: $output .= '<ul>';
6027: foreach my $entry (@entries) {
6028: my ($currdom,$typestr) = split(/:/,$entry);
6029: next if ($typestr eq '');
6030: my $domdesc = &Apache::lonnet::domain($currdom);
6031: my @currinsttypes = split(',',$typestr);
6032: my ($othertitle,$usertypes,$types) =
6033: &Apache::loncommon::sorted_inst_types($currdom);
6034: if ((ref($types) eq 'ARRAY') && (ref($usertypes) eq 'HASH')) {
6035: $usertypes->{'any'} = &mt('any user');
6036: if (keys(%{$usertypes}) > 0) {
6037: $usertypes->{'other'} = &mt('other users');
6038: }
6039: my @longinsttypes = map { $usertypes->{$_}; } @currinsttypes;
6040: $output .= '<li>'.$domdesc.':'.join(', ',@longinsttypes).'</li>';
6041: }
6042: }
6043: $output .= '</ul>';
6044: } else {
6045: $output .= &mt('None');
6046: }
6047: }
6048: $output .= '<br />'.&mt('(Set by Domain Coordinator)');
6049: next;
6050: }
1.241 raeburn 6051: my $showdomdesc = 1;
6052: my $includeempty = 1;
6053: my $num = 0;
6054: $output .= &Apache::loncommon::start_data_table().
6055: &Apache::loncommon::start_data_table_row()
6056: .'<td colspan="2"><span class="LC_nobreak"><label>'
6057: .&mt('Any user in any domain:')
6058: .' <input type="radio" name="selfenroll_all" value="1" ';
6059: if ($curr_types eq '*') {
6060: $output .= ' checked="checked" ';
6061: }
1.249 raeburn 6062: $output .= 'onchange="javascript:update_types('.
1.418 raeburn 6063: "'selfenroll_all'".');"'.$disabled.' />'.&mt('Yes').'</label>'.
1.249 raeburn 6064: ' <input type="radio" name="selfenroll_all" value="0" ';
1.241 raeburn 6065: if ($curr_types ne '*') {
6066: $output .= ' checked="checked" ';
6067: }
1.249 raeburn 6068: $output .= ' onchange="javascript:update_types('.
1.418 raeburn 6069: "'selfenroll_all'".');"'.$disabled.' />'.&mt('No').'</label></td>'.
1.249 raeburn 6070: &Apache::loncommon::end_data_table_row().
6071: &Apache::loncommon::end_data_table().
6072: &mt('Or').'<br />'.
6073: &Apache::loncommon::start_data_table();
1.241 raeburn 6074: my %currdoms;
1.249 raeburn 6075: if ($curr_types eq '') {
1.241 raeburn 6076: $output .= &new_selfenroll_dom_row($cdom,'0');
6077: } elsif ($curr_types ne '*') {
6078: my @entries = split(/;/,$curr_types);
6079: if (@entries > 0) {
6080: foreach my $entry (@entries) {
6081: my ($currdom,$typestr) = split(/:/,$entry);
6082: $currdoms{$currdom} = 1;
6083: my $domdesc = &Apache::lonnet::domain($currdom);
1.249 raeburn 6084: my @currinsttypes = split(',',$typestr);
1.241 raeburn 6085: $output .= &Apache::loncommon::start_data_table_row()
6086: .'<td valign="top"><span class="LC_nobreak">'.&mt('Domain:').'<b>'
6087: .' '.$domdesc.' ('.$currdom.')'
6088: .'</b><input type="hidden" name="selfenroll_dom_'.$num
6089: .'" value="'.$currdom.'" /></span><br />'
6090: .'<span class="LC_nobreak"><label><input type="checkbox" '
1.418 raeburn 6091: .'name="selfenroll_delete" value="'.$num.'" onchange="javascript:update_types('."'selfenroll_delete','$num'".');"'.$disabled.' />'
1.241 raeburn 6092: .&mt('Delete').'</label></span></td>';
1.249 raeburn 6093: $output .= '<td valign="top"> '.&mt('User types:').'<br />'
1.418 raeburn 6094: .&selfenroll_inst_types($num,$currdom,\@currinsttypes,$readonly).'</td>'
1.241 raeburn 6095: .&Apache::loncommon::end_data_table_row();
6096: $num ++;
6097: }
6098: }
6099: }
1.249 raeburn 6100: my $add_domtitle = &mt('Users in additional domain:');
1.241 raeburn 6101: if ($curr_types eq '*') {
1.249 raeburn 6102: $add_domtitle = &mt('Users in specific domain:');
1.241 raeburn 6103: } elsif ($curr_types eq '') {
1.249 raeburn 6104: $add_domtitle = &mt('Users in other domain:');
1.241 raeburn 6105: }
6106: $output .= &Apache::loncommon::start_data_table_row()
6107: .'<td colspan="2"><span class="LC_nobreak">'.$add_domtitle.'</span><br />'
6108: .&Apache::loncommon::select_dom_form('','selfenroll_newdom',
1.418 raeburn 6109: $includeempty,$showdomdesc,'','','',$readonly)
1.241 raeburn 6110: .'<input type="hidden" name="selfenroll_types_total" value="'.$num.'" />'
6111: .'</td>'.&Apache::loncommon::end_data_table_row()
6112: .&Apache::loncommon::end_data_table();
1.237 raeburn 6113: } elsif ($item eq 'registered') {
6114: my ($regon,$regoff);
1.398 raeburn 6115: my $registered;
6116: if (ref($currsettings) eq 'HASH') {
6117: $registered = $currsettings->{'selfenroll_registered'};
6118: }
1.400 raeburn 6119: if ($noedit{$item}) {
6120: if ($registered) {
6121: $output .= &mt('Must be registered in course');
6122: } else {
6123: $output .= &mt('No requirement');
6124: }
6125: $output .= '<br />'.&mt('(Set by Domain Coordinator)');
6126: next;
6127: }
1.398 raeburn 6128: if ($registered) {
1.237 raeburn 6129: $regon = ' checked="checked" ';
1.419 raeburn 6130: $regoff = '';
1.237 raeburn 6131: } else {
1.419 raeburn 6132: $regon = '';
1.237 raeburn 6133: $regoff = ' checked="checked" ';
6134: }
6135: $output .= '<label>'.
1.419 raeburn 6136: '<input type="radio" name="selfenroll_registered" value="1"'.$regon.$disabled.' />'.
1.244 bisitz 6137: &mt('Yes').'</label> <label>'.
1.419 raeburn 6138: '<input type="radio" name="selfenroll_registered" value="0"'.$regoff.$disabled.' />'.
1.244 bisitz 6139: &mt('No').'</label>';
1.237 raeburn 6140: } elsif ($item eq 'enroll_dates') {
1.398 raeburn 6141: my ($starttime,$endtime);
6142: if (ref($currsettings) eq 'HASH') {
6143: $starttime = $currsettings->{'selfenroll_start_date'};
6144: $endtime = $currsettings->{'selfenroll_end_date'};
6145: if ($starttime eq '') {
6146: $starttime = $currsettings->{'default_enrollment_start_date'};
6147: }
6148: if ($endtime eq '') {
6149: $endtime = $currsettings->{'default_enrollment_end_date'};
6150: }
1.237 raeburn 6151: }
1.400 raeburn 6152: if ($noedit{$item}) {
6153: $output .= &mt('From: [_1], to: [_2]',&Apache::lonlocal::locallocaltime($starttime),
6154: &Apache::lonlocal::locallocaltime($endtime));
6155: $output .= '<br />'.&mt('(Set by Domain Coordinator)');
6156: next;
6157: }
1.237 raeburn 6158: my $startform =
6159: &Apache::lonhtmlcommon::date_setter($formname,'selfenroll_start_date',$starttime,
1.418 raeburn 6160: $disabled,undef,undef,undef,undef,undef,undef,$nolink);
1.237 raeburn 6161: my $endform =
6162: &Apache::lonhtmlcommon::date_setter($formname,'selfenroll_end_date',$endtime,
1.418 raeburn 6163: $disabled,undef,undef,undef,undef,undef,undef,$nolink);
1.237 raeburn 6164: $output .= &selfenroll_date_forms($startform,$endform);
6165: } elsif ($item eq 'access_dates') {
1.398 raeburn 6166: my ($starttime,$endtime);
6167: if (ref($currsettings) eq 'HASH') {
6168: $starttime = $currsettings->{'selfenroll_start_access'};
6169: $endtime = $currsettings->{'selfenroll_end_access'};
6170: if ($starttime eq '') {
6171: $starttime = $currsettings->{'default_enrollment_start_date'};
6172: }
6173: if ($endtime eq '') {
6174: $endtime = $currsettings->{'default_enrollment_end_date'};
6175: }
1.237 raeburn 6176: }
1.400 raeburn 6177: if ($noedit{$item}) {
6178: $output .= &mt('From: [_1], to: [_2]',&Apache::lonlocal::locallocaltime($starttime),
6179: &Apache::lonlocal::locallocaltime($endtime));
6180: $output .= '<br />'.&mt('(Set by Domain Coordinator)');
6181: next;
6182: }
1.237 raeburn 6183: my $startform =
6184: &Apache::lonhtmlcommon::date_setter($formname,'selfenroll_start_access',$starttime,
1.418 raeburn 6185: $disabled,undef,undef,undef,undef,undef,undef,$nolink);
1.237 raeburn 6186: my $endform =
6187: &Apache::lonhtmlcommon::date_setter($formname,'selfenroll_end_access',$endtime,
1.418 raeburn 6188: $disabled,undef,undef,undef,undef,undef,undef,$nolink);
1.237 raeburn 6189: $output .= &selfenroll_date_forms($startform,$endform);
6190: } elsif ($item eq 'section') {
1.398 raeburn 6191: my $currsec;
6192: if (ref($currsettings) eq 'HASH') {
6193: $currsec = $currsettings->{'selfenroll_section'};
6194: }
1.237 raeburn 6195: my %sections_count = &Apache::loncommon::get_sections($cdom,$cnum);
6196: my $newsecval;
6197: if ($currsec ne 'none' && $currsec ne '') {
6198: if (!defined($sections_count{$currsec})) {
6199: $newsecval = $currsec;
6200: }
6201: }
1.400 raeburn 6202: if ($noedit{$item}) {
6203: if ($currsec ne '') {
6204: $output .= $currsec;
6205: } else {
6206: $output .= &mt('No specific section');
6207: }
6208: $output .= '<br />'.&mt('(Set by Domain Coordinator)');
6209: next;
6210: }
1.237 raeburn 6211: my $sections_select =
1.418 raeburn 6212: &Apache::lonuserutils::course_sections(\%sections_count,'st',$currsec,$disabled);
1.237 raeburn 6213: $output .= '<table class="LC_createuser">'."\n".
6214: '<tr class="LC_section_row">'."\n".
6215: '<td align="center">'.&mt('Existing sections')."\n".
6216: '<br />'.$sections_select.'</td><td align="center">'.
6217: &mt('New section').'<br />'."\n".
1.418 raeburn 6218: '<input type="text" name="newsec" size="15" value="'.$newsecval.'"'.$disabled.' />'."\n".
1.237 raeburn 6219: '<input type="hidden" name="sections" value="" />'."\n".
6220: '</td></tr></table>'."\n";
1.276 raeburn 6221: } elsif ($item eq 'approval') {
1.398 raeburn 6222: my ($currnotified,$currapproval,%appchecked);
6223: my %selfdescs = &Apache::lonuserutils::selfenroll_default_descs();
1.430 raeburn 6224: if (ref($currsettings) eq 'HASH') {
1.398 raeburn 6225: $currnotified = $currsettings->{'selfenroll_notifylist'};
6226: $currapproval = $currsettings->{'selfenroll_approval'};
6227: }
6228: if ($currapproval !~ /^[012]$/) {
6229: $currapproval = 0;
6230: }
1.400 raeburn 6231: if ($noedit{$item}) {
6232: $output .= $selfdescs{'approval'}{$currapproval}.
6233: '<br />'.&mt('(Set by Domain Coordinator)');
6234: next;
6235: }
1.398 raeburn 6236: $appchecked{$currapproval} = ' checked="checked"';
6237: for my $i (0..2) {
6238: $output .= '<label>'.
6239: '<input type="radio" name="selfenroll_approval" value="'.$i.'"'.
1.418 raeburn 6240: $appchecked{$i}.' onclick="toggleNotify();"'.$disabled.' />'.
6241: $selfdescs{'approval'}{$i}.'</label>'.(' 'x2);
1.276 raeburn 6242: }
6243: my %advhash = &Apache::lonnet::get_course_adv_roles($cid,1);
6244: my (@ccs,%notified);
1.322 raeburn 6245: my $ccrole = 'cc';
6246: if ($crstype eq 'Community') {
6247: $ccrole = 'co';
6248: }
6249: if ($advhash{$ccrole}) {
6250: @ccs = split(/,/,$advhash{$ccrole});
1.276 raeburn 6251: }
6252: if ($currnotified) {
6253: foreach my $current (split(/,/,$currnotified)) {
6254: $notified{$current} = 1;
6255: if (!grep(/^\Q$current\E$/,@ccs)) {
6256: push(@ccs,$current);
6257: }
6258: }
6259: }
6260: if (@ccs) {
1.398 raeburn 6261: my $style;
6262: unless ($currapproval) {
6263: $style = ' style="display: none;"';
6264: }
6265: $output .= '<br /><div id="notified"'.$style.'>'.
6266: &mt('Personnel to be notified when an enrollment request needs approval, or has been approved:').' '.
6267: &Apache::loncommon::start_data_table().
1.276 raeburn 6268: &Apache::loncommon::start_data_table_row();
6269: my $count = 0;
6270: my $numcols = 4;
6271: foreach my $cc (sort(@ccs)) {
6272: my $notifyon;
6273: my ($ccuname,$ccudom) = split(/:/,$cc);
6274: if ($notified{$cc}) {
6275: $notifyon = ' checked="checked" ';
6276: }
6277: if ($count && !$count%$numcols) {
6278: $output .= &Apache::loncommon::end_data_table_row().
6279: &Apache::loncommon::start_data_table_row()
6280: }
6281: $output .= '<td><span class="LC_nobreak"><label>'.
1.418 raeburn 6282: '<input type="checkbox" name="selfenroll_notify"'.$notifyon.' value="'.$cc.'"'.$disabled.' />'.
1.276 raeburn 6283: &Apache::loncommon::plainname($ccuname,$ccudom).
6284: '</label></span></td>';
1.343 raeburn 6285: $count ++;
1.276 raeburn 6286: }
6287: my $rem = $count%$numcols;
6288: if ($rem) {
6289: my $emptycols = $numcols - $rem;
6290: for (my $i=0; $i<$emptycols; $i++) {
6291: $output .= '<td> </td>';
6292: }
6293: }
6294: $output .= &Apache::loncommon::end_data_table_row().
1.398 raeburn 6295: &Apache::loncommon::end_data_table().
6296: '</div>';
1.276 raeburn 6297: }
6298: } elsif ($item eq 'limit') {
1.398 raeburn 6299: my ($crslimit,$selflimit,$nolimit,$currlim,$currcap);
6300: if (ref($currsettings) eq 'HASH') {
6301: $currlim = $currsettings->{'selfenroll_limit'};
6302: $currcap = $currsettings->{'selfenroll_cap'};
6303: }
1.400 raeburn 6304: if ($noedit{$item}) {
6305: if (($currlim eq 'allstudents') || ($currlim eq 'selfenrolled')) {
6306: if ($currlim eq 'allstudents') {
6307: $output .= &mt('Limit by total students');
6308: } elsif ($currlim eq 'selfenrolled') {
6309: $output .= &mt('Limit by total self-enrolled students');
6310: }
6311: $output .= ' '.&mt('Maximum: [_1]',$currcap).
6312: '<br />'.&mt('(Set by Domain Coordinator)');
6313: } else {
6314: $output .= &mt('No limit').'<br />'.&mt('(Set by Domain Coordinator)');
6315: }
6316: next;
6317: }
1.276 raeburn 6318: if ($currlim eq 'allstudents') {
6319: $crslimit = ' checked="checked" ';
6320: $selflimit = ' ';
6321: $nolimit = ' ';
6322: } elsif ($currlim eq 'selfenrolled') {
6323: $crslimit = ' ';
6324: $selflimit = ' checked="checked" ';
6325: $nolimit = ' ';
6326: } else {
6327: $crslimit = ' ';
6328: $selflimit = ' ';
1.398 raeburn 6329: $nolimit = ' checked="checked" ';
1.276 raeburn 6330: }
6331: $output .= '<table><tr><td><label>'.
1.418 raeburn 6332: '<input type="radio" name="selfenroll_limit" value="none"'.$nolimit.$disabled.'/>'.
1.276 raeburn 6333: &mt('No limit').'</label></td><td><label>'.
1.418 raeburn 6334: '<input type="radio" name="selfenroll_limit" value="allstudents"'.$crslimit.$disabled.'/>'.
1.276 raeburn 6335: &mt('Limit by total students').'</label></td><td><label>'.
1.418 raeburn 6336: '<input type="radio" name="selfenroll_limit" value="selfenrolled"'.$selflimit.$disabled.'/>'.
1.276 raeburn 6337: &mt('Limit by total self-enrolled students').
6338: '</td></tr><tr>'.
6339: '<td> </td><td colspan="2"><span class="LC_nobreak">'.
6340: (' 'x3).&mt('Maximum number allowed: ').
1.418 raeburn 6341: '<input type="text" name="selfenroll_cap" size = "5" value="'.$currcap.'"'.$disabled.' /></td></tr></table>';
1.237 raeburn 6342: }
6343: $output .= &Apache::lonhtmlcommon::row_closure(1);
6344: }
6345: }
1.418 raeburn 6346: $output .= &Apache::lonhtmlcommon::end_pick_box().'<br />';
6347: unless ($readonly) {
6348: $output .= '<input type="button" name="selfenrollconf" value="'
6349: .&mt('Save').'" onclick="validate_types(this.form);" />';
6350: }
6351: $output .= '<input type="hidden" name="action" value="selfenroll" />'
6352: .'<input type="hidden" name="state" value="done" />'."\n"
6353: .$additional.'</form>';
1.237 raeburn 6354: $r->print($output);
6355: return;
6356: }
6357:
1.400 raeburn 6358: sub get_noedit_fields {
6359: my ($cdom,$cnum,$crstype,$row) = @_;
6360: my %noedit;
6361: if (ref($row) eq 'ARRAY') {
6362: my %settings = &Apache::lonnet::get('environment',['internal.coursecode','internal.textbook',
6363: 'internal.selfenrollmgrdc',
6364: 'internal.selfenrollmgrcc'],$cdom,$cnum);
6365: my $type = &Apache::lonuserutils::get_extended_type($cdom,$cnum,$crstype,\%settings);
6366: my (%specific_managebydc,%specific_managebycc,%default_managebydc);
6367: map { $specific_managebydc{$_} = 1; } (split(/,/,$settings{'internal.selfenrollmgrdc'}));
6368: map { $specific_managebycc{$_} = 1; } (split(/,/,$settings{'internal.selfenrollmgrcc'}));
6369: my %domdefaults = &Apache::lonnet::get_domain_defaults($cdom);
6370: map { $default_managebydc{$_} = 1; } (split(/,/,$domdefaults{$type.'selfenrolladmdc'}));
6371:
6372: foreach my $item (@{$row}) {
6373: next if ($specific_managebycc{$item});
6374: if (($specific_managebydc{$item}) || ($default_managebydc{$item})) {
6375: $noedit{$item} = 1;
6376: }
6377: }
6378: }
6379: return %noedit;
6380: }
6381:
6382: sub visible_in_stdcat {
6383: my ($cdom,$cnum,$domconf) = @_;
6384: my ($cathash,%settable,@vismsgs,$cansetvis,$visible);
6385: unless (ref($domconf) eq 'HASH') {
6386: return ($visible,$cansetvis,\@vismsgs);
6387: }
6388: if (ref($domconf->{'coursecategories'}) eq 'HASH') {
6389: if ($domconf->{'coursecategories'}{'togglecats'} eq 'crs') {
1.256 raeburn 6390: $settable{'togglecats'} = 1;
6391: }
1.400 raeburn 6392: if ($domconf->{'coursecategories'}{'categorize'} eq 'crs') {
1.256 raeburn 6393: $settable{'categorize'} = 1;
6394: }
1.400 raeburn 6395: $cathash = $domconf->{'coursecategories'}{'cats'};
1.256 raeburn 6396: }
1.260 raeburn 6397: if ($settable{'togglecats'} && $settable{'categorize'}) {
1.256 raeburn 6398: $cansetvis = &mt('You are able to both assign a course category and choose to exclude this course from the catalog.');
6399: } elsif ($settable{'togglecats'}) {
6400: $cansetvis = &mt('You are able to choose to exclude this course from the catalog, but only a Domain Coordinator may assign a course category.');
1.260 raeburn 6401: } elsif ($settable{'categorize'}) {
1.256 raeburn 6402: $cansetvis = &mt('You may assign a course category, but only a Domain Coordinator may choose to exclude this course from the catalog.');
6403: } else {
6404: $cansetvis = &mt('Only a Domain Coordinator may assign a course category or choose to exclude this course from the catalog.');
6405: }
6406:
6407: my %currsettings =
6408: &Apache::lonnet::get('environment',['hidefromcat','categories','internal.coursecode'],
6409: $cdom,$cnum);
1.400 raeburn 6410: $visible = 0;
1.256 raeburn 6411: if ($currsettings{'internal.coursecode'} ne '') {
1.400 raeburn 6412: if (ref($domconf->{'coursecategories'}) eq 'HASH') {
6413: $cathash = $domconf->{'coursecategories'}{'cats'};
1.256 raeburn 6414: if (ref($cathash) eq 'HASH') {
6415: if ($cathash->{'instcode::0'} eq '') {
6416: push(@vismsgs,'dc_addinst');
6417: } else {
6418: $visible = 1;
6419: }
6420: } else {
6421: $visible = 1;
6422: }
6423: } else {
6424: $visible = 1;
6425: }
6426: } else {
6427: if (ref($cathash) eq 'HASH') {
6428: if ($cathash->{'instcode::0'} ne '') {
6429: push(@vismsgs,'dc_instcode');
6430: }
6431: } else {
6432: push(@vismsgs,'dc_instcode');
6433: }
6434: }
6435: if ($currsettings{'categories'} ne '') {
6436: my $cathash;
1.400 raeburn 6437: if (ref($domconf->{'coursecategories'}) eq 'HASH') {
6438: $cathash = $domconf->{'coursecategories'}{'cats'};
1.256 raeburn 6439: if (ref($cathash) eq 'HASH') {
6440: if (keys(%{$cathash}) == 0) {
6441: push(@vismsgs,'dc_catalog');
6442: } elsif ((keys(%{$cathash}) == 1) && ($cathash->{'instcode::0'} ne '')) {
6443: push(@vismsgs,'dc_categories');
6444: } else {
6445: my @currcategories = split('&',$currsettings{'categories'});
6446: my $matched = 0;
6447: foreach my $cat (@currcategories) {
6448: if ($cathash->{$cat} ne '') {
6449: $visible = 1;
6450: $matched = 1;
6451: last;
6452: }
6453: }
6454: if (!$matched) {
1.260 raeburn 6455: if ($settable{'categorize'}) {
1.256 raeburn 6456: push(@vismsgs,'chgcat');
6457: } else {
6458: push(@vismsgs,'dc_chgcat');
6459: }
6460: }
6461: }
6462: }
6463: }
6464: } else {
6465: if (ref($cathash) eq 'HASH') {
6466: if ((keys(%{$cathash}) > 1) ||
6467: (keys(%{$cathash}) == 1) && ($cathash->{'instcode::0'} eq '')) {
1.260 raeburn 6468: if ($settable{'categorize'}) {
1.256 raeburn 6469: push(@vismsgs,'addcat');
6470: } else {
6471: push(@vismsgs,'dc_addcat');
6472: }
6473: }
6474: }
6475: }
6476: if ($currsettings{'hidefromcat'} eq 'yes') {
6477: $visible = 0;
6478: if ($settable{'togglecats'}) {
6479: unshift(@vismsgs,'unhide');
6480: } else {
6481: unshift(@vismsgs,'dc_unhide')
6482: }
6483: }
1.400 raeburn 6484: return ($visible,$cansetvis,\@vismsgs);
6485: }
6486:
6487: sub cat_visibility {
6488: my %visactions = &Apache::lonlocal::texthash(
6489: vis => 'This course/community currently appears in the Course/Community Catalog for this domain.',
6490: gen => 'Courses can be both self-cataloging, based on an institutional code (e.g., fs08phy231), or can be assigned categories from a hierarchy defined for the domain.',
6491: miss => 'This course/community does not currently appear in the Course/Community Catalog for this domain.',
6492: none => 'Display of a course catalog is disabled for this domain.',
6493: yous => 'You should remedy this if you plan to allow self-enrollment, otherwise students will have difficulty finding this course.',
6494: coca => 'Courses can be absent from the Catalog, because they do not have an institutional code, have no assigned category, or have been specifically excluded.',
6495: make => 'Make any changes to self-enrollment settings below, click "Save", then take action to include the course in the Catalog:',
6496: take => 'Take the following action to ensure the course appears in the Catalog:',
6497: dc_chgconf => 'Ask a domain coordinator to change the Catalog type for this domain.',
6498: dc_setcode => 'Ask a domain coordinator to assign a six character code to the course',
6499: dc_unhide => 'Ask a domain coordinator to change the "Exclude from course catalog" setting.',
6500: dc_addinst => 'Ask a domain coordinator to enable display the catalog of "Official courses (with institutional codes)".',
6501: dc_instcode => 'Ask a domain coordinator to assign an institutional code (if this is an official course).',
6502: dc_catalog => 'Ask a domain coordinator to enable or create at least one course category in the domain.',
6503: dc_categories => 'Ask a domain coordinator to create a hierarchy of categories and sub categories for courses in the domain.',
6504: dc_chgcat => 'Ask a domain coordinator to change the category assigned to the course, as the one currently assigned is no longer used in the domain',
6505: dc_addcat => 'Ask a domain coordinator to assign a category to the course.',
6506: );
6507: $visactions{'unhide'} = &mt('Use [_1]Categorize course[_2] to change the "Exclude from course catalog" setting.','<a href="/adm/courseprefs?phase=display&actions=courseinfo">','</a>"');
6508: $visactions{'chgcat'} = &mt('Use [_1]Categorize course[_2] to change the category assigned to the course, as the one currently assigned is no longer used in the domain.','"<a href="/adm/courseprefs?phase=display&actions=courseinfo">','</a>"');
6509: $visactions{'addcat'} = &mt('Use [_1]Categorize course[_2] to assign a category to the course.','"<a href="/adm/courseprefs?phase=display&actions=courseinfo">','</a>"');
6510: return \%visactions;
1.256 raeburn 6511: }
6512:
1.241 raeburn 6513: sub new_selfenroll_dom_row {
6514: my ($newdom,$num) = @_;
6515: my $domdesc = &Apache::lonnet::domain($newdom);
6516: my $output;
6517: if ($domdesc ne '') {
6518: $output .= &Apache::loncommon::start_data_table_row()
6519: .'<td valign="top"><span class="LC_nobreak">'.&mt('Domain:').' <b>'.$domdesc
6520: .' ('.$newdom.')</b><input type="hidden" name="selfenroll_dom_'.$num
1.249 raeburn 6521: .'" value="'.$newdom.'" /></span><br />'
6522: .'<span class="LC_nobreak"><label><input type="checkbox" '
6523: .'name="selfenroll_activate" value="'.$num.'" '
6524: .'onchange="javascript:update_types('
6525: ."'selfenroll_activate','$num'".');" />'
6526: .&mt('Activate').'</label></span></td>';
1.241 raeburn 6527: my @currinsttypes;
6528: $output .= '<td>'.&mt('User types:').'<br />'
6529: .&selfenroll_inst_types($num,$newdom,\@currinsttypes).'</td>'
6530: .&Apache::loncommon::end_data_table_row();
6531: }
6532: return $output;
6533: }
6534:
6535: sub selfenroll_inst_types {
1.418 raeburn 6536: my ($num,$currdom,$currinsttypes,$readonly) = @_;
1.241 raeburn 6537: my $output;
6538: my $numinrow = 4;
6539: my $count = 0;
6540: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($currdom);
1.247 raeburn 6541: my $othervalue = 'any';
1.418 raeburn 6542: my $disabled;
6543: if ($readonly) {
6544: $disabled = ' disabled="disabled"';
6545: }
1.241 raeburn 6546: if ((ref($types) eq 'ARRAY') && (ref($usertypes) eq 'HASH')) {
1.251 raeburn 6547: if (keys(%{$usertypes}) > 0) {
1.247 raeburn 6548: $othervalue = 'other';
6549: }
1.241 raeburn 6550: $output .= '<table><tr>';
6551: foreach my $type (@{$types}) {
6552: if (($count > 0) && ($count%$numinrow == 0)) {
6553: $output .= '</tr><tr>';
6554: }
6555: if (defined($usertypes->{$type})) {
1.257 raeburn 6556: my $esc_type = &escape($type);
1.241 raeburn 6557: $output .= '<td><span class="LC_nobreak"><label><input type = "checkbox" value="'.
1.257 raeburn 6558: $esc_type.'" ';
1.241 raeburn 6559: if (ref($currinsttypes) eq 'ARRAY') {
6560: if (@{$currinsttypes} > 0) {
1.249 raeburn 6561: if (grep(/^any$/,@{$currinsttypes})) {
6562: $output .= 'checked="checked"';
1.257 raeburn 6563: } elsif (grep(/^\Q$esc_type\E$/,@{$currinsttypes})) {
1.241 raeburn 6564: $output .= 'checked="checked"';
6565: }
1.249 raeburn 6566: } else {
6567: $output .= 'checked="checked"';
1.241 raeburn 6568: }
6569: }
1.418 raeburn 6570: $output .= ' name="selfenroll_types_'.$num.'"'.$disabled.' />'.$usertypes->{$type}.'</label></span></td>';
1.241 raeburn 6571: }
6572: $count ++;
6573: }
6574: if (($count > 0) && ($count%$numinrow == 0)) {
6575: $output .= '</tr><tr>';
6576: }
1.249 raeburn 6577: $output .= '<td><span class="LC_nobreak"><label><input type = "checkbox" value="'.$othervalue.'"';
1.241 raeburn 6578: if (ref($currinsttypes) eq 'ARRAY') {
6579: if (@{$currinsttypes} > 0) {
1.249 raeburn 6580: if (grep(/^any$/,@{$currinsttypes})) {
6581: $output .= ' checked="checked"';
6582: } elsif ($othervalue eq 'other') {
6583: if (grep(/^\Q$othervalue\E$/,@{$currinsttypes})) {
6584: $output .= ' checked="checked"';
6585: }
1.241 raeburn 6586: }
1.249 raeburn 6587: } else {
6588: $output .= ' checked="checked"';
1.241 raeburn 6589: }
1.249 raeburn 6590: } else {
6591: $output .= ' checked="checked"';
1.241 raeburn 6592: }
1.418 raeburn 6593: $output .= ' name="selfenroll_types_'.$num.'"'.$disabled.' />'.$othertitle.'</label></span></td></tr></table>';
1.241 raeburn 6594: }
6595: return $output;
6596: }
6597:
1.237 raeburn 6598: sub selfenroll_date_forms {
6599: my ($startform,$endform) = @_;
6600: my $output .= &Apache::lonhtmlcommon::start_pick_box()."\n".
1.244 bisitz 6601: &Apache::lonhtmlcommon::row_title(&mt('Start date'),
1.237 raeburn 6602: 'LC_oddrow_value')."\n".
6603: $startform."\n".
6604: &Apache::lonhtmlcommon::row_closure(1).
1.244 bisitz 6605: &Apache::lonhtmlcommon::row_title(&mt('End date'),
1.237 raeburn 6606: 'LC_oddrow_value')."\n".
6607: $endform."\n".
6608: &Apache::lonhtmlcommon::row_closure(1).
6609: &Apache::lonhtmlcommon::end_pick_box();
6610: return $output;
6611: }
6612:
1.239 raeburn 6613: sub print_userchangelogs_display {
1.415 raeburn 6614: my ($r,$context,$permission,$brcrum) = @_;
1.363 raeburn 6615: my $formname = 'rolelog';
1.418 raeburn 6616: my ($username,$domain,$crstype,$viewablesec,%roleslog);
1.363 raeburn 6617: if ($context eq 'domain') {
6618: $domain = $env{'request.role.domain'};
6619: %roleslog=&Apache::lonnet::dump_dom('nohist_rolelog',$domain);
6620: } else {
6621: if ($context eq 'course') {
6622: $domain = $env{'course.'.$env{'request.course.id'}.'.domain'};
6623: $username = $env{'course.'.$env{'request.course.id'}.'.num'};
6624: $crstype = &Apache::loncommon::course_type();
1.418 raeburn 6625: $viewablesec = &Apache::lonuserutils::viewable_section($permission);
1.363 raeburn 6626: my %saveable_parameters = ('show' => 'scalar',);
6627: &Apache::loncommon::store_course_settings('roles_log',
6628: \%saveable_parameters);
6629: &Apache::loncommon::restore_course_settings('roles_log',
6630: \%saveable_parameters);
6631: } elsif ($context eq 'author') {
6632: $domain = $env{'user.domain'};
6633: if ($env{'request.role'} =~ m{^au\./\Q$domain\E/$}) {
6634: $username = $env{'user.name'};
6635: } else {
6636: undef($domain);
6637: }
6638: }
6639: if ($domain ne '' && $username ne '') {
6640: %roleslog=&Apache::lonnet::dump('nohist_rolelog',$domain,$username);
6641: }
6642: }
1.239 raeburn 6643: if ((keys(%roleslog))[0]=~/^error\:/) { undef(%roleslog); }
6644:
1.415 raeburn 6645: my $helpitem;
6646: if ($context eq 'course') {
6647: $helpitem = 'Course_User_Logs';
1.439 raeburn 6648: } elsif ($context eq 'domain') {
6649: $helpitem = 'Domain_Role_Logs';
6650: } elsif ($context eq 'author') {
6651: $helpitem = 'Author_User_Logs';
1.415 raeburn 6652: }
6653: push (@{$brcrum},
6654: {href => '/adm/createuser?action=changelogs',
6655: text => 'User Management Logs',
6656: help => $helpitem});
6657: my $bread_crumbs_component = 'User Changes';
6658: my $args = { bread_crumbs => $brcrum,
6659: bread_crumbs_component => $bread_crumbs_component};
6660:
6661: # Create navigation javascript
6662: my $jsnav = &userlogdisplay_js($formname);
6663:
6664: my $jscript = (<<ENDSCRIPT);
6665: <script type="text/javascript">
6666: // <![CDATA[
6667: $jsnav
6668: // ]]>
6669: </script>
6670: ENDSCRIPT
6671:
6672: # print page header
6673: $r->print(&header($jscript,$args));
6674:
1.239 raeburn 6675: # set defaults
6676: my $now = time();
6677: my $defstart = $now - (7*24*3600); #7 days ago
6678: my %defaults = (
6679: page => '1',
6680: show => '10',
6681: role => 'any',
6682: chgcontext => 'any',
6683: rolelog_start_date => $defstart,
6684: rolelog_end_date => $now,
6685: );
6686: my $more_records = 0;
6687:
6688: # set current
6689: my %curr;
6690: foreach my $item ('show','page','role','chgcontext') {
6691: $curr{$item} = $env{'form.'.$item};
6692: }
6693: my ($startdate,$enddate) =
6694: &Apache::lonuserutils::get_dates_from_form('rolelog_start_date','rolelog_end_date');
6695: $curr{'rolelog_start_date'} = $startdate;
6696: $curr{'rolelog_end_date'} = $enddate;
6697: foreach my $key (keys(%defaults)) {
6698: if ($curr{$key} eq '') {
6699: $curr{$key} = $defaults{$key};
6700: }
6701: }
1.248 raeburn 6702: my (%whodunit,%changed,$version);
6703: ($version) = ($r->dir_config('lonVersion') =~ /^([\d\.]+)\-/);
1.239 raeburn 6704: my ($minshown,$maxshown);
1.255 raeburn 6705: $minshown = 1;
1.239 raeburn 6706: my $count = 0;
1.415 raeburn 6707: if ($curr{'show'} =~ /\D/) {
6708: $curr{'page'} = 1;
6709: } else {
1.239 raeburn 6710: $maxshown = $curr{'page'} * $curr{'show'};
6711: if ($curr{'page'} > 1) {
6712: $minshown = 1 + ($curr{'page'} - 1) * $curr{'show'};
6713: }
6714: }
1.301 bisitz 6715:
1.327 raeburn 6716: # Form Header
6717: $r->print('<form action="/adm/createuser" method="post" name="'.$formname.'">'.
1.363 raeburn 6718: &role_display_filter($context,$formname,$domain,$username,\%curr,
6719: $version,$crstype));
1.327 raeburn 6720:
6721: my $showntableheader = 0;
6722:
6723: # Table Header
6724: my $tableheader =
6725: &Apache::loncommon::start_data_table_header_row()
6726: .'<th> </th>'
6727: .'<th>'.&mt('When').'</th>'
6728: .'<th>'.&mt('Who made the change').'</th>'
6729: .'<th>'.&mt('Changed User').'</th>'
1.363 raeburn 6730: .'<th>'.&mt('Role').'</th>';
6731:
6732: if ($context eq 'course') {
6733: $tableheader .= '<th>'.&mt('Section').'</th>';
6734: }
6735: $tableheader .=
6736: '<th>'.&mt('Context').'</th>'
1.327 raeburn 6737: .'<th>'.&mt('Start').'</th>'
6738: .'<th>'.&mt('End').'</th>'
6739: .&Apache::loncommon::end_data_table_header_row();
6740:
6741: # Display user change log data
1.239 raeburn 6742: foreach my $id (sort { $roleslog{$b}{'exe_time'}<=>$roleslog{$a}{'exe_time'} } (keys(%roleslog))) {
6743: next if (($roleslog{$id}{'exe_time'} < $curr{'rolelog_start_date'}) ||
6744: ($roleslog{$id}{'exe_time'} > $curr{'rolelog_end_date'}));
1.415 raeburn 6745: if ($curr{'show'} !~ /\D/) {
1.239 raeburn 6746: if ($count >= $curr{'page'} * $curr{'show'}) {
6747: $more_records = 1;
6748: last;
6749: }
6750: }
6751: if ($curr{'role'} ne 'any') {
6752: next if ($roleslog{$id}{'logentry'}{'role'} ne $curr{'role'});
6753: }
6754: if ($curr{'chgcontext'} ne 'any') {
6755: if ($curr{'chgcontext'} eq 'selfenroll') {
6756: next if (!$roleslog{$id}{'logentry'}{'selfenroll'});
6757: } else {
6758: next if ($roleslog{$id}{'logentry'}{'context'} ne $curr{'chgcontext'});
6759: }
6760: }
1.418 raeburn 6761: if (($context eq 'course') && ($viewablesec ne '')) {
1.430 raeburn 6762: next if ($roleslog{$id}{'logentry'}{'section'} ne $viewablesec);
1.418 raeburn 6763: }
1.239 raeburn 6764: $count ++;
6765: next if ($count < $minshown);
1.327 raeburn 6766: unless ($showntableheader) {
1.415 raeburn 6767: $r->print(&Apache::loncommon::start_data_table()
1.327 raeburn 6768: .$tableheader);
6769: $r->rflush();
6770: $showntableheader = 1;
6771: }
1.239 raeburn 6772: if ($whodunit{$roleslog{$id}{'exe_uname'}.':'.$roleslog{$id}{'exe_udom'}} eq '') {
6773: $whodunit{$roleslog{$id}{'exe_uname'}.':'.$roleslog{$id}{'exe_udom'}} =
6774: &Apache::loncommon::plainname($roleslog{$id}{'exe_uname'},$roleslog{$id}{'exe_udom'});
6775: }
6776: if ($changed{$roleslog{$id}{'uname'}.':'.$roleslog{$id}{'udom'}} eq '') {
6777: $changed{$roleslog{$id}{'uname'}.':'.$roleslog{$id}{'udom'}} =
6778: &Apache::loncommon::plainname($roleslog{$id}{'uname'},$roleslog{$id}{'udom'});
6779: }
6780: my $sec = $roleslog{$id}{'logentry'}{'section'};
6781: if ($sec eq '') {
6782: $sec = &mt('None');
6783: }
6784: my ($rolestart,$roleend);
6785: if ($roleslog{$id}{'delflag'}) {
6786: $rolestart = &mt('deleted');
6787: $roleend = &mt('deleted');
6788: } else {
6789: $rolestart = $roleslog{$id}{'logentry'}{'start'};
6790: $roleend = $roleslog{$id}{'logentry'}{'end'};
6791: if ($rolestart eq '' || $rolestart == 0) {
6792: $rolestart = &mt('No start date');
6793: } else {
6794: $rolestart = &Apache::lonlocal::locallocaltime($rolestart);
6795: }
6796: if ($roleend eq '' || $roleend == 0) {
6797: $roleend = &mt('No end date');
6798: } else {
6799: $roleend = &Apache::lonlocal::locallocaltime($roleend);
6800: }
6801: }
6802: my $chgcontext = $roleslog{$id}{'logentry'}{'context'};
6803: if ($roleslog{$id}{'logentry'}{'selfenroll'}) {
6804: $chgcontext = 'selfenroll';
6805: }
1.363 raeburn 6806: my %lt = &rolechg_contexts($context,$crstype);
1.239 raeburn 6807: if ($chgcontext ne '' && $lt{$chgcontext} ne '') {
6808: $chgcontext = $lt{$chgcontext};
6809: }
1.327 raeburn 6810: $r->print(
1.301 bisitz 6811: &Apache::loncommon::start_data_table_row()
6812: .'<td>'.$count.'</td>'
6813: .'<td>'.&Apache::lonlocal::locallocaltime($roleslog{$id}{'exe_time'}).'</td>'
6814: .'<td>'.$whodunit{$roleslog{$id}{'exe_uname'}.':'.$roleslog{$id}{'exe_udom'}}.'</td>'
6815: .'<td>'.$changed{$roleslog{$id}{'uname'}.':'.$roleslog{$id}{'udom'}}.'</td>'
1.363 raeburn 6816: .'<td>'.&Apache::lonnet::plaintext($roleslog{$id}{'logentry'}{'role'},$crstype).'</td>');
6817: if ($context eq 'course') {
6818: $r->print('<td>'.$sec.'</td>');
6819: }
6820: $r->print(
6821: '<td>'.$chgcontext.'</td>'
1.301 bisitz 6822: .'<td>'.$rolestart.'</td>'
6823: .'<td>'.$roleend.'</td>'
1.327 raeburn 6824: .&Apache::loncommon::end_data_table_row()."\n");
1.301 bisitz 6825: }
6826:
1.327 raeburn 6827: if ($showntableheader) { # Table footer, if content displayed above
1.415 raeburn 6828: $r->print(&Apache::loncommon::end_data_table().
6829: &userlogdisplay_navlinks(\%curr,$more_records));
1.327 raeburn 6830: } else { # No content displayed above
1.301 bisitz 6831: $r->print('<p class="LC_info">'
6832: .&mt('There are no records to display.')
6833: .'</p>'
6834: );
1.239 raeburn 6835: }
1.301 bisitz 6836:
1.327 raeburn 6837: # Form Footer
6838: $r->print(
6839: '<input type="hidden" name="page" value="'.$curr{'page'}.'" />'
6840: .'<input type="hidden" name="action" value="changelogs" />'
6841: .'</form>');
6842: return;
6843: }
1.301 bisitz 6844:
1.416 raeburn 6845: sub print_useraccesslogs_display {
6846: my ($r,$uname,$udom,$permission,$brcrum) = @_;
6847: my $formname = 'accesslog';
6848: my $form = 'document.accesslog';
6849:
6850: # set breadcrumbs
1.422 raeburn 6851: my %breadcrumb_text = &singleuser_breadcrumb('','domain',$udom);
1.431 raeburn 6852: my $prevphasestr;
6853: if ($env{'form.popup'}) {
6854: $brcrum = [];
6855: } else {
6856: push (@{$brcrum},
6857: {href => "javascript:backPage($form)",
6858: text => $breadcrumb_text{'search'}});
6859: my @prevphases;
6860: if ($env{'form.prevphases'}) {
6861: @prevphases = split(/,/,$env{'form.prevphases'});
6862: $prevphasestr = $env{'form.prevphases'};
6863: }
6864: if (($env{'form.phase'} eq 'userpicked') || (grep(/^userpicked$/,@prevphases))) {
6865: push(@{$brcrum},
6866: {href => "javascript:backPage($form,'get_user_info','select')",
6867: text => $breadcrumb_text{'userpicked'}});
6868: if ($env{'form.phase'} eq 'userpicked') {
6869: $prevphasestr = 'userpicked';
6870: }
1.416 raeburn 6871: }
6872: }
6873: push(@{$brcrum},
6874: {href => '/adm/createuser?action=accesslogs',
6875: text => 'User access logs',
1.424 raeburn 6876: help => 'Domain_User_Access_Logs'});
1.416 raeburn 6877: my $bread_crumbs_component = 'User Access Logs';
6878: my $args = { bread_crumbs => $brcrum,
6879: bread_crumbs_component => 'User Management'};
1.423 raeburn 6880: if ($env{'form.popup'}) {
6881: $args->{'no_nav_bar'} = 1;
1.431 raeburn 6882: $args->{'bread_crumbs_nomenu'} = 1;
1.423 raeburn 6883: }
1.416 raeburn 6884:
1.417 raeburn 6885: # set javascript
1.416 raeburn 6886: my ($jsback,$elements) = &crumb_utilities();
6887: my $jsnav = &userlogdisplay_js($formname);
6888:
6889: my $jscript = (<<ENDSCRIPT);
6890: <script type="text/javascript">
6891: // <![CDATA[
6892:
6893: $jsback
6894: $jsnav
6895:
6896: // ]]>
6897: </script>
6898:
6899: ENDSCRIPT
6900:
1.417 raeburn 6901: # print page header
1.416 raeburn 6902: $r->print(&header($jscript,$args));
6903:
6904: # early out unless log data can be displayed.
6905: unless ($permission->{'activity'}) {
6906: $r->print('<p class="LC_warning">'
6907: .&mt('You do not have rights to display user access logs.')
1.431 raeburn 6908: .'</p>');
6909: if ($env{'form.popup'}) {
6910: $r->print('<p><a href="javascript:window.close()">'.&mt('Close window').'</a></p>');
6911: } else {
6912: $r->print(&earlyout_accesslog_form($formname,$prevphasestr,$udom));
6913: }
1.416 raeburn 6914: return;
6915: }
6916:
6917: unless ($udom eq $env{'request.role.domain'}) {
6918: $r->print('<p class="LC_warning">'
6919: .&mt("User's domain must match role's domain")
6920: .'</p>'
6921: .&earlyout_accesslog_form($formname,$prevphasestr,$udom));
1.417 raeburn 6922: return;
1.416 raeburn 6923: }
6924:
6925: if (($uname eq '') || ($udom eq '')) {
6926: $r->print('<p class="LC_warning">'
6927: .&mt('Invalid username or domain')
6928: .'</p>'
6929: .&earlyout_accesslog_form($formname,$prevphasestr,$udom));
6930: return;
6931: }
6932:
1.437 raeburn 6933: if (&Apache::lonnet::privileged($uname,$udom,
6934: [$env{'request.role.domain'}],['dc','su'])) {
6935: unless (&Apache::lonnet::privileged($env{'user.name'},$env{'user.domain'},
6936: [$env{'request.role.domain'}],['dc','su'])) {
6937: $r->print('<p class="LC_warning">'
6938: .&mt('You need to be a privileged user to display user access logs for [_1]',
6939: &Apache::loncommon::aboutmewrapper(&Apache::loncommon::plainname($uname,$udom),
6940: $uname,$udom))
6941: .'</p>');
6942: if ($env{'form.popup'}) {
6943: $r->print('<p><a href="javascript:window.close()">'.&mt('Close window').'</a></p>');
6944: } else {
6945: $r->print(&earlyout_accesslog_form($formname,$prevphasestr,$udom));
6946: }
6947: return;
6948: }
6949: }
6950:
1.416 raeburn 6951: # set defaults
6952: my $now = time();
6953: my $defstart = $now - (7*24*3600);
6954: my %defaults = (
6955: page => '1',
6956: show => '10',
6957: activity => 'any',
6958: accesslog_start_date => $defstart,
6959: accesslog_end_date => $now,
6960: );
6961: my $more_records = 0;
6962:
6963: # set current
6964: my %curr;
6965: foreach my $item ('show','page','activity') {
6966: $curr{$item} = $env{'form.'.$item};
6967: }
6968: my ($startdate,$enddate) =
6969: &Apache::lonuserutils::get_dates_from_form('accesslog_start_date','accesslog_end_date');
6970: $curr{'accesslog_start_date'} = $startdate;
6971: $curr{'accesslog_end_date'} = $enddate;
6972: foreach my $key (keys(%defaults)) {
6973: if ($curr{$key} eq '') {
6974: $curr{$key} = $defaults{$key};
6975: }
6976: }
6977: my ($minshown,$maxshown);
6978: $minshown = 1;
6979: my $count = 0;
6980: if ($curr{'show'} =~ /\D/) {
6981: $curr{'page'} = 1;
6982: } else {
6983: $maxshown = $curr{'page'} * $curr{'show'};
6984: if ($curr{'page'} > 1) {
6985: $minshown = 1 + ($curr{'page'} - 1) * $curr{'show'};
6986: }
6987: }
6988:
6989: # form header
6990: $r->print('<form action="/adm/createuser" method="post" name="'.$formname.'">'.
6991: &activity_display_filter($formname,\%curr));
6992:
6993: my $showntableheader = 0;
6994: my ($nav_script,$nav_links);
6995:
6996: # table header
1.431 raeburn 6997: my $tableheader = '<h3>'.
6998: &mt('User access logs for: [_1]',
6999: &Apache::loncommon::aboutmewrapper(&Apache::loncommon::plainname($uname,$udom),$uname,$udom)).'</h3>'
7000: .&Apache::loncommon::start_data_table_header_row()
1.416 raeburn 7001: .'<th> </th>'
7002: .'<th>'.&mt('When').'</th>'
7003: .'<th>'.&mt('HostID').'</th>'
7004: .'<th>'.&mt('Event').'</th>'
7005: .'<th>'.&mt('Other data').'</th>'
7006: .&Apache::loncommon::end_data_table_header_row();
7007:
7008: my %filters=(
7009: start => $curr{'accesslog_start_date'},
7010: end => $curr{'accesslog_end_date'},
7011: action => $curr{'activity'},
7012: );
7013:
7014: my $reply = &Apache::lonnet::userlog_query($uname,$udom,%filters);
7015: unless ( ($reply =~/^timeout/) || ($reply =~/^error/) ) {
7016: my (%courses,%missing);
7017: my @results = split(/\&/,$reply);
7018: foreach my $item (reverse(@results)) {
7019: my ($timestamp,$host,$event) = split(/:/,$item);
7020: next unless ($event =~ /^(Log|Role)/);
7021: if ($curr{'show'} !~ /\D/) {
7022: if ($count >= $curr{'page'} * $curr{'show'}) {
7023: $more_records = 1;
7024: last;
7025: }
7026: }
7027: $count ++;
7028: next if ($count < $minshown);
7029: unless ($showntableheader) {
7030: $r->print($nav_script
7031: .&Apache::loncommon::start_data_table()
7032: .$tableheader);
7033: $r->rflush();
7034: $showntableheader = 1;
7035: }
1.418 raeburn 7036: my ($shown,$extra);
1.437 raeburn 7037: my ($event,$data) = split(/\s+/,&unescape($event),2);
1.416 raeburn 7038: if ($event eq 'Role') {
7039: my ($rolecode,$extent) = split(/\./,$data,2);
7040: next if ($extent eq '');
7041: my ($crstype,$desc,$info);
1.418 raeburn 7042: if ($extent =~ m{^/($match_domain)/($match_courseid)(?:/(\w+)|)$}) {
7043: my ($cdom,$cnum,$sec) = ($1,$2,$3);
1.416 raeburn 7044: my $cid = $cdom.'_'.$cnum;
7045: if (exists($courses{$cid})) {
7046: $crstype = $courses{$cid}{'type'};
7047: $desc = $courses{$cid}{'description'};
7048: } elsif ($missing{$cid}) {
7049: $crstype = 'Course';
7050: $desc = 'Course/Community';
7051: } else {
7052: my %crsinfo = &Apache::lonnet::courseiddump($cdom,'.',1,'.','.',$cnum,undef,undef,'.');
7053: if (ref($crsinfo{$cdom.'_'.$cnum}) eq 'HASH') {
7054: $courses{$cid} = $crsinfo{$cid};
7055: $crstype = $crsinfo{$cid}{'type'};
7056: $desc = $crsinfo{$cid}{'description'};
7057: } else {
7058: $missing{$cid} = 1;
7059: }
7060: }
7061: $extra = &mt($crstype).': <a href="/public/'.$cdom.'/'.$cnum.'/syllabus">'.$desc.'</a>';
1.418 raeburn 7062: if ($sec ne '') {
7063: $extra .= ' ('.&mt('Section: [_1]',$sec).')';
7064: }
1.416 raeburn 7065: } elsif ($extent =~ m{^/($match_domain)/($match_username|$)}) {
7066: my ($dom,$name) = ($1,$2);
7067: if ($rolecode eq 'au') {
7068: $extra = '';
7069: } elsif ($rolecode =~ /^(ca|aa)$/) {
1.417 raeburn 7070: $extra = &mt('Authoring Space: [_1]',$name.':'.$dom);
1.416 raeburn 7071: } elsif ($rolecode =~ /^(li|dg|dh|dc|sc)$/) {
7072: $extra = &mt('Domain: [_1]',$dom);
7073: }
7074: }
7075: my $rolename;
7076: if ($rolecode =~ m{^cr/($match_domain)/($match_username)/(\w+)}) {
7077: my $role = $3;
1.417 raeburn 7078: my $owner = "($2:$1)";
1.416 raeburn 7079: if ($2 eq $1.'-domainconfig') {
7080: $owner = '(ad hoc)';
1.417 raeburn 7081: }
1.416 raeburn 7082: $rolename = &mt('Custom role: [_1]',$role.' '.$owner);
7083: } else {
7084: $rolename = &Apache::lonnet::plaintext($rolecode,$crstype);
7085: }
7086: $shown = &mt('Role selection: [_1]',$rolename);
7087: } else {
7088: $shown = &mt($event);
1.437 raeburn 7089: if ($data =~ /^webdav/) {
7090: my ($path,$clientip) = split(/\s+/,$data,2);
7091: $path =~ s/^webdav//;
7092: if ($clientip ne '') {
7093: $extra = &mt('Client IP address: [_1]',$clientip);
7094: }
7095: if ($path ne '') {
7096: $shown .= ' '.&mt('(WebDAV access to [_1])',$path);
7097: }
7098: } elsif ($data ne '') {
7099: $extra = &mt('Client IP address: [_1]',$data);
1.416 raeburn 7100: }
7101: }
7102: $r->print(
7103: &Apache::loncommon::start_data_table_row()
7104: .'<td>'.$count.'</td>'
7105: .'<td>'.&Apache::lonlocal::locallocaltime($timestamp).'</td>'
7106: .'<td>'.$host.'</td>'
7107: .'<td>'.$shown.'</td>'
7108: .'<td>'.$extra.'</td>'
7109: .&Apache::loncommon::end_data_table_row()."\n");
7110: }
7111: }
7112:
7113: if ($showntableheader) { # Table footer, if content displayed above
7114: $r->print(&Apache::loncommon::end_data_table().
7115: &userlogdisplay_navlinks(\%curr,$more_records));
7116: } else { # No content displayed above
7117: $r->print('<p class="LC_info">'
7118: .&mt('There are no records to display.')
7119: .'</p>');
7120: }
7121:
1.423 raeburn 7122: if ($env{'form.popup'} == 1) {
7123: $r->print('<input type="hidden" name="popup" value="1" />'."\n");
7124: }
7125:
1.416 raeburn 7126: # Form Footer
7127: $r->print(
7128: '<input type="hidden" name="currstate" value="" />'
7129: .'<input type="hidden" name="accessuname" value="'.$uname.'" />'
7130: .'<input type="hidden" name="accessudom" value="'.$udom.'" />'
7131: .'<input type="hidden" name="page" value="'.$curr{'page'}.'" />'
7132: .'<input type="hidden" name="prevphases" value="'.$prevphasestr.'" />'
7133: .'<input type="hidden" name="phase" value="activity" />'
7134: .'<input type="hidden" name="action" value="accesslogs" />'
7135: .'<input type="hidden" name="srchdomain" value="'.$udom.'" />'
7136: .'<input type="hidden" name="srchby" value="'.$env{'form.srchby'}.'" />'
7137: .'<input type="hidden" name="srchtype" value="'.$env{'form.srchtype'}.'" />'
7138: .'<input type="hidden" name="srchterm" value="'.&HTML::Entities::encode($env{'form.srchterm'},'<>"&').'" />'
7139: .'<input type="hidden" name="srchin" value="'.$env{'form.srchin'}.'" />'
7140: .'</form>');
7141: return;
7142: }
7143:
7144: sub earlyout_accesslog_form {
7145: my ($formname,$prevphasestr,$udom) = @_;
7146: my $srchterm = &HTML::Entities::encode($env{'form.srchterm'},'<>"&');
7147: return <<"END";
7148: <form action="/adm/createuser" method="post" name="$formname">
7149: <input type="hidden" name="currstate" value="" />
7150: <input type="hidden" name="prevphases" value="$prevphasestr" />
7151: <input type="hidden" name="phase" value="activity" />
7152: <input type="hidden" name="action" value="accesslogs" />
7153: <input type="hidden" name="srchdomain" value="$udom" />
7154: <input type="hidden" name="srchby" value="$env{'form.srchby'}" />
7155: <input type="hidden" name="srchtype" value="$env{'form.srchtype'}" />
7156: <input type="hidden" name="srchterm" value="$srchterm" />
7157: <input type="hidden" name="srchin" value="$env{'form.srchin'}" />
7158: </form>
7159: END
7160: }
7161:
7162: sub activity_display_filter {
7163: my ($formname,$curr) = @_;
7164: my $nolink = 1;
7165: my $output = '<table><tr><td valign="top">'.
7166: '<span class="LC_nobreak"><b>'.&mt('Actions/page:').'</b></span><br />'.
7167: &Apache::lonmeta::selectbox('show',$curr->{'show'},undef,
7168: (&mt('all'),5,10,20,50,100,1000,10000)).
7169: '</td><td> </td>';
7170: my $startform =
7171: &Apache::lonhtmlcommon::date_setter($formname,'accesslog_start_date',
7172: $curr->{'accesslog_start_date'},undef,
7173: undef,undef,undef,undef,undef,undef,$nolink);
7174: my $endform =
7175: &Apache::lonhtmlcommon::date_setter($formname,'accesslog_end_date',
7176: $curr->{'accesslog_end_date'},undef,
7177: undef,undef,undef,undef,undef,undef,$nolink);
7178: my %lt = &Apache::lonlocal::texthash (
7179: activity => 'Activity',
7180: Role => 'Role selection',
7181: log => 'Log-in or Logout',
7182: );
7183: $output .= '<td valign="top"><b>'.&mt('Window during which actions occurred:').'</b><br />'.
7184: '<table><tr><td>'.&mt('After:').
7185: '</td><td>'.$startform.'</td></tr>'.
7186: '<tr><td>'.&mt('Before:').'</td>'.
7187: '<td>'.$endform.'</td></tr></table>'.
7188: '</td>'.
7189: '<td> </td>'.
7190: '<td valign="top"><b>'.&mt('Activities').'</b><br />'.
7191: '<select name="activity"><option value="any"';
7192: if ($curr->{'activity'} eq 'any') {
7193: $output .= ' selected="selected"';
7194: }
7195: $output .= '>'.&mt('Any').'</option>'."\n";
7196: foreach my $activity ('Role','log') {
7197: my $selstr = '';
7198: if ($activity eq $curr->{'activity'}) {
7199: $selstr = ' selected="selected"';
7200: }
7201: $output .= '<option value="'.$activity.'"'.$selstr.'>'.$lt{$activity}.'</option>';
7202: }
7203: $output .= '</select></td>'.
7204: '</tr></table>';
7205: # Update Display button
7206: $output .= '<p>'
7207: .'<input type="submit" value="'.&mt('Update Display').'" />'
1.431 raeburn 7208: .'</p><hr />';
1.416 raeburn 7209: return $output;
7210: }
7211:
1.415 raeburn 7212: sub userlogdisplay_js {
7213: my ($formname) = @_;
7214: return <<"ENDSCRIPT";
7215:
1.239 raeburn 7216: function chgPage(caller) {
7217: if (caller == 'previous') {
7218: document.$formname.page.value --;
7219: }
7220: if (caller == 'next') {
7221: document.$formname.page.value ++;
7222: }
1.327 raeburn 7223: document.$formname.submit();
1.239 raeburn 7224: return;
7225: }
7226: ENDSCRIPT
1.415 raeburn 7227: }
7228:
7229: sub userlogdisplay_navlinks {
7230: my ($curr,$more_records) = @_;
7231: return unless(ref($curr) eq 'HASH');
7232: # Navigation Buttons
7233: my $nav_links = '<p>';
7234: if (($curr->{'page'} > 1) || ($more_records)) {
7235: if (($curr->{'page'} > 1) && ($curr->{'show'} !~ /\D/)) {
7236: $nav_links .= '<input type="button"'
7237: .' onclick="javascript:chgPage('."'previous'".');"'
7238: .' value="'.&mt('Previous [_1] changes',$curr->{'show'})
7239: .'" /> ';
7240: }
7241: if ($more_records) {
7242: $nav_links .= '<input type="button"'
7243: .' onclick="javascript:chgPage('."'next'".');"'
7244: .' value="'.&mt('Next [_1] changes',$curr->{'show'})
7245: .'" />';
1.301 bisitz 7246: }
7247: }
1.415 raeburn 7248: $nav_links .= '</p>';
7249: return $nav_links;
1.239 raeburn 7250: }
7251:
7252: sub role_display_filter {
1.363 raeburn 7253: my ($context,$formname,$cdom,$cnum,$curr,$version,$crstype) = @_;
7254: my $lctype;
7255: if ($context eq 'course') {
7256: $lctype = lc($crstype);
7257: }
1.239 raeburn 7258: my $nolink = 1;
7259: my $output = '<table><tr><td valign="top">'.
1.301 bisitz 7260: '<span class="LC_nobreak"><b>'.&mt('Changes/page:').'</b></span><br />'.
1.239 raeburn 7261: &Apache::lonmeta::selectbox('show',$curr->{'show'},undef,
7262: (&mt('all'),5,10,20,50,100,1000,10000)).
7263: '</td><td> </td>';
7264: my $startform =
7265: &Apache::lonhtmlcommon::date_setter($formname,'rolelog_start_date',
7266: $curr->{'rolelog_start_date'},undef,
7267: undef,undef,undef,undef,undef,undef,$nolink);
7268: my $endform =
7269: &Apache::lonhtmlcommon::date_setter($formname,'rolelog_end_date',
7270: $curr->{'rolelog_end_date'},undef,
7271: undef,undef,undef,undef,undef,undef,$nolink);
1.363 raeburn 7272: my %lt = &rolechg_contexts($context,$crstype);
1.301 bisitz 7273: $output .= '<td valign="top"><b>'.&mt('Window during which changes occurred:').'</b><br />'.
7274: '<table><tr><td>'.&mt('After:').
7275: '</td><td>'.$startform.'</td></tr>'.
7276: '<tr><td>'.&mt('Before:').'</td>'.
7277: '<td>'.$endform.'</td></tr></table>'.
7278: '</td>'.
7279: '<td> </td>'.
1.239 raeburn 7280: '<td valign="top"><b>'.&mt('Role:').'</b><br />'.
7281: '<select name="role"><option value="any"';
7282: if ($curr->{'role'} eq 'any') {
7283: $output .= ' selected="selected"';
7284: }
7285: $output .= '>'.&mt('Any').'</option>'."\n";
1.363 raeburn 7286: my @roles = &Apache::lonuserutils::roles_by_context($context,1,$crstype);
1.239 raeburn 7287: foreach my $role (@roles) {
7288: my $plrole;
7289: if ($role eq 'cr') {
7290: $plrole = &mt('Custom Role');
7291: } else {
1.318 raeburn 7292: $plrole=&Apache::lonnet::plaintext($role,$crstype);
1.239 raeburn 7293: }
7294: my $selstr = '';
7295: if ($role eq $curr->{'role'}) {
7296: $selstr = ' selected="selected"';
7297: }
7298: $output .= ' <option value="'.$role.'"'.$selstr.'>'.$plrole.'</option>';
7299: }
1.301 bisitz 7300: $output .= '</select></td>'.
7301: '<td> </td>'.
7302: '<td valign="top"><b>'.
1.239 raeburn 7303: &mt('Context:').'</b><br /><select name="chgcontext">';
1.363 raeburn 7304: my @posscontexts;
7305: if ($context eq 'course') {
1.376 raeburn 7306: @posscontexts = ('any','automated','updatenow','createcourse','course','domain','selfenroll','requestcourses');
1.363 raeburn 7307: } elsif ($context eq 'domain') {
7308: @posscontexts = ('any','domain','requestauthor','domconfig','server');
7309: } else {
7310: @posscontexts = ('any','author','domain');
7311: }
7312: foreach my $chgtype (@posscontexts) {
1.239 raeburn 7313: my $selstr = '';
7314: if ($curr->{'chgcontext'} eq $chgtype) {
1.301 bisitz 7315: $selstr = ' selected="selected"';
1.239 raeburn 7316: }
1.363 raeburn 7317: if ($context eq 'course') {
1.376 raeburn 7318: if (($chgtype eq 'automated') || ($chgtype eq 'updatenow')) {
1.363 raeburn 7319: next if (!&Apache::lonnet::auto_run($cnum,$cdom));
7320: }
1.239 raeburn 7321: }
7322: $output .= '<option value="'.$chgtype.'"'.$selstr.'>'.$lt{$chgtype}.'</option>'."\n";
1.248 raeburn 7323: }
1.303 bisitz 7324: $output .= '</select></td>'
7325: .'</tr></table>';
7326:
7327: # Update Display button
7328: $output .= '<p>'
7329: .'<input type="submit" value="'.&mt('Update Display').'" />'
7330: .'</p>';
7331:
7332: # Server version info
1.363 raeburn 7333: my $needsrev = '2.11.0';
7334: if ($context eq 'course') {
7335: $needsrev = '2.7.0';
7336: }
7337:
1.303 bisitz 7338: $output .= '<p class="LC_info">'
7339: .&mt('Only changes made from servers running LON-CAPA [_1] or later are displayed.'
1.363 raeburn 7340: ,$needsrev);
1.248 raeburn 7341: if ($version) {
1.303 bisitz 7342: $output .= ' '.&mt('This LON-CAPA server is version [_1]',$version);
7343: }
7344: $output .= '</p><hr />';
1.239 raeburn 7345: return $output;
7346: }
7347:
7348: sub rolechg_contexts {
1.363 raeburn 7349: my ($context,$crstype) = @_;
7350: my %lt;
7351: if ($context eq 'course') {
7352: %lt = &Apache::lonlocal::texthash (
1.239 raeburn 7353: any => 'Any',
1.376 raeburn 7354: automated => 'Automated Enrollment',
1.239 raeburn 7355: updatenow => 'Roster Update',
7356: createcourse => 'Course Creation',
7357: course => 'User Management in course',
7358: domain => 'User Management in domain',
1.313 raeburn 7359: selfenroll => 'Self-enrolled',
1.318 raeburn 7360: requestcourses => 'Course Request',
1.239 raeburn 7361: );
1.363 raeburn 7362: if ($crstype eq 'Community') {
7363: $lt{'createcourse'} = &mt('Community Creation');
7364: $lt{'course'} = &mt('User Management in community');
7365: $lt{'requestcourses'} = &mt('Community Request');
7366: }
7367: } elsif ($context eq 'domain') {
7368: %lt = &Apache::lonlocal::texthash (
7369: any => 'Any',
7370: domain => 'User Management in domain',
7371: requestauthor => 'Authoring Request',
7372: server => 'Command line script (DC role)',
7373: domconfig => 'Self-enrolled',
7374: );
7375: } else {
7376: %lt = &Apache::lonlocal::texthash (
7377: any => 'Any',
7378: domain => 'User Management in domain',
7379: author => 'User Management by author',
7380: );
7381: }
1.239 raeburn 7382: return %lt;
7383: }
7384:
1.428 raeburn 7385: sub print_helpdeskaccess_display {
7386: my ($r,$permission,$brcrum) = @_;
7387: my $formname = 'helpdeskaccess';
7388: my $helpitem = 'Course_Helpdesk_Access';
7389: push (@{$brcrum},
7390: {href => '/adm/createuser?action=helpdesk',
7391: text => 'Helpdesk Access',
7392: help => $helpitem});
7393: my $bread_crumbs_component = 'Helpdesk Staff Access';
7394: my $args = { bread_crumbs => $brcrum,
7395: bread_crumbs_component => $bread_crumbs_component};
7396:
7397: my $cdom = $env{'course.'.$env{'request.course.id'}.'.domain'};
7398: my $cnum = $env{'course.'.$env{'request.course.id'}.'.num'};
7399: my $confname = $cdom.'-domainconfig';
7400: my $crstype = &Apache::loncommon::course_type();
7401:
1.434 raeburn 7402: my @accesstypes = ('all','dh','da','none');
1.428 raeburn 7403: my ($numstatustypes,@jsarray);
7404: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($cdom);
7405: if (ref($types) eq 'ARRAY') {
1.430 raeburn 7406: if (@{$types} > 0) {
1.428 raeburn 7407: $numstatustypes = scalar(@{$types});
7408: push(@accesstypes,'status');
7409: @jsarray = ('bystatus');
7410: }
7411: }
7412: my %customroles = &get_domain_customroles($cdom,$confname);
1.432 raeburn 7413: my %domhelpdesk = &Apache::lonnet::get_active_domroles($cdom,['dh','da']);
1.428 raeburn 7414: if (keys(%domhelpdesk)) {
7415: push(@accesstypes,('inc','exc'));
7416: push(@jsarray,('notinc','notexc'));
7417: }
7418: push(@jsarray,'privs');
7419: my $hiddenstr = join("','",@jsarray);
7420: my $rolestr = join("','",sort(keys(%customroles)));
7421:
7422: my $jscript;
7423: my (%settings,%overridden);
7424: if (keys(%customroles)) {
7425: &get_adhocrole_settings($env{'request.course.id'},\@accesstypes,
7426: $types,\%customroles,\%settings,\%overridden);
7427: my %jsfull=();
7428: my %jslevels= (
7429: course => {},
7430: domain => {},
7431: system => {},
7432: );
7433: my %jslevelscurrent=(
7434: course => {},
7435: domain => {},
7436: system => {},
7437: );
7438: my (%privs,%jsprivs);
7439: &Apache::lonuserutils::custom_role_privs(\%privs,\%jsfull,\%jslevels,\%jslevelscurrent);
7440: foreach my $priv (keys(%jsfull)) {
7441: if ($jslevels{'course'}{$priv}) {
7442: $jsprivs{$priv} = 1;
7443: }
7444: }
7445: my (%elements,%stored);
7446: foreach my $role (keys(%customroles)) {
7447: $elements{$role.'_access'} = 'radio';
7448: $elements{$role.'_incrs'} = 'radio';
7449: if ($numstatustypes) {
7450: $elements{$role.'_status'} = 'checkbox';
7451: }
7452: if (keys(%domhelpdesk) > 0) {
7453: $elements{$role.'_staff_inc'} = 'checkbox';
7454: $elements{$role.'_staff_exc'} = 'checkbox';
7455: }
1.430 raeburn 7456: $elements{$role.'_override'} = 'checkbox';
1.428 raeburn 7457: if (ref($settings{$role}) eq 'HASH') {
7458: if ($settings{$role}{'access'} ne '') {
7459: my $curraccess = $settings{$role}{'access'};
7460: $stored{$role.'_access'} = $curraccess;
7461: $stored{$role.'_incrs'} = 1;
7462: if ($curraccess eq 'status') {
7463: if (ref($settings{$role}{'status'}) eq 'ARRAY') {
7464: $stored{$role.'_status'} = $settings{$role}{'status'};
7465: }
7466: } elsif (($curraccess eq 'exc') || ($curraccess eq 'inc')) {
7467: if (ref($settings{$role}{$curraccess}) eq 'ARRAY') {
7468: $stored{$role.'_staff_'.$curraccess} = $settings{$role}{$curraccess};
7469: }
7470: }
7471: } else {
7472: $stored{$role.'_incrs'} = 0;
7473: }
7474: $stored{$role.'_override'} = [];
7475: if ($env{'course.'.$env{'request.course.id'}.'.internal.adhocpriv.'.$role}) {
7476: if (ref($settings{$role}{'off'}) eq 'ARRAY') {
7477: foreach my $priv (@{$settings{$role}{'off'}}) {
7478: push(@{$stored{$role.'_override'}},$priv);
7479: }
7480: }
7481: if (ref($settings{$role}{'on'}) eq 'ARRAY') {
7482: foreach my $priv (@{$settings{$role}{'on'}}) {
7483: unless (grep(/^$priv$/,@{$stored{$role.'_override'}})) {
7484: push(@{$stored{$role.'_override'}},$priv);
7485: }
7486: }
7487: }
7488: }
7489: } else {
7490: $stored{$role.'_incrs'} = 0;
7491: }
7492: }
7493: $jscript = &Apache::lonhtmlcommon::set_form_elements(\%elements,\%stored);
7494: }
7495:
7496: my $js = <<"ENDJS";
7497: <script type="text/javascript">
7498: // <![CDATA[
7499: $jscript;
7500:
7501: function switchRoleTab(caller,role) {
7502: if (document.getElementById(role+'_maindiv')) {
7503: if (caller.id != 'LC_current_minitab') {
7504: if (document.getElementById('LC_current_minitab')) {
7505: document.getElementById('LC_current_minitab').id=null;
7506: }
7507: var roledivs = Array('$rolestr');
7508: if (roledivs.length > 0) {
7509: for (var i=0; i<roledivs.length; i++) {
7510: if (document.getElementById(roledivs[i]+'_maindiv')) {
7511: document.getElementById(roledivs[i]+'_maindiv').style.display='none';
7512: }
7513: }
7514: }
7515: caller.id = 'LC_current_minitab';
7516: document.getElementById(role+'_maindiv').style.display='block';
7517: }
7518: }
7519: return false;
1.430 raeburn 7520: }
1.428 raeburn 7521:
7522: function helpdeskAccess(role) {
7523: var curraccess = null;
7524: if (document.$formname.elements[role+'_access'].length) {
7525: for (var i=0; i<document.$formname.elements[role+'_access'].length; i++) {
7526: if (document.$formname.elements[role+'_access'][i].checked) {
7527: curraccess = document.$formname.elements[role+'_access'][i].value;
7528: }
7529: }
7530: }
7531: var shown = Array();
7532: var hidden = Array();
7533: if (curraccess == 'none') {
1.430 raeburn 7534: hidden = Array ('$hiddenstr');
1.428 raeburn 7535: } else {
7536: if (curraccess == 'status') {
1.430 raeburn 7537: shown = Array ('bystatus','privs');
7538: hidden = Array ('notinc','notexc');
1.428 raeburn 7539: } else {
7540: if (curraccess == 'exc') {
7541: shown = Array ('notexc','privs');
7542: hidden = Array ('notinc','bystatus');
7543: }
7544: if (curraccess == 'inc') {
7545: shown = Array ('notinc','privs');
7546: hidden = Array ('notexc','bystatus');
7547: }
7548: if (curraccess == 'all') {
7549: shown = Array ('privs');
7550: hidden = Array ('notinc','notexc','bystatus');
7551: }
7552: }
7553: }
7554: if (hidden.length > 0) {
7555: for (var i=0; i<hidden.length; i++) {
7556: if (document.getElementById(role+'_'+hidden[i])) {
1.430 raeburn 7557: document.getElementById(role+'_'+hidden[i]).style.display = 'none';
1.428 raeburn 7558: }
7559: }
7560: }
7561: if (shown.length > 0) {
7562: for (var i=0; i<shown.length; i++) {
7563: if (document.getElementById(role+'_'+shown[i])) {
7564: if (shown[i] == 'privs') {
7565: document.getElementById(role+'_'+shown[i]).style.display = 'block';
7566: } else {
7567: document.getElementById(role+'_'+shown[i]).style.display = 'inline';
7568: }
7569: }
7570: }
7571: }
7572: return;
7573: }
7574:
7575: function toggleAccess(role) {
7576: if ((document.getElementById(role+'_setincrs')) &&
7577: (document.getElementById(role+'_setindom'))) {
7578: for (var i=0; i<document.$formname.elements[role+'_incrs'].length; i++) {
7579: if (document.$formname.elements[role+'_incrs'][i].checked) {
7580: if (document.$formname.elements[role+'_incrs'][i].value == 1) {
7581: document.getElementById(role+'_setindom').style.display = 'none';
1.430 raeburn 7582: document.getElementById(role+'_setincrs').style.display = 'block';
1.428 raeburn 7583: } else {
7584: document.getElementById(role+'_setincrs').style.display = 'none';
7585: document.getElementById(role+'_setindom').style.display = 'block';
7586: }
7587: break;
7588: }
7589: }
7590: }
7591: return;
7592: }
7593:
7594: // ]]>
7595: </script>
7596: ENDJS
7597:
7598: $args->{add_entries} = {onload => "javascript:setFormElements(document.$formname)"};
7599:
7600: # print page header
7601: $r->print(&header($js,$args));
7602: # print form header
7603: $r->print('<form action="/adm/createuser" method="post" name="'.$formname.'">');
7604:
7605: if (keys(%customroles)) {
7606: my %lt = &Apache::lonlocal::texthash(
7607: 'aco' => 'As course owner you may override the defaults set in the domain for role usage and/or privileges.',
7608: 'rou' => 'Role usage',
7609: 'whi' => 'Which helpdesk personnel may use this role?',
7610: 'udd' => 'Use domain default',
1.433 raeburn 7611: 'all' => 'All with domain helpdesk or helpdesk assistant role',
1.434 raeburn 7612: 'dh' => 'All with domain helpdesk role',
7613: 'da' => 'All with domain helpdesk assistant role',
1.428 raeburn 7614: 'none' => 'None',
7615: 'status' => 'Determined based on institutional status',
1.430 raeburn 7616: 'inc' => 'Include all, but exclude specific personnel',
1.428 raeburn 7617: 'exc' => 'Exclude all, but include specific personnel',
7618: 'hel' => 'Helpdesk',
7619: 'rpr' => 'Role privileges',
7620: );
7621: $lt{'tfh'} = &mt("Custom [_1]ad hoc[_2] course roles available for use by the domain's helpdesk are as follows",'<i>','</i>');
7622: my %domconfig = &Apache::lonnet::get_dom('configuration',['helpsettings'],$cdom);
7623: my (%domcurrent,%ordered,%description,%domusage,$disabled);
7624: if (ref($domconfig{'helpsettings'}) eq 'HASH') {
7625: if (ref($domconfig{'helpsettings'}{'adhoc'}) eq 'HASH') {
7626: %domcurrent = %{$domconfig{'helpsettings'}{'adhoc'}};
7627: }
7628: }
7629: my $count = 0;
7630: foreach my $role (sort(keys(%customroles))) {
7631: my ($order,$desc,$access_in_dom);
7632: if (ref($domcurrent{$role}) eq 'HASH') {
7633: $order = $domcurrent{$role}{'order'};
7634: $desc = $domcurrent{$role}{'desc'};
7635: $access_in_dom = $domcurrent{$role}{'access'};
7636: }
7637: if ($order eq '') {
7638: $order = $count;
7639: }
7640: $ordered{$order} = $role;
7641: if ($desc ne '') {
7642: $description{$role} = $desc;
7643: } else {
7644: $description{$role}= $role;
7645: }
7646: $count++;
7647: }
7648: %domusage = &domain_adhoc_access(\%customroles,\%domcurrent,\@accesstypes,$usertypes,$othertitle);
7649: my @roles_by_num = ();
7650: foreach my $item (sort {$a <=> $b } (keys(%ordered))) {
7651: push(@roles_by_num,$ordered{$item});
1.430 raeburn 7652: }
1.429 raeburn 7653: $r->print('<p>'.$lt{'tfh'}.': <i>'.join('</i>, <i>',map { $description{$_}; } @roles_by_num).'</i>.');
1.428 raeburn 7654: if ($permission->{'owner'}) {
7655: $r->print('<br />'.$lt{'aco'}.'</p><p>');
7656: $r->print('<input type="hidden" name="state" value="process" />'.
7657: '<input type="submit" value="'.&mt('Save changes').'" />');
7658: } else {
7659: if ($env{'course.'.$env{'request.course.id'}.'.internal.courseowner'}) {
7660: my ($ownername,$ownerdom) = split(/:/,$env{'course.'.$env{'request.course.id'}.'.internal.courseowner'});
7661: $r->print('<br />'.&mt('The course owner -- [_1] -- can override the default access and/or privileges for these ad hoc roles.',
7662: &Apache::loncommon::aboutmewrapper(&Apache::loncommon::plainname($ownername,$ownerdom),$ownername,$ownerdom)));
7663: }
7664: $disabled = ' disabled="disabled"';
7665: }
7666: $r->print('</p>');
7667:
7668: $r->print('<div id="LC_minitab_header"><ul>');
7669: my $count = 0;
7670: my %visibility;
7671: foreach my $role (@roles_by_num) {
7672: my $id;
7673: if ($count == 0) {
7674: $id=' id="LC_current_minitab"';
1.430 raeburn 7675: $visibility{$role} = ' style="display:block"';
1.428 raeburn 7676: } else {
7677: $visibility{$role} = ' style="display:none"';
7678: }
7679: $count ++;
7680: $r->print('<li'.$id.'><a href="#" onclick="javascript:switchRoleTab(this.parentNode,'."'$role'".');">'.$description{$role}.'</a></li>');
7681: }
7682: $r->print('</ul></div>');
7683:
7684: foreach my $role (@roles_by_num) {
7685: my %usecheck = (
7686: all => ' checked="checked"',
7687: );
7688: my %displaydiv = (
7689: status => 'none',
7690: inc => 'none',
7691: exc => 'none',
7692: priv => 'block',
7693: );
7694: my (%selected,$overridden,$incrscheck,$indomcheck,$indomvis,$incrsvis);
1.430 raeburn 7695: if (ref($settings{$role}) eq 'HASH') {
1.428 raeburn 7696: if ($settings{$role}{'access'} ne '') {
7697: $indomvis = ' style="display:none"';
7698: $incrsvis = ' style="display:block"';
1.430 raeburn 7699: $incrscheck = ' checked="checked"';
1.428 raeburn 7700: if ($settings{$role}{'access'} ne 'all') {
7701: $usecheck{$settings{$role}{'access'}} = $usecheck{'all'};
7702: delete($usecheck{'all'});
7703: if ($settings{$role}{'access'} eq 'status') {
7704: my $access = 'status';
7705: $displaydiv{$access} = 'inline';
7706: if (ref($settings{$role}{$access}) eq 'ARRAY') {
7707: $selected{$access} = $settings{$role}{$access};
7708: }
7709: } elsif ($settings{$role}{'access'} =~ /^(inc|exc)$/) {
7710: my $access = $1;
7711: $displaydiv{$access} = 'inline';
7712: if (ref($settings{$role}{$access}) eq 'ARRAY') {
7713: $selected{$access} = $settings{$role}{$access};
7714: }
7715: } elsif ($settings{$role}{'access'} eq 'none') {
7716: $displaydiv{'priv'} = 'none';
7717: }
7718: }
7719: } else {
7720: $indomcheck = ' checked="checked"';
7721: $indomvis = ' style="display:block"';
7722: $incrsvis = ' style="display:none"';
7723: }
7724: } else {
7725: $indomcheck = ' checked="checked"';
1.430 raeburn 7726: $indomvis = ' style="display:block"';
1.428 raeburn 7727: $incrsvis = ' style="display:none"';
7728: }
7729: $r->print('<div class="LC_left_float" id="'.$role.'_maindiv"'.$visibility{$role}.'>'.
7730: '<fieldset><legend>'.$lt{'rou'}.'</legend>'.
7731: '<p>'.$lt{'whi'}.' <span class="LC_nobreak">'.
7732: '<label><input type="radio" name="'.$role.'_incrs" value="1"'.$incrscheck.' onclick="toggleAccess('."'$role'".');"'.$disabled.'>'.
7733: &mt('Set here in [_1]',lc($crstype)).'</label>'.
7734: '<span>'.(' 'x2).
7735: '<label><input type="radio" name="'.$role.'_incrs" value="0"'.$indomcheck.' onclick="toggleAccess('."'$role'".');"'.$disabled.'>'.
7736: $lt{'udd'}.'</label><span></p>'.
7737: '<div id="'.$role.'_setindom"'.$indomvis.'>'.
7738: '<span class="LC_cusr_emph">'.$domusage{$role}.'</span></div>'.
7739: '<div id="'.$role.'_setincrs"'.$incrsvis.'>');
7740: foreach my $access (@accesstypes) {
7741: $r->print('<p><label><input type="radio" name="'.$role.'_access" value="'.$access.'" '.$usecheck{$access}.
7742: ' onclick="helpdeskAccess('."'$role'".');"'.$disabled.' />'.$lt{$access}.'</label>');
7743: if ($access eq 'status') {
7744: $r->print('<div id="'.$role.'_bystatus" style="display:'.$displaydiv{$access}.'">'.
7745: &Apache::lonuserutils::adhoc_status_types($cdom,undef,$role,$selected{$access},
7746: $othertitle,$usertypes,$types,$disabled).
7747: '</div>');
7748: } elsif (($access eq 'inc') && (keys(%domhelpdesk) > 0)) {
7749: $r->print('<div id="'.$role.'_notinc" style="display:'.$displaydiv{$access}.'">'.
7750: &Apache::lonuserutils::adhoc_staff($access,undef,$role,$selected{$access},
7751: \%domhelpdesk,$disabled).
7752: '</div>');
7753: } elsif (($access eq 'exc') && (keys(%domhelpdesk) > 0)) {
7754: $r->print('<div id="'.$role.'_notexc" style="display:'.$displaydiv{$access}.'">'.
7755: &Apache::lonuserutils::adhoc_staff($access,undef,$role,$selected{$access},
7756: \%domhelpdesk,$disabled).
7757: '</div>');
7758: }
7759: $r->print('</p>');
7760: }
7761: $r->print('</div></fieldset>');
7762: my %full=();
7763: my %levels= (
7764: course => {},
7765: domain => {},
7766: system => {},
7767: );
7768: my %levelscurrent=(
7769: course => {},
7770: domain => {},
7771: system => {},
7772: );
7773: &Apache::lonuserutils::custom_role_privs($customroles{$role},\%full,\%levels,\%levelscurrent);
7774: $r->print('<fieldset id="'.$role.'_privs" style="display:'.$displaydiv{'priv'}.'">'.
7775: '<legend>'.$lt{'rpr'}.'</legend>'.
7776: &role_priv_table($role,$permission,$crstype,\%full,\%levels,\%levelscurrent,$overridden{$role}).
7777: '</fieldset></div><div style="padding:0;clear:both;margin:0;border:0"></div>');
7778: }
1.429 raeburn 7779: if ($permission->{'owner'}) {
7780: $r->print('<p><input type="submit" value="'.&mt('Save changes').'" /></p>');
7781: }
1.428 raeburn 7782: } else {
7783: $r->print(&mt('Helpdesk roles have not yet been created in this domain.'));
7784: }
7785: # Form Footer
7786: $r->print('<input type="hidden" name="action" value="helpdesk" />'
7787: .'</form>');
7788: return;
7789: }
7790:
7791: sub domain_adhoc_access {
7792: my ($roles,$domcurrent,$accesstypes,$usertypes,$othertitle) = @_;
7793: my %domusage;
7794: return unless ((ref($roles) eq 'HASH') && (ref($domcurrent) eq 'HASH') && (ref($accesstypes) eq 'ARRAY'));
7795: foreach my $role (keys(%{$roles})) {
7796: if (ref($domcurrent->{$role}) eq 'HASH') {
7797: my $access = $domcurrent->{$role}{'access'};
7798: if (($access eq '') || (!grep(/^\Q$access\E$/,@{$accesstypes}))) {
7799: $access = 'all';
1.432 raeburn 7800: $domusage{$role} = &mt('Any user in domain with active [_1] or [_2] role',&Apache::lonnet::plaintext('dh'),
7801: &Apache::lonnet::plaintext('da'));
1.428 raeburn 7802: } elsif ($access eq 'status') {
7803: if (ref($domcurrent->{$role}{$access}) eq 'ARRAY') {
7804: my @shown;
7805: foreach my $type (@{$domcurrent->{$role}{$access}}) {
7806: unless ($type eq 'default') {
7807: if ($usertypes->{$type}) {
7808: push(@shown,$usertypes->{$type});
7809: }
7810: }
7811: }
7812: if (grep(/^default$/,@{$domcurrent->{$role}{$access}})) {
7813: push(@shown,$othertitle);
7814: }
7815: if (@shown) {
7816: my $shownstatus = join(' '.&mt('or').' ',@shown);
1.432 raeburn 7817: $domusage{$role} = &mt('Any user in domain with active [_1] or [_2] role, and institutional status: [_3]',
7818: &Apache::lonnet::plaintext('dh'),&Apache::lonnet::plaintext('da'),$shownstatus);
1.428 raeburn 7819: } else {
7820: $domusage{$role} = &mt('No one in the domain');
7821: }
7822: }
7823: } elsif ($access eq 'inc') {
7824: my @dominc = ();
7825: if (ref($domcurrent->{$role}{'inc'}) eq 'ARRAY') {
7826: foreach my $user (@{$domcurrent->{$role}{'inc'}}) {
7827: my ($uname,$udom) = split(/:/,$user);
7828: push(@dominc,&Apache::loncommon::aboutmewrapper(&Apache::loncommon::plainname($uname,$udom),$uname,$udom));
7829: }
7830: my $showninc = join(', ',@dominc);
7831: if ($showninc ne '') {
1.432 raeburn 7832: $domusage{$role} = &mt('Include any user in domain with active [_1] or [_2] role, except: [_3]',
7833: &Apache::lonnet::plaintext('dh'),&Apache::lonnet::plaintext('da'),$showninc);
1.428 raeburn 7834: } else {
1.432 raeburn 7835: $domusage{$role} = &mt('Any user in domain with active [_1] or [_2] role',
7836: &Apache::lonnet::plaintext('dh'),&Apache::lonnet::plaintext('da'));
1.428 raeburn 7837: }
7838: }
7839: } elsif ($access eq 'exc') {
7840: my @domexc = ();
7841: if (ref($domcurrent->{$role}{'exc'}) eq 'ARRAY') {
7842: foreach my $user (@{$domcurrent->{$role}{'exc'}}) {
7843: my ($uname,$udom) = split(/:/,$user);
7844: push(@domexc,&Apache::loncommon::aboutmewrapper(&Apache::loncommon::plainname($uname,$udom),$uname,$udom));
7845: }
7846: }
7847: my $shownexc = join(', ',@domexc);
7848: if ($shownexc ne '') {
1.432 raeburn 7849: $domusage{$role} = &mt('Only the following in the domain with active [_1] or [_2] role: [_3]',
7850: &Apache::lonnet::plaintext('dh'),&Apache::lonnet::plaintext('da'),$shownexc);
1.428 raeburn 7851: } else {
7852: $domusage{$role} = &mt('No one in the domain');
7853: }
7854: } elsif ($access eq 'none') {
7855: $domusage{$role} = &mt('No one in the domain');
1.434 raeburn 7856: } elsif ($access eq 'dh') {
1.433 raeburn 7857: $domusage{$role} = &mt('Any user in domain with active [_1] role',&Apache::lonnet::plaintext('dh'));
1.434 raeburn 7858: } elsif ($access eq 'da') {
1.433 raeburn 7859: $domusage{$role} = &mt('Any user in domain with active [_1] role',&Apache::lonnet::plaintext('da'));
1.428 raeburn 7860: } elsif ($access eq 'all') {
1.432 raeburn 7861: $domusage{$role} = &mt('Any user in domain with active [_1] or [_2] role',
7862: &Apache::lonnet::plaintext('dh'),&Apache::lonnet::plaintext('da'));
1.428 raeburn 7863: }
7864: } else {
1.432 raeburn 7865: $domusage{$role} = &mt('Any user in domain with active [_1] or [_2] role',
7866: &Apache::lonnet::plaintext('dh'),&Apache::lonnet::plaintext('da'));
1.428 raeburn 7867: }
7868: }
7869: return %domusage;
7870: }
7871:
7872: sub get_domain_customroles {
7873: my ($cdom,$confname) = @_;
7874: my %existing=&Apache::lonnet::dump('roles',$cdom,$confname,'rolesdef_');
7875: my %customroles;
7876: foreach my $key (keys(%existing)) {
7877: if ($key=~/^rolesdef\_(\w+)$/) {
7878: my $rolename = $1;
7879: my %privs;
7880: ($privs{'system'},$privs{'domain'},$privs{'course'}) = split(/\_/,$existing{$key});
7881: $customroles{$rolename} = \%privs;
7882: }
7883: }
7884: return %customroles;
7885: }
7886:
7887: sub role_priv_table {
7888: my ($role,$permission,$crstype,$full,$levels,$levelscurrent,$overridden) = @_;
7889: return unless ((ref($full) eq 'HASH') && (ref($levels) eq 'HASH') &&
7890: (ref($levelscurrent) eq 'HASH'));
7891: my %lt=&Apache::lonlocal::texthash (
7892: 'crl' => 'Course Level Privilege',
7893: 'def' => 'Domain Defaults',
7894: 'ove' => 'Override in Course',
7895: 'ine' => 'In effect',
7896: 'dis' => 'Disabled',
7897: 'ena' => 'Enabled',
7898: );
7899: if ($crstype eq 'Community') {
7900: $lt{'ove'} = 'Override in Community',
7901: }
7902: my @status = ('Disabled','Enabled');
7903: my (%on,%off);
7904: if (ref($overridden) eq 'HASH') {
7905: if (ref($overridden->{'on'}) eq 'ARRAY') {
7906: map { $on{$_} = 1; } (@{$overridden->{'on'}});
7907: }
7908: if (ref($overridden->{'off'}) eq 'ARRAY') {
7909: map { $off{$_} = 1; } (@{$overridden->{'off'}});
7910: }
7911: }
7912: my $output=&Apache::loncommon::start_data_table().
7913: &Apache::loncommon::start_data_table_header_row().
7914: '<th>'.$lt{'crl'}.'</th><th>'.$lt{'def'}.'</th><th>'.$lt{'ove'}.
7915: '</th><th>'.$lt{'ine'}.'</th>'.
7916: &Apache::loncommon::end_data_table_header_row();
7917: foreach my $priv (sort(keys(%{$full}))) {
7918: next unless ($levels->{'course'}{$priv});
7919: my $privtext = &Apache::lonnet::plaintext($priv,$crstype);
7920: my ($default,$ineffect);
7921: if ($levelscurrent->{'course'}{$priv}) {
7922: $default = '<img src="/adm/lonIcons/navmap.correct.gif" alt="'.$lt{'ena'}.'" />';
7923: $ineffect = $default;
7924: }
7925: my ($customstatus,$checked);
7926: $output .= &Apache::loncommon::start_data_table_row().
7927: '<td>'.$privtext.'</td>'.
7928: '<td>'.$default.'</td><td>';
7929: if (($levelscurrent->{'course'}{$priv}) && ($off{$priv})) {
7930: if ($permission->{'owner'}) {
7931: $checked = ' checked="checked"';
7932: }
7933: $customstatus = '<img src="/adm/lonIcons/navmap.wrong.gif" alt="'.$lt{'dis'}.'" />';
1.430 raeburn 7934: $ineffect = $customstatus;
1.428 raeburn 7935: } elsif ((!$levelscurrent->{'course'}{$priv}) && ($on{$priv})) {
7936: if ($permission->{'owner'}) {
1.430 raeburn 7937: $checked = ' checked="checked"';
1.428 raeburn 7938: }
7939: $customstatus = '<img src="/adm/lonIcons/navmap.correct.gif" alt="'.$lt{'ena'}.'" />';
1.430 raeburn 7940: $ineffect = $customstatus;
1.428 raeburn 7941: }
7942: if ($permission->{'owner'}) {
7943: $output .= '<input type="checkbox" name="'.$role.'_override" value="'.$priv.'"'.$checked.' />';
7944: } else {
7945: $output .= $customstatus;
7946: }
7947: $output .= '</td><td>'.$ineffect.'</td>'.
7948: &Apache::loncommon::end_data_table_row();
7949: }
7950: $output .= &Apache::loncommon::end_data_table();
7951: return $output;
7952: }
7953:
7954: sub get_adhocrole_settings {
1.430 raeburn 7955: my ($cid,$accesstypes,$types,$customroles,$settings,$overridden) = @_;
1.428 raeburn 7956: return unless ((ref($accesstypes) eq 'ARRAY') && (ref($customroles) eq 'HASH') &&
7957: (ref($settings) eq 'HASH') && (ref($overridden) eq 'HASH'));
7958: foreach my $role (split(/,/,$env{'course.'.$cid.'.internal.adhocaccess'})) {
7959: my ($curraccess,$rest) = split(/=/,$env{'course.'.$cid.'.internal.adhoc.'.$role});
7960: if (($curraccess ne '') && (grep(/^\Q$curraccess\E$/,@{$accesstypes}))) {
7961: $settings->{$role}{'access'} = $curraccess;
7962: if (($curraccess eq 'status') && (ref($types) eq 'ARRAY')) {
7963: my @status = split(/,/,$rest);
7964: my @currstatus;
7965: foreach my $type (@status) {
7966: if ($type eq 'default') {
7967: push(@currstatus,$type);
7968: } elsif (grep(/^\Q$type\E$/,@{$types})) {
7969: push(@currstatus,$type);
7970: }
7971: }
7972: if (@currstatus) {
7973: $settings->{$role}{$curraccess} = \@currstatus;
7974: } elsif (($curraccess eq 'exc') || ($curraccess eq 'inc')) {
7975: my @personnel = split(/,/,$rest);
7976: $settings->{$role}{$curraccess} = \@personnel;
7977: }
7978: }
7979: }
7980: }
7981: foreach my $role (keys(%{$customroles})) {
7982: if ($env{'course.'.$cid.'.internal.adhocpriv.'.$role}) {
7983: my %currentprivs;
7984: if (ref($customroles->{$role}) eq 'HASH') {
7985: if (exists($customroles->{$role}{'course'})) {
7986: my %full=();
7987: my %levels= (
7988: course => {},
7989: domain => {},
7990: system => {},
7991: );
7992: my %levelscurrent=(
7993: course => {},
7994: domain => {},
7995: system => {},
7996: );
7997: &Apache::lonuserutils::custom_role_privs($customroles->{$role},\%full,\%levels,\%levelscurrent);
7998: %currentprivs = %{$levelscurrent{'course'}};
7999: }
8000: }
8001: foreach my $item (split(/,/,$env{'course.'.$cid.'.internal.adhocpriv.'.$role})) {
8002: next if ($item eq '');
8003: my ($rule,$rest) = split(/=/,$item);
8004: next unless (($rule eq 'off') || ($rule eq 'on'));
8005: foreach my $priv (split(/:/,$rest)) {
8006: if ($priv ne '') {
8007: if ($rule eq 'off') {
8008: push(@{$overridden->{$role}{'off'}},$priv);
8009: if ($currentprivs{$priv}) {
8010: push(@{$settings->{$role}{'off'}},$priv);
8011: }
8012: } else {
8013: push(@{$overridden->{$role}{'on'}},$priv);
8014: unless ($currentprivs{$priv}) {
8015: push(@{$settings->{$role}{'on'}},$priv);
8016: }
8017: }
8018: }
8019: }
8020: }
8021: }
8022: }
8023: return;
8024: }
8025:
8026: sub update_helpdeskaccess {
8027: my ($r,$permission,$brcrum) = @_;
8028: my $helpitem = 'Course_Helpdesk_Access';
8029: push (@{$brcrum},
8030: {href => '/adm/createuser?action=helpdesk',
8031: text => 'Helpdesk Access',
8032: help => $helpitem},
8033: {href => '/adm/createuser?action=helpdesk',
8034: text => 'Result',
8035: help => $helpitem}
8036: );
8037: my $bread_crumbs_component = 'Helpdesk Staff Access';
8038: my $args = { bread_crumbs => $brcrum,
8039: bread_crumbs_component => $bread_crumbs_component};
8040:
8041: # print page header
8042: $r->print(&header('',$args));
8043: unless ((ref($permission) eq 'HASH') && ($permission->{'owner'})) {
8044: $r->print('<p class="LC_error">'.&mt('You do not have permission to change helpdesk access.').'</p>');
8045: return;
8046: }
1.434 raeburn 8047: my @accesstypes = ('all','dh','da','none','status','inc','exc');
1.428 raeburn 8048: my $cdom = $env{'course.'.$env{'request.course.id'}.'.domain'};
8049: my $cnum = $env{'course.'.$env{'request.course.id'}.'.num'};
8050: my $confname = $cdom.'-domainconfig';
8051: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($cdom);
8052: my $crstype = &Apache::loncommon::course_type();
8053: my %customroles = &get_domain_customroles($cdom,$confname);
8054: my (%settings,%overridden);
8055: &get_adhocrole_settings($env{'request.course.id'},\@accesstypes,
8056: $types,\%customroles,\%settings,\%overridden);
1.432 raeburn 8057: my %domhelpdesk = &Apache::lonnet::get_active_domroles($cdom,['dh','da']);
1.428 raeburn 8058: my (%changed,%storehash,@todelete);
8059:
8060: if (keys(%customroles)) {
8061: my (%newsettings,@incrs);
8062: foreach my $role (keys(%customroles)) {
8063: $newsettings{$role} = {
8064: access => '',
8065: status => '',
8066: exc => '',
8067: inc => '',
8068: on => '',
8069: off => '',
8070: };
8071: my %current;
8072: if (ref($settings{$role}) eq 'HASH') {
8073: %current = %{$settings{$role}};
8074: }
8075: if (ref($overridden{$role}) eq 'HASH') {
8076: $current{'overridden'} = $overridden{$role};
8077: }
8078: if ($env{'form.'.$role.'_incrs'}) {
8079: my $access = $env{'form.'.$role.'_access'};
8080: if (grep(/^\Q$access\E$/,@accesstypes)) {
8081: push(@incrs,$role);
8082: unless ($current{'access'} eq $access) {
8083: $changed{$role}{'access'} = 1;
1.430 raeburn 8084: $storehash{'internal.adhoc.'.$role} = $access;
1.428 raeburn 8085: }
8086: if ($access eq 'status') {
8087: my @statuses = &Apache::loncommon::get_env_multiple('form.'.$role.'_status');
8088: my @stored;
8089: my @shownstatus;
8090: if (ref($types) eq 'ARRAY') {
8091: foreach my $type (sort(@statuses)) {
8092: if ($type eq 'default') {
8093: push(@stored,$type);
8094: } elsif (grep(/^\Q$type\E$/,@{$types})) {
8095: push(@stored,$type);
8096: push(@shownstatus,$usertypes->{$type});
8097: }
8098: }
8099: if (grep(/^default$/,@statuses)) {
8100: push(@shownstatus,$othertitle);
8101: }
8102: $storehash{'internal.adhoc.'.$role} .= '='.join(',',@stored);
8103: }
8104: $newsettings{$role}{'status'} = join(' '.&mt('or').' ',@shownstatus);
8105: if (ref($current{'status'}) eq 'ARRAY') {
8106: my @diffs = &Apache::loncommon::compare_arrays(\@stored,$current{'status'});
8107: if (@diffs) {
8108: $changed{$role}{'status'} = 1;
8109: }
8110: } elsif (@stored) {
8111: $changed{$role}{'status'} = 1;
8112: }
8113: } elsif (($access eq 'inc') || ($access eq 'exc')) {
8114: my @personnel = &Apache::loncommon::get_env_multiple('form.'.$role.'_staff_'.$access);
8115: my @newspecstaff;
8116: my @stored;
8117: my @currstaff;
8118: foreach my $person (sort(@personnel)) {
8119: if ($domhelpdesk{$person}) {
1.430 raeburn 8120: push(@stored,$person);
1.428 raeburn 8121: }
8122: }
8123: if (ref($current{$access}) eq 'ARRAY') {
8124: my @diffs = &Apache::loncommon::compare_arrays(\@stored,$current{$access});
8125: if (@diffs) {
8126: $changed{$role}{$access} = 1;
8127: }
8128: } elsif (@stored) {
8129: $changed{$role}{$access} = 1;
8130: }
8131: $storehash{'internal.adhoc.'.$role} .= '='.join(',',@stored);
8132: foreach my $person (@stored) {
8133: my ($uname,$udom) = split(/:/,$person);
8134: push(@newspecstaff,&Apache::loncommon::aboutmewrapper(&Apache::loncommon::plainname($uname,$udom,'lastname'),$uname,$udom));
8135: }
8136: $newsettings{$role}{$access} = join(', ',sort(@newspecstaff));
8137: }
8138: $newsettings{$role}{'access'} = $access;
8139: }
8140: } else {
8141: if (($current{'access'} ne '') && (grep(/^\Q$current{'access'}\E$/,@accesstypes))) {
8142: $changed{$role}{'access'} = 1;
8143: $newsettings{$role} = {};
8144: push(@todelete,'internal.adhoc.'.$role);
8145: }
8146: }
8147: if (($env{'form.'.$role.'_incrs'}) && ($env{'form.'.$role.'_access'} eq 'none')) {
8148: if (ref($current{'overridden'}) eq 'HASH') {
8149: push(@todelete,'internal.adhocpriv.'.$role);
8150: }
8151: } else {
8152: my %full=();
8153: my %levels= (
8154: course => {},
8155: domain => {},
8156: system => {},
8157: );
8158: my %levelscurrent=(
8159: course => {},
8160: domain => {},
8161: system => {},
8162: );
8163: &Apache::lonuserutils::custom_role_privs($customroles{$role},\%full,\%levels,\%levelscurrent);
8164: my (@updatedon,@updatedoff,@override);
8165: @override = &Apache::loncommon::get_env_multiple('form.'.$role.'_override');
1.430 raeburn 8166: if (@override) {
1.428 raeburn 8167: foreach my $priv (sort(keys(%full))) {
8168: next unless ($levels{'course'}{$priv});
8169: if (grep(/^\Q$priv\E$/,@override)) {
8170: if ($levelscurrent{'course'}{$priv}) {
8171: push(@updatedoff,$priv);
8172: } else {
8173: push(@updatedon,$priv);
8174: }
8175: }
8176: }
8177: }
8178: if (@updatedon) {
1.430 raeburn 8179: $newsettings{$role}{'on'} = join('</li><li>', map { &Apache::lonnet::plaintext($_,$crstype) } (@updatedon));
1.428 raeburn 8180: }
8181: if (@updatedoff) {
8182: $newsettings{$role}{'off'} = join('</li><li>', map { &Apache::lonnet::plaintext($_,$crstype) } (@updatedoff));
8183: }
8184: if (ref($current{'overridden'}) eq 'HASH') {
8185: if (ref($current{'overridden'}{'on'}) eq 'ARRAY') {
8186: if (@updatedon) {
8187: my @diffs = &Apache::loncommon::compare_arrays(\@updatedon,$current{'overridden'}{'on'});
8188: if (@diffs) {
8189: $changed{$role}{'on'} = 1;
8190: }
8191: } else {
8192: $changed{$role}{'on'} = 1;
8193: }
8194: } elsif (@updatedon) {
8195: $changed{$role}{'on'} = 1;
8196: }
8197: if (ref($current{'overridden'}{'off'}) eq 'ARRAY') {
8198: if (@updatedoff) {
8199: my @diffs = &Apache::loncommon::compare_arrays(\@updatedoff,$current{'overridden'}{'off'});
8200: if (@diffs) {
8201: $changed{$role}{'off'} = 1;
8202: }
8203: } else {
8204: $changed{$role}{'off'} = 1;
8205: }
8206: } elsif (@updatedoff) {
8207: $changed{$role}{'off'} = 1;
8208: }
8209: } else {
8210: if (@updatedon) {
8211: $changed{$role}{'on'} = 1;
8212: }
8213: if (@updatedoff) {
8214: $changed{$role}{'off'} = 1;
8215: }
8216: }
8217: if (ref($changed{$role}) eq 'HASH') {
8218: if (($changed{$role}{'on'} || $changed{$role}{'off'})) {
8219: my $newpriv;
8220: if (@updatedon) {
8221: $newpriv = 'on='.join(':',@updatedon);
8222: }
8223: if (@updatedoff) {
8224: $newpriv .= ($newpriv ? ',' : '' ).'off='.join(':',@updatedoff);
8225: }
8226: if ($newpriv eq '') {
8227: push(@todelete,'internal.adhocpriv.'.$role);
8228: } else {
8229: $storehash{'internal.adhocpriv.'.$role} = $newpriv;
8230: }
8231: }
8232: }
8233: }
8234: }
8235: if (@incrs) {
8236: $storehash{'internal.adhocaccess'} = join(',',@incrs);
8237: } elsif (@todelete) {
8238: push(@todelete,'internal.adhocaccess');
8239: }
8240: if (keys(%changed)) {
8241: my ($putres,$delres);
8242: if (keys(%storehash)) {
8243: $putres = &Apache::lonnet::put('environment',\%storehash,$cdom,$cnum);
8244: my %newenvhash;
8245: foreach my $key (keys(%storehash)) {
8246: $newenvhash{'course.'.$env{'request.course.id'}.'.'.$key} = $storehash{$key};
8247: }
8248: &Apache::lonnet::appenv(\%newenvhash);
8249: }
8250: if (@todelete) {
8251: $delres = &Apache::lonnet::del('environment',\@todelete,$cdom,$cnum);
8252: foreach my $key (@todelete) {
8253: &Apache::lonnet::delenv('course.'.$env{'request.course.id'}.'.'.$key);
8254: }
8255: }
8256: if (($putres eq 'ok') || ($delres eq 'ok')) {
8257: my %domconfig = &Apache::lonnet::get_dom('configuration',['helpsettings'],$cdom);
8258: my (%domcurrent,%ordered,%description,%domusage);
8259: if (ref($domconfig{'helpsettings'}) eq 'HASH') {
8260: if (ref($domconfig{'helpsettings'}{'adhoc'}) eq 'HASH') {
8261: %domcurrent = %{$domconfig{'helpsettings'}{'adhoc'}};
8262: }
8263: }
8264: my $count = 0;
8265: foreach my $role (sort(keys(%customroles))) {
8266: my ($order,$desc);
8267: if (ref($domcurrent{$role}) eq 'HASH') {
8268: $order = $domcurrent{$role}{'order'};
8269: $desc = $domcurrent{$role}{'desc'};
8270: }
8271: if ($order eq '') {
8272: $order = $count;
8273: }
8274: $ordered{$order} = $role;
8275: if ($desc ne '') {
8276: $description{$role} = $desc;
8277: } else {
8278: $description{$role}= $role;
8279: }
8280: $count++;
8281: }
8282: my @roles_by_num = ();
8283: foreach my $item (sort {$a <=> $b } (keys(%ordered))) {
8284: push(@roles_by_num,$ordered{$item});
8285: }
8286: %domusage = &domain_adhoc_access(\%changed,\%domcurrent,\@accesstypes,$usertypes,$othertitle);
1.430 raeburn 8287: $r->print(&mt('Helpdesk access settings have been changed as follows').'<br />');
1.428 raeburn 8288: $r->print('<ul>');
8289: foreach my $role (@roles_by_num) {
8290: next unless (ref($changed{$role}) eq 'HASH');
8291: $r->print('<li>'.&mt('Ad hoc role').': <b>'.$description{$role}.'</b>'.
8292: '<ul>');
1.430 raeburn 8293: if ($changed{$role}{'access'} || $changed{$role}{'status'} || $changed{$role}{'inc'} || $changed{$role}{'exc'}) {
1.428 raeburn 8294: $r->print('<li>');
8295: if ($env{'form.'.$role.'_incrs'}) {
8296: if ($newsettings{$role}{'access'} eq 'all') {
8297: $r->print(&mt('All helpdesk staff can access '.lc($crstype).' with this role.'));
1.434 raeburn 8298: } elsif ($newsettings{$role}{'access'} eq 'dh') {
1.433 raeburn 8299: $r->print(&mt('Helpdesk staff can use this role if they have an active [_1] role',
8300: &Apache::lonnet::plaintext('dh')));
1.434 raeburn 8301: } elsif ($newsettings{$role}{'access'} eq 'da') {
1.433 raeburn 8302: $r->print(&mt('Helpdesk staff can use this role if they have an active [_1] role',
8303: &Apache::lonnet::plaintext('da')));
1.428 raeburn 8304: } elsif ($newsettings{$role}{'access'} eq 'none') {
8305: $r->print(&mt('No helpdesk staff can access '.lc($crstype).' with this role.'));
8306: } elsif ($newsettings{$role}{'access'} eq 'status') {
8307: if ($newsettings{$role}{'status'}) {
8308: my ($access,$rest) = split(/=/,$storehash{'internal.adhoc.'.$role});
1.430 raeburn 8309: if (split(/,/,$rest) > 1) {
1.428 raeburn 8310: $r->print(&mt('Helpdesk staff can use this role if their institutional type is one of: [_1].',
8311: $newsettings{$role}{'status'}));
8312: } else {
8313: $r->print(&mt('Helpdesk staff can use this role if their institutional type is: [_1].',
8314: $newsettings{$role}{'status'}));
8315: }
8316: } else {
8317: $r->print(&mt('No helpdesk staff can access '.lc($crstype).' with this role.'));
8318: }
8319: } elsif ($newsettings{$role}{'access'} eq 'exc') {
8320: if ($newsettings{$role}{'exc'}) {
8321: $r->print(&mt('Helpdesk staff who can use this role are as follows:').' '.$newsettings{$role}{'exc'}.'.');
8322: } else {
8323: $r->print(&mt('No helpdesk staff can access '.lc($crstype).' with this role.'));
8324: }
8325: } elsif ($newsettings{$role}{'access'} eq 'inc') {
8326: if ($newsettings{$role}{'inc'}) {
8327: $r->print(&mt('All helpdesk staff may use this role except the following:').' '.$newsettings{$role}{'inc'}.'.');
8328: } else {
8329: $r->print(&mt('All helpdesk staff may use this role.'));
8330: }
8331: }
8332: } else {
8333: $r->print(&mt('Default access set in the domain now applies.').'<br />'.
8334: '<span class="LC_cusr_emph">'.$domusage{$role}.'</span>');
8335: }
8336: $r->print('</li>');
8337: }
8338: unless ($newsettings{$role}{'access'} eq 'none') {
8339: if ($changed{$role}{'off'}) {
8340: if ($newsettings{$role}{'off'}) {
8341: $r->print('<li>'.&mt('Privileges which are available by default for this ad hoc role, but are disabled for this specific '.lc($crstype).':').
8342: '<ul><li>'.$newsettings{$role}{'off'}.'</li></ul></li>');
8343: } else {
1.430 raeburn 8344: $r->print('<li>'.&mt('All privileges available by default for this ad hoc role are enabled.').'</li>');
1.428 raeburn 8345: }
8346: }
1.430 raeburn 8347: if ($changed{$role}{'on'}) {
1.428 raeburn 8348: if ($newsettings{$role}{'on'}) {
8349: $r->print('<li>'.&mt('Privileges which are not available by default for this ad hoc role, but are enabled for this specific '.lc($crstype).':').
8350: '<ul><li>'.$newsettings{$role}{'on'}.'</li></ul></li>');
8351: } else {
1.430 raeburn 8352: $r->print('<li>'.&mt('None of the privileges unavailable by default for this ad hoc role are enabled.').'</li>');
1.428 raeburn 8353: }
8354: }
8355: }
8356: $r->print('</ul></li>');
8357: }
8358: $r->print('</ul>');
8359: }
8360: } else {
1.430 raeburn 8361: $r->print(&mt('No changes made to helpdesk access settings.'));
1.428 raeburn 8362: }
8363: }
8364: return;
8365: }
8366:
1.27 matthew 8367: #-------------------------------------------------- functions for &phase_two
1.160 raeburn 8368: sub user_search_result {
1.221 raeburn 8369: my ($context,$srch) = @_;
1.160 raeburn 8370: my %allhomes;
8371: my %inst_matches;
8372: my %srch_results;
1.181 raeburn 8373: my ($response,$currstate,$forcenewuser,$dirsrchres);
1.183 raeburn 8374: $srch->{'srchterm'} =~ s/\s+/ /g;
1.176 raeburn 8375: if ($srch->{'srchby'} !~ /^(uname|lastname|lastfirst)$/) {
1.160 raeburn 8376: $response = &mt('Invalid search.');
8377: }
8378: if ($srch->{'srchin'} !~ /^(crs|dom|alc|instd)$/) {
8379: $response = &mt('Invalid search.');
8380: }
1.177 raeburn 8381: if ($srch->{'srchtype'} !~ /^(exact|contains|begins)$/) {
1.160 raeburn 8382: $response = &mt('Invalid search.');
8383: }
8384: if ($srch->{'srchterm'} eq '') {
8385: $response = &mt('You must enter a search term.');
8386: }
1.183 raeburn 8387: if ($srch->{'srchterm'} =~ /^\s+$/) {
8388: $response = &mt('Your search term must contain more than just spaces.');
8389: }
1.160 raeburn 8390: if (($srch->{'srchin'} eq 'dom') || ($srch->{'srchin'} eq 'instd')) {
8391: if (($srch->{'srchdomain'} eq '') ||
1.163 albertel 8392: ! (&Apache::lonnet::domain($srch->{'srchdomain'}))) {
1.160 raeburn 8393: $response = &mt('You must specify a valid domain when searching in a domain or institutional directory.')
8394: }
8395: }
8396: if (($srch->{'srchin'} eq 'dom') || ($srch->{'srchin'} eq 'crs') ||
8397: ($srch->{'srchin'} eq 'alc')) {
1.176 raeburn 8398: if ($srch->{'srchby'} eq 'uname') {
1.243 raeburn 8399: my $unamecheck = $srch->{'srchterm'};
8400: if ($srch->{'srchtype'} eq 'contains') {
8401: if ($unamecheck !~ /^\w/) {
8402: $unamecheck = 'a'.$unamecheck;
8403: }
8404: }
8405: if ($unamecheck !~ /^$match_username$/) {
1.176 raeburn 8406: $response = &mt('You must specify a valid username. Only the following are allowed: letters numbers - . @');
8407: }
1.160 raeburn 8408: }
8409: }
1.180 raeburn 8410: if ($response ne '') {
1.413 raeburn 8411: $response = '<span class="LC_warning">'.$response.'</span><br />';
1.180 raeburn 8412: }
1.160 raeburn 8413: if ($srch->{'srchin'} eq 'instd') {
1.412 raeburn 8414: my $instd_chk = &instdirectorysrch_check($srch);
1.160 raeburn 8415: if ($instd_chk ne 'ok') {
1.412 raeburn 8416: my $domd_chk = &domdirectorysrch_check($srch);
1.413 raeburn 8417: $response .= '<span class="LC_warning">'.$instd_chk.'</span><br />';
1.412 raeburn 8418: if ($domd_chk eq 'ok') {
1.435 raeburn 8419: $response .= &mt('You may want to search in the LON-CAPA domain instead of in the institutional directory.');
1.412 raeburn 8420: }
1.415 raeburn 8421: $response .= '<br />';
1.412 raeburn 8422: }
8423: } else {
1.417 raeburn 8424: unless (($context eq 'requestcrs') && ($srch->{'srchtype'} eq 'exact')) {
1.412 raeburn 8425: my $domd_chk = &domdirectorysrch_check($srch);
1.438 raeburn 8426: if (($domd_chk ne 'ok') && ($env{'form.action'} ne 'accesslogs')) {
1.412 raeburn 8427: my $instd_chk = &instdirectorysrch_check($srch);
1.413 raeburn 8428: $response .= '<span class="LC_warning">'.$domd_chk.'</span><br />';
1.412 raeburn 8429: if ($instd_chk eq 'ok') {
1.435 raeburn 8430: $response .= &mt('You may want to search in the institutional directory instead of in the LON-CAPA domain.');
1.412 raeburn 8431: }
1.415 raeburn 8432: $response .= '<br />';
1.412 raeburn 8433: }
1.160 raeburn 8434: }
8435: }
8436: if ($response ne '') {
1.180 raeburn 8437: return ($currstate,$response);
1.160 raeburn 8438: }
8439: if ($srch->{'srchby'} eq 'uname') {
8440: if (($srch->{'srchin'} eq 'dom') || ($srch->{'srchin'} eq 'crs')) {
8441: if ($env{'form.forcenew'}) {
8442: if ($srch->{'srchdomain'} ne $env{'request.role.domain'}) {
8443: my $uhome=&Apache::lonnet::homeserver($srch->{'srchterm'},$srch->{'srchdomain'});
8444: if ($uhome eq 'no_host') {
8445: my $domdesc = &Apache::lonnet::domain($env{'request.role.domain'},'description');
1.180 raeburn 8446: my $showdom = &display_domain_info($env{'request.role.domain'});
8447: $response = &mt('New users can only be created in the domain to which your current role belongs - [_1].',$showdom);
1.160 raeburn 8448: } else {
1.179 raeburn 8449: $currstate = 'modify';
1.160 raeburn 8450: }
8451: } else {
1.179 raeburn 8452: $currstate = 'modify';
1.160 raeburn 8453: }
8454: } else {
8455: if ($srch->{'srchin'} eq 'dom') {
1.162 raeburn 8456: if ($srch->{'srchtype'} eq 'exact') {
8457: my $uhome=&Apache::lonnet::homeserver($srch->{'srchterm'},$srch->{'srchdomain'});
8458: if ($uhome eq 'no_host') {
1.179 raeburn 8459: ($currstate,$response,$forcenewuser) =
1.221 raeburn 8460: &build_search_response($context,$srch,%srch_results);
1.162 raeburn 8461: } else {
1.179 raeburn 8462: $currstate = 'modify';
1.416 raeburn 8463: if ($env{'form.action'} eq 'accesslogs') {
8464: $currstate = 'activity';
8465: }
1.310 raeburn 8466: my $uname = $srch->{'srchterm'};
8467: my $udom = $srch->{'srchdomain'};
8468: $srch_results{$uname.':'.$udom} =
8469: { &Apache::lonnet::get('environment',
8470: ['firstname',
8471: 'lastname',
8472: 'permanentemail'],
8473: $udom,$uname)
8474: };
1.162 raeburn 8475: }
8476: } else {
8477: %srch_results = &Apache::lonnet::usersearch($srch);
1.179 raeburn 8478: ($currstate,$response,$forcenewuser) =
1.221 raeburn 8479: &build_search_response($context,$srch,%srch_results);
1.160 raeburn 8480: }
8481: } else {
1.167 albertel 8482: my $courseusers = &get_courseusers();
1.162 raeburn 8483: if ($srch->{'srchtype'} eq 'exact') {
1.167 albertel 8484: if (exists($courseusers->{$srch->{'srchterm'}.':'.$srch->{'srchdomain'}})) {
1.179 raeburn 8485: $currstate = 'modify';
1.162 raeburn 8486: } else {
1.179 raeburn 8487: ($currstate,$response,$forcenewuser) =
1.221 raeburn 8488: &build_search_response($context,$srch,%srch_results);
1.162 raeburn 8489: }
1.160 raeburn 8490: } else {
1.167 albertel 8491: foreach my $user (keys(%$courseusers)) {
1.162 raeburn 8492: my ($cuname,$cudomain) = split(/:/,$user);
8493: if ($cudomain eq $srch->{'srchdomain'}) {
1.177 raeburn 8494: my $matched = 0;
8495: if ($srch->{'srchtype'} eq 'begins') {
8496: if ($cuname =~ /^\Q$srch->{'srchterm'}\E/i) {
8497: $matched = 1;
8498: }
8499: } else {
8500: if ($cuname =~ /\Q$srch->{'srchterm'}\E/i) {
8501: $matched = 1;
8502: }
8503: }
8504: if ($matched) {
1.167 albertel 8505: $srch_results{$user} =
8506: {&Apache::lonnet::get('environment',
8507: ['firstname',
8508: 'lastname',
1.194 albertel 8509: 'permanentemail'],
8510: $cudomain,$cuname)};
1.162 raeburn 8511: }
8512: }
8513: }
1.179 raeburn 8514: ($currstate,$response,$forcenewuser) =
1.221 raeburn 8515: &build_search_response($context,$srch,%srch_results);
1.160 raeburn 8516: }
8517: }
8518: }
8519: } elsif ($srch->{'srchin'} eq 'alc') {
1.179 raeburn 8520: $currstate = 'query';
1.160 raeburn 8521: } elsif ($srch->{'srchin'} eq 'instd') {
1.181 raeburn 8522: ($dirsrchres,%srch_results) = &Apache::lonnet::inst_directory_query($srch);
8523: if ($dirsrchres eq 'ok') {
8524: ($currstate,$response,$forcenewuser) =
1.221 raeburn 8525: &build_search_response($context,$srch,%srch_results);
1.181 raeburn 8526: } else {
8527: my $showdom = &display_domain_info($srch->{'srchdomain'});
8528: $response = '<span class="LC_warning">'.
8529: &mt('Institutional directory search is not available in domain: [_1]',$showdom).
8530: '</span><br />'.
1.435 raeburn 8531: &mt('You may want to search in the LON-CAPA domain instead of in the institutional directory.').
1.415 raeburn 8532: '<br />';
1.181 raeburn 8533: }
1.160 raeburn 8534: }
8535: } else {
8536: if ($srch->{'srchin'} eq 'dom') {
8537: %srch_results = &Apache::lonnet::usersearch($srch);
1.179 raeburn 8538: ($currstate,$response,$forcenewuser) =
1.221 raeburn 8539: &build_search_response($context,$srch,%srch_results);
1.160 raeburn 8540: } elsif ($srch->{'srchin'} eq 'crs') {
1.167 albertel 8541: my $courseusers = &get_courseusers();
8542: foreach my $user (keys(%$courseusers)) {
1.160 raeburn 8543: my ($uname,$udom) = split(/:/,$user);
8544: my %names = &Apache::loncommon::getnames($uname,$udom);
8545: my %emails = &Apache::loncommon::getemails($uname,$udom);
8546: if ($srch->{'srchby'} eq 'lastname') {
8547: if ((($srch->{'srchtype'} eq 'exact') &&
8548: ($names{'lastname'} eq $srch->{'srchterm'})) ||
1.177 raeburn 8549: (($srch->{'srchtype'} eq 'begins') &&
8550: ($names{'lastname'} =~ /^\Q$srch->{'srchterm'}\E/i)) ||
1.160 raeburn 8551: (($srch->{'srchtype'} eq 'contains') &&
8552: ($names{'lastname'} =~ /\Q$srch->{'srchterm'}\E/i))) {
8553: $srch_results{$user} = {firstname => $names{'firstname'},
8554: lastname => $names{'lastname'},
8555: permanentemail => $emails{'permanentemail'},
8556: };
8557: }
8558: } elsif ($srch->{'srchby'} eq 'lastfirst') {
8559: my ($srchlast,$srchfirst) = split(/,/,$srch->{'srchterm'});
1.177 raeburn 8560: $srchlast =~ s/\s+$//;
8561: $srchfirst =~ s/^\s+//;
1.160 raeburn 8562: if ($srch->{'srchtype'} eq 'exact') {
8563: if (($names{'lastname'} eq $srchlast) &&
8564: ($names{'firstname'} eq $srchfirst)) {
8565: $srch_results{$user} = {firstname => $names{'firstname'},
8566: lastname => $names{'lastname'},
8567: permanentemail => $emails{'permanentemail'},
8568:
8569: };
8570: }
1.177 raeburn 8571: } elsif ($srch->{'srchtype'} eq 'begins') {
8572: if (($names{'lastname'} =~ /^\Q$srchlast\E/i) &&
8573: ($names{'firstname'} =~ /^\Q$srchfirst\E/i)) {
8574: $srch_results{$user} = {firstname => $names{'firstname'},
8575: lastname => $names{'lastname'},
8576: permanentemail => $emails{'permanentemail'},
8577: };
8578: }
8579: } else {
1.160 raeburn 8580: if (($names{'lastname'} =~ /\Q$srchlast\E/i) &&
8581: ($names{'firstname'} =~ /\Q$srchfirst\E/i)) {
8582: $srch_results{$user} = {firstname => $names{'firstname'},
8583: lastname => $names{'lastname'},
8584: permanentemail => $emails{'permanentemail'},
8585: };
8586: }
8587: }
8588: }
8589: }
1.179 raeburn 8590: ($currstate,$response,$forcenewuser) =
1.221 raeburn 8591: &build_search_response($context,$srch,%srch_results);
1.160 raeburn 8592: } elsif ($srch->{'srchin'} eq 'alc') {
1.179 raeburn 8593: $currstate = 'query';
1.160 raeburn 8594: } elsif ($srch->{'srchin'} eq 'instd') {
1.181 raeburn 8595: ($dirsrchres,%srch_results) = &Apache::lonnet::inst_directory_query($srch);
8596: if ($dirsrchres eq 'ok') {
8597: ($currstate,$response,$forcenewuser) =
1.221 raeburn 8598: &build_search_response($context,$srch,%srch_results);
1.181 raeburn 8599: } else {
1.412 raeburn 8600: my $showdom = &display_domain_info($srch->{'srchdomain'});
8601: $response = '<span class="LC_warning">'.
1.181 raeburn 8602: &mt('Institutional directory search is not available in domain: [_1]',$showdom).
8603: '</span><br />'.
1.435 raeburn 8604: &mt('You may want to search in the LON-CAPA domain instead of in the institutional directory.').
1.415 raeburn 8605: '<br />';
1.181 raeburn 8606: }
1.160 raeburn 8607: }
8608: }
1.179 raeburn 8609: return ($currstate,$response,$forcenewuser,\%srch_results);
1.160 raeburn 8610: }
8611:
1.412 raeburn 8612: sub domdirectorysrch_check {
8613: my ($srch) = @_;
8614: my $response;
8615: my %dom_inst_srch = &Apache::lonnet::get_dom('configuration',
8616: ['directorysrch'],$srch->{'srchdomain'});
8617: my $showdom = &display_domain_info($srch->{'srchdomain'});
8618: if (ref($dom_inst_srch{'directorysrch'}) eq 'HASH') {
8619: if ($dom_inst_srch{'directorysrch'}{'lcavailable'} eq '0') {
8620: return &mt('LON-CAPA directory search is not available in domain: [_1]',$showdom);
8621: }
8622: if ($dom_inst_srch{'directorysrch'}{'lclocalonly'}) {
8623: if ($env{'request.role.domain'} ne $srch->{'srchdomain'}) {
8624: return &mt('LON-CAPA directory search in domain: [_1] is only allowed for users with a current role in the domain.',$showdom);
8625: }
8626: }
8627: }
8628: return 'ok';
8629: }
8630:
8631: sub instdirectorysrch_check {
1.160 raeburn 8632: my ($srch) = @_;
8633: my $can_search = 0;
8634: my $response;
8635: my %dom_inst_srch = &Apache::lonnet::get_dom('configuration',
8636: ['directorysrch'],$srch->{'srchdomain'});
1.180 raeburn 8637: my $showdom = &display_domain_info($srch->{'srchdomain'});
1.160 raeburn 8638: if (ref($dom_inst_srch{'directorysrch'}) eq 'HASH') {
8639: if (!$dom_inst_srch{'directorysrch'}{'available'}) {
1.180 raeburn 8640: return &mt('Institutional directory search is not available in domain: [_1]',$showdom);
1.160 raeburn 8641: }
8642: if ($dom_inst_srch{'directorysrch'}{'localonly'}) {
8643: if ($env{'request.role.domain'} ne $srch->{'srchdomain'}) {
1.180 raeburn 8644: return &mt('Institutional directory search in domain: [_1] is only allowed for users with a current role in the domain.',$showdom);
1.160 raeburn 8645: }
8646: my @usertypes = split(/:/,$env{'environment.inststatus'});
8647: if (!@usertypes) {
8648: push(@usertypes,'default');
8649: }
8650: if (ref($dom_inst_srch{'directorysrch'}{'cansearch'}) eq 'ARRAY') {
8651: foreach my $type (@usertypes) {
8652: if (grep(/^\Q$type\E$/,@{$dom_inst_srch{'directorysrch'}{'cansearch'}})) {
8653: $can_search = 1;
8654: last;
8655: }
8656: }
8657: }
8658: if (!$can_search) {
8659: my ($insttypes,$order) = &Apache::lonnet::retrieve_inst_usertypes($srch->{'srchdomain'});
8660: my @longtypes;
8661: foreach my $item (@usertypes) {
1.229 raeburn 8662: if (defined($insttypes->{$item})) {
8663: push (@longtypes,$insttypes->{$item});
8664: } elsif ($item eq 'default') {
8665: push (@longtypes,&mt('other'));
8666: }
1.160 raeburn 8667: }
8668: my $insttype_str = join(', ',@longtypes);
1.180 raeburn 8669: return &mt('Institutional directory search in domain: [_1] is not available to your user type: ',$showdom).$insttype_str;
1.229 raeburn 8670: }
1.160 raeburn 8671: } else {
8672: $can_search = 1;
8673: }
8674: } else {
1.180 raeburn 8675: return &mt('Institutional directory search has not been configured for domain: [_1]',$showdom);
1.160 raeburn 8676: }
8677: my %longtext = &Apache::lonlocal::texthash (
1.167 albertel 8678: uname => 'username',
1.160 raeburn 8679: lastfirst => 'last name, first name',
1.167 albertel 8680: lastname => 'last name',
1.172 raeburn 8681: contains => 'contains',
1.178 raeburn 8682: exact => 'as exact match to',
8683: begins => 'begins with',
1.160 raeburn 8684: );
8685: if ($can_search) {
8686: if (ref($dom_inst_srch{'directorysrch'}{'searchby'}) eq 'ARRAY') {
8687: if (!grep(/^\Q$srch->{'srchby'}\E$/,@{$dom_inst_srch{'directorysrch'}{'searchby'}})) {
1.180 raeburn 8688: return &mt('Institutional directory search in domain: [_1] is not available for searching by "[_2]"',$showdom,$longtext{$srch->{'srchby'}});
1.160 raeburn 8689: }
8690: } else {
1.180 raeburn 8691: return &mt('Institutional directory search in domain: [_1] is not available.', $showdom);
1.160 raeburn 8692: }
8693: }
8694: if ($can_search) {
1.178 raeburn 8695: if (ref($dom_inst_srch{'directorysrch'}{'searchtypes'}) eq 'ARRAY') {
8696: if (grep(/^\Q$srch->{'srchtype'}\E/,@{$dom_inst_srch{'directorysrch'}{'searchtypes'}})) {
8697: return 'ok';
8698: } else {
1.180 raeburn 8699: return &mt('Institutional directory search in domain [_1] is not available for the requested search type: "[_2]"',$showdom,$longtext{$srch->{'srchtype'}});
1.178 raeburn 8700: }
8701: } else {
8702: if ((($dom_inst_srch{'directorysrch'}{'searchtypes'} eq 'specify') &&
8703: ($srch->{'srchtype'} eq 'exact' || $srch->{'srchtype'} eq 'contains')) ||
8704: ($dom_inst_srch{'directorysrch'}{'searchtypes'} eq $srch->{'srchtype'})) {
8705: return 'ok';
8706: } else {
1.180 raeburn 8707: return &mt('Institutional directory search in domain [_1] is not available for the requested search type: "[_2]"',$showdom,$longtext{$srch->{'srchtype'}});
1.178 raeburn 8708: }
1.160 raeburn 8709: }
8710: }
8711: }
8712:
8713: sub get_courseusers {
8714: my %advhash;
1.167 albertel 8715: my $classlist = &Apache::loncoursedata::get_classlist();
1.160 raeburn 8716: my %coursepersonnel=&Apache::lonnet::get_course_adv_roles();
8717: foreach my $role (sort(keys(%coursepersonnel))) {
8718: foreach my $user (split(/\,/,$coursepersonnel{$role})) {
1.167 albertel 8719: if (!exists($classlist->{$user})) {
8720: $classlist->{$user} = [];
8721: }
1.160 raeburn 8722: }
8723: }
1.167 albertel 8724: return $classlist;
1.160 raeburn 8725: }
8726:
8727: sub build_search_response {
1.221 raeburn 8728: my ($context,$srch,%srch_results) = @_;
1.179 raeburn 8729: my ($currstate,$response,$forcenewuser);
1.160 raeburn 8730: my %names = (
1.330 bisitz 8731: 'uname' => 'username',
8732: 'lastname' => 'last name',
1.160 raeburn 8733: 'lastfirst' => 'last name, first name',
1.330 bisitz 8734: 'crs' => 'this course',
8735: 'dom' => 'LON-CAPA domain',
8736: 'instd' => 'the institutional directory for domain',
1.160 raeburn 8737: );
8738:
8739: my %single = (
1.180 raeburn 8740: begins => 'A match',
1.160 raeburn 8741: contains => 'A match',
1.180 raeburn 8742: exact => 'An exact match',
1.160 raeburn 8743: );
8744: my %nomatch = (
1.180 raeburn 8745: begins => 'No match',
1.160 raeburn 8746: contains => 'No match',
1.180 raeburn 8747: exact => 'No exact match',
1.160 raeburn 8748: );
8749: if (keys(%srch_results) > 1) {
1.179 raeburn 8750: $currstate = 'select';
1.160 raeburn 8751: } else {
8752: if (keys(%srch_results) == 1) {
1.416 raeburn 8753: if ($env{'form.action'} eq 'accesslogs') {
8754: $currstate = 'activity';
8755: } else {
8756: $currstate = 'modify';
8757: }
1.180 raeburn 8758: $response = &mt("$single{$srch->{'srchtype'}} was found for the $names{$srch->{'srchby'}} ([_1]) in $names{$srch->{'srchin'}}.",$srch->{'srchterm'});
8759: if ($srch->{'srchin'} eq 'dom' || $srch->{'srchin'} eq 'instd') {
1.330 bisitz 8760: $response .= ': '.&display_domain_info($srch->{'srchdomain'});
1.180 raeburn 8761: }
1.330 bisitz 8762: } else { # Search has nothing found. Prepare message to user.
8763: $response = '<span class="LC_warning">';
1.180 raeburn 8764: if ($srch->{'srchin'} eq 'dom' || $srch->{'srchin'} eq 'instd') {
1.330 bisitz 8765: $response .= &mt("$nomatch{$srch->{'srchtype'}} found for the $names{$srch->{'srchby'}} [_1] in $names{$srch->{'srchin'}}: [_2]",
8766: '<b>'.$srch->{'srchterm'}.'</b>',
8767: &display_domain_info($srch->{'srchdomain'}));
8768: } else {
8769: $response .= &mt("$nomatch{$srch->{'srchtype'}} found for the $names{$srch->{'srchby'}} [_1] in $names{$srch->{'srchin'}}.",
8770: '<b>'.$srch->{'srchterm'}.'</b>');
1.180 raeburn 8771: }
8772: $response .= '</span>';
1.330 bisitz 8773:
1.160 raeburn 8774: if ($srch->{'srchin'} ne 'alc') {
8775: $forcenewuser = 1;
8776: my $cansrchinst = 0;
1.438 raeburn 8777: if (($srch->{'srchdomain'}) && ($env{'form.action'} ne 'accesslogs')) {
1.160 raeburn 8778: my %domconfig = &Apache::lonnet::get_dom('configuration',['directorysrch'],$srch->{'srchdomain'});
8779: if (ref($domconfig{'directorysrch'}) eq 'HASH') {
8780: if ($domconfig{'directorysrch'}{'available'}) {
8781: $cansrchinst = 1;
8782: }
8783: }
8784: }
1.180 raeburn 8785: if ((($srch->{'srchby'} eq 'lastfirst') ||
8786: ($srch->{'srchby'} eq 'lastname')) &&
8787: ($srch->{'srchin'} eq 'dom')) {
8788: if ($cansrchinst) {
8789: $response .= '<br />'.&mt('You may want to broaden your search to a search of the institutional directory for the domain.');
1.160 raeburn 8790: }
8791: }
1.180 raeburn 8792: if ($srch->{'srchin'} eq 'crs') {
8793: $response .= '<br />'.&mt('You may want to broaden your search to the selected LON-CAPA domain.');
8794: }
8795: }
1.305 raeburn 8796: my $createdom = $env{'request.role.domain'};
8797: if ($context eq 'requestcrs') {
8798: if ($env{'form.coursedom'} ne '') {
8799: $createdom = $env{'form.coursedom'};
8800: }
8801: }
1.416 raeburn 8802: unless (($env{'form.action'} eq 'accesslogs') || (($srch->{'srchby'} eq 'uname') && ($srch->{'srchin'} eq 'dom') &&
8803: ($srch->{'srchtype'} eq 'exact') && ($srch->{'srchdomain'} eq $createdom))) {
1.221 raeburn 8804: my $cancreate =
1.305 raeburn 8805: &Apache::lonuserutils::can_create_user($createdom,$context);
8806: my $targetdom = '<span class="LC_cusr_emph">'.$createdom.'</span>';
1.221 raeburn 8807: if ($cancreate) {
1.305 raeburn 8808: my $showdom = &display_domain_info($createdom);
1.266 bisitz 8809: $response .= '<br /><br />'
8810: .'<b>'.&mt('To add a new user:').'</b>'
1.305 raeburn 8811: .'<br />';
8812: if ($context eq 'requestcrs') {
8813: $response .= &mt("(You can only define new users in the new course's domain - [_1])",$targetdom);
8814: } else {
8815: $response .= &mt("(You can only create new users in your current role's domain - [_1])",$targetdom);
8816: }
8817: $response .='<ul><li>'
1.266 bisitz 8818: .&mt("Set 'Domain/institution to search' to: [_1]",'<span class="LC_cusr_emph">'.$showdom.'</span>')
8819: .'</li><li>'
8820: .&mt("Set 'Search criteria' to: [_1]username is ..... in selected LON-CAPA domain[_2]",'<span class="LC_cusr_emph">','</span>')
8821: .'</li><li>'
8822: .&mt('Provide the proposed username')
8823: .'</li><li>'
8824: .&mt("Click 'Search'")
8825: .'</li></ul><br />';
1.221 raeburn 8826: } else {
1.422 raeburn 8827: unless (($context eq 'domain') && ($env{'form.action'} eq 'singleuser')) {
8828: my $helplink = ' href="javascript:helpMenu('."'display'".')"';
8829: $response .= '<br /><br />';
8830: if ($context eq 'requestcrs') {
8831: $response .= &mt("You are not authorized to define new users in the new course's domain - [_1].",$targetdom);
8832: } else {
8833: $response .= &mt("You are not authorized to create new users in your current role's domain - [_1].",$targetdom);
8834: }
8835: $response .= '<br />'
8836: .&mt('Please contact the [_1]helpdesk[_2] if you need to create a new user.'
8837: ,' <a'.$helplink.'>'
8838: ,'</a>')
8839: .'<br />';
1.305 raeburn 8840: }
1.221 raeburn 8841: }
1.160 raeburn 8842: }
8843: }
8844: }
1.179 raeburn 8845: return ($currstate,$response,$forcenewuser);
1.160 raeburn 8846: }
8847:
1.180 raeburn 8848: sub display_domain_info {
8849: my ($dom) = @_;
8850: my $output = $dom;
8851: if ($dom ne '') {
8852: my $domdesc = &Apache::lonnet::domain($dom,'description');
8853: if ($domdesc ne '') {
8854: $output .= ' <span class="LC_cusr_emph">('.$domdesc.')</span>';
8855: }
8856: }
8857: return $output;
8858: }
8859:
1.160 raeburn 8860: sub crumb_utilities {
8861: my %elements = (
8862: crtuser => {
8863: srchterm => 'text',
1.172 raeburn 8864: srchin => 'selectbox',
1.160 raeburn 8865: srchby => 'selectbox',
8866: srchtype => 'selectbox',
8867: srchdomain => 'selectbox',
8868: },
1.207 raeburn 8869: crtusername => {
8870: srchterm => 'text',
8871: srchdomain => 'selectbox',
8872: },
1.160 raeburn 8873: docustom => {
8874: rolename => 'selectbox',
8875: newrolename => 'textbox',
8876: },
1.179 raeburn 8877: studentform => {
8878: srchterm => 'text',
8879: srchin => 'selectbox',
8880: srchby => 'selectbox',
8881: srchtype => 'selectbox',
8882: srchdomain => 'selectbox',
8883: },
1.160 raeburn 8884: );
8885:
8886: my $jsback .= qq|
8887: function backPage(formname,prevphase,prevstate) {
1.211 raeburn 8888: if (typeof prevphase == 'undefined') {
8889: formname.phase.value = '';
8890: }
8891: else {
8892: formname.phase.value = prevphase;
8893: }
8894: if (typeof prevstate == 'undefined') {
8895: formname.currstate.value = '';
8896: }
8897: else {
8898: formname.currstate.value = prevstate;
8899: }
1.160 raeburn 8900: formname.submit();
8901: }
8902: |;
8903: return ($jsback,\%elements);
8904: }
8905:
1.26 matthew 8906: sub course_level_table {
1.375 raeburn 8907: my ($inccourses,$showcredits,$defaultcredits) = @_;
8908: return unless (ref($inccourses) eq 'HASH');
1.26 matthew 8909: my $table = '';
1.62 www 8910: # Custom Roles?
8911:
1.190 raeburn 8912: my %customroles=&Apache::lonuserutils::my_custom_roles();
1.89 raeburn 8913: my %lt=&Apache::lonlocal::texthash(
8914: 'exs' => "Existing sections",
8915: 'new' => "Define new section",
8916: 'ssd' => "Set Start Date",
8917: 'sed' => "Set End Date",
1.131 raeburn 8918: 'crl' => "Course Level",
1.89 raeburn 8919: 'act' => "Activate",
8920: 'rol' => "Role",
8921: 'ext' => "Extent",
1.113 raeburn 8922: 'grs' => "Section",
1.375 raeburn 8923: 'crd' => "Credits",
1.89 raeburn 8924: 'sta' => "Start",
8925: 'end' => "End"
8926: );
1.62 www 8927:
1.375 raeburn 8928: foreach my $protectedcourse (sort(keys(%{$inccourses}))) {
1.135 raeburn 8929: my $thiscourse=$protectedcourse;
1.26 matthew 8930: $thiscourse=~s:_:/:g;
8931: my %coursedata=&Apache::lonnet::coursedescription($thiscourse);
1.365 raeburn 8932: my $isowner = &Apache::lonuserutils::is_courseowner($protectedcourse,$coursedata{'internal.courseowner'});
1.26 matthew 8933: my $area=$coursedata{'description'};
1.321 raeburn 8934: my $crstype=$coursedata{'type'};
1.135 raeburn 8935: if (!defined($area)) { $area=&mt('Unavailable course').': '.$protectedcourse; }
1.89 raeburn 8936: my ($domain,$cnum)=split(/\//,$thiscourse);
1.115 albertel 8937: my %sections_count;
1.101 albertel 8938: if (defined($env{'request.course.id'})) {
8939: if ($env{'request.course.id'} eq $domain.'_'.$cnum) {
1.115 albertel 8940: %sections_count =
8941: &Apache::loncommon::get_sections($domain,$cnum);
1.92 raeburn 8942: }
8943: }
1.321 raeburn 8944: my @roles = &Apache::lonuserutils::roles_by_context('course','',$crstype);
1.213 raeburn 8945: foreach my $role (@roles) {
1.321 raeburn 8946: my $plrole=&Apache::lonnet::plaintext($role,$crstype);
1.329 raeburn 8947: if ((&Apache::lonnet::allowed('c'.$role,$thiscourse)) ||
8948: ((($role eq 'cc') || ($role eq 'co')) && ($isowner))) {
1.221 raeburn 8949: $table .= &course_level_row($protectedcourse,$role,$area,$domain,
1.375 raeburn 8950: $plrole,\%sections_count,\%lt,
1.402 raeburn 8951: $showcredits,$defaultcredits,$crstype);
1.221 raeburn 8952: } elsif ($env{'request.course.sec'} ne '') {
8953: if (&Apache::lonnet::allowed('c'.$role,$thiscourse.'/'.
8954: $env{'request.course.sec'})) {
8955: $table .= &course_level_row($protectedcourse,$role,$area,$domain,
1.375 raeburn 8956: $plrole,\%sections_count,\%lt,
1.402 raeburn 8957: $showcredits,$defaultcredits,$crstype);
1.26 matthew 8958: }
8959: }
8960: }
1.221 raeburn 8961: if (&Apache::lonnet::allowed('ccr',$thiscourse)) {
1.324 raeburn 8962: foreach my $cust (sort(keys(%customroles))) {
8963: next if ($crstype eq 'Community' && $customroles{$cust} =~ /bre\&S/);
1.221 raeburn 8964: my $role = 'cr_cr_'.$env{'user.domain'}.'_'.$env{'user.name'}.'_'.$cust;
8965: $table .= &course_level_row($protectedcourse,$role,$area,$domain,
1.402 raeburn 8966: $cust,\%sections_count,\%lt,
8967: $showcredits,$defaultcredits,$crstype);
1.221 raeburn 8968: }
1.62 www 8969: }
1.26 matthew 8970: }
8971: return '' if ($table eq ''); # return nothing if there is nothing
8972: # in the table
1.188 raeburn 8973: my $result;
8974: if (!$env{'request.course.id'}) {
8975: $result = '<h4>'.$lt{'crl'}.'</h4>'."\n";
8976: }
8977: $result .=
1.136 raeburn 8978: &Apache::loncommon::start_data_table().
8979: &Apache::loncommon::start_data_table_header_row().
1.375 raeburn 8980: '<th>'.$lt{'act'}.'</th><th>'.$lt{'rol'}.'</th>'."\n".
1.402 raeburn 8981: '<th>'.$lt{'ext'}.'</th><th>'."\n";
8982: if ($showcredits) {
8983: $result .= $lt{'crd'}.'</th>';
8984: }
8985: $result .=
1.375 raeburn 8986: '<th>'.$lt{'grs'}.'</th><th>'.$lt{'sta'}.'</th>'."\n".
8987: '<th>'.$lt{'end'}.'</th>'.
1.136 raeburn 8988: &Apache::loncommon::end_data_table_header_row().
8989: $table.
8990: &Apache::loncommon::end_data_table();
1.26 matthew 8991: return $result;
8992: }
1.88 raeburn 8993:
1.221 raeburn 8994: sub course_level_row {
1.375 raeburn 8995: my ($protectedcourse,$role,$area,$domain,$plrole,$sections_count,
1.402 raeburn 8996: $lt,$showcredits,$defaultcredits,$crstype) = @_;
1.375 raeburn 8997: my $creditem;
1.222 raeburn 8998: my $row = &Apache::loncommon::start_data_table_row().
8999: ' <td><input type="checkbox" name="act_'.
9000: $protectedcourse.'_'.$role.'" /></td>'."\n".
9001: ' <td>'.$plrole.'</td>'."\n".
9002: ' <td>'.$area.'<br />Domain: '.$domain.'</td>'."\n";
1.402 raeburn 9003: if (($showcredits) && ($role eq 'st') && ($crstype eq 'Course')) {
1.375 raeburn 9004: $row .=
9005: '<td><input type="text" name="credits_'.$protectedcourse.'_'.
9006: $role.'" size="3" value="'.$defaultcredits.'" /></td>';
9007: } else {
9008: $row .= '<td> </td>';
9009: }
1.322 raeburn 9010: if (($role eq 'cc') || ($role eq 'co')) {
1.222 raeburn 9011: $row .= '<td> </td>';
1.221 raeburn 9012: } elsif ($env{'request.course.sec'} ne '') {
1.222 raeburn 9013: $row .= ' <td><input type="hidden" value="'.
9014: $env{'request.course.sec'}.'" '.
9015: 'name="sec_'.$protectedcourse.'_'.$role.'" />'.
9016: $env{'request.course.sec'}.'</td>';
1.221 raeburn 9017: } else {
9018: if (ref($sections_count) eq 'HASH') {
9019: my $currsec =
9020: &Apache::lonuserutils::course_sections($sections_count,
9021: $protectedcourse.'_'.$role);
1.222 raeburn 9022: $row .= '<td><table class="LC_createuser">'."\n".
9023: '<tr class="LC_section_row">'."\n".
9024: ' <td valign="top">'.$lt->{'exs'}.'<br />'.
9025: $currsec.'</td>'."\n".
9026: ' <td> </td>'."\n".
9027: ' <td valign="top"> '.$lt->{'new'}.'<br />'.
1.221 raeburn 9028: '<input type="text" name="newsec_'.$protectedcourse.'_'.$role.
9029: '" value="" />'.
9030: '<input type="hidden" '.
9031: 'name="sec_'.$protectedcourse.'_'.$role.'" /></td>'."\n".
1.222 raeburn 9032: '</tr></table></td>'."\n";
1.221 raeburn 9033: } else {
1.222 raeburn 9034: $row .= '<td><input type="text" size="10" '.
1.375 raeburn 9035: 'name="sec_'.$protectedcourse.'_'.$role.'" /></td>'."\n";
1.221 raeburn 9036: }
9037: }
1.222 raeburn 9038: $row .= <<ENDTIMEENTRY;
9039: <td><input type="hidden" name="start_$protectedcourse\_$role" value="" />
1.221 raeburn 9040: <a href=
9041: "javascript:pjump('date_start','Start Date $plrole',document.cu.start_$protectedcourse\_$role.value,'start_$protectedcourse\_$role','cu.pres','dateset')">$lt->{'ssd'}</a></td>
1.222 raeburn 9042: <td><input type="hidden" name="end_$protectedcourse\_$role" value="" />
1.221 raeburn 9043: <a href=
9044: "javascript:pjump('date_end','End Date $plrole',document.cu.end_$protectedcourse\_$role.value,'end_$protectedcourse\_$role','cu.pres','dateset')">$lt->{'sed'}</a></td>
9045: ENDTIMEENTRY
1.222 raeburn 9046: $row .= &Apache::loncommon::end_data_table_row();
9047: return $row;
1.221 raeburn 9048: }
9049:
1.88 raeburn 9050: sub course_level_dc {
1.375 raeburn 9051: my ($dcdom,$showcredits) = @_;
1.190 raeburn 9052: my %customroles=&Apache::lonuserutils::my_custom_roles();
1.213 raeburn 9053: my @roles = &Apache::lonuserutils::roles_by_context('course');
1.88 raeburn 9054: my $hiddenitems = '<input type="hidden" name="dcdomain" value="'.$dcdom.'" />'.
9055: '<input type="hidden" name="origdom" value="'.$dcdom.'" />'.
1.133 raeburn 9056: '<input type="hidden" name="dccourse" value="" />';
1.355 www 9057: my $courseform=&Apache::loncommon::selectcourse_link
1.356 raeburn 9058: ('cu','dccourse','dcdomain','coursedesc',undef,undef,'Select','crstype');
1.375 raeburn 9059: my $credit_elem;
9060: if ($showcredits) {
9061: $credit_elem = 'credits';
9062: }
9063: my $cb_jscript = &Apache::loncommon::coursebrowser_javascript($dcdom,'currsec','cu','role','Course/Community Browser',$credit_elem);
1.88 raeburn 9064: my %lt=&Apache::lonlocal::texthash(
9065: 'rol' => "Role",
1.113 raeburn 9066: 'grs' => "Section",
1.88 raeburn 9067: 'exs' => "Existing sections",
9068: 'new' => "Define new section",
9069: 'sta' => "Start",
9070: 'end' => "End",
9071: 'ssd' => "Set Start Date",
1.355 www 9072: 'sed' => "Set End Date",
1.375 raeburn 9073: 'scc' => "Course/Community",
9074: 'crd' => "Credits",
1.88 raeburn 9075: );
1.323 raeburn 9076: my $header = '<h4>'.&mt('Course/Community Level').'</h4>'.
1.136 raeburn 9077: &Apache::loncommon::start_data_table().
9078: &Apache::loncommon::start_data_table_header_row().
1.375 raeburn 9079: '<th>'.$lt{'scc'}.'</th><th>'.$lt{'rol'}.'</th>'."\n".
1.397 bisitz 9080: '<th>'.$lt{'grs'}.'</th>'."\n";
9081: $header .= '<th>'.$lt{'crd'}.'</th>'."\n" if ($showcredits);
9082: $header .= '<th>'.$lt{'sta'}.'</th><th>'.$lt{'end'}.'</th>'."\n".
1.136 raeburn 9083: &Apache::loncommon::end_data_table_header_row();
1.143 raeburn 9084: my $otheritems = &Apache::loncommon::start_data_table_row()."\n".
1.356 raeburn 9085: '<td><br /><span class="LC_nobreak"><input type="text" name="coursedesc" value="" onfocus="this.blur();opencrsbrowser('."'cu','dccourse','dcdomain','coursedesc','','','','crstype'".')" />'.
9086: $courseform.(' ' x4).'</span></td>'."\n".
1.389 bisitz 9087: '<td valign="top"><br /><select name="role">'."\n";
1.213 raeburn 9088: foreach my $role (@roles) {
1.135 raeburn 9089: my $plrole=&Apache::lonnet::plaintext($role);
1.389 bisitz 9090: $otheritems .= ' <option value="'.$role.'">'.$plrole.'</option>';
1.88 raeburn 9091: }
1.404 raeburn 9092: if ( keys(%customroles) > 0) {
9093: foreach my $cust (sort(keys(%customroles))) {
1.101 albertel 9094: my $custrole='cr_cr_'.$env{'user.domain'}.
1.135 raeburn 9095: '_'.$env{'user.name'}.'_'.$cust;
1.389 bisitz 9096: $otheritems .= ' <option value="'.$custrole.'">'.$cust.'</option>';
1.88 raeburn 9097: }
9098: }
9099: $otheritems .= '</select></td><td>'.
9100: '<table border="0" cellspacing="0" cellpadding="0">'.
9101: '<tr><td valign="top"><b>'.$lt{'exs'}.'</b><br /><select name="currsec">'.
1.389 bisitz 9102: ' <option value=""><--'.&mt('Pick course first').'</option></select></td>'.
1.88 raeburn 9103: '<td> </td>'.
9104: '<td valign="top"> <b>'.$lt{'new'}.'</b><br />'.
1.113 raeburn 9105: '<input type="text" name="newsec" value="" />'.
1.237 raeburn 9106: '<input type="hidden" name="section" value="" />'.
1.323 raeburn 9107: '<input type="hidden" name="groups" value="" />'.
9108: '<input type="hidden" name="crstype" value="" /></td>'.
1.375 raeburn 9109: '</tr></table></td>'."\n";
9110: if ($showcredits) {
9111: $otheritems .= '<td><br />'."\n".
1.397 bisitz 9112: '<input type="text" size="3" name="credits" value="" /></td>'."\n";
1.375 raeburn 9113: }
1.88 raeburn 9114: $otheritems .= <<ENDTIMEENTRY;
1.323 raeburn 9115: <td><br /><input type="hidden" name="start" value='' />
1.88 raeburn 9116: <a href=
9117: "javascript:pjump('date_start','Start Date',document.cu.start.value,'start','cu.pres','dateset')">$lt{'ssd'}</a></td>
1.323 raeburn 9118: <td><br /><input type="hidden" name="end" value='' />
1.88 raeburn 9119: <a href=
9120: "javascript:pjump('date_end','End Date',document.cu.end.value,'end','cu.pres','dateset')">$lt{'sed'}</a></td>
9121: ENDTIMEENTRY
1.136 raeburn 9122: $otheritems .= &Apache::loncommon::end_data_table_row().
9123: &Apache::loncommon::end_data_table()."\n";
1.88 raeburn 9124: return $cb_jscript.$header.$hiddenitems.$otheritems;
9125: }
9126:
1.237 raeburn 9127: sub update_selfenroll_config {
1.400 raeburn 9128: my ($r,$cid,$cdom,$cnum,$context,$crstype,$currsettings) = @_;
1.398 raeburn 9129: return unless (ref($currsettings) eq 'HASH');
9130: my ($row,$lt) = &Apache::lonuserutils::get_selfenroll_titles();
9131: my %curr_groups = &Apache::longroup::coursegroups($cdom,$cnum);
1.237 raeburn 9132: my (%changes,%warning);
1.241 raeburn 9133: my $curr_types;
1.400 raeburn 9134: my %noedit;
9135: unless ($context eq 'domain') {
9136: %noedit = &get_noedit_fields($cdom,$cnum,$crstype,$row);
9137: }
1.237 raeburn 9138: if (ref($row) eq 'ARRAY') {
9139: foreach my $item (@{$row}) {
1.400 raeburn 9140: next if ($noedit{$item});
1.237 raeburn 9141: if ($item eq 'enroll_dates') {
9142: my (%currenrolldate,%newenrolldate);
9143: foreach my $type ('start','end') {
1.398 raeburn 9144: $currenrolldate{$type} = $currsettings->{'selfenroll_'.$type.'_date'};
1.237 raeburn 9145: $newenrolldate{$type} = &Apache::lonhtmlcommon::get_date_from_form('selfenroll_'.$type.'_date');
9146: if ($newenrolldate{$type} ne $currenrolldate{$type}) {
9147: $changes{'internal.selfenroll_'.$type.'_date'} = $newenrolldate{$type};
9148: }
9149: }
9150: } elsif ($item eq 'access_dates') {
9151: my (%currdate,%newdate);
9152: foreach my $type ('start','end') {
1.398 raeburn 9153: $currdate{$type} = $currsettings->{'selfenroll_'.$type.'_access'};
1.237 raeburn 9154: $newdate{$type} = &Apache::lonhtmlcommon::get_date_from_form('selfenroll_'.$type.'_access');
9155: if ($newdate{$type} ne $currdate{$type}) {
9156: $changes{'internal.selfenroll_'.$type.'_access'} = $newdate{$type};
9157: }
9158: }
1.241 raeburn 9159: } elsif ($item eq 'types') {
1.398 raeburn 9160: $curr_types = $currsettings->{'selfenroll_'.$item};
1.241 raeburn 9161: if ($env{'form.selfenroll_all'}) {
9162: if ($curr_types ne '*') {
9163: $changes{'internal.selfenroll_types'} = '*';
9164: } else {
9165: next;
9166: }
9167: } else {
1.249 raeburn 9168: my %currdoms;
1.241 raeburn 9169: my @entries = split(/;/,$curr_types);
9170: my @deletedoms = &Apache::loncommon::get_env_multiple('form.selfenroll_delete');
1.249 raeburn 9171: my @activations = &Apache::loncommon::get_env_multiple('form.selfenroll_activate');
1.241 raeburn 9172: my $newnum = 0;
1.249 raeburn 9173: my @latesttypes;
9174: foreach my $num (@activations) {
9175: my @types = &Apache::loncommon::get_env_multiple('form.selfenroll_types_'.$num);
9176: if (@types > 0) {
1.241 raeburn 9177: @types = sort(@types);
9178: my $typestr = join(',',@types);
1.249 raeburn 9179: my $typedom = $env{'form.selfenroll_dom_'.$num};
9180: $latesttypes[$newnum] = $typedom.':'.$typestr;
9181: $currdoms{$typedom} = 1;
1.241 raeburn 9182: $newnum ++;
9183: }
9184: }
1.338 raeburn 9185: for (my $j=0; $j<$env{'form.selfenroll_types_total'}; $j++) {
9186: if ((!grep(/^$j$/,@deletedoms)) && (!grep(/^$j$/,@activations))) {
1.249 raeburn 9187: my @types = &Apache::loncommon::get_env_multiple('form.selfenroll_types_'.$j);
9188: if (@types > 0) {
9189: @types = sort(@types);
9190: my $typestr = join(',',@types);
9191: my $typedom = $env{'form.selfenroll_dom_'.$j};
9192: $latesttypes[$newnum] = $typedom.':'.$typestr;
9193: $currdoms{$typedom} = 1;
9194: $newnum ++;
9195: }
9196: }
9197: }
9198: if ($env{'form.selfenroll_newdom'} ne '') {
9199: my $typedom = $env{'form.selfenroll_newdom'};
9200: if ((!defined($currdoms{$typedom})) &&
9201: (&Apache::lonnet::domain($typedom) ne '')) {
9202: my $typestr;
9203: my ($othertitle,$usertypes,$types) =
9204: &Apache::loncommon::sorted_inst_types($typedom);
9205: my $othervalue = 'any';
9206: if ((ref($types) eq 'ARRAY') && (ref($usertypes) eq 'HASH')) {
9207: if (@{$types} > 0) {
1.257 raeburn 9208: my @esc_types = map { &escape($_); } @{$types};
1.249 raeburn 9209: $othervalue = 'other';
1.258 raeburn 9210: $typestr = join(',',(@esc_types,$othervalue));
1.249 raeburn 9211: }
9212: $typestr = $othervalue;
9213: } else {
9214: $typestr = $othervalue;
9215: }
9216: $latesttypes[$newnum] = $typedom.':'.$typestr;
9217: $newnum ++ ;
9218: }
9219: }
1.241 raeburn 9220: my $selfenroll_types = join(';',@latesttypes);
9221: if ($selfenroll_types ne $curr_types) {
9222: $changes{'internal.selfenroll_types'} = $selfenroll_types;
9223: }
9224: }
1.276 raeburn 9225: } elsif ($item eq 'limit') {
9226: my $newlimit = $env{'form.selfenroll_limit'};
9227: my $newcap = $env{'form.selfenroll_cap'};
9228: $newcap =~s/\s+//g;
1.398 raeburn 9229: my $currlimit = $currsettings->{'selfenroll_limit'};
1.276 raeburn 9230: $currlimit = 'none' if ($currlimit eq '');
1.398 raeburn 9231: my $currcap = $currsettings->{'selfenroll_cap'};
1.276 raeburn 9232: if ($newlimit ne $currlimit) {
9233: if ($newlimit ne 'none') {
9234: if ($newcap =~ /^\d+$/) {
9235: if ($newcap ne $currcap) {
9236: $changes{'internal.selfenroll_cap'} = $newcap;
9237: }
9238: $changes{'internal.selfenroll_limit'} = $newlimit;
9239: } else {
1.398 raeburn 9240: $warning{$item} = &mt('Maximum enrollment setting unchanged.').'<br />'.
9241: &mt('The value provided was invalid - it must be a positive integer if enrollment is being limited.');
1.276 raeburn 9242: }
9243: } elsif ($currcap ne '') {
9244: $changes{'internal.selfenroll_cap'} = '';
9245: $changes{'internal.selfenroll_limit'} = $newlimit;
9246: }
9247: } elsif ($currlimit ne 'none') {
9248: if ($newcap =~ /^\d+$/) {
9249: if ($newcap ne $currcap) {
9250: $changes{'internal.selfenroll_cap'} = $newcap;
9251: }
9252: } else {
1.398 raeburn 9253: $warning{$item} = &mt('Maximum enrollment setting unchanged.').'<br />'.
9254: &mt('The value provided was invalid - it must be a positive integer if enrollment is being limited.');
1.276 raeburn 9255: }
9256: }
9257: } elsif ($item eq 'approval') {
9258: my (@currnotified,@newnotified);
1.398 raeburn 9259: my $currapproval = $currsettings->{'selfenroll_approval'};
9260: my $currnotifylist = $currsettings->{'selfenroll_notifylist'};
1.276 raeburn 9261: if ($currnotifylist ne '') {
9262: @currnotified = split(/,/,$currnotifylist);
9263: @currnotified = sort(@currnotified);
9264: }
9265: my $newapproval = $env{'form.selfenroll_approval'};
9266: @newnotified = &Apache::loncommon::get_env_multiple('form.selfenroll_notify');
9267: @newnotified = sort(@newnotified);
9268: if ($newapproval ne $currapproval) {
9269: $changes{'internal.selfenroll_approval'} = $newapproval;
9270: if (!$newapproval) {
9271: if ($currnotifylist ne '') {
9272: $changes{'internal.selfenroll_notifylist'} = '';
9273: }
9274: } else {
9275: my @differences =
1.295 raeburn 9276: &Apache::loncommon::compare_arrays(\@currnotified,\@newnotified);
1.276 raeburn 9277: if (@differences > 0) {
9278: if (@newnotified > 0) {
9279: $changes{'internal.selfenroll_notifylist'} = join(',',@newnotified);
9280: } else {
9281: $changes{'internal.selfenroll_notifylist'} = join(',',@newnotified);
9282: }
9283: }
9284: }
9285: } else {
1.295 raeburn 9286: my @differences = &Apache::loncommon::compare_arrays(\@currnotified,\@newnotified);
1.276 raeburn 9287: if (@differences > 0) {
9288: if (@newnotified > 0) {
9289: $changes{'internal.selfenroll_notifylist'} = join(',',@newnotified);
9290: } else {
9291: $changes{'internal.selfenroll_notifylist'} = '';
9292: }
9293: }
9294: }
1.237 raeburn 9295: } else {
1.398 raeburn 9296: my $curr_val = $currsettings->{'selfenroll_'.$item};
1.237 raeburn 9297: my $newval = $env{'form.selfenroll_'.$item};
9298: if ($item eq 'section') {
9299: $newval = $env{'form.sections'};
1.241 raeburn 9300: if (defined($curr_groups{$newval})) {
1.237 raeburn 9301: $newval = $curr_val;
1.398 raeburn 9302: $warning{$item} = &mt('Section for self-enrolled users unchanged as the proposed section is a group').'<br />'.
9303: &mt('Group names and section names must be distinct');
1.237 raeburn 9304: } elsif ($newval eq 'all') {
9305: $newval = $curr_val;
1.274 bisitz 9306: $warning{$item} = &mt('Section for self-enrolled users unchanged, as "all" is a reserved section name.');
1.237 raeburn 9307: }
9308: if ($newval eq '') {
9309: $newval = 'none';
9310: }
9311: }
9312: if ($newval ne $curr_val) {
9313: $changes{'internal.selfenroll_'.$item} = $newval;
9314: }
1.241 raeburn 9315: }
1.237 raeburn 9316: }
9317: if (keys(%warning) > 0) {
9318: foreach my $item (@{$row}) {
9319: if (exists($warning{$item})) {
9320: $r->print($warning{$item}.'<br />');
9321: }
9322: }
9323: }
9324: if (keys(%changes) > 0) {
9325: my $putresult = &Apache::lonnet::put('environment',\%changes,$cdom,$cnum);
9326: if ($putresult eq 'ok') {
9327: if ((exists($changes{'internal.selfenroll_types'})) ||
9328: (exists($changes{'internal.selfenroll_start_date'})) ||
9329: (exists($changes{'internal.selfenroll_end_date'}))) {
9330: my %crsinfo = &Apache::lonnet::courseiddump($cdom,'.',1,'.','.',
9331: $cnum,undef,undef,'Course');
9332: my $chome = &Apache::lonnet::homeserver($cnum,$cdom);
1.398 raeburn 9333: if (ref($crsinfo{$cid}) eq 'HASH') {
1.237 raeburn 9334: foreach my $item ('selfenroll_types','selfenroll_start_date','selfenroll_end_date') {
9335: if (exists($changes{'internal.'.$item})) {
1.398 raeburn 9336: $crsinfo{$cid}{$item} = $changes{'internal.'.$item};
1.237 raeburn 9337: }
9338: }
9339: my $crsputresult =
9340: &Apache::lonnet::courseidput($cdom,\%crsinfo,
9341: $chome,'notime');
9342: }
9343: }
9344: $r->print(&mt('The following changes were made to self-enrollment settings:').'<ul>');
9345: foreach my $item (@{$row}) {
9346: my $title = $item;
9347: if (ref($lt) eq 'HASH') {
9348: $title = $lt->{$item};
9349: }
9350: if ($item eq 'enroll_dates') {
9351: foreach my $type ('start','end') {
9352: if (exists($changes{'internal.selfenroll_'.$type.'_date'})) {
9353: my $newdate = &Apache::lonlocal::locallocaltime($changes{'internal.selfenroll_'.$type.'_date'});
1.244 bisitz 9354: $r->print('<li>'.&mt('[_1]: "[_2]" set to "[_3]".',
1.237 raeburn 9355: $title,$type,$newdate).'</li>');
9356: }
9357: }
9358: } elsif ($item eq 'access_dates') {
9359: foreach my $type ('start','end') {
9360: if (exists($changes{'internal.selfenroll_'.$type.'_access'})) {
9361: my $newdate = &Apache::lonlocal::locallocaltime($changes{'internal.selfenroll_'.$type.'_access'});
1.244 bisitz 9362: $r->print('<li>'.&mt('[_1]: "[_2]" set to "[_3]".',
1.237 raeburn 9363: $title,$type,$newdate).'</li>');
9364: }
9365: }
1.276 raeburn 9366: } elsif ($item eq 'limit') {
9367: if ((exists($changes{'internal.selfenroll_limit'})) ||
9368: (exists($changes{'internal.selfenroll_cap'}))) {
9369: my ($newval,$newcap);
9370: if ($changes{'internal.selfenroll_cap'} ne '') {
9371: $newcap = $changes{'internal.selfenroll_cap'}
9372: } else {
1.398 raeburn 9373: $newcap = $currsettings->{'selfenroll_cap'};
1.276 raeburn 9374: }
9375: if ($changes{'internal.selfenroll_limit'} eq 'none') {
9376: $newval = &mt('No limit');
9377: } elsif ($changes{'internal.selfenroll_limit'} eq
9378: 'allstudents') {
9379: $newval = &mt('New self-enrollment no longer allowed when total (all students) reaches [_1].',$newcap);
9380: } elsif ($changes{'internal.selfenroll_limit'} eq 'selfenrolled') {
9381: $newval = &mt('New self-enrollment no longer allowed when total number of self-enrolled students reaches [_1].',$newcap);
9382: } else {
1.398 raeburn 9383: my $currlimit = $currsettings->{'selfenroll_limit'};
1.276 raeburn 9384: if ($currlimit eq 'allstudents') {
9385: $newval = &mt('New self-enrollment no longer allowed when total (all students) reaches [_1].',$newcap);
9386: } elsif ($changes{'internal.selfenroll_limit'} eq 'selfenrolled') {
1.308 raeburn 9387: $newval = &mt('New self-enrollment no longer allowed when total number of self-enrolled students reaches [_1].',$newcap);
1.276 raeburn 9388: }
9389: }
9390: $r->print('<li>'.&mt('"[_1]" set to "[_2]".',$title,$newval).'</li>'."\n");
9391: }
9392: } elsif ($item eq 'approval') {
9393: if ((exists($changes{'internal.selfenroll_approval'})) ||
9394: (exists($changes{'internal.selfenroll_notifylist'}))) {
1.398 raeburn 9395: my %selfdescs = &Apache::lonuserutils::selfenroll_default_descs();
1.276 raeburn 9396: my ($newval,$newnotify);
9397: if (exists($changes{'internal.selfenroll_notifylist'})) {
9398: $newnotify = $changes{'internal.selfenroll_notifylist'};
9399: } else {
1.398 raeburn 9400: $newnotify = $currsettings->{'selfenroll_notifylist'};
1.276 raeburn 9401: }
1.398 raeburn 9402: if (exists($changes{'internal.selfenroll_approval'})) {
9403: if ($changes{'internal.selfenroll_approval'} !~ /^[012]$/) {
9404: $changes{'internal.selfenroll_approval'} = '0';
9405: }
9406: $newval = $selfdescs{'approval'}{$changes{'internal.selfenroll_approval'}};
1.276 raeburn 9407: } else {
1.398 raeburn 9408: my $currapproval = $currsettings->{'selfenroll_approval'};
9409: if ($currapproval !~ /^[012]$/) {
9410: $currapproval = 0;
1.276 raeburn 9411: }
1.398 raeburn 9412: $newval = $selfdescs{'approval'}{$currapproval};
1.276 raeburn 9413: }
9414: $r->print('<li>'.&mt('"[_1]" set to "[_2]".',$title,$newval));
9415: if ($newnotify) {
1.277 raeburn 9416: $r->print('<br />'.&mt('The following will be notified when an enrollment request needs approval, or has been approved: [_1].',$newnotify));
1.276 raeburn 9417: } else {
1.277 raeburn 9418: $r->print('<br />'.&mt('No notifications sent when an enrollment request needs approval, or has been approved.'));
1.276 raeburn 9419: }
9420: $r->print('</li>'."\n");
9421: }
1.237 raeburn 9422: } else {
9423: if (exists($changes{'internal.selfenroll_'.$item})) {
1.241 raeburn 9424: my $newval = $changes{'internal.selfenroll_'.$item};
9425: if ($item eq 'types') {
9426: if ($newval eq '') {
9427: $newval = &mt('None');
9428: } elsif ($newval eq '*') {
9429: $newval = &mt('Any user in any domain');
9430: }
1.245 raeburn 9431: } elsif ($item eq 'registered') {
9432: if ($newval eq '1') {
9433: $newval = &mt('Yes');
9434: } elsif ($newval eq '0') {
9435: $newval = &mt('No');
9436: }
1.241 raeburn 9437: }
1.244 bisitz 9438: $r->print('<li>'.&mt('"[_1]" set to "[_2]".',$title,$newval).'</li>'."\n");
1.237 raeburn 9439: }
9440: }
9441: }
9442: $r->print('</ul>');
1.398 raeburn 9443: if ($env{'course.'.$cid.'.description'} ne '') {
9444: my %newenvhash;
9445: foreach my $key (keys(%changes)) {
9446: $newenvhash{'course.'.$cid.'.'.$key} = $changes{$key};
9447: }
9448: &Apache::lonnet::appenv(\%newenvhash);
1.237 raeburn 9449: }
9450: } else {
1.398 raeburn 9451: $r->print(&mt('An error occurred when saving changes to self-enrollment settings in this course.').'<br />'.
9452: &mt('The error was: [_1].',$putresult));
1.237 raeburn 9453: }
9454: } else {
1.249 raeburn 9455: $r->print(&mt('No changes were made to the existing self-enrollment settings in this course.'));
1.237 raeburn 9456: }
9457: } else {
1.249 raeburn 9458: $r->print(&mt('No changes were made to the existing self-enrollment settings in this course.'));
1.241 raeburn 9459: }
1.400 raeburn 9460: my $visactions = &cat_visibility();
9461: my ($cathash,%cattype);
9462: my %domconfig = &Apache::lonnet::get_dom('configuration',['coursecategories'],$cdom);
9463: if (ref($domconfig{'coursecategories'}) eq 'HASH') {
9464: $cathash = $domconfig{'coursecategories'}{'cats'};
9465: $cattype{'auth'} = $domconfig{'coursecategories'}{'auth'};
9466: $cattype{'unauth'} = $domconfig{'coursecategories'}{'unauth'};
9467: } else {
9468: $cathash = {};
9469: $cattype{'auth'} = 'std';
9470: $cattype{'unauth'} = 'std';
9471: }
9472: if (($cattype{'auth'} eq 'none') && ($cattype{'unauth'} eq 'none')) {
9473: $r->print('<br /><span class="LC_warning">'.$visactions->{'miss'}.'</span><br />'.$visactions->{'yous'}.
9474: '<br />'.
9475: '<br />'.$visactions->{'take'}.'<ul>'.
9476: '<li>'.$visactions->{'dc_chgconf'}.'</li>'.
9477: '</ul>');
9478: } elsif (($cattype{'auth'} !~ /^(std|domonly)$/) && ($cattype{'unauth'} !~ /^(std|domonly)$/)) {
9479: if ($currsettings->{'uniquecode'}) {
9480: $r->print('<span class="LC_info">'.$visactions->{'vis'}.'</span>');
9481: } else {
1.366 bisitz 9482: $r->print('<br /><span class="LC_warning">'.$visactions->{'miss'}.'</span><br />'.$visactions->{'yous'}.
1.400 raeburn 9483: '<br />'.
9484: '<br />'.$visactions->{'take'}.'<ul>'.
9485: '<li>'.$visactions->{'dc_setcode'}.'</li>'.
9486: '</ul><br />');
9487: }
9488: } else {
9489: my ($visible,$cansetvis,$vismsgs) = &visible_in_stdcat($cdom,$cnum,\%domconfig);
9490: if (ref($visactions) eq 'HASH') {
9491: if (!$visible) {
9492: $r->print('<br /><span class="LC_warning">'.$visactions->{'miss'}.'</span><br />'.$visactions->{'yous'}.
9493: '<br />');
9494: if (ref($vismsgs) eq 'ARRAY') {
9495: $r->print('<br />'.$visactions->{'take'}.'<ul>');
9496: foreach my $item (@{$vismsgs}) {
9497: $r->print('<li>'.$visactions->{$item}.'</li>');
9498: }
9499: $r->print('</ul>');
1.256 raeburn 9500: }
1.400 raeburn 9501: $r->print($cansetvis);
1.256 raeburn 9502: }
9503: }
9504: }
1.237 raeburn 9505: return;
9506: }
9507:
1.27 matthew 9508: #---------------------------------------------- end functions for &phase_two
1.29 matthew 9509:
9510: #--------------------------------- functions for &phase_two and &phase_three
9511:
9512: #--------------------------end of functions for &phase_two and &phase_three
1.372 raeburn 9513:
1.1 www 9514: 1;
9515: __END__
1.2 www 9516:
9517:
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>