Annotation of loncom/interface/loncreateuser.pm, revision 1.462
1.20 harris41 1: # The LearningOnline Network with CAPA
1.1 www 2: # Create a user
3: #
1.462 ! raeburn 4: # $Id: loncreateuser.pm,v 1.461 2022/11/10 14:08:37 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.456 raeburn 74: use HTML::Entities;
1.1 www 75:
1.20 harris41 76: my $loginscript; # piece of javascript used in two separate instances
77: my $authformnop;
78: my $authformkrb;
79: my $authformint;
80: my $authformfsys;
81: my $authformloc;
1.449 raeburn 82: my $authformlti;
1.20 harris41 83:
1.94 matthew 84: sub initialize_authen_forms {
1.227 raeburn 85: my ($dom,$formname,$curr_authtype,$mode) = @_;
86: my ($krbdef,$krbdefdom) = &Apache::loncommon::get_kerberos_defaults($dom);
87: my %param = ( formname => $formname,
1.187 raeburn 88: kerb_def_dom => $krbdefdom,
1.227 raeburn 89: kerb_def_auth => $krbdef,
1.187 raeburn 90: domain => $dom,
91: );
1.188 raeburn 92: my %abv_auth = &auth_abbrev();
1.449 raeburn 93: if ($curr_authtype =~ /^(krb4|krb5|internal|localauth|unix|lti):(.*)$/) {
1.188 raeburn 94: my $long_auth = $1;
1.227 raeburn 95: my $curr_autharg = $2;
1.188 raeburn 96: my %abv_auth = &auth_abbrev();
97: $param{'curr_authtype'} = $abv_auth{$long_auth};
98: if ($long_auth =~ /^krb(4|5)$/) {
99: $param{'curr_kerb_ver'} = $1;
1.227 raeburn 100: $param{'curr_autharg'} = $curr_autharg;
1.188 raeburn 101: }
1.205 raeburn 102: if ($mode eq 'modifyuser') {
103: $param{'mode'} = $mode;
104: }
1.187 raeburn 105: }
1.227 raeburn 106: $loginscript = &Apache::loncommon::authform_header(%param);
107: $authformkrb = &Apache::loncommon::authform_kerberos(%param);
1.31 matthew 108: $authformnop = &Apache::loncommon::authform_nochange(%param);
109: $authformint = &Apache::loncommon::authform_internal(%param);
110: $authformfsys = &Apache::loncommon::authform_filesystem(%param);
111: $authformloc = &Apache::loncommon::authform_local(%param);
1.449 raeburn 112: $authformlti = &Apache::loncommon::authform_lti(%param);
1.20 harris41 113: }
114:
1.188 raeburn 115: sub auth_abbrev {
116: my %abv_auth = (
1.368 raeburn 117: krb5 => 'krb',
118: krb4 => 'krb',
119: internal => 'int',
120: localauth => 'loc',
121: unix => 'fsys',
1.449 raeburn 122: lti => 'lti',
1.188 raeburn 123: );
124: return %abv_auth;
125: }
1.43 www 126:
1.134 raeburn 127: # ====================================================
128:
1.378 raeburn 129: sub user_quotas {
1.134 raeburn 130: my ($ccuname,$ccdomain) = @_;
131: my %lt = &Apache::lonlocal::texthash(
1.267 raeburn 132: 'usrt' => "User Tools",
133: 'cust' => "Custom quota",
134: 'chqu' => "Change quota",
1.134 raeburn 135: );
1.378 raeburn 136:
1.149 raeburn 137: my $quota_javascript = <<"END_SCRIPT";
138: <script type="text/javascript">
1.301 bisitz 139: // <![CDATA[
1.378 raeburn 140: function quota_changes(caller,context) {
141: var customoff = document.getElementById('custom_'+context+'quota_off');
142: var customon = document.getElementById('custom_'+context+'quota_on');
143: var number = document.getElementById(context+'quota');
1.149 raeburn 144: if (caller == "custom") {
1.378 raeburn 145: if (customoff) {
146: if (customoff.checked) {
147: number.value = "";
148: }
1.149 raeburn 149: }
150: }
151: if (caller == "quota") {
1.378 raeburn 152: if (customon) {
153: customon.checked = true;
154: }
1.149 raeburn 155: }
1.378 raeburn 156: return;
1.149 raeburn 157: }
1.301 bisitz 158: // ]]>
1.149 raeburn 159: </script>
160: END_SCRIPT
1.378 raeburn 161: my $longinsttype;
162: my ($usertypes,$order) = &Apache::lonnet::retrieve_inst_usertypes($ccdomain);
1.267 raeburn 163: my $output = $quota_javascript."\n".
164: '<h3>'.$lt{'usrt'}.'</h3>'."\n".
165: &Apache::loncommon::start_data_table();
166:
1.418 raeburn 167: if ((&Apache::lonnet::allowed('mut',$ccdomain)) ||
168: (&Apache::lonnet::allowed('udp',$ccdomain))) {
1.275 raeburn 169: $output .= &build_tools_display($ccuname,$ccdomain,'tools');
1.267 raeburn 170: }
1.378 raeburn 171:
172: my %titles = &Apache::lonlocal::texthash (
173: portfolio => "Disk space allocated to user's portfolio files",
1.385 bisitz 174: author => "Disk space allocated to user's Authoring Space (if role assigned)",
1.378 raeburn 175: );
176: foreach my $name ('portfolio','author') {
177: my ($currquota,$quotatype,$inststatus,$defquota) =
178: &Apache::loncommon::get_user_quota($ccuname,$ccdomain,$name);
179: if ($longinsttype eq '') {
180: if ($inststatus ne '') {
181: if ($usertypes->{$inststatus} ne '') {
182: $longinsttype = $usertypes->{$inststatus};
183: }
184: }
185: }
186: my ($showquota,$custom_on,$custom_off,$defaultinfo);
187: $custom_on = ' ';
188: $custom_off = ' checked="checked" ';
189: if ($quotatype eq 'custom') {
190: $custom_on = $custom_off;
191: $custom_off = ' ';
192: $showquota = $currquota;
193: if ($longinsttype eq '') {
194: $defaultinfo = &mt('For this user, the default quota would be [_1]'
1.383 raeburn 195: .' MB.',$defquota);
1.378 raeburn 196: } else {
197: $defaultinfo = &mt("For this user, the default quota would be [_1]".
1.383 raeburn 198: " MB, as determined by the user's institutional".
1.378 raeburn 199: " affiliation ([_2]).",$defquota,$longinsttype);
200: }
201: } else {
202: if ($longinsttype eq '') {
203: $defaultinfo = &mt('For this user, the default quota is [_1]'
1.383 raeburn 204: .' MB.',$defquota);
1.378 raeburn 205: } else {
206: $defaultinfo = &mt("For this user, the default quota of [_1]".
1.383 raeburn 207: " MB, is determined by the user's institutional".
1.378 raeburn 208: " affiliation ([_2]).",$defquota,$longinsttype);
209: }
210: }
211:
212: if (&Apache::lonnet::allowed('mpq',$ccdomain)) {
213: $output .= '<tr class="LC_info_row">'."\n".
214: ' <td>'.$titles{$name}.'</td>'."\n".
215: ' </tr>'."\n".
216: &Apache::loncommon::start_data_table_row()."\n".
1.390 bisitz 217: ' <td><span class="LC_nobreak">'.
218: &mt('Current quota: [_1] MB',$currquota).'</span> '.
1.378 raeburn 219: $defaultinfo.'</td>'."\n".
220: &Apache::loncommon::end_data_table_row()."\n".
221: &Apache::loncommon::start_data_table_row()."\n".
222: ' <td><span class="LC_nobreak">'.$lt{'chqu'}.
223: ': <label>'.
224: '<input type="radio" name="custom_'.$name.'quota" id="custom_'.$name.'quota_off" '.
1.379 raeburn 225: 'value="0" '.$custom_off.' onchange="javascript:quota_changes('."'custom','$name'".');"'.
1.390 bisitz 226: ' /><span class="LC_nobreak">'.
227: &mt('Default ([_1] MB)',$defquota).'</span></label> '.
1.378 raeburn 228: ' <label><input type="radio" name="custom_'.$name.'quota" id="custom_'.$name.'quota_on" '.
1.379 raeburn 229: 'value="1" '.$custom_on.' onchange="javascript:quota_changes('."'custom','$name'".');"'.
1.378 raeburn 230: ' />'.$lt{'cust'}.':</label> '.
1.379 raeburn 231: '<input type="text" name="'.$name.'quota" id="'.$name.'quota" size ="5" '.
232: 'value="'.$showquota.'" onfocus="javascript:quota_changes('."'quota','$name'".');"'.
1.390 bisitz 233: ' /> '.&mt('MB').'</span></td>'."\n".
1.378 raeburn 234: &Apache::loncommon::end_data_table_row()."\n";
235: }
236: }
1.267 raeburn 237: $output .= &Apache::loncommon::end_data_table();
1.134 raeburn 238: return $output;
239: }
240:
1.275 raeburn 241: sub build_tools_display {
242: my ($ccuname,$ccdomain,$context) = @_;
1.306 raeburn 243: my (@usertools,%userenv,$output,@options,%validations,%reqtitles,%reqdisplay,
1.332 raeburn 244: $colspan,$isadv,%domconfig);
1.275 raeburn 245: my %lt = &Apache::lonlocal::texthash (
246: 'blog' => "Personal User Blog",
247: 'aboutme' => "Personal Information Page",
1.385 bisitz 248: 'webdav' => "WebDAV access to Authoring Spaces (if SSL and author/co-author)",
1.275 raeburn 249: 'portfolio' => "Personal User Portfolio",
1.459 raeburn 250: 'timezone' => "Can set Time Zone",
1.275 raeburn 251: 'avai' => "Available",
252: 'cusa' => "availability",
253: 'chse' => "Change setting",
254: 'usde' => "Use default",
255: 'uscu' => "Use custom",
256: 'official' => 'Can request creation of official courses',
1.299 raeburn 257: 'unofficial' => 'Can request creation of unofficial courses',
258: 'community' => 'Can request creation of communities',
1.384 raeburn 259: 'textbook' => 'Can request creation of textbook courses',
1.411 raeburn 260: 'placement' => 'Can request creation of placement tests',
1.449 raeburn 261: 'lti' => 'Can request creation of LTI courses',
1.362 raeburn 262: 'requestauthor' => 'Can request author space',
1.275 raeburn 263: );
1.462 ! raeburn 264: $isadv = &Apache::lonnet::is_advanced_user($ccdomain,$ccuname);
1.279 raeburn 265: if ($context eq 'requestcourses') {
1.275 raeburn 266: %userenv = &Apache::lonnet::userenvironment($ccdomain,$ccuname,
1.299 raeburn 267: 'requestcourses.official','requestcourses.unofficial',
1.411 raeburn 268: 'requestcourses.community','requestcourses.textbook',
1.449 raeburn 269: 'requestcourses.placement','requestcourses.lti');
270: @usertools = ('official','unofficial','community','textbook','placement','lti');
1.309 raeburn 271: @options =('norequest','approval','autolimit','validate');
1.306 raeburn 272: %validations = &Apache::lonnet::auto_courserequest_checks($ccdomain);
273: %reqtitles = &courserequest_titles();
274: %reqdisplay = &courserequest_display();
275: $colspan = ' colspan="2"';
1.332 raeburn 276: %domconfig =
277: &Apache::lonnet::get_dom('configuration',['requestcourses'],$ccdomain);
1.362 raeburn 278: } elsif ($context eq 'requestauthor') {
279: %userenv = &Apache::lonnet::userenvironment($ccdomain,$ccuname,
280: 'requestauthor');
281: @usertools = ('requestauthor');
282: @options =('norequest','approval','automatic');
283: %reqtitles = &requestauthor_titles();
284: %reqdisplay = &requestauthor_display();
285: $colspan = ' colspan="2"';
286: %domconfig =
287: &Apache::lonnet::get_dom('configuration',['requestauthor'],$ccdomain);
1.275 raeburn 288: } else {
289: %userenv = &Apache::lonnet::userenvironment($ccdomain,$ccuname,
1.361 raeburn 290: 'tools.aboutme','tools.portfolio','tools.blog',
1.459 raeburn 291: 'tools.webdav','tools.timezone');
292: @usertools = ('aboutme','blog','webdav','portfolio','timezone');
1.275 raeburn 293: }
294: foreach my $item (@usertools) {
1.306 raeburn 295: my ($custom_access,$curr_access,$cust_on,$cust_off,$tool_on,$tool_off,
296: $currdisp,$custdisp,$custradio);
1.275 raeburn 297: $cust_off = 'checked="checked" ';
298: $tool_on = 'checked="checked" ';
299: $curr_access =
300: &Apache::lonnet::usertools_access($ccuname,$ccdomain,$item,undef,
1.462 ! raeburn 301: $context,\%userenv,'',
! 302: {'is_adv' => $isadv});
1.362 raeburn 303: if ($context eq 'requestauthor') {
304: if ($userenv{$context} ne '') {
305: $cust_on = ' checked="checked" ';
306: $cust_off = '';
307: }
308: } elsif ($userenv{$context.'.'.$item} ne '') {
1.306 raeburn 309: $cust_on = ' checked="checked" ';
310: $cust_off = '';
311: }
312: if ($context eq 'requestcourses') {
313: if ($userenv{$context.'.'.$item} eq '') {
1.314 raeburn 314: $custom_access = &mt('Currently from default setting.');
1.306 raeburn 315: } else {
316: $custom_access = &mt('Currently from custom setting.');
1.275 raeburn 317: }
1.362 raeburn 318: } elsif ($context eq 'requestauthor') {
319: if ($userenv{$context} eq '') {
320: $custom_access = &mt('Currently from default setting.');
321: } else {
322: $custom_access = &mt('Currently from custom setting.');
323: }
1.275 raeburn 324: } else {
1.306 raeburn 325: if ($userenv{$context.'.'.$item} eq '') {
1.314 raeburn 326: $custom_access =
1.306 raeburn 327: &mt('Availability determined currently from default setting.');
328: if (!$curr_access) {
329: $tool_off = 'checked="checked" ';
330: $tool_on = '';
331: }
332: } else {
1.314 raeburn 333: $custom_access =
1.306 raeburn 334: &mt('Availability determined currently from custom setting.');
335: if ($userenv{$context.'.'.$item} == 0) {
336: $tool_off = 'checked="checked" ';
337: $tool_on = '';
338: }
1.275 raeburn 339: }
340: }
341: $output .= ' <tr class="LC_info_row">'."\n".
1.306 raeburn 342: ' <td'.$colspan.'>'.$lt{$item}.'</td>'."\n".
1.275 raeburn 343: ' </tr>'."\n".
1.306 raeburn 344: &Apache::loncommon::start_data_table_row()."\n";
1.418 raeburn 345:
1.362 raeburn 346: if (($context eq 'requestcourses') || ($context eq 'requestauthor')) {
1.306 raeburn 347: my ($curroption,$currlimit);
1.362 raeburn 348: my $envkey = $context.'.'.$item;
349: if ($context eq 'requestauthor') {
350: $envkey = $context;
351: }
352: if ($userenv{$envkey} ne '') {
353: $curroption = $userenv{$envkey};
1.332 raeburn 354: } else {
355: my (@inststatuses);
1.362 raeburn 356: if ($context eq 'requestcourses') {
357: $curroption =
358: &Apache::loncoursequeueadmin::get_processtype('course',$ccuname,$ccdomain,
359: $isadv,$ccdomain,$item,
360: \@inststatuses,\%domconfig);
361: } else {
362: $curroption =
363: &Apache::loncoursequeueadmin::get_processtype('requestauthor',$ccuname,$ccdomain,
364: $isadv,$ccdomain,undef,
365: \@inststatuses,\%domconfig);
366: }
1.332 raeburn 367: }
1.306 raeburn 368: if (!$curroption) {
369: $curroption = 'norequest';
370: }
371: if ($curroption =~ /^autolimit=(\d*)$/) {
372: $currlimit = $1;
1.314 raeburn 373: if ($currlimit eq '') {
374: $currdisp = &mt('Yes, automatic creation');
375: } else {
376: $currdisp = &mt('Yes, up to [quant,_1,request]/user',$currlimit);
377: }
1.306 raeburn 378: } else {
379: $currdisp = $reqdisplay{$curroption};
380: }
381: $custdisp = '<table>';
382: foreach my $option (@options) {
383: my $val = $option;
384: if ($option eq 'norequest') {
385: $val = 0;
386: }
387: if ($option eq 'validate') {
388: my $canvalidate = 0;
389: if (ref($validations{$item}) eq 'HASH') {
390: if ($validations{$item}{'_custom_'}) {
391: $canvalidate = 1;
392: }
393: }
394: next if (!$canvalidate);
395: }
396: my $checked = '';
397: if ($option eq $curroption) {
398: $checked = ' checked="checked"';
399: } elsif ($option eq 'autolimit') {
400: if ($curroption =~ /^autolimit/) {
401: $checked = ' checked="checked"';
402: }
403: }
1.362 raeburn 404: my $name = 'crsreq_'.$item;
405: if ($context eq 'requestauthor') {
406: $name = $item;
407: }
1.306 raeburn 408: $custdisp .= '<tr><td><span class="LC_nobreak"><label>'.
1.362 raeburn 409: '<input type="radio" name="'.$name.'" '.
410: 'value="'.$val.'"'.$checked.' />'.
1.306 raeburn 411: $reqtitles{$option}.'</label> ';
412: if ($option eq 'autolimit') {
1.362 raeburn 413: $custdisp .= '<input type="text" name="'.$name.
414: '_limit" size="1" '.
1.314 raeburn 415: 'value="'.$currlimit.'" /></span><br />'.
416: $reqtitles{'unlimited'};
1.362 raeburn 417: } else {
418: $custdisp .= '</span>';
419: }
420: $custdisp .= '</td></tr>';
1.306 raeburn 421: }
422: $custdisp .= '</table>';
423: $custradio = '</span></td><td>'.&mt('Custom setting').'<br />'.$custdisp;
424: } else {
425: $currdisp = ($curr_access?&mt('Yes'):&mt('No'));
1.362 raeburn 426: my $name = $context.'_'.$item;
427: if ($context eq 'requestauthor') {
428: $name = $context;
429: }
1.306 raeburn 430: $custdisp = '<span class="LC_nobreak"><label>'.
1.362 raeburn 431: '<input type="radio" name="'.$name.'"'.
1.361 raeburn 432: ' value="1" '.$tool_on.'/>'.&mt('On').'</label> <label>'.
1.362 raeburn 433: '<input type="radio" name="'.$name.'" value="0" '.
1.306 raeburn 434: $tool_off.'/>'.&mt('Off').'</label></span>';
435: $custradio = (' 'x2).'--'.$lt{'cusa'}.': '.$custdisp.
436: '</span>';
437: }
438: $output .= ' <td'.$colspan.'>'.$custom_access.(' 'x4).
1.419 raeburn 439: $lt{'avai'}.': '.$currdisp.'</td>'."\n".
1.418 raeburn 440: &Apache::loncommon::end_data_table_row()."\n";
441: unless (&Apache::lonnet::allowed('udp',$ccdomain)) {
442: $output .=
1.275 raeburn 443: &Apache::loncommon::start_data_table_row()."\n".
1.306 raeburn 444: ' <td style="vertical-align:top;"><span class="LC_nobreak">'.
445: $lt{'chse'}.': <label>'.
1.275 raeburn 446: '<input type="radio" name="custom'.$item.'" value="0" '.
1.306 raeburn 447: $cust_off.'/>'.$lt{'usde'}.'</label>'.(' ' x3).
448: '<label><input type="radio" name="custom'.$item.'" value="1" '.
449: $cust_on.'/>'.$lt{'uscu'}.'</label>'.$custradio.'</td>'.
1.275 raeburn 450: &Apache::loncommon::end_data_table_row()."\n";
1.418 raeburn 451: }
1.275 raeburn 452: }
453: return $output;
454: }
455:
1.300 raeburn 456: sub coursereq_externaluser {
457: my ($ccuname,$ccdomain,$cdom) = @_;
1.306 raeburn 458: my (@usertools,@options,%validations,%userenv,$output);
1.300 raeburn 459: my %lt = &Apache::lonlocal::texthash (
460: 'official' => 'Can request creation of official courses',
461: 'unofficial' => 'Can request creation of unofficial courses',
462: 'community' => 'Can request creation of communities',
1.384 raeburn 463: 'textbook' => 'Can request creation of textbook courses',
1.411 raeburn 464: 'placement' => 'Can request creation of placement tests',
1.300 raeburn 465: );
466:
467: %userenv = &Apache::lonnet::userenvironment($ccdomain,$ccuname,
468: 'reqcrsotherdom.official','reqcrsotherdom.unofficial',
1.411 raeburn 469: 'reqcrsotherdom.community','reqcrsotherdom.textbook',
470: 'reqcrsotherdom.placement');
471: @usertools = ('official','unofficial','community','textbook','placement');
1.309 raeburn 472: @options = ('approval','validate','autolimit');
1.306 raeburn 473: %validations = &Apache::lonnet::auto_courserequest_checks($cdom);
474: my $optregex = join('|',@options);
475: my %reqtitles = &courserequest_titles();
1.300 raeburn 476: foreach my $item (@usertools) {
1.306 raeburn 477: my ($curroption,$currlimit,$tooloff);
1.300 raeburn 478: if ($userenv{'reqcrsotherdom.'.$item} ne '') {
479: my @curr = split(',',$userenv{'reqcrsotherdom.'.$item});
1.314 raeburn 480: foreach my $req (@curr) {
481: if ($req =~ /^\Q$cdom\E\:($optregex)=?(\d*)$/) {
482: $curroption = $1;
483: $currlimit = $2;
484: last;
1.306 raeburn 485: }
486: }
1.314 raeburn 487: if (!$curroption) {
488: $curroption = 'norequest';
489: $tooloff = ' checked="checked"';
490: }
1.306 raeburn 491: } else {
492: $curroption = 'norequest';
493: $tooloff = ' checked="checked"';
494: }
495: $output.= &Apache::loncommon::start_data_table_row()."\n".
1.314 raeburn 496: ' <td><span class="LC_nobreak">'.$lt{$item}.': </span></td><td>'.
497: '<table><tr><td valign="top">'."\n".
1.306 raeburn 498: '<label><input type="radio" name="reqcrsotherdom_'.$item.
1.314 raeburn 499: '" value=""'.$tooloff.' />'.$reqtitles{'norequest'}.
500: '</label></td>';
1.306 raeburn 501: foreach my $option (@options) {
502: if ($option eq 'validate') {
503: my $canvalidate = 0;
504: if (ref($validations{$item}) eq 'HASH') {
505: if ($validations{$item}{'_external_'}) {
506: $canvalidate = 1;
507: }
508: }
509: next if (!$canvalidate);
510: }
511: my $checked = '';
512: if ($option eq $curroption) {
513: $checked = ' checked="checked"';
514: }
1.314 raeburn 515: $output .= '<td valign="top"><span class="LC_nobreak"><label>'.
1.306 raeburn 516: '<input type="radio" name="reqcrsotherdom_'.$item.
517: '" value="'.$option.'"'.$checked.' />'.
1.314 raeburn 518: $reqtitles{$option}.'</label>';
1.306 raeburn 519: if ($option eq 'autolimit') {
1.314 raeburn 520: $output .= ' <input type="text" name="reqcrsotherdom_'.
1.306 raeburn 521: $item.'_limit" size="1" '.
1.314 raeburn 522: 'value="'.$currlimit.'" /></span>'.
523: '<br />'.$reqtitles{'unlimited'};
524: } else {
525: $output .= '</span>';
1.300 raeburn 526: }
1.314 raeburn 527: $output .= '</td>';
1.300 raeburn 528: }
1.314 raeburn 529: $output .= '</td></tr></table></td>'."\n".
1.300 raeburn 530: &Apache::loncommon::end_data_table_row()."\n";
531: }
532: return $output;
533: }
534:
1.362 raeburn 535: sub domainrole_req {
536: my ($ccuname,$ccdomain) = @_;
537: return '<br /><h3>'.
538: &mt('User Can Request Assignment of Domain Roles?').
539: '</h3>'."\n".
540: &Apache::loncommon::start_data_table().
541: &build_tools_display($ccuname,$ccdomain,
542: 'requestauthor').
543: &Apache::loncommon::end_data_table();
544: }
545:
1.306 raeburn 546: sub courserequest_titles {
547: my %titles = &Apache::lonlocal::texthash (
548: official => 'Official',
549: unofficial => 'Unofficial',
550: community => 'Communities',
1.384 raeburn 551: textbook => 'Textbook',
1.411 raeburn 552: placement => 'Placement Tests',
1.449 raeburn 553: lti => 'LTI Provider',
1.306 raeburn 554: norequest => 'Not allowed',
1.309 raeburn 555: approval => 'Approval by Dom. Coord.',
1.306 raeburn 556: validate => 'With validation',
557: autolimit => 'Numerical limit',
1.314 raeburn 558: unlimited => '(blank for unlimited)',
1.306 raeburn 559: );
560: return %titles;
561: }
562:
563: sub courserequest_display {
564: my %titles = &Apache::lonlocal::texthash (
1.309 raeburn 565: approval => 'Yes, need approval',
1.306 raeburn 566: validate => 'Yes, with validation',
567: norequest => 'No',
568: );
569: return %titles;
570: }
571:
1.362 raeburn 572: sub requestauthor_titles {
573: my %titles = &Apache::lonlocal::texthash (
574: norequest => 'Not allowed',
575: approval => 'Approval by Dom. Coord.',
576: automatic => 'Automatic approval',
577: );
578: return %titles;
579:
580: }
581:
582: sub requestauthor_display {
583: my %titles = &Apache::lonlocal::texthash (
584: approval => 'Yes, need approval',
585: automatic => 'Yes, automatic approval',
586: norequest => 'No',
587: );
588: return %titles;
589: }
590:
1.383 raeburn 591: sub requestchange_display {
592: my %titles = &Apache::lonlocal::texthash (
593: approval => "availability set to 'on' (approval required)",
594: automatic => "availability set to 'on' (automatic approval)",
595: norequest => "availability set to 'off'",
596: );
597: return %titles;
598: }
599:
1.362 raeburn 600: sub curr_requestauthor {
601: my ($uname,$udom,$isadv,$inststatuses,$domconfig) = @_;
602: return unless ((ref($inststatuses) eq 'ARRAY') && (ref($domconfig) eq 'HASH'));
603: if ($uname eq '' || $udom eq '') {
604: $uname = $env{'user.name'};
605: $udom = $env{'user.domain'};
606: $isadv = $env{'user.adv'};
607: }
608: my (%userenv,%settings,$val);
609: my @options = ('automatic','approval');
610: %userenv =
611: &Apache::lonnet::userenvironment($udom,$uname,'requestauthor','inststatus');
612: if ($userenv{'requestauthor'}) {
613: $val = $userenv{'requestauthor'};
614: @{$inststatuses} = ('_custom_');
615: } else {
616: my %alltasks;
617: if (ref($domconfig->{'requestauthor'}) eq 'HASH') {
618: %settings = %{$domconfig->{'requestauthor'}};
619: if (($isadv) && ($settings{'_LC_adv'} ne '')) {
620: $val = $settings{'_LC_adv'};
621: @{$inststatuses} = ('_LC_adv_');
622: } else {
623: if ($userenv{'inststatus'} ne '') {
624: @{$inststatuses} = split(',',$userenv{'inststatus'});
625: } else {
626: @{$inststatuses} = ('default');
627: }
628: foreach my $status (@{$inststatuses}) {
629: if (exists($settings{$status})) {
630: my $value = $settings{$status};
631: next unless ($value);
632: unless (exists($alltasks{$value})) {
633: if (ref($alltasks{$value}) eq 'ARRAY') {
634: unless(grep(/^\Q$status\E$/,@{$alltasks{$value}})) {
635: push(@{$alltasks{$value}},$status);
636: }
637: } else {
638: @{$alltasks{$value}} = ($status);
639: }
640: }
641: }
642: }
643: foreach my $option (@options) {
644: if ($alltasks{$option}) {
645: $val = $option;
646: last;
647: }
648: }
649: }
650: }
651: }
652: return $val;
653: }
654:
1.2 www 655: # =================================================================== Phase one
1.1 www 656:
1.42 matthew 657: sub print_username_entry_form {
1.439 raeburn 658: my ($r,$context,$response,$srch,$forcenewuser,$crstype,$brcrum,
659: $permission) = @_;
1.101 albertel 660: my $defdom=$env{'request.role.domain'};
1.160 raeburn 661: my $formtoset = 'crtuser';
662: if (exists($env{'form.startrolename'})) {
663: $formtoset = 'docustom';
664: $env{'form.rolename'} = $env{'form.startrolename'};
1.207 raeburn 665: } elsif ($env{'form.origform'} eq 'crtusername') {
666: $formtoset = $env{'form.origform'};
1.160 raeburn 667: }
668:
669: my ($jsback,$elements) = &crumb_utilities();
670:
671: my $jscript = &Apache::loncommon::studentbrowser_javascript()."\n".
1.165 albertel 672: '<script type="text/javascript">'."\n".
1.301 bisitz 673: '// <![CDATA['."\n".
674: &Apache::lonhtmlcommon::set_form_elements($elements->{$formtoset})."\n".
675: '// ]]>'."\n".
1.162 raeburn 676: '</script>'."\n";
1.160 raeburn 677:
1.324 raeburn 678: my %existingroles=&Apache::lonuserutils::my_custom_roles($crstype);
679: if (($env{'form.action'} eq 'custom') && (keys(%existingroles) > 0)
680: && (&Apache::lonnet::allowed('mcr','/'))) {
681: $jscript .= &customrole_javascript();
682: }
1.224 raeburn 683: my $helpitem = 'Course_Change_Privileges';
684: if ($env{'form.action'} eq 'custom') {
1.439 raeburn 685: if ($context eq 'course') {
686: $helpitem = 'Course_Editing_Custom_Roles';
687: } elsif ($context eq 'domain') {
688: $helpitem = 'Domain_Editing_Custom_Roles';
689: }
1.224 raeburn 690: } elsif ($env{'form.action'} eq 'singlestudent') {
691: $helpitem = 'Course_Add_Student';
1.416 raeburn 692: } elsif ($env{'form.action'} eq 'accesslogs') {
693: $helpitem = 'Domain_User_Access_Logs';
1.439 raeburn 694: } elsif ($context eq 'author') {
695: $helpitem = 'Author_Change_Privileges';
696: } elsif ($context eq 'domain') {
697: if ($permission->{'cusr'}) {
698: $helpitem = 'Domain_Change_Privileges';
699: } elsif ($permission->{'view'}) {
700: $helpitem = 'Domain_View_Privileges';
701: } else {
702: undef($helpitem);
703: }
1.224 raeburn 704: }
1.422 raeburn 705: my %breadcrumb_text = &singleuser_breadcrumb($crstype,$context,$defdom);
1.351 raeburn 706: if ($env{'form.action'} eq 'custom') {
707: push(@{$brcrum},
708: {href=>"javascript:backPage(document.crtuser)",
709: text=>"Pick custom role",
710: help => $helpitem,}
711: );
712: } else {
713: push (@{$brcrum},
714: {href => "javascript:backPage(document.crtuser)",
715: text => $breadcrumb_text{'search'},
716: help => $helpitem,
717: faq => 282,
718: bug => 'Instructor Interface',}
719: );
720: }
721: my %loaditems = (
722: 'onload' => "javascript:setFormElements(document.$formtoset)",
723: );
724: my $args = {bread_crumbs => $brcrum,
725: bread_crumbs_component => 'User Management',
726: add_entries => \%loaditems,};
727: $r->print(&Apache::loncommon::start_page('User Management',$jscript,$args));
728:
1.71 sakharuk 729: my %lt=&Apache::lonlocal::texthash(
1.229 raeburn 730: 'srst' => 'Search for a user and enroll as a student',
1.318 raeburn 731: 'srme' => 'Search for a user and enroll as a member',
1.229 raeburn 732: 'srad' => 'Search for a user and modify/add user information or roles',
1.422 raeburn 733: 'srvu' => 'Search for a user and view user information and roles',
1.416 raeburn 734: 'srva' => 'Search for a user and view access log information',
1.71 sakharuk 735: 'usr' => "Username",
736: 'dom' => "Domain",
1.324 raeburn 737: 'ecrp' => "Define or Edit Custom Role",
738: 'nr' => "role name",
1.282 schafran 739: 'cre' => "Next",
1.71 sakharuk 740: );
1.351 raeburn 741:
1.214 raeburn 742: if ($env{'form.action'} eq 'custom') {
1.190 raeburn 743: if (&Apache::lonnet::allowed('mcr','/')) {
1.324 raeburn 744: my $newroletext = &mt('Define new custom role:');
745: $r->print('<form action="/adm/createuser" method="post" name="docustom">'.
746: '<input type="hidden" name="action" value="'.$env{'form.action'}.'" />'.
747: '<input type="hidden" name="phase" value="selected_custom_edit" />'.
748: '<h3>'.$lt{'ecrp'}.'</h3>'.
749: &Apache::loncommon::start_data_table().
750: &Apache::loncommon::start_data_table_row().
751: '<td>');
752: if (keys(%existingroles) > 0) {
753: $r->print('<br /><label><input type="radio" name="customroleaction" value="new" checked="checked" onclick="setCustomFields();" /><b>'.$newroletext.'</b></label>');
754: } else {
755: $r->print('<br /><input type="hidden" name="customroleaction" value="new" /><b>'.$newroletext.'</b>');
756: }
757: $r->print('</td><td align="center">'.$lt{'nr'}.'<br /><input type="text" size="15" name="newrolename" onfocus="setCustomAction('."'new'".');" /></td>'.
758: &Apache::loncommon::end_data_table_row());
759: if (keys(%existingroles) > 0) {
760: $r->print(&Apache::loncommon::start_data_table_row().'<td><br />'.
761: '<label><input type="radio" name="customroleaction" value="edit" onclick="setCustomFields();"/><b>'.
762: &mt('View/Modify existing role:').'</b></label></td>'.
763: '<td align="center"><br />'.
764: '<select name="rolename" onchange="setCustomAction('."'edit'".');">'.
1.326 raeburn 765: '<option value="" selected="selected">'.
1.324 raeburn 766: &mt('Select'));
767: foreach my $role (sort(keys(%existingroles))) {
1.326 raeburn 768: $r->print('<option value="'.$role.'">'.$role.'</option>');
1.324 raeburn 769: }
770: $r->print('</select>'.
771: '</td>'.
772: &Apache::loncommon::end_data_table_row());
773: }
774: $r->print(&Apache::loncommon::end_data_table().'<p>'.
775: '<input name="customeditor" type="submit" value="'.
776: $lt{'cre'}.'" /></p>'.
777: '</form>');
1.190 raeburn 778: }
1.213 raeburn 779: } else {
1.229 raeburn 780: my $actiontext = $lt{'srad'};
1.436 raeburn 781: my $fixeddom;
1.213 raeburn 782: if ($env{'form.action'} eq 'singlestudent') {
1.318 raeburn 783: if ($crstype eq 'Community') {
784: $actiontext = $lt{'srme'};
785: } else {
786: $actiontext = $lt{'srst'};
787: }
1.416 raeburn 788: } elsif ($env{'form.action'} eq 'accesslogs') {
1.417 raeburn 789: $actiontext = $lt{'srva'};
1.436 raeburn 790: $fixeddom = 1;
1.422 raeburn 791: } elsif (($env{'form.action'} eq 'singleuser') &&
792: ($context eq 'domain') && (!&Apache::lonnet::allowed('mau',$defdom))) {
793: $actiontext = $lt{'srvu'};
1.439 raeburn 794: $fixeddom = 1;
1.213 raeburn 795: }
1.324 raeburn 796: $r->print("<h3>$actiontext</h3>");
1.213 raeburn 797: if ($env{'form.origform'} ne 'crtusername') {
1.415 raeburn 798: if ($response) {
799: $r->print("\n<div>$response</div>".
800: '<br clear="all" />');
801: }
1.213 raeburn 802: }
1.436 raeburn 803: $r->print(&entry_form($defdom,$srch,$forcenewuser,$context,$response,$crstype,$fixeddom));
1.107 www 804: }
1.110 albertel 805: }
806:
1.324 raeburn 807: sub customrole_javascript {
808: my $js = <<"END";
809: <script type="text/javascript">
810: // <![CDATA[
811:
812: function setCustomFields() {
813: if (document.docustom.customroleaction.length > 0) {
814: for (var i=0; i<document.docustom.customroleaction.length; i++) {
815: if (document.docustom.customroleaction[i].checked) {
816: if (document.docustom.customroleaction[i].value == 'new') {
817: document.docustom.rolename.selectedIndex = 0;
818: } else {
819: document.docustom.newrolename.value = '';
820: }
821: }
822: }
823: }
824: return;
825: }
826:
827: function setCustomAction(caller) {
828: if (document.docustom.customroleaction.length > 0) {
829: for (var i=0; i<document.docustom.customroleaction.length; i++) {
830: if (document.docustom.customroleaction[i].value == caller) {
831: document.docustom.customroleaction[i].checked = true;
832: }
833: }
834: }
835: setCustomFields();
836: return;
837: }
838:
839: // ]]>
840: </script>
841: END
842: return $js;
843: }
844:
1.160 raeburn 845: sub entry_form {
1.416 raeburn 846: my ($dom,$srch,$forcenewuser,$context,$responsemsg,$crstype,$fixeddom) = @_;
1.229 raeburn 847: my ($usertype,$inexact);
1.214 raeburn 848: if (ref($srch) eq 'HASH') {
849: if (($srch->{'srchin'} eq 'dom') &&
850: ($srch->{'srchby'} eq 'uname') &&
851: ($srch->{'srchtype'} eq 'exact') &&
852: ($srch->{'srchdomain'} ne '') &&
853: ($srch->{'srchterm'} ne '')) {
1.353 raeburn 854: my (%curr_rules,%got_rules);
1.214 raeburn 855: my ($rules,$ruleorder) =
856: &Apache::lonnet::inst_userrules($srch->{'srchdomain'},'username');
1.353 raeburn 857: $usertype = &Apache::lonuserutils::check_usertype($srch->{'srchdomain'},$srch->{'srchterm'},$rules,\%curr_rules,\%got_rules);
1.229 raeburn 858: } else {
859: $inexact = 1;
1.214 raeburn 860: }
1.207 raeburn 861: }
1.438 raeburn 862: my ($cancreate,$noinstd);
863: if ($env{'form.action'} eq 'accesslogs') {
864: $noinstd = 1;
865: } else {
866: $cancreate =
867: &Apache::lonuserutils::can_create_user($dom,$context,$usertype);
868: }
1.412 raeburn 869: my ($userpicker,$cansearch) =
1.179 raeburn 870: &Apache::loncommon::user_picker($dom,$srch,$forcenewuser,
1.438 raeburn 871: 'document.crtuser',$cancreate,$usertype,$context,$fixeddom,$noinstd);
1.160 raeburn 872: my $srchbutton = &mt('Search');
1.229 raeburn 873: if ($env{'form.action'} eq 'singlestudent') {
874: $srchbutton = &mt('Search and Enroll');
1.416 raeburn 875: } elsif ($env{'form.action'} eq 'accesslogs') {
876: $srchbutton = &mt('Search');
1.229 raeburn 877: } elsif ($cancreate && $responsemsg ne '' && $inexact) {
878: $srchbutton = &mt('Search or Add New User');
879: }
1.412 raeburn 880: my $output;
881: if ($cansearch) {
882: $output = <<"ENDBLOCK";
1.160 raeburn 883: <form action="/adm/createuser" method="post" name="crtuser">
1.190 raeburn 884: <input type="hidden" name="action" value="$env{'form.action'}" />
1.160 raeburn 885: <input type="hidden" name="phase" value="get_user_info" />
886: $userpicker
1.179 raeburn 887: <input name="userrole" type="button" value="$srchbutton" onclick="javascript:validateEntry(document.crtuser)" />
1.160 raeburn 888: </form>
1.207 raeburn 889: ENDBLOCK
1.412 raeburn 890: } else {
891: $output = '<p>'.$userpicker.'</p>';
892: }
1.422 raeburn 893: if (($env{'form.phase'} eq '') && ($env{'form.action'} ne 'accesslogs') &&
1.430 raeburn 894: (!(($env{'form.action'} eq 'singleuser') && ($context eq 'domain') &&
1.422 raeburn 895: (!&Apache::lonnet::allowed('mau',$env{'request.role.domain'}))))) {
1.207 raeburn 896: my $defdom=$env{'request.role.domain'};
1.446 raeburn 897: my ($trusted,$untrusted);
1.444 raeburn 898: if ($context eq 'course') {
1.446 raeburn 899: ($trusted,$untrusted) = &Apache::lonnet::trusted_domains('enroll',$defdom);
1.444 raeburn 900: } elsif ($context eq 'author') {
1.446 raeburn 901: ($trusted,$untrusted) = &Apache::lonnet::trusted_domains('othcoau',$defdom);
1.444 raeburn 902: } elsif ($context eq 'domain') {
1.446 raeburn 903: ($trusted,$untrusted) = &Apache::lonnet::trusted_domains('domroles',$defdom);
1.444 raeburn 904: }
1.446 raeburn 905: my $domform = &Apache::loncommon::select_dom_form($defdom,'srchdomain',undef,undef,undef,$trusted,$untrusted);
1.207 raeburn 906: my %lt=&Apache::lonlocal::texthash(
1.229 raeburn 907: 'enro' => 'Enroll one student',
1.318 raeburn 908: 'enrm' => 'Enroll one member',
1.229 raeburn 909: 'admo' => 'Add/modify a single user',
910: 'crea' => 'create new user if required',
911: 'uskn' => "username is known",
1.207 raeburn 912: 'crnu' => 'Create a new user',
913: 'usr' => 'Username',
914: 'dom' => 'in domain',
1.229 raeburn 915: 'enrl' => 'Enroll',
916: 'cram' => 'Create/Modify user',
1.207 raeburn 917: );
1.229 raeburn 918: my $sellink=&Apache::loncommon::selectstudent_link('crtusername','srchterm','srchdomain');
919: my ($title,$buttontext,$showresponse);
1.318 raeburn 920: if ($env{'form.action'} eq 'singlestudent') {
921: if ($crstype eq 'Community') {
922: $title = $lt{'enrm'};
923: } else {
924: $title = $lt{'enro'};
925: }
1.229 raeburn 926: $buttontext = $lt{'enrl'};
927: } else {
928: $title = $lt{'admo'};
929: $buttontext = $lt{'cram'};
930: }
931: if ($cancreate) {
932: $title .= ' <span class="LC_cusr_subheading">('.$lt{'crea'}.')</span>';
933: } else {
934: $title .= ' <span class="LC_cusr_subheading">('.$lt{'uskn'}.')</span>';
935: }
936: if ($env{'form.origform'} eq 'crtusername') {
937: $showresponse = $responsemsg;
938: }
1.207 raeburn 939: $output .= <<"ENDDOCUMENT";
1.229 raeburn 940: <br />
1.207 raeburn 941: <form action="/adm/createuser" method="post" name="crtusername">
942: <input type="hidden" name="action" value="$env{'form.action'}" />
943: <input type="hidden" name="phase" value="createnewuser" />
944: <input type="hidden" name="srchtype" value="exact" />
1.233 raeburn 945: <input type="hidden" name="srchby" value="uname" />
1.207 raeburn 946: <input type="hidden" name="srchin" value="dom" />
947: <input type="hidden" name="forcenewuser" value="1" />
948: <input type="hidden" name="origform" value="crtusername" />
1.229 raeburn 949: <h3>$title</h3>
950: $showresponse
1.207 raeburn 951: <table>
952: <tr>
953: <td>$lt{'usr'}:</td>
954: <td><input type="text" size="15" name="srchterm" /></td>
955: <td> $lt{'dom'}:</td><td>$domform</td>
1.229 raeburn 956: <td> $sellink </td>
957: <td> <input name="userrole" type="submit" value="$buttontext" /></td>
1.207 raeburn 958: </tr>
959: </table>
960: </form>
1.160 raeburn 961: ENDDOCUMENT
1.207 raeburn 962: }
1.160 raeburn 963: return $output;
964: }
1.110 albertel 965:
966: sub user_modification_js {
1.113 raeburn 967: my ($pjump_def,$dc_setcourse_code,$nondc_setsection_code,$groupslist)=@_;
968:
1.110 albertel 969: return <<END;
970: <script type="text/javascript" language="Javascript">
1.301 bisitz 971: // <![CDATA[
1.314 raeburn 972:
1.110 albertel 973: $pjump_def
974: $dc_setcourse_code
975:
976: function dateset() {
977: eval("document.cu."+document.cu.pres_marker.value+
978: ".value=document.cu.pres_value.value");
1.359 www 979: modalWindow.close();
1.110 albertel 980: }
981:
1.113 raeburn 982: $nondc_setsection_code
1.301 bisitz 983: // ]]>
1.110 albertel 984: </script>
985: END
1.2 www 986: }
987:
988: # =================================================================== Phase two
1.160 raeburn 989: sub print_user_selection_page {
1.351 raeburn 990: my ($r,$response,$srch,$srch_results,$srcharray,$context,$opener_elements,$crstype,$brcrum) = @_;
1.160 raeburn 991: my @fields = ('username','domain','lastname','firstname','permanentemail');
992: my $sortby = $env{'form.sortby'};
993:
994: if (!grep(/^\Q$sortby\E$/,@fields)) {
995: $sortby = 'lastname';
996: }
997:
998: my ($jsback,$elements) = &crumb_utilities();
999:
1000: my $jscript = (<<ENDSCRIPT);
1001: <script type="text/javascript">
1.301 bisitz 1002: // <![CDATA[
1.160 raeburn 1003: function pickuser(uname,udom) {
1004: document.usersrchform.seluname.value=uname;
1005: document.usersrchform.seludom.value=udom;
1006: document.usersrchform.phase.value="userpicked";
1007: document.usersrchform.submit();
1008: }
1009:
1010: $jsback
1.301 bisitz 1011: // ]]>
1.160 raeburn 1012: </script>
1013: ENDSCRIPT
1014:
1015: my %lt=&Apache::lonlocal::texthash(
1.179 raeburn 1016: 'usrch' => "User Search to add/modify roles",
1017: 'stusrch' => "User Search to enroll student",
1.318 raeburn 1018: 'memsrch' => "User Search to enroll member",
1.416 raeburn 1019: 'srcva' => "Search for a user and view access log information",
1.422 raeburn 1020: 'usrvu' => "User Search to view user roles",
1.179 raeburn 1021: 'usel' => "Select a user to add/modify roles",
1.422 raeburn 1022: 'suvr' => "Select a user to view roles",
1.318 raeburn 1023: 'stusel' => "Select a user to enroll as a student",
1024: 'memsel' => "Select a user to enroll as a member",
1.416 raeburn 1025: 'vacsel' => "Select a user to view access log",
1.160 raeburn 1026: 'username' => "username",
1027: 'domain' => "domain",
1028: 'lastname' => "last name",
1029: 'firstname' => "first name",
1030: 'permanentemail' => "permanent e-mail",
1031: );
1.302 raeburn 1032: if ($context eq 'requestcrs') {
1033: $r->print('<div>');
1034: } else {
1.422 raeburn 1035: my %breadcrumb_text = &singleuser_breadcrumb($crstype,$context,$srch->{'srchdomain'});
1.351 raeburn 1036: my $helpitem;
1037: if ($env{'form.action'} eq 'singleuser') {
1038: $helpitem = 'Course_Change_Privileges';
1039: } elsif ($env{'form.action'} eq 'singlestudent') {
1040: $helpitem = 'Course_Add_Student';
1.439 raeburn 1041: } elsif ($context eq 'author') {
1042: $helpitem = 'Author_Change_Privileges';
1043: } elsif ($context eq 'domain') {
1044: $helpitem = 'Domain_Change_Privileges';
1.351 raeburn 1045: }
1046: push (@{$brcrum},
1047: {href => "javascript:backPage(document.usersrchform,'','')",
1048: text => $breadcrumb_text{'search'},
1049: faq => 282,
1050: bug => 'Instructor Interface',},
1051: {href => "javascript:backPage(document.usersrchform,'get_user_info','select')",
1052: text => $breadcrumb_text{'userpicked'},
1053: faq => 282,
1054: bug => 'Instructor Interface',
1055: help => $helpitem}
1056: );
1057: $r->print(&Apache::loncommon::start_page('User Management',$jscript,{bread_crumbs => $brcrum}));
1.302 raeburn 1058: if ($env{'form.action'} eq 'singleuser') {
1.422 raeburn 1059: my $readonly;
1060: if (($context eq 'domain') && (!&Apache::lonnet::allowed('mau',$srch->{'srchdomain'}))) {
1061: $readonly = 1;
1062: $r->print("<b>$lt{'usrvu'}</b><br />");
1063: } else {
1064: $r->print("<b>$lt{'usrch'}</b><br />");
1065: }
1.318 raeburn 1066: $r->print(&entry_form($srch->{'srchdomain'},$srch,undef,$context,undef,$crstype));
1.422 raeburn 1067: if ($readonly) {
1068: $r->print('<h3>'.$lt{'suvr'}.'</h3>');
1069: } else {
1070: $r->print('<h3>'.$lt{'usel'}.'</h3>');
1071: }
1.302 raeburn 1072: } elsif ($env{'form.action'} eq 'singlestudent') {
1.318 raeburn 1073: $r->print($jscript."<b>");
1074: if ($crstype eq 'Community') {
1075: $r->print($lt{'memsrch'});
1076: } else {
1077: $r->print($lt{'stusrch'});
1078: }
1079: $r->print("</b><br />");
1080: $r->print(&entry_form($srch->{'srchdomain'},$srch,undef,$context,undef,$crstype));
1081: $r->print('</form><h3>');
1082: if ($crstype eq 'Community') {
1083: $r->print($lt{'memsel'});
1084: } else {
1085: $r->print($lt{'stusel'});
1086: }
1087: $r->print('</h3>');
1.416 raeburn 1088: } elsif ($env{'form.action'} eq 'accesslogs') {
1089: $r->print("<b>$lt{'srcva'}</b><br />");
1.438 raeburn 1090: $r->print(&entry_form($srch->{'srchdomain'},$srch,undef,$context,undef,undef,1));
1.416 raeburn 1091: $r->print('<h3>'.$lt{'vacsel'}.'</h3>');
1.302 raeburn 1092: }
1.179 raeburn 1093: }
1.380 bisitz 1094: $r->print('<form name="usersrchform" method="post" action="">'.
1.160 raeburn 1095: &Apache::loncommon::start_data_table()."\n".
1096: &Apache::loncommon::start_data_table_header_row()."\n".
1097: ' <th> </th>'."\n");
1098: foreach my $field (@fields) {
1099: $r->print(' <th><a href="javascript:document.usersrchform.sortby.value='.
1100: "'".$field."'".';document.usersrchform.submit();">'.
1101: $lt{$field}.'</a></th>'."\n");
1102: }
1103: $r->print(&Apache::loncommon::end_data_table_header_row());
1104:
1105: my @sorted_users = sort {
1.167 albertel 1106: lc($srch_results->{$a}->{$sortby}) cmp lc($srch_results->{$b}->{$sortby})
1.160 raeburn 1107: ||
1.167 albertel 1108: lc($srch_results->{$a}->{lastname}) cmp lc($srch_results->{$b}->{lastname})
1.160 raeburn 1109: ||
1110: lc($srch_results->{$a}->{firstname}) cmp lc($srch_results->{$b}->{firstname})
1.167 albertel 1111: ||
1112: lc($a) cmp lc($b)
1.160 raeburn 1113: } (keys(%$srch_results));
1114:
1115: foreach my $user (@sorted_users) {
1116: my ($uname,$udom) = split(/:/,$user);
1.302 raeburn 1117: my $onclick;
1118: if ($context eq 'requestcrs') {
1.314 raeburn 1119: $onclick =
1.302 raeburn 1120: 'onclick="javascript:gochoose('."'$uname','$udom',".
1121: "'$srch_results->{$user}->{firstname}',".
1122: "'$srch_results->{$user}->{lastname}',".
1123: "'$srch_results->{$user}->{permanentemail}'".');"';
1124: } else {
1.314 raeburn 1125: $onclick =
1.302 raeburn 1126: ' onclick="javascript:pickuser('."'".$uname."'".','."'".$udom."'".');"';
1127: }
1.160 raeburn 1128: $r->print(&Apache::loncommon::start_data_table_row().
1.302 raeburn 1129: '<td><input type="button" name="seluser" value="'.&mt('Select').'" '.
1130: $onclick.' /></td>'.
1.160 raeburn 1131: '<td><tt>'.$uname.'</tt></td>'.
1132: '<td><tt>'.$udom.'</tt></td>');
1133: foreach my $field ('lastname','firstname','permanentemail') {
1134: $r->print('<td>'.$srch_results->{$user}->{$field}.'</td>');
1135: }
1136: $r->print(&Apache::loncommon::end_data_table_row());
1137: }
1138: $r->print(&Apache::loncommon::end_data_table().'<br /><br />');
1.179 raeburn 1139: if (ref($srcharray) eq 'ARRAY') {
1140: foreach my $item (@{$srcharray}) {
1141: $r->print('<input type="hidden" name="'.$item.'" value="'.$env{'form.'.$item}.'" />'."\n");
1142: }
1143: }
1.160 raeburn 1144: $r->print(' <input type="hidden" name="sortby" value="'.$sortby.'" />'."\n".
1145: ' <input type="hidden" name="seluname" value="" />'."\n".
1146: ' <input type="hidden" name="seludom" value="" />'."\n".
1.179 raeburn 1147: ' <input type="hidden" name="currstate" value="select" />'."\n".
1.190 raeburn 1148: ' <input type="hidden" name="phase" value="get_user_info" />'."\n".
1.214 raeburn 1149: ' <input type="hidden" name="action" value="'.$env{'form.action'}.'" />'."\n");
1.302 raeburn 1150: if ($context eq 'requestcrs') {
1151: $r->print($opener_elements.'</form></div>');
1152: } else {
1.351 raeburn 1153: $r->print($response.'</form>');
1.302 raeburn 1154: }
1.160 raeburn 1155: }
1156:
1157: sub print_user_query_page {
1.351 raeburn 1158: my ($r,$caller,$brcrum) = @_;
1.160 raeburn 1159: # FIXME - this is for a network-wide name search (similar to catalog search)
1160: # To use frames with similar behavior to catalog/portfolio search.
1161: # To be implemented.
1162: return;
1163: }
1164:
1.42 matthew 1165: sub print_user_modification_page {
1.375 raeburn 1166: my ($r,$ccuname,$ccdomain,$srch,$response,$context,$permission,$crstype,
1167: $brcrum,$showcredits) = @_;
1.185 raeburn 1168: if (($ccuname eq '') || ($ccdomain eq '')) {
1.215 raeburn 1169: my $usermsg = &mt('No username and/or domain provided.');
1170: $env{'form.phase'} = '';
1.439 raeburn 1171: &print_username_entry_form($r,$context,$usermsg,'','',$crstype,$brcrum,
1172: $permission);
1.58 www 1173: return;
1174: }
1.213 raeburn 1175: my ($form,$formname);
1176: if ($env{'form.action'} eq 'singlestudent') {
1177: $form = 'document.enrollstudent';
1178: $formname = 'enrollstudent';
1179: } else {
1180: $form = 'document.cu';
1181: $formname = 'cu';
1182: }
1.188 raeburn 1183: my %abv_auth = &auth_abbrev();
1.227 raeburn 1184: my (%rulematch,%inst_results,$newuser,%alerts,%curr_rules,%got_rules);
1.185 raeburn 1185: my $uhome=&Apache::lonnet::homeserver($ccuname,$ccdomain);
1186: if ($uhome eq 'no_host') {
1.215 raeburn 1187: my $usertype;
1188: my ($rules,$ruleorder) =
1189: &Apache::lonnet::inst_userrules($ccdomain,'username');
1190: $usertype =
1.353 raeburn 1191: &Apache::lonuserutils::check_usertype($ccdomain,$ccuname,$rules,
1.362 raeburn 1192: \%curr_rules,\%got_rules);
1.215 raeburn 1193: my $cancreate =
1194: &Apache::lonuserutils::can_create_user($ccdomain,$context,
1195: $usertype);
1196: if (!$cancreate) {
1.292 bisitz 1197: my $helplink = 'javascript:helpMenu('."'display'".')';
1.215 raeburn 1198: my %usertypetext = (
1199: official => 'institutional',
1200: unofficial => 'non-institutional',
1201: );
1202: my $response;
1203: if ($env{'form.origform'} eq 'crtusername') {
1.362 raeburn 1204: $response = '<span class="LC_warning">'.
1205: &mt('No match found for the username [_1] in LON-CAPA domain: [_2]',
1206: '<b>'.$ccuname.'</b>',$ccdomain).
1.215 raeburn 1207: '</span><br />';
1208: }
1.292 bisitz 1209: $response .= '<p class="LC_warning">'
1210: .&mt("You are not authorized to create new $usertypetext{$usertype} users in this domain.")
1.418 raeburn 1211: .' ';
1212: if ($context eq 'domain') {
1213: $response .= &mt('Please contact a [_1] for assistance.',
1214: &Apache::lonnet::plaintext('dc'));
1215: } else {
1216: $response .= &mt('Please contact the [_1]helpdesk[_2] for assistance.'
1217: ,'<a href="'.$helplink.'">','</a>');
1218: }
1219: $response .= '</p><br />';
1.215 raeburn 1220: $env{'form.phase'} = '';
1.439 raeburn 1221: &print_username_entry_form($r,$context,$response,undef,undef,$crstype,$brcrum,
1222: $permission);
1.215 raeburn 1223: return;
1224: }
1.188 raeburn 1225: $newuser = 1;
1.193 raeburn 1226: my $checkhash;
1227: my $checks = { 'username' => 1 };
1.196 raeburn 1228: $checkhash->{$ccuname.':'.$ccdomain} = { 'newuser' => $newuser };
1.193 raeburn 1229: &Apache::loncommon::user_rule_check($checkhash,$checks,
1.196 raeburn 1230: \%alerts,\%rulematch,\%inst_results,\%curr_rules,\%got_rules);
1231: if (ref($alerts{'username'}) eq 'HASH') {
1232: if (ref($alerts{'username'}{$ccdomain}) eq 'HASH') {
1233: my $domdesc =
1.193 raeburn 1234: &Apache::lonnet::domain($ccdomain,'description');
1.196 raeburn 1235: if ($alerts{'username'}{$ccdomain}{$ccuname}) {
1236: my $userchkmsg;
1237: if (ref($curr_rules{$ccdomain}) eq 'HASH') {
1238: $userchkmsg =
1239: &Apache::loncommon::instrule_disallow_msg('username',
1.193 raeburn 1240: $domdesc,1).
1241: &Apache::loncommon::user_rule_formats($ccdomain,
1242: $domdesc,$curr_rules{$ccdomain}{'username'},
1243: 'username');
1.196 raeburn 1244: }
1.215 raeburn 1245: $env{'form.phase'} = '';
1.439 raeburn 1246: &print_username_entry_form($r,$context,$userchkmsg,undef,undef,$crstype,$brcrum,
1247: $permission);
1.196 raeburn 1248: return;
1.215 raeburn 1249: }
1.193 raeburn 1250: }
1.185 raeburn 1251: }
1.187 raeburn 1252: } else {
1.188 raeburn 1253: $newuser = 0;
1.185 raeburn 1254: }
1.160 raeburn 1255: if ($response) {
1.215 raeburn 1256: $response = '<br />'.$response;
1.160 raeburn 1257: }
1.149 raeburn 1258:
1.52 matthew 1259: my $pjump_def = &Apache::lonhtmlcommon::pjump_javascript_definition();
1.88 raeburn 1260: my $dc_setcourse_code = '';
1.119 raeburn 1261: my $nondc_setsection_code = '';
1.112 albertel 1262: my %loaditem;
1.114 albertel 1263:
1.216 raeburn 1264: my $groupslist = &Apache::lonuserutils::get_groupslist();
1.88 raeburn 1265:
1.375 raeburn 1266: my $js = &validation_javascript($context,$ccdomain,$pjump_def,$crstype,
1.216 raeburn 1267: $groupslist,$newuser,$formname,\%loaditem);
1.422 raeburn 1268: my %breadcrumb_text = &singleuser_breadcrumb($crstype,$context,$ccdomain);
1.224 raeburn 1269: my $helpitem = 'Course_Change_Privileges';
1270: if ($env{'form.action'} eq 'singlestudent') {
1271: $helpitem = 'Course_Add_Student';
1.439 raeburn 1272: } elsif ($context eq 'author') {
1273: $helpitem = 'Author_Change_Privileges';
1274: } elsif ($context eq 'domain') {
1275: $helpitem = 'Domain_Change_Privileges';
1.224 raeburn 1276: }
1.351 raeburn 1277: push (@{$brcrum},
1278: {href => "javascript:backPage($form)",
1279: text => $breadcrumb_text{'search'},
1280: faq => 282,
1281: bug => 'Instructor Interface',});
1282: if ($env{'form.phase'} eq 'userpicked') {
1283: push(@{$brcrum},
1284: {href => "javascript:backPage($form,'get_user_info','select')",
1285: text => $breadcrumb_text{'userpicked'},
1286: faq => 282,
1287: bug => 'Instructor Interface',});
1288: }
1289: push(@{$brcrum},
1290: {href => "javascript:backPage($form,'$env{'form.phase'}','modify')",
1291: text => $breadcrumb_text{'modify'},
1292: faq => 282,
1293: bug => 'Instructor Interface',
1294: help => $helpitem});
1295: my $args = {'add_entries' => \%loaditem,
1296: 'bread_crumbs' => $brcrum,
1297: 'bread_crumbs_component' => 'User Management'};
1298: if ($env{'form.popup'}) {
1299: $args->{'no_nav_bar'} = 1;
1300: }
1301: my $start_page =
1302: &Apache::loncommon::start_page('User Management',$js,$args);
1.3 www 1303:
1.25 matthew 1304: my $forminfo =<<"ENDFORMINFO";
1.216 raeburn 1305: <form action="/adm/createuser" method="post" name="$formname">
1.190 raeburn 1306: <input type="hidden" name="phase" value="update_user_data" />
1.188 raeburn 1307: <input type="hidden" name="ccuname" value="$ccuname" />
1308: <input type="hidden" name="ccdomain" value="$ccdomain" />
1.157 albertel 1309: <input type="hidden" name="pres_value" value="" />
1310: <input type="hidden" name="pres_type" value="" />
1311: <input type="hidden" name="pres_marker" value="" />
1.25 matthew 1312: ENDFORMINFO
1.375 raeburn 1313: my (%inccourses,$roledom,$defaultcredits);
1.329 raeburn 1314: if ($context eq 'course') {
1315: $inccourses{$env{'request.course.id'}}=1;
1316: $roledom = $env{'course.'.$env{'request.course.id'}.'.domain'};
1.375 raeburn 1317: if ($showcredits) {
1318: $defaultcredits = &Apache::lonuserutils::get_defaultcredits();
1319: }
1.329 raeburn 1320: } elsif ($context eq 'author') {
1321: $roledom = $env{'request.role.domain'};
1322: } elsif ($context eq 'domain') {
1323: foreach my $key (keys(%env)) {
1324: $roledom = $env{'request.role.domain'};
1325: if ($key=~/^user\.priv\.cm\.\/($roledom)\/($match_username)/) {
1326: $inccourses{$1.'_'.$2}=1;
1327: }
1328: }
1329: } else {
1330: foreach my $key (keys(%env)) {
1331: if ($key=~/^user\.priv\.cm\.\/($match_domain)\/($match_username)/) {
1332: $inccourses{$1.'_'.$2}=1;
1333: }
1.2 www 1334: }
1.24 matthew 1335: }
1.389 bisitz 1336: my $title = '';
1.216 raeburn 1337: if ($newuser) {
1.427 raeburn 1338: my ($portfolioform,$domroleform);
1.267 raeburn 1339: if ((&Apache::lonnet::allowed('mpq',$env{'request.role.domain'})) ||
1340: (&Apache::lonnet::allowed('mut',$env{'request.role.domain'}))) {
1341: # Current user has quota or user tools modification privileges
1.378 raeburn 1342: $portfolioform = '<br />'.&user_quotas($ccuname,$ccdomain);
1.134 raeburn 1343: }
1.383 raeburn 1344: if ((&Apache::lonnet::allowed('cau',$env{'request.role.domain'})) &&
1345: ($ccdomain eq $env{'request.role.domain'})) {
1.362 raeburn 1346: $domroleform = '<br />'.&domainrole_req($ccuname,$ccdomain);
1347: }
1.227 raeburn 1348: &initialize_authen_forms($ccdomain,$formname);
1.188 raeburn 1349: my %lt=&Apache::lonlocal::texthash(
1350: 'lg' => 'Login Data',
1.190 raeburn 1351: 'hs' => "Home Server",
1.188 raeburn 1352: );
1.185 raeburn 1353: $r->print(<<ENDTITLE);
1.110 albertel 1354: $start_page
1.160 raeburn 1355: $response
1.25 matthew 1356: $forminfo
1.31 matthew 1357: <script type="text/javascript" language="Javascript">
1.301 bisitz 1358: // <![CDATA[
1.20 harris41 1359: $loginscript
1.301 bisitz 1360: // ]]>
1.31 matthew 1361: </script>
1.20 harris41 1362: <input type='hidden' name='makeuser' value='1' />
1.185 raeburn 1363: ENDTITLE
1.213 raeburn 1364: if ($env{'form.action'} eq 'singlestudent') {
1.318 raeburn 1365: if ($crstype eq 'Community') {
1.389 bisitz 1366: $title = &mt('Create New User [_1] in domain [_2] as a member',
1367: '"'.$ccuname.'"','"'.$ccdomain.'"');
1.318 raeburn 1368: } else {
1.389 bisitz 1369: $title = &mt('Create New User [_1] in domain [_2] as a student',
1370: '"'.$ccuname.'"','"'.$ccdomain.'"');
1.318 raeburn 1371: }
1.389 bisitz 1372: } else {
1373: $title = &mt('Create New User [_1] in domain [_2]',
1374: '"'.$ccuname.'"','"'.$ccdomain.'"');
1.213 raeburn 1375: }
1.389 bisitz 1376: $r->print('<h2>'.$title.'</h2>'."\n");
1377: $r->print('<div class="LC_left_float">');
1.393 raeburn 1378: $r->print(&personal_data_display($ccuname,$ccdomain,$newuser,$context,
1379: $inst_results{$ccuname.':'.$ccdomain}));
1380: # Option to disable student/employee ID conflict checking not offerred for new users.
1.187 raeburn 1381: my ($home_server_pick,$numlib) =
1382: &Apache::loncommon::home_server_form_item($ccdomain,'hserver',
1383: 'default','hide');
1384: if ($numlib > 1) {
1385: $r->print("
1.185 raeburn 1386: <br />
1.187 raeburn 1387: $lt{'hs'}: $home_server_pick
1388: <br />");
1389: } else {
1390: $r->print($home_server_pick);
1391: }
1.304 raeburn 1392: if (&Apache::lonnet::allowed('ccc',$env{'request.role.domain'})) {
1.362 raeburn 1393: $r->print('<br /><h3>'.
1394: &mt('User Can Request Creation of Courses/Communities in this Domain?').'</h3>'.
1.304 raeburn 1395: &Apache::loncommon::start_data_table().
1396: &build_tools_display($ccuname,$ccdomain,
1397: 'requestcourses').
1398: &Apache::loncommon::end_data_table());
1399: }
1.188 raeburn 1400: $r->print('</div>'."\n".'<div class="LC_left_float"><h3>'.
1401: $lt{'lg'}.'</h3>');
1.185 raeburn 1402: my ($fixedauth,$varauth,$authmsg);
1.193 raeburn 1403: if (ref($rulematch{$ccuname.':'.$ccdomain}) eq 'HASH') {
1404: my $matchedrule = $rulematch{$ccuname.':'.$ccdomain}{'username'};
1405: my ($rules,$ruleorder) =
1406: &Apache::lonnet::inst_userrules($ccdomain,'username');
1.185 raeburn 1407: if (ref($rules) eq 'HASH') {
1.193 raeburn 1408: if (ref($rules->{$matchedrule}) eq 'HASH') {
1409: my $authtype = $rules->{$matchedrule}{'authtype'};
1.185 raeburn 1410: if ($authtype !~ /^(krb4|krb5|int|fsys|loc)$/) {
1.190 raeburn 1411: $r->print(&Apache::lonuserutils::set_login($ccdomain,$authformkrb,$authformint,$authformloc));
1.275 raeburn 1412: } else {
1.193 raeburn 1413: my $authparm = $rules->{$matchedrule}{'authparm'};
1.273 raeburn 1414: $authmsg = $rules->{$matchedrule}{'authmsg'};
1.185 raeburn 1415: if ($authtype =~ /^krb(4|5)$/) {
1416: my $ver = $1;
1417: if ($authparm ne '') {
1418: $fixedauth = <<"KERB";
1419: <input type="hidden" name="login" value="krb" />
1420: <input type="hidden" name="krbver" value="$ver" />
1421: <input type="hidden" name="krbarg" value="$authparm" />
1422: KERB
1423: }
1424: } else {
1425: $fixedauth =
1426: '<input type="hidden" name="login" value="'.$authtype.'" />'."\n";
1.193 raeburn 1427: if ($rules->{$matchedrule}{'authparmfixed'}) {
1.185 raeburn 1428: $fixedauth .=
1429: '<input type="hidden" name="'.$authtype.'arg" value="'.$authparm.'" />'."\n";
1430: } else {
1.273 raeburn 1431: if ($authtype eq 'int') {
1432: $varauth = '<br />'.
1.301 bisitz 1433: &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 1434: } elsif ($authtype eq 'loc') {
1435: $varauth = '<br />'.
1436: &mt('[_1] Local Authentication with argument [_2]','','<input type="text" name="'.$authtype.'arg" value="" />')."\n";
1437: } else {
1438: $varauth =
1.185 raeburn 1439: '<input type="text" name="'.$authtype.'arg" value="" />'."\n";
1.273 raeburn 1440: }
1.185 raeburn 1441: }
1442: }
1443: }
1444: } else {
1.190 raeburn 1445: $r->print(&Apache::lonuserutils::set_login($ccdomain,$authformkrb,$authformint,$authformloc));
1.185 raeburn 1446: }
1447: }
1448: if ($authmsg) {
1449: $r->print(<<ENDAUTH);
1450: $fixedauth
1451: $authmsg
1452: $varauth
1453: ENDAUTH
1454: }
1455: } else {
1.190 raeburn 1456: $r->print(&Apache::lonuserutils::set_login($ccdomain,$authformkrb,$authformint,$authformloc));
1.187 raeburn 1457: }
1.427 raeburn 1458: $r->print($portfolioform.$domroleform);
1.215 raeburn 1459: if ($env{'form.action'} eq 'singlestudent') {
1460: $r->print(&date_sections_select($context,$newuser,$formname,
1.375 raeburn 1461: $permission,$crstype,$ccuname,
1462: $ccdomain,$showcredits));
1.215 raeburn 1463: }
1464: $r->print('</div><div class="LC_clear_float_footer"></div>');
1.216 raeburn 1465: } else { # user already exists
1.389 bisitz 1466: $r->print($start_page.$forminfo);
1.213 raeburn 1467: if ($env{'form.action'} eq 'singlestudent') {
1.318 raeburn 1468: if ($crstype eq 'Community') {
1.389 bisitz 1469: $title = &mt('Enroll one member: [_1] in domain [_2]',
1470: '"'.$ccuname.'"','"'.$ccdomain.'"');
1.318 raeburn 1471: } else {
1.389 bisitz 1472: $title = &mt('Enroll one student: [_1] in domain [_2]',
1473: '"'.$ccuname.'"','"'.$ccdomain.'"');
1.318 raeburn 1474: }
1.213 raeburn 1475: } else {
1.418 raeburn 1476: if ($permission->{'cusr'}) {
1477: $title = &mt('Modify existing user: [_1] in domain [_2]',
1478: '"'.$ccuname.'"','"'.$ccdomain.'"');
1479: } else {
1480: $title = &mt('Existing user: [_1] in domain [_2]',
1.389 bisitz 1481: '"'.$ccuname.'"','"'.$ccdomain.'"');
1.418 raeburn 1482: }
1.213 raeburn 1483: }
1.389 bisitz 1484: $r->print('<h2>'.$title.'</h2>'."\n");
1485: $r->print('<div class="LC_left_float">');
1.393 raeburn 1486: $r->print(&personal_data_display($ccuname,$ccdomain,$newuser,$context,
1487: $inst_results{$ccuname.':'.$ccdomain}));
1.430 raeburn 1488: if ((&Apache::lonnet::allowed('ccc',$env{'request.role.domain'})) ||
1.418 raeburn 1489: (&Apache::lonnet::allowed('udp',$env{'request.role.domain'}))) {
1.450 raeburn 1490: $r->print('<br /><h3>'.&mt('User Can Request Creation of Courses/Communities in this Domain?').'</h3>'."\n");
1491: if (($env{'request.role.domain'} eq $ccdomain) ||
1492: (&Apache::lonnet::will_trust('reqcrs',$ccdomain,$env{'request.role.domain'}))) {
1493: $r->print(&Apache::loncommon::start_data_table());
1494: if ($env{'request.role.domain'} eq $ccdomain) {
1495: $r->print(&build_tools_display($ccuname,$ccdomain,'requestcourses'));
1496: } else {
1.444 raeburn 1497: $r->print(&coursereq_externaluser($ccuname,$ccdomain,
1498: $env{'request.role.domain'}));
1499: }
1.450 raeburn 1500: $r->print(&Apache::loncommon::end_data_table());
1501: } else {
1502: $r->print(&mt('Domain configuration for this domain prohibits course creation by users from domain: "[_1]"',
1503: &Apache::lonnet::domain($ccdomain,'description')));
1.300 raeburn 1504: }
1.275 raeburn 1505: }
1.199 raeburn 1506: $r->print('</div>');
1.427 raeburn 1507: my @order = ('auth','quota','tools','requestauthor');
1.362 raeburn 1508: my %user_text;
1509: my ($isadv,$isauthor) =
1.418 raeburn 1510: &Apache::lonnet::is_advanced_user($ccdomain,$ccuname);
1.362 raeburn 1511: if ((!$isauthor) &&
1.418 raeburn 1512: ((&Apache::lonnet::allowed('cau',$env{'request.role.domain'})) ||
1513: (&Apache::lonnet::allowed('udp',$env{'request.role.domain'}))) &&
1.430 raeburn 1514: ($env{'request.role.domain'} eq $ccdomain)) {
1.362 raeburn 1515: $user_text{'requestauthor'} = &domainrole_req($ccuname,$ccdomain);
1516: }
1.451 raeburn 1517: $user_text{'auth'} = &user_authentication($ccuname,$ccdomain,$formname,$crstype,$permission);
1.267 raeburn 1518: if ((&Apache::lonnet::allowed('mpq',$ccdomain)) ||
1.418 raeburn 1519: (&Apache::lonnet::allowed('mut',$ccdomain)) ||
1520: (&Apache::lonnet::allowed('udp',$ccdomain))) {
1.188 raeburn 1521: # Current user has quota modification privileges
1.378 raeburn 1522: $user_text{'quota'} = &user_quotas($ccuname,$ccdomain);
1.267 raeburn 1523: }
1524: if (!&Apache::lonnet::allowed('mpq',$ccdomain)) {
1525: if (&Apache::lonnet::allowed('mpq',$env{'request.role.domain'})) {
1526: my %lt=&Apache::lonlocal::texthash(
1.385 bisitz 1527: 'dska' => "Disk quotas for user's portfolio and Authoring Space",
1528: 'youd' => "You do not have privileges to modify the portfolio and/or Authoring Space quotas for this user.",
1.267 raeburn 1529: 'ichr' => "If a change is required, contact a domain coordinator for the domain",
1530: );
1.362 raeburn 1531: $user_text{'quota'} = <<ENDNOPORTPRIV;
1.188 raeburn 1532: <h3>$lt{'dska'}</h3>
1533: $lt{'youd'} $lt{'ichr'}: $ccdomain
1534: ENDNOPORTPRIV
1.267 raeburn 1535: }
1536: }
1537: if (!&Apache::lonnet::allowed('mut',$ccdomain)) {
1538: if (&Apache::lonnet::allowed('mut',$env{'request.role.domain'})) {
1539: my %lt=&Apache::lonlocal::texthash(
1540: 'utav' => "User Tools Availability",
1.361 raeburn 1541: 'yodo' => "You do not have privileges to modify Portfolio, Blog, WebDAV, or Personal Information Page settings for this user.",
1.267 raeburn 1542: 'ifch' => "If a change is required, contact a domain coordinator for the domain",
1543: );
1.362 raeburn 1544: $user_text{'tools'} = <<ENDNOTOOLSPRIV;
1.267 raeburn 1545: <h3>$lt{'utav'}</h3>
1546: $lt{'yodo'} $lt{'ifch'}: $ccdomain
1547: ENDNOTOOLSPRIV
1548: }
1.188 raeburn 1549: }
1.362 raeburn 1550: my $gotdiv = 0;
1551: foreach my $item (@order) {
1552: if ($user_text{$item} ne '') {
1553: unless ($gotdiv) {
1554: $r->print('<div class="LC_left_float">');
1555: $gotdiv = 1;
1556: }
1557: $r->print('<br />'.$user_text{$item});
1558: }
1559: }
1560: if ($env{'form.action'} eq 'singlestudent') {
1561: unless ($gotdiv) {
1562: $r->print('<div class="LC_left_float">');
1.213 raeburn 1563: }
1.375 raeburn 1564: my $credits;
1565: if ($showcredits) {
1566: $credits = &get_user_credits($ccuname,$ccdomain,$defaultcredits);
1567: if ($credits eq '') {
1568: $credits = $defaultcredits;
1569: }
1570: }
1.374 raeburn 1571: $r->print(&date_sections_select($context,$newuser,$formname,
1.375 raeburn 1572: $permission,$crstype,$ccuname,
1573: $ccdomain,$showcredits));
1.374 raeburn 1574: }
1.362 raeburn 1575: if ($gotdiv) {
1576: $r->print('</div><div class="LC_clear_float_footer"></div>');
1.188 raeburn 1577: }
1.418 raeburn 1578: my $statuses;
1579: if (($context eq 'domain') && (&Apache::lonnet::allowed('udp',$ccdomain)) &&
1580: (!&Apache::lonnet::allowed('mau',$ccdomain))) {
1581: $statuses = ['active'];
1582: } elsif (($context eq 'course') && ((&Apache::lonnet::allowed('vcl',$env{'request.course.id'})) ||
1583: ($env{'request.course.sec'} &&
1584: &Apache::lonnet::allowed('vcl',$env{'request.course.id'}.'/'.$env{'request.course.sec'})))) {
1.430 raeburn 1585: $statuses = ['active'];
1.418 raeburn 1586: }
1.217 raeburn 1587: if ($env{'form.action'} ne 'singlestudent') {
1.329 raeburn 1588: &display_existing_roles($r,$ccuname,$ccdomain,\%inccourses,$context,
1.418 raeburn 1589: $roledom,$crstype,$showcredits,$statuses);
1.217 raeburn 1590: }
1.25 matthew 1591: } ## End of new user/old user logic
1.218 raeburn 1592: if ($env{'form.action'} eq 'singlestudent') {
1.318 raeburn 1593: my $btntxt;
1594: if ($crstype eq 'Community') {
1595: $btntxt = &mt('Enroll Member');
1596: } else {
1597: $btntxt = &mt('Enroll Student');
1598: }
1599: $r->print('<br /><input type="button" value="'.$btntxt.'" onclick="setSections(this.form)" />'."\n");
1.418 raeburn 1600: } elsif ($permission->{'cusr'}) {
1.393 raeburn 1601: $r->print('<div class="LC_left_float">'.
1602: '<fieldset><legend>'.&mt('Add Roles').'</legend>');
1.218 raeburn 1603: my $addrolesdisplay = 0;
1604: if ($context eq 'domain' || $context eq 'author') {
1605: $addrolesdisplay = &new_coauthor_roles($r,$ccuname,$ccdomain);
1606: }
1607: if ($context eq 'domain') {
1.357 raeburn 1608: my $add_domainroles = &new_domain_roles($r,$ccdomain);
1.218 raeburn 1609: if (!$addrolesdisplay) {
1610: $addrolesdisplay = $add_domainroles;
1.2 www 1611: }
1.375 raeburn 1612: $r->print(&course_level_dc($env{'request.role.domain'},$showcredits));
1.393 raeburn 1613: $r->print('</fieldset></div><div class="LC_clear_float_footer"></div>'.
1614: '<br /><input type="button" value="'.&mt('Save').'" onclick="setCourse()" />'."\n");
1.218 raeburn 1615: } elsif ($context eq 'author') {
1616: if ($addrolesdisplay) {
1.393 raeburn 1617: $r->print('</fieldset></div><div class="LC_clear_float_footer"></div>'.
1618: '<br /><input type="button" value="'.&mt('Save').'"');
1.218 raeburn 1619: if ($newuser) {
1.301 bisitz 1620: $r->print(' onclick="auth_check()" \>'."\n");
1.218 raeburn 1621: } else {
1.461 raeburn 1622: $r->print(' onclick="this.form.submit()" \>'."\n");
1.218 raeburn 1623: }
1.188 raeburn 1624: } else {
1.393 raeburn 1625: $r->print('</fieldset></div>'.
1626: '<div class="LC_clear_float_footer"></div>'.
1627: '<br /><a href="javascript:backPage(document.cu)">'.
1.218 raeburn 1628: &mt('Back to previous page').'</a>');
1.188 raeburn 1629: }
1630: } else {
1.375 raeburn 1631: $r->print(&course_level_table(\%inccourses,$showcredits,$defaultcredits));
1.393 raeburn 1632: $r->print('</fieldset></div><div class="LC_clear_float_footer"></div>'.
1633: '<br /><input type="button" value="'.&mt('Save').'" onclick="setSections(this.form)" />'."\n");
1.188 raeburn 1634: }
1.88 raeburn 1635: }
1.188 raeburn 1636: $r->print(&Apache::lonhtmlcommon::echo_form_input(['phase','userrole','ccdomain','prevphase','currstate','ccuname','ccdomain']));
1.179 raeburn 1637: $r->print('<input type="hidden" name="currstate" value="" />');
1.393 raeburn 1638: $r->print('<input type="hidden" name="prevphase" value="'.$env{'form.phase'}.'" /></form><br /><br />');
1.218 raeburn 1639: return;
1.2 www 1640: }
1.1 www 1641:
1.213 raeburn 1642: sub singleuser_breadcrumb {
1.422 raeburn 1643: my ($crstype,$context,$domain) = @_;
1.213 raeburn 1644: my %breadcrumb_text;
1645: if ($env{'form.action'} eq 'singlestudent') {
1.318 raeburn 1646: if ($crstype eq 'Community') {
1647: $breadcrumb_text{'search'} = 'Enroll a member';
1648: } else {
1649: $breadcrumb_text{'search'} = 'Enroll a student';
1650: }
1.422 raeburn 1651: $breadcrumb_text{'userpicked'} = 'Select a user';
1652: $breadcrumb_text{'modify'} = 'Set section/dates';
1.416 raeburn 1653: } elsif ($env{'form.action'} eq 'accesslogs') {
1654: $breadcrumb_text{'search'} = 'View access logs for a user';
1.422 raeburn 1655: $breadcrumb_text{'userpicked'} = 'Select a user';
1656: $breadcrumb_text{'activity'} = 'Activity';
1657: } elsif (($env{'form.action'} eq 'singleuser') && ($context eq 'domain') &&
1658: (!&Apache::lonnet::allowed('mau',$domain))) {
1659: $breadcrumb_text{'search'} = "View user's roles";
1660: $breadcrumb_text{'userpicked'} = 'Select a user';
1661: $breadcrumb_text{'modify'} = 'User roles';
1.213 raeburn 1662: } else {
1.229 raeburn 1663: $breadcrumb_text{'search'} = 'Create/modify a user';
1.422 raeburn 1664: $breadcrumb_text{'userpicked'} = 'Select a user';
1665: $breadcrumb_text{'modify'} = 'Set user role';
1.213 raeburn 1666: }
1667: return %breadcrumb_text;
1668: }
1669:
1670: sub date_sections_select {
1.375 raeburn 1671: my ($context,$newuser,$formname,$permission,$crstype,$ccuname,$ccdomain,
1672: $showcredits) = @_;
1673: my $credits;
1674: if ($showcredits) {
1675: my $defaultcredits = &Apache::lonuserutils::get_defaultcredits();
1676: $credits = &get_user_credits($ccuname,$ccdomain,$defaultcredits);
1677: if ($credits eq '') {
1678: $credits = $defaultcredits;
1679: }
1680: }
1.213 raeburn 1681: my $cid = $env{'request.course.id'};
1682: my ($cnum,$cdom) = &Apache::lonuserutils::get_course_identity($cid);
1683: my $date_table = '<h3>'.&mt('Starting and Ending Dates').'</h3>'."\n".
1684: &Apache::lonuserutils::date_setting_table(undef,undef,$context,
1685: undef,$formname,$permission);
1686: my $rowtitle = 'Section';
1.375 raeburn 1687: my $secbox = '<h3>'.&mt('Section and Credits').'</h3>'."\n".
1.213 raeburn 1688: &Apache::lonuserutils::section_picker($cdom,$cnum,'st',$rowtitle,
1.375 raeburn 1689: $permission,$context,'',$crstype,
1690: $showcredits,$credits);
1.213 raeburn 1691: my $output = $date_table.$secbox;
1692: return $output;
1693: }
1694:
1.216 raeburn 1695: sub validation_javascript {
1.375 raeburn 1696: my ($context,$ccdomain,$pjump_def,$crstype,$groupslist,$newuser,$formname,
1.216 raeburn 1697: $loaditem) = @_;
1698: my $dc_setcourse_code = '';
1699: my $nondc_setsection_code = '';
1700: if ($context eq 'domain') {
1701: my $dcdom = $env{'request.role.domain'};
1702: $loaditem->{'onload'} = "document.cu.coursedesc.value='';";
1.227 raeburn 1703: $dc_setcourse_code =
1704: &Apache::lonuserutils::dc_setcourse_js('cu','singleuser',$context);
1.216 raeburn 1705: } else {
1.227 raeburn 1706: my $checkauth;
1707: if (($newuser) || (&Apache::lonnet::allowed('mau',$ccdomain))) {
1708: $checkauth = 1;
1709: }
1710: if ($context eq 'course') {
1711: $nondc_setsection_code =
1712: &Apache::lonuserutils::setsections_javascript($formname,$groupslist,
1.375 raeburn 1713: undef,$checkauth,
1714: $crstype);
1.227 raeburn 1715: }
1716: if ($checkauth) {
1717: $nondc_setsection_code .=
1718: &Apache::lonuserutils::verify_authen($formname,$context);
1719: }
1.216 raeburn 1720: }
1721: my $js = &user_modification_js($pjump_def,$dc_setcourse_code,
1722: $nondc_setsection_code,$groupslist);
1723: my ($jsback,$elements) = &crumb_utilities();
1724: $js .= "\n".
1.301 bisitz 1725: '<script type="text/javascript">'."\n".
1726: '// <![CDATA['."\n".
1727: $jsback."\n".
1728: '// ]]>'."\n".
1729: '</script>'."\n";
1.216 raeburn 1730: return $js;
1731: }
1732:
1.217 raeburn 1733: sub display_existing_roles {
1.375 raeburn 1734: my ($r,$ccuname,$ccdomain,$inccourses,$context,$roledom,$crstype,
1.418 raeburn 1735: $showcredits,$statuses) = @_;
1.329 raeburn 1736: my $now=time;
1.418 raeburn 1737: my $showall = 1;
1738: my ($showexpired,$showactive);
1739: if ((ref($statuses) eq 'ARRAY') && (@{$statuses} > 0)) {
1740: $showall = 0;
1741: if (grep(/^expired$/,@{$statuses})) {
1742: $showexpired = 1;
1743: }
1744: if (grep(/^active$/,@{$statuses})) {
1745: $showactive = 1;
1746: }
1747: if ($showexpired && $showactive) {
1748: $showall = 1;
1749: }
1750: }
1.329 raeburn 1751: my %lt=&Apache::lonlocal::texthash(
1.217 raeburn 1752: 'rer' => "Existing Roles",
1753: 'rev' => "Revoke",
1754: 'del' => "Delete",
1755: 'ren' => "Re-Enable",
1756: 'rol' => "Role",
1757: 'ext' => "Extent",
1.375 raeburn 1758: 'crd' => "Credits",
1.217 raeburn 1759: 'sta' => "Start",
1760: 'end' => "End",
1761: );
1.329 raeburn 1762: my (%rolesdump,%roletext,%sortrole,%roleclass,%rolepriv);
1763: if ($context eq 'course' || $context eq 'author') {
1764: my @roles = &Apache::lonuserutils::roles_by_context($context,1,$crstype);
1765: my %roleshash =
1766: &Apache::lonnet::get_my_roles($ccuname,$ccdomain,'userroles',
1767: ['active','previous','future'],\@roles,$roledom,1);
1768: foreach my $key (keys(%roleshash)) {
1769: my ($start,$end) = split(':',$roleshash{$key});
1770: next if ($start eq '-1' || $end eq '-1');
1771: my ($rnum,$rdom,$role,$sec) = split(':',$key);
1772: if ($context eq 'course') {
1773: next unless (($rnum eq $env{'course.'.$env{'request.course.id'}.'.num'})
1774: && ($rdom eq $env{'course.'.$env{'request.course.id'}.'.domain'}));
1775: } elsif ($context eq 'author') {
1776: next unless (($rnum eq $env{'user.name'}) && ($rdom eq $env{'request.role.domain'}));
1777: }
1778: my ($newkey,$newvalue,$newrole);
1779: $newkey = '/'.$rdom.'/'.$rnum;
1780: if ($sec ne '') {
1781: $newkey .= '/'.$sec;
1782: }
1783: $newvalue = $role;
1784: if ($role =~ /^cr/) {
1785: $newrole = 'cr';
1786: } else {
1787: $newrole = $role;
1788: }
1789: $newkey .= '_'.$newrole;
1790: if ($start ne '' && $end ne '') {
1791: $newvalue .= '_'.$end.'_'.$start;
1.335 raeburn 1792: } elsif ($end ne '') {
1793: $newvalue .= '_'.$end;
1.329 raeburn 1794: }
1795: $rolesdump{$newkey} = $newvalue;
1796: }
1797: } else {
1.360 raeburn 1798: %rolesdump=&Apache::lonnet::dump('roles',$ccdomain,$ccuname);
1.329 raeburn 1799: }
1800: # Build up table of user roles to allow revocation and re-enabling of roles.
1801: my ($tmp) = keys(%rolesdump);
1802: return if ($tmp =~ /^(con_lost|error)/i);
1803: foreach my $area (sort { my $a1=join('_',(split('_',$a))[1,0]);
1804: my $b1=join('_',(split('_',$b))[1,0]);
1805: return $a1 cmp $b1;
1806: } keys(%rolesdump)) {
1807: next if ($area =~ /^rolesdef/);
1808: my $envkey=$area;
1809: my $role = $rolesdump{$area};
1810: my $thisrole=$area;
1811: $area =~ s/\_\w\w$//;
1812: my ($role_code,$role_end_time,$role_start_time) =
1813: split(/_/,$role);
1.418 raeburn 1814: my $active=1;
1815: $active=0 if (($role_end_time) && ($now>$role_end_time));
1816: if ($active) {
1817: next unless($showall || $showactive);
1818: } else {
1.430 raeburn 1819: next unless($showall || $showexpired);
1.418 raeburn 1820: }
1.217 raeburn 1821: # Is this a custom role? Get role owner and title.
1.329 raeburn 1822: my ($croleudom,$croleuname,$croletitle)=
1823: ($role_code=~m{^cr/($match_domain)/($match_username)/(\w+)$});
1824: my $allowed=0;
1825: my $delallowed=0;
1826: my $sortkey=$role_code;
1827: my $class='Unknown';
1.375 raeburn 1828: my $credits='';
1.418 raeburn 1829: my $csec;
1.421 raeburn 1830: if ($area =~ m{^/($match_domain)/($match_courseid)}) {
1.329 raeburn 1831: $class='Course';
1832: my ($coursedom,$coursedir) = ($1,$2);
1833: my $cid = $1.'_'.$2;
1834: # $1.'_'.$2 is the course id (eg. 103_12345abcef103l3).
1.421 raeburn 1835: next if ($envkey =~ m{^/$match_domain/$match_courseid/[A-Za-z0-9]+_gr$});
1.329 raeburn 1836: my %coursedata=
1837: &Apache::lonnet::coursedescription($cid);
1838: if ($coursedir =~ /^$match_community$/) {
1839: $class='Community';
1840: }
1841: $sortkey.="\0$coursedom";
1842: my $carea;
1843: if (defined($coursedata{'description'})) {
1844: $carea=$coursedata{'description'}.
1845: '<br />'.&mt('Domain').': '.$coursedom.(' 'x8).
1846: &Apache::loncommon::syllabuswrapper(&mt('Syllabus'),$coursedir,$coursedom);
1847: $sortkey.="\0".$coursedata{'description'};
1848: } else {
1849: if ($class eq 'Community') {
1850: $carea=&mt('Unavailable community').': '.$area;
1851: $sortkey.="\0".&mt('Unavailable community').': '.$area;
1.217 raeburn 1852: } else {
1853: $carea=&mt('Unavailable course').': '.$area;
1854: $sortkey.="\0".&mt('Unavailable course').': '.$area;
1855: }
1.329 raeburn 1856: }
1857: $sortkey.="\0$coursedir";
1858: $inccourses->{$cid}=1;
1.375 raeburn 1859: if (($showcredits) && ($class eq 'Course') && ($role_code eq 'st')) {
1860: my $defaultcredits = $coursedata{'internal.defaultcredits'};
1861: $credits =
1862: &get_user_credits($ccuname,$ccdomain,$defaultcredits,
1863: $coursedom,$coursedir);
1864: if ($credits eq '') {
1865: $credits = $defaultcredits;
1866: }
1867: }
1.329 raeburn 1868: if ((&Apache::lonnet::allowed('c'.$role_code,$coursedom.'/'.$coursedir)) ||
1869: (&Apache::lonnet::allowed('c'.$role_code,$ccdomain))) {
1870: $allowed=1;
1871: }
1872: unless ($allowed) {
1.365 raeburn 1873: my $isowner = &Apache::lonuserutils::is_courseowner($cid,$coursedata{'internal.courseowner'});
1.329 raeburn 1874: if ($isowner) {
1875: if (($role_code eq 'co') && ($class eq 'Community')) {
1876: $allowed = 1;
1877: } elsif (($role_code eq 'cc') && ($class eq 'Course')) {
1878: $allowed = 1;
1879: }
1.217 raeburn 1880: }
1.329 raeburn 1881: }
1882: if ((&Apache::lonnet::allowed('dro',$coursedom)) ||
1883: (&Apache::lonnet::allowed('dro',$ccdomain))) {
1884: $delallowed=1;
1885: }
1.217 raeburn 1886: # - custom role. Needs more info, too
1.329 raeburn 1887: if ($croletitle) {
1888: if (&Apache::lonnet::allowed('ccr',$coursedom.'/'.$coursedir)) {
1889: $allowed=1;
1890: $thisrole.='.'.$role_code;
1.217 raeburn 1891: }
1.329 raeburn 1892: }
1.418 raeburn 1893: if ($area=~m{^/($match_domain/$match_courseid/(\w+))}) {
1894: $csec = $2;
1895: $carea.='<br />'.&mt('Section: [_1]',$csec);
1896: $sortkey.="\0$csec";
1.329 raeburn 1897: if (!$allowed) {
1.418 raeburn 1898: if ($env{'request.course.sec'} eq $csec) {
1899: if (&Apache::lonnet::allowed('c'.$role_code,$1)) {
1.329 raeburn 1900: $allowed = 1;
1.217 raeburn 1901: }
1902: }
1903: }
1.329 raeburn 1904: }
1905: $area=$carea;
1906: } else {
1907: $sortkey.="\0".$area;
1908: # Determine if current user is able to revoke privileges
1909: if ($area=~m{^/($match_domain)/}) {
1910: if ((&Apache::lonnet::allowed('c'.$role_code,$1)) ||
1911: (&Apache::lonnet::allowed('c'.$role_code,$ccdomain))) {
1912: $allowed=1;
1.217 raeburn 1913: }
1.329 raeburn 1914: if (((&Apache::lonnet::allowed('dro',$1)) ||
1915: (&Apache::lonnet::allowed('dro',$ccdomain))) &&
1916: ($role_code ne 'dc')) {
1917: $delallowed=1;
1.217 raeburn 1918: }
1.329 raeburn 1919: } else {
1920: if (&Apache::lonnet::allowed('c'.$role_code,'/')) {
1.217 raeburn 1921: $allowed=1;
1922: }
1923: }
1.363 raeburn 1924: if ($role_code eq 'ca' || $role_code eq 'au' || $role_code eq 'aa') {
1.377 raeburn 1925: $class='Authoring Space';
1.329 raeburn 1926: } elsif ($role_code eq 'su') {
1927: $class='System';
1.217 raeburn 1928: } else {
1.329 raeburn 1929: $class='Domain';
1.217 raeburn 1930: }
1.329 raeburn 1931: }
1932: if (($role_code eq 'ca') || ($role_code eq 'aa')) {
1933: $area=~m{/($match_domain)/($match_username)};
1934: if (&Apache::lonuserutils::authorpriv($2,$1)) {
1935: $allowed=1;
1.217 raeburn 1936: } else {
1.329 raeburn 1937: $allowed=0;
1.217 raeburn 1938: }
1.329 raeburn 1939: }
1940: my $row = '';
1.418 raeburn 1941: if ($showall) {
1942: $row.= '<td>';
1943: if (($active) && ($allowed)) {
1944: $row.= '<input type="checkbox" name="rev:'.$thisrole.'" />';
1945: } else {
1946: if ($active) {
1947: $row.=' ';
1948: } else {
1949: $row.=&mt('expired or revoked');
1950: }
1951: }
1952: $row.='</td><td>';
1953: if ($allowed && !$active) {
1954: $row.= '<input type="checkbox" name="ren:'.$thisrole.'" />';
1955: } else {
1956: $row.=' ';
1957: }
1958: $row.='</td><td>';
1959: if ($delallowed) {
1960: $row.= '<input type="checkbox" name="del:'.$thisrole.'" />';
1.217 raeburn 1961: } else {
1.418 raeburn 1962: $row.=' ';
1.217 raeburn 1963: }
1.430 raeburn 1964: $row.= '</td>';
1.329 raeburn 1965: }
1966: my $plaintext='';
1967: if (!$croletitle) {
1.375 raeburn 1968: $plaintext=&Apache::lonnet::plaintext($role_code,$class);
1969: if (($showcredits) && ($credits ne '')) {
1970: $plaintext .= '<br/ ><span class="LC_nobreak">'.
1971: '<span class="LC_fontsize_small">'.
1972: &mt('Credits: [_1]',$credits).
1973: '</span></span>';
1974: }
1.329 raeburn 1975: } else {
1976: $plaintext=
1.395 bisitz 1977: &mt('Custom role [_1][_2]defined by [_3]',
1.346 bisitz 1978: '"'.$croletitle.'"',
1979: '<br />',
1980: $croleuname.':'.$croleudom);
1.329 raeburn 1981: }
1.418 raeburn 1982: $row.= '<td>'.$plaintext.'</td>'.
1983: '<td>'.$area.'</td>'.
1984: '<td>'.($role_start_time?&Apache::lonlocal::locallocaltime($role_start_time)
1985: : ' ' ).'</td>'.
1986: '<td>'.($role_end_time ?&Apache::lonlocal::locallocaltime($role_end_time)
1987: : ' ' ).'</td>';
1.329 raeburn 1988: $sortrole{$sortkey}=$envkey;
1989: $roletext{$envkey}=$row;
1990: $roleclass{$envkey}=$class;
1.418 raeburn 1991: if ($allowed) {
1992: $rolepriv{$envkey}='edit';
1993: } else {
1994: if ($context eq 'domain') {
1.420 raeburn 1995: if ((&Apache::lonnet::allowed('vur',$ccdomain)) &&
1.421 raeburn 1996: ($envkey=~m{^/$ccdomain/})) {
1.418 raeburn 1997: $rolepriv{$envkey}='view';
1998: }
1999: } elsif ($context eq 'course') {
2000: if ((&Apache::lonnet::allowed('vcl',$env{'request.course.id'})) ||
2001: ($env{'request.course.sec'} && ($env{'request.course.sec'} eq $csec) &&
2002: &Apache::lonnet::allowed('vcl',$env{'request.course.id'}.'/'.$env{'request.course.sec'}))) {
2003: $rolepriv{$envkey}='view';
2004: }
2005: }
2006: }
1.329 raeburn 2007: } # end of foreach (table building loop)
2008:
2009: my $rolesdisplay = 0;
2010: my %output = ();
1.377 raeburn 2011: foreach my $type ('Authoring Space','Course','Community','Domain','System','Unknown') {
1.329 raeburn 2012: $output{$type} = '';
2013: foreach my $which (sort {uc($a) cmp uc($b)} (keys(%sortrole))) {
2014: if ( ($roleclass{$sortrole{$which}} =~ /^\Q$type\E/ ) && ($rolepriv{$sortrole{$which}}) ) {
2015: $output{$type}.=
2016: &Apache::loncommon::start_data_table_row().
2017: $roletext{$sortrole{$which}}.
2018: &Apache::loncommon::end_data_table_row();
1.217 raeburn 2019: }
1.329 raeburn 2020: }
2021: unless($output{$type} eq '') {
2022: $output{$type} = '<tr class="LC_info_row">'.
2023: "<td align='center' colspan='7'>".&mt($type)."</td></tr>".
2024: $output{$type};
2025: $rolesdisplay = 1;
2026: }
2027: }
2028: if ($rolesdisplay == 1) {
2029: my $contextrole='';
2030: if ($env{'request.course.id'}) {
2031: if (&Apache::loncommon::course_type() eq 'Community') {
2032: $contextrole = &mt('Existing Roles in this Community');
1.290 bisitz 2033: } else {
1.329 raeburn 2034: $contextrole = &mt('Existing Roles in this Course');
1.290 bisitz 2035: }
1.329 raeburn 2036: } elsif ($env{'request.role'} =~ /^au\./) {
1.377 raeburn 2037: $contextrole = &mt('Existing Co-Author Roles in your Authoring Space');
1.329 raeburn 2038: } else {
1.418 raeburn 2039: if ($showall) {
2040: $contextrole = &mt('Existing Roles in this Domain');
2041: } elsif ($showactive) {
2042: $contextrole = &mt('Unexpired Roles in this Domain');
2043: } elsif ($showexpired) {
2044: $contextrole = &mt('Expired or Revoked Roles in this Domain');
2045: }
1.329 raeburn 2046: }
1.393 raeburn 2047: $r->print('<div class="LC_left_float">'.
1.375 raeburn 2048: '<fieldset><legend>'.$contextrole.'</legend>'.
1.217 raeburn 2049: &Apache::loncommon::start_data_table("LC_createuser").
1.418 raeburn 2050: &Apache::loncommon::start_data_table_header_row());
2051: if ($showall) {
2052: $r->print(
1.419 raeburn 2053: '<th>'.$lt{'rev'}.'</th><th>'.$lt{'ren'}.'</th><th>'.$lt{'del'}.'</th>'
1.418 raeburn 2054: );
2055: } elsif ($showexpired) {
2056: $r->print('<th>'.$lt{'rev'}.'</th>');
2057: }
2058: $r->print(
1.419 raeburn 2059: '<th>'.$lt{'rol'}.'</th><th>'.$lt{'ext'}.'</th>'.
2060: '<th>'.$lt{'sta'}.'</th><th>'.$lt{'end'}.'</th>'.
1.217 raeburn 2061: &Apache::loncommon::end_data_table_header_row());
1.377 raeburn 2062: foreach my $type ('Authoring Space','Course','Community','Domain','System','Unknown') {
1.329 raeburn 2063: if ($output{$type}) {
2064: $r->print($output{$type}."\n");
1.217 raeburn 2065: }
2066: }
1.375 raeburn 2067: $r->print(&Apache::loncommon::end_data_table().
2068: '</fieldset></div>');
1.329 raeburn 2069: }
1.217 raeburn 2070: return;
2071: }
2072:
1.218 raeburn 2073: sub new_coauthor_roles {
2074: my ($r,$ccuname,$ccdomain) = @_;
2075: my $addrolesdisplay = 0;
2076: #
2077: # Co-Author
2078: #
2079: if (&Apache::lonuserutils::authorpriv($env{'user.name'},
2080: $env{'request.role.domain'}) &&
2081: ($env{'user.name'} ne $ccuname || $env{'user.domain'} ne $ccdomain)) {
2082: # No sense in assigning co-author role to yourself
2083: $addrolesdisplay = 1;
2084: my $cuname=$env{'user.name'};
2085: my $cudom=$env{'request.role.domain'};
2086: my %lt=&Apache::lonlocal::texthash(
1.377 raeburn 2087: 'cs' => "Authoring Space",
1.218 raeburn 2088: 'act' => "Activate",
2089: 'rol' => "Role",
2090: 'ext' => "Extent",
2091: 'sta' => "Start",
2092: 'end' => "End",
2093: 'cau' => "Co-Author",
2094: 'caa' => "Assistant Co-Author",
2095: 'ssd' => "Set Start Date",
2096: 'sed' => "Set End Date"
2097: );
2098: $r->print('<h4>'.$lt{'cs'}.'</h4>'."\n".
2099: &Apache::loncommon::start_data_table()."\n".
2100: &Apache::loncommon::start_data_table_header_row()."\n".
2101: '<th>'.$lt{'act'}.'</th><th>'.$lt{'rol'}.'</th>'.
2102: '<th>'.$lt{'ext'}.'</th><th>'.$lt{'sta'}.'</th>'.
2103: '<th>'.$lt{'end'}.'</th>'."\n".
2104: &Apache::loncommon::end_data_table_header_row()."\n".
2105: &Apache::loncommon::start_data_table_row().'
2106: <td>
1.291 bisitz 2107: <input type="checkbox" name="act_'.$cudom.'_'.$cuname.'_ca" />
1.218 raeburn 2108: </td>
2109: <td>'.$lt{'cau'}.'</td>
2110: <td>'.$cudom.'_'.$cuname.'</td>
2111: <td><input type="hidden" name="start_'.$cudom.'_'.$cuname.'_ca" value="" />
2112: <a href=
2113: "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>
2114: <td><input type="hidden" name="end_'.$cudom.'_'.$cuname.'_ca" value="" />
2115: <a href=
2116: "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".
2117: &Apache::loncommon::end_data_table_row()."\n".
2118: &Apache::loncommon::start_data_table_row()."\n".
1.291 bisitz 2119: '<td><input type="checkbox" name="act_'.$cudom.'_'.$cuname.'_aa" /></td>
1.218 raeburn 2120: <td>'.$lt{'caa'}.'</td>
2121: <td>'.$cudom.'_'.$cuname.'</td>
2122: <td><input type="hidden" name="start_'.$cudom.'_'.$cuname.'_aa" value="" />
2123: <a href=
2124: "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>
2125: <td><input type="hidden" name="end_'.$cudom.'_'.$cuname.'_aa" value="" />
2126: <a href=
2127: "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".
2128: &Apache::loncommon::end_data_table_row()."\n".
2129: &Apache::loncommon::end_data_table());
2130: } elsif ($env{'request.role'} =~ /^au\./) {
2131: if (!(&Apache::lonuserutils::authorpriv($env{'user.name'},
2132: $env{'request.role.domain'}))) {
2133: $r->print('<span class="LC_error">'.
2134: &mt('You do not have privileges to assign co-author roles.').
2135: '</span>');
2136: } elsif (($env{'user.name'} eq $ccuname) &&
2137: ($env{'user.domain'} eq $ccdomain)) {
1.377 raeburn 2138: $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 2139: }
2140: }
2141: return $addrolesdisplay;;
2142: }
2143:
2144: sub new_domain_roles {
1.357 raeburn 2145: my ($r,$ccdomain) = @_;
1.218 raeburn 2146: my $addrolesdisplay = 0;
2147: #
2148: # Domain level
2149: #
2150: my $num_domain_level = 0;
2151: my $domaintext =
2152: '<h4>'.&mt('Domain Level').'</h4>'.
2153: &Apache::loncommon::start_data_table().
2154: &Apache::loncommon::start_data_table_header_row().
2155: '<th>'.&mt('Activate').'</th><th>'.&mt('Role').'</th><th>'.
2156: &mt('Extent').'</th>'.
2157: '<th>'.&mt('Start').'</th><th>'.&mt('End').'</th>'.
2158: &Apache::loncommon::end_data_table_header_row();
1.312 raeburn 2159: my @allroles = &Apache::lonuserutils::roles_by_context('domain');
1.445 raeburn 2160: my $uprimary = &Apache::lonnet::domain($env{'request.role.domain'},'primary');
2161: my $uintdom = &Apache::lonnet::internet_dom($uprimary);
1.218 raeburn 2162: foreach my $thisdomain (sort(&Apache::lonnet::all_domains())) {
1.312 raeburn 2163: foreach my $role (@allroles) {
2164: next if ($role eq 'ad');
1.357 raeburn 2165: next if (($role eq 'au') && ($ccdomain ne $thisdomain));
1.218 raeburn 2166: if (&Apache::lonnet::allowed('c'.$role,$thisdomain)) {
1.445 raeburn 2167: if ($role eq 'dc') {
2168: unless ($thisdomain eq $env{'request.role.domain'}) {
2169: my $domprim = &Apache::lonnet::domain($thisdomain,'primary');
2170: my $intdom = &Apache::lonnet::internet_dom($domprim);
2171: next unless ($uintdom eq $intdom);
2172: }
2173: }
1.218 raeburn 2174: my $plrole=&Apache::lonnet::plaintext($role);
2175: my %lt=&Apache::lonlocal::texthash(
2176: 'ssd' => "Set Start Date",
2177: 'sed' => "Set End Date"
2178: );
2179: $num_domain_level ++;
2180: $domaintext .=
2181: &Apache::loncommon::start_data_table_row().
1.291 bisitz 2182: '<td><input type="checkbox" name="act_'.$thisdomain.'_'.$role.'" /></td>
1.218 raeburn 2183: <td>'.$plrole.'</td>
2184: <td>'.$thisdomain.'</td>
2185: <td><input type="hidden" name="start_'.$thisdomain.'_'.$role.'" value="" />
2186: <a href=
2187: "javascript:pjump('."'date_start','Start Date $plrole',document.cu.start_$thisdomain\_$role.value,'start_$thisdomain\_$role','cu.pres','dateset'".')">'.$lt{'ssd'}.'</a></td>
2188: <td><input type="hidden" name="end_'.$thisdomain.'_'.$role.'" value="" />
2189: <a href=
2190: "javascript:pjump('."'date_end','End Date $plrole',document.cu.end_$thisdomain\_$role.value,'end_$thisdomain\_$role','cu.pres','dateset'".')">'.$lt{'sed'}.'</a></td>'.
2191: &Apache::loncommon::end_data_table_row();
2192: }
2193: }
2194: }
2195: $domaintext.= &Apache::loncommon::end_data_table();
2196: if ($num_domain_level > 0) {
2197: $r->print($domaintext);
2198: $addrolesdisplay = 1;
2199: }
2200: return $addrolesdisplay;
2201: }
2202:
1.188 raeburn 2203: sub user_authentication {
1.451 raeburn 2204: my ($ccuname,$ccdomain,$formname,$crstype,$permission) = @_;
1.188 raeburn 2205: my $currentauth=&Apache::lonnet::queryauthenticate($ccuname,$ccdomain);
1.227 raeburn 2206: my $outcome;
1.418 raeburn 2207: my %lt=&Apache::lonlocal::texthash(
2208: 'err' => "ERROR",
2209: 'uuas' => "This user has an unrecognized authentication scheme",
2210: 'adcs' => "Please alert a domain coordinator of this situation",
2211: 'sldb' => "Please specify login data below",
2212: 'ld' => "Login Data"
2213: );
1.188 raeburn 2214: # Check for a bad authentication type
1.449 raeburn 2215: if ($currentauth !~ /^(krb4|krb5|unix|internal|localauth|lti):/) {
1.188 raeburn 2216: # bad authentication scheme
2217: if (&Apache::lonnet::allowed('mau',$ccdomain)) {
1.227 raeburn 2218: &initialize_authen_forms($ccdomain,$formname);
2219:
1.190 raeburn 2220: my $choices = &Apache::lonuserutils::set_login($ccdomain,$authformkrb,$authformint,$authformloc);
1.188 raeburn 2221: $outcome = <<ENDBADAUTH;
2222: <script type="text/javascript" language="Javascript">
1.301 bisitz 2223: // <![CDATA[
1.188 raeburn 2224: $loginscript
1.301 bisitz 2225: // ]]>
1.188 raeburn 2226: </script>
2227: <span class="LC_error">$lt{'err'}:
2228: $lt{'uuas'} ($currentauth). $lt{'sldb'}.</span>
2229: <h3>$lt{'ld'}</h3>
2230: $choices
2231: ENDBADAUTH
2232: } else {
2233: # This user is not allowed to modify the user's
2234: # authentication scheme, so just notify them of the problem
2235: $outcome = <<ENDBADAUTH;
2236: <span class="LC_error"> $lt{'err'}:
2237: $lt{'uuas'} ($currentauth). $lt{'adcs'}.
2238: </span>
2239: ENDBADAUTH
2240: }
2241: } else { # Authentication type is valid
1.418 raeburn 2242:
1.227 raeburn 2243: &initialize_authen_forms($ccdomain,$formname,$currentauth,'modifyuser');
1.205 raeburn 2244: my ($authformcurrent,$can_modify,@authform_others) =
1.188 raeburn 2245: &modify_login_block($ccdomain,$currentauth);
2246: if (&Apache::lonnet::allowed('mau',$ccdomain)) {
2247: # Current user has login modification privileges
2248: $outcome =
2249: '<script type="text/javascript" language="Javascript">'."\n".
1.301 bisitz 2250: '// <![CDATA['."\n".
1.188 raeburn 2251: $loginscript."\n".
1.301 bisitz 2252: '// ]]>'."\n".
1.188 raeburn 2253: '</script>'."\n".
2254: '<h3>'.$lt{'ld'}.'</h3>'.
2255: &Apache::loncommon::start_data_table().
1.205 raeburn 2256: &Apache::loncommon::start_data_table_row().
1.188 raeburn 2257: '<td>'.$authformnop;
1.418 raeburn 2258: if (($can_modify) && (&Apache::lonnet::allowed('mau',$ccdomain))) {
1.188 raeburn 2259: $outcome .= '</td>'."\n".
2260: &Apache::loncommon::end_data_table_row().
2261: &Apache::loncommon::start_data_table_row().
2262: '<td>'.$authformcurrent.'</td>'.
2263: &Apache::loncommon::end_data_table_row()."\n";
2264: } else {
1.200 raeburn 2265: $outcome .= ' ('.$authformcurrent.')</td>'.
2266: &Apache::loncommon::end_data_table_row()."\n";
1.188 raeburn 2267: }
1.418 raeburn 2268: if (&Apache::lonnet::allowed('mau',$ccdomain)) {
2269: foreach my $item (@authform_others) {
2270: $outcome .= &Apache::loncommon::start_data_table_row().
2271: '<td>'.$item.'</td>'.
2272: &Apache::loncommon::end_data_table_row()."\n";
2273: }
1.188 raeburn 2274: }
1.205 raeburn 2275: $outcome .= &Apache::loncommon::end_data_table();
1.188 raeburn 2276: } else {
1.451 raeburn 2277: if (($currentauth =~ /^internal:/) &&
2278: (&Apache::lonuserutils::can_change_internalpass($ccuname,$ccdomain,$crstype,$permission))) {
2279: $outcome = <<"ENDJS";
2280: <script type="text/javascript">
2281: // <![CDATA[
2282: function togglePwd(form) {
2283: if (form.newintpwd.length) {
2284: if (document.getElementById('LC_ownersetpwd')) {
2285: for (var i=0; i<form.newintpwd.length; i++) {
2286: if (form.newintpwd[i].checked) {
2287: if (form.newintpwd[i].value == 1) {
2288: document.getElementById('LC_ownersetpwd').style.display = 'inline-block';
2289: } else {
2290: document.getElementById('LC_ownersetpwd').style.display = 'none';
2291: }
2292: }
2293: }
2294: }
2295: }
2296: }
2297: // ]]>
2298: </script>
2299: ENDJS
2300:
2301: $outcome .= '<h3>'.$lt{'ld'}.'</h3>'.
2302: &Apache::loncommon::start_data_table().
2303: &Apache::loncommon::start_data_table_row().
2304: '<td>'.&mt('Internally authenticated').'<br />'.&mt("Change user's password?").
2305: '<label><input type="radio" name="newintpwd" value="0" checked="checked" onclick="togglePwd(this.form);" />'.
2306: &mt('No').'</label>'.(' 'x2).
2307: '<label><input type="radio" name="newintpwd" value="1" onclick="togglePwd(this.form);" />'.&mt('Yes').'</label>'.
2308: '<div id="LC_ownersetpwd" style="display:none">'.
2309: ' '.&mt('Password').' <input type="password" size="15" name="intarg" value="" />'.
2310: '<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></div></td>'.
2311: &Apache::loncommon::end_data_table_row().
2312: &Apache::loncommon::end_data_table();
2313: }
1.418 raeburn 2314: if (&Apache::lonnet::allowed('udp',$ccdomain)) {
2315: # Current user has rights to view domain preferences for user's domain
2316: my $result;
2317: if ($currentauth =~ /^krb(4|5):([^:]*)$/) {
2318: my ($krbver,$krbrealm) = ($1,$2);
2319: if ($krbrealm eq '') {
2320: $result = &mt('Currently Kerberos authenticated, Version [_1].',$krbver);
2321: } else {
2322: $result = &mt('Currently Kerberos authenticated with domain [_1] Version [_2].',
1.426 raeburn 2323: $krbrealm,$krbver);
1.418 raeburn 2324: }
2325: } elsif ($currentauth =~ /^internal:/) {
2326: $result = &mt('Currently internally authenticated.');
2327: } elsif ($currentauth =~ /^localauth:/) {
2328: $result = &mt('Currently using local (institutional) authentication.');
2329: } elsif ($currentauth =~ /^unix:/) {
2330: $result = &mt('Currently Filesystem Authenticated.');
1.449 raeburn 2331: } elsif ($currentauth =~ /^lti:/) {
1.451 raeburn 2332: $result = &mt('Currently LTI authenticated.');
1.418 raeburn 2333: }
2334: $outcome = '<h3>'.$lt{'ld'}.'</h3>'.
2335: &Apache::loncommon::start_data_table().
2336: &Apache::loncommon::start_data_table_row().
2337: '<td>'.$result.'</td>'.
2338: &Apache::loncommon::end_data_table_row()."\n".
2339: &Apache::loncommon::end_data_table();
2340: } elsif (&Apache::lonnet::allowed('mau',$env{'request.role.domain'})) {
1.188 raeburn 2341: my %lt=&Apache::lonlocal::texthash(
2342: 'ccld' => "Change Current Login Data",
2343: 'yodo' => "You do not have privileges to modify the authentication configuration for this user.",
2344: 'ifch' => "If a change is required, contact a domain coordinator for the domain",
2345: );
2346: $outcome .= <<ENDNOPRIV;
2347: <h3>$lt{'ccld'}</h3>
2348: $lt{'yodo'} $lt{'ifch'}: $ccdomain
1.235 raeburn 2349: <input type="hidden" name="login" value="nochange" />
1.188 raeburn 2350: ENDNOPRIV
2351: }
2352: }
2353: } ## End of "check for bad authentication type" logic
2354: return $outcome;
2355: }
2356:
1.187 raeburn 2357: sub modify_login_block {
2358: my ($dom,$currentauth) = @_;
2359: my %domconfig = &Apache::lonnet::get_dom('configuration',['usercreation'],$dom);
2360: my ($authnum,%can_assign) =
2361: &Apache::loncommon::get_assignable_auth($dom);
1.205 raeburn 2362: my ($authformcurrent,@authform_others,$show_override_msg);
1.187 raeburn 2363: if ($currentauth=~/^krb(4|5):/) {
2364: $authformcurrent=$authformkrb;
2365: if ($can_assign{'int'}) {
1.205 raeburn 2366: push(@authform_others,$authformint);
1.187 raeburn 2367: }
2368: if ($can_assign{'loc'}) {
1.205 raeburn 2369: push(@authform_others,$authformloc);
1.187 raeburn 2370: }
1.449 raeburn 2371: if ($can_assign{'lti'}) {
2372: push(@authform_others,$authformlti);
2373: }
1.187 raeburn 2374: if (($can_assign{'krb4'}) || ($can_assign{'krb5'})) {
2375: $show_override_msg = 1;
2376: }
2377: } elsif ($currentauth=~/^internal:/) {
2378: $authformcurrent=$authformint;
2379: if (($can_assign{'krb4'}) || ($can_assign{'krb5'})) {
1.205 raeburn 2380: push(@authform_others,$authformkrb);
1.187 raeburn 2381: }
2382: if ($can_assign{'loc'}) {
1.205 raeburn 2383: push(@authform_others,$authformloc);
1.187 raeburn 2384: }
1.449 raeburn 2385: if ($can_assign{'lti'}) {
2386: push(@authform_others,$authformlti);
2387: }
1.187 raeburn 2388: if ($can_assign{'int'}) {
2389: $show_override_msg = 1;
2390: }
2391: } elsif ($currentauth=~/^unix:/) {
2392: $authformcurrent=$authformfsys;
2393: if (($can_assign{'krb4'}) || ($can_assign{'krb5'})) {
1.205 raeburn 2394: push(@authform_others,$authformkrb);
1.187 raeburn 2395: }
2396: if ($can_assign{'int'}) {
1.205 raeburn 2397: push(@authform_others,$authformint);
1.187 raeburn 2398: }
2399: if ($can_assign{'loc'}) {
1.205 raeburn 2400: push(@authform_others,$authformloc);
1.187 raeburn 2401: }
1.449 raeburn 2402: if ($can_assign{'lti'}) {
2403: push(@authform_others,$authformlti);
2404: }
1.187 raeburn 2405: if ($can_assign{'fsys'}) {
2406: $show_override_msg = 1;
2407: }
2408: } elsif ($currentauth=~/^localauth:/) {
2409: $authformcurrent=$authformloc;
2410: if (($can_assign{'krb4'}) || ($can_assign{'krb5'})) {
1.205 raeburn 2411: push(@authform_others,$authformkrb);
1.187 raeburn 2412: }
2413: if ($can_assign{'int'}) {
1.205 raeburn 2414: push(@authform_others,$authformint);
1.187 raeburn 2415: }
1.449 raeburn 2416: if ($can_assign{'lti'}) {
2417: push(@authform_others,$authformlti);
2418: }
1.187 raeburn 2419: if ($can_assign{'loc'}) {
2420: $show_override_msg = 1;
2421: }
1.449 raeburn 2422: } elsif ($currentauth=~/^lti:/) {
2423: $authformcurrent=$authformlti;
2424: if (($can_assign{'krb4'}) || ($can_assign{'krb5'})) {
2425: push(@authform_others,$authformkrb);
2426: }
2427: if ($can_assign{'int'}) {
2428: push(@authform_others,$authformint);
2429: }
2430: if ($can_assign{'loc'}) {
2431: push(@authform_others,$authformloc);
2432: }
1.187 raeburn 2433: }
2434: if ($show_override_msg) {
1.205 raeburn 2435: $authformcurrent = '<table><tr><td colspan="3">'.$authformcurrent.
2436: '</td></tr>'."\n".
2437: '<tr><td> </td>'.
2438: '<td><b>'.&mt('Currently in use').'</b></td>'.
2439: '<td align="right"><span class="LC_cusr_emph">'.
1.187 raeburn 2440: &mt('will override current values').
1.205 raeburn 2441: '</span></td></tr></table>';
1.187 raeburn 2442: }
1.205 raeburn 2443: return ($authformcurrent,$show_override_msg,@authform_others);
1.187 raeburn 2444: }
2445:
1.188 raeburn 2446: sub personal_data_display {
1.456 raeburn 2447: my ($ccuname,$ccdomain,$newuser,$context,$inst_results,$rolesarray,$now,
2448: $captchaform,$emailusername,$usertype,$usernameset,$condition,$excluded,$showsubmit) = @_;
1.388 bisitz 2449: my ($output,%userenv,%canmodify,%canmodify_status);
1.219 raeburn 2450: my @userinfo = ('firstname','middlename','lastname','generation',
2451: 'permanentemail','id');
1.252 raeburn 2452: my $rowcount = 0;
2453: my $editable = 0;
1.391 raeburn 2454: my %textboxsize = (
2455: firstname => '15',
2456: middlename => '15',
2457: lastname => '15',
2458: generation => '5',
2459: permanentemail => '25',
2460: id => '15',
2461: );
2462:
2463: my %lt=&Apache::lonlocal::texthash(
2464: 'pd' => "Personal Data",
2465: 'firstname' => "First Name",
2466: 'middlename' => "Middle Name",
2467: 'lastname' => "Last Name",
2468: 'generation' => "Generation",
2469: 'permanentemail' => "Permanent e-mail address",
2470: 'id' => "Student/Employee ID",
2471: 'lg' => "Login Data",
2472: 'inststatus' => "Affiliation",
2473: 'email' => 'E-mail address',
2474: 'valid' => 'Validation',
1.442 raeburn 2475: 'username' => 'Username',
1.391 raeburn 2476: );
2477:
2478: %canmodify_status =
1.286 raeburn 2479: &Apache::lonuserutils::can_modify_userinfo($context,$ccdomain,
2480: ['inststatus'],$rolesarray);
1.253 raeburn 2481: if (!$newuser) {
1.188 raeburn 2482: # Get the users information
2483: %userenv = &Apache::lonnet::get('environment',
2484: ['firstname','middlename','lastname','generation',
1.286 raeburn 2485: 'permanentemail','id','inststatus'],$ccdomain,$ccuname);
1.219 raeburn 2486: %canmodify =
2487: &Apache::lonuserutils::can_modify_userinfo($context,$ccdomain,
1.252 raeburn 2488: \@userinfo,$rolesarray);
1.257 raeburn 2489: } elsif ($context eq 'selfcreate') {
1.391 raeburn 2490: if ($newuser eq 'email') {
1.396 raeburn 2491: if (ref($emailusername) eq 'HASH') {
2492: if (ref($emailusername->{$usertype}) eq 'HASH') {
2493: my ($infofields,$infotitles) = &Apache::loncommon::emailusername_info();
1.442 raeburn 2494: @userinfo = ();
1.396 raeburn 2495: if ((ref($infofields) eq 'ARRAY') && (ref($infotitles) eq 'HASH')) {
2496: foreach my $field (@{$infofields}) {
2497: if ($emailusername->{$usertype}->{$field}) {
2498: push(@userinfo,$field);
2499: $canmodify{$field} = 1;
2500: unless ($textboxsize{$field}) {
2501: $textboxsize{$field} = 25;
2502: }
2503: unless ($lt{$field}) {
2504: $lt{$field} = $infotitles->{$field};
2505: }
2506: if ($emailusername->{$usertype}->{$field} eq 'required') {
2507: $lt{$field} .= '<b>*</b>';
2508: }
1.391 raeburn 2509: }
2510: }
2511: }
2512: }
2513: }
2514: } else {
2515: %canmodify = &selfcreate_canmodify($context,$ccdomain,\@userinfo,
2516: $inst_results,$rolesarray);
2517: }
1.188 raeburn 2518: }
1.391 raeburn 2519:
1.188 raeburn 2520: my $genhelp=&Apache::loncommon::help_open_topic('Generation');
2521: $output = '<h3>'.$lt{'pd'}.'</h3>'.
2522: &Apache::lonhtmlcommon::start_pick_box();
1.391 raeburn 2523: if (($context eq 'selfcreate') && ($newuser eq 'email')) {
1.443 raeburn 2524: my $size = 25;
1.442 raeburn 2525: if ($condition) {
1.443 raeburn 2526: if ($condition =~ /^\@[^\@]+$/) {
2527: $size = 10;
1.442 raeburn 2528: } else {
2529: undef($condition);
2530: }
1.443 raeburn 2531: }
2532: if ($excluded) {
2533: unless ($excluded =~ /^\@[^\@]+$/) {
2534: undef($condition);
2535: }
1.442 raeburn 2536: }
1.396 raeburn 2537: $output .= &Apache::lonhtmlcommon::row_title($lt{'email'}.'<b>*</b>',undef,
1.391 raeburn 2538: 'LC_oddrow_value')."\n".
1.443 raeburn 2539: '<input type="text" name="uname" size="'.$size.'" value="" autocomplete="off" />';
2540: if ($condition) {
2541: $output .= $condition;
2542: } elsif ($excluded) {
2543: $output .= '<br /><span style="font-size: smaller">'.&mt('You must use an e-mail address that does not end with [_1]',
2544: $excluded).'</span>';
2545: }
2546: if ($usernameset eq 'first') {
2547: $output .= '<br /><span style="font-size: smaller">';
2548: if ($condition) {
2549: $output .= &mt('Your username in LON-CAPA will be the part of your e-mail address before [_1]',
2550: $condition);
2551: } else {
2552: $output .= &mt('Your username in LON-CAPA will be the part of your e-mail address before the @');
2553: }
2554: $output .= '</span>';
2555: }
1.391 raeburn 2556: $rowcount ++;
2557: $output .= &Apache::lonhtmlcommon::row_closure(1);
1.460 raeburn 2558: my $upassone = '<input type="password" name="upass'.$now.'" size="20" autocomplete="new-password" />';
2559: my $upasstwo = '<input type="password" name="upasscheck'.$now.'" size="20" autocomplete="new-password" />';
1.396 raeburn 2560: $output .= &Apache::lonhtmlcommon::row_title(&mt('Password').'<b>*</b>',
1.391 raeburn 2561: 'LC_pick_box_title',
2562: 'LC_oddrow_value')."\n".
2563: $upassone."\n".
2564: &Apache::lonhtmlcommon::row_closure(1)."\n".
1.396 raeburn 2565: &Apache::lonhtmlcommon::row_title(&mt('Confirm password').'<b>*</b>',
1.391 raeburn 2566: 'LC_pick_box_title',
2567: 'LC_oddrow_value')."\n".
2568: $upasstwo.
2569: &Apache::lonhtmlcommon::row_closure()."\n";
1.443 raeburn 2570: if ($usernameset eq 'free') {
2571: my $onclick = "toggleUsernameDisp(this,'selfcreateusername');";
1.442 raeburn 2572: $output .= &Apache::lonhtmlcommon::row_title($lt{'username'},undef,'LC_oddrow_value')."\n".
1.455 raeburn 2573: '<span class="LC_nobreak">'.&mt('Use e-mail address: ').
2574: '<label><input type="radio" name="emailused" value="1" checked="checked" onclick="'.$onclick.'" />'.
2575: &mt('Yes').'</label>'.(' 'x2).
2576: '<label><input type="radio" name="emailused" value="0" onclick="'.$onclick.'" />'.
2577: &mt('No').'</label></span>'."\n".
1.442 raeburn 2578: '<div id="selfcreateusername" style="display: none; font-size: smaller">'.
2579: '<br /><span class="LC_nobreak">'.&mt('Preferred username').
2580: ' <input type="text" name="username" value="" size="20" autocomplete="off"/>'.
2581: '</span></div>'."\n".&Apache::lonhtmlcommon::row_closure(1);
2582: $rowcount ++;
2583: }
1.391 raeburn 2584: }
1.188 raeburn 2585: foreach my $item (@userinfo) {
2586: my $rowtitle = $lt{$item};
1.252 raeburn 2587: my $hiderow = 0;
1.188 raeburn 2588: if ($item eq 'generation') {
2589: $rowtitle = $genhelp.$rowtitle;
2590: }
1.252 raeburn 2591: my $row = &Apache::lonhtmlcommon::row_title($rowtitle,undef,'LC_oddrow_value')."\n";
1.188 raeburn 2592: if ($newuser) {
1.210 raeburn 2593: if (ref($inst_results) eq 'HASH') {
2594: if ($inst_results->{$item} ne '') {
1.252 raeburn 2595: $row .= '<input type="hidden" name="c'.$item.'" value="'.$inst_results->{$item}.'" />'.$inst_results->{$item};
1.210 raeburn 2596: } else {
1.252 raeburn 2597: if ($context eq 'selfcreate') {
1.391 raeburn 2598: if ($canmodify{$item}) {
1.394 raeburn 2599: $row .= '<input type="text" name="c'.$item.'" size="'.$textboxsize{$item}.'" value="" autocomplete="off" />';
1.252 raeburn 2600: $editable ++;
2601: } else {
2602: $hiderow = 1;
2603: }
1.253 raeburn 2604: } else {
2605: $row .= '<input type="text" name="c'.$item.'" size="'.$textboxsize{$item}.'" value="" />';
1.252 raeburn 2606: }
1.210 raeburn 2607: }
1.188 raeburn 2608: } else {
1.252 raeburn 2609: if ($context eq 'selfcreate') {
1.401 raeburn 2610: if ($canmodify{$item}) {
2611: if ($newuser eq 'email') {
2612: $row .= '<input type="text" name="'.$item.'" size="'.$textboxsize{$item}.'" value="" autocomplete="off" />';
1.287 raeburn 2613: } else {
1.401 raeburn 2614: $row .= '<input type="text" name="c'.$item.'" size="'.$textboxsize{$item}.'" value="" autocomplete="off" />';
1.287 raeburn 2615: }
1.401 raeburn 2616: $editable ++;
2617: } else {
2618: $hiderow = 1;
1.252 raeburn 2619: }
1.253 raeburn 2620: } else {
2621: $row .= '<input type="text" name="c'.$item.'" size="'.$textboxsize{$item}.'" value="" />';
1.252 raeburn 2622: }
1.188 raeburn 2623: }
2624: } else {
1.219 raeburn 2625: if ($canmodify{$item}) {
1.252 raeburn 2626: $row .= '<input type="text" name="c'.$item.'" size="'.$textboxsize{$item}.'" value="'.$userenv{$item}.'" />';
1.393 raeburn 2627: if (($item eq 'id') && (!$newuser)) {
2628: $row .= '<br />'.&Apache::lonuserutils::forceid_change($context);
2629: }
1.188 raeburn 2630: } else {
1.252 raeburn 2631: $row .= $userenv{$item};
1.188 raeburn 2632: }
2633: }
1.252 raeburn 2634: $row .= &Apache::lonhtmlcommon::row_closure(1);
2635: if (!$hiderow) {
2636: $output .= $row;
2637: $rowcount ++;
2638: }
1.188 raeburn 2639: }
1.286 raeburn 2640: if (($canmodify_status{'inststatus'}) || ($context ne 'selfcreate')) {
2641: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($ccdomain);
2642: if (ref($types) eq 'ARRAY') {
2643: if (@{$types} > 0) {
2644: my ($hiderow,$shown);
2645: if ($canmodify_status{'inststatus'}) {
2646: $shown = &pick_inst_statuses($userenv{'inststatus'},$usertypes,$types);
2647: } else {
2648: if ($userenv{'inststatus'} eq '') {
2649: $hiderow = 1;
1.334 raeburn 2650: } else {
2651: my @showitems;
2652: foreach my $item ( map { &unescape($_); } split(':',$userenv{'inststatus'})) {
2653: if (exists($usertypes->{$item})) {
2654: push(@showitems,$usertypes->{$item});
2655: } else {
2656: push(@showitems,$item);
2657: }
2658: }
2659: if (@showitems) {
2660: $shown = join(', ',@showitems);
2661: } else {
2662: $hiderow = 1;
2663: }
1.286 raeburn 2664: }
2665: }
2666: if (!$hiderow) {
1.389 bisitz 2667: my $row = &Apache::lonhtmlcommon::row_title(&mt('Affiliations'),undef,'LC_oddrow_value')."\n".
1.286 raeburn 2668: $shown.&Apache::lonhtmlcommon::row_closure(1);
2669: if ($context eq 'selfcreate') {
2670: $rowcount ++;
2671: }
2672: $output .= $row;
2673: }
2674: }
2675: }
2676: }
1.391 raeburn 2677: if (($context eq 'selfcreate') && ($newuser eq 'email')) {
2678: if ($captchaform) {
1.410 raeburn 2679: $output .= &Apache::lonhtmlcommon::row_title($lt{'valid'}.'*',
2680: 'LC_pick_box_title')."\n".
1.456 raeburn 2681: $captchaform."\n".'<br /><br />'.
1.391 raeburn 2682: &Apache::lonhtmlcommon::row_closure(1);
2683: $rowcount ++;
2684: }
1.456 raeburn 2685: if ($showsubmit) {
2686: my $submit_text = &mt('Create account');
2687: $output .= &Apache::lonhtmlcommon::row_title()."\n".
2688: '<br /><input type="submit" name="createaccount" value="'.
2689: $submit_text.'" />';
2690: if ($usertype ne '') {
2691: $output .= '<input type="hidden" name="type" value="'.
2692: &HTML::Entities::encode($usertype,'\'<>"&').'" />';
2693: }
2694: $output .= &Apache::lonhtmlcommon::row_closure(1);
2695: }
1.391 raeburn 2696: }
1.188 raeburn 2697: $output .= &Apache::lonhtmlcommon::end_pick_box();
1.206 raeburn 2698: if (wantarray) {
1.252 raeburn 2699: if ($context eq 'selfcreate') {
2700: return($output,$rowcount,$editable);
2701: } else {
1.388 bisitz 2702: return $output;
1.252 raeburn 2703: }
1.206 raeburn 2704: } else {
2705: return $output;
2706: }
1.188 raeburn 2707: }
2708:
1.286 raeburn 2709: sub pick_inst_statuses {
2710: my ($curr,$usertypes,$types) = @_;
2711: my ($output,$rem,@currtypes);
2712: if ($curr ne '') {
2713: @currtypes = map { &unescape($_); } split(/:/,$curr);
2714: }
2715: my $numinrow = 2;
2716: if (ref($types) eq 'ARRAY') {
2717: $output = '<table>';
2718: my $lastcolspan;
2719: for (my $i=0; $i<@{$types}; $i++) {
2720: if (defined($usertypes->{$types->[$i]})) {
2721: my $rem = $i%($numinrow);
2722: if ($rem == 0) {
2723: if ($i<@{$types}-1) {
2724: if ($i > 0) {
2725: $output .= '</tr>';
2726: }
2727: $output .= '<tr>';
2728: }
2729: } elsif ($i==@{$types}-1) {
2730: my $colsleft = $numinrow - $rem;
2731: if ($colsleft > 1) {
2732: $lastcolspan = ' colspan="'.$colsleft.'"';
2733: }
2734: }
2735: my $check = ' ';
2736: if (grep(/^\Q$types->[$i]\E$/,@currtypes)) {
2737: $check = ' checked="checked" ';
2738: }
2739: $output .= '<td class="LC_left_item"'.$lastcolspan.'>'.
2740: '<span class="LC_nobreak"><label>'.
2741: '<input type="checkbox" name="inststatus" '.
2742: 'value="'.$types->[$i].'"'.$check.'/>'.
2743: $usertypes->{$types->[$i]}.'</label></span></td>';
2744: }
2745: }
2746: $output .= '</tr></table>';
2747: }
2748: return $output;
2749: }
2750:
1.257 raeburn 2751: sub selfcreate_canmodify {
2752: my ($context,$dom,$userinfo,$inst_results,$rolesarray) = @_;
2753: if (ref($inst_results) eq 'HASH') {
2754: my @inststatuses = &get_inststatuses($inst_results);
2755: if (@inststatuses == 0) {
2756: @inststatuses = ('default');
2757: }
2758: $rolesarray = \@inststatuses;
2759: }
2760: my %canmodify =
2761: &Apache::lonuserutils::can_modify_userinfo($context,$dom,$userinfo,
2762: $rolesarray);
2763: return %canmodify;
2764: }
2765:
1.252 raeburn 2766: sub get_inststatuses {
2767: my ($insthashref) = @_;
2768: my @inststatuses = ();
2769: if (ref($insthashref) eq 'HASH') {
2770: if (ref($insthashref->{'inststatus'}) eq 'ARRAY') {
2771: @inststatuses = @{$insthashref->{'inststatus'}};
2772: }
2773: }
2774: return @inststatuses;
2775: }
2776:
1.4 www 2777: # ================================================================= Phase Three
1.42 matthew 2778: sub update_user_data {
1.451 raeburn 2779: my ($r,$context,$crstype,$brcrum,$showcredits,$permission) = @_;
1.101 albertel 2780: my $uhome=&Apache::lonnet::homeserver($env{'form.ccuname'},
2781: $env{'form.ccdomain'});
1.27 matthew 2782: # Error messages
1.188 raeburn 2783: my $error = '<span class="LC_error">'.&mt('Error').': ';
1.193 raeburn 2784: my $end = '</span><br /><br />';
2785: my $rtnlink = '<a href="javascript:backPage(document.userupdate,'.
1.188 raeburn 2786: "'$env{'form.prevphase'}','modify')".'" />'.
1.219 raeburn 2787: &mt('Return to previous page').'</a>'.
2788: &Apache::loncommon::end_page();
2789: my $now = time;
1.40 www 2790: my $title;
1.101 albertel 2791: if (exists($env{'form.makeuser'})) {
1.40 www 2792: $title='Set Privileges for New User';
2793: } else {
2794: $title='Modify User Privileges';
2795: }
1.213 raeburn 2796: my $newuser = 0;
1.160 raeburn 2797: my ($jsback,$elements) = &crumb_utilities();
2798: my $jscript = '<script type="text/javascript">'."\n".
1.301 bisitz 2799: '// <![CDATA['."\n".
2800: $jsback."\n".
2801: '// ]]>'."\n".
2802: '</script>'."\n";
1.422 raeburn 2803: my %breadcrumb_text = &singleuser_breadcrumb($crstype,$context,$env{'form.ccdomain'});
1.351 raeburn 2804: push (@{$brcrum},
2805: {href => "javascript:backPage(document.userupdate)",
2806: text => $breadcrumb_text{'search'},
2807: faq => 282,
2808: bug => 'Instructor Interface',}
2809: );
2810: if ($env{'form.prevphase'} eq 'userpicked') {
2811: push(@{$brcrum},
2812: {href => "javascript:backPage(document.userupdate,'get_user_info','select')",
2813: text => $breadcrumb_text{'userpicked'},
2814: faq => 282,
2815: bug => 'Instructor Interface',});
1.233 raeburn 2816: }
1.224 raeburn 2817: my $helpitem = 'Course_Change_Privileges';
2818: if ($env{'form.action'} eq 'singlestudent') {
2819: $helpitem = 'Course_Add_Student';
1.439 raeburn 2820: } elsif ($context eq 'author') {
2821: $helpitem = 'Author_Change_Privileges';
2822: } elsif ($context eq 'domain') {
2823: $helpitem = 'Domain_Change_Privileges';
1.224 raeburn 2824: }
1.351 raeburn 2825: push(@{$brcrum},
2826: {href => "javascript:backPage(document.userupdate,'$env{'form.prevphase'}','modify')",
2827: text => $breadcrumb_text{'modify'},
2828: faq => 282,
2829: bug => 'Instructor Interface',},
2830: {href => "/adm/createuser",
2831: text => "Result",
2832: faq => 282,
2833: bug => 'Instructor Interface',
2834: help => $helpitem});
2835: my $args = {bread_crumbs => $brcrum,
2836: bread_crumbs_component => 'User Management'};
2837: if ($env{'form.popup'}) {
2838: $args->{'no_nav_bar'} = 1;
2839: }
2840: $r->print(&Apache::loncommon::start_page($title,$jscript,$args));
1.188 raeburn 2841: $r->print(&update_result_form($uhome));
1.27 matthew 2842: # Check Inputs
1.101 albertel 2843: if (! $env{'form.ccuname'} ) {
1.193 raeburn 2844: $r->print($error.&mt('No login name specified').'.'.$end.$rtnlink);
1.27 matthew 2845: return;
2846: }
1.138 albertel 2847: if ( $env{'form.ccuname'} ne
2848: &LONCAPA::clean_username($env{'form.ccuname'}) ) {
1.281 bisitz 2849: $r->print($error.&mt('Invalid login name.').' '.
2850: &mt('Only letters, numbers, periods, dashes, @, and underscores are valid.').
1.193 raeburn 2851: $end.$rtnlink);
1.27 matthew 2852: return;
2853: }
1.101 albertel 2854: if (! $env{'form.ccdomain'} ) {
1.193 raeburn 2855: $r->print($error.&mt('No domain specified').'.'.$end.$rtnlink);
1.27 matthew 2856: return;
2857: }
1.138 albertel 2858: if ( $env{'form.ccdomain'} ne
2859: &LONCAPA::clean_domain($env{'form.ccdomain'}) ) {
1.281 bisitz 2860: $r->print($error.&mt('Invalid domain name.').' '.
2861: &mt('Only letters, numbers, periods, dashes, and underscores are valid.').
1.193 raeburn 2862: $end.$rtnlink);
1.27 matthew 2863: return;
2864: }
1.219 raeburn 2865: if ($uhome eq 'no_host') {
2866: $newuser = 1;
2867: }
1.101 albertel 2868: if (! exists($env{'form.makeuser'})) {
1.29 matthew 2869: # Modifying an existing user, so check the validity of the name
2870: if ($uhome eq 'no_host') {
1.389 bisitz 2871: $r->print(
2872: $error
2873: .'<p class="LC_error">'
2874: .&mt('Unable to determine home server for [_1] in domain [_2].',
2875: '"'.$env{'form.ccuname'}.'"','"'.$env{'form.ccdomain'}.'"')
2876: .'</p>');
1.29 matthew 2877: return;
2878: }
2879: }
1.27 matthew 2880: # Determine authentication method and password for the user being modified
2881: my $amode='';
2882: my $genpwd='';
1.101 albertel 2883: if ($env{'form.login'} eq 'krb') {
1.41 albertel 2884: $amode='krb';
1.101 albertel 2885: $amode.=$env{'form.krbver'};
2886: $genpwd=$env{'form.krbarg'};
2887: } elsif ($env{'form.login'} eq 'int') {
1.27 matthew 2888: $amode='internal';
1.101 albertel 2889: $genpwd=$env{'form.intarg'};
2890: } elsif ($env{'form.login'} eq 'fsys') {
1.27 matthew 2891: $amode='unix';
1.101 albertel 2892: $genpwd=$env{'form.fsysarg'};
2893: } elsif ($env{'form.login'} eq 'loc') {
1.27 matthew 2894: $amode='localauth';
1.101 albertel 2895: $genpwd=$env{'form.locarg'};
1.27 matthew 2896: $genpwd=" " if (!$genpwd);
1.449 raeburn 2897: } elsif ($env{'form.login'} eq 'lti') {
2898: $amode='lti';
2899: $genpwd=" ";
1.101 albertel 2900: } elsif (($env{'form.login'} eq 'nochange') ||
2901: ($env{'form.login'} eq '' )) {
1.34 matthew 2902: # There is no need to tell the user we did not change what they
2903: # did not ask us to change.
1.35 matthew 2904: # If they are creating a new user but have not specified login
2905: # information this will be caught below.
1.30 matthew 2906: } else {
1.367 golterma 2907: $r->print($error.&mt('Invalid login mode or password').$end.$rtnlink);
2908: return;
1.27 matthew 2909: }
1.164 albertel 2910:
1.188 raeburn 2911: $r->print('<h3>'.&mt('User [_1] in domain [_2]',
1.367 golterma 2912: $env{'form.ccuname'}.' ('.&Apache::loncommon::plainname($env{'form.ccuname'},
2913: $env{'form.ccdomain'}).')', $env{'form.ccdomain'}).'</h3>');
2914: my %prog_state = &Apache::lonhtmlcommon::Create_PrgWin($r,2);
1.344 bisitz 2915:
1.193 raeburn 2916: my (%alerts,%rulematch,%inst_results,%curr_rules);
1.334 raeburn 2917: my @userinfo = ('firstname','middlename','lastname','generation','permanentemail','id');
1.459 raeburn 2918: my @usertools = ('aboutme','blog','webdav','portfolio','timezone');
1.449 raeburn 2919: my @requestcourses = ('official','unofficial','community','textbook','placement','lti');
1.362 raeburn 2920: my @requestauthor = ('requestauthor');
1.286 raeburn 2921: my ($othertitle,$usertypes,$types) =
2922: &Apache::loncommon::sorted_inst_types($env{'form.ccdomain'});
1.334 raeburn 2923: my %canmodify_status =
2924: &Apache::lonuserutils::can_modify_userinfo($context,$env{'form.ccdomain'},
2925: ['inststatus']);
1.101 albertel 2926: if ($env{'form.makeuser'}) {
1.164 albertel 2927: $r->print('<h3>'.&mt('Creating new account.').'</h3>');
1.27 matthew 2928: # Check for the authentication mode and password
2929: if (! $amode || ! $genpwd) {
1.193 raeburn 2930: $r->print($error.&mt('Invalid login mode or password').$end.$rtnlink);
1.27 matthew 2931: return;
1.18 albertel 2932: }
1.29 matthew 2933: # Determine desired host
1.101 albertel 2934: my $desiredhost = $env{'form.hserver'};
1.29 matthew 2935: if (lc($desiredhost) eq 'default') {
2936: $desiredhost = undef;
2937: } else {
1.147 albertel 2938: my %home_servers =
2939: &Apache::lonnet::get_servers($env{'form.ccdomain'},'library');
1.29 matthew 2940: if (! exists($home_servers{$desiredhost})) {
1.193 raeburn 2941: $r->print($error.&mt('Invalid home server specified').$end.$rtnlink);
2942: return;
2943: }
2944: }
2945: # Check ID format
2946: my %checkhash;
2947: my %checks = ('id' => 1);
2948: %{$checkhash{$env{'form.ccuname'}.':'.$env{'form.ccdomain'}}} = (
1.219 raeburn 2949: 'newuser' => $newuser,
1.196 raeburn 2950: 'id' => $env{'form.cid'},
1.193 raeburn 2951: );
1.196 raeburn 2952: if ($env{'form.cid'} ne '') {
2953: &Apache::loncommon::user_rule_check(\%checkhash,\%checks,\%alerts,
2954: \%rulematch,\%inst_results,\%curr_rules);
2955: if (ref($alerts{'id'}) eq 'HASH') {
2956: if (ref($alerts{'id'}{$env{'form.ccdomain'}}) eq 'HASH') {
2957: my $domdesc =
2958: &Apache::lonnet::domain($env{'form.ccdomain'},'description');
2959: if ($alerts{'id'}{$env{'form.ccdomain'}}{$env{'form.cid'}}) {
2960: my $userchkmsg;
2961: if (ref($curr_rules{$env{'form.ccdomain'}}) eq 'HASH') {
2962: $userchkmsg =
2963: &Apache::loncommon::instrule_disallow_msg('id',
2964: $domdesc,1).
2965: &Apache::loncommon::user_rule_formats($env{'form.ccdomain'},
2966: $domdesc,$curr_rules{$env{'form.ccdomain'}}{'id'},'id');
2967: }
2968: $r->print($error.&mt('Invalid ID format').$end.
2969: $userchkmsg.$rtnlink);
2970: return;
2971: }
2972: }
1.29 matthew 2973: }
2974: }
1.367 golterma 2975: &Apache::lonhtmlcommon::Increment_PrgWin($r, \%prog_state);
1.27 matthew 2976: # Call modifyuser
2977: my $result = &Apache::lonnet::modifyuser
1.193 raeburn 2978: ($env{'form.ccdomain'},$env{'form.ccuname'},$env{'form.cid'},
1.188 raeburn 2979: $amode,$genpwd,$env{'form.cfirstname'},
2980: $env{'form.cmiddlename'},$env{'form.clastname'},
2981: $env{'form.cgeneration'},undef,$desiredhost,
2982: $env{'form.cpermanentemail'});
1.77 www 2983: $r->print(&mt('Generating user').': '.$result);
1.219 raeburn 2984: $uhome = &Apache::lonnet::homeserver($env{'form.ccuname'},
1.101 albertel 2985: $env{'form.ccdomain'});
1.334 raeburn 2986: my (%changeHash,%newcustom,%changed,%changedinfo);
1.267 raeburn 2987: if ($uhome ne 'no_host') {
1.334 raeburn 2988: if ($context eq 'domain') {
1.378 raeburn 2989: foreach my $name ('portfolio','author') {
2990: if ($env{'form.custom_'.$name.'quota'} == 1) {
2991: if ($env{'form.'.$name.'quota'} eq '') {
2992: $newcustom{$name.'quota'} = 0;
2993: } else {
2994: $newcustom{$name.'quota'} = $env{'form.'.$name.'quota'};
2995: $newcustom{$name.'quota'} =~ s/[^\d\.]//g;
2996: }
2997: if ("a_admin($newcustom{$name.'quota'},\%changeHash,$name)) {
2998: $changed{$name.'quota'} = 1;
2999: }
1.334 raeburn 3000: }
3001: }
3002: foreach my $item (@usertools) {
3003: if ($env{'form.custom'.$item} == 1) {
3004: $newcustom{$item} = $env{'form.tools_'.$item};
3005: $changed{$item} = &tool_admin($item,$newcustom{$item},
3006: \%changeHash,'tools');
3007: }
1.267 raeburn 3008: }
1.334 raeburn 3009: foreach my $item (@requestcourses) {
1.341 raeburn 3010: if ($env{'form.custom'.$item} == 1) {
3011: $newcustom{$item} = $env{'form.crsreq_'.$item};
3012: if ($env{'form.crsreq_'.$item} eq 'autolimit') {
3013: $newcustom{$item} .= '=';
1.383 raeburn 3014: $env{'form.crsreq_'.$item.'_limit'} =~ s/\D+//g;
3015: if ($env{'form.crsreq_'.$item.'_limit'}) {
1.341 raeburn 3016: $newcustom{$item} .= $env{'form.crsreq_'.$item.'_limit'};
3017: }
1.334 raeburn 3018: }
1.341 raeburn 3019: $changed{$item} = &tool_admin($item,$newcustom{$item},
3020: \%changeHash,'requestcourses');
1.334 raeburn 3021: }
1.275 raeburn 3022: }
1.362 raeburn 3023: if ($env{'form.customrequestauthor'} == 1) {
3024: $newcustom{'requestauthor'} = $env{'form.requestauthor'};
3025: $changed{'requestauthor'} = &tool_admin('requestauthor',
3026: $newcustom{'requestauthor'},
3027: \%changeHash,'requestauthor');
3028: }
1.275 raeburn 3029: }
1.334 raeburn 3030: if ($canmodify_status{'inststatus'}) {
3031: if (exists($env{'form.inststatus'})) {
3032: my @inststatuses = &Apache::loncommon::get_env_multiple('form.inststatus');
3033: if (@inststatuses > 0) {
3034: $changeHash{'inststatus'} = join(',',@inststatuses);
3035: $changed{'inststatus'} = $changeHash{'inststatus'};
1.306 raeburn 3036: }
3037: }
1.232 raeburn 3038: }
1.334 raeburn 3039: if (keys(%changed)) {
3040: foreach my $item (@userinfo) {
3041: $changeHash{$item} = $env{'form.c'.$item};
1.286 raeburn 3042: }
1.267 raeburn 3043: my $chgresult =
3044: &Apache::lonnet::put('environment',\%changeHash,
3045: $env{'form.ccdomain'},$env{'form.ccuname'});
3046: }
1.232 raeburn 3047: }
1.454 raeburn 3048: $r->print('<br />'.&mt('Home Server').': '.$uhome.' '.
1.219 raeburn 3049: &Apache::lonnet::hostname($uhome));
1.101 albertel 3050: } elsif (($env{'form.login'} ne 'nochange') &&
3051: ($env{'form.login'} ne '' )) {
1.27 matthew 3052: # Modify user privileges
3053: if (! $amode || ! $genpwd) {
1.193 raeburn 3054: $r->print($error.'Invalid login mode or password'.$end.$rtnlink);
1.27 matthew 3055: return;
1.20 harris41 3056: }
1.395 bisitz 3057: # Only allow authentication modification if the person has authority
1.101 albertel 3058: if (&Apache::lonnet::allowed('mau',$env{'form.ccdomain'})) {
1.20 harris41 3059: $r->print('Modifying authentication: '.
1.31 matthew 3060: &Apache::lonnet::modifyuserauth(
1.101 albertel 3061: $env{'form.ccdomain'},$env{'form.ccuname'},
1.21 harris41 3062: $amode,$genpwd));
1.454 raeburn 3063: $r->print('<br />'.&mt('Home Server').': '.&Apache::lonnet::homeserver
1.101 albertel 3064: ($env{'form.ccuname'},$env{'form.ccdomain'}));
1.4 www 3065: } else {
1.27 matthew 3066: # Okay, this is a non-fatal error.
1.452 raeburn 3067: $r->print($error.&mt('You do not have privileges to modify the authentication configuration for this user.').$end);
1.27 matthew 3068: }
1.451 raeburn 3069: } elsif (($env{'form.intarg'} ne '') &&
3070: (&Apache::lonnet::queryauthenticate($env{'form.ccuname'},$env{'form.ccdomain'}) =~ /^internal:/) &&
3071: (&Apache::lonuserutils::can_change_internalpass($env{'form.ccuname'},$env{'form.ccdomain'},$crstype,$permission))) {
3072: $r->print('Modifying authentication: '.
3073: &Apache::lonnet::modifyuserauth(
3074: $env{'form.ccdomain'},$env{'form.ccuname'},
3075: 'internal',$env{'form.intarg'}));
1.28 matthew 3076: }
1.344 bisitz 3077: $r->rflush(); # Finish display of header before time consuming actions start
1.367 golterma 3078: &Apache::lonhtmlcommon::Increment_PrgWin($r,\%prog_state);
1.28 matthew 3079: ##
1.375 raeburn 3080: my (@userroles,%userupdate,$cnum,$cdom,$defaultcredits,%namechanged);
1.213 raeburn 3081: if ($context eq 'course') {
1.375 raeburn 3082: ($cnum,$cdom) =
3083: &Apache::lonuserutils::get_course_identity();
1.318 raeburn 3084: $crstype = &Apache::loncommon::course_type($cdom.'_'.$cnum);
1.375 raeburn 3085: if ($showcredits) {
3086: $defaultcredits = &Apache::lonuserutils::get_defaultcredits($cdom,$cnum);
3087: }
1.213 raeburn 3088: }
1.101 albertel 3089: if (! $env{'form.makeuser'} ) {
1.28 matthew 3090: # Check for need to change
3091: my %userenv = &Apache::lonnet::get
1.134 raeburn 3092: ('environment',['firstname','middlename','lastname','generation',
1.378 raeburn 3093: 'id','permanentemail','portfolioquota','authorquota','inststatus',
1.459 raeburn 3094: 'tools.aboutme','tools.blog','tools.webdav',
3095: 'tools.portfolio','tools.timezone',
1.361 raeburn 3096: 'requestcourses.official','requestcourses.unofficial',
1.384 raeburn 3097: 'requestcourses.community','requestcourses.textbook',
1.458 raeburn 3098: 'requestcourses.lti','requestauthor',
1.384 raeburn 3099: 'reqcrsotherdom.official','reqcrsotherdom.unofficial',
3100: 'reqcrsotherdom.community','reqcrsotherdom.textbook',
1.458 raeburn 3101: 'reqcrsotherdom.placement'],
1.160 raeburn 3102: $env{'form.ccdomain'},$env{'form.ccuname'});
1.28 matthew 3103: my ($tmp) = keys(%userenv);
3104: if ($tmp =~ /^(con_lost|error)/i) {
3105: %userenv = ();
3106: }
1.206 raeburn 3107: my $no_forceid_alert;
3108: # Check to see if user information can be changed
3109: my %domconfig =
3110: &Apache::lonnet::get_dom('configuration',['usermodification'],
3111: $env{'form.ccdomain'});
1.213 raeburn 3112: my @statuses = ('active','future');
3113: my %roles = &Apache::lonnet::get_my_roles($env{'form.ccuname'},$env{'form.ccdomain'},'userroles',\@statuses,undef,$env{'request.role.domain'});
3114: my ($auname,$audom);
1.220 raeburn 3115: if ($context eq 'author') {
1.206 raeburn 3116: $auname = $env{'user.name'};
3117: $audom = $env{'user.domain'};
3118: }
3119: foreach my $item (keys(%roles)) {
1.220 raeburn 3120: my ($rolenum,$roledom,$role) = split(/:/,$item,-1);
1.206 raeburn 3121: if ($context eq 'course') {
3122: if ($cnum ne '' && $cdom ne '') {
3123: if ($rolenum eq $cnum && $roledom eq $cdom) {
3124: if (!grep(/^\Q$role\E$/,@userroles)) {
3125: push(@userroles,$role);
3126: }
3127: }
3128: }
3129: } elsif ($context eq 'author') {
3130: if ($rolenum eq $auname && $roledom eq $audom) {
1.461 raeburn 3131: if (!grep(/^\Q$role\E$/,@userroles)) {
1.206 raeburn 3132: push(@userroles,$role);
3133: }
3134: }
3135: }
3136: }
1.220 raeburn 3137: if ($env{'form.action'} eq 'singlestudent') {
3138: if (!grep(/^st$/,@userroles)) {
3139: push(@userroles,'st');
3140: }
3141: } else {
3142: # Check for course or co-author roles being activated or re-enabled
3143: if ($context eq 'author' || $context eq 'course') {
3144: foreach my $key (keys(%env)) {
3145: if ($context eq 'author') {
3146: if ($key=~/^form\.act_\Q$audom\E_\Q$auname\E_([^_]+)/) {
3147: if (!grep(/^\Q$1\E$/,@userroles)) {
3148: push(@userroles,$1);
3149: }
3150: } elsif ($key =~/^form\.ren\:\Q$audom\E\/\Q$auname\E_([^_]+)/) {
3151: if (!grep(/^\Q$1\E$/,@userroles)) {
3152: push(@userroles,$1);
3153: }
1.206 raeburn 3154: }
1.220 raeburn 3155: } elsif ($context eq 'course') {
3156: if ($key=~/^form\.act_\Q$cdom\E_\Q$cnum\E_([^_]+)/) {
3157: if (!grep(/^\Q$1\E$/,@userroles)) {
3158: push(@userroles,$1);
3159: }
3160: } elsif ($key =~/^form\.ren\:\Q$cdom\E\/\Q$cnum\E(\/?\w*)_([^_]+)/) {
3161: if (!grep(/^\Q$1\E$/,@userroles)) {
3162: push(@userroles,$1);
3163: }
1.206 raeburn 3164: }
3165: }
3166: }
3167: }
3168: }
3169: #Check to see if we can change personal data for the user
3170: my (@mod_disallowed,@longroles);
3171: foreach my $role (@userroles) {
3172: if ($role eq 'cr') {
3173: push(@longroles,'Custom');
3174: } else {
1.318 raeburn 3175: push(@longroles,&Apache::lonnet::plaintext($role,$crstype));
1.206 raeburn 3176: }
3177: }
1.219 raeburn 3178: my %canmodify = &Apache::lonuserutils::can_modify_userinfo($context,$env{'form.ccdomain'},\@userinfo,\@userroles);
3179: foreach my $item (@userinfo) {
1.28 matthew 3180: # Strip leading and trailing whitespace
1.203 raeburn 3181: $env{'form.c'.$item} =~ s/(\s+$|^\s+)//g;
1.219 raeburn 3182: if (!$canmodify{$item}) {
1.207 raeburn 3183: if (defined($env{'form.c'.$item})) {
3184: if ($env{'form.c'.$item} ne $userenv{$item}) {
3185: push(@mod_disallowed,$item);
3186: }
1.206 raeburn 3187: }
3188: $env{'form.c'.$item} = $userenv{$item};
3189: }
1.28 matthew 3190: }
1.259 bisitz 3191: # Check to see if we can change the Student/Employee ID
1.196 raeburn 3192: my $forceid = $env{'form.forceid'};
3193: my $recurseid = $env{'form.recurseid'};
3194: my (%alerts,%rulematch,%idinst_results,%curr_rules,%got_rules);
1.203 raeburn 3195: my %uidhash = &Apache::lonnet::idrget($env{'form.ccdomain'},
3196: $env{'form.ccuname'});
3197: if (($uidhash{$env{'form.ccuname'}}) &&
3198: ($uidhash{$env{'form.ccuname'}}!~/error\:/) &&
3199: (!$forceid)) {
3200: if ($env{'form.cid'} ne $uidhash{$env{'form.ccuname'}}) {
3201: $env{'form.cid'} = $userenv{'id'};
1.293 bisitz 3202: $no_forceid_alert = &mt('New student/employee ID does not match existing ID for this user.')
1.259 bisitz 3203: .'<br />'
3204: .&mt("Change is not permitted without checking the 'Force ID change' checkbox on the previous page.")
3205: .'<br />'."\n";
1.203 raeburn 3206: }
3207: }
3208: if ($env{'form.cid'} ne $userenv{'id'}) {
1.196 raeburn 3209: my $checkhash;
3210: my $checks = { 'id' => 1 };
3211: $checkhash->{$env{'form.ccuname'}.':'.$env{'form.ccdomain'}} =
3212: { 'newuser' => $newuser,
3213: 'id' => $env{'form.cid'},
3214: };
3215: &Apache::loncommon::user_rule_check($checkhash,$checks,
3216: \%alerts,\%rulematch,\%idinst_results,\%curr_rules,\%got_rules);
3217: if (ref($alerts{'id'}) eq 'HASH') {
3218: if (ref($alerts{'id'}{$env{'form.ccdomain'}}) eq 'HASH') {
1.203 raeburn 3219: $env{'form.cid'} = $userenv{'id'};
1.196 raeburn 3220: }
3221: }
3222: }
1.378 raeburn 3223: my (%quotachanged,%oldquota,%newquota,%olddefquota,%newdefquota,
3224: $oldinststatus,$newinststatus,%oldisdefault,%newisdefault,%oldsettings,
1.339 raeburn 3225: %oldsettingstext,%newsettings,%newsettingstext,@disporder,
1.378 raeburn 3226: %oldsettingstatus,%newsettingstatus);
1.334 raeburn 3227: @disporder = ('inststatus');
3228: if ($env{'request.role.domain'} eq $env{'form.ccdomain'}) {
1.362 raeburn 3229: push(@disporder,'requestcourses','requestauthor');
1.334 raeburn 3230: } else {
3231: push(@disporder,'reqcrsotherdom');
3232: }
3233: push(@disporder,('quota','tools'));
1.338 raeburn 3234: $oldinststatus = $userenv{'inststatus'};
1.378 raeburn 3235: foreach my $name ('portfolio','author') {
3236: ($olddefquota{$name},$oldsettingstatus{$name}) =
3237: &Apache::loncommon::default_quota($env{'form.ccdomain'},$oldinststatus,$name);
3238: ($newdefquota{$name},$newsettingstatus{$name}) = ($olddefquota{$name},$oldsettingstatus{$name});
3239: }
1.334 raeburn 3240: my %canshow;
1.220 raeburn 3241: if (&Apache::lonnet::allowed('mpq',$env{'form.ccdomain'})) {
1.334 raeburn 3242: $canshow{'quota'} = 1;
1.220 raeburn 3243: }
1.267 raeburn 3244: if (&Apache::lonnet::allowed('mut',$env{'form.ccdomain'})) {
1.334 raeburn 3245: $canshow{'tools'} = 1;
1.267 raeburn 3246: }
1.275 raeburn 3247: if (&Apache::lonnet::allowed('ccc',$env{'form.ccdomain'})) {
1.334 raeburn 3248: $canshow{'requestcourses'} = 1;
1.300 raeburn 3249: } elsif (&Apache::lonnet::allowed('ccc',$env{'request.role.domain'})) {
1.334 raeburn 3250: $canshow{'reqcrsotherdom'} = 1;
1.275 raeburn 3251: }
1.286 raeburn 3252: if (&Apache::lonnet::allowed('mau',$env{'form.ccdomain'})) {
1.334 raeburn 3253: $canshow{'inststatus'} = 1;
1.286 raeburn 3254: }
1.362 raeburn 3255: if (&Apache::lonnet::allowed('cau',$env{'form.ccdomain'})) {
3256: $canshow{'requestauthor'} = 1;
3257: }
1.267 raeburn 3258: my (%changeHash,%changed);
1.286 raeburn 3259: if ($oldinststatus eq '') {
1.334 raeburn 3260: $oldsettings{'inststatus'} = $othertitle;
1.286 raeburn 3261: } else {
3262: if (ref($usertypes) eq 'HASH') {
1.334 raeburn 3263: $oldsettings{'inststatus'} = join(', ',map{ $usertypes->{ &unescape($_) }; } (split(/:/,$userenv{'inststatus'})));
1.286 raeburn 3264: } else {
1.334 raeburn 3265: $oldsettings{'inststatus'} = join(', ',map{ &unescape($_); } (split(/:/,$userenv{'inststatus'})));
1.286 raeburn 3266: }
3267: }
3268: $changeHash{'inststatus'} = $userenv{'inststatus'};
1.334 raeburn 3269: if ($canmodify_status{'inststatus'}) {
3270: $canshow{'inststatus'} = 1;
1.286 raeburn 3271: if (exists($env{'form.inststatus'})) {
3272: my @inststatuses = &Apache::loncommon::get_env_multiple('form.inststatus');
3273: if (@inststatuses > 0) {
3274: $newinststatus = join(':',map { &escape($_); } @inststatuses);
3275: $changeHash{'inststatus'} = $newinststatus;
3276: if ($newinststatus ne $oldinststatus) {
3277: $changed{'inststatus'} = $newinststatus;
1.378 raeburn 3278: foreach my $name ('portfolio','author') {
3279: ($newdefquota{$name},$newsettingstatus{$name}) =
3280: &Apache::loncommon::default_quota($env{'form.ccdomain'},$newinststatus,$name);
3281: }
1.286 raeburn 3282: }
3283: if (ref($usertypes) eq 'HASH') {
1.334 raeburn 3284: $newsettings{'inststatus'} = join(', ',map{ $usertypes->{$_}; } (@inststatuses));
1.286 raeburn 3285: } else {
1.337 raeburn 3286: $newsettings{'inststatus'} = join(', ',@inststatuses);
1.286 raeburn 3287: }
1.334 raeburn 3288: }
3289: } else {
3290: $newinststatus = '';
3291: $changeHash{'inststatus'} = $newinststatus;
3292: $newsettings{'inststatus'} = $othertitle;
3293: if ($newinststatus ne $oldinststatus) {
3294: $changed{'inststatus'} = $changeHash{'inststatus'};
1.378 raeburn 3295: foreach my $name ('portfolio','author') {
3296: ($newdefquota{$name},$newsettingstatus{$name}) =
3297: &Apache::loncommon::default_quota($env{'form.ccdomain'},$newinststatus,$name);
3298: }
1.286 raeburn 3299: }
3300: }
1.334 raeburn 3301: } elsif ($context ne 'selfcreate') {
3302: $canshow{'inststatus'} = 1;
1.337 raeburn 3303: $newsettings{'inststatus'} = $oldsettings{'inststatus'};
1.286 raeburn 3304: }
1.378 raeburn 3305: foreach my $name ('portfolio','author') {
3306: $changeHash{$name.'quota'} = $userenv{$name.'quota'};
3307: }
1.334 raeburn 3308: if ($context eq 'domain') {
1.378 raeburn 3309: foreach my $name ('portfolio','author') {
3310: if ($userenv{$name.'quota'} ne '') {
3311: $oldquota{$name} = $userenv{$name.'quota'};
3312: if ($env{'form.custom_'.$name.'quota'} == 1) {
3313: if ($env{'form.'.$name.'quota'} eq '') {
3314: $newquota{$name} = 0;
3315: } else {
3316: $newquota{$name} = $env{'form.'.$name.'quota'};
3317: $newquota{$name} =~ s/[^\d\.]//g;
3318: }
3319: if ($newquota{$name} != $oldquota{$name}) {
3320: if ("a_admin($newquota{$name},\%changeHash,$name)) {
3321: $changed{$name.'quota'} = 1;
3322: }
3323: }
1.334 raeburn 3324: } else {
1.378 raeburn 3325: if ("a_admin('',\%changeHash,$name)) {
3326: $changed{$name.'quota'} = 1;
3327: $newquota{$name} = $newdefquota{$name};
3328: $newisdefault{$name} = 1;
3329: }
1.334 raeburn 3330: }
1.149 raeburn 3331: } else {
1.378 raeburn 3332: $oldisdefault{$name} = 1;
3333: $oldquota{$name} = $olddefquota{$name};
3334: if ($env{'form.custom_'.$name.'quota'} == 1) {
3335: if ($env{'form.'.$name.'quota'} eq '') {
3336: $newquota{$name} = 0;
3337: } else {
3338: $newquota{$name} = $env{'form.'.$name.'quota'};
3339: $newquota{$name} =~ s/[^\d\.]//g;
3340: }
3341: if ("a_admin($newquota{$name},\%changeHash,$name)) {
3342: $changed{$name.'quota'} = 1;
3343: }
1.334 raeburn 3344: } else {
1.378 raeburn 3345: $newquota{$name} = $newdefquota{$name};
3346: $newisdefault{$name} = 1;
1.334 raeburn 3347: }
1.378 raeburn 3348: }
3349: if ($oldisdefault{$name}) {
3350: $oldsettingstext{'quota'}{$name} = &get_defaultquota_text($oldsettingstatus{$name});
1.383 raeburn 3351: } else {
3352: $oldsettingstext{'quota'}{$name} = &mt('custom quota: [_1] MB',$oldquota{$name});
1.378 raeburn 3353: }
3354: if ($newisdefault{$name}) {
3355: $newsettingstext{'quota'}{$name} = &get_defaultquota_text($newsettingstatus{$name});
1.383 raeburn 3356: } else {
3357: $newsettingstext{'quota'}{$name} = &mt('custom quota: [_1] MB',$newquota{$name});
1.134 raeburn 3358: }
3359: }
1.334 raeburn 3360: &tool_changes('tools',\@usertools,\%oldsettings,\%oldsettingstext,\%userenv,
3361: \%changeHash,\%changed,\%newsettings,\%newsettingstext);
3362: if ($env{'form.ccdomain'} eq $env{'request.role.domain'}) {
3363: &tool_changes('requestcourses',\@requestcourses,\%oldsettings,\%oldsettingstext,
3364: \%userenv,\%changeHash,\%changed,\%newsettings,\%newsettingstext);
1.384 raeburn 3365: &tool_changes('requestauthor',\@requestauthor,\%oldsettings,\%oldsettingstext,
3366: \%userenv,\%changeHash,\%changed,\%newsettings,\%newsettingstext);
1.149 raeburn 3367: } else {
1.334 raeburn 3368: &tool_changes('reqcrsotherdom',\@requestcourses,\%oldsettings,\%oldsettingstext,
3369: \%userenv,\%changeHash,\%changed,\%newsettings,\%newsettingstext);
1.149 raeburn 3370: }
3371: }
1.334 raeburn 3372: foreach my $item (@userinfo) {
3373: if ($env{'form.c'.$item} ne $userenv{$item}) {
3374: $namechanged{$item} = 1;
3375: }
1.204 raeburn 3376: }
1.378 raeburn 3377: foreach my $name ('portfolio','author') {
1.390 bisitz 3378: $oldsettings{'quota'}{$name} = &mt('[_1] MB',$oldquota{$name});
3379: $newsettings{'quota'}{$name} = &mt('[_1] MB',$newquota{$name});
1.378 raeburn 3380: }
1.334 raeburn 3381: if ((keys(%namechanged) > 0) || (keys(%changed) > 0)) {
1.267 raeburn 3382: my ($chgresult,$namechgresult);
3383: if (keys(%changed) > 0) {
3384: $chgresult =
1.204 raeburn 3385: &Apache::lonnet::put('environment',\%changeHash,
3386: $env{'form.ccdomain'},$env{'form.ccuname'});
1.267 raeburn 3387: if ($chgresult eq 'ok') {
3388: if (($env{'user.name'} eq $env{'form.ccuname'}) &&
3389: ($env{'user.domain'} eq $env{'form.ccdomain'})) {
1.270 raeburn 3390: my %newenvhash;
3391: foreach my $key (keys(%changed)) {
1.411 raeburn 3392: if (($key eq 'official') || ($key eq 'unofficial') ||
3393: ($key eq 'community') || ($key eq 'textbook') ||
1.449 raeburn 3394: ($key eq 'placement') || ($key eq 'lti')) {
1.279 raeburn 3395: $newenvhash{'environment.requestcourses.'.$key} =
3396: $changeHash{'requestcourses.'.$key};
1.362 raeburn 3397: if ($changeHash{'requestcourses.'.$key}) {
1.332 raeburn 3398: $newenvhash{'environment.canrequest.'.$key} = 1;
1.279 raeburn 3399: } else {
3400: $newenvhash{'environment.canrequest.'.$key} =
3401: &Apache::lonnet::usertools_access($env{'user.name'},$env{'user.domain'},
3402: $key,'reload','requestcourses');
3403: }
1.362 raeburn 3404: } elsif ($key eq 'requestauthor') {
3405: $newenvhash{'environment.'.$key} = $changeHash{$key};
3406: if ($changeHash{$key}) {
3407: $newenvhash{'environment.canrequest.author'} = 1;
3408: } else {
3409: $newenvhash{'environment.canrequest.author'} =
3410: &Apache::lonnet::usertools_access($env{'user.name'},$env{'user.domain'},
3411: $key,'reload','requestauthor');
3412: }
1.275 raeburn 3413: } elsif ($key ne 'quota') {
1.270 raeburn 3414: $newenvhash{'environment.tools.'.$key} =
3415: $changeHash{'tools.'.$key};
1.279 raeburn 3416: if ($changeHash{'tools.'.$key} ne '') {
3417: $newenvhash{'environment.availabletools.'.$key} =
3418: $changeHash{'tools.'.$key};
3419: } else {
3420: $newenvhash{'environment.availabletools.'.$key} =
1.367 golterma 3421: &Apache::lonnet::usertools_access($env{'user.name'},$env{'user.domain'},
3422: $key,'reload','tools');
1.279 raeburn 3423: }
1.270 raeburn 3424: }
3425: }
1.271 raeburn 3426: if (keys(%newenvhash)) {
3427: &Apache::lonnet::appenv(\%newenvhash);
3428: }
1.267 raeburn 3429: }
3430: }
1.204 raeburn 3431: }
1.334 raeburn 3432: if (keys(%namechanged) > 0) {
1.337 raeburn 3433: foreach my $field (@userinfo) {
3434: $changeHash{$field} = $env{'form.c'.$field};
3435: }
3436: # Make the change
1.204 raeburn 3437: $namechgresult =
3438: &Apache::lonnet::modifyuser($env{'form.ccdomain'},
3439: $env{'form.ccuname'},$changeHash{'id'},undef,undef,
3440: $changeHash{'firstname'},$changeHash{'middlename'},
3441: $changeHash{'lastname'},$changeHash{'generation'},
1.337 raeburn 3442: $changeHash{'id'},undef,$changeHash{'permanentemail'},undef,\@userinfo);
1.220 raeburn 3443: %userupdate = (
3444: lastname => $env{'form.clastname'},
3445: middlename => $env{'form.cmiddlename'},
3446: firstname => $env{'form.cfirstname'},
3447: generation => $env{'form.cgeneration'},
3448: id => $env{'form.cid'},
3449: );
1.204 raeburn 3450: }
1.334 raeburn 3451: if (((keys(%namechanged) > 0) && $namechgresult eq 'ok') ||
1.267 raeburn 3452: ((keys(%changed) > 0) && $chgresult eq 'ok')) {
1.28 matthew 3453: # Tell the user we changed the name
1.334 raeburn 3454: &display_userinfo($r,1,\@disporder,\%canshow,\@requestcourses,
1.362 raeburn 3455: \@usertools,\@requestauthor,\%userenv,\%changed,\%namechanged,
1.334 raeburn 3456: \%oldsettings, \%oldsettingstext,\%newsettings,
3457: \%newsettingstext);
1.203 raeburn 3458: if ($env{'form.cid'} ne $userenv{'id'}) {
3459: &Apache::lonnet::idput($env{'form.ccdomain'},
1.407 raeburn 3460: {$env{'form.ccuname'} => $env{'form.cid'}},$uhome,'ids');
1.203 raeburn 3461: if (($recurseid) &&
3462: (&Apache::lonnet::allowed('mau',$env{'form.ccdomain'}))) {
3463: my $idresult =
3464: &Apache::lonuserutils::propagate_id_change(
3465: $env{'form.ccuname'},$env{'form.ccdomain'},
3466: \%userupdate);
3467: $r->print('<br />'.$idresult.'<br />');
3468: }
1.196 raeburn 3469: }
1.149 raeburn 3470: if (($env{'form.ccdomain'} eq $env{'user.domain'}) &&
3471: ($env{'form.ccuname'} eq $env{'user.name'})) {
3472: my %newenvhash;
3473: foreach my $key (keys(%changeHash)) {
3474: $newenvhash{'environment.'.$key} = $changeHash{$key};
3475: }
1.238 raeburn 3476: &Apache::lonnet::appenv(\%newenvhash);
1.149 raeburn 3477: }
1.28 matthew 3478: } else { # error occurred
1.389 bisitz 3479: $r->print(
3480: '<p class="LC_error">'
3481: .&mt('Unable to successfully change environment for [_1] in domain [_2].',
3482: '"'.$env{'form.ccuname'}.'"',
3483: '"'.$env{'form.ccdomain'}.'"')
3484: .'</p>');
1.28 matthew 3485: }
1.334 raeburn 3486: } else { # End of if ($env ... ) logic
1.275 raeburn 3487: # They did not want to change the users name, quota, tool availability,
3488: # or ability to request creation of courses,
1.267 raeburn 3489: # but we can still tell them what the name and quota and availabilities are
1.334 raeburn 3490: &display_userinfo($r,undef,\@disporder,\%canshow,\@requestcourses,
1.362 raeburn 3491: \@usertools,\@requestauthor,\%userenv,\%changed,\%namechanged,\%oldsettings,
1.334 raeburn 3492: \%oldsettingstext,\%newsettings,\%newsettingstext);
1.28 matthew 3493: }
1.206 raeburn 3494: if (@mod_disallowed) {
3495: my ($rolestr,$contextname);
3496: if (@longroles > 0) {
3497: $rolestr = join(', ',@longroles);
3498: } else {
3499: $rolestr = &mt('No roles');
3500: }
3501: if ($context eq 'course') {
1.399 bisitz 3502: $contextname = 'course';
1.206 raeburn 3503: } elsif ($context eq 'author') {
1.399 bisitz 3504: $contextname = 'co-author';
1.206 raeburn 3505: }
3506: $r->print(&mt('The following fields were not updated: ').'<ul>');
3507: my %fieldtitles = &Apache::loncommon::personal_data_fieldtitles();
3508: foreach my $field (@mod_disallowed) {
3509: $r->print('<li>'.$fieldtitles{$field}.'</li>'."\n");
3510: }
1.207 raeburn 3511: $r->print('</ul>');
3512: if (@mod_disallowed == 1) {
1.399 bisitz 3513: $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 3514: } else {
1.399 bisitz 3515: $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 3516: }
1.292 bisitz 3517: my $helplink = 'javascript:helpMenu('."'display'".')';
3518: $r->print('<span class="LC_cusr_emph">'.$rolestr.'</span><br />'
3519: .&mt('Please contact your [_1]helpdesk[_2] for more information.'
3520: ,'<a href="'.$helplink.'">','</a>')
3521: .'<br />');
1.206 raeburn 3522: }
1.259 bisitz 3523: $r->print('<span class="LC_warning">'
3524: .$no_forceid_alert
3525: .&Apache::lonuserutils::print_namespacing_alerts($env{'form.ccdomain'},\%alerts,\%curr_rules)
3526: .'</span>');
1.4 www 3527: }
1.367 golterma 3528: &Apache::lonhtmlcommon::Close_PrgWin($r,\%prog_state);
1.220 raeburn 3529: if ($env{'form.action'} eq 'singlestudent') {
1.375 raeburn 3530: &enroll_single_student($r,$uhome,$amode,$genpwd,$now,$newuser,$context,
3531: $crstype,$showcredits,$defaultcredits);
1.386 bisitz 3532: my $linktext = ($crstype eq 'Community' ?
3533: &mt('Enroll Another Member') : &mt('Enroll Another Student'));
3534: $r->print(
3535: &Apache::lonhtmlcommon::actionbox([
3536: '<a href="javascript:backPage(document.userupdate)">'
3537: .($crstype eq 'Community' ?
3538: &mt('Enroll Another Member') : &mt('Enroll Another Student'))
3539: .'</a>']));
1.220 raeburn 3540: } else {
1.375 raeburn 3541: my @rolechanges = &update_roles($r,$context,$showcredits);
1.334 raeburn 3542: if (keys(%namechanged) > 0) {
1.220 raeburn 3543: if ($context eq 'course') {
3544: if (@userroles > 0) {
1.225 raeburn 3545: if ((@rolechanges == 0) ||
3546: (!(grep(/^st$/,@rolechanges)))) {
3547: if (grep(/^st$/,@userroles)) {
3548: my $classlistupdated =
3549: &Apache::lonuserutils::update_classlist($cdom,
1.220 raeburn 3550: $cnum,$env{'form.ccdomain'},
3551: $env{'form.ccuname'},\%userupdate);
1.225 raeburn 3552: }
1.220 raeburn 3553: }
3554: }
3555: }
3556: }
1.226 raeburn 3557: my $userinfo = &Apache::loncommon::plainname($env{'form.ccuname'},
1.233 raeburn 3558: $env{'form.ccdomain'});
3559: if ($env{'form.popup'}) {
3560: $r->print('<p><a href="javascript:window.close()">'.&mt('Close window').'</a></p>');
3561: } else {
1.367 golterma 3562: $r->print('<br />'.&Apache::lonhtmlcommon::actionbox(['<a href="javascript:backPage(document.userupdate,'."'$env{'form.prevphase'}','modify'".')">'
3563: .&mt('Modify this user: [_1]','<span class="LC_cusr_emph">'.$env{'form.ccuname'}.':'.$env{'form.ccdomain'}.' ('.$userinfo.')</span>').'</a>',
3564: '<a href="javascript:backPage(document.userupdate)">'.&mt('Create/Modify Another User').'</a>']));
1.233 raeburn 3565: }
1.220 raeburn 3566: }
3567: }
3568:
1.334 raeburn 3569: sub display_userinfo {
1.362 raeburn 3570: my ($r,$changed,$order,$canshow,$requestcourses,$usertools,$requestauthor,
3571: $userenv,$changedhash,$namechangedhash,$oldsetting,$oldsettingtext,
1.334 raeburn 3572: $newsetting,$newsettingtext) = @_;
3573: return unless (ref($order) eq 'ARRAY' &&
3574: ref($canshow) eq 'HASH' &&
3575: ref($requestcourses) eq 'ARRAY' &&
1.362 raeburn 3576: ref($requestauthor) eq 'ARRAY' &&
1.334 raeburn 3577: ref($usertools) eq 'ARRAY' &&
3578: ref($userenv) eq 'HASH' &&
3579: ref($changedhash) eq 'HASH' &&
3580: ref($oldsetting) eq 'HASH' &&
3581: ref($oldsettingtext) eq 'HASH' &&
3582: ref($newsetting) eq 'HASH' &&
3583: ref($newsettingtext) eq 'HASH');
3584: my %lt=&Apache::lonlocal::texthash(
1.372 raeburn 3585: 'ui' => 'User Information',
1.334 raeburn 3586: 'uic' => 'User Information Changed',
3587: 'firstname' => 'First Name',
3588: 'middlename' => 'Middle Name',
3589: 'lastname' => 'Last Name',
3590: 'generation' => 'Generation',
3591: 'id' => 'Student/Employee ID',
3592: 'permanentemail' => 'Permanent e-mail address',
1.378 raeburn 3593: 'portfolioquota' => 'Disk space allocated to portfolio files',
1.385 bisitz 3594: 'authorquota' => 'Disk space allocated to Authoring Space',
1.334 raeburn 3595: 'blog' => 'Blog Availability',
1.361 raeburn 3596: 'webdav' => 'WebDAV Availability',
1.334 raeburn 3597: 'aboutme' => 'Personal Information Page Availability',
3598: 'portfolio' => 'Portfolio Availability',
1.459 raeburn 3599: 'timezone' => 'Can set own Time Zone',
1.334 raeburn 3600: 'official' => 'Can Request Official Courses',
3601: 'unofficial' => 'Can Request Unofficial Courses',
3602: 'community' => 'Can Request Communities',
1.384 raeburn 3603: 'textbook' => 'Can Request Textbook Courses',
1.411 raeburn 3604: 'placement' => 'Can Request Placement Tests',
1.449 raeburn 3605: 'lti' => 'Can Request LTI Courses',
1.362 raeburn 3606: 'requestauthor' => 'Can Request Author Role',
1.334 raeburn 3607: 'inststatus' => "Affiliation",
3608: 'prvs' => 'Previous Value:',
3609: 'chto' => 'Changed To:'
3610: );
3611: if ($changed) {
1.372 raeburn 3612: $r->print('<h3>'.$lt{'uic'}.'</h3>'.
1.367 golterma 3613: &Apache::loncommon::start_data_table().
3614: &Apache::loncommon::start_data_table_header_row());
1.334 raeburn 3615: $r->print("<th> </th>\n");
1.367 golterma 3616: $r->print('<th><b>'.$lt{'prvs'}.'</b></th>');
3617: $r->print('<th><span class="LC_nobreak"><b>'.$lt{'chto'}.'</b></span></th>');
3618: $r->print(&Apache::loncommon::end_data_table_header_row());
3619: my @userinfo = ('firstname','middlename','lastname','generation','permanentemail','id');
3620:
1.334 raeburn 3621: foreach my $item (@userinfo) {
3622: my $value = $env{'form.c'.$item};
1.367 golterma 3623: #show changes only:
1.383 raeburn 3624: unless ($value eq $userenv->{$item}){
1.367 golterma 3625: $r->print(&Apache::loncommon::start_data_table_row());
3626: $r->print("<td>$lt{$item}</td>\n");
1.383 raeburn 3627: $r->print("<td>".$userenv->{$item}."</td>\n");
1.367 golterma 3628: $r->print("<td>$value </td>\n");
3629: $r->print(&Apache::loncommon::end_data_table_row());
1.334 raeburn 3630: }
3631: }
3632: foreach my $entry (@{$order}) {
1.383 raeburn 3633: if ($canshow->{$entry}) {
3634: if (($entry eq 'requestcourses') || ($entry eq 'reqcrsotherdom') || ($entry eq 'requestauthor')) {
3635: my @items;
3636: if ($entry eq 'requestauthor') {
3637: @items = ($entry);
3638: } else {
3639: @items = @{$requestcourses};
1.384 raeburn 3640: }
1.383 raeburn 3641: foreach my $item (@items) {
3642: if (($newsetting->{$item} ne $oldsetting->{$item}) ||
3643: ($newsettingtext->{$item} ne $oldsettingtext->{$item})) {
3644: $r->print(&Apache::loncommon::start_data_table_row()."\n");
3645: $r->print("<td>$lt{$item}</td>\n");
3646: $r->print("<td>".$oldsetting->{$item});
3647: if ($oldsettingtext->{$item}) {
3648: if ($oldsetting->{$item}) {
3649: $r->print(' -- ');
3650: }
3651: $r->print($oldsettingtext->{$item});
3652: }
3653: $r->print("</td>\n");
3654: $r->print("<td>".$newsetting->{$item});
3655: if ($newsettingtext->{$item}) {
3656: if ($newsetting->{$item}) {
3657: $r->print(' -- ');
3658: }
3659: $r->print($newsettingtext->{$item});
3660: }
3661: $r->print("</td>\n");
3662: $r->print(&Apache::loncommon::end_data_table_row()."\n");
1.334 raeburn 3663: }
3664: }
3665: } elsif ($entry eq 'tools') {
3666: foreach my $item (@{$usertools}) {
1.383 raeburn 3667: if ($newsetting->{$item} ne $oldsetting->{$item}) {
3668: $r->print(&Apache::loncommon::start_data_table_row()."\n");
3669: $r->print("<td>$lt{$item}</td>\n");
3670: $r->print("<td>".$oldsetting->{$item}.' '.$oldsettingtext->{$item}."</td>\n");
3671: $r->print("<td>".$newsetting->{$item}.' '.$newsettingtext->{$item}."</td>\n");
3672: $r->print(&Apache::loncommon::end_data_table_row()."\n");
1.334 raeburn 3673: }
3674: }
1.378 raeburn 3675: } elsif ($entry eq 'quota') {
3676: if ((ref($oldsetting->{$entry}) eq 'HASH') && (ref($oldsettingtext->{$entry}) eq 'HASH') &&
3677: (ref($newsetting->{$entry}) eq 'HASH') && (ref($newsettingtext->{$entry}) eq 'HASH')) {
3678: foreach my $name ('portfolio','author') {
1.383 raeburn 3679: if ($newsetting->{$entry}->{$name} ne $oldsetting->{$entry}->{$name}) {
3680: $r->print(&Apache::loncommon::start_data_table_row()."\n");
3681: $r->print("<td>$lt{$name.$entry}</td>\n");
3682: $r->print("<td>".$oldsettingtext->{$entry}->{$name}."</td>\n");
3683: $r->print("<td>".$newsettingtext->{$entry}->{$name}."</td>\n");
3684: $r->print(&Apache::loncommon::end_data_table_row()."\n");
1.378 raeburn 3685: }
3686: }
3687: }
1.334 raeburn 3688: } else {
1.383 raeburn 3689: if ($newsetting->{$entry} ne $oldsetting->{$entry}) {
3690: $r->print(&Apache::loncommon::start_data_table_row()."\n");
3691: $r->print("<td>$lt{$entry}</td>\n");
3692: $r->print("<td>".$oldsetting->{$entry}.' '.$oldsettingtext->{$entry}."</td>\n");
3693: $r->print("<td>".$newsetting->{$entry}.' '.$newsettingtext->{$entry}."</td>\n");
3694: $r->print(&Apache::loncommon::end_data_table_row()."\n");
1.334 raeburn 3695: }
3696: }
3697: }
3698: }
1.367 golterma 3699: $r->print(&Apache::loncommon::end_data_table().'<br />');
1.372 raeburn 3700: } else {
3701: $r->print('<h3>'.$lt{'ui'}.'</h3>'.
3702: '<p>'.&mt('No changes made to user information').'</p>');
1.334 raeburn 3703: }
3704: return;
3705: }
3706:
1.275 raeburn 3707: sub tool_changes {
3708: my ($context,$usertools,$oldaccess,$oldaccesstext,$userenv,$changeHash,
3709: $changed,$newaccess,$newaccesstext) = @_;
3710: if (!((ref($usertools) eq 'ARRAY') && (ref($oldaccess) eq 'HASH') &&
3711: (ref($oldaccesstext) eq 'HASH') && (ref($userenv) eq 'HASH') &&
3712: (ref($changeHash) eq 'HASH') && (ref($changed) eq 'HASH') &&
3713: (ref($newaccess) eq 'HASH') && (ref($newaccesstext) eq 'HASH'))) {
3714: return;
3715: }
1.383 raeburn 3716: my %reqdisplay = &requestchange_display();
1.300 raeburn 3717: if ($context eq 'reqcrsotherdom') {
1.309 raeburn 3718: my @options = ('approval','validate','autolimit');
1.306 raeburn 3719: my $optregex = join('|',@options);
1.300 raeburn 3720: my $cdom = $env{'request.role.domain'};
3721: foreach my $tool (@{$usertools}) {
1.383 raeburn 3722: $oldaccesstext->{$tool} = &mt("availability set to 'off'");
1.314 raeburn 3723: $newaccesstext->{$tool} = $oldaccesstext->{$tool};
1.300 raeburn 3724: $changeHash->{$context.'.'.$tool} = $userenv->{$context.'.'.$tool};
1.383 raeburn 3725: my ($newop,$limit);
1.314 raeburn 3726: if ($env{'form.'.$context.'_'.$tool}) {
3727: $newop = $env{'form.'.$context.'_'.$tool};
3728: if ($newop eq 'autolimit') {
1.383 raeburn 3729: $limit = $env{'form.'.$context.'_'.$tool.'_limit'};
1.314 raeburn 3730: $limit =~ s/\D+//g;
3731: $newop .= '='.$limit;
3732: }
3733: }
1.300 raeburn 3734: if ($userenv->{$context.'.'.$tool} eq '') {
1.314 raeburn 3735: if ($newop) {
3736: $changed->{$tool}=&tool_admin($tool,$cdom.':'.$newop,
1.300 raeburn 3737: $changeHash,$context);
3738: if ($changed->{$tool}) {
1.383 raeburn 3739: if ($newop =~ /^autolimit/) {
3740: if ($limit) {
3741: $newaccesstext->{$tool} = &mt('available with automatic approval, up to limit of [quant,_1,request] per user',$limit);
3742: } else {
3743: $newaccesstext->{$tool} = &mt('available with automatic approval (unlimited)');
3744: }
3745: } else {
3746: $newaccesstext->{$tool} = $reqdisplay{$newop};
3747: }
1.300 raeburn 3748: } else {
3749: $newaccesstext->{$tool} = $oldaccesstext->{$tool};
3750: }
3751: }
3752: } else {
3753: my @curr = split(',',$userenv->{$context.'.'.$tool});
3754: my @new;
3755: my $changedoms;
1.314 raeburn 3756: foreach my $req (@curr) {
3757: if ($req =~ /^\Q$cdom\E\:($optregex\=?\d*)$/) {
3758: my $oldop = $1;
1.383 raeburn 3759: if ($oldop =~ /^autolimit=(\d*)/) {
3760: my $limit = $1;
3761: if ($limit) {
3762: $oldaccesstext->{$tool} = &mt('available with automatic approval, up to limit of [quant,_1,request] per user',$limit);
3763: } else {
3764: $oldaccesstext->{$tool} = &mt('available with automatic approval (unlimited)');
3765: }
3766: } else {
3767: $oldaccesstext->{$tool} = $reqdisplay{$oldop};
3768: }
1.314 raeburn 3769: if ($oldop ne $newop) {
3770: $changedoms = 1;
3771: foreach my $item (@curr) {
3772: my ($reqdom,$option) = split(':',$item);
3773: unless ($reqdom eq $cdom) {
3774: push(@new,$item);
3775: }
3776: }
3777: if ($newop) {
3778: push(@new,$cdom.':'.$newop);
1.300 raeburn 3779: }
1.314 raeburn 3780: @new = sort(@new);
1.300 raeburn 3781: }
1.314 raeburn 3782: last;
1.300 raeburn 3783: }
1.314 raeburn 3784: }
3785: if ((!$changedoms) && ($newop)) {
1.300 raeburn 3786: $changedoms = 1;
1.306 raeburn 3787: @new = sort(@curr,$cdom.':'.$newop);
1.300 raeburn 3788: }
3789: if ($changedoms) {
1.314 raeburn 3790: my $newdomstr;
1.300 raeburn 3791: if (@new) {
3792: $newdomstr = join(',',@new);
3793: }
3794: $changed->{$tool}=&tool_admin($tool,$newdomstr,$changeHash,
3795: $context);
3796: if ($changed->{$tool}) {
3797: if ($env{'form.'.$context.'_'.$tool}) {
1.306 raeburn 3798: if ($env{'form.'.$context.'_'.$tool} eq 'autolimit') {
1.314 raeburn 3799: my $limit = $env{'form.'.$context.'_'.$tool.'_limit'};
3800: $limit =~ s/\D+//g;
3801: if ($limit) {
1.383 raeburn 3802: $newaccesstext->{$tool} = &mt('available with automatic approval, up to limit of [quant,_1,request] per user',$limit);
1.314 raeburn 3803: } else {
1.383 raeburn 3804: $newaccesstext->{$tool} = &mt('available with automatic approval (unlimited)');
1.306 raeburn 3805: }
1.314 raeburn 3806: } else {
1.306 raeburn 3807: $newaccesstext->{$tool} = $reqdisplay{$env{'form.'.$context.'_'.$tool}};
3808: }
1.300 raeburn 3809: } else {
1.383 raeburn 3810: $newaccesstext->{$tool} = &mt("availability set to 'off'");
1.300 raeburn 3811: }
3812: }
3813: }
3814: }
3815: }
3816: return;
3817: }
1.275 raeburn 3818: foreach my $tool (@{$usertools}) {
1.383 raeburn 3819: my ($newval,$limit,$envkey);
1.362 raeburn 3820: $envkey = $context.'.'.$tool;
1.306 raeburn 3821: if ($context eq 'requestcourses') {
3822: $newval = $env{'form.crsreq_'.$tool};
3823: if ($newval eq 'autolimit') {
1.383 raeburn 3824: $limit = $env{'form.crsreq_'.$tool.'_limit'};
3825: $limit =~ s/\D+//g;
3826: $newval .= '='.$limit;
1.306 raeburn 3827: }
1.362 raeburn 3828: } elsif ($context eq 'requestauthor') {
3829: $newval = $env{'form.'.$context};
3830: $envkey = $context;
1.314 raeburn 3831: } else {
1.306 raeburn 3832: $newval = $env{'form.'.$context.'_'.$tool};
3833: }
1.362 raeburn 3834: if ($userenv->{$envkey} ne '') {
1.275 raeburn 3835: $oldaccess->{$tool} = &mt('custom');
1.383 raeburn 3836: if (($context eq 'requestcourses') || ($context eq 'requestauthor')) {
3837: if ($userenv->{$envkey} =~ /^autolimit=(\d*)$/) {
3838: my $currlimit = $1;
3839: if ($currlimit eq '') {
3840: $oldaccesstext->{$tool} = &mt('available with automatic approval (unlimited)');
3841: } else {
3842: $oldaccesstext->{$tool} = &mt('available with automatic approval, up to limit of [quant,_1,request] per user',$currlimit);
3843: }
3844: } elsif ($userenv->{$envkey}) {
3845: $oldaccesstext->{$tool} = $reqdisplay{$userenv->{$envkey}};
3846: } else {
3847: $oldaccesstext->{$tool} = &mt("availability set to 'off'");
3848: }
1.275 raeburn 3849: } else {
1.383 raeburn 3850: if ($userenv->{$envkey}) {
3851: $oldaccesstext->{$tool} = &mt("availability set to 'on'");
3852: } else {
3853: $oldaccesstext->{$tool} = &mt("availability set to 'off'");
3854: }
1.275 raeburn 3855: }
1.362 raeburn 3856: $changeHash->{$envkey} = $userenv->{$envkey};
1.275 raeburn 3857: if ($env{'form.custom'.$tool} == 1) {
1.362 raeburn 3858: if ($newval ne $userenv->{$envkey}) {
1.306 raeburn 3859: $changed->{$tool} = &tool_admin($tool,$newval,$changeHash,
3860: $context);
1.275 raeburn 3861: if ($changed->{$tool}) {
3862: $newaccess->{$tool} = &mt('custom');
1.383 raeburn 3863: if (($context eq 'requestcourses') || ($context eq 'requestauthor')) {
3864: if ($newval =~ /^autolimit/) {
3865: if ($limit) {
3866: $newaccesstext->{$tool} = &mt('available with automatic approval, up to limit of [quant,_1,request] per user',$limit);
3867: } else {
3868: $newaccesstext->{$tool} = &mt('available with automatic approval (unlimited)');
3869: }
3870: } elsif ($newval) {
3871: $newaccesstext->{$tool} = $reqdisplay{$newval};
3872: } else {
3873: $newaccesstext->{$tool} = &mt("availability set to 'off'");
3874: }
1.275 raeburn 3875: } else {
1.383 raeburn 3876: if ($newval) {
3877: $newaccesstext->{$tool} = &mt("availability set to 'on'");
3878: } else {
3879: $newaccesstext->{$tool} = &mt("availability set to 'off'");
3880: }
1.275 raeburn 3881: }
3882: } else {
3883: $newaccess->{$tool} = $oldaccess->{$tool};
1.383 raeburn 3884: if (($context eq 'requestcourses') || ($context eq 'requestauthor')) {
3885: if ($newval =~ /^autolimit/) {
3886: if ($limit) {
3887: $newaccesstext->{$tool} = &mt('available with automatic approval, up to limit of [quant,_1,request] per user',$limit);
3888: } else {
3889: $newaccesstext->{$tool} = &mt('available with automatic approval (unlimited)');
3890: }
3891: } elsif ($newval) {
3892: $newaccesstext->{$tool} = $reqdisplay{$newval};
3893: } else {
3894: $newaccesstext->{$tool} = &mt("availability set to 'off'");
3895: }
1.275 raeburn 3896: } else {
1.383 raeburn 3897: if ($userenv->{$context.'.'.$tool}) {
3898: $newaccesstext->{$tool} = &mt("availability set to 'on'");
3899: } else {
3900: $newaccesstext->{$tool} = &mt("availability set to 'off'");
3901: }
1.275 raeburn 3902: }
3903: }
3904: } else {
3905: $newaccess->{$tool} = $oldaccess->{$tool};
3906: $newaccesstext->{$tool} = $oldaccesstext->{$tool};
3907: }
3908: } else {
3909: $changed->{$tool} = &tool_admin($tool,'',$changeHash,$context);
3910: if ($changed->{$tool}) {
3911: $newaccess->{$tool} = &mt('default');
3912: } else {
3913: $newaccess->{$tool} = $oldaccess->{$tool};
1.383 raeburn 3914: if (($context eq 'requestcourses') || ($context eq 'requestauthor')) {
3915: if ($newval =~ /^autolimit/) {
3916: if ($limit) {
3917: $newaccesstext->{$tool} = &mt('available with automatic approval, up to limit of [quant,_1,request] per user',$limit);
3918: } else {
3919: $newaccesstext->{$tool} = &mt('available with automatic approval (unlimited)');
3920: }
3921: } elsif ($newval) {
3922: $newaccesstext->{$tool} = $reqdisplay{$newval};
3923: } else {
3924: $newaccesstext->{$tool} = &mt("availability set to 'off'");
3925: }
1.275 raeburn 3926: } else {
1.383 raeburn 3927: if ($userenv->{$context.'.'.$tool}) {
3928: $newaccesstext->{$tool} = &mt("availability set to 'on'");
3929: } else {
3930: $newaccesstext->{$tool} = &mt("availability set to 'off'");
3931: }
1.275 raeburn 3932: }
3933: }
3934: }
3935: } else {
3936: $oldaccess->{$tool} = &mt('default');
3937: if ($env{'form.custom'.$tool} == 1) {
1.306 raeburn 3938: $changed->{$tool} = &tool_admin($tool,$newval,$changeHash,
3939: $context);
1.275 raeburn 3940: if ($changed->{$tool}) {
3941: $newaccess->{$tool} = &mt('custom');
1.383 raeburn 3942: if (($context eq 'requestcourses') || ($context eq 'requestauthor')) {
3943: if ($newval =~ /^autolimit/) {
3944: if ($limit) {
3945: $newaccesstext->{$tool} = &mt('available with automatic approval, up to limit of [quant,_1,request] per user',$limit);
3946: } else {
3947: $newaccesstext->{$tool} = &mt('available with automatic approval (unlimited)');
3948: }
3949: } elsif ($newval) {
3950: $newaccesstext->{$tool} = $reqdisplay{$newval};
3951: } else {
3952: $newaccesstext->{$tool} = &mt("availability set to 'off'");
3953: }
1.275 raeburn 3954: } else {
1.383 raeburn 3955: if ($newval) {
3956: $newaccesstext->{$tool} = &mt("availability set to 'on'");
3957: } else {
3958: $newaccesstext->{$tool} = &mt("availability set to 'off'");
3959: }
1.275 raeburn 3960: }
3961: } else {
3962: $newaccess->{$tool} = $oldaccess->{$tool};
3963: }
3964: } else {
3965: $newaccess->{$tool} = $oldaccess->{$tool};
3966: }
3967: }
3968: }
3969: return;
3970: }
3971:
1.220 raeburn 3972: sub update_roles {
1.375 raeburn 3973: my ($r,$context,$showcredits) = @_;
1.4 www 3974: my $now=time;
1.225 raeburn 3975: my @rolechanges;
1.220 raeburn 3976: my %disallowed;
1.73 sakharuk 3977: $r->print('<h3>'.&mt('Modifying Roles').'</h3>');
1.404 raeburn 3978: foreach my $key (keys(%env)) {
1.135 raeburn 3979: next if (! $env{$key});
1.190 raeburn 3980: next if ($key eq 'form.action');
1.27 matthew 3981: # Revoke roles
1.135 raeburn 3982: if ($key=~/^form\.rev/) {
3983: if ($key=~/^form\.rev\:([^\_]+)\_([^\_\.]+)$/) {
1.64 www 3984: # Revoke standard role
1.170 albertel 3985: my ($scope,$role) = ($1,$2);
3986: my $result =
3987: &Apache::lonnet::revokerole($env{'form.ccdomain'},
3988: $env{'form.ccuname'},
1.239 raeburn 3989: $scope,$role,'','',$context);
1.367 golterma 3990: $r->print(&Apache::lonhtmlcommon::confirm_success(
1.369 bisitz 3991: &mt('Revoking [_1] in [_2]',
3992: &Apache::lonnet::plaintext($role),
1.372 raeburn 3993: &Apache::loncommon::show_role_extent($scope,$context,$role)),
1.369 bisitz 3994: $result ne "ok").'<br />');
3995: if ($result ne "ok") {
3996: $r->print(&mt('Error: [_1]',$result).'<br />');
3997: }
1.170 albertel 3998: if ($role eq 'st') {
1.202 raeburn 3999: my $result =
1.198 raeburn 4000: &Apache::lonuserutils::classlist_drop($scope,
4001: $env{'form.ccuname'},$env{'form.ccdomain'},
1.202 raeburn 4002: $now);
1.367 golterma 4003: $r->print(&Apache::lonhtmlcommon::confirm_success($result));
1.53 www 4004: }
1.225 raeburn 4005: if (!grep(/^\Q$role\E$/,@rolechanges)) {
4006: push(@rolechanges,$role);
4007: }
1.196 raeburn 4008: }
1.195 raeburn 4009: if ($key=~m{^form\.rev\:([^_]+)_cr\.cr/($match_domain)/($match_username)/(\w+)$}s) {
1.64 www 4010: # Revoke custom role
1.369 bisitz 4011: my $result = &Apache::lonnet::revokecustomrole(
4012: $env{'form.ccdomain'},$env{'form.ccuname'},$1,$2,$3,$4,'','',$context);
1.367 golterma 4013: $r->print(&Apache::lonhtmlcommon::confirm_success(
1.369 bisitz 4014: &mt('Revoking custom role [_1] by [_2] in [_3]',
1.372 raeburn 4015: $4,$3.':'.$2,&Apache::loncommon::show_role_extent($1,$context,'cr')),
1.369 bisitz 4016: $result ne 'ok').'<br />');
4017: if ($result ne "ok") {
4018: $r->print(&mt('Error: [_1]',$result).'<br />');
4019: }
1.225 raeburn 4020: if (!grep(/^cr$/,@rolechanges)) {
4021: push(@rolechanges,'cr');
4022: }
1.64 www 4023: }
1.135 raeburn 4024: } elsif ($key=~/^form\.del/) {
4025: if ($key=~/^form\.del\:([^\_]+)\_([^\_\.]+)$/) {
1.116 raeburn 4026: # Delete standard role
1.170 albertel 4027: my ($scope,$role) = ($1,$2);
4028: my $result =
4029: &Apache::lonnet::assignrole($env{'form.ccdomain'},
4030: $env{'form.ccuname'},
1.239 raeburn 4031: $scope,$role,$now,0,1,'',
4032: $context);
1.367 golterma 4033: $r->print(&Apache::lonhtmlcommon::confirm_success(
4034: &mt('Deleting [_1] in [_2]',
1.369 bisitz 4035: &Apache::lonnet::plaintext($role),
1.372 raeburn 4036: &Apache::loncommon::show_role_extent($scope,$context,$role)),
1.369 bisitz 4037: $result ne 'ok').'<br />');
4038: if ($result ne "ok") {
4039: $r->print(&mt('Error: [_1]',$result).'<br />');
4040: }
1.367 golterma 4041:
1.170 albertel 4042: if ($role eq 'st') {
1.202 raeburn 4043: my $result =
1.198 raeburn 4044: &Apache::lonuserutils::classlist_drop($scope,
4045: $env{'form.ccuname'},$env{'form.ccdomain'},
1.202 raeburn 4046: $now);
1.369 bisitz 4047: $r->print(&Apache::lonhtmlcommon::confirm_success($result));
1.81 albertel 4048: }
1.225 raeburn 4049: if (!grep(/^\Q$role\E$/,@rolechanges)) {
4050: push(@rolechanges,$role);
4051: }
1.116 raeburn 4052: }
1.139 albertel 4053: if ($key=~m{^form\.del\:([^_]+)_cr\.cr/($match_domain)/($match_username)/(\w+)$}) {
1.116 raeburn 4054: my ($url,$rdom,$rnam,$rolename) = ($1,$2,$3,$4);
4055: # Delete custom role
1.369 bisitz 4056: my $result =
4057: &Apache::lonnet::assigncustomrole($env{'form.ccdomain'},
4058: $env{'form.ccuname'},$url,$rdom,$rnam,$rolename,$now,
4059: 0,1,$context);
4060: $r->print(&Apache::lonhtmlcommon::confirm_success(&mt('Deleting custom role [_1] by [_2] in [_3]',
1.372 raeburn 4061: $rolename,$rnam.':'.$rdom,&Apache::loncommon::show_role_extent($1,$context,'cr')),
1.369 bisitz 4062: $result ne "ok").'<br />');
4063: if ($result ne "ok") {
4064: $r->print(&mt('Error: [_1]',$result).'<br />');
4065: }
1.367 golterma 4066:
1.225 raeburn 4067: if (!grep(/^cr$/,@rolechanges)) {
4068: push(@rolechanges,'cr');
4069: }
1.116 raeburn 4070: }
1.135 raeburn 4071: } elsif ($key=~/^form\.ren/) {
1.101 albertel 4072: my $udom = $env{'form.ccdomain'};
4073: my $uname = $env{'form.ccuname'};
1.116 raeburn 4074: # Re-enable standard role
1.135 raeburn 4075: if ($key=~/^form\.ren\:([^\_]+)\_([^\_\.]+)$/) {
1.89 raeburn 4076: my $url = $1;
4077: my $role = $2;
4078: my $logmsg;
4079: my $output;
4080: if ($role eq 'st') {
1.141 albertel 4081: if ($url =~ m-^/($match_domain)/($match_courseid)/?(\w*)$-) {
1.374 raeburn 4082: my ($cdom,$cnum,$csec) = ($1,$2,$3);
1.375 raeburn 4083: my $credits;
4084: if ($showcredits) {
4085: my $defaultcredits =
4086: &Apache::lonuserutils::get_defaultcredits($cdom,$cnum);
4087: $credits = &get_user_credits($defaultcredits,$cdom,$cnum);
4088: }
4089: my $result = &Apache::loncommon::commit_studentrole(\$logmsg,$udom,$uname,$url,$role,$now,0,$cdom,$cnum,$csec,$context,$credits);
1.220 raeburn 4090: if (($result =~ /^error/) || ($result eq 'not_in_class') || ($result eq 'unknown_course') || ($result eq 'refused')) {
1.223 raeburn 4091: if ($result eq 'refused' && $logmsg) {
4092: $output = $logmsg;
4093: } else {
1.369 bisitz 4094: $output = &mt('Error: [_1]',$result)."\n";
1.223 raeburn 4095: }
1.89 raeburn 4096: } else {
1.372 raeburn 4097: $output = &Apache::lonhtmlcommon::confirm_success(&mt('Assigning [_1] in [_2] starting [_3]',
4098: &Apache::lonnet::plaintext($role),
4099: &Apache::loncommon::show_role_extent($url,$context,'st'),
4100: &Apache::lonlocal::locallocaltime($now))).'<br />'.$logmsg.'<br />';
1.89 raeburn 4101: }
4102: }
4103: } else {
1.101 albertel 4104: my $result=&Apache::lonnet::assignrole($env{'form.ccdomain'},
1.239 raeburn 4105: $env{'form.ccuname'},$url,$role,0,$now,'','',
4106: $context);
1.461 raeburn 4107: $output = &Apache::lonhtmlcommon::confirm_success(&mt('Re-enabling [_1] in [_2]',
4108: &Apache::lonnet::plaintext($role),
4109: &Apache::loncommon::show_role_extent($url,$context,$role)),$result ne "ok").'<br />';
1.369 bisitz 4110: if ($result ne "ok") {
4111: $output .= &mt('Error: [_1]',$result).'<br />';
4112: }
4113: }
1.89 raeburn 4114: $r->print($output);
1.225 raeburn 4115: if (!grep(/^\Q$role\E$/,@rolechanges)) {
4116: push(@rolechanges,$role);
4117: }
1.113 raeburn 4118: }
1.116 raeburn 4119: # Re-enable custom role
1.139 albertel 4120: if ($key=~m{^form\.ren\:([^_]+)_cr\.cr/($match_domain)/($match_username)/(\w+)$}) {
1.116 raeburn 4121: my ($url,$rdom,$rnam,$rolename) = ($1,$2,$3,$4);
4122: my $result = &Apache::lonnet::assigncustomrole(
4123: $env{'form.ccdomain'}, $env{'form.ccuname'},
1.240 raeburn 4124: $url,$rdom,$rnam,$rolename,0,$now,undef,$context);
1.369 bisitz 4125: $r->print(&Apache::lonhtmlcommon::confirm_success(
4126: &mt('Re-enabling custom role [_1] by [_2] in [_3]',
1.372 raeburn 4127: $rolename,$rnam.':'.$rdom,&Apache::loncommon::show_role_extent($1,$context,'cr')),
1.369 bisitz 4128: $result ne "ok").'<br />');
4129: if ($result ne "ok") {
4130: $r->print(&mt('Error: [_1]',$result).'<br />');
4131: }
1.225 raeburn 4132: if (!grep(/^cr$/,@rolechanges)) {
4133: push(@rolechanges,'cr');
4134: }
1.116 raeburn 4135: }
1.135 raeburn 4136: } elsif ($key=~/^form\.act/) {
1.101 albertel 4137: my $udom = $env{'form.ccdomain'};
4138: my $uname = $env{'form.ccuname'};
1.141 albertel 4139: if ($key=~/^form\.act\_($match_domain)\_($match_courseid)\_cr_cr_($match_domain)_($match_username)_([^\_]+)$/) {
1.65 www 4140: # Activate a custom role
1.83 albertel 4141: my ($one,$two,$three,$four,$five)=($1,$2,$3,$4,$5);
4142: my $url='/'.$one.'/'.$two;
4143: my $full=$one.'_'.$two.'_cr_cr_'.$three.'_'.$four.'_'.$five;
1.65 www 4144:
1.101 albertel 4145: my $start = ( $env{'form.start_'.$full} ?
4146: $env{'form.start_'.$full} :
1.88 raeburn 4147: $now );
1.101 albertel 4148: my $end = ( $env{'form.end_'.$full} ?
4149: $env{'form.end_'.$full} :
1.88 raeburn 4150: 0 );
4151:
4152: # split multiple sections
4153: my %sections = ();
1.461 raeburn 4154: my $num_sections = &build_roles($env{'form.sec_'.$full},\%sections,$five);
1.88 raeburn 4155: if ($num_sections == 0) {
1.240 raeburn 4156: $r->print(&Apache::loncommon::commit_customrole($udom,$uname,$url,$three,$four,$five,$start,$end,$context));
1.88 raeburn 4157: } else {
1.114 albertel 4158: my %curr_groups =
1.117 raeburn 4159: &Apache::longroup::coursegroups($one,$two);
1.404 raeburn 4160: foreach my $sec (sort {$a cmp $b} keys(%sections)) {
1.113 raeburn 4161: if (($sec eq 'none') || ($sec eq 'all') ||
4162: exists($curr_groups{$sec})) {
4163: $disallowed{$sec} = $url;
4164: next;
4165: }
4166: my $securl = $url.'/'.$sec;
1.240 raeburn 4167: $r->print(&Apache::loncommon::commit_customrole($udom,$uname,$securl,$three,$four,$five,$start,$end,$context));
1.88 raeburn 4168: }
4169: }
1.225 raeburn 4170: if (!grep(/^cr$/,@rolechanges)) {
4171: push(@rolechanges,'cr');
4172: }
1.142 raeburn 4173: } elsif ($key=~/^form\.act\_($match_domain)\_($match_name)\_([^\_]+)$/) {
1.27 matthew 4174: # Activate roles for sections with 3 id numbers
4175: # set start, end times, and the url for the class
1.83 albertel 4176: my ($one,$two,$three)=($1,$2,$3);
1.461 raeburn 4177: my $start = ( $env{'form.start_'.$one.'_'.$two.'_'.$three} ?
4178: $env{'form.start_'.$one.'_'.$two.'_'.$three} :
1.27 matthew 4179: $now );
1.461 raeburn 4180: my $end = ( $env{'form.end_'.$one.'_'.$two.'_'.$three} ?
1.101 albertel 4181: $env{'form.end_'.$one.'_'.$two.'_'.$three} :
1.27 matthew 4182: 0 );
1.83 albertel 4183: my $url='/'.$one.'/'.$two;
1.88 raeburn 4184: my $type = 'three';
4185: # split multiple sections
4186: my %sections = ();
1.101 albertel 4187: my $num_sections = &build_roles($env{'form.sec_'.$one.'_'.$two.'_'.$three},\%sections,$three);
1.375 raeburn 4188: my $credits;
4189: if ($three eq 'st') {
1.461 raeburn 4190: if ($showcredits) {
1.375 raeburn 4191: my $defaultcredits =
4192: &Apache::lonuserutils::get_defaultcredits($one,$two);
4193: $credits = $env{'form.credits_'.$one.'_'.$two.'_'.$three};
4194: $credits =~ s/[^\d\.]//g;
4195: if ($credits eq $defaultcredits) {
4196: undef($credits);
4197: }
4198: }
4199: }
1.88 raeburn 4200: if ($num_sections == 0) {
1.375 raeburn 4201: $r->print(&Apache::loncommon::commit_standardrole($udom,$uname,$url,$three,$start,$end,$one,$two,'',$context,$credits));
1.88 raeburn 4202: } else {
1.114 albertel 4203: my %curr_groups =
1.117 raeburn 4204: &Apache::longroup::coursegroups($one,$two);
1.88 raeburn 4205: my $emptysec = 0;
1.404 raeburn 4206: foreach my $sec (sort {$a cmp $b} keys(%sections)) {
1.88 raeburn 4207: $sec =~ s/\W//g;
1.113 raeburn 4208: if ($sec ne '') {
4209: if (($sec eq 'none') || ($sec eq 'all') ||
4210: exists($curr_groups{$sec})) {
4211: $disallowed{$sec} = $url;
4212: next;
4213: }
1.88 raeburn 4214: my $securl = $url.'/'.$sec;
1.375 raeburn 4215: $r->print(&Apache::loncommon::commit_standardrole($udom,$uname,$securl,$three,$start,$end,$one,$two,$sec,$context,$credits));
1.88 raeburn 4216: } else {
4217: $emptysec = 1;
4218: }
4219: }
4220: if ($emptysec) {
1.375 raeburn 4221: $r->print(&Apache::loncommon::commit_standardrole($udom,$uname,$url,$three,$start,$end,$one,$two,'',$context,$credits));
1.88 raeburn 4222: }
1.225 raeburn 4223: }
4224: if (!grep(/^\Q$three\E$/,@rolechanges)) {
4225: push(@rolechanges,$three);
4226: }
1.135 raeburn 4227: } elsif ($key=~/^form\.act\_([^\_]+)\_([^\_]+)$/) {
1.27 matthew 4228: # Activate roles for sections with two id numbers
4229: # set start, end times, and the url for the class
1.461 raeburn 4230: my $start = ( $env{'form.start_'.$1.'_'.$2} ?
4231: $env{'form.start_'.$1.'_'.$2} :
1.27 matthew 4232: $now );
1.461 raeburn 4233: my $end = ( $env{'form.end_'.$1.'_'.$2} ?
1.101 albertel 4234: $env{'form.end_'.$1.'_'.$2} :
1.27 matthew 4235: 0 );
1.225 raeburn 4236: my $one = $1;
4237: my $two = $2;
4238: my $url='/'.$one.'/';
1.88 raeburn 4239: # split multiple sections
4240: my %sections = ();
1.225 raeburn 4241: my $num_sections = &build_roles($env{'form.sec_'.$one.'_'.$two},\%sections,$two);
1.88 raeburn 4242: if ($num_sections == 0) {
1.240 raeburn 4243: $r->print(&Apache::loncommon::commit_standardrole($udom,$uname,$url,$two,$start,$end,$one,undef,'',$context));
1.88 raeburn 4244: } else {
4245: my $emptysec = 0;
1.404 raeburn 4246: foreach my $sec (sort {$a cmp $b} keys(%sections)) {
1.88 raeburn 4247: if ($sec ne '') {
4248: my $securl = $url.'/'.$sec;
1.240 raeburn 4249: $r->print(&Apache::loncommon::commit_standardrole($udom,$uname,$securl,$two,$start,$end,$one,undef,$sec,$context));
1.88 raeburn 4250: } else {
4251: $emptysec = 1;
4252: }
4253: }
4254: if ($emptysec) {
1.240 raeburn 4255: $r->print(&Apache::loncommon::commit_standardrole($udom,$uname,$url,$two,$start,$end,$one,undef,'',$context));
1.88 raeburn 4256: }
4257: }
1.225 raeburn 4258: if (!grep(/^\Q$two\E$/,@rolechanges)) {
4259: push(@rolechanges,$two);
4260: }
1.64 www 4261: } else {
1.190 raeburn 4262: $r->print('<p><span class="LC_error">'.&mt('ERROR').': '.&mt('Unknown command').' <tt>'.$key.'</tt></span></p><br />');
1.64 www 4263: }
1.113 raeburn 4264: foreach my $key (sort(keys(%disallowed))) {
1.274 bisitz 4265: $r->print('<p class="LC_warning">');
1.113 raeburn 4266: if (($key eq 'none') || ($key eq 'all')) {
1.274 bisitz 4267: $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 4268: } else {
1.274 bisitz 4269: $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 4270: }
1.274 bisitz 4271: $r->print('</p><p>'
4272: .&mt('Please [_1]go back[_2] and choose a different section name.'
4273: ,'<a href="javascript:history.go(-1)'
4274: ,'</a>')
4275: .'</p><br />'
4276: );
1.113 raeburn 4277: }
4278: }
1.101 albertel 4279: } # End of foreach (keys(%env))
1.75 www 4280: # Flush the course logs so reverse user roles immediately updated
1.349 raeburn 4281: $r->register_cleanup(\&Apache::lonnet::flushcourselogs);
1.225 raeburn 4282: if (@rolechanges == 0) {
1.372 raeburn 4283: $r->print('<p>'.&mt('No roles to modify').'</p>');
1.193 raeburn 4284: }
1.225 raeburn 4285: return @rolechanges;
1.220 raeburn 4286: }
4287:
1.375 raeburn 4288: sub get_user_credits {
4289: my ($uname,$udom,$defaultcredits,$cdom,$cnum) = @_;
4290: if ($cdom eq '' || $cnum eq '') {
4291: return unless ($env{'request.course.id'});
4292: $cdom = $env{'course.'.$env{'request.course.id'}.'.domain'};
4293: $cnum = $env{'course.'.$env{'request.course.id'}.'.num'};
4294: }
4295: my $credits;
4296: my %currhash =
4297: &Apache::lonnet::get('classlist',[$uname.':'.$udom],$cdom,$cnum);
4298: if (keys(%currhash) > 0) {
4299: my @items = split(/:/,$currhash{$uname.':'.$udom});
4300: my $crdidx = &Apache::loncoursedata::CL_CREDITS() - 3;
4301: $credits = $items[$crdidx];
4302: $credits =~ s/[^\d\.]//g;
4303: }
4304: if ($credits eq $defaultcredits) {
4305: undef($credits);
4306: }
4307: return $credits;
4308: }
4309:
1.220 raeburn 4310: sub enroll_single_student {
1.375 raeburn 4311: my ($r,$uhome,$amode,$genpwd,$now,$newuser,$context,$crstype,
4312: $showcredits,$defaultcredits) = @_;
1.318 raeburn 4313: $r->print('<h3>');
4314: if ($crstype eq 'Community') {
4315: $r->print(&mt('Enrolling Member'));
4316: } else {
4317: $r->print(&mt('Enrolling Student'));
4318: }
4319: $r->print('</h3>');
1.220 raeburn 4320:
4321: # Remove non alphanumeric values from section
4322: $env{'form.sections'}=~s/\W//g;
4323:
1.375 raeburn 4324: my $credits;
4325: if (($showcredits) && ($env{'form.credits'} ne '')) {
4326: $credits = $env{'form.credits'};
4327: $credits =~ s/[^\d\.]//g;
4328: if ($credits ne '') {
4329: if ($credits eq $defaultcredits) {
4330: undef($credits);
4331: }
4332: }
4333: }
4334:
1.220 raeburn 4335: # Clean out any old student roles the user has in this class.
4336: &Apache::lonuserutils::modifystudent($env{'form.ccdomain'},
4337: $env{'form.ccuname'},$env{'request.course.id'},undef,$uhome);
4338: my ($startdate,$enddate) = &Apache::lonuserutils::get_dates_from_form();
4339: my $enroll_result =
4340: &Apache::lonnet::modify_student_enrollment($env{'form.ccdomain'},
4341: $env{'form.ccuname'},$env{'form.cid'},$env{'form.cfirstname'},
4342: $env{'form.cmiddlename'},$env{'form.clastname'},
4343: $env{'form.generation'},$env{'form.sections'},$enddate,
1.375 raeburn 4344: $startdate,'manual',undef,$env{'request.course.id'},'',$context,
4345: $credits);
1.220 raeburn 4346: if ($enroll_result =~ /^ok/) {
1.381 bisitz 4347: $r->print(&mt('[_1] enrolled','<b>'.$env{'form.ccuname'}.':'.$env{'form.ccdomain'}.'</b>'));
1.220 raeburn 4348: if ($env{'form.sections'} ne '') {
4349: $r->print(' '.&mt('in section [_1]',$env{'form.sections'}));
4350: }
4351: my ($showstart,$showend);
4352: if ($startdate <= $now) {
4353: $showstart = &mt('Access starts immediately');
4354: } else {
4355: $showstart = &mt('Access starts: ').&Apache::lonlocal::locallocaltime($startdate);
4356: }
4357: if ($enddate == 0) {
4358: $showend = &mt('ends: no ending date');
4359: } else {
4360: $showend = &mt('ends: ').&Apache::lonlocal::locallocaltime($enddate);
4361: }
4362: $r->print('.<br />'.$showstart.'; '.$showend);
4363: if ($startdate <= $now && !$newuser) {
1.386 bisitz 4364: $r->print('<p class="LC_info">');
1.318 raeburn 4365: if ($crstype eq 'Community') {
1.392 raeburn 4366: $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 4367: } else {
1.392 raeburn 4368: $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 4369: }
4370: $r->print('</p>');
1.220 raeburn 4371: }
4372: } else {
4373: $r->print(&mt('unable to enroll').": ".$enroll_result);
4374: }
4375: return;
1.188 raeburn 4376: }
4377:
1.204 raeburn 4378: sub get_defaultquota_text {
4379: my ($settingstatus) = @_;
4380: my $defquotatext;
4381: if ($settingstatus eq '') {
1.383 raeburn 4382: $defquotatext = &mt('default');
1.204 raeburn 4383: } else {
4384: my ($usertypes,$order) =
4385: &Apache::lonnet::retrieve_inst_usertypes($env{'form.ccdomain'});
4386: if ($usertypes->{$settingstatus} eq '') {
1.383 raeburn 4387: $defquotatext = &mt('default');
1.204 raeburn 4388: } else {
1.383 raeburn 4389: $defquotatext = &mt('default for [_1]',$usertypes->{$settingstatus});
1.204 raeburn 4390: }
4391: }
4392: return $defquotatext;
4393: }
4394:
1.188 raeburn 4395: sub update_result_form {
4396: my ($uhome) = @_;
4397: my $outcome =
1.367 golterma 4398: '<form name="userupdate" method="post" action="">'."\n";
1.160 raeburn 4399: foreach my $item ('srchby','srchin','srchtype','srchterm','srchdomain','ccuname','ccdomain') {
1.188 raeburn 4400: $outcome .= '<input type="hidden" name="'.$item.'" value="'.$env{'form.'.$item}.'" />'."\n";
1.160 raeburn 4401: }
1.207 raeburn 4402: if ($env{'form.origname'} ne '') {
4403: $outcome .= '<input type="hidden" name="origname" value="'.$env{'form.origname'}.'" />'."\n";
4404: }
1.160 raeburn 4405: foreach my $item ('sortby','seluname','seludom') {
4406: if (exists($env{'form.'.$item})) {
1.188 raeburn 4407: $outcome .= '<input type="hidden" name="'.$item.'" value="'.$env{'form.'.$item}.'" />'."\n";
1.160 raeburn 4408: }
4409: }
1.188 raeburn 4410: if ($uhome eq 'no_host') {
4411: $outcome .= '<input type="hidden" name="forcenewuser" value="1" />'."\n";
4412: }
4413: $outcome .= '<input type="hidden" name="phase" value="" />'."\n".
1.383 raeburn 4414: '<input type="hidden" name="currstate" value="" />'."\n".
4415: '<input type="hidden" name="action" value="'.$env{'form.action'}.'" />'."\n".
1.188 raeburn 4416: '</form>';
4417: return $outcome;
1.4 www 4418: }
4419:
1.149 raeburn 4420: sub quota_admin {
1.378 raeburn 4421: my ($setquota,$changeHash,$name) = @_;
1.149 raeburn 4422: my $quotachanged;
4423: if (&Apache::lonnet::allowed('mpq',$env{'form.ccdomain'})) {
4424: # Current user has quota modification privileges
1.267 raeburn 4425: if (ref($changeHash) eq 'HASH') {
4426: $quotachanged = 1;
1.378 raeburn 4427: $changeHash->{$name.'quota'} = $setquota;
1.267 raeburn 4428: }
1.149 raeburn 4429: }
4430: return $quotachanged;
4431: }
4432:
1.267 raeburn 4433: sub tool_admin {
1.275 raeburn 4434: my ($tool,$settool,$changeHash,$context) = @_;
4435: my $canchange = 0;
1.279 raeburn 4436: if ($context eq 'requestcourses') {
1.275 raeburn 4437: if (&Apache::lonnet::allowed('ccc',$env{'form.ccdomain'})) {
4438: $canchange = 1;
4439: }
1.300 raeburn 4440: } elsif ($context eq 'reqcrsotherdom') {
4441: if (&Apache::lonnet::allowed('ccc',$env{'request.role.domain'})) {
4442: $canchange = 1;
4443: }
1.362 raeburn 4444: } elsif ($context eq 'requestauthor') {
4445: if (&Apache::lonnet::allowed('cau',$env{'request.role.domain'})) {
4446: $canchange = 1;
4447: }
1.275 raeburn 4448: } elsif (&Apache::lonnet::allowed('mut',$env{'form.ccdomain'})) {
4449: # Current user has quota modification privileges
4450: $canchange = 1;
4451: }
1.267 raeburn 4452: my $toolchanged;
1.275 raeburn 4453: if ($canchange) {
1.267 raeburn 4454: if (ref($changeHash) eq 'HASH') {
4455: $toolchanged = 1;
1.362 raeburn 4456: if ($tool eq 'requestauthor') {
4457: $changeHash->{$context} = $settool;
4458: } else {
4459: $changeHash->{$context.'.'.$tool} = $settool;
4460: }
1.267 raeburn 4461: }
4462: }
4463: return $toolchanged;
4464: }
4465:
1.88 raeburn 4466: sub build_roles {
1.89 raeburn 4467: my ($sectionstr,$sections,$role) = @_;
1.88 raeburn 4468: my $num_sections = 0;
4469: if ($sectionstr=~ /,/) {
4470: my @secnums = split/,/,$sectionstr;
1.89 raeburn 4471: if ($role eq 'st') {
4472: $secnums[0] =~ s/\W//g;
4473: $$sections{$secnums[0]} = 1;
4474: $num_sections = 1;
4475: } else {
4476: foreach my $sec (@secnums) {
4477: $sec =~ ~s/\W//g;
1.150 banghart 4478: if (!($sec eq "")) {
1.89 raeburn 4479: if (exists($$sections{$sec})) {
4480: $$sections{$sec} ++;
4481: } else {
4482: $$sections{$sec} = 1;
4483: $num_sections ++;
4484: }
1.88 raeburn 4485: }
4486: }
4487: }
4488: } else {
4489: $sectionstr=~s/\W//g;
4490: unless ($sectionstr eq '') {
4491: $$sections{$sectionstr} = 1;
4492: $num_sections ++;
4493: }
4494: }
1.129 albertel 4495:
1.88 raeburn 4496: return $num_sections;
4497: }
4498:
1.58 www 4499: # ========================================================== Custom Role Editor
4500:
4501: sub custom_role_editor {
1.439 raeburn 4502: my ($r,$context,$brcrum,$prefix,$permission) = @_;
1.324 raeburn 4503: my $action = $env{'form.customroleaction'};
1.439 raeburn 4504: my ($rolename,$helpitem);
1.324 raeburn 4505: if ($action eq 'new') {
4506: $rolename=$env{'form.newrolename'};
4507: } else {
4508: $rolename=$env{'form.rolename'};
1.59 www 4509: }
4510:
1.324 raeburn 4511: my ($crstype,$context);
4512: if ($env{'request.course.id'}) {
4513: $crstype = &Apache::loncommon::course_type();
4514: $context = 'course';
1.439 raeburn 4515: $helpitem = 'Course_Editing_Custom_Roles';
1.324 raeburn 4516: } else {
4517: $context = 'domain';
1.414 raeburn 4518: $crstype = 'course';
1.439 raeburn 4519: $helpitem = 'Domain_Editing_Custom_Roles';
1.324 raeburn 4520: }
1.351 raeburn 4521:
4522: $rolename=~s/[^A-Za-z0-9]//gs;
4523: if (!$rolename || $env{'form.phase'} eq 'pickrole') {
1.439 raeburn 4524: &print_username_entry_form($r,$context,undef,undef,undef,$crstype,$brcrum,
4525: $permission);
1.351 raeburn 4526: return;
4527: }
4528:
1.414 raeburn 4529: my $formname = 'form1';
4530: my %privs=();
4531: my $body_top = '<h2>';
4532: # ------------------------------------------------------- Does this role exist?
1.59 www 4533: my ($rdummy,$roledef)=
4534: &Apache::lonnet::get('roles',["rolesdef_$rolename"]);
4535: if (($rdummy ne 'con_lost') && ($roledef ne '')) {
1.414 raeburn 4536: $body_top .= &mt('Existing Role').' "';
1.61 www 4537: # ------------------------------------------------- Get current role privileges
1.414 raeburn 4538: ($privs{'system'},$privs{'domain'},$privs{'course'})=split(/\_/,$roledef);
4539: if ($privs{'system'} =~ /bre\&S/) {
4540: if ($context eq 'domain') {
1.417 raeburn 4541: $crstype = 'Course';
1.414 raeburn 4542: } elsif ($crstype eq 'Community') {
4543: $privs{'system'} =~ s/bre\&S//;
4544: }
4545: } elsif ($context eq 'domain') {
4546: $crstype = 'Course';
1.324 raeburn 4547: }
1.59 www 4548: } else {
1.414 raeburn 4549: $body_top .= &mt('New Role').' "';
4550: $roledef='';
1.59 www 4551: }
1.153 banghart 4552: $body_top .= $rolename.'"</h2>';
1.414 raeburn 4553:
4554: # ------------------------------------------------------- What can be assigned?
4555: my %full=();
1.417 raeburn 4556: my %levels=(
1.414 raeburn 4557: course => {},
4558: domain => {},
4559: system => {},
4560: );
4561: my %levelscurrent=(
4562: course => {},
4563: domain => {},
4564: system => {},
4565: );
4566: &Apache::lonuserutils::custom_role_privs(\%privs,\%full,\%levels,\%levelscurrent);
1.160 raeburn 4567: my ($jsback,$elements) = &crumb_utilities();
1.414 raeburn 4568: my @templateroles = &Apache::lonuserutils::custom_template_roles($context,$crstype);
1.417 raeburn 4569: my $head_script =
1.414 raeburn 4570: &Apache::lonuserutils::custom_roledefs_js($context,$crstype,$formname,
4571: \%full,\@templateroles,$jsback);
1.351 raeburn 4572: push (@{$brcrum},
1.414 raeburn 4573: {href => "javascript:backPage(document.$formname,'pickrole','')",
1.351 raeburn 4574: text => "Pick custom role",
4575: faq => 282,bug=>'Instructor Interface',},
1.414 raeburn 4576: {href => "javascript:backPage(document.$formname,'','')",
1.351 raeburn 4577: text => "Edit custom role",
4578: faq => 282,
4579: bug => 'Instructor Interface',
1.439 raeburn 4580: help => $helpitem}
1.351 raeburn 4581: );
4582: my $args = { bread_crumbs => $brcrum,
4583: bread_crumbs_component => 'User Management'};
4584: $r->print(&Apache::loncommon::start_page('Custom Role Editor',
4585: $head_script,$args).
4586: $body_top);
1.414 raeburn 4587: $r->print('<form name="'.$formname.'" method="post" action="">'."\n".
4588: &Apache::lonuserutils::custom_role_header($context,$crstype,
4589: \@templateroles,$prefix));
1.264 bisitz 4590:
1.61 www 4591: $r->print(<<ENDCCF);
4592: <input type="hidden" name="phase" value="set_custom_roles" />
4593: <input type="hidden" name="rolename" value="$rolename" />
4594: ENDCCF
1.414 raeburn 4595: $r->print(&Apache::lonuserutils::custom_role_table($crstype,\%full,\%levels,
4596: \%levelscurrent,$prefix));
1.135 raeburn 4597: $r->print(&Apache::loncommon::end_data_table().
1.190 raeburn 4598: '<input type="hidden" name="action" value="'.$env{'form.action'}.'" />'.
1.160 raeburn 4599: '<input type="hidden" name="startrolename" value="'.$env{'form.rolename'}.
1.417 raeburn 4600: '" />'."\n".'<input type="hidden" name="currstate" value="" />'."\n".
1.160 raeburn 4601: '<input type="reset" value="'.&mt("Reset").'" />'."\n".
1.351 raeburn 4602: '<input type="submit" value="'.&mt('Save').'" /></form>');
1.61 www 4603: }
1.414 raeburn 4604:
1.61 www 4605: # ---------------------------------------------------------- Call to definerole
4606: sub set_custom_role {
1.439 raeburn 4607: my ($r,$context,$brcrum,$prefix,$permission) = @_;
1.101 albertel 4608: my $rolename=$env{'form.rolename'};
1.63 www 4609: $rolename=~s/[^A-Za-z0-9]//gs;
1.150 banghart 4610: if (!$rolename) {
1.439 raeburn 4611: &custom_role_editor($r,$context,$brcrum,$prefix,$permission);
1.61 www 4612: return;
4613: }
1.160 raeburn 4614: my ($jsback,$elements) = &crumb_utilities();
1.301 bisitz 4615: my $jscript = '<script type="text/javascript">'
4616: .'// <![CDATA['."\n"
4617: .$jsback."\n"
4618: .'// ]]>'."\n"
4619: .'</script>'."\n";
1.439 raeburn 4620: my $helpitem = 'Course_Editing_Custom_Roles';
4621: if ($context eq 'domain') {
4622: $helpitem = 'Domain_Editing_Custom_Roles';
4623: }
1.352 raeburn 4624: push(@{$brcrum},
4625: {href => "javascript:backPage(document.customresult,'pickrole','')",
4626: text => "Pick custom role",
4627: faq => 282,
4628: bug => 'Instructor Interface',},
4629: {href => "javascript:backPage(document.customresult,'selected_custom_edit','')",
4630: text => "Edit custom role",
4631: faq => 282,
4632: bug => 'Instructor Interface',},
4633: {href => "javascript:backPage(document.customresult,'set_custom_roles','')",
4634: text => "Result",
4635: faq => 282,
4636: bug => 'Instructor Interface',
1.439 raeburn 4637: help => $helpitem,}
1.352 raeburn 4638: );
4639: my $args = { bread_crumbs => $brcrum,
1.414 raeburn 4640: bread_crumbs_component => 'User Management'};
1.351 raeburn 4641: $r->print(&Apache::loncommon::start_page('Save Custom Role',$jscript,$args));
1.160 raeburn 4642:
1.393 raeburn 4643: my $newrole;
1.61 www 4644: my ($rdummy,$roledef)=
1.110 albertel 4645: &Apache::lonnet::get('roles',["rolesdef_$rolename"]);
4646:
1.61 www 4647: # ------------------------------------------------------- Does this role exist?
1.188 raeburn 4648: $r->print('<h3>');
1.61 www 4649: if (($rdummy ne 'con_lost') && ($roledef ne '')) {
1.73 sakharuk 4650: $r->print(&mt('Existing Role').' "');
1.61 www 4651: } else {
1.73 sakharuk 4652: $r->print(&mt('New Role').' "');
1.61 www 4653: $roledef='';
1.393 raeburn 4654: $newrole = 1;
1.61 www 4655: }
1.188 raeburn 4656: $r->print($rolename.'"</h3>');
1.414 raeburn 4657: # ------------------------------------------------- Assign role and show result
1.61 www 4658:
1.387 bisitz 4659: my $errmsg;
1.414 raeburn 4660: my %newprivs = &Apache::lonuserutils::custom_role_update($rolename,$prefix);
4661: # Assign role and return result
4662: my $result = &Apache::lonnet::definerole($rolename,$newprivs{'s'},$newprivs{'d'},
4663: $newprivs{'c'});
1.387 bisitz 4664: if ($result ne 'ok') {
4665: $errmsg = ': '.$result;
4666: }
4667: my $message =
4668: &Apache::lonhtmlcommon::confirm_success(
4669: &mt('Defining Role').$errmsg, ($result eq 'ok' ? 0 : 1));
1.101 albertel 4670: if ($env{'request.course.id'}) {
4671: my $url='/'.$env{'request.course.id'};
1.63 www 4672: $url=~s/\_/\//g;
1.387 bisitz 4673: $result =
4674: &Apache::lonnet::assigncustomrole(
4675: $env{'user.domain'},$env{'user.name'},
4676: $url,
4677: $env{'user.domain'},$env{'user.name'},
4678: $rolename,undef,undef,undef,$context);
4679: if ($result ne 'ok') {
4680: $errmsg = ': '.$result;
4681: }
4682: $message .=
4683: '<br />'
4684: .&Apache::lonhtmlcommon::confirm_success(
4685: &mt('Assigning Role to Self').$errmsg, ($result eq 'ok' ? 0 : 1));
1.63 www 4686: }
1.380 bisitz 4687: $r->print(
1.387 bisitz 4688: &Apache::loncommon::confirmwrapper($message)
4689: .'<br />'
4690: .&Apache::lonhtmlcommon::actionbox([
4691: '<a href="javascript:backPage(document.customresult,'."'pickrole'".')">'
4692: .&mt('Create or edit another custom role')
4693: .'</a>'])
1.380 bisitz 4694: .'<form name="customresult" method="post" action="">'
1.387 bisitz 4695: .&Apache::lonhtmlcommon::echo_form_input([])
4696: .'</form>'
1.380 bisitz 4697: );
1.58 www 4698: }
4699:
1.2 www 4700: # ================================================================ Main Handler
4701: sub handler {
4702: my $r = shift;
4703: if ($r->header_only) {
1.68 www 4704: &Apache::loncommon::content_type($r,'text/html');
1.2 www 4705: $r->send_http_header;
4706: return OK;
4707: }
1.439 raeburn 4708: my ($context,$crstype,$cid,$cnum,$cdom,$allhelpitems);
4709:
1.190 raeburn 4710: if ($env{'request.course.id'}) {
4711: $context = 'course';
1.318 raeburn 4712: $crstype = &Apache::loncommon::course_type();
1.190 raeburn 4713: } elsif ($env{'request.role'} =~ /^au\./) {
1.206 raeburn 4714: $context = 'author';
1.190 raeburn 4715: } else {
4716: $context = 'domain';
4717: }
1.375 raeburn 4718:
1.439 raeburn 4719: my ($permission,$allowed) =
4720: &Apache::lonuserutils::get_permission($context,$crstype);
4721:
4722: if ($allowed) {
4723: my @allhelp;
4724: if ($context eq 'course') {
4725: $cid = $env{'request.course.id'};
4726: $cdom = $env{'course.'.$cid.'.domain'};
4727: $cnum = $env{'course.'.$cid.'.num'};
4728:
4729: if ($permission->{'cusr'}) {
4730: push(@allhelp,'Course_Create_Class_List');
4731: }
4732: if ($permission->{'view'} || $permission->{'cusr'}) {
4733: push(@allhelp,('Course_Change_Privileges','Course_View_Class_List'));
4734: }
4735: if ($permission->{'custom'}) {
4736: push(@allhelp,'Course_Editing_Custom_Roles');
4737: }
4738: if ($permission->{'cusr'}) {
4739: push(@allhelp,('Course_Add_Student','Course_Drop_Student'));
4740: }
4741: unless ($permission->{'cusr_section'}) {
4742: if (&Apache::lonnet::auto_run($cnum,$cdom) && (($permission->{'cusr'}) || ($permission->{'view'}))) {
4743: push(@allhelp,'Course_Automated_Enrollment');
4744: }
4745: if ($permission->{'selfenrolladmin'}) {
4746: push(@allhelp,'Course_Approve_Selfenroll');
4747: }
4748: }
4749: if ($permission->{'grp_manage'}) {
4750: push(@allhelp,'Course_Manage_Group');
4751: }
4752: if ($permission->{'view'} || $permission->{'cusr'}) {
4753: push(@allhelp,'Course_User_Logs');
4754: }
4755: } elsif ($context eq 'author') {
4756: push(@allhelp,('Author_Change_Privileges','Author_Create_Coauthor_List',
4757: 'Author_View_Coauthor_List','Author_User_Logs'));
4758: } else {
4759: if ($permission->{'cusr'}) {
4760: push(@allhelp,'Domain_Change_Privileges');
4761: if ($permission->{'activity'}) {
4762: push(@allhelp,'Domain_User_Access_Logs');
4763: }
4764: push(@allhelp,('Domain_Create_Users','Domain_View_Users_List'));
4765: if ($permission->{'custom'}) {
4766: push(@allhelp,'Domain_Editing_Custom_Roles');
4767: }
4768: push(@allhelp,('Domain_Role_Approvals','Domain_Username_Approvals','Domain_Change_Logs'));
4769: } elsif ($permission->{'view'}) {
4770: push(@allhelp,'Domain_View_Privileges');
4771: if ($permission->{'activity'}) {
4772: push(@allhelp,'Domain_User_Access_Logs');
4773: }
4774: push(@allhelp,('Domain_View_Users_List','Domain_Change_Logs'));
4775: }
4776: }
4777: if (@allhelp) {
4778: $allhelpitems = join(',',@allhelp);
4779: }
4780: }
4781:
1.190 raeburn 4782: &Apache::loncommon::get_unprocessed_cgi($ENV{'QUERY_STRING'},
1.233 raeburn 4783: ['action','state','callingform','roletype','showrole','bulkaction','popup','phase',
1.391 raeburn 4784: 'username','domain','srchterm','srchdomain','srchin','srchby','srchtype','queue']);
1.190 raeburn 4785: &Apache::lonhtmlcommon::clear_breadcrumbs();
1.351 raeburn 4786: my $args;
4787: my $brcrum = [];
4788: my $bread_crumbs_component = 'User Management';
1.391 raeburn 4789: if (($env{'form.action'} ne 'dateselect') && ($env{'form.action'} ne 'displayuserreq')) {
1.351 raeburn 4790: $brcrum = [{href=>"/adm/createuser",
4791: text=>"User Management",
1.439 raeburn 4792: help=>$allhelpitems}
1.351 raeburn 4793: ];
1.202 raeburn 4794: }
1.190 raeburn 4795: if (!$allowed) {
1.358 raeburn 4796: if ($context eq 'course') {
4797: $r->internal_redirect('/adm/viewclasslist');
4798: return OK;
4799: }
1.190 raeburn 4800: $env{'user.error.msg'}=
4801: "/adm/createuser:cst:0:0:Cannot create/modify user data ".
4802: "or view user status.";
4803: return HTTP_NOT_ACCEPTABLE;
4804: }
4805:
4806: &Apache::loncommon::content_type($r,'text/html');
4807: $r->send_http_header;
4808:
1.375 raeburn 4809: my $showcredits;
4810: if ((($context eq 'course') && ($crstype eq 'Course')) ||
4811: ($context eq 'domain')) {
4812: my %domdefaults =
4813: &Apache::lonnet::get_domain_defaults($env{'request.role.domain'});
4814: if ($domdefaults{'officialcredits'} || $domdefaults{'unofficialcredits'}) {
4815: $showcredits = 1;
4816: }
4817: }
4818:
1.190 raeburn 4819: # Main switch on form.action and form.state, as appropriate
4820: if (! exists($env{'form.action'})) {
1.351 raeburn 4821: $args = {bread_crumbs => $brcrum,
4822: bread_crumbs_component => $bread_crumbs_component};
4823: $r->print(&header(undef,$args));
1.318 raeburn 4824: $r->print(&print_main_menu($permission,$context,$crstype));
1.190 raeburn 4825: } elsif ($env{'form.action'} eq 'upload' && $permission->{'cusr'}) {
1.439 raeburn 4826: my $helpitem = 'Course_Create_Class_List';
4827: if ($context eq 'author') {
4828: $helpitem = 'Author_Create_Coauthor_List';
4829: } elsif ($context eq 'domain') {
4830: $helpitem = 'Domain_Create_Users';
4831: }
1.351 raeburn 4832: push(@{$brcrum},
4833: { href => '/adm/createuser?action=upload&state=',
4834: text => 'Upload Users List',
1.439 raeburn 4835: help => $helpitem,
1.351 raeburn 4836: });
4837: $bread_crumbs_component = 'Upload Users List';
4838: $args = {bread_crumbs => $brcrum,
4839: bread_crumbs_component => $bread_crumbs_component};
4840: $r->print(&header(undef,$args));
1.190 raeburn 4841: $r->print('<form name="studentform" method="post" '.
4842: 'enctype="multipart/form-data" '.
4843: ' action="/adm/createuser">'."\n");
4844: if (! exists($env{'form.state'})) {
4845: &Apache::lonuserutils::print_first_users_upload_form($r,$context);
4846: } elsif ($env{'form.state'} eq 'got_file') {
1.448 raeburn 4847: my $result =
4848: &Apache::lonuserutils::print_upload_manager_form($r,$context,
4849: $permission,
4850: $crstype,$showcredits);
4851: if ($result eq 'missingdata') {
4852: delete($env{'form.state'});
4853: &Apache::lonuserutils::print_first_users_upload_form($r,$context);
4854: }
1.190 raeburn 4855: } elsif ($env{'form.state'} eq 'enrolling') {
4856: if ($env{'form.datatoken'}) {
1.448 raeburn 4857: my $result = &Apache::lonuserutils::upfile_drop_add($r,$context,
4858: $permission,
4859: $showcredits);
4860: if ($result eq 'missingdata') {
4861: delete($env{'form.state'});
4862: &Apache::lonuserutils::print_first_users_upload_form($r,$context);
4863: } elsif ($result eq 'invalidhome') {
4864: $env{'form.state'} = 'got_file';
4865: delete($env{'form.lcserver'});
4866: my $result =
4867: &Apache::lonuserutils::print_upload_manager_form($r,$context,$permission,
4868: $crstype,$showcredits);
4869: if ($result eq 'missingdata') {
4870: delete($env{'form.state'});
4871: &Apache::lonuserutils::print_first_users_upload_form($r,$context);
4872: }
4873: }
4874: } else {
4875: delete($env{'form.state'});
4876: &Apache::lonuserutils::print_first_users_upload_form($r,$context);
1.190 raeburn 4877: }
4878: } else {
4879: &Apache::lonuserutils::print_first_users_upload_form($r,$context);
4880: }
1.447 raeburn 4881: $r->print('</form>');
1.416 raeburn 4882: } elsif (((($env{'form.action'} eq 'singleuser') || ($env{'form.action'}
4883: eq 'singlestudent')) && ($permission->{'cusr'})) ||
1.418 raeburn 4884: (($env{'form.action'} eq 'singleuser') && ($permission->{'view'})) ||
1.416 raeburn 4885: (($env{'form.action'} eq 'accesslogs') && ($permission->{'activity'}))) {
1.190 raeburn 4886: my $phase = $env{'form.phase'};
4887: my @search = ('srchterm','srchby','srchin','srchtype','srchdomain');
1.192 albertel 4888: &Apache::loncreateuser::restore_prev_selections();
4889: my $srch;
4890: foreach my $item (@search) {
4891: $srch->{$item} = $env{'form.'.$item};
4892: }
1.207 raeburn 4893: if (($phase eq 'get_user_info') || ($phase eq 'userpicked') ||
1.416 raeburn 4894: ($phase eq 'createnewuser') || ($phase eq 'activity')) {
1.207 raeburn 4895: if ($env{'form.phase'} eq 'createnewuser') {
4896: my $response;
4897: if ($env{'form.srchterm'} !~ /^$match_username$/) {
1.366 bisitz 4898: my $response =
4899: '<span class="LC_warning">'
4900: .&mt('You must specify a valid username. Only the following are allowed:'
4901: .' letters numbers - . @')
4902: .'</span>';
1.221 raeburn 4903: $env{'form.phase'} = '';
1.375 raeburn 4904: &print_username_entry_form($r,$context,$response,$srch,undef,
1.439 raeburn 4905: $crstype,$brcrum,$permission);
1.207 raeburn 4906: } else {
4907: my $ccuname =&LONCAPA::clean_username($srch->{'srchterm'});
4908: my $ccdomain=&LONCAPA::clean_domain($srch->{'srchdomain'});
4909: &print_user_modification_page($r,$ccuname,$ccdomain,
1.221 raeburn 4910: $srch,$response,$context,
1.375 raeburn 4911: $permission,$crstype,$brcrum,
4912: $showcredits);
1.207 raeburn 4913: }
4914: } elsif ($env{'form.phase'} eq 'get_user_info') {
1.190 raeburn 4915: my ($currstate,$response,$forcenewuser,$results) =
1.221 raeburn 4916: &user_search_result($context,$srch);
1.190 raeburn 4917: if ($env{'form.currstate'} eq 'modify') {
4918: $currstate = $env{'form.currstate'};
4919: }
4920: if ($currstate eq 'select') {
4921: &print_user_selection_page($r,$response,$srch,$results,
1.351 raeburn 4922: \@search,$context,undef,$crstype,
4923: $brcrum);
1.416 raeburn 4924: } elsif (($currstate eq 'modify') || ($env{'form.action'} eq 'accesslogs')) {
4925: my ($ccuname,$ccdomain,$uhome);
1.190 raeburn 4926: if (($srch->{'srchby'} eq 'uname') &&
4927: ($srch->{'srchtype'} eq 'exact')) {
4928: $ccuname = $srch->{'srchterm'};
4929: $ccdomain= $srch->{'srchdomain'};
4930: } else {
4931: my @matchedunames = keys(%{$results});
4932: ($ccuname,$ccdomain) = split(/:/,$matchedunames[0]);
4933: }
4934: $ccuname =&LONCAPA::clean_username($ccuname);
4935: $ccdomain=&LONCAPA::clean_domain($ccdomain);
1.416 raeburn 4936: if ($env{'form.action'} eq 'accesslogs') {
4937: my $uhome;
4938: if (($ccuname ne '') && ($ccdomain ne '')) {
4939: $uhome = &Apache::lonnet::homeserver($ccuname,$ccdomain);
4940: }
4941: if (($uhome eq '') || ($uhome eq 'no_host')) {
4942: $env{'form.phase'} = '';
4943: undef($forcenewuser);
4944: #if ($response) {
4945: # unless ($response =~ m{\Q<br /><br />\E$}) {
4946: # $response .= '<br /><br />';
4947: # }
4948: #}
4949: &print_username_entry_form($r,$context,$response,$srch,
1.439 raeburn 4950: $forcenewuser,$crstype,$brcrum,
4951: $permission);
1.416 raeburn 4952: } else {
4953: &print_useraccesslogs_display($r,$ccuname,$ccdomain,$permission,$brcrum);
4954: }
4955: } else {
4956: if ($env{'form.forcenewuser'}) {
4957: $response = '';
4958: }
4959: &print_user_modification_page($r,$ccuname,$ccdomain,
4960: $srch,$response,$context,
4961: $permission,$crstype,$brcrum);
1.190 raeburn 4962: }
4963: } elsif ($currstate eq 'query') {
1.351 raeburn 4964: &print_user_query_page($r,'createuser',$brcrum);
1.190 raeburn 4965: } else {
1.229 raeburn 4966: $env{'form.phase'} = '';
1.207 raeburn 4967: &print_username_entry_form($r,$context,$response,$srch,
1.439 raeburn 4968: $forcenewuser,$crstype,$brcrum,
4969: $permission);
1.190 raeburn 4970: }
4971: } elsif ($env{'form.phase'} eq 'userpicked') {
4972: my $ccuname = &LONCAPA::clean_username($env{'form.seluname'});
4973: my $ccdomain = &LONCAPA::clean_domain($env{'form.seludom'});
1.416 raeburn 4974: if ($env{'form.action'} eq 'accesslogs') {
4975: &print_useraccesslogs_display($r,$ccuname,$ccdomain,$permission,$brcrum);
4976: } else {
4977: &print_user_modification_page($r,$ccuname,$ccdomain,$srch,'',
4978: $context,$permission,$crstype,
4979: $brcrum);
4980: }
4981: } elsif ($env{'form.action'} eq 'accesslogs') {
4982: my $ccuname = &LONCAPA::clean_username($env{'form.accessuname'});
4983: my $ccdomain = &LONCAPA::clean_domain($env{'form.accessudom'});
4984: &print_useraccesslogs_display($r,$ccuname,$ccdomain,$permission,$brcrum);
1.190 raeburn 4985: }
4986: } elsif ($env{'form.phase'} eq 'update_user_data') {
1.451 raeburn 4987: &update_user_data($r,$context,$crstype,$brcrum,$showcredits,$permission);
1.190 raeburn 4988: } else {
1.351 raeburn 4989: &print_username_entry_form($r,$context,undef,$srch,undef,$crstype,
1.439 raeburn 4990: $brcrum,$permission);
1.190 raeburn 4991: }
4992: } elsif ($env{'form.action'} eq 'custom' && $permission->{'custom'}) {
1.414 raeburn 4993: my $prefix;
1.190 raeburn 4994: if ($env{'form.phase'} eq 'set_custom_roles') {
1.439 raeburn 4995: &set_custom_role($r,$context,$brcrum,$prefix,$permission);
1.190 raeburn 4996: } else {
1.439 raeburn 4997: &custom_role_editor($r,$context,$brcrum,$prefix,$permission);
1.190 raeburn 4998: }
1.362 raeburn 4999: } elsif (($env{'form.action'} eq 'processauthorreq') &&
5000: ($permission->{'cusr'}) &&
5001: (&Apache::lonnet::allowed('cau',$env{'request.role.domain'}))) {
5002: push(@{$brcrum},
5003: {href => '/adm/createuser?action=processauthorreq',
1.385 bisitz 5004: text => 'Authoring Space requests',
1.362 raeburn 5005: help => 'Domain_Role_Approvals'});
5006: $bread_crumbs_component = 'Authoring requests';
5007: if ($env{'form.state'} eq 'done') {
5008: push(@{$brcrum},
5009: {href => '/adm/createuser?action=authorreqqueue',
5010: text => 'Result',
5011: help => 'Domain_Role_Approvals'});
5012: $bread_crumbs_component = 'Authoring request result';
5013: }
5014: $args = { bread_crumbs => $brcrum,
5015: bread_crumbs_component => $bread_crumbs_component};
1.391 raeburn 5016: my $js = &usernamerequest_javascript();
5017: $r->print(&header(&add_script($js),$args));
1.362 raeburn 5018: if (!exists($env{'form.state'})) {
5019: $r->print(&Apache::loncoursequeueadmin::display_queued_requests('requestauthor',
5020: $env{'request.role.domain'}));
5021: } elsif ($env{'form.state'} eq 'done') {
5022: $r->print('<h3>'.&mt('Authoring request processing').'</h3>'."\n");
5023: $r->print(&Apache::loncoursequeueadmin::update_request_queue('requestauthor',
5024: $env{'request.role.domain'}));
5025: }
1.391 raeburn 5026: } elsif (($env{'form.action'} eq 'processusernamereq') &&
5027: ($permission->{'cusr'}) &&
5028: (&Apache::lonnet::allowed('cau',$env{'request.role.domain'}))) {
5029: push(@{$brcrum},
5030: {href => '/adm/createuser?action=processusernamereq',
5031: text => 'LON-CAPA account requests',
5032: help => 'Domain_Username_Approvals'});
5033: $bread_crumbs_component = 'Account requests';
5034: if ($env{'form.state'} eq 'done') {
5035: push(@{$brcrum},
5036: {href => '/adm/createuser?action=usernamereqqueue',
5037: text => 'Result',
5038: help => 'Domain_Username_Approvals'});
5039: $bread_crumbs_component = 'LON-CAPA account request result';
5040: }
5041: $args = { bread_crumbs => $brcrum,
5042: bread_crumbs_component => $bread_crumbs_component};
5043: my $js = &usernamerequest_javascript();
5044: $r->print(&header(&add_script($js),$args));
5045: if (!exists($env{'form.state'})) {
5046: $r->print(&Apache::loncoursequeueadmin::display_queued_requests('requestusername',
5047: $env{'request.role.domain'}));
5048: } elsif ($env{'form.state'} eq 'done') {
5049: $r->print('<h3>'.&mt('LON-CAPA account request processing').'</h3>'."\n");
5050: $r->print(&Apache::loncoursequeueadmin::update_request_queue('requestusername',
5051: $env{'request.role.domain'}));
5052: }
5053: } elsif (($env{'form.action'} eq 'displayuserreq') &&
5054: ($permission->{'cusr'})) {
5055: my $dom = $env{'form.domain'};
5056: my $uname = $env{'form.username'};
5057: my $warning;
5058: if (($dom =~ /^$match_domain$/) && (&Apache::lonnet::domain($dom) ne '')) {
5059: if (($dom eq $env{'request.role.domain'}) && (&Apache::lonnet::allowed('ccc',$dom))) {
5060: if (($uname =~ /^$match_username$/) && ($env{'form.queue'} eq 'approval')) {
5061: my $uhome = &Apache::lonnet::homeserver($uname,$dom);
5062: if ($uhome eq 'no_host') {
5063: my $queue = $env{'form.queue'};
5064: my $reqkey = &escape($uname).'_'.$queue;
5065: my $namespace = 'usernamequeue';
5066: my $domconfig = &Apache::lonnet::get_domainconfiguser($dom);
5067: my %queued =
5068: &Apache::lonnet::get($namespace,[$reqkey],$dom,$domconfig);
5069: unless ($queued{$reqkey}) {
5070: $warning = &mt('No information was found for this LON-CAPA account request.');
5071: }
5072: } else {
5073: $warning = &mt('A LON-CAPA account already exists for the requested username and domain.');
5074: }
5075: } else {
5076: $warning = &mt('LON-CAPA account request status check is for an invalid username.');
5077: }
5078: } else {
5079: $warning = &mt('You do not have rights to view LON-CAPA account requests in the domain specified.');
5080: }
5081: } else {
5082: $warning = &mt('LON-CAPA account request status check is for an invalid domain.');
5083: }
5084: my $args = { only_body => 1 };
5085: $r->print(&header(undef,$args).
5086: '<h3>'.&mt('LON-CAPA Account Request Details').'</h3>');
5087: if ($warning ne '') {
5088: $r->print('<div class="LC_warning">'.$warning.'</div>');
5089: } else {
5090: my ($infofields,$infotitles) = &Apache::loncommon::emailusername_info();
5091: my $domconfiguser = &Apache::lonnet::get_domainconfiguser($dom);
5092: my %domconfig = &Apache::lonnet::get_dom('configuration',['usercreation'],$dom);
5093: if (ref($domconfig{'usercreation'}) eq 'HASH') {
5094: if (ref($domconfig{'usercreation'}{'cancreate'}) eq 'HASH') {
5095: if (ref($domconfig{'usercreation'}{'cancreate'}{'emailusername'}) eq 'HASH') {
5096: my %info =
5097: &Apache::lonnet::get('nohist_requestedusernames',[$uname],$dom,$domconfiguser);
5098: if (ref($info{$uname}) eq 'HASH') {
1.396 raeburn 5099: my $usertype = $info{$uname}{'inststatus'};
5100: unless ($usertype) {
5101: $usertype = 'default';
5102: }
1.442 raeburn 5103: my ($showstatus,$showemail,$pickstart);
5104: my $numextras = 0;
5105: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
1.443 raeburn 5106: if ((ref($types) eq 'ARRAY') && (@{$types} > 0)) {
5107: if (ref($usertypes) eq 'HASH') {
5108: if ($usertypes->{$usertype}) {
5109: $showstatus = $usertypes->{$usertype};
5110: } else {
5111: $showstatus = $othertitle;
5112: }
5113: if ($showstatus) {
5114: $numextras ++;
5115: }
1.442 raeburn 5116: }
5117: }
5118: if (($info{$uname}{'email'} ne '') && ($info{$uname}{'email'} ne $uname)) {
5119: $showemail = $info{$uname}{'email'};
5120: $numextras ++;
5121: }
1.396 raeburn 5122: if (ref($domconfig{'usercreation'}{'cancreate'}{'emailusername'}{$usertype}) eq 'HASH') {
5123: if ((ref($infofields) eq 'ARRAY') && (ref($infotitles) eq 'HASH')) {
1.442 raeburn 5124: $pickstart = 1;
1.396 raeburn 5125: $r->print('<div>'.&Apache::lonhtmlcommon::start_pick_box());
1.442 raeburn 5126: my ($num,$count);
1.396 raeburn 5127: $count = scalar(keys(%{$domconfig{'usercreation'}{'cancreate'}{'emailusername'}{$usertype}}));
1.442 raeburn 5128: $count += $numextras;
1.396 raeburn 5129: foreach my $field (@{$infofields}) {
5130: next unless ($domconfig{'usercreation'}{'cancreate'}{'emailusername'}{$usertype}{$field});
5131: next unless ($infotitles->{$field});
5132: $r->print(&Apache::lonhtmlcommon::row_title($infotitles->{$field}).
5133: $info{$uname}{$field});
5134: $num ++;
1.442 raeburn 5135: unless ($count == $num) {
1.396 raeburn 5136: $r->print(&Apache::lonhtmlcommon::row_closure());
5137: }
5138: }
1.442 raeburn 5139: }
5140: }
5141: if ($numextras) {
5142: unless ($pickstart) {
5143: $r->print('<div>'.&Apache::lonhtmlcommon::start_pick_box());
5144: $pickstart = 1;
5145: }
5146: if ($showemail) {
5147: my $closure = '';
5148: unless ($showstatus) {
5149: $closure = 1;
1.391 raeburn 5150: }
1.442 raeburn 5151: $r->print(&Apache::lonhtmlcommon::row_title(&mt('E-mail address')).
5152: $showemail.
5153: &Apache::lonhtmlcommon::row_closure($closure));
1.391 raeburn 5154: }
1.442 raeburn 5155: if ($showstatus) {
5156: $r->print(&Apache::lonhtmlcommon::row_title(&mt('Status type[_1](self-reported)','<br />')).
5157: $showstatus.
5158: &Apache::lonhtmlcommon::row_closure(1));
5159: }
5160: }
5161: if ($pickstart) {
5162: $r->print(&Apache::lonhtmlcommon::end_pick_box().'</div>');
5163: } else {
5164: $r->print('<div>'.&mt('No information to display for this account request.').'</div>');
1.391 raeburn 5165: }
1.442 raeburn 5166: } else {
5167: $r->print('<div>'.&mt('No information available for this account request.').'</div>');
1.391 raeburn 5168: }
5169: }
5170: }
5171: }
5172: }
1.442 raeburn 5173: $r->print(&close_popup_form());
1.207 raeburn 5174: } elsif (($env{'form.action'} eq 'listusers') &&
5175: ($permission->{'view'} || $permission->{'cusr'})) {
1.439 raeburn 5176: my $helpitem = 'Course_View_Class_List';
5177: if ($context eq 'author') {
5178: $helpitem = 'Author_View_Coauthor_List';
5179: } elsif ($context eq 'domain') {
5180: $helpitem = 'Domain_View_Users_List';
5181: }
1.202 raeburn 5182: if ($env{'form.phase'} eq 'bulkchange') {
1.351 raeburn 5183: push(@{$brcrum},
5184: {href => '/adm/createuser?action=listusers',
5185: text => "List Users"},
5186: {href => "/adm/createuser",
5187: text => "Result",
1.439 raeburn 5188: help => $helpitem});
1.351 raeburn 5189: $bread_crumbs_component = 'Update Users';
5190: $args = {bread_crumbs => $brcrum,
5191: bread_crumbs_component => $bread_crumbs_component};
5192: $r->print(&header(undef,$args));
1.202 raeburn 5193: my $setting = $env{'form.roletype'};
5194: my $choice = $env{'form.bulkaction'};
5195: if ($permission->{'cusr'}) {
1.336 raeburn 5196: &Apache::lonuserutils::update_user_list($r,$context,$setting,$choice,$crstype);
1.221 raeburn 5197: } else {
5198: $r->print(&mt('You are not authorized to make bulk changes to user roles'));
1.223 raeburn 5199: $r->print('<p><a href="/adm/createuser?action=listusers">'.&mt('Display User Lists').'</a>');
1.202 raeburn 5200: }
5201: } else {
1.351 raeburn 5202: push(@{$brcrum},
5203: {href => '/adm/createuser?action=listusers',
5204: text => "List Users",
1.439 raeburn 5205: help => $helpitem});
1.351 raeburn 5206: $bread_crumbs_component = 'List Users';
5207: $args = {bread_crumbs => $brcrum,
5208: bread_crumbs_component => $bread_crumbs_component};
1.202 raeburn 5209: my ($cb_jscript,$jscript,$totcodes,$codetitles,$idlist,$idlist_titles);
5210: my $formname = 'studentform';
1.364 raeburn 5211: my $hidecall = "hide_searching();";
1.321 raeburn 5212: if (($context eq 'domain') && (($env{'form.roletype'} eq 'course') ||
5213: ($env{'form.roletype'} eq 'community'))) {
5214: if ($env{'form.roletype'} eq 'course') {
5215: ($cb_jscript,$jscript,$totcodes,$codetitles,$idlist,$idlist_titles) =
5216: &Apache::lonuserutils::courses_selector($env{'request.role.domain'},
5217: $formname);
5218: } elsif ($env{'form.roletype'} eq 'community') {
5219: $cb_jscript =
5220: &Apache::loncommon::coursebrowser_javascript($env{'request.role.domain'});
5221: my %elements = (
5222: coursepick => 'radio',
5223: coursetotal => 'text',
5224: courselist => 'text',
5225: );
5226: $jscript = &Apache::lonhtmlcommon::set_form_elements(\%elements);
5227: }
1.364 raeburn 5228: $jscript .= &verify_user_display($context)."\n".
5229: &Apache::loncommon::check_uncheck_jscript();
1.202 raeburn 5230: my $js = &add_script($jscript).$cb_jscript;
5231: my $loadcode =
5232: &Apache::lonuserutils::course_selector_loadcode($formname);
5233: if ($loadcode ne '') {
1.364 raeburn 5234: $args->{add_entries} = {onload => "$loadcode;$hidecall"};
5235: } else {
5236: $args->{add_entries} = {onload => $hidecall};
1.202 raeburn 5237: }
1.351 raeburn 5238: $r->print(&header($js,$args));
1.191 raeburn 5239: } else {
1.364 raeburn 5240: $args->{add_entries} = {onload => $hidecall};
5241: $jscript = &verify_user_display($context).
5242: &Apache::loncommon::check_uncheck_jscript();
5243: $r->print(&header(&add_script($jscript),$args));
1.191 raeburn 5244: }
1.202 raeburn 5245: &Apache::lonuserutils::print_userlist($r,undef,$permission,$context,
1.375 raeburn 5246: $formname,$totcodes,$codetitles,$idlist,$idlist_titles,
5247: $showcredits);
1.191 raeburn 5248: }
1.213 raeburn 5249: } elsif ($env{'form.action'} eq 'drop' && $permission->{'cusr'}) {
1.318 raeburn 5250: my $brtext;
5251: if ($crstype eq 'Community') {
5252: $brtext = 'Drop Members';
5253: } else {
5254: $brtext = 'Drop Students';
5255: }
1.351 raeburn 5256: push(@{$brcrum},
5257: {href => '/adm/createuser?action=drop',
5258: text => $brtext,
5259: help => 'Course_Drop_Student'});
5260: if ($env{'form.state'} eq 'done') {
5261: push(@{$brcrum},
5262: {href=>'/adm/createuser?action=drop',
5263: text=>"Result"});
5264: }
5265: $bread_crumbs_component = $brtext;
5266: $args = {bread_crumbs => $brcrum,
5267: bread_crumbs_component => $bread_crumbs_component};
5268: $r->print(&header(undef,$args));
1.213 raeburn 5269: if (!exists($env{'form.state'})) {
1.318 raeburn 5270: &Apache::lonuserutils::print_drop_menu($r,$context,$permission,$crstype);
1.213 raeburn 5271: } elsif ($env{'form.state'} eq 'done') {
5272: &Apache::lonuserutils::update_user_list($r,$context,undef,
5273: $env{'form.action'});
5274: }
1.202 raeburn 5275: } elsif ($env{'form.action'} eq 'dateselect') {
5276: if ($permission->{'cusr'}) {
1.351 raeburn 5277: $r->print(&header(undef,{'no_nav_bar' => 1}).
1.375 raeburn 5278: &Apache::lonuserutils::date_section_selector($context,$permission,
5279: $crstype,$showcredits));
1.202 raeburn 5280: } else {
1.351 raeburn 5281: $r->print(&header(undef,{'no_nav_bar' => 1}).
5282: '<span class="LC_error">'.&mt('You do not have permission to modify dates or sections for users').'</span>');
1.202 raeburn 5283: }
1.237 raeburn 5284: } elsif ($env{'form.action'} eq 'selfenroll') {
1.398 raeburn 5285: if ($permission->{selfenrolladmin}) {
5286: my %currsettings = (
5287: selfenroll_types => $env{'course.'.$cid.'.internal.selfenroll_types'},
5288: selfenroll_registered => $env{'course.'.$cid.'.internal.selfenroll_registered'},
5289: selfenroll_section => $env{'course.'.$cid.'.internal.selfenroll_section'},
5290: selfenroll_notifylist => $env{'course.'.$cid.'.internal.selfenroll_notifylist'},
5291: selfenroll_approval => $env{'course.'.$cid.'.internal.selfenroll_approval'},
5292: selfenroll_limit => $env{'course.'.$cid.'.internal.selfenroll_limit'},
5293: selfenroll_cap => $env{'course.'.$cid.'.internal.selfenroll_cap'},
5294: selfenroll_start_date => $env{'course.'.$cid.'.internal.selfenroll_start_date'},
5295: selfenroll_end_date => $env{'course.'.$cid.'.internal.selfenroll_end_date'},
5296: selfenroll_start_access => $env{'course.'.$cid.'.internal.selfenroll_start_access'},
5297: selfenroll_end_access => $env{'course.'.$cid.'.internal.selfenroll_end_access'},
5298: default_enrollment_start_date => $env{'course.'.$cid.'.default_enrollment_start_date'},
5299: default_enrollment_end_date => $env{'course.'.$cid.'.default_enrollment_end_date'},
1.400 raeburn 5300: uniquecode => $env{'course.'.$cid.'.internal.uniquecode'},
1.398 raeburn 5301: );
5302: push(@{$brcrum},
5303: {href => '/adm/createuser?action=selfenroll',
5304: text => "Configure Self-enrollment",
5305: help => 'Course_Self_Enrollment'});
5306: if (!exists($env{'form.state'})) {
5307: $args = { bread_crumbs => $brcrum,
5308: bread_crumbs_component => 'Configure Self-enrollment'};
5309: $r->print(&header(undef,$args));
5310: $r->print('<h3>'.&mt('Self-enrollment with a student role').'</h3>'."\n");
5311: &print_selfenroll_menu($r,'course',$cid,$cdom,$cnum,\%currsettings);
5312: } elsif ($env{'form.state'} eq 'done') {
5313: push (@{$brcrum},
5314: {href=>'/adm/createuser?action=selfenroll',
5315: text=>"Result"});
5316: $args = { bread_crumbs => $brcrum,
5317: bread_crumbs_component => 'Self-enrollment result'};
5318: $r->print(&header(undef,$args));
5319: $r->print('<h3>'.&mt('Self-enrollment with a student role').'</h3>'."\n");
1.400 raeburn 5320: &update_selfenroll_config($r,$cid,$cdom,$cnum,$context,$crstype,\%currsettings);
1.398 raeburn 5321: }
5322: } else {
5323: $r->print(&header(undef,{'no_nav_bar' => 1}).
5324: '<span class="LC_error">'.&mt('You do not have permission to configure self-enrollment').'</span>');
1.237 raeburn 5325: }
1.277 raeburn 5326: } elsif ($env{'form.action'} eq 'selfenrollqueue') {
1.418 raeburn 5327: if ($permission->{selfenrolladmin}) {
1.351 raeburn 5328: push(@{$brcrum},
5329: {href => '/adm/createuser?action=selfenrollqueue',
1.418 raeburn 5330: text => 'Enrollment requests',
1.439 raeburn 5331: help => 'Course_Approve_Selfenroll'});
1.418 raeburn 5332: $bread_crumbs_component = 'Enrollment requests';
5333: if ($env{'form.state'} eq 'done') {
5334: push(@{$brcrum},
5335: {href => '/adm/createuser?action=selfenrollqueue',
5336: text => 'Result',
1.439 raeburn 5337: help => 'Course_Approve_Selfenroll'});
1.418 raeburn 5338: $bread_crumbs_component = 'Enrollment result';
5339: }
5340: $args = { bread_crumbs => $brcrum,
5341: bread_crumbs_component => $bread_crumbs_component};
5342: $r->print(&header(undef,$args));
5343: my $coursedesc = $env{'course.'.$cid.'.description'};
5344: if (!exists($env{'form.state'})) {
5345: $r->print('<h3>'.&mt('Pending enrollment requests').'</h3>'."\n");
5346: $r->print(&Apache::loncoursequeueadmin::display_queued_requests($context,
5347: $cdom,$cnum));
5348: } elsif ($env{'form.state'} eq 'done') {
5349: $r->print('<h3>'.&mt('Enrollment request processing').'</h3>'."\n");
5350: $r->print(&Apache::loncoursequeueadmin::update_request_queue($context,
1.430 raeburn 5351: $cdom,$cnum,$coursedesc));
1.418 raeburn 5352: }
5353: } else {
5354: $r->print(&header(undef,{'no_nav_bar' => 1}).
5355: '<span class="LC_error">'.&mt('You do not have permission to manage self-enrollment').'</span>');
1.351 raeburn 5356: }
1.418 raeburn 5357: } elsif ($env{'form.action'} eq 'changelogs') {
5358: if ($permission->{cusr} || $permission->{view}) {
5359: &print_userchangelogs_display($r,$context,$permission,$brcrum);
5360: } else {
5361: $r->print(&header(undef,{'no_nav_bar' => 1}).
5362: '<span class="LC_error">'.&mt('You do not have permission to view change logs').'</span>');
1.277 raeburn 5363: }
1.428 raeburn 5364: } elsif ($env{'form.action'} eq 'helpdesk') {
5365: if (($permission->{'owner'}) || ($permission->{'co-owner'})) {
5366: if ($env{'form.state'} eq 'process') {
5367: if ($permission->{'owner'}) {
5368: &update_helpdeskaccess($r,$permission,$brcrum);
5369: } else {
5370: &print_helpdeskaccess_display($r,$permission,$brcrum);
1.430 raeburn 5371: }
1.428 raeburn 5372: } else {
5373: &print_helpdeskaccess_display($r,$permission,$brcrum);
5374: }
5375: } else {
5376: $r->print(&header(undef,{'no_nav_bar' => 1}).
5377: '<span class="LC_error">'.&mt('You do not have permission to view helpdesk access').'</span>');
5378: }
1.190 raeburn 5379: } else {
1.351 raeburn 5380: $bread_crumbs_component = 'User Management';
5381: $args = { bread_crumbs => $brcrum,
5382: bread_crumbs_component => $bread_crumbs_component};
5383: $r->print(&header(undef,$args));
1.318 raeburn 5384: $r->print(&print_main_menu($permission,$context,$crstype));
1.190 raeburn 5385: }
1.351 raeburn 5386: $r->print(&Apache::loncommon::end_page());
1.190 raeburn 5387: return OK;
5388: }
5389:
5390: sub header {
1.351 raeburn 5391: my ($jscript,$args) = @_;
1.190 raeburn 5392: my $start_page;
1.351 raeburn 5393: if (ref($args) eq 'HASH') {
5394: $start_page=&Apache::loncommon::start_page('User Management',$jscript,$args);
1.190 raeburn 5395: } else {
1.351 raeburn 5396: $start_page=&Apache::loncommon::start_page('User Management',$jscript);
1.190 raeburn 5397: }
5398: return $start_page;
5399: }
1.2 www 5400:
1.191 raeburn 5401: sub add_script {
5402: my ($js) = @_;
1.301 bisitz 5403: return '<script type="text/javascript">'."\n"
5404: .'// <![CDATA['."\n"
5405: .$js."\n"
5406: .'// ]]>'."\n"
5407: .'</script>'."\n";
1.191 raeburn 5408: }
5409:
1.391 raeburn 5410: sub usernamerequest_javascript {
5411: my $js = <<ENDJS;
5412:
5413: function openusernamereqdisplay(dom,uname,queue) {
5414: var url = '/adm/createuser?action=displayuserreq';
5415: url += '&domain='+dom+'&username='+uname+'&queue='+queue;
5416: var title = 'Account_Request_Browser';
5417: var options = 'scrollbars=1,resizable=1,menubar=0';
5418: options += ',width=700,height=600';
5419: var stdeditbrowser = open(url,title,options,'1');
5420: stdeditbrowser.focus();
5421: return;
5422: }
5423:
5424: ENDJS
5425: }
5426:
5427: sub close_popup_form {
5428: my $close= &mt('Close Window');
5429: return << "END";
5430: <p><form name="displayreq" action="" method="post">
5431: <input type="button" name="closeme" value="$close" onclick="javascript:self.close();" />
5432: </form></p>
5433: END
5434: }
5435:
1.202 raeburn 5436: sub verify_user_display {
1.364 raeburn 5437: my ($context) = @_;
1.374 raeburn 5438: my %lt = &Apache::lonlocal::texthash (
5439: course => 'course(s): description, section(s), status',
5440: community => 'community(s): description, section(s), status',
5441: author => 'author',
5442: );
1.364 raeburn 5443: my $photos;
5444: if (($context eq 'course') && $env{'request.course.id'}) {
5445: $photos = $env{'course.'.$env{'request.course.id'}.'.internal.showphoto'};
5446: }
1.202 raeburn 5447: my $output = <<"END";
5448:
1.364 raeburn 5449: function hide_searching() {
5450: if (document.getElementById('searching')) {
5451: document.getElementById('searching').style.display = 'none';
5452: }
5453: return;
5454: }
5455:
1.202 raeburn 5456: function display_update() {
5457: document.studentform.action.value = 'listusers';
5458: document.studentform.phase.value = 'display';
5459: document.studentform.submit();
5460: }
5461:
1.364 raeburn 5462: function updateCols(caller) {
5463: var context = '$context';
5464: var photos = '$photos';
5465: if (caller == 'Status') {
1.374 raeburn 5466: if ((context == 'domain') &&
5467: ((document.studentform.roletype.options[document.studentform.roletype.selectedIndex].value == 'course') ||
5468: (document.studentform.roletype.options[document.studentform.roletype.selectedIndex].value == 'community'))) {
1.364 raeburn 5469: document.getElementById('showcolstatus').checked = false;
5470: document.getElementById('showcolstatus').disabled = 'disabled';
5471: document.getElementById('showcolstart').checked = false;
5472: document.getElementById('showcolend').checked = false;
1.374 raeburn 5473: } else {
5474: if (document.studentform.Status.options[document.studentform.Status.selectedIndex].value == 'Any') {
5475: document.getElementById('showcolstatus').checked = true;
5476: document.getElementById('showcolstatus').disabled = '';
5477: document.getElementById('showcolstart').checked = true;
5478: document.getElementById('showcolend').checked = true;
5479: } else {
5480: document.getElementById('showcolstatus').checked = false;
5481: document.getElementById('showcolstatus').disabled = 'disabled';
5482: document.getElementById('showcolstart').checked = false;
5483: document.getElementById('showcolend').checked = false;
5484: }
1.364 raeburn 5485: }
5486: }
5487: if (caller == 'output') {
5488: if (photos == 1) {
5489: if (document.getElementById('showcolphoto')) {
5490: var photoitem = document.getElementById('showcolphoto');
5491: if (document.studentform.output.options[document.studentform.output.selectedIndex].value == 'html') {
5492: photoitem.checked = true;
5493: photoitem.disabled = '';
5494: } else {
5495: photoitem.checked = false;
5496: photoitem.disabled = 'disabled';
5497: }
5498: }
5499: }
5500: }
5501: if (caller == 'showrole') {
1.371 raeburn 5502: if ((document.studentform.showrole.options[document.studentform.showrole.selectedIndex].value == 'Any') ||
5503: (document.studentform.showrole.options[document.studentform.showrole.selectedIndex].value == 'cr')) {
1.364 raeburn 5504: document.getElementById('showcolrole').checked = true;
5505: document.getElementById('showcolrole').disabled = '';
5506: } else {
5507: document.getElementById('showcolrole').checked = false;
5508: document.getElementById('showcolrole').disabled = 'disabled';
5509: }
1.374 raeburn 5510: if (context == 'domain') {
1.382 raeburn 5511: var quotausageshow = 0;
1.374 raeburn 5512: if ((document.studentform.roletype.options[document.studentform.roletype.selectedIndex].value == 'course') ||
5513: (document.studentform.roletype.options[document.studentform.roletype.selectedIndex].value == 'community')) {
5514: document.getElementById('showcolstatus').checked = false;
5515: document.getElementById('showcolstatus').disabled = 'disabled';
5516: document.getElementById('showcolstart').checked = false;
5517: document.getElementById('showcolend').checked = false;
5518: } else {
5519: if (document.studentform.Status.options[document.studentform.Status.selectedIndex].value == 'Any') {
5520: document.getElementById('showcolstatus').checked = true;
5521: document.getElementById('showcolstatus').disabled = '';
5522: document.getElementById('showcolstart').checked = true;
5523: document.getElementById('showcolend').checked = true;
5524: }
5525: }
5526: if (document.studentform.roletype.options[document.studentform.roletype.selectedIndex].value == 'domain') {
5527: document.getElementById('showcolextent').disabled = 'disabled';
5528: document.getElementById('showcolextent').checked = 'false';
5529: document.getElementById('showextent').style.display='none';
5530: document.getElementById('showcoltextextent').innerHTML = '';
1.382 raeburn 5531: if ((document.studentform.showrole.options[document.studentform.showrole.selectedIndex].value == 'au') ||
5532: (document.studentform.showrole.options[document.studentform.showrole.selectedIndex].value == 'Any')) {
5533: if (document.getElementById('showcolauthorusage')) {
5534: document.getElementById('showcolauthorusage').disabled = '';
5535: }
5536: if (document.getElementById('showcolauthorquota')) {
5537: document.getElementById('showcolauthorquota').disabled = '';
5538: }
5539: quotausageshow = 1;
5540: }
1.374 raeburn 5541: } else {
5542: document.getElementById('showextent').style.display='block';
5543: document.getElementById('showextent').style.textAlign='left';
5544: document.getElementById('showextent').style.textFace='normal';
5545: if (document.studentform.roletype.options[document.studentform.roletype.selectedIndex].value == 'author') {
5546: document.getElementById('showcolextent').disabled = '';
5547: document.getElementById('showcolextent').checked = 'true';
5548: document.getElementById('showcoltextextent').innerHTML="$lt{'author'}";
5549: } else {
5550: document.getElementById('showcolextent').disabled = '';
5551: document.getElementById('showcolextent').checked = 'true';
5552: if (document.studentform.roletype.options[document.studentform.roletype.selectedIndex].value == 'community') {
5553: document.getElementById('showcoltextextent').innerHTML="$lt{'community'}";
5554: } else {
5555: document.getElementById('showcoltextextent').innerHTML="$lt{'course'}";
5556: }
5557: }
5558: }
1.382 raeburn 5559: if (quotausageshow == 0) {
5560: if (document.getElementById('showcolauthorusage')) {
5561: document.getElementById('showcolauthorusage').checked = false;
5562: document.getElementById('showcolauthorusage').disabled = 'disabled';
5563: }
5564: if (document.getElementById('showcolauthorquota')) {
5565: document.getElementById('showcolauthorquota').checked = false;
5566: document.getElementById('showcolauthorquota').disabled = 'disabled';
5567: }
5568: }
1.374 raeburn 5569: }
1.364 raeburn 5570: }
5571: return;
5572: }
5573:
1.202 raeburn 5574: END
5575: return $output;
5576:
5577: }
5578:
1.190 raeburn 5579: ###############################################################
5580: ###############################################################
5581: # Menu Phase One
5582: sub print_main_menu {
1.318 raeburn 5583: my ($permission,$context,$crstype) = @_;
5584: my $linkcontext = $context;
5585: my $stuterm = lc(&Apache::lonnet::plaintext('st',$crstype));
5586: if (($context eq 'course') && ($crstype eq 'Community')) {
5587: $linkcontext = lc($crstype);
5588: $stuterm = 'Members';
5589: }
1.208 raeburn 5590: my %links = (
1.298 droeschl 5591: domain => {
5592: upload => 'Upload a File of Users',
5593: singleuser => 'Add/Modify a User',
5594: listusers => 'Manage Users',
5595: },
5596: author => {
5597: upload => 'Upload a File of Co-authors',
5598: singleuser => 'Add/Modify a Co-author',
5599: listusers => 'Manage Co-authors',
5600: },
5601: course => {
5602: upload => 'Upload a File of Course Users',
5603: singleuser => 'Add/Modify a Course User',
1.354 www 5604: listusers => 'List and Modify Multiple Course Users',
1.298 droeschl 5605: },
1.318 raeburn 5606: community => {
5607: upload => 'Upload a File of Community Users',
5608: singleuser => 'Add/Modify a Community User',
1.354 www 5609: listusers => 'List and Modify Multiple Community Users',
1.318 raeburn 5610: },
5611: );
5612: my %linktitles = (
5613: domain => {
5614: singleuser => 'Add a user to the domain, and/or a course or community in the domain.',
5615: listusers => 'Show and manage users in this domain.',
5616: },
5617: author => {
5618: singleuser => 'Add a user with a co- or assistant author role.',
5619: listusers => 'Show and manage co- or assistant authors.',
5620: },
5621: course => {
5622: singleuser => 'Add a user with a certain role to this course.',
5623: listusers => 'Show and manage users in this course.',
5624: },
5625: community => {
5626: singleuser => 'Add a user with a certain role to this community.',
5627: listusers => 'Show and manage users in this community.',
5628: },
1.298 droeschl 5629: );
1.418 raeburn 5630: if ($linkcontext eq 'domain') {
5631: unless ($permission->{'cusr'}) {
1.430 raeburn 5632: $links{'domain'}{'singleuser'} = 'View a User';
1.418 raeburn 5633: $linktitles{'domain'}{'singleuser'} = 'View information about a user in the domain';
5634: }
5635: } elsif ($linkcontext eq 'course') {
5636: unless ($permission->{'cusr'}) {
5637: $links{'course'}{'singleuser'} = 'View a Course User';
5638: $linktitles{'course'}{'singleuser'} = 'View information about a user in this course';
5639: $links{'course'}{'listusers'} = 'List Course Users';
5640: $linktitles{'course'}{'listusers'} = 'Show information about users in this course';
5641: }
5642: } elsif ($linkcontext eq 'community') {
5643: unless ($permission->{'cusr'}) {
5644: $links{'community'}{'singleuser'} = 'View a Community User';
5645: $linktitles{'community'}{'singleuser'} = 'View information about a user in this community';
5646: $links{'community'}{'listusers'} = 'List Community Users';
5647: $linktitles{'community'}{'listusers'} = 'Show information about users in this community';
5648: }
5649: }
1.298 droeschl 5650: my @menu = ( {categorytitle => 'Single Users',
5651: items =>
5652: [
5653: {
1.318 raeburn 5654: linktext => $links{$linkcontext}{'singleuser'},
1.298 droeschl 5655: icon => 'edit-redo.png',
5656: #help => 'Course_Change_Privileges',
5657: url => '/adm/createuser?action=singleuser',
1.418 raeburn 5658: permission => ($permission->{'view'} || $permission->{'cusr'}),
1.318 raeburn 5659: linktitle => $linktitles{$linkcontext}{'singleuser'},
1.298 droeschl 5660: },
5661: ]},
5662:
5663: {categorytitle => 'Multiple Users',
5664: items =>
5665: [
5666: {
1.318 raeburn 5667: linktext => $links{$linkcontext}{'upload'},
1.340 wenzelju 5668: icon => 'uplusr.png',
1.298 droeschl 5669: #help => 'Course_Create_Class_List',
5670: url => '/adm/createuser?action=upload',
5671: permission => $permission->{'cusr'},
5672: linktitle => 'Upload a CSV or a text file containing users.',
5673: },
5674: {
1.318 raeburn 5675: linktext => $links{$linkcontext}{'listusers'},
1.340 wenzelju 5676: icon => 'mngcu.png',
1.298 droeschl 5677: #help => 'Course_View_Class_List',
5678: url => '/adm/createuser?action=listusers',
5679: permission => ($permission->{'view'} || $permission->{'cusr'}),
1.318 raeburn 5680: linktitle => $linktitles{$linkcontext}{'listusers'},
1.298 droeschl 5681: },
5682:
5683: ]},
5684:
5685: {categorytitle => 'Administration',
5686: items => [ ]},
5687: );
1.415 raeburn 5688:
1.265 mielkec 5689: if ($context eq 'domain'){
1.416 raeburn 5690: push(@{ $menu[0]->{items} }, # Single Users
5691: {
5692: linktext => 'User Access Log',
1.417 raeburn 5693: icon => 'document-properties.png',
1.425 raeburn 5694: #help => 'Domain_User_Access_Logs',
1.416 raeburn 5695: url => '/adm/createuser?action=accesslogs',
5696: permission => $permission->{'activity'},
5697: linktitle => 'View user access log.',
5698: }
5699: );
1.298 droeschl 5700:
5701: push(@{ $menu[2]->{items} }, #Category: Administration
5702: {
5703: linktext => 'Custom Roles',
5704: icon => 'emblem-photos.png',
5705: #help => 'Course_Editing_Custom_Roles',
5706: url => '/adm/createuser?action=custom',
5707: permission => $permission->{'custom'},
5708: linktitle => 'Configure a custom role.',
5709: },
1.362 raeburn 5710: {
5711: linktext => 'Authoring Space Requests',
5712: icon => 'selfenrl-queue.png',
5713: #help => 'Domain_Role_Approvals',
5714: url => '/adm/createuser?action=processauthorreq',
5715: permission => $permission->{'cusr'},
5716: linktitle => 'Approve or reject author role requests',
5717: },
1.363 raeburn 5718: {
1.391 raeburn 5719: linktext => 'LON-CAPA Account Requests',
5720: icon => 'list-add.png',
5721: #help => 'Domain_Username_Approvals',
5722: url => '/adm/createuser?action=processusernamereq',
5723: permission => $permission->{'cusr'},
5724: linktitle => 'Approve or reject LON-CAPA account requests',
5725: },
5726: {
1.363 raeburn 5727: linktext => 'Change Log',
5728: icon => 'document-properties.png',
5729: #help => 'Course_User_Logs',
5730: url => '/adm/createuser?action=changelogs',
1.418 raeburn 5731: permission => ($permission->{'cusr'} || $permission->{'view'}),
1.363 raeburn 5732: linktitle => 'View change log.',
5733: },
1.298 droeschl 5734: );
5735:
1.265 mielkec 5736: }elsif ($context eq 'course'){
1.298 droeschl 5737: my ($cnum,$cdom) = &Apache::lonuserutils::get_course_identity();
1.318 raeburn 5738:
5739: my %linktext = (
5740: 'Course' => {
5741: single => 'Add/Modify a Student',
5742: drop => 'Drop Students',
5743: groups => 'Course Groups',
5744: },
5745: 'Community' => {
5746: single => 'Add/Modify a Member',
5747: drop => 'Drop Members',
5748: groups => 'Community Groups',
5749: },
5750: );
1.411 raeburn 5751: $linktext{'Placement'} = $linktext{'Course'};
1.318 raeburn 5752:
5753: my %linktitle = (
5754: 'Course' => {
5755: single => 'Add a user with the role of student to this course',
5756: drop => 'Remove a student from this course.',
5757: groups => 'Manage course groups',
5758: },
5759: 'Community' => {
5760: single => 'Add a user with the role of member to this community',
5761: drop => 'Remove a member from this community.',
5762: groups => 'Manage community groups',
5763: },
5764: );
5765:
1.411 raeburn 5766: $linktitle{'Placement'} = $linktitle{'Course'};
5767:
1.298 droeschl 5768: push(@{ $menu[0]->{items} }, #Category: Single Users
5769: {
1.318 raeburn 5770: linktext => $linktext{$crstype}{'single'},
1.298 droeschl 5771: #help => 'Course_Add_Student',
5772: icon => 'list-add.png',
5773: url => '/adm/createuser?action=singlestudent',
5774: permission => $permission->{'cusr'},
1.318 raeburn 5775: linktitle => $linktitle{$crstype}{'single'},
1.298 droeschl 5776: },
5777: );
5778:
5779: push(@{ $menu[1]->{items} }, #Category: Multiple Users
5780: {
1.318 raeburn 5781: linktext => $linktext{$crstype}{'drop'},
1.298 droeschl 5782: icon => 'edit-undo.png',
5783: #help => 'Course_Drop_Student',
5784: url => '/adm/createuser?action=drop',
5785: permission => $permission->{'cusr'},
1.318 raeburn 5786: linktitle => $linktitle{$crstype}{'drop'},
1.298 droeschl 5787: },
5788: );
5789: push(@{ $menu[2]->{items} }, #Category: Administration
1.428 raeburn 5790: {
5791: linktext => 'Helpdesk Access',
5792: icon => 'helpdesk-access.png',
5793: #help => 'Course_Helpdesk_Access',
5794: url => '/adm/createuser?action=helpdesk',
5795: permission => ($permission->{'owner'} || $permission->{'co-owner'}),
5796: linktitle => 'Helpdesk access options',
5797: },
5798: {
1.298 droeschl 5799: linktext => 'Custom Roles',
5800: icon => 'emblem-photos.png',
5801: #help => 'Course_Editing_Custom_Roles',
5802: url => '/adm/createuser?action=custom',
5803: permission => $permission->{'custom'},
5804: linktitle => 'Configure a custom role.',
5805: },
5806: {
1.318 raeburn 5807: linktext => $linktext{$crstype}{'groups'},
1.333 wenzelju 5808: icon => 'grps.png',
1.298 droeschl 5809: #help => 'Course_Manage_Group',
5810: url => '/adm/coursegroups?refpage=cusr',
5811: permission => $permission->{'grp_manage'},
1.318 raeburn 5812: linktitle => $linktitle{$crstype}{'groups'},
1.298 droeschl 5813: },
5814: {
1.328 wenzelju 5815: linktext => 'Change Log',
1.298 droeschl 5816: icon => 'document-properties.png',
5817: #help => 'Course_User_Logs',
5818: url => '/adm/createuser?action=changelogs',
1.418 raeburn 5819: permission => ($permission->{'view'} || $permission->{'cusr'}),
1.298 droeschl 5820: linktitle => 'View change log.',
5821: },
5822: );
1.277 raeburn 5823: if ($env{'course.'.$env{'request.course.id'}.'.internal.selfenroll_approval'}) {
1.298 droeschl 5824: push(@{ $menu[2]->{items} },
1.398 raeburn 5825: {
1.298 droeschl 5826: linktext => 'Enrollment Requests',
5827: icon => 'selfenrl-queue.png',
5828: #help => 'Course_Approve_Selfenroll',
5829: url => '/adm/createuser?action=selfenrollqueue',
1.398 raeburn 5830: permission => $permission->{'selfenrolladmin'},
1.298 droeschl 5831: linktitle =>'Approve or reject enrollment requests.',
5832: },
5833: );
1.277 raeburn 5834: }
1.298 droeschl 5835:
1.265 mielkec 5836: if (!exists($permission->{'cusr_section'})){
1.320 raeburn 5837: if ($crstype ne 'Community') {
5838: push(@{ $menu[2]->{items} },
5839: {
5840: linktext => 'Automated Enrollment',
5841: icon => 'roles.png',
5842: #help => 'Course_Automated_Enrollment',
5843: permission => (&Apache::lonnet::auto_run($cnum,$cdom)
1.418 raeburn 5844: && (($permission->{'cusr'}) ||
5845: ($permission->{'view'}))),
1.320 raeburn 5846: url => '/adm/populate',
5847: linktitle => 'Automated enrollment manager.',
5848: }
5849: );
5850: }
5851: push(@{ $menu[2]->{items} },
1.298 droeschl 5852: {
5853: linktext => 'User Self-Enrollment',
1.342 wenzelju 5854: icon => 'self_enroll.png',
1.298 droeschl 5855: #help => 'Course_Self_Enrollment',
5856: url => '/adm/createuser?action=selfenroll',
1.398 raeburn 5857: permission => $permission->{'selfenrolladmin'},
1.317 bisitz 5858: linktitle => 'Configure user self-enrollment.',
1.298 droeschl 5859: },
5860: );
5861: }
1.363 raeburn 5862: } elsif ($context eq 'author') {
1.370 raeburn 5863: push(@{ $menu[2]->{items} }, #Category: Administration
1.363 raeburn 5864: {
5865: linktext => 'Change Log',
5866: icon => 'document-properties.png',
5867: #help => 'Course_User_Logs',
5868: url => '/adm/createuser?action=changelogs',
5869: permission => $permission->{'cusr'},
5870: linktitle => 'View change log.',
5871: },
1.370 raeburn 5872: );
1.363 raeburn 5873: }
5874: return Apache::lonhtmlcommon::generate_menu(@menu);
1.250 raeburn 5875: # { text => 'View Log-in History',
5876: # help => 'Course_User_Logins',
5877: # action => 'logins',
5878: # permission => $permission->{'cusr'},
5879: # });
1.190 raeburn 5880: }
5881:
1.189 albertel 5882: sub restore_prev_selections {
5883: my %saveable_parameters = ('srchby' => 'scalar',
5884: 'srchin' => 'scalar',
5885: 'srchtype' => 'scalar',
5886: );
5887: &Apache::loncommon::store_settings('user','user_picker',
5888: \%saveable_parameters);
5889: &Apache::loncommon::restore_settings('user','user_picker',
5890: \%saveable_parameters);
5891: }
5892:
1.237 raeburn 5893: sub print_selfenroll_menu {
1.418 raeburn 5894: my ($r,$context,$cid,$cdom,$cnum,$currsettings,$additional,$readonly) = @_;
1.322 raeburn 5895: my $crstype = &Apache::loncommon::course_type();
1.398 raeburn 5896: my $formname = 'selfenroll';
1.237 raeburn 5897: my $nolink = 1;
1.398 raeburn 5898: my ($row,$lt) = &Apache::lonuserutils::get_selfenroll_titles();
1.237 raeburn 5899: my $groupslist = &Apache::lonuserutils::get_groupslist();
5900: my $setsec_js =
5901: &Apache::lonuserutils::setsections_javascript($formname,$groupslist);
1.249 raeburn 5902: my %alerts = &Apache::lonlocal::texthash(
5903: acto => 'Activation of self-enrollment was selected for the following domain(s)',
5904: butn => 'but no user types have been checked.',
5905: wilf => "Please uncheck 'activate' or check at least one type.",
5906: );
1.418 raeburn 5907: my $disabled;
5908: if ($readonly) {
5909: $disabled = ' disabled="disabled"';
5910: }
1.405 damieng 5911: &js_escape(\%alerts);
1.249 raeburn 5912: my $selfenroll_js = <<"ENDSCRIPT";
5913: function update_types(caller,num) {
5914: var delidx = getIndexByName('selfenroll_delete');
5915: var actidx = getIndexByName('selfenroll_activate');
5916: if (caller == 'selfenroll_all') {
5917: var selall;
5918: for (var i=0; i<document.$formname.selfenroll_all.length; i++) {
5919: if (document.$formname.selfenroll_all[i].checked) {
5920: selall = document.$formname.selfenroll_all[i].value;
5921: }
5922: }
5923: if (selall == 1) {
5924: if (delidx != -1) {
5925: if (document.$formname.selfenroll_delete.length) {
5926: for (var j=0; j<document.$formname.selfenroll_delete.length; j++) {
5927: document.$formname.selfenroll_delete[j].checked = true;
5928: }
5929: } else {
5930: document.$formname.elements[delidx].checked = true;
5931: }
5932: }
5933: if (actidx != -1) {
5934: if (document.$formname.selfenroll_activate.length) {
5935: for (var j=0; j<document.$formname.selfenroll_activate.length; j++) {
5936: document.$formname.selfenroll_activate[j].checked = false;
5937: }
5938: } else {
5939: document.$formname.elements[actidx].checked = false;
5940: }
5941: }
5942: document.$formname.selfenroll_newdom.selectedIndex = 0;
5943: }
5944: }
5945: if (caller == 'selfenroll_activate') {
5946: if (document.$formname.selfenroll_activate.length) {
5947: for (var j=0; j<document.$formname.selfenroll_activate.length; j++) {
5948: if (document.$formname.selfenroll_activate[j].value == num) {
5949: if (document.$formname.selfenroll_activate[j].checked) {
5950: for (var i=0; i<document.$formname.selfenroll_all.length; i++) {
5951: if (document.$formname.selfenroll_all[i].value == '1') {
5952: document.$formname.selfenroll_all[i].checked = false;
5953: }
5954: if (document.$formname.selfenroll_all[i].value == '0') {
5955: document.$formname.selfenroll_all[i].checked = true;
5956: }
5957: }
5958: }
5959: }
5960: }
5961: } else {
5962: for (var i=0; i<document.$formname.selfenroll_all.length; i++) {
5963: if (document.$formname.selfenroll_all[i].value == '1') {
5964: document.$formname.selfenroll_all[i].checked = false;
5965: }
5966: if (document.$formname.selfenroll_all[i].value == '0') {
5967: document.$formname.selfenroll_all[i].checked = true;
5968: }
5969: }
5970: }
5971: }
5972: if (caller == 'selfenroll_delete') {
5973: if (document.$formname.selfenroll_delete.length) {
5974: for (var j=0; j<document.$formname.selfenroll_delete.length; j++) {
5975: if (document.$formname.selfenroll_delete[j].value == num) {
5976: if (document.$formname.selfenroll_delete[j].checked) {
5977: var delindex = getIndexByName('selfenroll_types_'+num);
5978: if (delindex != -1) {
5979: if (document.$formname.elements[delindex].length) {
5980: for (var k=0; k<document.$formname.elements[delindex].length; k++) {
5981: document.$formname.elements[delindex][k].checked = false;
5982: }
5983: } else {
5984: document.$formname.elements[delindex].checked = false;
5985: }
5986: }
5987: }
5988: }
5989: }
5990: } else {
5991: if (document.$formname.selfenroll_delete.checked) {
5992: var delindex = getIndexByName('selfenroll_types_'+num);
5993: if (delindex != -1) {
5994: if (document.$formname.elements[delindex].length) {
5995: for (var k=0; k<document.$formname.elements[delindex].length; k++) {
5996: document.$formname.elements[delindex][k].checked = false;
5997: }
5998: } else {
5999: document.$formname.elements[delindex].checked = false;
6000: }
6001: }
6002: }
6003: }
6004: }
6005: return;
6006: }
6007:
6008: function validate_types(form) {
6009: var needaction = new Array();
6010: var countfail = 0;
6011: var actidx = getIndexByName('selfenroll_activate');
6012: if (actidx != -1) {
6013: if (document.$formname.selfenroll_activate.length) {
6014: for (var j=0; j<document.$formname.selfenroll_activate.length; j++) {
6015: var num = document.$formname.selfenroll_activate[j].value;
6016: if (document.$formname.selfenroll_activate[j].checked) {
6017: countfail = check_types(num,countfail,needaction)
6018: }
6019: }
6020: } else {
6021: if (document.$formname.selfenroll_activate.checked) {
1.398 raeburn 6022: var num = document.$formname.selfenroll_activate.value;
1.249 raeburn 6023: countfail = check_types(num,countfail,needaction)
6024: }
6025: }
6026: }
6027: if (countfail > 0) {
6028: var msg = "$alerts{'acto'}\\n";
6029: var loopend = needaction.length -1;
6030: if (loopend > 0) {
6031: for (var m=0; m<loopend; m++) {
6032: msg += needaction[m]+", ";
6033: }
6034: }
6035: msg += needaction[loopend]+"\\n$alerts{'butn'}\\n$alerts{'wilf'}";
6036: alert(msg);
6037: return;
6038: }
6039: setSections(form);
6040: }
6041:
6042: function check_types(num,countfail,needaction) {
1.441 raeburn 6043: var boxname = 'selfenroll_types_'+num;
6044: var typeidx = getIndexByName(boxname);
1.249 raeburn 6045: var count = 0;
6046: if (typeidx != -1) {
1.441 raeburn 6047: if (document.$formname.elements[boxname].length) {
6048: for (var k=0; k<document.$formname.elements[boxname].length; k++) {
6049: if (document.$formname.elements[boxname][k].checked) {
1.249 raeburn 6050: count ++;
6051: }
6052: }
6053: } else {
6054: if (document.$formname.elements[typeidx].checked) {
6055: count ++;
6056: }
6057: }
6058: if (count == 0) {
6059: var domidx = getIndexByName('selfenroll_dom_'+num);
6060: if (domidx != -1) {
6061: var domname = document.$formname.elements[domidx].value;
6062: needaction[countfail] = domname;
6063: countfail ++;
6064: }
6065: }
6066: }
6067: return countfail;
6068: }
6069:
1.398 raeburn 6070: function toggleNotify() {
6071: var selfenrollApproval = 0;
6072: if (document.$formname.selfenroll_approval.length) {
6073: for (var i=0; i<document.$formname.selfenroll_approval.length; i++) {
6074: if (document.$formname.selfenroll_approval[i].checked) {
6075: selfenrollApproval = document.$formname.selfenroll_approval[i].value;
6076: break;
6077: }
6078: }
6079: }
6080: if (document.getElementById('notified')) {
6081: if (selfenrollApproval == 0) {
6082: document.getElementById('notified').style.display='none';
6083: } else {
6084: document.getElementById('notified').style.display='block';
6085: }
6086: }
6087: return;
6088: }
6089:
1.249 raeburn 6090: function getIndexByName(item) {
6091: for (var i=0;i<document.$formname.elements.length;i++) {
6092: if (document.$formname.elements[i].name == item) {
6093: return i;
6094: }
6095: }
6096: return -1;
6097: }
6098: ENDSCRIPT
1.256 raeburn 6099:
1.237 raeburn 6100: my $output = '<script type="text/javascript">'."\n".
1.301 bisitz 6101: '// <![CDATA['."\n".
1.249 raeburn 6102: $setsec_js."\n".$selfenroll_js."\n".
1.301 bisitz 6103: '// ]]>'."\n".
1.237 raeburn 6104: '</script>'."\n".
1.256 raeburn 6105: '<h3>'.$lt->{'selfenroll'}.'</h3>'."\n";
1.400 raeburn 6106:
6107: my $visactions = &cat_visibility();
6108: my ($cathash,%cattype);
6109: my %domconfig = &Apache::lonnet::get_dom('configuration',['coursecategories'],$cdom);
6110: if (ref($domconfig{'coursecategories'}) eq 'HASH') {
6111: $cathash = $domconfig{'coursecategories'}{'cats'};
6112: $cattype{'auth'} = $domconfig{'coursecategories'}{'auth'};
6113: $cattype{'unauth'} = $domconfig{'coursecategories'}{'unauth'};
1.406 raeburn 6114: if ($cattype{'auth'} eq '') {
6115: $cattype{'auth'} = 'std';
6116: }
6117: if ($cattype{'unauth'} eq '') {
6118: $cattype{'unauth'} = 'std';
6119: }
1.400 raeburn 6120: } else {
6121: $cathash = {};
6122: $cattype{'auth'} = 'std';
6123: $cattype{'unauth'} = 'std';
6124: }
6125: if (($cattype{'auth'} eq 'none') && ($cattype{'unauth'} eq 'none')) {
6126: $r->print('<br /><span class="LC_warning">'.$visactions->{'miss'}.'</span><br />'.$visactions->{'yous'}.
6127: '<br />'.
6128: '<br />'.$visactions->{'take'}.'<ul>'.
6129: '<li>'.$visactions->{'dc_chgconf'}.'</li>'.
6130: '</ul>');
6131: } elsif (($cattype{'auth'} !~ /^(std|domonly)$/) && ($cattype{'unauth'} !~ /^(std|domonly)$/)) {
6132: if ($currsettings->{'uniquecode'}) {
6133: $r->print('<span class="LC_info">'.$visactions->{'vis'}.'</span>');
6134: } else {
6135: $r->print('<br /><span class="LC_warning">'.$visactions->{'miss'}.'</span><br />'.$visactions->{'yous'}.
6136: '<br />'.
6137: '<br />'.$visactions->{'take'}.'<ul>'.
6138: '<li>'.$visactions->{'dc_setcode'}.'</li>'.
6139: '</ul><br />');
6140: }
6141: } else {
6142: my ($visible,$cansetvis,$vismsgs) = &visible_in_stdcat($cdom,$cnum,\%domconfig);
6143: if (ref($visactions) eq 'HASH') {
6144: if ($visible) {
6145: $output .= '<p class="LC_info">'.$visactions->{'vis'}.'</p>';
6146: } else {
6147: $output .= '<p class="LC_warning">'.$visactions->{'miss'}.'</p>'
6148: .$visactions->{'yous'}.
6149: '<p>'.$visactions->{'gen'}.'<br />'.$visactions->{'coca'};
6150: if (ref($vismsgs) eq 'ARRAY') {
6151: $output .= '<br />'.$visactions->{'make'}.'<ul>';
6152: foreach my $item (@{$vismsgs}) {
6153: $output .= '<li>'.$visactions->{$item}.'</li>';
6154: }
6155: $output .= '</ul>';
1.256 raeburn 6156: }
1.400 raeburn 6157: $output .= '</p>';
1.256 raeburn 6158: }
6159: }
6160: }
1.398 raeburn 6161: my $actionhref = '/adm/createuser';
6162: if ($context eq 'domain') {
6163: $actionhref = '/adm/modifycourse';
6164: }
1.400 raeburn 6165:
6166: my %noedit;
6167: unless ($context eq 'domain') {
6168: %noedit = &get_noedit_fields($cdom,$cnum,$crstype,$row);
6169: }
1.398 raeburn 6170: $output .= '<form name="'.$formname.'" method="post" action="'.$actionhref.'">'."\n".
1.256 raeburn 6171: &Apache::lonhtmlcommon::start_pick_box();
1.237 raeburn 6172: if (ref($row) eq 'ARRAY') {
6173: foreach my $item (@{$row}) {
6174: my $title = $item;
6175: if (ref($lt) eq 'HASH') {
6176: $title = $lt->{$item};
6177: }
1.297 bisitz 6178: $output .= &Apache::lonhtmlcommon::row_title($title);
1.237 raeburn 6179: if ($item eq 'types') {
1.398 raeburn 6180: my $curr_types;
6181: if (ref($currsettings) eq 'HASH') {
6182: $curr_types = $currsettings->{'selfenroll_types'};
6183: }
1.400 raeburn 6184: if ($noedit{$item}) {
6185: if ($curr_types eq '*') {
6186: $output .= &mt('Any user in any domain');
6187: } else {
6188: my @entries = split(/;/,$curr_types);
6189: if (@entries > 0) {
6190: $output .= '<ul>';
6191: foreach my $entry (@entries) {
6192: my ($currdom,$typestr) = split(/:/,$entry);
6193: next if ($typestr eq '');
6194: my $domdesc = &Apache::lonnet::domain($currdom);
6195: my @currinsttypes = split(',',$typestr);
6196: my ($othertitle,$usertypes,$types) =
6197: &Apache::loncommon::sorted_inst_types($currdom);
6198: if ((ref($types) eq 'ARRAY') && (ref($usertypes) eq 'HASH')) {
6199: $usertypes->{'any'} = &mt('any user');
6200: if (keys(%{$usertypes}) > 0) {
6201: $usertypes->{'other'} = &mt('other users');
6202: }
6203: my @longinsttypes = map { $usertypes->{$_}; } @currinsttypes;
6204: $output .= '<li>'.$domdesc.':'.join(', ',@longinsttypes).'</li>';
6205: }
6206: }
6207: $output .= '</ul>';
6208: } else {
6209: $output .= &mt('None');
6210: }
6211: }
6212: $output .= '<br />'.&mt('(Set by Domain Coordinator)');
6213: next;
6214: }
1.241 raeburn 6215: my $showdomdesc = 1;
6216: my $includeempty = 1;
6217: my $num = 0;
6218: $output .= &Apache::loncommon::start_data_table().
6219: &Apache::loncommon::start_data_table_row()
6220: .'<td colspan="2"><span class="LC_nobreak"><label>'
6221: .&mt('Any user in any domain:')
6222: .' <input type="radio" name="selfenroll_all" value="1" ';
6223: if ($curr_types eq '*') {
6224: $output .= ' checked="checked" ';
6225: }
1.249 raeburn 6226: $output .= 'onchange="javascript:update_types('.
1.418 raeburn 6227: "'selfenroll_all'".');"'.$disabled.' />'.&mt('Yes').'</label>'.
1.249 raeburn 6228: ' <input type="radio" name="selfenroll_all" value="0" ';
1.241 raeburn 6229: if ($curr_types ne '*') {
6230: $output .= ' checked="checked" ';
6231: }
1.249 raeburn 6232: $output .= ' onchange="javascript:update_types('.
1.418 raeburn 6233: "'selfenroll_all'".');"'.$disabled.' />'.&mt('No').'</label></td>'.
1.249 raeburn 6234: &Apache::loncommon::end_data_table_row().
6235: &Apache::loncommon::end_data_table().
6236: &mt('Or').'<br />'.
6237: &Apache::loncommon::start_data_table();
1.241 raeburn 6238: my %currdoms;
1.249 raeburn 6239: if ($curr_types eq '') {
1.241 raeburn 6240: $output .= &new_selfenroll_dom_row($cdom,'0');
6241: } elsif ($curr_types ne '*') {
6242: my @entries = split(/;/,$curr_types);
6243: if (@entries > 0) {
6244: foreach my $entry (@entries) {
6245: my ($currdom,$typestr) = split(/:/,$entry);
6246: $currdoms{$currdom} = 1;
6247: my $domdesc = &Apache::lonnet::domain($currdom);
1.249 raeburn 6248: my @currinsttypes = split(',',$typestr);
1.241 raeburn 6249: $output .= &Apache::loncommon::start_data_table_row()
6250: .'<td valign="top"><span class="LC_nobreak">'.&mt('Domain:').'<b>'
6251: .' '.$domdesc.' ('.$currdom.')'
6252: .'</b><input type="hidden" name="selfenroll_dom_'.$num
6253: .'" value="'.$currdom.'" /></span><br />'
6254: .'<span class="LC_nobreak"><label><input type="checkbox" '
1.418 raeburn 6255: .'name="selfenroll_delete" value="'.$num.'" onchange="javascript:update_types('."'selfenroll_delete','$num'".');"'.$disabled.' />'
1.241 raeburn 6256: .&mt('Delete').'</label></span></td>';
1.249 raeburn 6257: $output .= '<td valign="top"> '.&mt('User types:').'<br />'
1.418 raeburn 6258: .&selfenroll_inst_types($num,$currdom,\@currinsttypes,$readonly).'</td>'
1.241 raeburn 6259: .&Apache::loncommon::end_data_table_row();
6260: $num ++;
6261: }
6262: }
6263: }
1.249 raeburn 6264: my $add_domtitle = &mt('Users in additional domain:');
1.241 raeburn 6265: if ($curr_types eq '*') {
1.249 raeburn 6266: $add_domtitle = &mt('Users in specific domain:');
1.241 raeburn 6267: } elsif ($curr_types eq '') {
1.249 raeburn 6268: $add_domtitle = &mt('Users in other domain:');
1.241 raeburn 6269: }
1.446 raeburn 6270: my ($trusted,$untrusted) = &Apache::lonnet::trusted_domains('enroll',$cdom);
1.241 raeburn 6271: $output .= &Apache::loncommon::start_data_table_row()
6272: .'<td colspan="2"><span class="LC_nobreak">'.$add_domtitle.'</span><br />'
6273: .&Apache::loncommon::select_dom_form('','selfenroll_newdom',
1.446 raeburn 6274: $includeempty,$showdomdesc,'',$trusted,$untrusted,$readonly)
1.241 raeburn 6275: .'<input type="hidden" name="selfenroll_types_total" value="'.$num.'" />'
6276: .'</td>'.&Apache::loncommon::end_data_table_row()
6277: .&Apache::loncommon::end_data_table();
1.237 raeburn 6278: } elsif ($item eq 'registered') {
6279: my ($regon,$regoff);
1.398 raeburn 6280: my $registered;
6281: if (ref($currsettings) eq 'HASH') {
6282: $registered = $currsettings->{'selfenroll_registered'};
6283: }
1.400 raeburn 6284: if ($noedit{$item}) {
6285: if ($registered) {
6286: $output .= &mt('Must be registered in course');
6287: } else {
6288: $output .= &mt('No requirement');
6289: }
6290: $output .= '<br />'.&mt('(Set by Domain Coordinator)');
6291: next;
6292: }
1.398 raeburn 6293: if ($registered) {
1.237 raeburn 6294: $regon = ' checked="checked" ';
1.419 raeburn 6295: $regoff = '';
1.237 raeburn 6296: } else {
1.419 raeburn 6297: $regon = '';
1.237 raeburn 6298: $regoff = ' checked="checked" ';
6299: }
6300: $output .= '<label>'.
1.419 raeburn 6301: '<input type="radio" name="selfenroll_registered" value="1"'.$regon.$disabled.' />'.
1.244 bisitz 6302: &mt('Yes').'</label> <label>'.
1.419 raeburn 6303: '<input type="radio" name="selfenroll_registered" value="0"'.$regoff.$disabled.' />'.
1.244 bisitz 6304: &mt('No').'</label>';
1.237 raeburn 6305: } elsif ($item eq 'enroll_dates') {
1.398 raeburn 6306: my ($starttime,$endtime);
6307: if (ref($currsettings) eq 'HASH') {
6308: $starttime = $currsettings->{'selfenroll_start_date'};
6309: $endtime = $currsettings->{'selfenroll_end_date'};
6310: if ($starttime eq '') {
6311: $starttime = $currsettings->{'default_enrollment_start_date'};
6312: }
6313: if ($endtime eq '') {
6314: $endtime = $currsettings->{'default_enrollment_end_date'};
6315: }
1.237 raeburn 6316: }
1.400 raeburn 6317: if ($noedit{$item}) {
6318: $output .= &mt('From: [_1], to: [_2]',&Apache::lonlocal::locallocaltime($starttime),
6319: &Apache::lonlocal::locallocaltime($endtime));
6320: $output .= '<br />'.&mt('(Set by Domain Coordinator)');
6321: next;
6322: }
1.237 raeburn 6323: my $startform =
6324: &Apache::lonhtmlcommon::date_setter($formname,'selfenroll_start_date',$starttime,
1.418 raeburn 6325: $disabled,undef,undef,undef,undef,undef,undef,$nolink);
1.237 raeburn 6326: my $endform =
6327: &Apache::lonhtmlcommon::date_setter($formname,'selfenroll_end_date',$endtime,
1.418 raeburn 6328: $disabled,undef,undef,undef,undef,undef,undef,$nolink);
1.237 raeburn 6329: $output .= &selfenroll_date_forms($startform,$endform);
6330: } elsif ($item eq 'access_dates') {
1.398 raeburn 6331: my ($starttime,$endtime);
6332: if (ref($currsettings) eq 'HASH') {
6333: $starttime = $currsettings->{'selfenroll_start_access'};
6334: $endtime = $currsettings->{'selfenroll_end_access'};
6335: if ($starttime eq '') {
6336: $starttime = $currsettings->{'default_enrollment_start_date'};
6337: }
6338: if ($endtime eq '') {
6339: $endtime = $currsettings->{'default_enrollment_end_date'};
6340: }
1.237 raeburn 6341: }
1.400 raeburn 6342: if ($noedit{$item}) {
6343: $output .= &mt('From: [_1], to: [_2]',&Apache::lonlocal::locallocaltime($starttime),
6344: &Apache::lonlocal::locallocaltime($endtime));
6345: $output .= '<br />'.&mt('(Set by Domain Coordinator)');
6346: next;
6347: }
1.237 raeburn 6348: my $startform =
6349: &Apache::lonhtmlcommon::date_setter($formname,'selfenroll_start_access',$starttime,
1.418 raeburn 6350: $disabled,undef,undef,undef,undef,undef,undef,$nolink);
1.237 raeburn 6351: my $endform =
6352: &Apache::lonhtmlcommon::date_setter($formname,'selfenroll_end_access',$endtime,
1.418 raeburn 6353: $disabled,undef,undef,undef,undef,undef,undef,$nolink);
1.237 raeburn 6354: $output .= &selfenroll_date_forms($startform,$endform);
6355: } elsif ($item eq 'section') {
1.398 raeburn 6356: my $currsec;
6357: if (ref($currsettings) eq 'HASH') {
6358: $currsec = $currsettings->{'selfenroll_section'};
6359: }
1.237 raeburn 6360: my %sections_count = &Apache::loncommon::get_sections($cdom,$cnum);
6361: my $newsecval;
6362: if ($currsec ne 'none' && $currsec ne '') {
6363: if (!defined($sections_count{$currsec})) {
6364: $newsecval = $currsec;
6365: }
6366: }
1.400 raeburn 6367: if ($noedit{$item}) {
6368: if ($currsec ne '') {
6369: $output .= $currsec;
6370: } else {
6371: $output .= &mt('No specific section');
6372: }
6373: $output .= '<br />'.&mt('(Set by Domain Coordinator)');
6374: next;
6375: }
1.237 raeburn 6376: my $sections_select =
1.418 raeburn 6377: &Apache::lonuserutils::course_sections(\%sections_count,'st',$currsec,$disabled);
1.237 raeburn 6378: $output .= '<table class="LC_createuser">'."\n".
6379: '<tr class="LC_section_row">'."\n".
6380: '<td align="center">'.&mt('Existing sections')."\n".
6381: '<br />'.$sections_select.'</td><td align="center">'.
6382: &mt('New section').'<br />'."\n".
1.418 raeburn 6383: '<input type="text" name="newsec" size="15" value="'.$newsecval.'"'.$disabled.' />'."\n".
1.237 raeburn 6384: '<input type="hidden" name="sections" value="" />'."\n".
6385: '</td></tr></table>'."\n";
1.276 raeburn 6386: } elsif ($item eq 'approval') {
1.398 raeburn 6387: my ($currnotified,$currapproval,%appchecked);
6388: my %selfdescs = &Apache::lonuserutils::selfenroll_default_descs();
1.430 raeburn 6389: if (ref($currsettings) eq 'HASH') {
1.398 raeburn 6390: $currnotified = $currsettings->{'selfenroll_notifylist'};
6391: $currapproval = $currsettings->{'selfenroll_approval'};
6392: }
6393: if ($currapproval !~ /^[012]$/) {
6394: $currapproval = 0;
6395: }
1.400 raeburn 6396: if ($noedit{$item}) {
6397: $output .= $selfdescs{'approval'}{$currapproval}.
6398: '<br />'.&mt('(Set by Domain Coordinator)');
6399: next;
6400: }
1.398 raeburn 6401: $appchecked{$currapproval} = ' checked="checked"';
6402: for my $i (0..2) {
6403: $output .= '<label>'.
6404: '<input type="radio" name="selfenroll_approval" value="'.$i.'"'.
1.418 raeburn 6405: $appchecked{$i}.' onclick="toggleNotify();"'.$disabled.' />'.
6406: $selfdescs{'approval'}{$i}.'</label>'.(' 'x2);
1.276 raeburn 6407: }
6408: my %advhash = &Apache::lonnet::get_course_adv_roles($cid,1);
6409: my (@ccs,%notified);
1.322 raeburn 6410: my $ccrole = 'cc';
6411: if ($crstype eq 'Community') {
6412: $ccrole = 'co';
6413: }
6414: if ($advhash{$ccrole}) {
6415: @ccs = split(/,/,$advhash{$ccrole});
1.276 raeburn 6416: }
6417: if ($currnotified) {
6418: foreach my $current (split(/,/,$currnotified)) {
6419: $notified{$current} = 1;
6420: if (!grep(/^\Q$current\E$/,@ccs)) {
6421: push(@ccs,$current);
6422: }
6423: }
6424: }
6425: if (@ccs) {
1.398 raeburn 6426: my $style;
6427: unless ($currapproval) {
6428: $style = ' style="display: none;"';
6429: }
6430: $output .= '<br /><div id="notified"'.$style.'>'.
6431: &mt('Personnel to be notified when an enrollment request needs approval, or has been approved:').' '.
6432: &Apache::loncommon::start_data_table().
1.276 raeburn 6433: &Apache::loncommon::start_data_table_row();
6434: my $count = 0;
6435: my $numcols = 4;
6436: foreach my $cc (sort(@ccs)) {
6437: my $notifyon;
6438: my ($ccuname,$ccudom) = split(/:/,$cc);
6439: if ($notified{$cc}) {
6440: $notifyon = ' checked="checked" ';
6441: }
6442: if ($count && !$count%$numcols) {
6443: $output .= &Apache::loncommon::end_data_table_row().
6444: &Apache::loncommon::start_data_table_row()
6445: }
6446: $output .= '<td><span class="LC_nobreak"><label>'.
1.418 raeburn 6447: '<input type="checkbox" name="selfenroll_notify"'.$notifyon.' value="'.$cc.'"'.$disabled.' />'.
1.276 raeburn 6448: &Apache::loncommon::plainname($ccuname,$ccudom).
6449: '</label></span></td>';
1.343 raeburn 6450: $count ++;
1.276 raeburn 6451: }
6452: my $rem = $count%$numcols;
6453: if ($rem) {
6454: my $emptycols = $numcols - $rem;
6455: for (my $i=0; $i<$emptycols; $i++) {
6456: $output .= '<td> </td>';
6457: }
6458: }
6459: $output .= &Apache::loncommon::end_data_table_row().
1.398 raeburn 6460: &Apache::loncommon::end_data_table().
6461: '</div>';
1.276 raeburn 6462: }
6463: } elsif ($item eq 'limit') {
1.398 raeburn 6464: my ($crslimit,$selflimit,$nolimit,$currlim,$currcap);
6465: if (ref($currsettings) eq 'HASH') {
6466: $currlim = $currsettings->{'selfenroll_limit'};
6467: $currcap = $currsettings->{'selfenroll_cap'};
6468: }
1.400 raeburn 6469: if ($noedit{$item}) {
6470: if (($currlim eq 'allstudents') || ($currlim eq 'selfenrolled')) {
6471: if ($currlim eq 'allstudents') {
6472: $output .= &mt('Limit by total students');
6473: } elsif ($currlim eq 'selfenrolled') {
6474: $output .= &mt('Limit by total self-enrolled students');
6475: }
6476: $output .= ' '.&mt('Maximum: [_1]',$currcap).
6477: '<br />'.&mt('(Set by Domain Coordinator)');
6478: } else {
6479: $output .= &mt('No limit').'<br />'.&mt('(Set by Domain Coordinator)');
6480: }
6481: next;
6482: }
1.276 raeburn 6483: if ($currlim eq 'allstudents') {
6484: $crslimit = ' checked="checked" ';
6485: $selflimit = ' ';
6486: $nolimit = ' ';
6487: } elsif ($currlim eq 'selfenrolled') {
6488: $crslimit = ' ';
6489: $selflimit = ' checked="checked" ';
6490: $nolimit = ' ';
6491: } else {
6492: $crslimit = ' ';
6493: $selflimit = ' ';
1.398 raeburn 6494: $nolimit = ' checked="checked" ';
1.276 raeburn 6495: }
6496: $output .= '<table><tr><td><label>'.
1.418 raeburn 6497: '<input type="radio" name="selfenroll_limit" value="none"'.$nolimit.$disabled.'/>'.
1.276 raeburn 6498: &mt('No limit').'</label></td><td><label>'.
1.418 raeburn 6499: '<input type="radio" name="selfenroll_limit" value="allstudents"'.$crslimit.$disabled.'/>'.
1.276 raeburn 6500: &mt('Limit by total students').'</label></td><td><label>'.
1.418 raeburn 6501: '<input type="radio" name="selfenroll_limit" value="selfenrolled"'.$selflimit.$disabled.'/>'.
1.276 raeburn 6502: &mt('Limit by total self-enrolled students').
6503: '</td></tr><tr>'.
6504: '<td> </td><td colspan="2"><span class="LC_nobreak">'.
6505: (' 'x3).&mt('Maximum number allowed: ').
1.418 raeburn 6506: '<input type="text" name="selfenroll_cap" size = "5" value="'.$currcap.'"'.$disabled.' /></td></tr></table>';
1.237 raeburn 6507: }
6508: $output .= &Apache::lonhtmlcommon::row_closure(1);
6509: }
6510: }
1.418 raeburn 6511: $output .= &Apache::lonhtmlcommon::end_pick_box().'<br />';
6512: unless ($readonly) {
6513: $output .= '<input type="button" name="selfenrollconf" value="'
6514: .&mt('Save').'" onclick="validate_types(this.form);" />';
6515: }
6516: $output .= '<input type="hidden" name="action" value="selfenroll" />'
6517: .'<input type="hidden" name="state" value="done" />'."\n"
6518: .$additional.'</form>';
1.237 raeburn 6519: $r->print($output);
6520: return;
6521: }
6522:
1.400 raeburn 6523: sub get_noedit_fields {
6524: my ($cdom,$cnum,$crstype,$row) = @_;
6525: my %noedit;
6526: if (ref($row) eq 'ARRAY') {
6527: my %settings = &Apache::lonnet::get('environment',['internal.coursecode','internal.textbook',
6528: 'internal.selfenrollmgrdc',
6529: 'internal.selfenrollmgrcc'],$cdom,$cnum);
6530: my $type = &Apache::lonuserutils::get_extended_type($cdom,$cnum,$crstype,\%settings);
6531: my (%specific_managebydc,%specific_managebycc,%default_managebydc);
6532: map { $specific_managebydc{$_} = 1; } (split(/,/,$settings{'internal.selfenrollmgrdc'}));
6533: map { $specific_managebycc{$_} = 1; } (split(/,/,$settings{'internal.selfenrollmgrcc'}));
6534: my %domdefaults = &Apache::lonnet::get_domain_defaults($cdom);
6535: map { $default_managebydc{$_} = 1; } (split(/,/,$domdefaults{$type.'selfenrolladmdc'}));
6536:
6537: foreach my $item (@{$row}) {
6538: next if ($specific_managebycc{$item});
6539: if (($specific_managebydc{$item}) || ($default_managebydc{$item})) {
6540: $noedit{$item} = 1;
6541: }
6542: }
6543: }
6544: return %noedit;
6545: }
6546:
6547: sub visible_in_stdcat {
6548: my ($cdom,$cnum,$domconf) = @_;
6549: my ($cathash,%settable,@vismsgs,$cansetvis,$visible);
6550: unless (ref($domconf) eq 'HASH') {
6551: return ($visible,$cansetvis,\@vismsgs);
6552: }
6553: if (ref($domconf->{'coursecategories'}) eq 'HASH') {
6554: if ($domconf->{'coursecategories'}{'togglecats'} eq 'crs') {
1.256 raeburn 6555: $settable{'togglecats'} = 1;
6556: }
1.400 raeburn 6557: if ($domconf->{'coursecategories'}{'categorize'} eq 'crs') {
1.256 raeburn 6558: $settable{'categorize'} = 1;
6559: }
1.400 raeburn 6560: $cathash = $domconf->{'coursecategories'}{'cats'};
1.256 raeburn 6561: }
1.260 raeburn 6562: if ($settable{'togglecats'} && $settable{'categorize'}) {
1.256 raeburn 6563: $cansetvis = &mt('You are able to both assign a course category and choose to exclude this course from the catalog.');
6564: } elsif ($settable{'togglecats'}) {
6565: $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 6566: } elsif ($settable{'categorize'}) {
1.256 raeburn 6567: $cansetvis = &mt('You may assign a course category, but only a Domain Coordinator may choose to exclude this course from the catalog.');
6568: } else {
6569: $cansetvis = &mt('Only a Domain Coordinator may assign a course category or choose to exclude this course from the catalog.');
6570: }
6571:
6572: my %currsettings =
6573: &Apache::lonnet::get('environment',['hidefromcat','categories','internal.coursecode'],
6574: $cdom,$cnum);
1.400 raeburn 6575: $visible = 0;
1.256 raeburn 6576: if ($currsettings{'internal.coursecode'} ne '') {
1.400 raeburn 6577: if (ref($domconf->{'coursecategories'}) eq 'HASH') {
6578: $cathash = $domconf->{'coursecategories'}{'cats'};
1.256 raeburn 6579: if (ref($cathash) eq 'HASH') {
6580: if ($cathash->{'instcode::0'} eq '') {
6581: push(@vismsgs,'dc_addinst');
6582: } else {
6583: $visible = 1;
6584: }
6585: } else {
6586: $visible = 1;
6587: }
6588: } else {
6589: $visible = 1;
6590: }
6591: } else {
6592: if (ref($cathash) eq 'HASH') {
6593: if ($cathash->{'instcode::0'} ne '') {
6594: push(@vismsgs,'dc_instcode');
6595: }
6596: } else {
6597: push(@vismsgs,'dc_instcode');
6598: }
6599: }
6600: if ($currsettings{'categories'} ne '') {
6601: my $cathash;
1.400 raeburn 6602: if (ref($domconf->{'coursecategories'}) eq 'HASH') {
6603: $cathash = $domconf->{'coursecategories'}{'cats'};
1.256 raeburn 6604: if (ref($cathash) eq 'HASH') {
6605: if (keys(%{$cathash}) == 0) {
6606: push(@vismsgs,'dc_catalog');
6607: } elsif ((keys(%{$cathash}) == 1) && ($cathash->{'instcode::0'} ne '')) {
6608: push(@vismsgs,'dc_categories');
6609: } else {
6610: my @currcategories = split('&',$currsettings{'categories'});
6611: my $matched = 0;
6612: foreach my $cat (@currcategories) {
6613: if ($cathash->{$cat} ne '') {
6614: $visible = 1;
6615: $matched = 1;
6616: last;
6617: }
6618: }
6619: if (!$matched) {
1.260 raeburn 6620: if ($settable{'categorize'}) {
1.256 raeburn 6621: push(@vismsgs,'chgcat');
6622: } else {
6623: push(@vismsgs,'dc_chgcat');
6624: }
6625: }
6626: }
6627: }
6628: }
6629: } else {
6630: if (ref($cathash) eq 'HASH') {
6631: if ((keys(%{$cathash}) > 1) ||
6632: (keys(%{$cathash}) == 1) && ($cathash->{'instcode::0'} eq '')) {
1.260 raeburn 6633: if ($settable{'categorize'}) {
1.256 raeburn 6634: push(@vismsgs,'addcat');
6635: } else {
6636: push(@vismsgs,'dc_addcat');
6637: }
6638: }
6639: }
6640: }
6641: if ($currsettings{'hidefromcat'} eq 'yes') {
6642: $visible = 0;
6643: if ($settable{'togglecats'}) {
6644: unshift(@vismsgs,'unhide');
6645: } else {
6646: unshift(@vismsgs,'dc_unhide')
6647: }
6648: }
1.400 raeburn 6649: return ($visible,$cansetvis,\@vismsgs);
6650: }
6651:
6652: sub cat_visibility {
6653: my %visactions = &Apache::lonlocal::texthash(
6654: vis => 'This course/community currently appears in the Course/Community Catalog for this domain.',
6655: 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.',
6656: miss => 'This course/community does not currently appear in the Course/Community Catalog for this domain.',
6657: none => 'Display of a course catalog is disabled for this domain.',
6658: yous => 'You should remedy this if you plan to allow self-enrollment, otherwise students will have difficulty finding this course.',
6659: 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.',
6660: make => 'Make any changes to self-enrollment settings below, click "Save", then take action to include the course in the Catalog:',
6661: take => 'Take the following action to ensure the course appears in the Catalog:',
6662: dc_chgconf => 'Ask a domain coordinator to change the Catalog type for this domain.',
6663: dc_setcode => 'Ask a domain coordinator to assign a six character code to the course',
6664: dc_unhide => 'Ask a domain coordinator to change the "Exclude from course catalog" setting.',
6665: dc_addinst => 'Ask a domain coordinator to enable display the catalog of "Official courses (with institutional codes)".',
6666: dc_instcode => 'Ask a domain coordinator to assign an institutional code (if this is an official course).',
6667: dc_catalog => 'Ask a domain coordinator to enable or create at least one course category in the domain.',
6668: dc_categories => 'Ask a domain coordinator to create a hierarchy of categories and sub categories for courses in the domain.',
6669: 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',
6670: dc_addcat => 'Ask a domain coordinator to assign a category to the course.',
6671: );
6672: $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>"');
6673: $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>"');
6674: $visactions{'addcat'} = &mt('Use [_1]Categorize course[_2] to assign a category to the course.','"<a href="/adm/courseprefs?phase=display&actions=courseinfo">','</a>"');
6675: return \%visactions;
1.256 raeburn 6676: }
6677:
1.241 raeburn 6678: sub new_selfenroll_dom_row {
6679: my ($newdom,$num) = @_;
6680: my $domdesc = &Apache::lonnet::domain($newdom);
6681: my $output;
6682: if ($domdesc ne '') {
6683: $output .= &Apache::loncommon::start_data_table_row()
6684: .'<td valign="top"><span class="LC_nobreak">'.&mt('Domain:').' <b>'.$domdesc
6685: .' ('.$newdom.')</b><input type="hidden" name="selfenroll_dom_'.$num
1.249 raeburn 6686: .'" value="'.$newdom.'" /></span><br />'
6687: .'<span class="LC_nobreak"><label><input type="checkbox" '
6688: .'name="selfenroll_activate" value="'.$num.'" '
6689: .'onchange="javascript:update_types('
6690: ."'selfenroll_activate','$num'".');" />'
6691: .&mt('Activate').'</label></span></td>';
1.241 raeburn 6692: my @currinsttypes;
6693: $output .= '<td>'.&mt('User types:').'<br />'
6694: .&selfenroll_inst_types($num,$newdom,\@currinsttypes).'</td>'
6695: .&Apache::loncommon::end_data_table_row();
6696: }
6697: return $output;
6698: }
6699:
6700: sub selfenroll_inst_types {
1.418 raeburn 6701: my ($num,$currdom,$currinsttypes,$readonly) = @_;
1.241 raeburn 6702: my $output;
6703: my $numinrow = 4;
6704: my $count = 0;
6705: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($currdom);
1.247 raeburn 6706: my $othervalue = 'any';
1.418 raeburn 6707: my $disabled;
6708: if ($readonly) {
6709: $disabled = ' disabled="disabled"';
6710: }
1.241 raeburn 6711: if ((ref($types) eq 'ARRAY') && (ref($usertypes) eq 'HASH')) {
1.251 raeburn 6712: if (keys(%{$usertypes}) > 0) {
1.247 raeburn 6713: $othervalue = 'other';
6714: }
1.241 raeburn 6715: $output .= '<table><tr>';
6716: foreach my $type (@{$types}) {
6717: if (($count > 0) && ($count%$numinrow == 0)) {
6718: $output .= '</tr><tr>';
6719: }
6720: if (defined($usertypes->{$type})) {
1.257 raeburn 6721: my $esc_type = &escape($type);
1.241 raeburn 6722: $output .= '<td><span class="LC_nobreak"><label><input type = "checkbox" value="'.
1.257 raeburn 6723: $esc_type.'" ';
1.241 raeburn 6724: if (ref($currinsttypes) eq 'ARRAY') {
6725: if (@{$currinsttypes} > 0) {
1.249 raeburn 6726: if (grep(/^any$/,@{$currinsttypes})) {
6727: $output .= 'checked="checked"';
1.257 raeburn 6728: } elsif (grep(/^\Q$esc_type\E$/,@{$currinsttypes})) {
1.241 raeburn 6729: $output .= 'checked="checked"';
6730: }
1.249 raeburn 6731: } else {
6732: $output .= 'checked="checked"';
1.241 raeburn 6733: }
6734: }
1.418 raeburn 6735: $output .= ' name="selfenroll_types_'.$num.'"'.$disabled.' />'.$usertypes->{$type}.'</label></span></td>';
1.241 raeburn 6736: }
6737: $count ++;
6738: }
6739: if (($count > 0) && ($count%$numinrow == 0)) {
6740: $output .= '</tr><tr>';
6741: }
1.249 raeburn 6742: $output .= '<td><span class="LC_nobreak"><label><input type = "checkbox" value="'.$othervalue.'"';
1.241 raeburn 6743: if (ref($currinsttypes) eq 'ARRAY') {
6744: if (@{$currinsttypes} > 0) {
1.249 raeburn 6745: if (grep(/^any$/,@{$currinsttypes})) {
6746: $output .= ' checked="checked"';
6747: } elsif ($othervalue eq 'other') {
6748: if (grep(/^\Q$othervalue\E$/,@{$currinsttypes})) {
6749: $output .= ' checked="checked"';
6750: }
1.241 raeburn 6751: }
1.249 raeburn 6752: } else {
6753: $output .= ' checked="checked"';
1.241 raeburn 6754: }
1.249 raeburn 6755: } else {
6756: $output .= ' checked="checked"';
1.241 raeburn 6757: }
1.418 raeburn 6758: $output .= ' name="selfenroll_types_'.$num.'"'.$disabled.' />'.$othertitle.'</label></span></td></tr></table>';
1.241 raeburn 6759: }
6760: return $output;
6761: }
6762:
1.237 raeburn 6763: sub selfenroll_date_forms {
6764: my ($startform,$endform) = @_;
6765: my $output .= &Apache::lonhtmlcommon::start_pick_box()."\n".
1.244 bisitz 6766: &Apache::lonhtmlcommon::row_title(&mt('Start date'),
1.237 raeburn 6767: 'LC_oddrow_value')."\n".
6768: $startform."\n".
6769: &Apache::lonhtmlcommon::row_closure(1).
1.244 bisitz 6770: &Apache::lonhtmlcommon::row_title(&mt('End date'),
1.237 raeburn 6771: 'LC_oddrow_value')."\n".
6772: $endform."\n".
6773: &Apache::lonhtmlcommon::row_closure(1).
6774: &Apache::lonhtmlcommon::end_pick_box();
6775: return $output;
6776: }
6777:
1.239 raeburn 6778: sub print_userchangelogs_display {
1.415 raeburn 6779: my ($r,$context,$permission,$brcrum) = @_;
1.363 raeburn 6780: my $formname = 'rolelog';
1.418 raeburn 6781: my ($username,$domain,$crstype,$viewablesec,%roleslog);
1.363 raeburn 6782: if ($context eq 'domain') {
6783: $domain = $env{'request.role.domain'};
6784: %roleslog=&Apache::lonnet::dump_dom('nohist_rolelog',$domain);
6785: } else {
6786: if ($context eq 'course') {
6787: $domain = $env{'course.'.$env{'request.course.id'}.'.domain'};
6788: $username = $env{'course.'.$env{'request.course.id'}.'.num'};
6789: $crstype = &Apache::loncommon::course_type();
1.418 raeburn 6790: $viewablesec = &Apache::lonuserutils::viewable_section($permission);
1.363 raeburn 6791: my %saveable_parameters = ('show' => 'scalar',);
6792: &Apache::loncommon::store_course_settings('roles_log',
6793: \%saveable_parameters);
6794: &Apache::loncommon::restore_course_settings('roles_log',
6795: \%saveable_parameters);
6796: } elsif ($context eq 'author') {
6797: $domain = $env{'user.domain'};
6798: if ($env{'request.role'} =~ m{^au\./\Q$domain\E/$}) {
6799: $username = $env{'user.name'};
6800: } else {
6801: undef($domain);
6802: }
6803: }
6804: if ($domain ne '' && $username ne '') {
6805: %roleslog=&Apache::lonnet::dump('nohist_rolelog',$domain,$username);
6806: }
6807: }
1.239 raeburn 6808: if ((keys(%roleslog))[0]=~/^error\:/) { undef(%roleslog); }
6809:
1.415 raeburn 6810: my $helpitem;
6811: if ($context eq 'course') {
6812: $helpitem = 'Course_User_Logs';
1.439 raeburn 6813: } elsif ($context eq 'domain') {
6814: $helpitem = 'Domain_Role_Logs';
6815: } elsif ($context eq 'author') {
6816: $helpitem = 'Author_User_Logs';
1.415 raeburn 6817: }
6818: push (@{$brcrum},
6819: {href => '/adm/createuser?action=changelogs',
6820: text => 'User Management Logs',
6821: help => $helpitem});
6822: my $bread_crumbs_component = 'User Changes';
6823: my $args = { bread_crumbs => $brcrum,
6824: bread_crumbs_component => $bread_crumbs_component};
6825:
6826: # Create navigation javascript
6827: my $jsnav = &userlogdisplay_js($formname);
6828:
6829: my $jscript = (<<ENDSCRIPT);
6830: <script type="text/javascript">
6831: // <![CDATA[
6832: $jsnav
6833: // ]]>
6834: </script>
6835: ENDSCRIPT
6836:
6837: # print page header
6838: $r->print(&header($jscript,$args));
6839:
1.239 raeburn 6840: # set defaults
6841: my $now = time();
6842: my $defstart = $now - (7*24*3600); #7 days ago
6843: my %defaults = (
6844: page => '1',
6845: show => '10',
6846: role => 'any',
6847: chgcontext => 'any',
6848: rolelog_start_date => $defstart,
6849: rolelog_end_date => $now,
6850: );
6851: my $more_records = 0;
6852:
6853: # set current
6854: my %curr;
6855: foreach my $item ('show','page','role','chgcontext') {
6856: $curr{$item} = $env{'form.'.$item};
6857: }
6858: my ($startdate,$enddate) =
6859: &Apache::lonuserutils::get_dates_from_form('rolelog_start_date','rolelog_end_date');
6860: $curr{'rolelog_start_date'} = $startdate;
6861: $curr{'rolelog_end_date'} = $enddate;
6862: foreach my $key (keys(%defaults)) {
6863: if ($curr{$key} eq '') {
6864: $curr{$key} = $defaults{$key};
6865: }
6866: }
1.248 raeburn 6867: my (%whodunit,%changed,$version);
6868: ($version) = ($r->dir_config('lonVersion') =~ /^([\d\.]+)\-/);
1.239 raeburn 6869: my ($minshown,$maxshown);
1.255 raeburn 6870: $minshown = 1;
1.239 raeburn 6871: my $count = 0;
1.415 raeburn 6872: if ($curr{'show'} =~ /\D/) {
6873: $curr{'page'} = 1;
6874: } else {
1.239 raeburn 6875: $maxshown = $curr{'page'} * $curr{'show'};
6876: if ($curr{'page'} > 1) {
6877: $minshown = 1 + ($curr{'page'} - 1) * $curr{'show'};
6878: }
6879: }
1.301 bisitz 6880:
1.327 raeburn 6881: # Form Header
6882: $r->print('<form action="/adm/createuser" method="post" name="'.$formname.'">'.
1.363 raeburn 6883: &role_display_filter($context,$formname,$domain,$username,\%curr,
6884: $version,$crstype));
1.327 raeburn 6885:
6886: my $showntableheader = 0;
6887:
6888: # Table Header
6889: my $tableheader =
6890: &Apache::loncommon::start_data_table_header_row()
6891: .'<th> </th>'
6892: .'<th>'.&mt('When').'</th>'
6893: .'<th>'.&mt('Who made the change').'</th>'
6894: .'<th>'.&mt('Changed User').'</th>'
1.363 raeburn 6895: .'<th>'.&mt('Role').'</th>';
6896:
6897: if ($context eq 'course') {
6898: $tableheader .= '<th>'.&mt('Section').'</th>';
6899: }
6900: $tableheader .=
6901: '<th>'.&mt('Context').'</th>'
1.327 raeburn 6902: .'<th>'.&mt('Start').'</th>'
6903: .'<th>'.&mt('End').'</th>'
6904: .&Apache::loncommon::end_data_table_header_row();
6905:
6906: # Display user change log data
1.239 raeburn 6907: foreach my $id (sort { $roleslog{$b}{'exe_time'}<=>$roleslog{$a}{'exe_time'} } (keys(%roleslog))) {
6908: next if (($roleslog{$id}{'exe_time'} < $curr{'rolelog_start_date'}) ||
6909: ($roleslog{$id}{'exe_time'} > $curr{'rolelog_end_date'}));
1.415 raeburn 6910: if ($curr{'show'} !~ /\D/) {
1.239 raeburn 6911: if ($count >= $curr{'page'} * $curr{'show'}) {
6912: $more_records = 1;
6913: last;
6914: }
6915: }
6916: if ($curr{'role'} ne 'any') {
6917: next if ($roleslog{$id}{'logentry'}{'role'} ne $curr{'role'});
6918: }
6919: if ($curr{'chgcontext'} ne 'any') {
6920: if ($curr{'chgcontext'} eq 'selfenroll') {
6921: next if (!$roleslog{$id}{'logentry'}{'selfenroll'});
6922: } else {
6923: next if ($roleslog{$id}{'logentry'}{'context'} ne $curr{'chgcontext'});
6924: }
6925: }
1.418 raeburn 6926: if (($context eq 'course') && ($viewablesec ne '')) {
1.430 raeburn 6927: next if ($roleslog{$id}{'logentry'}{'section'} ne $viewablesec);
1.418 raeburn 6928: }
1.239 raeburn 6929: $count ++;
6930: next if ($count < $minshown);
1.327 raeburn 6931: unless ($showntableheader) {
1.415 raeburn 6932: $r->print(&Apache::loncommon::start_data_table()
1.327 raeburn 6933: .$tableheader);
6934: $r->rflush();
6935: $showntableheader = 1;
6936: }
1.239 raeburn 6937: if ($whodunit{$roleslog{$id}{'exe_uname'}.':'.$roleslog{$id}{'exe_udom'}} eq '') {
6938: $whodunit{$roleslog{$id}{'exe_uname'}.':'.$roleslog{$id}{'exe_udom'}} =
6939: &Apache::loncommon::plainname($roleslog{$id}{'exe_uname'},$roleslog{$id}{'exe_udom'});
6940: }
6941: if ($changed{$roleslog{$id}{'uname'}.':'.$roleslog{$id}{'udom'}} eq '') {
6942: $changed{$roleslog{$id}{'uname'}.':'.$roleslog{$id}{'udom'}} =
6943: &Apache::loncommon::plainname($roleslog{$id}{'uname'},$roleslog{$id}{'udom'});
6944: }
6945: my $sec = $roleslog{$id}{'logentry'}{'section'};
6946: if ($sec eq '') {
6947: $sec = &mt('None');
6948: }
6949: my ($rolestart,$roleend);
6950: if ($roleslog{$id}{'delflag'}) {
6951: $rolestart = &mt('deleted');
6952: $roleend = &mt('deleted');
6953: } else {
6954: $rolestart = $roleslog{$id}{'logentry'}{'start'};
6955: $roleend = $roleslog{$id}{'logentry'}{'end'};
6956: if ($rolestart eq '' || $rolestart == 0) {
6957: $rolestart = &mt('No start date');
6958: } else {
6959: $rolestart = &Apache::lonlocal::locallocaltime($rolestart);
6960: }
6961: if ($roleend eq '' || $roleend == 0) {
6962: $roleend = &mt('No end date');
6963: } else {
6964: $roleend = &Apache::lonlocal::locallocaltime($roleend);
6965: }
6966: }
6967: my $chgcontext = $roleslog{$id}{'logentry'}{'context'};
6968: if ($roleslog{$id}{'logentry'}{'selfenroll'}) {
6969: $chgcontext = 'selfenroll';
6970: }
1.363 raeburn 6971: my %lt = &rolechg_contexts($context,$crstype);
1.239 raeburn 6972: if ($chgcontext ne '' && $lt{$chgcontext} ne '') {
6973: $chgcontext = $lt{$chgcontext};
6974: }
1.327 raeburn 6975: $r->print(
1.301 bisitz 6976: &Apache::loncommon::start_data_table_row()
6977: .'<td>'.$count.'</td>'
6978: .'<td>'.&Apache::lonlocal::locallocaltime($roleslog{$id}{'exe_time'}).'</td>'
6979: .'<td>'.$whodunit{$roleslog{$id}{'exe_uname'}.':'.$roleslog{$id}{'exe_udom'}}.'</td>'
6980: .'<td>'.$changed{$roleslog{$id}{'uname'}.':'.$roleslog{$id}{'udom'}}.'</td>'
1.363 raeburn 6981: .'<td>'.&Apache::lonnet::plaintext($roleslog{$id}{'logentry'}{'role'},$crstype).'</td>');
6982: if ($context eq 'course') {
6983: $r->print('<td>'.$sec.'</td>');
6984: }
6985: $r->print(
6986: '<td>'.$chgcontext.'</td>'
1.301 bisitz 6987: .'<td>'.$rolestart.'</td>'
6988: .'<td>'.$roleend.'</td>'
1.327 raeburn 6989: .&Apache::loncommon::end_data_table_row()."\n");
1.301 bisitz 6990: }
6991:
1.327 raeburn 6992: if ($showntableheader) { # Table footer, if content displayed above
1.415 raeburn 6993: $r->print(&Apache::loncommon::end_data_table().
6994: &userlogdisplay_navlinks(\%curr,$more_records));
1.327 raeburn 6995: } else { # No content displayed above
1.301 bisitz 6996: $r->print('<p class="LC_info">'
6997: .&mt('There are no records to display.')
6998: .'</p>'
6999: );
1.239 raeburn 7000: }
1.301 bisitz 7001:
1.327 raeburn 7002: # Form Footer
7003: $r->print(
7004: '<input type="hidden" name="page" value="'.$curr{'page'}.'" />'
7005: .'<input type="hidden" name="action" value="changelogs" />'
7006: .'</form>');
7007: return;
7008: }
1.301 bisitz 7009:
1.416 raeburn 7010: sub print_useraccesslogs_display {
7011: my ($r,$uname,$udom,$permission,$brcrum) = @_;
7012: my $formname = 'accesslog';
7013: my $form = 'document.accesslog';
7014:
7015: # set breadcrumbs
1.422 raeburn 7016: my %breadcrumb_text = &singleuser_breadcrumb('','domain',$udom);
1.431 raeburn 7017: my $prevphasestr;
7018: if ($env{'form.popup'}) {
7019: $brcrum = [];
7020: } else {
7021: push (@{$brcrum},
7022: {href => "javascript:backPage($form)",
7023: text => $breadcrumb_text{'search'}});
7024: my @prevphases;
7025: if ($env{'form.prevphases'}) {
7026: @prevphases = split(/,/,$env{'form.prevphases'});
7027: $prevphasestr = $env{'form.prevphases'};
7028: }
7029: if (($env{'form.phase'} eq 'userpicked') || (grep(/^userpicked$/,@prevphases))) {
7030: push(@{$brcrum},
7031: {href => "javascript:backPage($form,'get_user_info','select')",
7032: text => $breadcrumb_text{'userpicked'}});
7033: if ($env{'form.phase'} eq 'userpicked') {
7034: $prevphasestr = 'userpicked';
7035: }
1.416 raeburn 7036: }
7037: }
7038: push(@{$brcrum},
7039: {href => '/adm/createuser?action=accesslogs',
7040: text => 'User access logs',
1.424 raeburn 7041: help => 'Domain_User_Access_Logs'});
1.416 raeburn 7042: my $bread_crumbs_component = 'User Access Logs';
7043: my $args = { bread_crumbs => $brcrum,
7044: bread_crumbs_component => 'User Management'};
1.423 raeburn 7045: if ($env{'form.popup'}) {
7046: $args->{'no_nav_bar'} = 1;
1.431 raeburn 7047: $args->{'bread_crumbs_nomenu'} = 1;
1.423 raeburn 7048: }
1.416 raeburn 7049:
1.417 raeburn 7050: # set javascript
1.416 raeburn 7051: my ($jsback,$elements) = &crumb_utilities();
7052: my $jsnav = &userlogdisplay_js($formname);
7053:
7054: my $jscript = (<<ENDSCRIPT);
7055: <script type="text/javascript">
7056: // <![CDATA[
7057:
7058: $jsback
7059: $jsnav
7060:
7061: // ]]>
7062: </script>
7063:
7064: ENDSCRIPT
7065:
1.417 raeburn 7066: # print page header
1.416 raeburn 7067: $r->print(&header($jscript,$args));
7068:
7069: # early out unless log data can be displayed.
7070: unless ($permission->{'activity'}) {
7071: $r->print('<p class="LC_warning">'
7072: .&mt('You do not have rights to display user access logs.')
1.431 raeburn 7073: .'</p>');
7074: if ($env{'form.popup'}) {
7075: $r->print('<p><a href="javascript:window.close()">'.&mt('Close window').'</a></p>');
7076: } else {
7077: $r->print(&earlyout_accesslog_form($formname,$prevphasestr,$udom));
7078: }
1.416 raeburn 7079: return;
7080: }
7081:
7082: unless ($udom eq $env{'request.role.domain'}) {
7083: $r->print('<p class="LC_warning">'
7084: .&mt("User's domain must match role's domain")
7085: .'</p>'
7086: .&earlyout_accesslog_form($formname,$prevphasestr,$udom));
1.417 raeburn 7087: return;
1.416 raeburn 7088: }
7089:
7090: if (($uname eq '') || ($udom eq '')) {
7091: $r->print('<p class="LC_warning">'
7092: .&mt('Invalid username or domain')
7093: .'</p>'
7094: .&earlyout_accesslog_form($formname,$prevphasestr,$udom));
7095: return;
7096: }
7097:
1.437 raeburn 7098: if (&Apache::lonnet::privileged($uname,$udom,
7099: [$env{'request.role.domain'}],['dc','su'])) {
7100: unless (&Apache::lonnet::privileged($env{'user.name'},$env{'user.domain'},
7101: [$env{'request.role.domain'}],['dc','su'])) {
7102: $r->print('<p class="LC_warning">'
7103: .&mt('You need to be a privileged user to display user access logs for [_1]',
7104: &Apache::loncommon::aboutmewrapper(&Apache::loncommon::plainname($uname,$udom),
7105: $uname,$udom))
7106: .'</p>');
7107: if ($env{'form.popup'}) {
7108: $r->print('<p><a href="javascript:window.close()">'.&mt('Close window').'</a></p>');
7109: } else {
7110: $r->print(&earlyout_accesslog_form($formname,$prevphasestr,$udom));
7111: }
7112: return;
7113: }
7114: }
7115:
1.416 raeburn 7116: # set defaults
7117: my $now = time();
7118: my $defstart = $now - (7*24*3600);
7119: my %defaults = (
7120: page => '1',
7121: show => '10',
7122: activity => 'any',
7123: accesslog_start_date => $defstart,
7124: accesslog_end_date => $now,
7125: );
7126: my $more_records = 0;
7127:
7128: # set current
7129: my %curr;
7130: foreach my $item ('show','page','activity') {
7131: $curr{$item} = $env{'form.'.$item};
7132: }
7133: my ($startdate,$enddate) =
7134: &Apache::lonuserutils::get_dates_from_form('accesslog_start_date','accesslog_end_date');
7135: $curr{'accesslog_start_date'} = $startdate;
7136: $curr{'accesslog_end_date'} = $enddate;
7137: foreach my $key (keys(%defaults)) {
7138: if ($curr{$key} eq '') {
7139: $curr{$key} = $defaults{$key};
7140: }
7141: }
7142: my ($minshown,$maxshown);
7143: $minshown = 1;
7144: my $count = 0;
7145: if ($curr{'show'} =~ /\D/) {
7146: $curr{'page'} = 1;
7147: } else {
7148: $maxshown = $curr{'page'} * $curr{'show'};
7149: if ($curr{'page'} > 1) {
7150: $minshown = 1 + ($curr{'page'} - 1) * $curr{'show'};
7151: }
7152: }
7153:
7154: # form header
7155: $r->print('<form action="/adm/createuser" method="post" name="'.$formname.'">'.
7156: &activity_display_filter($formname,\%curr));
7157:
7158: my $showntableheader = 0;
7159: my ($nav_script,$nav_links);
7160:
7161: # table header
1.453 raeburn 7162: my $heading = '<h3>'.
1.431 raeburn 7163: &mt('User access logs for: [_1]',
1.453 raeburn 7164: &Apache::loncommon::aboutmewrapper(&Apache::loncommon::plainname($uname,$udom),$uname,$udom)).'</h3>';
7165: my $tableheader = $heading
1.431 raeburn 7166: .&Apache::loncommon::start_data_table_header_row()
1.416 raeburn 7167: .'<th> </th>'
7168: .'<th>'.&mt('When').'</th>'
7169: .'<th>'.&mt('HostID').'</th>'
7170: .'<th>'.&mt('Event').'</th>'
7171: .'<th>'.&mt('Other data').'</th>'
7172: .&Apache::loncommon::end_data_table_header_row();
7173:
7174: my %filters=(
7175: start => $curr{'accesslog_start_date'},
7176: end => $curr{'accesslog_end_date'},
7177: action => $curr{'activity'},
7178: );
7179:
7180: my $reply = &Apache::lonnet::userlog_query($uname,$udom,%filters);
7181: unless ( ($reply =~/^timeout/) || ($reply =~/^error/) ) {
7182: my (%courses,%missing);
7183: my @results = split(/\&/,$reply);
7184: foreach my $item (reverse(@results)) {
7185: my ($timestamp,$host,$event) = split(/:/,$item);
7186: next unless ($event =~ /^(Log|Role)/);
7187: if ($curr{'show'} !~ /\D/) {
7188: if ($count >= $curr{'page'} * $curr{'show'}) {
7189: $more_records = 1;
7190: last;
7191: }
7192: }
7193: $count ++;
7194: next if ($count < $minshown);
7195: unless ($showntableheader) {
7196: $r->print($nav_script
7197: .&Apache::loncommon::start_data_table()
7198: .$tableheader);
7199: $r->rflush();
7200: $showntableheader = 1;
7201: }
1.418 raeburn 7202: my ($shown,$extra);
1.437 raeburn 7203: my ($event,$data) = split(/\s+/,&unescape($event),2);
1.416 raeburn 7204: if ($event eq 'Role') {
7205: my ($rolecode,$extent) = split(/\./,$data,2);
7206: next if ($extent eq '');
7207: my ($crstype,$desc,$info);
1.418 raeburn 7208: if ($extent =~ m{^/($match_domain)/($match_courseid)(?:/(\w+)|)$}) {
7209: my ($cdom,$cnum,$sec) = ($1,$2,$3);
1.416 raeburn 7210: my $cid = $cdom.'_'.$cnum;
7211: if (exists($courses{$cid})) {
7212: $crstype = $courses{$cid}{'type'};
7213: $desc = $courses{$cid}{'description'};
7214: } elsif ($missing{$cid}) {
7215: $crstype = 'Course';
7216: $desc = 'Course/Community';
7217: } else {
7218: my %crsinfo = &Apache::lonnet::courseiddump($cdom,'.',1,'.','.',$cnum,undef,undef,'.');
7219: if (ref($crsinfo{$cdom.'_'.$cnum}) eq 'HASH') {
7220: $courses{$cid} = $crsinfo{$cid};
7221: $crstype = $crsinfo{$cid}{'type'};
7222: $desc = $crsinfo{$cid}{'description'};
7223: } else {
7224: $missing{$cid} = 1;
7225: }
7226: }
7227: $extra = &mt($crstype).': <a href="/public/'.$cdom.'/'.$cnum.'/syllabus">'.$desc.'</a>';
1.418 raeburn 7228: if ($sec ne '') {
7229: $extra .= ' ('.&mt('Section: [_1]',$sec).')';
7230: }
1.416 raeburn 7231: } elsif ($extent =~ m{^/($match_domain)/($match_username|$)}) {
7232: my ($dom,$name) = ($1,$2);
7233: if ($rolecode eq 'au') {
7234: $extra = '';
7235: } elsif ($rolecode =~ /^(ca|aa)$/) {
1.417 raeburn 7236: $extra = &mt('Authoring Space: [_1]',$name.':'.$dom);
1.416 raeburn 7237: } elsif ($rolecode =~ /^(li|dg|dh|dc|sc)$/) {
7238: $extra = &mt('Domain: [_1]',$dom);
7239: }
7240: }
7241: my $rolename;
7242: if ($rolecode =~ m{^cr/($match_domain)/($match_username)/(\w+)}) {
7243: my $role = $3;
1.417 raeburn 7244: my $owner = "($2:$1)";
1.416 raeburn 7245: if ($2 eq $1.'-domainconfig') {
7246: $owner = '(ad hoc)';
1.417 raeburn 7247: }
1.416 raeburn 7248: $rolename = &mt('Custom role: [_1]',$role.' '.$owner);
7249: } else {
7250: $rolename = &Apache::lonnet::plaintext($rolecode,$crstype);
7251: }
7252: $shown = &mt('Role selection: [_1]',$rolename);
7253: } else {
7254: $shown = &mt($event);
1.437 raeburn 7255: if ($data =~ /^webdav/) {
7256: my ($path,$clientip) = split(/\s+/,$data,2);
7257: $path =~ s/^webdav//;
7258: if ($clientip ne '') {
7259: $extra = &mt('Client IP address: [_1]',$clientip);
7260: }
7261: if ($path ne '') {
7262: $shown .= ' '.&mt('(WebDAV access to [_1])',$path);
7263: }
7264: } elsif ($data ne '') {
7265: $extra = &mt('Client IP address: [_1]',$data);
1.416 raeburn 7266: }
7267: }
7268: $r->print(
7269: &Apache::loncommon::start_data_table_row()
7270: .'<td>'.$count.'</td>'
7271: .'<td>'.&Apache::lonlocal::locallocaltime($timestamp).'</td>'
7272: .'<td>'.$host.'</td>'
7273: .'<td>'.$shown.'</td>'
7274: .'<td>'.$extra.'</td>'
7275: .&Apache::loncommon::end_data_table_row()."\n");
7276: }
7277: }
7278:
7279: if ($showntableheader) { # Table footer, if content displayed above
7280: $r->print(&Apache::loncommon::end_data_table().
7281: &userlogdisplay_navlinks(\%curr,$more_records));
7282: } else { # No content displayed above
1.453 raeburn 7283: $r->print($heading.'<p class="LC_info">'
1.416 raeburn 7284: .&mt('There are no records to display.')
7285: .'</p>');
7286: }
7287:
1.423 raeburn 7288: if ($env{'form.popup'} == 1) {
7289: $r->print('<input type="hidden" name="popup" value="1" />'."\n");
7290: }
7291:
1.416 raeburn 7292: # Form Footer
7293: $r->print(
7294: '<input type="hidden" name="currstate" value="" />'
7295: .'<input type="hidden" name="accessuname" value="'.$uname.'" />'
7296: .'<input type="hidden" name="accessudom" value="'.$udom.'" />'
7297: .'<input type="hidden" name="page" value="'.$curr{'page'}.'" />'
7298: .'<input type="hidden" name="prevphases" value="'.$prevphasestr.'" />'
7299: .'<input type="hidden" name="phase" value="activity" />'
7300: .'<input type="hidden" name="action" value="accesslogs" />'
7301: .'<input type="hidden" name="srchdomain" value="'.$udom.'" />'
7302: .'<input type="hidden" name="srchby" value="'.$env{'form.srchby'}.'" />'
7303: .'<input type="hidden" name="srchtype" value="'.$env{'form.srchtype'}.'" />'
7304: .'<input type="hidden" name="srchterm" value="'.&HTML::Entities::encode($env{'form.srchterm'},'<>"&').'" />'
7305: .'<input type="hidden" name="srchin" value="'.$env{'form.srchin'}.'" />'
7306: .'</form>');
7307: return;
7308: }
7309:
7310: sub earlyout_accesslog_form {
7311: my ($formname,$prevphasestr,$udom) = @_;
7312: my $srchterm = &HTML::Entities::encode($env{'form.srchterm'},'<>"&');
7313: return <<"END";
7314: <form action="/adm/createuser" method="post" name="$formname">
7315: <input type="hidden" name="currstate" value="" />
7316: <input type="hidden" name="prevphases" value="$prevphasestr" />
7317: <input type="hidden" name="phase" value="activity" />
7318: <input type="hidden" name="action" value="accesslogs" />
7319: <input type="hidden" name="srchdomain" value="$udom" />
7320: <input type="hidden" name="srchby" value="$env{'form.srchby'}" />
7321: <input type="hidden" name="srchtype" value="$env{'form.srchtype'}" />
7322: <input type="hidden" name="srchterm" value="$srchterm" />
7323: <input type="hidden" name="srchin" value="$env{'form.srchin'}" />
7324: </form>
7325: END
7326: }
7327:
7328: sub activity_display_filter {
7329: my ($formname,$curr) = @_;
7330: my $nolink = 1;
7331: my $output = '<table><tr><td valign="top">'.
7332: '<span class="LC_nobreak"><b>'.&mt('Actions/page:').'</b></span><br />'.
7333: &Apache::lonmeta::selectbox('show',$curr->{'show'},undef,
7334: (&mt('all'),5,10,20,50,100,1000,10000)).
7335: '</td><td> </td>';
7336: my $startform =
7337: &Apache::lonhtmlcommon::date_setter($formname,'accesslog_start_date',
7338: $curr->{'accesslog_start_date'},undef,
7339: undef,undef,undef,undef,undef,undef,$nolink);
7340: my $endform =
7341: &Apache::lonhtmlcommon::date_setter($formname,'accesslog_end_date',
7342: $curr->{'accesslog_end_date'},undef,
7343: undef,undef,undef,undef,undef,undef,$nolink);
7344: my %lt = &Apache::lonlocal::texthash (
7345: activity => 'Activity',
7346: Role => 'Role selection',
7347: log => 'Log-in or Logout',
7348: );
7349: $output .= '<td valign="top"><b>'.&mt('Window during which actions occurred:').'</b><br />'.
7350: '<table><tr><td>'.&mt('After:').
7351: '</td><td>'.$startform.'</td></tr>'.
7352: '<tr><td>'.&mt('Before:').'</td>'.
7353: '<td>'.$endform.'</td></tr></table>'.
7354: '</td>'.
7355: '<td> </td>'.
7356: '<td valign="top"><b>'.&mt('Activities').'</b><br />'.
7357: '<select name="activity"><option value="any"';
7358: if ($curr->{'activity'} eq 'any') {
7359: $output .= ' selected="selected"';
7360: }
7361: $output .= '>'.&mt('Any').'</option>'."\n";
7362: foreach my $activity ('Role','log') {
7363: my $selstr = '';
7364: if ($activity eq $curr->{'activity'}) {
7365: $selstr = ' selected="selected"';
7366: }
7367: $output .= '<option value="'.$activity.'"'.$selstr.'>'.$lt{$activity}.'</option>';
7368: }
7369: $output .= '</select></td>'.
7370: '</tr></table>';
7371: # Update Display button
7372: $output .= '<p>'
7373: .'<input type="submit" value="'.&mt('Update Display').'" />'
1.431 raeburn 7374: .'</p><hr />';
1.416 raeburn 7375: return $output;
7376: }
7377:
1.415 raeburn 7378: sub userlogdisplay_js {
7379: my ($formname) = @_;
7380: return <<"ENDSCRIPT";
7381:
1.239 raeburn 7382: function chgPage(caller) {
7383: if (caller == 'previous') {
7384: document.$formname.page.value --;
7385: }
7386: if (caller == 'next') {
7387: document.$formname.page.value ++;
7388: }
1.327 raeburn 7389: document.$formname.submit();
1.239 raeburn 7390: return;
7391: }
7392: ENDSCRIPT
1.415 raeburn 7393: }
7394:
7395: sub userlogdisplay_navlinks {
7396: my ($curr,$more_records) = @_;
7397: return unless(ref($curr) eq 'HASH');
7398: # Navigation Buttons
7399: my $nav_links = '<p>';
7400: if (($curr->{'page'} > 1) || ($more_records)) {
7401: if (($curr->{'page'} > 1) && ($curr->{'show'} !~ /\D/)) {
7402: $nav_links .= '<input type="button"'
7403: .' onclick="javascript:chgPage('."'previous'".');"'
7404: .' value="'.&mt('Previous [_1] changes',$curr->{'show'})
7405: .'" /> ';
7406: }
7407: if ($more_records) {
7408: $nav_links .= '<input type="button"'
7409: .' onclick="javascript:chgPage('."'next'".');"'
7410: .' value="'.&mt('Next [_1] changes',$curr->{'show'})
7411: .'" />';
1.301 bisitz 7412: }
7413: }
1.415 raeburn 7414: $nav_links .= '</p>';
7415: return $nav_links;
1.239 raeburn 7416: }
7417:
7418: sub role_display_filter {
1.363 raeburn 7419: my ($context,$formname,$cdom,$cnum,$curr,$version,$crstype) = @_;
7420: my $lctype;
7421: if ($context eq 'course') {
7422: $lctype = lc($crstype);
7423: }
1.239 raeburn 7424: my $nolink = 1;
7425: my $output = '<table><tr><td valign="top">'.
1.301 bisitz 7426: '<span class="LC_nobreak"><b>'.&mt('Changes/page:').'</b></span><br />'.
1.239 raeburn 7427: &Apache::lonmeta::selectbox('show',$curr->{'show'},undef,
7428: (&mt('all'),5,10,20,50,100,1000,10000)).
7429: '</td><td> </td>';
7430: my $startform =
7431: &Apache::lonhtmlcommon::date_setter($formname,'rolelog_start_date',
7432: $curr->{'rolelog_start_date'},undef,
7433: undef,undef,undef,undef,undef,undef,$nolink);
7434: my $endform =
7435: &Apache::lonhtmlcommon::date_setter($formname,'rolelog_end_date',
7436: $curr->{'rolelog_end_date'},undef,
7437: undef,undef,undef,undef,undef,undef,$nolink);
1.363 raeburn 7438: my %lt = &rolechg_contexts($context,$crstype);
1.301 bisitz 7439: $output .= '<td valign="top"><b>'.&mt('Window during which changes occurred:').'</b><br />'.
7440: '<table><tr><td>'.&mt('After:').
7441: '</td><td>'.$startform.'</td></tr>'.
7442: '<tr><td>'.&mt('Before:').'</td>'.
7443: '<td>'.$endform.'</td></tr></table>'.
7444: '</td>'.
7445: '<td> </td>'.
1.239 raeburn 7446: '<td valign="top"><b>'.&mt('Role:').'</b><br />'.
7447: '<select name="role"><option value="any"';
7448: if ($curr->{'role'} eq 'any') {
7449: $output .= ' selected="selected"';
7450: }
7451: $output .= '>'.&mt('Any').'</option>'."\n";
1.363 raeburn 7452: my @roles = &Apache::lonuserutils::roles_by_context($context,1,$crstype);
1.239 raeburn 7453: foreach my $role (@roles) {
7454: my $plrole;
7455: if ($role eq 'cr') {
7456: $plrole = &mt('Custom Role');
7457: } else {
1.318 raeburn 7458: $plrole=&Apache::lonnet::plaintext($role,$crstype);
1.239 raeburn 7459: }
7460: my $selstr = '';
7461: if ($role eq $curr->{'role'}) {
7462: $selstr = ' selected="selected"';
7463: }
7464: $output .= ' <option value="'.$role.'"'.$selstr.'>'.$plrole.'</option>';
7465: }
1.301 bisitz 7466: $output .= '</select></td>'.
7467: '<td> </td>'.
7468: '<td valign="top"><b>'.
1.239 raeburn 7469: &mt('Context:').'</b><br /><select name="chgcontext">';
1.363 raeburn 7470: my @posscontexts;
7471: if ($context eq 'course') {
1.457 raeburn 7472: @posscontexts = ('any','automated','updatenow','createcourse','course','domain','selfenroll','requestcourses','chgtype');
1.363 raeburn 7473: } elsif ($context eq 'domain') {
7474: @posscontexts = ('any','domain','requestauthor','domconfig','server');
7475: } else {
7476: @posscontexts = ('any','author','domain');
1.457 raeburn 7477: }
1.363 raeburn 7478: foreach my $chgtype (@posscontexts) {
1.239 raeburn 7479: my $selstr = '';
7480: if ($curr->{'chgcontext'} eq $chgtype) {
1.301 bisitz 7481: $selstr = ' selected="selected"';
1.239 raeburn 7482: }
1.363 raeburn 7483: if ($context eq 'course') {
1.376 raeburn 7484: if (($chgtype eq 'automated') || ($chgtype eq 'updatenow')) {
1.363 raeburn 7485: next if (!&Apache::lonnet::auto_run($cnum,$cdom));
7486: }
1.239 raeburn 7487: }
7488: $output .= '<option value="'.$chgtype.'"'.$selstr.'>'.$lt{$chgtype}.'</option>'."\n";
1.248 raeburn 7489: }
1.303 bisitz 7490: $output .= '</select></td>'
7491: .'</tr></table>';
7492:
7493: # Update Display button
7494: $output .= '<p>'
7495: .'<input type="submit" value="'.&mt('Update Display').'" />'
7496: .'</p>';
7497:
7498: # Server version info
1.363 raeburn 7499: my $needsrev = '2.11.0';
7500: if ($context eq 'course') {
7501: $needsrev = '2.7.0';
7502: }
7503:
1.303 bisitz 7504: $output .= '<p class="LC_info">'
7505: .&mt('Only changes made from servers running LON-CAPA [_1] or later are displayed.'
1.363 raeburn 7506: ,$needsrev);
1.248 raeburn 7507: if ($version) {
1.303 bisitz 7508: $output .= ' '.&mt('This LON-CAPA server is version [_1]',$version);
7509: }
7510: $output .= '</p><hr />';
1.239 raeburn 7511: return $output;
7512: }
7513:
7514: sub rolechg_contexts {
1.363 raeburn 7515: my ($context,$crstype) = @_;
7516: my %lt;
7517: if ($context eq 'course') {
7518: %lt = &Apache::lonlocal::texthash (
1.239 raeburn 7519: any => 'Any',
1.376 raeburn 7520: automated => 'Automated Enrollment',
1.457 raeburn 7521: chgtype => 'Enrollment Type/Lock Change',
1.239 raeburn 7522: updatenow => 'Roster Update',
7523: createcourse => 'Course Creation',
7524: course => 'User Management in course',
7525: domain => 'User Management in domain',
1.313 raeburn 7526: selfenroll => 'Self-enrolled',
1.318 raeburn 7527: requestcourses => 'Course Request',
1.239 raeburn 7528: );
1.363 raeburn 7529: if ($crstype eq 'Community') {
7530: $lt{'createcourse'} = &mt('Community Creation');
7531: $lt{'course'} = &mt('User Management in community');
7532: $lt{'requestcourses'} = &mt('Community Request');
7533: }
7534: } elsif ($context eq 'domain') {
7535: %lt = &Apache::lonlocal::texthash (
7536: any => 'Any',
7537: domain => 'User Management in domain',
7538: requestauthor => 'Authoring Request',
7539: server => 'Command line script (DC role)',
7540: domconfig => 'Self-enrolled',
7541: );
7542: } else {
7543: %lt = &Apache::lonlocal::texthash (
7544: any => 'Any',
7545: domain => 'User Management in domain',
7546: author => 'User Management by author',
7547: );
7548: }
1.239 raeburn 7549: return %lt;
7550: }
7551:
1.428 raeburn 7552: sub print_helpdeskaccess_display {
7553: my ($r,$permission,$brcrum) = @_;
7554: my $formname = 'helpdeskaccess';
7555: my $helpitem = 'Course_Helpdesk_Access';
7556: push (@{$brcrum},
7557: {href => '/adm/createuser?action=helpdesk',
7558: text => 'Helpdesk Access',
7559: help => $helpitem});
7560: my $bread_crumbs_component = 'Helpdesk Staff Access';
7561: my $args = { bread_crumbs => $brcrum,
7562: bread_crumbs_component => $bread_crumbs_component};
7563:
7564: my $cdom = $env{'course.'.$env{'request.course.id'}.'.domain'};
7565: my $cnum = $env{'course.'.$env{'request.course.id'}.'.num'};
7566: my $confname = $cdom.'-domainconfig';
7567: my $crstype = &Apache::loncommon::course_type();
7568:
1.434 raeburn 7569: my @accesstypes = ('all','dh','da','none');
1.428 raeburn 7570: my ($numstatustypes,@jsarray);
7571: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($cdom);
7572: if (ref($types) eq 'ARRAY') {
1.430 raeburn 7573: if (@{$types} > 0) {
1.428 raeburn 7574: $numstatustypes = scalar(@{$types});
7575: push(@accesstypes,'status');
7576: @jsarray = ('bystatus');
7577: }
7578: }
7579: my %customroles = &get_domain_customroles($cdom,$confname);
1.432 raeburn 7580: my %domhelpdesk = &Apache::lonnet::get_active_domroles($cdom,['dh','da']);
1.428 raeburn 7581: if (keys(%domhelpdesk)) {
7582: push(@accesstypes,('inc','exc'));
7583: push(@jsarray,('notinc','notexc'));
7584: }
7585: push(@jsarray,'privs');
7586: my $hiddenstr = join("','",@jsarray);
7587: my $rolestr = join("','",sort(keys(%customroles)));
7588:
7589: my $jscript;
7590: my (%settings,%overridden);
7591: if (keys(%customroles)) {
7592: &get_adhocrole_settings($env{'request.course.id'},\@accesstypes,
7593: $types,\%customroles,\%settings,\%overridden);
7594: my %jsfull=();
7595: my %jslevels= (
7596: course => {},
7597: domain => {},
7598: system => {},
7599: );
7600: my %jslevelscurrent=(
7601: course => {},
7602: domain => {},
7603: system => {},
7604: );
7605: my (%privs,%jsprivs);
7606: &Apache::lonuserutils::custom_role_privs(\%privs,\%jsfull,\%jslevels,\%jslevelscurrent);
7607: foreach my $priv (keys(%jsfull)) {
7608: if ($jslevels{'course'}{$priv}) {
7609: $jsprivs{$priv} = 1;
7610: }
7611: }
7612: my (%elements,%stored);
7613: foreach my $role (keys(%customroles)) {
7614: $elements{$role.'_access'} = 'radio';
7615: $elements{$role.'_incrs'} = 'radio';
7616: if ($numstatustypes) {
7617: $elements{$role.'_status'} = 'checkbox';
7618: }
7619: if (keys(%domhelpdesk) > 0) {
7620: $elements{$role.'_staff_inc'} = 'checkbox';
7621: $elements{$role.'_staff_exc'} = 'checkbox';
7622: }
1.430 raeburn 7623: $elements{$role.'_override'} = 'checkbox';
1.428 raeburn 7624: if (ref($settings{$role}) eq 'HASH') {
7625: if ($settings{$role}{'access'} ne '') {
7626: my $curraccess = $settings{$role}{'access'};
7627: $stored{$role.'_access'} = $curraccess;
7628: $stored{$role.'_incrs'} = 1;
7629: if ($curraccess eq 'status') {
7630: if (ref($settings{$role}{'status'}) eq 'ARRAY') {
7631: $stored{$role.'_status'} = $settings{$role}{'status'};
7632: }
7633: } elsif (($curraccess eq 'exc') || ($curraccess eq 'inc')) {
7634: if (ref($settings{$role}{$curraccess}) eq 'ARRAY') {
7635: $stored{$role.'_staff_'.$curraccess} = $settings{$role}{$curraccess};
7636: }
7637: }
7638: } else {
7639: $stored{$role.'_incrs'} = 0;
7640: }
7641: $stored{$role.'_override'} = [];
7642: if ($env{'course.'.$env{'request.course.id'}.'.internal.adhocpriv.'.$role}) {
7643: if (ref($settings{$role}{'off'}) eq 'ARRAY') {
7644: foreach my $priv (@{$settings{$role}{'off'}}) {
7645: push(@{$stored{$role.'_override'}},$priv);
7646: }
7647: }
7648: if (ref($settings{$role}{'on'}) eq 'ARRAY') {
7649: foreach my $priv (@{$settings{$role}{'on'}}) {
7650: unless (grep(/^$priv$/,@{$stored{$role.'_override'}})) {
7651: push(@{$stored{$role.'_override'}},$priv);
7652: }
7653: }
7654: }
7655: }
7656: } else {
7657: $stored{$role.'_incrs'} = 0;
7658: }
7659: }
7660: $jscript = &Apache::lonhtmlcommon::set_form_elements(\%elements,\%stored);
7661: }
7662:
7663: my $js = <<"ENDJS";
7664: <script type="text/javascript">
7665: // <![CDATA[
7666: $jscript;
7667:
7668: function switchRoleTab(caller,role) {
7669: if (document.getElementById(role+'_maindiv')) {
7670: if (caller.id != 'LC_current_minitab') {
7671: if (document.getElementById('LC_current_minitab')) {
7672: document.getElementById('LC_current_minitab').id=null;
7673: }
7674: var roledivs = Array('$rolestr');
7675: if (roledivs.length > 0) {
7676: for (var i=0; i<roledivs.length; i++) {
7677: if (document.getElementById(roledivs[i]+'_maindiv')) {
7678: document.getElementById(roledivs[i]+'_maindiv').style.display='none';
7679: }
7680: }
7681: }
7682: caller.id = 'LC_current_minitab';
7683: document.getElementById(role+'_maindiv').style.display='block';
7684: }
7685: }
7686: return false;
1.430 raeburn 7687: }
1.428 raeburn 7688:
7689: function helpdeskAccess(role) {
7690: var curraccess = null;
7691: if (document.$formname.elements[role+'_access'].length) {
7692: for (var i=0; i<document.$formname.elements[role+'_access'].length; i++) {
7693: if (document.$formname.elements[role+'_access'][i].checked) {
7694: curraccess = document.$formname.elements[role+'_access'][i].value;
7695: }
7696: }
7697: }
7698: var shown = Array();
7699: var hidden = Array();
7700: if (curraccess == 'none') {
1.430 raeburn 7701: hidden = Array ('$hiddenstr');
1.428 raeburn 7702: } else {
7703: if (curraccess == 'status') {
1.430 raeburn 7704: shown = Array ('bystatus','privs');
7705: hidden = Array ('notinc','notexc');
1.428 raeburn 7706: } else {
7707: if (curraccess == 'exc') {
7708: shown = Array ('notexc','privs');
7709: hidden = Array ('notinc','bystatus');
7710: }
7711: if (curraccess == 'inc') {
7712: shown = Array ('notinc','privs');
7713: hidden = Array ('notexc','bystatus');
7714: }
7715: if (curraccess == 'all') {
7716: shown = Array ('privs');
7717: hidden = Array ('notinc','notexc','bystatus');
7718: }
7719: }
7720: }
7721: if (hidden.length > 0) {
7722: for (var i=0; i<hidden.length; i++) {
7723: if (document.getElementById(role+'_'+hidden[i])) {
1.430 raeburn 7724: document.getElementById(role+'_'+hidden[i]).style.display = 'none';
1.428 raeburn 7725: }
7726: }
7727: }
7728: if (shown.length > 0) {
7729: for (var i=0; i<shown.length; i++) {
7730: if (document.getElementById(role+'_'+shown[i])) {
7731: if (shown[i] == 'privs') {
7732: document.getElementById(role+'_'+shown[i]).style.display = 'block';
7733: } else {
7734: document.getElementById(role+'_'+shown[i]).style.display = 'inline';
7735: }
7736: }
7737: }
7738: }
7739: return;
7740: }
7741:
7742: function toggleAccess(role) {
7743: if ((document.getElementById(role+'_setincrs')) &&
7744: (document.getElementById(role+'_setindom'))) {
7745: for (var i=0; i<document.$formname.elements[role+'_incrs'].length; i++) {
7746: if (document.$formname.elements[role+'_incrs'][i].checked) {
7747: if (document.$formname.elements[role+'_incrs'][i].value == 1) {
7748: document.getElementById(role+'_setindom').style.display = 'none';
1.430 raeburn 7749: document.getElementById(role+'_setincrs').style.display = 'block';
1.428 raeburn 7750: } else {
7751: document.getElementById(role+'_setincrs').style.display = 'none';
7752: document.getElementById(role+'_setindom').style.display = 'block';
7753: }
7754: break;
7755: }
7756: }
7757: }
7758: return;
7759: }
7760:
7761: // ]]>
7762: </script>
7763: ENDJS
7764:
7765: $args->{add_entries} = {onload => "javascript:setFormElements(document.$formname)"};
7766:
7767: # print page header
7768: $r->print(&header($js,$args));
7769: # print form header
7770: $r->print('<form action="/adm/createuser" method="post" name="'.$formname.'">');
7771:
7772: if (keys(%customroles)) {
7773: my %lt = &Apache::lonlocal::texthash(
7774: 'aco' => 'As course owner you may override the defaults set in the domain for role usage and/or privileges.',
7775: 'rou' => 'Role usage',
7776: 'whi' => 'Which helpdesk personnel may use this role?',
7777: 'udd' => 'Use domain default',
1.433 raeburn 7778: 'all' => 'All with domain helpdesk or helpdesk assistant role',
1.434 raeburn 7779: 'dh' => 'All with domain helpdesk role',
7780: 'da' => 'All with domain helpdesk assistant role',
1.428 raeburn 7781: 'none' => 'None',
7782: 'status' => 'Determined based on institutional status',
1.430 raeburn 7783: 'inc' => 'Include all, but exclude specific personnel',
1.428 raeburn 7784: 'exc' => 'Exclude all, but include specific personnel',
7785: 'hel' => 'Helpdesk',
7786: 'rpr' => 'Role privileges',
7787: );
7788: $lt{'tfh'} = &mt("Custom [_1]ad hoc[_2] course roles available for use by the domain's helpdesk are as follows",'<i>','</i>');
7789: my %domconfig = &Apache::lonnet::get_dom('configuration',['helpsettings'],$cdom);
7790: my (%domcurrent,%ordered,%description,%domusage,$disabled);
7791: if (ref($domconfig{'helpsettings'}) eq 'HASH') {
7792: if (ref($domconfig{'helpsettings'}{'adhoc'}) eq 'HASH') {
7793: %domcurrent = %{$domconfig{'helpsettings'}{'adhoc'}};
7794: }
7795: }
7796: my $count = 0;
7797: foreach my $role (sort(keys(%customroles))) {
7798: my ($order,$desc,$access_in_dom);
7799: if (ref($domcurrent{$role}) eq 'HASH') {
7800: $order = $domcurrent{$role}{'order'};
7801: $desc = $domcurrent{$role}{'desc'};
7802: $access_in_dom = $domcurrent{$role}{'access'};
7803: }
7804: if ($order eq '') {
7805: $order = $count;
7806: }
7807: $ordered{$order} = $role;
7808: if ($desc ne '') {
7809: $description{$role} = $desc;
7810: } else {
7811: $description{$role}= $role;
7812: }
7813: $count++;
7814: }
7815: %domusage = &domain_adhoc_access(\%customroles,\%domcurrent,\@accesstypes,$usertypes,$othertitle);
7816: my @roles_by_num = ();
7817: foreach my $item (sort {$a <=> $b } (keys(%ordered))) {
7818: push(@roles_by_num,$ordered{$item});
1.430 raeburn 7819: }
1.429 raeburn 7820: $r->print('<p>'.$lt{'tfh'}.': <i>'.join('</i>, <i>',map { $description{$_}; } @roles_by_num).'</i>.');
1.428 raeburn 7821: if ($permission->{'owner'}) {
7822: $r->print('<br />'.$lt{'aco'}.'</p><p>');
7823: $r->print('<input type="hidden" name="state" value="process" />'.
7824: '<input type="submit" value="'.&mt('Save changes').'" />');
7825: } else {
7826: if ($env{'course.'.$env{'request.course.id'}.'.internal.courseowner'}) {
7827: my ($ownername,$ownerdom) = split(/:/,$env{'course.'.$env{'request.course.id'}.'.internal.courseowner'});
7828: $r->print('<br />'.&mt('The course owner -- [_1] -- can override the default access and/or privileges for these ad hoc roles.',
7829: &Apache::loncommon::aboutmewrapper(&Apache::loncommon::plainname($ownername,$ownerdom),$ownername,$ownerdom)));
7830: }
7831: $disabled = ' disabled="disabled"';
7832: }
7833: $r->print('</p>');
7834:
7835: $r->print('<div id="LC_minitab_header"><ul>');
7836: my $count = 0;
7837: my %visibility;
7838: foreach my $role (@roles_by_num) {
7839: my $id;
7840: if ($count == 0) {
7841: $id=' id="LC_current_minitab"';
1.430 raeburn 7842: $visibility{$role} = ' style="display:block"';
1.428 raeburn 7843: } else {
7844: $visibility{$role} = ' style="display:none"';
7845: }
7846: $count ++;
7847: $r->print('<li'.$id.'><a href="#" onclick="javascript:switchRoleTab(this.parentNode,'."'$role'".');">'.$description{$role}.'</a></li>');
7848: }
7849: $r->print('</ul></div>');
7850:
7851: foreach my $role (@roles_by_num) {
7852: my %usecheck = (
7853: all => ' checked="checked"',
7854: );
7855: my %displaydiv = (
7856: status => 'none',
7857: inc => 'none',
7858: exc => 'none',
7859: priv => 'block',
7860: );
7861: my (%selected,$overridden,$incrscheck,$indomcheck,$indomvis,$incrsvis);
1.430 raeburn 7862: if (ref($settings{$role}) eq 'HASH') {
1.428 raeburn 7863: if ($settings{$role}{'access'} ne '') {
7864: $indomvis = ' style="display:none"';
7865: $incrsvis = ' style="display:block"';
1.430 raeburn 7866: $incrscheck = ' checked="checked"';
1.428 raeburn 7867: if ($settings{$role}{'access'} ne 'all') {
7868: $usecheck{$settings{$role}{'access'}} = $usecheck{'all'};
7869: delete($usecheck{'all'});
7870: if ($settings{$role}{'access'} eq 'status') {
7871: my $access = 'status';
7872: $displaydiv{$access} = 'inline';
7873: if (ref($settings{$role}{$access}) eq 'ARRAY') {
7874: $selected{$access} = $settings{$role}{$access};
7875: }
7876: } elsif ($settings{$role}{'access'} =~ /^(inc|exc)$/) {
7877: my $access = $1;
7878: $displaydiv{$access} = 'inline';
7879: if (ref($settings{$role}{$access}) eq 'ARRAY') {
7880: $selected{$access} = $settings{$role}{$access};
7881: }
7882: } elsif ($settings{$role}{'access'} eq 'none') {
7883: $displaydiv{'priv'} = 'none';
7884: }
7885: }
7886: } else {
7887: $indomcheck = ' checked="checked"';
7888: $indomvis = ' style="display:block"';
7889: $incrsvis = ' style="display:none"';
7890: }
7891: } else {
7892: $indomcheck = ' checked="checked"';
1.430 raeburn 7893: $indomvis = ' style="display:block"';
1.428 raeburn 7894: $incrsvis = ' style="display:none"';
7895: }
7896: $r->print('<div class="LC_left_float" id="'.$role.'_maindiv"'.$visibility{$role}.'>'.
7897: '<fieldset><legend>'.$lt{'rou'}.'</legend>'.
7898: '<p>'.$lt{'whi'}.' <span class="LC_nobreak">'.
7899: '<label><input type="radio" name="'.$role.'_incrs" value="1"'.$incrscheck.' onclick="toggleAccess('."'$role'".');"'.$disabled.'>'.
7900: &mt('Set here in [_1]',lc($crstype)).'</label>'.
7901: '<span>'.(' 'x2).
7902: '<label><input type="radio" name="'.$role.'_incrs" value="0"'.$indomcheck.' onclick="toggleAccess('."'$role'".');"'.$disabled.'>'.
7903: $lt{'udd'}.'</label><span></p>'.
7904: '<div id="'.$role.'_setindom"'.$indomvis.'>'.
7905: '<span class="LC_cusr_emph">'.$domusage{$role}.'</span></div>'.
7906: '<div id="'.$role.'_setincrs"'.$incrsvis.'>');
7907: foreach my $access (@accesstypes) {
7908: $r->print('<p><label><input type="radio" name="'.$role.'_access" value="'.$access.'" '.$usecheck{$access}.
7909: ' onclick="helpdeskAccess('."'$role'".');"'.$disabled.' />'.$lt{$access}.'</label>');
7910: if ($access eq 'status') {
7911: $r->print('<div id="'.$role.'_bystatus" style="display:'.$displaydiv{$access}.'">'.
7912: &Apache::lonuserutils::adhoc_status_types($cdom,undef,$role,$selected{$access},
7913: $othertitle,$usertypes,$types,$disabled).
7914: '</div>');
7915: } elsif (($access eq 'inc') && (keys(%domhelpdesk) > 0)) {
7916: $r->print('<div id="'.$role.'_notinc" style="display:'.$displaydiv{$access}.'">'.
7917: &Apache::lonuserutils::adhoc_staff($access,undef,$role,$selected{$access},
7918: \%domhelpdesk,$disabled).
7919: '</div>');
7920: } elsif (($access eq 'exc') && (keys(%domhelpdesk) > 0)) {
7921: $r->print('<div id="'.$role.'_notexc" style="display:'.$displaydiv{$access}.'">'.
7922: &Apache::lonuserutils::adhoc_staff($access,undef,$role,$selected{$access},
7923: \%domhelpdesk,$disabled).
7924: '</div>');
7925: }
7926: $r->print('</p>');
7927: }
7928: $r->print('</div></fieldset>');
7929: my %full=();
7930: my %levels= (
7931: course => {},
7932: domain => {},
7933: system => {},
7934: );
7935: my %levelscurrent=(
7936: course => {},
7937: domain => {},
7938: system => {},
7939: );
7940: &Apache::lonuserutils::custom_role_privs($customroles{$role},\%full,\%levels,\%levelscurrent);
7941: $r->print('<fieldset id="'.$role.'_privs" style="display:'.$displaydiv{'priv'}.'">'.
7942: '<legend>'.$lt{'rpr'}.'</legend>'.
7943: &role_priv_table($role,$permission,$crstype,\%full,\%levels,\%levelscurrent,$overridden{$role}).
7944: '</fieldset></div><div style="padding:0;clear:both;margin:0;border:0"></div>');
7945: }
1.429 raeburn 7946: if ($permission->{'owner'}) {
7947: $r->print('<p><input type="submit" value="'.&mt('Save changes').'" /></p>');
7948: }
1.428 raeburn 7949: } else {
7950: $r->print(&mt('Helpdesk roles have not yet been created in this domain.'));
7951: }
7952: # Form Footer
7953: $r->print('<input type="hidden" name="action" value="helpdesk" />'
7954: .'</form>');
7955: return;
7956: }
7957:
7958: sub domain_adhoc_access {
7959: my ($roles,$domcurrent,$accesstypes,$usertypes,$othertitle) = @_;
7960: my %domusage;
7961: return unless ((ref($roles) eq 'HASH') && (ref($domcurrent) eq 'HASH') && (ref($accesstypes) eq 'ARRAY'));
7962: foreach my $role (keys(%{$roles})) {
7963: if (ref($domcurrent->{$role}) eq 'HASH') {
7964: my $access = $domcurrent->{$role}{'access'};
7965: if (($access eq '') || (!grep(/^\Q$access\E$/,@{$accesstypes}))) {
7966: $access = 'all';
1.432 raeburn 7967: $domusage{$role} = &mt('Any user in domain with active [_1] or [_2] role',&Apache::lonnet::plaintext('dh'),
7968: &Apache::lonnet::plaintext('da'));
1.428 raeburn 7969: } elsif ($access eq 'status') {
7970: if (ref($domcurrent->{$role}{$access}) eq 'ARRAY') {
7971: my @shown;
7972: foreach my $type (@{$domcurrent->{$role}{$access}}) {
7973: unless ($type eq 'default') {
7974: if ($usertypes->{$type}) {
7975: push(@shown,$usertypes->{$type});
7976: }
7977: }
7978: }
7979: if (grep(/^default$/,@{$domcurrent->{$role}{$access}})) {
7980: push(@shown,$othertitle);
7981: }
7982: if (@shown) {
7983: my $shownstatus = join(' '.&mt('or').' ',@shown);
1.432 raeburn 7984: $domusage{$role} = &mt('Any user in domain with active [_1] or [_2] role, and institutional status: [_3]',
7985: &Apache::lonnet::plaintext('dh'),&Apache::lonnet::plaintext('da'),$shownstatus);
1.428 raeburn 7986: } else {
7987: $domusage{$role} = &mt('No one in the domain');
7988: }
7989: }
7990: } elsif ($access eq 'inc') {
7991: my @dominc = ();
7992: if (ref($domcurrent->{$role}{'inc'}) eq 'ARRAY') {
7993: foreach my $user (@{$domcurrent->{$role}{'inc'}}) {
7994: my ($uname,$udom) = split(/:/,$user);
7995: push(@dominc,&Apache::loncommon::aboutmewrapper(&Apache::loncommon::plainname($uname,$udom),$uname,$udom));
7996: }
7997: my $showninc = join(', ',@dominc);
7998: if ($showninc ne '') {
1.432 raeburn 7999: $domusage{$role} = &mt('Include any user in domain with active [_1] or [_2] role, except: [_3]',
8000: &Apache::lonnet::plaintext('dh'),&Apache::lonnet::plaintext('da'),$showninc);
1.428 raeburn 8001: } else {
1.432 raeburn 8002: $domusage{$role} = &mt('Any user in domain with active [_1] or [_2] role',
8003: &Apache::lonnet::plaintext('dh'),&Apache::lonnet::plaintext('da'));
1.428 raeburn 8004: }
8005: }
8006: } elsif ($access eq 'exc') {
8007: my @domexc = ();
8008: if (ref($domcurrent->{$role}{'exc'}) eq 'ARRAY') {
8009: foreach my $user (@{$domcurrent->{$role}{'exc'}}) {
8010: my ($uname,$udom) = split(/:/,$user);
8011: push(@domexc,&Apache::loncommon::aboutmewrapper(&Apache::loncommon::plainname($uname,$udom),$uname,$udom));
8012: }
8013: }
8014: my $shownexc = join(', ',@domexc);
8015: if ($shownexc ne '') {
1.432 raeburn 8016: $domusage{$role} = &mt('Only the following in the domain with active [_1] or [_2] role: [_3]',
8017: &Apache::lonnet::plaintext('dh'),&Apache::lonnet::plaintext('da'),$shownexc);
1.428 raeburn 8018: } else {
8019: $domusage{$role} = &mt('No one in the domain');
8020: }
8021: } elsif ($access eq 'none') {
8022: $domusage{$role} = &mt('No one in the domain');
1.434 raeburn 8023: } elsif ($access eq 'dh') {
1.433 raeburn 8024: $domusage{$role} = &mt('Any user in domain with active [_1] role',&Apache::lonnet::plaintext('dh'));
1.434 raeburn 8025: } elsif ($access eq 'da') {
1.433 raeburn 8026: $domusage{$role} = &mt('Any user in domain with active [_1] role',&Apache::lonnet::plaintext('da'));
1.428 raeburn 8027: } elsif ($access eq 'all') {
1.432 raeburn 8028: $domusage{$role} = &mt('Any user in domain with active [_1] or [_2] role',
8029: &Apache::lonnet::plaintext('dh'),&Apache::lonnet::plaintext('da'));
1.428 raeburn 8030: }
8031: } else {
1.432 raeburn 8032: $domusage{$role} = &mt('Any user in domain with active [_1] or [_2] role',
8033: &Apache::lonnet::plaintext('dh'),&Apache::lonnet::plaintext('da'));
1.428 raeburn 8034: }
8035: }
8036: return %domusage;
8037: }
8038:
8039: sub get_domain_customroles {
8040: my ($cdom,$confname) = @_;
8041: my %existing=&Apache::lonnet::dump('roles',$cdom,$confname,'rolesdef_');
8042: my %customroles;
8043: foreach my $key (keys(%existing)) {
8044: if ($key=~/^rolesdef\_(\w+)$/) {
8045: my $rolename = $1;
8046: my %privs;
8047: ($privs{'system'},$privs{'domain'},$privs{'course'}) = split(/\_/,$existing{$key});
8048: $customroles{$rolename} = \%privs;
8049: }
8050: }
8051: return %customroles;
8052: }
8053:
8054: sub role_priv_table {
8055: my ($role,$permission,$crstype,$full,$levels,$levelscurrent,$overridden) = @_;
8056: return unless ((ref($full) eq 'HASH') && (ref($levels) eq 'HASH') &&
8057: (ref($levelscurrent) eq 'HASH'));
8058: my %lt=&Apache::lonlocal::texthash (
8059: 'crl' => 'Course Level Privilege',
8060: 'def' => 'Domain Defaults',
8061: 'ove' => 'Override in Course',
8062: 'ine' => 'In effect',
8063: 'dis' => 'Disabled',
8064: 'ena' => 'Enabled',
8065: );
8066: if ($crstype eq 'Community') {
8067: $lt{'ove'} = 'Override in Community',
8068: }
8069: my @status = ('Disabled','Enabled');
8070: my (%on,%off);
8071: if (ref($overridden) eq 'HASH') {
8072: if (ref($overridden->{'on'}) eq 'ARRAY') {
8073: map { $on{$_} = 1; } (@{$overridden->{'on'}});
8074: }
8075: if (ref($overridden->{'off'}) eq 'ARRAY') {
8076: map { $off{$_} = 1; } (@{$overridden->{'off'}});
8077: }
8078: }
8079: my $output=&Apache::loncommon::start_data_table().
8080: &Apache::loncommon::start_data_table_header_row().
8081: '<th>'.$lt{'crl'}.'</th><th>'.$lt{'def'}.'</th><th>'.$lt{'ove'}.
8082: '</th><th>'.$lt{'ine'}.'</th>'.
8083: &Apache::loncommon::end_data_table_header_row();
8084: foreach my $priv (sort(keys(%{$full}))) {
8085: next unless ($levels->{'course'}{$priv});
8086: my $privtext = &Apache::lonnet::plaintext($priv,$crstype);
8087: my ($default,$ineffect);
8088: if ($levelscurrent->{'course'}{$priv}) {
8089: $default = '<img src="/adm/lonIcons/navmap.correct.gif" alt="'.$lt{'ena'}.'" />';
8090: $ineffect = $default;
8091: }
8092: my ($customstatus,$checked);
8093: $output .= &Apache::loncommon::start_data_table_row().
8094: '<td>'.$privtext.'</td>'.
8095: '<td>'.$default.'</td><td>';
8096: if (($levelscurrent->{'course'}{$priv}) && ($off{$priv})) {
8097: if ($permission->{'owner'}) {
8098: $checked = ' checked="checked"';
8099: }
8100: $customstatus = '<img src="/adm/lonIcons/navmap.wrong.gif" alt="'.$lt{'dis'}.'" />';
1.430 raeburn 8101: $ineffect = $customstatus;
1.428 raeburn 8102: } elsif ((!$levelscurrent->{'course'}{$priv}) && ($on{$priv})) {
8103: if ($permission->{'owner'}) {
1.430 raeburn 8104: $checked = ' checked="checked"';
1.428 raeburn 8105: }
8106: $customstatus = '<img src="/adm/lonIcons/navmap.correct.gif" alt="'.$lt{'ena'}.'" />';
1.430 raeburn 8107: $ineffect = $customstatus;
1.428 raeburn 8108: }
8109: if ($permission->{'owner'}) {
8110: $output .= '<input type="checkbox" name="'.$role.'_override" value="'.$priv.'"'.$checked.' />';
8111: } else {
8112: $output .= $customstatus;
8113: }
8114: $output .= '</td><td>'.$ineffect.'</td>'.
8115: &Apache::loncommon::end_data_table_row();
8116: }
8117: $output .= &Apache::loncommon::end_data_table();
8118: return $output;
8119: }
8120:
8121: sub get_adhocrole_settings {
1.430 raeburn 8122: my ($cid,$accesstypes,$types,$customroles,$settings,$overridden) = @_;
1.428 raeburn 8123: return unless ((ref($accesstypes) eq 'ARRAY') && (ref($customroles) eq 'HASH') &&
8124: (ref($settings) eq 'HASH') && (ref($overridden) eq 'HASH'));
8125: foreach my $role (split(/,/,$env{'course.'.$cid.'.internal.adhocaccess'})) {
8126: my ($curraccess,$rest) = split(/=/,$env{'course.'.$cid.'.internal.adhoc.'.$role});
8127: if (($curraccess ne '') && (grep(/^\Q$curraccess\E$/,@{$accesstypes}))) {
8128: $settings->{$role}{'access'} = $curraccess;
8129: if (($curraccess eq 'status') && (ref($types) eq 'ARRAY')) {
8130: my @status = split(/,/,$rest);
8131: my @currstatus;
8132: foreach my $type (@status) {
8133: if ($type eq 'default') {
8134: push(@currstatus,$type);
8135: } elsif (grep(/^\Q$type\E$/,@{$types})) {
8136: push(@currstatus,$type);
8137: }
8138: }
8139: if (@currstatus) {
8140: $settings->{$role}{$curraccess} = \@currstatus;
8141: } elsif (($curraccess eq 'exc') || ($curraccess eq 'inc')) {
8142: my @personnel = split(/,/,$rest);
8143: $settings->{$role}{$curraccess} = \@personnel;
8144: }
8145: }
8146: }
8147: }
8148: foreach my $role (keys(%{$customroles})) {
8149: if ($env{'course.'.$cid.'.internal.adhocpriv.'.$role}) {
8150: my %currentprivs;
8151: if (ref($customroles->{$role}) eq 'HASH') {
8152: if (exists($customroles->{$role}{'course'})) {
8153: my %full=();
8154: my %levels= (
8155: course => {},
8156: domain => {},
8157: system => {},
8158: );
8159: my %levelscurrent=(
8160: course => {},
8161: domain => {},
8162: system => {},
8163: );
8164: &Apache::lonuserutils::custom_role_privs($customroles->{$role},\%full,\%levels,\%levelscurrent);
8165: %currentprivs = %{$levelscurrent{'course'}};
8166: }
8167: }
8168: foreach my $item (split(/,/,$env{'course.'.$cid.'.internal.adhocpriv.'.$role})) {
8169: next if ($item eq '');
8170: my ($rule,$rest) = split(/=/,$item);
8171: next unless (($rule eq 'off') || ($rule eq 'on'));
8172: foreach my $priv (split(/:/,$rest)) {
8173: if ($priv ne '') {
8174: if ($rule eq 'off') {
8175: push(@{$overridden->{$role}{'off'}},$priv);
8176: if ($currentprivs{$priv}) {
8177: push(@{$settings->{$role}{'off'}},$priv);
8178: }
8179: } else {
8180: push(@{$overridden->{$role}{'on'}},$priv);
8181: unless ($currentprivs{$priv}) {
8182: push(@{$settings->{$role}{'on'}},$priv);
8183: }
8184: }
8185: }
8186: }
8187: }
8188: }
8189: }
8190: return;
8191: }
8192:
8193: sub update_helpdeskaccess {
8194: my ($r,$permission,$brcrum) = @_;
8195: my $helpitem = 'Course_Helpdesk_Access';
8196: push (@{$brcrum},
8197: {href => '/adm/createuser?action=helpdesk',
8198: text => 'Helpdesk Access',
8199: help => $helpitem},
8200: {href => '/adm/createuser?action=helpdesk',
8201: text => 'Result',
8202: help => $helpitem}
8203: );
8204: my $bread_crumbs_component = 'Helpdesk Staff Access';
8205: my $args = { bread_crumbs => $brcrum,
8206: bread_crumbs_component => $bread_crumbs_component};
8207:
8208: # print page header
8209: $r->print(&header('',$args));
8210: unless ((ref($permission) eq 'HASH') && ($permission->{'owner'})) {
8211: $r->print('<p class="LC_error">'.&mt('You do not have permission to change helpdesk access.').'</p>');
8212: return;
8213: }
1.434 raeburn 8214: my @accesstypes = ('all','dh','da','none','status','inc','exc');
1.428 raeburn 8215: my $cdom = $env{'course.'.$env{'request.course.id'}.'.domain'};
8216: my $cnum = $env{'course.'.$env{'request.course.id'}.'.num'};
8217: my $confname = $cdom.'-domainconfig';
8218: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($cdom);
8219: my $crstype = &Apache::loncommon::course_type();
8220: my %customroles = &get_domain_customroles($cdom,$confname);
8221: my (%settings,%overridden);
8222: &get_adhocrole_settings($env{'request.course.id'},\@accesstypes,
8223: $types,\%customroles,\%settings,\%overridden);
1.432 raeburn 8224: my %domhelpdesk = &Apache::lonnet::get_active_domroles($cdom,['dh','da']);
1.428 raeburn 8225: my (%changed,%storehash,@todelete);
8226:
8227: if (keys(%customroles)) {
8228: my (%newsettings,@incrs);
8229: foreach my $role (keys(%customroles)) {
8230: $newsettings{$role} = {
8231: access => '',
8232: status => '',
8233: exc => '',
8234: inc => '',
8235: on => '',
8236: off => '',
8237: };
8238: my %current;
8239: if (ref($settings{$role}) eq 'HASH') {
8240: %current = %{$settings{$role}};
8241: }
8242: if (ref($overridden{$role}) eq 'HASH') {
8243: $current{'overridden'} = $overridden{$role};
8244: }
8245: if ($env{'form.'.$role.'_incrs'}) {
8246: my $access = $env{'form.'.$role.'_access'};
8247: if (grep(/^\Q$access\E$/,@accesstypes)) {
8248: push(@incrs,$role);
8249: unless ($current{'access'} eq $access) {
8250: $changed{$role}{'access'} = 1;
1.430 raeburn 8251: $storehash{'internal.adhoc.'.$role} = $access;
1.428 raeburn 8252: }
8253: if ($access eq 'status') {
8254: my @statuses = &Apache::loncommon::get_env_multiple('form.'.$role.'_status');
8255: my @stored;
8256: my @shownstatus;
8257: if (ref($types) eq 'ARRAY') {
8258: foreach my $type (sort(@statuses)) {
8259: if ($type eq 'default') {
8260: push(@stored,$type);
8261: } elsif (grep(/^\Q$type\E$/,@{$types})) {
8262: push(@stored,$type);
8263: push(@shownstatus,$usertypes->{$type});
8264: }
8265: }
8266: if (grep(/^default$/,@statuses)) {
8267: push(@shownstatus,$othertitle);
8268: }
8269: $storehash{'internal.adhoc.'.$role} .= '='.join(',',@stored);
8270: }
8271: $newsettings{$role}{'status'} = join(' '.&mt('or').' ',@shownstatus);
8272: if (ref($current{'status'}) eq 'ARRAY') {
8273: my @diffs = &Apache::loncommon::compare_arrays(\@stored,$current{'status'});
8274: if (@diffs) {
8275: $changed{$role}{'status'} = 1;
8276: }
8277: } elsif (@stored) {
8278: $changed{$role}{'status'} = 1;
8279: }
8280: } elsif (($access eq 'inc') || ($access eq 'exc')) {
8281: my @personnel = &Apache::loncommon::get_env_multiple('form.'.$role.'_staff_'.$access);
8282: my @newspecstaff;
8283: my @stored;
8284: my @currstaff;
8285: foreach my $person (sort(@personnel)) {
8286: if ($domhelpdesk{$person}) {
1.430 raeburn 8287: push(@stored,$person);
1.428 raeburn 8288: }
8289: }
8290: if (ref($current{$access}) eq 'ARRAY') {
8291: my @diffs = &Apache::loncommon::compare_arrays(\@stored,$current{$access});
8292: if (@diffs) {
8293: $changed{$role}{$access} = 1;
8294: }
8295: } elsif (@stored) {
8296: $changed{$role}{$access} = 1;
8297: }
8298: $storehash{'internal.adhoc.'.$role} .= '='.join(',',@stored);
8299: foreach my $person (@stored) {
8300: my ($uname,$udom) = split(/:/,$person);
8301: push(@newspecstaff,&Apache::loncommon::aboutmewrapper(&Apache::loncommon::plainname($uname,$udom,'lastname'),$uname,$udom));
8302: }
8303: $newsettings{$role}{$access} = join(', ',sort(@newspecstaff));
8304: }
8305: $newsettings{$role}{'access'} = $access;
8306: }
8307: } else {
8308: if (($current{'access'} ne '') && (grep(/^\Q$current{'access'}\E$/,@accesstypes))) {
8309: $changed{$role}{'access'} = 1;
8310: $newsettings{$role} = {};
8311: push(@todelete,'internal.adhoc.'.$role);
8312: }
8313: }
8314: if (($env{'form.'.$role.'_incrs'}) && ($env{'form.'.$role.'_access'} eq 'none')) {
8315: if (ref($current{'overridden'}) eq 'HASH') {
8316: push(@todelete,'internal.adhocpriv.'.$role);
8317: }
8318: } else {
8319: my %full=();
8320: my %levels= (
8321: course => {},
8322: domain => {},
8323: system => {},
8324: );
8325: my %levelscurrent=(
8326: course => {},
8327: domain => {},
8328: system => {},
8329: );
8330: &Apache::lonuserutils::custom_role_privs($customroles{$role},\%full,\%levels,\%levelscurrent);
8331: my (@updatedon,@updatedoff,@override);
8332: @override = &Apache::loncommon::get_env_multiple('form.'.$role.'_override');
1.430 raeburn 8333: if (@override) {
1.428 raeburn 8334: foreach my $priv (sort(keys(%full))) {
8335: next unless ($levels{'course'}{$priv});
8336: if (grep(/^\Q$priv\E$/,@override)) {
8337: if ($levelscurrent{'course'}{$priv}) {
8338: push(@updatedoff,$priv);
8339: } else {
8340: push(@updatedon,$priv);
8341: }
8342: }
8343: }
8344: }
8345: if (@updatedon) {
1.430 raeburn 8346: $newsettings{$role}{'on'} = join('</li><li>', map { &Apache::lonnet::plaintext($_,$crstype) } (@updatedon));
1.428 raeburn 8347: }
8348: if (@updatedoff) {
8349: $newsettings{$role}{'off'} = join('</li><li>', map { &Apache::lonnet::plaintext($_,$crstype) } (@updatedoff));
8350: }
8351: if (ref($current{'overridden'}) eq 'HASH') {
8352: if (ref($current{'overridden'}{'on'}) eq 'ARRAY') {
8353: if (@updatedon) {
8354: my @diffs = &Apache::loncommon::compare_arrays(\@updatedon,$current{'overridden'}{'on'});
8355: if (@diffs) {
8356: $changed{$role}{'on'} = 1;
8357: }
8358: } else {
8359: $changed{$role}{'on'} = 1;
8360: }
8361: } elsif (@updatedon) {
8362: $changed{$role}{'on'} = 1;
8363: }
8364: if (ref($current{'overridden'}{'off'}) eq 'ARRAY') {
8365: if (@updatedoff) {
8366: my @diffs = &Apache::loncommon::compare_arrays(\@updatedoff,$current{'overridden'}{'off'});
8367: if (@diffs) {
8368: $changed{$role}{'off'} = 1;
8369: }
8370: } else {
8371: $changed{$role}{'off'} = 1;
8372: }
8373: } elsif (@updatedoff) {
8374: $changed{$role}{'off'} = 1;
8375: }
8376: } else {
8377: if (@updatedon) {
8378: $changed{$role}{'on'} = 1;
8379: }
8380: if (@updatedoff) {
8381: $changed{$role}{'off'} = 1;
8382: }
8383: }
8384: if (ref($changed{$role}) eq 'HASH') {
8385: if (($changed{$role}{'on'} || $changed{$role}{'off'})) {
8386: my $newpriv;
8387: if (@updatedon) {
8388: $newpriv = 'on='.join(':',@updatedon);
8389: }
8390: if (@updatedoff) {
8391: $newpriv .= ($newpriv ? ',' : '' ).'off='.join(':',@updatedoff);
8392: }
8393: if ($newpriv eq '') {
8394: push(@todelete,'internal.adhocpriv.'.$role);
8395: } else {
8396: $storehash{'internal.adhocpriv.'.$role} = $newpriv;
8397: }
8398: }
8399: }
8400: }
8401: }
8402: if (@incrs) {
8403: $storehash{'internal.adhocaccess'} = join(',',@incrs);
8404: } elsif (@todelete) {
8405: push(@todelete,'internal.adhocaccess');
8406: }
8407: if (keys(%changed)) {
8408: my ($putres,$delres);
8409: if (keys(%storehash)) {
8410: $putres = &Apache::lonnet::put('environment',\%storehash,$cdom,$cnum);
8411: my %newenvhash;
8412: foreach my $key (keys(%storehash)) {
8413: $newenvhash{'course.'.$env{'request.course.id'}.'.'.$key} = $storehash{$key};
8414: }
8415: &Apache::lonnet::appenv(\%newenvhash);
8416: }
8417: if (@todelete) {
8418: $delres = &Apache::lonnet::del('environment',\@todelete,$cdom,$cnum);
8419: foreach my $key (@todelete) {
8420: &Apache::lonnet::delenv('course.'.$env{'request.course.id'}.'.'.$key);
8421: }
8422: }
8423: if (($putres eq 'ok') || ($delres eq 'ok')) {
8424: my %domconfig = &Apache::lonnet::get_dom('configuration',['helpsettings'],$cdom);
8425: my (%domcurrent,%ordered,%description,%domusage);
8426: if (ref($domconfig{'helpsettings'}) eq 'HASH') {
8427: if (ref($domconfig{'helpsettings'}{'adhoc'}) eq 'HASH') {
8428: %domcurrent = %{$domconfig{'helpsettings'}{'adhoc'}};
8429: }
8430: }
8431: my $count = 0;
8432: foreach my $role (sort(keys(%customroles))) {
8433: my ($order,$desc);
8434: if (ref($domcurrent{$role}) eq 'HASH') {
8435: $order = $domcurrent{$role}{'order'};
8436: $desc = $domcurrent{$role}{'desc'};
8437: }
8438: if ($order eq '') {
8439: $order = $count;
8440: }
8441: $ordered{$order} = $role;
8442: if ($desc ne '') {
8443: $description{$role} = $desc;
8444: } else {
8445: $description{$role}= $role;
8446: }
8447: $count++;
8448: }
8449: my @roles_by_num = ();
8450: foreach my $item (sort {$a <=> $b } (keys(%ordered))) {
8451: push(@roles_by_num,$ordered{$item});
8452: }
8453: %domusage = &domain_adhoc_access(\%changed,\%domcurrent,\@accesstypes,$usertypes,$othertitle);
1.430 raeburn 8454: $r->print(&mt('Helpdesk access settings have been changed as follows').'<br />');
1.428 raeburn 8455: $r->print('<ul>');
8456: foreach my $role (@roles_by_num) {
8457: next unless (ref($changed{$role}) eq 'HASH');
8458: $r->print('<li>'.&mt('Ad hoc role').': <b>'.$description{$role}.'</b>'.
8459: '<ul>');
1.430 raeburn 8460: if ($changed{$role}{'access'} || $changed{$role}{'status'} || $changed{$role}{'inc'} || $changed{$role}{'exc'}) {
1.428 raeburn 8461: $r->print('<li>');
8462: if ($env{'form.'.$role.'_incrs'}) {
8463: if ($newsettings{$role}{'access'} eq 'all') {
8464: $r->print(&mt('All helpdesk staff can access '.lc($crstype).' with this role.'));
1.434 raeburn 8465: } elsif ($newsettings{$role}{'access'} eq 'dh') {
1.433 raeburn 8466: $r->print(&mt('Helpdesk staff can use this role if they have an active [_1] role',
8467: &Apache::lonnet::plaintext('dh')));
1.434 raeburn 8468: } elsif ($newsettings{$role}{'access'} eq 'da') {
1.433 raeburn 8469: $r->print(&mt('Helpdesk staff can use this role if they have an active [_1] role',
8470: &Apache::lonnet::plaintext('da')));
1.428 raeburn 8471: } elsif ($newsettings{$role}{'access'} eq 'none') {
8472: $r->print(&mt('No helpdesk staff can access '.lc($crstype).' with this role.'));
8473: } elsif ($newsettings{$role}{'access'} eq 'status') {
8474: if ($newsettings{$role}{'status'}) {
8475: my ($access,$rest) = split(/=/,$storehash{'internal.adhoc.'.$role});
1.430 raeburn 8476: if (split(/,/,$rest) > 1) {
1.428 raeburn 8477: $r->print(&mt('Helpdesk staff can use this role if their institutional type is one of: [_1].',
8478: $newsettings{$role}{'status'}));
8479: } else {
8480: $r->print(&mt('Helpdesk staff can use this role if their institutional type is: [_1].',
8481: $newsettings{$role}{'status'}));
8482: }
8483: } else {
8484: $r->print(&mt('No helpdesk staff can access '.lc($crstype).' with this role.'));
8485: }
8486: } elsif ($newsettings{$role}{'access'} eq 'exc') {
8487: if ($newsettings{$role}{'exc'}) {
8488: $r->print(&mt('Helpdesk staff who can use this role are as follows:').' '.$newsettings{$role}{'exc'}.'.');
8489: } else {
8490: $r->print(&mt('No helpdesk staff can access '.lc($crstype).' with this role.'));
8491: }
8492: } elsif ($newsettings{$role}{'access'} eq 'inc') {
8493: if ($newsettings{$role}{'inc'}) {
8494: $r->print(&mt('All helpdesk staff may use this role except the following:').' '.$newsettings{$role}{'inc'}.'.');
8495: } else {
8496: $r->print(&mt('All helpdesk staff may use this role.'));
8497: }
8498: }
8499: } else {
8500: $r->print(&mt('Default access set in the domain now applies.').'<br />'.
8501: '<span class="LC_cusr_emph">'.$domusage{$role}.'</span>');
8502: }
8503: $r->print('</li>');
8504: }
8505: unless ($newsettings{$role}{'access'} eq 'none') {
8506: if ($changed{$role}{'off'}) {
8507: if ($newsettings{$role}{'off'}) {
8508: $r->print('<li>'.&mt('Privileges which are available by default for this ad hoc role, but are disabled for this specific '.lc($crstype).':').
8509: '<ul><li>'.$newsettings{$role}{'off'}.'</li></ul></li>');
8510: } else {
1.430 raeburn 8511: $r->print('<li>'.&mt('All privileges available by default for this ad hoc role are enabled.').'</li>');
1.428 raeburn 8512: }
8513: }
1.430 raeburn 8514: if ($changed{$role}{'on'}) {
1.428 raeburn 8515: if ($newsettings{$role}{'on'}) {
8516: $r->print('<li>'.&mt('Privileges which are not available by default for this ad hoc role, but are enabled for this specific '.lc($crstype).':').
8517: '<ul><li>'.$newsettings{$role}{'on'}.'</li></ul></li>');
8518: } else {
1.430 raeburn 8519: $r->print('<li>'.&mt('None of the privileges unavailable by default for this ad hoc role are enabled.').'</li>');
1.428 raeburn 8520: }
8521: }
8522: }
8523: $r->print('</ul></li>');
8524: }
8525: $r->print('</ul>');
8526: }
8527: } else {
1.430 raeburn 8528: $r->print(&mt('No changes made to helpdesk access settings.'));
1.428 raeburn 8529: }
8530: }
8531: return;
8532: }
8533:
1.27 matthew 8534: #-------------------------------------------------- functions for &phase_two
1.160 raeburn 8535: sub user_search_result {
1.221 raeburn 8536: my ($context,$srch) = @_;
1.160 raeburn 8537: my %allhomes;
8538: my %inst_matches;
8539: my %srch_results;
1.181 raeburn 8540: my ($response,$currstate,$forcenewuser,$dirsrchres);
1.183 raeburn 8541: $srch->{'srchterm'} =~ s/\s+/ /g;
1.176 raeburn 8542: if ($srch->{'srchby'} !~ /^(uname|lastname|lastfirst)$/) {
1.160 raeburn 8543: $response = &mt('Invalid search.');
8544: }
8545: if ($srch->{'srchin'} !~ /^(crs|dom|alc|instd)$/) {
8546: $response = &mt('Invalid search.');
8547: }
1.177 raeburn 8548: if ($srch->{'srchtype'} !~ /^(exact|contains|begins)$/) {
1.160 raeburn 8549: $response = &mt('Invalid search.');
8550: }
8551: if ($srch->{'srchterm'} eq '') {
8552: $response = &mt('You must enter a search term.');
8553: }
1.183 raeburn 8554: if ($srch->{'srchterm'} =~ /^\s+$/) {
8555: $response = &mt('Your search term must contain more than just spaces.');
8556: }
1.160 raeburn 8557: if (($srch->{'srchin'} eq 'dom') || ($srch->{'srchin'} eq 'instd')) {
8558: if (($srch->{'srchdomain'} eq '') ||
1.163 albertel 8559: ! (&Apache::lonnet::domain($srch->{'srchdomain'}))) {
1.160 raeburn 8560: $response = &mt('You must specify a valid domain when searching in a domain or institutional directory.')
8561: }
8562: }
8563: if (($srch->{'srchin'} eq 'dom') || ($srch->{'srchin'} eq 'crs') ||
8564: ($srch->{'srchin'} eq 'alc')) {
1.176 raeburn 8565: if ($srch->{'srchby'} eq 'uname') {
1.243 raeburn 8566: my $unamecheck = $srch->{'srchterm'};
8567: if ($srch->{'srchtype'} eq 'contains') {
8568: if ($unamecheck !~ /^\w/) {
8569: $unamecheck = 'a'.$unamecheck;
8570: }
8571: }
8572: if ($unamecheck !~ /^$match_username$/) {
1.176 raeburn 8573: $response = &mt('You must specify a valid username. Only the following are allowed: letters numbers - . @');
8574: }
1.160 raeburn 8575: }
8576: }
1.180 raeburn 8577: if ($response ne '') {
1.413 raeburn 8578: $response = '<span class="LC_warning">'.$response.'</span><br />';
1.180 raeburn 8579: }
1.160 raeburn 8580: if ($srch->{'srchin'} eq 'instd') {
1.412 raeburn 8581: my $instd_chk = &instdirectorysrch_check($srch);
1.160 raeburn 8582: if ($instd_chk ne 'ok') {
1.412 raeburn 8583: my $domd_chk = &domdirectorysrch_check($srch);
1.413 raeburn 8584: $response .= '<span class="LC_warning">'.$instd_chk.'</span><br />';
1.412 raeburn 8585: if ($domd_chk eq 'ok') {
1.435 raeburn 8586: $response .= &mt('You may want to search in the LON-CAPA domain instead of in the institutional directory.');
1.412 raeburn 8587: }
1.415 raeburn 8588: $response .= '<br />';
1.412 raeburn 8589: }
8590: } else {
1.417 raeburn 8591: unless (($context eq 'requestcrs') && ($srch->{'srchtype'} eq 'exact')) {
1.412 raeburn 8592: my $domd_chk = &domdirectorysrch_check($srch);
1.438 raeburn 8593: if (($domd_chk ne 'ok') && ($env{'form.action'} ne 'accesslogs')) {
1.412 raeburn 8594: my $instd_chk = &instdirectorysrch_check($srch);
1.413 raeburn 8595: $response .= '<span class="LC_warning">'.$domd_chk.'</span><br />';
1.412 raeburn 8596: if ($instd_chk eq 'ok') {
1.435 raeburn 8597: $response .= &mt('You may want to search in the institutional directory instead of in the LON-CAPA domain.');
1.412 raeburn 8598: }
1.415 raeburn 8599: $response .= '<br />';
1.412 raeburn 8600: }
1.160 raeburn 8601: }
8602: }
8603: if ($response ne '') {
1.180 raeburn 8604: return ($currstate,$response);
1.160 raeburn 8605: }
8606: if ($srch->{'srchby'} eq 'uname') {
8607: if (($srch->{'srchin'} eq 'dom') || ($srch->{'srchin'} eq 'crs')) {
8608: if ($env{'form.forcenew'}) {
8609: if ($srch->{'srchdomain'} ne $env{'request.role.domain'}) {
8610: my $uhome=&Apache::lonnet::homeserver($srch->{'srchterm'},$srch->{'srchdomain'});
8611: if ($uhome eq 'no_host') {
8612: my $domdesc = &Apache::lonnet::domain($env{'request.role.domain'},'description');
1.180 raeburn 8613: my $showdom = &display_domain_info($env{'request.role.domain'});
8614: $response = &mt('New users can only be created in the domain to which your current role belongs - [_1].',$showdom);
1.160 raeburn 8615: } else {
1.179 raeburn 8616: $currstate = 'modify';
1.160 raeburn 8617: }
8618: } else {
1.179 raeburn 8619: $currstate = 'modify';
1.160 raeburn 8620: }
8621: } else {
8622: if ($srch->{'srchin'} eq 'dom') {
1.162 raeburn 8623: if ($srch->{'srchtype'} eq 'exact') {
8624: my $uhome=&Apache::lonnet::homeserver($srch->{'srchterm'},$srch->{'srchdomain'});
8625: if ($uhome eq 'no_host') {
1.179 raeburn 8626: ($currstate,$response,$forcenewuser) =
1.221 raeburn 8627: &build_search_response($context,$srch,%srch_results);
1.162 raeburn 8628: } else {
1.179 raeburn 8629: $currstate = 'modify';
1.416 raeburn 8630: if ($env{'form.action'} eq 'accesslogs') {
8631: $currstate = 'activity';
8632: }
1.310 raeburn 8633: my $uname = $srch->{'srchterm'};
8634: my $udom = $srch->{'srchdomain'};
8635: $srch_results{$uname.':'.$udom} =
8636: { &Apache::lonnet::get('environment',
8637: ['firstname',
8638: 'lastname',
8639: 'permanentemail'],
8640: $udom,$uname)
8641: };
1.162 raeburn 8642: }
8643: } else {
8644: %srch_results = &Apache::lonnet::usersearch($srch);
1.179 raeburn 8645: ($currstate,$response,$forcenewuser) =
1.221 raeburn 8646: &build_search_response($context,$srch,%srch_results);
1.160 raeburn 8647: }
8648: } else {
1.167 albertel 8649: my $courseusers = &get_courseusers();
1.162 raeburn 8650: if ($srch->{'srchtype'} eq 'exact') {
1.167 albertel 8651: if (exists($courseusers->{$srch->{'srchterm'}.':'.$srch->{'srchdomain'}})) {
1.179 raeburn 8652: $currstate = 'modify';
1.162 raeburn 8653: } else {
1.179 raeburn 8654: ($currstate,$response,$forcenewuser) =
1.221 raeburn 8655: &build_search_response($context,$srch,%srch_results);
1.162 raeburn 8656: }
1.160 raeburn 8657: } else {
1.167 albertel 8658: foreach my $user (keys(%$courseusers)) {
1.162 raeburn 8659: my ($cuname,$cudomain) = split(/:/,$user);
8660: if ($cudomain eq $srch->{'srchdomain'}) {
1.177 raeburn 8661: my $matched = 0;
8662: if ($srch->{'srchtype'} eq 'begins') {
8663: if ($cuname =~ /^\Q$srch->{'srchterm'}\E/i) {
8664: $matched = 1;
8665: }
8666: } else {
8667: if ($cuname =~ /\Q$srch->{'srchterm'}\E/i) {
8668: $matched = 1;
8669: }
8670: }
8671: if ($matched) {
1.167 albertel 8672: $srch_results{$user} =
8673: {&Apache::lonnet::get('environment',
8674: ['firstname',
8675: 'lastname',
1.194 albertel 8676: 'permanentemail'],
8677: $cudomain,$cuname)};
1.162 raeburn 8678: }
8679: }
8680: }
1.179 raeburn 8681: ($currstate,$response,$forcenewuser) =
1.221 raeburn 8682: &build_search_response($context,$srch,%srch_results);
1.160 raeburn 8683: }
8684: }
8685: }
8686: } elsif ($srch->{'srchin'} eq 'alc') {
1.179 raeburn 8687: $currstate = 'query';
1.160 raeburn 8688: } elsif ($srch->{'srchin'} eq 'instd') {
1.181 raeburn 8689: ($dirsrchres,%srch_results) = &Apache::lonnet::inst_directory_query($srch);
8690: if ($dirsrchres eq 'ok') {
8691: ($currstate,$response,$forcenewuser) =
1.221 raeburn 8692: &build_search_response($context,$srch,%srch_results);
1.181 raeburn 8693: } else {
8694: my $showdom = &display_domain_info($srch->{'srchdomain'});
8695: $response = '<span class="LC_warning">'.
8696: &mt('Institutional directory search is not available in domain: [_1]',$showdom).
8697: '</span><br />'.
1.435 raeburn 8698: &mt('You may want to search in the LON-CAPA domain instead of in the institutional directory.').
1.415 raeburn 8699: '<br />';
1.181 raeburn 8700: }
1.160 raeburn 8701: }
8702: } else {
8703: if ($srch->{'srchin'} eq 'dom') {
8704: %srch_results = &Apache::lonnet::usersearch($srch);
1.179 raeburn 8705: ($currstate,$response,$forcenewuser) =
1.221 raeburn 8706: &build_search_response($context,$srch,%srch_results);
1.160 raeburn 8707: } elsif ($srch->{'srchin'} eq 'crs') {
1.167 albertel 8708: my $courseusers = &get_courseusers();
8709: foreach my $user (keys(%$courseusers)) {
1.160 raeburn 8710: my ($uname,$udom) = split(/:/,$user);
8711: my %names = &Apache::loncommon::getnames($uname,$udom);
8712: my %emails = &Apache::loncommon::getemails($uname,$udom);
8713: if ($srch->{'srchby'} eq 'lastname') {
8714: if ((($srch->{'srchtype'} eq 'exact') &&
8715: ($names{'lastname'} eq $srch->{'srchterm'})) ||
1.177 raeburn 8716: (($srch->{'srchtype'} eq 'begins') &&
8717: ($names{'lastname'} =~ /^\Q$srch->{'srchterm'}\E/i)) ||
1.160 raeburn 8718: (($srch->{'srchtype'} eq 'contains') &&
8719: ($names{'lastname'} =~ /\Q$srch->{'srchterm'}\E/i))) {
8720: $srch_results{$user} = {firstname => $names{'firstname'},
8721: lastname => $names{'lastname'},
8722: permanentemail => $emails{'permanentemail'},
8723: };
8724: }
8725: } elsif ($srch->{'srchby'} eq 'lastfirst') {
8726: my ($srchlast,$srchfirst) = split(/,/,$srch->{'srchterm'});
1.177 raeburn 8727: $srchlast =~ s/\s+$//;
8728: $srchfirst =~ s/^\s+//;
1.160 raeburn 8729: if ($srch->{'srchtype'} eq 'exact') {
8730: if (($names{'lastname'} eq $srchlast) &&
8731: ($names{'firstname'} eq $srchfirst)) {
8732: $srch_results{$user} = {firstname => $names{'firstname'},
8733: lastname => $names{'lastname'},
8734: permanentemail => $emails{'permanentemail'},
8735:
8736: };
8737: }
1.177 raeburn 8738: } elsif ($srch->{'srchtype'} eq 'begins') {
8739: if (($names{'lastname'} =~ /^\Q$srchlast\E/i) &&
8740: ($names{'firstname'} =~ /^\Q$srchfirst\E/i)) {
8741: $srch_results{$user} = {firstname => $names{'firstname'},
8742: lastname => $names{'lastname'},
8743: permanentemail => $emails{'permanentemail'},
8744: };
8745: }
8746: } else {
1.160 raeburn 8747: if (($names{'lastname'} =~ /\Q$srchlast\E/i) &&
8748: ($names{'firstname'} =~ /\Q$srchfirst\E/i)) {
8749: $srch_results{$user} = {firstname => $names{'firstname'},
8750: lastname => $names{'lastname'},
8751: permanentemail => $emails{'permanentemail'},
8752: };
8753: }
8754: }
8755: }
8756: }
1.179 raeburn 8757: ($currstate,$response,$forcenewuser) =
1.221 raeburn 8758: &build_search_response($context,$srch,%srch_results);
1.160 raeburn 8759: } elsif ($srch->{'srchin'} eq 'alc') {
1.179 raeburn 8760: $currstate = 'query';
1.160 raeburn 8761: } elsif ($srch->{'srchin'} eq 'instd') {
1.181 raeburn 8762: ($dirsrchres,%srch_results) = &Apache::lonnet::inst_directory_query($srch);
8763: if ($dirsrchres eq 'ok') {
8764: ($currstate,$response,$forcenewuser) =
1.221 raeburn 8765: &build_search_response($context,$srch,%srch_results);
1.181 raeburn 8766: } else {
1.412 raeburn 8767: my $showdom = &display_domain_info($srch->{'srchdomain'});
8768: $response = '<span class="LC_warning">'.
1.181 raeburn 8769: &mt('Institutional directory search is not available in domain: [_1]',$showdom).
8770: '</span><br />'.
1.435 raeburn 8771: &mt('You may want to search in the LON-CAPA domain instead of in the institutional directory.').
1.415 raeburn 8772: '<br />';
1.181 raeburn 8773: }
1.160 raeburn 8774: }
8775: }
1.179 raeburn 8776: return ($currstate,$response,$forcenewuser,\%srch_results);
1.160 raeburn 8777: }
8778:
1.412 raeburn 8779: sub domdirectorysrch_check {
8780: my ($srch) = @_;
8781: my $response;
8782: my %dom_inst_srch = &Apache::lonnet::get_dom('configuration',
8783: ['directorysrch'],$srch->{'srchdomain'});
8784: my $showdom = &display_domain_info($srch->{'srchdomain'});
8785: if (ref($dom_inst_srch{'directorysrch'}) eq 'HASH') {
8786: if ($dom_inst_srch{'directorysrch'}{'lcavailable'} eq '0') {
8787: return &mt('LON-CAPA directory search is not available in domain: [_1]',$showdom);
8788: }
8789: if ($dom_inst_srch{'directorysrch'}{'lclocalonly'}) {
8790: if ($env{'request.role.domain'} ne $srch->{'srchdomain'}) {
8791: return &mt('LON-CAPA directory search in domain: [_1] is only allowed for users with a current role in the domain.',$showdom);
8792: }
8793: }
8794: }
8795: return 'ok';
8796: }
8797:
8798: sub instdirectorysrch_check {
1.160 raeburn 8799: my ($srch) = @_;
8800: my $can_search = 0;
8801: my $response;
8802: my %dom_inst_srch = &Apache::lonnet::get_dom('configuration',
8803: ['directorysrch'],$srch->{'srchdomain'});
1.180 raeburn 8804: my $showdom = &display_domain_info($srch->{'srchdomain'});
1.160 raeburn 8805: if (ref($dom_inst_srch{'directorysrch'}) eq 'HASH') {
8806: if (!$dom_inst_srch{'directorysrch'}{'available'}) {
1.180 raeburn 8807: return &mt('Institutional directory search is not available in domain: [_1]',$showdom);
1.160 raeburn 8808: }
8809: if ($dom_inst_srch{'directorysrch'}{'localonly'}) {
8810: if ($env{'request.role.domain'} ne $srch->{'srchdomain'}) {
1.180 raeburn 8811: return &mt('Institutional directory search in domain: [_1] is only allowed for users with a current role in the domain.',$showdom);
1.160 raeburn 8812: }
8813: my @usertypes = split(/:/,$env{'environment.inststatus'});
8814: if (!@usertypes) {
8815: push(@usertypes,'default');
8816: }
8817: if (ref($dom_inst_srch{'directorysrch'}{'cansearch'}) eq 'ARRAY') {
8818: foreach my $type (@usertypes) {
8819: if (grep(/^\Q$type\E$/,@{$dom_inst_srch{'directorysrch'}{'cansearch'}})) {
8820: $can_search = 1;
8821: last;
8822: }
8823: }
8824: }
8825: if (!$can_search) {
8826: my ($insttypes,$order) = &Apache::lonnet::retrieve_inst_usertypes($srch->{'srchdomain'});
8827: my @longtypes;
8828: foreach my $item (@usertypes) {
1.229 raeburn 8829: if (defined($insttypes->{$item})) {
8830: push (@longtypes,$insttypes->{$item});
8831: } elsif ($item eq 'default') {
8832: push (@longtypes,&mt('other'));
8833: }
1.160 raeburn 8834: }
8835: my $insttype_str = join(', ',@longtypes);
1.180 raeburn 8836: return &mt('Institutional directory search in domain: [_1] is not available to your user type: ',$showdom).$insttype_str;
1.229 raeburn 8837: }
1.160 raeburn 8838: } else {
8839: $can_search = 1;
8840: }
8841: } else {
1.180 raeburn 8842: return &mt('Institutional directory search has not been configured for domain: [_1]',$showdom);
1.160 raeburn 8843: }
8844: my %longtext = &Apache::lonlocal::texthash (
1.167 albertel 8845: uname => 'username',
1.160 raeburn 8846: lastfirst => 'last name, first name',
1.167 albertel 8847: lastname => 'last name',
1.172 raeburn 8848: contains => 'contains',
1.178 raeburn 8849: exact => 'as exact match to',
8850: begins => 'begins with',
1.160 raeburn 8851: );
8852: if ($can_search) {
8853: if (ref($dom_inst_srch{'directorysrch'}{'searchby'}) eq 'ARRAY') {
8854: if (!grep(/^\Q$srch->{'srchby'}\E$/,@{$dom_inst_srch{'directorysrch'}{'searchby'}})) {
1.180 raeburn 8855: return &mt('Institutional directory search in domain: [_1] is not available for searching by "[_2]"',$showdom,$longtext{$srch->{'srchby'}});
1.160 raeburn 8856: }
8857: } else {
1.180 raeburn 8858: return &mt('Institutional directory search in domain: [_1] is not available.', $showdom);
1.160 raeburn 8859: }
8860: }
8861: if ($can_search) {
1.178 raeburn 8862: if (ref($dom_inst_srch{'directorysrch'}{'searchtypes'}) eq 'ARRAY') {
8863: if (grep(/^\Q$srch->{'srchtype'}\E/,@{$dom_inst_srch{'directorysrch'}{'searchtypes'}})) {
8864: return 'ok';
8865: } else {
1.180 raeburn 8866: return &mt('Institutional directory search in domain [_1] is not available for the requested search type: "[_2]"',$showdom,$longtext{$srch->{'srchtype'}});
1.178 raeburn 8867: }
8868: } else {
8869: if ((($dom_inst_srch{'directorysrch'}{'searchtypes'} eq 'specify') &&
8870: ($srch->{'srchtype'} eq 'exact' || $srch->{'srchtype'} eq 'contains')) ||
8871: ($dom_inst_srch{'directorysrch'}{'searchtypes'} eq $srch->{'srchtype'})) {
8872: return 'ok';
8873: } else {
1.180 raeburn 8874: return &mt('Institutional directory search in domain [_1] is not available for the requested search type: "[_2]"',$showdom,$longtext{$srch->{'srchtype'}});
1.178 raeburn 8875: }
1.160 raeburn 8876: }
8877: }
8878: }
8879:
8880: sub get_courseusers {
8881: my %advhash;
1.167 albertel 8882: my $classlist = &Apache::loncoursedata::get_classlist();
1.160 raeburn 8883: my %coursepersonnel=&Apache::lonnet::get_course_adv_roles();
8884: foreach my $role (sort(keys(%coursepersonnel))) {
8885: foreach my $user (split(/\,/,$coursepersonnel{$role})) {
1.167 albertel 8886: if (!exists($classlist->{$user})) {
8887: $classlist->{$user} = [];
8888: }
1.160 raeburn 8889: }
8890: }
1.167 albertel 8891: return $classlist;
1.160 raeburn 8892: }
8893:
8894: sub build_search_response {
1.221 raeburn 8895: my ($context,$srch,%srch_results) = @_;
1.179 raeburn 8896: my ($currstate,$response,$forcenewuser);
1.160 raeburn 8897: my %names = (
1.330 bisitz 8898: 'uname' => 'username',
8899: 'lastname' => 'last name',
1.160 raeburn 8900: 'lastfirst' => 'last name, first name',
1.330 bisitz 8901: 'crs' => 'this course',
8902: 'dom' => 'LON-CAPA domain',
8903: 'instd' => 'the institutional directory for domain',
1.160 raeburn 8904: );
8905:
8906: my %single = (
1.180 raeburn 8907: begins => 'A match',
1.160 raeburn 8908: contains => 'A match',
1.180 raeburn 8909: exact => 'An exact match',
1.160 raeburn 8910: );
8911: my %nomatch = (
1.180 raeburn 8912: begins => 'No match',
1.160 raeburn 8913: contains => 'No match',
1.180 raeburn 8914: exact => 'No exact match',
1.160 raeburn 8915: );
8916: if (keys(%srch_results) > 1) {
1.179 raeburn 8917: $currstate = 'select';
1.160 raeburn 8918: } else {
8919: if (keys(%srch_results) == 1) {
1.416 raeburn 8920: if ($env{'form.action'} eq 'accesslogs') {
8921: $currstate = 'activity';
8922: } else {
8923: $currstate = 'modify';
8924: }
1.180 raeburn 8925: $response = &mt("$single{$srch->{'srchtype'}} was found for the $names{$srch->{'srchby'}} ([_1]) in $names{$srch->{'srchin'}}.",$srch->{'srchterm'});
8926: if ($srch->{'srchin'} eq 'dom' || $srch->{'srchin'} eq 'instd') {
1.330 bisitz 8927: $response .= ': '.&display_domain_info($srch->{'srchdomain'});
1.180 raeburn 8928: }
1.330 bisitz 8929: } else { # Search has nothing found. Prepare message to user.
8930: $response = '<span class="LC_warning">';
1.180 raeburn 8931: if ($srch->{'srchin'} eq 'dom' || $srch->{'srchin'} eq 'instd') {
1.330 bisitz 8932: $response .= &mt("$nomatch{$srch->{'srchtype'}} found for the $names{$srch->{'srchby'}} [_1] in $names{$srch->{'srchin'}}: [_2]",
8933: '<b>'.$srch->{'srchterm'}.'</b>',
8934: &display_domain_info($srch->{'srchdomain'}));
8935: } else {
8936: $response .= &mt("$nomatch{$srch->{'srchtype'}} found for the $names{$srch->{'srchby'}} [_1] in $names{$srch->{'srchin'}}.",
8937: '<b>'.$srch->{'srchterm'}.'</b>');
1.180 raeburn 8938: }
8939: $response .= '</span>';
1.330 bisitz 8940:
1.160 raeburn 8941: if ($srch->{'srchin'} ne 'alc') {
8942: $forcenewuser = 1;
8943: my $cansrchinst = 0;
1.438 raeburn 8944: if (($srch->{'srchdomain'}) && ($env{'form.action'} ne 'accesslogs')) {
1.160 raeburn 8945: my %domconfig = &Apache::lonnet::get_dom('configuration',['directorysrch'],$srch->{'srchdomain'});
8946: if (ref($domconfig{'directorysrch'}) eq 'HASH') {
8947: if ($domconfig{'directorysrch'}{'available'}) {
8948: $cansrchinst = 1;
8949: }
8950: }
8951: }
1.180 raeburn 8952: if ((($srch->{'srchby'} eq 'lastfirst') ||
8953: ($srch->{'srchby'} eq 'lastname')) &&
8954: ($srch->{'srchin'} eq 'dom')) {
8955: if ($cansrchinst) {
8956: $response .= '<br />'.&mt('You may want to broaden your search to a search of the institutional directory for the domain.');
1.160 raeburn 8957: }
8958: }
1.180 raeburn 8959: if ($srch->{'srchin'} eq 'crs') {
8960: $response .= '<br />'.&mt('You may want to broaden your search to the selected LON-CAPA domain.');
8961: }
8962: }
1.305 raeburn 8963: my $createdom = $env{'request.role.domain'};
8964: if ($context eq 'requestcrs') {
8965: if ($env{'form.coursedom'} ne '') {
8966: $createdom = $env{'form.coursedom'};
8967: }
8968: }
1.416 raeburn 8969: unless (($env{'form.action'} eq 'accesslogs') || (($srch->{'srchby'} eq 'uname') && ($srch->{'srchin'} eq 'dom') &&
8970: ($srch->{'srchtype'} eq 'exact') && ($srch->{'srchdomain'} eq $createdom))) {
1.221 raeburn 8971: my $cancreate =
1.305 raeburn 8972: &Apache::lonuserutils::can_create_user($createdom,$context);
8973: my $targetdom = '<span class="LC_cusr_emph">'.$createdom.'</span>';
1.221 raeburn 8974: if ($cancreate) {
1.305 raeburn 8975: my $showdom = &display_domain_info($createdom);
1.266 bisitz 8976: $response .= '<br /><br />'
8977: .'<b>'.&mt('To add a new user:').'</b>'
1.305 raeburn 8978: .'<br />';
8979: if ($context eq 'requestcrs') {
8980: $response .= &mt("(You can only define new users in the new course's domain - [_1])",$targetdom);
8981: } else {
8982: $response .= &mt("(You can only create new users in your current role's domain - [_1])",$targetdom);
8983: }
8984: $response .='<ul><li>'
1.266 bisitz 8985: .&mt("Set 'Domain/institution to search' to: [_1]",'<span class="LC_cusr_emph">'.$showdom.'</span>')
8986: .'</li><li>'
8987: .&mt("Set 'Search criteria' to: [_1]username is ..... in selected LON-CAPA domain[_2]",'<span class="LC_cusr_emph">','</span>')
8988: .'</li><li>'
8989: .&mt('Provide the proposed username')
8990: .'</li><li>'
8991: .&mt("Click 'Search'")
8992: .'</li></ul><br />';
1.221 raeburn 8993: } else {
1.422 raeburn 8994: unless (($context eq 'domain') && ($env{'form.action'} eq 'singleuser')) {
8995: my $helplink = ' href="javascript:helpMenu('."'display'".')"';
8996: $response .= '<br /><br />';
8997: if ($context eq 'requestcrs') {
8998: $response .= &mt("You are not authorized to define new users in the new course's domain - [_1].",$targetdom);
8999: } else {
9000: $response .= &mt("You are not authorized to create new users in your current role's domain - [_1].",$targetdom);
9001: }
9002: $response .= '<br />'
9003: .&mt('Please contact the [_1]helpdesk[_2] if you need to create a new user.'
9004: ,' <a'.$helplink.'>'
9005: ,'</a>')
9006: .'<br />';
1.305 raeburn 9007: }
1.221 raeburn 9008: }
1.160 raeburn 9009: }
9010: }
9011: }
1.179 raeburn 9012: return ($currstate,$response,$forcenewuser);
1.160 raeburn 9013: }
9014:
1.180 raeburn 9015: sub display_domain_info {
9016: my ($dom) = @_;
9017: my $output = $dom;
9018: if ($dom ne '') {
9019: my $domdesc = &Apache::lonnet::domain($dom,'description');
9020: if ($domdesc ne '') {
9021: $output .= ' <span class="LC_cusr_emph">('.$domdesc.')</span>';
9022: }
9023: }
9024: return $output;
9025: }
9026:
1.160 raeburn 9027: sub crumb_utilities {
9028: my %elements = (
9029: crtuser => {
9030: srchterm => 'text',
1.172 raeburn 9031: srchin => 'selectbox',
1.160 raeburn 9032: srchby => 'selectbox',
9033: srchtype => 'selectbox',
9034: srchdomain => 'selectbox',
9035: },
1.207 raeburn 9036: crtusername => {
9037: srchterm => 'text',
9038: srchdomain => 'selectbox',
9039: },
1.160 raeburn 9040: docustom => {
9041: rolename => 'selectbox',
9042: newrolename => 'textbox',
9043: },
1.179 raeburn 9044: studentform => {
9045: srchterm => 'text',
9046: srchin => 'selectbox',
9047: srchby => 'selectbox',
9048: srchtype => 'selectbox',
9049: srchdomain => 'selectbox',
9050: },
1.160 raeburn 9051: );
9052:
9053: my $jsback .= qq|
9054: function backPage(formname,prevphase,prevstate) {
1.211 raeburn 9055: if (typeof prevphase == 'undefined') {
9056: formname.phase.value = '';
9057: }
9058: else {
9059: formname.phase.value = prevphase;
9060: }
9061: if (typeof prevstate == 'undefined') {
9062: formname.currstate.value = '';
9063: }
9064: else {
9065: formname.currstate.value = prevstate;
9066: }
1.160 raeburn 9067: formname.submit();
9068: }
9069: |;
9070: return ($jsback,\%elements);
9071: }
9072:
1.26 matthew 9073: sub course_level_table {
1.375 raeburn 9074: my ($inccourses,$showcredits,$defaultcredits) = @_;
9075: return unless (ref($inccourses) eq 'HASH');
1.26 matthew 9076: my $table = '';
1.62 www 9077: # Custom Roles?
9078:
1.190 raeburn 9079: my %customroles=&Apache::lonuserutils::my_custom_roles();
1.89 raeburn 9080: my %lt=&Apache::lonlocal::texthash(
9081: 'exs' => "Existing sections",
9082: 'new' => "Define new section",
9083: 'ssd' => "Set Start Date",
9084: 'sed' => "Set End Date",
1.131 raeburn 9085: 'crl' => "Course Level",
1.89 raeburn 9086: 'act' => "Activate",
9087: 'rol' => "Role",
9088: 'ext' => "Extent",
1.113 raeburn 9089: 'grs' => "Section",
1.375 raeburn 9090: 'crd' => "Credits",
1.89 raeburn 9091: 'sta' => "Start",
9092: 'end' => "End"
9093: );
1.62 www 9094:
1.375 raeburn 9095: foreach my $protectedcourse (sort(keys(%{$inccourses}))) {
1.135 raeburn 9096: my $thiscourse=$protectedcourse;
1.26 matthew 9097: $thiscourse=~s:_:/:g;
9098: my %coursedata=&Apache::lonnet::coursedescription($thiscourse);
1.365 raeburn 9099: my $isowner = &Apache::lonuserutils::is_courseowner($protectedcourse,$coursedata{'internal.courseowner'});
1.26 matthew 9100: my $area=$coursedata{'description'};
1.321 raeburn 9101: my $crstype=$coursedata{'type'};
1.135 raeburn 9102: if (!defined($area)) { $area=&mt('Unavailable course').': '.$protectedcourse; }
1.89 raeburn 9103: my ($domain,$cnum)=split(/\//,$thiscourse);
1.115 albertel 9104: my %sections_count;
1.101 albertel 9105: if (defined($env{'request.course.id'})) {
9106: if ($env{'request.course.id'} eq $domain.'_'.$cnum) {
1.115 albertel 9107: %sections_count =
9108: &Apache::loncommon::get_sections($domain,$cnum);
1.92 raeburn 9109: }
9110: }
1.321 raeburn 9111: my @roles = &Apache::lonuserutils::roles_by_context('course','',$crstype);
1.213 raeburn 9112: foreach my $role (@roles) {
1.321 raeburn 9113: my $plrole=&Apache::lonnet::plaintext($role,$crstype);
1.329 raeburn 9114: if ((&Apache::lonnet::allowed('c'.$role,$thiscourse)) ||
9115: ((($role eq 'cc') || ($role eq 'co')) && ($isowner))) {
1.221 raeburn 9116: $table .= &course_level_row($protectedcourse,$role,$area,$domain,
1.375 raeburn 9117: $plrole,\%sections_count,\%lt,
1.402 raeburn 9118: $showcredits,$defaultcredits,$crstype);
1.221 raeburn 9119: } elsif ($env{'request.course.sec'} ne '') {
9120: if (&Apache::lonnet::allowed('c'.$role,$thiscourse.'/'.
9121: $env{'request.course.sec'})) {
9122: $table .= &course_level_row($protectedcourse,$role,$area,$domain,
1.375 raeburn 9123: $plrole,\%sections_count,\%lt,
1.402 raeburn 9124: $showcredits,$defaultcredits,$crstype);
1.26 matthew 9125: }
9126: }
9127: }
1.221 raeburn 9128: if (&Apache::lonnet::allowed('ccr',$thiscourse)) {
1.324 raeburn 9129: foreach my $cust (sort(keys(%customroles))) {
9130: next if ($crstype eq 'Community' && $customroles{$cust} =~ /bre\&S/);
1.221 raeburn 9131: my $role = 'cr_cr_'.$env{'user.domain'}.'_'.$env{'user.name'}.'_'.$cust;
9132: $table .= &course_level_row($protectedcourse,$role,$area,$domain,
1.402 raeburn 9133: $cust,\%sections_count,\%lt,
9134: $showcredits,$defaultcredits,$crstype);
1.221 raeburn 9135: }
1.62 www 9136: }
1.26 matthew 9137: }
9138: return '' if ($table eq ''); # return nothing if there is nothing
9139: # in the table
1.188 raeburn 9140: my $result;
9141: if (!$env{'request.course.id'}) {
9142: $result = '<h4>'.$lt{'crl'}.'</h4>'."\n";
9143: }
9144: $result .=
1.136 raeburn 9145: &Apache::loncommon::start_data_table().
9146: &Apache::loncommon::start_data_table_header_row().
1.375 raeburn 9147: '<th>'.$lt{'act'}.'</th><th>'.$lt{'rol'}.'</th>'."\n".
1.402 raeburn 9148: '<th>'.$lt{'ext'}.'</th><th>'."\n";
9149: if ($showcredits) {
9150: $result .= $lt{'crd'}.'</th>';
9151: }
9152: $result .=
1.375 raeburn 9153: '<th>'.$lt{'grs'}.'</th><th>'.$lt{'sta'}.'</th>'."\n".
9154: '<th>'.$lt{'end'}.'</th>'.
1.136 raeburn 9155: &Apache::loncommon::end_data_table_header_row().
9156: $table.
9157: &Apache::loncommon::end_data_table();
1.26 matthew 9158: return $result;
9159: }
1.88 raeburn 9160:
1.221 raeburn 9161: sub course_level_row {
1.375 raeburn 9162: my ($protectedcourse,$role,$area,$domain,$plrole,$sections_count,
1.402 raeburn 9163: $lt,$showcredits,$defaultcredits,$crstype) = @_;
1.375 raeburn 9164: my $creditem;
1.222 raeburn 9165: my $row = &Apache::loncommon::start_data_table_row().
9166: ' <td><input type="checkbox" name="act_'.
9167: $protectedcourse.'_'.$role.'" /></td>'."\n".
9168: ' <td>'.$plrole.'</td>'."\n".
9169: ' <td>'.$area.'<br />Domain: '.$domain.'</td>'."\n";
1.402 raeburn 9170: if (($showcredits) && ($role eq 'st') && ($crstype eq 'Course')) {
1.375 raeburn 9171: $row .=
9172: '<td><input type="text" name="credits_'.$protectedcourse.'_'.
9173: $role.'" size="3" value="'.$defaultcredits.'" /></td>';
9174: } else {
9175: $row .= '<td> </td>';
9176: }
1.322 raeburn 9177: if (($role eq 'cc') || ($role eq 'co')) {
1.222 raeburn 9178: $row .= '<td> </td>';
1.221 raeburn 9179: } elsif ($env{'request.course.sec'} ne '') {
1.222 raeburn 9180: $row .= ' <td><input type="hidden" value="'.
9181: $env{'request.course.sec'}.'" '.
9182: 'name="sec_'.$protectedcourse.'_'.$role.'" />'.
9183: $env{'request.course.sec'}.'</td>';
1.221 raeburn 9184: } else {
9185: if (ref($sections_count) eq 'HASH') {
9186: my $currsec =
9187: &Apache::lonuserutils::course_sections($sections_count,
9188: $protectedcourse.'_'.$role);
1.222 raeburn 9189: $row .= '<td><table class="LC_createuser">'."\n".
9190: '<tr class="LC_section_row">'."\n".
9191: ' <td valign="top">'.$lt->{'exs'}.'<br />'.
9192: $currsec.'</td>'."\n".
9193: ' <td> </td>'."\n".
9194: ' <td valign="top"> '.$lt->{'new'}.'<br />'.
1.221 raeburn 9195: '<input type="text" name="newsec_'.$protectedcourse.'_'.$role.
9196: '" value="" />'.
9197: '<input type="hidden" '.
9198: 'name="sec_'.$protectedcourse.'_'.$role.'" /></td>'."\n".
1.222 raeburn 9199: '</tr></table></td>'."\n";
1.221 raeburn 9200: } else {
1.222 raeburn 9201: $row .= '<td><input type="text" size="10" '.
1.375 raeburn 9202: 'name="sec_'.$protectedcourse.'_'.$role.'" /></td>'."\n";
1.221 raeburn 9203: }
9204: }
1.222 raeburn 9205: $row .= <<ENDTIMEENTRY;
9206: <td><input type="hidden" name="start_$protectedcourse\_$role" value="" />
1.221 raeburn 9207: <a href=
9208: "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 9209: <td><input type="hidden" name="end_$protectedcourse\_$role" value="" />
1.221 raeburn 9210: <a href=
9211: "javascript:pjump('date_end','End Date $plrole',document.cu.end_$protectedcourse\_$role.value,'end_$protectedcourse\_$role','cu.pres','dateset')">$lt->{'sed'}</a></td>
9212: ENDTIMEENTRY
1.222 raeburn 9213: $row .= &Apache::loncommon::end_data_table_row();
9214: return $row;
1.221 raeburn 9215: }
9216:
1.88 raeburn 9217: sub course_level_dc {
1.375 raeburn 9218: my ($dcdom,$showcredits) = @_;
1.190 raeburn 9219: my %customroles=&Apache::lonuserutils::my_custom_roles();
1.213 raeburn 9220: my @roles = &Apache::lonuserutils::roles_by_context('course');
1.88 raeburn 9221: my $hiddenitems = '<input type="hidden" name="dcdomain" value="'.$dcdom.'" />'.
9222: '<input type="hidden" name="origdom" value="'.$dcdom.'" />'.
1.133 raeburn 9223: '<input type="hidden" name="dccourse" value="" />';
1.355 www 9224: my $courseform=&Apache::loncommon::selectcourse_link
1.356 raeburn 9225: ('cu','dccourse','dcdomain','coursedesc',undef,undef,'Select','crstype');
1.375 raeburn 9226: my $credit_elem;
9227: if ($showcredits) {
9228: $credit_elem = 'credits';
9229: }
9230: my $cb_jscript = &Apache::loncommon::coursebrowser_javascript($dcdom,'currsec','cu','role','Course/Community Browser',$credit_elem);
1.88 raeburn 9231: my %lt=&Apache::lonlocal::texthash(
9232: 'rol' => "Role",
1.113 raeburn 9233: 'grs' => "Section",
1.88 raeburn 9234: 'exs' => "Existing sections",
9235: 'new' => "Define new section",
9236: 'sta' => "Start",
9237: 'end' => "End",
9238: 'ssd' => "Set Start Date",
1.355 www 9239: 'sed' => "Set End Date",
1.375 raeburn 9240: 'scc' => "Course/Community",
9241: 'crd' => "Credits",
1.88 raeburn 9242: );
1.323 raeburn 9243: my $header = '<h4>'.&mt('Course/Community Level').'</h4>'.
1.136 raeburn 9244: &Apache::loncommon::start_data_table().
9245: &Apache::loncommon::start_data_table_header_row().
1.375 raeburn 9246: '<th>'.$lt{'scc'}.'</th><th>'.$lt{'rol'}.'</th>'."\n".
1.397 bisitz 9247: '<th>'.$lt{'grs'}.'</th>'."\n";
9248: $header .= '<th>'.$lt{'crd'}.'</th>'."\n" if ($showcredits);
9249: $header .= '<th>'.$lt{'sta'}.'</th><th>'.$lt{'end'}.'</th>'."\n".
1.136 raeburn 9250: &Apache::loncommon::end_data_table_header_row();
1.143 raeburn 9251: my $otheritems = &Apache::loncommon::start_data_table_row()."\n".
1.356 raeburn 9252: '<td><br /><span class="LC_nobreak"><input type="text" name="coursedesc" value="" onfocus="this.blur();opencrsbrowser('."'cu','dccourse','dcdomain','coursedesc','','','','crstype'".')" />'.
9253: $courseform.(' ' x4).'</span></td>'."\n".
1.389 bisitz 9254: '<td valign="top"><br /><select name="role">'."\n";
1.213 raeburn 9255: foreach my $role (@roles) {
1.135 raeburn 9256: my $plrole=&Apache::lonnet::plaintext($role);
1.389 bisitz 9257: $otheritems .= ' <option value="'.$role.'">'.$plrole.'</option>';
1.88 raeburn 9258: }
1.404 raeburn 9259: if ( keys(%customroles) > 0) {
9260: foreach my $cust (sort(keys(%customroles))) {
1.101 albertel 9261: my $custrole='cr_cr_'.$env{'user.domain'}.
1.135 raeburn 9262: '_'.$env{'user.name'}.'_'.$cust;
1.389 bisitz 9263: $otheritems .= ' <option value="'.$custrole.'">'.$cust.'</option>';
1.88 raeburn 9264: }
9265: }
9266: $otheritems .= '</select></td><td>'.
9267: '<table border="0" cellspacing="0" cellpadding="0">'.
9268: '<tr><td valign="top"><b>'.$lt{'exs'}.'</b><br /><select name="currsec">'.
1.389 bisitz 9269: ' <option value=""><--'.&mt('Pick course first').'</option></select></td>'.
1.88 raeburn 9270: '<td> </td>'.
9271: '<td valign="top"> <b>'.$lt{'new'}.'</b><br />'.
1.113 raeburn 9272: '<input type="text" name="newsec" value="" />'.
1.237 raeburn 9273: '<input type="hidden" name="section" value="" />'.
1.323 raeburn 9274: '<input type="hidden" name="groups" value="" />'.
9275: '<input type="hidden" name="crstype" value="" /></td>'.
1.375 raeburn 9276: '</tr></table></td>'."\n";
9277: if ($showcredits) {
9278: $otheritems .= '<td><br />'."\n".
1.397 bisitz 9279: '<input type="text" size="3" name="credits" value="" /></td>'."\n";
1.375 raeburn 9280: }
1.88 raeburn 9281: $otheritems .= <<ENDTIMEENTRY;
1.323 raeburn 9282: <td><br /><input type="hidden" name="start" value='' />
1.88 raeburn 9283: <a href=
9284: "javascript:pjump('date_start','Start Date',document.cu.start.value,'start','cu.pres','dateset')">$lt{'ssd'}</a></td>
1.323 raeburn 9285: <td><br /><input type="hidden" name="end" value='' />
1.88 raeburn 9286: <a href=
9287: "javascript:pjump('date_end','End Date',document.cu.end.value,'end','cu.pres','dateset')">$lt{'sed'}</a></td>
9288: ENDTIMEENTRY
1.136 raeburn 9289: $otheritems .= &Apache::loncommon::end_data_table_row().
9290: &Apache::loncommon::end_data_table()."\n";
1.88 raeburn 9291: return $cb_jscript.$header.$hiddenitems.$otheritems;
9292: }
9293:
1.237 raeburn 9294: sub update_selfenroll_config {
1.400 raeburn 9295: my ($r,$cid,$cdom,$cnum,$context,$crstype,$currsettings) = @_;
1.398 raeburn 9296: return unless (ref($currsettings) eq 'HASH');
9297: my ($row,$lt) = &Apache::lonuserutils::get_selfenroll_titles();
9298: my %curr_groups = &Apache::longroup::coursegroups($cdom,$cnum);
1.237 raeburn 9299: my (%changes,%warning);
1.241 raeburn 9300: my $curr_types;
1.400 raeburn 9301: my %noedit;
9302: unless ($context eq 'domain') {
9303: %noedit = &get_noedit_fields($cdom,$cnum,$crstype,$row);
9304: }
1.237 raeburn 9305: if (ref($row) eq 'ARRAY') {
9306: foreach my $item (@{$row}) {
1.400 raeburn 9307: next if ($noedit{$item});
1.237 raeburn 9308: if ($item eq 'enroll_dates') {
9309: my (%currenrolldate,%newenrolldate);
9310: foreach my $type ('start','end') {
1.398 raeburn 9311: $currenrolldate{$type} = $currsettings->{'selfenroll_'.$type.'_date'};
1.237 raeburn 9312: $newenrolldate{$type} = &Apache::lonhtmlcommon::get_date_from_form('selfenroll_'.$type.'_date');
9313: if ($newenrolldate{$type} ne $currenrolldate{$type}) {
9314: $changes{'internal.selfenroll_'.$type.'_date'} = $newenrolldate{$type};
9315: }
9316: }
9317: } elsif ($item eq 'access_dates') {
9318: my (%currdate,%newdate);
9319: foreach my $type ('start','end') {
1.398 raeburn 9320: $currdate{$type} = $currsettings->{'selfenroll_'.$type.'_access'};
1.237 raeburn 9321: $newdate{$type} = &Apache::lonhtmlcommon::get_date_from_form('selfenroll_'.$type.'_access');
9322: if ($newdate{$type} ne $currdate{$type}) {
9323: $changes{'internal.selfenroll_'.$type.'_access'} = $newdate{$type};
9324: }
9325: }
1.241 raeburn 9326: } elsif ($item eq 'types') {
1.398 raeburn 9327: $curr_types = $currsettings->{'selfenroll_'.$item};
1.241 raeburn 9328: if ($env{'form.selfenroll_all'}) {
9329: if ($curr_types ne '*') {
9330: $changes{'internal.selfenroll_types'} = '*';
9331: } else {
9332: next;
9333: }
9334: } else {
1.249 raeburn 9335: my %currdoms;
1.241 raeburn 9336: my @entries = split(/;/,$curr_types);
9337: my @deletedoms = &Apache::loncommon::get_env_multiple('form.selfenroll_delete');
1.249 raeburn 9338: my @activations = &Apache::loncommon::get_env_multiple('form.selfenroll_activate');
1.241 raeburn 9339: my $newnum = 0;
1.249 raeburn 9340: my @latesttypes;
9341: foreach my $num (@activations) {
9342: my @types = &Apache::loncommon::get_env_multiple('form.selfenroll_types_'.$num);
9343: if (@types > 0) {
1.241 raeburn 9344: @types = sort(@types);
9345: my $typestr = join(',',@types);
1.249 raeburn 9346: my $typedom = $env{'form.selfenroll_dom_'.$num};
9347: $latesttypes[$newnum] = $typedom.':'.$typestr;
9348: $currdoms{$typedom} = 1;
1.241 raeburn 9349: $newnum ++;
9350: }
9351: }
1.338 raeburn 9352: for (my $j=0; $j<$env{'form.selfenroll_types_total'}; $j++) {
9353: if ((!grep(/^$j$/,@deletedoms)) && (!grep(/^$j$/,@activations))) {
1.249 raeburn 9354: my @types = &Apache::loncommon::get_env_multiple('form.selfenroll_types_'.$j);
9355: if (@types > 0) {
9356: @types = sort(@types);
9357: my $typestr = join(',',@types);
9358: my $typedom = $env{'form.selfenroll_dom_'.$j};
9359: $latesttypes[$newnum] = $typedom.':'.$typestr;
9360: $currdoms{$typedom} = 1;
9361: $newnum ++;
9362: }
9363: }
9364: }
9365: if ($env{'form.selfenroll_newdom'} ne '') {
9366: my $typedom = $env{'form.selfenroll_newdom'};
9367: if ((!defined($currdoms{$typedom})) &&
9368: (&Apache::lonnet::domain($typedom) ne '')) {
9369: my $typestr;
9370: my ($othertitle,$usertypes,$types) =
9371: &Apache::loncommon::sorted_inst_types($typedom);
9372: my $othervalue = 'any';
9373: if ((ref($types) eq 'ARRAY') && (ref($usertypes) eq 'HASH')) {
9374: if (@{$types} > 0) {
1.257 raeburn 9375: my @esc_types = map { &escape($_); } @{$types};
1.249 raeburn 9376: $othervalue = 'other';
1.258 raeburn 9377: $typestr = join(',',(@esc_types,$othervalue));
1.249 raeburn 9378: }
9379: $typestr = $othervalue;
9380: } else {
9381: $typestr = $othervalue;
9382: }
9383: $latesttypes[$newnum] = $typedom.':'.$typestr;
9384: $newnum ++ ;
9385: }
9386: }
1.241 raeburn 9387: my $selfenroll_types = join(';',@latesttypes);
9388: if ($selfenroll_types ne $curr_types) {
9389: $changes{'internal.selfenroll_types'} = $selfenroll_types;
9390: }
9391: }
1.276 raeburn 9392: } elsif ($item eq 'limit') {
9393: my $newlimit = $env{'form.selfenroll_limit'};
9394: my $newcap = $env{'form.selfenroll_cap'};
9395: $newcap =~s/\s+//g;
1.398 raeburn 9396: my $currlimit = $currsettings->{'selfenroll_limit'};
1.276 raeburn 9397: $currlimit = 'none' if ($currlimit eq '');
1.398 raeburn 9398: my $currcap = $currsettings->{'selfenroll_cap'};
1.276 raeburn 9399: if ($newlimit ne $currlimit) {
9400: if ($newlimit ne 'none') {
9401: if ($newcap =~ /^\d+$/) {
9402: if ($newcap ne $currcap) {
9403: $changes{'internal.selfenroll_cap'} = $newcap;
9404: }
9405: $changes{'internal.selfenroll_limit'} = $newlimit;
9406: } else {
1.398 raeburn 9407: $warning{$item} = &mt('Maximum enrollment setting unchanged.').'<br />'.
9408: &mt('The value provided was invalid - it must be a positive integer if enrollment is being limited.');
1.276 raeburn 9409: }
9410: } elsif ($currcap ne '') {
9411: $changes{'internal.selfenroll_cap'} = '';
9412: $changes{'internal.selfenroll_limit'} = $newlimit;
9413: }
9414: } elsif ($currlimit ne 'none') {
9415: if ($newcap =~ /^\d+$/) {
9416: if ($newcap ne $currcap) {
9417: $changes{'internal.selfenroll_cap'} = $newcap;
9418: }
9419: } else {
1.398 raeburn 9420: $warning{$item} = &mt('Maximum enrollment setting unchanged.').'<br />'.
9421: &mt('The value provided was invalid - it must be a positive integer if enrollment is being limited.');
1.276 raeburn 9422: }
9423: }
9424: } elsif ($item eq 'approval') {
9425: my (@currnotified,@newnotified);
1.398 raeburn 9426: my $currapproval = $currsettings->{'selfenroll_approval'};
9427: my $currnotifylist = $currsettings->{'selfenroll_notifylist'};
1.276 raeburn 9428: if ($currnotifylist ne '') {
9429: @currnotified = split(/,/,$currnotifylist);
9430: @currnotified = sort(@currnotified);
9431: }
9432: my $newapproval = $env{'form.selfenroll_approval'};
9433: @newnotified = &Apache::loncommon::get_env_multiple('form.selfenroll_notify');
9434: @newnotified = sort(@newnotified);
9435: if ($newapproval ne $currapproval) {
9436: $changes{'internal.selfenroll_approval'} = $newapproval;
9437: if (!$newapproval) {
9438: if ($currnotifylist ne '') {
9439: $changes{'internal.selfenroll_notifylist'} = '';
9440: }
9441: } else {
9442: my @differences =
1.295 raeburn 9443: &Apache::loncommon::compare_arrays(\@currnotified,\@newnotified);
1.276 raeburn 9444: if (@differences > 0) {
9445: if (@newnotified > 0) {
9446: $changes{'internal.selfenroll_notifylist'} = join(',',@newnotified);
9447: } else {
9448: $changes{'internal.selfenroll_notifylist'} = join(',',@newnotified);
9449: }
9450: }
9451: }
9452: } else {
1.295 raeburn 9453: my @differences = &Apache::loncommon::compare_arrays(\@currnotified,\@newnotified);
1.276 raeburn 9454: if (@differences > 0) {
9455: if (@newnotified > 0) {
9456: $changes{'internal.selfenroll_notifylist'} = join(',',@newnotified);
9457: } else {
9458: $changes{'internal.selfenroll_notifylist'} = '';
9459: }
9460: }
9461: }
1.237 raeburn 9462: } else {
1.398 raeburn 9463: my $curr_val = $currsettings->{'selfenroll_'.$item};
1.237 raeburn 9464: my $newval = $env{'form.selfenroll_'.$item};
9465: if ($item eq 'section') {
9466: $newval = $env{'form.sections'};
1.241 raeburn 9467: if (defined($curr_groups{$newval})) {
1.237 raeburn 9468: $newval = $curr_val;
1.398 raeburn 9469: $warning{$item} = &mt('Section for self-enrolled users unchanged as the proposed section is a group').'<br />'.
9470: &mt('Group names and section names must be distinct');
1.237 raeburn 9471: } elsif ($newval eq 'all') {
9472: $newval = $curr_val;
1.274 bisitz 9473: $warning{$item} = &mt('Section for self-enrolled users unchanged, as "all" is a reserved section name.');
1.237 raeburn 9474: }
9475: if ($newval eq '') {
9476: $newval = 'none';
9477: }
9478: }
9479: if ($newval ne $curr_val) {
9480: $changes{'internal.selfenroll_'.$item} = $newval;
9481: }
1.241 raeburn 9482: }
1.237 raeburn 9483: }
9484: if (keys(%warning) > 0) {
9485: foreach my $item (@{$row}) {
9486: if (exists($warning{$item})) {
9487: $r->print($warning{$item}.'<br />');
9488: }
9489: }
9490: }
9491: if (keys(%changes) > 0) {
9492: my $putresult = &Apache::lonnet::put('environment',\%changes,$cdom,$cnum);
9493: if ($putresult eq 'ok') {
9494: if ((exists($changes{'internal.selfenroll_types'})) ||
9495: (exists($changes{'internal.selfenroll_start_date'})) ||
9496: (exists($changes{'internal.selfenroll_end_date'}))) {
9497: my %crsinfo = &Apache::lonnet::courseiddump($cdom,'.',1,'.','.',
9498: $cnum,undef,undef,'Course');
9499: my $chome = &Apache::lonnet::homeserver($cnum,$cdom);
1.398 raeburn 9500: if (ref($crsinfo{$cid}) eq 'HASH') {
1.237 raeburn 9501: foreach my $item ('selfenroll_types','selfenroll_start_date','selfenroll_end_date') {
9502: if (exists($changes{'internal.'.$item})) {
1.398 raeburn 9503: $crsinfo{$cid}{$item} = $changes{'internal.'.$item};
1.237 raeburn 9504: }
9505: }
9506: my $crsputresult =
9507: &Apache::lonnet::courseidput($cdom,\%crsinfo,
9508: $chome,'notime');
9509: }
9510: }
9511: $r->print(&mt('The following changes were made to self-enrollment settings:').'<ul>');
9512: foreach my $item (@{$row}) {
9513: my $title = $item;
9514: if (ref($lt) eq 'HASH') {
9515: $title = $lt->{$item};
9516: }
9517: if ($item eq 'enroll_dates') {
9518: foreach my $type ('start','end') {
9519: if (exists($changes{'internal.selfenroll_'.$type.'_date'})) {
9520: my $newdate = &Apache::lonlocal::locallocaltime($changes{'internal.selfenroll_'.$type.'_date'});
1.244 bisitz 9521: $r->print('<li>'.&mt('[_1]: "[_2]" set to "[_3]".',
1.237 raeburn 9522: $title,$type,$newdate).'</li>');
9523: }
9524: }
9525: } elsif ($item eq 'access_dates') {
9526: foreach my $type ('start','end') {
9527: if (exists($changes{'internal.selfenroll_'.$type.'_access'})) {
9528: my $newdate = &Apache::lonlocal::locallocaltime($changes{'internal.selfenroll_'.$type.'_access'});
1.244 bisitz 9529: $r->print('<li>'.&mt('[_1]: "[_2]" set to "[_3]".',
1.237 raeburn 9530: $title,$type,$newdate).'</li>');
9531: }
9532: }
1.276 raeburn 9533: } elsif ($item eq 'limit') {
9534: if ((exists($changes{'internal.selfenroll_limit'})) ||
9535: (exists($changes{'internal.selfenroll_cap'}))) {
9536: my ($newval,$newcap);
9537: if ($changes{'internal.selfenroll_cap'} ne '') {
9538: $newcap = $changes{'internal.selfenroll_cap'}
9539: } else {
1.398 raeburn 9540: $newcap = $currsettings->{'selfenroll_cap'};
1.276 raeburn 9541: }
9542: if ($changes{'internal.selfenroll_limit'} eq 'none') {
9543: $newval = &mt('No limit');
9544: } elsif ($changes{'internal.selfenroll_limit'} eq
9545: 'allstudents') {
9546: $newval = &mt('New self-enrollment no longer allowed when total (all students) reaches [_1].',$newcap);
9547: } elsif ($changes{'internal.selfenroll_limit'} eq 'selfenrolled') {
9548: $newval = &mt('New self-enrollment no longer allowed when total number of self-enrolled students reaches [_1].',$newcap);
9549: } else {
1.398 raeburn 9550: my $currlimit = $currsettings->{'selfenroll_limit'};
1.276 raeburn 9551: if ($currlimit eq 'allstudents') {
9552: $newval = &mt('New self-enrollment no longer allowed when total (all students) reaches [_1].',$newcap);
9553: } elsif ($changes{'internal.selfenroll_limit'} eq 'selfenrolled') {
1.308 raeburn 9554: $newval = &mt('New self-enrollment no longer allowed when total number of self-enrolled students reaches [_1].',$newcap);
1.276 raeburn 9555: }
9556: }
9557: $r->print('<li>'.&mt('"[_1]" set to "[_2]".',$title,$newval).'</li>'."\n");
9558: }
9559: } elsif ($item eq 'approval') {
9560: if ((exists($changes{'internal.selfenroll_approval'})) ||
9561: (exists($changes{'internal.selfenroll_notifylist'}))) {
1.398 raeburn 9562: my %selfdescs = &Apache::lonuserutils::selfenroll_default_descs();
1.276 raeburn 9563: my ($newval,$newnotify);
9564: if (exists($changes{'internal.selfenroll_notifylist'})) {
9565: $newnotify = $changes{'internal.selfenroll_notifylist'};
9566: } else {
1.398 raeburn 9567: $newnotify = $currsettings->{'selfenroll_notifylist'};
1.276 raeburn 9568: }
1.398 raeburn 9569: if (exists($changes{'internal.selfenroll_approval'})) {
9570: if ($changes{'internal.selfenroll_approval'} !~ /^[012]$/) {
9571: $changes{'internal.selfenroll_approval'} = '0';
9572: }
9573: $newval = $selfdescs{'approval'}{$changes{'internal.selfenroll_approval'}};
1.276 raeburn 9574: } else {
1.398 raeburn 9575: my $currapproval = $currsettings->{'selfenroll_approval'};
9576: if ($currapproval !~ /^[012]$/) {
9577: $currapproval = 0;
1.276 raeburn 9578: }
1.398 raeburn 9579: $newval = $selfdescs{'approval'}{$currapproval};
1.276 raeburn 9580: }
9581: $r->print('<li>'.&mt('"[_1]" set to "[_2]".',$title,$newval));
9582: if ($newnotify) {
1.277 raeburn 9583: $r->print('<br />'.&mt('The following will be notified when an enrollment request needs approval, or has been approved: [_1].',$newnotify));
1.276 raeburn 9584: } else {
1.277 raeburn 9585: $r->print('<br />'.&mt('No notifications sent when an enrollment request needs approval, or has been approved.'));
1.276 raeburn 9586: }
9587: $r->print('</li>'."\n");
9588: }
1.237 raeburn 9589: } else {
9590: if (exists($changes{'internal.selfenroll_'.$item})) {
1.241 raeburn 9591: my $newval = $changes{'internal.selfenroll_'.$item};
9592: if ($item eq 'types') {
9593: if ($newval eq '') {
9594: $newval = &mt('None');
9595: } elsif ($newval eq '*') {
9596: $newval = &mt('Any user in any domain');
9597: }
1.245 raeburn 9598: } elsif ($item eq 'registered') {
9599: if ($newval eq '1') {
9600: $newval = &mt('Yes');
9601: } elsif ($newval eq '0') {
9602: $newval = &mt('No');
9603: }
1.241 raeburn 9604: }
1.244 bisitz 9605: $r->print('<li>'.&mt('"[_1]" set to "[_2]".',$title,$newval).'</li>'."\n");
1.237 raeburn 9606: }
9607: }
9608: }
9609: $r->print('</ul>');
1.398 raeburn 9610: if ($env{'course.'.$cid.'.description'} ne '') {
9611: my %newenvhash;
9612: foreach my $key (keys(%changes)) {
9613: $newenvhash{'course.'.$cid.'.'.$key} = $changes{$key};
9614: }
9615: &Apache::lonnet::appenv(\%newenvhash);
1.237 raeburn 9616: }
9617: } else {
1.398 raeburn 9618: $r->print(&mt('An error occurred when saving changes to self-enrollment settings in this course.').'<br />'.
9619: &mt('The error was: [_1].',$putresult));
1.237 raeburn 9620: }
9621: } else {
1.249 raeburn 9622: $r->print(&mt('No changes were made to the existing self-enrollment settings in this course.'));
1.237 raeburn 9623: }
9624: } else {
1.249 raeburn 9625: $r->print(&mt('No changes were made to the existing self-enrollment settings in this course.'));
1.241 raeburn 9626: }
1.400 raeburn 9627: my $visactions = &cat_visibility();
9628: my ($cathash,%cattype);
9629: my %domconfig = &Apache::lonnet::get_dom('configuration',['coursecategories'],$cdom);
9630: if (ref($domconfig{'coursecategories'}) eq 'HASH') {
9631: $cathash = $domconfig{'coursecategories'}{'cats'};
9632: $cattype{'auth'} = $domconfig{'coursecategories'}{'auth'};
9633: $cattype{'unauth'} = $domconfig{'coursecategories'}{'unauth'};
9634: } else {
9635: $cathash = {};
9636: $cattype{'auth'} = 'std';
9637: $cattype{'unauth'} = 'std';
9638: }
9639: if (($cattype{'auth'} eq 'none') && ($cattype{'unauth'} eq 'none')) {
9640: $r->print('<br /><span class="LC_warning">'.$visactions->{'miss'}.'</span><br />'.$visactions->{'yous'}.
9641: '<br />'.
9642: '<br />'.$visactions->{'take'}.'<ul>'.
9643: '<li>'.$visactions->{'dc_chgconf'}.'</li>'.
9644: '</ul>');
9645: } elsif (($cattype{'auth'} !~ /^(std|domonly)$/) && ($cattype{'unauth'} !~ /^(std|domonly)$/)) {
9646: if ($currsettings->{'uniquecode'}) {
9647: $r->print('<span class="LC_info">'.$visactions->{'vis'}.'</span>');
9648: } else {
1.366 bisitz 9649: $r->print('<br /><span class="LC_warning">'.$visactions->{'miss'}.'</span><br />'.$visactions->{'yous'}.
1.400 raeburn 9650: '<br />'.
9651: '<br />'.$visactions->{'take'}.'<ul>'.
9652: '<li>'.$visactions->{'dc_setcode'}.'</li>'.
9653: '</ul><br />');
9654: }
9655: } else {
9656: my ($visible,$cansetvis,$vismsgs) = &visible_in_stdcat($cdom,$cnum,\%domconfig);
9657: if (ref($visactions) eq 'HASH') {
9658: if (!$visible) {
9659: $r->print('<br /><span class="LC_warning">'.$visactions->{'miss'}.'</span><br />'.$visactions->{'yous'}.
9660: '<br />');
9661: if (ref($vismsgs) eq 'ARRAY') {
9662: $r->print('<br />'.$visactions->{'take'}.'<ul>');
9663: foreach my $item (@{$vismsgs}) {
9664: $r->print('<li>'.$visactions->{$item}.'</li>');
9665: }
9666: $r->print('</ul>');
1.256 raeburn 9667: }
1.400 raeburn 9668: $r->print($cansetvis);
1.256 raeburn 9669: }
9670: }
9671: }
1.237 raeburn 9672: return;
9673: }
9674:
1.27 matthew 9675: #---------------------------------------------- end functions for &phase_two
1.29 matthew 9676:
9677: #--------------------------------- functions for &phase_two and &phase_three
9678:
9679: #--------------------------end of functions for &phase_two and &phase_three
1.372 raeburn 9680:
1.1 www 9681: 1;
9682: __END__
1.2 www 9683:
9684:
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>